From nobody Fri Apr 3 02:56:56 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AAB181DE3B5 for ; Tue, 17 Feb 2026 06:37:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771310225; cv=none; b=ooqeI5AV0JL4mX7tmHa+Lb1cUD4k7xUlrBz4/btsF5LOBwdRDD4DEsb4W/WdMoLCoHlLDeIwn/mNbUuoT7Fe5rYpKVNv7MGWef1QRgClDEh0MQWgijwo9y4JOcbzd3DKK5x8ZFqftCcVwIAZ3vf8RSpQE4Smp0rq3mDhY/A+bb8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771310225; c=relaxed/simple; bh=uGjzkrhdhXqwSIJbMckxgT5nNy3d6MsSF3Jryrexppc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=XIMlDur5c6/Mt5MvRaN2CswSVamI+DEaez/3nZdkKnpJvwsph+jL9qsyy1Xnq2j98nbX2eeb8FwuORmICrGOpMUkrLDQGCprntkETn0ab+OD4Dh7eOcwexMN9isoyDlLMjmsIH/g/faj6tBqby+2x602DGpuGEdh8EL9xqEAxrE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=njYfn1+L; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="njYfn1+L" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 29607C4AF0B; Tue, 17 Feb 2026 06:37:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1771310225; bh=uGjzkrhdhXqwSIJbMckxgT5nNy3d6MsSF3Jryrexppc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=njYfn1+Lxa9ZOudVq/alNThuCJSvN1gK71IKqFJLD1JYM00ORUiiVfs4XXo3nmv8G CgPLd7fFxSCLj2lzo5qV6dscLvJUDD81qFdO2rJOEmeNWAlDaq0OOyh04OuyPuumvl erKV75LKATxwffKhEYe3UiQNaD++F7fIKWtx5bmQrLNlQJ2pSwvlUJnVqCshM151sH OVntSAdPdtoLPnRwgwyEKl9uF1wtIp53LtHlC18uR8h9XApWDDAH8Ad8FKkwVM3xT5 6DV0q7zLiYGabO0/o234MV2f5Hxdpg3nWh+zRRoDpzFjisXg89TQ4tviByi52ZeV0O eYoiwJhgkWiAg== Received: by wens.tw (Postfix, from userid 1000) id 90D9E5F755; Tue, 17 Feb 2026 14:37:02 +0800 (CST) From: Chen-Yu Tsai 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@lists.freedesktop.org, linux-kernel@vger.kernel.org Subject: [RFT PATCH 1/2] drm/mipi-dbi: Provide option to invert reset GPIO logic Date: Tue, 17 Feb 2026 14:36:43 +0800 Message-ID: <20260217063647.3160826-2-wens@kernel.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260217063647.3160826-1-wens@kernel.org> References: <20260217063647.3160826-1-wens@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 --- 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; =20 - 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; =20 + /** + * @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 */ --=20 2.47.3 From nobody Fri Apr 3 02:56:56 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AAB8423A98E for ; Tue, 17 Feb 2026 06:37:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771310225; cv=none; b=GNfZ8druCD4h6VMisz6ak2/JG6rj1BQJuWxa6gTdDWT1acxjKONbeu7ofzpmMqS5J7Tv5mhiiELJ3PdrV7kuTfIlcDgI9INQxQQ103roeBx/h2tVwRCdu2y/uiIqAb7by4AiWcQFYcADAeJv+xcgtrwmTnljK1FR4+P6SqsxXLc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771310225; c=relaxed/simple; bh=gnTftnoIBkI330fF7Dod1W2djpjcPdodUfHbrfc7B/g=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Vfd90Cdg+JQ8/Yj80/A0FfVGEkvqKovMRywR6iWOqpj9slVzl7rgFaGpZllLacYCdnLJPtSqBom2iTCVv55ZQruKrECXAYzKkyLcE/7Xmo53/3isSweq8dJ6uUZD0aadHuyQdBRl+N/Z7YdeUaPi9IABQSjV5dcEh0bK+OxhAMo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=qeRAyOmo; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="qeRAyOmo" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 27601C19421; Tue, 17 Feb 2026 06:37:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1771310225; bh=gnTftnoIBkI330fF7Dod1W2djpjcPdodUfHbrfc7B/g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qeRAyOmoqhjiu31w51h8IzEas+BPYq/Rj9Cq2dbhwSdnplKN+wfCGbktqazo8D77u B8zwrM8yt2O3xLC33YeJuVEyhdffOWQsnC/AtioSipU14Oxxt1G7wRpQaCF/o6g9qb QVolPRYMdFj1D7ULLxpcdk5cu8AH2eFY7JEcj38aO+4Zgl3Msk87+FMXTUSN+95oBl DPOIfBitCJxZzletxwc19RyuGxMn/n9abDKojLyefHkoXPPICdq3KdNlZL6WoFgPdB rUreL4C47XIAU3ciM7ahQ2lk/Y/w8+OuwxfuBtXigimkw1SOP4QqYGwSYe0kWRcD5+ IPA0n/R8bqNDQ== Received: by wens.tw (Postfix, from userid 1000) id 977CE5FCAE; Tue, 17 Feb 2026 14:37:02 +0800 (CST) From: Chen-Yu Tsai 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@lists.freedesktop.org, linux-kernel@vger.kernel.org Subject: [RFT PATCH 2/2] drm/panel: sitronix-st7789v: Convert to mipi_dbi Date: Tue, 17 Feb 2026 14:36:44 +0800 Message-ID: <20260217063647.3160826-3-wens@kernel.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260217063647.3160826-1-wens@kernel.org> References: <20260217063647.3160826-1-wens@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 --- drivers/gpu/drm/panel/Kconfig | 1 + .../gpu/drm/panel/panel-sitronix-st7789v.c | 304 +++++++----------- 2 files changed, 109 insertions(+), 196 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/d= rm/panel/panel-sitronix-st7789v.c index d5f821d6b23c..27d1c4aefc53 100644 --- a/drivers/gpu/drm/panel/panel-sitronix-st7789v.c +++ b/drivers/gpu/drm/panel/panel-sitronix-st7789v.c @@ -14,6 +14,7 @@ =20 #include #include +#include #include =20 #define ST7789V_RAMCTRL_CMD 0xb0 @@ -125,9 +126,9 @@ struct st7789_panel_info { =20 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); } =20 -static int st7789v_spi_write(struct st7789v *ctx, enum st7789v_prefix pref= ix, - u8 data) -{ - struct spi_transfer xfer =3D { }; - u16 txbuf =3D ((prefix & 1) << 8) | data; - - xfer.tx_buf =3D &txbuf; - xfer.len =3D 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] =3D { }; - struct spi_message msg; - u16 txbuf =3D ((ST7789V_COMMAND & 1) << 8) | cmd; - u16 rxbuf[4] =3D {}; - u8 bit9 =3D 0; - int ret, i; - - switch (len) { - case 1: - case 3: - case 4: - break; - default: - return -EOPNOTSUPP; - } - - spi_message_init(&msg); - - xfer[0].tx_buf =3D &txbuf; - xfer[0].len =3D sizeof(txbuf); - spi_message_add_tail(&xfer[0], &msg); - - xfer[1].rx_buf =3D rxbuf; - xfer[1].len =3D len * 2; - spi_message_add_tail(&xfer[1], &msg); - - ret =3D spi_sync(ctx->spi, &msg); - if (ret) - return ret; - - for (i =3D 0; i < len; i++) { - buf[i] =3D rxbuf[i] >> i | (bit9 << (9 - i)); - if (i) - bit9 =3D rxbuf[i] & GENMASK(i - 1, 0); - } - - return 0; -} - static int st7789v_check_id(struct drm_panel *panel) { const u8 st7789v_ids[ST7789V_IDS_SIZE] =3D ST7789V_IDS; struct st7789v *ctx =3D panel_to_st7789v(panel); bool invalid_ids =3D false; int ret, i; - u8 ids[3]; + u8 ids[ST7789V_IDS_SIZE]; =20 if (ctx->spi->mode & SPI_NO_RX) return 0; =20 - ret =3D st7789v_read_data(ctx, MIPI_DCS_GET_DISPLAY_ID, ids, ST7789V_IDS_= SIZE); + ret =3D mipi_dbi_command_stackbuf(&ctx->dbi, MIPI_DCS_GET_DISPLAY_ID, + ids, sizeof(ids)); if (ret) return ret; =20 - for (i =3D 0; i < ST7789V_IDS_SIZE; i++) { + for (i =3D 0; i < sizeof(ids); i++) { if (ids[i] !=3D st7789v_ids[i]) { invalid_ids =3D true; break; @@ -379,6 +317,7 @@ static enum drm_panel_orientation st7789v_get_orientati= on(struct drm_panel *p) static int st7789v_prepare(struct drm_panel *panel) { struct st7789v *ctx =3D panel_to_st7789v(panel); + struct mipi_dbi *dbi =3D &ctx->dbi; u8 mode, pixel_fmt, polarity; int ret; =20 @@ -416,10 +355,7 @@ static int st7789v_prepare(struct drm_panel *panel) if (ret) return ret; =20 - gpiod_set_value(ctx->reset, 1); - msleep(30); - gpiod_set_value(ctx->reset, 0); - msleep(120); + mipi_dbi_hw_reset(&ctx->dbi); =20 /* * 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"); =20 - ST7789V_TEST(ret, st7789v_write_command(ctx, MIPI_DCS_EXIT_SLEEP_MODE)); + ST7789V_TEST(ret, mipi_dbi_command(dbi, MIPI_DCS_EXIT_SLEEP_MODE)); =20 /* We need to wait 120ms after a sleep out command */ msleep(120); =20 - 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))); =20 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)); } =20 if (ctx->info->partial_mode) { @@ -539,36 +455,27 @@ static int st7789v_prepare(struct drm_panel *panel) * add margins. */ =20 - 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])); } =20 - 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)); =20 - 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))); =20 return 0; } @@ -577,7 +484,7 @@ static int st7789v_enable(struct drm_panel *panel) { struct st7789v *ctx =3D panel_to_st7789v(panel); =20 - return st7789v_write_command(ctx, MIPI_DCS_SET_DISPLAY_ON); + return mipi_dbi_command(&ctx->dbi, MIPI_DCS_SET_DISPLAY_ON); } =20 static int st7789v_disable(struct drm_panel *panel) @@ -585,7 +492,7 @@ static int st7789v_disable(struct drm_panel *panel) struct st7789v *ctx =3D panel_to_st7789v(panel); int ret; =20 - 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)); =20 return 0; } @@ -595,7 +502,7 @@ static int st7789v_unprepare(struct drm_panel *panel) struct st7789v *ctx =3D panel_to_st7789v(panel); int ret; =20 - 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)); =20 regulator_disable(ctx->power); =20 @@ -615,6 +522,7 @@ static int st7789v_probe(struct spi_device *spi) { struct device *dev =3D &spi->dev; struct st7789v *ctx; + struct gpio_desc *dc; int ret; =20 ctx =3D 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 =3D spi; =20 - spi->bits_per_word =3D 9; - ret =3D spi_setup(spi); - if (ret < 0) - return dev_err_probe(&spi->dev, ret, "Failed to setup spi\n"); - ctx->info =3D device_get_match_data(&spi->dev); =20 ctx->power =3D 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"); =20 - ctx->reset =3D devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW); + ctx->dbi.reset =3D devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW); ret =3D PTR_ERR_OR_ZERO(ctx->reset); if (ret) return dev_err_probe(dev, ret, "Failed to get reset line\n"); =20 + dc =3D devm_gpiod_get_optional(&spi->dev, "dc", GPIOD_OUT_LOW); + ret =3D PTR_ERR_OR_ZERO(dc); + if (ret) + return dev_err_probe(&spi->dev, ret, "Failed to get GPIO for D/C\n"); + ret =3D 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"); =20 + ret =3D 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); =20 return 0; --=20 2.47.3