Lines Matching +full:hdmi +full:- +full:bridge

1 // SPDX-License-Identifier: GPL-2.0-only
3 * HDMI interface DSS driver for TI's OMAP4 family of SoCs.
5 * Copyright (C) 2010-2011 Texas Instruments Incorporated - http://www.ti.com/
10 #define DSS_SUBSYS_NAME "HDMI"
27 #include <sound/omap-hdmi-audio.h>
37 #include "hdmi.h"
39 static int hdmi_runtime_get(struct omap_hdmi *hdmi) in hdmi_runtime_get() argument
45 r = pm_runtime_get_sync(&hdmi->pdev->dev); in hdmi_runtime_get()
53 static void hdmi_runtime_put(struct omap_hdmi *hdmi) in hdmi_runtime_put() argument
59 r = pm_runtime_put_sync(&hdmi->pdev->dev); in hdmi_runtime_put()
60 WARN_ON(r < 0 && r != -ENOSYS); in hdmi_runtime_put()
65 struct omap_hdmi *hdmi = data; in hdmi_irq_handler() local
66 struct hdmi_wp_data *wp = &hdmi->wp; in hdmi_irq_handler()
92 u32 intr4 = hdmi_read_reg(hdmi->core.base, HDMI_CORE_SYS_INTR4); in hdmi_irq_handler()
94 hdmi_write_reg(hdmi->core.base, HDMI_CORE_SYS_INTR4, intr4); in hdmi_irq_handler()
96 hdmi4_cec_irq(&hdmi->core); in hdmi_irq_handler()
102 static int hdmi_power_on_core(struct omap_hdmi *hdmi) in hdmi_power_on_core() argument
106 if (hdmi->core.core_pwr_cnt++) in hdmi_power_on_core()
109 r = regulator_enable(hdmi->vdda_reg); in hdmi_power_on_core()
113 r = hdmi_runtime_get(hdmi); in hdmi_power_on_core()
117 hdmi4_core_powerdown_disable(&hdmi->core); in hdmi_power_on_core()
119 /* Make selection of HDMI in DSS */ in hdmi_power_on_core()
120 dss_select_hdmi_venc_clk_source(hdmi->dss, DSS_HDMI_M_PCLK); in hdmi_power_on_core()
122 hdmi->core_enabled = true; in hdmi_power_on_core()
127 regulator_disable(hdmi->vdda_reg); in hdmi_power_on_core()
129 hdmi->core.core_pwr_cnt--; in hdmi_power_on_core()
134 static void hdmi_power_off_core(struct omap_hdmi *hdmi) in hdmi_power_off_core() argument
136 if (--hdmi->core.core_pwr_cnt) in hdmi_power_off_core()
139 hdmi->core_enabled = false; in hdmi_power_off_core()
141 hdmi_runtime_put(hdmi); in hdmi_power_off_core()
142 regulator_disable(hdmi->vdda_reg); in hdmi_power_off_core()
145 static int hdmi_power_on_full(struct omap_hdmi *hdmi) in hdmi_power_on_full() argument
149 struct hdmi_wp_data *wp = &hdmi->wp; in hdmi_power_on_full()
153 r = hdmi_power_on_core(hdmi); in hdmi_power_on_full()
161 vm = &hdmi->cfg.vm; in hdmi_power_on_full()
163 DSSDBG("hdmi_power_on hactive= %d vactive = %d\n", vm->hactive, in hdmi_power_on_full()
164 vm->vactive); in hdmi_power_on_full()
166 pc = vm->pixelclock; in hdmi_power_on_full()
167 if (vm->flags & DISPLAY_FLAGS_DOUBLECLK) in hdmi_power_on_full()
173 dss_pll_calc_b(&hdmi->pll.pll, clk_get_rate(hdmi->pll.pll.clkin), in hdmi_power_on_full()
176 r = dss_pll_enable(&hdmi->pll.pll); in hdmi_power_on_full()
182 r = dss_pll_set_config(&hdmi->pll.pll, &hdmi_cinfo); in hdmi_power_on_full()
188 r = hdmi_phy_configure(&hdmi->phy, hdmi_cinfo.clkdco, in hdmi_power_on_full()
199 hdmi4_configure(&hdmi->core, &hdmi->wp, &hdmi->cfg); in hdmi_power_on_full()
201 r = dss_mgr_enable(&hdmi->output); in hdmi_power_on_full()
205 r = hdmi_wp_video_start(&hdmi->wp); in hdmi_power_on_full()
215 dss_mgr_disable(&hdmi->output); in hdmi_power_on_full()
217 hdmi_wp_set_phy_pwr(&hdmi->wp, HDMI_PHYPWRCMD_OFF); in hdmi_power_on_full()
221 dss_pll_disable(&hdmi->pll.pll); in hdmi_power_on_full()
223 hdmi_power_off_core(hdmi); in hdmi_power_on_full()
224 return -EIO; in hdmi_power_on_full()
227 static void hdmi_power_off_full(struct omap_hdmi *hdmi) in hdmi_power_off_full() argument
229 hdmi_wp_clear_irqenable(&hdmi->wp, ~HDMI_IRQ_CORE); in hdmi_power_off_full()
231 hdmi_wp_video_stop(&hdmi->wp); in hdmi_power_off_full()
233 dss_mgr_disable(&hdmi->output); in hdmi_power_off_full()
235 hdmi_wp_set_phy_pwr(&hdmi->wp, HDMI_PHYPWRCMD_OFF); in hdmi_power_off_full()
237 dss_pll_disable(&hdmi->pll.pll); in hdmi_power_off_full()
239 hdmi_power_off_core(hdmi); in hdmi_power_off_full()
244 struct omap_hdmi *hdmi = s->private; in hdmi_dump_regs() local
246 mutex_lock(&hdmi->lock); in hdmi_dump_regs()
248 if (hdmi_runtime_get(hdmi)) { in hdmi_dump_regs()
249 mutex_unlock(&hdmi->lock); in hdmi_dump_regs()
253 hdmi_wp_dump(&hdmi->wp, s); in hdmi_dump_regs()
254 hdmi_pll_dump(&hdmi->pll, s); in hdmi_dump_regs()
255 hdmi_phy_dump(&hdmi->phy, s); in hdmi_dump_regs()
256 hdmi4_core_dump(&hdmi->core, s); in hdmi_dump_regs()
258 hdmi_runtime_put(hdmi); in hdmi_dump_regs()
259 mutex_unlock(&hdmi->lock); in hdmi_dump_regs()
265 hdmi_wp_audio_enable(&hd->wp, true); in hdmi_start_audio_stream()
266 hdmi4_audio_start(&hd->core, &hd->wp); in hdmi_start_audio_stream()
271 hdmi4_audio_stop(&hd->core, &hd->wp); in hdmi_stop_audio_stream()
272 hdmi_wp_audio_enable(&hd->wp, false); in hdmi_stop_audio_stream()
277 struct omap_hdmi *hdmi = container_of(core, struct omap_hdmi, core); in hdmi4_core_enable() local
282 mutex_lock(&hdmi->lock); in hdmi4_core_enable()
284 r = hdmi_power_on_core(hdmi); in hdmi4_core_enable()
290 mutex_unlock(&hdmi->lock); in hdmi4_core_enable()
294 mutex_unlock(&hdmi->lock); in hdmi4_core_enable()
300 struct omap_hdmi *hdmi = container_of(core, struct omap_hdmi, core); in hdmi4_core_disable() local
304 mutex_lock(&hdmi->lock); in hdmi4_core_disable()
306 hdmi_power_off_core(hdmi); in hdmi4_core_disable()
308 mutex_unlock(&hdmi->lock); in hdmi4_core_disable()
311 /* -----------------------------------------------------------------------------
312 * DRM Bridge Operations
315 static int hdmi4_bridge_attach(struct drm_bridge *bridge, in hdmi4_bridge_attach() argument
318 struct omap_hdmi *hdmi = drm_bridge_to_hdmi(bridge); in hdmi4_bridge_attach() local
321 return -EINVAL; in hdmi4_bridge_attach()
323 return drm_bridge_attach(bridge->encoder, hdmi->output.next_bridge, in hdmi4_bridge_attach()
324 bridge, flags); in hdmi4_bridge_attach()
327 static void hdmi4_bridge_mode_set(struct drm_bridge *bridge, in hdmi4_bridge_mode_set() argument
331 struct omap_hdmi *hdmi = drm_bridge_to_hdmi(bridge); in hdmi4_bridge_mode_set() local
333 mutex_lock(&hdmi->lock); in hdmi4_bridge_mode_set()
335 drm_display_mode_to_videomode(adjusted_mode, &hdmi->cfg.vm); in hdmi4_bridge_mode_set()
337 dispc_set_tv_pclk(hdmi->dss->dispc, adjusted_mode->clock * 1000); in hdmi4_bridge_mode_set()
339 mutex_unlock(&hdmi->lock); in hdmi4_bridge_mode_set()
342 static void hdmi4_bridge_enable(struct drm_bridge *bridge, in hdmi4_bridge_enable() argument
345 struct omap_hdmi *hdmi = drm_bridge_to_hdmi(bridge); in hdmi4_bridge_enable() local
346 struct drm_atomic_state *state = bridge_state->base.state; in hdmi4_bridge_enable()
354 * None of these should fail, as the bridge can't be enabled without a in hdmi4_bridge_enable()
358 bridge->encoder); in hdmi4_bridge_enable()
364 crtc_state = drm_atomic_get_new_crtc_state(state, conn_state->crtc); in hdmi4_bridge_enable()
368 hdmi->cfg.hdmi_dvi_mode = connector->display_info.is_hdmi in hdmi4_bridge_enable()
371 if (connector->display_info.is_hdmi) { in hdmi4_bridge_enable()
375 mode = &crtc_state->adjusted_mode; in hdmi4_bridge_enable()
379 hdmi->cfg.infoframe = avi; in hdmi4_bridge_enable()
382 mutex_lock(&hdmi->lock); in hdmi4_bridge_enable()
384 ret = hdmi_power_on_full(hdmi); in hdmi4_bridge_enable()
390 if (hdmi->audio_configured) { in hdmi4_bridge_enable()
391 ret = hdmi4_audio_config(&hdmi->core, &hdmi->wp, in hdmi4_bridge_enable()
392 &hdmi->audio_config, in hdmi4_bridge_enable()
393 hdmi->cfg.vm.pixelclock); in hdmi4_bridge_enable()
396 hdmi->audio_abort_cb(&hdmi->pdev->dev); in hdmi4_bridge_enable()
397 hdmi->audio_configured = false; in hdmi4_bridge_enable()
401 spin_lock_irqsave(&hdmi->audio_playing_lock, flags); in hdmi4_bridge_enable()
402 if (hdmi->audio_configured && hdmi->audio_playing) in hdmi4_bridge_enable()
403 hdmi_start_audio_stream(hdmi); in hdmi4_bridge_enable()
404 hdmi->display_enabled = true; in hdmi4_bridge_enable()
405 spin_unlock_irqrestore(&hdmi->audio_playing_lock, flags); in hdmi4_bridge_enable()
408 mutex_unlock(&hdmi->lock); in hdmi4_bridge_enable()
411 static void hdmi4_bridge_disable(struct drm_bridge *bridge, in hdmi4_bridge_disable() argument
414 struct omap_hdmi *hdmi = drm_bridge_to_hdmi(bridge); in hdmi4_bridge_disable() local
417 mutex_lock(&hdmi->lock); in hdmi4_bridge_disable()
419 spin_lock_irqsave(&hdmi->audio_playing_lock, flags); in hdmi4_bridge_disable()
420 hdmi_stop_audio_stream(hdmi); in hdmi4_bridge_disable()
421 hdmi->display_enabled = false; in hdmi4_bridge_disable()
422 spin_unlock_irqrestore(&hdmi->audio_playing_lock, flags); in hdmi4_bridge_disable()
424 hdmi_power_off_full(hdmi); in hdmi4_bridge_disable()
426 mutex_unlock(&hdmi->lock); in hdmi4_bridge_disable()
429 static void hdmi4_bridge_hpd_notify(struct drm_bridge *bridge, in hdmi4_bridge_hpd_notify() argument
432 struct omap_hdmi *hdmi = drm_bridge_to_hdmi(bridge); in hdmi4_bridge_hpd_notify() local
435 hdmi4_cec_set_phys_addr(&hdmi->core, CEC_PHYS_ADDR_INVALID); in hdmi4_bridge_hpd_notify()
438 static struct edid *hdmi4_bridge_get_edid(struct drm_bridge *bridge, in hdmi4_bridge_get_edid() argument
441 struct omap_hdmi *hdmi = drm_bridge_to_hdmi(bridge); in hdmi4_bridge_get_edid() local
447 need_enable = hdmi->core_enabled == false; in hdmi4_bridge_get_edid()
450 r = hdmi4_core_enable(&hdmi->core); in hdmi4_bridge_get_edid()
455 mutex_lock(&hdmi->lock); in hdmi4_bridge_get_edid()
456 r = hdmi_runtime_get(hdmi); in hdmi4_bridge_get_edid()
459 r = hdmi4_core_ddc_init(&hdmi->core); in hdmi4_bridge_get_edid()
463 edid = drm_do_get_edid(connector, hdmi4_core_ddc_read, &hdmi->core); in hdmi4_bridge_get_edid()
466 hdmi_runtime_put(hdmi); in hdmi4_bridge_get_edid()
467 mutex_unlock(&hdmi->lock); in hdmi4_bridge_get_edid()
469 if (edid && edid->extensions) { in hdmi4_bridge_get_edid()
470 unsigned int len = (edid->extensions + 1) * EDID_LENGTH; in hdmi4_bridge_get_edid()
477 hdmi4_cec_set_phys_addr(&hdmi->core, cec_addr); in hdmi4_bridge_get_edid()
480 hdmi4_core_disable(&hdmi->core); in hdmi4_bridge_get_edid()
497 static void hdmi4_bridge_init(struct omap_hdmi *hdmi) in hdmi4_bridge_init() argument
499 hdmi->bridge.funcs = &hdmi4_bridge_funcs; in hdmi4_bridge_init()
500 hdmi->bridge.of_node = hdmi->pdev->dev.of_node; in hdmi4_bridge_init()
501 hdmi->bridge.ops = DRM_BRIDGE_OP_EDID; in hdmi4_bridge_init()
502 hdmi->bridge.type = DRM_MODE_CONNECTOR_HDMIA; in hdmi4_bridge_init()
504 drm_bridge_add(&hdmi->bridge); in hdmi4_bridge_init()
507 static void hdmi4_bridge_cleanup(struct omap_hdmi *hdmi) in hdmi4_bridge_cleanup() argument
509 drm_bridge_remove(&hdmi->bridge); in hdmi4_bridge_cleanup()
512 /* -----------------------------------------------------------------------------
521 mutex_lock(&hd->lock); in hdmi_audio_startup()
523 WARN_ON(hd->audio_abort_cb != NULL); in hdmi_audio_startup()
525 hd->audio_abort_cb = abort_cb; in hdmi_audio_startup()
527 mutex_unlock(&hd->lock); in hdmi_audio_startup()
536 mutex_lock(&hd->lock); in hdmi_audio_shutdown()
537 hd->audio_abort_cb = NULL; in hdmi_audio_shutdown()
538 hd->audio_configured = false; in hdmi_audio_shutdown()
539 hd->audio_playing = false; in hdmi_audio_shutdown()
540 mutex_unlock(&hd->lock); in hdmi_audio_shutdown()
550 spin_lock_irqsave(&hd->audio_playing_lock, flags); in hdmi_audio_start()
552 if (hd->display_enabled) { in hdmi_audio_start()
553 if (!hdmi_mode_has_audio(&hd->cfg)) in hdmi_audio_start()
558 hd->audio_playing = true; in hdmi_audio_start()
560 spin_unlock_irqrestore(&hd->audio_playing_lock, flags); in hdmi_audio_start()
569 WARN_ON(!hdmi_mode_has_audio(&hd->cfg)); in hdmi_audio_stop()
571 spin_lock_irqsave(&hd->audio_playing_lock, flags); in hdmi_audio_stop()
573 if (hd->display_enabled) in hdmi_audio_stop()
575 hd->audio_playing = false; in hdmi_audio_stop()
577 spin_unlock_irqrestore(&hd->audio_playing_lock, flags); in hdmi_audio_stop()
586 mutex_lock(&hd->lock); in hdmi_audio_config()
588 if (hd->display_enabled) { in hdmi_audio_config()
589 ret = hdmi4_audio_config(&hd->core, &hd->wp, dss_audio, in hdmi_audio_config()
590 hd->cfg.vm.pixelclock); in hdmi_audio_config()
595 hd->audio_configured = true; in hdmi_audio_config()
596 hd->audio_config = *dss_audio; in hdmi_audio_config()
598 mutex_unlock(&hd->lock); in hdmi_audio_config()
611 static int hdmi_audio_register(struct omap_hdmi *hdmi) in hdmi_audio_register() argument
614 .dev = &hdmi->pdev->dev, in hdmi_audio_register()
616 .audio_dma_addr = hdmi_wp_get_audio_dma_addr(&hdmi->wp), in hdmi_audio_register()
620 hdmi->audio_pdev = platform_device_register_data( in hdmi_audio_register()
621 &hdmi->pdev->dev, "omap-hdmi-audio", PLATFORM_DEVID_AUTO, in hdmi_audio_register()
624 if (IS_ERR(hdmi->audio_pdev)) in hdmi_audio_register()
625 return PTR_ERR(hdmi->audio_pdev); in hdmi_audio_register()
630 /* -----------------------------------------------------------------------------
637 struct omap_hdmi *hdmi = dev_get_drvdata(dev); in hdmi4_bind() local
640 hdmi->dss = dss; in hdmi4_bind()
642 r = hdmi_runtime_get(hdmi); in hdmi4_bind()
646 r = hdmi_pll_init(dss, hdmi->pdev, &hdmi->pll, &hdmi->wp); in hdmi4_bind()
650 r = hdmi4_cec_init(hdmi->pdev, &hdmi->core, &hdmi->wp); in hdmi4_bind()
654 r = hdmi_audio_register(hdmi); in hdmi4_bind()
656 DSSERR("Registering HDMI audio failed\n"); in hdmi4_bind()
660 hdmi->debugfs = dss_debugfs_create_file(dss, "hdmi", hdmi_dump_regs, in hdmi4_bind()
661 hdmi); in hdmi4_bind()
663 hdmi_runtime_put(hdmi); in hdmi4_bind()
668 hdmi4_cec_uninit(&hdmi->core); in hdmi4_bind()
670 hdmi_pll_uninit(&hdmi->pll); in hdmi4_bind()
672 hdmi_runtime_put(hdmi); in hdmi4_bind()
678 struct omap_hdmi *hdmi = dev_get_drvdata(dev); in hdmi4_unbind() local
680 dss_debugfs_remove_file(hdmi->debugfs); in hdmi4_unbind()
682 if (hdmi->audio_pdev) in hdmi4_unbind()
683 platform_device_unregister(hdmi->audio_pdev); in hdmi4_unbind()
685 hdmi4_cec_uninit(&hdmi->core); in hdmi4_unbind()
686 hdmi_pll_uninit(&hdmi->pll); in hdmi4_unbind()
694 /* -----------------------------------------------------------------------------
698 static int hdmi4_init_output(struct omap_hdmi *hdmi) in hdmi4_init_output() argument
700 struct omap_dss_device *out = &hdmi->output; in hdmi4_init_output()
703 hdmi4_bridge_init(hdmi); in hdmi4_init_output()
705 out->dev = &hdmi->pdev->dev; in hdmi4_init_output()
706 out->id = OMAP_DSS_OUTPUT_HDMI; in hdmi4_init_output()
707 out->type = OMAP_DISPLAY_TYPE_HDMI; in hdmi4_init_output()
708 out->name = "hdmi.0"; in hdmi4_init_output()
709 out->dispc_channel = OMAP_DSS_CHANNEL_DIGIT; in hdmi4_init_output()
710 out->owner = THIS_MODULE; in hdmi4_init_output()
711 out->of_port = 0; in hdmi4_init_output()
713 r = omapdss_device_init_output(out, &hdmi->bridge); in hdmi4_init_output()
715 hdmi4_bridge_cleanup(hdmi); in hdmi4_init_output()
724 static void hdmi4_uninit_output(struct omap_hdmi *hdmi) in hdmi4_uninit_output() argument
726 struct omap_dss_device *out = &hdmi->output; in hdmi4_uninit_output()
731 hdmi4_bridge_cleanup(hdmi); in hdmi4_uninit_output()
734 static int hdmi4_probe_of(struct omap_hdmi *hdmi) in hdmi4_probe_of() argument
736 struct platform_device *pdev = hdmi->pdev; in hdmi4_probe_of()
737 struct device_node *node = pdev->dev.of_node; in hdmi4_probe_of()
745 r = hdmi_parse_lanes_of(pdev, ep, &hdmi->phy); in hdmi4_probe_of()
752 struct omap_hdmi *hdmi; in hdmi4_probe() local
756 hdmi = kzalloc(sizeof(*hdmi), GFP_KERNEL); in hdmi4_probe()
757 if (!hdmi) in hdmi4_probe()
758 return -ENOMEM; in hdmi4_probe()
760 hdmi->pdev = pdev; in hdmi4_probe()
762 dev_set_drvdata(&pdev->dev, hdmi); in hdmi4_probe()
764 mutex_init(&hdmi->lock); in hdmi4_probe()
765 spin_lock_init(&hdmi->audio_playing_lock); in hdmi4_probe()
767 r = hdmi4_probe_of(hdmi); in hdmi4_probe()
771 r = hdmi_wp_init(pdev, &hdmi->wp, 4); in hdmi4_probe()
775 r = hdmi_phy_init(pdev, &hdmi->phy, 4); in hdmi4_probe()
779 r = hdmi4_core_init(pdev, &hdmi->core); in hdmi4_probe()
786 r = -ENODEV; in hdmi4_probe()
790 r = devm_request_threaded_irq(&pdev->dev, irq, in hdmi4_probe()
792 IRQF_ONESHOT, "OMAP HDMI", hdmi); in hdmi4_probe()
794 DSSERR("HDMI IRQ request failed\n"); in hdmi4_probe()
798 hdmi->vdda_reg = devm_regulator_get(&pdev->dev, "vdda"); in hdmi4_probe()
799 if (IS_ERR(hdmi->vdda_reg)) { in hdmi4_probe()
800 r = PTR_ERR(hdmi->vdda_reg); in hdmi4_probe()
801 if (r != -EPROBE_DEFER) in hdmi4_probe()
806 pm_runtime_enable(&pdev->dev); in hdmi4_probe()
808 r = hdmi4_init_output(hdmi); in hdmi4_probe()
812 r = component_add(&pdev->dev, &hdmi4_component_ops); in hdmi4_probe()
819 hdmi4_uninit_output(hdmi); in hdmi4_probe()
821 pm_runtime_disable(&pdev->dev); in hdmi4_probe()
823 kfree(hdmi); in hdmi4_probe()
829 struct omap_hdmi *hdmi = platform_get_drvdata(pdev); in hdmi4_remove() local
831 component_del(&pdev->dev, &hdmi4_component_ops); in hdmi4_remove()
833 hdmi4_uninit_output(hdmi); in hdmi4_remove()
835 pm_runtime_disable(&pdev->dev); in hdmi4_remove()
837 kfree(hdmi); in hdmi4_remove()
842 { .compatible = "ti,omap4-hdmi", },