lms283gf05.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * lms283gf05.c -- support for Samsung LMS283GF05 LCD
  4. *
  5. * Copyright (c) 2009 Marek Vasut <marek.vasut@gmail.com>
  6. */
  7. #include <linux/device.h>
  8. #include <linux/kernel.h>
  9. #include <linux/delay.h>
  10. #include <linux/slab.h>
  11. #include <linux/gpio/consumer.h>
  12. #include <linux/lcd.h>
  13. #include <linux/spi/spi.h>
  14. #include <linux/module.h>
  15. struct lms283gf05_state {
  16. struct spi_device *spi;
  17. struct lcd_device *ld;
  18. struct gpio_desc *reset;
  19. };
  20. struct lms283gf05_seq {
  21. unsigned char reg;
  22. unsigned short value;
  23. unsigned char delay;
  24. };
  25. /* Magic sequences supplied by manufacturer, for details refer to datasheet */
  26. static const struct lms283gf05_seq disp_initseq[] = {
  27. /* REG, VALUE, DELAY */
  28. { 0x07, 0x0000, 0 },
  29. { 0x13, 0x0000, 10 },
  30. { 0x11, 0x3004, 0 },
  31. { 0x14, 0x200F, 0 },
  32. { 0x10, 0x1a20, 0 },
  33. { 0x13, 0x0040, 50 },
  34. { 0x13, 0x0060, 0 },
  35. { 0x13, 0x0070, 200 },
  36. { 0x01, 0x0127, 0 },
  37. { 0x02, 0x0700, 0 },
  38. { 0x03, 0x1030, 0 },
  39. { 0x08, 0x0208, 0 },
  40. { 0x0B, 0x0620, 0 },
  41. { 0x0C, 0x0110, 0 },
  42. { 0x30, 0x0120, 0 },
  43. { 0x31, 0x0127, 0 },
  44. { 0x32, 0x0000, 0 },
  45. { 0x33, 0x0503, 0 },
  46. { 0x34, 0x0727, 0 },
  47. { 0x35, 0x0124, 0 },
  48. { 0x36, 0x0706, 0 },
  49. { 0x37, 0x0701, 0 },
  50. { 0x38, 0x0F00, 0 },
  51. { 0x39, 0x0F00, 0 },
  52. { 0x40, 0x0000, 0 },
  53. { 0x41, 0x0000, 0 },
  54. { 0x42, 0x013f, 0 },
  55. { 0x43, 0x0000, 0 },
  56. { 0x44, 0x013f, 0 },
  57. { 0x45, 0x0000, 0 },
  58. { 0x46, 0xef00, 0 },
  59. { 0x47, 0x013f, 0 },
  60. { 0x48, 0x0000, 0 },
  61. { 0x07, 0x0015, 30 },
  62. { 0x07, 0x0017, 0 },
  63. { 0x20, 0x0000, 0 },
  64. { 0x21, 0x0000, 0 },
  65. { 0x22, 0x0000, 0 }
  66. };
  67. static const struct lms283gf05_seq disp_pdwnseq[] = {
  68. { 0x07, 0x0016, 30 },
  69. { 0x07, 0x0004, 0 },
  70. { 0x10, 0x0220, 20 },
  71. { 0x13, 0x0060, 50 },
  72. { 0x13, 0x0040, 50 },
  73. { 0x13, 0x0000, 0 },
  74. { 0x10, 0x0000, 0 }
  75. };
  76. static void lms283gf05_reset(struct gpio_desc *gpiod)
  77. {
  78. gpiod_set_value(gpiod, 0); /* De-asserted */
  79. mdelay(100);
  80. gpiod_set_value(gpiod, 1); /* Asserted */
  81. mdelay(20);
  82. gpiod_set_value(gpiod, 0); /* De-asserted */
  83. mdelay(20);
  84. }
  85. static void lms283gf05_toggle(struct spi_device *spi,
  86. const struct lms283gf05_seq *seq, int sz)
  87. {
  88. char buf[3];
  89. int i;
  90. for (i = 0; i < sz; i++) {
  91. buf[0] = 0x74;
  92. buf[1] = 0x00;
  93. buf[2] = seq[i].reg;
  94. spi_write(spi, buf, 3);
  95. buf[0] = 0x76;
  96. buf[1] = seq[i].value >> 8;
  97. buf[2] = seq[i].value & 0xff;
  98. spi_write(spi, buf, 3);
  99. mdelay(seq[i].delay);
  100. }
  101. }
  102. static int lms283gf05_power_set(struct lcd_device *ld, int power)
  103. {
  104. struct lms283gf05_state *st = lcd_get_data(ld);
  105. struct spi_device *spi = st->spi;
  106. if (power <= FB_BLANK_NORMAL) {
  107. if (st->reset)
  108. lms283gf05_reset(st->reset);
  109. lms283gf05_toggle(spi, disp_initseq, ARRAY_SIZE(disp_initseq));
  110. } else {
  111. lms283gf05_toggle(spi, disp_pdwnseq, ARRAY_SIZE(disp_pdwnseq));
  112. if (st->reset)
  113. gpiod_set_value(st->reset, 1); /* Asserted */
  114. }
  115. return 0;
  116. }
  117. static const struct lcd_ops lms_ops = {
  118. .set_power = lms283gf05_power_set,
  119. .get_power = NULL,
  120. };
  121. static int lms283gf05_probe(struct spi_device *spi)
  122. {
  123. struct lms283gf05_state *st;
  124. struct lcd_device *ld;
  125. st = devm_kzalloc(&spi->dev, sizeof(struct lms283gf05_state),
  126. GFP_KERNEL);
  127. if (st == NULL)
  128. return -ENOMEM;
  129. st->reset = gpiod_get_optional(&spi->dev, "reset", GPIOD_OUT_LOW);
  130. if (IS_ERR(st->reset))
  131. return PTR_ERR(st->reset);
  132. gpiod_set_consumer_name(st->reset, "LMS283GF05 RESET");
  133. ld = devm_lcd_device_register(&spi->dev, "lms283gf05", &spi->dev, st,
  134. &lms_ops);
  135. if (IS_ERR(ld))
  136. return PTR_ERR(ld);
  137. st->spi = spi;
  138. st->ld = ld;
  139. spi_set_drvdata(spi, st);
  140. /* kick in the LCD */
  141. if (st->reset)
  142. lms283gf05_reset(st->reset);
  143. lms283gf05_toggle(spi, disp_initseq, ARRAY_SIZE(disp_initseq));
  144. return 0;
  145. }
  146. static struct spi_driver lms283gf05_driver = {
  147. .driver = {
  148. .name = "lms283gf05",
  149. },
  150. .probe = lms283gf05_probe,
  151. };
  152. module_spi_driver(lms283gf05_driver);
  153. MODULE_AUTHOR("Marek Vasut <marek.vasut@gmail.com>");
  154. MODULE_DESCRIPTION("LCD283GF05 LCD");
  155. MODULE_LICENSE("GPL v2");