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