xref: /openbmc/linux/drivers/gpu/drm/panel/panel-edp.c (revision 9429b12d)
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 	/** @override_edid_mode: Override the mode obtained by edid. */
208 	const struct drm_display_mode *override_edid_mode;
209 };
210 
211 struct panel_edp {
212 	struct drm_panel base;
213 	bool enabled;
214 	bool no_hpd;
215 
216 	bool prepared;
217 
218 	ktime_t prepared_time;
219 	ktime_t unprepared_time;
220 
221 	const struct panel_desc *desc;
222 
223 	struct regulator *supply;
224 	struct i2c_adapter *ddc;
225 	struct drm_dp_aux *aux;
226 
227 	struct gpio_desc *enable_gpio;
228 	struct gpio_desc *hpd_gpio;
229 
230 	const struct edp_panel_entry *detected_panel;
231 
232 	struct edid *edid;
233 
234 	struct drm_display_mode override_mode;
235 
236 	enum drm_panel_orientation orientation;
237 };
238 
to_panel_edp(struct drm_panel * panel)239 static inline struct panel_edp *to_panel_edp(struct drm_panel *panel)
240 {
241 	return container_of(panel, struct panel_edp, base);
242 }
243 
panel_edp_get_timings_modes(struct panel_edp * panel,struct drm_connector * connector)244 static unsigned int panel_edp_get_timings_modes(struct panel_edp *panel,
245 						struct drm_connector *connector)
246 {
247 	struct drm_display_mode *mode;
248 	unsigned int i, num = 0;
249 
250 	for (i = 0; i < panel->desc->num_timings; i++) {
251 		const struct display_timing *dt = &panel->desc->timings[i];
252 		struct videomode vm;
253 
254 		videomode_from_timing(dt, &vm);
255 		mode = drm_mode_create(connector->dev);
256 		if (!mode) {
257 			dev_err(panel->base.dev, "failed to add mode %ux%u\n",
258 				dt->hactive.typ, dt->vactive.typ);
259 			continue;
260 		}
261 
262 		drm_display_mode_from_videomode(&vm, mode);
263 
264 		mode->type |= DRM_MODE_TYPE_DRIVER;
265 
266 		if (panel->desc->num_timings == 1)
267 			mode->type |= DRM_MODE_TYPE_PREFERRED;
268 
269 		drm_mode_probed_add(connector, mode);
270 		num++;
271 	}
272 
273 	return num;
274 }
275 
panel_edp_get_display_modes(struct panel_edp * panel,struct drm_connector * connector)276 static unsigned int panel_edp_get_display_modes(struct panel_edp *panel,
277 						struct drm_connector *connector)
278 {
279 	struct drm_display_mode *mode;
280 	unsigned int i, num = 0;
281 
282 	for (i = 0; i < panel->desc->num_modes; i++) {
283 		const struct drm_display_mode *m = &panel->desc->modes[i];
284 
285 		mode = drm_mode_duplicate(connector->dev, m);
286 		if (!mode) {
287 			dev_err(panel->base.dev, "failed to add mode %ux%u@%u\n",
288 				m->hdisplay, m->vdisplay,
289 				drm_mode_vrefresh(m));
290 			continue;
291 		}
292 
293 		mode->type |= DRM_MODE_TYPE_DRIVER;
294 
295 		if (panel->desc->num_modes == 1)
296 			mode->type |= DRM_MODE_TYPE_PREFERRED;
297 
298 		drm_mode_set_name(mode);
299 
300 		drm_mode_probed_add(connector, mode);
301 		num++;
302 	}
303 
304 	return num;
305 }
306 
panel_edp_override_edid_mode(struct panel_edp * panel,struct drm_connector * connector,const struct drm_display_mode * override_mode)307 static int panel_edp_override_edid_mode(struct panel_edp *panel,
308 					struct drm_connector *connector,
309 					const struct drm_display_mode *override_mode)
310 {
311 	struct drm_display_mode *mode;
312 
313 	mode = drm_mode_duplicate(connector->dev, override_mode);
314 	if (!mode) {
315 		dev_err(panel->base.dev, "failed to add additional mode\n");
316 		return 0;
317 	}
318 
319 	mode->type |= DRM_MODE_TYPE_DRIVER | DRM_MODE_TYPE_PREFERRED;
320 	drm_mode_set_name(mode);
321 	drm_mode_probed_add(connector, mode);
322 	return 1;
323 }
324 
panel_edp_get_non_edid_modes(struct panel_edp * panel,struct drm_connector * connector)325 static int panel_edp_get_non_edid_modes(struct panel_edp *panel,
326 					struct drm_connector *connector)
327 {
328 	struct drm_display_mode *mode;
329 	bool has_override = panel->override_mode.type;
330 	unsigned int num = 0;
331 
332 	if (!panel->desc)
333 		return 0;
334 
335 	if (has_override) {
336 		mode = drm_mode_duplicate(connector->dev,
337 					  &panel->override_mode);
338 		if (mode) {
339 			drm_mode_probed_add(connector, mode);
340 			num = 1;
341 		} else {
342 			dev_err(panel->base.dev, "failed to add override mode\n");
343 		}
344 	}
345 
346 	/* Only add timings if override was not there or failed to validate */
347 	if (num == 0 && panel->desc->num_timings)
348 		num = panel_edp_get_timings_modes(panel, connector);
349 
350 	/*
351 	 * Only add fixed modes if timings/override added no mode.
352 	 *
353 	 * We should only ever have either the display timings specified
354 	 * or a fixed mode. Anything else is rather bogus.
355 	 */
356 	WARN_ON(panel->desc->num_timings && panel->desc->num_modes);
357 	if (num == 0)
358 		num = panel_edp_get_display_modes(panel, connector);
359 
360 	connector->display_info.bpc = panel->desc->bpc;
361 	connector->display_info.width_mm = panel->desc->size.width;
362 	connector->display_info.height_mm = panel->desc->size.height;
363 
364 	return num;
365 }
366 
panel_edp_wait(ktime_t start_ktime,unsigned int min_ms)367 static void panel_edp_wait(ktime_t start_ktime, unsigned int min_ms)
368 {
369 	ktime_t now_ktime, min_ktime;
370 
371 	if (!min_ms)
372 		return;
373 
374 	min_ktime = ktime_add(start_ktime, ms_to_ktime(min_ms));
375 	now_ktime = ktime_get_boottime();
376 
377 	if (ktime_before(now_ktime, min_ktime))
378 		msleep(ktime_to_ms(ktime_sub(min_ktime, now_ktime)) + 1);
379 }
380 
panel_edp_disable(struct drm_panel * panel)381 static int panel_edp_disable(struct drm_panel *panel)
382 {
383 	struct panel_edp *p = to_panel_edp(panel);
384 
385 	if (!p->enabled)
386 		return 0;
387 
388 	if (p->desc->delay.disable)
389 		msleep(p->desc->delay.disable);
390 
391 	p->enabled = false;
392 
393 	return 0;
394 }
395 
panel_edp_suspend(struct device * dev)396 static int panel_edp_suspend(struct device *dev)
397 {
398 	struct panel_edp *p = dev_get_drvdata(dev);
399 
400 	drm_dp_dpcd_set_powered(p->aux, false);
401 	gpiod_set_value_cansleep(p->enable_gpio, 0);
402 	regulator_disable(p->supply);
403 	p->unprepared_time = ktime_get_boottime();
404 
405 	return 0;
406 }
407 
panel_edp_unprepare(struct drm_panel * panel)408 static int panel_edp_unprepare(struct drm_panel *panel)
409 {
410 	struct panel_edp *p = to_panel_edp(panel);
411 	int ret;
412 
413 	/* Unpreparing when already unprepared is a no-op */
414 	if (!p->prepared)
415 		return 0;
416 
417 	ret = pm_runtime_put_sync_suspend(panel->dev);
418 	if (ret < 0)
419 		return ret;
420 	p->prepared = false;
421 
422 	return 0;
423 }
424 
panel_edp_get_hpd_gpio(struct device * dev,struct panel_edp * p)425 static int panel_edp_get_hpd_gpio(struct device *dev, struct panel_edp *p)
426 {
427 	p->hpd_gpio = devm_gpiod_get_optional(dev, "hpd", GPIOD_IN);
428 	if (IS_ERR(p->hpd_gpio))
429 		return dev_err_probe(dev, PTR_ERR(p->hpd_gpio),
430 				     "failed to get 'hpd' GPIO\n");
431 
432 	return 0;
433 }
434 
panel_edp_can_read_hpd(struct panel_edp * p)435 static bool panel_edp_can_read_hpd(struct panel_edp *p)
436 {
437 	return !p->no_hpd && (p->hpd_gpio || (p->aux && p->aux->wait_hpd_asserted));
438 }
439 
panel_edp_prepare_once(struct panel_edp * p)440 static int panel_edp_prepare_once(struct panel_edp *p)
441 {
442 	struct device *dev = p->base.dev;
443 	unsigned int delay;
444 	int err;
445 	int hpd_asserted;
446 	unsigned long hpd_wait_us;
447 
448 	panel_edp_wait(p->unprepared_time, p->desc->delay.unprepare);
449 
450 	err = regulator_enable(p->supply);
451 	if (err < 0) {
452 		dev_err(dev, "failed to enable supply: %d\n", err);
453 		return err;
454 	}
455 
456 	gpiod_set_value_cansleep(p->enable_gpio, 1);
457 	drm_dp_dpcd_set_powered(p->aux, true);
458 
459 	delay = p->desc->delay.hpd_reliable;
460 	if (p->no_hpd)
461 		delay = max(delay, p->desc->delay.hpd_absent);
462 	if (delay)
463 		msleep(delay);
464 
465 	if (panel_edp_can_read_hpd(p)) {
466 		if (p->desc->delay.hpd_absent)
467 			hpd_wait_us = p->desc->delay.hpd_absent * 1000UL;
468 		else
469 			hpd_wait_us = 2000000;
470 
471 		if (p->hpd_gpio) {
472 			err = readx_poll_timeout(gpiod_get_value_cansleep,
473 						 p->hpd_gpio, hpd_asserted,
474 						 hpd_asserted, 1000, hpd_wait_us);
475 			if (hpd_asserted < 0)
476 				err = hpd_asserted;
477 		} else {
478 			err = p->aux->wait_hpd_asserted(p->aux, hpd_wait_us);
479 		}
480 
481 		if (err) {
482 			if (err != -ETIMEDOUT)
483 				dev_err(dev,
484 					"error waiting for hpd GPIO: %d\n", err);
485 			goto error;
486 		}
487 	}
488 
489 	p->prepared_time = ktime_get_boottime();
490 
491 	return 0;
492 
493 error:
494 	drm_dp_dpcd_set_powered(p->aux, false);
495 	gpiod_set_value_cansleep(p->enable_gpio, 0);
496 	regulator_disable(p->supply);
497 	p->unprepared_time = ktime_get_boottime();
498 
499 	return err;
500 }
501 
502 /*
503  * Some panels simply don't always come up and need to be power cycled to
504  * work properly.  We'll allow for a handful of retries.
505  */
506 #define MAX_PANEL_PREPARE_TRIES		5
507 
panel_edp_resume(struct device * dev)508 static int panel_edp_resume(struct device *dev)
509 {
510 	struct panel_edp *p = dev_get_drvdata(dev);
511 	int ret;
512 	int try;
513 
514 	for (try = 0; try < MAX_PANEL_PREPARE_TRIES; try++) {
515 		ret = panel_edp_prepare_once(p);
516 		if (ret != -ETIMEDOUT)
517 			break;
518 	}
519 
520 	if (ret == -ETIMEDOUT)
521 		dev_err(dev, "Prepare timeout after %d tries\n", try);
522 	else if (try)
523 		dev_warn(dev, "Prepare needed %d retries\n", try);
524 
525 	return ret;
526 }
527 
panel_edp_prepare(struct drm_panel * panel)528 static int panel_edp_prepare(struct drm_panel *panel)
529 {
530 	struct panel_edp *p = to_panel_edp(panel);
531 	int ret;
532 
533 	/* Preparing when already prepared is a no-op */
534 	if (p->prepared)
535 		return 0;
536 
537 	ret = pm_runtime_get_sync(panel->dev);
538 	if (ret < 0) {
539 		pm_runtime_put_autosuspend(panel->dev);
540 		return ret;
541 	}
542 
543 	p->prepared = true;
544 
545 	return 0;
546 }
547 
panel_edp_enable(struct drm_panel * panel)548 static int panel_edp_enable(struct drm_panel *panel)
549 {
550 	struct panel_edp *p = to_panel_edp(panel);
551 	unsigned int delay;
552 
553 	if (p->enabled)
554 		return 0;
555 
556 	delay = p->desc->delay.enable;
557 
558 	/*
559 	 * If there is a "prepare_to_enable" delay then that's supposed to be
560 	 * the delay from HPD going high until we can turn the backlight on.
561 	 * However, we can only count this if HPD is readable by the panel
562 	 * driver.
563 	 *
564 	 * If we aren't handling the HPD pin ourselves then the best we
565 	 * can do is assume that HPD went high immediately before we were
566 	 * called (and link training took zero time). Note that "no-hpd"
567 	 * actually counts as handling HPD ourselves since we're doing the
568 	 * worst case delay (in prepare) ourselves.
569 	 *
570 	 * NOTE: if we ever end up in this "if" statement then we're
571 	 * guaranteed that the panel_edp_wait() call below will do no delay.
572 	 * It already handles that case, though, so we don't need any special
573 	 * code for it.
574 	 */
575 	if (p->desc->delay.prepare_to_enable &&
576 	    !panel_edp_can_read_hpd(p) && !p->no_hpd)
577 		delay = max(delay, p->desc->delay.prepare_to_enable);
578 
579 	if (delay)
580 		msleep(delay);
581 
582 	panel_edp_wait(p->prepared_time, p->desc->delay.prepare_to_enable);
583 
584 	p->enabled = true;
585 
586 	return 0;
587 }
588 
panel_edp_get_modes(struct drm_panel * panel,struct drm_connector * connector)589 static int panel_edp_get_modes(struct drm_panel *panel,
590 			       struct drm_connector *connector)
591 {
592 	struct panel_edp *p = to_panel_edp(panel);
593 	int num = 0;
594 	bool has_override_edid_mode = p->detected_panel &&
595 				      p->detected_panel != ERR_PTR(-EINVAL) &&
596 				      p->detected_panel->override_edid_mode;
597 
598 	/* probe EDID if a DDC bus is available */
599 	if (p->ddc) {
600 		pm_runtime_get_sync(panel->dev);
601 
602 		if (!p->edid)
603 			p->edid = drm_get_edid(connector, p->ddc);
604 		if (p->edid) {
605 			if (has_override_edid_mode) {
606 				/*
607 				 * override_edid_mode is specified. Use
608 				 * override_edid_mode instead of from edid.
609 				 */
610 				num += panel_edp_override_edid_mode(p, connector,
611 						p->detected_panel->override_edid_mode);
612 			} else {
613 				num += drm_add_edid_modes(connector, p->edid);
614 			}
615 		}
616 
617 		pm_runtime_mark_last_busy(panel->dev);
618 		pm_runtime_put_autosuspend(panel->dev);
619 	}
620 
621 	/*
622 	 * Add hard-coded panel modes. Don't call this if there are no timings
623 	 * and no modes (the generic edp-panel case) because it will clobber
624 	 * the display_info that was already set by drm_add_edid_modes().
625 	 */
626 	if (p->desc->num_timings || p->desc->num_modes)
627 		num += panel_edp_get_non_edid_modes(p, connector);
628 	else if (!num)
629 		dev_warn(p->base.dev, "No display modes\n");
630 
631 	/*
632 	 * TODO: Remove once all drm drivers call
633 	 * drm_connector_set_orientation_from_panel()
634 	 */
635 	drm_connector_set_panel_orientation(connector, p->orientation);
636 
637 	return num;
638 }
639 
panel_edp_get_timings(struct drm_panel * panel,unsigned int num_timings,struct display_timing * timings)640 static int panel_edp_get_timings(struct drm_panel *panel,
641 				 unsigned int num_timings,
642 				 struct display_timing *timings)
643 {
644 	struct panel_edp *p = to_panel_edp(panel);
645 	unsigned int i;
646 
647 	if (p->desc->num_timings < num_timings)
648 		num_timings = p->desc->num_timings;
649 
650 	if (timings)
651 		for (i = 0; i < num_timings; i++)
652 			timings[i] = p->desc->timings[i];
653 
654 	return p->desc->num_timings;
655 }
656 
panel_edp_get_orientation(struct drm_panel * panel)657 static enum drm_panel_orientation panel_edp_get_orientation(struct drm_panel *panel)
658 {
659 	struct panel_edp *p = to_panel_edp(panel);
660 
661 	return p->orientation;
662 }
663 
detected_panel_show(struct seq_file * s,void * data)664 static int detected_panel_show(struct seq_file *s, void *data)
665 {
666 	struct drm_panel *panel = s->private;
667 	struct panel_edp *p = to_panel_edp(panel);
668 
669 	if (IS_ERR(p->detected_panel))
670 		seq_puts(s, "UNKNOWN\n");
671 	else if (!p->detected_panel)
672 		seq_puts(s, "HARDCODED\n");
673 	else
674 		seq_printf(s, "%s\n", p->detected_panel->name);
675 
676 	return 0;
677 }
678 
679 DEFINE_SHOW_ATTRIBUTE(detected_panel);
680 
panel_edp_debugfs_init(struct drm_panel * panel,struct dentry * root)681 static void panel_edp_debugfs_init(struct drm_panel *panel, struct dentry *root)
682 {
683 	debugfs_create_file("detected_panel", 0600, root, panel, &detected_panel_fops);
684 }
685 
686 static const struct drm_panel_funcs panel_edp_funcs = {
687 	.disable = panel_edp_disable,
688 	.unprepare = panel_edp_unprepare,
689 	.prepare = panel_edp_prepare,
690 	.enable = panel_edp_enable,
691 	.get_modes = panel_edp_get_modes,
692 	.get_orientation = panel_edp_get_orientation,
693 	.get_timings = panel_edp_get_timings,
694 	.debugfs_init = panel_edp_debugfs_init,
695 };
696 
697 #define PANEL_EDP_BOUNDS_CHECK(to_check, bounds, field) \
698 	(to_check->field.typ >= bounds->field.min && \
699 	 to_check->field.typ <= bounds->field.max)
panel_edp_parse_panel_timing_node(struct device * dev,struct panel_edp * panel,const struct display_timing * ot)700 static void panel_edp_parse_panel_timing_node(struct device *dev,
701 					      struct panel_edp *panel,
702 					      const struct display_timing *ot)
703 {
704 	const struct panel_desc *desc = panel->desc;
705 	struct videomode vm;
706 	unsigned int i;
707 
708 	if (WARN_ON(desc->num_modes)) {
709 		dev_err(dev, "Reject override mode: panel has a fixed mode\n");
710 		return;
711 	}
712 	if (WARN_ON(!desc->num_timings)) {
713 		dev_err(dev, "Reject override mode: no timings specified\n");
714 		return;
715 	}
716 
717 	for (i = 0; i < panel->desc->num_timings; i++) {
718 		const struct display_timing *dt = &panel->desc->timings[i];
719 
720 		if (!PANEL_EDP_BOUNDS_CHECK(ot, dt, hactive) ||
721 		    !PANEL_EDP_BOUNDS_CHECK(ot, dt, hfront_porch) ||
722 		    !PANEL_EDP_BOUNDS_CHECK(ot, dt, hback_porch) ||
723 		    !PANEL_EDP_BOUNDS_CHECK(ot, dt, hsync_len) ||
724 		    !PANEL_EDP_BOUNDS_CHECK(ot, dt, vactive) ||
725 		    !PANEL_EDP_BOUNDS_CHECK(ot, dt, vfront_porch) ||
726 		    !PANEL_EDP_BOUNDS_CHECK(ot, dt, vback_porch) ||
727 		    !PANEL_EDP_BOUNDS_CHECK(ot, dt, vsync_len))
728 			continue;
729 
730 		if (ot->flags != dt->flags)
731 			continue;
732 
733 		videomode_from_timing(ot, &vm);
734 		drm_display_mode_from_videomode(&vm, &panel->override_mode);
735 		panel->override_mode.type |= DRM_MODE_TYPE_DRIVER |
736 					     DRM_MODE_TYPE_PREFERRED;
737 		break;
738 	}
739 
740 	if (WARN_ON(!panel->override_mode.type))
741 		dev_err(dev, "Reject override mode: No display_timing found\n");
742 }
743 
744 static const struct edp_panel_entry *find_edp_panel(u32 panel_id);
745 
generic_edp_panel_probe(struct device * dev,struct panel_edp * panel)746 static int generic_edp_panel_probe(struct device *dev, struct panel_edp *panel)
747 {
748 	struct panel_desc *desc;
749 	u32 panel_id;
750 	char vend[4];
751 	u16 product_id;
752 	u32 reliable_ms = 0;
753 	u32 absent_ms = 0;
754 	int ret;
755 
756 	desc = devm_kzalloc(dev, sizeof(*desc), GFP_KERNEL);
757 	if (!desc)
758 		return -ENOMEM;
759 	panel->desc = desc;
760 
761 	/*
762 	 * Read the dts properties for the initial probe. These are used by
763 	 * the runtime resume code which will get called by the
764 	 * pm_runtime_get_sync() call below.
765 	 */
766 	of_property_read_u32(dev->of_node, "hpd-reliable-delay-ms", &reliable_ms);
767 	desc->delay.hpd_reliable = reliable_ms;
768 	of_property_read_u32(dev->of_node, "hpd-absent-delay-ms", &absent_ms);
769 	desc->delay.hpd_absent = absent_ms;
770 
771 	/* Power the panel on so we can read the EDID */
772 	ret = pm_runtime_get_sync(dev);
773 	if (ret < 0) {
774 		dev_err(dev, "Couldn't power on panel to read EDID: %d\n", ret);
775 		goto exit;
776 	}
777 
778 	panel_id = drm_edid_get_panel_id(panel->ddc);
779 	if (!panel_id) {
780 		dev_err(dev, "Couldn't identify panel via EDID\n");
781 		ret = -EIO;
782 		goto exit;
783 	}
784 	drm_edid_decode_panel_id(panel_id, vend, &product_id);
785 
786 	panel->detected_panel = find_edp_panel(panel_id);
787 
788 	/*
789 	 * We're using non-optimized timings and want it really obvious that
790 	 * someone needs to add an entry to the table, so we'll do a WARN_ON
791 	 * splat.
792 	 */
793 	if (WARN_ON(!panel->detected_panel)) {
794 		dev_warn(dev,
795 			 "Unknown panel %s %#06x, using conservative timings\n",
796 			 vend, product_id);
797 
798 		/*
799 		 * It's highly likely that the panel will work if we use very
800 		 * conservative timings, so let's do that. We already know that
801 		 * the HPD-related delays must have worked since we got this
802 		 * far, so we really just need the "unprepare" / "enable"
803 		 * delays. We don't need "prepare_to_enable" since that
804 		 * overlaps the "enable" delay anyway.
805 		 *
806 		 * Nearly all panels have a "unprepare" delay of 500 ms though
807 		 * there are a few with 1000. Let's stick 2000 in just to be
808 		 * super conservative.
809 		 *
810 		 * An "enable" delay of 80 ms seems the most common, but we'll
811 		 * throw in 200 ms to be safe.
812 		 */
813 		desc->delay.unprepare = 2000;
814 		desc->delay.enable = 200;
815 
816 		panel->detected_panel = ERR_PTR(-EINVAL);
817 	} else {
818 		dev_info(dev, "Detected %s %s (%#06x)\n",
819 			 vend, panel->detected_panel->name, product_id);
820 
821 		/* Update the delay; everything else comes from EDID */
822 		desc->delay = *panel->detected_panel->delay;
823 	}
824 
825 	ret = 0;
826 exit:
827 	pm_runtime_mark_last_busy(dev);
828 	pm_runtime_put_autosuspend(dev);
829 
830 	return ret;
831 }
832 
panel_edp_probe(struct device * dev,const struct panel_desc * desc,struct drm_dp_aux * aux)833 static int panel_edp_probe(struct device *dev, const struct panel_desc *desc,
834 			   struct drm_dp_aux *aux)
835 {
836 	struct panel_edp *panel;
837 	struct display_timing dt;
838 	struct device_node *ddc;
839 	int err;
840 
841 	panel = devm_kzalloc(dev, sizeof(*panel), GFP_KERNEL);
842 	if (!panel)
843 		return -ENOMEM;
844 
845 	panel->enabled = false;
846 	panel->prepared_time = 0;
847 	panel->desc = desc;
848 	panel->aux = aux;
849 
850 	panel->no_hpd = of_property_read_bool(dev->of_node, "no-hpd");
851 	if (!panel->no_hpd) {
852 		err = panel_edp_get_hpd_gpio(dev, panel);
853 		if (err)
854 			return err;
855 	}
856 
857 	panel->supply = devm_regulator_get(dev, "power");
858 	if (IS_ERR(panel->supply))
859 		return PTR_ERR(panel->supply);
860 
861 	panel->enable_gpio = devm_gpiod_get_optional(dev, "enable",
862 						     GPIOD_OUT_LOW);
863 	if (IS_ERR(panel->enable_gpio))
864 		return dev_err_probe(dev, PTR_ERR(panel->enable_gpio),
865 				     "failed to request GPIO\n");
866 
867 	err = of_drm_get_panel_orientation(dev->of_node, &panel->orientation);
868 	if (err) {
869 		dev_err(dev, "%pOF: failed to get orientation %d\n", dev->of_node, err);
870 		return err;
871 	}
872 
873 	ddc = of_parse_phandle(dev->of_node, "ddc-i2c-bus", 0);
874 	if (ddc) {
875 		panel->ddc = of_find_i2c_adapter_by_node(ddc);
876 		of_node_put(ddc);
877 
878 		if (!panel->ddc)
879 			return -EPROBE_DEFER;
880 	} else if (aux) {
881 		panel->ddc = &aux->ddc;
882 	}
883 
884 	if (!of_get_display_timing(dev->of_node, "panel-timing", &dt))
885 		panel_edp_parse_panel_timing_node(dev, panel, &dt);
886 
887 	dev_set_drvdata(dev, panel);
888 
889 	drm_panel_init(&panel->base, dev, &panel_edp_funcs, DRM_MODE_CONNECTOR_eDP);
890 
891 	err = drm_panel_of_backlight(&panel->base);
892 	if (err)
893 		goto err_finished_ddc_init;
894 
895 	/*
896 	 * We use runtime PM for prepare / unprepare since those power the panel
897 	 * on and off and those can be very slow operations. This is important
898 	 * to optimize powering the panel on briefly to read the EDID before
899 	 * fully enabling the panel.
900 	 */
901 	pm_runtime_enable(dev);
902 	pm_runtime_set_autosuspend_delay(dev, 1000);
903 	pm_runtime_use_autosuspend(dev);
904 
905 	if (of_device_is_compatible(dev->of_node, "edp-panel")) {
906 		err = generic_edp_panel_probe(dev, panel);
907 		if (err) {
908 			dev_err_probe(dev, err,
909 				      "Couldn't detect panel nor find a fallback\n");
910 			goto err_finished_pm_runtime;
911 		}
912 		/* generic_edp_panel_probe() replaces desc in the panel */
913 		desc = panel->desc;
914 	} else if (desc->bpc != 6 && desc->bpc != 8 && desc->bpc != 10) {
915 		dev_warn(dev, "Expected bpc in {6,8,10} but got: %u\n", desc->bpc);
916 	}
917 
918 	if (!panel->base.backlight && panel->aux) {
919 		pm_runtime_get_sync(dev);
920 		err = drm_panel_dp_aux_backlight(&panel->base, panel->aux);
921 		pm_runtime_mark_last_busy(dev);
922 		pm_runtime_put_autosuspend(dev);
923 		if (err)
924 			goto err_finished_pm_runtime;
925 	}
926 
927 	drm_panel_add(&panel->base);
928 
929 	return 0;
930 
931 err_finished_pm_runtime:
932 	pm_runtime_dont_use_autosuspend(dev);
933 	pm_runtime_disable(dev);
934 err_finished_ddc_init:
935 	if (panel->ddc && (!panel->aux || panel->ddc != &panel->aux->ddc))
936 		put_device(&panel->ddc->dev);
937 
938 	return err;
939 }
940 
panel_edp_remove(struct device * dev)941 static void panel_edp_remove(struct device *dev)
942 {
943 	struct panel_edp *panel = dev_get_drvdata(dev);
944 
945 	drm_panel_remove(&panel->base);
946 	drm_panel_disable(&panel->base);
947 	drm_panel_unprepare(&panel->base);
948 
949 	pm_runtime_dont_use_autosuspend(dev);
950 	pm_runtime_disable(dev);
951 	if (panel->ddc && (!panel->aux || panel->ddc != &panel->aux->ddc))
952 		put_device(&panel->ddc->dev);
953 
954 	kfree(panel->edid);
955 	panel->edid = NULL;
956 }
957 
panel_edp_shutdown(struct device * dev)958 static void panel_edp_shutdown(struct device *dev)
959 {
960 	struct panel_edp *panel = dev_get_drvdata(dev);
961 
962 	drm_panel_disable(&panel->base);
963 	drm_panel_unprepare(&panel->base);
964 }
965 
966 static const struct display_timing auo_b101ean01_timing = {
967 	.pixelclock = { 65300000, 72500000, 75000000 },
968 	.hactive = { 1280, 1280, 1280 },
969 	.hfront_porch = { 18, 119, 119 },
970 	.hback_porch = { 21, 21, 21 },
971 	.hsync_len = { 32, 32, 32 },
972 	.vactive = { 800, 800, 800 },
973 	.vfront_porch = { 4, 4, 4 },
974 	.vback_porch = { 8, 8, 8 },
975 	.vsync_len = { 18, 20, 20 },
976 };
977 
978 static const struct panel_desc auo_b101ean01 = {
979 	.timings = &auo_b101ean01_timing,
980 	.num_timings = 1,
981 	.bpc = 6,
982 	.size = {
983 		.width = 217,
984 		.height = 136,
985 	},
986 };
987 
988 static const struct drm_display_mode auo_b116xak01_mode = {
989 	.clock = 69300,
990 	.hdisplay = 1366,
991 	.hsync_start = 1366 + 48,
992 	.hsync_end = 1366 + 48 + 32,
993 	.htotal = 1366 + 48 + 32 + 10,
994 	.vdisplay = 768,
995 	.vsync_start = 768 + 4,
996 	.vsync_end = 768 + 4 + 6,
997 	.vtotal = 768 + 4 + 6 + 15,
998 	.flags = DRM_MODE_FLAG_NVSYNC | DRM_MODE_FLAG_NHSYNC,
999 };
1000 
1001 static const struct panel_desc auo_b116xak01 = {
1002 	.modes = &auo_b116xak01_mode,
1003 	.num_modes = 1,
1004 	.bpc = 6,
1005 	.size = {
1006 		.width = 256,
1007 		.height = 144,
1008 	},
1009 	.delay = {
1010 		.hpd_absent = 200,
1011 		.unprepare = 500,
1012 		.enable = 50,
1013 	},
1014 };
1015 
1016 static const struct drm_display_mode auo_b133han05_mode = {
1017 	.clock = 142600,
1018 	.hdisplay = 1920,
1019 	.hsync_start = 1920 + 58,
1020 	.hsync_end = 1920 + 58 + 42,
1021 	.htotal = 1920 + 58 + 42 + 60,
1022 	.vdisplay = 1080,
1023 	.vsync_start = 1080 + 3,
1024 	.vsync_end = 1080 + 3 + 5,
1025 	.vtotal = 1080 + 3 + 5 + 54,
1026 };
1027 
1028 static const struct panel_desc auo_b133han05 = {
1029 	.modes = &auo_b133han05_mode,
1030 	.num_modes = 1,
1031 	.bpc = 8,
1032 	.size = {
1033 		.width = 293,
1034 		.height = 165,
1035 	},
1036 	.delay = {
1037 		.hpd_reliable = 100,
1038 		.enable = 20,
1039 		.unprepare = 50,
1040 	},
1041 };
1042 
1043 static const struct drm_display_mode auo_b133htn01_mode = {
1044 	.clock = 150660,
1045 	.hdisplay = 1920,
1046 	.hsync_start = 1920 + 172,
1047 	.hsync_end = 1920 + 172 + 80,
1048 	.htotal = 1920 + 172 + 80 + 60,
1049 	.vdisplay = 1080,
1050 	.vsync_start = 1080 + 25,
1051 	.vsync_end = 1080 + 25 + 10,
1052 	.vtotal = 1080 + 25 + 10 + 10,
1053 };
1054 
1055 static const struct panel_desc auo_b133htn01 = {
1056 	.modes = &auo_b133htn01_mode,
1057 	.num_modes = 1,
1058 	.bpc = 6,
1059 	.size = {
1060 		.width = 293,
1061 		.height = 165,
1062 	},
1063 	.delay = {
1064 		.hpd_reliable = 105,
1065 		.enable = 20,
1066 		.unprepare = 50,
1067 	},
1068 };
1069 
1070 static const struct drm_display_mode auo_b133xtn01_mode = {
1071 	.clock = 69500,
1072 	.hdisplay = 1366,
1073 	.hsync_start = 1366 + 48,
1074 	.hsync_end = 1366 + 48 + 32,
1075 	.htotal = 1366 + 48 + 32 + 20,
1076 	.vdisplay = 768,
1077 	.vsync_start = 768 + 3,
1078 	.vsync_end = 768 + 3 + 6,
1079 	.vtotal = 768 + 3 + 6 + 13,
1080 };
1081 
1082 static const struct panel_desc auo_b133xtn01 = {
1083 	.modes = &auo_b133xtn01_mode,
1084 	.num_modes = 1,
1085 	.bpc = 6,
1086 	.size = {
1087 		.width = 293,
1088 		.height = 165,
1089 	},
1090 };
1091 
1092 static const struct drm_display_mode auo_b140han06_mode = {
1093 	.clock = 141000,
1094 	.hdisplay = 1920,
1095 	.hsync_start = 1920 + 16,
1096 	.hsync_end = 1920 + 16 + 16,
1097 	.htotal = 1920 + 16 + 16 + 152,
1098 	.vdisplay = 1080,
1099 	.vsync_start = 1080 + 3,
1100 	.vsync_end = 1080 + 3 + 14,
1101 	.vtotal = 1080 + 3 + 14 + 19,
1102 };
1103 
1104 static const struct panel_desc auo_b140han06 = {
1105 	.modes = &auo_b140han06_mode,
1106 	.num_modes = 1,
1107 	.bpc = 8,
1108 	.size = {
1109 		.width = 309,
1110 		.height = 174,
1111 	},
1112 	.delay = {
1113 		.hpd_reliable = 100,
1114 		.enable = 20,
1115 		.unprepare = 50,
1116 	},
1117 };
1118 
1119 static const struct drm_display_mode boe_nv101wxmn51_modes[] = {
1120 	{
1121 		.clock = 71900,
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 		.clock = 57500,
1133 		.hdisplay = 1280,
1134 		.hsync_start = 1280 + 48,
1135 		.hsync_end = 1280 + 48 + 32,
1136 		.htotal = 1280 + 48 + 32 + 80,
1137 		.vdisplay = 800,
1138 		.vsync_start = 800 + 3,
1139 		.vsync_end = 800 + 3 + 5,
1140 		.vtotal = 800 + 3 + 5 + 24,
1141 	},
1142 };
1143 
1144 static const struct panel_desc boe_nv101wxmn51 = {
1145 	.modes = boe_nv101wxmn51_modes,
1146 	.num_modes = ARRAY_SIZE(boe_nv101wxmn51_modes),
1147 	.bpc = 8,
1148 	.size = {
1149 		.width = 217,
1150 		.height = 136,
1151 	},
1152 	.delay = {
1153 		/* TODO: should be hpd-absent and no-hpd should be set? */
1154 		.hpd_reliable = 210,
1155 		.enable = 50,
1156 		.unprepare = 160,
1157 	},
1158 };
1159 
1160 static const struct drm_display_mode boe_nv110wtm_n61_modes[] = {
1161 	{
1162 		.clock = 207800,
1163 		.hdisplay = 2160,
1164 		.hsync_start = 2160 + 48,
1165 		.hsync_end = 2160 + 48 + 32,
1166 		.htotal = 2160 + 48 + 32 + 100,
1167 		.vdisplay = 1440,
1168 		.vsync_start = 1440 + 3,
1169 		.vsync_end = 1440 + 3 + 6,
1170 		.vtotal = 1440 + 3 + 6 + 31,
1171 		.flags = DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC,
1172 	},
1173 	{
1174 		.clock = 138500,
1175 		.hdisplay = 2160,
1176 		.hsync_start = 2160 + 48,
1177 		.hsync_end = 2160 + 48 + 32,
1178 		.htotal = 2160 + 48 + 32 + 100,
1179 		.vdisplay = 1440,
1180 		.vsync_start = 1440 + 3,
1181 		.vsync_end = 1440 + 3 + 6,
1182 		.vtotal = 1440 + 3 + 6 + 31,
1183 		.flags = DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC,
1184 	},
1185 };
1186 
1187 static const struct panel_desc boe_nv110wtm_n61 = {
1188 	.modes = boe_nv110wtm_n61_modes,
1189 	.num_modes = ARRAY_SIZE(boe_nv110wtm_n61_modes),
1190 	.bpc = 8,
1191 	.size = {
1192 		.width = 233,
1193 		.height = 155,
1194 	},
1195 	.delay = {
1196 		.hpd_absent = 200,
1197 		.prepare_to_enable = 80,
1198 		.enable = 50,
1199 		.unprepare = 500,
1200 	},
1201 };
1202 
1203 /* Also used for boe_nv133fhm_n62 */
1204 static const struct drm_display_mode boe_nv133fhm_n61_modes = {
1205 	.clock = 147840,
1206 	.hdisplay = 1920,
1207 	.hsync_start = 1920 + 48,
1208 	.hsync_end = 1920 + 48 + 32,
1209 	.htotal = 1920 + 48 + 32 + 200,
1210 	.vdisplay = 1080,
1211 	.vsync_start = 1080 + 3,
1212 	.vsync_end = 1080 + 3 + 6,
1213 	.vtotal = 1080 + 3 + 6 + 31,
1214 	.flags = DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC,
1215 };
1216 
1217 /* Also used for boe_nv133fhm_n62 */
1218 static const struct panel_desc boe_nv133fhm_n61 = {
1219 	.modes = &boe_nv133fhm_n61_modes,
1220 	.num_modes = 1,
1221 	.bpc = 6,
1222 	.size = {
1223 		.width = 294,
1224 		.height = 165,
1225 	},
1226 	.delay = {
1227 		/*
1228 		 * When power is first given to the panel there's a short
1229 		 * spike on the HPD line.  It was explained that this spike
1230 		 * was until the TCON data download was complete.  On
1231 		 * one system this was measured at 8 ms.  We'll put 15 ms
1232 		 * in the prepare delay just to be safe.  That means:
1233 		 * - If HPD isn't hooked up you still have 200 ms delay.
1234 		 * - If HPD is hooked up we won't try to look at it for the
1235 		 *   first 15 ms.
1236 		 */
1237 		.hpd_reliable = 15,
1238 		.hpd_absent = 200,
1239 
1240 		.unprepare = 500,
1241 	},
1242 };
1243 
1244 static const struct drm_display_mode boe_nv140fhmn49_modes[] = {
1245 	{
1246 		.clock = 148500,
1247 		.hdisplay = 1920,
1248 		.hsync_start = 1920 + 48,
1249 		.hsync_end = 1920 + 48 + 32,
1250 		.htotal = 2200,
1251 		.vdisplay = 1080,
1252 		.vsync_start = 1080 + 3,
1253 		.vsync_end = 1080 + 3 + 5,
1254 		.vtotal = 1125,
1255 	},
1256 };
1257 
1258 static const struct panel_desc boe_nv140fhmn49 = {
1259 	.modes = boe_nv140fhmn49_modes,
1260 	.num_modes = ARRAY_SIZE(boe_nv140fhmn49_modes),
1261 	.bpc = 6,
1262 	.size = {
1263 		.width = 309,
1264 		.height = 174,
1265 	},
1266 	.delay = {
1267 		/* TODO: should be hpd-absent and no-hpd should be set? */
1268 		.hpd_reliable = 210,
1269 		.enable = 50,
1270 		.unprepare = 160,
1271 	},
1272 };
1273 
1274 static const struct drm_display_mode innolux_n116bca_ea1_mode = {
1275 	.clock = 76420,
1276 	.hdisplay = 1366,
1277 	.hsync_start = 1366 + 136,
1278 	.hsync_end = 1366 + 136 + 30,
1279 	.htotal = 1366 + 136 + 30 + 60,
1280 	.vdisplay = 768,
1281 	.vsync_start = 768 + 8,
1282 	.vsync_end = 768 + 8 + 12,
1283 	.vtotal = 768 + 8 + 12 + 12,
1284 	.flags = DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC,
1285 };
1286 
1287 static const struct panel_desc innolux_n116bca_ea1 = {
1288 	.modes = &innolux_n116bca_ea1_mode,
1289 	.num_modes = 1,
1290 	.bpc = 6,
1291 	.size = {
1292 		.width = 256,
1293 		.height = 144,
1294 	},
1295 	.delay = {
1296 		.hpd_absent = 200,
1297 		.enable = 80,
1298 		.disable = 50,
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,b133han05",
1741 		.data = &auo_b133han05,
1742 	}, {
1743 		.compatible = "auo,b133htn01",
1744 		.data = &auo_b133htn01,
1745 	}, {
1746 		.compatible = "auo,b133xtn01",
1747 		.data = &auo_b133xtn01,
1748 	}, {
1749 		.compatible = "auo,b140han06",
1750 		.data = &auo_b140han06,
1751 	}, {
1752 		.compatible = "boe,nv101wxmn51",
1753 		.data = &boe_nv101wxmn51,
1754 	}, {
1755 		.compatible = "boe,nv110wtm-n61",
1756 		.data = &boe_nv110wtm_n61,
1757 	}, {
1758 		.compatible = "boe,nv133fhm-n61",
1759 		.data = &boe_nv133fhm_n61,
1760 	}, {
1761 		.compatible = "boe,nv133fhm-n62",
1762 		.data = &boe_nv133fhm_n61,
1763 	}, {
1764 		.compatible = "boe,nv140fhmn49",
1765 		.data = &boe_nv140fhmn49,
1766 	}, {
1767 		.compatible = "innolux,n116bca-ea1",
1768 		.data = &innolux_n116bca_ea1,
1769 	}, {
1770 		.compatible = "innolux,n116bge",
1771 		.data = &innolux_n116bge,
1772 	}, {
1773 		.compatible = "innolux,n125hce-gn1",
1774 		.data = &innolux_n125hce_gn1,
1775 	}, {
1776 		.compatible = "innolux,p120zdg-bf1",
1777 		.data = &innolux_p120zdg_bf1,
1778 	}, {
1779 		.compatible = "ivo,m133nwf4-r0",
1780 		.data = &ivo_m133nwf4_r0,
1781 	}, {
1782 		.compatible = "kingdisplay,kd116n21-30nv-a010",
1783 		.data = &kingdisplay_kd116n21_30nv_a010,
1784 	}, {
1785 		.compatible = "lg,lp079qx1-sp0v",
1786 		.data = &lg_lp079qx1_sp0v,
1787 	}, {
1788 		.compatible = "lg,lp097qx1-spa1",
1789 		.data = &lg_lp097qx1_spa1,
1790 	}, {
1791 		.compatible = "lg,lp120up1",
1792 		.data = &lg_lp120up1,
1793 	}, {
1794 		.compatible = "lg,lp129qe",
1795 		.data = &lg_lp129qe,
1796 	}, {
1797 		.compatible = "neweast,wjfh116008a",
1798 		.data = &neweast_wjfh116008a,
1799 	}, {
1800 		.compatible = "samsung,lsn122dl01-c01",
1801 		.data = &samsung_lsn122dl01_c01,
1802 	}, {
1803 		.compatible = "samsung,ltn140at29-301",
1804 		.data = &samsung_ltn140at29_301,
1805 	}, {
1806 		.compatible = "sharp,ld-d5116z01b",
1807 		.data = &sharp_ld_d5116z01b,
1808 	}, {
1809 		.compatible = "sharp,lq123p1jx31",
1810 		.data = &sharp_lq123p1jx31,
1811 	}, {
1812 		.compatible = "sharp,lq140m1jw46",
1813 		.data = &sharp_lq140m1jw46,
1814 	}, {
1815 		.compatible = "starry,kr122ea0sra",
1816 		.data = &starry_kr122ea0sra,
1817 	}, {
1818 		/* sentinel */
1819 	}
1820 };
1821 MODULE_DEVICE_TABLE(of, platform_of_match);
1822 
1823 static const struct panel_delay delay_200_500_p2e80 = {
1824 	.hpd_absent = 200,
1825 	.unprepare = 500,
1826 	.prepare_to_enable = 80,
1827 };
1828 
1829 static const struct panel_delay delay_200_500_p2e100 = {
1830 	.hpd_absent = 200,
1831 	.unprepare = 500,
1832 	.prepare_to_enable = 100,
1833 };
1834 
1835 static const struct panel_delay delay_200_500_e50 = {
1836 	.hpd_absent = 200,
1837 	.unprepare = 500,
1838 	.enable = 50,
1839 };
1840 
1841 static const struct panel_delay delay_200_500_e80_d50 = {
1842 	.hpd_absent = 200,
1843 	.unprepare = 500,
1844 	.enable = 80,
1845 	.disable = 50,
1846 };
1847 
1848 static const struct panel_delay delay_100_500_e200 = {
1849 	.hpd_absent = 100,
1850 	.unprepare = 500,
1851 	.enable = 200,
1852 };
1853 
1854 static const struct panel_delay delay_200_500_e200 = {
1855 	.hpd_absent = 200,
1856 	.unprepare = 500,
1857 	.enable = 200,
1858 };
1859 
1860 #define EDP_PANEL_ENTRY(vend_chr_0, vend_chr_1, vend_chr_2, product_id, _delay, _name) \
1861 { \
1862 	.name = _name, \
1863 	.panel_id = drm_edid_encode_panel_id(vend_chr_0, vend_chr_1, vend_chr_2, \
1864 					     product_id), \
1865 	.delay = _delay \
1866 }
1867 
1868 #define EDP_PANEL_ENTRY2(vend_chr_0, vend_chr_1, vend_chr_2, product_id, _delay, _name, _mode) \
1869 { \
1870 	.name = _name, \
1871 	.panel_id = drm_edid_encode_panel_id(vend_chr_0, vend_chr_1, vend_chr_2, \
1872 					     product_id), \
1873 	.delay = _delay, \
1874 	.override_edid_mode = _mode \
1875 }
1876 
1877 /*
1878  * This table is used to figure out power sequencing delays for panels that
1879  * are detected by EDID. Entries here may point to entries in the
1880  * platform_of_match table (if a panel is listed in both places).
1881  *
1882  * Sort first by vendor, then by product ID.
1883  */
1884 static const struct edp_panel_entry edp_panels[] = {
1885 	EDP_PANEL_ENTRY('A', 'U', 'O', 0x1062, &delay_200_500_e50, "B120XAN01.0"),
1886 	EDP_PANEL_ENTRY('A', 'U', 'O', 0x145c, &delay_200_500_e50, "B116XAB01.4"),
1887 	EDP_PANEL_ENTRY('A', 'U', 'O', 0x1e9b, &delay_200_500_e50, "B133UAN02.1"),
1888 	EDP_PANEL_ENTRY('A', 'U', 'O', 0x1ea5, &delay_200_500_e50, "B116XAK01.6"),
1889 	EDP_PANEL_ENTRY('A', 'U', 'O', 0x235c, &delay_200_500_e50, "B116XTN02.3"),
1890 	EDP_PANEL_ENTRY('A', 'U', 'O', 0x405c, &auo_b116xak01.delay, "B116XAK01.0"),
1891 	EDP_PANEL_ENTRY('A', 'U', 'O', 0x582d, &delay_200_500_e50, "B133UAN01.0"),
1892 	EDP_PANEL_ENTRY('A', 'U', 'O', 0x615c, &delay_200_500_e50, "B116XAN06.1"),
1893 	EDP_PANEL_ENTRY('A', 'U', 'O', 0x8594, &delay_200_500_e50, "B133UAN01.0"),
1894 
1895 	EDP_PANEL_ENTRY('B', 'O', 'E', 0x0786, &delay_200_500_p2e80, "NV116WHM-T01"),
1896 	EDP_PANEL_ENTRY('B', 'O', 'E', 0x07d1, &boe_nv133fhm_n61.delay, "NV133FHM-N61"),
1897 	EDP_PANEL_ENTRY('B', 'O', 'E', 0x082d, &boe_nv133fhm_n61.delay, "NV133FHM-N62"),
1898 	EDP_PANEL_ENTRY('B', 'O', 'E', 0x09c3, &delay_200_500_e50, "NT116WHM-N21,836X2"),
1899 	EDP_PANEL_ENTRY('B', 'O', 'E', 0x094b, &delay_200_500_e50, "NT116WHM-N21"),
1900 	EDP_PANEL_ENTRY('B', 'O', 'E', 0x095f, &delay_200_500_e50, "NE135FBM-N41 v8.1"),
1901 	EDP_PANEL_ENTRY('B', 'O', 'E', 0x0979, &delay_200_500_e50, "NV116WHM-N49 V8.0"),
1902 	EDP_PANEL_ENTRY('B', 'O', 'E', 0x098d, &boe_nv110wtm_n61.delay, "NV110WTM-N61"),
1903 	EDP_PANEL_ENTRY('B', 'O', 'E', 0x09dd, &delay_200_500_e50, "NT116WHM-N21"),
1904 	EDP_PANEL_ENTRY('B', 'O', 'E', 0x0a5d, &delay_200_500_e50, "NV116WHM-N45"),
1905 	EDP_PANEL_ENTRY('B', 'O', 'E', 0x0ac5, &delay_200_500_e50, "NV116WHM-N4C"),
1906 
1907 	EDP_PANEL_ENTRY('C', 'M', 'N', 0x1139, &delay_200_500_e80_d50, "N116BGE-EA2"),
1908 	EDP_PANEL_ENTRY('C', 'M', 'N', 0x114c, &innolux_n116bca_ea1.delay, "N116BCA-EA1"),
1909 	EDP_PANEL_ENTRY('C', 'M', 'N', 0x1152, &delay_200_500_e80_d50, "N116BCN-EA1"),
1910 	EDP_PANEL_ENTRY('C', 'M', 'N', 0x1153, &delay_200_500_e80_d50, "N116BGE-EA2"),
1911 	EDP_PANEL_ENTRY('C', 'M', 'N', 0x1154, &delay_200_500_e80_d50, "N116BCA-EA2"),
1912 	EDP_PANEL_ENTRY('C', 'M', 'N', 0x1247, &delay_200_500_e80_d50, "N120ACA-EA1"),
1913 	EDP_PANEL_ENTRY('C', 'M', 'N', 0x14d4, &delay_200_500_e80_d50, "N140HCA-EAC"),
1914 
1915 	EDP_PANEL_ENTRY('I', 'V', 'O', 0x057d, &delay_200_500_e200, "R140NWF5 RH"),
1916 	EDP_PANEL_ENTRY('I', 'V', 'O', 0x854a, &delay_200_500_p2e100, "M133NW4J"),
1917 	EDP_PANEL_ENTRY('I', 'V', 'O', 0x854b, &delay_200_500_p2e100, "R133NW4K-R0"),
1918 
1919 	EDP_PANEL_ENTRY('K', 'D', 'B', 0x0624, &kingdisplay_kd116n21_30nv_a010.delay, "116N21-30NV-A010"),
1920 	EDP_PANEL_ENTRY('K', 'D', 'B', 0x1120, &delay_200_500_e80_d50, "116N29-30NK-C007"),
1921 
1922 	EDP_PANEL_ENTRY('S', 'H', 'P', 0x1511, &delay_200_500_e50, "LQ140M1JW48"),
1923 	EDP_PANEL_ENTRY('S', 'H', 'P', 0x1523, &sharp_lq140m1jw46.delay, "LQ140M1JW46"),
1924 	EDP_PANEL_ENTRY('S', 'H', 'P', 0x154c, &delay_200_500_p2e100, "LQ116M1JW10"),
1925 
1926 	EDP_PANEL_ENTRY('S', 'T', 'A', 0x0100, &delay_100_500_e200, "2081116HHD028001-51D"),
1927 
1928 	{ /* sentinal */ }
1929 };
1930 
find_edp_panel(u32 panel_id)1931 static const struct edp_panel_entry *find_edp_panel(u32 panel_id)
1932 {
1933 	const struct edp_panel_entry *panel;
1934 
1935 	if (!panel_id)
1936 		return NULL;
1937 
1938 	for (panel = edp_panels; panel->panel_id; panel++)
1939 		if (panel->panel_id == panel_id)
1940 			return panel;
1941 
1942 	return NULL;
1943 }
1944 
panel_edp_platform_probe(struct platform_device * pdev)1945 static int panel_edp_platform_probe(struct platform_device *pdev)
1946 {
1947 	const struct of_device_id *id;
1948 
1949 	/* Skip one since "edp-panel" is only supported on DP AUX bus */
1950 	id = of_match_node(platform_of_match + 1, pdev->dev.of_node);
1951 	if (!id)
1952 		return -ENODEV;
1953 
1954 	return panel_edp_probe(&pdev->dev, id->data, NULL);
1955 }
1956 
panel_edp_platform_remove(struct platform_device * pdev)1957 static void panel_edp_platform_remove(struct platform_device *pdev)
1958 {
1959 	panel_edp_remove(&pdev->dev);
1960 }
1961 
panel_edp_platform_shutdown(struct platform_device * pdev)1962 static void panel_edp_platform_shutdown(struct platform_device *pdev)
1963 {
1964 	panel_edp_shutdown(&pdev->dev);
1965 }
1966 
1967 static const struct dev_pm_ops panel_edp_pm_ops = {
1968 	SET_RUNTIME_PM_OPS(panel_edp_suspend, panel_edp_resume, NULL)
1969 	SET_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend,
1970 				pm_runtime_force_resume)
1971 };
1972 
1973 static struct platform_driver panel_edp_platform_driver = {
1974 	.driver = {
1975 		.name = "panel-edp",
1976 		.of_match_table = platform_of_match,
1977 		.pm = &panel_edp_pm_ops,
1978 	},
1979 	.probe = panel_edp_platform_probe,
1980 	.remove_new = panel_edp_platform_remove,
1981 	.shutdown = panel_edp_platform_shutdown,
1982 };
1983 
panel_edp_dp_aux_ep_probe(struct dp_aux_ep_device * aux_ep)1984 static int panel_edp_dp_aux_ep_probe(struct dp_aux_ep_device *aux_ep)
1985 {
1986 	const struct of_device_id *id;
1987 
1988 	id = of_match_node(platform_of_match, aux_ep->dev.of_node);
1989 	if (!id)
1990 		return -ENODEV;
1991 
1992 	return panel_edp_probe(&aux_ep->dev, id->data, aux_ep->aux);
1993 }
1994 
panel_edp_dp_aux_ep_remove(struct dp_aux_ep_device * aux_ep)1995 static void panel_edp_dp_aux_ep_remove(struct dp_aux_ep_device *aux_ep)
1996 {
1997 	panel_edp_remove(&aux_ep->dev);
1998 }
1999 
panel_edp_dp_aux_ep_shutdown(struct dp_aux_ep_device * aux_ep)2000 static void panel_edp_dp_aux_ep_shutdown(struct dp_aux_ep_device *aux_ep)
2001 {
2002 	panel_edp_shutdown(&aux_ep->dev);
2003 }
2004 
2005 static struct dp_aux_ep_driver panel_edp_dp_aux_ep_driver = {
2006 	.driver = {
2007 		.name = "panel-simple-dp-aux",
2008 		.of_match_table = platform_of_match,	/* Same as platform one! */
2009 		.pm = &panel_edp_pm_ops,
2010 	},
2011 	.probe = panel_edp_dp_aux_ep_probe,
2012 	.remove = panel_edp_dp_aux_ep_remove,
2013 	.shutdown = panel_edp_dp_aux_ep_shutdown,
2014 };
2015 
panel_edp_init(void)2016 static int __init panel_edp_init(void)
2017 {
2018 	int err;
2019 
2020 	err = platform_driver_register(&panel_edp_platform_driver);
2021 	if (err < 0)
2022 		return err;
2023 
2024 	err = dp_aux_dp_driver_register(&panel_edp_dp_aux_ep_driver);
2025 	if (err < 0)
2026 		goto err_did_platform_register;
2027 
2028 	return 0;
2029 
2030 err_did_platform_register:
2031 	platform_driver_unregister(&panel_edp_platform_driver);
2032 
2033 	return err;
2034 }
2035 module_init(panel_edp_init);
2036 
panel_edp_exit(void)2037 static void __exit panel_edp_exit(void)
2038 {
2039 	dp_aux_dp_driver_unregister(&panel_edp_dp_aux_ep_driver);
2040 	platform_driver_unregister(&panel_edp_platform_driver);
2041 }
2042 module_exit(panel_edp_exit);
2043 
2044 MODULE_AUTHOR("Thierry Reding <treding@nvidia.com>");
2045 MODULE_DESCRIPTION("DRM Driver for Simple eDP Panels");
2046 MODULE_LICENSE("GPL and additional rights");
2047