display.c 9.4 KB

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