mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Vladimir Bely <vlwwwwww@gmail.com>
To: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>,
	Maxime Ripard <mripard@kernel.org>,
	Thomas Zimmermann <tzimmermann@suse.de>,
	Neil Armstrong <neil.armstrong@linaro.org>,
	Rob Clark <robin.clark@oss.qualcomm.com>,
	Dmitry Baryshkov <lumag@kernel.org>
Cc: David Airlie <airlied@gmail.com>, Simona Vetter <simona@ffwll.ch>,
	Abhinav Kumar <abhinav.kumar@linux.dev>,
	Jessica Zhang <jesszhan0024@gmail.com>,
	Sean Paul <sean@poorly.run>,
	Marijn Suijten <marijn.suijten@somainline.org>,
	Stephan Gerhold <stephan@gerhold.net>,
	Michael Srba <Michael.Srba@seznam.cz>,
	dri-devel@lists.freedesktop.org, linux-arm-msm@vger.kernel.org,
	freedreno@lists.freedesktop.org, linux-kernel@vger.kernel.org,
	Vladimir Bely <vlwwwwww@gmail.com>
Subject: [PATCH 1/5] drm/mipi-dsi: add multi-message batch transfer support
Date: Sun, 29 Nov 2026 16:00:22 +0300	[thread overview]
Message-ID: <20261129130026.581466-2-vlwwwwww@gmail.com> (raw)
In-Reply-To: <20261129130026.581466-1-vlwwwwww@gmail.com>

Add an optional .transfer_batch() callback to struct mipi_dsi_host_ops
and a mipi_dsi_dcs_write_batch() helper (analogous to i2c_transfer() and
spi_sync_transfer()) so panel drivers can submit a sequence of DCS
commands together.

When a DSI host implements .transfer_batch(), its hardware can pack
multiple command packets into a single DMA transfer and transmit them
atomically within one blanking interval.  Hosts that do not implement
.transfer_batch() fall back transparently to sequential .transfer()
calls.

Signed-off-by: Vladimir Bely <vlwwwwww@gmail.com>
---
 drivers/gpu/drm/drm_mipi_dsi.c | 98 ++++++++++++++++++++++++++++++++++
 include/drm/drm_mipi_dsi.h     | 21 ++++++++
 2 files changed, 119 insertions(+)

diff --git a/drivers/gpu/drm/drm_mipi_dsi.c b/drivers/gpu/drm/drm_mipi_dsi.c
index 3ac1dd5ad..03c077764 100644
--- a/drivers/gpu/drm/drm_mipi_dsi.c
+++ b/drivers/gpu/drm/drm_mipi_dsi.c
@@ -459,6 +459,37 @@ static ssize_t mipi_dsi_device_transfer(struct mipi_dsi_device *dsi,
 	return ops->transfer(dsi->host, msg);
 }
 
