2 * Copyright (c) 2017, Fuzhou Rockchip Electronics Co., Ltd
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
10 #include <linux/backlight.h>
11 #include <linux/gpio/consumer.h>
12 #include <linux/module.h>
14 #include <linux/of_device.h>
15 #include <linux/regulator/consumer.h>
18 #include <drm/drm_crtc.h>
19 #include <drm/drm_mipi_dsi.h>
20 #include <drm/drm_panel.h>
22 #include <video/mipi_display.h>
24 struct panel_init_cmd
{
29 #define _INIT_CMD(...) { \
30 .len = sizeof((char[]){__VA_ARGS__}), \
31 .data = (char[]){__VA_ARGS__} }
34 const struct drm_display_mode
*mode
;
42 enum mipi_dsi_pixel_format format
;
43 const struct panel_init_cmd
*init_cmds
;
45 const char * const *supply_names
;
46 unsigned int num_supplies
;
47 unsigned int sleep_mode_delay
;
48 unsigned int power_down_delay
;
51 struct innolux_panel
{
52 struct drm_panel base
;
53 struct mipi_dsi_device
*link
;
54 const struct panel_desc
*desc
;
56 struct backlight_device
*backlight
;
57 struct regulator_bulk_data
*supplies
;
58 unsigned int num_supplies
;
59 struct gpio_desc
*enable_gpio
;
65 static inline struct innolux_panel
*to_innolux_panel(struct drm_panel
*panel
)
67 return container_of(panel
, struct innolux_panel
, base
);
70 static int innolux_panel_disable(struct drm_panel
*panel
)
72 struct innolux_panel
*innolux
= to_innolux_panel(panel
);
74 if (!innolux
->enabled
)
77 backlight_disable(innolux
->backlight
);
79 innolux
->enabled
= false;
84 static int innolux_panel_unprepare(struct drm_panel
*panel
)
86 struct innolux_panel
*innolux
= to_innolux_panel(panel
);
89 if (!innolux
->prepared
)
92 err
= mipi_dsi_dcs_set_display_off(innolux
->link
);
94 DRM_DEV_ERROR(panel
->dev
, "failed to set display off: %d\n",
97 err
= mipi_dsi_dcs_enter_sleep_mode(innolux
->link
);
99 DRM_DEV_ERROR(panel
->dev
, "failed to enter sleep mode: %d\n",
104 if (innolux
->desc
->sleep_mode_delay
)
105 msleep(innolux
->desc
->sleep_mode_delay
);
107 gpiod_set_value_cansleep(innolux
->enable_gpio
, 0);
109 if (innolux
->desc
->power_down_delay
)
110 msleep(innolux
->desc
->power_down_delay
);
112 err
= regulator_bulk_disable(innolux
->desc
->num_supplies
,
117 innolux
->prepared
= false;
122 static int innolux_panel_prepare(struct drm_panel
*panel
)
124 struct innolux_panel
*innolux
= to_innolux_panel(panel
);
127 if (innolux
->prepared
)
130 gpiod_set_value_cansleep(innolux
->enable_gpio
, 0);
132 err
= regulator_bulk_enable(innolux
->desc
->num_supplies
,
137 /* p079zca: t2 (20ms), p097pfg: t4 (15ms) */
138 usleep_range(20000, 21000);
140 gpiod_set_value_cansleep(innolux
->enable_gpio
, 1);
142 /* p079zca: t4, p097pfg: t5 */
143 usleep_range(20000, 21000);
145 if (innolux
->desc
->init_cmds
) {
146 const struct panel_init_cmd
*cmds
=
147 innolux
->desc
->init_cmds
;
150 for (i
= 0; cmds
[i
].len
!= 0; i
++) {
151 const struct panel_init_cmd
*cmd
= &cmds
[i
];
153 err
= mipi_dsi_generic_write(innolux
->link
, cmd
->data
,
157 "failed to write command %u\n", i
);
162 * Included by random guessing, because without this
163 * (or at least, some delay), the panel sometimes
164 * didn't appear to pick up the command sequence.
166 err
= mipi_dsi_dcs_nop(innolux
->link
);
169 "failed to send DCS nop: %d\n", err
);
175 err
= mipi_dsi_dcs_exit_sleep_mode(innolux
->link
);
177 DRM_DEV_ERROR(panel
->dev
, "failed to exit sleep mode: %d\n",
182 /* T6: 120ms - 1000ms*/
185 err
= mipi_dsi_dcs_set_display_on(innolux
->link
);
187 DRM_DEV_ERROR(panel
->dev
, "failed to set display on: %d\n",
193 usleep_range(5000, 6000);
195 innolux
->prepared
= true;
200 gpiod_set_value_cansleep(innolux
->enable_gpio
, 0);
201 regulator_bulk_disable(innolux
->desc
->num_supplies
, innolux
->supplies
);
206 static int innolux_panel_enable(struct drm_panel
*panel
)
208 struct innolux_panel
*innolux
= to_innolux_panel(panel
);
211 if (innolux
->enabled
)
214 ret
= backlight_enable(innolux
->backlight
);
216 DRM_DEV_ERROR(panel
->drm
->dev
,
217 "Failed to enable backlight %d\n", ret
);
221 innolux
->enabled
= true;
226 static const char * const innolux_p079zca_supply_names
[] = {
230 static const struct drm_display_mode innolux_p079zca_mode
= {
233 .hsync_start
= 768 + 40,
234 .hsync_end
= 768 + 40 + 40,
235 .htotal
= 768 + 40 + 40 + 40,
237 .vsync_start
= 1024 + 20,
238 .vsync_end
= 1024 + 20 + 4,
239 .vtotal
= 1024 + 20 + 4 + 20,
243 static const struct panel_desc innolux_p079zca_panel_desc
= {
244 .mode
= &innolux_p079zca_mode
,
250 .flags
= MIPI_DSI_MODE_VIDEO
| MIPI_DSI_MODE_VIDEO_SYNC_PULSE
|
252 .format
= MIPI_DSI_FMT_RGB888
,
254 .supply_names
= innolux_p079zca_supply_names
,
255 .num_supplies
= ARRAY_SIZE(innolux_p079zca_supply_names
),
256 .power_down_delay
= 80, /* T8: 80ms - 1000ms */
259 static const char * const innolux_p097pfg_supply_names
[] = {
264 static const struct drm_display_mode innolux_p097pfg_mode
= {
267 .hsync_start
= 1536 + 100,
268 .hsync_end
= 1536 + 100 + 24,
269 .htotal
= 1536 + 100 + 24 + 100,
271 .vsync_start
= 2048 + 100,
272 .vsync_end
= 2048 + 100 + 2,
273 .vtotal
= 2048 + 100 + 2 + 18,
278 * Display manufacturer failed to provide init sequencing according to
279 * https://chromium-review.googlesource.com/c/chromiumos/third_party/coreboot/+/892065/
280 * so the init sequence stems from a register dump of a working panel.
282 static const struct panel_init_cmd innolux_p097pfg_init_cmds
[] = {
284 _INIT_CMD(0xF0, 0x55, 0xAA, 0x52, 0x08, 0x00),
285 _INIT_CMD(0xB1, 0xE8, 0x11),
286 _INIT_CMD(0xB2, 0x25, 0x02),
287 _INIT_CMD(0xB5, 0x08, 0x00),
288 _INIT_CMD(0xBC, 0x0F, 0x00),
289 _INIT_CMD(0xB8, 0x03, 0x06, 0x00, 0x00),
290 _INIT_CMD(0xBD, 0x01, 0x90, 0x14, 0x14),
291 _INIT_CMD(0x6F, 0x01),
292 _INIT_CMD(0xC0, 0x03),
293 _INIT_CMD(0x6F, 0x02),
294 _INIT_CMD(0xC1, 0x0D),
295 _INIT_CMD(0xD9, 0x01, 0x09, 0x70),
296 _INIT_CMD(0xC5, 0x12, 0x21, 0x00),
297 _INIT_CMD(0xBB, 0x93, 0x93),
300 _INIT_CMD(0xF0, 0x55, 0xAA, 0x52, 0x08, 0x01),
301 _INIT_CMD(0xB3, 0x3C, 0x3C),
302 _INIT_CMD(0xB4, 0x0F, 0x0F),
303 _INIT_CMD(0xB9, 0x45, 0x45),
304 _INIT_CMD(0xBA, 0x14, 0x14),
305 _INIT_CMD(0xCA, 0x02),
306 _INIT_CMD(0xCE, 0x04),
307 _INIT_CMD(0xC3, 0x9B, 0x9B),
308 _INIT_CMD(0xD8, 0xC0, 0x03),
309 _INIT_CMD(0xBC, 0x82, 0x01),
310 _INIT_CMD(0xBD, 0x9E, 0x01),
313 _INIT_CMD(0xF0, 0x55, 0xAA, 0x52, 0x08, 0x02),
314 _INIT_CMD(0xB0, 0x82),
315 _INIT_CMD(0xD1, 0x00, 0x00, 0x00, 0x3E, 0x00, 0x82, 0x00, 0xA5,
316 0x00, 0xC1, 0x00, 0xEA, 0x01, 0x0D, 0x01, 0x40),
317 _INIT_CMD(0xD2, 0x01, 0x6A, 0x01, 0xA8, 0x01, 0xDC, 0x02, 0x29,
318 0x02, 0x67, 0x02, 0x68, 0x02, 0xA8, 0x02, 0xF0),
319 _INIT_CMD(0xD3, 0x03, 0x19, 0x03, 0x49, 0x03, 0x67, 0x03, 0x8C,
320 0x03, 0xA6, 0x03, 0xC7, 0x03, 0xDE, 0x03, 0xEC),
321 _INIT_CMD(0xD4, 0x03, 0xFF, 0x03, 0xFF),
322 _INIT_CMD(0xE0, 0x00, 0x00, 0x00, 0x86, 0x00, 0xC5, 0x00, 0xE5,
323 0x00, 0xFF, 0x01, 0x26, 0x01, 0x45, 0x01, 0x75),
324 _INIT_CMD(0xE1, 0x01, 0x9C, 0x01, 0xD5, 0x02, 0x05, 0x02, 0x4D,
325 0x02, 0x86, 0x02, 0x87, 0x02, 0xC3, 0x03, 0x03),
326 _INIT_CMD(0xE2, 0x03, 0x2A, 0x03, 0x56, 0x03, 0x72, 0x03, 0x94,
327 0x03, 0xAC, 0x03, 0xCB, 0x03, 0xE0, 0x03, 0xED),
328 _INIT_CMD(0xE3, 0x03, 0xFF, 0x03, 0xFF),
331 _INIT_CMD(0xF0, 0x55, 0xAA, 0x52, 0x08, 0x03),
332 _INIT_CMD(0xB0, 0x00, 0x00, 0x00, 0x00),
333 _INIT_CMD(0xB1, 0x00, 0x00, 0x00, 0x00),
334 _INIT_CMD(0xB2, 0x00, 0x00, 0x06, 0x04, 0x01, 0x40, 0x85),
335 _INIT_CMD(0xB3, 0x10, 0x07, 0xFC, 0x04, 0x01, 0x40, 0x80),
336 _INIT_CMD(0xB6, 0xF0, 0x08, 0x00, 0x04, 0x00, 0x00, 0x00, 0x01,
338 _INIT_CMD(0xBA, 0xC5, 0x07, 0x00, 0x04, 0x11, 0x25, 0x8C),
339 _INIT_CMD(0xBB, 0xC5, 0x07, 0x00, 0x03, 0x11, 0x25, 0x8C),
340 _INIT_CMD(0xC0, 0x00, 0x3C, 0x00, 0x00, 0x00, 0x80, 0x80),
341 _INIT_CMD(0xC1, 0x00, 0x3C, 0x00, 0x00, 0x00, 0x80, 0x80),
342 _INIT_CMD(0xC4, 0x00, 0x00),
343 _INIT_CMD(0xEF, 0x41),
346 _INIT_CMD(0xF0, 0x55, 0xAA, 0x52, 0x08, 0x04),
347 _INIT_CMD(0xEC, 0x4C),
350 _INIT_CMD(0xF0, 0x55, 0xAA, 0x52, 0x08, 0x05),
351 _INIT_CMD(0xB0, 0x13, 0x03, 0x03, 0x01),
352 _INIT_CMD(0xB1, 0x30, 0x00),
353 _INIT_CMD(0xB2, 0x02, 0x02, 0x00),
354 _INIT_CMD(0xB3, 0x82, 0x23, 0x82, 0x9D),
355 _INIT_CMD(0xB4, 0xC5, 0x75, 0x24, 0x57),
356 _INIT_CMD(0xB5, 0x00, 0xD4, 0x72, 0x11, 0x11, 0xAB, 0x0A),
357 _INIT_CMD(0xB6, 0x00, 0x00, 0xD5, 0x72, 0x24, 0x56),
358 _INIT_CMD(0xB7, 0x5C, 0xDC, 0x5C, 0x5C),
359 _INIT_CMD(0xB9, 0x0C, 0x00, 0x00, 0x01, 0x00),
360 _INIT_CMD(0xC0, 0x75, 0x11, 0x11, 0x54, 0x05),
361 _INIT_CMD(0xC6, 0x00, 0x00, 0x00, 0x00),
362 _INIT_CMD(0xD0, 0x00, 0x48, 0x08, 0x00, 0x00),
363 _INIT_CMD(0xD1, 0x00, 0x48, 0x09, 0x00, 0x00),
366 _INIT_CMD(0xF0, 0x55, 0xAA, 0x52, 0x08, 0x06),
367 _INIT_CMD(0xB0, 0x02, 0x32, 0x32, 0x08, 0x2F),
368 _INIT_CMD(0xB1, 0x2E, 0x15, 0x14, 0x13, 0x12),
369 _INIT_CMD(0xB2, 0x11, 0x10, 0x00, 0x3D, 0x3D),
370 _INIT_CMD(0xB3, 0x3D, 0x3D, 0x3D, 0x3D, 0x3D),
371 _INIT_CMD(0xB4, 0x3D, 0x32),
372 _INIT_CMD(0xB5, 0x03, 0x32, 0x32, 0x09, 0x2F),
373 _INIT_CMD(0xB6, 0x2E, 0x1B, 0x1A, 0x19, 0x18),
374 _INIT_CMD(0xB7, 0x17, 0x16, 0x01, 0x3D, 0x3D),
375 _INIT_CMD(0xB8, 0x3D, 0x3D, 0x3D, 0x3D, 0x3D),
376 _INIT_CMD(0xB9, 0x3D, 0x32),
377 _INIT_CMD(0xC0, 0x01, 0x32, 0x32, 0x09, 0x2F),
378 _INIT_CMD(0xC1, 0x2E, 0x1A, 0x1B, 0x16, 0x17),
379 _INIT_CMD(0xC2, 0x18, 0x19, 0x03, 0x3D, 0x3D),
380 _INIT_CMD(0xC3, 0x3D, 0x3D, 0x3D, 0x3D, 0x3D),
381 _INIT_CMD(0xC4, 0x3D, 0x32),
382 _INIT_CMD(0xC5, 0x00, 0x32, 0x32, 0x08, 0x2F),
383 _INIT_CMD(0xC6, 0x2E, 0x14, 0x15, 0x10, 0x11),
384 _INIT_CMD(0xC7, 0x12, 0x13, 0x02, 0x3D, 0x3D),
385 _INIT_CMD(0xC8, 0x3D, 0x3D, 0x3D, 0x3D, 0x3D),
386 _INIT_CMD(0xC9, 0x3D, 0x32),
391 static const struct panel_desc innolux_p097pfg_panel_desc
= {
392 .mode
= &innolux_p097pfg_mode
,
398 .flags
= MIPI_DSI_MODE_VIDEO
| MIPI_DSI_MODE_VIDEO_SYNC_PULSE
|
400 .format
= MIPI_DSI_FMT_RGB888
,
401 .init_cmds
= innolux_p097pfg_init_cmds
,
403 .supply_names
= innolux_p097pfg_supply_names
,
404 .num_supplies
= ARRAY_SIZE(innolux_p097pfg_supply_names
),
405 .sleep_mode_delay
= 100, /* T15 */
408 static int innolux_panel_get_modes(struct drm_panel
*panel
)
410 struct innolux_panel
*innolux
= to_innolux_panel(panel
);
411 const struct drm_display_mode
*m
= innolux
->desc
->mode
;
412 struct drm_display_mode
*mode
;
414 mode
= drm_mode_duplicate(panel
->drm
, m
);
416 DRM_DEV_ERROR(panel
->drm
->dev
, "failed to add mode %ux%ux@%u\n",
417 m
->hdisplay
, m
->vdisplay
, m
->vrefresh
);
421 drm_mode_set_name(mode
);
423 drm_mode_probed_add(panel
->connector
, mode
);
425 panel
->connector
->display_info
.width_mm
=
426 innolux
->desc
->size
.width
;
427 panel
->connector
->display_info
.height_mm
=
428 innolux
->desc
->size
.height
;
429 panel
->connector
->display_info
.bpc
= innolux
->desc
->bpc
;
434 static const struct drm_panel_funcs innolux_panel_funcs
= {
435 .disable
= innolux_panel_disable
,
436 .unprepare
= innolux_panel_unprepare
,
437 .prepare
= innolux_panel_prepare
,
438 .enable
= innolux_panel_enable
,
439 .get_modes
= innolux_panel_get_modes
,
442 static const struct of_device_id innolux_of_match
[] = {
443 { .compatible
= "innolux,p079zca",
444 .data
= &innolux_p079zca_panel_desc
446 { .compatible
= "innolux,p097pfg",
447 .data
= &innolux_p097pfg_panel_desc
451 MODULE_DEVICE_TABLE(of
, innolux_of_match
);
453 static int innolux_panel_add(struct mipi_dsi_device
*dsi
,
454 const struct panel_desc
*desc
)
456 struct innolux_panel
*innolux
;
457 struct device
*dev
= &dsi
->dev
;
460 innolux
= devm_kzalloc(dev
, sizeof(*innolux
), GFP_KERNEL
);
464 innolux
->desc
= desc
;
466 innolux
->supplies
= devm_kcalloc(dev
, desc
->num_supplies
,
467 sizeof(*innolux
->supplies
),
469 if (!innolux
->supplies
)
472 for (i
= 0; i
< desc
->num_supplies
; i
++)
473 innolux
->supplies
[i
].supply
= desc
->supply_names
[i
];
475 err
= devm_regulator_bulk_get(dev
, desc
->num_supplies
,
480 innolux
->enable_gpio
= devm_gpiod_get_optional(dev
, "enable",
482 if (IS_ERR(innolux
->enable_gpio
)) {
483 err
= PTR_ERR(innolux
->enable_gpio
);
484 dev_dbg(dev
, "failed to get enable gpio: %d\n", err
);
485 innolux
->enable_gpio
= NULL
;
488 innolux
->backlight
= devm_of_find_backlight(dev
);
489 if (IS_ERR(innolux
->backlight
))
490 return PTR_ERR(innolux
->backlight
);
492 drm_panel_init(&innolux
->base
);
493 innolux
->base
.funcs
= &innolux_panel_funcs
;
494 innolux
->base
.dev
= dev
;
496 err
= drm_panel_add(&innolux
->base
);
500 mipi_dsi_set_drvdata(dsi
, innolux
);
506 static void innolux_panel_del(struct innolux_panel
*innolux
)
508 drm_panel_remove(&innolux
->base
);
511 static int innolux_panel_probe(struct mipi_dsi_device
*dsi
)
513 const struct panel_desc
*desc
;
516 desc
= of_device_get_match_data(&dsi
->dev
);
517 dsi
->mode_flags
= desc
->flags
;
518 dsi
->format
= desc
->format
;
519 dsi
->lanes
= desc
->lanes
;
521 err
= innolux_panel_add(dsi
, desc
);
525 return mipi_dsi_attach(dsi
);
528 static int innolux_panel_remove(struct mipi_dsi_device
*dsi
)
530 struct innolux_panel
*innolux
= mipi_dsi_get_drvdata(dsi
);
533 err
= innolux_panel_unprepare(&innolux
->base
);
535 DRM_DEV_ERROR(&dsi
->dev
, "failed to unprepare panel: %d\n",
538 err
= innolux_panel_disable(&innolux
->base
);
540 DRM_DEV_ERROR(&dsi
->dev
, "failed to disable panel: %d\n", err
);
542 err
= mipi_dsi_detach(dsi
);
544 DRM_DEV_ERROR(&dsi
->dev
, "failed to detach from DSI host: %d\n",
547 innolux_panel_del(innolux
);
552 static void innolux_panel_shutdown(struct mipi_dsi_device
*dsi
)
554 struct innolux_panel
*innolux
= mipi_dsi_get_drvdata(dsi
);
556 innolux_panel_unprepare(&innolux
->base
);
557 innolux_panel_disable(&innolux
->base
);
560 static struct mipi_dsi_driver innolux_panel_driver
= {
562 .name
= "panel-innolux-p079zca",
563 .of_match_table
= innolux_of_match
,
565 .probe
= innolux_panel_probe
,
566 .remove
= innolux_panel_remove
,
567 .shutdown
= innolux_panel_shutdown
,
569 module_mipi_dsi_driver(innolux_panel_driver
);
571 MODULE_AUTHOR("Chris Zhong <zyw@rock-chips.com>");
572 MODULE_AUTHOR("Lin Huang <hl@rock-chips.com>");
573 MODULE_DESCRIPTION("Innolux P079ZCA panel driver");
574 MODULE_LICENSE("GPL v2");