1 From fa01d26c4572ed40dfe867d3c488abcb1d9a9db4 Mon Sep 17 00:00:00 2001
2 From: Dave Stevenson <dave.stevenson@raspberrypi.com>
3 Date: Wed, 5 Jan 2022 19:14:48 +0000
4 Subject: [PATCH] drm/panel: Add panel driver for Ilitek ILI9806E panel
6 The Ilitek ILI9806E driver is used in the Pimoroni HyperPixel4
7 and potentially other displays. Whilst it can support multiple
8 interfaces, this driver only accounts for SPI configuration and
11 Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
13 drivers/gpu/drm/panel/Kconfig | 11 +
14 drivers/gpu/drm/panel/Makefile | 1 +
15 drivers/gpu/drm/panel/panel-ilitek-ili9806e.c | 486 ++++++++++++++++++
16 3 files changed, 498 insertions(+)
17 create mode 100644 drivers/gpu/drm/panel/panel-ilitek-ili9806e.c
19 --- a/drivers/gpu/drm/panel/Kconfig
20 +++ b/drivers/gpu/drm/panel/Kconfig
21 @@ -139,6 +139,17 @@ config DRM_PANEL_ILITEK_ILI9341
22 QVGA (240x320) RGB panels. support serial & parallel rgb
25 +config DRM_PANEL_ILITEK_ILI9806E
26 + tristate "Ilitek ILI9806E-based panels"
27 + depends on OF && SPI
28 + depends on DRM_KMS_HELPER
29 + depends on DRM_KMS_CMA_HELPER
30 + depends on BACKLIGHT_CLASS_DEVICE
33 + Say Y if you want to enable support for panels based on the
34 + Ilitek ILI9806e controller.
36 config DRM_PANEL_ILITEK_ILI9881C
37 tristate "Ilitek ILI9881C-based panels"
39 --- a/drivers/gpu/drm/panel/Makefile
40 +++ b/drivers/gpu/drm/panel/Makefile
41 @@ -12,6 +12,7 @@ obj-$(CONFIG_DRM_PANEL_FEIXIN_K101_IM2BA
42 obj-$(CONFIG_DRM_PANEL_FEIYANG_FY07024DI26A30D) += panel-feiyang-fy07024di26a30d.o
43 obj-$(CONFIG_DRM_PANEL_ILITEK_IL9322) += panel-ilitek-ili9322.o
44 obj-$(CONFIG_DRM_PANEL_ILITEK_ILI9341) += panel-ilitek-ili9341.o
45 +obj-$(CONFIG_DRM_PANEL_ILITEK_ILI9806E) += panel-ilitek-ili9806e.o
46 obj-$(CONFIG_DRM_PANEL_ILITEK_ILI9881C) += panel-ilitek-ili9881c.o
47 obj-$(CONFIG_DRM_PANEL_INNOLUX_EJ030NA) += panel-innolux-ej030na.o
48 obj-$(CONFIG_DRM_PANEL_INNOLUX_P079ZCA) += panel-innolux-p079zca.o
50 +++ b/drivers/gpu/drm/panel/panel-ilitek-ili9806e.c
52 +// SPDX-License-Identifier: GPL-2.0-only
54 + * Ilitek ILI9806E TFT LCD drm_panel driver.
56 + * Copyright (C) 2022 Raspberry Pi Ltd
58 + * Derived from drivers/drm/gpu/panel/panel-sitronix-st7789v.c
59 + * Copyright (C) 2017 Free Electrons
62 +#include <drm/drm_modes.h>
63 +#include <drm/drm_panel.h>
65 +#include <linux/bitops.h>
66 +#include <linux/gpio/consumer.h>
67 +#include <linux/media-bus-format.h>
68 +#include <linux/module.h>
69 +#include <linux/of_device.h>
70 +#include <linux/regmap.h>
71 +#include <linux/regulator/consumer.h>
72 +#include <linux/spi/spi.h>
74 +#include <video/mipi_display.h>
75 +#include <video/of_videomode.h>
76 +#include <video/videomode.h>
79 + struct drm_panel panel;
80 + struct spi_device *spi;
81 + struct gpio_desc *reset;
82 + struct regulator *power;
86 +#define ILI9806_DATA BIT(8)
88 +#define ILI9806_MAX_MSG_LEN 6
90 +struct ili9806e_msg {
92 + u16 msg[ILI9806_MAX_MSG_LEN];
95 +#define ILI9806_SET_PAGE(page) \
100 + ILI9806_DATA | 0xFF, \
101 + ILI9806_DATA | 0x98, \
102 + ILI9806_DATA | 0x06, \
103 + ILI9806_DATA | 0x04, \
104 + ILI9806_DATA | (page) \
108 +#define ILI9806_SET_REG_PARAM(reg, data) \
113 + ILI9806_DATA | (data), \
117 +#define ILI9806_SET_REG(reg) \
120 + .msg = { (reg) }, \
123 +static const struct ili9806e_msg panel_init[] = {
124 + ILI9806_SET_PAGE(1),
127 + * SEPT_SDIO = 0 (spi interface transfer through SDA pin)
128 + * SDO_STATUS = 1 (always output, but without output tri-state)
130 + ILI9806_SET_REG_PARAM(0x08, 0x10),
132 + * VSPL = 1 (vertical sync polarity)
133 + * HSPL = 0 (horizontal sync polarity)
134 + * DPL = 0 (PCLK polarity)
135 + * EPL = 1 (data enable polarity)
137 + ILI9806_SET_REG_PARAM(0x21, 0x0d),
138 + /* resolution control (0x02 = 480x800) */
139 + ILI9806_SET_REG_PARAM(0x30, 0x02),
140 + /* display inversion control (0x00 = column inversion) */
141 + ILI9806_SET_REG_PARAM(0x31, 0x00),
143 + * EXB1T = 0 (internal charge pump)
144 + * EXT_CPCK_SEL = 1 (pump clock control signal = output 2 x waveform)
145 + * BT = 0 (DDVDH / DDVDL voltage = VCI x 2 / VCI x -2)
147 + ILI9806_SET_REG_PARAM(0x40, 0x10),
149 + * DDVDH_CLP = 5.6 (DDVDH clamp leve)
150 + * DDVDL_CLP = -5.6 (DDVDL clamp leve)
152 + ILI9806_SET_REG_PARAM(0x41, 0x55),
154 + * VGH_CP = 2DDVDH - DDVDL (step up factor for VGH)
155 + * VGL_CP = DDVDL + VCL - VCIP (step up factor for VGL)
157 + ILI9806_SET_REG_PARAM(0x42, 0x02),
159 + * VGH_CLPEN = 0 (disable VGH clamp level)
160 + * VGH_CLP = 9 (15.0 VGH clamp level - but this is disabled so not used?)
162 + ILI9806_SET_REG_PARAM(0x43, 0x84),
164 + * VGL_CLPEN = 0 (disable VGL clamp level)
165 + * VGL_CLP = 9 (-11.0 VGL clamp level - but this is disabled so not used?)
167 + ILI9806_SET_REG_PARAM(0x44, 0x84),
170 + * VREG1OUT voltage for positive gamma?
172 + ILI9806_SET_REG_PARAM(0x50, 0x78),
174 + * VREG2OUT voltage for negative gamma?
176 + ILI9806_SET_REG_PARAM(0x51, 0x78),
178 + ILI9806_SET_REG_PARAM(0x52, 0x00),
179 + ILI9806_SET_REG_PARAM(0x53, 0x77),
180 + ILI9806_SET_REG_PARAM(0x57, 0x60),
181 + ILI9806_SET_REG_PARAM(0x60, 0x07),
182 + ILI9806_SET_REG_PARAM(0x61, 0x00),
183 + ILI9806_SET_REG_PARAM(0x62, 0x08),
184 + ILI9806_SET_REG_PARAM(0x63, 0x00),
185 + ILI9806_SET_REG_PARAM(0xA0, 0x00),
186 + ILI9806_SET_REG_PARAM(0xA1, 0x07),
187 + ILI9806_SET_REG_PARAM(0xA2, 0x0C),
188 + ILI9806_SET_REG_PARAM(0xA3, 0x0B),
189 + ILI9806_SET_REG_PARAM(0xA4, 0x03),
190 + ILI9806_SET_REG_PARAM(0xA5, 0x07),
191 + ILI9806_SET_REG_PARAM(0xA6, 0x06),
192 + ILI9806_SET_REG_PARAM(0xA7, 0x04),
193 + ILI9806_SET_REG_PARAM(0xA8, 0x08),
194 + ILI9806_SET_REG_PARAM(0xA9, 0x0C),
195 + ILI9806_SET_REG_PARAM(0xAA, 0x13),
196 + ILI9806_SET_REG_PARAM(0xAB, 0x06),
197 + ILI9806_SET_REG_PARAM(0xAC, 0x0D),
198 + ILI9806_SET_REG_PARAM(0xAD, 0x19),
199 + ILI9806_SET_REG_PARAM(0xAE, 0x10),
200 + ILI9806_SET_REG_PARAM(0xAF, 0x00),
201 + /* negative gamma control
202 + * set the gray scale voltage to adjust the gamma characteristics of the panel
204 + ILI9806_SET_REG_PARAM(0xC0, 0x00),
205 + ILI9806_SET_REG_PARAM(0xC1, 0x07),
206 + ILI9806_SET_REG_PARAM(0xC2, 0x0C),
207 + ILI9806_SET_REG_PARAM(0xC3, 0x0B),
208 + ILI9806_SET_REG_PARAM(0xC4, 0x03),
209 + ILI9806_SET_REG_PARAM(0xC5, 0x07),
210 + ILI9806_SET_REG_PARAM(0xC6, 0x07),
211 + ILI9806_SET_REG_PARAM(0xC7, 0x04),
212 + ILI9806_SET_REG_PARAM(0xC8, 0x08),
213 + ILI9806_SET_REG_PARAM(0xC9, 0x0C),
214 + ILI9806_SET_REG_PARAM(0xCA, 0x13),
215 + ILI9806_SET_REG_PARAM(0xCB, 0x06),
216 + ILI9806_SET_REG_PARAM(0xCC, 0x0D),
217 + ILI9806_SET_REG_PARAM(0xCD, 0x18),
218 + ILI9806_SET_REG_PARAM(0xCE, 0x10),
219 + ILI9806_SET_REG_PARAM(0xCF, 0x00),
221 + ILI9806_SET_PAGE(6),
223 + ILI9806_SET_REG_PARAM(0x00, 0x20),
224 + ILI9806_SET_REG_PARAM(0x01, 0x0A),
225 + ILI9806_SET_REG_PARAM(0x02, 0x00),
226 + ILI9806_SET_REG_PARAM(0x03, 0x00),
227 + ILI9806_SET_REG_PARAM(0x04, 0x01),
228 + ILI9806_SET_REG_PARAM(0x05, 0x01),
229 + ILI9806_SET_REG_PARAM(0x06, 0x98),
230 + ILI9806_SET_REG_PARAM(0x07, 0x06),
231 + ILI9806_SET_REG_PARAM(0x08, 0x01),
232 + ILI9806_SET_REG_PARAM(0x09, 0x80),
233 + ILI9806_SET_REG_PARAM(0x0A, 0x00),
234 + ILI9806_SET_REG_PARAM(0x0B, 0x00),
235 + ILI9806_SET_REG_PARAM(0x0C, 0x01),
236 + ILI9806_SET_REG_PARAM(0x0D, 0x01),
237 + ILI9806_SET_REG_PARAM(0x0E, 0x00),
238 + ILI9806_SET_REG_PARAM(0x0F, 0x00),
239 + ILI9806_SET_REG_PARAM(0x10, 0xF0),
240 + ILI9806_SET_REG_PARAM(0x11, 0xF4),
241 + ILI9806_SET_REG_PARAM(0x12, 0x01),
242 + ILI9806_SET_REG_PARAM(0x13, 0x00),
243 + ILI9806_SET_REG_PARAM(0x14, 0x00),
244 + ILI9806_SET_REG_PARAM(0x15, 0xC0),
245 + ILI9806_SET_REG_PARAM(0x16, 0x08),
246 + ILI9806_SET_REG_PARAM(0x17, 0x00),
247 + ILI9806_SET_REG_PARAM(0x18, 0x00),
248 + ILI9806_SET_REG_PARAM(0x19, 0x00),
249 + ILI9806_SET_REG_PARAM(0x1A, 0x00),
250 + ILI9806_SET_REG_PARAM(0x1B, 0x00),
251 + ILI9806_SET_REG_PARAM(0x1C, 0x00),
252 + ILI9806_SET_REG_PARAM(0x1D, 0x00),
253 + ILI9806_SET_REG_PARAM(0x20, 0x01),
254 + ILI9806_SET_REG_PARAM(0x21, 0x23),
255 + ILI9806_SET_REG_PARAM(0x22, 0x45),
256 + ILI9806_SET_REG_PARAM(0x23, 0x67),
257 + ILI9806_SET_REG_PARAM(0x24, 0x01),
258 + ILI9806_SET_REG_PARAM(0x25, 0x23),
259 + ILI9806_SET_REG_PARAM(0x26, 0x45),
260 + ILI9806_SET_REG_PARAM(0x27, 0x67),
261 + ILI9806_SET_REG_PARAM(0x30, 0x11),
262 + ILI9806_SET_REG_PARAM(0x31, 0x11),
263 + ILI9806_SET_REG_PARAM(0x32, 0x00),
264 + ILI9806_SET_REG_PARAM(0x33, 0xEE),
265 + ILI9806_SET_REG_PARAM(0x34, 0xFF),
266 + ILI9806_SET_REG_PARAM(0x35, 0xBB),
267 + ILI9806_SET_REG_PARAM(0x36, 0xAA),
268 + ILI9806_SET_REG_PARAM(0x37, 0xDD),
269 + ILI9806_SET_REG_PARAM(0x38, 0xCC),
270 + ILI9806_SET_REG_PARAM(0x39, 0x66),
271 + ILI9806_SET_REG_PARAM(0x3A, 0x77),
272 + ILI9806_SET_REG_PARAM(0x3B, 0x22),
273 + ILI9806_SET_REG_PARAM(0x3C, 0x22),
274 + ILI9806_SET_REG_PARAM(0x3D, 0x22),
275 + ILI9806_SET_REG_PARAM(0x3E, 0x22),
276 + ILI9806_SET_REG_PARAM(0x3F, 0x22),
277 + ILI9806_SET_REG_PARAM(0x40, 0x22),
278 + /* register doesn't exist on page 6? */
279 + ILI9806_SET_REG_PARAM(0x52, 0x10),
280 + /* doesn't make sense, not valid according to datasheet */
281 + ILI9806_SET_REG_PARAM(0x53, 0x10),
282 + /* doesn't make sense, not valid according to datasheet */
283 + ILI9806_SET_REG_PARAM(0x54, 0x13),
285 + ILI9806_SET_PAGE(7),
288 + ILI9806_SET_REG_PARAM(0x18, 0x1D),
289 + /* enable VGL_REG */
290 + ILI9806_SET_REG_PARAM(0x17, 0x22),
291 + /* register doesn't exist on page 7? */
292 + ILI9806_SET_REG_PARAM(0x02, 0x77),
293 + /* register doesn't exist on page 7? */
294 + ILI9806_SET_REG_PARAM(0x26, 0xB2),
295 + /* register doesn't exist on page 7? */
296 + ILI9806_SET_REG_PARAM(0xE1, 0x79),
298 + ILI9806_SET_PAGE(0),
300 + ILI9806_SET_REG_PARAM(MIPI_DCS_SET_PIXEL_FORMAT,
301 + MIPI_DCS_PIXEL_FMT_18BIT << 4),
302 + ILI9806_SET_REG_PARAM(MIPI_DCS_SET_TEAR_ON, 0x00),
303 + ILI9806_SET_REG(MIPI_DCS_EXIT_SLEEP_MODE),
306 +#define NUM_INIT_REGS ARRAY_SIZE(panel_init)
308 +static inline struct ili9806 *panel_to_ili9806(struct drm_panel *panel)
310 + return container_of(panel, struct ili9806, panel);
313 +static int ili9806_write_msg(struct ili9806 *ctx, const struct ili9806e_msg *msg)
315 + struct spi_transfer xfer = { };
316 + struct spi_message spi;
317 + //u16 txbuf[] = { msg->, ILI9806_DATA | data };
319 + spi_message_init(&spi);
321 + xfer.tx_buf = msg->msg;
322 + xfer.bits_per_word = 9;
323 + xfer.len = sizeof(u16) * msg->len;
325 + spi_message_add_tail(&xfer, &spi);
326 + return spi_sync(ctx->spi, &spi);
329 +static int ili9806e_write_msg_list(struct ili9806 *ctx,
330 + const struct ili9806e_msg msgs[],
331 + unsigned int num_msgs)
335 + for (i = 0; i < num_msgs; i++) {
336 + ret = ili9806_write_msg(ctx, &msgs[i]);
344 +static const struct drm_display_mode ili9806e_480x800_mode = {
347 + .hsync_start = 480 + 10,
348 + .hsync_end = 480 + 10 + 16,
349 + .htotal = 480 + 10 + 16 + 59,
351 + .vsync_start = 800 + 15,
352 + .vsync_end = 800 + 15 + 113,
353 + .vtotal = 800 + 15 + 113 + 15,
354 + .flags = DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC,
357 +static int ili9806_get_modes(struct drm_panel *panel,
358 + struct drm_connector *connector)
360 + struct ili9806 *ctx = panel_to_ili9806(panel);
361 + struct drm_display_mode *mode;
363 + mode = drm_mode_duplicate(connector->dev, &ili9806e_480x800_mode);
365 + dev_err(panel->dev, "failed to add mode %ux%ux@%u\n",
366 + ili9806e_480x800_mode.hdisplay,
367 + ili9806e_480x800_mode.vdisplay,
368 + drm_mode_vrefresh(&ili9806e_480x800_mode));
372 + drm_mode_set_name(mode);
374 + mode->type = DRM_MODE_TYPE_DRIVER | DRM_MODE_TYPE_PREFERRED;
375 + drm_mode_probed_add(connector, mode);
377 + connector->display_info.width_mm = 61;
378 + connector->display_info.height_mm = 103;
379 + drm_display_info_set_bus_formats(&connector->display_info,
380 + &ctx->bus_format, 1);
381 + connector->display_info.bus_flags =
382 + DRM_BUS_FLAG_PIXDATA_DRIVE_NEGEDGE;
387 +static int ili9806_prepare(struct drm_panel *panel)
389 + struct ili9806 *ctx = panel_to_ili9806(panel);
392 + ret = regulator_enable(ctx->power);
396 + ret = ili9806e_write_msg_list(ctx, panel_init, NUM_INIT_REGS);
401 +static int ili9806_enable(struct drm_panel *panel)
403 + struct ili9806 *ctx = panel_to_ili9806(panel);
404 + const struct ili9806e_msg msg = ILI9806_SET_REG(MIPI_DCS_SET_DISPLAY_ON);
407 + ret = ili9806_write_msg(ctx, &msg);
412 +static int ili9806_disable(struct drm_panel *panel)
414 + struct ili9806 *ctx = panel_to_ili9806(panel);
415 + const struct ili9806e_msg msg = ILI9806_SET_REG(MIPI_DCS_SET_DISPLAY_OFF);
418 + ret = ili9806_write_msg(ctx, &msg);
423 +static int ili9806_unprepare(struct drm_panel *panel)
425 + struct ili9806 *ctx = panel_to_ili9806(panel);
426 + const struct ili9806e_msg msg = ILI9806_SET_REG(MIPI_DCS_ENTER_SLEEP_MODE);
429 + ret = ili9806_write_msg(ctx, &msg);
434 +static const struct drm_panel_funcs ili9806_drm_funcs = {
435 + .disable = ili9806_disable,
436 + .enable = ili9806_enable,
437 + .get_modes = ili9806_get_modes,
438 + .prepare = ili9806_prepare,
439 + .unprepare = ili9806_unprepare,
442 +static const struct of_device_id ili9806_of_match[] = {
443 + { .compatible = "txw,txw397017s2",
444 + .data = (void *)MEDIA_BUS_FMT_RGB888_1X24,
446 + .compatible = "pimoroni,hyperpixel4",
447 + .data = (void *)MEDIA_BUS_FMT_RGB666_1X24_CPADHI,
449 + .compatible = "ilitek,ili9806e",
450 + .data = (void *)MEDIA_BUS_FMT_RGB888_1X24,
455 +MODULE_DEVICE_TABLE(of, ili9806_of_match);
457 +static int ili9806_probe(struct spi_device *spi)
459 + const struct ili9806e_msg panel_reset[] = {
460 + ILI9806_SET_PAGE(0),
461 + ILI9806_SET_REG_PARAM(0x01, 0x00)
463 + const struct of_device_id *id;
464 + struct ili9806 *ctx;
467 + ctx = devm_kzalloc(&spi->dev, sizeof(*ctx), GFP_KERNEL);
471 + id = of_match_node(ili9806_of_match, spi->dev.of_node);
475 + ctx->bus_format = (u32)id->data;
477 + spi_set_drvdata(spi, ctx);
480 + drm_panel_init(&ctx->panel, &spi->dev, &ili9806_drm_funcs,
481 + DRM_MODE_CONNECTOR_DPI);
483 + ctx->power = devm_regulator_get(&spi->dev, "power");
484 + if (IS_ERR(ctx->power))
485 + return PTR_ERR(ctx->power);
487 + ctx->reset = devm_gpiod_get_optional(&spi->dev, "reset", GPIOD_OUT_LOW);
488 + if (IS_ERR(ctx->reset)) {
489 + dev_err(&spi->dev, "Couldn't get our reset line\n");
490 + return PTR_ERR(ctx->reset);
494 + ili9806e_write_msg_list(ctx, panel_reset, ARRAY_SIZE(panel_reset));
497 + ret = drm_panel_of_backlight(&ctx->panel);
501 + drm_panel_add(&ctx->panel);
506 +static int ili9806_remove(struct spi_device *spi)
508 + struct ili9806 *ctx = spi_get_drvdata(spi);
510 + drm_panel_remove(&ctx->panel);
515 +static const struct spi_device_id ili9806_ids[] = {
516 + { "txw397017s2", 0 },
518 + { "hyperpixel4", 0 },
522 +MODULE_DEVICE_TABLE(spi, ili9806_ids);
524 +static struct spi_driver ili9806_driver = {
525 + .probe = ili9806_probe,
526 + .remove = ili9806_remove,
528 + .name = "ili9806e",
529 + .of_match_table = ili9806_of_match,
531 + .id_table = ili9806_ids,
533 +module_spi_driver(ili9806_driver);
535 +MODULE_AUTHOR("Dave Stevenson <dave.stevenson@raspberrypi.com>");
536 +MODULE_DESCRIPTION("ili9806 LCD panel driver");
537 +MODULE_LICENSE("GPL v2");