lms283gf05.c 4.3 KB

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