Skip to content

Commit 9afa302

Browse files
brglLee Jones
authored andcommitted
backlight: gpio: Pull gpio_backlight_initial_power_state() into probe
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 <[email protected]> Acked-by: Daniel Thompson <[email protected]> Signed-off-by: Lee Jones <[email protected]>
1 parent d17465a commit 9afa302

File tree

1 file changed

+14
-24
lines changed

1 file changed

+14
-24
lines changed

drivers/video/backlight/gpio_backlight.c

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,8 @@
1717
#include <linux/slab.h>
1818

1919
struct gpio_backlight {
20-
struct device *dev;
2120
struct device *fbdev;
22-
2321
struct gpio_desc *gpiod;
24-
int def_value;
2522
};
2623

2724
static int gpio_backlight_get_next_brightness(struct backlight_device *bl)
@@ -60,41 +57,24 @@ static const struct backlight_ops gpio_backlight_ops = {
6057
.check_fb = gpio_backlight_check_fb,
6158
};
6259

63-
static int gpio_backlight_initial_power_state(struct gpio_backlight *gbl)
64-
{
65-
struct device_node *node = gbl->dev->of_node;
66-
67-
/* Not booted with device tree or no phandle link to the node */
68-
if (!node || !node->phandle)
69-
return gbl->def_value ? FB_BLANK_UNBLANK : FB_BLANK_POWERDOWN;
70-
71-
/* if the enable GPIO is disabled, do not enable the backlight */
72-
if (gpiod_get_direction(gbl->gpiod) == 0 &&
73-
gpiod_get_value_cansleep(gbl->gpiod) == 0)
74-
return FB_BLANK_POWERDOWN;
75-
76-
return FB_BLANK_UNBLANK;
77-
}
78-
7960
static int gpio_backlight_probe(struct platform_device *pdev)
8061
{
8162
struct device *dev = &pdev->dev;
8263
struct gpio_backlight_platform_data *pdata = dev_get_platdata(dev);
64+
struct device_node *of_node = dev->of_node;
8365
struct backlight_properties props;
8466
struct backlight_device *bl;
8567
struct gpio_backlight *gbl;
86-
int ret, init_brightness;
68+
int ret, init_brightness, def_value;
8769

8870
gbl = devm_kzalloc(dev, sizeof(*gbl), GFP_KERNEL);
8971
if (gbl == NULL)
9072
return -ENOMEM;
9173

92-
gbl->dev = dev;
93-
9474
if (pdata)
9575
gbl->fbdev = pdata->fbdev;
9676

97-
gbl->def_value = device_property_read_bool(dev, "default-on");
77+
def_value = device_property_read_bool(dev, "default-on");
9878

9979
gbl->gpiod = devm_gpiod_get(dev, NULL, GPIOD_ASIS);
10080
if (IS_ERR(gbl->gpiod)) {
@@ -115,7 +95,17 @@ static int gpio_backlight_probe(struct platform_device *pdev)
11595
return PTR_ERR(bl);
11696
}
11797

118-
bl->props.power = gpio_backlight_initial_power_state(gbl);
98+
/* Set the initial power state */
99+
if (!of_node || !of_node->phandle)
100+
/* Not booted with device tree or no phandle link to the node */
101+
bl->props.power = def_value ? FB_BLANK_UNBLANK
102+
: FB_BLANK_POWERDOWN;
103+
else if (gpiod_get_direction(gbl->gpiod) == 0 &&
104+
gpiod_get_value_cansleep(gbl->gpiod) == 0)
105+
bl->props.power = FB_BLANK_POWERDOWN;
106+
else
107+
bl->props.power = FB_BLANK_UNBLANK;
108+
119109
bl->props.brightness = 1;
120110

121111
init_brightness = gpio_backlight_get_next_brightness(bl);

0 commit comments

Comments
 (0)