lcd_sx1.c 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  1. /*
  2. * LCD panel support for the Siemens SX1 mobile phone
  3. *
  4. * Current version : Vovan888@gmail.com, great help from FCA00000
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License as published by the
  8. * Free Software Foundation; either version 2 of the License, or (at your
  9. * option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along
  17. * with this program; if not, write to the Free Software Foundation, Inc.,
  18. * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  19. */
  20. #include <linux/module.h>
  21. #include <linux/platform_device.h>
  22. #include <linux/delay.h>
  23. #include <linux/io.h>
  24. #include <mach/gpio.h>
  25. #include <mach/omapfb.h>
  26. #include <mach/mcbsp.h>
  27. #include <mach/mux.h>
  28. /*
  29. * OMAP310 GPIO registers
  30. */
  31. #define GPIO_DATA_INPUT 0xfffce000
  32. #define GPIO_DATA_OUTPUT 0xfffce004
  33. #define GPIO_DIR_CONTROL 0xfffce008
  34. #define GPIO_INT_CONTROL 0xfffce00c
  35. #define GPIO_INT_MASK 0xfffce010
  36. #define GPIO_INT_STATUS 0xfffce014
  37. #define GPIO_PIN_CONTROL 0xfffce018
  38. #define A_LCD_SSC_RD 3
  39. #define A_LCD_SSC_SD 7
  40. #define _A_LCD_RESET 9
  41. #define _A_LCD_SSC_CS 12
  42. #define _A_LCD_SSC_A0 13
  43. #define DSP_REG 0xE1017024
  44. const unsigned char INIT_1[12] = {
  45. 0x1C, 0x02, 0x88, 0x00, 0x1E, 0xE0, 0x00, 0xDC, 0x00, 0x02, 0x00
  46. };
  47. const unsigned char INIT_2[127] = {
  48. 0x15, 0x00, 0x29, 0x00, 0x3E, 0x00, 0x51, 0x00,
  49. 0x65, 0x00, 0x7A, 0x00, 0x8D, 0x00, 0xA1, 0x00,
  50. 0xB6, 0x00, 0xC7, 0x00, 0xD8, 0x00, 0xEB, 0x00,
  51. 0xFB, 0x00, 0x0B, 0x01, 0x1B, 0x01, 0x27, 0x01,
  52. 0x34, 0x01, 0x41, 0x01, 0x4C, 0x01, 0x55, 0x01,
  53. 0x5F, 0x01, 0x68, 0x01, 0x70, 0x01, 0x78, 0x01,
  54. 0x7E, 0x01, 0x86, 0x01, 0x8C, 0x01, 0x94, 0x01,
  55. 0x9B, 0x01, 0xA1, 0x01, 0xA4, 0x01, 0xA9, 0x01,
  56. 0xAD, 0x01, 0xB2, 0x01, 0xB7, 0x01, 0xBC, 0x01,
  57. 0xC0, 0x01, 0xC4, 0x01, 0xC8, 0x01, 0xCB, 0x01,
  58. 0xCF, 0x01, 0xD2, 0x01, 0xD5, 0x01, 0xD8, 0x01,
  59. 0xDB, 0x01, 0xE0, 0x01, 0xE3, 0x01, 0xE6, 0x01,
  60. 0xE8, 0x01, 0xEB, 0x01, 0xEE, 0x01, 0xF1, 0x01,
  61. 0xF3, 0x01, 0xF8, 0x01, 0xF9, 0x01, 0xFC, 0x01,
  62. 0x00, 0x02, 0x03, 0x02, 0x07, 0x02, 0x09, 0x02,
  63. 0x0E, 0x02, 0x13, 0x02, 0x1C, 0x02, 0x00
  64. };
  65. const unsigned char INIT_3[15] = {
  66. 0x14, 0x26, 0x33, 0x3D, 0x45, 0x4D, 0x53, 0x59,
  67. 0x5E, 0x63, 0x67, 0x6D, 0x71, 0x78, 0xFF
  68. };
  69. static void epson_sendbyte(int flag, unsigned char byte)
  70. {
  71. int i, shifter = 0x80;
  72. if (!flag)
  73. omap_set_gpio_dataout(_A_LCD_SSC_A0, 0);
  74. mdelay(2);
  75. omap_set_gpio_dataout(A_LCD_SSC_RD, 1);
  76. omap_set_gpio_dataout(A_LCD_SSC_SD, flag);
  77. OMAP_MCBSP_WRITE(OMAP1510_MCBSP3_BASE, PCR0, 0x2200);
  78. OMAP_MCBSP_WRITE(OMAP1510_MCBSP3_BASE, PCR0, 0x2202);
  79. for (i = 0; i < 8; i++) {
  80. OMAP_MCBSP_WRITE(OMAP1510_MCBSP3_BASE, PCR0, 0x2200);
  81. omap_set_gpio_dataout(A_LCD_SSC_SD, shifter & byte);
  82. OMAP_MCBSP_WRITE(OMAP1510_MCBSP3_BASE, PCR0, 0x2202);
  83. shifter >>= 1;
  84. }
  85. omap_set_gpio_dataout(_A_LCD_SSC_A0, 1);
  86. }
  87. static void init_system(void)
  88. {
  89. omap_mcbsp_request(OMAP_MCBSP3);
  90. omap_mcbsp_stop(OMAP_MCBSP3);
  91. }
  92. static void setup_GPIO(void)
  93. {
  94. /* new wave */
  95. omap_request_gpio(A_LCD_SSC_RD);
  96. omap_request_gpio(A_LCD_SSC_SD);
  97. omap_request_gpio(_A_LCD_RESET);
  98. omap_request_gpio(_A_LCD_SSC_CS);
  99. omap_request_gpio(_A_LCD_SSC_A0);
  100. /* set all GPIOs to output */
  101. omap_set_gpio_direction(A_LCD_SSC_RD, 0);
  102. omap_set_gpio_direction(A_LCD_SSC_SD, 0);
  103. omap_set_gpio_direction(_A_LCD_RESET, 0);
  104. omap_set_gpio_direction(_A_LCD_SSC_CS, 0);
  105. omap_set_gpio_direction(_A_LCD_SSC_A0, 0);
  106. /* set GPIO data */
  107. omap_set_gpio_dataout(A_LCD_SSC_RD, 1);
  108. omap_set_gpio_dataout(A_LCD_SSC_SD, 0);
  109. omap_set_gpio_dataout(_A_LCD_RESET, 0);
  110. omap_set_gpio_dataout(_A_LCD_SSC_CS, 1);
  111. omap_set_gpio_dataout(_A_LCD_SSC_A0, 1);
  112. }
  113. static void display_init(void)
  114. {
  115. int i;
  116. omap_cfg_reg(MCBSP3_CLKX);
  117. mdelay(2);
  118. setup_GPIO();
  119. mdelay(2);
  120. /* reset LCD */
  121. omap_set_gpio_dataout(A_LCD_SSC_SD, 1);
  122. epson_sendbyte(0, 0x25);
  123. omap_set_gpio_dataout(_A_LCD_RESET, 0);
  124. mdelay(10);
  125. omap_set_gpio_dataout(_A_LCD_RESET, 1);
  126. omap_set_gpio_dataout(_A_LCD_SSC_CS, 1);
  127. mdelay(2);
  128. omap_set_gpio_dataout(_A_LCD_SSC_CS, 0);
  129. /* init LCD, phase 1 */
  130. epson_sendbyte(0, 0xCA);
  131. for (i = 0; i < 10; i++)
  132. epson_sendbyte(1, INIT_1[i]);
  133. omap_set_gpio_dataout(_A_LCD_SSC_CS, 1);
  134. omap_set_gpio_dataout(_A_LCD_SSC_CS, 0);
  135. /* init LCD phase 2 */
  136. epson_sendbyte(0, 0xCB);
  137. for (i = 0; i < 125; i++)
  138. epson_sendbyte(1, INIT_2[i]);
  139. omap_set_gpio_dataout(_A_LCD_SSC_CS, 1);
  140. omap_set_gpio_dataout(_A_LCD_SSC_CS, 0);
  141. /* init LCD phase 2a */
  142. epson_sendbyte(0, 0xCC);
  143. for (i = 0; i < 14; i++)
  144. epson_sendbyte(1, INIT_3[i]);
  145. omap_set_gpio_dataout(_A_LCD_SSC_CS, 1);
  146. omap_set_gpio_dataout(_A_LCD_SSC_CS, 0);
  147. /* init LCD phase 3 */
  148. epson_sendbyte(0, 0xBC);
  149. epson_sendbyte(1, 0x08);
  150. omap_set_gpio_dataout(_A_LCD_SSC_CS, 1);
  151. omap_set_gpio_dataout(_A_LCD_SSC_CS, 0);
  152. /* init LCD phase 4 */
  153. epson_sendbyte(0, 0x07);
  154. epson_sendbyte(1, 0x05);
  155. omap_set_gpio_dataout(_A_LCD_SSC_CS, 1);
  156. omap_set_gpio_dataout(_A_LCD_SSC_CS, 0);
  157. /* init LCD phase 5 */
  158. epson_sendbyte(0, 0x94);
  159. omap_set_gpio_dataout(_A_LCD_SSC_CS, 1);
  160. omap_set_gpio_dataout(_A_LCD_SSC_CS, 0);
  161. /* init LCD phase 6 */
  162. epson_sendbyte(0, 0xC6);
  163. epson_sendbyte(1, 0x80);
  164. omap_set_gpio_dataout(_A_LCD_SSC_CS, 1);
  165. mdelay(100); /* used to be 1000 */
  166. omap_set_gpio_dataout(_A_LCD_SSC_CS, 0);
  167. /* init LCD phase 7 */
  168. epson_sendbyte(0, 0x16);
  169. epson_sendbyte(1, 0x02);
  170. epson_sendbyte(1, 0x00);
  171. epson_sendbyte(1, 0xB1);
  172. epson_sendbyte(1, 0x00);
  173. omap_set_gpio_dataout(_A_LCD_SSC_CS, 1);
  174. omap_set_gpio_dataout(_A_LCD_SSC_CS, 0);
  175. /* init LCD phase 8 */
  176. epson_sendbyte(0, 0x76);
  177. epson_sendbyte(1, 0x00);
  178. epson_sendbyte(1, 0x00);
  179. epson_sendbyte(1, 0xDB);
  180. epson_sendbyte(1, 0x00);
  181. omap_set_gpio_dataout(_A_LCD_SSC_CS, 1);
  182. omap_set_gpio_dataout(_A_LCD_SSC_CS, 0);
  183. /* init LCD phase 9 */
  184. epson_sendbyte(0, 0xAF);
  185. omap_set_gpio_dataout(_A_LCD_SSC_CS, 1);
  186. }
  187. static int sx1_panel_init(struct lcd_panel *panel, struct omapfb_device *fbdev)
  188. {
  189. return 0;
  190. }
  191. static void sx1_panel_cleanup(struct lcd_panel *panel)
  192. {
  193. }
  194. static void sx1_panel_disable(struct lcd_panel *panel)
  195. {
  196. printk(KERN_INFO "SX1: LCD panel disable\n");
  197. sx1_setmmipower(0);
  198. omap_set_gpio_dataout(_A_LCD_SSC_CS, 1);
  199. epson_sendbyte(0, 0x25);
  200. omap_set_gpio_dataout(_A_LCD_SSC_CS, 0);
  201. epson_sendbyte(0, 0xAE);
  202. omap_set_gpio_dataout(_A_LCD_SSC_CS, 1);
  203. mdelay(100);
  204. omap_set_gpio_dataout(_A_LCD_SSC_CS, 0);
  205. epson_sendbyte(0, 0x95);
  206. omap_set_gpio_dataout(_A_LCD_SSC_CS, 1);
  207. }
  208. static int sx1_panel_enable(struct lcd_panel *panel)
  209. {
  210. printk(KERN_INFO "lcd_sx1: LCD panel enable\n");
  211. init_system();
  212. display_init();
  213. sx1_setmmipower(1);
  214. sx1_setbacklight(0x18);
  215. sx1_setkeylight (0x06);
  216. return 0;
  217. }
  218. static unsigned long sx1_panel_get_caps(struct lcd_panel *panel)
  219. {
  220. return 0;
  221. }
  222. struct lcd_panel sx1_panel = {
  223. .name = "sx1",
  224. .config = OMAP_LCDC_PANEL_TFT | OMAP_LCDC_INV_VSYNC |
  225. OMAP_LCDC_INV_HSYNC | OMAP_LCDC_INV_PIX_CLOCK |
  226. OMAP_LCDC_INV_OUTPUT_EN,
  227. .x_res = 176,
  228. .y_res = 220,
  229. .data_lines = 16,
  230. .bpp = 16,
  231. .hsw = 5,
  232. .hfp = 5,
  233. .hbp = 5,
  234. .vsw = 2,
  235. .vfp = 1,
  236. .vbp = 1,
  237. .pixel_clock = 1500,
  238. .init = sx1_panel_init,
  239. .cleanup = sx1_panel_cleanup,
  240. .enable = sx1_panel_enable,
  241. .disable = sx1_panel_disable,
  242. .get_caps = sx1_panel_get_caps,
  243. };
  244. static int sx1_panel_probe(struct platform_device *pdev)
  245. {
  246. omapfb_register_panel(&sx1_panel);
  247. return 0;
  248. }
  249. static int sx1_panel_remove(struct platform_device *pdev)
  250. {
  251. return 0;
  252. }
  253. static int sx1_panel_suspend(struct platform_device *pdev, pm_message_t mesg)
  254. {
  255. return 0;
  256. }
  257. static int sx1_panel_resume(struct platform_device *pdev)
  258. {
  259. return 0;
  260. }
  261. struct platform_driver sx1_panel_driver = {
  262. .probe = sx1_panel_probe,
  263. .remove = sx1_panel_remove,
  264. .suspend = sx1_panel_suspend,
  265. .resume = sx1_panel_resume,
  266. .driver = {
  267. .name = "lcd_sx1",
  268. .owner = THIS_MODULE,
  269. },
  270. };
  271. static int sx1_panel_drv_init(void)
  272. {
  273. return platform_driver_register(&sx1_panel_driver);
  274. }
  275. static void sx1_panel_drv_cleanup(void)
  276. {
  277. platform_driver_unregister(&sx1_panel_driver);
  278. }
  279. module_init(sx1_panel_drv_init);
  280. module_exit(sx1_panel_drv_cleanup);