Skip to contentSkip to conversation

drm/panel: kingdisplay-kd097d04: Use mipi_dsi_*_multi() functions

PATCH Superseded Archit More 2 participants 2 messages Nov 10

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/panel: kingdisplay-kd097d04: Use mipi_dsi_*_multi() functions

The mipi_dsi_dcs_*() and mipi_dsi_generic_write() functions used by this driver are deprecated in favor of their _multi() counterparts, as noted in Documentation/gpu/todo.rst.

Convert disable(), unprepare(), and prepare() to use the _multi() APIs.

---
 .../drm/panel/panel-kingdisplay-kd097d04.c    | 54 ++++++-------------
 1 file changed, 17 insertions(+), 37 deletions(-)
drivers/gpu/drm/panel/panel-kingdisplay-kd097d04.c +17 -37
index 893af9b16756..01f5a96f1cfb 100644
@@ -180,28 +180,21 @@ struct kingdisplay_panel *to_kingdisplay_panel(struct drm_panel *panel)
 static int kingdisplay_panel_disable(struct drm_panel *panel)
 {
 	struct kingdisplay_panel *kingdisplay = to_kingdisplay_panel(panel);
-	int err;
+	struct mipi_dsi_multi_context dsi_ctx = { .dsi = kingdisplay->link };
 
-	err = mipi_dsi_dcs_set_display_off(kingdisplay->link);
-	if (err < 0)
-		dev_err(panel->dev, "failed to set display off: %d\n", err);
+	mipi_dsi_dcs_set_display_off_multi(&dsi_ctx);
 
-	return 0;
+	return dsi_ctx.accum_err;
 }
 
 static int kingdisplay_panel_unprepare(struct drm_panel *panel)
 {
 	struct kingdisplay_panel *kingdisplay = to_kingdisplay_panel(panel);
+	struct mipi_dsi_multi_context dsi_ctx = { .dsi = kingdisplay->link };
 	int err;
 
-	err = mipi_dsi_dcs_enter_sleep_mode(kingdisplay->link);
-	if (err < 0) {
-		dev_err(panel->dev, "failed to enter sleep mode: %d\n", err);
-		return err;
-	}
-
-	/* T15: 120ms */
-	msleep(120);
+	mipi_dsi_dcs_enter_sleep_mode_multi(&dsi_ctx);
+	mipi_dsi_msleep(&dsi_ctx, 120);
 
 	gpiod_set_value_cansleep(kingdisplay->enable_gpio, 0);
 
@@ -209,12 +202,13 @@ static int kingdisplay_panel_unprepare(struct drm_panel *panel)
 	if (err < 0)
 		return err;
 
-	return 0;
+	return dsi_ctx.accum_err;
 }
 
 static int kingdisplay_panel_prepare(struct drm_panel *panel)
 {
 	struct kingdisplay_panel *kingdisplay = to_kingdisplay_panel(panel);
+	struct mipi_dsi_multi_context dsi_ctx = { .dsi = kingdisplay->link };
 	int err, regulator_err;
 	unsigned int i;
 
@@ -232,32 +226,18 @@ static int kingdisplay_panel_prepare(struct drm_panel *panel)
 	/* T4: 15ms */
 	usleep_range(15000, 16000);
 
-	for (i = 0; i < ARRAY_SIZE(init_code); i++) {
-		err = mipi_dsi_generic_write(kingdisplay->link, &init_code[i],
-					sizeof(struct kingdisplay_panel_cmd));
-		if (err < 0) {
-			dev_err(panel->dev, "failed write init cmds: %d\n", err);
-			goto poweroff;
-		}
-	}
+	for (i = 0; i < ARRAY_SIZE(init_code); i++)
+		mipi_dsi_generic_write_multi(&dsi_ctx, &init_code[i],
+					     sizeof(struct kingdisplay_panel_cmd));
 
-	err = mipi_dsi_dcs_exit_sleep_mode(kingdisplay->link);
-	if (err < 0) {
-		dev_err(panel->dev, "failed to exit sleep mode: %d\n", err);
-		goto poweroff;
-	}
+	mipi_dsi_dcs_exit_sleep_mode_multi(&dsi_ctx);
+	mipi_dsi_msleep(&dsi_ctx, 120);
 
-	/* T6: 120ms */
-	msleep(120);
+	mipi_dsi_dcs_set_display_on_multi(&dsi_ctx);
+	mipi_dsi_usleep_range(&dsi_ctx, 10000, 11000);
 
-	err = mipi_dsi_dcs_set_display_on(kingdisplay->link);
-	if (err < 0) {
-		dev_err(panel->dev, "failed to set display on: %d\n", err);
+	if (dsi_ctx.accum_err)
 		goto poweroff;
-	}
-
-	/* T7: 10ms */
-	usleep_range(10000, 11000);
 
 	return 0;
 
@@ -268,7 +248,7 @@ static int kingdisplay_panel_prepare(struct drm_panel *panel)
 	if (regulator_err)
 		dev_err(panel->dev, "failed to disable regulator: %d\n", regulator_err);
 
-	return err;
+	return dsi_ctx.accum_err;
 }
 
 static const struct drm_display_mode default_mode = {
Signature · 1 line
2.34.1
#1 lore raw
Thank you for your contribution! Sashiko AI review found 2 potential issues to consider: - [Medium] drm/panel: state imbalance in kingdisplay_panel_unprepare() on DSI error - [Medium] drm/panel…

Thank you for your contribution! Sashiko AI review found 2 potential issues to consider:
- [Medium] drm/panel: state imbalance in kingdisplay_panel_unprepare() on DSI error
- [Medium] drm/panel: kingdisplay_panel_disable() error return leaves panel enabled
--

commit ce1c20733cce84cf65434f3ef6732b56a7367cda
Author: Archit More <[email protected]>

drm/panel: kingdisplay-kd097d04: Use mipi_dsi_*_multi() functions

This commit converts the Kingdisplay KD097D04 panel driver's disable, unprepare, and prepare callbacks to use the mipi_dsi_*_multi() helpers.

Quoted 9 lines
drivers/gpu/drm/panel/panel-kingdisplay-kd097d04.c +0 -1
index 893af9b167567..01f5a96f1cfbf 100644
@@ -180,28 +180,21 @@ struct kingdisplay_panel *to_kingdisplay_panel(struct drm_panel *panel)
 static int kingdisplay_panel_disable(struct drm_panel *panel)
 {
 	struct kingdisplay_panel *kingdisplay = to_kingdisplay_panel(panel);
-	int err;

drivers/gpu/drm/panel/panel-kingdisplay-kd097d04.c struct kingdisplay_panel *to_kingdisplay_panel(struct drm_panel *panel) · line 188

Quoted 10 lines
drivers/gpu/drm/panel/panel-kingdisplay-kd097d04.c +3 -4
+	struct mipi_dsi_multi_context dsi_ctx = { .dsi = kingdisplay->link };
 
-	err = mipi_dsi_dcs_set_display_off(kingdisplay->link);
-	if (err < 0)
-		dev_err(panel->dev, "failed to set display off: %d\n", err);
+	mipi_dsi_dcs_set_display_off_multi(&dsi_ctx);
 
-	return 0;
+	return dsi_ctx.accum_err;
 }

[Severity: Medium]
Should kingdisplay_panel_disable() still return 0 here?

In drm_panel_disable(), the backlight is disabled before calling panel->funcs->disable(), and a negative return value skips clearing panel->enabled. If mipi_dsi_dcs_set_display_off_multi() fails, panel->enabled remains true and the next drm_panel_enable() returns early without re-enabling the backlight.

Quoted 20 lines
drivers/gpu/drm/panel/panel-kingdisplay-kd097d04.c +3 -8
 static int kingdisplay_panel_unprepare(struct drm_panel *panel)
 {
 	struct kingdisplay_panel *kingdisplay = to_kingdisplay_panel(panel);
+	struct mipi_dsi_multi_context dsi_ctx = { .dsi = kingdisplay->link };
 	int err;
 
-	err = mipi_dsi_dcs_enter_sleep_mode(kingdisplay->link);
-	if (err < 0) {
-		dev_err(panel->dev, "failed to enter sleep mode: %d\n", err);
-		return err;
-	}
-
-	/* T15: 120ms */
-	msleep(120);
+	mipi_dsi_dcs_enter_sleep_mode_multi(&dsi_ctx);
+	mipi_dsi_msleep(&dsi_ctx, 120);
 
 	gpiod_set_value_cansleep(kingdisplay->enable_gpio, 0);
 

drivers/gpu/drm/panel/panel-kingdisplay-kd097d04.c static int kingdisplay_panel_unprepare(struct drm_panel *panel) · line 206

Quoted 6 lines
drivers/gpu/drm/panel/panel-kingdisplay-kd097d04.c +1 -1
@@ -209,12 +202,13 @@ static int kingdisplay_panel_unprepare(struct drm_panel *panel)
 	if (err < 0)
 		return err;
 
-	return 0;
+	return dsi_ctx.accum_err;
 }

[Severity: Medium]
Does returning dsi_ctx.accum_err after disabling kingdisplay->supply leave panel->prepared out of sync with the hardware state?

When mipi_dsi_dcs_enter_sleep_mode_multi() fails, this function still deasserts enable_gpio and disables kingdisplay->supply, but returns a negative error code to drm_panel_unprepare(), which then skips setting panel->prepared = false. The next drm_panel_prepare() sees panel->prepared as true and skips powering the panel back on, while a subsequent drm_panel_unprepare() calls regulator_disable() a second time and underflows the regulator enable count.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1