Received: by 2002:a25:824b:0:0:0:0:0 with SMTP id d11csp8276192ybn; Tue, 1 Oct 2019 06:00:36 -0700 (PDT) X-Google-Smtp-Source: APXvYqzeOfOZL5XiQNdYMuPnLGP46yYj/tWzrryXpIQwI0VUzjSVoCMF71ypDV6OYSrYJCM4ZALW X-Received: by 2002:a50:aa96:: with SMTP id q22mr25266623edc.179.1569934836493; Tue, 01 Oct 2019 06:00:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1569934836; cv=none; d=google.com; s=arc-20160816; b=RE0g2v2jdLSo6BHz9/1PbgqVVALqR9xfiwKCzHxFQfLHAIiQ55Z3dqH0kn1UrUbDGc ETD92LxhKeo7qBMVf6xMxrQilEUk8k7E3mTEx8IqL8OsBS3PRtBniNCcVpvl6l2n6Yci PuwZZCoou5mU/8dF1fOlV3NkBKFN1d9eEty5hFQ3J+fQjZ7PEDhfwwXwVE+XI5EeHI+S VqjULn9kRGijU6MY3lnRoZ1HHfm0v/3fSvq9lP8jEeiaabWZb7MTlQcufbcT8WRYxgow 3IDKanEVJLMJBKwLreTq6fB7TvMwPfiAOb89ojgyHoYTX/GDTeAHyFuvv7tFM2LHcIv3 e3KQ== 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=AptOB7aQMzupkvqKi0d1i4i7uXh0E5N7gRvX5FWeAOU=; b=nkm/0GCkET57x524OIIzu/6XNcggbmSy5igIl4ZA9JZuLyeJjZFKfvUL7VUkbRcxF9 uvLWOVHtj1Fz5y8bdwR9aurUCEEyFfV/HyBf2D017UKWYhcyMvYo0JGW51X6YGkRHwPF Ge0znl6YISlUg4hAW0CsdGKKsWkphbBcHCvp4hp7Lh2HQOcdDObjE0Cwr8cPjAi81VKM PB6/E9jod3u2xcQE+tBqKW4Qlu76TAOcfMwzPe2vwGjglB8ILnaa7dgGoUjkG8G9Zp9k OH8M8Cin/AhV7tEXA7c0TT43kR4o7B3K5pA60U8J3WdCS7EITXmx0VMEUx6O5bydLazB krnQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bgdev-pl.20150623.gappssmtp.com header.s=20150623 header.b="Mj8KL/3y"; 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 r18si8893690ejr.189.2019.10.01.06.00.11; Tue, 01 Oct 2019 06:00:36 -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="Mj8KL/3y"; 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 S2388192AbfJAM7n (ORCPT + 99 others); Tue, 1 Oct 2019 08:59:43 -0400 Received: from mail-wm1-f66.google.com ([209.85.128.66]:55140 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388212AbfJAM7f (ORCPT ); Tue, 1 Oct 2019 08:59:35 -0400 Received: by mail-wm1-f66.google.com with SMTP id p7so3274525wmp.4 for ; Tue, 01 Oct 2019 05:59:33 -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=AptOB7aQMzupkvqKi0d1i4i7uXh0E5N7gRvX5FWeAOU=; b=Mj8KL/3yO/+8pQR6hKmMxjehp8UsaQmJXB+50w4JFC0Jbpw/bv2KHHtQqu6BYcbZ0s GnstolGS0HMZooKY2nCYemYIsdaW8nlkyXolNB7aBZ2wQgg3+tC6mtqu6pxs7bjcCWXy 7cPPNplvd38z+flfRXABRtkSJsSPiN7w4B2Z5mXYR4SNSpvQjEYEP05z6/up9NkcTA3h r36ddCNTZVeEErft7TF+UYk0jwcNEJCYfaFm1PMfMF+x+dFlzVYdG6Dlz00VIYzPoksO 1NiE+Kx8avaQAi9fzsQecRgxXfikJ7hT2QJFzwEMqauBQWPwUJyenh0Ni5myYPeN0+5a veOQ== 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=AptOB7aQMzupkvqKi0d1i4i7uXh0E5N7gRvX5FWeAOU=; b=Ncj0aPNnwmQstFuWz2cM0Hsj/TeBgZBo0H/VMSvHlx8nNFMJXdZMYzHbyxqN3lal1H LeU+Nn/fba608XcRhJcggAiwn6f14La+yfJhzCXZ42cYO3AZHadFofET+GjEj1kVElKg s8dz3Frrb8hOwGC8YLjSHxN2nAbBLwB+qn3pfniRDGadK2BEtwU8oKRjIa6BPn7LDSGn EKXT15PPlYvmXc6h4kYFE8RxF9PSKvTInHRLc3hG+ZCDFcuCo8haj3Wx7vn5nUm9pLDS 90ZY38tXkg2zdmA69Gk5Y91ygDvbt2xVZgjmD0HSPMjieV4Rmimy9bEBasSLjXelXlPj TECg== X-Gm-Message-State: APjAAAWISnfzjqc+Y8tyet4hzh7LATC8g4/YwE56CEjlGiQ8N0i3tLeU O1EXNLg8Z+7TUQChnZItOnJIuQ== X-Received: by 2002:a1c:7d92:: with SMTP id y140mr3594356wmc.141.1569934773015; Tue, 01 Oct 2019 05:59:33 -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 3sm3561400wmo.22.2019.10.01.05.59.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Oct 2019 05:59:32 -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 v4 7/7] backlight: gpio: pull gpio_backlight_initial_power_state() into probe Date: Tue, 1 Oct 2019 14:58:37 +0200 Message-Id: <20191001125837.4472-8-brgl@bgdev.pl> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191001125837.4472-1-brgl@bgdev.pl> References: <20191001125837.4472-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 | 36 ++++++++---------------- 1 file changed, 12 insertions(+), 24 deletions(-) diff --git a/drivers/video/backlight/gpio_backlight.c b/drivers/video/backlight/gpio_backlight.c index 6247687b6330..37ec184f0c5c 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,15 @@ static int gpio_backlight_probe(struct platform_device *pdev) return PTR_ERR(bl); } - bl->props.power = gpio_backlight_initial_power_state(gbl); + /* Not booted with device tree or no phandle link to the node */ + if (!of_node || !of_node->phandle) + 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