[PATCH v2] drm/panel: samsung-s6d16d0: Use mipi_dsi_*_multi(); fix minor bugs

Akash Sukhavasi posted 1 patch 1 month, 2 weeks ago
drivers/gpu/drm/panel/panel-samsung-s6d16d0.c | 55 +++++++++------------------
1 file changed, 17 insertions(+), 38 deletions(-)
[PATCH v2] drm/panel: samsung-s6d16d0: Use mipi_dsi_*_multi(); fix minor bugs
Posted by Akash Sukhavasi 1 month, 2 weeks ago
The mipi_dsi_dcs_*() functions used by this driver are deprecated
in favour of their _multi() counterparts, as noted in
Documentation/gpu/todo.rst. The _multi() variants record the
first error in a context structure and skip subsequent calls once
an error is set, removing the need to check the return value
after each command. They also log failures internally, making the
per-call dev_err() calls redundant.

Convert prepare(), enable(), disable(), and unprepare() to use
mipi_dsi_dcs_*_multi().

unprepare() previously returned an error if
mipi_dsi_dcs_enter_sleep_mode() failed, skipping RESET assertion
and regulator_disable(). Because drm_panel_unprepare() does not
clear panel->prepared when the callback returns an error,
drm_panel_prepare() would then return early on the next call,
leaving the panel powered and unable to be re-initialised. The
converted code always asserts RESET, disables the regulator, and
returns 0.

Also fix a typo in a comment ("Enabe" -> "Enable").

Signed-off-by: Akash Sukhavasi <akash.sukhavasi@gmail.com>
---
Compile tested only, no hardware available. checkpatch and a W=1
build are clean.
---
Changes in v2:
- Keep intermediate dsi variable for readability, per Neil's review.
- Add comment explaining why accum_err is not checked in unprepare().
- Simplify prepare() to a single return path.
- Link to v1: https://lore.kernel.org/r/20260807-mipi-dsi-s6d16d0-multi-v1-1-c6179f6f3c98@gmail.com
---
 drivers/gpu/drm/panel/panel-samsung-s6d16d0.c | 55 +++++++++------------------
 1 file changed, 17 insertions(+), 38 deletions(-)

