Skip to contentSkip to conversation

drm/panel: jdi-lt070me05000: Use MIPI DSI multi functions

PATCH Superseded Chintan Patel 2 participants 2 messages Jan 31

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/panel: jdi-lt070me05000: Use MIPI DSI multi functions

Convert to the non-deprecated mipi_dsi_*_multi() helpers per the TODO list. These reduce boilerplate error checking while providing proper error accumulation via mipi_dsi_multi_context.

Also use mipi_dsi_msleep()/mipi_dsi_usleep_range() macros for all delays, which automatically skip on error.

---
 .../gpu/drm/panel/panel-jdi-lt070me05000.c    | 105 ++++--------------
 1 file changed, 23 insertions(+), 82 deletions(-)
drivers/gpu/drm/panel/panel-jdi-lt070me05000.c +23 -82
index 3513e5c4dd8c..50272364d9d4 100644
@@ -48,34 +48,16 @@ static inline struct jdi_panel *to_jdi_panel(struct drm_panel *panel)
 static int jdi_panel_init(struct jdi_panel *jdi)
 {
 	struct mipi_dsi_device *dsi = jdi->dsi;
-	struct device *dev = &jdi->dsi->dev;
-	int ret;
+	struct mipi_dsi_multi_context dsi_ctx = { .dsi = dsi };
 
 	dsi->mode_flags |= MIPI_DSI_MODE_LPM;
 
-	ret = mipi_dsi_dcs_soft_reset(dsi);
-	if (ret < 0)
-		return ret;
-
-	usleep_range(10000, 20000);
-
-	ret = mipi_dsi_dcs_set_pixel_format(dsi, MIPI_DCS_PIXEL_FMT_24BIT << 4);
-	if (ret < 0) {
-		dev_err(dev, "failed to set pixel format: %d\n", ret);
-		return ret;
-	}
-
-	ret = mipi_dsi_dcs_set_column_address(dsi, 0, jdi->mode->hdisplay - 1);
-	if (ret < 0) {
-		dev_err(dev, "failed to set column address: %d\n", ret);
-		return ret;
-	}
+	mipi_dsi_dcs_soft_reset_multi(&dsi_ctx);
+	mipi_dsi_usleep_range(&dsi_ctx, 10000, 20000);
 
-	ret = mipi_dsi_dcs_set_page_address(dsi, 0, jdi->mode->vdisplay - 1);
-	if (ret < 0) {
-		dev_err(dev, "failed to set page address: %d\n", ret);
-		return ret;
-	}
+	mipi_dsi_dcs_set_pixel_format_multi(&dsi_ctx, MIPI_DCS_PIXEL_FMT_24BIT << 4);
+	mipi_dsi_dcs_set_column_address_multi(&dsi_ctx, 0, jdi->mode->hdisplay - 1);
+	mipi_dsi_dcs_set_page_address_multi(&dsi_ctx, 0, jdi->mode->vdisplay - 1);
 
 	/*
 	 * BIT(5) BCTRL = 1 Backlight Control Block On, Brightness registers
@@ -83,90 +65,49 @@ static int jdi_panel_init(struct jdi_panel *jdi)
 	 * BIT(3) BL = 1    Backlight Control On
 	 * BIT(2) DD = 0    Display Dimming is Off
 	 */
-	ret = mipi_dsi_dcs_write(dsi, MIPI_DCS_WRITE_CONTROL_DISPLAY,
-				 (u8[]){ 0x24 }, 1);
-	if (ret < 0) {
-		dev_err(dev, "failed to write control display: %d\n", ret);
-		return ret;
-	}
+	mipi_dsi_dcs_write_seq_multi(&dsi_ctx, MIPI_DCS_WRITE_CONTROL_DISPLAY, 0x24);
 
 	/* CABC off */
-	ret = mipi_dsi_dcs_write(dsi, MIPI_DCS_WRITE_POWER_SAVE,
-				 (u8[]){ 0x00 }, 1);
-	if (ret < 0) {
-		dev_err(dev, "failed to set cabc off: %d\n", ret);
-		return ret;
-	}
+	mipi_dsi_dcs_write_seq_multi(&dsi_ctx, MIPI_DCS_WRITE_POWER_SAVE, 0x00);
 
-	ret = mipi_dsi_dcs_exit_sleep_mode(dsi);
-	if (ret < 0) {
-		dev_err(dev, "failed to set exit sleep mode: %d\n", ret);
-		return ret;
-	}
-
-	msleep(120);
-
-	ret = mipi_dsi_generic_write(dsi, (u8[]){0xB0, 0x00}, 2);
-	if (ret < 0) {
-		dev_err(dev, "failed to set mcap: %d\n", ret);
-		return ret;
-	}
+	mipi_dsi_dcs_exit_sleep_mode_multi(&dsi_ctx);
+	mipi_dsi_msleep(&dsi_ctx, 120);
 
-	mdelay(10);
+	mipi_dsi_generic_write_multi(&dsi_ctx, (u8[]){0xB0, 0x00}, 2);
+	mipi_dsi_msleep(&dsi_ctx, 10);
 
 	/* Interface setting, video mode */
-	ret = mipi_dsi_generic_write(dsi, (u8[])
-				     {0xB3, 0x26, 0x08, 0x00, 0x20, 0x00}, 6);
-	if (ret < 0) {
-		dev_err(dev, "failed to set display interface setting: %d\n"
-			, ret);
-		return ret;
-	}
+	mipi_dsi_generic_write_multi(&dsi_ctx, (u8[]){0xB3, 0x26, 0x08, 0x00, 0x20, 0x00}, 6);
+	mipi_dsi_msleep(&dsi_ctx, 20);
 
-	mdelay(20);
+	mipi_dsi_generic_write_multi(&dsi_ctx, (u8[]){0xB0, 0x03}, 2);
 
-	ret = mipi_dsi_generic_write(dsi, (u8[]){0xB0, 0x03}, 2);
-	if (ret < 0) {
-		dev_err(dev, "failed to set default values for mcap: %d\n"
-			, ret);
-		return ret;
-	}
-
-	return 0;
+	return dsi_ctx.accum_err;
 }
 
 static int jdi_panel_on(struct jdi_panel *jdi)
 {
 	struct mipi_dsi_device *dsi = jdi->dsi;
-	struct device *dev = &jdi->dsi->dev;
-	int ret;
+	struct mipi_dsi_multi_context dsi_ctx = { .dsi = dsi };
 
 	dsi->mode_flags |= MIPI_DSI_MODE_LPM;
 
-	ret = mipi_dsi_dcs_set_display_on(dsi);
-	if (ret < 0)
-		dev_err(dev, "failed to set display on: %d\n", ret);
+	mipi_dsi_dcs_set_display_on_multi(&dsi_ctx);
 
-	return ret;
+	return dsi_ctx.accum_err;
 }
 
 static void jdi_panel_off(struct jdi_panel *jdi)
 {
 	struct mipi_dsi_device *dsi = jdi->dsi;
-	struct device *dev = &jdi->dsi->dev;
-	int ret;
+	struct mipi_dsi_multi_context dsi_ctx = { .dsi = dsi };
 
 	dsi->mode_flags &= ~MIPI_DSI_MODE_LPM;
 
-	ret = mipi_dsi_dcs_set_display_off(dsi);
-	if (ret < 0)
-		dev_err(dev, "failed to set display off: %d\n", ret);
-
-	ret = mipi_dsi_dcs_enter_sleep_mode(dsi);
-	if (ret < 0)
-		dev_err(dev, "failed to enter sleep mode: %d\n", ret);
+	mipi_dsi_dcs_set_display_off_multi(&dsi_ctx);
+	mipi_dsi_dcs_enter_sleep_mode_multi(&dsi_ctx);
 
-	msleep(100);
+	mipi_dsi_msleep(&dsi_ctx, 100);
 }
 
 static int jdi_panel_disable(struct drm_panel *panel)
