lcd_2430sdp.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  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/twl.h>
  28. #include <plat/mux.h>
  29. #include <asm/mach-types.h>
  30. #include "omapfb.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_PIXCLOCK_MAX 5400 /* freq 5.4 MHz */
  38. #define PM_RECEIVER TWL4030_MODULE_PM_RECEIVER
  39. #define ENABLE_VAUX2_DEDICATED 0x09
  40. #define ENABLE_VAUX2_DEV_GRP 0x20
  41. #define ENABLE_VAUX3_DEDICATED 0x03
  42. #define ENABLE_VAUX3_DEV_GRP 0x20
  43. #define ENABLE_VPLL2_DEDICATED 0x05
  44. #define ENABLE_VPLL2_DEV_GRP 0xE0
  45. #define TWL4030_VPLL2_DEV_GRP 0x33
  46. #define TWL4030_VPLL2_DEDICATED 0x36
  47. #define t2_out(c, r, v) twl_i2c_write_u8(c, r, v)
  48. static int sdp2430_panel_init(struct lcd_panel *panel,
  49. struct omapfb_device *fbdev)
  50. {
  51. if (machine_is_omap_3430sdp()) {
  52. enable_gpio = SDP3430_LCD_PANEL_ENABLE_GPIO;
  53. backlight_gpio = SDP3430_LCD_PANEL_BACKLIGHT_GPIO;
  54. } else {
  55. enable_gpio = SDP2430_LCD_PANEL_ENABLE_GPIO;
  56. backlight_gpio = SDP2430_LCD_PANEL_BACKLIGHT_GPIO;
  57. }
  58. gpio_request(enable_gpio, "LCD enable"); /* LCD panel */
  59. gpio_request(backlight_gpio, "LCD bl"); /* LCD backlight */
  60. gpio_direction_output(enable_gpio, 0);
  61. gpio_direction_output(backlight_gpio, 0);
  62. return 0;
  63. }
  64. static void sdp2430_panel_cleanup(struct lcd_panel *panel)
  65. {
  66. gpio_free(backlight_gpio);
  67. gpio_free(enable_gpio);
  68. }
  69. static int sdp2430_panel_enable(struct lcd_panel *panel)
  70. {
  71. u8 ded_val, ded_reg;
  72. u8 grp_val, grp_reg;
  73. if (machine_is_omap_3430sdp()) {
  74. ded_reg = TWL4030_VAUX3_DEDICATED;
  75. ded_val = ENABLE_VAUX3_DEDICATED;
  76. grp_reg = TWL4030_VAUX3_DEV_GRP;
  77. grp_val = ENABLE_VAUX3_DEV_GRP;
  78. if (omap_rev() > OMAP3430_REV_ES1_0) {
  79. t2_out(PM_RECEIVER, ENABLE_VPLL2_DEDICATED,
  80. TWL4030_VPLL2_DEDICATED);
  81. t2_out(PM_RECEIVER, ENABLE_VPLL2_DEV_GRP,
  82. TWL4030_VPLL2_DEV_GRP);
  83. }
  84. } else {
  85. ded_reg = TWL4030_VAUX2_DEDICATED;
  86. ded_val = ENABLE_VAUX2_DEDICATED;
  87. grp_reg = TWL4030_VAUX2_DEV_GRP;
  88. grp_val = ENABLE_VAUX2_DEV_GRP;
  89. }
  90. gpio_set_value(enable_gpio, 1);
  91. gpio_set_value(backlight_gpio, 1);
  92. if (0 != t2_out(PM_RECEIVER, ded_val, ded_reg))
  93. return -EIO;
  94. if (0 != t2_out(PM_RECEIVER, grp_val, grp_reg))
  95. return -EIO;
  96. return 0;
  97. }
  98. static void sdp2430_panel_disable(struct lcd_panel *panel)
  99. {
  100. gpio_set_value(enable_gpio, 0);
  101. gpio_set_value(backlight_gpio, 0);
  102. if (omap_rev() > OMAP3430_REV_ES1_0) {
  103. t2_out(PM_RECEIVER, 0x0, TWL4030_VPLL2_DEDICATED);
  104. t2_out(PM_RECEIVER, 0x0, TWL4030_VPLL2_DEV_GRP);
  105. msleep(4);
  106. }
  107. }
  108. static unsigned long sdp2430_panel_get_caps(struct lcd_panel *panel)
  109. {
  110. return 0;
  111. }
  112. struct lcd_panel sdp2430_panel = {
  113. .name = "sdp2430",
  114. .config = OMAP_LCDC_PANEL_TFT | OMAP_LCDC_INV_VSYNC |
  115. OMAP_LCDC_INV_HSYNC,
  116. .bpp = 16,
  117. .data_lines = 16,
  118. .x_res = 240,
  119. .y_res = 320,
  120. .hsw = 3, /* hsync_len (4) - 1 */
  121. .hfp = 3, /* right_margin (4) - 1 */
  122. .hbp = 39, /* left_margin (40) - 1 */
  123. .vsw = 1, /* vsync_len (2) - 1 */
  124. .vfp = 2, /* lower_margin */
  125. .vbp = 7, /* upper_margin (8) - 1 */
  126. .pixel_clock = LCD_PIXCLOCK_MAX,
  127. .init = sdp2430_panel_init,
  128. .cleanup = sdp2430_panel_cleanup,
  129. .enable = sdp2430_panel_enable,
  130. .disable = sdp2430_panel_disable,
  131. .get_caps = sdp2430_panel_get_caps,
  132. };
  133. static int sdp2430_panel_probe(struct platform_device *pdev)
  134. {
  135. omapfb_register_panel(&sdp2430_panel);
  136. return 0;
  137. }
  138. static int sdp2430_panel_remove(struct platform_device *pdev)
  139. {
  140. return 0;
  141. }
  142. static int sdp2430_panel_suspend(struct platform_device *pdev,
  143. pm_message_t mesg)
  144. {
  145. return 0;
  146. }
  147. static int sdp2430_panel_resume(struct platform_device *pdev)
  148. {
  149. return 0;
  150. }
  151. struct platform_driver sdp2430_panel_driver = {
  152. .probe = sdp2430_panel_probe,
  153. .remove = sdp2430_panel_remove,
  154. .suspend = sdp2430_panel_suspend,
  155. .resume = sdp2430_panel_resume,
  156. .driver = {
  157. .name = "sdp2430_lcd",
  158. .owner = THIS_MODULE,
  159. },
  160. };
  161. static int __init sdp2430_panel_drv_init(void)
  162. {
  163. return platform_driver_register(&sdp2430_panel_driver);
  164. }
  165. static void __exit sdp2430_panel_drv_exit(void)
  166. {
  167. platform_driver_unregister(&sdp2430_panel_driver);
  168. }
  169. module_init(sdp2430_panel_drv_init);
  170. module_exit(sdp2430_panel_drv_exit);