2 * HDMI driver for OMAP5
4 * Copyright (C) 2014 Texas Instruments Incorporated
9 * Archit Taneja <archit@ti.com>
10 * Tomi Valkeinen <tomi.valkeinen@ti.com>
12 * This program is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License version 2 as published by
14 * the Free Software Foundation.
16 * This program is distributed in the hope that it will be useful, but WITHOUT
17 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
21 * You should have received a copy of the GNU General Public License along with
22 * this program. If not, see <http://www.gnu.org/licenses/>.
25 #define DSS_SUBSYS_NAME "HDMI"
27 #include <linux/kernel.h>
28 #include <linux/module.h>
29 #include <linux/err.h>
31 #include <linux/interrupt.h>
32 #include <linux/mutex.h>
33 #include <linux/delay.h>
34 #include <linux/string.h>
35 #include <linux/platform_device.h>
36 #include <linux/pm_runtime.h>
37 #include <linux/clk.h>
38 #include <linux/gpio.h>
39 #include <linux/regulator/consumer.h>
40 #include <video/omapdss.h>
41 #include <sound/omap-hdmi-audio.h>
43 #include "hdmi5_core.h"
45 #include "dss_features.h"
47 static struct omap_hdmi hdmi
;
49 static int hdmi_runtime_get(void)
53 DSSDBG("hdmi_runtime_get\n");
55 r
= pm_runtime_get_sync(&hdmi
.pdev
->dev
);
63 static void hdmi_runtime_put(void)
67 DSSDBG("hdmi_runtime_put\n");
69 r
= pm_runtime_put_sync(&hdmi
.pdev
->dev
);
70 WARN_ON(r
< 0 && r
!= -ENOSYS
);
73 static irqreturn_t
hdmi_irq_handler(int irq
, void *data
)
75 struct hdmi_wp_data
*wp
= data
;
78 irqstatus
= hdmi_wp_get_irqstatus(wp
);
79 hdmi_wp_set_irqstatus(wp
, irqstatus
);
81 if ((irqstatus
& HDMI_IRQ_LINK_CONNECT
) &&
82 irqstatus
& HDMI_IRQ_LINK_DISCONNECT
) {
85 * If we get both connect and disconnect interrupts at the same
86 * time, turn off the PHY, clear interrupts, and restart, which
87 * raises connect interrupt if a cable is connected, or nothing
88 * if cable is not connected.
91 hdmi_wp_set_phy_pwr(wp
, HDMI_PHYPWRCMD_OFF
);
94 * We always get bogus CONNECT & DISCONNECT interrupts when
95 * setting the PHY to LDOON. To ignore those, we force the RXDET
96 * line to 0 until the PHY power state has been changed.
98 v
= hdmi_read_reg(hdmi
.phy
.base
, HDMI_TXPHY_PAD_CFG_CTRL
);
99 v
= FLD_MOD(v
, 1, 15, 15); /* FORCE_RXDET_HIGH */
100 v
= FLD_MOD(v
, 0, 14, 7); /* RXDET_LINE */
101 hdmi_write_reg(hdmi
.phy
.base
, HDMI_TXPHY_PAD_CFG_CTRL
, v
);
103 hdmi_wp_set_irqstatus(wp
, HDMI_IRQ_LINK_CONNECT
|
104 HDMI_IRQ_LINK_DISCONNECT
);
106 hdmi_wp_set_phy_pwr(wp
, HDMI_PHYPWRCMD_LDOON
);
108 REG_FLD_MOD(hdmi
.phy
.base
, HDMI_TXPHY_PAD_CFG_CTRL
, 0, 15, 15);
110 } else if (irqstatus
& HDMI_IRQ_LINK_CONNECT
) {
111 hdmi_wp_set_phy_pwr(wp
, HDMI_PHYPWRCMD_TXON
);
112 } else if (irqstatus
& HDMI_IRQ_LINK_DISCONNECT
) {
113 hdmi_wp_set_phy_pwr(wp
, HDMI_PHYPWRCMD_LDOON
);
119 static int hdmi_init_regulator(void)
122 struct regulator
*reg
;
124 if (hdmi
.vdda_reg
!= NULL
)
127 reg
= devm_regulator_get(&hdmi
.pdev
->dev
, "vdda");
129 DSSERR("can't get VDDA regulator\n");
133 if (regulator_can_change_voltage(reg
)) {
134 r
= regulator_set_voltage(reg
, 1800000, 1800000);
136 devm_regulator_put(reg
);
137 DSSWARN("can't set the regulator voltage\n");
147 static int hdmi_power_on_core(struct omap_dss_device
*dssdev
)
151 r
= regulator_enable(hdmi
.vdda_reg
);
155 r
= hdmi_runtime_get();
157 goto err_runtime_get
;
159 /* Make selection of HDMI in DSS */
160 dss_select_hdmi_venc_clk_source(DSS_HDMI_M_PCLK
);
162 hdmi
.core_enabled
= true;
167 regulator_disable(hdmi
.vdda_reg
);
172 static void hdmi_power_off_core(struct omap_dss_device
*dssdev
)
174 hdmi
.core_enabled
= false;
177 regulator_disable(hdmi
.vdda_reg
);
180 static int hdmi_power_on_full(struct omap_dss_device
*dssdev
)
183 struct omap_video_timings
*p
;
184 struct omap_overlay_manager
*mgr
= hdmi
.output
.manager
;
185 struct dss_pll_clock_info hdmi_cinfo
= { 0 };
187 r
= hdmi_power_on_core(dssdev
);
191 p
= &hdmi
.cfg
.timings
;
193 DSSDBG("hdmi_power_on x_res= %d y_res = %d\n", p
->x_res
, p
->y_res
);
195 hdmi_pll_compute(&hdmi
.pll
, p
->pixelclock
, &hdmi_cinfo
);
197 /* disable and clear irqs */
198 hdmi_wp_clear_irqenable(&hdmi
.wp
, 0xffffffff);
199 hdmi_wp_set_irqstatus(&hdmi
.wp
,
200 hdmi_wp_get_irqstatus(&hdmi
.wp
));
202 r
= dss_pll_enable(&hdmi
.pll
.pll
);
204 DSSERR("Failed to enable PLL\n");
208 r
= dss_pll_set_config(&hdmi
.pll
.pll
, &hdmi_cinfo
);
210 DSSERR("Failed to configure PLL\n");
214 r
= hdmi_phy_configure(&hdmi
.phy
, hdmi_cinfo
.clkdco
,
215 hdmi_cinfo
.clkout
[0]);
217 DSSDBG("Failed to start PHY\n");
221 r
= hdmi_wp_set_phy_pwr(&hdmi
.wp
, HDMI_PHYPWRCMD_LDOON
);
225 hdmi5_configure(&hdmi
.core
, &hdmi
.wp
, &hdmi
.cfg
);
227 /* bypass TV gamma table */
228 dispc_enable_gamma_table(0);
231 dss_mgr_set_timings(mgr
, p
);
233 r
= hdmi_wp_video_start(&hdmi
.wp
);
237 r
= dss_mgr_enable(mgr
);
241 hdmi_wp_set_irqenable(&hdmi
.wp
,
242 HDMI_IRQ_LINK_CONNECT
| HDMI_IRQ_LINK_DISCONNECT
);
247 hdmi_wp_video_stop(&hdmi
.wp
);
249 hdmi_wp_set_phy_pwr(&hdmi
.wp
, HDMI_PHYPWRCMD_OFF
);
253 dss_pll_disable(&hdmi
.pll
.pll
);
255 hdmi_power_off_core(dssdev
);
259 static void hdmi_power_off_full(struct omap_dss_device
*dssdev
)
261 struct omap_overlay_manager
*mgr
= hdmi
.output
.manager
;
263 hdmi_wp_clear_irqenable(&hdmi
.wp
, 0xffffffff);
265 dss_mgr_disable(mgr
);
267 hdmi_wp_video_stop(&hdmi
.wp
);
269 hdmi_wp_set_phy_pwr(&hdmi
.wp
, HDMI_PHYPWRCMD_OFF
);
271 dss_pll_disable(&hdmi
.pll
.pll
);
273 hdmi_power_off_core(dssdev
);
276 static int hdmi_display_check_timing(struct omap_dss_device
*dssdev
,
277 struct omap_video_timings
*timings
)
279 struct omap_dss_device
*out
= &hdmi
.output
;
281 /* TODO: proper interlace support */
282 if (timings
->interlace
)
285 if (!dispc_mgr_timings_ok(out
->dispc_channel
, timings
))
291 static void hdmi_display_set_timing(struct omap_dss_device
*dssdev
,
292 struct omap_video_timings
*timings
)
294 mutex_lock(&hdmi
.lock
);
296 hdmi
.cfg
.timings
= *timings
;
298 dispc_set_tv_pclk(timings
->pixelclock
);
300 mutex_unlock(&hdmi
.lock
);
303 static void hdmi_display_get_timings(struct omap_dss_device
*dssdev
,
304 struct omap_video_timings
*timings
)
306 *timings
= hdmi
.cfg
.timings
;
309 static void hdmi_dump_regs(struct seq_file
*s
)
311 mutex_lock(&hdmi
.lock
);
313 if (hdmi_runtime_get()) {
314 mutex_unlock(&hdmi
.lock
);
318 hdmi_wp_dump(&hdmi
.wp
, s
);
319 hdmi_pll_dump(&hdmi
.pll
, s
);
320 hdmi_phy_dump(&hdmi
.phy
, s
);
321 hdmi5_core_dump(&hdmi
.core
, s
);
324 mutex_unlock(&hdmi
.lock
);
327 static int read_edid(u8
*buf
, int len
)
332 mutex_lock(&hdmi
.lock
);
334 r
= hdmi_runtime_get();
337 idlemode
= REG_GET(hdmi
.wp
.base
, HDMI_WP_SYSCONFIG
, 3, 2);
339 REG_FLD_MOD(hdmi
.wp
.base
, HDMI_WP_SYSCONFIG
, 1, 3, 2);
341 r
= hdmi5_read_edid(&hdmi
.core
, buf
, len
);
343 REG_FLD_MOD(hdmi
.wp
.base
, HDMI_WP_SYSCONFIG
, idlemode
, 3, 2);
346 mutex_unlock(&hdmi
.lock
);
351 static int hdmi_display_enable(struct omap_dss_device
*dssdev
)
353 struct omap_dss_device
*out
= &hdmi
.output
;
356 DSSDBG("ENTER hdmi_display_enable\n");
358 mutex_lock(&hdmi
.lock
);
360 if (out
== NULL
|| out
->manager
== NULL
) {
361 DSSERR("failed to enable display: no output/manager\n");
366 r
= hdmi_power_on_full(dssdev
);
368 DSSERR("failed to power on device\n");
372 hdmi
.display_enabled
= true;
374 mutex_unlock(&hdmi
.lock
);
378 mutex_unlock(&hdmi
.lock
);
382 static void hdmi_display_disable(struct omap_dss_device
*dssdev
)
384 DSSDBG("Enter hdmi_display_disable\n");
386 mutex_lock(&hdmi
.lock
);
388 if (hdmi
.audio_pdev
&& hdmi
.audio_abort_cb
)
389 hdmi
.audio_abort_cb(&hdmi
.audio_pdev
->dev
);
391 hdmi_power_off_full(dssdev
);
393 hdmi
.display_enabled
= false;
395 mutex_unlock(&hdmi
.lock
);
398 static int hdmi_core_enable(struct omap_dss_device
*dssdev
)
402 DSSDBG("ENTER omapdss_hdmi_core_enable\n");
404 mutex_lock(&hdmi
.lock
);
406 r
= hdmi_power_on_core(dssdev
);
408 DSSERR("failed to power on device\n");
412 mutex_unlock(&hdmi
.lock
);
416 mutex_unlock(&hdmi
.lock
);
420 static void hdmi_core_disable(struct omap_dss_device
*dssdev
)
422 DSSDBG("Enter omapdss_hdmi_core_disable\n");
424 mutex_lock(&hdmi
.lock
);
426 hdmi_power_off_core(dssdev
);
428 mutex_unlock(&hdmi
.lock
);
431 static int hdmi_connect(struct omap_dss_device
*dssdev
,
432 struct omap_dss_device
*dst
)
434 struct omap_overlay_manager
*mgr
;
437 r
= hdmi_init_regulator();
441 mgr
= omap_dss_get_overlay_manager(dssdev
->dispc_channel
);
445 r
= dss_mgr_connect(mgr
, dssdev
);
449 r
= omapdss_output_set_device(dssdev
, dst
);
451 DSSERR("failed to connect output to new device: %s\n",
453 dss_mgr_disconnect(mgr
, dssdev
);
460 static void hdmi_disconnect(struct omap_dss_device
*dssdev
,
461 struct omap_dss_device
*dst
)
463 WARN_ON(dst
!= dssdev
->dst
);
465 if (dst
!= dssdev
->dst
)
468 omapdss_output_unset_device(dssdev
);
471 dss_mgr_disconnect(dssdev
->manager
, dssdev
);
474 static int hdmi_read_edid(struct omap_dss_device
*dssdev
,
480 need_enable
= hdmi
.core_enabled
== false;
483 r
= hdmi_core_enable(dssdev
);
488 r
= read_edid(edid
, len
);
491 hdmi_core_disable(dssdev
);
496 static int hdmi_set_infoframe(struct omap_dss_device
*dssdev
,
497 const struct hdmi_avi_infoframe
*avi
)
499 hdmi
.cfg
.infoframe
= *avi
;
503 static int hdmi_set_hdmi_mode(struct omap_dss_device
*dssdev
,
506 hdmi
.cfg
.hdmi_dvi_mode
= hdmi_mode
? HDMI_HDMI
: HDMI_DVI
;
510 static const struct omapdss_hdmi_ops hdmi_ops
= {
511 .connect
= hdmi_connect
,
512 .disconnect
= hdmi_disconnect
,
514 .enable
= hdmi_display_enable
,
515 .disable
= hdmi_display_disable
,
517 .check_timings
= hdmi_display_check_timing
,
518 .set_timings
= hdmi_display_set_timing
,
519 .get_timings
= hdmi_display_get_timings
,
521 .read_edid
= hdmi_read_edid
,
522 .set_infoframe
= hdmi_set_infoframe
,
523 .set_hdmi_mode
= hdmi_set_hdmi_mode
,
526 static void hdmi_init_output(struct platform_device
*pdev
)
528 struct omap_dss_device
*out
= &hdmi
.output
;
530 out
->dev
= &pdev
->dev
;
531 out
->id
= OMAP_DSS_OUTPUT_HDMI
;
532 out
->output_type
= OMAP_DISPLAY_TYPE_HDMI
;
533 out
->name
= "hdmi.0";
534 out
->dispc_channel
= OMAP_DSS_CHANNEL_DIGIT
;
535 out
->ops
.hdmi
= &hdmi_ops
;
536 out
->owner
= THIS_MODULE
;
538 omapdss_register_output(out
);
541 static void hdmi_uninit_output(struct platform_device
*pdev
)
543 struct omap_dss_device
*out
= &hdmi
.output
;
545 omapdss_unregister_output(out
);
548 static int hdmi_probe_of(struct platform_device
*pdev
)
550 struct device_node
*node
= pdev
->dev
.of_node
;
551 struct device_node
*ep
;
554 ep
= omapdss_of_get_first_endpoint(node
);
558 r
= hdmi_parse_lanes_of(pdev
, ep
, &hdmi
.phy
);
570 /* Audio callbacks */
571 static int hdmi_audio_startup(struct device
*dev
,
572 void (*abort_cb
)(struct device
*dev
))
574 struct omap_hdmi
*hd
= dev_get_drvdata(dev
);
577 mutex_lock(&hd
->lock
);
579 if (!hdmi_mode_has_audio(&hd
->cfg
) || !hd
->display_enabled
) {
584 hd
->audio_abort_cb
= abort_cb
;
587 mutex_unlock(&hd
->lock
);
592 static int hdmi_audio_shutdown(struct device
*dev
)
594 struct omap_hdmi
*hd
= dev_get_drvdata(dev
);
596 mutex_lock(&hd
->lock
);
597 hd
->audio_abort_cb
= NULL
;
598 mutex_unlock(&hd
->lock
);
603 static int hdmi_audio_start(struct device
*dev
)
605 struct omap_hdmi
*hd
= dev_get_drvdata(dev
);
607 WARN_ON(!hdmi_mode_has_audio(&hd
->cfg
));
608 WARN_ON(!hd
->display_enabled
);
610 /* No-idle while playing audio, store the old value */
611 hd
->wp_idlemode
= REG_GET(hdmi
.wp
.base
, HDMI_WP_SYSCONFIG
, 3, 2);
612 REG_FLD_MOD(hdmi
.wp
.base
, HDMI_WP_SYSCONFIG
, 1, 3, 2);
614 hdmi_wp_audio_enable(&hd
->wp
, true);
615 hdmi_wp_audio_core_req_enable(&hd
->wp
, true);
620 static void hdmi_audio_stop(struct device
*dev
)
622 struct omap_hdmi
*hd
= dev_get_drvdata(dev
);
624 WARN_ON(!hdmi_mode_has_audio(&hd
->cfg
));
625 WARN_ON(!hd
->display_enabled
);
627 hdmi_wp_audio_core_req_enable(&hd
->wp
, false);
628 hdmi_wp_audio_enable(&hd
->wp
, false);
630 /* Playback stopped, restore original idlemode */
631 REG_FLD_MOD(hdmi
.wp
.base
, HDMI_WP_SYSCONFIG
, hd
->wp_idlemode
, 3, 2);
634 static int hdmi_audio_config(struct device
*dev
,
635 struct omap_dss_audio
*dss_audio
)
637 struct omap_hdmi
*hd
= dev_get_drvdata(dev
);
640 mutex_lock(&hd
->lock
);
642 if (!hdmi_mode_has_audio(&hd
->cfg
) || !hd
->display_enabled
) {
647 ret
= hdmi5_audio_config(&hd
->core
, &hd
->wp
, dss_audio
,
648 hd
->cfg
.timings
.pixelclock
);
651 mutex_unlock(&hd
->lock
);
656 static const struct omap_hdmi_audio_ops hdmi_audio_ops
= {
657 .audio_startup
= hdmi_audio_startup
,
658 .audio_shutdown
= hdmi_audio_shutdown
,
659 .audio_start
= hdmi_audio_start
,
660 .audio_stop
= hdmi_audio_stop
,
661 .audio_config
= hdmi_audio_config
,
664 static int hdmi_audio_register(struct device
*dev
)
666 struct omap_hdmi_audio_pdata pdata
= {
668 .dss_version
= omapdss_get_version(),
669 .audio_dma_addr
= hdmi_wp_get_audio_dma_addr(&hdmi
.wp
),
670 .ops
= &hdmi_audio_ops
,
673 hdmi
.audio_pdev
= platform_device_register_data(
674 dev
, "omap-hdmi-audio", PLATFORM_DEVID_AUTO
,
675 &pdata
, sizeof(pdata
));
677 if (IS_ERR(hdmi
.audio_pdev
))
678 return PTR_ERR(hdmi
.audio_pdev
);
683 /* HDMI HW IP initialisation */
684 static int omapdss_hdmihw_probe(struct platform_device
*pdev
)
690 dev_set_drvdata(&pdev
->dev
, &hdmi
);
692 mutex_init(&hdmi
.lock
);
694 if (pdev
->dev
.of_node
) {
695 r
= hdmi_probe_of(pdev
);
700 r
= hdmi_wp_init(pdev
, &hdmi
.wp
);
704 r
= hdmi_pll_init(pdev
, &hdmi
.pll
, &hdmi
.wp
);
708 r
= hdmi_phy_init(pdev
, &hdmi
.phy
);
712 r
= hdmi5_core_init(pdev
, &hdmi
.core
);
716 irq
= platform_get_irq(pdev
, 0);
718 DSSERR("platform_get_irq failed\n");
723 r
= devm_request_threaded_irq(&pdev
->dev
, irq
,
724 NULL
, hdmi_irq_handler
,
725 IRQF_ONESHOT
, "OMAP HDMI", &hdmi
.wp
);
727 DSSERR("HDMI IRQ request failed\n");
731 pm_runtime_enable(&pdev
->dev
);
733 hdmi_init_output(pdev
);
735 r
= hdmi_audio_register(&pdev
->dev
);
737 DSSERR("Registering HDMI audio failed %d\n", r
);
738 hdmi_uninit_output(pdev
);
739 pm_runtime_disable(&pdev
->dev
);
743 dss_debugfs_create_file("hdmi", hdmi_dump_regs
);
747 hdmi_pll_uninit(&hdmi
.pll
);
751 static int __exit
omapdss_hdmihw_remove(struct platform_device
*pdev
)
754 platform_device_unregister(hdmi
.audio_pdev
);
756 hdmi_uninit_output(pdev
);
758 hdmi_pll_uninit(&hdmi
.pll
);
760 pm_runtime_disable(&pdev
->dev
);
765 static int hdmi_runtime_suspend(struct device
*dev
)
772 static int hdmi_runtime_resume(struct device
*dev
)
776 r
= dispc_runtime_get();
783 static const struct dev_pm_ops hdmi_pm_ops
= {
784 .runtime_suspend
= hdmi_runtime_suspend
,
785 .runtime_resume
= hdmi_runtime_resume
,
788 static const struct of_device_id hdmi_of_match
[] = {
789 { .compatible
= "ti,omap5-hdmi", },
790 { .compatible
= "ti,dra7-hdmi", },
794 static struct platform_driver omapdss_hdmihw_driver
= {
795 .probe
= omapdss_hdmihw_probe
,
796 .remove
= __exit_p(omapdss_hdmihw_remove
),
798 .name
= "omapdss_hdmi5",
800 .of_match_table
= hdmi_of_match
,
801 .suppress_bind_attrs
= true,
805 int __init
hdmi5_init_platform_driver(void)
807 return platform_driver_register(&omapdss_hdmihw_driver
);
810 void __exit
hdmi5_uninit_platform_driver(void)
812 platform_driver_unregister(&omapdss_hdmihw_driver
);