mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [RFT PATCH v2 0/2] drm/panel: sitronix-st7789v: Convert to mipi_dbi
@ 2026-02-17  9:27 Chen-Yu Tsai
  2026-02-17  9:27 ` [RFT PATCH v2 1/2] drm/mipi-dbi: Provide option to invert reset GPIO logic Chen-Yu Tsai
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Chen-Yu Tsai @ 2026-02-17  9:27 UTC (permalink / raw)
  To: Neil Armstrong, Jessica Zhang, Maarten Lankhorst, Maxime Ripard,
	Thomas Zimmermann
  Cc: Sebastian Reichel, Gerald Loacker, Michael Riesch, Miquel Raynal,
	Chen-Yu Tsai, David Airlie, Simona Vetter, Archit Anant,
	dri-devel, linux-kernel

Hi folks,

This small series converts the st7789v panel to use the mipi-dbi helpers
for register access.

Originally I intended to also add tinydrm support. My purpose was just
to test a TFT module that is on the Avaota A1 board. Archit is interested
in working on this driver, and I already used his/her previous patch to
check that my TFT was sort of working, albeit probably with the wrong
internal parameters. So this series will serve as a base for that work.

Patch 1 adds an option to invert the reset GPIO logic in the mipi-dbi
helpers. The reset logic originally assumes "high" is out of reset,
so an "enable" GPIO rather than a "reset" GPIO. However the st7789v
drivers assumes the proper "reset" GPIO logic.

Patch 2 converts all SPI register accesses in the st7789v to use the
mipi_dbi helpers. This actually reduces the number of function calls,
as the command and data portions of each message are combined. This
conversion also lets the driver support 8-bit plus D/C GPIO transfers.


This series is unfortunately only compile tested, as I do not have an
st7789v panel that is wired up for RGB input. So please help test the
changes.


Thanks
ChenYu

Changes since v1:
- Fix compile error from half changed reset GPIO handling 

Chen-Yu Tsai (2):
  drm/mipi-dbi: Provide option to invert reset GPIO logic
  drm/panel: sitronix-st7789v: Convert to mipi_dbi

 drivers/gpu/drm/drm_mipi_dbi.c                |   4 +-
 drivers/gpu/drm/panel/Kconfig                 |   1 +
 .../gpu/drm/panel/panel-sitronix-st7789v.c    | 306 +++++++-----------
 include/drm/drm_mipi_dbi.h                    |   9 +
 4 files changed, 121 insertions(+), 199 deletions(-)

-- 
2.47.3


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

* [RFT PATCH v2 1/2] drm/mipi-dbi: Provide option to invert reset GPIO logic
  2026-02-17  9:27 [RFT PATCH v2 0/2] drm/panel: sitronix-st7789v: Convert to mipi_dbi Chen-Yu Tsai
@ 2026-02-17  9:27 ` Chen-Yu Tsai
  2026-02-17  9:27 ` [RFT PATCH v2 2/2] drm/panel: sitronix-st7789v: Convert to mipi_dbi Chen-Yu Tsai
  2026-02-18  6:37 ` [RFT PATCH v2 0/2] " Archit Anant
  2 siblings, 0 replies; 4+ messages in thread
From: Chen-Yu Tsai @ 2026-02-17  9:27 UTC (permalink / raw)
  To: Neil Armstrong, Jessica Zhang, Maarten Lankhorst, Maxime Ripard,
	Thomas Zimmermann
  Cc: Sebastian Reichel, Gerald Loacker, Michael Riesch, Miquel Raynal,
	Chen-Yu Tsai, David Airlie, Simona Vetter, Archit Anant,
	dri-devel, linux-kernel

When mipi_dbi (tinydrm) was added, the reset handling assumed that
"logic high" or "active" was out of reset, while "logic low" or
"inactive" was in reset. This is the opposite of how many reset
bindings are written, wherein "active" means the reset is active, i.e
the device is put or held in reset.

Provide an option to invert the logic so that drivers for bindings with
"active is in reset" using mipi_dbi can use the common reset handling.

Signed-off-by: Chen-Yu Tsai <wens@kernel.org>
---
 drivers/gpu/drm/drm_mipi_dbi.c | 4 ++--
 include/drm/drm_mipi_dbi.h     | 9 +++++++++
 2 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/drm_mipi_dbi.c b/drivers/gpu/drm/drm_mipi_dbi.c
index 00482227a9cd..7fa1f73a38a4 100644
--- a/drivers/gpu/drm/drm_mipi_dbi.c
+++ b/drivers/gpu/drm/drm_mipi_dbi.c
@@ -713,9 +713,9 @@ void mipi_dbi_hw_reset(struct mipi_dbi *dbi)
 	if (!dbi->reset)
 		return;
 
-	gpiod_set_value_cansleep(dbi->reset, 0);
+	gpiod_set_value_cansleep(dbi->reset, dbi->invert_reset ? 1 : 0);
 	usleep_range(20, 1000);
