mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 0/5] drm: mipi-dsi/msm/panel: add DSI batch transfer and s6e88a0-ams452ef01 backlight
@ 2026-11-29 13:00 Vladimir Bely
  2026-11-29 13:00 ` [PATCH 1/5] drm/mipi-dsi: add multi-message batch transfer support Vladimir Bely
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Vladimir Bely @ 2026-11-29 13:00 UTC (permalink / raw)
  To: Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann,
	Neil Armstrong, Rob Clark, Dmitry Baryshkov
  Cc: David Airlie, Simona Vetter, Abhinav Kumar, Jessica Zhang,
	Sean Paul, Marijn Suijten, Stephan Gerhold, Michael Srba,
	dri-devel, linux-arm-msm, freedreno, linux-kernel, Vladimir Bely

This series adds multi-message batch transfer support to MIPI DSI and
drm/msm/dsi, together with its first user: Samsung AMS452EF01 (S6E88A0)
AMOLED backlight support.

On video-mode DSI hosts that must synchronize command transfers with
blanking (such as Qualcomm DSI 6G < v2.1 without hardware DMA line
scheduling), each separate mipi_dsi_host_ops.transfer() call waits for a
full frame cycle (~33 ms at 60 Hz).  Panels whose runtime brightness
updates require multiple DCS commands (e.g., Samsung S6E88A0 sending
test-key, AOR, ELVSS, gamma, latch, and test-key-off = 6 packets, 80
bytes total) consequently take ~200-230 ms per brightness step (~4.5
updates/sec), making slider drags and wake fade-in animations visibly
choppy and spreading AOR/ELVSS/gamma writes across multiple frames.

Qualcomm's DSI CMD DMA engine natively supports chaining multiple
packets in one DMA buffer by setting BIT(7) ("Last packet") only on the
last packet.  This series exposes that capability cleanly via an
optional .transfer_batch() host op and mipi_dsi_dcs_write_batch()
(falling back to sequential .transfer() calls on all other hosts),
implements multi-packet CMD DMA in drm/msm/dsi, and uses it in
panel-samsung-s6e88a0-ams452ef01.

Patches 3-5 supersede the earlier standalone panel series [1] so the new
mipi_dsi_dcs_write_batch() helper is submitted together with its first
in-tree caller:
- Patches 3-4 are unchanged from [1].
- Patch 5 replaces the 6 separate mipi_dsi_dcs_write_*_multi() calls in
  s6e88a0_ams452ef01_bl_update_status() with a single
  mipi_dsi_dcs_write_batch() call.

Tested on Samsung Galaxy A3 (SM-A300F, MSM8916, DSI 6G v1.3, rev C
AMS452EF01 panel): 20 consecutive brightness updates complete in 705 ms
(35 ms/update, ~6x faster than ~200 ms) with zero DSI/MDP errors and
smooth slider and wake fade transitions.

[1] https://lore.kernel.org/linux-arm-msm/20261129002512.993570-1-vlwwwwww@gmail.com/

Stephan Gerhold (1):
  drm/panel: s6e88a0-ams452ef01: set prepare_prev_first

Vladimir Bely (4):
  drm/mipi-dsi: add multi-message batch transfer support
  drm/msm/dsi: implement transfer_batch using multi-packet CMD DMA
  drm/panel: s6e88a0-ams452ef01: move display off to disable callback
  drm/panel: s6e88a0-ams452ef01: add backlight support

 drivers/gpu/drm/drm_mipi_dsi.c                |  98 +++
 drivers/gpu/drm/msm/dsi/dsi.h                 |   4 +
 drivers/gpu/drm/msm/dsi/dsi_host.c            | 187 +++-
 drivers/gpu/drm/msm/dsi/dsi_manager.c         |  40 +
 drivers/gpu/drm/panel/Kconfig                 |   1 +
 .../panel/panel-samsung-s6e88a0-ams452ef01.c  | 833 +++++++++++++++++-
 include/drm/drm_mipi_dsi.h                    |  21 +
 7 files changed, 1165 insertions(+), 19 deletions(-)


base-commit: 5ce32a0c94a827ff44ee60898c28060714dcff75
-- 
2.43.0


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

* [PATCH 1/5] drm/mipi-dsi: add multi-message batch transfer support
  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
  2026-11-29 13:00 ` [PATCH 2/5] drm/msm/dsi: implement transfer_batch using multi-packet CMD DMA Vladimir Bely
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Vladimir Bely @ 2026-11-29 13:00 UTC (permalink / raw)
  To: Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann,
	Neil Armstrong, Rob Clark, Dmitry Baryshkov
  Cc: David Airlie, Simona Vetter, Abhinav Kumar, Jessica Zhang,
	Sean Paul, Marijn Suijten, Stephan Gerhold, Michael Srba,
	dri-devel, linux-arm-msm, freedreno, linux-kernel, Vladimir Bely

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


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

* [PATCH 2/5] drm/msm/dsi: implement transfer_batch using multi-packet CMD DMA
  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 ` [PATCH 1/5] drm/mipi-dsi: add multi-message batch transfer support Vladimir Bely
@ 2026-11-29 13:00 ` Vladimir Bely
  2026-11-29 13:00 ` [PATCH 3/5] drm/panel: s6e88a0-ams452ef01: set prepare_prev_first Vladimir Bely
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Vladimir Bely @ 2026-11-29 13:00 UTC (permalink / raw)
  To: Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann,
	Neil Armstrong, Rob Clark, Dmitry Baryshkov
  Cc: David Airlie, Simona Vetter, Abhinav Kumar, Jessica Zhang,
	Sean Paul, Marijn Suijten, Stephan Gerhold, Michael Srba,
	dri-devel, linux-arm-msm, freedreno, linux-kernel, Vladimir Bely

The MSM DSI command DMA engine natively supports chaining multiple
packets in a single DMA buffer by setting BIT(7) ("Last packet") only on
the final packet of the transfer.  Previously, each mipi_dsi_msg was
dispatched as its own DMA transfer, meaning every command in video mode
paid a full dsi_wait4video_eng_busy() cycle (~33 ms at 60 Hz) on DSI 6G
controllers without hardware DMA scheduling.

For panels whose brightness updates require multiple DCS commands (such
as Samsung S6E88A0 AMOLED panels sending test-key, AOR, ELVSS, gamma,
latch, and test-key-off = 6 commands, 80 bytes total), a single
brightness change took ~200-230 ms (~4.5 updates/sec).

Implement struct mipi_dsi_host_ops.transfer_batch() by packing
contiguous write-only messages that share the same LPM flag into a
single CMD DMA buffer (splitting cleanly if a chunk exceeds the BLLP or
TX buffer limit, and falling back to single-message transfer for reads
or empty messages).  Tested on Samsung Galaxy A3 (SM-A300F, MSM8916,
DSI 6G v1.3): backlight updates drop from ~200 ms to ~35 ms (~6x faster)
with all 6 commands sent atomically in a single VBLANK.

Signed-off-by: Vladimir Bely <vlwwwwww@gmail.com>
---
 drivers/gpu/drm/msm/dsi/dsi.h         |   4 +
 drivers/gpu/drm/msm/dsi/dsi_host.c    | 187 +++++++++++++++++++++++---
 drivers/gpu/drm/msm/dsi/dsi_manager.c |  40 ++++++
 3 files changed, 214 insertions(+), 17 deletions(-)

diff --git a/drivers/gpu/drm/msm/dsi/dsi.h b/drivers/gpu/drm/msm/dsi/dsi.h
index 93c028a12..e7b3c66e7 100644
--- a/drivers/gpu/drm/msm/dsi/dsi.h
+++ b/drivers/gpu/drm/msm/dsi/dsi.h
@@ -51,6 +51,8 @@ struct msm_dsi {
 int msm_dsi_manager_connector_init(struct msm_dsi *msm_dsi,
 				   struct drm_encoder *encoder);
 int msm_dsi_manager_cmd_xfer(int id, const struct mipi_dsi_msg *msg);
+int msm_dsi_manager_cmd_xfer_batch(int id, const struct mipi_dsi_msg *msgs,
+				   size_t count);
 bool msm_dsi_manager_cmd_xfer_trigger(int id, u32 dma_base, u32 len);
 int msm_dsi_manager_register(struct msm_dsi *msm_dsi);
 void msm_dsi_manager_unregister(struct msm_dsi *msm_dsi);
@@ -64,6 +66,8 @@ void msm_dsi_host_xfer_restore(struct mipi_dsi_host *host,
 					const struct mipi_dsi_msg *msg);
 int msm_dsi_host_cmd_tx(struct mipi_dsi_host *host,
 					const struct mipi_dsi_msg *msg);
+int msm_dsi_host_cmd_tx_batch(struct mipi_dsi_host *host,
+			      const struct mipi_dsi_msg *msgs, size_t count);
 int msm_dsi_host_cmd_rx(struct mipi_dsi_host *host,
 					const struct mipi_dsi_msg *msg);
 void msm_dsi_host_cmd_xfer_commit(struct mipi_dsi_host *host,
diff --git a/drivers/gpu/drm/msm/dsi/dsi_host.c b/drivers/gpu/drm/msm/dsi/dsi_host.c
index 78f0fd259..6e1630edc 100644
--- a/drivers/gpu/drm/msm/dsi/dsi_host.c
+++ b/drivers/gpu/drm/msm/dsi/dsi_host.c
@@ -1321,6 +1321,32 @@ void dsi_tx_buf_put_6g(struct msm_dsi_host *msm_host)
 	msm_gem_put_vaddr(msm_host->tx_gem_obj);
 }
 
+static int dsi_cmd_dma_pack(u8 *data, const struct mipi_dsi_packet *packet,
+			    const struct mipi_dsi_msg *msg, bool last)
+{
+	int len = (packet->size + 3) & (~0x3);
+
+	/* MSM specific command format in memory */
+	data[0] = packet->header[1];
+	data[1] = packet->header[2];
+	data[2] = packet->header[0];
+	data[3] = last ? BIT(7) : 0; /* Last packet */
+	if (mipi_dsi_packet_format_is_long(msg->type))
+		data[3] |= BIT(6);
+	if (msg->rx_buf && msg->rx_len)
+		data[3] |= BIT(5);
+
+	/* Long packet */
+	if (packet->payload && packet->payload_length)
+		memcpy(data + 4, packet->payload, packet->payload_length);
+
+	/* Append 0xff to the end */
+	if (packet->size < len)
+		memset(data + packet->size, 0xff, len - packet->size);
+
+	return len;
+}
+
 /*
  * prepare cmd buffer to be txed
  */
@@ -1352,23 +1378,7 @@ static int dsi_cmd_dma_add(struct msm_dsi_host *msm_host,
 		return ret;
 	}
 
-	/* MSM specific command format in memory */
-	data[0] = packet.header[1];
-	data[1] = packet.header[2];
-	data[2] = packet.header[0];
-	data[3] = BIT(7); /* Last packet */
-	if (mipi_dsi_packet_format_is_long(msg->type))
-		data[3] |= BIT(6);
-	if (msg->rx_buf && msg->rx_len)
-		data[3] |= BIT(5);
-
-	/* Long packet */
-	if (packet.payload && packet.payload_length)
-		memcpy(data + 4, packet.payload, packet.payload_length);
-
-	/* Append 0xff to the end */
-	if (packet.size < len)
-		memset(data + packet.size, 0xff, len - packet.size);
+	dsi_cmd_dma_pack(data, &packet, msg, true);
 
 	if (cfg_hnd->ops->tx_buf_put)
 		cfg_hnd->ops->tx_buf_put(msm_host);
@@ -1568,6 +1578,90 @@ static int dsi_cmds2buf_tx(struct msm_dsi_host *msm_host,
 	return len;
 }
 
+static int dsi_cmds2buf_tx_batch(struct msm_dsi_host *msm_host,
+				 const struct mipi_dsi_msg *msgs, size_t count)
+{
+	const struct msm_dsi_cfg_handler *cfg_hnd = msm_host->cfg_hnd;
+	int max_len = msm_host->tx_size;
+	int offset = 0, last_offset = 0;
+	u8 *data = NULL;
+	size_t i;
+	int ret;
+
+	if ((msm_host->mode_flags & MIPI_DSI_MODE_VIDEO) && msm_host->mode) {
+		int bllp_len = msm_host->mode->hdisplay *
+			mipi_dsi_pixel_format_to_bpp(msm_host->format) / 8;
+
+		max_len = min(max_len, bllp_len);
+	}
+
+	for (i = 0; i < count; i++) {
+		struct mipi_dsi_packet packet;
+		int pkt_len;
+
+		ret = mipi_dsi_create_packet(&packet, &msgs[i]);
+		if (ret) {
+			pr_err("%s: create packet failed, %d\n", __func__, ret);
+			goto err_put;
+		}
+		pkt_len = (packet.size + 3) & (~0x3);
+		if (pkt_len > max_len) {
+			pr_err("%s: cmd cannot fit into transfer buffer, len=%d\n",
+			       __func__, pkt_len);
+			ret = -EINVAL;
+			goto err_put;
+		}
+
+		if (offset > 0 && offset + pkt_len > max_len) {
+			data[last_offset + 3] |= BIT(7); /* Last packet */
+			if (cfg_hnd->ops->tx_buf_put)
+				cfg_hnd->ops->tx_buf_put(msm_host);
+			data = NULL;
+
+			ret = dsi_cmd_dma_tx(msm_host, offset);
+			if (ret < 0)
+				return ret;
+			if (ret < offset)
+				return -EIO;
+			offset = 0;
+		}
+
+		if (!data) {
+			data = cfg_hnd->ops->tx_buf_get(msm_host);
+			if (IS_ERR(data)) {
+				ret = PTR_ERR(data);
+				pr_err("%s: get vaddr failed, %d\n", __func__, ret);
+				return ret;
+			}
+		}
+
+		dsi_cmd_dma_pack(data + offset, &packet, &msgs[i], false);
+		last_offset = offset;
+		offset += pkt_len;
+	}
+
+	if (offset > 0) {
+		data[last_offset + 3] |= BIT(7); /* Last packet */
+		if (cfg_hnd->ops->tx_buf_put)
+			cfg_hnd->ops->tx_buf_put(msm_host);
+
+		ret = dsi_cmd_dma_tx(msm_host, offset);
+		if (ret < 0)
+			return ret;
+		if (ret < offset)
+			return -EIO;
+	} else if (data && cfg_hnd->ops->tx_buf_put) {
+		cfg_hnd->ops->tx_buf_put(msm_host);
+	}
+
+	return 0;
+
+err_put:
+	if (data && cfg_hnd->ops->tx_buf_put)
+		cfg_hnd->ops->tx_buf_put(msm_host);
+	return ret;
+}
+
 static void dsi_err_worker(struct work_struct *work)
 {
 	struct msm_dsi_host *msm_host =
@@ -1789,10 +1883,61 @@ static ssize_t dsi_host_transfer(struct mipi_dsi_host *host,
 	return ret;
 }
 
+static int dsi_host_transfer_batch(struct mipi_dsi_host *host,
+				   const struct mipi_dsi_msg *msgs,
+				   size_t count)
+{
+	struct msm_dsi_host *msm_host = to_msm_dsi_host(host);
+	size_t i = 0;
+	int ret = 0;
+
+	if (!msgs || !msm_host->power_on)
+		return -EINVAL;
+
+	if (!count)
+		return 0;
+
+	mutex_lock(&msm_host->cmd_mutex);
+	while (i < count) {
+		size_t j;
+		u16 lpm;
+
+		if ((msgs[i].rx_buf && msgs[i].rx_len) ||
+		    !msgs[i].tx_buf || !msgs[i].tx_len) {
+			ret = msm_dsi_manager_cmd_xfer(msm_host->id, &msgs[i]);
+			i++;
+		} else {
+			lpm = msgs[i].flags & MIPI_DSI_MSG_USE_LPM;
+			j = i + 1;
+			while (j < count &&
+			       !(msgs[j].rx_buf && msgs[j].rx_len) &&
+			       msgs[j].tx_buf && msgs[j].tx_len &&
+			       (msgs[j].flags & MIPI_DSI_MSG_USE_LPM) == lpm)
+				j++;
+
+			if (j - i == 1)
+				ret = msm_dsi_manager_cmd_xfer(msm_host->id,
+							       &msgs[i]);
+			else
+				ret = msm_dsi_manager_cmd_xfer_batch(msm_host->id,
+								     &msgs[i],
+								     j - i);
+			i = j;
+		}
+
+		if (ret < 0)
+			break;
+	}
+	mutex_unlock(&msm_host->cmd_mutex);
+
+	return ret < 0 ? ret : 0;
+}
+
 static const struct mipi_dsi_host_ops dsi_host_ops = {
 	.attach = dsi_host_attach,
 	.detach = dsi_host_detach,
 	.transfer = dsi_host_transfer,
+	.transfer_batch = dsi_host_transfer_batch,
 };
 
 /*
@@ -2225,6 +2370,14 @@ int msm_dsi_host_cmd_tx(struct mipi_dsi_host *host,
 	return dsi_cmds2buf_tx(msm_host, msg);
 }
 
+int msm_dsi_host_cmd_tx_batch(struct mipi_dsi_host *host,
+			      const struct mipi_dsi_msg *msgs, size_t count)
+{
+	struct msm_dsi_host *msm_host = to_msm_dsi_host(host);
+
+	return dsi_cmds2buf_tx_batch(msm_host, msgs, count);
+}
+
 int msm_dsi_host_cmd_rx(struct mipi_dsi_host *host,
 				const struct mipi_dsi_msg *msg)
 {
diff --git a/drivers/gpu/drm/msm/dsi/dsi_manager.c b/drivers/gpu/drm/msm/dsi/dsi_manager.c
index 531d4ff78..45c077fd9 100644
--- a/drivers/gpu/drm/msm/dsi/dsi_manager.c
+++ b/drivers/gpu/drm/msm/dsi/dsi_manager.c
@@ -539,6 +539,46 @@ int msm_dsi_manager_cmd_xfer(int id, const struct mipi_dsi_msg *msg)
 	return ret;
 }
 
+int msm_dsi_manager_cmd_xfer_batch(int id, const struct mipi_dsi_msg *msgs,
+				   size_t count)
+{
+	struct msm_dsi *msm_dsi = dsi_mgr_get_dsi(id);
+	struct msm_dsi *msm_dsi0 = dsi_mgr_get_dsi(DSI_0);
+	struct mipi_dsi_host *host = msm_dsi->host;
+	bool need_sync = IS_SYNC_NEEDED();
+	int ret;
+
+	if (!msgs || !count)
+		return 0;
+
+	if (need_sync && id == DSI_0)
+		return 0;
+
+	if (need_sync && msm_dsi0) {
+		ret = msm_dsi_host_xfer_prepare(msm_dsi0->host, &msgs[0]);
+		if (ret) {
+			pr_err("%s: failed to prepare non-trigger host, %d\n",
+			       __func__, ret);
+			return ret;
+		}
+	}
+	ret = msm_dsi_host_xfer_prepare(host, &msgs[0]);
+	if (ret) {
+		pr_err("%s: failed to prepare host, %d\n", __func__, ret);
+		goto restore_host0;
+	}
+
+	ret = msm_dsi_host_cmd_tx_batch(host, msgs, count);
+
+	msm_dsi_host_xfer_restore(host, &msgs[0]);
+
+restore_host0:
+	if (need_sync && msm_dsi0)
+		msm_dsi_host_xfer_restore(msm_dsi0->host, &msgs[0]);
+
+	return ret;
+}
+
 bool msm_dsi_manager_cmd_xfer_trigger(int id, u32 dma_base, u32 len)
 {
 	struct msm_dsi *msm_dsi = dsi_mgr_get_dsi(id);
-- 
2.43.0


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

* [PATCH 3/5] drm/panel: s6e88a0-ams452ef01: set prepare_prev_first
  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 ` [PATCH 1/5] drm/mipi-dsi: add multi-message batch transfer support Vladimir Bely
  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 ` 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
  4 siblings, 0 replies; 6+ messages in thread
From: Vladimir Bely @ 2026-11-29 13:00 UTC (permalink / raw)
  To: Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann,
	Neil Armstrong, Rob Clark, Dmitry Baryshkov
  Cc: David Airlie, Simona Vetter, Abhinav Kumar, Jessica Zhang,
	Sean Paul, Marijn Suijten, Stephan Gerhold, Michael Srba,
	dri-devel, linux-arm-msm, freedreno, linux-kernel, Vladimir Bely

From: Stephan Gerhold <stephan@gerhold.net>

This is needed to be able to send DSI commands when DRM_PANEL_BRIDGE is
used, because otherwise the DSI host is powered up after the panel
pre_enable() hook is called.

Signed-off-by: Stephan Gerhold <stephan@gerhold.net>
Signed-off-by: Vladimir Bely <vlwwwwww@gmail.com>
---
 drivers/gpu/drm/panel/panel-samsung-s6e88a0-ams452ef01.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/gpu/drm/panel/panel-samsung-s6e88a0-ams452ef01.c b/drivers/gpu/drm/panel/panel-samsung-s6e88a0-ams452ef01.c
index 2178e03e4..a4063a5af 100644
--- a/drivers/gpu/drm/panel/panel-samsung-s6e88a0-ams452ef01.c
+++ b/drivers/gpu/drm/panel/panel-samsung-s6e88a0-ams452ef01.c
@@ -195,6 +195,7 @@ static int s6e88a0_ams452ef01_probe(struct mipi_dsi_device *dsi)
 	dsi->lanes = 2;
 	dsi->format = MIPI_DSI_FMT_RGB888;
 	dsi->mode_flags = MIPI_DSI_MODE_VIDEO | MIPI_DSI_MODE_VIDEO_BURST;
+	ctx->panel.prepare_prev_first = true;
 
 	ret = devm_drm_panel_add(dev, &ctx->panel);
 	if (ret)
-- 
2.43.0


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

* [PATCH 4/5] drm/panel: s6e88a0-ams452ef01: move display off to disable callback
  2026-11-29 13:00 [PATCH 0/5] drm: mipi-dsi/msm/panel: add DSI batch transfer and s6e88a0-ams452ef01 backlight Vladimir Bely
                   ` (2 preceding siblings ...)
  2026-11-29 13:00 ` [PATCH 3/5] drm/panel: s6e88a0-ams452ef01: set prepare_prev_first Vladimir Bely
@ 2026-11-29 13:00 ` Vladimir Bely
  2026-11-29 13:00 ` [PATCH 5/5] drm/panel: s6e88a0-ams452ef01: add backlight support Vladimir Bely
  4 siblings, 0 replies; 6+ messages in thread
From: Vladimir Bely @ 2026-11-29 13:00 UTC (permalink / raw)
  To: Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann,
	Neil Armstrong, Rob Clark, Dmitry Baryshkov
  Cc: David Airlie, Simona Vetter, Abhinav Kumar, Jessica Zhang,
	Sean Paul, Marijn Suijten, Stephan Gerhold, Michael Srba,
	dri-devel, linux-arm-msm, freedreno, linux-kernel, Vladimir Bely

Currently the driver has no .disable callback and only sends
MIPI_DCS_SET_DISPLAY_OFF in unprepare(), after the DSI host has already
stopped the video stream. Because this is a video-mode AMOLED panel
without internal frame memory, leaving display-on active after video
stops produces ~160 ms of visible noise/stripes on every screen blank.

Add a .disable callback that sends display-off and waits 35 ms while
the video stream is still active, keeping sleep-in in unprepare().
Tested on Samsung Galaxy A3 (SM-A300F).

Signed-off-by: Vladimir Bely <vlwwwwww@gmail.com>
---
 .../drm/panel/panel-samsung-s6e88a0-ams452ef01.c | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/panel/panel-samsung-s6e88a0-ams452ef01.c b/drivers/gpu/drm/panel/panel-samsung-s6e88a0-ams452ef01.c
index a4063a5af..43502a3ea 100644
--- a/drivers/gpu/drm/panel/panel-samsung-s6e88a0-ams452ef01.c
+++ b/drivers/gpu/drm/panel/panel-samsung-s6e88a0-ams452ef01.c
@@ -82,8 +82,6 @@ static void s6e88a0_ams452ef01_off(struct s6e88a0_ams452ef01 *ctx)
 
 	dsi->mode_flags &= ~MIPI_DSI_MODE_LPM;
 
-	mipi_dsi_dcs_set_display_off_multi(&dsi_ctx);
-	mipi_dsi_msleep(&dsi_ctx, 35);
 	mipi_dsi_dcs_enter_sleep_mode_multi(&dsi_ctx);
 	mipi_dsi_msleep(&dsi_ctx, 120);
 }
@@ -110,6 +108,19 @@ static int s6e88a0_ams452ef01_prepare(struct drm_panel *panel)
 	return 0;
 }
 
+/* Blank the panel while the video stream still runs, it shows noise without */
+static int s6e88a0_ams452ef01_disable(struct drm_panel *panel)
+{
+	struct s6e88a0_ams452ef01 *ctx = to_s6e88a0_ams452ef01(panel);
+	struct mipi_dsi_multi_context dsi_ctx = { .dsi = ctx->dsi };
+
+	ctx->dsi->mode_flags &= ~MIPI_DSI_MODE_LPM;
+	mipi_dsi_dcs_set_display_off_multi(&dsi_ctx);
+	mipi_dsi_msleep(&dsi_ctx, 35);
+
+	return dsi_ctx.accum_err;
+}
+
 static int s6e88a0_ams452ef01_unprepare(struct drm_panel *panel)
 {
 	struct s6e88a0_ams452ef01 *ctx = to_s6e88a0_ams452ef01(panel);
@@ -156,6 +167,7 @@ static int s6e88a0_ams452ef01_get_modes(struct drm_panel *panel,
 }
 
 static const struct drm_panel_funcs s6e88a0_ams452ef01_panel_funcs = {
+	.disable = s6e88a0_ams452ef01_disable,
 	.unprepare = s6e88a0_ams452ef01_unprepare,
 	.prepare = s6e88a0_ams452ef01_prepare,
 	.get_modes = s6e88a0_ams452ef01_get_modes,
-- 
2.43.0


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

* [PATCH 5/5] drm/panel: s6e88a0-ams452ef01: add backlight support
  2026-11-29 13:00 [PATCH 0/5] drm: mipi-dsi/msm/panel: add DSI batch transfer and s6e88a0-ams452ef01 backlight Vladimir Bely
                   ` (3 preceding siblings ...)
  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 ` Vladimir Bely
  4 siblings, 0 replies; 6+ messages in thread
From: Vladimir Bely @ 2026-11-29 13:00 UTC (permalink / raw)
  To: Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann,
	Neil Armstrong, Rob Clark, Dmitry Baryshkov
  Cc: David Airlie, Simona Vetter, Abhinav Kumar, Jessica Zhang,
	Sean Paul, Marijn Suijten, Stephan Gerhold, Michael Srba,
	dri-devel, linux-arm-msm, freedreno, linux-kernel, Vladimir Bely

Add AMOLED brightness control ("smart dimming") for the Samsung
AMS452EF01 panel with S6E88A0 controller:

- On first prepare(), read panel revision ID3 (DCh) and the 33-byte
  factory MTP calibration (C8h) under level-2 test key, then precompute
  the 62-level gamma table (5..360 cd/m2) for revision A or C panels
  using fixed-point math matching the vendor algorithm. If calibration
  read fails, fall back gracefully to the fixed max-brightness gamma.
- Register a raw backlight device (0..255) on ctx->panel.backlight so
  drm_panel_enable()/disable() drive it automatically.
- In update_status(), map brightness 0..255 to the 62 hardware levels
  (skipping redundant writes when the level is unchanged or the panel is
  disabled/blanked) and send test-key-on (F0h), AOR (B2h), ELVSS (B6h),
  gamma (CAh), latch (F7h), and test-key-off (F0h) atomically via
  mipi_dsi_dcs_write_batch() in HS mode so the active video stream is
  not disturbed and updates complete in a single VBLANK (~35 ms on
  MSM8916 instead of ~200 ms with 6 individual transfers).
- Add `depends on BACKLIGHT_CLASS_DEVICE` to
  DRM_PANEL_SAMSUNG_S6E88A0_AMS452EF01 in Kconfig.

Tested on Samsung Galaxy A3 (SM-A300F, rev C panel) with smooth
brightness transitions across the full 0..255 range.

Signed-off-by: Vladimir Bely <vlwwwwww@gmail.com>
---
 drivers/gpu/drm/panel/Kconfig                 |   1 +
 .../panel/panel-samsung-s6e88a0-ams452ef01.c  | 816 ++++++++++++++++++
 2 files changed, 817 insertions(+)

diff --git a/drivers/gpu/drm/panel/Kconfig b/drivers/gpu/drm/panel/Kconfig
index 26ffa2378..39bad7f6c 100644
--- a/drivers/gpu/drm/panel/Kconfig
+++ b/drivers/gpu/drm/panel/Kconfig
@@ -1035,6 +1035,7 @@ config DRM_PANEL_SAMSUNG_S6E88A0_AMS427AP24
 config DRM_PANEL_SAMSUNG_S6E88A0_AMS452EF01
 	tristate "Samsung AMS452EF01 panel with S6E88A0 DSI video mode controller"
 	depends on OF
+	depends on BACKLIGHT_CLASS_DEVICE
 	select DRM_MIPI_DSI
 	select VIDEOMODE_HELPERS
 
diff --git a/drivers/gpu/drm/panel/panel-samsung-s6e88a0-ams452ef01.c b/drivers/gpu/drm/panel/panel-samsung-s6e88a0-ams452ef01.c
index 43502a3ea..faa5e7d35 100644
--- a/drivers/gpu/drm/panel/panel-samsung-s6e88a0-ams452ef01.c
+++ b/drivers/gpu/drm/panel/panel-samsung-s6e88a0-ams452ef01.c
@@ -1,11 +1,15 @@
 // SPDX-License-Identifier: GPL-2.0-only
 // Copyright (C) 2019, Michael Srba
 
+#include <linux/backlight.h>
 #include <linux/delay.h>
 #include <linux/gpio/consumer.h>
+#include <linux/math64.h>
+#include <linux/minmax.h>
 #include <linux/module.h>
 #include <linux/of.h>
 #include <linux/regulator/consumer.h>
+#include <linux/slab.h>
 
 #include <video/mipi_display.h>
 
@@ -15,11 +19,697 @@
 
 #include "panel-samsung-dsi.h"
 
+/*
+ * Brightness levels and the tables of the vendor driver. Each level has an
+ * AOR and ELVSS setting, and a gamma generated from the panel calibration.
+ */
+/*
+ * Luminance of the brightness levels, in cd/m2:
+ * 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 19, 20, 21
+ * 22, 24, 25, 27, 29, 30, 32, 34, 37, 39, 41, 44, 47, 50, 53, 56
+ * 60, 64, 68, 72, 77, 82, 87, 93, 98, 105, 111, 119, 126, 134, 143, 152
+ * 162, 172, 183, 195, 207, 220, 234, 249, 265, 282, 300, 316, 333, 360
+ */
+
+/* Highest backlight brightness (0-255) mapped to each level */
+static const u8 s6e88a0_ams452ef01_brightness_max[] = {
+	5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
+	15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
+	25, 26, 27, 28, 29, 30, 32, 34, 36, 38,
+	40, 43, 46, 49, 52, 56, 59, 63, 67, 71,
+	76, 80, 86, 91, 97, 104, 110, 118, 125, 133,
+	142, 150, 160, 170, 181, 193, 205, 218, 230, 242,
+	254, 255,
+};
+
+/* AMOLED Off Ratio (B2h) of each level */
+static const u16 s6e88a0_ams452ef01_aor[] = {
+	0x3ac, 0x3a5, 0x39b, 0x393, 0x389, 0x380, 0x377, 0x36f,
+	0x365, 0x35c, 0x352, 0x34a, 0x341, 0x32f, 0x325, 0x31d,
+	0x312, 0x301, 0x2f7, 0x2e5, 0x2d3, 0x2c8, 0x2b7, 0x2a2,
+	0x287, 0x274, 0x25f, 0x242, 0x222, 0x205, 0x1e5, 0x1c7,
+	0x19e, 0x178, 0x178, 0x178, 0x178, 0x178, 0x178, 0x178,
+	0x178, 0x178, 0x178, 0x178, 0x178, 0x178, 0x178, 0x178,
+	0x178, 0x14f, 0x122, 0x0ef, 0x0bd, 0x085, 0x049, 0x00a,
+	0x00a, 0x00a, 0x00a, 0x00a, 0x00a, 0x00a,
+};
+
+/* ELVSS (B6h) of each level */
+static const u8 s6e88a0_ams452ef01_elvss[] = {
+	0x17, 0x17, 0x17, 0x17, 0x17, 0x17, 0x17, 0x17,
+	0x17, 0x17, 0x17, 0x17, 0x17, 0x17, 0x17, 0x17,
+	0x17, 0x17, 0x17, 0x17, 0x17, 0x17, 0x17, 0x17,
+	0x17, 0x17, 0x17, 0x17, 0x17, 0x17, 0x17, 0x17,
+	0x17, 0x17, 0x17, 0x17, 0x17, 0x16, 0x16, 0x15,
+	0x15, 0x15, 0x14, 0x14, 0x13, 0x13, 0x12, 0x12,
+	0x11, 0x11, 0x10, 0x10, 0x10, 0x10, 0x0f, 0x0f,
+	0x0f, 0x0e, 0x0d, 0x0c, 0x0c, 0x0b,
+};
+
+/* Panel revision A: luminance the gamma of each level is based on (AOR does the rest) */
+static const u16 s6e88a0_ams452ef01_base_luminance_reva[] = {
+	112, 112, 112, 112, 112, 112, 112, 112, 112, 112,
+	112, 112, 112, 112, 112, 112, 112, 112, 112, 112,
+	112, 112, 112, 112, 112, 112, 112, 112, 112, 112,
+	112, 112, 112, 112, 112, 120, 129, 134, 144, 153,
+	162, 173, 182, 196, 206, 218, 232, 245, 257, 257,
+	257, 257, 257, 257, 257, 257, 276, 289, 303, 321,
+	336, 360,
+};
+
+/* Panel revision A: gray index offsets of V255 V203 V151 V87 V51 V35 V23 V11 V3 */
+static const s8 s6e88a0_ams452ef01_gradation_offset_reva[][9] = {
+	{ 0, 6, 10, 20, 29, 34, 38, -1, 0 },
+	{ 0, 5, 9, 19, 26, 30, 35, -1, -2 },
+	{ 0, 5, 7, 16, 22, 26, 30, 3, 1 },
+	{ 0, 4, 7, 14, 20, 24, 27, 29, 4 },
+	{ 0, 4, 6, 13, 19, 22, 26, 28, 14 },
+	{ 0, 4, 6, 12, 17, 20, 24, 27, 22 },
+	{ 0, 4, 6, 11, 16, 19, 23, 25, 22 },
+	{ 0, 3, 5, 10, 14, 17, 21, 24, 28 },
+	{ 0, 3, 5, 10, 14, 16, 20, 23, 24 },
+	{ 0, 3, 5, 9, 13, 15, 19, 22, 22 },
+	{ 0, 3, 4, 8, 12, 14, 18, 21, 22 },
+	{ 0, 3, 4, 8, 11, 13, 17, 20, 24 },
+	{ 0, 3, 4, 7, 10, 12, 16, 19, 25 },
+	{ 0, 3, 4, 6, 9, 11, 15, 18, 19 },
+	{ 0, 3, 3, 6, 9, 10, 14, 17, 19 },
+	{ 0, 3, 3, 6, 9, 10, 14, 17, 18 },
+	{ 0, 3, 3, 6, 8, 10, 14, 16, 18 },
+	{ 0, 3, 3, 5, 7, 9, 13, 15, 18 },
+	{ 0, 3, 3, 5, 7, 9, 12, 15, 18 },
+	{ 0, 3, 3, 5, 6, 8, 11, 14, 18 },
+	{ 0, 3, 3, 4, 6, 7, 10, 13, 20 },
+	{ 0, 3, 3, 4, 5, 7, 10, 13, 17 },
+	{ 0, 3, 3, 4, 5, 7, 9, 12, 16 },
+	{ 0, 2, 3, 4, 5, 6, 9, 12, 12 },
+	{ 0, 2, 2, 3, 4, 5, 8, 11, 13 },
+	{ 0, 2, 2, 3, 4, 5, 8, 11, 10 },
+	{ 0, 2, 2, 3, 4, 5, 7, 10, 12 },
+	{ 0, 2, 2, 3, 4, 4, 7, 10, 10 },
+	{ 0, 2, 2, 3, 3, 4, 6, 9, 8 },
+	{ 0, 2, 2, 2, 3, 3, 6, 8,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3 },
+	{ 0, 0, 0, 0, 0, 0, 0, 0, 0 },
+};
+
+/* Panel revision A: R/G/B corrections of V255 V203 V151 V87 V51 V35 V23 V11 */
+static const s8 s6e88a0_ams452ef01_rgb_offset_reva[][24] = {
+	{ -3, 0, -3, -1, 0, -2, -4, 0, -4, -7, 4, -8, -7, 4, -10, -4, 3, -7, -1, 1, -3, -2, 3, -8 },
+	{ -2, 0, -2, -2, 0, -2, -3, 0, -4, -7, 3, -8, -7, 4, -10, -4, 2, -5, 0, 1, -2, -2, 4, -10 },
+	{ -2, 0, -2, -1, 0, -1, -2, 0, -3, -7, 3, -8, -7, 4, -9, -2, 2, -4, 0, 1, -4, -2, 4, -9 },
+	{ -1, 0, -1, -2, 0, -2, -1, 0, -2, -6, 3, -7, -7, 3, -8, -1, 2, -4, -1, 2, -6, 0, 1, -3 },
+	{ -1, 0, -1, -1, 0, -1, -2, 0, -3, -5, 2, -6, -7, 4, -9, -4, 2, -6, -1, 1, -4, 2, 1, -2 },
+	{ -1, 0, -1, -1, 0, -1, -1, 0, -2, -4, 2, -5, -6, 4, -8, -2, 2, -6, -3, 2, -6, 0, 2, -4 },
+	{ -1, 0, -1, 0, 0, -1, -2, 0, -2, -4, 2, -5, -7, 3, -8, -2, 2, -6, -3, 2, -5, 0, 2, -4 },
+	{ -1, 0, -1, 0, 0, 0, -1, 0, -2, -4, 2, -4, -6, 3, -8, -3, 2, -5, -2, 1, -4, 0, 3, -7 },
+	{ 0, 0, 0, -1, 0, -1, -2, 0, -2, -4, 1, -4, -3, 3, -6, -5, 2, -6, -2, 2, -5, -1, 2, -5 },
+	{ 0, 0, 0, -1, 0, -1, -1, 0, -1, -3, 1, -4, -4, 3, -7, -3, 2, -5, -2, 2, -6, -1, 3, -8 },
+	{ 0, 0, 0, -1, 0, -1, -1, 0, -1, -4, 1, -4, -3, 3, -7, -3, 2, -5, -2, 2, -6, 0, 3, -6 },
+	{ 0, 0, 0, -1, 0, -1, -1, 0, -1, -3, 1, -3, -4, 3, -8, -3, 2, -5, -1, 3, -6, -2, 2, -6 },
+	{ 0, 0, 0, 0, 0, 0, -1, 0, -2, -3, 1, -3, -3, 3, -6, -3, 2, -5, -2, 2, -6, -4, 3, -7 },
+	{ 0, 0, 0, 0, 0, 0, -1, 0, -1, -3, 1, -4, -4, 3, -7, -3, 1, -4, -2, 3, -7, -2, 3, -6 },
+	{ 0, 0, 0, 0, 0, 0, -1, 0, -1, -2, 1, -3, -2, 3, -6, -5, 2, -6, -3, 3, -7, -2, 3, -7 },
+	{ 0, 0, 0, 0, 0, 0, -1, 0, -1, -2, 1, -3, -3, 2, -6, -5, 2, -6, -2, 3, -6, -3, 3, -8 },
+	{ 0, 0, 0, 0, 0, 0, -1, 0, -1, -2, 1, -3, -3, 3, -6, -3, 1, -4, -2, 2, -6, -3, 5, -10 },
+	{ 0, 0, 0, 0, 0, 0, -1, 0, -1, -1, 0, -2, -2, 3, -6, -4, 1, -4, -3, 2, -6, -1, 4, -9 },
+	{ 0, 0, 0, 0, 0, 0, -1, 0, -1, -1, 0, -2, -2, 2, -6, -3, 2, -4, -6, 3, -8, -2, 4, -8 },
+	{ 0, 0, 0, 0, 0, 0, -1, 0, -1, -1, 0, -2, -2, 2, -6, -2, 1, -3, -4, 3, -7, -3, 4, -8 },
+	{ 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, -2, -1, 2, -6, -4, 2, -4, -2, 2, -6, -4, 4, -9 },
+	{ 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, -2, -2, 2, -6, -4, 1, -4, -3, 2, -6, -3, 5, -10 },
+	{ 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, -2, -2, 2, -6, -2, 1, -2, -5, 4, -8, -1, 4, -8 },
+	{ 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, -2, -1, 2, -5, -4, 1, -4, -3, 2, -6, -1, 4, -8 },
+	{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, -1, 2, -5, -4, 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-4 },
+	{ 0, 0, 1, 0, 0, 0, 0, 0, -1, 0, 0, 0, 1, 0, 0, 0, 1, -2, 0, 0, 1, -1, 2, -6 },
+	{ 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0, 0, 0, 0, -2, 0, 0, 1, 0, 2, -5 },
+	{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 1, 0, 0, 0, 0, -2, 0, 0, 1, 0, 1, -4 },
+	{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, -2, 0, 0, 2, 0, 1, -4 },
+	{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
+	{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
+	{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
+	{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
+	{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
+	{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
+	{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
+};
+
+/* Panel revision C: luminance the gamma of each level is based on (AOR does the rest) */
+static const u16 s6e88a0_ams452ef01_base_luminance_revc[] = {
+	111, 111, 111, 111, 111, 111, 111, 111, 111, 111,
+	111, 111, 111, 111, 111, 111, 111, 111, 111, 111,
+	111, 111, 111, 111, 111, 111, 111, 111, 111, 111,
+	111, 111, 111, 111, 117, 123, 131, 140, 148, 157,
+	165, 176, 184, 196, 204, 217, 229, 243, 255, 255,
+	255, 255, 255, 255, 255, 255, 272, 283, 300, 318,
+	333, 360,
+};
+
+/* Panel revision C: gray index offsets of V255 V203 V151 V87 V51 V35 V23 V11 V3 */
+static const s8 s6e88a0_ams452ef01_gradation_offset_revc[][9] = {
+	{ 0, 6, 12, 20, 27, 31, 36, 39, 40 },
+	{ 0, 6, 11, 17, 24, 28, 31, 36, 39 },
+	{ 0, 4, 8, 15, 20, 24, 28, 31, 32 },
+	{ 0, 3, 5, 11, 16, 20, 24, 26, 29 },
+	{ 0, 2, 4, 9, 15, 18, 22, 24, 26 },
+	{ 0, 4, 7, 11, 14, 19, 22, 24, 25 },
+	{ 0, 2, 4, 7, 12, 15, 19, 21, 23 },
+	{ 0, 1, 3, 7, 11, 14, 17, 20, 21 },
+	{ 0, 1, 2, 6, 10, 13, 16, 19, 20 },
+	{ 0, 1, 2, 6, 10, 13, 16, 18, 19 },
+	{ 0, 1, 2, 5, 9, 12, 14, 17, 18 },
+	{ 0, 1, 2, 4, 8, 11, 14, 16, 17 },
+	{ 0, 1, 1, 4, 8, 10, 13, 15, 16 },
+	{ 0, 1, 1, 3, 7, 9, 12, 14, 15 },
+	{ 0, 1, 1, 3, 6, 9, 11, 14, 14 },
+	{ 0, 1, 1, 3, 6, 8, 10, 13, 14 },
+	{ 0, 1, 1, 2, 6, 8, 10, 13, 13 },
+	{ 0, 1, 1, 2, 5, 7, 9, 12, 13 },
+	{ 0, 1, 1, 2, 5, 7, 9, 11, 12 },
+	{ 0, 1, 1, 2, 4, 6, 8, 11, 11 },
+	{ 0, 1, 0, 2, 4, 6, 8, 10, 11 },
+	{ 0, 1, 0, 2, 4, 6, 8, 10, 10 },
+	{ 0, 1, 0, 1, 4, 5, 7, 10, 10 },
+	{ 0, 1, 0, 1, 4, 5, 7, 9, 10 },
+	{ 0, 1, 0, 1, 3, 5, 6, 8, 9 },
+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{ 0, 1, 2, 2, 0, 1, 1, 1, 1 },
+	{ 0, 2, 4, 1, 1, 0, 0, 0, 1 },
+	{ 0, 1, 3, 1, 0, 0, 1, 0, 1 },
+	{ 0, 1, 4, 1, 0, 0, 0, 0, 1 },
+	{ 0, 0, 3, 0, 0, 0, 0, 0, 1 },
+	{ 0, 0, 0, 0, 0, 0, 0, 0, 0 },
+};
+
+/* Panel revision C: R/G/B corrections of V255 V203 V151 V87 V51 V35 V23 V11 */
+static const s8 s6e88a0_ams452ef01_rgb_offset_revc[][24] = {
+	{ -5, 0, -4, -3, 0, -3, -6, 1, -4, -16, 4, -13,
+	  -19, 6, -16, -13, 5, -10, -4, 3, -6, -6, 8, -8 },
+	{ -3, 0, -3, -3, 0, -3, -5, 1, -4, -13, 4, -10,
+	  -15, 5, -13, -15, 4, -12, -10, 5, -13, -6, 4, -8 },
+	{ -4, -1, -4, -3, 0, -2, -4, 1, -3, -14, 4, -10,
+	  -18, 5, -15, -13, 3, -11, -8, 4, -10, -10, 5, -11 },
+	{ -2, 0, -2, -3, 0, -3, -6, 0, -4, -14, 3, -11,
+	  -20, 6, -16, -13, 6, -15, -7, 4, -8, -8, 6, -13 },
+	{ -2, 0, -2, -2, 0, -2, -5, 0, -5, -13, 3, -9,
+	  -18, 6, -14, -13, 6, -14, -7, 4, -11, -11, 6, -14 },
+	{ -2, 0, -2, -2, -1, -2, -5, 0, -4, -10, 3, -8,
+	  -20, 6, -14, -8, 5, -7, -9, 5, -13, -11, 5, -12 },
+	{ 0, 0, 0, -1, 0, -1, -4, 0, -2, -9, 2, -6,
+	  -10, 5, -10, -12, 5, -12, -7, 4, -8, -8, 6, -14 },
+	{ 0, 0, 0, -1, 0, -1, -3, 0, -2, -8, 3, -6,
+	  -10, 5, -10, -9, 5, -11, -6, 5, -10, -8, 5, -11 },
+	{ 0, 0, 0, 0, 0, 0, -4, 0, -3, -7, 2, -5, -12, 5, -11, -9, 5, -11, -9, 6, -12, -6, 5, -12 },
+	{ 0, 0, 0, 0, 0, 0, -4, 0, -3, -7, 2, -5,
+	  -11, 4, -10, -8, 4, -10, -10, 6, -12, -7, 6, -13 },
+	{ 0, 0, 0, 0, 0, 0, -3, 0, -2, -7, 2, -5,
+	  -9, 4, -10, -8, 5, -10, -10, 5, -12, -10, 7, -16 },
+	{ 0, 0, 0, 0, 0, 0, -2, 0, -2, -7, 1, -4, -9, 4, -10, -10, 5, -11, -8, 4, -10, -7, 7, -14 },
+	{ 0, 0, 0, 0, 0, 0, -2, 0, -1, -6, 1, -4, -8, 4, -10, -12, 5, -11, -7, 4, -9, -6, 7, -15 },
+	{ 0, 0, 0, 0, 0, 0, -1, 0, 0, -5, 1, -4, -8, 4, -9, -10, 4, -9, -9, 5, -12, -7, 7, -15 },
+	{ 0, 0, 0, 0, 0, 0, -1, 0, 0, -5, 1, -4, -7, 4, -9, -9, 3, -8, -9, 6, -14, -6, 6, -12 },
+	{ 0, 0, 0, 0, 0, 0, -1, 0, 0, -4, 1, -3, -7, 4, -9, -8, 4, -9, -8, 6, -12, -6, 6, -13 },
+	{ 0, 0, 0, 0, 0, 0, -1, 0, 0, -4, 1, -3, -5, 4, -8, -9, 3, -8, -8, 6, -12, -6, 6, -12 },
+	{ 0, 0, 0, 0, 0, 0, -1, 0, 0, -3, 1, -2, -5, 4, -8, -9, 3, -7, -8, 5, -12, -9, 6, -14 },
+	{ 0, 0, 0, 0, 0, 0, -1, 0, 0, -3, 1, -2, -5, 3, -8, -8, 3, -6, -7, 5, -11, -8, 7, -16 },
+	{ 0, 0, 0, 0, 0, 0, -1, 0, 0, -3, 1, -2, -4, 4, -8, -8, 2, -6, -6, 5, -11, -7, 6, -12 },
+	{ 0, 0, 0, 0, 0, 0, 0, 0, 0, -4, 1, -2, -3, 4, -8, -7, 2, -5, -7, 4, -10, -9, 8, -16 },
+	{ 0, 0, 0, 0, 0, 0, 0, 0, 0, -4, 1, -2, -3, 3, -8, -7, 2, -5, -7, 4, -10, -9, 7, -16 },
+	{ 0, 0, 0, 0, 0, 0, 0, 0, 0, -4, 0, -2, -3, 3, -8, -8, 3, -6, -6, 5, -10, -5, 6, -12 },
+	{ 0, 0, 0, 0, 0, 0, 0, 0, 0, -4, 0, -2, -2, 3, -7, -7, 2, -5, -6, 4, -10, -7, 7, -14 },
+	{ 0, 0, 0, 0, 0, 0, 0, 0, 0, -3, 0, -2, -3, 2, -6, -6, 2, -4, -5, 5, -10, -7, 7, -14 },
+	{ 0, 0, 0, 0, 0, 0, 0, 0, 0, -2, 0, -1, -2, 2, -6, -7, 2, -5, -4, 4, -8, -8, 6, -14 },
+	{ 0, 0, 0, 0, 0, 0, 0, 0, 0, -2, 0, -1, -2, 2, -6, -5, 2, -4, -4, 3, -8, -7, 8, -16 },
+	{ 0, 0, 0, 0, 0, 0, 0, 0, 0, -2, 0, -1, 0, 2, -5, -6, 1, -4, -5, 4, -10, -7, 7, -14 },
+	{ 0, 0, 0, 0, 0, 0, 0, 0, 0, -2, 0, -1, 0, 2, -5, -6, 2, -4, -3, 3, -7, -5, 6, -12 },
+	{ 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, -1, 0, 2, -5, -6, 1, -4, -4, 3, -8, -5, 7, -14 },
+	{ 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, -1, 0, 2, -5, -4, 1, -3, -3, 3, -7, -8, 6, -14 },
+	{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, 2, -4, -4, 1, -3, -3, 2, -6, -7, 7, -16 },
+	{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, -5, -2, 1, -2, -3, 3, -6, -6, 6, -14 },
+	{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, -4, -2, 1, -2, -3, 2, -6, -6, 6, -14 },
+	{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, -4, -2, 0, -2, -2, 2, -4, -6, 7, -16 },
+	{ 1, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0, -1, 0, 2, -4, -3, 1, -2, -1, 2, -4, -6, 6, -13 },
+	{ 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, -4, -2, 0, -1, -3, 2, -6, -4, 6, -13 },
+	{ 0, 0, -1, 1, 0, 0, 0, 0, -1, 0, 0, 0, 0, 2, -4, -2, 0, -1, -1, 2, -5, -6, 6, -14 },
+	{ 0, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0, 0, 0, 1, -4, -3, 0, -1, -2, 2, -6, -7, 6, -14 },
+	{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, -4, -1, 0, -1, -1, 2, -5, -6, 6, -13 },
+	{ 0, 0, 0, 1, 0, 0, 0, 0, -1, 0, 0, 0, 0, 1, -4, -2, 0, 0, -3, 2, -6, -6, 5, -12 },
+	{ 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, -3, -1, 0, -1, -3, 2, -5, -5, 5, -12 },
+	{ 0, 0, 0, 1, 0, 0, 0, 0, -1, 0, 0, 0, 0, 1, -3, -2, 0, -1, -2, 1, -4, -5, 5, -11 },
+	{ 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, 0, 0, 1, -2, 0, 0, 0, -2, 2, -4, -4, 5, -10 },
+	{ 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, -3, -2, 0, -2, -2, 1, -4, -5, 4, -10 },
+	{ 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, -2, 0, 0, -2, -3, 1, -4, -3, 5, -11 },
+	{ 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -2, 0, 0, -2, -2, 1, -3, -3, 4, -10 },
+	{ 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -2, 0, 1, -2, -2, 1, -2, -3, 4, -9 },
+	{ 0, 0, 1, 0, 0, 0, 1, 0, 0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 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
+};
+
+/* (i / 255)^2.15 << 22 */
+static const u32 s6e88a0_ams452ef01_coeff_2p15[] = {
+	0, 28, 125, 298, 553, 894, 1323, 1843,
+	2456, 3164, 3968, 4871, 5873, 6976, 8180, 9488,
+	10901, 12418, 14042, 15773, 17612, 19560, 21618, 23786,
+	26065, 28456, 30959, 33576, 36307, 39152, 42112, 45188,
+	48381, 51690, 55116, 58660, 62323, 66105, 70006, 74027,
+	78168, 82430, 86813, 91318, 95945, 100694, 105567, 110563,
+	115682, 120926, 126294, 131788, 137406, 143150, 149020, 155017,
+	161140, 167390, 173768, 180273, 186906, 193668, 200558, 207578,
+	214726, 222005, 229413, 236951, 244620, 252420, 260351, 268413,
+	276607, 284933, 293391, 301981, 310705, 319561, 328550, 337673,
+	346930, 356321, 365846, 375506, 385300, 395229, 405294, 415494,
+	425830, 436302, 446910, 457654, 468535, 479553, 490708, 502001,
+	513431, 524998, 536704, 548547, 560530, 572650, 584910, 597308,
+	609846, 622523, 635340, 648296, 661393, 674630, 688007, 701525,
+	715183, 728983, 742923, 757005, 771229, 785594, 800101, 814750,
+	829542, 844476, 859552, 874771, 890133, 905639, 921288, 937080,
+	953015, 969095, 985319, 1001686, 1018199, 1034855, 1051656, 1068602,
+	1085693, 1102929, 1120311, 1137838, 1155510, 1173328, 1191293, 1209403,
+	1227659, 1246062, 1264612, 1283308, 1302151, 1321140, 1340277, 1359562,
+	1378994, 1398573, 1418300, 1438175, 1458198, 1478369, 1498688, 1519156,
+	1539772, 1560537, 1581451, 1602514, 1623726, 1645087, 1666598, 1688258,
+	1710068, 1732028, 1754138, 1776398, 1798807, 1821368, 1844078, 1866940,
+	1889952, 1913115, 1936429, 1959894, 1983510, 2007278, 2031197, 2055268,
+	2079490, 2103864, 2128391, 2153069, 2177900, 2202883, 2228018, 2253306,
+	2278747, 2304341, 2330088, 2355987, 2382040, 2408246, 2434606, 2461119,
+	2487786, 2514607, 2541581, 2568710, 2595992, 2623429, 2651020, 2678766,
+	2706666, 2734721, 2762931, 2791295, 2819815, 2848490, 2877320, 2906305,
+	2935446, 2964742, 2994194, 3023802, 3053566, 3083485, 3113561, 3143793,
+	3174181, 3204726, 3235427, 3266285, 3297300, 3328471, 3359800, 3391285,
+	3422927, 3454727, 3486684, 3518799, 3551071, 3583500, 3616088, 3648833,
+	3681736, 3714798, 3748017, 3781395, 3814931, 3848625, 3882478, 3916489,
+	3950660, 3984989, 4019477, 4054124, 4088930, 4123895, 4159020, 4194304,
+};
+
+/* 360 * (i / 255)^2.2 << 22 */
+static const u32 s6e88a0_ams452ef01_curve_2p2_360[] = {
+	0, 7666, 35224, 85949, 161847, 264428,
+	394918, 554357, 743656, 963624, 1214994, 1498435,
+	1814566, 2163961, 2547157, 2964659, 3416945, 3904466,
+	4427652, 4986915, 5582645, 6215219, 6884999, 7592333,
+	8337556, 9120991, 9942953, 10803744, 11703659, 12642984,
+	13621997, 14640966, 15700156, 16799822, 17940214, 19121577,
+	20344148, 21608161, 22913842, 24261416, 25651100, 27083107,
+	28557649, 30074929, 31635150, 33238509, 34885202, 36575418,
+	38309345, 40087169, 41909069, 43775226, 45685814, 47641006,
+	49640972, 51685881, 53775898, 55911184, 58091902, 60318208,
+	62590261, 64908212, 67272215, 69682419, 72138972, 74642022,
+	77191711, 79788183, 82431579, 85122037, 87859696, 90644692,
+	93477158, 96357229, 99285035, 102260706, 105284372, 108356159,
+	111476194, 114644602, 117861504, 121127025, 124441284, 127804402,
+	131216496, 134677686, 138188086, 141747812, 145356979, 149015699,
+	152724084, 156482246, 160290295, 164148340, 168056489, 172014850,
+	176023528, 180082630, 184192259, 188352521, 192563517, 196825349,
+	201138120, 205501929, 209916876, 214383060, 218900580, 223469532,
+	228090013, 232762120, 237485947, 242261589, 247089140, 251968693,
+	256900341, 261884176, 266920288, 272008769, 277149707, 282343194,
+	287589317, 292888165, 298239825, 303644384, 309101929, 314612546,
+	320176319, 325793334, 331463675, 337187426, 342964669, 348795488,
+	354679965, 360618181, 366610218, 372656155, 378756075, 384910055,
+	391118176, 397380516, 403697153, 410068166, 416493632, 422973628,
+	429508231, 436097516, 442741560, 449440438, 456194224, 463002994,
+	469866820, 476785778, 483759940, 490789380, 497874169, 505014380,
+	512210085, 519461355, 526768261, 534130874, 541549264, 549023502,
+	556553657, 564139797, 571781993, 579480313, 587234824, 595045596,
+	602912695, 610836188, 618816144, 626852629, 634945708, 643095448,
+	651301914, 659565173, 667885289, 676262327, 684696351, 693187426,
+	701735616, 710340985, 719003595, 727723510, 736500793, 745335507,
+	754227713, 763177473, 772184850, 781249905, 790372699, 799553293,
+	808791748, 818088124, 827442482, 836854881, 846325381, 855854042,
+	865440922, 875086082, 884789579, 894551472, 904371820, 914250680,
+	924188110, 934184168, 944238911, 954352397, 964524681, 974755822,
+	985045875, 995394897, 1005802944, 1016270071, 1026796335, 1037381790,
+	1048026492, 1058730496, 1069493857, 1080316629, 1091198867, 1102140624,
+	1113141956, 1124202915, 1135323556, 1146503931, 1157744095, 1169044100,
+	1180403998, 1191823843, 1203303688, 1214843583, 1226443583, 1238103738,
+	1249824100, 1261604721, 1273445652, 1285346945, 1297308650, 1309330819,
+	1321413502, 1333556750, 1345760613, 1358025142, 1370350386, 1382736395,
+	1395183219, 1407690908, 1420259511, 1432889077, 1445579655, 1458331295,
+	1471144045, 1484017953, 1496953069, 1509949440,
+};
+
+#define S6E88A0_NUM_LEVELS	((int)ARRAY_SIZE(s6e88a0_ams452ef01_brightness_max))
+#define S6E88A0_GAMMA_LEN	33	/* CAh payload, also the C8h MTP layout */
+#define S6E88A0_SHIFT		22	/* fixed point fraction bits */
+
+/* Gray level of each gamma point: V0 V1 V3 V11 V23 V35 V51 V87 V151 V203 V255 */
+static const u8 s6e88a0_ams452ef01_point_gray[] = {
+	0, 1, 3, 11, 23, 35, 51, 87, 151, 203, 255,
+};
+
+#define POINT_V0	0
+#define POINT_V1	1
+#define POINT_V3	2
+#define POINT_V11	3
+#define POINT_V255	10
+#define NUM_POINTS	((int)ARRAY_SIZE(s6e88a0_ams452ef01_point_gray))
+
+/* Gamma register of the 360 cd/m2 level, which the MTP offsets are relative to */
+static const u8 s6e88a0_ams452ef01_gamma_max[S6E88A0_GAMMA_LEN] = {
+	0x01, 0x00, 0x01, 0x00, 0x01, 0x00,	/* V255 R, G, B */
+	0x80, 0x80, 0x80,			/* V203 R, G, B */
+	0x80, 0x80, 0x80,			/* V151 */
+	0x80, 0x80, 0x80,			/* V87 */
+	0x80, 0x80, 0x80,			/* V51 */
+	0x80, 0x80, 0x80,			/* V35 */
+	0x80, 0x80, 0x80,			/* V23 */
+	0x80, 0x80, 0x80,			/* V11 */
+	0x6b, 0x68, 0x71,			/* V3 */
+	0x00, 0x00, 0x00,			/* VT */
+};
+
+static const u8 s6e88a0_ams452ef01_vt_coeff[] = {
+	0, 12, 24, 36, 48, 60, 72, 84, 96, 108, 138, 148, 158, 168, 178, 186,
+};
+
+/* VREG0 output, 5.8 V on revision A panels and 5.6 V on others */
+#define S6E88A0_VREG_REV_A	((58 << S6E88A0_SHIFT) / 10)
+#define S6E88A0_VREG_REV_C	((56 << S6E88A0_SHIFT) / 10)
+
+struct s6e88a0_ams452ef01_dimming {
+	bool rev_a;
+	s32 vreg;
+	s32 vt[3];
+	/* MTP offsets: V255, then V203 V151 V87 V51 V35 V23 V11 V3, then VT */
+	s32 mtp_v255[3];
+	s32 mtp[8][3];
+	s32 mtp_vt[3];
+	s32 point[3][NUM_POINTS];	/* voltage of each gamma point */
+	s32 gray[3][256];		/* voltage of each gray level */
+};
+
+/* Offsets are sign and magnitude, bit 7 being the sign */
+static s32 s6e88a0_ams452ef01_signed(u8 v)
+{
+	return v & 0x80 ? -(v & 0x7f) : v;
+}
+
+/* Voltage of a gamma point from its register value and the point above */
+static u32 s6e88a0_ams452ef01_point_volt(s32 top, s32 above, s32 reg, u32 coeff)
+{
+	/* top - (top - above) * (coeff + reg) / (coeff * 5) */
+	u64 span = (u64)(s64)(top - above);
+	u64 ratio = div_u64((u64)(s64)(coeff + reg) << S6E88A0_SHIFT, coeff * 5);
+
+	return top - (u32)((span * ratio) >> S6E88A0_SHIFT);
+}
+
+static void s6e88a0_ams452ef01_parse_mtp(struct s6e88a0_ams452ef01_dimming *dim,
+					 const u8 *mtp)
+{
+	int ch, k;
+
+	for (ch = 0; ch < 3; ch++) {
+		dim->mtp_v255[ch] = mtp[2 * ch] ? -mtp[2 * ch + 1] : mtp[2 * ch + 1];
+		for (k = 0; k < 8; k++)
+			dim->mtp[k][ch] = s6e88a0_ams452ef01_signed(mtp[6 + 3 * k + ch]);
+		dim->mtp_vt[ch] = s6e88a0_ams452ef01_signed(mtp[30 + ch]);
+	}
+}
+
+/* Voltages of the gamma points and of every gray level, from the MTP */
+static void s6e88a0_ams452ef01_gen_gray(struct s6e88a0_ams452ef01_dimming *dim)
+{
+	const u8 *ref = s6e88a0_ams452ef01_gamma_max;
+	s32 vreg = dim->vreg;
+	int ch, p, g;
+
+	for (ch = 0; ch < 3; ch++) {
+		s32 *point = dim->point[ch];
+		u32 vt_idx = clamp(dim->mtp_vt[ch], 0, 15);
+		s32 v255 = (ref[2 * ch] << 8 | ref[2 * ch + 1]) + dim->mtp_v255[ch];
+		u64 ratio;
+
+		/* V255 and VT are relative to VREG0 */
+		ratio = div_u64((u64)(s64)(72 + v255) << S6E88A0_SHIFT, 860);
+		point[POINT_V255] = vreg - (u32)(((u64)vreg * ratio) >> S6E88A0_SHIFT);
+		point[POINT_V0] = vreg;
+		point[POINT_V1] = 0;	/* unused, V0-V3 is interpolated */
+
+		ratio = div_u64((u64)s6e88a0_ams452ef01_vt_coeff[vt_idx] << S6E88A0_SHIFT, 860);
+		dim->vt[ch] = vreg - (u32)(((u64)vreg * ratio) >> S6E88A0_SHIFT);
+
+		/* V203 down to V11 are relative to VT and the point above */
+		for (p = POINT_V255 - 1, g = 0; p >= POINT_V11; p--, g++) {
+			s32 mtp_reg = dim->mtp[g][ch] + ref[6 + 3 * g + ch];
+
+			point[p] = s6e88a0_ams452ef01_point_volt(dim->vt[ch], point[p + 1],
+								 mtp_reg, 64);
+		}
+
+		/* V3 is relative to VREG0 and V11 */
+		point[POINT_V3] = s6e88a0_ams452ef01_point_volt(vreg, point[POINT_V11],
+								dim->mtp[7][ch] + ref[27 + ch], 64);
+
+		/* Interpolate the gray levels between the points */
+		for (p = 0; p < NUM_POINTS; p++)
+			dim->gray[ch][s6e88a0_ams452ef01_point_gray[p]] = point[p];
+
+		for (p = POINT_V0; p < POINT_V255; p++) {
+			int lo = s6e88a0_ams452ef01_point_gray[p];
+			int hi, span;
+
+			if (p == POINT_V1)
+				continue;	/* V0-V3 is a single segment */
+			hi = s6e88a0_ams452ef01_point_gray[p == POINT_V0 ? POINT_V3 : p + 1];
+			span = hi - lo;
+
+			for (g = lo + 1; g < hi; g++) {
+				u64 v = (u64)(s64)(dim->gray[ch][lo] - dim->gray[ch][hi]) *
+					(span - (g - lo)) << S6E88A0_SHIFT;
+
+				dim->gray[ch][g] = dim->gray[ch][hi] +
+					(u32)(div_u64(v, span) >> S6E88A0_SHIFT);
+			}
+		}
+	}
+}
+
+/* Gray level whose luminance on the 360 cd/m2 2.2 gamma curve is closest */
+static int s6e88a0_ams452ef01_find_gray(s64 lum)
+{
+	int g;
+
+	for (g = 0; g < 255; g++) {
+		s64 d1 = lum - s6e88a0_ams452ef01_curve_2p2_360[g];
+		s64 d2 = lum - s6e88a0_ams452ef01_curve_2p2_360[g + 1];
+
+		if (d2 < 0)
+			return d1 + d2 <= 0 ? g : g + 1;
+		if (d1 == 0)
+			return g;
+		if (d2 == 0)
+			return g + 1;
+	}
+
+	return 255;
+}
+
+/* Register value of a gamma point from the voltages of its gray levels */
+static u8 s6e88a0_ams452ef01_point_reg(s32 top, s32 volt, s32 above, u32 coeff)
+{
+	u64 v;
+
+	if (top <= above || top <= volt)
+		return 0;
+
+	v = (u64)(s64)(top - volt) * (coeff * 5);
+
+	return (div_u64(v, (u32)(u64)(s64)(top - above)) - coeff) & 0xff;
+}
+
+static void s6e88a0_ams452ef01_gen_level(const struct s6e88a0_ams452ef01_dimming *dim,
+					 int level, u8 *out)
+{
+	const u16 *base = dim->rev_a ? s6e88a0_ams452ef01_base_luminance_reva :
+				       s6e88a0_ams452ef01_base_luminance_revc;
+	const s8 *grad = dim->rev_a ? s6e88a0_ams452ef01_gradation_offset_reva[level] :
+				      s6e88a0_ams452ef01_gradation_offset_revc[level];
+	const s8 *rgb = dim->rev_a ? s6e88a0_ams452ef01_rgb_offset_reva[level] :
+				     s6e88a0_ams452ef01_rgb_offset_revc[level];
+	int gray[NUM_POINTS];
+	int reg[S6E88A0_GAMMA_LEN];
+	int ch, p, k;
+
+	/* Target gray level of each point (V1 to V255) for this luminance */
+	for (p = POINT_V1; p < NUM_POINTS; p++) {
+		u8 point_gray = s6e88a0_ams452ef01_point_gray[p];
+		s64 lum = (s64)s6e88a0_ams452ef01_coeff_2p15[point_gray] * base[level];
+
+		gray[p] = s6e88a0_ams452ef01_find_gray(lum);
+	}
+	for (p = POINT_V255, k = 0; p > POINT_V1; p--, k++)
+		gray[p] = clamp(gray[p] + grad[k], 1, 255);
+
+	for (ch = 0; ch < 3; ch++) {
+		const s32 *v = dim->gray[ch];
+		u64 v255 = div_u64((u64)(s64)(dim->vreg - v[gray[POINT_V255]]) * 860,
+				   dim->vreg) - 72;
+
+		/* V255 is 9 bits wide, the others are 8 bits */
+		reg[2 * ch] = (v255 >> 8) & 0xff;
+		reg[2 * ch + 1] = v255 & 0xff;
+		for (p = POINT_V255 - 1, k = 0; p >= POINT_V11; p--, k++)
+			reg[6 + 3 * k + ch] =
+				s6e88a0_ams452ef01_point_reg(dim->vt[ch], v[gray[p]],
+							     v[gray[p + 1]], 64);
+		reg[27 + ch] = s6e88a0_ams452ef01_point_reg(dim->vreg, v[gray[POINT_V3]],
+							    v[gray[POINT_V11]], 64);
+		reg[30 + ch] = s6e88a0_ams452ef01_gamma_max[30 + ch];
+	}
+
+	/* Per level colour correction */
+	for (ch = 0; ch < 3; ch++) {
+		int v255 = (reg[2 * ch] << 8 | reg[2 * ch + 1]) + rgb[ch];
+
+		reg[2 * ch] = (v255 / 256) & 0xff;
+		reg[2 * ch + 1] = v255 & 0xff;
+	}
+	for (k = 3; k < 24; k++)
+		reg[k + 3] += rgb[k];
+
+	/* The panel adds its MTP offsets back */
+	for (ch = 0; ch < 3; ch++) {
+		int v255 = (reg[2 * ch] << 8 | reg[2 * ch + 1]) - dim->mtp_v255[ch];
+
+		reg[2 * ch] = (v255 / 256) & 0xff;
+		reg[2 * ch + 1] = v255 & 0xff;
+		for (k = 0; k < 8; k++)
+			reg[6 + 3 * k + ch] = clamp(reg[6 + 3 * k + ch] - dim->mtp[k][ch], 0, 255);
+	}
+
+	for (k = 0; k < S6E88A0_GAMMA_LEN; k++)
+		out[k] = reg[k];
+}
+
+/*
+ * Generate the gamma of every brightness level from the panel calibration
+ * (MTP), like the vendor "smart dimming": the AOR table gives the luminance,
+ * this keeps the 2.2 gamma curve and the white point at each level.
+ */
+static void s6e88a0_ams452ef01_gen_gamma(struct s6e88a0_ams452ef01_dimming *dim,
+					 const u8 *mtp, u8 id3,
+					 u8 (*gamma)[S6E88A0_GAMMA_LEN])
+{
+	int level;
+
+	dim->rev_a = id3 == 0x00;
+	dim->vreg = dim->rev_a ? S6E88A0_VREG_REV_A : S6E88A0_VREG_REV_C;
+	s6e88a0_ams452ef01_parse_mtp(dim, mtp);
+	s6e88a0_ams452ef01_gen_gray(dim);
+
+	for (level = 0; level < S6E88A0_NUM_LEVELS - 1; level++)
+		s6e88a0_ams452ef01_gen_level(dim, level, gamma[level]);
+	/* The top level is the reference itself */
+	memcpy(gamma[S6E88A0_NUM_LEVELS - 1], s6e88a0_ams452ef01_gamma_max,
+	       S6E88A0_GAMMA_LEN);
+}
+
 struct s6e88a0_ams452ef01 {
 	struct drm_panel panel;
 	struct mipi_dsi_device *dsi;
 	struct regulator_bulk_data supplies[2];
 	struct gpio_desc *reset_gpio;
+	bool gamma_ready;
+	int level;	/* brightness level last written, -1 for none */
+	u8 gamma[S6E88A0_NUM_LEVELS][S6E88A0_GAMMA_LEN];
 };
 
 static inline struct
@@ -86,9 +776,48 @@ static void s6e88a0_ams452ef01_off(struct s6e88a0_ams452ef01 *ctx)
 	mipi_dsi_msleep(&dsi_ctx, 120);
 }
 
+/* Read the panel revision and calibration, then generate the gamma tables */
+static int s6e88a0_ams452ef01_init_dimming(struct s6e88a0_ams452ef01 *ctx)
+{
+	struct mipi_dsi_device *dsi = ctx->dsi;
+	struct mipi_dsi_multi_context dsi_ctx = { .dsi = dsi };
+	struct s6e88a0_ams452ef01_dimming *dim;
+	u8 mtp[S6E88A0_GAMMA_LEN];
+	u8 id3;
+	int ret;
+
+	samsung_dsi_test_key_on_lvl2(&dsi_ctx);
+	if (dsi_ctx.accum_err)
+		return dsi_ctx.accum_err;
+
+	/* Short reads are checked too, a partial MTP would give a wrong gamma */
+	ret = mipi_dsi_dcs_read(dsi, 0xdc, &id3, sizeof(id3));
+	if (ret == sizeof(id3))
+		ret = mipi_dsi_dcs_read(dsi, 0xc8, mtp, sizeof(mtp));
+
+	samsung_dsi_test_key_off_lvl2(&dsi_ctx);
+
+	if (ret < 0)
+		return ret;
+	if (ret != sizeof(mtp))
+		return -EIO;
+
+	dim = kzalloc_obj(*dim);
+	if (!dim)
+		return -ENOMEM;
+
+	s6e88a0_ams452ef01_gen_gamma(dim, mtp, id3, ctx->gamma);
+	kfree(dim);
+
+	dev_dbg(&dsi->dev, "ID3 %#04x, MTP %*ph\n", id3, (int)sizeof(mtp), mtp);
+
+	return 0;
+}
+
 static int s6e88a0_ams452ef01_prepare(struct drm_panel *panel)
 {
 	struct s6e88a0_ams452ef01 *ctx = to_s6e88a0_ams452ef01(panel);
+	struct device *dev = &ctx->dsi->dev;
 	int ret;
 
 	ret = regulator_bulk_enable(ARRAY_SIZE(ctx->supplies), ctx->supplies);
@@ -104,6 +833,17 @@ static int s6e88a0_ams452ef01_prepare(struct drm_panel *panel)
 				       ctx->supplies);
 		return ret;
 	}
+	ctx->level = -1;	/* on() set the default gamma */
+
+	/* The calibration does not change, read it on the first power on */
+	if (!ctx->gamma_ready) {
+		ret = s6e88a0_ams452ef01_init_dimming(ctx);
+		if (ret < 0)
+			dev_warn(dev, "Failed to read calibration, keeping a fixed gamma: %d\n",
+				 ret);
+		else
+			ctx->gamma_ready = true;
+	}
 
 	return 0;
 }
@@ -173,6 +913,70 @@ static const struct drm_panel_funcs s6e88a0_ams452ef01_panel_funcs = {
 	.get_modes = s6e88a0_ams452ef01_get_modes,
 };
 
+static int s6e88a0_ams452ef01_bl_update_status(struct backlight_device *bl)
+{
+	static const u8 key_on[] = { 0xf0, 0x5a, 0x5a };
+	static const u8 update[] = { 0xf7, 0x03 };
+	static const u8 key_off[] = { 0xf0, 0xa5, 0xa5 };
+	struct s6e88a0_ams452ef01 *ctx = bl_get_data(bl);
+	struct mipi_dsi_device *dsi = ctx->dsi;
+	int brightness = backlight_get_brightness(bl);
+	int level, ret;
+	u16 aor;
+	u8 b2[6];
+	u8 b6[3];
+	u8 ca[1 + S6E88A0_GAMMA_LEN];
+	const struct mipi_dsi_dcs_cmd cmds[] = {
+		{ key_on, sizeof(key_on) },
+		{ b2, sizeof(b2) },
+		{ b6, sizeof(b6) },
+		{ ca, sizeof(ca) },
+		{ update, sizeof(update) },
+		{ key_off, sizeof(key_off) },
+	};
+
+	/*
+	 * drm_panel_enable() applies the brightness when the panel turns on,
+	 * nothing to do while it is off or turning off.
+	 */
+	if (!ctx->panel.enabled || backlight_is_blank(bl))
+		return 0;
+
+	for (level = 0; level < S6E88A0_NUM_LEVELS - 1; level++)
+		if (brightness <= s6e88a0_ams452ef01_brightness_max[level])
+			break;
+	if (level == ctx->level)
+		return 0;
+
+	aor = s6e88a0_ams452ef01_aor[level];
+	b2[0] = 0xb2;
+	b2[1] = 0x40;
+	b2[2] = 0x0a;
+	b2[3] = 0x17;
+	b2[4] = aor >> 8;
+	b2[5] = aor & 0xff;
+	b6[0] = 0xb6;
+	b6[1] = 0x2c;
+	b6[2] = s6e88a0_ams452ef01_elvss[level];
+	ca[0] = 0xca;
+	memcpy(&ca[1], ctx->gamma_ready ? ctx->gamma[level] :
+		       s6e88a0_ams452ef01_gamma_max, S6E88A0_GAMMA_LEN);
+
+	/* Low power transfers would disturb the video stream */
+	dsi->mode_flags &= ~MIPI_DSI_MODE_LPM;
+	ret = mipi_dsi_dcs_write_batch(dsi, cmds, ARRAY_SIZE(cmds));
+	dsi->mode_flags |= MIPI_DSI_MODE_LPM;
+
+	if (!ret)
+		ctx->level = level;
+
+	return ret;
+}
+
+static const struct backlight_ops s6e88a0_ams452ef01_bl_ops = {
+	.update_status = s6e88a0_ams452ef01_bl_update_status,
+};
+
 static int s6e88a0_ams452ef01_probe(struct mipi_dsi_device *dsi)
 {
 	struct device *dev = &dsi->dev;
@@ -209,6 +1013,18 @@ static int s6e88a0_ams452ef01_probe(struct mipi_dsi_device *dsi)
 	dsi->mode_flags = MIPI_DSI_MODE_VIDEO | MIPI_DSI_MODE_VIDEO_BURST;
 	ctx->panel.prepare_prev_first = true;
 
+	ctx->panel.backlight =
+		devm_backlight_device_register(dev, dev_name(dev), dev, ctx,
+					       &s6e88a0_ams452ef01_bl_ops,
+					       &(const struct backlight_properties) {
+						       .type = BACKLIGHT_RAW,
+						       .brightness = 255,
+						       .max_brightness = 255,
+					       });
+	if (IS_ERR(ctx->panel.backlight))
+		return dev_err_probe(dev, PTR_ERR(ctx->panel.backlight),
+				     "Failed to register backlight\n");
+
 	ret = devm_drm_panel_add(dev, &ctx->panel);
 	if (ret)
 		return ret;
-- 
2.43.0


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

end of thread, other threads:[~2026-11-29 13:00 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 ` [PATCH 1/5] drm/mipi-dsi: add multi-message batch transfer support Vladimir Bely
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

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®