Lines Matching full:hdmi
10 #include <linux/hdmi.h>
24 #include <sound/hdmi-codec.h>
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()
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
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()
927 mtk_hdmi_hw_aud_set_mclk(hdmi, hdmi->aud_param.aud_mclk); 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()
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()
1105 dev_dbg(hdmi->dev, "codec:%d, input:%d, channel:%d, fs:%d\n", 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()
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()
1210 struct mtk_hdmi *hdmi = hdmi_ctx_from_bridge(bridge); in mtk_hdmi_bridge_mode_valid() local
1213 dev_dbg(hdmi->dev, "xres=%d, yres=%d, refresh=%d, intl=%d clock=%d\n", in mtk_hdmi_bridge_mode_valid()
1217 next_bridge = drm_bridge_get_next_bridge(&hdmi->bridge); in mtk_hdmi_bridge_mode_valid()
1227 if (hdmi->conf) { in mtk_hdmi_bridge_mode_valid()
1228 if (hdmi->conf->cea_modes_only && !drm_match_cea_mode(mode)) in mtk_hdmi_bridge_mode_valid()
1231 if (hdmi->conf->max_mode_clock && in mtk_hdmi_bridge_mode_valid()
1232 mode->clock > hdmi->conf->max_mode_clock) in mtk_hdmi_bridge_mode_valid()
1246 struct mtk_hdmi *hdmi = dev_get_drvdata(dev); in mtk_hdmi_hpd_event() local
1248 if (hdmi && hdmi->bridge.encoder && hdmi->bridge.encoder->dev) { in mtk_hdmi_hpd_event()
1251 status = mtk_hdmi_detect(hdmi); in mtk_hdmi_hpd_event()
1252 drm_helper_hpd_irq_event(hdmi->bridge.encoder->dev); in mtk_hdmi_hpd_event()
1253 drm_bridge_hpd_notify(&hdmi->bridge, status); in mtk_hdmi_hpd_event()
1263 struct mtk_hdmi *hdmi = hdmi_ctx_from_bridge(bridge); in mtk_hdmi_bridge_detect() local
1265 return mtk_hdmi_detect(hdmi); in mtk_hdmi_bridge_detect()
1271 struct mtk_hdmi *hdmi = hdmi_ctx_from_bridge(bridge); in mtk_hdmi_bridge_get_edid() local
1274 if (!hdmi->ddc_adpt) in mtk_hdmi_bridge_get_edid()
1276 edid = drm_get_edid(connector, hdmi->ddc_adpt); in mtk_hdmi_bridge_get_edid()
1279 hdmi->dvi_mode = !drm_detect_monitor_audio(edid); in mtk_hdmi_bridge_get_edid()
1286 struct mtk_hdmi *hdmi = hdmi_ctx_from_bridge(bridge); in mtk_hdmi_bridge_attach() local
1295 if (hdmi->next_bridge) { in mtk_hdmi_bridge_attach()
1296 ret = drm_bridge_attach(bridge->encoder, hdmi->next_bridge, in mtk_hdmi_bridge_attach()
1302 mtk_cec_set_hpd_event(hdmi->cec_dev, mtk_hdmi_hpd_event, hdmi->dev); in mtk_hdmi_bridge_attach()
1317 struct mtk_hdmi *hdmi = hdmi_ctx_from_bridge(bridge); in mtk_hdmi_bridge_atomic_disable() local
1319 if (!hdmi->enabled) in mtk_hdmi_bridge_atomic_disable()
1322 phy_power_off(hdmi->phy); in mtk_hdmi_bridge_atomic_disable()
1323 clk_disable_unprepare(hdmi->clk[MTK_HDMI_CLK_HDMI_PIXEL]); in mtk_hdmi_bridge_atomic_disable()
1324 clk_disable_unprepare(hdmi->clk[MTK_HDMI_CLK_HDMI_PLL]); in mtk_hdmi_bridge_atomic_disable()
1326 hdmi->curr_conn = NULL; in mtk_hdmi_bridge_atomic_disable()
1328 hdmi->enabled = false; in mtk_hdmi_bridge_atomic_disable()
1334 struct mtk_hdmi *hdmi = hdmi_ctx_from_bridge(bridge); in mtk_hdmi_bridge_atomic_post_disable() local
1336 if (!hdmi->powered) in mtk_hdmi_bridge_atomic_post_disable()
1339 mtk_hdmi_hw_1p4_version_enable(hdmi, true); in mtk_hdmi_bridge_atomic_post_disable()
1340 mtk_hdmi_hw_make_reg_writable(hdmi, false); in mtk_hdmi_bridge_atomic_post_disable()
1342 hdmi->powered = false; in mtk_hdmi_bridge_atomic_post_disable()
1349 struct mtk_hdmi *hdmi = hdmi_ctx_from_bridge(bridge); in mtk_hdmi_bridge_mode_set() local
1351 dev_dbg(hdmi->dev, "cur info: name:%s, hdisplay:%d\n", in mtk_hdmi_bridge_mode_set()
1353 dev_dbg(hdmi->dev, "hsync_start:%d,hsync_end:%d, htotal:%d", in mtk_hdmi_bridge_mode_set()
1356 dev_dbg(hdmi->dev, "hskew:%d, vdisplay:%d\n", in mtk_hdmi_bridge_mode_set()
1358 dev_dbg(hdmi->dev, "vsync_start:%d, vsync_end:%d, vtotal:%d", in mtk_hdmi_bridge_mode_set()
1361 dev_dbg(hdmi->dev, "vscan:%d, flag:%d\n", in mtk_hdmi_bridge_mode_set()
1364 drm_mode_copy(&hdmi->mode, adjusted_mode); in mtk_hdmi_bridge_mode_set()
1370 struct mtk_hdmi *hdmi = hdmi_ctx_from_bridge(bridge); in mtk_hdmi_bridge_atomic_pre_enable() local
1372 mtk_hdmi_hw_make_reg_writable(hdmi, true); in mtk_hdmi_bridge_atomic_pre_enable()
1373 mtk_hdmi_hw_1p4_version_enable(hdmi, true); in mtk_hdmi_bridge_atomic_pre_enable()
1375 hdmi->powered = true; in mtk_hdmi_bridge_atomic_pre_enable()
1378 static void mtk_hdmi_send_infoframe(struct mtk_hdmi *hdmi, in mtk_hdmi_send_infoframe() argument
1381 mtk_hdmi_setup_audio_infoframe(hdmi); in mtk_hdmi_send_infoframe()
1382 mtk_hdmi_setup_avi_infoframe(hdmi, mode); in mtk_hdmi_send_infoframe()
1383 mtk_hdmi_setup_spd_infoframe(hdmi, "mediatek", "On-chip HDMI"); in mtk_hdmi_send_infoframe()
1385 mtk_hdmi_setup_vendor_specific_infoframe(hdmi, mode); in mtk_hdmi_send_infoframe()
1392 struct mtk_hdmi *hdmi = hdmi_ctx_from_bridge(bridge); in mtk_hdmi_bridge_atomic_enable() local
1395 hdmi->curr_conn = drm_atomic_get_new_connector_for_encoder(state, in mtk_hdmi_bridge_atomic_enable()
1398 mtk_hdmi_output_set_display_mode(hdmi, &hdmi->mode); in mtk_hdmi_bridge_atomic_enable()
1399 clk_prepare_enable(hdmi->clk[MTK_HDMI_CLK_HDMI_PLL]); in mtk_hdmi_bridge_atomic_enable()
1400 clk_prepare_enable(hdmi->clk[MTK_HDMI_CLK_HDMI_PIXEL]); in mtk_hdmi_bridge_atomic_enable()
1401 phy_power_on(hdmi->phy); in mtk_hdmi_bridge_atomic_enable()
1402 mtk_hdmi_send_infoframe(hdmi, &hdmi->mode); in mtk_hdmi_bridge_atomic_enable()
1404 hdmi->enabled = true; in mtk_hdmi_bridge_atomic_enable()
1423 static int mtk_hdmi_dt_parse_pdata(struct mtk_hdmi *hdmi, in mtk_hdmi_dt_parse_pdata() argument
1434 ret = mtk_hdmi_get_all_clk(hdmi, np); in mtk_hdmi_dt_parse_pdata()
1442 /* The CEC module handles HDMI hotplug detection */ in mtk_hdmi_dt_parse_pdata()
1451 dev_err(hdmi->dev, "Waiting for CEC device %pOF\n", in mtk_hdmi_dt_parse_pdata()
1457 hdmi->cec_dev = &cec_pdev->dev; in mtk_hdmi_dt_parse_pdata()
1460 * The mediatek,syscon-hdmi property contains a phandle link to the in mtk_hdmi_dt_parse_pdata()
1464 regmap = syscon_regmap_lookup_by_phandle(np, "mediatek,syscon-hdmi"); in mtk_hdmi_dt_parse_pdata()
1465 ret = of_property_read_u32_index(np, "mediatek,syscon-hdmi", 1, in mtk_hdmi_dt_parse_pdata()
1466 &hdmi->sys_offset); in mtk_hdmi_dt_parse_pdata()
1475 hdmi->sys_regmap = regmap; in mtk_hdmi_dt_parse_pdata()
1478 hdmi->regs = devm_ioremap_resource(dev, mem); in mtk_hdmi_dt_parse_pdata()
1479 if (IS_ERR(hdmi->regs)) { in mtk_hdmi_dt_parse_pdata()
1480 ret = PTR_ERR(hdmi->regs); in mtk_hdmi_dt_parse_pdata()
1490 if (!of_device_is_compatible(remote, "hdmi-connector")) { in mtk_hdmi_dt_parse_pdata()
1491 hdmi->next_bridge = of_drm_find_bridge(remote); in mtk_hdmi_dt_parse_pdata()
1492 if (!hdmi->next_bridge) { in mtk_hdmi_dt_parse_pdata()
1510 hdmi->ddc_adpt = of_find_i2c_adapter_by_node(i2c_np); in mtk_hdmi_dt_parse_pdata()
1512 if (!hdmi->ddc_adpt) { in mtk_hdmi_dt_parse_pdata()
1520 put_device(hdmi->cec_dev); in mtk_hdmi_dt_parse_pdata()
1525 * HDMI audio codec callbacks
1532 struct mtk_hdmi *hdmi = dev_get_drvdata(dev); in mtk_hdmi_audio_hw_params() local
1536 dev_dbg(hdmi->dev, "%s: %u Hz, %d bit, %d channels\n", __func__, in mtk_hdmi_audio_hw_params()
1539 if (!hdmi->bridge.encoder) in mtk_hdmi_audio_hw_params()
1556 dev_err(hdmi->dev, "channel[%d] not supported!\n", chan); in mtk_hdmi_audio_hw_params()
1570 dev_err(hdmi->dev, "rate[%d] not supported!\n", in mtk_hdmi_audio_hw_params()
1589 dev_err(hdmi->dev, "%s: Invalid DAI format %d\n", __func__, in mtk_hdmi_audio_hw_params()
1597 mtk_hdmi_audio_set_param(hdmi, &hdmi_params); in mtk_hdmi_audio_hw_params()
1604 struct mtk_hdmi *hdmi = dev_get_drvdata(dev); in mtk_hdmi_audio_startup() local
1606 mtk_hdmi_audio_enable(hdmi); in mtk_hdmi_audio_startup()
1613 struct mtk_hdmi *hdmi = dev_get_drvdata(dev); in mtk_hdmi_audio_shutdown() local
1615 mtk_hdmi_audio_disable(hdmi); in mtk_hdmi_audio_shutdown()
1622 struct mtk_hdmi *hdmi = dev_get_drvdata(dev); in mtk_hdmi_audio_mute() local
1625 mtk_hdmi_hw_aud_mute(hdmi); in mtk_hdmi_audio_mute()
1627 mtk_hdmi_hw_aud_unmute(hdmi); in mtk_hdmi_audio_mute()
1634 struct mtk_hdmi *hdmi = dev_get_drvdata(dev); in mtk_hdmi_audio_get_eld() local
1636 if (hdmi->enabled) in mtk_hdmi_audio_get_eld()
1637 memcpy(buf, hdmi->curr_conn->eld, min(sizeof(hdmi->curr_conn->eld), len)); in mtk_hdmi_audio_get_eld()
1647 struct mtk_hdmi *hdmi = data; in mtk_hdmi_audio_hook_plugged_cb() local
1649 mutex_lock(&hdmi->update_plugged_status_lock); in mtk_hdmi_audio_hook_plugged_cb()
1650 hdmi->plugged_cb = fn; in mtk_hdmi_audio_hook_plugged_cb()
1651 hdmi->codec_dev = codec_dev; in mtk_hdmi_audio_hook_plugged_cb()
1652 mutex_unlock(&hdmi->update_plugged_status_lock); in mtk_hdmi_audio_hook_plugged_cb()
1654 mtk_hdmi_update_plugged_status(hdmi); in mtk_hdmi_audio_hook_plugged_cb()
1671 struct mtk_hdmi *hdmi = dev_get_drvdata(dev); in mtk_hdmi_register_audio_driver() local
1676 .data = hdmi, in mtk_hdmi_register_audio_driver()
1686 DRM_INFO("%s driver bound to HDMI\n", HDMI_CODEC_DRV_NAME); in mtk_hdmi_register_audio_driver()
1692 struct mtk_hdmi *hdmi; in mtk_drm_hdmi_probe() local
1696 hdmi = devm_kzalloc(dev, sizeof(*hdmi), GFP_KERNEL); in mtk_drm_hdmi_probe()
1697 if (!hdmi) in mtk_drm_hdmi_probe()
1700 hdmi->dev = dev; in mtk_drm_hdmi_probe()
1701 hdmi->conf = of_device_get_match_data(dev); in mtk_drm_hdmi_probe()
1703 ret = mtk_hdmi_dt_parse_pdata(hdmi, pdev); in mtk_drm_hdmi_probe()
1707 hdmi->phy = devm_phy_get(dev, "hdmi"); in mtk_drm_hdmi_probe()
1708 if (IS_ERR(hdmi->phy)) { in mtk_drm_hdmi_probe()
1709 ret = PTR_ERR(hdmi->phy); in mtk_drm_hdmi_probe()
1710 dev_err(dev, "Failed to get HDMI PHY: %d\n", ret); in mtk_drm_hdmi_probe()
1714 mutex_init(&hdmi->update_plugged_status_lock); in mtk_drm_hdmi_probe()
1715 platform_set_drvdata(pdev, hdmi); in mtk_drm_hdmi_probe()
1717 ret = mtk_hdmi_output_init(hdmi); in mtk_drm_hdmi_probe()
1719 dev_err(dev, "Failed to initialize hdmi output\n"); in mtk_drm_hdmi_probe()
1729 hdmi->bridge.funcs = &mtk_hdmi_bridge_funcs; in mtk_drm_hdmi_probe()
1730 hdmi->bridge.of_node = pdev->dev.of_node; in mtk_drm_hdmi_probe()
1731 hdmi->bridge.ops = DRM_BRIDGE_OP_DETECT | DRM_BRIDGE_OP_EDID in mtk_drm_hdmi_probe()
1733 hdmi->bridge.type = DRM_MODE_CONNECTOR_HDMIA; in mtk_drm_hdmi_probe()
1734 drm_bridge_add(&hdmi->bridge); in mtk_drm_hdmi_probe()
1736 ret = mtk_hdmi_clk_enable_audio(hdmi); in mtk_drm_hdmi_probe()
1745 drm_bridge_remove(&hdmi->bridge); in mtk_drm_hdmi_probe()
1751 struct mtk_hdmi *hdmi = platform_get_drvdata(pdev); in mtk_drm_hdmi_remove() local
1753 drm_bridge_remove(&hdmi->bridge); in mtk_drm_hdmi_remove()
1754 mtk_hdmi_clk_disable_audio(hdmi); in mtk_drm_hdmi_remove()
1760 struct mtk_hdmi *hdmi = dev_get_drvdata(dev); in mtk_hdmi_suspend() local
1762 mtk_hdmi_clk_disable_audio(hdmi); in mtk_hdmi_suspend()
1769 struct mtk_hdmi *hdmi = dev_get_drvdata(dev); in mtk_hdmi_resume() local
1772 ret = mtk_hdmi_clk_enable_audio(hdmi); in mtk_hdmi_resume()
1774 dev_err(dev, "hdmi resume failed!\n"); in mtk_hdmi_resume()
1794 { .compatible = "mediatek,mt2701-hdmi",
1797 { .compatible = "mediatek,mt8167-hdmi",
1800 { .compatible = "mediatek,mt8173-hdmi",
1810 .name = "mediatek-drm-hdmi",
1838 MODULE_DESCRIPTION("MediaTek HDMI Driver");