Lines Matching refs:ac97

49 	int (*patch)(struct snd_ac97 *ac97);
50 int (*mpatch)(struct snd_ac97 *ac97);
195 static void update_power_regs(struct snd_ac97 *ac97);
197 #define ac97_is_power_save_mode(ac97) \
198 ((ac97->scaps & AC97_SCAP_POWER_SAVE) && power_save)
200 #define ac97_is_power_save_mode(ac97) 0
203 #define ac97_err(ac97, fmt, args...) \
204 dev_err((ac97)->bus->card->dev, fmt, ##args)
205 #define ac97_warn(ac97, fmt, args...) \
206 dev_warn((ac97)->bus->card->dev, fmt, ##args)
207 #define ac97_dbg(ac97, fmt, args...) \
208 dev_dbg((ac97)->bus->card->dev, fmt, ##args)
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);
459 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
465 val = snd_ac97_read_cache(ac97, e->reg);
476 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
493 return snd_ac97_update_bits(ac97, e->reg, mask, val);
496 /* save/restore ac97 v2.3 paging */
497 static int snd_ac97_page_save(struct snd_ac97 *ac97, int reg, struct snd_kcontrol *kcontrol)
501 (ac97->ext_id & AC97_EI_REV_MASK) >= AC97_EI_REV_23 &&
504 mutex_lock(&ac97->page_mutex); /* lock paging */
505 page_save = snd_ac97_read(ac97, AC97_INT_PAGING) & AC97_PAGE_MASK;
506 snd_ac97_update_bits(ac97, AC97_INT_PAGING, AC97_PAGE_MASK, page);
511 static void snd_ac97_page_restore(struct snd_ac97 *ac97, int page_save)
514 snd_ac97_update_bits(ac97, AC97_INT_PAGING, AC97_PAGE_MASK, page_save);
515 mutex_unlock(&ac97->page_mutex); /* unlock paging */
537 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
545 page_save = snd_ac97_page_save(ac97, reg, kcontrol);
546 ucontrol->value.integer.value[0] = (snd_ac97_read_cache(ac97, reg) >> shift) & mask;
548 ucontrol->value.integer.value[1] = (snd_ac97_read_cache(ac97, reg) >> rshift) & mask;
554 snd_ac97_page_restore(ac97, page_save);
561 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
570 page_save = snd_ac97_page_save(ac97, reg, kcontrol);
583 err = snd_ac97_update_bits(ac97, reg, val_mask, val);
584 snd_ac97_page_restore(ac97, page_save);
590 ac97->power_up &= ~(1 << (reg>>1));
592 ac97->power_up |= 1 << (reg>>1);
593 update_power_regs(ac97);
680 static void set_inv_eapd(struct snd_ac97 *ac97, struct snd_kcontrol *kctl)
683 snd_ac97_update_bits(ac97, AC97_POWERDOWN, (1<<15), (1<<15)); /* EAPD up */
684 ac97->scaps |= AC97_SCAP_INV_EAPD;
718 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
720 mutex_lock(&ac97->reg_mutex);
721 ucontrol->value.iec958.status[0] = ac97->spdif_status & 0xff;
722 ucontrol->value.iec958.status[1] = (ac97->spdif_status >> 8) & 0xff;
723 ucontrol->value.iec958.status[2] = (ac97->spdif_status >> 16) & 0xff;
724 ucontrol->value.iec958.status[3] = (ac97->spdif_status >> 24) & 0xff;
725 mutex_unlock(&ac97->reg_mutex);
731 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
764 mutex_lock(&ac97->reg_mutex);
765 change = ac97->spdif_status != new;
766 ac97->spdif_status = new;
768 if (ac97->flags & AC97_CS_SPDIF) {
775 change |= snd_ac97_update_bits_nolock(ac97, AC97_CSR_SPDIF, 0x3fff, ((val & 0xcfff) | (x << 12)));
776 } else if (ac97->flags & AC97_CX_SPDIF) {
780 change |= snd_ac97_update_bits_nolock(ac97, AC97_CXR_AUDIO_MISC,
783 } else if (ac97->id == AC97_ID_YMF743) {
784 change |= snd_ac97_update_bits_nolock(ac97,
790 unsigned short extst = snd_ac97_read_cache(ac97, AC97_EXTENDED_STATUS);
791 snd_ac97_update_bits_nolock(ac97, AC97_EXTENDED_STATUS, AC97_EA_SPDIF, 0); /* turn off */
793 change |= snd_ac97_update_bits_nolock(ac97, AC97_SPDIF, 0x3fff, val);
795 snd_ac97_update_bits_nolock(ac97, AC97_EXTENDED_STATUS, AC97_EA_SPDIF, AC97_EA_SPDIF); /* turn on again */
798 mutex_unlock(&ac97->reg_mutex);
805 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
815 mutex_lock(&ac97->reg_mutex);
818 old = snd_ac97_read_cache(ac97, reg);
823 unsigned short extst = snd_ac97_read_cache(ac97, AC97_EXTENDED_STATUS);
824 snd_ac97_update_bits_nolock(ac97, AC97_EXTENDED_STATUS, AC97_EA_SPDIF, 0); /* turn off */
825 change = snd_ac97_update_bits_nolock(ac97, reg, mask, value);
827 snd_ac97_update_bits_nolock(ac97, AC97_EXTENDED_STATUS, AC97_EA_SPDIF, AC97_EA_SPDIF); /* turn on again */
829 mutex_unlock(&ac97->reg_mutex);
874 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
880 if (lshift != rshift && (ac97->flags & AC97_STEREO_MUTES))
891 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
897 ucontrol->value.integer.value[0] = mask - ((ac97->spec.ad18xx.pcmreg[codec] >> lshift) & mask);
898 if (lshift != rshift && (ac97->flags & AC97_STEREO_MUTES))
899 ucontrol->value.integer.value[1] = mask - ((ac97->spec.ad18xx.pcmreg[codec] >> rshift) & mask);
905 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
914 if (lshift != rshift && (ac97->flags & AC97_STEREO_MUTES)) {
918 return snd_ac97_ad18xx_update_pcm_bits(ac97, codec, valmask, val);
937 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
940 mutex_lock(&ac97->page_mutex);
941 ucontrol->value.integer.value[0] = 31 - ((ac97->spec.ad18xx.pcmreg[codec] >> 8) & 31);
942 ucontrol->value.integer.value[1] = 31 - ((ac97->spec.ad18xx.pcmreg[codec] >> 0) & 31);
943 mutex_unlock(&ac97->page_mutex);
949 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
955 return snd_ac97_ad18xx_update_pcm_bits(ac97, codec, 0x1f1f, (val1 << 8) | val2);
982 static void snd_ac97_powerdown(struct snd_ac97 *ac97);
1002 static int snd_ac97_free(struct snd_ac97 *ac97)
1004 if (ac97) {
1006 cancel_delayed_work_sync(&ac97->power_work);
1008 snd_ac97_proc_done(ac97);
1009 if (ac97->bus)
1010 ac97->bus->codec[ac97->num] = NULL;
1011 if (ac97->private_free)
1012 ac97->private_free(ac97);
1013 kfree(ac97);
1020 struct snd_ac97 *ac97 = device->device_data;
1021 snd_ac97_powerdown(ac97); /* for avoiding click noises during shut down */
1022 return snd_ac97_free(ac97);
1025 static int snd_ac97_try_volume_mix(struct snd_ac97 * ac97, int reg)
1029 if (! snd_ac97_valid_reg(ac97, reg))
1034 return ac97->caps & AC97_BC_BASS_TREBLE ? 1 : 0;
1036 return ac97->caps & AC97_BC_HEADPHONE ? 1 : 0;
1038 return ac97->caps & AC97_BC_DEDICATED_MIC ? 1 : 0;
1040 if (ac97->caps & AC97_BC_3D_TECH_ID_MASK) {
1041 val = snd_ac97_read(ac97, reg);
1047 if ((ac97->ext_id & AC97_EI_CDAC) == 0)
1051 if ((ac97->ext_id & AC97_EI_LDAC) == 0)
1057 if ((ac97->ext_id & AC97_EI_SDAC) == 0)
1062 val = snd_ac97_read(ac97, reg);
1066 snd_ac97_write_cache(ac97, reg, val | mask);
1067 val = snd_ac97_read(ac97, reg);
1068 val = snd_ac97_read(ac97, reg);
1075 static void check_volume_resolution(struct snd_ac97 *ac97, int reg, unsigned char *lo_max, unsigned char *hi_max)
1082 if (ac97->res_table) {
1084 for (tbl = ac97->res_table; tbl->reg; tbl++) {
1097 ac97, reg,
1100 /* Do the read twice due to buffers on some ac97 codecs.
1104 val = snd_ac97_read(ac97, reg);
1105 val = snd_ac97_read(ac97, reg);
1115 static int snd_ac97_try_bit(struct snd_ac97 * ac97, int reg, int bit)
1120 orig = snd_ac97_read(ac97, reg);
1122 snd_ac97_write(ac97, reg, val);
1123 res = snd_ac97_read(ac97, reg);
1124 snd_ac97_write_cache(ac97, reg, orig);
1129 static void snd_ac97_change_volume_params2(struct snd_ac97 * ac97, int reg, int shift, unsigned char *max)
1135 snd_ac97_write(ac97, reg, val);
1136 val1 = snd_ac97_read(ac97, reg);
1141 snd_ac97_write_cache(ac97, reg, AC97_MUTE_MASK_STEREO);
1156 struct snd_ac97 * ac97)
1160 template.index = ac97->num;
1161 return snd_ctl_new1(&template, ac97);
1169 struct snd_ac97 *ac97)
1175 if (! snd_ac97_valid_reg(ac97, reg))
1179 val = snd_ac97_read(ac97, reg);
1180 if (check_stereo || (ac97->flags & AC97_STEREO_MUTES)) {
1183 snd_ac97_write(ac97, reg, val1);
1184 if (val1 == snd_ac97_read(ac97, reg))
1191 tmp.index = ac97->num;
1192 kctl = snd_ctl_new1(&tmp, ac97);
1197 tmp.index = ac97->num;
1198 kctl = snd_ctl_new1(&tmp, ac97);
1204 snd_ac97_write_cache(ac97, reg, val | mute_mask);
1238 unsigned int hi_max, struct snd_ac97 *ac97)
1243 if (! snd_ac97_valid_reg(ac97, reg))
1248 tmp.index = ac97->num;
1249 kctl = snd_ctl_new1(&tmp, ac97);
1253 tmp.index = ac97->num;
1254 kctl = snd_ctl_new1(&tmp, ac97);
1266 ac97, reg,
1267 (snd_ac97_read(ac97, reg) & AC97_MUTE_MASK_STEREO)
1278 struct snd_ac97 *ac97)
1284 if (! snd_ac97_valid_reg(ac97, reg))
1287 if (snd_ac97_try_bit(ac97, reg, 15)) {
1291 ac97)) < 0)
1294 check_volume_resolution(ac97, reg, &lo_max, &hi_max);
1297 if ((err = snd_ac97_cvol_new(card, name, reg, lo_max, hi_max, ac97)) < 0)
1303 #define snd_ac97_cmix_new(card, pfx, reg, acheck, ac97) \
1304 snd_ac97_cmix_new_stereo(card, pfx, reg, 0, acheck, ac97)
1305 #define snd_ac97_cmute_new(card, name, reg, acheck, ac97) \
1306 snd_ac97_cmute_new_stereo(card, name, reg, 0, acheck, ac97)
1308 static unsigned int snd_ac97_determine_spdif_rates(struct snd_ac97 *ac97);
1310 static int snd_ac97_mixer_build(struct snd_ac97 * ac97)
1312 struct snd_card *card = ac97->bus->card;
1320 if (snd_ac97_try_volume_mix(ac97, AC97_MASTER)) {
1321 if (ac97->flags & AC97_HAS_NO_MASTER_VOL)
1323 AC97_MASTER, 0, ac97);
1326 AC97_MASTER, 0, ac97);
1331 ac97->regs[AC97_CENTER_LFE_MASTER] = AC97_MUTE_MASK_STEREO;
1334 if ((snd_ac97_try_volume_mix(ac97, AC97_CENTER_LFE_MASTER))
1335 && !(ac97->flags & AC97_AD_MULTI)) {
1336 if ((err = snd_ctl_add(card, snd_ac97_cnew(&snd_ac97_controls_center[0], ac97))) < 0)
1338 if ((err = snd_ctl_add(card, kctl = snd_ac97_cnew(&snd_ac97_controls_center[1], ac97))) < 0)
1340 snd_ac97_change_volume_params2(ac97, AC97_CENTER_LFE_MASTER, 0, &max);
1344 snd_ac97_write_cache(ac97, AC97_CENTER_LFE_MASTER, ac97->regs[AC97_CENTER_LFE_MASTER] | max);
1348 if ((snd_ac97_try_volume_mix(ac97, AC97_CENTER_LFE_MASTER+1))
1349 && !(ac97->flags & AC97_AD_MULTI)) {
1350 if ((err = snd_ctl_add(card, snd_ac97_cnew(&snd_ac97_controls_lfe[0], ac97))) < 0)
1352 if ((err = snd_ctl_add(card, kctl = snd_ac97_cnew(&snd_ac97_controls_lfe[1], ac97))) < 0)
1354 snd_ac97_change_volume_params2(ac97, AC97_CENTER_LFE_MASTER, 8, &max);
1358 snd_ac97_write_cache(ac97, AC97_CENTER_LFE_MASTER, ac97->regs[AC97_CENTER_LFE_MASTER] | max << 8);
1362 if ((snd_ac97_try_volume_mix(ac97, AC97_SURROUND_MASTER))
1363 && !(ac97->flags & AC97_AD_MULTI)) {
1367 ac97)) < 0)
1372 if (snd_ac97_try_volume_mix(ac97, AC97_HEADPHONE)) {
1374 AC97_HEADPHONE, 0, ac97)) < 0)
1379 if (snd_ac97_try_volume_mix(ac97, AC97_MASTER_MONO)) {
1381 AC97_MASTER_MONO, 0, ac97)) < 0)
1386 if (!(ac97->flags & AC97_HAS_NO_TONE)) {
1387 if (snd_ac97_try_volume_mix(ac97, AC97_MASTER_TONE)) {
1389 if ((err = snd_ctl_add(card, kctl = snd_ac97_cnew(&snd_ac97_controls_tone[idx], ac97))) < 0)
1391 if (ac97->id == AC97_ID_YMF743 ||
1392 ac97->id == AC97_ID_YMF753) {
1397 snd_ac97_write_cache(ac97, AC97_MASTER_TONE, 0x0f0f);
1402 if (!(ac97->flags & AC97_HAS_NO_PC_BEEP) &&
1403 ((ac97->flags & AC97_HAS_PC_BEEP) ||
1404 snd_ac97_try_volume_mix(ac97, AC97_PC_BEEP))) {
1406 if ((err = snd_ctl_add(card, kctl = snd_ac97_cnew(&snd_ac97_controls_pc_beep[idx], ac97))) < 0)
1410 ac97,
1412 (snd_ac97_read(ac97, AC97_PC_BEEP)
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 & AC97_BC_SIM_STEREO) {
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 & AC97_BC_LOUDNESS) {
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)
1657 ac97_dbg(ac97, "AC97_GPIO_CFG = %x\n",
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)
1935 /* register ac97 codec to bus */
1938 struct snd_ac97 *ac97 = device->device_data;
1941 ac97->dev.bus = &ac97_bus_type;
1942 ac97->dev.parent = ac97->bus->card->dev;
1943 ac97->dev.release = ac97_device_release;
1944 dev_set_name(&ac97->dev, "%d-%d:%s",
1945 ac97->bus->card->number, ac97->num,
1946 snd_ac97_get_short_name(ac97));
1947 if ((err = device_register(&ac97->dev)) < 0) {
1948 ac97_err(ac97, "Can't register ac97 bus\n");
1949 put_device(&ac97->dev);
1950 ac97->dev.bus = NULL;
1956 /* disconnect ac97 codec */
1959 struct snd_ac97 *ac97 = device->device_data;
1960 if (ac97->dev.bus)
1961 device_unregister(&ac97->dev);
1979 * @template: the template of ac97, including index, callbacks and
1981 * @rac97: the pointer to store the new ac97 instance.
1990 * The ac97 instance is registered as a low-level device, so you don't
1998 struct snd_ac97 *ac97;
2019 ac97 = kzalloc(sizeof(*ac97), GFP_KERNEL);
2020 if (ac97 == NULL)
2022 ac97->private_data = template->private_data;
2023 ac97->private_free = template->private_free;
2024 ac97->bus = bus;
2025 ac97->pci = template->pci;
2026 ac97->num = template->num;
2027 ac97->addr = template->addr;
2028 ac97->scaps = template->scaps;
2029 ac97->res_table = template->res_table;
2030 bus->codec[ac97->num] = ac97;
2031 mutex_init(&ac97->reg_mutex);
2032 mutex_init(&ac97->page_mutex);
2034 INIT_DELAYED_WORK(&ac97->power_work, do_update_power);
2038 if (ac97->pci) {
2039 pci_read_config_word(ac97->pci, PCI_SUBSYSTEM_VENDOR_ID, &ac97->subsystem_vendor);
2040 pci_read_config_word(ac97->pci, PCI_SUBSYSTEM_ID, &ac97->subsystem_device);
2044 bus->ops->reset(ac97);
2048 ac97->id = snd_ac97_read(ac97, AC97_VENDOR_ID1) << 16;
2049 ac97->id |= snd_ac97_read(ac97, AC97_VENDOR_ID2);
2050 if (ac97->id && ac97->id != (unsigned int)-1) {
2051 pid = look_for_codec_id(snd_ac97_codec_ids, ac97->id);
2057 if (!(ac97->scaps & AC97_SCAP_SKIP_AUDIO))
2058 snd_ac97_write(ac97, AC97_RESET, 0);
2059 if (!(ac97->scaps & AC97_SCAP_SKIP_MODEM))
2060 snd_ac97_write(ac97, AC97_EXTENDED_MID, 0);
2062 bus->ops->wait(ac97);
2065 if (ac97->scaps & AC97_SCAP_SKIP_AUDIO)
2066 err = ac97_reset_wait(ac97, msecs_to_jiffies(500), 1);
2068 err = ac97_reset_wait(ac97, msecs_to_jiffies(500), 0);
2070 err = ac97_reset_wait(ac97,
2074 ac97_warn(ac97, "AC'97 %d does not respond - RESET\n",
2075 ac97->num);
2080 ac97->id = snd_ac97_read(ac97, AC97_VENDOR_ID1) << 16;
2081 ac97->id |= snd_ac97_read(ac97, AC97_VENDOR_ID2);
2082 if (! (ac97->scaps & AC97_SCAP_DETECT_BY_VENDOR) &&
2083 (ac97->id == 0x00000000 || ac97->id == 0xffffffff)) {
2084 ac97_err(ac97,
2086 ac97->num, ac97->id);
2087 snd_ac97_free(ac97);
2090 pid = look_for_codec_id(snd_ac97_codec_ids, ac97->id);
2092 ac97->flags |= pid->flags;
2095 if (!(ac97->scaps & AC97_SCAP_SKIP_AUDIO) && !(ac97->scaps & AC97_SCAP_AUDIO)) {
2097 snd_ac97_write_cache(ac97, AC97_REC_GAIN, 0x8a06);
2098 if (((err = snd_ac97_read(ac97, AC97_REC_GAIN)) & 0x7fff) == 0x0a06)
2099 ac97->scaps |= AC97_SCAP_AUDIO;
2101 if (ac97->scaps & AC97_SCAP_AUDIO) {
2102 ac97->caps = snd_ac97_read(ac97, AC97_RESET);
2103 ac97->ext_id = snd_ac97_read(ac97, AC97_EXTENDED_ID);
2104 if (ac97->ext_id == 0xffff) /* invalid combination */
2105 ac97->ext_id = 0;
2109 if (!(ac97->scaps & AC97_SCAP_SKIP_MODEM) && !(ac97->scaps & AC97_SCAP_MODEM)) {
2110 ac97->ext_mid = snd_ac97_read(ac97, AC97_EXTENDED_MID);
2111 if (ac97->ext_mid == 0xffff) /* invalid combination */
2112 ac97->ext_mid = 0;
2113 if (ac97->ext_mid & 1)
2114 ac97->scaps |= AC97_SCAP_MODEM;
2117 if (!ac97_is_audio(ac97) && !ac97_is_modem(ac97)) {
2118 if (!(ac97->scaps & (AC97_SCAP_SKIP_AUDIO|AC97_SCAP_SKIP_MODEM)))
2119 ac97_err(ac97,
2121 ac97->num);
2122 snd_ac97_free(ac97);
2130 if (ac97_is_audio(ac97)) {
2132 snd_ac97_write_cache(ac97, AC97_POWERDOWN, 0);
2133 if (! (ac97->flags & AC97_DEFAULT_POWER_OFF)) {
2134 snd_ac97_write_cache(ac97, AC97_RESET, 0); /* reset to defaults */
2136 snd_ac97_write_cache(ac97, AC97_POWERDOWN, 0);
2139 snd_ac97_write_cache(ac97, AC97_GENERAL_PURPOSE, 0);
2142 if ((snd_ac97_read(ac97, AC97_POWERDOWN) & 0x0f) == 0x0f)
2146 ac97_warn(ac97,
2147 "AC'97 %d analog subsections not ready\n", ac97->num);
2151 if (ac97_is_modem(ac97)) {
2157 if (ac97->ext_mid & AC97_MEI_LINE1) {
2158 snd_ac97_write_cache(ac97, AC97_LINE1_RATE, 8000);
2161 if (ac97->ext_mid & AC97_MEI_LINE2) {
2162 snd_ac97_write_cache(ac97, AC97_LINE2_RATE, 8000);
2165 if (ac97->ext_mid & AC97_MEI_HANDSET) {
2166 snd_ac97_write_cache(ac97, AC97_HANDSET_RATE, 8000);
2169 snd_ac97_write_cache(ac97, AC97_EXTENDED_MSTATUS, 0);
2172 snd_ac97_write_cache(ac97, AC97_EXTENDED_MSTATUS, 0);
2175 if ((snd_ac97_read(ac97, AC97_EXTENDED_MSTATUS) & tmp) == tmp)
2179 ac97_warn(ac97,
2181 ac97->num,
2182 snd_ac97_read(ac97, AC97_EXTENDED_MSTATUS));
2186 if (ac97_is_audio(ac97))
2187 ac97->addr = (ac97->ext_id & AC97_EI_ADDR_MASK) >> AC97_EI_ADDR_SHIFT;
2189 ac97->addr = (ac97->ext_mid & AC97_MEI_ADDR_MASK) >> AC97_MEI_ADDR_SHIFT;
2190 if (ac97->ext_id & 0x01c9) { /* L/R, MIC, SDAC, LDAC VRA support */
2191 reg = snd_ac97_read(ac97, AC97_EXTENDED_STATUS);
2192 reg |= ac97->ext_id & 0x01c0; /* LDAC/SDAC/CDAC */
2194 reg |= ac97->ext_id & 0x0009; /* VRA/VRM */
2195 snd_ac97_write_cache(ac97, AC97_EXTENDED_STATUS, reg);
2197 if ((ac97->ext_id & AC97_EI_DRA) && bus->dra) {
2200 snd_ac97_update_bits(ac97, AC97_GENERAL_PURPOSE, AC97_GP_DRSS_MASK, AC97_GP_DRSS_78);
2201 if ((snd_ac97_read(ac97, AC97_GENERAL_PURPOSE) & AC97_GP_DRSS_MASK) == AC97_GP_DRSS_78)
2202 ac97->flags |= AC97_DOUBLE_RATE;
2204 snd_ac97_update_bits(ac97, AC97_GENERAL_PURPOSE, AC97_GP_DRSS_MASK, 0);
2206 if (ac97->ext_id & AC97_EI_VRA) { /* VRA support */
2207 snd_ac97_determine_rates(ac97, AC97_PCM_FRONT_DAC_RATE, 0, &ac97->rates[AC97_RATES_FRONT_DAC]);
2208 snd_ac97_determine_rates(ac97, AC97_PCM_LR_ADC_RATE, 0, &ac97->rates[AC97_RATES_ADC]);
2210 ac97->rates[AC97_RATES_FRONT_DAC] = SNDRV_PCM_RATE_48000;
2211 if (ac97->flags & AC97_DOUBLE_RATE)
2212 ac97->rates[AC97_RATES_FRONT_DAC] |= SNDRV_PCM_RATE_96000;
2213 ac97->rates[AC97_RATES_ADC] = SNDRV_PCM_RATE_48000;
2215 if (ac97->ext_id & AC97_EI_SPDIF) {
2217 ac97->rates[AC97_RATES_SPDIF] = SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_32000;
2219 if (ac97->ext_id & AC97_EI_VRM) { /* MIC VRA support */
2220 snd_ac97_determine_rates(ac97, AC97_PCM_MIC_ADC_RATE, 0, &ac97->rates[AC97_RATES_MIC_ADC]);
2222 ac97->rates[AC97_RATES_MIC_ADC] = SNDRV_PCM_RATE_48000;
2224 if (ac97->ext_id & AC97_EI_SDAC) { /* SDAC support */
2225 snd_ac97_determine_rates(ac97, AC97_PCM_SURR_DAC_RATE, AC97_PCM_FRONT_DAC_RATE, &ac97->rates[AC97_RATES_SURR_DAC]);
2226 ac97->scaps |= AC97_SCAP_SURROUND_DAC;
2228 if (ac97->ext_id & AC97_EI_LDAC) { /* LDAC support */
2229 snd_ac97_determine_rates(ac97, AC97_PCM_LFE_DAC_RATE, AC97_PCM_FRONT_DAC_RATE, &ac97->rates[AC97_RATES_LFE_DAC]);
2230 ac97->scaps |= AC97_SCAP_CENTER_LFE_DAC;
2234 bus->ops->init(ac97);
2235 snd_ac97_get_name(ac97, ac97->id, name, !ac97_is_audio(ac97));
2236 snd_ac97_get_name(NULL, ac97->id, name, !ac97_is_audio(ac97)); // ac97->id might be changed in the special setup code
2237 if (! ac97->build_ops)
2238 ac97->build_ops = &null_build_ops;
2240 if (ac97_is_audio(ac97)) {
2250 sprintf(comp, "AC97a:%08x", ac97->id);
2252 snd_ac97_free(ac97);
2255 if (snd_ac97_mixer_build(ac97) < 0) {
2256 snd_ac97_free(ac97);
2260 if (ac97_is_modem(ac97)) {
2270 sprintf(comp, "AC97m:%08x", ac97->id);
2272 snd_ac97_free(ac97);
2275 if (snd_ac97_modem_build(card, ac97) < 0) {
2276 snd_ac97_free(ac97);
2280 if (ac97_is_audio(ac97))
2281 update_power_regs(ac97);
2282 snd_ac97_proc_init(ac97);
2283 if ((err = snd_device_new(card, SNDRV_DEV_CODEC, ac97, &ops)) < 0) {
2284 snd_ac97_free(ac97);
2287 *rac97 = ac97;
2299 static void snd_ac97_powerdown(struct snd_ac97 *ac97)
2303 if (ac97_is_audio(ac97)) {
2305 snd_ac97_write(ac97, AC97_MASTER, 0x9f9f);
2306 snd_ac97_write(ac97, AC97_HEADPHONE, 0x9f9f);
2310 power = ac97->regs[AC97_EXTENDED_STATUS];
2311 if (ac97->scaps & AC97_SCAP_SURROUND_DAC)
2313 if (ac97->scaps & AC97_SCAP_CENTER_LFE_DAC)
2316 snd_ac97_write(ac97, AC97_EXTENDED_STATUS, power);
2319 if (ac97->scaps & AC97_SCAP_INV_EAPD)
2320 power = ac97->regs[AC97_POWERDOWN] & ~AC97_PD_EAPD;
2321 else if (! (ac97->scaps & AC97_SCAP_EAPD_LED))
2322 power = ac97->regs[AC97_POWERDOWN] | AC97_PD_EAPD;
2325 snd_ac97_write(ac97, AC97_POWERDOWN, power);
2328 snd_ac97_write(ac97, AC97_POWERDOWN, power);
2329 if (ac97_is_power_save_mode(ac97)) {
2331 snd_ac97_write(ac97, AC97_POWERDOWN, power);
2336 snd_ac97_write(ac97, AC97_POWERDOWN, power);
2363 * @ac97: the codec instance
2371 int snd_ac97_update_power(struct snd_ac97 *ac97, int reg, int powerup)
2375 if (! ac97)
2385 ac97->power_up |= (1 << i);
2387 ac97->power_up &= ~(1 << i);
2393 if (ac97_is_power_save_mode(ac97) && !powerup)
2398 schedule_delayed_work(&ac97->power_work,
2401 cancel_delayed_work(&ac97->power_work);
2402 update_power_regs(ac97);
2411 static void update_power_regs(struct snd_ac97 *ac97)
2418 if (ac97->scaps & AC97_SCAP_SURROUND_DAC)
2420 if (ac97->scaps & AC97_SCAP_CENTER_LFE_DAC)
2423 if (ac97_is_power_save_mode(ac97))
2424 power_up = ac97->power_up;
2427 if (ac97->regs[AC97_POWERDOWN] & AC97_PD_PR2) {
2429 snd_ac97_update_bits(ac97, AC97_POWERDOWN,
2432 snd_ac97_update_bits(ac97, AC97_POWERDOWN,
2441 snd_ac97_update_bits(ac97, power_regs[i].power_reg,
2445 if (! (ac97->regs[AC97_POWERDOWN] & AC97_PD_PR2)) {
2447 snd_ac97_update_bits(ac97, AC97_POWERDOWN,
2449 snd_ac97_update_bits(ac97, AC97_POWERDOWN,
2459 * @ac97: the ac97 instance
2463 void snd_ac97_suspend(struct snd_ac97 *ac97)
2465 if (! ac97)
2467 if (ac97->build_ops->suspend)
2468 ac97->build_ops->suspend(ac97);
2470 cancel_delayed_work_sync(&ac97->power_work);
2472 snd_ac97_powerdown(ac97);
2478 * restore ac97 status
2480 static void snd_ac97_restore_status(struct snd_ac97 *ac97)
2491 if (test_bit(i, ac97->reg_accessed)) {
2492 snd_ac97_write(ac97, i, ac97->regs[i]);
2493 snd_ac97_read(ac97, i);
2501 static void snd_ac97_restore_iec958(struct snd_ac97 *ac97)
2503 if (ac97->ext_id & AC97_EI_SPDIF) {
2504 if (ac97->regs[AC97_EXTENDED_STATUS] & AC97_EA_SPDIF) {
2506 snd_ac97_update_bits(ac97, AC97_EXTENDED_STATUS, AC97_EA_SPDIF, 0);
2507 snd_ac97_write(ac97, AC97_EXTENDED_STATUS, ac97->regs[AC97_EXTENDED_STATUS]);
2508 if (ac97->flags & AC97_CS_SPDIF)
2509 snd_ac97_write(ac97, AC97_CSR_SPDIF, ac97->regs[AC97_CSR_SPDIF]);
2511 snd_ac97_write(ac97, AC97_SPDIF, ac97->regs[AC97_SPDIF]);
2512 snd_ac97_update_bits(ac97, AC97_EXTENDED_STATUS, AC97_EA_SPDIF, AC97_EA_SPDIF); /* turn on again */
2519 * @ac97: the ac97 instance
2524 void snd_ac97_resume(struct snd_ac97 *ac97)
2528 if (! ac97)
2531 if (ac97->bus->ops->reset) {
2532 ac97->bus->ops->reset(ac97);
2536 snd_ac97_write(ac97, AC97_POWERDOWN, 0);
2537 if (! (ac97->flags & AC97_DEFAULT_POWER_OFF)) {
2538 if (!(ac97->scaps & AC97_SCAP_SKIP_AUDIO))
2539 snd_ac97_write(ac97, AC97_RESET, 0);
2540 else if (!(ac97->scaps & AC97_SCAP_SKIP_MODEM))
2541 snd_ac97_write(ac97, AC97_EXTENDED_MID, 0);
2543 snd_ac97_write(ac97, AC97_POWERDOWN, 0);
2545 snd_ac97_write(ac97, AC97_GENERAL_PURPOSE, 0);
2547 snd_ac97_write(ac97, AC97_POWERDOWN, ac97->regs[AC97_POWERDOWN]);
2548 if (ac97_is_audio(ac97)) {
2549 ac97->bus->ops->write(ac97, AC97_MASTER, 0x8101);
2552 if (snd_ac97_read(ac97, AC97_MASTER) == 0x8101)
2557 ac97->bus->ops->write(ac97, AC97_MASTER, AC97_MUTE_MASK_MONO);
2558 if (snd_ac97_read(ac97, AC97_MASTER) != AC97_MUTE_MASK_MONO)
2563 unsigned short val = snd_ac97_read(ac97, AC97_EXTENDED_MID);
2571 if (ac97->bus->ops->init)
2572 ac97->bus->ops->init(ac97);
2574 if (ac97->build_ops->resume)
2575 ac97->build_ops->resume(ac97);
2577 snd_ac97_restore_status(ac97);
2578 snd_ac97_restore_iec958(ac97);
2598 static int snd_ac97_remove_ctl(struct snd_ac97 *ac97, const char *name,
2605 return snd_ctl_remove_id(ac97->bus->card, &id);
2608 static struct snd_kcontrol *ctl_find(struct snd_ac97 *ac97, const char *name, const char *suffix)
2614 return snd_ctl_find_id(ac97->bus->card, &sid);
2618 static int snd_ac97_rename_ctl(struct snd_ac97 *ac97, const char *src,
2621 struct snd_kcontrol *kctl = ctl_find(ac97, src, suffix);
2630 static void snd_ac97_rename_vol_ctl(struct snd_ac97 *ac97, const char *src,
2633 snd_ac97_rename_ctl(ac97, src, dst, "Switch");
2634 snd_ac97_rename_ctl(ac97, src, dst, "Volume");
2638 static int snd_ac97_swap_ctl(struct snd_ac97 *ac97, const char *s1,
2642 kctl1 = ctl_find(ac97, s1, suffix);
2643 kctl2 = ctl_find(ac97, s2, suffix);
2666 /* ac97 tune: bind Master and Headphone controls */
2667 static int tune_hp_only(struct snd_ac97 *ac97)
2669 struct snd_kcontrol *msw = ctl_find(ac97, "Master Playback Switch", NULL);
2670 struct snd_kcontrol *mvol = ctl_find(ac97, "Master Playback Volume", NULL);
2675 snd_ac97_remove_ctl(ac97, "Headphone Playback", "Switch");
2676 snd_ac97_remove_ctl(ac97, "Headphone Playback", "Volume");
2681 /* ac97 tune: use Headphone control as master */
2682 static int tune_hp_only(struct snd_ac97 *ac97)
2684 if (ctl_find(ac97, "Headphone Playback Switch", NULL) == NULL)
2686 snd_ac97_remove_ctl(ac97, "Master Playback", "Switch");
2687 snd_ac97_remove_ctl(ac97, "Master Playback", "Volume");
2688 snd_ac97_rename_vol_ctl(ac97, "Headphone Playback", "Master Playback");
2693 /* ac97 tune: swap Headphone and Master controls */
2694 static int tune_swap_hp(struct snd_ac97 *ac97)
2696 if (ctl_find(ac97, "Headphone Playback Switch", NULL) == NULL)
2698 snd_ac97_rename_vol_ctl(ac97, "Master Playback", "Line-Out Playback");
2699 snd_ac97_rename_vol_ctl(ac97, "Headphone Playback", "Master Playback");
2703 /* ac97 tune: swap Surround and Master controls */
2704 static int tune_swap_surround(struct snd_ac97 *ac97)
2706 if (snd_ac97_swap_ctl(ac97, "Master Playback", "Surround Playback", "Switch") ||
2707 snd_ac97_swap_ctl(ac97, "Master Playback", "Surround Playback", "Volume"))
2712 /* ac97 tune: set up mic sharing for AD codecs */
2713 static int tune_ad_sharing(struct snd_ac97 *ac97)
2716 if ((ac97->id & 0xffffff00) != 0x41445300) {
2717 ac97_err(ac97, "ac97_quirk AD_SHARING is only for AD codecs\n");
2721 scfg = snd_ac97_read(ac97, AC97_AD_SERIAL_CFG);
2722 snd_ac97_write_cache(ac97, AC97_AD_SERIAL_CFG, scfg | 0x0200);
2729 /* ac97 tune: set up ALC jack-select */
2730 static int tune_alc_jack(struct snd_ac97 *ac97)
2732 if ((ac97->id & 0xffffff00) != 0x414c4700) {
2733 ac97_err(ac97,
2737 snd_ac97_update_bits(ac97, 0x7a, 0x20, 0x20); /* select jack detect function */
2738 snd_ac97_update_bits(ac97, 0x7a, 0x01, 0x01); /* Line-out auto mute */
2739 if (ac97->id == AC97_ID_ALC658D)
2740 snd_ac97_update_bits(ac97, 0x74, 0x0800, 0x0800);
2741 return snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&snd_ac97_alc_jack_detect, ac97));
2744 /* ac97 tune: inversed EAPD bit */
2745 static int tune_inv_eapd(struct snd_ac97 *ac97)
2747 struct snd_kcontrol *kctl = ctl_find(ac97, "External Amplifier", NULL);
2750 set_inv_eapd(ac97, kctl);
2758 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
2766 snd_ac97_update_bits(ac97, AC97_POWERDOWN, AC97_PD_EAPD,
2767 (ac97->regs[AC97_MASTER] & mask) == mask ?
2773 /* ac97 tune: EAPD controls mute LED bound with the master mute */
2774 static int tune_mute_led(struct snd_ac97 *ac97)
2776 struct snd_kcontrol *msw = ctl_find(ac97, "Master Playback Switch", NULL);
2780 snd_ac97_remove_ctl(ac97, "External Amplifier", NULL);
2782 ac97, AC97_POWERDOWN,
2785 ac97->scaps |= AC97_SCAP_EAPD_LED;
2794 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
2802 snd_ac97_update_bits(ac97, AC97_POWERDOWN, AC97_PD_EAPD,
2803 (ac97->regs[AC97_MASTER] & mask) == mask ?
2809 static int tune_hp_mute_led(struct snd_ac97 *ac97)
2811 struct snd_kcontrol *msw = ctl_find(ac97, "Master Playback Switch", NULL);
2812 struct snd_kcontrol *mvol = ctl_find(ac97, "Master Playback Volume", NULL);
2817 snd_ac97_remove_ctl(ac97, "External Amplifier", NULL);
2818 snd_ac97_remove_ctl(ac97, "Headphone Playback", "Switch");
2819 snd_ac97_remove_ctl(ac97, "Headphone Playback", "Volume");
2821 ac97, AC97_POWERDOWN,
2845 static int apply_quirk(struct snd_ac97 *ac97, int type)
2852 return applicable_quirks[type].func(ac97);
2857 static int apply_quirk_str(struct snd_ac97 *ac97, const char *typestr)
2865 return apply_quirk(ac97, i);
2869 return apply_quirk(ac97, (int)simple_strtoul(typestr, NULL, 10));
2875 * @ac97: the ac97 instance
2886 int snd_ac97_tune_hardware(struct snd_ac97 *ac97,
2893 result = apply_quirk_str(ac97, override);
2895 ac97_err(ac97, "applying quirk type %s failed (%d)\n",
2904 if (quirk->subvendor != ac97->subsystem_vendor)
2906 if ((! quirk->mask && quirk->subdevice == ac97->subsystem_device) ||
2907 quirk->subdevice == (quirk->mask & ac97->subsystem_device)) {
2908 if (quirk->codec_id && quirk->codec_id != ac97->id)
2910 ac97_dbg(ac97, "ac97 quirk for %s (%04x:%04x)\n",
2911 quirk->name, ac97->subsystem_vendor,
2912 ac97->subsystem_device);
2913 result = apply_quirk(ac97, quirk->type);
2915 ac97_err(ac97,