Lines Matching +full:hdmi +full:- +full:bridge
1 // SPDX-License-Identifier: GPL-2.0-only
7 #include <linux/arm-smccc.h>
10 #include <linux/hdmi.h>
24 #include <sound/hdmi-codec.h>
155 struct drm_bridge bridge; member
187 return container_of(b, struct mtk_hdmi, bridge); in hdmi_ctx_from_bridge()
190 static u32 mtk_hdmi_read(struct mtk_hdmi *hdmi, u32 offset) in mtk_hdmi_read() argument
192 return readl(hdmi->regs + offset); in mtk_hdmi_read()
195 static void mtk_hdmi_write(struct mtk_hdmi *hdmi, u32 offset, u32 val) in mtk_hdmi_write() argument
197 writel(val, hdmi->regs + offset); in mtk_hdmi_write()
200 static void mtk_hdmi_clear_bits(struct mtk_hdmi *hdmi, u32 offset, u32 bits) in mtk_hdmi_clear_bits() argument
202 void __iomem *reg = hdmi->regs + offset; in mtk_hdmi_clear_bits()
210 static void mtk_hdmi_set_bits(struct mtk_hdmi *hdmi, u32 offset, u32 bits) in mtk_hdmi_set_bits() argument
212 void __iomem *reg = hdmi->regs + offset; in mtk_hdmi_set_bits()
220 static void mtk_hdmi_mask(struct mtk_hdmi *hdmi, u32 offset, u32 val, u32 mask) in mtk_hdmi_mask() argument
222 void __iomem *reg = hdmi->regs + offset; in mtk_hdmi_mask()
230 static void mtk_hdmi_hw_vid_black(struct mtk_hdmi *hdmi, bool black) in mtk_hdmi_hw_vid_black() argument
232 mtk_hdmi_mask(hdmi, VIDEO_CFG_4, black ? GEN_RGB : NORMAL_PATH, in mtk_hdmi_hw_vid_black()
236 static void mtk_hdmi_hw_make_reg_writable(struct mtk_hdmi *hdmi, bool enable) in mtk_hdmi_hw_make_reg_writable() argument
241 * MT8173 HDMI hardware has an output control bit to enable/disable HDMI in mtk_hdmi_hw_make_reg_writable()
243 * The ARM trusted firmware provides an API for the HDMI driver to set in mtk_hdmi_hw_make_reg_writable()
244 * this control bit to enable HDMI output in supervisor mode. in mtk_hdmi_hw_make_reg_writable()
246 if (hdmi->conf && hdmi->conf->tz_disabled) in mtk_hdmi_hw_make_reg_writable()
247 regmap_update_bits(hdmi->sys_regmap, in mtk_hdmi_hw_make_reg_writable()
248 hdmi->sys_offset + HDMI_SYS_CFG20, in mtk_hdmi_hw_make_reg_writable()
254 regmap_update_bits(hdmi->sys_regmap, hdmi->sys_offset + HDMI_SYS_CFG20, in mtk_hdmi_hw_make_reg_writable()
256 regmap_update_bits(hdmi->sys_regmap, hdmi->sys_offset + HDMI_SYS_CFG1C, in mtk_hdmi_hw_make_reg_writable()
260 static void mtk_hdmi_hw_1p4_version_enable(struct mtk_hdmi *hdmi, bool enable) in mtk_hdmi_hw_1p4_version_enable() argument
262 regmap_update_bits(hdmi->sys_regmap, hdmi->sys_offset + HDMI_SYS_CFG20, in mtk_hdmi_hw_1p4_version_enable()
266 static void mtk_hdmi_hw_aud_mute(struct mtk_hdmi *hdmi) in mtk_hdmi_hw_aud_mute() argument
268 mtk_hdmi_set_bits(hdmi, GRL_AUDIO_CFG, AUDIO_ZERO); in mtk_hdmi_hw_aud_mute()
271 static void mtk_hdmi_hw_aud_unmute(struct mtk_hdmi *hdmi) in mtk_hdmi_hw_aud_unmute() argument
273 mtk_hdmi_clear_bits(hdmi, GRL_AUDIO_CFG, AUDIO_ZERO); in mtk_hdmi_hw_aud_unmute()
276 static void mtk_hdmi_hw_reset(struct mtk_hdmi *hdmi) in mtk_hdmi_hw_reset() argument
278 regmap_update_bits(hdmi->sys_regmap, hdmi->sys_offset + HDMI_SYS_CFG1C, in mtk_hdmi_hw_reset()
280 regmap_update_bits(hdmi->sys_regmap, hdmi->sys_offset + HDMI_SYS_CFG1C, in mtk_hdmi_hw_reset()
282 mtk_hdmi_clear_bits(hdmi, GRL_CFG3, CFG3_CONTROL_PACKET_DELAY); in mtk_hdmi_hw_reset()
283 regmap_update_bits(hdmi->sys_regmap, hdmi->sys_offset + HDMI_SYS_CFG1C, in mtk_hdmi_hw_reset()
287 static void mtk_hdmi_hw_enable_notice(struct mtk_hdmi *hdmi, bool enable_notice) in mtk_hdmi_hw_enable_notice() argument
289 mtk_hdmi_mask(hdmi, GRL_CFG2, enable_notice ? CFG2_NOTICE_EN : 0, in mtk_hdmi_hw_enable_notice()
293 static void mtk_hdmi_hw_write_int_mask(struct mtk_hdmi *hdmi, u32 int_mask) in mtk_hdmi_hw_write_int_mask() argument
295 mtk_hdmi_write(hdmi, GRL_INT_MASK, int_mask); in mtk_hdmi_hw_write_int_mask()
298 static void mtk_hdmi_hw_enable_dvi_mode(struct mtk_hdmi *hdmi, bool enable) in mtk_hdmi_hw_enable_dvi_mode() argument
300 mtk_hdmi_mask(hdmi, GRL_CFG1, enable ? CFG1_DVI : 0, CFG1_DVI); in mtk_hdmi_hw_enable_dvi_mode()
303 static void mtk_hdmi_hw_send_info_frame(struct mtk_hdmi *hdmi, u8 *buffer, in mtk_hdmi_hw_send_info_frame() argument
321 dev_dbg(hdmi->dev, in mtk_hdmi_hw_send_info_frame()
343 dev_err(hdmi->dev, "Unknown infoframe type %d\n", frame_type); in mtk_hdmi_hw_send_info_frame()
346 mtk_hdmi_clear_bits(hdmi, ctrl_reg, ctrl_frame_en); in mtk_hdmi_hw_send_info_frame()
347 mtk_hdmi_write(hdmi, GRL_INFOFRM_TYPE, frame_type); in mtk_hdmi_hw_send_info_frame()
348 mtk_hdmi_write(hdmi, GRL_INFOFRM_VER, frame_ver); in mtk_hdmi_hw_send_info_frame()
349 mtk_hdmi_write(hdmi, GRL_INFOFRM_LNG, frame_len); in mtk_hdmi_hw_send_info_frame()
351 mtk_hdmi_write(hdmi, GRL_IFM_PORT, checksum); in mtk_hdmi_hw_send_info_frame()
353 mtk_hdmi_write(hdmi, GRL_IFM_PORT, frame_data[i]); in mtk_hdmi_hw_send_info_frame()
355 mtk_hdmi_set_bits(hdmi, ctrl_reg, ctrl_frame_en); in mtk_hdmi_hw_send_info_frame()
358 static void mtk_hdmi_hw_send_aud_packet(struct mtk_hdmi *hdmi, bool enable) in mtk_hdmi_hw_send_aud_packet() argument
360 mtk_hdmi_mask(hdmi, GRL_SHIFT_R2, enable ? 0 : AUDIO_PACKET_OFF, in mtk_hdmi_hw_send_aud_packet()
364 static void mtk_hdmi_hw_config_sys(struct mtk_hdmi *hdmi) in mtk_hdmi_hw_config_sys() argument
366 regmap_update_bits(hdmi->sys_regmap, hdmi->sys_offset + HDMI_SYS_CFG20, in mtk_hdmi_hw_config_sys()
369 regmap_update_bits(hdmi->sys_regmap, hdmi->sys_offset + HDMI_SYS_CFG20, in mtk_hdmi_hw_config_sys()
373 static void mtk_hdmi_hw_set_deep_color_mode(struct mtk_hdmi *hdmi) in mtk_hdmi_hw_set_deep_color_mode() argument
375 regmap_update_bits(hdmi->sys_regmap, hdmi->sys_offset + HDMI_SYS_CFG20, in mtk_hdmi_hw_set_deep_color_mode()
380 static void mtk_hdmi_hw_send_av_mute(struct mtk_hdmi *hdmi) in mtk_hdmi_hw_send_av_mute() argument
382 mtk_hdmi_clear_bits(hdmi, GRL_CFG4, CTRL_AVMUTE); in mtk_hdmi_hw_send_av_mute()
384 mtk_hdmi_set_bits(hdmi, GRL_CFG4, CTRL_AVMUTE); in mtk_hdmi_hw_send_av_mute()
387 static void mtk_hdmi_hw_send_av_unmute(struct mtk_hdmi *hdmi) in mtk_hdmi_hw_send_av_unmute() argument
389 mtk_hdmi_mask(hdmi, GRL_CFG4, CFG4_AV_UNMUTE_EN, in mtk_hdmi_hw_send_av_unmute()
392 mtk_hdmi_mask(hdmi, GRL_CFG4, CFG4_AV_UNMUTE_SET, in mtk_hdmi_hw_send_av_unmute()
396 static void mtk_hdmi_hw_ncts_enable(struct mtk_hdmi *hdmi, bool on) in mtk_hdmi_hw_ncts_enable() argument
398 mtk_hdmi_mask(hdmi, GRL_CTS_CTRL, on ? 0 : CTS_CTRL_SOFT, in mtk_hdmi_hw_ncts_enable()
402 static void mtk_hdmi_hw_ncts_auto_write_enable(struct mtk_hdmi *hdmi, in mtk_hdmi_hw_ncts_auto_write_enable() argument
405 mtk_hdmi_mask(hdmi, GRL_CTS_CTRL, enable ? NCTS_WRI_ANYTIME : 0, in mtk_hdmi_hw_ncts_auto_write_enable()
409 static void mtk_hdmi_hw_msic_setting(struct mtk_hdmi *hdmi, in mtk_hdmi_hw_msic_setting() argument
412 mtk_hdmi_clear_bits(hdmi, GRL_CFG4, CFG4_MHL_MODE); in mtk_hdmi_hw_msic_setting()
414 if (mode->flags & DRM_MODE_FLAG_INTERLACE && in mtk_hdmi_hw_msic_setting()
415 mode->clock == 74250 && in mtk_hdmi_hw_msic_setting()
416 mode->vdisplay == 1080) in mtk_hdmi_hw_msic_setting()
417 mtk_hdmi_clear_bits(hdmi, GRL_CFG2, CFG2_MHL_DE_SEL); in mtk_hdmi_hw_msic_setting()
419 mtk_hdmi_set_bits(hdmi, GRL_CFG2, CFG2_MHL_DE_SEL); in mtk_hdmi_hw_msic_setting()
422 static void mtk_hdmi_hw_aud_set_channel_swap(struct mtk_hdmi *hdmi, in mtk_hdmi_hw_aud_set_channel_swap() argument
447 mtk_hdmi_mask(hdmi, GRL_CH_SWAP, swap_bit, 0xff); in mtk_hdmi_hw_aud_set_channel_swap()
450 static void mtk_hdmi_hw_aud_set_bit_num(struct mtk_hdmi *hdmi, in mtk_hdmi_hw_aud_set_bit_num() argument
468 mtk_hdmi_mask(hdmi, GRL_AOUT_CFG, val, AOUT_BNUM_SEL_MASK); in mtk_hdmi_hw_aud_set_bit_num()
471 static void mtk_hdmi_hw_aud_set_i2s_fmt(struct mtk_hdmi *hdmi, in mtk_hdmi_hw_aud_set_i2s_fmt() argument
476 val = mtk_hdmi_read(hdmi, GRL_CFG0); in mtk_hdmi_hw_aud_set_i2s_fmt()
500 mtk_hdmi_write(hdmi, GRL_CFG0, val); in mtk_hdmi_hw_aud_set_i2s_fmt()
503 static void mtk_hdmi_hw_audio_config(struct mtk_hdmi *hdmi, bool dst) in mtk_hdmi_hw_audio_config() argument
509 mtk_hdmi_clear_bits(hdmi, GRL_AOUT_CFG, HIGH_BIT_RATE_PACKET_ALIGN); in mtk_hdmi_hw_audio_config()
516 mtk_hdmi_mask(hdmi, GRL_AUDIO_CFG, val, mask); in mtk_hdmi_hw_audio_config()
519 static void mtk_hdmi_hw_aud_set_i2s_chan_num(struct mtk_hdmi *hdmi, in mtk_hdmi_hw_aud_set_i2s_chan_num() argument
557 mtk_hdmi_write(hdmi, GRL_CH_SW0, ch_switch & 0xff); in mtk_hdmi_hw_aud_set_i2s_chan_num()
558 mtk_hdmi_write(hdmi, GRL_CH_SW1, (ch_switch >> 8) & 0xff); in mtk_hdmi_hw_aud_set_i2s_chan_num()
559 mtk_hdmi_write(hdmi, GRL_CH_SW2, (ch_switch >> 16) & 0xff); in mtk_hdmi_hw_aud_set_i2s_chan_num()
560 mtk_hdmi_write(hdmi, GRL_I2S_UV, i2s_uv); in mtk_hdmi_hw_aud_set_i2s_chan_num()
563 static void mtk_hdmi_hw_aud_set_input_type(struct mtk_hdmi *hdmi, in mtk_hdmi_hw_aud_set_input_type() argument
568 val = mtk_hdmi_read(hdmi, GRL_CFG1); in mtk_hdmi_hw_aud_set_input_type()
576 mtk_hdmi_write(hdmi, GRL_CFG1, val); in mtk_hdmi_hw_aud_set_input_type()
579 static void mtk_hdmi_hw_aud_set_channel_status(struct mtk_hdmi *hdmi, in mtk_hdmi_hw_aud_set_channel_status() argument
585 mtk_hdmi_write(hdmi, GRL_I2S_C_STA0 + i * 4, channel_status[i]); in mtk_hdmi_hw_aud_set_channel_status()
586 mtk_hdmi_write(hdmi, GRL_L_STATUS_0 + i * 4, channel_status[i]); in mtk_hdmi_hw_aud_set_channel_status()
587 mtk_hdmi_write(hdmi, GRL_R_STATUS_0 + i * 4, channel_status[i]); in mtk_hdmi_hw_aud_set_channel_status()
590 mtk_hdmi_write(hdmi, GRL_L_STATUS_0 + i * 4, 0); in mtk_hdmi_hw_aud_set_channel_status()
591 mtk_hdmi_write(hdmi, GRL_R_STATUS_0 + i * 4, 0); in mtk_hdmi_hw_aud_set_channel_status()
595 static void mtk_hdmi_hw_aud_src_reenable(struct mtk_hdmi *hdmi) in mtk_hdmi_hw_aud_src_reenable() argument
599 val = mtk_hdmi_read(hdmi, GRL_MIX_CTRL); in mtk_hdmi_hw_aud_src_reenable()
602 mtk_hdmi_write(hdmi, GRL_MIX_CTRL, val); in mtk_hdmi_hw_aud_src_reenable()
605 mtk_hdmi_write(hdmi, GRL_MIX_CTRL, val); in mtk_hdmi_hw_aud_src_reenable()
609 static void mtk_hdmi_hw_aud_src_disable(struct mtk_hdmi *hdmi) in mtk_hdmi_hw_aud_src_disable() argument
613 val = mtk_hdmi_read(hdmi, GRL_MIX_CTRL); in mtk_hdmi_hw_aud_src_disable()
615 mtk_hdmi_write(hdmi, GRL_MIX_CTRL, val); in mtk_hdmi_hw_aud_src_disable()
616 mtk_hdmi_write(hdmi, GRL_SHIFT_L1, 0x00); in mtk_hdmi_hw_aud_src_disable()
619 static void mtk_hdmi_hw_aud_set_mclk(struct mtk_hdmi *hdmi, in mtk_hdmi_hw_aud_set_mclk() argument
624 val = mtk_hdmi_read(hdmi, GRL_CFG5); in mtk_hdmi_hw_aud_set_mclk()
647 mtk_hdmi_write(hdmi, GRL_CFG5, val); in mtk_hdmi_hw_aud_set_mclk()
655 /* Recommended N values from HDMI specification, tables 7-1 to 7-3 */
667 * hdmi_recommended_n() - Return N value recommended by HDMI specification
676 for (i = 0; i < ARRAY_SIZE(hdmi_rec_n_table) - 1; i++) { in hdmi_recommended_n()
684 return recommended->n[0]; in hdmi_recommended_n()
686 return recommended->n[1]; in hdmi_recommended_n()
688 return recommended->n[2]; in hdmi_recommended_n()
690 return recommended->n[1] * 2; in hdmi_recommended_n()
692 return recommended->n[2] * 2; in hdmi_recommended_n()
694 return recommended->n[1] * 4; in hdmi_recommended_n()
696 return recommended->n[2] * 4; in hdmi_recommended_n()
725 static void do_hdmi_hw_aud_set_ncts(struct mtk_hdmi *hdmi, unsigned int n, in do_hdmi_hw_aud_set_ncts() argument
731 mtk_hdmi_write(hdmi, GRL_NCTS, 0); in do_hdmi_hw_aud_set_ncts()
732 mtk_hdmi_write(hdmi, GRL_NCTS, 0); in do_hdmi_hw_aud_set_ncts()
733 mtk_hdmi_write(hdmi, GRL_NCTS, 0); in do_hdmi_hw_aud_set_ncts()
746 mtk_hdmi_write(hdmi, GRL_NCTS, val[i]); in do_hdmi_hw_aud_set_ncts()
749 static void mtk_hdmi_hw_aud_set_ncts(struct mtk_hdmi *hdmi, in mtk_hdmi_hw_aud_set_ncts() argument
758 dev_dbg(hdmi->dev, "%s: sample_rate=%u, clock=%d, cts=%u, n=%u\n", in mtk_hdmi_hw_aud_set_ncts()
761 mtk_hdmi_mask(hdmi, DUMMY_304, AUDIO_I2S_NCTS_SEL_64, in mtk_hdmi_hw_aud_set_ncts()
763 do_hdmi_hw_aud_set_ncts(hdmi, n, cts); in mtk_hdmi_hw_aud_set_ncts()
836 static int mtk_hdmi_video_change_vpll(struct mtk_hdmi *hdmi, u32 clock) in mtk_hdmi_video_change_vpll() argument
842 ret = clk_set_rate(hdmi->clk[MTK_HDMI_CLK_HDMI_PLL], clock); in mtk_hdmi_video_change_vpll()
844 dev_err(hdmi->dev, "Failed to set PLL to %u Hz: %d\n", clock, in mtk_hdmi_video_change_vpll()
849 rate = clk_get_rate(hdmi->clk[MTK_HDMI_CLK_HDMI_PLL]); in mtk_hdmi_video_change_vpll()
852 dev_warn(hdmi->dev, "Want PLL %u Hz, got %lu Hz\n", clock, in mtk_hdmi_video_change_vpll()
855 dev_dbg(hdmi->dev, "Want PLL %u Hz, got %lu Hz\n", clock, rate); in mtk_hdmi_video_change_vpll()
857 mtk_hdmi_hw_config_sys(hdmi); in mtk_hdmi_video_change_vpll()
858 mtk_hdmi_hw_set_deep_color_mode(hdmi); in mtk_hdmi_video_change_vpll()
862 static void mtk_hdmi_video_set_display_mode(struct mtk_hdmi *hdmi, in mtk_hdmi_video_set_display_mode() argument
865 mtk_hdmi_hw_reset(hdmi); in mtk_hdmi_video_set_display_mode()
866 mtk_hdmi_hw_enable_notice(hdmi, true); in mtk_hdmi_video_set_display_mode()
867 mtk_hdmi_hw_write_int_mask(hdmi, 0xff); in mtk_hdmi_video_set_display_mode()
868 mtk_hdmi_hw_enable_dvi_mode(hdmi, hdmi->dvi_mode); in mtk_hdmi_video_set_display_mode()
869 mtk_hdmi_hw_ncts_auto_write_enable(hdmi, true); in mtk_hdmi_video_set_display_mode()
871 mtk_hdmi_hw_msic_setting(hdmi, mode); in mtk_hdmi_video_set_display_mode()
875 static void mtk_hdmi_aud_set_input(struct mtk_hdmi *hdmi) in mtk_hdmi_aud_set_input() argument
881 mtk_hdmi_hw_aud_set_channel_swap(hdmi, HDMI_AUD_SWAP_LFE_CC); in mtk_hdmi_aud_set_input()
882 mtk_hdmi_set_bits(hdmi, GRL_MIX_CTRL, MIX_CTRL_FLAT); in mtk_hdmi_aud_set_input()
884 if (hdmi->aud_param.aud_input_type == HDMI_AUD_INPUT_SPDIF && in mtk_hdmi_aud_set_input()
885 hdmi->aud_param.aud_codec == HDMI_AUDIO_CODING_TYPE_DST) { in mtk_hdmi_aud_set_input()
886 mtk_hdmi_hw_aud_set_bit_num(hdmi, HDMI_AUDIO_SAMPLE_SIZE_24); in mtk_hdmi_aud_set_input()
887 } else if (hdmi->aud_param.aud_i2s_fmt == HDMI_I2S_MODE_LJT_24BIT) { in mtk_hdmi_aud_set_input()
888 hdmi->aud_param.aud_i2s_fmt = HDMI_I2S_MODE_LJT_16BIT; in mtk_hdmi_aud_set_input()
891 mtk_hdmi_hw_aud_set_i2s_fmt(hdmi, hdmi->aud_param.aud_i2s_fmt); in mtk_hdmi_aud_set_input()
892 mtk_hdmi_hw_aud_set_bit_num(hdmi, HDMI_AUDIO_SAMPLE_SIZE_24); in mtk_hdmi_aud_set_input()
894 dst = ((hdmi->aud_param.aud_input_type == HDMI_AUD_INPUT_SPDIF) && in mtk_hdmi_aud_set_input()
895 (hdmi->aud_param.aud_codec == HDMI_AUDIO_CODING_TYPE_DST)); in mtk_hdmi_aud_set_input()
896 mtk_hdmi_hw_audio_config(hdmi, dst); in mtk_hdmi_aud_set_input()
898 if (hdmi->aud_param.aud_input_type == HDMI_AUD_INPUT_SPDIF) in mtk_hdmi_aud_set_input()
901 chan_type = hdmi->aud_param.aud_input_chan_type; in mtk_hdmi_aud_set_input()
903 mtk_hdmi_hw_aud_set_i2s_chan_num(hdmi, chan_type, chan_count); in mtk_hdmi_aud_set_input()
904 mtk_hdmi_hw_aud_set_input_type(hdmi, hdmi->aud_param.aud_input_type); in mtk_hdmi_aud_set_input()
907 static int mtk_hdmi_aud_set_src(struct mtk_hdmi *hdmi, in mtk_hdmi_aud_set_src() argument
910 unsigned int sample_rate = hdmi->aud_param.codec_params.sample_rate; in mtk_hdmi_aud_set_src()
912 mtk_hdmi_hw_ncts_enable(hdmi, false); in mtk_hdmi_aud_set_src()
913 mtk_hdmi_hw_aud_src_disable(hdmi); in mtk_hdmi_aud_set_src()
914 mtk_hdmi_clear_bits(hdmi, GRL_CFG2, CFG2_ACLK_INV); in mtk_hdmi_aud_set_src()
916 if (hdmi->aud_param.aud_input_type == HDMI_AUD_INPUT_I2S) { in mtk_hdmi_aud_set_src()
925 return -EINVAL; in mtk_hdmi_aud_set_src()
927 mtk_hdmi_hw_aud_set_mclk(hdmi, hdmi->aud_param.aud_mclk); in mtk_hdmi_aud_set_src()
935 return -EINVAL; in mtk_hdmi_aud_set_src()
937 mtk_hdmi_hw_aud_set_mclk(hdmi, HDMI_AUD_MCLK_128FS); in mtk_hdmi_aud_set_src()
940 mtk_hdmi_hw_aud_set_ncts(hdmi, sample_rate, display_mode->clock); in mtk_hdmi_aud_set_src()
942 mtk_hdmi_hw_aud_src_reenable(hdmi); in mtk_hdmi_aud_set_src()
946 static int mtk_hdmi_aud_output_config(struct mtk_hdmi *hdmi, in mtk_hdmi_aud_output_config() argument
949 mtk_hdmi_hw_aud_mute(hdmi); in mtk_hdmi_aud_output_config()
950 mtk_hdmi_hw_send_aud_packet(hdmi, false); in mtk_hdmi_aud_output_config()
952 mtk_hdmi_aud_set_input(hdmi); in mtk_hdmi_aud_output_config()
953 mtk_hdmi_aud_set_src(hdmi, display_mode); in mtk_hdmi_aud_output_config()
954 mtk_hdmi_hw_aud_set_channel_status(hdmi, in mtk_hdmi_aud_output_config()
955 hdmi->aud_param.codec_params.iec.status); in mtk_hdmi_aud_output_config()
959 mtk_hdmi_hw_ncts_enable(hdmi, true); in mtk_hdmi_aud_output_config()
960 mtk_hdmi_hw_send_aud_packet(hdmi, true); in mtk_hdmi_aud_output_config()
961 mtk_hdmi_hw_aud_unmute(hdmi); in mtk_hdmi_aud_output_config()
965 static int mtk_hdmi_setup_avi_infoframe(struct mtk_hdmi *hdmi, in mtk_hdmi_setup_avi_infoframe() argument
973 hdmi->curr_conn, mode); in mtk_hdmi_setup_avi_infoframe()
975 dev_err(hdmi->dev, in mtk_hdmi_setup_avi_infoframe()
982 dev_err(hdmi->dev, "Failed to pack AVI infoframe: %zd\n", err); in mtk_hdmi_setup_avi_infoframe()
986 mtk_hdmi_hw_send_info_frame(hdmi, buffer, sizeof(buffer)); in mtk_hdmi_setup_avi_infoframe()
990 static int mtk_hdmi_setup_spd_infoframe(struct mtk_hdmi *hdmi, in mtk_hdmi_setup_spd_infoframe() argument
1000 dev_err(hdmi->dev, "Failed to initialize SPD infoframe: %zd\n", in mtk_hdmi_setup_spd_infoframe()
1007 dev_err(hdmi->dev, "Failed to pack SDP infoframe: %zd\n", err); in mtk_hdmi_setup_spd_infoframe()
1011 mtk_hdmi_hw_send_info_frame(hdmi, buffer, sizeof(buffer)); in mtk_hdmi_setup_spd_infoframe()
1015 static int mtk_hdmi_setup_audio_infoframe(struct mtk_hdmi *hdmi) in mtk_hdmi_setup_audio_infoframe() argument
1023 dev_err(hdmi->dev, "Failed to setup audio infoframe: %zd\n", in mtk_hdmi_setup_audio_infoframe()
1032 hdmi->aud_param.aud_input_chan_type); in mtk_hdmi_setup_audio_infoframe()
1036 dev_err(hdmi->dev, "Failed to pack audio infoframe: %zd\n", in mtk_hdmi_setup_audio_infoframe()
1041 mtk_hdmi_hw_send_info_frame(hdmi, buffer, sizeof(buffer)); in mtk_hdmi_setup_audio_infoframe()
1045 static int mtk_hdmi_setup_vendor_specific_infoframe(struct mtk_hdmi *hdmi, in mtk_hdmi_setup_vendor_specific_infoframe() argument
1053 hdmi->curr_conn, mode); in mtk_hdmi_setup_vendor_specific_infoframe()
1055 dev_err(hdmi->dev, in mtk_hdmi_setup_vendor_specific_infoframe()
1062 dev_err(hdmi->dev, "Failed to pack vendor infoframe: %zd\n", in mtk_hdmi_setup_vendor_specific_infoframe()
1067 mtk_hdmi_hw_send_info_frame(hdmi, buffer, sizeof(buffer)); in mtk_hdmi_setup_vendor_specific_infoframe()
1071 static int mtk_hdmi_output_init(struct mtk_hdmi *hdmi) in mtk_hdmi_output_init() argument
1073 struct hdmi_audio_param *aud_param = &hdmi->aud_param; in mtk_hdmi_output_init()
1075 hdmi->csp = HDMI_COLORSPACE_RGB; in mtk_hdmi_output_init()
1076 aud_param->aud_codec = HDMI_AUDIO_CODING_TYPE_PCM; in mtk_hdmi_output_init()
1077 aud_param->aud_sampe_size = HDMI_AUDIO_SAMPLE_SIZE_16; in mtk_hdmi_output_init()
1078 aud_param->aud_input_type = HDMI_AUD_INPUT_I2S; in mtk_hdmi_output_init()
1079 aud_param->aud_i2s_fmt = HDMI_I2S_MODE_I2S_24BIT; in mtk_hdmi_output_init()
1080 aud_param->aud_mclk = HDMI_AUD_MCLK_128FS; in mtk_hdmi_output_init()
1081 aud_param->aud_input_chan_type = HDMI_AUD_CHAN_TYPE_2_0; in mtk_hdmi_output_init()
1086 static void mtk_hdmi_audio_enable(struct mtk_hdmi *hdmi) in mtk_hdmi_audio_enable() argument
1088 mtk_hdmi_hw_send_aud_packet(hdmi, true); in mtk_hdmi_audio_enable()
1089 hdmi->audio_enable = true; in mtk_hdmi_audio_enable()
1092 static void mtk_hdmi_audio_disable(struct mtk_hdmi *hdmi) in mtk_hdmi_audio_disable() argument
1094 mtk_hdmi_hw_send_aud_packet(hdmi, false); in mtk_hdmi_audio_disable()
1095 hdmi->audio_enable = false; in mtk_hdmi_audio_disable()
1098 static int mtk_hdmi_audio_set_param(struct mtk_hdmi *hdmi, in mtk_hdmi_audio_set_param() argument
1101 if (!hdmi->audio_enable) { in mtk_hdmi_audio_set_param()
1102 dev_err(hdmi->dev, "hdmi audio is in disable state!\n"); in mtk_hdmi_audio_set_param()
1103 return -EINVAL; in mtk_hdmi_audio_set_param()
1105 dev_dbg(hdmi->dev, "codec:%d, input:%d, channel:%d, fs:%d\n", in mtk_hdmi_audio_set_param()
1106 param->aud_codec, param->aud_input_type, in mtk_hdmi_audio_set_param()
1107 param->aud_input_chan_type, param->codec_params.sample_rate); in mtk_hdmi_audio_set_param()
1108 memcpy(&hdmi->aud_param, param, sizeof(*param)); in mtk_hdmi_audio_set_param()
1109 return mtk_hdmi_aud_output_config(hdmi, &hdmi->mode); in mtk_hdmi_audio_set_param()
1112 static int mtk_hdmi_output_set_display_mode(struct mtk_hdmi *hdmi, in mtk_hdmi_output_set_display_mode() argument
1117 mtk_hdmi_hw_vid_black(hdmi, true); in mtk_hdmi_output_set_display_mode()
1118 mtk_hdmi_hw_aud_mute(hdmi); in mtk_hdmi_output_set_display_mode()
1119 mtk_hdmi_hw_send_av_mute(hdmi); in mtk_hdmi_output_set_display_mode()
1120 phy_power_off(hdmi->phy); in mtk_hdmi_output_set_display_mode()
1122 ret = mtk_hdmi_video_change_vpll(hdmi, in mtk_hdmi_output_set_display_mode()
1123 mode->clock * 1000); in mtk_hdmi_output_set_display_mode()
1125 dev_err(hdmi->dev, "Failed to set vpll: %d\n", ret); in mtk_hdmi_output_set_display_mode()
1128 mtk_hdmi_video_set_display_mode(hdmi, mode); in mtk_hdmi_output_set_display_mode()
1130 phy_power_on(hdmi->phy); in mtk_hdmi_output_set_display_mode()
1131 mtk_hdmi_aud_output_config(hdmi, mode); in mtk_hdmi_output_set_display_mode()
1133 mtk_hdmi_hw_vid_black(hdmi, false); in mtk_hdmi_output_set_display_mode()
1134 mtk_hdmi_hw_aud_unmute(hdmi); in mtk_hdmi_output_set_display_mode()
1135 mtk_hdmi_hw_send_av_unmute(hdmi); in mtk_hdmi_output_set_display_mode()
1147 static int mtk_hdmi_get_all_clk(struct mtk_hdmi *hdmi, in mtk_hdmi_get_all_clk() argument
1153 hdmi->clk[i] = of_clk_get_by_name(np, in mtk_hdmi_get_all_clk()
1155 if (IS_ERR(hdmi->clk[i])) in mtk_hdmi_get_all_clk()
1156 return PTR_ERR(hdmi->clk[i]); in mtk_hdmi_get_all_clk()
1161 static int mtk_hdmi_clk_enable_audio(struct mtk_hdmi *hdmi) in mtk_hdmi_clk_enable_audio() argument
1165 ret = clk_prepare_enable(hdmi->clk[MTK_HDMI_CLK_AUD_BCLK]); in mtk_hdmi_clk_enable_audio()
1169 ret = clk_prepare_enable(hdmi->clk[MTK_HDMI_CLK_AUD_SPDIF]); in mtk_hdmi_clk_enable_audio()
1175 clk_disable_unprepare(hdmi->clk[MTK_HDMI_CLK_AUD_BCLK]); in mtk_hdmi_clk_enable_audio()
1179 static void mtk_hdmi_clk_disable_audio(struct mtk_hdmi *hdmi) in mtk_hdmi_clk_disable_audio() argument
1181 clk_disable_unprepare(hdmi->clk[MTK_HDMI_CLK_AUD_BCLK]); in mtk_hdmi_clk_disable_audio()
1182 clk_disable_unprepare(hdmi->clk[MTK_HDMI_CLK_AUD_SPDIF]); in mtk_hdmi_clk_disable_audio()
1186 mtk_hdmi_update_plugged_status(struct mtk_hdmi *hdmi) in mtk_hdmi_update_plugged_status() argument
1190 mutex_lock(&hdmi->update_plugged_status_lock); in mtk_hdmi_update_plugged_status()
1191 connected = mtk_cec_hpd_high(hdmi->cec_dev); in mtk_hdmi_update_plugged_status()
1192 if (hdmi->plugged_cb && hdmi->codec_dev) in mtk_hdmi_update_plugged_status()
1193 hdmi->plugged_cb(hdmi->codec_dev, connected); in mtk_hdmi_update_plugged_status()
1194 mutex_unlock(&hdmi->update_plugged_status_lock); in mtk_hdmi_update_plugged_status()
1200 static enum drm_connector_status mtk_hdmi_detect(struct mtk_hdmi *hdmi) in mtk_hdmi_detect() argument
1202 return mtk_hdmi_update_plugged_status(hdmi); in mtk_hdmi_detect()
1206 mtk_hdmi_bridge_mode_valid(struct drm_bridge *bridge, in mtk_hdmi_bridge_mode_valid() argument
1210 struct mtk_hdmi *hdmi = hdmi_ctx_from_bridge(bridge); in mtk_hdmi_bridge_mode_valid() local
1212 dev_dbg(hdmi->dev, "xres=%d, yres=%d, refresh=%d, intl=%d clock=%d\n", in mtk_hdmi_bridge_mode_valid()
1213 mode->hdisplay, mode->vdisplay, drm_mode_vrefresh(mode), in mtk_hdmi_bridge_mode_valid()
1214 !!(mode->flags & DRM_MODE_FLAG_INTERLACE), mode->clock * 1000); in mtk_hdmi_bridge_mode_valid()
1216 if (hdmi->conf) { in mtk_hdmi_bridge_mode_valid()
1217 if (hdmi->conf->cea_modes_only && !drm_match_cea_mode(mode)) in mtk_hdmi_bridge_mode_valid()
1220 if (hdmi->conf->max_mode_clock && in mtk_hdmi_bridge_mode_valid()
1221 mode->clock > hdmi->conf->max_mode_clock) in mtk_hdmi_bridge_mode_valid()
1225 if (mode->clock < 27000) in mtk_hdmi_bridge_mode_valid()
1227 if (mode->clock > 297000) in mtk_hdmi_bridge_mode_valid()
1235 struct mtk_hdmi *hdmi = dev_get_drvdata(dev); in mtk_hdmi_hpd_event() local
1237 if (hdmi && hdmi->bridge.encoder && hdmi->bridge.encoder->dev) { in mtk_hdmi_hpd_event()
1240 status = mtk_hdmi_detect(hdmi); in mtk_hdmi_hpd_event()
1241 drm_helper_hpd_irq_event(hdmi->bridge.encoder->dev); in mtk_hdmi_hpd_event()
1242 drm_bridge_hpd_notify(&hdmi->bridge, status); in mtk_hdmi_hpd_event()
1247 * Bridge callbacks
1250 static enum drm_connector_status mtk_hdmi_bridge_detect(struct drm_bridge *bridge) in mtk_hdmi_bridge_detect() argument
1252 struct mtk_hdmi *hdmi = hdmi_ctx_from_bridge(bridge); in mtk_hdmi_bridge_detect() local
1254 return mtk_hdmi_detect(hdmi); in mtk_hdmi_bridge_detect()
1257 static const struct drm_edid *mtk_hdmi_bridge_edid_read(struct drm_bridge *bridge, in mtk_hdmi_bridge_edid_read() argument
1260 struct mtk_hdmi *hdmi = hdmi_ctx_from_bridge(bridge); in mtk_hdmi_bridge_edid_read() local
1263 if (!hdmi->ddc_adpt) in mtk_hdmi_bridge_edid_read()
1265 drm_edid = drm_edid_read_ddc(connector, hdmi->ddc_adpt); in mtk_hdmi_bridge_edid_read()
1268 * FIXME: This should use !connector->display_info.has_audio (or in mtk_hdmi_bridge_edid_read()
1269 * !connector->display_info.is_hdmi) from a path that has read in mtk_hdmi_bridge_edid_read()
1274 hdmi->dvi_mode = !drm_detect_monitor_audio(edid); in mtk_hdmi_bridge_edid_read()
1280 static int mtk_hdmi_bridge_attach(struct drm_bridge *bridge, in mtk_hdmi_bridge_attach() argument
1283 struct mtk_hdmi *hdmi = hdmi_ctx_from_bridge(bridge); in mtk_hdmi_bridge_attach() local
1289 return -EINVAL; in mtk_hdmi_bridge_attach()
1292 if (hdmi->next_bridge) { in mtk_hdmi_bridge_attach()
1293 ret = drm_bridge_attach(bridge->encoder, hdmi->next_bridge, in mtk_hdmi_bridge_attach()
1294 bridge, flags); in mtk_hdmi_bridge_attach()
1299 mtk_cec_set_hpd_event(hdmi->cec_dev, mtk_hdmi_hpd_event, hdmi->dev); in mtk_hdmi_bridge_attach()
1304 static bool mtk_hdmi_bridge_mode_fixup(struct drm_bridge *bridge, in mtk_hdmi_bridge_mode_fixup() argument
1311 static void mtk_hdmi_bridge_atomic_disable(struct drm_bridge *bridge, in mtk_hdmi_bridge_atomic_disable() argument
1314 struct mtk_hdmi *hdmi = hdmi_ctx_from_bridge(bridge); in mtk_hdmi_bridge_atomic_disable() local
1316 if (!hdmi->enabled) in mtk_hdmi_bridge_atomic_disable()
1319 phy_power_off(hdmi->phy); in mtk_hdmi_bridge_atomic_disable()
1320 clk_disable_unprepare(hdmi->clk[MTK_HDMI_CLK_HDMI_PIXEL]); in mtk_hdmi_bridge_atomic_disable()
1321 clk_disable_unprepare(hdmi->clk[MTK_HDMI_CLK_HDMI_PLL]); in mtk_hdmi_bridge_atomic_disable()
1323 hdmi->curr_conn = NULL; in mtk_hdmi_bridge_atomic_disable()
1325 hdmi->enabled = false; in mtk_hdmi_bridge_atomic_disable()
1328 static void mtk_hdmi_bridge_atomic_post_disable(struct drm_bridge *bridge, in mtk_hdmi_bridge_atomic_post_disable() argument
1331 struct mtk_hdmi *hdmi = hdmi_ctx_from_bridge(bridge); in mtk_hdmi_bridge_atomic_post_disable() local
1333 if (!hdmi->powered) in mtk_hdmi_bridge_atomic_post_disable()
1336 mtk_hdmi_hw_1p4_version_enable(hdmi, true); in mtk_hdmi_bridge_atomic_post_disable()
1337 mtk_hdmi_hw_make_reg_writable(hdmi, false); in mtk_hdmi_bridge_atomic_post_disable()
1339 hdmi->powered = false; in mtk_hdmi_bridge_atomic_post_disable()
1342 static void mtk_hdmi_bridge_mode_set(struct drm_bridge *bridge, in mtk_hdmi_bridge_mode_set() argument
1346 struct mtk_hdmi *hdmi = hdmi_ctx_from_bridge(bridge); in mtk_hdmi_bridge_mode_set() local
1348 dev_dbg(hdmi->dev, "cur info: name:%s, hdisplay:%d\n", in mtk_hdmi_bridge_mode_set()
1349 adjusted_mode->name, adjusted_mode->hdisplay); in mtk_hdmi_bridge_mode_set()
1350 dev_dbg(hdmi->dev, "hsync_start:%d,hsync_end:%d, htotal:%d", in mtk_hdmi_bridge_mode_set()
1351 adjusted_mode->hsync_start, adjusted_mode->hsync_end, in mtk_hdmi_bridge_mode_set()
1352 adjusted_mode->htotal); in mtk_hdmi_bridge_mode_set()
1353 dev_dbg(hdmi->dev, "hskew:%d, vdisplay:%d\n", in mtk_hdmi_bridge_mode_set()
1354 adjusted_mode->hskew, adjusted_mode->vdisplay); in mtk_hdmi_bridge_mode_set()
1355 dev_dbg(hdmi->dev, "vsync_start:%d, vsync_end:%d, vtotal:%d", in mtk_hdmi_bridge_mode_set()
1356 adjusted_mode->vsync_start, adjusted_mode->vsync_end, in mtk_hdmi_bridge_mode_set()
1357 adjusted_mode->vtotal); in mtk_hdmi_bridge_mode_set()
1358 dev_dbg(hdmi->dev, "vscan:%d, flag:%d\n", in mtk_hdmi_bridge_mode_set()
1359 adjusted_mode->vscan, adjusted_mode->flags); in mtk_hdmi_bridge_mode_set()
1361 drm_mode_copy(&hdmi->mode, adjusted_mode); in mtk_hdmi_bridge_mode_set()
1364 static void mtk_hdmi_bridge_atomic_pre_enable(struct drm_bridge *bridge, in mtk_hdmi_bridge_atomic_pre_enable() argument
1367 struct mtk_hdmi *hdmi = hdmi_ctx_from_bridge(bridge); in mtk_hdmi_bridge_atomic_pre_enable() local
1369 mtk_hdmi_hw_make_reg_writable(hdmi, true); in mtk_hdmi_bridge_atomic_pre_enable()
1370 mtk_hdmi_hw_1p4_version_enable(hdmi, true); in mtk_hdmi_bridge_atomic_pre_enable()
1372 hdmi->powered = true; in mtk_hdmi_bridge_atomic_pre_enable()
1375 static void mtk_hdmi_send_infoframe(struct mtk_hdmi *hdmi, in mtk_hdmi_send_infoframe() argument
1378 mtk_hdmi_setup_audio_infoframe(hdmi); in mtk_hdmi_send_infoframe()
1379 mtk_hdmi_setup_avi_infoframe(hdmi, mode); in mtk_hdmi_send_infoframe()
1380 mtk_hdmi_setup_spd_infoframe(hdmi, "mediatek", "On-chip HDMI"); in mtk_hdmi_send_infoframe()
1381 if (mode->flags & DRM_MODE_FLAG_3D_MASK) in mtk_hdmi_send_infoframe()
1382 mtk_hdmi_setup_vendor_specific_infoframe(hdmi, mode); in mtk_hdmi_send_infoframe()
1385 static void mtk_hdmi_bridge_atomic_enable(struct drm_bridge *bridge, in mtk_hdmi_bridge_atomic_enable() argument
1388 struct drm_atomic_state *state = old_state->base.state; in mtk_hdmi_bridge_atomic_enable()
1389 struct mtk_hdmi *hdmi = hdmi_ctx_from_bridge(bridge); in mtk_hdmi_bridge_atomic_enable() local
1392 hdmi->curr_conn = drm_atomic_get_new_connector_for_encoder(state, in mtk_hdmi_bridge_atomic_enable()
1393 bridge->encoder); in mtk_hdmi_bridge_atomic_enable()
1395 mtk_hdmi_output_set_display_mode(hdmi, &hdmi->mode); in mtk_hdmi_bridge_atomic_enable()
1396 clk_prepare_enable(hdmi->clk[MTK_HDMI_CLK_HDMI_PLL]); in mtk_hdmi_bridge_atomic_enable()
1397 clk_prepare_enable(hdmi->clk[MTK_HDMI_CLK_HDMI_PIXEL]); in mtk_hdmi_bridge_atomic_enable()
1398 phy_power_on(hdmi->phy); in mtk_hdmi_bridge_atomic_enable()
1399 mtk_hdmi_send_infoframe(hdmi, &hdmi->mode); in mtk_hdmi_bridge_atomic_enable()
1401 hdmi->enabled = true; in mtk_hdmi_bridge_atomic_enable()
1420 static int mtk_hdmi_dt_parse_pdata(struct mtk_hdmi *hdmi, in mtk_hdmi_dt_parse_pdata() argument
1423 struct device *dev = &pdev->dev; in mtk_hdmi_dt_parse_pdata()
1424 struct device_node *np = dev->of_node; in mtk_hdmi_dt_parse_pdata()
1431 ret = mtk_hdmi_get_all_clk(hdmi, np); in mtk_hdmi_dt_parse_pdata()
1433 if (ret != -EPROBE_DEFER) in mtk_hdmi_dt_parse_pdata()
1439 /* The CEC module handles HDMI hotplug detection */ in mtk_hdmi_dt_parse_pdata()
1440 cec_np = of_get_compatible_child(np->parent, "mediatek,mt8173-cec"); in mtk_hdmi_dt_parse_pdata()
1443 return -EINVAL; in mtk_hdmi_dt_parse_pdata()
1448 dev_err(hdmi->dev, "Waiting for CEC device %pOF\n", in mtk_hdmi_dt_parse_pdata()
1451 return -EPROBE_DEFER; in mtk_hdmi_dt_parse_pdata()
1454 hdmi->cec_dev = &cec_pdev->dev; in mtk_hdmi_dt_parse_pdata()
1457 * The mediatek,syscon-hdmi property contains a phandle link to the in mtk_hdmi_dt_parse_pdata()
1461 regmap = syscon_regmap_lookup_by_phandle(np, "mediatek,syscon-hdmi"); in mtk_hdmi_dt_parse_pdata()
1462 ret = of_property_read_u32_index(np, "mediatek,syscon-hdmi", 1, in mtk_hdmi_dt_parse_pdata()
1463 &hdmi->sys_offset); in mtk_hdmi_dt_parse_pdata()
1472 hdmi->sys_regmap = regmap; in mtk_hdmi_dt_parse_pdata()
1475 hdmi->regs = devm_ioremap_resource(dev, mem); in mtk_hdmi_dt_parse_pdata()
1476 if (IS_ERR(hdmi->regs)) { in mtk_hdmi_dt_parse_pdata()
1477 ret = PTR_ERR(hdmi->regs); in mtk_hdmi_dt_parse_pdata()
1483 ret = -EINVAL; in mtk_hdmi_dt_parse_pdata()
1487 if (!of_device_is_compatible(remote, "hdmi-connector")) { in mtk_hdmi_dt_parse_pdata()
1488 hdmi->next_bridge = of_drm_find_bridge(remote); in mtk_hdmi_dt_parse_pdata()
1489 if (!hdmi->next_bridge) { in mtk_hdmi_dt_parse_pdata()
1490 dev_err(dev, "Waiting for external bridge\n"); in mtk_hdmi_dt_parse_pdata()
1492 ret = -EPROBE_DEFER; in mtk_hdmi_dt_parse_pdata()
1497 i2c_np = of_parse_phandle(remote, "ddc-i2c-bus", 0); in mtk_hdmi_dt_parse_pdata()
1499 dev_err(dev, "Failed to find ddc-i2c-bus node in %pOF\n", in mtk_hdmi_dt_parse_pdata()
1502 ret = -EINVAL; in mtk_hdmi_dt_parse_pdata()
1507 hdmi->ddc_adpt = of_find_i2c_adapter_by_node(i2c_np); in mtk_hdmi_dt_parse_pdata()
1509 if (!hdmi->ddc_adpt) { in mtk_hdmi_dt_parse_pdata()
1511 ret = -EINVAL; in mtk_hdmi_dt_parse_pdata()
1517 put_device(hdmi->cec_dev); in mtk_hdmi_dt_parse_pdata()
1522 * HDMI audio codec callbacks
1529 struct mtk_hdmi *hdmi = dev_get_drvdata(dev); in mtk_hdmi_audio_hw_params() local
1531 unsigned int chan = params->cea.channels; in mtk_hdmi_audio_hw_params()
1533 dev_dbg(hdmi->dev, "%s: %u Hz, %d bit, %d channels\n", __func__, in mtk_hdmi_audio_hw_params()
1534 params->sample_rate, params->sample_width, chan); in mtk_hdmi_audio_hw_params()
1536 if (!hdmi->bridge.encoder) in mtk_hdmi_audio_hw_params()
1537 return -ENODEV; in mtk_hdmi_audio_hw_params()
1553 dev_err(hdmi->dev, "channel[%d] not supported!\n", chan); in mtk_hdmi_audio_hw_params()
1554 return -EINVAL; in mtk_hdmi_audio_hw_params()
1557 switch (params->sample_rate) { in mtk_hdmi_audio_hw_params()
1567 dev_err(hdmi->dev, "rate[%d] not supported!\n", in mtk_hdmi_audio_hw_params()
1568 params->sample_rate); in mtk_hdmi_audio_hw_params()
1569 return -EINVAL; in mtk_hdmi_audio_hw_params()
1572 switch (daifmt->fmt) { in mtk_hdmi_audio_hw_params()
1586 dev_err(hdmi->dev, "%s: Invalid DAI format %d\n", __func__, in mtk_hdmi_audio_hw_params()
1587 daifmt->fmt); in mtk_hdmi_audio_hw_params()
1588 return -EINVAL; in mtk_hdmi_audio_hw_params()
1594 mtk_hdmi_audio_set_param(hdmi, &hdmi_params); in mtk_hdmi_audio_hw_params()
1601 struct mtk_hdmi *hdmi = dev_get_drvdata(dev); in mtk_hdmi_audio_startup() local
1603 mtk_hdmi_audio_enable(hdmi); in mtk_hdmi_audio_startup()
1610 struct mtk_hdmi *hdmi = dev_get_drvdata(dev); in mtk_hdmi_audio_shutdown() local
1612 mtk_hdmi_audio_disable(hdmi); in mtk_hdmi_audio_shutdown()
1619 struct mtk_hdmi *hdmi = dev_get_drvdata(dev); in mtk_hdmi_audio_mute() local
1622 mtk_hdmi_hw_aud_mute(hdmi); in mtk_hdmi_audio_mute()
1624 mtk_hdmi_hw_aud_unmute(hdmi); in mtk_hdmi_audio_mute()
1631 struct mtk_hdmi *hdmi = dev_get_drvdata(dev); in mtk_hdmi_audio_get_eld() local
1633 if (hdmi->enabled) in mtk_hdmi_audio_get_eld()
1634 memcpy(buf, hdmi->curr_conn->eld, min(sizeof(hdmi->curr_conn->eld), len)); in mtk_hdmi_audio_get_eld()
1644 struct mtk_hdmi *hdmi = data; in mtk_hdmi_audio_hook_plugged_cb() local
1646 mutex_lock(&hdmi->update_plugged_status_lock); in mtk_hdmi_audio_hook_plugged_cb()
1647 hdmi->plugged_cb = fn; in mtk_hdmi_audio_hook_plugged_cb()
1648 hdmi->codec_dev = codec_dev; in mtk_hdmi_audio_hook_plugged_cb()
1649 mutex_unlock(&hdmi->update_plugged_status_lock); in mtk_hdmi_audio_hook_plugged_cb()
1651 mtk_hdmi_update_plugged_status(hdmi); in mtk_hdmi_audio_hook_plugged_cb()
1668 struct mtk_hdmi *hdmi = dev_get_drvdata(dev); in mtk_hdmi_register_audio_driver() local
1673 .data = hdmi, in mtk_hdmi_register_audio_driver()
1683 DRM_INFO("%s driver bound to HDMI\n", HDMI_CODEC_DRV_NAME); in mtk_hdmi_register_audio_driver()
1689 struct mtk_hdmi *hdmi; in mtk_hdmi_probe() local
1690 struct device *dev = &pdev->dev; in mtk_hdmi_probe()
1693 hdmi = devm_kzalloc(dev, sizeof(*hdmi), GFP_KERNEL); in mtk_hdmi_probe()
1694 if (!hdmi) in mtk_hdmi_probe()
1695 return -ENOMEM; in mtk_hdmi_probe()
1697 hdmi->dev = dev; in mtk_hdmi_probe()
1698 hdmi->conf = of_device_get_match_data(dev); in mtk_hdmi_probe()
1700 ret = mtk_hdmi_dt_parse_pdata(hdmi, pdev); in mtk_hdmi_probe()
1704 hdmi->phy = devm_phy_get(dev, "hdmi"); in mtk_hdmi_probe()
1705 if (IS_ERR(hdmi->phy)) in mtk_hdmi_probe()
1706 return dev_err_probe(dev, PTR_ERR(hdmi->phy), in mtk_hdmi_probe()
1707 "Failed to get HDMI PHY\n"); in mtk_hdmi_probe()
1709 mutex_init(&hdmi->update_plugged_status_lock); in mtk_hdmi_probe()
1710 platform_set_drvdata(pdev, hdmi); in mtk_hdmi_probe()
1712 ret = mtk_hdmi_output_init(hdmi); in mtk_hdmi_probe()
1715 "Failed to initialize hdmi output\n"); in mtk_hdmi_probe()
1722 hdmi->bridge.funcs = &mtk_hdmi_bridge_funcs; in mtk_hdmi_probe()
1723 hdmi->bridge.of_node = pdev->dev.of_node; in mtk_hdmi_probe()
1724 hdmi->bridge.ops = DRM_BRIDGE_OP_DETECT | DRM_BRIDGE_OP_EDID in mtk_hdmi_probe()
1726 hdmi->bridge.type = DRM_MODE_CONNECTOR_HDMIA; in mtk_hdmi_probe()
1727 drm_bridge_add(&hdmi->bridge); in mtk_hdmi_probe()
1729 ret = mtk_hdmi_clk_enable_audio(hdmi); in mtk_hdmi_probe()
1731 drm_bridge_remove(&hdmi->bridge); in mtk_hdmi_probe()
1741 struct mtk_hdmi *hdmi = platform_get_drvdata(pdev); in mtk_hdmi_remove() local
1743 drm_bridge_remove(&hdmi->bridge); in mtk_hdmi_remove()
1744 mtk_hdmi_clk_disable_audio(hdmi); in mtk_hdmi_remove()
1750 struct mtk_hdmi *hdmi = dev_get_drvdata(dev); in mtk_hdmi_suspend() local
1752 mtk_hdmi_clk_disable_audio(hdmi); in mtk_hdmi_suspend()
1759 struct mtk_hdmi *hdmi = dev_get_drvdata(dev); in mtk_hdmi_resume() local
1762 ret = mtk_hdmi_clk_enable_audio(hdmi); in mtk_hdmi_resume()
1764 dev_err(dev, "hdmi resume failed!\n"); in mtk_hdmi_resume()
1784 { .compatible = "mediatek,mt2701-hdmi",
1787 { .compatible = "mediatek,mt8167-hdmi",
1790 { .compatible = "mediatek,mt8173-hdmi",
1800 .name = "mediatek-drm-hdmi",
1828 MODULE_DESCRIPTION("MediaTek HDMI Driver");