Received: by 2002:a25:d7c1:0:0:0:0:0 with SMTP id o184csp5346955ybg; Tue, 22 Oct 2019 01:39:07 -0700 (PDT) X-Google-Smtp-Source: APXvYqw+0bB9L8R74ZvnPMENSFPBVZwTV52rWf94SloApC4QdLf6bll/NecNpHB1ibYk5HZU+dul X-Received: by 2002:a17:906:2cd2:: with SMTP id r18mr26054365ejr.282.1571733547828; Tue, 22 Oct 2019 01:39:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571733547; cv=none; d=google.com; s=arc-20160816; b=ngB5PpzmL3LnyK3GgS/njb4O8aD1eSO9P5RQ1cGH+pZas5giYtvSt0sU47jFCQxe8D 3ZTBxXqG9iym5QOpmbl8UD7k6i6OpnXInRau8ZmVJsKA61/9qx41DSLnPu4QqjhtfU8y J5GzqhnYR+UCYFkzNKCerFt9/AFyd8O7T+mTUOGoA2gHoar2xtqkuLml+cCGG0pZX02s HLjbEoDEGVG4cZhHkxKqGN7WHxmg1Y8fWKPLAd/98p3ccuF+yUbCtaLXA5WDK0FCzNrC f7R4CLy+WSRYL+cHbM+Q5Zuq8rrliqKFRs5UzoDom2urv4P5qbrRntRllHKA8Nq5AMqJ h6pg== 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=OjHvv8ZdSVaFl2j34zmQMRFMhFwh+26xUwIofDUAWMQ=; b=ZHHg79ZL9/FMb0Qt4UDedv+WW9rIqqj2rTqkBqlobHAH5rOCHA+U8eMIBJLb6geZ1W 3rqbgp/XbnPzaKlFAwZ4ZETy+Pq2RUwzN7BsTPqMgMVlYx6rvU4yNrvp/pMoTV4Dg0ET WD+RMyTIzgX/aU+Y8j+KclgjA8KsHJUIAMitIQOr/4tc64E4mHRM1wyyemVyn5/mA3Eq 9+2/j4fKaLgTXtS55W3HLpJtDd40RmDdwjxoJpKbnAZv/vGDk83VlFwSjw7V0mqNA5CK fmJmcyrevZLhXwi/9N/pMJ9Dpvrcei48/2FMzKVhsGWWWnOV+ZqrOZ5dZzFHsd0xOll0 OAbg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bgdev-pl.20150623.gappssmtp.com header.s=20150623 header.b=UkLVmhIa; 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 h12si2730276ejd.17.2019.10.22.01.38.43; Tue, 22 Oct 2019 01:39:07 -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=UkLVmhIa; 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 S1731365AbfJVIhN (ORCPT + 99 others); Tue, 22 Oct 2019 04:37:13 -0400 Received: from mail-wm1-f68.google.com ([209.85.128.68]:39314 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388329AbfJVIgm (ORCPT ); Tue, 22 Oct 2019 04:36:42 -0400 Received: by mail-wm1-f68.google.com with SMTP id r141so5676416wme.4 for ; Tue, 22 Oct 2019 01:36:40 -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=OjHvv8ZdSVaFl2j34zmQMRFMhFwh+26xUwIofDUAWMQ=; b=UkLVmhIaiNsxcswxRm7saAjEeStKBBF+NXde2AaAQaH3O4OXrI2JqpEeNiYtx1tT4k O3tmDJV08ouTAT18mpcXHM49waszOD09C3kcJoqJ1K3QN1xmklwP/eU7Hi3Da1KpH6+p xHzUd7cW8tvQpL0LdK8EzIbsEydpnZXp6EgfJ09/AxanR8iqfgD2W5clxItpQ1XlxvE1 Y3NivMmlc1FI2uZ+h4mjPDpGg07DcZC5wE4UFYAR5q7HGQNTlYTFiD5P+jRs/sNoqlfW 5Afs8sR94u+Uqox3JbfZuJfuKgrV7Pd2SzSCLdqv7UzJb6rRU5U+dBwxaIfjR8LqHfw9 VMTA== 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=OjHvv8ZdSVaFl2j34zmQMRFMhFwh+26xUwIofDUAWMQ=; b=M2hEhzcGiwT5wTswHU3pF9s5JvCdwvcPg5ESjX9NOHO2dqKquIgLaCaOp/mOHOJ9Ii HGsylaSdjQ3xEjgf20YcCobBDhGWJSlvthFNkn9cOD4d0wWC0By8whbKSPNte4P33E0f ZfoJDLphkyy43Q1z6pytlf3KWwG9mjoIOnstDaMiDk/9/UgYI89lfNmD8vdnxc/pAuqO QxbX7ngBgjYpbqhWofdRyDwul6Lvcqlx5uGNwhZJnpAUFK7570JqYdW8P65rkAmXkBx0 e4Jmg24kIZ1Qbm5Fcc2nczrgGwBXaT3vvIm4mA7dXUhN8uan4Mu2xc0M2PORyhEkWFcN GRgQ== X-Gm-Message-State: APjAAAUH+IdUjtyDh9WQQgvGQb8AQuUrBjK5+ITizUCt7KFpiCyZ8UnW 6/cO8Ctnr04RMkUEKoJOMKCQzRV8LEY= X-Received: by 2002:a7b:cb03:: with SMTP id u3mr1840598wmj.126.1571733399937; Tue, 22 Oct 2019 01:36:39 -0700 (PDT) Received: from localhost.localdomain (amontpellier-652-1-281-69.w109-210.abo.wanadoo.fr. [109.210.96.69]) by smtp.gmail.com with ESMTPSA id g17sm17115253wrq.58.2019.10.22.01.36.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Oct 2019 01:36:39 -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 v7 3/9] backlight: gpio: explicitly set the direction of the GPIO Date: Tue, 22 Oct 2019 10:36:24 +0200 Message-Id: <20191022083630.28175-4-brgl@bgdev.pl> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191022083630.28175-1-brgl@bgdev.pl> References: <20191022083630.28175-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..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