diff --git a/drivers/gpu/drm/panel/panel-samsung-s6d16d0.c b/drivers/gpu/drm/panel/panel-samsung-s6d16d0.c
index 54a65abf7e89..e734fffa45a4 100644
--- a/drivers/gpu/drm/panel/panel-samsung-s6d16d0.c
+++ b/drivers/gpu/drm/panel/panel-samsung-s6d16d0.c
@@ -48,14 +48,10 @@ static int s6d16d0_unprepare(struct drm_panel *panel)
 {
 	struct s6d16d0 *s6 = panel_to_s6d16d0(panel);
 	struct mipi_dsi_device *dsi = to_mipi_dsi_device(s6->dev);
-	int ret;
+	struct mipi_dsi_multi_context dsi_ctx = { .dsi = dsi };
 
-	/* Enter sleep mode */
-	ret = mipi_dsi_dcs_enter_sleep_mode(dsi);
-	if (ret) {
-		dev_err(s6->dev, "failed to enter sleep mode (%d)\n", ret);
-		return ret;
-	}
+	/* Enter sleep mode; error does not prevent power-off */
+	mipi_dsi_dcs_enter_sleep_mode_multi(&dsi_ctx);
 
 	/* Assert RESET */
 	gpiod_set_value_cansleep(s6->reset_gpio, 1);
@@ -68,6 +64,7 @@ static int s6d16d0_prepare(struct drm_panel *panel)
 {
 	struct s6d16d0 *s6 = panel_to_s6d16d0(panel);
 	struct mipi_dsi_device *dsi = to_mipi_dsi_device(s6->dev);
+	struct mipi_dsi_multi_context dsi_ctx = { .dsi = dsi };
 	int ret;
 
 	ret = regulator_enable(s6->supply);
@@ -83,57 +80,39 @@ static int s6d16d0_prepare(struct drm_panel *panel)
 	gpiod_set_value_cansleep(s6->reset_gpio, 0);
 	msleep(120);
 
-	/* Enabe tearing mode: send TE (tearing effect) at VBLANK */
-	ret = mipi_dsi_dcs_set_tear_on(dsi,
+	/* Enable tearing mode: send TE (tearing effect) at VBLANK */
+	mipi_dsi_dcs_set_tear_on_multi(&dsi_ctx,
 				       MIPI_DSI_DCS_TEAR_MODE_VBLANK);
-	if (ret) {
-		dev_err(s6->dev, "failed to enable vblank TE (%d)\n", ret);
-		goto err_power_off;
-	}
 	/* Exit sleep mode and power on */
-	ret = mipi_dsi_dcs_exit_sleep_mode(dsi);
-	if (ret) {
-		dev_err(s6->dev, "failed to exit sleep mode (%d)\n", ret);
-		goto err_power_off;
+	mipi_dsi_dcs_exit_sleep_mode_multi(&dsi_ctx);
+	if (dsi_ctx.accum_err) {
+		gpiod_set_value_cansleep(s6->reset_gpio, 1);
+		regulator_disable(s6->supply);
 	}
 
-	return 0;
-
-err_power_off:
-	gpiod_set_value_cansleep(s6->reset_gpio, 1);
-	regulator_disable(s6->supply);
-
-	return ret;
+	return dsi_ctx.accum_err;
 }
 
 static int s6d16d0_enable(struct drm_panel *panel)
 {
 	struct s6d16d0 *s6 = panel_to_s6d16d0(panel);
 	struct mipi_dsi_device *dsi = to_mipi_dsi_device(s6->dev);
-	int ret;
+	struct mipi_dsi_multi_context dsi_ctx = { .dsi = dsi };
 
-	ret = mipi_dsi_dcs_set_display_on(dsi);
-	if (ret) {
-		dev_err(s6->dev, "failed to turn display on (%d)\n", ret);
-		return ret;
-	}
+	mipi_dsi_dcs_set_display_on_multi(&dsi_ctx);
 
-	return 0;
+	return dsi_ctx.accum_err;
 }
 
 static int s6d16d0_disable(struct drm_panel *panel)
 {
 	struct s6d16d0 *s6 = panel_to_s6d16d0(panel);
 	struct mipi_dsi_device *dsi = to_mipi_dsi_device(s6->dev);
-	int ret;
+	struct mipi_dsi_multi_context dsi_ctx = { .dsi = dsi };
 
-	ret = mipi_dsi_dcs_set_display_off(dsi);
-	if (ret) {
-		dev_err(s6->dev, "failed to turn display off (%d)\n", ret);
-		return ret;
-	}
+	mipi_dsi_dcs_set_display_off_multi(&dsi_ctx);
 
-	return 0;
+	return dsi_ctx.accum_err;
 }
 
 static int s6d16d0_get_modes(struct drm_panel *panel,

---
base-commit: dc2f9f7fed1a8ea5290f9f60c6310d497e85e666
change-id: 20260807-mipi-dsi-s6d16d0-multi-167e236e9666

Best regards,
-- 
Akash Sukhavasi <akash.sukhavasi@gmail.com>
Re: [PATCH v2] drm/panel: samsung-s6d16d0: Use mipi_dsi_*_multi(); fix minor bugs
Posted by Linus Walleij 1 month, 2 weeks ago
On Tue, Aug 11, 2026 at 1:45 AM Akash Sukhavasi
<akash.sukhavasi@gmail.com> wrote:

> The mipi_dsi_dcs_*() functions used by this driver are deprecated
> in favour of their _multi() counterparts, as noted in
> Documentation/gpu/todo.rst. The _multi() variants record the
> first error in a context structure and skip subsequent calls once
> an error is set, removing the need to check the return value
> after each command. They also log failures internally, making the
> per-call dev_err() calls redundant.
>
> Convert prepare(), enable(), disable(), and unprepare() to use
> mipi_dsi_dcs_*_multi().
>
> unprepare() previously returned an error if
> mipi_dsi_dcs_enter_sleep_mode() failed, skipping RESET assertion
> and regulator_disable(). Because drm_panel_unprepare() does not
> clear panel->prepared when the callback returns an error,
> drm_panel_prepare() would then return early on the next call,
> leaving the panel powered and unable to be re-initialised. The
> converted code always asserts RESET, disables the regulator, and
> returns 0.
>
> Also fix a typo in a comment ("Enabe" -> "Enable").
>
> Signed-off-by: Akash Sukhavasi <akash.sukhavasi@gmail.com>

Patch applied to drm-misc-next.

I can't test it for the moment but that is no reason to hold
back the patch, I will deal with the fallout of there is
some problem!

Yours,
Linus Walleij
Re: [PATCH v2] drm/panel: samsung-s6d16d0: Use mipi_dsi_*_multi(); fix minor bugs
Posted by Neil Armstrong 1 month, 2 weeks ago
On 8/11/26 01:45, Akash Sukhavasi wrote:
> The mipi_dsi_dcs_*() functions used by this driver are deprecated
> in favour of their _multi() counterparts, as noted in
> Documentation/gpu/todo.rst. The _multi() variants record the
> first error in a context structure and skip subsequent calls once
> an error is set, removing the need to check the return value
> after each command. They also log failures internally, making the
> per-call dev_err() calls redundant.
> 
> Convert prepare(), enable(), disable(), and unprepare() to use
> mipi_dsi_dcs_*_multi().
> 
> unprepare() previously returned an error if
> mipi_dsi_dcs_enter_sleep_mode() failed, skipping RESET assertion
> and regulator_disable(). Because drm_panel_unprepare() does not
> clear panel->prepared when the callback returns an error,
> drm_panel_prepare() would then return early on the next call,
> leaving the panel powered and unable to be re-initialised. The
> converted code always asserts RESET, disables the regulator, and
> returns 0.
> 
> Also fix a typo in a comment ("Enabe" -> "Enable").
> 
> Signed-off-by: Akash Sukhavasi <akash.sukhavasi@gmail.com>
> ---
> Compile tested only, no hardware available. checkpatch and a W=1
> build are clean.
> ---
> Changes in v2:
> - Keep intermediate dsi variable for readability, per Neil's review.
> - Add comment explaining why accum_err is not checked in unprepare().
> - Simplify prepare() to a single return path.
> - Link to v1: https://lore.kernel.org/r/20260807-mipi-dsi-s6d16d0-multi-v1-1-c6179f6f3c98@gmail.com
> ---
>   drivers/gpu/drm/panel/panel-samsung-s6d16d0.c | 55 +++++++++------------------
>   1 file changed, 17 insertions(+), 38 deletions(-)
> 
> diff --git a/drivers/gpu/drm/panel/panel-samsung-s6d16d0.c b/drivers/gpu/drm/panel/panel-samsung-s6d16d0.c
> index 54a65abf7e89..e734fffa45a4 100644
> --- a/drivers/gpu/drm/panel/panel-samsung-s6d16d0.c
> +++ b/drivers/gpu/drm/panel/panel-samsung-s6d16d0.c
> @@ -48,14 +48,10 @@ static int s6d16d0_unprepare(struct drm_panel *panel)
>   {
>   	struct s6d16d0 *s6 = panel_to_s6d16d0(panel);
>   	struct mipi_dsi_device *dsi = to_mipi_dsi_device(s6->dev);
> -	int ret;
> +	struct mipi_dsi_multi_context dsi_ctx = { .dsi = dsi };
>   
> -	/* Enter sleep mode */
> -	ret = mipi_dsi_dcs_enter_sleep_mode(dsi);
> -	if (ret) {
> -		dev_err(s6->dev, "failed to enter sleep mode (%d)\n", ret);
> -		return ret;
> -	}
> +	/* Enter sleep mode; error does not prevent power-off */
> +	mipi_dsi_dcs_enter_sleep_mode_multi(&dsi_ctx);
>   
>   	/* Assert RESET */
>   	gpiod_set_value_cansleep(s6->reset_gpio, 1);
> @@ -68,6 +64,7 @@ static int s6d16d0_prepare(struct drm_panel *panel)
>   {
>   	struct s6d16d0 *s6 = panel_to_s6d16d0(panel);
>   	struct mipi_dsi_device *dsi = to_mipi_dsi_device(s6->dev);
> +	struct mipi_dsi_multi_context dsi_ctx = { .dsi = dsi };
>   	int ret;
>   
>   	ret = regulator_enable(s6->supply);
> @@ -83,57 +80,39 @@ static int s6d16d0_prepare(struct drm_panel *panel)
>   	gpiod_set_value_cansleep(s6->reset_gpio, 0);
>   	msleep(120);
>   
> -	/* Enabe tearing mode: send TE (tearing effect) at VBLANK */
> -	ret = mipi_dsi_dcs_set_tear_on(dsi,
> +	/* Enable tearing mode: send TE (tearing effect) at VBLANK */
> +	mipi_dsi_dcs_set_tear_on_multi(&dsi_ctx,
>   				       MIPI_DSI_DCS_TEAR_MODE_VBLANK);
> -	if (ret) {
> -		dev_err(s6->dev, "failed to enable vblank TE (%d)\n", ret);
> -		goto err_power_off;
> -	}
>   	/* Exit sleep mode and power on */
> -	ret = mipi_dsi_dcs_exit_sleep_mode(dsi);
> -	if (ret) {
> -		dev_err(s6->dev, "failed to exit sleep mode (%d)\n", ret);
> -		goto err_power_off;
> +	mipi_dsi_dcs_exit_sleep_mode_multi(&dsi_ctx);
> +	if (dsi_ctx.accum_err) {
> +		gpiod_set_value_cansleep(s6->reset_gpio, 1);
> +		regulator_disable(s6->supply);
>   	}
>   
> -	return 0;
> -
> -err_power_off:
> -	gpiod_set_value_cansleep(s6->reset_gpio, 1);
> -	regulator_disable(s6->supply);
> -
> -	return ret;
> +	return dsi_ctx.accum_err;
>   }
>   
>   static int s6d16d0_enable(struct drm_panel *panel)
>   {
>   	struct s6d16d0 *s6 = panel_to_s6d16d0(panel);
>   	struct mipi_dsi_device *dsi = to_mipi_dsi_device(s6->dev);
> -	int ret;
> +	struct mipi_dsi_multi_context dsi_ctx = { .dsi = dsi };
>   
> -	ret = mipi_dsi_dcs_set_display_on(dsi);
> -	if (ret) {
> -		dev_err(s6->dev, "failed to turn display on (%d)\n", ret);
> -		return ret;
> -	}
> +	mipi_dsi_dcs_set_display_on_multi(&dsi_ctx);
>   
> -	return 0;
> +	return dsi_ctx.accum_err;
>   }
>   
>   static int s6d16d0_disable(struct drm_panel *panel)
>   {
>   	struct s6d16d0 *s6 = panel_to_s6d16d0(panel);
>   	struct mipi_dsi_device *dsi = to_mipi_dsi_device(s6->dev);
> -	int ret;
> +	struct mipi_dsi_multi_context dsi_ctx = { .dsi = dsi };
>   
> -	ret = mipi_dsi_dcs_set_display_off(dsi);
> -	if (ret) {
> -		dev_err(s6->dev, "failed to turn display off (%d)\n", ret);
> -		return ret;
> -	}
> +	mipi_dsi_dcs_set_display_off_multi(&dsi_ctx);
>   
> -	return 0;
> +	return dsi_ctx.accum_err;
>   }
>   
>   static int s6d16d0_get_modes(struct drm_panel *panel,
> 
> ---
> base-commit: dc2f9f7fed1a8ea5290f9f60c6310d497e85e666
> change-id: 20260807-mipi-dsi-s6d16d0-multi-167e236e9666
> 
> Best regards,

Reviewed-by: Neil Armstrong <neil.armstrong@linaro.org>

Thanks,
Neil