hitachi_tx18d42vm_lcd.c 2.0 KB

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