hitachi_tx18d42vm_lcd.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Hitachi tx18d42vm LVDS LCD panel driver
  4. *
  5. * (C) Copyright 2015 Hans de Goede <hdegoede@redhat.com>
  6. */
  7. #include <common.h>
  8. #include <malloc.h>
  9. #include <asm/gpio.h>
  10. #include <errno.h>
  11. /*
  12. * Very simple write only SPI support, this does not use the generic SPI infra
  13. * because that assumes R/W SPI, requiring a MISO pin. Also the necessary glue
  14. * code alone would be larger then this minimal version.
  15. */
  16. static void lcd_panel_spi_write(int cs, int clk, int mosi,
  17. unsigned int data, int bits)
  18. {
  19. int i, offset;
  20. gpio_direction_output(cs, 0);
  21. for (i = 0; i < bits; i++) {
  22. gpio_direction_output(clk, 0);
  23. offset = (bits - 1) - i;
  24. gpio_direction_output(mosi, (data >> offset) & 1);
  25. udelay(2);
  26. gpio_direction_output(clk, 1);
  27. udelay(2);
  28. }
  29. gpio_direction_output(cs, 1);
  30. udelay(2);
  31. }
  32. int hitachi_tx18d42vm_init(void)
  33. {
  34. const u16 init_data[] = {
  35. 0x0029, /* reset */
  36. 0x0025, /* standby */
  37. 0x0840, /* enable normally black */
  38. 0x0430, /* enable FRC/dither */
  39. 0x385f, /* enter test mode(1) */
  40. 0x3ca4, /* enter test mode(2) */
  41. 0x3409, /* enable SDRRS, enlarge OE width */
  42. 0x4041, /* adopt 2 line / 1 dot */
  43. };
  44. int i, cs, clk, mosi, ret = 0;
  45. cs = name_to_gpio(CONFIG_VIDEO_LCD_SPI_CS);
  46. clk = name_to_gpio(CONFIG_VIDEO_LCD_SPI_SCLK);
  47. mosi = name_to_gpio(CONFIG_VIDEO_LCD_SPI_MOSI);
  48. if (cs == -1 || clk == -1 || mosi == 1) {
  49. printf("Error tx18d42vm spi gpio config is invalid\n");
  50. return -EINVAL;
  51. }
  52. if (gpio_request(cs, "tx18d42vm-spi-cs") != 0 ||
  53. gpio_request(clk, "tx18d42vm-spi-clk") != 0 ||
  54. gpio_request(mosi, "tx18d42vm-spi-mosi") != 0) {
  55. printf("Error cannot request tx18d42vm spi gpios\n");
  56. ret = -EBUSY;
  57. goto out;
  58. }
  59. for (i = 0; i < ARRAY_SIZE(init_data); i++)
  60. lcd_panel_spi_write(cs, clk, mosi, init_data[i], 16);
  61. mdelay(50); /* All the tx18d42vm drivers have a delay here ? */
  62. lcd_panel_spi_write(cs, clk, mosi, 0x00ad, 16); /* display on */
  63. out:
  64. gpio_free(mosi);
  65. gpio_free(clk);
  66. gpio_free(cs);
  67. return ret;
  68. }