hdmi4.c 18 KB

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