lcd_sx1.c 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  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. gpio_set_value(_A_LCD_SSC_A0, 0);
  74. mdelay(2);
  75. gpio_set_value(A_LCD_SSC_RD, 1);
  76. gpio_set_value(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. gpio_set_value(A_LCD_SSC_SD, shifter & byte);
  82. OMAP_MCBSP_WRITE(OMAP1510_MCBSP3_BASE, PCR0, 0x2202);
  83. shifter >>= 1;
  84. }
  85. gpio_set_value(_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. gpio_request(A_LCD_SSC_RD, "lcd_ssc_rd");
  96. gpio_request(A_LCD_SSC_SD, "lcd_ssc_sd");
  97. gpio_request(_A_LCD_RESET, "lcd_reset");
  98. gpio_request(_A_LCD_SSC_CS, "lcd_ssc_cs");
  99. gpio_request(_A_LCD_SSC_A0, "lcd_ssc_a0");
  100. /* set GPIOs to output, with initial data */
  101. gpio_direction_output(A_LCD_SSC_RD, 1);
  102. gpio_direction_output(A_LCD_SSC_SD, 0);
  103. gpio_direction_output(_A_LCD_RESET, 0);
  104. gpio_direction_output(_A_LCD_SSC_CS, 1);
  105. gpio_direction_output(_A_LCD_SSC_A0, 1);
  106. }
  107. static void display_init(void)
  108. {
  109. int i;
  110. omap_cfg_reg(MCBSP3_CLKX);
  111. mdelay(2);
  112. setup_GPIO();
  113. mdelay(2);
  114. /* reset LCD */
  115. gpio_set_value(A_LCD_SSC_SD, 1);
  116. epson_sendbyte(0, 0x25);
  117. gpio_set_value(_A_LCD_RESET, 0);
  118. mdelay(10);
  119. gpio_set_value(_A_LCD_RESET, 1);
  120. gpio_set_value(_A_LCD_SSC_CS, 1);
  121. mdelay(2);
  122. gpio_set_value(_A_LCD_SSC_CS, 0);
  123. /* init LCD, phase 1 */
  124. epson_sendbyte(0, 0xCA);
  125. for (i = 0; i < 10; i++)
  126. epson_sendbyte(1, INIT_1[i]);
  127. gpio_set_value(_A_LCD_SSC_CS, 1);
  128. gpio_set_value(_A_LCD_SSC_CS, 0);
  129. /* init LCD phase 2 */
  130. epson_sendbyte(0, 0xCB);
  131. for (i = 0; i < 125; i++)
  132. epson_sendbyte(1, INIT_2[i]);
  133. gpio_set_value(_A_LCD_SSC_CS, 1);
  134. gpio_set_value(_A_LCD_SSC_CS, 0);
  135. /* init LCD phase 2a */
  136. epson_sendbyte(0, 0xCC);
  137. for (i = 0; i < 14; i++)
  138. epson_sendbyte(1, INIT_3[i]);
  139. gpio_set_value(_A_LCD_SSC_CS, 1);
  140. gpio_set_value(_A_LCD_SSC_CS, 0);
  141. /* init LCD phase 3 */
  142. epson_sendbyte(0, 0xBC);
  143. epson_sendbyte(1, 0x08);
  144. gpio_set_value(_A_LCD_SSC_CS, 1);
  145. gpio_set_value(_A_LCD_SSC_CS, 0);
  146. /* init LCD phase 4 */
  147. epson_sendbyte(0, 0x07);
  148. epson_sendbyte(1, 0x05);
  149. gpio_set_value(_A_LCD_SSC_CS, 1);
  150. gpio_set_value(_A_LCD_SSC_CS, 0);
  151. /* init LCD phase 5 */
  152. epson_sendbyte(0, 0x94);
  153. gpio_set_value(_A_LCD_SSC_CS, 1);
  154. gpio_set_value(_A_LCD_SSC_CS, 0);
  155. /* init LCD phase 6 */
  156. epson_sendbyte(0, 0xC6);
  157. epson_sendbyte(1, 0x80);
  158. gpio_set_value(_A_LCD_SSC_CS, 1);
  159. mdelay(100); /* used to be 1000 */
  160. gpio_set_value(_A_LCD_SSC_CS, 0);
  161. /* init LCD phase 7 */
  162. epson_sendbyte(0, 0x16);
  163. epson_sendbyte(1, 0x02);
  164. epson_sendbyte(1, 0x00);
  165. epson_sendbyte(1, 0xB1);
  166. epson_sendbyte(1, 0x00);
  167. gpio_set_value(_A_LCD_SSC_CS, 1);
  168. gpio_set_value(_A_LCD_SSC_CS, 0);
  169. /* init LCD phase 8 */
  170. epson_sendbyte(0, 0x76);
  171. epson_sendbyte(1, 0x00);
  172. epson_sendbyte(1, 0x00);
  173. epson_sendbyte(1, 0xDB);
  174. epson_sendbyte(1, 0x00);
  175. gpio_set_value(_A_LCD_SSC_CS, 1);
  176. gpio_set_value(_A_LCD_SSC_CS, 0);
  177. /* init LCD phase 9 */
  178. epson_sendbyte(0, 0xAF);
  179. gpio_set_value(_A_LCD_SSC_CS, 1);
  180. }
  181. static int sx1_panel_init(struct lcd_panel *panel, struct omapfb_device *fbdev)
  182. {
  183. return 0;
  184. }
  185. static void sx1_panel_cleanup(struct lcd_panel *panel)
  186. {
  187. }
  188. static void sx1_panel_disable(struct lcd_panel *panel)
  189. {
  190. printk(KERN_INFO "SX1: LCD panel disable\n");
  191. sx1_setmmipower(0);
  192. gpio_set_value(_A_LCD_SSC_CS, 1);
  193. epson_sendbyte(0, 0x25);
  194. gpio_set_value(_A_LCD_SSC_CS, 0);
  195. epson_sendbyte(0, 0xAE);
  196. gpio_set_value(_A_LCD_SSC_CS, 1);
  197. mdelay(100);
  198. gpio_set_value(_A_LCD_SSC_CS, 0);
  199. epson_sendbyte(0, 0x95);
  200. gpio_set_value(_A_LCD_SSC_CS, 1);
  201. }
  202. static int sx1_panel_enable(struct lcd_panel *panel)
  203. {
  204. printk(KERN_INFO "lcd_sx1: LCD panel enable\n");
  205. init_system();
  206. display_init();
  207. sx1_setmmipower(1);
  208. sx1_setbacklight(0x18);
  209. sx1_setkeylight (0x06);
  210. return 0;
  211. }
  212. static unsigned long sx1_panel_get_caps(struct lcd_panel *panel)
  213. {
  214. return 0;
  215. }
  216. struct lcd_panel sx1_panel = {
  217. .name = "sx1",
  218. .config = OMAP_LCDC_PANEL_TFT | OMAP_LCDC_INV_VSYNC |
  219. OMAP_LCDC_INV_HSYNC | OMAP_LCDC_INV_PIX_CLOCK |
  220. OMAP_LCDC_INV_OUTPUT_EN,
  221. .x_res = 176,
  222. .y_res = 220,
  223. .data_lines = 16,
  224. .bpp = 16,
  225. .hsw = 5,
  226. .hfp = 5,
  227. .hbp = 5,
  228. .vsw = 2,
  229. .vfp = 1,
  230. .vbp = 1,
  231. .pixel_clock = 1500,
  232. .init = sx1_panel_init,
  233. .cleanup = sx1_panel_cleanup,
  234. .enable = sx1_panel_enable,
  235. .disable = sx1_panel_disable,
  236. .get_caps = sx1_panel_get_caps,
  237. };
  238. static int sx1_panel_probe(struct platform_device *pdev)
  239. {
  240. omapfb_register_panel(&sx1_panel);
  241. return 0;
  242. }
  243. static int sx1_panel_remove(struct platform_device *pdev)
  244. {
  245. return 0;
  246. }
  247. static int sx1_panel_suspend(struct platform_device *pdev, pm_message_t mesg)
  248. {
  249. return 0;
  250. }
  251. static int sx1_panel_resume(struct platform_device *pdev)
  252. {
  253. return 0;
  254. }
  255. struct platform_driver sx1_panel_driver = {
  256. .probe = sx1_panel_probe,
  257. .remove = sx1_panel_remove,
  258. .suspend = sx1_panel_suspend,
  259. .resume = sx1_panel_resume,
  260. .driver = {
  261. .name = "lcd_sx1",
  262. .owner = THIS_MODULE,
  263. },
  264. };
  265. static int sx1_panel_drv_init(void)
  266. {
  267. return platform_driver_register(&sx1_panel_driver);
  268. }
  269. static void sx1_panel_drv_cleanup(void)
  270. {
  271. platform_driver_unregister(&sx1_panel_driver);
  272. }
  273. module_init(sx1_panel_drv_init);
  274. module_exit(sx1_panel_drv_cleanup);