display.c 13 KB

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