xref: /linux/drivers/gpu/drm/omapdrm/dss/hdmi4.c (revision af873fcecef567abf8a3468b06dd4e4aab46da6d)
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 
21 #define DSS_SUBSYS_NAME "HDMI"
22 
23 #include <linux/kernel.h>
24 #include <linux/module.h>
25 #include <linux/err.h>
26 #include <linux/io.h>
27 #include <linux/interrupt.h>
28 #include <linux/mutex.h>
29 #include <linux/delay.h>
30 #include <linux/string.h>
31 #include <linux/platform_device.h>
32 #include <linux/pm_runtime.h>
33 #include <linux/clk.h>
34 #include <linux/gpio.h>
35 #include <linux/regulator/consumer.h>
36 #include <linux/component.h>
37 #include <linux/of.h>
38 #include <linux/of_graph.h>
39 #include <sound/omap-hdmi-audio.h>
40 #include <media/cec.h>
41 
42 #include "omapdss.h"
43 #include "hdmi4_core.h"
44 #include "hdmi4_cec.h"
45 #include "dss.h"
46 #include "hdmi.h"
47 
48 static int hdmi_runtime_get(struct omap_hdmi *hdmi)
49 {
50 	int r;
51 
52 	DSSDBG("hdmi_runtime_get\n");
53 
54 	r = pm_runtime_get_sync(&hdmi->pdev->dev);
55 	WARN_ON(r < 0);
56 	if (r < 0)
57 		return r;
58 
59 	return 0;
60 }
61 
62 static void hdmi_runtime_put(struct omap_hdmi *hdmi)
63 {
64 	int r;
65 
66 	DSSDBG("hdmi_runtime_put\n");
67 
68 	r = pm_runtime_put_sync(&hdmi->pdev->dev);
69 	WARN_ON(r < 0 && r != -ENOSYS);
70 }
71 
72 static irqreturn_t hdmi_irq_handler(int irq, void *data)
73 {
74 	struct omap_hdmi *hdmi = data;
75 	struct hdmi_wp_data *wp = &hdmi->wp;
76 	u32 irqstatus;
77 
78 	irqstatus = hdmi_wp_get_irqstatus(wp);
79 	hdmi_wp_set_irqstatus(wp, irqstatus);
80 
81 	if ((irqstatus & HDMI_IRQ_LINK_CONNECT) &&
82 			irqstatus & HDMI_IRQ_LINK_DISCONNECT) {
83 		/*
84 		 * If we get both connect and disconnect interrupts at the same
85 		 * time, turn off the PHY, clear interrupts, and restart, which
86 		 * raises connect interrupt if a cable is connected, or nothing
87 		 * if cable is not connected.
88 		 */
89 		hdmi_wp_set_phy_pwr(wp, HDMI_PHYPWRCMD_OFF);
90 
91 		hdmi_wp_set_irqstatus(wp, HDMI_IRQ_LINK_CONNECT |
92 				HDMI_IRQ_LINK_DISCONNECT);
93 
94 		hdmi_wp_set_phy_pwr(wp, HDMI_PHYPWRCMD_LDOON);
95 	} else if (irqstatus & HDMI_IRQ_LINK_CONNECT) {
96 		hdmi_wp_set_phy_pwr(wp, HDMI_PHYPWRCMD_TXON);
97 	} else if (irqstatus & HDMI_IRQ_LINK_DISCONNECT) {
98 		hdmi_wp_set_phy_pwr(wp, HDMI_PHYPWRCMD_LDOON);
99 	}
100 	if (irqstatus & HDMI_IRQ_CORE) {
101 		u32 intr4 = hdmi_read_reg(hdmi->core.base, HDMI_CORE_SYS_INTR4);
102 
103 		hdmi_write_reg(hdmi->core.base, HDMI_CORE_SYS_INTR4, intr4);
104 		if (intr4 & 8)
105 			hdmi4_cec_irq(&hdmi->core);
106 	}
107 
108 	return IRQ_HANDLED;
109 }
110 
111 static int hdmi_power_on_core(struct omap_hdmi *hdmi)
112 {
113 	int r;
114 
115 	if (hdmi->core.core_pwr_cnt++)
116 		return 0;
117 
118 	r = regulator_enable(hdmi->vdda_reg);
119 	if (r)
120 		goto err_reg_enable;
121 
122 	r = hdmi_runtime_get(hdmi);
123 	if (r)
124 		goto err_runtime_get;
125 
126 	hdmi4_core_powerdown_disable(&hdmi->core);
127 
128 	/* Make selection of HDMI in DSS */
129 	dss_select_hdmi_venc_clk_source(hdmi->dss, DSS_HDMI_M_PCLK);
130 
131 	hdmi->core_enabled = true;
132 
133 	return 0;
134 
135 err_runtime_get:
136 	regulator_disable(hdmi->vdda_reg);
137 err_reg_enable:
138 	hdmi->core.core_pwr_cnt--;
139 
140 	return r;
141 }
142 
143 static void hdmi_power_off_core(struct omap_hdmi *hdmi)
144 {
145 	if (--hdmi->core.core_pwr_cnt)
146 		return;
147 
148 	hdmi->core_enabled = false;
149 
150 	hdmi_runtime_put(hdmi);
151 	regulator_disable(hdmi->vdda_reg);
152 }
153 
154 static int hdmi_power_on_full(struct omap_hdmi *hdmi)
155 {
156 	int r;
157 	const struct videomode *vm;
158 	struct hdmi_wp_data *wp = &hdmi->wp;
159 	struct dss_pll_clock_info hdmi_cinfo = { 0 };
160 	unsigned int pc;
161 
162 	r = hdmi_power_on_core(hdmi);
163 	if (r)
164 		return r;
165 
166 	/* disable and clear irqs */
167 	hdmi_wp_clear_irqenable(wp, ~HDMI_IRQ_CORE);
168 	hdmi_wp_set_irqstatus(wp, ~HDMI_IRQ_CORE);
169 
170 	vm = &hdmi->cfg.vm;
171 
172 	DSSDBG("hdmi_power_on hactive= %d vactive = %d\n", vm->hactive,
173 	       vm->vactive);
174 
175 	pc = vm->pixelclock;
176 	if (vm->flags & DISPLAY_FLAGS_DOUBLECLK)
177 		pc *= 2;
178 
179 	/* DSS_HDMI_TCLK is bitclk / 10 */
180 	pc *= 10;
181 
182 	dss_pll_calc_b(&hdmi->pll.pll, clk_get_rate(hdmi->pll.pll.clkin),
183 		pc, &hdmi_cinfo);
184 
185 	r = dss_pll_enable(&hdmi->pll.pll);
186 	if (r) {
187 		DSSERR("Failed to enable PLL\n");
188 		goto err_pll_enable;
189 	}
190 
191 	r = dss_pll_set_config(&hdmi->pll.pll, &hdmi_cinfo);
192 	if (r) {
193 		DSSERR("Failed to configure PLL\n");
194 		goto err_pll_cfg;
195 	}
196 
197 	r = hdmi_phy_configure(&hdmi->phy, hdmi_cinfo.clkdco,
198 		hdmi_cinfo.clkout[0]);
199 	if (r) {
200 		DSSDBG("Failed to configure PHY\n");
201 		goto err_phy_cfg;
202 	}
203 
204 	r = hdmi_wp_set_phy_pwr(wp, HDMI_PHYPWRCMD_LDOON);
205 	if (r)
206 		goto err_phy_pwr;
207 
208 	hdmi4_configure(&hdmi->core, &hdmi->wp, &hdmi->cfg);
209 
210 	r = dss_mgr_enable(&hdmi->output);
211 	if (r)
212 		goto err_mgr_enable;
213 
214 	r = hdmi_wp_video_start(&hdmi->wp);
215 	if (r)
216 		goto err_vid_enable;
217 
218 	hdmi_wp_set_irqenable(wp,
219 		HDMI_IRQ_LINK_CONNECT | HDMI_IRQ_LINK_DISCONNECT);
220 
221 	return 0;
222 
223 err_vid_enable:
224 	dss_mgr_disable(&hdmi->output);
225 err_mgr_enable:
226 	hdmi_wp_set_phy_pwr(&hdmi->wp, HDMI_PHYPWRCMD_OFF);
227 err_phy_pwr:
228 err_phy_cfg:
229 err_pll_cfg:
230 	dss_pll_disable(&hdmi->pll.pll);
231 err_pll_enable:
232 	hdmi_power_off_core(hdmi);
233 	return -EIO;
234 }
235 
236 static void hdmi_power_off_full(struct omap_hdmi *hdmi)
237 {
238 	hdmi_wp_clear_irqenable(&hdmi->wp, ~HDMI_IRQ_CORE);
239 
240 	hdmi_wp_video_stop(&hdmi->wp);
241 
242 	dss_mgr_disable(&hdmi->output);
243 
244 	hdmi_wp_set_phy_pwr(&hdmi->wp, HDMI_PHYPWRCMD_OFF);
245 
246 	dss_pll_disable(&hdmi->pll.pll);
247 
248 	hdmi_power_off_core(hdmi);
249 }
250 
251 static void hdmi_display_set_timings(struct omap_dss_device *dssdev,
252 				     const struct drm_display_mode *mode)
253 {
254 	struct omap_hdmi *hdmi = dssdev_to_hdmi(dssdev);
255 
256 	mutex_lock(&hdmi->lock);
257 
258 	drm_display_mode_to_videomode(mode, &hdmi->cfg.vm);
259 
260 	dispc_set_tv_pclk(hdmi->dss->dispc, mode->clock * 1000);
261 
262 	mutex_unlock(&hdmi->lock);
263 }
264 
265 static int hdmi_dump_regs(struct seq_file *s, void *p)
266 {
267 	struct omap_hdmi *hdmi = s->private;
268 
269 	mutex_lock(&hdmi->lock);
270 
271 	if (hdmi_runtime_get(hdmi)) {
272 		mutex_unlock(&hdmi->lock);
273 		return 0;
274 	}
275 
276 	hdmi_wp_dump(&hdmi->wp, s);
277 	hdmi_pll_dump(&hdmi->pll, s);
278 	hdmi_phy_dump(&hdmi->phy, s);
279 	hdmi4_core_dump(&hdmi->core, s);
280 
281 	hdmi_runtime_put(hdmi);
282 	mutex_unlock(&hdmi->lock);
283 	return 0;
284 }
285 
286 static int read_edid(struct omap_hdmi *hdmi, u8 *buf, int len)
287 {
288 	int r;
289 
290 	mutex_lock(&hdmi->lock);
291 
292 	r = hdmi_runtime_get(hdmi);
293 	BUG_ON(r);
294 
295 	r = hdmi4_read_edid(&hdmi->core,  buf, len);
296 
297 	hdmi_runtime_put(hdmi);
298 	mutex_unlock(&hdmi->lock);
299 
300 	return r;
301 }
302 
303 static void hdmi_start_audio_stream(struct omap_hdmi *hd)
304 {
305 	hdmi_wp_audio_enable(&hd->wp, true);
306 	hdmi4_audio_start(&hd->core, &hd->wp);
307 }
308 
309 static void hdmi_stop_audio_stream(struct omap_hdmi *hd)
310 {
311 	hdmi4_audio_stop(&hd->core, &hd->wp);
312 	hdmi_wp_audio_enable(&hd->wp, false);
313 }
314 
315 static void hdmi_display_enable(struct omap_dss_device *dssdev)
316 {
317 	struct omap_hdmi *hdmi = dssdev_to_hdmi(dssdev);
318 	unsigned long flags;
319 	int r;
320 
321 	DSSDBG("ENTER hdmi_display_enable\n");
322 
323 	mutex_lock(&hdmi->lock);
324 
325 	r = hdmi_power_on_full(hdmi);
326 	if (r) {
327 		DSSERR("failed to power on device\n");
328 		goto done;
329 	}
330 
331 	if (hdmi->audio_configured) {
332 		r = hdmi4_audio_config(&hdmi->core, &hdmi->wp,
333 				       &hdmi->audio_config,
334 				       hdmi->cfg.vm.pixelclock);
335 		if (r) {
336 			DSSERR("Error restoring audio configuration: %d", r);
337 			hdmi->audio_abort_cb(&hdmi->pdev->dev);
338 			hdmi->audio_configured = false;
339 		}
340 	}
341 
342 	spin_lock_irqsave(&hdmi->audio_playing_lock, flags);
343 	if (hdmi->audio_configured && hdmi->audio_playing)
344 		hdmi_start_audio_stream(hdmi);
345 	hdmi->display_enabled = true;
346 	spin_unlock_irqrestore(&hdmi->audio_playing_lock, flags);
347 
348 done:
349 	mutex_unlock(&hdmi->lock);
350 }
351 
352 static void hdmi_display_disable(struct omap_dss_device *dssdev)
353 {
354 	struct omap_hdmi *hdmi = dssdev_to_hdmi(dssdev);
355 	unsigned long flags;
356 
357 	DSSDBG("Enter hdmi_display_disable\n");
358 
359 	mutex_lock(&hdmi->lock);
360 
361 	spin_lock_irqsave(&hdmi->audio_playing_lock, flags);
362 	hdmi_stop_audio_stream(hdmi);
363 	hdmi->display_enabled = false;
364 	spin_unlock_irqrestore(&hdmi->audio_playing_lock, flags);
365 
366 	hdmi_power_off_full(hdmi);
367 
368 	mutex_unlock(&hdmi->lock);
369 }
370 
371 int hdmi4_core_enable(struct hdmi_core_data *core)
372 {
373 	struct omap_hdmi *hdmi = container_of(core, struct omap_hdmi, core);
374 	int r = 0;
375 
376 	DSSDBG("ENTER omapdss_hdmi4_core_enable\n");
377 
378 	mutex_lock(&hdmi->lock);
379 
380 	r = hdmi_power_on_core(hdmi);
381 	if (r) {
382 		DSSERR("failed to power on device\n");
383 		goto err0;
384 	}
385 
386 	mutex_unlock(&hdmi->lock);
387 	return 0;
388 
389 err0:
390 	mutex_unlock(&hdmi->lock);
391 	return r;
392 }
393 
394 void hdmi4_core_disable(struct hdmi_core_data *core)
395 {
396 	struct omap_hdmi *hdmi = container_of(core, struct omap_hdmi, core);
397 
398 	DSSDBG("Enter omapdss_hdmi4_core_disable\n");
399 
400 	mutex_lock(&hdmi->lock);
401 
402 	hdmi_power_off_core(hdmi);
403 
404 	mutex_unlock(&hdmi->lock);
405 }
406 
407 static int hdmi_connect(struct omap_dss_device *src,
408 			struct omap_dss_device *dst)
409 {
410 	return omapdss_device_connect(dst->dss, dst, dst->next);
411 }
412 
413 static void hdmi_disconnect(struct omap_dss_device *src,
414 			    struct omap_dss_device *dst)
415 {
416 	omapdss_device_disconnect(dst, dst->next);
417 }
418 
419 static int hdmi_read_edid(struct omap_dss_device *dssdev,
420 		u8 *edid, int len)
421 {
422 	struct omap_hdmi *hdmi = dssdev_to_hdmi(dssdev);
423 	bool need_enable;
424 	int r;
425 
426 	need_enable = hdmi->core_enabled == false;
427 
428 	if (need_enable) {
429 		r = hdmi4_core_enable(&hdmi->core);
430 		if (r)
431 			return r;
432 	}
433 
434 	r = read_edid(hdmi, edid, len);
435 	if (r >= 256)
436 		hdmi4_cec_set_phys_addr(&hdmi->core,
437 					cec_get_edid_phys_addr(edid, r, NULL));
438 	else
439 		hdmi4_cec_set_phys_addr(&hdmi->core, CEC_PHYS_ADDR_INVALID);
440 	if (need_enable)
441 		hdmi4_core_disable(&hdmi->core);
442 
443 	return r;
444 }
445 
446 static void hdmi_lost_hotplug(struct omap_dss_device *dssdev)
447 {
448 	struct omap_hdmi *hdmi = dssdev_to_hdmi(dssdev);
449 
450 	hdmi4_cec_set_phys_addr(&hdmi->core, CEC_PHYS_ADDR_INVALID);
451 }
452 
453 static int hdmi_set_infoframe(struct omap_dss_device *dssdev,
454 		const struct hdmi_avi_infoframe *avi)
455 {
456 	struct omap_hdmi *hdmi = dssdev_to_hdmi(dssdev);
457 
458 	hdmi->cfg.infoframe = *avi;
459 	return 0;
460 }
461 
462 static int hdmi_set_hdmi_mode(struct omap_dss_device *dssdev,
463 		bool hdmi_mode)
464 {
465 	struct omap_hdmi *hdmi = dssdev_to_hdmi(dssdev);
466 
467 	hdmi->cfg.hdmi_dvi_mode = hdmi_mode ? HDMI_HDMI : HDMI_DVI;
468 	return 0;
469 }
470 
471 static const struct omap_dss_device_ops hdmi_ops = {
472 	.connect		= hdmi_connect,
473 	.disconnect		= hdmi_disconnect,
474 
475 	.enable			= hdmi_display_enable,
476 	.disable		= hdmi_display_disable,
477 
478 	.set_timings		= hdmi_display_set_timings,
479 
480 	.read_edid		= hdmi_read_edid,
481 
482 	.hdmi = {
483 		.lost_hotplug		= hdmi_lost_hotplug,
484 		.set_infoframe		= hdmi_set_infoframe,
485 		.set_hdmi_mode		= hdmi_set_hdmi_mode,
486 	},
487 };
488 
489 /* -----------------------------------------------------------------------------
490  * Audio Callbacks
491  */
492 
493 static int hdmi_audio_startup(struct device *dev,
494 			      void (*abort_cb)(struct device *dev))
495 {
496 	struct omap_hdmi *hd = dev_get_drvdata(dev);
497 
498 	mutex_lock(&hd->lock);
499 
500 	WARN_ON(hd->audio_abort_cb != NULL);
501 
502 	hd->audio_abort_cb = abort_cb;
503 
504 	mutex_unlock(&hd->lock);
505 
506 	return 0;
507 }
508 
509 static int hdmi_audio_shutdown(struct device *dev)
510 {
511 	struct omap_hdmi *hd = dev_get_drvdata(dev);
512 
513 	mutex_lock(&hd->lock);
514 	hd->audio_abort_cb = NULL;
515 	hd->audio_configured = false;
516 	hd->audio_playing = false;
517 	mutex_unlock(&hd->lock);
518 
519 	return 0;
520 }
521 
522 static int hdmi_audio_start(struct device *dev)
523 {
524 	struct omap_hdmi *hd = dev_get_drvdata(dev);
525 	unsigned long flags;
526 
527 	spin_lock_irqsave(&hd->audio_playing_lock, flags);
528 
529 	if (hd->display_enabled) {
530 		if (!hdmi_mode_has_audio(&hd->cfg))
531 			DSSERR("%s: Video mode does not support audio\n",
532 			       __func__);
533 		hdmi_start_audio_stream(hd);
534 	}
535 	hd->audio_playing = true;
536 
537 	spin_unlock_irqrestore(&hd->audio_playing_lock, flags);
538 	return 0;
539 }
540 
541 static void hdmi_audio_stop(struct device *dev)
542 {
543 	struct omap_hdmi *hd = dev_get_drvdata(dev);
544 	unsigned long flags;
545 
546 	WARN_ON(!hdmi_mode_has_audio(&hd->cfg));
547 
548 	spin_lock_irqsave(&hd->audio_playing_lock, flags);
549 
550 	if (hd->display_enabled)
551 		hdmi_stop_audio_stream(hd);
552 	hd->audio_playing = false;
553 
554 	spin_unlock_irqrestore(&hd->audio_playing_lock, flags);
555 }
556 
557 static int hdmi_audio_config(struct device *dev,
558 			     struct omap_dss_audio *dss_audio)
559 {
560 	struct omap_hdmi *hd = dev_get_drvdata(dev);
561 	int ret = 0;
562 
563 	mutex_lock(&hd->lock);
564 
565 	if (hd->display_enabled) {
566 		ret = hdmi4_audio_config(&hd->core, &hd->wp, dss_audio,
567 					 hd->cfg.vm.pixelclock);
568 		if (ret)
569 			goto out;
570 	}
571 
572 	hd->audio_configured = true;
573 	hd->audio_config = *dss_audio;
574 out:
575 	mutex_unlock(&hd->lock);
576 
577 	return ret;
578 }
579 
580 static const struct omap_hdmi_audio_ops hdmi_audio_ops = {
581 	.audio_startup = hdmi_audio_startup,
582 	.audio_shutdown = hdmi_audio_shutdown,
583 	.audio_start = hdmi_audio_start,
584 	.audio_stop = hdmi_audio_stop,
585 	.audio_config = hdmi_audio_config,
586 };
587 
588 static int hdmi_audio_register(struct omap_hdmi *hdmi)
589 {
590 	struct omap_hdmi_audio_pdata pdata = {
591 		.dev = &hdmi->pdev->dev,
592 		.version = 4,
593 		.audio_dma_addr = hdmi_wp_get_audio_dma_addr(&hdmi->wp),
594 		.ops = &hdmi_audio_ops,
595 	};
596 
597 	hdmi->audio_pdev = platform_device_register_data(
598 		&hdmi->pdev->dev, "omap-hdmi-audio", PLATFORM_DEVID_AUTO,
599 		&pdata, sizeof(pdata));
600 
601 	if (IS_ERR(hdmi->audio_pdev))
602 		return PTR_ERR(hdmi->audio_pdev);
603 
604 	return 0;
605 }
606 
607 /* -----------------------------------------------------------------------------
608  * Component Bind & Unbind
609  */
610 
611 static int hdmi4_bind(struct device *dev, struct device *master, void *data)
612 {
613 	struct dss_device *dss = dss_get_device(master);
614 	struct omap_hdmi *hdmi = dev_get_drvdata(dev);
615 	int r;
616 
617 	hdmi->dss = dss;
618 
619 	r = hdmi_runtime_get(hdmi);
620 	if (r)
621 		return r;
622 
623 	r = hdmi_pll_init(dss, hdmi->pdev, &hdmi->pll, &hdmi->wp);
624 	if (r)
625 		goto err_runtime_put;
626 
627 	r = hdmi4_cec_init(hdmi->pdev, &hdmi->core, &hdmi->wp);
628 	if (r)
629 		goto err_pll_uninit;
630 
631 	r = hdmi_audio_register(hdmi);
632 	if (r) {
633 		DSSERR("Registering HDMI audio failed\n");
634 		goto err_cec_uninit;
635 	}
636 
637 	hdmi->debugfs = dss_debugfs_create_file(dss, "hdmi", hdmi_dump_regs,
638 					       hdmi);
639 
640 	hdmi_runtime_put(hdmi);
641 
642 	return 0;
643 
644 err_cec_uninit:
645 	hdmi4_cec_uninit(&hdmi->core);
646 err_pll_uninit:
647 	hdmi_pll_uninit(&hdmi->pll);
648 err_runtime_put:
649 	hdmi_runtime_put(hdmi);
650 	return r;
651 }
652 
653 static void hdmi4_unbind(struct device *dev, struct device *master, void *data)
654 {
655 	struct omap_hdmi *hdmi = dev_get_drvdata(dev);
656 
657 	dss_debugfs_remove_file(hdmi->debugfs);
658 
659 	if (hdmi->audio_pdev)
660 		platform_device_unregister(hdmi->audio_pdev);
661 
662 	hdmi4_cec_uninit(&hdmi->core);
663 	hdmi_pll_uninit(&hdmi->pll);
664 }
665 
666 static const struct component_ops hdmi4_component_ops = {
667 	.bind	= hdmi4_bind,
668 	.unbind	= hdmi4_unbind,
669 };
670 
671 /* -----------------------------------------------------------------------------
672  * Probe & Remove, Suspend & Resume
673  */
674 
675 static int hdmi4_init_output(struct omap_hdmi *hdmi)
676 {
677 	struct omap_dss_device *out = &hdmi->output;
678 	int r;
679 
680 	out->dev = &hdmi->pdev->dev;
681 	out->id = OMAP_DSS_OUTPUT_HDMI;
682 	out->type = OMAP_DISPLAY_TYPE_HDMI;
683 	out->name = "hdmi.0";
684 	out->dispc_channel = OMAP_DSS_CHANNEL_DIGIT;
685 	out->ops = &hdmi_ops;
686 	out->owner = THIS_MODULE;
687 	out->of_ports = BIT(0);
688 	out->ops_flags = OMAP_DSS_DEVICE_OP_EDID;
689 
690 	r = omapdss_device_init_output(out);
691 	if (r < 0)
692 		return r;
693 
694 	omapdss_device_register(out);
695 
696 	return 0;
697 }
698 
699 static void hdmi4_uninit_output(struct omap_hdmi *hdmi)
700 {
701 	struct omap_dss_device *out = &hdmi->output;
702 
703 	omapdss_device_unregister(out);
704 	omapdss_device_cleanup_output(out);
705 }
706 
707 static int hdmi4_probe_of(struct omap_hdmi *hdmi)
708 {
709 	struct platform_device *pdev = hdmi->pdev;
710 	struct device_node *node = pdev->dev.of_node;
711 	struct device_node *ep;
712 	int r;
713 
714 	ep = of_graph_get_endpoint_by_regs(node, 0, 0);
715 	if (!ep)
716 		return 0;
717 
718 	r = hdmi_parse_lanes_of(pdev, ep, &hdmi->phy);
719 	of_node_put(ep);
720 	return r;
721 }
722 
723 static int hdmi4_probe(struct platform_device *pdev)
724 {
725 	struct omap_hdmi *hdmi;
726 	int irq;
727 	int r;
728 
729 	hdmi = kzalloc(sizeof(*hdmi), GFP_KERNEL);
730 	if (!hdmi)
731 		return -ENOMEM;
732 
733 	hdmi->pdev = pdev;
734 
735 	dev_set_drvdata(&pdev->dev, hdmi);
736 
737 	mutex_init(&hdmi->lock);
738 	spin_lock_init(&hdmi->audio_playing_lock);
739 
740 	r = hdmi4_probe_of(hdmi);
741 	if (r)
742 		goto err_free;
743 
744 	r = hdmi_wp_init(pdev, &hdmi->wp, 4);
745 	if (r)
746 		goto err_free;
747 
748 	r = hdmi_phy_init(pdev, &hdmi->phy, 4);
749 	if (r)
750 		goto err_free;
751 
752 	r = hdmi4_core_init(pdev, &hdmi->core);
753 	if (r)
754 		goto err_free;
755 
756 	irq = platform_get_irq(pdev, 0);
757 	if (irq < 0) {
758 		DSSERR("platform_get_irq failed\n");
759 		r = -ENODEV;
760 		goto err_free;
761 	}
762 
763 	r = devm_request_threaded_irq(&pdev->dev, irq,
764 			NULL, hdmi_irq_handler,
765 			IRQF_ONESHOT, "OMAP HDMI", hdmi);
766 	if (r) {
767 		DSSERR("HDMI IRQ request failed\n");
768 		goto err_free;
769 	}
770 
771 	hdmi->vdda_reg = devm_regulator_get(&pdev->dev, "vdda");
772 	if (IS_ERR(hdmi->vdda_reg)) {
773 		r = PTR_ERR(hdmi->vdda_reg);
774 		if (r != -EPROBE_DEFER)
775 			DSSERR("can't get VDDA regulator\n");
776 		goto err_free;
777 	}
778 
779 	pm_runtime_enable(&pdev->dev);
780 
781 	r = hdmi4_init_output(hdmi);
782 	if (r)
783 		goto err_pm_disable;
784 
785 	r = component_add(&pdev->dev, &hdmi4_component_ops);
786 	if (r)
787 		goto err_uninit_output;
788 
789 	return 0;
790 
791 err_uninit_output:
792 	hdmi4_uninit_output(hdmi);
793 err_pm_disable:
794 	pm_runtime_disable(&pdev->dev);
795 err_free:
796 	kfree(hdmi);
797 	return r;
798 }
799 
800 static int hdmi4_remove(struct platform_device *pdev)
801 {
802 	struct omap_hdmi *hdmi = platform_get_drvdata(pdev);
803 
804 	component_del(&pdev->dev, &hdmi4_component_ops);
805 
806 	hdmi4_uninit_output(hdmi);
807 
808 	pm_runtime_disable(&pdev->dev);
809 
810 	kfree(hdmi);
811 	return 0;
812 }
813 
814 static const struct of_device_id hdmi_of_match[] = {
815 	{ .compatible = "ti,omap4-hdmi", },
816 	{},
817 };
818 
819 struct platform_driver omapdss_hdmi4hw_driver = {
820 	.probe		= hdmi4_probe,
821 	.remove		= hdmi4_remove,
822 	.driver         = {
823 		.name   = "omapdss_hdmi",
824 		.of_match_table = hdmi_of_match,
825 		.suppress_bind_attrs = true,
826 	},
827 };
828