Signature · 1 line
2.43.0
#1 lore raw

Hi,

Quoted 9 lines · Chintan Patel

Convert to the non-deprecated mipi_dsi_*_multi() helpers per the TODO list. These reduce boilerplate error checking while providing proper error accumulation via mipi_dsi_multi_context.

Also use mipi_dsi_msleep()/mipi_dsi_usleep_range() macros for all delays, which automatically skip on error.

I'd skip my Suggested-by here. I'm already on the TODO. ;-)

drivers/gpu/drm/panel/panel-jdi-lt070me05000.c static int jdi_panel_init(struct jdi_panel *jdi) · line 115

Quoted 11 lines
drivers/gpu/drm/panel/panel-jdi-lt070me05000.c +2 -8
-       msleep(120);
-
-       ret = mipi_dsi_generic_write(dsi, (u8[]){0xB0, 0x00}, 2);
-       if (ret < 0) {
-               dev_err(dev, "failed to set mcap: %d\n", ret);
-               return ret;
-       }
+       mipi_dsi_dcs_exit_sleep_mode_multi(&dsi_ctx);
+       mipi_dsi_msleep(&dsi_ctx, 120);
 
-       mdelay(10);

It's worth noting that the old code used a "mdelay" instead of a "msleep" here. ...but I recognize that there is no "mipi_dsi_mdelay". It's _probably_ OK to change this and we've already got other sleeping calls in this function, but it could change the amount of delay a bit.

