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>
37 #include "hdmi4_core.h"
39 #include "dss_features.h"
43 struct platform_device *pdev;
45 struct hdmi_wp_data wp;
46 struct hdmi_pll_data pll;
47 struct hdmi_phy_data phy;
48 struct hdmi_core_data core;
50 struct hdmi_config cfg;
53 struct regulator *vdda_hdmi_dac_reg;
57 struct omap_dss_device output;
60 static int hdmi_runtime_get(void)
64 DSSDBG("hdmi_runtime_get\n");
66 r = pm_runtime_get_sync(&hdmi.pdev->dev);
74 static void hdmi_runtime_put(void)
78 DSSDBG("hdmi_runtime_put\n");
80 r = pm_runtime_put_sync(&hdmi.pdev->dev);
81 WARN_ON(r < 0 && r != -ENOSYS);
84 static irqreturn_t hdmi_irq_handler(int irq, void *data)
86 struct hdmi_wp_data *wp = data;
89 irqstatus = hdmi_wp_get_irqstatus(wp);
90 hdmi_wp_set_irqstatus(wp, irqstatus);
92 if ((irqstatus & HDMI_IRQ_LINK_CONNECT) &&
93 irqstatus & HDMI_IRQ_LINK_DISCONNECT) {
95 * If we get both connect and disconnect interrupts at the same
96 * time, turn off the PHY, clear interrupts, and restart, which
97 * raises connect interrupt if a cable is connected, or nothing
98 * if cable is not connected.
100 hdmi_wp_set_phy_pwr(wp, HDMI_PHYPWRCMD_OFF);
102 hdmi_wp_set_irqstatus(wp, HDMI_IRQ_LINK_CONNECT |
103 HDMI_IRQ_LINK_DISCONNECT);
105 hdmi_wp_set_phy_pwr(wp, HDMI_PHYPWRCMD_LDOON);
106 } else if (irqstatus & HDMI_IRQ_LINK_CONNECT) {
107 hdmi_wp_set_phy_pwr(wp, HDMI_PHYPWRCMD_TXON);
108 } else if (irqstatus & HDMI_IRQ_LINK_DISCONNECT) {
109 hdmi_wp_set_phy_pwr(wp, HDMI_PHYPWRCMD_LDOON);
115 static int hdmi_init_regulator(void)
118 struct regulator *reg;
120 if (hdmi.vdda_hdmi_dac_reg != NULL)
123 reg = devm_regulator_get(&hdmi.pdev->dev, "vdda");
126 if (PTR_ERR(reg) != -EPROBE_DEFER)
127 DSSERR("can't get VDDA regulator\n");
131 if (regulator_can_change_voltage(reg)) {
132 r = regulator_set_voltage(reg, 1800000, 1800000);
134 devm_regulator_put(reg);
135 DSSWARN("can't set the regulator voltage\n");
140 hdmi.vdda_hdmi_dac_reg = reg;
145 static int hdmi_power_on_core(struct omap_dss_device *dssdev)
149 r = regulator_enable(hdmi.vdda_hdmi_dac_reg);
153 r = hdmi_runtime_get();
155 goto err_runtime_get;
157 /* Make selection of HDMI in DSS */
158 dss_select_hdmi_venc_clk_source(DSS_HDMI_M_PCLK);
160 hdmi.core_enabled = true;
165 regulator_disable(hdmi.vdda_hdmi_dac_reg);
170 static void hdmi_power_off_core(struct omap_dss_device *dssdev)
172 hdmi.core_enabled = false;
175 regulator_disable(hdmi.vdda_hdmi_dac_reg);
178 static int hdmi_power_on_full(struct omap_dss_device *dssdev)
181 struct omap_video_timings *p;
182 struct omap_overlay_manager *mgr = hdmi.output.manager;
183 struct hdmi_wp_data *wp = &hdmi.wp;
185 r = hdmi_power_on_core(dssdev);
189 /* disable and clear irqs */
190 hdmi_wp_clear_irqenable(wp, 0xffffffff);
191 hdmi_wp_set_irqstatus(wp, 0xffffffff);
193 p = &hdmi.cfg.timings;
195 DSSDBG("hdmi_power_on x_res= %d y_res = %d\n", p->x_res, p->y_res);
197 hdmi_pll_compute(&hdmi.pll, clk_get_rate(hdmi.sys_clk), p->pixelclock);
199 r = hdmi_pll_enable(&hdmi.pll);
201 DSSERR("Failed to enable PLL\n");
205 r = hdmi_pll_set_config(&hdmi.pll);
207 DSSERR("Failed to configure PLL\n");
211 r = hdmi_phy_configure(&hdmi.phy, hdmi.pll.info.clkdco,
212 hdmi.pll.info.clkout);
214 DSSDBG("Failed to configure PHY\n");
218 r = hdmi_wp_set_phy_pwr(wp, HDMI_PHYPWRCMD_LDOON);
222 hdmi4_configure(&hdmi.core, &hdmi.wp, &hdmi.cfg);
224 /* bypass TV gamma table */
225 dispc_enable_gamma_table(0);
228 dss_mgr_set_timings(mgr, p);
230 r = hdmi_wp_video_start(&hdmi.wp);
234 r = dss_mgr_enable(mgr);
238 hdmi_wp_set_irqenable(wp,
239 HDMI_IRQ_LINK_CONNECT | HDMI_IRQ_LINK_DISCONNECT);
244 hdmi_wp_video_stop(&hdmi.wp);
247 hdmi_wp_set_phy_pwr(&hdmi.wp, HDMI_PHYPWRCMD_OFF);
250 hdmi_pll_disable(&hdmi.pll);
252 hdmi_power_off_core(dssdev);
256 static void hdmi_power_off_full(struct omap_dss_device *dssdev)
258 struct omap_overlay_manager *mgr = hdmi.output.manager;
260 hdmi_wp_clear_irqenable(&hdmi.wp, 0xffffffff);
262 dss_mgr_disable(mgr);
264 hdmi_wp_video_stop(&hdmi.wp);
266 hdmi_wp_set_phy_pwr(&hdmi.wp, HDMI_PHYPWRCMD_OFF);
268 hdmi_pll_disable(&hdmi.pll);
270 hdmi_power_off_core(dssdev);
273 static int hdmi_display_check_timing(struct omap_dss_device *dssdev,
274 struct omap_video_timings *timings)
276 struct omap_dss_device *out = &hdmi.output;
278 if (!dispc_mgr_timings_ok(out->dispc_channel, timings))
284 static void hdmi_display_set_timing(struct omap_dss_device *dssdev,
285 struct omap_video_timings *timings)
287 mutex_lock(&hdmi.lock);
289 hdmi.cfg.timings = *timings;
291 dispc_set_tv_pclk(timings->pixelclock);
293 mutex_unlock(&hdmi.lock);
296 static void hdmi_display_get_timings(struct omap_dss_device *dssdev,
297 struct omap_video_timings *timings)
299 *timings = hdmi.cfg.timings;
302 static void hdmi_dump_regs(struct seq_file *s)
304 mutex_lock(&hdmi.lock);
306 if (hdmi_runtime_get()) {
307 mutex_unlock(&hdmi.lock);
311 hdmi_wp_dump(&hdmi.wp, s);
312 hdmi_pll_dump(&hdmi.pll, s);
313 hdmi_phy_dump(&hdmi.phy, s);
314 hdmi4_core_dump(&hdmi.core, s);
317 mutex_unlock(&hdmi.lock);
320 static int read_edid(u8 *buf, int len)
324 mutex_lock(&hdmi.lock);
326 r = hdmi_runtime_get();
329 r = hdmi4_read_edid(&hdmi.core, buf, len);
332 mutex_unlock(&hdmi.lock);
337 static int hdmi_display_enable(struct omap_dss_device *dssdev)
339 struct omap_dss_device *out = &hdmi.output;
342 DSSDBG("ENTER hdmi_display_enable\n");
344 mutex_lock(&hdmi.lock);
346 if (out == NULL || out->manager == NULL) {
347 DSSERR("failed to enable display: no output/manager\n");
352 r = hdmi_power_on_full(dssdev);
354 DSSERR("failed to power on device\n");
358 mutex_unlock(&hdmi.lock);
362 mutex_unlock(&hdmi.lock);
366 static void hdmi_display_disable(struct omap_dss_device *dssdev)
368 DSSDBG("Enter hdmi_display_disable\n");
370 mutex_lock(&hdmi.lock);
372 hdmi_power_off_full(dssdev);
374 mutex_unlock(&hdmi.lock);
377 static int hdmi_core_enable(struct omap_dss_device *dssdev)
381 DSSDBG("ENTER omapdss_hdmi_core_enable\n");
383 mutex_lock(&hdmi.lock);
385 r = hdmi_power_on_core(dssdev);
387 DSSERR("failed to power on device\n");
391 mutex_unlock(&hdmi.lock);
395 mutex_unlock(&hdmi.lock);
399 static void hdmi_core_disable(struct omap_dss_device *dssdev)
401 DSSDBG("Enter omapdss_hdmi_core_disable\n");
403 mutex_lock(&hdmi.lock);
405 hdmi_power_off_core(dssdev);
407 mutex_unlock(&hdmi.lock);
410 static int hdmi_get_clocks(struct platform_device *pdev)
414 clk = devm_clk_get(&pdev->dev, "sys_clk");
416 DSSERR("can't get sys_clk\n");
425 static int hdmi_connect(struct omap_dss_device *dssdev,
426 struct omap_dss_device *dst)
428 struct omap_overlay_manager *mgr;
431 r = hdmi_init_regulator();
435 mgr = omap_dss_get_overlay_manager(dssdev->dispc_channel);
439 r = dss_mgr_connect(mgr, dssdev);
443 r = omapdss_output_set_device(dssdev, dst);
445 DSSERR("failed to connect output to new device: %s\n",
447 dss_mgr_disconnect(mgr, dssdev);
454 static void hdmi_disconnect(struct omap_dss_device *dssdev,
455 struct omap_dss_device *dst)
457 WARN_ON(dst != dssdev->dst);
459 if (dst != dssdev->dst)
462 omapdss_output_unset_device(dssdev);
465 dss_mgr_disconnect(dssdev->manager, dssdev);
468 static int hdmi_read_edid(struct omap_dss_device *dssdev,
474 need_enable = hdmi.core_enabled == false;
477 r = hdmi_core_enable(dssdev);
482 r = read_edid(edid, len);
485 hdmi_core_disable(dssdev);
490 #if defined(CONFIG_OMAP4_DSS_HDMI_AUDIO)
491 static int hdmi_audio_enable(struct omap_dss_device *dssdev)
495 mutex_lock(&hdmi.lock);
497 if (!hdmi_mode_has_audio(hdmi.cfg.hdmi_dvi_mode)) {
502 r = hdmi_wp_audio_enable(&hdmi.wp, true);
506 mutex_unlock(&hdmi.lock);
510 mutex_unlock(&hdmi.lock);
514 static void hdmi_audio_disable(struct omap_dss_device *dssdev)
516 hdmi_wp_audio_enable(&hdmi.wp, false);
519 static int hdmi_audio_start(struct omap_dss_device *dssdev)
521 return hdmi4_audio_start(&hdmi.core, &hdmi.wp);
524 static void hdmi_audio_stop(struct omap_dss_device *dssdev)
526 hdmi4_audio_stop(&hdmi.core, &hdmi.wp);
529 static bool hdmi_audio_supported(struct omap_dss_device *dssdev)
533 mutex_lock(&hdmi.lock);
535 r = hdmi_mode_has_audio(hdmi.cfg.hdmi_dvi_mode);
537 mutex_unlock(&hdmi.lock);
541 static int hdmi_audio_config(struct omap_dss_device *dssdev,
542 struct omap_dss_audio *audio)
545 u32 pclk = hdmi.cfg.timings.pixelclock;
547 mutex_lock(&hdmi.lock);
549 if (!hdmi_mode_has_audio(hdmi.cfg.hdmi_dvi_mode)) {
554 r = hdmi4_audio_config(&hdmi.core, &hdmi.wp, audio, pclk);
558 mutex_unlock(&hdmi.lock);
562 mutex_unlock(&hdmi.lock);
566 static int hdmi_audio_enable(struct omap_dss_device *dssdev)
571 static void hdmi_audio_disable(struct omap_dss_device *dssdev)
575 static int hdmi_audio_start(struct omap_dss_device *dssdev)
580 static void hdmi_audio_stop(struct omap_dss_device *dssdev)
584 static bool hdmi_audio_supported(struct omap_dss_device *dssdev)
589 static int hdmi_audio_config(struct omap_dss_device *dssdev,
590 struct omap_dss_audio *audio)
596 static int hdmi_set_infoframe(struct omap_dss_device *dssdev,
597 const struct hdmi_avi_infoframe *avi)
599 hdmi.cfg.infoframe = *avi;
603 static int hdmi_set_hdmi_mode(struct omap_dss_device *dssdev,
606 hdmi.cfg.hdmi_dvi_mode = hdmi_mode ? HDMI_HDMI : HDMI_DVI;
610 static const struct omapdss_hdmi_ops hdmi_ops = {
611 .connect = hdmi_connect,
612 .disconnect = hdmi_disconnect,
614 .enable = hdmi_display_enable,
615 .disable = hdmi_display_disable,
617 .check_timings = hdmi_display_check_timing,
618 .set_timings = hdmi_display_set_timing,
619 .get_timings = hdmi_display_get_timings,
621 .read_edid = hdmi_read_edid,
622 .set_infoframe = hdmi_set_infoframe,
623 .set_hdmi_mode = hdmi_set_hdmi_mode,
625 .audio_enable = hdmi_audio_enable,
626 .audio_disable = hdmi_audio_disable,
627 .audio_start = hdmi_audio_start,
628 .audio_stop = hdmi_audio_stop,
629 .audio_supported = hdmi_audio_supported,
630 .audio_config = hdmi_audio_config,
633 static void hdmi_init_output(struct platform_device *pdev)
635 struct omap_dss_device *out = &hdmi.output;
637 out->dev = &pdev->dev;
638 out->id = OMAP_DSS_OUTPUT_HDMI;
639 out->output_type = OMAP_DISPLAY_TYPE_HDMI;
640 out->name = "hdmi.0";
641 out->dispc_channel = OMAP_DSS_CHANNEL_DIGIT;
642 out->ops.hdmi = &hdmi_ops;
643 out->owner = THIS_MODULE;
645 omapdss_register_output(out);
648 static void __exit hdmi_uninit_output(struct platform_device *pdev)
650 struct omap_dss_device *out = &hdmi.output;
652 omapdss_unregister_output(out);
655 static int hdmi_probe_of(struct platform_device *pdev)
657 struct device_node *node = pdev->dev.of_node;
658 struct device_node *ep;
661 ep = omapdss_of_get_first_endpoint(node);
665 r = hdmi_parse_lanes_of(pdev, ep, &hdmi.phy);
677 /* HDMI HW IP initialisation */
678 static int omapdss_hdmihw_probe(struct platform_device *pdev)
685 mutex_init(&hdmi.lock);
687 if (pdev->dev.of_node) {
688 r = hdmi_probe_of(pdev);
693 r = hdmi_wp_init(pdev, &hdmi.wp);
697 r = hdmi_pll_init(pdev, &hdmi.pll, &hdmi.wp);
701 r = hdmi_phy_init(pdev, &hdmi.phy);
705 r = hdmi4_core_init(pdev, &hdmi.core);
709 r = hdmi_get_clocks(pdev);
711 DSSERR("can't get clocks\n");
715 irq = platform_get_irq(pdev, 0);
717 DSSERR("platform_get_irq failed\n");
721 r = devm_request_threaded_irq(&pdev->dev, irq,
722 NULL, hdmi_irq_handler,
723 IRQF_ONESHOT, "OMAP HDMI", &hdmi.wp);
725 DSSERR("HDMI IRQ request failed\n");
729 pm_runtime_enable(&pdev->dev);
731 hdmi_init_output(pdev);
733 dss_debugfs_create_file("hdmi", hdmi_dump_regs);
738 static int __exit omapdss_hdmihw_remove(struct platform_device *pdev)
740 hdmi_uninit_output(pdev);
742 pm_runtime_disable(&pdev->dev);
747 static int hdmi_runtime_suspend(struct device *dev)
749 clk_disable_unprepare(hdmi.sys_clk);
756 static int hdmi_runtime_resume(struct device *dev)
760 r = dispc_runtime_get();
764 clk_prepare_enable(hdmi.sys_clk);
769 static const struct dev_pm_ops hdmi_pm_ops = {
770 .runtime_suspend = hdmi_runtime_suspend,
771 .runtime_resume = hdmi_runtime_resume,
774 static const struct of_device_id hdmi_of_match[] = {
775 { .compatible = "ti,omap4-hdmi", },
779 static struct platform_driver omapdss_hdmihw_driver = {
780 .probe = omapdss_hdmihw_probe,
781 .remove = __exit_p(omapdss_hdmihw_remove),
783 .name = "omapdss_hdmi",
784 .owner = THIS_MODULE,
786 .of_match_table = hdmi_of_match,
787 .suppress_bind_attrs = true,
791 int __init hdmi4_init_platform_driver(void)
793 return platform_driver_register(&omapdss_hdmihw_driver);
796 void __exit hdmi4_uninit_platform_driver(void)
798 platform_driver_unregister(&omapdss_hdmihw_driver);