@@ -192,6 +192,32 @@ static int pwm_backlight_parse_dt(struct device *dev,
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 );
@@ -200,7 +226,6 @@ static int pwm_backlight_probe(struct platform_device *pdev)
200
226
struct backlight_device * bl ;
201
227
struct device_node * node = pdev -> dev .of_node ;
202
228
struct pwm_bl_data * pb ;
203
- int initial_blank = FB_BLANK_UNBLANK ;
204
229
struct pwm_args pargs ;
205
230
int ret ;
206
231
@@ -267,30 +292,23 @@ static int pwm_backlight_probe(struct platform_device *pdev)
267
292
pb -> enable_gpio = gpio_to_desc (data -> enable_gpio );
268
293
}
269
294
270
- if (pb -> enable_gpio ) {
271
- /*
272
- * If the driver is probed from the device tree and there is a
273
- * phandle link pointing to the backlight node, it is safe to
274
- * assume that another driver will enable the backlight at the
275
- * appropriate time. Therefore, if it is disabled, keep it so.
276
- */
277
- if (node && node -> phandle &&
278
- gpiod_get_direction (pb -> enable_gpio ) == GPIOF_DIR_OUT &&
279
- gpiod_get_value (pb -> enable_gpio ) == 0 )
280
- initial_blank = FB_BLANK_POWERDOWN ;
281
- else
282
- gpiod_direction_output (pb -> enable_gpio , 1 );
283
- }
295
+ /*
296
+ * If the GPIO is configured as input, change the direction to output
297
+ * and set the GPIO as active.
298
+ * Do not force the GPIO to active when it was already output as it
299
+ * could cause backlight flickering or we would enable the backlight too
300
+ * early. Leave the decision of the initial backlight state for later.
301
+ */
302
+ if (pb -> enable_gpio &&
303
+ gpiod_get_direction (pb -> enable_gpio ) == GPIOF_DIR_IN )
304
+ gpiod_direction_output (pb -> enable_gpio , 1 );
284
305
285
306
pb -> power_supply = devm_regulator_get (& pdev -> dev , "power" );
286
307
if (IS_ERR (pb -> power_supply )) {
287
308
ret = PTR_ERR (pb -> power_supply );
288
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
312
pb -> pwm = devm_pwm_get (& pdev -> dev , NULL );
295
313
if (IS_ERR (pb -> pwm ) && PTR_ERR (pb -> pwm ) != - EPROBE_DEFER && !node ) {
296
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
367
bl -> props .brightness = data -> dft_brightness ;
350
- bl -> props .power = initial_blank ;
368
+ bl -> props .power = pwm_backlight_initial_power_state ( pb ) ;
351
369
backlight_update_status (bl );
352
370
353
371
platform_set_drvdata (pdev , bl );
0 commit comments