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