]> git.karo-electronics.de Git - mv-sheeva.git/blob - sound/pci/hda/alc_quirks.c
a63a517780d69339ab89b66124f97829da379e34
[mv-sheeva.git] / sound / pci / hda / alc_quirks.c
1 /*
2  * Common codes for Realtek codec quirks
3  * included by patch_realtek.c
4  */
5
6 /*
7  * configuration template - to be copied to the spec instance
8  */
9 struct alc_config_preset {
10         const struct snd_kcontrol_new *mixers[5]; /* should be identical size
11                                              * with spec
12                                              */
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;
23         hda_nid_t dig_in_nid;
24         unsigned int num_channel_mode;
25         const struct hda_channel_mode *channel_mode;
26         int need_dac_fix;
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);
36 #endif
37 };
38
39 /*
40  * channel mode setting
41  */
42 static int alc_ch_mode_info(struct snd_kcontrol *kcontrol,
43                             struct snd_ctl_elem_info *uinfo)
44 {
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);
49 }
50
51 static int alc_ch_mode_get(struct snd_kcontrol *kcontrol,
52                            struct snd_ctl_elem_value *ucontrol)
53 {
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);
59 }
60
61 static int alc_ch_mode_put(struct snd_kcontrol *kcontrol,
62                            struct snd_ctl_elem_value *ucontrol)
63 {
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;
73         }
74         return err;
75 }
76
77 static void alc_fixup_autocfg_pin_nums(struct hda_codec *codec)
78 {
79         struct alc_spec *spec = codec->spec;
80         struct auto_pin_cfg *cfg = &spec->autocfg;
81
82         if (!cfg->line_outs) {
83                 while (cfg->line_outs < AUTO_CFG_MAX_OUTS &&
84                        cfg->line_out_pins[cfg->line_outs])
85                         cfg->line_outs++;
86         }
87         if (!cfg->speaker_outs) {
88                 while (cfg->speaker_outs < AUTO_CFG_MAX_OUTS &&
89                        cfg->speaker_pins[cfg->speaker_outs])
90                         cfg->speaker_outs++;
91         }
92         if (!cfg->hp_outs) {
93                 while (cfg->hp_outs < AUTO_CFG_MAX_OUTS &&
94                        cfg->hp_pins[cfg->hp_outs])
95                         cfg->hp_outs++;
96         }
97 }
98
99 /*
100  * set up from the preset table
101  */
102 static void setup_preset(struct hda_codec *codec,
103                          const struct alc_config_preset *preset)
104 {
105         struct alc_spec *spec = codec->spec;
106         int i;
107
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];
112              i++)
113                 add_verb(spec, preset->init_verbs[i]);
114
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;
119
120         if (preset->const_channel_count)
121                 spec->multiout.max_channels = preset->const_channel_count;
122         else
123                 spec->multiout.max_channels = spec->channel_mode[0].channels;
124         spec->ext_channel_count = spec->channel_mode[0].channels;
125
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;
131
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;
136
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;
141
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;
147 #endif
148
149         if (preset->setup)
150                 preset->setup(codec);
151
152         alc_fixup_autocfg_pin_nums(codec);
153 }
154
155 static void alc_simple_setup_automute(struct alc_spec *spec, int mode)
156 {
157         int lo_pin = spec->autocfg.line_out_pins[0];
158
159         if (lo_pin == spec->autocfg.speaker_pins[0] ||
160                 lo_pin == spec->autocfg.hp_pins[0])
161                 lo_pin = 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];
167 }