lcdc_truly_ips3p2335.c 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  1. /* Copyright (c) 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/module.h>
  15. #include <linux/gpio.h>
  16. #include <mach/pmic.h>
  17. #include "msm_fb.h"
  18. static int prev_bl = 17;
  19. static int spi_cs;
  20. static int spi_sclk;
  21. static int spi_mosi;
  22. static int gpio_backlight_en;
  23. static int gpio_display_reset;
  24. struct truly_state_type {
  25. boolean disp_initialized;
  26. boolean display_on;
  27. boolean disp_powered_up;
  28. };
  29. static struct truly_state_type truly_state = { 0 };
  30. static struct msm_panel_common_pdata *lcdc_truly_pdata;
  31. static char init_item_v1[] = { 0xff, 0x83, 0x57, };
  32. static char init_item_v2[] = { 0x03, };
  33. static char init_item_v3[] = { 0x00, 0x13, 0x1C, 0x1C, 0x83, 0x48, };
  34. static char init_item_v4[] = { 0x43, 0x06, 0x06, 0x06, };
  35. static char init_item_v5[] = { 0x53, };
  36. static char init_item_v6[] = { 0x02, 0x40, 0x00, 0x2a, 0x2a, 0x0d, 0x3f, };
  37. static char init_item_v7[] = { 0x70, 0x50, 0x01, 0x3c, 0xe8, 0x08, };
  38. static char init_item_v8[] = { 0x17, 0x0f, };
  39. static char init_item_v9[] = { 0x60};
  40. static char init_item_v10[] = { 0x00, 0x13, 0x1a, 0x29, 0x2d, 0x41, 0x49,
  41. 0x52, 0x48, 0x41, 0x3c, 0x33, 0x30, 0x1c,
  42. 0x19, 0x03, 0x00, 0x13, 0x1a, 0x29, 0x2d,
  43. 0x41, 0x49, 0x52, 0x48, 0x41, 0x3c, 0x33,
  44. 0x31, 0x1c, 0x19, 0x03, 0x00, 0x01,
  45. };
  46. static char init_item_v11[] = { 0x40, };
  47. static inline void truly_spi_write_byte(char dc, uint8 data)
  48. {
  49. uint32 bit;
  50. int bnum;
  51. gpio_set_value_cansleep(spi_sclk, 0); /* clk low */
  52. /* dc: 0 for command, 1 for parameter */
  53. gpio_set_value_cansleep(spi_mosi, dc);
  54. udelay(1); /* at least 20 ns */
  55. gpio_set_value_cansleep(spi_sclk, 1); /* clk high */
  56. udelay(1); /* at least 20 ns */
  57. bnum = 8; /* 8 data bits */
  58. bit = 0x80;
  59. while (bnum) {
  60. gpio_set_value_cansleep(spi_sclk, 0); /* clk low */
  61. if (data & bit)
  62. gpio_set_value_cansleep(spi_mosi, 1);
  63. else
  64. gpio_set_value_cansleep(spi_mosi, 0);
  65. udelay(1);
  66. gpio_set_value_cansleep(spi_sclk, 1); /* clk high */
  67. udelay(1);
  68. bit >>= 1;
  69. bnum--;
  70. }
  71. }
  72. static inline int truly_spi_write(char cmd, char *data, int num)
  73. {
  74. int i;
  75. gpio_set_value_cansleep(spi_cs, 0); /* cs low */
  76. /* command byte first */
  77. truly_spi_write_byte(0, cmd);
  78. /* followed by parameter bytes */
  79. for (i = 0; i < num; i++) {
  80. if (data)
  81. truly_spi_write_byte(1, data[i]);
  82. }
  83. gpio_set_value_cansleep(spi_mosi, 1); /* mosi high */
  84. gpio_set_value_cansleep(spi_cs, 1); /* cs high */
  85. udelay(10);
  86. return 0;
  87. }
  88. static void spi_pin_assign(void)
  89. {
  90. /* Setting the Default GPIO's */
  91. spi_mosi = *(lcdc_truly_pdata->gpio_num);
  92. spi_sclk = *(lcdc_truly_pdata->gpio_num + 1);
  93. spi_cs = *(lcdc_truly_pdata->gpio_num + 2);
  94. gpio_backlight_en = *(lcdc_truly_pdata->gpio_num + 3);
  95. gpio_display_reset = *(lcdc_truly_pdata->gpio_num + 4);
  96. pr_debug("spi_mosi:%d spi_sclk:%d spi_cs:%d backlight:%d reset:%d\n",
  97. spi_mosi, spi_sclk, spi_cs, gpio_backlight_en,
  98. gpio_display_reset);
  99. }
  100. static void truly_disp_powerup(void)
  101. {
  102. /* Reset the hardware first */
  103. /* Include DAC power up implementation here */
  104. if (!truly_state.disp_powered_up && !truly_state.display_on)
  105. truly_state.disp_powered_up = TRUE;
  106. }
  107. static void truly_disp_reginit(void)
  108. {
  109. pr_debug("%s disp_powered_up:%d display_on:%d\n", __func__,
  110. truly_state.disp_powered_up, truly_state.display_on);
  111. if (truly_state.disp_powered_up && !truly_state.display_on) {
  112. gpio_set_value_cansleep(spi_cs, 1); /* cs high */
  113. truly_spi_write(0xb9, init_item_v1, sizeof(init_item_v1));
  114. msleep(20);
  115. truly_spi_write(0xcc, init_item_v2, sizeof(init_item_v2));
  116. truly_spi_write(0xb1, init_item_v3, sizeof(init_item_v3));
  117. truly_spi_write(0xb3, init_item_v4, sizeof(init_item_v4));
  118. truly_spi_write(0xb6, init_item_v5, sizeof(init_item_v5));
  119. truly_spi_write(0xb4, init_item_v6, sizeof(init_item_v6));
  120. truly_spi_write(0xc0, init_item_v7, sizeof(init_item_v7));
  121. truly_spi_write(0xe3, init_item_v8, sizeof(init_item_v8));
  122. truly_spi_write(0x3a, init_item_v9, sizeof(init_item_v9));
  123. truly_spi_write(0xe0, init_item_v10, sizeof(init_item_v10));
  124. truly_spi_write(0x36, init_item_v11, sizeof(init_item_v11));
  125. truly_spi_write(0x11, NULL, 0);
  126. msleep(150);
  127. truly_spi_write(0x29, NULL, 0);
  128. msleep(25);
  129. truly_state.display_on = TRUE;
  130. }
  131. }
  132. static int lcdc_truly_panel_on(struct platform_device *pdev)
  133. {
  134. struct msm_fb_data_type *mfd = platform_get_drvdata(pdev);
  135. if (!mfd->cont_splash_done) {
  136. mfd->cont_splash_done = 1;
  137. return 0;
  138. }
  139. /* Configure reset GPIO that drives DAC */
  140. if (lcdc_truly_pdata->panel_config_gpio)
  141. lcdc_truly_pdata->panel_config_gpio(1);
  142. gpio_set_value_cansleep(gpio_display_reset, 1);
  143. truly_disp_powerup();
  144. truly_disp_reginit();
  145. truly_state.disp_initialized = TRUE;
  146. return 0;
  147. }
  148. static int lcdc_truly_panel_off(struct platform_device *pdev)
  149. {
  150. if (truly_state.disp_powered_up && truly_state.display_on) {
  151. /* Main panel power off (Pull down reset) */
  152. gpio_set_value_cansleep(gpio_display_reset, 0);
  153. truly_state.display_on = FALSE;
  154. truly_state.disp_initialized = FALSE;
  155. }
  156. return 0;
  157. }
  158. static void lcdc_truly_set_backlight(struct msm_fb_data_type *mfd)
  159. {
  160. int step = 0, i = 0;
  161. unsigned long flags;
  162. int bl_level = mfd->bl_level;
  163. /* real backlight level, 1 - max, 16 - min, 17 - off */
  164. bl_level = 17 - bl_level;
  165. if (bl_level > prev_bl) {
  166. step = bl_level - prev_bl;
  167. if (bl_level == 17)
  168. step--;
  169. } else if (bl_level < prev_bl) {
  170. step = bl_level + 16 - prev_bl;
  171. } else {
  172. pr_info("%s: no change\n", __func__);
  173. return;
  174. }
  175. if (bl_level == 17) {
  176. /* turn off backlight */
  177. gpio_set_value(gpio_backlight_en, 0);
  178. } else {
  179. local_irq_save(flags);
  180. if (prev_bl == 17) {
  181. /* turn on backlight */
  182. gpio_set_value(gpio_backlight_en, 1);
  183. udelay(30);
  184. }
  185. /* adjust backlight level */
  186. for (i = 0; i < step; i++) {
  187. gpio_set_value(gpio_backlight_en, 0);
  188. udelay(1);
  189. gpio_set_value(gpio_backlight_en, 1);
  190. udelay(1);
  191. }
  192. local_irq_restore(flags);
  193. }
  194. msleep(20);
  195. prev_bl = bl_level;
  196. return;
  197. }
  198. static int __devinit truly_probe(struct platform_device *pdev)
  199. {
  200. if (pdev->id == 0) {
  201. lcdc_truly_pdata = pdev->dev.platform_data;
  202. if (!lcdc_truly_pdata)
  203. pr_err("%s pdata is null\n", __func__);
  204. spi_pin_assign();
  205. return 0;
  206. }
  207. msm_fb_add_device(pdev);
  208. return 0;
  209. }
  210. static struct platform_driver this_driver = {
  211. .probe = truly_probe,
  212. .driver = {
  213. .name = "lcdc_truly_hvga_ips3p2335_pt",
  214. },
  215. };
  216. static struct msm_fb_panel_data truly_panel_data = {
  217. .on = lcdc_truly_panel_on,
  218. .off = lcdc_truly_panel_off,
  219. .set_backlight = lcdc_truly_set_backlight,
  220. };
  221. static struct platform_device this_device = {
  222. .name = "lcdc_truly_hvga_ips3p2335_pt",
  223. .id = 1,
  224. .dev = {
  225. .platform_data = &truly_panel_data,
  226. }
  227. };
  228. static int __init lcdc_truly_panel_init(void)
  229. {
  230. int ret;
  231. struct msm_panel_info *pinfo;
  232. ret = msm_fb_detect_client("lcdc_truly_hvga_ips3p2335_pt");
  233. if (ret)
  234. return 0;
  235. ret = platform_driver_register(&this_driver);
  236. if (ret) {
  237. pr_err("%s() driver registration failed", __func__);
  238. return ret;
  239. }
  240. pinfo = &truly_panel_data.panel_info;
  241. pinfo->xres = 320;
  242. pinfo->yres = 480;
  243. MSM_FB_SINGLE_MODE_PANEL(pinfo);
  244. pinfo->type = LCDC_PANEL;
  245. pinfo->pdest = DISPLAY_1;
  246. pinfo->wait_cycle = 0;
  247. pinfo->bpp = 18;
  248. pinfo->fb_num = 2;
  249. /* 10Mhz mdp_lcdc_pclk and mdp_lcdc_pad_pcl */
  250. pinfo->clk_rate = 10240000;
  251. pinfo->bl_max = 16;
  252. pinfo->bl_min = 1;
  253. pinfo->lcdc.h_back_porch = 16; /* hsw = 8 + hbp=16 */
  254. pinfo->lcdc.h_front_porch = 4;
  255. pinfo->lcdc.h_pulse_width = 8;
  256. pinfo->lcdc.v_back_porch = 7; /* vsw=1 + vbp = 7 */
  257. pinfo->lcdc.v_front_porch = 3;
  258. pinfo->lcdc.v_pulse_width = 1;
  259. pinfo->lcdc.border_clr = 0; /* blk */
  260. pinfo->lcdc.underflow_clr = 0xff; /* blue */
  261. pinfo->lcdc.hsync_skew = 0;
  262. ret = platform_device_register(&this_device);
  263. if (ret) {
  264. pr_err("%s not able to register the device\n", __func__);
  265. platform_driver_unregister(&this_driver);
  266. }
  267. return ret;
  268. }
  269. device_initcall(lcdc_truly_panel_init);