From patchwork Sun Apr 30 08:17:31 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 98387 Delivered-To: patch@linaro.org Received: by 10.140.109.52 with SMTP id k49csp962315qgf; Sun, 30 Apr 2017 01:18:29 -0700 (PDT) X-Received: by 10.84.128.99 with SMTP id 90mr26275717pla.166.1493540309759; Sun, 30 Apr 2017 01:18:29 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l17si10979552pgj.292.2017.04.30.01.18.29; Sun, 30 Apr 2017 01:18:29 -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 S1167128AbdD3IRv (ORCPT + 25 others); Sun, 30 Apr 2017 04:17:51 -0400 Received: from mail-lf0-f50.google.com ([209.85.215.50]:35040 "EHLO mail-lf0-f50.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1167087AbdD3IRm (ORCPT ); Sun, 30 Apr 2017 04:17:42 -0400 Received: by mail-lf0-f50.google.com with SMTP id 75so50558975lfs.2 for ; Sun, 30 Apr 2017 01:17:41 -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=RQdpfJlma1F+3+aOWe43q4qMdY8oC//UTK4NruJ1cQ4=; b=dBtwLJDC39Xta909oDq4I38V2VNx7luWd3HI1RQplbEnk3/SBBuTswlfHpB+Y4qyv3 oWTeOA603U93s2cqWDJ0INcAd1HJBPWRfDNFvYG+qFZvaQC01ZtYtxXf1cmELwaCXvOU DrSn8pnQxaWTR/EZLNhTp1tDENX54vPsVOoeA= 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=RQdpfJlma1F+3+aOWe43q4qMdY8oC//UTK4NruJ1cQ4=; b=Sys+L6WIjy553/JuJjICKRZta1gpcfPkTiBZRKnCsYqyWaGTJQFN0QoituBIP+Mixi hYHwE+xbQzjESs7ZOdgbeeGUBiLP/q8eB63OTZDOvaTF3BqO5QC7H4eKZ48DnQyq+pcD qDnH+UiPGz4CXBIoTdefexppitryZ/Zj95709ajmIVSV6dk4OCXFy8W4ikfzPua451+U HD4SsXUNKvbPqyqLIhceJAtZpjT1jQ0CI9XobL9aaqJBOFOdhEajwy5mW4WscUALrY8C jDO4w34Iqb8dR1UaSnwmw0v6NCa6kDeHatzdNKxhdKvxJOvvrlq43TkF2SwDmsbKLVJN T2cg== X-Gm-Message-State: AN3rC/50KpGuA8uykRtBC4+He+fGFJxzRch+KvR9CI2fAtxT0yGu8f68 LidrA4YakvFbB/RD X-Received: by 10.25.193.205 with SMTP id r196mr5616423lff.127.1493540260250; Sun, 30 Apr 2017 01:17:40 -0700 (PDT) Received: from fabina.bredbandsbolaget.se (c-d67b71d5.014-348-6c756e10.cust.bredbandsbolaget.se. [213.113.123.214]) by smtp.gmail.com with ESMTPSA id t6sm2018101lfd.44.2017.04.30.01.17.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 30 Apr 2017 01:17:38 -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] backlight: gpio: Convert to use GPIO descriptor Date: Sun, 30 Apr 2017 10:17:31 +0200 Message-Id: <20170430081731.14315-1-linus.walleij@linaro.org> X-Mailer: git-send-email 2.9.3 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. Signed-off-by: Linus Walleij --- drivers/video/backlight/gpio_backlight.c | 74 ++++++++++++++++++++------------ 1 file changed, 46 insertions(+), 28 deletions(-) -- 2.9.3 Acked-by: Daniel Thompson diff --git a/drivers/video/backlight/gpio_backlight.c b/drivers/video/backlight/gpio_backlight.c index 18134416b154..17dd8071ad4d 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,30 @@ 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"); + if (gbl->def_value) + flags = GPIOD_OUT_HIGH; + else + flags = 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 +97,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 +116,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));