📄 ac97_patch.c
字号:
/* * Copyright (c) by Jaroslav Kysela <perex@perex.cz> * Universal interface for Audio Codec '97 * * For more details look to AC '97 component specification revision 2.2 * by Intel Corporation (http://developer.intel.com) and to datasheets * for specific codecs. * * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */#include "ac97_local.h"#include "ac97_patch.h"/* * Chip specific initialization */static int patch_build_controls(struct snd_ac97 * ac97, const struct snd_kcontrol_new *controls, int count){ int idx, err; for (idx = 0; idx < count; idx++) if ((err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&controls[idx], ac97))) < 0) return err; return 0;}/* replace with a new TLV */static void reset_tlv(struct snd_ac97 *ac97, const char *name, const unsigned int *tlv){ struct snd_ctl_elem_id sid; struct snd_kcontrol *kctl; memset(&sid, 0, sizeof(sid)); strcpy(sid.name, name); sid.iface = SNDRV_CTL_ELEM_IFACE_MIXER; kctl = snd_ctl_find_id(ac97->bus->card, &sid); if (kctl && kctl->tlv.p) kctl->tlv.p = tlv;}/* set to the page, update bits and restore the page */static int ac97_update_bits_page(struct snd_ac97 *ac97, unsigned short reg, unsigned short mask, unsigned short value, unsigned short page){ unsigned short page_save; int ret; mutex_lock(&ac97->page_mutex); page_save = snd_ac97_read(ac97, AC97_INT_PAGING) & AC97_PAGE_MASK; snd_ac97_update_bits(ac97, AC97_INT_PAGING, AC97_PAGE_MASK, page); ret = snd_ac97_update_bits(ac97, reg, mask, value); snd_ac97_update_bits(ac97, AC97_INT_PAGING, AC97_PAGE_MASK, page_save); mutex_unlock(&ac97->page_mutex); /* unlock paging */ return ret;}/* * shared line-in/mic controls */static int ac97_enum_text_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo, const char **texts, unsigned int nums){ uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; uinfo->count = 1; uinfo->value.enumerated.items = nums; if (uinfo->value.enumerated.item > nums - 1) uinfo->value.enumerated.item = nums - 1; strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]); return 0;}static int ac97_surround_jack_mode_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo){ static const char *texts[] = { "Shared", "Independent" }; return ac97_enum_text_info(kcontrol, uinfo, texts, 2);}static int ac97_surround_jack_mode_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol){ struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); ucontrol->value.enumerated.item[0] = ac97->indep_surround; return 0;}static int ac97_surround_jack_mode_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol){ struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); unsigned char indep = !!ucontrol->value.enumerated.item[0]; if (indep != ac97->indep_surround) { ac97->indep_surround = indep; if (ac97->build_ops->update_jacks) ac97->build_ops->update_jacks(ac97); return 1; } return 0;}static int ac97_channel_mode_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo){ static const char *texts[] = { "2ch", "4ch", "6ch" }; if (kcontrol->private_value) return ac97_enum_text_info(kcontrol, uinfo, texts, 2); /* 4ch only */ return ac97_enum_text_info(kcontrol, uinfo, texts, 3);}static int ac97_channel_mode_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol){ struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); ucontrol->value.enumerated.item[0] = ac97->channel_mode; return 0;}static int ac97_channel_mode_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol){ struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); unsigned char mode = ucontrol->value.enumerated.item[0]; if (mode != ac97->channel_mode) { ac97->channel_mode = mode; if (ac97->build_ops->update_jacks) ac97->build_ops->update_jacks(ac97); return 1; } return 0;}#define AC97_SURROUND_JACK_MODE_CTL \ { \ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ .name = "Surround Jack Mode", \ .info = ac97_surround_jack_mode_info, \ .get = ac97_surround_jack_mode_get, \ .put = ac97_surround_jack_mode_put, \ }#define AC97_CHANNEL_MODE_CTL \ { \ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ .name = "Channel Mode", \ .info = ac97_channel_mode_info, \ .get = ac97_channel_mode_get, \ .put = ac97_channel_mode_put, \ }#define AC97_CHANNEL_MODE_4CH_CTL \ { \ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ .name = "Channel Mode", \ .info = ac97_channel_mode_info, \ .get = ac97_channel_mode_get, \ .put = ac97_channel_mode_put, \ .private_value = 1, \ }static inline int is_surround_on(struct snd_ac97 *ac97){ return ac97->channel_mode >= 1;}static inline int is_clfe_on(struct snd_ac97 *ac97){ return ac97->channel_mode >= 2;}/* system has shared jacks with surround out enabled */static inline int is_shared_surrout(struct snd_ac97 *ac97){ return !ac97->indep_surround && is_surround_on(ac97);}/* system has shared jacks with center/lfe out enabled */static inline int is_shared_clfeout(struct snd_ac97 *ac97){ return !ac97->indep_surround && is_clfe_on(ac97);}/* system has shared jacks with line in enabled */static inline int is_shared_linein(struct snd_ac97 *ac97){ return !ac97->indep_surround && !is_surround_on(ac97);}/* system has shared jacks with mic in enabled */static inline int is_shared_micin(struct snd_ac97 *ac97){ return !ac97->indep_surround && !is_clfe_on(ac97);}/* The following snd_ac97_ymf753_... items added by David Shust (dshust@shustring.com) *//* Modified for YMF743 by Keita Maehara <maehara@debian.org> *//* It is possible to indicate to the Yamaha YMF7x3 the type of speakers being used. */static int snd_ac97_ymf7x3_info_speaker(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo){ static char *texts[3] = { "Standard", "Small", "Smaller" }; uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; uinfo->count = 1; uinfo->value.enumerated.items = 3; if (uinfo->value.enumerated.item > 2) uinfo->value.enumerated.item = 2; strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]); return 0;}static int snd_ac97_ymf7x3_get_speaker(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol){ struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); unsigned short val; val = ac97->regs[AC97_YMF7X3_3D_MODE_SEL]; val = (val >> 10) & 3; if (val > 0) /* 0 = invalid */ val--; ucontrol->value.enumerated.item[0] = val; return 0;}static int snd_ac97_ymf7x3_put_speaker(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol){ struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); unsigned short val; if (ucontrol->value.enumerated.item[0] > 2) return -EINVAL; val = (ucontrol->value.enumerated.item[0] + 1) << 10; return snd_ac97_update(ac97, AC97_YMF7X3_3D_MODE_SEL, val);}static const struct snd_kcontrol_new snd_ac97_ymf7x3_controls_speaker ={ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = "3D Control - Speaker", .info = snd_ac97_ymf7x3_info_speaker, .get = snd_ac97_ymf7x3_get_speaker, .put = snd_ac97_ymf7x3_put_speaker,};/* It is possible to indicate to the Yamaha YMF7x3 the source to direct to the S/PDIF output. */static int snd_ac97_ymf7x3_spdif_source_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo){ static char *texts[2] = { "AC-Link", "A/D Converter" }; uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; uinfo->count = 1; uinfo->value.enumerated.items = 2; if (uinfo->value.enumerated.item > 1) uinfo->value.enumerated.item = 1; strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]); return 0;}static int snd_ac97_ymf7x3_spdif_source_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol){ struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); unsigned short val; val = ac97->regs[AC97_YMF7X3_DIT_CTRL]; ucontrol->value.enumerated.item[0] = (val >> 1) & 1; return 0;}static int snd_ac97_ymf7x3_spdif_source_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol){ struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); unsigned short val; if (ucontrol->value.enumerated.item[0] > 1) return -EINVAL; val = ucontrol->value.enumerated.item[0] << 1; return snd_ac97_update_bits(ac97, AC97_YMF7X3_DIT_CTRL, 0x0002, val);}static int patch_yamaha_ymf7x3_3d(struct snd_ac97 *ac97){ struct snd_kcontrol *kctl; int err; kctl = snd_ac97_cnew(&snd_ac97_controls_3d[0], ac97); err = snd_ctl_add(ac97->bus->card, kctl); if (err < 0) return err; strcpy(kctl->id.name, "3D Control - Wide"); kctl->private_value = AC97_SINGLE_VALUE(AC97_3D_CONTROL, 9, 7, 0); snd_ac97_write_cache(ac97, AC97_3D_CONTROL, 0x0000); err = snd_ctl_add(ac97->bus->card, snd_ac97_cnew(&snd_ac97_ymf7x3_controls_speaker, ac97)); if (err < 0) return err; snd_ac97_write_cache(ac97, AC97_YMF7X3_3D_MODE_SEL, 0x0c00); return 0;}static const struct snd_kcontrol_new snd_ac97_yamaha_ymf743_controls_spdif[3] ={ AC97_SINGLE(SNDRV_CTL_NAME_IEC958("", PLAYBACK, SWITCH), AC97_YMF7X3_DIT_CTRL, 0, 1, 0), { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, NONE) "Source", .info = snd_ac97_ymf7x3_spdif_source_info, .get = snd_ac97_ymf7x3_spdif_source_get, .put = snd_ac97_ymf7x3_spdif_source_put, }, AC97_SINGLE(SNDRV_CTL_NAME_IEC958("", NONE, NONE) "Mute", AC97_YMF7X3_DIT_CTRL, 2, 1, 1)};static int patch_yamaha_ymf743_build_spdif(struct snd_ac97 *ac97){ int err; err = patch_build_controls(ac97, &snd_ac97_controls_spdif[0], 3); if (err < 0) return err; err = patch_build_controls(ac97, snd_ac97_yamaha_ymf743_controls_spdif, 3); if (err < 0) return err; /* set default PCM S/PDIF params */ /* PCM audio,no copyright,no preemphasis,PCM coder,original */ snd_ac97_write_cache(ac97, AC97_YMF7X3_DIT_CTRL, 0xa201); return 0;}static struct snd_ac97_build_ops patch_yamaha_ymf743_ops = { .build_spdif = patch_yamaha_ymf743_build_spdif, .build_3d = patch_yamaha_ymf7x3_3d,};static int patch_yamaha_ymf743(struct snd_ac97 *ac97){ ac97->build_ops = &patch_yamaha_ymf743_ops; ac97->caps |= AC97_BC_BASS_TREBLE; ac97->caps |= 0x04 << 10; /* Yamaha 3D enhancement */ ac97->rates[AC97_RATES_SPDIF] = SNDRV_PCM_RATE_48000; /* 48k only */ ac97->ext_id |= AC97_EI_SPDIF; /* force the detection of spdif */ return 0;}/* The AC'97 spec states that the S/PDIF signal is to be output at pin 48. The YMF753 will output the S/PDIF signal to pin 43, 47 (EAPD), or 48. By default, no output pin is selected, and the S/PDIF signal is not output.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -