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. enum omap_channel channel = dssdev->dispc_channel;
  134. struct hdmi_wp_data *wp = &hdmi.wp;
  135. struct dss_pll_clock_info hdmi_cinfo = { 0 };
  136. unsigned pc;
  137. r = hdmi_power_on_core(dssdev);
  138. if (r)
  139. return r;
  140. /* disable and clear irqs */
  141. hdmi_wp_clear_irqenable(wp, 0xffffffff);
  142. hdmi_wp_set_irqstatus(wp, 0xffffffff);
  143. p = &hdmi.cfg.timings;
  144. DSSDBG("hdmi_power_on x_res= %d y_res = %d\n", p->x_res, p->y_res);
  145. pc = p->pixelclock;
  146. if (p->double_pixel)
  147. pc *= 2;
  148. hdmi_pll_compute(&hdmi.pll, pc, &hdmi_cinfo);
  149. r = dss_pll_enable(&hdmi.pll.pll);
  150. if (r) {
  151. DSSERR("Failed to enable PLL\n");
  152. goto err_pll_enable;
  153. }
  154. r = dss_pll_set_config(&hdmi.pll.pll, &hdmi_cinfo);
  155. if (r) {
  156. DSSERR("Failed to configure PLL\n");
  157. goto err_pll_cfg;
  158. }
  159. r = hdmi_phy_configure(&hdmi.phy, hdmi_cinfo.clkdco,
  160. hdmi_cinfo.clkout[0]);
  161. if (r) {
  162. DSSDBG("Failed to configure PHY\n");
  163. goto err_phy_cfg;
  164. }
  165. r = hdmi_wp_set_phy_pwr(wp, HDMI_PHYPWRCMD_LDOON);
  166. if (r)
  167. goto err_phy_pwr;
  168. hdmi4_configure(&hdmi.core, &hdmi.wp, &hdmi.cfg);
  169. /* bypass TV gamma table */
  170. dispc_enable_gamma_table(0);
  171. /* tv size */
  172. dss_mgr_set_timings(channel, p);
  173. r = dss_mgr_enable(channel);
  174. if (r)
  175. goto err_mgr_enable;
  176. r = hdmi_wp_video_start(&hdmi.wp);
  177. if (r)
  178. goto err_vid_enable;
  179. hdmi_wp_set_irqenable(wp,
  180. HDMI_IRQ_LINK_CONNECT | HDMI_IRQ_LINK_DISCONNECT);
  181. return 0;
  182. err_vid_enable:
  183. dss_mgr_disable(channel);
  184. err_mgr_enable:
  185. hdmi_wp_set_phy_pwr(&hdmi.wp, HDMI_PHYPWRCMD_OFF);
  186. err_phy_pwr:
  187. err_phy_cfg:
  188. err_pll_cfg:
  189. dss_pll_disable(&hdmi.pll.pll);
  190. err_pll_enable:
  191. hdmi_power_off_core(dssdev);
  192. return -EIO;
  193. }
  194. static void hdmi_power_off_full(struct omap_dss_device *dssdev)
  195. {
  196. enum omap_channel channel = dssdev->dispc_channel;
  197. hdmi_wp_clear_irqenable(&hdmi.wp, 0xffffffff);
  198. hdmi_wp_video_stop(&hdmi.wp);
  199. dss_mgr_disable(channel);
  200. hdmi_wp_set_phy_pwr(&hdmi.wp, HDMI_PHYPWRCMD_OFF);
  201. dss_pll_disable(&hdmi.pll.pll);
  202. hdmi_power_off_core(dssdev);
  203. }
  204. static int hdmi_display_check_timing(struct omap_dss_device *dssdev,
  205. struct omap_video_timings *timings)
  206. {
  207. if (!dispc_mgr_timings_ok(dssdev->dispc_channel, timings))
  208. return -EINVAL;
  209. return 0;
  210. }
  211. static void hdmi_display_set_timing(struct omap_dss_device *dssdev,
  212. struct omap_video_timings *timings)
  213. {
  214. mutex_lock(&hdmi.lock);
  215. hdmi.cfg.timings = *timings;
  216. dispc_set_tv_pclk(timings->pixelclock);
  217. mutex_unlock(&hdmi.lock);
  218. }
  219. static void hdmi_display_get_timings(struct omap_dss_device *dssdev,
  220. struct omap_video_timings *timings)
  221. {
  222. *timings = hdmi.cfg.timings;
  223. }
  224. static void hdmi_dump_regs(struct seq_file *s)
  225. {
  226. mutex_lock(&hdmi.lock);
  227. if (hdmi_runtime_get()) {
  228. mutex_unlock(&hdmi.lock);
  229. return;
  230. }
  231. hdmi_wp_dump(&hdmi.wp, s);
  232. hdmi_pll_dump(&hdmi.pll, s);
  233. hdmi_phy_dump(&hdmi.phy, s);
  234. hdmi4_core_dump(&hdmi.core, s);
  235. hdmi_runtime_put();
  236. mutex_unlock(&hdmi.lock);
  237. }
  238. static int read_edid(u8 *buf, int len)
  239. {
  240. int r;
  241. mutex_lock(&hdmi.lock);
  242. r = hdmi_runtime_get();
  243. BUG_ON(r);
  244. r = hdmi4_read_edid(&hdmi.core, buf, len);
  245. hdmi_runtime_put();
  246. mutex_unlock(&hdmi.lock);
  247. return r;
  248. }
  249. static void hdmi_start_audio_stream(struct omap_hdmi *hd)
  250. {
  251. hdmi_wp_audio_enable(&hd->wp, true);
  252. hdmi4_audio_start(&hd->core, &hd->wp);
  253. }
  254. static void hdmi_stop_audio_stream(struct omap_hdmi *hd)
  255. {
  256. hdmi4_audio_stop(&hd->core, &hd->wp);
  257. hdmi_wp_audio_enable(&hd->wp, false);
  258. }
  259. static int hdmi_display_enable(struct omap_dss_device *dssdev)
  260. {
  261. struct omap_dss_device *out = &hdmi.output;
  262. unsigned long flags;
  263. int r = 0;
  264. DSSDBG("ENTER hdmi_display_enable\n");
  265. mutex_lock(&hdmi.lock);
  266. if (!out->dispc_channel_connected) {
  267. DSSERR("failed to enable display: no output/manager\n");
  268. r = -ENODEV;
  269. goto err0;
  270. }
  271. r = hdmi_power_on_full(dssdev);
  272. if (r) {
  273. DSSERR("failed to power on device\n");
  274. goto err0;
  275. }
  276. if (hdmi.audio_configured) {
  277. r = hdmi4_audio_config(&hdmi.core, &hdmi.wp, &hdmi.audio_config,
  278. hdmi.cfg.timings.pixelclock);
  279. if (r) {
  280. DSSERR("Error restoring audio configuration: %d", r);
  281. hdmi.audio_abort_cb(&hdmi.pdev->dev);
  282. hdmi.audio_configured = false;
  283. }
  284. }
  285. spin_lock_irqsave(&hdmi.audio_playing_lock, flags);
  286. if (hdmi.audio_configured && hdmi.audio_playing)
  287. hdmi_start_audio_stream(&hdmi);
  288. hdmi.display_enabled = true;
  289. spin_unlock_irqrestore(&hdmi.audio_playing_lock, flags);
  290. mutex_unlock(&hdmi.lock);
  291. return 0;
  292. err0:
  293. mutex_unlock(&hdmi.lock);
  294. return r;
  295. }
  296. static void hdmi_display_disable(struct omap_dss_device *dssdev)
  297. {
  298. unsigned long flags;
  299. DSSDBG("Enter hdmi_display_disable\n");
  300. mutex_lock(&hdmi.lock);
  301. spin_lock_irqsave(&hdmi.audio_playing_lock, flags);
  302. hdmi_stop_audio_stream(&hdmi);
  303. hdmi.display_enabled = false;
  304. spin_unlock_irqrestore(&hdmi.audio_playing_lock, flags);
  305. hdmi_power_off_full(dssdev);
  306. mutex_unlock(&hdmi.lock);
  307. }
  308. static int hdmi_core_enable(struct omap_dss_device *dssdev)
  309. {
  310. int r = 0;
  311. DSSDBG("ENTER omapdss_hdmi_core_enable\n");
  312. mutex_lock(&hdmi.lock);
  313. r = hdmi_power_on_core(dssdev);
  314. if (r) {
  315. DSSERR("failed to power on device\n");
  316. goto err0;
  317. }
  318. mutex_unlock(&hdmi.lock);
  319. return 0;
  320. err0:
  321. mutex_unlock(&hdmi.lock);
  322. return r;
  323. }
  324. static void hdmi_core_disable(struct omap_dss_device *dssdev)
  325. {
  326. DSSDBG("Enter omapdss_hdmi_core_disable\n");
  327. mutex_lock(&hdmi.lock);
  328. hdmi_power_off_core(dssdev);
  329. mutex_unlock(&hdmi.lock);
  330. }
  331. static int hdmi_connect(struct omap_dss_device *dssdev,
  332. struct omap_dss_device *dst)
  333. {
  334. enum omap_channel channel = dssdev->dispc_channel;
  335. int r;
  336. r = hdmi_init_regulator();
  337. if (r)
  338. return r;
  339. r = dss_mgr_connect(channel, 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(channel, 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. enum omap_channel channel = dssdev->dispc_channel;
  355. WARN_ON(dst != dssdev->dst);
  356. if (dst != dssdev->dst)
  357. return;
  358. omapdss_output_unset_device(dssdev);
  359. dss_mgr_disconnect(channel, 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. }