backlight: gpio: simplify the driver
Subsystems (3)
v2 cover backlight: gpio: simplify the driver
From: Bartosz Golaszewski <[email protected]>
While working on my other series related to gpio-backlight[1] I noticed that we could simplify the driver if we made the only user of platform data use GPIO lookups and device properties. This series tries to do that.
The first patch adds all necessary data structures to ecovec24. Patch 2/7 unifies much of the code for both pdata and non-pdata cases. Patches 3-4/7 remove unused platform data fields. Last three patches contain additional improvements for the GPIO backlight driver while we're already modifying it.
I don't have access to this HW but hopefully this works. Only compile tested.
[1] https://lkml.org/lkml/2019/6/25/900
v1 -> v2:
- rebased on top of v5.3-rc1 and adjusted to the recent changes from Andy
- added additional two patches with minor improvements
Bartosz Golaszewski (7):
sh: ecovec24: add additional properties to the backlight device
backlight: gpio: simplify the platform data handling
sh: ecovec24: don't set unused fields in platform data
backlight: gpio: remove unused fields from platform data
backlight: gpio: remove dev from struct gpio_backlight
backlight: gpio: remove def_value from struct gpio_backlight
backlight: gpio: use a helper variable for &pdev->dev
arch/sh/boards/mach-ecovec24/setup.c | 33 ++++++-- drivers/video/backlight/gpio_backlight.c | 87 ++++++-------------- include/linux/platform_data/gpio_backlight.h | 3 - 3 files changed, 48 insertions(+), 75 deletions(-)
Signature · 1 line
2.21.0
PATCH v2 1/7 sh: ecovec24: add additional properties to the backlight device
From: Bartosz Golaszewski <[email protected]>
Add a GPIO lookup entry and a device property for GPIO backlight to the board file. Tie them to the platform device which is now registered using platform_device_register_full() because of the properties. These changes are inactive now but will be used once the gpio backlight driver is modified.
--- arch/sh/boards/mach-ecovec24/setup.c | 30 +++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-)
arch/sh/boards/mach-ecovec24/setup.c +25 -5
@@ -371,6 +371,19 @@ static struct platform_device lcdc_device = { }, }; +static struct gpiod_lookup_table gpio_backlight_lookup = { + .dev_id ="gpio-backlight.0" , + .table = { +GPIO_LOOKUP ("sh7724_pfc" ,GPIO_PTR1 ,NULL ,GPIO_ACTIVE_HIGH ), + { } + }, +}; + +static struct property_entry gpio_backlight_props[] = { +PROPERTY_ENTRY_BOOL ("default-on" ), + { } +}; +static struct gpio_backlight_platform_data gpio_backlight_data = { .fbdev = &lcdc_device.dev, .gpio =GPIO_PTR1 ,
@@ -378,13 +391,15 @@ static struct gpio_backlight_platform_data gpio_backlight_data = { .name = "backlight", }; -static struct platform_device gpio_backlight_device = { +static const struct platform_device_info gpio_backlight_device_info = { .name ="gpio-backlight" , - .dev = { - .platform_data = &gpio_backlight_data, - }, + .data = &gpio_backlight_data, + .size_data =sizeof (gpio_backlight_data), + .properties = gpio_backlight_props, }; +static struct platform_device *gpio_backlight_device; +/* CEU0 */ static struct ceu_platform_data ceu0_pdata = { .num_subdevs =2 ,
@@ -1006,7 +1021,6 @@ static struct platform_device *ecovec_devices[] __initdata = { &usb1_common_device, &usbhs_device, &lcdc_device, - &gpio_backlight_device, &keysc_device, &cn12_power, #if defined(CONFIG_MMC_SDHI) || defined(CONFIG_MMC_SDHI_MODULE)
@@ -1464,6 +1478,12 @@ static int __init arch_setup(void)#endif #endif +gpiod_add_lookup_table (&gpio_backlight_lookup); + gpio_backlight_device =platform_device_register_full ( + &gpio_backlight_device_info); +if (IS_ERR (gpio_backlight_device)) +return PTR_ERR (gpio_backlight_device); +return platform_add_devices (ecovec_devices,ARRAY_SIZE (ecovec_devices)); }
Signature · 1 line
2.21.0
Re: [PATCH v2 1/7] sh: ecovec24: add additional properties to the backlight device
Quoted 9 lines · Bartosz Golaszewski
From: Bartosz Golaszewski <[email protected]>
Add a GPIO lookup entry and a device property for GPIO backlight to the board file. Tie them to the platform device which is now registered using
platform_device_register_full()because of the properties. These changes are inactive now but will be used once the gpio backlight driver is modified.Signed-off-by Bartosz Golaszewski <[email protected]>
Clever! I must also use these dynamic properties now.
Yours,
Linus Walleij
PATCH v2 2/7 backlight: gpio: simplify the platform data handling
In reply to Bartosz GolaszewskiFrom: Bartosz Golaszewski <[email protected]>
Now that the last user of platform data (sh ecovec24) defines a proper GPIO lookup and sets the 'default-on' device property, we can drop the platform_data-specific GPIO handling and unify a big chunk of code.
The only field used from the platform data is now the fbdev pointer.
--- drivers/video/backlight/gpio_backlight.c | 64 +++++------------------- 1 file changed, 13 insertions(+), 51 deletions(-)
drivers/video/backlight/gpio_backlight.c +13 -51
@@ -55,30 +55,6 @@ static const struct backlight_ops gpio_backlight_ops = { .check_fb = gpio_backlight_check_fb, }; -static int gpio_backlight_probe_dt (struct platform_device *pdev, -struct gpio_backlight *gbl) -{ -struct device *dev = &pdev->dev; -enum gpiod_flags flags; -int ret; - - gbl->def_value =device_property_read_bool (dev,"default-on" ); - flags = gbl->def_value ?GPIOD_OUT_HIGH :GPIOD_OUT_LOW ; - - gbl->gpiod =devm_gpiod_get (dev,NULL , flags); -if (IS_ERR (gbl->gpiod)) { - ret =PTR_ERR (gbl->gpiod); - -if (ret != -EPROBE_DEFER ) { -dev_err (dev, -"Error: The gpios parameter is missing or invalid.\n" ); - } -return ret; - } - -return 0 ; -} -static int gpio_backlight_probe (struct platform_device *pdev) { struct gpio_backlight_platform_data *pdata =
@@ -86,6 +62,7 @@ static int gpio_backlight_probe(struct platform_device *pdev)struct backlight_properties props;struct backlight_device *bl;struct gpio_backlight *gbl; +enum gpiod_flags flags;int ret; gbl =devm_kzalloc (&pdev->dev,sizeof (*gbl),GFP_KERNEL );
@@ -94,35 +71,20 @@ static int gpio_backlight_probe(struct platform_device *pdev) gbl->dev = &pdev->dev; -if (pdev->dev.fwnode) { - ret =gpio_backlight_probe_dt (pdev, gbl); -if (ret) -return ret; - }else if (pdata) { -/* -* Legacy platform data GPIO retrieveal. Do not expand -* the use of this code path, currently only used by one -* SH board. -*/ -unsigned long flags =GPIOF_DIR_OUT ; - +if (pdata) gbl->fbdev = pdata->fbdev; - gbl->def_value = pdata->def_value; - flags |= gbl->def_value ?GPIOF_INIT_HIGH :GPIOF_INIT_LOW ; - - ret =devm_gpio_request_one (gbl->dev, pdata->gpio, flags, - pdata ? pdata->name :"backlight" ); -if (ret <0 ) { -dev_err (&pdev->dev,"unable to request GPIO\n" ); -return ret; + + gbl->def_value =device_property_read_bool (&pdev->dev,"default-on" ); + flags = gbl->def_value ?GPIOD_OUT_HIGH :GPIOD_OUT_LOW ; + + gbl->gpiod =devm_gpiod_get (&pdev->dev,NULL , flags); +if (IS_ERR (gbl->gpiod)) { + ret =PTR_ERR (gbl->gpiod); +if (ret != -EPROBE_DEFER ) { +dev_err (&pdev->dev, +"Error: The gpios parameter is missing or invalid.\n" ); } - gbl->gpiod =gpio_to_desc (pdata->gpio); -if (!gbl->gpiod) -return -EINVAL ; - }else { -dev_err (&pdev->dev, -"failed to find platform data or device tree node.\n" ); -return -ENODEV ; +return ret; }memset (&props,0 ,sizeof (props));
Signature · 1 line
2.21.0
Re: [PATCH v2 2/7] backlight: gpio: simplify the platform data handling
Quoted 9 lines · Bartosz Golaszewski
From: Bartosz Golaszewski <[email protected]>
Now that the last user of platform data (sh ecovec24) defines a proper GPIO lookup and sets the 'default-on' device property, we can drop the platform_data-specific GPIO handling and unify a big chunk of code.
The only field used from the platform data is now the fbdev pointer.
Signed-off-by Bartosz Golaszewski <[email protected]>
Quoted 98 lines
--- drivers/video/backlight/gpio_backlight.c | 64 +++++------------------- 1 file changed, 13 insertions(+), 51 deletions(-)drivers/video/backlight/gpio_backlight.c +13
-51@@ -55,30 +55,6 @@ static const struct backlight_ops gpio_backlight_ops = { .check_fb = gpio_backlight_check_fb, }; -static int gpio_backlight_probe_dt (struct platform_device *pdev, -struct gpio_backlight *gbl) -{ -struct device *dev = &pdev->dev; -enum gpiod_flags flags; -int ret; - - gbl->def_value =device_property_read_bool (dev,"default-on" ); - flags = gbl->def_value ?GPIOD_OUT_HIGH :GPIOD_OUT_LOW ; - - gbl->gpiod =devm_gpiod_get (dev,NULL , flags); -if (IS_ERR (gbl->gpiod)) { - ret =PTR_ERR (gbl->gpiod); - -if (ret != -EPROBE_DEFER ) { -dev_err (dev, -"Error: The gpios parameter is missing or invalid.\n" ); - } -return ret; - } - -return 0 ; -} -static int gpio_backlight_probe (struct platform_device *pdev) { struct gpio_backlight_platform_data *pdata =@@ -86,6 +62,7 @@ static int gpio_backlight_probe(struct platform_device *pdev)struct backlight_properties props;struct backlight_device *bl;struct gpio_backlight *gbl; +enum gpiod_flags flags;int ret; gbl =devm_kzalloc (&pdev->dev,sizeof (*gbl),GFP_KERNEL );@@ -94,35 +71,20 @@ static int gpio_backlight_probe(struct platform_device *pdev) gbl->dev = &pdev->dev; -if (pdev->dev.fwnode) { - ret =gpio_backlight_probe_dt (pdev, gbl); -if (ret) -return ret; - }else if (pdata) { -/* -* Legacy platform data GPIO retrieveal. Do not expand -* the use of this code path, currently only used by one -* SH board. -*/ -unsigned long flags =GPIOF_DIR_OUT ; - +if (pdata) gbl->fbdev = pdata->fbdev; - gbl->def_value = pdata->def_value; - flags |= gbl->def_value ?GPIOF_INIT_HIGH :GPIOF_INIT_LOW ; - - ret =devm_gpio_request_one (gbl->dev, pdata->gpio, flags, - pdata ? pdata->name :"backlight" ); -if (ret <0 ) { -dev_err (&pdev->dev,"unable to request GPIO\n" ); -return ret; + + gbl->def_value =device_property_read_bool (&pdev->dev,"default-on" ); + flags = gbl->def_value ?GPIOD_OUT_HIGH :GPIOD_OUT_LOW ; + + gbl->gpiod =devm_gpiod_get (&pdev->dev,NULL , flags); +if (IS_ERR (gbl->gpiod)) { + ret =PTR_ERR (gbl->gpiod); +if (ret != -EPROBE_DEFER ) { +dev_err (&pdev->dev, +"Error: The gpios parameter is missing or invalid.\n" ); } - gbl->gpiod =gpio_to_desc (pdata->gpio); -if (!gbl->gpiod) -return -EINVAL ; - }else { -dev_err (&pdev->dev, -"failed to find platform data or device tree node.\n" ); -return -ENODEV ; +return ret; }memset (&props,0 ,sizeof (props));Signature · 1 line
2.21.0
Re: [PATCH v2 2/7] backlight: gpio: simplify the platform data handling
In reply to Bartosz GolaszewskiQuoted 21 lines · Bartosz Golaszewski
From: Bartosz Golaszewski <[email protected]>
Now that the last user of platform data (sh ecovec24) defines a proper GPIO lookup and sets the 'default-on' device property, we can drop the platform_data-specific GPIO handling and unify a big chunk of code.
The only field used from the platform data is now the fbdev pointer.
drivers/video/backlight/gpio_backlight.c +0
-13-static int gpio_backlight_probe_dt (struct platform_device *pdev, -struct gpio_backlight *gbl) -{ -struct device *dev = &pdev->dev; -enum gpiod_flags flags; -int ret; - - gbl->def_value =device_property_read_bool (dev,"default-on" ); - flags = gbl->def_value ?GPIOD_OUT_HIGH :GPIOD_OUT_LOW ; - - gbl->gpiod =devm_gpiod_get (dev,NULL , flags); -if (IS_ERR (gbl->gpiod)) { - ret =PTR_ERR (gbl->gpiod);
drivers/video/backlight/gpio_backlight.c static const struct backlight_ops gpio_backlight_ops = { · line 80
Quoted 10 lines
drivers/video/backlight/gpio_backlight.c +0
-10- -if (ret != -EPROBE_DEFER ) { -dev_err (dev, -"Error: The gpios parameter is missing or invalid.\n" ); - } -return ret; - } - -return 0 ; -}
Why not leave this function (perhaps with different name)?
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v2 2/7] backlight: gpio: simplify the platform data handling
pon., 22 lip 2019 o 18:06 Andy Shevchenko
<[email protected]> napisał(a):
Quoted 36 lines · Bartosz Golaszewski
Quoted 21 lines
From: Bartosz Golaszewski <[email protected]>
Now that the last user of platform data (sh ecovec24) defines a proper GPIO lookup and sets the 'default-on' device property, we can drop the platform_data-specific GPIO handling and unify a big chunk of code.
The only field used from the platform data is now the fbdev pointer.
drivers/video/backlight/gpio_backlight.c +0
-13-static int gpio_backlight_probe_dt (struct platform_device *pdev, -struct gpio_backlight *gbl) -{ -struct device *dev = &pdev->dev; -enum gpiod_flags flags; -int ret; - - gbl->def_value =device_property_read_bool (dev,"default-on" ); - flags = gbl->def_value ?GPIOD_OUT_HIGH :GPIOD_OUT_LOW ; - - gbl->gpiod =devm_gpiod_get (dev,NULL , flags); -if (IS_ERR (gbl->gpiod)) { - ret =PTR_ERR (gbl->gpiod);drivers/video/backlight/gpio_backlight.c static const struct backlight_ops gpio_backlight_ops = { · line 80
Quoted 10 lines
drivers/video/backlight/gpio_backlight.c +0
-10- -if (ret != -EPROBE_DEFER ) { -dev_err (dev, -"Error: The gpios parameter is missing or invalid.\n" ); - } -return ret; - } - -return 0 ; -}Why not leave this function (perhaps with different name)?
Quoted 5 lines
--
With Best Regards,
Andy Shevchenko
Why would we do that if the entire probe() function is now less than 50 lines long? Also: it gets inlined by the compiler anyway. It doesn't make sense IMO.
Bart
Re: [PATCH v2 2/7] backlight: gpio: simplify the platform data handling
Quoted 38 lines · Bartosz Golaszewski
pon., 22 lip 2019 o 18:06 Andy Shevchenko
<[email protected]> napisał(a):Quoted 27 lines · Bartosz Golaszewski
Quoted 25 lines
From: Bartosz Golaszewski <[email protected]>
Now that the last user of platform data (sh ecovec24) defines a proper GPIO lookup and sets the 'default-on' device property, we can drop the platform_data-specific GPIO handling and unify a big chunk of code.
The only field used from the platform data is now the fbdev pointer.
drivers/video/backlight/gpio_backlight.c +0
-17-static int gpio_backlight_probe_dt (struct platform_device *pdev, -struct gpio_backlight *gbl) -{ -struct device *dev = &pdev->dev; -enum gpiod_flags flags; -int ret; - - gbl->def_value =device_property_read_bool (dev,"default-on" ); - flags = gbl->def_value ?GPIOD_OUT_HIGH :GPIOD_OUT_LOW ; - - gbl->gpiod =devm_gpiod_get (dev,NULL , flags); -if (IS_ERR (gbl->gpiod)) { - ret =PTR_ERR (gbl->gpiod); - -if (ret != -EPROBE_DEFER ) { -dev_err (dev, -"Error: The gpios parameter is missing or invalid.\n" );Quoted 8 lines
drivers/video/backlight/gpio_backlight.c static const struct backlight_ops gpio_backlight_ops = { · line 80
Quoted 6 lines
drivers/video/backlight/gpio_backlight.c +0
-6- } -return ret; - } - -return 0 ; -}Why not leave this function (perhaps with different name)?
Quoted 3 lines
Why would we do that if the entire
probe()function is now less than 50 lines long? Also: it gets inlined by the compiler anyway. It doesn't make sense IMO.
I'm not against this, perhaps, dropping and moving can be split to two changes.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v2 2/7] backlight: gpio: simplify the platform data handling
wt., 23 lip 2019 o 17:32 Andy Shevchenko
<[email protected]> napisał(a):
Quoted 40 lines · Bartosz Golaszewski
Quoted 38 lines
pon., 22 lip 2019 o 18:06 Andy Shevchenko
<[email protected]> napisał(a):Quoted 35 lines · Bartosz Golaszewski
Quoted 21 lines
From: Bartosz Golaszewski <[email protected]>
Now that the last user of platform data (sh ecovec24) defines a proper GPIO lookup and sets the 'default-on' device property, we can drop the platform_data-specific GPIO handling and unify a big chunk of code.
The only field used from the platform data is now the fbdev pointer.
drivers/video/backlight/gpio_backlight.c +0
-13-static int gpio_backlight_probe_dt (struct platform_device *pdev, -struct gpio_backlight *gbl) -{ -struct device *dev = &pdev->dev; -enum gpiod_flags flags; -int ret; - - gbl->def_value =device_property_read_bool (dev,"default-on" ); - flags = gbl->def_value ?GPIOD_OUT_HIGH :GPIOD_OUT_LOW ; - - gbl->gpiod =devm_gpiod_get (dev,NULL , flags); -if (IS_ERR (gbl->gpiod)) { - ret =PTR_ERR (gbl->gpiod);drivers/video/backlight/gpio_backlight.c static const struct backlight_ops gpio_backlight_ops = { · line 80
Quoted 10 lines
drivers/video/backlight/gpio_backlight.c +0
-10- -if (ret != -EPROBE_DEFER ) { -dev_err (dev, -"Error: The gpios parameter is missing or invalid.\n" ); - } -return ret; - } - -return 0 ; -}Why not leave this function (perhaps with different name)?
Quoted 6 lines
Quoted 3 lines
Why would we do that if the entire
probe()function is now less than 50 lines long? Also: it gets inlined by the compiler anyway. It doesn't make sense IMO.I'm not against this, perhaps, dropping and moving can be split to two changes.
This really is unnecessary - we can do it in a single patch alright.
Bart
PATCH v2 3/7 sh: ecovec24: don't set unused fields in platform data
In reply to Bartosz GolaszewskiFrom: Bartosz Golaszewski <[email protected]>
Platform data fields other than fbdev are no longer used by the backlight driver. Remove them.
--- arch/sh/boards/mach-ecovec24/setup.c | 3 --- 1 file changed, 3 deletions(-)
arch/sh/boards/mach-ecovec24/setup.c +0 -3
@@ -386,9 +386,6 @@ static struct property_entry gpio_backlight_props[] = {static struct gpio_backlight_platform_data gpio_backlight_data = { .fbdev = &lcdc_device.dev, - .gpio =GPIO_PTR1 , - .def_value =1 , - .name ="backlight" , };static const struct platform_device_info gpio_backlight_device_info = {
Signature · 1 line
2.21.0
PATCH v2 4/7 backlight: gpio: remove unused fields from platform data
In reply to Bartosz GolaszewskiFrom: Bartosz Golaszewski <[email protected]>
Remove the platform data fields that nobody uses.
--- include/linux/platform_data/gpio_backlight.h | 3 --- 1 file changed, 3 deletions(-)
include/linux/platform_data/gpio_backlight.h +0 -3
@@ -9,9 +9,6 @@ struct device;struct gpio_backlight_platform_data {struct device *fbdev; -int gpio; -int def_value; -const char *name; };#endif
Signature · 1 line
2.21.0
Re: [PATCH v2 4/7] backlight: gpio: remove unused fields from platform data
Quoted 5 lines · Bartosz Golaszewski
From: Bartosz Golaszewski <[email protected]>
Remove the platform data fields that nobody uses.
Signed-off-by Bartosz Golaszewski <[email protected]>
Quoted 21 lines
--- include/linux/platform_data/gpio_backlight.h | 3 --- 1 file changed, 3 deletions(-)include/linux/platform_data/gpio_backlight.h +0
-3@@ -9,9 +9,6 @@ struct device;struct gpio_backlight_platform_data {struct device *fbdev; -int gpio; -int def_value; -const char *name; };#endif Signature · 1 line
2.21.0
PATCH v2 5/7 backlight: gpio: remove dev from struct gpio_backlight
In reply to Bartosz GolaszewskiFrom: Bartosz Golaszewski <[email protected]>
This field is unused. Remove it.
--- drivers/video/backlight/gpio_backlight.c | 4 ---- 1 file changed, 4 deletions(-)
drivers/video/backlight/gpio_backlight.c +0 -4
@@ -19,9 +19,7 @@#include <linux/slab.h> struct gpio_backlight { -struct device *dev;struct device *fbdev; -struct gpio_desc *gpiod;int def_value; };
@@ -69,8 +67,6 @@ static int gpio_backlight_probe(struct platform_device *pdev)if (gbl ==NULL )return -ENOMEM ; - gbl->dev = &pdev->dev; -if (pdata) gbl->fbdev = pdata->fbdev;
Signature · 1 line
2.21.0
Re: [PATCH v2 5/7] backlight: gpio: remove dev from struct gpio_backlight
Quoted 5 lines · Bartosz Golaszewski
From: Bartosz Golaszewski <[email protected]>
This field is unused. Remove it.
Signed-off-by Bartosz Golaszewski <[email protected]>
Quoted 30 lines
--- drivers/video/backlight/gpio_backlight.c | 4 ---- 1 file changed, 4 deletions(-)drivers/video/backlight/gpio_backlight.c +0
-4@@ -19,9 +19,7 @@#include <linux/slab.h> struct gpio_backlight { -struct device *dev;struct device *fbdev; -struct gpio_desc *gpiod;int def_value; };@@ -69,8 +67,6 @@ static int gpio_backlight_probe(struct platform_device *pdev)if (gbl ==NULL )return -ENOMEM ; - gbl->dev = &pdev->dev; -if (pdata) gbl->fbdev = pdata->fbdev;Signature · 1 line
2.21.0
PATCH v2 6/7 backlight: gpio: remove def_value from struct gpio_backlight
In reply to Bartosz GolaszewskiFrom: Bartosz Golaszewski <[email protected]>
This field is unused outside of probe(). There's no need to store it. We can make it into a local variable.
--- drivers/video/backlight/gpio_backlight.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)
drivers/video/backlight/gpio_backlight.c +4 -5
@@ -21,7 +21,6 @@struct gpio_backlight {struct device *fbdev;struct gpio_desc *gpiod; -int def_value; };static int gpio_backlight_update_status (struct backlight_device *bl)
@@ -61,7 +60,7 @@ static int gpio_backlight_probe(struct platform_device *pdev)struct backlight_device *bl;struct gpio_backlight *gbl;enum gpiod_flags flags; -int ret; +int ret, def_value; gbl =devm_kzalloc (&pdev->dev,sizeof (*gbl),GFP_KERNEL );if (gbl ==NULL )
@@ -70,8 +69,8 @@ static int gpio_backlight_probe(struct platform_device *pdev)if (pdata) gbl->fbdev = pdata->fbdev; - gbl->def_value =device_property_read_bool (&pdev->dev,"default-on" ); - flags = gbl->def_value ?GPIOD_OUT_HIGH :GPIOD_OUT_LOW ; + def_value =device_property_read_bool (&pdev->dev,"default-on" ); + flags = def_value ?GPIOD_OUT_HIGH :GPIOD_OUT_LOW ; gbl->gpiod =devm_gpiod_get (&pdev->dev,NULL , flags);if (IS_ERR (gbl->gpiod)) {
@@ -94,7 +93,7 @@ static int gpio_backlight_probe(struct platform_device *pdev)return PTR_ERR (bl); } - bl->props.brightness = gbl->def_value; + bl->props.brightness = def_value;backlight_update_status (bl);platform_set_drvdata (pdev, bl);
Signature · 1 line
2.21.0
Re: [PATCH v2 6/7] backlight: gpio: remove def_value from struct gpio_backlight
Quoted 6 lines · Bartosz Golaszewski
From: Bartosz Golaszewski <[email protected]>
This field is unused outside of
probe(). There's no need to store it. We can make it into a local variable.Signed-off-by Bartosz Golaszewski <[email protected]>
Quoted 48 lines
--- drivers/video/backlight/gpio_backlight.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-)drivers/video/backlight/gpio_backlight.c +4
-5@@ -21,7 +21,6 @@struct gpio_backlight {struct device *fbdev;struct gpio_desc *gpiod; -int def_value; };static int gpio_backlight_update_status (struct backlight_device *bl)@@ -61,7 +60,7 @@ static int gpio_backlight_probe(struct platform_device *pdev)struct backlight_device *bl;struct gpio_backlight *gbl;enum gpiod_flags flags; -int ret; +int ret, def_value; gbl =devm_kzalloc (&pdev->dev,sizeof (*gbl),GFP_KERNEL );if (gbl =NULL )@@ -70,8 +69,8 @@ static int gpio_backlight_probe(struct platform_device *pdev)if (pdata) gbl->fbdev = pdata->fbdev; - gbl->def_value =device_property_read_bool (&pdev->dev,"default-on" ); - flags = gbl->def_value ?GPIOD_OUT_HIGH :GPIOD_OUT_LOW ; + def_value =device_property_read_bool (&pdev->dev,"default-on" ); + flags = def_value ?GPIOD_OUT_HIGH :GPIOD_OUT_LOW ; gbl->gpiod =devm_gpiod_get (&pdev->dev,NULL , flags);if (IS_ERR (gbl->gpiod)) {@@ -94,7 +93,7 @@ static int gpio_backlight_probe(struct platform_device *pdev)return PTR_ERR (bl); } - bl->props.brightness = gbl->def_value; + bl->props.brightness = def_value;backlight_update_status (bl);platform_set_drvdata (pdev, bl);Signature · 1 line
2.21.0
PATCH v2 7/7 backlight: gpio: use a helper variable for &pdev->dev
In reply to Bartosz GolaszewskiFrom: Bartosz Golaszewski <[email protected]>
Instead of dereferencing pdev each time, use a helper variable for the associated device pointer.
--- drivers/video/backlight/gpio_backlight.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-)
drivers/video/backlight/gpio_backlight.c +12 -10
@@ -54,29 +54,32 @@ static const struct backlight_ops gpio_backlight_ops = {static int gpio_backlight_probe (struct platform_device *pdev) { -struct gpio_backlight_platform_data *pdata = -dev_get_platdata (&pdev->dev); +struct gpio_backlight_platform_data *pdata;struct backlight_properties props;struct backlight_device *bl;struct gpio_backlight *gbl;enum gpiod_flags flags; +struct device *dev;int ret, def_value; - gbl =devm_kzalloc (&pdev->dev,sizeof (*gbl),GFP_KERNEL ); + dev = &pdev->dev; + pdata =dev_get_platdata (dev); + + gbl =devm_kzalloc (dev,sizeof (*gbl),GFP_KERNEL );if (gbl ==NULL )return -ENOMEM ;if (pdata) gbl->fbdev = pdata->fbdev; - def_value =device_property_read_bool (&pdev->dev,"default-on" ); + def_value =device_property_read_bool (dev,"default-on" ); flags = def_value ?GPIOD_OUT_HIGH :GPIOD_OUT_LOW ; - gbl->gpiod =devm_gpiod_get (&pdev->dev,NULL , flags); + gbl->gpiod =devm_gpiod_get (dev,NULL , flags);if (IS_ERR (gbl->gpiod)) { ret =PTR_ERR (gbl->gpiod);if (ret != -EPROBE_DEFER ) { -dev_err (&pdev->dev, +dev_err (dev,"Error: The gpios parameter is missing or invalid.\n" ); }return ret;
@@ -85,11 +88,10 @@ static int gpio_backlight_probe(struct platform_device *pdev)memset (&props,0 ,sizeof (props)); props.type =BACKLIGHT_RAW ; props.max_brightness =1 ; - bl =devm_backlight_device_register (&pdev->dev,dev_name (&pdev->dev), - &pdev->dev, gbl, &gpio_backlight_ops, - &props); + bl =devm_backlight_device_register (dev,dev_name (dev), dev, gbl, + &gpio_backlight_ops, &props);if (IS_ERR (bl)) { -dev_err (&pdev->dev,"failed to register backlight\n" ); +dev_err (dev,"failed to register backlight\n" );return PTR_ERR (bl); }
Signature · 1 line
2.21.0
Re: [PATCH v2 7/7] backlight: gpio: use a helper variable for &pdev->dev
Quoted 6 lines · Bartosz Golaszewski
From: Bartosz Golaszewski <[email protected]>
Instead of dereferencing pdev each time, use a helper variable for the associated device pointer.
Signed-off-by Bartosz Golaszewski <[email protected]>
Quoted 65 lines
--- drivers/video/backlight/gpio_backlight.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-)drivers/video/backlight/gpio_backlight.c +12
-10@@ -54,29 +54,32 @@ static const struct backlight_ops gpio_backlight_ops = {static int gpio_backlight_probe (struct platform_device *pdev) { -struct gpio_backlight_platform_data *pdata = -dev_get_platdata (&pdev->dev); +struct gpio_backlight_platform_data *pdata;struct backlight_properties props;struct backlight_device *bl;struct gpio_backlight *gbl;enum gpiod_flags flags; +struct device *dev;int ret, def_value; - gbl =devm_kzalloc (&pdev->dev,sizeof (*gbl),GFP_KERNEL ); + dev = &pdev->dev; + pdata =dev_get_platdata (dev); + + gbl =devm_kzalloc (dev,sizeof (*gbl),GFP_KERNEL );if (gbl ==NULL )return -ENOMEM ;if (pdata) gbl->fbdev = pdata->fbdev; - def_value =device_property_read_bool (&pdev->dev,"default-on" ); + def_value =device_property_read_bool (dev,"default-on" ); flags = def_value ?GPIOD_OUT_HIGH :GPIOD_OUT_LOW ; - gbl->gpiod =devm_gpiod_get (&pdev->dev,NULL , flags); + gbl->gpiod =devm_gpiod_get (dev,NULL , flags);if (IS_ERR (gbl->gpiod)) { ret =PTR_ERR (gbl->gpiod);if (ret != -EPROBE_DEFER ) { -dev_err (&pdev->dev, +dev_err (dev,"Error: The gpios parameter is missing or invalid.\n" ); }return ret;@@ -85,11 +88,10 @@ static int gpio_backlight_probe(struct platform_device *pdev)memset (&props,0 ,sizeof (props)); props.type =BACKLIGHT_RAW ; props.max_brightness =1 ; - bl =devm_backlight_device_register (&pdev->dev,dev_name (&pdev->dev), - &pdev->dev, gbl, &gpio_backlight_ops, - &props); + bl =devm_backlight_device_register (dev,dev_name (dev), dev, gbl, + &gpio_backlight_ops, &props);if (IS_ERR (bl)) { -dev_err (&pdev->dev,"failed to register backlight\n" ); +dev_err (dev,"failed to register backlight\n" );return PTR_ERR (bl); }Signature · 1 line
2.21.0
Re: [PATCH v2 7/7] backlight: gpio: use a helper variable for &pdev->dev
In reply to Bartosz GolaszewskiQuoted 7 lines · Bartosz Golaszewski
From: Bartosz Golaszewski <[email protected]>
Instead of dereferencing pdev each time, use a helper variable for the associated device pointer.
static int
gpio_backlight_probe(struct platform_device *pdev){
drivers/video/backlight/gpio_backlight.c static const struct backlight_ops gpio_backlight_ops = { · line 62
Quoted 8 lines
drivers/video/backlight/gpio_backlight.c +2
-2-struct gpio_backlight_platform_data *pdata = -dev_get_platdata (&pdev->dev); +struct gpio_backlight_platform_data *pdata;struct backlight_properties props;struct backlight_device *bl;struct gpio_backlight *gbl;enum gpiod_flags flags; +struct device *dev;
Can't we do
struct device dev = &pdev->dev; struct gpio_backlight_platform_data *pdata = dev_get_platdata(dev);
? It fits 80 nicely.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v2 7/7] backlight: gpio: use a helper variable for &pdev->dev
pon., 22 lip 2019 o 18:09 Andy Shevchenko
<[email protected]> napisał(a):
Quoted 18 lines · Bartosz Golaszewski
Quoted 7 lines
From: Bartosz Golaszewski <[email protected]>
Instead of dereferencing pdev each time, use a helper variable for the associated device pointer.
static int
gpio_backlight_probe(struct platform_device *pdev){drivers/video/backlight/gpio_backlight.c static const struct backlight_ops gpio_backlight_ops = { · line 62
Quoted 8 lines
drivers/video/backlight/gpio_backlight.c +2
-2-struct gpio_backlight_platform_data *pdata = -dev_get_platdata (&pdev->dev); +struct gpio_backlight_platform_data *pdata;struct backlight_properties props;struct backlight_device *bl;struct gpio_backlight *gbl;enum gpiod_flags flags; +struct device *dev;
Quoted 7 lines
Can't we do
struct device dev = &pdev->dev; struct gpio_backlight_platform_data *pdata = dev_get_platdata(dev);? It fits 80 nicely.
IMO it's more readable like that with the reverse christmas tree layout.
Bart
Re: [PATCH v2 7/7] backlight: gpio: use a helper variable for &pdev->dev
Quoted 22 lines · Bartosz Golaszewski
pon., 22 lip 2019 o 18:09 Andy Shevchenko
<[email protected]> napisał(a):Quoted 20 lines · Bartosz Golaszewski
Quoted 7 lines
From: Bartosz Golaszewski <[email protected]>
Instead of dereferencing pdev each time, use a helper variable for the associated device pointer.
static int
gpio_backlight_probe(struct platform_device *pdev){drivers/video/backlight/gpio_backlight.c static const struct backlight_ops gpio_backlight_ops = { · line 62
Quoted 8 lines
drivers/video/backlight/gpio_backlight.c +2
-2-struct gpio_backlight_platform_data *pdata = -dev_get_platdata (&pdev->dev); +struct gpio_backlight_platform_data *pdata;struct backlight_properties props;struct backlight_device *bl;struct gpio_backlight *gbl;enum gpiod_flags flags; +struct device *dev;Can't we do
Quoted 7 lines
Quoted 5 lines
struct device dev = &pdev->dev; struct gpio_backlight_platform_data *pdata = dev_get_platdata(dev);? It fits 80 nicely.
IMO it's more readable like that with the reverse christmas tree layout.
There is no requirement for reverse christmas tree layout for this area of the kernel (and especially not where RCTL is used as a justification to avoid initializers).
I have a weak personal preference for initializers although it is sufficiently weak I was happy to put a reviewed by on the original patch without comment.
Daniel.
Re: [PATCH v2 7/7] backlight: gpio: use a helper variable for &pdev->dev
In reply to Bartosz GolaszewskiQuoted 22 lines · Bartosz Golaszewski
pon., 22 lip 2019 o 18:09 Andy Shevchenko
<[email protected]> napisał(a):Quoted 20 lines · Bartosz Golaszewski
Quoted 7 lines
From: Bartosz Golaszewski <[email protected]>
Instead of dereferencing pdev each time, use a helper variable for the associated device pointer.
static int
gpio_backlight_probe(struct platform_device *pdev){drivers/video/backlight/gpio_backlight.c static const struct backlight_ops gpio_backlight_ops = { · line 62
Quoted 8 lines
drivers/video/backlight/gpio_backlight.c +2
-2-struct gpio_backlight_platform_data *pdata = -dev_get_platdata (&pdev->dev); +struct gpio_backlight_platform_data *pdata;struct backlight_properties props;struct backlight_device *bl;struct gpio_backlight *gbl;enum gpiod_flags flags; +struct device *dev;Can't we do
Quoted 7 lines
Quoted 5 lines
struct device dev = &pdev->dev; struct gpio_backlight_platform_data *pdata = dev_get_platdata(dev);? It fits 80 nicely.
IMO it's more readable like that with the reverse christmas tree layout.
It makes more churn in the original code and for initializers the order is defined by its nature.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v2 7/7] backlight: gpio: use a helper variable for &pdev->dev
wt., 23 lip 2019 o 17:34 Andy Shevchenko
<[email protected]> napisał(a):
Quoted 30 lines · Bartosz Golaszewski
Quoted 28 lines
pon., 22 lip 2019 o 18:09 Andy Shevchenko
<[email protected]> napisał(a):Quoted 25 lines · Bartosz Golaszewski
Quoted 7 lines
From: Bartosz Golaszewski <[email protected]>
Instead of dereferencing pdev each time, use a helper variable for the associated device pointer.
static int
gpio_backlight_probe(struct platform_device *pdev){drivers/video/backlight/gpio_backlight.c static const struct backlight_ops gpio_backlight_ops = { · line 62
Quoted 8 lines
drivers/video/backlight/gpio_backlight.c +2
-2-struct gpio_backlight_platform_data *pdata = -dev_get_platdata (&pdev->dev); +struct gpio_backlight_platform_data *pdata;struct backlight_properties props;struct backlight_device *bl;struct gpio_backlight *gbl;enum gpiod_flags flags; +struct device *dev;Can't we do
struct device dev = &pdev->dev; struct gpio_backlight_platform_data *pdata = dev_get_platdata(dev);? It fits 80 nicely.
Quoted 10 lines
Quoted 1 line
IMO it's more readable like that with the reverse christmas tree layout.
It makes more churn in the original code and for initializers the order is defined by its nature.
--
With Best Regards,
Andy Shevchenko
Fair enough, I changed it in v3.
Bart
Quoted 13 lines · Bartosz Golaszewski
From: Bartosz Golaszewski <[email protected]>
While working on my other series related to gpio-backlight[1] I noticed that we could simplify the driver if we made the only user of platform data use GPIO lookups and device properties. This series tries to do that.
The first patch adds all necessary data structures to ecovec24. Patch 2/7 unifies much of the code for both pdata and non-pdata cases. Patches 3-4/7 remove unused platform data fields. Last three patches contain additional improvements for the GPIO backlight driver while we're already modifying it.
Quoted 4 lines
I don't have access to this HW but hopefully this works. Only compile tested.
For uncommented ones
Quoted 22 lines
v1 -> v2:
- rebased on top of v5.3-rc1 and adjusted to the recent changes from Andy
- added additional two patches with minor improvementsBartosz Golaszewski (7):
sh: ecovec24: add additional properties to the backlight device
backlight: gpio: simplify the platform data handling
sh: ecovec24: don't set unused fields in platform data
backlight: gpio: remove unused fields from platform data
backlight: gpio: remove dev from structgpio_backlight
backlight: gpio: removedef_valuefrom structgpio_backlight
backlight: gpio: use a helper variable for&pdev->devarch/sh/boards/mach-ecovec24/setup.c | 33 ++++++-- drivers/video/backlight/gpio_backlight.c | 87 ++++++-------------- include/linux/platform_data/gpio_backlight.h | 3 - 3 files changed, 48 insertions(+), 75 deletions(-)Signature · 1 line
2.21.0
Signature · 2 lines
With Best Regards, Andy Shevchenko