Received: by 2002:a25:d7c1:0:0:0:0:0 with SMTP id o184csp1807578ybg; Sat, 19 Oct 2019 02:57:08 -0700 (PDT) X-Google-Smtp-Source: APXvYqxbhwbo12OlimhNxCbls4bOg5soxPJFPXhLxCEUXxMXq/OM49wamVMOF1uRfqIx3uOfhnUv X-Received: by 2002:a17:906:524b:: with SMTP id y11mr12356413ejm.82.1571479028161; Sat, 19 Oct 2019 02:57:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571479028; cv=none; d=google.com; s=arc-20160816; b=eXDkAs/2U56R5DmzBVvIFGvU0VJTWdwW6M2GwyNjc8M45pj2DL7o1hr7XsVib7iuke 8Pf8hQvl6R7umyGCnufeP9x7mN5mMxIy0/CA0zjMBNYyHrgP078l/pT3M7ZgLzJljNAq vKQ4helo+jR+OrDSDGf5pPK6+cbR578rsYxC8NjjCBeThRFFF/sYvTKRApXOFex8Qsqw ZqdQkJ6up7uTpyaNhbQvue5BHL8FmeOZ0S1rLjoRuVfsYaaFti3BHorzFU2kX0DonE+1 en5hZnUcZ/Dd4UJPM+Q70OHm6bTqzEI2AJ0in6FSsNLB7iAH5evg593ChpWlK7smrYlM 4Zdg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=+S1F9dGo/ErbKc+5MFUBRKg7ZKdxaGhAR9G3FlyzzL8=; b=nBk2YYHPsdEwqPDbp36YDjQ+8+HcOrY24WclP0//9HUw7weBMVyPLyGY+22pFpL1mV FHU7m88F5XaxM1cDTSuzRKD+oDz/C9nuryWRatzJIhtPA5Eef7PbvO0tGTW7DjK5oScF xiaXga+2Lz4IJw+FrsQsdQr+q+HZlEDi5K5O4EYax3SNp9lgE63nw25SmNgcSqLlUIkK N9fN3X0y2SgEXAC/Hg1DU9ACITpas3WK8Lk4Y2HDh45BaDjQk/cd3yyUIZ4yDzgkFhVU YE8P1QSJbTw/UAlCma5sCgXVAapZAb6pHVgtwpZEDOKeobozDOs20/nKp7AobYCn0dbR f8hg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bgdev-pl.20150623.gappssmtp.com header.s=20150623 header.b=0LLfhTrc; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g21si4784945ejk.23.2019.10.19.02.56.45; Sat, 19 Oct 2019 02:57:08 -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=@bgdev-pl.20150623.gappssmtp.com header.s=20150623 header.b=0LLfhTrc; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728357AbfJSIgT (ORCPT + 99 others); Sat, 19 Oct 2019 04:36:19 -0400 Received: from mail-wm1-f67.google.com ([209.85.128.67]:51272 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728310AbfJSIgP (ORCPT ); Sat, 19 Oct 2019 04:36:15 -0400 Received: by mail-wm1-f67.google.com with SMTP id q70so1183063wme.1 for ; Sat, 19 Oct 2019 01:36:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=+S1F9dGo/ErbKc+5MFUBRKg7ZKdxaGhAR9G3FlyzzL8=; b=0LLfhTrcJfkDD2KAFAf2MOHq0yJVpuFZpKnviLv848iy8t7hqY+CGdVLo3/g5BzAnP Vmh1RNwwivxdx6HOxcryCtVTIx1NP3zdU3hhJF4LXX8poyhw6UbZy12/dERrSdt7b5L9 TGO6h+x33e73YSGHYwVFplerlB38wTr663PRMwBBzMcgU2gIDpuQSYG5VDCkuoQh0T21 l4Tbe6CyZ6122rckrz/yK1AQZfrsa2U/DC2+ep4qqNVIvr2TqG5o4XGlnLdguOBzftfm DWBdQAc/YGRkHAthUyAoIVEN+OfKp5K8t/sUuhPJqeDIclC6LBHEW6SutvjPGJ3KyY7n K0DQ== 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:mime-version:content-transfer-encoding; bh=+S1F9dGo/ErbKc+5MFUBRKg7ZKdxaGhAR9G3FlyzzL8=; b=F0RgoyzrbDg82Qw6Dj/aVqSGOK/oXwZIZEyaqxBFwiImawv9GmJB9Ns4bY91XmJUgQ ublEid2X+nDnpQxfn4KdC7ZUhIIrauG7/GKEpnFylCifdg/r+vGxqgHwBVp+imS+Ghmo G5JATp6ngbzMIokeF/B7NL1U3O09fAV6Wv5AL3s5NpCyVIUd8BYnbxWRkLulWmZRnWQE qZa3g8AlsmQDH/n4NudcNOCoW+emv1rT0MFh2ntwZqIFER4ssq20Y2PlIq6Nw5l4Ft2F YH8FU9U8dhhNCI2/xtv3WaTZLrlH5LfXDM964Z1izgcYEms6k11T3aYXkUdi14LZ8X9S ATbw== X-Gm-Message-State: APjAAAXP0CINUKWhnI85/DEUaL29ymgrh2zsHLQUI85ns0tDZvczJIx2 Glc1FQpbB0Rsw08HaitG8xD10A== X-Received: by 2002:a1c:8157:: with SMTP id c84mr10602738wmd.56.1571474173411; Sat, 19 Oct 2019 01:36:13 -0700 (PDT) Received: from debian-brgl.home ([2a01:cb1d:af:5b00:6d6c:8493:1ab5:dad7]) by smtp.gmail.com with ESMTPSA id u1sm7242627wmc.38.2019.10.19.01.36.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 19 Oct 2019 01:36:12 -0700 (PDT) From: Bartosz Golaszewski To: Yoshinori Sato , Rich Felker , Lee Jones , Daniel Thompson , Jingoo Han , Bartlomiej Zolnierkiewicz , Linus Walleij , Andy Shevchenko , Jacopo Mondi Cc: linux-sh@vger.kernel.org, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-fbdev@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH v6 3/9] backlight: gpio: explicitly set the direction of the GPIO Date: Sat, 19 Oct 2019 10:35:50 +0200 Message-Id: <20191019083556.19466-4-brgl@bgdev.pl> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191019083556.19466-1-brgl@bgdev.pl> References: <20191019083556.19466-1-brgl@bgdev.pl> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Bartosz Golaszewski The GPIO backlight driver currently requests the line 'as is', without acively setting its direction. This can lead to problems: if the line is in input mode by default, we won't be able to drive it later when updating the status and also reading its initial value doesn't make sense for backlight setting. Request the line 'as is' initially, so that we can read its value without affecting it but then change the direction to output explicitly when setting the initial brightness. Also: check the current direction and only read the value if it's output. Signed-off-by: Bartosz Golaszewski --- drivers/video/backlight/gpio_backlight.c | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/drivers/video/backlight/gpio_backlight.c b/drivers/video/backlight/gpio_backlight.c index 3955b513f2f8..a36ac3a45b81 100644 --- a/drivers/video/backlight/gpio_backlight.c +++ b/drivers/video/backlight/gpio_backlight.c @@ -25,9 +25,8 @@ struct gpio_backlight { int def_value; }; -static int gpio_backlight_update_status(struct backlight_device *bl) +static int gpio_backlight_get_curr_brightness(struct backlight_device *bl) { - struct gpio_backlight *gbl = bl_get_data(bl); int brightness = bl->props.brightness; if (bl->props.power != FB_BLANK_UNBLANK || @@ -35,6 +34,14 @@ static int gpio_backlight_update_status(struct backlight_device *bl) bl->props.state & (BL_CORE_SUSPENDED | BL_CORE_FBBLANK)) brightness = 0; + return brightness; +} + +static int gpio_backlight_update_status(struct backlight_device *bl) +{ + struct gpio_backlight *gbl = bl_get_data(bl); + int brightness = gpio_backlight_get_curr_brightness(bl); + gpiod_set_value_cansleep(gbl->gpiod, brightness); return 0; @@ -85,7 +92,8 @@ static int gpio_backlight_initial_power_state(struct gpio_backlight *gbl) return gbl->def_value ? FB_BLANK_UNBLANK : FB_BLANK_POWERDOWN; /* if the enable GPIO is disabled, do not enable the backlight */ - if (gpiod_get_value_cansleep(gbl->gpiod) == 0) + if (gpiod_get_direction(gbl->gpiod) == 0 && + gpiod_get_value_cansleep(gbl->gpiod) == 0) return FB_BLANK_POWERDOWN; return FB_BLANK_UNBLANK; @@ -98,7 +106,7 @@ static int gpio_backlight_probe(struct platform_device *pdev) struct backlight_properties props; struct backlight_device *bl; struct gpio_backlight *gbl; - int ret; + int ret, init_brightness; gbl = devm_kzalloc(&pdev->dev, sizeof(*gbl), GFP_KERNEL); if (gbl == NULL) @@ -151,7 +159,12 @@ static int gpio_backlight_probe(struct platform_device *pdev) bl->props.power = gpio_backlight_initial_power_state(gbl); bl->props.brightness = 1; - backlight_update_status(bl); + init_brightness = gpio_backlight_get_curr_brightness(bl); + ret = gpiod_direction_output(gbl->gpiod, init_brightness); + if (ret) { + dev_err(&pdev->dev, "failed to set initial brightness\n"); + return ret; + } platform_set_drvdata(pdev, bl); return 0; -- 2.23.0