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