Lines Matching refs:hdmi
138 int (*configure)(struct dw_hdmi *hdmi,
201 void (*enable_audio)(struct dw_hdmi *hdmi);
202 void (*disable_audio)(struct dw_hdmi *hdmi);
220 static inline void hdmi_writeb(struct dw_hdmi *hdmi, u8 val, int offset) in hdmi_writeb() argument
222 regmap_write(hdmi->regm, offset << hdmi->reg_shift, val); in hdmi_writeb()
225 static inline u8 hdmi_readb(struct dw_hdmi *hdmi, int offset) in hdmi_readb() argument
229 regmap_read(hdmi->regm, offset << hdmi->reg_shift, &val); in hdmi_readb()
234 static void handle_plugged_change(struct dw_hdmi *hdmi, bool plugged) in handle_plugged_change() argument
236 if (hdmi->plugged_cb && hdmi->codec_dev) in handle_plugged_change()
237 hdmi->plugged_cb(hdmi->codec_dev, plugged); in handle_plugged_change()
240 int dw_hdmi_set_plugged_cb(struct dw_hdmi *hdmi, hdmi_codec_plugged_cb fn, in dw_hdmi_set_plugged_cb() argument
245 mutex_lock(&hdmi->mutex); in dw_hdmi_set_plugged_cb()
246 hdmi->plugged_cb = fn; in dw_hdmi_set_plugged_cb()
247 hdmi->codec_dev = codec_dev; in dw_hdmi_set_plugged_cb()
248 plugged = hdmi->last_connector_result == connector_status_connected; in dw_hdmi_set_plugged_cb()
249 handle_plugged_change(hdmi, plugged); in dw_hdmi_set_plugged_cb()
250 mutex_unlock(&hdmi->mutex); in dw_hdmi_set_plugged_cb()
256 static void hdmi_modb(struct dw_hdmi *hdmi, u8 data, u8 mask, unsigned reg) in hdmi_modb() argument
258 regmap_update_bits(hdmi->regm, reg << hdmi->reg_shift, mask, data); in hdmi_modb()
261 static void hdmi_mask_writeb(struct dw_hdmi *hdmi, u8 data, unsigned int reg, in hdmi_mask_writeb() argument
264 hdmi_modb(hdmi, data << shift, mask, reg); in hdmi_mask_writeb()
267 static void dw_hdmi_i2c_init(struct dw_hdmi *hdmi) in dw_hdmi_i2c_init() argument
269 hdmi_writeb(hdmi, HDMI_PHY_I2CM_INT_ADDR_DONE_POL, in dw_hdmi_i2c_init()
272 hdmi_writeb(hdmi, HDMI_PHY_I2CM_CTLINT_ADDR_NAC_POL | in dw_hdmi_i2c_init()
277 hdmi_writeb(hdmi, 0x00, HDMI_I2CM_SOFTRSTZ); in dw_hdmi_i2c_init()
280 hdmi_writeb(hdmi, 0x00, HDMI_I2CM_DIV); in dw_hdmi_i2c_init()
283 hdmi_writeb(hdmi, HDMI_I2CM_INT_DONE_POL, HDMI_I2CM_INT); in dw_hdmi_i2c_init()
284 hdmi_writeb(hdmi, HDMI_I2CM_CTLINT_NAC_POL | HDMI_I2CM_CTLINT_ARB_POL, in dw_hdmi_i2c_init()
288 hdmi_writeb(hdmi, HDMI_IH_I2CM_STAT0_ERROR | HDMI_IH_I2CM_STAT0_DONE, in dw_hdmi_i2c_init()
292 hdmi_writeb(hdmi, HDMI_IH_I2CM_STAT0_ERROR | HDMI_IH_I2CM_STAT0_DONE, in dw_hdmi_i2c_init()
296 static bool dw_hdmi_i2c_unwedge(struct dw_hdmi *hdmi) in dw_hdmi_i2c_unwedge() argument
299 if (!hdmi->unwedge_state) in dw_hdmi_i2c_unwedge()
302 dev_info(hdmi->dev, "Attempting to unwedge stuck i2c bus\n"); in dw_hdmi_i2c_unwedge()
336 pinctrl_select_state(hdmi->pinctrl, hdmi->unwedge_state); in dw_hdmi_i2c_unwedge()
338 pinctrl_select_state(hdmi->pinctrl, hdmi->default_state); in dw_hdmi_i2c_unwedge()
343 static int dw_hdmi_i2c_wait(struct dw_hdmi *hdmi) in dw_hdmi_i2c_wait() argument
345 struct dw_hdmi_i2c *i2c = hdmi->i2c; in dw_hdmi_i2c_wait()
351 if (!dw_hdmi_i2c_unwedge(hdmi)) in dw_hdmi_i2c_wait()
367 static int dw_hdmi_i2c_read(struct dw_hdmi *hdmi, in dw_hdmi_i2c_read() argument
370 struct dw_hdmi_i2c *i2c = hdmi->i2c; in dw_hdmi_i2c_read()
374 dev_dbg(hdmi->dev, "set read register address to 0\n"); in dw_hdmi_i2c_read()
382 hdmi_writeb(hdmi, i2c->slave_reg++, HDMI_I2CM_ADDRESS); in dw_hdmi_i2c_read()
384 hdmi_writeb(hdmi, HDMI_I2CM_OPERATION_READ_EXT, in dw_hdmi_i2c_read()
387 hdmi_writeb(hdmi, HDMI_I2CM_OPERATION_READ, in dw_hdmi_i2c_read()
390 ret = dw_hdmi_i2c_wait(hdmi); in dw_hdmi_i2c_read()
394 *buf++ = hdmi_readb(hdmi, HDMI_I2CM_DATAI); in dw_hdmi_i2c_read()
401 static int dw_hdmi_i2c_write(struct dw_hdmi *hdmi, in dw_hdmi_i2c_write() argument
404 struct dw_hdmi_i2c *i2c = hdmi->i2c; in dw_hdmi_i2c_write()
418 hdmi_writeb(hdmi, *buf++, HDMI_I2CM_DATAO); in dw_hdmi_i2c_write()
419 hdmi_writeb(hdmi, i2c->slave_reg++, HDMI_I2CM_ADDRESS); in dw_hdmi_i2c_write()
420 hdmi_writeb(hdmi, HDMI_I2CM_OPERATION_WRITE, in dw_hdmi_i2c_write()
423 ret = dw_hdmi_i2c_wait(hdmi); in dw_hdmi_i2c_write()
434 struct dw_hdmi *hdmi = i2c_get_adapdata(adap); in dw_hdmi_i2c_xfer() local
435 struct dw_hdmi_i2c *i2c = hdmi->i2c; in dw_hdmi_i2c_xfer()
448 dev_dbg(hdmi->dev, "xfer: num: %d, addr: %#x\n", num, addr); in dw_hdmi_i2c_xfer()
452 dev_dbg(hdmi->dev, in dw_hdmi_i2c_xfer()
462 hdmi_writeb(hdmi, 0x00, HDMI_IH_MUTE_I2CM_STAT0); in dw_hdmi_i2c_xfer()
465 hdmi_writeb(hdmi, addr, HDMI_I2CM_SLAVE); in dw_hdmi_i2c_xfer()
474 dev_dbg(hdmi->dev, "xfer: num: %d/%d, len: %d, flags: %#x\n", in dw_hdmi_i2c_xfer()
478 hdmi_writeb(hdmi, DDC_SEGMENT_ADDR, HDMI_I2CM_SEGADDR); in dw_hdmi_i2c_xfer()
479 hdmi_writeb(hdmi, *msgs[i].buf, HDMI_I2CM_SEGPTR); in dw_hdmi_i2c_xfer()
482 ret = dw_hdmi_i2c_read(hdmi, msgs[i].buf, in dw_hdmi_i2c_xfer()
485 ret = dw_hdmi_i2c_write(hdmi, msgs[i].buf, in dw_hdmi_i2c_xfer()
496 hdmi_writeb(hdmi, HDMI_IH_I2CM_STAT0_ERROR | HDMI_IH_I2CM_STAT0_DONE, in dw_hdmi_i2c_xfer()
514 static struct i2c_adapter *dw_hdmi_i2c_adapter(struct dw_hdmi *hdmi) in dw_hdmi_i2c_adapter() argument
520 i2c = devm_kzalloc(hdmi->dev, sizeof(*i2c), GFP_KERNEL); in dw_hdmi_i2c_adapter()
530 adap->dev.parent = hdmi->dev; in dw_hdmi_i2c_adapter()
533 i2c_set_adapdata(adap, hdmi); in dw_hdmi_i2c_adapter()
537 dev_warn(hdmi->dev, "cannot add %s I2C adapter\n", adap->name); in dw_hdmi_i2c_adapter()
538 devm_kfree(hdmi->dev, i2c); in dw_hdmi_i2c_adapter()
542 hdmi->i2c = i2c; in dw_hdmi_i2c_adapter()
544 dev_info(hdmi->dev, "registered %s I2C bus driver\n", adap->name); in dw_hdmi_i2c_adapter()
549 static void hdmi_set_cts_n(struct dw_hdmi *hdmi, unsigned int cts, in hdmi_set_cts_n() argument
553 hdmi_modb(hdmi, 0, HDMI_AUD_CTS3_CTS_MANUAL, HDMI_AUD_CTS3); in hdmi_set_cts_n()
556 hdmi_modb(hdmi, 0, HDMI_AUD_CTS3_N_SHIFT_MASK, HDMI_AUD_CTS3); in hdmi_set_cts_n()
560 hdmi_writeb(hdmi, ((cts >> 16) & in hdmi_set_cts_n()
565 hdmi_writeb(hdmi, 0, HDMI_AUD_CTS3); in hdmi_set_cts_n()
566 hdmi_writeb(hdmi, (cts >> 8) & 0xff, HDMI_AUD_CTS2); in hdmi_set_cts_n()
567 hdmi_writeb(hdmi, cts & 0xff, HDMI_AUD_CTS1); in hdmi_set_cts_n()
569 hdmi_writeb(hdmi, (n >> 16) & 0x0f, HDMI_AUD_N3); in hdmi_set_cts_n()
570 hdmi_writeb(hdmi, (n >> 8) & 0xff, HDMI_AUD_N2); in hdmi_set_cts_n()
571 hdmi_writeb(hdmi, n & 0xff, HDMI_AUD_N1); in hdmi_set_cts_n()
638 void dw_hdmi_set_channel_status(struct dw_hdmi *hdmi, in dw_hdmi_set_channel_status() argument
645 hdmi_writeb(hdmi, channel_status[3], HDMI_FC_AUDSCHNLS7); in dw_hdmi_set_channel_status()
646 hdmi_writeb(hdmi, channel_status[4], HDMI_FC_AUDSCHNLS8); in dw_hdmi_set_channel_status()
650 static void hdmi_set_clk_regenerator(struct dw_hdmi *hdmi, in hdmi_set_clk_regenerator() argument
660 config3 = hdmi_readb(hdmi, HDMI_CONFIG3_ID); in hdmi_set_clk_regenerator()
675 dev_dbg(hdmi->dev, "%s: fs=%uHz ftdms=%lu.%03luMHz N=%d cts=%d\n", in hdmi_set_clk_regenerator()
683 spin_lock_irq(&hdmi->audio_lock); in hdmi_set_clk_regenerator()
684 hdmi->audio_n = n; in hdmi_set_clk_regenerator()
685 hdmi->audio_cts = cts; in hdmi_set_clk_regenerator()
686 hdmi_set_cts_n(hdmi, cts, hdmi->audio_enable ? n : 0); in hdmi_set_clk_regenerator()
687 spin_unlock_irq(&hdmi->audio_lock); in hdmi_set_clk_regenerator()
690 static void hdmi_init_clk_regenerator(struct dw_hdmi *hdmi) in hdmi_init_clk_regenerator() argument
692 mutex_lock(&hdmi->audio_mutex); in hdmi_init_clk_regenerator()
693 hdmi_set_clk_regenerator(hdmi, 74250000, hdmi->sample_rate); in hdmi_init_clk_regenerator()
694 mutex_unlock(&hdmi->audio_mutex); in hdmi_init_clk_regenerator()
697 static void hdmi_clk_regenerator_update_pixel_clock(struct dw_hdmi *hdmi) in hdmi_clk_regenerator_update_pixel_clock() argument
699 mutex_lock(&hdmi->audio_mutex); in hdmi_clk_regenerator_update_pixel_clock()
700 hdmi_set_clk_regenerator(hdmi, hdmi->hdmi_data.video_mode.mtmdsclock, in hdmi_clk_regenerator_update_pixel_clock()
701 hdmi->sample_rate); in hdmi_clk_regenerator_update_pixel_clock()
702 mutex_unlock(&hdmi->audio_mutex); in hdmi_clk_regenerator_update_pixel_clock()
705 void dw_hdmi_set_sample_rate(struct dw_hdmi *hdmi, unsigned int rate) in dw_hdmi_set_sample_rate() argument
707 mutex_lock(&hdmi->audio_mutex); in dw_hdmi_set_sample_rate()
708 hdmi->sample_rate = rate; in dw_hdmi_set_sample_rate()
709 hdmi_set_clk_regenerator(hdmi, hdmi->hdmi_data.video_mode.mtmdsclock, in dw_hdmi_set_sample_rate()
710 hdmi->sample_rate); in dw_hdmi_set_sample_rate()
711 mutex_unlock(&hdmi->audio_mutex); in dw_hdmi_set_sample_rate()
715 void dw_hdmi_set_channel_count(struct dw_hdmi *hdmi, unsigned int cnt) in dw_hdmi_set_channel_count() argument
719 mutex_lock(&hdmi->audio_mutex); in dw_hdmi_set_channel_count()
730 hdmi_modb(hdmi, layout, HDMI_FC_AUDSCONF_AUD_PACKET_LAYOUT_MASK, in dw_hdmi_set_channel_count()
734 hdmi_modb(hdmi, (cnt - 1) << HDMI_FC_AUDICONF0_CC_OFFSET, in dw_hdmi_set_channel_count()
737 mutex_unlock(&hdmi->audio_mutex); in dw_hdmi_set_channel_count()
741 void dw_hdmi_set_channel_allocation(struct dw_hdmi *hdmi, unsigned int ca) in dw_hdmi_set_channel_allocation() argument
743 mutex_lock(&hdmi->audio_mutex); in dw_hdmi_set_channel_allocation()
745 hdmi_writeb(hdmi, ca, HDMI_FC_AUDICONF2); in dw_hdmi_set_channel_allocation()
747 mutex_unlock(&hdmi->audio_mutex); in dw_hdmi_set_channel_allocation()
751 static void hdmi_enable_audio_clk(struct dw_hdmi *hdmi, bool enable) in hdmi_enable_audio_clk() argument
754 hdmi->mc_clkdis &= ~HDMI_MC_CLKDIS_AUDCLK_DISABLE; in hdmi_enable_audio_clk()
756 hdmi->mc_clkdis |= HDMI_MC_CLKDIS_AUDCLK_DISABLE; in hdmi_enable_audio_clk()
757 hdmi_writeb(hdmi, hdmi->mc_clkdis, HDMI_MC_CLKDIS); in hdmi_enable_audio_clk()
760 static u8 *hdmi_audio_get_eld(struct dw_hdmi *hdmi) in hdmi_audio_get_eld() argument
762 if (!hdmi->curr_conn) in hdmi_audio_get_eld()
765 return hdmi->curr_conn->eld; in hdmi_audio_get_eld()
768 static void dw_hdmi_ahb_audio_enable(struct dw_hdmi *hdmi) in dw_hdmi_ahb_audio_enable() argument
770 hdmi_set_cts_n(hdmi, hdmi->audio_cts, hdmi->audio_n); in dw_hdmi_ahb_audio_enable()
773 static void dw_hdmi_ahb_audio_disable(struct dw_hdmi *hdmi) in dw_hdmi_ahb_audio_disable() argument
775 hdmi_set_cts_n(hdmi, hdmi->audio_cts, 0); in dw_hdmi_ahb_audio_disable()
778 static void dw_hdmi_i2s_audio_enable(struct dw_hdmi *hdmi) in dw_hdmi_i2s_audio_enable() argument
780 hdmi_set_cts_n(hdmi, hdmi->audio_cts, hdmi->audio_n); in dw_hdmi_i2s_audio_enable()
781 hdmi_enable_audio_clk(hdmi, true); in dw_hdmi_i2s_audio_enable()
784 static void dw_hdmi_i2s_audio_disable(struct dw_hdmi *hdmi) in dw_hdmi_i2s_audio_disable() argument
786 hdmi_enable_audio_clk(hdmi, false); in dw_hdmi_i2s_audio_disable()
789 void dw_hdmi_audio_enable(struct dw_hdmi *hdmi) in dw_hdmi_audio_enable() argument
793 spin_lock_irqsave(&hdmi->audio_lock, flags); in dw_hdmi_audio_enable()
794 hdmi->audio_enable = true; in dw_hdmi_audio_enable()
795 if (hdmi->enable_audio) in dw_hdmi_audio_enable()
796 hdmi->enable_audio(hdmi); in dw_hdmi_audio_enable()
797 spin_unlock_irqrestore(&hdmi->audio_lock, flags); in dw_hdmi_audio_enable()
801 void dw_hdmi_audio_disable(struct dw_hdmi *hdmi) in dw_hdmi_audio_disable() argument
805 spin_lock_irqsave(&hdmi->audio_lock, flags); in dw_hdmi_audio_disable()
806 hdmi->audio_enable = false; in dw_hdmi_audio_disable()
807 if (hdmi->disable_audio) in dw_hdmi_audio_disable()
808 hdmi->disable_audio(hdmi); in dw_hdmi_audio_disable()
809 spin_unlock_irqrestore(&hdmi->audio_lock, flags); in dw_hdmi_audio_disable()
906 static void hdmi_video_sample(struct dw_hdmi *hdmi) in hdmi_video_sample() argument
911 switch (hdmi->hdmi_data.enc_in_bus_format) { in hdmi_video_sample()
959 hdmi_writeb(hdmi, val, HDMI_TX_INVID0); in hdmi_video_sample()
965 hdmi_writeb(hdmi, val, HDMI_TX_INSTUFFING); in hdmi_video_sample()
966 hdmi_writeb(hdmi, 0x0, HDMI_TX_GYDATA0); in hdmi_video_sample()
967 hdmi_writeb(hdmi, 0x0, HDMI_TX_GYDATA1); in hdmi_video_sample()
968 hdmi_writeb(hdmi, 0x0, HDMI_TX_RCRDATA0); in hdmi_video_sample()
969 hdmi_writeb(hdmi, 0x0, HDMI_TX_RCRDATA1); in hdmi_video_sample()
970 hdmi_writeb(hdmi, 0x0, HDMI_TX_BCBDATA0); in hdmi_video_sample()
971 hdmi_writeb(hdmi, 0x0, HDMI_TX_BCBDATA1); in hdmi_video_sample()
974 static int is_color_space_conversion(struct dw_hdmi *hdmi) in is_color_space_conversion() argument
976 struct hdmi_data_info *hdmi_data = &hdmi->hdmi_data; in is_color_space_conversion()
986 static int is_color_space_decimation(struct dw_hdmi *hdmi) in is_color_space_decimation() argument
988 if (!hdmi_bus_fmt_is_yuv422(hdmi->hdmi_data.enc_out_bus_format)) in is_color_space_decimation()
991 if (hdmi_bus_fmt_is_rgb(hdmi->hdmi_data.enc_in_bus_format) || in is_color_space_decimation()
992 hdmi_bus_fmt_is_yuv444(hdmi->hdmi_data.enc_in_bus_format)) in is_color_space_decimation()
998 static int is_color_space_interpolation(struct dw_hdmi *hdmi) in is_color_space_interpolation() argument
1000 if (!hdmi_bus_fmt_is_yuv422(hdmi->hdmi_data.enc_in_bus_format)) in is_color_space_interpolation()
1003 if (hdmi_bus_fmt_is_rgb(hdmi->hdmi_data.enc_out_bus_format) || in is_color_space_interpolation()
1004 hdmi_bus_fmt_is_yuv444(hdmi->hdmi_data.enc_out_bus_format)) in is_color_space_interpolation()
1010 static bool is_csc_needed(struct dw_hdmi *hdmi) in is_csc_needed() argument
1012 return is_color_space_conversion(hdmi) || in is_csc_needed()
1013 is_color_space_decimation(hdmi) || in is_csc_needed()
1014 is_color_space_interpolation(hdmi); in is_csc_needed()
1017 static void dw_hdmi_update_csc_coeffs(struct dw_hdmi *hdmi) in dw_hdmi_update_csc_coeffs() argument
1024 is_input_rgb = hdmi_bus_fmt_is_rgb(hdmi->hdmi_data.enc_in_bus_format); in dw_hdmi_update_csc_coeffs()
1025 is_output_rgb = hdmi_bus_fmt_is_rgb(hdmi->hdmi_data.enc_out_bus_format); in dw_hdmi_update_csc_coeffs()
1028 if (hdmi->hdmi_data.enc_out_encoding == V4L2_YCBCR_ENC_601) in dw_hdmi_update_csc_coeffs()
1033 if (hdmi->hdmi_data.enc_out_encoding == V4L2_YCBCR_ENC_601) in dw_hdmi_update_csc_coeffs()
1039 hdmi->hdmi_data.rgb_limited_range) { in dw_hdmi_update_csc_coeffs()
1049 hdmi_writeb(hdmi, coeff_a & 0xff, HDMI_CSC_COEF_A1_LSB + i * 2); in dw_hdmi_update_csc_coeffs()
1050 hdmi_writeb(hdmi, coeff_a >> 8, HDMI_CSC_COEF_A1_MSB + i * 2); in dw_hdmi_update_csc_coeffs()
1051 hdmi_writeb(hdmi, coeff_b & 0xff, HDMI_CSC_COEF_B1_LSB + i * 2); in dw_hdmi_update_csc_coeffs()
1052 hdmi_writeb(hdmi, coeff_b >> 8, HDMI_CSC_COEF_B1_MSB + i * 2); in dw_hdmi_update_csc_coeffs()
1053 hdmi_writeb(hdmi, coeff_c & 0xff, HDMI_CSC_COEF_C1_LSB + i * 2); in dw_hdmi_update_csc_coeffs()
1054 hdmi_writeb(hdmi, coeff_c >> 8, HDMI_CSC_COEF_C1_MSB + i * 2); in dw_hdmi_update_csc_coeffs()
1057 hdmi_modb(hdmi, csc_scale, HDMI_CSC_SCALE_CSCSCALE_MASK, in dw_hdmi_update_csc_coeffs()
1061 static void hdmi_video_csc(struct dw_hdmi *hdmi) in hdmi_video_csc() argument
1068 if (is_color_space_interpolation(hdmi)) in hdmi_video_csc()
1070 else if (is_color_space_decimation(hdmi)) in hdmi_video_csc()
1073 switch (hdmi_bus_fmt_color_depth(hdmi->hdmi_data.enc_out_bus_format)) { in hdmi_video_csc()
1092 hdmi_writeb(hdmi, interpolation | decimation, HDMI_CSC_CFG); in hdmi_video_csc()
1093 hdmi_modb(hdmi, color_depth, HDMI_CSC_SCALE_CSC_COLORDE_PTH_MASK, in hdmi_video_csc()
1096 dw_hdmi_update_csc_coeffs(hdmi); in hdmi_video_csc()
1104 static void hdmi_video_packetize(struct dw_hdmi *hdmi) in hdmi_video_packetize() argument
1109 struct hdmi_data_info *hdmi_data = &hdmi->hdmi_data; in hdmi_video_packetize()
1112 if (hdmi_bus_fmt_is_rgb(hdmi->hdmi_data.enc_out_bus_format) || in hdmi_video_packetize()
1113 hdmi_bus_fmt_is_yuv444(hdmi->hdmi_data.enc_out_bus_format) || in hdmi_video_packetize()
1114 hdmi_bus_fmt_is_yuv420(hdmi->hdmi_data.enc_out_bus_format)) { in hdmi_video_packetize()
1116 hdmi->hdmi_data.enc_out_bus_format)) { in hdmi_video_packetize()
1133 } else if (hdmi_bus_fmt_is_yuv422(hdmi->hdmi_data.enc_out_bus_format)) { in hdmi_video_packetize()
1135 hdmi->hdmi_data.enc_out_bus_format)) { in hdmi_video_packetize()
1161 hdmi_writeb(hdmi, val, HDMI_VP_PR_CD); in hdmi_video_packetize()
1163 hdmi_modb(hdmi, HDMI_VP_STUFF_PR_STUFFING_STUFFING_MODE, in hdmi_video_packetize()
1175 hdmi_modb(hdmi, vp_conf, in hdmi_video_packetize()
1179 hdmi_modb(hdmi, 1 << HDMI_VP_STUFF_IDEFAULT_PHASE_OFFSET, in hdmi_video_packetize()
1182 hdmi_writeb(hdmi, remap_size, HDMI_VP_REMAP); in hdmi_video_packetize()
1200 hdmi_modb(hdmi, vp_conf, in hdmi_video_packetize()
1204 hdmi_modb(hdmi, HDMI_VP_STUFF_PP_STUFFING_STUFFING_MODE | in hdmi_video_packetize()
1209 hdmi_modb(hdmi, output_select, HDMI_VP_CONF_OUTPUT_SELECTOR_MASK, in hdmi_video_packetize()
1217 static inline void hdmi_phy_test_clear(struct dw_hdmi *hdmi, in hdmi_phy_test_clear() argument
1220 hdmi_modb(hdmi, bit << HDMI_PHY_TST0_TSTCLR_OFFSET, in hdmi_phy_test_clear()
1224 static bool hdmi_phy_wait_i2c_done(struct dw_hdmi *hdmi, int msec) in hdmi_phy_wait_i2c_done() argument
1228 while ((val = hdmi_readb(hdmi, HDMI_IH_I2CMPHY_STAT0) & 0x3) == 0) { in hdmi_phy_wait_i2c_done()
1233 hdmi_writeb(hdmi, val, HDMI_IH_I2CMPHY_STAT0); in hdmi_phy_wait_i2c_done()
1238 void dw_hdmi_phy_i2c_write(struct dw_hdmi *hdmi, unsigned short data, in dw_hdmi_phy_i2c_write() argument
1241 hdmi_writeb(hdmi, 0xFF, HDMI_IH_I2CMPHY_STAT0); in dw_hdmi_phy_i2c_write()
1242 hdmi_writeb(hdmi, addr, HDMI_PHY_I2CM_ADDRESS_ADDR); in dw_hdmi_phy_i2c_write()
1243 hdmi_writeb(hdmi, (unsigned char)(data >> 8), in dw_hdmi_phy_i2c_write()
1245 hdmi_writeb(hdmi, (unsigned char)(data >> 0), in dw_hdmi_phy_i2c_write()
1247 hdmi_writeb(hdmi, HDMI_PHY_I2CM_OPERATION_ADDR_WRITE, in dw_hdmi_phy_i2c_write()
1249 hdmi_phy_wait_i2c_done(hdmi, 1000); in dw_hdmi_phy_i2c_write()
1254 static bool dw_hdmi_support_scdc(struct dw_hdmi *hdmi, in dw_hdmi_support_scdc() argument
1258 if (hdmi->version < 0x200a) in dw_hdmi_support_scdc()
1262 if (!hdmi->ddc) in dw_hdmi_support_scdc()
1266 if (!display->hdmi.scdc.supported || in dw_hdmi_support_scdc()
1267 !display->hdmi.scdc.scrambling.supported) in dw_hdmi_support_scdc()
1274 if (!display->hdmi.scdc.scrambling.low_rates && in dw_hdmi_support_scdc()
1294 void dw_hdmi_set_high_tmds_clock_ratio(struct dw_hdmi *hdmi, in dw_hdmi_set_high_tmds_clock_ratio() argument
1297 unsigned long mtmdsclock = hdmi->hdmi_data.video_mode.mtmdsclock; in dw_hdmi_set_high_tmds_clock_ratio()
1300 if (dw_hdmi_support_scdc(hdmi, display)) { in dw_hdmi_set_high_tmds_clock_ratio()
1302 drm_scdc_set_high_tmds_clock_ratio(hdmi->ddc, 1); in dw_hdmi_set_high_tmds_clock_ratio()
1304 drm_scdc_set_high_tmds_clock_ratio(hdmi->ddc, 0); in dw_hdmi_set_high_tmds_clock_ratio()
1309 static void dw_hdmi_phy_enable_powerdown(struct dw_hdmi *hdmi, bool enable) in dw_hdmi_phy_enable_powerdown() argument
1311 hdmi_mask_writeb(hdmi, !enable, HDMI_PHY_CONF0, in dw_hdmi_phy_enable_powerdown()
1316 static void dw_hdmi_phy_enable_tmds(struct dw_hdmi *hdmi, u8 enable) in dw_hdmi_phy_enable_tmds() argument
1318 hdmi_mask_writeb(hdmi, enable, HDMI_PHY_CONF0, in dw_hdmi_phy_enable_tmds()
1323 static void dw_hdmi_phy_enable_svsret(struct dw_hdmi *hdmi, u8 enable) in dw_hdmi_phy_enable_svsret() argument
1325 hdmi_mask_writeb(hdmi, enable, HDMI_PHY_CONF0, in dw_hdmi_phy_enable_svsret()
1330 void dw_hdmi_phy_gen2_pddq(struct dw_hdmi *hdmi, u8 enable) in dw_hdmi_phy_gen2_pddq() argument
1332 hdmi_mask_writeb(hdmi, enable, HDMI_PHY_CONF0, in dw_hdmi_phy_gen2_pddq()
1338 void dw_hdmi_phy_gen2_txpwron(struct dw_hdmi *hdmi, u8 enable) in dw_hdmi_phy_gen2_txpwron() argument
1340 hdmi_mask_writeb(hdmi, enable, HDMI_PHY_CONF0, in dw_hdmi_phy_gen2_txpwron()
1346 static void dw_hdmi_phy_sel_data_en_pol(struct dw_hdmi *hdmi, u8 enable) in dw_hdmi_phy_sel_data_en_pol() argument
1348 hdmi_mask_writeb(hdmi, enable, HDMI_PHY_CONF0, in dw_hdmi_phy_sel_data_en_pol()
1353 static void dw_hdmi_phy_sel_interface_control(struct dw_hdmi *hdmi, u8 enable) in dw_hdmi_phy_sel_interface_control() argument
1355 hdmi_mask_writeb(hdmi, enable, HDMI_PHY_CONF0, in dw_hdmi_phy_sel_interface_control()
1360 void dw_hdmi_phy_reset(struct dw_hdmi *hdmi) in dw_hdmi_phy_reset() argument
1363 hdmi_writeb(hdmi, HDMI_MC_PHYRSTZ_PHYRSTZ, HDMI_MC_PHYRSTZ); in dw_hdmi_phy_reset()
1364 hdmi_writeb(hdmi, 0, HDMI_MC_PHYRSTZ); in dw_hdmi_phy_reset()
1368 void dw_hdmi_phy_i2c_set_addr(struct dw_hdmi *hdmi, u8 address) in dw_hdmi_phy_i2c_set_addr() argument
1370 hdmi_phy_test_clear(hdmi, 1); in dw_hdmi_phy_i2c_set_addr()
1371 hdmi_writeb(hdmi, address, HDMI_PHY_I2CM_SLAVE_ADDR); in dw_hdmi_phy_i2c_set_addr()
1372 hdmi_phy_test_clear(hdmi, 0); in dw_hdmi_phy_i2c_set_addr()
1376 static void dw_hdmi_phy_power_off(struct dw_hdmi *hdmi) in dw_hdmi_phy_power_off() argument
1378 const struct dw_hdmi_phy_data *phy = hdmi->phy.data; in dw_hdmi_phy_power_off()
1383 dw_hdmi_phy_enable_tmds(hdmi, 0); in dw_hdmi_phy_power_off()
1384 dw_hdmi_phy_enable_powerdown(hdmi, true); in dw_hdmi_phy_power_off()
1388 dw_hdmi_phy_gen2_txpwron(hdmi, 0); in dw_hdmi_phy_power_off()
1395 val = hdmi_readb(hdmi, HDMI_PHY_STAT0); in dw_hdmi_phy_power_off()
1403 dev_warn(hdmi->dev, "PHY failed to power down\n"); in dw_hdmi_phy_power_off()
1405 dev_dbg(hdmi->dev, "PHY powered down in %u iterations\n", i); in dw_hdmi_phy_power_off()
1407 dw_hdmi_phy_gen2_pddq(hdmi, 1); in dw_hdmi_phy_power_off()
1410 static int dw_hdmi_phy_power_on(struct dw_hdmi *hdmi) in dw_hdmi_phy_power_on() argument
1412 const struct dw_hdmi_phy_data *phy = hdmi->phy.data; in dw_hdmi_phy_power_on()
1417 dw_hdmi_phy_enable_powerdown(hdmi, false); in dw_hdmi_phy_power_on()
1420 dw_hdmi_phy_enable_tmds(hdmi, 0); in dw_hdmi_phy_power_on()
1421 dw_hdmi_phy_enable_tmds(hdmi, 1); in dw_hdmi_phy_power_on()
1425 dw_hdmi_phy_gen2_txpwron(hdmi, 1); in dw_hdmi_phy_power_on()
1426 dw_hdmi_phy_gen2_pddq(hdmi, 0); in dw_hdmi_phy_power_on()
1430 val = hdmi_readb(hdmi, HDMI_PHY_STAT0) & HDMI_PHY_TX_PHY_LOCK; in dw_hdmi_phy_power_on()
1438 dev_err(hdmi->dev, "PHY PLL failed to lock\n"); in dw_hdmi_phy_power_on()
1442 dev_dbg(hdmi->dev, "PHY PLL locked %u iterations\n", i); in dw_hdmi_phy_power_on()
1451 static int hdmi_phy_configure_dwc_hdmi_3d_tx(struct dw_hdmi *hdmi, in hdmi_phy_configure_dwc_hdmi_3d_tx() argument
1479 dw_hdmi_phy_i2c_write(hdmi, mpll_config->res[0].cpce, in hdmi_phy_configure_dwc_hdmi_3d_tx()
1481 dw_hdmi_phy_i2c_write(hdmi, mpll_config->res[0].gmp, in hdmi_phy_configure_dwc_hdmi_3d_tx()
1483 dw_hdmi_phy_i2c_write(hdmi, curr_ctrl->curr[0], in hdmi_phy_configure_dwc_hdmi_3d_tx()
1486 dw_hdmi_phy_i2c_write(hdmi, 0, HDMI_3D_TX_PHY_PLLPHBYCTRL); in hdmi_phy_configure_dwc_hdmi_3d_tx()
1487 dw_hdmi_phy_i2c_write(hdmi, HDMI_3D_TX_PHY_MSM_CTRL_CKO_SEL_FB_CLK, in hdmi_phy_configure_dwc_hdmi_3d_tx()
1490 dw_hdmi_phy_i2c_write(hdmi, phy_config->term, HDMI_3D_TX_PHY_TXTERM); in hdmi_phy_configure_dwc_hdmi_3d_tx()
1491 dw_hdmi_phy_i2c_write(hdmi, phy_config->sym_ctr, in hdmi_phy_configure_dwc_hdmi_3d_tx()
1493 dw_hdmi_phy_i2c_write(hdmi, phy_config->vlev_ctr, in hdmi_phy_configure_dwc_hdmi_3d_tx()
1497 dw_hdmi_phy_i2c_write(hdmi, HDMI_3D_TX_PHY_CKCALCTRL_OVERRIDE, in hdmi_phy_configure_dwc_hdmi_3d_tx()
1503 static int hdmi_phy_configure(struct dw_hdmi *hdmi, in hdmi_phy_configure() argument
1506 const struct dw_hdmi_phy_data *phy = hdmi->phy.data; in hdmi_phy_configure()
1507 const struct dw_hdmi_plat_data *pdata = hdmi->plat_data; in hdmi_phy_configure()
1508 unsigned long mpixelclock = hdmi->hdmi_data.video_mode.mpixelclock; in hdmi_phy_configure()
1509 unsigned long mtmdsclock = hdmi->hdmi_data.video_mode.mtmdsclock; in hdmi_phy_configure()
1512 dw_hdmi_phy_power_off(hdmi); in hdmi_phy_configure()
1514 dw_hdmi_set_high_tmds_clock_ratio(hdmi, display); in hdmi_phy_configure()
1518 dw_hdmi_phy_enable_svsret(hdmi, 1); in hdmi_phy_configure()
1520 dw_hdmi_phy_reset(hdmi); in hdmi_phy_configure()
1522 hdmi_writeb(hdmi, HDMI_MC_HEACPHY_RST_ASSERT, HDMI_MC_HEACPHY_RST); in hdmi_phy_configure()
1524 dw_hdmi_phy_i2c_set_addr(hdmi, HDMI_PHY_I2CM_SLAVE_ADDR_PHY_GEN2); in hdmi_phy_configure()
1528 ret = pdata->configure_phy(hdmi, pdata->priv_data, mpixelclock); in hdmi_phy_configure()
1530 ret = phy->configure(hdmi, pdata, mpixelclock); in hdmi_phy_configure()
1532 dev_err(hdmi->dev, "PHY configuration failed (clock %lu)\n", in hdmi_phy_configure()
1541 return dw_hdmi_phy_power_on(hdmi); in hdmi_phy_configure()
1544 static int dw_hdmi_phy_init(struct dw_hdmi *hdmi, void *data, in dw_hdmi_phy_init() argument
1552 dw_hdmi_phy_sel_data_en_pol(hdmi, 1); in dw_hdmi_phy_init()
1553 dw_hdmi_phy_sel_interface_control(hdmi, 0); in dw_hdmi_phy_init()
1555 ret = hdmi_phy_configure(hdmi, display); in dw_hdmi_phy_init()
1563 static void dw_hdmi_phy_disable(struct dw_hdmi *hdmi, void *data) in dw_hdmi_phy_disable() argument
1565 dw_hdmi_phy_power_off(hdmi); in dw_hdmi_phy_disable()
1568 enum drm_connector_status dw_hdmi_phy_read_hpd(struct dw_hdmi *hdmi, in dw_hdmi_phy_read_hpd() argument
1571 return hdmi_readb(hdmi, HDMI_PHY_STAT0) & HDMI_PHY_HPD ? in dw_hdmi_phy_read_hpd()
1576 void dw_hdmi_phy_update_hpd(struct dw_hdmi *hdmi, void *data, in dw_hdmi_phy_update_hpd() argument
1579 u8 old_mask = hdmi->phy_mask; in dw_hdmi_phy_update_hpd()
1582 hdmi->phy_mask |= HDMI_PHY_RX_SENSE; in dw_hdmi_phy_update_hpd()
1584 hdmi->phy_mask &= ~HDMI_PHY_RX_SENSE; in dw_hdmi_phy_update_hpd()
1586 if (old_mask != hdmi->phy_mask) in dw_hdmi_phy_update_hpd()
1587 hdmi_writeb(hdmi, hdmi->phy_mask, HDMI_PHY_MASK0); in dw_hdmi_phy_update_hpd()
1591 void dw_hdmi_phy_setup_hpd(struct dw_hdmi *hdmi, void *data) in dw_hdmi_phy_setup_hpd() argument
1597 hdmi_writeb(hdmi, HDMI_PHY_HPD | HDMI_PHY_RX_SENSE, HDMI_PHY_POL0); in dw_hdmi_phy_setup_hpd()
1598 hdmi_writeb(hdmi, HDMI_IH_PHY_STAT0_HPD | HDMI_IH_PHY_STAT0_RX_SENSE, in dw_hdmi_phy_setup_hpd()
1602 hdmi_writeb(hdmi, hdmi->phy_mask, HDMI_PHY_MASK0); in dw_hdmi_phy_setup_hpd()
1605 hdmi_writeb(hdmi, HDMI_IH_PHY_STAT0_HPD | HDMI_IH_PHY_STAT0_RX_SENSE, in dw_hdmi_phy_setup_hpd()
1607 hdmi_writeb(hdmi, ~(HDMI_IH_PHY_STAT0_HPD | HDMI_IH_PHY_STAT0_RX_SENSE), in dw_hdmi_phy_setup_hpd()
1624 static void hdmi_tx_hdcp_config(struct dw_hdmi *hdmi) in hdmi_tx_hdcp_config() argument
1628 if (hdmi->hdmi_data.video_mode.mdataenablepolarity) in hdmi_tx_hdcp_config()
1634 hdmi_modb(hdmi, HDMI_A_HDCPCFG0_RXDETECT_DISABLE, in hdmi_tx_hdcp_config()
1637 hdmi_modb(hdmi, de, HDMI_A_VIDPOLCFG_DATAENPOL_MASK, HDMI_A_VIDPOLCFG); in hdmi_tx_hdcp_config()
1639 hdmi_modb(hdmi, HDMI_A_HDCPCFG1_ENCRYPTIONDISABLE_DISABLE, in hdmi_tx_hdcp_config()
1643 static void hdmi_config_AVI(struct dw_hdmi *hdmi, in hdmi_config_AVI() argument
1653 if (hdmi_bus_fmt_is_rgb(hdmi->hdmi_data.enc_out_bus_format)) { in hdmi_config_AVI()
1655 hdmi->hdmi_data.rgb_limited_range ? in hdmi_config_AVI()
1664 if (hdmi_bus_fmt_is_yuv444(hdmi->hdmi_data.enc_out_bus_format)) in hdmi_config_AVI()
1666 else if (hdmi_bus_fmt_is_yuv422(hdmi->hdmi_data.enc_out_bus_format)) in hdmi_config_AVI()
1668 else if (hdmi_bus_fmt_is_yuv420(hdmi->hdmi_data.enc_out_bus_format)) in hdmi_config_AVI()
1674 if (!hdmi_bus_fmt_is_rgb(hdmi->hdmi_data.enc_out_bus_format)) { in hdmi_config_AVI()
1675 switch (hdmi->hdmi_data.enc_out_encoding) { in hdmi_config_AVI()
1677 if (hdmi->hdmi_data.enc_in_encoding == V4L2_YCBCR_ENC_XV601) in hdmi_config_AVI()
1685 if (hdmi->hdmi_data.enc_in_encoding == V4L2_YCBCR_ENC_XV709) in hdmi_config_AVI()
1722 hdmi_writeb(hdmi, val, HDMI_FC_AVICONF0); in hdmi_config_AVI()
1728 hdmi_writeb(hdmi, val, HDMI_FC_AVICONF1); in hdmi_config_AVI()
1736 hdmi_writeb(hdmi, val, HDMI_FC_AVICONF2); in hdmi_config_AVI()
1740 hdmi_writeb(hdmi, val, HDMI_FC_AVIVID); in hdmi_config_AVI()
1743 val = (((hdmi->hdmi_data.video_mode.mpixelrepetitioninput + 1) << in hdmi_config_AVI()
1746 ((hdmi->hdmi_data.video_mode.mpixelrepetitionoutput << in hdmi_config_AVI()
1749 hdmi_writeb(hdmi, val, HDMI_FC_PRCONF); in hdmi_config_AVI()
1757 hdmi_writeb(hdmi, val, HDMI_FC_AVICONF3); in hdmi_config_AVI()
1760 hdmi_writeb(hdmi, frame.top_bar & 0xff, HDMI_FC_AVIETB0); in hdmi_config_AVI()
1761 hdmi_writeb(hdmi, (frame.top_bar >> 8) & 0xff, HDMI_FC_AVIETB1); in hdmi_config_AVI()
1762 hdmi_writeb(hdmi, frame.bottom_bar & 0xff, HDMI_FC_AVISBB0); in hdmi_config_AVI()
1763 hdmi_writeb(hdmi, (frame.bottom_bar >> 8) & 0xff, HDMI_FC_AVISBB1); in hdmi_config_AVI()
1764 hdmi_writeb(hdmi, frame.left_bar & 0xff, HDMI_FC_AVIELB0); in hdmi_config_AVI()
1765 hdmi_writeb(hdmi, (frame.left_bar >> 8) & 0xff, HDMI_FC_AVIELB1); in hdmi_config_AVI()
1766 hdmi_writeb(hdmi, frame.right_bar & 0xff, HDMI_FC_AVISRB0); in hdmi_config_AVI()
1767 hdmi_writeb(hdmi, (frame.right_bar >> 8) & 0xff, HDMI_FC_AVISRB1); in hdmi_config_AVI()
1770 static void hdmi_config_vendor_specific_infoframe(struct dw_hdmi *hdmi, in hdmi_config_vendor_specific_infoframe() argument
1791 dev_err(hdmi->dev, "Failed to pack vendor infoframe: %zd\n", in hdmi_config_vendor_specific_infoframe()
1795 hdmi_mask_writeb(hdmi, 0, HDMI_FC_DATAUTO0, HDMI_FC_DATAUTO0_VSD_OFFSET, in hdmi_config_vendor_specific_infoframe()
1799 hdmi_writeb(hdmi, buffer[2], HDMI_FC_VSDSIZE); in hdmi_config_vendor_specific_infoframe()
1802 hdmi_writeb(hdmi, buffer[4], HDMI_FC_VSDIEEEID0); in hdmi_config_vendor_specific_infoframe()
1803 hdmi_writeb(hdmi, buffer[5], HDMI_FC_VSDIEEEID1); in hdmi_config_vendor_specific_infoframe()
1804 hdmi_writeb(hdmi, buffer[6], HDMI_FC_VSDIEEEID2); in hdmi_config_vendor_specific_infoframe()
1807 hdmi_writeb(hdmi, buffer[7], HDMI_FC_VSDPAYLOAD0); in hdmi_config_vendor_specific_infoframe()
1808 hdmi_writeb(hdmi, buffer[8], HDMI_FC_VSDPAYLOAD1); in hdmi_config_vendor_specific_infoframe()
1811 hdmi_writeb(hdmi, buffer[9], HDMI_FC_VSDPAYLOAD2); in hdmi_config_vendor_specific_infoframe()
1814 hdmi_writeb(hdmi, 1, HDMI_FC_DATAUTO1); in hdmi_config_vendor_specific_infoframe()
1817 hdmi_writeb(hdmi, 0x11, HDMI_FC_DATAUTO2); in hdmi_config_vendor_specific_infoframe()
1820 hdmi_mask_writeb(hdmi, 1, HDMI_FC_DATAUTO0, HDMI_FC_DATAUTO0_VSD_OFFSET, in hdmi_config_vendor_specific_infoframe()
1824 static void hdmi_config_drm_infoframe(struct dw_hdmi *hdmi, in hdmi_config_drm_infoframe() argument
1833 if (!hdmi->plat_data->use_drm_infoframe) in hdmi_config_drm_infoframe()
1836 hdmi_modb(hdmi, HDMI_FC_PACKET_TX_EN_DRM_DISABLE, in hdmi_config_drm_infoframe()
1845 dev_err(hdmi->dev, "Failed to pack drm infoframe: %zd\n", err); in hdmi_config_drm_infoframe()
1849 hdmi_writeb(hdmi, frame.version, HDMI_FC_DRM_HB0); in hdmi_config_drm_infoframe()
1850 hdmi_writeb(hdmi, frame.length, HDMI_FC_DRM_HB1); in hdmi_config_drm_infoframe()
1853 hdmi_writeb(hdmi, buffer[4 + i], HDMI_FC_DRM_PB0 + i); in hdmi_config_drm_infoframe()
1855 hdmi_writeb(hdmi, 1, HDMI_FC_DRM_UP); in hdmi_config_drm_infoframe()
1856 hdmi_modb(hdmi, HDMI_FC_PACKET_TX_EN_DRM_ENABLE, in hdmi_config_drm_infoframe()
1860 static void hdmi_av_composer(struct dw_hdmi *hdmi, in hdmi_av_composer() argument
1865 const struct drm_hdmi_info *hdmi_info = &display->hdmi; in hdmi_av_composer()
1866 struct hdmi_vmode *vmode = &hdmi->hdmi_data.video_mode; in hdmi_av_composer()
1872 dev_dbg(hdmi->dev, "final pixclk = %d\n", vmode->mpixelclock); in hdmi_av_composer()
1876 if (!hdmi_bus_fmt_is_yuv422(hdmi->hdmi_data.enc_out_bus_format)) { in hdmi_av_composer()
1878 hdmi->hdmi_data.enc_out_bus_format)) { in hdmi_av_composer()
1891 if (hdmi_bus_fmt_is_yuv420(hdmi->hdmi_data.enc_out_bus_format)) in hdmi_av_composer()
1894 dev_dbg(hdmi->dev, "final tmdsclock = %d\n", vmode->mtmdsclock); in hdmi_av_composer()
1897 inv_val = (hdmi->hdmi_data.hdcp_enable || in hdmi_av_composer()
1898 (dw_hdmi_support_scdc(hdmi, display) && in hdmi_av_composer()
1916 if (hdmi->vic == 39) in hdmi_av_composer()
1927 inv_val |= hdmi->sink_is_hdmi ? in hdmi_av_composer()
1931 hdmi_writeb(hdmi, inv_val, HDMI_FC_INVIDCONF); in hdmi_av_composer()
1942 if (hdmi_bus_fmt_is_yuv420(hdmi->hdmi_data.enc_out_bus_format)) { in hdmi_av_composer()
1966 if (dw_hdmi_support_scdc(hdmi, display)) { in hdmi_av_composer()
1978 drm_scdc_readb(hdmi->ddc, SCDC_SINK_VERSION, in hdmi_av_composer()
1980 drm_scdc_writeb(hdmi->ddc, SCDC_SOURCE_VERSION, in hdmi_av_composer()
1984 drm_scdc_set_scrambling(hdmi->ddc, 1); in hdmi_av_composer()
1993 hdmi_writeb(hdmi, (u8)~HDMI_MC_SWRSTZ_TMDSSWRST_REQ, in hdmi_av_composer()
1995 hdmi_writeb(hdmi, 1, HDMI_FC_SCRAMBLER_CTRL); in hdmi_av_composer()
1997 hdmi_writeb(hdmi, 0, HDMI_FC_SCRAMBLER_CTRL); in hdmi_av_composer()
1998 hdmi_writeb(hdmi, (u8)~HDMI_MC_SWRSTZ_TMDSSWRST_REQ, in hdmi_av_composer()
2000 drm_scdc_set_scrambling(hdmi->ddc, 0); in hdmi_av_composer()
2005 hdmi_writeb(hdmi, hdisplay >> 8, HDMI_FC_INHACTV1); in hdmi_av_composer()
2006 hdmi_writeb(hdmi, hdisplay, HDMI_FC_INHACTV0); in hdmi_av_composer()
2009 hdmi_writeb(hdmi, vdisplay >> 8, HDMI_FC_INVACTV1); in hdmi_av_composer()
2010 hdmi_writeb(hdmi, vdisplay, HDMI_FC_INVACTV0); in hdmi_av_composer()
2013 hdmi_writeb(hdmi, hblank >> 8, HDMI_FC_INHBLANK1); in hdmi_av_composer()
2014 hdmi_writeb(hdmi, hblank, HDMI_FC_INHBLANK0); in hdmi_av_composer()
2017 hdmi_writeb(hdmi, vblank, HDMI_FC_INVBLANK); in hdmi_av_composer()
2020 hdmi_writeb(hdmi, h_de_hs >> 8, HDMI_FC_HSYNCINDELAY1); in hdmi_av_composer()
2021 hdmi_writeb(hdmi, h_de_hs, HDMI_FC_HSYNCINDELAY0); in hdmi_av_composer()
2024 hdmi_writeb(hdmi, v_de_vs, HDMI_FC_VSYNCINDELAY); in hdmi_av_composer()
2027 hdmi_writeb(hdmi, hsync_len >> 8, HDMI_FC_HSYNCINWIDTH1); in hdmi_av_composer()
2028 hdmi_writeb(hdmi, hsync_len, HDMI_FC_HSYNCINWIDTH0); in hdmi_av_composer()
2031 hdmi_writeb(hdmi, vsync_len, HDMI_FC_VSYNCINWIDTH); in hdmi_av_composer()
2035 static void dw_hdmi_enable_video_path(struct dw_hdmi *hdmi) in dw_hdmi_enable_video_path() argument
2038 hdmi_writeb(hdmi, 12, HDMI_FC_CTRLDUR); in dw_hdmi_enable_video_path()
2039 hdmi_writeb(hdmi, 32, HDMI_FC_EXCTRLDUR); in dw_hdmi_enable_video_path()
2040 hdmi_writeb(hdmi, 1, HDMI_FC_EXCTRLSPAC); in dw_hdmi_enable_video_path()
2043 hdmi_writeb(hdmi, 0x0B, HDMI_FC_CH0PREAM); in dw_hdmi_enable_video_path()
2044 hdmi_writeb(hdmi, 0x16, HDMI_FC_CH1PREAM); in dw_hdmi_enable_video_path()
2045 hdmi_writeb(hdmi, 0x21, HDMI_FC_CH2PREAM); in dw_hdmi_enable_video_path()
2048 hdmi->mc_clkdis |= HDMI_MC_CLKDIS_HDCPCLK_DISABLE | in dw_hdmi_enable_video_path()
2053 hdmi->mc_clkdis &= ~HDMI_MC_CLKDIS_PIXELCLK_DISABLE; in dw_hdmi_enable_video_path()
2054 hdmi_writeb(hdmi, hdmi->mc_clkdis, HDMI_MC_CLKDIS); in dw_hdmi_enable_video_path()
2056 hdmi->mc_clkdis &= ~HDMI_MC_CLKDIS_TMDSCLK_DISABLE; in dw_hdmi_enable_video_path()
2057 hdmi_writeb(hdmi, hdmi->mc_clkdis, HDMI_MC_CLKDIS); in dw_hdmi_enable_video_path()
2060 if (is_csc_needed(hdmi)) { in dw_hdmi_enable_video_path()
2061 hdmi->mc_clkdis &= ~HDMI_MC_CLKDIS_CSCCLK_DISABLE; in dw_hdmi_enable_video_path()
2062 hdmi_writeb(hdmi, hdmi->mc_clkdis, HDMI_MC_CLKDIS); in dw_hdmi_enable_video_path()
2064 hdmi_writeb(hdmi, HDMI_MC_FLOWCTRL_FEED_THROUGH_OFF_CSC_IN_PATH, in dw_hdmi_enable_video_path()
2067 hdmi->mc_clkdis |= HDMI_MC_CLKDIS_CSCCLK_DISABLE; in dw_hdmi_enable_video_path()
2068 hdmi_writeb(hdmi, hdmi->mc_clkdis, HDMI_MC_CLKDIS); in dw_hdmi_enable_video_path()
2070 hdmi_writeb(hdmi, HDMI_MC_FLOWCTRL_FEED_THROUGH_OFF_CSC_BYPASS, in dw_hdmi_enable_video_path()
2076 static void dw_hdmi_clear_overflow(struct dw_hdmi *hdmi) in dw_hdmi_clear_overflow() argument
2099 switch (hdmi->version) { in dw_hdmi_clear_overflow()
2116 hdmi_writeb(hdmi, (u8)~HDMI_MC_SWRSTZ_TMDSSWRST_REQ, HDMI_MC_SWRSTZ); in dw_hdmi_clear_overflow()
2118 val = hdmi_readb(hdmi, HDMI_FC_INVIDCONF); in dw_hdmi_clear_overflow()
2120 hdmi_writeb(hdmi, val, HDMI_FC_INVIDCONF); in dw_hdmi_clear_overflow()
2123 static void hdmi_disable_overflow_interrupts(struct dw_hdmi *hdmi) in hdmi_disable_overflow_interrupts() argument
2125 hdmi_writeb(hdmi, HDMI_IH_MUTE_FC_STAT2_OVERFLOW_MASK, in hdmi_disable_overflow_interrupts()
2129 static int dw_hdmi_setup(struct dw_hdmi *hdmi, in dw_hdmi_setup() argument
2135 hdmi_disable_overflow_interrupts(hdmi); in dw_hdmi_setup()
2137 hdmi->vic = drm_match_cea_mode(mode); in dw_hdmi_setup()
2139 if (!hdmi->vic) { in dw_hdmi_setup()
2140 dev_dbg(hdmi->dev, "Non-CEA mode used in HDMI\n"); in dw_hdmi_setup()
2142 dev_dbg(hdmi->dev, "CEA mode used vic=%d\n", hdmi->vic); in dw_hdmi_setup()
2145 if ((hdmi->vic == 6) || (hdmi->vic == 7) || in dw_hdmi_setup()
2146 (hdmi->vic == 21) || (hdmi->vic == 22) || in dw_hdmi_setup()
2147 (hdmi->vic == 2) || (hdmi->vic == 3) || in dw_hdmi_setup()
2148 (hdmi->vic == 17) || (hdmi->vic == 18)) in dw_hdmi_setup()
2149 hdmi->hdmi_data.enc_out_encoding = V4L2_YCBCR_ENC_601; in dw_hdmi_setup()
2151 hdmi->hdmi_data.enc_out_encoding = V4L2_YCBCR_ENC_709; in dw_hdmi_setup()
2153 hdmi->hdmi_data.video_mode.mpixelrepetitionoutput = 0; in dw_hdmi_setup()
2154 hdmi->hdmi_data.video_mode.mpixelrepetitioninput = 0; in dw_hdmi_setup()
2156 if (hdmi->hdmi_data.enc_in_bus_format == MEDIA_BUS_FMT_FIXED) in dw_hdmi_setup()
2157 hdmi->hdmi_data.enc_in_bus_format = MEDIA_BUS_FMT_RGB888_1X24; in dw_hdmi_setup()
2160 if (hdmi->plat_data->input_bus_encoding) in dw_hdmi_setup()
2161 hdmi->hdmi_data.enc_in_encoding = in dw_hdmi_setup()
2162 hdmi->plat_data->input_bus_encoding; in dw_hdmi_setup()
2164 hdmi->hdmi_data.enc_in_encoding = V4L2_YCBCR_ENC_DEFAULT; in dw_hdmi_setup()
2166 if (hdmi->hdmi_data.enc_out_bus_format == MEDIA_BUS_FMT_FIXED) in dw_hdmi_setup()
2167 hdmi->hdmi_data.enc_out_bus_format = MEDIA_BUS_FMT_RGB888_1X24; in dw_hdmi_setup()
2169 hdmi->hdmi_data.rgb_limited_range = hdmi->sink_is_hdmi && in dw_hdmi_setup()
2173 hdmi->hdmi_data.pix_repet_factor = 0; in dw_hdmi_setup()
2174 hdmi->hdmi_data.hdcp_enable = 0; in dw_hdmi_setup()
2175 hdmi->hdmi_data.video_mode.mdataenablepolarity = true; in dw_hdmi_setup()
2178 hdmi_av_composer(hdmi, &connector->display_info, mode); in dw_hdmi_setup()
2181 ret = hdmi->phy.ops->init(hdmi, hdmi->phy.data, in dw_hdmi_setup()
2183 &hdmi->previous_mode); in dw_hdmi_setup()
2186 hdmi->phy.enabled = true; in dw_hdmi_setup()
2189 dw_hdmi_enable_video_path(hdmi); in dw_hdmi_setup()
2191 if (hdmi->sink_has_audio) { in dw_hdmi_setup()
2192 dev_dbg(hdmi->dev, "sink has audio support\n"); in dw_hdmi_setup()
2195 hdmi_clk_regenerator_update_pixel_clock(hdmi); in dw_hdmi_setup()
2196 hdmi_enable_audio_clk(hdmi, hdmi->audio_enable); in dw_hdmi_setup()
2200 if (hdmi->sink_is_hdmi) { in dw_hdmi_setup()
2201 dev_dbg(hdmi->dev, "%s HDMI mode\n", __func__); in dw_hdmi_setup()
2204 hdmi_config_AVI(hdmi, connector, mode); in dw_hdmi_setup()
2205 hdmi_config_vendor_specific_infoframe(hdmi, connector, mode); in dw_hdmi_setup()
2206 hdmi_config_drm_infoframe(hdmi, connector); in dw_hdmi_setup()
2208 dev_dbg(hdmi->dev, "%s DVI mode\n", __func__); in dw_hdmi_setup()
2211 hdmi_video_packetize(hdmi); in dw_hdmi_setup()
2212 hdmi_video_csc(hdmi); in dw_hdmi_setup()
2213 hdmi_video_sample(hdmi); in dw_hdmi_setup()
2214 hdmi_tx_hdcp_config(hdmi); in dw_hdmi_setup()
2216 dw_hdmi_clear_overflow(hdmi); in dw_hdmi_setup()
2221 static void initialize_hdmi_ih_mutes(struct dw_hdmi *hdmi) in initialize_hdmi_ih_mutes() argument
2232 ih_mute = hdmi_readb(hdmi, HDMI_IH_MUTE) | in initialize_hdmi_ih_mutes()
2236 hdmi_writeb(hdmi, ih_mute, HDMI_IH_MUTE); in initialize_hdmi_ih_mutes()
2239 hdmi_writeb(hdmi, 0xff, HDMI_VP_MASK); in initialize_hdmi_ih_mutes()
2240 hdmi_writeb(hdmi, 0xff, HDMI_FC_MASK0); in initialize_hdmi_ih_mutes()
2241 hdmi_writeb(hdmi, 0xff, HDMI_FC_MASK1); in initialize_hdmi_ih_mutes()
2242 hdmi_writeb(hdmi, 0xff, HDMI_FC_MASK2); in initialize_hdmi_ih_mutes()
2243 hdmi_writeb(hdmi, 0xff, HDMI_PHY_MASK0); in initialize_hdmi_ih_mutes()
2244 hdmi_writeb(hdmi, 0xff, HDMI_PHY_I2CM_INT_ADDR); in initialize_hdmi_ih_mutes()
2245 hdmi_writeb(hdmi, 0xff, HDMI_PHY_I2CM_CTLINT_ADDR); in initialize_hdmi_ih_mutes()
2246 hdmi_writeb(hdmi, 0xff, HDMI_AUD_INT); in initialize_hdmi_ih_mutes()
2247 hdmi_writeb(hdmi, 0xff, HDMI_AUD_SPDIFINT); in initialize_hdmi_ih_mutes()
2248 hdmi_writeb(hdmi, 0xff, HDMI_AUD_HBR_MASK); in initialize_hdmi_ih_mutes()
2249 hdmi_writeb(hdmi, 0xff, HDMI_GP_MASK); in initialize_hdmi_ih_mutes()
2250 hdmi_writeb(hdmi, 0xff, HDMI_A_APIINTMSK); in initialize_hdmi_ih_mutes()
2251 hdmi_writeb(hdmi, 0xff, HDMI_I2CM_INT); in initialize_hdmi_ih_mutes()
2252 hdmi_writeb(hdmi, 0xff, HDMI_I2CM_CTLINT); in initialize_hdmi_ih_mutes()
2255 hdmi_writeb(hdmi, 0xff, HDMI_IH_MUTE_FC_STAT0); in initialize_hdmi_ih_mutes()
2256 hdmi_writeb(hdmi, 0xff, HDMI_IH_MUTE_FC_STAT1); in initialize_hdmi_ih_mutes()
2257 hdmi_writeb(hdmi, 0xff, HDMI_IH_MUTE_FC_STAT2); in initialize_hdmi_ih_mutes()
2258 hdmi_writeb(hdmi, 0xff, HDMI_IH_MUTE_AS_STAT0); in initialize_hdmi_ih_mutes()
2259 hdmi_writeb(hdmi, 0xff, HDMI_IH_MUTE_PHY_STAT0); in initialize_hdmi_ih_mutes()
2260 hdmi_writeb(hdmi, 0xff, HDMI_IH_MUTE_I2CM_STAT0); in initialize_hdmi_ih_mutes()
2261 hdmi_writeb(hdmi, 0xff, HDMI_IH_MUTE_CEC_STAT0); in initialize_hdmi_ih_mutes()
2262 hdmi_writeb(hdmi, 0xff, HDMI_IH_MUTE_VP_STAT0); in initialize_hdmi_ih_mutes()
2263 hdmi_writeb(hdmi, 0xff, HDMI_IH_MUTE_I2CMPHY_STAT0); in initialize_hdmi_ih_mutes()
2264 hdmi_writeb(hdmi, 0xff, HDMI_IH_MUTE_AHBDMAAUD_STAT0); in initialize_hdmi_ih_mutes()
2269 hdmi_writeb(hdmi, ih_mute, HDMI_IH_MUTE); in initialize_hdmi_ih_mutes()
2272 static void dw_hdmi_poweron(struct dw_hdmi *hdmi) in dw_hdmi_poweron() argument
2274 hdmi->bridge_is_on = true; in dw_hdmi_poweron()
2280 dw_hdmi_setup(hdmi, hdmi->curr_conn, &hdmi->previous_mode); in dw_hdmi_poweron()
2283 static void dw_hdmi_poweroff(struct dw_hdmi *hdmi) in dw_hdmi_poweroff() argument
2285 if (hdmi->phy.enabled) { in dw_hdmi_poweroff()
2286 hdmi->phy.ops->disable(hdmi, hdmi->phy.data); in dw_hdmi_poweroff()
2287 hdmi->phy.enabled = false; in dw_hdmi_poweroff()
2290 hdmi->bridge_is_on = false; in dw_hdmi_poweroff()
2293 static void dw_hdmi_update_power(struct dw_hdmi *hdmi) in dw_hdmi_update_power() argument
2295 int force = hdmi->force; in dw_hdmi_update_power()
2297 if (hdmi->disabled) { in dw_hdmi_update_power()
2300 if (hdmi->rxsense) in dw_hdmi_update_power()
2307 if (hdmi->bridge_is_on) in dw_hdmi_update_power()
2308 dw_hdmi_poweroff(hdmi); in dw_hdmi_update_power()
2310 if (!hdmi->bridge_is_on) in dw_hdmi_update_power()
2311 dw_hdmi_poweron(hdmi); in dw_hdmi_update_power()
2327 static void dw_hdmi_update_phy_mask(struct dw_hdmi *hdmi) in dw_hdmi_update_phy_mask() argument
2329 if (hdmi->phy.ops->update_hpd) in dw_hdmi_update_phy_mask()
2330 hdmi->phy.ops->update_hpd(hdmi, hdmi->phy.data, in dw_hdmi_update_phy_mask()
2331 hdmi->force, hdmi->disabled, in dw_hdmi_update_phy_mask()
2332 hdmi->rxsense); in dw_hdmi_update_phy_mask()
2335 static enum drm_connector_status dw_hdmi_detect(struct dw_hdmi *hdmi) in dw_hdmi_detect() argument
2339 result = hdmi->phy.ops->read_hpd(hdmi, hdmi->phy.data); in dw_hdmi_detect()
2341 mutex_lock(&hdmi->mutex); in dw_hdmi_detect()
2342 if (result != hdmi->last_connector_result) { in dw_hdmi_detect()
2343 dev_dbg(hdmi->dev, "read_hpd result: %d", result); in dw_hdmi_detect()
2344 handle_plugged_change(hdmi, in dw_hdmi_detect()
2346 hdmi->last_connector_result = result; in dw_hdmi_detect()
2348 mutex_unlock(&hdmi->mutex); in dw_hdmi_detect()
2353 static struct edid *dw_hdmi_get_edid(struct dw_hdmi *hdmi, in dw_hdmi_get_edid() argument
2358 if (!hdmi->ddc) in dw_hdmi_get_edid()
2361 edid = drm_get_edid(connector, hdmi->ddc); in dw_hdmi_get_edid()
2363 dev_dbg(hdmi->dev, "failed to get edid\n"); in dw_hdmi_get_edid()
2367 dev_dbg(hdmi->dev, "got edid: width[%d] x height[%d]\n", in dw_hdmi_get_edid()
2370 hdmi->sink_is_hdmi = drm_detect_hdmi_monitor(edid); in dw_hdmi_get_edid()
2371 hdmi->sink_has_audio = drm_detect_monitor_audio(edid); in dw_hdmi_get_edid()
2383 struct dw_hdmi *hdmi = container_of(connector, struct dw_hdmi, in dw_hdmi_connector_detect() local
2385 return dw_hdmi_detect(hdmi); in dw_hdmi_connector_detect()
2390 struct dw_hdmi *hdmi = container_of(connector, struct dw_hdmi, in dw_hdmi_connector_get_modes() local
2395 edid = dw_hdmi_get_edid(hdmi, connector); in dw_hdmi_connector_get_modes()
2400 cec_notifier_set_phys_addr_from_edid(hdmi->cec_notifier, edid); in dw_hdmi_connector_get_modes()
2433 struct dw_hdmi *hdmi = container_of(connector, struct dw_hdmi, in dw_hdmi_connector_force() local
2436 mutex_lock(&hdmi->mutex); in dw_hdmi_connector_force()
2437 hdmi->force = connector->force; in dw_hdmi_connector_force()
2438 dw_hdmi_update_power(hdmi); in dw_hdmi_connector_force()
2439 dw_hdmi_update_phy_mask(hdmi); in dw_hdmi_connector_force()
2440 mutex_unlock(&hdmi->mutex); in dw_hdmi_connector_force()
2458 static int dw_hdmi_connector_create(struct dw_hdmi *hdmi) in dw_hdmi_connector_create() argument
2460 struct drm_connector *connector = &hdmi->connector; in dw_hdmi_connector_create()
2464 if (hdmi->version >= 0x200a) in dw_hdmi_connector_create()
2466 hdmi->plat_data->ycbcr_420_allowed; in dw_hdmi_connector_create()
2475 drm_connector_init_with_ddc(hdmi->bridge.dev, connector, in dw_hdmi_connector_create()
2478 hdmi->ddc); in dw_hdmi_connector_create()
2488 if (hdmi->version >= 0x200a && hdmi->plat_data->use_drm_infoframe) in dw_hdmi_connector_create()
2491 drm_connector_attach_encoder(connector, hdmi->bridge.encoder); in dw_hdmi_connector_create()
2495 notifier = cec_notifier_conn_register(hdmi->dev, NULL, &conn_info); in dw_hdmi_connector_create()
2499 mutex_lock(&hdmi->cec_notifier_mutex); in dw_hdmi_connector_create()
2500 hdmi->cec_notifier = notifier; in dw_hdmi_connector_create()
2501 mutex_unlock(&hdmi->cec_notifier_mutex); in dw_hdmi_connector_create()
2542 bool is_hdmi2_sink = info->hdmi.scdc.supported || in dw_hdmi_bridge_atomic_get_output_bus_fmts()
2573 (info->hdmi.y420_dc_modes & DRM_EDID_YCBCR420_DC_48)) in dw_hdmi_bridge_atomic_get_output_bus_fmts()
2577 (info->hdmi.y420_dc_modes & DRM_EDID_YCBCR420_DC_36)) in dw_hdmi_bridge_atomic_get_output_bus_fmts()
2581 (info->hdmi.y420_dc_modes & DRM_EDID_YCBCR420_DC_30)) in dw_hdmi_bridge_atomic_get_output_bus_fmts()
2767 struct dw_hdmi *hdmi = bridge->driver_private; in dw_hdmi_bridge_atomic_check() local
2769 hdmi->hdmi_data.enc_out_bus_format = in dw_hdmi_bridge_atomic_check()
2772 hdmi->hdmi_data.enc_in_bus_format = in dw_hdmi_bridge_atomic_check()
2775 dev_dbg(hdmi->dev, "input format 0x%04x, output format 0x%04x\n", in dw_hdmi_bridge_atomic_check()
2785 struct dw_hdmi *hdmi = bridge->driver_private; in dw_hdmi_bridge_attach() local
2788 return drm_bridge_attach(bridge->encoder, hdmi->next_bridge, in dw_hdmi_bridge_attach()
2791 return dw_hdmi_connector_create(hdmi); in dw_hdmi_bridge_attach()
2796 struct dw_hdmi *hdmi = bridge->driver_private; in dw_hdmi_bridge_detach() local
2798 mutex_lock(&hdmi->cec_notifier_mutex); in dw_hdmi_bridge_detach()
2799 cec_notifier_conn_unregister(hdmi->cec_notifier); in dw_hdmi_bridge_detach()
2800 hdmi->cec_notifier = NULL; in dw_hdmi_bridge_detach()
2801 mutex_unlock(&hdmi->cec_notifier_mutex); in dw_hdmi_bridge_detach()
2809 struct dw_hdmi *hdmi = bridge->driver_private; in dw_hdmi_bridge_mode_valid() local
2810 const struct dw_hdmi_plat_data *pdata = hdmi->plat_data; in dw_hdmi_bridge_mode_valid()
2818 mode_status = pdata->mode_valid(hdmi, pdata->priv_data, info, in dw_hdmi_bridge_mode_valid()
2828 struct dw_hdmi *hdmi = bridge->driver_private; in dw_hdmi_bridge_mode_set() local
2830 mutex_lock(&hdmi->mutex); in dw_hdmi_bridge_mode_set()
2833 memcpy(&hdmi->previous_mode, mode, sizeof(hdmi->previous_mode)); in dw_hdmi_bridge_mode_set()
2835 mutex_unlock(&hdmi->mutex); in dw_hdmi_bridge_mode_set()
2841 struct dw_hdmi *hdmi = bridge->driver_private; in dw_hdmi_bridge_atomic_disable() local
2843 mutex_lock(&hdmi->mutex); in dw_hdmi_bridge_atomic_disable()
2844 hdmi->disabled = true; in dw_hdmi_bridge_atomic_disable()
2845 hdmi->curr_conn = NULL; in dw_hdmi_bridge_atomic_disable()
2846 dw_hdmi_update_power(hdmi); in dw_hdmi_bridge_atomic_disable()
2847 dw_hdmi_update_phy_mask(hdmi); in dw_hdmi_bridge_atomic_disable()
2848 mutex_unlock(&hdmi->mutex); in dw_hdmi_bridge_atomic_disable()
2854 struct dw_hdmi *hdmi = bridge->driver_private; in dw_hdmi_bridge_atomic_enable() local
2861 mutex_lock(&hdmi->mutex); in dw_hdmi_bridge_atomic_enable()
2862 hdmi->disabled = false; in dw_hdmi_bridge_atomic_enable()
2863 hdmi->curr_conn = connector; in dw_hdmi_bridge_atomic_enable()
2864 dw_hdmi_update_power(hdmi); in dw_hdmi_bridge_atomic_enable()
2865 dw_hdmi_update_phy_mask(hdmi); in dw_hdmi_bridge_atomic_enable()
2866 mutex_unlock(&hdmi->mutex); in dw_hdmi_bridge_atomic_enable()
2871 struct dw_hdmi *hdmi = bridge->driver_private; in dw_hdmi_bridge_detect() local
2873 return dw_hdmi_detect(hdmi); in dw_hdmi_bridge_detect()
2879 struct dw_hdmi *hdmi = bridge->driver_private; in dw_hdmi_bridge_get_edid() local
2881 return dw_hdmi_get_edid(hdmi, connector); in dw_hdmi_bridge_get_edid()
2905 static irqreturn_t dw_hdmi_i2c_irq(struct dw_hdmi *hdmi) in dw_hdmi_i2c_irq() argument
2907 struct dw_hdmi_i2c *i2c = hdmi->i2c; in dw_hdmi_i2c_irq()
2910 stat = hdmi_readb(hdmi, HDMI_IH_I2CM_STAT0); in dw_hdmi_i2c_irq()
2914 hdmi_writeb(hdmi, stat, HDMI_IH_I2CM_STAT0); in dw_hdmi_i2c_irq()
2925 struct dw_hdmi *hdmi = dev_id; in dw_hdmi_hardirq() local
2929 if (hdmi->i2c) in dw_hdmi_hardirq()
2930 ret = dw_hdmi_i2c_irq(hdmi); in dw_hdmi_hardirq()
2932 intr_stat = hdmi_readb(hdmi, HDMI_IH_PHY_STAT0); in dw_hdmi_hardirq()
2934 hdmi_writeb(hdmi, ~0, HDMI_IH_MUTE_PHY_STAT0); in dw_hdmi_hardirq()
2941 void dw_hdmi_setup_rx_sense(struct dw_hdmi *hdmi, bool hpd, bool rx_sense) in dw_hdmi_setup_rx_sense() argument
2943 mutex_lock(&hdmi->mutex); in dw_hdmi_setup_rx_sense()
2945 if (!hdmi->force) { in dw_hdmi_setup_rx_sense()
2951 hdmi->rxsense = false; in dw_hdmi_setup_rx_sense()
2960 hdmi->rxsense = true; in dw_hdmi_setup_rx_sense()
2962 dw_hdmi_update_power(hdmi); in dw_hdmi_setup_rx_sense()
2963 dw_hdmi_update_phy_mask(hdmi); in dw_hdmi_setup_rx_sense()
2965 mutex_unlock(&hdmi->mutex); in dw_hdmi_setup_rx_sense()
2971 struct dw_hdmi *hdmi = dev_id; in dw_hdmi_irq() local
2975 intr_stat = hdmi_readb(hdmi, HDMI_IH_PHY_STAT0); in dw_hdmi_irq()
2976 phy_int_pol = hdmi_readb(hdmi, HDMI_PHY_POL0); in dw_hdmi_irq()
2977 phy_stat = hdmi_readb(hdmi, HDMI_PHY_STAT0); in dw_hdmi_irq()
2992 hdmi_modb(hdmi, ~phy_int_pol, phy_pol_mask, HDMI_PHY_POL0); in dw_hdmi_irq()
3003 dw_hdmi_setup_rx_sense(hdmi, in dw_hdmi_irq()
3008 mutex_lock(&hdmi->cec_notifier_mutex); in dw_hdmi_irq()
3009 cec_notifier_phys_addr_invalidate(hdmi->cec_notifier); in dw_hdmi_irq()
3010 mutex_unlock(&hdmi->cec_notifier_mutex); in dw_hdmi_irq()
3021 dev_dbg(hdmi->dev, "EVENT=%s\n", in dw_hdmi_irq()
3025 if (hdmi->bridge.dev) { in dw_hdmi_irq()
3026 drm_helper_hpd_irq_event(hdmi->bridge.dev); in dw_hdmi_irq()
3027 drm_bridge_hpd_notify(&hdmi->bridge, status); in dw_hdmi_irq()
3031 hdmi_writeb(hdmi, intr_stat, HDMI_IH_PHY_STAT0); in dw_hdmi_irq()
3032 hdmi_writeb(hdmi, ~(HDMI_IH_PHY_STAT0_HPD | HDMI_IH_PHY_STAT0_RX_SENSE), in dw_hdmi_irq()
3077 static int dw_hdmi_detect_phy(struct dw_hdmi *hdmi) in dw_hdmi_detect_phy() argument
3082 phy_type = hdmi->plat_data->phy_force_vendor ? in dw_hdmi_detect_phy()
3084 hdmi_readb(hdmi, HDMI_CONFIG2_ID); in dw_hdmi_detect_phy()
3088 if (!hdmi->plat_data->phy_ops || !hdmi->plat_data->phy_name) { in dw_hdmi_detect_phy()
3089 dev_err(hdmi->dev, in dw_hdmi_detect_phy()
3094 hdmi->phy.ops = hdmi->plat_data->phy_ops; in dw_hdmi_detect_phy()
3095 hdmi->phy.data = hdmi->plat_data->phy_data; in dw_hdmi_detect_phy()
3096 hdmi->phy.name = hdmi->plat_data->phy_name; in dw_hdmi_detect_phy()
3103 hdmi->phy.ops = &dw_hdmi_synopsys_phy_ops; in dw_hdmi_detect_phy()
3104 hdmi->phy.name = dw_hdmi_phys[i].name; in dw_hdmi_detect_phy()
3105 hdmi->phy.data = (void *)&dw_hdmi_phys[i]; in dw_hdmi_detect_phy()
3108 !hdmi->plat_data->configure_phy) { in dw_hdmi_detect_phy()
3109 dev_err(hdmi->dev, "%s requires platform support\n", in dw_hdmi_detect_phy()
3110 hdmi->phy.name); in dw_hdmi_detect_phy()
3118 dev_err(hdmi->dev, "Unsupported HDMI PHY type (%02x)\n", phy_type); in dw_hdmi_detect_phy()
3122 static void dw_hdmi_cec_enable(struct dw_hdmi *hdmi) in dw_hdmi_cec_enable() argument
3124 mutex_lock(&hdmi->mutex); in dw_hdmi_cec_enable()
3125 hdmi->mc_clkdis &= ~HDMI_MC_CLKDIS_CECCLK_DISABLE; in dw_hdmi_cec_enable()
3126 hdmi_writeb(hdmi, hdmi->mc_clkdis, HDMI_MC_CLKDIS); in dw_hdmi_cec_enable()
3127 mutex_unlock(&hdmi->mutex); in dw_hdmi_cec_enable()
3130 static void dw_hdmi_cec_disable(struct dw_hdmi *hdmi) in dw_hdmi_cec_disable() argument
3132 mutex_lock(&hdmi->mutex); in dw_hdmi_cec_disable()
3133 hdmi->mc_clkdis |= HDMI_MC_CLKDIS_CECCLK_DISABLE; in dw_hdmi_cec_disable()
3134 hdmi_writeb(hdmi, hdmi->mc_clkdis, HDMI_MC_CLKDIS); in dw_hdmi_cec_disable()
3135 mutex_unlock(&hdmi->mutex); in dw_hdmi_cec_disable()
3159 static void dw_hdmi_init_hw(struct dw_hdmi *hdmi) in dw_hdmi_init_hw() argument
3161 initialize_hdmi_ih_mutes(hdmi); in dw_hdmi_init_hw()
3168 dw_hdmi_i2c_init(hdmi); in dw_hdmi_init_hw()
3170 if (hdmi->phy.ops->setup_hpd) in dw_hdmi_init_hw()
3171 hdmi->phy.ops->setup_hpd(hdmi, hdmi->phy.data); in dw_hdmi_init_hw()
3178 static int dw_hdmi_parse_dt(struct dw_hdmi *hdmi) in dw_hdmi_parse_dt() argument
3183 if (!hdmi->plat_data->output_port) in dw_hdmi_parse_dt()
3186 endpoint = of_graph_get_endpoint_by_regs(hdmi->dev->of_node, in dw_hdmi_parse_dt()
3187 hdmi->plat_data->output_port, in dw_hdmi_parse_dt()
3195 dev_err(hdmi->dev, "Missing endpoint in port@%u\n", in dw_hdmi_parse_dt()
3196 hdmi->plat_data->output_port); in dw_hdmi_parse_dt()
3203 dev_err(hdmi->dev, "Endpoint in port@%u unconnected\n", in dw_hdmi_parse_dt()
3204 hdmi->plat_data->output_port); in dw_hdmi_parse_dt()
3209 dev_err(hdmi->dev, "port@%u remote device is disabled\n", in dw_hdmi_parse_dt()
3210 hdmi->plat_data->output_port); in dw_hdmi_parse_dt()
3215 hdmi->next_bridge = of_drm_find_bridge(remote); in dw_hdmi_parse_dt()
3217 if (!hdmi->next_bridge) in dw_hdmi_parse_dt()
3231 struct dw_hdmi *hdmi; in dw_hdmi_probe() local
3241 hdmi = devm_kzalloc(dev, sizeof(*hdmi), GFP_KERNEL); in dw_hdmi_probe()
3242 if (!hdmi) in dw_hdmi_probe()
3245 hdmi->plat_data = plat_data; in dw_hdmi_probe()
3246 hdmi->dev = dev; in dw_hdmi_probe()
3247 hdmi->sample_rate = 48000; in dw_hdmi_probe()
3248 hdmi->disabled = true; in dw_hdmi_probe()
3249 hdmi->rxsense = true; in dw_hdmi_probe()
3250 hdmi->phy_mask = (u8)~(HDMI_PHY_HPD | HDMI_PHY_RX_SENSE); in dw_hdmi_probe()
3251 hdmi->mc_clkdis = 0x7f; in dw_hdmi_probe()
3252 hdmi->last_connector_result = connector_status_disconnected; in dw_hdmi_probe()
3254 mutex_init(&hdmi->mutex); in dw_hdmi_probe()
3255 mutex_init(&hdmi->audio_mutex); in dw_hdmi_probe()
3256 mutex_init(&hdmi->cec_notifier_mutex); in dw_hdmi_probe()
3257 spin_lock_init(&hdmi->audio_lock); in dw_hdmi_probe()
3259 ret = dw_hdmi_parse_dt(hdmi); in dw_hdmi_probe()
3265 hdmi->ddc = of_get_i2c_adapter_by_node(ddc_node); in dw_hdmi_probe()
3267 if (!hdmi->ddc) { in dw_hdmi_probe()
3268 dev_dbg(hdmi->dev, "failed to read ddc node\n"); in dw_hdmi_probe()
3273 dev_dbg(hdmi->dev, "no ddc property found\n"); in dw_hdmi_probe()
3283 hdmi->reg_shift = 2; in dw_hdmi_probe()
3294 hdmi->regs = devm_ioremap_resource(dev, iores); in dw_hdmi_probe()
3295 if (IS_ERR(hdmi->regs)) { in dw_hdmi_probe()
3296 ret = PTR_ERR(hdmi->regs); in dw_hdmi_probe()
3300 hdmi->regm = devm_regmap_init_mmio(dev, hdmi->regs, reg_config); in dw_hdmi_probe()
3301 if (IS_ERR(hdmi->regm)) { in dw_hdmi_probe()
3303 ret = PTR_ERR(hdmi->regm); in dw_hdmi_probe()
3307 hdmi->regm = plat_data->regm; in dw_hdmi_probe()
3310 hdmi->isfr_clk = devm_clk_get(hdmi->dev, "isfr"); in dw_hdmi_probe()
3311 if (IS_ERR(hdmi->isfr_clk)) { in dw_hdmi_probe()
3312 ret = PTR_ERR(hdmi->isfr_clk); in dw_hdmi_probe()
3313 dev_err(hdmi->dev, "Unable to get HDMI isfr clk: %d\n", ret); in dw_hdmi_probe()
3317 ret = clk_prepare_enable(hdmi->isfr_clk); in dw_hdmi_probe()
3319 dev_err(hdmi->dev, "Cannot enable HDMI isfr clock: %d\n", ret); in dw_hdmi_probe()
3323 hdmi->iahb_clk = devm_clk_get(hdmi->dev, "iahb"); in dw_hdmi_probe()
3324 if (IS_ERR(hdmi->iahb_clk)) { in dw_hdmi_probe()
3325 ret = PTR_ERR(hdmi->iahb_clk); in dw_hdmi_probe()
3326 dev_err(hdmi->dev, "Unable to get HDMI iahb clk: %d\n", ret); in dw_hdmi_probe()
3330 ret = clk_prepare_enable(hdmi->iahb_clk); in dw_hdmi_probe()
3332 dev_err(hdmi->dev, "Cannot enable HDMI iahb clock: %d\n", ret); in dw_hdmi_probe()
3336 hdmi->cec_clk = devm_clk_get(hdmi->dev, "cec"); in dw_hdmi_probe()
3337 if (PTR_ERR(hdmi->cec_clk) == -ENOENT) { in dw_hdmi_probe()
3338 hdmi->cec_clk = NULL; in dw_hdmi_probe()
3339 } else if (IS_ERR(hdmi->cec_clk)) { in dw_hdmi_probe()
3340 ret = PTR_ERR(hdmi->cec_clk); in dw_hdmi_probe()
3342 dev_err(hdmi->dev, "Cannot get HDMI cec clock: %d\n", in dw_hdmi_probe()
3345 hdmi->cec_clk = NULL; in dw_hdmi_probe()
3348 ret = clk_prepare_enable(hdmi->cec_clk); in dw_hdmi_probe()
3350 dev_err(hdmi->dev, "Cannot enable HDMI cec clock: %d\n", in dw_hdmi_probe()
3357 hdmi->version = (hdmi_readb(hdmi, HDMI_DESIGN_ID) << 8) in dw_hdmi_probe()
3358 | (hdmi_readb(hdmi, HDMI_REVISION_ID) << 0); in dw_hdmi_probe()
3359 prod_id0 = hdmi_readb(hdmi, HDMI_PRODUCT_ID0); in dw_hdmi_probe()
3360 prod_id1 = hdmi_readb(hdmi, HDMI_PRODUCT_ID1); in dw_hdmi_probe()
3365 hdmi->version, prod_id0, prod_id1); in dw_hdmi_probe()
3370 ret = dw_hdmi_detect_phy(hdmi); in dw_hdmi_probe()
3375 hdmi->version >> 12, hdmi->version & 0xfff, in dw_hdmi_probe()
3377 hdmi->phy.name); in dw_hdmi_probe()
3379 dw_hdmi_init_hw(hdmi); in dw_hdmi_probe()
3389 dev_name(dev), hdmi); in dw_hdmi_probe()
3397 hdmi_init_clk_regenerator(hdmi); in dw_hdmi_probe()
3400 if (!hdmi->ddc) { in dw_hdmi_probe()
3402 hdmi->pinctrl = devm_pinctrl_get(dev); in dw_hdmi_probe()
3403 if (!IS_ERR(hdmi->pinctrl)) { in dw_hdmi_probe()
3404 hdmi->unwedge_state = in dw_hdmi_probe()
3405 pinctrl_lookup_state(hdmi->pinctrl, "unwedge"); in dw_hdmi_probe()
3406 hdmi->default_state = in dw_hdmi_probe()
3407 pinctrl_lookup_state(hdmi->pinctrl, "default"); in dw_hdmi_probe()
3409 if (IS_ERR(hdmi->default_state) || in dw_hdmi_probe()
3410 IS_ERR(hdmi->unwedge_state)) { in dw_hdmi_probe()
3411 if (!IS_ERR(hdmi->unwedge_state)) in dw_hdmi_probe()
3414 hdmi->default_state = NULL; in dw_hdmi_probe()
3415 hdmi->unwedge_state = NULL; in dw_hdmi_probe()
3419 hdmi->ddc = dw_hdmi_i2c_adapter(hdmi); in dw_hdmi_probe()
3420 if (IS_ERR(hdmi->ddc)) in dw_hdmi_probe()
3421 hdmi->ddc = NULL; in dw_hdmi_probe()
3424 hdmi->bridge.driver_private = hdmi; in dw_hdmi_probe()
3425 hdmi->bridge.funcs = &dw_hdmi_bridge_funcs; in dw_hdmi_probe()
3426 hdmi->bridge.ops = DRM_BRIDGE_OP_DETECT | DRM_BRIDGE_OP_EDID in dw_hdmi_probe()
3429 hdmi->bridge.of_node = pdev->dev.of_node; in dw_hdmi_probe()
3436 config0 = hdmi_readb(hdmi, HDMI_CONFIG0_ID); in dw_hdmi_probe()
3437 config3 = hdmi_readb(hdmi, HDMI_CONFIG3_ID); in dw_hdmi_probe()
3443 audio.base = hdmi->regs; in dw_hdmi_probe()
3445 audio.hdmi = hdmi; in dw_hdmi_probe()
3447 hdmi->enable_audio = dw_hdmi_ahb_audio_enable; in dw_hdmi_probe()
3448 hdmi->disable_audio = dw_hdmi_ahb_audio_disable; in dw_hdmi_probe()
3454 hdmi->audio = platform_device_register_full(&pdevinfo); in dw_hdmi_probe()
3458 audio.hdmi = hdmi; in dw_hdmi_probe()
3462 hdmi->enable_audio = dw_hdmi_i2s_audio_enable; in dw_hdmi_probe()
3463 hdmi->disable_audio = dw_hdmi_i2s_audio_disable; in dw_hdmi_probe()
3469 hdmi->audio = platform_device_register_full(&pdevinfo); in dw_hdmi_probe()
3473 cec.hdmi = hdmi; in dw_hdmi_probe()
3482 hdmi->cec = platform_device_register_full(&pdevinfo); in dw_hdmi_probe()
3485 drm_bridge_add(&hdmi->bridge); in dw_hdmi_probe()
3487 return hdmi; in dw_hdmi_probe()
3490 clk_disable_unprepare(hdmi->iahb_clk); in dw_hdmi_probe()
3491 clk_disable_unprepare(hdmi->cec_clk); in dw_hdmi_probe()
3493 clk_disable_unprepare(hdmi->isfr_clk); in dw_hdmi_probe()
3495 i2c_put_adapter(hdmi->ddc); in dw_hdmi_probe()
3501 void dw_hdmi_remove(struct dw_hdmi *hdmi) in dw_hdmi_remove() argument
3503 drm_bridge_remove(&hdmi->bridge); in dw_hdmi_remove()
3505 if (hdmi->audio && !IS_ERR(hdmi->audio)) in dw_hdmi_remove()
3506 platform_device_unregister(hdmi->audio); in dw_hdmi_remove()
3507 if (!IS_ERR(hdmi->cec)) in dw_hdmi_remove()
3508 platform_device_unregister(hdmi->cec); in dw_hdmi_remove()
3511 hdmi_writeb(hdmi, ~0, HDMI_IH_MUTE_PHY_STAT0); in dw_hdmi_remove()
3513 clk_disable_unprepare(hdmi->iahb_clk); in dw_hdmi_remove()
3514 clk_disable_unprepare(hdmi->isfr_clk); in dw_hdmi_remove()
3515 clk_disable_unprepare(hdmi->cec_clk); in dw_hdmi_remove()
3517 if (hdmi->i2c) in dw_hdmi_remove()
3518 i2c_del_adapter(&hdmi->i2c->adap); in dw_hdmi_remove()
3520 i2c_put_adapter(hdmi->ddc); in dw_hdmi_remove()
3531 struct dw_hdmi *hdmi; in dw_hdmi_bind() local
3534 hdmi = dw_hdmi_probe(pdev, plat_data); in dw_hdmi_bind()
3535 if (IS_ERR(hdmi)) in dw_hdmi_bind()
3536 return hdmi; in dw_hdmi_bind()
3538 ret = drm_bridge_attach(encoder, &hdmi->bridge, NULL, 0); in dw_hdmi_bind()
3540 dw_hdmi_remove(hdmi); in dw_hdmi_bind()
3544 return hdmi; in dw_hdmi_bind()
3548 void dw_hdmi_unbind(struct dw_hdmi *hdmi) in dw_hdmi_unbind() argument
3550 dw_hdmi_remove(hdmi); in dw_hdmi_unbind()
3554 void dw_hdmi_resume(struct dw_hdmi *hdmi) in dw_hdmi_resume() argument
3556 dw_hdmi_init_hw(hdmi); in dw_hdmi_resume()