linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v4] drm/mediatek: allow commands to be sent during video mode
@ 2022-02-14  9:27 Julien STEPHAN
  2022-02-14  9:43 ` AngeloGioacchino Del Regno
  0 siblings, 1 reply; 3+ messages in thread
From: Julien STEPHAN @ 2022-02-14  9:27 UTC (permalink / raw)
  To: angelogioacchino.delregno
  Cc: Julien STEPHAN, Mattijs Korpershoek, Chun-Kuang Hu,
	Philipp Zabel, David Airlie, Daniel Vetter, Matthias Brugger,
	open list:DRM DRIVERS FOR MEDIATEK,
	moderated list:DRM DRIVERS FOR MEDIATEK,
	moderated list:ARM/Mediatek SoC support, open list

Mipi dsi panel drivers can use mipi_dsi_dcs_{set,get}_display_brightness()
to request backlight changes.

This can be done during panel initialization (dsi is in command mode)
or afterwards (dsi is in Video Mode).

When the DSI is in Video Mode, all commands are rejected.

Detect current DSI mode in mtk_dsi_host_transfer() and switch modes
temporarily to allow commands to be sent.

Signed-off-by: Julien STEPHAN <jstephan@baylibre.com>
Signed-off-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>
---
Changes in v4:
    - fix missing space:  "ret : recv_cnt;"
Changes in v3:
    - increase readability of code and use correct return variable (see
      comment
https://lore.kernel.org/linux-mediatek/4907bdc1-b4a6-e9ad-5cfa-266fc20c0bec@collabora.com/)

Changes in v2:
    - update commit message to be more descriptive

 drivers/gpu/drm/mediatek/mtk_dsi.c | 33 ++++++++++++++++++++++--------
 1 file changed, 24 insertions(+), 9 deletions(-)

diff --git a/drivers/gpu/drm/mediatek/mtk_dsi.c b/drivers/gpu/drm/mediatek/mtk_dsi.c
index 5d90d2eb0019..abdd9cdebd86 100644
--- a/drivers/gpu/drm/mediatek/mtk_dsi.c
+++ b/drivers/gpu/drm/mediatek/mtk_dsi.c
@@ -891,24 +891,33 @@ static ssize_t mtk_dsi_host_transfer(struct mipi_dsi_host *host,
 	u8 read_data[16];
 	void *src_addr;
 	u8 irq_flag = CMD_DONE_INT_FLAG;
+	u32 dsi_mode;
+	int ret;

-	if (readl(dsi->regs + DSI_MODE_CTRL) & MODE) {
-		DRM_ERROR("dsi engine is not command mode\n");
-		return -EINVAL;
+	dsi_mode = readl(dsi->regs + DSI_MODE_CTRL);
+	if (dsi_mode & MODE) {
+		mtk_dsi_stop(dsi);
+		ret = mtk_dsi_switch_to_cmd_mode(dsi, VM_DONE_INT_FLAG, 500);
+		if (ret)
+			goto restore_dsi_mode;
 	}

 	if (MTK_DSI_HOST_IS_READ(msg->type))
 		irq_flag |= LPRX_RD_RDY_INT_FLAG;

-	if (mtk_dsi_host_send_cmd(dsi, msg, irq_flag) < 0)
-		return -ETIME;
+	ret = mtk_dsi_host_send_cmd(dsi, msg, irq_flag);
+	if (ret)
+		goto restore_dsi_mode;

-	if (!MTK_DSI_HOST_IS_READ(msg->type))
-		return 0;
+	if (!MTK_DSI_HOST_IS_READ(msg->type)) {
+		recv_cnt = 0;
+		goto restore_dsi_mode;
+	}

 	if (!msg->rx_buf) {
 		DRM_ERROR("dsi receive buffer size may be NULL\n");
-		return -EINVAL;
+		ret = -EINVAL;
+		goto restore_dsi_mode;
 	}

 	for (i = 0; i < 16; i++)
@@ -933,7 +942,13 @@ static ssize_t mtk_dsi_host_transfer(struct mipi_dsi_host *host,
 	DRM_INFO("dsi get %d byte data from the panel address(0x%x)\n",
 		 recv_cnt, *((u8 *)(msg->tx_buf)));

-	return recv_cnt;
+restore_dsi_mode:
+	if (dsi_mode & MODE) {
+		mtk_dsi_set_mode(dsi);
+		mtk_dsi_start(dsi);
+	}
+
+	return ret < 0 ? ret : recv_cnt;
 }

 static const struct mipi_dsi_host_ops mtk_dsi_ops = {
--
2.35.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH v4] drm/mediatek: allow commands to be sent during video mode
  2022-02-14  9:27 [PATCH v4] drm/mediatek: allow commands to be sent during video mode Julien STEPHAN
@ 2022-02-14  9:43 ` AngeloGioacchino Del Regno
  2022-02-17 15:15   ` Chun-Kuang Hu
  0 siblings, 1 reply; 3+ messages in thread
From: AngeloGioacchino Del Regno @ 2022-02-14  9:43 UTC (permalink / raw)
  To: Julien STEPHAN
  Cc: Mattijs Korpershoek, Chun-Kuang Hu, Philipp Zabel, David Airlie,
	Daniel Vetter, Matthias Brugger,
	open list:DRM DRIVERS FOR MEDIATEK,
	moderated list:DRM DRIVERS FOR MEDIATEK,
	moderated list:ARM/Mediatek SoC support, open list

Il 14/02/22 10:27, Julien STEPHAN ha scritto:
> Mipi dsi panel drivers can use mipi_dsi_dcs_{set,get}_display_brightness()
> to request backlight changes.
> 
> This can be done during panel initialization (dsi is in command mode)
> or afterwards (dsi is in Video Mode).
> 
> When the DSI is in Video Mode, all commands are rejected.
> 
> Detect current DSI mode in mtk_dsi_host_transfer() and switch modes
> temporarily to allow commands to be sent.
> 
> Signed-off-by: Julien STEPHAN <jstephan@baylibre.com>
> Signed-off-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>

Please, next time, don't drop the tags that reviewers are giving to you, unless
the patch changes radically.

Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>

> ---
> Changes in v4:
>      - fix missing space:  "ret : recv_cnt;"
> Changes in v3:
>      - increase readability of code and use correct return variable (see
>        comment
> https://lore.kernel.org/linux-mediatek/4907bdc1-b4a6-e9ad-5cfa-266fc20c0bec@collabora.com/)
> 
> Changes in v2:
>      - update commit message to be more descriptive
> 
>   drivers/gpu/drm/mediatek/mtk_dsi.c | 33 ++++++++++++++++++++++--------
>   1 file changed, 24 insertions(+), 9 deletions(-)
> 
> diff --git a/drivers/gpu/drm/mediatek/mtk_dsi.c b/drivers/gpu/drm/mediatek/mtk_dsi.c
> index 5d90d2eb0019..abdd9cdebd86 100644
> --- a/drivers/gpu/drm/mediatek/mtk_dsi.c
> +++ b/drivers/gpu/drm/mediatek/mtk_dsi.c
> @@ -891,24 +891,33 @@ static ssize_t mtk_dsi_host_transfer(struct mipi_dsi_host *host,
>   	u8 read_data[16];
>   	void *src_addr;
>   	u8 irq_flag = CMD_DONE_INT_FLAG;
> +	u32 dsi_mode;
> +	int ret;
> 
> -	if (readl(dsi->regs + DSI_MODE_CTRL) & MODE) {
> -		DRM_ERROR("dsi engine is not command mode\n");
> -		return -EINVAL;
> +	dsi_mode = readl(dsi->regs + DSI_MODE_CTRL);
> +	if (dsi_mode & MODE) {
> +		mtk_dsi_stop(dsi);
> +		ret = mtk_dsi_switch_to_cmd_mode(dsi, VM_DONE_INT_FLAG, 500);
> +		if (ret)
> +			goto restore_dsi_mode;
>   	}
> 
>   	if (MTK_DSI_HOST_IS_READ(msg->type))
>   		irq_flag |= LPRX_RD_RDY_INT_FLAG;
> 
> -	if (mtk_dsi_host_send_cmd(dsi, msg, irq_flag) < 0)
> -		return -ETIME;
> +	ret = mtk_dsi_host_send_cmd(dsi, msg, irq_flag);
> +	if (ret)
> +		goto restore_dsi_mode;
> 
> -	if (!MTK_DSI_HOST_IS_READ(msg->type))
> -		return 0;
> +	if (!MTK_DSI_HOST_IS_READ(msg->type)) {
> +		recv_cnt = 0;
> +		goto restore_dsi_mode;
> +	}
> 
>   	if (!msg->rx_buf) {
>   		DRM_ERROR("dsi receive buffer size may be NULL\n");
> -		return -EINVAL;
> +		ret = -EINVAL;
> +		goto restore_dsi_mode;
>   	}
> 
>   	for (i = 0; i < 16; i++)
> @@ -933,7 +942,13 @@ static ssize_t mtk_dsi_host_transfer(struct mipi_dsi_host *host,
>   	DRM_INFO("dsi get %d byte data from the panel address(0x%x)\n",
>   		 recv_cnt, *((u8 *)(msg->tx_buf)));
> 
> -	return recv_cnt;
> +restore_dsi_mode:
> +	if (dsi_mode & MODE) {
> +		mtk_dsi_set_mode(dsi);
> +		mtk_dsi_start(dsi);
> +	}
> +
> +	return ret < 0 ? ret : recv_cnt;
>   }
> 
>   static const struct mipi_dsi_host_ops mtk_dsi_ops = {
> --
> 2.35.1
> 




^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v4] drm/mediatek: allow commands to be sent during video mode
  2022-02-14  9:43 ` AngeloGioacchino Del Regno
