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

drm/panel-sony-acx424akp: Modernize backlight handling

This converts the internal backlight in the Sony ACX424AKP
driver to do it the canonical way:

- Assign the panel->backlight during probe.
- Let the panel framework handle the backlight.
- Make the backlight .set_brightness() turn the backlight
off completely if blank.
- Fix some dev_err_probe() use cases along the way.

Tested on the U8500 HREF520 reference design.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Reviewed-by: Sam Ravnborg <sam@ravnborg.org>
Link: https://patchwork.freedesktop.org/patch/msgid/20210715092808.1100106-1-linus.walleij@linaro.org

+26 -56
+26 -56
drivers/gpu/drm/panel/panel-sony-acx424akp.c
··· 40 40 struct acx424akp { 41 41 struct drm_panel panel; 42 42 struct device *dev; 43 - struct backlight_device *bl; 44 43 struct regulator *supply; 45 44 struct gpio_desc *reset_gpio; 46 45 bool video_mode; ··· 100 101 u8 pwm_div; 101 102 u8 par; 102 103 int ret; 104 + 105 + if (backlight_is_blank(bl)) { 106 + /* Disable backlight */ 107 + par = 0x00; 108 + ret = mipi_dsi_dcs_write(dsi, MIPI_DCS_WRITE_CONTROL_DISPLAY, 109 + &par, 1); 110 + if (ret) { 111 + dev_err(acx->dev, "failed to disable display backlight (%d)\n", ret); 112 + return ret; 113 + } 114 + return 0; 115 + } 103 116 104 117 /* Calculate the PWM duty cycle in n/256's */ 105 118 pwm_ratio = max(((duty_ns * 256) / period_ns) - 1, 1); ··· 181 170 182 171 static const struct backlight_ops acx424akp_bl_ops = { 183 172 .update_status = acx424akp_set_brightness, 173 + }; 174 + 175 + static const struct backlight_properties acx424akp_bl_props = { 176 + .type = BACKLIGHT_RAW, 177 + .brightness = 512, 178 + .max_brightness = 1023, 184 179 }; 185 180 186 181 static int acx424akp_read_id(struct acx424akp *acx) ··· 327 310 } 328 311 } 329 312 330 - acx->bl->props.power = FB_BLANK_NORMAL; 331 - 332 313 return 0; 333 314 334 315 err_power_off: ··· 338 323 { 339 324 struct acx424akp *acx = panel_to_acx424akp(panel); 340 325 struct mipi_dsi_device *dsi = to_mipi_dsi_device(acx->dev); 341 - u8 par; 342 326 int ret; 343 - 344 - /* Disable backlight */ 345 - par = 0x00; 346 - ret = mipi_dsi_dcs_write(dsi, MIPI_DCS_WRITE_CONTROL_DISPLAY, 347 - &par, 1); 348 - if (ret) { 349 - dev_err(acx->dev, "failed to disable display backlight (%d)\n", ret); 350 - return ret; 351 - } 352 327 353 328 ret = mipi_dsi_dcs_set_display_off(dsi); 354 329 if (ret) { ··· 355 350 msleep(85); 356 351 357 352 acx424akp_power_off(acx); 358 - acx->bl->props.power = FB_BLANK_POWERDOWN; 359 353 360 354 return 0; 361 355 } 362 356 363 - static int acx424akp_enable(struct drm_panel *panel) 364 - { 365 - struct acx424akp *acx = panel_to_acx424akp(panel); 366 - 367 - /* 368 - * The backlight is on as long as the display is on 369 - * so no use to call backlight_enable() here. 370 - */ 371 - acx->bl->props.power = FB_BLANK_UNBLANK; 372 - 373 - return 0; 374 - } 375 - 376 - static int acx424akp_disable(struct drm_panel *panel) 377 - { 378 - struct acx424akp *acx = panel_to_acx424akp(panel); 379 - 380 - /* 381 - * The backlight is on as long as the display is on 382 - * so no use to call backlight_disable() here. 383 - */ 384 - acx->bl->props.power = FB_BLANK_NORMAL; 385 - 386 - return 0; 387 - } 388 357 389 358 static int acx424akp_get_modes(struct drm_panel *panel, 390 359 struct drm_connector *connector) ··· 388 409 } 389 410 390 411 static const struct drm_panel_funcs acx424akp_drm_funcs = { 391 - .disable = acx424akp_disable, 392 412 .unprepare = acx424akp_unprepare, 393 413 .prepare = acx424akp_prepare, 394 - .enable = acx424akp_enable, 395 414 .get_modes = acx424akp_get_modes, 396 415 }; 397 416 ··· 435 458 /* This asserts RESET by default */ 436 459 acx->reset_gpio = devm_gpiod_get_optional(dev, "reset", 437 460 GPIOD_OUT_HIGH); 438 - if (IS_ERR(acx->reset_gpio)) { 439 - ret = PTR_ERR(acx->reset_gpio); 440 - if (ret != -EPROBE_DEFER) 441 - dev_err(dev, "failed to request GPIO (%d)\n", ret); 442 - return ret; 443 - } 461 + if (IS_ERR(acx->reset_gpio)) 462 + return dev_err_probe(dev, PTR_ERR(acx->reset_gpio), 463 + "failed to request GPIO\n"); 444 464 445 465 drm_panel_init(&acx->panel, dev, &acx424akp_drm_funcs, 446 466 DRM_MODE_CONNECTOR_DSI); 447 467 448 - acx->bl = devm_backlight_device_register(dev, "acx424akp", dev, acx, 449 - &acx424akp_bl_ops, NULL); 450 - if (IS_ERR(acx->bl)) { 451 - dev_err(dev, "failed to register backlight device\n"); 452 - return PTR_ERR(acx->bl); 453 - } 454 - acx->bl->props.max_brightness = 1023; 455 - acx->bl->props.brightness = 512; 456 - acx->bl->props.power = FB_BLANK_POWERDOWN; 468 + acx->panel.backlight = devm_backlight_device_register(dev, "acx424akp", dev, acx, 469 + &acx424akp_bl_ops, &acx424akp_bl_props); 470 + if (IS_ERR(acx->panel.backlight)) 471 + return dev_err_probe(dev, PTR_ERR(acx->panel.backlight), 472 + "failed to register backlight device\n"); 457 473 458 474 drm_panel_add(&acx->panel); 459 475