1 // SPDX-License-Identifier: GPL-2.0-only
3 * Ilitek ILI9341 TFT LCD drm_panel driver.
5 * This panel can be configured to support:
6 * - 16-bit parallel RGB interface
7 * - 18-bit parallel RGB interface
8 * - 4-line serial spi interface
13 * Derived from drivers/drm/gpu/panel/panel-ilitek-ili9322.c
14 * the reuse of DBI abstraction part referred from Linus's patch
15 * "drm/panel: s6e63m0: Switch to DBI abstraction for SPI"
17 * For only-dbi part, copy from David's code (drm/tiny/ili9341.c)
21 #include <linux/backlight.h>
22 #include <linux/bitops.h>
23 #include <linux/delay.h>
24 #include <linux/gpio/consumer.h>
25 #include <linux/module.h>
27 #include <linux/regulator/consumer.h>
28 #include <linux/spi/spi.h>
30 #include <video/mipi_display.h>
32 #include <drm/drm_atomic_helper.h>
33 #include <drm/drm_drv.h>
34 #include <drm/drm_fbdev_generic.h>
35 #include <drm/drm_gem_atomic_helper.h>
36 #include <drm/drm_gem_dma_helper.h>
37 #include <drm/drm_gem_framebuffer_helper.h>
38 #include <drm/drm_mipi_dbi.h>
39 #include <drm/drm_modes.h>
40 #include <drm/drm_panel.h>
41 #include <drm/drm_print.h>
43 #define ILI9341_RGB_INTERFACE 0xb0 /* RGB Interface Signal Control */
44 #define ILI9341_FRC 0xb1 /* Frame Rate Control register */
45 #define ILI9341_DFC 0xb6 /* Display Function Control register */
46 #define ILI9341_POWER1 0xc0 /* Power Control 1 register */
47 #define ILI9341_POWER2 0xc1 /* Power Control 2 register */
48 #define ILI9341_VCOM1 0xc5 /* VCOM Control 1 register */
49 #define ILI9341_VCOM2 0xc7 /* VCOM Control 2 register */
50 #define ILI9341_POWERA 0xcb /* Power control A register */
51 #define ILI9341_POWERB 0xcf /* Power control B register */
52 #define ILI9341_PGAMMA 0xe0 /* Positive Gamma Correction register */
53 #define ILI9341_NGAMMA 0xe1 /* Negative Gamma Correction register */
54 #define ILI9341_DTCA 0xe8 /* Driver timing control A */
55 #define ILI9341_DTCB 0xea /* Driver timing control B */
56 #define ILI9341_POWER_SEQ 0xed /* Power on sequence register */
57 #define ILI9341_3GAMMA_EN 0xf2 /* 3 Gamma enable register */
58 #define ILI9341_INTERFACE 0xf6 /* Interface control register */
59 #define ILI9341_PRC 0xf7 /* Pump ratio control register */
60 #define ILI9341_ETMOD 0xb7 /* Entry mode set */
62 #define ILI9341_MADCTL_BGR BIT(3)
63 #define ILI9341_MADCTL_MV BIT(5)
64 #define ILI9341_MADCTL_MX BIT(6)
65 #define ILI9341_MADCTL_MY BIT(7)
67 #define ILI9341_POWER_B_LEN 3
68 #define ILI9341_POWER_SEQ_LEN 4
69 #define ILI9341_DTCA_LEN 3
70 #define ILI9341_DTCB_LEN 2
71 #define ILI9341_POWER_A_LEN 5
72 #define ILI9341_DFC_1_LEN 2
73 #define ILI9341_FRC_LEN 2
74 #define ILI9341_VCOM_1_LEN 2
75 #define ILI9341_DFC_2_LEN 4
76 #define ILI9341_COLUMN_ADDR_LEN 4
77 #define ILI9341_PAGE_ADDR_LEN 4
78 #define ILI9341_INTERFACE_LEN 3
79 #define ILI9341_PGAMMA_LEN 15
80 #define ILI9341_NGAMMA_LEN 15
81 #define ILI9341_CA_LEN 3
83 #define ILI9341_PIXEL_DPI_16_BITS (BIT(6) | BIT(4))
84 #define ILI9341_PIXEL_DPI_18_BITS (BIT(6) | BIT(5))
85 #define ILI9341_GAMMA_CURVE_1 BIT(0)
86 #define ILI9341_IF_WE_MODE BIT(0)
87 #define ILI9341_IF_BIG_ENDIAN 0x00
88 #define ILI9341_IF_DM_RGB BIT(2)
89 #define ILI9341_IF_DM_INTERNAL 0x00
90 #define ILI9341_IF_DM_VSYNC BIT(3)
91 #define ILI9341_IF_RM_RGB BIT(1)
92 #define ILI9341_IF_RIM_RGB 0x00
94 #define ILI9341_COLUMN_ADDR 0x00ef
95 #define ILI9341_PAGE_ADDR 0x013f
97 #define ILI9341_RGB_EPL BIT(0)
98 #define ILI9341_RGB_DPL BIT(1)
99 #define ILI9341_RGB_HSPL BIT(2)
100 #define ILI9341_RGB_VSPL BIT(3)
101 #define ILI9341_RGB_DE_MODE BIT(6)
102 #define ILI9341_RGB_DISP_PATH_MEM BIT(7)
104 #define ILI9341_DBI_VCOMH_4P6V 0x23
105 #define ILI9341_DBI_PWR_2_DEFAULT 0x10
106 #define ILI9341_DBI_PRC_NORMAL 0x20
107 #define ILI9341_DBI_VCOM_1_VMH_4P25V 0x3e
108 #define ILI9341_DBI_VCOM_1_VML_1P5V 0x28
109 #define ILI9341_DBI_VCOM_2_DEC_58 0x86
110 #define ILI9341_DBI_FRC_DIVA 0x00
111 #define ILI9341_DBI_FRC_RTNA 0x1b
112 #define ILI9341_DBI_EMS_GAS BIT(0)
113 #define ILI9341_DBI_EMS_DTS BIT(1)
114 #define ILI9341_DBI_EMS_GON BIT(2)
116 /* struct ili9341_config - the system specific ILI9341 configuration */
117 struct ili9341_config {
119 /* mode: the drm display mode */
120 const struct drm_display_mode mode;
121 /* ca: TODO: need comments for this register */
122 u8 ca[ILI9341_CA_LEN];
123 /* power_b: TODO: need comments for this register */
124 u8 power_b[ILI9341_POWER_B_LEN];
125 /* power_seq: TODO: need comments for this register */
126 u8 power_seq[ILI9341_POWER_SEQ_LEN];
127 /* dtca: TODO: need comments for this register */
128 u8 dtca[ILI9341_DTCA_LEN];
129 /* dtcb: TODO: need comments for this register */
130 u8 dtcb[ILI9341_DTCB_LEN];
131 /* power_a: TODO: need comments for this register */
132 u8 power_a[ILI9341_POWER_A_LEN];
133 /* frc: Frame Rate Control (In Normal Mode/Full Colors) (B1h) */
134 u8 frc[ILI9341_FRC_LEN];
135 /* prc: TODO: need comments for this register */
137 /* dfc_1: B6h DISCTRL (Display Function Control) */
138 u8 dfc_1[ILI9341_DFC_1_LEN];
139 /* power_1: Power Control 1 (C0h) */
141 /* power_2: Power Control 2 (C1h) */
143 /* vcom_1: VCOM Control 1(C5h) */
144 u8 vcom_1[ILI9341_VCOM_1_LEN];
145 /* vcom_2: VCOM Control 2(C7h) */
147 /* address_mode: Memory Access Control (36h) */
149 /* g3amma_en: TODO: need comments for this register */
151 /* rgb_interface: RGB Interface Signal Control (B0h) */
153 /* dfc_2: refer to dfc_1 */
154 u8 dfc_2[ILI9341_DFC_2_LEN];
155 /* column_addr: Column Address Set (2Ah) */
156 u8 column_addr[ILI9341_COLUMN_ADDR_LEN];
157 /* page_addr: Page Address Set (2Bh) */
158 u8 page_addr[ILI9341_PAGE_ADDR_LEN];
159 /* interface: Interface Control (F6h) */
160 u8 interface[ILI9341_INTERFACE_LEN];
162 * pixel_format: This command sets the pixel format for the RGB
167 * gamma_curve: This command is used to select the desired Gamma
171 /* pgamma: Positive Gamma Correction (E0h) */
172 u8 pgamma[ILI9341_PGAMMA_LEN];
173 /* ngamma: Negative Gamma Correction (E1h) */
174 u8 ngamma[ILI9341_NGAMMA_LEN];
179 const struct ili9341_config *conf;
180 struct drm_panel panel;
181 struct gpio_desc *reset_gpio;
182 struct gpio_desc *dc_gpio;
183 struct mipi_dbi *dbi;
185 struct regulator_bulk_data supplies[3];
189 * The Stm32f429-disco board has a panel ili9341 connected to ltdc controller
191 static const struct ili9341_config ili9341_stm32f429_disco_data = {
192 .max_spi_speed = 10000000,
196 .hsync_start = 240 + 10,/* hfp 10 */
197 .hsync_end = 240 + 10 + 10,/* hsync 10 */
198 .htotal = 240 + 10 + 10 + 20,/* hbp 20 */
200 .vsync_start = 320 + 4,/* vfp 4 */
201 .vsync_end = 320 + 4 + 2,/* vsync 2 */
202 .vtotal = 320 + 4 + 2 + 2,/* vbp 2 */
206 .type = DRM_MODE_TYPE_DRIVER | DRM_MODE_TYPE_PREFERRED,
208 .ca = {0xc3, 0x08, 0x50},
209 .power_b = {0x00, 0xc1, 0x30},
210 .power_seq = {0x64, 0x03, 0x12, 0x81},
211 .dtca = {0x85, 0x00, 0x78},
212 .power_a = {0x39, 0x2c, 0x00, 0x34, 0x02},
214 .dtcb = {0x00, 0x00},
215 /* 0x00 fosc, 0x1b 70hz */
218 * 0x0a Interval scan, AGND AGND AGND AGND
219 * 0xa2 Normally white, G1 -> G320, S720 -> S1,
220 * Scan Cycle 5 frames,85ms
222 .dfc_1 = {0x0a, 0xa2},
225 /* 0x10 AVDD=vci*2, VGH=vci*7, VGL=-vci*4 */
227 /* 0x45 VCOMH 4.425v, 0x15 VCOML -1.975*/
228 .vcom_1 = {0x45, 0x15},
229 /* 0x90 offset voltage, VMH-48, VML-48 */
232 * 0xc8 Row Address Order, Column Address Order
235 .address_mode = 0xc8,
239 * Display Data Path: Memory
241 * DOTCLK polarity set (data fetched at the falling time)
243 .rgb_interface = ILI9341_RGB_DISP_PATH_MEM |
244 ILI9341_RGB_DE_MODE |
248 * Gate outputs in non-display area: Interval scan
249 * Determine source/VCOM output in a non-display area in the partial
250 * display mode: AGND AGND AGND AGND
253 * Scan Cycle: 15 frames
255 * Liquid crystal type: Normally white
256 * Gate Output Scan Direction: G1 -> G320
257 * Source Output Scan Direction: S720 -> S1
260 * LCD Driver Line: 320 lines
265 .dfc_2 = {0x0a, 0xa7, 0x27, 0x04},
266 /* column address: 240 */
267 .column_addr = {0x00, 0x00, (ILI9341_COLUMN_ADDR >> 4) & 0xff,
268 ILI9341_COLUMN_ADDR & 0xff},
269 /* page address: 320 */
270 .page_addr = {0x00, 0x00, (ILI9341_PAGE_ADDR >> 4) & 0xff,
271 ILI9341_PAGE_ADDR & 0xff},
273 * Memory write control: When the transfer number of data exceeds
274 * (EC-SC+1)*(EP-SP+1), the column and page number will be
275 * reset, and the exceeding data will be written into the following
277 * Display Operation Mode: RGB Interface Mode
278 * Interface for RAM Access: RGB interface
279 * 16- bit RGB interface (1 transfer/pixel)
281 .interface = {ILI9341_IF_WE_MODE, 0x00,
282 ILI9341_IF_DM_RGB | ILI9341_IF_RM_RGB},
283 /* DPI: 16 bits / pixel */
284 .pixel_format = ILI9341_PIXEL_DPI_16_BITS,
285 /* Curve Selected: Gamma curve 1 (G2.2) */
286 .gamma_curve = ILI9341_GAMMA_CURVE_1,
287 .pgamma = {0x0f, 0x29, 0x24, 0x0c, 0x0e,
288 0x09, 0x4e, 0x78, 0x3c, 0x09,
289 0x13, 0x05, 0x17, 0x11, 0x00},
290 .ngamma = {0x00, 0x16, 0x1b, 0x04, 0x11,
291 0x07, 0x31, 0x33, 0x42, 0x05,
292 0x0c, 0x0a, 0x28, 0x2f, 0x0f},
295 static inline struct ili9341 *panel_to_ili9341(struct drm_panel *panel)
297 return container_of(panel, struct ili9341, panel);
300 static void ili9341_dpi_init(struct ili9341 *ili)
302 struct device *dev = (&ili->panel)->dev;
303 struct mipi_dbi *dbi = ili->dbi;
304 struct ili9341_config *cfg = (struct ili9341_config *)ili->conf;
307 mipi_dbi_command_stackbuf(dbi, 0xca, cfg->ca, ILI9341_CA_LEN);
308 mipi_dbi_command_stackbuf(dbi, ILI9341_POWERB, cfg->power_b,
309 ILI9341_POWER_B_LEN);
310 mipi_dbi_command_stackbuf(dbi, ILI9341_POWER_SEQ, cfg->power_seq,
311 ILI9341_POWER_SEQ_LEN);
312 mipi_dbi_command_stackbuf(dbi, ILI9341_DTCA, cfg->dtca,
314 mipi_dbi_command_stackbuf(dbi, ILI9341_POWERA, cfg->power_a,
315 ILI9341_POWER_A_LEN);
316 mipi_dbi_command(ili->dbi, ILI9341_PRC, cfg->prc);
317 mipi_dbi_command_stackbuf(dbi, ILI9341_DTCB, cfg->dtcb,
319 mipi_dbi_command_stackbuf(dbi, ILI9341_FRC, cfg->frc, ILI9341_FRC_LEN);
320 mipi_dbi_command_stackbuf(dbi, ILI9341_DFC, cfg->dfc_1,
322 mipi_dbi_command(dbi, ILI9341_POWER1, cfg->power_1);
323 mipi_dbi_command(dbi, ILI9341_POWER2, cfg->power_2);
326 mipi_dbi_command_stackbuf(dbi, ILI9341_VCOM1, cfg->vcom_1,
328 mipi_dbi_command(dbi, ILI9341_VCOM2, cfg->vcom_2);
329 mipi_dbi_command(dbi, MIPI_DCS_SET_ADDRESS_MODE, cfg->address_mode);
332 mipi_dbi_command(dbi, ILI9341_3GAMMA_EN, cfg->g3amma_en);
333 mipi_dbi_command(dbi, ILI9341_RGB_INTERFACE, cfg->rgb_interface);
334 mipi_dbi_command_stackbuf(dbi, ILI9341_DFC, cfg->dfc_2,
337 /* Colomn address set */
338 mipi_dbi_command_stackbuf(dbi, MIPI_DCS_SET_COLUMN_ADDRESS,
339 cfg->column_addr, ILI9341_COLUMN_ADDR_LEN);
341 /* Page address set */
342 mipi_dbi_command_stackbuf(dbi, MIPI_DCS_SET_PAGE_ADDRESS,
343 cfg->page_addr, ILI9341_PAGE_ADDR_LEN);
344 mipi_dbi_command_stackbuf(dbi, ILI9341_INTERFACE, cfg->interface,
345 ILI9341_INTERFACE_LEN);
348 mipi_dbi_command(dbi, MIPI_DCS_SET_PIXEL_FORMAT, cfg->pixel_format);
349 mipi_dbi_command(dbi, MIPI_DCS_WRITE_MEMORY_START);
351 mipi_dbi_command(dbi, MIPI_DCS_SET_GAMMA_CURVE, cfg->gamma_curve);
352 mipi_dbi_command_stackbuf(dbi, ILI9341_PGAMMA, cfg->pgamma,
354 mipi_dbi_command_stackbuf(dbi, ILI9341_NGAMMA, cfg->ngamma,
356 mipi_dbi_command(dbi, MIPI_DCS_EXIT_SLEEP_MODE);
358 mipi_dbi_command(dbi, MIPI_DCS_SET_DISPLAY_ON);
359 mipi_dbi_command(dbi, MIPI_DCS_WRITE_MEMORY_START);
361 dev_info(dev, "Initialized display rgb interface\n");
364 static int ili9341_dpi_power_on(struct ili9341 *ili)
366 struct device *dev = (&ili->panel)->dev;
370 gpiod_set_value(ili->reset_gpio, 1);
373 ret = regulator_bulk_enable(ARRAY_SIZE(ili->supplies),
376 dev_err(dev, "unable to enable vcc\n");
381 /* De-assert RESET */
382 gpiod_set_value(ili->reset_gpio, 0);
388 static int ili9341_dpi_power_off(struct ili9341 *ili)
391 gpiod_set_value(ili->reset_gpio, 1);
394 return regulator_bulk_disable(ARRAY_SIZE(ili->supplies),
398 static int ili9341_dpi_disable(struct drm_panel *panel)
400 struct ili9341 *ili = panel_to_ili9341(panel);
402 mipi_dbi_command(ili->dbi, MIPI_DCS_SET_DISPLAY_OFF);
406 static int ili9341_dpi_unprepare(struct drm_panel *panel)
408 struct ili9341 *ili = panel_to_ili9341(panel);
410 return ili9341_dpi_power_off(ili);
413 static int ili9341_dpi_prepare(struct drm_panel *panel)
415 struct ili9341 *ili = panel_to_ili9341(panel);
418 ret = ili9341_dpi_power_on(ili);
422 ili9341_dpi_init(ili);
427 static int ili9341_dpi_enable(struct drm_panel *panel)
429 struct ili9341 *ili = panel_to_ili9341(panel);
431 mipi_dbi_command(ili->dbi, MIPI_DCS_SET_DISPLAY_ON);
435 static int ili9341_dpi_get_modes(struct drm_panel *panel,
436 struct drm_connector *connector)
438 struct ili9341 *ili = panel_to_ili9341(panel);
439 struct drm_device *drm = connector->dev;
440 struct drm_display_mode *mode;
441 struct drm_display_info *info;
443 info = &connector->display_info;
444 info->width_mm = ili->conf->mode.width_mm;
445 info->height_mm = ili->conf->mode.height_mm;
447 if (ili->conf->rgb_interface & ILI9341_RGB_DPL)
448 info->bus_flags |= DRM_BUS_FLAG_PIXDATA_DRIVE_POSEDGE;
450 info->bus_flags |= DRM_BUS_FLAG_PIXDATA_DRIVE_NEGEDGE;
452 if (ili->conf->rgb_interface & ILI9341_RGB_EPL)
453 info->bus_flags |= DRM_BUS_FLAG_DE_LOW;
455 info->bus_flags |= DRM_BUS_FLAG_DE_HIGH;
457 mode = drm_mode_duplicate(drm, &ili->conf->mode);
459 drm_err(drm, "bad mode or failed to add mode\n");
462 drm_mode_set_name(mode);
464 /* Set up the polarity */
465 if (ili->conf->rgb_interface & ILI9341_RGB_HSPL)
466 mode->flags |= DRM_MODE_FLAG_PHSYNC;
468 mode->flags |= DRM_MODE_FLAG_NHSYNC;
470 if (ili->conf->rgb_interface & ILI9341_RGB_VSPL)
471 mode->flags |= DRM_MODE_FLAG_PVSYNC;
473 mode->flags |= DRM_MODE_FLAG_NVSYNC;
475 drm_mode_probed_add(connector, mode);
477 return 1; /* Number of modes */
480 static const struct drm_panel_funcs ili9341_dpi_funcs = {
481 .disable = ili9341_dpi_disable,
482 .unprepare = ili9341_dpi_unprepare,
483 .prepare = ili9341_dpi_prepare,
484 .enable = ili9341_dpi_enable,
485 .get_modes = ili9341_dpi_get_modes,
488 static void ili9341_dbi_enable(struct drm_simple_display_pipe *pipe,
489 struct drm_crtc_state *crtc_state,
490 struct drm_plane_state *plane_state)
492 struct mipi_dbi_dev *dbidev = drm_to_mipi_dbi_dev(pipe->crtc.dev);
493 struct mipi_dbi *dbi = &dbidev->dbi;
497 if (!drm_dev_enter(pipe->crtc.dev, &idx))
500 ret = mipi_dbi_poweron_conditional_reset(dbidev);
506 mipi_dbi_command(dbi, MIPI_DCS_SET_DISPLAY_OFF);
508 mipi_dbi_command(dbi, ILI9341_POWERB, 0x00, 0xc1, 0x30);
509 mipi_dbi_command(dbi, ILI9341_POWER_SEQ, 0x64, 0x03, 0x12, 0x81);
510 mipi_dbi_command(dbi, ILI9341_DTCA, 0x85, 0x00, 0x78);
511 mipi_dbi_command(dbi, ILI9341_POWERA, 0x39, 0x2c, 0x00, 0x34, 0x02);
512 mipi_dbi_command(dbi, ILI9341_PRC, ILI9341_DBI_PRC_NORMAL);
513 mipi_dbi_command(dbi, ILI9341_DTCB, 0x00, 0x00);
516 mipi_dbi_command(dbi, ILI9341_POWER1, ILI9341_DBI_VCOMH_4P6V);
517 mipi_dbi_command(dbi, ILI9341_POWER2, ILI9341_DBI_PWR_2_DEFAULT);
519 mipi_dbi_command(dbi, ILI9341_VCOM1, ILI9341_DBI_VCOM_1_VMH_4P25V,
520 ILI9341_DBI_VCOM_1_VML_1P5V);
521 mipi_dbi_command(dbi, ILI9341_VCOM2, ILI9341_DBI_VCOM_2_DEC_58);
523 /* Memory Access Control */
524 mipi_dbi_command(dbi, MIPI_DCS_SET_PIXEL_FORMAT,
525 MIPI_DCS_PIXEL_FMT_16BIT);
528 mipi_dbi_command(dbi, ILI9341_FRC, ILI9341_DBI_FRC_DIVA & 0x03,
529 ILI9341_DBI_FRC_RTNA & 0x1f);
532 mipi_dbi_command(dbi, ILI9341_3GAMMA_EN, 0x00);
533 mipi_dbi_command(dbi, MIPI_DCS_SET_GAMMA_CURVE, ILI9341_GAMMA_CURVE_1);
534 mipi_dbi_command(dbi, ILI9341_PGAMMA,
535 0x0f, 0x31, 0x2b, 0x0c, 0x0e, 0x08, 0x4e, 0xf1,
536 0x37, 0x07, 0x10, 0x03, 0x0e, 0x09, 0x00);
537 mipi_dbi_command(dbi, ILI9341_NGAMMA,
538 0x00, 0x0e, 0x14, 0x03, 0x11, 0x07, 0x31, 0xc1,
539 0x48, 0x08, 0x0f, 0x0c, 0x31, 0x36, 0x0f);
542 mipi_dbi_command(dbi, ILI9341_ETMOD, ILI9341_DBI_EMS_GAS |
543 ILI9341_DBI_EMS_DTS |
544 ILI9341_DBI_EMS_GON);
547 mipi_dbi_command(dbi, ILI9341_DFC, 0x08, 0x82, 0x27, 0x00);
548 mipi_dbi_command(dbi, MIPI_DCS_EXIT_SLEEP_MODE);
551 mipi_dbi_command(dbi, MIPI_DCS_SET_DISPLAY_ON);
555 switch (dbidev->rotation) {
557 addr_mode = ILI9341_MADCTL_MX;
560 addr_mode = ILI9341_MADCTL_MV;
563 addr_mode = ILI9341_MADCTL_MY;
566 addr_mode = ILI9341_MADCTL_MV | ILI9341_MADCTL_MY |
571 addr_mode |= ILI9341_MADCTL_BGR;
572 mipi_dbi_command(dbi, MIPI_DCS_SET_ADDRESS_MODE, addr_mode);
573 mipi_dbi_enable_flush(dbidev, crtc_state, plane_state);
574 drm_info(&dbidev->drm, "Initialized display serial interface\n");
579 static const struct drm_simple_display_pipe_funcs ili9341_dbi_funcs = {
580 DRM_MIPI_DBI_SIMPLE_DISPLAY_PIPE_FUNCS(ili9341_dbi_enable),
583 static const struct drm_display_mode ili9341_dbi_mode = {
584 DRM_SIMPLE_MODE(240, 320, 37, 49),
587 DEFINE_DRM_GEM_DMA_FOPS(ili9341_dbi_fops);
589 static struct drm_driver ili9341_dbi_driver = {
590 .driver_features = DRIVER_GEM | DRIVER_MODESET | DRIVER_ATOMIC,
591 .fops = &ili9341_dbi_fops,
592 DRM_GEM_DMA_DRIVER_OPS_VMAP,
593 .debugfs_init = mipi_dbi_debugfs_init,
595 .desc = "Ilitek ILI9341",
601 static int ili9341_dbi_probe(struct spi_device *spi, struct gpio_desc *dc,
602 struct gpio_desc *reset)
604 struct device *dev = &spi->dev;
605 struct mipi_dbi_dev *dbidev;
606 struct mipi_dbi *dbi;
607 struct drm_device *drm;
608 struct regulator *vcc;
612 vcc = devm_regulator_get_optional(dev, "vcc");
614 dev_err(dev, "get optional vcc failed\n");
618 dbidev = devm_drm_dev_alloc(dev, &ili9341_dbi_driver,
619 struct mipi_dbi_dev, drm);
621 return PTR_ERR(dbidev);
626 dbidev->regulator = vcc;
628 drm_mode_config_init(drm);
630 dbidev->backlight = devm_of_find_backlight(dev);
631 if (IS_ERR(dbidev->backlight))
632 return PTR_ERR(dbidev->backlight);
634 device_property_read_u32(dev, "rotation", &rotation);
636 ret = mipi_dbi_spi_init(spi, dbi, dc);
640 ret = mipi_dbi_dev_init(dbidev, &ili9341_dbi_funcs,
641 &ili9341_dbi_mode, rotation);
645 drm_mode_config_reset(drm);
647 ret = drm_dev_register(drm, 0);
651 spi_set_drvdata(spi, drm);
653 drm_fbdev_generic_setup(drm, 0);
658 static int ili9341_dpi_probe(struct spi_device *spi, struct gpio_desc *dc,
659 struct gpio_desc *reset)
661 struct device *dev = &spi->dev;
665 ili = devm_kzalloc(dev, sizeof(struct ili9341), GFP_KERNEL);
669 ili->dbi = devm_kzalloc(dev, sizeof(struct mipi_dbi),
674 ili->supplies[0].supply = "vci";
675 ili->supplies[1].supply = "vddi";
676 ili->supplies[2].supply = "vddi-led";
677 ret = devm_regulator_bulk_get(dev, ARRAY_SIZE(ili->supplies),
680 dev_err(dev, "failed to get regulators: %d\n", ret);
684 ret = mipi_dbi_spi_init(spi, ili->dbi, dc);
688 spi_set_drvdata(spi, ili);
689 ili->reset_gpio = reset;
691 * Every new incarnation of this display must have a unique
692 * data entry for the system in this driver.
694 ili->conf = of_device_get_match_data(dev);
696 dev_err(dev, "missing device configuration\n");
700 ili->max_spi_speed = ili->conf->max_spi_speed;
701 drm_panel_init(&ili->panel, dev, &ili9341_dpi_funcs,
702 DRM_MODE_CONNECTOR_DPI);
703 drm_panel_add(&ili->panel);
708 static int ili9341_probe(struct spi_device *spi)
710 struct device *dev = &spi->dev;
711 struct gpio_desc *dc;
712 struct gpio_desc *reset;
713 const struct spi_device_id *id = spi_get_device_id(spi);
715 reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_HIGH);
717 dev_err(dev, "Failed to get gpio 'reset'\n");
719 dc = devm_gpiod_get_optional(dev, "dc", GPIOD_OUT_LOW);
721 dev_err(dev, "Failed to get gpio 'dc'\n");
723 if (!strcmp(id->name, "sf-tc240t-9370-t"))
724 return ili9341_dpi_probe(spi, dc, reset);
725 else if (!strcmp(id->name, "yx240qv29"))
726 return ili9341_dbi_probe(spi, dc, reset);
731 static void ili9341_remove(struct spi_device *spi)
733 const struct spi_device_id *id = spi_get_device_id(spi);
734 struct ili9341 *ili = spi_get_drvdata(spi);
735 struct drm_device *drm = spi_get_drvdata(spi);
737 if (!strcmp(id->name, "sf-tc240t-9370-t")) {
738 ili9341_dpi_power_off(ili);
739 drm_panel_remove(&ili->panel);
740 } else if (!strcmp(id->name, "yx240qv29")) {
742 drm_atomic_helper_shutdown(drm);
746 static void ili9341_shutdown(struct spi_device *spi)
748 const struct spi_device_id *id = spi_get_device_id(spi);
750 if (!strcmp(id->name, "yx240qv29"))
751 drm_atomic_helper_shutdown(spi_get_drvdata(spi));
754 static const struct of_device_id ili9341_of_match[] = {
756 .compatible = "st,sf-tc240t-9370-t",
757 .data = &ili9341_stm32f429_disco_data,
760 /* porting from tiny/ili9341.c
761 * for original mipi dbi compitable
763 .compatible = "adafruit,yx240qv29",
768 MODULE_DEVICE_TABLE(of, ili9341_of_match);
770 static const struct spi_device_id ili9341_id[] = {
772 { "sf-tc240t-9370-t", 0 },
775 MODULE_DEVICE_TABLE(spi, ili9341_id);
777 static struct spi_driver ili9341_driver = {
778 .probe = ili9341_probe,
779 .remove = ili9341_remove,
780 .shutdown = ili9341_shutdown,
781 .id_table = ili9341_id,
783 .name = "panel-ilitek-ili9341",
784 .of_match_table = ili9341_of_match,
787 module_spi_driver(ili9341_driver);
790 MODULE_DESCRIPTION("ILI9341 LCD panel driver");
791 MODULE_LICENSE("GPL v2");