hdmi4.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831
  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 omap_video_timings *p;
  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. p = &hdmi.cfg.timings;
  136. DSSDBG("hdmi_power_on x_res= %d y_res = %d\n", p->x_res, p->y_res);
  137. pc = p->pixelclock;
  138. if (p->double_pixel)
  139. pc *= 2;
  140. /* DSS_HDMI_TCLK is bitclk / 10 */
  141. pc *= 10;
  142. dss_pll_calc_b(&hdmi.pll.pll, clk_get_rate(hdmi.pll.pll.clkin),
  143. pc, &hdmi_cinfo);
  144. r = dss_pll_enable(&hdmi.pll.pll);
  145. if (r) {
  146. DSSERR("Failed to enable PLL\n");
  147. goto err_pll_enable;
  148. }
  149. r = dss_pll_set_config(&hdmi.pll.pll, &hdmi_cinfo);
  150. if (r) {
  151. DSSERR("Failed to configure PLL\n");
  152. goto err_pll_cfg;
  153. }
  154. r = hdmi_phy_configure(&hdmi.phy, hdmi_cinfo.clkdco,
  155. hdmi_cinfo.clkout[0]);
  156. if (r) {
  157. DSSDBG("Failed to configure PHY\n");
  158. goto err_phy_cfg;
  159. }
  160. r = hdmi_wp_set_phy_pwr(wp, HDMI_PHYPWRCMD_LDOON);
  161. if (r)
  162. goto err_phy_pwr;
  163. hdmi4_configure(&hdmi.core, &hdmi.wp, &hdmi.cfg);
  164. /* tv size */
  165. dss_mgr_set_timings(channel, p);
  166. r = dss_mgr_enable(channel);
  167. if (r)
  168. goto err_mgr_enable;
  169. r = hdmi_wp_video_start(&hdmi.wp);
  170. if (r)
  171. goto err_vid_enable;
  172. hdmi_wp_set_irqenable(wp,
  173. HDMI_IRQ_LINK_CONNECT | HDMI_IRQ_LINK_DISCONNECT);
  174. return 0;
  175. err_vid_enable:
  176. dss_mgr_disable(channel);
  177. err_mgr_enable:
  178. hdmi_wp_set_phy_pwr(&hdmi.wp, HDMI_PHYPWRCMD_OFF);
  179. err_phy_pwr:
  180. err_phy_cfg:
  181. err_pll_cfg:
  182. dss_pll_disable(&hdmi.pll.pll);
  183. err_pll_enable:
  184. hdmi_power_off_core(dssdev);
  185. return -EIO;
  186. }
  187. static void hdmi_power_off_full(struct omap_dss_device *dssdev)
  188. {
  189. enum omap_channel channel = dssdev->dispc_channel;
  190. hdmi_wp_clear_irqenable(&hdmi.wp, 0xffffffff);
  191. hdmi_wp_video_stop(&hdmi.wp);
  192. dss_mgr_disable(channel);
  193. hdmi_wp_set_phy_pwr(&hdmi.wp, HDMI_PHYPWRCMD_OFF);
  194. dss_pll_disable(&hdmi.pll.pll);
  195. hdmi_power_off_core(dssdev);
  196. }
  197. static int hdmi_display_check_timing(struct omap_dss_device *dssdev,
  198. struct omap_video_timings *timings)
  199. {
  200. if (!dispc_mgr_timings_ok(dssdev->dispc_channel, timings))
  201. return -EINVAL;
  202. return 0;
  203. }
  204. static void hdmi_display_set_timing(struct omap_dss_device *dssdev,
  205. struct omap_video_timings *timings)
  206. {
  207. mutex_lock(&hdmi.lock);
  208. hdmi.cfg.timings = *timings;
  209. dispc_set_tv_pclk(timings->pixelclock);
  210. mutex_unlock(&hdmi.lock);
  211. }
  212. static void hdmi_display_get_timings(struct omap_dss_device *dssdev,
  213. struct omap_video_timings *timings)
  214. {
  215. *timings = hdmi.cfg.timings;
  216. }
  217. static void hdmi_dump_regs(struct seq_file *s)
  218. {
  219. mutex_lock(&hdmi.lock);
  220. if (hdmi_runtime_get()) {
  221. mutex_unlock(&hdmi.lock);
  222. return;
  223. }
  224. hdmi_wp_dump(&hdmi.wp, s);
  225. hdmi_pll_dump(&hdmi.pll, s);
  226. hdmi_phy_dump(&hdmi.phy, s);
  227. hdmi4_core_dump(&hdmi.core, s);
  228. hdmi_runtime_put();
  229. mutex_unlock(&hdmi.lock);
  230. }
  231. static int read_edid(u8 *buf, int len)
  232. {
  233. int r;
  234. mutex_lock(&hdmi.lock);
  235. r = hdmi_runtime_get();
  236. BUG_ON(r);
  237. r = hdmi4_read_edid(&hdmi.core, buf, len);
  238. hdmi_runtime_put();
  239. mutex_unlock(&hdmi.lock);
  240. return r;
  241. }
  242. static void hdmi_start_audio_stream(struct omap_hdmi *hd)
  243. {
  244. hdmi_wp_audio_enable(&hd->wp, true);
  245. hdmi4_audio_start(&hd->core, &hd->wp);
  246. }
  247. static void hdmi_stop_audio_stream(struct omap_hdmi *hd)
  248. {
  249. hdmi4_audio_stop(&hd->core, &hd->wp);
  250. hdmi_wp_audio_enable(&hd->wp, false);
  251. }
  252. static int hdmi_display_enable(struct omap_dss_device *dssdev)
  253. {
  254. struct omap_dss_device *out = &hdmi.output;
  255. unsigned long flags;
  256. int r = 0;
  257. DSSDBG("ENTER hdmi_display_enable\n");
  258. mutex_lock(&hdmi.lock);
  259. if (!out->dispc_channel_connected) {
  260. DSSERR("failed to enable display: no output/manager\n");
  261. r = -ENODEV;
  262. goto err0;
  263. }
  264. r = hdmi_power_on_full(dssdev);
  265. if (r) {
  266. DSSERR("failed to power on device\n");
  267. goto err0;
  268. }
  269. if (hdmi.audio_configured) {
  270. r = hdmi4_audio_config(&hdmi.core, &hdmi.wp, &hdmi.audio_config,
  271. hdmi.cfg.timings.pixelclock);
  272. if (r) {
  273. DSSERR("Error restoring audio configuration: %d", r);
  274. hdmi.audio_abort_cb(&hdmi.pdev->dev);
  275. hdmi.audio_configured = false;
  276. }
  277. }
  278. spin_lock_irqsave(&hdmi.audio_playing_lock, flags);
  279. if (hdmi.audio_configured && hdmi.audio_playing)
  280. hdmi_start_audio_stream(&hdmi);
  281. hdmi.display_enabled = true;
  282. spin_unlock_irqrestore(&hdmi.audio_playing_lock, flags);
  283. mutex_unlock(&hdmi.lock);
  284. return 0;
  285. err0:
  286. mutex_unlock(&hdmi.lock);
  287. return r;
  288. }
  289. static void hdmi_display_disable(struct omap_dss_device *dssdev)
  290. {
  291. unsigned long flags;
  292. DSSDBG("Enter hdmi_display_disable\n");
  293. mutex_lock(&hdmi.lock);
  294. spin_lock_irqsave(&hdmi.audio_playing_lock, flags);
  295. hdmi_stop_audio_stream(&hdmi);
  296. hdmi.display_enabled = false;
  297. spin_unlock_irqrestore(&hdmi.audio_playing_lock, flags);
  298. hdmi_power_off_full(dssdev);
  299. mutex_unlock(&hdmi.lock);
  300. }
  301. static int hdmi_core_enable(struct omap_dss_device *dssdev)
  302. {
  303. int r = 0;
  304. DSSDBG("ENTER omapdss_hdmi_core_enable\n");
  305. mutex_lock(&hdmi.lock);
  306. r = hdmi_power_on_core(dssdev);
  307. if (r) {
  308. DSSERR("failed to power on device\n");
  309. goto err0;
  310. }
  311. mutex_unlock(&hdmi.lock);
  312. return 0;
  313. err0:
  314. mutex_unlock(&hdmi.lock);
  315. return r;
  316. }
  317. static void hdmi_core_disable(struct omap_dss_device *dssdev)
  318. {
  319. DSSDBG("Enter omapdss_hdmi_core_disable\n");
  320. mutex_lock(&hdmi.lock);
  321. hdmi_power_off_core(dssdev);
  322. mutex_unlock(&hdmi.lock);
  323. }
  324. static int hdmi_connect(struct omap_dss_device *dssdev,
  325. struct omap_dss_device *dst)
  326. {
  327. enum omap_channel channel = dssdev->dispc_channel;
  328. int r;
  329. r = hdmi_init_regulator();
  330. if (r)
  331. return r;
  332. r = dss_mgr_connect(channel, dssdev);
  333. if (r)
  334. return r;
  335. r = omapdss_output_set_device(dssdev, dst);
  336. if (r) {
  337. DSSERR("failed to connect output to new device: %s\n",
  338. dst->name);
  339. dss_mgr_disconnect(channel, dssdev);
  340. return r;
  341. }
  342. return 0;
  343. }
  344. static void hdmi_disconnect(struct omap_dss_device *dssdev,
  345. struct omap_dss_device *dst)
  346. {
  347. enum omap_channel channel = dssdev->dispc_channel;
  348. WARN_ON(dst != dssdev->dst);
  349. if (dst != dssdev->dst)
  350. return;
  351. omapdss_output_unset_device(dssdev);
  352. dss_mgr_disconnect(channel, dssdev);
  353. }
  354. static int hdmi_read_edid(struct omap_dss_device *dssdev,
  355. u8 *edid, int len)
  356. {
  357. bool need_enable;
  358. int r;
  359. need_enable = hdmi.core_enabled == false;
  360. if (need_enable) {
  361. r = hdmi_core_enable(dssdev);
  362. if (r)
  363. return r;
  364. }
  365. r = read_edid(edid, len);
  366. if (need_enable)
  367. hdmi_core_disable(dssdev);
  368. return r;
  369. }
  370. static int hdmi_set_infoframe(struct omap_dss_device *dssdev,
  371. const struct hdmi_avi_infoframe *avi)
  372. {
  373. hdmi.cfg.infoframe = *avi;
  374. return 0;
  375. }
  376. static int hdmi_set_hdmi_mode(struct omap_dss_device *dssdev,
  377. bool hdmi_mode)
  378. {
  379. hdmi.cfg.hdmi_dvi_mode = hdmi_mode ? HDMI_HDMI : HDMI_DVI;
  380. return 0;
  381. }
  382. static const struct omapdss_hdmi_ops hdmi_ops = {
  383. .connect = hdmi_connect,
  384. .disconnect = hdmi_disconnect,
  385. .enable = hdmi_display_enable,
  386. .disable = hdmi_display_disable,
  387. .check_timings = hdmi_display_check_timing,
  388. .set_timings = hdmi_display_set_timing,
  389. .get_timings = hdmi_display_get_timings,
  390. .read_edid = hdmi_read_edid,
  391. .set_infoframe = hdmi_set_infoframe,
  392. .set_hdmi_mode = hdmi_set_hdmi_mode,
  393. };
  394. static void hdmi_init_output(struct platform_device *pdev)
  395. {
  396. struct omap_dss_device *out = &hdmi.output;
  397. out->dev = &pdev->dev;
  398. out->id = OMAP_DSS_OUTPUT_HDMI;
  399. out->output_type = OMAP_DISPLAY_TYPE_HDMI;
  400. out->name = "hdmi.0";
  401. out->dispc_channel = OMAP_DSS_CHANNEL_DIGIT;
  402. out->ops.hdmi = &hdmi_ops;
  403. out->owner = THIS_MODULE;
  404. omapdss_register_output(out);
  405. }
  406. static void hdmi_uninit_output(struct platform_device *pdev)
  407. {
  408. struct omap_dss_device *out = &hdmi.output;
  409. omapdss_unregister_output(out);
  410. }
  411. static int hdmi_probe_of(struct platform_device *pdev)
  412. {
  413. struct device_node *node = pdev->dev.of_node;
  414. struct device_node *ep;
  415. int r;
  416. ep = omapdss_of_get_first_endpoint(node);
  417. if (!ep)
  418. return 0;
  419. r = hdmi_parse_lanes_of(pdev, ep, &hdmi.phy);
  420. if (r)
  421. goto err;
  422. of_node_put(ep);
  423. return 0;
  424. err:
  425. of_node_put(ep);
  426. return r;
  427. }
  428. /* Audio callbacks */
  429. static int hdmi_audio_startup(struct device *dev,
  430. void (*abort_cb)(struct device *dev))
  431. {
  432. struct omap_hdmi *hd = dev_get_drvdata(dev);
  433. int ret = 0;
  434. mutex_lock(&hd->lock);
  435. if (!hdmi_mode_has_audio(&hd->cfg) || !hd->display_enabled) {
  436. ret = -EPERM;
  437. goto out;
  438. }
  439. hd->audio_abort_cb = abort_cb;
  440. out:
  441. mutex_unlock(&hd->lock);
  442. return ret;
  443. }
  444. static int hdmi_audio_shutdown(struct device *dev)
  445. {
  446. struct omap_hdmi *hd = dev_get_drvdata(dev);
  447. mutex_lock(&hd->lock);
  448. hd->audio_abort_cb = NULL;
  449. hd->audio_configured = false;
  450. hd->audio_playing = false;
  451. mutex_unlock(&hd->lock);
  452. return 0;
  453. }
  454. static int hdmi_audio_start(struct device *dev)
  455. {
  456. struct omap_hdmi *hd = dev_get_drvdata(dev);
  457. unsigned long flags;
  458. WARN_ON(!hdmi_mode_has_audio(&hd->cfg));
  459. spin_lock_irqsave(&hd->audio_playing_lock, flags);
  460. if (hd->display_enabled)
  461. hdmi_start_audio_stream(hd);
  462. hd->audio_playing = true;
  463. spin_unlock_irqrestore(&hd->audio_playing_lock, flags);
  464. return 0;
  465. }
  466. static void hdmi_audio_stop(struct device *dev)
  467. {
  468. struct omap_hdmi *hd = dev_get_drvdata(dev);
  469. unsigned long flags;
  470. WARN_ON(!hdmi_mode_has_audio(&hd->cfg));
  471. spin_lock_irqsave(&hd->audio_playing_lock, flags);
  472. if (hd->display_enabled)
  473. hdmi_stop_audio_stream(hd);
  474. hd->audio_playing = false;
  475. spin_unlock_irqrestore(&hd->audio_playing_lock, flags);
  476. }
  477. static int hdmi_audio_config(struct device *dev,
  478. struct omap_dss_audio *dss_audio)
  479. {
  480. struct omap_hdmi *hd = dev_get_drvdata(dev);
  481. int ret;
  482. mutex_lock(&hd->lock);
  483. if (!hdmi_mode_has_audio(&hd->cfg) || !hd->display_enabled) {
  484. ret = -EPERM;
  485. goto out;
  486. }
  487. ret = hdmi4_audio_config(&hd->core, &hd->wp, dss_audio,
  488. hd->cfg.timings.pixelclock);
  489. if (!ret) {
  490. hd->audio_configured = true;
  491. hd->audio_config = *dss_audio;
  492. }
  493. out:
  494. mutex_unlock(&hd->lock);
  495. return ret;
  496. }
  497. static const struct omap_hdmi_audio_ops hdmi_audio_ops = {
  498. .audio_startup = hdmi_audio_startup,
  499. .audio_shutdown = hdmi_audio_shutdown,
  500. .audio_start = hdmi_audio_start,
  501. .audio_stop = hdmi_audio_stop,
  502. .audio_config = hdmi_audio_config,
  503. };
  504. static int hdmi_audio_register(struct device *dev)
  505. {
  506. struct omap_hdmi_audio_pdata pdata = {
  507. .dev = dev,
  508. .dss_version = omapdss_get_version(),
  509. .audio_dma_addr = hdmi_wp_get_audio_dma_addr(&hdmi.wp),
  510. .ops = &hdmi_audio_ops,
  511. };
  512. hdmi.audio_pdev = platform_device_register_data(
  513. dev, "omap-hdmi-audio", PLATFORM_DEVID_AUTO,
  514. &pdata, sizeof(pdata));
  515. if (IS_ERR(hdmi.audio_pdev))
  516. return PTR_ERR(hdmi.audio_pdev);
  517. return 0;
  518. }
  519. /* HDMI HW IP initialisation */
  520. static int hdmi4_bind(struct device *dev, struct device *master, void *data)
  521. {
  522. struct platform_device *pdev = to_platform_device(dev);
  523. int r;
  524. int irq;
  525. hdmi.pdev = pdev;
  526. dev_set_drvdata(&pdev->dev, &hdmi);
  527. mutex_init(&hdmi.lock);
  528. spin_lock_init(&hdmi.audio_playing_lock);
  529. if (pdev->dev.of_node) {
  530. r = hdmi_probe_of(pdev);
  531. if (r)
  532. return r;
  533. }
  534. r = hdmi_wp_init(pdev, &hdmi.wp);
  535. if (r)
  536. return r;
  537. r = hdmi_pll_init(pdev, &hdmi.pll, &hdmi.wp);
  538. if (r)
  539. return r;
  540. r = hdmi_phy_init(pdev, &hdmi.phy);
  541. if (r)
  542. goto err;
  543. r = hdmi4_core_init(pdev, &hdmi.core);
  544. if (r)
  545. goto err;
  546. irq = platform_get_irq(pdev, 0);
  547. if (irq < 0) {
  548. DSSERR("platform_get_irq failed\n");
  549. r = -ENODEV;
  550. goto err;
  551. }
  552. r = devm_request_threaded_irq(&pdev->dev, irq,
  553. NULL, hdmi_irq_handler,
  554. IRQF_ONESHOT, "OMAP HDMI", &hdmi.wp);
  555. if (r) {
  556. DSSERR("HDMI IRQ request failed\n");
  557. goto err;
  558. }
  559. pm_runtime_enable(&pdev->dev);
  560. hdmi_init_output(pdev);
  561. r = hdmi_audio_register(&pdev->dev);
  562. if (r) {
  563. DSSERR("Registering HDMI audio failed\n");
  564. hdmi_uninit_output(pdev);
  565. pm_runtime_disable(&pdev->dev);
  566. return r;
  567. }
  568. dss_debugfs_create_file("hdmi", hdmi_dump_regs);
  569. return 0;
  570. err:
  571. hdmi_pll_uninit(&hdmi.pll);
  572. return r;
  573. }
  574. static void hdmi4_unbind(struct device *dev, struct device *master, void *data)
  575. {
  576. struct platform_device *pdev = to_platform_device(dev);
  577. if (hdmi.audio_pdev)
  578. platform_device_unregister(hdmi.audio_pdev);
  579. hdmi_uninit_output(pdev);
  580. hdmi_pll_uninit(&hdmi.pll);
  581. pm_runtime_disable(&pdev->dev);
  582. }
  583. static const struct component_ops hdmi4_component_ops = {
  584. .bind = hdmi4_bind,
  585. .unbind = hdmi4_unbind,
  586. };
  587. static int hdmi4_probe(struct platform_device *pdev)
  588. {
  589. return component_add(&pdev->dev, &hdmi4_component_ops);
  590. }
  591. static int hdmi4_remove(struct platform_device *pdev)
  592. {
  593. component_del(&pdev->dev, &hdmi4_component_ops);
  594. return 0;
  595. }
  596. static int hdmi_runtime_suspend(struct device *dev)
  597. {
  598. dispc_runtime_put();
  599. return 0;
  600. }
  601. static int hdmi_runtime_resume(struct device *dev)
  602. {
  603. int r;
  604. r = dispc_runtime_get();
  605. if (r < 0)
  606. return r;
  607. return 0;
  608. }
  609. static const struct dev_pm_ops hdmi_pm_ops = {
  610. .runtime_suspend = hdmi_runtime_suspend,
  611. .runtime_resume = hdmi_runtime_resume,
  612. };
  613. static const struct of_device_id hdmi_of_match[] = {
  614. { .compatible = "ti,omap4-hdmi", },
  615. {},
  616. };
  617. static struct platform_driver omapdss_hdmihw_driver = {
  618. .probe = hdmi4_probe,
  619. .remove = hdmi4_remove,
  620. .driver = {
  621. .name = "omapdss_hdmi",
  622. .pm = &hdmi_pm_ops,
  623. .of_match_table = hdmi_of_match,
  624. .suppress_bind_attrs = true,
  625. },
  626. };
  627. int __init hdmi4_init_platform_driver(void)
  628. {
  629. return platform_driver_register(&omapdss_hdmihw_driver);
  630. }
  631. void hdmi4_uninit_platform_driver(void)
  632. {
  633. platform_driver_unregister(&omapdss_hdmihw_driver);
  634. }