display.c 14 KB

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