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