Lines Matching full:ac97
33 MODULE_PARM_DESC(enable_loopback, "Enable AC97 ADC/DAC Loopback Control");
49 int (*patch)(struct snd_ac97 *ac97);
50 int (*mpatch)(struct snd_ac97 *ac97);
62 * currently used by the AC97 emulation of the almost-AC97 PCI168 card.
194 static void update_power_regs(struct snd_ac97 *ac97);
196 #define ac97_is_power_save_mode(ac97) \
197 ((ac97->scaps & AC97_SCAP_POWER_SAVE) && power_save)
199 #define ac97_is_power_save_mode(ac97) 0
202 #define ac97_err(ac97, fmt, args...) \
203 dev_err((ac97)->bus->card->dev, fmt, ##args)
204 #define ac97_warn(ac97, fmt, args...) \
205 dev_warn((ac97)->bus->card->dev, fmt, ##args)
206 #define ac97_dbg(ac97, fmt, args...) \
207 dev_dbg((ac97)->bus->card->dev, fmt, ##args)
213 static int snd_ac97_valid_reg(struct snd_ac97 *ac97, unsigned short reg)
216 switch (ac97->id) {
261 * @ac97: the ac97 instance
271 void snd_ac97_write(struct snd_ac97 *ac97, unsigned short reg, unsigned short value)
273 if (!snd_ac97_valid_reg(ac97, reg))
275 if ((ac97->id & 0xffffff00) == AC97_ID_ALC100) {
278 ac97->bus->ops->write(ac97, AC97_RESET, 0); /* reset audio codec */
280 ac97->bus->ops->write(ac97, reg, value);
288 * @ac97: the ac97 instance
296 unsigned short snd_ac97_read(struct snd_ac97 *ac97, unsigned short reg)
298 if (!snd_ac97_valid_reg(ac97, reg))
300 return ac97->bus->ops->read(ac97, reg);
304 static inline unsigned short snd_ac97_read_cache(struct snd_ac97 *ac97, unsigned short reg)
306 if (! test_bit(reg, ac97->reg_accessed)) {
307 ac97->regs[reg] = ac97->bus->ops->read(ac97, reg);
308 // set_bit(reg, ac97->reg_accessed);
310 return ac97->regs[reg];
317 * @ac97: the ac97 instance
325 void snd_ac97_write_cache(struct snd_ac97 *ac97, unsigned short reg, unsigned short value)
327 if (!snd_ac97_valid_reg(ac97, reg))
329 guard(mutex)(&ac97->reg_mutex);
330 ac97->regs[reg] = value;
331 ac97->bus->ops->write(ac97, reg, value);
332 set_bit(reg, ac97->reg_accessed);
339 * @ac97: the ac97 instance
349 int snd_ac97_update(struct snd_ac97 *ac97, unsigned short reg, unsigned short value)
353 if (!snd_ac97_valid_reg(ac97, reg))
355 guard(mutex)(&ac97->reg_mutex);
356 change = ac97->regs[reg] != value;
358 ac97->regs[reg] = value;
359 ac97->bus->ops->write(ac97, reg, value);
361 set_bit(reg, ac97->reg_accessed);
369 * @ac97: the ac97 instance
380 int snd_ac97_update_bits(struct snd_ac97 *ac97, unsigned short reg, unsigned short mask, unsigned short value)
382 if (!snd_ac97_valid_reg(ac97, reg))
384 guard(mutex)(&ac97->reg_mutex);
385 return snd_ac97_update_bits_nolock(ac97, reg, mask, value);
391 int snd_ac97_update_bits_nolock(struct snd_ac97 *ac97, unsigned short reg,
397 old = snd_ac97_read_cache(ac97, reg);
401 ac97->regs[reg] = new;
402 ac97->bus->ops->write(ac97, reg, new);
404 set_bit(reg, ac97->reg_accessed);
408 static int snd_ac97_ad18xx_update_pcm_bits(struct snd_ac97 *ac97, int codec, unsigned short mask, unsigned short value)
413 guard(mutex)(&ac97->page_mutex);
414 old = ac97->spec.ad18xx.pcmreg[codec];
418 guard(mutex)(&ac97->reg_mutex);
419 cfg = snd_ac97_read_cache(ac97, AC97_AD_SERIAL_CFG);
420 ac97->spec.ad18xx.pcmreg[codec] = new;
422 ac97->bus->ops->write(ac97, AC97_AD_SERIAL_CFG,
424 ac97->spec.ad18xx.unchained[codec] | ac97->spec.ad18xx.chained[codec]);
426 ac97->bus->ops->write(ac97, AC97_PCM, new);
428 ac97->bus->ops->write(ac97, AC97_AD_SERIAL_CFG,
450 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
456 val = snd_ac97_read_cache(ac97, e->reg);
467 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
484 return snd_ac97_update_bits(ac97, e->reg, mask, val);
487 /* save/restore ac97 v2.3 paging */
488 static int snd_ac97_page_save(struct snd_ac97 *ac97, int reg, struct snd_kcontrol *kcontrol)
492 (ac97->ext_id & AC97_EI_REV_MASK) >= AC97_EI_REV_23 &&
495 mutex_lock(&ac97->page_mutex); /* lock paging */
496 page_save = snd_ac97_read(ac97, AC97_INT_PAGING) & AC97_PAGE_MASK;
497 snd_ac97_update_bits(ac97, AC97_INT_PAGING, AC97_PAGE_MASK, page);
502 static void snd_ac97_page_restore(struct snd_ac97 *ac97, int page_save)
505 snd_ac97_update_bits(ac97, AC97_INT_PAGING, AC97_PAGE_MASK, page_save);
506 mutex_unlock(&ac97->page_mutex); /* unlock paging */
528 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
536 page_save = snd_ac97_page_save(ac97, reg, kcontrol);
537 ucontrol->value.integer.value[0] = (snd_ac97_read_cache(ac97, reg) >> shift) & mask;
539 ucontrol->value.integer.value[1] = (snd_ac97_read_cache(ac97, reg) >> rshift) & mask;
545 snd_ac97_page_restore(ac97, page_save);
552 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
561 page_save = snd_ac97_page_save(ac97, reg, kcontrol);
574 err = snd_ac97_update_bits(ac97, reg, val_mask, val);
575 snd_ac97_page_restore(ac97, page_save);
581 ac97->power_up &= ~(1 << (reg>>1));
583 ac97->power_up |= 1 << (reg>>1);
584 update_power_regs(ac97);
671 static void set_inv_eapd(struct snd_ac97 *ac97, struct snd_kcontrol *kctl)
674 snd_ac97_update_bits(ac97, AC97_POWERDOWN, (1<<15), (1<<15)); /* EAPD up */
675 ac97->scaps |= AC97_SCAP_INV_EAPD;
709 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
711 guard(mutex)(&ac97->reg_mutex);
712 ucontrol->value.iec958.status[0] = ac97->spdif_status & 0xff;
713 ucontrol->value.iec958.status[1] = (ac97->spdif_status >> 8) & 0xff;
714 ucontrol->value.iec958.status[2] = (ac97->spdif_status >> 16) & 0xff;
715 ucontrol->value.iec958.status[3] = (ac97->spdif_status >> 24) & 0xff;
721 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
754 guard(mutex)(&ac97->reg_mutex);
755 change = ac97->spdif_status != new;
756 ac97->spdif_status = new;
758 if (ac97->flags & AC97_CS_SPDIF) {
765 change |= snd_ac97_update_bits_nolock(ac97, AC97_CSR_SPDIF, 0x3fff, ((val & 0xcfff) | (x << 12)));
766 } else if (ac97->flags & AC97_CX_SPDIF) {
770 change |= snd_ac97_update_bits_nolock(ac97, AC97_CXR_AUDIO_MISC,
773 } else if (ac97->id == AC97_ID_YMF743) {
774 change |= snd_ac97_update_bits_nolock(ac97,
780 unsigned short extst = snd_ac97_read_cache(ac97, AC97_EXTENDED_STATUS);
781 snd_ac97_update_bits_nolock(ac97, AC97_EXTENDED_STATUS, AC97_EA_SPDIF, 0); /* turn off */
783 change |= snd_ac97_update_bits_nolock(ac97, AC97_SPDIF, 0x3fff, val);
785 snd_ac97_update_bits_nolock(ac97, AC97_EXTENDED_STATUS, AC97_EA_SPDIF, AC97_EA_SPDIF); /* turn on again */
794 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
804 guard(mutex)(&ac97->reg_mutex);
807 old = snd_ac97_read_cache(ac97, reg);
812 unsigned short extst = snd_ac97_read_cache(ac97, AC97_EXTENDED_STATUS);
813 snd_ac97_update_bits_nolock(ac97, AC97_EXTENDED_STATUS, AC97_EA_SPDIF, 0); /* turn off */
814 change = snd_ac97_update_bits_nolock(ac97, reg, mask, value);
816 snd_ac97_update_bits_nolock(ac97, AC97_EXTENDED_STATUS, AC97_EA_SPDIF, AC97_EA_SPDIF); /* turn on again */
847 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "AC97-SPSA",
862 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
868 if (lshift != rshift && (ac97->flags & AC97_STEREO_MUTES))
879 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
885 ucontrol->value.integer.value[0] = mask - ((ac97->spec.ad18xx.pcmreg[codec] >> lshift) & mask);
886 if (lshift != rshift && (ac97->flags & AC97_STEREO_MUTES))
887 ucontrol->value.integer.value[1] = mask - ((ac97->spec.ad18xx.pcmreg[codec] >> rshift) & mask);
893 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
902 if (lshift != rshift && (ac97->flags & AC97_STEREO_MUTES)) {
906 return snd_ac97_ad18xx_update_pcm_bits(ac97, codec, valmask, val);
925 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
928 guard(mutex)(&ac97->page_mutex);
929 ucontrol->value.integer.value[0] = 31 - ((ac97->spec.ad18xx.pcmreg[codec] >> 8) & 31);
930 ucontrol->value.integer.value[1] = 31 - ((ac97->spec.ad18xx.pcmreg[codec] >> 0) & 31);
936 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
942 return snd_ac97_ad18xx_update_pcm_bits(ac97, codec, 0x1f1f, (val1 << 8) | val2);
969 static void snd_ac97_powerdown(struct snd_ac97 *ac97);
989 static int snd_ac97_free(struct snd_ac97 *ac97)
991 if (ac97) {
993 cancel_delayed_work_sync(&ac97->power_work);
995 snd_ac97_proc_done(ac97);
996 if (ac97->bus)
997 ac97->bus->codec[ac97->num] = NULL;
998 if (ac97->private_free)
999 ac97->private_free(ac97);
1000 kfree(ac97);
1007 struct snd_ac97 *ac97 = device->device_data;
1008 snd_ac97_powerdown(ac97); /* for avoiding click noises during shut down */
1009 return snd_ac97_free(ac97);
1012 static int snd_ac97_try_volume_mix(struct snd_ac97 * ac97, int reg)
1016 if (! snd_ac97_valid_reg(ac97, reg))
1021 return ac97->caps & AC97_BC_BASS_TREBLE ? 1 : 0;
1023 return ac97->caps & AC97_BC_HEADPHONE ? 1 : 0;
1025 return ac97->caps & AC97_BC_DEDICATED_MIC ? 1 : 0;
1027 if (ac97->caps & AC97_BC_3D_TECH_ID_MASK) {
1028 val = snd_ac97_read(ac97, reg);
1034 if ((ac97->ext_id & AC97_EI_CDAC) == 0)
1038 if ((ac97->ext_id & AC97_EI_LDAC) == 0)
1044 if ((ac97->ext_id & AC97_EI_SDAC) == 0)
1049 val = snd_ac97_read(ac97, reg);
1053 snd_ac97_write_cache(ac97, reg, val | mask);
1054 val = snd_ac97_read(ac97, reg);
1055 val = snd_ac97_read(ac97, reg);
1062 static void check_volume_resolution(struct snd_ac97 *ac97, int reg, unsigned char *lo_max, unsigned char *hi_max)
1069 if (ac97->res_table) {
1071 for (tbl = ac97->res_table; tbl->reg; tbl++) {
1084 ac97, reg,
1087 /* Do the read twice due to buffers on some ac97 codecs.
1091 val = snd_ac97_read(ac97, reg);
1092 val = snd_ac97_read(ac97, reg);
1102 static int snd_ac97_try_bit(struct snd_ac97 * ac97, int reg, int bit)
1107 orig = snd_ac97_read(ac97, reg);
1109 snd_ac97_write(ac97, reg, val);
1110 res = snd_ac97_read(ac97, reg);
1111 snd_ac97_write_cache(ac97, reg, orig);
1116 static void snd_ac97_change_volume_params2(struct snd_ac97 * ac97, int reg, int shift, unsigned char *max)
1122 snd_ac97_write(ac97, reg, val);
1123 val1 = snd_ac97_read(ac97, reg);
1128 snd_ac97_write_cache(ac97, reg, AC97_MUTE_MASK_STEREO);
1143 struct snd_ac97 * ac97)
1147 template.index = ac97->num;
1148 return snd_ctl_new1(&template, ac97);
1156 struct snd_ac97 *ac97)
1162 if (! snd_ac97_valid_reg(ac97, reg))
1166 val = snd_ac97_read(ac97, reg);
1167 if (check_stereo || (ac97->flags & AC97_STEREO_MUTES)) {
1170 snd_ac97_write(ac97, reg, val1);
1171 if (val1 == snd_ac97_read(ac97, reg))
1178 tmp.index = ac97->num;
1179 kctl = snd_ctl_new1(&tmp, ac97);
1184 tmp.index = ac97->num;
1185 kctl = snd_ctl_new1(&tmp, ac97);
1191 snd_ac97_write_cache(ac97, reg, val | mute_mask);
1225 unsigned int hi_max, struct snd_ac97 *ac97)
1230 if (! snd_ac97_valid_reg(ac97, reg))
1235 tmp.index = ac97->num;
1236 kctl = snd_ctl_new1(&tmp, ac97);
1240 tmp.index = ac97->num;
1241 kctl = snd_ctl_new1(&tmp, ac97);
1253 ac97, reg,
1254 (snd_ac97_read(ac97, reg) & AC97_MUTE_MASK_STEREO)
1265 struct snd_ac97 *ac97)
1271 if (! snd_ac97_valid_reg(ac97, reg))
1274 if (snd_ac97_try_bit(ac97, reg, 15)) {
1278 ac97);
1282 check_volume_resolution(ac97, reg, &lo_max, &hi_max);
1285 err = snd_ac97_cvol_new(card, name, reg, lo_max, hi_max, ac97);
1292 #define snd_ac97_cmix_new(card, pfx, reg, acheck, ac97) \
1293 snd_ac97_cmix_new_stereo(card, pfx, reg, 0, acheck, ac97)
1294 #define snd_ac97_cmute_new(card, name, reg, acheck, ac97) \
1295 snd_ac97_cmute_new_stereo(card, name, reg, 0, acheck, ac97)
1297 static unsigned int snd_ac97_determine_spdif_rates(struct snd_ac97 *ac97);
1299 static int snd_ac97_mixer_build(struct snd_ac97 * ac97)
1301 struct snd_card *card = ac97->bus->card;
1309 if (snd_ac97_try_volume_mix(ac97, AC97_MASTER)) {
1310 if (ac97->flags & AC97_HAS_NO_MASTER_VOL)
1312 AC97_MASTER, 0, ac97);
1315 AC97_MASTER, 0, ac97);
1320 ac97->regs[AC97_CENTER_LFE_MASTER] = AC97_MUTE_MASK_STEREO;
1323 if ((snd_ac97_try_volume_mix(ac97, AC97_CENTER_LFE_MASTER))
1324 && !(ac97->flags & AC97_AD_MULTI)) {
1325 err = snd_ctl_add(card, snd_ac97_cnew(&snd_ac97_controls_center[0], ac97));
1328 err = snd_ctl_add(card, kctl = snd_ac97_cnew(&snd_ac97_controls_center[1], ac97));
1331 snd_ac97_change_volume_params2(ac97, AC97_CENTER_LFE_MASTER, 0, &max);
1335 snd_ac97_write_cache(ac97, AC97_CENTER_LFE_MASTER, ac97->regs[AC97_CENTER_LFE_MASTER] | max);
1339 if ((snd_ac97_try_volume_mix(ac97, AC97_CENTER_LFE_MASTER+1))
1340 && !(ac97->flags & AC97_AD_MULTI)) {
1341 err = snd_ctl_add(card, snd_ac97_cnew(&snd_ac97_controls_lfe[0], ac97));
1344 err = snd_ctl_add(card, kctl = snd_ac97_cnew(&snd_ac97_controls_lfe[1], ac97));
1347 snd_ac97_change_volume_params2(ac97, AC97_CENTER_LFE_MASTER, 8, &max);
1351 snd_ac97_write_cache(ac97, AC97_CENTER_LFE_MASTER, ac97->regs[AC97_CENTER_LFE_MASTER] | max << 8);
1355 if ((snd_ac97_try_volume_mix(ac97, AC97_SURROUND_MASTER))
1356 && !(ac97->flags & AC97_AD_MULTI)) {
1360 ac97);
1366 if (snd_ac97_try_volume_mix(ac97, AC97_HEADPHONE)) {
1368 AC97_HEADPHONE, 0, ac97);
1374 if (snd_ac97_try_volume_mix(ac97, AC97_MASTER_MONO)) {
1376 AC97_MASTER_MONO, 0, ac97);
1382 if (!(ac97->flags & AC97_HAS_NO_TONE)) {
1383 if (snd_ac97_try_volume_mix(ac97, AC97_MASTER_TONE)) {
1385 kctl = snd_ac97_cnew(&snd_ac97_controls_tone[idx], ac97);
1389 if (ac97->id == AC97_ID_YMF743 ||
1390 ac97->id == AC97_ID_YMF753) {
1395 snd_ac97_write_cache(ac97, AC97_MASTER_TONE, 0x0f0f);
1400 if (!(ac97->flags & AC97_HAS_NO_PC_BEEP) &&
1401 ((ac97->flags & AC97_HAS_PC_BEEP) ||
1402 snd_ac97_try_volume_mix(ac97, AC97_PC_BEEP))) {
1404 kctl = snd_ac97_cnew(&snd_ac97_controls_pc_beep[idx], ac97);
1411 ac97,
1413 (snd_ac97_read(ac97, AC97_PC_BEEP)
1419 if (!(ac97->flags & AC97_HAS_NO_PHONE)) {
1420 if (snd_ac97_try_volume_mix(ac97, AC97_PHONE)) {
1422 AC97_PHONE, 1, ac97);
1429 if (!(ac97->flags & AC97_HAS_NO_MIC)) {
1430 if (snd_ac97_try_volume_mix(ac97, AC97_MIC)) {
1432 AC97_MIC, 1, ac97);
1435 err = snd_ctl_add(card, snd_ac97_cnew(&snd_ac97_controls_mic_boost, ac97));
1442 if (snd_ac97_try_volume_mix(ac97, AC97_LINE)) {
1444 AC97_LINE, 1, ac97);
1450 if (!(ac97->flags & AC97_HAS_NO_CD)) {
1451 if (snd_ac97_try_volume_mix(ac97, AC97_CD)) {
1453 AC97_CD, 1, ac97);
1460 if (!(ac97->flags & AC97_HAS_NO_VIDEO)) {
1461 if (snd_ac97_try_volume_mix(ac97, AC97_VIDEO)) {
1463 AC97_VIDEO, 1, ac97);
1470 if (!(ac97->flags & AC97_HAS_NO_AUX)) {
1471 if (snd_ac97_try_volume_mix(ac97, AC97_AUX)) {
1473 AC97_AUX, 1, ac97);
1480 if (ac97->flags & AC97_AD_MULTI) {
1482 if (ac97->flags & AC97_STEREO_MUTES)
1487 kctl = snd_ac97_cnew(&snd_ac97_controls_ad18xx_pcm[idx], ac97);
1493 ac97->spec.ad18xx.pcmreg[0] = init_val;
1494 if (ac97->scaps & AC97_SCAP_SURROUND_DAC) {
1496 kctl = snd_ac97_cnew(&snd_ac97_controls_ad18xx_surround[idx], ac97);
1502 ac97->spec.ad18xx.pcmreg[1] = init_val;
1504 if (ac97->scaps & AC97_SCAP_CENTER_LFE_DAC) {
1506 kctl = snd_ac97_cnew(&snd_ac97_controls_ad18xx_center[idx], ac97);
1513 kctl = snd_ac97_cnew(&snd_ac97_controls_ad18xx_lfe[idx], ac97);
1519 ac97->spec.ad18xx.pcmreg[2] = init_val;
1521 snd_ac97_write_cache(ac97, AC97_PCM, init_val);
1523 if (!(ac97->flags & AC97_HAS_NO_STD_PCM)) {
1524 if (ac97->flags & AC97_HAS_NO_PCM_VOL)
1527 AC97_PCM, 0, ac97);
1530 AC97_PCM, 0, ac97);
1537 if (!(ac97->flags & AC97_HAS_NO_REC_GAIN)) {
1538 err = snd_ctl_add(card, snd_ac97_cnew(&snd_ac97_control_capture_src, ac97));
1541 if (snd_ac97_try_bit(ac97, AC97_REC_GAIN, 15)) {
1543 AC97_REC_GAIN, 0, ac97);
1547 kctl = snd_ac97_cnew(&snd_ac97_control_capture_vol, ac97);
1552 snd_ac97_write_cache(ac97, AC97_REC_SEL, 0x0000);
1553 snd_ac97_write_cache(ac97, AC97_REC_GAIN, 0x0000);
1556 if (snd_ac97_try_volume_mix(ac97, AC97_REC_GAIN_MIC)) {
1558 kctl = snd_ac97_cnew(&snd_ac97_controls_mic_capture[idx], ac97);
1564 snd_ac97_write_cache(ac97, AC97_REC_GAIN_MIC, 0x0000);
1568 if (snd_ac97_try_bit(ac97, AC97_GENERAL_PURPOSE, 15)) {
1569 err = snd_ctl_add(card, snd_ac97_cnew(&snd_ac97_controls_general[AC97_GENERAL_PCM_OUT], ac97));
1575 if (ac97->caps & AC97_BC_SIM_STEREO) {
1576 err = snd_ctl_add(card, snd_ac97_cnew(&snd_ac97_controls_general[AC97_GENERAL_STEREO_ENHANCEMENT], ac97));
1582 if (snd_ac97_try_bit(ac97, AC97_GENERAL_PURPOSE, 13)) {
1583 err = snd_ctl_add(card, snd_ac97_cnew(&snd_ac97_controls_general[AC97_GENERAL_3D], ac97));
1589 if (ac97->caps & AC97_BC_LOUDNESS) {
1590 err = snd_ctl_add(card, snd_ac97_cnew(&snd_ac97_controls_general[AC97_GENERAL_LOUDNESS], ac97));
1596 if (snd_ac97_try_bit(ac97, AC97_GENERAL_PURPOSE, 9)) {
1597 err = snd_ctl_add(card, snd_ac97_cnew(&snd_ac97_controls_general[AC97_GENERAL_MONO], ac97));
1603 if (snd_ac97_try_bit(ac97, AC97_GENERAL_PURPOSE, 8)) {
1604 err = snd_ctl_add(card, snd_ac97_cnew(&snd_ac97_controls_general[AC97_GENERAL_MIC], ac97));
1610 if (enable_loopback && snd_ac97_try_bit(ac97, AC97_GENERAL_PURPOSE, 7)) {
1611 err = snd_ctl_add(card, snd_ac97_cnew(&snd_ac97_controls_general[AC97_GENERAL_LOOPBACK], ac97));
1616 snd_ac97_update_bits(ac97, AC97_GENERAL_PURPOSE, ~AC97_GP_DRSS_MASK, 0x0000);
1619 if (ac97->build_ops->build_3d) {
1620 ac97->build_ops->build_3d(ac97);
1622 if (snd_ac97_try_volume_mix(ac97, AC97_3D_CONTROL)) {
1625 snd_ac97_write(ac97, AC97_3D_CONTROL, val);
1626 val = snd_ac97_read(ac97, AC97_3D_CONTROL);
1628 kctl = snd_ac97_cnew(&snd_ac97_controls_3d[0], ac97);
1634 kctl = snd_ac97_cnew(&snd_ac97_controls_3d[1], ac97);
1640 snd_ac97_write_cache(ac97, AC97_3D_CONTROL, 0x0000);
1647 if (ac97->subsystem_vendor == 0x1043 &&
1648 ac97->subsystem_device == 0x810f)
1649 ac97->ext_id |= AC97_EI_SPDIF;
1651 if ((ac97->ext_id & AC97_EI_SPDIF) && !(ac97->scaps & AC97_SCAP_NO_SPDIF)) {
1652 if (ac97->build_ops->build_spdif) {
1653 err = ac97->build_ops->build_spdif(ac97);
1658 err = snd_ctl_add(card, snd_ac97_cnew(&snd_ac97_controls_spdif[idx], ac97));
1662 if (ac97->build_ops->build_post_spdif) {
1663 err = ac97->build_ops->build_post_spdif(ac97);
1669 snd_ac97_write_cache(ac97, AC97_SPDIF, 0x2a20);
1670 ac97->rates[AC97_RATES_SPDIF] = snd_ac97_determine_spdif_rates(ac97);
1672 ac97->spdif_status = SNDRV_PCM_DEFAULT_CON_SPDIF;
1676 if (ac97->build_ops->build_specific) {
1677 err = ac97->build_ops->build_specific(ac97);
1682 if (snd_ac97_try_bit(ac97, AC97_POWERDOWN, 15)) {
1683 kctl = snd_ac97_cnew(&snd_ac97_control_eapd, ac97);
1686 if (ac97->scaps & AC97_SCAP_INV_EAPD)
1687 set_inv_eapd(ac97, kctl);
1696 static int snd_ac97_modem_build(struct snd_card *card, struct snd_ac97 * ac97)
1701 ac97_dbg(ac97, "AC97_GPIO_CFG = %x\n",
1702 snd_ac97_read(ac97,AC97_GPIO_CFG));
1704 snd_ac97_write(ac97, AC97_GPIO_CFG, 0xffff & ~(AC97_GPIO_LINE1_OH));
1705 snd_ac97_write(ac97, AC97_GPIO_POLARITY, 0xffff & ~(AC97_GPIO_LINE1_OH));
1706 snd_ac97_write(ac97, AC97_GPIO_STICKY, 0xffff);
1707 snd_ac97_write(ac97, AC97_GPIO_WAKEUP, 0x0);
1708 snd_ac97_write(ac97, AC97_MISC_AFE, 0x0);
1712 err = snd_ctl_add(card, snd_ctl_new1(&snd_ac97_controls_modem_switches[idx], ac97));
1718 if (ac97->build_ops->build_specific) {
1719 err = ac97->build_ops->build_specific(ac97);
1727 static int snd_ac97_test_rate(struct snd_ac97 *ac97, int reg, int shadow_reg, int rate)
1732 tmp = ((unsigned int)rate * ac97->bus->clock) / 48000;
1733 snd_ac97_write_cache(ac97, reg, tmp & 0xffff);
1735 snd_ac97_write_cache(ac97, shadow_reg, tmp & 0xffff);
1736 val = snd_ac97_read(ac97, reg);
1740 static void snd_ac97_determine_rates(struct snd_ac97 *ac97, int reg, int shadow_reg, unsigned int *r_result)
1745 if (ac97->bus->no_vra) {
1747 if ((ac97->flags & AC97_DOUBLE_RATE) &&
1753 saved = snd_ac97_read(ac97, reg);
1754 if ((ac97->ext_id & AC97_EI_DRA) && reg == AC97_PCM_FRONT_DAC_RATE)
1755 snd_ac97_update_bits(ac97, AC97_EXTENDED_STATUS,
1758 if (snd_ac97_test_rate(ac97, reg, shadow_reg, 11000))
1761 if (snd_ac97_test_rate(ac97, reg, shadow_reg, 8000))
1763 if (snd_ac97_test_rate(ac97, reg, shadow_reg, 11025))
1765 if (snd_ac97_test_rate(ac97, reg, shadow_reg, 16000))
1767 if (snd_ac97_test_rate(ac97, reg, shadow_reg, 22050))
1769 if (snd_ac97_test_rate(ac97, reg, shadow_reg, 32000))
1771 if (snd_ac97_test_rate(ac97, reg, shadow_reg, 44100))
1773 if (snd_ac97_test_rate(ac97, reg, shadow_reg, 48000))
1775 if ((ac97->flags & AC97_DOUBLE_RATE) &&
1778 snd_ac97_update_bits(ac97, AC97_EXTENDED_STATUS,
1780 if (snd_ac97_test_rate(ac97, reg, shadow_reg, 64000 / 2))
1782 if (snd_ac97_test_rate(ac97, reg, shadow_reg, 88200 / 2))
1784 if (snd_ac97_test_rate(ac97, reg, shadow_reg, 96000 / 2))
1787 if (!snd_ac97_test_rate(ac97, reg, shadow_reg, 76100 / 2))
1789 snd_ac97_update_bits(ac97, AC97_EXTENDED_STATUS,
1793 snd_ac97_write_cache(ac97, reg, saved);
1795 snd_ac97_write_cache(ac97, shadow_reg, saved);
1800 static unsigned int snd_ac97_determine_spdif_rates(struct snd_ac97 *ac97)
1812 snd_ac97_update_bits(ac97, AC97_SPDIF, AC97_SC_SPSR_MASK, ctl_bits[i]);
1813 if ((snd_ac97_read(ac97, AC97_SPDIF) & AC97_SC_SPSR_MASK) == ctl_bits[i])
1831 void snd_ac97_get_name(struct snd_ac97 *ac97, unsigned int id, char *name,
1845 if (ac97 && pid->patch) {
1848 pid->patch(ac97);
1857 if (ac97 && pid->patch) {
1860 pid->patch(ac97);
1870 * @ac97: the codec instance
1874 const char *snd_ac97_get_short_name(struct snd_ac97 *ac97)
1879 if (pid->id == (ac97->id & pid->mask))
1889 static int ac97_reset_wait(struct snd_ac97 *ac97, int timeout, int with_modem)
1898 snd_ac97_read(ac97, AC97_RESET);
1899 snd_ac97_read(ac97, AC97_VENDOR_ID1);
1900 snd_ac97_read(ac97, AC97_VENDOR_ID2);
1903 val = snd_ac97_read(ac97, AC97_EXTENDED_MID);
1907 if (ac97->scaps & AC97_SCAP_DETECT_BY_VENDOR) {
1909 val = snd_ac97_read(ac97, AC97_VENDOR_ID1);
1917 snd_ac97_write_cache(ac97, AC97_REC_GAIN, 0x8a05);
1918 if ((snd_ac97_read(ac97, AC97_REC_GAIN) & 0x7fff) == 0x0a05)
1927 * snd_ac97_bus - create an AC97 bus component
1932 * @rbus: the pointer to store the new AC97 bus instance.
1934 * Creates an AC97 bus component. An struct snd_ac97_bus instance is newly
1943 * The AC97 bus instance is registered as a low-level device, so you don't
1987 /* register ac97 codec to bus */
1990 struct snd_ac97 *ac97 = device->device_data;
1993 ac97->dev.bus = &ac97_bus_type;
1994 ac97->dev.parent = ac97->bus->card->dev;
1995 ac97->dev.release = ac97_device_release;
1996 dev_set_name(&ac97->dev, "%d-%d:%s",
1997 ac97->bus->card->number, ac97->num,
1998 snd_ac97_get_short_name(ac97));
1999 err = device_register(&ac97->dev);
2001 ac97_err(ac97, "Can't register ac97 bus\n");
2002 put_device(&ac97->dev);
2003 ac97->dev.bus = NULL;
2009 /* disconnect ac97 codec */
2012 struct snd_ac97 *ac97 = device->device_data;
2013 if (ac97->dev.bus)
2014 device_unregister(&ac97->dev);
2031 * @bus: the AC97 bus which codec is attached to
2032 * @template: the template of ac97, including index, callbacks and
2034 * @rac97: the pointer to store the new ac97 instance.
2043 * The ac97 instance is registered as a low-level device, so you don't
2051 struct snd_ac97 *ac97;
2072 ac97 = kzalloc(sizeof(*ac97), GFP_KERNEL);
2073 if (ac97 == NULL)
2075 ac97->private_data = template->private_data;
2076 ac97->private_free = template->private_free;
2077 ac97->bus = bus;
2078 ac97->pci = template->pci;
2079 ac97->num = template->num;
2080 ac97->addr = template->addr;
2081 ac97->scaps = template->scaps;
2082 ac97->res_table = template->res_table;
2083 bus->codec[ac97->num] = ac97;
2084 mutex_init(&ac97->reg_mutex);
2085 mutex_init(&ac97->page_mutex);
2087 INIT_DELAYED_WORK(&ac97->power_work, do_update_power);
2091 if (ac97->pci) {
2092 pci_read_config_word(ac97->pci, PCI_SUBSYSTEM_VENDOR_ID, &ac97->subsystem_vendor);
2093 pci_read_config_word(ac97->pci, PCI_SUBSYSTEM_ID, &ac97->subsystem_device);
2097 bus->ops->reset(ac97);
2101 ac97->id = snd_ac97_read(ac97, AC97_VENDOR_ID1) << 16;
2102 ac97->id |= snd_ac97_read(ac97, AC97_VENDOR_ID2);
2103 if (ac97->id && ac97->id != (unsigned int)-1) {
2104 pid = look_for_codec_id(snd_ac97_codec_ids, ac97->id);
2110 if (!(ac97->scaps & AC97_SCAP_SKIP_AUDIO))
2111 snd_ac97_write(ac97, AC97_RESET, 0);
2112 if (!(ac97->scaps & AC97_SCAP_SKIP_MODEM))
2113 snd_ac97_write(ac97, AC97_EXTENDED_MID, 0);
2115 bus->ops->wait(ac97);
2118 if (ac97->scaps & AC97_SCAP_SKIP_AUDIO)
2119 err = ac97_reset_wait(ac97, msecs_to_jiffies(500), 1);
2121 err = ac97_reset_wait(ac97, msecs_to_jiffies(500), 0);
2123 err = ac97_reset_wait(ac97,
2127 ac97_warn(ac97, "AC'97 %d does not respond - RESET\n",
2128 ac97->num);
2133 ac97->id = snd_ac97_read(ac97, AC97_VENDOR_ID1) << 16;
2134 ac97->id |= snd_ac97_read(ac97, AC97_VENDOR_ID2);
2135 if (! (ac97->scaps & AC97_SCAP_DETECT_BY_VENDOR) &&
2136 (ac97->id == 0x00000000 || ac97->id == 0xffffffff)) {
2137 ac97_err(ac97,
2139 ac97->num, ac97->id);
2140 snd_ac97_free(ac97);
2143 pid = look_for_codec_id(snd_ac97_codec_ids, ac97->id);
2145 ac97->flags |= pid->flags;
2148 if (!(ac97->scaps & AC97_SCAP_SKIP_AUDIO) && !(ac97->scaps & AC97_SCAP_AUDIO)) {
2150 snd_ac97_write_cache(ac97, AC97_REC_GAIN, 0x8a06);
2151 err = snd_ac97_read(ac97, AC97_REC_GAIN);
2153 ac97->scaps |= AC97_SCAP_AUDIO;
2155 if (ac97->scaps & AC97_SCAP_AUDIO) {
2156 ac97->caps = snd_ac97_read(ac97, AC97_RESET);
2157 ac97->ext_id = snd_ac97_read(ac97, AC97_EXTENDED_ID);
2158 if (ac97->ext_id == 0xffff) /* invalid combination */
2159 ac97->ext_id = 0;
2163 if (!(ac97->scaps & AC97_SCAP_SKIP_MODEM) && !(ac97->scaps & AC97_SCAP_MODEM)) {
2164 ac97->ext_mid = snd_ac97_read(ac97, AC97_EXTENDED_MID);
2165 if (ac97->ext_mid == 0xffff) /* invalid combination */
2166 ac97->ext_mid = 0;
2167 if (ac97->ext_mid & 1)
2168 ac97->scaps |= AC97_SCAP_MODEM;
2171 if (!ac97_is_audio(ac97) && !ac97_is_modem(ac97)) {
2172 if (!(ac97->scaps & (AC97_SCAP_SKIP_AUDIO|AC97_SCAP_SKIP_MODEM)))
2173 ac97_err(ac97,
2175 ac97->num);
2176 snd_ac97_free(ac97);
2184 if (ac97_is_audio(ac97)) {
2186 snd_ac97_write_cache(ac97, AC97_POWERDOWN, 0);
2187 if (! (ac97->flags & AC97_DEFAULT_POWER_OFF)) {
2188 snd_ac97_write_cache(ac97, AC97_RESET, 0); /* reset to defaults */
2190 snd_ac97_write_cache(ac97, AC97_POWERDOWN, 0);
2193 snd_ac97_write_cache(ac97, AC97_GENERAL_PURPOSE, 0);
2196 if ((snd_ac97_read(ac97, AC97_POWERDOWN) & 0x0f) == 0x0f)
2200 ac97_warn(ac97,
2201 "AC'97 %d analog subsections not ready\n", ac97->num);
2205 if (ac97_is_modem(ac97)) {
2211 if (ac97->ext_mid & AC97_MEI_LINE1) {
2212 snd_ac97_write_cache(ac97, AC97_LINE1_RATE, 8000);
2215 if (ac97->ext_mid & AC97_MEI_LINE2) {
2216 snd_ac97_write_cache(ac97, AC97_LINE2_RATE, 8000);
2219 if (ac97->ext_mid & AC97_MEI_HANDSET) {
2220 snd_ac97_write_cache(ac97, AC97_HANDSET_RATE, 8000);
2223 snd_ac97_write_cache(ac97, AC97_EXTENDED_MSTATUS, 0);
2226 snd_ac97_write_cache(ac97, AC97_EXTENDED_MSTATUS, 0);
2229 if ((snd_ac97_read(ac97, AC97_EXTENDED_MSTATUS) & tmp) == tmp)
2233 ac97_warn(ac97,
2235 ac97->num,
2236 snd_ac97_read(ac97, AC97_EXTENDED_MSTATUS));
2240 if (ac97_is_audio(ac97))
2241 ac97->addr = (ac97->ext_id & AC97_EI_ADDR_MASK) >> AC97_EI_ADDR_SHIFT;
2243 ac97->addr = (ac97->ext_mid & AC97_MEI_ADDR_MASK) >> AC97_MEI_ADDR_SHIFT;
2244 if (ac97->ext_id & 0x01c9) { /* L/R, MIC, SDAC, LDAC VRA support */
2245 reg = snd_ac97_read(ac97, AC97_EXTENDED_STATUS);
2246 reg |= ac97->ext_id & 0x01c0; /* LDAC/SDAC/CDAC */
2248 reg |= ac97->ext_id & 0x0009; /* VRA/VRM */
2249 snd_ac97_write_cache(ac97, AC97_EXTENDED_STATUS, reg);
2251 if ((ac97->ext_id & AC97_EI_DRA) && bus->dra) {
2254 snd_ac97_update_bits(ac97, AC97_GENERAL_PURPOSE, AC97_GP_DRSS_MASK, AC97_GP_DRSS_78);
2255 if ((snd_ac97_read(ac97, AC97_GENERAL_PURPOSE) & AC97_GP_DRSS_MASK) == AC97_GP_DRSS_78)
2256 ac97->flags |= AC97_DOUBLE_RATE;
2258 snd_ac97_update_bits(ac97, AC97_GENERAL_PURPOSE, AC97_GP_DRSS_MASK, 0);
2260 if (ac97->ext_id & AC97_EI_VRA) { /* VRA support */
2261 snd_ac97_determine_rates(ac97, AC97_PCM_FRONT_DAC_RATE, 0, &ac97->rates[AC97_RATES_FRONT_DAC]);
2262 snd_ac97_determine_rates(ac97, AC97_PCM_LR_ADC_RATE, 0, &ac97->rates[AC97_RATES_ADC]);
2264 ac97->rates[AC97_RATES_FRONT_DAC] = SNDRV_PCM_RATE_48000;
2265 if (ac97->flags & AC97_DOUBLE_RATE)
2266 ac97->rates[AC97_RATES_FRONT_DAC] |= SNDRV_PCM_RATE_96000;
2267 ac97->rates[AC97_RATES_ADC] = SNDRV_PCM_RATE_48000;
2269 if (ac97->ext_id & AC97_EI_SPDIF) {
2271 ac97->rates[AC97_RATES_SPDIF] = SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_32000;
2273 if (ac97->ext_id & AC97_EI_VRM) { /* MIC VRA support */
2274 snd_ac97_determine_rates(ac97, AC97_PCM_MIC_ADC_RATE, 0, &ac97->rates[AC97_RATES_MIC_ADC]);
2276 ac97->rates[AC97_RATES_MIC_ADC] = SNDRV_PCM_RATE_48000;
2278 if (ac97->ext_id & AC97_EI_SDAC) { /* SDAC support */
2279 snd_ac97_determine_rates(ac97, AC97_PCM_SURR_DAC_RATE, AC97_PCM_FRONT_DAC_RATE, &ac97->rates[AC97_RATES_SURR_DAC]);
2280 ac97->scaps |= AC97_SCAP_SURROUND_DAC;
2282 if (ac97->ext_id & AC97_EI_LDAC) { /* LDAC support */
2283 snd_ac97_determine_rates(ac97, AC97_PCM_LFE_DAC_RATE, AC97_PCM_FRONT_DAC_RATE, &ac97->rates[AC97_RATES_LFE_DAC]);
2284 ac97->scaps |= AC97_SCAP_CENTER_LFE_DAC;
2288 bus->ops->init(ac97);
2289 snd_ac97_get_name(ac97, ac97->id, name, sizeof(name), !ac97_is_audio(ac97));
2290 snd_ac97_get_name(NULL, ac97->id, name, sizeof(name), !ac97_is_audio(ac97)); // ac97->id might be changed in the special setup code
2291 if (! ac97->build_ops)
2292 ac97->build_ops = &null_build_ops;
2294 if (ac97_is_audio(ac97)) {
2304 sprintf(comp, "AC97a:%08x", ac97->id);
2307 snd_ac97_free(ac97);
2310 if (snd_ac97_mixer_build(ac97) < 0) {
2311 snd_ac97_free(ac97);
2315 if (ac97_is_modem(ac97)) {
2325 sprintf(comp, "AC97m:%08x", ac97->id);
2328 snd_ac97_free(ac97);
2331 if (snd_ac97_modem_build(card, ac97) < 0) {
2332 snd_ac97_free(ac97);
2336 if (ac97_is_audio(ac97))
2337 update_power_regs(ac97);
2338 snd_ac97_proc_init(ac97);
2339 err = snd_device_new(card, SNDRV_DEV_CODEC, ac97, &ops);
2341 snd_ac97_free(ac97);
2344 *rac97 = ac97;
2356 static void snd_ac97_powerdown(struct snd_ac97 *ac97)
2360 if (ac97_is_audio(ac97)) {
2362 snd_ac97_write(ac97, AC97_MASTER, 0x9f9f);
2363 snd_ac97_write(ac97, AC97_HEADPHONE, 0x9f9f);
2367 power = ac97->regs[AC97_EXTENDED_STATUS];
2368 if (ac97->scaps & AC97_SCAP_SURROUND_DAC)
2370 if (ac97->scaps & AC97_SCAP_CENTER_LFE_DAC)
2373 snd_ac97_write(ac97, AC97_EXTENDED_STATUS, power);
2376 if (ac97->scaps & AC97_SCAP_INV_EAPD)
2377 power = ac97->regs[AC97_POWERDOWN] & ~AC97_PD_EAPD;
2378 else if (! (ac97->scaps & AC97_SCAP_EAPD_LED))
2379 power = ac97->regs[AC97_POWERDOWN] | AC97_PD_EAPD;
2382 snd_ac97_write(ac97, AC97_POWERDOWN, power);
2385 snd_ac97_write(ac97, AC97_POWERDOWN, power);
2386 if (ac97_is_power_save_mode(ac97)) {
2388 snd_ac97_write(ac97, AC97_POWERDOWN, power);
2393 snd_ac97_write(ac97, AC97_POWERDOWN, power);
2420 * @ac97: the codec instance
2424 * Update the AC97 powerdown register bits of the given part.
2428 int snd_ac97_update_power(struct snd_ac97 *ac97, int reg, int powerup)
2432 if (! ac97)
2442 ac97->power_up |= (1 << i);
2444 ac97->power_up &= ~(1 << i);
2450 if (ac97_is_power_save_mode(ac97) && !powerup)
2455 schedule_delayed_work(&ac97->power_work, secs_to_jiffies(power_save));
2457 cancel_delayed_work(&ac97->power_work);
2458 update_power_regs(ac97);
2467 static void update_power_regs(struct snd_ac97 *ac97)
2474 if (ac97->scaps & AC97_SCAP_SURROUND_DAC)
2476 if (ac97->scaps & AC97_SCAP_CENTER_LFE_DAC)
2479 if (ac97_is_power_save_mode(ac97))
2480 power_up = ac97->power_up;
2483 if (ac97->regs[AC97_POWERDOWN] & AC97_PD_PR2) {
2485 snd_ac97_update_bits(ac97, AC97_POWERDOWN,
2488 snd_ac97_update_bits(ac97, AC97_POWERDOWN,
2497 snd_ac97_update_bits(ac97, power_regs[i].power_reg,
2501 if (! (ac97->regs[AC97_POWERDOWN] & AC97_PD_PR2)) {
2503 snd_ac97_update_bits(ac97, AC97_POWERDOWN,
2505 snd_ac97_update_bits(ac97, AC97_POWERDOWN,
2514 * snd_ac97_suspend - General suspend function for AC97 codec
2515 * @ac97: the ac97 instance
2519 void snd_ac97_suspend(struct snd_ac97 *ac97)
2521 if (! ac97)
2523 if (ac97->build_ops->suspend)
2524 ac97->build_ops->suspend(ac97);
2526 cancel_delayed_work_sync(&ac97->power_work);
2528 snd_ac97_powerdown(ac97);
2534 * restore ac97 status
2536 static void snd_ac97_restore_status(struct snd_ac97 *ac97)
2547 if (test_bit(i, ac97->reg_accessed)) {
2548 snd_ac97_write(ac97, i, ac97->regs[i]);
2549 snd_ac97_read(ac97, i);
2557 static void snd_ac97_restore_iec958(struct snd_ac97 *ac97)
2559 if (ac97->ext_id & AC97_EI_SPDIF) {
2560 if (ac97->regs[AC97_EXTENDED_STATUS] & AC97_EA_SPDIF) {
2562 snd_ac97_update_bits(ac97, AC97_EXTENDED_STATUS, AC97_EA_SPDIF, 0);
2563 snd_ac97_write(ac97, AC97_EXTENDED_STATUS, ac97->regs[AC97_EXTENDED_STATUS]);
2564 if (ac97->flags & AC97_CS_SPDIF)
2565 snd_ac97_write(ac97, AC97_CSR_SPDIF, ac97->regs[AC97_CSR_SPDIF]);
2567 snd_ac97_write(ac97, AC97_SPDIF, ac97->regs[AC97_SPDIF]);
2568 snd_ac97_update_bits(ac97, AC97_EXTENDED_STATUS, AC97_EA_SPDIF, AC97_EA_SPDIF); /* turn on again */
2574 * snd_ac97_resume - General resume function for AC97 codec
2575 * @ac97: the ac97 instance
2580 void snd_ac97_resume(struct snd_ac97 *ac97)
2584 if (! ac97)
2587 if (ac97->bus->ops->reset) {
2588 ac97->bus->ops->reset(ac97);
2592 snd_ac97_write(ac97, AC97_POWERDOWN, 0);
2593 if (! (ac97->flags & AC97_DEFAULT_POWER_OFF)) {
2594 if (!(ac97->scaps & AC97_SCAP_SKIP_AUDIO))
2595 snd_ac97_write(ac97, AC97_RESET, 0);
2596 else if (!(ac97->scaps & AC97_SCAP_SKIP_MODEM))
2597 snd_ac97_write(ac97, AC97_EXTENDED_MID, 0);
2599 snd_ac97_write(ac97, AC97_POWERDOWN, 0);
2601 snd_ac97_write(ac97, AC97_GENERAL_PURPOSE, 0);
2603 snd_ac97_write(ac97, AC97_POWERDOWN, ac97->regs[AC97_POWERDOWN]);
2604 if (ac97_is_audio(ac97)) {
2605 ac97->bus->ops->write(ac97, AC97_MASTER, 0x8101);
2608 if (snd_ac97_read(ac97, AC97_MASTER) == 0x8101)
2613 ac97->bus->ops->write(ac97, AC97_MASTER, AC97_MUTE_MASK_MONO);
2614 if (snd_ac97_read(ac97, AC97_MASTER) != AC97_MUTE_MASK_MONO)
2619 unsigned short val = snd_ac97_read(ac97, AC97_EXTENDED_MID);
2627 if (ac97->bus->ops->init)
2628 ac97->bus->ops->init(ac97);
2630 if (ac97->build_ops->resume)
2631 ac97->build_ops->resume(ac97);
2633 snd_ac97_restore_status(ac97);
2634 snd_ac97_restore_iec958(ac97);
2651 pr_warn("ALSA: AC97 control name '%s %s' truncated to '%s'\n",
2655 pr_warn("ALSA: AC97 control name '%s' truncated to '%s'\n",
2661 static int snd_ac97_remove_ctl(struct snd_ac97 *ac97, const char *name,
2668 return snd_ctl_remove_id(ac97->bus->card, &id);
2671 static struct snd_kcontrol *ctl_find(struct snd_ac97 *ac97, const char *name, const char *suffix)
2677 return snd_ctl_find_id(ac97->bus->card, &sid);
2681 static int snd_ac97_rename_ctl(struct snd_ac97 *ac97, const char *src,
2684 struct snd_kcontrol *kctl = ctl_find(ac97, src, suffix);
2689 snd_ctl_rename(ac97->bus->card, kctl, name);
2696 static void snd_ac97_rename_vol_ctl(struct snd_ac97 *ac97, const char *src,
2699 snd_ac97_rename_ctl(ac97, src, dst, "Switch");
2700 snd_ac97_rename_ctl(ac97, src, dst, "Volume");
2704 static int snd_ac97_swap_ctl(struct snd_ac97 *ac97, const char *s1,
2710 kctl1 = ctl_find(ac97, s1, suffix);
2711 kctl2 = ctl_find(ac97, s2, suffix);
2714 snd_ctl_rename(ac97->bus->card, kctl1, name);
2717 snd_ctl_rename(ac97->bus->card, kctl2, name);
2738 /* ac97 tune: bind Master and Headphone controls */
2739 static int tune_hp_only(struct snd_ac97 *ac97)
2741 struct snd_kcontrol *msw = ctl_find(ac97, "Master Playback Switch", NULL);
2742 struct snd_kcontrol *mvol = ctl_find(ac97, "Master Playback Volume", NULL);
2747 snd_ac97_remove_ctl(ac97, "Headphone Playback", "Switch");
2748 snd_ac97_remove_ctl(ac97, "Headphone Playback", "Volume");
2753 /* ac97 tune: use Headphone control as master */
2754 static int tune_hp_only(struct snd_ac97 *ac97)
2756 if (ctl_find(ac97, "Headphone Playback Switch", NULL) == NULL)
2758 snd_ac97_remove_ctl(ac97, "Master Playback", "Switch");
2759 snd_ac97_remove_ctl(ac97, "Master Playback", "Volume");
2760 snd_ac97_rename_vol_ctl(ac97, "Headphone Playback", "Master Playback");
2765 /* ac97 tune: swap Headphone and Master controls */
2766 static int tune_swap_hp(struct snd_ac97 *ac97)
2768 if (ctl_find(ac97, "Headphone Playback Switch", NULL) == NULL)
2770 snd_ac97_rename_vol_ctl(ac97, "Master Playback", "Line-Out Playback");
2771 snd_ac97_rename_vol_ctl(ac97, "Headphone Playback", "Master Playback");
2775 /* ac97 tune: swap Surround and Master controls */
2776 static int tune_swap_surround(struct snd_ac97 *ac97)
2778 if (snd_ac97_swap_ctl(ac97, "Master Playback", "Surround Playback", "Switch") ||
2779 snd_ac97_swap_ctl(ac97, "Master Playback", "Surround Playback", "Volume"))
2784 /* ac97 tune: set up mic sharing for AD codecs */
2785 static int tune_ad_sharing(struct snd_ac97 *ac97)
2788 if ((ac97->id & 0xffffff00) != 0x41445300) {
2789 ac97_err(ac97, "ac97_quirk AD_SHARING is only for AD codecs\n");
2793 scfg = snd_ac97_read(ac97, AC97_AD_SERIAL_CFG);
2794 snd_ac97_write_cache(ac97, AC97_AD_SERIAL_CFG, scfg | 0x0200);
2801 /* ac97 tune: set up ALC jack-select */
2802 static int tune_alc_jack(struct snd_ac97 *ac97)
2804 if ((ac97->id & 0xffffff00) != 0x414c4700) {
2805 ac97_err(ac97,
2809 snd_ac97_update_bits(ac97, 0x7a, 0x20, 0x20); /* select jack detect function */
2810 snd_ac97_update_bits(ac97, 0x7a, 0x01, 0x01); /* Line-out auto mute */
2811 if (ac97->id == AC97_ID_ALC658D)
2812 snd_ac97_update_bits(ac97, 0x74, 0x0800, 0x0800);
2813 return snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&snd_ac97_alc_jack_detect, ac97));
2816 /* ac97 tune: inversed EAPD bit */
2817 static int tune_inv_eapd(struct snd_ac97 *ac97)
2819 struct snd_kcontrol *kctl = ctl_find(ac97, "External Amplifier", NULL);
2822 set_inv_eapd(ac97, kctl);
2830 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
2838 snd_ac97_update_bits(ac97, AC97_POWERDOWN, AC97_PD_EAPD,
2839 (ac97->regs[AC97_MASTER] & mask) == mask ?
2845 /* ac97 tune: EAPD controls mute LED bound with the master mute */
2846 static int tune_mute_led(struct snd_ac97 *ac97)
2848 struct snd_kcontrol *msw = ctl_find(ac97, "Master Playback Switch", NULL);
2852 snd_ac97_remove_ctl(ac97, "External Amplifier", NULL);
2854 ac97, AC97_POWERDOWN,
2857 ac97->scaps |= AC97_SCAP_EAPD_LED;
2866 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
2874 snd_ac97_update_bits(ac97, AC97_POWERDOWN, AC97_PD_EAPD,
2875 (ac97->regs[AC97_MASTER] & mask) == mask ?
2881 static int tune_hp_mute_led(struct snd_ac97 *ac97)
2883 struct snd_kcontrol *msw = ctl_find(ac97, "Master Playback Switch", NULL);
2884 struct snd_kcontrol *mvol = ctl_find(ac97, "Master Playback Volume", NULL);
2889 snd_ac97_remove_ctl(ac97, "External Amplifier", NULL);
2890 snd_ac97_remove_ctl(ac97, "Headphone Playback", "Switch");
2891 snd_ac97_remove_ctl(ac97, "Headphone Playback", "Volume");
2893 ac97, AC97_POWERDOWN,
2917 static int apply_quirk(struct snd_ac97 *ac97, int type)
2924 return applicable_quirks[type].func(ac97);
2929 static int apply_quirk_str(struct snd_ac97 *ac97, const char *typestr)
2937 return apply_quirk(ac97, i);
2941 return apply_quirk(ac97, (int)simple_strtoul(typestr, NULL, 10));
2947 * @ac97: the ac97 instance
2958 int snd_ac97_tune_hardware(struct snd_ac97 *ac97,
2965 result = apply_quirk_str(ac97, override);
2967 ac97_err(ac97, "applying quirk type %s failed (%d)\n",
2976 if (quirk->subvendor != ac97->subsystem_vendor)
2978 if ((! quirk->mask && quirk->subdevice == ac97->subsystem_device) ||
2979 quirk->subdevice == (quirk->mask & ac97->subsystem_device)) {
2980 if (quirk->codec_id && quirk->codec_id != ac97->id)
2982 ac97_dbg(ac97, "ac97 quirk for %s (%04x:%04x)\n",
2983 quirk->name, ac97->subsystem_vendor,
2984 ac97->subsystem_device);
2985 result = apply_quirk(ac97, quirk->type);
2987 ac97_err(ac97,