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