Lines Matching defs:ac97
64 int (*patch)(struct snd_ac97 *ac97);
65 int (*mpatch)(struct snd_ac97 *ac97);
201 static void update_power_regs(struct snd_ac97 *ac97);
203 #define ac97_is_power_save_mode(ac97) \
204 ((ac97->scaps & AC97_SCAP_POWER_SAVE) && power_save)
206 #define ac97_is_power_save_mode(ac97) 0
214 static int snd_ac97_valid_reg(struct snd_ac97 *ac97, unsigned short reg)
217 switch (ac97->id) {
262 * @ac97: the ac97 instance
272 void snd_ac97_write(struct snd_ac97 *ac97, unsigned short reg, unsigned short value)
274 if (!snd_ac97_valid_reg(ac97, reg))
276 if ((ac97->id & 0xffffff00) == AC97_ID_ALC100) {
279 ac97->bus->ops->write(ac97, AC97_RESET, 0); /* reset audio codec */
281 ac97->bus->ops->write(ac97, reg, value);
289 * @ac97: the ac97 instance
297 unsigned short snd_ac97_read(struct snd_ac97 *ac97, unsigned short reg)
299 if (!snd_ac97_valid_reg(ac97, reg))
301 return ac97->bus->ops->read(ac97, reg);
305 static inline unsigned short snd_ac97_read_cache(struct snd_ac97 *ac97, unsigned short reg)
307 if (! test_bit(reg, ac97->reg_accessed)) {
308 ac97->regs[reg] = ac97->bus->ops->read(ac97, reg);
309 // set_bit(reg, ac97->reg_accessed);
311 return ac97->regs[reg];
318 * @ac97: the ac97 instance
326 void snd_ac97_write_cache(struct snd_ac97 *ac97, unsigned short reg, unsigned short value)
328 if (!snd_ac97_valid_reg(ac97, reg))
330 mutex_lock(&ac97->reg_mutex);
331 ac97->regs[reg] = value;
332 ac97->bus->ops->write(ac97, reg, value);
333 set_bit(reg, ac97->reg_accessed);
334 mutex_unlock(&ac97->reg_mutex);
341 * @ac97: the ac97 instance
351 int snd_ac97_update(struct snd_ac97 *ac97, unsigned short reg, unsigned short value)
355 if (!snd_ac97_valid_reg(ac97, reg))
357 mutex_lock(&ac97->reg_mutex);
358 change = ac97->regs[reg] != value;
360 ac97->regs[reg] = value;
361 ac97->bus->ops->write(ac97, reg, value);
363 set_bit(reg, ac97->reg_accessed);
364 mutex_unlock(&ac97->reg_mutex);
372 * @ac97: the ac97 instance
383 int snd_ac97_update_bits(struct snd_ac97 *ac97, unsigned short reg, unsigned short mask, unsigned short value)
387 if (!snd_ac97_valid_reg(ac97, reg))
389 mutex_lock(&ac97->reg_mutex);
390 change = snd_ac97_update_bits_nolock(ac97, reg, mask, value);
391 mutex_unlock(&ac97->reg_mutex);
398 int snd_ac97_update_bits_nolock(struct snd_ac97 *ac97, unsigned short reg,
404 old = snd_ac97_read_cache(ac97, reg);
408 ac97->regs[reg] = new;
409 ac97->bus->ops->write(ac97, reg, new);
411 set_bit(reg, ac97->reg_accessed);
415 static int snd_ac97_ad18xx_update_pcm_bits(struct snd_ac97 *ac97, int codec, unsigned short mask, unsigned short value)
420 mutex_lock(&ac97->page_mutex);
421 old = ac97->spec.ad18xx.pcmreg[codec];
425 mutex_lock(&ac97->reg_mutex);
426 cfg = snd_ac97_read_cache(ac97, AC97_AD_SERIAL_CFG);
427 ac97->spec.ad18xx.pcmreg[codec] = new;
429 ac97->bus->ops->write(ac97, AC97_AD_SERIAL_CFG,
431 ac97->spec.ad18xx.unchained[codec] | ac97->spec.ad18xx.chained[codec]);
433 ac97->bus->ops->write(ac97, AC97_PCM, new);
435 ac97->bus->ops->write(ac97, AC97_AD_SERIAL_CFG,
437 mutex_unlock(&ac97->reg_mutex);
439 mutex_unlock(&ac97->page_mutex);
465 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
471 val = snd_ac97_read_cache(ac97, e->reg);
482 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
499 return snd_ac97_update_bits(ac97, e->reg, mask, val);
502 /* save/restore ac97 v2.3 paging */
503 static int snd_ac97_page_save(struct snd_ac97 *ac97, int reg, struct snd_kcontrol *kcontrol)
507 (ac97->ext_id & AC97_EI_REV_MASK) >= AC97_EI_REV_23 &&
510 mutex_lock(&ac97->page_mutex); /* lock paging */
511 page_save = snd_ac97_read(ac97, AC97_INT_PAGING) & AC97_PAGE_MASK;
512 snd_ac97_update_bits(ac97, AC97_INT_PAGING, AC97_PAGE_MASK, page);
517 static void snd_ac97_page_restore(struct snd_ac97 *ac97, int page_save)
520 snd_ac97_update_bits(ac97, AC97_INT_PAGING, AC97_PAGE_MASK, page_save);
521 mutex_unlock(&ac97->page_mutex); /* unlock paging */
543 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
551 page_save = snd_ac97_page_save(ac97, reg, kcontrol);
552 ucontrol->value.integer.value[0] = (snd_ac97_read_cache(ac97, reg) >> shift) & mask;
554 ucontrol->value.integer.value[1] = (snd_ac97_read_cache(ac97, reg) >> rshift) & mask;
560 snd_ac97_page_restore(ac97, page_save);
567 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
576 page_save = snd_ac97_page_save(ac97, reg, kcontrol);
589 err = snd_ac97_update_bits(ac97, reg, val_mask, val);
590 snd_ac97_page_restore(ac97, page_save);
596 ac97->power_up &= ~(1 << (reg>>1));
598 ac97->power_up |= 1 << (reg>>1);
599 update_power_regs(ac97);
691 static void set_inv_eapd(struct snd_ac97 *ac97, struct snd_kcontrol *kctl)
694 snd_ac97_update_bits(ac97, AC97_POWERDOWN, (1<<15), (1<<15)); /* EAPD up */
695 ac97->scaps |= AC97_SCAP_INV_EAPD;
728 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
730 mutex_lock(&ac97->reg_mutex);
731 ucontrol->value.iec958.status[0] = ac97->spdif_status & 0xff;
732 ucontrol->value.iec958.status[1] = (ac97->spdif_status >> 8) & 0xff;
733 ucontrol->value.iec958.status[2] = (ac97->spdif_status >> 16) & 0xff;
734 ucontrol->value.iec958.status[3] = (ac97->spdif_status >> 24) & 0xff;
735 mutex_unlock(&ac97->reg_mutex);
741 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
774 mutex_lock(&ac97->reg_mutex);
775 change = ac97->spdif_status != new;
776 ac97->spdif_status = new;
778 if (ac97->flags & AC97_CS_SPDIF) {
785 change |= snd_ac97_update_bits_nolock(ac97, AC97_CSR_SPDIF, 0x3fff, ((val & 0xcfff) | (x << 12)));
786 } else if (ac97->flags & AC97_CX_SPDIF) {
790 change |= snd_ac97_update_bits_nolock(ac97, AC97_CXR_AUDIO_MISC,
793 } else if (ac97->id == AC97_ID_YMF743) {
794 change |= snd_ac97_update_bits_nolock(ac97,
800 unsigned short extst = snd_ac97_read_cache(ac97, AC97_EXTENDED_STATUS);
801 snd_ac97_update_bits_nolock(ac97, AC97_EXTENDED_STATUS, AC97_EA_SPDIF, 0); /* turn off */
803 change |= snd_ac97_update_bits_nolock(ac97, AC97_SPDIF, 0x3fff, val);
805 snd_ac97_update_bits_nolock(ac97, AC97_EXTENDED_STATUS, AC97_EA_SPDIF, AC97_EA_SPDIF); /* turn on again */
808 mutex_unlock(&ac97->reg_mutex);
815 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
825 mutex_lock(&ac97->reg_mutex);
828 old = snd_ac97_read_cache(ac97, reg);
833 unsigned short extst = snd_ac97_read_cache(ac97, AC97_EXTENDED_STATUS);
834 snd_ac97_update_bits_nolock(ac97, AC97_EXTENDED_STATUS, AC97_EA_SPDIF, 0); /* turn off */
835 change = snd_ac97_update_bits_nolock(ac97, reg, mask, value);
837 snd_ac97_update_bits_nolock(ac97, AC97_EXTENDED_STATUS, AC97_EA_SPDIF, AC97_EA_SPDIF); /* turn on again */
839 mutex_unlock(&ac97->reg_mutex);
884 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
890 if (lshift != rshift && (ac97->flags & AC97_STEREO_MUTES))
901 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
907 ucontrol->value.integer.value[0] = mask - ((ac97->spec.ad18xx.pcmreg[codec] >> lshift) & mask);
908 if (lshift != rshift && (ac97->flags & AC97_STEREO_MUTES))
909 ucontrol->value.integer.value[1] = mask - ((ac97->spec.ad18xx.pcmreg[codec] >> rshift) & mask);
915 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
924 if (lshift != rshift && (ac97->flags & AC97_STEREO_MUTES)) {
928 return snd_ac97_ad18xx_update_pcm_bits(ac97, codec, valmask, val);
947 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
950 mutex_lock(&ac97->page_mutex);
951 ucontrol->value.integer.value[0] = 31 - ((ac97->spec.ad18xx.pcmreg[codec] >> 0) & 31);
952 ucontrol->value.integer.value[1] = 31 - ((ac97->spec.ad18xx.pcmreg[codec] >> 8) & 31);
953 mutex_unlock(&ac97->page_mutex);
959 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
965 return snd_ac97_ad18xx_update_pcm_bits(ac97, codec, 0x1f1f, (val1 << 8) | val2);
992 static void snd_ac97_powerdown(struct snd_ac97 *ac97);
1012 static int snd_ac97_free(struct snd_ac97 *ac97)
1014 if (ac97) {
1016 cancel_delayed_work(&ac97->power_work);
1019 snd_ac97_proc_done(ac97);
1020 if (ac97->bus)
1021 ac97->bus->codec[ac97->num] = NULL;
1022 if (ac97->private_free)
1023 ac97->private_free(ac97);
1024 kfree(ac97);
1031 struct snd_ac97 *ac97 = device->device_data;
1032 snd_ac97_powerdown(ac97); /* for avoiding click noises during shut down */
1033 return snd_ac97_free(ac97);
1036 static int snd_ac97_try_volume_mix(struct snd_ac97 * ac97, int reg)
1040 if (! snd_ac97_valid_reg(ac97, reg))
1045 return ac97->caps & 0x04 ? 1 : 0;
1047 return ac97->caps & 0x10 ? 1 : 0;
1049 return ac97->caps & 0x01 ? 1 : 0;
1051 if (ac97->caps & 0x7c00) {
1052 val = snd_ac97_read(ac97, reg);
1058 if ((ac97->ext_id & AC97_EI_CDAC) == 0)
1062 if ((ac97->ext_id & AC97_EI_LDAC) == 0)
1068 if ((ac97->ext_id & AC97_EI_SDAC) == 0)
1073 val = snd_ac97_read(ac97, reg);
1077 snd_ac97_write_cache(ac97, reg, val | mask);
1078 val = snd_ac97_read(ac97, reg);
1079 val = snd_ac97_read(ac97, reg);
1086 static void check_volume_resolution(struct snd_ac97 *ac97, int reg, unsigned char *lo_max, unsigned char *hi_max)
1093 if (ac97->res_table) {
1095 for (tbl = ac97->res_table; tbl->reg; tbl++) {
1107 snd_ac97_write(ac97, reg, 0x8080 | cbit[i] | (cbit[i] << 8));
1108 /* Do the read twice due to buffers on some ac97 codecs.
1112 val = snd_ac97_read(ac97, reg);
1113 val = snd_ac97_read(ac97, reg);
1123 static int snd_ac97_try_bit(struct snd_ac97 * ac97, int reg, int bit)
1128 orig = snd_ac97_read(ac97, reg);
1130 snd_ac97_write(ac97, reg, val);
1131 res = snd_ac97_read(ac97, reg);
1132 snd_ac97_write_cache(ac97, reg, orig);
1137 static void snd_ac97_change_volume_params2(struct snd_ac97 * ac97, int reg, int shift, unsigned char *max)
1143 snd_ac97_write(ac97, reg, val);
1144 val1 = snd_ac97_read(ac97, reg);
1149 snd_ac97_write_cache(ac97, reg, 0x8080);
1164 struct snd_ac97 * ac97)
1168 template.index = ac97->num;
1169 return snd_ctl_new1(&template, ac97);
1177 struct snd_ac97 *ac97)
1183 if (! snd_ac97_valid_reg(ac97, reg))
1187 val = snd_ac97_read(ac97, reg);
1188 if (check_stereo || (ac97->flags & AC97_STEREO_MUTES)) {
1191 snd_ac97_write(ac97, reg, val1);
1192 if (val1 == snd_ac97_read(ac97, reg))
1199 tmp.index = ac97->num;
1200 kctl = snd_ctl_new1(&tmp, ac97);
1205 tmp.index = ac97->num;
1206 kctl = snd_ctl_new1(&tmp, ac97);
1212 snd_ac97_write_cache(ac97, reg, val | mute_mask);
1246 unsigned int hi_max, struct snd_ac97 *ac97)
1251 if (! snd_ac97_valid_reg(ac97, reg))
1256 tmp.index = ac97->num;
1257 kctl = snd_ctl_new1(&tmp, ac97);
1261 tmp.index = ac97->num;
1262 kctl = snd_ctl_new1(&tmp, ac97);
1271 snd_ac97_write_cache(ac97, reg,
1272 (snd_ac97_read(ac97, reg) & 0x8080) |
1282 struct snd_ac97 *ac97)
1288 if (! snd_ac97_valid_reg(ac97, reg))
1291 if (snd_ac97_try_bit(ac97, reg, 15)) {
1295 ac97)) < 0)
1298 check_volume_resolution(ac97, reg, &lo_max, &hi_max);
1301 if ((err = snd_ac97_cvol_new(card, name, reg, lo_max, hi_max, ac97)) < 0)
1307 #define snd_ac97_cmix_new(card, pfx, reg, acheck, ac97) \
1308 snd_ac97_cmix_new_stereo(card, pfx, reg, 0, acheck, ac97)
1309 #define snd_ac97_cmute_new(card, name, reg, acheck, ac97) \
1310 snd_ac97_cmute_new_stereo(card, name, reg, 0, acheck, ac97)
1312 static unsigned int snd_ac97_determine_spdif_rates(struct snd_ac97 *ac97);
1314 static int snd_ac97_mixer_build(struct snd_ac97 * ac97)
1316 struct snd_card *card = ac97->bus->card;
1324 if (snd_ac97_try_volume_mix(ac97, AC97_MASTER)) {
1325 if (ac97->flags & AC97_HAS_NO_MASTER_VOL)
1327 AC97_MASTER, 0, ac97);
1330 AC97_MASTER, 0, ac97);
1335 ac97->regs[AC97_CENTER_LFE_MASTER] = 0x8080;
1338 if ((snd_ac97_try_volume_mix(ac97, AC97_CENTER_LFE_MASTER))
1339 && !(ac97->flags & AC97_AD_MULTI)) {
1340 if ((err = snd_ctl_add(card, snd_ac97_cnew(&snd_ac97_controls_center[0], ac97))) < 0)
1342 if ((err = snd_ctl_add(card, kctl = snd_ac97_cnew(&snd_ac97_controls_center[1], ac97))) < 0)
1344 snd_ac97_change_volume_params2(ac97, AC97_CENTER_LFE_MASTER, 0, &max);
1348 snd_ac97_write_cache(ac97, AC97_CENTER_LFE_MASTER, ac97->regs[AC97_CENTER_LFE_MASTER] | max);
1352 if ((snd_ac97_try_volume_mix(ac97, AC97_CENTER_LFE_MASTER+1))
1353 && !(ac97->flags & AC97_AD_MULTI)) {
1354 if ((err = snd_ctl_add(card, snd_ac97_cnew(&snd_ac97_controls_lfe[0], ac97))) < 0)
1356 if ((err = snd_ctl_add(card, kctl = snd_ac97_cnew(&snd_ac97_controls_lfe[1], ac97))) < 0)
1358 snd_ac97_change_volume_params2(ac97, AC97_CENTER_LFE_MASTER, 8, &max);
1362 snd_ac97_write_cache(ac97, AC97_CENTER_LFE_MASTER, ac97->regs[AC97_CENTER_LFE_MASTER] | max << 8);
1366 if ((snd_ac97_try_volume_mix(ac97, AC97_SURROUND_MASTER))
1367 && !(ac97->flags & AC97_AD_MULTI)) {
1371 ac97)) < 0)
1376 if (snd_ac97_try_volume_mix(ac97, AC97_HEADPHONE)) {
1378 AC97_HEADPHONE, 0, ac97)) < 0)
1383 if (snd_ac97_try_volume_mix(ac97, AC97_MASTER_MONO)) {
1385 AC97_MASTER_MONO, 0, ac97)) < 0)
1390 if (!(ac97->flags & AC97_HAS_NO_TONE)) {
1391 if (snd_ac97_try_volume_mix(ac97, AC97_MASTER_TONE)) {
1393 if ((err = snd_ctl_add(card, kctl = snd_ac97_cnew(&snd_ac97_controls_tone[idx], ac97))) < 0)
1395 if (ac97->id == AC97_ID_YMF743 ||
1396 ac97->id == AC97_ID_YMF753) {
1401 snd_ac97_write_cache(ac97, AC97_MASTER_TONE, 0x0f0f);
1406 if (!(ac97->flags & AC97_HAS_NO_PC_BEEP) &&
1407 ((ac97->flags & AC97_HAS_PC_BEEP) ||
1408 snd_ac97_try_volume_mix(ac97, AC97_PC_BEEP))) {
1410 if ((err = snd_ctl_add(card, kctl = snd_ac97_cnew(&snd_ac97_controls_pc_beep[idx], ac97))) < 0)
1413 snd_ac97_write_cache(ac97, AC97_PC_BEEP,
1414 snd_ac97_read(ac97, AC97_PC_BEEP) | 0x801e);
1418 if (!(ac97->flags & AC97_HAS_NO_PHONE)) {
1419 if (snd_ac97_try_volume_mix(ac97, AC97_PHONE)) {
1421 AC97_PHONE, 1, ac97)) < 0)
1427 if (!(ac97->flags & AC97_HAS_NO_MIC)) {
1428 if (snd_ac97_try_volume_mix(ac97, AC97_MIC)) {
1430 AC97_MIC, 1, ac97)) < 0)
1432 if ((err = snd_ctl_add(card, snd_ac97_cnew(&snd_ac97_controls_mic_boost, ac97))) < 0)
1438 if (snd_ac97_try_volume_mix(ac97, AC97_LINE)) {
1440 AC97_LINE, 1, ac97)) < 0)
1445 if (!(ac97->flags & AC97_HAS_NO_CD)) {
1446 if (snd_ac97_try_volume_mix(ac97, AC97_CD)) {
1448 AC97_CD, 1, ac97)) < 0)
1454 if (!(ac97->flags & AC97_HAS_NO_VIDEO)) {
1455 if (snd_ac97_try_volume_mix(ac97, AC97_VIDEO)) {
1457 AC97_VIDEO, 1, ac97)) < 0)
1463 if (!(ac97->flags & AC97_HAS_NO_AUX)) {
1464 if (snd_ac97_try_volume_mix(ac97, AC97_AUX)) {
1466 AC97_AUX, 1, ac97)) < 0)
1472 if (ac97->flags & AC97_AD_MULTI) {
1474 if (ac97->flags & AC97_STEREO_MUTES)
1479 if ((err = snd_ctl_add(card, kctl = snd_ac97_cnew(&snd_ac97_controls_ad18xx_pcm[idx], ac97))) < 0)
1482 ac97->spec.ad18xx.pcmreg[0] = init_val;
1483 if (ac97->scaps & AC97_SCAP_SURROUND_DAC) {
1485 if ((err = snd_ctl_add(card, kctl = snd_ac97_cnew(&snd_ac97_controls_ad18xx_surround[idx], ac97))) < 0)
1488 ac97->spec.ad18xx.pcmreg[1] = init_val;
1490 if (ac97->scaps & AC97_SCAP_CENTER_LFE_DAC) {
1492 if ((err = snd_ctl_add(card, kctl = snd_ac97_cnew(&snd_ac97_controls_ad18xx_center[idx], ac97))) < 0)
1496 if ((err = snd_ctl_add(card, kctl = snd_ac97_cnew(&snd_ac97_controls_ad18xx_lfe[idx], ac97))) < 0)
1499 ac97->spec.ad18xx.pcmreg[2] = init_val;
1501 snd_ac97_write_cache(ac97, AC97_PCM, init_val);
1503 if (!(ac97->flags & AC97_HAS_NO_STD_PCM)) {
1504 if (ac97->flags & AC97_HAS_NO_PCM_VOL)
1507 AC97_PCM, 0, ac97);
1510 AC97_PCM, 0, ac97);
1517 if (!(ac97->flags & AC97_HAS_NO_REC_GAIN)) {
1518 if ((err = snd_ctl_add(card, snd_ac97_cnew(&snd_ac97_control_capture_src, ac97))) < 0)
1520 if (snd_ac97_try_bit(ac97, AC97_REC_GAIN, 15)) {
1522 AC97_REC_GAIN, 0, ac97);
1526 if ((err = snd_ctl_add(card, kctl = snd_ac97_cnew(&snd_ac97_control_capture_vol, ac97))) < 0)
1529 snd_ac97_write_cache(ac97, AC97_REC_SEL, 0x0000);
1530 snd_ac97_write_cache(ac97, AC97_REC_GAIN, 0x0000);
1533 if (snd_ac97_try_volume_mix(ac97, AC97_REC_GAIN_MIC)) {
1535 if ((err = snd_ctl_add(card, kctl = snd_ac97_cnew(&snd_ac97_controls_mic_capture[idx], ac97))) < 0)
1538 snd_ac97_write_cache(ac97, AC97_REC_GAIN_MIC, 0x0000);
1542 if (snd_ac97_try_bit(ac97, AC97_GENERAL_PURPOSE, 15)) {
1543 if ((err = snd_ctl_add(card, snd_ac97_cnew(&snd_ac97_controls_general[AC97_GENERAL_PCM_OUT], ac97))) < 0)
1548 if (ac97->caps & 0x0008) {
1549 if ((err = snd_ctl_add(card, snd_ac97_cnew(&snd_ac97_controls_general[AC97_GENERAL_STEREO_ENHANCEMENT], ac97))) < 0)
1554 if (snd_ac97_try_bit(ac97, AC97_GENERAL_PURPOSE, 13)) {
1555 if ((err = snd_ctl_add(card, snd_ac97_cnew(&snd_ac97_controls_general[AC97_GENERAL_3D], ac97))) < 0)
1560 if (ac97->caps & 0x0020) {
1561 if ((err = snd_ctl_add(card, snd_ac97_cnew(&snd_ac97_controls_general[AC97_GENERAL_LOUDNESS], ac97))) < 0)
1566 if (snd_ac97_try_bit(ac97, AC97_GENERAL_PURPOSE, 9)) {
1567 if ((err = snd_ctl_add(card, snd_ac97_cnew(&snd_ac97_controls_general[AC97_GENERAL_MONO], ac97))) < 0)
1572 if (snd_ac97_try_bit(ac97, AC97_GENERAL_PURPOSE, 8)) {
1573 if ((err = snd_ctl_add(card, snd_ac97_cnew(&snd_ac97_controls_general[AC97_GENERAL_MIC], ac97))) < 0)
1578 if (enable_loopback && snd_ac97_try_bit(ac97, AC97_GENERAL_PURPOSE, 7)) {
1579 if ((err = snd_ctl_add(card, snd_ac97_cnew(&snd_ac97_controls_general[AC97_GENERAL_LOOPBACK], ac97))) < 0)
1583 snd_ac97_update_bits(ac97, AC97_GENERAL_PURPOSE, ~AC97_GP_DRSS_MASK, 0x0000);
1586 if (ac97->build_ops->build_3d) {
1587 ac97->build_ops->build_3d(ac97);
1589 if (snd_ac97_try_volume_mix(ac97, AC97_3D_CONTROL)) {
1592 snd_ac97_write(ac97, AC97_3D_CONTROL, val);
1593 val = snd_ac97_read(ac97, AC97_3D_CONTROL);
1595 if ((err = snd_ctl_add(card, kctl = snd_ac97_cnew(&snd_ac97_controls_3d[0], ac97))) < 0)
1599 if ((err = snd_ctl_add(card, kctl = snd_ac97_cnew(&snd_ac97_controls_3d[1], ac97))) < 0)
1603 snd_ac97_write_cache(ac97, AC97_3D_CONTROL, 0x0000);
1610 if (ac97->subsystem_vendor == 0x1043 &&
1611 ac97->subsystem_device == 0x810f)
1612 ac97->ext_id |= AC97_EI_SPDIF;
1614 if ((ac97->ext_id & AC97_EI_SPDIF) && !(ac97->scaps & AC97_SCAP_NO_SPDIF)) {
1615 if (ac97->build_ops->build_spdif) {
1616 if ((err = ac97->build_ops->build_spdif(ac97)) < 0)
1620 if ((err = snd_ctl_add(card, snd_ac97_cnew(&snd_ac97_controls_spdif[idx], ac97))) < 0)
1622 if (ac97->build_ops->build_post_spdif) {
1623 if ((err = ac97->build_ops->build_post_spdif(ac97)) < 0)
1628 snd_ac97_write_cache(ac97, AC97_SPDIF, 0x2a20);
1629 ac97->rates[AC97_RATES_SPDIF] = snd_ac97_determine_spdif_rates(ac97);
1631 ac97->spdif_status = SNDRV_PCM_DEFAULT_CON_SPDIF;
1635 if (ac97->build_ops->build_specific)
1636 if ((err = ac97->build_ops->build_specific(ac97)) < 0)
1639 if (snd_ac97_try_bit(ac97, AC97_POWERDOWN, 15)) {
1640 kctl = snd_ac97_cnew(&snd_ac97_control_eapd, ac97);
1643 if (ac97->scaps & AC97_SCAP_INV_EAPD)
1644 set_inv_eapd(ac97, kctl);
1652 static int snd_ac97_modem_build(struct snd_card *card, struct snd_ac97 * ac97)
1658 snd_ac97_read(ac97,AC97_GPIO_CFG));
1660 snd_ac97_write(ac97, AC97_GPIO_CFG, 0xffff & ~(AC97_GPIO_LINE1_OH));
1661 snd_ac97_write(ac97, AC97_GPIO_POLARITY, 0xffff & ~(AC97_GPIO_LINE1_OH));
1662 snd_ac97_write(ac97, AC97_GPIO_STICKY, 0xffff);
1663 snd_ac97_write(ac97, AC97_GPIO_WAKEUP, 0x0);
1664 snd_ac97_write(ac97, AC97_MISC_AFE, 0x0);
1668 if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_ac97_controls_modem_switches[idx], ac97))) < 0)
1672 if (ac97->build_ops->build_specific)
1673 if ((err = ac97->build_ops->build_specific(ac97)) < 0)
1679 static int snd_ac97_test_rate(struct snd_ac97 *ac97, int reg, int shadow_reg, int rate)
1684 tmp = ((unsigned int)rate * ac97->bus->clock) / 48000;
1685 snd_ac97_write_cache(ac97, reg, tmp & 0xffff);
1687 snd_ac97_write_cache(ac97, shadow_reg, tmp & 0xffff);
1688 val = snd_ac97_read(ac97, reg);
1692 static void snd_ac97_determine_rates(struct snd_ac97 *ac97, int reg, int shadow_reg, unsigned int *r_result)
1697 if (ac97->bus->no_vra) {
1699 if ((ac97->flags & AC97_DOUBLE_RATE) &&
1705 saved = snd_ac97_read(ac97, reg);
1706 if ((ac97->ext_id & AC97_EI_DRA) && reg == AC97_PCM_FRONT_DAC_RATE)
1707 snd_ac97_update_bits(ac97, AC97_EXTENDED_STATUS,
1710 if (snd_ac97_test_rate(ac97, reg, shadow_reg, 11000))
1713 if (snd_ac97_test_rate(ac97, reg, shadow_reg, 8000))
1715 if (snd_ac97_test_rate(ac97, reg, shadow_reg, 11025))
1717 if (snd_ac97_test_rate(ac97, reg, shadow_reg, 16000))
1719 if (snd_ac97_test_rate(ac97, reg, shadow_reg, 22050))
1721 if (snd_ac97_test_rate(ac97, reg, shadow_reg, 32000))
1723 if (snd_ac97_test_rate(ac97, reg, shadow_reg, 44100))
1725 if (snd_ac97_test_rate(ac97, reg, shadow_reg, 48000))
1727 if ((ac97->flags & AC97_DOUBLE_RATE) &&
1730 snd_ac97_update_bits(ac97, AC97_EXTENDED_STATUS,
1732 if (snd_ac97_test_rate(ac97, reg, shadow_reg, 64000 / 2))
1734 if (snd_ac97_test_rate(ac97, reg, shadow_reg, 88200 / 2))
1736 if (snd_ac97_test_rate(ac97, reg, shadow_reg, 96000 / 2))
1739 if (!snd_ac97_test_rate(ac97, reg, shadow_reg, 76100 / 2))
1741 snd_ac97_update_bits(ac97, AC97_EXTENDED_STATUS,
1745 snd_ac97_write_cache(ac97, reg, saved);
1747 snd_ac97_write_cache(ac97, shadow_reg, saved);
1752 static unsigned int snd_ac97_determine_spdif_rates(struct snd_ac97 *ac97)
1764 snd_ac97_update_bits(ac97, AC97_SPDIF, AC97_SC_SPSR_MASK, ctl_bits[i]);
1765 if ((snd_ac97_read(ac97, AC97_SPDIF) & AC97_SC_SPSR_MASK) == ctl_bits[i])
1783 void snd_ac97_get_name(struct snd_ac97 *ac97, unsigned int id, char *name, int modem)
1796 if (ac97 && pid->patch) {
1799 pid->patch(ac97);
1808 if (ac97 && pid->patch) {
1811 pid->patch(ac97);
1819 * @ac97: the codec instance
1823 const char *snd_ac97_get_short_name(struct snd_ac97 *ac97)
1828 if (pid->id == (ac97->id & pid->mask))
1838 static int ac97_reset_wait(struct snd_ac97 *ac97, int timeout, int with_modem)
1847 snd_ac97_read(ac97, AC97_RESET);
1848 snd_ac97_read(ac97, AC97_VENDOR_ID1);
1849 snd_ac97_read(ac97, AC97_VENDOR_ID2);
1852 val = snd_ac97_read(ac97, AC97_EXTENDED_MID);
1856 if (ac97->scaps & AC97_SCAP_DETECT_BY_VENDOR) {
1858 val = snd_ac97_read(ac97, AC97_VENDOR_ID1);
1866 snd_ac97_write_cache(ac97, AC97_REC_GAIN, 0x8a05);
1867 if ((snd_ac97_read(ac97, AC97_REC_GAIN) & 0x7fff) == 0x0a05)
1934 /* register ac97 codec to bus */
1937 struct snd_ac97 *ac97 = device->device_data;
1940 ac97->dev.bus = &ac97_bus_type;
1941 ac97->dev.parent = ac97->bus->card->dev;
1942 ac97->dev.release = ac97_device_release;
1943 dev_set_name(&ac97->dev, "%d-%d:%s",
1944 ac97->bus->card->number, ac97->num,
1945 snd_ac97_get_short_name(ac97));
1946 if ((err = device_register(&ac97->dev)) < 0) {
1947 snd_printk(KERN_ERR "Can't register ac97 bus\n");
1948 ac97->dev.bus = NULL;
1954 /* disconnect ac97 codec */
1957 struct snd_ac97 *ac97 = device->device_data;
1958 if (ac97->dev.bus)
1959 device_unregister(&ac97->dev);
1977 * @template: the template of ac97, including index, callbacks and
1979 * @rac97: the pointer to store the new ac97 instance.
1988 * The ac97 instance is registered as a low-level device, so you don't
1996 struct snd_ac97 *ac97;
2018 ac97 = kzalloc(sizeof(*ac97), GFP_KERNEL);
2019 if (ac97 == NULL)
2021 ac97->private_data = template->private_data;
2022 ac97->private_free = template->private_free;
2023 ac97->bus = bus;
2024 ac97->pci = template->pci;
2025 ac97->num = template->num;
2026 ac97->addr = template->addr;
2027 ac97->scaps = template->scaps;
2028 ac97->res_table = template->res_table;
2029 bus->codec[ac97->num] = ac97;
2030 mutex_init(&ac97->reg_mutex);
2031 mutex_init(&ac97->page_mutex);
2033 INIT_DELAYED_WORK(&ac97->power_work, do_update_power);
2037 if (ac97->pci) {
2038 pci_read_config_word(ac97->pci, PCI_SUBSYSTEM_VENDOR_ID, &ac97->subsystem_vendor);
2039 pci_read_config_word(ac97->pci, PCI_SUBSYSTEM_ID, &ac97->subsystem_device);
2043 bus->ops->reset(ac97);
2047 ac97->id = snd_ac97_read(ac97, AC97_VENDOR_ID1) << 16;
2048 ac97->id |= snd_ac97_read(ac97, AC97_VENDOR_ID2);
2049 if (ac97->id && ac97->id != (unsigned int)-1) {
2050 pid = look_for_codec_id(snd_ac97_codec_ids, ac97->id);
2056 if (!(ac97->scaps & AC97_SCAP_SKIP_AUDIO))
2057 snd_ac97_write(ac97, AC97_RESET, 0);
2058 if (!(ac97->scaps & AC97_SCAP_SKIP_MODEM))
2059 snd_ac97_write(ac97, AC97_EXTENDED_MID, 0);
2061 bus->ops->wait(ac97);
2064 if (ac97->scaps & AC97_SCAP_SKIP_AUDIO)
2065 err = ac97_reset_wait(ac97, msecs_to_jiffies(500), 1);
2067 err = ac97_reset_wait(ac97, msecs_to_jiffies(500), 0);
2069 err = ac97_reset_wait(ac97,
2073 snd_printk(KERN_WARNING "AC'97 %d does not respond - RESET\n", ac97->num);
2078 ac97->id = snd_ac97_read(ac97, AC97_VENDOR_ID1) << 16;
2079 ac97->id |= snd_ac97_read(ac97, AC97_VENDOR_ID2);
2080 if (! (ac97->scaps & AC97_SCAP_DETECT_BY_VENDOR) &&
2081 (ac97->id == 0x00000000 || ac97->id == 0xffffffff)) {
2082 snd_printk(KERN_ERR "AC'97 %d access is not valid [0x%x], removing mixer.\n", ac97->num, ac97->id);
2083 snd_ac97_free(ac97);
2086 pid = look_for_codec_id(snd_ac97_codec_ids, ac97->id);
2088 ac97->flags |= pid->flags;
2091 if (!(ac97->scaps & AC97_SCAP_SKIP_AUDIO) && !(ac97->scaps & AC97_SCAP_AUDIO)) {
2093 snd_ac97_write_cache(ac97, AC97_REC_GAIN, 0x8a06);
2094 if (((err = snd_ac97_read(ac97, AC97_REC_GAIN)) & 0x7fff) == 0x0a06)
2095 ac97->scaps |= AC97_SCAP_AUDIO;
2097 if (ac97->scaps & AC97_SCAP_AUDIO) {
2098 ac97->caps = snd_ac97_read(ac97, AC97_RESET);
2099 ac97->ext_id = snd_ac97_read(ac97, AC97_EXTENDED_ID);
2100 if (ac97->ext_id == 0xffff) /* invalid combination */
2101 ac97->ext_id = 0;
2105 if (!(ac97->scaps & AC97_SCAP_SKIP_MODEM) && !(ac97->scaps & AC97_SCAP_MODEM)) {
2106 ac97->ext_mid = snd_ac97_read(ac97, AC97_EXTENDED_MID);
2107 if (ac97->ext_mid == 0xffff) /* invalid combination */
2108 ac97->ext_mid = 0;
2109 if (ac97->ext_mid & 1)
2110 ac97->scaps |= AC97_SCAP_MODEM;
2113 if (!ac97_is_audio(ac97) && !ac97_is_modem(ac97)) {
2114 if (!(ac97->scaps & (AC97_SCAP_SKIP_AUDIO|AC97_SCAP_SKIP_MODEM)))
2115 snd_printk(KERN_ERR "AC'97 %d access error (not audio or modem codec)\n", ac97->num);
2116 snd_ac97_free(ac97);
2123 if (ac97_is_audio(ac97)) {
2125 snd_ac97_write_cache(ac97, AC97_POWERDOWN, 0);
2126 if (! (ac97->flags & AC97_DEFAULT_POWER_OFF)) {
2127 snd_ac97_write_cache(ac97, AC97_RESET, 0); /* reset to defaults */
2129 snd_ac97_write_cache(ac97, AC97_POWERDOWN, 0);
2132 snd_ac97_write_cache(ac97, AC97_GENERAL_PURPOSE, 0);
2135 if ((snd_ac97_read(ac97, AC97_POWERDOWN) & 0x0f) == 0x0f)
2139 snd_printk(KERN_WARNING "AC'97 %d analog subsections not ready\n", ac97->num);
2142 if (ac97_is_modem(ac97)) {
2148 if (ac97->ext_mid & AC97_MEI_LINE1) {
2149 snd_ac97_write_cache(ac97, AC97_LINE1_RATE, 8000);
2152 if (ac97->ext_mid & AC97_MEI_LINE2) {
2153 snd_ac97_write_cache(ac97, AC97_LINE2_RATE, 8000);
2156 if (ac97->ext_mid & AC97_MEI_HANDSET) {
2157 snd_ac97_write_cache(ac97, AC97_HANDSET_RATE, 8000);
2160 snd_ac97_write_cache(ac97, AC97_EXTENDED_MSTATUS, 0);
2163 snd_ac97_write_cache(ac97, AC97_EXTENDED_MSTATUS, 0);
2166 if ((snd_ac97_read(ac97, AC97_EXTENDED_MSTATUS) & tmp) == tmp)
2170 snd_printk(KERN_WARNING "MC'97 %d converters and GPIO not ready (0x%x)\n", ac97->num, snd_ac97_read(ac97, AC97_EXTENDED_MSTATUS));
2174 if (ac97_is_audio(ac97))
2175 ac97->addr = (ac97->ext_id & AC97_EI_ADDR_MASK) >> AC97_EI_ADDR_SHIFT;
2177 ac97->addr = (ac97->ext_mid & AC97_MEI_ADDR_MASK) >> AC97_MEI_ADDR_SHIFT;
2178 if (ac97->ext_id & 0x01c9) { /* L/R, MIC, SDAC, LDAC VRA support */
2179 reg = snd_ac97_read(ac97, AC97_EXTENDED_STATUS);
2180 reg |= ac97->ext_id & 0x01c0; /* LDAC/SDAC/CDAC */
2182 reg |= ac97->ext_id & 0x0009; /* VRA/VRM */
2183 snd_ac97_write_cache(ac97, AC97_EXTENDED_STATUS, reg);
2185 if ((ac97->ext_id & AC97_EI_DRA) && bus->dra) {
2188 snd_ac97_update_bits(ac97, AC97_GENERAL_PURPOSE, AC97_GP_DRSS_MASK, AC97_GP_DRSS_78);
2189 if ((snd_ac97_read(ac97, AC97_GENERAL_PURPOSE) & AC97_GP_DRSS_MASK) == AC97_GP_DRSS_78)
2190 ac97->flags |= AC97_DOUBLE_RATE;
2192 snd_ac97_update_bits(ac97, AC97_GENERAL_PURPOSE, AC97_GP_DRSS_MASK, 0);
2194 if (ac97->ext_id & AC97_EI_VRA) { /* VRA support */
2195 snd_ac97_determine_rates(ac97, AC97_PCM_FRONT_DAC_RATE, 0, &ac97->rates[AC97_RATES_FRONT_DAC]);
2196 snd_ac97_determine_rates(ac97, AC97_PCM_LR_ADC_RATE, 0, &ac97->rates[AC97_RATES_ADC]);
2198 ac97->rates[AC97_RATES_FRONT_DAC] = SNDRV_PCM_RATE_48000;
2199 if (ac97->flags & AC97_DOUBLE_RATE)
2200 ac97->rates[AC97_RATES_FRONT_DAC] |= SNDRV_PCM_RATE_96000;
2201 ac97->rates[AC97_RATES_ADC] = SNDRV_PCM_RATE_48000;
2203 if (ac97->ext_id & AC97_EI_SPDIF) {
2205 ac97->rates[AC97_RATES_SPDIF] = SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_32000;
2207 if (ac97->ext_id & AC97_EI_VRM) { /* MIC VRA support */
2208 snd_ac97_determine_rates(ac97, AC97_PCM_MIC_ADC_RATE, 0, &ac97->rates[AC97_RATES_MIC_ADC]);
2210 ac97->rates[AC97_RATES_MIC_ADC] = SNDRV_PCM_RATE_48000;
2212 if (ac97->ext_id & AC97_EI_SDAC) { /* SDAC support */
2213 snd_ac97_determine_rates(ac97, AC97_PCM_SURR_DAC_RATE, AC97_PCM_FRONT_DAC_RATE, &ac97->rates[AC97_RATES_SURR_DAC]);
2214 ac97->scaps |= AC97_SCAP_SURROUND_DAC;
2216 if (ac97->ext_id & AC97_EI_LDAC) { /* LDAC support */
2217 snd_ac97_determine_rates(ac97, AC97_PCM_LFE_DAC_RATE, AC97_PCM_FRONT_DAC_RATE, &ac97->rates[AC97_RATES_LFE_DAC]);
2218 ac97->scaps |= AC97_SCAP_CENTER_LFE_DAC;
2222 bus->ops->init(ac97);
2223 snd_ac97_get_name(ac97, ac97->id, name, !ac97_is_audio(ac97));
2224 snd_ac97_get_name(NULL, ac97->id, name, !ac97_is_audio(ac97)); // ac97->id might be changed in the special setup code
2225 if (! ac97->build_ops)
2226 ac97->build_ops = &null_build_ops;
2228 if (ac97_is_audio(ac97)) {
2238 sprintf(comp, "AC97a:%08x", ac97->id);
2240 snd_ac97_free(ac97);
2243 if (snd_ac97_mixer_build(ac97) < 0) {
2244 snd_ac97_free(ac97);
2248 if (ac97_is_modem(ac97)) {
2258 sprintf(comp, "AC97m:%08x", ac97->id);
2260 snd_ac97_free(ac97);
2263 if (snd_ac97_modem_build(card, ac97) < 0) {
2264 snd_ac97_free(ac97);
2268 if (ac97_is_audio(ac97))
2269 update_power_regs(ac97);
2270 snd_ac97_proc_init(ac97);
2271 if ((err = snd_device_new(card, SNDRV_DEV_CODEC, ac97, &ops)) < 0) {
2272 snd_ac97_free(ac97);
2275 *rac97 = ac97;
2287 static void snd_ac97_powerdown(struct snd_ac97 *ac97)
2291 if (ac97_is_audio(ac97)) {
2293 snd_ac97_write(ac97, AC97_MASTER, 0x9f9f);
2294 snd_ac97_write(ac97, AC97_HEADPHONE, 0x9f9f);
2298 power = ac97->regs[AC97_EXTENDED_STATUS];
2299 if (ac97->scaps & AC97_SCAP_SURROUND_DAC)
2301 if (ac97->scaps & AC97_SCAP_CENTER_LFE_DAC)
2304 snd_ac97_write(ac97, AC97_EXTENDED_STATUS, power);
2307 if (ac97->scaps & AC97_SCAP_INV_EAPD)
2308 power = ac97->regs[AC97_POWERDOWN] & ~AC97_PD_EAPD;
2309 else if (! (ac97->scaps & AC97_SCAP_EAPD_LED))
2310 power = ac97->regs[AC97_POWERDOWN] | AC97_PD_EAPD;
2313 snd_ac97_write(ac97, AC97_POWERDOWN, power);
2316 snd_ac97_write(ac97, AC97_POWERDOWN, power);
2317 if (ac97_is_power_save_mode(ac97)) {
2319 snd_ac97_write(ac97, AC97_POWERDOWN, power);
2323 snd_ac97_write(ac97, AC97_POWERDOWN, power);
2350 * @ac97: the codec instance
2356 int snd_ac97_update_power(struct snd_ac97 *ac97, int reg, int powerup)
2360 if (! ac97)
2370 ac97->power_up |= (1 << i);
2372 ac97->power_up &= ~(1 << i);
2378 if (ac97_is_power_save_mode(ac97) && !powerup)
2383 schedule_delayed_work(&ac97->power_work,
2386 cancel_delayed_work(&ac97->power_work);
2387 update_power_regs(ac97);
2396 static void update_power_regs(struct snd_ac97 *ac97)
2403 if (ac97->scaps & AC97_SCAP_SURROUND_DAC)
2405 if (ac97->scaps & AC97_SCAP_CENTER_LFE_DAC)
2408 if (ac97_is_power_save_mode(ac97))
2409 power_up = ac97->power_up;
2412 if (ac97->regs[AC97_POWERDOWN] & AC97_PD_PR2) {
2414 snd_ac97_update_bits(ac97, AC97_POWERDOWN,
2417 snd_ac97_update_bits(ac97, AC97_POWERDOWN,
2426 snd_ac97_update_bits(ac97, power_regs[i].power_reg,
2430 if (! (ac97->regs[AC97_POWERDOWN] & AC97_PD_PR2)) {
2432 snd_ac97_update_bits(ac97, AC97_POWERDOWN,
2434 snd_ac97_update_bits(ac97, AC97_POWERDOWN,
2444 * @ac97: the ac97 instance
2448 void snd_ac97_suspend(struct snd_ac97 *ac97)
2450 if (! ac97)
2452 if (ac97->build_ops->suspend)
2453 ac97->build_ops->suspend(ac97);
2455 cancel_delayed_work(&ac97->power_work);
2458 snd_ac97_powerdown(ac97);
2464 * restore ac97 status
2466 static void snd_ac97_restore_status(struct snd_ac97 *ac97)
2477 if (test_bit(i, ac97->reg_accessed)) {
2478 snd_ac97_write(ac97, i, ac97->regs[i]);
2479 snd_ac97_read(ac97, i);
2487 static void snd_ac97_restore_iec958(struct snd_ac97 *ac97)
2489 if (ac97->ext_id & AC97_EI_SPDIF) {
2490 if (ac97->regs[AC97_EXTENDED_STATUS] & AC97_EA_SPDIF) {
2492 snd_ac97_update_bits(ac97, AC97_EXTENDED_STATUS, AC97_EA_SPDIF, 0);
2493 snd_ac97_write(ac97, AC97_EXTENDED_STATUS, ac97->regs[AC97_EXTENDED_STATUS]);
2494 if (ac97->flags & AC97_CS_SPDIF)
2495 snd_ac97_write(ac97, AC97_CSR_SPDIF, ac97->regs[AC97_CSR_SPDIF]);
2497 snd_ac97_write(ac97, AC97_SPDIF, ac97->regs[AC97_SPDIF]);
2498 snd_ac97_update_bits(ac97, AC97_EXTENDED_STATUS, AC97_EA_SPDIF, AC97_EA_SPDIF); /* turn on again */
2505 * @ac97: the ac97 instance
2510 void snd_ac97_resume(struct snd_ac97 *ac97)
2514 if (! ac97)
2517 if (ac97->bus->ops->reset) {
2518 ac97->bus->ops->reset(ac97);
2522 snd_ac97_write(ac97, AC97_POWERDOWN, 0);
2523 if (! (ac97->flags & AC97_DEFAULT_POWER_OFF)) {
2524 if (!(ac97->scaps & AC97_SCAP_SKIP_AUDIO))
2525 snd_ac97_write(ac97, AC97_RESET, 0);
2526 else if (!(ac97->scaps & AC97_SCAP_SKIP_MODEM))
2527 snd_ac97_write(ac97, AC97_EXTENDED_MID, 0);
2529 snd_ac97_write(ac97, AC97_POWERDOWN, 0);
2531 snd_ac97_write(ac97, AC97_GENERAL_PURPOSE, 0);
2533 snd_ac97_write(ac97, AC97_POWERDOWN, ac97->regs[AC97_POWERDOWN]);
2534 if (ac97_is_audio(ac97)) {
2535 ac97->bus->ops->write(ac97, AC97_MASTER, 0x8101);
2538 if (snd_ac97_read(ac97, AC97_MASTER) == 0x8101)
2542 ac97->bus->ops->write(ac97, AC97_MASTER, 0x8000);
2543 if (snd_ac97_read(ac97, AC97_MASTER) != 0x8000)
2548 unsigned short val = snd_ac97_read(ac97, AC97_EXTENDED_MID);
2556 if (ac97->bus->ops->init)
2557 ac97->bus->ops->init(ac97);
2559 if (ac97->build_ops->resume)
2560 ac97->build_ops->resume(ac97);
2562 snd_ac97_restore_status(ac97);
2563 snd_ac97_restore_iec958(ac97);
2583 static int snd_ac97_remove_ctl(struct snd_ac97 *ac97, const char *name,
2590 return snd_ctl_remove_id(ac97->bus->card, &id);
2593 static struct snd_kcontrol *ctl_find(struct snd_ac97 *ac97, const char *name, const char *suffix)
2599 return snd_ctl_find_id(ac97->bus->card, &sid);
2603 static int snd_ac97_rename_ctl(struct snd_ac97 *ac97, const char *src,
2606 struct snd_kcontrol *kctl = ctl_find(ac97, src, suffix);
2615 static void snd_ac97_rename_vol_ctl(struct snd_ac97 *ac97, const char *src,
2618 snd_ac97_rename_ctl(ac97, src, dst, "Switch");
2619 snd_ac97_rename_ctl(ac97, src, dst, "Volume");
2623 static int snd_ac97_swap_ctl(struct snd_ac97 *ac97, const char *s1,
2627 kctl1 = ctl_find(ac97, s1, suffix);
2628 kctl2 = ctl_find(ac97, s2, suffix);
2650 /* ac97 tune: bind Master and Headphone controls */
2651 static int tune_hp_only(struct snd_ac97 *ac97)
2653 struct snd_kcontrol *msw = ctl_find(ac97, "Master Playback Switch", NULL);
2654 struct snd_kcontrol *mvol = ctl_find(ac97, "Master Playback Volume", NULL);
2659 snd_ac97_remove_ctl(ac97, "Headphone Playback", "Switch");
2660 snd_ac97_remove_ctl(ac97, "Headphone Playback", "Volume");
2664 /* ac97 tune: swap Headphone and Master controls */
2665 static int tune_swap_hp(struct snd_ac97 *ac97)
2667 if (ctl_find(ac97, "Headphone Playback Switch", NULL) == NULL)
2669 snd_ac97_rename_vol_ctl(ac97, "Master Playback", "Line-Out Playback");
2670 snd_ac97_rename_vol_ctl(ac97, "Headphone Playback", "Master Playback");
2674 /* ac97 tune: swap Surround and Master controls */
2675 static int tune_swap_surround(struct snd_ac97 *ac97)
2677 if (snd_ac97_swap_ctl(ac97, "Master Playback", "Surround Playback", "Switch") ||
2678 snd_ac97_swap_ctl(ac97, "Master Playback", "Surround Playback", "Volume"))
2683 /* ac97 tune: set up mic sharing for AD codecs */
2684 static int tune_ad_sharing(struct snd_ac97 *ac97)
2687 if ((ac97->id & 0xffffff00) != 0x41445300) {
2692 scfg = snd_ac97_read(ac97, AC97_AD_SERIAL_CFG);
2693 snd_ac97_write_cache(ac97, AC97_AD_SERIAL_CFG, scfg | 0x0200);
2700 /* ac97 tune: set up ALC jack-select */
2701 static int tune_alc_jack(struct snd_ac97 *ac97)
2703 if ((ac97->id & 0xffffff00) != 0x414c4700) {
2707 snd_ac97_update_bits(ac97, 0x7a, 0x20, 0x20); /* select jack detect function */
2708 snd_ac97_update_bits(ac97, 0x7a, 0x01, 0x01); /* Line-out auto mute */
2709 if (ac97->id == AC97_ID_ALC658D)
2710 snd_ac97_update_bits(ac97, 0x74, 0x0800, 0x0800);
2711 return snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&snd_ac97_alc_jack_detect, ac97));
2714 /* ac97 tune: inversed EAPD bit */
2715 static int tune_inv_eapd(struct snd_ac97 *ac97)
2717 struct snd_kcontrol *kctl = ctl_find(ac97, "External Amplifier", NULL);
2720 set_inv_eapd(ac97, kctl);
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 /* ac97 tune: EAPD controls mute LED bound with the master mute */
2744 static int tune_mute_led(struct snd_ac97 *ac97)
2746 struct snd_kcontrol *msw = ctl_find(ac97, "Master Playback Switch", NULL);
2750 snd_ac97_remove_ctl(ac97, "External Amplifier", NULL);
2751 snd_ac97_update_bits(ac97, AC97_POWERDOWN, 0x8000, 0x8000); /* mute LED on */
2752 ac97->scaps |= AC97_SCAP_EAPD_LED;
2761 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
2769 snd_ac97_update_bits(ac97, AC97_POWERDOWN, 0x8000,
2770 (ac97->regs[AC97_MASTER] & mask) == mask ?
2776 static int tune_hp_mute_led(struct snd_ac97 *ac97)
2778 struct snd_kcontrol *msw = ctl_find(ac97, "Master Playback Switch", NULL);
2779 struct snd_kcontrol *mvol = ctl_find(ac97, "Master Playback Volume", NULL);
2784 snd_ac97_remove_ctl(ac97, "External Amplifier", NULL);
2785 snd_ac97_remove_ctl(ac97, "Headphone Playback", "Switch");
2786 snd_ac97_remove_ctl(ac97, "Headphone Playback", "Volume");
2787 snd_ac97_update_bits(ac97, AC97_POWERDOWN, 0x8000, 0x8000); /* mute LED on */
2809 static int apply_quirk(struct snd_ac97 *ac97, int type)
2816 return applicable_quirks[type].func(ac97);
2821 static int apply_quirk_str(struct snd_ac97 *ac97, const char *typestr)
2829 return apply_quirk(ac97, i);
2833 return apply_quirk(ac97, (int)simple_strtoul(typestr, NULL, 10));
2838 int snd_ac97_tune_hardware(struct snd_ac97 *ac97, struct ac97_quirk *quirk, const char *override)
2844 result = apply_quirk_str(ac97, override);
2854 if (quirk->subvendor != ac97->subsystem_vendor)
2856 if ((! quirk->mask && quirk->subdevice == ac97->subsystem_device) ||
2857 quirk->subdevice == (quirk->mask & ac97->subsystem_device)) {
2858 if (quirk->codec_id && quirk->codec_id != ac97->id)
2860 snd_printdd("ac97 quirk for %s (%04x:%04x)\n", quirk->name, ac97->subsystem_vendor, ac97->subsystem_device);
2861 result = apply_quirk(ac97, quirk->type);