From nobody Fri Apr 3 03:23:40 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 40860308F3B for ; Tue, 17 Feb 2026 09:27:52 +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=1771320472; cv=none; b=rnS29whfnndFltWWjd0cLj3iqXK876H2pQ2gtaLS7Rg1nQ1Sdi28M/fGHcHpzKjka0mro5TkGkwVaAJid1kyXMrmO9SckQ/pSnKSrOwf+/HGJDFsBCWRom3oZt4/7SzWekV2XrgvdnkQwPJOa86HHVAxXfdiI6lUpKUJkFtSPeE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771320472; c=relaxed/simple; bh=uGjzkrhdhXqwSIJbMckxgT5nNy3d6MsSF3Jryrexppc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=heMxv1xb2RWiiiveTY28mz/bY1tA7iE5GNgPt2l9dfEw45THg33f17DIZdGS9CxcOSToJTMkpliGVYLjCQtFOWW9oeMGfd7bpcfMEyMfmbElV23xyVMIrXFA9INaUecyYwy+iJ5clVPpM4jBCxWuDsOBIvFT+NaMQhVPhMum7ps= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=BNxc2S46; 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="BNxc2S46" Received: by smtp.kernel.org (Postfix) with ESMTPSA id AE8B4C4CEF7; Tue, 17 Feb 2026 09:27:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1771320471; bh=uGjzkrhdhXqwSIJbMckxgT5nNy3d6MsSF3Jryrexppc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BNxc2S46X9YlRIjj8PaWuj5CWyzTLESuP33i3mE8orNt0R+b5ZOBXjsScD8tBb77v iIZPaZ1m+II5eVo6mn4mw0z6VhnIgWupnEQUzvyPnUTxNabUUVS3OVtfpCixOfwky5 QUYfVfgOGIC4wCvwK5DlJoXsJeWB+N/1EIrneg40PNbu6oiuxIk8TomIk8zQYqK036 16MsqPOYyDo+8fxlpUw9F7lq4cEHUBtMVpm93qBabUgSmOsvXezKoUfuDqpWQIBvIf g6/R8lF+LnjixCIrdCaCaWm2qjYbsvmpd9EAerdmx281hsI/bLFvmQgCVjtyO6AU6H chnrY2iCDfWOg== Received: by wens.tw (Postfix, from userid 1000) id 8BF955F755; Tue, 17 Feb 2026 17:27:49 +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 v2 1/2] drm/mipi-dbi: Provide option to invert reset GPIO logic Date: Tue, 17 Feb 2026 17:27:36 +0800 Message-ID: <20260217092738.3238016-2-wens@kernel.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260217092738.3238016-1-wens@kernel.org> References: <20260217092738.3238016-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 03:23:40 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 07F1D3081DF for ; Tue, 17 Feb 2026 09:27:52 +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=1771320472; cv=none; b=l3fm/wGXobY/u0+0wJAl9ay+uRYp97wGgeLcq8Hs2B1DquEGpwXqJcUYXlQ5LxCf5q546zkDPY7s/mtyQzM5JT0DJ1wfgxjZtAjtqHs7FOLWALRv7o2alV5Rk3vSoCWJtSZQRxjsm7UdCdl+Al164EjbvDrx6anJFWVvEdcKQnE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771320472; c=relaxed/simple; bh=NNpamjb6/2EhUf0wzaqXXerTArB9ffwgxPdZbID8l9w=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=nydA3Snp/9m3vT40B8ISAm50uX3779BQAexPRISpur0bkxWy3DBTKpk0rmc9hsCu84gMr5CZy1xCa2ojmzGVD99l1O4rXeNkAdZL/9d1acmBoLEJTgi0u0BLwuBfcACwn4ALDhpN6GDPD4AySn0wYnLBkiwBVPtOCp23WFoa1ao= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=XTUArIkQ; 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="XTUArIkQ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id AEE18C4AF09; Tue, 17 Feb 2026 09:27:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1771320471; bh=NNpamjb6/2EhUf0wzaqXXerTArB9ffwgxPdZbID8l9w=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XTUArIkQ1REad2xVRfbdfdfxibYJKpZb49JaM5tgeIKlKKGd95+bv5Nlk3pmnHp44 hZ7jd2nlsEwgnQFNMDbT0ZVP3iO1kN1raOhhadOYAGJIiRl37RqL32y8yDCTrLPHN2 sRKavuIMGDs7wNPyQH1xAEH1RQYMOpK2nyS+TKRnwdW69PFGbBZNq3x1wOA4733I1Y 1qCy/1z6GoVZ86HDfAZMnGkAu2LJtEpugh7qfGcIq/ej3PBS1szxipIsp++8rFij/U 3Y46PNaR/NQQQouldQOMStULU1k/ECKRRHqqmyhH4g4s25A2tJ6Fzp0RTHnH9uzSND vJ1i/rK4TDk5w== Received: by wens.tw (Postfix, from userid 1000) id 93FCE5FCAE; Tue, 17 Feb 2026 17:27:49 +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 v2 2/2] drm/panel: sitronix-st7789v: Convert to mipi_dbi Date: Tue, 17 Feb 2026 17:27:37 +0800 Message-ID: <20260217092738.3238016-3-wens@kernel.org> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20260217092738.3238016-1-wens@kernel.org> References: <20260217092738.3238016-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 --- 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/d= rm/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 @@ =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); - ret =3D PTR_ERR_OR_ZERO(ctx->reset); + ctx->dbi.reset =3D devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_LOW); + ret =3D PTR_ERR_OR_ZERO(ctx->dbi.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