Received: by 2002:a25:d7c1:0:0:0:0:0 with SMTP id o184csp5437015ybg; Tue, 22 Oct 2019 03:17:39 -0700 (PDT) X-Google-Smtp-Source: APXvYqxNI3lUwLQa9b27kR0vUkjZOvrKX7zrG+b6skyEKZfKotz/8/EbAt3K95vp6iNIxuSH0reb X-Received: by 2002:a50:9269:: with SMTP id j38mr12057014eda.5.1571739459321; Tue, 22 Oct 2019 03:17:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571739459; cv=none; d=google.com; s=arc-20160816; b=B28e6VNn/mPS1wZBtMTqxMfgqCE68qDpsAvT+/EgagMt1JFs+Hq/vZT6jbeOE/bLbJ c3A1/mdfOKTDR8oKXQ5iEbBSoJgOyQzOubv3aD+iN6hJ6aMVwNkdHAiAl2qWiJt89EsI 9agW1Re6XOmpknCkZhMkEHTXm/o0thAj0rtgzZ9zPsVrVOZMj/092VR2eyjqefCM+nKq pH1aPuHG8tFNhhyfm85QIpaMudnQbABpZgFtZ0GftyX5/TREQ0y5V68FTyYSDnpEPUpy w46G/3EABNevmUEVNMdZB7+aQdvyRd8HphVIBheL93IWD3dfR/88ZwCiy7GcMmjGzzbc i69Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=Ecp7w/hJmXBVWFySg3KpzIRhvM49DSx8lFHehzy7hk0=; b=0Ux7LwqfPfAfbEIoDRg5xMD+lEReqJPj/stTRqrKF845YC8mEdmJPk6JoHv6bf9ocr wN1t0Oue1adVVh6puhrYHwCPKMOhurBwaxEb81foiYo7f86N8EOR/4moruKc/lTDnEqK Odlh7cjip7n4DaRKmXj24D+fY8d8D+KqO5WZwrWJPTHGMVdLHOYsewBPpXDRLmMYGAjI q3YztSY9Cc5l3l7o+TaeIVwm4valKGUxSNtXyO6Emn268udTkqz/TGvMO66IQQfeTvCz h+7GcLeITNT8W04/9qchpVaHd0drpZg2oUN3sMm+umvw7uUmT6fYHM1t1fcHW5unsmqZ Tq/w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=fRFiFu91; 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 17si9773010ejt.419.2019.10.22.03.17.15; Tue, 22 Oct 2019 03:17:39 -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 header.s=google header.b=fRFiFu91; 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 S1731743AbfJVKOW (ORCPT + 99 others); Tue, 22 Oct 2019 06:14:22 -0400 Received: from mail-wr1-f67.google.com ([209.85.221.67]:41783 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727101AbfJVKOW (ORCPT ); Tue, 22 Oct 2019 06:14:22 -0400 Received: by mail-wr1-f67.google.com with SMTP id p4so17371833wrm.8 for ; Tue, 22 Oct 2019 03:14:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=Ecp7w/hJmXBVWFySg3KpzIRhvM49DSx8lFHehzy7hk0=; b=fRFiFu9115aCE+SgtQZi4fJ3gGrz7s99XoenJ0ll+4BbNyYVHfehhS/TgSO8/MNxiK wwecmTwAPsjrc+Hj/hgjLWz11X+sweN1cPESRp41Q150VwGfLDHW1SmKZMk8JZPJTXs7 3SV6wGOX1b5QOcslTm2aou+1oRmAwbePg1zZZYbqzBdSNMhHb/ParUdwX0haH4Sf4COA VgW0Q8mE9zp4LoCF0PT/p9QoFC9Ox4117lV60UZCcmcZi78FU5qPf316/I5JCC2/VZPR 3rRBedVtPBkiORU65dNmroqlaRDNYzYYJcPqrbW3vT+Y3sAigm1A2YxAi91Jv/+NZvvj PbTg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=Ecp7w/hJmXBVWFySg3KpzIRhvM49DSx8lFHehzy7hk0=; b=niTmHPELKSegksMpgblmGCPk0N9fgujESavtew1dTbUbDzO9x56LsXdGPsGT1nivp1 H57fxe2mbBZMWgFrRxtfFg1YcZLbvzBESMkfXfmYlXKQbEbenS25+XYRc3YfhFv+x4+f mU9Rk6JJ9r0a3NwHkakv+Cf8plx7PXkQK4FemnhG8HkGNOQsVvxKQ/lmeoBYmfF9MeRS D10MXMhD9diRfxoxDFjUYTRwJAewa4w1tiNCJ40/0vXDsC2TEzpkHOu4jOJcvpaBL8Z2 RGY8Ky6dTtYj34Q50pLzXLDZZVPJInIs6ayJfKubgOhqy2PsvXdpi2amNbJnToa3QwDo EwjA== X-Gm-Message-State: APjAAAVXfjgq6xOXIX2h9i3C2/5a6L9c/2/jY8s1atLZsmyOuRCGjipu LmoAiwVmwS2jhY9duGkNTIBR7A== X-Received: by 2002:a05:6000:1288:: with SMTP id f8mr2667048wrx.111.1571739259892; Tue, 22 Oct 2019 03:14:19 -0700 (PDT) Received: from holly.lan (cpc141214-aztw34-2-0-cust773.18-1.cable.virginm.net. [86.9.19.6]) by smtp.gmail.com with ESMTPSA id l7sm8333986wro.17.2019.10.22.03.14.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Oct 2019 03:14:19 -0700 (PDT) Date: Tue, 22 Oct 2019 11:14:17 +0100 From: Daniel Thompson To: Bartosz Golaszewski Cc: Yoshinori Sato , Rich Felker , Lee Jones , Jingoo Han , Bartlomiej Zolnierkiewicz , Linus Walleij , Andy Shevchenko , Jacopo Mondi , linux-sh@vger.kernel.org, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-fbdev@vger.kernel.org, Bartosz Golaszewski Subject: Re: [PATCH v7 3/9] backlight: gpio: explicitly set the direction of the GPIO Message-ID: <20191022101417.24zkd3htnyfg3hy6@holly.lan> References: <20191022083630.28175-1-brgl@bgdev.pl> <20191022083630.28175-4-brgl@bgdev.pl> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20191022083630.28175-4-brgl@bgdev.pl> User-Agent: NeoMutt/20180716 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Oct 22, 2019 at 10:36:24AM +0200, Bartosz Golaszewski wrote: > 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 Reviewed-by: Daniel Thompson > --- > 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..52f17c9ca1c3 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_next_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_next_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_next_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 >