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>
25 #include <sound/hdmi-codec.h>
154 struct drm_bridge bridge; member
186 return container_of(b, struct mtk_hdmi, bridge); in hdmi_ctx_from_bridge()
194 static u32 mtk_hdmi_read(struct mtk_hdmi *hdmi, u32 offset) in mtk_hdmi_read() argument
196 return readl(hdmi->regs + offset); in mtk_hdmi_read()
199 static void mtk_hdmi_write(struct mtk_hdmi *hdmi, u32 offset, u32 val) in mtk_hdmi_write() argument
201 writel(val, hdmi->regs + offset); in mtk_hdmi_write()
204 static void mtk_hdmi_clear_bits(struct mtk_hdmi *hdmi, u32 offset, u32 bits) in mtk_hdmi_clear_bits() argument
206 void __iomem *reg = hdmi->regs + offset; in mtk_hdmi_clear_bits()
214 static void mtk_hdmi_set_bits(struct mtk_hdmi *hdmi, u32 offset, u32 bits) in mtk_hdmi_set_bits() argument
216 void __iomem *reg = hdmi->regs + offset; in mtk_hdmi_set_bits()
224 static void mtk_hdmi_mask(struct mtk_hdmi *hdmi, u32 offset, u32 val, u32 mask) in mtk_hdmi_mask() argument
226 void __iomem *reg = hdmi->regs + offset; in mtk_hdmi_mask()
234 static void mtk_hdmi_hw_vid_black(struct mtk_hdmi *hdmi, bool black) in mtk_hdmi_hw_vid_black() argument
236 mtk_hdmi_mask(hdmi, VIDEO_CFG_4, black ? GEN_RGB : NORMAL_PATH, in mtk_hdmi_hw_vid_black()
240 static void mtk_hdmi_hw_make_reg_writable(struct mtk_hdmi *hdmi, bool enable) in mtk_hdmi_hw_make_reg_writable() argument
245 * MT8173 HDMI hardware has an output control bit to enable/disable HDMI in mtk_hdmi_hw_make_reg_writable()
247 * The ARM trusted firmware provides an API for the HDMI driver to set in mtk_hdmi_hw_make_reg_writable()
248 * this control bit to enable HDMI output in supervisor mode. in mtk_hdmi_hw_make_reg_writable()
250 if (hdmi->conf && hdmi->conf->tz_disabled) in mtk_hdmi_hw_make_reg_writable()
251 regmap_update_bits(hdmi->sys_regmap, in mtk_hdmi_hw_make_reg_writable()
252 hdmi->sys_offset + HDMI_SYS_CFG20, in mtk_hdmi_hw_make_reg_writable()
258 regmap_update_bits(hdmi->sys_regmap, hdmi->sys_offset + HDMI_SYS_CFG20, in mtk_hdmi_hw_make_reg_writable()
260 regmap_update_bits(hdmi->sys_regmap, hdmi->sys_offset + HDMI_SYS_CFG1C, in mtk_hdmi_hw_make_reg_writable()
264 static void mtk_hdmi_hw_1p4_version_enable(struct mtk_hdmi *hdmi, bool enable) in mtk_hdmi_hw_1p4_version_enable() argument
266 regmap_update_bits(hdmi->sys_regmap, hdmi->sys_offset + HDMI_SYS_CFG20, in mtk_hdmi_hw_1p4_version_enable()
270 static void mtk_hdmi_hw_aud_mute(struct mtk_hdmi *hdmi) in mtk_hdmi_hw_aud_mute() argument
272 mtk_hdmi_set_bits(hdmi, GRL_AUDIO_CFG, AUDIO_ZERO); in mtk_hdmi_hw_aud_mute()
275 static void mtk_hdmi_hw_aud_unmute(struct mtk_hdmi *hdmi) in mtk_hdmi_hw_aud_unmute() argument
277 mtk_hdmi_clear_bits(hdmi, GRL_AUDIO_CFG, AUDIO_ZERO); in mtk_hdmi_hw_aud_unmute()
280 static void mtk_hdmi_hw_reset(struct mtk_hdmi *hdmi) in mtk_hdmi_hw_reset() argument
282 regmap_update_bits(hdmi->sys_regmap, hdmi->sys_offset + HDMI_SYS_CFG1C, in mtk_hdmi_hw_reset()
284 regmap_update_bits(hdmi->sys_regmap, hdmi->sys_offset + HDMI_SYS_CFG1C, in mtk_hdmi_hw_reset()
286 mtk_hdmi_clear_bits(hdmi, GRL_CFG3, CFG3_CONTROL_PACKET_DELAY); in mtk_hdmi_hw_reset()
287 regmap_update_bits(hdmi->sys_regmap, hdmi->sys_offset + HDMI_SYS_CFG1C, in mtk_hdmi_hw_reset()
291 static void mtk_hdmi_hw_enable_notice(struct mtk_hdmi *hdmi, bool enable_notice) in mtk_hdmi_hw_enable_notice() argument
293 mtk_hdmi_mask(hdmi, GRL_CFG2, enable_notice ? CFG2_NOTICE_EN : 0, in mtk_hdmi_hw_enable_notice()
297 static void mtk_hdmi_hw_write_int_mask(struct mtk_hdmi *hdmi, u32 int_mask) in mtk_hdmi_hw_write_int_mask() argument
299 mtk_hdmi_write(hdmi, GRL_INT_MASK, int_mask); in mtk_hdmi_hw_write_int_mask()
302 static void mtk_hdmi_hw_enable_dvi_mode(struct mtk_hdmi *hdmi, bool enable) in mtk_hdmi_hw_enable_dvi_mode() argument
304 mtk_hdmi_mask(hdmi, GRL_CFG1, enable ? CFG1_DVI : 0, CFG1_DVI); in mtk_hdmi_hw_enable_dvi_mode()
307 static void mtk_hdmi_hw_send_info_frame(struct mtk_hdmi *hdmi, u8 *buffer, in mtk_hdmi_hw_send_info_frame() argument
325 dev_dbg(hdmi->dev, in mtk_hdmi_hw_send_info_frame()
347 dev_err(hdmi->dev, "Unknown infoframe type %d\n", frame_type); in mtk_hdmi_hw_send_info_frame()
350 mtk_hdmi_clear_bits(hdmi, ctrl_reg, ctrl_frame_en); in mtk_hdmi_hw_send_info_frame()
351 mtk_hdmi_write(hdmi, GRL_INFOFRM_TYPE, frame_type); in mtk_hdmi_hw_send_info_frame()
352 mtk_hdmi_write(hdmi, GRL_INFOFRM_VER, frame_ver); in mtk_hdmi_hw_send_info_frame()
353 mtk_hdmi_write(hdmi, GRL_INFOFRM_LNG, frame_len); in mtk_hdmi_hw_send_info_frame()
355 mtk_hdmi_write(hdmi, GRL_IFM_PORT, checksum); in mtk_hdmi_hw_send_info_frame()
357 mtk_hdmi_write(hdmi, GRL_IFM_PORT, frame_data[i]); in mtk_hdmi_hw_send_info_frame()
359 mtk_hdmi_set_bits(hdmi, ctrl_reg, ctrl_frame_en); in mtk_hdmi_hw_send_info_frame()
362 static void mtk_hdmi_hw_send_aud_packet(struct mtk_hdmi *hdmi, bool enable) in mtk_hdmi_hw_send_aud_packet() argument
364 mtk_hdmi_mask(hdmi, GRL_SHIFT_R2, enable ? 0 : AUDIO_PACKET_OFF, in mtk_hdmi_hw_send_aud_packet()
368 static void mtk_hdmi_hw_config_sys(struct mtk_hdmi *hdmi) in mtk_hdmi_hw_config_sys() argument
370 regmap_update_bits(hdmi->sys_regmap, hdmi->sys_offset + HDMI_SYS_CFG20, in mtk_hdmi_hw_config_sys()
373 regmap_update_bits(hdmi->sys_regmap, hdmi->sys_offset + HDMI_SYS_CFG20, in mtk_hdmi_hw_config_sys()
377 static void mtk_hdmi_hw_set_deep_color_mode(struct mtk_hdmi *hdmi) in mtk_hdmi_hw_set_deep_color_mode() argument
379 regmap_update_bits(hdmi->sys_regmap, hdmi->sys_offset + HDMI_SYS_CFG20, in mtk_hdmi_hw_set_deep_color_mode()
384 static void mtk_hdmi_hw_send_av_mute(struct mtk_hdmi *hdmi) in mtk_hdmi_hw_send_av_mute() argument
386 mtk_hdmi_clear_bits(hdmi, GRL_CFG4, CTRL_AVMUTE); in mtk_hdmi_hw_send_av_mute()
388 mtk_hdmi_set_bits(hdmi, GRL_CFG4, CTRL_AVMUTE); in mtk_hdmi_hw_send_av_mute()
391 static void mtk_hdmi_hw_send_av_unmute(struct mtk_hdmi *hdmi) in mtk_hdmi_hw_send_av_unmute() argument
393 mtk_hdmi_mask(hdmi, GRL_CFG4, CFG4_AV_UNMUTE_EN, in mtk_hdmi_hw_send_av_unmute()
396 mtk_hdmi_mask(hdmi, GRL_CFG4, CFG4_AV_UNMUTE_SET, in mtk_hdmi_hw_send_av_unmute()
400 static void mtk_hdmi_hw_ncts_enable(struct mtk_hdmi *hdmi, bool on) in mtk_hdmi_hw_ncts_enable() argument
402 mtk_hdmi_mask(hdmi, GRL_CTS_CTRL, on ? 0 : CTS_CTRL_SOFT, in mtk_hdmi_hw_ncts_enable()
406 static void mtk_hdmi_hw_ncts_auto_write_enable(struct mtk_hdmi *hdmi, in mtk_hdmi_hw_ncts_auto_write_enable() argument
409 mtk_hdmi_mask(hdmi, GRL_CTS_CTRL, enable ? NCTS_WRI_ANYTIME : 0, in mtk_hdmi_hw_ncts_auto_write_enable()
413 static void mtk_hdmi_hw_msic_setting(struct mtk_hdmi *hdmi, in mtk_hdmi_hw_msic_setting() argument
416 mtk_hdmi_clear_bits(hdmi, GRL_CFG4, CFG4_MHL_MODE); in mtk_hdmi_hw_msic_setting()
418 if (mode->flags & DRM_MODE_FLAG_INTERLACE && in mtk_hdmi_hw_msic_setting()
419 mode->clock == 74250 && in mtk_hdmi_hw_msic_setting()
420 mode->vdisplay == 1080) in mtk_hdmi_hw_msic_setting()
421 mtk_hdmi_clear_bits(hdmi, GRL_CFG2, CFG2_MHL_DE_SEL); in mtk_hdmi_hw_msic_setting()
423 mtk_hdmi_set_bits(hdmi, GRL_CFG2, CFG2_MHL_DE_SEL); in mtk_hdmi_hw_msic_setting()
426 static void mtk_hdmi_hw_aud_set_channel_swap(struct mtk_hdmi *hdmi, in mtk_hdmi_hw_aud_set_channel_swap() argument
451 mtk_hdmi_mask(hdmi, GRL_CH_SWAP, swap_bit, 0xff); in mtk_hdmi_hw_aud_set_channel_swap()
454 static void mtk_hdmi_hw_aud_set_bit_num(struct mtk_hdmi *hdmi, in mtk_hdmi_hw_aud_set_bit_num() argument
472 mtk_hdmi_mask(hdmi, GRL_AOUT_CFG, val, AOUT_BNUM_SEL_MASK); in mtk_hdmi_hw_aud_set_bit_num()
475 static void mtk_hdmi_hw_aud_set_i2s_fmt(struct mtk_hdmi *hdmi, in mtk_hdmi_hw_aud_set_i2s_fmt() argument
480 val = mtk_hdmi_read(hdmi, GRL_CFG0); in mtk_hdmi_hw_aud_set_i2s_fmt()
504 mtk_hdmi_write(hdmi, GRL_CFG0, val); in mtk_hdmi_hw_aud_set_i2s_fmt()
507 static void mtk_hdmi_hw_audio_config(struct mtk_hdmi *hdmi, bool dst) in mtk_hdmi_hw_audio_config() argument
513 mtk_hdmi_clear_bits(hdmi, GRL_AOUT_CFG, HIGH_BIT_RATE_PACKET_ALIGN); in mtk_hdmi_hw_audio_config()
520 mtk_hdmi_mask(hdmi, GRL_AUDIO_CFG, val, mask); in mtk_hdmi_hw_audio_config()
523 static void mtk_hdmi_hw_aud_set_i2s_chan_num(struct mtk_hdmi *hdmi, in mtk_hdmi_hw_aud_set_i2s_chan_num() argument
561 mtk_hdmi_write(hdmi, GRL_CH_SW0, ch_switch & 0xff); in mtk_hdmi_hw_aud_set_i2s_chan_num()
562 mtk_hdmi_write(hdmi, GRL_CH_SW1, (ch_switch >> 8) & 0xff); in mtk_hdmi_hw_aud_set_i2s_chan_num()
563 mtk_hdmi_write(hdmi, GRL_CH_SW2, (ch_switch >> 16) & 0xff); in mtk_hdmi_hw_aud_set_i2s_chan_num()
564 mtk_hdmi_write(hdmi, GRL_I2S_UV, i2s_uv); in mtk_hdmi_hw_aud_set_i2s_chan_num()
567 static void mtk_hdmi_hw_aud_set_input_type(struct mtk_hdmi *hdmi, in mtk_hdmi_hw_aud_set_input_type() argument
572 val = mtk_hdmi_read(hdmi, GRL_CFG1); in mtk_hdmi_hw_aud_set_input_type()
580 mtk_hdmi_write(hdmi, GRL_CFG1, val); in mtk_hdmi_hw_aud_set_input_type()
583 static void mtk_hdmi_hw_aud_set_channel_status(struct mtk_hdmi *hdmi, in mtk_hdmi_hw_aud_set_channel_status() argument
589 mtk_hdmi_write(hdmi, GRL_I2S_C_STA0 + i * 4, channel_status[i]); in mtk_hdmi_hw_aud_set_channel_status()
590 mtk_hdmi_write(hdmi, GRL_L_STATUS_0 + i * 4, channel_status[i]); in mtk_hdmi_hw_aud_set_channel_status()
591 mtk_hdmi_write(hdmi, GRL_R_STATUS_0 + i * 4, channel_status[i]); in mtk_hdmi_hw_aud_set_channel_status()
594 mtk_hdmi_write(hdmi, GRL_L_STATUS_0 + i * 4, 0); in mtk_hdmi_hw_aud_set_channel_status()
595 mtk_hdmi_write(hdmi, GRL_R_STATUS_0 + i * 4, 0); in mtk_hdmi_hw_aud_set_channel_status()
599 static void mtk_hdmi_hw_aud_src_reenable(struct mtk_hdmi *hdmi) in mtk_hdmi_hw_aud_src_reenable() argument
603 val = mtk_hdmi_read(hdmi, GRL_MIX_CTRL); in mtk_hdmi_hw_aud_src_reenable()
606 mtk_hdmi_write(hdmi, GRL_MIX_CTRL, val); in mtk_hdmi_hw_aud_src_reenable()
609 mtk_hdmi_write(hdmi, GRL_MIX_CTRL, val); in mtk_hdmi_hw_aud_src_reenable()
613 static void mtk_hdmi_hw_aud_src_disable(struct mtk_hdmi *hdmi) in mtk_hdmi_hw_aud_src_disable() argument
617 val = mtk_hdmi_read(hdmi, GRL_MIX_CTRL); in mtk_hdmi_hw_aud_src_disable()
619 mtk_hdmi_write(hdmi, GRL_MIX_CTRL, val); in mtk_hdmi_hw_aud_src_disable()
620 mtk_hdmi_write(hdmi, GRL_SHIFT_L1, 0x00); in mtk_hdmi_hw_aud_src_disable()
623 static void mtk_hdmi_hw_aud_set_mclk(struct mtk_hdmi *hdmi, in mtk_hdmi_hw_aud_set_mclk() argument
628 val = mtk_hdmi_read(hdmi, GRL_CFG5); in mtk_hdmi_hw_aud_set_mclk()
651 mtk_hdmi_write(hdmi, GRL_CFG5, val); in mtk_hdmi_hw_aud_set_mclk()
659 /* Recommended N values from HDMI specification, tables 7-1 to 7-3 */
671 * hdmi_recommended_n() - Return N value recommended by HDMI specification
680 for (i = 0; i < ARRAY_SIZE(hdmi_rec_n_table) - 1; i++) { in hdmi_recommended_n()
688 return recommended->n[0]; in hdmi_recommended_n()
690 return recommended->n[1]; in hdmi_recommended_n()
692 return recommended->n[2]; in hdmi_recommended_n()
694 return recommended->n[1] * 2; in hdmi_recommended_n()
696 return recommended->n[2] * 2; in hdmi_recommended_n()
698 return recommended->n[1] * 4; in hdmi_recommended_n()
700 return recommended->n[2] * 4; in hdmi_recommended_n()
729 static void do_hdmi_hw_aud_set_ncts(struct mtk_hdmi *hdmi, unsigned int n, in do_hdmi_hw_aud_set_ncts() argument
735 mtk_hdmi_write(hdmi, GRL_NCTS, 0); in do_hdmi_hw_aud_set_ncts()
736 mtk_hdmi_write(hdmi, GRL_NCTS, 0); in do_hdmi_hw_aud_set_ncts()
737 mtk_hdmi_write(hdmi, GRL_NCTS, 0); in do_hdmi_hw_aud_set_ncts()
750 mtk_hdmi_write(hdmi, GRL_NCTS, val[i]); in do_hdmi_hw_aud_set_ncts()
753 static void mtk_hdmi_hw_aud_set_ncts(struct mtk_hdmi *hdmi, in mtk_hdmi_hw_aud_set_ncts() argument
762 dev_dbg(hdmi->dev, "%s: sample_rate=%u, clock=%d, cts=%u, n=%u\n", in mtk_hdmi_hw_aud_set_ncts()
765 mtk_hdmi_mask(hdmi, DUMMY_304, AUDIO_I2S_NCTS_SEL_64, in mtk_hdmi_hw_aud_set_ncts()
767 do_hdmi_hw_aud_set_ncts(hdmi, n, cts); in mtk_hdmi_hw_aud_set_ncts()
840 static int mtk_hdmi_video_change_vpll(struct mtk_hdmi *hdmi, u32 clock) in mtk_hdmi_video_change_vpll() argument
846 ret = clk_set_rate(hdmi->clk[MTK_HDMI_CLK_HDMI_PLL], clock); in mtk_hdmi_video_change_vpll()
848 dev_err(hdmi->dev, "Failed to set PLL to %u Hz: %d\n", clock, in mtk_hdmi_video_change_vpll()
853 rate = clk_get_rate(hdmi->clk[MTK_HDMI_CLK_HDMI_PLL]); in mtk_hdmi_video_change_vpll()
856 dev_warn(hdmi->dev, "Want PLL %u Hz, got %lu Hz\n", clock, in mtk_hdmi_video_change_vpll()
859 dev_dbg(hdmi->dev, "Want PLL %u Hz, got %lu Hz\n", clock, rate); in mtk_hdmi_video_change_vpll()
861 mtk_hdmi_hw_config_sys(hdmi); in mtk_hdmi_video_change_vpll()
862 mtk_hdmi_hw_set_deep_color_mode(hdmi); in mtk_hdmi_video_change_vpll()
866 static void mtk_hdmi_video_set_display_mode(struct mtk_hdmi *hdmi, in mtk_hdmi_video_set_display_mode() argument
869 mtk_hdmi_hw_reset(hdmi); in mtk_hdmi_video_set_display_mode()
870 mtk_hdmi_hw_enable_notice(hdmi, true); in mtk_hdmi_video_set_display_mode()
871 mtk_hdmi_hw_write_int_mask(hdmi, 0xff); in mtk_hdmi_video_set_display_mode()
872 mtk_hdmi_hw_enable_dvi_mode(hdmi, hdmi->dvi_mode); in mtk_hdmi_video_set_display_mode()
873 mtk_hdmi_hw_ncts_auto_write_enable(hdmi, true); in mtk_hdmi_video_set_display_mode()
875 mtk_hdmi_hw_msic_setting(hdmi, mode); in mtk_hdmi_video_set_display_mode()
878 static int mtk_hdmi_aud_enable_packet(struct mtk_hdmi *hdmi, bool enable) in mtk_hdmi_aud_enable_packet() argument
880 mtk_hdmi_hw_send_aud_packet(hdmi, enable); in mtk_hdmi_aud_enable_packet()
884 static int mtk_hdmi_aud_on_off_hw_ncts(struct mtk_hdmi *hdmi, bool on) in mtk_hdmi_aud_on_off_hw_ncts() argument
886 mtk_hdmi_hw_ncts_enable(hdmi, on); in mtk_hdmi_aud_on_off_hw_ncts()
890 static int mtk_hdmi_aud_set_input(struct mtk_hdmi *hdmi) in mtk_hdmi_aud_set_input() argument
896 mtk_hdmi_hw_aud_set_channel_swap(hdmi, HDMI_AUD_SWAP_LFE_CC); in mtk_hdmi_aud_set_input()
897 mtk_hdmi_set_bits(hdmi, GRL_MIX_CTRL, MIX_CTRL_FLAT); in mtk_hdmi_aud_set_input()
899 if (hdmi->aud_param.aud_input_type == HDMI_AUD_INPUT_SPDIF && in mtk_hdmi_aud_set_input()
900 hdmi->aud_param.aud_codec == HDMI_AUDIO_CODING_TYPE_DST) { in mtk_hdmi_aud_set_input()
901 mtk_hdmi_hw_aud_set_bit_num(hdmi, HDMI_AUDIO_SAMPLE_SIZE_24); in mtk_hdmi_aud_set_input()
902 } else if (hdmi->aud_param.aud_i2s_fmt == HDMI_I2S_MODE_LJT_24BIT) { in mtk_hdmi_aud_set_input()
903 hdmi->aud_param.aud_i2s_fmt = HDMI_I2S_MODE_LJT_16BIT; in mtk_hdmi_aud_set_input()
906 mtk_hdmi_hw_aud_set_i2s_fmt(hdmi, hdmi->aud_param.aud_i2s_fmt); in mtk_hdmi_aud_set_input()
907 mtk_hdmi_hw_aud_set_bit_num(hdmi, HDMI_AUDIO_SAMPLE_SIZE_24); in mtk_hdmi_aud_set_input()
909 dst = ((hdmi->aud_param.aud_input_type == HDMI_AUD_INPUT_SPDIF) && in mtk_hdmi_aud_set_input()
910 (hdmi->aud_param.aud_codec == HDMI_AUDIO_CODING_TYPE_DST)); in mtk_hdmi_aud_set_input()
911 mtk_hdmi_hw_audio_config(hdmi, dst); in mtk_hdmi_aud_set_input()
913 if (hdmi->aud_param.aud_input_type == HDMI_AUD_INPUT_SPDIF) in mtk_hdmi_aud_set_input()
916 chan_type = hdmi->aud_param.aud_input_chan_type; in mtk_hdmi_aud_set_input()
918 mtk_hdmi_hw_aud_set_i2s_chan_num(hdmi, chan_type, chan_count); in mtk_hdmi_aud_set_input()
919 mtk_hdmi_hw_aud_set_input_type(hdmi, hdmi->aud_param.aud_input_type); in mtk_hdmi_aud_set_input()
924 static int mtk_hdmi_aud_set_src(struct mtk_hdmi *hdmi, in mtk_hdmi_aud_set_src() argument
927 unsigned int sample_rate = hdmi->aud_param.codec_params.sample_rate; in mtk_hdmi_aud_set_src()
929 mtk_hdmi_aud_on_off_hw_ncts(hdmi, false); in mtk_hdmi_aud_set_src()
930 mtk_hdmi_hw_aud_src_disable(hdmi); in mtk_hdmi_aud_set_src()
931 mtk_hdmi_clear_bits(hdmi, GRL_CFG2, CFG2_ACLK_INV); in mtk_hdmi_aud_set_src()
933 if (hdmi->aud_param.aud_input_type == HDMI_AUD_INPUT_I2S) { in mtk_hdmi_aud_set_src()
942 return -EINVAL; in mtk_hdmi_aud_set_src()
944 mtk_hdmi_hw_aud_set_mclk(hdmi, hdmi->aud_param.aud_mclk); in mtk_hdmi_aud_set_src()
952 return -EINVAL; in mtk_hdmi_aud_set_src()
954 mtk_hdmi_hw_aud_set_mclk(hdmi, HDMI_AUD_MCLK_128FS); in mtk_hdmi_aud_set_src()
957 mtk_hdmi_hw_aud_set_ncts(hdmi, sample_rate, display_mode->clock); in mtk_hdmi_aud_set_src()
959 mtk_hdmi_hw_aud_src_reenable(hdmi); in mtk_hdmi_aud_set_src()
963 static int mtk_hdmi_aud_output_config(struct mtk_hdmi *hdmi, in mtk_hdmi_aud_output_config() argument
966 mtk_hdmi_hw_aud_mute(hdmi); in mtk_hdmi_aud_output_config()
967 mtk_hdmi_aud_enable_packet(hdmi, false); in mtk_hdmi_aud_output_config()
969 mtk_hdmi_aud_set_input(hdmi); in mtk_hdmi_aud_output_config()
970 mtk_hdmi_aud_set_src(hdmi, display_mode); in mtk_hdmi_aud_output_config()
971 mtk_hdmi_hw_aud_set_channel_status(hdmi, in mtk_hdmi_aud_output_config()
972 hdmi->aud_param.codec_params.iec.status); in mtk_hdmi_aud_output_config()
976 mtk_hdmi_aud_on_off_hw_ncts(hdmi, true); in mtk_hdmi_aud_output_config()
977 mtk_hdmi_aud_enable_packet(hdmi, true); in mtk_hdmi_aud_output_config()
978 mtk_hdmi_hw_aud_unmute(hdmi); in mtk_hdmi_aud_output_config()
982 static int mtk_hdmi_setup_avi_infoframe(struct mtk_hdmi *hdmi, in mtk_hdmi_setup_avi_infoframe() argument
990 &hdmi->conn, mode); in mtk_hdmi_setup_avi_infoframe()
992 dev_err(hdmi->dev, in mtk_hdmi_setup_avi_infoframe()
999 dev_err(hdmi->dev, "Failed to pack AVI infoframe: %zd\n", err); in mtk_hdmi_setup_avi_infoframe()
1003 mtk_hdmi_hw_send_info_frame(hdmi, buffer, sizeof(buffer)); in mtk_hdmi_setup_avi_infoframe()
1007 static int mtk_hdmi_setup_spd_infoframe(struct mtk_hdmi *hdmi, in mtk_hdmi_setup_spd_infoframe() argument
1017 dev_err(hdmi->dev, "Failed to initialize SPD infoframe: %zd\n", in mtk_hdmi_setup_spd_infoframe()
1024 dev_err(hdmi->dev, "Failed to pack SDP infoframe: %zd\n", err); in mtk_hdmi_setup_spd_infoframe()
1028 mtk_hdmi_hw_send_info_frame(hdmi, buffer, sizeof(buffer)); in mtk_hdmi_setup_spd_infoframe()
1032 static int mtk_hdmi_setup_audio_infoframe(struct mtk_hdmi *hdmi) in mtk_hdmi_setup_audio_infoframe() argument
1040 dev_err(hdmi->dev, "Failed to setup audio infoframe: %zd\n", in mtk_hdmi_setup_audio_infoframe()
1049 hdmi->aud_param.aud_input_chan_type); in mtk_hdmi_setup_audio_infoframe()
1053 dev_err(hdmi->dev, "Failed to pack audio infoframe: %zd\n", in mtk_hdmi_setup_audio_infoframe()
1058 mtk_hdmi_hw_send_info_frame(hdmi, buffer, sizeof(buffer)); in mtk_hdmi_setup_audio_infoframe()
1062 static int mtk_hdmi_setup_vendor_specific_infoframe(struct mtk_hdmi *hdmi, in mtk_hdmi_setup_vendor_specific_infoframe() argument
1070 &hdmi->conn, mode); in mtk_hdmi_setup_vendor_specific_infoframe()
1072 dev_err(hdmi->dev, in mtk_hdmi_setup_vendor_specific_infoframe()
1079 dev_err(hdmi->dev, "Failed to pack vendor infoframe: %zd\n", in mtk_hdmi_setup_vendor_specific_infoframe()
1084 mtk_hdmi_hw_send_info_frame(hdmi, buffer, sizeof(buffer)); in mtk_hdmi_setup_vendor_specific_infoframe()
1088 static int mtk_hdmi_output_init(struct mtk_hdmi *hdmi) in mtk_hdmi_output_init() argument
1090 struct hdmi_audio_param *aud_param = &hdmi->aud_param; in mtk_hdmi_output_init()
1092 hdmi->csp = HDMI_COLORSPACE_RGB; in mtk_hdmi_output_init()
1093 aud_param->aud_codec = HDMI_AUDIO_CODING_TYPE_PCM; in mtk_hdmi_output_init()
1094 aud_param->aud_sampe_size = HDMI_AUDIO_SAMPLE_SIZE_16; in mtk_hdmi_output_init()
1095 aud_param->aud_input_type = HDMI_AUD_INPUT_I2S; in mtk_hdmi_output_init()
1096 aud_param->aud_i2s_fmt = HDMI_I2S_MODE_I2S_24BIT; in mtk_hdmi_output_init()
1097 aud_param->aud_mclk = HDMI_AUD_MCLK_128FS; in mtk_hdmi_output_init()
1098 aud_param->aud_input_chan_type = HDMI_AUD_CHAN_TYPE_2_0; in mtk_hdmi_output_init()
1103 static void mtk_hdmi_audio_enable(struct mtk_hdmi *hdmi) in mtk_hdmi_audio_enable() argument
1105 mtk_hdmi_aud_enable_packet(hdmi, true); in mtk_hdmi_audio_enable()
1106 hdmi->audio_enable = true; in mtk_hdmi_audio_enable()
1109 static void mtk_hdmi_audio_disable(struct mtk_hdmi *hdmi) in mtk_hdmi_audio_disable() argument
1111 mtk_hdmi_aud_enable_packet(hdmi, false); in mtk_hdmi_audio_disable()
1112 hdmi->audio_enable = false; in mtk_hdmi_audio_disable()
1115 static int mtk_hdmi_audio_set_param(struct mtk_hdmi *hdmi, in mtk_hdmi_audio_set_param() argument
1118 if (!hdmi->audio_enable) { in mtk_hdmi_audio_set_param()
1119 dev_err(hdmi->dev, "hdmi audio is in disable state!\n"); in mtk_hdmi_audio_set_param()
1120 return -EINVAL; in mtk_hdmi_audio_set_param()
1122 dev_dbg(hdmi->dev, "codec:%d, input:%d, channel:%d, fs:%d\n", in mtk_hdmi_audio_set_param()
1123 param->aud_codec, param->aud_input_type, in mtk_hdmi_audio_set_param()
1124 param->aud_input_chan_type, param->codec_params.sample_rate); in mtk_hdmi_audio_set_param()
1125 memcpy(&hdmi->aud_param, param, sizeof(*param)); in mtk_hdmi_audio_set_param()
1126 return mtk_hdmi_aud_output_config(hdmi, &hdmi->mode); in mtk_hdmi_audio_set_param()
1129 static int mtk_hdmi_output_set_display_mode(struct mtk_hdmi *hdmi, in mtk_hdmi_output_set_display_mode() argument
1134 mtk_hdmi_hw_vid_black(hdmi, true); in mtk_hdmi_output_set_display_mode()
1135 mtk_hdmi_hw_aud_mute(hdmi); in mtk_hdmi_output_set_display_mode()
1136 mtk_hdmi_hw_send_av_mute(hdmi); in mtk_hdmi_output_set_display_mode()
1137 phy_power_off(hdmi->phy); in mtk_hdmi_output_set_display_mode()
1139 ret = mtk_hdmi_video_change_vpll(hdmi, in mtk_hdmi_output_set_display_mode()
1140 mode->clock * 1000); in mtk_hdmi_output_set_display_mode()
1142 dev_err(hdmi->dev, "Failed to set vpll: %d\n", ret); in mtk_hdmi_output_set_display_mode()
1145 mtk_hdmi_video_set_display_mode(hdmi, mode); in mtk_hdmi_output_set_display_mode()
1147 phy_power_on(hdmi->phy); in mtk_hdmi_output_set_display_mode()
1148 mtk_hdmi_aud_output_config(hdmi, mode); in mtk_hdmi_output_set_display_mode()
1150 mtk_hdmi_hw_vid_black(hdmi, false); in mtk_hdmi_output_set_display_mode()
1151 mtk_hdmi_hw_aud_unmute(hdmi); in mtk_hdmi_output_set_display_mode()
1152 mtk_hdmi_hw_send_av_unmute(hdmi); in mtk_hdmi_output_set_display_mode()
1164 static int mtk_hdmi_get_all_clk(struct mtk_hdmi *hdmi, in mtk_hdmi_get_all_clk() argument
1170 hdmi->clk[i] = of_clk_get_by_name(np, in mtk_hdmi_get_all_clk()
1172 if (IS_ERR(hdmi->clk[i])) in mtk_hdmi_get_all_clk()
1173 return PTR_ERR(hdmi->clk[i]); in mtk_hdmi_get_all_clk()
1178 static int mtk_hdmi_clk_enable_audio(struct mtk_hdmi *hdmi) in mtk_hdmi_clk_enable_audio() argument
1182 ret = clk_prepare_enable(hdmi->clk[MTK_HDMI_CLK_AUD_BCLK]); in mtk_hdmi_clk_enable_audio()
1186 ret = clk_prepare_enable(hdmi->clk[MTK_HDMI_CLK_AUD_SPDIF]); in mtk_hdmi_clk_enable_audio()
1192 clk_disable_unprepare(hdmi->clk[MTK_HDMI_CLK_AUD_BCLK]); in mtk_hdmi_clk_enable_audio()
1196 static void mtk_hdmi_clk_disable_audio(struct mtk_hdmi *hdmi) in mtk_hdmi_clk_disable_audio() argument
1198 clk_disable_unprepare(hdmi->clk[MTK_HDMI_CLK_AUD_BCLK]); in mtk_hdmi_clk_disable_audio()
1199 clk_disable_unprepare(hdmi->clk[MTK_HDMI_CLK_AUD_SPDIF]); in mtk_hdmi_clk_disable_audio()
1203 mtk_hdmi_update_plugged_status(struct mtk_hdmi *hdmi) in mtk_hdmi_update_plugged_status() argument
1207 mutex_lock(&hdmi->update_plugged_status_lock); in mtk_hdmi_update_plugged_status()
1208 connected = mtk_cec_hpd_high(hdmi->cec_dev); in mtk_hdmi_update_plugged_status()
1209 if (hdmi->plugged_cb && hdmi->codec_dev) in mtk_hdmi_update_plugged_status()
1210 hdmi->plugged_cb(hdmi->codec_dev, connected); in mtk_hdmi_update_plugged_status()
1211 mutex_unlock(&hdmi->update_plugged_status_lock); in mtk_hdmi_update_plugged_status()
1220 struct mtk_hdmi *hdmi = hdmi_ctx_from_conn(conn); in hdmi_conn_detect() local
1221 return mtk_hdmi_update_plugged_status(hdmi); in hdmi_conn_detect()
1226 struct mtk_hdmi *hdmi = hdmi_ctx_from_conn(conn); in hdmi_conn_destroy() local
1228 mtk_cec_set_hpd_event(hdmi->cec_dev, NULL, NULL); in hdmi_conn_destroy()
1235 struct mtk_hdmi *hdmi = hdmi_ctx_from_conn(conn); in mtk_hdmi_conn_get_modes() local
1239 if (!hdmi->ddc_adpt) in mtk_hdmi_conn_get_modes()
1240 return -ENODEV; in mtk_hdmi_conn_get_modes()
1242 edid = drm_get_edid(conn, hdmi->ddc_adpt); in mtk_hdmi_conn_get_modes()
1244 return -ENODEV; in mtk_hdmi_conn_get_modes()
1246 hdmi->dvi_mode = !drm_detect_monitor_audio(edid); in mtk_hdmi_conn_get_modes()
1258 struct mtk_hdmi *hdmi = hdmi_ctx_from_conn(conn); in mtk_hdmi_conn_mode_valid() local
1261 dev_dbg(hdmi->dev, "xres=%d, yres=%d, refresh=%d, intl=%d clock=%d\n", in mtk_hdmi_conn_mode_valid()
1262 mode->hdisplay, mode->vdisplay, drm_mode_vrefresh(mode), in mtk_hdmi_conn_mode_valid()
1263 !!(mode->flags & DRM_MODE_FLAG_INTERLACE), mode->clock * 1000); in mtk_hdmi_conn_mode_valid()
1265 next_bridge = drm_bridge_get_next_bridge(&hdmi->bridge); in mtk_hdmi_conn_mode_valid()
1275 if (mode->clock < 27000) in mtk_hdmi_conn_mode_valid()
1277 if (mode->clock > 297000) in mtk_hdmi_conn_mode_valid()
1285 struct mtk_hdmi *hdmi = hdmi_ctx_from_conn(conn); in mtk_hdmi_conn_best_enc() local
1287 return hdmi->bridge.encoder; in mtk_hdmi_conn_best_enc()
1308 struct mtk_hdmi *hdmi = dev_get_drvdata(dev); in mtk_hdmi_hpd_event() local
1310 if (hdmi && hdmi->bridge.encoder && hdmi->bridge.encoder->dev) in mtk_hdmi_hpd_event()
1311 drm_helper_hpd_irq_event(hdmi->bridge.encoder->dev); in mtk_hdmi_hpd_event()
1315 * Bridge callbacks
1318 static int mtk_hdmi_bridge_attach(struct drm_bridge *bridge, in mtk_hdmi_bridge_attach() argument
1321 struct mtk_hdmi *hdmi = hdmi_ctx_from_bridge(bridge); in mtk_hdmi_bridge_attach() local
1325 DRM_ERROR("Fix bridge driver to make connector optional!"); in mtk_hdmi_bridge_attach()
1326 return -EINVAL; in mtk_hdmi_bridge_attach()
1329 ret = drm_connector_init_with_ddc(bridge->encoder->dev, &hdmi->conn, in mtk_hdmi_bridge_attach()
1332 hdmi->ddc_adpt); in mtk_hdmi_bridge_attach()
1334 dev_err(hdmi->dev, "Failed to initialize connector: %d\n", ret); in mtk_hdmi_bridge_attach()
1337 drm_connector_helper_add(&hdmi->conn, &mtk_hdmi_connector_helper_funcs); in mtk_hdmi_bridge_attach()
1339 hdmi->conn.polled = DRM_CONNECTOR_POLL_HPD; in mtk_hdmi_bridge_attach()
1340 hdmi->conn.interlace_allowed = true; in mtk_hdmi_bridge_attach()
1341 hdmi->conn.doublescan_allowed = false; in mtk_hdmi_bridge_attach()
1343 ret = drm_connector_attach_encoder(&hdmi->conn, in mtk_hdmi_bridge_attach()
1344 bridge->encoder); in mtk_hdmi_bridge_attach()
1346 dev_err(hdmi->dev, in mtk_hdmi_bridge_attach()
1351 if (hdmi->next_bridge) { in mtk_hdmi_bridge_attach()
1352 ret = drm_bridge_attach(bridge->encoder, hdmi->next_bridge, in mtk_hdmi_bridge_attach()
1353 bridge, flags); in mtk_hdmi_bridge_attach()
1355 dev_err(hdmi->dev, in mtk_hdmi_bridge_attach()
1356 "Failed to attach external bridge: %d\n", ret); in mtk_hdmi_bridge_attach()
1361 mtk_cec_set_hpd_event(hdmi->cec_dev, mtk_hdmi_hpd_event, hdmi->dev); in mtk_hdmi_bridge_attach()
1366 static bool mtk_hdmi_bridge_mode_fixup(struct drm_bridge *bridge, in mtk_hdmi_bridge_mode_fixup() argument
1373 static void mtk_hdmi_bridge_disable(struct drm_bridge *bridge) in mtk_hdmi_bridge_disable() argument
1375 struct mtk_hdmi *hdmi = hdmi_ctx_from_bridge(bridge); in mtk_hdmi_bridge_disable() local
1377 if (!hdmi->enabled) in mtk_hdmi_bridge_disable()
1380 phy_power_off(hdmi->phy); in mtk_hdmi_bridge_disable()
1381 clk_disable_unprepare(hdmi->clk[MTK_HDMI_CLK_HDMI_PIXEL]); in mtk_hdmi_bridge_disable()
1382 clk_disable_unprepare(hdmi->clk[MTK_HDMI_CLK_HDMI_PLL]); in mtk_hdmi_bridge_disable()
1384 hdmi->enabled = false; in mtk_hdmi_bridge_disable()
1387 static void mtk_hdmi_bridge_post_disable(struct drm_bridge *bridge) in mtk_hdmi_bridge_post_disable() argument
1389 struct mtk_hdmi *hdmi = hdmi_ctx_from_bridge(bridge); in mtk_hdmi_bridge_post_disable() local
1391 if (!hdmi->powered) in mtk_hdmi_bridge_post_disable()
1394 mtk_hdmi_hw_1p4_version_enable(hdmi, true); in mtk_hdmi_bridge_post_disable()
1395 mtk_hdmi_hw_make_reg_writable(hdmi, false); in mtk_hdmi_bridge_post_disable()
1397 hdmi->powered = false; in mtk_hdmi_bridge_post_disable()
1400 static void mtk_hdmi_bridge_mode_set(struct drm_bridge *bridge, in mtk_hdmi_bridge_mode_set() argument
1404 struct mtk_hdmi *hdmi = hdmi_ctx_from_bridge(bridge); in mtk_hdmi_bridge_mode_set() local
1406 dev_dbg(hdmi->dev, "cur info: name:%s, hdisplay:%d\n", in mtk_hdmi_bridge_mode_set()
1407 adjusted_mode->name, adjusted_mode->hdisplay); in mtk_hdmi_bridge_mode_set()
1408 dev_dbg(hdmi->dev, "hsync_start:%d,hsync_end:%d, htotal:%d", in mtk_hdmi_bridge_mode_set()
1409 adjusted_mode->hsync_start, adjusted_mode->hsync_end, in mtk_hdmi_bridge_mode_set()
1410 adjusted_mode->htotal); in mtk_hdmi_bridge_mode_set()
1411 dev_dbg(hdmi->dev, "hskew:%d, vdisplay:%d\n", in mtk_hdmi_bridge_mode_set()
1412 adjusted_mode->hskew, adjusted_mode->vdisplay); in mtk_hdmi_bridge_mode_set()
1413 dev_dbg(hdmi->dev, "vsync_start:%d, vsync_end:%d, vtotal:%d", in mtk_hdmi_bridge_mode_set()
1414 adjusted_mode->vsync_start, adjusted_mode->vsync_end, in mtk_hdmi_bridge_mode_set()
1415 adjusted_mode->vtotal); in mtk_hdmi_bridge_mode_set()
1416 dev_dbg(hdmi->dev, "vscan:%d, flag:%d\n", in mtk_hdmi_bridge_mode_set()
1417 adjusted_mode->vscan, adjusted_mode->flags); in mtk_hdmi_bridge_mode_set()
1419 drm_mode_copy(&hdmi->mode, adjusted_mode); in mtk_hdmi_bridge_mode_set()
1422 static void mtk_hdmi_bridge_pre_enable(struct drm_bridge *bridge) in mtk_hdmi_bridge_pre_enable() argument
1424 struct mtk_hdmi *hdmi = hdmi_ctx_from_bridge(bridge); in mtk_hdmi_bridge_pre_enable() local
1426 mtk_hdmi_hw_make_reg_writable(hdmi, true); in mtk_hdmi_bridge_pre_enable()
1427 mtk_hdmi_hw_1p4_version_enable(hdmi, true); in mtk_hdmi_bridge_pre_enable()
1429 hdmi->powered = true; in mtk_hdmi_bridge_pre_enable()
1432 static void mtk_hdmi_send_infoframe(struct mtk_hdmi *hdmi, in mtk_hdmi_send_infoframe() argument
1435 mtk_hdmi_setup_audio_infoframe(hdmi); in mtk_hdmi_send_infoframe()
1436 mtk_hdmi_setup_avi_infoframe(hdmi, mode); in mtk_hdmi_send_infoframe()
1437 mtk_hdmi_setup_spd_infoframe(hdmi, "mediatek", "On-chip HDMI"); in mtk_hdmi_send_infoframe()
1438 if (mode->flags & DRM_MODE_FLAG_3D_MASK) in mtk_hdmi_send_infoframe()
1439 mtk_hdmi_setup_vendor_specific_infoframe(hdmi, mode); in mtk_hdmi_send_infoframe()
1442 static void mtk_hdmi_bridge_enable(struct drm_bridge *bridge) in mtk_hdmi_bridge_enable() argument
1444 struct mtk_hdmi *hdmi = hdmi_ctx_from_bridge(bridge); in mtk_hdmi_bridge_enable() local
1446 mtk_hdmi_output_set_display_mode(hdmi, &hdmi->mode); in mtk_hdmi_bridge_enable()
1447 clk_prepare_enable(hdmi->clk[MTK_HDMI_CLK_HDMI_PLL]); in mtk_hdmi_bridge_enable()
1448 clk_prepare_enable(hdmi->clk[MTK_HDMI_CLK_HDMI_PIXEL]); in mtk_hdmi_bridge_enable()
1449 phy_power_on(hdmi->phy); in mtk_hdmi_bridge_enable()
1450 mtk_hdmi_send_infoframe(hdmi, &hdmi->mode); in mtk_hdmi_bridge_enable()
1452 hdmi->enabled = true; in mtk_hdmi_bridge_enable()
1465 static int mtk_hdmi_dt_parse_pdata(struct mtk_hdmi *hdmi, in mtk_hdmi_dt_parse_pdata() argument
1468 struct device *dev = &pdev->dev; in mtk_hdmi_dt_parse_pdata()
1469 struct device_node *np = dev->of_node; in mtk_hdmi_dt_parse_pdata()
1476 ret = mtk_hdmi_get_all_clk(hdmi, np); in mtk_hdmi_dt_parse_pdata()
1478 if (ret != -EPROBE_DEFER) in mtk_hdmi_dt_parse_pdata()
1484 /* The CEC module handles HDMI hotplug detection */ in mtk_hdmi_dt_parse_pdata()
1485 cec_np = of_get_compatible_child(np->parent, "mediatek,mt8173-cec"); in mtk_hdmi_dt_parse_pdata()
1488 return -EINVAL; in mtk_hdmi_dt_parse_pdata()
1493 dev_err(hdmi->dev, "Waiting for CEC device %pOF\n", in mtk_hdmi_dt_parse_pdata()
1496 return -EPROBE_DEFER; in mtk_hdmi_dt_parse_pdata()
1499 hdmi->cec_dev = &cec_pdev->dev; in mtk_hdmi_dt_parse_pdata()
1502 * The mediatek,syscon-hdmi property contains a phandle link to the in mtk_hdmi_dt_parse_pdata()
1506 regmap = syscon_regmap_lookup_by_phandle(np, "mediatek,syscon-hdmi"); in mtk_hdmi_dt_parse_pdata()
1507 ret = of_property_read_u32_index(np, "mediatek,syscon-hdmi", 1, in mtk_hdmi_dt_parse_pdata()
1508 &hdmi->sys_offset); in mtk_hdmi_dt_parse_pdata()
1517 hdmi->sys_regmap = regmap; in mtk_hdmi_dt_parse_pdata()
1520 hdmi->regs = devm_ioremap_resource(dev, mem); in mtk_hdmi_dt_parse_pdata()
1521 if (IS_ERR(hdmi->regs)) { in mtk_hdmi_dt_parse_pdata()
1522 ret = PTR_ERR(hdmi->regs); in mtk_hdmi_dt_parse_pdata()
1528 ret = -EINVAL; in mtk_hdmi_dt_parse_pdata()
1532 if (!of_device_is_compatible(remote, "hdmi-connector")) { in mtk_hdmi_dt_parse_pdata()
1533 hdmi->next_bridge = of_drm_find_bridge(remote); in mtk_hdmi_dt_parse_pdata()
1534 if (!hdmi->next_bridge) { in mtk_hdmi_dt_parse_pdata()
1535 dev_err(dev, "Waiting for external bridge\n"); in mtk_hdmi_dt_parse_pdata()
1537 ret = -EPROBE_DEFER; in mtk_hdmi_dt_parse_pdata()
1542 i2c_np = of_parse_phandle(remote, "ddc-i2c-bus", 0); in mtk_hdmi_dt_parse_pdata()
1544 dev_err(dev, "Failed to find ddc-i2c-bus node in %pOF\n", in mtk_hdmi_dt_parse_pdata()
1547 ret = -EINVAL; in mtk_hdmi_dt_parse_pdata()
1552 hdmi->ddc_adpt = of_find_i2c_adapter_by_node(i2c_np); in mtk_hdmi_dt_parse_pdata()
1554 if (!hdmi->ddc_adpt) { in mtk_hdmi_dt_parse_pdata()
1556 ret = -EINVAL; in mtk_hdmi_dt_parse_pdata()
1562 put_device(hdmi->cec_dev); in mtk_hdmi_dt_parse_pdata()
1567 * HDMI audio codec callbacks
1574 struct mtk_hdmi *hdmi = dev_get_drvdata(dev); in mtk_hdmi_audio_hw_params() local
1576 unsigned int chan = params->cea.channels; in mtk_hdmi_audio_hw_params()
1578 dev_dbg(hdmi->dev, "%s: %u Hz, %d bit, %d channels\n", __func__, in mtk_hdmi_audio_hw_params()
1579 params->sample_rate, params->sample_width, chan); in mtk_hdmi_audio_hw_params()
1581 if (!hdmi->bridge.encoder) in mtk_hdmi_audio_hw_params()
1582 return -ENODEV; in mtk_hdmi_audio_hw_params()
1598 dev_err(hdmi->dev, "channel[%d] not supported!\n", chan); in mtk_hdmi_audio_hw_params()
1599 return -EINVAL; in mtk_hdmi_audio_hw_params()
1602 switch (params->sample_rate) { in mtk_hdmi_audio_hw_params()
1612 dev_err(hdmi->dev, "rate[%d] not supported!\n", in mtk_hdmi_audio_hw_params()
1613 params->sample_rate); in mtk_hdmi_audio_hw_params()
1614 return -EINVAL; in mtk_hdmi_audio_hw_params()
1617 switch (daifmt->fmt) { in mtk_hdmi_audio_hw_params()
1631 dev_err(hdmi->dev, "%s: Invalid DAI format %d\n", __func__, in mtk_hdmi_audio_hw_params()
1632 daifmt->fmt); in mtk_hdmi_audio_hw_params()
1633 return -EINVAL; in mtk_hdmi_audio_hw_params()
1639 mtk_hdmi_audio_set_param(hdmi, &hdmi_params); in mtk_hdmi_audio_hw_params()
1646 struct mtk_hdmi *hdmi = dev_get_drvdata(dev); in mtk_hdmi_audio_startup() local
1648 mtk_hdmi_audio_enable(hdmi); in mtk_hdmi_audio_startup()
1655 struct mtk_hdmi *hdmi = dev_get_drvdata(dev); in mtk_hdmi_audio_shutdown() local
1657 mtk_hdmi_audio_disable(hdmi); in mtk_hdmi_audio_shutdown()
1664 struct mtk_hdmi *hdmi = dev_get_drvdata(dev); in mtk_hdmi_audio_mute() local
1667 mtk_hdmi_hw_aud_mute(hdmi); in mtk_hdmi_audio_mute()
1669 mtk_hdmi_hw_aud_unmute(hdmi); in mtk_hdmi_audio_mute()
1676 struct mtk_hdmi *hdmi = dev_get_drvdata(dev); in mtk_hdmi_audio_get_eld() local
1678 memcpy(buf, hdmi->conn.eld, min(sizeof(hdmi->conn.eld), len)); in mtk_hdmi_audio_get_eld()
1687 struct mtk_hdmi *hdmi = data; in mtk_hdmi_audio_hook_plugged_cb() local
1689 mutex_lock(&hdmi->update_plugged_status_lock); in mtk_hdmi_audio_hook_plugged_cb()
1690 hdmi->plugged_cb = fn; in mtk_hdmi_audio_hook_plugged_cb()
1691 hdmi->codec_dev = codec_dev; in mtk_hdmi_audio_hook_plugged_cb()
1692 mutex_unlock(&hdmi->update_plugged_status_lock); in mtk_hdmi_audio_hook_plugged_cb()
1694 mtk_hdmi_update_plugged_status(hdmi); in mtk_hdmi_audio_hook_plugged_cb()
1711 struct mtk_hdmi *hdmi = dev_get_drvdata(dev); in mtk_hdmi_register_audio_driver() local
1716 .data = hdmi, in mtk_hdmi_register_audio_driver()
1726 DRM_INFO("%s driver bound to HDMI\n", HDMI_CODEC_DRV_NAME); in mtk_hdmi_register_audio_driver()
1732 struct mtk_hdmi *hdmi; in mtk_drm_hdmi_probe() local
1733 struct device *dev = &pdev->dev; in mtk_drm_hdmi_probe()
1736 hdmi = devm_kzalloc(dev, sizeof(*hdmi), GFP_KERNEL); in mtk_drm_hdmi_probe()
1737 if (!hdmi) in mtk_drm_hdmi_probe()
1738 return -ENOMEM; in mtk_drm_hdmi_probe()
1740 hdmi->dev = dev; in mtk_drm_hdmi_probe()
1741 hdmi->conf = of_device_get_match_data(dev); in mtk_drm_hdmi_probe()
1743 ret = mtk_hdmi_dt_parse_pdata(hdmi, pdev); in mtk_drm_hdmi_probe()
1747 hdmi->phy = devm_phy_get(dev, "hdmi"); in mtk_drm_hdmi_probe()
1748 if (IS_ERR(hdmi->phy)) { in mtk_drm_hdmi_probe()
1749 ret = PTR_ERR(hdmi->phy); in mtk_drm_hdmi_probe()
1750 dev_err(dev, "Failed to get HDMI PHY: %d\n", ret); in mtk_drm_hdmi_probe()
1754 mutex_init(&hdmi->update_plugged_status_lock); in mtk_drm_hdmi_probe()
1755 platform_set_drvdata(pdev, hdmi); in mtk_drm_hdmi_probe()
1757 ret = mtk_hdmi_output_init(hdmi); in mtk_drm_hdmi_probe()
1759 dev_err(dev, "Failed to initialize hdmi output\n"); in mtk_drm_hdmi_probe()
1769 hdmi->bridge.funcs = &mtk_hdmi_bridge_funcs; in mtk_drm_hdmi_probe()
1770 hdmi->bridge.of_node = pdev->dev.of_node; in mtk_drm_hdmi_probe()
1771 drm_bridge_add(&hdmi->bridge); in mtk_drm_hdmi_probe()
1773 ret = mtk_hdmi_clk_enable_audio(hdmi); in mtk_drm_hdmi_probe()
1782 drm_bridge_remove(&hdmi->bridge); in mtk_drm_hdmi_probe()
1788 struct mtk_hdmi *hdmi = platform_get_drvdata(pdev); in mtk_drm_hdmi_remove() local
1790 drm_bridge_remove(&hdmi->bridge); in mtk_drm_hdmi_remove()
1791 mtk_hdmi_clk_disable_audio(hdmi); in mtk_drm_hdmi_remove()
1798 struct mtk_hdmi *hdmi = dev_get_drvdata(dev); in mtk_hdmi_suspend() local
1800 mtk_hdmi_clk_disable_audio(hdmi); in mtk_hdmi_suspend()
1807 struct mtk_hdmi *hdmi = dev_get_drvdata(dev); in mtk_hdmi_resume() local
1810 ret = mtk_hdmi_clk_enable_audio(hdmi); in mtk_hdmi_resume()
1812 dev_err(dev, "hdmi resume failed!\n"); in mtk_hdmi_resume()
1827 { .compatible = "mediatek,mt2701-hdmi",
1830 { .compatible = "mediatek,mt8173-hdmi",
1839 .name = "mediatek-drm-hdmi",
1867 MODULE_DESCRIPTION("MediaTek HDMI Driver");