display.c 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418
  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 <linux/of.h>
  26. #include <linux/of_platform.h>
  27. #include <linux/slab.h>
  28. #include <linux/mfd/syscon.h>
  29. #include <linux/regmap.h>
  30. #include <linux/platform_data/omapdss.h>
  31. #include "omap_hwmod.h"
  32. #include "omap_device.h"
  33. #include "common.h"
  34. #include "soc.h"
  35. #include "iomap.h"
  36. #include "control.h"
  37. #include "display.h"
  38. #include "prm.h"
  39. #define DISPC_CONTROL 0x0040
  40. #define DISPC_CONTROL2 0x0238
  41. #define DISPC_CONTROL3 0x0848
  42. #define DISPC_IRQSTATUS 0x0018
  43. #define DSS_CONTROL 0x40
  44. #define DSS_SDI_CONTROL 0x44
  45. #define DSS_PLL_CONTROL 0x48
  46. #define LCD_EN_MASK (0x1 << 0)
  47. #define DIGIT_EN_MASK (0x1 << 1)
  48. #define FRAMEDONE_IRQ_SHIFT 0
  49. #define EVSYNC_EVEN_IRQ_SHIFT 2
  50. #define EVSYNC_ODD_IRQ_SHIFT 3
  51. #define FRAMEDONE2_IRQ_SHIFT 22
  52. #define FRAMEDONE3_IRQ_SHIFT 30
  53. #define FRAMEDONETV_IRQ_SHIFT 24
  54. /*
  55. * FRAMEDONE_IRQ_TIMEOUT: how long (in milliseconds) to wait during DISPC
  56. * reset before deciding that something has gone wrong
  57. */
  58. #define FRAMEDONE_IRQ_TIMEOUT 100
  59. #if defined(CONFIG_FB_OMAP2)
  60. static struct platform_device omap_display_device = {
  61. .name = "omapdss",
  62. .id = -1,
  63. .dev = {
  64. .platform_data = NULL,
  65. },
  66. };
  67. #define OMAP4_DSIPHY_SYSCON_OFFSET 0x78
  68. static struct regmap *omap4_dsi_mux_syscon;
  69. static int omap4_dsi_mux_pads(int dsi_id, unsigned lanes)
  70. {
  71. u32 enable_mask, enable_shift;
  72. u32 pipd_mask, pipd_shift;
  73. u32 reg;
  74. int ret;
  75. if (dsi_id == 0) {
  76. enable_mask = OMAP4_DSI1_LANEENABLE_MASK;
  77. enable_shift = OMAP4_DSI1_LANEENABLE_SHIFT;
  78. pipd_mask = OMAP4_DSI1_PIPD_MASK;
  79. pipd_shift = OMAP4_DSI1_PIPD_SHIFT;
  80. } else if (dsi_id == 1) {
  81. enable_mask = OMAP4_DSI2_LANEENABLE_MASK;
  82. enable_shift = OMAP4_DSI2_LANEENABLE_SHIFT;
  83. pipd_mask = OMAP4_DSI2_PIPD_MASK;
  84. pipd_shift = OMAP4_DSI2_PIPD_SHIFT;
  85. } else {
  86. return -ENODEV;
  87. }
  88. ret = regmap_read(omap4_dsi_mux_syscon,
  89. OMAP4_DSIPHY_SYSCON_OFFSET,
  90. &reg);
  91. if (ret)
  92. return ret;
  93. reg &= ~enable_mask;
  94. reg &= ~pipd_mask;
  95. reg |= (lanes << enable_shift) & enable_mask;
  96. reg |= (lanes << pipd_shift) & pipd_mask;
  97. regmap_write(omap4_dsi_mux_syscon, OMAP4_DSIPHY_SYSCON_OFFSET, reg);
  98. return 0;
  99. }
  100. static int omap_dsi_enable_pads(int dsi_id, unsigned lane_mask)
  101. {
  102. if (cpu_is_omap44xx())
  103. return omap4_dsi_mux_pads(dsi_id, lane_mask);
  104. return 0;
  105. }
  106. static void omap_dsi_disable_pads(int dsi_id, unsigned lane_mask)
  107. {
  108. if (cpu_is_omap44xx())
  109. omap4_dsi_mux_pads(dsi_id, 0);
  110. }
  111. static enum omapdss_version __init omap_display_get_version(void)
  112. {
  113. if (cpu_is_omap24xx())
  114. return OMAPDSS_VER_OMAP24xx;
  115. else if (cpu_is_omap3630())
  116. return OMAPDSS_VER_OMAP3630;
  117. else if (cpu_is_omap34xx()) {
  118. if (soc_is_am35xx()) {
  119. return OMAPDSS_VER_AM35xx;
  120. } else {
  121. if (omap_rev() < OMAP3430_REV_ES3_0)
  122. return OMAPDSS_VER_OMAP34xx_ES1;
  123. else
  124. return OMAPDSS_VER_OMAP34xx_ES3;
  125. }
  126. } else if (omap_rev() == OMAP4430_REV_ES1_0)
  127. return OMAPDSS_VER_OMAP4430_ES1;
  128. else if (omap_rev() == OMAP4430_REV_ES2_0 ||
  129. omap_rev() == OMAP4430_REV_ES2_1 ||
  130. omap_rev() == OMAP4430_REV_ES2_2)
  131. return OMAPDSS_VER_OMAP4430_ES2;
  132. else if (cpu_is_omap44xx())
  133. return OMAPDSS_VER_OMAP4;
  134. else if (soc_is_omap54xx())
  135. return OMAPDSS_VER_OMAP5;
  136. else if (soc_is_am43xx())
  137. return OMAPDSS_VER_AM43xx;
  138. else if (soc_is_dra7xx())
  139. return OMAPDSS_VER_DRA7xx;
  140. else
  141. return OMAPDSS_VER_UNKNOWN;
  142. }
  143. static int __init omapdss_init_fbdev(void)
  144. {
  145. static struct omap_dss_board_info board_data = {
  146. .dsi_enable_pads = omap_dsi_enable_pads,
  147. .dsi_disable_pads = omap_dsi_disable_pads,
  148. };
  149. struct device_node *node;
  150. int r;
  151. board_data.version = omap_display_get_version();
  152. if (board_data.version == OMAPDSS_VER_UNKNOWN) {
  153. pr_err("DSS not supported on this SoC\n");
  154. return -ENODEV;
  155. }
  156. omap_display_device.dev.platform_data = &board_data;
  157. r = platform_device_register(&omap_display_device);
  158. if (r < 0) {
  159. pr_err("Unable to register omapdss device\n");
  160. return r;
  161. }
  162. /* create vrfb device */
  163. r = omap_init_vrfb();
  164. if (r < 0) {
  165. pr_err("Unable to register omapvrfb device\n");
  166. return r;
  167. }
  168. /* create FB device */
  169. r = omap_init_fb();
  170. if (r < 0) {
  171. pr_err("Unable to register omapfb device\n");
  172. return r;
  173. }
  174. /* create V4L2 display device */
  175. r = omap_init_vout();
  176. if (r < 0) {
  177. pr_err("Unable to register omap_vout device\n");
  178. return r;
  179. }
  180. /* add DSI info for omap4 */
  181. node = of_find_node_by_name(NULL, "omap4_padconf_global");
  182. if (node)
  183. omap4_dsi_mux_syscon = syscon_node_to_regmap(node);
  184. return 0;
  185. }
  186. static const char * const omapdss_compat_names[] __initconst = {
  187. "ti,omap2-dss",
  188. "ti,omap3-dss",
  189. "ti,omap4-dss",
  190. "ti,omap5-dss",
  191. "ti,dra7-dss",
  192. };
  193. static struct device_node * __init omapdss_find_dss_of_node(void)
  194. {
  195. struct device_node *node;
  196. int i;
  197. for (i = 0; i < ARRAY_SIZE(omapdss_compat_names); ++i) {
  198. node = of_find_compatible_node(NULL, NULL,
  199. omapdss_compat_names[i]);
  200. if (node)
  201. return node;
  202. }
  203. return NULL;
  204. }
  205. static int __init omapdss_init_of(void)
  206. {
  207. int r;
  208. struct device_node *node;
  209. struct platform_device *pdev;
  210. /* only create dss helper devices if dss is enabled in the .dts */
  211. node = omapdss_find_dss_of_node();
  212. if (!node)
  213. return 0;
  214. if (!of_device_is_available(node))
  215. return 0;
  216. pdev = of_find_device_by_node(node);
  217. if (!pdev) {
  218. pr_err("Unable to find DSS platform device\n");
  219. return -ENODEV;
  220. }
  221. r = of_platform_populate(node, NULL, NULL, &pdev->dev);
  222. if (r) {
  223. pr_err("Unable to populate DSS submodule devices\n");
  224. return r;
  225. }
  226. return omapdss_init_fbdev();
  227. }
  228. omap_device_initcall(omapdss_init_of);
  229. #endif /* CONFIG_FB_OMAP2 */
  230. static void dispc_disable_outputs(void)
  231. {
  232. u32 v, irq_mask = 0;
  233. bool lcd_en, digit_en, lcd2_en = false, lcd3_en = false;
  234. int i;
  235. struct omap_dss_dispc_dev_attr *da;
  236. struct omap_hwmod *oh;
  237. oh = omap_hwmod_lookup("dss_dispc");
  238. if (!oh) {
  239. WARN(1, "display: could not disable outputs during reset - could not find dss_dispc hwmod\n");
  240. return;
  241. }
  242. if (!oh->dev_attr) {
  243. pr_err("display: could not disable outputs during reset due to missing dev_attr\n");
  244. return;
  245. }
  246. da = (struct omap_dss_dispc_dev_attr *)oh->dev_attr;
  247. /* store value of LCDENABLE and DIGITENABLE bits */
  248. v = omap_hwmod_read(oh, DISPC_CONTROL);
  249. lcd_en = v & LCD_EN_MASK;
  250. digit_en = v & DIGIT_EN_MASK;
  251. /* store value of LCDENABLE for LCD2 */
  252. if (da->manager_count > 2) {
  253. v = omap_hwmod_read(oh, DISPC_CONTROL2);
  254. lcd2_en = v & LCD_EN_MASK;
  255. }
  256. /* store value of LCDENABLE for LCD3 */
  257. if (da->manager_count > 3) {
  258. v = omap_hwmod_read(oh, DISPC_CONTROL3);
  259. lcd3_en = v & LCD_EN_MASK;
  260. }
  261. if (!(lcd_en | digit_en | lcd2_en | lcd3_en))
  262. return; /* no managers currently enabled */
  263. /*
  264. * If any manager was enabled, we need to disable it before
  265. * DSS clocks are disabled or DISPC module is reset
  266. */
  267. if (lcd_en)
  268. irq_mask |= 1 << FRAMEDONE_IRQ_SHIFT;
  269. if (digit_en) {
  270. if (da->has_framedonetv_irq) {
  271. irq_mask |= 1 << FRAMEDONETV_IRQ_SHIFT;
  272. } else {
  273. irq_mask |= 1 << EVSYNC_EVEN_IRQ_SHIFT |
  274. 1 << EVSYNC_ODD_IRQ_SHIFT;
  275. }
  276. }
  277. if (lcd2_en)
  278. irq_mask |= 1 << FRAMEDONE2_IRQ_SHIFT;
  279. if (lcd3_en)
  280. irq_mask |= 1 << FRAMEDONE3_IRQ_SHIFT;
  281. /*
  282. * clear any previous FRAMEDONE, FRAMEDONETV,
  283. * EVSYNC_EVEN/ODD, FRAMEDONE2 or FRAMEDONE3 interrupts
  284. */
  285. omap_hwmod_write(irq_mask, oh, DISPC_IRQSTATUS);
  286. /* disable LCD and TV managers */
  287. v = omap_hwmod_read(oh, DISPC_CONTROL);
  288. v &= ~(LCD_EN_MASK | DIGIT_EN_MASK);
  289. omap_hwmod_write(v, oh, DISPC_CONTROL);
  290. /* disable LCD2 manager */
  291. if (da->manager_count > 2) {
  292. v = omap_hwmod_read(oh, DISPC_CONTROL2);
  293. v &= ~LCD_EN_MASK;
  294. omap_hwmod_write(v, oh, DISPC_CONTROL2);
  295. }
  296. /* disable LCD3 manager */
  297. if (da->manager_count > 3) {
  298. v = omap_hwmod_read(oh, DISPC_CONTROL3);
  299. v &= ~LCD_EN_MASK;
  300. omap_hwmod_write(v, oh, DISPC_CONTROL3);
  301. }
  302. i = 0;
  303. while ((omap_hwmod_read(oh, DISPC_IRQSTATUS) & irq_mask) !=
  304. irq_mask) {
  305. i++;
  306. if (i > FRAMEDONE_IRQ_TIMEOUT) {
  307. pr_err("didn't get FRAMEDONE1/2/3 or TV interrupt\n");
  308. break;
  309. }
  310. mdelay(1);
  311. }
  312. }
  313. int omap_dss_reset(struct omap_hwmod *oh)
  314. {
  315. struct omap_hwmod_opt_clk *oc;
  316. int c = 0;
  317. int i, r;
  318. if (!(oh->class->sysc->sysc_flags & SYSS_HAS_RESET_STATUS)) {
  319. pr_err("dss_core: hwmod data doesn't contain reset data\n");
  320. return -EINVAL;
  321. }
  322. for (i = oh->opt_clks_cnt, oc = oh->opt_clks; i > 0; i--, oc++)
  323. if (oc->_clk)
  324. clk_prepare_enable(oc->_clk);
  325. dispc_disable_outputs();
  326. /* clear SDI registers */
  327. if (cpu_is_omap3430()) {
  328. omap_hwmod_write(0x0, oh, DSS_SDI_CONTROL);
  329. omap_hwmod_write(0x0, oh, DSS_PLL_CONTROL);
  330. }
  331. /*
  332. * clear DSS_CONTROL register to switch DSS clock sources to
  333. * PRCM clock, if any
  334. */
  335. omap_hwmod_write(0x0, oh, DSS_CONTROL);
  336. omap_test_timeout((omap_hwmod_read(oh, oh->class->sysc->syss_offs)
  337. & SYSS_RESETDONE_MASK),
  338. MAX_MODULE_SOFTRESET_WAIT, c);
  339. if (c == MAX_MODULE_SOFTRESET_WAIT)
  340. pr_warn("dss_core: waiting for reset to finish failed\n");
  341. else
  342. pr_debug("dss_core: softreset done\n");
  343. for (i = oh->opt_clks_cnt, oc = oh->opt_clks; i > 0; i--, oc++)
  344. if (oc->_clk)
  345. clk_disable_unprepare(oc->_clk);
  346. r = (c == MAX_MODULE_SOFTRESET_WAIT) ? -ETIMEDOUT : 0;
  347. return r;
  348. }