Skip to content

Commit 7835ed6

Browse files
committed
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 <[email protected]> Reviewed-by: Sam Ravnborg <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected]
1 parent 28be240 commit 7835ed6

File tree

1 file changed

+26
-56
lines changed

1 file changed

+26
-56
lines changed

drivers/gpu/drm/panel/panel-sony-acx424akp.c

Lines changed: 26 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
struct acx424akp {
4141
struct drm_panel panel;
4242
struct device *dev;
43-
struct backlight_device *bl;
4443
struct regulator *supply;
4544
struct gpio_desc *reset_gpio;
4645
bool video_mode;
@@ -102,6 +101,18 @@ static int acx424akp_set_brightness(struct backlight_device *bl)
102101
u8 par;
103102
int ret;
104103

104+
if (backlight_is_blank(bl)) {
105+
/* Disable backlight */
106+
par = 0x00;
107+
ret = mipi_dsi_dcs_write(dsi, MIPI_DCS_WRITE_CONTROL_DISPLAY,
108+
&par, 1);
109+
if (ret) {
110+
dev_err(acx->dev, "failed to disable display backlight (%d)\n", ret);
111+
return ret;
112+
}
113+
return 0;
114+
}
115+
105116
/* Calculate the PWM duty cycle in n/256's */
106117
pwm_ratio = max(((duty_ns * 256) / period_ns) - 1, 1);
107118
pwm_div = max(1,
@@ -172,6 +183,12 @@ static const struct backlight_ops acx424akp_bl_ops = {
172183
.update_status = acx424akp_set_brightness,
173184
};
174185

186+
static const struct backlight_properties acx424akp_bl_props = {
187+
.type = BACKLIGHT_RAW,
188+
.brightness = 512,
189+
.max_brightness = 1023,
190+
};
191+
175192
static int acx424akp_read_id(struct acx424akp *acx)
176193
{
177194
struct mipi_dsi_device *dsi = to_mipi_dsi_device(acx->dev);
@@ -310,8 +327,6 @@ static int acx424akp_prepare(struct drm_panel *panel)
310327
}
311328
}
312329

313-
acx->bl->props.power = FB_BLANK_NORMAL;
314-
315330
return 0;
316331

317332
err_power_off:
@@ -323,18 +338,8 @@ static int acx424akp_unprepare(struct drm_panel *panel)
323338
{
324339
struct acx424akp *acx = panel_to_acx424akp(panel);
325340
struct mipi_dsi_device *dsi = to_mipi_dsi_device(acx->dev);
326-
u8 par;
327341
int ret;
328342

329-
/* Disable backlight */
330-
par = 0x00;
331-
ret = mipi_dsi_dcs_write(dsi, MIPI_DCS_WRITE_CONTROL_DISPLAY,
332-
&par, 1);
333-
if (ret) {
334-
dev_err(acx->dev, "failed to disable display backlight (%d)\n", ret);
335-
return ret;
336-
}
337-
338343
ret = mipi_dsi_dcs_set_display_off(dsi);
339344
if (ret) {
340345
dev_err(acx->dev, "failed to turn display off (%d)\n", ret);
@@ -350,36 +355,10 @@ static int acx424akp_unprepare(struct drm_panel *panel)
350355
msleep(85);
351356

352357
acx424akp_power_off(acx);
353-
acx->bl->props.power = FB_BLANK_POWERDOWN;
354-
355-
return 0;
356-
}
357-
358-
static int acx424akp_enable(struct drm_panel *panel)
359-
{
360-
struct acx424akp *acx = panel_to_acx424akp(panel);
361-
362-
/*
363-
* The backlight is on as long as the display is on
364-
* so no use to call backlight_enable() here.
365-
*/
366-
acx->bl->props.power = FB_BLANK_UNBLANK;
367358

368359
return 0;
369360
}
370361

371-
static int acx424akp_disable(struct drm_panel *panel)
372-
{
373-
struct acx424akp *acx = panel_to_acx424akp(panel);
374-
375-
/*
376-
* The backlight is on as long as the display is on
377-
* so no use to call backlight_disable() here.
378-
*/
379-
acx->bl->props.power = FB_BLANK_NORMAL;
380-
381-
return 0;
382-
}
383362

384363
static int acx424akp_get_modes(struct drm_panel *panel,
385364
struct drm_connector *connector)
@@ -409,10 +388,8 @@ static int acx424akp_get_modes(struct drm_panel *panel,
409388
}
410389

411390
static const struct drm_panel_funcs acx424akp_drm_funcs = {
412-
.disable = acx424akp_disable,
413391
.unprepare = acx424akp_unprepare,
414392
.prepare = acx424akp_prepare,
415-
.enable = acx424akp_enable,
416393
.get_modes = acx424akp_get_modes,
417394
};
418395

@@ -458,25 +435,18 @@ static int acx424akp_probe(struct mipi_dsi_device *dsi)
458435
/* This asserts RESET by default */
459436
acx->reset_gpio = devm_gpiod_get_optional(dev, "reset",
460437
GPIOD_OUT_HIGH);
461-
if (IS_ERR(acx->reset_gpio)) {
462-
ret = PTR_ERR(acx->reset_gpio);
463-
if (ret != -EPROBE_DEFER)
464-
dev_err(dev, "failed to request GPIO (%d)\n", ret);
465-
return ret;
466-
}
438+
if (IS_ERR(acx->reset_gpio))
439+
return dev_err_probe(dev, PTR_ERR(acx->reset_gpio),
440+
"failed to request GPIO\n");
467441

468442
drm_panel_init(&acx->panel, dev, &acx424akp_drm_funcs,
469443
DRM_MODE_CONNECTOR_DSI);
470444

471-
acx->bl = devm_backlight_device_register(dev, "acx424akp", dev, acx,
472-
&acx424akp_bl_ops, NULL);
473-
if (IS_ERR(acx->bl)) {
474-
dev_err(dev, "failed to register backlight device\n");
475-
return PTR_ERR(acx->bl);
476-
}
477-
acx->bl->props.max_brightness = 1023;
478-
acx->bl->props.brightness = 512;
479-
acx->bl->props.power = FB_BLANK_POWERDOWN;
445+
acx->panel.backlight = devm_backlight_device_register(dev, "acx424akp", dev, acx,
446+
&acx424akp_bl_ops, &acx424akp_bl_props);
447+
if (IS_ERR(acx->panel.backlight))
448+
return dev_err_probe(dev, PTR_ERR(acx->panel.backlight),
449+
"failed to register backlight device\n");
480450

481451
drm_panel_add(&acx->panel);
482452

0 commit comments

Comments
 (0)