Lines Matching +full:tx +full:- +full:termination +full:- +full:fix

1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * DesignWare High-Definition Multimedia Interface (HDMI) driver
5 * Copyright (C) 2013-2015 Mentor Graphics Inc.
6 * Copyright (C) 2011-2013 Freescale Semiconductor, Inc.
19 #include <linux/dma-mapping.h>
22 #include <media/cec-notifier.h>
24 #include <uapi/linux/media-bus-format.h>
37 #include "dw-hdmi-audio.h"
38 #include "dw-hdmi-cec.h"
39 #include "dw-hdmi.h"
46 /* DW-HDMI Controller >= 0x200a are at least compliant with SCDC version 1 */
183 enum drm_connector_force force; /* mutex-protected force state */
221 regmap_write(hdmi->regm, offset << hdmi->reg_shift, val); in hdmi_writeb()
228 regmap_read(hdmi->regm, offset << hdmi->reg_shift, &val); in hdmi_readb()
235 if (hdmi->plugged_cb && hdmi->codec_dev) in handle_plugged_change()
236 hdmi->plugged_cb(hdmi->codec_dev, plugged); in handle_plugged_change()
244 mutex_lock(&hdmi->mutex); in dw_hdmi_set_plugged_cb()
245 hdmi->plugged_cb = fn; in dw_hdmi_set_plugged_cb()
246 hdmi->codec_dev = codec_dev; in dw_hdmi_set_plugged_cb()
247 plugged = hdmi->last_connector_result == connector_status_connected; in dw_hdmi_set_plugged_cb()
249 mutex_unlock(&hdmi->mutex); in dw_hdmi_set_plugged_cb()
257 regmap_update_bits(hdmi->regm, reg << hdmi->reg_shift, mask, data); in hdmi_modb()
298 if (!hdmi->unwedge_state) in dw_hdmi_i2c_unwedge()
301 dev_info(hdmi->dev, "Attempting to unwedge stuck i2c bus\n"); in dw_hdmi_i2c_unwedge()
335 pinctrl_select_state(hdmi->pinctrl, hdmi->unwedge_state); in dw_hdmi_i2c_unwedge()
337 pinctrl_select_state(hdmi->pinctrl, hdmi->default_state); in dw_hdmi_i2c_unwedge()
344 struct dw_hdmi_i2c *i2c = hdmi->i2c; in dw_hdmi_i2c_wait()
347 stat = wait_for_completion_timeout(&i2c->cmp, HZ / 10); in dw_hdmi_i2c_wait()
351 return -EAGAIN; in dw_hdmi_i2c_wait()
354 stat = wait_for_completion_timeout(&i2c->cmp, HZ / 10); in dw_hdmi_i2c_wait()
356 return -EAGAIN; in dw_hdmi_i2c_wait()
360 if (i2c->stat & HDMI_IH_I2CM_STAT0_ERROR) in dw_hdmi_i2c_wait()
361 return -EIO; in dw_hdmi_i2c_wait()
369 struct dw_hdmi_i2c *i2c = hdmi->i2c; in dw_hdmi_i2c_read()
372 if (!i2c->is_regaddr) { in dw_hdmi_i2c_read()
373 dev_dbg(hdmi->dev, "set read register address to 0\n"); in dw_hdmi_i2c_read()
374 i2c->slave_reg = 0x00; in dw_hdmi_i2c_read()
375 i2c->is_regaddr = true; in dw_hdmi_i2c_read()
378 while (length--) { in dw_hdmi_i2c_read()
379 reinit_completion(&i2c->cmp); in dw_hdmi_i2c_read()
381 hdmi_writeb(hdmi, i2c->slave_reg++, HDMI_I2CM_ADDRESS); in dw_hdmi_i2c_read()
382 if (i2c->is_segment) in dw_hdmi_i2c_read()
395 i2c->is_segment = false; in dw_hdmi_i2c_read()
403 struct dw_hdmi_i2c *i2c = hdmi->i2c; in dw_hdmi_i2c_write()
406 if (!i2c->is_regaddr) { in dw_hdmi_i2c_write()
408 i2c->slave_reg = buf[0]; in dw_hdmi_i2c_write()
409 length--; in dw_hdmi_i2c_write()
411 i2c->is_regaddr = true; in dw_hdmi_i2c_write()
414 while (length--) { in dw_hdmi_i2c_write()
415 reinit_completion(&i2c->cmp); in dw_hdmi_i2c_write()
418 hdmi_writeb(hdmi, i2c->slave_reg++, HDMI_I2CM_ADDRESS); in dw_hdmi_i2c_write()
434 struct dw_hdmi_i2c *i2c = hdmi->i2c; in dw_hdmi_i2c_xfer()
440 * The internal I2C controller does not support the multi-byte in dw_hdmi_i2c_xfer()
445 return -EOPNOTSUPP; in dw_hdmi_i2c_xfer()
447 dev_dbg(hdmi->dev, "xfer: num: %d, addr: %#x\n", num, addr); in dw_hdmi_i2c_xfer()
451 dev_dbg(hdmi->dev, in dw_hdmi_i2c_xfer()
454 return -EOPNOTSUPP; in dw_hdmi_i2c_xfer()
458 mutex_lock(&i2c->lock); in dw_hdmi_i2c_xfer()
467 i2c->is_regaddr = false; in dw_hdmi_i2c_xfer()
470 i2c->is_segment = false; in dw_hdmi_i2c_xfer()
473 dev_dbg(hdmi->dev, "xfer: num: %d/%d, len: %d, flags: %#x\n", in dw_hdmi_i2c_xfer()
476 i2c->is_segment = true; in dw_hdmi_i2c_xfer()
498 mutex_unlock(&i2c->lock); in dw_hdmi_i2c_xfer()
519 i2c = devm_kzalloc(hdmi->dev, sizeof(*i2c), GFP_KERNEL); in dw_hdmi_i2c_adapter()
521 return ERR_PTR(-ENOMEM); in dw_hdmi_i2c_adapter()
523 mutex_init(&i2c->lock); in dw_hdmi_i2c_adapter()
524 init_completion(&i2c->cmp); in dw_hdmi_i2c_adapter()
526 adap = &i2c->adap; in dw_hdmi_i2c_adapter()
527 adap->class = I2C_CLASS_DDC; in dw_hdmi_i2c_adapter()
528 adap->owner = THIS_MODULE; in dw_hdmi_i2c_adapter()
529 adap->dev.parent = hdmi->dev; in dw_hdmi_i2c_adapter()
530 adap->algo = &dw_hdmi_algorithm; in dw_hdmi_i2c_adapter()
531 strlcpy(adap->name, "DesignWare HDMI", sizeof(adap->name)); in dw_hdmi_i2c_adapter()
536 dev_warn(hdmi->dev, "cannot add %s I2C adapter\n", adap->name); in dw_hdmi_i2c_adapter()
537 devm_kfree(hdmi->dev, i2c); in dw_hdmi_i2c_adapter()
541 hdmi->i2c = i2c; in dw_hdmi_i2c_adapter()
543 dev_info(hdmi->dev, "registered %s I2C bus driver\n", adap->name); in dw_hdmi_i2c_adapter()
665 * can be up to 20 bits in total, so we need 64-bit math. Also in hdmi_set_clk_regenerator()
674 dev_dbg(hdmi->dev, "%s: fs=%uHz ftdms=%lu.%03luMHz N=%d cts=%d\n", in hdmi_set_clk_regenerator()
682 spin_lock_irq(&hdmi->audio_lock); in hdmi_set_clk_regenerator()
683 hdmi->audio_n = n; in hdmi_set_clk_regenerator()
684 hdmi->audio_cts = cts; in hdmi_set_clk_regenerator()
685 hdmi_set_cts_n(hdmi, cts, hdmi->audio_enable ? n : 0); in hdmi_set_clk_regenerator()
686 spin_unlock_irq(&hdmi->audio_lock); in hdmi_set_clk_regenerator()
691 mutex_lock(&hdmi->audio_mutex); in hdmi_init_clk_regenerator()
692 hdmi_set_clk_regenerator(hdmi, 74250000, hdmi->sample_rate); in hdmi_init_clk_regenerator()
693 mutex_unlock(&hdmi->audio_mutex); in hdmi_init_clk_regenerator()
698 mutex_lock(&hdmi->audio_mutex); in hdmi_clk_regenerator_update_pixel_clock()
699 hdmi_set_clk_regenerator(hdmi, hdmi->hdmi_data.video_mode.mtmdsclock, in hdmi_clk_regenerator_update_pixel_clock()
700 hdmi->sample_rate); in hdmi_clk_regenerator_update_pixel_clock()
701 mutex_unlock(&hdmi->audio_mutex); in hdmi_clk_regenerator_update_pixel_clock()
706 mutex_lock(&hdmi->audio_mutex); in dw_hdmi_set_sample_rate()
707 hdmi->sample_rate = rate; in dw_hdmi_set_sample_rate()
708 hdmi_set_clk_regenerator(hdmi, hdmi->hdmi_data.video_mode.mtmdsclock, in dw_hdmi_set_sample_rate()
709 hdmi->sample_rate); in dw_hdmi_set_sample_rate()
710 mutex_unlock(&hdmi->audio_mutex); in dw_hdmi_set_sample_rate()
718 mutex_lock(&hdmi->audio_mutex); in dw_hdmi_set_channel_count()
733 hdmi_modb(hdmi, (cnt - 1) << HDMI_FC_AUDICONF0_CC_OFFSET, in dw_hdmi_set_channel_count()
736 mutex_unlock(&hdmi->audio_mutex); in dw_hdmi_set_channel_count()
742 mutex_lock(&hdmi->audio_mutex); in dw_hdmi_set_channel_allocation()
746 mutex_unlock(&hdmi->audio_mutex); in dw_hdmi_set_channel_allocation()
753 hdmi->mc_clkdis &= ~HDMI_MC_CLKDIS_AUDCLK_DISABLE; in hdmi_enable_audio_clk()
755 hdmi->mc_clkdis |= HDMI_MC_CLKDIS_AUDCLK_DISABLE; in hdmi_enable_audio_clk()
756 hdmi_writeb(hdmi, hdmi->mc_clkdis, HDMI_MC_CLKDIS); in hdmi_enable_audio_clk()
761 hdmi_set_cts_n(hdmi, hdmi->audio_cts, hdmi->audio_n); in dw_hdmi_ahb_audio_enable()
766 hdmi_set_cts_n(hdmi, hdmi->audio_cts, 0); in dw_hdmi_ahb_audio_disable()
771 hdmi_set_cts_n(hdmi, hdmi->audio_cts, hdmi->audio_n); in dw_hdmi_i2s_audio_enable()
784 spin_lock_irqsave(&hdmi->audio_lock, flags); in dw_hdmi_audio_enable()
785 hdmi->audio_enable = true; in dw_hdmi_audio_enable()
786 if (hdmi->enable_audio) in dw_hdmi_audio_enable()
787 hdmi->enable_audio(hdmi); in dw_hdmi_audio_enable()
788 spin_unlock_irqrestore(&hdmi->audio_lock, flags); in dw_hdmi_audio_enable()
796 spin_lock_irqsave(&hdmi->audio_lock, flags); in dw_hdmi_audio_disable()
797 hdmi->audio_enable = false; in dw_hdmi_audio_disable()
798 if (hdmi->disable_audio) in dw_hdmi_audio_disable()
799 hdmi->disable_audio(hdmi); in dw_hdmi_audio_disable()
800 spin_unlock_irqrestore(&hdmi->audio_lock, flags); in dw_hdmi_audio_disable()
902 switch (hdmi->hdmi_data.enc_in_bus_format) { in hdmi_video_sample()
952 /* Enable TX stuffing: When DE is inactive, fix the output data to 0 */ in hdmi_video_sample()
967 struct hdmi_data_info *hdmi_data = &hdmi->hdmi_data; in is_color_space_conversion()
970 is_input_rgb = hdmi_bus_fmt_is_rgb(hdmi_data->enc_in_bus_format); in is_color_space_conversion()
971 is_output_rgb = hdmi_bus_fmt_is_rgb(hdmi_data->enc_out_bus_format); in is_color_space_conversion()
974 (is_input_rgb && is_output_rgb && hdmi_data->rgb_limited_range); in is_color_space_conversion()
979 if (!hdmi_bus_fmt_is_yuv422(hdmi->hdmi_data.enc_out_bus_format)) in is_color_space_decimation()
982 if (hdmi_bus_fmt_is_rgb(hdmi->hdmi_data.enc_in_bus_format) || in is_color_space_decimation()
983 hdmi_bus_fmt_is_yuv444(hdmi->hdmi_data.enc_in_bus_format)) in is_color_space_decimation()
991 if (!hdmi_bus_fmt_is_yuv422(hdmi->hdmi_data.enc_in_bus_format)) in is_color_space_interpolation()
994 if (hdmi_bus_fmt_is_rgb(hdmi->hdmi_data.enc_out_bus_format) || in is_color_space_interpolation()
995 hdmi_bus_fmt_is_yuv444(hdmi->hdmi_data.enc_out_bus_format)) in is_color_space_interpolation()
1015 is_input_rgb = hdmi_bus_fmt_is_rgb(hdmi->hdmi_data.enc_in_bus_format); in dw_hdmi_update_csc_coeffs()
1016 is_output_rgb = hdmi_bus_fmt_is_rgb(hdmi->hdmi_data.enc_out_bus_format); in dw_hdmi_update_csc_coeffs()
1019 if (hdmi->hdmi_data.enc_out_encoding == V4L2_YCBCR_ENC_601) in dw_hdmi_update_csc_coeffs()
1024 if (hdmi->hdmi_data.enc_out_encoding == V4L2_YCBCR_ENC_601) in dw_hdmi_update_csc_coeffs()
1030 hdmi->hdmi_data.rgb_limited_range) { in dw_hdmi_update_csc_coeffs()
1064 switch (hdmi_bus_fmt_color_depth(hdmi->hdmi_data.enc_out_bus_format)) { in hdmi_video_csc()
1100 struct hdmi_data_info *hdmi_data = &hdmi->hdmi_data; in hdmi_video_packetize()
1103 if (hdmi_bus_fmt_is_rgb(hdmi->hdmi_data.enc_out_bus_format) || in hdmi_video_packetize()
1104 hdmi_bus_fmt_is_yuv444(hdmi->hdmi_data.enc_out_bus_format) || in hdmi_video_packetize()
1105 hdmi_bus_fmt_is_yuv420(hdmi->hdmi_data.enc_out_bus_format)) { in hdmi_video_packetize()
1107 hdmi->hdmi_data.enc_out_bus_format)) { in hdmi_video_packetize()
1124 } else if (hdmi_bus_fmt_is_yuv422(hdmi->hdmi_data.enc_out_bus_format)) { in hdmi_video_packetize()
1126 hdmi->hdmi_data.enc_out_bus_format)) { in hdmi_video_packetize()
1149 ((hdmi_data->pix_repet_factor << in hdmi_video_packetize()
1158 if (hdmi_data->pix_repet_factor > 1) { in hdmi_video_packetize()
1204 /* -----------------------------------------------------------------------------
1220 if (msec-- == 0) in hdmi_phy_wait_i2c_done()
1249 if (hdmi->version < 0x200a) in dw_hdmi_support_scdc()
1253 if (!hdmi->ddc) in dw_hdmi_support_scdc()
1256 /* Disable if SCDC is not supported, or if an HF-VSDB block is absent */ in dw_hdmi_support_scdc()
1257 if (!display->hdmi.scdc.supported || in dw_hdmi_support_scdc()
1258 !display->hdmi.scdc.scrambling.supported) in dw_hdmi_support_scdc()
1265 if (!display->hdmi.scdc.scrambling.low_rates && in dw_hdmi_support_scdc()
1266 display->max_tmds_clock <= 340000) in dw_hdmi_support_scdc()
1274 * - The Source shall suspend transmission of the TMDS clock and data
1275 * - The Source shall write to the TMDS_Bit_Clock_Ratio bit to change it
1277 * - The Source shall allow a minimum of 1 ms and a maximum of 100 ms from
1288 unsigned long mtmdsclock = hdmi->hdmi_data.video_mode.mtmdsclock; in dw_hdmi_set_high_tmds_clock_ratio()
1290 /* Control for TMDS Bit Period/TMDS Clock-Period Ratio */ in dw_hdmi_set_high_tmds_clock_ratio()
1293 drm_scdc_set_high_tmds_clock_ratio(hdmi->ddc, 1); in dw_hdmi_set_high_tmds_clock_ratio()
1295 drm_scdc_set_high_tmds_clock_ratio(hdmi->ddc, 0); in dw_hdmi_set_high_tmds_clock_ratio()
1369 const struct dw_hdmi_phy_data *phy = hdmi->phy.data; in dw_hdmi_phy_power_off()
1373 if (phy->gen == 1) { in dw_hdmi_phy_power_off()
1394 dev_warn(hdmi->dev, "PHY failed to power down\n"); in dw_hdmi_phy_power_off()
1396 dev_dbg(hdmi->dev, "PHY powered down in %u iterations\n", i); in dw_hdmi_phy_power_off()
1403 const struct dw_hdmi_phy_data *phy = hdmi->phy.data; in dw_hdmi_phy_power_on()
1407 if (phy->gen == 1) { in dw_hdmi_phy_power_on()
1429 dev_err(hdmi->dev, "PHY PLL failed to lock\n"); in dw_hdmi_phy_power_on()
1430 return -ETIMEDOUT; in dw_hdmi_phy_power_on()
1433 dev_dbg(hdmi->dev, "PHY PLL locked %u iterations\n", i); in dw_hdmi_phy_power_on()
1438 * PHY configuration function for the DWC HDMI 3D TX PHY. Based on the available
1446 const struct dw_hdmi_mpll_config *mpll_config = pdata->mpll_cfg; in hdmi_phy_configure_dwc_hdmi_3d_tx()
1447 const struct dw_hdmi_curr_ctrl *curr_ctrl = pdata->cur_ctr; in hdmi_phy_configure_dwc_hdmi_3d_tx()
1448 const struct dw_hdmi_phy_config *phy_config = pdata->phy_config; in hdmi_phy_configure_dwc_hdmi_3d_tx()
1452 /* PLL/MPLL Cfg - always match on final entry */ in hdmi_phy_configure_dwc_hdmi_3d_tx()
1453 for (; mpll_config->mpixelclock != ~0UL; mpll_config++) in hdmi_phy_configure_dwc_hdmi_3d_tx()
1454 if (mpixelclock <= mpll_config->mpixelclock) in hdmi_phy_configure_dwc_hdmi_3d_tx()
1457 for (; curr_ctrl->mpixelclock != ~0UL; curr_ctrl++) in hdmi_phy_configure_dwc_hdmi_3d_tx()
1458 if (mpixelclock <= curr_ctrl->mpixelclock) in hdmi_phy_configure_dwc_hdmi_3d_tx()
1461 for (; phy_config->mpixelclock != ~0UL; phy_config++) in hdmi_phy_configure_dwc_hdmi_3d_tx()
1462 if (mpixelclock <= phy_config->mpixelclock) in hdmi_phy_configure_dwc_hdmi_3d_tx()
1465 if (mpll_config->mpixelclock == ~0UL || in hdmi_phy_configure_dwc_hdmi_3d_tx()
1466 curr_ctrl->mpixelclock == ~0UL || in hdmi_phy_configure_dwc_hdmi_3d_tx()
1467 phy_config->mpixelclock == ~0UL) in hdmi_phy_configure_dwc_hdmi_3d_tx()
1468 return -EINVAL; in hdmi_phy_configure_dwc_hdmi_3d_tx()
1470 dw_hdmi_phy_i2c_write(hdmi, mpll_config->res[0].cpce, in hdmi_phy_configure_dwc_hdmi_3d_tx()
1472 dw_hdmi_phy_i2c_write(hdmi, mpll_config->res[0].gmp, in hdmi_phy_configure_dwc_hdmi_3d_tx()
1474 dw_hdmi_phy_i2c_write(hdmi, curr_ctrl->curr[0], in hdmi_phy_configure_dwc_hdmi_3d_tx()
1481 dw_hdmi_phy_i2c_write(hdmi, phy_config->term, HDMI_3D_TX_PHY_TXTERM); in hdmi_phy_configure_dwc_hdmi_3d_tx()
1482 dw_hdmi_phy_i2c_write(hdmi, phy_config->sym_ctr, in hdmi_phy_configure_dwc_hdmi_3d_tx()
1484 dw_hdmi_phy_i2c_write(hdmi, phy_config->vlev_ctr, in hdmi_phy_configure_dwc_hdmi_3d_tx()
1487 /* Override and disable clock termination. */ in hdmi_phy_configure_dwc_hdmi_3d_tx()
1497 const struct dw_hdmi_phy_data *phy = hdmi->phy.data; in hdmi_phy_configure()
1498 const struct dw_hdmi_plat_data *pdata = hdmi->plat_data; in hdmi_phy_configure()
1499 unsigned long mpixelclock = hdmi->hdmi_data.video_mode.mpixelclock; in hdmi_phy_configure()
1500 unsigned long mtmdsclock = hdmi->hdmi_data.video_mode.mtmdsclock; in hdmi_phy_configure()
1508 if (phy->has_svsret) in hdmi_phy_configure()
1518 if (pdata->configure_phy) in hdmi_phy_configure()
1519 ret = pdata->configure_phy(hdmi, pdata->priv_data, mpixelclock); in hdmi_phy_configure()
1521 ret = phy->configure(hdmi, pdata, mpixelclock); in hdmi_phy_configure()
1523 dev_err(hdmi->dev, "PHY configuration failed (clock %lu)\n", in hdmi_phy_configure()
1570 u8 old_mask = hdmi->phy_mask; in dw_hdmi_phy_update_hpd()
1573 hdmi->phy_mask |= HDMI_PHY_RX_SENSE; in dw_hdmi_phy_update_hpd()
1575 hdmi->phy_mask &= ~HDMI_PHY_RX_SENSE; in dw_hdmi_phy_update_hpd()
1577 if (old_mask != hdmi->phy_mask) in dw_hdmi_phy_update_hpd()
1578 hdmi_writeb(hdmi, hdmi->phy_mask, HDMI_PHY_MASK0); in dw_hdmi_phy_update_hpd()
1593 hdmi_writeb(hdmi, hdmi->phy_mask, HDMI_PHY_MASK0); in dw_hdmi_phy_setup_hpd()
1611 /* -----------------------------------------------------------------------------
1612 * HDMI TX Setup
1619 if (hdmi->hdmi_data.video_mode.mdataenablepolarity) in hdmi_tx_hdcp_config()
1644 if (hdmi_bus_fmt_is_rgb(hdmi->hdmi_data.enc_out_bus_format)) { in hdmi_config_AVI()
1646 hdmi->hdmi_data.rgb_limited_range ? in hdmi_config_AVI()
1655 if (hdmi_bus_fmt_is_yuv444(hdmi->hdmi_data.enc_out_bus_format)) in hdmi_config_AVI()
1657 else if (hdmi_bus_fmt_is_yuv422(hdmi->hdmi_data.enc_out_bus_format)) in hdmi_config_AVI()
1659 else if (hdmi_bus_fmt_is_yuv420(hdmi->hdmi_data.enc_out_bus_format)) in hdmi_config_AVI()
1665 if (!hdmi_bus_fmt_is_rgb(hdmi->hdmi_data.enc_out_bus_format)) { in hdmi_config_AVI()
1666 switch (hdmi->hdmi_data.enc_out_encoding) { in hdmi_config_AVI()
1668 if (hdmi->hdmi_data.enc_in_encoding == V4L2_YCBCR_ENC_XV601) in hdmi_config_AVI()
1676 if (hdmi->hdmi_data.enc_in_encoding == V4L2_YCBCR_ENC_XV709) in hdmi_config_AVI()
1733 /* AVI Data Byte 5- set up input and output pixel repetition */ in hdmi_config_AVI()
1734 val = (((hdmi->hdmi_data.video_mode.mpixelrepetitioninput + 1) << in hdmi_config_AVI()
1737 ((hdmi->hdmi_data.video_mode.mpixelrepetitionoutput << in hdmi_config_AVI()
1750 /* AVI Data Bytes 6-13 */ in hdmi_config_AVI()
1782 dev_err(hdmi->dev, "Failed to pack vendor infoframe: %zd\n", in hdmi_config_vendor_specific_infoframe()
1818 const struct drm_connector_state *conn_state = connector->state; in hdmi_config_drm_infoframe()
1824 if (!hdmi->plat_data->use_drm_infoframe) in hdmi_config_drm_infoframe()
1836 dev_err(hdmi->dev, "Failed to pack drm infoframe: %zd\n", err); in hdmi_config_drm_infoframe()
1856 const struct drm_hdmi_info *hdmi_info = &display->hdmi; in hdmi_av_composer()
1857 struct hdmi_vmode *vmode = &hdmi->hdmi_data.video_mode; in hdmi_av_composer()
1861 vmode->mpixelclock = mode->clock * 1000; in hdmi_av_composer()
1863 dev_dbg(hdmi->dev, "final pixclk = %d\n", vmode->mpixelclock); in hdmi_av_composer()
1865 vmode->mtmdsclock = vmode->mpixelclock; in hdmi_av_composer()
1867 if (!hdmi_bus_fmt_is_yuv422(hdmi->hdmi_data.enc_out_bus_format)) { in hdmi_av_composer()
1869 hdmi->hdmi_data.enc_out_bus_format)) { in hdmi_av_composer()
1871 vmode->mtmdsclock = vmode->mpixelclock * 2; in hdmi_av_composer()
1874 vmode->mtmdsclock = vmode->mpixelclock * 3 / 2; in hdmi_av_composer()
1877 vmode->mtmdsclock = vmode->mpixelclock * 5 / 4; in hdmi_av_composer()
1882 if (hdmi_bus_fmt_is_yuv420(hdmi->hdmi_data.enc_out_bus_format)) in hdmi_av_composer()
1883 vmode->mtmdsclock /= 2; in hdmi_av_composer()
1885 dev_dbg(hdmi->dev, "final tmdsclock = %d\n", vmode->mtmdsclock); in hdmi_av_composer()
1888 inv_val = (hdmi->hdmi_data.hdcp_enable || in hdmi_av_composer()
1890 (vmode->mtmdsclock > HDMI14_MAX_TMDSCLK || in hdmi_av_composer()
1891 hdmi_info->scdc.scrambling.low_rates)) ? in hdmi_av_composer()
1895 inv_val |= mode->flags & DRM_MODE_FLAG_PVSYNC ? in hdmi_av_composer()
1899 inv_val |= mode->flags & DRM_MODE_FLAG_PHSYNC ? in hdmi_av_composer()
1903 inv_val |= (vmode->mdataenablepolarity ? in hdmi_av_composer()
1907 if (hdmi->vic == 39) in hdmi_av_composer()
1910 inv_val |= mode->flags & DRM_MODE_FLAG_INTERLACE ? in hdmi_av_composer()
1914 inv_val |= mode->flags & DRM_MODE_FLAG_INTERLACE ? in hdmi_av_composer()
1918 inv_val |= hdmi->sink_is_hdmi ? in hdmi_av_composer()
1924 hdisplay = mode->hdisplay; in hdmi_av_composer()
1925 hblank = mode->htotal - mode->hdisplay; in hdmi_av_composer()
1926 h_de_hs = mode->hsync_start - mode->hdisplay; in hdmi_av_composer()
1927 hsync_len = mode->hsync_end - mode->hsync_start; in hdmi_av_composer()
1933 if (hdmi_bus_fmt_is_yuv420(hdmi->hdmi_data.enc_out_bus_format)) { in hdmi_av_composer()
1940 vdisplay = mode->vdisplay; in hdmi_av_composer()
1941 vblank = mode->vtotal - mode->vdisplay; in hdmi_av_composer()
1942 v_de_vs = mode->vsync_start - mode->vdisplay; in hdmi_av_composer()
1943 vsync_len = mode->vsync_end - mode->vsync_start; in hdmi_av_composer()
1949 if (mode->flags & DRM_MODE_FLAG_INTERLACE) { in hdmi_av_composer()
1958 if (vmode->mtmdsclock > HDMI14_MAX_TMDSCLK || in hdmi_av_composer()
1959 hdmi_info->scdc.scrambling.low_rates) { in hdmi_av_composer()
1969 drm_scdc_readb(hdmi->ddc, SCDC_SINK_VERSION, in hdmi_av_composer()
1971 drm_scdc_writeb(hdmi->ddc, SCDC_SOURCE_VERSION, in hdmi_av_composer()
1975 drm_scdc_set_scrambling(hdmi->ddc, 1); in hdmi_av_composer()
1979 * that the quasi-static configuration bit in hdmi_av_composer()
1991 drm_scdc_set_scrambling(hdmi->ddc, 0); in hdmi_av_composer()
2039 hdmi->mc_clkdis |= HDMI_MC_CLKDIS_HDCPCLK_DISABLE | in dw_hdmi_enable_video_path()
2044 hdmi->mc_clkdis &= ~HDMI_MC_CLKDIS_PIXELCLK_DISABLE; in dw_hdmi_enable_video_path()
2045 hdmi_writeb(hdmi, hdmi->mc_clkdis, HDMI_MC_CLKDIS); in dw_hdmi_enable_video_path()
2047 hdmi->mc_clkdis &= ~HDMI_MC_CLKDIS_TMDSCLK_DISABLE; in dw_hdmi_enable_video_path()
2048 hdmi_writeb(hdmi, hdmi->mc_clkdis, HDMI_MC_CLKDIS); in dw_hdmi_enable_video_path()
2052 hdmi->mc_clkdis &= ~HDMI_MC_CLKDIS_CSCCLK_DISABLE; in dw_hdmi_enable_video_path()
2053 hdmi_writeb(hdmi, hdmi->mc_clkdis, HDMI_MC_CLKDIS); in dw_hdmi_enable_video_path()
2058 hdmi->mc_clkdis |= HDMI_MC_CLKDIS_CSCCLK_DISABLE; in dw_hdmi_enable_video_path()
2059 hdmi_writeb(hdmi, hdmi->mc_clkdis, HDMI_MC_CLKDIS); in dw_hdmi_enable_video_path()
2079 * The number of iterations matters and depends on the HDMI TX revision in dw_hdmi_clear_overflow()
2090 switch (hdmi->version) { in dw_hdmi_clear_overflow()
2128 hdmi->vic = drm_match_cea_mode(mode); in dw_hdmi_setup()
2130 if (!hdmi->vic) { in dw_hdmi_setup()
2131 dev_dbg(hdmi->dev, "Non-CEA mode used in HDMI\n"); in dw_hdmi_setup()
2133 dev_dbg(hdmi->dev, "CEA mode used vic=%d\n", hdmi->vic); in dw_hdmi_setup()
2136 if ((hdmi->vic == 6) || (hdmi->vic == 7) || in dw_hdmi_setup()
2137 (hdmi->vic == 21) || (hdmi->vic == 22) || in dw_hdmi_setup()
2138 (hdmi->vic == 2) || (hdmi->vic == 3) || in dw_hdmi_setup()
2139 (hdmi->vic == 17) || (hdmi->vic == 18)) in dw_hdmi_setup()
2140 hdmi->hdmi_data.enc_out_encoding = V4L2_YCBCR_ENC_601; in dw_hdmi_setup()
2142 hdmi->hdmi_data.enc_out_encoding = V4L2_YCBCR_ENC_709; in dw_hdmi_setup()
2144 hdmi->hdmi_data.video_mode.mpixelrepetitionoutput = 0; in dw_hdmi_setup()
2145 hdmi->hdmi_data.video_mode.mpixelrepetitioninput = 0; in dw_hdmi_setup()
2147 if (hdmi->hdmi_data.enc_in_bus_format == MEDIA_BUS_FMT_FIXED) in dw_hdmi_setup()
2148 hdmi->hdmi_data.enc_in_bus_format = MEDIA_BUS_FMT_RGB888_1X24; in dw_hdmi_setup()
2151 if (hdmi->plat_data->input_bus_encoding) in dw_hdmi_setup()
2152 hdmi->hdmi_data.enc_in_encoding = in dw_hdmi_setup()
2153 hdmi->plat_data->input_bus_encoding; in dw_hdmi_setup()
2155 hdmi->hdmi_data.enc_in_encoding = V4L2_YCBCR_ENC_DEFAULT; in dw_hdmi_setup()
2157 if (hdmi->hdmi_data.enc_out_bus_format == MEDIA_BUS_FMT_FIXED) in dw_hdmi_setup()
2158 hdmi->hdmi_data.enc_out_bus_format = MEDIA_BUS_FMT_RGB888_1X24; in dw_hdmi_setup()
2160 hdmi->hdmi_data.rgb_limited_range = hdmi->sink_is_hdmi && in dw_hdmi_setup()
2164 hdmi->hdmi_data.pix_repet_factor = 0; in dw_hdmi_setup()
2165 hdmi->hdmi_data.hdcp_enable = 0; in dw_hdmi_setup()
2166 hdmi->hdmi_data.video_mode.mdataenablepolarity = true; in dw_hdmi_setup()
2169 hdmi_av_composer(hdmi, &connector->display_info, mode); in dw_hdmi_setup()
2172 ret = hdmi->phy.ops->init(hdmi, hdmi->phy.data, in dw_hdmi_setup()
2173 &connector->display_info, in dw_hdmi_setup()
2174 &hdmi->previous_mode); in dw_hdmi_setup()
2177 hdmi->phy.enabled = true; in dw_hdmi_setup()
2182 if (hdmi->sink_has_audio) { in dw_hdmi_setup()
2183 dev_dbg(hdmi->dev, "sink has audio support\n"); in dw_hdmi_setup()
2185 /* HDMI Initialization Step E - Configure audio */ in dw_hdmi_setup()
2187 hdmi_enable_audio_clk(hdmi, hdmi->audio_enable); in dw_hdmi_setup()
2191 if (hdmi->sink_is_hdmi) { in dw_hdmi_setup()
2192 dev_dbg(hdmi->dev, "%s HDMI mode\n", __func__); in dw_hdmi_setup()
2194 /* HDMI Initialization Step F - Configure AVI InfoFrame */ in dw_hdmi_setup()
2199 dev_dbg(hdmi->dev, "%s DVI mode\n", __func__); in dw_hdmi_setup()
2265 hdmi->bridge_is_on = true; in dw_hdmi_poweron()
2269 * is only be called when !hdmi->disabled. in dw_hdmi_poweron()
2271 dw_hdmi_setup(hdmi, hdmi->curr_conn, &hdmi->previous_mode); in dw_hdmi_poweron()
2276 if (hdmi->phy.enabled) { in dw_hdmi_poweroff()
2277 hdmi->phy.ops->disable(hdmi, hdmi->phy.data); in dw_hdmi_poweroff()
2278 hdmi->phy.enabled = false; in dw_hdmi_poweroff()
2281 hdmi->bridge_is_on = false; in dw_hdmi_poweroff()
2286 int force = hdmi->force; in dw_hdmi_update_power()
2288 if (hdmi->disabled) { in dw_hdmi_update_power()
2291 if (hdmi->rxsense) in dw_hdmi_update_power()
2298 if (hdmi->bridge_is_on) in dw_hdmi_update_power()
2301 if (!hdmi->bridge_is_on) in dw_hdmi_update_power()
2320 if (hdmi->phy.ops->update_hpd) in dw_hdmi_update_phy_mask()
2321 hdmi->phy.ops->update_hpd(hdmi, hdmi->phy.data, in dw_hdmi_update_phy_mask()
2322 hdmi->force, hdmi->disabled, in dw_hdmi_update_phy_mask()
2323 hdmi->rxsense); in dw_hdmi_update_phy_mask()
2330 result = hdmi->phy.ops->read_hpd(hdmi, hdmi->phy.data); in dw_hdmi_detect()
2332 mutex_lock(&hdmi->mutex); in dw_hdmi_detect()
2333 if (result != hdmi->last_connector_result) { in dw_hdmi_detect()
2334 dev_dbg(hdmi->dev, "read_hpd result: %d", result); in dw_hdmi_detect()
2337 hdmi->last_connector_result = result; in dw_hdmi_detect()
2339 mutex_unlock(&hdmi->mutex); in dw_hdmi_detect()
2349 if (!hdmi->ddc) in dw_hdmi_get_edid()
2352 edid = drm_get_edid(connector, hdmi->ddc); in dw_hdmi_get_edid()
2354 dev_dbg(hdmi->dev, "failed to get edid\n"); in dw_hdmi_get_edid()
2358 dev_dbg(hdmi->dev, "got edid: width[%d] x height[%d]\n", in dw_hdmi_get_edid()
2359 edid->width_cm, edid->height_cm); in dw_hdmi_get_edid()
2361 hdmi->sink_is_hdmi = drm_detect_hdmi_monitor(edid); in dw_hdmi_get_edid()
2362 hdmi->sink_has_audio = drm_detect_monitor_audio(edid); in dw_hdmi_get_edid()
2367 /* -----------------------------------------------------------------------------
2391 cec_notifier_set_phys_addr_from_edid(hdmi->cec_notifier, edid); in dw_hdmi_connector_get_modes()
2401 struct drm_property_blob *old_blob = old_state->hdr_output_metadata; in hdr_metadata_equal()
2402 struct drm_property_blob *new_blob = new_state->hdr_output_metadata; in hdr_metadata_equal()
2407 if (old_blob->length != new_blob->length) in hdr_metadata_equal()
2410 return !memcmp(old_blob->data, new_blob->data, old_blob->length); in hdr_metadata_equal()
2420 struct drm_crtc *crtc = new_state->crtc; in dw_hdmi_connector_atomic_check()
2431 crtc_state->mode_changed = true; in dw_hdmi_connector_atomic_check()
2442 mutex_lock(&hdmi->mutex); in dw_hdmi_connector_force()
2443 hdmi->force = connector->force; in dw_hdmi_connector_force()
2446 mutex_unlock(&hdmi->mutex); in dw_hdmi_connector_force()
2466 struct drm_connector *connector = &hdmi->connector; in dw_hdmi_connector_create()
2470 if (hdmi->version >= 0x200a) in dw_hdmi_connector_create()
2471 connector->ycbcr_420_allowed = in dw_hdmi_connector_create()
2472 hdmi->plat_data->ycbcr_420_allowed; in dw_hdmi_connector_create()
2474 connector->ycbcr_420_allowed = false; in dw_hdmi_connector_create()
2476 connector->interlace_allowed = 1; in dw_hdmi_connector_create()
2477 connector->polled = DRM_CONNECTOR_POLL_HPD; in dw_hdmi_connector_create()
2481 drm_connector_init_with_ddc(hdmi->bridge.dev, connector, in dw_hdmi_connector_create()
2484 hdmi->ddc); in dw_hdmi_connector_create()
2494 if (hdmi->version >= 0x200a && hdmi->plat_data->use_drm_infoframe) in dw_hdmi_connector_create()
2495 drm_object_attach_property(&connector->base, in dw_hdmi_connector_create()
2496 connector->dev->mode_config.hdr_output_metadata_property, 0); in dw_hdmi_connector_create()
2498 drm_connector_attach_encoder(connector, hdmi->bridge.encoder); in dw_hdmi_connector_create()
2502 notifier = cec_notifier_conn_register(hdmi->dev, NULL, &conn_info); in dw_hdmi_connector_create()
2504 return -ENOMEM; in dw_hdmi_connector_create()
2506 mutex_lock(&hdmi->cec_notifier_mutex); in dw_hdmi_connector_create()
2507 hdmi->cec_notifier = notifier; in dw_hdmi_connector_create()
2508 mutex_unlock(&hdmi->cec_notifier_mutex); in dw_hdmi_connector_create()
2513 /* -----------------------------------------------------------------------------
2519 * - MEDIA_BUS_FMT_UYYVYY16_0_5X48,
2520 * - MEDIA_BUS_FMT_UYYVYY12_0_5X36,
2521 * - MEDIA_BUS_FMT_UYYVYY10_0_5X30,
2522 * - MEDIA_BUS_FMT_UYYVYY8_0_5X24,
2523 * - MEDIA_BUS_FMT_YUV16_1X48,
2524 * - MEDIA_BUS_FMT_RGB161616_1X48,
2525 * - MEDIA_BUS_FMT_UYVY12_1X24,
2526 * - MEDIA_BUS_FMT_YUV12_1X36,
2527 * - MEDIA_BUS_FMT_RGB121212_1X36,
2528 * - MEDIA_BUS_FMT_UYVY10_1X20,
2529 * - MEDIA_BUS_FMT_YUV10_1X30,
2530 * - MEDIA_BUS_FMT_RGB101010_1X30,
2531 * - MEDIA_BUS_FMT_UYVY8_1X16,
2532 * - MEDIA_BUS_FMT_YUV8_1X24,
2533 * - MEDIA_BUS_FMT_RGB888_1X24,
2545 struct drm_connector *conn = conn_state->connector; in dw_hdmi_bridge_atomic_get_output_bus_fmts()
2546 struct drm_display_info *info = &conn->display_info; in dw_hdmi_bridge_atomic_get_output_bus_fmts()
2547 struct drm_display_mode *mode = &crtc_state->mode; in dw_hdmi_bridge_atomic_get_output_bus_fmts()
2548 u8 max_bpc = conn_state->max_requested_bpc; in dw_hdmi_bridge_atomic_get_output_bus_fmts()
2549 bool is_hdmi2_sink = info->hdmi.scdc.supported || in dw_hdmi_bridge_atomic_get_output_bus_fmts()
2550 (info->color_formats & DRM_COLOR_FORMAT_YCRCB420); in dw_hdmi_bridge_atomic_get_output_bus_fmts()
2561 /* If dw-hdmi is the only bridge, avoid negociating with ourselves */ in dw_hdmi_bridge_atomic_get_output_bus_fmts()
2562 if (list_is_singular(&bridge->encoder->bridge_chain)) { in dw_hdmi_bridge_atomic_get_output_bus_fmts()
2573 if (conn->ycbcr_420_allowed && in dw_hdmi_bridge_atomic_get_output_bus_fmts()
2578 if (max_bpc >= 16 && info->bpc == 16 && in dw_hdmi_bridge_atomic_get_output_bus_fmts()
2579 (info->hdmi.y420_dc_modes & DRM_EDID_YCBCR420_DC_48)) in dw_hdmi_bridge_atomic_get_output_bus_fmts()
2582 if (max_bpc >= 12 && info->bpc >= 12 && in dw_hdmi_bridge_atomic_get_output_bus_fmts()
2583 (info->hdmi.y420_dc_modes & DRM_EDID_YCBCR420_DC_36)) in dw_hdmi_bridge_atomic_get_output_bus_fmts()
2586 if (max_bpc >= 10 && info->bpc >= 10 && in dw_hdmi_bridge_atomic_get_output_bus_fmts()
2587 (info->hdmi.y420_dc_modes & DRM_EDID_YCBCR420_DC_30)) in dw_hdmi_bridge_atomic_get_output_bus_fmts()
2603 if (max_bpc >= 16 && info->bpc == 16) { in dw_hdmi_bridge_atomic_get_output_bus_fmts()
2604 if (info->color_formats & DRM_COLOR_FORMAT_YCRCB444) in dw_hdmi_bridge_atomic_get_output_bus_fmts()
2610 if (max_bpc >= 12 && info->bpc >= 12) { in dw_hdmi_bridge_atomic_get_output_bus_fmts()
2611 if (info->color_formats & DRM_COLOR_FORMAT_YCRCB422) in dw_hdmi_bridge_atomic_get_output_bus_fmts()
2614 if (info->color_formats & DRM_COLOR_FORMAT_YCRCB444) in dw_hdmi_bridge_atomic_get_output_bus_fmts()
2620 if (max_bpc >= 10 && info->bpc >= 10) { in dw_hdmi_bridge_atomic_get_output_bus_fmts()
2621 if (info->color_formats & DRM_COLOR_FORMAT_YCRCB422) in dw_hdmi_bridge_atomic_get_output_bus_fmts()
2624 if (info->color_formats & DRM_COLOR_FORMAT_YCRCB444) in dw_hdmi_bridge_atomic_get_output_bus_fmts()
2630 if (info->color_formats & DRM_COLOR_FORMAT_YCRCB422) in dw_hdmi_bridge_atomic_get_output_bus_fmts()
2633 if (info->color_formats & DRM_COLOR_FORMAT_YCRCB444) in dw_hdmi_bridge_atomic_get_output_bus_fmts()
2646 * - MEDIA_BUS_FMT_RGB888_1X24
2647 * - MEDIA_BUS_FMT_YUV8_1X24
2648 * - MEDIA_BUS_FMT_UYVY8_1X16
2649 * - MEDIA_BUS_FMT_UYYVYY8_0_5X24
2650 * - MEDIA_BUS_FMT_RGB101010_1X30
2651 * - MEDIA_BUS_FMT_YUV10_1X30
2652 * - MEDIA_BUS_FMT_UYVY10_1X20
2653 * - MEDIA_BUS_FMT_UYYVYY10_0_5X30
2654 * - MEDIA_BUS_FMT_RGB121212_1X36
2655 * - MEDIA_BUS_FMT_YUV12_1X36
2656 * - MEDIA_BUS_FMT_UYVY12_1X24
2657 * - MEDIA_BUS_FMT_UYYVYY12_0_5X36
2658 * - MEDIA_BUS_FMT_RGB161616_1X48
2659 * - MEDIA_BUS_FMT_YUV16_1X48
2660 * - MEDIA_BUS_FMT_UYYVYY16_0_5X48
2773 struct dw_hdmi *hdmi = bridge->driver_private; in dw_hdmi_bridge_atomic_check()
2775 hdmi->hdmi_data.enc_out_bus_format = in dw_hdmi_bridge_atomic_check()
2776 bridge_state->output_bus_cfg.format; in dw_hdmi_bridge_atomic_check()
2778 hdmi->hdmi_data.enc_in_bus_format = in dw_hdmi_bridge_atomic_check()
2779 bridge_state->input_bus_cfg.format; in dw_hdmi_bridge_atomic_check()
2781 dev_dbg(hdmi->dev, "input format 0x%04x, output format 0x%04x\n", in dw_hdmi_bridge_atomic_check()
2782 bridge_state->input_bus_cfg.format, in dw_hdmi_bridge_atomic_check()
2783 bridge_state->output_bus_cfg.format); in dw_hdmi_bridge_atomic_check()
2791 struct dw_hdmi *hdmi = bridge->driver_private; in dw_hdmi_bridge_attach()
2801 struct dw_hdmi *hdmi = bridge->driver_private; in dw_hdmi_bridge_detach()
2803 mutex_lock(&hdmi->cec_notifier_mutex); in dw_hdmi_bridge_detach()
2804 cec_notifier_conn_unregister(hdmi->cec_notifier); in dw_hdmi_bridge_detach()
2805 hdmi->cec_notifier = NULL; in dw_hdmi_bridge_detach()
2806 mutex_unlock(&hdmi->cec_notifier_mutex); in dw_hdmi_bridge_detach()
2814 struct dw_hdmi *hdmi = bridge->driver_private; in dw_hdmi_bridge_mode_valid()
2815 const struct dw_hdmi_plat_data *pdata = hdmi->plat_data; in dw_hdmi_bridge_mode_valid()
2818 /* We don't support double-clocked modes */ in dw_hdmi_bridge_mode_valid()
2819 if (mode->flags & DRM_MODE_FLAG_DBLCLK) in dw_hdmi_bridge_mode_valid()
2822 if (pdata->mode_valid) in dw_hdmi_bridge_mode_valid()
2823 mode_status = pdata->mode_valid(hdmi, pdata->priv_data, info, in dw_hdmi_bridge_mode_valid()
2833 struct dw_hdmi *hdmi = bridge->driver_private; in dw_hdmi_bridge_mode_set()
2835 mutex_lock(&hdmi->mutex); in dw_hdmi_bridge_mode_set()
2838 memcpy(&hdmi->previous_mode, mode, sizeof(hdmi->previous_mode)); in dw_hdmi_bridge_mode_set()
2840 mutex_unlock(&hdmi->mutex); in dw_hdmi_bridge_mode_set()
2846 struct dw_hdmi *hdmi = bridge->driver_private; in dw_hdmi_bridge_atomic_disable()
2848 mutex_lock(&hdmi->mutex); in dw_hdmi_bridge_atomic_disable()
2849 hdmi->disabled = true; in dw_hdmi_bridge_atomic_disable()
2850 hdmi->curr_conn = NULL; in dw_hdmi_bridge_atomic_disable()
2853 mutex_unlock(&hdmi->mutex); in dw_hdmi_bridge_atomic_disable()
2859 struct dw_hdmi *hdmi = bridge->driver_private; in dw_hdmi_bridge_atomic_enable()
2860 struct drm_atomic_state *state = old_state->base.state; in dw_hdmi_bridge_atomic_enable()
2864 bridge->encoder); in dw_hdmi_bridge_atomic_enable()
2866 mutex_lock(&hdmi->mutex); in dw_hdmi_bridge_atomic_enable()
2867 hdmi->disabled = false; in dw_hdmi_bridge_atomic_enable()
2868 hdmi->curr_conn = connector; in dw_hdmi_bridge_atomic_enable()
2871 mutex_unlock(&hdmi->mutex); in dw_hdmi_bridge_atomic_enable()
2876 struct dw_hdmi *hdmi = bridge->driver_private; in dw_hdmi_bridge_detect()
2884 struct dw_hdmi *hdmi = bridge->driver_private; in dw_hdmi_bridge_get_edid()
2906 /* -----------------------------------------------------------------------------
2912 struct dw_hdmi_i2c *i2c = hdmi->i2c; in dw_hdmi_i2c_irq()
2921 i2c->stat = stat; in dw_hdmi_i2c_irq()
2923 complete(&i2c->cmp); in dw_hdmi_i2c_irq()
2934 if (hdmi->i2c) in dw_hdmi_hardirq()
2948 mutex_lock(&hdmi->mutex); in dw_hdmi_setup_rx_sense()
2950 if (!hdmi->force) { in dw_hdmi_setup_rx_sense()
2956 hdmi->rxsense = false; in dw_hdmi_setup_rx_sense()
2965 hdmi->rxsense = true; in dw_hdmi_setup_rx_sense()
2970 mutex_unlock(&hdmi->mutex); in dw_hdmi_setup_rx_sense()
3000 * load - in other words, there's something listening on the in dw_hdmi_irq()
3003 * ask the source to re-read the EDID. in dw_hdmi_irq()
3012 mutex_lock(&hdmi->cec_notifier_mutex); in dw_hdmi_irq()
3013 cec_notifier_phys_addr_invalidate(hdmi->cec_notifier); in dw_hdmi_irq()
3014 mutex_unlock(&hdmi->cec_notifier_mutex); in dw_hdmi_irq()
3023 dev_dbg(hdmi->dev, "EVENT=%s\n", in dw_hdmi_irq()
3027 if (hdmi->bridge.dev) { in dw_hdmi_irq()
3028 drm_helper_hpd_irq_event(hdmi->bridge.dev); in dw_hdmi_irq()
3029 drm_bridge_hpd_notify(&hdmi->bridge, status); in dw_hdmi_irq()
3043 .name = "DWC HDMI TX PHY",
3059 .name = "DWC HDMI 3D TX PHY + HEAC PHY",
3064 .name = "DWC HDMI 3D TX PHY",
3069 .name = "DWC HDMI 2.0 TX PHY",
3084 phy_type = hdmi->plat_data->phy_force_vendor ? in dw_hdmi_detect_phy()
3090 if (!hdmi->plat_data->phy_ops || !hdmi->plat_data->phy_name) { in dw_hdmi_detect_phy()
3091 dev_err(hdmi->dev, in dw_hdmi_detect_phy()
3093 return -ENODEV; in dw_hdmi_detect_phy()
3096 hdmi->phy.ops = hdmi->plat_data->phy_ops; in dw_hdmi_detect_phy()
3097 hdmi->phy.data = hdmi->plat_data->phy_data; in dw_hdmi_detect_phy()
3098 hdmi->phy.name = hdmi->plat_data->phy_name; in dw_hdmi_detect_phy()
3105 hdmi->phy.ops = &dw_hdmi_synopsys_phy_ops; in dw_hdmi_detect_phy()
3106 hdmi->phy.name = dw_hdmi_phys[i].name; in dw_hdmi_detect_phy()
3107 hdmi->phy.data = (void *)&dw_hdmi_phys[i]; in dw_hdmi_detect_phy()
3110 !hdmi->plat_data->configure_phy) { in dw_hdmi_detect_phy()
3111 dev_err(hdmi->dev, "%s requires platform support\n", in dw_hdmi_detect_phy()
3112 hdmi->phy.name); in dw_hdmi_detect_phy()
3113 return -ENODEV; in dw_hdmi_detect_phy()
3120 dev_err(hdmi->dev, "Unsupported HDMI PHY type (%02x)\n", phy_type); in dw_hdmi_detect_phy()
3121 return -ENODEV; in dw_hdmi_detect_phy()
3126 mutex_lock(&hdmi->mutex); in dw_hdmi_cec_enable()
3127 hdmi->mc_clkdis &= ~HDMI_MC_CLKDIS_CECCLK_DISABLE; in dw_hdmi_cec_enable()
3128 hdmi_writeb(hdmi, hdmi->mc_clkdis, HDMI_MC_CLKDIS); in dw_hdmi_cec_enable()
3129 mutex_unlock(&hdmi->mutex); in dw_hdmi_cec_enable()
3134 mutex_lock(&hdmi->mutex); in dw_hdmi_cec_disable()
3135 hdmi->mc_clkdis |= HDMI_MC_CLKDIS_CECCLK_DISABLE; in dw_hdmi_cec_disable()
3136 hdmi_writeb(hdmi, hdmi->mc_clkdis, HDMI_MC_CLKDIS); in dw_hdmi_cec_disable()
3137 mutex_unlock(&hdmi->mutex); in dw_hdmi_cec_disable()
3172 if (hdmi->phy.ops->setup_hpd) in dw_hdmi_init_hw()
3173 hdmi->phy.ops->setup_hpd(hdmi, hdmi->phy.data); in dw_hdmi_init_hw()
3176 /* -----------------------------------------------------------------------------
3182 struct device *dev = &pdev->dev; in dw_hdmi_probe()
3183 struct device_node *np = dev->of_node; in dw_hdmi_probe()
3199 return ERR_PTR(-ENOMEM); in dw_hdmi_probe()
3201 hdmi->plat_data = plat_data; in dw_hdmi_probe()
3202 hdmi->dev = dev; in dw_hdmi_probe()
3203 hdmi->sample_rate = 48000; in dw_hdmi_probe()
3204 hdmi->disabled = true; in dw_hdmi_probe()
3205 hdmi->rxsense = true; in dw_hdmi_probe()
3206 hdmi->phy_mask = (u8)~(HDMI_PHY_HPD | HDMI_PHY_RX_SENSE); in dw_hdmi_probe()
3207 hdmi->mc_clkdis = 0x7f; in dw_hdmi_probe()
3208 hdmi->last_connector_result = connector_status_disconnected; in dw_hdmi_probe()
3210 mutex_init(&hdmi->mutex); in dw_hdmi_probe()
3211 mutex_init(&hdmi->audio_mutex); in dw_hdmi_probe()
3212 mutex_init(&hdmi->cec_notifier_mutex); in dw_hdmi_probe()
3213 spin_lock_init(&hdmi->audio_lock); in dw_hdmi_probe()
3215 ddc_node = of_parse_phandle(np, "ddc-i2c-bus", 0); in dw_hdmi_probe()
3217 hdmi->ddc = of_get_i2c_adapter_by_node(ddc_node); in dw_hdmi_probe()
3219 if (!hdmi->ddc) { in dw_hdmi_probe()
3220 dev_dbg(hdmi->dev, "failed to read ddc node\n"); in dw_hdmi_probe()
3221 return ERR_PTR(-EPROBE_DEFER); in dw_hdmi_probe()
3225 dev_dbg(hdmi->dev, "no ddc property found\n"); in dw_hdmi_probe()
3228 if (!plat_data->regm) { in dw_hdmi_probe()
3231 of_property_read_u32(np, "reg-io-width", &val); in dw_hdmi_probe()
3235 hdmi->reg_shift = 2; in dw_hdmi_probe()
3241 dev_err(dev, "reg-io-width must be 1 or 4\n"); in dw_hdmi_probe()
3242 return ERR_PTR(-EINVAL); in dw_hdmi_probe()
3246 hdmi->regs = devm_ioremap_resource(dev, iores); in dw_hdmi_probe()
3247 if (IS_ERR(hdmi->regs)) { in dw_hdmi_probe()
3248 ret = PTR_ERR(hdmi->regs); in dw_hdmi_probe()
3252 hdmi->regm = devm_regmap_init_mmio(dev, hdmi->regs, reg_config); in dw_hdmi_probe()
3253 if (IS_ERR(hdmi->regm)) { in dw_hdmi_probe()
3255 ret = PTR_ERR(hdmi->regm); in dw_hdmi_probe()
3259 hdmi->regm = plat_data->regm; in dw_hdmi_probe()
3262 hdmi->isfr_clk = devm_clk_get(hdmi->dev, "isfr"); in dw_hdmi_probe()
3263 if (IS_ERR(hdmi->isfr_clk)) { in dw_hdmi_probe()
3264 ret = PTR_ERR(hdmi->isfr_clk); in dw_hdmi_probe()
3265 dev_err(hdmi->dev, "Unable to get HDMI isfr clk: %d\n", ret); in dw_hdmi_probe()
3269 ret = clk_prepare_enable(hdmi->isfr_clk); in dw_hdmi_probe()
3271 dev_err(hdmi->dev, "Cannot enable HDMI isfr clock: %d\n", ret); in dw_hdmi_probe()
3275 hdmi->iahb_clk = devm_clk_get(hdmi->dev, "iahb"); in dw_hdmi_probe()
3276 if (IS_ERR(hdmi->iahb_clk)) { in dw_hdmi_probe()
3277 ret = PTR_ERR(hdmi->iahb_clk); in dw_hdmi_probe()
3278 dev_err(hdmi->dev, "Unable to get HDMI iahb clk: %d\n", ret); in dw_hdmi_probe()
3282 ret = clk_prepare_enable(hdmi->iahb_clk); in dw_hdmi_probe()
3284 dev_err(hdmi->dev, "Cannot enable HDMI iahb clock: %d\n", ret); in dw_hdmi_probe()
3288 hdmi->cec_clk = devm_clk_get(hdmi->dev, "cec"); in dw_hdmi_probe()
3289 if (PTR_ERR(hdmi->cec_clk) == -ENOENT) { in dw_hdmi_probe()
3290 hdmi->cec_clk = NULL; in dw_hdmi_probe()
3291 } else if (IS_ERR(hdmi->cec_clk)) { in dw_hdmi_probe()
3292 ret = PTR_ERR(hdmi->cec_clk); in dw_hdmi_probe()
3293 if (ret != -EPROBE_DEFER) in dw_hdmi_probe()
3294 dev_err(hdmi->dev, "Cannot get HDMI cec clock: %d\n", in dw_hdmi_probe()
3297 hdmi->cec_clk = NULL; in dw_hdmi_probe()
3300 ret = clk_prepare_enable(hdmi->cec_clk); in dw_hdmi_probe()
3302 dev_err(hdmi->dev, "Cannot enable HDMI cec clock: %d\n", in dw_hdmi_probe()
3309 hdmi->version = (hdmi_readb(hdmi, HDMI_DESIGN_ID) << 8) in dw_hdmi_probe()
3317 hdmi->version, prod_id0, prod_id1); in dw_hdmi_probe()
3318 ret = -ENODEV; in dw_hdmi_probe()
3326 dev_info(dev, "Detected HDMI TX controller v%x.%03x %s HDCP (%s)\n", in dw_hdmi_probe()
3327 hdmi->version >> 12, hdmi->version & 0xfff, in dw_hdmi_probe()
3329 hdmi->phy.name); in dw_hdmi_probe()
3352 if (!hdmi->ddc) { in dw_hdmi_probe()
3354 hdmi->pinctrl = devm_pinctrl_get(dev); in dw_hdmi_probe()
3355 if (!IS_ERR(hdmi->pinctrl)) { in dw_hdmi_probe()
3356 hdmi->unwedge_state = in dw_hdmi_probe()
3357 pinctrl_lookup_state(hdmi->pinctrl, "unwedge"); in dw_hdmi_probe()
3358 hdmi->default_state = in dw_hdmi_probe()
3359 pinctrl_lookup_state(hdmi->pinctrl, "default"); in dw_hdmi_probe()
3361 if (IS_ERR(hdmi->default_state) || in dw_hdmi_probe()
3362 IS_ERR(hdmi->unwedge_state)) { in dw_hdmi_probe()
3363 if (!IS_ERR(hdmi->unwedge_state)) in dw_hdmi_probe()
3366 hdmi->default_state = NULL; in dw_hdmi_probe()
3367 hdmi->unwedge_state = NULL; in dw_hdmi_probe()
3371 hdmi->ddc = dw_hdmi_i2c_adapter(hdmi); in dw_hdmi_probe()
3372 if (IS_ERR(hdmi->ddc)) in dw_hdmi_probe()
3373 hdmi->ddc = NULL; in dw_hdmi_probe()
3376 hdmi->bridge.driver_private = hdmi; in dw_hdmi_probe()
3377 hdmi->bridge.funcs = &dw_hdmi_bridge_funcs; in dw_hdmi_probe()
3378 hdmi->bridge.ops = DRM_BRIDGE_OP_DETECT | DRM_BRIDGE_OP_EDID in dw_hdmi_probe()
3381 hdmi->bridge.of_node = pdev->dev.of_node; in dw_hdmi_probe()
3394 audio.phys = iores->start; in dw_hdmi_probe()
3395 audio.base = hdmi->regs; in dw_hdmi_probe()
3398 audio.eld = hdmi->connector.eld; in dw_hdmi_probe()
3399 hdmi->enable_audio = dw_hdmi_ahb_audio_enable; in dw_hdmi_probe()
3400 hdmi->disable_audio = dw_hdmi_ahb_audio_disable; in dw_hdmi_probe()
3402 pdevinfo.name = "dw-hdmi-ahb-audio"; in dw_hdmi_probe()
3406 hdmi->audio = platform_device_register_full(&pdevinfo); in dw_hdmi_probe()
3411 audio.eld = hdmi->connector.eld; in dw_hdmi_probe()
3414 hdmi->enable_audio = dw_hdmi_i2s_audio_enable; in dw_hdmi_probe()
3415 hdmi->disable_audio = dw_hdmi_i2s_audio_disable; in dw_hdmi_probe()
3417 pdevinfo.name = "dw-hdmi-i2s-audio"; in dw_hdmi_probe()
3421 hdmi->audio = platform_device_register_full(&pdevinfo); in dw_hdmi_probe()
3429 pdevinfo.name = "dw-hdmi-cec"; in dw_hdmi_probe()
3434 hdmi->cec = platform_device_register_full(&pdevinfo); in dw_hdmi_probe()
3437 drm_bridge_add(&hdmi->bridge); in dw_hdmi_probe()
3442 clk_disable_unprepare(hdmi->iahb_clk); in dw_hdmi_probe()
3443 if (hdmi->cec_clk) in dw_hdmi_probe()
3444 clk_disable_unprepare(hdmi->cec_clk); in dw_hdmi_probe()
3446 clk_disable_unprepare(hdmi->isfr_clk); in dw_hdmi_probe()
3448 i2c_put_adapter(hdmi->ddc); in dw_hdmi_probe()
3456 drm_bridge_remove(&hdmi->bridge); in dw_hdmi_remove()
3458 if (hdmi->audio && !IS_ERR(hdmi->audio)) in dw_hdmi_remove()
3459 platform_device_unregister(hdmi->audio); in dw_hdmi_remove()
3460 if (!IS_ERR(hdmi->cec)) in dw_hdmi_remove()
3461 platform_device_unregister(hdmi->cec); in dw_hdmi_remove()
3466 clk_disable_unprepare(hdmi->iahb_clk); in dw_hdmi_remove()
3467 clk_disable_unprepare(hdmi->isfr_clk); in dw_hdmi_remove()
3468 if (hdmi->cec_clk) in dw_hdmi_remove()
3469 clk_disable_unprepare(hdmi->cec_clk); in dw_hdmi_remove()
3471 if (hdmi->i2c) in dw_hdmi_remove()
3472 i2c_del_adapter(&hdmi->i2c->adap); in dw_hdmi_remove()
3474 i2c_put_adapter(hdmi->ddc); in dw_hdmi_remove()
3478 /* -----------------------------------------------------------------------------
3492 ret = drm_bridge_attach(encoder, &hdmi->bridge, NULL, 0); in dw_hdmi_bind()
3516 MODULE_AUTHOR("Andy Yan <andy.yan@rock-chips.com>");
3517 MODULE_AUTHOR("Yakir Yang <ykk@rock-chips.com>");
3521 MODULE_ALIAS("platform:dw-hdmi");