2 * Common codes for Realtek codec quirks
3 * included by patch_realtek.c
7 * configuration template - to be copied to the spec instance
9 struct alc_config_preset {
10 const struct snd_kcontrol_new *mixers[5]; /* should be identical size
13 const struct snd_kcontrol_new *cap_mixer; /* capture mixer */
14 const struct hda_verb *init_verbs[5];
15 unsigned int num_dacs;
16 const hda_nid_t *dac_nids;
17 hda_nid_t dig_out_nid; /* optional */
18 hda_nid_t hp_nid; /* optional */
19 const hda_nid_t *slave_dig_outs;
20 unsigned int num_adc_nids;
21 const hda_nid_t *adc_nids;
22 const hda_nid_t *capsrc_nids;
24 unsigned int num_channel_mode;
25 const struct hda_channel_mode *channel_mode;
27 int const_channel_count;
28 unsigned int num_mux_defs;
29 const struct hda_input_mux *input_mux;
30 void (*unsol_event)(struct hda_codec *, unsigned int);
31 void (*setup)(struct hda_codec *);
32 void (*init_hook)(struct hda_codec *);
33 #ifdef CONFIG_SND_HDA_POWER_SAVE
34 const struct hda_amp_list *loopbacks;
35 void (*power_hook)(struct hda_codec *codec);
40 * channel mode setting
42 static int alc_ch_mode_info(struct snd_kcontrol *kcontrol,
43 struct snd_ctl_elem_info *uinfo)
45 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
46 struct alc_spec *spec = codec->spec;
47 return snd_hda_ch_mode_info(codec, uinfo, spec->channel_mode,
48 spec->num_channel_mode);
51 static int alc_ch_mode_get(struct snd_kcontrol *kcontrol,
52 struct snd_ctl_elem_value *ucontrol)
54 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
55 struct alc_spec *spec = codec->spec;
56 return snd_hda_ch_mode_get(codec, ucontrol, spec->channel_mode,
57 spec->num_channel_mode,
58 spec->ext_channel_count);
61 static int alc_ch_mode_put(struct snd_kcontrol *kcontrol,
62 struct snd_ctl_elem_value *ucontrol)
64 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
65 struct alc_spec *spec = codec->spec;
66 int err = snd_hda_ch_mode_put(codec, ucontrol, spec->channel_mode,
67 spec->num_channel_mode,
68 &spec->ext_channel_count);
69 if (err >= 0 && !spec->const_channel_count) {
70 spec->multiout.max_channels = spec->ext_channel_count;
71 if (spec->need_dac_fix)
72 spec->multiout.num_dacs = spec->multiout.max_channels / 2;
77 static void alc_fixup_autocfg_pin_nums(struct hda_codec *codec)
79 struct alc_spec *spec = codec->spec;
80 struct auto_pin_cfg *cfg = &spec->autocfg;
82 if (!cfg->line_outs) {
83 while (cfg->line_outs < AUTO_CFG_MAX_OUTS &&
84 cfg->line_out_pins[cfg->line_outs])
87 if (!cfg->speaker_outs) {
88 while (cfg->speaker_outs < AUTO_CFG_MAX_OUTS &&
89 cfg->speaker_pins[cfg->speaker_outs])
93 while (cfg->hp_outs < AUTO_CFG_MAX_OUTS &&
94 cfg->hp_pins[cfg->hp_outs])
100 * set up from the preset table
102 static void setup_preset(struct hda_codec *codec,
103 const struct alc_config_preset *preset)
105 struct alc_spec *spec = codec->spec;
108 for (i = 0; i < ARRAY_SIZE(preset->mixers) && preset->mixers[i]; i++)
109 add_mixer(spec, preset->mixers[i]);
110 spec->cap_mixer = preset->cap_mixer;
111 for (i = 0; i < ARRAY_SIZE(preset->init_verbs) && preset->init_verbs[i];
113 add_verb(spec, preset->init_verbs[i]);
115 spec->channel_mode = preset->channel_mode;
116 spec->num_channel_mode = preset->num_channel_mode;
117 spec->need_dac_fix = preset->need_dac_fix;
118 spec->const_channel_count = preset->const_channel_count;
120 if (preset->const_channel_count)
121 spec->multiout.max_channels = preset->const_channel_count;
123 spec->multiout.max_channels = spec->channel_mode[0].channels;
124 spec->ext_channel_count = spec->channel_mode[0].channels;
126 spec->multiout.num_dacs = preset->num_dacs;
127 spec->multiout.dac_nids = preset->dac_nids;
128 spec->multiout.dig_out_nid = preset->dig_out_nid;
129 spec->multiout.slave_dig_outs = preset->slave_dig_outs;
130 spec->multiout.hp_nid = preset->hp_nid;
132 spec->num_mux_defs = preset->num_mux_defs;
133 if (!spec->num_mux_defs)
134 spec->num_mux_defs = 1;
135 spec->input_mux = preset->input_mux;
137 spec->num_adc_nids = preset->num_adc_nids;
138 spec->adc_nids = preset->adc_nids;
139 spec->capsrc_nids = preset->capsrc_nids;
140 spec->dig_in_nid = preset->dig_in_nid;
142 spec->unsol_event = preset->unsol_event;
143 spec->init_hook = preset->init_hook;
144 #ifdef CONFIG_SND_HDA_POWER_SAVE
145 spec->power_hook = preset->power_hook;
146 spec->loopback.amplist = preset->loopbacks;
150 preset->setup(codec);
152 alc_fixup_autocfg_pin_nums(codec);
155 static void alc_simple_setup_automute(struct alc_spec *spec, int mode)
157 int lo_pin = spec->autocfg.line_out_pins[0];
159 if (lo_pin == spec->autocfg.speaker_pins[0] ||
160 lo_pin == spec->autocfg.hp_pins[0])
162 spec->automute_mode = mode;
163 spec->detect_hp = !!spec->autocfg.hp_pins[0];
164 spec->detect_lo = !!lo_pin;
165 spec->automute_lo = spec->automute_lo_possible = !!lo_pin;
166 spec->automute_speaker = spec->automute_speaker_possible = !!spec->autocfg.speaker_pins[0];