Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

drm/panel: ili9341: Remove duplicate code

Remove duplicate code that is handled by tinyDRM,
i.e. drivers/gpu/drm/tiny/ili9341.c.

Suggested-by: Maxime Ripard <mripard@kernel.org>
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20240813091258.1625646-1-andriy.shevchenko@linux.intel.com
Signed-off-by: Maxime Ripard <mripard@kernel.org>

authored by

Andy Shevchenko and committed by
Maxime Ripard
e8653e63 9b79594a

+3 -207
+3 -207
drivers/gpu/drm/panel/panel-ilitek-ili9341.c
··· 13 13 * Derived from drivers/drm/gpu/panel/panel-ilitek-ili9322.c 14 14 * the reuse of DBI abstraction part referred from Linus's patch 15 15 * "drm/panel: s6e63m0: Switch to DBI abstraction for SPI" 16 - * 17 - * For only-dbi part, copy from David's code (drm/tiny/ili9341.c) 18 - * Copyright 2018 David Lechner <david@lechnology.com> 19 16 */ 20 17 21 18 #include <linux/backlight.h> ··· 483 486 .get_modes = ili9341_dpi_get_modes, 484 487 }; 485 488 486 - static void ili9341_dbi_enable(struct drm_simple_display_pipe *pipe, 487 - struct drm_crtc_state *crtc_state, 488 - struct drm_plane_state *plane_state) 489 - { 490 - struct mipi_dbi_dev *dbidev = drm_to_mipi_dbi_dev(pipe->crtc.dev); 491 - struct mipi_dbi *dbi = &dbidev->dbi; 492 - u8 addr_mode; 493 - int ret, idx; 494 - 495 - if (!drm_dev_enter(pipe->crtc.dev, &idx)) 496 - return; 497 - 498 - ret = mipi_dbi_poweron_conditional_reset(dbidev); 499 - if (ret < 0) 500 - goto out_exit; 501 - if (ret == 1) 502 - goto out_enable; 503 - 504 - mipi_dbi_command(dbi, MIPI_DCS_SET_DISPLAY_OFF); 505 - 506 - mipi_dbi_command(dbi, ILI9341_POWERB, 0x00, 0xc1, 0x30); 507 - mipi_dbi_command(dbi, ILI9341_POWER_SEQ, 0x64, 0x03, 0x12, 0x81); 508 - mipi_dbi_command(dbi, ILI9341_DTCA, 0x85, 0x00, 0x78); 509 - mipi_dbi_command(dbi, ILI9341_POWERA, 0x39, 0x2c, 0x00, 0x34, 0x02); 510 - mipi_dbi_command(dbi, ILI9341_PRC, ILI9341_DBI_PRC_NORMAL); 511 - mipi_dbi_command(dbi, ILI9341_DTCB, 0x00, 0x00); 512 - 513 - /* Power Control */ 514 - mipi_dbi_command(dbi, ILI9341_POWER1, ILI9341_DBI_VCOMH_4P6V); 515 - mipi_dbi_command(dbi, ILI9341_POWER2, ILI9341_DBI_PWR_2_DEFAULT); 516 - /* VCOM */ 517 - mipi_dbi_command(dbi, ILI9341_VCOM1, ILI9341_DBI_VCOM_1_VMH_4P25V, 518 - ILI9341_DBI_VCOM_1_VML_1P5V); 519 - mipi_dbi_command(dbi, ILI9341_VCOM2, ILI9341_DBI_VCOM_2_DEC_58); 520 - 521 - /* Memory Access Control */ 522 - mipi_dbi_command(dbi, MIPI_DCS_SET_PIXEL_FORMAT, 523 - MIPI_DCS_PIXEL_FMT_16BIT); 524 - 525 - /* Frame Rate */ 526 - mipi_dbi_command(dbi, ILI9341_FRC, ILI9341_DBI_FRC_DIVA & 0x03, 527 - ILI9341_DBI_FRC_RTNA & 0x1f); 528 - 529 - /* Gamma */ 530 - mipi_dbi_command(dbi, ILI9341_3GAMMA_EN, 0x00); 531 - mipi_dbi_command(dbi, MIPI_DCS_SET_GAMMA_CURVE, ILI9341_GAMMA_CURVE_1); 532 - mipi_dbi_command(dbi, ILI9341_PGAMMA, 533 - 0x0f, 0x31, 0x2b, 0x0c, 0x0e, 0x08, 0x4e, 0xf1, 534 - 0x37, 0x07, 0x10, 0x03, 0x0e, 0x09, 0x00); 535 - mipi_dbi_command(dbi, ILI9341_NGAMMA, 536 - 0x00, 0x0e, 0x14, 0x03, 0x11, 0x07, 0x31, 0xc1, 537 - 0x48, 0x08, 0x0f, 0x0c, 0x31, 0x36, 0x0f); 538 - 539 - /* DDRAM */ 540 - mipi_dbi_command(dbi, ILI9341_ETMOD, ILI9341_DBI_EMS_GAS | 541 - ILI9341_DBI_EMS_DTS | 542 - ILI9341_DBI_EMS_GON); 543 - 544 - /* Display */ 545 - mipi_dbi_command(dbi, ILI9341_DFC, 0x08, 0x82, 0x27, 0x00); 546 - mipi_dbi_command(dbi, MIPI_DCS_EXIT_SLEEP_MODE); 547 - msleep(100); 548 - 549 - mipi_dbi_command(dbi, MIPI_DCS_SET_DISPLAY_ON); 550 - msleep(100); 551 - 552 - out_enable: 553 - switch (dbidev->rotation) { 554 - default: 555 - addr_mode = ILI9341_MADCTL_MX; 556 - break; 557 - case 90: 558 - addr_mode = ILI9341_MADCTL_MV; 559 - break; 560 - case 180: 561 - addr_mode = ILI9341_MADCTL_MY; 562 - break; 563 - case 270: 564 - addr_mode = ILI9341_MADCTL_MV | ILI9341_MADCTL_MY | 565 - ILI9341_MADCTL_MX; 566 - break; 567 - } 568 - 569 - addr_mode |= ILI9341_MADCTL_BGR; 570 - mipi_dbi_command(dbi, MIPI_DCS_SET_ADDRESS_MODE, addr_mode); 571 - mipi_dbi_enable_flush(dbidev, crtc_state, plane_state); 572 - drm_info(&dbidev->drm, "Initialized display serial interface\n"); 573 - out_exit: 574 - drm_dev_exit(idx); 575 - } 576 - 577 - static const struct drm_simple_display_pipe_funcs ili9341_dbi_funcs = { 578 - DRM_MIPI_DBI_SIMPLE_DISPLAY_PIPE_FUNCS(ili9341_dbi_enable), 579 - }; 580 - 581 - static const struct drm_display_mode ili9341_dbi_mode = { 582 - DRM_SIMPLE_MODE(240, 320, 37, 49), 583 - }; 584 - 585 - DEFINE_DRM_GEM_DMA_FOPS(ili9341_dbi_fops); 586 - 587 - static struct drm_driver ili9341_dbi_driver = { 588 - .driver_features = DRIVER_GEM | DRIVER_MODESET | DRIVER_ATOMIC, 589 - .fops = &ili9341_dbi_fops, 590 - DRM_GEM_DMA_DRIVER_OPS_VMAP, 591 - .debugfs_init = mipi_dbi_debugfs_init, 592 - .name = "ili9341", 593 - .desc = "Ilitek ILI9341", 594 - .date = "20210716", 595 - .major = 1, 596 - .minor = 0, 597 - }; 598 - 599 - static int ili9341_dbi_probe(struct spi_device *spi, struct gpio_desc *dc, 600 - struct gpio_desc *reset) 601 - { 602 - struct device *dev = &spi->dev; 603 - struct mipi_dbi_dev *dbidev; 604 - struct mipi_dbi *dbi; 605 - struct drm_device *drm; 606 - struct regulator *vcc; 607 - u32 rotation = 0; 608 - int ret; 609 - 610 - vcc = devm_regulator_get_optional(dev, "vcc"); 611 - if (IS_ERR(vcc)) { 612 - dev_err(dev, "get optional vcc failed\n"); 613 - vcc = NULL; 614 - } 615 - 616 - dbidev = devm_drm_dev_alloc(dev, &ili9341_dbi_driver, 617 - struct mipi_dbi_dev, drm); 618 - if (IS_ERR(dbidev)) 619 - return PTR_ERR(dbidev); 620 - 621 - dbi = &dbidev->dbi; 622 - drm = &dbidev->drm; 623 - dbi->reset = reset; 624 - dbidev->regulator = vcc; 625 - 626 - drm_mode_config_init(drm); 627 - 628 - dbidev->backlight = devm_of_find_backlight(dev); 629 - if (IS_ERR(dbidev->backlight)) 630 - return PTR_ERR(dbidev->backlight); 631 - 632 - device_property_read_u32(dev, "rotation", &rotation); 633 - 634 - ret = mipi_dbi_spi_init(spi, dbi, dc); 635 - if (ret) 636 - return ret; 637 - 638 - ret = mipi_dbi_dev_init(dbidev, &ili9341_dbi_funcs, 639 - &ili9341_dbi_mode, rotation); 640 - if (ret) 641 - return ret; 642 - 643 - drm_mode_config_reset(drm); 644 - 645 - ret = drm_dev_register(drm, 0); 646 - if (ret) 647 - return ret; 648 - 649 - spi_set_drvdata(spi, drm); 650 - 651 - drm_fbdev_dma_setup(drm, 0); 652 - 653 - return 0; 654 - } 655 - 656 489 static int ili9341_dpi_probe(struct spi_device *spi, struct gpio_desc *dc, 657 490 struct gpio_desc *reset) 658 491 { ··· 538 711 struct device *dev = &spi->dev; 539 712 struct gpio_desc *dc; 540 713 struct gpio_desc *reset; 541 - const struct spi_device_id *id = spi_get_device_id(spi); 542 714 543 715 reset = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_HIGH); 544 716 if (IS_ERR(reset)) ··· 547 721 if (IS_ERR(dc)) 548 722 return dev_err_probe(dev, PTR_ERR(dc), "Failed to get gpio 'dc'\n"); 549 723 550 - if (!strcmp(id->name, "sf-tc240t-9370-t")) 551 - return ili9341_dpi_probe(spi, dc, reset); 552 - 553 - if (!strcmp(id->name, "yx240qv29")) 554 - return ili9341_dbi_probe(spi, dc, reset); 555 - 556 - return -ENODEV; 724 + return ili9341_dpi_probe(spi, dc, reset); 557 725 } 558 726 559 727 static void ili9341_remove(struct spi_device *spi) 560 728 { 561 - const struct spi_device_id *id = spi_get_device_id(spi); 562 729 struct ili9341 *ili = spi_get_drvdata(spi); 563 - struct drm_device *drm = spi_get_drvdata(spi); 564 730 565 - if (!strcmp(id->name, "sf-tc240t-9370-t")) { 566 - ili9341_dpi_power_off(ili); 567 - drm_panel_remove(&ili->panel); 568 - } else if (!strcmp(id->name, "yx240qv29")) { 569 - drm_dev_unplug(drm); 570 - drm_atomic_helper_shutdown(drm); 571 - } 572 - } 573 - 574 - static void ili9341_shutdown(struct spi_device *spi) 575 - { 576 - const struct spi_device_id *id = spi_get_device_id(spi); 577 - 578 - if (!strcmp(id->name, "yx240qv29")) 579 - drm_atomic_helper_shutdown(spi_get_drvdata(spi)); 731 + ili9341_dpi_power_off(ili); 732 + drm_panel_remove(&ili->panel); 580 733 } 581 734 582 735 static const struct of_device_id ili9341_of_match[] = { ··· 563 758 .compatible = "st,sf-tc240t-9370-t", 564 759 .data = &ili9341_stm32f429_disco_data, 565 760 }, 566 - { 567 - /* porting from tiny/ili9341.c 568 - * for original mipi dbi compitable 569 - */ 570 - .compatible = "adafruit,yx240qv29", 571 - .data = NULL, 572 - }, 573 761 { } 574 762 }; 575 763 MODULE_DEVICE_TABLE(of, ili9341_of_match); 576 764 577 765 static const struct spi_device_id ili9341_id[] = { 578 - { "yx240qv29", 0 }, 579 766 { "sf-tc240t-9370-t", 0 }, 580 767 { } 581 768 }; ··· 576 779 static struct spi_driver ili9341_driver = { 577 780 .probe = ili9341_probe, 578 781 .remove = ili9341_remove, 579 - .shutdown = ili9341_shutdown, 580 782 .id_table = ili9341_id, 581 783 .driver = { 582 784 .name = "panel-ilitek-ili9341",