27 #include <linux/slab.h>
28 #include <linux/pci.h>
29 #include <linux/module.h>
45 static bool enable_loopback;
50 #ifdef CONFIG_SND_AC97_POWER_SAVE
51 static int power_save = CONFIG_SND_AC97_POWER_SAVE_DEFAULT;
54 "(in second, 0 = disable).");
69 static const struct ac97_codec_id snd_ac97_codec_id_vendors[] = {
70 { 0x41445300, 0xffffff00,
"Analog Devices",
NULL,
NULL },
71 { 0x414b4d00, 0xffffff00,
"Asahi Kasei",
NULL,
NULL },
72 { 0x414c4300, 0xffffff00,
"Realtek",
NULL,
NULL },
73 { 0x414c4700, 0xffffff00,
"Realtek",
NULL,
NULL },
79 { 0x415a5400, 0xffffff00,
"Aztech Labs (emulated)",
NULL,
NULL },
80 { 0x434d4900, 0xffffff00,
"C-Media Electronics",
NULL,
NULL },
81 { 0x43525900, 0xffffff00,
"Cirrus Logic",
NULL,
NULL },
82 { 0x43585400, 0xffffff00,
"Conexant",
NULL,
NULL },
83 { 0x44543000, 0xffffff00,
"Diamond Technology",
NULL,
NULL },
84 { 0x454d4300, 0xffffff00,
"eMicro",
NULL,
NULL },
85 { 0x45838300, 0xffffff00,
"ESS Technology",
NULL,
NULL },
86 { 0x48525300, 0xffffff00,
"Intersil",
NULL,
NULL },
87 { 0x49434500, 0xffffff00,
"ICEnsemble",
NULL,
NULL },
88 { 0x49544500, 0xffffff00,
"ITE Tech.Inc",
NULL,
NULL },
89 { 0x4e534300, 0xffffff00,
"National Semiconductor",
NULL,
NULL },
90 { 0x50534300, 0xffffff00,
"Philips",
NULL,
NULL },
91 { 0x53494c00, 0xffffff00,
"Silicon Laboratory",
NULL,
NULL },
92 { 0x53544d00, 0xffffff00,
"STMicroelectronics",
NULL,
NULL },
93 { 0x54524100, 0xffffff00,
"TriTech",
NULL,
NULL },
94 { 0x54584e00, 0xffffff00,
"Texas Instruments",
NULL,
NULL },
95 { 0x56494100, 0xffffff00,
"VIA Technologies",
NULL,
NULL },
96 { 0x57454300, 0xffffff00,
"Winbond",
NULL,
NULL },
97 { 0x574d4c00, 0xffffff00,
"Wolfson",
NULL,
NULL },
98 { 0x594d4800, 0xffffff00,
"Yamaha",
NULL,
NULL },
99 { 0x83847600, 0xffffff00,
"SigmaTel",
NULL,
NULL },
104 { 0x41445303, 0xffffffff,
"AD1819", patch_ad1819,
NULL },
105 { 0x41445340, 0xffffffff,
"AD1881", patch_ad1881,
NULL },
106 { 0x41445348, 0xffffffff,
"AD1881A", patch_ad1881,
NULL },
107 { 0x41445360, 0xffffffff,
"AD1885", patch_ad1885,
NULL },
108 { 0x41445361, 0xffffffff,
"AD1886", patch_ad1886,
NULL },
109 { 0x41445362, 0xffffffff,
"AD1887", patch_ad1881,
NULL },
110 { 0x41445363, 0xffffffff,
"AD1886A", patch_ad1881,
NULL },
111 { 0x41445368, 0xffffffff,
"AD1888", patch_ad1888,
NULL },
112 { 0x41445370, 0xffffffff,
"AD1980", patch_ad1980,
NULL },
113 { 0x41445372, 0xffffffff,
"AD1981A", patch_ad1981a,
NULL },
114 { 0x41445374, 0xffffffff,
"AD1981B", patch_ad1981b,
NULL },
115 { 0x41445375, 0xffffffff,
"AD1985", patch_ad1985,
NULL },
116 { 0x41445378, 0xffffffff,
"AD1986", patch_ad1986,
NULL },
117 { 0x414b4d00, 0xffffffff,
"AK4540",
NULL,
NULL },
118 { 0x414b4d01, 0xffffffff,
"AK4542",
NULL,
NULL },
119 { 0x414b4d02, 0xffffffff,
"AK4543",
NULL,
NULL },
120 { 0x414b4d06, 0xffffffff,
"AK4544A",
NULL,
NULL },
121 { 0x414b4d07, 0xffffffff,
"AK4545",
NULL,
NULL },
122 { 0x414c4300, 0xffffff00,
"ALC100,100P",
NULL,
NULL },
123 { 0x414c4710, 0xfffffff0,
"ALC200,200P",
NULL,
NULL },
124 { 0x414c4721, 0xffffffff,
"ALC650D",
NULL,
NULL },
125 { 0x414c4722, 0xffffffff,
"ALC650E",
NULL,
NULL },
126 { 0x414c4723, 0xffffffff,
"ALC650F",
NULL,
NULL },
127 { 0x414c4720, 0xfffffff0,
"ALC650", patch_alc650,
NULL },
128 { 0x414c4730, 0xffffffff,
"ALC101",
NULL,
NULL },
129 { 0x414c4740, 0xfffffff0,
"ALC202",
NULL,
NULL },
130 { 0x414c4750, 0xfffffff0,
"ALC250",
NULL,
NULL },
131 { 0x414c4760, 0xfffffff0,
"ALC655", patch_alc655,
NULL },
132 { 0x414c4770, 0xfffffff0,
"ALC203", patch_alc203,
NULL },
133 { 0x414c4781, 0xffffffff,
"ALC658D",
NULL,
NULL },
134 { 0x414c4780, 0xfffffff0,
"ALC658", patch_alc655,
NULL },
135 { 0x414c4790, 0xfffffff0,
"ALC850", patch_alc850,
NULL },
136 { 0x415a5401, 0xffffffff,
"AZF3328", patch_aztech_azf3328,
NULL },
137 { 0x434d4941, 0xffffffff,
"CMI9738", patch_cm9738,
NULL },
138 { 0x434d4961, 0xffffffff,
"CMI9739", patch_cm9739,
NULL },
139 { 0x434d4969, 0xffffffff,
"CMI9780", patch_cm9780,
NULL },
140 { 0x434d4978, 0xffffffff,
"CMI9761A", patch_cm9761,
NULL },
141 { 0x434d4982, 0xffffffff,
"CMI9761B", patch_cm9761,
NULL },
142 { 0x434d4983, 0xffffffff,
"CMI9761A+", patch_cm9761,
NULL },
143 { 0x43525900, 0xfffffff8,
"CS4297",
NULL,
NULL },
144 { 0x43525910, 0xfffffff8,
"CS4297A", patch_cirrus_spdif,
NULL },
145 { 0x43525920, 0xfffffff8,
"CS4298", patch_cirrus_spdif,
NULL },
146 { 0x43525928, 0xfffffff8,
"CS4294",
NULL,
NULL },
147 { 0x43525930, 0xfffffff8,
"CS4299", patch_cirrus_cs4299,
NULL },
148 { 0x43525948, 0xfffffff8,
"CS4201",
NULL,
NULL },
149 { 0x43525958, 0xfffffff8,
"CS4205", patch_cirrus_spdif,
NULL },
150 { 0x43525960, 0xfffffff8,
"CS4291",
NULL,
NULL },
151 { 0x43525970, 0xfffffff8,
"CS4202",
NULL,
NULL },
152 { 0x43585421, 0xffffffff,
"HSD11246",
NULL,
NULL },
153 { 0x43585428, 0xfffffff8,
"Cx20468", patch_conexant,
NULL },
154 { 0x43585430, 0xffffffff,
"Cx20468-31", patch_conexant,
NULL },
155 { 0x43585431, 0xffffffff,
"Cx20551", patch_cx20551,
NULL },
156 { 0x44543031, 0xfffffff0,
"DT0398",
NULL,
NULL },
157 { 0x454d4328, 0xffffffff,
"EM28028",
NULL,
NULL },
158 { 0x45838308, 0xffffffff,
"ESS1988",
NULL,
NULL },
159 { 0x48525300, 0xffffff00,
"HMP9701",
NULL,
NULL },
160 { 0x49434501, 0xffffffff,
"ICE1230",
NULL,
NULL },
161 { 0x49434511, 0xffffffff,
"ICE1232",
NULL,
NULL },
162 { 0x49434514, 0xffffffff,
"ICE1232A",
NULL,
NULL },
163 { 0x49434551, 0xffffffff,
"VT1616", patch_vt1616,
NULL },
164 { 0x49434552, 0xffffffff,
"VT1616i", patch_vt1616,
NULL },
165 { 0x49544520, 0xffffffff,
"IT2226E",
NULL,
NULL },
166 { 0x49544561, 0xffffffff,
"IT2646E", patch_it2646,
NULL },
167 { 0x4e534300, 0xffffffff,
"LM4540,43,45,46,48",
NULL,
NULL },
168 { 0x4e534331, 0xffffffff,
"LM4549",
NULL,
NULL },
169 { 0x4e534350, 0xffffffff,
"LM4550", patch_lm4550,
NULL },
170 { 0x50534304, 0xffffffff,
"UCB1400", patch_ucb1400,
NULL },
171 { 0x53494c20, 0xffffffe0,
"Si3036,8", mpatch_si3036, mpatch_si3036,
AC97_MODEM_PATCH },
172 { 0x53544d02, 0xffffffff,
"ST7597",
NULL,
NULL },
173 { 0x54524102, 0xffffffff,
"TR28022",
NULL,
NULL },
174 { 0x54524103, 0xffffffff,
"TR28023",
NULL,
NULL },
175 { 0x54524106, 0xffffffff,
"TR28026",
NULL,
NULL },
176 { 0x54524108, 0xffffffff,
"TR28028", patch_tritech_tr28028,
NULL },
177 { 0x54524123, 0xffffffff,
"TR28602",
NULL,
NULL },
178 { 0x54584e20, 0xffffffff,
"TLC320AD9xC",
NULL,
NULL },
179 { 0x56494161, 0xffffffff,
"VIA1612A",
NULL,
NULL },
180 { 0x56494170, 0xffffffff,
"VIA1617A", patch_vt1617a,
NULL },
181 { 0x56494182, 0xffffffff,
"VIA1618", patch_vt1618,
NULL },
182 { 0x57454301, 0xffffffff,
"W83971D",
NULL,
NULL },
183 { 0x574d4c00, 0xffffffff,
"WM9701,WM9701A",
NULL,
NULL },
184 { 0x574d4C03, 0xffffffff,
"WM9703,WM9707,WM9708,WM9717", patch_wolfson03,
NULL},
185 { 0x574d4C04, 0xffffffff,
"WM9704M,WM9704Q", patch_wolfson04,
NULL},
186 { 0x574d4C05, 0xffffffff,
"WM9705,WM9710", patch_wolfson05,
NULL},
187 { 0x574d4C09, 0xffffffff,
"WM9709",
NULL,
NULL},
188 { 0x574d4C12, 0xffffffff,
"WM9711,WM9712,WM9715", patch_wolfson11,
NULL},
190 { 0x594d4800, 0xffffffff,
"YMF743", patch_yamaha_ymf743,
NULL },
191 { 0x594d4802, 0xffffffff,
"YMF752",
NULL,
NULL },
192 { 0x594d4803, 0xffffffff,
"YMF753", patch_yamaha_ymf753,
NULL },
193 { 0x83847600, 0xffffffff,
"STAC9700,83,84", patch_sigmatel_stac9700,
NULL },
194 { 0x83847604, 0xffffffff,
"STAC9701,3,4,5",
NULL,
NULL },
195 { 0x83847605, 0xffffffff,
"STAC9704",
NULL,
NULL },
196 { 0x83847608, 0xffffffff,
"STAC9708,11", patch_sigmatel_stac9708,
NULL },
197 { 0x83847609, 0xffffffff,
"STAC9721,23", patch_sigmatel_stac9721,
NULL },
198 { 0x83847644, 0xffffffff,
"STAC9744", patch_sigmatel_stac9744,
NULL },
199 { 0x83847650, 0xffffffff,
"STAC9750,51",
NULL,
NULL },
200 { 0x83847652, 0xffffffff,
"STAC9752,53",
NULL,
NULL },
201 { 0x83847656, 0xffffffff,
"STAC9756,57", patch_sigmatel_stac9756,
NULL },
202 { 0x83847658, 0xffffffff,
"STAC9758,59", patch_sigmatel_stac9758,
NULL },
203 { 0x83847666, 0xffffffff,
"STAC9766,67",
NULL,
NULL },
208 static void update_power_regs(
struct snd_ac97 *ac97);
209 #ifdef CONFIG_SND_AC97_POWER_SAVE
210 #define ac97_is_power_save_mode(ac97) \
211 ((ac97->scaps & AC97_SCAP_POWER_SAVE) && power_save)
213 #define ac97_is_power_save_mode(ac97) 0
221 static int snd_ac97_valid_reg(
struct snd_ac97 *ac97,
unsigned short reg)
230 if (reg == 0x22 || reg == 0x7a)
241 if (reg >= 0x3a && reg <= 0x6e)
250 if (reg >= 0x3c && reg <= 0x6e)
281 if (!snd_ac97_valid_reg(ac97, reg))
288 ac97->
bus->ops->write(ac97, reg, value);
306 if (!snd_ac97_valid_reg(ac97, reg))
308 return ac97->
bus->ops->read(ac97, reg);
312 static inline unsigned short snd_ac97_read_cache(
struct snd_ac97 *ac97,
unsigned short reg)
314 if (!
test_bit(reg, ac97->reg_accessed)) {
315 ac97->
regs[
reg] = ac97->
bus->ops->read(ac97, reg);
335 if (!snd_ac97_valid_reg(ac97, reg))
339 ac97->
bus->ops->write(ac97, reg, value);
340 set_bit(reg, ac97->reg_accessed);
362 if (!snd_ac97_valid_reg(ac97, reg))
368 ac97->
bus->ops->write(ac97, reg, value);
370 set_bit(reg, ac97->reg_accessed);
394 if (!snd_ac97_valid_reg(ac97, reg))
406 unsigned short mask,
unsigned short value)
409 unsigned short old,
new;
411 old = snd_ac97_read_cache(ac97, reg);
412 new = (old & ~mask) | (value & mask);
416 ac97->
bus->ops->write(ac97, reg,
new);
418 set_bit(reg, ac97->reg_accessed);
422 static int snd_ac97_ad18xx_update_pcm_bits(
struct snd_ac97 *ac97,
int codec,
unsigned short mask,
unsigned short value)
425 unsigned short old,
new,
cfg;
429 new = (old & ~mask) | (value & mask);
454 static int snd_ac97_info_enum_double(
struct snd_kcontrol *kcontrol,
469 static int snd_ac97_get_enum_double(
struct snd_kcontrol *kcontrol,
478 val = snd_ac97_read_cache(ac97, e->
reg);
486 static int snd_ac97_put_enum_double(
struct snd_kcontrol *kcontrol,
496 if (ucontrol->
value.enumerated.item[0] > e->
mask - 1)
501 if (ucontrol->
value.enumerated.item[1] > e->
mask - 1)
503 val |= ucontrol->
value.enumerated.item[1] << e->
shift_r;
515 (reg >= 0x60 && reg < 0x70)) {
524 static void snd_ac97_page_restore(
struct snd_ac97 *ac97,
int page_save)
526 if (page_save >= 0) {
533 static int snd_ac97_info_volsw(
struct snd_kcontrol *kcontrol,
541 uinfo->
count = shift == rshift ? 1 : 2;
547 static int snd_ac97_get_volsw(
struct snd_kcontrol *kcontrol,
558 page_save = snd_ac97_page_save(ac97, reg, kcontrol);
559 ucontrol->
value.integer.value[0] = (snd_ac97_read_cache(ac97, reg) >> shift) & mask;
561 ucontrol->
value.integer.value[1] = (snd_ac97_read_cache(ac97, reg) >> rshift) & mask;
563 ucontrol->
value.integer.value[0] = mask - ucontrol->
value.integer.value[0];
565 ucontrol->
value.integer.value[1] = mask - ucontrol->
value.integer.value[1];
567 snd_ac97_page_restore(ac97, page_save);
571 static int snd_ac97_put_volsw(
struct snd_kcontrol *kcontrol,
581 unsigned short val, val2, val_mask;
583 page_save = snd_ac97_page_save(ac97, reg, kcontrol);
584 val = (ucontrol->
value.integer.value[0] &
mask);
587 val_mask = mask << shift;
589 if (shift != rshift) {
590 val2 = (ucontrol->
value.integer.value[1] &
mask);
593 val_mask |= mask << rshift;
594 val |= val2 << rshift;
597 snd_ac97_page_restore(ac97, page_save);
598 #ifdef CONFIG_SND_AC97_POWER_SAVE
602 if (val & AC97_PD_EAPD)
603 ac97->power_up &= ~(1 << (reg>>1));
605 ac97->power_up |= 1 << (reg>>1);
606 update_power_regs(ac97);
631 static const char* std_rec_sel[] = {
"Mic",
"CD",
"Video",
"Aux",
"Line",
"Mix",
"Mix Mono",
"Phone"};
632 static const char* std_3d_path[] = {
"pre 3D",
"post 3D"};
633 static const char* std_mix[] = {
"Mix",
"Mic"};
634 static const char* std_mic[] = {
"Mic1",
"Mic2"};
636 static const struct ac97_enum std_enum[] = {
644 AC97_ENUM(
"Capture Source", std_enum[0]);
665 AC97_ENUM(
"PCM Out Path & Mute", std_enum[1]),
669 AC97_ENUM(
"Mono Output Select", std_enum[2]),
692 static const struct snd_kcontrol_new snd_ac97_controls_modem_switches[2] = {
750 unsigned int new = 0;
751 unsigned short val = 0;
761 default: val |= 1<<12;
break;
773 val |= ((
new >> 8) & 0xff) << 4;
774 switch ((
new >> 24) & 0xff) {
778 default: val |= 1<<12;
break;
787 int x = (val >> 12) & 0x03;
789 case 0: x = 1;
break;
790 case 2: x = 0;
break;
791 default: x = 0;
break;
805 ((val << 4) & 0xff00) |
806 ((val << 2) & 0x0038));
828 unsigned short value, old,
new;
831 value = (ucontrol->
value.integer.value[0] &
mask);
836 old = snd_ac97_read_cache(ac97, reg);
837 new = (old & ~mask) | value;
856 .info = snd_ac97_spdif_mask_info,
857 .get = snd_ac97_spdif_cmask_get,
863 .info = snd_ac97_spdif_mask_info,
864 .get = snd_ac97_spdif_pmask_get,
869 .info = snd_ac97_spdif_mask_info,
870 .get = snd_ac97_spdif_default_get,
871 .put = snd_ac97_spdif_default_put,
878 .info = snd_ac97_info_volsw,
879 .get = snd_ac97_get_volsw,
880 .put = snd_ac97_put_spsa,
885 #define AD18XX_PCM_BITS(xname, codec, lshift, rshift, mask) \
886 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .info = snd_ac97_ad18xx_pcm_info_bits, \
887 .get = snd_ac97_ad18xx_pcm_get_bits, .put = snd_ac97_ad18xx_pcm_put_bits, \
888 .private_value = (codec) | ((lshift) << 8) | ((rshift) << 12) | ((mask) << 16) }
928 unsigned short val, valmask;
930 val = (mask - (ucontrol->
value.integer.value[0] &
mask)) << lshift;
931 valmask = mask << lshift;
933 val |= (mask - (ucontrol->
value.integer.value[1] &
mask)) << rshift;
934 valmask |= mask << rshift;
936 return snd_ac97_ad18xx_update_pcm_bits(ac97, codec, valmask, val);
939 #define AD18XX_PCM_VOLUME(xname, codec) \
940 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .info = snd_ac97_ad18xx_pcm_info_volume, \
941 .get = snd_ac97_ad18xx_pcm_get_volume, .put = snd_ac97_ad18xx_pcm_put_volume, \
942 .private_value = codec }
969 unsigned short val1, val2;
971 val1 = 31 - (ucontrol->
value.integer.value[0] & 31);
972 val2 = 31 - (ucontrol->
value.integer.value[1] & 31);
973 return snd_ac97_ad18xx_update_pcm_bits(ac97, codec, 0x1f1f, (val1 << 8) | val2);
981 static const struct snd_kcontrol_new snd_ac97_controls_ad18xx_surround[2] = {
1000 static void snd_ac97_powerdown(
struct snd_ac97 *ac97);
1017 return snd_ac97_bus_free(bus);
1020 static int snd_ac97_free(
struct snd_ac97 *ac97)
1023 #ifdef CONFIG_SND_AC97_POWER_SAVE
1039 snd_ac97_powerdown(ac97);
1040 return snd_ac97_free(ac97);
1043 static int snd_ac97_try_volume_mix(
struct snd_ac97 * ac97,
int reg)
1047 if (! snd_ac97_valid_reg(ac97, reg))
1081 if (!(val & mask)) {
1093 static void check_volume_resolution(
struct snd_ac97 *ac97,
int reg,
unsigned char *lo_max,
unsigned char *hi_max)
1095 unsigned short cbit[3] = { 0x20, 0x10, 0x01 };
1096 unsigned char max[3] = { 63, 31, 15 };
1103 if (tbl->
reg == reg) {
1104 *lo_max = tbl->
bits & 0xff;
1105 *hi_max = (tbl->
bits >> 8) & 0xff;
1111 *lo_max = *hi_max = 0;
1124 if (! *lo_max && (val & 0x7f) == cbit[i])
1126 if (! *hi_max && ((val >> 8) & 0x7f) == cbit[i])
1128 if (*lo_max && *hi_max)
1133 static int snd_ac97_try_bit(
struct snd_ac97 * ac97,
int reg,
int bit)
1147 static void snd_ac97_change_volume_params2(
struct snd_ac97 * ac97,
int reg,
int shift,
unsigned char *max)
1149 unsigned short val, val1;
1162 static inline int printable(
unsigned int x)
1165 if (x < ' ' || x >= 0x71) {
1167 return x - 0x71 +
'A';
1177 memcpy(&
template, _template,
sizeof(
template));
1178 template.index = ac97->
num;
1185 static int snd_ac97_cmute_new_stereo(
struct snd_card *
card,
char *
name,
int reg,
1186 int check_stereo,
int check_amix,
1191 unsigned short val, val1, mute_mask;
1193 if (! snd_ac97_valid_reg(ac97, reg))
1235 static const unsigned int *find_db_scale(
unsigned int maxval)
1238 case 0x0f:
return db_scale_4bit;
1239 case 0x1f:
return db_scale_5bit;
1240 case 0x3f:
return db_scale_6bit;
1245 static void set_tlv_db_scale(
struct snd_kcontrol *kctl,
const unsigned int *
tlv)
1255 static int snd_ac97_cvol_new(
struct snd_card *card,
char *name,
int reg,
unsigned int lo_max,
1256 unsigned int hi_max,
struct snd_ac97 *ac97)
1261 if (! snd_ac97_valid_reg(ac97, reg))
1277 set_tlv_db_scale(kctl, db_scale_5bit_12db_max);
1279 set_tlv_db_scale(kctl, find_db_scale(lo_max));
1286 | lo_max | (hi_max << 8)
1294 static int snd_ac97_cmix_new_stereo(
struct snd_card *card,
const char *pfx,
1295 int reg,
int check_stereo,
int check_amix,
1300 unsigned char lo_max, hi_max;
1302 if (! snd_ac97_valid_reg(ac97, reg))
1305 if (snd_ac97_try_bit(ac97, reg, 15)) {
1306 sprintf(name,
"%s Switch", pfx);
1307 if ((err = snd_ac97_cmute_new_stereo(card, name, reg,
1308 check_stereo, check_amix,
1312 check_volume_resolution(ac97, reg, &lo_max, &hi_max);
1314 sprintf(name,
"%s Volume", pfx);
1315 if ((err = snd_ac97_cvol_new(card, name, reg, lo_max, hi_max, ac97)) < 0)
1321 #define snd_ac97_cmix_new(card, pfx, reg, acheck, ac97) \
1322 snd_ac97_cmix_new_stereo(card, pfx, reg, 0, acheck, ac97)
1323 #define snd_ac97_cmute_new(card, name, reg, acheck, ac97) \
1324 snd_ac97_cmute_new_stereo(card, name, reg, 0, acheck, ac97)
1326 static unsigned int snd_ac97_determine_spdif_rates(
struct snd_ac97 *ac97);
1328 static int snd_ac97_mixer_build(
struct snd_ac97 * ac97)
1354 if ((err =
snd_ctl_add(card, snd_ac97_cnew(&snd_ac97_controls_center[0], ac97))) < 0)
1356 if ((err =
snd_ctl_add(card, kctl = snd_ac97_cnew(&snd_ac97_controls_center[1], ac97))) < 0)
1361 set_tlv_db_scale(kctl, find_db_scale(max));
1368 if ((err =
snd_ctl_add(card, snd_ac97_cnew(&snd_ac97_controls_lfe[0], ac97))) < 0)
1370 if ((err =
snd_ctl_add(card, kctl = snd_ac97_cnew(&snd_ac97_controls_lfe[1], ac97))) < 0)
1375 set_tlv_db_scale(kctl, find_db_scale(max));
1383 if ((err = snd_ac97_cmix_new_stereo(card,
"Surround Playback",
1406 for (idx = 0; idx < 2; idx++) {
1407 if ((err =
snd_ctl_add(card, kctl = snd_ac97_cnew(&snd_ac97_controls_tone[idx], ac97))) < 0)
1423 for (idx = 0; idx < 2; idx++)
1424 if ((err =
snd_ctl_add(card, kctl = snd_ac97_cnew(&snd_ac97_controls_pc_beep[idx], ac97))) < 0)
1426 set_tlv_db_scale(kctl, db_scale_4bit);
1437 if (snd_ac97_try_volume_mix(ac97,
AC97_PHONE)) {
1446 if (snd_ac97_try_volume_mix(ac97,
AC97_MIC)) {
1450 if ((err =
snd_ctl_add(card, snd_ac97_cnew(&snd_ac97_controls_mic_boost, ac97))) < 0)
1456 if (snd_ac97_try_volume_mix(ac97,
AC97_LINE)) {
1464 if (snd_ac97_try_volume_mix(ac97,
AC97_CD)) {
1473 if (snd_ac97_try_volume_mix(ac97,
AC97_VIDEO)) {
1482 if (snd_ac97_try_volume_mix(ac97,
AC97_AUX)) {
1491 unsigned short init_val;
1496 for (idx = 0; idx < 2; idx++)
1497 if ((err =
snd_ctl_add(card, kctl = snd_ac97_cnew(&snd_ac97_controls_ad18xx_pcm[idx], ac97))) < 0)
1499 set_tlv_db_scale(kctl, db_scale_5bit);
1502 for (idx = 0; idx < 2; idx++)
1503 if ((err =
snd_ctl_add(card, kctl = snd_ac97_cnew(&snd_ac97_controls_ad18xx_surround[idx], ac97))) < 0)
1505 set_tlv_db_scale(kctl, db_scale_5bit);
1509 for (idx = 0; idx < 2; idx++)
1510 if ((err =
snd_ctl_add(card, kctl = snd_ac97_cnew(&snd_ac97_controls_ad18xx_center[idx], ac97))) < 0)
1512 set_tlv_db_scale(kctl, db_scale_5bit);
1513 for (idx = 0; idx < 2; idx++)
1514 if ((err =
snd_ctl_add(card, kctl = snd_ac97_cnew(&snd_ac97_controls_ad18xx_lfe[idx], ac97))) < 0)
1516 set_tlv_db_scale(kctl, db_scale_5bit);
1524 "PCM Playback Switch",
1536 if ((err =
snd_ctl_add(card, snd_ac97_cnew(&snd_ac97_control_capture_src, ac97))) < 0)
1544 if ((err =
snd_ctl_add(card, kctl = snd_ac97_cnew(&snd_ac97_control_capture_vol, ac97))) < 0)
1546 set_tlv_db_scale(kctl, db_scale_rec_gain);
1552 for (idx = 0; idx < 2; idx++)
1553 if ((err =
snd_ctl_add(card, kctl = snd_ac97_cnew(&snd_ac97_controls_mic_capture[idx], ac97))) < 0)
1555 set_tlv_db_scale(kctl, db_scale_rec_gain);
1612 val = val == 0x0606;
1613 if ((err =
snd_ctl_add(card, kctl = snd_ac97_cnew(&snd_ac97_controls_3d[0], ac97))) < 0)
1617 if ((err =
snd_ctl_add(card, kctl = snd_ac97_cnew(&snd_ac97_controls_3d[1], ac97))) < 0)
1634 if ((err = ac97->
build_ops->build_spdif(ac97)) < 0)
1637 for (idx = 0; idx < 5; idx++)
1638 if ((err =
snd_ctl_add(card, snd_ac97_cnew(&snd_ac97_controls_spdif[idx], ac97))) < 0)
1640 if (ac97->
build_ops->build_post_spdif) {
1641 if ((err = ac97->
build_ops->build_post_spdif(ac97)) < 0)
1654 if ((err = ac97->
build_ops->build_specific(ac97)) < 0)
1658 kctl = snd_ac97_cnew(&snd_ac97_control_eapd, ac97);
1662 set_inv_eapd(ac97, kctl);
1670 static int snd_ac97_modem_build(
struct snd_card *card,
struct snd_ac97 * ac97)
1685 for (idx = 0; idx <
ARRAY_SIZE(snd_ac97_controls_modem_switches); idx++)
1691 if ((err = ac97->
build_ops->build_specific(ac97)) < 0)
1697 static int snd_ac97_test_rate(
struct snd_ac97 *ac97,
int reg,
int shadow_reg,
int rate)
1702 tmp = ((
unsigned int)rate * ac97->
bus->clock) / 48000;
1707 return val == (tmp & 0xffff);
1710 static void snd_ac97_determine_rates(
struct snd_ac97 *ac97,
int reg,
int shadow_reg,
unsigned int *r_result)
1713 unsigned short saved;
1715 if (ac97->
bus->no_vra) {
1728 if (snd_ac97_test_rate(ac97, reg, shadow_reg, 11000))
1731 if (snd_ac97_test_rate(ac97, reg, shadow_reg, 8000))
1733 if (snd_ac97_test_rate(ac97, reg, shadow_reg, 11025))
1735 if (snd_ac97_test_rate(ac97, reg, shadow_reg, 16000))
1737 if (snd_ac97_test_rate(ac97, reg, shadow_reg, 22050))
1739 if (snd_ac97_test_rate(ac97, reg, shadow_reg, 32000))
1741 if (snd_ac97_test_rate(ac97, reg, shadow_reg, 44100))
1743 if (snd_ac97_test_rate(ac97, reg, shadow_reg, 48000))
1750 if (snd_ac97_test_rate(ac97, reg, shadow_reg, 64000 / 2))
1752 if (snd_ac97_test_rate(ac97, reg, shadow_reg, 88200 / 2))
1754 if (snd_ac97_test_rate(ac97, reg, shadow_reg, 96000 / 2))
1757 if (!snd_ac97_test_rate(ac97, reg, shadow_reg, 76100 / 2))
1770 static unsigned int snd_ac97_determine_spdif_rates(
struct snd_ac97 *ac97)
1772 unsigned int result = 0;
1774 static unsigned short ctl_bits[] = {
1777 static unsigned int rate_bits[] = {
1784 result |= rate_bits[
i];
1795 for (pid = table; pid->
id; pid++)
1796 if (pid->
id == (
id & pid->
mask))
1805 sprintf(name,
"0x%x %c%c%c",
id,
1806 printable(
id >> 24),
1807 printable(
id >> 16),
1808 printable(
id >> 8));
1809 pid = look_for_codec_id(snd_ac97_codec_id_vendors,
id);
1814 if (ac97 && pid->
patch) {
1820 pid = look_for_codec_id(snd_ac97_codec_ids,
id);
1824 if (pid->
mask != 0xffffffff)
1826 if (ac97 && pid->
patch) {
1845 for (pid = snd_ac97_codec_ids; pid->
id; pid++)
1846 if (pid->
id == (ac97->
id & pid->
mask))
1848 return "unknown codec";
1856 static int ac97_reset_wait(
struct snd_ac97 *ac97,
int timeout,
int with_modem)
1858 unsigned long end_time;
1871 if (val != 0xffff && (val & 1) != 0)
1877 if (val != 0 && val != 0xffff)
1937 snd_ac97_bus_free(bus);
1948 static void ac97_device_release(
struct device *
dev)
1959 ac97->
dev.parent = ac97->
bus->card->dev;
1960 ac97->
dev.release = ac97_device_release;
1962 ac97->
bus->card->number, ac97->
num,
1973 static int snd_ac97_dev_disconnect(
struct snd_device *device)
1984 #ifdef CONFIG_SND_AC97_POWER_SAVE
2017 unsigned long end_time;
2021 .dev_free = snd_ac97_dev_free,
2022 .dev_register = snd_ac97_dev_register,
2023 .dev_disconnect = snd_ac97_dev_disconnect,
2042 ac97->
pci =
template->pci;
2043 ac97->
num =
template->num;
2044 ac97->
addr =
template->addr;
2045 ac97->
scaps =
template->scaps;
2050 #ifdef CONFIG_SND_AC97_POWER_SAVE
2060 if (bus->
ops->reset) {
2061 bus->
ops->reset(ac97);
2067 if (ac97->
id && ac97->
id != (
unsigned int)-1) {
2068 pid = look_for_codec_id(snd_ac97_codec_ids, ac97->
id);
2079 bus->
ops->wait(ac97);
2087 err = ac97_reset_wait(ac97,
2099 (ac97->
id == 0x00000000 || ac97->
id == 0xffffffff)) {
2101 snd_ac97_free(ac97);
2104 pid = look_for_codec_id(snd_ac97_codec_ids, ac97->
id);
2118 if (ac97->
ext_id == 0xffff)
2131 if (!ac97_is_audio(ac97) && !ac97_is_modem(ac97)) {
2134 snd_ac97_free(ac97);
2138 if (bus->
ops->reset)
2142 if (ac97_is_audio(ac97)) {
2162 if (ac97_is_modem(ac97)) {
2194 if (ac97_is_audio(ac97))
2198 if (ac97->
ext_id & 0x01c9) {
2200 reg |= ac97->
ext_id & 0x01c0;
2202 reg |= ac97->
ext_id & 0x0009;
2242 bus->
ops->init(ac97);
2248 if (ac97_is_audio(ac97)) {
2260 snd_ac97_free(ac97);
2263 if (snd_ac97_mixer_build(ac97) < 0) {
2264 snd_ac97_free(ac97);
2268 if (ac97_is_modem(ac97)) {
2280 snd_ac97_free(ac97);
2283 if (snd_ac97_modem_build(card, ac97) < 0) {
2284 snd_ac97_free(ac97);
2288 if (ac97_is_audio(ac97))
2289 update_power_regs(ac97);
2292 snd_ac97_free(ac97);
2307 static void snd_ac97_powerdown(
struct snd_ac97 *ac97)
2309 unsigned short power;
2311 if (ac97_is_audio(ac97)) {
2368 #ifdef CONFIG_SND_AC97_POWER_SAVE
2377 int snd_ac97_update_power(
struct snd_ac97 *ac97,
int reg,
int powerup)
2389 if (power_regs[i].reg == reg) {
2391 ac97->power_up |= (1 <<
i);
2393 ac97->power_up &= ~(1 <<
i);
2408 update_power_regs(ac97);
2417 static void update_power_regs(
struct snd_ac97 *ac97)
2419 unsigned int power_up,
bits;
2428 #ifdef CONFIG_SND_AC97_POWER_SAVE
2430 power_up = ac97->power_up;
2443 if (power_up & (1 << i))
2446 bits = power_regs[
i].
mask;
2448 power_regs[i].mask, bits);
2454 AC97_PD_PR2, AC97_PD_PR2);
2469 void snd_ac97_suspend(
struct snd_ac97 *ac97)
2475 #ifdef CONFIG_SND_AC97_POWER_SAVE
2478 snd_ac97_powerdown(ac97);
2486 static void snd_ac97_restore_status(
struct snd_ac97 *ac97)
2490 for (i = 2; i < 0x7c ; i += 2) {
2497 if (
test_bit(i, ac97->reg_accessed)) {
2507 static void snd_ac97_restore_iec958(
struct snd_ac97 *ac97)
2530 void snd_ac97_resume(
struct snd_ac97 *ac97)
2532 unsigned long end_time;
2537 if (ac97->
bus->ops->reset) {
2538 ac97->
bus->ops->reset(ac97);
2554 if (ac97_is_audio(ac97)) {
2570 if (val != 0xffff && (val & 1) != 0)
2577 if (ac97->
bus->ops->init)
2578 ac97->
bus->ops->init(ac97);
2583 snd_ac97_restore_status(ac97);
2584 snd_ac97_restore_iec958(ac97);
2595 static void set_ctl_name(
char *
dst,
const char *
src,
const char *suffix)
2598 sprintf(dst,
"%s %s", src, suffix);
2604 static int snd_ac97_remove_ctl(
struct snd_ac97 *ac97,
const char *name,
2608 memset(&
id, 0,
sizeof(
id));
2609 set_ctl_name(
id.name, name, suffix);
2614 static struct snd_kcontrol *ctl_find(
struct snd_ac97 *ac97,
const char *name,
const char *suffix)
2617 memset(&sid, 0,
sizeof(sid));
2618 set_ctl_name(sid.
name, name, suffix);
2624 static int snd_ac97_rename_ctl(
struct snd_ac97 *ac97,
const char *src,
2625 const char *dst,
const char *suffix)
2627 struct snd_kcontrol *kctl = ctl_find(ac97, src, suffix);
2629 set_ctl_name(kctl->
id.name, dst, suffix);
2636 static void snd_ac97_rename_vol_ctl(
struct snd_ac97 *ac97,
const char *src,
2639 snd_ac97_rename_ctl(ac97, src, dst,
"Switch");
2640 snd_ac97_rename_ctl(ac97, src, dst,
"Volume");
2644 static int snd_ac97_swap_ctl(
struct snd_ac97 *ac97,
const char *
s1,
2645 const char *
s2,
const char *suffix)
2648 kctl1 = ctl_find(ac97, s1, suffix);
2649 kctl2 = ctl_find(ac97, s2, suffix);
2650 if (kctl1 && kctl2) {
2651 set_ctl_name(kctl1->
id.name, s2, suffix);
2652 set_ctl_name(kctl2->
id.name, s1, suffix);
2662 int err = snd_ac97_put_volsw(kcontrol, ucontrol);
2666 snd_ac97_put_volsw(kcontrol, ucontrol);
2673 static int tune_hp_only(
struct snd_ac97 *ac97)
2676 struct snd_kcontrol *mvol = ctl_find(ac97,
"Master Playback Volume",
NULL);
2677 if (! msw || ! mvol)
2679 msw->
put = bind_hp_volsw_put;
2680 mvol->
put = bind_hp_volsw_put;
2681 snd_ac97_remove_ctl(ac97,
"Headphone Playback",
"Switch");
2682 snd_ac97_remove_ctl(ac97,
"Headphone Playback",
"Volume");
2688 static int tune_hp_only(
struct snd_ac97 *ac97)
2690 if (ctl_find(ac97,
"Headphone Playback Switch",
NULL) ==
NULL)
2692 snd_ac97_remove_ctl(ac97,
"Master Playback",
"Switch");
2693 snd_ac97_remove_ctl(ac97,
"Master Playback",
"Volume");
2694 snd_ac97_rename_vol_ctl(ac97,
"Headphone Playback",
"Master Playback");
2700 static int tune_swap_hp(
struct snd_ac97 *ac97)
2702 if (ctl_find(ac97,
"Headphone Playback Switch",
NULL) ==
NULL)
2704 snd_ac97_rename_vol_ctl(ac97,
"Master Playback",
"Line-Out Playback");
2705 snd_ac97_rename_vol_ctl(ac97,
"Headphone Playback",
"Master Playback");
2710 static int tune_swap_surround(
struct snd_ac97 *ac97)
2712 if (snd_ac97_swap_ctl(ac97,
"Master Playback",
"Surround Playback",
"Switch") ||
2713 snd_ac97_swap_ctl(ac97,
"Master Playback",
"Surround Playback",
"Volume"))
2719 static int tune_ad_sharing(
struct snd_ac97 *ac97)
2721 unsigned short scfg;
2722 if ((ac97->
id & 0xffffff00) != 0x41445300) {
2736 static int tune_alc_jack(
struct snd_ac97 *ac97)
2738 if ((ac97->
id & 0xffffff00) != 0x414c4700) {
2746 return snd_ctl_add(ac97->
bus->card, snd_ac97_cnew(&snd_ac97_alc_jack_detect, ac97));
2750 static int tune_inv_eapd(
struct snd_ac97 *ac97)
2755 set_inv_eapd(ac97, kctl);
2761 int err = snd_ac97_put_volsw(kcontrol, ucontrol);
2766 unsigned short mask;
2767 if (shift != rshift)
2779 static int tune_mute_led(
struct snd_ac97 *ac97)
2784 msw->
put = master_mute_sw_put;
2785 snd_ac97_remove_ctl(ac97,
"External Amplifier",
NULL);
2788 AC97_PD_EAPD, AC97_PD_EAPD
2794 static int hp_master_mute_sw_put(
struct snd_kcontrol *kcontrol,
2797 int err = bind_hp_volsw_put(kcontrol, ucontrol);
2802 unsigned short mask;
2803 if (shift != rshift)
2814 static int tune_hp_mute_led(
struct snd_ac97 *ac97)
2817 struct snd_kcontrol *mvol = ctl_find(ac97,
"Master Playback Volume",
NULL);
2818 if (! msw || ! mvol)
2820 msw->
put = hp_master_mute_sw_put;
2821 mvol->
put = bind_hp_volsw_put;
2822 snd_ac97_remove_ctl(ac97,
"External Amplifier",
NULL);
2823 snd_ac97_remove_ctl(ac97,
"Headphone Playback",
"Switch");
2824 snd_ac97_remove_ctl(ac97,
"Headphone Playback",
"Volume");
2827 AC97_PD_EAPD, AC97_PD_EAPD
2839 {
"hp_only", tune_hp_only },
2840 {
"swap_hp", tune_swap_hp },
2841 {
"swap_surround", tune_swap_surround },
2842 {
"ad_sharing", tune_ad_sharing },
2843 {
"alc_jack", tune_alc_jack },
2844 {
"inv_eapd", tune_inv_eapd },
2845 {
"mute_led", tune_mute_led },
2846 {
"hp_mute_led", tune_hp_mute_led },
2850 static int apply_quirk(
struct snd_ac97 *ac97,
int type)
2854 else if (type >=
ARRAY_SIZE(applicable_quirks))
2856 if (applicable_quirks[type].
func)
2857 return applicable_quirks[
type].
func(ac97);
2862 static int apply_quirk_str(
struct snd_ac97 *ac97,
const char *typestr)
2867 for (i = 0; i <
ARRAY_SIZE(applicable_quirks); i++) {
2868 q = &applicable_quirks[
i];
2870 return apply_quirk(ac97, i);
2873 if (*typestr >=
'0' && *typestr <=
'9')
2896 if (
override &&
strcmp(
override,
"-1") &&
strcmp(
override,
"default")) {
2897 result = apply_quirk_str(ac97,
override);
2914 result = apply_quirk(ac97, quirk->
type);
2929 static int __init alsa_ac97_init(
void)
2934 static void __exit alsa_ac97_exit(
void)