Lines Matching +full:hdmi +full:- +full:phy
1 // SPDX-License-Identifier: GPL-2.0-or-later
32 #define DRIVER_NAME "meson-dw-hdmi"
33 #define DRIVER_DESC "Amlogic Meson HDMI-TX DRM driver"
36 * DOC: HDMI Output
38 * HDMI Output is composed of :
40 * - A Synopsys DesignWare HDMI Controller IP
41 * - A TOP control block controlling the Clocks and PHY
42 * - A custom HDMI PHY in order convert video to TMDS signal
47 * | HDMI TOP |<= HPD
50 * | Synopsys HDMI | HDMI PHY |=> TMDS
55 * The HDMI TOP block only supports HPD sensing.
56 * The Synopsys HDMI Controller interrupt is routed
59 * HDMI Controller is done a pair of addr+read/write
61 * The HDMI PHY is configured by registers in the
65 * block and the VPU HDMI mux selects either the ENCI
71 * HDMI controller.
74 * HDMI TX IP version 2.01a with HDCP and I2C & S/PDIF
79 * - HPD Rise & Fall interrupt
80 * - HDMI Controller Interrupt
81 * - HDMI PHY Init for 480i to 1080p60
82 * - VENC & HDMI Clock setup for 480i to 1080p60
83 * - VENC Mode setup for 480i to 1080p60
87 * - PHY, Clock and Mode setup for 2k && 4k modes
88 * - SDDC Scrambling mode for HDMI 2.0a
89 * - HDCP Setup
90 * - CEC Management
149 struct dw_hdmi *hdmi; member
156 return of_device_is_compatible(dw_hdmi->dev->of_node, compat); in dw_hdmi_is_compatible()
159 /* PHY (via TOP bridge) and Controller dedicated register interface */
170 writel(addr & 0xffff, dw_hdmi->hdmitx + HDMITX_TOP_ADDR_REG); in dw_hdmi_top_read()
171 writel(addr & 0xffff, dw_hdmi->hdmitx + HDMITX_TOP_ADDR_REG); in dw_hdmi_top_read()
174 data = readl(dw_hdmi->hdmitx + HDMITX_TOP_DATA_REG); in dw_hdmi_top_read()
175 data = readl(dw_hdmi->hdmitx + HDMITX_TOP_DATA_REG); in dw_hdmi_top_read()
185 return readl(dw_hdmi->hdmitx + HDMITX_TOP_G12A_OFFSET + (addr << 2)); in dw_hdmi_g12a_top_read()
196 writel(addr & 0xffff, dw_hdmi->hdmitx + HDMITX_TOP_ADDR_REG); in dw_hdmi_top_write()
197 writel(addr & 0xffff, dw_hdmi->hdmitx + HDMITX_TOP_ADDR_REG); in dw_hdmi_top_write()
200 writel(data, dw_hdmi->hdmitx + HDMITX_TOP_DATA_REG); in dw_hdmi_top_write()
208 writel(data, dw_hdmi->hdmitx + HDMITX_TOP_G12A_OFFSET + (addr << 2)); in dw_hdmi_g12a_top_write()
211 /* Helper to change specific bits in PHY registers */
217 unsigned int data = dw_hdmi->data->top_read(dw_hdmi, addr); in dw_hdmi_top_write_bits()
222 dw_hdmi->data->top_write(dw_hdmi, addr, data); in dw_hdmi_top_write_bits()
234 writel(addr & 0xffff, dw_hdmi->hdmitx + HDMITX_DWC_ADDR_REG); in dw_hdmi_dwc_read()
235 writel(addr & 0xffff, dw_hdmi->hdmitx + HDMITX_DWC_ADDR_REG); in dw_hdmi_dwc_read()
238 data = readl(dw_hdmi->hdmitx + HDMITX_DWC_DATA_REG); in dw_hdmi_dwc_read()
239 data = readl(dw_hdmi->hdmitx + HDMITX_DWC_DATA_REG); in dw_hdmi_dwc_read()
249 return readb(dw_hdmi->hdmitx + addr); in dw_hdmi_g12a_dwc_read()
260 writel(addr & 0xffff, dw_hdmi->hdmitx + HDMITX_DWC_ADDR_REG); in dw_hdmi_dwc_write()
261 writel(addr & 0xffff, dw_hdmi->hdmitx + HDMITX_DWC_ADDR_REG); in dw_hdmi_dwc_write()
264 writel(data, dw_hdmi->hdmitx + HDMITX_DWC_DATA_REG); in dw_hdmi_dwc_write()
272 writeb(data, dw_hdmi->hdmitx + addr); in dw_hdmi_g12a_dwc_write()
277 /* Setup PHY bandwidth modes */
282 struct meson_drm *priv = dw_hdmi->priv; in meson_hdmi_phy_setup_mode()
283 unsigned int pixel_clock = mode->clock; in meson_hdmi_phy_setup_mode()
288 if (dw_hdmi_is_compatible(dw_hdmi, "amlogic,meson-gxl-dw-hdmi") || in meson_hdmi_phy_setup_mode()
289 dw_hdmi_is_compatible(dw_hdmi, "amlogic,meson-gxm-dw-hdmi")) { in meson_hdmi_phy_setup_mode()
292 regmap_write(priv->hhi, HHI_HDMI_PHY_CNTL0, 0x333d3282); in meson_hdmi_phy_setup_mode()
293 regmap_write(priv->hhi, HHI_HDMI_PHY_CNTL3, 0x2136315b); in meson_hdmi_phy_setup_mode()
296 regmap_write(priv->hhi, HHI_HDMI_PHY_CNTL0, 0x33303382); in meson_hdmi_phy_setup_mode()
297 regmap_write(priv->hhi, HHI_HDMI_PHY_CNTL3, 0x2036315b); in meson_hdmi_phy_setup_mode()
300 regmap_write(priv->hhi, HHI_HDMI_PHY_CNTL0, 0x33303362); in meson_hdmi_phy_setup_mode()
301 regmap_write(priv->hhi, HHI_HDMI_PHY_CNTL3, 0x2016315b); in meson_hdmi_phy_setup_mode()
304 regmap_write(priv->hhi, HHI_HDMI_PHY_CNTL0, 0x33604142); in meson_hdmi_phy_setup_mode()
305 regmap_write(priv->hhi, HHI_HDMI_PHY_CNTL3, 0x0016315b); in meson_hdmi_phy_setup_mode()
308 "amlogic,meson-gxbb-dw-hdmi")) { in meson_hdmi_phy_setup_mode()
311 regmap_write(priv->hhi, HHI_HDMI_PHY_CNTL0, 0x33353245); in meson_hdmi_phy_setup_mode()
312 regmap_write(priv->hhi, HHI_HDMI_PHY_CNTL3, 0x2100115b); in meson_hdmi_phy_setup_mode()
315 regmap_write(priv->hhi, HHI_HDMI_PHY_CNTL0, 0x33634283); in meson_hdmi_phy_setup_mode()
316 regmap_write(priv->hhi, HHI_HDMI_PHY_CNTL3, 0xb000115b); in meson_hdmi_phy_setup_mode()
319 regmap_write(priv->hhi, HHI_HDMI_PHY_CNTL0, 0x33632122); in meson_hdmi_phy_setup_mode()
320 regmap_write(priv->hhi, HHI_HDMI_PHY_CNTL3, 0x2000115b); in meson_hdmi_phy_setup_mode()
323 "amlogic,meson-g12a-dw-hdmi")) { in meson_hdmi_phy_setup_mode()
326 regmap_write(priv->hhi, HHI_HDMI_PHY_CNTL0, 0x37eb65c4); in meson_hdmi_phy_setup_mode()
327 regmap_write(priv->hhi, HHI_HDMI_PHY_CNTL3, 0x2ab0ff3b); in meson_hdmi_phy_setup_mode()
328 regmap_write(priv->hhi, HHI_HDMI_PHY_CNTL5, 0x0000080b); in meson_hdmi_phy_setup_mode()
331 regmap_write(priv->hhi, HHI_HDMI_PHY_CNTL0, 0x33eb6262); in meson_hdmi_phy_setup_mode()
332 regmap_write(priv->hhi, HHI_HDMI_PHY_CNTL3, 0x2ab0ff3b); in meson_hdmi_phy_setup_mode()
333 regmap_write(priv->hhi, HHI_HDMI_PHY_CNTL5, 0x00000003); in meson_hdmi_phy_setup_mode()
336 regmap_write(priv->hhi, HHI_HDMI_PHY_CNTL0, 0x33eb4242); in meson_hdmi_phy_setup_mode()
337 regmap_write(priv->hhi, HHI_HDMI_PHY_CNTL3, 0x2ab0ff3b); in meson_hdmi_phy_setup_mode()
338 regmap_write(priv->hhi, HHI_HDMI_PHY_CNTL5, 0x00000003); in meson_hdmi_phy_setup_mode()
345 struct meson_drm *priv = dw_hdmi->priv; in meson_dw_hdmi_phy_reset()
348 regmap_update_bits(priv->hhi, HHI_HDMI_PHY_CNTL1, 0xf, 0xf); in meson_dw_hdmi_phy_reset()
353 regmap_update_bits(priv->hhi, HHI_HDMI_PHY_CNTL1, 0xf, 0xe); in meson_dw_hdmi_phy_reset()
358 static int dw_hdmi_phy_init(struct dw_hdmi *hdmi, void *data, in dw_hdmi_phy_init() argument
363 bool is_hdmi2_sink = display->hdmi.scdc.supported; in dw_hdmi_phy_init()
364 struct meson_drm *priv = dw_hdmi->priv; in dw_hdmi_phy_init()
366 readl_relaxed(priv->io_base + _REG(VPU_HDMI_SETTING)); in dw_hdmi_phy_init()
369 DRM_DEBUG_DRIVER("\"%s\" div%d\n", mode->name, in dw_hdmi_phy_init()
370 mode->clock > 340000 ? 40 : 10); in dw_hdmi_phy_init()
374 dw_hdmi_bus_fmt_is_420(hdmi)) in dw_hdmi_phy_init()
378 if (mode->clock > 340000 && !mode_is_420) { in dw_hdmi_phy_init()
379 dw_hdmi->data->top_write(dw_hdmi, HDMITX_TOP_TMDS_CLK_PTTN_01, in dw_hdmi_phy_init()
381 dw_hdmi->data->top_write(dw_hdmi, HDMITX_TOP_TMDS_CLK_PTTN_23, in dw_hdmi_phy_init()
384 dw_hdmi->data->top_write(dw_hdmi, HDMITX_TOP_TMDS_CLK_PTTN_01, in dw_hdmi_phy_init()
386 dw_hdmi->data->top_write(dw_hdmi, HDMITX_TOP_TMDS_CLK_PTTN_23, in dw_hdmi_phy_init()
391 dw_hdmi->data->top_write(dw_hdmi, HDMITX_TOP_TMDS_CLK_PTTN_CNTL, 0x1); in dw_hdmi_phy_init()
393 dw_hdmi->data->top_write(dw_hdmi, HDMITX_TOP_TMDS_CLK_PTTN_CNTL, 0x2); in dw_hdmi_phy_init()
395 /* Setup PHY parameters */ in dw_hdmi_phy_init()
399 regmap_update_bits(priv->hhi, HHI_HDMI_PHY_CNTL1, 0xf, 0); in dw_hdmi_phy_init()
401 dw_hdmi_set_high_tmds_clock_ratio(hdmi, display); in dw_hdmi_phy_init()
405 /* Reset PHY 3 times in a row */ in dw_hdmi_phy_init()
411 if (priv->venc.hdmi_use_enci) in dw_hdmi_phy_init()
412 writel_relaxed(0, priv->io_base + _REG(ENCI_VIDEO_EN)); in dw_hdmi_phy_init()
414 writel_relaxed(0, priv->io_base + _REG(ENCP_VIDEO_EN)); in dw_hdmi_phy_init()
416 /* Temporary Disable HDMI video stream to HDMI-TX */ in dw_hdmi_phy_init()
418 priv->io_base + _REG(VPU_HDMI_SETTING)); in dw_hdmi_phy_init()
420 priv->io_base + _REG(VPU_HDMI_SETTING)); in dw_hdmi_phy_init()
422 /* Re-Enable VENC video stream */ in dw_hdmi_phy_init()
423 if (priv->venc.hdmi_use_enci) in dw_hdmi_phy_init()
424 writel_relaxed(1, priv->io_base + _REG(ENCI_VIDEO_EN)); in dw_hdmi_phy_init()
426 writel_relaxed(1, priv->io_base + _REG(ENCP_VIDEO_EN)); in dw_hdmi_phy_init()
428 /* Push back HDMI clock settings */ in dw_hdmi_phy_init()
430 priv->io_base + _REG(VPU_HDMI_SETTING)); in dw_hdmi_phy_init()
432 /* Enable and Select HDMI video source for HDMI-TX */ in dw_hdmi_phy_init()
433 if (priv->venc.hdmi_use_enci) in dw_hdmi_phy_init()
435 priv->io_base + _REG(VPU_HDMI_SETTING)); in dw_hdmi_phy_init()
438 priv->io_base + _REG(VPU_HDMI_SETTING)); in dw_hdmi_phy_init()
443 static void dw_hdmi_phy_disable(struct dw_hdmi *hdmi, in dw_hdmi_phy_disable() argument
447 struct meson_drm *priv = dw_hdmi->priv; in dw_hdmi_phy_disable()
452 regmap_write(priv->hhi, HHI_HDMI_PHY_CNTL1, dw_hdmi->data->cntl1_init); in dw_hdmi_phy_disable()
453 regmap_write(priv->hhi, HHI_HDMI_PHY_CNTL0, dw_hdmi->data->cntl0_init); in dw_hdmi_phy_disable()
456 static enum drm_connector_status dw_hdmi_read_hpd(struct dw_hdmi *hdmi, in dw_hdmi_read_hpd() argument
461 return !!dw_hdmi->data->top_read(dw_hdmi, HDMITX_TOP_STAT0) ? in dw_hdmi_read_hpd()
465 static void dw_hdmi_setup_hpd(struct dw_hdmi *hdmi, in dw_hdmi_setup_hpd() argument
471 dw_hdmi->data->top_write(dw_hdmi, HDMITX_TOP_HPD_FILTER, in dw_hdmi_setup_hpd()
475 dw_hdmi->data->top_write(dw_hdmi, HDMITX_TOP_INTR_STAT_CLR, in dw_hdmi_setup_hpd()
496 stat = dw_hdmi->data->top_read(dw_hdmi, HDMITX_TOP_INTR_STAT); in dw_hdmi_top_irq()
497 dw_hdmi->data->top_write(dw_hdmi, HDMITX_TOP_INTR_STAT_CLR, stat); in dw_hdmi_top_irq()
501 dw_hdmi->irq_stat = stat; in dw_hdmi_top_irq()
505 /* HDMI Controller Interrupt */ in dw_hdmi_top_irq()
518 u32 stat = dw_hdmi->irq_stat; in dw_hdmi_top_thread_irq()
527 dw_hdmi_setup_rx_sense(dw_hdmi->hdmi, hpd_connected, in dw_hdmi_top_thread_irq()
530 drm_helper_hpd_irq_event(dw_hdmi->bridge->dev); in dw_hdmi_top_thread_irq()
531 drm_bridge_hpd_notify(dw_hdmi->bridge, in dw_hdmi_top_thread_irq()
539 /* DW HDMI Regmap */
546 *result = dw_hdmi->data->dwc_read(dw_hdmi, reg); in meson_dw_hdmi_reg_read()
557 dw_hdmi->data->dwc_write(dw_hdmi, reg, val); in meson_dw_hdmi_reg_write()
600 struct meson_drm *priv = meson_dw_hdmi->priv; in meson_dw_hdmi_init()
603 regmap_update_bits(priv->hhi, HHI_HDMI_CLK_CNTL, 0xffff, 0x100); in meson_dw_hdmi_init()
606 regmap_update_bits(priv->hhi, HHI_MEM_PD_REG0, 0xff << 8, 0); in meson_dw_hdmi_init()
608 /* Reset HDMITX APB & TX & PHY */ in meson_dw_hdmi_init()
609 reset_control_reset(meson_dw_hdmi->hdmitx_apb); in meson_dw_hdmi_init()
610 reset_control_reset(meson_dw_hdmi->hdmitx_ctrl); in meson_dw_hdmi_init()
611 reset_control_reset(meson_dw_hdmi->hdmitx_phy); in meson_dw_hdmi_init()
616 meson_dw_hdmi->hdmitx + HDMITX_TOP_CTRL_REG); in meson_dw_hdmi_init()
618 meson_dw_hdmi->hdmitx + HDMITX_DWC_CTRL_REG); in meson_dw_hdmi_init()
622 meson_dw_hdmi->data->top_write(meson_dw_hdmi, in meson_dw_hdmi_init()
627 meson_dw_hdmi->data->top_write(meson_dw_hdmi, in meson_dw_hdmi_init()
630 /* Enable normal output to PHY */ in meson_dw_hdmi_init()
631 meson_dw_hdmi->data->top_write(meson_dw_hdmi, HDMITX_TOP_BIST_CNTL, BIT(12)); in meson_dw_hdmi_init()
633 /* Setup PHY */ in meson_dw_hdmi_init()
634 regmap_write(priv->hhi, HHI_HDMI_PHY_CNTL1, meson_dw_hdmi->data->cntl1_init); in meson_dw_hdmi_init()
635 regmap_write(priv->hhi, HHI_HDMI_PHY_CNTL0, meson_dw_hdmi->data->cntl0_init); in meson_dw_hdmi_init()
637 /* Enable HDMI-TX Interrupt */ in meson_dw_hdmi_init()
638 meson_dw_hdmi->data->top_write(meson_dw_hdmi, HDMITX_TOP_INTR_STAT_CLR, in meson_dw_hdmi_init()
641 meson_dw_hdmi->data->top_write(meson_dw_hdmi, HDMITX_TOP_INTR_MASKN, in meson_dw_hdmi_init()
676 struct meson_drm *priv = drm->dev_private; in meson_dw_hdmi_bind()
683 match = of_device_get_match_data(&pdev->dev); in meson_dw_hdmi_bind()
685 dev_err(&pdev->dev, "failed to get match data\n"); in meson_dw_hdmi_bind()
686 return -ENODEV; in meson_dw_hdmi_bind()
692 return -ENOMEM; in meson_dw_hdmi_bind()
694 meson_dw_hdmi->priv = priv; in meson_dw_hdmi_bind()
695 meson_dw_hdmi->dev = dev; in meson_dw_hdmi_bind()
696 meson_dw_hdmi->data = match; in meson_dw_hdmi_bind()
697 dw_plat_data = &meson_dw_hdmi->dw_plat_data; in meson_dw_hdmi_bind()
699 ret = devm_regulator_get_enable_optional(dev, "hdmi"); in meson_dw_hdmi_bind()
700 if (ret < 0 && ret != -ENODEV) in meson_dw_hdmi_bind()
703 meson_dw_hdmi->hdmitx_apb = devm_reset_control_get_exclusive(dev, in meson_dw_hdmi_bind()
705 if (IS_ERR(meson_dw_hdmi->hdmitx_apb)) { in meson_dw_hdmi_bind()
707 return PTR_ERR(meson_dw_hdmi->hdmitx_apb); in meson_dw_hdmi_bind()
710 meson_dw_hdmi->hdmitx_ctrl = devm_reset_control_get_exclusive(dev, in meson_dw_hdmi_bind()
712 if (IS_ERR(meson_dw_hdmi->hdmitx_ctrl)) { in meson_dw_hdmi_bind()
714 return PTR_ERR(meson_dw_hdmi->hdmitx_ctrl); in meson_dw_hdmi_bind()
717 meson_dw_hdmi->hdmitx_phy = devm_reset_control_get_exclusive(dev, in meson_dw_hdmi_bind()
719 if (IS_ERR(meson_dw_hdmi->hdmitx_phy)) { in meson_dw_hdmi_bind()
721 return PTR_ERR(meson_dw_hdmi->hdmitx_phy); in meson_dw_hdmi_bind()
724 meson_dw_hdmi->hdmitx = devm_platform_ioremap_resource(pdev, 0); in meson_dw_hdmi_bind()
725 if (IS_ERR(meson_dw_hdmi->hdmitx)) in meson_dw_hdmi_bind()
726 return PTR_ERR(meson_dw_hdmi->hdmitx); in meson_dw_hdmi_bind()
740 dw_plat_data->regm = devm_regmap_init(dev, NULL, meson_dw_hdmi, in meson_dw_hdmi_bind()
742 if (IS_ERR(dw_plat_data->regm)) in meson_dw_hdmi_bind()
743 return PTR_ERR(dw_plat_data->regm); in meson_dw_hdmi_bind()
753 dev_err(dev, "Failed to request hdmi top irq\n"); in meson_dw_hdmi_bind()
761 dw_plat_data->priv_data = meson_dw_hdmi; in meson_dw_hdmi_bind()
762 dw_plat_data->phy_ops = &meson_dw_hdmi_phy_ops; in meson_dw_hdmi_bind()
763 dw_plat_data->phy_name = "meson_dw_hdmi_phy"; in meson_dw_hdmi_bind()
764 dw_plat_data->phy_data = meson_dw_hdmi; in meson_dw_hdmi_bind()
765 dw_plat_data->input_bus_encoding = V4L2_YCBCR_ENC_709; in meson_dw_hdmi_bind()
766 dw_plat_data->ycbcr_420_allowed = true; in meson_dw_hdmi_bind()
767 dw_plat_data->disable_cec = true; in meson_dw_hdmi_bind()
768 dw_plat_data->output_port = 1; in meson_dw_hdmi_bind()
770 if (dw_hdmi_is_compatible(meson_dw_hdmi, "amlogic,meson-gxl-dw-hdmi") || in meson_dw_hdmi_bind()
771 dw_hdmi_is_compatible(meson_dw_hdmi, "amlogic,meson-gxm-dw-hdmi") || in meson_dw_hdmi_bind()
772 dw_hdmi_is_compatible(meson_dw_hdmi, "amlogic,meson-g12a-dw-hdmi")) in meson_dw_hdmi_bind()
773 dw_plat_data->use_drm_infoframe = true; in meson_dw_hdmi_bind()
777 meson_dw_hdmi->hdmi = dw_hdmi_probe(pdev, &meson_dw_hdmi->dw_plat_data); in meson_dw_hdmi_bind()
778 if (IS_ERR(meson_dw_hdmi->hdmi)) in meson_dw_hdmi_bind()
779 return PTR_ERR(meson_dw_hdmi->hdmi); in meson_dw_hdmi_bind()
781 meson_dw_hdmi->bridge = of_drm_find_bridge(pdev->dev.of_node); in meson_dw_hdmi_bind()
783 DRM_DEBUG_DRIVER("HDMI controller initialized\n"); in meson_dw_hdmi_bind()
793 dw_hdmi_unbind(meson_dw_hdmi->hdmi); in meson_dw_hdmi_unbind()
809 meson_dw_hdmi->data->top_write(meson_dw_hdmi, in meson_dw_hdmi_pm_suspend()
824 dw_hdmi_resume(meson_dw_hdmi->hdmi); in meson_dw_hdmi_pm_resume()
831 return component_add(&pdev->dev, &meson_dw_hdmi_ops); in meson_dw_hdmi_probe()
836 component_del(&pdev->dev, &meson_dw_hdmi_ops); in meson_dw_hdmi_remove()
845 { .compatible = "amlogic,meson-gxbb-dw-hdmi",
847 { .compatible = "amlogic,meson-gxl-dw-hdmi",
849 { .compatible = "amlogic,meson-gxm-dw-hdmi",
851 { .compatible = "amlogic,meson-g12a-dw-hdmi",