hitachi_tx18d42vm_lcd.c 2.0 KB

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