ebi2_lcd.c 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  1. /* Copyright (c) 2008-2009, 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/module.h>
  14. #include <linux/moduleparam.h>
  15. #include <linux/kernel.h>
  16. #include <linux/slab.h>
  17. #include <linux/delay.h>
  18. #include <linux/mm.h>
  19. #include <linux/fb.h>
  20. #include <linux/init.h>
  21. #include <linux/ioport.h>
  22. #include <linux/device.h>
  23. #include <linux/dma-mapping.h>
  24. #include <linux/uaccess.h>
  25. #include <linux/workqueue.h>
  26. #include <linux/string.h>
  27. #include <linux/version.h>
  28. #include <linux/proc_fs.h>
  29. #include <linux/vmalloc.h>
  30. #include <linux/debugfs.h>
  31. #include "msm_fb.h"
  32. static int ebi2_lcd_probe(struct platform_device *pdev);
  33. static int ebi2_lcd_remove(struct platform_device *pdev);
  34. static int ebi2_lcd_runtime_suspend(struct device *dev)
  35. {
  36. dev_dbg(dev, "pm_runtime: suspending...\n");
  37. return 0;
  38. }
  39. static int ebi2_lcd_runtime_resume(struct device *dev)
  40. {
  41. dev_dbg(dev, "pm_runtime: resuming...\n");
  42. return 0;
  43. }
  44. static struct dev_pm_ops ebi2_lcd_dev_pm_ops = {
  45. .runtime_suspend = ebi2_lcd_runtime_suspend,
  46. .runtime_resume = ebi2_lcd_runtime_resume,
  47. };
  48. static struct platform_driver ebi2_lcd_driver = {
  49. .probe = ebi2_lcd_probe,
  50. .remove = ebi2_lcd_remove,
  51. .suspend = NULL,
  52. .resume = NULL,
  53. .shutdown = NULL,
  54. .driver = {
  55. .name = "ebi2_lcd",
  56. .pm = &ebi2_lcd_dev_pm_ops,
  57. },
  58. };
  59. static void *ebi2_base;
  60. static void *ebi2_lcd_cfg0;
  61. static void *ebi2_lcd_cfg1;
  62. static void __iomem *lcd01_base;
  63. static void __iomem *lcd02_base;
  64. static int lcd01_base_phys;
  65. static int ebi2_lcd_resource_initialized;
  66. static struct platform_device *pdev_list[MSM_FB_MAX_DEV_LIST];
  67. static int pdev_list_cnt;
  68. static struct lcdc_platform_data *ebi2_pdata;
  69. static int ebi2_lcd_on(struct platform_device *pdev)
  70. {
  71. int ret;
  72. if (ebi2_pdata && ebi2_pdata->lcdc_power_save)
  73. ebi2_pdata->lcdc_power_save(1);
  74. ret = panel_next_on(pdev);
  75. return ret;
  76. }
  77. static int ebi2_lcd_off(struct platform_device *pdev)
  78. {
  79. int ret;
  80. ret = panel_next_off(pdev);
  81. if (ebi2_pdata && ebi2_pdata->lcdc_power_save)
  82. ebi2_pdata->lcdc_power_save(0);
  83. return ret;
  84. }
  85. static int ebi2_lcd_probe(struct platform_device *pdev)
  86. {
  87. struct msm_fb_data_type *mfd;
  88. struct platform_device *mdp_dev = NULL;
  89. struct msm_fb_panel_data *pdata = NULL;
  90. int rc, i, hw_version;
  91. if (pdev->id == 0) {
  92. for (i = 0; i < pdev->num_resources; i++) {
  93. if (!strncmp(pdev->resource[i].name, "base", 4)) {
  94. ebi2_base = ioremap(pdev->resource[i].start,
  95. pdev->resource[i].end -
  96. pdev->resource[i].start + 1);
  97. if (!ebi2_base) {
  98. printk(KERN_ERR
  99. "ebi2_base ioremap failed!\n");
  100. return -ENOMEM;
  101. }
  102. ebi2_lcd_cfg0 = (void *)(ebi2_base + 0x20);
  103. ebi2_lcd_cfg1 = (void *)(ebi2_base + 0x24);
  104. } else if (!strncmp(pdev->resource[i].name,
  105. "lcd01", 5)) {
  106. lcd01_base_phys = pdev->resource[i].start;
  107. lcd01_base = ioremap(pdev->resource[i].start,
  108. pdev->resource[i].end -
  109. pdev->resource[i].start + 1);
  110. if (!lcd01_base) {
  111. printk(KERN_ERR
  112. "lcd01_base ioremap failed!\n");
  113. return -ENOMEM;
  114. }
  115. } else if (!strncmp(pdev->resource[i].name,
  116. "lcd02", 5)) {
  117. lcd02_base = ioremap(pdev->resource[i].start,
  118. pdev->resource[i].end -
  119. pdev->resource[i].start + 1);
  120. if (!lcd02_base) {
  121. printk(KERN_ERR
  122. "lcd02_base ioremap failed!\n");
  123. return -ENOMEM;
  124. }
  125. }
  126. }
  127. ebi2_pdata = pdev->dev.platform_data;
  128. ebi2_lcd_resource_initialized = 1;
  129. return 0;
  130. }
  131. if (!ebi2_lcd_resource_initialized)
  132. return -EPERM;
  133. mfd = platform_get_drvdata(pdev);
  134. if (!mfd)
  135. return -ENODEV;
  136. if (mfd->key != MFD_KEY)
  137. return -EINVAL;
  138. if (pdev_list_cnt >= MSM_FB_MAX_DEV_LIST)
  139. return -ENOMEM;
  140. if (ebi2_base == NULL)
  141. return -ENOMEM;
  142. mdp_dev = platform_device_alloc("mdp", pdev->id);
  143. if (!mdp_dev)
  144. return -ENOMEM;
  145. /* link to the latest pdev */
  146. mfd->pdev = mdp_dev;
  147. mfd->dest = DISPLAY_LCD;
  148. /* add panel data */
  149. if (platform_device_add_data
  150. (mdp_dev, pdev->dev.platform_data,
  151. sizeof(struct msm_fb_panel_data))) {
  152. printk(KERN_ERR "ebi2_lcd_probe: platform_device_add_data failed!\n");
  153. platform_device_put(mdp_dev);
  154. return -ENOMEM;
  155. }
  156. /* data chain */
  157. pdata = mdp_dev->dev.platform_data;
  158. pdata->on = ebi2_lcd_on;
  159. pdata->off = ebi2_lcd_off;
  160. pdata->next = pdev;
  161. /* get/set panel specific fb info */
  162. mfd->panel_info = pdata->panel_info;
  163. hw_version = inp32((int)ebi2_base + 8);
  164. if (mfd->panel_info.bpp == 24)
  165. mfd->fb_imgType = MDP_RGB_888;
  166. else if (mfd->panel_info.bpp == 18)
  167. mfd->fb_imgType = MDP_RGB_888;
  168. else
  169. mfd->fb_imgType = MDP_RGB_565;
  170. /* config msm ebi2 lcd register */
  171. if (mfd->panel_info.pdest == DISPLAY_1) {
  172. outp32(ebi2_base,
  173. (inp32(ebi2_base) & (~(EBI2_PRIM_LCD_CLR))) |
  174. EBI2_PRIM_LCD_SEL);
  175. /*
  176. * current design has one set of cfg0/1 register to control
  177. * both EBI2 channels. so, we're using the PRIM channel to
  178. * configure both.
  179. */
  180. outp32(ebi2_lcd_cfg0, mfd->panel_info.wait_cycle);
  181. if (hw_version < 0x2020) {
  182. if (mfd->panel_info.bpp == 18)
  183. outp32(ebi2_lcd_cfg1, 0x01000000);
  184. else
  185. outp32(ebi2_lcd_cfg1, 0x0);
  186. }
  187. } else {
  188. #ifdef DEBUG_EBI2_LCD
  189. /*
  190. * confliting with QCOM SURF FPGA CS.
  191. * OEM should enable below for their CS mapping
  192. */
  193. outp32(ebi2_base, (inp32(ebi2_base)&(~(EBI2_SECD_LCD_CLR)))
  194. |EBI2_SECD_LCD_SEL);
  195. #endif
  196. }
  197. /*
  198. * map cs (chip select) address
  199. */
  200. if (mfd->panel_info.pdest == DISPLAY_1) {
  201. mfd->cmd_port = lcd01_base;
  202. if (hw_version >= 0x2020) {
  203. mfd->data_port =
  204. (void *)((uint32) mfd->cmd_port + 0x80);
  205. mfd->data_port_phys =
  206. (void *)(lcd01_base_phys + 0x80);
  207. } else {
  208. mfd->data_port =
  209. (void *)((uint32) mfd->cmd_port +
  210. EBI2_PRIM_LCD_RS_PIN);
  211. mfd->data_port_phys =
  212. (void *)(LCD_PRIM_BASE_PHYS + EBI2_PRIM_LCD_RS_PIN);
  213. }
  214. } else {
  215. mfd->cmd_port = lcd01_base;
  216. mfd->data_port =
  217. (void *)((uint32) mfd->cmd_port + EBI2_SECD_LCD_RS_PIN);
  218. mfd->data_port_phys =
  219. (void *)(LCD_SECD_BASE_PHYS + EBI2_SECD_LCD_RS_PIN);
  220. }
  221. /*
  222. * set driver data
  223. */
  224. platform_set_drvdata(mdp_dev, mfd);
  225. /*
  226. * register in mdp driver
  227. */
  228. rc = platform_device_add(mdp_dev);
  229. if (rc) {
  230. goto ebi2_lcd_probe_err;
  231. }
  232. pm_runtime_set_active(&pdev->dev);
  233. pm_runtime_enable(&pdev->dev);
  234. pdev_list[pdev_list_cnt++] = pdev;
  235. return 0;
  236. ebi2_lcd_probe_err:
  237. platform_device_put(mdp_dev);
  238. return rc;
  239. }
  240. static int ebi2_lcd_remove(struct platform_device *pdev)
  241. {
  242. struct msm_fb_data_type *mfd;
  243. mfd = (struct msm_fb_data_type *)platform_get_drvdata(pdev);
  244. if (!mfd)
  245. return 0;
  246. if (mfd->key != MFD_KEY)
  247. return 0;
  248. iounmap(mfd->cmd_port);
  249. pm_runtime_disable(&pdev->dev);
  250. return 0;
  251. }
  252. static int ebi2_lcd_register_driver(void)
  253. {
  254. return platform_driver_register(&ebi2_lcd_driver);
  255. }
  256. static int __init ebi2_lcd_driver_init(void)
  257. {
  258. return ebi2_lcd_register_driver();
  259. }
  260. module_init(ebi2_lcd_driver_init);