blob: de78d3e0f22627aa2c5a4bb4faa09d644a8bd804 [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;
Ajay Kumarf673c372014-07-31 23:12:11 +053046
47 /**
48 * @prepare: the time (in milliseconds) that it takes for the panel to
49 * become ready and start receiving video data
50 * @enable: the time (in milliseconds) that it takes for the panel to
51 * display the first valid frame after starting to receive
52 * video data
53 * @disable: the time (in milliseconds) that it takes for the panel to
54 * turn the display off (no content is visible)
55 * @unprepare: the time (in milliseconds) that it takes for the panel
56 * to power itself down completely
57 */
58 struct {
59 unsigned int prepare;
60 unsigned int enable;
61 unsigned int disable;
62 unsigned int unprepare;
63 } delay;
Thierry Reding280921d2013-08-30 15:10:14 +020064};
65
Thierry Reding280921d2013-08-30 15:10:14 +020066struct panel_simple {
67 struct drm_panel base;
Ajay Kumar613a6332014-07-31 23:12:10 +053068 bool prepared;
Thierry Reding280921d2013-08-30 15:10:14 +020069 bool enabled;
70
71 const struct panel_desc *desc;
72
73 struct backlight_device *backlight;
74 struct regulator *supply;
75 struct i2c_adapter *ddc;
76
Alexandre Courbotcfdf0542014-03-01 14:00:58 +090077 struct gpio_desc *enable_gpio;
Thierry Reding280921d2013-08-30 15:10:14 +020078};
79
80static inline struct panel_simple *to_panel_simple(struct drm_panel *panel)
81{
82 return container_of(panel, struct panel_simple, base);
83}
84
85static int panel_simple_get_fixed_modes(struct panel_simple *panel)
86{
87 struct drm_connector *connector = panel->base.connector;
88 struct drm_device *drm = panel->base.drm;
89 struct drm_display_mode *mode;
90 unsigned int i, num = 0;
91
92 if (!panel->desc)
93 return 0;
94
95 for (i = 0; i < panel->desc->num_modes; i++) {
96 const struct drm_display_mode *m = &panel->desc->modes[i];
97
98 mode = drm_mode_duplicate(drm, m);
99 if (!mode) {
100 dev_err(drm->dev, "failed to add mode %ux%u@%u\n",
101 m->hdisplay, m->vdisplay, m->vrefresh);
102 continue;
103 }
104
105 drm_mode_set_name(mode);
106
107 drm_mode_probed_add(connector, mode);
108 num++;
109 }
110
Stéphane Marchesin0208d512014-06-19 18:18:28 -0700111 connector->display_info.bpc = panel->desc->bpc;
Thierry Reding280921d2013-08-30 15:10:14 +0200112 connector->display_info.width_mm = panel->desc->size.width;
113 connector->display_info.height_mm = panel->desc->size.height;
114
115 return num;
116}
117
118static int panel_simple_disable(struct drm_panel *panel)
119{
120 struct panel_simple *p = to_panel_simple(panel);
121
122 if (!p->enabled)
123 return 0;
124
125 if (p->backlight) {
126 p->backlight->props.power = FB_BLANK_POWERDOWN;
127 backlight_update_status(p->backlight);
128 }
129
Ajay Kumarf673c372014-07-31 23:12:11 +0530130 if (p->desc->delay.disable)
131 msleep(p->desc->delay.disable);
132
Thierry Reding280921d2013-08-30 15:10:14 +0200133 p->enabled = false;
134
135 return 0;
136}
137
Ajay Kumarc0e1d172014-07-31 23:12:04 +0530138static int panel_simple_unprepare(struct drm_panel *panel)
139{
Ajay Kumar613a6332014-07-31 23:12:10 +0530140 struct panel_simple *p = to_panel_simple(panel);
141
142 if (!p->prepared)
143 return 0;
144
145 if (p->enable_gpio)
146 gpiod_set_value_cansleep(p->enable_gpio, 0);
147
148 regulator_disable(p->supply);
149
Ajay Kumarf673c372014-07-31 23:12:11 +0530150 if (p->desc->delay.unprepare)
151 msleep(p->desc->delay.unprepare);
152
Ajay Kumar613a6332014-07-31 23:12:10 +0530153 p->prepared = false;
154
Ajay Kumarc0e1d172014-07-31 23:12:04 +0530155 return 0;
156}
157
158static int panel_simple_prepare(struct drm_panel *panel)
159{
Thierry Reding280921d2013-08-30 15:10:14 +0200160 struct panel_simple *p = to_panel_simple(panel);
161 int err;
162
Ajay Kumar613a6332014-07-31 23:12:10 +0530163 if (p->prepared)
Thierry Reding280921d2013-08-30 15:10:14 +0200164 return 0;
165
166 err = regulator_enable(p->supply);
167 if (err < 0) {
168 dev_err(panel->dev, "failed to enable supply: %d\n", err);
169 return err;
170 }
171
Alexandre Courbotcfdf0542014-03-01 14:00:58 +0900172 if (p->enable_gpio)
Thierry Reding15c1a912014-03-14 12:03:47 +0100173 gpiod_set_value_cansleep(p->enable_gpio, 1);
Thierry Reding280921d2013-08-30 15:10:14 +0200174
Ajay Kumarf673c372014-07-31 23:12:11 +0530175 if (p->desc->delay.prepare)
176 msleep(p->desc->delay.prepare);
177
Ajay Kumar613a6332014-07-31 23:12:10 +0530178 p->prepared = true;
179
180 return 0;
181}
182
183static int panel_simple_enable(struct drm_panel *panel)
184{
185 struct panel_simple *p = to_panel_simple(panel);
186
187 if (p->enabled)
188 return 0;
189
Ajay Kumarf673c372014-07-31 23:12:11 +0530190 if (p->desc->delay.enable)
191 msleep(p->desc->delay.enable);
192
Thierry Reding280921d2013-08-30 15:10:14 +0200193 if (p->backlight) {
194 p->backlight->props.power = FB_BLANK_UNBLANK;
195 backlight_update_status(p->backlight);
196 }
197
198 p->enabled = true;
199
200 return 0;
201}
202
203static int panel_simple_get_modes(struct drm_panel *panel)
204{
205 struct panel_simple *p = to_panel_simple(panel);
206 int num = 0;
207
208 /* probe EDID if a DDC bus is available */
209 if (p->ddc) {
210 struct edid *edid = drm_get_edid(panel->connector, p->ddc);
Stephen Warren70bf6872014-01-09 11:37:34 -0700211 drm_mode_connector_update_edid_property(panel->connector, edid);
Thierry Reding280921d2013-08-30 15:10:14 +0200212 if (edid) {
213 num += drm_add_edid_modes(panel->connector, edid);
214 kfree(edid);
215 }
216 }
217
218 /* add hard-coded panel modes */
219 num += panel_simple_get_fixed_modes(p);
220
221 return num;
222}
223
224static const struct drm_panel_funcs panel_simple_funcs = {
225 .disable = panel_simple_disable,
Ajay Kumarc0e1d172014-07-31 23:12:04 +0530226 .unprepare = panel_simple_unprepare,
227 .prepare = panel_simple_prepare,
Thierry Reding280921d2013-08-30 15:10:14 +0200228 .enable = panel_simple_enable,
229 .get_modes = panel_simple_get_modes,
230};
231
232static int panel_simple_probe(struct device *dev, const struct panel_desc *desc)
233{
234 struct device_node *backlight, *ddc;
235 struct panel_simple *panel;
Thierry Reding280921d2013-08-30 15:10:14 +0200236 int err;
237
238 panel = devm_kzalloc(dev, sizeof(*panel), GFP_KERNEL);
239 if (!panel)
240 return -ENOMEM;
241
242 panel->enabled = false;
Ajay Kumar613a6332014-07-31 23:12:10 +0530243 panel->prepared = false;
Thierry Reding280921d2013-08-30 15:10:14 +0200244 panel->desc = desc;
245
246 panel->supply = devm_regulator_get(dev, "power");
247 if (IS_ERR(panel->supply))
248 return PTR_ERR(panel->supply);
249
Alexandre Courbota61400d2014-10-23 17:16:58 +0900250 panel->enable_gpio = devm_gpiod_get_optional(dev, "enable",
251 GPIOD_OUT_LOW);
Alexandre Courbotcfdf0542014-03-01 14:00:58 +0900252 if (IS_ERR(panel->enable_gpio)) {
253 err = PTR_ERR(panel->enable_gpio);
Alexandre Courbot9746c612014-07-25 23:47:25 +0900254 dev_err(dev, "failed to request GPIO: %d\n", err);
255 return err;
256 }
Thierry Reding280921d2013-08-30 15:10:14 +0200257
Thierry Reding280921d2013-08-30 15:10:14 +0200258 backlight = of_parse_phandle(dev->of_node, "backlight", 0);
259 if (backlight) {
260 panel->backlight = of_find_backlight_by_node(backlight);
261 of_node_put(backlight);
262
Alexandre Courbotcfdf0542014-03-01 14:00:58 +0900263 if (!panel->backlight)
264 return -EPROBE_DEFER;
Thierry Reding280921d2013-08-30 15:10:14 +0200265 }
266
267 ddc = of_parse_phandle(dev->of_node, "ddc-i2c-bus", 0);
268 if (ddc) {
269 panel->ddc = of_find_i2c_adapter_by_node(ddc);
270 of_node_put(ddc);
271
272 if (!panel->ddc) {
273 err = -EPROBE_DEFER;
274 goto free_backlight;
275 }
276 }
277
278 drm_panel_init(&panel->base);
279 panel->base.dev = dev;
280 panel->base.funcs = &panel_simple_funcs;
281
282 err = drm_panel_add(&panel->base);
283 if (err < 0)
284 goto free_ddc;
285
286 dev_set_drvdata(dev, panel);
287
288 return 0;
289
290free_ddc:
291 if (panel->ddc)
292 put_device(&panel->ddc->dev);
293free_backlight:
294 if (panel->backlight)
295 put_device(&panel->backlight->dev);
Thierry Reding280921d2013-08-30 15:10:14 +0200296
297 return err;
298}
299
300static int panel_simple_remove(struct device *dev)
301{
302 struct panel_simple *panel = dev_get_drvdata(dev);
303
304 drm_panel_detach(&panel->base);
305 drm_panel_remove(&panel->base);
306
307 panel_simple_disable(&panel->base);
308
309 if (panel->ddc)
310 put_device(&panel->ddc->dev);
311
312 if (panel->backlight)
313 put_device(&panel->backlight->dev);
314
Thierry Reding280921d2013-08-30 15:10:14 +0200315 return 0;
316}
317
Thierry Redingd02fd932014-04-29 17:21:21 +0200318static void panel_simple_shutdown(struct device *dev)
319{
320 struct panel_simple *panel = dev_get_drvdata(dev);
321
322 panel_simple_disable(&panel->base);
323}
324
Thierry Reding280921d2013-08-30 15:10:14 +0200325static const struct drm_display_mode auo_b101aw03_mode = {
326 .clock = 51450,
327 .hdisplay = 1024,
328 .hsync_start = 1024 + 156,
329 .hsync_end = 1024 + 156 + 8,
330 .htotal = 1024 + 156 + 8 + 156,
331 .vdisplay = 600,
332 .vsync_start = 600 + 16,
333 .vsync_end = 600 + 16 + 6,
334 .vtotal = 600 + 16 + 6 + 16,
335 .vrefresh = 60,
336};
337
338static const struct panel_desc auo_b101aw03 = {
339 .modes = &auo_b101aw03_mode,
340 .num_modes = 1,
Stéphane Marchesin0208d512014-06-19 18:18:28 -0700341 .bpc = 6,
Thierry Reding280921d2013-08-30 15:10:14 +0200342 .size = {
343 .width = 223,
344 .height = 125,
345 },
346};
347
Rob Clarkdac746e2014-08-01 17:01:06 -0400348static const struct drm_display_mode auo_b101xtn01_mode = {
349 .clock = 72000,
350 .hdisplay = 1366,
351 .hsync_start = 1366 + 20,
352 .hsync_end = 1366 + 20 + 70,
353 .htotal = 1366 + 20 + 70,
354 .vdisplay = 768,
355 .vsync_start = 768 + 14,
356 .vsync_end = 768 + 14 + 42,
357 .vtotal = 768 + 14 + 42,
358 .vrefresh = 60,
359 .flags = DRM_MODE_FLAG_NVSYNC | DRM_MODE_FLAG_NHSYNC,
360};
361
362static const struct panel_desc auo_b101xtn01 = {
363 .modes = &auo_b101xtn01_mode,
364 .num_modes = 1,
365 .bpc = 6,
366 .size = {
367 .width = 223,
368 .height = 125,
369 },
370};
371
Stéphane Marchesina333f7a2014-05-23 19:27:59 -0700372static const struct drm_display_mode auo_b133xtn01_mode = {
373 .clock = 69500,
374 .hdisplay = 1366,
375 .hsync_start = 1366 + 48,
376 .hsync_end = 1366 + 48 + 32,
377 .htotal = 1366 + 48 + 32 + 20,
378 .vdisplay = 768,
379 .vsync_start = 768 + 3,
380 .vsync_end = 768 + 3 + 6,
381 .vtotal = 768 + 3 + 6 + 13,
382 .vrefresh = 60,
383};
384
385static const struct panel_desc auo_b133xtn01 = {
386 .modes = &auo_b133xtn01_mode,
387 .num_modes = 1,
Stéphane Marchesin0208d512014-06-19 18:18:28 -0700388 .bpc = 6,
Stéphane Marchesina333f7a2014-05-23 19:27:59 -0700389 .size = {
390 .width = 293,
391 .height = 165,
392 },
393};
394
Ajay Kumar3e51d602014-07-31 23:12:12 +0530395static const struct drm_display_mode auo_b133htn01_mode = {
396 .clock = 150660,
397 .hdisplay = 1920,
398 .hsync_start = 1920 + 172,
399 .hsync_end = 1920 + 172 + 80,
400 .htotal = 1920 + 172 + 80 + 60,
401 .vdisplay = 1080,
402 .vsync_start = 1080 + 25,
403 .vsync_end = 1080 + 25 + 10,
404 .vtotal = 1080 + 25 + 10 + 10,
405 .vrefresh = 60,
406};
407
408static const struct panel_desc auo_b133htn01 = {
409 .modes = &auo_b133htn01_mode,
410 .num_modes = 1,
411 .size = {
412 .width = 293,
413 .height = 165,
414 },
415 .delay = {
416 .prepare = 105,
417 .enable = 20,
418 .unprepare = 50,
419 },
420};
421
Stephen Warren4c930752014-01-07 16:46:26 -0700422static const struct drm_display_mode chunghwa_claa101wa01a_mode = {
423 .clock = 72070,
424 .hdisplay = 1366,
425 .hsync_start = 1366 + 58,
426 .hsync_end = 1366 + 58 + 58,
427 .htotal = 1366 + 58 + 58 + 58,
428 .vdisplay = 768,
429 .vsync_start = 768 + 4,
430 .vsync_end = 768 + 4 + 4,
431 .vtotal = 768 + 4 + 4 + 4,
432 .vrefresh = 60,
433};
434
435static const struct panel_desc chunghwa_claa101wa01a = {
436 .modes = &chunghwa_claa101wa01a_mode,
437 .num_modes = 1,
Stéphane Marchesin0208d512014-06-19 18:18:28 -0700438 .bpc = 6,
Stephen Warren4c930752014-01-07 16:46:26 -0700439 .size = {
440 .width = 220,
441 .height = 120,
442 },
443};
444
Thierry Reding280921d2013-08-30 15:10:14 +0200445static const struct drm_display_mode chunghwa_claa101wb01_mode = {
446 .clock = 69300,
447 .hdisplay = 1366,
448 .hsync_start = 1366 + 48,
449 .hsync_end = 1366 + 48 + 32,
450 .htotal = 1366 + 48 + 32 + 20,
451 .vdisplay = 768,
452 .vsync_start = 768 + 16,
453 .vsync_end = 768 + 16 + 8,
454 .vtotal = 768 + 16 + 8 + 16,
455 .vrefresh = 60,
456};
457
458static const struct panel_desc chunghwa_claa101wb01 = {
459 .modes = &chunghwa_claa101wb01_mode,
460 .num_modes = 1,
Stéphane Marchesin0208d512014-06-19 18:18:28 -0700461 .bpc = 6,
Thierry Reding280921d2013-08-30 15:10:14 +0200462 .size = {
463 .width = 223,
464 .height = 125,
465 },
466};
467
Stefan Agner26ab0062014-05-15 11:38:45 +0200468static const struct drm_display_mode edt_et057090dhu_mode = {
469 .clock = 25175,
470 .hdisplay = 640,
471 .hsync_start = 640 + 16,
472 .hsync_end = 640 + 16 + 30,
473 .htotal = 640 + 16 + 30 + 114,
474 .vdisplay = 480,
475 .vsync_start = 480 + 10,
476 .vsync_end = 480 + 10 + 3,
477 .vtotal = 480 + 10 + 3 + 32,
478 .vrefresh = 60,
479 .flags = DRM_MODE_FLAG_NVSYNC | DRM_MODE_FLAG_NHSYNC,
480};
481
482static const struct panel_desc edt_et057090dhu = {
483 .modes = &edt_et057090dhu_mode,
484 .num_modes = 1,
Stéphane Marchesin0208d512014-06-19 18:18:28 -0700485 .bpc = 6,
Stefan Agner26ab0062014-05-15 11:38:45 +0200486 .size = {
487 .width = 115,
488 .height = 86,
489 },
490};
491
Philipp Zabelfff5de42014-05-15 12:25:47 +0200492static const struct drm_display_mode edt_etm0700g0dh6_mode = {
493 .clock = 33260,
494 .hdisplay = 800,
495 .hsync_start = 800 + 40,
496 .hsync_end = 800 + 40 + 128,
497 .htotal = 800 + 40 + 128 + 88,
498 .vdisplay = 480,
499 .vsync_start = 480 + 10,
500 .vsync_end = 480 + 10 + 2,
501 .vtotal = 480 + 10 + 2 + 33,
502 .vrefresh = 60,
503 .flags = DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC,
504};
505
506static const struct panel_desc edt_etm0700g0dh6 = {
507 .modes = &edt_etm0700g0dh6_mode,
508 .num_modes = 1,
Stéphane Marchesin0208d512014-06-19 18:18:28 -0700509 .bpc = 6,
Philipp Zabelfff5de42014-05-15 12:25:47 +0200510 .size = {
511 .width = 152,
512 .height = 91,
513 },
514};
515
Boris BREZILLON102932b2014-06-05 15:53:32 +0200516static const struct drm_display_mode foxlink_fl500wvr00_a0t_mode = {
517 .clock = 32260,
518 .hdisplay = 800,
519 .hsync_start = 800 + 168,
520 .hsync_end = 800 + 168 + 64,
521 .htotal = 800 + 168 + 64 + 88,
522 .vdisplay = 480,
523 .vsync_start = 480 + 37,
524 .vsync_end = 480 + 37 + 2,
525 .vtotal = 480 + 37 + 2 + 8,
526 .vrefresh = 60,
527};
528
529static const struct panel_desc foxlink_fl500wvr00_a0t = {
530 .modes = &foxlink_fl500wvr00_a0t_mode,
531 .num_modes = 1,
532 .size = {
533 .width = 108,
534 .height = 65,
535 },
536};
537
Philipp Zabela8532052014-10-23 16:31:06 +0200538static const struct drm_display_mode hannstar_hsd070pww1_mode = {
539 .clock = 71100,
540 .hdisplay = 1280,
541 .hsync_start = 1280 + 1,
542 .hsync_end = 1280 + 1 + 158,
543 .htotal = 1280 + 1 + 158 + 1,
544 .vdisplay = 800,
545 .vsync_start = 800 + 1,
546 .vsync_end = 800 + 1 + 21,
547 .vtotal = 800 + 1 + 21 + 1,
548 .vrefresh = 60,
549};
550
551static const struct panel_desc hannstar_hsd070pww1 = {
552 .modes = &hannstar_hsd070pww1_mode,
553 .num_modes = 1,
554 .bpc = 6,
555 .size = {
556 .width = 151,
557 .height = 94,
558 },
559};
560
Thierry Reding0a2288c2014-07-03 14:02:59 +0200561static const struct drm_display_mode innolux_n116bge_mode = {
562 .clock = 71000,
563 .hdisplay = 1366,
564 .hsync_start = 1366 + 64,
565 .hsync_end = 1366 + 64 + 6,
566 .htotal = 1366 + 64 + 6 + 64,
567 .vdisplay = 768,
568 .vsync_start = 768 + 8,
569 .vsync_end = 768 + 8 + 4,
570 .vtotal = 768 + 8 + 4 + 8,
571 .vrefresh = 60,
572 .flags = DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC,
573};
574
575static const struct panel_desc innolux_n116bge = {
576 .modes = &innolux_n116bge_mode,
577 .num_modes = 1,
578 .bpc = 6,
579 .size = {
580 .width = 256,
581 .height = 144,
582 },
583};
584
Alban Bedelea447392014-07-22 08:38:55 +0200585static const struct drm_display_mode innolux_n156bge_l21_mode = {
586 .clock = 69300,
587 .hdisplay = 1366,
588 .hsync_start = 1366 + 16,
589 .hsync_end = 1366 + 16 + 34,
590 .htotal = 1366 + 16 + 34 + 50,
591 .vdisplay = 768,
592 .vsync_start = 768 + 2,
593 .vsync_end = 768 + 2 + 6,
594 .vtotal = 768 + 2 + 6 + 12,
595 .vrefresh = 60,
596};
597
598static const struct panel_desc innolux_n156bge_l21 = {
599 .modes = &innolux_n156bge_l21_mode,
600 .num_modes = 1,
Stéphane Marchesin0208d512014-06-19 18:18:28 -0700601 .bpc = 6,
Alban Bedelea447392014-07-22 08:38:55 +0200602 .size = {
603 .width = 344,
604 .height = 193,
605 },
606};
607
Thierry Redingec7c5652013-11-15 15:59:32 +0100608static const struct drm_display_mode lg_lp129qe_mode = {
609 .clock = 285250,
610 .hdisplay = 2560,
611 .hsync_start = 2560 + 48,
612 .hsync_end = 2560 + 48 + 32,
613 .htotal = 2560 + 48 + 32 + 80,
614 .vdisplay = 1700,
615 .vsync_start = 1700 + 3,
616 .vsync_end = 1700 + 3 + 10,
617 .vtotal = 1700 + 3 + 10 + 36,
618 .vrefresh = 60,
619};
620
621static const struct panel_desc lg_lp129qe = {
622 .modes = &lg_lp129qe_mode,
623 .num_modes = 1,
Stéphane Marchesin0208d512014-06-19 18:18:28 -0700624 .bpc = 8,
Thierry Redingec7c5652013-11-15 15:59:32 +0100625 .size = {
626 .width = 272,
627 .height = 181,
628 },
629};
630
Marc Dietrich6d54e3d2013-12-21 21:38:12 +0100631static const struct drm_display_mode samsung_ltn101nt05_mode = {
632 .clock = 54030,
633 .hdisplay = 1024,
634 .hsync_start = 1024 + 24,
635 .hsync_end = 1024 + 24 + 136,
636 .htotal = 1024 + 24 + 136 + 160,
637 .vdisplay = 600,
638 .vsync_start = 600 + 3,
639 .vsync_end = 600 + 3 + 6,
640 .vtotal = 600 + 3 + 6 + 61,
641 .vrefresh = 60,
642};
643
644static const struct panel_desc samsung_ltn101nt05 = {
645 .modes = &samsung_ltn101nt05_mode,
646 .num_modes = 1,
Stéphane Marchesin0208d512014-06-19 18:18:28 -0700647 .bpc = 6,
Marc Dietrich6d54e3d2013-12-21 21:38:12 +0100648 .size = {
649 .width = 1024,
650 .height = 600,
651 },
652};
653
Thierry Reding280921d2013-08-30 15:10:14 +0200654static const struct of_device_id platform_of_match[] = {
655 {
656 .compatible = "auo,b101aw03",
657 .data = &auo_b101aw03,
658 }, {
Rob Clarkdac746e2014-08-01 17:01:06 -0400659 .compatible = "auo,b101xtn01",
660 .data = &auo_b101xtn01,
661 }, {
Ajay Kumar3e51d602014-07-31 23:12:12 +0530662 .compatible = "auo,b133htn01",
663 .data = &auo_b133htn01,
664 }, {
Stéphane Marchesina333f7a2014-05-23 19:27:59 -0700665 .compatible = "auo,b133xtn01",
666 .data = &auo_b133xtn01,
667 }, {
Stephen Warren4c930752014-01-07 16:46:26 -0700668 .compatible = "chunghwa,claa101wa01a",
669 .data = &chunghwa_claa101wa01a
670 }, {
Thierry Reding280921d2013-08-30 15:10:14 +0200671 .compatible = "chunghwa,claa101wb01",
672 .data = &chunghwa_claa101wb01
673 }, {
Stefan Agner26ab0062014-05-15 11:38:45 +0200674 .compatible = "edt,et057090dhu",
675 .data = &edt_et057090dhu,
676 }, {
Philipp Zabelfff5de42014-05-15 12:25:47 +0200677 .compatible = "edt,et070080dh6",
678 .data = &edt_etm0700g0dh6,
679 }, {
680 .compatible = "edt,etm0700g0dh6",
681 .data = &edt_etm0700g0dh6,
682 }, {
Boris BREZILLON102932b2014-06-05 15:53:32 +0200683 .compatible = "foxlink,fl500wvr00-a0t",
684 .data = &foxlink_fl500wvr00_a0t,
685 }, {
Philipp Zabela8532052014-10-23 16:31:06 +0200686 .compatible = "hannstar,hsd070pww1",
687 .data = &hannstar_hsd070pww1,
688 }, {
Thierry Reding0a2288c2014-07-03 14:02:59 +0200689 .compatible = "innolux,n116bge",
690 .data = &innolux_n116bge,
691 }, {
Alban Bedelea447392014-07-22 08:38:55 +0200692 .compatible = "innolux,n156bge-l21",
693 .data = &innolux_n156bge_l21,
694 }, {
Thierry Redingec7c5652013-11-15 15:59:32 +0100695 .compatible = "lg,lp129qe",
696 .data = &lg_lp129qe,
697 }, {
Marc Dietrich6d54e3d2013-12-21 21:38:12 +0100698 .compatible = "samsung,ltn101nt05",
699 .data = &samsung_ltn101nt05,
700 }, {
Thierry Reding280921d2013-08-30 15:10:14 +0200701 /* sentinel */
702 }
703};
704MODULE_DEVICE_TABLE(of, platform_of_match);
705
706static int panel_simple_platform_probe(struct platform_device *pdev)
707{
708 const struct of_device_id *id;
709
710 id = of_match_node(platform_of_match, pdev->dev.of_node);
711 if (!id)
712 return -ENODEV;
713
714 return panel_simple_probe(&pdev->dev, id->data);
715}
716
717static int panel_simple_platform_remove(struct platform_device *pdev)
718{
719 return panel_simple_remove(&pdev->dev);
720}
721
Thierry Redingd02fd932014-04-29 17:21:21 +0200722static void panel_simple_platform_shutdown(struct platform_device *pdev)
723{
724 panel_simple_shutdown(&pdev->dev);
725}
726
Thierry Reding280921d2013-08-30 15:10:14 +0200727static struct platform_driver panel_simple_platform_driver = {
728 .driver = {
729 .name = "panel-simple",
730 .owner = THIS_MODULE,
731 .of_match_table = platform_of_match,
732 },
733 .probe = panel_simple_platform_probe,
734 .remove = panel_simple_platform_remove,
Thierry Redingd02fd932014-04-29 17:21:21 +0200735 .shutdown = panel_simple_platform_shutdown,
Thierry Reding280921d2013-08-30 15:10:14 +0200736};
737
Thierry Reding210fcd92013-11-22 19:27:11 +0100738struct panel_desc_dsi {
739 struct panel_desc desc;
740
Thierry Reding462658b2014-03-14 11:24:57 +0100741 unsigned long flags;
Thierry Reding210fcd92013-11-22 19:27:11 +0100742 enum mipi_dsi_pixel_format format;
743 unsigned int lanes;
744};
745
Alexandre Courbot712ac1b2014-01-21 18:57:10 +0900746static const struct drm_display_mode lg_ld070wx3_sl01_mode = {
747 .clock = 71000,
748 .hdisplay = 800,
749 .hsync_start = 800 + 32,
750 .hsync_end = 800 + 32 + 1,
751 .htotal = 800 + 32 + 1 + 57,
752 .vdisplay = 1280,
753 .vsync_start = 1280 + 28,
754 .vsync_end = 1280 + 28 + 1,
755 .vtotal = 1280 + 28 + 1 + 14,
756 .vrefresh = 60,
757};
758
759static const struct panel_desc_dsi lg_ld070wx3_sl01 = {
760 .desc = {
761 .modes = &lg_ld070wx3_sl01_mode,
762 .num_modes = 1,
763 .size = {
764 .width = 94,
765 .height = 151,
766 },
767 },
Alexandre Courbot5e4cc272014-07-08 21:32:12 +0900768 .flags = MIPI_DSI_MODE_VIDEO | MIPI_DSI_CLOCK_NON_CONTINUOUS,
Alexandre Courbot712ac1b2014-01-21 18:57:10 +0900769 .format = MIPI_DSI_FMT_RGB888,
770 .lanes = 4,
771};
772
Alexandre Courbot499ce852014-01-21 18:57:09 +0900773static const struct drm_display_mode lg_lh500wx1_sd03_mode = {
774 .clock = 67000,
775 .hdisplay = 720,
776 .hsync_start = 720 + 12,
777 .hsync_end = 720 + 12 + 4,
778 .htotal = 720 + 12 + 4 + 112,
779 .vdisplay = 1280,
780 .vsync_start = 1280 + 8,
781 .vsync_end = 1280 + 8 + 4,
782 .vtotal = 1280 + 8 + 4 + 12,
783 .vrefresh = 60,
784};
785
786static const struct panel_desc_dsi lg_lh500wx1_sd03 = {
787 .desc = {
788 .modes = &lg_lh500wx1_sd03_mode,
789 .num_modes = 1,
790 .size = {
791 .width = 62,
792 .height = 110,
793 },
794 },
795 .flags = MIPI_DSI_MODE_VIDEO,
796 .format = MIPI_DSI_FMT_RGB888,
797 .lanes = 4,
798};
799
Thierry Reding280921d2013-08-30 15:10:14 +0200800static const struct drm_display_mode panasonic_vvx10f004b00_mode = {
801 .clock = 157200,
802 .hdisplay = 1920,
803 .hsync_start = 1920 + 154,
804 .hsync_end = 1920 + 154 + 16,
805 .htotal = 1920 + 154 + 16 + 32,
806 .vdisplay = 1200,
807 .vsync_start = 1200 + 17,
808 .vsync_end = 1200 + 17 + 2,
809 .vtotal = 1200 + 17 + 2 + 16,
810 .vrefresh = 60,
811};
812
Thierry Reding210fcd92013-11-22 19:27:11 +0100813static const struct panel_desc_dsi panasonic_vvx10f004b00 = {
814 .desc = {
815 .modes = &panasonic_vvx10f004b00_mode,
816 .num_modes = 1,
817 .size = {
818 .width = 217,
819 .height = 136,
820 },
Thierry Reding280921d2013-08-30 15:10:14 +0200821 },
Alexandre Courbot5e4cc272014-07-08 21:32:12 +0900822 .flags = MIPI_DSI_MODE_VIDEO | MIPI_DSI_MODE_VIDEO_SYNC_PULSE |
823 MIPI_DSI_CLOCK_NON_CONTINUOUS,
Thierry Reding210fcd92013-11-22 19:27:11 +0100824 .format = MIPI_DSI_FMT_RGB888,
825 .lanes = 4,
826};
827
828static const struct of_device_id dsi_of_match[] = {
829 {
Alexandre Courbot712ac1b2014-01-21 18:57:10 +0900830 .compatible = "lg,ld070wx3-sl01",
831 .data = &lg_ld070wx3_sl01
832 }, {
Alexandre Courbot499ce852014-01-21 18:57:09 +0900833 .compatible = "lg,lh500wx1-sd03",
834 .data = &lg_lh500wx1_sd03
835 }, {
Thierry Reding210fcd92013-11-22 19:27:11 +0100836 .compatible = "panasonic,vvx10f004b00",
837 .data = &panasonic_vvx10f004b00
838 }, {
839 /* sentinel */
840 }
841};
842MODULE_DEVICE_TABLE(of, dsi_of_match);
843
844static int panel_simple_dsi_probe(struct mipi_dsi_device *dsi)
845{
846 const struct panel_desc_dsi *desc;
847 const struct of_device_id *id;
848 int err;
849
850 id = of_match_node(dsi_of_match, dsi->dev.of_node);
851 if (!id)
852 return -ENODEV;
853
854 desc = id->data;
855
856 err = panel_simple_probe(&dsi->dev, &desc->desc);
857 if (err < 0)
858 return err;
859
Thierry Reding462658b2014-03-14 11:24:57 +0100860 dsi->mode_flags = desc->flags;
Thierry Reding210fcd92013-11-22 19:27:11 +0100861 dsi->format = desc->format;
862 dsi->lanes = desc->lanes;
863
864 return mipi_dsi_attach(dsi);
865}
866
867static int panel_simple_dsi_remove(struct mipi_dsi_device *dsi)
868{
869 int err;
870
871 err = mipi_dsi_detach(dsi);
872 if (err < 0)
873 dev_err(&dsi->dev, "failed to detach from DSI host: %d\n", err);
874
875 return panel_simple_remove(&dsi->dev);
876}
877
Thierry Redingd02fd932014-04-29 17:21:21 +0200878static void panel_simple_dsi_shutdown(struct mipi_dsi_device *dsi)
879{
880 panel_simple_shutdown(&dsi->dev);
881}
882
Thierry Reding210fcd92013-11-22 19:27:11 +0100883static struct mipi_dsi_driver panel_simple_dsi_driver = {
884 .driver = {
885 .name = "panel-simple-dsi",
886 .owner = THIS_MODULE,
887 .of_match_table = dsi_of_match,
888 },
889 .probe = panel_simple_dsi_probe,
890 .remove = panel_simple_dsi_remove,
Thierry Redingd02fd932014-04-29 17:21:21 +0200891 .shutdown = panel_simple_dsi_shutdown,
Thierry Reding280921d2013-08-30 15:10:14 +0200892};
893
894static int __init panel_simple_init(void)
895{
Thierry Reding210fcd92013-11-22 19:27:11 +0100896 int err;
897
898 err = platform_driver_register(&panel_simple_platform_driver);
899 if (err < 0)
900 return err;
901
902 if (IS_ENABLED(CONFIG_DRM_MIPI_DSI)) {
903 err = mipi_dsi_driver_register(&panel_simple_dsi_driver);
904 if (err < 0)
905 return err;
906 }
907
908 return 0;
Thierry Reding280921d2013-08-30 15:10:14 +0200909}
910module_init(panel_simple_init);
911
912static void __exit panel_simple_exit(void)
913{
Thierry Reding210fcd92013-11-22 19:27:11 +0100914 if (IS_ENABLED(CONFIG_DRM_MIPI_DSI))
915 mipi_dsi_driver_unregister(&panel_simple_dsi_driver);
916
Thierry Reding280921d2013-08-30 15:10:14 +0200917 platform_driver_unregister(&panel_simple_platform_driver);
918}
919module_exit(panel_simple_exit);
920
921MODULE_AUTHOR("Thierry Reding <treding@nvidia.com>");
922MODULE_DESCRIPTION("DRM Driver for Simple Panels");
923MODULE_LICENSE("GPL and additional rights");