mdp4_dtv.c 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384
  1. /* Copyright (c) 2010-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 <linux/io.h>
  22. #include <linux/semaphore.h>
  23. #include <linux/uaccess.h>
  24. #include <linux/clk.h>
  25. #include <linux/platform_device.h>
  26. #include <asm/system.h>
  27. #include <asm/mach-types.h>
  28. #include <mach/hardware.h>
  29. #include <linux/pm_runtime.h>
  30. #include <mach/clk.h>
  31. #include "msm_fb.h"
  32. #include "mdp4.h"
  33. static int dtv_probe(struct platform_device *pdev);
  34. static int dtv_remove(struct platform_device *pdev);
  35. static int dtv_off(struct platform_device *pdev);
  36. static int dtv_on(struct platform_device *pdev);
  37. static int dtv_off_sub(void);
  38. static struct platform_device *pdev_list[MSM_FB_MAX_DEV_LIST];
  39. static int pdev_list_cnt;
  40. static struct clk *tv_src_clk;
  41. static struct clk *hdmi_clk;
  42. static struct clk *mdp_tv_clk;
  43. static struct platform_device *dtv_pdev;
  44. static struct workqueue_struct *dtv_work_queue;
  45. static struct work_struct dtv_off_work;
  46. static int mdp4_dtv_runtime_suspend(struct device *dev)
  47. {
  48. dev_dbg(dev, "pm_runtime: suspending...\n");
  49. return 0;
  50. }
  51. static int mdp4_dtv_runtime_resume(struct device *dev)
  52. {
  53. dev_dbg(dev, "pm_runtime: resuming...\n");
  54. return 0;
  55. }
  56. static const struct dev_pm_ops mdp4_dtv_dev_pm_ops = {
  57. .runtime_suspend = mdp4_dtv_runtime_suspend,
  58. .runtime_resume = mdp4_dtv_runtime_resume,
  59. };
  60. static struct platform_driver dtv_driver = {
  61. .probe = dtv_probe,
  62. .remove = dtv_remove,
  63. .suspend = NULL,
  64. .resume = NULL,
  65. .shutdown = NULL,
  66. .driver = {
  67. .name = "dtv",
  68. .pm = &mdp4_dtv_dev_pm_ops,
  69. },
  70. };
  71. static struct lcdc_platform_data *dtv_pdata;
  72. #ifdef CONFIG_MSM_BUS_SCALING
  73. static uint32_t dtv_bus_scale_handle;
  74. #else
  75. static struct clk *ebi1_clk;
  76. #endif
  77. static int dtv_off(struct platform_device *pdev)
  78. {
  79. int ret = 0;
  80. struct msm_fb_data_type *mfd = NULL;
  81. if (!pdev) {
  82. pr_err("%s: FAILED: invalid arg\n", __func__);
  83. return -EINVAL;
  84. }
  85. mfd = platform_get_drvdata(pdev);
  86. if (!mfd) {
  87. pr_err("%s: FAILED: invalid mfd\n", __func__);
  88. return -EINVAL;
  89. }
  90. dtv_pdev = pdev;
  91. /*
  92. * If it's a suspend operation then handle the device
  93. * power down synchronously.
  94. * Otherwise, queue work item to handle power down sequence.
  95. * This is needed since we need to wait for the audio engine
  96. * to shutdown first before we turn off the DTV device.
  97. */
  98. if (!mfd->suspend.op_suspend) {
  99. pr_debug("%s: Queuing work to turn off HDMI core\n", __func__);
  100. queue_work(dtv_work_queue, &dtv_off_work);
  101. } else {
  102. pr_debug("%s: turning off HDMI core\n", __func__);
  103. ret = dtv_off_sub();
  104. }
  105. return ret;
  106. }
  107. static int dtv_off_sub(void)
  108. {
  109. int ret = 0;
  110. if (!dtv_pdev) {
  111. pr_err("%s: FAILED: invalid arg\n", __func__);
  112. return -EINVAL;
  113. }
  114. ret = panel_next_off(dtv_pdev);
  115. pr_info("%s\n", __func__);
  116. clk_disable_unprepare(hdmi_clk);
  117. if (mdp_tv_clk)
  118. clk_disable_unprepare(mdp_tv_clk);
  119. if (dtv_pdata && dtv_pdata->lcdc_power_save)
  120. dtv_pdata->lcdc_power_save(0);
  121. if (dtv_pdata && dtv_pdata->lcdc_gpio_config)
  122. ret = dtv_pdata->lcdc_gpio_config(0);
  123. #ifdef CONFIG_MSM_BUS_SCALING
  124. if (dtv_bus_scale_handle > 0)
  125. msm_bus_scale_client_update_request(dtv_bus_scale_handle,
  126. 0);
  127. #else
  128. if (ebi1_clk)
  129. clk_disable_unprepare(ebi1_clk);
  130. #endif
  131. mdp4_extn_disp = 0;
  132. return ret;
  133. }
  134. static void dtv_off_work_func(struct work_struct *work)
  135. {
  136. dtv_off_sub();
  137. }
  138. static int dtv_on(struct platform_device *pdev)
  139. {
  140. int ret = 0;
  141. struct msm_fb_data_type *mfd;
  142. unsigned long panel_pixclock_freq , pm_qos_rate;
  143. /* If a power down is already underway, wait for it to finish */
  144. flush_work_sync(&dtv_off_work);
  145. mfd = platform_get_drvdata(pdev);
  146. panel_pixclock_freq = mfd->fbi->var.pixclock;
  147. if (panel_pixclock_freq > 58000000)
  148. /* pm_qos_rate should be in Khz */
  149. pm_qos_rate = panel_pixclock_freq / 1000 ;
  150. else
  151. pm_qos_rate = 58000;
  152. mdp4_extn_disp = 1;
  153. #ifdef CONFIG_MSM_BUS_SCALING
  154. if (dtv_bus_scale_handle > 0)
  155. msm_bus_scale_client_update_request(dtv_bus_scale_handle,
  156. 1);
  157. #else
  158. if (ebi1_clk) {
  159. clk_set_rate(ebi1_clk, pm_qos_rate * 1000);
  160. clk_prepare_enable(ebi1_clk);
  161. }
  162. #endif
  163. if (dtv_pdata && dtv_pdata->lcdc_power_save)
  164. dtv_pdata->lcdc_power_save(1);
  165. if (dtv_pdata && dtv_pdata->lcdc_gpio_config)
  166. ret = dtv_pdata->lcdc_gpio_config(1);
  167. mfd = platform_get_drvdata(pdev);
  168. ret = clk_set_rate(tv_src_clk, mfd->fbi->var.pixclock);
  169. if (ret) {
  170. pr_info("%s: clk_set_rate(%d) failed\n", __func__,
  171. mfd->fbi->var.pixclock);
  172. if (mfd->fbi->var.pixclock == 27030000)
  173. mfd->fbi->var.pixclock = 27000000;
  174. ret = clk_set_rate(tv_src_clk, mfd->fbi->var.pixclock);
  175. }
  176. pr_info("%s: tv_src_clk=%dkHz, pm_qos_rate=%ldkHz, [%d]\n", __func__,
  177. mfd->fbi->var.pixclock/1000, pm_qos_rate, ret);
  178. mfd->panel_info.clk_rate = mfd->fbi->var.pixclock;
  179. clk_prepare_enable(hdmi_clk);
  180. clk_reset(hdmi_clk, CLK_RESET_ASSERT);
  181. udelay(20);
  182. clk_reset(hdmi_clk, CLK_RESET_DEASSERT);
  183. if (mdp_tv_clk)
  184. clk_prepare_enable(mdp_tv_clk);
  185. ret = panel_next_on(pdev);
  186. return ret;
  187. }
  188. static int dtv_probe(struct platform_device *pdev)
  189. {
  190. struct msm_fb_data_type *mfd;
  191. struct fb_info *fbi;
  192. struct platform_device *mdp_dev = NULL;
  193. struct msm_fb_panel_data *pdata = NULL;
  194. int rc;
  195. if (pdev->id == 0) {
  196. dtv_pdata = pdev->dev.platform_data;
  197. #ifdef CONFIG_MSM_BUS_SCALING
  198. if (!dtv_bus_scale_handle && dtv_pdata &&
  199. dtv_pdata->bus_scale_table) {
  200. dtv_bus_scale_handle =
  201. msm_bus_scale_register_client(
  202. dtv_pdata->bus_scale_table);
  203. if (!dtv_bus_scale_handle) {
  204. pr_err("%s not able to get bus scale\n",
  205. __func__);
  206. }
  207. }
  208. #else
  209. ebi1_clk = clk_get(&pdev->dev, "mem_clk");
  210. if (IS_ERR(ebi1_clk)) {
  211. ebi1_clk = NULL;
  212. pr_warning("%s: Couldn't get ebi1 clock\n", __func__);
  213. }
  214. #endif
  215. tv_src_clk = clk_get(&pdev->dev, "src_clk");
  216. if (IS_ERR(tv_src_clk)) {
  217. pr_err("error: can't get tv_src_clk!\n");
  218. return IS_ERR(tv_src_clk);
  219. }
  220. hdmi_clk = clk_get(&pdev->dev, "hdmi_clk");
  221. if (IS_ERR(hdmi_clk)) {
  222. pr_err("error: can't get hdmi_clk!\n");
  223. return IS_ERR(hdmi_clk);
  224. }
  225. mdp_tv_clk = clk_get(&pdev->dev, "mdp_clk");
  226. if (IS_ERR(mdp_tv_clk))
  227. mdp_tv_clk = NULL;
  228. return 0;
  229. }
  230. dtv_work_queue = create_singlethread_workqueue("dtv_work");
  231. INIT_WORK(&dtv_off_work, dtv_off_work_func);
  232. mfd = platform_get_drvdata(pdev);
  233. if (!mfd)
  234. return -ENODEV;
  235. if (mfd->key != MFD_KEY)
  236. return -EINVAL;
  237. if (pdev_list_cnt >= MSM_FB_MAX_DEV_LIST)
  238. return -ENOMEM;
  239. mdp_dev = platform_device_alloc("mdp", pdev->id);
  240. if (!mdp_dev)
  241. return -ENOMEM;
  242. /*
  243. * link to the latest pdev
  244. */
  245. mfd->pdev = mdp_dev;
  246. mfd->dest = DISPLAY_LCDC;
  247. /*
  248. * alloc panel device data
  249. */
  250. if (platform_device_add_data
  251. (mdp_dev, pdev->dev.platform_data,
  252. sizeof(struct msm_fb_panel_data))) {
  253. pr_err("dtv_probe: platform_device_add_data failed!\n");
  254. platform_device_put(mdp_dev);
  255. return -ENOMEM;
  256. }
  257. /*
  258. * data chain
  259. */
  260. pdata = (struct msm_fb_panel_data *)mdp_dev->dev.platform_data;
  261. pdata->on = dtv_on;
  262. pdata->off = dtv_off;
  263. pdata->next = pdev;
  264. /*
  265. * get/set panel specific fb info
  266. */
  267. mfd->panel_info = pdata->panel_info;
  268. if (hdmi_prim_display)
  269. mfd->fb_imgType = MSMFB_DEFAULT_TYPE;
  270. else
  271. mfd->fb_imgType = MDP_RGB_565;
  272. fbi = mfd->fbi;
  273. fbi->var.pixclock = mfd->panel_info.clk_rate;
  274. fbi->var.left_margin = mfd->panel_info.lcdc.h_back_porch;
  275. fbi->var.right_margin = mfd->panel_info.lcdc.h_front_porch;
  276. fbi->var.upper_margin = mfd->panel_info.lcdc.v_back_porch;
  277. fbi->var.lower_margin = mfd->panel_info.lcdc.v_front_porch;
  278. fbi->var.hsync_len = mfd->panel_info.lcdc.h_pulse_width;
  279. fbi->var.vsync_len = mfd->panel_info.lcdc.v_pulse_width;
  280. /*
  281. * set driver data
  282. */
  283. platform_set_drvdata(mdp_dev, mfd);
  284. /*
  285. * register in mdp driver
  286. */
  287. rc = platform_device_add(mdp_dev);
  288. if (rc)
  289. goto dtv_probe_err;
  290. pm_runtime_set_active(&pdev->dev);
  291. pm_runtime_enable(&pdev->dev);
  292. pdev_list[pdev_list_cnt++] = pdev;
  293. return 0;
  294. dtv_probe_err:
  295. #ifdef CONFIG_MSM_BUS_SCALING
  296. if (dtv_pdata && dtv_pdata->bus_scale_table &&
  297. dtv_bus_scale_handle > 0)
  298. msm_bus_scale_unregister_client(dtv_bus_scale_handle);
  299. #endif
  300. platform_device_put(mdp_dev);
  301. return rc;
  302. }
  303. static int dtv_remove(struct platform_device *pdev)
  304. {
  305. if (dtv_work_queue)
  306. destroy_workqueue(dtv_work_queue);
  307. #ifdef CONFIG_MSM_BUS_SCALING
  308. if (dtv_pdata && dtv_pdata->bus_scale_table &&
  309. dtv_bus_scale_handle > 0)
  310. msm_bus_scale_unregister_client(dtv_bus_scale_handle);
  311. #else
  312. if (ebi1_clk)
  313. clk_put(ebi1_clk);
  314. #endif
  315. pm_runtime_disable(&pdev->dev);
  316. return 0;
  317. }
  318. static int dtv_register_driver(void)
  319. {
  320. return platform_driver_register(&dtv_driver);
  321. }
  322. static int __init dtv_driver_init(void)
  323. {
  324. return dtv_register_driver();
  325. }
  326. module_init(dtv_driver_init);