2 * Copyright (C) 2013, NVIDIA Corporation. All rights reserved.
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:
11 * The above copyright notice and this permission notice (including the
12 * next paragraph) shall be included in all copies or substantial portions
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.
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>
34 #include <video/display_timing.h>
35 #include <video/of_display_timing.h>
36 #include <video/videomode.h>
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>
46 * struct panel_delay - Describes delays for a simple panel.
50 * @hpd_reliable: Time for HPD to be reliable
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.
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.
61 unsigned int hpd_reliable;
64 * @hpd_absent: Time to wait if HPD isn't hooked up.
66 * Add this to the prepare delay if we know Hot Plug Detect isn't used.
68 * This is T3-max on eDP timing diagrams or the delay from power on
69 * until HPD is guaranteed to be asserted.
71 unsigned int hpd_absent;
74 * @powered_on_to_enable: Time between panel powered on and enable.
76 * The minimum time, in milliseconds, that needs to have passed
77 * between when panel powered on and enable may begin.
79 * This is (T3+T4+T5+T6+T8)-min on eDP timing diagrams or after the
80 * power supply enabled until we can turn the backlight on and see
83 * This doesn't normally need to be set if timings are already met by
84 * prepare_to_enable or enable.
86 unsigned int powered_on_to_enable;
89 * @prepare_to_enable: Time between prepare and enable.
91 * The minimum time, in milliseconds, that needs to have passed
92 * between when prepare finished and enable may begin. If at
93 * enable time less time has passed since prepare finished,
94 * the driver waits for the remaining time.
96 * If a fixed enable delay is also specified, we'll start
97 * counting before delaying for the fixed delay.
99 * If a fixed prepare delay is also specified, we won't start
100 * counting until after the fixed delay. We can't overlap this
101 * fixed delay with the min time because the fixed delay
102 * doesn't happen at the end of the function if a HPD GPIO was
108 * // do fixed prepare delay
109 * // wait for HPD GPIO if applicable
110 * // start counting for prepare_to_enable
113 * // do fixed enable delay
114 * // enforce prepare_to_enable min time
116 * This is not specified in a standard way on eDP timing diagrams.
117 * It is effectively the time from HPD going high till you can
118 * turn on the backlight.
120 unsigned int prepare_to_enable;
123 * @enable: Time for the panel to display a valid frame.
125 * The time (in milliseconds) that it takes for the panel to
126 * display the first valid frame after starting to receive
129 * This is (T6-min + max(T7-max, T8-min)) on eDP timing diagrams or
130 * the delay after link training finishes until we can turn the
131 * backlight on and see valid data.
136 * @disable: Time for the panel to turn the display off.
138 * The time (in milliseconds) that it takes for the panel to
139 * turn the display off (no content is visible).
141 * This is T9-min (delay from backlight off to end of valid video
142 * data) on eDP timing diagrams. It is not common to set.
144 unsigned int disable;
147 * @unprepare: Time to power down completely.
149 * The time (in milliseconds) that it takes for the panel
150 * to power itself down completely.
152 * This time is used to prevent a future "prepare" from
153 * starting until at least this many milliseconds has passed.
154 * If at prepare time less time has passed since unprepare
155 * finished, the driver waits for the remaining time.
157 * This is T12-min on eDP timing diagrams.
159 unsigned int unprepare;
163 * struct panel_desc - Describes a simple panel.
167 * @modes: Pointer to array of fixed modes appropriate for this panel.
169 * If only one mode then this can just be the address of the mode.
170 * NOTE: cannot be used with "timings" and also if this is specified
171 * then you cannot override the mode in the device tree.
173 const struct drm_display_mode *modes;
175 /** @num_modes: Number of elements in modes array. */
176 unsigned int num_modes;
179 * @timings: Pointer to array of display timings
181 * NOTE: cannot be used with "modes" and also these will be used to
182 * validate a device tree override if one is present.
184 const struct display_timing *timings;
186 /** @num_timings: Number of elements in timings array. */
187 unsigned int num_timings;
189 /** @bpc: Bits per color. */
192 /** @size: Structure containing the physical size of this panel. */
195 * @size.width: Width (in mm) of the active display area.
200 * @size.height: Height (in mm) of the active display area.
205 /** @delay: Structure containing various delay values for this panel. */
206 struct panel_delay delay;
210 * struct edp_panel_entry - Maps panel ID to delay / panel name.
212 struct edp_panel_entry {
213 /** @ident: edid identity used for panel matching. */
214 const struct drm_edid_ident ident;
216 /** @delay: The power sequencing delays needed for this panel. */
217 const struct panel_delay *delay;
219 /** @override_edid_mode: Override the mode obtained by edid. */
220 const struct drm_display_mode *override_edid_mode;
224 struct drm_panel base;
227 ktime_t prepared_time;
228 ktime_t powered_on_time;
229 ktime_t unprepared_time;
231 const struct panel_desc *desc;
233 struct regulator *supply;
234 struct i2c_adapter *ddc;
235 struct drm_dp_aux *aux;
237 struct gpio_desc *enable_gpio;
238 struct gpio_desc *hpd_gpio;
240 const struct edp_panel_entry *detected_panel;
242 const struct drm_edid *drm_edid;
244 struct drm_display_mode override_mode;
246 enum drm_panel_orientation orientation;
249 static inline struct panel_edp *to_panel_edp(struct drm_panel *panel)
251 return container_of(panel, struct panel_edp, base);
254 static unsigned int panel_edp_get_timings_modes(struct panel_edp *panel,
255 struct drm_connector *connector)
257 struct drm_display_mode *mode;
258 unsigned int i, num = 0;
260 for (i = 0; i < panel->desc->num_timings; i++) {
261 const struct display_timing *dt = &panel->desc->timings[i];
264 videomode_from_timing(dt, &vm);
265 mode = drm_mode_create(connector->dev);
267 dev_err(panel->base.dev, "failed to add mode %ux%u\n",
268 dt->hactive.typ, dt->vactive.typ);
272 drm_display_mode_from_videomode(&vm, mode);
274 mode->type |= DRM_MODE_TYPE_DRIVER;
276 if (panel->desc->num_timings == 1)
277 mode->type |= DRM_MODE_TYPE_PREFERRED;
279 drm_mode_probed_add(connector, mode);
286 static unsigned int panel_edp_get_display_modes(struct panel_edp *panel,
287 struct drm_connector *connector)
289 struct drm_display_mode *mode;
290 unsigned int i, num = 0;
292 for (i = 0; i < panel->desc->num_modes; i++) {
293 const struct drm_display_mode *m = &panel->desc->modes[i];
295 mode = drm_mode_duplicate(connector->dev, m);
297 dev_err(panel->base.dev, "failed to add mode %ux%u@%u\n",
298 m->hdisplay, m->vdisplay,
299 drm_mode_vrefresh(m));
303 mode->type |= DRM_MODE_TYPE_DRIVER;
305 if (panel->desc->num_modes == 1)
306 mode->type |= DRM_MODE_TYPE_PREFERRED;
308 drm_mode_set_name(mode);
310 drm_mode_probed_add(connector, mode);
317 static int panel_edp_override_edid_mode(struct panel_edp *panel,
318 struct drm_connector *connector,
319 const struct drm_display_mode *override_mode)
321 struct drm_display_mode *mode;
323 mode = drm_mode_duplicate(connector->dev, override_mode);
325 dev_err(panel->base.dev, "failed to add additional mode\n");
329 mode->type |= DRM_MODE_TYPE_DRIVER | DRM_MODE_TYPE_PREFERRED;
330 drm_mode_set_name(mode);
331 drm_mode_probed_add(connector, mode);
335 static int panel_edp_get_non_edid_modes(struct panel_edp *panel,
336 struct drm_connector *connector)
338 struct drm_display_mode *mode;
339 bool has_override = panel->override_mode.type;
340 unsigned int num = 0;
346 mode = drm_mode_duplicate(connector->dev,
347 &panel->override_mode);
349 drm_mode_probed_add(connector, mode);
352 dev_err(panel->base.dev, "failed to add override mode\n");
356 /* Only add timings if override was not there or failed to validate */
357 if (num == 0 && panel->desc->num_timings)
358 num = panel_edp_get_timings_modes(panel, connector);
361 * Only add fixed modes if timings/override added no mode.
363 * We should only ever have either the display timings specified
364 * or a fixed mode. Anything else is rather bogus.
366 WARN_ON(panel->desc->num_timings && panel->desc->num_modes);
368 num = panel_edp_get_display_modes(panel, connector);
370 connector->display_info.bpc = panel->desc->bpc;
371 connector->display_info.width_mm = panel->desc->size.width;
372 connector->display_info.height_mm = panel->desc->size.height;
377 static void panel_edp_wait(ktime_t start_ktime, unsigned int min_ms)
379 ktime_t now_ktime, min_ktime;
384 min_ktime = ktime_add(start_ktime, ms_to_ktime(min_ms));
385 now_ktime = ktime_get_boottime();
387 if (ktime_before(now_ktime, min_ktime))
388 msleep(ktime_to_ms(ktime_sub(min_ktime, now_ktime)) + 1);
391 static int panel_edp_disable(struct drm_panel *panel)
393 struct panel_edp *p = to_panel_edp(panel);
395 if (p->desc->delay.disable)
396 msleep(p->desc->delay.disable);
401 static int panel_edp_suspend(struct device *dev)
403 struct panel_edp *p = dev_get_drvdata(dev);
405 drm_dp_dpcd_set_powered(p->aux, false);
406 gpiod_set_value_cansleep(p->enable_gpio, 0);
407 regulator_disable(p->supply);
408 p->unprepared_time = ktime_get_boottime();
413 static int panel_edp_unprepare(struct drm_panel *panel)
417 ret = pm_runtime_put_sync_suspend(panel->dev);
424 static int panel_edp_get_hpd_gpio(struct device *dev, struct panel_edp *p)
426 p->hpd_gpio = devm_gpiod_get_optional(dev, "hpd", GPIOD_IN);
427 if (IS_ERR(p->hpd_gpio))
428 return dev_err_probe(dev, PTR_ERR(p->hpd_gpio),
429 "failed to get 'hpd' GPIO\n");
434 static bool panel_edp_can_read_hpd(struct panel_edp *p)
436 return !p->no_hpd && (p->hpd_gpio || (p->aux && p->aux->wait_hpd_asserted));
439 static int panel_edp_prepare_once(struct panel_edp *p)
441 struct device *dev = p->base.dev;
445 unsigned long hpd_wait_us;
447 panel_edp_wait(p->unprepared_time, p->desc->delay.unprepare);
449 err = regulator_enable(p->supply);
451 dev_err(dev, "failed to enable supply: %d\n", err);
455 gpiod_set_value_cansleep(p->enable_gpio, 1);
456 drm_dp_dpcd_set_powered(p->aux, true);
458 p->powered_on_time = ktime_get_boottime();
460 delay = p->desc->delay.hpd_reliable;
462 delay = max(delay, p->desc->delay.hpd_absent);
466 if (panel_edp_can_read_hpd(p)) {
467 if (p->desc->delay.hpd_absent)
468 hpd_wait_us = p->desc->delay.hpd_absent * 1000UL;
470 hpd_wait_us = 2000000;
473 err = readx_poll_timeout(gpiod_get_value_cansleep,
474 p->hpd_gpio, hpd_asserted,
475 hpd_asserted, 1000, hpd_wait_us);
476 if (hpd_asserted < 0)
479 err = p->aux->wait_hpd_asserted(p->aux, hpd_wait_us);
483 if (err != -ETIMEDOUT)
485 "error waiting for hpd GPIO: %d\n", err);
490 p->prepared_time = ktime_get_boottime();
495 drm_dp_dpcd_set_powered(p->aux, false);
496 gpiod_set_value_cansleep(p->enable_gpio, 0);
497 regulator_disable(p->supply);
498 p->unprepared_time = ktime_get_boottime();
504 * Some panels simply don't always come up and need to be power cycled to
505 * work properly. We'll allow for a handful of retries.
507 #define MAX_PANEL_PREPARE_TRIES 5
509 static int panel_edp_resume(struct device *dev)
511 struct panel_edp *p = dev_get_drvdata(dev);
515 for (try = 0; try < MAX_PANEL_PREPARE_TRIES; try++) {
516 ret = panel_edp_prepare_once(p);
517 if (ret != -ETIMEDOUT)
521 if (ret == -ETIMEDOUT)
522 dev_err(dev, "Prepare timeout after %d tries\n", try);
524 dev_warn(dev, "Prepare needed %d retries\n", try);
529 static int panel_edp_prepare(struct drm_panel *panel)
533 ret = pm_runtime_get_sync(panel->dev);
535 pm_runtime_put_autosuspend(panel->dev);
542 static int panel_edp_enable(struct drm_panel *panel)
544 struct panel_edp *p = to_panel_edp(panel);
547 delay = p->desc->delay.enable;
550 * If there is a "prepare_to_enable" delay then that's supposed to be
551 * the delay from HPD going high until we can turn the backlight on.
552 * However, we can only count this if HPD is readable by the panel
555 * If we aren't handling the HPD pin ourselves then the best we
556 * can do is assume that HPD went high immediately before we were
557 * called (and link training took zero time). Note that "no-hpd"
558 * actually counts as handling HPD ourselves since we're doing the
559 * worst case delay (in prepare) ourselves.
561 * NOTE: if we ever end up in this "if" statement then we're
562 * guaranteed that the panel_edp_wait() call below will do no delay.
563 * It already handles that case, though, so we don't need any special
566 if (p->desc->delay.prepare_to_enable &&
567 !panel_edp_can_read_hpd(p) && !p->no_hpd)
568 delay = max(delay, p->desc->delay.prepare_to_enable);
573 panel_edp_wait(p->prepared_time, p->desc->delay.prepare_to_enable);
575 panel_edp_wait(p->powered_on_time, p->desc->delay.powered_on_to_enable);
580 static int panel_edp_get_modes(struct drm_panel *panel,
581 struct drm_connector *connector)
583 struct panel_edp *p = to_panel_edp(panel);
585 bool has_hard_coded_modes = p->desc->num_timings || p->desc->num_modes;
586 bool has_override_edid_mode = p->detected_panel &&
587 p->detected_panel != ERR_PTR(-EINVAL) &&
588 p->detected_panel->override_edid_mode;
590 /* probe EDID if a DDC bus is available */
592 pm_runtime_get_sync(panel->dev);
595 p->drm_edid = drm_edid_read_ddc(connector, p->ddc);
597 drm_edid_connector_update(connector, p->drm_edid);
600 * If both edid and hard-coded modes exists, skip edid modes to
601 * avoid multiple preferred modes.
603 if (p->drm_edid && !has_hard_coded_modes) {
604 if (has_override_edid_mode) {
606 * override_edid_mode is specified. Use
607 * override_edid_mode instead of from edid.
609 num += panel_edp_override_edid_mode(p, connector,
610 p->detected_panel->override_edid_mode);
612 num += drm_edid_connector_add_modes(connector);
616 pm_runtime_mark_last_busy(panel->dev);
617 pm_runtime_put_autosuspend(panel->dev);
620 if (has_hard_coded_modes)
621 num += panel_edp_get_non_edid_modes(p, connector);
623 dev_warn(p->base.dev, "No display modes\n");
626 * TODO: Remove once all drm drivers call
627 * drm_connector_set_orientation_from_panel()
629 drm_connector_set_panel_orientation(connector, p->orientation);
634 static int panel_edp_get_timings(struct drm_panel *panel,
635 unsigned int num_timings,
636 struct display_timing *timings)
638 struct panel_edp *p = to_panel_edp(panel);
641 if (p->desc->num_timings < num_timings)
642 num_timings = p->desc->num_timings;
645 for (i = 0; i < num_timings; i++)
646 timings[i] = p->desc->timings[i];
648 return p->desc->num_timings;
651 static enum drm_panel_orientation panel_edp_get_orientation(struct drm_panel *panel)
653 struct panel_edp *p = to_panel_edp(panel);
655 return p->orientation;
658 static int detected_panel_show(struct seq_file *s, void *data)
660 struct drm_panel *panel = s->private;
661 struct panel_edp *p = to_panel_edp(panel);
663 if (IS_ERR(p->detected_panel))
664 seq_puts(s, "UNKNOWN\n");
665 else if (!p->detected_panel)
666 seq_puts(s, "HARDCODED\n");
668 seq_printf(s, "%s\n", p->detected_panel->ident.name);
673 DEFINE_SHOW_ATTRIBUTE(detected_panel);
675 static void panel_edp_debugfs_init(struct drm_panel *panel, struct dentry *root)
677 debugfs_create_file("detected_panel", 0600, root, panel, &detected_panel_fops);
680 static const struct drm_panel_funcs panel_edp_funcs = {
681 .disable = panel_edp_disable,
682 .unprepare = panel_edp_unprepare,
683 .prepare = panel_edp_prepare,
684 .enable = panel_edp_enable,
685 .get_modes = panel_edp_get_modes,
686 .get_orientation = panel_edp_get_orientation,
687 .get_timings = panel_edp_get_timings,
688 .debugfs_init = panel_edp_debugfs_init,
691 #define PANEL_EDP_BOUNDS_CHECK(to_check, bounds, field) \
692 (to_check->field.typ >= bounds->field.min && \
693 to_check->field.typ <= bounds->field.max)
694 static void panel_edp_parse_panel_timing_node(struct device *dev,
695 struct panel_edp *panel,
696 const struct display_timing *ot)
698 const struct panel_desc *desc = panel->desc;
702 if (WARN_ON(desc->num_modes)) {
703 dev_err(dev, "Reject override mode: panel has a fixed mode\n");
706 if (WARN_ON(!desc->num_timings)) {
707 dev_err(dev, "Reject override mode: no timings specified\n");
711 for (i = 0; i < panel->desc->num_timings; i++) {
712 const struct display_timing *dt = &panel->desc->timings[i];
714 if (!PANEL_EDP_BOUNDS_CHECK(ot, dt, hactive) ||
715 !PANEL_EDP_BOUNDS_CHECK(ot, dt, hfront_porch) ||
716 !PANEL_EDP_BOUNDS_CHECK(ot, dt, hback_porch) ||
717 !PANEL_EDP_BOUNDS_CHECK(ot, dt, hsync_len) ||
718 !PANEL_EDP_BOUNDS_CHECK(ot, dt, vactive) ||
719 !PANEL_EDP_BOUNDS_CHECK(ot, dt, vfront_porch) ||
720 !PANEL_EDP_BOUNDS_CHECK(ot, dt, vback_porch) ||
721 !PANEL_EDP_BOUNDS_CHECK(ot, dt, vsync_len))
724 if (ot->flags != dt->flags)
727 videomode_from_timing(ot, &vm);
728 drm_display_mode_from_videomode(&vm, &panel->override_mode);
729 panel->override_mode.type |= DRM_MODE_TYPE_DRIVER |
730 DRM_MODE_TYPE_PREFERRED;
734 if (WARN_ON(!panel->override_mode.type))
735 dev_err(dev, "Reject override mode: No display_timing found\n");
738 static const struct edp_panel_entry *find_edp_panel(u32 panel_id, const struct drm_edid *edid);
740 static void panel_edp_set_conservative_timings(struct panel_edp *panel, struct panel_desc *desc)
743 * It's highly likely that the panel will work if we use very
744 * conservative timings, so let's do that.
746 * Nearly all panels have a "unprepare" delay of 500 ms though
747 * there are a few with 1000. Let's stick 2000 in just to be
748 * super conservative.
750 * An "enable" delay of 80 ms seems the most common, but we'll
751 * throw in 200 ms to be safe.
753 desc->delay.unprepare = 2000;
754 desc->delay.enable = 200;
756 panel->detected_panel = ERR_PTR(-EINVAL);
759 static int generic_edp_panel_probe(struct device *dev, struct panel_edp *panel)
761 struct panel_desc *desc;
762 const struct drm_edid *base_block;
770 desc = devm_kzalloc(dev, sizeof(*desc), GFP_KERNEL);
776 * Read the dts properties for the initial probe. These are used by
777 * the runtime resume code which will get called by the
778 * pm_runtime_get_sync() call below.
780 of_property_read_u32(dev->of_node, "hpd-reliable-delay-ms", &reliable_ms);
781 desc->delay.hpd_reliable = reliable_ms;
782 of_property_read_u32(dev->of_node, "hpd-absent-delay-ms", &absent_ms);
783 desc->delay.hpd_absent = absent_ms;
785 /* Power the panel on so we can read the EDID */
786 ret = pm_runtime_get_sync(dev);
789 "Couldn't power on panel to ID it; using conservative timings: %d\n",
791 panel_edp_set_conservative_timings(panel, desc);
795 base_block = drm_edid_read_base_block(panel->ddc);
797 panel_id = drm_edid_get_panel_id(base_block);
799 dev_err(dev, "Couldn't read EDID for ID; using conservative timings\n");
800 panel_edp_set_conservative_timings(panel, desc);
803 drm_edid_decode_panel_id(panel_id, vend, &product_id);
805 panel->detected_panel = find_edp_panel(panel_id, base_block);
807 drm_edid_free(base_block);
810 * We're using non-optimized timings and want it really obvious that
811 * someone needs to add an entry to the table, so we'll do a WARN_ON
814 if (WARN_ON(!panel->detected_panel)) {
816 "Unknown panel %s %#06x, using conservative timings\n",
818 panel_edp_set_conservative_timings(panel, desc);
820 dev_info(dev, "Detected %s %s (%#06x)\n",
821 vend, panel->detected_panel->ident.name, product_id);
823 /* Update the delay; everything else comes from EDID */
824 desc->delay = *panel->detected_panel->delay;
828 pm_runtime_mark_last_busy(dev);
829 pm_runtime_put_autosuspend(dev);
834 static int panel_edp_probe(struct device *dev, const struct panel_desc *desc,
835 struct drm_dp_aux *aux)
837 struct panel_edp *panel;
838 struct display_timing dt;
839 struct device_node *ddc;
842 panel = devm_kzalloc(dev, sizeof(*panel), GFP_KERNEL);
846 panel->prepared_time = 0;
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);
857 panel->supply = devm_regulator_get(dev, "power");
858 if (IS_ERR(panel->supply))
859 return PTR_ERR(panel->supply);
861 panel->enable_gpio = devm_gpiod_get_optional(dev, "enable",
863 if (IS_ERR(panel->enable_gpio))
864 return dev_err_probe(dev, PTR_ERR(panel->enable_gpio),
865 "failed to request GPIO\n");
867 err = of_drm_get_panel_orientation(dev->of_node, &panel->orientation);
869 dev_err(dev, "%pOF: failed to get orientation %d\n", dev->of_node, err);
873 ddc = of_parse_phandle(dev->of_node, "ddc-i2c-bus", 0);
875 panel->ddc = of_find_i2c_adapter_by_node(ddc);
879 return -EPROBE_DEFER;
881 panel->ddc = &aux->ddc;
884 if (!of_get_display_timing(dev->of_node, "panel-timing", &dt))
885 panel_edp_parse_panel_timing_node(dev, panel, &dt);
887 dev_set_drvdata(dev, panel);
889 drm_panel_init(&panel->base, dev, &panel_edp_funcs, DRM_MODE_CONNECTOR_eDP);
891 err = drm_panel_of_backlight(&panel->base);
893 goto err_finished_ddc_init;
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.
901 pm_runtime_enable(dev);
902 pm_runtime_set_autosuspend_delay(dev, 1000);
903 pm_runtime_use_autosuspend(dev);
905 if (of_device_is_compatible(dev->of_node, "edp-panel")) {
906 err = generic_edp_panel_probe(dev, panel);
908 dev_err_probe(dev, err,
909 "Couldn't detect panel nor find a fallback\n");
910 goto err_finished_pm_runtime;
912 /* generic_edp_panel_probe() replaces desc in the panel */
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);
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);
925 * Warn if we get an error, but don't consider it fatal. Having
926 * a panel where we can't control the backlight is better than
930 dev_warn(dev, "failed to register dp aux backlight: %d\n", err);
933 drm_panel_add(&panel->base);
937 err_finished_pm_runtime:
938 pm_runtime_dont_use_autosuspend(dev);
939 pm_runtime_disable(dev);
940 err_finished_ddc_init:
941 if (panel->ddc && (!panel->aux || panel->ddc != &panel->aux->ddc))
942 put_device(&panel->ddc->dev);
947 static void panel_edp_shutdown(struct device *dev)
949 struct panel_edp *panel = dev_get_drvdata(dev);
952 * NOTE: the following two calls don't really belong here. It is the
953 * responsibility of a correctly written DRM modeset driver to call
954 * drm_atomic_helper_shutdown() at shutdown time and that should
955 * cause the panel to be disabled / unprepared if needed. For now,
956 * however, we'll keep these calls due to the sheer number of
957 * different DRM modeset drivers used with panel-edp. The fact that
958 * we're calling these and _also_ the drm_atomic_helper_shutdown()
959 * will try to disable/unprepare means that we can get a warning about
960 * trying to disable/unprepare an already disabled/unprepared panel,
961 * but that's something we'll have to live with until we've confirmed
962 * that all DRM modeset drivers are properly calling
963 * drm_atomic_helper_shutdown().
965 drm_panel_disable(&panel->base);
966 drm_panel_unprepare(&panel->base);
969 static void panel_edp_remove(struct device *dev)
971 struct panel_edp *panel = dev_get_drvdata(dev);
973 drm_panel_remove(&panel->base);
974 panel_edp_shutdown(dev);
976 pm_runtime_dont_use_autosuspend(dev);
977 pm_runtime_disable(dev);
978 if (panel->ddc && (!panel->aux || panel->ddc != &panel->aux->ddc))
979 put_device(&panel->ddc->dev);
981 drm_edid_free(panel->drm_edid);
982 panel->drm_edid = NULL;
985 static const struct display_timing auo_b101ean01_timing = {
986 .pixelclock = { 65300000, 72500000, 75000000 },
987 .hactive = { 1280, 1280, 1280 },
988 .hfront_porch = { 18, 119, 119 },
989 .hback_porch = { 21, 21, 21 },
990 .hsync_len = { 32, 32, 32 },
991 .vactive = { 800, 800, 800 },
992 .vfront_porch = { 4, 4, 4 },
993 .vback_porch = { 8, 8, 8 },
994 .vsync_len = { 18, 20, 20 },
997 static const struct panel_desc auo_b101ean01 = {
998 .timings = &auo_b101ean01_timing,
1007 static const struct drm_display_mode auo_b116xa3_mode = {
1010 .hsync_start = 1366 + 40,
1011 .hsync_end = 1366 + 40 + 40,
1012 .htotal = 1366 + 40 + 40 + 32,
1014 .vsync_start = 768 + 10,
1015 .vsync_end = 768 + 10 + 12,
1016 .vtotal = 768 + 10 + 12 + 6,
1017 .flags = DRM_MODE_FLAG_NVSYNC | DRM_MODE_FLAG_NHSYNC,
1020 static const struct drm_display_mode auo_b116xak01_mode = {
1023 .hsync_start = 1366 + 48,
1024 .hsync_end = 1366 + 48 + 32,
1025 .htotal = 1366 + 48 + 32 + 10,
1027 .vsync_start = 768 + 4,
1028 .vsync_end = 768 + 4 + 6,
1029 .vtotal = 768 + 4 + 6 + 15,
1030 .flags = DRM_MODE_FLAG_NVSYNC | DRM_MODE_FLAG_NHSYNC,
1033 static const struct panel_desc auo_b116xak01 = {
1034 .modes = &auo_b116xak01_mode,
1048 static const struct drm_display_mode auo_b133htn01_mode = {
1051 .hsync_start = 1920 + 172,
1052 .hsync_end = 1920 + 172 + 80,
1053 .htotal = 1920 + 172 + 80 + 60,
1055 .vsync_start = 1080 + 25,
1056 .vsync_end = 1080 + 25 + 10,
1057 .vtotal = 1080 + 25 + 10 + 10,
1060 static const struct panel_desc auo_b133htn01 = {
1061 .modes = &auo_b133htn01_mode,
1069 .hpd_reliable = 105,
1075 static const struct drm_display_mode auo_b133xtn01_mode = {
1078 .hsync_start = 1366 + 48,
1079 .hsync_end = 1366 + 48 + 32,
1080 .htotal = 1366 + 48 + 32 + 20,
1082 .vsync_start = 768 + 3,
1083 .vsync_end = 768 + 3 + 6,
1084 .vtotal = 768 + 3 + 6 + 13,
1087 static const struct panel_desc auo_b133xtn01 = {
1088 .modes = &auo_b133xtn01_mode,
1097 static const struct drm_display_mode boe_nv101wxmn51_modes[] = {
1101 .hsync_start = 1280 + 48,
1102 .hsync_end = 1280 + 48 + 32,
1103 .htotal = 1280 + 48 + 32 + 80,
1105 .vsync_start = 800 + 3,
1106 .vsync_end = 800 + 3 + 5,
1107 .vtotal = 800 + 3 + 5 + 24,
1112 .hsync_start = 1280 + 48,
1113 .hsync_end = 1280 + 48 + 32,
1114 .htotal = 1280 + 48 + 32 + 80,
1116 .vsync_start = 800 + 3,
1117 .vsync_end = 800 + 3 + 5,
1118 .vtotal = 800 + 3 + 5 + 24,
1122 static const struct panel_desc boe_nv101wxmn51 = {
1123 .modes = boe_nv101wxmn51_modes,
1124 .num_modes = ARRAY_SIZE(boe_nv101wxmn51_modes),
1131 /* TODO: should be hpd-absent and no-hpd should be set? */
1132 .hpd_reliable = 210,
1138 static const struct drm_display_mode boe_nv110wtm_n61_modes[] = {
1142 .hsync_start = 2160 + 48,
1143 .hsync_end = 2160 + 48 + 32,
1144 .htotal = 2160 + 48 + 32 + 100,
1146 .vsync_start = 1440 + 3,
1147 .vsync_end = 1440 + 3 + 6,
1148 .vtotal = 1440 + 3 + 6 + 31,
1149 .flags = DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC,
1154 .hsync_start = 2160 + 48,
1155 .hsync_end = 2160 + 48 + 32,
1156 .htotal = 2160 + 48 + 32 + 100,
1158 .vsync_start = 1440 + 3,
1159 .vsync_end = 1440 + 3 + 6,
1160 .vtotal = 1440 + 3 + 6 + 31,
1161 .flags = DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC,
1165 static const struct panel_desc boe_nv110wtm_n61 = {
1166 .modes = boe_nv110wtm_n61_modes,
1167 .num_modes = ARRAY_SIZE(boe_nv110wtm_n61_modes),
1175 .prepare_to_enable = 80,
1181 /* Also used for boe_nv133fhm_n62 */
1182 static const struct drm_display_mode boe_nv133fhm_n61_modes = {
1185 .hsync_start = 1920 + 48,
1186 .hsync_end = 1920 + 48 + 32,
1187 .htotal = 1920 + 48 + 32 + 200,
1189 .vsync_start = 1080 + 3,
1190 .vsync_end = 1080 + 3 + 6,
1191 .vtotal = 1080 + 3 + 6 + 31,
1192 .flags = DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC,
1195 /* Also used for boe_nv133fhm_n62 */
1196 static const struct panel_desc boe_nv133fhm_n61 = {
1197 .modes = &boe_nv133fhm_n61_modes,
1206 * When power is first given to the panel there's a short
1207 * spike on the HPD line. It was explained that this spike
1208 * was until the TCON data download was complete. On
1209 * one system this was measured at 8 ms. We'll put 15 ms
1210 * in the prepare delay just to be safe. That means:
1211 * - If HPD isn't hooked up you still have 200 ms delay.
1212 * - If HPD is hooked up we won't try to look at it for the
1222 static const struct drm_display_mode boe_nv140fhmn49_modes[] = {
1226 .hsync_start = 1920 + 48,
1227 .hsync_end = 1920 + 48 + 32,
1230 .vsync_start = 1080 + 3,
1231 .vsync_end = 1080 + 3 + 5,
1236 static const struct panel_desc boe_nv140fhmn49 = {
1237 .modes = boe_nv140fhmn49_modes,
1238 .num_modes = ARRAY_SIZE(boe_nv140fhmn49_modes),
1245 /* TODO: should be hpd-absent and no-hpd should be set? */
1246 .hpd_reliable = 210,
1252 static const struct drm_display_mode innolux_n116bca_ea1_mode = {
1255 .hsync_start = 1366 + 136,
1256 .hsync_end = 1366 + 136 + 30,
1257 .htotal = 1366 + 136 + 30 + 60,
1259 .vsync_start = 768 + 8,
1260 .vsync_end = 768 + 8 + 12,
1261 .vtotal = 768 + 8 + 12 + 12,
1262 .flags = DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC,
1265 static const struct panel_desc innolux_n116bca_ea1 = {
1266 .modes = &innolux_n116bca_ea1_mode,
1282 * Datasheet specifies that at 60 Hz refresh rate:
1283 * - total horizontal time: { 1506, 1592, 1716 }
1284 * - total vertical time: { 788, 800, 868 }
1286 * ...but doesn't go into exactly how that should be split into a front
1287 * porch, back porch, or sync length. For now we'll leave a single setting
1288 * here which allows a bit of tweaking of the pixel clock at the expense of
1291 static const struct display_timing innolux_n116bge_timing = {
1292 .pixelclock = { 72600000, 76420000, 80240000 },
1293 .hactive = { 1366, 1366, 1366 },
1294 .hfront_porch = { 136, 136, 136 },
1295 .hback_porch = { 60, 60, 60 },
1296 .hsync_len = { 30, 30, 30 },
1297 .vactive = { 768, 768, 768 },
1298 .vfront_porch = { 8, 8, 8 },
1299 .vback_porch = { 12, 12, 12 },
1300 .vsync_len = { 12, 12, 12 },
1301 .flags = DISPLAY_FLAGS_VSYNC_LOW | DISPLAY_FLAGS_HSYNC_LOW,
1304 static const struct panel_desc innolux_n116bge = {
1305 .timings = &innolux_n116bge_timing,
1314 static const struct drm_display_mode innolux_n125hce_gn1_mode = {
1317 .hsync_start = 1920 + 40,
1318 .hsync_end = 1920 + 40 + 40,
1319 .htotal = 1920 + 40 + 40 + 80,
1321 .vsync_start = 1080 + 4,
1322 .vsync_end = 1080 + 4 + 4,
1323 .vtotal = 1080 + 4 + 4 + 24,
1326 static const struct panel_desc innolux_n125hce_gn1 = {
1327 .modes = &innolux_n125hce_gn1_mode,
1336 static const struct drm_display_mode innolux_p120zdg_bf1_mode = {
1339 .hsync_start = 2160 + 48,
1340 .hsync_end = 2160 + 48 + 32,
1341 .htotal = 2160 + 48 + 32 + 80,
1343 .vsync_start = 1440 + 3,
1344 .vsync_end = 1440 + 3 + 10,
1345 .vtotal = 1440 + 3 + 10 + 27,
1346 .flags = DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC,
1349 static const struct panel_desc innolux_p120zdg_bf1 = {
1350 .modes = &innolux_p120zdg_bf1_mode,
1363 static const struct drm_display_mode kingdisplay_kd116n21_30nv_a010_mode = {
1366 .hsync_start = 1366 + 40,
1367 .hsync_end = 1366 + 40 + 32,
1368 .htotal = 1366 + 40 + 32 + 62,
1370 .vsync_start = 768 + 5,
1371 .vsync_end = 768 + 5 + 5,
1372 .vtotal = 768 + 5 + 5 + 122,
1373 .flags = DRM_MODE_FLAG_NVSYNC | DRM_MODE_FLAG_NHSYNC,
1376 static const struct panel_desc kingdisplay_kd116n21_30nv_a010 = {
1377 .modes = &kingdisplay_kd116n21_30nv_a010_mode,
1389 static const struct drm_display_mode lg_lp079qx1_sp0v_mode = {
1392 .hsync_start = 1536 + 12,
1393 .hsync_end = 1536 + 12 + 16,
1394 .htotal = 1536 + 12 + 16 + 48,
1396 .vsync_start = 2048 + 8,
1397 .vsync_end = 2048 + 8 + 4,
1398 .vtotal = 2048 + 8 + 4 + 8,
1399 .flags = DRM_MODE_FLAG_NVSYNC | DRM_MODE_FLAG_NHSYNC,
1402 static const struct panel_desc lg_lp079qx1_sp0v = {
1403 .modes = &lg_lp079qx1_sp0v_mode,
1411 static const struct drm_display_mode lg_lp097qx1_spa1_mode = {
1414 .hsync_start = 2048 + 150,
1415 .hsync_end = 2048 + 150 + 5,
1416 .htotal = 2048 + 150 + 5 + 5,
1418 .vsync_start = 1536 + 3,
1419 .vsync_end = 1536 + 3 + 1,
1420 .vtotal = 1536 + 3 + 1 + 9,
1423 static const struct panel_desc lg_lp097qx1_spa1 = {
1424 .modes = &lg_lp097qx1_spa1_mode,
1432 static const struct drm_display_mode lg_lp120up1_mode = {
1435 .hsync_start = 1920 + 40,
1436 .hsync_end = 1920 + 40 + 40,
1437 .htotal = 1920 + 40 + 40 + 80,
1439 .vsync_start = 1280 + 4,
1440 .vsync_end = 1280 + 4 + 4,
1441 .vtotal = 1280 + 4 + 4 + 12,
1444 static const struct panel_desc lg_lp120up1 = {
1445 .modes = &lg_lp120up1_mode,
1454 static const struct drm_display_mode lg_lp129qe_mode = {
1457 .hsync_start = 2560 + 48,
1458 .hsync_end = 2560 + 48 + 32,
1459 .htotal = 2560 + 48 + 32 + 80,
1461 .vsync_start = 1700 + 3,
1462 .vsync_end = 1700 + 3 + 10,
1463 .vtotal = 1700 + 3 + 10 + 36,
1466 static const struct panel_desc lg_lp129qe = {
1467 .modes = &lg_lp129qe_mode,
1476 static const struct drm_display_mode neweast_wjfh116008a_modes[] = {
1480 .hsync_start = 1920 + 48,
1481 .hsync_end = 1920 + 48 + 32,
1482 .htotal = 1920 + 48 + 32 + 80,
1484 .vsync_start = 1080 + 3,
1485 .vsync_end = 1080 + 3 + 5,
1486 .vtotal = 1080 + 3 + 5 + 23,
1487 .flags = DRM_MODE_FLAG_NVSYNC | DRM_MODE_FLAG_NHSYNC,
1491 .hsync_start = 1920 + 48,
1492 .hsync_end = 1920 + 48 + 32,
1493 .htotal = 1920 + 48 + 32 + 80,
1495 .vsync_start = 1080 + 3,
1496 .vsync_end = 1080 + 3 + 5,
1497 .vtotal = 1080 + 3 + 5 + 23,
1498 .flags = DRM_MODE_FLAG_NVSYNC | DRM_MODE_FLAG_NHSYNC,
1502 static const struct panel_desc neweast_wjfh116008a = {
1503 .modes = neweast_wjfh116008a_modes,
1511 .hpd_reliable = 110,
1517 static const struct drm_display_mode samsung_lsn122dl01_c01_mode = {
1520 .hsync_start = 2560 + 48,
1521 .hsync_end = 2560 + 48 + 32,
1522 .htotal = 2560 + 48 + 32 + 80,
1524 .vsync_start = 1600 + 2,
1525 .vsync_end = 1600 + 2 + 5,
1526 .vtotal = 1600 + 2 + 5 + 57,
1529 static const struct panel_desc samsung_lsn122dl01_c01 = {
1530 .modes = &samsung_lsn122dl01_c01_mode,
1538 static const struct drm_display_mode samsung_ltn140at29_301_mode = {
1541 .hsync_start = 1366 + 64,
1542 .hsync_end = 1366 + 64 + 48,
1543 .htotal = 1366 + 64 + 48 + 128,
1545 .vsync_start = 768 + 2,
1546 .vsync_end = 768 + 2 + 5,
1547 .vtotal = 768 + 2 + 5 + 17,
1550 static const struct panel_desc samsung_ltn140at29_301 = {
1551 .modes = &samsung_ltn140at29_301_mode,
1560 static const struct drm_display_mode sharp_ld_d5116z01b_mode = {
1563 .hsync_start = 1920 + 48,
1564 .hsync_end = 1920 + 48 + 32,
1565 .htotal = 1920 + 48 + 32 + 80,
1567 .vsync_start = 1280 + 3,
1568 .vsync_end = 1280 + 3 + 10,
1569 .vtotal = 1280 + 3 + 10 + 57,
1570 .flags = DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC,
1573 static const struct panel_desc sharp_ld_d5116z01b = {
1574 .modes = &sharp_ld_d5116z01b_mode,
1583 static const struct display_timing sharp_lq123p1jx31_timing = {
1584 .pixelclock = { 252750000, 252750000, 266604720 },
1585 .hactive = { 2400, 2400, 2400 },
1586 .hfront_porch = { 48, 48, 48 },
1587 .hback_porch = { 80, 80, 84 },
1588 .hsync_len = { 32, 32, 32 },
1589 .vactive = { 1600, 1600, 1600 },
1590 .vfront_porch = { 3, 3, 3 },
1591 .vback_porch = { 33, 33, 120 },
1592 .vsync_len = { 10, 10, 10 },
1593 .flags = DISPLAY_FLAGS_VSYNC_LOW | DISPLAY_FLAGS_HSYNC_LOW,
1596 static const struct panel_desc sharp_lq123p1jx31 = {
1597 .timings = &sharp_lq123p1jx31_timing,
1605 .hpd_reliable = 110,
1611 static const struct of_device_id platform_of_match[] = {
1614 .compatible = "edp-panel",
1617 * Do not add panels to the list below unless they cannot be handled by
1618 * the generic edp-panel compatible.
1620 * The only two valid reasons are:
1621 * - Because of the panel issues (e.g. broken EDID or broken
1623 * - Because the eDP drivers didn't wire up the AUX bus properly.
1624 * NOTE that, though this is a marginally valid reason,
1625 * some justification needs to be made for why the platform can't
1626 * wire up the AUX bus properly.
1628 * In all other cases the platform should use the aux-bus and declare
1629 * the panel using the 'edp-panel' compatible as a device on the AUX
1633 .compatible = "auo,b101ean01",
1634 .data = &auo_b101ean01,
1636 .compatible = "auo,b116xa01",
1637 .data = &auo_b116xak01,
1639 .compatible = "auo,b133htn01",
1640 .data = &auo_b133htn01,
1642 .compatible = "auo,b133xtn01",
1643 .data = &auo_b133xtn01,
1645 .compatible = "boe,nv101wxmn51",
1646 .data = &boe_nv101wxmn51,
1648 .compatible = "boe,nv110wtm-n61",
1649 .data = &boe_nv110wtm_n61,
1651 .compatible = "boe,nv133fhm-n61",
1652 .data = &boe_nv133fhm_n61,
1654 .compatible = "boe,nv133fhm-n62",
1655 .data = &boe_nv133fhm_n61,
1657 .compatible = "boe,nv140fhmn49",
1658 .data = &boe_nv140fhmn49,
1660 .compatible = "innolux,n116bca-ea1",
1661 .data = &innolux_n116bca_ea1,
1663 .compatible = "innolux,n116bge",
1664 .data = &innolux_n116bge,
1666 .compatible = "innolux,n125hce-gn1",
1667 .data = &innolux_n125hce_gn1,
1669 .compatible = "innolux,p120zdg-bf1",
1670 .data = &innolux_p120zdg_bf1,
1672 .compatible = "kingdisplay,kd116n21-30nv-a010",
1673 .data = &kingdisplay_kd116n21_30nv_a010,
1675 .compatible = "lg,lp079qx1-sp0v",
1676 .data = &lg_lp079qx1_sp0v,
1678 .compatible = "lg,lp097qx1-spa1",
1679 .data = &lg_lp097qx1_spa1,
1681 .compatible = "lg,lp120up1",
1682 .data = &lg_lp120up1,
1684 .compatible = "lg,lp129qe",
1685 .data = &lg_lp129qe,
1687 .compatible = "neweast,wjfh116008a",
1688 .data = &neweast_wjfh116008a,
1690 .compatible = "samsung,lsn122dl01-c01",
1691 .data = &samsung_lsn122dl01_c01,
1693 .compatible = "samsung,ltn140at29-301",
1694 .data = &samsung_ltn140at29_301,
1696 .compatible = "sharp,ld-d5116z01b",
1697 .data = &sharp_ld_d5116z01b,
1699 .compatible = "sharp,lq123p1jx31",
1700 .data = &sharp_lq123p1jx31,
1705 MODULE_DEVICE_TABLE(of, platform_of_match);
1707 static const struct panel_delay delay_200_500_p2e80 = {
1710 .prepare_to_enable = 80,
1713 static const struct panel_delay delay_200_500_e50_p2e80 = {
1717 .prepare_to_enable = 80,
1720 static const struct panel_delay delay_200_500_p2e100 = {
1723 .prepare_to_enable = 100,
1726 static const struct panel_delay delay_200_500_e50 = {
1732 static const struct panel_delay delay_200_500_e50_p2e200 = {
1736 .prepare_to_enable = 200,
1739 static const struct panel_delay delay_200_500_e80 = {
1745 static const struct panel_delay delay_200_500_e80_d50 = {
1752 static const struct panel_delay delay_80_500_e50 = {
1758 static const struct panel_delay delay_100_500_e200 = {
1764 static const struct panel_delay delay_200_500_e200 = {
1770 static const struct panel_delay delay_200_500_e200_d200 = {
1777 static const struct panel_delay delay_200_500_e200_d10 = {
1784 static const struct panel_delay delay_200_150_e200 = {
1790 static const struct panel_delay delay_200_500_e50_po2e200 = {
1794 .powered_on_to_enable = 200,
1797 #define EDP_PANEL_ENTRY(vend_chr_0, vend_chr_1, vend_chr_2, product_id, _delay, _name) \
1801 .panel_id = drm_edid_encode_panel_id(vend_chr_0, vend_chr_1, vend_chr_2, \
1807 #define EDP_PANEL_ENTRY2(vend_chr_0, vend_chr_1, vend_chr_2, product_id, _delay, _name, _mode) \
1811 .panel_id = drm_edid_encode_panel_id(vend_chr_0, vend_chr_1, vend_chr_2, \
1815 .override_edid_mode = _mode \
1819 * This table is used to figure out power sequencing delays for panels that
1820 * are detected by EDID. Entries here may point to entries in the
1821 * platform_of_match table (if a panel is listed in both places).
1823 * Sort first by vendor, then by product ID.
1825 static const struct edp_panel_entry edp_panels[] = {
1826 EDP_PANEL_ENTRY('A', 'U', 'O', 0x105c, &delay_200_500_e50, "B116XTN01.0"),
1827 EDP_PANEL_ENTRY('A', 'U', 'O', 0x1062, &delay_200_500_e50, "B120XAN01.0"),
1828 EDP_PANEL_ENTRY('A', 'U', 'O', 0x125c, &delay_200_500_e50, "Unknown"),
1829 EDP_PANEL_ENTRY('A', 'U', 'O', 0x145c, &delay_200_500_e50, "B116XAB01.4"),
1830 EDP_PANEL_ENTRY('A', 'U', 'O', 0x1999, &delay_200_500_e50, "Unknown"),
1831 EDP_PANEL_ENTRY('A', 'U', 'O', 0x1e9b, &delay_200_500_e50, "B133UAN02.1"),
1832 EDP_PANEL_ENTRY('A', 'U', 'O', 0x1ea5, &delay_200_500_e50, "B116XAK01.6"),
1833 EDP_PANEL_ENTRY('A', 'U', 'O', 0x203d, &delay_200_500_e50, "B140HTN02.0"),
1834 EDP_PANEL_ENTRY('A', 'U', 'O', 0x208d, &delay_200_500_e50, "B140HTN02.1"),
1835 EDP_PANEL_ENTRY('A', 'U', 'O', 0x235c, &delay_200_500_e50, "B116XTN02.3"),
1836 EDP_PANEL_ENTRY('A', 'U', 'O', 0x239b, &delay_200_500_e50, "B116XAN06.1"),
1837 EDP_PANEL_ENTRY('A', 'U', 'O', 0x255c, &delay_200_500_e50, "B116XTN02.5"),
1838 EDP_PANEL_ENTRY('A', 'U', 'O', 0x403d, &delay_200_500_e50, "B140HAN04.0"),
1839 EDP_PANEL_ENTRY('A', 'U', 'O', 0x405c, &auo_b116xak01.delay, "B116XAN04.0"),
1840 EDP_PANEL_ENTRY2('A', 'U', 'O', 0x405c, &auo_b116xak01.delay, "B116XAK01.0",
1842 EDP_PANEL_ENTRY('A', 'U', 'O', 0x435c, &delay_200_500_e50, "Unknown"),
1843 EDP_PANEL_ENTRY('A', 'U', 'O', 0x582d, &delay_200_500_e50, "B133UAN01.0"),
1844 EDP_PANEL_ENTRY('A', 'U', 'O', 0x615c, &delay_200_500_e50, "B116XAN06.1"),
1845 EDP_PANEL_ENTRY('A', 'U', 'O', 0x635c, &delay_200_500_e50, "B116XAN06.3"),
1846 EDP_PANEL_ENTRY('A', 'U', 'O', 0x639c, &delay_200_500_e50, "B140HAK02.7"),
1847 EDP_PANEL_ENTRY('A', 'U', 'O', 0x723c, &delay_200_500_e50, "B140XTN07.2"),
1848 EDP_PANEL_ENTRY('A', 'U', 'O', 0x8594, &delay_200_500_e50, "B133UAN01.0"),
1849 EDP_PANEL_ENTRY('A', 'U', 'O', 0xd497, &delay_200_500_e50, "B120XAN01.0"),
1850 EDP_PANEL_ENTRY('A', 'U', 'O', 0xf390, &delay_200_500_e50, "B140XTN07.7"),
1852 EDP_PANEL_ENTRY('B', 'O', 'E', 0x0607, &delay_200_500_e200, "Unknown"),
1853 EDP_PANEL_ENTRY('B', 'O', 'E', 0x0608, &delay_200_500_e50, "NT116WHM-N11"),
1854 EDP_PANEL_ENTRY('B', 'O', 'E', 0x0609, &delay_200_500_e50_po2e200, "NT116WHM-N21 V4.1"),
1855 EDP_PANEL_ENTRY('B', 'O', 'E', 0x0623, &delay_200_500_e200, "NT116WHM-N21 V4.0"),
1856 EDP_PANEL_ENTRY('B', 'O', 'E', 0x0668, &delay_200_500_e200, "Unknown"),
1857 EDP_PANEL_ENTRY('B', 'O', 'E', 0x068f, &delay_200_500_e200, "Unknown"),
1858 EDP_PANEL_ENTRY('B', 'O', 'E', 0x06e5, &delay_200_500_e200, "Unknown"),
1859 EDP_PANEL_ENTRY('B', 'O', 'E', 0x0705, &delay_200_500_e200, "Unknown"),
1860 EDP_PANEL_ENTRY('B', 'O', 'E', 0x0715, &delay_200_150_e200, "NT116WHM-N21"),
1861 EDP_PANEL_ENTRY('B', 'O', 'E', 0x0717, &delay_200_500_e50_po2e200, "NV133FHM-N42"),
1862 EDP_PANEL_ENTRY('B', 'O', 'E', 0x0731, &delay_200_500_e80, "NT116WHM-N42"),
1863 EDP_PANEL_ENTRY('B', 'O', 'E', 0x0741, &delay_200_500_e200, "NT116WHM-N44"),
1864 EDP_PANEL_ENTRY('B', 'O', 'E', 0x0744, &delay_200_500_e200, "Unknown"),
1865 EDP_PANEL_ENTRY('B', 'O', 'E', 0x074c, &delay_200_500_e200, "Unknown"),
1866 EDP_PANEL_ENTRY('B', 'O', 'E', 0x0751, &delay_200_500_e200, "Unknown"),
1867 EDP_PANEL_ENTRY('B', 'O', 'E', 0x0754, &delay_200_500_e50_po2e200, "NV116WHM-N45"),
1868 EDP_PANEL_ENTRY('B', 'O', 'E', 0x0771, &delay_200_500_e200, "Unknown"),
1869 EDP_PANEL_ENTRY('B', 'O', 'E', 0x0786, &delay_200_500_p2e80, "NV116WHM-T01"),
1870 EDP_PANEL_ENTRY('B', 'O', 'E', 0x0797, &delay_200_500_e200, "Unknown"),
1871 EDP_PANEL_ENTRY('B', 'O', 'E', 0x07a8, &delay_200_500_e50_po2e200, "NT116WHM-N21"),
1872 EDP_PANEL_ENTRY('B', 'O', 'E', 0x07d1, &boe_nv133fhm_n61.delay, "NV133FHM-N61"),
1873 EDP_PANEL_ENTRY('B', 'O', 'E', 0x07d3, &delay_200_500_e200, "Unknown"),
1874 EDP_PANEL_ENTRY('B', 'O', 'E', 0x07f6, &delay_200_500_e200, "NT140FHM-N44"),
1875 EDP_PANEL_ENTRY('B', 'O', 'E', 0x07f8, &delay_200_500_e200, "Unknown"),
1876 EDP_PANEL_ENTRY('B', 'O', 'E', 0x0813, &delay_200_500_e200, "Unknown"),
1877 EDP_PANEL_ENTRY('B', 'O', 'E', 0x0827, &delay_200_500_e50_p2e80, "NT140WHM-N44 V8.0"),
1878 EDP_PANEL_ENTRY('B', 'O', 'E', 0x082d, &boe_nv133fhm_n61.delay, "NV133FHM-N62"),
1879 EDP_PANEL_ENTRY('B', 'O', 'E', 0x0843, &delay_200_500_e200, "Unknown"),
1880 EDP_PANEL_ENTRY('B', 'O', 'E', 0x08b2, &delay_200_500_e200, "NT140WHM-N49"),
1881 EDP_PANEL_ENTRY('B', 'O', 'E', 0x0848, &delay_200_500_e200, "Unknown"),
1882 EDP_PANEL_ENTRY('B', 'O', 'E', 0x0849, &delay_200_500_e200, "Unknown"),
1883 EDP_PANEL_ENTRY('B', 'O', 'E', 0x09c3, &delay_200_500_e50, "NT116WHM-N21,836X2"),
1884 EDP_PANEL_ENTRY('B', 'O', 'E', 0x094b, &delay_200_500_e50, "NT116WHM-N21"),
1885 EDP_PANEL_ENTRY('B', 'O', 'E', 0x0951, &delay_200_500_e80, "NV116WHM-N47"),
1886 EDP_PANEL_ENTRY('B', 'O', 'E', 0x095f, &delay_200_500_e50, "NE135FBM-N41 v8.1"),
1887 EDP_PANEL_ENTRY('B', 'O', 'E', 0x096e, &delay_200_500_e50_po2e200, "NV116WHM-T07 V8.0"),
1888 EDP_PANEL_ENTRY('B', 'O', 'E', 0x0979, &delay_200_500_e50, "NV116WHM-N49 V8.0"),
1889 EDP_PANEL_ENTRY('B', 'O', 'E', 0x098d, &boe_nv110wtm_n61.delay, "NV110WTM-N61"),
1890 EDP_PANEL_ENTRY('B', 'O', 'E', 0x0993, &delay_200_500_e80, "NV116WHM-T14 V8.0"),
1891 EDP_PANEL_ENTRY('B', 'O', 'E', 0x09ad, &delay_200_500_e80, "NV116WHM-N47"),
1892 EDP_PANEL_ENTRY('B', 'O', 'E', 0x09ae, &delay_200_500_e200, "NT140FHM-N45"),
1893 EDP_PANEL_ENTRY('B', 'O', 'E', 0x09dd, &delay_200_500_e50, "NT116WHM-N21"),
1894 EDP_PANEL_ENTRY('B', 'O', 'E', 0x0a36, &delay_200_500_e200, "Unknown"),
1895 EDP_PANEL_ENTRY('B', 'O', 'E', 0x0a3e, &delay_200_500_e80, "NV116WHM-N49"),
1896 EDP_PANEL_ENTRY('B', 'O', 'E', 0x0a5d, &delay_200_500_e50, "NV116WHM-N45"),
1897 EDP_PANEL_ENTRY('B', 'O', 'E', 0x0ac5, &delay_200_500_e50, "NV116WHM-N4C"),
1898 EDP_PANEL_ENTRY('B', 'O', 'E', 0x0b34, &delay_200_500_e80, "NV122WUM-N41"),
1899 EDP_PANEL_ENTRY('B', 'O', 'E', 0x0b43, &delay_200_500_e200, "NV140FHM-T09"),
1900 EDP_PANEL_ENTRY('B', 'O', 'E', 0x0b56, &delay_200_500_e80, "NT140FHM-N47"),
1901 EDP_PANEL_ENTRY('B', 'O', 'E', 0x0c20, &delay_200_500_e80, "NT140FHM-N47"),
1902 EDP_PANEL_ENTRY('B', 'O', 'E', 0x0cb6, &delay_200_500_e200, "NT116WHM-N44"),
1904 EDP_PANEL_ENTRY('C', 'M', 'N', 0x1130, &delay_200_500_e50, "N116BGE-EB2"),
1905 EDP_PANEL_ENTRY('C', 'M', 'N', 0x1132, &delay_200_500_e80_d50, "N116BGE-EA2"),
1906 EDP_PANEL_ENTRY('C', 'M', 'N', 0x1138, &innolux_n116bca_ea1.delay, "N116BCA-EA1-RC4"),
1907 EDP_PANEL_ENTRY('C', 'M', 'N', 0x1139, &delay_200_500_e80_d50, "N116BGE-EA2"),
1908 EDP_PANEL_ENTRY('C', 'M', 'N', 0x1141, &delay_200_500_e80_d50, "Unknown"),
1909 EDP_PANEL_ENTRY('C', 'M', 'N', 0x1145, &delay_200_500_e80_d50, "N116BCN-EB1"),
1910 EDP_PANEL_ENTRY('C', 'M', 'N', 0x114a, &delay_200_500_e80_d50, "Unknown"),
1911 EDP_PANEL_ENTRY('C', 'M', 'N', 0x114c, &innolux_n116bca_ea1.delay, "N116BCA-EA1"),
1912 EDP_PANEL_ENTRY('C', 'M', 'N', 0x1152, &delay_200_500_e80_d50, "N116BCN-EA1"),
1913 EDP_PANEL_ENTRY('C', 'M', 'N', 0x1153, &delay_200_500_e80_d50, "N116BGE-EA2"),
1914 EDP_PANEL_ENTRY('C', 'M', 'N', 0x1154, &delay_200_500_e80_d50, "N116BCA-EA2"),
1915 EDP_PANEL_ENTRY('C', 'M', 'N', 0x1156, &delay_200_500_e80_d50, "Unknown"),
1916 EDP_PANEL_ENTRY('C', 'M', 'N', 0x1157, &delay_200_500_e80_d50, "N116BGE-EA2"),
1917 EDP_PANEL_ENTRY('C', 'M', 'N', 0x115b, &delay_200_500_e80_d50, "N116BCN-EB1"),
1918 EDP_PANEL_ENTRY('C', 'M', 'N', 0x115e, &delay_200_500_e80_d50, "N116BCA-EA1"),
1919 EDP_PANEL_ENTRY('C', 'M', 'N', 0x1160, &delay_200_500_e80_d50, "N116BCJ-EAK"),
1920 EDP_PANEL_ENTRY('C', 'M', 'N', 0x1247, &delay_200_500_e80_d50, "N120ACA-EA1"),
1921 EDP_PANEL_ENTRY('C', 'M', 'N', 0x142b, &delay_200_500_e80_d50, "N140HCA-EAC"),
1922 EDP_PANEL_ENTRY('C', 'M', 'N', 0x142e, &delay_200_500_e80_d50, "N140BGA-EA4"),
1923 EDP_PANEL_ENTRY('C', 'M', 'N', 0x144f, &delay_200_500_e80_d50, "N140HGA-EA1"),
1924 EDP_PANEL_ENTRY('C', 'M', 'N', 0x1468, &delay_200_500_e80, "N140HGA-EA1"),
1925 EDP_PANEL_ENTRY('C', 'M', 'N', 0x14d4, &delay_200_500_e80_d50, "N140HCA-EAC"),
1926 EDP_PANEL_ENTRY('C', 'M', 'N', 0x14d6, &delay_200_500_e80_d50, "N140BGA-EA4"),
1927 EDP_PANEL_ENTRY('C', 'M', 'N', 0x14e5, &delay_200_500_e80_d50, "N140HGA-EA1"),
1929 EDP_PANEL_ENTRY('C', 'S', 'O', 0x1200, &delay_200_500_e50_p2e200, "MNC207QS1-1"),
1931 EDP_PANEL_ENTRY('C', 'S', 'W', 0x1100, &delay_200_500_e80_d50, "MNB601LS1-1"),
1933 EDP_PANEL_ENTRY('H', 'K', 'C', 0x2d51, &delay_200_500_e200, "Unknown"),
1934 EDP_PANEL_ENTRY('H', 'K', 'C', 0x2d5b, &delay_200_500_e200, "Unknown"),
1935 EDP_PANEL_ENTRY('H', 'K', 'C', 0x2d5c, &delay_200_500_e200, "MB116AN01-2"),
1937 EDP_PANEL_ENTRY('I', 'V', 'O', 0x048e, &delay_200_500_e200_d10, "M116NWR6 R5"),
1938 EDP_PANEL_ENTRY('I', 'V', 'O', 0x057d, &delay_200_500_e200, "R140NWF5 RH"),
1939 EDP_PANEL_ENTRY('I', 'V', 'O', 0x854a, &delay_200_500_p2e100, "M133NW4J"),
1940 EDP_PANEL_ENTRY('I', 'V', 'O', 0x854b, &delay_200_500_p2e100, "R133NW4K-R0"),
1941 EDP_PANEL_ENTRY('I', 'V', 'O', 0x8c4d, &delay_200_150_e200, "R140NWFM R1"),
1943 EDP_PANEL_ENTRY('K', 'D', 'B', 0x044f, &delay_200_500_e80_d50, "Unknown"),
1944 EDP_PANEL_ENTRY('K', 'D', 'B', 0x0624, &kingdisplay_kd116n21_30nv_a010.delay, "116N21-30NV-A010"),
1945 EDP_PANEL_ENTRY('K', 'D', 'B', 0x1118, &delay_200_500_e50, "KD116N29-30NK-A005"),
1946 EDP_PANEL_ENTRY('K', 'D', 'B', 0x1120, &delay_200_500_e80_d50, "116N29-30NK-C007"),
1947 EDP_PANEL_ENTRY('K', 'D', 'B', 0x1212, &delay_200_500_e50, "KD116N0930A16"),
1949 EDP_PANEL_ENTRY('K', 'D', 'C', 0x044f, &delay_200_500_e50, "KD116N9-30NH-F3"),
1950 EDP_PANEL_ENTRY('K', 'D', 'C', 0x05f1, &delay_200_500_e80_d50, "KD116N5-30NV-G7"),
1951 EDP_PANEL_ENTRY('K', 'D', 'C', 0x0809, &delay_200_500_e50, "KD116N2930A15"),
1953 EDP_PANEL_ENTRY('L', 'G', 'D', 0x0000, &delay_200_500_e200_d200, "Unknown"),
1954 EDP_PANEL_ENTRY('L', 'G', 'D', 0x048d, &delay_200_500_e200_d200, "Unknown"),
1955 EDP_PANEL_ENTRY('L', 'G', 'D', 0x0497, &delay_200_500_e200_d200, "LP116WH7-SPB1"),
1956 EDP_PANEL_ENTRY('L', 'G', 'D', 0x052c, &delay_200_500_e200_d200, "LP133WF2-SPL7"),
1957 EDP_PANEL_ENTRY('L', 'G', 'D', 0x0537, &delay_200_500_e200_d200, "Unknown"),
1958 EDP_PANEL_ENTRY('L', 'G', 'D', 0x054a, &delay_200_500_e200_d200, "LP116WH8-SPC1"),
1959 EDP_PANEL_ENTRY('L', 'G', 'D', 0x0567, &delay_200_500_e200_d200, "Unknown"),
1960 EDP_PANEL_ENTRY('L', 'G', 'D', 0x05af, &delay_200_500_e200_d200, "Unknown"),
1961 EDP_PANEL_ENTRY('L', 'G', 'D', 0x05f1, &delay_200_500_e200_d200, "Unknown"),
1963 EDP_PANEL_ENTRY('S', 'D', 'C', 0x416d, &delay_100_500_e200, "ATNA45AF01"),
1965 EDP_PANEL_ENTRY('S', 'H', 'P', 0x1511, &delay_200_500_e50, "LQ140M1JW48"),
1966 EDP_PANEL_ENTRY('S', 'H', 'P', 0x1523, &delay_80_500_e50, "LQ140M1JW46"),
1967 EDP_PANEL_ENTRY('S', 'H', 'P', 0x153a, &delay_200_500_e50, "LQ140T1JH01"),
1968 EDP_PANEL_ENTRY('S', 'H', 'P', 0x154c, &delay_200_500_p2e100, "LQ116M1JW10"),
1970 EDP_PANEL_ENTRY('S', 'T', 'A', 0x0100, &delay_100_500_e200, "2081116HHD028001-51D"),
1975 static const struct edp_panel_entry *find_edp_panel(u32 panel_id, const struct drm_edid *edid)
1977 const struct edp_panel_entry *panel;
1983 * Match with identity first. This allows handling the case where
1984 * vendors incorrectly reused the same panel ID for multiple panels that
1985 * need different settings. If there's no match, try again with panel
1986 * ID, which should be unique.
1988 for (panel = edp_panels; panel->ident.panel_id; panel++)
1989 if (drm_edid_match(edid, &panel->ident))
1992 for (panel = edp_panels; panel->ident.panel_id; panel++)
1993 if (panel->ident.panel_id == panel_id)
1999 static int panel_edp_platform_probe(struct platform_device *pdev)
2001 const struct of_device_id *id;
2003 /* Skip one since "edp-panel" is only supported on DP AUX bus */
2004 id = of_match_node(platform_of_match + 1, pdev->dev.of_node);
2008 return panel_edp_probe(&pdev->dev, id->data, NULL);
2011 static void panel_edp_platform_remove(struct platform_device *pdev)
2013 panel_edp_remove(&pdev->dev);
2016 static void panel_edp_platform_shutdown(struct platform_device *pdev)
2018 panel_edp_shutdown(&pdev->dev);
2021 static const struct dev_pm_ops panel_edp_pm_ops = {
2022 SET_RUNTIME_PM_OPS(panel_edp_suspend, panel_edp_resume, NULL)
2023 SET_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend,
2024 pm_runtime_force_resume)
2027 static struct platform_driver panel_edp_platform_driver = {
2029 .name = "panel-edp",
2030 .of_match_table = platform_of_match,
2031 .pm = &panel_edp_pm_ops,
2033 .probe = panel_edp_platform_probe,
2034 .remove_new = panel_edp_platform_remove,
2035 .shutdown = panel_edp_platform_shutdown,
2038 static int panel_edp_dp_aux_ep_probe(struct dp_aux_ep_device *aux_ep)
2040 const struct of_device_id *id;
2042 id = of_match_node(platform_of_match, aux_ep->dev.of_node);
2046 return panel_edp_probe(&aux_ep->dev, id->data, aux_ep->aux);
2049 static void panel_edp_dp_aux_ep_remove(struct dp_aux_ep_device *aux_ep)
2051 panel_edp_remove(&aux_ep->dev);
2054 static void panel_edp_dp_aux_ep_shutdown(struct dp_aux_ep_device *aux_ep)
2056 panel_edp_shutdown(&aux_ep->dev);
2059 static struct dp_aux_ep_driver panel_edp_dp_aux_ep_driver = {
2061 .name = "panel-simple-dp-aux",
2062 .of_match_table = platform_of_match, /* Same as platform one! */
2063 .pm = &panel_edp_pm_ops,
2065 .probe = panel_edp_dp_aux_ep_probe,
2066 .remove = panel_edp_dp_aux_ep_remove,
2067 .shutdown = panel_edp_dp_aux_ep_shutdown,
2070 static int __init panel_edp_init(void)
2074 err = platform_driver_register(&panel_edp_platform_driver);
2078 err = dp_aux_dp_driver_register(&panel_edp_dp_aux_ep_driver);
2080 goto err_did_platform_register;
2084 err_did_platform_register:
2085 platform_driver_unregister(&panel_edp_platform_driver);
2089 module_init(panel_edp_init);
2091 static void __exit panel_edp_exit(void)
2093 dp_aux_dp_driver_unregister(&panel_edp_dp_aux_ep_driver);
2094 platform_driver_unregister(&panel_edp_platform_driver);
2096 module_exit(panel_edp_exit);
2099 MODULE_DESCRIPTION("DRM Driver for Simple eDP Panels");
2100 MODULE_LICENSE("GPL and additional rights");