From cc21942bce652d1a92dae85b785378256e1df1f7 Mon Sep 17 00:00:00 2001 From: Uwe Kleine-König Date: Wed, 6 Jul 2016 19:33:05 +0200 Subject: backlight: lcd: Fix race condition during register MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Once device_register is called for a device its attributes might be accessed. As the callbacks of a lcd device's attributes make use of the lcd_ops, the respective member must be setup before calling device_register. Signed-off-by: Uwe Kleine-König Signed-off-by: Lee Jones --- drivers/video/backlight/lcd.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'drivers/video') diff --git a/drivers/video/backlight/lcd.c b/drivers/video/backlight/lcd.c index 7de847df224f..4b40c6a4d441 100644 --- a/drivers/video/backlight/lcd.c +++ b/drivers/video/backlight/lcd.c @@ -226,6 +226,8 @@ struct lcd_device *lcd_device_register(const char *name, struct device *parent, dev_set_name(&new_ld->dev, "%s", name); dev_set_drvdata(&new_ld->dev, devdata); + new_ld->ops = ops; + rc = device_register(&new_ld->dev); if (rc) { put_device(&new_ld->dev); @@ -238,8 +240,6 @@ struct lcd_device *lcd_device_register(const char *name, struct device *parent, return ERR_PTR(rc); } - new_ld->ops = ops; - return new_ld; } EXPORT_SYMBOL(lcd_device_register); -- cgit v1.2.3 From 0eb3fba8c68275f0122f65f7316efaaf86448016 Mon Sep 17 00:00:00 2001 From: Alexey Khoroshilov Date: Sat, 9 Jul 2016 01:19:51 +0300 Subject: backlight: adp5520: Fix error handling in adp5520_bl_probe() If adp5520_bl_setup() fails, sysfs group left unremoved. By the way, fix overcomplicated assignement of error code. Found by Linux Driver Verification project (linuxtesting.org). Signed-off-by: Alexey Khoroshilov Acked-by: Michael Hennerich Signed-off-by: Lee Jones --- drivers/video/backlight/adp5520_bl.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'drivers/video') diff --git a/drivers/video/backlight/adp5520_bl.c b/drivers/video/backlight/adp5520_bl.c index dd88ba1d71ce..35373e2065b2 100644 --- a/drivers/video/backlight/adp5520_bl.c +++ b/drivers/video/backlight/adp5520_bl.c @@ -332,10 +332,18 @@ static int adp5520_bl_probe(struct platform_device *pdev) } platform_set_drvdata(pdev, bl); - ret |= adp5520_bl_setup(bl); + ret = adp5520_bl_setup(bl); + if (ret) { + dev_err(&pdev->dev, "failed to setup\n"); + if (data->pdata->en_ambl_sens) + sysfs_remove_group(&bl->dev.kobj, + &adp5520_bl_attr_group); + return ret; + } + backlight_update_status(bl); - return ret; + return 0; } static int adp5520_bl_remove(struct platform_device *pdev) -- cgit v1.2.3 From 7613c922315e308a6486d802abed2eb74443dffd Mon Sep 17 00:00:00 2001 From: Peter Ujfalusi Date: Tue, 22 Nov 2016 15:41:22 +0200 Subject: backlight: pwm_bl: Move the checks for initial power state to a separate function Move the checks to select the initial state for the backlight to a new function and document the checks we are doing. With the separate function it is going to be easier to fix or improve the initial power state configuration later and it is easier to read the code. Signed-off-by: Peter Ujfalusi Reviewed-by: Philipp Zabel Reviewed-by: Thierry Reding Signed-off-by: Lee Jones --- drivers/video/backlight/pwm_bl.c | 56 ++++++++++++++++++++++++++-------------- 1 file changed, 37 insertions(+), 19 deletions(-) (limited to 'drivers/video') diff --git a/drivers/video/backlight/pwm_bl.c b/drivers/video/backlight/pwm_bl.c index 12614006211e..5712ddd053dd 100644 --- a/drivers/video/backlight/pwm_bl.c +++ b/drivers/video/backlight/pwm_bl.c @@ -192,6 +192,32 @@ static int pwm_backlight_parse_dt(struct device *dev, } #endif +static int pwm_backlight_initial_power_state(const struct pwm_bl_data *pb) +{ + struct device_node *node = pb->dev->of_node; + + /* Not booted with device tree or no phandle link to the node */ + if (!node || !node->phandle) + return FB_BLANK_UNBLANK; + + /* + * 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 the enable GPIO is disabled, do not enable the backlight */ + if (pb->enable_gpio && gpiod_get_value(pb->enable_gpio) == 0) + return FB_BLANK_POWERDOWN; + + /* The regulator is disabled, do not enable the backlight */ + if (!regulator_is_enabled(pb->power_supply)) + return FB_BLANK_POWERDOWN; + + return FB_BLANK_UNBLANK; +} + static int pwm_backlight_probe(struct platform_device *pdev) { struct platform_pwm_backlight_data *data = dev_get_platdata(&pdev->dev); @@ -200,7 +226,6 @@ static int pwm_backlight_probe(struct platform_device *pdev) struct backlight_device *bl; struct device_node *node = pdev->dev.of_node; struct pwm_bl_data *pb; - int initial_blank = FB_BLANK_UNBLANK; struct pwm_args pargs; int ret; @@ -267,20 +292,16 @@ 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 (node && node->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); - } + /* + * If the GPIO is configured as input, change the direction to output + * and set the GPIO as active. + * Do not force the GPIO to active when it was already output as it + * could cause backlight flickering or we would enable the backlight too + * early. Leave the decision of the initial backlight state for later. + */ + if (pb->enable_gpio && + gpiod_get_direction(pb->enable_gpio) == GPIOF_DIR_IN) + gpiod_direction_output(pb->enable_gpio, 1); pb->power_supply = devm_regulator_get(&pdev->dev, "power"); if (IS_ERR(pb->power_supply)) { @@ -288,9 +309,6 @@ static int pwm_backlight_probe(struct platform_device *pdev) goto err_alloc; } - 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 && !node) { dev_err(&pdev->dev, "unable to request PWM, trying legacy API\n"); @@ -347,7 +365,7 @@ static int pwm_backlight_probe(struct platform_device *pdev) } bl->props.brightness = data->dft_brightness; - bl->props.power = initial_blank; + bl->props.power = pwm_backlight_initial_power_state(pb); backlight_update_status(bl); platform_set_drvdata(pdev, bl); -- cgit v1.2.3 From d1b81294575098d989be1f2f6bb628091ceaa87b Mon Sep 17 00:00:00 2001 From: Peter Ujfalusi Date: Tue, 22 Nov 2016 15:41:23 +0200 Subject: backlight: pwm_bl: Check the PWM state for initial backlight power state If the PWM is not enabled the backlight initially should not be enabled either if we have booted with DT and there is a phandle pointing to the backlight node. The patch extends the checks to decide if we should keep the backlight off initially. Signed-off-by: Peter Ujfalusi Acked-by: Philipp Zabel Reviewed-by: Thierry Reding Signed-off-by: Lee Jones --- drivers/video/backlight/pwm_bl.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'drivers/video') diff --git a/drivers/video/backlight/pwm_bl.c b/drivers/video/backlight/pwm_bl.c index 5712ddd053dd..d7efcb632f7d 100644 --- a/drivers/video/backlight/pwm_bl.c +++ b/drivers/video/backlight/pwm_bl.c @@ -215,6 +215,10 @@ static int pwm_backlight_initial_power_state(const struct pwm_bl_data *pb) if (!regulator_is_enabled(pb->power_supply)) return FB_BLANK_POWERDOWN; + /* The PWM is disabled, keep it like this */ + if (!pwm_is_enabled(pb->pwm)) + return FB_BLANK_POWERDOWN; + return FB_BLANK_UNBLANK; } -- cgit v1.2.3 From bb82250fc45631bcac52af22328cb7c4dda3b763 Mon Sep 17 00:00:00 2001 From: Javier Martinez Canillas Date: Mon, 2 Jan 2017 13:03:27 -0300 Subject: backlight: da9052: Fix module autoload The driver has a platform device ID table with multiple device entries, each setting a different register address in its driver_data to control the WLED brightness. But the driver doesn't export these as aliases with MODULE_DEVICE_TABLE() when the driver is built as a module, instead it just has a single alias using MODULE_ALIAS("platform:da9052-backlight"). That is clearly wrong since there isn't a "da9052-backlight" in the platform device ID table, so if that device name is used, the device won't even match the driver. So instead of having a wrong alias, export the ones in the dev ID table. Before this patch: $ modinfo drivers/video/backlight/da9052_bl.ko | grep alias alias: platform:da9052-backlight After this patch: $ modinfo drivers/video/backlight/da9052_bl.ko | grep alias alias: platform:da9052-wled3 alias: platform:da9052-wled2 alias: platform:da9052-wled1 Signed-off-by: Javier Martinez Canillas Acked-by: Adam Thomson Acked-by: Jingoo Han Signed-off-by: Lee Jones --- drivers/video/backlight/da9052_bl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers/video') diff --git a/drivers/video/backlight/da9052_bl.c b/drivers/video/backlight/da9052_bl.c index fd2be417aa64..49035c12739a 100644 --- a/drivers/video/backlight/da9052_bl.c +++ b/drivers/video/backlight/da9052_bl.c @@ -167,6 +167,7 @@ static const struct platform_device_id da9052_wled_ids[] = { }, { }, }; +MODULE_DEVICE_TABLE(platform, da9052_wled_ids); static struct platform_driver da9052_wled_driver = { .probe = da9052_backlight_probe, @@ -182,4 +183,3 @@ module_platform_driver(da9052_wled_driver); MODULE_AUTHOR("David Dajun Chen "); MODULE_DESCRIPTION("Backlight driver for DA9052 PMIC"); MODULE_LICENSE("GPL"); -MODULE_ALIAS("platform:da9052-backlight"); -- cgit v1.2.3