blob: 4bf33c6b42f07a6fc1eeb9cdc444b38134987fff [file] [log] [blame]
Thierry Reding280921d2013-08-30 15:10:14 +02001/*
2 * Copyright (C) 2013, NVIDIA Corporation. All rights reserved.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sub license,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the
12 * next paragraph) shall be included in all copies or substantial portions
13 * of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
22 */
23
24#include <linux/backlight.h>
Alexandre Courbotcfdf0542014-03-01 14:00:58 +090025#include <linux/gpio/consumer.h>
Thierry Reding280921d2013-08-30 15:10:14 +020026#include <linux/module.h>
Thierry Reding280921d2013-08-30 15:10:14 +020027#include <linux/of_platform.h>
28#include <linux/platform_device.h>
29#include <linux/regulator/consumer.h>
30
31#include <drm/drmP.h>
32#include <drm/drm_crtc.h>
Thierry Reding210fcd92013-11-22 19:27:11 +010033#include <drm/drm_mipi_dsi.h>
Thierry Reding280921d2013-08-30 15:10:14 +020034#include <drm/drm_panel.h>
35
36struct panel_desc {
37 const struct drm_display_mode *modes;
38 unsigned int num_modes;
39
Stéphane Marchesin0208d512014-06-19 18:18:28 -070040 unsigned int bpc;
41
Thierry Reding280921d2013-08-30 15:10:14 +020042 struct {
43 unsigned int width;
44 unsigned int height;
45 } size;
46};
47
Thierry Reding280921d2013-08-30 15:10:14 +020048struct panel_simple {
49 struct drm_panel base;
50 bool enabled;
51
52 const struct panel_desc *desc;
53
54 struct backlight_device *backlight;
55 struct regulator *supply;
56 struct i2c_adapter *ddc;
57
Alexandre Courbotcfdf0542014-03-01 14:00:58 +090058 struct gpio_desc *enable_gpio;
Thierry Reding280921d2013-08-30 15:10:14 +020059};
60
61static inline struct panel_simple *to_panel_simple(struct drm_panel *panel)
62{
63 return container_of(panel, struct panel_simple, base);
64}
65
66static int panel_simple_get_fixed_modes(struct panel_simple *panel)
67{
68 struct drm_connector *connector = panel->base.connector;
69 struct drm_device *drm = panel->base.drm;
70 struct drm_display_mode *mode;
71 unsigned int i, num = 0;
72
73 if (!panel->desc)
74 return 0;
75
76 for (i = 0; i < panel->desc->num_modes; i++) {
77 const struct drm_display_mode *m = &panel->desc->modes[i];
78
79 mode = drm_mode_duplicate(drm, m);
80 if (!mode) {
81 dev_err(drm->dev, "failed to add mode %ux%u@%u\n",
82 m->hdisplay, m->vdisplay, m->vrefresh);
83 continue;
84 }
85
86 drm_mode_set_name(mode);
87
88 drm_mode_probed_add(connector, mode);
89 num++;
90 }
91
Stéphane Marchesin0208d512014-06-19 18:18:28 -070092 connector->display_info.bpc = panel->desc->bpc;
Thierry Reding280921d2013-08-30 15:10:14 +020093 connector->display_info.width_mm = panel->desc->size.width;
94 connector->display_info.height_mm = panel->desc->size.height;
95
96 return num;
97}
98
99static int panel_simple_disable(struct drm_panel *panel)
100{
101 struct panel_simple *p = to_panel_simple(panel);
102
103 if (!p->enabled)
104 return 0;
105
106 if (p->backlight) {
107 p->backlight->props.power = FB_BLANK_POWERDOWN;
108 backlight_update_status(p->backlight);
109 }
110
Alexandre Courbotcfdf0542014-03-01 14:00:58 +0900111 if (p->enable_gpio)
Thierry Reding15c1a912014-03-14 12:03:47 +0100112 gpiod_set_value_cansleep(p->enable_gpio, 0);
Thierry Reding280921d2013-08-30 15:10:14 +0200113
114 regulator_disable(p->supply);
115 p->enabled = false;
116
117 return 0;
118}
119
Ajay Kumarc0e1d172014-07-31 23:12:04 +0530120static int panel_simple_unprepare(struct drm_panel *panel)
121{
122 return 0;
123}
124
125static int panel_simple_prepare(struct drm_panel *panel)
126{
127 return 0;
128}
129
Thierry Reding280921d2013-08-30 15:10:14 +0200130static int panel_simple_enable(struct drm_panel *panel)
131{
132 struct panel_simple *p = to_panel_simple(panel);
133 int err;
134
135 if (p->enabled)
136 return 0;
137
138 err = regulator_enable(p->supply);
139 if (err < 0) {
140 dev_err(panel->dev, "failed to enable supply: %d\n", err);
141 return err;
142 }
143
Alexandre Courbotcfdf0542014-03-01 14:00:58 +0900144 if (p->enable_gpio)
Thierry Reding15c1a912014-03-14 12:03:47 +0100145 gpiod_set_value_cansleep(p->enable_gpio, 1);
Thierry Reding280921d2013-08-30 15:10:14 +0200146
147 if (p->backlight) {
148 p->backlight->props.power = FB_BLANK_UNBLANK;
149 backlight_update_status(p->backlight);
150 }
151
152 p->enabled = true;
153
154 return 0;
155}
156
157static int panel_simple_get_modes(struct drm_panel *panel)
158{
159 struct panel_simple *p = to_panel_simple(panel);
160 int num = 0;
161
162 /* probe EDID if a DDC bus is available */
163 if (p->ddc) {
164 struct edid *edid = drm_get_edid(panel->connector, p->ddc);
Stephen Warren70bf6872014-01-09 11:37:34 -0700165 drm_mode_connector_update_edid_property(panel->connector, edid);
Thierry Reding280921d2013-08-30 15:10:14 +0200166 if (edid) {
167 num += drm_add_edid_modes(panel->connector, edid);
168 kfree(edid);
169 }
170 }
171
172 /* add hard-coded panel modes */
173 num += panel_simple_get_fixed_modes(p);
174
175 return num;
176}
177
178static const struct drm_panel_funcs panel_simple_funcs = {
179 .disable = panel_simple_disable,
Ajay Kumarc0e1d172014-07-31 23:12:04 +0530180 .unprepare = panel_simple_unprepare,
181 .prepare = panel_simple_prepare,
Thierry Reding280921d2013-08-30 15:10:14 +0200182 .enable = panel_simple_enable,
183 .get_modes = panel_simple_get_modes,
184};
185
186static int panel_simple_probe(struct device *dev, const struct panel_desc *desc)
187{
188 struct device_node *backlight, *ddc;
189 struct panel_simple *panel;
Thierry Reding280921d2013-08-30 15:10:14 +0200190 int err;
191
192 panel = devm_kzalloc(dev, sizeof(*panel), GFP_KERNEL);
193 if (!panel)
194 return -ENOMEM;
195
196 panel->enabled = false;
197 panel->desc = desc;
198
199 panel->supply = devm_regulator_get(dev, "power");
200 if (IS_ERR(panel->supply))
201 return PTR_ERR(panel->supply);
202
Alexandre Courbotcfdf0542014-03-01 14:00:58 +0900203 panel->enable_gpio = devm_gpiod_get(dev, "enable");
204 if (IS_ERR(panel->enable_gpio)) {
205 err = PTR_ERR(panel->enable_gpio);
206 if (err != -ENOENT) {
207 dev_err(dev, "failed to request GPIO: %d\n", err);
Thierry Reding280921d2013-08-30 15:10:14 +0200208 return err;
209 }
210
Alexandre Courbotcfdf0542014-03-01 14:00:58 +0900211 panel->enable_gpio = NULL;
212 } else {
213 err = gpiod_direction_output(panel->enable_gpio, 0);
Thierry Reding280921d2013-08-30 15:10:14 +0200214 if (err < 0) {
Alexandre Courbotcfdf0542014-03-01 14:00:58 +0900215 dev_err(dev, "failed to setup GPIO: %d\n", err);
216 return err;
Thierry Reding280921d2013-08-30 15:10:14 +0200217 }
218 }
219
220 backlight = of_parse_phandle(dev->of_node, "backlight", 0);
221 if (backlight) {
222 panel->backlight = of_find_backlight_by_node(backlight);
223 of_node_put(backlight);
224
Alexandre Courbotcfdf0542014-03-01 14:00:58 +0900225 if (!panel->backlight)
226 return -EPROBE_DEFER;
Thierry Reding280921d2013-08-30 15:10:14 +0200227 }
228
229 ddc = of_parse_phandle(dev->of_node, "ddc-i2c-bus", 0);
230 if (ddc) {
231 panel->ddc = of_find_i2c_adapter_by_node(ddc);
232 of_node_put(ddc);
233
234 if (!panel->ddc) {
235 err = -EPROBE_DEFER;
236 goto free_backlight;
237 }
238 }
239
240 drm_panel_init(&panel->base);
241 panel->base.dev = dev;
242 panel->base.funcs = &panel_simple_funcs;
243
244 err = drm_panel_add(&panel->base);
245 if (err < 0)
246 goto free_ddc;
247
248 dev_set_drvdata(dev, panel);
249
250 return 0;
251
252free_ddc:
253 if (panel->ddc)
254 put_device(&panel->ddc->dev);
255free_backlight:
256 if (panel->backlight)
257 put_device(&panel->backlight->dev);
Thierry Reding280921d2013-08-30 15:10:14 +0200258
259 return err;
260}
261
262static int panel_simple_remove(struct device *dev)
263{
264 struct panel_simple *panel = dev_get_drvdata(dev);
265
266 drm_panel_detach(&panel->base);
267 drm_panel_remove(&panel->base);
268
269 panel_simple_disable(&panel->base);
270
271 if (panel->ddc)
272 put_device(&panel->ddc->dev);
273
274 if (panel->backlight)
275 put_device(&panel->backlight->dev);
276
Thierry Reding280921d2013-08-30 15:10:14 +0200277 return 0;
278}
279
Thierry Redingd02fd932014-04-29 17:21:21 +0200280static void panel_simple_shutdown(struct device *dev)
281{
282 struct panel_simple *panel = dev_get_drvdata(dev);
283
284 panel_simple_disable(&panel->base);
285}
286
Thierry Reding280921d2013-08-30 15:10:14 +0200287static const struct drm_display_mode auo_b101aw03_mode = {
288 .clock = 51450,
289 .hdisplay = 1024,
290 .hsync_start = 1024 + 156,
291 .hsync_end = 1024 + 156 + 8,
292 .htotal = 1024 + 156 + 8 + 156,
293 .vdisplay = 600,
294 .vsync_start = 600 + 16,
295 .vsync_end = 600 + 16 + 6,
296 .vtotal = 600 + 16 + 6 + 16,
297 .vrefresh = 60,
298};
299
300static const struct panel_desc auo_b101aw03 = {
301 .modes = &auo_b101aw03_mode,
302 .num_modes = 1,
Stéphane Marchesin0208d512014-06-19 18:18:28 -0700303 .bpc = 6,
Thierry Reding280921d2013-08-30 15:10:14 +0200304 .size = {
305 .width = 223,
306 .height = 125,
307 },
308};
309
Stéphane Marchesina333f7a2014-05-23 19:27:59 -0700310static const struct drm_display_mode auo_b133xtn01_mode = {
311 .clock = 69500,
312 .hdisplay = 1366,
313 .hsync_start = 1366 + 48,
314 .hsync_end = 1366 + 48 + 32,
315 .htotal = 1366 + 48 + 32 + 20,
316 .vdisplay = 768,
317 .vsync_start = 768 + 3,
318 .vsync_end = 768 + 3 + 6,
319 .vtotal = 768 + 3 + 6 + 13,
320 .vrefresh = 60,
321};
322
323static const struct panel_desc auo_b133xtn01 = {
324 .modes = &auo_b133xtn01_mode,
325 .num_modes = 1,
Stéphane Marchesin0208d512014-06-19 18:18:28 -0700326 .bpc = 6,
Stéphane Marchesina333f7a2014-05-23 19:27:59 -0700327 .size = {
328 .width = 293,
329 .height = 165,
330 },
331};
332
Stephen Warren4c930752014-01-07 16:46:26 -0700333static const struct drm_display_mode chunghwa_claa101wa01a_mode = {
334 .clock = 72070,
335 .hdisplay = 1366,
336 .hsync_start = 1366 + 58,
337 .hsync_end = 1366 + 58 + 58,
338 .htotal = 1366 + 58 + 58 + 58,
339 .vdisplay = 768,
340 .vsync_start = 768 + 4,
341 .vsync_end = 768 + 4 + 4,
342 .vtotal = 768 + 4 + 4 + 4,
343 .vrefresh = 60,
344};
345
346static const struct panel_desc chunghwa_claa101wa01a = {
347 .modes = &chunghwa_claa101wa01a_mode,
348 .num_modes = 1,
Stéphane Marchesin0208d512014-06-19 18:18:28 -0700349 .bpc = 6,
Stephen Warren4c930752014-01-07 16:46:26 -0700350 .size = {
351 .width = 220,
352 .height = 120,
353 },
354};
355
Thierry Reding280921d2013-08-30 15:10:14 +0200356static const struct drm_display_mode chunghwa_claa101wb01_mode = {
357 .clock = 69300,
358 .hdisplay = 1366,
359 .hsync_start = 1366 + 48,
360 .hsync_end = 1366 + 48 + 32,
361 .htotal = 1366 + 48 + 32 + 20,
362 .vdisplay = 768,
363 .vsync_start = 768 + 16,
364 .vsync_end = 768 + 16 + 8,
365 .vtotal = 768 + 16 + 8 + 16,
366 .vrefresh = 60,
367};
368
369static const struct panel_desc chunghwa_claa101wb01 = {
370 .modes = &chunghwa_claa101wb01_mode,
371 .num_modes = 1,
Stéphane Marchesin0208d512014-06-19 18:18:28 -0700372 .bpc = 6,
Thierry Reding280921d2013-08-30 15:10:14 +0200373 .size = {
374 .width = 223,
375 .height = 125,
376 },
377};
378
Stefan Agner26ab0062014-05-15 11:38:45 +0200379static const struct drm_display_mode edt_et057090dhu_mode = {
380 .clock = 25175,
381 .hdisplay = 640,
382 .hsync_start = 640 + 16,
383 .hsync_end = 640 + 16 + 30,
384 .htotal = 640 + 16 + 30 + 114,
385 .vdisplay = 480,
386 .vsync_start = 480 + 10,
387 .vsync_end = 480 + 10 + 3,
388 .vtotal = 480 + 10 + 3 + 32,
389 .vrefresh = 60,
390 .flags = DRM_MODE_FLAG_NVSYNC | DRM_MODE_FLAG_NHSYNC,
391};
392
393static const struct panel_desc edt_et057090dhu = {
394 .modes = &edt_et057090dhu_mode,
395 .num_modes = 1,
Stéphane Marchesin0208d512014-06-19 18:18:28 -0700396 .bpc = 6,
Stefan Agner26ab0062014-05-15 11:38:45 +0200397 .size = {
398 .width = 115,
399 .height = 86,
400 },
401};
402
Philipp Zabelfff5de42014-05-15 12:25:47 +0200403static const struct drm_display_mode edt_etm0700g0dh6_mode = {
404 .clock = 33260,
405 .hdisplay = 800,
406 .hsync_start = 800 + 40,
407 .hsync_end = 800 + 40 + 128,
408 .htotal = 800 + 40 + 128 + 88,
409 .vdisplay = 480,
410 .vsync_start = 480 + 10,
411 .vsync_end = 480 + 10 + 2,
412 .vtotal = 480 + 10 + 2 + 33,
413 .vrefresh = 60,
414 .flags = DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC,
415};
416
417static const struct panel_desc edt_etm0700g0dh6 = {
418 .modes = &edt_etm0700g0dh6_mode,
419 .num_modes = 1,
Stéphane Marchesin0208d512014-06-19 18:18:28 -0700420 .bpc = 6,
Philipp Zabelfff5de42014-05-15 12:25:47 +0200421 .size = {
422 .width = 152,
423 .height = 91,
424 },
425};
426
Boris BREZILLON102932b2014-06-05 15:53:32 +0200427static const struct drm_display_mode foxlink_fl500wvr00_a0t_mode = {
428 .clock = 32260,
429 .hdisplay = 800,
430 .hsync_start = 800 + 168,
431 .hsync_end = 800 + 168 + 64,
432 .htotal = 800 + 168 + 64 + 88,
433 .vdisplay = 480,
434 .vsync_start = 480 + 37,
435 .vsync_end = 480 + 37 + 2,
436 .vtotal = 480 + 37 + 2 + 8,
437 .vrefresh = 60,
438};
439
440static const struct panel_desc foxlink_fl500wvr00_a0t = {
441 .modes = &foxlink_fl500wvr00_a0t_mode,
442 .num_modes = 1,
443 .size = {
444 .width = 108,
445 .height = 65,
446 },
447};
448
Thierry Reding0a2288c2014-07-03 14:02:59 +0200449static const struct drm_display_mode innolux_n116bge_mode = {
450 .clock = 71000,
451 .hdisplay = 1366,
452 .hsync_start = 1366 + 64,
453 .hsync_end = 1366 + 64 + 6,
454 .htotal = 1366 + 64 + 6 + 64,
455 .vdisplay = 768,
456 .vsync_start = 768 + 8,
457 .vsync_end = 768 + 8 + 4,
458 .vtotal = 768 + 8 + 4 + 8,
459 .vrefresh = 60,
460 .flags = DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC,
461};
462
463static const struct panel_desc innolux_n116bge = {
464 .modes = &innolux_n116bge_mode,
465 .num_modes = 1,
466 .bpc = 6,
467 .size = {
468 .width = 256,
469 .height = 144,
470 },
471};
472
Alban Bedelea447392014-07-22 08:38:55 +0200473static const struct drm_display_mode innolux_n156bge_l21_mode = {
474 .clock = 69300,
475 .hdisplay = 1366,
476 .hsync_start = 1366 + 16,
477 .hsync_end = 1366 + 16 + 34,
478 .htotal = 1366 + 16 + 34 + 50,
479 .vdisplay = 768,
480 .vsync_start = 768 + 2,
481 .vsync_end = 768 + 2 + 6,
482 .vtotal = 768 + 2 + 6 + 12,
483 .vrefresh = 60,
484};
485
486static const struct panel_desc innolux_n156bge_l21 = {
487 .modes = &innolux_n156bge_l21_mode,
488 .num_modes = 1,
Stéphane Marchesin0208d512014-06-19 18:18:28 -0700489 .bpc = 6,
Alban Bedelea447392014-07-22 08:38:55 +0200490 .size = {
491 .width = 344,
492 .height = 193,
493 },
494};
495
Thierry Redingec7c5652013-11-15 15:59:32 +0100496static const struct drm_display_mode lg_lp129qe_mode = {
497 .clock = 285250,
498 .hdisplay = 2560,
499 .hsync_start = 2560 + 48,
500 .hsync_end = 2560 + 48 + 32,
501 .htotal = 2560 + 48 + 32 + 80,
502 .vdisplay = 1700,
503 .vsync_start = 1700 + 3,
504 .vsync_end = 1700 + 3 + 10,
505 .vtotal = 1700 + 3 + 10 + 36,
506 .vrefresh = 60,
507};
508
509static const struct panel_desc lg_lp129qe = {
510 .modes = &lg_lp129qe_mode,
511 .num_modes = 1,
Stéphane Marchesin0208d512014-06-19 18:18:28 -0700512 .bpc = 8,
Thierry Redingec7c5652013-11-15 15:59:32 +0100513 .size = {
514 .width = 272,
515 .height = 181,
516 },
517};
518
Marc Dietrich6d54e3d2013-12-21 21:38:12 +0100519static const struct drm_display_mode samsung_ltn101nt05_mode = {
520 .clock = 54030,
521 .hdisplay = 1024,
522 .hsync_start = 1024 + 24,
523 .hsync_end = 1024 + 24 + 136,
524 .htotal = 1024 + 24 + 136 + 160,
525 .vdisplay = 600,
526 .vsync_start = 600 + 3,
527 .vsync_end = 600 + 3 + 6,
528 .vtotal = 600 + 3 + 6 + 61,
529 .vrefresh = 60,
530};
531
532static const struct panel_desc samsung_ltn101nt05 = {
533 .modes = &samsung_ltn101nt05_mode,
534 .num_modes = 1,
Stéphane Marchesin0208d512014-06-19 18:18:28 -0700535 .bpc = 6,
Marc Dietrich6d54e3d2013-12-21 21:38:12 +0100536 .size = {
537 .width = 1024,
538 .height = 600,
539 },
540};
541
Thierry Reding280921d2013-08-30 15:10:14 +0200542static const struct of_device_id platform_of_match[] = {
543 {
544 .compatible = "auo,b101aw03",
545 .data = &auo_b101aw03,
546 }, {
Stéphane Marchesina333f7a2014-05-23 19:27:59 -0700547 .compatible = "auo,b133xtn01",
548 .data = &auo_b133xtn01,
549 }, {
Stephen Warren4c930752014-01-07 16:46:26 -0700550 .compatible = "chunghwa,claa101wa01a",
551 .data = &chunghwa_claa101wa01a
552 }, {
Thierry Reding280921d2013-08-30 15:10:14 +0200553 .compatible = "chunghwa,claa101wb01",
554 .data = &chunghwa_claa101wb01
555 }, {
Stefan Agner26ab0062014-05-15 11:38:45 +0200556 .compatible = "edt,et057090dhu",
557 .data = &edt_et057090dhu,
558 }, {
Philipp Zabelfff5de42014-05-15 12:25:47 +0200559 .compatible = "edt,et070080dh6",
560 .data = &edt_etm0700g0dh6,
561 }, {
562 .compatible = "edt,etm0700g0dh6",
563 .data = &edt_etm0700g0dh6,
564 }, {
Boris BREZILLON102932b2014-06-05 15:53:32 +0200565 .compatible = "foxlink,fl500wvr00-a0t",
566 .data = &foxlink_fl500wvr00_a0t,
567 }, {
Thierry Reding0a2288c2014-07-03 14:02:59 +0200568 .compatible = "innolux,n116bge",
569 .data = &innolux_n116bge,
570 }, {
Alban Bedelea447392014-07-22 08:38:55 +0200571 .compatible = "innolux,n156bge-l21",
572 .data = &innolux_n156bge_l21,
573 }, {
Thierry Redingec7c5652013-11-15 15:59:32 +0100574 .compatible = "lg,lp129qe",
575 .data = &lg_lp129qe,
576 }, {
Marc Dietrich6d54e3d2013-12-21 21:38:12 +0100577 .compatible = "samsung,ltn101nt05",
578 .data = &samsung_ltn101nt05,
579 }, {
Thierry Reding280921d2013-08-30 15:10:14 +0200580 /* sentinel */
581 }
582};
583MODULE_DEVICE_TABLE(of, platform_of_match);
584
585static int panel_simple_platform_probe(struct platform_device *pdev)
586{
587 const struct of_device_id *id;
588
589 id = of_match_node(platform_of_match, pdev->dev.of_node);
590 if (!id)
591 return -ENODEV;
592
593 return panel_simple_probe(&pdev->dev, id->data);
594}
595
596static int panel_simple_platform_remove(struct platform_device *pdev)
597{
598 return panel_simple_remove(&pdev->dev);
599}
600
Thierry Redingd02fd932014-04-29 17:21:21 +0200601static void panel_simple_platform_shutdown(struct platform_device *pdev)
602{
603 panel_simple_shutdown(&pdev->dev);
604}
605
Thierry Reding280921d2013-08-30 15:10:14 +0200606static struct platform_driver panel_simple_platform_driver = {
607 .driver = {
608 .name = "panel-simple",
609 .owner = THIS_MODULE,
610 .of_match_table = platform_of_match,
611 },
612 .probe = panel_simple_platform_probe,
613 .remove = panel_simple_platform_remove,
Thierry Redingd02fd932014-04-29 17:21:21 +0200614 .shutdown = panel_simple_platform_shutdown,
Thierry Reding280921d2013-08-30 15:10:14 +0200615};
616
Thierry Reding210fcd92013-11-22 19:27:11 +0100617struct panel_desc_dsi {
618 struct panel_desc desc;
619
Thierry Reding462658b2014-03-14 11:24:57 +0100620 unsigned long flags;
Thierry Reding210fcd92013-11-22 19:27:11 +0100621 enum mipi_dsi_pixel_format format;
622 unsigned int lanes;
623};
624
Alexandre Courbot712ac1b2014-01-21 18:57:10 +0900625static const struct drm_display_mode lg_ld070wx3_sl01_mode = {
626 .clock = 71000,
627 .hdisplay = 800,
628 .hsync_start = 800 + 32,
629 .hsync_end = 800 + 32 + 1,
630 .htotal = 800 + 32 + 1 + 57,
631 .vdisplay = 1280,
632 .vsync_start = 1280 + 28,
633 .vsync_end = 1280 + 28 + 1,
634 .vtotal = 1280 + 28 + 1 + 14,
635 .vrefresh = 60,
636};
637
638static const struct panel_desc_dsi lg_ld070wx3_sl01 = {
639 .desc = {
640 .modes = &lg_ld070wx3_sl01_mode,
641 .num_modes = 1,
642 .size = {
643 .width = 94,
644 .height = 151,
645 },
646 },
Alexandre Courbot5e4cc272014-07-08 21:32:12 +0900647 .flags = MIPI_DSI_MODE_VIDEO | MIPI_DSI_CLOCK_NON_CONTINUOUS,
Alexandre Courbot712ac1b2014-01-21 18:57:10 +0900648 .format = MIPI_DSI_FMT_RGB888,
649 .lanes = 4,
650};
651
Alexandre Courbot499ce852014-01-21 18:57:09 +0900652static const struct drm_display_mode lg_lh500wx1_sd03_mode = {
653 .clock = 67000,
654 .hdisplay = 720,
655 .hsync_start = 720 + 12,
656 .hsync_end = 720 + 12 + 4,
657 .htotal = 720 + 12 + 4 + 112,
658 .vdisplay = 1280,
659 .vsync_start = 1280 + 8,
660 .vsync_end = 1280 + 8 + 4,
661 .vtotal = 1280 + 8 + 4 + 12,
662 .vrefresh = 60,
663};
664
665static const struct panel_desc_dsi lg_lh500wx1_sd03 = {
666 .desc = {
667 .modes = &lg_lh500wx1_sd03_mode,
668 .num_modes = 1,
669 .size = {
670 .width = 62,
671 .height = 110,
672 },
673 },
674 .flags = MIPI_DSI_MODE_VIDEO,
675 .format = MIPI_DSI_FMT_RGB888,
676 .lanes = 4,
677};
678
Thierry Reding280921d2013-08-30 15:10:14 +0200679static const struct drm_display_mode panasonic_vvx10f004b00_mode = {
680 .clock = 157200,
681 .hdisplay = 1920,
682 .hsync_start = 1920 + 154,
683 .hsync_end = 1920 + 154 + 16,
684 .htotal = 1920 + 154 + 16 + 32,
685 .vdisplay = 1200,
686 .vsync_start = 1200 + 17,
687 .vsync_end = 1200 + 17 + 2,
688 .vtotal = 1200 + 17 + 2 + 16,
689 .vrefresh = 60,
690};
691
Thierry Reding210fcd92013-11-22 19:27:11 +0100692static const struct panel_desc_dsi panasonic_vvx10f004b00 = {
693 .desc = {
694 .modes = &panasonic_vvx10f004b00_mode,
695 .num_modes = 1,
696 .size = {
697 .width = 217,
698 .height = 136,
699 },
Thierry Reding280921d2013-08-30 15:10:14 +0200700 },
Alexandre Courbot5e4cc272014-07-08 21:32:12 +0900701 .flags = MIPI_DSI_MODE_VIDEO | MIPI_DSI_MODE_VIDEO_SYNC_PULSE |
702 MIPI_DSI_CLOCK_NON_CONTINUOUS,
Thierry Reding210fcd92013-11-22 19:27:11 +0100703 .format = MIPI_DSI_FMT_RGB888,
704 .lanes = 4,
705};
706
707static const struct of_device_id dsi_of_match[] = {
708 {
Alexandre Courbot712ac1b2014-01-21 18:57:10 +0900709 .compatible = "lg,ld070wx3-sl01",
710 .data = &lg_ld070wx3_sl01
711 }, {
Alexandre Courbot499ce852014-01-21 18:57:09 +0900712 .compatible = "lg,lh500wx1-sd03",
713 .data = &lg_lh500wx1_sd03
714 }, {
Thierry Reding210fcd92013-11-22 19:27:11 +0100715 .compatible = "panasonic,vvx10f004b00",
716 .data = &panasonic_vvx10f004b00
717 }, {
718 /* sentinel */
719 }
720};
721MODULE_DEVICE_TABLE(of, dsi_of_match);
722
723static int panel_simple_dsi_probe(struct mipi_dsi_device *dsi)
724{
725 const struct panel_desc_dsi *desc;
726 const struct of_device_id *id;
727 int err;
728
729 id = of_match_node(dsi_of_match, dsi->dev.of_node);
730 if (!id)
731 return -ENODEV;
732
733 desc = id->data;
734
735 err = panel_simple_probe(&dsi->dev, &desc->desc);
736 if (err < 0)
737 return err;
738
Thierry Reding462658b2014-03-14 11:24:57 +0100739 dsi->mode_flags = desc->flags;
Thierry Reding210fcd92013-11-22 19:27:11 +0100740 dsi->format = desc->format;
741 dsi->lanes = desc->lanes;
742
743 return mipi_dsi_attach(dsi);
744}
745
746static int panel_simple_dsi_remove(struct mipi_dsi_device *dsi)
747{
748 int err;
749
750 err = mipi_dsi_detach(dsi);
751 if (err < 0)
752 dev_err(&dsi->dev, "failed to detach from DSI host: %d\n", err);
753
754 return panel_simple_remove(&dsi->dev);
755}
756
Thierry Redingd02fd932014-04-29 17:21:21 +0200757static void panel_simple_dsi_shutdown(struct mipi_dsi_device *dsi)
758{
759 panel_simple_shutdown(&dsi->dev);
760}
761
Thierry Reding210fcd92013-11-22 19:27:11 +0100762static struct mipi_dsi_driver panel_simple_dsi_driver = {
763 .driver = {
764 .name = "panel-simple-dsi",
765 .owner = THIS_MODULE,
766 .of_match_table = dsi_of_match,
767 },
768 .probe = panel_simple_dsi_probe,
769 .remove = panel_simple_dsi_remove,
Thierry Redingd02fd932014-04-29 17:21:21 +0200770 .shutdown = panel_simple_dsi_shutdown,
Thierry Reding280921d2013-08-30 15:10:14 +0200771};
772
773static int __init panel_simple_init(void)
774{
Thierry Reding210fcd92013-11-22 19:27:11 +0100775 int err;
776
777 err = platform_driver_register(&panel_simple_platform_driver);
778 if (err < 0)
779 return err;
780
781 if (IS_ENABLED(CONFIG_DRM_MIPI_DSI)) {
782 err = mipi_dsi_driver_register(&panel_simple_dsi_driver);
783 if (err < 0)
784 return err;
785 }
786
787 return 0;
Thierry Reding280921d2013-08-30 15:10:14 +0200788}
789module_init(panel_simple_init);
790
791static void __exit panel_simple_exit(void)
792{
Thierry Reding210fcd92013-11-22 19:27:11 +0100793 if (IS_ENABLED(CONFIG_DRM_MIPI_DSI))
794 mipi_dsi_driver_unregister(&panel_simple_dsi_driver);
795
Thierry Reding280921d2013-08-30 15:10:14 +0200796 platform_driver_unregister(&panel_simple_platform_driver);
797}
798module_exit(panel_simple_exit);
799
800MODULE_AUTHOR("Thierry Reding <treding@nvidia.com>");
801MODULE_DESCRIPTION("DRM Driver for Simple Panels");
802MODULE_LICENSE("GPL and additional rights");