drm/panel: novatek-nt36672a: Convert to mipi_dsi_*_multi() helpers
PATCH v2 1/1 drm/panel: novatek-nt36672a: Convert to mipi_dsi_*_multi() helpers
Convert the driver to use the non-deprecated mipi_dsi_*_multi() helpers and mipi_dsi_msleep().
Switch DCS command sequences to the multi context API and accumulate errors via struct mipi_dsi_multi_context. Replace open-coded error handling with the multi helpers and convert nt36672a_send_cmds() and power sequencing accordingly.
---
Changes in v2:
- Address alignment feedback from Doug.
- Restore original power-down ordering.
- Drop return value from nt36672a_panel_power_off().
- Consolidate error handling around dsi_ctx.accum_err.
.../gpu/drm/panel/panel-novatek-nt36672a.c | 98 ++++++------------- 1 file changed, 30 insertions(+), 68 deletions(-)
drivers/gpu/drm/panel/panel-novatek-nt36672a.c +30 -68
@@ -79,70 +79,53 @@ static inline struct nt36672a_panel *to_nt36672a_panel(struct drm_panel *panel) return container_of(panel, struct nt36672a_panel, base); } -static int nt36672a_send_cmds (struct drm_panel *panel,const struct nt36672a_panel_cmd *cmds, -int num) +static void nt36672a_send_cmds (struct mipi_dsi_multi_context *dsi_ctx, +const struct nt36672a_panel_cmd *cmds,int num) { -struct nt36672a_panel *pinfo =to_nt36672a_panel (panel);unsigned int i; -int err;for (i =0 ; i < num; i++) {const struct nt36672a_panel_cmd *cmd = &cmds[i]; - err =mipi_dsi_dcs_write (pinfo->link, cmd->data[0 ], cmd->data +1 ,1 ); - -if (err <0 ) -return err; +/* cmd->data[0] is the DCS command, cmd->data[1] is the parameter */ +mipi_dsi_dcs_write_buffer_multi (dsi_ctx, cmd->data,sizeof (cmd->data)); } - -return 0 ; } -static int nt36672a_panel_power_off (struct drm_panel *panel) +static void nt36672a_panel_power_off (struct drm_panel *panel) {struct nt36672a_panel *pinfo =to_nt36672a_panel (panel); -int ret =0 ;gpiod_set_value (pinfo->reset_gpio,1 ); - ret =regulator_bulk_disable (ARRAY_SIZE (pinfo->supplies), pinfo->supplies); -if (ret) -dev_err (panel->dev,"regulator_bulk_disable failed %d\n" , ret); - -return ret; +if (regulator_bulk_disable (ARRAY_SIZE (pinfo->supplies), pinfo->supplies) <0 ) +dev_err (panel->dev,"regulator_bulk_disable failed\n" ); }static int nt36672a_panel_unprepare (struct drm_panel *panel) {struct nt36672a_panel *pinfo =to_nt36672a_panel (panel); -int ret; +struct mipi_dsi_multi_context dsi_ctx = { .dsi = pinfo->link };/* send off cmds */ - ret =nt36672a_send_cmds (panel, pinfo->desc->off_cmds, - pinfo->desc->num_off_cmds); +nt36672a_send_cmds (&dsi_ctx, pinfo->desc->off_cmds, + pinfo->desc->num_off_cmds); -if (ret <0 ) -dev_err (panel->dev,"failed to send DCS off cmds: %d\n" , ret); - - ret =mipi_dsi_dcs_set_display_off (pinfo->link); -if (ret <0 ) -dev_err (panel->dev,"set_display_off cmd failed ret = %d\n" , ret); +mipi_dsi_dcs_set_display_off_multi (&dsi_ctx); +/* Reset error to continue power-down even if display off failed */ + dsi_ctx.accum_err =0 ;/* 120ms delay required here as per DCS spec */ msleep (120 ); - ret =mipi_dsi_dcs_enter_sleep_mode (pinfo->link); -if (ret <0 ) -dev_err (panel->dev,"enter_sleep cmd failed ret = %d\n" , ret); +mipi_dsi_dcs_enter_sleep_mode_multi (&dsi_ctx);/* 0x3C = 60ms delay */ -msleep (60 ); +mipi_dsi_msleep (&dsi_ctx,60 ); - ret =nt36672a_panel_power_off (panel); -if (ret <0 ) -dev_err (panel->dev,"power_off failed ret = %d\n" , ret); +nt36672a_panel_power_off (panel); -return ret; +return 0 ; }static int nt36672a_panel_power_on (struct nt36672a_panel *pinfo)
@@ -170,52 +153,31 @@ static int nt36672a_panel_power_on(struct nt36672a_panel *pinfo)static int nt36672a_panel_prepare (struct drm_panel *panel) {struct nt36672a_panel *pinfo =to_nt36672a_panel (panel); -int err; +struct mipi_dsi_multi_context dsi_ctx = { .dsi = pinfo->link }; - err =nt36672a_panel_power_on (pinfo); -if (err <0 ) - goto poweroff; + dsi_ctx.accum_err =nt36672a_panel_power_on (pinfo);/* send first part of init cmds */ - err =nt36672a_send_cmds (panel, pinfo->desc->on_cmds_1, - pinfo->desc->num_on_cmds_1); +nt36672a_send_cmds (&dsi_ctx, pinfo->desc->on_cmds_1, + pinfo->desc->num_on_cmds_1); -if (err <0 ) { -dev_err (panel->dev,"failed to send DCS Init 1st Code: %d\n" , err); - goto poweroff; - } - - err =mipi_dsi_dcs_exit_sleep_mode (pinfo->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);/* 0x46 = 70 ms delay */ -msleep (70 ); +mipi_dsi_msleep (&dsi_ctx,70 ); - err =mipi_dsi_dcs_set_display_on (pinfo->link); -if (err <0 ) { -dev_err (panel->dev,"failed to Set Display ON: %d\n" , err); - goto poweroff; - } +mipi_dsi_dcs_set_display_on_multi (&dsi_ctx);/* Send rest of the init cmds */ - err =nt36672a_send_cmds (panel, pinfo->desc->on_cmds_2, - pinfo->desc->num_on_cmds_2); +nt36672a_send_cmds (&dsi_ctx, pinfo->desc->on_cmds_2, + pinfo->desc->num_on_cmds_2); -if (err <0 ) { -dev_err (panel->dev,"failed to send DCS Init 2nd Code: %d\n" , err); - goto poweroff; - } +mipi_dsi_msleep (&dsi_ctx,120 ); -msleep (120 ); +if (dsi_ctx.accum_err <0 ) +gpiod_set_value (pinfo->reset_gpio,0 ); -return 0 ; - -poweroff: -gpiod_set_value (pinfo->reset_gpio,0 ); -return err; +return dsi_ctx.accum_err; } static int nt36672a_panel_get_modes(struct drm_panel *panel,
Signature · 1 line
2.43.0
Hi,
Quoted 6 lines · Chintan Patel
drivers/gpu/drm/panel/panel-novatek-nt36672a.c +1
-2-static int nt36672a_panel_power_off (struct drm_panel *panel) +static void nt36672a_panel_power_off (struct drm_panel *panel) {struct nt36672a_panel *pinfo =to_nt36672a_panel (panel); -int ret =0 ;
drivers/gpu/drm/panel/panel-novatek-nt36672a.c static inline struct nt36672a_panel *to_nt36672a_panel(struct drm_panel *panel) · line 102
Quoted 10 lines
drivers/gpu/drm/panel/panel-novatek-nt36672a.c +2
-5gpiod_set_value (pinfo->reset_gpio,1 ); - ret =regulator_bulk_disable (ARRAY_SIZE (pinfo->supplies), pinfo->supplies); -if (ret) -dev_err (panel->dev,"regulator_bulk_disable failed %d\n" , ret); - -return ret; +if (regulator_bulk_disable (ARRAY_SIZE (pinfo->supplies), pinfo->supplies) <0 ) +dev_err (panel->dev,"regulator_bulk_disable failed\n" );
nit: IMO It would have been OK to keep the local "ret" variable here, but I won't insist. That would have allowed you to keep printing the error code, which is nice. It's OK to have "ret" as a local variable even if you aren't returning it...
Quoted 10 lines
}
static int
nt36672a_panel_unprepare(struct drm_panel *panel){ struct nt36672a_panel *pinfo = to_nt36672a_panel(panel);drivers/gpu/drm/panel/panel-novatek-nt36672a.c +1
-2-int ret; +struct mipi_dsi_multi_context dsi_ctx = { .dsi = pinfo->link };/* send off cmds */ - ret = nt36672a_send_cmds(panel, pinfo->desc->off_cmds,
drivers/gpu/drm/panel/panel-novatek-nt36672a.c static inline struct nt36672a_panel *to_nt36672a_panel(struct drm_panel *panel) · line 129
Quoted 10 lines
drivers/gpu/drm/panel/panel-novatek-nt36672a.c +2
-7- pinfo->desc->num_off_cmds); +nt36672a_send_cmds (&dsi_ctx, pinfo->desc->off_cmds, + pinfo->desc->num_off_cmds); -if (ret <0 ) -dev_err (panel->dev,"failed to send DCS off cmds: %d\n" , ret); - - ret =mipi_dsi_dcs_set_display_off (pinfo->link); -if (ret <0 ) -dev_err (panel->dev,"set_display_off cmd failed ret = %d\n" , ret);
Probably also need a dsi_ctx.accum_err = 0; here? Old code still sent the "display off" command even if nt36672a_send_cmds() returned an error I think?
Quoted 5 lines
drivers/gpu/drm/panel/panel-novatek-nt36672a.c +3
-0+mipi_dsi_dcs_set_display_off_multi (&dsi_ctx); +/* Reset error to continue power-down even if display off failed */ + dsi_ctx.accum_err =0 ;/* 120ms delay required here as per DCS spec */
drivers/gpu/drm/panel/panel-novatek-nt36672a.c static inline struct nt36672a_panel *to_nt36672a_panel(struct drm_panel *panel) · line 124
Quoted 10 lines
drivers/gpu/drm/panel/panel-novatek-nt36672a.c +2
-4msleep (120 ); - ret =mipi_dsi_dcs_enter_sleep_mode (pinfo->link); -if (ret <0 ) -dev_err (panel->dev,"enter_sleep cmd failed ret = %d\n" , ret); +mipi_dsi_dcs_enter_sleep_mode_multi (&dsi_ctx);/* 0x3C = 60ms delay */ -msleep (60 ); +mipi_dsi_msleep (&dsi_ctx,60 );
I think this one should still be a regular msleep(60), right? Prior code still did msleep(60) even if mipi_dsi_dcs_enter_sleep_mode() returned an error, so you probably still should too.
drivers/gpu/drm/panel/panel-novatek-nt36672a.c static inline struct nt36672a_panel *to_nt36672a_panel(struct drm_panel *panel) · line 128
Quoted 7 lines
drivers/gpu/drm/panel/panel-novatek-nt36672a.c +2
-4- ret =nt36672a_panel_power_off (panel); -if (ret <0 ) -dev_err (panel->dev,"power_off failed ret = %d\n" , ret); +nt36672a_panel_power_off (panel); -return ret; +return 0 ;
I didn't notice before, but I guess this is a minor change. Previously nt36672a_panel_unprepare() would ignore all errors (other than printing) except it would return the final error return from the regulator_bulk_disable() call. Now it will also ignore the error from the regulator_bulk_disable().
IMO this is fine, but since it's a slight change in functionality it could be noted in the commit message. Something like:
This patch is intended to functionally be a no-op, though there is one slight change. Previously a failure in regulator_bulk_disable() would have caused nt36672a_panel_unprepare() to return an error. Now it won't. No other errors in nt36672a_panel_unprepare() were propagated, so this makes things consistent.
Hi Doug,
Thanks for the detailed review — this is very helpful.
Good catch on a few of these.
Quoted 11 lines · Chintan Patel
Quoted 9 lines
drivers/gpu/drm/panel/panel-novatek-nt36672a.c +1
-2-static int nt36672a_panel_power_off (struct drm_panel *panel) +static void nt36672a_panel_power_off (struct drm_panel *panel) {struct nt36672a_panel *pinfo =to_nt36672a_panel (panel); -int ret =0 ;gpiod_set_value (pinfo->reset_gpio,1 );
Quoted 13 lines
drivers/gpu/drm/panel/panel-novatek-nt36672a.c static inline struct nt36672a_panel *to_nt36672a_panel(struct drm_panel *panel) · line 102
Quoted 7 lines
drivers/gpu/drm/panel/panel-novatek-nt36672a.c +2
-5- ret =regulator_bulk_disable (ARRAY_SIZE (pinfo->supplies), pinfo->supplies); -if (ret) -dev_err (panel->dev,"regulator_bulk_disable failed %d\n" , ret); - -return ret; +if (regulator_bulk_disable (ARRAY_SIZE (pinfo->supplies), pinfo->supplies) <0 ) +dev_err (panel->dev,"regulator_bulk_disable failed\n" );nit: IMO It would have been OK to keep the local "ret" variable here, but I won't insist. That would have allowed you to keep printing the error code, which is nice. It's OK to have "ret" as a local variable even if you aren't returning it...
I’ll restore the local ret variable in nt36672a_panel_power_off() so we continue printing the regulator error code even though the function now returns void.
Quoted 21 lines
Quoted 10 lines
} static int nt36672a_panel_unprepare(struct drm_panel *panel) { struct nt36672a_panel *pinfo = to_nt36672a_panel(panel);drivers/gpu/drm/panel/panel-novatek-nt36672a.c +1
-2-int ret; +struct mipi_dsi_multi_context dsi_ctx = { .dsi = pinfo->link };/* send off cmds */ - ret = nt36672a_send_cmds(panel, pinfo->desc->off_cmds,drivers/gpu/drm/panel/panel-novatek-nt36672a.c static inline struct nt36672a_panel *to_nt36672a_panel(struct drm_panel *panel) · line 129
Quoted 10 lines
drivers/gpu/drm/panel/panel-novatek-nt36672a.c +2
-7- pinfo->desc->num_off_cmds); +nt36672a_send_cmds (&dsi_ctx, pinfo->desc->off_cmds, + pinfo->desc->num_off_cmds); -if (ret <0 ) -dev_err (panel->dev,"failed to send DCS off cmds: %d\n" , ret); - - ret =mipi_dsi_dcs_set_display_off (pinfo->link); -if (ret <0 ) -dev_err (panel->dev,"set_display_off cmd failed ret = %d\n" , ret);
Quoted 4 lines
Probably also need a
dsi_ctx.accum_err = 0;here? Old code still sent the "display off" command even ifnt36672a_send_cmds()returned an error I think?
You’re right about needing to reset dsi_ctx.accum_err before calling mipi_dsi_dcs_set_display_off_multi(). The old code would still send the display-off command even if nt36672a_send_cmds() failed, so I’ll add the reset there to preserve the original behavior.
Quoted 12 lines
Quoted 12 lines
drivers/gpu/drm/panel/panel-novatek-nt36672a.c +4
-3+mipi_dsi_dcs_set_display_off_multi (&dsi_ctx); +/* Reset error to continue power-down even if display off failed */ + dsi_ctx.accum_err =0 ;/* 120ms delay required here as per DCS spec */ msleep (120 ); - ret =mipi_dsi_dcs_enter_sleep_mode (pinfo->link); -if (ret <0 ) -dev_err (panel->dev,"enter_sleep cmd failed ret = %d\n" , ret); +mipi_dsi_dcs_enter_sleep_mode_multi (&dsi_ctx);
Quoted 8 lines
drivers/gpu/drm/panel/panel-novatek-nt36672a.c static inline struct nt36672a_panel *to_nt36672a_panel(struct drm_panel *panel) · line 124
Quoted 3 lines
/* 0x3C = 60ms delay */drivers/gpu/drm/panel/panel-novatek-nt36672a.c +1
-1-msleep (60 ); +mipi_dsi_msleep (&dsi_ctx,60 );I think this one should still be a regular msleep(60), right? Prior code still did msleep(60) even if
mipi_dsi_dcs_enter_sleep_mode()returned an error, so you probably still should too.
Agreed on keeping the msleep(60) as a regular sleep. Since the old code always slept regardless of DSI errors, using mipi_dsi_msleep() there would subtly change the power-down timing semantics.
Quoted 14 lines
drivers/gpu/drm/panel/panel-novatek-nt36672a.c static inline struct nt36672a_panel *to_nt36672a_panel(struct drm_panel *panel) · line 128
Quoted 7 lines
drivers/gpu/drm/panel/panel-novatek-nt36672a.c +2
-4- ret =nt36672a_panel_power_off (panel); -if (ret <0 ) -dev_err (panel->dev,"power_off failed ret = %d\n" , ret); +nt36672a_panel_power_off (panel); -return ret; +return 0 ;I didn't notice before, but I guess this is a minor change. Previously
nt36672a_panel_unprepare()would ignore all errors (other than printing) except it would return the final error return from theregulator_bulk_disable()call. Now it will also ignore the error from theregulator_bulk_disable().
Quoted 8 lines
IMO this is fine, but since it's a slight change in functionality it could be noted in the commit message. Something like:
This patch is intended to functionally be a no-op, though there is one slight change. Previously a failure in
regulator_bulk_disable()would have causednt36672a_panel_unprepare()to return an error. Now it won't. No other errors innt36672a_panel_unprepare()were propagated, so this makes things consistent.
I’ll also note in the commit message that nt36672a_panel_unprepare() no longer propagates the regulator error, since previously that was the only error returned and all others were ignored.
I’ll send a v3 shortly incorporating these adjustments.
Thanks again for the careful review.
-Chintan