display.c 9.7 KB

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