| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * Ilitek ILI9322 TFT LCD drm_panel driver. |
|---|
| 3 | 4 | * |
|---|
| .. | .. |
|---|
| 16 | 17 | * |
|---|
| 17 | 18 | * Copyright (C) 2017 Linus Walleij <linus.walleij@linaro.org> |
|---|
| 18 | 19 | * Derived from drivers/drm/gpu/panel/panel-samsung-ld9040.c |
|---|
| 19 | | - * |
|---|
| 20 | | - * This program is free software; you can redistribute it and/or modify |
|---|
| 21 | | - * it under the terms of the GNU General Public License version 2 as |
|---|
| 22 | | - * published by the Free Software Foundation. |
|---|
| 23 | 20 | */ |
|---|
| 24 | 21 | |
|---|
| 25 | | -#include <drm/drmP.h> |
|---|
| 26 | | -#include <drm/drm_panel.h> |
|---|
| 27 | | - |
|---|
| 28 | | -#include <linux/of_device.h> |
|---|
| 29 | 22 | #include <linux/bitops.h> |
|---|
| 30 | 23 | #include <linux/gpio/consumer.h> |
|---|
| 31 | 24 | #include <linux/module.h> |
|---|
| 25 | +#include <linux/of_device.h> |
|---|
| 32 | 26 | #include <linux/regmap.h> |
|---|
| 33 | 27 | #include <linux/regulator/consumer.h> |
|---|
| 34 | 28 | #include <linux/spi/spi.h> |
|---|
| .. | .. |
|---|
| 36 | 30 | #include <video/mipi_display.h> |
|---|
| 37 | 31 | #include <video/of_videomode.h> |
|---|
| 38 | 32 | #include <video/videomode.h> |
|---|
| 33 | + |
|---|
| 34 | +#include <drm/drm_modes.h> |
|---|
| 35 | +#include <drm/drm_panel.h> |
|---|
| 39 | 36 | |
|---|
| 40 | 37 | #define ILI9322_CHIP_ID 0x00 |
|---|
| 41 | 38 | #define ILI9322_CHIP_ID_MAGIC 0x96 |
|---|
| .. | .. |
|---|
| 351 | 348 | |
|---|
| 352 | 349 | static int ili9322_init(struct drm_panel *panel, struct ili9322 *ili) |
|---|
| 353 | 350 | { |
|---|
| 354 | | - struct drm_connector *connector = panel->connector; |
|---|
| 355 | 351 | u8 reg; |
|---|
| 356 | 352 | int ret; |
|---|
| 357 | 353 | int i; |
|---|
| .. | .. |
|---|
| 382 | 378 | "can't set up VCOM amplitude (%d)\n", ret); |
|---|
| 383 | 379 | return ret; |
|---|
| 384 | 380 | } |
|---|
| 385 | | - }; |
|---|
| 381 | + } |
|---|
| 386 | 382 | |
|---|
| 387 | 383 | if (ili->vcom_high != U8_MAX) { |
|---|
| 388 | 384 | ret = regmap_write(ili->regmap, ILI9322_VCOM_HIGH, |
|---|
| .. | .. |
|---|
| 391 | 387 | dev_err(ili->dev, "can't set up VCOM high (%d)\n", ret); |
|---|
| 392 | 388 | return ret; |
|---|
| 393 | 389 | } |
|---|
| 394 | | - }; |
|---|
| 390 | + } |
|---|
| 395 | 391 | |
|---|
| 396 | 392 | /* Set up gamma correction */ |
|---|
| 397 | 393 | for (i = 0; i < ARRAY_SIZE(ili->gamma); i++) { |
|---|
| .. | .. |
|---|
| 409 | 405 | * Polarity and inverted color order for RGB input. |
|---|
| 410 | 406 | * None of this applies in the BT.656 mode. |
|---|
| 411 | 407 | */ |
|---|
| 412 | | - if (ili->conf->dclk_active_high) { |
|---|
| 408 | + reg = 0; |
|---|
| 409 | + if (ili->conf->dclk_active_high) |
|---|
| 413 | 410 | reg = ILI9322_POL_DCLK; |
|---|
| 414 | | - connector->display_info.bus_flags |= |
|---|
| 415 | | - DRM_BUS_FLAG_PIXDATA_POSEDGE; |
|---|
| 416 | | - } else { |
|---|
| 417 | | - reg = 0; |
|---|
| 418 | | - connector->display_info.bus_flags |= |
|---|
| 419 | | - DRM_BUS_FLAG_PIXDATA_NEGEDGE; |
|---|
| 420 | | - } |
|---|
| 421 | | - if (ili->conf->de_active_high) { |
|---|
| 411 | + if (ili->conf->de_active_high) |
|---|
| 422 | 412 | reg |= ILI9322_POL_DE; |
|---|
| 423 | | - connector->display_info.bus_flags |= |
|---|
| 424 | | - DRM_BUS_FLAG_DE_HIGH; |
|---|
| 425 | | - } else { |
|---|
| 426 | | - connector->display_info.bus_flags |= |
|---|
| 427 | | - DRM_BUS_FLAG_DE_LOW; |
|---|
| 428 | | - } |
|---|
| 429 | 413 | if (ili->conf->hsync_active_high) |
|---|
| 430 | 414 | reg |= ILI9322_POL_HSYNC; |
|---|
| 431 | 415 | if (ili->conf->vsync_active_high) |
|---|
| .. | .. |
|---|
| 555 | 539 | |
|---|
| 556 | 540 | /* Serial RGB modes */ |
|---|
| 557 | 541 | static const struct drm_display_mode srgb_320x240_mode = { |
|---|
| 558 | | - .clock = 2453500, |
|---|
| 542 | + .clock = 24535, |
|---|
| 559 | 543 | .hdisplay = 320, |
|---|
| 560 | 544 | .hsync_start = 320 + 359, |
|---|
| 561 | 545 | .hsync_end = 320 + 359 + 1, |
|---|
| .. | .. |
|---|
| 564 | 548 | .vsync_start = 240 + 4, |
|---|
| 565 | 549 | .vsync_end = 240 + 4 + 1, |
|---|
| 566 | 550 | .vtotal = 262, |
|---|
| 567 | | - .vrefresh = 60, |
|---|
| 568 | 551 | .flags = 0, |
|---|
| 569 | 552 | }; |
|---|
| 570 | 553 | |
|---|
| 571 | 554 | static const struct drm_display_mode srgb_360x240_mode = { |
|---|
| 572 | | - .clock = 2700000, |
|---|
| 555 | + .clock = 27000, |
|---|
| 573 | 556 | .hdisplay = 360, |
|---|
| 574 | 557 | .hsync_start = 360 + 35, |
|---|
| 575 | 558 | .hsync_end = 360 + 35 + 1, |
|---|
| .. | .. |
|---|
| 578 | 561 | .vsync_start = 240 + 21, |
|---|
| 579 | 562 | .vsync_end = 240 + 21 + 1, |
|---|
| 580 | 563 | .vtotal = 262, |
|---|
| 581 | | - .vrefresh = 60, |
|---|
| 582 | 564 | .flags = 0, |
|---|
| 583 | 565 | }; |
|---|
| 584 | 566 | |
|---|
| 585 | 567 | /* This is the only mode listed for parallel RGB in the datasheet */ |
|---|
| 586 | 568 | static const struct drm_display_mode prgb_320x240_mode = { |
|---|
| 587 | | - .clock = 6400000, |
|---|
| 569 | + .clock = 64000, |
|---|
| 588 | 570 | .hdisplay = 320, |
|---|
| 589 | 571 | .hsync_start = 320 + 38, |
|---|
| 590 | 572 | .hsync_end = 320 + 38 + 1, |
|---|
| .. | .. |
|---|
| 593 | 575 | .vsync_start = 240 + 4, |
|---|
| 594 | 576 | .vsync_end = 240 + 4 + 1, |
|---|
| 595 | 577 | .vtotal = 262, |
|---|
| 596 | | - .vrefresh = 60, |
|---|
| 597 | 578 | .flags = 0, |
|---|
| 598 | 579 | }; |
|---|
| 599 | 580 | |
|---|
| 600 | 581 | /* YUV modes */ |
|---|
| 601 | 582 | static const struct drm_display_mode yuv_640x320_mode = { |
|---|
| 602 | | - .clock = 2454000, |
|---|
| 583 | + .clock = 24540, |
|---|
| 603 | 584 | .hdisplay = 640, |
|---|
| 604 | 585 | .hsync_start = 640 + 252, |
|---|
| 605 | 586 | .hsync_end = 640 + 252 + 1, |
|---|
| .. | .. |
|---|
| 608 | 589 | .vsync_start = 320 + 4, |
|---|
| 609 | 590 | .vsync_end = 320 + 4 + 1, |
|---|
| 610 | 591 | .vtotal = 320 + 4 + 1 + 18, |
|---|
| 611 | | - .vrefresh = 60, |
|---|
| 612 | 592 | .flags = 0, |
|---|
| 613 | 593 | }; |
|---|
| 614 | 594 | |
|---|
| 615 | 595 | static const struct drm_display_mode yuv_720x360_mode = { |
|---|
| 616 | | - .clock = 2700000, |
|---|
| 596 | + .clock = 27000, |
|---|
| 617 | 597 | .hdisplay = 720, |
|---|
| 618 | 598 | .hsync_start = 720 + 252, |
|---|
| 619 | 599 | .hsync_end = 720 + 252 + 1, |
|---|
| .. | .. |
|---|
| 622 | 602 | .vsync_start = 360 + 4, |
|---|
| 623 | 603 | .vsync_end = 360 + 4 + 1, |
|---|
| 624 | 604 | .vtotal = 360 + 4 + 1 + 18, |
|---|
| 625 | | - .vrefresh = 60, |
|---|
| 626 | 605 | .flags = 0, |
|---|
| 627 | 606 | }; |
|---|
| 628 | 607 | |
|---|
| 629 | 608 | /* BT.656 VGA mode, 640x480 */ |
|---|
| 630 | 609 | static const struct drm_display_mode itu_r_bt_656_640_mode = { |
|---|
| 631 | | - .clock = 2454000, |
|---|
| 610 | + .clock = 24540, |
|---|
| 632 | 611 | .hdisplay = 640, |
|---|
| 633 | 612 | .hsync_start = 640 + 3, |
|---|
| 634 | 613 | .hsync_end = 640 + 3 + 1, |
|---|
| .. | .. |
|---|
| 637 | 616 | .vsync_start = 480 + 4, |
|---|
| 638 | 617 | .vsync_end = 480 + 4 + 1, |
|---|
| 639 | 618 | .vtotal = 500, |
|---|
| 640 | | - .vrefresh = 60, |
|---|
| 641 | 619 | .flags = 0, |
|---|
| 642 | 620 | }; |
|---|
| 643 | 621 | |
|---|
| 644 | 622 | /* BT.656 D1 mode 720x480 */ |
|---|
| 645 | 623 | static const struct drm_display_mode itu_r_bt_656_720_mode = { |
|---|
| 646 | | - .clock = 2700000, |
|---|
| 624 | + .clock = 27000, |
|---|
| 647 | 625 | .hdisplay = 720, |
|---|
| 648 | 626 | .hsync_start = 720 + 3, |
|---|
| 649 | 627 | .hsync_end = 720 + 3 + 1, |
|---|
| .. | .. |
|---|
| 652 | 630 | .vsync_start = 480 + 4, |
|---|
| 653 | 631 | .vsync_end = 480 + 4 + 1, |
|---|
| 654 | 632 | .vtotal = 500, |
|---|
| 655 | | - .vrefresh = 60, |
|---|
| 656 | 633 | .flags = 0, |
|---|
| 657 | 634 | }; |
|---|
| 658 | 635 | |
|---|
| 659 | | -static int ili9322_get_modes(struct drm_panel *panel) |
|---|
| 636 | +static int ili9322_get_modes(struct drm_panel *panel, |
|---|
| 637 | + struct drm_connector *connector) |
|---|
| 660 | 638 | { |
|---|
| 661 | | - struct drm_connector *connector = panel->connector; |
|---|
| 662 | 639 | struct ili9322 *ili = panel_to_ili9322(panel); |
|---|
| 640 | + struct drm_device *drm = connector->dev; |
|---|
| 663 | 641 | struct drm_display_mode *mode; |
|---|
| 642 | + struct drm_display_info *info; |
|---|
| 664 | 643 | |
|---|
| 665 | | - strncpy(connector->display_info.name, "ILI9322 TFT LCD driver\0", |
|---|
| 666 | | - DRM_DISPLAY_INFO_LEN); |
|---|
| 667 | | - connector->display_info.width_mm = ili->conf->width_mm; |
|---|
| 668 | | - connector->display_info.height_mm = ili->conf->height_mm; |
|---|
| 644 | + info = &connector->display_info; |
|---|
| 645 | + info->width_mm = ili->conf->width_mm; |
|---|
| 646 | + info->height_mm = ili->conf->height_mm; |
|---|
| 647 | + if (ili->conf->dclk_active_high) |
|---|
| 648 | + info->bus_flags |= DRM_BUS_FLAG_PIXDATA_DRIVE_POSEDGE; |
|---|
| 649 | + else |
|---|
| 650 | + info->bus_flags |= DRM_BUS_FLAG_PIXDATA_DRIVE_NEGEDGE; |
|---|
| 651 | + |
|---|
| 652 | + if (ili->conf->de_active_high) |
|---|
| 653 | + info->bus_flags |= DRM_BUS_FLAG_DE_HIGH; |
|---|
| 654 | + else |
|---|
| 655 | + info->bus_flags |= DRM_BUS_FLAG_DE_LOW; |
|---|
| 669 | 656 | |
|---|
| 670 | 657 | switch (ili->input) { |
|---|
| 671 | 658 | case ILI9322_INPUT_SRGB_DUMMY_320X240: |
|---|
| 672 | | - mode = drm_mode_duplicate(panel->drm, &srgb_320x240_mode); |
|---|
| 659 | + mode = drm_mode_duplicate(drm, &srgb_320x240_mode); |
|---|
| 673 | 660 | break; |
|---|
| 674 | 661 | case ILI9322_INPUT_SRGB_DUMMY_360X240: |
|---|
| 675 | | - mode = drm_mode_duplicate(panel->drm, &srgb_360x240_mode); |
|---|
| 662 | + mode = drm_mode_duplicate(drm, &srgb_360x240_mode); |
|---|
| 676 | 663 | break; |
|---|
| 677 | 664 | case ILI9322_INPUT_PRGB_THROUGH: |
|---|
| 678 | 665 | case ILI9322_INPUT_PRGB_ALIGNED: |
|---|
| 679 | | - mode = drm_mode_duplicate(panel->drm, &prgb_320x240_mode); |
|---|
| 666 | + mode = drm_mode_duplicate(drm, &prgb_320x240_mode); |
|---|
| 680 | 667 | break; |
|---|
| 681 | 668 | case ILI9322_INPUT_YUV_640X320_YCBCR: |
|---|
| 682 | | - mode = drm_mode_duplicate(panel->drm, &yuv_640x320_mode); |
|---|
| 669 | + mode = drm_mode_duplicate(drm, &yuv_640x320_mode); |
|---|
| 683 | 670 | break; |
|---|
| 684 | 671 | case ILI9322_INPUT_YUV_720X360_YCBCR: |
|---|
| 685 | | - mode = drm_mode_duplicate(panel->drm, &yuv_720x360_mode); |
|---|
| 672 | + mode = drm_mode_duplicate(drm, &yuv_720x360_mode); |
|---|
| 686 | 673 | break; |
|---|
| 687 | 674 | case ILI9322_INPUT_ITU_R_BT656_720X360_YCBCR: |
|---|
| 688 | | - mode = drm_mode_duplicate(panel->drm, &itu_r_bt_656_720_mode); |
|---|
| 675 | + mode = drm_mode_duplicate(drm, &itu_r_bt_656_720_mode); |
|---|
| 689 | 676 | break; |
|---|
| 690 | 677 | case ILI9322_INPUT_ITU_R_BT656_640X320_YCBCR: |
|---|
| 691 | | - mode = drm_mode_duplicate(panel->drm, &itu_r_bt_656_640_mode); |
|---|
| 678 | + mode = drm_mode_duplicate(drm, &itu_r_bt_656_640_mode); |
|---|
| 692 | 679 | break; |
|---|
| 693 | 680 | default: |
|---|
| 694 | 681 | mode = NULL; |
|---|
| 695 | 682 | break; |
|---|
| 696 | 683 | } |
|---|
| 697 | 684 | if (!mode) { |
|---|
| 698 | | - DRM_ERROR("bad mode or failed to add mode\n"); |
|---|
| 685 | + dev_err(panel->dev, "bad mode or failed to add mode\n"); |
|---|
| 699 | 686 | return -EINVAL; |
|---|
| 700 | 687 | } |
|---|
| 701 | 688 | drm_mode_set_name(mode); |
|---|
| .. | .. |
|---|
| 901 | 888 | ili->input = ili->conf->input; |
|---|
| 902 | 889 | } |
|---|
| 903 | 890 | |
|---|
| 904 | | - drm_panel_init(&ili->panel); |
|---|
| 905 | | - ili->panel.dev = dev; |
|---|
| 906 | | - ili->panel.funcs = &ili9322_drm_funcs; |
|---|
| 891 | + drm_panel_init(&ili->panel, dev, &ili9322_drm_funcs, |
|---|
| 892 | + DRM_MODE_CONNECTOR_DPI); |
|---|
| 907 | 893 | |
|---|
| 908 | | - return drm_panel_add(&ili->panel); |
|---|
| 894 | + drm_panel_add(&ili->panel); |
|---|
| 895 | + |
|---|
| 896 | + return 0; |
|---|
| 909 | 897 | } |
|---|
| 910 | 898 | |
|---|
| 911 | 899 | static int ili9322_remove(struct spi_device *spi) |
|---|