display.c 9.4 KB

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