Lines Matching refs:hdmi

10 #include <linux/hdmi.h>
25 #include <sound/hdmi-codec.h>
194 static u32 mtk_hdmi_read(struct mtk_hdmi *hdmi, u32 offset)
196 return readl(hdmi->regs + offset);
199 static void mtk_hdmi_write(struct mtk_hdmi *hdmi, u32 offset, u32 val)
201 writel(val, hdmi->regs + offset);
204 static void mtk_hdmi_clear_bits(struct mtk_hdmi *hdmi, u32 offset, u32 bits)
206 void __iomem *reg = hdmi->regs + offset;
214 static void mtk_hdmi_set_bits(struct mtk_hdmi *hdmi, u32 offset, u32 bits)
216 void __iomem *reg = hdmi->regs + offset;
224 static void mtk_hdmi_mask(struct mtk_hdmi *hdmi, u32 offset, u32 val, u32 mask)
226 void __iomem *reg = hdmi->regs + offset;
234 static void mtk_hdmi_hw_vid_black(struct mtk_hdmi *hdmi, bool black)
236 mtk_hdmi_mask(hdmi, VIDEO_CFG_4, black ? GEN_RGB : NORMAL_PATH,
240 static void mtk_hdmi_hw_make_reg_writable(struct mtk_hdmi *hdmi, bool enable)
250 if (hdmi->conf && hdmi->conf->tz_disabled)
251 regmap_update_bits(hdmi->sys_regmap,
252 hdmi->sys_offset + HDMI_SYS_CFG20,
258 regmap_update_bits(hdmi->sys_regmap, hdmi->sys_offset + HDMI_SYS_CFG20,
260 regmap_update_bits(hdmi->sys_regmap, hdmi->sys_offset + HDMI_SYS_CFG1C,
264 static void mtk_hdmi_hw_1p4_version_enable(struct mtk_hdmi *hdmi, bool enable)
266 regmap_update_bits(hdmi->sys_regmap, hdmi->sys_offset + HDMI_SYS_CFG20,
270 static void mtk_hdmi_hw_aud_mute(struct mtk_hdmi *hdmi)
272 mtk_hdmi_set_bits(hdmi, GRL_AUDIO_CFG, AUDIO_ZERO);
275 static void mtk_hdmi_hw_aud_unmute(struct mtk_hdmi *hdmi)
277 mtk_hdmi_clear_bits(hdmi, GRL_AUDIO_CFG, AUDIO_ZERO);
280 static void mtk_hdmi_hw_reset(struct mtk_hdmi *hdmi)
282 regmap_update_bits(hdmi->sys_regmap, hdmi->sys_offset + HDMI_SYS_CFG1C,
284 regmap_update_bits(hdmi->sys_regmap, hdmi->sys_offset + HDMI_SYS_CFG1C,
286 mtk_hdmi_clear_bits(hdmi, GRL_CFG3, CFG3_CONTROL_PACKET_DELAY);
287 regmap_update_bits(hdmi->sys_regmap, hdmi->sys_offset + HDMI_SYS_CFG1C,
291 static void mtk_hdmi_hw_enable_notice(struct mtk_hdmi *hdmi, bool enable_notice)
293 mtk_hdmi_mask(hdmi, GRL_CFG2, enable_notice ? CFG2_NOTICE_EN : 0,
297 static void mtk_hdmi_hw_write_int_mask(struct mtk_hdmi *hdmi, u32 int_mask)
299 mtk_hdmi_write(hdmi, GRL_INT_MASK, int_mask);
302 static void mtk_hdmi_hw_enable_dvi_mode(struct mtk_hdmi *hdmi, bool enable)
304 mtk_hdmi_mask(hdmi, GRL_CFG1, enable ? CFG1_DVI : 0, CFG1_DVI);
307 static void mtk_hdmi_hw_send_info_frame(struct mtk_hdmi *hdmi, u8 *buffer,
325 dev_dbg(hdmi->dev,
347 dev_err(hdmi->dev, "Unknown infoframe type %d\n", frame_type);
350 mtk_hdmi_clear_bits(hdmi, ctrl_reg, ctrl_frame_en);
351 mtk_hdmi_write(hdmi, GRL_INFOFRM_TYPE, frame_type);
352 mtk_hdmi_write(hdmi, GRL_INFOFRM_VER, frame_ver);
353 mtk_hdmi_write(hdmi, GRL_INFOFRM_LNG, frame_len);
355 mtk_hdmi_write(hdmi, GRL_IFM_PORT, checksum);
357 mtk_hdmi_write(hdmi, GRL_IFM_PORT, frame_data[i]);
359 mtk_hdmi_set_bits(hdmi, ctrl_reg, ctrl_frame_en);
362 static void mtk_hdmi_hw_send_aud_packet(struct mtk_hdmi *hdmi, bool enable)
364 mtk_hdmi_mask(hdmi, GRL_SHIFT_R2, enable ? 0 : AUDIO_PACKET_OFF,
368 static void mtk_hdmi_hw_config_sys(struct mtk_hdmi *hdmi)
370 regmap_update_bits(hdmi->sys_regmap, hdmi->sys_offset + HDMI_SYS_CFG20,
373 regmap_update_bits(hdmi->sys_regmap, hdmi->sys_offset + HDMI_SYS_CFG20,
377 static void mtk_hdmi_hw_set_deep_color_mode(struct mtk_hdmi *hdmi)
379 regmap_update_bits(hdmi->sys_regmap, hdmi->sys_offset + HDMI_SYS_CFG20,
384 static void mtk_hdmi_hw_send_av_mute(struct mtk_hdmi *hdmi)
386 mtk_hdmi_clear_bits(hdmi, GRL_CFG4, CTRL_AVMUTE);
388 mtk_hdmi_set_bits(hdmi, GRL_CFG4, CTRL_AVMUTE);
391 static void mtk_hdmi_hw_send_av_unmute(struct mtk_hdmi *hdmi)
393 mtk_hdmi_mask(hdmi, GRL_CFG4, CFG4_AV_UNMUTE_EN,
396 mtk_hdmi_mask(hdmi, GRL_CFG4, CFG4_AV_UNMUTE_SET,
400 static void mtk_hdmi_hw_ncts_enable(struct mtk_hdmi *hdmi, bool on)
402 mtk_hdmi_mask(hdmi, GRL_CTS_CTRL, on ? 0 : CTS_CTRL_SOFT,
406 static void mtk_hdmi_hw_ncts_auto_write_enable(struct mtk_hdmi *hdmi,
409 mtk_hdmi_mask(hdmi, GRL_CTS_CTRL, enable ? NCTS_WRI_ANYTIME : 0,
413 static void mtk_hdmi_hw_msic_setting(struct mtk_hdmi *hdmi,
416 mtk_hdmi_clear_bits(hdmi, GRL_CFG4, CFG4_MHL_MODE);
421 mtk_hdmi_clear_bits(hdmi, GRL_CFG2, CFG2_MHL_DE_SEL);
423 mtk_hdmi_set_bits(hdmi, GRL_CFG2, CFG2_MHL_DE_SEL);
426 static void mtk_hdmi_hw_aud_set_channel_swap(struct mtk_hdmi *hdmi,
451 mtk_hdmi_mask(hdmi, GRL_CH_SWAP, swap_bit, 0xff);
454 static void mtk_hdmi_hw_aud_set_bit_num(struct mtk_hdmi *hdmi,
472 mtk_hdmi_mask(hdmi, GRL_AOUT_CFG, val, AOUT_BNUM_SEL_MASK);
475 static void mtk_hdmi_hw_aud_set_i2s_fmt(struct mtk_hdmi *hdmi,
480 val = mtk_hdmi_read(hdmi, GRL_CFG0);
504 mtk_hdmi_write(hdmi, GRL_CFG0, val);
507 static void mtk_hdmi_hw_audio_config(struct mtk_hdmi *hdmi, bool dst)
513 mtk_hdmi_clear_bits(hdmi, GRL_AOUT_CFG, HIGH_BIT_RATE_PACKET_ALIGN);
520 mtk_hdmi_mask(hdmi, GRL_AUDIO_CFG, val, mask);
523 static void mtk_hdmi_hw_aud_set_i2s_chan_num(struct mtk_hdmi *hdmi,
561 mtk_hdmi_write(hdmi, GRL_CH_SW0, ch_switch & 0xff);
562 mtk_hdmi_write(hdmi, GRL_CH_SW1, (ch_switch >> 8) & 0xff);
563 mtk_hdmi_write(hdmi, GRL_CH_SW2, (ch_switch >> 16) & 0xff);
564 mtk_hdmi_write(hdmi, GRL_I2S_UV, i2s_uv);
567 static void mtk_hdmi_hw_aud_set_input_type(struct mtk_hdmi *hdmi,
572 val = mtk_hdmi_read(hdmi, GRL_CFG1);
580 mtk_hdmi_write(hdmi, GRL_CFG1, val);
583 static void mtk_hdmi_hw_aud_set_channel_status(struct mtk_hdmi *hdmi,
589 mtk_hdmi_write(hdmi, GRL_I2S_C_STA0 + i * 4, channel_status[i]);
590 mtk_hdmi_write(hdmi, GRL_L_STATUS_0 + i * 4, channel_status[i]);
591 mtk_hdmi_write(hdmi, GRL_R_STATUS_0 + i * 4, channel_status[i]);
594 mtk_hdmi_write(hdmi, GRL_L_STATUS_0 + i * 4, 0);
595 mtk_hdmi_write(hdmi, GRL_R_STATUS_0 + i * 4, 0);
599 static void mtk_hdmi_hw_aud_src_reenable(struct mtk_hdmi *hdmi)
603 val = mtk_hdmi_read(hdmi, GRL_MIX_CTRL);
606 mtk_hdmi_write(hdmi, GRL_MIX_CTRL, val);
609 mtk_hdmi_write(hdmi, GRL_MIX_CTRL, val);
613 static void mtk_hdmi_hw_aud_src_disable(struct mtk_hdmi *hdmi)
617 val = mtk_hdmi_read(hdmi, GRL_MIX_CTRL);
619 mtk_hdmi_write(hdmi, GRL_MIX_CTRL, val);
620 mtk_hdmi_write(hdmi, GRL_SHIFT_L1, 0x00);
623 static void mtk_hdmi_hw_aud_set_mclk(struct mtk_hdmi *hdmi,
628 val = mtk_hdmi_read(hdmi, GRL_CFG5);
651 mtk_hdmi_write(hdmi, GRL_CFG5, val);
729 static void do_hdmi_hw_aud_set_ncts(struct mtk_hdmi *hdmi, unsigned int n,
735 mtk_hdmi_write(hdmi, GRL_NCTS, 0);
736 mtk_hdmi_write(hdmi, GRL_NCTS, 0);
737 mtk_hdmi_write(hdmi, GRL_NCTS, 0);
750 mtk_hdmi_write(hdmi, GRL_NCTS, val[i]);
753 static void mtk_hdmi_hw_aud_set_ncts(struct mtk_hdmi *hdmi,
762 dev_dbg(hdmi->dev, "%s: sample_rate=%u, clock=%d, cts=%u, n=%u\n",
765 mtk_hdmi_mask(hdmi, DUMMY_304, AUDIO_I2S_NCTS_SEL_64,
767 do_hdmi_hw_aud_set_ncts(hdmi, n, cts);
840 static int mtk_hdmi_video_change_vpll(struct mtk_hdmi *hdmi, u32 clock)
846 ret = clk_set_rate(hdmi->clk[MTK_HDMI_CLK_HDMI_PLL], clock);
848 dev_err(hdmi->dev, "Failed to set PLL to %u Hz: %d\n", clock,
853 rate = clk_get_rate(hdmi->clk[MTK_HDMI_CLK_HDMI_PLL]);
856 dev_warn(hdmi->dev, "Want PLL %u Hz, got %lu Hz\n", clock,
859 dev_dbg(hdmi->dev, "Want PLL %u Hz, got %lu Hz\n", clock, rate);
861 mtk_hdmi_hw_config_sys(hdmi);
862 mtk_hdmi_hw_set_deep_color_mode(hdmi);
866 static void mtk_hdmi_video_set_display_mode(struct mtk_hdmi *hdmi,
869 mtk_hdmi_hw_reset(hdmi);
870 mtk_hdmi_hw_enable_notice(hdmi, true);
871 mtk_hdmi_hw_write_int_mask(hdmi, 0xff);
872 mtk_hdmi_hw_enable_dvi_mode(hdmi, hdmi->dvi_mode);
873 mtk_hdmi_hw_ncts_auto_write_enable(hdmi, true);
875 mtk_hdmi_hw_msic_setting(hdmi, mode);
878 static int mtk_hdmi_aud_enable_packet(struct mtk_hdmi *hdmi, bool enable)
880 mtk_hdmi_hw_send_aud_packet(hdmi, enable);
884 static int mtk_hdmi_aud_on_off_hw_ncts(struct mtk_hdmi *hdmi, bool on)
886 mtk_hdmi_hw_ncts_enable(hdmi, on);
890 static int mtk_hdmi_aud_set_input(struct mtk_hdmi *hdmi)
896 mtk_hdmi_hw_aud_set_channel_swap(hdmi, HDMI_AUD_SWAP_LFE_CC);
897 mtk_hdmi_set_bits(hdmi, GRL_MIX_CTRL, MIX_CTRL_FLAT);
899 if (hdmi->aud_param.aud_input_type == HDMI_AUD_INPUT_SPDIF &&
900 hdmi->aud_param.aud_codec == HDMI_AUDIO_CODING_TYPE_DST) {
901 mtk_hdmi_hw_aud_set_bit_num(hdmi, HDMI_AUDIO_SAMPLE_SIZE_24);
902 } else if (hdmi->aud_param.aud_i2s_fmt == HDMI_I2S_MODE_LJT_24BIT) {
903 hdmi->aud_param.aud_i2s_fmt = HDMI_I2S_MODE_LJT_16BIT;
906 mtk_hdmi_hw_aud_set_i2s_fmt(hdmi, hdmi->aud_param.aud_i2s_fmt);
907 mtk_hdmi_hw_aud_set_bit_num(hdmi, HDMI_AUDIO_SAMPLE_SIZE_24);
909 dst = ((hdmi->aud_param.aud_input_type == HDMI_AUD_INPUT_SPDIF) &&
910 (hdmi->aud_param.aud_codec == HDMI_AUDIO_CODING_TYPE_DST));
911 mtk_hdmi_hw_audio_config(hdmi, dst);
913 if (hdmi->aud_param.aud_input_type == HDMI_AUD_INPUT_SPDIF)
916 chan_type = hdmi->aud_param.aud_input_chan_type;
918 mtk_hdmi_hw_aud_set_i2s_chan_num(hdmi, chan_type, chan_count);
919 mtk_hdmi_hw_aud_set_input_type(hdmi, hdmi->aud_param.aud_input_type);
924 static int mtk_hdmi_aud_set_src(struct mtk_hdmi *hdmi,
927 unsigned int sample_rate = hdmi->aud_param.codec_params.sample_rate;
929 mtk_hdmi_aud_on_off_hw_ncts(hdmi, false);
930 mtk_hdmi_hw_aud_src_disable(hdmi);
931 mtk_hdmi_clear_bits(hdmi, GRL_CFG2, CFG2_ACLK_INV);
933 if (hdmi->aud_param.aud_input_type == HDMI_AUD_INPUT_I2S) {
944 mtk_hdmi_hw_aud_set_mclk(hdmi, hdmi->aud_param.aud_mclk);
954 mtk_hdmi_hw_aud_set_mclk(hdmi, HDMI_AUD_MCLK_128FS);
957 mtk_hdmi_hw_aud_set_ncts(hdmi, sample_rate, display_mode->clock);
959 mtk_hdmi_hw_aud_src_reenable(hdmi);
963 static int mtk_hdmi_aud_output_config(struct mtk_hdmi *hdmi,
966 mtk_hdmi_hw_aud_mute(hdmi);
967 mtk_hdmi_aud_enable_packet(hdmi, false);
969 mtk_hdmi_aud_set_input(hdmi);
970 mtk_hdmi_aud_set_src(hdmi, display_mode);
971 mtk_hdmi_hw_aud_set_channel_status(hdmi,
972 hdmi->aud_param.codec_params.iec.status);
976 mtk_hdmi_aud_on_off_hw_ncts(hdmi, true);
977 mtk_hdmi_aud_enable_packet(hdmi, true);
978 mtk_hdmi_hw_aud_unmute(hdmi);
982 static int mtk_hdmi_setup_avi_infoframe(struct mtk_hdmi *hdmi,
990 &hdmi->conn, mode);
992 dev_err(hdmi->dev,
999 dev_err(hdmi->dev, "Failed to pack AVI infoframe: %zd\n", err);
1003 mtk_hdmi_hw_send_info_frame(hdmi, buffer, sizeof(buffer));
1007 static int mtk_hdmi_setup_spd_infoframe(struct mtk_hdmi *hdmi,
1017 dev_err(hdmi->dev, "Failed to initialize SPD infoframe: %zd\n",
1024 dev_err(hdmi->dev, "Failed to pack SDP infoframe: %zd\n", err);
1028 mtk_hdmi_hw_send_info_frame(hdmi, buffer, sizeof(buffer));
1032 static int mtk_hdmi_setup_audio_infoframe(struct mtk_hdmi *hdmi)
1040 dev_err(hdmi->dev, "Failed to setup audio infoframe: %zd\n",
1049 hdmi->aud_param.aud_input_chan_type);
1053 dev_err(hdmi->dev, "Failed to pack audio infoframe: %zd\n",
1058 mtk_hdmi_hw_send_info_frame(hdmi, buffer, sizeof(buffer));
1062 static int mtk_hdmi_setup_vendor_specific_infoframe(struct mtk_hdmi *hdmi,
1070 &hdmi->conn, mode);
1072 dev_err(hdmi->dev,
1079 dev_err(hdmi->dev, "Failed to pack vendor infoframe: %zd\n",
1084 mtk_hdmi_hw_send_info_frame(hdmi, buffer, sizeof(buffer));
1088 static int mtk_hdmi_output_init(struct mtk_hdmi *hdmi)
1090 struct hdmi_audio_param *aud_param = &hdmi->aud_param;
1092 hdmi->csp = HDMI_COLORSPACE_RGB;
1103 static void mtk_hdmi_audio_enable(struct mtk_hdmi *hdmi)
1105 mtk_hdmi_aud_enable_packet(hdmi, true);
1106 hdmi->audio_enable = true;
1109 static void mtk_hdmi_audio_disable(struct mtk_hdmi *hdmi)
1111 mtk_hdmi_aud_enable_packet(hdmi, false);
1112 hdmi->audio_enable = false;
1115 static int mtk_hdmi_audio_set_param(struct mtk_hdmi *hdmi,
1118 if (!hdmi->audio_enable) {
1119 dev_err(hdmi->dev, "hdmi audio is in disable state!\n");
1122 dev_dbg(hdmi->dev, "codec:%d, input:%d, channel:%d, fs:%d\n",
1125 memcpy(&hdmi->aud_param, param, sizeof(*param));
1126 return mtk_hdmi_aud_output_config(hdmi, &hdmi->mode);
1129 static int mtk_hdmi_output_set_display_mode(struct mtk_hdmi *hdmi,
1134 mtk_hdmi_hw_vid_black(hdmi, true);
1135 mtk_hdmi_hw_aud_mute(hdmi);
1136 mtk_hdmi_hw_send_av_mute(hdmi);
1137 phy_power_off(hdmi->phy);
1139 ret = mtk_hdmi_video_change_vpll(hdmi,
1142 dev_err(hdmi->dev, "Failed to set vpll: %d\n", ret);
1145 mtk_hdmi_video_set_display_mode(hdmi, mode);
1147 phy_power_on(hdmi->phy);
1148 mtk_hdmi_aud_output_config(hdmi, mode);
1150 mtk_hdmi_hw_vid_black(hdmi, false);
1151 mtk_hdmi_hw_aud_unmute(hdmi);
1152 mtk_hdmi_hw_send_av_unmute(hdmi);
1164 static int mtk_hdmi_get_all_clk(struct mtk_hdmi *hdmi,
1170 hdmi->clk[i] = of_clk_get_by_name(np,
1172 if (IS_ERR(hdmi->clk[i]))
1173 return PTR_ERR(hdmi->clk[i]);
1178 static int mtk_hdmi_clk_enable_audio(struct mtk_hdmi *hdmi)
1182 ret = clk_prepare_enable(hdmi->clk[MTK_HDMI_CLK_AUD_BCLK]);
1186 ret = clk_prepare_enable(hdmi->clk[MTK_HDMI_CLK_AUD_SPDIF]);
1192 clk_disable_unprepare(hdmi->clk[MTK_HDMI_CLK_AUD_BCLK]);
1196 static void mtk_hdmi_clk_disable_audio(struct mtk_hdmi *hdmi)
1198 clk_disable_unprepare(hdmi->clk[MTK_HDMI_CLK_AUD_BCLK]);
1199 clk_disable_unprepare(hdmi->clk[MTK_HDMI_CLK_AUD_SPDIF]);
1203 mtk_hdmi_update_plugged_status(struct mtk_hdmi *hdmi)
1207 mutex_lock(&hdmi->update_plugged_status_lock);
1208 connected = mtk_cec_hpd_high(hdmi->cec_dev);
1209 if (hdmi->plugged_cb && hdmi->codec_dev)
1210 hdmi->plugged_cb(hdmi->codec_dev, connected);
1211 mutex_unlock(&hdmi->update_plugged_status_lock);
1220 struct mtk_hdmi *hdmi = hdmi_ctx_from_conn(conn);
1221 return mtk_hdmi_update_plugged_status(hdmi);
1226 struct mtk_hdmi *hdmi = hdmi_ctx_from_conn(conn);
1228 mtk_cec_set_hpd_event(hdmi->cec_dev, NULL, NULL);
1235 struct mtk_hdmi *hdmi = hdmi_ctx_from_conn(conn);
1239 if (!hdmi->ddc_adpt)
1242 edid = drm_get_edid(conn, hdmi->ddc_adpt);
1246 hdmi->dvi_mode = !drm_detect_monitor_audio(edid);
1258 struct mtk_hdmi *hdmi = hdmi_ctx_from_conn(conn);
1261 dev_dbg(hdmi->dev, "xres=%d, yres=%d, refresh=%d, intl=%d clock=%d\n",
1265 next_bridge = drm_bridge_get_next_bridge(&hdmi->bridge);
1285 struct mtk_hdmi *hdmi = hdmi_ctx_from_conn(conn);
1287 return hdmi->bridge.encoder;
1308 struct mtk_hdmi *hdmi = dev_get_drvdata(dev);
1310 if (hdmi && hdmi->bridge.encoder && hdmi->bridge.encoder->dev)
1311 drm_helper_hpd_irq_event(hdmi->bridge.encoder->dev);
1321 struct mtk_hdmi *hdmi = hdmi_ctx_from_bridge(bridge);
1329 ret = drm_connector_init_with_ddc(bridge->encoder->dev, &hdmi->conn,
1332 hdmi->ddc_adpt);
1334 dev_err(hdmi->dev, "Failed to initialize connector: %d\n", ret);
1337 drm_connector_helper_add(&hdmi->conn, &mtk_hdmi_connector_helper_funcs);
1339 hdmi->conn.polled = DRM_CONNECTOR_POLL_HPD;
1340 hdmi->conn.interlace_allowed = true;
1341 hdmi->conn.doublescan_allowed = false;
1343 ret = drm_connector_attach_encoder(&hdmi->conn,
1346 dev_err(hdmi->dev,
1351 if (hdmi->next_bridge) {
1352 ret = drm_bridge_attach(bridge->encoder, hdmi->next_bridge,
1355 dev_err(hdmi->dev,
1361 mtk_cec_set_hpd_event(hdmi->cec_dev, mtk_hdmi_hpd_event, hdmi->dev);
1375 struct mtk_hdmi *hdmi = hdmi_ctx_from_bridge(bridge);
1377 if (!hdmi->enabled)
1380 phy_power_off(hdmi->phy);
1381 clk_disable_unprepare(hdmi->clk[MTK_HDMI_CLK_HDMI_PIXEL]);
1382 clk_disable_unprepare(hdmi->clk[MTK_HDMI_CLK_HDMI_PLL]);
1384 hdmi->enabled = false;
1389 struct mtk_hdmi *hdmi = hdmi_ctx_from_bridge(bridge);
1391 if (!hdmi->powered)
1394 mtk_hdmi_hw_1p4_version_enable(hdmi, true);
1395 mtk_hdmi_hw_make_reg_writable(hdmi, false);
1397 hdmi->powered = false;
1404 struct mtk_hdmi *hdmi = hdmi_ctx_from_bridge(bridge);
1406 dev_dbg(hdmi->dev, "cur info: name:%s, hdisplay:%d\n",
1408 dev_dbg(hdmi->dev, "hsync_start:%d,hsync_end:%d, htotal:%d",
1411 dev_dbg(hdmi->dev, "hskew:%d, vdisplay:%d\n",
1413 dev_dbg(hdmi->dev, "vsync_start:%d, vsync_end:%d, vtotal:%d",
1416 dev_dbg(hdmi->dev, "vscan:%d, flag:%d\n",
1419 drm_mode_copy(&hdmi->mode, adjusted_mode);
1424 struct mtk_hdmi *hdmi = hdmi_ctx_from_bridge(bridge);
1426 mtk_hdmi_hw_make_reg_writable(hdmi, true);
1427 mtk_hdmi_hw_1p4_version_enable(hdmi, true);
1429 hdmi->powered = true;
1432 static void mtk_hdmi_send_infoframe(struct mtk_hdmi *hdmi,
1435 mtk_hdmi_setup_audio_infoframe(hdmi);
1436 mtk_hdmi_setup_avi_infoframe(hdmi, mode);
1437 mtk_hdmi_setup_spd_infoframe(hdmi, "mediatek", "On-chip HDMI");
1439 mtk_hdmi_setup_vendor_specific_infoframe(hdmi, mode);
1444 struct mtk_hdmi *hdmi = hdmi_ctx_from_bridge(bridge);
1446 mtk_hdmi_output_set_display_mode(hdmi, &hdmi->mode);
1447 clk_prepare_enable(hdmi->clk[MTK_HDMI_CLK_HDMI_PLL]);
1448 clk_prepare_enable(hdmi->clk[MTK_HDMI_CLK_HDMI_PIXEL]);
1449 phy_power_on(hdmi->phy);
1450 mtk_hdmi_send_infoframe(hdmi, &hdmi->mode);
1452 hdmi->enabled = true;
1465 static int mtk_hdmi_dt_parse_pdata(struct mtk_hdmi *hdmi,
1476 ret = mtk_hdmi_get_all_clk(hdmi, np);
1493 dev_err(hdmi->dev, "Waiting for CEC device %pOF\n",
1499 hdmi->cec_dev = &cec_pdev->dev;
1502 * The mediatek,syscon-hdmi property contains a phandle link to the
1506 regmap = syscon_regmap_lookup_by_phandle(np, "mediatek,syscon-hdmi");
1507 ret = of_property_read_u32_index(np, "mediatek,syscon-hdmi", 1,
1508 &hdmi->sys_offset);
1517 hdmi->sys_regmap = regmap;
1520 hdmi->regs = devm_ioremap_resource(dev, mem);
1521 if (IS_ERR(hdmi->regs)) {
1522 ret = PTR_ERR(hdmi->regs);
1532 if (!of_device_is_compatible(remote, "hdmi-connector")) {
1533 hdmi->next_bridge = of_drm_find_bridge(remote);
1534 if (!hdmi->next_bridge) {
1552 hdmi->ddc_adpt = of_find_i2c_adapter_by_node(i2c_np);
1554 if (!hdmi->ddc_adpt) {
1562 put_device(hdmi->cec_dev);
1574 struct mtk_hdmi *hdmi = dev_get_drvdata(dev);
1578 dev_dbg(hdmi->dev, "%s: %u Hz, %d bit, %d channels\n", __func__,
1581 if (!hdmi->bridge.encoder)
1598 dev_err(hdmi->dev, "channel[%d] not supported!\n", chan);
1612 dev_err(hdmi->dev, "rate[%d] not supported!\n",
1631 dev_err(hdmi->dev, "%s: Invalid DAI format %d\n", __func__,
1639 mtk_hdmi_audio_set_param(hdmi, &hdmi_params);
1646 struct mtk_hdmi *hdmi = dev_get_drvdata(dev);
1648 mtk_hdmi_audio_enable(hdmi);
1655 struct mtk_hdmi *hdmi = dev_get_drvdata(dev);
1657 mtk_hdmi_audio_disable(hdmi);
1664 struct mtk_hdmi *hdmi = dev_get_drvdata(dev);
1667 mtk_hdmi_hw_aud_mute(hdmi);
1669 mtk_hdmi_hw_aud_unmute(hdmi);
1676 struct mtk_hdmi *hdmi = dev_get_drvdata(dev);
1678 memcpy(buf, hdmi->conn.eld, min(sizeof(hdmi->conn.eld), len));
1687 struct mtk_hdmi *hdmi = data;
1689 mutex_lock(&hdmi->update_plugged_status_lock);
1690 hdmi->plugged_cb = fn;
1691 hdmi->codec_dev = codec_dev;
1692 mutex_unlock(&hdmi->update_plugged_status_lock);
1694 mtk_hdmi_update_plugged_status(hdmi);
1711 struct mtk_hdmi *hdmi = dev_get_drvdata(dev);
1716 .data = hdmi,
1732 struct mtk_hdmi *hdmi;
1736 hdmi = devm_kzalloc(dev, sizeof(*hdmi), GFP_KERNEL);
1737 if (!hdmi)
1740 hdmi->dev = dev;
1741 hdmi->conf = of_device_get_match_data(dev);
1743 ret = mtk_hdmi_dt_parse_pdata(hdmi, pdev);
1747 hdmi->phy = devm_phy_get(dev, "hdmi");
1748 if (IS_ERR(hdmi->phy)) {
1749 ret = PTR_ERR(hdmi->phy);
1754 mutex_init(&hdmi->update_plugged_status_lock);
1755 platform_set_drvdata(pdev, hdmi);
1757 ret = mtk_hdmi_output_init(hdmi);
1759 dev_err(dev, "Failed to initialize hdmi output\n");
1769 hdmi->bridge.funcs = &mtk_hdmi_bridge_funcs;
1770 hdmi->bridge.of_node = pdev->dev.of_node;
1771 drm_bridge_add(&hdmi->bridge);
1773 ret = mtk_hdmi_clk_enable_audio(hdmi);
1782 drm_bridge_remove(&hdmi->bridge);
1788 struct mtk_hdmi *hdmi = platform_get_drvdata(pdev);
1790 drm_bridge_remove(&hdmi->bridge);
1791 mtk_hdmi_clk_disable_audio(hdmi);
1798 struct mtk_hdmi *hdmi = dev_get_drvdata(dev);
1800 mtk_hdmi_clk_disable_audio(hdmi);
1807 struct mtk_hdmi *hdmi = dev_get_drvdata(dev);
1810 ret = mtk_hdmi_clk_enable_audio(hdmi);
1812 dev_err(dev, "hdmi resume failed!\n");
1827 { .compatible = "mediatek,mt2701-hdmi",
1830 { .compatible = "mediatek,mt8173-hdmi",
1839 .name = "mediatek-drm-hdmi",