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;
203 r = hdmi_power_on_core(dssdev);
207 p = &hdmi.cfg.timings;
209 DSSDBG("hdmi_power_on x_res= %d y_res = %d\n", p->x_res, p->y_res);
211 /* the functions below use kHz pixel clock. TODO: change to Hz */
212 phy = p->pixelclock / 1000;
214 hdmi_pll_compute(&hdmi.pll, clk_get_rate(hdmi.sys_clk), phy);
216 /* disable and clear irqs */
217 hdmi_wp_clear_irqenable(&hdmi.wp, 0xffffffff);
218 hdmi_wp_set_irqstatus(&hdmi.wp,
219 hdmi_wp_get_irqstatus(&hdmi.wp));
221 /* config the PLL and PHY hdmi_set_pll_pwrfirst */
222 r = hdmi_pll_enable(&hdmi.pll, &hdmi.wp);
224 DSSDBG("Failed to lock PLL\n");
228 r = hdmi_phy_configure(&hdmi.phy, &hdmi.cfg);
230 DSSDBG("Failed to start PHY\n");
234 r = hdmi_wp_set_phy_pwr(&hdmi.wp, HDMI_PHYPWRCMD_LDOON);
238 hdmi5_configure(&hdmi.core, &hdmi.wp, &hdmi.cfg);
240 /* bypass TV gamma table */
241 dispc_enable_gamma_table(0);
244 dss_mgr_set_timings(mgr, p);
246 r = hdmi_wp_video_start(&hdmi.wp);
250 r = dss_mgr_enable(mgr);
254 hdmi_wp_set_irqenable(&hdmi.wp,
255 HDMI_IRQ_LINK_CONNECT | HDMI_IRQ_LINK_DISCONNECT);
260 hdmi_wp_video_stop(&hdmi.wp);
262 hdmi_wp_set_phy_pwr(&hdmi.wp, HDMI_PHYPWRCMD_OFF);
265 hdmi_pll_disable(&hdmi.pll, &hdmi.wp);
267 hdmi_power_off_core(dssdev);
271 static void hdmi_power_off_full(struct omap_dss_device *dssdev)
273 struct omap_overlay_manager *mgr = hdmi.output.manager;
275 hdmi_wp_clear_irqenable(&hdmi.wp, 0xffffffff);
277 dss_mgr_disable(mgr);
279 hdmi_wp_video_stop(&hdmi.wp);
281 hdmi_wp_set_phy_pwr(&hdmi.wp, HDMI_PHYPWRCMD_OFF);
283 hdmi_pll_disable(&hdmi.pll, &hdmi.wp);
285 hdmi_power_off_core(dssdev);
288 static int hdmi_display_check_timing(struct omap_dss_device *dssdev,
289 struct omap_video_timings *timings)
291 struct omap_dss_device *out = &hdmi.output;
293 if (!dispc_mgr_timings_ok(out->dispc_channel, timings))
299 static void hdmi_display_set_timing(struct omap_dss_device *dssdev,
300 struct omap_video_timings *timings)
302 mutex_lock(&hdmi.lock);
304 hdmi.cfg.timings = *timings;
306 dispc_set_tv_pclk(timings->pixelclock);
308 mutex_unlock(&hdmi.lock);
311 static void hdmi_display_get_timings(struct omap_dss_device *dssdev,
312 struct omap_video_timings *timings)
314 *timings = hdmi.cfg.timings;
317 static void hdmi_dump_regs(struct seq_file *s)
319 mutex_lock(&hdmi.lock);
321 if (hdmi_runtime_get()) {
322 mutex_unlock(&hdmi.lock);
326 hdmi_wp_dump(&hdmi.wp, s);
327 hdmi_pll_dump(&hdmi.pll, s);
328 hdmi_phy_dump(&hdmi.phy, s);
329 hdmi5_core_dump(&hdmi.core, s);
332 mutex_unlock(&hdmi.lock);
335 static int read_edid(u8 *buf, int len)
340 mutex_lock(&hdmi.lock);
342 r = hdmi_runtime_get();
345 idlemode = REG_GET(hdmi.wp.base, HDMI_WP_SYSCONFIG, 3, 2);
347 REG_FLD_MOD(hdmi.wp.base, HDMI_WP_SYSCONFIG, 1, 3, 2);
349 r = hdmi5_read_edid(&hdmi.core, buf, len);
351 REG_FLD_MOD(hdmi.wp.base, HDMI_WP_SYSCONFIG, idlemode, 3, 2);
354 mutex_unlock(&hdmi.lock);
359 static int hdmi_display_enable(struct omap_dss_device *dssdev)
361 struct omap_dss_device *out = &hdmi.output;
364 DSSDBG("ENTER hdmi_display_enable\n");
366 mutex_lock(&hdmi.lock);
368 if (out == NULL || out->manager == NULL) {
369 DSSERR("failed to enable display: no output/manager\n");
374 r = hdmi_power_on_full(dssdev);
376 DSSERR("failed to power on device\n");
380 mutex_unlock(&hdmi.lock);
384 mutex_unlock(&hdmi.lock);
388 static void hdmi_display_disable(struct omap_dss_device *dssdev)
390 DSSDBG("Enter hdmi_display_disable\n");
392 mutex_lock(&hdmi.lock);
394 hdmi_power_off_full(dssdev);
396 mutex_unlock(&hdmi.lock);
399 static int hdmi_core_enable(struct omap_dss_device *dssdev)
403 DSSDBG("ENTER omapdss_hdmi_core_enable\n");
405 mutex_lock(&hdmi.lock);
407 r = hdmi_power_on_core(dssdev);
409 DSSERR("failed to power on device\n");
413 mutex_unlock(&hdmi.lock);
417 mutex_unlock(&hdmi.lock);
421 static void hdmi_core_disable(struct omap_dss_device *dssdev)
423 DSSDBG("Enter omapdss_hdmi_core_disable\n");
425 mutex_lock(&hdmi.lock);
427 hdmi_power_off_core(dssdev);
429 mutex_unlock(&hdmi.lock);
432 static int hdmi_get_clocks(struct platform_device *pdev)
436 clk = devm_clk_get(&pdev->dev, "sys_clk");
438 DSSERR("can't get sys_clk\n");
447 static int hdmi_connect(struct omap_dss_device *dssdev,
448 struct omap_dss_device *dst)
450 struct omap_overlay_manager *mgr;
453 r = hdmi_init_regulator();
457 mgr = omap_dss_get_overlay_manager(dssdev->dispc_channel);
461 r = dss_mgr_connect(mgr, dssdev);
465 r = omapdss_output_set_device(dssdev, dst);
467 DSSERR("failed to connect output to new device: %s\n",
469 dss_mgr_disconnect(mgr, dssdev);
476 static void hdmi_disconnect(struct omap_dss_device *dssdev,
477 struct omap_dss_device *dst)
479 WARN_ON(dst != dssdev->dst);
481 if (dst != dssdev->dst)
484 omapdss_output_unset_device(dssdev);
487 dss_mgr_disconnect(dssdev->manager, dssdev);
490 static int hdmi_read_edid(struct omap_dss_device *dssdev,
496 need_enable = hdmi.core_enabled == false;
499 r = hdmi_core_enable(dssdev);
504 r = read_edid(edid, len);
507 hdmi_core_disable(dssdev);
512 #if defined(CONFIG_OMAP5_DSS_HDMI_AUDIO)
513 static int hdmi_audio_enable(struct omap_dss_device *dssdev)
517 mutex_lock(&hdmi.lock);
519 if (!hdmi_mode_has_audio(hdmi.cfg.hdmi_dvi_mode)) {
524 r = hdmi_wp_audio_enable(&hdmi.wp, true);
528 mutex_unlock(&hdmi.lock);
532 mutex_unlock(&hdmi.lock);
536 static void hdmi_audio_disable(struct omap_dss_device *dssdev)
538 hdmi_wp_audio_enable(&hdmi.wp, false);
541 static int hdmi_audio_start(struct omap_dss_device *dssdev)
543 return hdmi_wp_audio_core_req_enable(&hdmi.wp, true);
546 static void hdmi_audio_stop(struct omap_dss_device *dssdev)
548 hdmi_wp_audio_core_req_enable(&hdmi.wp, false);
551 static bool hdmi_audio_supported(struct omap_dss_device *dssdev)
555 mutex_lock(&hdmi.lock);
557 r = hdmi_mode_has_audio(hdmi.cfg.hdmi_dvi_mode);
559 mutex_unlock(&hdmi.lock);
563 static int hdmi_audio_config(struct omap_dss_device *dssdev,
564 struct omap_dss_audio *audio)
567 u32 pclk = hdmi.cfg.timings.pixelclock;
569 mutex_lock(&hdmi.lock);
571 if (!hdmi_mode_has_audio(hdmi.cfg.hdmi_dvi_mode)) {
576 r = hdmi5_audio_config(&hdmi.core, &hdmi.wp, audio, pclk);
580 mutex_unlock(&hdmi.lock);
584 mutex_unlock(&hdmi.lock);
588 static int hdmi_audio_enable(struct omap_dss_device *dssdev)
593 static void hdmi_audio_disable(struct omap_dss_device *dssdev)
597 static int hdmi_audio_start(struct omap_dss_device *dssdev)
602 static void hdmi_audio_stop(struct omap_dss_device *dssdev)
606 static bool hdmi_audio_supported(struct omap_dss_device *dssdev)
611 static int hdmi_audio_config(struct omap_dss_device *dssdev,
612 struct omap_dss_audio *audio)
618 static int hdmi_set_infoframe(struct omap_dss_device *dssdev,
619 const struct hdmi_avi_infoframe *avi)
621 hdmi.cfg.infoframe = *avi;
625 static int hdmi_set_hdmi_mode(struct omap_dss_device *dssdev,
628 hdmi.cfg.hdmi_dvi_mode = hdmi_mode ? HDMI_HDMI : HDMI_DVI;
632 static const struct omapdss_hdmi_ops hdmi_ops = {
633 .connect = hdmi_connect,
634 .disconnect = hdmi_disconnect,
636 .enable = hdmi_display_enable,
637 .disable = hdmi_display_disable,
639 .check_timings = hdmi_display_check_timing,
640 .set_timings = hdmi_display_set_timing,
641 .get_timings = hdmi_display_get_timings,
643 .read_edid = hdmi_read_edid,
644 .set_infoframe = hdmi_set_infoframe,
645 .set_hdmi_mode = hdmi_set_hdmi_mode,
647 .audio_enable = hdmi_audio_enable,
648 .audio_disable = hdmi_audio_disable,
649 .audio_start = hdmi_audio_start,
650 .audio_stop = hdmi_audio_stop,
651 .audio_supported = hdmi_audio_supported,
652 .audio_config = hdmi_audio_config,
655 static void hdmi_init_output(struct platform_device *pdev)
657 struct omap_dss_device *out = &hdmi.output;
659 out->dev = &pdev->dev;
660 out->id = OMAP_DSS_OUTPUT_HDMI;
661 out->output_type = OMAP_DISPLAY_TYPE_HDMI;
662 out->name = "hdmi.0";
663 out->dispc_channel = OMAP_DSS_CHANNEL_DIGIT;
664 out->ops.hdmi = &hdmi_ops;
665 out->owner = THIS_MODULE;
667 omapdss_register_output(out);
670 static void __exit hdmi_uninit_output(struct platform_device *pdev)
672 struct omap_dss_device *out = &hdmi.output;
674 omapdss_unregister_output(out);
677 static int hdmi_probe_of(struct platform_device *pdev)
679 struct device_node *node = pdev->dev.of_node;
680 struct device_node *ep;
683 ep = omapdss_of_get_first_endpoint(node);
687 r = hdmi_parse_lanes_of(pdev, ep, &hdmi.phy);
699 /* HDMI HW IP initialisation */
700 static int omapdss_hdmihw_probe(struct platform_device *pdev)
707 mutex_init(&hdmi.lock);
709 if (pdev->dev.of_node) {
710 r = hdmi_probe_of(pdev);
715 r = hdmi_wp_init(pdev, &hdmi.wp);
719 r = hdmi_pll_init(pdev, &hdmi.pll);
723 r = hdmi_phy_init(pdev, &hdmi.phy);
727 r = hdmi5_core_init(pdev, &hdmi.core);
731 r = hdmi_get_clocks(pdev);
733 DSSERR("can't get clocks\n");
737 irq = platform_get_irq(pdev, 0);
739 DSSERR("platform_get_irq failed\n");
743 r = devm_request_threaded_irq(&pdev->dev, irq,
744 NULL, hdmi_irq_handler,
745 IRQF_ONESHOT, "OMAP HDMI", &hdmi.wp);
747 DSSERR("HDMI IRQ request failed\n");
751 pm_runtime_enable(&pdev->dev);
753 hdmi_init_output(pdev);
755 dss_debugfs_create_file("hdmi", hdmi_dump_regs);
760 static int __exit omapdss_hdmihw_remove(struct platform_device *pdev)
762 hdmi_uninit_output(pdev);
764 pm_runtime_disable(&pdev->dev);
769 static int hdmi_runtime_suspend(struct device *dev)
771 clk_disable_unprepare(hdmi.sys_clk);
778 static int hdmi_runtime_resume(struct device *dev)
782 r = dispc_runtime_get();
786 clk_prepare_enable(hdmi.sys_clk);
791 static const struct dev_pm_ops hdmi_pm_ops = {
792 .runtime_suspend = hdmi_runtime_suspend,
793 .runtime_resume = hdmi_runtime_resume,
796 static const struct of_device_id hdmi_of_match[] = {
797 { .compatible = "ti,omap5-hdmi", },
801 static struct platform_driver omapdss_hdmihw_driver = {
802 .probe = omapdss_hdmihw_probe,
803 .remove = __exit_p(omapdss_hdmihw_remove),
805 .name = "omapdss_hdmi5",
806 .owner = THIS_MODULE,
808 .of_match_table = hdmi_of_match,
809 .suppress_bind_attrs = true,
813 int __init hdmi5_init_platform_driver(void)
815 return platform_driver_register(&omapdss_hdmihw_driver);
818 void __exit hdmi5_uninit_platform_driver(void)
820 platform_driver_unregister(&omapdss_hdmihw_driver);