Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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 <peter.ujfalusi@ti.com>
Reviewed-by: Philipp Zabel <p.zabel@pengutronix.de>
Reviewed-by: Thierry Reding <treding@nvidia.com>
Signed-off-by: Lee Jones <lee.jones@linaro.org>

authored by

Peter Ujfalusi and committed by
Lee Jones
7613c922 0eb3fba8

+37 -19
+37 -19
drivers/video/backlight/pwm_bl.c
··· 192 192 } 193 193 #endif 194 194 195 + static int pwm_backlight_initial_power_state(const struct pwm_bl_data *pb) 196 + { 197 + struct device_node *node = pb->dev->of_node; 198 + 199 + /* Not booted with device tree or no phandle link to the node */ 200 + if (!node || !node->phandle) 201 + return FB_BLANK_UNBLANK; 202 + 203 + /* 204 + * If the driver is probed from the device tree and there is a 205 + * phandle link pointing to the backlight node, it is safe to 206 + * assume that another driver will enable the backlight at the 207 + * appropriate time. Therefore, if it is disabled, keep it so. 208 + */ 209 + 210 + /* if the enable GPIO is disabled, do not enable the backlight */ 211 + if (pb->enable_gpio && gpiod_get_value(pb->enable_gpio) == 0) 212 + return FB_BLANK_POWERDOWN; 213 + 214 + /* The regulator is disabled, do not enable the backlight */ 215 + if (!regulator_is_enabled(pb->power_supply)) 216 + return FB_BLANK_POWERDOWN; 217 + 218 + return FB_BLANK_UNBLANK; 219 + } 220 + 195 221 static int pwm_backlight_probe(struct platform_device *pdev) 196 222 { 197 223 struct platform_pwm_backlight_data *data = dev_get_platdata(&pdev->dev); ··· 226 200 struct backlight_device *bl; 227 201 struct device_node *node = pdev->dev.of_node; 228 202 struct pwm_bl_data *pb; 229 - int initial_blank = FB_BLANK_UNBLANK; 230 203 struct pwm_args pargs; 231 204 int ret; 232 205 ··· 292 267 pb->enable_gpio = gpio_to_desc(data->enable_gpio); 293 268 } 294 269 295 - if (pb->enable_gpio) { 296 - /* 297 - * If the driver is probed from the device tree and there is a 298 - * phandle link pointing to the backlight node, it is safe to 299 - * assume that another driver will enable the backlight at the 300 - * appropriate time. Therefore, if it is disabled, keep it so. 301 - */ 302 - if (node && node->phandle && 303 - gpiod_get_direction(pb->enable_gpio) == GPIOF_DIR_OUT && 304 - gpiod_get_value(pb->enable_gpio) == 0) 305 - initial_blank = FB_BLANK_POWERDOWN; 306 - else 307 - gpiod_direction_output(pb->enable_gpio, 1); 308 - } 270 + /* 271 + * If the GPIO is configured as input, change the direction to output 272 + * and set the GPIO as active. 273 + * Do not force the GPIO to active when it was already output as it 274 + * could cause backlight flickering or we would enable the backlight too 275 + * early. Leave the decision of the initial backlight state for later. 276 + */ 277 + if (pb->enable_gpio && 278 + gpiod_get_direction(pb->enable_gpio) == GPIOF_DIR_IN) 279 + gpiod_direction_output(pb->enable_gpio, 1); 309 280 310 281 pb->power_supply = devm_regulator_get(&pdev->dev, "power"); 311 282 if (IS_ERR(pb->power_supply)) { 312 283 ret = PTR_ERR(pb->power_supply); 313 284 goto err_alloc; 314 285 } 315 - 316 - if (node && node->phandle && !regulator_is_enabled(pb->power_supply)) 317 - initial_blank = FB_BLANK_POWERDOWN; 318 286 319 287 pb->pwm = devm_pwm_get(&pdev->dev, NULL); 320 288 if (IS_ERR(pb->pwm) && PTR_ERR(pb->pwm) != -EPROBE_DEFER && !node) { ··· 365 347 } 366 348 367 349 bl->props.brightness = data->dft_brightness; 368 - bl->props.power = initial_blank; 350 + bl->props.power = pwm_backlight_initial_power_state(pb); 369 351 backlight_update_status(bl); 370 352 371 353 platform_set_drvdata(pdev, bl);