hdmi4.c 18 KB

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