display.c 12 KB

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