From patchwork Tue May 30 11:48:21 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 100706 Delivered-To: patch@linaro.org Received: by 10.140.96.100 with SMTP id j91csp170426qge; Tue, 30 May 2017 04:48:52 -0700 (PDT) X-Received: by 10.101.91.74 with SMTP id y10mr3481156pgr.16.1496144932071; Tue, 30 May 2017 04:48:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1496144932; cv=none; d=google.com; s=arc-20160816; b=xtRLDbnRBt+3S9WhbLb0lqsJegZAOJL4uaxWZSFpWI13rQHh3vCoetyqbZR7sfgp1p gcScyWc5+CzWrLNrBEaHIBiaEeD4+GhQCOGaXvjge1babHbsUFW9fRY1biM6SS7wtJSV 5ApEwHJoputdsTKng+xbZ5ucA6DBxrz/x+7MFCJSFjQ/VPX0bKU8e8/Ys/UuLrRpHRE0 nDN8RhkXt0RBY8hrYM6TUAGfyJvKIJuWCDDISmAF5fSVrcW6sxisFGJeR/lY8W1clkXQ /0wH3th6A5ARc7EfFTh1vDxO+IgaPQFCzd2iFYerIq1q1Qjk2Bz/gKqWYLGzQA6IZjDF MDdw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=TxLnju10B6zunzbCO+iIMWQloXsHztIrtd8FG/+6+b4=; b=Vqs7Zj5wsU84tMa4QHTUieM2g6EA6GK/t7+Td5v0EUusKc31LwH97JsYHDyah0PDOu 6tO+1BzNVNgRieLy6/VQjQkD/ChEwcZ4eJUiXKzdo5pVqf2YLm0ecZxLBE51WecMw4T5 zLwpZN9IaVyqlvlvA3qzlnkmfSx+/koEv5GkOiYBxNnNJbP4ZpYAlMnYylOtN20xkeFK d0n+AKOGWj2qtwIgBEttSTNdnmVmduTys6jFbnFfZfpLpzVxiNuOaqpUohhYslIdwXWA zOt2nHfNzoBPM0TTF/8Dma1GG/IGu+zMUvfIg8WGKyAR8sMHVzmVKH/3Hx5d9U8WpRlF Uj0A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r15si13377400pfj.70.2017.05.30.04.48.51; Tue, 30 May 2017 04:48:52 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751525AbdE3Lsd (ORCPT + 25 others); Tue, 30 May 2017 07:48:33 -0400 Received: from mail-lf0-f43.google.com ([209.85.215.43]:35978 "EHLO mail-lf0-f43.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751184AbdE3Lsa (ORCPT ); Tue, 30 May 2017 07:48:30 -0400 Received: by mail-lf0-f43.google.com with SMTP id h4so47594397lfj.3 for ; Tue, 30 May 2017 04:48:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=TxLnju10B6zunzbCO+iIMWQloXsHztIrtd8FG/+6+b4=; b=ViooGX5CoHzKjl597TFZzVXZBhkTOzAmOjis5/Upb/Sb2XT4lWV2OQ/OQgXPGLDp5C TQiMOdUY3KeODYY1W973zMjcGvMPYYMoWXxf3jPpjmGwJu9pb+AnL+QFLETdvZrJjYaE UjpLG3+N0ziCdU39mzBTqxmzP87ujSPZBN82I= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=TxLnju10B6zunzbCO+iIMWQloXsHztIrtd8FG/+6+b4=; b=Xz9QjfePmytwV2YszAmA5VjlM1GSF8wyWaYP8QyGjuTiNftH8XU5E7h8dwiAfVMFCA EKS68u7ISgQf4oBauFaV2KG9vXQ8NBsEqiqzJqMpR8mMrOV6tl/adN/jB0qlXogvxxuk imqMXSNYMgFEpoxewajQn5pKVowoG5eJ0+6GLnP5OnSwsIGxfnF65T79WNgthosiudet YDx8Ef+cU/tTLvwkLaCrNZLz4JCYRVlRiJjGVyEJFMTLo9S7f5HK3Ahl0WiPNSQaaVoQ R6fe2zvA61qhsMldh6Ak+GaTKq0hTlCAdboqskkSsvn0bLwkT6DyyvfKaRuDNGRaX2VG 7qkg== X-Gm-Message-State: AODbwcDCWh6l9wD4axM2ekNo2WnEh0GftOquxmPiYa9SOP1EFnUaPN7s FmOpwf+gWau1rZHt X-Received: by 10.46.20.9 with SMTP id u9mr6632269ljd.14.1496144908894; Tue, 30 May 2017 04:48:28 -0700 (PDT) Received: from fabina.bredbandsbolaget.se (c-9d7e71d5.014-348-6c756e10.cust.bredbandsbolaget.se. [213.113.126.157]) by smtp.gmail.com with ESMTPSA id z4sm2633554lfd.64.2017.05.30.04.48.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 30 May 2017 04:48:27 -0700 (PDT) From: Linus Walleij To: Lee Jones , Daniel Thompson , Jingoo Han , linux-kernel@vger.kernel.org Cc: Laurent Pinchart , Linus Walleij Subject: [PATCH 1/2 v2] backlight: gpio: Convert to use GPIO descriptor Date: Tue, 30 May 2017 13:48:21 +0200 Message-Id: <20170530114822.24308-1-linus.walleij@linaro.org> X-Mailer: git-send-email 2.9.4 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This driver is predominantly used by device tree systems, all of which can deal with modern GPIO descriptors. The legacy GPIO API is only used by one SH board so make the GPIO descriptor the default way to deal with it. As an intended side effect we do not need to look around in the device tree for the inversion flag since the GPIO descriptors will intrinsically deal with this. Acked-by: Daniel Thompson Signed-off-by: Linus Walleij --- ChangeLog v1->v2: - Assign flags value using the ternary operator. --- drivers/video/backlight/gpio_backlight.c | 71 +++++++++++++++++++------------- 1 file changed, 43 insertions(+), 28 deletions(-) -- 2.9.4 Reviewed-by: Laurent Pinchart diff --git a/drivers/video/backlight/gpio_backlight.c b/drivers/video/backlight/gpio_backlight.c index 18134416b154..5ffaff1e4142 100644 --- a/drivers/video/backlight/gpio_backlight.c +++ b/drivers/video/backlight/gpio_backlight.c @@ -9,7 +9,8 @@ #include #include #include -#include +#include /* Only for legacy support */ +#include #include #include #include @@ -23,7 +24,7 @@ struct gpio_backlight { struct device *dev; struct device *fbdev; - int gpio; + struct gpio_desc *gpiod; int active; int def_value; }; @@ -38,8 +39,8 @@ static int gpio_backlight_update_status(struct backlight_device *bl) bl->props.state & (BL_CORE_SUSPENDED | BL_CORE_FBBLANK)) brightness = 0; - gpio_set_value_cansleep(gbl->gpio, - brightness ? gbl->active : !gbl->active); + gpiod_set_value_cansleep(gbl->gpiod, + brightness ? gbl->active : !gbl->active); return 0; } @@ -61,23 +62,27 @@ static const struct backlight_ops gpio_backlight_ops = { static int gpio_backlight_probe_dt(struct platform_device *pdev, struct gpio_backlight *gbl) { - struct device_node *np = pdev->dev.of_node; - enum of_gpio_flags gpio_flags; + struct device *dev = &pdev->dev; + struct device_node *np = dev->of_node; + enum gpiod_flags flags; + int ret; + + gbl->def_value = of_property_read_bool(np, "default-on"); + flags = gbl->def_value ? GPIOD_OUT_HIGH : GPIOD_OUT_LOW; + /* GPIO descriptors keep track of inversion */ + gbl->active = 1; - gbl->gpio = of_get_gpio_flags(np, 0, &gpio_flags); + gbl->gpiod = devm_gpiod_get(dev, NULL, flags); + if (IS_ERR(gbl->gpiod)) { + ret = PTR_ERR(gbl->gpiod); - if (!gpio_is_valid(gbl->gpio)) { - if (gbl->gpio != -EPROBE_DEFER) { - dev_err(&pdev->dev, + if (ret != -EPROBE_DEFER) { + dev_err(dev, "Error: The gpios parameter is missing or invalid.\n"); } - return gbl->gpio; + return ret; } - gbl->active = (gpio_flags & OF_GPIO_ACTIVE_LOW) ? 0 : 1; - - gbl->def_value = of_property_read_bool(np, "default-on"); - return 0; } @@ -89,7 +94,6 @@ static int gpio_backlight_probe(struct platform_device *pdev) struct backlight_device *bl; struct gpio_backlight *gbl; struct device_node *np = pdev->dev.of_node; - unsigned long flags = GPIOF_DIR_OUT; int ret; if (!pdata && !np) { @@ -109,22 +113,33 @@ static int gpio_backlight_probe(struct platform_device *pdev) if (ret) return ret; } else { + /* + * Legacy platform data GPIO retrieveal. Do not expand + * the use of this code path, currently only used by one + * SH board. + */ + unsigned long flags = GPIOF_DIR_OUT; + gbl->fbdev = pdata->fbdev; - gbl->gpio = pdata->gpio; gbl->active = pdata->active_low ? 0 : 1; gbl->def_value = pdata->def_value; - } - - if (gbl->active) - flags |= gbl->def_value ? GPIOF_INIT_HIGH : GPIOF_INIT_LOW; - else - flags |= gbl->def_value ? GPIOF_INIT_LOW : GPIOF_INIT_HIGH; - ret = devm_gpio_request_one(gbl->dev, gbl->gpio, flags, - pdata ? pdata->name : "backlight"); - if (ret < 0) { - dev_err(&pdev->dev, "unable to request GPIO\n"); - return ret; + if (gbl->active) + flags |= gbl->def_value ? + GPIOF_INIT_HIGH : GPIOF_INIT_LOW; + else + flags |= gbl->def_value ? + GPIOF_INIT_LOW : GPIOF_INIT_HIGH; + + ret = devm_gpio_request_one(gbl->dev, pdata->gpio, flags, + pdata ? pdata->name : "backlight"); + if (ret < 0) { + dev_err(&pdev->dev, "unable to request GPIO\n"); + return ret; + } + gbl->gpiod = gpio_to_desc(pdata->gpio); + if (!gbl->gpiod) + return -EINVAL; } memset(&props, 0, sizeof(props)); From patchwork Tue May 30 11:48:22 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 100707 Delivered-To: patch@linaro.org Received: by 10.140.96.100 with SMTP id j91csp170427qge; Tue, 30 May 2017 04:48:52 -0700 (PDT) X-Received: by 10.99.144.199 with SMTP id a190mr23123059pge.193.1496144932704; Tue, 30 May 2017 04:48:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1496144932; cv=none; d=google.com; s=arc-20160816; b=VevuyFl4Otz4f4srTo7O4RwA9edP1TTcbP9JVMGtw7CfQ8f0yIq6Zsag3/qsH6pKEJ Hu27AZiSPGZLDI0tdLy/9SKejmukodlGL6tdxyxQvgqlKu8LE2YdiQZxxOnQTL00b7u4 JpEj7P1SHZhL1+WOgyewH7FIoskkrOGiWFFwhM2VFErOONYDzurMPU92ZL/Hebd9r/ym gN+U749s1NjC0c+QjpQ1OjypC/56t/WchTczJKZlJ/xwP3qGr/CwGM8ZZB75/+o19Cz0 k5RQ8z13YgLz4WJcOJ+4MQn+OYKYERsNDdVq1q2zeHn5TF7/92zZllYvR/k7AN2On5Ei S2AA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=PBWpj/7U9MtY+LBXiWGbu7EhpQ8b90eG02dNW19QSeQ=; b=XujkhpRwF8nTuFpxEr26A1K60hq0QfAS2X6HcPvFcWP+XajeGqZxvVssJzZBOroyPA H21ndKd98kVBiXsHReWDQsgUfepUTAzz4vGnLQno6SEwjdP3rX3TUWt+Ic7cVoDMKpJf lOP0xakSQlJmlHr8wySTjK46YyX2ViTtFMDWCaa8UzW/aO0/ervimm+bSqMS4/b9uKBK pProDX6fml8X1A0olMV95taNUSgNVfuwVj0n1E7rczo9TB78cOD84dpVpPzYNNRfu3XW rszqYERQvWXuu0kzuJO8aLCPZ6h8fWk/oKqGurgJ9kY7PsaLD5VG4H9+H9/JoQIzZzW8 bKUA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r15si13377400pfj.70.2017.05.30.04.48.52; Tue, 30 May 2017 04:48:52 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751569AbdE3Lsj (ORCPT + 25 others); Tue, 30 May 2017 07:48:39 -0400 Received: from mail-lf0-f48.google.com ([209.85.215.48]:34642 "EHLO mail-lf0-f48.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751511AbdE3Lsd (ORCPT ); Tue, 30 May 2017 07:48:33 -0400 Received: by mail-lf0-f48.google.com with SMTP id 99so47600235lfu.1 for ; Tue, 30 May 2017 04:48:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=PBWpj/7U9MtY+LBXiWGbu7EhpQ8b90eG02dNW19QSeQ=; b=J+xgxtBu6Ts4UCFYd/QSPySs4opbTyP2Kldrcv2PgqaFUJxart4B0a24tZZTWscam3 UaFrtFC5xyDl2lwg3BK9Q91avyACiCL76yLdSG+4n+20qCe0UZJAzReAqQt7L6q+nafH wi9p+PcCv79aPSFHpglnFEErbRW5NFsPC8elY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=PBWpj/7U9MtY+LBXiWGbu7EhpQ8b90eG02dNW19QSeQ=; b=TpQAO+BojQF1xLOSQeWW+3rXycNtkb7C9F5MaRqYTyLpJdvFKnPpY1rzQorRiD0Ikt 8d28dyTyQmh6W/kI/MMV5h0oXwXXQm8/kIsD+dcAEiv3y3B4WHQegaYkOTfIDgtxI6CE wQF9YJk26tRGa+dOO4+fcoASYBahs3WopJ7cP9+IrRGMyTA8Qs9Dj3jec6/Q5p4hM911 eorTAddjDzRmrbIo01Ivk1BQlr2SWNGVtlOEglPpw+pRiOVMEFCMMYBFmwXDWrZpyDH6 5O4bIC8iMHqp0ax8J/FG4VI7777zU4UTxG1RnqTnuSY/TCHgUqq5jrmmwDkhQzX1/N/T X/sA== X-Gm-Message-State: AODbwcB2+dGSj235WLMwibJEwvvTSMYTD6j0/8Y/Atc6CrdoqnTzP8lD ljKKPA9QVWdfe/SQ X-Received: by 10.25.208.14 with SMTP id h14mr5172258lfg.174.1496144912092; Tue, 30 May 2017 04:48:32 -0700 (PDT) Received: from fabina.bredbandsbolaget.se (c-9d7e71d5.014-348-6c756e10.cust.bredbandsbolaget.se. [213.113.126.157]) by smtp.gmail.com with ESMTPSA id z4sm2633554lfd.64.2017.05.30.04.48.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 30 May 2017 04:48:31 -0700 (PDT) From: Linus Walleij To: Lee Jones , Daniel Thompson , Jingoo Han , linux-kernel@vger.kernel.org Cc: Laurent Pinchart , Linus Walleij Subject: [PATCH 2/2 v2] backlight: gpio: delete pdata inversion Date: Tue, 30 May 2017 13:48:22 +0200 Message-Id: <20170530114822.24308-2-linus.walleij@linaro.org> X-Mailer: git-send-email 2.9.4 In-Reply-To: <20170530114822.24308-1-linus.walleij@linaro.org> References: <20170530114822.24308-1-linus.walleij@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The option to invert the output of the GPIO (active low) is not used by the only platform still using platform data to set up a GPIO backlight (one SH board). Delete the option as we do not expect to expand the use of board files for this driver, and GPIO descriptors intrinsically keep track of any signal inversion. Acked-by: Daniel Thompson Signed-off-by: Linus Walleij --- ChangeLog v1->v2: - Rebase on the v2 of patch [1/2] --- drivers/video/backlight/gpio_backlight.c | 15 ++------------- include/linux/platform_data/gpio_backlight.h | 1 - 2 files changed, 2 insertions(+), 14 deletions(-) -- 2.9.4 Reviewed-by: Laurent Pinchart diff --git a/drivers/video/backlight/gpio_backlight.c b/drivers/video/backlight/gpio_backlight.c index 5ffaff1e4142..e470da95d806 100644 --- a/drivers/video/backlight/gpio_backlight.c +++ b/drivers/video/backlight/gpio_backlight.c @@ -25,7 +25,6 @@ struct gpio_backlight { struct device *fbdev; struct gpio_desc *gpiod; - int active; int def_value; }; @@ -39,8 +38,7 @@ static int gpio_backlight_update_status(struct backlight_device *bl) bl->props.state & (BL_CORE_SUSPENDED | BL_CORE_FBBLANK)) brightness = 0; - gpiod_set_value_cansleep(gbl->gpiod, - brightness ? gbl->active : !gbl->active); + gpiod_set_value_cansleep(gbl->gpiod, brightness); return 0; } @@ -69,8 +67,6 @@ static int gpio_backlight_probe_dt(struct platform_device *pdev, gbl->def_value = of_property_read_bool(np, "default-on"); flags = gbl->def_value ? GPIOD_OUT_HIGH : GPIOD_OUT_LOW; - /* GPIO descriptors keep track of inversion */ - gbl->active = 1; gbl->gpiod = devm_gpiod_get(dev, NULL, flags); if (IS_ERR(gbl->gpiod)) { @@ -121,15 +117,8 @@ static int gpio_backlight_probe(struct platform_device *pdev) unsigned long flags = GPIOF_DIR_OUT; gbl->fbdev = pdata->fbdev; - gbl->active = pdata->active_low ? 0 : 1; gbl->def_value = pdata->def_value; - - if (gbl->active) - flags |= gbl->def_value ? - GPIOF_INIT_HIGH : GPIOF_INIT_LOW; - else - flags |= gbl->def_value ? - GPIOF_INIT_LOW : GPIOF_INIT_HIGH; + flags |= gbl->def_value ? GPIOF_INIT_HIGH : GPIOF_INIT_LOW; ret = devm_gpio_request_one(gbl->dev, pdata->gpio, flags, pdata ? pdata->name : "backlight"); diff --git a/include/linux/platform_data/gpio_backlight.h b/include/linux/platform_data/gpio_backlight.h index 5ae0d9c80d4d..683d90453c41 100644 --- a/include/linux/platform_data/gpio_backlight.h +++ b/include/linux/platform_data/gpio_backlight.h @@ -14,7 +14,6 @@ struct gpio_backlight_platform_data { struct device *fbdev; int gpio; int def_value; - bool active_low; const char *name; };