mirror of
https://github.com/torvalds/linux.git
synced 2024-11-17 09:31:50 +00:00
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 <bgolaszewski@baylibre.com> Acked-by: Daniel Thompson <daniel.thompson@linaro.org> Signed-off-by: Lee Jones <lee.jones@linaro.org>
This commit is contained in:
parent
d17465a0af
commit
9afa302473
@ -17,11 +17,8 @@
|
||||
#include <linux/slab.h>
|
||||
|
||||
struct gpio_backlight {
|
||||
struct device *dev;
|
||||
struct device *fbdev;
|
||||
|
||||
struct gpio_desc *gpiod;
|
||||
int def_value;
|
||||
};
|
||||
|
||||
static int gpio_backlight_get_next_brightness(struct backlight_device *bl)
|
||||
@ -60,41 +57,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_direction(gbl->gpiod) == 0 &&
|
||||
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, init_brightness;
|
||||
int ret, init_brightness, 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)) {
|
||||
@ -115,7 +95,17 @@ 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_direction(gbl->gpiod) == 0 &&
|
||||
gpiod_get_value_cansleep(gbl->gpiod) == 0)
|
||||
bl->props.power = FB_BLANK_POWERDOWN;
|
||||
else
|
||||
bl->props.power = FB_BLANK_UNBLANK;
|
||||
|
||||
bl->props.brightness = 1;
|
||||
|
||||
init_brightness = gpio_backlight_get_next_brightness(bl);
|
||||
|
Loading…
Reference in New Issue
Block a user