display.c 8.4 KB

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