hdmi4.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832
  1. /*
  2. * HDMI interface DSS driver for TI's OMAP4 family of SoCs.
  3. * Copyright (C) 2010-2011 Texas Instruments Incorporated - http://www.ti.com/
  4. * Authors: Yong Zhi
  5. * Mythri pk <mythripk@ti.com>
  6. *
  7. * This program is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU General Public License version 2 as published by
  9. * the Free Software Foundation.
  10. *
  11. * This program is distributed in the hope that it will be useful, but WITHOUT
  12. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  14. * more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along with
  17. * this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #define DSS_SUBSYS_NAME "HDMI"
  20. #include <linux/kernel.h>
  21. #include <linux/module.h>
  22. #include <linux/err.h>
  23. #include <linux/io.h>
  24. #include <linux/interrupt.h>
  25. #include <linux/mutex.h>
  26. #include <linux/delay.h>
  27. #include <linux/string.h>
  28. #include <linux/platform_device.h>
  29. #include <linux/pm_runtime.h>
  30. #include <linux/clk.h>
  31. #include <linux/gpio.h>
  32. #include <linux/regulator/consumer.h>
  33. #include <linux/component.h>
  34. #include <linux/of.h>
  35. #include <sound/omap-hdmi-audio.h>
  36. #include "omapdss.h"
  37. #include "hdmi4_core.h"
  38. #include "dss.h"
  39. #include "dss_features.h"
  40. #include "hdmi.h"
  41. static struct omap_hdmi hdmi;
  42. static int hdmi_runtime_get(void)
  43. {
  44. int r;
  45. DSSDBG("hdmi_runtime_get\n");
  46. r = pm_runtime_get_sync(&hdmi.pdev->dev);
  47. WARN_ON(r < 0);
  48. if (r < 0)
  49. return r;
  50. return 0;
  51. }
  52. static void hdmi_runtime_put(void)
  53. {
  54. int r;
  55. DSSDBG("hdmi_runtime_put\n");
  56. r = pm_runtime_put_sync(&hdmi.pdev->dev);
  57. WARN_ON(r < 0 && r != -ENOSYS);
  58. }
  59. static irqreturn_t hdmi_irq_handler(int irq, void *data)
  60. {
  61. struct hdmi_wp_data *wp = data;
  62. u32 irqstatus;
  63. irqstatus = hdmi_wp_get_irqstatus(wp);
  64. hdmi_wp_set_irqstatus(wp, irqstatus);
  65. if ((irqstatus & HDMI_IRQ_LINK_CONNECT) &&
  66. irqstatus & HDMI_IRQ_LINK_DISCONNECT) {
  67. /*
  68. * If we get both connect and disconnect interrupts at the same
  69. * time, turn off the PHY, clear interrupts, and restart, which
  70. * raises connect interrupt if a cable is connected, or nothing
  71. * if cable is not connected.
  72. */
  73. hdmi_wp_set_phy_pwr(wp, HDMI_PHYPWRCMD_OFF);
  74. hdmi_wp_set_irqstatus(wp, HDMI_IRQ_LINK_CONNECT |
  75. HDMI_IRQ_LINK_DISCONNECT);
  76. hdmi_wp_set_phy_pwr(wp, HDMI_PHYPWRCMD_LDOON);
  77. } else if (irqstatus & HDMI_IRQ_LINK_CONNECT) {
  78. hdmi_wp_set_phy_pwr(wp, HDMI_PHYPWRCMD_TXON);
  79. } else if (irqstatus & HDMI_IRQ_LINK_DISCONNECT) {
  80. hdmi_wp_set_phy_pwr(wp, HDMI_PHYPWRCMD_LDOON);
  81. }
  82. return IRQ_HANDLED;
  83. }
  84. static int hdmi_init_regulator(void)
  85. {
  86. struct regulator *reg;
  87. if (hdmi.vdda_reg != NULL)
  88. return 0;
  89. reg = devm_regulator_get(&hdmi.pdev->dev, "vdda");
  90. if (IS_ERR(reg)) {
  91. if (PTR_ERR(reg) != -EPROBE_DEFER)
  92. DSSERR("can't get VDDA regulator\n");
  93. return PTR_ERR(reg);
  94. }
  95. hdmi.vdda_reg = reg;
  96. return 0;
  97. }
  98. static int hdmi_power_on_core(struct omap_dss_device *dssdev)
  99. {
  100. int r;
  101. r = regulator_enable(hdmi.vdda_reg);
  102. if (r)
  103. return r;
  104. r = hdmi_runtime_get();
  105. if (r)
  106. goto err_runtime_get;
  107. /* Make selection of HDMI in DSS */
  108. dss_select_hdmi_venc_clk_source(DSS_HDMI_M_PCLK);
  109. hdmi.core_enabled = true;
  110. return 0;
  111. err_runtime_get:
  112. regulator_disable(hdmi.vdda_reg);
  113. return r;
  114. }
  115. static void hdmi_power_off_core(struct omap_dss_device *dssdev)
  116. {
  117. hdmi.core_enabled = false;
  118. hdmi_runtime_put();
  119. regulator_disable(hdmi.vdda_reg);
  120. }
  121. static int hdmi_power_on_full(struct omap_dss_device *dssdev)
  122. {
  123. int r;
  124. struct videomode *vm;
  125. enum omap_channel channel = dssdev->dispc_channel;
  126. struct hdmi_wp_data *wp = &hdmi.wp;
  127. struct dss_pll_clock_info hdmi_cinfo = { 0 };
  128. unsigned pc;
  129. r = hdmi_power_on_core(dssdev);
  130. if (r)
  131. return r;
  132. /* disable and clear irqs */
  133. hdmi_wp_clear_irqenable(wp, 0xffffffff);
  134. hdmi_wp_set_irqstatus(wp, 0xffffffff);
  135. vm = &hdmi.cfg.vm;
  136. DSSDBG("hdmi_power_on hactive= %d vactive = %d\n", vm->hactive,
  137. vm->vactive);
  138. pc = vm->pixelclock;
  139. if (vm->flags & DISPLAY_FLAGS_DOUBLECLK)
  140. pc *= 2;
  141. /* DSS_HDMI_TCLK is bitclk / 10 */
  142. pc *= 10;
  143. dss_pll_calc_b(&hdmi.pll.pll, clk_get_rate(hdmi.pll.pll.clkin),
  144. pc, &hdmi_cinfo);
  145. r = dss_pll_enable(&hdmi.pll.pll);
  146. if (r) {
  147. DSSERR("Failed to enable PLL\n");
  148. goto err_pll_enable;
  149. }
  150. r = dss_pll_set_config(&hdmi.pll.pll, &hdmi_cinfo);
  151. if (r) {
  152. DSSERR("Failed to configure PLL\n");
  153. goto err_pll_cfg;
  154. }
  155. r = hdmi_phy_configure(&hdmi.phy, hdmi_cinfo.clkdco,
  156. hdmi_cinfo.clkout[0]);
  157. if (r) {
  158. DSSDBG("Failed to configure PHY\n");
  159. goto err_phy_cfg;
  160. }
  161. r = hdmi_wp_set_phy_pwr(wp, HDMI_PHYPWRCMD_LDOON);
  162. if (r)
  163. goto err_phy_pwr;
  164. hdmi4_configure(&hdmi.core, &hdmi.wp, &hdmi.cfg);
  165. /* tv size */
  166. dss_mgr_set_timings(channel, vm);
  167. r = dss_mgr_enable(channel);
  168. if (r)
  169. goto err_mgr_enable;
  170. r = hdmi_wp_video_start(&hdmi.wp);
  171. if (r)
  172. goto err_vid_enable;
  173. hdmi_wp_set_irqenable(wp,
  174. HDMI_IRQ_LINK_CONNECT | HDMI_IRQ_LINK_DISCONNECT);
  175. return 0;
  176. err_vid_enable:
  177. dss_mgr_disable(channel);
  178. err_mgr_enable:
  179. hdmi_wp_set_phy_pwr(&hdmi.wp, HDMI_PHYPWRCMD_OFF);
  180. err_phy_pwr:
  181. err_phy_cfg:
  182. err_pll_cfg:
  183. dss_pll_disable(&hdmi.pll.pll);
  184. err_pll_enable:
  185. hdmi_power_off_core(dssdev);
  186. return -EIO;
  187. }
  188. static void hdmi_power_off_full(struct omap_dss_device *dssdev)
  189. {
  190. enum omap_channel channel = dssdev->dispc_channel;
  191. hdmi_wp_clear_irqenable(&hdmi.wp, 0xffffffff);
  192. hdmi_wp_video_stop(&hdmi.wp);
  193. dss_mgr_disable(channel);
  194. hdmi_wp_set_phy_pwr(&hdmi.wp, HDMI_PHYPWRCMD_OFF);
  195. dss_pll_disable(&hdmi.pll.pll);
  196. hdmi_power_off_core(dssdev);
  197. }
  198. static int hdmi_display_check_timing(struct omap_dss_device *dssdev,
  199. struct videomode *vm)
  200. {
  201. if (!dispc_mgr_timings_ok(dssdev->dispc_channel, vm))
  202. return -EINVAL;
  203. return 0;
  204. }
  205. static void hdmi_display_set_timing(struct omap_dss_device *dssdev,
  206. struct videomode *vm)
  207. {
  208. mutex_lock(&hdmi.lock);
  209. hdmi.cfg.vm = *vm;
  210. dispc_set_tv_pclk(vm->pixelclock);
  211. mutex_unlock(&hdmi.lock);
  212. }
  213. static void hdmi_display_get_timings(struct omap_dss_device *dssdev,
  214. struct videomode *vm)
  215. {
  216. *vm = hdmi.cfg.vm;
  217. }
  218. static void hdmi_dump_regs(struct seq_file *s)
  219. {
  220. mutex_lock(&hdmi.lock);
  221. if (hdmi_runtime_get()) {
  222. mutex_unlock(&hdmi.lock);
  223. return;
  224. }
  225. hdmi_wp_dump(&hdmi.wp, s);
  226. hdmi_pll_dump(&hdmi.pll, s);
  227. hdmi_phy_dump(&hdmi.phy, s);
  228. hdmi4_core_dump(&hdmi.core, s);
  229. hdmi_runtime_put();
  230. mutex_unlock(&hdmi.lock);
  231. }
  232. static int read_edid(u8 *buf, int len)
  233. {
  234. int r;
  235. mutex_lock(&hdmi.lock);
  236. r = hdmi_runtime_get();
  237. BUG_ON(r);
  238. r = hdmi4_read_edid(&hdmi.core, buf, len);
  239. hdmi_runtime_put();
  240. mutex_unlock(&hdmi.lock);
  241. return r;
  242. }
  243. static void hdmi_start_audio_stream(struct omap_hdmi *hd)
  244. {
  245. hdmi_wp_audio_enable(&hd->wp, true);
  246. hdmi4_audio_start(&hd->core, &hd->wp);
  247. }
  248. static void hdmi_stop_audio_stream(struct omap_hdmi *hd)
  249. {
  250. hdmi4_audio_stop(&hd->core, &hd->wp);
  251. hdmi_wp_audio_enable(&hd->wp, false);
  252. }
  253. static int hdmi_display_enable(struct omap_dss_device *dssdev)
  254. {
  255. struct omap_dss_device *out = &hdmi.output;
  256. unsigned long flags;
  257. int r = 0;
  258. DSSDBG("ENTER hdmi_display_enable\n");
  259. mutex_lock(&hdmi.lock);
  260. if (!out->dispc_channel_connected) {
  261. DSSERR("failed to enable display: no output/manager\n");
  262. r = -ENODEV;
  263. goto err0;
  264. }
  265. r = hdmi_power_on_full(dssdev);
  266. if (r) {
  267. DSSERR("failed to power on device\n");
  268. goto err0;
  269. }
  270. if (hdmi.audio_configured) {
  271. r = hdmi4_audio_config(&hdmi.core, &hdmi.wp, &hdmi.audio_config,
  272. hdmi.cfg.vm.pixelclock);
  273. if (r) {
  274. DSSERR("Error restoring audio configuration: %d", r);
  275. hdmi.audio_abort_cb(&hdmi.pdev->dev);
  276. hdmi.audio_configured = false;
  277. }
  278. }
  279. spin_lock_irqsave(&hdmi.audio_playing_lock, flags);
  280. if (hdmi.audio_configured && hdmi.audio_playing)
  281. hdmi_start_audio_stream(&hdmi);
  282. hdmi.display_enabled = true;
  283. spin_unlock_irqrestore(&hdmi.audio_playing_lock, flags);
  284. mutex_unlock(&hdmi.lock);
  285. return 0;
  286. err0:
  287. mutex_unlock(&hdmi.lock);
  288. return r;
  289. }
  290. static void hdmi_display_disable(struct omap_dss_device *dssdev)
  291. {
  292. unsigned long flags;
  293. DSSDBG("Enter hdmi_display_disable\n");
  294. mutex_lock(&hdmi.lock);
  295. spin_lock_irqsave(&hdmi.audio_playing_lock, flags);
  296. hdmi_stop_audio_stream(&hdmi);
  297. hdmi.display_enabled = false;
  298. spin_unlock_irqrestore(&hdmi.audio_playing_lock, flags);
  299. hdmi_power_off_full(dssdev);
  300. mutex_unlock(&hdmi.lock);
  301. }
  302. static int hdmi_core_enable(struct omap_dss_device *dssdev)
  303. {
  304. int r = 0;
  305. DSSDBG("ENTER omapdss_hdmi_core_enable\n");
  306. mutex_lock(&hdmi.lock);
  307. r = hdmi_power_on_core(dssdev);
  308. if (r) {
  309. DSSERR("failed to power on device\n");
  310. goto err0;
  311. }
  312. mutex_unlock(&hdmi.lock);
  313. return 0;
  314. err0:
  315. mutex_unlock(&hdmi.lock);
  316. return r;
  317. }
  318. static void hdmi_core_disable(struct omap_dss_device *dssdev)
  319. {
  320. DSSDBG("Enter omapdss_hdmi_core_disable\n");
  321. mutex_lock(&hdmi.lock);
  322. hdmi_power_off_core(dssdev);
  323. mutex_unlock(&hdmi.lock);
  324. }
  325. static int hdmi_connect(struct omap_dss_device *dssdev,
  326. struct omap_dss_device *dst)
  327. {
  328. enum omap_channel channel = dssdev->dispc_channel;
  329. int r;
  330. r = hdmi_init_regulator();
  331. if (r)
  332. return r;
  333. r = dss_mgr_connect(channel, dssdev);
  334. if (r)
  335. return r;
  336. r = omapdss_output_set_device(dssdev, dst);
  337. if (r) {
  338. DSSERR("failed to connect output to new device: %s\n",
  339. dst->name);
  340. dss_mgr_disconnect(channel, dssdev);
  341. return r;
  342. }
  343. return 0;
  344. }
  345. static void hdmi_disconnect(struct omap_dss_device *dssdev,
  346. struct omap_dss_device *dst)
  347. {
  348. enum omap_channel channel = dssdev->dispc_channel;
  349. WARN_ON(dst != dssdev->dst);
  350. if (dst != dssdev->dst)
  351. return;
  352. omapdss_output_unset_device(dssdev);
  353. dss_mgr_disconnect(channel, dssdev);
  354. }
  355. static int hdmi_read_edid(struct omap_dss_device *dssdev,
  356. u8 *edid, int len)
  357. {
  358. bool need_enable;
  359. int r;
  360. need_enable = hdmi.core_enabled == false;
  361. if (need_enable) {
  362. r = hdmi_core_enable(dssdev);
  363. if (r)
  364. return r;
  365. }
  366. r = read_edid(edid, len);
  367. if (need_enable)
  368. hdmi_core_disable(dssdev);
  369. return r;
  370. }
  371. static int hdmi_set_infoframe(struct omap_dss_device *dssdev,
  372. const struct hdmi_avi_infoframe *avi)
  373. {
  374. hdmi.cfg.infoframe = *avi;
  375. return 0;
  376. }
  377. static int hdmi_set_hdmi_mode(struct omap_dss_device *dssdev,
  378. bool hdmi_mode)
  379. {
  380. hdmi.cfg.hdmi_dvi_mode = hdmi_mode ? HDMI_HDMI : HDMI_DVI;
  381. return 0;
  382. }
  383. static const struct omapdss_hdmi_ops hdmi_ops = {
  384. .connect = hdmi_connect,
  385. .disconnect = hdmi_disconnect,
  386. .enable = hdmi_display_enable,
  387. .disable = hdmi_display_disable,
  388. .check_timings = hdmi_display_check_timing,
  389. .set_timings = hdmi_display_set_timing,
  390. .get_timings = hdmi_display_get_timings,
  391. .read_edid = hdmi_read_edid,
  392. .set_infoframe = hdmi_set_infoframe,
  393. .set_hdmi_mode = hdmi_set_hdmi_mode,
  394. };
  395. static void hdmi_init_output(struct platform_device *pdev)
  396. {
  397. struct omap_dss_device *out = &hdmi.output;
  398. out->dev = &pdev->dev;
  399. out->id = OMAP_DSS_OUTPUT_HDMI;
  400. out->output_type = OMAP_DISPLAY_TYPE_HDMI;
  401. out->name = "hdmi.0";
  402. out->dispc_channel = OMAP_DSS_CHANNEL_DIGIT;
  403. out->ops.hdmi = &hdmi_ops;
  404. out->owner = THIS_MODULE;
  405. omapdss_register_output(out);
  406. }
  407. static void hdmi_uninit_output(struct platform_device *pdev)
  408. {
  409. struct omap_dss_device *out = &hdmi.output;
  410. omapdss_unregister_output(out);
  411. }
  412. static int hdmi_probe_of(struct platform_device *pdev)
  413. {
  414. struct device_node *node = pdev->dev.of_node;
  415. struct device_node *ep;
  416. int r;
  417. ep = omapdss_of_get_first_endpoint(node);
  418. if (!ep)
  419. return 0;
  420. r = hdmi_parse_lanes_of(pdev, ep, &hdmi.phy);
  421. if (r)
  422. goto err;
  423. of_node_put(ep);
  424. return 0;
  425. err:
  426. of_node_put(ep);
  427. return r;
  428. }
  429. /* Audio callbacks */
  430. static int hdmi_audio_startup(struct device *dev,
  431. void (*abort_cb)(struct device *dev))
  432. {
  433. struct omap_hdmi *hd = dev_get_drvdata(dev);
  434. int ret = 0;
  435. mutex_lock(&hd->lock);
  436. if (!hdmi_mode_has_audio(&hd->cfg) || !hd->display_enabled) {
  437. ret = -EPERM;
  438. goto out;
  439. }
  440. hd->audio_abort_cb = abort_cb;
  441. out:
  442. mutex_unlock(&hd->lock);
  443. return ret;
  444. }
  445. static int hdmi_audio_shutdown(struct device *dev)
  446. {
  447. struct omap_hdmi *hd = dev_get_drvdata(dev);
  448. mutex_lock(&hd->lock);
  449. hd->audio_abort_cb = NULL;
  450. hd->audio_configured = false;
  451. hd->audio_playing = false;
  452. mutex_unlock(&hd->lock);
  453. return 0;
  454. }
  455. static int hdmi_audio_start(struct device *dev)
  456. {
  457. struct omap_hdmi *hd = dev_get_drvdata(dev);
  458. unsigned long flags;
  459. WARN_ON(!hdmi_mode_has_audio(&hd->cfg));
  460. spin_lock_irqsave(&hd->audio_playing_lock, flags);
  461. if (hd->display_enabled)
  462. hdmi_start_audio_stream(hd);
  463. hd->audio_playing = true;
  464. spin_unlock_irqrestore(&hd->audio_playing_lock, flags);
  465. return 0;
  466. }
  467. static void hdmi_audio_stop(struct device *dev)
  468. {
  469. struct omap_hdmi *hd = dev_get_drvdata(dev);
  470. unsigned long flags;
  471. WARN_ON(!hdmi_mode_has_audio(&hd->cfg));
  472. spin_lock_irqsave(&hd->audio_playing_lock, flags);
  473. if (hd->display_enabled)
  474. hdmi_stop_audio_stream(hd);
  475. hd->audio_playing = false;
  476. spin_unlock_irqrestore(&hd->audio_playing_lock, flags);
  477. }
  478. static int hdmi_audio_config(struct device *dev,
  479. struct omap_dss_audio *dss_audio)
  480. {
  481. struct omap_hdmi *hd = dev_get_drvdata(dev);
  482. int ret;
  483. mutex_lock(&hd->lock);
  484. if (!hdmi_mode_has_audio(&hd->cfg) || !hd->display_enabled) {
  485. ret = -EPERM;
  486. goto out;
  487. }
  488. ret = hdmi4_audio_config(&hd->core, &hd->wp, dss_audio,
  489. hd->cfg.vm.pixelclock);
  490. if (!ret) {
  491. hd->audio_configured = true;
  492. hd->audio_config = *dss_audio;
  493. }
  494. out:
  495. mutex_unlock(&hd->lock);
  496. return ret;
  497. }
  498. static const struct omap_hdmi_audio_ops hdmi_audio_ops = {
  499. .audio_startup = hdmi_audio_startup,
  500. .audio_shutdown = hdmi_audio_shutdown,
  501. .audio_start = hdmi_audio_start,
  502. .audio_stop = hdmi_audio_stop,
  503. .audio_config = hdmi_audio_config,
  504. };
  505. static int hdmi_audio_register(struct device *dev)
  506. {
  507. struct omap_hdmi_audio_pdata pdata = {
  508. .dev = dev,
  509. .dss_version = omapdss_get_version(),
  510. .audio_dma_addr = hdmi_wp_get_audio_dma_addr(&hdmi.wp),
  511. .ops = &hdmi_audio_ops,
  512. };
  513. hdmi.audio_pdev = platform_device_register_data(
  514. dev, "omap-hdmi-audio", PLATFORM_DEVID_AUTO,
  515. &pdata, sizeof(pdata));
  516. if (IS_ERR(hdmi.audio_pdev))
  517. return PTR_ERR(hdmi.audio_pdev);
  518. return 0;
  519. }
  520. /* HDMI HW IP initialisation */
  521. static int hdmi4_bind(struct device *dev, struct device *master, void *data)
  522. {
  523. struct platform_device *pdev = to_platform_device(dev);
  524. int r;
  525. int irq;
  526. hdmi.pdev = pdev;
  527. dev_set_drvdata(&pdev->dev, &hdmi);
  528. mutex_init(&hdmi.lock);
  529. spin_lock_init(&hdmi.audio_playing_lock);
  530. if (pdev->dev.of_node) {
  531. r = hdmi_probe_of(pdev);
  532. if (r)
  533. return r;
  534. }
  535. r = hdmi_wp_init(pdev, &hdmi.wp);
  536. if (r)
  537. return r;
  538. r = hdmi_pll_init(pdev, &hdmi.pll, &hdmi.wp);
  539. if (r)
  540. return r;
  541. r = hdmi_phy_init(pdev, &hdmi.phy);
  542. if (r)
  543. goto err;
  544. r = hdmi4_core_init(pdev, &hdmi.core);
  545. if (r)
  546. goto err;
  547. irq = platform_get_irq(pdev, 0);
  548. if (irq < 0) {
  549. DSSERR("platform_get_irq failed\n");
  550. r = -ENODEV;
  551. goto err;
  552. }
  553. r = devm_request_threaded_irq(&pdev->dev, irq,
  554. NULL, hdmi_irq_handler,
  555. IRQF_ONESHOT, "OMAP HDMI", &hdmi.wp);
  556. if (r) {
  557. DSSERR("HDMI IRQ request failed\n");
  558. goto err;
  559. }
  560. pm_runtime_enable(&pdev->dev);
  561. hdmi_init_output(pdev);
  562. r = hdmi_audio_register(&pdev->dev);
  563. if (r) {
  564. DSSERR("Registering HDMI audio failed\n");
  565. hdmi_uninit_output(pdev);
  566. pm_runtime_disable(&pdev->dev);
  567. return r;
  568. }
  569. dss_debugfs_create_file("hdmi", hdmi_dump_regs);
  570. return 0;
  571. err:
  572. hdmi_pll_uninit(&hdmi.pll);
  573. return r;
  574. }
  575. static void hdmi4_unbind(struct device *dev, struct device *master, void *data)
  576. {
  577. struct platform_device *pdev = to_platform_device(dev);
  578. if (hdmi.audio_pdev)
  579. platform_device_unregister(hdmi.audio_pdev);
  580. hdmi_uninit_output(pdev);
  581. hdmi_pll_uninit(&hdmi.pll);
  582. pm_runtime_disable(&pdev->dev);
  583. }
  584. static const struct component_ops hdmi4_component_ops = {
  585. .bind = hdmi4_bind,
  586. .unbind = hdmi4_unbind,
  587. };
  588. static int hdmi4_probe(struct platform_device *pdev)
  589. {
  590. return component_add(&pdev->dev, &hdmi4_component_ops);
  591. }
  592. static int hdmi4_remove(struct platform_device *pdev)
  593. {
  594. component_del(&pdev->dev, &hdmi4_component_ops);
  595. return 0;
  596. }
  597. static int hdmi_runtime_suspend(struct device *dev)
  598. {
  599. dispc_runtime_put();
  600. return 0;
  601. }
  602. static int hdmi_runtime_resume(struct device *dev)
  603. {
  604. int r;
  605. r = dispc_runtime_get();
  606. if (r < 0)
  607. return r;
  608. return 0;
  609. }
  610. static const struct dev_pm_ops hdmi_pm_ops = {
  611. .runtime_suspend = hdmi_runtime_suspend,
  612. .runtime_resume = hdmi_runtime_resume,
  613. };
  614. static const struct of_device_id hdmi_of_match[] = {
  615. { .compatible = "ti,omap4-hdmi", },
  616. {},
  617. };
  618. static struct platform_driver omapdss_hdmihw_driver = {
  619. .probe = hdmi4_probe,
  620. .remove = hdmi4_remove,
  621. .driver = {
  622. .name = "omapdss_hdmi",
  623. .pm = &hdmi_pm_ops,
  624. .of_match_table = hdmi_of_match,
  625. .suppress_bind_attrs = true,
  626. },
  627. };
  628. int __init hdmi4_init_platform_driver(void)
  629. {
  630. return platform_driver_register(&omapdss_hdmihw_driver);
  631. }
  632. void hdmi4_uninit_platform_driver(void)
  633. {
  634. platform_driver_unregister(&omapdss_hdmihw_driver);
  635. }