^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /* SPDX-License-Identifier: GPL-2.0-or-later */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Universal Interface for Intel High Definition Audio Codec
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Local helper functions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Copyright (c) 2004 Takashi Iwai <tiwai@suse.de>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #ifndef __SOUND_HDA_LOCAL_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #define __SOUND_HDA_LOCAL_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) /* We abuse kcontrol_new.subdev field to pass the NID corresponding to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) * the given new control. If id.subdev has a bit flag HDA_SUBDEV_NID_FLAG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) * snd_hda_ctl_add() takes the lower-bit subdev value as a valid NID.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) * Note that the subdevice field is cleared again before the real registration
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) * in snd_hda_ctl_add(), so that this value won't appear in the outside.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #define HDA_SUBDEV_NID_FLAG (1U << 31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #define HDA_SUBDEV_AMP_FLAG (1U << 30)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) * for mixer controls
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #define HDA_COMPOSE_AMP_VAL_OFS(nid,chs,idx,dir,ofs) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) ((nid) | ((chs)<<16) | ((dir)<<18) | ((idx)<<19) | ((ofs)<<23))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #define HDA_AMP_VAL_MIN_MUTE (1<<29)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #define HDA_COMPOSE_AMP_VAL(nid,chs,idx,dir) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) HDA_COMPOSE_AMP_VAL_OFS(nid, chs, idx, dir, 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) /* mono volume with index (index=0,1,...) (channel=1,2) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) #define HDA_CODEC_VOLUME_MONO_IDX(xname, xcidx, nid, channel, xindex, dir, flags) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xcidx, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) .subdevice = HDA_SUBDEV_AMP_FLAG, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) SNDRV_CTL_ELEM_ACCESS_TLV_READ | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) .info = snd_hda_mixer_amp_volume_info, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) .get = snd_hda_mixer_amp_volume_get, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) .put = snd_hda_mixer_amp_volume_put, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) .tlv = { .c = snd_hda_mixer_amp_tlv }, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) .private_value = HDA_COMPOSE_AMP_VAL(nid, channel, xindex, dir) | flags }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) /* stereo volume with index */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) #define HDA_CODEC_VOLUME_IDX(xname, xcidx, nid, xindex, direction) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) HDA_CODEC_VOLUME_MONO_IDX(xname, xcidx, nid, 3, xindex, direction, 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) /* mono volume */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) #define HDA_CODEC_VOLUME_MONO(xname, nid, channel, xindex, direction) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) HDA_CODEC_VOLUME_MONO_IDX(xname, 0, nid, channel, xindex, direction, 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) /* stereo volume */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) #define HDA_CODEC_VOLUME(xname, nid, xindex, direction) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) HDA_CODEC_VOLUME_MONO(xname, nid, 3, xindex, direction)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) /* stereo volume with min=mute */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) #define HDA_CODEC_VOLUME_MIN_MUTE(xname, nid, xindex, direction) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) HDA_CODEC_VOLUME_MONO_IDX(xname, 0, nid, 3, xindex, direction, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) HDA_AMP_VAL_MIN_MUTE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) /* mono mute switch with index (index=0,1,...) (channel=1,2) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) #define HDA_CODEC_MUTE_MONO_IDX(xname, xcidx, nid, channel, xindex, direction) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xcidx, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) .subdevice = HDA_SUBDEV_AMP_FLAG, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) .info = snd_hda_mixer_amp_switch_info, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) .get = snd_hda_mixer_amp_switch_get, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) .put = snd_hda_mixer_amp_switch_put, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) .private_value = HDA_COMPOSE_AMP_VAL(nid, channel, xindex, direction) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) /* stereo mute switch with index */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) #define HDA_CODEC_MUTE_IDX(xname, xcidx, nid, xindex, direction) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) HDA_CODEC_MUTE_MONO_IDX(xname, xcidx, nid, 3, xindex, direction)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) /* mono mute switch */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) #define HDA_CODEC_MUTE_MONO(xname, nid, channel, xindex, direction) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) HDA_CODEC_MUTE_MONO_IDX(xname, 0, nid, channel, xindex, direction)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) /* stereo mute switch */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) #define HDA_CODEC_MUTE(xname, nid, xindex, direction) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) HDA_CODEC_MUTE_MONO(xname, nid, 3, xindex, direction)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) #ifdef CONFIG_SND_HDA_INPUT_BEEP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) /* special beep mono mute switch with index (index=0,1,...) (channel=1,2) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) #define HDA_CODEC_MUTE_BEEP_MONO_IDX(xname, xcidx, nid, channel, xindex, direction) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xcidx, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) .subdevice = HDA_SUBDEV_AMP_FLAG, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) .info = snd_hda_mixer_amp_switch_info, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) .get = snd_hda_mixer_amp_switch_get_beep, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) .put = snd_hda_mixer_amp_switch_put_beep, \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) .private_value = HDA_COMPOSE_AMP_VAL(nid, channel, xindex, direction) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) /* no digital beep - just the standard one */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) #define HDA_CODEC_MUTE_BEEP_MONO_IDX(xname, xcidx, nid, ch, xidx, dir) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) HDA_CODEC_MUTE_MONO_IDX(xname, xcidx, nid, ch, xidx, dir)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) #endif /* CONFIG_SND_HDA_INPUT_BEEP */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) /* special beep mono mute switch */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) #define HDA_CODEC_MUTE_BEEP_MONO(xname, nid, channel, xindex, direction) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) HDA_CODEC_MUTE_BEEP_MONO_IDX(xname, 0, nid, channel, xindex, direction)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) /* special beep stereo mute switch */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) #define HDA_CODEC_MUTE_BEEP(xname, nid, xindex, direction) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) HDA_CODEC_MUTE_BEEP_MONO(xname, nid, 3, xindex, direction)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) extern const char *snd_hda_pcm_type_name[];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) int snd_hda_mixer_amp_volume_info(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) struct snd_ctl_elem_info *uinfo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) int snd_hda_mixer_amp_volume_get(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) struct snd_ctl_elem_value *ucontrol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) int snd_hda_mixer_amp_volume_put(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) struct snd_ctl_elem_value *ucontrol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) int snd_hda_mixer_amp_tlv(struct snd_kcontrol *kcontrol, int op_flag,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) unsigned int size, unsigned int __user *_tlv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) int snd_hda_mixer_amp_switch_info(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) struct snd_ctl_elem_info *uinfo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) int snd_hda_mixer_amp_switch_get(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) struct snd_ctl_elem_value *ucontrol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) int snd_hda_mixer_amp_switch_put(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) struct snd_ctl_elem_value *ucontrol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) #ifdef CONFIG_SND_HDA_INPUT_BEEP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) int snd_hda_mixer_amp_switch_get_beep(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) struct snd_ctl_elem_value *ucontrol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) int snd_hda_mixer_amp_switch_put_beep(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) struct snd_ctl_elem_value *ucontrol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) /* lowlevel accessor with caching; use carefully */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) #define snd_hda_codec_amp_read(codec, nid, ch, dir, idx) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) snd_hdac_regmap_get_amp(&(codec)->core, nid, ch, dir, idx)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) int snd_hda_codec_amp_update(struct hda_codec *codec, hda_nid_t nid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) int ch, int dir, int idx, int mask, int val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) int snd_hda_codec_amp_stereo(struct hda_codec *codec, hda_nid_t nid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) int direction, int idx, int mask, int val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) int snd_hda_codec_amp_init(struct hda_codec *codec, hda_nid_t nid, int ch,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) int direction, int idx, int mask, int val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) int snd_hda_codec_amp_init_stereo(struct hda_codec *codec, hda_nid_t nid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) int dir, int idx, int mask, int val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) void snd_hda_set_vmaster_tlv(struct hda_codec *codec, hda_nid_t nid, int dir,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) unsigned int *tlv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) struct snd_kcontrol *snd_hda_find_mixer_ctl(struct hda_codec *codec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) const char *name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) int __snd_hda_add_vmaster(struct hda_codec *codec, char *name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) unsigned int *tlv, const char * const *followers,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) const char *suffix, bool init_follower_vol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) struct snd_kcontrol **ctl_ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) #define snd_hda_add_vmaster(codec, name, tlv, followers, suffix) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) __snd_hda_add_vmaster(codec, name, tlv, followers, suffix, true, NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) int snd_hda_codec_reset(struct hda_codec *codec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) void snd_hda_codec_register(struct hda_codec *codec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) void snd_hda_codec_cleanup_for_unbind(struct hda_codec *codec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) #define snd_hda_regmap_sync(codec) snd_hdac_regmap_sync(&(codec)->core)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) enum {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) HDA_VMUTE_OFF,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) HDA_VMUTE_ON,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) HDA_VMUTE_FOLLOW_MASTER,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) struct hda_vmaster_mute_hook {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) /* below two fields must be filled by the caller of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) * snd_hda_add_vmaster_hook() beforehand
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) struct snd_kcontrol *sw_kctl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) void (*hook)(void *, int);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) /* below are initialized automatically */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) unsigned int mute_mode; /* HDA_VMUTE_XXX */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) struct hda_codec *codec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) int snd_hda_add_vmaster_hook(struct hda_codec *codec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) struct hda_vmaster_mute_hook *hook,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) bool expose_enum_ctl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) void snd_hda_sync_vmaster_hook(struct hda_vmaster_mute_hook *hook);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) /* amp value bits */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) #define HDA_AMP_MUTE 0x80
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) #define HDA_AMP_UNMUTE 0x00
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) #define HDA_AMP_VOLMASK 0x7f
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) * SPDIF I/O
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) int snd_hda_create_dig_out_ctls(struct hda_codec *codec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) hda_nid_t associated_nid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) hda_nid_t cvt_nid, int type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) #define snd_hda_create_spdif_out_ctls(codec, anid, cnid) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) snd_hda_create_dig_out_ctls(codec, anid, cnid, HDA_PCM_TYPE_SPDIF)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) int snd_hda_create_spdif_in_ctls(struct hda_codec *codec, hda_nid_t nid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) * input MUX helper
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) #define HDA_MAX_NUM_INPUTS 16
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) struct hda_input_mux_item {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) char label[32];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) unsigned int index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) struct hda_input_mux {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) unsigned int num_items;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) struct hda_input_mux_item items[HDA_MAX_NUM_INPUTS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) int snd_hda_input_mux_info(const struct hda_input_mux *imux,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) struct snd_ctl_elem_info *uinfo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) int snd_hda_input_mux_put(struct hda_codec *codec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) const struct hda_input_mux *imux,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) struct snd_ctl_elem_value *ucontrol, hda_nid_t nid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) unsigned int *cur_val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) int snd_hda_add_imux_item(struct hda_codec *codec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) struct hda_input_mux *imux, const char *label,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) int index, int *type_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) * Multi-channel / digital-out PCM helper
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) enum { HDA_FRONT, HDA_REAR, HDA_CLFE, HDA_SIDE }; /* index for dac_nidx */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) enum { HDA_DIG_NONE, HDA_DIG_EXCLUSIVE, HDA_DIG_ANALOG_DUP }; /* dig_out_used */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) #define HDA_MAX_OUTS 5
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) struct hda_multi_out {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) int num_dacs; /* # of DACs, must be more than 1 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) const hda_nid_t *dac_nids; /* DAC list */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) hda_nid_t hp_nid; /* optional DAC for HP, 0 when not exists */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) hda_nid_t hp_out_nid[HDA_MAX_OUTS]; /* DACs for multiple HPs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) hda_nid_t extra_out_nid[HDA_MAX_OUTS]; /* other (e.g. speaker) DACs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) hda_nid_t dig_out_nid; /* digital out audio widget */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) const hda_nid_t *follower_dig_outs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) int max_channels; /* currently supported analog channels */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) int dig_out_used; /* current usage of digital out (HDA_DIG_XXX) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) int no_share_stream; /* don't share a stream with multiple pins */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) int share_spdif; /* share SPDIF pin */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) /* PCM information for both analog and SPDIF DACs */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) unsigned int analog_rates;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) unsigned int analog_maxbps;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) u64 analog_formats;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) unsigned int spdif_rates;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) unsigned int spdif_maxbps;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) u64 spdif_formats;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) int snd_hda_create_spdif_share_sw(struct hda_codec *codec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) struct hda_multi_out *mout);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) int snd_hda_multi_out_dig_open(struct hda_codec *codec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) struct hda_multi_out *mout);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) int snd_hda_multi_out_dig_close(struct hda_codec *codec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) struct hda_multi_out *mout);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) int snd_hda_multi_out_dig_prepare(struct hda_codec *codec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) struct hda_multi_out *mout,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) unsigned int stream_tag,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) unsigned int format,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) struct snd_pcm_substream *substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) int snd_hda_multi_out_dig_cleanup(struct hda_codec *codec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) struct hda_multi_out *mout);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) int snd_hda_multi_out_analog_open(struct hda_codec *codec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) struct hda_multi_out *mout,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) struct snd_pcm_substream *substream,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) struct hda_pcm_stream *hinfo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) int snd_hda_multi_out_analog_prepare(struct hda_codec *codec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) struct hda_multi_out *mout,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) unsigned int stream_tag,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) unsigned int format,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) struct snd_pcm_substream *substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) int snd_hda_multi_out_analog_cleanup(struct hda_codec *codec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) struct hda_multi_out *mout);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) * generic proc interface
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) #ifdef CONFIG_SND_PROC_FS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) int snd_hda_codec_proc_new(struct hda_codec *codec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) static inline int snd_hda_codec_proc_new(struct hda_codec *codec) { return 0; }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) #define SND_PRINT_BITS_ADVISED_BUFSIZE 16
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) void snd_print_pcm_bits(int pcm, char *buf, int buflen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) * Misc
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) int snd_hda_add_new_ctls(struct hda_codec *codec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) const struct snd_kcontrol_new *knew);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) * Fix-up pin default configurations and add default verbs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) struct hda_pintbl {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) hda_nid_t nid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) u32 val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) struct hda_model_fixup {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) const int id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) const char *name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) struct hda_fixup {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) int type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) bool chained:1; /* call the chained fixup(s) after this */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) bool chained_before:1; /* call the chained fixup(s) before this */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) int chain_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) union {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) const struct hda_pintbl *pins;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) const struct hda_verb *verbs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) void (*func)(struct hda_codec *codec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) const struct hda_fixup *fix,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) int action);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) } v;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) struct snd_hda_pin_quirk {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) unsigned int codec; /* Codec vendor/device ID */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) unsigned short subvendor; /* PCI subvendor ID */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) const struct hda_pintbl *pins; /* list of matching pins */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) #ifdef CONFIG_SND_DEBUG_VERBOSE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) const char *name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) int value; /* quirk value */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) #ifdef CONFIG_SND_DEBUG_VERBOSE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) #define SND_HDA_PIN_QUIRK(_codec, _subvendor, _name, _value, _pins...) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) { .codec = _codec,\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) .subvendor = _subvendor,\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) .name = _name,\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) .value = _value,\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) .pins = (const struct hda_pintbl[]) { _pins, {0, 0}} \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) #define SND_HDA_PIN_QUIRK(_codec, _subvendor, _name, _value, _pins...) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) { .codec = _codec,\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) .subvendor = _subvendor,\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) .value = _value,\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) .pins = (const struct hda_pintbl[]) { _pins, {0, 0}} \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) #define HDA_FIXUP_ID_NOT_SET -1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) #define HDA_FIXUP_ID_NO_FIXUP -2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) /* fixup types */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) enum {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) HDA_FIXUP_INVALID,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) HDA_FIXUP_PINS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) HDA_FIXUP_VERBS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) HDA_FIXUP_FUNC,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) HDA_FIXUP_PINCTLS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) /* fixup action definitions */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) enum {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) HDA_FIXUP_ACT_PRE_PROBE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) HDA_FIXUP_ACT_PROBE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) HDA_FIXUP_ACT_INIT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) HDA_FIXUP_ACT_BUILD,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) HDA_FIXUP_ACT_FREE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) int snd_hda_add_verbs(struct hda_codec *codec, const struct hda_verb *list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) void snd_hda_apply_verbs(struct hda_codec *codec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) void snd_hda_apply_pincfgs(struct hda_codec *codec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) const struct hda_pintbl *cfg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) void snd_hda_apply_fixup(struct hda_codec *codec, int action);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) void snd_hda_pick_fixup(struct hda_codec *codec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) const struct hda_model_fixup *models,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) const struct snd_pci_quirk *quirk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) const struct hda_fixup *fixlist);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) void snd_hda_pick_pin_fixup(struct hda_codec *codec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) const struct snd_hda_pin_quirk *pin_quirk,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) const struct hda_fixup *fixlist,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) bool match_all_pins);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) /* helper macros to retrieve pin default-config values */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) #define get_defcfg_connect(cfg) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) ((cfg & AC_DEFCFG_PORT_CONN) >> AC_DEFCFG_PORT_CONN_SHIFT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) #define get_defcfg_association(cfg) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) ((cfg & AC_DEFCFG_DEF_ASSOC) >> AC_DEFCFG_ASSOC_SHIFT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) #define get_defcfg_location(cfg) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) ((cfg & AC_DEFCFG_LOCATION) >> AC_DEFCFG_LOCATION_SHIFT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) #define get_defcfg_sequence(cfg) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) (cfg & AC_DEFCFG_SEQUENCE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) #define get_defcfg_device(cfg) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) ((cfg & AC_DEFCFG_DEVICE) >> AC_DEFCFG_DEVICE_SHIFT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) #define get_defcfg_misc(cfg) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) ((cfg & AC_DEFCFG_MISC) >> AC_DEFCFG_MISC_SHIFT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) /* amp values */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) #define AMP_IN_MUTE(idx) (0x7080 | ((idx)<<8))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) #define AMP_IN_UNMUTE(idx) (0x7000 | ((idx)<<8))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) #define AMP_OUT_MUTE 0xb080
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) #define AMP_OUT_UNMUTE 0xb000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) #define AMP_OUT_ZERO 0xb000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) /* pinctl values */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) #define PIN_IN (AC_PINCTL_IN_EN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) #define PIN_VREFHIZ (AC_PINCTL_IN_EN | AC_PINCTL_VREF_HIZ)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) #define PIN_VREF50 (AC_PINCTL_IN_EN | AC_PINCTL_VREF_50)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) #define PIN_VREFGRD (AC_PINCTL_IN_EN | AC_PINCTL_VREF_GRD)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) #define PIN_VREF80 (AC_PINCTL_IN_EN | AC_PINCTL_VREF_80)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) #define PIN_VREF100 (AC_PINCTL_IN_EN | AC_PINCTL_VREF_100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) #define PIN_OUT (AC_PINCTL_OUT_EN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) #define PIN_HP (AC_PINCTL_OUT_EN | AC_PINCTL_HP_EN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) #define PIN_HP_AMP (AC_PINCTL_HP_EN)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) unsigned int snd_hda_get_default_vref(struct hda_codec *codec, hda_nid_t pin);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) unsigned int snd_hda_correct_pin_ctl(struct hda_codec *codec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) hda_nid_t pin, unsigned int val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) int _snd_hda_set_pin_ctl(struct hda_codec *codec, hda_nid_t pin,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) unsigned int val, bool cached);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) * _snd_hda_set_pin_ctl - Set a pin-control value safely
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) * @codec: the codec instance
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) * @pin: the pin NID to set the control
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) * @val: the pin-control value (AC_PINCTL_* bits)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) * This function sets the pin-control value to the given pin, but
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) * filters out the invalid pin-control bits when the pin has no such
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) * capabilities. For example, when PIN_HP is passed but the pin has no
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) * HP-drive capability, the HP bit is omitted.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) * The function doesn't check the input VREF capability bits, though.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) * Use snd_hda_get_default_vref() to guess the right value.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) * Also, this function is only for analog pins, not for HDMI pins.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) static inline int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) snd_hda_set_pin_ctl(struct hda_codec *codec, hda_nid_t pin, unsigned int val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) return _snd_hda_set_pin_ctl(codec, pin, val, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) * snd_hda_set_pin_ctl_cache - Set a pin-control value safely
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) * @codec: the codec instance
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) * @pin: the pin NID to set the control
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) * @val: the pin-control value (AC_PINCTL_* bits)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) * Just like snd_hda_set_pin_ctl() but write to cache as well.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) static inline int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) snd_hda_set_pin_ctl_cache(struct hda_codec *codec, hda_nid_t pin,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) unsigned int val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) return _snd_hda_set_pin_ctl(codec, pin, val, true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) int snd_hda_codec_get_pin_target(struct hda_codec *codec, hda_nid_t nid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) int snd_hda_codec_set_pin_target(struct hda_codec *codec, hda_nid_t nid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) unsigned int val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) #define for_each_hda_codec_node(nid, codec) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) for ((nid) = (codec)->core.start_nid; (nid) < (codec)->core.end_nid; (nid)++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) * get widget capabilities
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) static inline u32 get_wcaps(struct hda_codec *codec, hda_nid_t nid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) if (nid < codec->core.start_nid ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) nid >= codec->core.start_nid + codec->core.num_nodes)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) return codec->wcaps[nid - codec->core.start_nid];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) /* get the widget type from widget capability bits */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) static inline int get_wcaps_type(unsigned int wcaps)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) if (!wcaps)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) return -1; /* invalid type */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) return (wcaps & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) static inline unsigned int get_wcaps_channels(u32 wcaps)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) unsigned int chans;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) chans = (wcaps & AC_WCAP_CHAN_CNT_EXT) >> 13;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) chans = ((chans << 1) | 1) + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) return chans;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) static inline void snd_hda_override_wcaps(struct hda_codec *codec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) hda_nid_t nid, u32 val)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) if (nid >= codec->core.start_nid &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) nid < codec->core.start_nid + codec->core.num_nodes)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) codec->wcaps[nid - codec->core.start_nid] = val;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) u32 query_amp_caps(struct hda_codec *codec, hda_nid_t nid, int direction);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) int snd_hda_override_amp_caps(struct hda_codec *codec, hda_nid_t nid, int dir,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) unsigned int caps);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) * snd_hda_query_pin_caps - Query PIN capabilities
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) * @codec: the HD-auio codec
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) * @nid: the NID to query
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) * Query PIN capabilities for the given widget.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) * Returns the obtained capability bits.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) * When cap bits have been already read, this doesn't read again but
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) * returns the cached value.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) static inline u32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) snd_hda_query_pin_caps(struct hda_codec *codec, hda_nid_t nid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) return snd_hda_param_read(codec, nid, AC_PAR_PIN_CAP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) * snd_hda_override_pin_caps - Override the pin capabilities
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) * @codec: the CODEC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) * @nid: the NID to override
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) * @caps: the capability bits to set
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) * Override the cached PIN capabilitiy bits value by the given one.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) * Returns zero if successful or a negative error code.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) static inline int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) snd_hda_override_pin_caps(struct hda_codec *codec, hda_nid_t nid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) unsigned int caps)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) return snd_hdac_override_parm(&codec->core, nid, AC_PAR_PIN_CAP, caps);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) bool snd_hda_check_amp_caps(struct hda_codec *codec, hda_nid_t nid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) int dir, unsigned int bits);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) #define nid_has_mute(codec, nid, dir) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) snd_hda_check_amp_caps(codec, nid, dir, (AC_AMPCAP_MUTE | AC_AMPCAP_MIN_MUTE))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) #define nid_has_volume(codec, nid, dir) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) snd_hda_check_amp_caps(codec, nid, dir, AC_AMPCAP_NUM_STEPS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) /* flags for hda_nid_item */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) #define HDA_NID_ITEM_AMP (1<<0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) struct hda_nid_item {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) struct snd_kcontrol *kctl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) unsigned int index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) hda_nid_t nid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) unsigned short flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) int snd_hda_ctl_add(struct hda_codec *codec, hda_nid_t nid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) struct snd_kcontrol *kctl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) int snd_hda_add_nid(struct hda_codec *codec, struct snd_kcontrol *kctl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) unsigned int index, hda_nid_t nid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) void snd_hda_ctls_clear(struct hda_codec *codec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) * hwdep interface
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) #ifdef CONFIG_SND_HDA_HWDEP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) int snd_hda_create_hwdep(struct hda_codec *codec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) static inline int snd_hda_create_hwdep(struct hda_codec *codec) { return 0; }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) void snd_hda_sysfs_init(struct hda_codec *codec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) void snd_hda_sysfs_clear(struct hda_codec *codec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) extern const struct attribute_group *snd_hda_dev_attr_groups[];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) #ifdef CONFIG_SND_HDA_RECONFIG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) const char *snd_hda_get_hint(struct hda_codec *codec, const char *key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) int snd_hda_get_bool_hint(struct hda_codec *codec, const char *key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) int snd_hda_get_int_hint(struct hda_codec *codec, const char *key, int *valp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) static inline
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) const char *snd_hda_get_hint(struct hda_codec *codec, const char *key)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) return NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) static inline
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) int snd_hda_get_bool_hint(struct hda_codec *codec, const char *key)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) return -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) static inline
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) int snd_hda_get_int_hint(struct hda_codec *codec, const char *key, int *valp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) return -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) * power-management
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) void snd_hda_schedule_power_save(struct hda_codec *codec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) struct hda_amp_list {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) hda_nid_t nid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) unsigned char dir;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) unsigned char idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) struct hda_loopback_check {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) const struct hda_amp_list *amplist;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) int power_on;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) int snd_hda_check_amp_list_power(struct hda_codec *codec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) struct hda_loopback_check *check,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) hda_nid_t nid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) /* check whether the actual power state matches with the target state */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) static inline bool
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) snd_hda_check_power_state(struct hda_codec *codec, hda_nid_t nid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) unsigned int target_state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) return snd_hdac_check_power_state(&codec->core, nid, target_state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) static inline unsigned int snd_hda_sync_power_state(struct hda_codec *codec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) hda_nid_t nid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) unsigned int target_state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) return snd_hdac_sync_power_state(&codec->core, nid, target_state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) unsigned int snd_hda_codec_eapd_power_filter(struct hda_codec *codec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) hda_nid_t nid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) unsigned int power_state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) * AMP control callbacks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) /* retrieve parameters from private_value */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) #define get_amp_nid_(pv) ((pv) & 0xffff)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) #define get_amp_nid(kc) get_amp_nid_((kc)->private_value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) #define get_amp_channels(kc) (((kc)->private_value >> 16) & 0x3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) #define get_amp_direction_(pv) (((pv) >> 18) & 0x1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) #define get_amp_direction(kc) get_amp_direction_((kc)->private_value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) #define get_amp_index_(pv) (((pv) >> 19) & 0xf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) #define get_amp_index(kc) get_amp_index_((kc)->private_value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) #define get_amp_offset(kc) (((kc)->private_value >> 23) & 0x3f)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) #define get_amp_min_mute(kc) (((kc)->private_value >> 29) & 0x1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) * enum control helper
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643) int snd_hda_enum_helper_info(struct snd_kcontrol *kcontrol,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) struct snd_ctl_elem_info *uinfo,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) int num_items, const char * const *texts);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) #define snd_hda_enum_bool_helper_info(kcontrol, uinfo) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) snd_hda_enum_helper_info(kcontrol, uinfo, 0, NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) * CEA Short Audio Descriptor data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) struct cea_sad {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) int channels;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) int format; /* (format == 0) indicates invalid SAD */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) int rates;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) int sample_bits; /* for LPCM */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) int max_bitrate; /* for AC3...ATRAC */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) int profile; /* for WMAPRO */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) #define ELD_FIXED_BYTES 20
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) #define ELD_MAX_SIZE 256
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) #define ELD_MAX_MNL 16
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) #define ELD_MAX_SAD 16
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) * ELD: EDID Like Data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) struct parsed_hdmi_eld {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) * all fields will be cleared before updating ELD
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673) int baseline_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) int eld_ver;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) int cea_edid_ver;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) char monitor_name[ELD_MAX_MNL + 1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) int manufacture_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) int product_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) u64 port_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) int support_hdcp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) int support_ai;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) int conn_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) int aud_synch_delay;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) int spk_alloc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) int sad_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) struct cea_sad sad[ELD_MAX_SAD];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) struct hdmi_eld {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) bool monitor_present;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) bool eld_valid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) int eld_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) char eld_buffer[ELD_MAX_SIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) struct parsed_hdmi_eld info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) int snd_hdmi_get_eld_size(struct hda_codec *codec, hda_nid_t nid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) int snd_hdmi_get_eld(struct hda_codec *codec, hda_nid_t nid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) unsigned char *buf, int *eld_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) int snd_hdmi_parse_eld(struct hda_codec *codec, struct parsed_hdmi_eld *e,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) const unsigned char *buf, int size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) void snd_hdmi_show_eld(struct hda_codec *codec, struct parsed_hdmi_eld *e);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) void snd_hdmi_eld_update_pcm_info(struct parsed_hdmi_eld *e,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) struct hda_pcm_stream *hinfo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) int snd_hdmi_get_eld_ati(struct hda_codec *codec, hda_nid_t nid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) unsigned char *buf, int *eld_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) bool rev3_or_later);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) #ifdef CONFIG_SND_PROC_FS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) void snd_hdmi_print_eld_info(struct hdmi_eld *eld,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) struct snd_info_buffer *buffer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) void snd_hdmi_write_eld_info(struct hdmi_eld *eld,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) struct snd_info_buffer *buffer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) #define SND_PRINT_CHANNEL_ALLOCATION_ADVISED_BUFSIZE 80
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) void snd_print_channel_allocation(int spk_alloc, char *buf, int buflen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) #define codec_err(codec, fmt, args...) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) dev_err(hda_codec_dev(codec), fmt, ##args)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) #define codec_warn(codec, fmt, args...) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) dev_warn(hda_codec_dev(codec), fmt, ##args)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) #define codec_info(codec, fmt, args...) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) dev_info(hda_codec_dev(codec), fmt, ##args)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) #define codec_dbg(codec, fmt, args...) \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) dev_dbg(hda_codec_dev(codec), fmt, ##args)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) #endif /* __SOUND_HDA_LOCAL_H */