lcdc_gordon.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458
  1. /* Copyright (c) 2009-2010, 2012 The Linux Foundation. All rights reserved.
  2. *
  3. * This program is free software; you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License version 2 and
  5. * only version 2 as published by the Free Software Foundation.
  6. *
  7. * This program is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. * GNU General Public License for more details.
  11. *
  12. */
  13. #include <linux/delay.h>
  14. #include <linux/gpio.h>
  15. #include "msm_fb.h"
  16. /* registers */
  17. #define GORDON_REG_NOP 0x00
  18. #define GORDON_REG_IMGCTL1 0x10
  19. #define GORDON_REG_IMGCTL2 0x11
  20. #define GORDON_REG_IMGSET1 0x12
  21. #define GORDON_REG_IMGSET2 0x13
  22. #define GORDON_REG_IVBP1 0x14
  23. #define GORDON_REG_IHBP1 0x15
  24. #define GORDON_REG_IVNUM1 0x16
  25. #define GORDON_REG_IHNUM1 0x17
  26. #define GORDON_REG_IVBP2 0x18
  27. #define GORDON_REG_IHBP2 0x19
  28. #define GORDON_REG_IVNUM2 0x1A
  29. #define GORDON_REG_IHNUM2 0x1B
  30. #define GORDON_REG_LCDIFCTL1 0x30
  31. #define GORDON_REG_VALTRAN 0x31
  32. #define GORDON_REG_AVCTL 0x33
  33. #define GORDON_REG_LCDIFCTL2 0x34
  34. #define GORDON_REG_LCDIFCTL3 0x35
  35. #define GORDON_REG_LCDIFSET1 0x36
  36. #define GORDON_REG_PCCTL 0x3C
  37. #define GORDON_REG_TPARAM1 0x40
  38. #define GORDON_REG_TLCDIF1 0x41
  39. #define GORDON_REG_TSSPB_ST1 0x42
  40. #define GORDON_REG_TSSPB_ED1 0x43
  41. #define GORDON_REG_TSCK_ST1 0x44
  42. #define GORDON_REG_TSCK_WD1 0x45
  43. #define GORDON_REG_TGSPB_VST1 0x46
  44. #define GORDON_REG_TGSPB_VED1 0x47
  45. #define GORDON_REG_TGSPB_CH1 0x48
  46. #define GORDON_REG_TGCK_ST1 0x49
  47. #define GORDON_REG_TGCK_ED1 0x4A
  48. #define GORDON_REG_TPCTL_ST1 0x4B
  49. #define GORDON_REG_TPCTL_ED1 0x4C
  50. #define GORDON_REG_TPCHG_ED1 0x4D
  51. #define GORDON_REG_TCOM_CH1 0x4E
  52. #define GORDON_REG_THBP1 0x4F
  53. #define GORDON_REG_TPHCTL1 0x50
  54. #define GORDON_REG_EVPH1 0x51
  55. #define GORDON_REG_EVPL1 0x52
  56. #define GORDON_REG_EVNH1 0x53
  57. #define GORDON_REG_EVNL1 0x54
  58. #define GORDON_REG_TBIAS1 0x55
  59. #define GORDON_REG_TPARAM2 0x56
  60. #define GORDON_REG_TLCDIF2 0x57
  61. #define GORDON_REG_TSSPB_ST2 0x58
  62. #define GORDON_REG_TSSPB_ED2 0x59
  63. #define GORDON_REG_TSCK_ST2 0x5A
  64. #define GORDON_REG_TSCK_WD2 0x5B
  65. #define GORDON_REG_TGSPB_VST2 0x5C
  66. #define GORDON_REG_TGSPB_VED2 0x5D
  67. #define GORDON_REG_TGSPB_CH2 0x5E
  68. #define GORDON_REG_TGCK_ST2 0x5F
  69. #define GORDON_REG_TGCK_ED2 0x60
  70. #define GORDON_REG_TPCTL_ST2 0x61
  71. #define GORDON_REG_TPCTL_ED2 0x62
  72. #define GORDON_REG_TPCHG_ED2 0x63
  73. #define GORDON_REG_TCOM_CH2 0x64
  74. #define GORDON_REG_THBP2 0x65
  75. #define GORDON_REG_TPHCTL2 0x66
  76. #define GORDON_REG_POWCTL 0x80
  77. static int lcdc_gordon_panel_off(struct platform_device *pdev);
  78. static int spi_cs;
  79. static int spi_sclk;
  80. static int spi_sdo;
  81. static int spi_sdi;
  82. static int spi_dac;
  83. static int bl_level;
  84. static unsigned char bit_shift[8] = { (1 << 7), /* MSB */
  85. (1 << 6),
  86. (1 << 5),
  87. (1 << 4),
  88. (1 << 3),
  89. (1 << 2),
  90. (1 << 1),
  91. (1 << 0) /* LSB */
  92. };
  93. struct gordon_state_type{
  94. boolean disp_initialized;
  95. boolean display_on;
  96. boolean disp_powered_up;
  97. };
  98. static struct gordon_state_type gordon_state = { 0 };
  99. static struct msm_panel_common_pdata *lcdc_gordon_pdata;
  100. static void serigo(uint16 reg, uint8 data)
  101. {
  102. unsigned int tx_val = ((0x00FF & reg) << 8) | data;
  103. unsigned char i, val = 0;
  104. /* Enable the Chip Select */
  105. gpio_set_value(spi_cs, 1);
  106. udelay(33);
  107. /* Transmit it in two parts, Higher Byte first, then Lower Byte */
  108. val = (unsigned char)((tx_val & 0xFF00) >> 8);
  109. /* Clock should be Low before entering ! */
  110. for (i = 0; i < 8; i++) {
  111. /* #1: Drive the Data (High or Low) */
  112. if (val & bit_shift[i])
  113. gpio_set_value(spi_sdi, 1);
  114. else
  115. gpio_set_value(spi_sdi, 0);
  116. /* #2: Drive the Clk High and then Low */
  117. udelay(33);
  118. gpio_set_value(spi_sclk, 1);
  119. udelay(33);
  120. gpio_set_value(spi_sclk, 0);
  121. }
  122. /* Idle state of SDO (MOSI) is Low */
  123. gpio_set_value(spi_sdi, 0);
  124. /* ..then Lower Byte */
  125. val = (uint8) (tx_val & 0x00FF);
  126. /* Before we enter here the Clock should be Low ! */
  127. for (i = 0; i < 8; i++) {
  128. /* #1: Drive the Data (High or Low) */
  129. if (val & bit_shift[i])
  130. gpio_set_value(spi_sdi, 1);
  131. else
  132. gpio_set_value(spi_sdi, 0);
  133. /* #2: Drive the Clk High and then Low */
  134. udelay(33);
  135. gpio_set_value(spi_sclk, 1);
  136. udelay(33);
  137. gpio_set_value(spi_sclk, 0);
  138. }
  139. /* Idle state of SDO (MOSI) is Low */
  140. gpio_set_value(spi_sdi, 0);
  141. /* Now Disable the Chip Select */
  142. udelay(33);
  143. gpio_set_value(spi_cs, 0);
  144. }
  145. static void spi_init(void)
  146. {
  147. /* Setting the Default GPIO's */
  148. spi_sclk = *(lcdc_gordon_pdata->gpio_num);
  149. spi_cs = *(lcdc_gordon_pdata->gpio_num + 1);
  150. spi_sdi = *(lcdc_gordon_pdata->gpio_num + 2);
  151. spi_sdo = *(lcdc_gordon_pdata->gpio_num + 3);
  152. /* Set the output so that we dont disturb the slave device */
  153. gpio_set_value(spi_sclk, 0);
  154. gpio_set_value(spi_sdi, 0);
  155. /* Set the Chip Select De-asserted */
  156. gpio_set_value(spi_cs, 0);
  157. }
  158. static void gordon_disp_powerup(void)
  159. {
  160. if (!gordon_state.disp_powered_up && !gordon_state.display_on) {
  161. /* Reset the hardware first */
  162. /* Include DAC power up implementation here */
  163. gordon_state.disp_powered_up = TRUE;
  164. }
  165. }
  166. static void gordon_init(void)
  167. {
  168. /* Image interface settings */
  169. serigo(GORDON_REG_IMGCTL2, 0x00);
  170. serigo(GORDON_REG_IMGSET1, 0x00);
  171. /* Exchange the RGB signal for J510(Softbank mobile) */
  172. serigo(GORDON_REG_IMGSET2, 0x12);
  173. serigo(GORDON_REG_LCDIFSET1, 0x00);
  174. /* Pre-charge settings */
  175. serigo(GORDON_REG_PCCTL, 0x09);
  176. serigo(GORDON_REG_LCDIFCTL2, 0x7B);
  177. mdelay(1);
  178. }
  179. static void gordon_disp_on(void)
  180. {
  181. if (gordon_state.disp_powered_up && !gordon_state.display_on) {
  182. gordon_init();
  183. mdelay(20);
  184. /* gordon_dispmode setting */
  185. serigo(GORDON_REG_TPARAM1, 0x30);
  186. serigo(GORDON_REG_TLCDIF1, 0x00);
  187. serigo(GORDON_REG_TSSPB_ST1, 0x8B);
  188. serigo(GORDON_REG_TSSPB_ED1, 0x93);
  189. serigo(GORDON_REG_TSCK_ST1, 0x88);
  190. serigo(GORDON_REG_TSCK_WD1, 0x00);
  191. serigo(GORDON_REG_TGSPB_VST1, 0x01);
  192. serigo(GORDON_REG_TGSPB_VED1, 0x02);
  193. serigo(GORDON_REG_TGSPB_CH1, 0x5E);
  194. serigo(GORDON_REG_TGCK_ST1, 0x80);
  195. serigo(GORDON_REG_TGCK_ED1, 0x3C);
  196. serigo(GORDON_REG_TPCTL_ST1, 0x50);
  197. serigo(GORDON_REG_TPCTL_ED1, 0x74);
  198. serigo(GORDON_REG_TPCHG_ED1, 0x78);
  199. serigo(GORDON_REG_TCOM_CH1, 0x50);
  200. serigo(GORDON_REG_THBP1, 0x84);
  201. serigo(GORDON_REG_TPHCTL1, 0x00);
  202. serigo(GORDON_REG_EVPH1, 0x70);
  203. serigo(GORDON_REG_EVPL1, 0x64);
  204. serigo(GORDON_REG_EVNH1, 0x56);
  205. serigo(GORDON_REG_EVNL1, 0x48);
  206. serigo(GORDON_REG_TBIAS1, 0x88);
  207. /* QVGA settings */
  208. serigo(GORDON_REG_TPARAM2, 0x28);
  209. serigo(GORDON_REG_TLCDIF2, 0x14);
  210. serigo(GORDON_REG_TSSPB_ST2, 0x49);
  211. serigo(GORDON_REG_TSSPB_ED2, 0x4B);
  212. serigo(GORDON_REG_TSCK_ST2, 0x4A);
  213. serigo(GORDON_REG_TSCK_WD2, 0x02);
  214. serigo(GORDON_REG_TGSPB_VST2, 0x02);
  215. serigo(GORDON_REG_TGSPB_VED2, 0x03);
  216. serigo(GORDON_REG_TGSPB_CH2, 0x2F);
  217. serigo(GORDON_REG_TGCK_ST2, 0x40);
  218. serigo(GORDON_REG_TGCK_ED2, 0x1E);
  219. serigo(GORDON_REG_TPCTL_ST2, 0x2C);
  220. serigo(GORDON_REG_TPCTL_ED2, 0x3A);
  221. serigo(GORDON_REG_TPCHG_ED2, 0x3C);
  222. serigo(GORDON_REG_TCOM_CH2, 0x28);
  223. serigo(GORDON_REG_THBP2, 0x4D);
  224. serigo(GORDON_REG_TPHCTL2, 0x1A);
  225. /* VGA settings */
  226. serigo(GORDON_REG_IVBP1, 0x02);
  227. serigo(GORDON_REG_IHBP1, 0x90);
  228. serigo(GORDON_REG_IVNUM1, 0xA0);
  229. serigo(GORDON_REG_IHNUM1, 0x78);
  230. /* QVGA settings */
  231. serigo(GORDON_REG_IVBP2, 0x02);
  232. serigo(GORDON_REG_IHBP2, 0x48);
  233. serigo(GORDON_REG_IVNUM2, 0x50);
  234. serigo(GORDON_REG_IHNUM2, 0x3C);
  235. /* Gordon Charge pump settings and ON */
  236. serigo(GORDON_REG_POWCTL, 0x03);
  237. mdelay(15);
  238. serigo(GORDON_REG_POWCTL, 0x07);
  239. mdelay(15);
  240. serigo(GORDON_REG_POWCTL, 0x0F);
  241. mdelay(15);
  242. serigo(GORDON_REG_AVCTL, 0x03);
  243. mdelay(15);
  244. serigo(GORDON_REG_POWCTL, 0x1F);
  245. mdelay(15);
  246. serigo(GORDON_REG_POWCTL, 0x5F);
  247. mdelay(15);
  248. serigo(GORDON_REG_POWCTL, 0x7F);
  249. mdelay(15);
  250. serigo(GORDON_REG_LCDIFCTL1, 0x02);
  251. mdelay(15);
  252. serigo(GORDON_REG_IMGCTL1, 0x00);
  253. mdelay(15);
  254. serigo(GORDON_REG_LCDIFCTL3, 0x00);
  255. mdelay(15);
  256. serigo(GORDON_REG_VALTRAN, 0x01);
  257. mdelay(15);
  258. serigo(GORDON_REG_LCDIFCTL1, 0x03);
  259. mdelay(1);
  260. gordon_state.display_on = TRUE;
  261. }
  262. }
  263. static int lcdc_gordon_panel_on(struct platform_device *pdev)
  264. {
  265. if (!gordon_state.disp_initialized) {
  266. /* Configure reset GPIO that drives DAC */
  267. lcdc_gordon_pdata->panel_config_gpio(1);
  268. spi_dac = *(lcdc_gordon_pdata->gpio_num + 4);
  269. gpio_set_value(spi_dac, 0);
  270. udelay(15);
  271. gpio_set_value(spi_dac, 1);
  272. spi_init(); /* LCD needs SPI */
  273. gordon_disp_powerup();
  274. gordon_disp_on();
  275. if (bl_level <= 1) {
  276. /* keep back light OFF */
  277. serigo(GORDON_REG_LCDIFCTL2, 0x0B);
  278. udelay(15);
  279. serigo(GORDON_REG_VALTRAN, 0x01);
  280. } else {
  281. /* keep back light ON */
  282. serigo(GORDON_REG_LCDIFCTL2, 0x7B);
  283. udelay(15);
  284. serigo(GORDON_REG_VALTRAN, 0x01);
  285. }
  286. gordon_state.disp_initialized = TRUE;
  287. }
  288. return 0;
  289. }
  290. static int lcdc_gordon_panel_off(struct platform_device *pdev)
  291. {
  292. if (gordon_state.disp_powered_up && gordon_state.display_on) {
  293. serigo(GORDON_REG_LCDIFCTL2, 0x7B);
  294. serigo(GORDON_REG_VALTRAN, 0x01);
  295. serigo(GORDON_REG_LCDIFCTL1, 0x02);
  296. serigo(GORDON_REG_LCDIFCTL3, 0x01);
  297. mdelay(20);
  298. serigo(GORDON_REG_VALTRAN, 0x01);
  299. serigo(GORDON_REG_IMGCTL1, 0x01);
  300. serigo(GORDON_REG_LCDIFCTL1, 0x00);
  301. mdelay(20);
  302. serigo(GORDON_REG_POWCTL, 0x1F);
  303. mdelay(40);
  304. serigo(GORDON_REG_POWCTL, 0x07);
  305. mdelay(40);
  306. serigo(GORDON_REG_POWCTL, 0x03);
  307. mdelay(40);
  308. serigo(GORDON_REG_POWCTL, 0x00);
  309. mdelay(40);
  310. lcdc_gordon_pdata->panel_config_gpio(0);
  311. gordon_state.display_on = FALSE;
  312. gordon_state.disp_initialized = FALSE;
  313. }
  314. return 0;
  315. }
  316. static void lcdc_gordon_set_backlight(struct msm_fb_data_type *mfd)
  317. {
  318. bl_level = mfd->bl_level;
  319. if (gordon_state.disp_initialized) {
  320. if (bl_level <= 1) {
  321. /* keep back light OFF */
  322. serigo(GORDON_REG_LCDIFCTL2, 0x0B);
  323. udelay(15);
  324. serigo(GORDON_REG_VALTRAN, 0x01);
  325. } else {
  326. /* keep back light ON */
  327. serigo(GORDON_REG_LCDIFCTL2, 0x7B);
  328. udelay(15);
  329. serigo(GORDON_REG_VALTRAN, 0x01);
  330. }
  331. }
  332. }
  333. static int __devinit gordon_probe(struct platform_device *pdev)
  334. {
  335. if (pdev->id == 0) {
  336. lcdc_gordon_pdata = pdev->dev.platform_data;
  337. return 0;
  338. }
  339. msm_fb_add_device(pdev);
  340. return 0;
  341. }
  342. static struct platform_driver this_driver = {
  343. .probe = gordon_probe,
  344. .driver = {
  345. .name = "lcdc_gordon_vga",
  346. },
  347. };
  348. static struct msm_fb_panel_data gordon_panel_data = {
  349. .on = lcdc_gordon_panel_on,
  350. .off = lcdc_gordon_panel_off,
  351. .set_backlight = lcdc_gordon_set_backlight,
  352. };
  353. static struct platform_device this_device = {
  354. .name = "lcdc_gordon_vga",
  355. .id = 1,
  356. .dev = {
  357. .platform_data = &gordon_panel_data,
  358. }
  359. };
  360. static int __init lcdc_gordon_panel_init(void)
  361. {
  362. int ret;
  363. struct msm_panel_info *pinfo;
  364. #ifdef CONFIG_FB_MSM_TRY_MDDI_CATCH_LCDC_PRISM
  365. if (msm_fb_detect_client("lcdc_gordon_vga"))
  366. return 0;
  367. #endif
  368. ret = platform_driver_register(&this_driver);
  369. if (ret)
  370. return ret;
  371. pinfo = &gordon_panel_data.panel_info;
  372. pinfo->xres = 480;
  373. pinfo->yres = 640;
  374. MSM_FB_SINGLE_MODE_PANEL(pinfo);
  375. pinfo->type = LCDC_PANEL;
  376. pinfo->pdest = DISPLAY_1;
  377. pinfo->wait_cycle = 0;
  378. pinfo->bpp = 24;
  379. pinfo->fb_num = 2;
  380. pinfo->clk_rate = 24500000;
  381. pinfo->bl_max = 4;
  382. pinfo->bl_min = 1;
  383. pinfo->lcdc.h_back_porch = 84;
  384. pinfo->lcdc.h_front_porch = 33;
  385. pinfo->lcdc.h_pulse_width = 60;
  386. pinfo->lcdc.v_back_porch = 0;
  387. pinfo->lcdc.v_front_porch = 2;
  388. pinfo->lcdc.v_pulse_width = 2;
  389. pinfo->lcdc.border_clr = 0; /* blk */
  390. pinfo->lcdc.underflow_clr = 0xff; /* blue */
  391. pinfo->lcdc.hsync_skew = 0;
  392. ret = platform_device_register(&this_device);
  393. if (ret)
  394. platform_driver_unregister(&this_driver);
  395. return ret;
  396. }
  397. module_init(lcdc_gordon_panel_init);