@ 2022-02-17 15:15   ` Chun-Kuang Hu
  0 siblings, 0 replies; 3+ messages in thread
From: Chun-Kuang Hu @ 2022-02-17 15:15 UTC (permalink / raw)
  To: AngeloGioacchino Del Regno
  Cc: Julien STEPHAN, Mattijs Korpershoek, Chun-Kuang Hu,
	Philipp Zabel, David Airlie, Daniel Vetter, Matthias Brugger,
	open list:DRM DRIVERS FOR MEDIATEK,
	moderated list:DRM DRIVERS FOR MEDIATEK,
	moderated list:ARM/Mediatek SoC support, open list

 [1Hi, Julien:

AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com> 於
2022年2月14日 週一 下午5:43寫道:
>
> Il 14/02/22 10:27, Julien STEPHAN ha scritto:
> > Mipi dsi panel drivers can use mipi_dsi_dcs_{set,get}_display_brightness()
> > to request backlight changes.
> >
> > This can be done during panel initialization (dsi is in command mode)
> > or afterwards (dsi is in Video Mode).
> >
> > When the DSI is in Video Mode, all commands are rejected.
> >
> > Detect current DSI mode in mtk_dsi_host_transfer() and switch modes
> > temporarily to allow commands to be sent.

Applied to mediatek-drm-next [1], thanks.

[1] https://git.kernel.org/pub/scm/linux/kernel/git/chunkuang.hu/linux.git/log/?h=mediatek-drm-next

Regards,
Chun-Kuang.

> >
> > Signed-off-by: Julien STEPHAN <jstephan@baylibre.com>
> > Signed-off-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>
>
> Please, next time, don't drop the tags that reviewers are giving to you, unless
> the patch changes radically.
>
> Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
>
> > ---
> > Changes in v4:
> >      - fix missing space:  "ret : recv_cnt;"
> > Changes in v3:
> >      - increase readability of code and use correct return variable (see
> >        comment
> > https://lore.kernel.org/linux-mediatek/4907bdc1-b4a6-e9ad-5cfa-266fc20c0bec@collabora.com/)
> >
> > Changes in v2:
> >      - update commit message to be more descriptive
> >
> >   drivers/gpu/drm/mediatek/mtk_dsi.c | 33 ++++++++++++++++++++++--------
> >   1 file changed, 24 insertions(+), 9 deletions(-)
> >
> > diff --git a/drivers/gpu/drm/mediatek/mtk_dsi.c b/drivers/gpu/drm/mediatek/mtk_dsi.c
> > index 5d90d2eb0019..abdd9cdebd86 100644
> > --- a/drivers/gpu/drm/mediatek/mtk_dsi.c
> > +++ b/drivers/gpu/drm/mediatek/mtk_dsi.c
> > @@ -891,24 +891,33 @@ static ssize_t mtk_dsi_host_transfer(struct mipi_dsi_host *host,
> >       u8 read_data[16];
> >       void *src_addr;
> >       u8 irq_flag = CMD_DONE_INT_FLAG;
> > +     u32 dsi_mode;
> > +     int ret;
> >
> > -     if (readl(dsi->regs + DSI_MODE_CTRL) & MODE) {
> > -             DRM_ERROR("dsi engine is not command mode\n");
> > -             return -EINVAL;
> > +     dsi_mode = readl(dsi->regs + DSI_MODE_CTRL);
> > +     if (dsi_mode & MODE) {
> > +             mtk_dsi_stop(dsi);
> > +             ret = mtk_dsi_switch_to_cmd_mode(dsi, VM_DONE_INT_FLAG, 500);
> > +             if (ret)
> > +                     goto restore_dsi_mode;
> >       }
> >
> >       if (MTK_DSI_HOST_IS_READ(msg->type))
> >               irq_flag |= LPRX_RD_RDY_INT_FLAG;
> >
> > -     if (mtk_dsi_host_send_cmd(dsi, msg, irq_flag) < 0)
> > -             return -ETIME;
> > +     ret = mtk_dsi_host_send_cmd(dsi, msg, irq_flag);
> > +     if (ret)
> > +             goto restore_dsi_mode;
> >
> > -     if (!MTK_DSI_HOST_IS_READ(msg->type))
> > -             return 0;
> > +     if (!MTK_DSI_HOST_IS_READ(msg->type)) {
> > +             recv_cnt = 0;
> > +             goto restore_dsi_mode;
> > +     }
> >
> >       if (!msg->rx_buf) {
> >               DRM_ERROR("dsi receive buffer size may be NULL\n");
> > -             return -EINVAL;
> > +             ret = -EINVAL;
> > +             goto restore_dsi_mode;
> >       }
> >
> >       for (i = 0; i < 16; i++)
> > @@ -933,7 +942,13 @@ static ssize_t mtk_dsi_host_transfer(struct mipi_dsi_host *host,
> >       DRM_INFO("dsi get %d byte data from the panel address(0x%x)\n",
> >                recv_cnt, *((u8 *)(msg->tx_buf)));
> >
> > -     return recv_cnt;
> > +restore_dsi_mode:
> > +     if (dsi_mode & MODE) {
> > +             mtk_dsi_set_mode(dsi);
> > +             mtk_dsi_start(dsi);
> > +     }
> > +
> > +     return ret < 0 ? ret : recv_cnt;
> >   }
> >
> >   static const struct mipi_dsi_host_ops mtk_dsi_ops = {
> > --
> > 2.35.1
> >
>
>
>

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-02-17 15:16 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-14  9:27 [PATCH v4] drm/mediatek: allow commands to be sent during video mode Julien STEPHAN
2022-02-14  9:43 ` AngeloGioacchino Del Regno
2022-02-17 15:15   ` Chun-Kuang Hu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).