aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPeter Ujfalusi <peter.ujfalusi@ti.com>2016-11-22 08:41:22 -0500
committerLee Jones <lee.jones@linaro.org>2017-01-04 06:37:38 -0500
commit7613c922315e308a6486d802abed2eb74443dffd (patch)
treebbee1fba762af8ce5a7e4a1de8f9cd5fcf8e0e6f
parent0eb3fba8c68275f0122f65f7316efaaf86448016 (diff)
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>
-rw-r--r--drivers/video/backlight/pwm_bl.c56
1 files changed, 37 insertions, 19 deletions
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,
192} 192}
193#endif 193#endif
194 194
195static 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
195static int pwm_backlight_probe(struct platform_device *pdev) 221static int pwm_backlight_probe(struct platform_device *pdev)
196{ 222{
197 struct platform_pwm_backlight_data *data = dev_get_platdata(&pdev->dev); 223 struct platform_pwm_backlight_data *data = dev_get_platdata(&pdev->dev);
@@ -200,7 +226,6 @@ static int pwm_backlight_probe(struct platform_device *pdev)
200 struct backlight_device *bl; 226 struct backlight_device *bl;
201 struct device_node *node = pdev->dev.of_node; 227 struct device_node *node = pdev->dev.of_node;
202 struct pwm_bl_data *pb; 228 struct pwm_bl_data *pb;
203 int initial_blank = FB_BLANK_UNBLANK;
204 struct pwm_args pargs; 229 struct pwm_args pargs;
205 int ret; 230 int ret;
206 231
@@ -267,20 +292,16 @@ static int pwm_backlight_probe(struct platform_device *pdev)
267 pb->enable_gpio = gpio_to_desc(data->enable_gpio); 292 pb->enable_gpio = gpio_to_desc(data->enable_gpio);
268 } 293 }
269 294
270 if (pb->enable_gpio) { 295 /*
271 /* 296 * If the GPIO is configured as input, change the direction to output
272 * If the driver is probed from the device tree and there is a 297 * and set the GPIO as active.
273 * phandle link pointing to the backlight node, it is safe to 298 * Do not force the GPIO to active when it was already output as it
274 * assume that another driver will enable the backlight at the 299 * could cause backlight flickering or we would enable the backlight too
275 * appropriate time. Therefore, if it is disabled, keep it so. 300 * early. Leave the decision of the initial backlight state for later.
276 */ 301 */
277 if (node && node->phandle && 302 if (pb->enable_gpio &&
278 gpiod_get_direction(pb->enable_gpio) == GPIOF_DIR_OUT && 303 gpiod_get_direction(pb->enable_gpio) == GPIOF_DIR_IN)
279 gpiod_get_value(pb->enable_gpio) == 0) 304 gpiod_direction_output(pb->enable_gpio, 1);
280 initial_blank = FB_BLANK_POWERDOWN;
281 else
282 gpiod_direction_output(pb->enable_gpio, 1);
283 }
284 305
285 pb->power_supply = devm_regulator_get(&pdev->dev, "power"); 306 pb->power_supply = devm_regulator_get(&pdev->dev, "power");
286 if (IS_ERR(pb->power_supply)) { 307 if (IS_ERR(pb->power_supply)) {
@@ -288,9 +309,6 @@ static int pwm_backlight_probe(struct platform_device *pdev)
288 goto err_alloc; 309 goto err_alloc;
289 } 310 }
290 311
291 if (node && node->phandle && !regulator_is_enabled(pb->power_supply))
292 initial_blank = FB_BLANK_POWERDOWN;
293
294 pb->pwm = devm_pwm_get(&pdev->dev, NULL); 312 pb->pwm = devm_pwm_get(&pdev->dev, NULL);
295 if (IS_ERR(pb->pwm) && PTR_ERR(pb->pwm) != -EPROBE_DEFER && !node) { 313 if (IS_ERR(pb->pwm) && PTR_ERR(pb->pwm) != -EPROBE_DEFER && !node) {
296 dev_err(&pdev->dev, "unable to request PWM, trying legacy API\n"); 314 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)
347 } 365 }
348 366
349 bl->props.brightness = data->dft_brightness; 367 bl->props.brightness = data->dft_brightness;
350 bl->props.power = initial_blank; 368 bl->props.power = pwm_backlight_initial_power_state(pb);
351 backlight_update_status(bl); 369 backlight_update_status(bl);
352 370
353 platform_set_drvdata(pdev, bl); 371 platform_set_drvdata(pdev, bl);