dpi.c 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381
  1. /*
  2. * linux/drivers/video/omap2/dss/dpi.c
  3. *
  4. * Copyright (C) 2009 Nokia Corporation
  5. * Author: Tomi Valkeinen <tomi.valkeinen@nokia.com>
  6. *
  7. * Some code and ideas taken from drivers/video/omap/ driver
  8. * by Imre Deak.
  9. *
  10. * This program is free software; you can redistribute it and/or modify it
  11. * under the terms of the GNU General Public License version 2 as published by
  12. * the Free Software Foundation.
  13. *
  14. * This program is distributed in the hope that it will be useful, but WITHOUT
  15. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  16. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  17. * more details.
  18. *
  19. * You should have received a copy of the GNU General Public License along with
  20. * this program. If not, see <http://www.gnu.org/licenses/>.
  21. */
  22. #define DSS_SUBSYS_NAME "DPI"
  23. #include <linux/kernel.h>
  24. #include <linux/delay.h>
  25. #include <linux/export.h>
  26. #include <linux/err.h>
  27. #include <linux/errno.h>
  28. #include <linux/platform_device.h>
  29. #include <linux/regulator/consumer.h>
  30. #include <video/omapdss.h>
  31. #include <plat/cpu.h>
  32. #include "dss.h"
  33. static struct {
  34. struct regulator *vdds_dsi_reg;
  35. struct platform_device *dsidev;
  36. } dpi;
  37. static struct platform_device *dpi_get_dsidev(enum omap_dss_clk_source clk)
  38. {
  39. int dsi_module;
  40. dsi_module = clk == OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC ? 0 : 1;
  41. return dsi_get_dsidev_from_id(dsi_module);
  42. }
  43. static bool dpi_use_dsi_pll(struct omap_dss_device *dssdev)
  44. {
  45. if (dssdev->clocks.dispc.dispc_fclk_src ==
  46. OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC ||
  47. dssdev->clocks.dispc.dispc_fclk_src ==
  48. OMAP_DSS_CLK_SRC_DSI2_PLL_HSDIV_DISPC ||
  49. dssdev->clocks.dispc.channel.lcd_clk_src ==
  50. OMAP_DSS_CLK_SRC_DSI_PLL_HSDIV_DISPC ||
  51. dssdev->clocks.dispc.channel.lcd_clk_src ==
  52. OMAP_DSS_CLK_SRC_DSI2_PLL_HSDIV_DISPC)
  53. return true;
  54. else
  55. return false;
  56. }
  57. static int dpi_set_dsi_clk(struct omap_dss_device *dssdev, bool is_tft,
  58. unsigned long pck_req, unsigned long *fck, int *lck_div,
  59. int *pck_div)
  60. {
  61. struct dsi_clock_info dsi_cinfo;
  62. struct dispc_clock_info dispc_cinfo;
  63. int r;
  64. r = dsi_pll_calc_clock_div_pck(dpi.dsidev, is_tft, pck_req,
  65. &dsi_cinfo, &dispc_cinfo);
  66. if (r)
  67. return r;
  68. r = dsi_pll_set_clock_div(dpi.dsidev, &dsi_cinfo);
  69. if (r)
  70. return r;
  71. dss_select_dispc_clk_source(dssdev->clocks.dispc.dispc_fclk_src);
  72. r = dispc_mgr_set_clock_div(dssdev->manager->id, &dispc_cinfo);
  73. if (r) {
  74. dss_select_dispc_clk_source(OMAP_DSS_CLK_SRC_FCK);
  75. return r;
  76. }
  77. *fck = dsi_cinfo.dsi_pll_hsdiv_dispc_clk;
  78. *lck_div = dispc_cinfo.lck_div;
  79. *pck_div = dispc_cinfo.pck_div;
  80. return 0;
  81. }
  82. static int dpi_set_dispc_clk(struct omap_dss_device *dssdev, bool is_tft,
  83. unsigned long pck_req, unsigned long *fck, int *lck_div,
  84. int *pck_div)
  85. {
  86. struct dss_clock_info dss_cinfo;
  87. struct dispc_clock_info dispc_cinfo;
  88. int r;
  89. r = dss_calc_clock_div(is_tft, pck_req, &dss_cinfo, &dispc_cinfo);
  90. if (r)
  91. return r;
  92. r = dss_set_clock_div(&dss_cinfo);
  93. if (r)
  94. return r;
  95. r = dispc_mgr_set_clock_div(dssdev->manager->id, &dispc_cinfo);
  96. if (r)
  97. return r;
  98. *fck = dss_cinfo.fck;
  99. *lck_div = dispc_cinfo.lck_div;
  100. *pck_div = dispc_cinfo.pck_div;
  101. return 0;
  102. }
  103. static int dpi_set_mode(struct omap_dss_device *dssdev)
  104. {
  105. struct omap_video_timings *t = &dssdev->panel.timings;
  106. int lck_div = 0, pck_div = 0;
  107. unsigned long fck = 0;
  108. unsigned long pck;
  109. bool is_tft;
  110. int r = 0;
  111. dispc_mgr_set_pol_freq(dssdev->manager->id, dssdev->panel.config,
  112. dssdev->panel.acbi, dssdev->panel.acb);
  113. is_tft = (dssdev->panel.config & OMAP_DSS_LCD_TFT) != 0;
  114. if (dpi_use_dsi_pll(dssdev))
  115. r = dpi_set_dsi_clk(dssdev, is_tft, t->pixel_clock * 1000,
  116. &fck, &lck_div, &pck_div);
  117. else
  118. r = dpi_set_dispc_clk(dssdev, is_tft, t->pixel_clock * 1000,
  119. &fck, &lck_div, &pck_div);
  120. if (r)
  121. return r;
  122. pck = fck / lck_div / pck_div / 1000;
  123. if (pck != t->pixel_clock) {
  124. DSSWARN("Could not find exact pixel clock. "
  125. "Requested %d kHz, got %lu kHz\n",
  126. t->pixel_clock, pck);
  127. t->pixel_clock = pck;
  128. }
  129. dispc_mgr_set_lcd_timings(dssdev->manager->id, t);
  130. return 0;
  131. }
  132. static void dpi_basic_init(struct omap_dss_device *dssdev)
  133. {
  134. bool is_tft;
  135. is_tft = (dssdev->panel.config & OMAP_DSS_LCD_TFT) != 0;
  136. dispc_mgr_set_io_pad_mode(DSS_IO_PAD_MODE_BYPASS);
  137. dispc_mgr_enable_stallmode(dssdev->manager->id, false);
  138. dispc_mgr_set_lcd_display_type(dssdev->manager->id, is_tft ?
  139. OMAP_DSS_LCD_DISPLAY_TFT : OMAP_DSS_LCD_DISPLAY_STN);
  140. dispc_mgr_set_tft_data_lines(dssdev->manager->id,
  141. dssdev->phy.dpi.data_lines);
  142. }
  143. int omapdss_dpi_display_enable(struct omap_dss_device *dssdev)
  144. {
  145. int r;
  146. if (dssdev->manager == NULL) {
  147. DSSERR("failed to enable display: no manager\n");
  148. return -ENODEV;
  149. }
  150. r = omap_dss_start_device(dssdev);
  151. if (r) {
  152. DSSERR("failed to start device\n");
  153. goto err_start_dev;
  154. }
  155. if (cpu_is_omap34xx()) {
  156. r = regulator_enable(dpi.vdds_dsi_reg);
  157. if (r)
  158. goto err_reg_enable;
  159. }
  160. r = dss_runtime_get();
  161. if (r)
  162. goto err_get_dss;
  163. r = dispc_runtime_get();
  164. if (r)
  165. goto err_get_dispc;
  166. dpi_basic_init(dssdev);
  167. if (dpi_use_dsi_pll(dssdev)) {
  168. r = dsi_runtime_get(dpi.dsidev);
  169. if (r)
  170. goto err_get_dsi;
  171. r = dsi_pll_init(dpi.dsidev, 0, 1);
  172. if (r)
  173. goto err_dsi_pll_init;
  174. }
  175. r = dpi_set_mode(dssdev);
  176. if (r)
  177. goto err_set_mode;
  178. mdelay(2);
  179. dssdev->manager->enable(dssdev->manager);
  180. return 0;
  181. err_set_mode:
  182. if (dpi_use_dsi_pll(dssdev))
  183. dsi_pll_uninit(dpi.dsidev, true);
  184. err_dsi_pll_init:
  185. if (dpi_use_dsi_pll(dssdev))
  186. dsi_runtime_put(dpi.dsidev);
  187. err_get_dsi:
  188. dispc_runtime_put();
  189. err_get_dispc:
  190. dss_runtime_put();
  191. err_get_dss:
  192. if (cpu_is_omap34xx())
  193. regulator_disable(dpi.vdds_dsi_reg);
  194. err_reg_enable:
  195. omap_dss_stop_device(dssdev);
  196. err_start_dev:
  197. return r;
  198. }
  199. EXPORT_SYMBOL(omapdss_dpi_display_enable);
  200. void omapdss_dpi_display_disable(struct omap_dss_device *dssdev)
  201. {
  202. dssdev->manager->disable(dssdev->manager);
  203. if (dpi_use_dsi_pll(dssdev)) {
  204. dss_select_dispc_clk_source(OMAP_DSS_CLK_SRC_FCK);
  205. dsi_pll_uninit(dpi.dsidev, true);
  206. dsi_runtime_put(dpi.dsidev);
  207. }
  208. dispc_runtime_put();
  209. dss_runtime_put();
  210. if (cpu_is_omap34xx())
  211. regulator_disable(dpi.vdds_dsi_reg);
  212. omap_dss_stop_device(dssdev);
  213. }
  214. EXPORT_SYMBOL(omapdss_dpi_display_disable);
  215. void dpi_set_timings(struct omap_dss_device *dssdev,
  216. struct omap_video_timings *timings)
  217. {
  218. int r;
  219. DSSDBG("dpi_set_timings\n");
  220. dssdev->panel.timings = *timings;
  221. if (dssdev->state == OMAP_DSS_DISPLAY_ACTIVE) {
  222. r = dss_runtime_get();
  223. if (r)
  224. return;
  225. r = dispc_runtime_get();
  226. if (r) {
  227. dss_runtime_put();
  228. return;
  229. }
  230. dpi_set_mode(dssdev);
  231. dispc_mgr_go(dssdev->manager->id);
  232. dispc_runtime_put();
  233. dss_runtime_put();
  234. }
  235. }
  236. EXPORT_SYMBOL(dpi_set_timings);
  237. int dpi_check_timings(struct omap_dss_device *dssdev,
  238. struct omap_video_timings *timings)
  239. {
  240. bool is_tft;
  241. int r;
  242. int lck_div, pck_div;
  243. unsigned long fck;
  244. unsigned long pck;
  245. struct dispc_clock_info dispc_cinfo;
  246. if (!dispc_lcd_timings_ok(timings))
  247. return -EINVAL;
  248. if (timings->pixel_clock == 0)
  249. return -EINVAL;
  250. is_tft = (dssdev->panel.config & OMAP_DSS_LCD_TFT) != 0;
  251. if (dpi_use_dsi_pll(dssdev)) {
  252. struct dsi_clock_info dsi_cinfo;
  253. r = dsi_pll_calc_clock_div_pck(dpi.dsidev, is_tft,
  254. timings->pixel_clock * 1000,
  255. &dsi_cinfo, &dispc_cinfo);
  256. if (r)
  257. return r;
  258. fck = dsi_cinfo.dsi_pll_hsdiv_dispc_clk;
  259. } else {
  260. struct dss_clock_info dss_cinfo;
  261. r = dss_calc_clock_div(is_tft, timings->pixel_clock * 1000,
  262. &dss_cinfo, &dispc_cinfo);
  263. if (r)
  264. return r;
  265. fck = dss_cinfo.fck;
  266. }
  267. lck_div = dispc_cinfo.lck_div;
  268. pck_div = dispc_cinfo.pck_div;
  269. pck = fck / lck_div / pck_div / 1000;
  270. timings->pixel_clock = pck;
  271. return 0;
  272. }
  273. EXPORT_SYMBOL(dpi_check_timings);
  274. int dpi_init_display(struct omap_dss_device *dssdev)
  275. {
  276. DSSDBG("init_display\n");
  277. if (cpu_is_omap34xx() && dpi.vdds_dsi_reg == NULL) {
  278. struct regulator *vdds_dsi;
  279. vdds_dsi = dss_get_vdds_dsi();
  280. if (IS_ERR(vdds_dsi)) {
  281. DSSERR("can't get VDDS_DSI regulator\n");
  282. return PTR_ERR(vdds_dsi);
  283. }
  284. dpi.vdds_dsi_reg = vdds_dsi;
  285. }
  286. if (dpi_use_dsi_pll(dssdev)) {
  287. enum omap_dss_clk_source dispc_fclk_src =
  288. dssdev->clocks.dispc.dispc_fclk_src;
  289. dpi.dsidev = dpi_get_dsidev(dispc_fclk_src);
  290. }
  291. return 0;
  292. }
  293. int dpi_init(void)
  294. {
  295. return 0;
  296. }
  297. void dpi_exit(void)
  298. {
  299. }