-	gpiod_set_value_cansleep(dbi->reset, 1);
+	gpiod_set_value_cansleep(dbi->reset, dbi->invert_reset ? 0 : 1);
 	msleep(120);
 }
 EXPORT_SYMBOL(mipi_dbi_hw_reset);
diff --git a/include/drm/drm_mipi_dbi.h b/include/drm/drm_mipi_dbi.h
index f45f9612c0bc..6cebf74bcecc 100644
--- a/include/drm/drm_mipi_dbi.h
+++ b/include/drm/drm_mipi_dbi.h
@@ -44,6 +44,15 @@ struct mipi_dbi {
 	 */
 	bool swap_bytes;
 
+	/**
+	 * @invert_reset: Invert reset logic level.
+	 *
+	 * This is needed as drm_mipi_dbi (formerly tinydrm) introduced reset
+	 * GPIO controls with "logic high" being "out of reset", while other
+	 * bindings typically have "logic high" as "in reset".
+	 */
+	bool invert_reset;
+
 	/**
 	 * @reset: Optional reset gpio
 	 */
-- 
2.47.3


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

* [RFT PATCH v2 2/2] drm/panel: sitronix-st7789v: Convert to mipi_dbi
  2026-02-17  9:27 [RFT PATCH v2 0/2] drm/panel: sitronix-st7789v: Convert to mipi_dbi Chen-Yu Tsai
  2026-02-17  9:27 ` [RFT PATCH v2 1/2] drm/mipi-dbi: Provide option to invert reset GPIO logic Chen-Yu Tsai
@ 2026-02-17  9:27 ` Chen-Yu Tsai
  2026-02-18  6:37 ` [RFT PATCH v2 0/2] " Archit Anant
  2 siblings, 0 replies; 4+ messages in thread
From: Chen-Yu Tsai @ 2026-02-17  9:27 UTC (permalink / raw)
  To: Neil Armstrong, Jessica Zhang, Maarten Lankhorst, Maxime Ripard,
	Thomas Zimmermann
  Cc: Sebastian Reichel, Gerald Loacker, Michael Riesch, Miquel Raynal,
	Chen-Yu Tsai, David Airlie, Simona Vetter, Archit Anant,
	dri-devel, linux-kernel

The wire protocol of the ST7789V is basically MIPI DBI. Switch to the
mipi_dbi helpers to reduce some code. This also ends up adding support
for 8-bit D/C mode. The reset logic in the mipi_dbi helpers is also
used.

While at it, also clean up st7789v_check_id() to use ST7789V_IDS_SIZE
to declare the ids array size and sizeof(ids) where the size is
needed.

Signed-off-by: Chen-Yu Tsai <wens@kernel.org>
---
Changes since v1:
- Fix compile error from half changed reset GPIO handling
---
 drivers/gpu/drm/panel/Kconfig                 |   1 +
 .../gpu/drm/panel/panel-sitronix-st7789v.c    | 306 +++++++-----------
 2 files changed, 110 insertions(+), 197 deletions(-)

diff --git a/drivers/gpu/drm/panel/Kconfig b/drivers/gpu/drm/panel/Kconfig
index 307152ad7759..64325874d3e2 100644
--- a/drivers/gpu/drm/panel/Kconfig
+++ b/drivers/gpu/drm/panel/Kconfig
@@ -1011,6 +1011,7 @@ config DRM_PANEL_SITRONIX_ST7789V
 	tristate "Sitronix ST7789V panel"
 	depends on OF && SPI
 	depends on BACKLIGHT_CLASS_DEVICE
+	select DRM_MIPI_DBI
 	help
 	  Say Y here if you want to enable support for the Sitronix
 	  ST7789V controller for 240x320 LCD panels
diff --git a/drivers/gpu/drm/panel/panel-sitronix-st7789v.c b/drivers/gpu/drm/panel/panel-sitronix-st7789v.c
index d5f821d6b23c..b77e616f2994 100644
--- a/drivers/gpu/drm/panel/panel-sitronix-st7789v.c
+++ b/drivers/gpu/drm/panel/panel-sitronix-st7789v.c
@@ -14,6 +14,7 @@
 
 #include <drm/drm_device.h>
 #include <drm/drm_modes.h>
+#include <drm/drm_mipi_dbi.h>
 #include <drm/drm_panel.h>
 
 #define ST7789V_RAMCTRL_CMD		0xb0
@@ -125,9 +126,9 @@ struct st7789_panel_info {
 
 struct st7789v {
 	struct drm_panel panel;
+	struct mipi_dbi dbi;
 	const struct st7789_panel_info *info;
 	struct spi_device *spi;
-	struct gpio_desc *reset;
 	struct regulator *power;
 	enum drm_panel_orientation orientation;
 };
@@ -142,86 +143,23 @@ static inline struct st7789v *panel_to_st7789v(struct drm_panel *panel)
 	return container_of(panel, struct st7789v, panel);
 }
 
-static int st7789v_spi_write(struct st7789v *ctx, enum st7789v_prefix prefix,
-			     u8 data)
-{
-	struct spi_transfer xfer = { };
-	u16 txbuf = ((prefix & 1) << 8) | data;
-
-	xfer.tx_buf = &txbuf;
-	xfer.len = sizeof(txbuf);
-
-	return spi_sync_transfer(ctx->spi, &xfer, 1);
-}
-
-static int st7789v_write_command(struct st7789v *ctx, u8 cmd)
-{
-	return st7789v_spi_write(ctx, ST7789V_COMMAND, cmd);
-}
-
-static int st7789v_write_data(struct st7789v *ctx, u8 cmd)
-{
-	return st7789v_spi_write(ctx, ST7789V_DATA, cmd);
-}
-
-static int st7789v_read_data(struct st7789v *ctx, u8 cmd, u8 *buf,
-			     unsigned int len)
-{
-	struct spi_transfer xfer[2] = { };
-	struct spi_message msg;
-	u16 txbuf = ((ST7789V_COMMAND & 1) << 8) | cmd;
-	u16 rxbuf[4] = {};
-	u8 bit9 = 0;
-	int ret, i;
-
-	switch (len) {
-	case 1:
-	case 3:
-	case 4:
-		break;
-	default:
-		return -EOPNOTSUPP;
-	}
-
-	spi_message_init(&msg);
-
-	xfer[0].tx_buf = &txbuf;
-	xfer[0].len = sizeof(txbuf);
-	spi_message_add_tail(&xfer[0], &msg);
-
-	xfer[1].rx_buf = rxbuf;
-	xfer[1].len = len * 2;
-	spi_message_add_tail(&xfer[1], &msg);
-
-	ret = spi_sync(ctx->spi, &msg);
-	if (ret)
-		return ret;
-
-	for (i = 0; i < len; i++) {
-		buf[i] = rxbuf[i] >> i | (bit9 << (9 - i));
-		if (i)
-			bit9 = rxbuf[i] & GENMASK(i - 1, 0);
-	}
-
-	return 0;
-}
-
 static int st7789v_check_id(struct drm_panel *panel)
 {
 	const u8 st7789v_ids[ST7789V_IDS_SIZE] = ST7789V_IDS;
 	struct st7789v *ctx = panel_to_st7789v(panel);
 	bool invalid_ids = false;
 	int ret, i;
-	u8 ids[3];
+	u8 ids[ST7789V_IDS_SIZE];
 
 	if (ctx->spi->mode & SPI_NO_RX)
 		return 0;
 
-	ret = st7789v_read_data(ctx, MIPI_DCS_GET_DISPLAY_ID, ids, ST7789V_IDS_SIZE);
+	ret = mipi_dbi_command_stackbuf(&ctx->dbi, MIPI_DCS_GET_DISPLAY_ID,
+					ids, sizeof(ids));
 	if (ret)
 		return ret;
 
-	for (i = 0; i < ST7789V_IDS_SIZE; i++) {
+	for (i = 0; i < sizeof(ids); i++) {
 		if (ids[i] != st7789v_ids[i]) {
 			invalid_ids = true;
 			break;
@@ -379,6 +317,7 @@ static enum drm_panel_orientation st7789v_get_orientation(struct drm_panel *p)
 static int st7789v_prepare(struct drm_panel *panel)
 {
 	struct st7789v *ctx = panel_to_st7789v(panel);
+	struct mipi_dbi *dbi = &ctx->dbi;
 	u8 mode, pixel_fmt, polarity;
 	int ret;
 
@@ -416,10 +355,7 @@ static int st7789v_prepare(struct drm_panel *panel)
 	if (ret)
 		return ret;
 
-	gpiod_set_value(ctx->reset, 1);
-	msleep(30);
-	gpiod_set_value(ctx->reset, 0);
-	msleep(120);
+	mipi_dbi_hw_reset(&ctx->dbi);
 
 	/*
 	 * Avoid failing if the IDs are invalid in case the Rx bus width
@@ -429,101 +365,81 @@ static int st7789v_prepare(struct drm_panel *panel)
 	if (ret)
 		dev_warn(panel->dev, "Unrecognized panel IDs");
 
-	ST7789V_TEST(ret, st7789v_write_command(ctx, MIPI_DCS_EXIT_SLEEP_MODE));
+	ST7789V_TEST(ret, mipi_dbi_command(dbi, MIPI_DCS_EXIT_SLEEP_MODE));
 
 	/* We need to wait 120ms after a sleep out command */
 	msleep(120);
 
-	ST7789V_TEST(ret, st7789v_write_command(ctx,
-						MIPI_DCS_SET_ADDRESS_MODE));
-	ST7789V_TEST(ret, st7789v_write_data(ctx, 0));
-
-	ST7789V_TEST(ret, st7789v_write_command(ctx,
-						MIPI_DCS_SET_PIXEL_FORMAT));
-	ST7789V_TEST(ret, st7789v_write_data(ctx, pixel_fmt));
-
-	ST7789V_TEST(ret, st7789v_write_command(ctx, ST7789V_PORCTRL_CMD));
-	ST7789V_TEST(ret, st7789v_write_data(ctx, 0xc));
-	ST7789V_TEST(ret, st7789v_write_data(ctx, 0xc));
-	ST7789V_TEST(ret, st7789v_write_data(ctx, 0));
-	ST7789V_TEST(ret, st7789v_write_data(ctx, ST7789V_PORCTRL_IDLE_BP(3) |
-					     ST7789V_PORCTRL_IDLE_FP(3)));
-	ST7789V_TEST(ret, st7789v_write_data(ctx,
-					     ST7789V_PORCTRL_PARTIAL_BP(3) |
-					     ST7789V_PORCTRL_PARTIAL_FP(3)));
-
-	ST7789V_TEST(ret, st7789v_write_command(ctx, ST7789V_GCTRL_CMD));
-	ST7789V_TEST(ret, st7789v_write_data(ctx, ST7789V_GCTRL_VGLS(5) |
-					     ST7789V_GCTRL_VGHS(3)));
-
-	ST7789V_TEST(ret, st7789v_write_command(ctx, ST7789V_VCOMS_CMD));
-	ST7789V_TEST(ret, st7789v_write_data(ctx, 0x2b));
-
-	ST7789V_TEST(ret, st7789v_write_command(ctx, ST7789V_LCMCTRL_CMD));
-	ST7789V_TEST(ret, st7789v_write_data(ctx, ST7789V_LCMCTRL_XMH |
-					     ST7789V_LCMCTRL_XMX |
-					     ST7789V_LCMCTRL_XBGR));
-
-	ST7789V_TEST(ret, st7789v_write_command(ctx, ST7789V_VDVVRHEN_CMD));
-	ST7789V_TEST(ret, st7789v_write_data(ctx, ST7789V_VDVVRHEN_CMDEN));
-
-	ST7789V_TEST(ret, st7789v_write_command(ctx, ST7789V_VRHS_CMD));
-	ST7789V_TEST(ret, st7789v_write_data(ctx, 0xf));
-
-	ST7789V_TEST(ret, st7789v_write_command(ctx, ST7789V_VDVS_CMD));
-	ST7789V_TEST(ret, st7789v_write_data(ctx, 0x20));
-
-	ST7789V_TEST(ret, st7789v_write_command(ctx, ST7789V_FRCTRL2_CMD));
-	ST7789V_TEST(ret, st7789v_write_data(ctx, 0xf));
-
-	ST7789V_TEST(ret, st7789v_write_command(ctx, ST7789V_PWCTRL1_CMD));
-	ST7789V_TEST(ret, st7789v_write_data(ctx, ST7789V_PWCTRL1_MAGIC));
-	ST7789V_TEST(ret, st7789v_write_data(ctx, ST7789V_PWCTRL1_AVDD(2) |
-					     ST7789V_PWCTRL1_AVCL(2) |
-					     ST7789V_PWCTRL1_VDS(1)));
-
-	ST7789V_TEST(ret, st7789v_write_command(ctx, ST7789V_PVGAMCTRL_CMD));
-	ST7789V_TEST(ret, st7789v_write_data(ctx, ST7789V_PVGAMCTRL_VP63(0xd)));
-	ST7789V_TEST(ret, st7789v_write_data(ctx, ST7789V_PVGAMCTRL_VP1(0xca)));
-	ST7789V_TEST(ret, st7789v_write_data(ctx, ST7789V_PVGAMCTRL_VP2(0xe)));
-	ST7789V_TEST(ret, st7789v_write_data(ctx, ST7789V_PVGAMCTRL_VP4(8)));
-	ST7789V_TEST(ret, st7789v_write_data(ctx, ST7789V_PVGAMCTRL_VP6(9)));
-	ST7789V_TEST(ret, st7789v_write_data(ctx, ST7789V_PVGAMCTRL_VP13(7)));
-	ST7789V_TEST(ret, st7789v_write_data(ctx, ST7789V_PVGAMCTRL_VP20(0x2d)));
-	ST7789V_TEST(ret, st7789v_write_data(ctx, ST7789V_PVGAMCTRL_VP27(0xb) |
-					     ST7789V_PVGAMCTRL_VP36(3)));
-	ST7789V_TEST(ret, st7789v_write_data(ctx, ST7789V_PVGAMCTRL_VP43(0x3d)));
-	ST7789V_TEST(ret, st7789v_write_data(ctx, ST7789V_PVGAMCTRL_JP1(3) |
-					     ST7789V_PVGAMCTRL_VP50(4)));
-	ST7789V_TEST(ret, st7789v_write_data(ctx, ST7789V_PVGAMCTRL_VP57(0xa)));
-	ST7789V_TEST(ret, st7789v_write_data(ctx, ST7789V_PVGAMCTRL_VP59(0xa)));
-	ST7789V_TEST(ret, st7789v_write_data(ctx, ST7789V_PVGAMCTRL_VP61(0x1b)));
-	ST7789V_TEST(ret, st7789v_write_data(ctx, ST7789V_PVGAMCTRL_VP62(0x28)));
-
-	ST7789V_TEST(ret, st7789v_write_command(ctx, ST7789V_NVGAMCTRL_CMD));
-	ST7789V_TEST(ret, st7789v_write_data(ctx, ST7789V_NVGAMCTRL_VN63(0xd)));
-	ST7789V_TEST(ret, st7789v_write_data(ctx, ST7789V_NVGAMCTRL_VN1(0xca)));
-	ST7789V_TEST(ret, st7789v_write_data(ctx, ST7789V_NVGAMCTRL_VN2(0xf)));
-	ST7789V_TEST(ret, st7789v_write_data(ctx, ST7789V_NVGAMCTRL_VN4(8)));
-	ST7789V_TEST(ret, st7789v_write_data(ctx, ST7789V_NVGAMCTRL_VN6(8)));
-	ST7789V_TEST(ret, st7789v_write_data(ctx, ST7789V_NVGAMCTRL_VN13(7)));
-	ST7789V_TEST(ret, st7789v_write_data(ctx, ST7789V_NVGAMCTRL_VN20(0x2e)));
-	ST7789V_TEST(ret, st7789v_write_data(ctx, ST7789V_NVGAMCTRL_VN27(0xc) |
-					     ST7789V_NVGAMCTRL_VN36(5)));
-	ST7789V_TEST(ret, st7789v_write_data(ctx, ST7789V_NVGAMCTRL_VN43(0x40)));
-	ST7789V_TEST(ret, st7789v_write_data(ctx, ST7789V_NVGAMCTRL_JN1(3) |
-					     ST7789V_NVGAMCTRL_VN50(4)));
-	ST7789V_TEST(ret, st7789v_write_data(ctx, ST7789V_NVGAMCTRL_VN57(9)));
-	ST7789V_TEST(ret, st7789v_write_data(ctx, ST7789V_NVGAMCTRL_VN59(0xb)));
-	ST7789V_TEST(ret, st7789v_write_data(ctx, ST7789V_NVGAMCTRL_VN61(0x1b)));
-	ST7789V_TEST(ret, st7789v_write_data(ctx, ST7789V_NVGAMCTRL_VN62(0x28)));
+	ST7789V_TEST(ret, mipi_dbi_command(dbi, MIPI_DCS_SET_ADDRESS_MODE, 0));
+	ST7789V_TEST(ret, mipi_dbi_command(dbi, MIPI_DCS_SET_PIXEL_FORMAT, pixel_fmt));
+	ST7789V_TEST(ret, mipi_dbi_command(dbi, ST7789V_PORCTRL_CMD, 0xc, 0xc, 0,
+					   ST7789V_PORCTRL_IDLE_BP(3) |
+					   ST7789V_PORCTRL_IDLE_FP(3),
+					   ST7789V_PORCTRL_PARTIAL_BP(3) |
+					   ST7789V_PORCTRL_PARTIAL_FP(3)));
+
+	ST7789V_TEST(ret, mipi_dbi_command(dbi, ST7789V_GCTRL_CMD,
+					   ST7789V_GCTRL_VGLS(5) |
+					   ST7789V_GCTRL_VGHS(3)));
+	ST7789V_TEST(ret, mipi_dbi_command(dbi, ST7789V_VCOMS_CMD, 0x2b));
+
+	ST7789V_TEST(ret, mipi_dbi_command(dbi, ST7789V_LCMCTRL_CMD,
+					   ST7789V_LCMCTRL_XMH |
+					   ST7789V_LCMCTRL_XMX |
+					   ST7789V_LCMCTRL_XBGR));
+
+	ST7789V_TEST(ret, mipi_dbi_command(dbi, ST7789V_VDVVRHEN_CMD,
+					   ST7789V_VDVVRHEN_CMDEN));
+
+	ST7789V_TEST(ret, mipi_dbi_command(dbi, ST7789V_VRHS_CMD, 0xf));
+	ST7789V_TEST(ret, mipi_dbi_command(dbi, ST7789V_VDVS_CMD, 0x20));
+	ST7789V_TEST(ret, mipi_dbi_command(dbi, ST7789V_FRCTRL2_CMD, 0xf));
+	ST7789V_TEST(ret, mipi_dbi_command(dbi, ST7789V_PWCTRL1_CMD,
+					   ST7789V_PWCTRL1_MAGIC,
+					   ST7789V_PWCTRL1_AVDD(2) |
+					   ST7789V_PWCTRL1_AVCL(2) |
+					   ST7789V_PWCTRL1_VDS(1)));
+
+	ST7789V_TEST(ret, mipi_dbi_command(dbi, ST7789V_PVGAMCTRL_CMD,
+					   ST7789V_PVGAMCTRL_VP63(0xd),
+					   ST7789V_PVGAMCTRL_VP1(0xca),
+					   ST7789V_PVGAMCTRL_VP2(0xe),
+					   ST7789V_PVGAMCTRL_VP4(8),
+					   ST7789V_PVGAMCTRL_VP6(9),
+					   ST7789V_PVGAMCTRL_VP13(7),
+					   ST7789V_PVGAMCTRL_VP20(0x2d),
+					   ST7789V_PVGAMCTRL_VP27(0xb) |
+					   ST7789V_PVGAMCTRL_VP36(3),
+					   ST7789V_PVGAMCTRL_VP43(0x3d),
+					   ST7789V_PVGAMCTRL_JP1(3) |
+					   ST7789V_PVGAMCTRL_VP50(4),
+					   ST7789V_PVGAMCTRL_VP57(0xa),
+					   ST7789V_PVGAMCTRL_VP59(0xa),
+					   ST7789V_PVGAMCTRL_VP61(0x1b),
+					   ST7789V_PVGAMCTRL_VP62(0x28)));
+
+	ST7789V_TEST(ret, mipi_dbi_command(dbi, ST7789V_NVGAMCTRL_CMD,
+					   ST7789V_NVGAMCTRL_VN63(0xd),
+					   ST7789V_NVGAMCTRL_VN1(0xca),
+					   ST7789V_NVGAMCTRL_VN2(0xf),
+					   ST7789V_NVGAMCTRL_VN4(8),
+					   ST7789V_NVGAMCTRL_VN6(8),
+					   ST7789V_NVGAMCTRL_VN13(7),
+					   ST7789V_NVGAMCTRL_VN20(0x2e),
+					   ST7789V_NVGAMCTRL_VN27(0xc) |
+					   ST7789V_NVGAMCTRL_VN36(5),
+					   ST7789V_NVGAMCTRL_VN43(0x40),
+					   ST7789V_NVGAMCTRL_JN1(3) |
+					   ST7789V_NVGAMCTRL_VN50(4),
+					   ST7789V_NVGAMCTRL_VN57(9),
+					   ST7789V_NVGAMCTRL_VN59(0xb),
+					   ST7789V_NVGAMCTRL_VN61(0x1b),
+					   ST7789V_NVGAMCTRL_VN62(0x28)));
 
 	if (ctx->info->invert_mode) {
-		ST7789V_TEST(ret, st7789v_write_command(ctx,
-						MIPI_DCS_ENTER_INVERT_MODE));
+		ST7789V_TEST(ret, mipi_dbi_command(dbi, MIPI_DCS_ENTER_INVERT_MODE));
 	} else {
-		ST7789V_TEST(ret, st7789v_write_command(ctx,
-						MIPI_DCS_EXIT_INVERT_MODE));
+		ST7789V_TEST(ret, mipi_dbi_command(dbi,	MIPI_DCS_EXIT_INVERT_MODE));
 	}
 
 	if (ctx->info->partial_mode) {
@@ -539,36 +455,27 @@ static int st7789v_prepare(struct drm_panel *panel)
 		 * add margins.
 		 */
 
-		ST7789V_TEST(ret, st7789v_write_command(
-					  ctx, MIPI_DCS_ENTER_PARTIAL_MODE));
-
-		ST7789V_TEST(ret, st7789v_write_command(
-					  ctx, MIPI_DCS_SET_PAGE_ADDRESS));
-		ST7789V_TEST(ret, st7789v_write_data(ctx, area_data[0]));
-		ST7789V_TEST(ret, st7789v_write_data(ctx, area_data[1]));
-		ST7789V_TEST(ret, st7789v_write_data(ctx, area_data[2]));
-		ST7789V_TEST(ret, st7789v_write_data(ctx, area_data[3]));
-
-		ST7789V_TEST(ret, st7789v_write_command(
-					  ctx, MIPI_DCS_SET_PARTIAL_ROWS));
-		ST7789V_TEST(ret, st7789v_write_data(ctx, area_data[0]));
-		ST7789V_TEST(ret, st7789v_write_data(ctx, area_data[1]));
-		ST7789V_TEST(ret, st7789v_write_data(ctx, area_data[2]));
-		ST7789V_TEST(ret, st7789v_write_data(ctx, area_data[3]));
+		ST7789V_TEST(ret, mipi_dbi_command(dbi, MIPI_DCS_ENTER_PARTIAL_MODE));
+
+		ST7789V_TEST(ret, mipi_dbi_command(dbi, MIPI_DCS_SET_PAGE_ADDRESS,
+						   area_data[0], area_data[1],
+						   area_data[2], area_data[3]));
+
+		ST7789V_TEST(ret, mipi_dbi_command(dbi, MIPI_DCS_SET_PARTIAL_ROWS,
+						   area_data[0], area_data[1],
+						   area_data[2], area_data[3]));
 	}
 
-	ST7789V_TEST(ret, st7789v_write_command(ctx, ST7789V_RAMCTRL_CMD));
-	ST7789V_TEST(ret, st7789v_write_data(ctx, ST7789V_RAMCTRL_DM_RGB |
-					     ST7789V_RAMCTRL_RM_RGB));
-	ST7789V_TEST(ret, st7789v_write_data(ctx, ST7789V_RAMCTRL_EPF(3) |
-					     ST7789V_RAMCTRL_MAGIC));
+	ST7789V_TEST(ret, mipi_dbi_command(dbi, ST7789V_RAMCTRL_CMD,
+					   ST7789V_RAMCTRL_DM_RGB |
+					   ST7789V_RAMCTRL_RM_RGB,
+					   ST7789V_RAMCTRL_EPF(3) |
+					   ST7789V_RAMCTRL_MAGIC));
 
-	ST7789V_TEST(ret, st7789v_write_command(ctx, ST7789V_RGBCTRL_CMD));
-	ST7789V_TEST(ret, st7789v_write_data(ctx, mode |
-					     ST7789V_RGBCTRL_RCM(2) |
-					     polarity));
-	ST7789V_TEST(ret, st7789v_write_data(ctx, ST7789V_RGBCTRL_VBP(8)));
-	ST7789V_TEST(ret, st7789v_write_data(ctx, ST7789V_RGBCTRL_HBP(20)));
+	ST7789V_TEST(ret, mipi_dbi_command(dbi, ST7789V_RGBCTRL_CMD,
+					   mode | ST7789V_RGBCTRL_RCM(2) | polarity,
+					   ST7789V_RGBCTRL_VBP(8),
+					   ST7789V_RGBCTRL_HBP(20)));
 
 	return 0;
 }
@@ -577,7 +484,7 @@ static int st7789v_enable(struct drm_panel *panel)
 {
 	struct st7789v *ctx = panel_to_st7789v(panel);
 
-	return st7789v_write_command(ctx, MIPI_DCS_SET_DISPLAY_ON);
+	return mipi_dbi_command(&ctx->dbi, MIPI_DCS_SET_DISPLAY_ON);
 }
 
 static int st7789v_disable(struct drm_panel *panel)
@@ -585,7 +492,7 @@ static int st7789v_disable(struct drm_panel *panel)
 	struct st7789v *ctx = panel_to_st7789v(panel);
 	int ret;
 
-	ST7789V_TEST(ret, st7789v_write_command(ctx, MIPI_DCS_SET_DISPLAY_OFF));
+	ST7789V_TEST(ret, mipi_dbi_command(&ctx->dbi, MIPI_DCS_SET_DISPLAY_OFF));
 
 	return 0;
 }
@@ -595,7 +502,7 @@ static int st7789v_unprepare(struct drm_panel *panel)
 	struct st7789v *ctx = panel_to_st7789v(panel);
 	int ret;
 
-	ST7789V_TEST(ret, st7789v_write_command(ctx, MIPI_DCS_ENTER_SLEEP_MODE));
+	ST7789V_TEST(ret, mipi_dbi_command(&ctx->dbi, MIPI_DCS_ENTER_SLEEP_MODE));
 
 	regulator_disable(ctx->power);
 
@@ -615,6 +522,7 @@ static int st7789v_probe(struct spi_device *spi)
 {
 	struct device *dev = &spi->dev;
 	struct st7789v *ctx;
+	struct gpio_desc *dc;
 	int ret;
 
 	ctx = devm_drm_panel_alloc(dev, struct st7789v, panel,
@@ -625,11 +533,6 @@ static int st7789v_probe(struct spi_device *spi)
 	spi_set_drvdata(spi, ctx);
 	ctx->spi = spi;
 
-	spi->bits_per_word = 9;
-	ret = spi_setup(spi);
-	if (ret < 0)
-		return dev_err_probe(&spi->dev, ret, "Failed to setup spi\n");
-
 	ctx->info = device_get_match_data(&spi->dev);
 
 	ctx->power = devm_regulator_get(dev, "power");
@@ -637,11 +540,16 @@ static int st7789v_probe(struct spi_device *spi)
 	if (ret)
 		return dev_err_probe(dev, ret, "Failed to get regulator\n");
 
-	ctx->reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW);
-	ret = PTR_ERR_OR_ZERO(ctx->reset);
+	ctx->dbi.reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW);
+	ret = PTR_ERR_OR_ZERO(ctx->dbi.reset);
 	if (ret)
 		return dev_err_probe(dev, ret, "Failed to get reset line\n");
 
+	dc = devm_gpiod_get_optional(&spi->dev, "dc", GPIOD_OUT_LOW);
+	ret = PTR_ERR_OR_ZERO(dc);
+	if (ret)
+		return dev_err_probe(&spi->dev, ret, "Failed to get GPIO for D/C\n");
+
 	ret = drm_panel_of_backlight(&ctx->panel);
 	if (ret)
 		return dev_err_probe(dev, ret, "Failed to get backlight\n");
@@ -650,6 +558,10 @@ static int st7789v_probe(struct spi_device *spi)
 	if (ret)
 		return dev_err_probe(&spi->dev, ret, "Failed to get orientation\n");
 
+	ret = mipi_dbi_spi_init(spi, &ctx->dbi, dc);
+	if (ret)
+		return dev_err_probe(&spi->dev, ret, "Failed to init MIPI DBI\n");
+
 	drm_panel_add(&ctx->panel);
 
 	return 0;
-- 
2.47.3


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

* Re: [RFT PATCH v2 0/2] drm/panel: sitronix-st7789v: Convert to mipi_dbi
  2026-02-17  9:27 [RFT PATCH v2 0/2] drm/panel: sitronix-st7789v: Convert to mipi_dbi Chen-Yu Tsai
  2026-02-17  9:27 ` [RFT PATCH v2 1/2] drm/mipi-dbi: Provide option to invert reset GPIO logic Chen-Yu Tsai
  2026-02-17  9:27 ` [RFT PATCH v2 2/2] drm/panel: sitronix-st7789v: Convert to mipi_dbi Chen-Yu Tsai
@ 2026-02-18  6:37 ` Archit Anant
  2 siblings, 0 replies; 4+ messages in thread
From: Archit Anant @ 2026-02-18  6:37 UTC (permalink / raw)
  To: Chen-Yu Tsai
  Cc: Neil Armstrong, Jessica Zhang, Maarten Lankhorst, Maxime Ripard,
	Thomas Zimmermann, Sebastian Reichel, Gerald Loacker,
	Michael Riesch, Miquel Raynal, David Airlie, Simona Vetter,
	dri-devel, linux-kernel

On Tue, Feb 17, 2026 at 2:57 PM Chen-Yu Tsai <wens@kernel.org> wrote:
>
> Hi folks,
>
> This small series converts the st7789v panel to use the mipi-dbi helpers
> for register access.
>
> Originally I intended to also add tinydrm support. My purpose was just
> to test a TFT module that is on the Avaota A1 board. Archit is interested
> in working on this driver, and I already used his/her previous patch to
> check that my TFT was sort of working, albeit probably with the wrong
> internal parameters. So this series will serve as a base for that work.
>
> Patch 1 adds an option to invert the reset GPIO logic in the mipi-dbi
> helpers. The reset logic originally assumes "high" is out of reset,
> so an "enable" GPIO rather than a "reset" GPIO. However the st7789v
> drivers assumes the proper "reset" GPIO logic.
>
> Patch 2 converts all SPI register accesses in the st7789v to use the
> mipi_dbi helpers. This actually reduces the number of function calls,
> as the command and data portions of each message are combined. This
> conversion also lets the driver support 8-bit plus D/C GPIO transfers.
>
>
> This series is unfortunately only compile tested, as I do not have an
> st7789v panel that is wired up for RGB input. So please help test the
> changes.
>
>
> Thanks
> ChenYu
>

Hi ChenYu,

Thank you for sharing the series.

I’ll focus on completing the transition to the mipi_dbi helpers,
ensuring the reset
handling works correctly with the optional logic inversion, and updating
st7789v_check_id() to use ST7789V_IDS_SIZE and sizeof(ids) as discussed.

Although I don’t have access to the hardware, I’ll make sure the series builds
cleanly and review the changes carefully. I’ll also verify that the
8-bit SPI + D/C
GPIO configuration is handled correctly at the driver level.

--
Sincerely,
Archit Anant

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

end of thread, other threads:[~2026-02-18  6:37 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-02-17  9:27 [RFT PATCH v2 0/2] drm/panel: sitronix-st7789v: Convert to mipi_dbi Chen-Yu Tsai
2026-02-17  9:27 ` [RFT PATCH v2 1/2] drm/mipi-dbi: Provide option to invert reset GPIO logic Chen-Yu Tsai
2026-02-17  9:27 ` [RFT PATCH v2 2/2] drm/panel: sitronix-st7789v: Convert to mipi_dbi Chen-Yu Tsai
2026-02-18  6:37 ` [RFT PATCH v2 0/2] " Archit Anant

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome