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>
42 #include "hdmi5_core.h"
44 #include "dss_features.h"
48 struct platform_device *pdev;
50 struct hdmi_wp_data wp;
51 struct hdmi_pll_data pll;
52 struct hdmi_phy_data phy;
53 struct hdmi_core_data core;
55 struct hdmi_config cfg;
58 struct regulator *vdda_reg;
62 struct omap_dss_device output;
65 static int hdmi_runtime_get(void)
69 DSSDBG("hdmi_runtime_get\n");
71 r = pm_runtime_get_sync(&hdmi.pdev->dev);
79 static void hdmi_runtime_put(void)
83 DSSDBG("hdmi_runtime_put\n");
85 r = pm_runtime_put_sync(&hdmi.pdev->dev);
86 WARN_ON(r < 0 && r != -ENOSYS);
89 static irqreturn_t hdmi_irq_handler(int irq, void *data)
91 struct hdmi_wp_data *wp = data;
94 irqstatus = hdmi_wp_get_irqstatus(wp);
95 hdmi_wp_set_irqstatus(wp, irqstatus);
97 if ((irqstatus & HDMI_IRQ_LINK_CONNECT) &&
98 irqstatus & HDMI_IRQ_LINK_DISCONNECT) {
101 * If we get both connect and disconnect interrupts at the same
102 * time, turn off the PHY, clear interrupts, and restart, which
103 * raises connect interrupt if a cable is connected, or nothing
104 * if cable is not connected.
107 hdmi_wp_set_phy_pwr(wp, HDMI_PHYPWRCMD_OFF);
110 * We always get bogus CONNECT & DISCONNECT interrupts when
111 * setting the PHY to LDOON. To ignore those, we force the RXDET
112 * line to 0 until the PHY power state has been changed.
114 v = hdmi_read_reg(hdmi.phy.base, HDMI_TXPHY_PAD_CFG_CTRL);
115 v = FLD_MOD(v, 1, 15, 15); /* FORCE_RXDET_HIGH */
116 v = FLD_MOD(v, 0, 14, 7); /* RXDET_LINE */
117 hdmi_write_reg(hdmi.phy.base, HDMI_TXPHY_PAD_CFG_CTRL, v);
119 hdmi_wp_set_irqstatus(wp, HDMI_IRQ_LINK_CONNECT |
120 HDMI_IRQ_LINK_DISCONNECT);
122 hdmi_wp_set_phy_pwr(wp, HDMI_PHYPWRCMD_LDOON);
124 REG_FLD_MOD(hdmi.phy.base, HDMI_TXPHY_PAD_CFG_CTRL, 0, 15, 15);
126 } else if (irqstatus & HDMI_IRQ_LINK_CONNECT) {
127 hdmi_wp_set_phy_pwr(wp, HDMI_PHYPWRCMD_TXON);
128 } else if (irqstatus & HDMI_IRQ_LINK_DISCONNECT) {
129 hdmi_wp_set_phy_pwr(wp, HDMI_PHYPWRCMD_LDOON);
135 static int hdmi_init_regulator(void)
138 struct regulator *reg;
140 if (hdmi.vdda_reg != NULL)
143 reg = devm_regulator_get(&hdmi.pdev->dev, "vdda");
145 DSSERR("can't get VDDA regulator\n");
149 if (regulator_can_change_voltage(reg)) {
150 r = regulator_set_voltage(reg, 1800000, 1800000);
152 devm_regulator_put(reg);
153 DSSWARN("can't set the regulator voltage\n");
163 static int hdmi_power_on_core(struct omap_dss_device *dssdev)
167 r = regulator_enable(hdmi.vdda_reg);
171 r = hdmi_runtime_get();
173 goto err_runtime_get;
175 /* Make selection of HDMI in DSS */
176 dss_select_hdmi_venc_clk_source(DSS_HDMI_M_PCLK);
178 hdmi.core_enabled = true;
183 regulator_disable(hdmi.vdda_reg);
188 static void hdmi_power_off_core(struct omap_dss_device *dssdev)
190 hdmi.core_enabled = false;
193 regulator_disable(hdmi.vdda_reg);
196 static int hdmi_power_on_full(struct omap_dss_device *dssdev)
199 struct omap_video_timings *p;
200 struct omap_overlay_manager *mgr = hdmi.output.manager;
202 r = hdmi_power_on_core(dssdev);
206 p = &hdmi.cfg.timings;
208 DSSDBG("hdmi_power_on x_res= %d y_res = %d\n", p->x_res, p->y_res);
210 hdmi_pll_compute(&hdmi.pll, clk_get_rate(hdmi.sys_clk), p->pixelclock);
212 /* disable and clear irqs */
213 hdmi_wp_clear_irqenable(&hdmi.wp, 0xffffffff);
214 hdmi_wp_set_irqstatus(&hdmi.wp,
215 hdmi_wp_get_irqstatus(&hdmi.wp));
217 /* config the PLL and PHY hdmi_set_pll_pwrfirst */
218 r = hdmi_pll_enable(&hdmi.pll, &hdmi.wp);
220 DSSDBG("Failed to lock PLL\n");
224 r = hdmi_phy_configure(&hdmi.phy, hdmi.pll.info.clkdco,
225 hdmi.pll.info.clkout);
227 DSSDBG("Failed to start PHY\n");
231 r = hdmi_wp_set_phy_pwr(&hdmi.wp, HDMI_PHYPWRCMD_LDOON);
235 hdmi5_configure(&hdmi.core, &hdmi.wp, &hdmi.cfg);
237 /* bypass TV gamma table */
238 dispc_enable_gamma_table(0);
241 dss_mgr_set_timings(mgr, p);
243 r = hdmi_wp_video_start(&hdmi.wp);
247 r = dss_mgr_enable(mgr);
251 hdmi_wp_set_irqenable(&hdmi.wp,
252 HDMI_IRQ_LINK_CONNECT | HDMI_IRQ_LINK_DISCONNECT);
257 hdmi_wp_video_stop(&hdmi.wp);
259 hdmi_wp_set_phy_pwr(&hdmi.wp, HDMI_PHYPWRCMD_OFF);
262 hdmi_pll_disable(&hdmi.pll, &hdmi.wp);
264 hdmi_power_off_core(dssdev);
268 static void hdmi_power_off_full(struct omap_dss_device *dssdev)
270 struct omap_overlay_manager *mgr = hdmi.output.manager;
272 hdmi_wp_clear_irqenable(&hdmi.wp, 0xffffffff);
274 dss_mgr_disable(mgr);
276 hdmi_wp_video_stop(&hdmi.wp);
278 hdmi_wp_set_phy_pwr(&hdmi.wp, HDMI_PHYPWRCMD_OFF);
280 hdmi_pll_disable(&hdmi.pll, &hdmi.wp);
282 hdmi_power_off_core(dssdev);
285 static int hdmi_display_check_timing(struct omap_dss_device *dssdev,
286 struct omap_video_timings *timings)
288 struct omap_dss_device *out = &hdmi.output;
290 /* TODO: proper interlace support */
291 if (timings->interlace)
294 if (!dispc_mgr_timings_ok(out->dispc_channel, timings))
300 static void hdmi_display_set_timing(struct omap_dss_device *dssdev,
301 struct omap_video_timings *timings)
303 mutex_lock(&hdmi.lock);
305 hdmi.cfg.timings = *timings;
307 dispc_set_tv_pclk(timings->pixelclock);
309 mutex_unlock(&hdmi.lock);
312 static void hdmi_display_get_timings(struct omap_dss_device *dssdev,
313 struct omap_video_timings *timings)
315 *timings = hdmi.cfg.timings;
318 static void hdmi_dump_regs(struct seq_file *s)
320 mutex_lock(&hdmi.lock);
322 if (hdmi_runtime_get()) {
323 mutex_unlock(&hdmi.lock);
327 hdmi_wp_dump(&hdmi.wp, s);
328 hdmi_pll_dump(&hdmi.pll, s);
329 hdmi_phy_dump(&hdmi.phy, s);
330 hdmi5_core_dump(&hdmi.core, s);
333 mutex_unlock(&hdmi.lock);
336 static int read_edid(u8 *buf, int len)
341 mutex_lock(&hdmi.lock);
343 r = hdmi_runtime_get();
346 idlemode = REG_GET(hdmi.wp.base, HDMI_WP_SYSCONFIG, 3, 2);
348 REG_FLD_MOD(hdmi.wp.base, HDMI_WP_SYSCONFIG, 1, 3, 2);
350 r = hdmi5_read_edid(&hdmi.core, buf, len);
352 REG_FLD_MOD(hdmi.wp.base, HDMI_WP_SYSCONFIG, idlemode, 3, 2);
355 mutex_unlock(&hdmi.lock);
360 static int hdmi_display_enable(struct omap_dss_device *dssdev)
362 struct omap_dss_device *out = &hdmi.output;
365 DSSDBG("ENTER hdmi_display_enable\n");
367 mutex_lock(&hdmi.lock);
369 if (out == NULL || out->manager == NULL) {
370 DSSERR("failed to enable display: no output/manager\n");
375 r = hdmi_power_on_full(dssdev);
377 DSSERR("failed to power on device\n");
381 mutex_unlock(&hdmi.lock);
385 mutex_unlock(&hdmi.lock);
389 static void hdmi_display_disable(struct omap_dss_device *dssdev)
391 DSSDBG("Enter hdmi_display_disable\n");
393 mutex_lock(&hdmi.lock);
395 hdmi_power_off_full(dssdev);
397 mutex_unlock(&hdmi.lock);
400 static int hdmi_core_enable(struct omap_dss_device *dssdev)
404 DSSDBG("ENTER omapdss_hdmi_core_enable\n");
406 mutex_lock(&hdmi.lock);
408 r = hdmi_power_on_core(dssdev);
410 DSSERR("failed to power on device\n");
414 mutex_unlock(&hdmi.lock);
418 mutex_unlock(&hdmi.lock);
422 static void hdmi_core_disable(struct omap_dss_device *dssdev)
424 DSSDBG("Enter omapdss_hdmi_core_disable\n");
426 mutex_lock(&hdmi.lock);
428 hdmi_power_off_core(dssdev);
430 mutex_unlock(&hdmi.lock);
433 static int hdmi_get_clocks(struct platform_device *pdev)
437 clk = devm_clk_get(&pdev->dev, "sys_clk");
439 DSSERR("can't get sys_clk\n");
448 static int hdmi_connect(struct omap_dss_device *dssdev,
449 struct omap_dss_device *dst)
451 struct omap_overlay_manager *mgr;
454 r = hdmi_init_regulator();
458 mgr = omap_dss_get_overlay_manager(dssdev->dispc_channel);
462 r = dss_mgr_connect(mgr, dssdev);
466 r = omapdss_output_set_device(dssdev, dst);
468 DSSERR("failed to connect output to new device: %s\n",
470 dss_mgr_disconnect(mgr, dssdev);
477 static void hdmi_disconnect(struct omap_dss_device *dssdev,
478 struct omap_dss_device *dst)
480 WARN_ON(dst != dssdev->dst);
482 if (dst != dssdev->dst)
485 omapdss_output_unset_device(dssdev);
488 dss_mgr_disconnect(dssdev->manager, dssdev);
491 static int hdmi_read_edid(struct omap_dss_device *dssdev,
497 need_enable = hdmi.core_enabled == false;
500 r = hdmi_core_enable(dssdev);
505 r = read_edid(edid, len);
508 hdmi_core_disable(dssdev);
513 #if defined(CONFIG_OMAP5_DSS_HDMI_AUDIO)
514 static int hdmi_audio_enable(struct omap_dss_device *dssdev)
518 mutex_lock(&hdmi.lock);
520 if (!hdmi_mode_has_audio(hdmi.cfg.hdmi_dvi_mode)) {
525 r = hdmi_wp_audio_enable(&hdmi.wp, true);
529 mutex_unlock(&hdmi.lock);
533 mutex_unlock(&hdmi.lock);
537 static void hdmi_audio_disable(struct omap_dss_device *dssdev)
539 hdmi_wp_audio_enable(&hdmi.wp, false);
542 static int hdmi_audio_start(struct omap_dss_device *dssdev)
544 return hdmi_wp_audio_core_req_enable(&hdmi.wp, true);
547 static void hdmi_audio_stop(struct omap_dss_device *dssdev)
549 hdmi_wp_audio_core_req_enable(&hdmi.wp, false);
552 static bool hdmi_audio_supported(struct omap_dss_device *dssdev)
556 mutex_lock(&hdmi.lock);
558 r = hdmi_mode_has_audio(hdmi.cfg.hdmi_dvi_mode);
560 mutex_unlock(&hdmi.lock);
564 static int hdmi_audio_config(struct omap_dss_device *dssdev,
565 struct omap_dss_audio *audio)
568 u32 pclk = hdmi.cfg.timings.pixelclock;
570 mutex_lock(&hdmi.lock);
572 if (!hdmi_mode_has_audio(hdmi.cfg.hdmi_dvi_mode)) {
577 r = hdmi5_audio_config(&hdmi.core, &hdmi.wp, audio, pclk);
581 mutex_unlock(&hdmi.lock);
585 mutex_unlock(&hdmi.lock);
589 static int hdmi_audio_enable(struct omap_dss_device *dssdev)
594 static void hdmi_audio_disable(struct omap_dss_device *dssdev)
598 static int hdmi_audio_start(struct omap_dss_device *dssdev)
603 static void hdmi_audio_stop(struct omap_dss_device *dssdev)
607 static bool hdmi_audio_supported(struct omap_dss_device *dssdev)
612 static int hdmi_audio_config(struct omap_dss_device *dssdev,
613 struct omap_dss_audio *audio)
619 static int hdmi_set_infoframe(struct omap_dss_device *dssdev,
620 const struct hdmi_avi_infoframe *avi)
622 hdmi.cfg.infoframe = *avi;
626 static int hdmi_set_hdmi_mode(struct omap_dss_device *dssdev,
629 hdmi.cfg.hdmi_dvi_mode = hdmi_mode ? HDMI_HDMI : HDMI_DVI;
633 static const struct omapdss_hdmi_ops hdmi_ops = {
634 .connect = hdmi_connect,
635 .disconnect = hdmi_disconnect,
637 .enable = hdmi_display_enable,
638 .disable = hdmi_display_disable,
640 .check_timings = hdmi_display_check_timing,
641 .set_timings = hdmi_display_set_timing,
642 .get_timings = hdmi_display_get_timings,
644 .read_edid = hdmi_read_edid,
645 .set_infoframe = hdmi_set_infoframe,
646 .set_hdmi_mode = hdmi_set_hdmi_mode,
648 .audio_enable = hdmi_audio_enable,
649 .audio_disable = hdmi_audio_disable,
650 .audio_start = hdmi_audio_start,
651 .audio_stop = hdmi_audio_stop,
652 .audio_supported = hdmi_audio_supported,
653 .audio_config = hdmi_audio_config,
656 static void hdmi_init_output(struct platform_device *pdev)
658 struct omap_dss_device *out = &hdmi.output;
660 out->dev = &pdev->dev;
661 out->id = OMAP_DSS_OUTPUT_HDMI;
662 out->output_type = OMAP_DISPLAY_TYPE_HDMI;
663 out->name = "hdmi.0";
664 out->dispc_channel = OMAP_DSS_CHANNEL_DIGIT;
665 out->ops.hdmi = &hdmi_ops;
666 out->owner = THIS_MODULE;
668 omapdss_register_output(out);
671 static void __exit hdmi_uninit_output(struct platform_device *pdev)
673 struct omap_dss_device *out = &hdmi.output;
675 omapdss_unregister_output(out);
678 static int hdmi_probe_of(struct platform_device *pdev)
680 struct device_node *node = pdev->dev.of_node;
681 struct device_node *ep;
684 ep = omapdss_of_get_first_endpoint(node);
688 r = hdmi_parse_lanes_of(pdev, ep, &hdmi.phy);
700 /* HDMI HW IP initialisation */
701 static int omapdss_hdmihw_probe(struct platform_device *pdev)
708 mutex_init(&hdmi.lock);
710 if (pdev->dev.of_node) {
711 r = hdmi_probe_of(pdev);
716 r = hdmi_wp_init(pdev, &hdmi.wp);
720 r = hdmi_pll_init(pdev, &hdmi.pll);
724 r = hdmi_phy_init(pdev, &hdmi.phy);
728 r = hdmi5_core_init(pdev, &hdmi.core);
732 r = hdmi_get_clocks(pdev);
734 DSSERR("can't get clocks\n");
738 irq = platform_get_irq(pdev, 0);
740 DSSERR("platform_get_irq failed\n");
744 r = devm_request_threaded_irq(&pdev->dev, irq,
745 NULL, hdmi_irq_handler,
746 IRQF_ONESHOT, "OMAP HDMI", &hdmi.wp);
748 DSSERR("HDMI IRQ request failed\n");
752 pm_runtime_enable(&pdev->dev);
754 hdmi_init_output(pdev);
756 dss_debugfs_create_file("hdmi", hdmi_dump_regs);
761 static int __exit omapdss_hdmihw_remove(struct platform_device *pdev)
763 hdmi_uninit_output(pdev);
765 pm_runtime_disable(&pdev->dev);
770 static int hdmi_runtime_suspend(struct device *dev)
772 clk_disable_unprepare(hdmi.sys_clk);
779 static int hdmi_runtime_resume(struct device *dev)
783 r = dispc_runtime_get();
787 clk_prepare_enable(hdmi.sys_clk);
792 static const struct dev_pm_ops hdmi_pm_ops = {
793 .runtime_suspend = hdmi_runtime_suspend,
794 .runtime_resume = hdmi_runtime_resume,
797 static const struct of_device_id hdmi_of_match[] = {
798 { .compatible = "ti,omap5-hdmi", },
802 static struct platform_driver omapdss_hdmihw_driver = {
803 .probe = omapdss_hdmihw_probe,
804 .remove = __exit_p(omapdss_hdmihw_remove),
806 .name = "omapdss_hdmi5",
807 .owner = THIS_MODULE,
809 .of_match_table = hdmi_of_match,
810 .suppress_bind_attrs = true,
814 int __init hdmi5_init_platform_driver(void)
816 return platform_driver_register(&omapdss_hdmihw_driver);
819 void __exit hdmi5_uninit_platform_driver(void)
821 platform_driver_unregister(&omapdss_hdmihw_driver);