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