lcd_2430sdp.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. /*
  2. * LCD panel support for the TI 2430SDP board
  3. *
  4. * Copyright (C) 2007 MontaVista
  5. * Author: Hunyue Yau <hyau@mvista.com>
  6. *
  7. * Derived from drivers/video/omap/lcd-apollon.c
  8. *
  9. * This program is free software; you can redistribute it and/or modify it
  10. * under the terms of the GNU General Public License as published by the
  11. * Free Software Foundation; either version 2 of the License, or (at your
  12. * option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful, but
  15. * WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License along
  20. * with this program; if not, write to the Free Software Foundation, Inc.,
  21. * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  22. */
  23. #include <linux/module.h>
  24. #include <linux/platform_device.h>
  25. #include <linux/delay.h>
  26. #include <linux/gpio.h>
  27. #include <linux/i2c/twl4030.h>
  28. #include <mach/mux.h>
  29. #include <mach/omapfb.h>
  30. #include <asm/mach-types.h>
  31. #define SDP2430_LCD_PANEL_BACKLIGHT_GPIO 91
  32. #define SDP2430_LCD_PANEL_ENABLE_GPIO 154
  33. #define SDP3430_LCD_PANEL_BACKLIGHT_GPIO 24
  34. #define SDP3430_LCD_PANEL_ENABLE_GPIO 28
  35. static unsigned backlight_gpio;
  36. static unsigned enable_gpio;
  37. #define LCD_PANEL_BACKLIGHT_GPIO 91
  38. #define LCD_PANEL_ENABLE_GPIO 154
  39. #define LCD_PIXCLOCK_MAX 5400 /* freq 5.4 MHz */
  40. #define PM_RECEIVER TWL4030_MODULE_PM_RECEIVER
  41. #define ENABLE_VAUX2_DEDICATED 0x09
  42. #define ENABLE_VAUX2_DEV_GRP 0x20
  43. #define t2_out(c, r, v) twl4030_i2c_write_u8(c, r, v)
  44. static int sdp2430_panel_init(struct lcd_panel *panel,
  45. struct omapfb_device *fbdev)
  46. {
  47. if (machine_is_omap_3430sdp()) {
  48. enable_gpio = SDP3430_LCD_PANEL_ENABLE_GPIO;
  49. backlight_gpio = SDP3430_LCD_PANEL_BACKLIGHT_GPIO;
  50. } else {
  51. enable_gpio = SDP2430_LCD_PANEL_ENABLE_GPIO;
  52. backlight_gpio = SDP2430_LCD_PANEL_BACKLIGHT_GPIO;
  53. }
  54. gpio_request(enable_gpio, "LCD enable"); /* LCD panel */
  55. gpio_request(backlight_gpio, "LCD bl"); /* LCD backlight */
  56. gpio_direction_output(enable_gpio, 0);
  57. gpio_direction_output(backlight_gpio, 0);
  58. return 0;
  59. }
  60. static void sdp2430_panel_cleanup(struct lcd_panel *panel)
  61. {
  62. gpio_free(backlight_gpio);
  63. gpio_free(enable_gpio);
  64. }
  65. static int sdp2430_panel_enable(struct lcd_panel *panel)
  66. {
  67. u8 ded_val, ded_reg;
  68. u8 grp_val, grp_reg;
  69. if (machine_is_omap_3430sdp()) {
  70. ded_reg = TWL4030_VAUX3_DEDICATED;
  71. ded_val = ENABLE_VAUX3_DEDICATED;
  72. grp_reg = TWL4030_VAUX3_DEV_GRP;
  73. grp_val = ENABLE_VAUX3_DEV_GRP;
  74. if (omap_rev() > OMAP3430_REV_ES1_0) {
  75. t2_out(PM_RECEIVER, ENABLE_VPLL2_DEDICATED,
  76. TWL4030_VPLL2_DEDICATED);
  77. t2_out(PM_RECEIVER, ENABLE_VPLL2_DEV_GRP,
  78. TWL4030_VPLL2_DEV_GRP);
  79. }
  80. } else {
  81. ded_reg = TWL4030_VAUX2_DEDICATED;
  82. ded_val = ENABLE_VAUX2_DEDICATED;
  83. grp_reg = TWL4030_VAUX2_DEV_GRP;
  84. grp_val = ENABLE_VAUX2_DEV_GRP;
  85. }
  86. gpio_set_value(enable_gpio, 1);
  87. gpio_set_value(backlight_gpio, 1);
  88. if (0 != t2_out(PM_RECEIVER, ded_val, ded_reg))
  89. return -EIO;
  90. if (0 != t2_out(PM_RECEIVER, grp_val, grp_reg))
  91. return -EIO;
  92. return 0;
  93. }
  94. static void sdp2430_panel_disable(struct lcd_panel *panel)
  95. {
  96. gpio_set_value(enable_gpio, 0);
  97. gpio_set_value(backlight_gpio, 0);
  98. if (omap_rev() > OMAP3430_REV_ES1_0) {
  99. t2_out(PM_RECEIVER, 0x0, TWL4030_VPLL2_DEDICATED);
  100. t2_out(PM_RECEIVER, 0x0, TWL4030_VPLL2_DEV_GRP);
  101. msleep(4);
  102. }
  103. }
  104. static unsigned long sdp2430_panel_get_caps(struct lcd_panel *panel)
  105. {
  106. return 0;
  107. }
  108. struct lcd_panel sdp2430_panel = {
  109. .name = "sdp2430",
  110. .config = OMAP_LCDC_PANEL_TFT | OMAP_LCDC_INV_VSYNC |
  111. OMAP_LCDC_INV_HSYNC,
  112. .bpp = 16,
  113. .data_lines = 16,
  114. .x_res = 240,
  115. .y_res = 320,
  116. .hsw = 3, /* hsync_len (4) - 1 */
  117. .hfp = 3, /* right_margin (4) - 1 */
  118. .hbp = 39, /* left_margin (40) - 1 */
  119. .vsw = 1, /* vsync_len (2) - 1 */
  120. .vfp = 2, /* lower_margin */
  121. .vbp = 7, /* upper_margin (8) - 1 */
  122. .pixel_clock = LCD_PIXCLOCK_MAX,
  123. .init = sdp2430_panel_init,
  124. .cleanup = sdp2430_panel_cleanup,
  125. .enable = sdp2430_panel_enable,
  126. .disable = sdp2430_panel_disable,
  127. .get_caps = sdp2430_panel_get_caps,
  128. };
  129. static int sdp2430_panel_probe(struct platform_device *pdev)
  130. {
  131. omapfb_register_panel(&sdp2430_panel);
  132. return 0;
  133. }
  134. static int sdp2430_panel_remove(struct platform_device *pdev)
  135. {
  136. return 0;
  137. }
  138. static int sdp2430_panel_suspend(struct platform_device *pdev,
  139. pm_message_t mesg)
  140. {
  141. return 0;
  142. }
  143. static int sdp2430_panel_resume(struct platform_device *pdev)
  144. {
  145. return 0;
  146. }
  147. struct platform_driver sdp2430_panel_driver = {
  148. .probe = sdp2430_panel_probe,
  149. .remove = sdp2430_panel_remove,
  150. .suspend = sdp2430_panel_suspend,
  151. .resume = sdp2430_panel_resume,
  152. .driver = {
  153. .name = "sdp2430_lcd",
  154. .owner = THIS_MODULE,
  155. },
  156. };
  157. static int __init sdp2430_panel_drv_init(void)
  158. {
  159. return platform_driver_register(&sdp2430_panel_driver);
  160. }
  161. static void __exit sdp2430_panel_drv_exit(void)
  162. {
  163. platform_driver_unregister(&sdp2430_panel_driver);
  164. }
  165. module_init(sdp2430_panel_drv_init);
  166. module_exit(sdp2430_panel_drv_exit);