0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #ifndef __SOUND_AC97_CODEC_H
0011 #define __SOUND_AC97_CODEC_H
0012
0013 #include <linux/bitops.h>
0014 #include <linux/device.h>
0015 #include <linux/workqueue.h>
0016 #include <sound/ac97/regs.h>
0017 #include <sound/pcm.h>
0018 #include <sound/control.h>
0019 #include <sound/info.h>
0020
0021
0022 #define AC97_BUS_MAX_DEVICES 4
0023
0024
0025 #define AC97_SIGMATEL_OUTSEL 0x64
0026 #define AC97_SIGMATEL_INSEL 0x66
0027 #define AC97_SIGMATEL_IOMISC 0x68
0028 #define AC97_SIGMATEL_ANALOG 0x6c
0029 #define AC97_SIGMATEL_DAC2INVERT 0x6e
0030 #define AC97_SIGMATEL_BIAS1 0x70
0031 #define AC97_SIGMATEL_BIAS2 0x72
0032 #define AC97_SIGMATEL_VARIOUS 0x72
0033 #define AC97_SIGMATEL_MULTICHN 0x74
0034 #define AC97_SIGMATEL_CIC1 0x76
0035 #define AC97_SIGMATEL_CIC2 0x78
0036
0037
0038 #define AC97_AD_TEST 0x5a
0039 #define AC97_AD_TEST2 0x5c
0040 #define AC97_AD_HPFD_SHIFT 12
0041 #define AC97_AD_CODEC_CFG 0x70
0042 #define AC97_AD_JACK_SPDIF 0x72
0043 #define AC97_AD_SERIAL_CFG 0x74
0044 #define AC97_AD_MISC 0x76
0045 #define AC97_AD_VREFD_SHIFT 2
0046
0047
0048 #define AC97_CSR_ACMODE 0x5e
0049 #define AC97_CSR_MISC_CRYSTAL 0x60
0050 #define AC97_CSR_SPDIF 0x68
0051 #define AC97_CSR_SERIAL 0x6a
0052 #define AC97_CSR_SPECF_ADDR 0x6c
0053 #define AC97_CSR_SPECF_DATA 0x6e
0054 #define AC97_CSR_BDI_STATUS 0x7a
0055
0056
0057 #define AC97_CXR_AUDIO_MISC 0x5c
0058 #define AC97_CXR_SPDIFEN (1<<3)
0059 #define AC97_CXR_COPYRGT (1<<2)
0060 #define AC97_CXR_SPDIF_MASK (3<<0)
0061 #define AC97_CXR_SPDIF_PCM 0x0
0062 #define AC97_CXR_SPDIF_AC3 0x2
0063
0064
0065 #define AC97_ALC650_SPDIF_INPUT_STATUS1 0x60
0066
0067 #define AC97_ALC650_PRO 0x0001
0068 #define AC97_ALC650_NAUDIO 0x0002
0069 #define AC97_ALC650_COPY 0x0004
0070 #define AC97_ALC650_PRE 0x0038
0071 #define AC97_ALC650_PRE_SHIFT 3
0072 #define AC97_ALC650_MODE 0x00C0
0073 #define AC97_ALC650_MODE_SHIFT 6
0074 #define AC97_ALC650_CC_MASK 0x7f00
0075 #define AC97_ALC650_CC_SHIFT 8
0076 #define AC97_ALC650_L 0x8000
0077
0078 #define AC97_ALC650_SPDIF_INPUT_STATUS2 0x62
0079
0080 #define AC97_ALC650_SOUCE_MASK 0x000f
0081 #define AC97_ALC650_CHANNEL_MASK 0x00f0
0082 #define AC97_ALC650_CHANNEL_SHIFT 4
0083 #define AC97_ALC650_SPSR_MASK 0x0f00
0084 #define AC97_ALC650_SPSR_SHIFT 8
0085 #define AC97_ALC650_SPSR_44K 0x0000
0086 #define AC97_ALC650_SPSR_48K 0x0200
0087 #define AC97_ALC650_SPSR_32K 0x0300
0088 #define AC97_ALC650_CLOCK_ACCURACY 0x3000
0089 #define AC97_ALC650_CLOCK_SHIFT 12
0090 #define AC97_ALC650_CLOCK_LOCK 0x4000
0091 #define AC97_ALC650_V 0x8000
0092
0093 #define AC97_ALC650_SURR_DAC_VOL 0x64
0094 #define AC97_ALC650_LFE_DAC_VOL 0x66
0095 #define AC97_ALC650_UNKNOWN1 0x68
0096 #define AC97_ALC650_MULTICH 0x6a
0097 #define AC97_ALC650_UNKNOWN2 0x6c
0098 #define AC97_ALC650_REVISION 0x6e
0099 #define AC97_ALC650_UNKNOWN3 0x70
0100 #define AC97_ALC650_UNKNOWN4 0x72
0101 #define AC97_ALC650_MISC 0x74
0102 #define AC97_ALC650_GPIO_SETUP 0x76
0103 #define AC97_ALC650_GPIO_STATUS 0x78
0104 #define AC97_ALC650_CLOCK 0x7a
0105
0106
0107 #define AC97_YMF7X3_DIT_CTRL 0x66
0108 #define AC97_YMF7X3_3D_MODE_SEL 0x68
0109
0110
0111 #define AC97_CM9738_VENDOR_CTRL 0x5a
0112 #define AC97_CM9739_MULTI_CHAN 0x64
0113 #define AC97_CM9739_SPDIF_IN_STATUS 0x68
0114 #define AC97_CM9739_SPDIF_CTRL 0x6c
0115
0116
0117 #define AC97_WM97XX_FMIXER_VOL 0x72
0118 #define AC97_WM9704_RMIXER_VOL 0x74
0119 #define AC97_WM9704_TEST 0x5a
0120 #define AC97_WM9704_RPCM_VOL 0x70
0121 #define AC97_WM9711_OUT3VOL 0x16
0122
0123
0124
0125 #define AC97_SCAP_AUDIO (1<<0)
0126 #define AC97_SCAP_MODEM (1<<1)
0127 #define AC97_SCAP_SURROUND_DAC (1<<2)
0128 #define AC97_SCAP_CENTER_LFE_DAC (1<<3)
0129 #define AC97_SCAP_SKIP_AUDIO (1<<4)
0130 #define AC97_SCAP_SKIP_MODEM (1<<5)
0131 #define AC97_SCAP_INDEP_SDIN (1<<6)
0132 #define AC97_SCAP_INV_EAPD (1<<7)
0133 #define AC97_SCAP_DETECT_BY_VENDOR (1<<8)
0134 #define AC97_SCAP_NO_SPDIF (1<<9)
0135 #define AC97_SCAP_EAPD_LED (1<<10)
0136 #define AC97_SCAP_POWER_SAVE (1<<11)
0137
0138
0139 #define AC97_HAS_PC_BEEP (1<<0)
0140 #define AC97_AD_MULTI (1<<1)
0141 #define AC97_CS_SPDIF (1<<2)
0142 #define AC97_CX_SPDIF (1<<3)
0143 #define AC97_STEREO_MUTES (1<<4)
0144 #define AC97_DOUBLE_RATE (1<<5)
0145 #define AC97_HAS_NO_MASTER_VOL (1<<6)
0146 #define AC97_HAS_NO_PCM_VOL (1<<7)
0147 #define AC97_DEFAULT_POWER_OFF (1<<8)
0148 #define AC97_MODEM_PATCH (1<<9)
0149 #define AC97_HAS_NO_REC_GAIN (1<<10)
0150 #define AC97_HAS_NO_PHONE (1<<11)
0151 #define AC97_HAS_NO_PC_BEEP (1<<12)
0152 #define AC97_HAS_NO_VIDEO (1<<13)
0153 #define AC97_HAS_NO_CD (1<<14)
0154 #define AC97_HAS_NO_MIC (1<<15)
0155 #define AC97_HAS_NO_TONE (1<<16)
0156 #define AC97_HAS_NO_STD_PCM (1<<17)
0157 #define AC97_HAS_NO_AUX (1<<18)
0158 #define AC97_HAS_8CH (1<<19)
0159
0160
0161 #define AC97_RATES_FRONT_DAC 0
0162 #define AC97_RATES_SURR_DAC 1
0163 #define AC97_RATES_LFE_DAC 2
0164 #define AC97_RATES_ADC 3
0165 #define AC97_RATES_MIC_ADC 4
0166 #define AC97_RATES_SPDIF 5
0167
0168 #define AC97_NUM_GPIOS 16
0169
0170
0171
0172
0173 struct snd_ac97;
0174 struct snd_ac97_gpio_priv;
0175 struct snd_pcm_chmap;
0176
0177 struct snd_ac97_build_ops {
0178 int (*build_3d) (struct snd_ac97 *ac97);
0179 int (*build_specific) (struct snd_ac97 *ac97);
0180 int (*build_spdif) (struct snd_ac97 *ac97);
0181 int (*build_post_spdif) (struct snd_ac97 *ac97);
0182 #ifdef CONFIG_PM
0183 void (*suspend) (struct snd_ac97 *ac97);
0184 void (*resume) (struct snd_ac97 *ac97);
0185 #endif
0186 void (*update_jacks) (struct snd_ac97 *ac97);
0187 };
0188
0189 struct snd_ac97_bus_ops {
0190 void (*reset) (struct snd_ac97 *ac97);
0191 void (*warm_reset)(struct snd_ac97 *ac97);
0192 void (*write) (struct snd_ac97 *ac97, unsigned short reg, unsigned short val);
0193 unsigned short (*read) (struct snd_ac97 *ac97, unsigned short reg);
0194 void (*wait) (struct snd_ac97 *ac97);
0195 void (*init) (struct snd_ac97 *ac97);
0196 };
0197
0198 struct snd_ac97_bus {
0199
0200 const struct snd_ac97_bus_ops *ops;
0201 void *private_data;
0202 void (*private_free) (struct snd_ac97_bus *bus);
0203
0204 struct snd_card *card;
0205 unsigned short num;
0206 unsigned short no_vra: 1,
0207 dra: 1,
0208 isdin: 1;
0209 unsigned int clock;
0210 spinlock_t bus_lock;
0211 unsigned short used_slots[2][4];
0212 unsigned short pcms_count;
0213 struct ac97_pcm *pcms;
0214 struct snd_ac97 *codec[4];
0215 struct snd_info_entry *proc;
0216 };
0217
0218
0219 struct snd_ac97_res_table {
0220 unsigned short reg;
0221 unsigned short bits;
0222 };
0223
0224 struct snd_ac97_template {
0225 void *private_data;
0226 void (*private_free) (struct snd_ac97 *ac97);
0227 struct pci_dev *pci;
0228 unsigned short num;
0229 unsigned short addr;
0230 unsigned int scaps;
0231 const struct snd_ac97_res_table *res_table;
0232 };
0233
0234 struct snd_ac97 {
0235
0236 const struct snd_ac97_build_ops *build_ops;
0237 void *private_data;
0238 void (*private_free) (struct snd_ac97 *ac97);
0239
0240 struct snd_ac97_bus *bus;
0241 struct pci_dev *pci;
0242 struct snd_info_entry *proc;
0243 struct snd_info_entry *proc_regs;
0244 unsigned short subsystem_vendor;
0245 unsigned short subsystem_device;
0246 struct mutex reg_mutex;
0247 struct mutex page_mutex;
0248 unsigned short num;
0249 unsigned short addr;
0250 unsigned int id;
0251 unsigned short caps;
0252 unsigned short ext_id;
0253 unsigned short ext_mid;
0254 const struct snd_ac97_res_table *res_table;
0255 unsigned int scaps;
0256 unsigned int flags;
0257 unsigned int rates[6];
0258 unsigned int spdif_status;
0259 unsigned short regs[0x80];
0260 DECLARE_BITMAP(reg_accessed, 0x80);
0261 union {
0262 struct {
0263 unsigned short unchained[3];
0264 unsigned short chained[3];
0265 unsigned short id[3];
0266 unsigned short pcmreg[3];
0267 unsigned short codec_cfg[3];
0268 unsigned char swap_mic_linein;
0269 unsigned char lo_as_master;
0270 } ad18xx;
0271 unsigned int dev_flags;
0272 } spec;
0273
0274 unsigned char indep_surround;
0275 unsigned char channel_mode;
0276
0277 #ifdef CONFIG_SND_AC97_POWER_SAVE
0278 unsigned int power_up;
0279 struct delayed_work power_work;
0280 #endif
0281 struct device dev;
0282 struct snd_ac97_gpio_priv *gpio_priv;
0283
0284 struct snd_pcm_chmap *chmaps[2];
0285 };
0286
0287 #define to_ac97_t(d) container_of(d, struct snd_ac97, dev)
0288
0289
0290 static inline int ac97_is_audio(struct snd_ac97 * ac97)
0291 {
0292 return (ac97->scaps & AC97_SCAP_AUDIO);
0293 }
0294 static inline int ac97_is_modem(struct snd_ac97 * ac97)
0295 {
0296 return (ac97->scaps & AC97_SCAP_MODEM);
0297 }
0298 static inline int ac97_is_rev22(struct snd_ac97 * ac97)
0299 {
0300 return (ac97->ext_id & AC97_EI_REV_MASK) >= AC97_EI_REV_22;
0301 }
0302 static inline int ac97_can_amap(struct snd_ac97 * ac97)
0303 {
0304 return (ac97->ext_id & AC97_EI_AMAP) != 0;
0305 }
0306 static inline int ac97_can_spdif(struct snd_ac97 * ac97)
0307 {
0308 return (ac97->ext_id & AC97_EI_SPDIF) != 0;
0309 }
0310
0311
0312
0313 int snd_ac97_bus(struct snd_card *card, int num,
0314 const struct snd_ac97_bus_ops *ops,
0315 void *private_data, struct snd_ac97_bus **rbus);
0316
0317 int snd_ac97_mixer(struct snd_ac97_bus *bus, struct snd_ac97_template *template,
0318 struct snd_ac97 **rac97);
0319 const char *snd_ac97_get_short_name(struct snd_ac97 *ac97);
0320
0321 void snd_ac97_write(struct snd_ac97 *ac97, unsigned short reg, unsigned short value);
0322 unsigned short snd_ac97_read(struct snd_ac97 *ac97, unsigned short reg);
0323 void snd_ac97_write_cache(struct snd_ac97 *ac97, unsigned short reg, unsigned short value);
0324 int snd_ac97_update(struct snd_ac97 *ac97, unsigned short reg, unsigned short value);
0325 int snd_ac97_update_bits(struct snd_ac97 *ac97, unsigned short reg, unsigned short mask, unsigned short value);
0326 #ifdef CONFIG_SND_AC97_POWER_SAVE
0327 int snd_ac97_update_power(struct snd_ac97 *ac97, int reg, int powerup);
0328 #else
0329 static inline int snd_ac97_update_power(struct snd_ac97 *ac97, int reg,
0330 int powerup)
0331 {
0332 return 0;
0333 }
0334 #endif
0335 #ifdef CONFIG_PM
0336 void snd_ac97_suspend(struct snd_ac97 *ac97);
0337 void snd_ac97_resume(struct snd_ac97 *ac97);
0338 #endif
0339 int snd_ac97_reset(struct snd_ac97 *ac97, bool try_warm, unsigned int id,
0340 unsigned int id_mask);
0341
0342
0343 enum {
0344 AC97_TUNE_DEFAULT = -1,
0345 AC97_TUNE_NONE = 0,
0346 AC97_TUNE_HP_ONLY,
0347 AC97_TUNE_SWAP_HP,
0348 AC97_TUNE_SWAP_SURROUND,
0349 AC97_TUNE_AD_SHARING,
0350 AC97_TUNE_ALC_JACK,
0351 AC97_TUNE_INV_EAPD,
0352 AC97_TUNE_MUTE_LED,
0353 AC97_TUNE_HP_MUTE_LED,
0354 };
0355
0356 struct ac97_quirk {
0357 unsigned short subvendor;
0358 unsigned short subdevice;
0359 unsigned short mask;
0360 unsigned int codec_id;
0361 const char *name;
0362 int type;
0363 };
0364
0365 int snd_ac97_tune_hardware(struct snd_ac97 *ac97,
0366 const struct ac97_quirk *quirk,
0367 const char *override);
0368 int snd_ac97_set_rate(struct snd_ac97 *ac97, int reg, unsigned int rate);
0369
0370
0371
0372
0373
0374 enum ac97_pcm_cfg {
0375 AC97_PCM_CFG_FRONT = 2,
0376 AC97_PCM_CFG_REAR = 10,
0377 AC97_PCM_CFG_LFE = 11,
0378 AC97_PCM_CFG_40 = 4,
0379 AC97_PCM_CFG_51 = 6,
0380 AC97_PCM_CFG_SPDIF = 20
0381 };
0382
0383 struct ac97_pcm {
0384 struct snd_ac97_bus *bus;
0385 unsigned int stream: 1,
0386 exclusive: 1,
0387 copy_flag: 1,
0388 spdif: 1;
0389 unsigned short aslots;
0390 unsigned short cur_dbl;
0391 unsigned int rates;
0392 struct {
0393 unsigned short slots;
0394 unsigned short rslots[4];
0395 unsigned char rate_table[4];
0396 struct snd_ac97 *codec[4];
0397 } r[2];
0398 unsigned long private_value;
0399 };
0400
0401 int snd_ac97_pcm_assign(struct snd_ac97_bus *ac97,
0402 unsigned short pcms_count,
0403 const struct ac97_pcm *pcms);
0404 int snd_ac97_pcm_open(struct ac97_pcm *pcm, unsigned int rate,
0405 enum ac97_pcm_cfg cfg, unsigned short slots);
0406 int snd_ac97_pcm_close(struct ac97_pcm *pcm);
0407 int snd_ac97_pcm_double_rate_rules(struct snd_pcm_runtime *runtime);
0408
0409
0410 extern struct bus_type ac97_bus_type;
0411
0412
0413 static inline void snd_ac97_dev_add_pdata(struct snd_ac97 *ac97, void *data)
0414 {
0415 ac97->dev.platform_data = data;
0416 }
0417
0418 #endif