display.c 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  1. /*
  2. * OMAP2plus display device setup / initialization.
  3. *
  4. * Copyright (C) 2010 Texas Instruments Incorporated - http://www.ti.com/
  5. * Senthilvadivu Guruswamy
  6. * Sumit Semwal
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License version 2 as
  10. * published by the Free Software Foundation.
  11. *
  12. * This program is distributed "as is" WITHOUT ANY WARRANTY of any
  13. * kind, whether express or implied; without even the implied warranty
  14. * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. */
  17. #include <linux/string.h>
  18. #include <linux/kernel.h>
  19. #include <linux/init.h>
  20. #include <linux/platform_device.h>
  21. #include <linux/io.h>
  22. #include <linux/clk.h>
  23. #include <linux/err.h>
  24. #include <video/omapdss.h>
  25. #include <plat/omap_hwmod.h>
  26. #include <plat/omap_device.h>
  27. #include <plat/omap-pm.h>
  28. #include <plat/common.h>
  29. #include "control.h"
  30. #include "display.h"
  31. #define DISPC_CONTROL 0x0040
  32. #define DISPC_CONTROL2 0x0238
  33. #define DISPC_IRQSTATUS 0x0018
  34. #define DSS_SYSCONFIG 0x10
  35. #define DSS_SYSSTATUS 0x14
  36. #define DSS_CONTROL 0x40
  37. #define DSS_SDI_CONTROL 0x44
  38. #define DSS_PLL_CONTROL 0x48
  39. #define LCD_EN_MASK (0x1 << 0)
  40. #define DIGIT_EN_MASK (0x1 << 1)
  41. #define FRAMEDONE_IRQ_SHIFT 0
  42. #define EVSYNC_EVEN_IRQ_SHIFT 2
  43. #define EVSYNC_ODD_IRQ_SHIFT 3
  44. #define FRAMEDONE2_IRQ_SHIFT 22
  45. #define FRAMEDONETV_IRQ_SHIFT 24
  46. /*
  47. * FRAMEDONE_IRQ_TIMEOUT: how long (in milliseconds) to wait during DISPC
  48. * reset before deciding that something has gone wrong
  49. */
  50. #define FRAMEDONE_IRQ_TIMEOUT 100
  51. static struct platform_device omap_display_device = {
  52. .name = "omapdss",
  53. .id = -1,
  54. .dev = {
  55. .platform_data = NULL,
  56. },
  57. };
  58. struct omap_dss_hwmod_data {
  59. const char *oh_name;
  60. const char *dev_name;
  61. const int id;
  62. };
  63. static const struct omap_dss_hwmod_data omap2_dss_hwmod_data[] __initdata = {
  64. { "dss_core", "omapdss_dss", -1 },
  65. { "dss_dispc", "omapdss_dispc", -1 },
  66. { "dss_rfbi", "omapdss_rfbi", -1 },
  67. { "dss_venc", "omapdss_venc", -1 },
  68. };
  69. static const struct omap_dss_hwmod_data omap3_dss_hwmod_data[] __initdata = {
  70. { "dss_core", "omapdss_dss", -1 },
  71. { "dss_dispc", "omapdss_dispc", -1 },
  72. { "dss_rfbi", "omapdss_rfbi", -1 },
  73. { "dss_venc", "omapdss_venc", -1 },
  74. { "dss_dsi1", "omapdss_dsi", 0 },
  75. };
  76. static const struct omap_dss_hwmod_data omap4_dss_hwmod_data[] __initdata = {
  77. { "dss_core", "omapdss_dss", -1 },
  78. { "dss_dispc", "omapdss_dispc", -1 },
  79. { "dss_rfbi", "omapdss_rfbi", -1 },
  80. { "dss_venc", "omapdss_venc", -1 },
  81. { "dss_dsi1", "omapdss_dsi", 0 },
  82. { "dss_dsi2", "omapdss_dsi", 1 },
  83. { "dss_hdmi", "omapdss_hdmi", -1 },
  84. };
  85. static int omap4_dsi_mux_pads(int dsi_id, unsigned lanes)
  86. {
  87. u32 enable_mask, enable_shift;
  88. u32 pipd_mask, pipd_shift;
  89. u32 reg;
  90. if (dsi_id == 0) {
  91. enable_mask = OMAP4_DSI1_LANEENABLE_MASK;
  92. enable_shift = OMAP4_DSI1_LANEENABLE_SHIFT;
  93. pipd_mask = OMAP4_DSI1_PIPD_MASK;
  94. pipd_shift = OMAP4_DSI1_PIPD_SHIFT;
  95. } else if (dsi_id == 1) {
  96. enable_mask = OMAP4_DSI2_LANEENABLE_MASK;
  97. enable_shift = OMAP4_DSI2_LANEENABLE_SHIFT;
  98. pipd_mask = OMAP4_DSI2_PIPD_MASK;
  99. pipd_shift = OMAP4_DSI2_PIPD_SHIFT;
  100. } else {
  101. return -ENODEV;
  102. }
  103. reg = omap4_ctrl_pad_readl(OMAP4_CTRL_MODULE_PAD_CORE_CONTROL_DSIPHY);
  104. reg &= ~enable_mask;
  105. reg &= ~pipd_mask;
  106. reg |= (lanes << enable_shift) & enable_mask;
  107. reg |= (lanes << pipd_shift) & pipd_mask;
  108. omap4_ctrl_pad_writel(reg, OMAP4_CTRL_MODULE_PAD_CORE_CONTROL_DSIPHY);
  109. return 0;
  110. }
  111. static int omap_dsi_enable_pads(int dsi_id, unsigned lane_mask)
  112. {
  113. if (cpu_is_omap44xx())
  114. return omap4_dsi_mux_pads(dsi_id, lane_mask);
  115. return 0;
  116. }
  117. static void omap_dsi_disable_pads(int dsi_id, unsigned lane_mask)
  118. {
  119. if (cpu_is_omap44xx())
  120. omap4_dsi_mux_pads(dsi_id, 0);
  121. }
  122. int __init omap_display_init(struct omap_dss_board_info *board_data)
  123. {
  124. int r = 0;
  125. struct omap_hwmod *oh;
  126. struct platform_device *pdev;
  127. int i, oh_count;
  128. struct omap_display_platform_data pdata;
  129. const struct omap_dss_hwmod_data *curr_dss_hwmod;
  130. memset(&pdata, 0, sizeof(pdata));
  131. if (cpu_is_omap24xx()) {
  132. curr_dss_hwmod = omap2_dss_hwmod_data;
  133. oh_count = ARRAY_SIZE(omap2_dss_hwmod_data);
  134. } else if (cpu_is_omap34xx()) {
  135. curr_dss_hwmod = omap3_dss_hwmod_data;
  136. oh_count = ARRAY_SIZE(omap3_dss_hwmod_data);
  137. } else {
  138. curr_dss_hwmod = omap4_dss_hwmod_data;
  139. oh_count = ARRAY_SIZE(omap4_dss_hwmod_data);
  140. }
  141. if (board_data->dsi_enable_pads == NULL)
  142. board_data->dsi_enable_pads = omap_dsi_enable_pads;
  143. if (board_data->dsi_disable_pads == NULL)
  144. board_data->dsi_disable_pads = omap_dsi_disable_pads;
  145. pdata.board_data = board_data;
  146. pdata.board_data->get_context_loss_count =
  147. omap_pm_get_dev_context_loss_count;
  148. for (i = 0; i < oh_count; i++) {
  149. oh = omap_hwmod_lookup(curr_dss_hwmod[i].oh_name);
  150. if (!oh) {
  151. pr_err("Could not look up %s\n",
  152. curr_dss_hwmod[i].oh_name);
  153. return -ENODEV;
  154. }
  155. pdev = omap_device_build(curr_dss_hwmod[i].dev_name,
  156. curr_dss_hwmod[i].id, oh, &pdata,
  157. sizeof(struct omap_display_platform_data),
  158. NULL, 0, 0);
  159. if (WARN((IS_ERR(pdev)), "Could not build omap_device for %s\n",
  160. curr_dss_hwmod[i].oh_name))
  161. return -ENODEV;
  162. }
  163. omap_display_device.dev.platform_data = board_data;
  164. r = platform_device_register(&omap_display_device);
  165. if (r < 0)
  166. printk(KERN_ERR "Unable to register OMAP-Display device\n");
  167. return r;
  168. }
  169. static void dispc_disable_outputs(void)
  170. {
  171. u32 v, irq_mask = 0;
  172. bool lcd_en, digit_en, lcd2_en = false;
  173. int i;
  174. struct omap_dss_dispc_dev_attr *da;
  175. struct omap_hwmod *oh;
  176. oh = omap_hwmod_lookup("dss_dispc");
  177. if (!oh) {
  178. WARN(1, "display: could not disable outputs during reset - could not find dss_dispc hwmod\n");
  179. return;
  180. }
  181. if (!oh->dev_attr) {
  182. pr_err("display: could not disable outputs during reset due to missing dev_attr\n");
  183. return;
  184. }
  185. da = (struct omap_dss_dispc_dev_attr *)oh->dev_attr;
  186. /* store value of LCDENABLE and DIGITENABLE bits */
  187. v = omap_hwmod_read(oh, DISPC_CONTROL);
  188. lcd_en = v & LCD_EN_MASK;
  189. digit_en = v & DIGIT_EN_MASK;
  190. /* store value of LCDENABLE for LCD2 */
  191. if (da->manager_count > 2) {
  192. v = omap_hwmod_read(oh, DISPC_CONTROL2);
  193. lcd2_en = v & LCD_EN_MASK;
  194. }
  195. if (!(lcd_en | digit_en | lcd2_en))
  196. return; /* no managers currently enabled */
  197. /*
  198. * If any manager was enabled, we need to disable it before
  199. * DSS clocks are disabled or DISPC module is reset
  200. */
  201. if (lcd_en)
  202. irq_mask |= 1 << FRAMEDONE_IRQ_SHIFT;
  203. if (digit_en) {
  204. if (da->has_framedonetv_irq) {
  205. irq_mask |= 1 << FRAMEDONETV_IRQ_SHIFT;
  206. } else {
  207. irq_mask |= 1 << EVSYNC_EVEN_IRQ_SHIFT |
  208. 1 << EVSYNC_ODD_IRQ_SHIFT;
  209. }
  210. }
  211. if (lcd2_en)
  212. irq_mask |= 1 << FRAMEDONE2_IRQ_SHIFT;
  213. /*
  214. * clear any previous FRAMEDONE, FRAMEDONETV,
  215. * EVSYNC_EVEN/ODD or FRAMEDONE2 interrupts
  216. */
  217. omap_hwmod_write(irq_mask, oh, DISPC_IRQSTATUS);
  218. /* disable LCD and TV managers */
  219. v = omap_hwmod_read(oh, DISPC_CONTROL);
  220. v &= ~(LCD_EN_MASK | DIGIT_EN_MASK);
  221. omap_hwmod_write(v, oh, DISPC_CONTROL);
  222. /* disable LCD2 manager */
  223. if (da->manager_count > 2) {
  224. v = omap_hwmod_read(oh, DISPC_CONTROL2);
  225. v &= ~LCD_EN_MASK;
  226. omap_hwmod_write(v, oh, DISPC_CONTROL2);
  227. }
  228. i = 0;
  229. while ((omap_hwmod_read(oh, DISPC_IRQSTATUS) & irq_mask) !=
  230. irq_mask) {
  231. i++;
  232. if (i > FRAMEDONE_IRQ_TIMEOUT) {
  233. pr_err("didn't get FRAMEDONE1/2 or TV interrupt\n");
  234. break;
  235. }
  236. mdelay(1);
  237. }
  238. }
  239. #define MAX_MODULE_SOFTRESET_WAIT 10000
  240. int omap_dss_reset(struct omap_hwmod *oh)
  241. {
  242. struct omap_hwmod_opt_clk *oc;
  243. int c = 0;
  244. int i, r;
  245. if (!(oh->class->sysc->sysc_flags & SYSS_HAS_RESET_STATUS)) {
  246. pr_err("dss_core: hwmod data doesn't contain reset data\n");
  247. return -EINVAL;
  248. }
  249. for (i = oh->opt_clks_cnt, oc = oh->opt_clks; i > 0; i--, oc++)
  250. if (oc->_clk)
  251. clk_enable(oc->_clk);
  252. dispc_disable_outputs();
  253. /* clear SDI registers */
  254. if (cpu_is_omap3430()) {
  255. omap_hwmod_write(0x0, oh, DSS_SDI_CONTROL);
  256. omap_hwmod_write(0x0, oh, DSS_PLL_CONTROL);
  257. }
  258. /*
  259. * clear DSS_CONTROL register to switch DSS clock sources to
  260. * PRCM clock, if any
  261. */
  262. omap_hwmod_write(0x0, oh, DSS_CONTROL);
  263. omap_test_timeout((omap_hwmod_read(oh, oh->class->sysc->syss_offs)
  264. & SYSS_RESETDONE_MASK),
  265. MAX_MODULE_SOFTRESET_WAIT, c);
  266. if (c == MAX_MODULE_SOFTRESET_WAIT)
  267. pr_warning("dss_core: waiting for reset to finish failed\n");
  268. else
  269. pr_debug("dss_core: softreset done\n");
  270. for (i = oh->opt_clks_cnt, oc = oh->opt_clks; i > 0; i--, oc++)
  271. if (oc->_clk)
  272. clk_disable(oc->_clk);
  273. r = (c == MAX_MODULE_SOFTRESET_WAIT) ? -ETIMEDOUT : 0;
  274. return r;
  275. }