/drivers/staging/msm/ebi2_lcd.c

https://bitbucket.org/slukk/jb-tsm-kernel-4.2 · C · 250 lines · 176 code · 35 blank · 39 comment · 34 complexity · a0d1d6554b2e6422c9eccc2ce54a9d15 MD5 · raw file

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