Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Matt Wu <Matt_Wu@acersoftech.com.cn> |
| 3 | * Apr 26, 2001 |
| 4 | * Routines for control of ALi pci audio M5451 |
| 5 | * |
| 6 | * BUGS: |
| 7 | * -- |
| 8 | * |
| 9 | * TODO: |
| 10 | * -- |
| 11 | * |
| 12 | * This program is free software; you can redistribute it and/or modify |
| 13 | * it under the terms of the GNU General Public Lcodecnse as published by |
| 14 | * the Free Software Foundation; either version 2 of the Lcodecnse, or |
| 15 | * (at your option) any later version. |
| 16 | * |
| 17 | * This program is distributed in the hope that it will be useful, |
| 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 20 | * GNU General Public Lcodecnse for more details. |
| 21 | * |
| 22 | * You should have received a copy of the GNU General Public Lcodecnse |
| 23 | * along with this program; if not, write to the Free Software |
| 24 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 25 | * |
| 26 | */ |
| 27 | |
| 28 | #include <sound/driver.h> |
| 29 | #include <asm/io.h> |
| 30 | #include <linux/delay.h> |
| 31 | #include <linux/interrupt.h> |
| 32 | #include <linux/init.h> |
| 33 | #include <linux/pci.h> |
| 34 | #include <linux/slab.h> |
| 35 | #include <linux/moduleparam.h> |
Matthias Gehre | 910638a | 2006-03-28 01:56:48 -0800 | [diff] [blame] | 36 | #include <linux/dma-mapping.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | #include <sound/core.h> |
| 38 | #include <sound/pcm.h> |
| 39 | #include <sound/info.h> |
| 40 | #include <sound/ac97_codec.h> |
| 41 | #include <sound/mpu401.h> |
| 42 | #include <sound/initval.h> |
| 43 | |
| 44 | MODULE_AUTHOR("Matt Wu <Matt_Wu@acersoftech.com.cn>"); |
| 45 | MODULE_DESCRIPTION("ALI M5451"); |
| 46 | MODULE_LICENSE("GPL"); |
| 47 | MODULE_SUPPORTED_DEVICE("{{ALI,M5451,pci},{ALI,M5451}}"); |
| 48 | |
Takashi Iwai | 8a3fb4d | 2005-10-20 17:10:49 +0200 | [diff] [blame] | 49 | static int index = SNDRV_DEFAULT_IDX1; /* Index */ |
| 50 | static char *id = SNDRV_DEFAULT_STR1; /* ID for this card */ |
| 51 | static int pcm_channels = 32; |
Takashi Iwai | 6581f4e | 2006-05-17 17:14:51 +0200 | [diff] [blame] | 52 | static int spdif; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | |
Takashi Iwai | 8a3fb4d | 2005-10-20 17:10:49 +0200 | [diff] [blame] | 54 | module_param(index, int, 0444); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | MODULE_PARM_DESC(index, "Index value for ALI M5451 PCI Audio."); |
Takashi Iwai | 8a3fb4d | 2005-10-20 17:10:49 +0200 | [diff] [blame] | 56 | module_param(id, charp, 0444); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | MODULE_PARM_DESC(id, "ID string for ALI M5451 PCI Audio."); |
Takashi Iwai | 8a3fb4d | 2005-10-20 17:10:49 +0200 | [diff] [blame] | 58 | module_param(pcm_channels, int, 0444); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | MODULE_PARM_DESC(pcm_channels, "PCM Channels"); |
Takashi Iwai | 8a3fb4d | 2005-10-20 17:10:49 +0200 | [diff] [blame] | 60 | module_param(spdif, bool, 0444); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | MODULE_PARM_DESC(spdif, "Support SPDIF I/O"); |
| 62 | |
Takashi Iwai | 8a3fb4d | 2005-10-20 17:10:49 +0200 | [diff] [blame] | 63 | /* just for backward compatibility */ |
| 64 | static int enable; |
| 65 | module_param(enable, bool, 0444); |
| 66 | |
| 67 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | /* |
| 69 | * Debug part definitions |
| 70 | */ |
| 71 | |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 72 | /* #define ALI_DEBUG */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | |
| 74 | #ifdef ALI_DEBUG |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 75 | #define snd_ali_printk(format, args...) printk(KERN_DEBUG format, ##args); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | #else |
| 77 | #define snd_ali_printk(format, args...) |
| 78 | #endif |
| 79 | |
| 80 | /* |
| 81 | * Constants definition |
| 82 | */ |
| 83 | |
Takashi Iwai | 8cdfd25 | 2005-09-07 14:08:11 +0200 | [diff] [blame] | 84 | #define DEVICE_ID_ALI5451 ((PCI_VENDOR_ID_AL<<16)|PCI_DEVICE_ID_AL_M5451) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | |
| 86 | |
| 87 | #define ALI_CHANNELS 32 |
| 88 | |
| 89 | #define ALI_PCM_IN_CHANNEL 31 |
| 90 | #define ALI_SPDIF_IN_CHANNEL 19 |
| 91 | #define ALI_SPDIF_OUT_CHANNEL 15 |
| 92 | #define ALI_CENTER_CHANNEL 24 |
| 93 | #define ALI_LEF_CHANNEL 23 |
| 94 | #define ALI_SURR_LEFT_CHANNEL 26 |
| 95 | #define ALI_SURR_RIGHT_CHANNEL 25 |
Sasha Khapyorsky | 5cbff89 | 2005-05-30 08:09:56 +0200 | [diff] [blame] | 96 | #define ALI_MODEM_IN_CHANNEL 21 |
| 97 | #define ALI_MODEM_OUT_CHANNEL 20 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | |
| 99 | #define SNDRV_ALI_VOICE_TYPE_PCM 01 |
| 100 | #define SNDRV_ALI_VOICE_TYPE_OTH 02 |
| 101 | |
| 102 | #define ALI_5451_V02 0x02 |
| 103 | |
| 104 | /* |
| 105 | * Direct Registers |
| 106 | */ |
| 107 | |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 108 | #define ALI_LEGACY_DMAR0 0x00 /* ADR0 */ |
| 109 | #define ALI_LEGACY_DMAR4 0x04 /* CNT0 */ |
| 110 | #define ALI_LEGACY_DMAR11 0x0b /* MOD */ |
| 111 | #define ALI_LEGACY_DMAR15 0x0f /* MMR */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | #define ALI_MPUR0 0x20 |
| 113 | #define ALI_MPUR1 0x21 |
| 114 | #define ALI_MPUR2 0x22 |
| 115 | #define ALI_MPUR3 0x23 |
| 116 | |
| 117 | #define ALI_AC97_WRITE 0x40 |
| 118 | #define ALI_AC97_READ 0x44 |
| 119 | |
| 120 | #define ALI_SCTRL 0x48 |
| 121 | #define ALI_SPDIF_OUT_ENABLE 0x20 |
Sasha Khapyorsky | 5cbff89 | 2005-05-30 08:09:56 +0200 | [diff] [blame] | 122 | #define ALI_SCTRL_LINE_IN2 (1 << 9) |
| 123 | #define ALI_SCTRL_GPIO_IN2 (1 << 13) |
| 124 | #define ALI_SCTRL_LINE_OUT_EN (1 << 20) |
| 125 | #define ALI_SCTRL_GPIO_OUT_EN (1 << 23) |
| 126 | #define ALI_SCTRL_CODEC1_READY (1 << 24) |
| 127 | #define ALI_SCTRL_CODEC2_READY (1 << 25) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | #define ALI_AC97_GPIO 0x4c |
Sasha Khapyorsky | 5cbff89 | 2005-05-30 08:09:56 +0200 | [diff] [blame] | 129 | #define ALI_AC97_GPIO_ENABLE 0x8000 |
| 130 | #define ALI_AC97_GPIO_DATA_SHIFT 16 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | #define ALI_SPDIF_CS 0x70 |
| 132 | #define ALI_SPDIF_CTRL 0x74 |
| 133 | #define ALI_SPDIF_IN_FUNC_ENABLE 0x02 |
| 134 | #define ALI_SPDIF_IN_CH_STATUS 0x40 |
| 135 | #define ALI_SPDIF_OUT_CH_STATUS 0xbf |
| 136 | #define ALI_START 0x80 |
| 137 | #define ALI_STOP 0x84 |
| 138 | #define ALI_CSPF 0x90 |
| 139 | #define ALI_AINT 0x98 |
| 140 | #define ALI_GC_CIR 0xa0 |
| 141 | #define ENDLP_IE 0x00001000 |
| 142 | #define MIDLP_IE 0x00002000 |
| 143 | #define ALI_AINTEN 0xa4 |
| 144 | #define ALI_VOLUME 0xa8 |
| 145 | #define ALI_SBDELTA_DELTA_R 0xac |
| 146 | #define ALI_MISCINT 0xb0 |
| 147 | #define ADDRESS_IRQ 0x00000020 |
| 148 | #define TARGET_REACHED 0x00008000 |
| 149 | #define MIXER_OVERFLOW 0x00000800 |
| 150 | #define MIXER_UNDERFLOW 0x00000400 |
Sasha Khapyorsky | 5cbff89 | 2005-05-30 08:09:56 +0200 | [diff] [blame] | 151 | #define GPIO_IRQ 0x01000000 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | #define ALI_SBBL_SBCL 0xc0 |
| 153 | #define ALI_SBCTRL_SBE2R_SBDD 0xc4 |
| 154 | #define ALI_STIMER 0xc8 |
| 155 | #define ALI_GLOBAL_CONTROL 0xd4 |
| 156 | #define ALI_SPDIF_OUT_SEL_PCM 0x00000400 /* bit 10 */ |
| 157 | #define ALI_SPDIF_IN_SUPPORT 0x00000800 /* bit 11 */ |
| 158 | #define ALI_SPDIF_OUT_CH_ENABLE 0x00008000 /* bit 15 */ |
| 159 | #define ALI_SPDIF_IN_CH_ENABLE 0x00080000 /* bit 19 */ |
| 160 | #define ALI_PCM_IN_ENABLE 0x80000000 /* bit 31 */ |
| 161 | |
| 162 | #define ALI_CSO_ALPHA_FMS 0xe0 |
| 163 | #define ALI_LBA 0xe4 |
| 164 | #define ALI_ESO_DELTA 0xe8 |
| 165 | #define ALI_GVSEL_PAN_VOC_CTRL_EC 0xf0 |
| 166 | #define ALI_EBUF1 0xf4 |
| 167 | #define ALI_EBUF2 0xf8 |
| 168 | |
| 169 | #define ALI_REG(codec, x) ((codec)->port + x) |
| 170 | |
Sasha Khapyorsky | 5cbff89 | 2005-05-30 08:09:56 +0200 | [diff] [blame] | 171 | #define MAX_CODECS 2 |
| 172 | |
| 173 | |
Takashi Iwai | d1fabd9 | 2005-11-17 14:56:03 +0100 | [diff] [blame] | 174 | struct snd_ali; |
| 175 | struct snd_ali_voice; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 | |
Takashi Iwai | d1fabd9 | 2005-11-17 14:56:03 +0100 | [diff] [blame] | 177 | struct snd_ali_channel_control { |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 178 | /* register data */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 | struct REGDATA { |
| 180 | unsigned int start; |
| 181 | unsigned int stop; |
| 182 | unsigned int aint; |
| 183 | unsigned int ainten; |
| 184 | } data; |
| 185 | |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 186 | /* register addresses */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | struct REGS { |
| 188 | unsigned int start; |
| 189 | unsigned int stop; |
| 190 | unsigned int aint; |
| 191 | unsigned int ainten; |
| 192 | unsigned int ac97read; |
| 193 | unsigned int ac97write; |
| 194 | } regs; |
| 195 | |
Takashi Iwai | d1fabd9 | 2005-11-17 14:56:03 +0100 | [diff] [blame] | 196 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | |
Takashi Iwai | d1fabd9 | 2005-11-17 14:56:03 +0100 | [diff] [blame] | 198 | struct snd_ali_voice { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | unsigned int number; |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 200 | unsigned int use :1, |
| 201 | pcm :1, |
| 202 | midi :1, |
| 203 | mode :1, |
| 204 | synth :1, |
| 205 | running :1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 206 | |
| 207 | /* PCM data */ |
Takashi Iwai | d1fabd9 | 2005-11-17 14:56:03 +0100 | [diff] [blame] | 208 | struct snd_ali *codec; |
| 209 | struct snd_pcm_substream *substream; |
| 210 | struct snd_ali_voice *extra; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 212 | int eso; /* final ESO value for channel */ |
| 213 | int count; /* runtime->period_size */ |
| 214 | |
| 215 | /* --- */ |
| 216 | |
| 217 | void *private_data; |
| 218 | void (*private_free)(void *private_data); |
| 219 | }; |
| 220 | |
| 221 | |
Takashi Iwai | d1fabd9 | 2005-11-17 14:56:03 +0100 | [diff] [blame] | 222 | struct snd_alidev { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 223 | |
Takashi Iwai | d1fabd9 | 2005-11-17 14:56:03 +0100 | [diff] [blame] | 224 | struct snd_ali_voice voices[ALI_CHANNELS]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 225 | |
| 226 | unsigned int chcnt; /* num of opened channels */ |
| 227 | unsigned int chmap; /* bitmap for opened channels */ |
| 228 | unsigned int synthcount; |
| 229 | |
Takashi Iwai | d1fabd9 | 2005-11-17 14:56:03 +0100 | [diff] [blame] | 230 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 231 | |
| 232 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | #define ALI_GLOBAL_REGS 56 |
| 234 | #define ALI_CHANNEL_REGS 8 |
Takashi Iwai | d1fabd9 | 2005-11-17 14:56:03 +0100 | [diff] [blame] | 235 | struct snd_ali_image { |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 236 | u32 regs[ALI_GLOBAL_REGS]; |
| 237 | u32 channel_regs[ALI_CHANNELS][ALI_CHANNEL_REGS]; |
Takashi Iwai | d1fabd9 | 2005-11-17 14:56:03 +0100 | [diff] [blame] | 238 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 239 | |
| 240 | |
Takashi Iwai | d1fabd9 | 2005-11-17 14:56:03 +0100 | [diff] [blame] | 241 | struct snd_ali { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | unsigned long irq; |
| 243 | unsigned long port; |
| 244 | unsigned char revision; |
| 245 | |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 246 | unsigned int hw_initialized :1; |
| 247 | unsigned int spdif_support :1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | |
| 249 | struct pci_dev *pci; |
| 250 | struct pci_dev *pci_m1533; |
| 251 | struct pci_dev *pci_m7101; |
| 252 | |
Takashi Iwai | d1fabd9 | 2005-11-17 14:56:03 +0100 | [diff] [blame] | 253 | struct snd_card *card; |
| 254 | struct snd_pcm *pcm[MAX_CODECS]; |
| 255 | struct snd_alidev synth; |
| 256 | struct snd_ali_channel_control chregs; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 257 | |
| 258 | /* S/PDIF Mask */ |
| 259 | unsigned int spdif_mask; |
| 260 | |
| 261 | unsigned int spurious_irq_count; |
| 262 | unsigned int spurious_irq_max_delta; |
| 263 | |
Sasha Khapyorsky | 5cbff89 | 2005-05-30 08:09:56 +0200 | [diff] [blame] | 264 | unsigned int num_of_codecs; |
| 265 | |
Takashi Iwai | d1fabd9 | 2005-11-17 14:56:03 +0100 | [diff] [blame] | 266 | struct snd_ac97_bus *ac97_bus; |
| 267 | struct snd_ac97 *ac97[MAX_CODECS]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 268 | unsigned short ac97_ext_id; |
| 269 | unsigned short ac97_ext_status; |
| 270 | |
| 271 | spinlock_t reg_lock; |
| 272 | spinlock_t voice_alloc; |
| 273 | |
| 274 | #ifdef CONFIG_PM |
Takashi Iwai | d1fabd9 | 2005-11-17 14:56:03 +0100 | [diff] [blame] | 275 | struct snd_ali_image *image; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 276 | #endif |
| 277 | }; |
| 278 | |
Takashi Iwai | f40b689 | 2006-07-05 16:51:05 +0200 | [diff] [blame] | 279 | static struct pci_device_id snd_ali_ids[] = { |
Jon Mason | ec6c8c3 | 2006-01-13 13:17:43 +0100 | [diff] [blame] | 280 | {PCI_DEVICE(PCI_VENDOR_ID_AL, PCI_DEVICE_ID_AL_M5451), 0, 0, 0}, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 281 | {0, } |
| 282 | }; |
| 283 | MODULE_DEVICE_TABLE(pci, snd_ali_ids); |
| 284 | |
Takashi Iwai | d1fabd9 | 2005-11-17 14:56:03 +0100 | [diff] [blame] | 285 | static void snd_ali_clear_voices(struct snd_ali *, unsigned int, unsigned int); |
| 286 | static unsigned short snd_ali_codec_peek(struct snd_ali *, int, unsigned short); |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 287 | static void snd_ali_codec_poke(struct snd_ali *, int, unsigned short, |
| 288 | unsigned short); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 289 | |
| 290 | /* |
| 291 | * AC97 ACCESS |
| 292 | */ |
| 293 | |
Takashi Iwai | d1fabd9 | 2005-11-17 14:56:03 +0100 | [diff] [blame] | 294 | static inline unsigned int snd_ali_5451_peek(struct snd_ali *codec, |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 295 | unsigned int port) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 296 | { |
| 297 | return (unsigned int)inl(ALI_REG(codec, port)); |
| 298 | } |
| 299 | |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 300 | static inline void snd_ali_5451_poke(struct snd_ali *codec, |
| 301 | unsigned int port, |
| 302 | unsigned int val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 303 | { |
| 304 | outl((unsigned int)val, ALI_REG(codec, port)); |
| 305 | } |
| 306 | |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 307 | static int snd_ali_codec_ready(struct snd_ali *codec, |
| 308 | unsigned int port) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 309 | { |
| 310 | unsigned long end_time; |
| 311 | unsigned int res; |
| 312 | |
Takashi Iwai | 755e137 | 2005-11-11 21:05:27 +0100 | [diff] [blame] | 313 | end_time = jiffies + msecs_to_jiffies(250); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 314 | do { |
| 315 | res = snd_ali_5451_peek(codec,port); |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 316 | if (!(res & 0x8000)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | return 0; |
Takashi Iwai | 755e137 | 2005-11-11 21:05:27 +0100 | [diff] [blame] | 318 | schedule_timeout_uninterruptible(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 319 | } while (time_after_eq(end_time, jiffies)); |
| 320 | snd_ali_5451_poke(codec, port, res & ~0x8000); |
| 321 | snd_printdd("ali_codec_ready: codec is not ready.\n "); |
| 322 | return -EIO; |
| 323 | } |
| 324 | |
Takashi Iwai | d1fabd9 | 2005-11-17 14:56:03 +0100 | [diff] [blame] | 325 | static int snd_ali_stimer_ready(struct snd_ali *codec) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 326 | { |
| 327 | unsigned long end_time; |
| 328 | unsigned long dwChk1,dwChk2; |
| 329 | |
| 330 | dwChk1 = snd_ali_5451_peek(codec, ALI_STIMER); |
| 331 | dwChk2 = snd_ali_5451_peek(codec, ALI_STIMER); |
| 332 | |
Takashi Iwai | 755e137 | 2005-11-11 21:05:27 +0100 | [diff] [blame] | 333 | end_time = jiffies + msecs_to_jiffies(250); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 334 | do { |
| 335 | dwChk2 = snd_ali_5451_peek(codec, ALI_STIMER); |
| 336 | if (dwChk2 != dwChk1) |
| 337 | return 0; |
Takashi Iwai | 755e137 | 2005-11-11 21:05:27 +0100 | [diff] [blame] | 338 | schedule_timeout_uninterruptible(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 339 | } while (time_after_eq(end_time, jiffies)); |
Takashi Iwai | 99b359b | 2005-10-20 18:26:44 +0200 | [diff] [blame] | 340 | snd_printk(KERN_ERR "ali_stimer_read: stimer is not ready.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 341 | return -EIO; |
| 342 | } |
| 343 | |
Takashi Iwai | d1fabd9 | 2005-11-17 14:56:03 +0100 | [diff] [blame] | 344 | static void snd_ali_codec_poke(struct snd_ali *codec,int secondary, |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 345 | unsigned short reg, |
| 346 | unsigned short val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 347 | { |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 348 | unsigned int dwVal; |
| 349 | unsigned int port; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 350 | |
| 351 | if (reg >= 0x80) { |
Takashi Iwai | 99b359b | 2005-10-20 18:26:44 +0200 | [diff] [blame] | 352 | snd_printk(KERN_ERR "ali_codec_poke: reg(%xh) invalid.\n", reg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 353 | return; |
| 354 | } |
| 355 | |
| 356 | port = codec->chregs.regs.ac97write; |
| 357 | |
Takashi Iwai | 755e137 | 2005-11-11 21:05:27 +0100 | [diff] [blame] | 358 | if (snd_ali_codec_ready(codec, port) < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 359 | return; |
Takashi Iwai | 755e137 | 2005-11-11 21:05:27 +0100 | [diff] [blame] | 360 | if (snd_ali_stimer_ready(codec) < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 361 | return; |
| 362 | |
| 363 | dwVal = (unsigned int) (reg & 0xff); |
| 364 | dwVal |= 0x8000 | (val << 16); |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 365 | if (secondary) |
| 366 | dwVal |= 0x0080; |
| 367 | if (codec->revision == ALI_5451_V02) |
| 368 | dwVal |= 0x0100; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 369 | |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 370 | snd_ali_5451_poke(codec, port, dwVal); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 371 | |
| 372 | return ; |
| 373 | } |
| 374 | |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 375 | static unsigned short snd_ali_codec_peek(struct snd_ali *codec, |
| 376 | int secondary, |
| 377 | unsigned short reg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 378 | { |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 379 | unsigned int dwVal; |
| 380 | unsigned int port; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 381 | |
| 382 | if (reg >= 0x80) { |
Takashi Iwai | 99b359b | 2005-10-20 18:26:44 +0200 | [diff] [blame] | 383 | snd_printk(KERN_ERR "ali_codec_peek: reg(%xh) invalid.\n", reg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 384 | return ~0; |
| 385 | } |
| 386 | |
| 387 | port = codec->chregs.regs.ac97read; |
| 388 | |
Takashi Iwai | 755e137 | 2005-11-11 21:05:27 +0100 | [diff] [blame] | 389 | if (snd_ali_codec_ready(codec, port) < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 390 | return ~0; |
Takashi Iwai | 755e137 | 2005-11-11 21:05:27 +0100 | [diff] [blame] | 391 | if (snd_ali_stimer_ready(codec) < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 392 | return ~0; |
| 393 | |
| 394 | dwVal = (unsigned int) (reg & 0xff); |
| 395 | dwVal |= 0x8000; /* bit 15*/ |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 396 | if (secondary) |
| 397 | dwVal |= 0x0080; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 398 | |
| 399 | snd_ali_5451_poke(codec, port, dwVal); |
| 400 | |
Takashi Iwai | 755e137 | 2005-11-11 21:05:27 +0100 | [diff] [blame] | 401 | if (snd_ali_stimer_ready(codec) < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 402 | return ~0; |
Takashi Iwai | 755e137 | 2005-11-11 21:05:27 +0100 | [diff] [blame] | 403 | if (snd_ali_codec_ready(codec, port) < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 404 | return ~0; |
| 405 | |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 406 | return (snd_ali_5451_peek(codec, port) & 0xffff0000) >> 16; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 407 | } |
| 408 | |
Takashi Iwai | d1fabd9 | 2005-11-17 14:56:03 +0100 | [diff] [blame] | 409 | static void snd_ali_codec_write(struct snd_ac97 *ac97, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 410 | unsigned short reg, |
| 411 | unsigned short val ) |
| 412 | { |
Takashi Iwai | d1fabd9 | 2005-11-17 14:56:03 +0100 | [diff] [blame] | 413 | struct snd_ali *codec = ac97->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 414 | |
| 415 | snd_ali_printk("codec_write: reg=%xh data=%xh.\n", reg, val); |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 416 | if (reg == AC97_GPIO_STATUS) { |
| 417 | outl((val << ALI_AC97_GPIO_DATA_SHIFT) | ALI_AC97_GPIO_ENABLE, |
| 418 | ALI_REG(codec, ALI_AC97_GPIO)); |
Sasha Khapyorsky | 5cbff89 | 2005-05-30 08:09:56 +0200 | [diff] [blame] | 419 | return; |
| 420 | } |
| 421 | snd_ali_codec_poke(codec, ac97->num, reg, val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 422 | return ; |
| 423 | } |
| 424 | |
| 425 | |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 426 | static unsigned short snd_ali_codec_read(struct snd_ac97 *ac97, |
| 427 | unsigned short reg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 428 | { |
Takashi Iwai | d1fabd9 | 2005-11-17 14:56:03 +0100 | [diff] [blame] | 429 | struct snd_ali *codec = ac97->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 430 | |
| 431 | snd_ali_printk("codec_read reg=%xh.\n", reg); |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 432 | return snd_ali_codec_peek(codec, ac97->num, reg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 433 | } |
| 434 | |
| 435 | /* |
| 436 | * AC97 Reset |
| 437 | */ |
| 438 | |
Takashi Iwai | d1fabd9 | 2005-11-17 14:56:03 +0100 | [diff] [blame] | 439 | static int snd_ali_reset_5451(struct snd_ali *codec) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 440 | { |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 441 | struct pci_dev *pci_dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 442 | unsigned short wCount, wReg; |
| 443 | unsigned int dwVal; |
| 444 | |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 445 | pci_dev = codec->pci_m1533; |
| 446 | if (pci_dev) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 447 | pci_read_config_dword(pci_dev, 0x7c, &dwVal); |
| 448 | pci_write_config_dword(pci_dev, 0x7c, dwVal | 0x08000000); |
| 449 | udelay(5000); |
| 450 | pci_read_config_dword(pci_dev, 0x7c, &dwVal); |
| 451 | pci_write_config_dword(pci_dev, 0x7c, dwVal & 0xf7ffffff); |
| 452 | udelay(5000); |
| 453 | } |
| 454 | |
| 455 | pci_dev = codec->pci; |
| 456 | pci_read_config_dword(pci_dev, 0x44, &dwVal); |
| 457 | pci_write_config_dword(pci_dev, 0x44, dwVal | 0x000c0000); |
| 458 | udelay(500); |
| 459 | pci_read_config_dword(pci_dev, 0x44, &dwVal); |
| 460 | pci_write_config_dword(pci_dev, 0x44, dwVal & 0xfffbffff); |
| 461 | udelay(5000); |
| 462 | |
| 463 | wCount = 200; |
| 464 | while(wCount--) { |
| 465 | wReg = snd_ali_codec_peek(codec, 0, AC97_POWERDOWN); |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 466 | if ((wReg & 0x000f) == 0x000f) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 467 | return 0; |
| 468 | udelay(5000); |
| 469 | } |
| 470 | |
| 471 | /* non-fatal if you have a non PM capable codec */ |
| 472 | /* snd_printk(KERN_WARNING "ali5451: reset time out\n"); */ |
| 473 | return 0; |
| 474 | } |
| 475 | |
| 476 | #ifdef CODEC_RESET |
| 477 | |
Takashi Iwai | d1fabd9 | 2005-11-17 14:56:03 +0100 | [diff] [blame] | 478 | static int snd_ali_reset_codec(struct snd_ali *codec) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 479 | { |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 480 | struct pci_dev *pci_dev; |
| 481 | unsigned char bVal; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 482 | unsigned int dwVal; |
| 483 | unsigned short wCount, wReg; |
| 484 | |
| 485 | pci_dev = codec->pci_m1533; |
| 486 | |
| 487 | pci_read_config_dword(pci_dev, 0x7c, &dwVal); |
| 488 | pci_write_config_dword(pci_dev, 0x7c, dwVal | 0x08000000); |
| 489 | udelay(5000); |
| 490 | pci_read_config_dword(pci_dev, 0x7c, &dwVal); |
| 491 | pci_write_config_dword(pci_dev, 0x7c, dwVal & 0xf7ffffff); |
| 492 | udelay(5000); |
| 493 | |
| 494 | bVal = inb(ALI_REG(codec,ALI_SCTRL)); |
| 495 | bVal |= 0x02; |
| 496 | outb(ALI_REG(codec,ALI_SCTRL),bVal); |
| 497 | udelay(5000); |
| 498 | bVal = inb(ALI_REG(codec,ALI_SCTRL)); |
| 499 | bVal &= 0xfd; |
| 500 | outb(ALI_REG(codec,ALI_SCTRL),bVal); |
| 501 | udelay(15000); |
| 502 | |
| 503 | wCount = 200; |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 504 | while (wCount--) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 505 | wReg = snd_ali_codec_read(codec->ac97, AC97_POWERDOWN); |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 506 | if ((wReg & 0x000f) == 0x000f) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 507 | return 0; |
| 508 | udelay(5000); |
| 509 | } |
| 510 | return -1; |
| 511 | } |
| 512 | |
| 513 | #endif |
| 514 | |
| 515 | /* |
| 516 | * ALI 5451 Controller |
| 517 | */ |
| 518 | |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 519 | static void snd_ali_enable_special_channel(struct snd_ali *codec, |
| 520 | unsigned int channel) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 521 | { |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 522 | unsigned long dwVal; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 523 | |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 524 | dwVal = inl(ALI_REG(codec, ALI_GLOBAL_CONTROL)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 525 | dwVal |= 1 << (channel & 0x0000001f); |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 526 | outl(dwVal, ALI_REG(codec, ALI_GLOBAL_CONTROL)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 527 | } |
| 528 | |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 529 | static void snd_ali_disable_special_channel(struct snd_ali *codec, |
| 530 | unsigned int channel) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 531 | { |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 532 | unsigned long dwVal; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 533 | |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 534 | dwVal = inl(ALI_REG(codec, ALI_GLOBAL_CONTROL)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 535 | dwVal &= ~(1 << (channel & 0x0000001f)); |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 536 | outl(dwVal, ALI_REG(codec, ALI_GLOBAL_CONTROL)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 537 | } |
| 538 | |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 539 | static void snd_ali_enable_address_interrupt(struct snd_ali *codec) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 540 | { |
| 541 | unsigned int gc; |
| 542 | |
| 543 | gc = inl(ALI_REG(codec, ALI_GC_CIR)); |
| 544 | gc |= ENDLP_IE; |
| 545 | gc |= MIDLP_IE; |
| 546 | outl( gc, ALI_REG(codec, ALI_GC_CIR)); |
| 547 | } |
| 548 | |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 549 | static void snd_ali_disable_address_interrupt(struct snd_ali *codec) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 550 | { |
| 551 | unsigned int gc; |
| 552 | |
| 553 | gc = inl(ALI_REG(codec, ALI_GC_CIR)); |
| 554 | gc &= ~ENDLP_IE; |
| 555 | gc &= ~MIDLP_IE; |
| 556 | outl(gc, ALI_REG(codec, ALI_GC_CIR)); |
| 557 | } |
| 558 | |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 559 | #if 0 /* not used */ |
| 560 | static void snd_ali_enable_voice_irq(struct snd_ali *codec, |
| 561 | unsigned int channel) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 562 | { |
| 563 | unsigned int mask; |
Takashi Iwai | d1fabd9 | 2005-11-17 14:56:03 +0100 | [diff] [blame] | 564 | struct snd_ali_channel_control *pchregs = &(codec->chregs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 565 | |
| 566 | snd_ali_printk("enable_voice_irq channel=%d\n",channel); |
| 567 | |
| 568 | mask = 1 << (channel & 0x1f); |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 569 | pchregs->data.ainten = inl(ALI_REG(codec, pchregs->regs.ainten)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 570 | pchregs->data.ainten |= mask; |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 571 | outl(pchregs->data.ainten, ALI_REG(codec, pchregs->regs.ainten)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 572 | } |
| 573 | #endif |
| 574 | |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 575 | static void snd_ali_disable_voice_irq(struct snd_ali *codec, |
| 576 | unsigned int channel) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 577 | { |
| 578 | unsigned int mask; |
Takashi Iwai | d1fabd9 | 2005-11-17 14:56:03 +0100 | [diff] [blame] | 579 | struct snd_ali_channel_control *pchregs = &(codec->chregs); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 580 | |
| 581 | snd_ali_printk("disable_voice_irq channel=%d\n",channel); |
| 582 | |
| 583 | mask = 1 << (channel & 0x1f); |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 584 | pchregs->data.ainten = inl(ALI_REG(codec, pchregs->regs.ainten)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 585 | pchregs->data.ainten &= ~mask; |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 586 | outl(pchregs->data.ainten, ALI_REG(codec, pchregs->regs.ainten)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 587 | } |
| 588 | |
Takashi Iwai | d1fabd9 | 2005-11-17 14:56:03 +0100 | [diff] [blame] | 589 | static int snd_ali_alloc_pcm_channel(struct snd_ali *codec, int channel) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 590 | { |
| 591 | unsigned int idx = channel & 0x1f; |
| 592 | |
| 593 | if (codec->synth.chcnt >= ALI_CHANNELS){ |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 594 | snd_printk(KERN_ERR |
| 595 | "ali_alloc_pcm_channel: no free channels.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 596 | return -1; |
| 597 | } |
| 598 | |
| 599 | if (!(codec->synth.chmap & (1 << idx))) { |
| 600 | codec->synth.chmap |= 1 << idx; |
| 601 | codec->synth.chcnt++; |
| 602 | snd_ali_printk("alloc_pcm_channel no. %d.\n",idx); |
| 603 | return idx; |
| 604 | } |
| 605 | return -1; |
| 606 | } |
| 607 | |
Takashi Iwai | d1fabd9 | 2005-11-17 14:56:03 +0100 | [diff] [blame] | 608 | static int snd_ali_find_free_channel(struct snd_ali * codec, int rec) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 609 | { |
| 610 | int idx; |
| 611 | int result = -1; |
| 612 | |
| 613 | snd_ali_printk("find_free_channel: for %s\n",rec ? "rec" : "pcm"); |
| 614 | |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 615 | /* recording */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 616 | if (rec) { |
| 617 | if (codec->spdif_support && |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 618 | (inl(ALI_REG(codec, ALI_GLOBAL_CONTROL)) & |
| 619 | ALI_SPDIF_IN_SUPPORT)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 620 | idx = ALI_SPDIF_IN_CHANNEL; |
| 621 | else |
| 622 | idx = ALI_PCM_IN_CHANNEL; |
| 623 | |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 624 | result = snd_ali_alloc_pcm_channel(codec, idx); |
| 625 | if (result >= 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 626 | return result; |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 627 | else { |
| 628 | snd_printk(KERN_ERR "ali_find_free_channel: " |
| 629 | "record channel is busy now.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 630 | return -1; |
| 631 | } |
| 632 | } |
| 633 | |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 634 | /* playback... */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 635 | if (codec->spdif_support && |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 636 | (inl(ALI_REG(codec, ALI_GLOBAL_CONTROL)) & |
| 637 | ALI_SPDIF_OUT_CH_ENABLE)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 638 | idx = ALI_SPDIF_OUT_CHANNEL; |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 639 | result = snd_ali_alloc_pcm_channel(codec, idx); |
| 640 | if (result >= 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 641 | return result; |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 642 | else |
| 643 | snd_printk(KERN_ERR "ali_find_free_channel: " |
| 644 | "S/PDIF out channel is in busy now.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 645 | } |
| 646 | |
| 647 | for (idx = 0; idx < ALI_CHANNELS; idx++) { |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 648 | result = snd_ali_alloc_pcm_channel(codec, idx); |
| 649 | if (result >= 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 650 | return result; |
| 651 | } |
Takashi Iwai | 99b359b | 2005-10-20 18:26:44 +0200 | [diff] [blame] | 652 | snd_printk(KERN_ERR "ali_find_free_channel: no free channels.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 653 | return -1; |
| 654 | } |
| 655 | |
Takashi Iwai | d1fabd9 | 2005-11-17 14:56:03 +0100 | [diff] [blame] | 656 | static void snd_ali_free_channel_pcm(struct snd_ali *codec, int channel) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 657 | { |
| 658 | unsigned int idx = channel & 0x0000001f; |
| 659 | |
| 660 | snd_ali_printk("free_channel_pcm channel=%d\n",channel); |
| 661 | |
| 662 | if (channel < 0 || channel >= ALI_CHANNELS) |
| 663 | return; |
| 664 | |
| 665 | if (!(codec->synth.chmap & (1 << idx))) { |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 666 | snd_printk(KERN_ERR "ali_free_channel_pcm: " |
| 667 | "channel %d is not in use.\n", channel); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 668 | return; |
| 669 | } else { |
| 670 | codec->synth.chmap &= ~(1 << idx); |
| 671 | codec->synth.chcnt--; |
| 672 | } |
| 673 | } |
| 674 | |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 675 | #if 0 /* not used */ |
| 676 | static void snd_ali_start_voice(struct snd_ali *codec, unsigned int channel) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 677 | { |
| 678 | unsigned int mask = 1 << (channel & 0x1f); |
| 679 | |
| 680 | snd_ali_printk("start_voice: channel=%d\n",channel); |
| 681 | outl(mask, ALI_REG(codec,codec->chregs.regs.start)); |
| 682 | } |
| 683 | #endif |
| 684 | |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 685 | static void snd_ali_stop_voice(struct snd_ali *codec, unsigned int channel) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 686 | { |
| 687 | unsigned int mask = 1 << (channel & 0x1f); |
| 688 | |
| 689 | snd_ali_printk("stop_voice: channel=%d\n",channel); |
| 690 | outl(mask, ALI_REG(codec, codec->chregs.regs.stop)); |
| 691 | } |
| 692 | |
| 693 | /* |
| 694 | * S/PDIF Part |
| 695 | */ |
| 696 | |
Takashi Iwai | d1fabd9 | 2005-11-17 14:56:03 +0100 | [diff] [blame] | 697 | static void snd_ali_delay(struct snd_ali *codec,int interval) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 698 | { |
| 699 | unsigned long begintimer,currenttimer; |
| 700 | |
| 701 | begintimer = inl(ALI_REG(codec, ALI_STIMER)); |
| 702 | currenttimer = inl(ALI_REG(codec, ALI_STIMER)); |
| 703 | |
| 704 | while (currenttimer < begintimer + interval) { |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 705 | if (snd_ali_stimer_ready(codec) < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 706 | break; |
| 707 | currenttimer = inl(ALI_REG(codec, ALI_STIMER)); |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 708 | cpu_relax(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 709 | } |
| 710 | } |
| 711 | |
Takashi Iwai | d1fabd9 | 2005-11-17 14:56:03 +0100 | [diff] [blame] | 712 | static void snd_ali_detect_spdif_rate(struct snd_ali *codec) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 713 | { |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 714 | u16 wval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 715 | u16 count = 0; |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 716 | u8 bval, R1 = 0, R2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 717 | |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 718 | bval = inb(ALI_REG(codec, ALI_SPDIF_CTRL + 1)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 719 | bval |= 0x1F; |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 720 | outb(bval, ALI_REG(codec, ALI_SPDIF_CTRL + 1)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 721 | |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 722 | while ((R1 < 0x0b || R1 > 0x0e) && R1 != 0x12 && count <= 50000) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 723 | count ++; |
| 724 | snd_ali_delay(codec, 6); |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 725 | bval = inb(ALI_REG(codec, ALI_SPDIF_CTRL + 1)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 726 | R1 = bval & 0x1F; |
| 727 | } |
| 728 | |
| 729 | if (count > 50000) { |
Takashi Iwai | 99b359b | 2005-10-20 18:26:44 +0200 | [diff] [blame] | 730 | snd_printk(KERN_ERR "ali_detect_spdif_rate: timeout!\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 731 | return; |
| 732 | } |
| 733 | |
| 734 | count = 0; |
| 735 | while (count++ <= 50000) { |
| 736 | snd_ali_delay(codec, 6); |
| 737 | bval = inb(ALI_REG(codec,ALI_SPDIF_CTRL + 1)); |
| 738 | R2 = bval & 0x1F; |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 739 | if (R2 != R1) |
| 740 | R1 = R2; |
| 741 | else |
| 742 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 743 | } |
| 744 | |
| 745 | if (count > 50000) { |
Takashi Iwai | 99b359b | 2005-10-20 18:26:44 +0200 | [diff] [blame] | 746 | snd_printk(KERN_ERR "ali_detect_spdif_rate: timeout!\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 747 | return; |
| 748 | } |
| 749 | |
| 750 | if (R2 >= 0x0b && R2 <= 0x0e) { |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 751 | wval = inw(ALI_REG(codec, ALI_SPDIF_CTRL + 2)); |
| 752 | wval &= 0xe0f0; |
| 753 | wval |= (0x09 << 8) | 0x05; |
| 754 | outw(wval, ALI_REG(codec, ALI_SPDIF_CTRL + 2)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 755 | |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 756 | bval = inb(ALI_REG(codec, ALI_SPDIF_CS + 3)) & 0xf0; |
| 757 | outb(bval | 0x02, ALI_REG(codec, ALI_SPDIF_CS + 3)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 758 | } else if (R2 == 0x12) { |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 759 | wval = inw(ALI_REG(codec, ALI_SPDIF_CTRL + 2)); |
| 760 | wval &= 0xe0f0; |
| 761 | wval |= (0x0e << 8) | 0x08; |
| 762 | outw(wval, ALI_REG(codec, ALI_SPDIF_CTRL + 2)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 763 | |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 764 | bval = inb(ALI_REG(codec,ALI_SPDIF_CS + 3)) & 0xf0; |
| 765 | outb(bval | 0x03, ALI_REG(codec, ALI_SPDIF_CS + 3)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 766 | } |
| 767 | } |
| 768 | |
Takashi Iwai | d1fabd9 | 2005-11-17 14:56:03 +0100 | [diff] [blame] | 769 | static unsigned int snd_ali_get_spdif_in_rate(struct snd_ali *codec) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 770 | { |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 771 | u32 dwRate; |
| 772 | u8 bval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 773 | |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 774 | bval = inb(ALI_REG(codec, ALI_SPDIF_CTRL)); |
| 775 | bval &= 0x7f; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 776 | bval |= 0x40; |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 777 | outb(bval, ALI_REG(codec, ALI_SPDIF_CTRL)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 778 | |
| 779 | snd_ali_detect_spdif_rate(codec); |
| 780 | |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 781 | bval = inb(ALI_REG(codec, ALI_SPDIF_CS + 3)); |
| 782 | bval &= 0x0f; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 783 | |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 784 | switch (bval) { |
| 785 | case 0: dwRate = 44100; break; |
| 786 | case 1: dwRate = 48000; break; |
| 787 | case 2: dwRate = 32000; break; |
| 788 | default: dwRate = 0; break; |
| 789 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 790 | |
| 791 | return dwRate; |
| 792 | } |
| 793 | |
Takashi Iwai | d1fabd9 | 2005-11-17 14:56:03 +0100 | [diff] [blame] | 794 | static void snd_ali_enable_spdif_in(struct snd_ali *codec) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 795 | { |
| 796 | unsigned int dwVal; |
| 797 | |
| 798 | dwVal = inl(ALI_REG(codec, ALI_GLOBAL_CONTROL)); |
| 799 | dwVal |= ALI_SPDIF_IN_SUPPORT; |
| 800 | outl(dwVal, ALI_REG(codec, ALI_GLOBAL_CONTROL)); |
| 801 | |
| 802 | dwVal = inb(ALI_REG(codec, ALI_SPDIF_CTRL)); |
| 803 | dwVal |= 0x02; |
| 804 | outb(dwVal, ALI_REG(codec, ALI_SPDIF_CTRL)); |
| 805 | |
| 806 | snd_ali_enable_special_channel(codec, ALI_SPDIF_IN_CHANNEL); |
| 807 | } |
| 808 | |
Takashi Iwai | d1fabd9 | 2005-11-17 14:56:03 +0100 | [diff] [blame] | 809 | static void snd_ali_disable_spdif_in(struct snd_ali *codec) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 810 | { |
| 811 | unsigned int dwVal; |
| 812 | |
| 813 | dwVal = inl(ALI_REG(codec, ALI_GLOBAL_CONTROL)); |
| 814 | dwVal &= ~ALI_SPDIF_IN_SUPPORT; |
| 815 | outl(dwVal, ALI_REG(codec, ALI_GLOBAL_CONTROL)); |
| 816 | |
| 817 | snd_ali_disable_special_channel(codec, ALI_SPDIF_IN_CHANNEL); |
| 818 | } |
| 819 | |
| 820 | |
Takashi Iwai | d1fabd9 | 2005-11-17 14:56:03 +0100 | [diff] [blame] | 821 | static void snd_ali_set_spdif_out_rate(struct snd_ali *codec, unsigned int rate) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 822 | { |
| 823 | unsigned char bVal; |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 824 | unsigned int dwRate; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 825 | |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 826 | switch (rate) { |
| 827 | case 32000: dwRate = 0x300; break; |
| 828 | case 48000: dwRate = 0x200; break; |
| 829 | default: dwRate = 0; break; |
| 830 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 831 | |
| 832 | bVal = inb(ALI_REG(codec, ALI_SPDIF_CTRL)); |
| 833 | bVal &= (unsigned char)(~(1<<6)); |
| 834 | |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 835 | bVal |= 0x80; /* select right */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 836 | outb(bVal, ALI_REG(codec, ALI_SPDIF_CTRL)); |
| 837 | outb(dwRate | 0x20, ALI_REG(codec, ALI_SPDIF_CS + 2)); |
| 838 | |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 839 | bVal &= ~0x80; /* select left */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 840 | outb(bVal, ALI_REG(codec, ALI_SPDIF_CTRL)); |
| 841 | outw(rate | 0x10, ALI_REG(codec, ALI_SPDIF_CS + 2)); |
| 842 | } |
| 843 | |
Takashi Iwai | d1fabd9 | 2005-11-17 14:56:03 +0100 | [diff] [blame] | 844 | static void snd_ali_enable_spdif_out(struct snd_ali *codec) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 845 | { |
| 846 | unsigned short wVal; |
| 847 | unsigned char bVal; |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 848 | struct pci_dev *pci_dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 849 | |
| 850 | pci_dev = codec->pci_m1533; |
| 851 | if (pci_dev == NULL) |
| 852 | return; |
| 853 | pci_read_config_byte(pci_dev, 0x61, &bVal); |
| 854 | bVal |= 0x40; |
| 855 | pci_write_config_byte(pci_dev, 0x61, bVal); |
| 856 | pci_read_config_byte(pci_dev, 0x7d, &bVal); |
| 857 | bVal |= 0x01; |
| 858 | pci_write_config_byte(pci_dev, 0x7d, bVal); |
| 859 | |
| 860 | pci_read_config_byte(pci_dev, 0x7e, &bVal); |
| 861 | bVal &= (~0x20); |
| 862 | bVal |= 0x10; |
| 863 | pci_write_config_byte(pci_dev, 0x7e, bVal); |
| 864 | |
| 865 | bVal = inb(ALI_REG(codec, ALI_SCTRL)); |
| 866 | outb(bVal | ALI_SPDIF_OUT_ENABLE, ALI_REG(codec, ALI_SCTRL)); |
| 867 | |
| 868 | bVal = inb(ALI_REG(codec, ALI_SPDIF_CTRL)); |
| 869 | outb(bVal & ALI_SPDIF_OUT_CH_STATUS, ALI_REG(codec, ALI_SPDIF_CTRL)); |
| 870 | |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 871 | wVal = inw(ALI_REG(codec, ALI_GLOBAL_CONTROL)); |
| 872 | wVal |= ALI_SPDIF_OUT_SEL_PCM; |
| 873 | outw(wVal, ALI_REG(codec, ALI_GLOBAL_CONTROL)); |
| 874 | snd_ali_disable_special_channel(codec, ALI_SPDIF_OUT_CHANNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 875 | } |
| 876 | |
Takashi Iwai | d1fabd9 | 2005-11-17 14:56:03 +0100 | [diff] [blame] | 877 | static void snd_ali_enable_spdif_chnout(struct snd_ali *codec) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 878 | { |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 879 | unsigned short wVal; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 880 | |
| 881 | wVal = inw(ALI_REG(codec, ALI_GLOBAL_CONTROL)); |
| 882 | wVal &= ~ALI_SPDIF_OUT_SEL_PCM; |
| 883 | outw(wVal, ALI_REG(codec, ALI_GLOBAL_CONTROL)); |
| 884 | /* |
| 885 | wVal = inw(ALI_REG(codec, ALI_SPDIF_CS)); |
| 886 | if (flag & ALI_SPDIF_OUT_NON_PCM) |
| 887 | wVal |= 0x0002; |
| 888 | else |
| 889 | wVal &= (~0x0002); |
| 890 | outw(wVal, ALI_REG(codec, ALI_SPDIF_CS)); |
| 891 | */ |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 892 | snd_ali_enable_special_channel(codec, ALI_SPDIF_OUT_CHANNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 893 | } |
| 894 | |
Takashi Iwai | d1fabd9 | 2005-11-17 14:56:03 +0100 | [diff] [blame] | 895 | static void snd_ali_disable_spdif_chnout(struct snd_ali *codec) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 896 | { |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 897 | unsigned short wVal; |
| 898 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 899 | wVal = inw(ALI_REG(codec, ALI_GLOBAL_CONTROL)); |
| 900 | wVal |= ALI_SPDIF_OUT_SEL_PCM; |
| 901 | outw(wVal, ALI_REG(codec, ALI_GLOBAL_CONTROL)); |
| 902 | |
| 903 | snd_ali_enable_special_channel(codec, ALI_SPDIF_OUT_CHANNEL); |
| 904 | } |
| 905 | |
Takashi Iwai | d1fabd9 | 2005-11-17 14:56:03 +0100 | [diff] [blame] | 906 | static void snd_ali_disable_spdif_out(struct snd_ali *codec) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 907 | { |
| 908 | unsigned char bVal; |
| 909 | |
| 910 | bVal = inb(ALI_REG(codec, ALI_SCTRL)); |
| 911 | outb(bVal & ~ALI_SPDIF_OUT_ENABLE, ALI_REG(codec, ALI_SCTRL)); |
| 912 | |
| 913 | snd_ali_disable_spdif_chnout(codec); |
| 914 | } |
| 915 | |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 916 | static void snd_ali_update_ptr(struct snd_ali *codec, int channel) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 917 | { |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 918 | struct snd_ali_voice *pvoice; |
Takashi Iwai | d1fabd9 | 2005-11-17 14:56:03 +0100 | [diff] [blame] | 919 | struct snd_pcm_runtime *runtime; |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 920 | struct snd_ali_channel_control *pchregs; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 921 | unsigned int old, mask; |
| 922 | #ifdef ALI_DEBUG |
| 923 | unsigned int temp, cspf; |
| 924 | #endif |
| 925 | |
| 926 | pchregs = &(codec->chregs); |
| 927 | |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 928 | /* check if interrupt occurred for channel */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 929 | old = pchregs->data.aint; |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 930 | mask = 1U << (channel & 0x1f); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 931 | |
| 932 | if (!(old & mask)) |
| 933 | return; |
| 934 | |
| 935 | pvoice = &codec->synth.voices[channel]; |
| 936 | runtime = pvoice->substream->runtime; |
| 937 | |
| 938 | udelay(100); |
| 939 | spin_lock(&codec->reg_lock); |
| 940 | |
| 941 | if (pvoice->pcm && pvoice->substream) { |
| 942 | /* pcm interrupt */ |
| 943 | #ifdef ALI_DEBUG |
| 944 | outb((u8)(pvoice->number), ALI_REG(codec, ALI_GC_CIR)); |
| 945 | temp = inw(ALI_REG(codec, ALI_CSO_ALPHA_FMS + 2)); |
| 946 | cspf = (inl(ALI_REG(codec, ALI_CSPF)) & mask) == mask; |
| 947 | #endif |
| 948 | if (pvoice->running) { |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 949 | snd_ali_printk("update_ptr: cso=%4.4x cspf=%d.\n", |
| 950 | (u16)temp, cspf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 951 | spin_unlock(&codec->reg_lock); |
| 952 | snd_pcm_period_elapsed(pvoice->substream); |
| 953 | spin_lock(&codec->reg_lock); |
| 954 | } else { |
| 955 | snd_ali_stop_voice(codec, channel); |
| 956 | snd_ali_disable_voice_irq(codec, channel); |
| 957 | } |
| 958 | } else if (codec->synth.voices[channel].synth) { |
| 959 | /* synth interrupt */ |
| 960 | } else if (codec->synth.voices[channel].midi) { |
| 961 | /* midi interrupt */ |
| 962 | } else { |
| 963 | /* unknown interrupt */ |
| 964 | snd_ali_stop_voice(codec, channel); |
| 965 | snd_ali_disable_voice_irq(codec, channel); |
| 966 | } |
| 967 | spin_unlock(&codec->reg_lock); |
| 968 | outl(mask,ALI_REG(codec,pchregs->regs.aint)); |
| 969 | pchregs->data.aint = old & (~mask); |
| 970 | } |
| 971 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 972 | static irqreturn_t snd_ali_card_interrupt(int irq, void *dev_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 973 | { |
Takashi Iwai | d1fabd9 | 2005-11-17 14:56:03 +0100 | [diff] [blame] | 974 | struct snd_ali *codec = dev_id; |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 975 | int channel; |
| 976 | unsigned int audio_int; |
| 977 | struct snd_ali_channel_control *pchregs; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 978 | |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 979 | if (codec == NULL || !codec->hw_initialized) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 980 | return IRQ_NONE; |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 981 | |
| 982 | audio_int = inl(ALI_REG(codec, ALI_MISCINT)); |
| 983 | if (!audio_int) |
| 984 | return IRQ_NONE; |
| 985 | |
| 986 | pchregs = &(codec->chregs); |
| 987 | if (audio_int & ADDRESS_IRQ) { |
| 988 | /* get interrupt status for all channels */ |
| 989 | pchregs->data.aint = inl(ALI_REG(codec, pchregs->regs.aint)); |
| 990 | for (channel = 0; channel < ALI_CHANNELS; channel++) |
| 991 | snd_ali_update_ptr(codec, channel); |
| 992 | } |
| 993 | outl((TARGET_REACHED | MIXER_OVERFLOW | MIXER_UNDERFLOW), |
| 994 | ALI_REG(codec, ALI_MISCINT)); |
| 995 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 996 | return IRQ_HANDLED; |
| 997 | } |
| 998 | |
| 999 | |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 1000 | static struct snd_ali_voice *snd_ali_alloc_voice(struct snd_ali * codec, |
| 1001 | int type, int rec, int channel) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1002 | { |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 1003 | struct snd_ali_voice *pvoice; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1004 | int idx; |
| 1005 | |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 1006 | snd_ali_printk("alloc_voice: type=%d rec=%d\n", type, rec); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1007 | |
Takashi Iwai | 755e137 | 2005-11-11 21:05:27 +0100 | [diff] [blame] | 1008 | spin_lock_irq(&codec->voice_alloc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1009 | if (type == SNDRV_ALI_VOICE_TYPE_PCM) { |
Sasha Khapyorsky | 5cbff89 | 2005-05-30 08:09:56 +0200 | [diff] [blame] | 1010 | idx = channel > 0 ? snd_ali_alloc_pcm_channel(codec, channel) : |
| 1011 | snd_ali_find_free_channel(codec,rec); |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 1012 | if (idx < 0) { |
Takashi Iwai | 99b359b | 2005-10-20 18:26:44 +0200 | [diff] [blame] | 1013 | snd_printk(KERN_ERR "ali_alloc_voice: err.\n"); |
Takashi Iwai | 755e137 | 2005-11-11 21:05:27 +0100 | [diff] [blame] | 1014 | spin_unlock_irq(&codec->voice_alloc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1015 | return NULL; |
| 1016 | } |
| 1017 | pvoice = &(codec->synth.voices[idx]); |
Takashi Iwai | 755e137 | 2005-11-11 21:05:27 +0100 | [diff] [blame] | 1018 | pvoice->codec = codec; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1019 | pvoice->use = 1; |
| 1020 | pvoice->pcm = 1; |
| 1021 | pvoice->mode = rec; |
Takashi Iwai | 755e137 | 2005-11-11 21:05:27 +0100 | [diff] [blame] | 1022 | spin_unlock_irq(&codec->voice_alloc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1023 | return pvoice; |
| 1024 | } |
Takashi Iwai | 755e137 | 2005-11-11 21:05:27 +0100 | [diff] [blame] | 1025 | spin_unlock_irq(&codec->voice_alloc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1026 | return NULL; |
| 1027 | } |
| 1028 | |
| 1029 | |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 1030 | static void snd_ali_free_voice(struct snd_ali * codec, |
| 1031 | struct snd_ali_voice *pvoice) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1032 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1033 | void (*private_free)(void *); |
| 1034 | void *private_data; |
| 1035 | |
| 1036 | snd_ali_printk("free_voice: channel=%d\n",pvoice->number); |
| 1037 | if (pvoice == NULL || !pvoice->use) |
| 1038 | return; |
| 1039 | snd_ali_clear_voices(codec, pvoice->number, pvoice->number); |
Takashi Iwai | 755e137 | 2005-11-11 21:05:27 +0100 | [diff] [blame] | 1040 | spin_lock_irq(&codec->voice_alloc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1041 | private_free = pvoice->private_free; |
| 1042 | private_data = pvoice->private_data; |
| 1043 | pvoice->private_free = NULL; |
| 1044 | pvoice->private_data = NULL; |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 1045 | if (pvoice->pcm) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1046 | snd_ali_free_channel_pcm(codec, pvoice->number); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1047 | pvoice->use = pvoice->pcm = pvoice->synth = 0; |
| 1048 | pvoice->substream = NULL; |
Takashi Iwai | 755e137 | 2005-11-11 21:05:27 +0100 | [diff] [blame] | 1049 | spin_unlock_irq(&codec->voice_alloc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1050 | if (private_free) |
| 1051 | private_free(private_data); |
| 1052 | } |
| 1053 | |
| 1054 | |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 1055 | static void snd_ali_clear_voices(struct snd_ali *codec, |
| 1056 | unsigned int v_min, |
| 1057 | unsigned int v_max) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1058 | { |
| 1059 | unsigned int i; |
| 1060 | |
| 1061 | for (i = v_min; i <= v_max; i++) { |
| 1062 | snd_ali_stop_voice(codec, i); |
| 1063 | snd_ali_disable_voice_irq(codec, i); |
| 1064 | } |
| 1065 | } |
| 1066 | |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 1067 | static void snd_ali_write_voice_regs(struct snd_ali *codec, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1068 | unsigned int Channel, |
| 1069 | unsigned int LBA, |
| 1070 | unsigned int CSO, |
| 1071 | unsigned int ESO, |
| 1072 | unsigned int DELTA, |
| 1073 | unsigned int ALPHA_FMS, |
| 1074 | unsigned int GVSEL, |
| 1075 | unsigned int PAN, |
| 1076 | unsigned int VOL, |
| 1077 | unsigned int CTRL, |
| 1078 | unsigned int EC) |
| 1079 | { |
| 1080 | unsigned int ctlcmds[4]; |
| 1081 | |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 1082 | outb((unsigned char)(Channel & 0x001f), ALI_REG(codec, ALI_GC_CIR)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1083 | |
| 1084 | ctlcmds[0] = (CSO << 16) | (ALPHA_FMS & 0x0000ffff); |
| 1085 | ctlcmds[1] = LBA; |
| 1086 | ctlcmds[2] = (ESO << 16) | (DELTA & 0x0ffff); |
| 1087 | ctlcmds[3] = (GVSEL << 31) | |
| 1088 | ((PAN & 0x0000007f) << 24) | |
| 1089 | ((VOL & 0x000000ff) << 16) | |
| 1090 | ((CTRL & 0x0000000f) << 12) | |
| 1091 | (EC & 0x00000fff); |
| 1092 | |
| 1093 | outb(Channel, ALI_REG(codec, ALI_GC_CIR)); |
| 1094 | |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 1095 | outl(ctlcmds[0], ALI_REG(codec, ALI_CSO_ALPHA_FMS)); |
| 1096 | outl(ctlcmds[1], ALI_REG(codec, ALI_LBA)); |
| 1097 | outl(ctlcmds[2], ALI_REG(codec, ALI_ESO_DELTA)); |
| 1098 | outl(ctlcmds[3], ALI_REG(codec, ALI_GVSEL_PAN_VOC_CTRL_EC)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1099 | |
| 1100 | outl(0x30000000, ALI_REG(codec, ALI_EBUF1)); /* Still Mode */ |
| 1101 | outl(0x30000000, ALI_REG(codec, ALI_EBUF2)); /* Still Mode */ |
| 1102 | } |
| 1103 | |
| 1104 | static unsigned int snd_ali_convert_rate(unsigned int rate, int rec) |
| 1105 | { |
| 1106 | unsigned int delta; |
| 1107 | |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 1108 | if (rate < 4000) |
| 1109 | rate = 4000; |
| 1110 | if (rate > 48000) |
| 1111 | rate = 48000; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1112 | |
| 1113 | if (rec) { |
| 1114 | if (rate == 44100) |
| 1115 | delta = 0x116a; |
| 1116 | else if (rate == 8000) |
| 1117 | delta = 0x6000; |
| 1118 | else if (rate == 48000) |
| 1119 | delta = 0x1000; |
| 1120 | else |
| 1121 | delta = ((48000 << 12) / rate) & 0x0000ffff; |
| 1122 | } else { |
| 1123 | if (rate == 44100) |
| 1124 | delta = 0xeb3; |
| 1125 | else if (rate == 8000) |
| 1126 | delta = 0x2ab; |
| 1127 | else if (rate == 48000) |
| 1128 | delta = 0x1000; |
| 1129 | else |
| 1130 | delta = (((rate << 12) + rate) / 48000) & 0x0000ffff; |
| 1131 | } |
| 1132 | |
| 1133 | return delta; |
| 1134 | } |
| 1135 | |
Takashi Iwai | d1fabd9 | 2005-11-17 14:56:03 +0100 | [diff] [blame] | 1136 | static unsigned int snd_ali_control_mode(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1137 | { |
| 1138 | unsigned int CTRL; |
Takashi Iwai | d1fabd9 | 2005-11-17 14:56:03 +0100 | [diff] [blame] | 1139 | struct snd_pcm_runtime *runtime = substream->runtime; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1140 | |
| 1141 | /* set ctrl mode |
| 1142 | CTRL default: 8-bit (unsigned) mono, loop mode enabled |
| 1143 | */ |
| 1144 | CTRL = 0x00000001; |
| 1145 | if (snd_pcm_format_width(runtime->format) == 16) |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 1146 | CTRL |= 0x00000008; /* 16-bit data */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1147 | if (!snd_pcm_format_unsigned(runtime->format)) |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 1148 | CTRL |= 0x00000002; /* signed data */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1149 | if (runtime->channels > 1) |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 1150 | CTRL |= 0x00000004; /* stereo data */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1151 | return CTRL; |
| 1152 | } |
| 1153 | |
| 1154 | /* |
| 1155 | * PCM part |
| 1156 | */ |
| 1157 | |
Takashi Iwai | d1fabd9 | 2005-11-17 14:56:03 +0100 | [diff] [blame] | 1158 | static int snd_ali_trigger(struct snd_pcm_substream *substream, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1159 | int cmd) |
| 1160 | |
| 1161 | { |
Takashi Iwai | d1fabd9 | 2005-11-17 14:56:03 +0100 | [diff] [blame] | 1162 | struct snd_ali *codec = snd_pcm_substream_chip(substream); |
Takashi Iwai | d1fabd9 | 2005-11-17 14:56:03 +0100 | [diff] [blame] | 1163 | struct snd_pcm_substream *s; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1164 | unsigned int what, whati, capture_flag; |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 1165 | struct snd_ali_voice *pvoice, *evoice; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1166 | unsigned int val; |
| 1167 | int do_start; |
| 1168 | |
| 1169 | switch (cmd) { |
| 1170 | case SNDRV_PCM_TRIGGER_START: |
| 1171 | case SNDRV_PCM_TRIGGER_RESUME: |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 1172 | do_start = 1; |
| 1173 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1174 | case SNDRV_PCM_TRIGGER_STOP: |
| 1175 | case SNDRV_PCM_TRIGGER_SUSPEND: |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 1176 | do_start = 0; |
| 1177 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1178 | default: |
| 1179 | return -EINVAL; |
| 1180 | } |
| 1181 | |
| 1182 | what = whati = capture_flag = 0; |
Takashi Iwai | ef991b9 | 2007-02-22 12:52:53 +0100 | [diff] [blame] | 1183 | snd_pcm_group_for_each_entry(s, substream) { |
Takashi Iwai | d1fabd9 | 2005-11-17 14:56:03 +0100 | [diff] [blame] | 1184 | if ((struct snd_ali *) snd_pcm_substream_chip(s) == codec) { |
| 1185 | pvoice = s->runtime->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1186 | evoice = pvoice->extra; |
| 1187 | what |= 1 << (pvoice->number & 0x1f); |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 1188 | if (evoice == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1189 | whati |= 1 << (pvoice->number & 0x1f); |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 1190 | else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1191 | whati |= 1 << (evoice->number & 0x1f); |
| 1192 | what |= 1 << (evoice->number & 0x1f); |
| 1193 | } |
| 1194 | if (do_start) { |
| 1195 | pvoice->running = 1; |
| 1196 | if (evoice != NULL) |
| 1197 | evoice->running = 1; |
| 1198 | } else { |
| 1199 | pvoice->running = 0; |
| 1200 | if (evoice != NULL) |
| 1201 | evoice->running = 0; |
| 1202 | } |
| 1203 | snd_pcm_trigger_done(s, substream); |
| 1204 | if (pvoice->mode) |
| 1205 | capture_flag = 1; |
| 1206 | } |
| 1207 | } |
| 1208 | spin_lock(&codec->reg_lock); |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 1209 | if (!do_start) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1210 | outl(what, ALI_REG(codec, ALI_STOP)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1211 | val = inl(ALI_REG(codec, ALI_AINTEN)); |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 1212 | if (do_start) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1213 | val |= whati; |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 1214 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1215 | val &= ~whati; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1216 | outl(val, ALI_REG(codec, ALI_AINTEN)); |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 1217 | if (do_start) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1218 | outl(what, ALI_REG(codec, ALI_START)); |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 1219 | snd_ali_printk("trigger: what=%xh whati=%xh\n", what, whati); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1220 | spin_unlock(&codec->reg_lock); |
| 1221 | |
| 1222 | return 0; |
| 1223 | } |
| 1224 | |
Takashi Iwai | d1fabd9 | 2005-11-17 14:56:03 +0100 | [diff] [blame] | 1225 | static int snd_ali_playback_hw_params(struct snd_pcm_substream *substream, |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 1226 | struct snd_pcm_hw_params *hw_params) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1227 | { |
Takashi Iwai | d1fabd9 | 2005-11-17 14:56:03 +0100 | [diff] [blame] | 1228 | struct snd_ali *codec = snd_pcm_substream_chip(substream); |
| 1229 | struct snd_pcm_runtime *runtime = substream->runtime; |
| 1230 | struct snd_ali_voice *pvoice = runtime->private_data; |
| 1231 | struct snd_ali_voice *evoice = pvoice->extra; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1232 | int err; |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 1233 | |
| 1234 | err = snd_pcm_lib_malloc_pages(substream, |
| 1235 | params_buffer_bytes(hw_params)); |
| 1236 | if (err < 0) |
| 1237 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1238 | |
| 1239 | /* voice management */ |
| 1240 | |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 1241 | if (params_buffer_size(hw_params) / 2 != |
| 1242 | params_period_size(hw_params)) { |
| 1243 | if (!evoice) { |
| 1244 | evoice = snd_ali_alloc_voice(codec, |
| 1245 | SNDRV_ALI_VOICE_TYPE_PCM, |
| 1246 | 0, -1); |
| 1247 | if (!evoice) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1248 | return -ENOMEM; |
| 1249 | pvoice->extra = evoice; |
| 1250 | evoice->substream = substream; |
| 1251 | } |
| 1252 | } else { |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 1253 | if (!evoice) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1254 | snd_ali_free_voice(codec, evoice); |
| 1255 | pvoice->extra = evoice = NULL; |
| 1256 | } |
| 1257 | } |
| 1258 | |
| 1259 | return 0; |
| 1260 | } |
| 1261 | |
Takashi Iwai | d1fabd9 | 2005-11-17 14:56:03 +0100 | [diff] [blame] | 1262 | static int snd_ali_playback_hw_free(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1263 | { |
Takashi Iwai | d1fabd9 | 2005-11-17 14:56:03 +0100 | [diff] [blame] | 1264 | struct snd_ali *codec = snd_pcm_substream_chip(substream); |
| 1265 | struct snd_pcm_runtime *runtime = substream->runtime; |
| 1266 | struct snd_ali_voice *pvoice = runtime->private_data; |
| 1267 | struct snd_ali_voice *evoice = pvoice ? pvoice->extra : NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1268 | |
| 1269 | snd_pcm_lib_free_pages(substream); |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 1270 | if (!evoice) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1271 | snd_ali_free_voice(codec, evoice); |
| 1272 | pvoice->extra = NULL; |
| 1273 | } |
| 1274 | return 0; |
| 1275 | } |
| 1276 | |
Takashi Iwai | d1fabd9 | 2005-11-17 14:56:03 +0100 | [diff] [blame] | 1277 | static int snd_ali_hw_params(struct snd_pcm_substream *substream, |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 1278 | struct snd_pcm_hw_params *hw_params) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1279 | { |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 1280 | return snd_pcm_lib_malloc_pages(substream, |
| 1281 | params_buffer_bytes(hw_params)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1282 | } |
| 1283 | |
Takashi Iwai | d1fabd9 | 2005-11-17 14:56:03 +0100 | [diff] [blame] | 1284 | static int snd_ali_hw_free(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1285 | { |
| 1286 | return snd_pcm_lib_free_pages(substream); |
| 1287 | } |
| 1288 | |
Takashi Iwai | d1fabd9 | 2005-11-17 14:56:03 +0100 | [diff] [blame] | 1289 | static int snd_ali_playback_prepare(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1290 | { |
Takashi Iwai | d1fabd9 | 2005-11-17 14:56:03 +0100 | [diff] [blame] | 1291 | struct snd_ali *codec = snd_pcm_substream_chip(substream); |
| 1292 | struct snd_pcm_runtime *runtime = substream->runtime; |
| 1293 | struct snd_ali_voice *pvoice = runtime->private_data; |
| 1294 | struct snd_ali_voice *evoice = pvoice->extra; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1295 | |
| 1296 | unsigned int LBA; |
| 1297 | unsigned int Delta; |
| 1298 | unsigned int ESO; |
| 1299 | unsigned int CTRL; |
| 1300 | unsigned int GVSEL; |
| 1301 | unsigned int PAN; |
| 1302 | unsigned int VOL; |
| 1303 | unsigned int EC; |
| 1304 | |
| 1305 | snd_ali_printk("playback_prepare ...\n"); |
| 1306 | |
Takashi Iwai | 755e137 | 2005-11-11 21:05:27 +0100 | [diff] [blame] | 1307 | spin_lock_irq(&codec->reg_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1308 | |
| 1309 | /* set Delta (rate) value */ |
| 1310 | Delta = snd_ali_convert_rate(runtime->rate, 0); |
| 1311 | |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 1312 | if (pvoice->number == ALI_SPDIF_IN_CHANNEL || |
| 1313 | pvoice->number == ALI_PCM_IN_CHANNEL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1314 | snd_ali_disable_special_channel(codec, pvoice->number); |
| 1315 | else if (codec->spdif_support && |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 1316 | (inl(ALI_REG(codec, ALI_GLOBAL_CONTROL)) & |
| 1317 | ALI_SPDIF_OUT_CH_ENABLE) |
| 1318 | && pvoice->number == ALI_SPDIF_OUT_CHANNEL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1319 | snd_ali_set_spdif_out_rate(codec, runtime->rate); |
| 1320 | Delta = 0x1000; |
| 1321 | } |
| 1322 | |
| 1323 | /* set Loop Back Address */ |
| 1324 | LBA = runtime->dma_addr; |
| 1325 | |
| 1326 | /* set interrupt count size */ |
| 1327 | pvoice->count = runtime->period_size; |
| 1328 | |
| 1329 | /* set target ESO for channel */ |
| 1330 | pvoice->eso = runtime->buffer_size; |
| 1331 | |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 1332 | snd_ali_printk("playback_prepare: eso=%xh count=%xh\n", |
| 1333 | pvoice->eso, pvoice->count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1334 | |
| 1335 | /* set ESO to capture first MIDLP interrupt */ |
| 1336 | ESO = pvoice->eso -1; |
| 1337 | /* set ctrl mode */ |
| 1338 | CTRL = snd_ali_control_mode(substream); |
| 1339 | |
| 1340 | GVSEL = 1; |
| 1341 | PAN = 0; |
| 1342 | VOL = 0; |
| 1343 | EC = 0; |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 1344 | snd_ali_printk("playback_prepare:\n"); |
| 1345 | snd_ali_printk("ch=%d, Rate=%d Delta=%xh,GVSEL=%xh,PAN=%xh,CTRL=%xh\n", |
| 1346 | pvoice->number,runtime->rate,Delta,GVSEL,PAN,CTRL); |
| 1347 | snd_ali_write_voice_regs(codec, |
| 1348 | pvoice->number, |
| 1349 | LBA, |
| 1350 | 0, /* cso */ |
| 1351 | ESO, |
| 1352 | Delta, |
| 1353 | 0, /* alpha */ |
| 1354 | GVSEL, |
| 1355 | PAN, |
| 1356 | VOL, |
| 1357 | CTRL, |
| 1358 | EC); |
| 1359 | if (!evoice) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1360 | evoice->count = pvoice->count; |
| 1361 | evoice->eso = pvoice->count << 1; |
| 1362 | ESO = evoice->eso - 1; |
| 1363 | snd_ali_write_voice_regs(codec, |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 1364 | evoice->number, |
| 1365 | LBA, |
| 1366 | 0, /* cso */ |
| 1367 | ESO, |
| 1368 | Delta, |
| 1369 | 0, /* alpha */ |
| 1370 | GVSEL, |
| 1371 | 0x7f, |
| 1372 | 0x3ff, |
| 1373 | CTRL, |
| 1374 | EC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1375 | } |
Takashi Iwai | 755e137 | 2005-11-11 21:05:27 +0100 | [diff] [blame] | 1376 | spin_unlock_irq(&codec->reg_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1377 | return 0; |
| 1378 | } |
| 1379 | |
| 1380 | |
Takashi Iwai | d1fabd9 | 2005-11-17 14:56:03 +0100 | [diff] [blame] | 1381 | static int snd_ali_prepare(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1382 | { |
Takashi Iwai | d1fabd9 | 2005-11-17 14:56:03 +0100 | [diff] [blame] | 1383 | struct snd_ali *codec = snd_pcm_substream_chip(substream); |
| 1384 | struct snd_pcm_runtime *runtime = substream->runtime; |
| 1385 | struct snd_ali_voice *pvoice = runtime->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1386 | unsigned int LBA; |
| 1387 | unsigned int Delta; |
| 1388 | unsigned int ESO; |
| 1389 | unsigned int CTRL; |
| 1390 | unsigned int GVSEL; |
| 1391 | unsigned int PAN; |
| 1392 | unsigned int VOL; |
| 1393 | unsigned int EC; |
| 1394 | u8 bValue; |
| 1395 | |
Takashi Iwai | 755e137 | 2005-11-11 21:05:27 +0100 | [diff] [blame] | 1396 | spin_lock_irq(&codec->reg_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1397 | |
Sasha Khapyorsky | 5cbff89 | 2005-05-30 08:09:56 +0200 | [diff] [blame] | 1398 | snd_ali_printk("ali_prepare...\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1399 | |
| 1400 | snd_ali_enable_special_channel(codec,pvoice->number); |
| 1401 | |
Sasha Khapyorsky | 5cbff89 | 2005-05-30 08:09:56 +0200 | [diff] [blame] | 1402 | Delta = (pvoice->number == ALI_MODEM_IN_CHANNEL || |
| 1403 | pvoice->number == ALI_MODEM_OUT_CHANNEL) ? |
| 1404 | 0x1000 : snd_ali_convert_rate(runtime->rate, pvoice->mode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1405 | |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 1406 | /* Prepare capture intr channel */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1407 | if (pvoice->number == ALI_SPDIF_IN_CHANNEL) { |
| 1408 | |
| 1409 | unsigned int rate; |
| 1410 | |
Takashi Iwai | 755e137 | 2005-11-11 21:05:27 +0100 | [diff] [blame] | 1411 | spin_unlock_irq(&codec->reg_lock); |
| 1412 | if (codec->revision != ALI_5451_V02) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1413 | return -1; |
Takashi Iwai | 755e137 | 2005-11-11 21:05:27 +0100 | [diff] [blame] | 1414 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1415 | rate = snd_ali_get_spdif_in_rate(codec); |
| 1416 | if (rate == 0) { |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 1417 | snd_printk(KERN_WARNING "ali_capture_preapre: " |
| 1418 | "spdif rate detect err!\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1419 | rate = 48000; |
| 1420 | } |
Takashi Iwai | 755e137 | 2005-11-11 21:05:27 +0100 | [diff] [blame] | 1421 | spin_lock_irq(&codec->reg_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1422 | bValue = inb(ALI_REG(codec,ALI_SPDIF_CTRL)); |
| 1423 | if (bValue & 0x10) { |
| 1424 | outb(bValue,ALI_REG(codec,ALI_SPDIF_CTRL)); |
Takashi Iwai | 99b359b | 2005-10-20 18:26:44 +0200 | [diff] [blame] | 1425 | printk(KERN_WARNING "clear SPDIF parity error flag.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1426 | } |
| 1427 | |
| 1428 | if (rate != 48000) |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 1429 | Delta = ((rate << 12) / runtime->rate) & 0x00ffff; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1430 | } |
| 1431 | |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 1432 | /* set target ESO for channel */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1433 | pvoice->eso = runtime->buffer_size; |
| 1434 | |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 1435 | /* set interrupt count size */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1436 | pvoice->count = runtime->period_size; |
| 1437 | |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 1438 | /* set Loop Back Address */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1439 | LBA = runtime->dma_addr; |
| 1440 | |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 1441 | /* set ESO to capture first MIDLP interrupt */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1442 | ESO = pvoice->eso - 1; |
| 1443 | CTRL = snd_ali_control_mode(substream); |
| 1444 | GVSEL = 0; |
| 1445 | PAN = 0x00; |
| 1446 | VOL = 0x00; |
| 1447 | EC = 0; |
| 1448 | |
| 1449 | snd_ali_write_voice_regs( codec, |
| 1450 | pvoice->number, |
| 1451 | LBA, |
| 1452 | 0, /* cso */ |
| 1453 | ESO, |
| 1454 | Delta, |
| 1455 | 0, /* alpha */ |
| 1456 | GVSEL, |
| 1457 | PAN, |
| 1458 | VOL, |
| 1459 | CTRL, |
| 1460 | EC); |
| 1461 | |
Takashi Iwai | 755e137 | 2005-11-11 21:05:27 +0100 | [diff] [blame] | 1462 | spin_unlock_irq(&codec->reg_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1463 | |
| 1464 | return 0; |
| 1465 | } |
| 1466 | |
| 1467 | |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 1468 | static snd_pcm_uframes_t |
| 1469 | snd_ali_playback_pointer(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1470 | { |
Takashi Iwai | d1fabd9 | 2005-11-17 14:56:03 +0100 | [diff] [blame] | 1471 | struct snd_ali *codec = snd_pcm_substream_chip(substream); |
| 1472 | struct snd_pcm_runtime *runtime = substream->runtime; |
| 1473 | struct snd_ali_voice *pvoice = runtime->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1474 | unsigned int cso; |
| 1475 | |
| 1476 | spin_lock(&codec->reg_lock); |
| 1477 | if (!pvoice->running) { |
| 1478 | spin_unlock(&codec->reg_lock); |
| 1479 | return 0; |
| 1480 | } |
| 1481 | outb(pvoice->number, ALI_REG(codec, ALI_GC_CIR)); |
| 1482 | cso = inw(ALI_REG(codec, ALI_CSO_ALPHA_FMS + 2)); |
| 1483 | spin_unlock(&codec->reg_lock); |
| 1484 | snd_ali_printk("playback pointer returned cso=%xh.\n", cso); |
| 1485 | |
| 1486 | return cso; |
| 1487 | } |
| 1488 | |
| 1489 | |
Takashi Iwai | d1fabd9 | 2005-11-17 14:56:03 +0100 | [diff] [blame] | 1490 | static snd_pcm_uframes_t snd_ali_pointer(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1491 | { |
Takashi Iwai | d1fabd9 | 2005-11-17 14:56:03 +0100 | [diff] [blame] | 1492 | struct snd_ali *codec = snd_pcm_substream_chip(substream); |
| 1493 | struct snd_pcm_runtime *runtime = substream->runtime; |
| 1494 | struct snd_ali_voice *pvoice = runtime->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1495 | unsigned int cso; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1496 | |
Takashi Iwai | 755e137 | 2005-11-11 21:05:27 +0100 | [diff] [blame] | 1497 | spin_lock(&codec->reg_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1498 | if (!pvoice->running) { |
Takashi Iwai | 755e137 | 2005-11-11 21:05:27 +0100 | [diff] [blame] | 1499 | spin_unlock_irq(&codec->reg_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1500 | return 0; |
| 1501 | } |
| 1502 | outb(pvoice->number, ALI_REG(codec, ALI_GC_CIR)); |
| 1503 | cso = inw(ALI_REG(codec, ALI_CSO_ALPHA_FMS + 2)); |
Takashi Iwai | 755e137 | 2005-11-11 21:05:27 +0100 | [diff] [blame] | 1504 | spin_unlock(&codec->reg_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1505 | |
| 1506 | return cso; |
| 1507 | } |
| 1508 | |
Takashi Iwai | d1fabd9 | 2005-11-17 14:56:03 +0100 | [diff] [blame] | 1509 | static struct snd_pcm_hardware snd_ali_playback = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1510 | { |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 1511 | .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED | |
| 1512 | SNDRV_PCM_INFO_BLOCK_TRANSFER | |
| 1513 | SNDRV_PCM_INFO_MMAP_VALID | |
| 1514 | SNDRV_PCM_INFO_RESUME | |
| 1515 | SNDRV_PCM_INFO_SYNC_START), |
| 1516 | .formats = (SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE | |
| 1517 | SNDRV_PCM_FMTBIT_S8 | SNDRV_PCM_FMTBIT_U16_LE), |
| 1518 | .rates = SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1519 | .rate_min = 4000, |
| 1520 | .rate_max = 48000, |
| 1521 | .channels_min = 1, |
| 1522 | .channels_max = 2, |
| 1523 | .buffer_bytes_max = (256*1024), |
| 1524 | .period_bytes_min = 64, |
| 1525 | .period_bytes_max = (256*1024), |
| 1526 | .periods_min = 1, |
| 1527 | .periods_max = 1024, |
| 1528 | .fifo_size = 0, |
| 1529 | }; |
| 1530 | |
| 1531 | /* |
| 1532 | * Capture support device description |
| 1533 | */ |
| 1534 | |
Takashi Iwai | d1fabd9 | 2005-11-17 14:56:03 +0100 | [diff] [blame] | 1535 | static struct snd_pcm_hardware snd_ali_capture = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1536 | { |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 1537 | .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED | |
| 1538 | SNDRV_PCM_INFO_BLOCK_TRANSFER | |
| 1539 | SNDRV_PCM_INFO_MMAP_VALID | |
| 1540 | SNDRV_PCM_INFO_RESUME | |
| 1541 | SNDRV_PCM_INFO_SYNC_START), |
| 1542 | .formats = (SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE | |
| 1543 | SNDRV_PCM_FMTBIT_S8 | SNDRV_PCM_FMTBIT_U16_LE), |
| 1544 | .rates = SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1545 | .rate_min = 4000, |
| 1546 | .rate_max = 48000, |
| 1547 | .channels_min = 1, |
| 1548 | .channels_max = 2, |
| 1549 | .buffer_bytes_max = (128*1024), |
| 1550 | .period_bytes_min = 64, |
| 1551 | .period_bytes_max = (128*1024), |
| 1552 | .periods_min = 1, |
| 1553 | .periods_max = 1024, |
| 1554 | .fifo_size = 0, |
| 1555 | }; |
| 1556 | |
Takashi Iwai | d1fabd9 | 2005-11-17 14:56:03 +0100 | [diff] [blame] | 1557 | static void snd_ali_pcm_free_substream(struct snd_pcm_runtime *runtime) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1558 | { |
Takashi Iwai | d1fabd9 | 2005-11-17 14:56:03 +0100 | [diff] [blame] | 1559 | struct snd_ali_voice *pvoice = runtime->private_data; |
| 1560 | struct snd_ali *codec; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1561 | |
| 1562 | if (pvoice) { |
| 1563 | codec = pvoice->codec; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1564 | snd_ali_free_voice(pvoice->codec, pvoice); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1565 | } |
| 1566 | } |
| 1567 | |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 1568 | static int snd_ali_open(struct snd_pcm_substream *substream, int rec, |
| 1569 | int channel, struct snd_pcm_hardware *phw) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1570 | { |
Takashi Iwai | d1fabd9 | 2005-11-17 14:56:03 +0100 | [diff] [blame] | 1571 | struct snd_ali *codec = snd_pcm_substream_chip(substream); |
| 1572 | struct snd_pcm_runtime *runtime = substream->runtime; |
| 1573 | struct snd_ali_voice *pvoice; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1574 | |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 1575 | pvoice = snd_ali_alloc_voice(codec, SNDRV_ALI_VOICE_TYPE_PCM, rec, |
| 1576 | channel); |
| 1577 | if (!pvoice) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1578 | return -EAGAIN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1579 | |
| 1580 | pvoice->substream = substream; |
| 1581 | runtime->private_data = pvoice; |
| 1582 | runtime->private_free = snd_ali_pcm_free_substream; |
| 1583 | |
Sasha Khapyorsky | 5cbff89 | 2005-05-30 08:09:56 +0200 | [diff] [blame] | 1584 | runtime->hw = *phw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1585 | snd_pcm_set_sync(substream); |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 1586 | snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_BUFFER_SIZE, |
| 1587 | 0, 64*1024); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1588 | return 0; |
| 1589 | } |
| 1590 | |
Takashi Iwai | d1fabd9 | 2005-11-17 14:56:03 +0100 | [diff] [blame] | 1591 | static int snd_ali_playback_open(struct snd_pcm_substream *substream) |
Sasha Khapyorsky | 5cbff89 | 2005-05-30 08:09:56 +0200 | [diff] [blame] | 1592 | { |
| 1593 | return snd_ali_open(substream, 0, -1, &snd_ali_playback); |
| 1594 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1595 | |
Takashi Iwai | d1fabd9 | 2005-11-17 14:56:03 +0100 | [diff] [blame] | 1596 | static int snd_ali_capture_open(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1597 | { |
Sasha Khapyorsky | 5cbff89 | 2005-05-30 08:09:56 +0200 | [diff] [blame] | 1598 | return snd_ali_open(substream, 1, -1, &snd_ali_capture); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1599 | } |
| 1600 | |
Takashi Iwai | d1fabd9 | 2005-11-17 14:56:03 +0100 | [diff] [blame] | 1601 | static int snd_ali_playback_close(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1602 | { |
| 1603 | return 0; |
| 1604 | } |
| 1605 | |
Takashi Iwai | d1fabd9 | 2005-11-17 14:56:03 +0100 | [diff] [blame] | 1606 | static int snd_ali_close(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1607 | { |
Takashi Iwai | d1fabd9 | 2005-11-17 14:56:03 +0100 | [diff] [blame] | 1608 | struct snd_ali *codec = snd_pcm_substream_chip(substream); |
| 1609 | struct snd_ali_voice *pvoice = substream->runtime->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1610 | |
| 1611 | snd_ali_disable_special_channel(codec,pvoice->number); |
| 1612 | |
| 1613 | return 0; |
| 1614 | } |
| 1615 | |
Takashi Iwai | d1fabd9 | 2005-11-17 14:56:03 +0100 | [diff] [blame] | 1616 | static struct snd_pcm_ops snd_ali_playback_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1617 | .open = snd_ali_playback_open, |
| 1618 | .close = snd_ali_playback_close, |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 1619 | .ioctl = snd_pcm_lib_ioctl, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1620 | .hw_params = snd_ali_playback_hw_params, |
| 1621 | .hw_free = snd_ali_playback_hw_free, |
| 1622 | .prepare = snd_ali_playback_prepare, |
| 1623 | .trigger = snd_ali_trigger, |
| 1624 | .pointer = snd_ali_playback_pointer, |
| 1625 | }; |
| 1626 | |
Takashi Iwai | d1fabd9 | 2005-11-17 14:56:03 +0100 | [diff] [blame] | 1627 | static struct snd_pcm_ops snd_ali_capture_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1628 | .open = snd_ali_capture_open, |
Sasha Khapyorsky | 5cbff89 | 2005-05-30 08:09:56 +0200 | [diff] [blame] | 1629 | .close = snd_ali_close, |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 1630 | .ioctl = snd_pcm_lib_ioctl, |
Sasha Khapyorsky | 5cbff89 | 2005-05-30 08:09:56 +0200 | [diff] [blame] | 1631 | .hw_params = snd_ali_hw_params, |
| 1632 | .hw_free = snd_ali_hw_free, |
| 1633 | .prepare = snd_ali_prepare, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1634 | .trigger = snd_ali_trigger, |
Sasha Khapyorsky | 5cbff89 | 2005-05-30 08:09:56 +0200 | [diff] [blame] | 1635 | .pointer = snd_ali_pointer, |
| 1636 | }; |
| 1637 | |
| 1638 | /* |
| 1639 | * Modem PCM |
| 1640 | */ |
| 1641 | |
Takashi Iwai | d1fabd9 | 2005-11-17 14:56:03 +0100 | [diff] [blame] | 1642 | static int snd_ali_modem_hw_params(struct snd_pcm_substream *substream, |
| 1643 | struct snd_pcm_hw_params *hw_params) |
Sasha Khapyorsky | 5cbff89 | 2005-05-30 08:09:56 +0200 | [diff] [blame] | 1644 | { |
Takashi Iwai | d1fabd9 | 2005-11-17 14:56:03 +0100 | [diff] [blame] | 1645 | struct snd_ali *chip = snd_pcm_substream_chip(substream); |
Sasha Khapyorsky | 5cbff89 | 2005-05-30 08:09:56 +0200 | [diff] [blame] | 1646 | unsigned int modem_num = chip->num_of_codecs - 1; |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 1647 | snd_ac97_write(chip->ac97[modem_num], AC97_LINE1_RATE, |
| 1648 | params_rate(hw_params)); |
Sasha Khapyorsky | 5cbff89 | 2005-05-30 08:09:56 +0200 | [diff] [blame] | 1649 | snd_ac97_write(chip->ac97[modem_num], AC97_LINE1_LEVEL, 0); |
| 1650 | return snd_ali_hw_params(substream, hw_params); |
| 1651 | } |
| 1652 | |
Takashi Iwai | d1fabd9 | 2005-11-17 14:56:03 +0100 | [diff] [blame] | 1653 | static struct snd_pcm_hardware snd_ali_modem = |
Sasha Khapyorsky | 5cbff89 | 2005-05-30 08:09:56 +0200 | [diff] [blame] | 1654 | { |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 1655 | .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED | |
| 1656 | SNDRV_PCM_INFO_BLOCK_TRANSFER | |
| 1657 | SNDRV_PCM_INFO_MMAP_VALID | |
| 1658 | SNDRV_PCM_INFO_RESUME | |
| 1659 | SNDRV_PCM_INFO_SYNC_START), |
| 1660 | .formats = SNDRV_PCM_FMTBIT_S16_LE, |
| 1661 | .rates = (SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_8000 | |
| 1662 | SNDRV_PCM_RATE_16000), |
Sasha Khapyorsky | 5cbff89 | 2005-05-30 08:09:56 +0200 | [diff] [blame] | 1663 | .rate_min = 8000, |
| 1664 | .rate_max = 16000, |
| 1665 | .channels_min = 1, |
| 1666 | .channels_max = 1, |
| 1667 | .buffer_bytes_max = (256*1024), |
| 1668 | .period_bytes_min = 64, |
| 1669 | .period_bytes_max = (256*1024), |
| 1670 | .periods_min = 1, |
| 1671 | .periods_max = 1024, |
| 1672 | .fifo_size = 0, |
| 1673 | }; |
| 1674 | |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 1675 | static int snd_ali_modem_open(struct snd_pcm_substream *substream, int rec, |
| 1676 | int channel) |
Sasha Khapyorsky | 5cbff89 | 2005-05-30 08:09:56 +0200 | [diff] [blame] | 1677 | { |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 1678 | static unsigned int rates[] = {8000, 9600, 12000, 16000}; |
Takashi Iwai | d1fabd9 | 2005-11-17 14:56:03 +0100 | [diff] [blame] | 1679 | static struct snd_pcm_hw_constraint_list hw_constraint_rates = { |
Sasha Khapyorsky | 5cbff89 | 2005-05-30 08:09:56 +0200 | [diff] [blame] | 1680 | .count = ARRAY_SIZE(rates), |
| 1681 | .list = rates, |
| 1682 | .mask = 0, |
| 1683 | }; |
| 1684 | int err = snd_ali_open(substream, rec, channel, &snd_ali_modem); |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 1685 | |
Sasha Khapyorsky | 5cbff89 | 2005-05-30 08:09:56 +0200 | [diff] [blame] | 1686 | if (err) |
| 1687 | return err; |
| 1688 | return snd_pcm_hw_constraint_list(substream->runtime, 0, |
| 1689 | SNDRV_PCM_HW_PARAM_RATE, &hw_constraint_rates); |
| 1690 | } |
| 1691 | |
Takashi Iwai | d1fabd9 | 2005-11-17 14:56:03 +0100 | [diff] [blame] | 1692 | static int snd_ali_modem_playback_open(struct snd_pcm_substream *substream) |
Sasha Khapyorsky | 5cbff89 | 2005-05-30 08:09:56 +0200 | [diff] [blame] | 1693 | { |
| 1694 | return snd_ali_modem_open(substream, 0, ALI_MODEM_OUT_CHANNEL); |
| 1695 | } |
| 1696 | |
Takashi Iwai | d1fabd9 | 2005-11-17 14:56:03 +0100 | [diff] [blame] | 1697 | static int snd_ali_modem_capture_open(struct snd_pcm_substream *substream) |
Sasha Khapyorsky | 5cbff89 | 2005-05-30 08:09:56 +0200 | [diff] [blame] | 1698 | { |
| 1699 | return snd_ali_modem_open(substream, 1, ALI_MODEM_IN_CHANNEL); |
| 1700 | } |
| 1701 | |
Takashi Iwai | d1fabd9 | 2005-11-17 14:56:03 +0100 | [diff] [blame] | 1702 | static struct snd_pcm_ops snd_ali_modem_playback_ops = { |
Sasha Khapyorsky | 5cbff89 | 2005-05-30 08:09:56 +0200 | [diff] [blame] | 1703 | .open = snd_ali_modem_playback_open, |
| 1704 | .close = snd_ali_close, |
| 1705 | .ioctl = snd_pcm_lib_ioctl, |
| 1706 | .hw_params = snd_ali_modem_hw_params, |
| 1707 | .hw_free = snd_ali_hw_free, |
| 1708 | .prepare = snd_ali_prepare, |
| 1709 | .trigger = snd_ali_trigger, |
| 1710 | .pointer = snd_ali_pointer, |
| 1711 | }; |
| 1712 | |
Takashi Iwai | d1fabd9 | 2005-11-17 14:56:03 +0100 | [diff] [blame] | 1713 | static struct snd_pcm_ops snd_ali_modem_capture_ops = { |
Sasha Khapyorsky | 5cbff89 | 2005-05-30 08:09:56 +0200 | [diff] [blame] | 1714 | .open = snd_ali_modem_capture_open, |
| 1715 | .close = snd_ali_close, |
| 1716 | .ioctl = snd_pcm_lib_ioctl, |
| 1717 | .hw_params = snd_ali_modem_hw_params, |
| 1718 | .hw_free = snd_ali_hw_free, |
| 1719 | .prepare = snd_ali_prepare, |
| 1720 | .trigger = snd_ali_trigger, |
| 1721 | .pointer = snd_ali_pointer, |
| 1722 | }; |
| 1723 | |
| 1724 | |
| 1725 | struct ali_pcm_description { |
| 1726 | char *name; |
| 1727 | unsigned int playback_num; |
| 1728 | unsigned int capture_num; |
Takashi Iwai | d1fabd9 | 2005-11-17 14:56:03 +0100 | [diff] [blame] | 1729 | struct snd_pcm_ops *playback_ops; |
| 1730 | struct snd_pcm_ops *capture_ops; |
Sasha Khapyorsky | 6632d19 | 2005-09-29 11:48:17 +0200 | [diff] [blame] | 1731 | unsigned short class; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1732 | }; |
| 1733 | |
| 1734 | |
Takashi Iwai | d1fabd9 | 2005-11-17 14:56:03 +0100 | [diff] [blame] | 1735 | static void snd_ali_pcm_free(struct snd_pcm *pcm) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1736 | { |
Takashi Iwai | d1fabd9 | 2005-11-17 14:56:03 +0100 | [diff] [blame] | 1737 | struct snd_ali *codec = pcm->private_data; |
Sasha Khapyorsky | 5cbff89 | 2005-05-30 08:09:56 +0200 | [diff] [blame] | 1738 | codec->pcm[pcm->device] = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1739 | } |
| 1740 | |
Sasha Khapyorsky | 5cbff89 | 2005-05-30 08:09:56 +0200 | [diff] [blame] | 1741 | |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 1742 | static int __devinit snd_ali_pcm(struct snd_ali * codec, int device, |
| 1743 | struct ali_pcm_description *desc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1744 | { |
Takashi Iwai | d1fabd9 | 2005-11-17 14:56:03 +0100 | [diff] [blame] | 1745 | struct snd_pcm *pcm; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1746 | int err; |
| 1747 | |
Sasha Khapyorsky | 5cbff89 | 2005-05-30 08:09:56 +0200 | [diff] [blame] | 1748 | err = snd_pcm_new(codec->card, desc->name, device, |
| 1749 | desc->playback_num, desc->capture_num, &pcm); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1750 | if (err < 0) { |
Takashi Iwai | 99b359b | 2005-10-20 18:26:44 +0200 | [diff] [blame] | 1751 | snd_printk(KERN_ERR "snd_ali_pcm: err called snd_pcm_new.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1752 | return err; |
| 1753 | } |
| 1754 | pcm->private_data = codec; |
| 1755 | pcm->private_free = snd_ali_pcm_free; |
Sasha Khapyorsky | 5cbff89 | 2005-05-30 08:09:56 +0200 | [diff] [blame] | 1756 | if (desc->playback_ops) |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 1757 | snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, |
| 1758 | desc->playback_ops); |
Sasha Khapyorsky | 5cbff89 | 2005-05-30 08:09:56 +0200 | [diff] [blame] | 1759 | if (desc->capture_ops) |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 1760 | snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, |
| 1761 | desc->capture_ops); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1762 | |
| 1763 | snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV, |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 1764 | snd_dma_pci_data(codec->pci), |
| 1765 | 64*1024, 128*1024); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1766 | |
| 1767 | pcm->info_flags = 0; |
Sasha Khapyorsky | 6632d19 | 2005-09-29 11:48:17 +0200 | [diff] [blame] | 1768 | pcm->dev_class = desc->class; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1769 | pcm->dev_subclass = SNDRV_PCM_SUBCLASS_GENERIC_MIX; |
Sasha Khapyorsky | 5cbff89 | 2005-05-30 08:09:56 +0200 | [diff] [blame] | 1770 | strcpy(pcm->name, desc->name); |
| 1771 | codec->pcm[0] = pcm; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1772 | return 0; |
| 1773 | } |
| 1774 | |
Clemens Ladisch | a53fc18 | 2005-08-11 15:59:17 +0200 | [diff] [blame] | 1775 | static struct ali_pcm_description ali_pcms[] = { |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 1776 | { .name = "ALI 5451", |
| 1777 | .playback_num = ALI_CHANNELS, |
| 1778 | .capture_num = 1, |
| 1779 | .playback_ops = &snd_ali_playback_ops, |
| 1780 | .capture_ops = &snd_ali_capture_ops |
| 1781 | }, |
| 1782 | { .name = "ALI 5451 modem", |
| 1783 | .playback_num = 1, |
| 1784 | .capture_num = 1, |
| 1785 | .playback_ops = &snd_ali_modem_playback_ops, |
| 1786 | .capture_ops = &snd_ali_modem_capture_ops, |
| 1787 | .class = SNDRV_PCM_CLASS_MODEM |
| 1788 | } |
Sasha Khapyorsky | 5cbff89 | 2005-05-30 08:09:56 +0200 | [diff] [blame] | 1789 | }; |
| 1790 | |
Takashi Iwai | d1fabd9 | 2005-11-17 14:56:03 +0100 | [diff] [blame] | 1791 | static int __devinit snd_ali_build_pcms(struct snd_ali *codec) |
Sasha Khapyorsky | 5cbff89 | 2005-05-30 08:09:56 +0200 | [diff] [blame] | 1792 | { |
| 1793 | int i, err; |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 1794 | for (i = 0; i < codec->num_of_codecs && i < ARRAY_SIZE(ali_pcms); i++) { |
| 1795 | err = snd_ali_pcm(codec, i, &ali_pcms[i]); |
| 1796 | if (err < 0) |
Sasha Khapyorsky | 5cbff89 | 2005-05-30 08:09:56 +0200 | [diff] [blame] | 1797 | return err; |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 1798 | } |
Sasha Khapyorsky | 5cbff89 | 2005-05-30 08:09:56 +0200 | [diff] [blame] | 1799 | return 0; |
| 1800 | } |
| 1801 | |
| 1802 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1803 | #define ALI5451_SPDIF(xname, xindex, value) \ |
| 1804 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex,\ |
| 1805 | .info = snd_ali5451_spdif_info, .get = snd_ali5451_spdif_get, \ |
| 1806 | .put = snd_ali5451_spdif_put, .private_value = value} |
| 1807 | |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 1808 | static int snd_ali5451_spdif_info(struct snd_kcontrol *kcontrol, |
| 1809 | struct snd_ctl_elem_info *uinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1810 | { |
| 1811 | uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; |
| 1812 | uinfo->count = 1; |
| 1813 | uinfo->value.integer.min = 0; |
| 1814 | uinfo->value.integer.max = 1; |
| 1815 | return 0; |
| 1816 | } |
| 1817 | |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 1818 | static int snd_ali5451_spdif_get(struct snd_kcontrol *kcontrol, |
| 1819 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1820 | { |
Takashi Iwai | d1fabd9 | 2005-11-17 14:56:03 +0100 | [diff] [blame] | 1821 | struct snd_ali *codec = kcontrol->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1822 | unsigned int enable; |
| 1823 | |
| 1824 | enable = ucontrol->value.integer.value[0] ? 1 : 0; |
| 1825 | |
Takashi Iwai | 755e137 | 2005-11-11 21:05:27 +0100 | [diff] [blame] | 1826 | spin_lock_irq(&codec->reg_lock); |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 1827 | switch (kcontrol->private_value) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1828 | case 0: |
| 1829 | enable = (codec->spdif_mask & 0x02) ? 1 : 0; |
| 1830 | break; |
| 1831 | case 1: |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 1832 | enable = ((codec->spdif_mask & 0x02) && |
| 1833 | (codec->spdif_mask & 0x04)) ? 1 : 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1834 | break; |
| 1835 | case 2: |
| 1836 | enable = (codec->spdif_mask & 0x01) ? 1 : 0; |
| 1837 | break; |
| 1838 | default: |
| 1839 | break; |
| 1840 | } |
| 1841 | ucontrol->value.integer.value[0] = enable; |
Takashi Iwai | 755e137 | 2005-11-11 21:05:27 +0100 | [diff] [blame] | 1842 | spin_unlock_irq(&codec->reg_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1843 | return 0; |
| 1844 | } |
| 1845 | |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 1846 | static int snd_ali5451_spdif_put(struct snd_kcontrol *kcontrol, |
| 1847 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1848 | { |
Takashi Iwai | d1fabd9 | 2005-11-17 14:56:03 +0100 | [diff] [blame] | 1849 | struct snd_ali *codec = kcontrol->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1850 | unsigned int change = 0, enable = 0; |
| 1851 | |
| 1852 | enable = ucontrol->value.integer.value[0] ? 1 : 0; |
| 1853 | |
Takashi Iwai | 755e137 | 2005-11-11 21:05:27 +0100 | [diff] [blame] | 1854 | spin_lock_irq(&codec->reg_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1855 | switch (kcontrol->private_value) { |
| 1856 | case 0: |
| 1857 | change = (codec->spdif_mask & 0x02) ? 1 : 0; |
| 1858 | change = change ^ enable; |
| 1859 | if (change) { |
| 1860 | if (enable) { |
| 1861 | codec->spdif_mask |= 0x02; |
| 1862 | snd_ali_enable_spdif_out(codec); |
| 1863 | } else { |
| 1864 | codec->spdif_mask &= ~(0x02); |
| 1865 | codec->spdif_mask &= ~(0x04); |
| 1866 | snd_ali_disable_spdif_out(codec); |
| 1867 | } |
| 1868 | } |
| 1869 | break; |
| 1870 | case 1: |
| 1871 | change = (codec->spdif_mask & 0x04) ? 1 : 0; |
| 1872 | change = change ^ enable; |
| 1873 | if (change && (codec->spdif_mask & 0x02)) { |
| 1874 | if (enable) { |
| 1875 | codec->spdif_mask |= 0x04; |
| 1876 | snd_ali_enable_spdif_chnout(codec); |
| 1877 | } else { |
| 1878 | codec->spdif_mask &= ~(0x04); |
| 1879 | snd_ali_disable_spdif_chnout(codec); |
| 1880 | } |
| 1881 | } |
| 1882 | break; |
| 1883 | case 2: |
| 1884 | change = (codec->spdif_mask & 0x01) ? 1 : 0; |
| 1885 | change = change ^ enable; |
| 1886 | if (change) { |
| 1887 | if (enable) { |
| 1888 | codec->spdif_mask |= 0x01; |
| 1889 | snd_ali_enable_spdif_in(codec); |
| 1890 | } else { |
| 1891 | codec->spdif_mask &= ~(0x01); |
| 1892 | snd_ali_disable_spdif_in(codec); |
| 1893 | } |
| 1894 | } |
| 1895 | break; |
| 1896 | default: |
| 1897 | break; |
| 1898 | } |
Takashi Iwai | 755e137 | 2005-11-11 21:05:27 +0100 | [diff] [blame] | 1899 | spin_unlock_irq(&codec->reg_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1900 | |
| 1901 | return change; |
| 1902 | } |
| 1903 | |
Takashi Iwai | d1fabd9 | 2005-11-17 14:56:03 +0100 | [diff] [blame] | 1904 | static struct snd_kcontrol_new snd_ali5451_mixer_spdif[] __devinitdata = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1905 | /* spdif aplayback switch */ |
| 1906 | /* FIXME: "IEC958 Playback Switch" may conflict with one on ac97_codec */ |
Clemens Ladisch | 10e8d78 | 2005-08-03 13:40:08 +0200 | [diff] [blame] | 1907 | ALI5451_SPDIF(SNDRV_CTL_NAME_IEC958("Output ",NONE,SWITCH), 0, 0), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1908 | /* spdif out to spdif channel */ |
Clemens Ladisch | 10e8d78 | 2005-08-03 13:40:08 +0200 | [diff] [blame] | 1909 | ALI5451_SPDIF(SNDRV_CTL_NAME_IEC958("Channel Output ",NONE,SWITCH), 0, 1), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1910 | /* spdif in from spdif channel */ |
| 1911 | ALI5451_SPDIF(SNDRV_CTL_NAME_IEC958("",CAPTURE,SWITCH), 0, 2) |
| 1912 | }; |
| 1913 | |
Takashi Iwai | d1fabd9 | 2005-11-17 14:56:03 +0100 | [diff] [blame] | 1914 | static int __devinit snd_ali_mixer(struct snd_ali * codec) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1915 | { |
Takashi Iwai | d1fabd9 | 2005-11-17 14:56:03 +0100 | [diff] [blame] | 1916 | struct snd_ac97_template ac97; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1917 | unsigned int idx; |
Sasha Khapyorsky | 5cbff89 | 2005-05-30 08:09:56 +0200 | [diff] [blame] | 1918 | int i, err; |
Takashi Iwai | d1fabd9 | 2005-11-17 14:56:03 +0100 | [diff] [blame] | 1919 | static struct snd_ac97_bus_ops ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1920 | .write = snd_ali_codec_write, |
| 1921 | .read = snd_ali_codec_read, |
| 1922 | }; |
| 1923 | |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 1924 | err = snd_ac97_bus(codec->card, 0, &ops, codec, &codec->ac97_bus); |
| 1925 | if (err < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1926 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1927 | |
| 1928 | memset(&ac97, 0, sizeof(ac97)); |
| 1929 | ac97.private_data = codec; |
Sasha Khapyorsky | 5cbff89 | 2005-05-30 08:09:56 +0200 | [diff] [blame] | 1930 | |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 1931 | for (i = 0; i < codec->num_of_codecs; i++) { |
Sasha Khapyorsky | 5cbff89 | 2005-05-30 08:09:56 +0200 | [diff] [blame] | 1932 | ac97.num = i; |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 1933 | err = snd_ac97_mixer(codec->ac97_bus, &ac97, &codec->ac97[i]); |
| 1934 | if (err < 0) { |
| 1935 | snd_printk(KERN_ERR |
| 1936 | "ali mixer %d creating error.\n", i); |
| 1937 | if (i == 0) |
Takashi Iwai | 4d060fd | 2005-10-04 13:50:44 +0200 | [diff] [blame] | 1938 | return err; |
| 1939 | codec->num_of_codecs = 1; |
| 1940 | break; |
| 1941 | } |
Sasha Khapyorsky | 5cbff89 | 2005-05-30 08:09:56 +0200 | [diff] [blame] | 1942 | } |
| 1943 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1944 | if (codec->spdif_support) { |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 1945 | for (idx = 0; idx < ARRAY_SIZE(snd_ali5451_mixer_spdif); idx++) { |
| 1946 | err = snd_ctl_add(codec->card, |
| 1947 | snd_ctl_new1(&snd_ali5451_mixer_spdif[idx], codec)); |
| 1948 | if (err < 0) |
| 1949 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1950 | } |
| 1951 | } |
| 1952 | return 0; |
| 1953 | } |
| 1954 | |
| 1955 | #ifdef CONFIG_PM |
Takashi Iwai | bf53c3b | 2005-11-17 16:10:51 +0100 | [diff] [blame] | 1956 | static int ali_suspend(struct pci_dev *pci, pm_message_t state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1957 | { |
Takashi Iwai | bf53c3b | 2005-11-17 16:10:51 +0100 | [diff] [blame] | 1958 | struct snd_card *card = pci_get_drvdata(pci); |
| 1959 | struct snd_ali *chip = card->private_data; |
Takashi Iwai | d1fabd9 | 2005-11-17 14:56:03 +0100 | [diff] [blame] | 1960 | struct snd_ali_image *im; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1961 | int i, j; |
| 1962 | |
| 1963 | im = chip->image; |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 1964 | if (!im) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1965 | return 0; |
| 1966 | |
Takashi Iwai | bf53c3b | 2005-11-17 16:10:51 +0100 | [diff] [blame] | 1967 | snd_power_change_state(card, SNDRV_CTL_POWER_D3hot); |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 1968 | for (i = 0; i < chip->num_of_codecs; i++) { |
Takashi Iwai | bf53c3b | 2005-11-17 16:10:51 +0100 | [diff] [blame] | 1969 | snd_pcm_suspend_all(chip->pcm[i]); |
| 1970 | snd_ac97_suspend(chip->ac97[i]); |
Sasha Khapyorsky | 5cbff89 | 2005-05-30 08:09:56 +0200 | [diff] [blame] | 1971 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1972 | |
| 1973 | spin_lock_irq(&chip->reg_lock); |
| 1974 | |
| 1975 | im->regs[ALI_MISCINT >> 2] = inl(ALI_REG(chip, ALI_MISCINT)); |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 1976 | /* im->regs[ALI_START >> 2] = inl(ALI_REG(chip, ALI_START)); */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1977 | im->regs[ALI_STOP >> 2] = inl(ALI_REG(chip, ALI_STOP)); |
| 1978 | |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 1979 | /* disable all IRQ bits */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1980 | outl(0, ALI_REG(chip, ALI_MISCINT)); |
| 1981 | |
| 1982 | for (i = 0; i < ALI_GLOBAL_REGS; i++) { |
| 1983 | if ((i*4 == ALI_MISCINT) || (i*4 == ALI_STOP)) |
| 1984 | continue; |
| 1985 | im->regs[i] = inl(ALI_REG(chip, i*4)); |
| 1986 | } |
| 1987 | |
| 1988 | for (i = 0; i < ALI_CHANNELS; i++) { |
| 1989 | outb(i, ALI_REG(chip, ALI_GC_CIR)); |
| 1990 | for (j = 0; j < ALI_CHANNEL_REGS; j++) |
| 1991 | im->channel_regs[i][j] = inl(ALI_REG(chip, j*4 + 0xe0)); |
| 1992 | } |
| 1993 | |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 1994 | /* stop all HW channel */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1995 | outl(0xffffffff, ALI_REG(chip, ALI_STOP)); |
| 1996 | |
| 1997 | spin_unlock_irq(&chip->reg_lock); |
Takashi Iwai | 30b3539 | 2006-10-11 18:52:53 +0200 | [diff] [blame] | 1998 | |
Takashi Iwai | bf53c3b | 2005-11-17 16:10:51 +0100 | [diff] [blame] | 1999 | pci_disable_device(pci); |
| 2000 | pci_save_state(pci); |
Takashi Iwai | 30b3539 | 2006-10-11 18:52:53 +0200 | [diff] [blame] | 2001 | pci_set_power_state(pci, pci_choose_state(pci, state)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2002 | return 0; |
| 2003 | } |
| 2004 | |
Takashi Iwai | bf53c3b | 2005-11-17 16:10:51 +0100 | [diff] [blame] | 2005 | static int ali_resume(struct pci_dev *pci) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2006 | { |
Takashi Iwai | bf53c3b | 2005-11-17 16:10:51 +0100 | [diff] [blame] | 2007 | struct snd_card *card = pci_get_drvdata(pci); |
| 2008 | struct snd_ali *chip = card->private_data; |
Takashi Iwai | d1fabd9 | 2005-11-17 14:56:03 +0100 | [diff] [blame] | 2009 | struct snd_ali_image *im; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2010 | int i, j; |
| 2011 | |
| 2012 | im = chip->image; |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 2013 | if (!im) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2014 | return 0; |
| 2015 | |
Takashi Iwai | 30b3539 | 2006-10-11 18:52:53 +0200 | [diff] [blame] | 2016 | pci_set_power_state(pci, PCI_D0); |
Takashi Iwai | bf53c3b | 2005-11-17 16:10:51 +0100 | [diff] [blame] | 2017 | pci_restore_state(pci); |
Takashi Iwai | 30b3539 | 2006-10-11 18:52:53 +0200 | [diff] [blame] | 2018 | if (pci_enable_device(pci) < 0) { |
| 2019 | printk(KERN_ERR "ali5451: pci_enable_device failed, " |
| 2020 | "disabling device\n"); |
| 2021 | snd_card_disconnect(card); |
| 2022 | return -EIO; |
| 2023 | } |
| 2024 | pci_set_master(pci); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2025 | |
| 2026 | spin_lock_irq(&chip->reg_lock); |
| 2027 | |
| 2028 | for (i = 0; i < ALI_CHANNELS; i++) { |
| 2029 | outb(i, ALI_REG(chip, ALI_GC_CIR)); |
| 2030 | for (j = 0; j < ALI_CHANNEL_REGS; j++) |
| 2031 | outl(im->channel_regs[i][j], ALI_REG(chip, j*4 + 0xe0)); |
| 2032 | } |
| 2033 | |
| 2034 | for (i = 0; i < ALI_GLOBAL_REGS; i++) { |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 2035 | if ((i*4 == ALI_MISCINT) || (i*4 == ALI_STOP) || |
| 2036 | (i*4 == ALI_START)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2037 | continue; |
| 2038 | outl(im->regs[i], ALI_REG(chip, i*4)); |
| 2039 | } |
| 2040 | |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 2041 | /* start HW channel */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2042 | outl(im->regs[ALI_START >> 2], ALI_REG(chip, ALI_START)); |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 2043 | /* restore IRQ enable bits */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2044 | outl(im->regs[ALI_MISCINT >> 2], ALI_REG(chip, ALI_MISCINT)); |
| 2045 | |
| 2046 | spin_unlock_irq(&chip->reg_lock); |
| 2047 | |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 2048 | for (i = 0 ; i < chip->num_of_codecs; i++) |
Takashi Iwai | bf53c3b | 2005-11-17 16:10:51 +0100 | [diff] [blame] | 2049 | snd_ac97_resume(chip->ac97[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2050 | |
Takashi Iwai | bf53c3b | 2005-11-17 16:10:51 +0100 | [diff] [blame] | 2051 | snd_power_change_state(card, SNDRV_CTL_POWER_D0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2052 | return 0; |
| 2053 | } |
| 2054 | #endif /* CONFIG_PM */ |
| 2055 | |
Takashi Iwai | d1fabd9 | 2005-11-17 14:56:03 +0100 | [diff] [blame] | 2056 | static int snd_ali_free(struct snd_ali * codec) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2057 | { |
| 2058 | if (codec->hw_initialized) |
| 2059 | snd_ali_disable_address_interrupt(codec); |
| 2060 | if (codec->irq >= 0) { |
| 2061 | synchronize_irq(codec->irq); |
Takashi Iwai | 437a5a4 | 2006-11-21 12:14:23 +0100 | [diff] [blame] | 2062 | free_irq(codec->irq, codec); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2063 | } |
| 2064 | if (codec->port) |
| 2065 | pci_release_regions(codec->pci); |
| 2066 | pci_disable_device(codec->pci); |
| 2067 | #ifdef CONFIG_PM |
| 2068 | kfree(codec->image); |
| 2069 | #endif |
Jiri Slaby | 0dd119f | 2005-09-07 14:28:33 +0200 | [diff] [blame] | 2070 | pci_dev_put(codec->pci_m1533); |
| 2071 | pci_dev_put(codec->pci_m7101); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2072 | kfree(codec); |
| 2073 | return 0; |
| 2074 | } |
| 2075 | |
Takashi Iwai | d1fabd9 | 2005-11-17 14:56:03 +0100 | [diff] [blame] | 2076 | static int snd_ali_chip_init(struct snd_ali *codec) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2077 | { |
| 2078 | unsigned int legacy; |
| 2079 | unsigned char temp; |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 2080 | struct pci_dev *pci_dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2081 | |
| 2082 | snd_ali_printk("chip initializing ... \n"); |
| 2083 | |
| 2084 | if (snd_ali_reset_5451(codec)) { |
Takashi Iwai | 99b359b | 2005-10-20 18:26:44 +0200 | [diff] [blame] | 2085 | snd_printk(KERN_ERR "ali_chip_init: reset 5451 error.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2086 | return -1; |
| 2087 | } |
| 2088 | |
| 2089 | if (codec->revision == ALI_5451_V02) { |
| 2090 | pci_dev = codec->pci_m1533; |
| 2091 | pci_read_config_byte(pci_dev, 0x59, &temp); |
| 2092 | temp |= 0x80; |
| 2093 | pci_write_config_byte(pci_dev, 0x59, temp); |
| 2094 | |
| 2095 | pci_dev = codec->pci_m7101; |
| 2096 | pci_read_config_byte(pci_dev, 0xb8, &temp); |
| 2097 | temp |= 0x20; |
| 2098 | pci_write_config_byte(pci_dev, 0xB8, temp); |
| 2099 | } |
| 2100 | |
| 2101 | pci_read_config_dword(codec->pci, 0x44, &legacy); |
| 2102 | legacy &= 0xff00ff00; |
| 2103 | legacy |= 0x000800aa; |
| 2104 | pci_write_config_dword(codec->pci, 0x44, legacy); |
| 2105 | |
| 2106 | outl(0x80000001, ALI_REG(codec, ALI_GLOBAL_CONTROL)); |
| 2107 | outl(0x00000000, ALI_REG(codec, ALI_AINTEN)); |
| 2108 | outl(0xffffffff, ALI_REG(codec, ALI_AINT)); |
| 2109 | outl(0x00000000, ALI_REG(codec, ALI_VOLUME)); |
| 2110 | outb(0x10, ALI_REG(codec, ALI_MPUR2)); |
| 2111 | |
| 2112 | codec->ac97_ext_id = snd_ali_codec_peek(codec, 0, AC97_EXTENDED_ID); |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 2113 | codec->ac97_ext_status = snd_ali_codec_peek(codec, 0, |
| 2114 | AC97_EXTENDED_STATUS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2115 | if (codec->spdif_support) { |
| 2116 | snd_ali_enable_spdif_out(codec); |
| 2117 | codec->spdif_mask = 0x00000002; |
| 2118 | } |
| 2119 | |
Sasha Khapyorsky | 5cbff89 | 2005-05-30 08:09:56 +0200 | [diff] [blame] | 2120 | codec->num_of_codecs = 1; |
| 2121 | |
| 2122 | /* secondary codec - modem */ |
| 2123 | if (inl(ALI_REG(codec, ALI_SCTRL)) & ALI_SCTRL_CODEC2_READY) { |
| 2124 | codec->num_of_codecs++; |
| 2125 | outl(inl(ALI_REG(codec, ALI_SCTRL)) | |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 2126 | (ALI_SCTRL_LINE_IN2 | ALI_SCTRL_GPIO_IN2 | |
| 2127 | ALI_SCTRL_LINE_OUT_EN), |
| 2128 | ALI_REG(codec, ALI_SCTRL)); |
Sasha Khapyorsky | 5cbff89 | 2005-05-30 08:09:56 +0200 | [diff] [blame] | 2129 | } |
| 2130 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2131 | snd_ali_printk("chip initialize succeed.\n"); |
| 2132 | return 0; |
| 2133 | |
| 2134 | } |
| 2135 | |
Sasha Khapyorsky | 5cbff89 | 2005-05-30 08:09:56 +0200 | [diff] [blame] | 2136 | /* proc for register dump */ |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 2137 | static void snd_ali_proc_read(struct snd_info_entry *entry, |
| 2138 | struct snd_info_buffer *buf) |
Sasha Khapyorsky | 5cbff89 | 2005-05-30 08:09:56 +0200 | [diff] [blame] | 2139 | { |
Takashi Iwai | d1fabd9 | 2005-11-17 14:56:03 +0100 | [diff] [blame] | 2140 | struct snd_ali *codec = entry->private_data; |
Sasha Khapyorsky | 5cbff89 | 2005-05-30 08:09:56 +0200 | [diff] [blame] | 2141 | int i; |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 2142 | for (i = 0; i < 256 ; i+= 4) |
Sasha Khapyorsky | 5cbff89 | 2005-05-30 08:09:56 +0200 | [diff] [blame] | 2143 | snd_iprintf(buf, "%02x: %08x\n", i, inl(ALI_REG(codec, i))); |
| 2144 | } |
| 2145 | |
Takashi Iwai | d1fabd9 | 2005-11-17 14:56:03 +0100 | [diff] [blame] | 2146 | static void __devinit snd_ali_proc_init(struct snd_ali *codec) |
Sasha Khapyorsky | 5cbff89 | 2005-05-30 08:09:56 +0200 | [diff] [blame] | 2147 | { |
Takashi Iwai | d1fabd9 | 2005-11-17 14:56:03 +0100 | [diff] [blame] | 2148 | struct snd_info_entry *entry; |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 2149 | if (!snd_card_proc_new(codec->card, "ali5451", &entry)) |
Takashi Iwai | bf85020 | 2006-04-28 15:13:41 +0200 | [diff] [blame] | 2150 | snd_info_set_text_ops(entry, codec, snd_ali_proc_read); |
Sasha Khapyorsky | 5cbff89 | 2005-05-30 08:09:56 +0200 | [diff] [blame] | 2151 | } |
| 2152 | |
Takashi Iwai | d1fabd9 | 2005-11-17 14:56:03 +0100 | [diff] [blame] | 2153 | static int __devinit snd_ali_resources(struct snd_ali *codec) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2154 | { |
| 2155 | int err; |
| 2156 | |
| 2157 | snd_ali_printk("resouces allocation ...\n"); |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 2158 | err = pci_request_regions(codec->pci, "ALI 5451"); |
| 2159 | if (err < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2160 | return err; |
| 2161 | codec->port = pci_resource_start(codec->pci, 0); |
| 2162 | |
Takashi Iwai | 437a5a4 | 2006-11-21 12:14:23 +0100 | [diff] [blame] | 2163 | if (request_irq(codec->pci->irq, snd_ali_card_interrupt, |
| 2164 | IRQF_SHARED, "ALI 5451", codec)) { |
Takashi Iwai | 99b359b | 2005-10-20 18:26:44 +0200 | [diff] [blame] | 2165 | snd_printk(KERN_ERR "Unable to request irq.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2166 | return -EBUSY; |
| 2167 | } |
| 2168 | codec->irq = codec->pci->irq; |
| 2169 | snd_ali_printk("resouces allocated.\n"); |
| 2170 | return 0; |
| 2171 | } |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 2172 | static int snd_ali_dev_free(struct snd_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2173 | { |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 2174 | struct snd_ali *codec = device->device_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2175 | snd_ali_free(codec); |
| 2176 | return 0; |
| 2177 | } |
| 2178 | |
Takashi Iwai | d1fabd9 | 2005-11-17 14:56:03 +0100 | [diff] [blame] | 2179 | static int __devinit snd_ali_create(struct snd_card *card, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2180 | struct pci_dev *pci, |
| 2181 | int pcm_streams, |
| 2182 | int spdif_support, |
Takashi Iwai | d1fabd9 | 2005-11-17 14:56:03 +0100 | [diff] [blame] | 2183 | struct snd_ali ** r_ali) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2184 | { |
Takashi Iwai | d1fabd9 | 2005-11-17 14:56:03 +0100 | [diff] [blame] | 2185 | struct snd_ali *codec; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2186 | int i, err; |
Takashi Iwai | bf53c3b | 2005-11-17 16:10:51 +0100 | [diff] [blame] | 2187 | unsigned short cmdw; |
| 2188 | static struct snd_device_ops ops = { |
Takashi Iwai | d1fabd9 | 2005-11-17 14:56:03 +0100 | [diff] [blame] | 2189 | .dev_free = snd_ali_dev_free, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2190 | }; |
| 2191 | |
| 2192 | *r_ali = NULL; |
| 2193 | |
| 2194 | snd_ali_printk("creating ...\n"); |
| 2195 | |
| 2196 | /* enable PCI device */ |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 2197 | err = pci_enable_device(pci); |
| 2198 | if (err < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2199 | return err; |
| 2200 | /* check, if we can restrict PCI DMA transfers to 31 bits */ |
Matthias Gehre | 910638a | 2006-03-28 01:56:48 -0800 | [diff] [blame] | 2201 | if (pci_set_dma_mask(pci, DMA_31BIT_MASK) < 0 || |
| 2202 | pci_set_consistent_dma_mask(pci, DMA_31BIT_MASK) < 0) { |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 2203 | snd_printk(KERN_ERR "architecture does not support " |
| 2204 | "31bit PCI busmaster DMA\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2205 | pci_disable_device(pci); |
| 2206 | return -ENXIO; |
| 2207 | } |
| 2208 | |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 2209 | codec = kzalloc(sizeof(*codec), GFP_KERNEL); |
| 2210 | if (!codec) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2211 | pci_disable_device(pci); |
| 2212 | return -ENOMEM; |
| 2213 | } |
| 2214 | |
| 2215 | spin_lock_init(&codec->reg_lock); |
| 2216 | spin_lock_init(&codec->voice_alloc); |
| 2217 | |
| 2218 | codec->card = card; |
| 2219 | codec->pci = pci; |
| 2220 | codec->irq = -1; |
| 2221 | pci_read_config_byte(pci, PCI_REVISION_ID, &codec->revision); |
| 2222 | codec->spdif_support = spdif_support; |
| 2223 | |
| 2224 | if (pcm_streams < 1) |
| 2225 | pcm_streams = 1; |
| 2226 | if (pcm_streams > 32) |
| 2227 | pcm_streams = 32; |
| 2228 | |
| 2229 | pci_set_master(pci); |
| 2230 | pci_read_config_word(pci, PCI_COMMAND, &cmdw); |
| 2231 | if ((cmdw & PCI_COMMAND_IO) != PCI_COMMAND_IO) { |
| 2232 | cmdw |= PCI_COMMAND_IO; |
| 2233 | pci_write_config_word(pci, PCI_COMMAND, cmdw); |
| 2234 | } |
| 2235 | pci_set_master(pci); |
| 2236 | |
| 2237 | if (snd_ali_resources(codec)) { |
| 2238 | snd_ali_free(codec); |
| 2239 | return -EBUSY; |
| 2240 | } |
| 2241 | |
| 2242 | synchronize_irq(pci->irq); |
| 2243 | |
| 2244 | codec->synth.chmap = 0; |
| 2245 | codec->synth.chcnt = 0; |
| 2246 | codec->spdif_mask = 0; |
| 2247 | codec->synth.synthcount = 0; |
| 2248 | |
| 2249 | if (codec->revision == ALI_5451_V02) |
| 2250 | codec->chregs.regs.ac97read = ALI_AC97_WRITE; |
| 2251 | else |
| 2252 | codec->chregs.regs.ac97read = ALI_AC97_READ; |
| 2253 | codec->chregs.regs.ac97write = ALI_AC97_WRITE; |
| 2254 | |
| 2255 | codec->chregs.regs.start = ALI_START; |
| 2256 | codec->chregs.regs.stop = ALI_STOP; |
| 2257 | codec->chregs.regs.aint = ALI_AINT; |
| 2258 | codec->chregs.regs.ainten = ALI_AINTEN; |
| 2259 | |
| 2260 | codec->chregs.data.start = 0x00; |
| 2261 | codec->chregs.data.stop = 0x00; |
| 2262 | codec->chregs.data.aint = 0x00; |
| 2263 | codec->chregs.data.ainten = 0x00; |
| 2264 | |
| 2265 | /* M1533: southbridge */ |
Takashi Iwai | bf53c3b | 2005-11-17 16:10:51 +0100 | [diff] [blame] | 2266 | codec->pci_m1533 = pci_get_device(0x10b9, 0x1533, NULL); |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 2267 | if (!codec->pci_m1533) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2268 | snd_printk(KERN_ERR "ali5451: cannot find ALi 1533 chip.\n"); |
| 2269 | snd_ali_free(codec); |
| 2270 | return -ENODEV; |
| 2271 | } |
| 2272 | /* M7101: power management */ |
Takashi Iwai | bf53c3b | 2005-11-17 16:10:51 +0100 | [diff] [blame] | 2273 | codec->pci_m7101 = pci_get_device(0x10b9, 0x7101, NULL); |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 2274 | if (!codec->pci_m7101 && codec->revision == ALI_5451_V02) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2275 | snd_printk(KERN_ERR "ali5451: cannot find ALi 7101 chip.\n"); |
| 2276 | snd_ali_free(codec); |
| 2277 | return -ENODEV; |
| 2278 | } |
| 2279 | |
| 2280 | snd_ali_printk("snd_device_new is called.\n"); |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 2281 | err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, codec, &ops); |
| 2282 | if (err < 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2283 | snd_ali_free(codec); |
| 2284 | return err; |
| 2285 | } |
| 2286 | |
Takashi Iwai | c187c04 | 2007-02-19 15:27:33 +0100 | [diff] [blame] | 2287 | snd_card_set_dev(card, &pci->dev); |
| 2288 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2289 | /* initialise synth voices*/ |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 2290 | for (i = 0; i < ALI_CHANNELS; i++) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2291 | codec->synth.voices[i].number = i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2292 | |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 2293 | err = snd_ali_chip_init(codec); |
| 2294 | if (err < 0) { |
Takashi Iwai | 99b359b | 2005-10-20 18:26:44 +0200 | [diff] [blame] | 2295 | snd_printk(KERN_ERR "ali create: chip init error.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2296 | return err; |
| 2297 | } |
| 2298 | |
| 2299 | #ifdef CONFIG_PM |
| 2300 | codec->image = kmalloc(sizeof(*codec->image), GFP_KERNEL); |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 2301 | if (!codec->image) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2302 | snd_printk(KERN_WARNING "can't allocate apm buffer\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2303 | #endif |
| 2304 | |
| 2305 | snd_ali_enable_address_interrupt(codec); |
| 2306 | codec->hw_initialized = 1; |
| 2307 | |
| 2308 | *r_ali = codec; |
| 2309 | snd_ali_printk("created.\n"); |
| 2310 | return 0; |
| 2311 | } |
| 2312 | |
| 2313 | static int __devinit snd_ali_probe(struct pci_dev *pci, |
| 2314 | const struct pci_device_id *pci_id) |
| 2315 | { |
Takashi Iwai | d1fabd9 | 2005-11-17 14:56:03 +0100 | [diff] [blame] | 2316 | struct snd_card *card; |
| 2317 | struct snd_ali *codec; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2318 | int err; |
| 2319 | |
| 2320 | snd_ali_printk("probe ...\n"); |
| 2321 | |
Takashi Iwai | 8a3fb4d | 2005-10-20 17:10:49 +0200 | [diff] [blame] | 2322 | card = snd_card_new(index, id, THIS_MODULE, 0); |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 2323 | if (!card) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2324 | return -ENOMEM; |
| 2325 | |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 2326 | err = snd_ali_create(card, pci, pcm_channels, spdif, &codec); |
| 2327 | if (err < 0) |
| 2328 | goto error; |
Takashi Iwai | bf53c3b | 2005-11-17 16:10:51 +0100 | [diff] [blame] | 2329 | card->private_data = codec; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2330 | |
| 2331 | snd_ali_printk("mixer building ...\n"); |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 2332 | err = snd_ali_mixer(codec); |
| 2333 | if (err < 0) |
| 2334 | goto error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2335 | |
| 2336 | snd_ali_printk("pcm building ...\n"); |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 2337 | err = snd_ali_build_pcms(codec); |
| 2338 | if (err < 0) |
| 2339 | goto error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2340 | |
Sasha Khapyorsky | 5cbff89 | 2005-05-30 08:09:56 +0200 | [diff] [blame] | 2341 | snd_ali_proc_init(codec); |
| 2342 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2343 | strcpy(card->driver, "ALI5451"); |
| 2344 | strcpy(card->shortname, "ALI 5451"); |
| 2345 | |
| 2346 | sprintf(card->longname, "%s at 0x%lx, irq %li", |
| 2347 | card->shortname, codec->port, codec->irq); |
| 2348 | |
| 2349 | snd_ali_printk("register card.\n"); |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 2350 | err = snd_card_register(card); |
| 2351 | if (err < 0) |
| 2352 | goto error; |
| 2353 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2354 | pci_set_drvdata(pci, card); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2355 | return 0; |
Takashi Iwai | f9ab2b1 | 2007-04-03 13:20:49 +0200 | [diff] [blame] | 2356 | |
| 2357 | error: |
| 2358 | snd_card_free(card); |
| 2359 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2360 | } |
| 2361 | |
| 2362 | static void __devexit snd_ali_remove(struct pci_dev *pci) |
| 2363 | { |
| 2364 | snd_card_free(pci_get_drvdata(pci)); |
| 2365 | pci_set_drvdata(pci, NULL); |
| 2366 | } |
| 2367 | |
| 2368 | static struct pci_driver driver = { |
| 2369 | .name = "ALI 5451", |
| 2370 | .id_table = snd_ali_ids, |
| 2371 | .probe = snd_ali_probe, |
| 2372 | .remove = __devexit_p(snd_ali_remove), |
Takashi Iwai | bf53c3b | 2005-11-17 16:10:51 +0100 | [diff] [blame] | 2373 | #ifdef CONFIG_PM |
| 2374 | .suspend = ali_suspend, |
| 2375 | .resume = ali_resume, |
| 2376 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2377 | }; |
| 2378 | |
| 2379 | static int __init alsa_card_ali_init(void) |
| 2380 | { |
Takashi Iwai | 01d25d4 | 2005-04-11 16:58:24 +0200 | [diff] [blame] | 2381 | return pci_register_driver(&driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2382 | } |
| 2383 | |
| 2384 | static void __exit alsa_card_ali_exit(void) |
| 2385 | { |
| 2386 | pci_unregister_driver(&driver); |
| 2387 | } |
| 2388 | |
| 2389 | module_init(alsa_card_ali_init) |
| 2390 | module_exit(alsa_card_ali_exit) |