Loading...
1/*
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/debugfs.h>
25#include <linux/delay.h>
26#include <linux/gpio/consumer.h>
27#include <linux/iopoll.h>
28#include <linux/module.h>
29#include <linux/of_platform.h>
30#include <linux/platform_device.h>
31#include <linux/pm_runtime.h>
32#include <linux/regulator/consumer.h>
33
34#include <video/display_timing.h>
35#include <video/of_display_timing.h>
36#include <video/videomode.h>
37
38#include <drm/display/drm_dp_aux_bus.h>
39#include <drm/display/drm_dp_helper.h>
40#include <drm/drm_crtc.h>
41#include <drm/drm_device.h>
42#include <drm/drm_edid.h>
43#include <drm/drm_panel.h>
44
45/**
46 * struct panel_delay - Describes delays for a simple panel.
47 */
48struct panel_delay {
49 /**
50 * @hpd_reliable: Time for HPD to be reliable
51 *
52 * The time (in milliseconds) that it takes after powering the panel
53 * before the HPD signal is reliable. Ideally this is 0 but some panels,
54 * board designs, or bad pulldown configs can cause a glitch here.
55 *
56 * NOTE: on some old panel data this number appears to be much too big.
57 * Presumably some old panels simply didn't have HPD hooked up and put
58 * the hpd_absent here because this field predates the
59 * hpd_absent. While that works, it's non-ideal.
60 */
61 unsigned int hpd_reliable;
62
63 /**
64 * @hpd_absent: Time to wait if HPD isn't hooked up.
65 *
66 * Add this to the prepare delay if we know Hot Plug Detect isn't used.
67 *
68 * This is T3-max on eDP timing diagrams or the delay from power on
69 * until HPD is guaranteed to be asserted.
70 */
71 unsigned int hpd_absent;
72
73 /**
74 * @powered_on_to_enable: Time between panel powered on and enable.
75 *
76 * The minimum time, in milliseconds, that needs to have passed
77 * between when panel powered on and enable may begin.
78 *
79 * This is (T3+T4+T5+T6+T8)-min on eDP timing diagrams or after the
80 * power supply enabled until we can turn the backlight on and see
81 * valid data.
82 *
83 * This doesn't normally need to be set if timings are already met by
84 * prepare_to_enable or enable.
85 */
86 unsigned int powered_on_to_enable;
87
88 /**
89 * @prepare_to_enable: Time between prepare and enable.
90 *
91 * The minimum time, in milliseconds, that needs to have passed
92 * between when prepare finished and enable may begin. If at
93 * enable time less time has passed since prepare finished,
94 * the driver waits for the remaining time.
95 *
96 * If a fixed enable delay is also specified, we'll start
97 * counting before delaying for the fixed delay.
98 *
99 * If a fixed prepare delay is also specified, we won't start
100 * counting until after the fixed delay. We can't overlap this
101 * fixed delay with the min time because the fixed delay
102 * doesn't happen at the end of the function if a HPD GPIO was
103 * specified.
104 *
105 * In other words:
106 * prepare()
107 * ...
108 * // do fixed prepare delay
109 * // wait for HPD GPIO if applicable
110 * // start counting for prepare_to_enable
111 *
112 * enable()
113 * // do fixed enable delay
114 * // enforce prepare_to_enable min time
115 *
116 * This is not specified in a standard way on eDP timing diagrams.
117 * It is effectively the time from HPD going high till you can
118 * turn on the backlight.
119 */
120 unsigned int prepare_to_enable;
121
122 /**
123 * @enable: Time for the panel to display a valid frame.
124 *
125 * The time (in milliseconds) that it takes for the panel to
126 * display the first valid frame after starting to receive
127 * video data.
128 *
129 * This is (T6-min + max(T7-max, T8-min)) on eDP timing diagrams or
130 * the delay after link training finishes until we can turn the
131 * backlight on and see valid data.
132 */
133 unsigned int enable;
134
135 /**
136 * @disable: Time for the panel to turn the display off.
137 *
138 * The time (in milliseconds) that it takes for the panel to
139 * turn the display off (no content is visible).
140 *
141 * This is T9-min (delay from backlight off to end of valid video
142 * data) on eDP timing diagrams. It is not common to set.
143 */
144 unsigned int disable;
145
146 /**
147 * @unprepare: Time to power down completely.
148 *
149 * The time (in milliseconds) that it takes for the panel
150 * to power itself down completely.
151 *
152 * This time is used to prevent a future "prepare" from
153 * starting until at least this many milliseconds has passed.
154 * If at prepare time less time has passed since unprepare
155 * finished, the driver waits for the remaining time.
156 *
157 * This is T12-min on eDP timing diagrams.
158 */
159 unsigned int unprepare;
160};
161
162/**
163 * struct panel_desc - Describes a simple panel.
164 */
165struct panel_desc {
166 /**
167 * @modes: Pointer to array of fixed modes appropriate for this panel.
168 *
169 * If only one mode then this can just be the address of the mode.
170 * NOTE: cannot be used with "timings" and also if this is specified
171 * then you cannot override the mode in the device tree.
172 */
173 const struct drm_display_mode *modes;
174
175 /** @num_modes: Number of elements in modes array. */
176 unsigned int num_modes;
177
178 /**
179 * @timings: Pointer to array of display timings
180 *
181 * NOTE: cannot be used with "modes" and also these will be used to
182 * validate a device tree override if one is present.
183 */
184 const struct display_timing *timings;
185
186 /** @num_timings: Number of elements in timings array. */
187 unsigned int num_timings;
188
189 /** @bpc: Bits per color. */
190 unsigned int bpc;
191
192 /** @size: Structure containing the physical size of this panel. */
193 struct {
194 /**
195 * @size.width: Width (in mm) of the active display area.
196 */
197 unsigned int width;
198
199 /**
200 * @size.height: Height (in mm) of the active display area.
201 */
202 unsigned int height;
203 } size;
204
205 /** @delay: Structure containing various delay values for this panel. */
206 struct panel_delay delay;
207};
208
209/**
210 * struct edp_panel_entry - Maps panel ID to delay / panel name.
211 */
212struct edp_panel_entry {
213 /** @ident: edid identity used for panel matching. */
214 const struct drm_edid_ident ident;
215
216 /** @delay: The power sequencing delays needed for this panel. */
217 const struct panel_delay *delay;
218
219 /** @override_edid_mode: Override the mode obtained by edid. */
220 const struct drm_display_mode *override_edid_mode;
221};
222
223struct panel_edp {
224 struct drm_panel base;
225 bool no_hpd;
226
227 ktime_t prepared_time;
228 ktime_t powered_on_time;
229 ktime_t unprepared_time;
230
231 const struct panel_desc *desc;
232
233 struct regulator *supply;
234 struct i2c_adapter *ddc;
235 struct drm_dp_aux *aux;
236
237 struct gpio_desc *enable_gpio;
238 struct gpio_desc *hpd_gpio;
239
240 const struct edp_panel_entry *detected_panel;
241
242 const struct drm_edid *drm_edid;
243
244 struct drm_display_mode override_mode;
245
246 enum drm_panel_orientation orientation;
247};
248
249static inline struct panel_edp *to_panel_edp(struct drm_panel *panel)
250{
251 return container_of(panel, struct panel_edp, base);
252}
253
254static unsigned int panel_edp_get_timings_modes(struct panel_edp *panel,
255 struct drm_connector *connector)
256{
257 struct drm_display_mode *mode;
258 unsigned int i, num = 0;
259
260 for (i = 0; i < panel->desc->num_timings; i++) {
261 const struct display_timing *dt = &panel->desc->timings[i];
262 struct videomode vm;
263
264 videomode_from_timing(dt, &vm);
265 mode = drm_mode_create(connector->dev);
266 if (!mode) {
267 dev_err(panel->base.dev, "failed to add mode %ux%u\n",
268 dt->hactive.typ, dt->vactive.typ);
269 continue;
270 }
271
272 drm_display_mode_from_videomode(&vm, mode);
273
274 mode->type |= DRM_MODE_TYPE_DRIVER;
275
276 if (panel->desc->num_timings == 1)
277 mode->type |= DRM_MODE_TYPE_PREFERRED;
278
279 drm_mode_probed_add(connector, mode);
280 num++;
281 }
282
283 return num;
284}
285
286static unsigned int panel_edp_get_display_modes(struct panel_edp *panel,
287 struct drm_connector *connector)
288{
289 struct drm_display_mode *mode;
290 unsigned int i, num = 0;
291
292 for (i = 0; i < panel->desc->num_modes; i++) {
293 const struct drm_display_mode *m = &panel->desc->modes[i];
294
295 mode = drm_mode_duplicate(connector->dev, m);
296 if (!mode) {
297 dev_err(panel->base.dev, "failed to add mode %ux%u@%u\n",
298 m->hdisplay, m->vdisplay,
299 drm_mode_vrefresh(m));
300 continue;
301 }
302
303 mode->type |= DRM_MODE_TYPE_DRIVER;
304
305 if (panel->desc->num_modes == 1)
306 mode->type |= DRM_MODE_TYPE_PREFERRED;
307
308 drm_mode_set_name(mode);
309
310 drm_mode_probed_add(connector, mode);
311 num++;
312 }
313
314 return num;
315}
316
317static int panel_edp_override_edid_mode(struct panel_edp *panel,
318 struct drm_connector *connector,
319 const struct drm_display_mode *override_mode)
320{
321 struct drm_display_mode *mode;
322
323 mode = drm_mode_duplicate(connector->dev, override_mode);
324 if (!mode) {
325 dev_err(panel->base.dev, "failed to add additional mode\n");
326 return 0;
327 }
328
329 mode->type |= DRM_MODE_TYPE_DRIVER | DRM_MODE_TYPE_PREFERRED;
330 drm_mode_set_name(mode);
331 drm_mode_probed_add(connector, mode);
332 return 1;
333}
334
335static int panel_edp_get_non_edid_modes(struct panel_edp *panel,
336 struct drm_connector *connector)
337{
338 struct drm_display_mode *mode;
339 bool has_override = panel->override_mode.type;
340 unsigned int num = 0;
341
342 if (!panel->desc)
343 return 0;
344
345 if (has_override) {
346 mode = drm_mode_duplicate(connector->dev,
347 &panel->override_mode);
348 if (mode) {
349 drm_mode_probed_add(connector, mode);
350 num = 1;
351 } else {
352 dev_err(panel->base.dev, "failed to add override mode\n");
353 }
354 }
355
356 /* Only add timings if override was not there or failed to validate */
357 if (num == 0 && panel->desc->num_timings)
358 num = panel_edp_get_timings_modes(panel, connector);
359
360 /*
361 * Only add fixed modes if timings/override added no mode.
362 *
363 * We should only ever have either the display timings specified
364 * or a fixed mode. Anything else is rather bogus.
365 */
366 WARN_ON(panel->desc->num_timings && panel->desc->num_modes);
367 if (num == 0)
368 num = panel_edp_get_display_modes(panel, connector);
369
370 connector->display_info.bpc = panel->desc->bpc;
371 connector->display_info.width_mm = panel->desc->size.width;
372 connector->display_info.height_mm = panel->desc->size.height;
373
374 return num;
375}
376
377static void panel_edp_wait(ktime_t start_ktime, unsigned int min_ms)
378{
379 ktime_t now_ktime, min_ktime;
380
381 if (!min_ms)
382 return;
383
384 min_ktime = ktime_add(start_ktime, ms_to_ktime(min_ms));
385 now_ktime = ktime_get_boottime();
386
387 if (ktime_before(now_ktime, min_ktime))
388 msleep(ktime_to_ms(ktime_sub(min_ktime, now_ktime)) + 1);
389}
390
391static int panel_edp_disable(struct drm_panel *panel)
392{
393 struct panel_edp *p = to_panel_edp(panel);
394
395 if (p->desc->delay.disable)
396 msleep(p->desc->delay.disable);
397
398 return 0;
399}
400
401static int panel_edp_suspend(struct device *dev)
402{
403 struct panel_edp *p = dev_get_drvdata(dev);
404
405 drm_dp_dpcd_set_powered(p->aux, false);
406 gpiod_set_value_cansleep(p->enable_gpio, 0);
407 regulator_disable(p->supply);
408 p->unprepared_time = ktime_get_boottime();
409
410 return 0;
411}
412
413static int panel_edp_unprepare(struct drm_panel *panel)
414{
415 int ret;
416
417 ret = pm_runtime_put_sync_suspend(panel->dev);
418 if (ret < 0)
419 return ret;
420
421 return 0;
422}
423
424static int panel_edp_get_hpd_gpio(struct device *dev, struct panel_edp *p)
425{
426 p->hpd_gpio = devm_gpiod_get_optional(dev, "hpd", GPIOD_IN);
427 if (IS_ERR(p->hpd_gpio))
428 return dev_err_probe(dev, PTR_ERR(p->hpd_gpio),
429 "failed to get 'hpd' GPIO\n");
430
431 return 0;
432}
433
434static bool panel_edp_can_read_hpd(struct panel_edp *p)
435{
436 return !p->no_hpd && (p->hpd_gpio || (p->aux && p->aux->wait_hpd_asserted));
437}
438
439static int panel_edp_prepare_once(struct panel_edp *p)
440{
441 struct device *dev = p->base.dev;
442 unsigned int delay;
443 int err;
444 int hpd_asserted;
445 unsigned long hpd_wait_us;
446
447 panel_edp_wait(p->unprepared_time, p->desc->delay.unprepare);
448
449 err = regulator_enable(p->supply);
450 if (err < 0) {
451 dev_err(dev, "failed to enable supply: %d\n", err);
452 return err;
453 }
454
455 gpiod_set_value_cansleep(p->enable_gpio, 1);
456 drm_dp_dpcd_set_powered(p->aux, true);
457
458 p->powered_on_time = ktime_get_boottime();
459
460 delay = p->desc->delay.hpd_reliable;
461 if (p->no_hpd)
462 delay = max(delay, p->desc->delay.hpd_absent);
463 if (delay)
464 msleep(delay);
465
466 if (panel_edp_can_read_hpd(p)) {
467 if (p->desc->delay.hpd_absent)
468 hpd_wait_us = p->desc->delay.hpd_absent * 1000UL;
469 else
470 hpd_wait_us = 2000000;
471
472 if (p->hpd_gpio) {
473 err = readx_poll_timeout(gpiod_get_value_cansleep,
474 p->hpd_gpio, hpd_asserted,
475 hpd_asserted, 1000, hpd_wait_us);
476 if (hpd_asserted < 0)
477 err = hpd_asserted;
478 } else {
479 err = p->aux->wait_hpd_asserted(p->aux, hpd_wait_us);
480 }
481
482 if (err) {
483 if (err != -ETIMEDOUT)
484 dev_err(dev,
485 "error waiting for hpd GPIO: %d\n", err);
486 goto error;
487 }
488 }
489
490 p->prepared_time = ktime_get_boottime();
491
492 return 0;
493
494error:
495 drm_dp_dpcd_set_powered(p->aux, false);
496 gpiod_set_value_cansleep(p->enable_gpio, 0);
497 regulator_disable(p->supply);
498 p->unprepared_time = ktime_get_boottime();
499
500 return err;
501}
502
503/*
504 * Some panels simply don't always come up and need to be power cycled to
505 * work properly. We'll allow for a handful of retries.
506 */
507#define MAX_PANEL_PREPARE_TRIES 5
508
509static int panel_edp_resume(struct device *dev)
510{
511 struct panel_edp *p = dev_get_drvdata(dev);
512 int ret;
513 int try;
514
515 for (try = 0; try < MAX_PANEL_PREPARE_TRIES; try++) {
516 ret = panel_edp_prepare_once(p);
517 if (ret != -ETIMEDOUT)
518 break;
519 }
520
521 if (ret == -ETIMEDOUT)
522 dev_err(dev, "Prepare timeout after %d tries\n", try);
523 else if (try)
524 dev_warn(dev, "Prepare needed %d retries\n", try);
525
526 return ret;
527}
528
529static int panel_edp_prepare(struct drm_panel *panel)
530{
531 int ret;
532
533 ret = pm_runtime_get_sync(panel->dev);
534 if (ret < 0) {
535 pm_runtime_put_autosuspend(panel->dev);
536 return ret;
537 }
538
539 return 0;
540}
541
542static int panel_edp_enable(struct drm_panel *panel)
543{
544 struct panel_edp *p = to_panel_edp(panel);
545 unsigned int delay;
546
547 delay = p->desc->delay.enable;
548
549 /*
550 * If there is a "prepare_to_enable" delay then that's supposed to be
551 * the delay from HPD going high until we can turn the backlight on.
552 * However, we can only count this if HPD is readable by the panel
553 * driver.
554 *
555 * If we aren't handling the HPD pin ourselves then the best we
556 * can do is assume that HPD went high immediately before we were
557 * called (and link training took zero time). Note that "no-hpd"
558 * actually counts as handling HPD ourselves since we're doing the
559 * worst case delay (in prepare) ourselves.
560 *
561 * NOTE: if we ever end up in this "if" statement then we're
562 * guaranteed that the panel_edp_wait() call below will do no delay.
563 * It already handles that case, though, so we don't need any special
564 * code for it.
565 */
566 if (p->desc->delay.prepare_to_enable &&
567 !panel_edp_can_read_hpd(p) && !p->no_hpd)
568 delay = max(delay, p->desc->delay.prepare_to_enable);
569
570 if (delay)
571 msleep(delay);
572
573 panel_edp_wait(p->prepared_time, p->desc->delay.prepare_to_enable);
574
575 panel_edp_wait(p->powered_on_time, p->desc->delay.powered_on_to_enable);
576
577 return 0;
578}
579
580static int panel_edp_get_modes(struct drm_panel *panel,
581 struct drm_connector *connector)
582{
583 struct panel_edp *p = to_panel_edp(panel);
584 int num = 0;
585 bool has_hard_coded_modes = p->desc->num_timings || p->desc->num_modes;
586 bool has_override_edid_mode = p->detected_panel &&
587 p->detected_panel != ERR_PTR(-EINVAL) &&
588 p->detected_panel->override_edid_mode;
589
590 /* probe EDID if a DDC bus is available */
591 if (p->ddc) {
592 pm_runtime_get_sync(panel->dev);
593
594 if (!p->drm_edid)
595 p->drm_edid = drm_edid_read_ddc(connector, p->ddc);
596
597 drm_edid_connector_update(connector, p->drm_edid);
598
599 /*
600 * If both edid and hard-coded modes exists, skip edid modes to
601 * avoid multiple preferred modes.
602 */
603 if (p->drm_edid && !has_hard_coded_modes) {
604 if (has_override_edid_mode) {
605 /*
606 * override_edid_mode is specified. Use
607 * override_edid_mode instead of from edid.
608 */
609 num += panel_edp_override_edid_mode(p, connector,
610 p->detected_panel->override_edid_mode);
611 } else {
612 num += drm_edid_connector_add_modes(connector);
613 }
614 }
615
616 pm_runtime_mark_last_busy(panel->dev);
617 pm_runtime_put_autosuspend(panel->dev);
618 }
619
620 if (has_hard_coded_modes)
621 num += panel_edp_get_non_edid_modes(p, connector);
622 else if (!num)
623 dev_warn(p->base.dev, "No display modes\n");
624
625 /*
626 * TODO: Remove once all drm drivers call
627 * drm_connector_set_orientation_from_panel()
628 */
629 drm_connector_set_panel_orientation(connector, p->orientation);
630
631 return num;
632}
633
634static int panel_edp_get_timings(struct drm_panel *panel,
635 unsigned int num_timings,
636 struct display_timing *timings)
637{
638 struct panel_edp *p = to_panel_edp(panel);
639 unsigned int i;
640
641 if (p->desc->num_timings < num_timings)
642 num_timings = p->desc->num_timings;
643
644 if (timings)
645 for (i = 0; i < num_timings; i++)
646 timings[i] = p->desc->timings[i];
647
648 return p->desc->num_timings;
649}
650
651static enum drm_panel_orientation panel_edp_get_orientation(struct drm_panel *panel)
652{
653 struct panel_edp *p = to_panel_edp(panel);
654
655 return p->orientation;
656}
657
658static int detected_panel_show(struct seq_file *s, void *data)
659{
660 struct drm_panel *panel = s->private;
661 struct panel_edp *p = to_panel_edp(panel);
662
663 if (IS_ERR(p->detected_panel))
664 seq_puts(s, "UNKNOWN\n");
665 else if (!p->detected_panel)
666 seq_puts(s, "HARDCODED\n");
667 else
668 seq_printf(s, "%s\n", p->detected_panel->ident.name);
669
670 return 0;
671}
672
673DEFINE_SHOW_ATTRIBUTE(detected_panel);
674
675static void panel_edp_debugfs_init(struct drm_panel *panel, struct dentry *root)
676{
677 debugfs_create_file("detected_panel", 0600, root, panel, &detected_panel_fops);
678}
679
680static const struct drm_panel_funcs panel_edp_funcs = {
681 .disable = panel_edp_disable,
682 .unprepare = panel_edp_unprepare,
683 .prepare = panel_edp_prepare,
684 .enable = panel_edp_enable,
685 .get_modes = panel_edp_get_modes,
686 .get_orientation = panel_edp_get_orientation,
687 .get_timings = panel_edp_get_timings,
688 .debugfs_init = panel_edp_debugfs_init,
689};
690
691#define PANEL_EDP_BOUNDS_CHECK(to_check, bounds, field) \
692 (to_check->field.typ >= bounds->field.min && \
693 to_check->field.typ <= bounds->field.max)
694static void panel_edp_parse_panel_timing_node(struct device *dev,
695 struct panel_edp *panel,
696 const struct display_timing *ot)
697{
698 const struct panel_desc *desc = panel->desc;
699 struct videomode vm;
700 unsigned int i;
701
702 if (WARN_ON(desc->num_modes)) {
703 dev_err(dev, "Reject override mode: panel has a fixed mode\n");
704 return;
705 }
706 if (WARN_ON(!desc->num_timings)) {
707 dev_err(dev, "Reject override mode: no timings specified\n");
708 return;
709 }
710
711 for (i = 0; i < panel->desc->num_timings; i++) {
712 const struct display_timing *dt = &panel->desc->timings[i];
713
714 if (!PANEL_EDP_BOUNDS_CHECK(ot, dt, hactive) ||
715 !PANEL_EDP_BOUNDS_CHECK(ot, dt, hfront_porch) ||
716 !PANEL_EDP_BOUNDS_CHECK(ot, dt, hback_porch) ||
717 !PANEL_EDP_BOUNDS_CHECK(ot, dt, hsync_len) ||
718 !PANEL_EDP_BOUNDS_CHECK(ot, dt, vactive) ||
719 !PANEL_EDP_BOUNDS_CHECK(ot, dt, vfront_porch) ||
720 !PANEL_EDP_BOUNDS_CHECK(ot, dt, vback_porch) ||
721 !PANEL_EDP_BOUNDS_CHECK(ot, dt, vsync_len))
722 continue;
723
724 if (ot->flags != dt->flags)
725 continue;
726
727 videomode_from_timing(ot, &vm);
728 drm_display_mode_from_videomode(&vm, &panel->override_mode);
729 panel->override_mode.type |= DRM_MODE_TYPE_DRIVER |
730 DRM_MODE_TYPE_PREFERRED;
731 break;
732 }
733
734 if (WARN_ON(!panel->override_mode.type))
735 dev_err(dev, "Reject override mode: No display_timing found\n");
736}
737
738static const struct edp_panel_entry *find_edp_panel(u32 panel_id, const struct drm_edid *edid);
739
740static void panel_edp_set_conservative_timings(struct panel_edp *panel, struct panel_desc *desc)
741{
742 /*
743 * It's highly likely that the panel will work if we use very
744 * conservative timings, so let's do that.
745 *
746 * Nearly all panels have a "unprepare" delay of 500 ms though
747 * there are a few with 1000. Let's stick 2000 in just to be
748 * super conservative.
749 *
750 * An "enable" delay of 80 ms seems the most common, but we'll
751 * throw in 200 ms to be safe.
752 */
753 desc->delay.unprepare = 2000;
754 desc->delay.enable = 200;
755
756 panel->detected_panel = ERR_PTR(-EINVAL);
757}
758
759static int generic_edp_panel_probe(struct device *dev, struct panel_edp *panel)
760{
761 struct panel_desc *desc;
762 const struct drm_edid *base_block;
763 u32 panel_id;
764 char vend[4];
765 u16 product_id;
766 u32 reliable_ms = 0;
767 u32 absent_ms = 0;
768 int ret;
769
770 desc = devm_kzalloc(dev, sizeof(*desc), GFP_KERNEL);
771 if (!desc)
772 return -ENOMEM;
773 panel->desc = desc;
774
775 /*
776 * Read the dts properties for the initial probe. These are used by
777 * the runtime resume code which will get called by the
778 * pm_runtime_get_sync() call below.
779 */
780 of_property_read_u32(dev->of_node, "hpd-reliable-delay-ms", &reliable_ms);
781 desc->delay.hpd_reliable = reliable_ms;
782 of_property_read_u32(dev->of_node, "hpd-absent-delay-ms", &absent_ms);
783 desc->delay.hpd_absent = absent_ms;
784
785 /* Power the panel on so we can read the EDID */
786 ret = pm_runtime_get_sync(dev);
787 if (ret < 0) {
788 dev_err(dev,
789 "Couldn't power on panel to ID it; using conservative timings: %d\n",
790 ret);
791 panel_edp_set_conservative_timings(panel, desc);
792 goto exit;
793 }
794
795 base_block = drm_edid_read_base_block(panel->ddc);
796 if (base_block) {
797 panel_id = drm_edid_get_panel_id(base_block);
798 } else {
799 dev_err(dev, "Couldn't read EDID for ID; using conservative timings\n");
800 panel_edp_set_conservative_timings(panel, desc);
801 goto exit;
802 }
803 drm_edid_decode_panel_id(panel_id, vend, &product_id);
804
805 panel->detected_panel = find_edp_panel(panel_id, base_block);
806
807 drm_edid_free(base_block);
808
809 /*
810 * We're using non-optimized timings and want it really obvious that
811 * someone needs to add an entry to the table, so we'll do a WARN_ON
812 * splat.
813 */
814 if (WARN_ON(!panel->detected_panel)) {
815 dev_warn(dev,
816 "Unknown panel %s %#06x, using conservative timings\n",
817 vend, product_id);
818 panel_edp_set_conservative_timings(panel, desc);
819 } else {
820 dev_info(dev, "Detected %s %s (%#06x)\n",
821 vend, panel->detected_panel->ident.name, product_id);
822
823 /* Update the delay; everything else comes from EDID */
824 desc->delay = *panel->detected_panel->delay;
825 }
826
827exit:
828 pm_runtime_mark_last_busy(dev);
829 pm_runtime_put_autosuspend(dev);
830
831 return 0;
832}
833
834static int panel_edp_probe(struct device *dev, const struct panel_desc *desc,
835 struct drm_dp_aux *aux)
836{
837 struct panel_edp *panel;
838 struct display_timing dt;
839 struct device_node *ddc;
840 int err;
841
842 panel = devm_kzalloc(dev, sizeof(*panel), GFP_KERNEL);
843 if (!panel)
844 return -ENOMEM;
845
846 panel->prepared_time = 0;
847 panel->desc = desc;
848 panel->aux = aux;
849
850 panel->no_hpd = of_property_read_bool(dev->of_node, "no-hpd");
851 if (!panel->no_hpd) {
852 err = panel_edp_get_hpd_gpio(dev, panel);
853 if (err)
854 return err;
855 }
856
857 panel->supply = devm_regulator_get(dev, "power");
858 if (IS_ERR(panel->supply))
859 return PTR_ERR(panel->supply);
860
861 panel->enable_gpio = devm_gpiod_get_optional(dev, "enable",
862 GPIOD_OUT_LOW);
863 if (IS_ERR(panel->enable_gpio))
864 return dev_err_probe(dev, PTR_ERR(panel->enable_gpio),
865 "failed to request GPIO\n");
866
867 err = of_drm_get_panel_orientation(dev->of_node, &panel->orientation);
868 if (err) {
869 dev_err(dev, "%pOF: failed to get orientation %d\n", dev->of_node, err);
870 return err;
871 }
872
873 ddc = of_parse_phandle(dev->of_node, "ddc-i2c-bus", 0);
874 if (ddc) {
875 panel->ddc = of_find_i2c_adapter_by_node(ddc);
876 of_node_put(ddc);
877
878 if (!panel->ddc)
879 return -EPROBE_DEFER;
880 } else if (aux) {
881 panel->ddc = &aux->ddc;
882 }
883
884 if (!of_get_display_timing(dev->of_node, "panel-timing", &dt))
885 panel_edp_parse_panel_timing_node(dev, panel, &dt);
886
887 dev_set_drvdata(dev, panel);
888
889 drm_panel_init(&panel->base, dev, &panel_edp_funcs, DRM_MODE_CONNECTOR_eDP);
890
891 err = drm_panel_of_backlight(&panel->base);
892 if (err)
893 goto err_finished_ddc_init;
894
895 /*
896 * We use runtime PM for prepare / unprepare since those power the panel
897 * on and off and those can be very slow operations. This is important
898 * to optimize powering the panel on briefly to read the EDID before
899 * fully enabling the panel.
900 */
901 pm_runtime_enable(dev);
902 pm_runtime_set_autosuspend_delay(dev, 1000);
903 pm_runtime_use_autosuspend(dev);
904
905 if (of_device_is_compatible(dev->of_node, "edp-panel")) {
906 err = generic_edp_panel_probe(dev, panel);
907 if (err) {
908 dev_err_probe(dev, err,
909 "Couldn't detect panel nor find a fallback\n");
910 goto err_finished_pm_runtime;
911 }
912 /* generic_edp_panel_probe() replaces desc in the panel */
913 desc = panel->desc;
914 } else if (desc->bpc != 6 && desc->bpc != 8 && desc->bpc != 10) {
915 dev_warn(dev, "Expected bpc in {6,8,10} but got: %u\n", desc->bpc);
916 }
917
918 if (!panel->base.backlight && panel->aux) {
919 pm_runtime_get_sync(dev);
920 err = drm_panel_dp_aux_backlight(&panel->base, panel->aux);
921 pm_runtime_mark_last_busy(dev);
922 pm_runtime_put_autosuspend(dev);
923
924 /*
925 * Warn if we get an error, but don't consider it fatal. Having
926 * a panel where we can't control the backlight is better than
927 * no panel.
928 */
929 if (err)
930 dev_warn(dev, "failed to register dp aux backlight: %d\n", err);
931 }
932
933 drm_panel_add(&panel->base);
934
935 return 0;
936
937err_finished_pm_runtime:
938 pm_runtime_dont_use_autosuspend(dev);
939 pm_runtime_disable(dev);
940err_finished_ddc_init:
941 if (panel->ddc && (!panel->aux || panel->ddc != &panel->aux->ddc))
942 put_device(&panel->ddc->dev);
943
944 return err;
945}
946
947static void panel_edp_shutdown(struct device *dev)
948{
949 struct panel_edp *panel = dev_get_drvdata(dev);
950
951 /*
952 * NOTE: the following two calls don't really belong here. It is the
953 * responsibility of a correctly written DRM modeset driver to call
954 * drm_atomic_helper_shutdown() at shutdown time and that should
955 * cause the panel to be disabled / unprepared if needed. For now,
956 * however, we'll keep these calls due to the sheer number of
957 * different DRM modeset drivers used with panel-edp. Once we've
958 * confirmed that all DRM modeset drivers using this panel properly
959 * call drm_atomic_helper_shutdown() we can simply delete the two
960 * calls below.
961 *
962 * TO BE EXPLICIT: THE CALLS BELOW SHOULDN'T BE COPIED TO ANY NEW
963 * PANEL DRIVERS.
964 *
965 * FIXME: If we're still haven't figured out if all DRM modeset
966 * drivers properly call drm_atomic_helper_shutdown() but we _have_
967 * managed to make sure that DRM modeset drivers get their shutdown()
968 * callback before the panel's shutdown() callback (perhaps using
969 * device link), we could add a WARN_ON here to help move forward.
970 */
971 if (panel->base.enabled)
972 drm_panel_disable(&panel->base);
973 if (panel->base.prepared)
974 drm_panel_unprepare(&panel->base);
975}
976
977static void panel_edp_remove(struct device *dev)
978{
979 struct panel_edp *panel = dev_get_drvdata(dev);
980
981 drm_panel_remove(&panel->base);
982 panel_edp_shutdown(dev);
983
984 pm_runtime_dont_use_autosuspend(dev);
985 pm_runtime_disable(dev);
986 if (panel->ddc && (!panel->aux || panel->ddc != &panel->aux->ddc))
987 put_device(&panel->ddc->dev);
988
989 drm_edid_free(panel->drm_edid);
990 panel->drm_edid = NULL;
991}
992
993static const struct display_timing auo_b101ean01_timing = {
994 .pixelclock = { 65300000, 72500000, 75000000 },
995 .hactive = { 1280, 1280, 1280 },
996 .hfront_porch = { 18, 119, 119 },
997 .hback_porch = { 21, 21, 21 },
998 .hsync_len = { 32, 32, 32 },
999 .vactive = { 800, 800, 800 },
1000 .vfront_porch = { 4, 4, 4 },
1001 .vback_porch = { 8, 8, 8 },
1002 .vsync_len = { 18, 20, 20 },
1003};
1004
1005static const struct panel_desc auo_b101ean01 = {
1006 .timings = &auo_b101ean01_timing,
1007 .num_timings = 1,
1008 .bpc = 6,
1009 .size = {
1010 .width = 217,
1011 .height = 136,
1012 },
1013};
1014
1015static const struct drm_display_mode auo_b116xa3_mode = {
1016 .clock = 70589,
1017 .hdisplay = 1366,
1018 .hsync_start = 1366 + 40,
1019 .hsync_end = 1366 + 40 + 40,
1020 .htotal = 1366 + 40 + 40 + 32,
1021 .vdisplay = 768,
1022 .vsync_start = 768 + 10,
1023 .vsync_end = 768 + 10 + 12,
1024 .vtotal = 768 + 10 + 12 + 6,
1025 .flags = DRM_MODE_FLAG_NVSYNC | DRM_MODE_FLAG_NHSYNC,
1026};
1027
1028static const struct drm_display_mode auo_b116xak01_mode = {
1029 .clock = 69300,
1030 .hdisplay = 1366,
1031 .hsync_start = 1366 + 48,
1032 .hsync_end = 1366 + 48 + 32,
1033 .htotal = 1366 + 48 + 32 + 10,
1034 .vdisplay = 768,
1035 .vsync_start = 768 + 4,
1036 .vsync_end = 768 + 4 + 6,
1037 .vtotal = 768 + 4 + 6 + 15,
1038 .flags = DRM_MODE_FLAG_NVSYNC | DRM_MODE_FLAG_NHSYNC,
1039};
1040
1041static const struct panel_desc auo_b116xak01 = {
1042 .modes = &auo_b116xak01_mode,
1043 .num_modes = 1,
1044 .bpc = 6,
1045 .size = {
1046 .width = 256,
1047 .height = 144,
1048 },
1049 .delay = {
1050 .hpd_absent = 200,
1051 .unprepare = 500,
1052 .enable = 50,
1053 },
1054};
1055
1056static const struct drm_display_mode auo_b133htn01_mode = {
1057 .clock = 150660,
1058 .hdisplay = 1920,
1059 .hsync_start = 1920 + 172,
1060 .hsync_end = 1920 + 172 + 80,
1061 .htotal = 1920 + 172 + 80 + 60,
1062 .vdisplay = 1080,
1063 .vsync_start = 1080 + 25,
1064 .vsync_end = 1080 + 25 + 10,
1065 .vtotal = 1080 + 25 + 10 + 10,
1066};
1067
1068static const struct panel_desc auo_b133htn01 = {
1069 .modes = &auo_b133htn01_mode,
1070 .num_modes = 1,
1071 .bpc = 6,
1072 .size = {
1073 .width = 293,
1074 .height = 165,
1075 },
1076 .delay = {
1077 .hpd_reliable = 105,
1078 .enable = 20,
1079 .unprepare = 50,
1080 },
1081};
1082
1083static const struct drm_display_mode auo_b133xtn01_mode = {
1084 .clock = 69500,
1085 .hdisplay = 1366,
1086 .hsync_start = 1366 + 48,
1087 .hsync_end = 1366 + 48 + 32,
1088 .htotal = 1366 + 48 + 32 + 20,
1089 .vdisplay = 768,
1090 .vsync_start = 768 + 3,
1091 .vsync_end = 768 + 3 + 6,
1092 .vtotal = 768 + 3 + 6 + 13,
1093};
1094
1095static const struct panel_desc auo_b133xtn01 = {
1096 .modes = &auo_b133xtn01_mode,
1097 .num_modes = 1,
1098 .bpc = 6,
1099 .size = {
1100 .width = 293,
1101 .height = 165,
1102 },
1103};
1104
1105static const struct drm_display_mode boe_nv101wxmn51_modes[] = {
1106 {
1107 .clock = 71900,
1108 .hdisplay = 1280,
1109 .hsync_start = 1280 + 48,
1110 .hsync_end = 1280 + 48 + 32,
1111 .htotal = 1280 + 48 + 32 + 80,
1112 .vdisplay = 800,
1113 .vsync_start = 800 + 3,
1114 .vsync_end = 800 + 3 + 5,
1115 .vtotal = 800 + 3 + 5 + 24,
1116 },
1117 {
1118 .clock = 57500,
1119 .hdisplay = 1280,
1120 .hsync_start = 1280 + 48,
1121 .hsync_end = 1280 + 48 + 32,
1122 .htotal = 1280 + 48 + 32 + 80,
1123 .vdisplay = 800,
1124 .vsync_start = 800 + 3,
1125 .vsync_end = 800 + 3 + 5,
1126 .vtotal = 800 + 3 + 5 + 24,
1127 },
1128};
1129
1130static const struct panel_desc boe_nv101wxmn51 = {
1131 .modes = boe_nv101wxmn51_modes,
1132 .num_modes = ARRAY_SIZE(boe_nv101wxmn51_modes),
1133 .bpc = 8,
1134 .size = {
1135 .width = 217,
1136 .height = 136,
1137 },
1138 .delay = {
1139 /* TODO: should be hpd-absent and no-hpd should be set? */
1140 .hpd_reliable = 210,
1141 .enable = 50,
1142 .unprepare = 160,
1143 },
1144};
1145
1146static const struct drm_display_mode boe_nv110wtm_n61_modes[] = {
1147 {
1148 .clock = 207800,
1149 .hdisplay = 2160,
1150 .hsync_start = 2160 + 48,
1151 .hsync_end = 2160 + 48 + 32,
1152 .htotal = 2160 + 48 + 32 + 100,
1153 .vdisplay = 1440,
1154 .vsync_start = 1440 + 3,
1155 .vsync_end = 1440 + 3 + 6,
1156 .vtotal = 1440 + 3 + 6 + 31,
1157 .flags = DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC,
1158 },
1159 {
1160 .clock = 138500,
1161 .hdisplay = 2160,
1162 .hsync_start = 2160 + 48,
1163 .hsync_end = 2160 + 48 + 32,
1164 .htotal = 2160 + 48 + 32 + 100,
1165 .vdisplay = 1440,
1166 .vsync_start = 1440 + 3,
1167 .vsync_end = 1440 + 3 + 6,
1168 .vtotal = 1440 + 3 + 6 + 31,
1169 .flags = DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC,
1170 },
1171};
1172
1173static const struct panel_desc boe_nv110wtm_n61 = {
1174 .modes = boe_nv110wtm_n61_modes,
1175 .num_modes = ARRAY_SIZE(boe_nv110wtm_n61_modes),
1176 .bpc = 8,
1177 .size = {
1178 .width = 233,
1179 .height = 155,
1180 },
1181 .delay = {
1182 .hpd_absent = 200,
1183 .prepare_to_enable = 80,
1184 .enable = 50,
1185 .unprepare = 500,
1186 },
1187};
1188
1189/* Also used for boe_nv133fhm_n62 */
1190static const struct drm_display_mode boe_nv133fhm_n61_modes = {
1191 .clock = 147840,
1192 .hdisplay = 1920,
1193 .hsync_start = 1920 + 48,
1194 .hsync_end = 1920 + 48 + 32,
1195 .htotal = 1920 + 48 + 32 + 200,
1196 .vdisplay = 1080,
1197 .vsync_start = 1080 + 3,
1198 .vsync_end = 1080 + 3 + 6,
1199 .vtotal = 1080 + 3 + 6 + 31,
1200 .flags = DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC,
1201};
1202
1203/* Also used for boe_nv133fhm_n62 */
1204static const struct panel_desc boe_nv133fhm_n61 = {
1205 .modes = &boe_nv133fhm_n61_modes,
1206 .num_modes = 1,
1207 .bpc = 6,
1208 .size = {
1209 .width = 294,
1210 .height = 165,
1211 },
1212 .delay = {
1213 /*
1214 * When power is first given to the panel there's a short
1215 * spike on the HPD line. It was explained that this spike
1216 * was until the TCON data download was complete. On
1217 * one system this was measured at 8 ms. We'll put 15 ms
1218 * in the prepare delay just to be safe. That means:
1219 * - If HPD isn't hooked up you still have 200 ms delay.
1220 * - If HPD is hooked up we won't try to look at it for the
1221 * first 15 ms.
1222 */
1223 .hpd_reliable = 15,
1224 .hpd_absent = 200,
1225
1226 .unprepare = 500,
1227 },
1228};
1229
1230static const struct drm_display_mode boe_nv140fhmn49_modes[] = {
1231 {
1232 .clock = 148500,
1233 .hdisplay = 1920,
1234 .hsync_start = 1920 + 48,
1235 .hsync_end = 1920 + 48 + 32,
1236 .htotal = 2200,
1237 .vdisplay = 1080,
1238 .vsync_start = 1080 + 3,
1239 .vsync_end = 1080 + 3 + 5,
1240 .vtotal = 1125,
1241 },
1242};
1243
1244static const struct panel_desc boe_nv140fhmn49 = {
1245 .modes = boe_nv140fhmn49_modes,
1246 .num_modes = ARRAY_SIZE(boe_nv140fhmn49_modes),
1247 .bpc = 6,
1248 .size = {
1249 .width = 309,
1250 .height = 174,
1251 },
1252 .delay = {
1253 /* TODO: should be hpd-absent and no-hpd should be set? */
1254 .hpd_reliable = 210,
1255 .enable = 50,
1256 .unprepare = 160,
1257 },
1258};
1259
1260static const struct drm_display_mode innolux_n116bca_ea1_mode = {
1261 .clock = 76420,
1262 .hdisplay = 1366,
1263 .hsync_start = 1366 + 136,
1264 .hsync_end = 1366 + 136 + 30,
1265 .htotal = 1366 + 136 + 30 + 60,
1266 .vdisplay = 768,
1267 .vsync_start = 768 + 8,
1268 .vsync_end = 768 + 8 + 12,
1269 .vtotal = 768 + 8 + 12 + 12,
1270 .flags = DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC,
1271};
1272
1273static const struct panel_desc innolux_n116bca_ea1 = {
1274 .modes = &innolux_n116bca_ea1_mode,
1275 .num_modes = 1,
1276 .bpc = 6,
1277 .size = {
1278 .width = 256,
1279 .height = 144,
1280 },
1281 .delay = {
1282 .hpd_absent = 200,
1283 .enable = 80,
1284 .disable = 50,
1285 .unprepare = 500,
1286 },
1287};
1288
1289/*
1290 * Datasheet specifies that at 60 Hz refresh rate:
1291 * - total horizontal time: { 1506, 1592, 1716 }
1292 * - total vertical time: { 788, 800, 868 }
1293 *
1294 * ...but doesn't go into exactly how that should be split into a front
1295 * porch, back porch, or sync length. For now we'll leave a single setting
1296 * here which allows a bit of tweaking of the pixel clock at the expense of
1297 * refresh rate.
1298 */
1299static const struct display_timing innolux_n116bge_timing = {
1300 .pixelclock = { 72600000, 76420000, 80240000 },
1301 .hactive = { 1366, 1366, 1366 },
1302 .hfront_porch = { 136, 136, 136 },
1303 .hback_porch = { 60, 60, 60 },
1304 .hsync_len = { 30, 30, 30 },
1305 .vactive = { 768, 768, 768 },
1306 .vfront_porch = { 8, 8, 8 },
1307 .vback_porch = { 12, 12, 12 },
1308 .vsync_len = { 12, 12, 12 },
1309 .flags = DISPLAY_FLAGS_VSYNC_LOW | DISPLAY_FLAGS_HSYNC_LOW,
1310};
1311
1312static const struct panel_desc innolux_n116bge = {
1313 .timings = &innolux_n116bge_timing,
1314 .num_timings = 1,
1315 .bpc = 6,
1316 .size = {
1317 .width = 256,
1318 .height = 144,
1319 },
1320};
1321
1322static const struct drm_display_mode innolux_n125hce_gn1_mode = {
1323 .clock = 162000,
1324 .hdisplay = 1920,
1325 .hsync_start = 1920 + 40,
1326 .hsync_end = 1920 + 40 + 40,
1327 .htotal = 1920 + 40 + 40 + 80,
1328 .vdisplay = 1080,
1329 .vsync_start = 1080 + 4,
1330 .vsync_end = 1080 + 4 + 4,
1331 .vtotal = 1080 + 4 + 4 + 24,
1332};
1333
1334static const struct panel_desc innolux_n125hce_gn1 = {
1335 .modes = &innolux_n125hce_gn1_mode,
1336 .num_modes = 1,
1337 .bpc = 8,
1338 .size = {
1339 .width = 276,
1340 .height = 155,
1341 },
1342};
1343
1344static const struct drm_display_mode innolux_p120zdg_bf1_mode = {
1345 .clock = 206016,
1346 .hdisplay = 2160,
1347 .hsync_start = 2160 + 48,
1348 .hsync_end = 2160 + 48 + 32,
1349 .htotal = 2160 + 48 + 32 + 80,
1350 .vdisplay = 1440,
1351 .vsync_start = 1440 + 3,
1352 .vsync_end = 1440 + 3 + 10,
1353 .vtotal = 1440 + 3 + 10 + 27,
1354 .flags = DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC,
1355};
1356
1357static const struct panel_desc innolux_p120zdg_bf1 = {
1358 .modes = &innolux_p120zdg_bf1_mode,
1359 .num_modes = 1,
1360 .bpc = 8,
1361 .size = {
1362 .width = 254,
1363 .height = 169,
1364 },
1365 .delay = {
1366 .hpd_absent = 200,
1367 .unprepare = 500,
1368 },
1369};
1370
1371static const struct drm_display_mode kingdisplay_kd116n21_30nv_a010_mode = {
1372 .clock = 81000,
1373 .hdisplay = 1366,
1374 .hsync_start = 1366 + 40,
1375 .hsync_end = 1366 + 40 + 32,
1376 .htotal = 1366 + 40 + 32 + 62,
1377 .vdisplay = 768,
1378 .vsync_start = 768 + 5,
1379 .vsync_end = 768 + 5 + 5,
1380 .vtotal = 768 + 5 + 5 + 122,
1381 .flags = DRM_MODE_FLAG_NVSYNC | DRM_MODE_FLAG_NHSYNC,
1382};
1383
1384static const struct panel_desc kingdisplay_kd116n21_30nv_a010 = {
1385 .modes = &kingdisplay_kd116n21_30nv_a010_mode,
1386 .num_modes = 1,
1387 .bpc = 6,
1388 .size = {
1389 .width = 256,
1390 .height = 144,
1391 },
1392 .delay = {
1393 .hpd_absent = 200,
1394 },
1395};
1396
1397static const struct drm_display_mode lg_lp079qx1_sp0v_mode = {
1398 .clock = 200000,
1399 .hdisplay = 1536,
1400 .hsync_start = 1536 + 12,
1401 .hsync_end = 1536 + 12 + 16,
1402 .htotal = 1536 + 12 + 16 + 48,
1403 .vdisplay = 2048,
1404 .vsync_start = 2048 + 8,
1405 .vsync_end = 2048 + 8 + 4,
1406 .vtotal = 2048 + 8 + 4 + 8,
1407 .flags = DRM_MODE_FLAG_NVSYNC | DRM_MODE_FLAG_NHSYNC,
1408};
1409
1410static const struct panel_desc lg_lp079qx1_sp0v = {
1411 .modes = &lg_lp079qx1_sp0v_mode,
1412 .num_modes = 1,
1413 .size = {
1414 .width = 129,
1415 .height = 171,
1416 },
1417};
1418
1419static const struct drm_display_mode lg_lp097qx1_spa1_mode = {
1420 .clock = 205210,
1421 .hdisplay = 2048,
1422 .hsync_start = 2048 + 150,
1423 .hsync_end = 2048 + 150 + 5,
1424 .htotal = 2048 + 150 + 5 + 5,
1425 .vdisplay = 1536,
1426 .vsync_start = 1536 + 3,
1427 .vsync_end = 1536 + 3 + 1,
1428 .vtotal = 1536 + 3 + 1 + 9,
1429};
1430
1431static const struct panel_desc lg_lp097qx1_spa1 = {
1432 .modes = &lg_lp097qx1_spa1_mode,
1433 .num_modes = 1,
1434 .size = {
1435 .width = 208,
1436 .height = 147,
1437 },
1438};
1439
1440static const struct drm_display_mode lg_lp120up1_mode = {
1441 .clock = 162300,
1442 .hdisplay = 1920,
1443 .hsync_start = 1920 + 40,
1444 .hsync_end = 1920 + 40 + 40,
1445 .htotal = 1920 + 40 + 40 + 80,
1446 .vdisplay = 1280,
1447 .vsync_start = 1280 + 4,
1448 .vsync_end = 1280 + 4 + 4,
1449 .vtotal = 1280 + 4 + 4 + 12,
1450};
1451
1452static const struct panel_desc lg_lp120up1 = {
1453 .modes = &lg_lp120up1_mode,
1454 .num_modes = 1,
1455 .bpc = 8,
1456 .size = {
1457 .width = 267,
1458 .height = 183,
1459 },
1460};
1461
1462static const struct drm_display_mode lg_lp129qe_mode = {
1463 .clock = 285250,
1464 .hdisplay = 2560,
1465 .hsync_start = 2560 + 48,
1466 .hsync_end = 2560 + 48 + 32,
1467 .htotal = 2560 + 48 + 32 + 80,
1468 .vdisplay = 1700,
1469 .vsync_start = 1700 + 3,
1470 .vsync_end = 1700 + 3 + 10,
1471 .vtotal = 1700 + 3 + 10 + 36,
1472};
1473
1474static const struct panel_desc lg_lp129qe = {
1475 .modes = &lg_lp129qe_mode,
1476 .num_modes = 1,
1477 .bpc = 8,
1478 .size = {
1479 .width = 272,
1480 .height = 181,
1481 },
1482};
1483
1484static const struct drm_display_mode neweast_wjfh116008a_modes[] = {
1485 {
1486 .clock = 138500,
1487 .hdisplay = 1920,
1488 .hsync_start = 1920 + 48,
1489 .hsync_end = 1920 + 48 + 32,
1490 .htotal = 1920 + 48 + 32 + 80,
1491 .vdisplay = 1080,
1492 .vsync_start = 1080 + 3,
1493 .vsync_end = 1080 + 3 + 5,
1494 .vtotal = 1080 + 3 + 5 + 23,
1495 .flags = DRM_MODE_FLAG_NVSYNC | DRM_MODE_FLAG_NHSYNC,
1496 }, {
1497 .clock = 110920,
1498 .hdisplay = 1920,
1499 .hsync_start = 1920 + 48,
1500 .hsync_end = 1920 + 48 + 32,
1501 .htotal = 1920 + 48 + 32 + 80,
1502 .vdisplay = 1080,
1503 .vsync_start = 1080 + 3,
1504 .vsync_end = 1080 + 3 + 5,
1505 .vtotal = 1080 + 3 + 5 + 23,
1506 .flags = DRM_MODE_FLAG_NVSYNC | DRM_MODE_FLAG_NHSYNC,
1507 }
1508};
1509
1510static const struct panel_desc neweast_wjfh116008a = {
1511 .modes = neweast_wjfh116008a_modes,
1512 .num_modes = 2,
1513 .bpc = 6,
1514 .size = {
1515 .width = 260,
1516 .height = 150,
1517 },
1518 .delay = {
1519 .hpd_reliable = 110,
1520 .enable = 20,
1521 .unprepare = 500,
1522 },
1523};
1524
1525static const struct drm_display_mode samsung_lsn122dl01_c01_mode = {
1526 .clock = 271560,
1527 .hdisplay = 2560,
1528 .hsync_start = 2560 + 48,
1529 .hsync_end = 2560 + 48 + 32,
1530 .htotal = 2560 + 48 + 32 + 80,
1531 .vdisplay = 1600,
1532 .vsync_start = 1600 + 2,
1533 .vsync_end = 1600 + 2 + 5,
1534 .vtotal = 1600 + 2 + 5 + 57,
1535};
1536
1537static const struct panel_desc samsung_lsn122dl01_c01 = {
1538 .modes = &samsung_lsn122dl01_c01_mode,
1539 .num_modes = 1,
1540 .size = {
1541 .width = 263,
1542 .height = 164,
1543 },
1544};
1545
1546static const struct drm_display_mode samsung_ltn140at29_301_mode = {
1547 .clock = 76300,
1548 .hdisplay = 1366,
1549 .hsync_start = 1366 + 64,
1550 .hsync_end = 1366 + 64 + 48,
1551 .htotal = 1366 + 64 + 48 + 128,
1552 .vdisplay = 768,
1553 .vsync_start = 768 + 2,
1554 .vsync_end = 768 + 2 + 5,
1555 .vtotal = 768 + 2 + 5 + 17,
1556};
1557
1558static const struct panel_desc samsung_ltn140at29_301 = {
1559 .modes = &samsung_ltn140at29_301_mode,
1560 .num_modes = 1,
1561 .bpc = 6,
1562 .size = {
1563 .width = 320,
1564 .height = 187,
1565 },
1566};
1567
1568static const struct drm_display_mode sharp_ld_d5116z01b_mode = {
1569 .clock = 168480,
1570 .hdisplay = 1920,
1571 .hsync_start = 1920 + 48,
1572 .hsync_end = 1920 + 48 + 32,
1573 .htotal = 1920 + 48 + 32 + 80,
1574 .vdisplay = 1280,
1575 .vsync_start = 1280 + 3,
1576 .vsync_end = 1280 + 3 + 10,
1577 .vtotal = 1280 + 3 + 10 + 57,
1578 .flags = DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC,
1579};
1580
1581static const struct panel_desc sharp_ld_d5116z01b = {
1582 .modes = &sharp_ld_d5116z01b_mode,
1583 .num_modes = 1,
1584 .bpc = 8,
1585 .size = {
1586 .width = 260,
1587 .height = 120,
1588 },
1589};
1590
1591static const struct display_timing sharp_lq123p1jx31_timing = {
1592 .pixelclock = { 252750000, 252750000, 266604720 },
1593 .hactive = { 2400, 2400, 2400 },
1594 .hfront_porch = { 48, 48, 48 },
1595 .hback_porch = { 80, 80, 84 },
1596 .hsync_len = { 32, 32, 32 },
1597 .vactive = { 1600, 1600, 1600 },
1598 .vfront_porch = { 3, 3, 3 },
1599 .vback_porch = { 33, 33, 120 },
1600 .vsync_len = { 10, 10, 10 },
1601 .flags = DISPLAY_FLAGS_VSYNC_LOW | DISPLAY_FLAGS_HSYNC_LOW,
1602};
1603
1604static const struct panel_desc sharp_lq123p1jx31 = {
1605 .timings = &sharp_lq123p1jx31_timing,
1606 .num_timings = 1,
1607 .bpc = 8,
1608 .size = {
1609 .width = 259,
1610 .height = 173,
1611 },
1612 .delay = {
1613 .hpd_reliable = 110,
1614 .enable = 50,
1615 .unprepare = 550,
1616 },
1617};
1618
1619static const struct of_device_id platform_of_match[] = {
1620 {
1621 /* Must be first */
1622 .compatible = "edp-panel",
1623 },
1624 /*
1625 * Do not add panels to the list below unless they cannot be handled by
1626 * the generic edp-panel compatible.
1627 *
1628 * The only two valid reasons are:
1629 * - Because of the panel issues (e.g. broken EDID or broken
1630 * identification).
1631 * - Because the eDP drivers didn't wire up the AUX bus properly.
1632 * NOTE that, though this is a marginally valid reason,
1633 * some justification needs to be made for why the platform can't
1634 * wire up the AUX bus properly.
1635 *
1636 * In all other cases the platform should use the aux-bus and declare
1637 * the panel using the 'edp-panel' compatible as a device on the AUX
1638 * bus.
1639 */
1640 {
1641 .compatible = "auo,b101ean01",
1642 .data = &auo_b101ean01,
1643 }, {
1644 .compatible = "auo,b116xa01",
1645 .data = &auo_b116xak01,
1646 }, {
1647 .compatible = "auo,b133htn01",
1648 .data = &auo_b133htn01,
1649 }, {
1650 .compatible = "auo,b133xtn01",
1651 .data = &auo_b133xtn01,
1652 }, {
1653 .compatible = "boe,nv101wxmn51",
1654 .data = &boe_nv101wxmn51,
1655 }, {
1656 .compatible = "boe,nv110wtm-n61",
1657 .data = &boe_nv110wtm_n61,
1658 }, {
1659 .compatible = "boe,nv133fhm-n61",
1660 .data = &boe_nv133fhm_n61,
1661 }, {
1662 .compatible = "boe,nv133fhm-n62",
1663 .data = &boe_nv133fhm_n61,
1664 }, {
1665 .compatible = "boe,nv140fhmn49",
1666 .data = &boe_nv140fhmn49,
1667 }, {
1668 .compatible = "innolux,n116bca-ea1",
1669 .data = &innolux_n116bca_ea1,
1670 }, {
1671 .compatible = "innolux,n116bge",
1672 .data = &innolux_n116bge,
1673 }, {
1674 .compatible = "innolux,n125hce-gn1",
1675 .data = &innolux_n125hce_gn1,
1676 }, {
1677 .compatible = "innolux,p120zdg-bf1",
1678 .data = &innolux_p120zdg_bf1,
1679 }, {
1680 .compatible = "kingdisplay,kd116n21-30nv-a010",
1681 .data = &kingdisplay_kd116n21_30nv_a010,
1682 }, {
1683 .compatible = "lg,lp079qx1-sp0v",
1684 .data = &lg_lp079qx1_sp0v,
1685 }, {
1686 .compatible = "lg,lp097qx1-spa1",
1687 .data = &lg_lp097qx1_spa1,
1688 }, {
1689 .compatible = "lg,lp120up1",
1690 .data = &lg_lp120up1,
1691 }, {
1692 .compatible = "lg,lp129qe",
1693 .data = &lg_lp129qe,
1694 }, {
1695 .compatible = "neweast,wjfh116008a",
1696 .data = &neweast_wjfh116008a,
1697 }, {
1698 .compatible = "samsung,lsn122dl01-c01",
1699 .data = &samsung_lsn122dl01_c01,
1700 }, {
1701 .compatible = "samsung,ltn140at29-301",
1702 .data = &samsung_ltn140at29_301,
1703 }, {
1704 .compatible = "sharp,ld-d5116z01b",
1705 .data = &sharp_ld_d5116z01b,
1706 }, {
1707 .compatible = "sharp,lq123p1jx31",
1708 .data = &sharp_lq123p1jx31,
1709 }, {
1710 /* sentinel */
1711 }
1712};
1713MODULE_DEVICE_TABLE(of, platform_of_match);
1714
1715static const struct panel_delay delay_200_500_p2e80 = {
1716 .hpd_absent = 200,
1717 .unprepare = 500,
1718 .prepare_to_enable = 80,
1719};
1720
1721static const struct panel_delay delay_200_500_e50_p2e80 = {
1722 .hpd_absent = 200,
1723 .unprepare = 500,
1724 .enable = 50,
1725 .prepare_to_enable = 80,
1726};
1727
1728static const struct panel_delay delay_200_500_p2e100 = {
1729 .hpd_absent = 200,
1730 .unprepare = 500,
1731 .prepare_to_enable = 100,
1732};
1733
1734static const struct panel_delay delay_200_500_e50 = {
1735 .hpd_absent = 200,
1736 .unprepare = 500,
1737 .enable = 50,
1738};
1739
1740static const struct panel_delay delay_200_500_e50_p2e200 = {
1741 .hpd_absent = 200,
1742 .unprepare = 500,
1743 .enable = 50,
1744 .prepare_to_enable = 200,
1745};
1746
1747static const struct panel_delay delay_200_500_e80 = {
1748 .hpd_absent = 200,
1749 .unprepare = 500,
1750 .enable = 80,
1751};
1752
1753static const struct panel_delay delay_200_500_e80_d50 = {
1754 .hpd_absent = 200,
1755 .unprepare = 500,
1756 .enable = 80,
1757 .disable = 50,
1758};
1759
1760static const struct panel_delay delay_80_500_e50 = {
1761 .hpd_absent = 80,
1762 .unprepare = 500,
1763 .enable = 50,
1764};
1765
1766static const struct panel_delay delay_100_500_e200 = {
1767 .hpd_absent = 100,
1768 .unprepare = 500,
1769 .enable = 200,
1770};
1771
1772static const struct panel_delay delay_200_500_e200 = {
1773 .hpd_absent = 200,
1774 .unprepare = 500,
1775 .enable = 200,
1776};
1777
1778static const struct panel_delay delay_200_500_e200_d200 = {
1779 .hpd_absent = 200,
1780 .unprepare = 500,
1781 .enable = 200,
1782 .disable = 200,
1783};
1784
1785static const struct panel_delay delay_200_500_e200_d10 = {
1786 .hpd_absent = 200,
1787 .unprepare = 500,
1788 .enable = 200,
1789 .disable = 10,
1790};
1791
1792static const struct panel_delay delay_200_150_e200 = {
1793 .hpd_absent = 200,
1794 .unprepare = 150,
1795 .enable = 200,
1796};
1797
1798static const struct panel_delay delay_200_500_e50_po2e200 = {
1799 .hpd_absent = 200,
1800 .unprepare = 500,
1801 .enable = 50,
1802 .powered_on_to_enable = 200,
1803};
1804
1805#define EDP_PANEL_ENTRY(vend_chr_0, vend_chr_1, vend_chr_2, product_id, _delay, _name) \
1806{ \
1807 .ident = { \
1808 .name = _name, \
1809 .panel_id = drm_edid_encode_panel_id(vend_chr_0, vend_chr_1, vend_chr_2, \
1810 product_id), \
1811 }, \
1812 .delay = _delay \
1813}
1814
1815#define EDP_PANEL_ENTRY2(vend_chr_0, vend_chr_1, vend_chr_2, product_id, _delay, _name, _mode) \
1816{ \
1817 .ident = { \
1818 .name = _name, \
1819 .panel_id = drm_edid_encode_panel_id(vend_chr_0, vend_chr_1, vend_chr_2, \
1820 product_id), \
1821 }, \
1822 .delay = _delay, \
1823 .override_edid_mode = _mode \
1824}
1825
1826/*
1827 * This table is used to figure out power sequencing delays for panels that
1828 * are detected by EDID. Entries here may point to entries in the
1829 * platform_of_match table (if a panel is listed in both places).
1830 *
1831 * Sort first by vendor, then by product ID.
1832 */
1833static const struct edp_panel_entry edp_panels[] = {
1834 EDP_PANEL_ENTRY('A', 'U', 'O', 0x105c, &delay_200_500_e50, "B116XTN01.0"),
1835 EDP_PANEL_ENTRY('A', 'U', 'O', 0x1062, &delay_200_500_e50, "B120XAN01.0"),
1836 EDP_PANEL_ENTRY('A', 'U', 'O', 0x125c, &delay_200_500_e50, "Unknown"),
1837 EDP_PANEL_ENTRY('A', 'U', 'O', 0x145c, &delay_200_500_e50, "B116XAB01.4"),
1838 EDP_PANEL_ENTRY('A', 'U', 'O', 0x1999, &delay_200_500_e50, "Unknown"),
1839 EDP_PANEL_ENTRY('A', 'U', 'O', 0x1e9b, &delay_200_500_e50, "B133UAN02.1"),
1840 EDP_PANEL_ENTRY('A', 'U', 'O', 0x1ea5, &delay_200_500_e50, "B116XAK01.6"),
1841 EDP_PANEL_ENTRY('A', 'U', 'O', 0x203d, &delay_200_500_e50, "B140HTN02.0"),
1842 EDP_PANEL_ENTRY('A', 'U', 'O', 0x208d, &delay_200_500_e50, "B140HTN02.1"),
1843 EDP_PANEL_ENTRY('A', 'U', 'O', 0x235c, &delay_200_500_e50, "B116XTN02.3"),
1844 EDP_PANEL_ENTRY('A', 'U', 'O', 0x239b, &delay_200_500_e50, "B116XAN06.1"),
1845 EDP_PANEL_ENTRY('A', 'U', 'O', 0x255c, &delay_200_500_e50, "B116XTN02.5"),
1846 EDP_PANEL_ENTRY('A', 'U', 'O', 0x403d, &delay_200_500_e50, "B140HAN04.0"),
1847 EDP_PANEL_ENTRY('A', 'U', 'O', 0x405c, &auo_b116xak01.delay, "B116XAN04.0"),
1848 EDP_PANEL_ENTRY2('A', 'U', 'O', 0x405c, &auo_b116xak01.delay, "B116XAK01.0",
1849 &auo_b116xa3_mode),
1850 EDP_PANEL_ENTRY('A', 'U', 'O', 0x435c, &delay_200_500_e50, "Unknown"),
1851 EDP_PANEL_ENTRY('A', 'U', 'O', 0x582d, &delay_200_500_e50, "B133UAN01.0"),
1852 EDP_PANEL_ENTRY('A', 'U', 'O', 0x615c, &delay_200_500_e50, "B116XAN06.1"),
1853 EDP_PANEL_ENTRY('A', 'U', 'O', 0x635c, &delay_200_500_e50, "B116XAN06.3"),
1854 EDP_PANEL_ENTRY('A', 'U', 'O', 0x639c, &delay_200_500_e50, "B140HAK02.7"),
1855 EDP_PANEL_ENTRY('A', 'U', 'O', 0x723c, &delay_200_500_e50, "B140XTN07.2"),
1856 EDP_PANEL_ENTRY('A', 'U', 'O', 0x73aa, &delay_200_500_e50, "B116XTN02.3"),
1857 EDP_PANEL_ENTRY('A', 'U', 'O', 0x8594, &delay_200_500_e50, "B133UAN01.0"),
1858 EDP_PANEL_ENTRY('A', 'U', 'O', 0xa199, &delay_200_500_e50, "B116XAN06.1"),
1859 EDP_PANEL_ENTRY('A', 'U', 'O', 0xc4b4, &delay_200_500_e50, "B116XAT04.1"),
1860 EDP_PANEL_ENTRY('A', 'U', 'O', 0xd497, &delay_200_500_e50, "B120XAN01.0"),
1861 EDP_PANEL_ENTRY('A', 'U', 'O', 0xf390, &delay_200_500_e50, "B140XTN07.7"),
1862
1863 EDP_PANEL_ENTRY('B', 'O', 'E', 0x0607, &delay_200_500_e200, "Unknown"),
1864 EDP_PANEL_ENTRY('B', 'O', 'E', 0x0608, &delay_200_500_e50, "NT116WHM-N11"),
1865 EDP_PANEL_ENTRY('B', 'O', 'E', 0x0609, &delay_200_500_e50_po2e200, "NT116WHM-N21 V4.1"),
1866 EDP_PANEL_ENTRY('B', 'O', 'E', 0x0623, &delay_200_500_e200, "NT116WHM-N21 V4.0"),
1867 EDP_PANEL_ENTRY('B', 'O', 'E', 0x0668, &delay_200_500_e200, "Unknown"),
1868 EDP_PANEL_ENTRY('B', 'O', 'E', 0x068f, &delay_200_500_e200, "Unknown"),
1869 EDP_PANEL_ENTRY('B', 'O', 'E', 0x06e5, &delay_200_500_e200, "Unknown"),
1870 EDP_PANEL_ENTRY('B', 'O', 'E', 0x0705, &delay_200_500_e200, "Unknown"),
1871 EDP_PANEL_ENTRY('B', 'O', 'E', 0x0715, &delay_200_150_e200, "NT116WHM-N21"),
1872 EDP_PANEL_ENTRY('B', 'O', 'E', 0x0717, &delay_200_500_e50_po2e200, "NV133FHM-N42"),
1873 EDP_PANEL_ENTRY('B', 'O', 'E', 0x0731, &delay_200_500_e80, "NT116WHM-N42"),
1874 EDP_PANEL_ENTRY('B', 'O', 'E', 0x0741, &delay_200_500_e200, "NT116WHM-N44"),
1875 EDP_PANEL_ENTRY('B', 'O', 'E', 0x0744, &delay_200_500_e200, "Unknown"),
1876 EDP_PANEL_ENTRY('B', 'O', 'E', 0x074c, &delay_200_500_e200, "Unknown"),
1877 EDP_PANEL_ENTRY('B', 'O', 'E', 0x0751, &delay_200_500_e200, "Unknown"),
1878 EDP_PANEL_ENTRY('B', 'O', 'E', 0x0754, &delay_200_500_e50_po2e200, "NV116WHM-N45"),
1879 EDP_PANEL_ENTRY('B', 'O', 'E', 0x0771, &delay_200_500_e200, "Unknown"),
1880 EDP_PANEL_ENTRY('B', 'O', 'E', 0x0786, &delay_200_500_p2e80, "NV116WHM-T01"),
1881 EDP_PANEL_ENTRY('B', 'O', 'E', 0x0797, &delay_200_500_e200, "Unknown"),
1882 EDP_PANEL_ENTRY('B', 'O', 'E', 0x07a8, &delay_200_500_e50_po2e200, "NT116WHM-N21"),
1883 EDP_PANEL_ENTRY('B', 'O', 'E', 0x07d1, &boe_nv133fhm_n61.delay, "NV133FHM-N61"),
1884 EDP_PANEL_ENTRY('B', 'O', 'E', 0x07d3, &delay_200_500_e200, "Unknown"),
1885 EDP_PANEL_ENTRY('B', 'O', 'E', 0x07f6, &delay_200_500_e200, "NT140FHM-N44"),
1886 EDP_PANEL_ENTRY('B', 'O', 'E', 0x07f8, &delay_200_500_e200, "Unknown"),
1887 EDP_PANEL_ENTRY('B', 'O', 'E', 0x0813, &delay_200_500_e200, "Unknown"),
1888 EDP_PANEL_ENTRY('B', 'O', 'E', 0x0827, &delay_200_500_e50_p2e80, "NT140WHM-N44 V8.0"),
1889 EDP_PANEL_ENTRY('B', 'O', 'E', 0x082d, &boe_nv133fhm_n61.delay, "NV133FHM-N62"),
1890 EDP_PANEL_ENTRY('B', 'O', 'E', 0x0843, &delay_200_500_e200, "Unknown"),
1891 EDP_PANEL_ENTRY('B', 'O', 'E', 0x08b2, &delay_200_500_e200, "NT140WHM-N49"),
1892 EDP_PANEL_ENTRY('B', 'O', 'E', 0x0848, &delay_200_500_e200, "Unknown"),
1893 EDP_PANEL_ENTRY('B', 'O', 'E', 0x0849, &delay_200_500_e200, "Unknown"),
1894 EDP_PANEL_ENTRY('B', 'O', 'E', 0x09c3, &delay_200_500_e50, "NT116WHM-N21,836X2"),
1895 EDP_PANEL_ENTRY('B', 'O', 'E', 0x094b, &delay_200_500_e50, "NT116WHM-N21"),
1896 EDP_PANEL_ENTRY('B', 'O', 'E', 0x0951, &delay_200_500_e80, "NV116WHM-N47"),
1897 EDP_PANEL_ENTRY('B', 'O', 'E', 0x095f, &delay_200_500_e50, "NE135FBM-N41 v8.1"),
1898 EDP_PANEL_ENTRY('B', 'O', 'E', 0x096e, &delay_200_500_e50_po2e200, "NV116WHM-T07 V8.0"),
1899 EDP_PANEL_ENTRY('B', 'O', 'E', 0x0979, &delay_200_500_e50, "NV116WHM-N49 V8.0"),
1900 EDP_PANEL_ENTRY('B', 'O', 'E', 0x098d, &boe_nv110wtm_n61.delay, "NV110WTM-N61"),
1901 EDP_PANEL_ENTRY('B', 'O', 'E', 0x0993, &delay_200_500_e80, "NV116WHM-T14 V8.0"),
1902 EDP_PANEL_ENTRY('B', 'O', 'E', 0x09ad, &delay_200_500_e80, "NV116WHM-N47"),
1903 EDP_PANEL_ENTRY('B', 'O', 'E', 0x09ae, &delay_200_500_e200, "NT140FHM-N45"),
1904 EDP_PANEL_ENTRY('B', 'O', 'E', 0x09dd, &delay_200_500_e50, "NT116WHM-N21"),
1905 EDP_PANEL_ENTRY('B', 'O', 'E', 0x0a1b, &delay_200_500_e50, "NV133WUM-N63"),
1906 EDP_PANEL_ENTRY('B', 'O', 'E', 0x0a36, &delay_200_500_e200, "Unknown"),
1907 EDP_PANEL_ENTRY('B', 'O', 'E', 0x0a3e, &delay_200_500_e80, "NV116WHM-N49"),
1908 EDP_PANEL_ENTRY('B', 'O', 'E', 0x0a5d, &delay_200_500_e50, "NV116WHM-N45"),
1909 EDP_PANEL_ENTRY('B', 'O', 'E', 0x0ac5, &delay_200_500_e50, "NV116WHM-N4C"),
1910 EDP_PANEL_ENTRY('B', 'O', 'E', 0x0ae8, &delay_200_500_e50_p2e80, "NV140WUM-N41"),
1911 EDP_PANEL_ENTRY('B', 'O', 'E', 0x0b34, &delay_200_500_e80, "NV122WUM-N41"),
1912 EDP_PANEL_ENTRY('B', 'O', 'E', 0x0b43, &delay_200_500_e200, "NV140FHM-T09"),
1913 EDP_PANEL_ENTRY('B', 'O', 'E', 0x0b56, &delay_200_500_e80, "NT140FHM-N47"),
1914 EDP_PANEL_ENTRY('B', 'O', 'E', 0x0b66, &delay_200_500_e80, "NE140WUM-N6G"),
1915 EDP_PANEL_ENTRY('B', 'O', 'E', 0x0c20, &delay_200_500_e80, "NT140FHM-N47"),
1916 EDP_PANEL_ENTRY('B', 'O', 'E', 0x0cb6, &delay_200_500_e200, "NT116WHM-N44"),
1917 EDP_PANEL_ENTRY('B', 'O', 'E', 0x0cfa, &delay_200_500_e50, "NV116WHM-A4D"),
1918
1919 EDP_PANEL_ENTRY('C', 'M', 'N', 0x1130, &delay_200_500_e50, "N116BGE-EB2"),
1920 EDP_PANEL_ENTRY('C', 'M', 'N', 0x1132, &delay_200_500_e80_d50, "N116BGE-EA2"),
1921 EDP_PANEL_ENTRY('C', 'M', 'N', 0x1138, &innolux_n116bca_ea1.delay, "N116BCA-EA1-RC4"),
1922 EDP_PANEL_ENTRY('C', 'M', 'N', 0x1139, &delay_200_500_e80_d50, "N116BGE-EA2"),
1923 EDP_PANEL_ENTRY('C', 'M', 'N', 0x1141, &delay_200_500_e80_d50, "Unknown"),
1924 EDP_PANEL_ENTRY('C', 'M', 'N', 0x1145, &delay_200_500_e80_d50, "N116BCN-EB1"),
1925 EDP_PANEL_ENTRY('C', 'M', 'N', 0x114a, &delay_200_500_e80_d50, "Unknown"),
1926 EDP_PANEL_ENTRY('C', 'M', 'N', 0x114c, &innolux_n116bca_ea1.delay, "N116BCA-EA1"),
1927 EDP_PANEL_ENTRY('C', 'M', 'N', 0x1152, &delay_200_500_e80_d50, "N116BCN-EA1"),
1928 EDP_PANEL_ENTRY('C', 'M', 'N', 0x1153, &delay_200_500_e80_d50, "N116BGE-EA2"),
1929 EDP_PANEL_ENTRY('C', 'M', 'N', 0x1154, &delay_200_500_e80_d50, "N116BCA-EA2"),
1930 EDP_PANEL_ENTRY('C', 'M', 'N', 0x1156, &delay_200_500_e80_d50, "Unknown"),
1931 EDP_PANEL_ENTRY('C', 'M', 'N', 0x1157, &delay_200_500_e80_d50, "N116BGE-EA2"),
1932 EDP_PANEL_ENTRY('C', 'M', 'N', 0x115b, &delay_200_500_e80_d50, "N116BCN-EB1"),
1933 EDP_PANEL_ENTRY('C', 'M', 'N', 0x115d, &delay_200_500_e80_d50, "N116BCA-EA2"),
1934 EDP_PANEL_ENTRY('C', 'M', 'N', 0x115e, &delay_200_500_e80_d50, "N116BCA-EA1"),
1935 EDP_PANEL_ENTRY('C', 'M', 'N', 0x1160, &delay_200_500_e80_d50, "N116BCJ-EAK"),
1936 EDP_PANEL_ENTRY('C', 'M', 'N', 0x1161, &delay_200_500_e80, "N116BCP-EA2"),
1937 EDP_PANEL_ENTRY('C', 'M', 'N', 0x1247, &delay_200_500_e80_d50, "N120ACA-EA1"),
1938 EDP_PANEL_ENTRY('C', 'M', 'N', 0x142b, &delay_200_500_e80_d50, "N140HCA-EAC"),
1939 EDP_PANEL_ENTRY('C', 'M', 'N', 0x142e, &delay_200_500_e80_d50, "N140BGA-EA4"),
1940 EDP_PANEL_ENTRY('C', 'M', 'N', 0x144f, &delay_200_500_e80_d50, "N140HGA-EA1"),
1941 EDP_PANEL_ENTRY('C', 'M', 'N', 0x1468, &delay_200_500_e80, "N140HGA-EA1"),
1942 EDP_PANEL_ENTRY('C', 'M', 'N', 0x14d4, &delay_200_500_e80_d50, "N140HCA-EAC"),
1943 EDP_PANEL_ENTRY('C', 'M', 'N', 0x14d6, &delay_200_500_e80_d50, "N140BGA-EA4"),
1944 EDP_PANEL_ENTRY('C', 'M', 'N', 0x14e5, &delay_200_500_e80_d50, "N140HGA-EA1"),
1945
1946 EDP_PANEL_ENTRY('C', 'S', 'O', 0x1200, &delay_200_500_e50_p2e200, "MNC207QS1-1"),
1947
1948 EDP_PANEL_ENTRY('C', 'S', 'W', 0x1100, &delay_200_500_e80_d50, "MNB601LS1-1"),
1949 EDP_PANEL_ENTRY('C', 'S', 'W', 0x1104, &delay_200_500_e50, "MNB601LS1-4"),
1950
1951 EDP_PANEL_ENTRY('H', 'K', 'C', 0x2d51, &delay_200_500_e200, "Unknown"),
1952 EDP_PANEL_ENTRY('H', 'K', 'C', 0x2d5b, &delay_200_500_e200, "MB116AN01"),
1953 EDP_PANEL_ENTRY('H', 'K', 'C', 0x2d5c, &delay_200_500_e200, "MB116AN01-2"),
1954
1955 EDP_PANEL_ENTRY('I', 'V', 'O', 0x048e, &delay_200_500_e200_d10, "M116NWR6 R5"),
1956 EDP_PANEL_ENTRY('I', 'V', 'O', 0x057d, &delay_200_500_e200, "R140NWF5 RH"),
1957 EDP_PANEL_ENTRY('I', 'V', 'O', 0x854a, &delay_200_500_p2e100, "M133NW4J"),
1958 EDP_PANEL_ENTRY('I', 'V', 'O', 0x854b, &delay_200_500_p2e100, "R133NW4K-R0"),
1959 EDP_PANEL_ENTRY('I', 'V', 'O', 0x8c4d, &delay_200_150_e200, "R140NWFM R1"),
1960
1961 EDP_PANEL_ENTRY('K', 'D', 'B', 0x044f, &delay_200_500_e80_d50, "Unknown"),
1962 EDP_PANEL_ENTRY('K', 'D', 'B', 0x0624, &kingdisplay_kd116n21_30nv_a010.delay, "116N21-30NV-A010"),
1963 EDP_PANEL_ENTRY('K', 'D', 'B', 0x1118, &delay_200_500_e50, "KD116N29-30NK-A005"),
1964 EDP_PANEL_ENTRY('K', 'D', 'B', 0x1120, &delay_200_500_e80_d50, "116N29-30NK-C007"),
1965 EDP_PANEL_ENTRY('K', 'D', 'B', 0x1212, &delay_200_500_e50, "KD116N0930A16"),
1966
1967 EDP_PANEL_ENTRY('K', 'D', 'C', 0x044f, &delay_200_500_e50, "KD116N9-30NH-F3"),
1968 EDP_PANEL_ENTRY('K', 'D', 'C', 0x05f1, &delay_200_500_e80_d50, "KD116N5-30NV-G7"),
1969 EDP_PANEL_ENTRY('K', 'D', 'C', 0x0809, &delay_200_500_e50, "KD116N2930A15"),
1970
1971 EDP_PANEL_ENTRY('L', 'G', 'D', 0x0000, &delay_200_500_e200_d200, "Unknown"),
1972 EDP_PANEL_ENTRY('L', 'G', 'D', 0x048d, &delay_200_500_e200_d200, "Unknown"),
1973 EDP_PANEL_ENTRY('L', 'G', 'D', 0x0497, &delay_200_500_e200_d200, "LP116WH7-SPB1"),
1974 EDP_PANEL_ENTRY('L', 'G', 'D', 0x052c, &delay_200_500_e200_d200, "LP133WF2-SPL7"),
1975 EDP_PANEL_ENTRY('L', 'G', 'D', 0x0537, &delay_200_500_e200_d200, "Unknown"),
1976 EDP_PANEL_ENTRY('L', 'G', 'D', 0x054a, &delay_200_500_e200_d200, "LP116WH8-SPC1"),
1977 EDP_PANEL_ENTRY('L', 'G', 'D', 0x0567, &delay_200_500_e200_d200, "Unknown"),
1978 EDP_PANEL_ENTRY('L', 'G', 'D', 0x05af, &delay_200_500_e200_d200, "Unknown"),
1979 EDP_PANEL_ENTRY('L', 'G', 'D', 0x05f1, &delay_200_500_e200_d200, "Unknown"),
1980 EDP_PANEL_ENTRY('L', 'G', 'D', 0x0778, &delay_200_500_e200_d200, "134WT1"),
1981
1982 EDP_PANEL_ENTRY('S', 'H', 'P', 0x1511, &delay_200_500_e50, "LQ140M1JW48"),
1983 EDP_PANEL_ENTRY('S', 'H', 'P', 0x1523, &delay_80_500_e50, "LQ140M1JW46"),
1984 EDP_PANEL_ENTRY('S', 'H', 'P', 0x153a, &delay_200_500_e50, "LQ140T1JH01"),
1985 EDP_PANEL_ENTRY('S', 'H', 'P', 0x154c, &delay_200_500_p2e100, "LQ116M1JW10"),
1986 EDP_PANEL_ENTRY('S', 'H', 'P', 0x1593, &delay_200_500_p2e100, "LQ134N1"),
1987
1988 EDP_PANEL_ENTRY('S', 'T', 'A', 0x0100, &delay_100_500_e200, "2081116HHD028001-51D"),
1989
1990 { /* sentinal */ }
1991};
1992
1993static const struct edp_panel_entry *find_edp_panel(u32 panel_id, const struct drm_edid *edid)
1994{
1995 const struct edp_panel_entry *panel;
1996
1997 if (!panel_id)
1998 return NULL;
1999
2000 /*
2001 * Match with identity first. This allows handling the case where
2002 * vendors incorrectly reused the same panel ID for multiple panels that
2003 * need different settings. If there's no match, try again with panel
2004 * ID, which should be unique.
2005 */
2006 for (panel = edp_panels; panel->ident.panel_id; panel++)
2007 if (drm_edid_match(edid, &panel->ident))
2008 return panel;
2009
2010 for (panel = edp_panels; panel->ident.panel_id; panel++)
2011 if (panel->ident.panel_id == panel_id)
2012 return panel;
2013
2014 return NULL;
2015}
2016
2017static int panel_edp_platform_probe(struct platform_device *pdev)
2018{
2019 const struct of_device_id *id;
2020
2021 /* Skip one since "edp-panel" is only supported on DP AUX bus */
2022 id = of_match_node(platform_of_match + 1, pdev->dev.of_node);
2023 if (!id)
2024 return -ENODEV;
2025
2026 return panel_edp_probe(&pdev->dev, id->data, NULL);
2027}
2028
2029static void panel_edp_platform_remove(struct platform_device *pdev)
2030{
2031 panel_edp_remove(&pdev->dev);
2032}
2033
2034static void panel_edp_platform_shutdown(struct platform_device *pdev)
2035{
2036 panel_edp_shutdown(&pdev->dev);
2037}
2038
2039static const struct dev_pm_ops panel_edp_pm_ops = {
2040 SET_RUNTIME_PM_OPS(panel_edp_suspend, panel_edp_resume, NULL)
2041 SET_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend,
2042 pm_runtime_force_resume)
2043};
2044
2045static struct platform_driver panel_edp_platform_driver = {
2046 .driver = {
2047 .name = "panel-edp",
2048 .of_match_table = platform_of_match,
2049 .pm = &panel_edp_pm_ops,
2050 },
2051 .probe = panel_edp_platform_probe,
2052 .remove = panel_edp_platform_remove,
2053 .shutdown = panel_edp_platform_shutdown,
2054};
2055
2056static int panel_edp_dp_aux_ep_probe(struct dp_aux_ep_device *aux_ep)
2057{
2058 const struct of_device_id *id;
2059
2060 id = of_match_node(platform_of_match, aux_ep->dev.of_node);
2061 if (!id)
2062 return -ENODEV;
2063
2064 return panel_edp_probe(&aux_ep->dev, id->data, aux_ep->aux);
2065}
2066
2067static void panel_edp_dp_aux_ep_remove(struct dp_aux_ep_device *aux_ep)
2068{
2069 panel_edp_remove(&aux_ep->dev);
2070}
2071
2072static void panel_edp_dp_aux_ep_shutdown(struct dp_aux_ep_device *aux_ep)
2073{
2074 panel_edp_shutdown(&aux_ep->dev);
2075}
2076
2077static struct dp_aux_ep_driver panel_edp_dp_aux_ep_driver = {
2078 .driver = {
2079 .name = "panel-simple-dp-aux",
2080 .of_match_table = platform_of_match, /* Same as platform one! */
2081 .pm = &panel_edp_pm_ops,
2082 },
2083 .probe = panel_edp_dp_aux_ep_probe,
2084 .remove = panel_edp_dp_aux_ep_remove,
2085 .shutdown = panel_edp_dp_aux_ep_shutdown,
2086};
2087
2088static int __init panel_edp_init(void)
2089{
2090 int err;
2091
2092 err = platform_driver_register(&panel_edp_platform_driver);
2093 if (err < 0)
2094 return err;
2095
2096 err = dp_aux_dp_driver_register(&panel_edp_dp_aux_ep_driver);
2097 if (err < 0)
2098 goto err_did_platform_register;
2099
2100 return 0;
2101
2102err_did_platform_register:
2103 platform_driver_unregister(&panel_edp_platform_driver);
2104
2105 return err;
2106}
2107module_init(panel_edp_init);
2108
2109static void __exit panel_edp_exit(void)
2110{
2111 dp_aux_dp_driver_unregister(&panel_edp_dp_aux_ep_driver);
2112 platform_driver_unregister(&panel_edp_platform_driver);
2113}
2114module_exit(panel_edp_exit);
2115
2116MODULE_AUTHOR("Thierry Reding <treding@nvidia.com>");
2117MODULE_DESCRIPTION("DRM Driver for Simple eDP Panels");
2118MODULE_LICENSE("GPL and additional rights");
1/*
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/debugfs.h>
25#include <linux/delay.h>
26#include <linux/gpio/consumer.h>
27#include <linux/iopoll.h>
28#include <linux/module.h>
29#include <linux/of_platform.h>
30#include <linux/platform_device.h>
31#include <linux/pm_runtime.h>
32#include <linux/regulator/consumer.h>
33
34#include <video/display_timing.h>
35#include <video/of_display_timing.h>
36#include <video/videomode.h>
37
38#include <drm/display/drm_dp_aux_bus.h>
39#include <drm/display/drm_dp_helper.h>
40#include <drm/drm_crtc.h>
41#include <drm/drm_device.h>
42#include <drm/drm_edid.h>
43#include <drm/drm_panel.h>
44
45/**
46 * struct panel_delay - Describes delays for a simple panel.
47 */
48struct panel_delay {
49 /**
50 * @hpd_reliable: Time for HPD to be reliable
51 *
52 * The time (in milliseconds) that it takes after powering the panel
53 * before the HPD signal is reliable. Ideally this is 0 but some panels,
54 * board designs, or bad pulldown configs can cause a glitch here.
55 *
56 * NOTE: on some old panel data this number appears to be much too big.
57 * Presumably some old panels simply didn't have HPD hooked up and put
58 * the hpd_absent here because this field predates the
59 * hpd_absent. While that works, it's non-ideal.
60 */
61 unsigned int hpd_reliable;
62
63 /**
64 * @hpd_absent: Time to wait if HPD isn't hooked up.
65 *
66 * Add this to the prepare delay if we know Hot Plug Detect isn't used.
67 *
68 * This is T3-max on eDP timing diagrams or the delay from power on
69 * until HPD is guaranteed to be asserted.
70 */
71 unsigned int hpd_absent;
72
73 /**
74 * @prepare_to_enable: Time between prepare and enable.
75 *
76 * The minimum time, in milliseconds, that needs to have passed
77 * between when prepare finished and enable may begin. If at
78 * enable time less time has passed since prepare finished,
79 * the driver waits for the remaining time.
80 *
81 * If a fixed enable delay is also specified, we'll start
82 * counting before delaying for the fixed delay.
83 *
84 * If a fixed prepare delay is also specified, we won't start
85 * counting until after the fixed delay. We can't overlap this
86 * fixed delay with the min time because the fixed delay
87 * doesn't happen at the end of the function if a HPD GPIO was
88 * specified.
89 *
90 * In other words:
91 * prepare()
92 * ...
93 * // do fixed prepare delay
94 * // wait for HPD GPIO if applicable
95 * // start counting for prepare_to_enable
96 *
97 * enable()
98 * // do fixed enable delay
99 * // enforce prepare_to_enable min time
100 *
101 * This is not specified in a standard way on eDP timing diagrams.
102 * It is effectively the time from HPD going high till you can
103 * turn on the backlight.
104 */
105 unsigned int prepare_to_enable;
106
107 /**
108 * @enable: Time for the panel to display a valid frame.
109 *
110 * The time (in milliseconds) that it takes for the panel to
111 * display the first valid frame after starting to receive
112 * video data.
113 *
114 * This is (T6-min + max(T7-max, T8-min)) on eDP timing diagrams or
115 * the delay after link training finishes until we can turn the
116 * backlight on and see valid data.
117 */
118 unsigned int enable;
119
120 /**
121 * @disable: Time for the panel to turn the display off.
122 *
123 * The time (in milliseconds) that it takes for the panel to
124 * turn the display off (no content is visible).
125 *
126 * This is T9-min (delay from backlight off to end of valid video
127 * data) on eDP timing diagrams. It is not common to set.
128 */
129 unsigned int disable;
130
131 /**
132 * @unprepare: Time to power down completely.
133 *
134 * The time (in milliseconds) that it takes for the panel
135 * to power itself down completely.
136 *
137 * This time is used to prevent a future "prepare" from
138 * starting until at least this many milliseconds has passed.
139 * If at prepare time less time has passed since unprepare
140 * finished, the driver waits for the remaining time.
141 *
142 * This is T12-min on eDP timing diagrams.
143 */
144 unsigned int unprepare;
145};
146
147/**
148 * struct panel_desc - Describes a simple panel.
149 */
150struct panel_desc {
151 /**
152 * @modes: Pointer to array of fixed modes appropriate for this panel.
153 *
154 * If only one mode then this can just be the address of the mode.
155 * NOTE: cannot be used with "timings" and also if this is specified
156 * then you cannot override the mode in the device tree.
157 */
158 const struct drm_display_mode *modes;
159
160 /** @num_modes: Number of elements in modes array. */
161 unsigned int num_modes;
162
163 /**
164 * @timings: Pointer to array of display timings
165 *
166 * NOTE: cannot be used with "modes" and also these will be used to
167 * validate a device tree override if one is present.
168 */
169 const struct display_timing *timings;
170
171 /** @num_timings: Number of elements in timings array. */
172 unsigned int num_timings;
173
174 /** @bpc: Bits per color. */
175 unsigned int bpc;
176
177 /** @size: Structure containing the physical size of this panel. */
178 struct {
179 /**
180 * @size.width: Width (in mm) of the active display area.
181 */
182 unsigned int width;
183
184 /**
185 * @size.height: Height (in mm) of the active display area.
186 */
187 unsigned int height;
188 } size;
189
190 /** @delay: Structure containing various delay values for this panel. */
191 struct panel_delay delay;
192};
193
194/**
195 * struct edp_panel_entry - Maps panel ID to delay / panel name.
196 */
197struct edp_panel_entry {
198 /** @panel_id: 32-bit ID for panel, encoded with drm_edid_encode_panel_id(). */
199 u32 panel_id;
200
201 /** @delay: The power sequencing delays needed for this panel. */
202 const struct panel_delay *delay;
203
204 /** @name: Name of this panel (for printing to logs). */
205 const char *name;
206
207 /** @override_edid_mode: Override the mode obtained by edid. */
208 const struct drm_display_mode *override_edid_mode;
209};
210
211struct panel_edp {
212 struct drm_panel base;
213 bool enabled;
214 bool no_hpd;
215
216 bool prepared;
217
218 ktime_t prepared_time;
219 ktime_t unprepared_time;
220
221 const struct panel_desc *desc;
222
223 struct regulator *supply;
224 struct i2c_adapter *ddc;
225 struct drm_dp_aux *aux;
226
227 struct gpio_desc *enable_gpio;
228 struct gpio_desc *hpd_gpio;
229
230 const struct edp_panel_entry *detected_panel;
231
232 struct edid *edid;
233
234 struct drm_display_mode override_mode;
235
236 enum drm_panel_orientation orientation;
237};
238
239static inline struct panel_edp *to_panel_edp(struct drm_panel *panel)
240{
241 return container_of(panel, struct panel_edp, base);
242}
243
244static unsigned int panel_edp_get_timings_modes(struct panel_edp *panel,
245 struct drm_connector *connector)
246{
247 struct drm_display_mode *mode;
248 unsigned int i, num = 0;
249
250 for (i = 0; i < panel->desc->num_timings; i++) {
251 const struct display_timing *dt = &panel->desc->timings[i];
252 struct videomode vm;
253
254 videomode_from_timing(dt, &vm);
255 mode = drm_mode_create(connector->dev);
256 if (!mode) {
257 dev_err(panel->base.dev, "failed to add mode %ux%u\n",
258 dt->hactive.typ, dt->vactive.typ);
259 continue;
260 }
261
262 drm_display_mode_from_videomode(&vm, mode);
263
264 mode->type |= DRM_MODE_TYPE_DRIVER;
265
266 if (panel->desc->num_timings == 1)
267 mode->type |= DRM_MODE_TYPE_PREFERRED;
268
269 drm_mode_probed_add(connector, mode);
270 num++;
271 }
272
273 return num;
274}
275
276static unsigned int panel_edp_get_display_modes(struct panel_edp *panel,
277 struct drm_connector *connector)
278{
279 struct drm_display_mode *mode;
280 unsigned int i, num = 0;
281
282 for (i = 0; i < panel->desc->num_modes; i++) {
283 const struct drm_display_mode *m = &panel->desc->modes[i];
284
285 mode = drm_mode_duplicate(connector->dev, m);
286 if (!mode) {
287 dev_err(panel->base.dev, "failed to add mode %ux%u@%u\n",
288 m->hdisplay, m->vdisplay,
289 drm_mode_vrefresh(m));
290 continue;
291 }
292
293 mode->type |= DRM_MODE_TYPE_DRIVER;
294
295 if (panel->desc->num_modes == 1)
296 mode->type |= DRM_MODE_TYPE_PREFERRED;
297
298 drm_mode_set_name(mode);
299
300 drm_mode_probed_add(connector, mode);
301 num++;
302 }
303
304 return num;
305}
306
307static int panel_edp_override_edid_mode(struct panel_edp *panel,
308 struct drm_connector *connector,
309 const struct drm_display_mode *override_mode)
310{
311 struct drm_display_mode *mode;
312
313 mode = drm_mode_duplicate(connector->dev, override_mode);
314 if (!mode) {
315 dev_err(panel->base.dev, "failed to add additional mode\n");
316 return 0;
317 }
318
319 mode->type |= DRM_MODE_TYPE_DRIVER | DRM_MODE_TYPE_PREFERRED;
320 drm_mode_set_name(mode);
321 drm_mode_probed_add(connector, mode);
322 return 1;
323}
324
325static int panel_edp_get_non_edid_modes(struct panel_edp *panel,
326 struct drm_connector *connector)
327{
328 struct drm_display_mode *mode;
329 bool has_override = panel->override_mode.type;
330 unsigned int num = 0;
331
332 if (!panel->desc)
333 return 0;
334
335 if (has_override) {
336 mode = drm_mode_duplicate(connector->dev,
337 &panel->override_mode);
338 if (mode) {
339 drm_mode_probed_add(connector, mode);
340 num = 1;
341 } else {
342 dev_err(panel->base.dev, "failed to add override mode\n");
343 }
344 }
345
346 /* Only add timings if override was not there or failed to validate */
347 if (num == 0 && panel->desc->num_timings)
348 num = panel_edp_get_timings_modes(panel, connector);
349
350 /*
351 * Only add fixed modes if timings/override added no mode.
352 *
353 * We should only ever have either the display timings specified
354 * or a fixed mode. Anything else is rather bogus.
355 */
356 WARN_ON(panel->desc->num_timings && panel->desc->num_modes);
357 if (num == 0)
358 num = panel_edp_get_display_modes(panel, connector);
359
360 connector->display_info.bpc = panel->desc->bpc;
361 connector->display_info.width_mm = panel->desc->size.width;
362 connector->display_info.height_mm = panel->desc->size.height;
363
364 return num;
365}
366
367static void panel_edp_wait(ktime_t start_ktime, unsigned int min_ms)
368{
369 ktime_t now_ktime, min_ktime;
370
371 if (!min_ms)
372 return;
373
374 min_ktime = ktime_add(start_ktime, ms_to_ktime(min_ms));
375 now_ktime = ktime_get_boottime();
376
377 if (ktime_before(now_ktime, min_ktime))
378 msleep(ktime_to_ms(ktime_sub(min_ktime, now_ktime)) + 1);
379}
380
381static int panel_edp_disable(struct drm_panel *panel)
382{
383 struct panel_edp *p = to_panel_edp(panel);
384
385 if (!p->enabled)
386 return 0;
387
388 if (p->desc->delay.disable)
389 msleep(p->desc->delay.disable);
390
391 p->enabled = false;
392
393 return 0;
394}
395
396static int panel_edp_suspend(struct device *dev)
397{
398 struct panel_edp *p = dev_get_drvdata(dev);
399
400 gpiod_set_value_cansleep(p->enable_gpio, 0);
401 regulator_disable(p->supply);
402 p->unprepared_time = ktime_get_boottime();
403
404 return 0;
405}
406
407static int panel_edp_unprepare(struct drm_panel *panel)
408{
409 struct panel_edp *p = to_panel_edp(panel);
410 int ret;
411
412 /* Unpreparing when already unprepared is a no-op */
413 if (!p->prepared)
414 return 0;
415
416 pm_runtime_mark_last_busy(panel->dev);
417 ret = pm_runtime_put_autosuspend(panel->dev);
418 if (ret < 0)
419 return ret;
420 p->prepared = false;
421
422 return 0;
423}
424
425static int panel_edp_get_hpd_gpio(struct device *dev, struct panel_edp *p)
426{
427 p->hpd_gpio = devm_gpiod_get_optional(dev, "hpd", GPIOD_IN);
428 if (IS_ERR(p->hpd_gpio))
429 return dev_err_probe(dev, PTR_ERR(p->hpd_gpio),
430 "failed to get 'hpd' GPIO\n");
431
432 return 0;
433}
434
435static bool panel_edp_can_read_hpd(struct panel_edp *p)
436{
437 return !p->no_hpd && (p->hpd_gpio || (p->aux && p->aux->wait_hpd_asserted));
438}
439
440static int panel_edp_prepare_once(struct panel_edp *p)
441{
442 struct device *dev = p->base.dev;
443 unsigned int delay;
444 int err;
445 int hpd_asserted;
446 unsigned long hpd_wait_us;
447
448 panel_edp_wait(p->unprepared_time, p->desc->delay.unprepare);
449
450 err = regulator_enable(p->supply);
451 if (err < 0) {
452 dev_err(dev, "failed to enable supply: %d\n", err);
453 return err;
454 }
455
456 gpiod_set_value_cansleep(p->enable_gpio, 1);
457
458 delay = p->desc->delay.hpd_reliable;
459 if (p->no_hpd)
460 delay = max(delay, p->desc->delay.hpd_absent);
461 if (delay)
462 msleep(delay);
463
464 if (panel_edp_can_read_hpd(p)) {
465 if (p->desc->delay.hpd_absent)
466 hpd_wait_us = p->desc->delay.hpd_absent * 1000UL;
467 else
468 hpd_wait_us = 2000000;
469
470 if (p->hpd_gpio) {
471 err = readx_poll_timeout(gpiod_get_value_cansleep,
472 p->hpd_gpio, hpd_asserted,
473 hpd_asserted, 1000, hpd_wait_us);
474 if (hpd_asserted < 0)
475 err = hpd_asserted;
476 } else {
477 err = p->aux->wait_hpd_asserted(p->aux, hpd_wait_us);
478 }
479
480 if (err) {
481 if (err != -ETIMEDOUT)
482 dev_err(dev,
483 "error waiting for hpd GPIO: %d\n", err);
484 goto error;
485 }
486 }
487
488 p->prepared_time = ktime_get_boottime();
489
490 return 0;
491
492error:
493 gpiod_set_value_cansleep(p->enable_gpio, 0);
494 regulator_disable(p->supply);
495 p->unprepared_time = ktime_get_boottime();
496
497 return err;
498}
499
500/*
501 * Some panels simply don't always come up and need to be power cycled to
502 * work properly. We'll allow for a handful of retries.
503 */
504#define MAX_PANEL_PREPARE_TRIES 5
505
506static int panel_edp_resume(struct device *dev)
507{
508 struct panel_edp *p = dev_get_drvdata(dev);
509 int ret;
510 int try;
511
512 for (try = 0; try < MAX_PANEL_PREPARE_TRIES; try++) {
513 ret = panel_edp_prepare_once(p);
514 if (ret != -ETIMEDOUT)
515 break;
516 }
517
518 if (ret == -ETIMEDOUT)
519 dev_err(dev, "Prepare timeout after %d tries\n", try);
520 else if (try)
521 dev_warn(dev, "Prepare needed %d retries\n", try);
522
523 return ret;
524}
525
526static int panel_edp_prepare(struct drm_panel *panel)
527{
528 struct panel_edp *p = to_panel_edp(panel);
529 int ret;
530
531 /* Preparing when already prepared is a no-op */
532 if (p->prepared)
533 return 0;
534
535 ret = pm_runtime_get_sync(panel->dev);
536 if (ret < 0) {
537 pm_runtime_put_autosuspend(panel->dev);
538 return ret;
539 }
540
541 p->prepared = true;
542
543 return 0;
544}
545
546static int panel_edp_enable(struct drm_panel *panel)
547{
548 struct panel_edp *p = to_panel_edp(panel);
549 unsigned int delay;
550
551 if (p->enabled)
552 return 0;
553
554 delay = p->desc->delay.enable;
555
556 /*
557 * If there is a "prepare_to_enable" delay then that's supposed to be
558 * the delay from HPD going high until we can turn the backlight on.
559 * However, we can only count this if HPD is readable by the panel
560 * driver.
561 *
562 * If we aren't handling the HPD pin ourselves then the best we
563 * can do is assume that HPD went high immediately before we were
564 * called (and link training took zero time). Note that "no-hpd"
565 * actually counts as handling HPD ourselves since we're doing the
566 * worst case delay (in prepare) ourselves.
567 *
568 * NOTE: if we ever end up in this "if" statement then we're
569 * guaranteed that the panel_edp_wait() call below will do no delay.
570 * It already handles that case, though, so we don't need any special
571 * code for it.
572 */
573 if (p->desc->delay.prepare_to_enable &&
574 !panel_edp_can_read_hpd(p) && !p->no_hpd)
575 delay = max(delay, p->desc->delay.prepare_to_enable);
576
577 if (delay)
578 msleep(delay);
579
580 panel_edp_wait(p->prepared_time, p->desc->delay.prepare_to_enable);
581
582 p->enabled = true;
583
584 return 0;
585}
586
587static int panel_edp_get_modes(struct drm_panel *panel,
588 struct drm_connector *connector)
589{
590 struct panel_edp *p = to_panel_edp(panel);
591 int num = 0;
592 bool has_hard_coded_modes = p->desc->num_timings || p->desc->num_modes;
593 bool has_override_edid_mode = p->detected_panel &&
594 p->detected_panel != ERR_PTR(-EINVAL) &&
595 p->detected_panel->override_edid_mode;
596
597 /* probe EDID if a DDC bus is available */
598 if (p->ddc) {
599 pm_runtime_get_sync(panel->dev);
600
601 if (!p->edid)
602 p->edid = drm_get_edid(connector, p->ddc);
603 /*
604 * If both edid and hard-coded modes exists, skip edid modes to
605 * avoid multiple preferred modes.
606 */
607 if (p->edid && !has_hard_coded_modes) {
608 if (has_override_edid_mode) {
609 /*
610 * override_edid_mode is specified. Use
611 * override_edid_mode instead of from edid.
612 */
613 num += panel_edp_override_edid_mode(p, connector,
614 p->detected_panel->override_edid_mode);
615 } else {
616 num += drm_add_edid_modes(connector, p->edid);
617 }
618 }
619
620 pm_runtime_mark_last_busy(panel->dev);
621 pm_runtime_put_autosuspend(panel->dev);
622 }
623
624 if (has_hard_coded_modes)
625 num += panel_edp_get_non_edid_modes(p, connector);
626 else if (!num)
627 dev_warn(p->base.dev, "No display modes\n");
628
629 /*
630 * TODO: Remove once all drm drivers call
631 * drm_connector_set_orientation_from_panel()
632 */
633 drm_connector_set_panel_orientation(connector, p->orientation);
634
635 return num;
636}
637
638static int panel_edp_get_timings(struct drm_panel *panel,
639 unsigned int num_timings,
640 struct display_timing *timings)
641{
642 struct panel_edp *p = to_panel_edp(panel);
643 unsigned int i;
644
645 if (p->desc->num_timings < num_timings)
646 num_timings = p->desc->num_timings;
647
648 if (timings)
649 for (i = 0; i < num_timings; i++)
650 timings[i] = p->desc->timings[i];
651
652 return p->desc->num_timings;
653}
654
655static enum drm_panel_orientation panel_edp_get_orientation(struct drm_panel *panel)
656{
657 struct panel_edp *p = to_panel_edp(panel);
658
659 return p->orientation;
660}
661
662static int detected_panel_show(struct seq_file *s, void *data)
663{
664 struct drm_panel *panel = s->private;
665 struct panel_edp *p = to_panel_edp(panel);
666
667 if (IS_ERR(p->detected_panel))
668 seq_puts(s, "UNKNOWN\n");
669 else if (!p->detected_panel)
670 seq_puts(s, "HARDCODED\n");
671 else
672 seq_printf(s, "%s\n", p->detected_panel->name);
673
674 return 0;
675}
676
677DEFINE_SHOW_ATTRIBUTE(detected_panel);
678
679static void panel_edp_debugfs_init(struct drm_panel *panel, struct dentry *root)
680{
681 debugfs_create_file("detected_panel", 0600, root, panel, &detected_panel_fops);
682}
683
684static const struct drm_panel_funcs panel_edp_funcs = {
685 .disable = panel_edp_disable,
686 .unprepare = panel_edp_unprepare,
687 .prepare = panel_edp_prepare,
688 .enable = panel_edp_enable,
689 .get_modes = panel_edp_get_modes,
690 .get_orientation = panel_edp_get_orientation,
691 .get_timings = panel_edp_get_timings,
692 .debugfs_init = panel_edp_debugfs_init,
693};
694
695#define PANEL_EDP_BOUNDS_CHECK(to_check, bounds, field) \
696 (to_check->field.typ >= bounds->field.min && \
697 to_check->field.typ <= bounds->field.max)
698static void panel_edp_parse_panel_timing_node(struct device *dev,
699 struct panel_edp *panel,
700 const struct display_timing *ot)
701{
702 const struct panel_desc *desc = panel->desc;
703 struct videomode vm;
704 unsigned int i;
705
706 if (WARN_ON(desc->num_modes)) {
707 dev_err(dev, "Reject override mode: panel has a fixed mode\n");
708 return;
709 }
710 if (WARN_ON(!desc->num_timings)) {
711 dev_err(dev, "Reject override mode: no timings specified\n");
712 return;
713 }
714
715 for (i = 0; i < panel->desc->num_timings; i++) {
716 const struct display_timing *dt = &panel->desc->timings[i];
717
718 if (!PANEL_EDP_BOUNDS_CHECK(ot, dt, hactive) ||
719 !PANEL_EDP_BOUNDS_CHECK(ot, dt, hfront_porch) ||
720 !PANEL_EDP_BOUNDS_CHECK(ot, dt, hback_porch) ||
721 !PANEL_EDP_BOUNDS_CHECK(ot, dt, hsync_len) ||
722 !PANEL_EDP_BOUNDS_CHECK(ot, dt, vactive) ||
723 !PANEL_EDP_BOUNDS_CHECK(ot, dt, vfront_porch) ||
724 !PANEL_EDP_BOUNDS_CHECK(ot, dt, vback_porch) ||
725 !PANEL_EDP_BOUNDS_CHECK(ot, dt, vsync_len))
726 continue;
727
728 if (ot->flags != dt->flags)
729 continue;
730
731 videomode_from_timing(ot, &vm);
732 drm_display_mode_from_videomode(&vm, &panel->override_mode);
733 panel->override_mode.type |= DRM_MODE_TYPE_DRIVER |
734 DRM_MODE_TYPE_PREFERRED;
735 break;
736 }
737
738 if (WARN_ON(!panel->override_mode.type))
739 dev_err(dev, "Reject override mode: No display_timing found\n");
740}
741
742static const struct edp_panel_entry *find_edp_panel(u32 panel_id);
743
744static int generic_edp_panel_probe(struct device *dev, struct panel_edp *panel)
745{
746 struct panel_desc *desc;
747 u32 panel_id;
748 char vend[4];
749 u16 product_id;
750 u32 reliable_ms = 0;
751 u32 absent_ms = 0;
752 int ret;
753
754 desc = devm_kzalloc(dev, sizeof(*desc), GFP_KERNEL);
755 if (!desc)
756 return -ENOMEM;
757 panel->desc = desc;
758
759 /*
760 * Read the dts properties for the initial probe. These are used by
761 * the runtime resume code which will get called by the
762 * pm_runtime_get_sync() call below.
763 */
764 of_property_read_u32(dev->of_node, "hpd-reliable-delay-ms", &reliable_ms);
765 desc->delay.hpd_reliable = reliable_ms;
766 of_property_read_u32(dev->of_node, "hpd-absent-delay-ms", &absent_ms);
767 desc->delay.hpd_absent = absent_ms;
768
769 /* Power the panel on so we can read the EDID */
770 ret = pm_runtime_get_sync(dev);
771 if (ret < 0) {
772 dev_err(dev, "Couldn't power on panel to read EDID: %d\n", ret);
773 goto exit;
774 }
775
776 panel_id = drm_edid_get_panel_id(panel->ddc);
777 if (!panel_id) {
778 dev_err(dev, "Couldn't identify panel via EDID\n");
779 ret = -EIO;
780 goto exit;
781 }
782 drm_edid_decode_panel_id(panel_id, vend, &product_id);
783
784 panel->detected_panel = find_edp_panel(panel_id);
785
786 /*
787 * We're using non-optimized timings and want it really obvious that
788 * someone needs to add an entry to the table, so we'll do a WARN_ON
789 * splat.
790 */
791 if (WARN_ON(!panel->detected_panel)) {
792 dev_warn(dev,
793 "Unknown panel %s %#06x, using conservative timings\n",
794 vend, product_id);
795
796 /*
797 * It's highly likely that the panel will work if we use very
798 * conservative timings, so let's do that. We already know that
799 * the HPD-related delays must have worked since we got this
800 * far, so we really just need the "unprepare" / "enable"
801 * delays. We don't need "prepare_to_enable" since that
802 * overlaps the "enable" delay anyway.
803 *
804 * Nearly all panels have a "unprepare" delay of 500 ms though
805 * there are a few with 1000. Let's stick 2000 in just to be
806 * super conservative.
807 *
808 * An "enable" delay of 80 ms seems the most common, but we'll
809 * throw in 200 ms to be safe.
810 */
811 desc->delay.unprepare = 2000;
812 desc->delay.enable = 200;
813
814 panel->detected_panel = ERR_PTR(-EINVAL);
815 } else {
816 dev_info(dev, "Detected %s %s (%#06x)\n",
817 vend, panel->detected_panel->name, product_id);
818
819 /* Update the delay; everything else comes from EDID */
820 desc->delay = *panel->detected_panel->delay;
821 }
822
823 ret = 0;
824exit:
825 pm_runtime_mark_last_busy(dev);
826 pm_runtime_put_autosuspend(dev);
827
828 return ret;
829}
830
831static int panel_edp_probe(struct device *dev, const struct panel_desc *desc,
832 struct drm_dp_aux *aux)
833{
834 struct panel_edp *panel;
835 struct display_timing dt;
836 struct device_node *ddc;
837 int err;
838
839 panel = devm_kzalloc(dev, sizeof(*panel), GFP_KERNEL);
840 if (!panel)
841 return -ENOMEM;
842
843 panel->enabled = false;
844 panel->prepared_time = 0;
845 panel->desc = desc;
846 panel->aux = aux;
847
848 panel->no_hpd = of_property_read_bool(dev->of_node, "no-hpd");
849 if (!panel->no_hpd) {
850 err = panel_edp_get_hpd_gpio(dev, panel);
851 if (err)
852 return err;
853 }
854
855 panel->supply = devm_regulator_get(dev, "power");
856 if (IS_ERR(panel->supply))
857 return PTR_ERR(panel->supply);
858
859 panel->enable_gpio = devm_gpiod_get_optional(dev, "enable",
860 GPIOD_OUT_LOW);
861 if (IS_ERR(panel->enable_gpio))
862 return dev_err_probe(dev, PTR_ERR(panel->enable_gpio),
863 "failed to request GPIO\n");
864
865 err = of_drm_get_panel_orientation(dev->of_node, &panel->orientation);
866 if (err) {
867 dev_err(dev, "%pOF: failed to get orientation %d\n", dev->of_node, err);
868 return err;
869 }
870
871 ddc = of_parse_phandle(dev->of_node, "ddc-i2c-bus", 0);
872 if (ddc) {
873 panel->ddc = of_find_i2c_adapter_by_node(ddc);
874 of_node_put(ddc);
875
876 if (!panel->ddc)
877 return -EPROBE_DEFER;
878 } else if (aux) {
879 panel->ddc = &aux->ddc;
880 }
881
882 if (!of_get_display_timing(dev->of_node, "panel-timing", &dt))
883 panel_edp_parse_panel_timing_node(dev, panel, &dt);
884
885 dev_set_drvdata(dev, panel);
886
887 drm_panel_init(&panel->base, dev, &panel_edp_funcs, DRM_MODE_CONNECTOR_eDP);
888
889 err = drm_panel_of_backlight(&panel->base);
890 if (err)
891 goto err_finished_ddc_init;
892
893 /*
894 * We use runtime PM for prepare / unprepare since those power the panel
895 * on and off and those can be very slow operations. This is important
896 * to optimize powering the panel on briefly to read the EDID before
897 * fully enabling the panel.
898 */
899 pm_runtime_enable(dev);
900 pm_runtime_set_autosuspend_delay(dev, 1000);
901 pm_runtime_use_autosuspend(dev);
902
903 if (of_device_is_compatible(dev->of_node, "edp-panel")) {
904 err = generic_edp_panel_probe(dev, panel);
905 if (err) {
906 dev_err_probe(dev, err,
907 "Couldn't detect panel nor find a fallback\n");
908 goto err_finished_pm_runtime;
909 }
910 /* generic_edp_panel_probe() replaces desc in the panel */
911 desc = panel->desc;
912 } else if (desc->bpc != 6 && desc->bpc != 8 && desc->bpc != 10) {
913 dev_warn(dev, "Expected bpc in {6,8,10} but got: %u\n", desc->bpc);
914 }
915
916 if (!panel->base.backlight && panel->aux) {
917 pm_runtime_get_sync(dev);
918 err = drm_panel_dp_aux_backlight(&panel->base, panel->aux);
919 pm_runtime_mark_last_busy(dev);
920 pm_runtime_put_autosuspend(dev);
921 if (err)
922 goto err_finished_pm_runtime;
923 }
924
925 drm_panel_add(&panel->base);
926
927 return 0;
928
929err_finished_pm_runtime:
930 pm_runtime_dont_use_autosuspend(dev);
931 pm_runtime_disable(dev);
932err_finished_ddc_init:
933 if (panel->ddc && (!panel->aux || panel->ddc != &panel->aux->ddc))
934 put_device(&panel->ddc->dev);
935
936 return err;
937}
938
939static void panel_edp_remove(struct device *dev)
940{
941 struct panel_edp *panel = dev_get_drvdata(dev);
942
943 drm_panel_remove(&panel->base);
944 drm_panel_disable(&panel->base);
945 drm_panel_unprepare(&panel->base);
946
947 pm_runtime_dont_use_autosuspend(dev);
948 pm_runtime_disable(dev);
949 if (panel->ddc && (!panel->aux || panel->ddc != &panel->aux->ddc))
950 put_device(&panel->ddc->dev);
951
952 kfree(panel->edid);
953 panel->edid = NULL;
954}
955
956static void panel_edp_shutdown(struct device *dev)
957{
958 struct panel_edp *panel = dev_get_drvdata(dev);
959
960 drm_panel_disable(&panel->base);
961 drm_panel_unprepare(&panel->base);
962}
963
964static const struct display_timing auo_b101ean01_timing = {
965 .pixelclock = { 65300000, 72500000, 75000000 },
966 .hactive = { 1280, 1280, 1280 },
967 .hfront_porch = { 18, 119, 119 },
968 .hback_porch = { 21, 21, 21 },
969 .hsync_len = { 32, 32, 32 },
970 .vactive = { 800, 800, 800 },
971 .vfront_porch = { 4, 4, 4 },
972 .vback_porch = { 8, 8, 8 },
973 .vsync_len = { 18, 20, 20 },
974};
975
976static const struct panel_desc auo_b101ean01 = {
977 .timings = &auo_b101ean01_timing,
978 .num_timings = 1,
979 .bpc = 6,
980 .size = {
981 .width = 217,
982 .height = 136,
983 },
984};
985
986static const struct drm_display_mode auo_b116xa3_mode = {
987 .clock = 70589,
988 .hdisplay = 1366,
989 .hsync_start = 1366 + 40,
990 .hsync_end = 1366 + 40 + 40,
991 .htotal = 1366 + 40 + 40 + 32,
992 .vdisplay = 768,
993 .vsync_start = 768 + 10,
994 .vsync_end = 768 + 10 + 12,
995 .vtotal = 768 + 10 + 12 + 6,
996 .flags = DRM_MODE_FLAG_NVSYNC | DRM_MODE_FLAG_NHSYNC,
997};
998
999static const struct drm_display_mode auo_b116xak01_mode = {
1000 .clock = 69300,
1001 .hdisplay = 1366,
1002 .hsync_start = 1366 + 48,
1003 .hsync_end = 1366 + 48 + 32,
1004 .htotal = 1366 + 48 + 32 + 10,
1005 .vdisplay = 768,
1006 .vsync_start = 768 + 4,
1007 .vsync_end = 768 + 4 + 6,
1008 .vtotal = 768 + 4 + 6 + 15,
1009 .flags = DRM_MODE_FLAG_NVSYNC | DRM_MODE_FLAG_NHSYNC,
1010};
1011
1012static const struct panel_desc auo_b116xak01 = {
1013 .modes = &auo_b116xak01_mode,
1014 .num_modes = 1,
1015 .bpc = 6,
1016 .size = {
1017 .width = 256,
1018 .height = 144,
1019 },
1020 .delay = {
1021 .hpd_absent = 200,
1022 .unprepare = 500,
1023 .enable = 50,
1024 },
1025};
1026
1027static const struct drm_display_mode auo_b133han05_mode = {
1028 .clock = 142600,
1029 .hdisplay = 1920,
1030 .hsync_start = 1920 + 58,
1031 .hsync_end = 1920 + 58 + 42,
1032 .htotal = 1920 + 58 + 42 + 60,
1033 .vdisplay = 1080,
1034 .vsync_start = 1080 + 3,
1035 .vsync_end = 1080 + 3 + 5,
1036 .vtotal = 1080 + 3 + 5 + 54,
1037};
1038
1039static const struct panel_desc auo_b133han05 = {
1040 .modes = &auo_b133han05_mode,
1041 .num_modes = 1,
1042 .bpc = 8,
1043 .size = {
1044 .width = 293,
1045 .height = 165,
1046 },
1047 .delay = {
1048 .hpd_reliable = 100,
1049 .enable = 20,
1050 .unprepare = 50,
1051 },
1052};
1053
1054static const struct drm_display_mode auo_b133htn01_mode = {
1055 .clock = 150660,
1056 .hdisplay = 1920,
1057 .hsync_start = 1920 + 172,
1058 .hsync_end = 1920 + 172 + 80,
1059 .htotal = 1920 + 172 + 80 + 60,
1060 .vdisplay = 1080,
1061 .vsync_start = 1080 + 25,
1062 .vsync_end = 1080 + 25 + 10,
1063 .vtotal = 1080 + 25 + 10 + 10,
1064};
1065
1066static const struct panel_desc auo_b133htn01 = {
1067 .modes = &auo_b133htn01_mode,
1068 .num_modes = 1,
1069 .bpc = 6,
1070 .size = {
1071 .width = 293,
1072 .height = 165,
1073 },
1074 .delay = {
1075 .hpd_reliable = 105,
1076 .enable = 20,
1077 .unprepare = 50,
1078 },
1079};
1080
1081static const struct drm_display_mode auo_b133xtn01_mode = {
1082 .clock = 69500,
1083 .hdisplay = 1366,
1084 .hsync_start = 1366 + 48,
1085 .hsync_end = 1366 + 48 + 32,
1086 .htotal = 1366 + 48 + 32 + 20,
1087 .vdisplay = 768,
1088 .vsync_start = 768 + 3,
1089 .vsync_end = 768 + 3 + 6,
1090 .vtotal = 768 + 3 + 6 + 13,
1091};
1092
1093static const struct panel_desc auo_b133xtn01 = {
1094 .modes = &auo_b133xtn01_mode,
1095 .num_modes = 1,
1096 .bpc = 6,
1097 .size = {
1098 .width = 293,
1099 .height = 165,
1100 },
1101};
1102
1103static const struct drm_display_mode auo_b140han06_mode = {
1104 .clock = 141000,
1105 .hdisplay = 1920,
1106 .hsync_start = 1920 + 16,
1107 .hsync_end = 1920 + 16 + 16,
1108 .htotal = 1920 + 16 + 16 + 152,
1109 .vdisplay = 1080,
1110 .vsync_start = 1080 + 3,
1111 .vsync_end = 1080 + 3 + 14,
1112 .vtotal = 1080 + 3 + 14 + 19,
1113};
1114
1115static const struct panel_desc auo_b140han06 = {
1116 .modes = &auo_b140han06_mode,
1117 .num_modes = 1,
1118 .bpc = 8,
1119 .size = {
1120 .width = 309,
1121 .height = 174,
1122 },
1123 .delay = {
1124 .hpd_reliable = 100,
1125 .enable = 20,
1126 .unprepare = 50,
1127 },
1128};
1129
1130static const struct drm_display_mode boe_nv101wxmn51_modes[] = {
1131 {
1132 .clock = 71900,
1133 .hdisplay = 1280,
1134 .hsync_start = 1280 + 48,
1135 .hsync_end = 1280 + 48 + 32,
1136 .htotal = 1280 + 48 + 32 + 80,
1137 .vdisplay = 800,
1138 .vsync_start = 800 + 3,
1139 .vsync_end = 800 + 3 + 5,
1140 .vtotal = 800 + 3 + 5 + 24,
1141 },
1142 {
1143 .clock = 57500,
1144 .hdisplay = 1280,
1145 .hsync_start = 1280 + 48,
1146 .hsync_end = 1280 + 48 + 32,
1147 .htotal = 1280 + 48 + 32 + 80,
1148 .vdisplay = 800,
1149 .vsync_start = 800 + 3,
1150 .vsync_end = 800 + 3 + 5,
1151 .vtotal = 800 + 3 + 5 + 24,
1152 },
1153};
1154
1155static const struct panel_desc boe_nv101wxmn51 = {
1156 .modes = boe_nv101wxmn51_modes,
1157 .num_modes = ARRAY_SIZE(boe_nv101wxmn51_modes),
1158 .bpc = 8,
1159 .size = {
1160 .width = 217,
1161 .height = 136,
1162 },
1163 .delay = {
1164 /* TODO: should be hpd-absent and no-hpd should be set? */
1165 .hpd_reliable = 210,
1166 .enable = 50,
1167 .unprepare = 160,
1168 },
1169};
1170
1171static const struct drm_display_mode boe_nv110wtm_n61_modes[] = {
1172 {
1173 .clock = 207800,
1174 .hdisplay = 2160,
1175 .hsync_start = 2160 + 48,
1176 .hsync_end = 2160 + 48 + 32,
1177 .htotal = 2160 + 48 + 32 + 100,
1178 .vdisplay = 1440,
1179 .vsync_start = 1440 + 3,
1180 .vsync_end = 1440 + 3 + 6,
1181 .vtotal = 1440 + 3 + 6 + 31,
1182 .flags = DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC,
1183 },
1184 {
1185 .clock = 138500,
1186 .hdisplay = 2160,
1187 .hsync_start = 2160 + 48,
1188 .hsync_end = 2160 + 48 + 32,
1189 .htotal = 2160 + 48 + 32 + 100,
1190 .vdisplay = 1440,
1191 .vsync_start = 1440 + 3,
1192 .vsync_end = 1440 + 3 + 6,
1193 .vtotal = 1440 + 3 + 6 + 31,
1194 .flags = DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC,
1195 },
1196};
1197
1198static const struct panel_desc boe_nv110wtm_n61 = {
1199 .modes = boe_nv110wtm_n61_modes,
1200 .num_modes = ARRAY_SIZE(boe_nv110wtm_n61_modes),
1201 .bpc = 8,
1202 .size = {
1203 .width = 233,
1204 .height = 155,
1205 },
1206 .delay = {
1207 .hpd_absent = 200,
1208 .prepare_to_enable = 80,
1209 .enable = 50,
1210 .unprepare = 500,
1211 },
1212};
1213
1214/* Also used for boe_nv133fhm_n62 */
1215static const struct drm_display_mode boe_nv133fhm_n61_modes = {
1216 .clock = 147840,
1217 .hdisplay = 1920,
1218 .hsync_start = 1920 + 48,
1219 .hsync_end = 1920 + 48 + 32,
1220 .htotal = 1920 + 48 + 32 + 200,
1221 .vdisplay = 1080,
1222 .vsync_start = 1080 + 3,
1223 .vsync_end = 1080 + 3 + 6,
1224 .vtotal = 1080 + 3 + 6 + 31,
1225 .flags = DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC,
1226};
1227
1228/* Also used for boe_nv133fhm_n62 */
1229static const struct panel_desc boe_nv133fhm_n61 = {
1230 .modes = &boe_nv133fhm_n61_modes,
1231 .num_modes = 1,
1232 .bpc = 6,
1233 .size = {
1234 .width = 294,
1235 .height = 165,
1236 },
1237 .delay = {
1238 /*
1239 * When power is first given to the panel there's a short
1240 * spike on the HPD line. It was explained that this spike
1241 * was until the TCON data download was complete. On
1242 * one system this was measured at 8 ms. We'll put 15 ms
1243 * in the prepare delay just to be safe. That means:
1244 * - If HPD isn't hooked up you still have 200 ms delay.
1245 * - If HPD is hooked up we won't try to look at it for the
1246 * first 15 ms.
1247 */
1248 .hpd_reliable = 15,
1249 .hpd_absent = 200,
1250
1251 .unprepare = 500,
1252 },
1253};
1254
1255static const struct drm_display_mode boe_nv140fhmn49_modes[] = {
1256 {
1257 .clock = 148500,
1258 .hdisplay = 1920,
1259 .hsync_start = 1920 + 48,
1260 .hsync_end = 1920 + 48 + 32,
1261 .htotal = 2200,
1262 .vdisplay = 1080,
1263 .vsync_start = 1080 + 3,
1264 .vsync_end = 1080 + 3 + 5,
1265 .vtotal = 1125,
1266 },
1267};
1268
1269static const struct panel_desc boe_nv140fhmn49 = {
1270 .modes = boe_nv140fhmn49_modes,
1271 .num_modes = ARRAY_SIZE(boe_nv140fhmn49_modes),
1272 .bpc = 6,
1273 .size = {
1274 .width = 309,
1275 .height = 174,
1276 },
1277 .delay = {
1278 /* TODO: should be hpd-absent and no-hpd should be set? */
1279 .hpd_reliable = 210,
1280 .enable = 50,
1281 .unprepare = 160,
1282 },
1283};
1284
1285static const struct drm_display_mode innolux_n116bca_ea1_mode = {
1286 .clock = 76420,
1287 .hdisplay = 1366,
1288 .hsync_start = 1366 + 136,
1289 .hsync_end = 1366 + 136 + 30,
1290 .htotal = 1366 + 136 + 30 + 60,
1291 .vdisplay = 768,
1292 .vsync_start = 768 + 8,
1293 .vsync_end = 768 + 8 + 12,
1294 .vtotal = 768 + 8 + 12 + 12,
1295 .flags = DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC,
1296};
1297
1298static const struct panel_desc innolux_n116bca_ea1 = {
1299 .modes = &innolux_n116bca_ea1_mode,
1300 .num_modes = 1,
1301 .bpc = 6,
1302 .size = {
1303 .width = 256,
1304 .height = 144,
1305 },
1306 .delay = {
1307 .hpd_absent = 200,
1308 .enable = 80,
1309 .disable = 50,
1310 .unprepare = 500,
1311 },
1312};
1313
1314/*
1315 * Datasheet specifies that at 60 Hz refresh rate:
1316 * - total horizontal time: { 1506, 1592, 1716 }
1317 * - total vertical time: { 788, 800, 868 }
1318 *
1319 * ...but doesn't go into exactly how that should be split into a front
1320 * porch, back porch, or sync length. For now we'll leave a single setting
1321 * here which allows a bit of tweaking of the pixel clock at the expense of
1322 * refresh rate.
1323 */
1324static const struct display_timing innolux_n116bge_timing = {
1325 .pixelclock = { 72600000, 76420000, 80240000 },
1326 .hactive = { 1366, 1366, 1366 },
1327 .hfront_porch = { 136, 136, 136 },
1328 .hback_porch = { 60, 60, 60 },
1329 .hsync_len = { 30, 30, 30 },
1330 .vactive = { 768, 768, 768 },
1331 .vfront_porch = { 8, 8, 8 },
1332 .vback_porch = { 12, 12, 12 },
1333 .vsync_len = { 12, 12, 12 },
1334 .flags = DISPLAY_FLAGS_VSYNC_LOW | DISPLAY_FLAGS_HSYNC_LOW,
1335};
1336
1337static const struct panel_desc innolux_n116bge = {
1338 .timings = &innolux_n116bge_timing,
1339 .num_timings = 1,
1340 .bpc = 6,
1341 .size = {
1342 .width = 256,
1343 .height = 144,
1344 },
1345};
1346
1347static const struct drm_display_mode innolux_n125hce_gn1_mode = {
1348 .clock = 162000,
1349 .hdisplay = 1920,
1350 .hsync_start = 1920 + 40,
1351 .hsync_end = 1920 + 40 + 40,
1352 .htotal = 1920 + 40 + 40 + 80,
1353 .vdisplay = 1080,
1354 .vsync_start = 1080 + 4,
1355 .vsync_end = 1080 + 4 + 4,
1356 .vtotal = 1080 + 4 + 4 + 24,
1357};
1358
1359static const struct panel_desc innolux_n125hce_gn1 = {
1360 .modes = &innolux_n125hce_gn1_mode,
1361 .num_modes = 1,
1362 .bpc = 8,
1363 .size = {
1364 .width = 276,
1365 .height = 155,
1366 },
1367};
1368
1369static const struct drm_display_mode innolux_p120zdg_bf1_mode = {
1370 .clock = 206016,
1371 .hdisplay = 2160,
1372 .hsync_start = 2160 + 48,
1373 .hsync_end = 2160 + 48 + 32,
1374 .htotal = 2160 + 48 + 32 + 80,
1375 .vdisplay = 1440,
1376 .vsync_start = 1440 + 3,
1377 .vsync_end = 1440 + 3 + 10,
1378 .vtotal = 1440 + 3 + 10 + 27,
1379 .flags = DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC,
1380};
1381
1382static const struct panel_desc innolux_p120zdg_bf1 = {
1383 .modes = &innolux_p120zdg_bf1_mode,
1384 .num_modes = 1,
1385 .bpc = 8,
1386 .size = {
1387 .width = 254,
1388 .height = 169,
1389 },
1390 .delay = {
1391 .hpd_absent = 200,
1392 .unprepare = 500,
1393 },
1394};
1395
1396static const struct drm_display_mode ivo_m133nwf4_r0_mode = {
1397 .clock = 138778,
1398 .hdisplay = 1920,
1399 .hsync_start = 1920 + 24,
1400 .hsync_end = 1920 + 24 + 48,
1401 .htotal = 1920 + 24 + 48 + 88,
1402 .vdisplay = 1080,
1403 .vsync_start = 1080 + 3,
1404 .vsync_end = 1080 + 3 + 12,
1405 .vtotal = 1080 + 3 + 12 + 17,
1406 .flags = DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC,
1407};
1408
1409static const struct panel_desc ivo_m133nwf4_r0 = {
1410 .modes = &ivo_m133nwf4_r0_mode,
1411 .num_modes = 1,
1412 .bpc = 8,
1413 .size = {
1414 .width = 294,
1415 .height = 165,
1416 },
1417 .delay = {
1418 .hpd_absent = 200,
1419 .unprepare = 500,
1420 },
1421};
1422
1423static const struct drm_display_mode kingdisplay_kd116n21_30nv_a010_mode = {
1424 .clock = 81000,
1425 .hdisplay = 1366,
1426 .hsync_start = 1366 + 40,
1427 .hsync_end = 1366 + 40 + 32,
1428 .htotal = 1366 + 40 + 32 + 62,
1429 .vdisplay = 768,
1430 .vsync_start = 768 + 5,
1431 .vsync_end = 768 + 5 + 5,
1432 .vtotal = 768 + 5 + 5 + 122,
1433 .flags = DRM_MODE_FLAG_NVSYNC | DRM_MODE_FLAG_NHSYNC,
1434};
1435
1436static const struct panel_desc kingdisplay_kd116n21_30nv_a010 = {
1437 .modes = &kingdisplay_kd116n21_30nv_a010_mode,
1438 .num_modes = 1,
1439 .bpc = 6,
1440 .size = {
1441 .width = 256,
1442 .height = 144,
1443 },
1444 .delay = {
1445 .hpd_absent = 200,
1446 },
1447};
1448
1449static const struct drm_display_mode lg_lp079qx1_sp0v_mode = {
1450 .clock = 200000,
1451 .hdisplay = 1536,
1452 .hsync_start = 1536 + 12,
1453 .hsync_end = 1536 + 12 + 16,
1454 .htotal = 1536 + 12 + 16 + 48,
1455 .vdisplay = 2048,
1456 .vsync_start = 2048 + 8,
1457 .vsync_end = 2048 + 8 + 4,
1458 .vtotal = 2048 + 8 + 4 + 8,
1459 .flags = DRM_MODE_FLAG_NVSYNC | DRM_MODE_FLAG_NHSYNC,
1460};
1461
1462static const struct panel_desc lg_lp079qx1_sp0v = {
1463 .modes = &lg_lp079qx1_sp0v_mode,
1464 .num_modes = 1,
1465 .size = {
1466 .width = 129,
1467 .height = 171,
1468 },
1469};
1470
1471static const struct drm_display_mode lg_lp097qx1_spa1_mode = {
1472 .clock = 205210,
1473 .hdisplay = 2048,
1474 .hsync_start = 2048 + 150,
1475 .hsync_end = 2048 + 150 + 5,
1476 .htotal = 2048 + 150 + 5 + 5,
1477 .vdisplay = 1536,
1478 .vsync_start = 1536 + 3,
1479 .vsync_end = 1536 + 3 + 1,
1480 .vtotal = 1536 + 3 + 1 + 9,
1481};
1482
1483static const struct panel_desc lg_lp097qx1_spa1 = {
1484 .modes = &lg_lp097qx1_spa1_mode,
1485 .num_modes = 1,
1486 .size = {
1487 .width = 208,
1488 .height = 147,
1489 },
1490};
1491
1492static const struct drm_display_mode lg_lp120up1_mode = {
1493 .clock = 162300,
1494 .hdisplay = 1920,
1495 .hsync_start = 1920 + 40,
1496 .hsync_end = 1920 + 40 + 40,
1497 .htotal = 1920 + 40 + 40 + 80,
1498 .vdisplay = 1280,
1499 .vsync_start = 1280 + 4,
1500 .vsync_end = 1280 + 4 + 4,
1501 .vtotal = 1280 + 4 + 4 + 12,
1502};
1503
1504static const struct panel_desc lg_lp120up1 = {
1505 .modes = &lg_lp120up1_mode,
1506 .num_modes = 1,
1507 .bpc = 8,
1508 .size = {
1509 .width = 267,
1510 .height = 183,
1511 },
1512};
1513
1514static const struct drm_display_mode lg_lp129qe_mode = {
1515 .clock = 285250,
1516 .hdisplay = 2560,
1517 .hsync_start = 2560 + 48,
1518 .hsync_end = 2560 + 48 + 32,
1519 .htotal = 2560 + 48 + 32 + 80,
1520 .vdisplay = 1700,
1521 .vsync_start = 1700 + 3,
1522 .vsync_end = 1700 + 3 + 10,
1523 .vtotal = 1700 + 3 + 10 + 36,
1524};
1525
1526static const struct panel_desc lg_lp129qe = {
1527 .modes = &lg_lp129qe_mode,
1528 .num_modes = 1,
1529 .bpc = 8,
1530 .size = {
1531 .width = 272,
1532 .height = 181,
1533 },
1534};
1535
1536static const struct drm_display_mode neweast_wjfh116008a_modes[] = {
1537 {
1538 .clock = 138500,
1539 .hdisplay = 1920,
1540 .hsync_start = 1920 + 48,
1541 .hsync_end = 1920 + 48 + 32,
1542 .htotal = 1920 + 48 + 32 + 80,
1543 .vdisplay = 1080,
1544 .vsync_start = 1080 + 3,
1545 .vsync_end = 1080 + 3 + 5,
1546 .vtotal = 1080 + 3 + 5 + 23,
1547 .flags = DRM_MODE_FLAG_NVSYNC | DRM_MODE_FLAG_NHSYNC,
1548 }, {
1549 .clock = 110920,
1550 .hdisplay = 1920,
1551 .hsync_start = 1920 + 48,
1552 .hsync_end = 1920 + 48 + 32,
1553 .htotal = 1920 + 48 + 32 + 80,
1554 .vdisplay = 1080,
1555 .vsync_start = 1080 + 3,
1556 .vsync_end = 1080 + 3 + 5,
1557 .vtotal = 1080 + 3 + 5 + 23,
1558 .flags = DRM_MODE_FLAG_NVSYNC | DRM_MODE_FLAG_NHSYNC,
1559 }
1560};
1561
1562static const struct panel_desc neweast_wjfh116008a = {
1563 .modes = neweast_wjfh116008a_modes,
1564 .num_modes = 2,
1565 .bpc = 6,
1566 .size = {
1567 .width = 260,
1568 .height = 150,
1569 },
1570 .delay = {
1571 .hpd_reliable = 110,
1572 .enable = 20,
1573 .unprepare = 500,
1574 },
1575};
1576
1577static const struct drm_display_mode samsung_lsn122dl01_c01_mode = {
1578 .clock = 271560,
1579 .hdisplay = 2560,
1580 .hsync_start = 2560 + 48,
1581 .hsync_end = 2560 + 48 + 32,
1582 .htotal = 2560 + 48 + 32 + 80,
1583 .vdisplay = 1600,
1584 .vsync_start = 1600 + 2,
1585 .vsync_end = 1600 + 2 + 5,
1586 .vtotal = 1600 + 2 + 5 + 57,
1587};
1588
1589static const struct panel_desc samsung_lsn122dl01_c01 = {
1590 .modes = &samsung_lsn122dl01_c01_mode,
1591 .num_modes = 1,
1592 .size = {
1593 .width = 263,
1594 .height = 164,
1595 },
1596};
1597
1598static const struct drm_display_mode samsung_ltn140at29_301_mode = {
1599 .clock = 76300,
1600 .hdisplay = 1366,
1601 .hsync_start = 1366 + 64,
1602 .hsync_end = 1366 + 64 + 48,
1603 .htotal = 1366 + 64 + 48 + 128,
1604 .vdisplay = 768,
1605 .vsync_start = 768 + 2,
1606 .vsync_end = 768 + 2 + 5,
1607 .vtotal = 768 + 2 + 5 + 17,
1608};
1609
1610static const struct panel_desc samsung_ltn140at29_301 = {
1611 .modes = &samsung_ltn140at29_301_mode,
1612 .num_modes = 1,
1613 .bpc = 6,
1614 .size = {
1615 .width = 320,
1616 .height = 187,
1617 },
1618};
1619
1620static const struct drm_display_mode sharp_ld_d5116z01b_mode = {
1621 .clock = 168480,
1622 .hdisplay = 1920,
1623 .hsync_start = 1920 + 48,
1624 .hsync_end = 1920 + 48 + 32,
1625 .htotal = 1920 + 48 + 32 + 80,
1626 .vdisplay = 1280,
1627 .vsync_start = 1280 + 3,
1628 .vsync_end = 1280 + 3 + 10,
1629 .vtotal = 1280 + 3 + 10 + 57,
1630 .flags = DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC,
1631};
1632
1633static const struct panel_desc sharp_ld_d5116z01b = {
1634 .modes = &sharp_ld_d5116z01b_mode,
1635 .num_modes = 1,
1636 .bpc = 8,
1637 .size = {
1638 .width = 260,
1639 .height = 120,
1640 },
1641};
1642
1643static const struct display_timing sharp_lq123p1jx31_timing = {
1644 .pixelclock = { 252750000, 252750000, 266604720 },
1645 .hactive = { 2400, 2400, 2400 },
1646 .hfront_porch = { 48, 48, 48 },
1647 .hback_porch = { 80, 80, 84 },
1648 .hsync_len = { 32, 32, 32 },
1649 .vactive = { 1600, 1600, 1600 },
1650 .vfront_porch = { 3, 3, 3 },
1651 .vback_porch = { 33, 33, 120 },
1652 .vsync_len = { 10, 10, 10 },
1653 .flags = DISPLAY_FLAGS_VSYNC_LOW | DISPLAY_FLAGS_HSYNC_LOW,
1654};
1655
1656static const struct panel_desc sharp_lq123p1jx31 = {
1657 .timings = &sharp_lq123p1jx31_timing,
1658 .num_timings = 1,
1659 .bpc = 8,
1660 .size = {
1661 .width = 259,
1662 .height = 173,
1663 },
1664 .delay = {
1665 .hpd_reliable = 110,
1666 .enable = 50,
1667 .unprepare = 550,
1668 },
1669};
1670
1671static const struct drm_display_mode sharp_lq140m1jw46_mode[] = {
1672 {
1673 .clock = 346500,
1674 .hdisplay = 1920,
1675 .hsync_start = 1920 + 48,
1676 .hsync_end = 1920 + 48 + 32,
1677 .htotal = 1920 + 48 + 32 + 80,
1678 .vdisplay = 1080,
1679 .vsync_start = 1080 + 3,
1680 .vsync_end = 1080 + 3 + 5,
1681 .vtotal = 1080 + 3 + 5 + 69,
1682 .flags = DRM_MODE_FLAG_NVSYNC | DRM_MODE_FLAG_NHSYNC,
1683 }, {
1684 .clock = 144370,
1685 .hdisplay = 1920,
1686 .hsync_start = 1920 + 48,
1687 .hsync_end = 1920 + 48 + 32,
1688 .htotal = 1920 + 48 + 32 + 80,
1689 .vdisplay = 1080,
1690 .vsync_start = 1080 + 3,
1691 .vsync_end = 1080 + 3 + 5,
1692 .vtotal = 1080 + 3 + 5 + 69,
1693 .flags = DRM_MODE_FLAG_NVSYNC | DRM_MODE_FLAG_NHSYNC,
1694 },
1695};
1696
1697static const struct panel_desc sharp_lq140m1jw46 = {
1698 .modes = sharp_lq140m1jw46_mode,
1699 .num_modes = ARRAY_SIZE(sharp_lq140m1jw46_mode),
1700 .bpc = 8,
1701 .size = {
1702 .width = 309,
1703 .height = 174,
1704 },
1705 .delay = {
1706 .hpd_absent = 80,
1707 .enable = 50,
1708 .unprepare = 500,
1709 },
1710};
1711
1712static const struct drm_display_mode starry_kr122ea0sra_mode = {
1713 .clock = 147000,
1714 .hdisplay = 1920,
1715 .hsync_start = 1920 + 16,
1716 .hsync_end = 1920 + 16 + 16,
1717 .htotal = 1920 + 16 + 16 + 32,
1718 .vdisplay = 1200,
1719 .vsync_start = 1200 + 15,
1720 .vsync_end = 1200 + 15 + 2,
1721 .vtotal = 1200 + 15 + 2 + 18,
1722 .flags = DRM_MODE_FLAG_NVSYNC | DRM_MODE_FLAG_NHSYNC,
1723};
1724
1725static const struct panel_desc starry_kr122ea0sra = {
1726 .modes = &starry_kr122ea0sra_mode,
1727 .num_modes = 1,
1728 .size = {
1729 .width = 263,
1730 .height = 164,
1731 },
1732 .delay = {
1733 /* TODO: should be hpd-absent and no-hpd should be set? */
1734 .hpd_reliable = 10 + 200,
1735 .enable = 50,
1736 .unprepare = 10 + 500,
1737 },
1738};
1739
1740static const struct of_device_id platform_of_match[] = {
1741 {
1742 /* Must be first */
1743 .compatible = "edp-panel",
1744 }, {
1745 .compatible = "auo,b101ean01",
1746 .data = &auo_b101ean01,
1747 }, {
1748 .compatible = "auo,b116xa01",
1749 .data = &auo_b116xak01,
1750 }, {
1751 .compatible = "auo,b133han05",
1752 .data = &auo_b133han05,
1753 }, {
1754 .compatible = "auo,b133htn01",
1755 .data = &auo_b133htn01,
1756 }, {
1757 .compatible = "auo,b133xtn01",
1758 .data = &auo_b133xtn01,
1759 }, {
1760 .compatible = "auo,b140han06",
1761 .data = &auo_b140han06,
1762 }, {
1763 .compatible = "boe,nv101wxmn51",
1764 .data = &boe_nv101wxmn51,
1765 }, {
1766 .compatible = "boe,nv110wtm-n61",
1767 .data = &boe_nv110wtm_n61,
1768 }, {
1769 .compatible = "boe,nv133fhm-n61",
1770 .data = &boe_nv133fhm_n61,
1771 }, {
1772 .compatible = "boe,nv133fhm-n62",
1773 .data = &boe_nv133fhm_n61,
1774 }, {
1775 .compatible = "boe,nv140fhmn49",
1776 .data = &boe_nv140fhmn49,
1777 }, {
1778 .compatible = "innolux,n116bca-ea1",
1779 .data = &innolux_n116bca_ea1,
1780 }, {
1781 .compatible = "innolux,n116bge",
1782 .data = &innolux_n116bge,
1783 }, {
1784 .compatible = "innolux,n125hce-gn1",
1785 .data = &innolux_n125hce_gn1,
1786 }, {
1787 .compatible = "innolux,p120zdg-bf1",
1788 .data = &innolux_p120zdg_bf1,
1789 }, {
1790 .compatible = "ivo,m133nwf4-r0",
1791 .data = &ivo_m133nwf4_r0,
1792 }, {
1793 .compatible = "kingdisplay,kd116n21-30nv-a010",
1794 .data = &kingdisplay_kd116n21_30nv_a010,
1795 }, {
1796 .compatible = "lg,lp079qx1-sp0v",
1797 .data = &lg_lp079qx1_sp0v,
1798 }, {
1799 .compatible = "lg,lp097qx1-spa1",
1800 .data = &lg_lp097qx1_spa1,
1801 }, {
1802 .compatible = "lg,lp120up1",
1803 .data = &lg_lp120up1,
1804 }, {
1805 .compatible = "lg,lp129qe",
1806 .data = &lg_lp129qe,
1807 }, {
1808 .compatible = "neweast,wjfh116008a",
1809 .data = &neweast_wjfh116008a,
1810 }, {
1811 .compatible = "samsung,lsn122dl01-c01",
1812 .data = &samsung_lsn122dl01_c01,
1813 }, {
1814 .compatible = "samsung,ltn140at29-301",
1815 .data = &samsung_ltn140at29_301,
1816 }, {
1817 .compatible = "sharp,ld-d5116z01b",
1818 .data = &sharp_ld_d5116z01b,
1819 }, {
1820 .compatible = "sharp,lq123p1jx31",
1821 .data = &sharp_lq123p1jx31,
1822 }, {
1823 .compatible = "sharp,lq140m1jw46",
1824 .data = &sharp_lq140m1jw46,
1825 }, {
1826 .compatible = "starry,kr122ea0sra",
1827 .data = &starry_kr122ea0sra,
1828 }, {
1829 /* sentinel */
1830 }
1831};
1832MODULE_DEVICE_TABLE(of, platform_of_match);
1833
1834static const struct panel_delay delay_200_500_p2e80 = {
1835 .hpd_absent = 200,
1836 .unprepare = 500,
1837 .prepare_to_enable = 80,
1838};
1839
1840static const struct panel_delay delay_200_500_p2e100 = {
1841 .hpd_absent = 200,
1842 .unprepare = 500,
1843 .prepare_to_enable = 100,
1844};
1845
1846static const struct panel_delay delay_200_500_e50 = {
1847 .hpd_absent = 200,
1848 .unprepare = 500,
1849 .enable = 50,
1850};
1851
1852static const struct panel_delay delay_200_500_e80 = {
1853 .hpd_absent = 200,
1854 .unprepare = 500,
1855 .enable = 80,
1856};
1857
1858static const struct panel_delay delay_200_500_e80_d50 = {
1859 .hpd_absent = 200,
1860 .unprepare = 500,
1861 .enable = 80,
1862 .disable = 50,
1863};
1864
1865static const struct panel_delay delay_100_500_e200 = {
1866 .hpd_absent = 100,
1867 .unprepare = 500,
1868 .enable = 200,
1869};
1870
1871static const struct panel_delay delay_200_500_e200 = {
1872 .hpd_absent = 200,
1873 .unprepare = 500,
1874 .enable = 200,
1875};
1876
1877static const struct panel_delay delay_200_500_e200_d10 = {
1878 .hpd_absent = 200,
1879 .unprepare = 500,
1880 .enable = 200,
1881 .disable = 10,
1882};
1883
1884static const struct panel_delay delay_200_150_e200 = {
1885 .hpd_absent = 200,
1886 .unprepare = 150,
1887 .enable = 200,
1888};
1889
1890#define EDP_PANEL_ENTRY(vend_chr_0, vend_chr_1, vend_chr_2, product_id, _delay, _name) \
1891{ \
1892 .name = _name, \
1893 .panel_id = drm_edid_encode_panel_id(vend_chr_0, vend_chr_1, vend_chr_2, \
1894 product_id), \
1895 .delay = _delay \
1896}
1897
1898#define EDP_PANEL_ENTRY2(vend_chr_0, vend_chr_1, vend_chr_2, product_id, _delay, _name, _mode) \
1899{ \
1900 .name = _name, \
1901 .panel_id = drm_edid_encode_panel_id(vend_chr_0, vend_chr_1, vend_chr_2, \
1902 product_id), \
1903 .delay = _delay, \
1904 .override_edid_mode = _mode \
1905}
1906
1907/*
1908 * This table is used to figure out power sequencing delays for panels that
1909 * are detected by EDID. Entries here may point to entries in the
1910 * platform_of_match table (if a panel is listed in both places).
1911 *
1912 * Sort first by vendor, then by product ID.
1913 */
1914static const struct edp_panel_entry edp_panels[] = {
1915 EDP_PANEL_ENTRY('A', 'U', 'O', 0x1062, &delay_200_500_e50, "B120XAN01.0"),
1916 EDP_PANEL_ENTRY('A', 'U', 'O', 0x145c, &delay_200_500_e50, "B116XAB01.4"),
1917 EDP_PANEL_ENTRY('A', 'U', 'O', 0x1e9b, &delay_200_500_e50, "B133UAN02.1"),
1918 EDP_PANEL_ENTRY('A', 'U', 'O', 0x1ea5, &delay_200_500_e50, "B116XAK01.6"),
1919 EDP_PANEL_ENTRY('A', 'U', 'O', 0x208d, &delay_200_500_e50, "B140HTN02.1"),
1920 EDP_PANEL_ENTRY('A', 'U', 'O', 0x235c, &delay_200_500_e50, "B116XTN02.3"),
1921 EDP_PANEL_ENTRY('A', 'U', 'O', 0x239b, &delay_200_500_e50, "B116XAN06.1"),
1922 EDP_PANEL_ENTRY('A', 'U', 'O', 0x255c, &delay_200_500_e50, "B116XTN02.5"),
1923 EDP_PANEL_ENTRY('A', 'U', 'O', 0x403d, &delay_200_500_e50, "B140HAN04.0"),
1924 EDP_PANEL_ENTRY2('A', 'U', 'O', 0x405c, &auo_b116xak01.delay, "B116XAK01.0",
1925 &auo_b116xa3_mode),
1926 EDP_PANEL_ENTRY('A', 'U', 'O', 0x582d, &delay_200_500_e50, "B133UAN01.0"),
1927 EDP_PANEL_ENTRY2('A', 'U', 'O', 0x615c, &delay_200_500_e50, "B116XAN06.1",
1928 &auo_b116xa3_mode),
1929 EDP_PANEL_ENTRY('A', 'U', 'O', 0x635c, &delay_200_500_e50, "B116XAN06.3"),
1930 EDP_PANEL_ENTRY('A', 'U', 'O', 0x639c, &delay_200_500_e50, "B140HAK02.7"),
1931 EDP_PANEL_ENTRY('A', 'U', 'O', 0x8594, &delay_200_500_e50, "B133UAN01.0"),
1932 EDP_PANEL_ENTRY('A', 'U', 'O', 0xf390, &delay_200_500_e50, "B140XTN07.7"),
1933
1934 EDP_PANEL_ENTRY('B', 'O', 'E', 0x0715, &delay_200_150_e200, "NT116WHM-N21"),
1935 EDP_PANEL_ENTRY('B', 'O', 'E', 0x0731, &delay_200_500_e80, "NT116WHM-N42"),
1936 EDP_PANEL_ENTRY('B', 'O', 'E', 0x0741, &delay_200_500_e200, "NT116WHM-N44"),
1937 EDP_PANEL_ENTRY('B', 'O', 'E', 0x0786, &delay_200_500_p2e80, "NV116WHM-T01"),
1938 EDP_PANEL_ENTRY('B', 'O', 'E', 0x07d1, &boe_nv133fhm_n61.delay, "NV133FHM-N61"),
1939 EDP_PANEL_ENTRY('B', 'O', 'E', 0x07f6, &delay_200_500_e200, "NT140FHM-N44"),
1940 EDP_PANEL_ENTRY('B', 'O', 'E', 0x082d, &boe_nv133fhm_n61.delay, "NV133FHM-N62"),
1941 EDP_PANEL_ENTRY('B', 'O', 'E', 0x08b2, &delay_200_500_e200, "NT140WHM-N49"),
1942 EDP_PANEL_ENTRY('B', 'O', 'E', 0x09c3, &delay_200_500_e50, "NT116WHM-N21,836X2"),
1943 EDP_PANEL_ENTRY('B', 'O', 'E', 0x094b, &delay_200_500_e50, "NT116WHM-N21"),
1944 EDP_PANEL_ENTRY('B', 'O', 'E', 0x0951, &delay_200_500_e80, "NV116WHM-N47"),
1945 EDP_PANEL_ENTRY('B', 'O', 'E', 0x095f, &delay_200_500_e50, "NE135FBM-N41 v8.1"),
1946 EDP_PANEL_ENTRY('B', 'O', 'E', 0x0979, &delay_200_500_e50, "NV116WHM-N49 V8.0"),
1947 EDP_PANEL_ENTRY('B', 'O', 'E', 0x098d, &boe_nv110wtm_n61.delay, "NV110WTM-N61"),
1948 EDP_PANEL_ENTRY('B', 'O', 'E', 0x09ae, &delay_200_500_e200, "NT140FHM-N45"),
1949 EDP_PANEL_ENTRY('B', 'O', 'E', 0x09dd, &delay_200_500_e50, "NT116WHM-N21"),
1950 EDP_PANEL_ENTRY('B', 'O', 'E', 0x0a5d, &delay_200_500_e50, "NV116WHM-N45"),
1951 EDP_PANEL_ENTRY('B', 'O', 'E', 0x0ac5, &delay_200_500_e50, "NV116WHM-N4C"),
1952 EDP_PANEL_ENTRY('B', 'O', 'E', 0x0b43, &delay_200_500_e200, "NV140FHM-T09"),
1953 EDP_PANEL_ENTRY('B', 'O', 'E', 0x0b56, &delay_200_500_e80, "NT140FHM-N47"),
1954 EDP_PANEL_ENTRY('B', 'O', 'E', 0x0c20, &delay_200_500_e80, "NT140FHM-N47"),
1955
1956 EDP_PANEL_ENTRY('C', 'M', 'N', 0x1132, &delay_200_500_e80_d50, "N116BGE-EA2"),
1957 EDP_PANEL_ENTRY('C', 'M', 'N', 0x1138, &innolux_n116bca_ea1.delay, "N116BCA-EA1-RC4"),
1958 EDP_PANEL_ENTRY('C', 'M', 'N', 0x1139, &delay_200_500_e80_d50, "N116BGE-EA2"),
1959 EDP_PANEL_ENTRY('C', 'M', 'N', 0x1145, &delay_200_500_e80_d50, "N116BCN-EB1"),
1960 EDP_PANEL_ENTRY('C', 'M', 'N', 0x114c, &innolux_n116bca_ea1.delay, "N116BCA-EA1"),
1961 EDP_PANEL_ENTRY('C', 'M', 'N', 0x1152, &delay_200_500_e80_d50, "N116BCN-EA1"),
1962 EDP_PANEL_ENTRY('C', 'M', 'N', 0x1153, &delay_200_500_e80_d50, "N116BGE-EA2"),
1963 EDP_PANEL_ENTRY('C', 'M', 'N', 0x1154, &delay_200_500_e80_d50, "N116BCA-EA2"),
1964 EDP_PANEL_ENTRY('C', 'M', 'N', 0x1157, &delay_200_500_e80_d50, "N116BGE-EA2"),
1965 EDP_PANEL_ENTRY('C', 'M', 'N', 0x115b, &delay_200_500_e80_d50, "N116BCN-EB1"),
1966 EDP_PANEL_ENTRY('C', 'M', 'N', 0x1247, &delay_200_500_e80_d50, "N120ACA-EA1"),
1967 EDP_PANEL_ENTRY('C', 'M', 'N', 0x142b, &delay_200_500_e80_d50, "N140HCA-EAC"),
1968 EDP_PANEL_ENTRY('C', 'M', 'N', 0x144f, &delay_200_500_e80_d50, "N140HGA-EA1"),
1969 EDP_PANEL_ENTRY('C', 'M', 'N', 0x1468, &delay_200_500_e80, "N140HGA-EA1"),
1970 EDP_PANEL_ENTRY('C', 'M', 'N', 0x14d4, &delay_200_500_e80_d50, "N140HCA-EAC"),
1971 EDP_PANEL_ENTRY('C', 'M', 'N', 0x14d6, &delay_200_500_e80_d50, "N140BGA-EA4"),
1972 EDP_PANEL_ENTRY('C', 'M', 'N', 0x14e5, &delay_200_500_e80_d50, "N140HGA-EA1"),
1973
1974 EDP_PANEL_ENTRY('H', 'K', 'C', 0x2d5c, &delay_200_500_e200, "MB116AN01-2"),
1975
1976 EDP_PANEL_ENTRY('I', 'V', 'O', 0x048e, &delay_200_500_e200_d10, "M116NWR6 R5"),
1977 EDP_PANEL_ENTRY('I', 'V', 'O', 0x057d, &delay_200_500_e200, "R140NWF5 RH"),
1978 EDP_PANEL_ENTRY('I', 'V', 'O', 0x854a, &delay_200_500_p2e100, "M133NW4J"),
1979 EDP_PANEL_ENTRY('I', 'V', 'O', 0x854b, &delay_200_500_p2e100, "R133NW4K-R0"),
1980 EDP_PANEL_ENTRY('I', 'V', 'O', 0x8c4d, &delay_200_150_e200, "R140NWFM R1"),
1981
1982 EDP_PANEL_ENTRY('K', 'D', 'B', 0x0624, &kingdisplay_kd116n21_30nv_a010.delay, "116N21-30NV-A010"),
1983 EDP_PANEL_ENTRY('K', 'D', 'B', 0x1120, &delay_200_500_e80_d50, "116N29-30NK-C007"),
1984
1985 EDP_PANEL_ENTRY('K', 'D', 'C', 0x0809, &delay_200_500_e50, "KD116N2930A15"),
1986
1987 EDP_PANEL_ENTRY('S', 'D', 'C', 0x416d, &delay_100_500_e200, "ATNA45AF01"),
1988
1989 EDP_PANEL_ENTRY('S', 'H', 'P', 0x1511, &delay_200_500_e50, "LQ140M1JW48"),
1990 EDP_PANEL_ENTRY('S', 'H', 'P', 0x1523, &sharp_lq140m1jw46.delay, "LQ140M1JW46"),
1991 EDP_PANEL_ENTRY('S', 'H', 'P', 0x154c, &delay_200_500_p2e100, "LQ116M1JW10"),
1992
1993 EDP_PANEL_ENTRY('S', 'T', 'A', 0x0100, &delay_100_500_e200, "2081116HHD028001-51D"),
1994
1995 { /* sentinal */ }
1996};
1997
1998static const struct edp_panel_entry *find_edp_panel(u32 panel_id)
1999{
2000 const struct edp_panel_entry *panel;
2001
2002 if (!panel_id)
2003 return NULL;
2004
2005 for (panel = edp_panels; panel->panel_id; panel++)
2006 if (panel->panel_id == panel_id)
2007 return panel;
2008
2009 return NULL;
2010}
2011
2012static int panel_edp_platform_probe(struct platform_device *pdev)
2013{
2014 const struct of_device_id *id;
2015
2016 /* Skip one since "edp-panel" is only supported on DP AUX bus */
2017 id = of_match_node(platform_of_match + 1, pdev->dev.of_node);
2018 if (!id)
2019 return -ENODEV;
2020
2021 return panel_edp_probe(&pdev->dev, id->data, NULL);
2022}
2023
2024static void panel_edp_platform_remove(struct platform_device *pdev)
2025{
2026 panel_edp_remove(&pdev->dev);
2027}
2028
2029static void panel_edp_platform_shutdown(struct platform_device *pdev)
2030{
2031 panel_edp_shutdown(&pdev->dev);
2032}
2033
2034static const struct dev_pm_ops panel_edp_pm_ops = {
2035 SET_RUNTIME_PM_OPS(panel_edp_suspend, panel_edp_resume, NULL)
2036 SET_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend,
2037 pm_runtime_force_resume)
2038};
2039
2040static struct platform_driver panel_edp_platform_driver = {
2041 .driver = {
2042 .name = "panel-edp",
2043 .of_match_table = platform_of_match,
2044 .pm = &panel_edp_pm_ops,
2045 },
2046 .probe = panel_edp_platform_probe,
2047 .remove_new = panel_edp_platform_remove,
2048 .shutdown = panel_edp_platform_shutdown,
2049};
2050
2051static int panel_edp_dp_aux_ep_probe(struct dp_aux_ep_device *aux_ep)
2052{
2053 const struct of_device_id *id;
2054
2055 id = of_match_node(platform_of_match, aux_ep->dev.of_node);
2056 if (!id)
2057 return -ENODEV;
2058
2059 return panel_edp_probe(&aux_ep->dev, id->data, aux_ep->aux);
2060}
2061
2062static void panel_edp_dp_aux_ep_remove(struct dp_aux_ep_device *aux_ep)
2063{
2064 panel_edp_remove(&aux_ep->dev);
2065}
2066
2067static void panel_edp_dp_aux_ep_shutdown(struct dp_aux_ep_device *aux_ep)
2068{
2069 panel_edp_shutdown(&aux_ep->dev);
2070}
2071
2072static struct dp_aux_ep_driver panel_edp_dp_aux_ep_driver = {
2073 .driver = {
2074 .name = "panel-simple-dp-aux",
2075 .of_match_table = platform_of_match, /* Same as platform one! */
2076 .pm = &panel_edp_pm_ops,
2077 },
2078 .probe = panel_edp_dp_aux_ep_probe,
2079 .remove = panel_edp_dp_aux_ep_remove,
2080 .shutdown = panel_edp_dp_aux_ep_shutdown,
2081};
2082
2083static int __init panel_edp_init(void)
2084{
2085 int err;
2086
2087 err = platform_driver_register(&panel_edp_platform_driver);
2088 if (err < 0)
2089 return err;
2090
2091 err = dp_aux_dp_driver_register(&panel_edp_dp_aux_ep_driver);
2092 if (err < 0)
2093 goto err_did_platform_register;
2094
2095 return 0;
2096
2097err_did_platform_register:
2098 platform_driver_unregister(&panel_edp_platform_driver);
2099
2100 return err;
2101}
2102module_init(panel_edp_init);
2103
2104static void __exit panel_edp_exit(void)
2105{
2106 dp_aux_dp_driver_unregister(&panel_edp_dp_aux_ep_driver);
2107 platform_driver_unregister(&panel_edp_platform_driver);
2108}
2109module_exit(panel_edp_exit);
2110
2111MODULE_AUTHOR("Thierry Reding <treding@nvidia.com>");
2112MODULE_DESCRIPTION("DRM Driver for Simple eDP Panels");
2113MODULE_LICENSE("GPL and additional rights");