display.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554
  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 "omap_hwmod.h"
  27. #include "omap_device.h"
  28. #include "omap-pm.h"
  29. #include "common.h"
  30. #include "soc.h"
  31. #include "iomap.h"
  32. #include "control.h"
  33. #include "display.h"
  34. #include "prm.h"
  35. #define DISPC_CONTROL 0x0040
  36. #define DISPC_CONTROL2 0x0238
  37. #define DISPC_CONTROL3 0x0848
  38. #define DISPC_IRQSTATUS 0x0018
  39. #define DSS_SYSCONFIG 0x10
  40. #define DSS_SYSSTATUS 0x14
  41. #define DSS_CONTROL 0x40
  42. #define DSS_SDI_CONTROL 0x44
  43. #define DSS_PLL_CONTROL 0x48
  44. #define LCD_EN_MASK (0x1 << 0)
  45. #define DIGIT_EN_MASK (0x1 << 1)
  46. #define FRAMEDONE_IRQ_SHIFT 0
  47. #define EVSYNC_EVEN_IRQ_SHIFT 2
  48. #define EVSYNC_ODD_IRQ_SHIFT 3
  49. #define FRAMEDONE2_IRQ_SHIFT 22
  50. #define FRAMEDONE3_IRQ_SHIFT 30
  51. #define FRAMEDONETV_IRQ_SHIFT 24
  52. /*
  53. * FRAMEDONE_IRQ_TIMEOUT: how long (in milliseconds) to wait during DISPC
  54. * reset before deciding that something has gone wrong
  55. */
  56. #define FRAMEDONE_IRQ_TIMEOUT 100
  57. static struct platform_device omap_display_device = {
  58. .name = "omapdss",
  59. .id = -1,
  60. .dev = {
  61. .platform_data = NULL,
  62. },
  63. };
  64. struct omap_dss_hwmod_data {
  65. const char *oh_name;
  66. const char *dev_name;
  67. const int id;
  68. };
  69. static const struct omap_dss_hwmod_data omap2_dss_hwmod_data[] __initconst = {
  70. { "dss_core", "omapdss_dss", -1 },
  71. { "dss_dispc", "omapdss_dispc", -1 },
  72. { "dss_rfbi", "omapdss_rfbi", -1 },
  73. { "dss_venc", "omapdss_venc", -1 },
  74. };
  75. static const struct omap_dss_hwmod_data omap3_dss_hwmod_data[] __initconst = {
  76. { "dss_core", "omapdss_dss", -1 },
  77. { "dss_dispc", "omapdss_dispc", -1 },
  78. { "dss_rfbi", "omapdss_rfbi", -1 },
  79. { "dss_venc", "omapdss_venc", -1 },
  80. { "dss_dsi1", "omapdss_dsi", 0 },
  81. };
  82. static const struct omap_dss_hwmod_data omap4_dss_hwmod_data[] __initconst = {
  83. { "dss_core", "omapdss_dss", -1 },
  84. { "dss_dispc", "omapdss_dispc", -1 },
  85. { "dss_rfbi", "omapdss_rfbi", -1 },
  86. { "dss_dsi1", "omapdss_dsi", 0 },
  87. { "dss_dsi2", "omapdss_dsi", 1 },
  88. { "dss_hdmi", "omapdss_hdmi", -1 },
  89. };
  90. static int omap4_dsi_mux_pads(int dsi_id, unsigned lanes)
  91. {
  92. u32 enable_mask, enable_shift;
  93. u32 pipd_mask, pipd_shift;
  94. u32 reg;
  95. if (dsi_id == 0) {
  96. enable_mask = OMAP4_DSI1_LANEENABLE_MASK;
  97. enable_shift = OMAP4_DSI1_LANEENABLE_SHIFT;
  98. pipd_mask = OMAP4_DSI1_PIPD_MASK;
  99. pipd_shift = OMAP4_DSI1_PIPD_SHIFT;
  100. } else if (dsi_id == 1) {
  101. enable_mask = OMAP4_DSI2_LANEENABLE_MASK;
  102. enable_shift = OMAP4_DSI2_LANEENABLE_SHIFT;
  103. pipd_mask = OMAP4_DSI2_PIPD_MASK;
  104. pipd_shift = OMAP4_DSI2_PIPD_SHIFT;
  105. } else {
  106. return -ENODEV;
  107. }
  108. reg = omap4_ctrl_pad_readl(OMAP4_CTRL_MODULE_PAD_CORE_CONTROL_DSIPHY);
  109. reg &= ~enable_mask;
  110. reg &= ~pipd_mask;
  111. reg |= (lanes << enable_shift) & enable_mask;
  112. reg |= (lanes << pipd_shift) & pipd_mask;
  113. omap4_ctrl_pad_writel(reg, OMAP4_CTRL_MODULE_PAD_CORE_CONTROL_DSIPHY);
  114. return 0;
  115. }
  116. static int omap_dsi_enable_pads(int dsi_id, unsigned lane_mask)
  117. {
  118. if (cpu_is_omap44xx())
  119. return omap4_dsi_mux_pads(dsi_id, lane_mask);
  120. return 0;
  121. }
  122. static void omap_dsi_disable_pads(int dsi_id, unsigned lane_mask)
  123. {
  124. if (cpu_is_omap44xx())
  125. omap4_dsi_mux_pads(dsi_id, 0);
  126. }
  127. static int omap_dss_set_min_bus_tput(struct device *dev, unsigned long tput)
  128. {
  129. return omap_pm_set_min_bus_tput(dev, OCP_INITIATOR_AGENT, tput);
  130. }
  131. static struct platform_device *create_dss_pdev(const char *pdev_name,
  132. int pdev_id, const char *oh_name, void *pdata, int pdata_len,
  133. struct platform_device *parent)
  134. {
  135. struct platform_device *pdev;
  136. struct omap_device *od;
  137. struct omap_hwmod *ohs[1];
  138. struct omap_hwmod *oh;
  139. int r;
  140. oh = omap_hwmod_lookup(oh_name);
  141. if (!oh) {
  142. pr_err("Could not look up %s\n", oh_name);
  143. r = -ENODEV;
  144. goto err;
  145. }
  146. pdev = platform_device_alloc(pdev_name, pdev_id);
  147. if (!pdev) {
  148. pr_err("Could not create pdev for %s\n", pdev_name);
  149. r = -ENOMEM;
  150. goto err;
  151. }
  152. if (parent != NULL)
  153. pdev->dev.parent = &parent->dev;
  154. if (pdev->id != -1)
  155. dev_set_name(&pdev->dev, "%s.%d", pdev->name, pdev->id);
  156. else
  157. dev_set_name(&pdev->dev, "%s", pdev->name);
  158. ohs[0] = oh;
  159. od = omap_device_alloc(pdev, ohs, 1);
  160. if (IS_ERR(od)) {
  161. pr_err("Could not alloc omap_device for %s\n", pdev_name);
  162. r = -ENOMEM;
  163. goto err;
  164. }
  165. r = platform_device_add_data(pdev, pdata, pdata_len);
  166. if (r) {
  167. pr_err("Could not set pdata for %s\n", pdev_name);
  168. goto err;
  169. }
  170. r = omap_device_register(pdev);
  171. if (r) {
  172. pr_err("Could not register omap_device for %s\n", pdev_name);
  173. goto err;
  174. }
  175. return pdev;
  176. err:
  177. return ERR_PTR(r);
  178. }
  179. static struct platform_device *create_simple_dss_pdev(const char *pdev_name,
  180. int pdev_id, void *pdata, int pdata_len,
  181. struct platform_device *parent)
  182. {
  183. struct platform_device *pdev;
  184. int r;
  185. pdev = platform_device_alloc(pdev_name, pdev_id);
  186. if (!pdev) {
  187. pr_err("Could not create pdev for %s\n", pdev_name);
  188. r = -ENOMEM;
  189. goto err;
  190. }
  191. if (parent != NULL)
  192. pdev->dev.parent = &parent->dev;
  193. if (pdev->id != -1)
  194. dev_set_name(&pdev->dev, "%s.%d", pdev->name, pdev->id);
  195. else
  196. dev_set_name(&pdev->dev, "%s", pdev->name);
  197. r = platform_device_add_data(pdev, pdata, pdata_len);
  198. if (r) {
  199. pr_err("Could not set pdata for %s\n", pdev_name);
  200. goto err;
  201. }
  202. r = platform_device_add(pdev);
  203. if (r) {
  204. pr_err("Could not register platform_device for %s\n", pdev_name);
  205. goto err;
  206. }
  207. return pdev;
  208. err:
  209. return ERR_PTR(r);
  210. }
  211. static enum omapdss_version __init omap_display_get_version(void)
  212. {
  213. if (cpu_is_omap24xx())
  214. return OMAPDSS_VER_OMAP24xx;
  215. else if (cpu_is_omap3630())
  216. return OMAPDSS_VER_OMAP3630;
  217. else if (cpu_is_omap34xx()) {
  218. if (soc_is_am35xx()) {
  219. return OMAPDSS_VER_AM35xx;
  220. } else {
  221. if (omap_rev() < OMAP3430_REV_ES3_0)
  222. return OMAPDSS_VER_OMAP34xx_ES1;
  223. else
  224. return OMAPDSS_VER_OMAP34xx_ES3;
  225. }
  226. } else if (omap_rev() == OMAP4430_REV_ES1_0)
  227. return OMAPDSS_VER_OMAP4430_ES1;
  228. else if (omap_rev() == OMAP4430_REV_ES2_0 ||
  229. omap_rev() == OMAP4430_REV_ES2_1 ||
  230. omap_rev() == OMAP4430_REV_ES2_2)
  231. return OMAPDSS_VER_OMAP4430_ES2;
  232. else if (cpu_is_omap44xx())
  233. return OMAPDSS_VER_OMAP4;
  234. else if (soc_is_omap54xx())
  235. return OMAPDSS_VER_OMAP5;
  236. else
  237. return OMAPDSS_VER_UNKNOWN;
  238. }
  239. int __init omap_display_init(struct omap_dss_board_info *board_data)
  240. {
  241. int r = 0;
  242. struct platform_device *pdev;
  243. int i, oh_count;
  244. const struct omap_dss_hwmod_data *curr_dss_hwmod;
  245. struct platform_device *dss_pdev;
  246. enum omapdss_version ver;
  247. /* create omapdss device */
  248. ver = omap_display_get_version();
  249. if (ver == OMAPDSS_VER_UNKNOWN) {
  250. pr_err("DSS not supported on this SoC\n");
  251. return -ENODEV;
  252. }
  253. board_data->version = ver;
  254. board_data->dsi_enable_pads = omap_dsi_enable_pads;
  255. board_data->dsi_disable_pads = omap_dsi_disable_pads;
  256. board_data->get_context_loss_count = omap_pm_get_dev_context_loss_count;
  257. board_data->set_min_bus_tput = omap_dss_set_min_bus_tput;
  258. omap_display_device.dev.platform_data = board_data;
  259. r = platform_device_register(&omap_display_device);
  260. if (r < 0) {
  261. pr_err("Unable to register omapdss device\n");
  262. return r;
  263. }
  264. /* create devices for dss hwmods */
  265. if (cpu_is_omap24xx()) {
  266. curr_dss_hwmod = omap2_dss_hwmod_data;
  267. oh_count = ARRAY_SIZE(omap2_dss_hwmod_data);
  268. } else if (cpu_is_omap34xx()) {
  269. curr_dss_hwmod = omap3_dss_hwmod_data;
  270. oh_count = ARRAY_SIZE(omap3_dss_hwmod_data);
  271. } else {
  272. curr_dss_hwmod = omap4_dss_hwmod_data;
  273. oh_count = ARRAY_SIZE(omap4_dss_hwmod_data);
  274. }
  275. /*
  276. * First create the pdev for dss_core, which is used as a parent device
  277. * by the other dss pdevs. Note: dss_core has to be the first item in
  278. * the hwmod list.
  279. */
  280. dss_pdev = create_dss_pdev(curr_dss_hwmod[0].dev_name,
  281. curr_dss_hwmod[0].id,
  282. curr_dss_hwmod[0].oh_name,
  283. board_data, sizeof(*board_data),
  284. NULL);
  285. if (IS_ERR(dss_pdev)) {
  286. pr_err("Could not build omap_device for %s\n",
  287. curr_dss_hwmod[0].oh_name);
  288. return PTR_ERR(dss_pdev);
  289. }
  290. for (i = 1; i < oh_count; i++) {
  291. pdev = create_dss_pdev(curr_dss_hwmod[i].dev_name,
  292. curr_dss_hwmod[i].id,
  293. curr_dss_hwmod[i].oh_name,
  294. board_data, sizeof(*board_data),
  295. dss_pdev);
  296. if (IS_ERR(pdev)) {
  297. pr_err("Could not build omap_device for %s\n",
  298. curr_dss_hwmod[i].oh_name);
  299. return PTR_ERR(pdev);
  300. }
  301. }
  302. /* Create devices for DPI and SDI */
  303. pdev = create_simple_dss_pdev("omapdss_dpi", 0,
  304. board_data, sizeof(*board_data), dss_pdev);
  305. if (IS_ERR(pdev)) {
  306. pr_err("Could not build platform_device for omapdss_dpi\n");
  307. return PTR_ERR(pdev);
  308. }
  309. if (cpu_is_omap34xx()) {
  310. pdev = create_simple_dss_pdev("omapdss_sdi", 0,
  311. board_data, sizeof(*board_data), dss_pdev);
  312. if (IS_ERR(pdev)) {
  313. pr_err("Could not build platform_device for omapdss_sdi\n");
  314. return PTR_ERR(pdev);
  315. }
  316. }
  317. /* create DRM device */
  318. r = omap_init_drm();
  319. if (r < 0) {
  320. pr_err("Unable to register omapdrm device\n");
  321. return r;
  322. }
  323. /* create vrfb device */
  324. r = omap_init_vrfb();
  325. if (r < 0) {
  326. pr_err("Unable to register omapvrfb device\n");
  327. return r;
  328. }
  329. /* create FB device */
  330. r = omap_init_fb();
  331. if (r < 0) {
  332. pr_err("Unable to register omapfb device\n");
  333. return r;
  334. }
  335. /* create V4L2 display device */
  336. r = omap_init_vout();
  337. if (r < 0) {
  338. pr_err("Unable to register omap_vout device\n");
  339. return r;
  340. }
  341. return 0;
  342. }
  343. static void dispc_disable_outputs(void)
  344. {
  345. u32 v, irq_mask = 0;
  346. bool lcd_en, digit_en, lcd2_en = false, lcd3_en = false;
  347. int i;
  348. struct omap_dss_dispc_dev_attr *da;
  349. struct omap_hwmod *oh;
  350. oh = omap_hwmod_lookup("dss_dispc");
  351. if (!oh) {
  352. WARN(1, "display: could not disable outputs during reset - could not find dss_dispc hwmod\n");
  353. return;
  354. }
  355. if (!oh->dev_attr) {
  356. pr_err("display: could not disable outputs during reset due to missing dev_attr\n");
  357. return;
  358. }
  359. da = (struct omap_dss_dispc_dev_attr *)oh->dev_attr;
  360. /* store value of LCDENABLE and DIGITENABLE bits */
  361. v = omap_hwmod_read(oh, DISPC_CONTROL);
  362. lcd_en = v & LCD_EN_MASK;
  363. digit_en = v & DIGIT_EN_MASK;
  364. /* store value of LCDENABLE for LCD2 */
  365. if (da->manager_count > 2) {
  366. v = omap_hwmod_read(oh, DISPC_CONTROL2);
  367. lcd2_en = v & LCD_EN_MASK;
  368. }
  369. /* store value of LCDENABLE for LCD3 */
  370. if (da->manager_count > 3) {
  371. v = omap_hwmod_read(oh, DISPC_CONTROL3);
  372. lcd3_en = v & LCD_EN_MASK;
  373. }
  374. if (!(lcd_en | digit_en | lcd2_en | lcd3_en))
  375. return; /* no managers currently enabled */
  376. /*
  377. * If any manager was enabled, we need to disable it before
  378. * DSS clocks are disabled or DISPC module is reset
  379. */
  380. if (lcd_en)
  381. irq_mask |= 1 << FRAMEDONE_IRQ_SHIFT;
  382. if (digit_en) {
  383. if (da->has_framedonetv_irq) {
  384. irq_mask |= 1 << FRAMEDONETV_IRQ_SHIFT;
  385. } else {
  386. irq_mask |= 1 << EVSYNC_EVEN_IRQ_SHIFT |
  387. 1 << EVSYNC_ODD_IRQ_SHIFT;
  388. }
  389. }
  390. if (lcd2_en)
  391. irq_mask |= 1 << FRAMEDONE2_IRQ_SHIFT;
  392. if (lcd3_en)
  393. irq_mask |= 1 << FRAMEDONE3_IRQ_SHIFT;
  394. /*
  395. * clear any previous FRAMEDONE, FRAMEDONETV,
  396. * EVSYNC_EVEN/ODD, FRAMEDONE2 or FRAMEDONE3 interrupts
  397. */
  398. omap_hwmod_write(irq_mask, oh, DISPC_IRQSTATUS);
  399. /* disable LCD and TV managers */
  400. v = omap_hwmod_read(oh, DISPC_CONTROL);
  401. v &= ~(LCD_EN_MASK | DIGIT_EN_MASK);
  402. omap_hwmod_write(v, oh, DISPC_CONTROL);
  403. /* disable LCD2 manager */
  404. if (da->manager_count > 2) {
  405. v = omap_hwmod_read(oh, DISPC_CONTROL2);
  406. v &= ~LCD_EN_MASK;
  407. omap_hwmod_write(v, oh, DISPC_CONTROL2);
  408. }
  409. /* disable LCD3 manager */
  410. if (da->manager_count > 3) {
  411. v = omap_hwmod_read(oh, DISPC_CONTROL3);
  412. v &= ~LCD_EN_MASK;
  413. omap_hwmod_write(v, oh, DISPC_CONTROL3);
  414. }
  415. i = 0;
  416. while ((omap_hwmod_read(oh, DISPC_IRQSTATUS) & irq_mask) !=
  417. irq_mask) {
  418. i++;
  419. if (i > FRAMEDONE_IRQ_TIMEOUT) {
  420. pr_err("didn't get FRAMEDONE1/2/3 or TV interrupt\n");
  421. break;
  422. }
  423. mdelay(1);
  424. }
  425. }
  426. int omap_dss_reset(struct omap_hwmod *oh)
  427. {
  428. struct omap_hwmod_opt_clk *oc;
  429. int c = 0;
  430. int i, r;
  431. if (!(oh->class->sysc->sysc_flags & SYSS_HAS_RESET_STATUS)) {
  432. pr_err("dss_core: hwmod data doesn't contain reset data\n");
  433. return -EINVAL;
  434. }
  435. for (i = oh->opt_clks_cnt, oc = oh->opt_clks; i > 0; i--, oc++)
  436. if (oc->_clk)
  437. clk_prepare_enable(oc->_clk);
  438. dispc_disable_outputs();
  439. /* clear SDI registers */
  440. if (cpu_is_omap3430()) {
  441. omap_hwmod_write(0x0, oh, DSS_SDI_CONTROL);
  442. omap_hwmod_write(0x0, oh, DSS_PLL_CONTROL);
  443. }
  444. /*
  445. * clear DSS_CONTROL register to switch DSS clock sources to
  446. * PRCM clock, if any
  447. */
  448. omap_hwmod_write(0x0, oh, DSS_CONTROL);
  449. omap_test_timeout((omap_hwmod_read(oh, oh->class->sysc->syss_offs)
  450. & SYSS_RESETDONE_MASK),
  451. MAX_MODULE_SOFTRESET_WAIT, c);
  452. if (c == MAX_MODULE_SOFTRESET_WAIT)
  453. pr_warning("dss_core: waiting for reset to finish failed\n");
  454. else
  455. pr_debug("dss_core: softreset done\n");
  456. for (i = oh->opt_clks_cnt, oc = oh->opt_clks; i > 0; i--, oc++)
  457. if (oc->_clk)
  458. clk_disable_unprepare(oc->_clk);
  459. r = (c == MAX_MODULE_SOFTRESET_WAIT) ? -ETIMEDOUT : 0;
  460. return r;
  461. }