People always have fun bikeshedding about when to use the various delays, but IMO slightly better in this case would be to change this to the "usleep_range" call instead of "msleep". For functions like this that aren't run very often, you probably don't want a very large slop, so the mdelay(10) could probably be mipi_dsi_usleep_range(10000, 11000) and the later mdelay(20) could probably be mipi_dsi_usleep_range(20000, 21000). You'd probably want to at least mention this change in the commit message.

I'd leave the preexisting usleep_range(10000, 20000) with the preexisting 10ms slop just to be on the safe side.

Quoted 1 line

+ mipi_dsi_generic_write_multi(&dsi_ctx, (u8[]){0xB0, 0x00}, 2);

FWIW, instead of the above I believe it's cleaner to do this:

mipi_dsi_generic_write_seq_multi(&dsi_ctx, 0xb0, 0x00);

...it's probably worth changing to that while you're doing your cleanup?

I'll also note that lowercase hex (0xb0 instead of 0xB0) is the preferred style of the Linux kernel, so maybe switch to that as you're touching the code, too?

Quoted 8 lines

static void jdi_panel_off(struct jdi_panel *jdi)

 {
        struct mipi_dsi_device *dsi = jdi->dsi;
drivers/gpu/drm/panel/panel-jdi-lt070me05000.c +1 -2
-       struct device *dev = &jdi->dsi->dev;
-       int ret;
+       struct mipi_dsi_multi_context dsi_ctx = { .dsi = dsi };
 
        dsi->mode_flags &= ~MIPI_DSI_MODE_LPM;

drivers/gpu/drm/panel/panel-jdi-lt070me05000.c static int jdi_panel_init(struct jdi_panel *jdi) · line 108

Quoted 10 lines
drivers/gpu/drm/panel/panel-jdi-lt070me05000.c +2 -7
 
-       ret = mipi_dsi_dcs_set_display_off(dsi);
-       if (ret < 0)
-               dev_err(dev, "failed to set display off: %d\n", ret);
-
-       ret = mipi_dsi_dcs_enter_sleep_mode(dsi);
-       if (ret < 0)
-               dev_err(dev, "failed to enter sleep mode: %d\n", ret);
+       mipi_dsi_dcs_set_display_off_multi(&dsi_ctx);
+       mipi_dsi_dcs_enter_sleep_mode_multi(&dsi_ctx);

The old code still runs the "enter sleep mode" even if the "set display off" failed. This is probably on purpose. Power down code often ignores errors (other than reporting them) and continues on because there's not really better choices.

In this sense, you probably want a dsi_ctx.accum_err = 0 between the above two commands.

drivers/gpu/drm/panel/panel-jdi-lt070me05000.c static int jdi_panel_init(struct jdi_panel *jdi) · line 110

Quoted 2 lines
drivers/gpu/drm/panel/panel-jdi-lt070me05000.c +1 -1
-       msleep(100);
+       mipi_dsi_msleep(&dsi_ctx, 100);

Let's keep it as "msleep(100)". Old code would have slept here even if there were errors, and that could possibly make sense in power off. Let's preserve the old behavior. That makes sure even if there some errors we sleep enough before we start turning off regulators / GPIOs.