2 * HDMI interface DSS driver for TI's OMAP4 family of SoCs.
4 * Copyright (C) 2010-2011 Texas Instruments Incorporated - http://www.ti.com/
6 * Mythri pk <mythripk@ti.com>
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.
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
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/>.
21 #define DSS_SUBSYS_NAME "HDMI"
23 #include <linux/kernel.h>
24 #include <linux/module.h>
25 #include <linux/err.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>
38 #include <linux/of_graph.h>
39 #include <sound/omap-hdmi-audio.h>
40 #include <media/cec.h>
43 #include "hdmi4_core.h"
44 #include "hdmi4_cec.h"
48 static struct omap_hdmi hdmi
;
50 static int hdmi_runtime_get(void)
54 DSSDBG("hdmi_runtime_get\n");
56 r
= pm_runtime_get_sync(&hdmi
.pdev
->dev
);
64 static void hdmi_runtime_put(void)
68 DSSDBG("hdmi_runtime_put\n");
70 r
= pm_runtime_put_sync(&hdmi
.pdev
->dev
);
71 WARN_ON(r
< 0 && r
!= -ENOSYS
);
74 static irqreturn_t
hdmi_irq_handler(int irq
, void *data
)
76 struct omap_hdmi
*hdmi
= data
;
77 struct hdmi_wp_data
*wp
= &hdmi
->wp
;
80 irqstatus
= hdmi_wp_get_irqstatus(wp
);
81 hdmi_wp_set_irqstatus(wp
, irqstatus
);
83 if ((irqstatus
& HDMI_IRQ_LINK_CONNECT
) &&
84 irqstatus
& HDMI_IRQ_LINK_DISCONNECT
) {
86 * If we get both connect and disconnect interrupts at the same
87 * time, turn off the PHY, clear interrupts, and restart, which
88 * raises connect interrupt if a cable is connected, or nothing
89 * if cable is not connected.
91 hdmi_wp_set_phy_pwr(wp
, HDMI_PHYPWRCMD_OFF
);
93 hdmi_wp_set_irqstatus(wp
, HDMI_IRQ_LINK_CONNECT
|
94 HDMI_IRQ_LINK_DISCONNECT
);
96 hdmi_wp_set_phy_pwr(wp
, HDMI_PHYPWRCMD_LDOON
);
97 } else if (irqstatus
& HDMI_IRQ_LINK_CONNECT
) {
98 hdmi_wp_set_phy_pwr(wp
, HDMI_PHYPWRCMD_TXON
);
99 } else if (irqstatus
& HDMI_IRQ_LINK_DISCONNECT
) {
100 hdmi_wp_set_phy_pwr(wp
, HDMI_PHYPWRCMD_LDOON
);
102 if (irqstatus
& HDMI_IRQ_CORE
) {
103 u32 intr4
= hdmi_read_reg(hdmi
->core
.base
, HDMI_CORE_SYS_INTR4
);
105 hdmi_write_reg(hdmi
->core
.base
, HDMI_CORE_SYS_INTR4
, intr4
);
107 hdmi4_cec_irq(&hdmi
->core
);
113 static int hdmi_init_regulator(void)
115 struct regulator
*reg
;
117 if (hdmi
.vdda_reg
!= NULL
)
120 reg
= devm_regulator_get(&hdmi
.pdev
->dev
, "vdda");
123 if (PTR_ERR(reg
) != -EPROBE_DEFER
)
124 DSSERR("can't get VDDA regulator\n");
133 static int hdmi_power_on_core(struct omap_dss_device
*dssdev
)
137 if (hdmi
.core
.core_pwr_cnt
++)
140 r
= regulator_enable(hdmi
.vdda_reg
);
144 r
= hdmi_runtime_get();
146 goto err_runtime_get
;
148 hdmi4_core_powerdown_disable(&hdmi
.core
);
150 /* Make selection of HDMI in DSS */
151 dss_select_hdmi_venc_clk_source(DSS_HDMI_M_PCLK
);
153 hdmi
.core_enabled
= true;
158 regulator_disable(hdmi
.vdda_reg
);
160 hdmi
.core
.core_pwr_cnt
--;
165 static void hdmi_power_off_core(struct omap_dss_device
*dssdev
)
167 if (--hdmi
.core
.core_pwr_cnt
)
170 hdmi
.core_enabled
= false;
173 regulator_disable(hdmi
.vdda_reg
);
176 static int hdmi_power_on_full(struct omap_dss_device
*dssdev
)
179 struct videomode
*vm
;
180 enum omap_channel channel
= dssdev
->dispc_channel
;
181 struct hdmi_wp_data
*wp
= &hdmi
.wp
;
182 struct dss_pll_clock_info hdmi_cinfo
= { 0 };
185 r
= hdmi_power_on_core(dssdev
);
189 /* disable and clear irqs */
190 hdmi_wp_clear_irqenable(wp
, ~HDMI_IRQ_CORE
);
191 hdmi_wp_set_irqstatus(wp
, ~HDMI_IRQ_CORE
);
195 DSSDBG("hdmi_power_on hactive= %d vactive = %d\n", vm
->hactive
,
199 if (vm
->flags
& DISPLAY_FLAGS_DOUBLECLK
)
202 /* DSS_HDMI_TCLK is bitclk / 10 */
205 dss_pll_calc_b(&hdmi
.pll
.pll
, clk_get_rate(hdmi
.pll
.pll
.clkin
),
208 r
= dss_pll_enable(&hdmi
.pll
.pll
);
210 DSSERR("Failed to enable PLL\n");
214 r
= dss_pll_set_config(&hdmi
.pll
.pll
, &hdmi_cinfo
);
216 DSSERR("Failed to configure PLL\n");
220 r
= hdmi_phy_configure(&hdmi
.phy
, hdmi_cinfo
.clkdco
,
221 hdmi_cinfo
.clkout
[0]);
223 DSSDBG("Failed to configure PHY\n");
227 r
= hdmi_wp_set_phy_pwr(wp
, HDMI_PHYPWRCMD_LDOON
);
231 hdmi4_configure(&hdmi
.core
, &hdmi
.wp
, &hdmi
.cfg
);
234 dss_mgr_set_timings(channel
, vm
);
236 r
= dss_mgr_enable(channel
);
240 r
= hdmi_wp_video_start(&hdmi
.wp
);
244 hdmi_wp_set_irqenable(wp
,
245 HDMI_IRQ_LINK_CONNECT
| HDMI_IRQ_LINK_DISCONNECT
);
250 dss_mgr_disable(channel
);
252 hdmi_wp_set_phy_pwr(&hdmi
.wp
, HDMI_PHYPWRCMD_OFF
);
256 dss_pll_disable(&hdmi
.pll
.pll
);
258 hdmi_power_off_core(dssdev
);
262 static void hdmi_power_off_full(struct omap_dss_device
*dssdev
)
264 enum omap_channel channel
= dssdev
->dispc_channel
;
266 hdmi_wp_clear_irqenable(&hdmi
.wp
, ~HDMI_IRQ_CORE
);
268 hdmi_wp_video_stop(&hdmi
.wp
);
270 dss_mgr_disable(channel
);
272 hdmi_wp_set_phy_pwr(&hdmi
.wp
, HDMI_PHYPWRCMD_OFF
);
274 dss_pll_disable(&hdmi
.pll
.pll
);
276 hdmi_power_off_core(dssdev
);
279 static int hdmi_display_check_timing(struct omap_dss_device
*dssdev
,
280 struct videomode
*vm
)
282 if (!dispc_mgr_timings_ok(dssdev
->dispc_channel
, vm
))
288 static void hdmi_display_set_timing(struct omap_dss_device
*dssdev
,
289 struct videomode
*vm
)
291 mutex_lock(&hdmi
.lock
);
295 dispc_set_tv_pclk(vm
->pixelclock
);
297 mutex_unlock(&hdmi
.lock
);
300 static void hdmi_display_get_timings(struct omap_dss_device
*dssdev
,
301 struct videomode
*vm
)
306 static void hdmi_dump_regs(struct seq_file
*s
)
308 mutex_lock(&hdmi
.lock
);
310 if (hdmi_runtime_get()) {
311 mutex_unlock(&hdmi
.lock
);
315 hdmi_wp_dump(&hdmi
.wp
, s
);
316 hdmi_pll_dump(&hdmi
.pll
, s
);
317 hdmi_phy_dump(&hdmi
.phy
, s
);
318 hdmi4_core_dump(&hdmi
.core
, s
);
321 mutex_unlock(&hdmi
.lock
);
324 static int read_edid(u8
*buf
, int len
)
328 mutex_lock(&hdmi
.lock
);
330 r
= hdmi_runtime_get();
333 r
= hdmi4_read_edid(&hdmi
.core
, buf
, len
);
336 mutex_unlock(&hdmi
.lock
);
341 static void hdmi_start_audio_stream(struct omap_hdmi
*hd
)
343 hdmi_wp_audio_enable(&hd
->wp
, true);
344 hdmi4_audio_start(&hd
->core
, &hd
->wp
);
347 static void hdmi_stop_audio_stream(struct omap_hdmi
*hd
)
349 hdmi4_audio_stop(&hd
->core
, &hd
->wp
);
350 hdmi_wp_audio_enable(&hd
->wp
, false);
353 static int hdmi_display_enable(struct omap_dss_device
*dssdev
)
355 struct omap_dss_device
*out
= &hdmi
.output
;
359 DSSDBG("ENTER hdmi_display_enable\n");
361 mutex_lock(&hdmi
.lock
);
363 if (!out
->dispc_channel_connected
) {
364 DSSERR("failed to enable display: no output/manager\n");
369 r
= hdmi_power_on_full(dssdev
);
371 DSSERR("failed to power on device\n");
375 if (hdmi
.audio_configured
) {
376 r
= hdmi4_audio_config(&hdmi
.core
, &hdmi
.wp
, &hdmi
.audio_config
,
377 hdmi
.cfg
.vm
.pixelclock
);
379 DSSERR("Error restoring audio configuration: %d", r
);
380 hdmi
.audio_abort_cb(&hdmi
.pdev
->dev
);
381 hdmi
.audio_configured
= false;
385 spin_lock_irqsave(&hdmi
.audio_playing_lock
, flags
);
386 if (hdmi
.audio_configured
&& hdmi
.audio_playing
)
387 hdmi_start_audio_stream(&hdmi
);
388 hdmi
.display_enabled
= true;
389 spin_unlock_irqrestore(&hdmi
.audio_playing_lock
, flags
);
391 mutex_unlock(&hdmi
.lock
);
395 mutex_unlock(&hdmi
.lock
);
399 static void hdmi_display_disable(struct omap_dss_device
*dssdev
)
403 DSSDBG("Enter hdmi_display_disable\n");
405 mutex_lock(&hdmi
.lock
);
407 spin_lock_irqsave(&hdmi
.audio_playing_lock
, flags
);
408 hdmi_stop_audio_stream(&hdmi
);
409 hdmi
.display_enabled
= false;
410 spin_unlock_irqrestore(&hdmi
.audio_playing_lock
, flags
);
412 hdmi_power_off_full(dssdev
);
414 mutex_unlock(&hdmi
.lock
);
417 int hdmi4_core_enable(struct omap_dss_device
*dssdev
)
421 DSSDBG("ENTER omapdss_hdmi4_core_enable\n");
423 mutex_lock(&hdmi
.lock
);
425 r
= hdmi_power_on_core(dssdev
);
427 DSSERR("failed to power on device\n");
431 mutex_unlock(&hdmi
.lock
);
435 mutex_unlock(&hdmi
.lock
);
439 void hdmi4_core_disable(struct omap_dss_device
*dssdev
)
441 DSSDBG("Enter omapdss_hdmi4_core_disable\n");
443 mutex_lock(&hdmi
.lock
);
445 hdmi_power_off_core(dssdev
);
447 mutex_unlock(&hdmi
.lock
);
450 static int hdmi_connect(struct omap_dss_device
*dssdev
,
451 struct omap_dss_device
*dst
)
453 enum omap_channel channel
= dssdev
->dispc_channel
;
456 r
= hdmi_init_regulator();
460 r
= dss_mgr_connect(channel
, dssdev
);
464 r
= omapdss_output_set_device(dssdev
, dst
);
466 DSSERR("failed to connect output to new device: %s\n",
468 dss_mgr_disconnect(channel
, dssdev
);
475 static void hdmi_disconnect(struct omap_dss_device
*dssdev
,
476 struct omap_dss_device
*dst
)
478 enum omap_channel channel
= dssdev
->dispc_channel
;
480 WARN_ON(dst
!= dssdev
->dst
);
482 if (dst
!= dssdev
->dst
)
485 omapdss_output_unset_device(dssdev
);
487 dss_mgr_disconnect(channel
, dssdev
);
490 static int hdmi_read_edid(struct omap_dss_device
*dssdev
,
496 need_enable
= hdmi
.core_enabled
== false;
499 r
= hdmi4_core_enable(dssdev
);
504 r
= read_edid(edid
, len
);
506 hdmi4_cec_set_phys_addr(&hdmi
.core
,
507 cec_get_edid_phys_addr(edid
, r
, NULL
));
509 hdmi4_cec_set_phys_addr(&hdmi
.core
, CEC_PHYS_ADDR_INVALID
);
511 hdmi4_core_disable(dssdev
);
516 static void hdmi_lost_hotplug(struct omap_dss_device
*dssdev
)
518 hdmi4_cec_set_phys_addr(&hdmi
.core
, CEC_PHYS_ADDR_INVALID
);
521 static int hdmi_set_infoframe(struct omap_dss_device
*dssdev
,
522 const struct hdmi_avi_infoframe
*avi
)
524 hdmi
.cfg
.infoframe
= *avi
;
528 static int hdmi_set_hdmi_mode(struct omap_dss_device
*dssdev
,
531 hdmi
.cfg
.hdmi_dvi_mode
= hdmi_mode
? HDMI_HDMI
: HDMI_DVI
;
535 static const struct omapdss_hdmi_ops hdmi_ops
= {
536 .connect
= hdmi_connect
,
537 .disconnect
= hdmi_disconnect
,
539 .enable
= hdmi_display_enable
,
540 .disable
= hdmi_display_disable
,
542 .check_timings
= hdmi_display_check_timing
,
543 .set_timings
= hdmi_display_set_timing
,
544 .get_timings
= hdmi_display_get_timings
,
546 .read_edid
= hdmi_read_edid
,
547 .lost_hotplug
= hdmi_lost_hotplug
,
548 .set_infoframe
= hdmi_set_infoframe
,
549 .set_hdmi_mode
= hdmi_set_hdmi_mode
,
552 static void hdmi_init_output(struct platform_device
*pdev
)
554 struct omap_dss_device
*out
= &hdmi
.output
;
556 out
->dev
= &pdev
->dev
;
557 out
->id
= OMAP_DSS_OUTPUT_HDMI
;
558 out
->output_type
= OMAP_DISPLAY_TYPE_HDMI
;
559 out
->name
= "hdmi.0";
560 out
->dispc_channel
= OMAP_DSS_CHANNEL_DIGIT
;
561 out
->ops
.hdmi
= &hdmi_ops
;
562 out
->owner
= THIS_MODULE
;
564 omapdss_register_output(out
);
567 static void hdmi_uninit_output(struct platform_device
*pdev
)
569 struct omap_dss_device
*out
= &hdmi
.output
;
571 omapdss_unregister_output(out
);
574 static int hdmi_probe_of(struct platform_device
*pdev
)
576 struct device_node
*node
= pdev
->dev
.of_node
;
577 struct device_node
*ep
;
580 ep
= of_graph_get_endpoint_by_regs(node
, 0, 0);
584 r
= hdmi_parse_lanes_of(pdev
, ep
, &hdmi
.phy
);
596 /* Audio callbacks */
597 static int hdmi_audio_startup(struct device
*dev
,
598 void (*abort_cb
)(struct device
*dev
))
600 struct omap_hdmi
*hd
= dev_get_drvdata(dev
);
603 mutex_lock(&hd
->lock
);
605 if (!hdmi_mode_has_audio(&hd
->cfg
) || !hd
->display_enabled
) {
610 hd
->audio_abort_cb
= abort_cb
;
613 mutex_unlock(&hd
->lock
);
618 static int hdmi_audio_shutdown(struct device
*dev
)
620 struct omap_hdmi
*hd
= dev_get_drvdata(dev
);
622 mutex_lock(&hd
->lock
);
623 hd
->audio_abort_cb
= NULL
;
624 hd
->audio_configured
= false;
625 hd
->audio_playing
= false;
626 mutex_unlock(&hd
->lock
);
631 static int hdmi_audio_start(struct device
*dev
)
633 struct omap_hdmi
*hd
= dev_get_drvdata(dev
);
636 WARN_ON(!hdmi_mode_has_audio(&hd
->cfg
));
638 spin_lock_irqsave(&hd
->audio_playing_lock
, flags
);
640 if (hd
->display_enabled
)
641 hdmi_start_audio_stream(hd
);
642 hd
->audio_playing
= true;
644 spin_unlock_irqrestore(&hd
->audio_playing_lock
, flags
);
648 static void hdmi_audio_stop(struct device
*dev
)
650 struct omap_hdmi
*hd
= dev_get_drvdata(dev
);
653 WARN_ON(!hdmi_mode_has_audio(&hd
->cfg
));
655 spin_lock_irqsave(&hd
->audio_playing_lock
, flags
);
657 if (hd
->display_enabled
)
658 hdmi_stop_audio_stream(hd
);
659 hd
->audio_playing
= false;
661 spin_unlock_irqrestore(&hd
->audio_playing_lock
, flags
);
664 static int hdmi_audio_config(struct device
*dev
,
665 struct omap_dss_audio
*dss_audio
)
667 struct omap_hdmi
*hd
= dev_get_drvdata(dev
);
670 mutex_lock(&hd
->lock
);
672 if (!hdmi_mode_has_audio(&hd
->cfg
) || !hd
->display_enabled
) {
677 ret
= hdmi4_audio_config(&hd
->core
, &hd
->wp
, dss_audio
,
678 hd
->cfg
.vm
.pixelclock
);
680 hd
->audio_configured
= true;
681 hd
->audio_config
= *dss_audio
;
684 mutex_unlock(&hd
->lock
);
689 static const struct omap_hdmi_audio_ops hdmi_audio_ops
= {
690 .audio_startup
= hdmi_audio_startup
,
691 .audio_shutdown
= hdmi_audio_shutdown
,
692 .audio_start
= hdmi_audio_start
,
693 .audio_stop
= hdmi_audio_stop
,
694 .audio_config
= hdmi_audio_config
,
697 static int hdmi_audio_register(struct device
*dev
)
699 struct omap_hdmi_audio_pdata pdata
= {
702 .audio_dma_addr
= hdmi_wp_get_audio_dma_addr(&hdmi
.wp
),
703 .ops
= &hdmi_audio_ops
,
706 hdmi
.audio_pdev
= platform_device_register_data(
707 dev
, "omap-hdmi-audio", PLATFORM_DEVID_AUTO
,
708 &pdata
, sizeof(pdata
));
710 if (IS_ERR(hdmi
.audio_pdev
))
711 return PTR_ERR(hdmi
.audio_pdev
);
716 /* HDMI HW IP initialisation */
717 static int hdmi4_bind(struct device
*dev
, struct device
*master
, void *data
)
719 struct platform_device
*pdev
= to_platform_device(dev
);
724 dev_set_drvdata(&pdev
->dev
, &hdmi
);
726 mutex_init(&hdmi
.lock
);
727 spin_lock_init(&hdmi
.audio_playing_lock
);
729 r
= hdmi_probe_of(pdev
);
733 r
= hdmi_wp_init(pdev
, &hdmi
.wp
, 4);
737 r
= hdmi_pll_init(pdev
, &hdmi
.pll
, &hdmi
.wp
);
741 r
= hdmi_phy_init(pdev
, &hdmi
.phy
, 4);
745 r
= hdmi4_core_init(pdev
, &hdmi
.core
);
749 r
= hdmi4_cec_init(pdev
, &hdmi
.core
, &hdmi
.wp
);
753 irq
= platform_get_irq(pdev
, 0);
755 DSSERR("platform_get_irq failed\n");
760 r
= devm_request_threaded_irq(&pdev
->dev
, irq
,
761 NULL
, hdmi_irq_handler
,
762 IRQF_ONESHOT
, "OMAP HDMI", &hdmi
);
764 DSSERR("HDMI IRQ request failed\n");
768 pm_runtime_enable(&pdev
->dev
);
770 hdmi_init_output(pdev
);
772 r
= hdmi_audio_register(&pdev
->dev
);
774 DSSERR("Registering HDMI audio failed\n");
775 hdmi_uninit_output(pdev
);
776 pm_runtime_disable(&pdev
->dev
);
780 dss_debugfs_create_file("hdmi", hdmi_dump_regs
);
784 hdmi_pll_uninit(&hdmi
.pll
);
788 static void hdmi4_unbind(struct device
*dev
, struct device
*master
, void *data
)
790 struct platform_device
*pdev
= to_platform_device(dev
);
793 platform_device_unregister(hdmi
.audio_pdev
);
795 hdmi_uninit_output(pdev
);
797 hdmi4_cec_uninit(&hdmi
.core
);
799 hdmi_pll_uninit(&hdmi
.pll
);
801 pm_runtime_disable(&pdev
->dev
);
804 static const struct component_ops hdmi4_component_ops
= {
806 .unbind
= hdmi4_unbind
,
809 static int hdmi4_probe(struct platform_device
*pdev
)
811 return component_add(&pdev
->dev
, &hdmi4_component_ops
);
814 static int hdmi4_remove(struct platform_device
*pdev
)
816 component_del(&pdev
->dev
, &hdmi4_component_ops
);
820 static int hdmi_runtime_suspend(struct device
*dev
)
827 static int hdmi_runtime_resume(struct device
*dev
)
831 r
= dispc_runtime_get();
838 static const struct dev_pm_ops hdmi_pm_ops
= {
839 .runtime_suspend
= hdmi_runtime_suspend
,
840 .runtime_resume
= hdmi_runtime_resume
,
843 static const struct of_device_id hdmi_of_match
[] = {
844 { .compatible
= "ti,omap4-hdmi", },
848 struct platform_driver omapdss_hdmi4hw_driver
= {
849 .probe
= hdmi4_probe
,
850 .remove
= hdmi4_remove
,
852 .name
= "omapdss_hdmi",
854 .of_match_table
= hdmi_of_match
,
855 .suppress_bind_attrs
= true,