panel-sharp-ls037v7dw01.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. /*
  2. * LCD panel driver for Sharp LS037V7DW01
  3. *
  4. * Copyright (C) 2008 Nokia Corporation
  5. * Author: Tomi Valkeinen <tomi.valkeinen@nokia.com>
  6. *
  7. * This program is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU General Public License version 2 as published by
  9. * the Free Software Foundation.
  10. *
  11. * This program is distributed in the hope that it will be useful, but WITHOUT
  12. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  14. * more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along with
  17. * this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #include <linux/module.h>
  20. #include <linux/delay.h>
  21. #include <linux/device.h>
  22. #include <linux/fb.h>
  23. #include <linux/err.h>
  24. #include <linux/slab.h>
  25. #include <linux/gpio.h>
  26. #include <video/omapdss.h>
  27. #include <video/omap-panel-data.h>
  28. static struct omap_video_timings sharp_ls_timings = {
  29. .x_res = 480,
  30. .y_res = 640,
  31. .pixel_clock = 19200,
  32. .hsw = 2,
  33. .hfp = 1,
  34. .hbp = 28,
  35. .vsw = 1,
  36. .vfp = 1,
  37. .vbp = 1,
  38. .vsync_level = OMAPDSS_SIG_ACTIVE_LOW,
  39. .hsync_level = OMAPDSS_SIG_ACTIVE_LOW,
  40. .data_pclk_edge = OMAPDSS_DRIVE_SIG_RISING_EDGE,
  41. .de_level = OMAPDSS_SIG_ACTIVE_HIGH,
  42. .sync_pclk_edge = OMAPDSS_DRIVE_SIG_OPPOSITE_EDGES,
  43. };
  44. static inline struct panel_sharp_ls037v7dw01_data
  45. *get_panel_data(const struct omap_dss_device *dssdev)
  46. {
  47. return (struct panel_sharp_ls037v7dw01_data *) dssdev->data;
  48. }
  49. static int sharp_ls_panel_probe(struct omap_dss_device *dssdev)
  50. {
  51. struct panel_sharp_ls037v7dw01_data *pd = get_panel_data(dssdev);
  52. int r;
  53. if (!pd)
  54. return -EINVAL;
  55. dssdev->panel.timings = sharp_ls_timings;
  56. if (gpio_is_valid(pd->mo_gpio)) {
  57. r = devm_gpio_request_one(&dssdev->dev, pd->mo_gpio,
  58. GPIOF_OUT_INIT_LOW, "lcd MO");
  59. if (r)
  60. return r;
  61. }
  62. if (gpio_is_valid(pd->lr_gpio)) {
  63. r = devm_gpio_request_one(&dssdev->dev, pd->lr_gpio,
  64. GPIOF_OUT_INIT_HIGH, "lcd LR");
  65. if (r)
  66. return r;
  67. }
  68. if (gpio_is_valid(pd->ud_gpio)) {
  69. r = devm_gpio_request_one(&dssdev->dev, pd->ud_gpio,
  70. GPIOF_OUT_INIT_HIGH, "lcd UD");
  71. if (r)
  72. return r;
  73. }
  74. if (gpio_is_valid(pd->resb_gpio)) {
  75. r = devm_gpio_request_one(&dssdev->dev, pd->resb_gpio,
  76. GPIOF_OUT_INIT_LOW, "lcd RESB");
  77. if (r)
  78. return r;
  79. }
  80. if (gpio_is_valid(pd->ini_gpio)) {
  81. r = devm_gpio_request_one(&dssdev->dev, pd->ini_gpio,
  82. GPIOF_OUT_INIT_LOW, "lcd INI");
  83. if (r)
  84. return r;
  85. }
  86. return 0;
  87. }
  88. static void __exit sharp_ls_panel_remove(struct omap_dss_device *dssdev)
  89. {
  90. }
  91. static int sharp_ls_power_on(struct omap_dss_device *dssdev)
  92. {
  93. struct panel_sharp_ls037v7dw01_data *pd = get_panel_data(dssdev);
  94. int r = 0;
  95. if (dssdev->state == OMAP_DSS_DISPLAY_ACTIVE)
  96. return 0;
  97. omapdss_dpi_set_timings(dssdev, &dssdev->panel.timings);
  98. omapdss_dpi_set_data_lines(dssdev, dssdev->phy.dpi.data_lines);
  99. r = omapdss_dpi_display_enable(dssdev);
  100. if (r)
  101. goto err0;
  102. /* wait couple of vsyncs until enabling the LCD */
  103. msleep(50);
  104. if (gpio_is_valid(pd->resb_gpio))
  105. gpio_set_value_cansleep(pd->resb_gpio, 1);
  106. if (gpio_is_valid(pd->ini_gpio))
  107. gpio_set_value_cansleep(pd->ini_gpio, 1);
  108. return 0;
  109. err0:
  110. return r;
  111. }
  112. static void sharp_ls_power_off(struct omap_dss_device *dssdev)
  113. {
  114. struct panel_sharp_ls037v7dw01_data *pd = get_panel_data(dssdev);
  115. if (dssdev->state != OMAP_DSS_DISPLAY_ACTIVE)
  116. return;
  117. if (gpio_is_valid(pd->ini_gpio))
  118. gpio_set_value_cansleep(pd->ini_gpio, 0);
  119. if (gpio_is_valid(pd->resb_gpio))
  120. gpio_set_value_cansleep(pd->resb_gpio, 0);
  121. /* wait at least 5 vsyncs after disabling the LCD */
  122. msleep(100);
  123. omapdss_dpi_display_disable(dssdev);
  124. }
  125. static int sharp_ls_panel_enable(struct omap_dss_device *dssdev)
  126. {
  127. int r;
  128. r = sharp_ls_power_on(dssdev);
  129. dssdev->state = OMAP_DSS_DISPLAY_ACTIVE;
  130. return r;
  131. }
  132. static void sharp_ls_panel_disable(struct omap_dss_device *dssdev)
  133. {
  134. sharp_ls_power_off(dssdev);
  135. dssdev->state = OMAP_DSS_DISPLAY_DISABLED;
  136. }
  137. static struct omap_dss_driver sharp_ls_driver = {
  138. .probe = sharp_ls_panel_probe,
  139. .remove = __exit_p(sharp_ls_panel_remove),
  140. .enable = sharp_ls_panel_enable,
  141. .disable = sharp_ls_panel_disable,
  142. .driver = {
  143. .name = "sharp_ls_panel",
  144. .owner = THIS_MODULE,
  145. },
  146. };
  147. static int __init sharp_ls_panel_drv_init(void)
  148. {
  149. return omap_dss_register_driver(&sharp_ls_driver);
  150. }
  151. static void __exit sharp_ls_panel_drv_exit(void)
  152. {
  153. omap_dss_unregister_driver(&sharp_ls_driver);
  154. }
  155. module_init(sharp_ls_panel_drv_init);
  156. module_exit(sharp_ls_panel_drv_exit);
  157. MODULE_LICENSE("GPL");