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
);
75 if (!innolux
->enabled
)
78 backlight_disable(innolux
->backlight
);
80 err
= mipi_dsi_dcs_set_display_off(innolux
->link
);
82 DRM_DEV_ERROR(panel
->dev
, "failed to set display off: %d\n",
85 innolux
->enabled
= false;
90 static int innolux_panel_unprepare(struct drm_panel
*panel
)
92 struct innolux_panel
*innolux
= to_innolux_panel(panel
);
95 if (!innolux
->prepared
)
98 err
= mipi_dsi_dcs_enter_sleep_mode(innolux
->link
);
100 DRM_DEV_ERROR(panel
->dev
, "failed to enter sleep mode: %d\n",
105 if (innolux
->desc
->sleep_mode_delay
)
106 msleep(innolux
->desc
->sleep_mode_delay
);
108 gpiod_set_value_cansleep(innolux
->enable_gpio
, 0);
110 if (innolux
->desc
->power_down_delay
)
111 msleep(innolux
->desc
->power_down_delay
);
113 err
= regulator_bulk_disable(innolux
->desc
->num_supplies
,
118 innolux
->prepared
= false;
123 static int innolux_panel_prepare(struct drm_panel
*panel
)
125 struct innolux_panel
*innolux
= to_innolux_panel(panel
);
128 if (innolux
->prepared
)
131 gpiod_set_value_cansleep(innolux
->enable_gpio
, 0);
133 err
= regulator_bulk_enable(innolux
->desc
->num_supplies
,
138 /* p079zca: t2 (20ms), p097pfg: t4 (15ms) */
139 usleep_range(20000, 21000);
141 gpiod_set_value_cansleep(innolux
->enable_gpio
, 1);
143 /* p079zca: t4, p097pfg: t5 */
144 usleep_range(20000, 21000);
146 if (innolux
->desc
->init_cmds
) {
147 const struct panel_init_cmd
*cmds
=
148 innolux
->desc
->init_cmds
;
151 for (i
= 0; cmds
[i
].len
!= 0; i
++) {
152 const struct panel_init_cmd
*cmd
= &cmds
[i
];
154 err
= mipi_dsi_generic_write(innolux
->link
, cmd
->data
,
158 "failed to write command %u\n", i
);
163 * Included by random guessing, because without this
164 * (or at least, some delay), the panel sometimes
165 * didn't appear to pick up the command sequence.
167 err
= mipi_dsi_dcs_nop(innolux
->link
);
170 "failed to send DCS nop: %d\n", err
);
176 err
= mipi_dsi_dcs_exit_sleep_mode(innolux
->link
);
178 DRM_DEV_ERROR(panel
->dev
, "failed to exit sleep mode: %d\n",
183 /* T6: 120ms - 1000ms*/
186 err
= mipi_dsi_dcs_set_display_on(innolux
->link
);
188 DRM_DEV_ERROR(panel
->dev
, "failed to set display on: %d\n",
194 usleep_range(5000, 6000);
196 innolux
->prepared
= true;
201 gpiod_set_value_cansleep(innolux
->enable_gpio
, 0);
202 regulator_bulk_disable(innolux
->desc
->num_supplies
, innolux
->supplies
);
207 static int innolux_panel_enable(struct drm_panel
*panel
)
209 struct innolux_panel
*innolux
= to_innolux_panel(panel
);
212 if (innolux
->enabled
)
215 ret
= backlight_enable(innolux
->backlight
);
217 DRM_DEV_ERROR(panel
->drm
->dev
,
218 "Failed to enable backlight %d\n", ret
);
222 innolux
->enabled
= true;
227 static const char * const innolux_p079zca_supply_names
[] = {
231 static const struct drm_display_mode innolux_p079zca_mode
= {
234 .hsync_start
= 768 + 40,
235 .hsync_end
= 768 + 40 + 40,
236 .htotal
= 768 + 40 + 40 + 40,
238 .vsync_start
= 1024 + 20,
239 .vsync_end
= 1024 + 20 + 4,
240 .vtotal
= 1024 + 20 + 4 + 20,
244 static const struct panel_desc innolux_p079zca_panel_desc
= {
245 .mode
= &innolux_p079zca_mode
,
251 .flags
= MIPI_DSI_MODE_VIDEO
| MIPI_DSI_MODE_VIDEO_SYNC_PULSE
|
253 .format
= MIPI_DSI_FMT_RGB888
,
255 .supply_names
= innolux_p079zca_supply_names
,
256 .num_supplies
= ARRAY_SIZE(innolux_p079zca_supply_names
),
257 .power_down_delay
= 80, /* T8: 80ms - 1000ms */
260 static const char * const innolux_p097pfg_supply_names
[] = {
265 static const struct drm_display_mode innolux_p097pfg_mode
= {
268 .hsync_start
= 1536 + 100,
269 .hsync_end
= 1536 + 100 + 24,
270 .htotal
= 1536 + 100 + 24 + 100,
272 .vsync_start
= 2048 + 100,
273 .vsync_end
= 2048 + 100 + 2,
274 .vtotal
= 2048 + 100 + 2 + 18,
279 * Display manufacturer failed to provide init sequencing according to
280 * https://chromium-review.googlesource.com/c/chromiumos/third_party/coreboot/+/892065/
281 * so the init sequence stems from a register dump of a working panel.
283 static const struct panel_init_cmd innolux_p097pfg_init_cmds
[] = {
285 _INIT_CMD(0xF0, 0x55, 0xAA, 0x52, 0x08, 0x00),
286 _INIT_CMD(0xB1, 0xE8, 0x11),
287 _INIT_CMD(0xB2, 0x25, 0x02),
288 _INIT_CMD(0xB5, 0x08, 0x00),
289 _INIT_CMD(0xBC, 0x0F, 0x00),
290 _INIT_CMD(0xB8, 0x03, 0x06, 0x00, 0x00),
291 _INIT_CMD(0xBD, 0x01, 0x90, 0x14, 0x14),
292 _INIT_CMD(0x6F, 0x01),
293 _INIT_CMD(0xC0, 0x03),
294 _INIT_CMD(0x6F, 0x02),
295 _INIT_CMD(0xC1, 0x0D),
296 _INIT_CMD(0xD9, 0x01, 0x09, 0x70),
297 _INIT_CMD(0xC5, 0x12, 0x21, 0x00),
298 _INIT_CMD(0xBB, 0x93, 0x93),
301 _INIT_CMD(0xF0, 0x55, 0xAA, 0x52, 0x08, 0x01),
302 _INIT_CMD(0xB3, 0x3C, 0x3C),
303 _INIT_CMD(0xB4, 0x0F, 0x0F),
304 _INIT_CMD(0xB9, 0x45, 0x45),
305 _INIT_CMD(0xBA, 0x14, 0x14),
306 _INIT_CMD(0xCA, 0x02),
307 _INIT_CMD(0xCE, 0x04),
308 _INIT_CMD(0xC3, 0x9B, 0x9B),
309 _INIT_CMD(0xD8, 0xC0, 0x03),
310 _INIT_CMD(0xBC, 0x82, 0x01),
311 _INIT_CMD(0xBD, 0x9E, 0x01),
314 _INIT_CMD(0xF0, 0x55, 0xAA, 0x52, 0x08, 0x02),
315 _INIT_CMD(0xB0, 0x82),
316 _INIT_CMD(0xD1, 0x00, 0x00, 0x00, 0x3E, 0x00, 0x82, 0x00, 0xA5,
317 0x00, 0xC1, 0x00, 0xEA, 0x01, 0x0D, 0x01, 0x40),
318 _INIT_CMD(0xD2, 0x01, 0x6A, 0x01, 0xA8, 0x01, 0xDC, 0x02, 0x29,
319 0x02, 0x67, 0x02, 0x68, 0x02, 0xA8, 0x02, 0xF0),
320 _INIT_CMD(0xD3, 0x03, 0x19, 0x03, 0x49, 0x03, 0x67, 0x03, 0x8C,
321 0x03, 0xA6, 0x03, 0xC7, 0x03, 0xDE, 0x03, 0xEC),
322 _INIT_CMD(0xD4, 0x03, 0xFF, 0x03, 0xFF),
323 _INIT_CMD(0xE0, 0x00, 0x00, 0x00, 0x86, 0x00, 0xC5, 0x00, 0xE5,
324 0x00, 0xFF, 0x01, 0x26, 0x01, 0x45, 0x01, 0x75),
325 _INIT_CMD(0xE1, 0x01, 0x9C, 0x01, 0xD5, 0x02, 0x05, 0x02, 0x4D,
326 0x02, 0x86, 0x02, 0x87, 0x02, 0xC3, 0x03, 0x03),
327 _INIT_CMD(0xE2, 0x03, 0x2A, 0x03, 0x56, 0x03, 0x72, 0x03, 0x94,
328 0x03, 0xAC, 0x03, 0xCB, 0x03, 0xE0, 0x03, 0xED),
329 _INIT_CMD(0xE3, 0x03, 0xFF, 0x03, 0xFF),
332 _INIT_CMD(0xF0, 0x55, 0xAA, 0x52, 0x08, 0x03),
333 _INIT_CMD(0xB0, 0x00, 0x00, 0x00, 0x00),
334 _INIT_CMD(0xB1, 0x00, 0x00, 0x00, 0x00),
335 _INIT_CMD(0xB2, 0x00, 0x00, 0x06, 0x04, 0x01, 0x40, 0x85),
336 _INIT_CMD(0xB3, 0x10, 0x07, 0xFC, 0x04, 0x01, 0x40, 0x80),
337 _INIT_CMD(0xB6, 0xF0, 0x08, 0x00, 0x04, 0x00, 0x00, 0x00, 0x01,
339 _INIT_CMD(0xBA, 0xC5, 0x07, 0x00, 0x04, 0x11, 0x25, 0x8C),
340 _INIT_CMD(0xBB, 0xC5, 0x07, 0x00, 0x03, 0x11, 0x25, 0x8C),
341 _INIT_CMD(0xC0, 0x00, 0x3C, 0x00, 0x00, 0x00, 0x80, 0x80),
342 _INIT_CMD(0xC1, 0x00, 0x3C, 0x00, 0x00, 0x00, 0x80, 0x80),
343 _INIT_CMD(0xC4, 0x00, 0x00),
344 _INIT_CMD(0xEF, 0x41),
347 _INIT_CMD(0xF0, 0x55, 0xAA, 0x52, 0x08, 0x04),
348 _INIT_CMD(0xEC, 0x4C),
351 _INIT_CMD(0xF0, 0x55, 0xAA, 0x52, 0x08, 0x05),
352 _INIT_CMD(0xB0, 0x13, 0x03, 0x03, 0x01),
353 _INIT_CMD(0xB1, 0x30, 0x00),
354 _INIT_CMD(0xB2, 0x02, 0x02, 0x00),
355 _INIT_CMD(0xB3, 0x82, 0x23, 0x82, 0x9D),
356 _INIT_CMD(0xB4, 0xC5, 0x75, 0x24, 0x57),
357 _INIT_CMD(0xB5, 0x00, 0xD4, 0x72, 0x11, 0x11, 0xAB, 0x0A),
358 _INIT_CMD(0xB6, 0x00, 0x00, 0xD5, 0x72, 0x24, 0x56),
359 _INIT_CMD(0xB7, 0x5C, 0xDC, 0x5C, 0x5C),
360 _INIT_CMD(0xB9, 0x0C, 0x00, 0x00, 0x01, 0x00),
361 _INIT_CMD(0xC0, 0x75, 0x11, 0x11, 0x54, 0x05),
362 _INIT_CMD(0xC6, 0x00, 0x00, 0x00, 0x00),
363 _INIT_CMD(0xD0, 0x00, 0x48, 0x08, 0x00, 0x00),
364 _INIT_CMD(0xD1, 0x00, 0x48, 0x09, 0x00, 0x00),
367 _INIT_CMD(0xF0, 0x55, 0xAA, 0x52, 0x08, 0x06),
368 _INIT_CMD(0xB0, 0x02, 0x32, 0x32, 0x08, 0x2F),
369 _INIT_CMD(0xB1, 0x2E, 0x15, 0x14, 0x13, 0x12),
370 _INIT_CMD(0xB2, 0x11, 0x10, 0x00, 0x3D, 0x3D),
371 _INIT_CMD(0xB3, 0x3D, 0x3D, 0x3D, 0x3D, 0x3D),
372 _INIT_CMD(0xB4, 0x3D, 0x32),
373 _INIT_CMD(0xB5, 0x03, 0x32, 0x32, 0x09, 0x2F),
374 _INIT_CMD(0xB6, 0x2E, 0x1B, 0x1A, 0x19, 0x18),
375 _INIT_CMD(0xB7, 0x17, 0x16, 0x01, 0x3D, 0x3D),
376 _INIT_CMD(0xB8, 0x3D, 0x3D, 0x3D, 0x3D, 0x3D),
377 _INIT_CMD(0xB9, 0x3D, 0x32),
378 _INIT_CMD(0xC0, 0x01, 0x32, 0x32, 0x09, 0x2F),
379 _INIT_CMD(0xC1, 0x2E, 0x1A, 0x1B, 0x16, 0x17),
380 _INIT_CMD(0xC2, 0x18, 0x19, 0x03, 0x3D, 0x3D),
381 _INIT_CMD(0xC3, 0x3D, 0x3D, 0x3D, 0x3D, 0x3D),
382 _INIT_CMD(0xC4, 0x3D, 0x32),
383 _INIT_CMD(0xC5, 0x00, 0x32, 0x32, 0x08, 0x2F),
384 _INIT_CMD(0xC6, 0x2E, 0x14, 0x15, 0x10, 0x11),
385 _INIT_CMD(0xC7, 0x12, 0x13, 0x02, 0x3D, 0x3D),
386 _INIT_CMD(0xC8, 0x3D, 0x3D, 0x3D, 0x3D, 0x3D),
387 _INIT_CMD(0xC9, 0x3D, 0x32),
392 static const struct panel_desc innolux_p097pfg_panel_desc
= {
393 .mode
= &innolux_p097pfg_mode
,
399 .flags
= MIPI_DSI_MODE_VIDEO
| MIPI_DSI_MODE_VIDEO_SYNC_PULSE
|
401 .format
= MIPI_DSI_FMT_RGB888
,
402 .init_cmds
= innolux_p097pfg_init_cmds
,
404 .supply_names
= innolux_p097pfg_supply_names
,
405 .num_supplies
= ARRAY_SIZE(innolux_p097pfg_supply_names
),
406 .sleep_mode_delay
= 100, /* T15 */
409 static int innolux_panel_get_modes(struct drm_panel
*panel
)
411 struct innolux_panel
*innolux
= to_innolux_panel(panel
);
412 const struct drm_display_mode
*m
= innolux
->desc
->mode
;
413 struct drm_display_mode
*mode
;
415 mode
= drm_mode_duplicate(panel
->drm
, m
);
417 DRM_DEV_ERROR(panel
->drm
->dev
, "failed to add mode %ux%ux@%u\n",
418 m
->hdisplay
, m
->vdisplay
, m
->vrefresh
);
422 drm_mode_set_name(mode
);
424 drm_mode_probed_add(panel
->connector
, mode
);
426 panel
->connector
->display_info
.width_mm
=
427 innolux
->desc
->size
.width
;
428 panel
->connector
->display_info
.height_mm
=
429 innolux
->desc
->size
.height
;
430 panel
->connector
->display_info
.bpc
= innolux
->desc
->bpc
;
435 static const struct drm_panel_funcs innolux_panel_funcs
= {
436 .disable
= innolux_panel_disable
,
437 .unprepare
= innolux_panel_unprepare
,
438 .prepare
= innolux_panel_prepare
,
439 .enable
= innolux_panel_enable
,
440 .get_modes
= innolux_panel_get_modes
,
443 static const struct of_device_id innolux_of_match
[] = {
444 { .compatible
= "innolux,p079zca",
445 .data
= &innolux_p079zca_panel_desc
447 { .compatible
= "innolux,p097pfg",
448 .data
= &innolux_p097pfg_panel_desc
452 MODULE_DEVICE_TABLE(of
, innolux_of_match
);
454 static int innolux_panel_add(struct mipi_dsi_device
*dsi
,
455 const struct panel_desc
*desc
)
457 struct innolux_panel
*innolux
;
458 struct device
*dev
= &dsi
->dev
;
461 innolux
= devm_kzalloc(dev
, sizeof(*innolux
), GFP_KERNEL
);
465 innolux
->desc
= desc
;
467 innolux
->supplies
= devm_kcalloc(dev
, desc
->num_supplies
,
468 sizeof(*innolux
->supplies
),
470 if (!innolux
->supplies
)
473 for (i
= 0; i
< desc
->num_supplies
; i
++)
474 innolux
->supplies
[i
].supply
= desc
->supply_names
[i
];
476 err
= devm_regulator_bulk_get(dev
, desc
->num_supplies
,
481 innolux
->enable_gpio
= devm_gpiod_get_optional(dev
, "enable",
483 if (IS_ERR(innolux
->enable_gpio
)) {
484 err
= PTR_ERR(innolux
->enable_gpio
);
485 dev_dbg(dev
, "failed to get enable gpio: %d\n", err
);
486 innolux
->enable_gpio
= NULL
;
489 innolux
->backlight
= devm_of_find_backlight(dev
);
490 if (IS_ERR(innolux
->backlight
))
491 return PTR_ERR(innolux
->backlight
);
493 drm_panel_init(&innolux
->base
);
494 innolux
->base
.funcs
= &innolux_panel_funcs
;
495 innolux
->base
.dev
= dev
;
497 err
= drm_panel_add(&innolux
->base
);
501 mipi_dsi_set_drvdata(dsi
, innolux
);
507 static void innolux_panel_del(struct innolux_panel
*innolux
)
509 if (innolux
->base
.dev
)
510 drm_panel_remove(&innolux
->base
);
513 static int innolux_panel_probe(struct mipi_dsi_device
*dsi
)
515 const struct panel_desc
*desc
;
518 desc
= of_device_get_match_data(&dsi
->dev
);
519 dsi
->mode_flags
= desc
->flags
;
520 dsi
->format
= desc
->format
;
521 dsi
->lanes
= desc
->lanes
;
523 err
= innolux_panel_add(dsi
, desc
);
527 return mipi_dsi_attach(dsi
);
530 static int innolux_panel_remove(struct mipi_dsi_device
*dsi
)
532 struct innolux_panel
*innolux
= mipi_dsi_get_drvdata(dsi
);
535 err
= innolux_panel_unprepare(&innolux
->base
);
537 DRM_DEV_ERROR(&dsi
->dev
, "failed to unprepare panel: %d\n",
540 err
= innolux_panel_disable(&innolux
->base
);
542 DRM_DEV_ERROR(&dsi
->dev
, "failed to disable panel: %d\n", err
);
544 err
= mipi_dsi_detach(dsi
);
546 DRM_DEV_ERROR(&dsi
->dev
, "failed to detach from DSI host: %d\n",
549 innolux_panel_del(innolux
);
554 static void innolux_panel_shutdown(struct mipi_dsi_device
*dsi
)
556 struct innolux_panel
*innolux
= mipi_dsi_get_drvdata(dsi
);
558 innolux_panel_unprepare(&innolux
->base
);
559 innolux_panel_disable(&innolux
->base
);
562 static struct mipi_dsi_driver innolux_panel_driver
= {
564 .name
= "panel-innolux-p079zca",
565 .of_match_table
= innolux_of_match
,
567 .probe
= innolux_panel_probe
,
568 .remove
= innolux_panel_remove
,
569 .shutdown
= innolux_panel_shutdown
,
571 module_mipi_dsi_driver(innolux_panel_driver
);
573 MODULE_AUTHOR("Chris Zhong <zyw@rock-chips.com>");
574 MODULE_AUTHOR("Lin Huang <hl@rock-chips.com>");
575 MODULE_DESCRIPTION("Innolux P079ZCA panel driver");
576 MODULE_LICENSE("GPL v2");