1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (C) 2016 InforceComputing
4 * Author: Vinay Simha BN <simhavcs@gmail.com>
6 * Copyright (C) 2016 Linaro Ltd
7 * Author: Sumit Semwal <sumit.semwal@linaro.org>
9 * From internet archives, the panel for Nexus 7 2nd Gen, 2013 model is a
10 * JDI model LT070ME05000, and its data sheet is at:
11 * http://panelone.net/en/7-0-inch/JDI_LT070ME05000_7.0_inch-datasheet
14 #include <linux/backlight.h>
15 #include <linux/delay.h>
16 #include <linux/gpio/consumer.h>
17 #include <linux/module.h>
19 #include <linux/regulator/consumer.h>
21 #include <video/mipi_display.h>
23 #include <drm/drm_crtc.h>
24 #include <drm/drm_mipi_dsi.h>
25 #include <drm/drm_modes.h>
26 #include <drm/drm_panel.h>
28 static const char * const regulator_names
[] = {
34 struct drm_panel base
;
35 struct mipi_dsi_device
*dsi
;
37 struct regulator_bulk_data supplies
[ARRAY_SIZE(regulator_names
)];
39 struct gpio_desc
*enable_gpio
;
40 struct gpio_desc
*reset_gpio
;
41 struct gpio_desc
*dcdc_en_gpio
;
42 struct backlight_device
*backlight
;
47 const struct drm_display_mode
*mode
;
50 static inline struct jdi_panel
*to_jdi_panel(struct drm_panel
*panel
)
52 return container_of(panel
, struct jdi_panel
, base
);
55 static int jdi_panel_init(struct jdi_panel
*jdi
)
57 struct mipi_dsi_device
*dsi
= jdi
->dsi
;
58 struct device
*dev
= &jdi
->dsi
->dev
;
61 dsi
->mode_flags
|= MIPI_DSI_MODE_LPM
;
63 ret
= mipi_dsi_dcs_soft_reset(dsi
);
67 usleep_range(10000, 20000);
69 ret
= mipi_dsi_dcs_set_pixel_format(dsi
, MIPI_DCS_PIXEL_FMT_24BIT
<< 4);
71 dev_err(dev
, "failed to set pixel format: %d\n", ret
);
75 ret
= mipi_dsi_dcs_set_column_address(dsi
, 0, jdi
->mode
->hdisplay
- 1);
77 dev_err(dev
, "failed to set column address: %d\n", ret
);
81 ret
= mipi_dsi_dcs_set_page_address(dsi
, 0, jdi
->mode
->vdisplay
- 1);
83 dev_err(dev
, "failed to set page address: %d\n", ret
);
88 * BIT(5) BCTRL = 1 Backlight Control Block On, Brightness registers
90 * BIT(3) BL = 1 Backlight Control On
91 * BIT(2) DD = 0 Display Dimming is Off
93 ret
= mipi_dsi_dcs_write(dsi
, MIPI_DCS_WRITE_CONTROL_DISPLAY
,
96 dev_err(dev
, "failed to write control display: %d\n", ret
);
101 ret
= mipi_dsi_dcs_write(dsi
, MIPI_DCS_WRITE_POWER_SAVE
,
104 dev_err(dev
, "failed to set cabc off: %d\n", ret
);
108 ret
= mipi_dsi_dcs_exit_sleep_mode(dsi
);
110 dev_err(dev
, "failed to set exit sleep mode: %d\n", ret
);
116 ret
= mipi_dsi_generic_write(dsi
, (u8
[]){0xB0, 0x00}, 2);
118 dev_err(dev
, "failed to set mcap: %d\n", ret
);
124 /* Interface setting, video mode */
125 ret
= mipi_dsi_generic_write(dsi
, (u8
[])
126 {0xB3, 0x26, 0x08, 0x00, 0x20, 0x00}, 6);
128 dev_err(dev
, "failed to set display interface setting: %d\n"
135 ret
= mipi_dsi_generic_write(dsi
, (u8
[]){0xB0, 0x03}, 2);
137 dev_err(dev
, "failed to set default values for mcap: %d\n"
145 static int jdi_panel_on(struct jdi_panel
*jdi
)
147 struct mipi_dsi_device
*dsi
= jdi
->dsi
;
148 struct device
*dev
= &jdi
->dsi
->dev
;
151 dsi
->mode_flags
|= MIPI_DSI_MODE_LPM
;
153 ret
= mipi_dsi_dcs_set_display_on(dsi
);
155 dev_err(dev
, "failed to set display on: %d\n", ret
);
160 static void jdi_panel_off(struct jdi_panel
*jdi
)
162 struct mipi_dsi_device
*dsi
= jdi
->dsi
;
163 struct device
*dev
= &jdi
->dsi
->dev
;
166 dsi
->mode_flags
&= ~MIPI_DSI_MODE_LPM
;
168 ret
= mipi_dsi_dcs_set_display_off(dsi
);
170 dev_err(dev
, "failed to set display off: %d\n", ret
);
172 ret
= mipi_dsi_dcs_enter_sleep_mode(dsi
);
174 dev_err(dev
, "failed to enter sleep mode: %d\n", ret
);
179 static int jdi_panel_disable(struct drm_panel
*panel
)
181 struct jdi_panel
*jdi
= to_jdi_panel(panel
);
186 backlight_disable(jdi
->backlight
);
188 jdi
->enabled
= false;
193 static int jdi_panel_unprepare(struct drm_panel
*panel
)
195 struct jdi_panel
*jdi
= to_jdi_panel(panel
);
196 struct device
*dev
= &jdi
->dsi
->dev
;
204 ret
= regulator_bulk_disable(ARRAY_SIZE(jdi
->supplies
), jdi
->supplies
);
206 dev_err(dev
, "regulator disable failed, %d\n", ret
);
208 gpiod_set_value(jdi
->enable_gpio
, 0);
210 gpiod_set_value(jdi
->reset_gpio
, 1);
212 gpiod_set_value(jdi
->dcdc_en_gpio
, 0);
214 jdi
->prepared
= false;
219 static int jdi_panel_prepare(struct drm_panel
*panel
)
221 struct jdi_panel
*jdi
= to_jdi_panel(panel
);
222 struct device
*dev
= &jdi
->dsi
->dev
;
228 ret
= regulator_bulk_enable(ARRAY_SIZE(jdi
->supplies
), jdi
->supplies
);
230 dev_err(dev
, "regulator enable failed, %d\n", ret
);
236 gpiod_set_value(jdi
->dcdc_en_gpio
, 1);
237 usleep_range(10, 20);
239 gpiod_set_value(jdi
->reset_gpio
, 0);
240 usleep_range(10, 20);
242 gpiod_set_value(jdi
->enable_gpio
, 1);
243 usleep_range(10, 20);
245 ret
= jdi_panel_init(jdi
);
247 dev_err(dev
, "failed to init panel: %d\n", ret
);
251 ret
= jdi_panel_on(jdi
);
253 dev_err(dev
, "failed to set panel on: %d\n", ret
);
257 jdi
->prepared
= true;
262 ret
= regulator_bulk_disable(ARRAY_SIZE(jdi
->supplies
), jdi
->supplies
);
264 dev_err(dev
, "regulator disable failed, %d\n", ret
);
266 gpiod_set_value(jdi
->enable_gpio
, 0);
268 gpiod_set_value(jdi
->reset_gpio
, 1);
270 gpiod_set_value(jdi
->dcdc_en_gpio
, 0);
275 static int jdi_panel_enable(struct drm_panel
*panel
)
277 struct jdi_panel
*jdi
= to_jdi_panel(panel
);
282 backlight_enable(jdi
->backlight
);
289 static const struct drm_display_mode default_mode
= {
292 .hsync_start
= 1200 + 48,
293 .hsync_end
= 1200 + 48 + 32,
294 .htotal
= 1200 + 48 + 32 + 60,
296 .vsync_start
= 1920 + 3,
297 .vsync_end
= 1920 + 3 + 5,
298 .vtotal
= 1920 + 3 + 5 + 6,
302 static int jdi_panel_get_modes(struct drm_panel
*panel
,
303 struct drm_connector
*connector
)
305 struct drm_display_mode
*mode
;
306 struct jdi_panel
*jdi
= to_jdi_panel(panel
);
307 struct device
*dev
= &jdi
->dsi
->dev
;
309 mode
= drm_mode_duplicate(connector
->dev
, &default_mode
);
311 dev_err(dev
, "failed to add mode %ux%ux@%u\n",
312 default_mode
.hdisplay
, default_mode
.vdisplay
,
313 drm_mode_vrefresh(&default_mode
));
317 drm_mode_set_name(mode
);
319 drm_mode_probed_add(connector
, mode
);
321 connector
->display_info
.width_mm
= 95;
322 connector
->display_info
.height_mm
= 151;
327 static int dsi_dcs_bl_get_brightness(struct backlight_device
*bl
)
329 struct mipi_dsi_device
*dsi
= bl_get_data(bl
);
331 u16 brightness
= bl
->props
.brightness
;
333 dsi
->mode_flags
&= ~MIPI_DSI_MODE_LPM
;
335 ret
= mipi_dsi_dcs_get_display_brightness(dsi
, &brightness
);
339 dsi
->mode_flags
|= MIPI_DSI_MODE_LPM
;
341 return brightness
& 0xff;
344 static int dsi_dcs_bl_update_status(struct backlight_device
*bl
)
346 struct mipi_dsi_device
*dsi
= bl_get_data(bl
);
349 dsi
->mode_flags
&= ~MIPI_DSI_MODE_LPM
;
351 ret
= mipi_dsi_dcs_set_display_brightness(dsi
, bl
->props
.brightness
);
355 dsi
->mode_flags
|= MIPI_DSI_MODE_LPM
;
360 static const struct backlight_ops dsi_bl_ops
= {
361 .update_status
= dsi_dcs_bl_update_status
,
362 .get_brightness
= dsi_dcs_bl_get_brightness
,
365 static struct backlight_device
*
366 drm_panel_create_dsi_backlight(struct mipi_dsi_device
*dsi
)
368 struct device
*dev
= &dsi
->dev
;
369 struct backlight_properties props
;
371 memset(&props
, 0, sizeof(props
));
372 props
.type
= BACKLIGHT_RAW
;
373 props
.brightness
= 255;
374 props
.max_brightness
= 255;
376 return devm_backlight_device_register(dev
, dev_name(dev
), dev
, dsi
,
377 &dsi_bl_ops
, &props
);
380 static const struct drm_panel_funcs jdi_panel_funcs
= {
381 .disable
= jdi_panel_disable
,
382 .unprepare
= jdi_panel_unprepare
,
383 .prepare
= jdi_panel_prepare
,
384 .enable
= jdi_panel_enable
,
385 .get_modes
= jdi_panel_get_modes
,
388 static const struct of_device_id jdi_of_match
[] = {
389 { .compatible
= "jdi,lt070me05000", },
392 MODULE_DEVICE_TABLE(of
, jdi_of_match
);
394 static int jdi_panel_add(struct jdi_panel
*jdi
)
396 struct device
*dev
= &jdi
->dsi
->dev
;
400 jdi
->mode
= &default_mode
;
402 for (i
= 0; i
< ARRAY_SIZE(jdi
->supplies
); i
++)
403 jdi
->supplies
[i
].supply
= regulator_names
[i
];
405 ret
= devm_regulator_bulk_get(dev
, ARRAY_SIZE(jdi
->supplies
),
408 dev_err(dev
, "failed to init regulator, ret=%d\n", ret
);
412 jdi
->enable_gpio
= devm_gpiod_get(dev
, "enable", GPIOD_OUT_LOW
);
413 if (IS_ERR(jdi
->enable_gpio
)) {
414 ret
= PTR_ERR(jdi
->enable_gpio
);
415 dev_err(dev
, "cannot get enable-gpio %d\n", ret
);
419 jdi
->reset_gpio
= devm_gpiod_get(dev
, "reset", GPIOD_OUT_HIGH
);
420 if (IS_ERR(jdi
->reset_gpio
)) {
421 ret
= PTR_ERR(jdi
->reset_gpio
);
422 dev_err(dev
, "cannot get reset-gpios %d\n", ret
);
426 jdi
->dcdc_en_gpio
= devm_gpiod_get(dev
, "dcdc-en", GPIOD_OUT_LOW
);
427 if (IS_ERR(jdi
->dcdc_en_gpio
)) {
428 ret
= PTR_ERR(jdi
->dcdc_en_gpio
);
429 dev_err(dev
, "cannot get dcdc-en-gpio %d\n", ret
);
433 jdi
->backlight
= drm_panel_create_dsi_backlight(jdi
->dsi
);
434 if (IS_ERR(jdi
->backlight
)) {
435 ret
= PTR_ERR(jdi
->backlight
);
436 dev_err(dev
, "failed to register backlight %d\n", ret
);
440 drm_panel_init(&jdi
->base
, &jdi
->dsi
->dev
, &jdi_panel_funcs
,
441 DRM_MODE_CONNECTOR_DSI
);
443 drm_panel_add(&jdi
->base
);
448 static void jdi_panel_del(struct jdi_panel
*jdi
)
451 drm_panel_remove(&jdi
->base
);
454 static int jdi_panel_probe(struct mipi_dsi_device
*dsi
)
456 struct jdi_panel
*jdi
;
460 dsi
->format
= MIPI_DSI_FMT_RGB888
;
461 dsi
->mode_flags
= MIPI_DSI_MODE_VIDEO_HSE
| MIPI_DSI_MODE_VIDEO
|
462 MIPI_DSI_CLOCK_NON_CONTINUOUS
;
464 jdi
= devm_kzalloc(&dsi
->dev
, sizeof(*jdi
), GFP_KERNEL
);
468 mipi_dsi_set_drvdata(dsi
, jdi
);
472 ret
= jdi_panel_add(jdi
);
476 return mipi_dsi_attach(dsi
);
479 static int jdi_panel_remove(struct mipi_dsi_device
*dsi
)
481 struct jdi_panel
*jdi
= mipi_dsi_get_drvdata(dsi
);
484 ret
= jdi_panel_disable(&jdi
->base
);
486 dev_err(&dsi
->dev
, "failed to disable panel: %d\n", ret
);
488 ret
= mipi_dsi_detach(dsi
);
490 dev_err(&dsi
->dev
, "failed to detach from DSI host: %d\n",
498 static void jdi_panel_shutdown(struct mipi_dsi_device
*dsi
)
500 struct jdi_panel
*jdi
= mipi_dsi_get_drvdata(dsi
);
502 jdi_panel_disable(&jdi
->base
);
505 static struct mipi_dsi_driver jdi_panel_driver
= {
507 .name
= "panel-jdi-lt070me05000",
508 .of_match_table
= jdi_of_match
,
510 .probe
= jdi_panel_probe
,
511 .remove
= jdi_panel_remove
,
512 .shutdown
= jdi_panel_shutdown
,
514 module_mipi_dsi_driver(jdi_panel_driver
);
516 MODULE_AUTHOR("Sumit Semwal <sumit.semwal@linaro.org>");
517 MODULE_AUTHOR("Vinay Simha BN <simhavcs@gmail.com>");
518 MODULE_DESCRIPTION("JDI LT070ME05000 WUXGA");
519 MODULE_LICENSE("GPL v2");