hdmi4.c 17 KB

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