• Home
  • History
  • Annotate
  • Raw
  • Download
  • only in /netgear-WNDR4500v2-V1.0.0.60_1.0.38/src/linux/linux-2.6/sound/pci/ac97/

Lines Matching refs:ac97

64 	int (*patch)(struct snd_ac97 *ac97);
65 int (*mpatch)(struct snd_ac97 *ac97);
197 static void update_power_regs(struct snd_ac97 *ac97);
199 #define ac97_is_power_save_mode(ac97) \
200 ((ac97->scaps & AC97_SCAP_POWER_SAVE) && power_save)
202 #define ac97_is_power_save_mode(ac97) 0
210 static int snd_ac97_valid_reg(struct snd_ac97 *ac97, unsigned short reg)
213 switch (ac97->id) {
250 * @ac97: the ac97 instance
260 void snd_ac97_write(struct snd_ac97 *ac97, unsigned short reg, unsigned short value)
262 if (!snd_ac97_valid_reg(ac97, reg))
264 if ((ac97->id & 0xffffff00) == AC97_ID_ALC100) {
267 ac97->bus->ops->write(ac97, AC97_RESET, 0); /* reset audio codec */
269 ac97->bus->ops->write(ac97, reg, value);
277 * @ac97: the ac97 instance
285 unsigned short snd_ac97_read(struct snd_ac97 *ac97, unsigned short reg)
287 if (!snd_ac97_valid_reg(ac97, reg))
289 return ac97->bus->ops->read(ac97, reg);
293 static inline unsigned short snd_ac97_read_cache(struct snd_ac97 *ac97, unsigned short reg)
295 if (! test_bit(reg, ac97->reg_accessed)) {
296 ac97->regs[reg] = ac97->bus->ops->read(ac97, reg);
297 // set_bit(reg, ac97->reg_accessed);
299 return ac97->regs[reg];
306 * @ac97: the ac97 instance
314 void snd_ac97_write_cache(struct snd_ac97 *ac97, unsigned short reg, unsigned short value)
316 if (!snd_ac97_valid_reg(ac97, reg))
318 mutex_lock(&ac97->reg_mutex);
319 ac97->regs[reg] = value;
320 ac97->bus->ops->write(ac97, reg, value);
321 set_bit(reg, ac97->reg_accessed);
322 mutex_unlock(&ac97->reg_mutex);
329 * @ac97: the ac97 instance
339 int snd_ac97_update(struct snd_ac97 *ac97, unsigned short reg, unsigned short value)
343 if (!snd_ac97_valid_reg(ac97, reg))
345 mutex_lock(&ac97->reg_mutex);
346 change = ac97->regs[reg] != value;
348 ac97->regs[reg] = value;
349 ac97->bus->ops->write(ac97, reg, value);
351 set_bit(reg, ac97->reg_accessed);
352 mutex_unlock(&ac97->reg_mutex);
360 * @ac97: the ac97 instance
371 int snd_ac97_update_bits(struct snd_ac97 *ac97, unsigned short reg, unsigned short mask, unsigned short value)
375 if (!snd_ac97_valid_reg(ac97, reg))
377 mutex_lock(&ac97->reg_mutex);
378 change = snd_ac97_update_bits_nolock(ac97, reg, mask, value);
379 mutex_unlock(&ac97->reg_mutex);
386 int snd_ac97_update_bits_nolock(struct snd_ac97 *ac97, unsigned short reg,
392 old = snd_ac97_read_cache(ac97, reg);
396 ac97->regs[reg] = new;
397 ac97->bus->ops->write(ac97, reg, new);
399 set_bit(reg, ac97->reg_accessed);
403 static int snd_ac97_ad18xx_update_pcm_bits(struct snd_ac97 *ac97, int codec, unsigned short mask, unsigned short value)
408 mutex_lock(&ac97->page_mutex);
409 old = ac97->spec.ad18xx.pcmreg[codec];
413 mutex_lock(&ac97->reg_mutex);
414 cfg = snd_ac97_read_cache(ac97, AC97_AD_SERIAL_CFG);
415 ac97->spec.ad18xx.pcmreg[codec] = new;
417 ac97->bus->ops->write(ac97, AC97_AD_SERIAL_CFG,
419 ac97->spec.ad18xx.unchained[codec] | ac97->spec.ad18xx.chained[codec]);
421 ac97->bus->ops->write(ac97, AC97_PCM, new);
423 ac97->bus->ops->write(ac97, AC97_AD_SERIAL_CFG,
425 mutex_unlock(&ac97->reg_mutex);
427 mutex_unlock(&ac97->page_mutex);
453 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
459 val = snd_ac97_read_cache(ac97, e->reg);
470 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
487 return snd_ac97_update_bits(ac97, e->reg, mask, val);
490 /* save/restore ac97 v2.3 paging */
491 static int snd_ac97_page_save(struct snd_ac97 *ac97, int reg, struct snd_kcontrol *kcontrol)
495 (ac97->ext_id & AC97_EI_REV_MASK) >= AC97_EI_REV_23 &&
498 mutex_lock(&ac97->page_mutex); /* lock paging */
499 page_save = snd_ac97_read(ac97, AC97_INT_PAGING) & AC97_PAGE_MASK;
500 snd_ac97_update_bits(ac97, AC97_INT_PAGING, AC97_PAGE_MASK, page);
505 static void snd_ac97_page_restore(struct snd_ac97 *ac97, int page_save)
508 snd_ac97_update_bits(ac97, AC97_INT_PAGING, AC97_PAGE_MASK, page_save);
509 mutex_unlock(&ac97->page_mutex); /* unlock paging */
531 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
539 page_save = snd_ac97_page_save(ac97, reg, kcontrol);
540 ucontrol->value.integer.value[0] = (snd_ac97_read_cache(ac97, reg) >> shift) & mask;
542 ucontrol->value.integer.value[1] = (snd_ac97_read_cache(ac97, reg) >> rshift) & mask;
548 snd_ac97_page_restore(ac97, page_save);
555 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
564 page_save = snd_ac97_page_save(ac97, reg, kcontrol);
577 err = snd_ac97_update_bits(ac97, reg, val_mask, val);
578 snd_ac97_page_restore(ac97, page_save);
584 ac97->power_up &= ~(1 << (reg>>1));
586 ac97->power_up |= 1 << (reg>>1);
587 update_power_regs(ac97);
679 static void set_inv_eapd(struct snd_ac97 *ac97, struct snd_kcontrol *kctl)
682 snd_ac97_update_bits(ac97, AC97_POWERDOWN, (1<<15), (1<<15)); /* EAPD up */
683 ac97->scaps |= AC97_SCAP_INV_EAPD;
716 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
718 mutex_lock(&ac97->reg_mutex);
719 ucontrol->value.iec958.status[0] = ac97->spdif_status & 0xff;
720 ucontrol->value.iec958.status[1] = (ac97->spdif_status >> 8) & 0xff;
721 ucontrol->value.iec958.status[2] = (ac97->spdif_status >> 16) & 0xff;
722 ucontrol->value.iec958.status[3] = (ac97->spdif_status >> 24) & 0xff;
723 mutex_unlock(&ac97->reg_mutex);
729 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
762 mutex_lock(&ac97->reg_mutex);
763 change = ac97->spdif_status != new;
764 ac97->spdif_status = new;
766 if (ac97->flags & AC97_CS_SPDIF) {
773 change |= snd_ac97_update_bits_nolock(ac97, AC97_CSR_SPDIF, 0x3fff, ((val & 0xcfff) | (x << 12)));
774 } else if (ac97->flags & AC97_CX_SPDIF) {
778 change |= snd_ac97_update_bits_nolock(ac97, AC97_CXR_AUDIO_MISC,
782 unsigned short extst = snd_ac97_read_cache(ac97, AC97_EXTENDED_STATUS);
783 snd_ac97_update_bits_nolock(ac97, AC97_EXTENDED_STATUS, AC97_EA_SPDIF, 0); /* turn off */
785 change |= snd_ac97_update_bits_nolock(ac97, AC97_SPDIF, 0x3fff, val);
787 snd_ac97_update_bits_nolock(ac97, AC97_EXTENDED_STATUS, AC97_EA_SPDIF, AC97_EA_SPDIF); /* turn on again */
790 mutex_unlock(&ac97->reg_mutex);
797 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
807 mutex_lock(&ac97->reg_mutex);
810 old = snd_ac97_read_cache(ac97, reg);
815 unsigned short extst = snd_ac97_read_cache(ac97, AC97_EXTENDED_STATUS);
816 snd_ac97_update_bits_nolock(ac97, AC97_EXTENDED_STATUS, AC97_EA_SPDIF, 0); /* turn off */
817 change = snd_ac97_update_bits_nolock(ac97, reg, mask, value);
819 snd_ac97_update_bits_nolock(ac97, AC97_EXTENDED_STATUS, AC97_EA_SPDIF, AC97_EA_SPDIF); /* turn on again */
821 mutex_unlock(&ac97->reg_mutex);
866 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
872 if (lshift != rshift && (ac97->flags & AC97_STEREO_MUTES))
883 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
889 ucontrol->value.integer.value[0] = mask - ((ac97->spec.ad18xx.pcmreg[codec] >> lshift) & mask);
890 if (lshift != rshift && (ac97->flags & AC97_STEREO_MUTES))
891 ucontrol->value.integer.value[1] = mask - ((ac97->spec.ad18xx.pcmreg[codec] >> rshift) & mask);
897 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
906 if (lshift != rshift && (ac97->flags & AC97_STEREO_MUTES)) {
910 return snd_ac97_ad18xx_update_pcm_bits(ac97, codec, valmask, val);
929 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
932 mutex_lock(&ac97->page_mutex);
933 ucontrol->value.integer.value[0] = 31 - ((ac97->spec.ad18xx.pcmreg[codec] >> 0) & 31);
934 ucontrol->value.integer.value[1] = 31 - ((ac97->spec.ad18xx.pcmreg[codec] >> 8) & 31);
935 mutex_unlock(&ac97->page_mutex);
941 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
947 return snd_ac97_ad18xx_update_pcm_bits(ac97, codec, 0x1f1f, (val1 << 8) | val2);
974 static void snd_ac97_powerdown(struct snd_ac97 *ac97);
994 static int snd_ac97_free(struct snd_ac97 *ac97)
996 if (ac97) {
998 cancel_delayed_work(&ac97->power_work);
1001 snd_ac97_proc_done(ac97);
1002 if (ac97->bus)
1003 ac97->bus->codec[ac97->num] = NULL;
1004 if (ac97->private_free)
1005 ac97->private_free(ac97);
1006 kfree(ac97);
1013 struct snd_ac97 *ac97 = device->device_data;
1014 snd_ac97_powerdown(ac97); /* for avoiding click noises during shut down */
1015 return snd_ac97_free(ac97);
1018 static int snd_ac97_try_volume_mix(struct snd_ac97 * ac97, int reg)
1022 if (! snd_ac97_valid_reg(ac97, reg))
1027 return ac97->caps & 0x04 ? 1 : 0;
1029 return ac97->caps & 0x10 ? 1 : 0;
1031 return ac97->caps & 0x01 ? 1 : 0;
1033 if (ac97->caps & 0x7c00) {
1034 val = snd_ac97_read(ac97, reg);
1040 if ((ac97->ext_id & AC97_EI_CDAC) == 0)
1044 if ((ac97->ext_id & AC97_EI_LDAC) == 0)
1050 if ((ac97->ext_id & AC97_EI_SDAC) == 0)
1055 val = snd_ac97_read(ac97, reg);
1059 snd_ac97_write_cache(ac97, reg, val | mask);
1060 val = snd_ac97_read(ac97, reg);
1061 val = snd_ac97_read(ac97, reg);
1068 static void check_volume_resolution(struct snd_ac97 *ac97, int reg, unsigned char *lo_max, unsigned char *hi_max)
1075 if (ac97->res_table) {
1077 for (tbl = ac97->res_table; tbl->reg; tbl++) {
1089 snd_ac97_write(ac97, reg, 0x8080 | cbit[i] | (cbit[i] << 8));
1090 /* Do the read twice due to buffers on some ac97 codecs.
1094 val = snd_ac97_read(ac97, reg);
1095 val = snd_ac97_read(ac97, reg);
1105 static int snd_ac97_try_bit(struct snd_ac97 * ac97, int reg, int bit)
1110 orig = snd_ac97_read(ac97, reg);
1112 snd_ac97_write(ac97, reg, val);
1113 res = snd_ac97_read(ac97, reg);
1114 snd_ac97_write_cache(ac97, reg, orig);
1119 static void snd_ac97_change_volume_params2(struct snd_ac97 * ac97, int reg, int shift, unsigned char *max)
1125 snd_ac97_write(ac97, reg, val);
1126 val1 = snd_ac97_read(ac97, reg);
1131 snd_ac97_write_cache(ac97, reg, 0x8080);
1146 struct snd_ac97 * ac97)
1150 template.index = ac97->num;
1151 return snd_ctl_new1(&template, ac97);
1159 struct snd_ac97 *ac97)
1165 if (! snd_ac97_valid_reg(ac97, reg))
1169 val = snd_ac97_read(ac97, reg);
1170 if (check_stereo || (ac97->flags & AC97_STEREO_MUTES)) {
1173 snd_ac97_write(ac97, reg, val1);
1174 if (val1 == snd_ac97_read(ac97, reg))
1181 tmp.index = ac97->num;
1182 kctl = snd_ctl_new1(&tmp, ac97);
1187 tmp.index = ac97->num;
1188 kctl = snd_ctl_new1(&tmp, ac97);
1194 snd_ac97_write_cache(ac97, reg, val | mute_mask);
1228 unsigned int hi_max, struct snd_ac97 *ac97)
1233 if (! snd_ac97_valid_reg(ac97, reg))
1238 tmp.index = ac97->num;
1239 kctl = snd_ctl_new1(&tmp, ac97);
1243 tmp.index = ac97->num;
1244 kctl = snd_ctl_new1(&tmp, ac97);
1253 snd_ac97_write_cache(ac97, reg,
1254 (snd_ac97_read(ac97, reg) & 0x8080) |
1264 struct snd_ac97 *ac97)
1270 if (! snd_ac97_valid_reg(ac97, reg))
1273 if (snd_ac97_try_bit(ac97, reg, 15)) {
1277 ac97)) < 0)
1280 check_volume_resolution(ac97, reg, &lo_max, &hi_max);
1283 if ((err = snd_ac97_cvol_new(card, name, reg, lo_max, hi_max, ac97)) < 0)
1289 #define snd_ac97_cmix_new(card, pfx, reg, acheck, ac97) \
1290 snd_ac97_cmix_new_stereo(card, pfx, reg, 0, acheck, ac97)
1291 #define snd_ac97_cmute_new(card, name, reg, acheck, ac97) \
1292 snd_ac97_cmute_new_stereo(card, name, reg, 0, acheck, ac97)
1294 static unsigned int snd_ac97_determine_spdif_rates(struct snd_ac97 *ac97);
1296 static int snd_ac97_mixer_build(struct snd_ac97 * ac97)
1298 struct snd_card *card = ac97->bus->card;
1306 if (snd_ac97_try_volume_mix(ac97, AC97_MASTER)) {
1307 if (ac97->flags & AC97_HAS_NO_MASTER_VOL)
1309 AC97_MASTER, 0, ac97);
1312 AC97_MASTER, 0, ac97);
1317 ac97->regs[AC97_CENTER_LFE_MASTER] = 0x8080;
1320 if ((snd_ac97_try_volume_mix(ac97, AC97_CENTER_LFE_MASTER))
1321 && !(ac97->flags & AC97_AD_MULTI)) {
1322 if ((err = snd_ctl_add(card, snd_ac97_cnew(&snd_ac97_controls_center[0], ac97))) < 0)
1324 if ((err = snd_ctl_add(card, kctl = snd_ac97_cnew(&snd_ac97_controls_center[1], ac97))) < 0)
1326 snd_ac97_change_volume_params2(ac97, AC97_CENTER_LFE_MASTER, 0, &max);
1330 snd_ac97_write_cache(ac97, AC97_CENTER_LFE_MASTER, ac97->regs[AC97_CENTER_LFE_MASTER] | max);
1334 if ((snd_ac97_try_volume_mix(ac97, AC97_CENTER_LFE_MASTER+1))
1335 && !(ac97->flags & AC97_AD_MULTI)) {
1336 if ((err = snd_ctl_add(card, snd_ac97_cnew(&snd_ac97_controls_lfe[0], ac97))) < 0)
1338 if ((err = snd_ctl_add(card, kctl = snd_ac97_cnew(&snd_ac97_controls_lfe[1], ac97))) < 0)
1340 snd_ac97_change_volume_params2(ac97, AC97_CENTER_LFE_MASTER, 8, &max);
1344 snd_ac97_write_cache(ac97, AC97_CENTER_LFE_MASTER, ac97->regs[AC97_CENTER_LFE_MASTER] | max << 8);
1348 if ((snd_ac97_try_volume_mix(ac97, AC97_SURROUND_MASTER))
1349 && !(ac97->flags & AC97_AD_MULTI)) {
1353 ac97)) < 0)
1358 if (snd_ac97_try_volume_mix(ac97, AC97_HEADPHONE)) {
1360 AC97_HEADPHONE, 0, ac97)) < 0)
1365 if (snd_ac97_try_volume_mix(ac97, AC97_MASTER_MONO)) {
1367 AC97_MASTER_MONO, 0, ac97)) < 0)
1372 if (!(ac97->flags & AC97_HAS_NO_TONE)) {
1373 if (snd_ac97_try_volume_mix(ac97, AC97_MASTER_TONE)) {
1375 if ((err = snd_ctl_add(card, kctl = snd_ac97_cnew(&snd_ac97_controls_tone[idx], ac97))) < 0)
1377 if (ac97->id == AC97_ID_YMF753) {
1382 snd_ac97_write_cache(ac97, AC97_MASTER_TONE, 0x0f0f);
1387 if (!(ac97->flags & AC97_HAS_NO_PC_BEEP) &&
1388 ((ac97->flags & AC97_HAS_PC_BEEP) ||
1389 snd_ac97_try_volume_mix(ac97, AC97_PC_BEEP))) {
1391 if ((err = snd_ctl_add(card, kctl = snd_ac97_cnew(&snd_ac97_controls_pc_beep[idx], ac97))) < 0)
1394 snd_ac97_write_cache(ac97, AC97_PC_BEEP,
1395 snd_ac97_read(ac97, AC97_PC_BEEP) | 0x801e);
1399 if (!(ac97->flags & AC97_HAS_NO_PHONE)) {
1400 if (snd_ac97_try_volume_mix(ac97, AC97_PHONE)) {
1402 AC97_PHONE, 1, ac97)) < 0)
1408 if (!(ac97->flags & AC97_HAS_NO_MIC)) {
1409 if (snd_ac97_try_volume_mix(ac97, AC97_MIC)) {
1411 AC97_MIC, 1, ac97)) < 0)
1413 if ((err = snd_ctl_add(card, snd_ac97_cnew(&snd_ac97_controls_mic_boost, ac97))) < 0)
1419 if (snd_ac97_try_volume_mix(ac97, AC97_LINE)) {
1421 AC97_LINE, 1, ac97)) < 0)
1426 if (!(ac97->flags & AC97_HAS_NO_CD)) {
1427 if (snd_ac97_try_volume_mix(ac97, AC97_CD)) {
1429 AC97_CD, 1, ac97)) < 0)
1435 if (!(ac97->flags & AC97_HAS_NO_VIDEO)) {
1436 if (snd_ac97_try_volume_mix(ac97, AC97_VIDEO)) {
1438 AC97_VIDEO, 1, ac97)) < 0)
1444 if (!(ac97->flags & AC97_HAS_NO_AUX)) {
1445 if (snd_ac97_try_volume_mix(ac97, AC97_AUX)) {
1447 AC97_AUX, 1, ac97)) < 0)
1453 if (ac97->flags & AC97_AD_MULTI) {
1455 if (ac97->flags & AC97_STEREO_MUTES)
1460 if ((err = snd_ctl_add(card, kctl = snd_ac97_cnew(&snd_ac97_controls_ad18xx_pcm[idx], ac97))) < 0)
1463 ac97->spec.ad18xx.pcmreg[0] = init_val;
1464 if (ac97->scaps & AC97_SCAP_SURROUND_DAC) {
1466 if ((err = snd_ctl_add(card, kctl = snd_ac97_cnew(&snd_ac97_controls_ad18xx_surround[idx], ac97))) < 0)
1469 ac97->spec.ad18xx.pcmreg[1] = init_val;
1471 if (ac97->scaps & AC97_SCAP_CENTER_LFE_DAC) {
1473 if ((err = snd_ctl_add(card, kctl = snd_ac97_cnew(&snd_ac97_controls_ad18xx_center[idx], ac97))) < 0)
1477 if ((err = snd_ctl_add(card, kctl = snd_ac97_cnew(&snd_ac97_controls_ad18xx_lfe[idx], ac97))) < 0)
1480 ac97->spec.ad18xx.pcmreg[2] = init_val;
1482 snd_ac97_write_cache(ac97, AC97_PCM, init_val);
1484 if (!(ac97->flags & AC97_HAS_NO_STD_PCM)) {
1485 if (ac97->flags & AC97_HAS_NO_PCM_VOL)
1488 AC97_PCM, 0, ac97);
1491 AC97_PCM, 0, ac97);
1498 if (!(ac97->flags & AC97_HAS_NO_REC_GAIN)) {
1499 if ((err = snd_ctl_add(card, snd_ac97_cnew(&snd_ac97_control_capture_src, ac97))) < 0)
1501 if (snd_ac97_try_bit(ac97, AC97_REC_GAIN, 15)) {
1503 AC97_REC_GAIN, 0, ac97);
1507 if ((err = snd_ctl_add(card, kctl = snd_ac97_cnew(&snd_ac97_control_capture_vol, ac97))) < 0)
1510 snd_ac97_write_cache(ac97, AC97_REC_SEL, 0x0000);
1511 snd_ac97_write_cache(ac97, AC97_REC_GAIN, 0x0000);
1514 if (snd_ac97_try_volume_mix(ac97, AC97_REC_GAIN_MIC)) {
1516 if ((err = snd_ctl_add(card, kctl = snd_ac97_cnew(&snd_ac97_controls_mic_capture[idx], ac97))) < 0)
1519 snd_ac97_write_cache(ac97, AC97_REC_GAIN_MIC, 0x0000);
1523 if (snd_ac97_try_bit(ac97, AC97_GENERAL_PURPOSE, 15)) {
1524 if ((err = snd_ctl_add(card, snd_ac97_cnew(&snd_ac97_controls_general[AC97_GENERAL_PCM_OUT], ac97))) < 0)
1529 if (ac97->caps & 0x0008) {
1530 if ((err = snd_ctl_add(card, snd_ac97_cnew(&snd_ac97_controls_general[AC97_GENERAL_STEREO_ENHANCEMENT], ac97))) < 0)
1535 if (snd_ac97_try_bit(ac97, AC97_GENERAL_PURPOSE, 13)) {
1536 if ((err = snd_ctl_add(card, snd_ac97_cnew(&snd_ac97_controls_general[AC97_GENERAL_3D], ac97))) < 0)
1541 if (ac97->caps & 0x0020) {
1542 if ((err = snd_ctl_add(card, snd_ac97_cnew(&snd_ac97_controls_general[AC97_GENERAL_LOUDNESS], ac97))) < 0)
1547 if (snd_ac97_try_bit(ac97, AC97_GENERAL_PURPOSE, 9)) {
1548 if ((err = snd_ctl_add(card, snd_ac97_cnew(&snd_ac97_controls_general[AC97_GENERAL_MONO], ac97))) < 0)
1553 if (snd_ac97_try_bit(ac97, AC97_GENERAL_PURPOSE, 8)) {
1554 if ((err = snd_ctl_add(card, snd_ac97_cnew(&snd_ac97_controls_general[AC97_GENERAL_MIC], ac97))) < 0)
1559 if (enable_loopback && snd_ac97_try_bit(ac97, AC97_GENERAL_PURPOSE, 7)) {
1560 if ((err = snd_ctl_add(card, snd_ac97_cnew(&snd_ac97_controls_general[AC97_GENERAL_LOOPBACK], ac97))) < 0)
1564 snd_ac97_update_bits(ac97, AC97_GENERAL_PURPOSE, ~AC97_GP_DRSS_MASK, 0x0000);
1567 if (ac97->build_ops->build_3d) {
1568 ac97->build_ops->build_3d(ac97);
1570 if (snd_ac97_try_volume_mix(ac97, AC97_3D_CONTROL)) {
1573 snd_ac97_write(ac97, AC97_3D_CONTROL, val);
1574 val = snd_ac97_read(ac97, AC97_3D_CONTROL);
1576 if ((err = snd_ctl_add(card, kctl = snd_ac97_cnew(&snd_ac97_controls_3d[0], ac97))) < 0)
1580 if ((err = snd_ctl_add(card, kctl = snd_ac97_cnew(&snd_ac97_controls_3d[1], ac97))) < 0)
1584 snd_ac97_write_cache(ac97, AC97_3D_CONTROL, 0x0000);
1591 if (ac97->subsystem_vendor == 0x1043 &&
1592 ac97->subsystem_device == 0x810f)
1593 ac97->ext_id |= AC97_EI_SPDIF;
1595 if ((ac97->ext_id & AC97_EI_SPDIF) && !(ac97->scaps & AC97_SCAP_NO_SPDIF)) {
1596 if (ac97->build_ops->build_spdif) {
1597 if ((err = ac97->build_ops->build_spdif(ac97)) < 0)
1601 if ((err = snd_ctl_add(card, snd_ac97_cnew(&snd_ac97_controls_spdif[idx], ac97))) < 0)
1603 if (ac97->build_ops->build_post_spdif) {
1604 if ((err = ac97->build_ops->build_post_spdif(ac97)) < 0)
1609 snd_ac97_write_cache(ac97, AC97_SPDIF, 0x2a20);
1610 ac97->rates[AC97_RATES_SPDIF] = snd_ac97_determine_spdif_rates(ac97);
1612 ac97->spdif_status = SNDRV_PCM_DEFAULT_CON_SPDIF;
1616 if (ac97->build_ops->build_specific)
1617 if ((err = ac97->build_ops->build_specific(ac97)) < 0)
1620 if (snd_ac97_try_bit(ac97, AC97_POWERDOWN, 15)) {
1621 kctl = snd_ac97_cnew(&snd_ac97_control_eapd, ac97);
1624 if (ac97->scaps & AC97_SCAP_INV_EAPD)
1625 set_inv_eapd(ac97, kctl);
1633 static int snd_ac97_modem_build(struct snd_card *card, struct snd_ac97 * ac97)
1637 //printk("AC97_GPIO_CFG = %x\n",snd_ac97_read(ac97,AC97_GPIO_CFG));
1638 snd_ac97_write(ac97, AC97_GPIO_CFG, 0xffff & ~(AC97_GPIO_LINE1_OH));
1639 snd_ac97_write(ac97, AC97_GPIO_POLARITY, 0xffff & ~(AC97_GPIO_LINE1_OH));
1640 snd_ac97_write(ac97, AC97_GPIO_STICKY, 0xffff);
1641 snd_ac97_write(ac97, AC97_GPIO_WAKEUP, 0x0);
1642 snd_ac97_write(ac97, AC97_MISC_AFE, 0x0);
1646 if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_ac97_controls_modem_switches[idx], ac97))) < 0)
1650 if (ac97->build_ops->build_specific)
1651 if ((err = ac97->build_ops->build_specific(ac97)) < 0)
1657 static int snd_ac97_test_rate(struct snd_ac97 *ac97, int reg, int shadow_reg, int rate)
1662 tmp = ((unsigned int)rate * ac97->bus->clock) / 48000;
1663 snd_ac97_write_cache(ac97, reg, tmp & 0xffff);
1665 snd_ac97_write_cache(ac97, shadow_reg, tmp & 0xffff);
1666 val = snd_ac97_read(ac97, reg);
1670 static void snd_ac97_determine_rates(struct snd_ac97 *ac97, int reg, int shadow_reg, unsigned int *r_result)
1675 if (ac97->bus->no_vra) {
1677 if ((ac97->flags & AC97_DOUBLE_RATE) &&
1683 saved = snd_ac97_read(ac97, reg);
1684 if ((ac97->ext_id & AC97_EI_DRA) && reg == AC97_PCM_FRONT_DAC_RATE)
1685 snd_ac97_update_bits(ac97, AC97_EXTENDED_STATUS,
1688 if (snd_ac97_test_rate(ac97, reg, shadow_reg, 11000))
1691 if (snd_ac97_test_rate(ac97, reg, shadow_reg, 8000))
1693 if (snd_ac97_test_rate(ac97, reg, shadow_reg, 11025))
1695 if (snd_ac97_test_rate(ac97, reg, shadow_reg, 16000))
1697 if (snd_ac97_test_rate(ac97, reg, shadow_reg, 22050))
1699 if (snd_ac97_test_rate(ac97, reg, shadow_reg, 32000))
1701 if (snd_ac97_test_rate(ac97, reg, shadow_reg, 44100))
1703 if (snd_ac97_test_rate(ac97, reg, shadow_reg, 48000))
1705 if ((ac97->flags & AC97_DOUBLE_RATE) &&
1708 snd_ac97_update_bits(ac97, AC97_EXTENDED_STATUS,
1710 if (snd_ac97_test_rate(ac97, reg, shadow_reg, 64000 / 2))
1712 if (snd_ac97_test_rate(ac97, reg, shadow_reg, 88200 / 2))
1714 if (snd_ac97_test_rate(ac97, reg, shadow_reg, 96000 / 2))
1717 if (!snd_ac97_test_rate(ac97, reg, shadow_reg, 76100 / 2))
1719 snd_ac97_update_bits(ac97, AC97_EXTENDED_STATUS,
1723 snd_ac97_write_cache(ac97, reg, saved);
1725 snd_ac97_write_cache(ac97, shadow_reg, saved);
1730 static unsigned int snd_ac97_determine_spdif_rates(struct snd_ac97 *ac97)
1742 snd_ac97_update_bits(ac97, AC97_SPDIF, AC97_SC_SPSR_MASK, ctl_bits[i]);
1743 if ((snd_ac97_read(ac97, AC97_SPDIF) & AC97_SC_SPSR_MASK) == ctl_bits[i])
1761 void snd_ac97_get_name(struct snd_ac97 *ac97, unsigned int id, char *name, int modem)
1774 if (ac97 && pid->patch) {
1777 pid->patch(ac97);
1786 if (ac97 && pid->patch) {
1789 pid->patch(ac97);
1797 * @ac97: the codec instance
1801 const char *snd_ac97_get_short_name(struct snd_ac97 *ac97)
1806 if (pid->id == (ac97->id & pid->mask))
1816 static int ac97_reset_wait(struct snd_ac97 *ac97, int timeout, int with_modem)
1825 snd_ac97_read(ac97, AC97_RESET);
1826 snd_ac97_read(ac97, AC97_VENDOR_ID1);
1827 snd_ac97_read(ac97, AC97_VENDOR_ID2);
1830 val = snd_ac97_read(ac97, AC97_EXTENDED_MID);
1834 if (ac97->scaps & AC97_SCAP_DETECT_BY_VENDOR) {
1836 val = snd_ac97_read(ac97, AC97_VENDOR_ID1);
1844 snd_ac97_write_cache(ac97, AC97_REC_GAIN, 0x8a05);
1845 if ((snd_ac97_read(ac97, AC97_REC_GAIN) & 0x7fff) == 0x0a05)
1911 /* register ac97 codec to bus */
1914 struct snd_ac97 *ac97 = device->device_data;
1917 ac97->dev.bus = &ac97_bus_type;
1918 ac97->dev.parent = ac97->bus->card->dev;
1919 ac97->dev.release = ac97_device_release;
1920 snprintf(ac97->dev.bus_id, BUS_ID_SIZE, "%d-%d:%s",
1921 ac97->bus->card->number, ac97->num,
1922 snd_ac97_get_short_name(ac97));
1923 if ((err = device_register(&ac97->dev)) < 0) {
1924 snd_printk(KERN_ERR "Can't register ac97 bus\n");
1925 ac97->dev.bus = NULL;
1931 /* disconnect ac97 codec */
1934 struct snd_ac97 *ac97 = device->device_data;
1935 if (ac97->dev.bus)
1936 device_unregister(&ac97->dev);
1954 * @template: the template of ac97, including index, callbacks and
1956 * @rac97: the pointer to store the new ac97 instance.
1965 * The ac97 instance is registered as a low-level device, so you don't
1973 struct snd_ac97 *ac97;
1991 ac97 = kzalloc(sizeof(*ac97), GFP_KERNEL);
1992 if (ac97 == NULL)
1994 ac97->private_data = template->private_data;
1995 ac97->private_free = template->private_free;
1996 ac97->bus = bus;
1997 ac97->pci = template->pci;
1998 ac97->num = template->num;
1999 ac97->addr = template->addr;
2000 ac97->scaps = template->scaps;
2001 ac97->res_table = template->res_table;
2002 bus->codec[ac97->num] = ac97;
2003 mutex_init(&ac97->reg_mutex);
2004 mutex_init(&ac97->page_mutex);
2006 INIT_DELAYED_WORK(&ac97->power_work, do_update_power);
2010 if (ac97->pci) {
2011 pci_read_config_word(ac97->pci, PCI_SUBSYSTEM_VENDOR_ID, &ac97->subsystem_vendor);
2012 pci_read_config_word(ac97->pci, PCI_SUBSYSTEM_ID, &ac97->subsystem_device);
2016 bus->ops->reset(ac97);
2020 ac97->id = snd_ac97_read(ac97, AC97_VENDOR_ID1) << 16;
2021 ac97->id |= snd_ac97_read(ac97, AC97_VENDOR_ID2);
2022 if (ac97->id && ac97->id != (unsigned int)-1) {
2023 pid = look_for_codec_id(snd_ac97_codec_ids, ac97->id);
2029 if (!(ac97->scaps & AC97_SCAP_SKIP_AUDIO))
2030 snd_ac97_write(ac97, AC97_RESET, 0);
2031 if (!(ac97->scaps & AC97_SCAP_SKIP_MODEM))
2032 snd_ac97_write(ac97, AC97_EXTENDED_MID, 0);
2034 bus->ops->wait(ac97);
2037 if (ac97->scaps & AC97_SCAP_SKIP_AUDIO)
2038 err = ac97_reset_wait(ac97, HZ/2, 1);
2040 err = ac97_reset_wait(ac97, HZ/2, 0);
2042 err = ac97_reset_wait(ac97, HZ/2, 1);
2045 snd_printk(KERN_WARNING "AC'97 %d does not respond - RESET\n", ac97->num);
2050 ac97->id = snd_ac97_read(ac97, AC97_VENDOR_ID1) << 16;
2051 ac97->id |= snd_ac97_read(ac97, AC97_VENDOR_ID2);
2052 if (! (ac97->scaps & AC97_SCAP_DETECT_BY_VENDOR) &&
2053 (ac97->id == 0x00000000 || ac97->id == 0xffffffff)) {
2054 snd_printk(KERN_ERR "AC'97 %d access is not valid [0x%x], removing mixer.\n", ac97->num, ac97->id);
2055 snd_ac97_free(ac97);
2058 pid = look_for_codec_id(snd_ac97_codec_ids, ac97->id);
2060 ac97->flags |= pid->flags;
2063 if (!(ac97->scaps & AC97_SCAP_SKIP_AUDIO) && !(ac97->scaps & AC97_SCAP_AUDIO)) {
2065 snd_ac97_write_cache(ac97, AC97_REC_GAIN, 0x8a06);
2066 if (((err = snd_ac97_read(ac97, AC97_REC_GAIN)) & 0x7fff) == 0x0a06)
2067 ac97->scaps |= AC97_SCAP_AUDIO;
2069 if (ac97->scaps & AC97_SCAP_AUDIO) {
2070 ac97->caps = snd_ac97_read(ac97, AC97_RESET);
2071 ac97->ext_id = snd_ac97_read(ac97, AC97_EXTENDED_ID);
2072 if (ac97->ext_id == 0xffff) /* invalid combination */
2073 ac97->ext_id = 0;
2077 if (!(ac97->scaps & AC97_SCAP_SKIP_MODEM) && !(ac97->scaps & AC97_SCAP_MODEM)) {
2078 ac97->ext_mid = snd_ac97_read(ac97, AC97_EXTENDED_MID);
2079 if (ac97->ext_mid == 0xffff) /* invalid combination */
2080 ac97->ext_mid = 0;
2081 if (ac97->ext_mid & 1)
2082 ac97->scaps |= AC97_SCAP_MODEM;
2085 if (!ac97_is_audio(ac97) && !ac97_is_modem(ac97)) {
2086 if (!(ac97->scaps & (AC97_SCAP_SKIP_AUDIO|AC97_SCAP_SKIP_MODEM)))
2087 snd_printk(KERN_ERR "AC'97 %d access error (not audio or modem codec)\n", ac97->num);
2088 snd_ac97_free(ac97);
2095 if (ac97_is_audio(ac97)) {
2097 snd_ac97_write_cache(ac97, AC97_POWERDOWN, 0);
2098 if (! (ac97->flags & AC97_DEFAULT_POWER_OFF)) {
2099 snd_ac97_write_cache(ac97, AC97_RESET, 0); /* reset to defaults */
2101 snd_ac97_write_cache(ac97, AC97_POWERDOWN, 0);
2104 snd_ac97_write_cache(ac97, AC97_GENERAL_PURPOSE, 0);
2107 if ((snd_ac97_read(ac97, AC97_POWERDOWN) & 0x0f) == 0x0f)
2111 snd_printk(KERN_WARNING "AC'97 %d analog subsections not ready\n", ac97->num);
2114 if (ac97_is_modem(ac97)) {
2120 if (ac97->ext_mid & AC97_MEI_LINE1) {
2121 snd_ac97_write_cache(ac97, AC97_LINE1_RATE, 8000);
2124 if (ac97->ext_mid & AC97_MEI_LINE2) {
2125 snd_ac97_write_cache(ac97, AC97_LINE2_RATE, 8000);
2128 if (ac97->ext_mid & AC97_MEI_HANDSET) {
2129 snd_ac97_write_cache(ac97, AC97_HANDSET_RATE, 8000);
2132 snd_ac97_write_cache(ac97, AC97_EXTENDED_MSTATUS, 0);
2135 snd_ac97_write_cache(ac97, AC97_EXTENDED_MSTATUS, 0);
2138 if ((snd_ac97_read(ac97, AC97_EXTENDED_MSTATUS) & tmp) == tmp)
2142 snd_printk(KERN_WARNING "MC'97 %d converters and GPIO not ready (0x%x)\n", ac97->num, snd_ac97_read(ac97, AC97_EXTENDED_MSTATUS));
2146 if (ac97_is_audio(ac97))
2147 ac97->addr = (ac97->ext_id & AC97_EI_ADDR_MASK) >> AC97_EI_ADDR_SHIFT;
2149 ac97->addr = (ac97->ext_mid & AC97_MEI_ADDR_MASK) >> AC97_MEI_ADDR_SHIFT;
2150 if (ac97->ext_id & 0x01c9) { /* L/R, MIC, SDAC, LDAC VRA support */
2151 reg = snd_ac97_read(ac97, AC97_EXTENDED_STATUS);
2152 reg |= ac97->ext_id & 0x01c0; /* LDAC/SDAC/CDAC */
2154 reg |= ac97->ext_id & 0x0009; /* VRA/VRM */
2155 snd_ac97_write_cache(ac97, AC97_EXTENDED_STATUS, reg);
2157 if ((ac97->ext_id & AC97_EI_DRA) && bus->dra) {
2160 snd_ac97_update_bits(ac97, AC97_GENERAL_PURPOSE, AC97_GP_DRSS_MASK, AC97_GP_DRSS_78);
2161 if ((snd_ac97_read(ac97, AC97_GENERAL_PURPOSE) & AC97_GP_DRSS_MASK) == AC97_GP_DRSS_78)
2162 ac97->flags |= AC97_DOUBLE_RATE;
2164 snd_ac97_update_bits(ac97, AC97_GENERAL_PURPOSE, AC97_GP_DRSS_MASK, 0);
2166 if (ac97->ext_id & AC97_EI_VRA) { /* VRA support */
2167 snd_ac97_determine_rates(ac97, AC97_PCM_FRONT_DAC_RATE, 0, &ac97->rates[AC97_RATES_FRONT_DAC]);
2168 snd_ac97_determine_rates(ac97, AC97_PCM_LR_ADC_RATE, 0, &ac97->rates[AC97_RATES_ADC]);
2170 ac97->rates[AC97_RATES_FRONT_DAC] = SNDRV_PCM_RATE_48000;
2171 if (ac97->flags & AC97_DOUBLE_RATE)
2172 ac97->rates[AC97_RATES_FRONT_DAC] |= SNDRV_PCM_RATE_96000;
2173 ac97->rates[AC97_RATES_ADC] = SNDRV_PCM_RATE_48000;
2175 if (ac97->ext_id & AC97_EI_SPDIF) {
2177 ac97->rates[AC97_RATES_SPDIF] = SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_32000;
2179 if (ac97->ext_id & AC97_EI_VRM) { /* MIC VRA support */
2180 snd_ac97_determine_rates(ac97, AC97_PCM_MIC_ADC_RATE, 0, &ac97->rates[AC97_RATES_MIC_ADC]);
2182 ac97->rates[AC97_RATES_MIC_ADC] = SNDRV_PCM_RATE_48000;
2184 if (ac97->ext_id & AC97_EI_SDAC) { /* SDAC support */
2185 snd_ac97_determine_rates(ac97, AC97_PCM_SURR_DAC_RATE, AC97_PCM_FRONT_DAC_RATE, &ac97->rates[AC97_RATES_SURR_DAC]);
2186 ac97->scaps |= AC97_SCAP_SURROUND_DAC;
2188 if (ac97->ext_id & AC97_EI_LDAC) { /* LDAC support */
2189 snd_ac97_determine_rates(ac97, AC97_PCM_LFE_DAC_RATE, AC97_PCM_FRONT_DAC_RATE, &ac97->rates[AC97_RATES_LFE_DAC]);
2190 ac97->scaps |= AC97_SCAP_CENTER_LFE_DAC;
2194 bus->ops->init(ac97);
2195 snd_ac97_get_name(ac97, ac97->id, name, !ac97_is_audio(ac97));
2196 snd_ac97_get_name(NULL, ac97->id, name, !ac97_is_audio(ac97)); // ac97->id might be changed in the special setup code
2197 if (! ac97->build_ops)
2198 ac97->build_ops = &null_build_ops;
2200 if (ac97_is_audio(ac97)) {
2210 sprintf(comp, "AC97a:%08x", ac97->id);
2212 snd_ac97_free(ac97);
2215 if (snd_ac97_mixer_build(ac97) < 0) {
2216 snd_ac97_free(ac97);
2220 if (ac97_is_modem(ac97)) {
2230 sprintf(comp, "AC97m:%08x", ac97->id);
2232 snd_ac97_free(ac97);
2235 if (snd_ac97_modem_build(card, ac97) < 0) {
2236 snd_ac97_free(ac97);
2240 if (ac97_is_audio(ac97))
2241 update_power_regs(ac97);
2242 snd_ac97_proc_init(ac97);
2243 if ((err = snd_device_new(card, SNDRV_DEV_CODEC, ac97, &ops)) < 0) {
2244 snd_ac97_free(ac97);
2247 *rac97 = ac97;
2259 static void snd_ac97_powerdown(struct snd_ac97 *ac97)
2263 if (ac97_is_audio(ac97)) {
2265 snd_ac97_write(ac97, AC97_MASTER, 0x9f9f);
2266 snd_ac97_write(ac97, AC97_HEADPHONE, 0x9f9f);
2270 power = ac97->regs[AC97_EXTENDED_STATUS];
2271 if (ac97->scaps & AC97_SCAP_SURROUND_DAC)
2273 if (ac97->scaps & AC97_SCAP_CENTER_LFE_DAC)
2276 snd_ac97_write(ac97, AC97_EXTENDED_STATUS, power);
2279 if (ac97->scaps & AC97_SCAP_INV_EAPD)
2280 power = ac97->regs[AC97_POWERDOWN] & ~AC97_PD_EAPD;
2281 else if (! (ac97->scaps & AC97_SCAP_EAPD_LED))
2282 power = ac97->regs[AC97_POWERDOWN] | AC97_PD_EAPD;
2285 snd_ac97_write(ac97, AC97_POWERDOWN, power);
2288 snd_ac97_write(ac97, AC97_POWERDOWN, power);
2289 if (ac97_is_power_save_mode(ac97)) {
2293 snd_ac97_write(ac97, AC97_POWERDOWN, power);
2320 * @ac97: the codec instance
2326 int snd_ac97_update_power(struct snd_ac97 *ac97, int reg, int powerup)
2330 if (! ac97)
2340 ac97->power_up |= (1 << i);
2342 ac97->power_up &= ~(1 << i);
2348 if (ac97_is_power_save_mode(ac97) && !powerup)
2353 schedule_delayed_work(&ac97->power_work, HZ*2);
2355 cancel_delayed_work(&ac97->power_work);
2356 update_power_regs(ac97);
2365 static void update_power_regs(struct snd_ac97 *ac97)
2372 if (ac97->scaps & AC97_SCAP_SURROUND_DAC)
2374 if (ac97->scaps & AC97_SCAP_CENTER_LFE_DAC)
2377 if (ac97_is_power_save_mode(ac97))
2378 power_up = ac97->power_up;
2381 if (ac97->regs[AC97_POWERDOWN] & AC97_PD_PR2) {
2383 snd_ac97_update_bits(ac97, AC97_POWERDOWN,
2386 snd_ac97_update_bits(ac97, AC97_POWERDOWN,
2395 snd_ac97_update_bits(ac97, power_regs[i].power_reg,
2399 if (! (ac97->regs[AC97_POWERDOWN] & AC97_PD_PR2)) {
2401 snd_ac97_update_bits(ac97, AC97_POWERDOWN,
2403 snd_ac97_update_bits(ac97, AC97_POWERDOWN,
2413 * @ac97: the ac97 instance
2417 void snd_ac97_suspend(struct snd_ac97 *ac97)
2419 if (! ac97)
2421 if (ac97->build_ops->suspend)
2422 ac97->build_ops->suspend(ac97);
2424 cancel_delayed_work(&ac97->power_work);
2427 snd_ac97_powerdown(ac97);
2433 * restore ac97 status
2435 void snd_ac97_restore_status(struct snd_ac97 *ac97)
2446 if (test_bit(i, ac97->reg_accessed)) {
2447 snd_ac97_write(ac97, i, ac97->regs[i]);
2448 snd_ac97_read(ac97, i);
2456 void snd_ac97_restore_iec958(struct snd_ac97 *ac97)
2458 if (ac97->ext_id & AC97_EI_SPDIF) {
2459 if (ac97->regs[AC97_EXTENDED_STATUS] & AC97_EA_SPDIF) {
2461 snd_ac97_update_bits(ac97, AC97_EXTENDED_STATUS, AC97_EA_SPDIF, 0);
2462 snd_ac97_write(ac97, AC97_EXTENDED_STATUS, ac97->regs[AC97_EXTENDED_STATUS]);
2463 if (ac97->flags & AC97_CS_SPDIF)
2464 snd_ac97_write(ac97, AC97_CSR_SPDIF, ac97->regs[AC97_CSR_SPDIF]);
2466 snd_ac97_write(ac97, AC97_SPDIF, ac97->regs[AC97_SPDIF]);
2467 snd_ac97_update_bits(ac97, AC97_EXTENDED_STATUS, AC97_EA_SPDIF, AC97_EA_SPDIF); /* turn on again */
2474 * @ac97: the ac97 instance
2479 void snd_ac97_resume(struct snd_ac97 *ac97)
2483 if (! ac97)
2486 if (ac97->bus->ops->reset) {
2487 ac97->bus->ops->reset(ac97);
2491 snd_ac97_write(ac97, AC97_POWERDOWN, 0);
2492 if (! (ac97->flags & AC97_DEFAULT_POWER_OFF)) {
2493 snd_ac97_write(ac97, AC97_RESET, 0);
2495 snd_ac97_write(ac97, AC97_POWERDOWN, 0);
2497 snd_ac97_write(ac97, AC97_GENERAL_PURPOSE, 0);
2499 snd_ac97_write(ac97, AC97_POWERDOWN, ac97->regs[AC97_POWERDOWN]);
2500 if (ac97_is_audio(ac97)) {
2501 ac97->bus->ops->write(ac97, AC97_MASTER, 0x8101);
2504 if (snd_ac97_read(ac97, AC97_MASTER) == 0x8101)
2508 ac97->bus->ops->write(ac97, AC97_MASTER, 0x8000);
2509 if (snd_ac97_read(ac97, AC97_MASTER) != 0x8000)
2514 unsigned short val = snd_ac97_read(ac97, AC97_EXTENDED_MID);
2522 if (ac97->bus->ops->init)
2523 ac97->bus->ops->init(ac97);
2525 if (ac97->build_ops->resume)
2526 ac97->build_ops->resume(ac97);
2528 snd_ac97_restore_status(ac97);
2529 snd_ac97_restore_iec958(ac97);
2549 static int snd_ac97_remove_ctl(struct snd_ac97 *ac97, const char *name,
2556 return snd_ctl_remove_id(ac97->bus->card, &id);
2559 static struct snd_kcontrol *ctl_find(struct snd_ac97 *ac97, const char *name, const char *suffix)
2565 return snd_ctl_find_id(ac97->bus->card, &sid);
2569 static int snd_ac97_rename_ctl(struct snd_ac97 *ac97, const char *src,
2572 struct snd_kcontrol *kctl = ctl_find(ac97, src, suffix);
2581 static void snd_ac97_rename_vol_ctl(struct snd_ac97 *ac97, const char *src,
2584 snd_ac97_rename_ctl(ac97, src, dst, "Switch");
2585 snd_ac97_rename_ctl(ac97, src, dst, "Volume");
2589 static int snd_ac97_swap_ctl(struct snd_ac97 *ac97, const char *s1,
2593 kctl1 = ctl_find(ac97, s1, suffix);
2594 kctl2 = ctl_find(ac97, s2, suffix);
2616 /* ac97 tune: bind Master and Headphone controls */
2617 static int tune_hp_only(struct snd_ac97 *ac97)
2619 struct snd_kcontrol *msw = ctl_find(ac97, "Master Playback Switch", NULL);
2620 struct snd_kcontrol *mvol = ctl_find(ac97, "Master Playback Volume", NULL);
2625 snd_ac97_remove_ctl(ac97, "Headphone Playback", "Switch");
2626 snd_ac97_remove_ctl(ac97, "Headphone Playback", "Volume");
2631 /* ac97 tune: swap Headphone and Master controls */
2632 static int tune_swap_hp(struct snd_ac97 *ac97)
2634 if (ctl_find(ac97, "Headphone Playback Switch", NULL) == NULL)
2636 snd_ac97_rename_vol_ctl(ac97, "Master Playback", "Line-Out Playback");
2637 snd_ac97_rename_vol_ctl(ac97, "Headphone Playback", "Master Playback");
2641 /* ac97 tune: swap Surround and Master controls */
2642 static int tune_swap_surround(struct snd_ac97 *ac97)
2644 if (snd_ac97_swap_ctl(ac97, "Master Playback", "Surround Playback", "Switch") ||
2645 snd_ac97_swap_ctl(ac97, "Master Playback", "Surround Playback", "Volume"))
2650 /* ac97 tune: set up mic sharing for AD codecs */
2651 static int tune_ad_sharing(struct snd_ac97 *ac97)
2654 if ((ac97->id & 0xffffff00) != 0x41445300) {
2659 scfg = snd_ac97_read(ac97, AC97_AD_SERIAL_CFG);
2660 snd_ac97_write_cache(ac97, AC97_AD_SERIAL_CFG, scfg | 0x0200);
2667 /* ac97 tune: set up ALC jack-select */
2668 static int tune_alc_jack(struct snd_ac97 *ac97)
2670 if ((ac97->id & 0xffffff00) != 0x414c4700) {
2674 snd_ac97_update_bits(ac97, 0x7a, 0x20, 0x20); /* select jack detect function */
2675 snd_ac97_update_bits(ac97, 0x7a, 0x01, 0x01); /* Line-out auto mute */
2676 if (ac97->id == AC97_ID_ALC658D)
2677 snd_ac97_update_bits(ac97, 0x74, 0x0800, 0x0800);
2678 return snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&snd_ac97_alc_jack_detect, ac97));
2681 /* ac97 tune: inversed EAPD bit */
2682 static int tune_inv_eapd(struct snd_ac97 *ac97)
2684 struct snd_kcontrol *kctl = ctl_find(ac97, "External Amplifier", NULL);
2687 set_inv_eapd(ac97, kctl);
2695 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
2703 snd_ac97_update_bits(ac97, AC97_POWERDOWN, 0x8000,
2704 (ac97->regs[AC97_MASTER] & mask) == mask ?
2710 /* ac97 tune: EAPD controls mute LED bound with the master mute */
2711 static int tune_mute_led(struct snd_ac97 *ac97)
2713 struct snd_kcontrol *msw = ctl_find(ac97, "Master Playback Switch", NULL);
2717 snd_ac97_remove_ctl(ac97, "External Amplifier", NULL);
2718 snd_ac97_update_bits(ac97, AC97_POWERDOWN, 0x8000, 0x8000); /* mute LED on */
2719 ac97->scaps |= AC97_SCAP_EAPD_LED;
2728 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
2736 snd_ac97_update_bits(ac97, AC97_POWERDOWN, 0x8000,
2737 (ac97->regs[AC97_MASTER] & mask) == mask ?
2743 static int tune_hp_mute_led(struct snd_ac97 *ac97)
2745 struct snd_kcontrol *msw = ctl_find(ac97, "Master Playback Switch", NULL);
2746 struct snd_kcontrol *mvol = ctl_find(ac97, "Master Playback Volume", NULL);
2751 snd_ac97_remove_ctl(ac97, "External Amplifier", NULL);
2752 snd_ac97_remove_ctl(ac97, "Headphone Playback", "Switch");
2753 snd_ac97_remove_ctl(ac97, "Headphone Playback", "Volume");
2754 snd_ac97_update_bits(ac97, AC97_POWERDOWN, 0x8000, 0x8000); /* mute LED on */
2776 static int apply_quirk(struct snd_ac97 *ac97, int type)
2783 return applicable_quirks[type].func(ac97);
2788 static int apply_quirk_str(struct snd_ac97 *ac97, const char *typestr)
2796 return apply_quirk(ac97, i);
2800 return apply_quirk(ac97, (int)simple_strtoul(typestr, NULL, 10));
2805 int snd_ac97_tune_hardware(struct snd_ac97 *ac97, struct ac97_quirk *quirk, const char *override)
2811 result = apply_quirk_str(ac97, override);
2821 if (quirk->subvendor != ac97->subsystem_vendor)
2823 if ((! quirk->mask && quirk->subdevice == ac97->subsystem_device) ||
2824 quirk->subdevice == (quirk->mask & ac97->subsystem_device)) {
2825 if (quirk->codec_id && quirk->codec_id != ac97->id)
2827 snd_printdd("ac97 quirk for %s (%04x:%04x)\n", quirk->name, ac97->subsystem_vendor, ac97->subsystem_device);
2828 result = apply_quirk(ac97, quirk->type);