Lines Matching +full:bridge +full:- +full:enable
1 // SPDX-License-Identifier: GPL-2.0-only
7 #include <linux/arm-smccc.h>
24 #include <sound/hdmi-codec.h>
154 struct drm_bridge bridge; member
180 return container_of(b, struct mtk_hdmi, bridge); in hdmi_ctx_from_bridge()
185 regmap_update_bits(hdmi->regs, VIDEO_CFG_4, in mtk_hdmi_hw_vid_black()
189 static void mtk_hdmi_hw_make_reg_writable(struct mtk_hdmi *hdmi, bool enable) in mtk_hdmi_hw_make_reg_writable() argument
194 * MT8173 HDMI hardware has an output control bit to enable/disable HDMI in mtk_hdmi_hw_make_reg_writable()
197 * this control bit to enable HDMI output in supervisor mode. in mtk_hdmi_hw_make_reg_writable()
199 if (hdmi->conf && hdmi->conf->tz_disabled) in mtk_hdmi_hw_make_reg_writable()
200 regmap_update_bits(hdmi->sys_regmap, in mtk_hdmi_hw_make_reg_writable()
201 hdmi->sys_offset + HDMI_SYS_CFG20, in mtk_hdmi_hw_make_reg_writable()
202 0x80008005, enable ? 0x80000005 : 0x8000); in mtk_hdmi_hw_make_reg_writable()
207 regmap_update_bits(hdmi->sys_regmap, hdmi->sys_offset + HDMI_SYS_CFG20, in mtk_hdmi_hw_make_reg_writable()
208 HDMI_PCLK_FREE_RUN, enable ? HDMI_PCLK_FREE_RUN : 0); in mtk_hdmi_hw_make_reg_writable()
209 regmap_update_bits(hdmi->sys_regmap, hdmi->sys_offset + HDMI_SYS_CFG1C, in mtk_hdmi_hw_make_reg_writable()
210 HDMI_ON | ANLG_ON, enable ? (HDMI_ON | ANLG_ON) : 0); in mtk_hdmi_hw_make_reg_writable()
213 static void mtk_hdmi_hw_1p4_version_enable(struct mtk_hdmi *hdmi, bool enable) in mtk_hdmi_hw_1p4_version_enable() argument
215 regmap_update_bits(hdmi->sys_regmap, hdmi->sys_offset + HDMI_SYS_CFG20, in mtk_hdmi_hw_1p4_version_enable()
216 HDMI2P0_EN, enable ? 0 : HDMI2P0_EN); in mtk_hdmi_hw_1p4_version_enable()
221 regmap_set_bits(hdmi->regs, GRL_AUDIO_CFG, AUDIO_ZERO); in mtk_hdmi_hw_aud_mute()
226 regmap_clear_bits(hdmi->regs, GRL_AUDIO_CFG, AUDIO_ZERO); in mtk_hdmi_hw_aud_unmute()
231 regmap_update_bits(hdmi->sys_regmap, hdmi->sys_offset + HDMI_SYS_CFG1C, in mtk_hdmi_hw_reset()
233 regmap_update_bits(hdmi->sys_regmap, hdmi->sys_offset + HDMI_SYS_CFG1C, in mtk_hdmi_hw_reset()
235 regmap_clear_bits(hdmi->regs, GRL_CFG3, CFG3_CONTROL_PACKET_DELAY); in mtk_hdmi_hw_reset()
236 regmap_update_bits(hdmi->sys_regmap, hdmi->sys_offset + HDMI_SYS_CFG1C, in mtk_hdmi_hw_reset()
242 regmap_update_bits(hdmi->regs, GRL_CFG2, CFG2_NOTICE_EN, in mtk_hdmi_hw_enable_notice()
248 regmap_write(hdmi->regs, GRL_INT_MASK, int_mask); in mtk_hdmi_hw_write_int_mask()
251 static void mtk_hdmi_hw_enable_dvi_mode(struct mtk_hdmi *hdmi, bool enable) in mtk_hdmi_hw_enable_dvi_mode() argument
253 regmap_update_bits(hdmi->regs, GRL_CFG1, CFG1_DVI, enable ? CFG1_DVI : 0); in mtk_hdmi_hw_enable_dvi_mode()
274 dev_dbg(hdmi->dev, in mtk_hdmi_hw_send_info_frame()
296 dev_err(hdmi->dev, "Unknown infoframe type %d\n", frame_type); in mtk_hdmi_hw_send_info_frame()
299 regmap_clear_bits(hdmi->regs, ctrl_reg, ctrl_frame_en); in mtk_hdmi_hw_send_info_frame()
300 regmap_write(hdmi->regs, GRL_INFOFRM_TYPE, frame_type); in mtk_hdmi_hw_send_info_frame()
301 regmap_write(hdmi->regs, GRL_INFOFRM_VER, frame_ver); in mtk_hdmi_hw_send_info_frame()
302 regmap_write(hdmi->regs, GRL_INFOFRM_LNG, frame_len); in mtk_hdmi_hw_send_info_frame()
304 regmap_write(hdmi->regs, GRL_IFM_PORT, checksum); in mtk_hdmi_hw_send_info_frame()
306 regmap_write(hdmi->regs, GRL_IFM_PORT, frame_data[i]); in mtk_hdmi_hw_send_info_frame()
308 regmap_set_bits(hdmi->regs, ctrl_reg, ctrl_frame_en); in mtk_hdmi_hw_send_info_frame()
311 static void mtk_hdmi_hw_send_aud_packet(struct mtk_hdmi *hdmi, bool enable) in mtk_hdmi_hw_send_aud_packet() argument
313 regmap_update_bits(hdmi->regs, GRL_SHIFT_R2, in mtk_hdmi_hw_send_aud_packet()
314 AUDIO_PACKET_OFF, enable ? 0 : AUDIO_PACKET_OFF); in mtk_hdmi_hw_send_aud_packet()
319 regmap_update_bits(hdmi->sys_regmap, hdmi->sys_offset + HDMI_SYS_CFG20, in mtk_hdmi_hw_config_sys()
322 regmap_update_bits(hdmi->sys_regmap, hdmi->sys_offset + HDMI_SYS_CFG20, in mtk_hdmi_hw_config_sys()
328 regmap_update_bits(hdmi->sys_regmap, hdmi->sys_offset + HDMI_SYS_CFG20, in mtk_hdmi_hw_set_deep_color_mode()
335 regmap_clear_bits(hdmi->regs, GRL_CFG4, CTRL_AVMUTE); in mtk_hdmi_hw_send_av_mute()
337 regmap_set_bits(hdmi->regs, GRL_CFG4, CTRL_AVMUTE); in mtk_hdmi_hw_send_av_mute()
342 regmap_update_bits(hdmi->regs, GRL_CFG4, CFG4_AV_UNMUTE_EN | CFG4_AV_UNMUTE_SET, in mtk_hdmi_hw_send_av_unmute()
345 regmap_update_bits(hdmi->regs, GRL_CFG4, CFG4_AV_UNMUTE_EN | CFG4_AV_UNMUTE_SET, in mtk_hdmi_hw_send_av_unmute()
351 regmap_update_bits(hdmi->regs, GRL_CTS_CTRL, CTS_CTRL_SOFT, in mtk_hdmi_hw_ncts_enable()
356 bool enable) in mtk_hdmi_hw_ncts_auto_write_enable() argument
358 regmap_update_bits(hdmi->regs, GRL_CTS_CTRL, NCTS_WRI_ANYTIME, in mtk_hdmi_hw_ncts_auto_write_enable()
359 enable ? NCTS_WRI_ANYTIME : 0); in mtk_hdmi_hw_ncts_auto_write_enable()
365 regmap_clear_bits(hdmi->regs, GRL_CFG4, CFG4_MHL_MODE); in mtk_hdmi_hw_msic_setting()
367 if (mode->flags & DRM_MODE_FLAG_INTERLACE && in mtk_hdmi_hw_msic_setting()
368 mode->clock == 74250 && in mtk_hdmi_hw_msic_setting()
369 mode->vdisplay == 1080) in mtk_hdmi_hw_msic_setting()
370 regmap_clear_bits(hdmi->regs, GRL_CFG2, CFG2_MHL_DE_SEL); in mtk_hdmi_hw_msic_setting()
372 regmap_set_bits(hdmi->regs, GRL_CFG2, CFG2_MHL_DE_SEL); in mtk_hdmi_hw_msic_setting()
400 regmap_update_bits(hdmi->regs, GRL_CH_SWAP, 0xff, swap_bit); in mtk_hdmi_hw_aud_set_channel_swap()
421 regmap_update_bits(hdmi->regs, GRL_AOUT_CFG, AOUT_BNUM_SEL_MASK, val); in mtk_hdmi_hw_aud_set_bit_num()
429 regmap_read(hdmi->regs, GRL_CFG0, &val); in mtk_hdmi_hw_aud_set_i2s_fmt()
453 regmap_write(hdmi->regs, GRL_CFG0, val); in mtk_hdmi_hw_aud_set_i2s_fmt()
462 regmap_clear_bits(hdmi->regs, GRL_AOUT_CFG, HIGH_BIT_RATE_PACKET_ALIGN); in mtk_hdmi_hw_audio_config()
469 regmap_update_bits(hdmi->regs, GRL_AUDIO_CFG, mask, val); in mtk_hdmi_hw_audio_config()
510 regmap_write(hdmi->regs, GRL_CH_SW0, ch_switch & 0xff); in mtk_hdmi_hw_aud_set_i2s_chan_num()
511 regmap_write(hdmi->regs, GRL_CH_SW1, (ch_switch >> 8) & 0xff); in mtk_hdmi_hw_aud_set_i2s_chan_num()
512 regmap_write(hdmi->regs, GRL_CH_SW2, (ch_switch >> 16) & 0xff); in mtk_hdmi_hw_aud_set_i2s_chan_num()
513 regmap_write(hdmi->regs, GRL_I2S_UV, i2s_uv); in mtk_hdmi_hw_aud_set_i2s_chan_num()
521 regmap_read(hdmi->regs, GRL_CFG1, &val); in mtk_hdmi_hw_aud_set_input_type()
529 regmap_write(hdmi->regs, GRL_CFG1, val); in mtk_hdmi_hw_aud_set_input_type()
538 regmap_write(hdmi->regs, GRL_I2S_C_STA0 + i * 4, channel_status[i]); in mtk_hdmi_hw_aud_set_channel_status()
539 regmap_write(hdmi->regs, GRL_L_STATUS_0 + i * 4, channel_status[i]); in mtk_hdmi_hw_aud_set_channel_status()
540 regmap_write(hdmi->regs, GRL_R_STATUS_0 + i * 4, channel_status[i]); in mtk_hdmi_hw_aud_set_channel_status()
543 regmap_write(hdmi->regs, GRL_L_STATUS_0 + i * 4, 0); in mtk_hdmi_hw_aud_set_channel_status()
544 regmap_write(hdmi->regs, GRL_R_STATUS_0 + i * 4, 0); in mtk_hdmi_hw_aud_set_channel_status()
552 regmap_read(hdmi->regs, GRL_MIX_CTRL, &val); in mtk_hdmi_hw_aud_src_reenable()
555 regmap_write(hdmi->regs, GRL_MIX_CTRL, val); in mtk_hdmi_hw_aud_src_reenable()
558 regmap_write(hdmi->regs, GRL_MIX_CTRL, val); in mtk_hdmi_hw_aud_src_reenable()
566 regmap_read(hdmi->regs, GRL_MIX_CTRL, &val); in mtk_hdmi_hw_aud_src_disable()
568 regmap_write(hdmi->regs, GRL_MIX_CTRL, val); in mtk_hdmi_hw_aud_src_disable()
569 regmap_write(hdmi->regs, GRL_SHIFT_L1, 0x00); in mtk_hdmi_hw_aud_src_disable()
577 regmap_read(hdmi->regs, GRL_CFG5, &val); in mtk_hdmi_hw_aud_set_mclk()
600 regmap_write(hdmi->regs, GRL_CFG5, val); in mtk_hdmi_hw_aud_set_mclk()
608 /* Recommended N values from HDMI specification, tables 7-1 to 7-3 */
620 * hdmi_recommended_n() - Return N value recommended by HDMI specification
629 for (i = 0; i < ARRAY_SIZE(hdmi_rec_n_table) - 1; i++) { in hdmi_recommended_n()
637 return recommended->n[0]; in hdmi_recommended_n()
639 return recommended->n[1]; in hdmi_recommended_n()
641 return recommended->n[2]; in hdmi_recommended_n()
643 return recommended->n[1] * 2; in hdmi_recommended_n()
645 return recommended->n[2] * 2; in hdmi_recommended_n()
647 return recommended->n[1] * 4; in hdmi_recommended_n()
649 return recommended->n[2] * 4; in hdmi_recommended_n()
691 regmap_write(hdmi->regs, GRL_NCTS, 0); in do_hdmi_hw_aud_set_ncts()
692 regmap_write(hdmi->regs, GRL_NCTS, 0); in do_hdmi_hw_aud_set_ncts()
693 regmap_write(hdmi->regs, GRL_NCTS, 0); in do_hdmi_hw_aud_set_ncts()
706 regmap_write(hdmi->regs, GRL_NCTS, val[i]); in do_hdmi_hw_aud_set_ncts()
717 dev_dbg(hdmi->dev, "%s: sample_rate=%u, clock=%d, cts=%u, n=%u\n", in mtk_hdmi_hw_aud_set_ncts()
720 regmap_update_bits(hdmi->regs, DUMMY_304, AUDIO_I2S_NCTS_SEL, AUDIO_I2S_NCTS_SEL_64); in mtk_hdmi_hw_aud_set_ncts()
800 ret = clk_set_rate(hdmi->clk[MTK_HDMI_CLK_HDMI_PLL], clock); in mtk_hdmi_video_change_vpll()
802 dev_err(hdmi->dev, "Failed to set PLL to %u Hz: %d\n", clock, in mtk_hdmi_video_change_vpll()
807 rate = clk_get_rate(hdmi->clk[MTK_HDMI_CLK_HDMI_PLL]); in mtk_hdmi_video_change_vpll()
810 dev_warn(hdmi->dev, "Want PLL %u Hz, got %lu Hz\n", clock, in mtk_hdmi_video_change_vpll()
813 dev_dbg(hdmi->dev, "Want PLL %u Hz, got %lu Hz\n", clock, rate); in mtk_hdmi_video_change_vpll()
826 mtk_hdmi_hw_enable_dvi_mode(hdmi, hdmi->dvi_mode); in mtk_hdmi_video_set_display_mode()
840 regmap_set_bits(hdmi->regs, GRL_MIX_CTRL, MIX_CTRL_FLAT); in mtk_hdmi_aud_set_input()
842 if (hdmi->aud_param.aud_input_type == HDMI_AUD_INPUT_SPDIF && in mtk_hdmi_aud_set_input()
843 hdmi->aud_param.aud_codec == HDMI_AUDIO_CODING_TYPE_DST) { in mtk_hdmi_aud_set_input()
845 } else if (hdmi->aud_param.aud_i2s_fmt == HDMI_I2S_MODE_LJT_24BIT) { in mtk_hdmi_aud_set_input()
846 hdmi->aud_param.aud_i2s_fmt = HDMI_I2S_MODE_LJT_16BIT; in mtk_hdmi_aud_set_input()
849 mtk_hdmi_hw_aud_set_i2s_fmt(hdmi, hdmi->aud_param.aud_i2s_fmt); in mtk_hdmi_aud_set_input()
852 dst = ((hdmi->aud_param.aud_input_type == HDMI_AUD_INPUT_SPDIF) && in mtk_hdmi_aud_set_input()
853 (hdmi->aud_param.aud_codec == HDMI_AUDIO_CODING_TYPE_DST)); in mtk_hdmi_aud_set_input()
856 if (hdmi->aud_param.aud_input_type == HDMI_AUD_INPUT_SPDIF) in mtk_hdmi_aud_set_input()
859 chan_type = hdmi->aud_param.aud_input_chan_type; in mtk_hdmi_aud_set_input()
862 mtk_hdmi_hw_aud_set_input_type(hdmi, hdmi->aud_param.aud_input_type); in mtk_hdmi_aud_set_input()
868 unsigned int sample_rate = hdmi->aud_param.codec_params.sample_rate; in mtk_hdmi_aud_set_src()
872 regmap_clear_bits(hdmi->regs, GRL_CFG2, CFG2_ACLK_INV); in mtk_hdmi_aud_set_src()
874 if (hdmi->aud_param.aud_input_type == HDMI_AUD_INPUT_I2S) { in mtk_hdmi_aud_set_src()
883 return -EINVAL; in mtk_hdmi_aud_set_src()
885 mtk_hdmi_hw_aud_set_mclk(hdmi, hdmi->aud_param.aud_mclk); in mtk_hdmi_aud_set_src()
893 return -EINVAL; in mtk_hdmi_aud_set_src()
898 mtk_hdmi_hw_aud_set_ncts(hdmi, sample_rate, display_mode->clock); in mtk_hdmi_aud_set_src()
913 hdmi->aud_param.codec_params.iec.status); in mtk_hdmi_aud_output_config()
931 hdmi->curr_conn, mode); in mtk_hdmi_setup_avi_infoframe()
933 dev_err(hdmi->dev, in mtk_hdmi_setup_avi_infoframe()
940 dev_err(hdmi->dev, "Failed to pack AVI infoframe: %zd\n", err); in mtk_hdmi_setup_avi_infoframe()
950 struct drm_bridge *bridge = &hdmi->bridge; in mtk_hdmi_setup_spd_infoframe() local
955 err = hdmi_spd_infoframe_init(&frame, bridge->vendor, bridge->product); in mtk_hdmi_setup_spd_infoframe()
957 dev_err(hdmi->dev, "Failed to initialize SPD infoframe: %zd\n", in mtk_hdmi_setup_spd_infoframe()
964 dev_err(hdmi->dev, "Failed to pack SDP infoframe: %zd\n", err); in mtk_hdmi_setup_spd_infoframe()
980 dev_err(hdmi->dev, "Failed to setup audio infoframe: %zd\n", in mtk_hdmi_setup_audio_infoframe()
989 hdmi->aud_param.aud_input_chan_type); in mtk_hdmi_setup_audio_infoframe()
993 dev_err(hdmi->dev, "Failed to pack audio infoframe: %zd\n", in mtk_hdmi_setup_audio_infoframe()
1010 hdmi->curr_conn, mode); in mtk_hdmi_setup_vendor_specific_infoframe()
1012 dev_err(hdmi->dev, in mtk_hdmi_setup_vendor_specific_infoframe()
1019 dev_err(hdmi->dev, "Failed to pack vendor infoframe: %zd\n", in mtk_hdmi_setup_vendor_specific_infoframe()
1031 hdmi->audio_enable = true; in mtk_hdmi_audio_enable()
1037 hdmi->audio_enable = false; in mtk_hdmi_audio_disable()
1048 phy_power_off(hdmi->phy); in mtk_hdmi_output_set_display_mode()
1051 mode->clock * 1000); in mtk_hdmi_output_set_display_mode()
1053 dev_err(hdmi->dev, "Failed to set vpll: %d\n", ret); in mtk_hdmi_output_set_display_mode()
1058 phy_power_on(hdmi->phy); in mtk_hdmi_output_set_display_mode()
1081 hdmi->clk[i] = of_clk_get_by_name(np, in mtk_hdmi_get_all_clk()
1083 if (IS_ERR(hdmi->clk[i])) in mtk_hdmi_get_all_clk()
1084 return PTR_ERR(hdmi->clk[i]); in mtk_hdmi_get_all_clk()
1093 ret = clk_prepare_enable(hdmi->clk[MTK_HDMI_CLK_AUD_BCLK]); in mtk_hdmi_clk_enable_audio()
1097 ret = clk_prepare_enable(hdmi->clk[MTK_HDMI_CLK_AUD_SPDIF]); in mtk_hdmi_clk_enable_audio()
1099 clk_disable_unprepare(hdmi->clk[MTK_HDMI_CLK_AUD_BCLK]); in mtk_hdmi_clk_enable_audio()
1108 clk_disable_unprepare(hdmi->clk[MTK_HDMI_CLK_AUD_BCLK]); in mtk_hdmi_clk_disable_audio()
1109 clk_disable_unprepare(hdmi->clk[MTK_HDMI_CLK_AUD_SPDIF]); in mtk_hdmi_clk_disable_audio()
1117 mutex_lock(&hdmi->update_plugged_status_lock); in mtk_hdmi_update_plugged_status()
1118 connected = mtk_cec_hpd_high(hdmi->cec_dev); in mtk_hdmi_update_plugged_status()
1119 if (hdmi->plugged_cb && hdmi->codec_dev) in mtk_hdmi_update_plugged_status()
1120 hdmi->plugged_cb(hdmi->codec_dev, connected); in mtk_hdmi_update_plugged_status()
1121 mutex_unlock(&hdmi->update_plugged_status_lock); in mtk_hdmi_update_plugged_status()
1133 mtk_hdmi_bridge_mode_valid(struct drm_bridge *bridge, in mtk_hdmi_bridge_mode_valid() argument
1137 struct mtk_hdmi *hdmi = hdmi_ctx_from_bridge(bridge); in mtk_hdmi_bridge_mode_valid()
1139 dev_dbg(hdmi->dev, "xres=%d, yres=%d, refresh=%d, intl=%d clock=%d\n", in mtk_hdmi_bridge_mode_valid()
1140 mode->hdisplay, mode->vdisplay, drm_mode_vrefresh(mode), in mtk_hdmi_bridge_mode_valid()
1141 !!(mode->flags & DRM_MODE_FLAG_INTERLACE), mode->clock * 1000); in mtk_hdmi_bridge_mode_valid()
1143 if (hdmi->conf) { in mtk_hdmi_bridge_mode_valid()
1144 if (hdmi->conf->cea_modes_only && !drm_match_cea_mode(mode)) in mtk_hdmi_bridge_mode_valid()
1147 if (hdmi->conf->max_mode_clock && in mtk_hdmi_bridge_mode_valid()
1148 mode->clock > hdmi->conf->max_mode_clock) in mtk_hdmi_bridge_mode_valid()
1152 if (mode->clock < 27000) in mtk_hdmi_bridge_mode_valid()
1154 if (mode->clock > 297000) in mtk_hdmi_bridge_mode_valid()
1164 if (hdmi && hdmi->bridge.encoder && hdmi->bridge.encoder->dev) { in mtk_hdmi_hpd_event()
1168 drm_helper_hpd_irq_event(hdmi->bridge.encoder->dev); in mtk_hdmi_hpd_event()
1169 drm_bridge_hpd_notify(&hdmi->bridge, status); in mtk_hdmi_hpd_event()
1174 * Bridge callbacks
1178 mtk_hdmi_bridge_detect(struct drm_bridge *bridge, struct drm_connector *connector) in mtk_hdmi_bridge_detect() argument
1180 struct mtk_hdmi *hdmi = hdmi_ctx_from_bridge(bridge); in mtk_hdmi_bridge_detect()
1185 static const struct drm_edid *mtk_hdmi_bridge_edid_read(struct drm_bridge *bridge, in mtk_hdmi_bridge_edid_read() argument
1188 struct mtk_hdmi *hdmi = hdmi_ctx_from_bridge(bridge); in mtk_hdmi_bridge_edid_read()
1191 if (!hdmi->ddc_adpt) in mtk_hdmi_bridge_edid_read()
1193 drm_edid = drm_edid_read_ddc(connector, hdmi->ddc_adpt); in mtk_hdmi_bridge_edid_read()
1196 * FIXME: This should use !connector->display_info.has_audio (or in mtk_hdmi_bridge_edid_read()
1197 * !connector->display_info.is_hdmi) from a path that has read in mtk_hdmi_bridge_edid_read()
1202 hdmi->dvi_mode = !drm_detect_monitor_audio(edid); in mtk_hdmi_bridge_edid_read()
1208 static int mtk_hdmi_bridge_attach(struct drm_bridge *bridge, in mtk_hdmi_bridge_attach() argument
1212 struct mtk_hdmi *hdmi = hdmi_ctx_from_bridge(bridge); in mtk_hdmi_bridge_attach()
1218 return -EINVAL; in mtk_hdmi_bridge_attach()
1221 if (hdmi->next_bridge) { in mtk_hdmi_bridge_attach()
1222 ret = drm_bridge_attach(encoder, hdmi->next_bridge, in mtk_hdmi_bridge_attach()
1223 bridge, flags); in mtk_hdmi_bridge_attach()
1228 mtk_cec_set_hpd_event(hdmi->cec_dev, mtk_hdmi_hpd_event, hdmi->dev); in mtk_hdmi_bridge_attach()
1233 static bool mtk_hdmi_bridge_mode_fixup(struct drm_bridge *bridge, in mtk_hdmi_bridge_mode_fixup() argument
1240 static void mtk_hdmi_bridge_atomic_disable(struct drm_bridge *bridge, in mtk_hdmi_bridge_atomic_disable() argument
1243 struct mtk_hdmi *hdmi = hdmi_ctx_from_bridge(bridge); in mtk_hdmi_bridge_atomic_disable()
1245 if (!hdmi->enabled) in mtk_hdmi_bridge_atomic_disable()
1248 phy_power_off(hdmi->phy); in mtk_hdmi_bridge_atomic_disable()
1249 clk_disable_unprepare(hdmi->clk[MTK_HDMI_CLK_HDMI_PIXEL]); in mtk_hdmi_bridge_atomic_disable()
1250 clk_disable_unprepare(hdmi->clk[MTK_HDMI_CLK_HDMI_PLL]); in mtk_hdmi_bridge_atomic_disable()
1252 hdmi->curr_conn = NULL; in mtk_hdmi_bridge_atomic_disable()
1254 hdmi->enabled = false; in mtk_hdmi_bridge_atomic_disable()
1257 static void mtk_hdmi_bridge_atomic_post_disable(struct drm_bridge *bridge, in mtk_hdmi_bridge_atomic_post_disable() argument
1260 struct mtk_hdmi *hdmi = hdmi_ctx_from_bridge(bridge); in mtk_hdmi_bridge_atomic_post_disable()
1262 if (!hdmi->powered) in mtk_hdmi_bridge_atomic_post_disable()
1268 hdmi->powered = false; in mtk_hdmi_bridge_atomic_post_disable()
1271 static void mtk_hdmi_bridge_mode_set(struct drm_bridge *bridge, in mtk_hdmi_bridge_mode_set() argument
1275 struct mtk_hdmi *hdmi = hdmi_ctx_from_bridge(bridge); in mtk_hdmi_bridge_mode_set()
1277 dev_dbg(hdmi->dev, "cur info: name:%s, hdisplay:%d\n", in mtk_hdmi_bridge_mode_set()
1278 adjusted_mode->name, adjusted_mode->hdisplay); in mtk_hdmi_bridge_mode_set()
1279 dev_dbg(hdmi->dev, "hsync_start:%d,hsync_end:%d, htotal:%d", in mtk_hdmi_bridge_mode_set()
1280 adjusted_mode->hsync_start, adjusted_mode->hsync_end, in mtk_hdmi_bridge_mode_set()
1281 adjusted_mode->htotal); in mtk_hdmi_bridge_mode_set()
1282 dev_dbg(hdmi->dev, "hskew:%d, vdisplay:%d\n", in mtk_hdmi_bridge_mode_set()
1283 adjusted_mode->hskew, adjusted_mode->vdisplay); in mtk_hdmi_bridge_mode_set()
1284 dev_dbg(hdmi->dev, "vsync_start:%d, vsync_end:%d, vtotal:%d", in mtk_hdmi_bridge_mode_set()
1285 adjusted_mode->vsync_start, adjusted_mode->vsync_end, in mtk_hdmi_bridge_mode_set()
1286 adjusted_mode->vtotal); in mtk_hdmi_bridge_mode_set()
1287 dev_dbg(hdmi->dev, "vscan:%d, flag:%d\n", in mtk_hdmi_bridge_mode_set()
1288 adjusted_mode->vscan, adjusted_mode->flags); in mtk_hdmi_bridge_mode_set()
1290 drm_mode_copy(&hdmi->mode, adjusted_mode); in mtk_hdmi_bridge_mode_set()
1293 static void mtk_hdmi_bridge_atomic_pre_enable(struct drm_bridge *bridge, in mtk_hdmi_bridge_atomic_pre_enable() argument
1296 struct mtk_hdmi *hdmi = hdmi_ctx_from_bridge(bridge); in mtk_hdmi_bridge_atomic_pre_enable()
1301 hdmi->powered = true; in mtk_hdmi_bridge_atomic_pre_enable()
1310 if (mode->flags & DRM_MODE_FLAG_3D_MASK) in mtk_hdmi_send_infoframe()
1314 static void mtk_hdmi_bridge_atomic_enable(struct drm_bridge *bridge, in mtk_hdmi_bridge_atomic_enable() argument
1317 struct mtk_hdmi *hdmi = hdmi_ctx_from_bridge(bridge); in mtk_hdmi_bridge_atomic_enable()
1320 hdmi->curr_conn = drm_atomic_get_new_connector_for_encoder(state, in mtk_hdmi_bridge_atomic_enable()
1321 bridge->encoder); in mtk_hdmi_bridge_atomic_enable()
1323 mtk_hdmi_output_set_display_mode(hdmi, &hdmi->mode); in mtk_hdmi_bridge_atomic_enable()
1324 clk_prepare_enable(hdmi->clk[MTK_HDMI_CLK_HDMI_PLL]); in mtk_hdmi_bridge_atomic_enable()
1325 clk_prepare_enable(hdmi->clk[MTK_HDMI_CLK_HDMI_PIXEL]); in mtk_hdmi_bridge_atomic_enable()
1326 phy_power_on(hdmi->phy); in mtk_hdmi_bridge_atomic_enable()
1327 mtk_hdmi_send_infoframe(hdmi, &hdmi->mode); in mtk_hdmi_bridge_atomic_enable()
1329 hdmi->enabled = true; in mtk_hdmi_bridge_atomic_enable()
1359 cec_np = of_get_compatible_child(np->parent, "mediatek,mt8173-cec"); in mtk_hdmi_get_cec_dev()
1361 return dev_err_probe(dev, -EINVAL, "Failed to find CEC node\n"); in mtk_hdmi_get_cec_dev()
1365 dev_err(hdmi->dev, "Waiting for CEC device %pOF\n", in mtk_hdmi_get_cec_dev()
1368 return -EPROBE_DEFER; in mtk_hdmi_get_cec_dev()
1373 * The mediatek,syscon-hdmi property contains a phandle link to the in mtk_hdmi_get_cec_dev()
1377 hdmi->sys_regmap = syscon_regmap_lookup_by_phandle_args(np, "mediatek,syscon-hdmi", in mtk_hdmi_get_cec_dev()
1378 1, &hdmi->sys_offset); in mtk_hdmi_get_cec_dev()
1379 if (IS_ERR(hdmi->sys_regmap)) in mtk_hdmi_get_cec_dev()
1380 return dev_err_probe(dev, PTR_ERR(hdmi->sys_regmap), in mtk_hdmi_get_cec_dev()
1383 hdmi->cec_dev = &cec_pdev->dev; in mtk_hdmi_get_cec_dev()
1390 struct device *dev = &pdev->dev; in mtk_hdmi_dt_parse_pdata()
1391 struct device_node *np = dev->of_node; in mtk_hdmi_dt_parse_pdata()
1399 hdmi->regs = device_node_to_regmap(dev->of_node); in mtk_hdmi_dt_parse_pdata()
1400 if (IS_ERR(hdmi->regs)) in mtk_hdmi_dt_parse_pdata()
1401 return PTR_ERR(hdmi->regs); in mtk_hdmi_dt_parse_pdata()
1405 return -EINVAL; in mtk_hdmi_dt_parse_pdata()
1407 if (!of_device_is_compatible(remote, "hdmi-connector")) { in mtk_hdmi_dt_parse_pdata()
1408 hdmi->next_bridge = of_drm_find_bridge(remote); in mtk_hdmi_dt_parse_pdata()
1409 if (!hdmi->next_bridge) { in mtk_hdmi_dt_parse_pdata()
1410 dev_err(dev, "Waiting for external bridge\n"); in mtk_hdmi_dt_parse_pdata()
1412 return -EPROBE_DEFER; in mtk_hdmi_dt_parse_pdata()
1416 i2c_np = of_parse_phandle(remote, "ddc-i2c-bus", 0); in mtk_hdmi_dt_parse_pdata()
1419 return dev_err_probe(dev, -EINVAL, "No ddc-i2c-bus in connector\n"); in mtk_hdmi_dt_parse_pdata()
1421 hdmi->ddc_adpt = of_find_i2c_adapter_by_node(i2c_np); in mtk_hdmi_dt_parse_pdata()
1423 if (!hdmi->ddc_adpt) in mtk_hdmi_dt_parse_pdata()
1424 return dev_err_probe(dev, -EINVAL, "Failed to get ddc i2c adapter by node\n"); in mtk_hdmi_dt_parse_pdata()
1442 unsigned int chan = params->cea.channels; in mtk_hdmi_audio_params()
1444 dev_dbg(hdmi->dev, "%s: %u Hz, %d bit, %d channels\n", __func__, in mtk_hdmi_audio_params()
1445 params->sample_rate, params->sample_width, chan); in mtk_hdmi_audio_params()
1447 if (!hdmi->bridge.encoder) in mtk_hdmi_audio_params()
1448 return -ENODEV; in mtk_hdmi_audio_params()
1464 dev_err(hdmi->dev, "channel[%d] not supported!\n", chan); in mtk_hdmi_audio_params()
1465 return -EINVAL; in mtk_hdmi_audio_params()
1468 switch (params->sample_rate) { in mtk_hdmi_audio_params()
1478 dev_err(hdmi->dev, "rate[%d] not supported!\n", in mtk_hdmi_audio_params()
1479 params->sample_rate); in mtk_hdmi_audio_params()
1480 return -EINVAL; in mtk_hdmi_audio_params()
1483 switch (daifmt->fmt) { in mtk_hdmi_audio_params()
1497 dev_err(hdmi->dev, "%s: Invalid DAI format %d\n", __func__, in mtk_hdmi_audio_params()
1498 daifmt->fmt); in mtk_hdmi_audio_params()
1499 return -EINVAL; in mtk_hdmi_audio_params()
1502 memcpy(&hdmi->aud_param, &aud_params, sizeof(aud_params)); in mtk_hdmi_audio_params()
1504 dev_dbg(hdmi->dev, "codec:%d, input:%d, channel:%d, fs:%d\n", in mtk_hdmi_audio_params()
1517 if (!hdmi->audio_enable) { in mtk_hdmi_audio_hw_params()
1518 dev_err(hdmi->dev, "hdmi audio is in disable state!\n"); in mtk_hdmi_audio_hw_params()
1519 return -EINVAL; in mtk_hdmi_audio_hw_params()
1523 mtk_hdmi_aud_output_config(hdmi, &hdmi->mode); in mtk_hdmi_audio_hw_params()
1546 bool enable, int direction) in mtk_hdmi_audio_mute() argument
1550 if (enable) in mtk_hdmi_audio_mute()
1562 if (hdmi->enabled) in mtk_hdmi_audio_get_eld()
1563 memcpy(buf, hdmi->curr_conn->eld, min(sizeof(hdmi->curr_conn->eld), len)); in mtk_hdmi_audio_get_eld()
1572 mutex_lock(&hdmi->update_plugged_status_lock); in mtk_hdmi_audio_set_plugged_cb()
1573 hdmi->plugged_cb = fn; in mtk_hdmi_audio_set_plugged_cb()
1574 hdmi->codec_dev = codec_dev; in mtk_hdmi_audio_set_plugged_cb()
1575 mutex_unlock(&hdmi->update_plugged_status_lock); in mtk_hdmi_audio_set_plugged_cb()
1607 struct hdmi_audio_param *aud_param = &hdmi->aud_param; in mtk_hdmi_register_audio_driver()
1617 aud_param->aud_codec = HDMI_AUDIO_CODING_TYPE_PCM; in mtk_hdmi_register_audio_driver()
1618 aud_param->aud_sample_size = HDMI_AUDIO_SAMPLE_SIZE_16; in mtk_hdmi_register_audio_driver()
1619 aud_param->aud_input_type = HDMI_AUD_INPUT_I2S; in mtk_hdmi_register_audio_driver()
1620 aud_param->aud_i2s_fmt = HDMI_I2S_MODE_I2S_24BIT; in mtk_hdmi_register_audio_driver()
1621 aud_param->aud_mclk = HDMI_AUD_MCLK_128FS; in mtk_hdmi_register_audio_driver()
1622 aud_param->aud_input_chan_type = HDMI_AUD_CHAN_TYPE_2_0; in mtk_hdmi_register_audio_driver()
1624 hdmi->audio_pdev = platform_device_register_data(dev, in mtk_hdmi_register_audio_driver()
1629 if (IS_ERR(hdmi->audio_pdev)) in mtk_hdmi_register_audio_driver()
1630 return PTR_ERR(hdmi->audio_pdev); in mtk_hdmi_register_audio_driver()
1633 hdmi->audio_pdev); in mtk_hdmi_register_audio_driver()
1643 struct device *dev = &pdev->dev; in mtk_hdmi_probe()
1646 hdmi = devm_drm_bridge_alloc(dev, struct mtk_hdmi, bridge, in mtk_hdmi_probe()
1651 hdmi->dev = dev; in mtk_hdmi_probe()
1652 hdmi->conf = of_device_get_match_data(dev); in mtk_hdmi_probe()
1658 hdmi->phy = devm_phy_get(dev, "hdmi"); in mtk_hdmi_probe()
1659 if (IS_ERR(hdmi->phy)) in mtk_hdmi_probe()
1660 return dev_err_probe(dev, PTR_ERR(hdmi->phy), in mtk_hdmi_probe()
1663 mutex_init(&hdmi->update_plugged_status_lock); in mtk_hdmi_probe()
1671 hdmi->bridge.of_node = pdev->dev.of_node; in mtk_hdmi_probe()
1672 hdmi->bridge.ops = DRM_BRIDGE_OP_DETECT | DRM_BRIDGE_OP_EDID in mtk_hdmi_probe()
1674 hdmi->bridge.type = DRM_MODE_CONNECTOR_HDMIA; in mtk_hdmi_probe()
1675 hdmi->bridge.vendor = "MediaTek"; in mtk_hdmi_probe()
1676 hdmi->bridge.product = "On-Chip HDMI"; in mtk_hdmi_probe()
1678 ret = devm_drm_bridge_add(dev, &hdmi->bridge); in mtk_hdmi_probe()
1680 return dev_err_probe(dev, ret, "Failed to add bridge\n"); in mtk_hdmi_probe()
1685 "Failed to enable audio clocks\n"); in mtk_hdmi_probe()
1725 { .compatible = "mediatek,mt2701-hdmi", .data = &mtk_hdmi_conf_mt2701 },
1726 { .compatible = "mediatek,mt8167-hdmi", .data = &mtk_hdmi_conf_mt8167 },
1727 { .compatible = "mediatek,mt8173-hdmi" },
1736 .name = "mediatek-drm-hdmi",