lcdc_auo_wvga.c 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412
  1. /* Copyright (c) 2011, 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. #include <linux/delay.h>
  13. #include <linux/pwm.h>
  14. #ifdef CONFIG_SPI_QUP
  15. #include <linux/spi/spi.h>
  16. #else
  17. #include <mach/gpio.h>
  18. #endif
  19. #include "msm_fb.h"
  20. #define MAX_BACKLIGHT_LEVEL 15
  21. #define PANEL_CMD_BACKLIGHT_LEVEL 0x6A18
  22. #define PANEL_CMD_FORMAT 0x3A00
  23. #define PANEL_CMD_RGBCTRL 0x3B00
  24. #define PANEL_CMD_BCTRL 0x5300
  25. #define PANEL_CMD_PWM_EN 0x6A17
  26. #define PANEL_CMD_SLEEP_OUT 0x1100
  27. #define PANEL_CMD_DISP_ON 0x2900
  28. #define PANEL_CMD_DISP_OFF 0x2800
  29. #define PANEL_CMD_SLEEP_IN 0x1000
  30. #define LCDC_AUO_PANEL_NAME "lcdc_auo_wvga"
  31. #ifdef CONFIG_SPI_QUP
  32. #define LCDC_AUO_SPI_DEVICE_NAME "lcdc_auo_nt35582"
  33. static struct spi_device *lcdc_spi_client;
  34. #else
  35. static int spi_cs;
  36. static int spi_sclk;
  37. static int spi_mosi;
  38. #endif
  39. struct auo_state_type {
  40. boolean display_on;
  41. int bl_level;
  42. };
  43. static struct auo_state_type auo_state = { .bl_level = 10 };
  44. static struct msm_panel_common_pdata *lcdc_auo_pdata;
  45. #ifndef CONFIG_SPI_QUP
  46. static void auo_spi_write_byte(u8 data)
  47. {
  48. uint32 bit;
  49. int bnum;
  50. bnum = 8; /* 8 data bits */
  51. bit = 0x80;
  52. while (bnum--) {
  53. gpio_set_value(spi_sclk, 0); /* clk low */
  54. gpio_set_value(spi_mosi, (data & bit) ? 1 : 0);
  55. udelay(1);
  56. gpio_set_value(spi_sclk, 1); /* clk high */
  57. udelay(1);
  58. bit >>= 1;
  59. }
  60. gpio_set_value(spi_mosi, 0);
  61. }
  62. static void auo_spi_read_byte(u16 cmd_16, u8 *data)
  63. {
  64. int bnum;
  65. u8 cmd_hi = (u8)(cmd_16 >> 8);
  66. u8 cmd_low = (u8)(cmd_16);
  67. /* Chip Select - low */
  68. gpio_set_value(spi_cs, 0);
  69. udelay(2);
  70. /* command byte first */
  71. auo_spi_write_byte(0x20);
  72. udelay(2);
  73. auo_spi_write_byte(cmd_hi);
  74. udelay(2);
  75. auo_spi_write_byte(0x00);
  76. udelay(2);
  77. auo_spi_write_byte(cmd_low);
  78. udelay(2);
  79. auo_spi_write_byte(0xc0);
  80. udelay(2);
  81. gpio_direction_input(spi_mosi);
  82. /* followed by data bytes */
  83. bnum = 1 * 8; /* number of bits */
  84. *data = 0;
  85. while (bnum) {
  86. gpio_set_value(spi_sclk, 0); /* clk low */
  87. udelay(1);
  88. *data <<= 1;
  89. *data |= gpio_get_value(spi_mosi) ? 1 : 0;
  90. gpio_set_value(spi_sclk, 1); /* clk high */
  91. udelay(1);
  92. --bnum;
  93. if ((bnum % 8) == 0)
  94. ++data;
  95. }
  96. gpio_direction_output(spi_mosi, 0);
  97. /* Chip Select - high */
  98. udelay(2);
  99. gpio_set_value(spi_cs, 1);
  100. }
  101. #endif
  102. static int auo_serigo(u8 *input_data, int input_len)
  103. {
  104. #ifdef CONFIG_SPI_QUP
  105. int rc;
  106. struct spi_message m;
  107. struct spi_transfer t;
  108. if (!lcdc_spi_client) {
  109. pr_err("%s lcdc_spi_client is NULL\n", __func__);
  110. return -EINVAL;
  111. }
  112. memset(&t, 0, sizeof t);
  113. t.tx_buf = input_data;
  114. t.len = input_len;
  115. t.bits_per_word = 16;
  116. spi_setup(lcdc_spi_client);
  117. spi_message_init(&m);
  118. spi_message_add_tail(&t, &m);
  119. rc = spi_sync(lcdc_spi_client, &m);
  120. return rc;
  121. #else
  122. int i;
  123. /* Chip Select - low */
  124. gpio_set_value(spi_cs, 0);
  125. udelay(2);
  126. for (i = 0; i < input_len; ++i) {
  127. auo_spi_write_byte(input_data[i]);
  128. udelay(2);
  129. }
  130. /* Chip Select - high */
  131. gpio_set_value(spi_cs, 1);
  132. return 0;
  133. #endif
  134. }
  135. #ifndef CONFIG_SPI_QUP
  136. static void auo_spi_init(void)
  137. {
  138. spi_sclk = *(lcdc_auo_pdata->gpio_num);
  139. spi_cs = *(lcdc_auo_pdata->gpio_num + 1);
  140. spi_mosi = *(lcdc_auo_pdata->gpio_num + 2);
  141. /* Set the output so that we don't disturb the slave device */
  142. gpio_set_value(spi_sclk, 1);
  143. gpio_set_value(spi_mosi, 0);
  144. /* Set the Chip Select deasserted (active low) */
  145. gpio_set_value(spi_cs, 1);
  146. }
  147. #endif
  148. static struct work_struct disp_on_delayed_work;
  149. static void auo_write_cmd(u16 cmd)
  150. {
  151. u8 local_data[4];
  152. local_data[0] = 0x20;
  153. local_data[1] = (u8)(cmd >> 8);
  154. local_data[2] = 0;
  155. local_data[3] = (u8)cmd;
  156. auo_serigo(local_data, 4);
  157. }
  158. static void auo_write_cmd_1param(u16 cmd, u8 para1)
  159. {
  160. u8 local_data[6];
  161. local_data[0] = 0x20;
  162. local_data[1] = (u8)(cmd >> 8);
  163. local_data[2] = 0;
  164. local_data[3] = (u8)cmd;
  165. local_data[4] = 0x40;
  166. local_data[5] = para1;
  167. auo_serigo(local_data, 6);
  168. }
  169. static void lcdc_auo_set_backlight(struct msm_fb_data_type *mfd)
  170. {
  171. int bl_level;
  172. bl_level = mfd->bl_level;
  173. if (auo_state.display_on) {
  174. auo_write_cmd_1param(PANEL_CMD_BACKLIGHT_LEVEL,
  175. bl_level * 255 / MAX_BACKLIGHT_LEVEL);
  176. auo_state.bl_level = bl_level;
  177. }
  178. }
  179. static void auo_disp_on_delayed_work(struct work_struct *work_ptr)
  180. {
  181. /* 0x1100: Sleep Out */
  182. auo_write_cmd(PANEL_CMD_SLEEP_OUT);
  183. msleep(180);
  184. /* SET_PIXEL_FORMAT: Set how many bits per pixel are used (3A00h)*/
  185. auo_write_cmd_1param(PANEL_CMD_FORMAT, 0x66); /* 18 bits */
  186. /* RGBCTRL: RGB Interface Signal Control (3B00h) */
  187. auo_write_cmd_1param(PANEL_CMD_RGBCTRL, 0x2B);
  188. /* Display ON command */
  189. auo_write_cmd(PANEL_CMD_DISP_ON);
  190. msleep(20);
  191. /*Backlight on */
  192. auo_write_cmd_1param(PANEL_CMD_BCTRL, 0x24); /*BCTRL, BL */
  193. auo_write_cmd_1param(PANEL_CMD_PWM_EN, 0x01); /*Enable PWM Level */
  194. msleep(20);
  195. }
  196. static void auo_disp_on(void)
  197. {
  198. if (!auo_state.display_on) {
  199. INIT_WORK(&disp_on_delayed_work, auo_disp_on_delayed_work);
  200. #ifdef CONFIG_SPI_QUP
  201. if (lcdc_spi_client)
  202. #endif
  203. schedule_work(&disp_on_delayed_work);
  204. auo_state.display_on = TRUE;
  205. }
  206. }
  207. static int lcdc_auo_panel_on(struct platform_device *pdev)
  208. {
  209. pr_info("%s\n", __func__);
  210. if (!auo_state.display_on) {
  211. #ifndef CONFIG_SPI_QUP
  212. lcdc_auo_pdata->panel_config_gpio(1);
  213. auo_spi_init();
  214. #endif
  215. auo_disp_on();
  216. }
  217. return 0;
  218. }
  219. static int lcdc_auo_panel_off(struct platform_device *pdev)
  220. {
  221. pr_info("%s\n", __func__);
  222. if (auo_state.display_on) {
  223. /* 0x2800: Display Off */
  224. auo_write_cmd(PANEL_CMD_DISP_OFF);
  225. msleep(120);
  226. /* 0x1000: Sleep In */
  227. auo_write_cmd(PANEL_CMD_SLEEP_IN);
  228. msleep(120);
  229. auo_state.display_on = FALSE;
  230. }
  231. return 0;
  232. }
  233. static int auo_probe(struct platform_device *pdev)
  234. {
  235. pr_info("%s: id=%d\n", __func__, pdev->id);
  236. if (pdev->id == 0) {
  237. lcdc_auo_pdata = pdev->dev.platform_data;
  238. return 0;
  239. }
  240. msm_fb_add_device(pdev);
  241. return 0;
  242. }
  243. #ifdef CONFIG_SPI_QUP
  244. static int __devinit lcdc_auo_spi_probe(struct spi_device *spi)
  245. {
  246. pr_info("%s\n", __func__);
  247. lcdc_spi_client = spi;
  248. lcdc_spi_client->bits_per_word = 32;
  249. if (auo_state.display_on)
  250. schedule_work(&disp_on_delayed_work);
  251. return 0;
  252. }
  253. static int __devexit lcdc_auo_spi_remove(struct spi_device *spi)
  254. {
  255. lcdc_spi_client = NULL;
  256. return 0;
  257. }
  258. static struct spi_driver lcdc_auo_spi_driver = {
  259. .driver.name = LCDC_AUO_SPI_DEVICE_NAME,
  260. .driver.owner = THIS_MODULE,
  261. .probe = lcdc_auo_spi_probe,
  262. .remove = __devexit_p(lcdc_auo_spi_remove),
  263. };
  264. #endif
  265. static struct platform_driver this_driver = {
  266. .probe = auo_probe,
  267. .driver.name = LCDC_AUO_PANEL_NAME,
  268. };
  269. static struct msm_fb_panel_data auo_panel_data = {
  270. .on = lcdc_auo_panel_on,
  271. .off = lcdc_auo_panel_off,
  272. .set_backlight = lcdc_auo_set_backlight,
  273. };
  274. static struct platform_device this_device = {
  275. .name = LCDC_AUO_PANEL_NAME,
  276. .id = 1,
  277. .dev.platform_data = &auo_panel_data,
  278. };
  279. static int __init lcdc_auo_panel_init(void)
  280. {
  281. int ret;
  282. struct msm_panel_info *pinfo;
  283. if (msm_fb_detect_client(LCDC_AUO_PANEL_NAME)) {
  284. pr_err("%s: detect failed\n", __func__);
  285. return 0;
  286. }
  287. ret = platform_driver_register(&this_driver);
  288. if (ret) {
  289. pr_err("%s: driver register failed, rc=%d\n", __func__, ret);
  290. return ret;
  291. }
  292. pinfo = &auo_panel_data.panel_info;
  293. pinfo->xres = 480;
  294. pinfo->yres = 800;
  295. pinfo->type = LCDC_PANEL;
  296. pinfo->pdest = DISPLAY_1;
  297. pinfo->wait_cycle = 0;
  298. pinfo->bpp = 18;
  299. pinfo->fb_num = 2;
  300. pinfo->clk_rate = 25600000;
  301. pinfo->bl_max = MAX_BACKLIGHT_LEVEL;
  302. pinfo->bl_min = 1;
  303. pinfo->lcdc.h_back_porch = 16-2; /* HBP-HLW */
  304. pinfo->lcdc.h_front_porch = 16;
  305. pinfo->lcdc.h_pulse_width = 2;
  306. pinfo->lcdc.v_back_porch = 3-2; /* VBP-VLW */
  307. pinfo->lcdc.v_front_porch = 28;
  308. pinfo->lcdc.v_pulse_width = 2;
  309. pinfo->lcdc.border_clr = 0;
  310. pinfo->lcdc.underflow_clr = 0xff;
  311. pinfo->lcdc.hsync_skew = 0;
  312. ret = platform_device_register(&this_device);
  313. if (ret) {
  314. pr_err("%s: device register failed, rc=%d\n", __func__, ret);
  315. goto fail_driver;
  316. }
  317. #ifdef CONFIG_SPI_QUP
  318. ret = spi_register_driver(&lcdc_auo_spi_driver);
  319. if (ret) {
  320. pr_err("%s: spi register failed: rc=%d\n", __func__, ret);
  321. goto fail_device;
  322. }
  323. pr_info("%s: SUCCESS (SPI)\n", __func__);
  324. #else
  325. pr_info("%s: SUCCESS (BitBang)\n", __func__);
  326. #endif
  327. return ret;
  328. #ifdef CONFIG_SPI_QUP
  329. fail_device:
  330. platform_device_unregister(&this_device);
  331. #endif
  332. fail_driver:
  333. platform_driver_unregister(&this_driver);
  334. return ret;
  335. }
  336. module_init(lcdc_auo_panel_init);
  337. static void __exit lcdc_auo_panel_exit(void)
  338. {
  339. pr_info("%s\n", __func__);
  340. platform_device_unregister(&this_device);
  341. platform_driver_unregister(&this_driver);
  342. #ifdef CONFIG_SPI_QUP
  343. spi_unregister_driver(&lcdc_auo_spi_driver);
  344. #endif
  345. }
  346. module_exit(lcdc_auo_panel_exit);