From 86c68e2fb3eeb87ef716a0d61c5a346e9aee2ecb Mon Sep 17 00:00:00 2001 From: Arnd Bergmann Date: Mon, 23 Nov 2015 14:44:13 +0100 Subject: backlight: adp88x0: Fix uninitialized variable use gcc correctly warns about both the adp8860 and adp8870 backlight drivers using an uninitialized variable in their error handling path: drivers/video/backlight/adp8870_bl.c: In function 'adp8870_bl_ambient_light_zone_store': drivers/video/backlight/adp8870_bl.c:811:11: warning: 'reg_val' may be used uninitialized in this function This changes the code to only write back the data if it was correctly read to start with. As a side-note, the drivers are mostly identical, so I think they should really be merged into one file to avoid having to fix every bug twice. Signed-off-by: Arnd Bergmann Acked-by: Michael Hennerich Signed-off-by: Lee Jones --- drivers/video/backlight/adp8860_bl.c | 10 ++++++---- drivers/video/backlight/adp8870_bl.c | 10 ++++++---- 2 files changed, 12 insertions(+), 8 deletions(-) (limited to 'drivers/video') diff --git a/drivers/video/backlight/adp8860_bl.c b/drivers/video/backlight/adp8860_bl.c index 98ffe71e8af2..f0d4c0324580 100644 --- a/drivers/video/backlight/adp8860_bl.c +++ b/drivers/video/backlight/adp8860_bl.c @@ -621,10 +621,12 @@ static ssize_t adp8860_bl_ambient_light_zone_store(struct device *dev, /* Set user supplied ambient light zone */ mutex_lock(&data->lock); - adp8860_read(data->client, ADP8860_CFGR, ®_val); - reg_val &= ~(CFGR_BLV_MASK << CFGR_BLV_SHIFT); - reg_val |= (val - 1) << CFGR_BLV_SHIFT; - adp8860_write(data->client, ADP8860_CFGR, reg_val); + ret = adp8860_read(data->client, ADP8860_CFGR, ®_val); + if (!ret) { + reg_val &= ~(CFGR_BLV_MASK << CFGR_BLV_SHIFT); + reg_val |= (val - 1) << CFGR_BLV_SHIFT; + adp8860_write(data->client, ADP8860_CFGR, reg_val); + } mutex_unlock(&data->lock); } diff --git a/drivers/video/backlight/adp8870_bl.c b/drivers/video/backlight/adp8870_bl.c index 9d738352d7d4..21acac90fd77 100644 --- a/drivers/video/backlight/adp8870_bl.c +++ b/drivers/video/backlight/adp8870_bl.c @@ -807,10 +807,12 @@ static ssize_t adp8870_bl_ambient_light_zone_store(struct device *dev, /* Set user supplied ambient light zone */ mutex_lock(&data->lock); - adp8870_read(data->client, ADP8870_CFGR, ®_val); - reg_val &= ~(CFGR_BLV_MASK << CFGR_BLV_SHIFT); - reg_val |= (val - 1) << CFGR_BLV_SHIFT; - adp8870_write(data->client, ADP8870_CFGR, reg_val); + ret = adp8870_read(data->client, ADP8870_CFGR, ®_val); + if (!ret) { + reg_val &= ~(CFGR_BLV_MASK << CFGR_BLV_SHIFT); + reg_val |= (val - 1) << CFGR_BLV_SHIFT; + adp8870_write(data->client, ADP8870_CFGR, reg_val); + } mutex_unlock(&data->lock); } -- cgit v1.2.3 From 3698d7e7d221a5c90d4b55e96d0c8f98a8b4d7df Mon Sep 17 00:00:00 2001 From: Philipp Zabel Date: Wed, 18 Nov 2015 18:12:25 +0100 Subject: backlight: pwm_bl: Avoid backlight flicker when probed from DT If the driver is probed from the device tree, and there is a phandle property set on it, and the enable GPIO is already configured as output, and the backlight is currently disabled, keep it disabled. If all these conditions are met, assume there will be some other driver that can enable the backlight at the appropriate time. Signed-off-by: Philipp Zabel Reviewed-by: Christian Gmeiner Tested-by: Heiko Stuebner Signed-off-by: Lee Jones --- drivers/video/backlight/pwm_bl.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'drivers/video') diff --git a/drivers/video/backlight/pwm_bl.c b/drivers/video/backlight/pwm_bl.c index ae3c6b6fd5db..3daf9cc9bc31 100644 --- a/drivers/video/backlight/pwm_bl.c +++ b/drivers/video/backlight/pwm_bl.c @@ -199,6 +199,8 @@ static int pwm_backlight_probe(struct platform_device *pdev) struct backlight_properties props; struct backlight_device *bl; struct pwm_bl_data *pb; + phandle phandle = pdev->dev.of_node->phandle; + int initial_blank = FB_BLANK_UNBLANK; int ret; if (!data) { @@ -242,7 +244,7 @@ static int pwm_backlight_probe(struct platform_device *pdev) pb->enabled = false; pb->enable_gpio = devm_gpiod_get_optional(&pdev->dev, "enable", - GPIOD_OUT_HIGH); + GPIOD_ASIS); if (IS_ERR(pb->enable_gpio)) { ret = PTR_ERR(pb->enable_gpio); goto err_alloc; @@ -264,12 +266,30 @@ static int pwm_backlight_probe(struct platform_device *pdev) pb->enable_gpio = gpio_to_desc(data->enable_gpio); } + if (pb->enable_gpio) { + /* + * If the driver is probed from the device tree and there is a + * phandle link pointing to the backlight node, it is safe to + * assume that another driver will enable the backlight at the + * appropriate time. Therefore, if it is disabled, keep it so. + */ + if (phandle && + gpiod_get_direction(pb->enable_gpio) == GPIOF_DIR_OUT && + gpiod_get_value(pb->enable_gpio) == 0) + initial_blank = FB_BLANK_POWERDOWN; + else + gpiod_direction_output(pb->enable_gpio, 1); + } + pb->power_supply = devm_regulator_get(&pdev->dev, "power"); if (IS_ERR(pb->power_supply)) { ret = PTR_ERR(pb->power_supply); goto err_alloc; } + if (phandle && !regulator_is_enabled(pb->power_supply)) + initial_blank = FB_BLANK_POWERDOWN; + pb->pwm = devm_pwm_get(&pdev->dev, NULL); if (IS_ERR(pb->pwm) && PTR_ERR(pb->pwm) != -EPROBE_DEFER && !pdev->dev.of_node) { @@ -320,6 +340,7 @@ static int pwm_backlight_probe(struct platform_device *pdev) } bl->props.brightness = data->dft_brightness; + bl->props.power = initial_blank; backlight_update_status(bl); platform_set_drvdata(pdev, bl); -- cgit v1.2.3 From fcf13f0b9e4b54c51dff8366fc9a96d85129ff4c Mon Sep 17 00:00:00 2001 From: Enric Balletbo i Serra Date: Sun, 29 Nov 2015 17:29:46 +0100 Subject: backlight: tps65217_bl: Add MODULE_DEVICE_TABLE The device table is required to load modules based on modaliases. Signed-off-by: Enric Balletbo i Serra Signed-off-by: Lee Jones --- drivers/video/backlight/tps65217_bl.c | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'drivers/video') diff --git a/drivers/video/backlight/tps65217_bl.c b/drivers/video/backlight/tps65217_bl.c index 61d72bffd402..fd524ad860a5 100644 --- a/drivers/video/backlight/tps65217_bl.c +++ b/drivers/video/backlight/tps65217_bl.c @@ -320,10 +320,19 @@ static int tps65217_bl_probe(struct platform_device *pdev) return 0; } +#ifdef CONFIG_OF +static const struct of_device_id tps65217_bl_of_match[] = { + { .compatible = "ti,tps65217-bl", }, + { /* sentinel */ }, +}; +MODULE_DEVICE_TABLE(of, tps65217_bl_of_match); +#endif + static struct platform_driver tps65217_bl_driver = { .probe = tps65217_bl_probe, .driver = { .name = "tps65217-bl", + .of_match_table = of_match_ptr(tps65217_bl_of_match), }, }; -- cgit v1.2.3 From 8777078015bb77f0561303b6dea23d40bd9f3053 Mon Sep 17 00:00:00 2001 From: Philipp Zabel Date: Thu, 10 Dec 2015 10:09:06 +0100 Subject: backlight: pwm_bl: Fix broken PWM backlight for non-dt platforms Commit ee65ad0e2a9e ("backlight: pwm_bl: Avoid backlight flicker when probed from DT") tries to dereference the device of_node pointer unconditionally, causing a NULL pointer dereference on non-dt platforms. Fix it by replacing the phandle variable with a node variable and by checking that for NULL before dereferencing it. Reported-by: Robert Jarzmik Signed-off-by: Philipp Zabel Acked-by: Thierry Reding Tested-by: Robert Jarzmik Signed-off-by: Lee Jones --- drivers/video/backlight/pwm_bl.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'drivers/video') diff --git a/drivers/video/backlight/pwm_bl.c b/drivers/video/backlight/pwm_bl.c index 3daf9cc9bc31..a22c1ec29de7 100644 --- a/drivers/video/backlight/pwm_bl.c +++ b/drivers/video/backlight/pwm_bl.c @@ -198,8 +198,8 @@ static int pwm_backlight_probe(struct platform_device *pdev) struct platform_pwm_backlight_data defdata; struct backlight_properties props; struct backlight_device *bl; + struct device_node *node = pdev->dev.of_node; struct pwm_bl_data *pb; - phandle phandle = pdev->dev.of_node->phandle; int initial_blank = FB_BLANK_UNBLANK; int ret; @@ -273,7 +273,7 @@ static int pwm_backlight_probe(struct platform_device *pdev) * assume that another driver will enable the backlight at the * appropriate time. Therefore, if it is disabled, keep it so. */ - if (phandle && + if (node && node->phandle && gpiod_get_direction(pb->enable_gpio) == GPIOF_DIR_OUT && gpiod_get_value(pb->enable_gpio) == 0) initial_blank = FB_BLANK_POWERDOWN; @@ -287,12 +287,11 @@ static int pwm_backlight_probe(struct platform_device *pdev) goto err_alloc; } - if (phandle && !regulator_is_enabled(pb->power_supply)) + if (node && node->phandle && !regulator_is_enabled(pb->power_supply)) initial_blank = FB_BLANK_POWERDOWN; pb->pwm = devm_pwm_get(&pdev->dev, NULL); - if (IS_ERR(pb->pwm) && PTR_ERR(pb->pwm) != -EPROBE_DEFER - && !pdev->dev.of_node) { + if (IS_ERR(pb->pwm) && PTR_ERR(pb->pwm) != -EPROBE_DEFER && !node) { dev_err(&pdev->dev, "unable to request PWM, trying legacy API\n"); pb->legacy = true; pb->pwm = pwm_request(data->pwm_id, "pwm-backlight"); -- cgit v1.2.3 From 2f4647a149943b1f87e46858e9f13e02010347f7 Mon Sep 17 00:00:00 2001 From: Stefan Agner Date: Fri, 23 Oct 2015 16:44:43 -0700 Subject: backlight: gpio-backlight: Use default-on on GPIO request There are situations where the backlight should be on at boot time (e.g. if the boot loader already turned the display on). The DT bindings specify the "default-on" property for that purpose. Currently, the initial state of the GPIO at request time is always set to logical off (high or low depending on whether it is an active high or low GPIO). Since the GPIO is requested as an output, the GPIO will be driven low for a short period of time, which leads to a flickering display in the above use-case. Initialize the GPIO depending on the default-on property to be logical on or off. Signed-off-by: Stefan Agner Signed-off-by: Lee Jones --- drivers/video/backlight/gpio_backlight.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'drivers/video') diff --git a/drivers/video/backlight/gpio_backlight.c b/drivers/video/backlight/gpio_backlight.c index 5fbbc2ebdf93..18134416b154 100644 --- a/drivers/video/backlight/gpio_backlight.c +++ b/drivers/video/backlight/gpio_backlight.c @@ -89,6 +89,7 @@ static int gpio_backlight_probe(struct platform_device *pdev) struct backlight_device *bl; struct gpio_backlight *gbl; struct device_node *np = pdev->dev.of_node; + unsigned long flags = GPIOF_DIR_OUT; int ret; if (!pdata && !np) { @@ -114,9 +115,12 @@ static int gpio_backlight_probe(struct platform_device *pdev) gbl->def_value = pdata->def_value; } - ret = devm_gpio_request_one(gbl->dev, gbl->gpio, GPIOF_DIR_OUT | - (gbl->active ? GPIOF_INIT_LOW - : GPIOF_INIT_HIGH), + if (gbl->active) + flags |= gbl->def_value ? GPIOF_INIT_HIGH : GPIOF_INIT_LOW; + else + flags |= gbl->def_value ? GPIOF_INIT_LOW : GPIOF_INIT_HIGH; + + ret = devm_gpio_request_one(gbl->dev, gbl->gpio, flags, pdata ? pdata->name : "backlight"); if (ret < 0) { dev_err(&pdev->dev, "unable to request GPIO\n"); -- cgit v1.2.3 From 02f22c004ff2ab0ce1f2fa3cc6a87cf20a4fed40 Mon Sep 17 00:00:00 2001 From: Arnd Bergmann Date: Mon, 30 Nov 2015 12:24:23 +0100 Subject: backlight: adp8860: Fix another uninitialized variable use A recent patch I did fixed two potential uses of uninitialized variables in the adp8870 and adp8860 drivers. Unfortunately, I missed another one: drivers/video/backlight/adp8860_bl.c: In function 'adp8860_bl_ambient_light_level_show': drivers/video/backlight/adp8860_bl.c:570:11: warning: 'reg_val' may be used uninitialized in this function This does the same change as before in one additional function, and also changes the check for the return value in a way that avoids another false positive warning with a similar message. Signed-off-by: Arnd Bergmann Fixes: 6be3a5a9cd91 ("backlight: adp88x0: Fix uninitialized variable use") Acked-by: Michael Hennerich Acked-by: Jingoo Han Signed-off-by: Lee Jones --- drivers/video/backlight/adp8860_bl.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'drivers/video') diff --git a/drivers/video/backlight/adp8860_bl.c b/drivers/video/backlight/adp8860_bl.c index f0d4c0324580..510e559c060e 100644 --- a/drivers/video/backlight/adp8860_bl.c +++ b/drivers/video/backlight/adp8860_bl.c @@ -566,11 +566,13 @@ static ssize_t adp8860_bl_ambient_light_level_show(struct device *dev, mutex_lock(&data->lock); error = adp8860_read(data->client, ADP8860_PH1LEVL, ®_val); - ret_val = reg_val; - error |= adp8860_read(data->client, ADP8860_PH1LEVH, ®_val); + if (!error) { + ret_val = reg_val; + error = adp8860_read(data->client, ADP8860_PH1LEVH, ®_val); + } mutex_unlock(&data->lock); - if (error < 0) + if (error) return error; /* Return 13-bit conversion value for the first light sensor */ -- cgit v1.2.3 From 60d613d6aef4ae49988eeb3ad38af948c561db1e Mon Sep 17 00:00:00 2001 From: Vladimir Zapolskiy Date: Sun, 14 Jun 2015 17:32:14 +0300 Subject: backlight: pwm_bl: Free PWM requested by legacy API on error path If pwm is requested by legacy pwm_request() and if the following backlight_device_register() call fails, add pwm_free() clean-up. Signed-off-by: Vladimir Zapolskiy Signed-off-by: Lee Jones --- drivers/video/backlight/pwm_bl.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'drivers/video') diff --git a/drivers/video/backlight/pwm_bl.c b/drivers/video/backlight/pwm_bl.c index a22c1ec29de7..64f9e1b8655f 100644 --- a/drivers/video/backlight/pwm_bl.c +++ b/drivers/video/backlight/pwm_bl.c @@ -328,6 +328,8 @@ static int pwm_backlight_probe(struct platform_device *pdev) if (IS_ERR(bl)) { dev_err(&pdev->dev, "failed to register backlight\n"); ret = PTR_ERR(bl); + if (pb->legacy) + pwm_free(pb->pwm); goto err_alloc; } -- cgit v1.2.3