Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp3791684ybp; Sun, 6 Oct 2019 20:33:03 -0700 (PDT) X-Google-Smtp-Source: APXvYqwjbC/5pJjSoNzNC4BnrtC/jJXubiztNZcz7vo5bawi043MtlRLCyl05pExaaPtNEZrBPwO X-Received: by 2002:aa7:d313:: with SMTP id p19mr26623450edq.197.1570419183859; Sun, 06 Oct 2019 20:33:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570419183; cv=none; d=google.com; s=arc-20160816; b=hgpm86YUTpwWBSBW+Jgo+9kBm+djuPiR1BH86B1/afClsXAiZT9uxpxTJWS47OtUus F+CP49KEeS6pYw5HSYzfXm4tBG1bhDW+pZ9P8y5OU+ka5THUZEoXwAQkkNjssJKanPD3 2reCx3igAn6P0TO7HBejLQqZbXW+FLbfrfLSbVw5hksB7f2jBlYq3wvrf9O7hoo9uk7k et+3XWawAzwiBRVWND5HeiNOycPzVq6bg8RQh/W7Ph4GPVtUNs9fwz+/xGzb1h2Xj+P1 TZPoTunhswNxF3rgzOve5wYr4if3RbOgh1zQYe9XfbM//F9CLIbFm8qZOxk/aZ0wxeSo gCSw== 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=v4a+pKVTYSrGaRJIHf88S7PAjoi+WG4Wfk9hIUcxXSg=; b=qkVvPk8lGgFoJJ5Ci0FNwGcwYAwKERORFImc8xzPr3R04zK430MbVEgZWEG7UFMEqh YIMtR92wB1BueFpbNcnaG43KSXpFuyxinsni31oDuqxmQIaT/ibiF6voTQwPGfEQGc5I 2BoavmipFehJhHOsSsp1W6kMPxI5fZNh3ut+3/CCyKyfkxdBcwPnXx7SfP4zFQo+4Sm7 o+nKZ4AY3TXCpS9l+6rNJ8WAJZSsgGN3jaYsrYI/S+u0jBW7uBXNlZK7bweERLlWCmxV aCkOESDA2NOoqHjQQ9aKY504zZwr+F7tsc7I5q9+Xdj1QwyyH1qmIUUyXmS7ebLpl7Oy 35IQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bgdev-pl.20150623.gappssmtp.com header.s=20150623 header.b=VEhWSNZo; 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 d3si6609196ejw.31.2019.10.06.20.32.40; Sun, 06 Oct 2019 20:33:03 -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=VEhWSNZo; 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 S1727281AbfJGDcS (ORCPT + 99 others); Sun, 6 Oct 2019 23:32:18 -0400 Received: from mail-pf1-f194.google.com ([209.85.210.194]:35358 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727258AbfJGDcO (ORCPT ); Sun, 6 Oct 2019 23:32:14 -0400 Received: by mail-pf1-f194.google.com with SMTP id 205so7749691pfw.2 for ; Sun, 06 Oct 2019 20:32:12 -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=v4a+pKVTYSrGaRJIHf88S7PAjoi+WG4Wfk9hIUcxXSg=; b=VEhWSNZoLO5WHHbpp9caxeGXuImosevibbsBdB/CmdKiB1x1QaJiw3PM+vtD47onTj YnRJWOaxfiYOZMGKnNbIAnpk+Lkq3FitSuXfKNWTeVjsYnLhroWVQs+X9ZiUO38IcwTd rYYrkk7IaNSq5w6fCEOUfRmZ9UZ8BXM1z/VvKLUdDa5+ITtgJ6i795wC/Ax32hcUvskA 5XpcsN84YILPA2nLpfRifCQHKvAQu0rAFy8Ro1p1OrvG8Ax57GMGJEO+PYc96po6eCAp 6cQLwl1Rsh7FmaNNg7cNvfCg8BiyO0ggdLaZlKDi4Ouwzk9EVF/CUd28ES5S5X3zjTX3 ccJw== 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=v4a+pKVTYSrGaRJIHf88S7PAjoi+WG4Wfk9hIUcxXSg=; b=XCnpewz71gXA6AzegQFNKkAfl8Tq7ftxcet8rfgTUbmm4Ix8AA0uirViYsjMqBZ7eu OOaXMaL9pmtbD0d62YxcdFHPpCdArWKIWq2j9VAb/B9VmO1ZvrOTtdOkNdoz5GQ9gB53 m20+4U6jVvt9BlE6GEPzFJvtMYcSnyPxUxrPKtdmJTl/Ks9VZNILBYv7/gTtjJc6pHO9 brXsFDb0jKCIp7882hMWultBSqThk9XAGEdSs3YD9ENIuXmXHiwFEIctv2JTiuwcg7yw lKn94mS/BK/zlTZVdWBeRYcX8eVcAvJEIuGCL1DmTVPBeC6D+t8z7pWN8dYm/XQb/N9d rGHQ== X-Gm-Message-State: APjAAAWtM45KqSfj4+xx1f8ZvkI/xXQqOZSpvWHfzy4E3cYK1NsjdmV7 XIQBfGf4rSoUUvBMGi9frxUNIQ== X-Received: by 2002:a63:705b:: with SMTP id a27mr27756444pgn.136.1570419132502; Sun, 06 Oct 2019 20:32:12 -0700 (PDT) Received: from debian-brgl.local (96-95-220-76-static.hfc.comcastbusiness.net. [96.95.220.76]) by smtp.gmail.com with ESMTPSA id x10sm16377720pfr.44.2019.10.06.20.32.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 06 Oct 2019 20:32: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 v5 7/7] backlight: gpio: pull gpio_backlight_initial_power_state() into probe Date: Mon, 7 Oct 2019 05:32:00 +0200 Message-Id: <20191007033200.13443-8-brgl@bgdev.pl> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191007033200.13443-1-brgl@bgdev.pl> References: <20191007033200.13443-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 probe function in the gpio-backlight driver is quite short. If we pull gpio_backlight_initial_power_state() into probe we can drop two more fields from struct gpio_backlight and shrink the driver code. Signed-off-by: Bartosz Golaszewski --- drivers/video/backlight/gpio_backlight.c | 37 +++++++++--------------- 1 file changed, 13 insertions(+), 24 deletions(-) diff --git a/drivers/video/backlight/gpio_backlight.c b/drivers/video/backlight/gpio_backlight.c index 6247687b6330..407d4eaafc5c 100644 --- a/drivers/video/backlight/gpio_backlight.c +++ b/drivers/video/backlight/gpio_backlight.c @@ -17,11 +17,8 @@ #include struct gpio_backlight { - struct device *dev; struct device *fbdev; - struct gpio_desc *gpiod; - int def_value; }; static int gpio_backlight_update_status(struct backlight_device *bl) @@ -53,41 +50,24 @@ static const struct backlight_ops gpio_backlight_ops = { .check_fb = gpio_backlight_check_fb, }; -static int gpio_backlight_initial_power_state(struct gpio_backlight *gbl) -{ - struct device_node *node = gbl->dev->of_node; - - /* Not booted with device tree or no phandle link to the node */ - if (!node || !node->phandle) - 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) - return FB_BLANK_POWERDOWN; - - return FB_BLANK_UNBLANK; -} - - static int gpio_backlight_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; struct gpio_backlight_platform_data *pdata = dev_get_platdata(dev); + struct device_node *of_node = dev->of_node; struct backlight_properties props; struct backlight_device *bl; struct gpio_backlight *gbl; - int ret; + int ret, def_value; gbl = devm_kzalloc(dev, sizeof(*gbl), GFP_KERNEL); if (gbl == NULL) return -ENOMEM; - gbl->dev = dev; - if (pdata) gbl->fbdev = pdata->fbdev; - gbl->def_value = device_property_read_bool(dev, "default-on"); + def_value = device_property_read_bool(dev, "default-on"); gbl->gpiod = devm_gpiod_get(dev, NULL, GPIOD_ASIS); if (IS_ERR(gbl->gpiod)) { @@ -109,7 +89,16 @@ static int gpio_backlight_probe(struct platform_device *pdev) return PTR_ERR(bl); } - bl->props.power = gpio_backlight_initial_power_state(gbl); + /* Set the initial power state */ + if (!of_node || !of_node->phandle) + /* Not booted with device tree or no phandle link to the node */ + bl->props.power = def_value ? FB_BLANK_UNBLANK + : FB_BLANK_POWERDOWN; + else if (gpiod_get_value_cansleep(gbl->gpiod) == 0) + bl->props.power = FB_BLANK_POWERDOWN; + else + bl->props.power = FB_BLANK_UNBLANK; + bl->props.brightness = 1; backlight_update_status(bl); -- 2.23.0