Received: by 2002:a25:824b:0:0:0:0:0 with SMTP id d11csp727946ybn; Wed, 2 Oct 2019 05:21:26 -0700 (PDT) X-Google-Smtp-Source: APXvYqzWhJYNo31q9s042SXiC0UNlRLOuZD1+WY1vNP6e1VU0CHx7SON4nG3GapxP2DBfyjz8t4H X-Received: by 2002:a17:906:2ec8:: with SMTP id s8mr2821495eji.275.1570018886728; Wed, 02 Oct 2019 05:21:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570018886; cv=none; d=google.com; s=arc-20160816; b=sH6LArGY8t30CMJ8+1wZ8jtkH5vUPMB1IyfH57t+4F4n5Q89aEY3KxCZfdR9Lx+sd9 Bpvpw5CgvL54Ydn/XJmEUkk17uS2gsgSMvVhXKoQ+cShzWj67bt4DLagedN9pm2gaOaR ifIj6KIMuDbonBQIpWJFwUc4q2QZyDFbpZDy90kiIYxqNC03a/L0azlCCRlGp1DNMoP3 LrSlVUhUIOyNW98SubBfk/EWG4vkVq0ar5hbEBm3wvHFilAaNpy6c/wnqRC8Ke8AAes2 NsYehvsxX/+C/Cl7G+tO7Dz43Q+Iua88L0hVmZp4G7/sPeoTJAvRUi7KKdDIyWznnamZ O2HA== 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:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=Lh5QxEdgvHoHF5Kz6XaPdjsoiPWGW9FM0Kf+u5LlWyg=; b=RE1OOET4P7zzJXxUbbFJ3J9p2VF9zuK5rRyWUOJpOBhNbGMCfVT/l0ftVNtXDmwqC6 KE3yKGWR6mEg3Dx2FOy023KdUrjldeG45aydgDQD6X0f4CwVar1ySA+I3avVilvnLDhX 2NqFdEzpZx7i0tokzQerxDlZQWEyj22tqMvatWvGFQcA8dJF7uHIB2NAejG+9qElanLD UUdrD354D+bAo20JXArG7dimFQDqJ8E4efLxCliZKiGxtCKcUjamb9s5eTcr+GQkx+o4 yk3Oe/FCp4OqNUBqm9dM3ZFBXeZlDz2lgYVx37+uHdtZSbNa5rW1SFXSpRjjTqOJJt3r 100Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bgdev-pl.20150623.gappssmtp.com header.s=20150623 header.b=Q5Qfdh7f; 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 u21si10827992ejt.345.2019.10.02.05.21.02; Wed, 02 Oct 2019 05:21:26 -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=Q5Qfdh7f; 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 S1727523AbfJBLqa (ORCPT + 99 others); Wed, 2 Oct 2019 07:46:30 -0400 Received: from mail-io1-f68.google.com ([209.85.166.68]:39338 "EHLO mail-io1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727278AbfJBLq3 (ORCPT ); Wed, 2 Oct 2019 07:46:29 -0400 Received: by mail-io1-f68.google.com with SMTP id a1so56154104ioc.6 for ; Wed, 02 Oct 2019 04:46:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=Lh5QxEdgvHoHF5Kz6XaPdjsoiPWGW9FM0Kf+u5LlWyg=; b=Q5Qfdh7fI7j00zuYn+3Gvvh3U82Zj6uRr+9t+BfK+QrN6GksTsq1TtHlWVSl3DUc/+ KICkXd3QUhZFpe0w3wAfln7jgkv7gbMfFyG9fjM2V98eIGe3r3Gng/xkExa+eJEFFilu E15hdttybPJelTM62xKCQWTnZbv7QjtcbEnLaCqCktZpjN59SdX2dYOtnQ/wc+v0t2zu Z60M1o7opM5Y6bF/275R2KooX4xy51xnRv1hzx06KJKXKTdmdvkrexBDIvQoo7fX23JK JdQfSCs2jHEui+2UrN44EqlEtaVfgEtssfzfXCF4hdHKwb59nnOUY2wEhzYHMnDt+aS1 bpmw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=Lh5QxEdgvHoHF5Kz6XaPdjsoiPWGW9FM0Kf+u5LlWyg=; b=i6fPoOGqAJI1x50AZ1y6XPrpA75wxZoijCTQf2C+WWgulkDIwdlIbXJfYggIvRrEVw XWvOxVE/MbOFdFaUwbQ2oFfEza5oVTvU3BgvMWcR5cHj46mXa1m4pKU1auPtIxjDn0Qn SMTDos1WYbSrD3HkdX0YRs3oexbsFVHLiPlh1ChkYshXDPzAmij8RzUlTmNlxTxM5PfK NQpiZqmk2iMO2mk+6apBzSONoxxYyVNzljk39c0Fdsj8DWBUeTwgYu6xTqfJmnYx16VI /UCnvNnVRw5epQ0L3pmIMjZsnR6FPCC6c2mDMGy8z4YaMjVmvsBL4OO5jgfDBdj+20hn KVEA== X-Gm-Message-State: APjAAAUibn9zbRwXCJ1CSQ8AxkOlMEtilRi36KjBFQvv0eclkaZCRFfo ZmUu3oHri4YwAb58DPRzAEjId8GmYdemS8QuYwc75A== X-Received: by 2002:a5d:8911:: with SMTP id b17mr2872420ion.287.1570016788323; Wed, 02 Oct 2019 04:46:28 -0700 (PDT) MIME-Version: 1.0 References: <20191001125837.4472-1-brgl@bgdev.pl> <20191001125837.4472-8-brgl@bgdev.pl> <20191002103318.6owxberhml6mbtxm@holly.lan> In-Reply-To: <20191002103318.6owxberhml6mbtxm@holly.lan> From: Bartosz Golaszewski Date: Wed, 2 Oct 2019 13:46:17 +0200 Message-ID: Subject: Re: [PATCH v4 7/7] backlight: gpio: pull gpio_backlight_initial_power_state() into probe To: Daniel Thompson Cc: Yoshinori Sato , Rich Felker , Lee Jones , Jingoo Han , Bartlomiej Zolnierkiewicz , Linus Walleij , Andy Shevchenko , Jacopo Mondi , linux-sh@vger.kernel.org, Linux Kernel Mailing List , dri-devel@lists.freedesktop.org, linux-fbdev@vger.kernel.org, Bartosz Golaszewski Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org =C5=9Br., 2 pa=C5=BA 2019 o 12:33 Daniel Thompson napisa=C5=82(a): > > On Tue, Oct 01, 2019 at 02:58:37PM +0200, Bartosz Golaszewski wrote: > > 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/b= acklight/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_op= s =3D { > > .check_fb =3D gpio_backlight_check_fb, > > }; > > > > -static int gpio_backlight_initial_power_state(struct gpio_backlight *g= bl) > > I'm inclined to view deleting this function as removing a comment (e.g. > the function name helps us to read the code)! > Right, but why not just add a comment then? The probe function is 50 lines long, there's really no need to split it. This will get inlined anyway too. Bart > Removing the variables from the context structure is good but why not > just pass them to the function and let the compiler decided whether or > not to inline. > > > Daniel. > > > > -{ > > - struct device_node *node =3D 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_POWER= DOWN; > > - > > - /* if the enable GPIO is disabled, do not enable the backlight */ > > - if (gpiod_get_value_cansleep(gbl->gpiod) =3D=3D 0) > > - return FB_BLANK_POWERDOWN; > > - > > - return FB_BLANK_UNBLANK; > > -} > > - > > - > > static int gpio_backlight_probe(struct platform_device *pdev) > > { > > struct device *dev =3D &pdev->dev; > > struct gpio_backlight_platform_data *pdata =3D dev_get_platdata(d= ev); > > + struct device_node *of_node =3D dev->of_node; > > struct backlight_properties props; > > struct backlight_device *bl; > > struct gpio_backlight *gbl; > > - int ret; > > + int ret, def_value; > > > > gbl =3D devm_kzalloc(dev, sizeof(*gbl), GFP_KERNEL); > > if (gbl =3D=3D NULL) > > return -ENOMEM; > > > > - gbl->dev =3D dev; > > - > > if (pdata) > > gbl->fbdev =3D pdata->fbdev; > > > > - gbl->def_value =3D device_property_read_bool(dev, "default-on"); > > + def_value =3D device_property_read_bool(dev, "default-on"); > > > > gbl->gpiod =3D devm_gpiod_get(dev, NULL, GPIOD_ASIS); > > if (IS_ERR(gbl->gpiod)) { > > @@ -109,7 +89,15 @@ static int gpio_backlight_probe(struct platform_dev= ice *pdev) > > return PTR_ERR(bl); > > } > > > > - bl->props.power =3D 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 =3D def_value ? FB_BLANK_UNBLANK > > + : FB_BLANK_POWERDOWN; > > + else if (gpiod_get_value_cansleep(gbl->gpiod) =3D=3D 0) > > + bl->props.power =3D FB_BLANK_POWERDOWN; > > + else > > + bl->props.power =3D FB_BLANK_UNBLANK; > > + > > bl->props.brightness =3D 1; > > > > backlight_update_status(bl); > > -- > > 2.23.0 > >