hdmi5.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * HDMI driver for OMAP5
  4. *
  5. * Copyright (C) 2014 Texas Instruments Incorporated - https://www.ti.com/
  6. *
  7. * Authors:
  8. * Yong Zhi
  9. * Mythri pk
  10. * Archit Taneja <[email protected]>
  11. * Tomi Valkeinen <[email protected]>
  12. */
  13. #define DSS_SUBSYS_NAME "HDMI"
  14. #include <linux/kernel.h>
  15. #include <linux/module.h>
  16. #include <linux/err.h>
  17. #include <linux/io.h>
  18. #include <linux/interrupt.h>
  19. #include <linux/mutex.h>
  20. #include <linux/delay.h>
  21. #include <linux/string.h>
  22. #include <linux/platform_device.h>
  23. #include <linux/pm_runtime.h>
  24. #include <linux/clk.h>
  25. #include <linux/regulator/consumer.h>
  26. #include <linux/component.h>
  27. #include <linux/of.h>
  28. #include <linux/of_graph.h>
  29. #include <sound/omap-hdmi-audio.h>
  30. #include <drm/drm_atomic.h>
  31. #include <drm/drm_atomic_state_helper.h>
  32. #include <drm/drm_edid.h>
  33. #include "omapdss.h"
  34. #include "hdmi5_core.h"
  35. #include "dss.h"
  36. static int hdmi_runtime_get(struct omap_hdmi *hdmi)
  37. {
  38. int r;
  39. DSSDBG("hdmi_runtime_get\n");
  40. r = pm_runtime_get_sync(&hdmi->pdev->dev);
  41. if (WARN_ON(r < 0)) {
  42. pm_runtime_put_noidle(&hdmi->pdev->dev);
  43. return r;
  44. }
  45. return 0;
  46. }
  47. static void hdmi_runtime_put(struct omap_hdmi *hdmi)
  48. {
  49. int r;
  50. DSSDBG("hdmi_runtime_put\n");
  51. r = pm_runtime_put_sync(&hdmi->pdev->dev);
  52. WARN_ON(r < 0 && r != -ENOSYS);
  53. }
  54. static irqreturn_t hdmi_irq_handler(int irq, void *data)
  55. {
  56. struct omap_hdmi *hdmi = data;
  57. struct hdmi_wp_data *wp = &hdmi->wp;
  58. u32 irqstatus;
  59. irqstatus = hdmi_wp_get_irqstatus(wp);
  60. hdmi_wp_set_irqstatus(wp, irqstatus);
  61. if ((irqstatus & HDMI_IRQ_LINK_CONNECT) &&
  62. irqstatus & HDMI_IRQ_LINK_DISCONNECT) {
  63. u32 v;
  64. /*
  65. * If we get both connect and disconnect interrupts at the same
  66. * time, turn off the PHY, clear interrupts, and restart, which
  67. * raises connect interrupt if a cable is connected, or nothing
  68. * if cable is not connected.
  69. */
  70. hdmi_wp_set_phy_pwr(wp, HDMI_PHYPWRCMD_OFF);
  71. /*
  72. * We always get bogus CONNECT & DISCONNECT interrupts when
  73. * setting the PHY to LDOON. To ignore those, we force the RXDET
  74. * line to 0 until the PHY power state has been changed.
  75. */
  76. v = hdmi_read_reg(hdmi->phy.base, HDMI_TXPHY_PAD_CFG_CTRL);
  77. v = FLD_MOD(v, 1, 15, 15); /* FORCE_RXDET_HIGH */
  78. v = FLD_MOD(v, 0, 14, 7); /* RXDET_LINE */
  79. hdmi_write_reg(hdmi->phy.base, HDMI_TXPHY_PAD_CFG_CTRL, v);
  80. hdmi_wp_set_irqstatus(wp, HDMI_IRQ_LINK_CONNECT |
  81. HDMI_IRQ_LINK_DISCONNECT);
  82. hdmi_wp_set_phy_pwr(wp, HDMI_PHYPWRCMD_LDOON);
  83. REG_FLD_MOD(hdmi->phy.base, HDMI_TXPHY_PAD_CFG_CTRL, 0, 15, 15);
  84. } else if (irqstatus & HDMI_IRQ_LINK_CONNECT) {
  85. hdmi_wp_set_phy_pwr(wp, HDMI_PHYPWRCMD_TXON);
  86. } else if (irqstatus & HDMI_IRQ_LINK_DISCONNECT) {
  87. hdmi_wp_set_phy_pwr(wp, HDMI_PHYPWRCMD_LDOON);
  88. }
  89. return IRQ_HANDLED;
  90. }
  91. static int hdmi_power_on_core(struct omap_hdmi *hdmi)
  92. {
  93. int r;
  94. r = regulator_enable(hdmi->vdda_reg);
  95. if (r)
  96. return r;
  97. r = hdmi_runtime_get(hdmi);
  98. if (r)
  99. goto err_runtime_get;
  100. /* Make selection of HDMI in DSS */
  101. dss_select_hdmi_venc_clk_source(hdmi->dss, DSS_HDMI_M_PCLK);
  102. hdmi->core_enabled = true;
  103. return 0;
  104. err_runtime_get:
  105. regulator_disable(hdmi->vdda_reg);
  106. return r;
  107. }
  108. static void hdmi_power_off_core(struct omap_hdmi *hdmi)
  109. {
  110. hdmi->core_enabled = false;
  111. hdmi_runtime_put(hdmi);
  112. regulator_disable(hdmi->vdda_reg);
  113. }
  114. static int hdmi_power_on_full(struct omap_hdmi *hdmi)
  115. {
  116. int r;
  117. const struct videomode *vm;
  118. struct dss_pll_clock_info hdmi_cinfo = { 0 };
  119. unsigned int pc;
  120. r = hdmi_power_on_core(hdmi);
  121. if (r)
  122. return r;
  123. vm = &hdmi->cfg.vm;
  124. DSSDBG("hdmi_power_on hactive= %d vactive = %d\n", vm->hactive,
  125. vm->vactive);
  126. pc = vm->pixelclock;
  127. if (vm->flags & DISPLAY_FLAGS_DOUBLECLK)
  128. pc *= 2;
  129. /* DSS_HDMI_TCLK is bitclk / 10 */
  130. pc *= 10;
  131. dss_pll_calc_b(&hdmi->pll.pll, clk_get_rate(hdmi->pll.pll.clkin),
  132. pc, &hdmi_cinfo);
  133. /* disable and clear irqs */
  134. hdmi_wp_clear_irqenable(&hdmi->wp, 0xffffffff);
  135. hdmi_wp_set_irqstatus(&hdmi->wp,
  136. hdmi_wp_get_irqstatus(&hdmi->wp));
  137. r = dss_pll_enable(&hdmi->pll.pll);
  138. if (r) {
  139. DSSERR("Failed to enable PLL\n");
  140. goto err_pll_enable;
  141. }
  142. r = dss_pll_set_config(&hdmi->pll.pll, &hdmi_cinfo);
  143. if (r) {
  144. DSSERR("Failed to configure PLL\n");
  145. goto err_pll_cfg;
  146. }
  147. r = hdmi_phy_configure(&hdmi->phy, hdmi_cinfo.clkdco,
  148. hdmi_cinfo.clkout[0]);
  149. if (r) {
  150. DSSDBG("Failed to start PHY\n");
  151. goto err_phy_cfg;
  152. }
  153. r = hdmi_wp_set_phy_pwr(&hdmi->wp, HDMI_PHYPWRCMD_LDOON);
  154. if (r)
  155. goto err_phy_pwr;
  156. hdmi5_configure(&hdmi->core, &hdmi->wp, &hdmi->cfg);
  157. r = dss_mgr_enable(&hdmi->output);
  158. if (r)
  159. goto err_mgr_enable;
  160. r = hdmi_wp_video_start(&hdmi->wp);
  161. if (r)
  162. goto err_vid_enable;
  163. hdmi_wp_set_irqenable(&hdmi->wp,
  164. HDMI_IRQ_LINK_CONNECT | HDMI_IRQ_LINK_DISCONNECT);
  165. return 0;
  166. err_vid_enable:
  167. dss_mgr_disable(&hdmi->output);
  168. err_mgr_enable:
  169. hdmi_wp_set_phy_pwr(&hdmi->wp, HDMI_PHYPWRCMD_OFF);
  170. err_phy_pwr:
  171. err_phy_cfg:
  172. err_pll_cfg:
  173. dss_pll_disable(&hdmi->pll.pll);
  174. err_pll_enable:
  175. hdmi_power_off_core(hdmi);
  176. return -EIO;
  177. }
  178. static void hdmi_power_off_full(struct omap_hdmi *hdmi)
  179. {
  180. hdmi_wp_clear_irqenable(&hdmi->wp, 0xffffffff);
  181. hdmi_wp_video_stop(&hdmi->wp);
  182. dss_mgr_disable(&hdmi->output);
  183. hdmi_wp_set_phy_pwr(&hdmi->wp, HDMI_PHYPWRCMD_OFF);
  184. dss_pll_disable(&hdmi->pll.pll);
  185. hdmi_power_off_core(hdmi);
  186. }
  187. static int hdmi_dump_regs(struct seq_file *s, void *p)
  188. {
  189. struct omap_hdmi *hdmi = s->private;
  190. mutex_lock(&hdmi->lock);
  191. if (hdmi_runtime_get(hdmi)) {
  192. mutex_unlock(&hdmi->lock);
  193. return 0;
  194. }
  195. hdmi_wp_dump(&hdmi->wp, s);
  196. hdmi_pll_dump(&hdmi->pll, s);
  197. hdmi_phy_dump(&hdmi->phy, s);
  198. hdmi5_core_dump(&hdmi->core, s);
  199. hdmi_runtime_put(hdmi);
  200. mutex_unlock(&hdmi->lock);
  201. return 0;
  202. }
  203. static void hdmi_start_audio_stream(struct omap_hdmi *hd)
  204. {
  205. REG_FLD_MOD(hd->wp.base, HDMI_WP_SYSCONFIG, 1, 3, 2);
  206. hdmi_wp_audio_enable(&hd->wp, true);
  207. hdmi_wp_audio_core_req_enable(&hd->wp, true);
  208. }
  209. static void hdmi_stop_audio_stream(struct omap_hdmi *hd)
  210. {
  211. hdmi_wp_audio_core_req_enable(&hd->wp, false);
  212. hdmi_wp_audio_enable(&hd->wp, false);
  213. REG_FLD_MOD(hd->wp.base, HDMI_WP_SYSCONFIG, hd->wp_idlemode, 3, 2);
  214. }
  215. static int hdmi_core_enable(struct omap_hdmi *hdmi)
  216. {
  217. int r = 0;
  218. DSSDBG("ENTER omapdss_hdmi_core_enable\n");
  219. mutex_lock(&hdmi->lock);
  220. r = hdmi_power_on_core(hdmi);
  221. if (r) {
  222. DSSERR("failed to power on device\n");
  223. goto err0;
  224. }
  225. mutex_unlock(&hdmi->lock);
  226. return 0;
  227. err0:
  228. mutex_unlock(&hdmi->lock);
  229. return r;
  230. }
  231. static void hdmi_core_disable(struct omap_hdmi *hdmi)
  232. {
  233. DSSDBG("Enter omapdss_hdmi_core_disable\n");
  234. mutex_lock(&hdmi->lock);
  235. hdmi_power_off_core(hdmi);
  236. mutex_unlock(&hdmi->lock);
  237. }
  238. /* -----------------------------------------------------------------------------
  239. * DRM Bridge Operations
  240. */
  241. static int hdmi5_bridge_attach(struct drm_bridge *bridge,
  242. enum drm_bridge_attach_flags flags)
  243. {
  244. struct omap_hdmi *hdmi = drm_bridge_to_hdmi(bridge);
  245. if (!(flags & DRM_BRIDGE_ATTACH_NO_CONNECTOR))
  246. return -EINVAL;
  247. return drm_bridge_attach(bridge->encoder, hdmi->output.next_bridge,
  248. bridge, flags);
  249. }
  250. static void hdmi5_bridge_mode_set(struct drm_bridge *bridge,
  251. const struct drm_display_mode *mode,
  252. const struct drm_display_mode *adjusted_mode)
  253. {
  254. struct omap_hdmi *hdmi = drm_bridge_to_hdmi(bridge);
  255. mutex_lock(&hdmi->lock);
  256. drm_display_mode_to_videomode(adjusted_mode, &hdmi->cfg.vm);
  257. dispc_set_tv_pclk(hdmi->dss->dispc, adjusted_mode->clock * 1000);
  258. mutex_unlock(&hdmi->lock);
  259. }
  260. static void hdmi5_bridge_enable(struct drm_bridge *bridge,
  261. struct drm_bridge_state *bridge_state)
  262. {
  263. struct omap_hdmi *hdmi = drm_bridge_to_hdmi(bridge);
  264. struct drm_atomic_state *state = bridge_state->base.state;
  265. struct drm_connector_state *conn_state;
  266. struct drm_connector *connector;
  267. struct drm_crtc_state *crtc_state;
  268. unsigned long flags;
  269. int ret;
  270. /*
  271. * None of these should fail, as the bridge can't be enabled without a
  272. * valid CRTC to connector path with fully populated new states.
  273. */
  274. connector = drm_atomic_get_new_connector_for_encoder(state,
  275. bridge->encoder);
  276. if (WARN_ON(!connector))
  277. return;
  278. conn_state = drm_atomic_get_new_connector_state(state, connector);
  279. if (WARN_ON(!conn_state))
  280. return;
  281. crtc_state = drm_atomic_get_new_crtc_state(state, conn_state->crtc);
  282. if (WARN_ON(!crtc_state))
  283. return;
  284. hdmi->cfg.hdmi_dvi_mode = connector->display_info.is_hdmi
  285. ? HDMI_HDMI : HDMI_DVI;
  286. if (connector->display_info.is_hdmi) {
  287. const struct drm_display_mode *mode;
  288. struct hdmi_avi_infoframe avi;
  289. mode = &crtc_state->adjusted_mode;
  290. ret = drm_hdmi_avi_infoframe_from_display_mode(&avi, connector,
  291. mode);
  292. if (ret == 0)
  293. hdmi->cfg.infoframe = avi;
  294. }
  295. mutex_lock(&hdmi->lock);
  296. ret = hdmi_power_on_full(hdmi);
  297. if (ret) {
  298. DSSERR("failed to power on device\n");
  299. goto done;
  300. }
  301. if (hdmi->audio_configured) {
  302. ret = hdmi5_audio_config(&hdmi->core, &hdmi->wp,
  303. &hdmi->audio_config,
  304. hdmi->cfg.vm.pixelclock);
  305. if (ret) {
  306. DSSERR("Error restoring audio configuration: %d", ret);
  307. hdmi->audio_abort_cb(&hdmi->pdev->dev);
  308. hdmi->audio_configured = false;
  309. }
  310. }
  311. spin_lock_irqsave(&hdmi->audio_playing_lock, flags);
  312. if (hdmi->audio_configured && hdmi->audio_playing)
  313. hdmi_start_audio_stream(hdmi);
  314. hdmi->display_enabled = true;
  315. spin_unlock_irqrestore(&hdmi->audio_playing_lock, flags);
  316. done:
  317. mutex_unlock(&hdmi->lock);
  318. }
  319. static void hdmi5_bridge_disable(struct drm_bridge *bridge,
  320. struct drm_bridge_state *bridge_state)
  321. {
  322. struct omap_hdmi *hdmi = drm_bridge_to_hdmi(bridge);
  323. unsigned long flags;
  324. mutex_lock(&hdmi->lock);
  325. spin_lock_irqsave(&hdmi->audio_playing_lock, flags);
  326. hdmi_stop_audio_stream(hdmi);
  327. hdmi->display_enabled = false;
  328. spin_unlock_irqrestore(&hdmi->audio_playing_lock, flags);
  329. hdmi_power_off_full(hdmi);
  330. mutex_unlock(&hdmi->lock);
  331. }
  332. static struct edid *hdmi5_bridge_get_edid(struct drm_bridge *bridge,
  333. struct drm_connector *connector)
  334. {
  335. struct omap_hdmi *hdmi = drm_bridge_to_hdmi(bridge);
  336. struct edid *edid;
  337. bool need_enable;
  338. int idlemode;
  339. int r;
  340. need_enable = hdmi->core_enabled == false;
  341. if (need_enable) {
  342. r = hdmi_core_enable(hdmi);
  343. if (r)
  344. return NULL;
  345. }
  346. mutex_lock(&hdmi->lock);
  347. r = hdmi_runtime_get(hdmi);
  348. BUG_ON(r);
  349. idlemode = REG_GET(hdmi->wp.base, HDMI_WP_SYSCONFIG, 3, 2);
  350. /* No-idle mode */
  351. REG_FLD_MOD(hdmi->wp.base, HDMI_WP_SYSCONFIG, 1, 3, 2);
  352. hdmi5_core_ddc_init(&hdmi->core);
  353. edid = drm_do_get_edid(connector, hdmi5_core_ddc_read, &hdmi->core);
  354. hdmi5_core_ddc_uninit(&hdmi->core);
  355. REG_FLD_MOD(hdmi->wp.base, HDMI_WP_SYSCONFIG, idlemode, 3, 2);
  356. hdmi_runtime_put(hdmi);
  357. mutex_unlock(&hdmi->lock);
  358. if (need_enable)
  359. hdmi_core_disable(hdmi);
  360. return (struct edid *)edid;
  361. }
  362. static const struct drm_bridge_funcs hdmi5_bridge_funcs = {
  363. .attach = hdmi5_bridge_attach,
  364. .mode_set = hdmi5_bridge_mode_set,
  365. .atomic_duplicate_state = drm_atomic_helper_bridge_duplicate_state,
  366. .atomic_destroy_state = drm_atomic_helper_bridge_destroy_state,
  367. .atomic_reset = drm_atomic_helper_bridge_reset,
  368. .atomic_enable = hdmi5_bridge_enable,
  369. .atomic_disable = hdmi5_bridge_disable,
  370. .get_edid = hdmi5_bridge_get_edid,
  371. };
  372. static void hdmi5_bridge_init(struct omap_hdmi *hdmi)
  373. {
  374. hdmi->bridge.funcs = &hdmi5_bridge_funcs;
  375. hdmi->bridge.of_node = hdmi->pdev->dev.of_node;
  376. hdmi->bridge.ops = DRM_BRIDGE_OP_EDID;
  377. hdmi->bridge.type = DRM_MODE_CONNECTOR_HDMIA;
  378. drm_bridge_add(&hdmi->bridge);
  379. }
  380. static void hdmi5_bridge_cleanup(struct omap_hdmi *hdmi)
  381. {
  382. drm_bridge_remove(&hdmi->bridge);
  383. }
  384. /* -----------------------------------------------------------------------------
  385. * Audio Callbacks
  386. */
  387. static int hdmi_audio_startup(struct device *dev,
  388. void (*abort_cb)(struct device *dev))
  389. {
  390. struct omap_hdmi *hd = dev_get_drvdata(dev);
  391. mutex_lock(&hd->lock);
  392. WARN_ON(hd->audio_abort_cb != NULL);
  393. hd->audio_abort_cb = abort_cb;
  394. mutex_unlock(&hd->lock);
  395. return 0;
  396. }
  397. static int hdmi_audio_shutdown(struct device *dev)
  398. {
  399. struct omap_hdmi *hd = dev_get_drvdata(dev);
  400. mutex_lock(&hd->lock);
  401. hd->audio_abort_cb = NULL;
  402. hd->audio_configured = false;
  403. hd->audio_playing = false;
  404. mutex_unlock(&hd->lock);
  405. return 0;
  406. }
  407. static int hdmi_audio_start(struct device *dev)
  408. {
  409. struct omap_hdmi *hd = dev_get_drvdata(dev);
  410. unsigned long flags;
  411. spin_lock_irqsave(&hd->audio_playing_lock, flags);
  412. if (hd->display_enabled) {
  413. if (!hdmi_mode_has_audio(&hd->cfg))
  414. DSSERR("%s: Video mode does not support audio\n",
  415. __func__);
  416. hdmi_start_audio_stream(hd);
  417. }
  418. hd->audio_playing = true;
  419. spin_unlock_irqrestore(&hd->audio_playing_lock, flags);
  420. return 0;
  421. }
  422. static void hdmi_audio_stop(struct device *dev)
  423. {
  424. struct omap_hdmi *hd = dev_get_drvdata(dev);
  425. unsigned long flags;
  426. if (!hdmi_mode_has_audio(&hd->cfg))
  427. DSSERR("%s: Video mode does not support audio\n", __func__);
  428. spin_lock_irqsave(&hd->audio_playing_lock, flags);
  429. if (hd->display_enabled)
  430. hdmi_stop_audio_stream(hd);
  431. hd->audio_playing = false;
  432. spin_unlock_irqrestore(&hd->audio_playing_lock, flags);
  433. }
  434. static int hdmi_audio_config(struct device *dev,
  435. struct omap_dss_audio *dss_audio)
  436. {
  437. struct omap_hdmi *hd = dev_get_drvdata(dev);
  438. int ret = 0;
  439. mutex_lock(&hd->lock);
  440. if (hd->display_enabled) {
  441. ret = hdmi5_audio_config(&hd->core, &hd->wp, dss_audio,
  442. hd->cfg.vm.pixelclock);
  443. if (ret)
  444. goto out;
  445. }
  446. hd->audio_configured = true;
  447. hd->audio_config = *dss_audio;
  448. out:
  449. mutex_unlock(&hd->lock);
  450. return ret;
  451. }
  452. static const struct omap_hdmi_audio_ops hdmi_audio_ops = {
  453. .audio_startup = hdmi_audio_startup,
  454. .audio_shutdown = hdmi_audio_shutdown,
  455. .audio_start = hdmi_audio_start,
  456. .audio_stop = hdmi_audio_stop,
  457. .audio_config = hdmi_audio_config,
  458. };
  459. static int hdmi_audio_register(struct omap_hdmi *hdmi)
  460. {
  461. struct omap_hdmi_audio_pdata pdata = {
  462. .dev = &hdmi->pdev->dev,
  463. .version = 5,
  464. .audio_dma_addr = hdmi_wp_get_audio_dma_addr(&hdmi->wp),
  465. .ops = &hdmi_audio_ops,
  466. };
  467. hdmi->audio_pdev = platform_device_register_data(
  468. &hdmi->pdev->dev, "omap-hdmi-audio", PLATFORM_DEVID_AUTO,
  469. &pdata, sizeof(pdata));
  470. if (IS_ERR(hdmi->audio_pdev))
  471. return PTR_ERR(hdmi->audio_pdev);
  472. hdmi_runtime_get(hdmi);
  473. hdmi->wp_idlemode =
  474. REG_GET(hdmi->wp.base, HDMI_WP_SYSCONFIG, 3, 2);
  475. hdmi_runtime_put(hdmi);
  476. return 0;
  477. }
  478. /* -----------------------------------------------------------------------------
  479. * Component Bind & Unbind
  480. */
  481. static int hdmi5_bind(struct device *dev, struct device *master, void *data)
  482. {
  483. struct dss_device *dss = dss_get_device(master);
  484. struct omap_hdmi *hdmi = dev_get_drvdata(dev);
  485. int r;
  486. hdmi->dss = dss;
  487. r = hdmi_pll_init(dss, hdmi->pdev, &hdmi->pll, &hdmi->wp);
  488. if (r)
  489. return r;
  490. r = hdmi_audio_register(hdmi);
  491. if (r) {
  492. DSSERR("Registering HDMI audio failed %d\n", r);
  493. goto err_pll_uninit;
  494. }
  495. hdmi->debugfs = dss_debugfs_create_file(dss, "hdmi", hdmi_dump_regs,
  496. hdmi);
  497. return 0;
  498. err_pll_uninit:
  499. hdmi_pll_uninit(&hdmi->pll);
  500. return r;
  501. }
  502. static void hdmi5_unbind(struct device *dev, struct device *master, void *data)
  503. {
  504. struct omap_hdmi *hdmi = dev_get_drvdata(dev);
  505. dss_debugfs_remove_file(hdmi->debugfs);
  506. if (hdmi->audio_pdev)
  507. platform_device_unregister(hdmi->audio_pdev);
  508. hdmi_pll_uninit(&hdmi->pll);
  509. }
  510. static const struct component_ops hdmi5_component_ops = {
  511. .bind = hdmi5_bind,
  512. .unbind = hdmi5_unbind,
  513. };
  514. /* -----------------------------------------------------------------------------
  515. * Probe & Remove, Suspend & Resume
  516. */
  517. static int hdmi5_init_output(struct omap_hdmi *hdmi)
  518. {
  519. struct omap_dss_device *out = &hdmi->output;
  520. int r;
  521. hdmi5_bridge_init(hdmi);
  522. out->dev = &hdmi->pdev->dev;
  523. out->id = OMAP_DSS_OUTPUT_HDMI;
  524. out->type = OMAP_DISPLAY_TYPE_HDMI;
  525. out->name = "hdmi.0";
  526. out->dispc_channel = OMAP_DSS_CHANNEL_DIGIT;
  527. out->of_port = 0;
  528. r = omapdss_device_init_output(out, &hdmi->bridge);
  529. if (r < 0) {
  530. hdmi5_bridge_cleanup(hdmi);
  531. return r;
  532. }
  533. omapdss_device_register(out);
  534. return 0;
  535. }
  536. static void hdmi5_uninit_output(struct omap_hdmi *hdmi)
  537. {
  538. struct omap_dss_device *out = &hdmi->output;
  539. omapdss_device_unregister(out);
  540. omapdss_device_cleanup_output(out);
  541. hdmi5_bridge_cleanup(hdmi);
  542. }
  543. static int hdmi5_probe_of(struct omap_hdmi *hdmi)
  544. {
  545. struct platform_device *pdev = hdmi->pdev;
  546. struct device_node *node = pdev->dev.of_node;
  547. struct device_node *ep;
  548. int r;
  549. ep = of_graph_get_endpoint_by_regs(node, 0, 0);
  550. if (!ep)
  551. return 0;
  552. r = hdmi_parse_lanes_of(pdev, ep, &hdmi->phy);
  553. of_node_put(ep);
  554. return r;
  555. }
  556. static int hdmi5_probe(struct platform_device *pdev)
  557. {
  558. struct omap_hdmi *hdmi;
  559. int irq;
  560. int r;
  561. hdmi = kzalloc(sizeof(*hdmi), GFP_KERNEL);
  562. if (!hdmi)
  563. return -ENOMEM;
  564. hdmi->pdev = pdev;
  565. dev_set_drvdata(&pdev->dev, hdmi);
  566. mutex_init(&hdmi->lock);
  567. spin_lock_init(&hdmi->audio_playing_lock);
  568. r = hdmi5_probe_of(hdmi);
  569. if (r)
  570. goto err_free;
  571. r = hdmi_wp_init(pdev, &hdmi->wp, 5);
  572. if (r)
  573. goto err_free;
  574. r = hdmi_phy_init(pdev, &hdmi->phy, 5);
  575. if (r)
  576. goto err_free;
  577. r = hdmi5_core_init(pdev, &hdmi->core);
  578. if (r)
  579. goto err_free;
  580. irq = platform_get_irq(pdev, 0);
  581. if (irq < 0) {
  582. DSSERR("platform_get_irq failed\n");
  583. r = -ENODEV;
  584. goto err_free;
  585. }
  586. r = devm_request_threaded_irq(&pdev->dev, irq,
  587. NULL, hdmi_irq_handler,
  588. IRQF_ONESHOT, "OMAP HDMI", hdmi);
  589. if (r) {
  590. DSSERR("HDMI IRQ request failed\n");
  591. goto err_free;
  592. }
  593. hdmi->vdda_reg = devm_regulator_get(&pdev->dev, "vdda");
  594. if (IS_ERR(hdmi->vdda_reg)) {
  595. r = PTR_ERR(hdmi->vdda_reg);
  596. if (r != -EPROBE_DEFER)
  597. DSSERR("can't get VDDA regulator\n");
  598. goto err_free;
  599. }
  600. pm_runtime_enable(&pdev->dev);
  601. r = hdmi5_init_output(hdmi);
  602. if (r)
  603. goto err_pm_disable;
  604. r = component_add(&pdev->dev, &hdmi5_component_ops);
  605. if (r)
  606. goto err_uninit_output;
  607. return 0;
  608. err_uninit_output:
  609. hdmi5_uninit_output(hdmi);
  610. err_pm_disable:
  611. pm_runtime_disable(&pdev->dev);
  612. err_free:
  613. kfree(hdmi);
  614. return r;
  615. }
  616. static int hdmi5_remove(struct platform_device *pdev)
  617. {
  618. struct omap_hdmi *hdmi = platform_get_drvdata(pdev);
  619. component_del(&pdev->dev, &hdmi5_component_ops);
  620. hdmi5_uninit_output(hdmi);
  621. pm_runtime_disable(&pdev->dev);
  622. kfree(hdmi);
  623. return 0;
  624. }
  625. static const struct of_device_id hdmi_of_match[] = {
  626. { .compatible = "ti,omap5-hdmi", },
  627. { .compatible = "ti,dra7-hdmi", },
  628. {},
  629. };
  630. struct platform_driver omapdss_hdmi5hw_driver = {
  631. .probe = hdmi5_probe,
  632. .remove = hdmi5_remove,
  633. .driver = {
  634. .name = "omapdss_hdmi5",
  635. .of_match_table = hdmi_of_match,
  636. .suppress_bind_attrs = true,
  637. },
  638. };