lcdc.c 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  1. /* Copyright (c) 2008-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/module.h>
  14. #include <linux/kernel.h>
  15. #include <linux/sched.h>
  16. #include <linux/time.h>
  17. #include <linux/init.h>
  18. #include <linux/interrupt.h>
  19. #include <linux/spinlock.h>
  20. #include <linux/delay.h>
  21. #include <mach/hardware.h>
  22. #include <linux/io.h>
  23. #include <asm/system.h>
  24. #include <asm/mach-types.h>
  25. #include <linux/semaphore.h>
  26. #include <linux/uaccess.h>
  27. #include <linux/clk.h>
  28. #include <linux/platform_device.h>
  29. #include <linux/regulator/consumer.h>
  30. #include "msm_fb.h"
  31. static int lcdc_probe(struct platform_device *pdev);
  32. static int lcdc_remove(struct platform_device *pdev);
  33. static int lcdc_off(struct platform_device *pdev);
  34. static int lcdc_on(struct platform_device *pdev);
  35. static void cont_splash_clk_ctrl(int enable);
  36. static struct platform_device *pdev_list[MSM_FB_MAX_DEV_LIST];
  37. static int pdev_list_cnt;
  38. static struct clk *pixel_mdp_clk; /* drives the lcdc block in mdp */
  39. static struct clk *pixel_lcdc_clk; /* drives the lcdc interface */
  40. static struct platform_driver lcdc_driver = {
  41. .probe = lcdc_probe,
  42. .remove = lcdc_remove,
  43. .suspend = NULL,
  44. .resume = NULL,
  45. .shutdown = NULL,
  46. .driver = {
  47. .name = "lcdc",
  48. },
  49. };
  50. static struct lcdc_platform_data *lcdc_pdata;
  51. static int lcdc_off(struct platform_device *pdev)
  52. {
  53. int ret = 0;
  54. struct msm_fb_data_type *mfd;
  55. mfd = platform_get_drvdata(pdev);
  56. ret = panel_next_off(pdev);
  57. clk_disable_unprepare(pixel_mdp_clk);
  58. clk_disable_unprepare(pixel_lcdc_clk);
  59. if (lcdc_pdata && lcdc_pdata->lcdc_power_save)
  60. lcdc_pdata->lcdc_power_save(0);
  61. if (lcdc_pdata && lcdc_pdata->lcdc_gpio_config)
  62. ret = lcdc_pdata->lcdc_gpio_config(0);
  63. #ifndef CONFIG_MSM_BUS_SCALING
  64. if (mfd->ebi1_clk) {
  65. if (mdp_rev == MDP_REV_303) {
  66. if (clk_set_rate(mfd->ebi1_clk, 0))
  67. pr_err("%s: ebi1_lcdc_clk set rate failed\n",
  68. __func__);
  69. }
  70. clk_disable_unprepare(mfd->ebi1_clk);
  71. }
  72. #endif
  73. return ret;
  74. }
  75. static int lcdc_on(struct platform_device *pdev)
  76. {
  77. int ret = 0;
  78. struct msm_fb_data_type *mfd;
  79. unsigned long panel_pixclock_freq = 0;
  80. #ifndef CONFIG_MSM_BUS_SCALING
  81. unsigned long pm_qos_rate;
  82. #endif
  83. mfd = platform_get_drvdata(pdev);
  84. cont_splash_clk_ctrl(0);
  85. if (lcdc_pdata && lcdc_pdata->lcdc_get_clk)
  86. panel_pixclock_freq = lcdc_pdata->lcdc_get_clk();
  87. if (!panel_pixclock_freq)
  88. panel_pixclock_freq = mfd->fbi->var.pixclock;
  89. #ifndef CONFIG_MSM_BUS_SCALING
  90. if (panel_pixclock_freq > 65000000)
  91. /* pm_qos_rate should be in Khz */
  92. pm_qos_rate = panel_pixclock_freq / 1000 ;
  93. else
  94. pm_qos_rate = 65000;
  95. if (mfd->ebi1_clk) {
  96. if (mdp_rev == MDP_REV_303) {
  97. if (clk_set_rate(mfd->ebi1_clk, 65000000))
  98. pr_err("%s: ebi1_lcdc_clk set rate failed\n",
  99. __func__);
  100. } else {
  101. clk_set_rate(mfd->ebi1_clk, pm_qos_rate * 1000);
  102. }
  103. clk_prepare_enable(mfd->ebi1_clk);
  104. }
  105. #endif
  106. mfd = platform_get_drvdata(pdev);
  107. mfd->fbi->var.pixclock = clk_round_rate(pixel_mdp_clk,
  108. mfd->fbi->var.pixclock);
  109. ret = clk_set_rate(pixel_mdp_clk, mfd->fbi->var.pixclock);
  110. if (ret) {
  111. pr_err("%s: Can't set MDP LCDC pixel clock to rate %u\n",
  112. __func__, mfd->fbi->var.pixclock);
  113. goto out;
  114. }
  115. clk_prepare_enable(pixel_mdp_clk);
  116. clk_prepare_enable(pixel_lcdc_clk);
  117. if (lcdc_pdata && lcdc_pdata->lcdc_power_save)
  118. lcdc_pdata->lcdc_power_save(1);
  119. if (lcdc_pdata && lcdc_pdata->lcdc_gpio_config)
  120. ret = lcdc_pdata->lcdc_gpio_config(1);
  121. ret = panel_next_on(pdev);
  122. out:
  123. return ret;
  124. }
  125. static void cont_splash_clk_ctrl(int enable)
  126. {
  127. static int cont_splash_clks_enabled;
  128. if (enable && !cont_splash_clks_enabled) {
  129. clk_prepare_enable(pixel_mdp_clk);
  130. clk_prepare_enable(pixel_lcdc_clk);
  131. cont_splash_clks_enabled = 1;
  132. } else if (!enable && cont_splash_clks_enabled) {
  133. clk_disable_unprepare(pixel_mdp_clk);
  134. clk_disable_unprepare(pixel_lcdc_clk);
  135. cont_splash_clks_enabled = 0;
  136. }
  137. }
  138. static int lcdc_probe(struct platform_device *pdev)
  139. {
  140. struct msm_fb_data_type *mfd;
  141. struct fb_info *fbi;
  142. struct platform_device *mdp_dev = NULL;
  143. struct msm_fb_panel_data *pdata = NULL;
  144. int rc;
  145. struct clk *ebi1_clk = NULL;
  146. if (pdev->id == 0) {
  147. lcdc_pdata = pdev->dev.platform_data;
  148. pixel_mdp_clk = clk_get(&pdev->dev, "mdp_clk");
  149. if (IS_ERR(pixel_mdp_clk)) {
  150. pr_err("Couldnt find pixel_mdp_clk\n");
  151. return -EINVAL;
  152. }
  153. pixel_lcdc_clk = clk_get(&pdev->dev, "lcdc_clk");
  154. if (IS_ERR(pixel_lcdc_clk)) {
  155. pr_err("Couldnt find pixel_lcdc_clk\n");
  156. return -EINVAL;
  157. }
  158. #ifndef CONFIG_MSM_BUS_SCALING
  159. ebi1_clk = clk_get(&pdev->dev, "mem_clk");
  160. if (IS_ERR(ebi1_clk))
  161. return PTR_ERR(ebi1_clk);
  162. #endif
  163. return 0;
  164. }
  165. mfd = platform_get_drvdata(pdev);
  166. mfd->ebi1_clk = ebi1_clk;
  167. if (!mfd)
  168. return -ENODEV;
  169. if (mfd->key != MFD_KEY)
  170. return -EINVAL;
  171. if (pdev_list_cnt >= MSM_FB_MAX_DEV_LIST)
  172. return -ENOMEM;
  173. mdp_dev = platform_device_alloc("mdp", pdev->id);
  174. if (!mdp_dev)
  175. return -ENOMEM;
  176. cont_splash_clk_ctrl(1);
  177. /*
  178. * link to the latest pdev
  179. */
  180. mfd->pdev = mdp_dev;
  181. mfd->dest = DISPLAY_LCDC;
  182. /*
  183. * alloc panel device data
  184. */
  185. if (platform_device_add_data
  186. (mdp_dev, pdev->dev.platform_data,
  187. sizeof(struct msm_fb_panel_data))) {
  188. pr_err("lcdc_probe: platform_device_add_data failed!\n");
  189. platform_device_put(mdp_dev);
  190. return -ENOMEM;
  191. }
  192. /*
  193. * data chain
  194. */
  195. pdata = (struct msm_fb_panel_data *)mdp_dev->dev.platform_data;
  196. pdata->on = lcdc_on;
  197. pdata->off = lcdc_off;
  198. pdata->next = pdev;
  199. /*
  200. * get/set panel specific fb info
  201. */
  202. mfd->panel_info = pdata->panel_info;
  203. if (mfd->index == 0)
  204. mfd->fb_imgType = MSMFB_DEFAULT_TYPE;
  205. else
  206. mfd->fb_imgType = MDP_RGB_565;
  207. fbi = mfd->fbi;
  208. fbi->var.pixclock = clk_round_rate(pixel_mdp_clk,
  209. mfd->panel_info.clk_rate);
  210. fbi->var.left_margin = mfd->panel_info.lcdc.h_back_porch;
  211. fbi->var.right_margin = mfd->panel_info.lcdc.h_front_porch;
  212. fbi->var.upper_margin = mfd->panel_info.lcdc.v_back_porch;
  213. fbi->var.lower_margin = mfd->panel_info.lcdc.v_front_porch;
  214. fbi->var.hsync_len = mfd->panel_info.lcdc.h_pulse_width;
  215. fbi->var.vsync_len = mfd->panel_info.lcdc.v_pulse_width;
  216. /*
  217. * set driver data
  218. */
  219. platform_set_drvdata(mdp_dev, mfd);
  220. /*
  221. * register in mdp driver
  222. */
  223. rc = platform_device_add(mdp_dev);
  224. if (rc)
  225. goto lcdc_probe_err;
  226. pdev_list[pdev_list_cnt++] = pdev;
  227. return 0;
  228. lcdc_probe_err:
  229. platform_device_put(mdp_dev);
  230. return rc;
  231. }
  232. static int lcdc_remove(struct platform_device *pdev)
  233. {
  234. #ifndef CONFIG_MSM_BUS_SCALING
  235. struct msm_fb_data_type *mfd;
  236. mfd = platform_get_drvdata(pdev);
  237. clk_put(mfd->ebi1_clk);
  238. #endif
  239. return 0;
  240. }
  241. static int lcdc_register_driver(void)
  242. {
  243. return platform_driver_register(&lcdc_driver);
  244. }
  245. static int __init lcdc_driver_init(void)
  246. {
  247. return lcdc_register_driver();
  248. }
  249. module_init(lcdc_driver_init);