+static int mipi_dsi_device_transfer_batch(struct mipi_dsi_device *dsi,
+					  struct mipi_dsi_msg *msgs,
+					  size_t count)
+{
+	const struct mipi_dsi_host_ops *ops = dsi->host->ops;
+	size_t i;
+
+	if (!count)
+		return 0;
+
+	if (!ops || (!ops->transfer_batch && !ops->transfer))
+		return -ENOSYS;
+
+	if (dsi->mode_flags & MIPI_DSI_MODE_LPM) {
+		for (i = 0; i < count; i++)
+			msgs[i].flags |= MIPI_DSI_MSG_USE_LPM;
+	}
+
+	if (ops->transfer_batch)
+		return ops->transfer_batch(dsi->host, msgs, count);
+
+	for (i = 0; i < count; i++) {
+		ssize_t ret = ops->transfer(dsi->host, &msgs[i]);
+
+		if (ret < 0)
+			return ret;
+	}
+
+	return 0;
+}
+
 /**
  * mipi_dsi_packet_format_is_short - check if a packet is of the short format
  * @type: MIPI DSI data type of the packet
@@ -950,6 +981,73 @@ ssize_t mipi_dsi_dcs_write_buffer(struct mipi_dsi_device *dsi,
 }
 EXPORT_SYMBOL(mipi_dsi_dcs_write_buffer);
 
+/**
+ * mipi_dsi_dcs_write_batch() - transmit a batch of DCS commands
+ * @dsi: DSI peripheral device
+ * @cmds: array of DCS command buffers to transmit in order
+ * @count: number of entries in @cmds
+ *
+ * Builds a DSI message for each DCS command in @cmds and submits them via
+ * the host's .transfer_batch() callback when supported, falling back to
+ * sequential .transfer() calls otherwise.
+ *
+ * Return: 0 on success or a negative error code on failure.
+ */
+int mipi_dsi_dcs_write_batch(struct mipi_dsi_device *dsi,
+			     const struct mipi_dsi_dcs_cmd *cmds, size_t count)
+{
+	struct mipi_dsi_msg stack_msgs[8];
+	struct mipi_dsi_msg *msgs = stack_msgs;
+	size_t i;
+	int ret;
+
+	if (!count)
+		return 0;
+
+	if (!cmds)
+		return -EINVAL;
+
+	if (count > ARRAY_SIZE(stack_msgs)) {
+		msgs = kcalloc(count, sizeof(*msgs), GFP_KERNEL);
+		if (!msgs)
+			return -ENOMEM;
+	}
+
+	for (i = 0; i < count; i++) {
+		if (!cmds[i].data || !cmds[i].len) {
+			ret = -EINVAL;
+			goto out;
+		}
+
+		msgs[i] = (struct mipi_dsi_msg) {
+			.channel = dsi->channel,
+			.tx_buf = cmds[i].data,
+			.tx_len = cmds[i].len,
+		};
+
+		switch (cmds[i].len) {
+		case 1:
+			msgs[i].type = MIPI_DSI_DCS_SHORT_WRITE;
+			break;
+		case 2:
+			msgs[i].type = MIPI_DSI_DCS_SHORT_WRITE_PARAM;
+			break;
+		default:
+			msgs[i].type = MIPI_DSI_DCS_LONG_WRITE;
+			break;
+		}
+	}
+
+	ret = mipi_dsi_device_transfer_batch(dsi, msgs, count);
+
+out:
+	if (msgs != stack_msgs)
+		kfree(msgs);
+
+	return ret;
+}
+EXPORT_SYMBOL(mipi_dsi_dcs_write_batch);
+
 /**
  * mipi_dsi_dcs_write_buffer_chatty - mipi_dsi_dcs_write_buffer() w/ an error log
  * @dsi: DSI peripheral device
diff --git a/include/drm/drm_mipi_dsi.h b/include/drm/drm_mipi_dsi.h
index 7ff439672..e728f6c1c 100644
--- a/include/drm/drm_mipi_dsi.h
+++ b/include/drm/drm_mipi_dsi.h
@@ -64,11 +64,22 @@ struct mipi_dsi_packet {
 int mipi_dsi_create_packet(struct mipi_dsi_packet *packet,
 			   const struct mipi_dsi_msg *msg);
 
+/**
+ * struct mipi_dsi_dcs_cmd - DCS command buffer for batch transfers
+ * @data: buffer containing the DCS command and parameters
+ * @len: size of @data in bytes
+ */
+struct mipi_dsi_dcs_cmd {
+	const void *data;
+	size_t len;
+};
+
 /**
  * struct mipi_dsi_host_ops - DSI bus operations
  * @attach: attach DSI device to DSI host
  * @detach: detach DSI device from DSI host
  * @transfer: transmit a DSI packet
+ * @transfer_batch: optionally transmit a batch of DSI packets in one operation
  *
  * DSI packets transmitted by .transfer() are passed in as mipi_dsi_msg
  * structures. This structure contains information about the type of packet
@@ -78,6 +89,11 @@ int mipi_dsi_create_packet(struct mipi_dsi_packet *packet,
  * transmitted for write packets or the number of bytes received for read
  * packets.
  *
+ * When implemented, .transfer_batch() transmits @count packets in order and
+ * returns 0 on success or a negative error code on failure. Host drivers whose
+ * hardware supports packing multiple command packets into a single DMA transfer
+ * can use it to send a sequence of commands within a single blanking period.
+ *
  * Note that typically DSI packet transmission is atomic, so the .transfer()
  * function will seldomly return anything other than the number of bytes
  * contained in the transmit buffer on success.
@@ -94,6 +110,9 @@ struct mipi_dsi_host_ops {
 		      struct mipi_dsi_device *dsi);
 	ssize_t (*transfer)(struct mipi_dsi_host *host,
 			    const struct mipi_dsi_msg *msg);
+	int (*transfer_batch)(struct mipi_dsi_host *host,
+			      const struct mipi_dsi_msg *msgs,
+			      size_t count);
 };
 
 /**
@@ -336,6 +355,8 @@ enum mipi_dsi_dcs_tear_mode {
 
 ssize_t mipi_dsi_dcs_write_buffer(struct mipi_dsi_device *dsi,
 				  const void *data, size_t len);
+int mipi_dsi_dcs_write_batch(struct mipi_dsi_device *dsi,
+			     const struct mipi_dsi_dcs_cmd *cmds, size_t count);
 int mipi_dsi_dcs_write_buffer_chatty(struct mipi_dsi_device *dsi,
 				     const void *data, size_t len);
 void mipi_dsi_dcs_write_buffer_multi(struct mipi_dsi_multi_context *ctx,
-- 
2.43.0


  reply	other threads:[~2026-11-29 13:00 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-29 13:00 [PATCH 0/5] drm: mipi-dsi/msm/panel: add DSI batch transfer and s6e88a0-ams452ef01 backlight Vladimir Bely
2026-11-29 13:00 ` Vladimir Bely [this message]
2026-11-29 13:00 ` [PATCH 2/5] drm/msm/dsi: implement transfer_batch using multi-packet CMD DMA Vladimir Bely
2026-11-29 13:00 ` [PATCH 3/5] drm/panel: s6e88a0-ams452ef01: set prepare_prev_first Vladimir Bely
2026-11-29 13:00 ` [PATCH 4/5] drm/panel: s6e88a0-ams452ef01: move display off to disable callback Vladimir Bely
2026-11-29 13:00 ` [PATCH 5/5] drm/panel: s6e88a0-ams452ef01: add backlight support Vladimir Bely

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261129130026.581466-2-vlwwwwww@gmail.com \
    --to=vlwwwwww@gmail.com \
    --cc=Michael.Srba@seznam.cz \
    --cc=abhinav.kumar@linux.dev \
    --cc=airlied@gmail.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=freedreno@lists.freedesktop.org \
    --cc=jesszhan0024@gmail.com \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lumag@kernel.org \
    --cc=maarten.lankhorst@linux.intel.com \
    --cc=marijn.suijten@somainline.org \
    --cc=mripard@kernel.org \
    --cc=neil.armstrong@linaro.org \
    --cc=robin.clark@oss.qualcomm.com \
    --cc=sean@poorly.run \
    --cc=simona@ffwll.ch \
    --cc=stephan@gerhold.net \
    --cc=tzimmermann@suse.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®