From patchwork Mon Sep 23 21:41:05 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thierry Reding X-Patchwork-Id: 2930621 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id C18FABFF05 for ; Mon, 23 Sep 2013 21:51:20 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id D4FC12012D for ; Mon, 23 Sep 2013 21:51:19 +0000 (UTC) Received: from casper.infradead.org (casper.infradead.org [85.118.1.10]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id BDE5320034 for ; Mon, 23 Sep 2013 21:51:18 +0000 (UTC) Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1VOE2F-0002BN-Uz; Mon, 23 Sep 2013 21:51:16 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1VOE2D-0003y8-9W; Mon, 23 Sep 2013 21:51:13 +0000 Received: from mail-bk0-x232.google.com ([2a00:1450:4008:c01::232]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1VOE2A-0003x6-9U for linux-arm-kernel@lists.infradead.org; Mon, 23 Sep 2013 21:51:11 +0000 Received: by mail-bk0-f50.google.com with SMTP id mz11so1473683bkb.9 for ; Mon, 23 Sep 2013 14:50:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=ZVpBscfASpJZvnjXVrGUDds9ilMVXNi3JsLVy/aUYaE=; b=LQEM5UVpXgmk78yLYW0J/Fq7UvEY7+Z+7DZJi5lJ2zDnLk4664e4I5t1dBw168iT1A j08AE3jiR2rOCBWmQHBfGwBjMFsinIMcVw8tS4QbQIBSpk/jcSyvVsRLqEDoV7OdIaBb P/OxuAKZvqQVbK9d/hzogapRzRK55eQdqxNwprG2XTUcx3/2pHtc9DgT73rfZCFSJs2z cHcMU8w1UVKWF+H3cJ/KX41SlEORKE8EKp4Js914kLIn5EGeOM42tJFjwtlMrlRh3ZsY hwHqU8tOMIkn0FYMX+CCh2oOWfLQDCSbN2EkZhACkB4sFJsezY7IMQAuIsd6BJGTRTVo X6ww== X-Received: by 10.204.69.12 with SMTP id x12mr19237700bki.12.1379972566878; Mon, 23 Sep 2013 14:42:46 -0700 (PDT) Received: from localhost (port-13639.pppoe.wtnet.de. [84.46.53.124]) by mx.google.com with ESMTPSA id l5sm9648505bko.7.1969.12.31.16.00.00 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Mon, 23 Sep 2013 14:42:46 -0700 (PDT) From: Thierry Reding To: Thierry Reding Subject: [PATCH 08/10] pwm-backlight: Use new enable_gpio field Date: Mon, 23 Sep 2013 23:41:05 +0200 Message-Id: <1379972467-11243-9-git-send-email-treding@nvidia.com> X-Mailer: git-send-email 1.8.4 In-Reply-To: <1379972467-11243-1-git-send-email-treding@nvidia.com> References: <1379972467-11243-1-git-send-email-treding@nvidia.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20130923_175110_594026_662B9FA8 X-CRM114-Status: GOOD ( 18.46 ) X-Spam-Score: 1.4 (+) Cc: Mark Rutland , devicetree@vger.kernel.org, Kukjin Kim , Eric Miao , Pawel Moll , Ian Campbell , Tony Lindgren , Stephen Warren , Magnus Damm , linux-kernel@vger.kernel.org, Rob Herring , linux-samsung-soc@vger.kernel.org, linux-omap@vger.kernel.org, Simon Horman , linux-pwm@vger.kernel.org, Haojian Zhuang , Ben Dooks , linux-sh@vger.kernel.org, openezx-devel@lists.openezx.org, Guan Xuetao , linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-3.0 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, KHOP_BIG_TO_CC, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Make use of the new enable_gpio field and allow it to be set from DT as well. Now that all legacy users of platform data have been converted to initialize this field to an invalid value, it is safe to use the field from the driver. Signed-off-by: Thierry Reding --- .../bindings/video/backlight/pwm-backlight.txt | 3 ++ drivers/video/backlight/pwm_bl.c | 54 +++++++++++++++++++--- 2 files changed, 50 insertions(+), 7 deletions(-) diff --git a/Documentation/devicetree/bindings/video/backlight/pwm-backlight.txt b/Documentation/devicetree/bindings/video/backlight/pwm-backlight.txt index 1e4fc72..052eb03 100644 --- a/Documentation/devicetree/bindings/video/backlight/pwm-backlight.txt +++ b/Documentation/devicetree/bindings/video/backlight/pwm-backlight.txt @@ -14,6 +14,7 @@ Required properties: Optional properties: - pwm-names: a list of names for the PWM devices specified in the "pwms" property (see PWM binding[0]) + - enable-gpios: a list of GPIOs to enable and disable the backlight [0]: Documentation/devicetree/bindings/pwm/pwm.txt @@ -25,4 +26,6 @@ Example: brightness-levels = <0 4 8 16 32 64 128 255>; default-brightness-level = <6>; + + enable-gpios = <&gpio 58 0>; }; diff --git a/drivers/video/backlight/pwm_bl.c b/drivers/video/backlight/pwm_bl.c index 8a49b30..506810c 100644 --- a/drivers/video/backlight/pwm_bl.c +++ b/drivers/video/backlight/pwm_bl.c @@ -10,6 +10,8 @@ * published by the Free Software Foundation. */ +#include +#include #include #include #include @@ -27,6 +29,8 @@ struct pwm_bl_data { unsigned int period; unsigned int lth_brightness; unsigned int *levels; + int enable_gpio; + unsigned long enable_gpio_flags; int (*notify)(struct device *, int brightness); void (*notify_after)(struct device *, @@ -51,12 +55,27 @@ static void pwm_backlight_power_on(struct pwm_bl_data *pb, int brightness, pb->lth_brightness; pwm_config(pb->pwm, duty_cycle, pb->period); + + if (gpio_is_valid(pb->enable_gpio)) { + if (pb->enable_gpio_flags & PWM_BACKLIGHT_GPIO_ACTIVE_LOW) + gpio_set_value(pb->enable_gpio, 0); + else + gpio_set_value(pb->enable_gpio, 1); + } + pwm_enable(pb->pwm); } static void pwm_backlight_power_off(struct pwm_bl_data *pb) { pwm_disable(pb->pwm); + + if (gpio_is_valid(pb->enable_gpio)) { + if (pb->enable_gpio_flags & PWM_BACKLIGHT_GPIO_ACTIVE_LOW) + gpio_set_value(pb->enable_gpio, 1); + else + gpio_set_value(pb->enable_gpio, 0); + } } static int pwm_backlight_update_status(struct backlight_device *bl) @@ -108,6 +127,7 @@ static int pwm_backlight_parse_dt(struct device *dev, struct platform_pwm_backlight_data *data) { struct device_node *node = dev->of_node; + enum of_gpio_flags flags; struct property *prop; int length; u32 value; @@ -148,11 +168,10 @@ static int pwm_backlight_parse_dt(struct device *dev, data->max_brightness--; } - /* - * TODO: Most users of this driver use a number of GPIOs to control - * backlight power. Support for specifying these needs to be - * added. - */ + data->enable_gpio = of_get_named_gpio_flags(node, "enable-gpios", 0, + &flags); + if (gpio_is_valid(data->enable_gpio) && (flags & OF_GPIO_ACTIVE_LOW)) + data->enable_gpio_flags |= PWM_BACKLIGHT_GPIO_ACTIVE_LOW; return 0; } @@ -210,12 +229,30 @@ static int pwm_backlight_probe(struct platform_device *pdev) } else max = data->max_brightness; + pb->enable_gpio = data->enable_gpio; + pb->enable_gpio_flags = data->enable_gpio_flags; pb->notify = data->notify; pb->notify_after = data->notify_after; pb->check_fb = data->check_fb; pb->exit = data->exit; pb->dev = &pdev->dev; + if (gpio_is_valid(pb->enable_gpio)) { + unsigned long flags; + + if (pb->enable_gpio_flags & PWM_BACKLIGHT_GPIO_ACTIVE_LOW) + flags = GPIOF_OUT_INIT_HIGH; + else + flags = GPIOF_OUT_INIT_LOW; + + ret = gpio_request_one(pb->enable_gpio, flags, "enable"); + if (ret < 0) { + dev_err(&pdev->dev, "failed to request GPIO#%d: %d\n", + pb->enable_gpio, ret); + goto err_alloc; + } + } + pb->pwm = devm_pwm_get(&pdev->dev, NULL); if (IS_ERR(pb->pwm)) { dev_err(&pdev->dev, "unable to request PWM, trying legacy API\n"); @@ -224,7 +261,7 @@ static int pwm_backlight_probe(struct platform_device *pdev) if (IS_ERR(pb->pwm)) { dev_err(&pdev->dev, "unable to request legacy PWM\n"); ret = PTR_ERR(pb->pwm); - goto err_alloc; + goto err_gpio; } } @@ -249,7 +286,7 @@ static int pwm_backlight_probe(struct platform_device *pdev) if (IS_ERR(bl)) { dev_err(&pdev->dev, "failed to register backlight\n"); ret = PTR_ERR(bl); - goto err_alloc; + goto err_gpio; } if (data->dft_brightness > data->max_brightness) { @@ -265,6 +302,9 @@ static int pwm_backlight_probe(struct platform_device *pdev) platform_set_drvdata(pdev, bl); return 0; +err_gpio: + if (gpio_is_valid(pb->enable_gpio)) + gpio_free(pb->enable_gpio); err_alloc: if (data->exit) data->exit(&pdev->dev);