1 From 4d5992d474e75e58ceb0f3fe02e0f949c1255dcd Mon Sep 17 00:00:00 2001
2 From: Dave Stevenson <dave.stevenson@raspberrypi.com>
3 Date: Wed, 26 Jan 2022 16:02:31 +0000
4 Subject: [PATCH 0346/1085] drm/panel: Add panel driver for TDO Y17B based
7 The Top DisplayOptoelectronics (TDO) T17B driver chip is used
8 in the TL040HDS20CT panel (found in the Pimoroni HyperPixel4
9 Square display) and potentially other displays.
10 The driver chip supports SPI for configuration and DPI
13 Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
15 drivers/gpu/drm/panel/Kconfig | 11 +
16 drivers/gpu/drm/panel/Makefile | 1 +
17 drivers/gpu/drm/panel/panel-tdo-y17p.c | 277 +++++++++++++++++++++++++
18 3 files changed, 289 insertions(+)
19 create mode 100644 drivers/gpu/drm/panel/panel-tdo-y17p.c
21 --- a/drivers/gpu/drm/panel/Kconfig
22 +++ b/drivers/gpu/drm/panel/Kconfig
23 @@ -767,6 +767,17 @@ config DRM_PANEL_TDO_TL070WSH30
24 24 bit RGB per pixel. It provides a MIPI DSI interface to
25 the host, a built-in LED backlight and touch controller.
27 +config DRM_PANEL_TPO_Y17P
28 + tristate "TDO Y17P-based panels"
29 + depends on OF && SPI
30 + select DRM_KMS_HELPER
31 + depends on DRM_GEM_CMA_HELPER
32 + depends on BACKLIGHT_CLASS_DEVICE
35 + Say Y if you want to enable support for panels based on the
36 + TDO Y17P controller.
38 config DRM_PANEL_TPO_TD028TTEC1
39 tristate "Toppoly (TPO) TD028TTEC1 panel driver"
41 --- a/drivers/gpu/drm/panel/Makefile
42 +++ b/drivers/gpu/drm/panel/Makefile
43 @@ -77,6 +77,7 @@ obj-$(CONFIG_DRM_PANEL_SONY_TD4353_JDI)
44 obj-$(CONFIG_DRM_PANEL_SONY_TULIP_TRULY_NT35521) += panel-sony-tulip-truly-nt35521.o
45 obj-$(CONFIG_DRM_PANEL_STARTEK_KD070FHFID015) += panel-startek-kd070fhfid015.o
46 obj-$(CONFIG_DRM_PANEL_TDO_TL070WSH30) += panel-tdo-tl070wsh30.o
47 +obj-$(CONFIG_DRM_PANEL_TPO_Y17P) += panel-tdo-y17p.o
48 obj-$(CONFIG_DRM_PANEL_TPO_TD028TTEC1) += panel-tpo-td028ttec1.o
49 obj-$(CONFIG_DRM_PANEL_TPO_TD043MTEA1) += panel-tpo-td043mtea1.o
50 obj-$(CONFIG_DRM_PANEL_TPO_TPG110) += panel-tpo-tpg110.o
52 +++ b/drivers/gpu/drm/panel/panel-tdo-y17p.c
54 +// SPDX-License-Identifier: GPL-2.0-only
56 + * TDO Y17P TFT LCD drm_panel driver.
58 + * SPI configured DPI display controller
59 + * Copyright (C) 2022 Raspberry Pi Ltd
61 + * Derived from drivers/drm/gpu/panel/panel-sitronix-st7789v.c
62 + * Copyright (C) 2017 Free Electrons
65 +#include <drm/drm_modes.h>
66 +#include <drm/drm_panel.h>
68 +#include <linux/bitops.h>
69 +#include <linux/gpio/consumer.h>
70 +#include <linux/media-bus-format.h>
71 +#include <linux/module.h>
72 +#include <linux/of_device.h>
73 +#include <linux/regmap.h>
74 +#include <linux/regulator/consumer.h>
75 +#include <linux/spi/spi.h>
77 +#include <video/mipi_display.h>
78 +#include <video/of_videomode.h>
79 +#include <video/videomode.h>
82 + struct drm_panel panel;
83 + struct spi_device *spi;
84 + struct gpio_desc *reset;
85 + struct regulator *power;
89 +static const u16 panel_init[] = {
90 + 0x0ff, 0x1ff, 0x198, 0x106, 0x104, 0x101, 0x008, 0x110,
91 + 0x021, 0x109, 0x030, 0x102, 0x031, 0x100, 0x040, 0x110,
92 + 0x041, 0x155, 0x042, 0x102, 0x043, 0x109, 0x044, 0x107,
93 + 0x050, 0x178, 0x051, 0x178, 0x052, 0x100, 0x053, 0x16d,
94 + 0x060, 0x107, 0x061, 0x100, 0x062, 0x108, 0x063, 0x100,
95 + 0x0a0, 0x100, 0x0a1, 0x107, 0x0a2, 0x10c, 0x0a3, 0x10b,
96 + 0x0a4, 0x103, 0x0a5, 0x107, 0x0a6, 0x106, 0x0a7, 0x104,
97 + 0x0a8, 0x108, 0x0a9, 0x10c, 0x0aa, 0x113, 0x0ab, 0x106,
98 + 0x0ac, 0x10d, 0x0ad, 0x119, 0x0ae, 0x110, 0x0af, 0x100,
99 + 0x0c0, 0x100, 0x0c1, 0x107, 0x0c2, 0x10c, 0x0c3, 0x10b,
100 + 0x0c4, 0x103, 0x0c5, 0x107, 0x0c6, 0x107, 0x0c7, 0x104,
101 + 0x0c8, 0x108, 0x0c9, 0x10c, 0x0ca, 0x113, 0x0cb, 0x106,
102 + 0x0cc, 0x10d, 0x0cd, 0x118, 0x0ce, 0x110, 0x0cf, 0x100,
103 + 0x0ff, 0x1ff, 0x198, 0x106, 0x104, 0x106, 0x000, 0x120,
104 + 0x001, 0x10a, 0x002, 0x100, 0x003, 0x100, 0x004, 0x101,
105 + 0x005, 0x101, 0x006, 0x198, 0x007, 0x106, 0x008, 0x101,
106 + 0x009, 0x180, 0x00a, 0x100, 0x00b, 0x100, 0x00c, 0x101,
107 + 0x00d, 0x101, 0x00e, 0x100, 0x00f, 0x100, 0x010, 0x1f0,
108 + 0x011, 0x1f4, 0x012, 0x101, 0x013, 0x100, 0x014, 0x100,
109 + 0x015, 0x1c0, 0x016, 0x108, 0x017, 0x100, 0x018, 0x100,
110 + 0x019, 0x100, 0x01a, 0x100, 0x01b, 0x100, 0x01c, 0x100,
111 + 0x01d, 0x100, 0x020, 0x101, 0x021, 0x123, 0x022, 0x145,
112 + 0x023, 0x167, 0x024, 0x101, 0x025, 0x123, 0x026, 0x145,
113 + 0x027, 0x167, 0x030, 0x111, 0x031, 0x111, 0x032, 0x100,
114 + 0x033, 0x1ee, 0x034, 0x1ff, 0x035, 0x1bb, 0x036, 0x1aa,
115 + 0x037, 0x1dd, 0x038, 0x1cc, 0x039, 0x166, 0x03a, 0x177,
116 + 0x03b, 0x122, 0x03c, 0x122, 0x03d, 0x122, 0x03e, 0x122,
117 + 0x03f, 0x122, 0x040, 0x122, 0x052, 0x110, 0x053, 0x110,
118 + 0x0ff, 0x1ff, 0x198, 0x106, 0x104, 0x107, 0x018, 0x11d,
119 + 0x017, 0x122, 0x002, 0x177, 0x026, 0x1b2, 0x0e1, 0x179,
120 + 0x0ff, 0x1ff, 0x198, 0x106, 0x104, 0x100, 0x03a, 0x160,
121 + 0x035, 0x100, 0x011, 0x100,
124 +#define NUM_INIT_REGS ARRAY_SIZE(panel_init)
126 +static inline struct tdo_y17p *panel_to_tdo_y17p(struct drm_panel *panel)
128 + return container_of(panel, struct tdo_y17p, panel);
131 +static int tdo_y17p_write_msg(struct tdo_y17p *ctx, const u16 *msg, unsigned int len)
133 + struct spi_transfer xfer = { };
134 + struct spi_message spi;
136 + spi_message_init(&spi);
139 + xfer.bits_per_word = 9;
140 + xfer.len = sizeof(u16) * len;
142 + spi_message_add_tail(&xfer, &spi);
143 + return spi_sync(ctx->spi, &spi);
146 +static const struct drm_display_mode tdo_y17pe_720x720_mode = {
149 + .hsync_start = 720 + 20,
150 + .hsync_end = 720 + 20 + 20,
151 + .htotal = 720 + 20 + 20 + 40,
153 + .vsync_start = 720 + 15,
154 + .vsync_end = 720 + 15 + 15,
155 + .vtotal = 720 + 15 + 15 + 15,
156 + .flags = DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC,
159 +static int tdo_y17p_get_modes(struct drm_panel *panel,
160 + struct drm_connector *connector)
162 + struct tdo_y17p *ctx = panel_to_tdo_y17p(panel);
163 + struct drm_display_mode *mode;
165 + mode = drm_mode_duplicate(connector->dev, &tdo_y17pe_720x720_mode);
167 + dev_err(panel->dev, "failed to add mode %ux%ux@%u\n",
168 + tdo_y17pe_720x720_mode.hdisplay,
169 + tdo_y17pe_720x720_mode.vdisplay,
170 + drm_mode_vrefresh(&tdo_y17pe_720x720_mode));
174 + drm_mode_set_name(mode);
176 + mode->type = DRM_MODE_TYPE_DRIVER | DRM_MODE_TYPE_PREFERRED;
177 + drm_mode_probed_add(connector, mode);
179 + connector->display_info.width_mm = 72;
180 + connector->display_info.height_mm = 72;
181 + drm_display_info_set_bus_formats(&connector->display_info,
182 + &ctx->bus_format, 1);
183 + connector->display_info.bus_flags = 0;
188 +static int tdo_y17p_prepare(struct drm_panel *panel)
190 + struct tdo_y17p *ctx = panel_to_tdo_y17p(panel);
193 + ret = regulator_enable(ctx->power);
197 + ret = tdo_y17p_write_msg(ctx, panel_init, NUM_INIT_REGS);
204 +static int tdo_y17p_enable(struct drm_panel *panel)
206 + struct tdo_y17p *ctx = panel_to_tdo_y17p(panel);
207 + const u16 msg[] = { MIPI_DCS_SET_DISPLAY_ON };
210 + ret = tdo_y17p_write_msg(ctx, msg, ARRAY_SIZE(msg));
215 +static int tdo_y17p_disable(struct drm_panel *panel)
217 + struct tdo_y17p *ctx = panel_to_tdo_y17p(panel);
218 + const u16 msg[] = { MIPI_DCS_SET_DISPLAY_OFF };
221 + ret = tdo_y17p_write_msg(ctx, msg, ARRAY_SIZE(msg));
226 +static int tdo_y17p_unprepare(struct drm_panel *panel)
228 + struct tdo_y17p *ctx = panel_to_tdo_y17p(panel);
229 + const u16 msg[] = { MIPI_DCS_ENTER_SLEEP_MODE };
232 + ret = tdo_y17p_write_msg(ctx, msg, ARRAY_SIZE(msg));
237 +static const struct drm_panel_funcs tdo_y17p_drm_funcs = {
238 + .disable = tdo_y17p_disable,
239 + .enable = tdo_y17p_enable,
240 + .get_modes = tdo_y17p_get_modes,
241 + .prepare = tdo_y17p_prepare,
242 + .unprepare = tdo_y17p_unprepare,
245 +static const struct of_device_id tdo_y17p_of_match[] = {
246 + { .compatible = "tdo,tl040hds20ct",
247 + .data = (void *)MEDIA_BUS_FMT_BGR888_1X24,
249 + .compatible = "pimoroni,hyperpixel4square",
250 + .data = (void *)MEDIA_BUS_FMT_BGR666_1X24_CPADHI,
252 + .compatible = "tdo,y17p",
253 + .data = (void *)MEDIA_BUS_FMT_BGR888_1X24,
258 +MODULE_DEVICE_TABLE(of, tdo_y17p_of_match);
260 +static int tdo_y17p_probe(struct spi_device *spi)
262 + const struct of_device_id *id;
263 + struct tdo_y17p *ctx;
266 + ctx = devm_kzalloc(&spi->dev, sizeof(*ctx), GFP_KERNEL);
270 + id = of_match_node(tdo_y17p_of_match, spi->dev.of_node);
274 + ctx->bus_format = (u32)(uintptr_t)id->data;
276 + spi_set_drvdata(spi, ctx);
279 + drm_panel_init(&ctx->panel, &spi->dev, &tdo_y17p_drm_funcs,
280 + DRM_MODE_CONNECTOR_DPI);
282 + ctx->power = devm_regulator_get(&spi->dev, "power");
283 + if (IS_ERR(ctx->power))
284 + return PTR_ERR(ctx->power);
286 + ctx->reset = devm_gpiod_get_optional(&spi->dev, "reset", GPIOD_OUT_LOW);
287 + if (IS_ERR(ctx->reset)) {
288 + dev_err(&spi->dev, "Couldn't get our reset line\n");
289 + return PTR_ERR(ctx->reset);
292 + ret = drm_panel_of_backlight(&ctx->panel);
296 + drm_panel_add(&ctx->panel);
301 +static void tdo_y17p_remove(struct spi_device *spi)
303 + struct tdo_y17p *ctx = spi_get_drvdata(spi);
305 + drm_panel_remove(&ctx->panel);
308 +static const struct spi_device_id tdo_y17p_ids[] = {
309 + { "tl040hds20ct", 0 },
310 + { "hyperpixel4square", 0 },
315 +MODULE_DEVICE_TABLE(spi, tdo_y17p_ids);
317 +static struct spi_driver tdo_y17p_driver = {
318 + .probe = tdo_y17p_probe,
319 + .remove = tdo_y17p_remove,
321 + .name = "tdo_y17p",
322 + .of_match_table = tdo_y17p_of_match,
324 + .id_table = tdo_y17p_ids,
326 +module_spi_driver(tdo_y17p_driver);
328 +MODULE_AUTHOR("Dave Stevenson <dave.stevenson@raspberrypi.com>");
329 +MODULE_DESCRIPTION("TDO Y17P LCD panel driver");
330 +MODULE_LICENSE("GPL v2");