2 * HDMI interface DSS driver for TI's OMAP4 family of SoCs.
3 * Copyright (C) 2010-2011 Texas Instruments Incorporated - http://www.ti.com/
5 * Mythri pk <mythripk@ti.com>
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.
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
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/>.
20 #define DSS_SUBSYS_NAME "HDMI"
22 #include <linux/kernel.h>
23 #include <linux/module.h>
24 #include <linux/err.h>
26 #include <linux/interrupt.h>
27 #include <linux/mutex.h>
28 #include <linux/delay.h>
29 #include <linux/string.h>
30 #include <linux/platform_device.h>
31 #include <linux/pm_runtime.h>
32 #include <linux/clk.h>
33 #include <linux/gpio.h>
34 #include <linux/regulator/consumer.h>
35 #include <video/omapdss.h>
36 #include <sound/omap-hdmi-audio.h>
38 #include "hdmi4_core.h"
40 #include "dss_features.h"
43 static struct omap_hdmi hdmi
;
45 static int hdmi_runtime_get(void)
49 DSSDBG("hdmi_runtime_get\n");
51 r
= pm_runtime_get_sync(&hdmi
.pdev
->dev
);
59 static void hdmi_runtime_put(void)
63 DSSDBG("hdmi_runtime_put\n");
65 r
= pm_runtime_put_sync(&hdmi
.pdev
->dev
);
66 WARN_ON(r
< 0 && r
!= -ENOSYS
);
69 static irqreturn_t
hdmi_irq_handler(int irq
, void *data
)
71 struct hdmi_wp_data
*wp
= data
;
74 irqstatus
= hdmi_wp_get_irqstatus(wp
);
75 hdmi_wp_set_irqstatus(wp
, irqstatus
);
77 if ((irqstatus
& HDMI_IRQ_LINK_CONNECT
) &&
78 irqstatus
& HDMI_IRQ_LINK_DISCONNECT
) {
80 * If we get both connect and disconnect interrupts at the same
81 * time, turn off the PHY, clear interrupts, and restart, which
82 * raises connect interrupt if a cable is connected, or nothing
83 * if cable is not connected.
85 hdmi_wp_set_phy_pwr(wp
, HDMI_PHYPWRCMD_OFF
);
87 hdmi_wp_set_irqstatus(wp
, HDMI_IRQ_LINK_CONNECT
|
88 HDMI_IRQ_LINK_DISCONNECT
);
90 hdmi_wp_set_phy_pwr(wp
, HDMI_PHYPWRCMD_LDOON
);
91 } else if (irqstatus
& HDMI_IRQ_LINK_CONNECT
) {
92 hdmi_wp_set_phy_pwr(wp
, HDMI_PHYPWRCMD_TXON
);
93 } else if (irqstatus
& HDMI_IRQ_LINK_DISCONNECT
) {
94 hdmi_wp_set_phy_pwr(wp
, HDMI_PHYPWRCMD_LDOON
);
100 static int hdmi_init_regulator(void)
103 struct regulator
*reg
;
105 if (hdmi
.vdda_reg
!= NULL
)
108 reg
= devm_regulator_get(&hdmi
.pdev
->dev
, "vdda");
111 if (PTR_ERR(reg
) != -EPROBE_DEFER
)
112 DSSERR("can't get VDDA regulator\n");
116 if (regulator_can_change_voltage(reg
)) {
117 r
= regulator_set_voltage(reg
, 1800000, 1800000);
119 devm_regulator_put(reg
);
120 DSSWARN("can't set the regulator voltage\n");
130 static int hdmi_power_on_core(struct omap_dss_device
*dssdev
)
134 r
= regulator_enable(hdmi
.vdda_reg
);
138 r
= hdmi_runtime_get();
140 goto err_runtime_get
;
142 /* Make selection of HDMI in DSS */
143 dss_select_hdmi_venc_clk_source(DSS_HDMI_M_PCLK
);
145 hdmi
.core_enabled
= true;
150 regulator_disable(hdmi
.vdda_reg
);
155 static void hdmi_power_off_core(struct omap_dss_device
*dssdev
)
157 hdmi
.core_enabled
= false;
160 regulator_disable(hdmi
.vdda_reg
);
163 static int hdmi_power_on_full(struct omap_dss_device
*dssdev
)
166 struct omap_video_timings
*p
;
167 struct omap_overlay_manager
*mgr
= hdmi
.output
.manager
;
168 struct hdmi_wp_data
*wp
= &hdmi
.wp
;
169 struct dss_pll_clock_info hdmi_cinfo
= { 0 };
171 r
= hdmi_power_on_core(dssdev
);
175 /* disable and clear irqs */
176 hdmi_wp_clear_irqenable(wp
, 0xffffffff);
177 hdmi_wp_set_irqstatus(wp
, 0xffffffff);
179 p
= &hdmi
.cfg
.timings
;
181 DSSDBG("hdmi_power_on x_res= %d y_res = %d\n", p
->x_res
, p
->y_res
);
183 hdmi_pll_compute(&hdmi
.pll
, p
->pixelclock
, &hdmi_cinfo
);
185 r
= dss_pll_enable(&hdmi
.pll
.pll
);
187 DSSERR("Failed to enable PLL\n");
191 r
= dss_pll_set_config(&hdmi
.pll
.pll
, &hdmi_cinfo
);
193 DSSERR("Failed to configure PLL\n");
197 r
= hdmi_phy_configure(&hdmi
.phy
, hdmi_cinfo
.clkdco
,
198 hdmi_cinfo
.clkout
[0]);
200 DSSDBG("Failed to configure PHY\n");
204 r
= hdmi_wp_set_phy_pwr(wp
, HDMI_PHYPWRCMD_LDOON
);
208 hdmi4_configure(&hdmi
.core
, &hdmi
.wp
, &hdmi
.cfg
);
210 /* bypass TV gamma table */
211 dispc_enable_gamma_table(0);
214 dss_mgr_set_timings(mgr
, p
);
216 r
= hdmi_wp_video_start(&hdmi
.wp
);
220 r
= dss_mgr_enable(mgr
);
224 hdmi_wp_set_irqenable(wp
,
225 HDMI_IRQ_LINK_CONNECT
| HDMI_IRQ_LINK_DISCONNECT
);
230 hdmi_wp_video_stop(&hdmi
.wp
);
233 hdmi_wp_set_phy_pwr(&hdmi
.wp
, HDMI_PHYPWRCMD_OFF
);
236 dss_pll_disable(&hdmi
.pll
.pll
);
238 hdmi_power_off_core(dssdev
);
242 static void hdmi_power_off_full(struct omap_dss_device
*dssdev
)
244 struct omap_overlay_manager
*mgr
= hdmi
.output
.manager
;
246 hdmi_wp_clear_irqenable(&hdmi
.wp
, 0xffffffff);
248 dss_mgr_disable(mgr
);
250 hdmi_wp_video_stop(&hdmi
.wp
);
252 hdmi_wp_set_phy_pwr(&hdmi
.wp
, HDMI_PHYPWRCMD_OFF
);
254 dss_pll_disable(&hdmi
.pll
.pll
);
256 hdmi_power_off_core(dssdev
);
259 static int hdmi_display_check_timing(struct omap_dss_device
*dssdev
,
260 struct omap_video_timings
*timings
)
262 struct omap_dss_device
*out
= &hdmi
.output
;
264 if (!dispc_mgr_timings_ok(out
->dispc_channel
, timings
))
270 static void hdmi_display_set_timing(struct omap_dss_device
*dssdev
,
271 struct omap_video_timings
*timings
)
273 mutex_lock(&hdmi
.lock
);
275 hdmi
.cfg
.timings
= *timings
;
277 dispc_set_tv_pclk(timings
->pixelclock
);
279 mutex_unlock(&hdmi
.lock
);
282 static void hdmi_display_get_timings(struct omap_dss_device
*dssdev
,
283 struct omap_video_timings
*timings
)
285 *timings
= hdmi
.cfg
.timings
;
288 static void hdmi_dump_regs(struct seq_file
*s
)
290 mutex_lock(&hdmi
.lock
);
292 if (hdmi_runtime_get()) {
293 mutex_unlock(&hdmi
.lock
);
297 hdmi_wp_dump(&hdmi
.wp
, s
);
298 hdmi_pll_dump(&hdmi
.pll
, s
);
299 hdmi_phy_dump(&hdmi
.phy
, s
);
300 hdmi4_core_dump(&hdmi
.core
, s
);
303 mutex_unlock(&hdmi
.lock
);
306 static int read_edid(u8
*buf
, int len
)
310 mutex_lock(&hdmi
.lock
);
312 r
= hdmi_runtime_get();
315 r
= hdmi4_read_edid(&hdmi
.core
, buf
, len
);
318 mutex_unlock(&hdmi
.lock
);
323 static int hdmi_display_enable(struct omap_dss_device
*dssdev
)
325 struct omap_dss_device
*out
= &hdmi
.output
;
328 DSSDBG("ENTER hdmi_display_enable\n");
330 mutex_lock(&hdmi
.lock
);
332 if (out
== NULL
|| out
->manager
== NULL
) {
333 DSSERR("failed to enable display: no output/manager\n");
338 r
= hdmi_power_on_full(dssdev
);
340 DSSERR("failed to power on device\n");
344 hdmi
.display_enabled
= true;
346 mutex_unlock(&hdmi
.lock
);
350 mutex_unlock(&hdmi
.lock
);
354 static void hdmi_display_disable(struct omap_dss_device
*dssdev
)
356 DSSDBG("Enter hdmi_display_disable\n");
358 mutex_lock(&hdmi
.lock
);
360 if (hdmi
.audio_pdev
&& hdmi
.audio_abort_cb
)
361 hdmi
.audio_abort_cb(&hdmi
.audio_pdev
->dev
);
363 hdmi_power_off_full(dssdev
);
365 hdmi
.display_enabled
= false;
367 mutex_unlock(&hdmi
.lock
);
370 static int hdmi_core_enable(struct omap_dss_device
*dssdev
)
374 DSSDBG("ENTER omapdss_hdmi_core_enable\n");
376 mutex_lock(&hdmi
.lock
);
378 r
= hdmi_power_on_core(dssdev
);
380 DSSERR("failed to power on device\n");
384 mutex_unlock(&hdmi
.lock
);
388 mutex_unlock(&hdmi
.lock
);
392 static void hdmi_core_disable(struct omap_dss_device
*dssdev
)
394 DSSDBG("Enter omapdss_hdmi_core_disable\n");
396 mutex_lock(&hdmi
.lock
);
398 hdmi_power_off_core(dssdev
);
400 mutex_unlock(&hdmi
.lock
);
403 static int hdmi_connect(struct omap_dss_device
*dssdev
,
404 struct omap_dss_device
*dst
)
406 struct omap_overlay_manager
*mgr
;
409 r
= hdmi_init_regulator();
413 mgr
= omap_dss_get_overlay_manager(dssdev
->dispc_channel
);
417 r
= dss_mgr_connect(mgr
, dssdev
);
421 r
= omapdss_output_set_device(dssdev
, dst
);
423 DSSERR("failed to connect output to new device: %s\n",
425 dss_mgr_disconnect(mgr
, dssdev
);
432 static void hdmi_disconnect(struct omap_dss_device
*dssdev
,
433 struct omap_dss_device
*dst
)
435 WARN_ON(dst
!= dssdev
->dst
);
437 if (dst
!= dssdev
->dst
)
440 omapdss_output_unset_device(dssdev
);
443 dss_mgr_disconnect(dssdev
->manager
, dssdev
);
446 static int hdmi_read_edid(struct omap_dss_device
*dssdev
,
452 need_enable
= hdmi
.core_enabled
== false;
455 r
= hdmi_core_enable(dssdev
);
460 r
= read_edid(edid
, len
);
463 hdmi_core_disable(dssdev
);
468 static int hdmi_set_infoframe(struct omap_dss_device
*dssdev
,
469 const struct hdmi_avi_infoframe
*avi
)
471 hdmi
.cfg
.infoframe
= *avi
;
475 static int hdmi_set_hdmi_mode(struct omap_dss_device
*dssdev
,
478 hdmi
.cfg
.hdmi_dvi_mode
= hdmi_mode
? HDMI_HDMI
: HDMI_DVI
;
482 static const struct omapdss_hdmi_ops hdmi_ops
= {
483 .connect
= hdmi_connect
,
484 .disconnect
= hdmi_disconnect
,
486 .enable
= hdmi_display_enable
,
487 .disable
= hdmi_display_disable
,
489 .check_timings
= hdmi_display_check_timing
,
490 .set_timings
= hdmi_display_set_timing
,
491 .get_timings
= hdmi_display_get_timings
,
493 .read_edid
= hdmi_read_edid
,
494 .set_infoframe
= hdmi_set_infoframe
,
495 .set_hdmi_mode
= hdmi_set_hdmi_mode
,
498 static void hdmi_init_output(struct platform_device
*pdev
)
500 struct omap_dss_device
*out
= &hdmi
.output
;
502 out
->dev
= &pdev
->dev
;
503 out
->id
= OMAP_DSS_OUTPUT_HDMI
;
504 out
->output_type
= OMAP_DISPLAY_TYPE_HDMI
;
505 out
->name
= "hdmi.0";
506 out
->dispc_channel
= OMAP_DSS_CHANNEL_DIGIT
;
507 out
->ops
.hdmi
= &hdmi_ops
;
508 out
->owner
= THIS_MODULE
;
510 omapdss_register_output(out
);
513 static void hdmi_uninit_output(struct platform_device
*pdev
)
515 struct omap_dss_device
*out
= &hdmi
.output
;
517 omapdss_unregister_output(out
);
520 static int hdmi_probe_of(struct platform_device
*pdev
)
522 struct device_node
*node
= pdev
->dev
.of_node
;
523 struct device_node
*ep
;
526 ep
= omapdss_of_get_first_endpoint(node
);
530 r
= hdmi_parse_lanes_of(pdev
, ep
, &hdmi
.phy
);
542 /* Audio callbacks */
543 static int hdmi_audio_startup(struct device
*dev
,
544 void (*abort_cb
)(struct device
*dev
))
546 struct omap_hdmi
*hd
= dev_get_drvdata(dev
);
549 mutex_lock(&hd
->lock
);
551 if (!hdmi_mode_has_audio(&hd
->cfg
) || !hd
->display_enabled
) {
556 hd
->audio_abort_cb
= abort_cb
;
559 mutex_unlock(&hd
->lock
);
564 static int hdmi_audio_shutdown(struct device
*dev
)
566 struct omap_hdmi
*hd
= dev_get_drvdata(dev
);
568 mutex_lock(&hd
->lock
);
569 hd
->audio_abort_cb
= NULL
;
570 mutex_unlock(&hd
->lock
);
575 static int hdmi_audio_start(struct device
*dev
)
577 struct omap_hdmi
*hd
= dev_get_drvdata(dev
);
579 WARN_ON(!hdmi_mode_has_audio(&hd
->cfg
));
580 WARN_ON(!hd
->display_enabled
);
582 hdmi_wp_audio_enable(&hd
->wp
, true);
583 hdmi4_audio_start(&hd
->core
, &hd
->wp
);
588 static void hdmi_audio_stop(struct device
*dev
)
590 struct omap_hdmi
*hd
= dev_get_drvdata(dev
);
592 WARN_ON(!hdmi_mode_has_audio(&hd
->cfg
));
593 WARN_ON(!hd
->display_enabled
);
595 hdmi4_audio_stop(&hd
->core
, &hd
->wp
);
596 hdmi_wp_audio_enable(&hd
->wp
, false);
599 static int hdmi_audio_config(struct device
*dev
,
600 struct omap_dss_audio
*dss_audio
)
602 struct omap_hdmi
*hd
= dev_get_drvdata(dev
);
605 mutex_lock(&hd
->lock
);
607 if (!hdmi_mode_has_audio(&hd
->cfg
) || !hd
->display_enabled
) {
612 ret
= hdmi4_audio_config(&hd
->core
, &hd
->wp
, dss_audio
,
613 hd
->cfg
.timings
.pixelclock
);
616 mutex_unlock(&hd
->lock
);
621 static const struct omap_hdmi_audio_ops hdmi_audio_ops
= {
622 .audio_startup
= hdmi_audio_startup
,
623 .audio_shutdown
= hdmi_audio_shutdown
,
624 .audio_start
= hdmi_audio_start
,
625 .audio_stop
= hdmi_audio_stop
,
626 .audio_config
= hdmi_audio_config
,
629 static int hdmi_audio_register(struct device
*dev
)
631 struct omap_hdmi_audio_pdata pdata
= {
633 .dss_version
= omapdss_get_version(),
634 .audio_dma_addr
= hdmi_wp_get_audio_dma_addr(&hdmi
.wp
),
635 .ops
= &hdmi_audio_ops
,
638 hdmi
.audio_pdev
= platform_device_register_data(
639 dev
, "omap-hdmi-audio", PLATFORM_DEVID_AUTO
,
640 &pdata
, sizeof(pdata
));
642 if (IS_ERR(hdmi
.audio_pdev
))
643 return PTR_ERR(hdmi
.audio_pdev
);
648 /* HDMI HW IP initialisation */
649 static int omapdss_hdmihw_probe(struct platform_device
*pdev
)
655 dev_set_drvdata(&pdev
->dev
, &hdmi
);
657 mutex_init(&hdmi
.lock
);
659 if (pdev
->dev
.of_node
) {
660 r
= hdmi_probe_of(pdev
);
665 r
= hdmi_wp_init(pdev
, &hdmi
.wp
);
669 r
= hdmi_pll_init(pdev
, &hdmi
.pll
, &hdmi
.wp
);
673 r
= hdmi_phy_init(pdev
, &hdmi
.phy
);
677 r
= hdmi4_core_init(pdev
, &hdmi
.core
);
681 irq
= platform_get_irq(pdev
, 0);
683 DSSERR("platform_get_irq failed\n");
688 r
= devm_request_threaded_irq(&pdev
->dev
, irq
,
689 NULL
, hdmi_irq_handler
,
690 IRQF_ONESHOT
, "OMAP HDMI", &hdmi
.wp
);
692 DSSERR("HDMI IRQ request failed\n");
696 pm_runtime_enable(&pdev
->dev
);
698 hdmi_init_output(pdev
);
700 r
= hdmi_audio_register(&pdev
->dev
);
702 DSSERR("Registering HDMI audio failed\n");
703 hdmi_uninit_output(pdev
);
704 pm_runtime_disable(&pdev
->dev
);
708 dss_debugfs_create_file("hdmi", hdmi_dump_regs
);
712 hdmi_pll_uninit(&hdmi
.pll
);
716 static int __exit
omapdss_hdmihw_remove(struct platform_device
*pdev
)
719 platform_device_unregister(hdmi
.audio_pdev
);
721 hdmi_uninit_output(pdev
);
723 hdmi_pll_uninit(&hdmi
.pll
);
725 pm_runtime_disable(&pdev
->dev
);
730 static int hdmi_runtime_suspend(struct device
*dev
)
737 static int hdmi_runtime_resume(struct device
*dev
)
741 r
= dispc_runtime_get();
748 static const struct dev_pm_ops hdmi_pm_ops
= {
749 .runtime_suspend
= hdmi_runtime_suspend
,
750 .runtime_resume
= hdmi_runtime_resume
,
753 static const struct of_device_id hdmi_of_match
[] = {
754 { .compatible
= "ti,omap4-hdmi", },
758 static struct platform_driver omapdss_hdmihw_driver
= {
759 .probe
= omapdss_hdmihw_probe
,
760 .remove
= __exit_p(omapdss_hdmihw_remove
),
762 .name
= "omapdss_hdmi",
764 .of_match_table
= hdmi_of_match
,
765 .suppress_bind_attrs
= true,
769 int __init
hdmi4_init_platform_driver(void)
771 return platform_driver_register(&omapdss_hdmihw_driver
);
774 void __exit
hdmi4_uninit_platform_driver(void)
776 platform_driver_unregister(&omapdss_hdmihw_driver
);