Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Jaroslav Kysela | c1017a4 | 2007-10-15 09:50:19 +0200 | [diff] [blame] | 2 | * Copyright (c) by Jaroslav Kysela <perex@perex.cz> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | * Routines for control of YMF724/740/744/754 chips |
| 4 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation; either version 2 of the License, or |
| 8 | * (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write to the Free Software |
| 17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 18 | * |
| 19 | */ |
| 20 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | #include <linux/delay.h> |
Clemens Ladisch | 102fa90 | 2006-10-11 12:05:59 +0200 | [diff] [blame] | 22 | #include <linux/firmware.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | #include <linux/init.h> |
| 24 | #include <linux/interrupt.h> |
| 25 | #include <linux/pci.h> |
| 26 | #include <linux/sched.h> |
| 27 | #include <linux/slab.h> |
| 28 | #include <linux/vmalloc.h> |
David Woodhouse | b82a82d | 2008-05-29 14:40:00 +0300 | [diff] [blame] | 29 | #include <linux/mutex.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | |
| 31 | #include <sound/core.h> |
| 32 | #include <sound/control.h> |
| 33 | #include <sound/info.h> |
Takashi Iwai | 3392518 | 2006-08-28 13:29:42 +0200 | [diff] [blame] | 34 | #include <sound/tlv.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | #include <sound/ymfpci.h> |
| 36 | #include <sound/asoundef.h> |
| 37 | #include <sound/mpu401.h> |
| 38 | |
| 39 | #include <asm/io.h> |
Clemens Ladisch | 102fa90 | 2006-10-11 12:05:59 +0200 | [diff] [blame] | 40 | #include <asm/byteorder.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | |
| 42 | /* |
| 43 | * common I/O routines |
| 44 | */ |
| 45 | |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 46 | static void snd_ymfpci_irq_wait(struct snd_ymfpci *chip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 48 | static inline u8 snd_ymfpci_readb(struct snd_ymfpci *chip, u32 offset) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | { |
| 50 | return readb(chip->reg_area_virt + offset); |
| 51 | } |
| 52 | |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 53 | static inline void snd_ymfpci_writeb(struct snd_ymfpci *chip, u32 offset, u8 val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | { |
| 55 | writeb(val, chip->reg_area_virt + offset); |
| 56 | } |
| 57 | |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 58 | static inline u16 snd_ymfpci_readw(struct snd_ymfpci *chip, u32 offset) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | { |
| 60 | return readw(chip->reg_area_virt + offset); |
| 61 | } |
| 62 | |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 63 | static inline void snd_ymfpci_writew(struct snd_ymfpci *chip, u32 offset, u16 val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | { |
| 65 | writew(val, chip->reg_area_virt + offset); |
| 66 | } |
| 67 | |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 68 | static inline u32 snd_ymfpci_readl(struct snd_ymfpci *chip, u32 offset) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | { |
| 70 | return readl(chip->reg_area_virt + offset); |
| 71 | } |
| 72 | |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 73 | static inline void snd_ymfpci_writel(struct snd_ymfpci *chip, u32 offset, u32 val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | { |
| 75 | writel(val, chip->reg_area_virt + offset); |
| 76 | } |
| 77 | |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 78 | static int snd_ymfpci_codec_ready(struct snd_ymfpci *chip, int secondary) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | { |
Nishanth Aravamudan | ef21ca2 | 2005-07-09 10:13:22 +0200 | [diff] [blame] | 80 | unsigned long end_time; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | u32 reg = secondary ? YDSXGR_SECSTATUSADR : YDSXGR_PRISTATUSADR; |
| 82 | |
Nishanth Aravamudan | ef21ca2 | 2005-07-09 10:13:22 +0200 | [diff] [blame] | 83 | end_time = jiffies + msecs_to_jiffies(750); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | do { |
| 85 | if ((snd_ymfpci_readw(chip, reg) & 0x8000) == 0) |
| 86 | return 0; |
Nishanth Aravamudan | 8433a50 | 2005-10-24 15:02:37 +0200 | [diff] [blame] | 87 | schedule_timeout_uninterruptible(1); |
Nishanth Aravamudan | ef21ca2 | 2005-07-09 10:13:22 +0200 | [diff] [blame] | 88 | } while (time_before(jiffies, end_time)); |
Takashi Iwai | 99b359b | 2005-10-20 18:26:44 +0200 | [diff] [blame] | 89 | snd_printk(KERN_ERR "codec_ready: codec %i is not ready [0x%x]\n", secondary, snd_ymfpci_readw(chip, reg)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | return -EBUSY; |
| 91 | } |
| 92 | |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 93 | static void snd_ymfpci_codec_write(struct snd_ac97 *ac97, u16 reg, u16 val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | { |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 95 | struct snd_ymfpci *chip = ac97->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | u32 cmd; |
| 97 | |
| 98 | snd_ymfpci_codec_ready(chip, 0); |
| 99 | cmd = ((YDSXG_AC97WRITECMD | reg) << 16) | val; |
| 100 | snd_ymfpci_writel(chip, YDSXGR_AC97CMDDATA, cmd); |
| 101 | } |
| 102 | |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 103 | static u16 snd_ymfpci_codec_read(struct snd_ac97 *ac97, u16 reg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | { |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 105 | struct snd_ymfpci *chip = ac97->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | |
| 107 | if (snd_ymfpci_codec_ready(chip, 0)) |
| 108 | return ~0; |
| 109 | snd_ymfpci_writew(chip, YDSXGR_AC97CMDADR, YDSXG_AC97READCMD | reg); |
| 110 | if (snd_ymfpci_codec_ready(chip, 0)) |
| 111 | return ~0; |
| 112 | if (chip->device_id == PCI_DEVICE_ID_YAMAHA_744 && chip->rev < 2) { |
| 113 | int i; |
| 114 | for (i = 0; i < 600; i++) |
| 115 | snd_ymfpci_readw(chip, YDSXGR_PRISTATUSDATA); |
| 116 | } |
| 117 | return snd_ymfpci_readw(chip, YDSXGR_PRISTATUSDATA); |
| 118 | } |
| 119 | |
| 120 | /* |
| 121 | * Misc routines |
| 122 | */ |
| 123 | |
| 124 | static u32 snd_ymfpci_calc_delta(u32 rate) |
| 125 | { |
| 126 | switch (rate) { |
| 127 | case 8000: return 0x02aaab00; |
| 128 | case 11025: return 0x03accd00; |
| 129 | case 16000: return 0x05555500; |
| 130 | case 22050: return 0x07599a00; |
| 131 | case 32000: return 0x0aaaab00; |
| 132 | case 44100: return 0x0eb33300; |
| 133 | default: return ((rate << 16) / 375) << 5; |
| 134 | } |
| 135 | } |
| 136 | |
| 137 | static u32 def_rate[8] = { |
| 138 | 100, 2000, 8000, 11025, 16000, 22050, 32000, 48000 |
| 139 | }; |
| 140 | |
| 141 | static u32 snd_ymfpci_calc_lpfK(u32 rate) |
| 142 | { |
| 143 | u32 i; |
| 144 | static u32 val[8] = { |
| 145 | 0x00570000, 0x06AA0000, 0x18B20000, 0x20930000, |
| 146 | 0x2B9A0000, 0x35A10000, 0x3EAA0000, 0x40000000 |
| 147 | }; |
| 148 | |
| 149 | if (rate == 44100) |
| 150 | return 0x40000000; /* FIXME: What's the right value? */ |
| 151 | for (i = 0; i < 8; i++) |
| 152 | if (rate <= def_rate[i]) |
| 153 | return val[i]; |
| 154 | return val[0]; |
| 155 | } |
| 156 | |
| 157 | static u32 snd_ymfpci_calc_lpfQ(u32 rate) |
| 158 | { |
| 159 | u32 i; |
| 160 | static u32 val[8] = { |
| 161 | 0x35280000, 0x34A70000, 0x32020000, 0x31770000, |
| 162 | 0x31390000, 0x31C90000, 0x33D00000, 0x40000000 |
| 163 | }; |
| 164 | |
| 165 | if (rate == 44100) |
| 166 | return 0x370A0000; |
| 167 | for (i = 0; i < 8; i++) |
| 168 | if (rate <= def_rate[i]) |
| 169 | return val[i]; |
| 170 | return val[0]; |
| 171 | } |
| 172 | |
| 173 | /* |
| 174 | * Hardware start management |
| 175 | */ |
| 176 | |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 177 | static void snd_ymfpci_hw_start(struct snd_ymfpci *chip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | { |
| 179 | unsigned long flags; |
| 180 | |
| 181 | spin_lock_irqsave(&chip->reg_lock, flags); |
| 182 | if (chip->start_count++ > 0) |
| 183 | goto __end; |
| 184 | snd_ymfpci_writel(chip, YDSXGR_MODE, |
| 185 | snd_ymfpci_readl(chip, YDSXGR_MODE) | 3); |
| 186 | chip->active_bank = snd_ymfpci_readl(chip, YDSXGR_CTRLSELECT) & 1; |
| 187 | __end: |
| 188 | spin_unlock_irqrestore(&chip->reg_lock, flags); |
| 189 | } |
| 190 | |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 191 | static void snd_ymfpci_hw_stop(struct snd_ymfpci *chip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | { |
| 193 | unsigned long flags; |
| 194 | long timeout = 1000; |
| 195 | |
| 196 | spin_lock_irqsave(&chip->reg_lock, flags); |
| 197 | if (--chip->start_count > 0) |
| 198 | goto __end; |
| 199 | snd_ymfpci_writel(chip, YDSXGR_MODE, |
| 200 | snd_ymfpci_readl(chip, YDSXGR_MODE) & ~3); |
| 201 | while (timeout-- > 0) { |
| 202 | if ((snd_ymfpci_readl(chip, YDSXGR_STATUS) & 2) == 0) |
| 203 | break; |
| 204 | } |
| 205 | if (atomic_read(&chip->interrupt_sleep_count)) { |
| 206 | atomic_set(&chip->interrupt_sleep_count, 0); |
| 207 | wake_up(&chip->interrupt_sleep); |
| 208 | } |
| 209 | __end: |
| 210 | spin_unlock_irqrestore(&chip->reg_lock, flags); |
| 211 | } |
| 212 | |
| 213 | /* |
| 214 | * Playback voice management |
| 215 | */ |
| 216 | |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 217 | static int voice_alloc(struct snd_ymfpci *chip, |
| 218 | enum snd_ymfpci_voice_type type, int pair, |
| 219 | struct snd_ymfpci_voice **rvoice) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | { |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 221 | struct snd_ymfpci_voice *voice, *voice2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 222 | int idx; |
| 223 | |
| 224 | *rvoice = NULL; |
| 225 | for (idx = 0; idx < YDSXG_PLAYBACK_VOICES; idx += pair ? 2 : 1) { |
| 226 | voice = &chip->voices[idx]; |
| 227 | voice2 = pair ? &chip->voices[idx+1] : NULL; |
| 228 | if (voice->use || (voice2 && voice2->use)) |
| 229 | continue; |
| 230 | voice->use = 1; |
| 231 | if (voice2) |
| 232 | voice2->use = 1; |
| 233 | switch (type) { |
| 234 | case YMFPCI_PCM: |
| 235 | voice->pcm = 1; |
| 236 | if (voice2) |
| 237 | voice2->pcm = 1; |
| 238 | break; |
| 239 | case YMFPCI_SYNTH: |
| 240 | voice->synth = 1; |
| 241 | break; |
| 242 | case YMFPCI_MIDI: |
| 243 | voice->midi = 1; |
| 244 | break; |
| 245 | } |
| 246 | snd_ymfpci_hw_start(chip); |
| 247 | if (voice2) |
| 248 | snd_ymfpci_hw_start(chip); |
| 249 | *rvoice = voice; |
| 250 | return 0; |
| 251 | } |
| 252 | return -ENOMEM; |
| 253 | } |
| 254 | |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 255 | static int snd_ymfpci_voice_alloc(struct snd_ymfpci *chip, |
| 256 | enum snd_ymfpci_voice_type type, int pair, |
| 257 | struct snd_ymfpci_voice **rvoice) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | { |
| 259 | unsigned long flags; |
| 260 | int result; |
| 261 | |
Takashi Iwai | da3cec3 | 2008-08-08 17:12:14 +0200 | [diff] [blame] | 262 | if (snd_BUG_ON(!rvoice)) |
| 263 | return -EINVAL; |
| 264 | if (snd_BUG_ON(pair && type != YMFPCI_PCM)) |
| 265 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 266 | |
| 267 | spin_lock_irqsave(&chip->voice_lock, flags); |
| 268 | for (;;) { |
| 269 | result = voice_alloc(chip, type, pair, rvoice); |
| 270 | if (result == 0 || type != YMFPCI_PCM) |
| 271 | break; |
| 272 | /* TODO: synth/midi voice deallocation */ |
| 273 | break; |
| 274 | } |
| 275 | spin_unlock_irqrestore(&chip->voice_lock, flags); |
| 276 | return result; |
| 277 | } |
| 278 | |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 279 | static int snd_ymfpci_voice_free(struct snd_ymfpci *chip, struct snd_ymfpci_voice *pvoice) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 280 | { |
| 281 | unsigned long flags; |
| 282 | |
Takashi Iwai | da3cec3 | 2008-08-08 17:12:14 +0200 | [diff] [blame] | 283 | if (snd_BUG_ON(!pvoice)) |
| 284 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 285 | snd_ymfpci_hw_stop(chip); |
| 286 | spin_lock_irqsave(&chip->voice_lock, flags); |
Teru KAMOGASHIRA | 9ed1261 | 2006-12-04 18:03:53 +0100 | [diff] [blame] | 287 | if (pvoice->number == chip->src441_used) { |
| 288 | chip->src441_used = -1; |
| 289 | pvoice->ypcm->use_441_slot = 0; |
| 290 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 291 | pvoice->use = pvoice->pcm = pvoice->synth = pvoice->midi = 0; |
| 292 | pvoice->ypcm = NULL; |
| 293 | pvoice->interrupt = NULL; |
| 294 | spin_unlock_irqrestore(&chip->voice_lock, flags); |
| 295 | return 0; |
| 296 | } |
| 297 | |
| 298 | /* |
| 299 | * PCM part |
| 300 | */ |
| 301 | |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 302 | static void snd_ymfpci_pcm_interrupt(struct snd_ymfpci *chip, struct snd_ymfpci_voice *voice) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 303 | { |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 304 | struct snd_ymfpci_pcm *ypcm; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 305 | u32 pos, delta; |
| 306 | |
| 307 | if ((ypcm = voice->ypcm) == NULL) |
| 308 | return; |
| 309 | if (ypcm->substream == NULL) |
| 310 | return; |
| 311 | spin_lock(&chip->reg_lock); |
| 312 | if (ypcm->running) { |
| 313 | pos = le32_to_cpu(voice->bank[chip->active_bank].start); |
| 314 | if (pos < ypcm->last_pos) |
| 315 | delta = pos + (ypcm->buffer_size - ypcm->last_pos); |
| 316 | else |
| 317 | delta = pos - ypcm->last_pos; |
| 318 | ypcm->period_pos += delta; |
| 319 | ypcm->last_pos = pos; |
| 320 | if (ypcm->period_pos >= ypcm->period_size) { |
Takashi Iwai | ee41965 | 2009-02-05 16:11:31 +0100 | [diff] [blame] | 321 | /* |
| 322 | printk(KERN_DEBUG |
| 323 | "done - active_bank = 0x%x, start = 0x%x\n", |
| 324 | chip->active_bank, |
| 325 | voice->bank[chip->active_bank].start); |
| 326 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 327 | ypcm->period_pos %= ypcm->period_size; |
| 328 | spin_unlock(&chip->reg_lock); |
| 329 | snd_pcm_period_elapsed(ypcm->substream); |
| 330 | spin_lock(&chip->reg_lock); |
| 331 | } |
Clemens Ladisch | 9bcf655 | 2005-08-10 10:21:43 +0200 | [diff] [blame] | 332 | |
| 333 | if (unlikely(ypcm->update_pcm_vol)) { |
| 334 | unsigned int subs = ypcm->substream->number; |
| 335 | unsigned int next_bank = 1 - chip->active_bank; |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 336 | struct snd_ymfpci_playback_bank *bank; |
Clemens Ladisch | 9bcf655 | 2005-08-10 10:21:43 +0200 | [diff] [blame] | 337 | u32 volume; |
| 338 | |
| 339 | bank = &voice->bank[next_bank]; |
| 340 | volume = cpu_to_le32(chip->pcm_mixer[subs].left << 15); |
| 341 | bank->left_gain_end = volume; |
| 342 | if (ypcm->output_rear) |
| 343 | bank->eff2_gain_end = volume; |
| 344 | if (ypcm->voices[1]) |
| 345 | bank = &ypcm->voices[1]->bank[next_bank]; |
| 346 | volume = cpu_to_le32(chip->pcm_mixer[subs].right << 15); |
| 347 | bank->right_gain_end = volume; |
| 348 | if (ypcm->output_rear) |
| 349 | bank->eff3_gain_end = volume; |
| 350 | ypcm->update_pcm_vol--; |
| 351 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 352 | } |
| 353 | spin_unlock(&chip->reg_lock); |
| 354 | } |
| 355 | |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 356 | static void snd_ymfpci_pcm_capture_interrupt(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 357 | { |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 358 | struct snd_pcm_runtime *runtime = substream->runtime; |
| 359 | struct snd_ymfpci_pcm *ypcm = runtime->private_data; |
| 360 | struct snd_ymfpci *chip = ypcm->chip; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 361 | u32 pos, delta; |
| 362 | |
| 363 | spin_lock(&chip->reg_lock); |
| 364 | if (ypcm->running) { |
| 365 | pos = le32_to_cpu(chip->bank_capture[ypcm->capture_bank_number][chip->active_bank]->start) >> ypcm->shift; |
| 366 | if (pos < ypcm->last_pos) |
| 367 | delta = pos + (ypcm->buffer_size - ypcm->last_pos); |
| 368 | else |
| 369 | delta = pos - ypcm->last_pos; |
| 370 | ypcm->period_pos += delta; |
| 371 | ypcm->last_pos = pos; |
| 372 | if (ypcm->period_pos >= ypcm->period_size) { |
| 373 | ypcm->period_pos %= ypcm->period_size; |
Takashi Iwai | ee41965 | 2009-02-05 16:11:31 +0100 | [diff] [blame] | 374 | /* |
| 375 | printk(KERN_DEBUG |
| 376 | "done - active_bank = 0x%x, start = 0x%x\n", |
| 377 | chip->active_bank, |
| 378 | voice->bank[chip->active_bank].start); |
| 379 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 380 | spin_unlock(&chip->reg_lock); |
| 381 | snd_pcm_period_elapsed(substream); |
| 382 | spin_lock(&chip->reg_lock); |
| 383 | } |
| 384 | } |
| 385 | spin_unlock(&chip->reg_lock); |
| 386 | } |
| 387 | |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 388 | static int snd_ymfpci_playback_trigger(struct snd_pcm_substream *substream, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 389 | int cmd) |
| 390 | { |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 391 | struct snd_ymfpci *chip = snd_pcm_substream_chip(substream); |
| 392 | struct snd_ymfpci_pcm *ypcm = substream->runtime->private_data; |
Clemens Ladisch | 177a7cd | 2007-07-23 17:38:44 +0200 | [diff] [blame] | 393 | struct snd_kcontrol *kctl = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 394 | int result = 0; |
| 395 | |
| 396 | spin_lock(&chip->reg_lock); |
| 397 | if (ypcm->voices[0] == NULL) { |
| 398 | result = -EINVAL; |
| 399 | goto __unlock; |
| 400 | } |
| 401 | switch (cmd) { |
| 402 | case SNDRV_PCM_TRIGGER_START: |
| 403 | case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: |
| 404 | case SNDRV_PCM_TRIGGER_RESUME: |
| 405 | chip->ctrl_playback[ypcm->voices[0]->number + 1] = cpu_to_le32(ypcm->voices[0]->bank_addr); |
Teru KAMOGASHIRA | 9ed1261 | 2006-12-04 18:03:53 +0100 | [diff] [blame] | 406 | if (ypcm->voices[1] != NULL && !ypcm->use_441_slot) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 407 | chip->ctrl_playback[ypcm->voices[1]->number + 1] = cpu_to_le32(ypcm->voices[1]->bank_addr); |
| 408 | ypcm->running = 1; |
| 409 | break; |
| 410 | case SNDRV_PCM_TRIGGER_STOP: |
Clemens Ladisch | 177a7cd | 2007-07-23 17:38:44 +0200 | [diff] [blame] | 411 | if (substream->pcm == chip->pcm && !ypcm->use_441_slot) { |
| 412 | kctl = chip->pcm_mixer[substream->number].ctl; |
| 413 | kctl->vd[0].access |= SNDRV_CTL_ELEM_ACCESS_INACTIVE; |
| 414 | } |
| 415 | /* fall through */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 416 | case SNDRV_PCM_TRIGGER_PAUSE_PUSH: |
| 417 | case SNDRV_PCM_TRIGGER_SUSPEND: |
| 418 | chip->ctrl_playback[ypcm->voices[0]->number + 1] = 0; |
Teru KAMOGASHIRA | 9ed1261 | 2006-12-04 18:03:53 +0100 | [diff] [blame] | 419 | if (ypcm->voices[1] != NULL && !ypcm->use_441_slot) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 420 | chip->ctrl_playback[ypcm->voices[1]->number + 1] = 0; |
| 421 | ypcm->running = 0; |
| 422 | break; |
| 423 | default: |
| 424 | result = -EINVAL; |
| 425 | break; |
| 426 | } |
| 427 | __unlock: |
| 428 | spin_unlock(&chip->reg_lock); |
Clemens Ladisch | 177a7cd | 2007-07-23 17:38:44 +0200 | [diff] [blame] | 429 | if (kctl) |
| 430 | snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_INFO, &kctl->id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 431 | return result; |
| 432 | } |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 433 | static int snd_ymfpci_capture_trigger(struct snd_pcm_substream *substream, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 434 | int cmd) |
| 435 | { |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 436 | struct snd_ymfpci *chip = snd_pcm_substream_chip(substream); |
| 437 | struct snd_ymfpci_pcm *ypcm = substream->runtime->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 438 | int result = 0; |
| 439 | u32 tmp; |
| 440 | |
| 441 | spin_lock(&chip->reg_lock); |
| 442 | switch (cmd) { |
| 443 | case SNDRV_PCM_TRIGGER_START: |
| 444 | case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: |
| 445 | case SNDRV_PCM_TRIGGER_RESUME: |
| 446 | tmp = snd_ymfpci_readl(chip, YDSXGR_MAPOFREC) | (1 << ypcm->capture_bank_number); |
| 447 | snd_ymfpci_writel(chip, YDSXGR_MAPOFREC, tmp); |
| 448 | ypcm->running = 1; |
| 449 | break; |
| 450 | case SNDRV_PCM_TRIGGER_STOP: |
| 451 | case SNDRV_PCM_TRIGGER_PAUSE_PUSH: |
| 452 | case SNDRV_PCM_TRIGGER_SUSPEND: |
| 453 | tmp = snd_ymfpci_readl(chip, YDSXGR_MAPOFREC) & ~(1 << ypcm->capture_bank_number); |
| 454 | snd_ymfpci_writel(chip, YDSXGR_MAPOFREC, tmp); |
| 455 | ypcm->running = 0; |
| 456 | break; |
| 457 | default: |
| 458 | result = -EINVAL; |
| 459 | break; |
| 460 | } |
| 461 | spin_unlock(&chip->reg_lock); |
| 462 | return result; |
| 463 | } |
| 464 | |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 465 | static int snd_ymfpci_pcm_voice_alloc(struct snd_ymfpci_pcm *ypcm, int voices) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 466 | { |
| 467 | int err; |
| 468 | |
| 469 | if (ypcm->voices[1] != NULL && voices < 2) { |
| 470 | snd_ymfpci_voice_free(ypcm->chip, ypcm->voices[1]); |
| 471 | ypcm->voices[1] = NULL; |
| 472 | } |
| 473 | if (voices == 1 && ypcm->voices[0] != NULL) |
| 474 | return 0; /* already allocated */ |
| 475 | if (voices == 2 && ypcm->voices[0] != NULL && ypcm->voices[1] != NULL) |
| 476 | return 0; /* already allocated */ |
| 477 | if (voices > 1) { |
| 478 | if (ypcm->voices[0] != NULL && ypcm->voices[1] == NULL) { |
| 479 | snd_ymfpci_voice_free(ypcm->chip, ypcm->voices[0]); |
| 480 | ypcm->voices[0] = NULL; |
| 481 | } |
| 482 | } |
| 483 | err = snd_ymfpci_voice_alloc(ypcm->chip, YMFPCI_PCM, voices > 1, &ypcm->voices[0]); |
| 484 | if (err < 0) |
| 485 | return err; |
| 486 | ypcm->voices[0]->ypcm = ypcm; |
| 487 | ypcm->voices[0]->interrupt = snd_ymfpci_pcm_interrupt; |
| 488 | if (voices > 1) { |
| 489 | ypcm->voices[1] = &ypcm->chip->voices[ypcm->voices[0]->number + 1]; |
| 490 | ypcm->voices[1]->ypcm = ypcm; |
| 491 | } |
| 492 | return 0; |
| 493 | } |
| 494 | |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 495 | static void snd_ymfpci_pcm_init_voice(struct snd_ymfpci_pcm *ypcm, unsigned int voiceidx, |
| 496 | struct snd_pcm_runtime *runtime, |
Clemens Ladisch | 9bcf655 | 2005-08-10 10:21:43 +0200 | [diff] [blame] | 497 | int has_pcm_volume) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 498 | { |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 499 | struct snd_ymfpci_voice *voice = ypcm->voices[voiceidx]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 500 | u32 format; |
Clemens Ladisch | 9bcf655 | 2005-08-10 10:21:43 +0200 | [diff] [blame] | 501 | u32 delta = snd_ymfpci_calc_delta(runtime->rate); |
| 502 | u32 lpfQ = snd_ymfpci_calc_lpfQ(runtime->rate); |
| 503 | u32 lpfK = snd_ymfpci_calc_lpfK(runtime->rate); |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 504 | struct snd_ymfpci_playback_bank *bank; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 505 | unsigned int nbank; |
Clemens Ladisch | 9bcf655 | 2005-08-10 10:21:43 +0200 | [diff] [blame] | 506 | u32 vol_left, vol_right; |
| 507 | u8 use_left, use_right; |
Teru KAMOGASHIRA | 9ed1261 | 2006-12-04 18:03:53 +0100 | [diff] [blame] | 508 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 509 | |
Takashi Iwai | da3cec3 | 2008-08-08 17:12:14 +0200 | [diff] [blame] | 510 | if (snd_BUG_ON(!voice)) |
| 511 | return; |
Clemens Ladisch | 9bcf655 | 2005-08-10 10:21:43 +0200 | [diff] [blame] | 512 | if (runtime->channels == 1) { |
| 513 | use_left = 1; |
| 514 | use_right = 1; |
| 515 | } else { |
| 516 | use_left = (voiceidx & 1) == 0; |
| 517 | use_right = !use_left; |
| 518 | } |
| 519 | if (has_pcm_volume) { |
| 520 | vol_left = cpu_to_le32(ypcm->chip->pcm_mixer |
| 521 | [ypcm->substream->number].left << 15); |
| 522 | vol_right = cpu_to_le32(ypcm->chip->pcm_mixer |
| 523 | [ypcm->substream->number].right << 15); |
| 524 | } else { |
| 525 | vol_left = cpu_to_le32(0x40000000); |
| 526 | vol_right = cpu_to_le32(0x40000000); |
| 527 | } |
Teru KAMOGASHIRA | 9ed1261 | 2006-12-04 18:03:53 +0100 | [diff] [blame] | 528 | spin_lock_irqsave(&ypcm->chip->voice_lock, flags); |
Clemens Ladisch | 9bcf655 | 2005-08-10 10:21:43 +0200 | [diff] [blame] | 529 | format = runtime->channels == 2 ? 0x00010000 : 0; |
| 530 | if (snd_pcm_format_width(runtime->format) == 8) |
| 531 | format |= 0x80000000; |
Teru KAMOGASHIRA | 9ed1261 | 2006-12-04 18:03:53 +0100 | [diff] [blame] | 532 | else if (ypcm->chip->device_id == PCI_DEVICE_ID_YAMAHA_754 && |
| 533 | runtime->rate == 44100 && runtime->channels == 2 && |
| 534 | voiceidx == 0 && (ypcm->chip->src441_used == -1 || |
| 535 | ypcm->chip->src441_used == voice->number)) { |
| 536 | ypcm->chip->src441_used = voice->number; |
| 537 | ypcm->use_441_slot = 1; |
| 538 | format |= 0x10000000; |
Teru KAMOGASHIRA | 9ed1261 | 2006-12-04 18:03:53 +0100 | [diff] [blame] | 539 | } |
| 540 | if (ypcm->chip->src441_used == voice->number && |
| 541 | (format & 0x10000000) == 0) { |
| 542 | ypcm->chip->src441_used = -1; |
| 543 | ypcm->use_441_slot = 0; |
| 544 | } |
Clemens Ladisch | 9bcf655 | 2005-08-10 10:21:43 +0200 | [diff] [blame] | 545 | if (runtime->channels == 2 && (voiceidx & 1) != 0) |
| 546 | format |= 1; |
Teru KAMOGASHIRA | 9ed1261 | 2006-12-04 18:03:53 +0100 | [diff] [blame] | 547 | spin_unlock_irqrestore(&ypcm->chip->voice_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 548 | for (nbank = 0; nbank < 2; nbank++) { |
| 549 | bank = &voice->bank[nbank]; |
Clemens Ladisch | 9bcf655 | 2005-08-10 10:21:43 +0200 | [diff] [blame] | 550 | memset(bank, 0, sizeof(*bank)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 551 | bank->format = cpu_to_le32(format); |
Clemens Ladisch | 9bcf655 | 2005-08-10 10:21:43 +0200 | [diff] [blame] | 552 | bank->base = cpu_to_le32(runtime->dma_addr); |
| 553 | bank->loop_end = cpu_to_le32(ypcm->buffer_size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 554 | bank->lpfQ = cpu_to_le32(lpfQ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 555 | bank->delta = |
| 556 | bank->delta_end = cpu_to_le32(delta); |
| 557 | bank->lpfK = |
| 558 | bank->lpfK_end = cpu_to_le32(lpfK); |
Clemens Ladisch | 9bcf655 | 2005-08-10 10:21:43 +0200 | [diff] [blame] | 559 | bank->eg_gain = |
| 560 | bank->eg_gain_end = cpu_to_le32(0x40000000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 561 | |
Clemens Ladisch | 9bcf655 | 2005-08-10 10:21:43 +0200 | [diff] [blame] | 562 | if (ypcm->output_front) { |
| 563 | if (use_left) { |
| 564 | bank->left_gain = |
| 565 | bank->left_gain_end = vol_left; |
| 566 | } |
| 567 | if (use_right) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 568 | bank->right_gain = |
Clemens Ladisch | 9bcf655 | 2005-08-10 10:21:43 +0200 | [diff] [blame] | 569 | bank->right_gain_end = vol_right; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 570 | } |
Clemens Ladisch | 9bcf655 | 2005-08-10 10:21:43 +0200 | [diff] [blame] | 571 | } |
| 572 | if (ypcm->output_rear) { |
Jaroslav Kysela | 5a25c5c | 2006-01-18 08:02:24 +0100 | [diff] [blame] | 573 | if (!ypcm->swap_rear) { |
| 574 | if (use_left) { |
| 575 | bank->eff2_gain = |
| 576 | bank->eff2_gain_end = vol_left; |
| 577 | } |
| 578 | if (use_right) { |
| 579 | bank->eff3_gain = |
| 580 | bank->eff3_gain_end = vol_right; |
| 581 | } |
| 582 | } else { |
| 583 | /* The SPDIF out channels seem to be swapped, so we have |
| 584 | * to swap them here, too. The rear analog out channels |
| 585 | * will be wrong, but otherwise AC3 would not work. |
| 586 | */ |
| 587 | if (use_left) { |
| 588 | bank->eff3_gain = |
| 589 | bank->eff3_gain_end = vol_left; |
| 590 | } |
| 591 | if (use_right) { |
| 592 | bank->eff2_gain = |
| 593 | bank->eff2_gain_end = vol_right; |
| 594 | } |
| 595 | } |
| 596 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 597 | } |
| 598 | } |
| 599 | |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 600 | static int __devinit snd_ymfpci_ac3_init(struct snd_ymfpci *chip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 601 | { |
| 602 | if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(chip->pci), |
| 603 | 4096, &chip->ac3_tmp_base) < 0) |
| 604 | return -ENOMEM; |
| 605 | |
| 606 | chip->bank_effect[3][0]->base = |
| 607 | chip->bank_effect[3][1]->base = cpu_to_le32(chip->ac3_tmp_base.addr); |
| 608 | chip->bank_effect[3][0]->loop_end = |
| 609 | chip->bank_effect[3][1]->loop_end = cpu_to_le32(1024); |
| 610 | chip->bank_effect[4][0]->base = |
| 611 | chip->bank_effect[4][1]->base = cpu_to_le32(chip->ac3_tmp_base.addr + 2048); |
| 612 | chip->bank_effect[4][0]->loop_end = |
| 613 | chip->bank_effect[4][1]->loop_end = cpu_to_le32(1024); |
| 614 | |
| 615 | spin_lock_irq(&chip->reg_lock); |
| 616 | snd_ymfpci_writel(chip, YDSXGR_MAPOFEFFECT, |
| 617 | snd_ymfpci_readl(chip, YDSXGR_MAPOFEFFECT) | 3 << 3); |
| 618 | spin_unlock_irq(&chip->reg_lock); |
| 619 | return 0; |
| 620 | } |
| 621 | |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 622 | static int snd_ymfpci_ac3_done(struct snd_ymfpci *chip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 623 | { |
| 624 | spin_lock_irq(&chip->reg_lock); |
| 625 | snd_ymfpci_writel(chip, YDSXGR_MAPOFEFFECT, |
| 626 | snd_ymfpci_readl(chip, YDSXGR_MAPOFEFFECT) & ~(3 << 3)); |
| 627 | spin_unlock_irq(&chip->reg_lock); |
| 628 | // snd_ymfpci_irq_wait(chip); |
| 629 | if (chip->ac3_tmp_base.area) { |
| 630 | snd_dma_free_pages(&chip->ac3_tmp_base); |
| 631 | chip->ac3_tmp_base.area = NULL; |
| 632 | } |
| 633 | return 0; |
| 634 | } |
| 635 | |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 636 | static int snd_ymfpci_playback_hw_params(struct snd_pcm_substream *substream, |
| 637 | struct snd_pcm_hw_params *hw_params) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 638 | { |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 639 | struct snd_pcm_runtime *runtime = substream->runtime; |
| 640 | struct snd_ymfpci_pcm *ypcm = runtime->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 641 | int err; |
| 642 | |
| 643 | if ((err = snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params))) < 0) |
| 644 | return err; |
| 645 | if ((err = snd_ymfpci_pcm_voice_alloc(ypcm, params_channels(hw_params))) < 0) |
| 646 | return err; |
| 647 | return 0; |
| 648 | } |
| 649 | |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 650 | static int snd_ymfpci_playback_hw_free(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 651 | { |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 652 | struct snd_ymfpci *chip = snd_pcm_substream_chip(substream); |
| 653 | struct snd_pcm_runtime *runtime = substream->runtime; |
| 654 | struct snd_ymfpci_pcm *ypcm; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 655 | |
| 656 | if (runtime->private_data == NULL) |
| 657 | return 0; |
| 658 | ypcm = runtime->private_data; |
| 659 | |
| 660 | /* wait, until the PCI operations are not finished */ |
| 661 | snd_ymfpci_irq_wait(chip); |
| 662 | snd_pcm_lib_free_pages(substream); |
| 663 | if (ypcm->voices[1]) { |
| 664 | snd_ymfpci_voice_free(chip, ypcm->voices[1]); |
| 665 | ypcm->voices[1] = NULL; |
| 666 | } |
| 667 | if (ypcm->voices[0]) { |
| 668 | snd_ymfpci_voice_free(chip, ypcm->voices[0]); |
| 669 | ypcm->voices[0] = NULL; |
| 670 | } |
| 671 | return 0; |
| 672 | } |
| 673 | |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 674 | static int snd_ymfpci_playback_prepare(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 675 | { |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 676 | struct snd_ymfpci *chip = snd_pcm_substream_chip(substream); |
| 677 | struct snd_pcm_runtime *runtime = substream->runtime; |
| 678 | struct snd_ymfpci_pcm *ypcm = runtime->private_data; |
Clemens Ladisch | 177a7cd | 2007-07-23 17:38:44 +0200 | [diff] [blame] | 679 | struct snd_kcontrol *kctl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 680 | unsigned int nvoice; |
| 681 | |
| 682 | ypcm->period_size = runtime->period_size; |
| 683 | ypcm->buffer_size = runtime->buffer_size; |
| 684 | ypcm->period_pos = 0; |
| 685 | ypcm->last_pos = 0; |
| 686 | for (nvoice = 0; nvoice < runtime->channels; nvoice++) |
Clemens Ladisch | 9bcf655 | 2005-08-10 10:21:43 +0200 | [diff] [blame] | 687 | snd_ymfpci_pcm_init_voice(ypcm, nvoice, runtime, |
| 688 | substream->pcm == chip->pcm); |
Clemens Ladisch | 177a7cd | 2007-07-23 17:38:44 +0200 | [diff] [blame] | 689 | |
| 690 | if (substream->pcm == chip->pcm && !ypcm->use_441_slot) { |
| 691 | kctl = chip->pcm_mixer[substream->number].ctl; |
| 692 | kctl->vd[0].access &= ~SNDRV_CTL_ELEM_ACCESS_INACTIVE; |
| 693 | snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_INFO, &kctl->id); |
| 694 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 695 | return 0; |
| 696 | } |
| 697 | |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 698 | static int snd_ymfpci_capture_hw_params(struct snd_pcm_substream *substream, |
| 699 | struct snd_pcm_hw_params *hw_params) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 700 | { |
| 701 | return snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params)); |
| 702 | } |
| 703 | |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 704 | static int snd_ymfpci_capture_hw_free(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 705 | { |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 706 | struct snd_ymfpci *chip = snd_pcm_substream_chip(substream); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 707 | |
| 708 | /* wait, until the PCI operations are not finished */ |
| 709 | snd_ymfpci_irq_wait(chip); |
| 710 | return snd_pcm_lib_free_pages(substream); |
| 711 | } |
| 712 | |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 713 | static int snd_ymfpci_capture_prepare(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 714 | { |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 715 | struct snd_ymfpci *chip = snd_pcm_substream_chip(substream); |
| 716 | struct snd_pcm_runtime *runtime = substream->runtime; |
| 717 | struct snd_ymfpci_pcm *ypcm = runtime->private_data; |
| 718 | struct snd_ymfpci_capture_bank * bank; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 719 | int nbank; |
| 720 | u32 rate, format; |
| 721 | |
| 722 | ypcm->period_size = runtime->period_size; |
| 723 | ypcm->buffer_size = runtime->buffer_size; |
| 724 | ypcm->period_pos = 0; |
| 725 | ypcm->last_pos = 0; |
| 726 | ypcm->shift = 0; |
| 727 | rate = ((48000 * 4096) / runtime->rate) - 1; |
| 728 | format = 0; |
| 729 | if (runtime->channels == 2) { |
| 730 | format |= 2; |
| 731 | ypcm->shift++; |
| 732 | } |
| 733 | if (snd_pcm_format_width(runtime->format) == 8) |
| 734 | format |= 1; |
| 735 | else |
| 736 | ypcm->shift++; |
| 737 | switch (ypcm->capture_bank_number) { |
| 738 | case 0: |
| 739 | snd_ymfpci_writel(chip, YDSXGR_RECFORMAT, format); |
| 740 | snd_ymfpci_writel(chip, YDSXGR_RECSLOTSR, rate); |
| 741 | break; |
| 742 | case 1: |
| 743 | snd_ymfpci_writel(chip, YDSXGR_ADCFORMAT, format); |
| 744 | snd_ymfpci_writel(chip, YDSXGR_ADCSLOTSR, rate); |
| 745 | break; |
| 746 | } |
| 747 | for (nbank = 0; nbank < 2; nbank++) { |
| 748 | bank = chip->bank_capture[ypcm->capture_bank_number][nbank]; |
| 749 | bank->base = cpu_to_le32(runtime->dma_addr); |
| 750 | bank->loop_end = cpu_to_le32(ypcm->buffer_size << ypcm->shift); |
| 751 | bank->start = 0; |
| 752 | bank->num_of_loops = 0; |
| 753 | } |
| 754 | return 0; |
| 755 | } |
| 756 | |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 757 | static snd_pcm_uframes_t snd_ymfpci_playback_pointer(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 758 | { |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 759 | struct snd_ymfpci *chip = snd_pcm_substream_chip(substream); |
| 760 | struct snd_pcm_runtime *runtime = substream->runtime; |
| 761 | struct snd_ymfpci_pcm *ypcm = runtime->private_data; |
| 762 | struct snd_ymfpci_voice *voice = ypcm->voices[0]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 763 | |
| 764 | if (!(ypcm->running && voice)) |
| 765 | return 0; |
| 766 | return le32_to_cpu(voice->bank[chip->active_bank].start); |
| 767 | } |
| 768 | |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 769 | static snd_pcm_uframes_t snd_ymfpci_capture_pointer(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 770 | { |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 771 | struct snd_ymfpci *chip = snd_pcm_substream_chip(substream); |
| 772 | struct snd_pcm_runtime *runtime = substream->runtime; |
| 773 | struct snd_ymfpci_pcm *ypcm = runtime->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 774 | |
| 775 | if (!ypcm->running) |
| 776 | return 0; |
| 777 | return le32_to_cpu(chip->bank_capture[ypcm->capture_bank_number][chip->active_bank]->start) >> ypcm->shift; |
| 778 | } |
| 779 | |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 780 | static void snd_ymfpci_irq_wait(struct snd_ymfpci *chip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 781 | { |
| 782 | wait_queue_t wait; |
| 783 | int loops = 4; |
| 784 | |
| 785 | while (loops-- > 0) { |
| 786 | if ((snd_ymfpci_readl(chip, YDSXGR_MODE) & 3) == 0) |
| 787 | continue; |
| 788 | init_waitqueue_entry(&wait, current); |
| 789 | add_wait_queue(&chip->interrupt_sleep, &wait); |
| 790 | atomic_inc(&chip->interrupt_sleep_count); |
Nishanth Aravamudan | 8433a50 | 2005-10-24 15:02:37 +0200 | [diff] [blame] | 791 | schedule_timeout_uninterruptible(msecs_to_jiffies(50)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 792 | remove_wait_queue(&chip->interrupt_sleep, &wait); |
| 793 | } |
| 794 | } |
| 795 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 796 | static irqreturn_t snd_ymfpci_interrupt(int irq, void *dev_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 797 | { |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 798 | struct snd_ymfpci *chip = dev_id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 799 | u32 status, nvoice, mode; |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 800 | struct snd_ymfpci_voice *voice; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 801 | |
| 802 | status = snd_ymfpci_readl(chip, YDSXGR_STATUS); |
| 803 | if (status & 0x80000000) { |
| 804 | chip->active_bank = snd_ymfpci_readl(chip, YDSXGR_CTRLSELECT) & 1; |
| 805 | spin_lock(&chip->voice_lock); |
| 806 | for (nvoice = 0; nvoice < YDSXG_PLAYBACK_VOICES; nvoice++) { |
| 807 | voice = &chip->voices[nvoice]; |
| 808 | if (voice->interrupt) |
| 809 | voice->interrupt(chip, voice); |
| 810 | } |
| 811 | for (nvoice = 0; nvoice < YDSXG_CAPTURE_VOICES; nvoice++) { |
| 812 | if (chip->capture_substream[nvoice]) |
| 813 | snd_ymfpci_pcm_capture_interrupt(chip->capture_substream[nvoice]); |
| 814 | } |
| 815 | #if 0 |
| 816 | for (nvoice = 0; nvoice < YDSXG_EFFECT_VOICES; nvoice++) { |
| 817 | if (chip->effect_substream[nvoice]) |
| 818 | snd_ymfpci_pcm_effect_interrupt(chip->effect_substream[nvoice]); |
| 819 | } |
| 820 | #endif |
| 821 | spin_unlock(&chip->voice_lock); |
| 822 | spin_lock(&chip->reg_lock); |
| 823 | snd_ymfpci_writel(chip, YDSXGR_STATUS, 0x80000000); |
| 824 | mode = snd_ymfpci_readl(chip, YDSXGR_MODE) | 2; |
| 825 | snd_ymfpci_writel(chip, YDSXGR_MODE, mode); |
| 826 | spin_unlock(&chip->reg_lock); |
| 827 | |
| 828 | if (atomic_read(&chip->interrupt_sleep_count)) { |
| 829 | atomic_set(&chip->interrupt_sleep_count, 0); |
| 830 | wake_up(&chip->interrupt_sleep); |
| 831 | } |
| 832 | } |
| 833 | |
| 834 | status = snd_ymfpci_readw(chip, YDSXGR_INTFLAG); |
| 835 | if (status & 1) { |
| 836 | if (chip->timer) |
Clemens Ladisch | 6e2efaa | 2009-08-10 10:06:53 +0200 | [diff] [blame] | 837 | snd_timer_interrupt(chip->timer, chip->timer_ticks); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 838 | } |
| 839 | snd_ymfpci_writew(chip, YDSXGR_INTFLAG, status); |
| 840 | |
| 841 | if (chip->rawmidi) |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 842 | snd_mpu401_uart_interrupt(irq, chip->rawmidi->private_data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 843 | return IRQ_HANDLED; |
| 844 | } |
| 845 | |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 846 | static struct snd_pcm_hardware snd_ymfpci_playback = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 847 | { |
| 848 | .info = (SNDRV_PCM_INFO_MMAP | |
| 849 | SNDRV_PCM_INFO_MMAP_VALID | |
| 850 | SNDRV_PCM_INFO_INTERLEAVED | |
| 851 | SNDRV_PCM_INFO_BLOCK_TRANSFER | |
| 852 | SNDRV_PCM_INFO_PAUSE | |
| 853 | SNDRV_PCM_INFO_RESUME), |
| 854 | .formats = SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE, |
| 855 | .rates = SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000, |
| 856 | .rate_min = 8000, |
| 857 | .rate_max = 48000, |
| 858 | .channels_min = 1, |
| 859 | .channels_max = 2, |
| 860 | .buffer_bytes_max = 256 * 1024, /* FIXME: enough? */ |
| 861 | .period_bytes_min = 64, |
| 862 | .period_bytes_max = 256 * 1024, /* FIXME: enough? */ |
| 863 | .periods_min = 3, |
| 864 | .periods_max = 1024, |
| 865 | .fifo_size = 0, |
| 866 | }; |
| 867 | |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 868 | static struct snd_pcm_hardware snd_ymfpci_capture = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 869 | { |
| 870 | .info = (SNDRV_PCM_INFO_MMAP | |
| 871 | SNDRV_PCM_INFO_MMAP_VALID | |
| 872 | SNDRV_PCM_INFO_INTERLEAVED | |
| 873 | SNDRV_PCM_INFO_BLOCK_TRANSFER | |
| 874 | SNDRV_PCM_INFO_PAUSE | |
| 875 | SNDRV_PCM_INFO_RESUME), |
| 876 | .formats = SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE, |
| 877 | .rates = SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000, |
| 878 | .rate_min = 8000, |
| 879 | .rate_max = 48000, |
| 880 | .channels_min = 1, |
| 881 | .channels_max = 2, |
| 882 | .buffer_bytes_max = 256 * 1024, /* FIXME: enough? */ |
| 883 | .period_bytes_min = 64, |
| 884 | .period_bytes_max = 256 * 1024, /* FIXME: enough? */ |
| 885 | .periods_min = 3, |
| 886 | .periods_max = 1024, |
| 887 | .fifo_size = 0, |
| 888 | }; |
| 889 | |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 890 | static void snd_ymfpci_pcm_free_substream(struct snd_pcm_runtime *runtime) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 891 | { |
Jesper Juhl | 4d57277 | 2005-05-30 17:30:32 +0200 | [diff] [blame] | 892 | kfree(runtime->private_data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 893 | } |
| 894 | |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 895 | static int snd_ymfpci_playback_open_1(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 896 | { |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 897 | struct snd_ymfpci *chip = snd_pcm_substream_chip(substream); |
| 898 | struct snd_pcm_runtime *runtime = substream->runtime; |
| 899 | struct snd_ymfpci_pcm *ypcm; |
Clemens Ladisch | 84f9df1 | 2011-09-16 22:52:48 +0200 | [diff] [blame^] | 900 | int err; |
| 901 | |
| 902 | runtime->hw = snd_ymfpci_playback; |
| 903 | /* FIXME? True value is 256/48 = 5.33333 ms */ |
| 904 | err = snd_pcm_hw_constraint_minmax(runtime, |
| 905 | SNDRV_PCM_HW_PARAM_PERIOD_TIME, |
| 906 | 5334, UINT_MAX); |
| 907 | if (err < 0) |
| 908 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 909 | |
Takashi Iwai | e560d8d | 2005-09-09 14:21:46 +0200 | [diff] [blame] | 910 | ypcm = kzalloc(sizeof(*ypcm), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 911 | if (ypcm == NULL) |
| 912 | return -ENOMEM; |
| 913 | ypcm->chip = chip; |
| 914 | ypcm->type = PLAYBACK_VOICE; |
| 915 | ypcm->substream = substream; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 916 | runtime->private_data = ypcm; |
| 917 | runtime->private_free = snd_ymfpci_pcm_free_substream; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 918 | return 0; |
| 919 | } |
| 920 | |
| 921 | /* call with spinlock held */ |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 922 | static void ymfpci_open_extension(struct snd_ymfpci *chip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 923 | { |
| 924 | if (! chip->rear_opened) { |
| 925 | if (! chip->spdif_opened) /* set AC3 */ |
| 926 | snd_ymfpci_writel(chip, YDSXGR_MODE, |
| 927 | snd_ymfpci_readl(chip, YDSXGR_MODE) | (1 << 30)); |
| 928 | /* enable second codec (4CHEN) */ |
| 929 | snd_ymfpci_writew(chip, YDSXGR_SECCONFIG, |
| 930 | (snd_ymfpci_readw(chip, YDSXGR_SECCONFIG) & ~0x0330) | 0x0010); |
| 931 | } |
| 932 | } |
| 933 | |
| 934 | /* call with spinlock held */ |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 935 | static void ymfpci_close_extension(struct snd_ymfpci *chip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 936 | { |
| 937 | if (! chip->rear_opened) { |
| 938 | if (! chip->spdif_opened) |
| 939 | snd_ymfpci_writel(chip, YDSXGR_MODE, |
| 940 | snd_ymfpci_readl(chip, YDSXGR_MODE) & ~(1 << 30)); |
| 941 | snd_ymfpci_writew(chip, YDSXGR_SECCONFIG, |
| 942 | (snd_ymfpci_readw(chip, YDSXGR_SECCONFIG) & ~0x0330) & ~0x0010); |
| 943 | } |
| 944 | } |
| 945 | |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 946 | static int snd_ymfpci_playback_open(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 947 | { |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 948 | struct snd_ymfpci *chip = snd_pcm_substream_chip(substream); |
| 949 | struct snd_pcm_runtime *runtime = substream->runtime; |
| 950 | struct snd_ymfpci_pcm *ypcm; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 951 | int err; |
| 952 | |
| 953 | if ((err = snd_ymfpci_playback_open_1(substream)) < 0) |
| 954 | return err; |
| 955 | ypcm = runtime->private_data; |
| 956 | ypcm->output_front = 1; |
| 957 | ypcm->output_rear = chip->mode_dup4ch ? 1 : 0; |
Glen Masgai | d930126 | 2006-10-10 09:27:19 +0200 | [diff] [blame] | 958 | ypcm->swap_rear = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 959 | spin_lock_irq(&chip->reg_lock); |
| 960 | if (ypcm->output_rear) { |
| 961 | ymfpci_open_extension(chip); |
| 962 | chip->rear_opened++; |
| 963 | } |
| 964 | spin_unlock_irq(&chip->reg_lock); |
| 965 | return 0; |
| 966 | } |
| 967 | |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 968 | static int snd_ymfpci_playback_spdif_open(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 969 | { |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 970 | struct snd_ymfpci *chip = snd_pcm_substream_chip(substream); |
| 971 | struct snd_pcm_runtime *runtime = substream->runtime; |
| 972 | struct snd_ymfpci_pcm *ypcm; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 973 | int err; |
| 974 | |
| 975 | if ((err = snd_ymfpci_playback_open_1(substream)) < 0) |
| 976 | return err; |
| 977 | ypcm = runtime->private_data; |
| 978 | ypcm->output_front = 0; |
| 979 | ypcm->output_rear = 1; |
Glen Masgai | d930126 | 2006-10-10 09:27:19 +0200 | [diff] [blame] | 980 | ypcm->swap_rear = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 981 | spin_lock_irq(&chip->reg_lock); |
| 982 | snd_ymfpci_writew(chip, YDSXGR_SPDIFOUTCTRL, |
| 983 | snd_ymfpci_readw(chip, YDSXGR_SPDIFOUTCTRL) | 2); |
| 984 | ymfpci_open_extension(chip); |
| 985 | chip->spdif_pcm_bits = chip->spdif_bits; |
| 986 | snd_ymfpci_writew(chip, YDSXGR_SPDIFOUTSTATUS, chip->spdif_pcm_bits); |
| 987 | chip->spdif_opened++; |
| 988 | spin_unlock_irq(&chip->reg_lock); |
| 989 | |
| 990 | chip->spdif_pcm_ctl->vd[0].access &= ~SNDRV_CTL_ELEM_ACCESS_INACTIVE; |
| 991 | snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE | |
| 992 | SNDRV_CTL_EVENT_MASK_INFO, &chip->spdif_pcm_ctl->id); |
| 993 | return 0; |
| 994 | } |
| 995 | |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 996 | static int snd_ymfpci_playback_4ch_open(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 997 | { |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 998 | struct snd_ymfpci *chip = snd_pcm_substream_chip(substream); |
| 999 | struct snd_pcm_runtime *runtime = substream->runtime; |
| 1000 | struct snd_ymfpci_pcm *ypcm; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1001 | int err; |
| 1002 | |
| 1003 | if ((err = snd_ymfpci_playback_open_1(substream)) < 0) |
| 1004 | return err; |
| 1005 | ypcm = runtime->private_data; |
| 1006 | ypcm->output_front = 0; |
| 1007 | ypcm->output_rear = 1; |
Glen Masgai | d930126 | 2006-10-10 09:27:19 +0200 | [diff] [blame] | 1008 | ypcm->swap_rear = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1009 | spin_lock_irq(&chip->reg_lock); |
| 1010 | ymfpci_open_extension(chip); |
| 1011 | chip->rear_opened++; |
| 1012 | spin_unlock_irq(&chip->reg_lock); |
| 1013 | return 0; |
| 1014 | } |
| 1015 | |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 1016 | static int snd_ymfpci_capture_open(struct snd_pcm_substream *substream, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1017 | u32 capture_bank_number) |
| 1018 | { |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 1019 | struct snd_ymfpci *chip = snd_pcm_substream_chip(substream); |
| 1020 | struct snd_pcm_runtime *runtime = substream->runtime; |
| 1021 | struct snd_ymfpci_pcm *ypcm; |
Clemens Ladisch | 84f9df1 | 2011-09-16 22:52:48 +0200 | [diff] [blame^] | 1022 | int err; |
| 1023 | |
| 1024 | runtime->hw = snd_ymfpci_capture; |
| 1025 | /* FIXME? True value is 256/48 = 5.33333 ms */ |
| 1026 | err = snd_pcm_hw_constraint_minmax(runtime, |
| 1027 | SNDRV_PCM_HW_PARAM_PERIOD_TIME, |
| 1028 | 5334, UINT_MAX); |
| 1029 | if (err < 0) |
| 1030 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1031 | |
Takashi Iwai | e560d8d | 2005-09-09 14:21:46 +0200 | [diff] [blame] | 1032 | ypcm = kzalloc(sizeof(*ypcm), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1033 | if (ypcm == NULL) |
| 1034 | return -ENOMEM; |
| 1035 | ypcm->chip = chip; |
| 1036 | ypcm->type = capture_bank_number + CAPTURE_REC; |
| 1037 | ypcm->substream = substream; |
| 1038 | ypcm->capture_bank_number = capture_bank_number; |
| 1039 | chip->capture_substream[capture_bank_number] = substream; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1040 | runtime->private_data = ypcm; |
| 1041 | runtime->private_free = snd_ymfpci_pcm_free_substream; |
| 1042 | snd_ymfpci_hw_start(chip); |
| 1043 | return 0; |
| 1044 | } |
| 1045 | |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 1046 | static int snd_ymfpci_capture_rec_open(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1047 | { |
| 1048 | return snd_ymfpci_capture_open(substream, 0); |
| 1049 | } |
| 1050 | |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 1051 | static int snd_ymfpci_capture_ac97_open(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1052 | { |
| 1053 | return snd_ymfpci_capture_open(substream, 1); |
| 1054 | } |
| 1055 | |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 1056 | static int snd_ymfpci_playback_close_1(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1057 | { |
| 1058 | return 0; |
| 1059 | } |
| 1060 | |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 1061 | static int snd_ymfpci_playback_close(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1062 | { |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 1063 | struct snd_ymfpci *chip = snd_pcm_substream_chip(substream); |
| 1064 | struct snd_ymfpci_pcm *ypcm = substream->runtime->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1065 | |
| 1066 | spin_lock_irq(&chip->reg_lock); |
| 1067 | if (ypcm->output_rear && chip->rear_opened > 0) { |
| 1068 | chip->rear_opened--; |
| 1069 | ymfpci_close_extension(chip); |
| 1070 | } |
| 1071 | spin_unlock_irq(&chip->reg_lock); |
| 1072 | return snd_ymfpci_playback_close_1(substream); |
| 1073 | } |
| 1074 | |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 1075 | static int snd_ymfpci_playback_spdif_close(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1076 | { |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 1077 | struct snd_ymfpci *chip = snd_pcm_substream_chip(substream); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1078 | |
| 1079 | spin_lock_irq(&chip->reg_lock); |
| 1080 | chip->spdif_opened = 0; |
| 1081 | ymfpci_close_extension(chip); |
| 1082 | snd_ymfpci_writew(chip, YDSXGR_SPDIFOUTCTRL, |
| 1083 | snd_ymfpci_readw(chip, YDSXGR_SPDIFOUTCTRL) & ~2); |
| 1084 | snd_ymfpci_writew(chip, YDSXGR_SPDIFOUTSTATUS, chip->spdif_bits); |
| 1085 | spin_unlock_irq(&chip->reg_lock); |
| 1086 | chip->spdif_pcm_ctl->vd[0].access |= SNDRV_CTL_ELEM_ACCESS_INACTIVE; |
| 1087 | snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE | |
| 1088 | SNDRV_CTL_EVENT_MASK_INFO, &chip->spdif_pcm_ctl->id); |
| 1089 | return snd_ymfpci_playback_close_1(substream); |
| 1090 | } |
| 1091 | |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 1092 | static int snd_ymfpci_playback_4ch_close(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1093 | { |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 1094 | struct snd_ymfpci *chip = snd_pcm_substream_chip(substream); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1095 | |
| 1096 | spin_lock_irq(&chip->reg_lock); |
| 1097 | if (chip->rear_opened > 0) { |
| 1098 | chip->rear_opened--; |
| 1099 | ymfpci_close_extension(chip); |
| 1100 | } |
| 1101 | spin_unlock_irq(&chip->reg_lock); |
| 1102 | return snd_ymfpci_playback_close_1(substream); |
| 1103 | } |
| 1104 | |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 1105 | static int snd_ymfpci_capture_close(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1106 | { |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 1107 | struct snd_ymfpci *chip = snd_pcm_substream_chip(substream); |
| 1108 | struct snd_pcm_runtime *runtime = substream->runtime; |
| 1109 | struct snd_ymfpci_pcm *ypcm = runtime->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1110 | |
| 1111 | if (ypcm != NULL) { |
| 1112 | chip->capture_substream[ypcm->capture_bank_number] = NULL; |
| 1113 | snd_ymfpci_hw_stop(chip); |
| 1114 | } |
| 1115 | return 0; |
| 1116 | } |
| 1117 | |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 1118 | static struct snd_pcm_ops snd_ymfpci_playback_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1119 | .open = snd_ymfpci_playback_open, |
| 1120 | .close = snd_ymfpci_playback_close, |
| 1121 | .ioctl = snd_pcm_lib_ioctl, |
| 1122 | .hw_params = snd_ymfpci_playback_hw_params, |
| 1123 | .hw_free = snd_ymfpci_playback_hw_free, |
| 1124 | .prepare = snd_ymfpci_playback_prepare, |
| 1125 | .trigger = snd_ymfpci_playback_trigger, |
| 1126 | .pointer = snd_ymfpci_playback_pointer, |
| 1127 | }; |
| 1128 | |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 1129 | static struct snd_pcm_ops snd_ymfpci_capture_rec_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1130 | .open = snd_ymfpci_capture_rec_open, |
| 1131 | .close = snd_ymfpci_capture_close, |
| 1132 | .ioctl = snd_pcm_lib_ioctl, |
| 1133 | .hw_params = snd_ymfpci_capture_hw_params, |
| 1134 | .hw_free = snd_ymfpci_capture_hw_free, |
| 1135 | .prepare = snd_ymfpci_capture_prepare, |
| 1136 | .trigger = snd_ymfpci_capture_trigger, |
| 1137 | .pointer = snd_ymfpci_capture_pointer, |
| 1138 | }; |
| 1139 | |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 1140 | int __devinit snd_ymfpci_pcm(struct snd_ymfpci *chip, int device, struct snd_pcm ** rpcm) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1141 | { |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 1142 | struct snd_pcm *pcm; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1143 | int err; |
| 1144 | |
| 1145 | if (rpcm) |
| 1146 | *rpcm = NULL; |
| 1147 | if ((err = snd_pcm_new(chip->card, "YMFPCI", device, 32, 1, &pcm)) < 0) |
| 1148 | return err; |
| 1149 | pcm->private_data = chip; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1150 | |
| 1151 | snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_ymfpci_playback_ops); |
| 1152 | snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_ymfpci_capture_rec_ops); |
| 1153 | |
| 1154 | /* global setup */ |
| 1155 | pcm->info_flags = 0; |
| 1156 | strcpy(pcm->name, "YMFPCI"); |
| 1157 | chip->pcm = pcm; |
| 1158 | |
| 1159 | snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV, |
| 1160 | snd_dma_pci_data(chip->pci), 64*1024, 256*1024); |
| 1161 | |
| 1162 | if (rpcm) |
| 1163 | *rpcm = pcm; |
| 1164 | return 0; |
| 1165 | } |
| 1166 | |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 1167 | static struct snd_pcm_ops snd_ymfpci_capture_ac97_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1168 | .open = snd_ymfpci_capture_ac97_open, |
| 1169 | .close = snd_ymfpci_capture_close, |
| 1170 | .ioctl = snd_pcm_lib_ioctl, |
| 1171 | .hw_params = snd_ymfpci_capture_hw_params, |
| 1172 | .hw_free = snd_ymfpci_capture_hw_free, |
| 1173 | .prepare = snd_ymfpci_capture_prepare, |
| 1174 | .trigger = snd_ymfpci_capture_trigger, |
| 1175 | .pointer = snd_ymfpci_capture_pointer, |
| 1176 | }; |
| 1177 | |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 1178 | int __devinit snd_ymfpci_pcm2(struct snd_ymfpci *chip, int device, struct snd_pcm ** rpcm) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1179 | { |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 1180 | struct snd_pcm *pcm; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1181 | int err; |
| 1182 | |
| 1183 | if (rpcm) |
| 1184 | *rpcm = NULL; |
| 1185 | if ((err = snd_pcm_new(chip->card, "YMFPCI - PCM2", device, 0, 1, &pcm)) < 0) |
| 1186 | return err; |
| 1187 | pcm->private_data = chip; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1188 | |
| 1189 | snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_ymfpci_capture_ac97_ops); |
| 1190 | |
| 1191 | /* global setup */ |
| 1192 | pcm->info_flags = 0; |
| 1193 | sprintf(pcm->name, "YMFPCI - %s", |
| 1194 | chip->device_id == PCI_DEVICE_ID_YAMAHA_754 ? "Direct Recording" : "AC'97"); |
| 1195 | chip->pcm2 = pcm; |
| 1196 | |
| 1197 | snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV, |
| 1198 | snd_dma_pci_data(chip->pci), 64*1024, 256*1024); |
| 1199 | |
| 1200 | if (rpcm) |
| 1201 | *rpcm = pcm; |
| 1202 | return 0; |
| 1203 | } |
| 1204 | |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 1205 | static struct snd_pcm_ops snd_ymfpci_playback_spdif_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1206 | .open = snd_ymfpci_playback_spdif_open, |
| 1207 | .close = snd_ymfpci_playback_spdif_close, |
| 1208 | .ioctl = snd_pcm_lib_ioctl, |
| 1209 | .hw_params = snd_ymfpci_playback_hw_params, |
| 1210 | .hw_free = snd_ymfpci_playback_hw_free, |
| 1211 | .prepare = snd_ymfpci_playback_prepare, |
| 1212 | .trigger = snd_ymfpci_playback_trigger, |
| 1213 | .pointer = snd_ymfpci_playback_pointer, |
| 1214 | }; |
| 1215 | |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 1216 | int __devinit snd_ymfpci_pcm_spdif(struct snd_ymfpci *chip, int device, struct snd_pcm ** rpcm) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1217 | { |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 1218 | struct snd_pcm *pcm; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1219 | int err; |
| 1220 | |
| 1221 | if (rpcm) |
| 1222 | *rpcm = NULL; |
| 1223 | if ((err = snd_pcm_new(chip->card, "YMFPCI - IEC958", device, 1, 0, &pcm)) < 0) |
| 1224 | return err; |
| 1225 | pcm->private_data = chip; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1226 | |
| 1227 | snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_ymfpci_playback_spdif_ops); |
| 1228 | |
| 1229 | /* global setup */ |
| 1230 | pcm->info_flags = 0; |
| 1231 | strcpy(pcm->name, "YMFPCI - IEC958"); |
| 1232 | chip->pcm_spdif = pcm; |
| 1233 | |
| 1234 | snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV, |
| 1235 | snd_dma_pci_data(chip->pci), 64*1024, 256*1024); |
| 1236 | |
| 1237 | if (rpcm) |
| 1238 | *rpcm = pcm; |
| 1239 | return 0; |
| 1240 | } |
| 1241 | |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 1242 | static struct snd_pcm_ops snd_ymfpci_playback_4ch_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1243 | .open = snd_ymfpci_playback_4ch_open, |
| 1244 | .close = snd_ymfpci_playback_4ch_close, |
| 1245 | .ioctl = snd_pcm_lib_ioctl, |
| 1246 | .hw_params = snd_ymfpci_playback_hw_params, |
| 1247 | .hw_free = snd_ymfpci_playback_hw_free, |
| 1248 | .prepare = snd_ymfpci_playback_prepare, |
| 1249 | .trigger = snd_ymfpci_playback_trigger, |
| 1250 | .pointer = snd_ymfpci_playback_pointer, |
| 1251 | }; |
| 1252 | |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 1253 | int __devinit snd_ymfpci_pcm_4ch(struct snd_ymfpci *chip, int device, struct snd_pcm ** rpcm) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1254 | { |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 1255 | struct snd_pcm *pcm; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1256 | int err; |
| 1257 | |
| 1258 | if (rpcm) |
| 1259 | *rpcm = NULL; |
| 1260 | if ((err = snd_pcm_new(chip->card, "YMFPCI - Rear", device, 1, 0, &pcm)) < 0) |
| 1261 | return err; |
| 1262 | pcm->private_data = chip; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1263 | |
| 1264 | snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_ymfpci_playback_4ch_ops); |
| 1265 | |
| 1266 | /* global setup */ |
| 1267 | pcm->info_flags = 0; |
| 1268 | strcpy(pcm->name, "YMFPCI - Rear PCM"); |
| 1269 | chip->pcm_4ch = pcm; |
| 1270 | |
| 1271 | snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV, |
| 1272 | snd_dma_pci_data(chip->pci), 64*1024, 256*1024); |
| 1273 | |
| 1274 | if (rpcm) |
| 1275 | *rpcm = pcm; |
| 1276 | return 0; |
| 1277 | } |
| 1278 | |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 1279 | static int snd_ymfpci_spdif_default_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1280 | { |
| 1281 | uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958; |
| 1282 | uinfo->count = 1; |
| 1283 | return 0; |
| 1284 | } |
| 1285 | |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 1286 | static int snd_ymfpci_spdif_default_get(struct snd_kcontrol *kcontrol, |
| 1287 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1288 | { |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 1289 | struct snd_ymfpci *chip = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1290 | |
| 1291 | spin_lock_irq(&chip->reg_lock); |
| 1292 | ucontrol->value.iec958.status[0] = (chip->spdif_bits >> 0) & 0xff; |
| 1293 | ucontrol->value.iec958.status[1] = (chip->spdif_bits >> 8) & 0xff; |
Clemens Ladisch | fc80a20 | 2006-01-13 07:41:45 +0100 | [diff] [blame] | 1294 | ucontrol->value.iec958.status[3] = IEC958_AES3_CON_FS_48000; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1295 | spin_unlock_irq(&chip->reg_lock); |
| 1296 | return 0; |
| 1297 | } |
| 1298 | |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 1299 | static int snd_ymfpci_spdif_default_put(struct snd_kcontrol *kcontrol, |
| 1300 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1301 | { |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 1302 | struct snd_ymfpci *chip = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1303 | unsigned int val; |
| 1304 | int change; |
| 1305 | |
| 1306 | val = ((ucontrol->value.iec958.status[0] & 0x3e) << 0) | |
| 1307 | (ucontrol->value.iec958.status[1] << 8); |
| 1308 | spin_lock_irq(&chip->reg_lock); |
| 1309 | change = chip->spdif_bits != val; |
| 1310 | chip->spdif_bits = val; |
| 1311 | if ((snd_ymfpci_readw(chip, YDSXGR_SPDIFOUTCTRL) & 1) && chip->pcm_spdif == NULL) |
| 1312 | snd_ymfpci_writew(chip, YDSXGR_SPDIFOUTSTATUS, chip->spdif_bits); |
| 1313 | spin_unlock_irq(&chip->reg_lock); |
| 1314 | return change; |
| 1315 | } |
| 1316 | |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 1317 | static struct snd_kcontrol_new snd_ymfpci_spdif_default __devinitdata = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1318 | { |
| 1319 | .iface = SNDRV_CTL_ELEM_IFACE_PCM, |
| 1320 | .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,DEFAULT), |
| 1321 | .info = snd_ymfpci_spdif_default_info, |
| 1322 | .get = snd_ymfpci_spdif_default_get, |
| 1323 | .put = snd_ymfpci_spdif_default_put |
| 1324 | }; |
| 1325 | |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 1326 | static int snd_ymfpci_spdif_mask_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1327 | { |
| 1328 | uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958; |
| 1329 | uinfo->count = 1; |
| 1330 | return 0; |
| 1331 | } |
| 1332 | |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 1333 | static int snd_ymfpci_spdif_mask_get(struct snd_kcontrol *kcontrol, |
| 1334 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1335 | { |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 1336 | struct snd_ymfpci *chip = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1337 | |
| 1338 | spin_lock_irq(&chip->reg_lock); |
| 1339 | ucontrol->value.iec958.status[0] = 0x3e; |
| 1340 | ucontrol->value.iec958.status[1] = 0xff; |
| 1341 | spin_unlock_irq(&chip->reg_lock); |
| 1342 | return 0; |
| 1343 | } |
| 1344 | |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 1345 | static struct snd_kcontrol_new snd_ymfpci_spdif_mask __devinitdata = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1346 | { |
| 1347 | .access = SNDRV_CTL_ELEM_ACCESS_READ, |
| 1348 | .iface = SNDRV_CTL_ELEM_IFACE_PCM, |
| 1349 | .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,CON_MASK), |
| 1350 | .info = snd_ymfpci_spdif_mask_info, |
| 1351 | .get = snd_ymfpci_spdif_mask_get, |
| 1352 | }; |
| 1353 | |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 1354 | static int snd_ymfpci_spdif_stream_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1355 | { |
| 1356 | uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958; |
| 1357 | uinfo->count = 1; |
| 1358 | return 0; |
| 1359 | } |
| 1360 | |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 1361 | static int snd_ymfpci_spdif_stream_get(struct snd_kcontrol *kcontrol, |
| 1362 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1363 | { |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 1364 | struct snd_ymfpci *chip = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1365 | |
| 1366 | spin_lock_irq(&chip->reg_lock); |
| 1367 | ucontrol->value.iec958.status[0] = (chip->spdif_pcm_bits >> 0) & 0xff; |
| 1368 | ucontrol->value.iec958.status[1] = (chip->spdif_pcm_bits >> 8) & 0xff; |
Clemens Ladisch | fc80a20 | 2006-01-13 07:41:45 +0100 | [diff] [blame] | 1369 | ucontrol->value.iec958.status[3] = IEC958_AES3_CON_FS_48000; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1370 | spin_unlock_irq(&chip->reg_lock); |
| 1371 | return 0; |
| 1372 | } |
| 1373 | |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 1374 | static int snd_ymfpci_spdif_stream_put(struct snd_kcontrol *kcontrol, |
| 1375 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1376 | { |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 1377 | struct snd_ymfpci *chip = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1378 | unsigned int val; |
| 1379 | int change; |
| 1380 | |
| 1381 | val = ((ucontrol->value.iec958.status[0] & 0x3e) << 0) | |
| 1382 | (ucontrol->value.iec958.status[1] << 8); |
| 1383 | spin_lock_irq(&chip->reg_lock); |
| 1384 | change = chip->spdif_pcm_bits != val; |
| 1385 | chip->spdif_pcm_bits = val; |
| 1386 | if ((snd_ymfpci_readw(chip, YDSXGR_SPDIFOUTCTRL) & 2)) |
| 1387 | snd_ymfpci_writew(chip, YDSXGR_SPDIFOUTSTATUS, chip->spdif_pcm_bits); |
| 1388 | spin_unlock_irq(&chip->reg_lock); |
| 1389 | return change; |
| 1390 | } |
| 1391 | |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 1392 | static struct snd_kcontrol_new snd_ymfpci_spdif_stream __devinitdata = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1393 | { |
| 1394 | .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_INACTIVE, |
| 1395 | .iface = SNDRV_CTL_ELEM_IFACE_PCM, |
| 1396 | .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,PCM_STREAM), |
| 1397 | .info = snd_ymfpci_spdif_stream_info, |
| 1398 | .get = snd_ymfpci_spdif_stream_get, |
| 1399 | .put = snd_ymfpci_spdif_stream_put |
| 1400 | }; |
| 1401 | |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 1402 | static int snd_ymfpci_drec_source_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *info) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1403 | { |
Clemens Ladisch | bed6896 | 2011-01-10 16:29:06 +0100 | [diff] [blame] | 1404 | static const char *const texts[3] = {"AC'97", "IEC958", "ZV Port"}; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1405 | |
Clemens Ladisch | bed6896 | 2011-01-10 16:29:06 +0100 | [diff] [blame] | 1406 | return snd_ctl_enum_info(info, 1, 3, texts); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1407 | } |
| 1408 | |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 1409 | static int snd_ymfpci_drec_source_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *value) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1410 | { |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 1411 | struct snd_ymfpci *chip = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1412 | u16 reg; |
| 1413 | |
| 1414 | spin_lock_irq(&chip->reg_lock); |
| 1415 | reg = snd_ymfpci_readw(chip, YDSXGR_GLOBALCTRL); |
| 1416 | spin_unlock_irq(&chip->reg_lock); |
| 1417 | if (!(reg & 0x100)) |
| 1418 | value->value.enumerated.item[0] = 0; |
| 1419 | else |
| 1420 | value->value.enumerated.item[0] = 1 + ((reg & 0x200) != 0); |
| 1421 | return 0; |
| 1422 | } |
| 1423 | |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 1424 | static int snd_ymfpci_drec_source_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *value) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1425 | { |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 1426 | struct snd_ymfpci *chip = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1427 | u16 reg, old_reg; |
| 1428 | |
| 1429 | spin_lock_irq(&chip->reg_lock); |
| 1430 | old_reg = snd_ymfpci_readw(chip, YDSXGR_GLOBALCTRL); |
| 1431 | if (value->value.enumerated.item[0] == 0) |
| 1432 | reg = old_reg & ~0x100; |
| 1433 | else |
| 1434 | reg = (old_reg & ~0x300) | 0x100 | ((value->value.enumerated.item[0] == 2) << 9); |
| 1435 | snd_ymfpci_writew(chip, YDSXGR_GLOBALCTRL, reg); |
| 1436 | spin_unlock_irq(&chip->reg_lock); |
| 1437 | return reg != old_reg; |
| 1438 | } |
| 1439 | |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 1440 | static struct snd_kcontrol_new snd_ymfpci_drec_source __devinitdata = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1441 | .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, |
| 1442 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 1443 | .name = "Direct Recording Source", |
| 1444 | .info = snd_ymfpci_drec_source_info, |
| 1445 | .get = snd_ymfpci_drec_source_get, |
| 1446 | .put = snd_ymfpci_drec_source_put |
| 1447 | }; |
| 1448 | |
| 1449 | /* |
| 1450 | * Mixer controls |
| 1451 | */ |
| 1452 | |
Glen Masgai | d602c88 | 2005-09-28 08:19:05 +0200 | [diff] [blame] | 1453 | #define YMFPCI_SINGLE(xname, xindex, reg, shift) \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1454 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \ |
| 1455 | .info = snd_ymfpci_info_single, \ |
| 1456 | .get = snd_ymfpci_get_single, .put = snd_ymfpci_put_single, \ |
Glen Masgai | d602c88 | 2005-09-28 08:19:05 +0200 | [diff] [blame] | 1457 | .private_value = ((reg) | ((shift) << 16)) } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1458 | |
Takashi Iwai | a5ce889 | 2007-07-23 15:42:26 +0200 | [diff] [blame] | 1459 | #define snd_ymfpci_info_single snd_ctl_boolean_mono_info |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1460 | |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 1461 | static int snd_ymfpci_get_single(struct snd_kcontrol *kcontrol, |
| 1462 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1463 | { |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 1464 | struct snd_ymfpci *chip = snd_kcontrol_chip(kcontrol); |
Glen Masgai | d602c88 | 2005-09-28 08:19:05 +0200 | [diff] [blame] | 1465 | int reg = kcontrol->private_value & 0xffff; |
| 1466 | unsigned int shift = (kcontrol->private_value >> 16) & 0xff; |
| 1467 | unsigned int mask = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1468 | |
Glen Masgai | d602c88 | 2005-09-28 08:19:05 +0200 | [diff] [blame] | 1469 | switch (reg) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1470 | case YDSXGR_SPDIFOUTCTRL: break; |
| 1471 | case YDSXGR_SPDIFINCTRL: break; |
| 1472 | default: return -EINVAL; |
| 1473 | } |
Glen Masgai | d602c88 | 2005-09-28 08:19:05 +0200 | [diff] [blame] | 1474 | ucontrol->value.integer.value[0] = |
| 1475 | (snd_ymfpci_readl(chip, reg) >> shift) & mask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1476 | return 0; |
| 1477 | } |
| 1478 | |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 1479 | static int snd_ymfpci_put_single(struct snd_kcontrol *kcontrol, |
| 1480 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1481 | { |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 1482 | struct snd_ymfpci *chip = snd_kcontrol_chip(kcontrol); |
Glen Masgai | d602c88 | 2005-09-28 08:19:05 +0200 | [diff] [blame] | 1483 | int reg = kcontrol->private_value & 0xffff; |
| 1484 | unsigned int shift = (kcontrol->private_value >> 16) & 0xff; |
| 1485 | unsigned int mask = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1486 | int change; |
| 1487 | unsigned int val, oval; |
| 1488 | |
Glen Masgai | d602c88 | 2005-09-28 08:19:05 +0200 | [diff] [blame] | 1489 | switch (reg) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1490 | case YDSXGR_SPDIFOUTCTRL: break; |
| 1491 | case YDSXGR_SPDIFINCTRL: break; |
| 1492 | default: return -EINVAL; |
| 1493 | } |
| 1494 | val = (ucontrol->value.integer.value[0] & mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1495 | val <<= shift; |
| 1496 | spin_lock_irq(&chip->reg_lock); |
| 1497 | oval = snd_ymfpci_readl(chip, reg); |
| 1498 | val = (oval & ~(mask << shift)) | val; |
| 1499 | change = val != oval; |
| 1500 | snd_ymfpci_writel(chip, reg, val); |
| 1501 | spin_unlock_irq(&chip->reg_lock); |
| 1502 | return change; |
| 1503 | } |
| 1504 | |
Takashi Iwai | 0cb29ea | 2007-01-29 15:33:49 +0100 | [diff] [blame] | 1505 | static const DECLARE_TLV_DB_LINEAR(db_scale_native, TLV_DB_GAIN_MUTE, 0); |
Takashi Iwai | 3392518 | 2006-08-28 13:29:42 +0200 | [diff] [blame] | 1506 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1507 | #define YMFPCI_DOUBLE(xname, xindex, reg) \ |
| 1508 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \ |
Takashi Iwai | 3392518 | 2006-08-28 13:29:42 +0200 | [diff] [blame] | 1509 | .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_TLV_READ, \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1510 | .info = snd_ymfpci_info_double, \ |
| 1511 | .get = snd_ymfpci_get_double, .put = snd_ymfpci_put_double, \ |
Takashi Iwai | 3392518 | 2006-08-28 13:29:42 +0200 | [diff] [blame] | 1512 | .private_value = reg, \ |
| 1513 | .tlv = { .p = db_scale_native } } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1514 | |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 1515 | static int snd_ymfpci_info_double(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1516 | { |
| 1517 | unsigned int reg = kcontrol->private_value; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1518 | |
| 1519 | if (reg < 0x80 || reg >= 0xc0) |
| 1520 | return -EINVAL; |
Adrian Bunk | 467a8c2 | 2005-04-11 14:11:00 +0200 | [diff] [blame] | 1521 | uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1522 | uinfo->count = 2; |
| 1523 | uinfo->value.integer.min = 0; |
Adrian Bunk | 467a8c2 | 2005-04-11 14:11:00 +0200 | [diff] [blame] | 1524 | uinfo->value.integer.max = 16383; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1525 | return 0; |
| 1526 | } |
| 1527 | |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 1528 | static int snd_ymfpci_get_double(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1529 | { |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 1530 | struct snd_ymfpci *chip = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1531 | unsigned int reg = kcontrol->private_value; |
Adrian Bunk | 467a8c2 | 2005-04-11 14:11:00 +0200 | [diff] [blame] | 1532 | unsigned int shift_left = 0, shift_right = 16, mask = 16383; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1533 | unsigned int val; |
| 1534 | |
| 1535 | if (reg < 0x80 || reg >= 0xc0) |
| 1536 | return -EINVAL; |
| 1537 | spin_lock_irq(&chip->reg_lock); |
| 1538 | val = snd_ymfpci_readl(chip, reg); |
| 1539 | spin_unlock_irq(&chip->reg_lock); |
| 1540 | ucontrol->value.integer.value[0] = (val >> shift_left) & mask; |
| 1541 | ucontrol->value.integer.value[1] = (val >> shift_right) & mask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1542 | return 0; |
| 1543 | } |
| 1544 | |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 1545 | static int snd_ymfpci_put_double(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1546 | { |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 1547 | struct snd_ymfpci *chip = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1548 | unsigned int reg = kcontrol->private_value; |
Adrian Bunk | 467a8c2 | 2005-04-11 14:11:00 +0200 | [diff] [blame] | 1549 | unsigned int shift_left = 0, shift_right = 16, mask = 16383; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1550 | int change; |
| 1551 | unsigned int val1, val2, oval; |
| 1552 | |
| 1553 | if (reg < 0x80 || reg >= 0xc0) |
| 1554 | return -EINVAL; |
| 1555 | val1 = ucontrol->value.integer.value[0] & mask; |
| 1556 | val2 = ucontrol->value.integer.value[1] & mask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1557 | val1 <<= shift_left; |
| 1558 | val2 <<= shift_right; |
| 1559 | spin_lock_irq(&chip->reg_lock); |
| 1560 | oval = snd_ymfpci_readl(chip, reg); |
| 1561 | val1 = (oval & ~((mask << shift_left) | (mask << shift_right))) | val1 | val2; |
| 1562 | change = val1 != oval; |
| 1563 | snd_ymfpci_writel(chip, reg, val1); |
| 1564 | spin_unlock_irq(&chip->reg_lock); |
| 1565 | return change; |
| 1566 | } |
| 1567 | |
Clemens Ladisch | 177a7cd | 2007-07-23 17:38:44 +0200 | [diff] [blame] | 1568 | static int snd_ymfpci_put_nativedacvol(struct snd_kcontrol *kcontrol, |
| 1569 | struct snd_ctl_elem_value *ucontrol) |
| 1570 | { |
| 1571 | struct snd_ymfpci *chip = snd_kcontrol_chip(kcontrol); |
| 1572 | unsigned int reg = YDSXGR_NATIVEDACOUTVOL; |
| 1573 | unsigned int reg2 = YDSXGR_BUF441OUTVOL; |
| 1574 | int change; |
| 1575 | unsigned int value, oval; |
| 1576 | |
| 1577 | value = ucontrol->value.integer.value[0] & 0x3fff; |
| 1578 | value |= (ucontrol->value.integer.value[1] & 0x3fff) << 16; |
| 1579 | spin_lock_irq(&chip->reg_lock); |
| 1580 | oval = snd_ymfpci_readl(chip, reg); |
| 1581 | change = value != oval; |
| 1582 | snd_ymfpci_writel(chip, reg, value); |
| 1583 | snd_ymfpci_writel(chip, reg2, value); |
| 1584 | spin_unlock_irq(&chip->reg_lock); |
| 1585 | return change; |
| 1586 | } |
| 1587 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1588 | /* |
| 1589 | * 4ch duplication |
| 1590 | */ |
Takashi Iwai | a5ce889 | 2007-07-23 15:42:26 +0200 | [diff] [blame] | 1591 | #define snd_ymfpci_info_dup4ch snd_ctl_boolean_mono_info |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1592 | |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 1593 | static int snd_ymfpci_get_dup4ch(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1594 | { |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 1595 | struct snd_ymfpci *chip = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1596 | ucontrol->value.integer.value[0] = chip->mode_dup4ch; |
| 1597 | return 0; |
| 1598 | } |
| 1599 | |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 1600 | static int snd_ymfpci_put_dup4ch(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1601 | { |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 1602 | struct snd_ymfpci *chip = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1603 | int change; |
| 1604 | change = (ucontrol->value.integer.value[0] != chip->mode_dup4ch); |
| 1605 | if (change) |
| 1606 | chip->mode_dup4ch = !!ucontrol->value.integer.value[0]; |
| 1607 | return change; |
| 1608 | } |
| 1609 | |
| 1610 | |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 1611 | static struct snd_kcontrol_new snd_ymfpci_controls[] __devinitdata = { |
Clemens Ladisch | 177a7cd | 2007-07-23 17:38:44 +0200 | [diff] [blame] | 1612 | { |
| 1613 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 1614 | .name = "Wave Playback Volume", |
| 1615 | .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | |
| 1616 | SNDRV_CTL_ELEM_ACCESS_TLV_READ, |
| 1617 | .info = snd_ymfpci_info_double, |
| 1618 | .get = snd_ymfpci_get_double, |
| 1619 | .put = snd_ymfpci_put_nativedacvol, |
| 1620 | .private_value = YDSXGR_NATIVEDACOUTVOL, |
| 1621 | .tlv = { .p = db_scale_native }, |
| 1622 | }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1623 | YMFPCI_DOUBLE("Wave Capture Volume", 0, YDSXGR_NATIVEDACLOOPVOL), |
| 1624 | YMFPCI_DOUBLE("Digital Capture Volume", 0, YDSXGR_NATIVEDACINVOL), |
| 1625 | YMFPCI_DOUBLE("Digital Capture Volume", 1, YDSXGR_NATIVEADCINVOL), |
| 1626 | YMFPCI_DOUBLE("ADC Playback Volume", 0, YDSXGR_PRIADCOUTVOL), |
| 1627 | YMFPCI_DOUBLE("ADC Capture Volume", 0, YDSXGR_PRIADCLOOPVOL), |
| 1628 | YMFPCI_DOUBLE("ADC Playback Volume", 1, YDSXGR_SECADCOUTVOL), |
| 1629 | YMFPCI_DOUBLE("ADC Capture Volume", 1, YDSXGR_SECADCLOOPVOL), |
Raymond Yau | 89f3325 | 2011-09-09 19:15:01 +0800 | [diff] [blame] | 1630 | YMFPCI_DOUBLE("FM Legacy Playback Volume", 0, YDSXGR_LEGACYOUTVOL), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1631 | YMFPCI_DOUBLE(SNDRV_CTL_NAME_IEC958("AC97 ", PLAYBACK,VOLUME), 0, YDSXGR_ZVOUTVOL), |
| 1632 | YMFPCI_DOUBLE(SNDRV_CTL_NAME_IEC958("", CAPTURE,VOLUME), 0, YDSXGR_ZVLOOPVOL), |
| 1633 | YMFPCI_DOUBLE(SNDRV_CTL_NAME_IEC958("AC97 ",PLAYBACK,VOLUME), 1, YDSXGR_SPDIFOUTVOL), |
| 1634 | YMFPCI_DOUBLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,VOLUME), 1, YDSXGR_SPDIFLOOPVOL), |
Glen Masgai | d602c88 | 2005-09-28 08:19:05 +0200 | [diff] [blame] | 1635 | YMFPCI_SINGLE(SNDRV_CTL_NAME_IEC958("",PLAYBACK,SWITCH), 0, YDSXGR_SPDIFOUTCTRL, 0), |
| 1636 | YMFPCI_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,SWITCH), 0, YDSXGR_SPDIFINCTRL, 0), |
| 1637 | YMFPCI_SINGLE(SNDRV_CTL_NAME_IEC958("Loop",NONE,NONE), 0, YDSXGR_SPDIFINCTRL, 4), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1638 | { |
| 1639 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 1640 | .name = "4ch Duplication", |
| 1641 | .info = snd_ymfpci_info_dup4ch, |
| 1642 | .get = snd_ymfpci_get_dup4ch, |
| 1643 | .put = snd_ymfpci_put_dup4ch, |
| 1644 | }, |
| 1645 | }; |
| 1646 | |
| 1647 | |
| 1648 | /* |
| 1649 | * GPIO |
| 1650 | */ |
| 1651 | |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 1652 | static int snd_ymfpci_get_gpio_out(struct snd_ymfpci *chip, int pin) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1653 | { |
| 1654 | u16 reg, mode; |
| 1655 | unsigned long flags; |
| 1656 | |
| 1657 | spin_lock_irqsave(&chip->reg_lock, flags); |
| 1658 | reg = snd_ymfpci_readw(chip, YDSXGR_GPIOFUNCENABLE); |
| 1659 | reg &= ~(1 << (pin + 8)); |
| 1660 | reg |= (1 << pin); |
| 1661 | snd_ymfpci_writew(chip, YDSXGR_GPIOFUNCENABLE, reg); |
| 1662 | /* set the level mode for input line */ |
| 1663 | mode = snd_ymfpci_readw(chip, YDSXGR_GPIOTYPECONFIG); |
| 1664 | mode &= ~(3 << (pin * 2)); |
| 1665 | snd_ymfpci_writew(chip, YDSXGR_GPIOTYPECONFIG, mode); |
| 1666 | snd_ymfpci_writew(chip, YDSXGR_GPIOFUNCENABLE, reg | (1 << (pin + 8))); |
| 1667 | mode = snd_ymfpci_readw(chip, YDSXGR_GPIOINSTATUS); |
| 1668 | spin_unlock_irqrestore(&chip->reg_lock, flags); |
| 1669 | return (mode >> pin) & 1; |
| 1670 | } |
| 1671 | |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 1672 | static int snd_ymfpci_set_gpio_out(struct snd_ymfpci *chip, int pin, int enable) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1673 | { |
| 1674 | u16 reg; |
| 1675 | unsigned long flags; |
| 1676 | |
| 1677 | spin_lock_irqsave(&chip->reg_lock, flags); |
| 1678 | reg = snd_ymfpci_readw(chip, YDSXGR_GPIOFUNCENABLE); |
| 1679 | reg &= ~(1 << pin); |
| 1680 | reg &= ~(1 << (pin + 8)); |
| 1681 | snd_ymfpci_writew(chip, YDSXGR_GPIOFUNCENABLE, reg); |
| 1682 | snd_ymfpci_writew(chip, YDSXGR_GPIOOUTCTRL, enable << pin); |
| 1683 | snd_ymfpci_writew(chip, YDSXGR_GPIOFUNCENABLE, reg | (1 << (pin + 8))); |
| 1684 | spin_unlock_irqrestore(&chip->reg_lock, flags); |
| 1685 | |
| 1686 | return 0; |
| 1687 | } |
| 1688 | |
Takashi Iwai | a5ce889 | 2007-07-23 15:42:26 +0200 | [diff] [blame] | 1689 | #define snd_ymfpci_gpio_sw_info snd_ctl_boolean_mono_info |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1690 | |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 1691 | static int snd_ymfpci_gpio_sw_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1692 | { |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 1693 | struct snd_ymfpci *chip = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1694 | int pin = (int)kcontrol->private_value; |
| 1695 | ucontrol->value.integer.value[0] = snd_ymfpci_get_gpio_out(chip, pin); |
| 1696 | return 0; |
| 1697 | } |
| 1698 | |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 1699 | static int snd_ymfpci_gpio_sw_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1700 | { |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 1701 | struct snd_ymfpci *chip = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1702 | int pin = (int)kcontrol->private_value; |
| 1703 | |
| 1704 | if (snd_ymfpci_get_gpio_out(chip, pin) != ucontrol->value.integer.value[0]) { |
| 1705 | snd_ymfpci_set_gpio_out(chip, pin, !!ucontrol->value.integer.value[0]); |
| 1706 | ucontrol->value.integer.value[0] = snd_ymfpci_get_gpio_out(chip, pin); |
| 1707 | return 1; |
| 1708 | } |
| 1709 | return 0; |
| 1710 | } |
| 1711 | |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 1712 | static struct snd_kcontrol_new snd_ymfpci_rear_shared __devinitdata = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1713 | .name = "Shared Rear/Line-In Switch", |
| 1714 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 1715 | .info = snd_ymfpci_gpio_sw_info, |
| 1716 | .get = snd_ymfpci_gpio_sw_get, |
| 1717 | .put = snd_ymfpci_gpio_sw_put, |
| 1718 | .private_value = 2, |
| 1719 | }; |
| 1720 | |
Clemens Ladisch | 9bcf655 | 2005-08-10 10:21:43 +0200 | [diff] [blame] | 1721 | /* |
| 1722 | * PCM voice volume |
| 1723 | */ |
| 1724 | |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 1725 | static int snd_ymfpci_pcm_vol_info(struct snd_kcontrol *kcontrol, |
| 1726 | struct snd_ctl_elem_info *uinfo) |
Clemens Ladisch | 9bcf655 | 2005-08-10 10:21:43 +0200 | [diff] [blame] | 1727 | { |
| 1728 | uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; |
| 1729 | uinfo->count = 2; |
| 1730 | uinfo->value.integer.min = 0; |
| 1731 | uinfo->value.integer.max = 0x8000; |
| 1732 | return 0; |
| 1733 | } |
| 1734 | |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 1735 | static int snd_ymfpci_pcm_vol_get(struct snd_kcontrol *kcontrol, |
| 1736 | struct snd_ctl_elem_value *ucontrol) |
Clemens Ladisch | 9bcf655 | 2005-08-10 10:21:43 +0200 | [diff] [blame] | 1737 | { |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 1738 | struct snd_ymfpci *chip = snd_kcontrol_chip(kcontrol); |
Clemens Ladisch | 9bcf655 | 2005-08-10 10:21:43 +0200 | [diff] [blame] | 1739 | unsigned int subs = kcontrol->id.subdevice; |
| 1740 | |
| 1741 | ucontrol->value.integer.value[0] = chip->pcm_mixer[subs].left; |
| 1742 | ucontrol->value.integer.value[1] = chip->pcm_mixer[subs].right; |
| 1743 | return 0; |
| 1744 | } |
| 1745 | |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 1746 | static int snd_ymfpci_pcm_vol_put(struct snd_kcontrol *kcontrol, |
| 1747 | struct snd_ctl_elem_value *ucontrol) |
Clemens Ladisch | 9bcf655 | 2005-08-10 10:21:43 +0200 | [diff] [blame] | 1748 | { |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 1749 | struct snd_ymfpci *chip = snd_kcontrol_chip(kcontrol); |
Clemens Ladisch | 9bcf655 | 2005-08-10 10:21:43 +0200 | [diff] [blame] | 1750 | unsigned int subs = kcontrol->id.subdevice; |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 1751 | struct snd_pcm_substream *substream; |
Clemens Ladisch | 9bcf655 | 2005-08-10 10:21:43 +0200 | [diff] [blame] | 1752 | unsigned long flags; |
| 1753 | |
| 1754 | if (ucontrol->value.integer.value[0] != chip->pcm_mixer[subs].left || |
| 1755 | ucontrol->value.integer.value[1] != chip->pcm_mixer[subs].right) { |
| 1756 | chip->pcm_mixer[subs].left = ucontrol->value.integer.value[0]; |
| 1757 | chip->pcm_mixer[subs].right = ucontrol->value.integer.value[1]; |
Takashi Iwai | 4e98d6a | 2007-11-15 15:58:13 +0100 | [diff] [blame] | 1758 | if (chip->pcm_mixer[subs].left > 0x8000) |
| 1759 | chip->pcm_mixer[subs].left = 0x8000; |
| 1760 | if (chip->pcm_mixer[subs].right > 0x8000) |
| 1761 | chip->pcm_mixer[subs].right = 0x8000; |
Clemens Ladisch | 9bcf655 | 2005-08-10 10:21:43 +0200 | [diff] [blame] | 1762 | |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 1763 | substream = (struct snd_pcm_substream *)kcontrol->private_value; |
Clemens Ladisch | 9bcf655 | 2005-08-10 10:21:43 +0200 | [diff] [blame] | 1764 | spin_lock_irqsave(&chip->voice_lock, flags); |
| 1765 | if (substream->runtime && substream->runtime->private_data) { |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 1766 | struct snd_ymfpci_pcm *ypcm = substream->runtime->private_data; |
Teru KAMOGASHIRA | 9ed1261 | 2006-12-04 18:03:53 +0100 | [diff] [blame] | 1767 | if (!ypcm->use_441_slot) |
| 1768 | ypcm->update_pcm_vol = 2; |
Clemens Ladisch | 9bcf655 | 2005-08-10 10:21:43 +0200 | [diff] [blame] | 1769 | } |
| 1770 | spin_unlock_irqrestore(&chip->voice_lock, flags); |
| 1771 | return 1; |
| 1772 | } |
| 1773 | return 0; |
| 1774 | } |
| 1775 | |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 1776 | static struct snd_kcontrol_new snd_ymfpci_pcm_volume __devinitdata = { |
Clemens Ladisch | 9bcf655 | 2005-08-10 10:21:43 +0200 | [diff] [blame] | 1777 | .iface = SNDRV_CTL_ELEM_IFACE_PCM, |
| 1778 | .name = "PCM Playback Volume", |
| 1779 | .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | |
| 1780 | SNDRV_CTL_ELEM_ACCESS_INACTIVE, |
| 1781 | .info = snd_ymfpci_pcm_vol_info, |
| 1782 | .get = snd_ymfpci_pcm_vol_get, |
| 1783 | .put = snd_ymfpci_pcm_vol_put, |
| 1784 | }; |
| 1785 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1786 | |
| 1787 | /* |
| 1788 | * Mixer routines |
| 1789 | */ |
| 1790 | |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 1791 | static void snd_ymfpci_mixer_free_ac97_bus(struct snd_ac97_bus *bus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1792 | { |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 1793 | struct snd_ymfpci *chip = bus->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1794 | chip->ac97_bus = NULL; |
| 1795 | } |
| 1796 | |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 1797 | static void snd_ymfpci_mixer_free_ac97(struct snd_ac97 *ac97) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1798 | { |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 1799 | struct snd_ymfpci *chip = ac97->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1800 | chip->ac97 = NULL; |
| 1801 | } |
| 1802 | |
Glen Masgai | d930126 | 2006-10-10 09:27:19 +0200 | [diff] [blame] | 1803 | int __devinit snd_ymfpci_mixer(struct snd_ymfpci *chip, int rear_switch) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1804 | { |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 1805 | struct snd_ac97_template ac97; |
| 1806 | struct snd_kcontrol *kctl; |
| 1807 | struct snd_pcm_substream *substream; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1808 | unsigned int idx; |
| 1809 | int err; |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 1810 | static struct snd_ac97_bus_ops ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1811 | .write = snd_ymfpci_codec_write, |
| 1812 | .read = snd_ymfpci_codec_read, |
| 1813 | }; |
| 1814 | |
| 1815 | if ((err = snd_ac97_bus(chip->card, 0, &ops, chip, &chip->ac97_bus)) < 0) |
| 1816 | return err; |
| 1817 | chip->ac97_bus->private_free = snd_ymfpci_mixer_free_ac97_bus; |
| 1818 | chip->ac97_bus->no_vra = 1; /* YMFPCI doesn't need VRA */ |
| 1819 | |
| 1820 | memset(&ac97, 0, sizeof(ac97)); |
| 1821 | ac97.private_data = chip; |
| 1822 | ac97.private_free = snd_ymfpci_mixer_free_ac97; |
| 1823 | if ((err = snd_ac97_mixer(chip->ac97_bus, &ac97, &chip->ac97)) < 0) |
| 1824 | return err; |
| 1825 | |
| 1826 | /* to be sure */ |
| 1827 | snd_ac97_update_bits(chip->ac97, AC97_EXTENDED_STATUS, |
| 1828 | AC97_EA_VRA|AC97_EA_VRM, 0); |
| 1829 | |
| 1830 | for (idx = 0; idx < ARRAY_SIZE(snd_ymfpci_controls); idx++) { |
| 1831 | if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_ymfpci_controls[idx], chip))) < 0) |
| 1832 | return err; |
| 1833 | } |
| 1834 | |
| 1835 | /* add S/PDIF control */ |
Takashi Iwai | da3cec3 | 2008-08-08 17:12:14 +0200 | [diff] [blame] | 1836 | if (snd_BUG_ON(!chip->pcm_spdif)) |
| 1837 | return -ENXIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1838 | if ((err = snd_ctl_add(chip->card, kctl = snd_ctl_new1(&snd_ymfpci_spdif_default, chip))) < 0) |
| 1839 | return err; |
| 1840 | kctl->id.device = chip->pcm_spdif->device; |
| 1841 | if ((err = snd_ctl_add(chip->card, kctl = snd_ctl_new1(&snd_ymfpci_spdif_mask, chip))) < 0) |
| 1842 | return err; |
| 1843 | kctl->id.device = chip->pcm_spdif->device; |
| 1844 | if ((err = snd_ctl_add(chip->card, kctl = snd_ctl_new1(&snd_ymfpci_spdif_stream, chip))) < 0) |
| 1845 | return err; |
| 1846 | kctl->id.device = chip->pcm_spdif->device; |
| 1847 | chip->spdif_pcm_ctl = kctl; |
| 1848 | |
| 1849 | /* direct recording source */ |
| 1850 | if (chip->device_id == PCI_DEVICE_ID_YAMAHA_754 && |
| 1851 | (err = snd_ctl_add(chip->card, kctl = snd_ctl_new1(&snd_ymfpci_drec_source, chip))) < 0) |
| 1852 | return err; |
| 1853 | |
| 1854 | /* |
| 1855 | * shared rear/line-in |
| 1856 | */ |
| 1857 | if (rear_switch) { |
| 1858 | if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_ymfpci_rear_shared, chip))) < 0) |
| 1859 | return err; |
| 1860 | } |
| 1861 | |
Clemens Ladisch | 9bcf655 | 2005-08-10 10:21:43 +0200 | [diff] [blame] | 1862 | /* per-voice volume */ |
| 1863 | substream = chip->pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream; |
| 1864 | for (idx = 0; idx < 32; ++idx) { |
| 1865 | kctl = snd_ctl_new1(&snd_ymfpci_pcm_volume, chip); |
| 1866 | if (!kctl) |
| 1867 | return -ENOMEM; |
| 1868 | kctl->id.device = chip->pcm->device; |
| 1869 | kctl->id.subdevice = idx; |
| 1870 | kctl->private_value = (unsigned long)substream; |
| 1871 | if ((err = snd_ctl_add(chip->card, kctl)) < 0) |
| 1872 | return err; |
| 1873 | chip->pcm_mixer[idx].left = 0x8000; |
| 1874 | chip->pcm_mixer[idx].right = 0x8000; |
| 1875 | chip->pcm_mixer[idx].ctl = kctl; |
| 1876 | substream = substream->next; |
| 1877 | } |
| 1878 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1879 | return 0; |
| 1880 | } |
| 1881 | |
| 1882 | |
| 1883 | /* |
| 1884 | * timer |
| 1885 | */ |
| 1886 | |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 1887 | static int snd_ymfpci_timer_start(struct snd_timer *timer) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1888 | { |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 1889 | struct snd_ymfpci *chip; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1890 | unsigned long flags; |
| 1891 | unsigned int count; |
| 1892 | |
| 1893 | chip = snd_timer_chip(timer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1894 | spin_lock_irqsave(&chip->reg_lock, flags); |
Clemens Ladisch | 6e2efaa | 2009-08-10 10:06:53 +0200 | [diff] [blame] | 1895 | if (timer->sticks > 1) { |
| 1896 | chip->timer_ticks = timer->sticks; |
| 1897 | count = timer->sticks - 1; |
| 1898 | } else { |
| 1899 | /* |
| 1900 | * Divisor 1 is not allowed; fake it by using divisor 2 and |
| 1901 | * counting two ticks for each interrupt. |
| 1902 | */ |
| 1903 | chip->timer_ticks = 2; |
| 1904 | count = 2 - 1; |
| 1905 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1906 | snd_ymfpci_writew(chip, YDSXGR_TIMERCOUNT, count); |
| 1907 | snd_ymfpci_writeb(chip, YDSXGR_TIMERCTRL, 0x03); |
| 1908 | spin_unlock_irqrestore(&chip->reg_lock, flags); |
| 1909 | return 0; |
| 1910 | } |
| 1911 | |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 1912 | static int snd_ymfpci_timer_stop(struct snd_timer *timer) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1913 | { |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 1914 | struct snd_ymfpci *chip; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1915 | unsigned long flags; |
| 1916 | |
| 1917 | chip = snd_timer_chip(timer); |
| 1918 | spin_lock_irqsave(&chip->reg_lock, flags); |
| 1919 | snd_ymfpci_writeb(chip, YDSXGR_TIMERCTRL, 0x00); |
| 1920 | spin_unlock_irqrestore(&chip->reg_lock, flags); |
| 1921 | return 0; |
| 1922 | } |
| 1923 | |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 1924 | static int snd_ymfpci_timer_precise_resolution(struct snd_timer *timer, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1925 | unsigned long *num, unsigned long *den) |
| 1926 | { |
| 1927 | *num = 1; |
Clemens Ladisch | 6e2efaa | 2009-08-10 10:06:53 +0200 | [diff] [blame] | 1928 | *den = 96000; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1929 | return 0; |
| 1930 | } |
| 1931 | |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 1932 | static struct snd_timer_hardware snd_ymfpci_timer_hw = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1933 | .flags = SNDRV_TIMER_HW_AUTO, |
Clemens Ladisch | 6e2efaa | 2009-08-10 10:06:53 +0200 | [diff] [blame] | 1934 | .resolution = 10417, /* 1 / 96 kHz = 10.41666...us */ |
| 1935 | .ticks = 0x10000, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1936 | .start = snd_ymfpci_timer_start, |
| 1937 | .stop = snd_ymfpci_timer_stop, |
| 1938 | .precise_resolution = snd_ymfpci_timer_precise_resolution, |
| 1939 | }; |
| 1940 | |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 1941 | int __devinit snd_ymfpci_timer(struct snd_ymfpci *chip, int device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1942 | { |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 1943 | struct snd_timer *timer = NULL; |
| 1944 | struct snd_timer_id tid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1945 | int err; |
| 1946 | |
| 1947 | tid.dev_class = SNDRV_TIMER_CLASS_CARD; |
| 1948 | tid.dev_sclass = SNDRV_TIMER_SCLASS_NONE; |
| 1949 | tid.card = chip->card->number; |
| 1950 | tid.device = device; |
| 1951 | tid.subdevice = 0; |
| 1952 | if ((err = snd_timer_new(chip->card, "YMFPCI", &tid, &timer)) >= 0) { |
| 1953 | strcpy(timer->name, "YMFPCI timer"); |
| 1954 | timer->private_data = chip; |
| 1955 | timer->hw = snd_ymfpci_timer_hw; |
| 1956 | } |
| 1957 | chip->timer = timer; |
| 1958 | return err; |
| 1959 | } |
| 1960 | |
| 1961 | |
| 1962 | /* |
| 1963 | * proc interface |
| 1964 | */ |
| 1965 | |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 1966 | static void snd_ymfpci_proc_read(struct snd_info_entry *entry, |
| 1967 | struct snd_info_buffer *buffer) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1968 | { |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 1969 | struct snd_ymfpci *chip = entry->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1970 | int i; |
| 1971 | |
| 1972 | snd_iprintf(buffer, "YMFPCI\n\n"); |
| 1973 | for (i = 0; i <= YDSXGR_WORKBASE; i += 4) |
| 1974 | snd_iprintf(buffer, "%04x: %04x\n", i, snd_ymfpci_readl(chip, i)); |
| 1975 | } |
| 1976 | |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 1977 | static int __devinit snd_ymfpci_proc_init(struct snd_card *card, struct snd_ymfpci *chip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1978 | { |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 1979 | struct snd_info_entry *entry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1980 | |
| 1981 | if (! snd_card_proc_new(card, "ymfpci", &entry)) |
Takashi Iwai | bf85020 | 2006-04-28 15:13:41 +0200 | [diff] [blame] | 1982 | snd_info_set_text_ops(entry, chip, snd_ymfpci_proc_read); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1983 | return 0; |
| 1984 | } |
| 1985 | |
| 1986 | /* |
| 1987 | * initialization routines |
| 1988 | */ |
| 1989 | |
| 1990 | static void snd_ymfpci_aclink_reset(struct pci_dev * pci) |
| 1991 | { |
| 1992 | u8 cmd; |
| 1993 | |
| 1994 | pci_read_config_byte(pci, PCIR_DSXG_CTRL, &cmd); |
| 1995 | #if 0 // force to reset |
| 1996 | if (cmd & 0x03) { |
| 1997 | #endif |
| 1998 | pci_write_config_byte(pci, PCIR_DSXG_CTRL, cmd & 0xfc); |
| 1999 | pci_write_config_byte(pci, PCIR_DSXG_CTRL, cmd | 0x03); |
| 2000 | pci_write_config_byte(pci, PCIR_DSXG_CTRL, cmd & 0xfc); |
| 2001 | pci_write_config_word(pci, PCIR_DSXG_PWRCTRL1, 0); |
| 2002 | pci_write_config_word(pci, PCIR_DSXG_PWRCTRL2, 0); |
| 2003 | #if 0 |
| 2004 | } |
| 2005 | #endif |
| 2006 | } |
| 2007 | |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 2008 | static void snd_ymfpci_enable_dsp(struct snd_ymfpci *chip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2009 | { |
| 2010 | snd_ymfpci_writel(chip, YDSXGR_CONFIG, 0x00000001); |
| 2011 | } |
| 2012 | |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 2013 | static void snd_ymfpci_disable_dsp(struct snd_ymfpci *chip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2014 | { |
| 2015 | u32 val; |
| 2016 | int timeout = 1000; |
| 2017 | |
| 2018 | val = snd_ymfpci_readl(chip, YDSXGR_CONFIG); |
| 2019 | if (val) |
| 2020 | snd_ymfpci_writel(chip, YDSXGR_CONFIG, 0x00000000); |
| 2021 | while (timeout-- > 0) { |
| 2022 | val = snd_ymfpci_readl(chip, YDSXGR_STATUS); |
| 2023 | if ((val & 0x00000002) == 0) |
| 2024 | break; |
| 2025 | } |
| 2026 | } |
| 2027 | |
Clemens Ladisch | 102fa90 | 2006-10-11 12:05:59 +0200 | [diff] [blame] | 2028 | static int snd_ymfpci_request_firmware(struct snd_ymfpci *chip) |
| 2029 | { |
| 2030 | int err, is_1e; |
| 2031 | const char *name; |
| 2032 | |
| 2033 | err = request_firmware(&chip->dsp_microcode, "yamaha/ds1_dsp.fw", |
| 2034 | &chip->pci->dev); |
| 2035 | if (err >= 0) { |
David Woodhouse | b82a82d | 2008-05-29 14:40:00 +0300 | [diff] [blame] | 2036 | if (chip->dsp_microcode->size != YDSXG_DSPLENGTH) { |
Clemens Ladisch | 102fa90 | 2006-10-11 12:05:59 +0200 | [diff] [blame] | 2037 | snd_printk(KERN_ERR "DSP microcode has wrong size\n"); |
| 2038 | err = -EINVAL; |
| 2039 | } |
| 2040 | } |
Takashi Iwai | b7dd2b3 | 2007-04-26 14:13:44 +0200 | [diff] [blame] | 2041 | if (err < 0) |
Clemens Ladisch | 102fa90 | 2006-10-11 12:05:59 +0200 | [diff] [blame] | 2042 | return err; |
Clemens Ladisch | 102fa90 | 2006-10-11 12:05:59 +0200 | [diff] [blame] | 2043 | is_1e = chip->device_id == PCI_DEVICE_ID_YAMAHA_724F || |
| 2044 | chip->device_id == PCI_DEVICE_ID_YAMAHA_740C || |
| 2045 | chip->device_id == PCI_DEVICE_ID_YAMAHA_744 || |
| 2046 | chip->device_id == PCI_DEVICE_ID_YAMAHA_754; |
| 2047 | name = is_1e ? "yamaha/ds1e_ctrl.fw" : "yamaha/ds1_ctrl.fw"; |
| 2048 | err = request_firmware(&chip->controller_microcode, name, |
| 2049 | &chip->pci->dev); |
| 2050 | if (err >= 0) { |
David Woodhouse | b82a82d | 2008-05-29 14:40:00 +0300 | [diff] [blame] | 2051 | if (chip->controller_microcode->size != YDSXG_CTRLLENGTH) { |
Clemens Ladisch | 102fa90 | 2006-10-11 12:05:59 +0200 | [diff] [blame] | 2052 | snd_printk(KERN_ERR "controller microcode" |
| 2053 | " has wrong size\n"); |
| 2054 | err = -EINVAL; |
| 2055 | } |
| 2056 | } |
Takashi Iwai | b7dd2b3 | 2007-04-26 14:13:44 +0200 | [diff] [blame] | 2057 | if (err < 0) |
Clemens Ladisch | 102fa90 | 2006-10-11 12:05:59 +0200 | [diff] [blame] | 2058 | return err; |
Clemens Ladisch | 102fa90 | 2006-10-11 12:05:59 +0200 | [diff] [blame] | 2059 | return 0; |
| 2060 | } |
Clemens Ladisch | 7e0af29 | 2007-05-03 17:59:54 +0200 | [diff] [blame] | 2061 | |
| 2062 | MODULE_FIRMWARE("yamaha/ds1_dsp.fw"); |
| 2063 | MODULE_FIRMWARE("yamaha/ds1_ctrl.fw"); |
| 2064 | MODULE_FIRMWARE("yamaha/ds1e_ctrl.fw"); |
| 2065 | |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 2066 | static void snd_ymfpci_download_image(struct snd_ymfpci *chip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2067 | { |
| 2068 | int i; |
| 2069 | u16 ctrl; |
David Woodhouse | b82a82d | 2008-05-29 14:40:00 +0300 | [diff] [blame] | 2070 | const __le32 *inst; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2071 | |
| 2072 | snd_ymfpci_writel(chip, YDSXGR_NATIVEDACOUTVOL, 0x00000000); |
| 2073 | snd_ymfpci_disable_dsp(chip); |
| 2074 | snd_ymfpci_writel(chip, YDSXGR_MODE, 0x00010000); |
| 2075 | snd_ymfpci_writel(chip, YDSXGR_MODE, 0x00000000); |
| 2076 | snd_ymfpci_writel(chip, YDSXGR_MAPOFREC, 0x00000000); |
| 2077 | snd_ymfpci_writel(chip, YDSXGR_MAPOFEFFECT, 0x00000000); |
| 2078 | snd_ymfpci_writel(chip, YDSXGR_PLAYCTRLBASE, 0x00000000); |
| 2079 | snd_ymfpci_writel(chip, YDSXGR_RECCTRLBASE, 0x00000000); |
| 2080 | snd_ymfpci_writel(chip, YDSXGR_EFFCTRLBASE, 0x00000000); |
| 2081 | ctrl = snd_ymfpci_readw(chip, YDSXGR_GLOBALCTRL); |
| 2082 | snd_ymfpci_writew(chip, YDSXGR_GLOBALCTRL, ctrl & ~0x0007); |
| 2083 | |
| 2084 | /* setup DSP instruction code */ |
David Woodhouse | b82a82d | 2008-05-29 14:40:00 +0300 | [diff] [blame] | 2085 | inst = (const __le32 *)chip->dsp_microcode->data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2086 | for (i = 0; i < YDSXG_DSPLENGTH / 4; i++) |
David Woodhouse | b82a82d | 2008-05-29 14:40:00 +0300 | [diff] [blame] | 2087 | snd_ymfpci_writel(chip, YDSXGR_DSPINSTRAM + (i << 2), |
| 2088 | le32_to_cpu(inst[i])); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2089 | |
| 2090 | /* setup control instruction code */ |
David Woodhouse | b82a82d | 2008-05-29 14:40:00 +0300 | [diff] [blame] | 2091 | inst = (const __le32 *)chip->controller_microcode->data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2092 | for (i = 0; i < YDSXG_CTRLLENGTH / 4; i++) |
David Woodhouse | b82a82d | 2008-05-29 14:40:00 +0300 | [diff] [blame] | 2093 | snd_ymfpci_writel(chip, YDSXGR_CTRLINSTRAM + (i << 2), |
| 2094 | le32_to_cpu(inst[i])); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2095 | |
| 2096 | snd_ymfpci_enable_dsp(chip); |
| 2097 | } |
| 2098 | |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 2099 | static int __devinit snd_ymfpci_memalloc(struct snd_ymfpci *chip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2100 | { |
| 2101 | long size, playback_ctrl_size; |
| 2102 | int voice, bank, reg; |
| 2103 | u8 *ptr; |
| 2104 | dma_addr_t ptr_addr; |
| 2105 | |
| 2106 | playback_ctrl_size = 4 + 4 * YDSXG_PLAYBACK_VOICES; |
| 2107 | chip->bank_size_playback = snd_ymfpci_readl(chip, YDSXGR_PLAYCTRLSIZE) << 2; |
| 2108 | chip->bank_size_capture = snd_ymfpci_readl(chip, YDSXGR_RECCTRLSIZE) << 2; |
| 2109 | chip->bank_size_effect = snd_ymfpci_readl(chip, YDSXGR_EFFCTRLSIZE) << 2; |
| 2110 | chip->work_size = YDSXG_DEFAULT_WORK_SIZE; |
| 2111 | |
Clemens Ladisch | 7ab3992 | 2006-10-09 08:13:32 +0200 | [diff] [blame] | 2112 | size = ALIGN(playback_ctrl_size, 0x100) + |
| 2113 | ALIGN(chip->bank_size_playback * 2 * YDSXG_PLAYBACK_VOICES, 0x100) + |
| 2114 | ALIGN(chip->bank_size_capture * 2 * YDSXG_CAPTURE_VOICES, 0x100) + |
| 2115 | ALIGN(chip->bank_size_effect * 2 * YDSXG_EFFECT_VOICES, 0x100) + |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2116 | chip->work_size; |
| 2117 | /* work_ptr must be aligned to 256 bytes, but it's already |
| 2118 | covered with the kernel page allocation mechanism */ |
| 2119 | if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(chip->pci), |
| 2120 | size, &chip->work_ptr) < 0) |
| 2121 | return -ENOMEM; |
| 2122 | ptr = chip->work_ptr.area; |
| 2123 | ptr_addr = chip->work_ptr.addr; |
| 2124 | memset(ptr, 0, size); /* for sure */ |
| 2125 | |
| 2126 | chip->bank_base_playback = ptr; |
| 2127 | chip->bank_base_playback_addr = ptr_addr; |
| 2128 | chip->ctrl_playback = (u32 *)ptr; |
| 2129 | chip->ctrl_playback[0] = cpu_to_le32(YDSXG_PLAYBACK_VOICES); |
Clemens Ladisch | 7ab3992 | 2006-10-09 08:13:32 +0200 | [diff] [blame] | 2130 | ptr += ALIGN(playback_ctrl_size, 0x100); |
| 2131 | ptr_addr += ALIGN(playback_ctrl_size, 0x100); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2132 | for (voice = 0; voice < YDSXG_PLAYBACK_VOICES; voice++) { |
| 2133 | chip->voices[voice].number = voice; |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 2134 | chip->voices[voice].bank = (struct snd_ymfpci_playback_bank *)ptr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2135 | chip->voices[voice].bank_addr = ptr_addr; |
| 2136 | for (bank = 0; bank < 2; bank++) { |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 2137 | chip->bank_playback[voice][bank] = (struct snd_ymfpci_playback_bank *)ptr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2138 | ptr += chip->bank_size_playback; |
| 2139 | ptr_addr += chip->bank_size_playback; |
| 2140 | } |
| 2141 | } |
Clemens Ladisch | 7ab3992 | 2006-10-09 08:13:32 +0200 | [diff] [blame] | 2142 | ptr = (char *)ALIGN((unsigned long)ptr, 0x100); |
| 2143 | ptr_addr = ALIGN(ptr_addr, 0x100); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2144 | chip->bank_base_capture = ptr; |
| 2145 | chip->bank_base_capture_addr = ptr_addr; |
| 2146 | for (voice = 0; voice < YDSXG_CAPTURE_VOICES; voice++) |
| 2147 | for (bank = 0; bank < 2; bank++) { |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 2148 | chip->bank_capture[voice][bank] = (struct snd_ymfpci_capture_bank *)ptr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2149 | ptr += chip->bank_size_capture; |
| 2150 | ptr_addr += chip->bank_size_capture; |
| 2151 | } |
Clemens Ladisch | 7ab3992 | 2006-10-09 08:13:32 +0200 | [diff] [blame] | 2152 | ptr = (char *)ALIGN((unsigned long)ptr, 0x100); |
| 2153 | ptr_addr = ALIGN(ptr_addr, 0x100); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2154 | chip->bank_base_effect = ptr; |
| 2155 | chip->bank_base_effect_addr = ptr_addr; |
| 2156 | for (voice = 0; voice < YDSXG_EFFECT_VOICES; voice++) |
| 2157 | for (bank = 0; bank < 2; bank++) { |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 2158 | chip->bank_effect[voice][bank] = (struct snd_ymfpci_effect_bank *)ptr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2159 | ptr += chip->bank_size_effect; |
| 2160 | ptr_addr += chip->bank_size_effect; |
| 2161 | } |
Clemens Ladisch | 7ab3992 | 2006-10-09 08:13:32 +0200 | [diff] [blame] | 2162 | ptr = (char *)ALIGN((unsigned long)ptr, 0x100); |
| 2163 | ptr_addr = ALIGN(ptr_addr, 0x100); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2164 | chip->work_base = ptr; |
| 2165 | chip->work_base_addr = ptr_addr; |
| 2166 | |
Takashi Iwai | da3cec3 | 2008-08-08 17:12:14 +0200 | [diff] [blame] | 2167 | snd_BUG_ON(ptr + chip->work_size != |
| 2168 | chip->work_ptr.area + chip->work_ptr.bytes); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2169 | |
| 2170 | snd_ymfpci_writel(chip, YDSXGR_PLAYCTRLBASE, chip->bank_base_playback_addr); |
| 2171 | snd_ymfpci_writel(chip, YDSXGR_RECCTRLBASE, chip->bank_base_capture_addr); |
| 2172 | snd_ymfpci_writel(chip, YDSXGR_EFFCTRLBASE, chip->bank_base_effect_addr); |
| 2173 | snd_ymfpci_writel(chip, YDSXGR_WORKBASE, chip->work_base_addr); |
| 2174 | snd_ymfpci_writel(chip, YDSXGR_WORKSIZE, chip->work_size >> 2); |
| 2175 | |
| 2176 | /* S/PDIF output initialization */ |
| 2177 | chip->spdif_bits = chip->spdif_pcm_bits = SNDRV_PCM_DEFAULT_CON_SPDIF & 0xffff; |
| 2178 | snd_ymfpci_writew(chip, YDSXGR_SPDIFOUTCTRL, 0); |
| 2179 | snd_ymfpci_writew(chip, YDSXGR_SPDIFOUTSTATUS, chip->spdif_bits); |
| 2180 | |
| 2181 | /* S/PDIF input initialization */ |
| 2182 | snd_ymfpci_writew(chip, YDSXGR_SPDIFINCTRL, 0); |
| 2183 | |
| 2184 | /* digital mixer setup */ |
| 2185 | for (reg = 0x80; reg < 0xc0; reg += 4) |
| 2186 | snd_ymfpci_writel(chip, reg, 0); |
| 2187 | snd_ymfpci_writel(chip, YDSXGR_NATIVEDACOUTVOL, 0x3fff3fff); |
Takashi Iwai | 4a3b698 | 2008-06-25 17:17:00 +0200 | [diff] [blame] | 2188 | snd_ymfpci_writel(chip, YDSXGR_BUF441OUTVOL, 0x3fff3fff); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2189 | snd_ymfpci_writel(chip, YDSXGR_ZVOUTVOL, 0x3fff3fff); |
| 2190 | snd_ymfpci_writel(chip, YDSXGR_SPDIFOUTVOL, 0x3fff3fff); |
| 2191 | snd_ymfpci_writel(chip, YDSXGR_NATIVEADCINVOL, 0x3fff3fff); |
| 2192 | snd_ymfpci_writel(chip, YDSXGR_NATIVEDACINVOL, 0x3fff3fff); |
| 2193 | snd_ymfpci_writel(chip, YDSXGR_PRIADCLOOPVOL, 0x3fff3fff); |
| 2194 | snd_ymfpci_writel(chip, YDSXGR_LEGACYOUTVOL, 0x3fff3fff); |
| 2195 | |
| 2196 | return 0; |
| 2197 | } |
| 2198 | |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 2199 | static int snd_ymfpci_free(struct snd_ymfpci *chip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2200 | { |
| 2201 | u16 ctrl; |
| 2202 | |
Takashi Iwai | da3cec3 | 2008-08-08 17:12:14 +0200 | [diff] [blame] | 2203 | if (snd_BUG_ON(!chip)) |
| 2204 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2205 | |
| 2206 | if (chip->res_reg_area) { /* don't touch busy hardware */ |
| 2207 | snd_ymfpci_writel(chip, YDSXGR_NATIVEDACOUTVOL, 0); |
| 2208 | snd_ymfpci_writel(chip, YDSXGR_BUF441OUTVOL, 0); |
| 2209 | snd_ymfpci_writel(chip, YDSXGR_LEGACYOUTVOL, 0); |
| 2210 | snd_ymfpci_writel(chip, YDSXGR_STATUS, ~0); |
| 2211 | snd_ymfpci_disable_dsp(chip); |
| 2212 | snd_ymfpci_writel(chip, YDSXGR_PLAYCTRLBASE, 0); |
| 2213 | snd_ymfpci_writel(chip, YDSXGR_RECCTRLBASE, 0); |
| 2214 | snd_ymfpci_writel(chip, YDSXGR_EFFCTRLBASE, 0); |
| 2215 | snd_ymfpci_writel(chip, YDSXGR_WORKBASE, 0); |
| 2216 | snd_ymfpci_writel(chip, YDSXGR_WORKSIZE, 0); |
| 2217 | ctrl = snd_ymfpci_readw(chip, YDSXGR_GLOBALCTRL); |
| 2218 | snd_ymfpci_writew(chip, YDSXGR_GLOBALCTRL, ctrl & ~0x0007); |
| 2219 | } |
| 2220 | |
| 2221 | snd_ymfpci_ac3_done(chip); |
| 2222 | |
| 2223 | /* Set PCI device to D3 state */ |
| 2224 | #if 0 |
| 2225 | /* FIXME: temporarily disabled, otherwise we cannot fire up |
| 2226 | * the chip again unless reboot. ACPI bug? |
| 2227 | */ |
| 2228 | pci_set_power_state(chip->pci, 3); |
| 2229 | #endif |
| 2230 | |
| 2231 | #ifdef CONFIG_PM |
| 2232 | vfree(chip->saved_regs); |
| 2233 | #endif |
Takashi Iwai | 95866d38 | 2008-03-22 10:11:08 +0100 | [diff] [blame] | 2234 | if (chip->irq >= 0) |
| 2235 | free_irq(chip->irq, chip); |
Takashi Iwai | b1d5776 | 2005-10-10 11:56:31 +0200 | [diff] [blame] | 2236 | release_and_free_resource(chip->mpu_res); |
| 2237 | release_and_free_resource(chip->fm_res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2238 | snd_ymfpci_free_gameport(chip); |
| 2239 | if (chip->reg_area_virt) |
| 2240 | iounmap(chip->reg_area_virt); |
| 2241 | if (chip->work_ptr.area) |
| 2242 | snd_dma_free_pages(&chip->work_ptr); |
| 2243 | |
Takashi Iwai | b1d5776 | 2005-10-10 11:56:31 +0200 | [diff] [blame] | 2244 | release_and_free_resource(chip->res_reg_area); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2245 | |
| 2246 | pci_write_config_word(chip->pci, 0x40, chip->old_legacy_ctrl); |
| 2247 | |
| 2248 | pci_disable_device(chip->pci); |
Takashi Iwai | b7dd2b3 | 2007-04-26 14:13:44 +0200 | [diff] [blame] | 2249 | release_firmware(chip->dsp_microcode); |
| 2250 | release_firmware(chip->controller_microcode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2251 | kfree(chip); |
| 2252 | return 0; |
| 2253 | } |
| 2254 | |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 2255 | static int snd_ymfpci_dev_free(struct snd_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2256 | { |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 2257 | struct snd_ymfpci *chip = device->device_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2258 | return snd_ymfpci_free(chip); |
| 2259 | } |
| 2260 | |
| 2261 | #ifdef CONFIG_PM |
| 2262 | static int saved_regs_index[] = { |
| 2263 | /* spdif */ |
| 2264 | YDSXGR_SPDIFOUTCTRL, |
| 2265 | YDSXGR_SPDIFOUTSTATUS, |
| 2266 | YDSXGR_SPDIFINCTRL, |
| 2267 | /* volumes */ |
| 2268 | YDSXGR_PRIADCLOOPVOL, |
| 2269 | YDSXGR_NATIVEDACINVOL, |
| 2270 | YDSXGR_NATIVEDACOUTVOL, |
Teru KAMOGASHIRA | 9ed1261 | 2006-12-04 18:03:53 +0100 | [diff] [blame] | 2271 | YDSXGR_BUF441OUTVOL, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2272 | YDSXGR_NATIVEADCINVOL, |
| 2273 | YDSXGR_SPDIFLOOPVOL, |
| 2274 | YDSXGR_SPDIFOUTVOL, |
| 2275 | YDSXGR_ZVOUTVOL, |
| 2276 | YDSXGR_LEGACYOUTVOL, |
| 2277 | /* address bases */ |
| 2278 | YDSXGR_PLAYCTRLBASE, |
| 2279 | YDSXGR_RECCTRLBASE, |
| 2280 | YDSXGR_EFFCTRLBASE, |
| 2281 | YDSXGR_WORKBASE, |
| 2282 | /* capture set up */ |
| 2283 | YDSXGR_MAPOFREC, |
| 2284 | YDSXGR_RECFORMAT, |
| 2285 | YDSXGR_RECSLOTSR, |
| 2286 | YDSXGR_ADCFORMAT, |
| 2287 | YDSXGR_ADCSLOTSR, |
| 2288 | }; |
| 2289 | #define YDSXGR_NUM_SAVED_REGS ARRAY_SIZE(saved_regs_index) |
| 2290 | |
Takashi Iwai | ded4623 | 2005-11-17 16:09:43 +0100 | [diff] [blame] | 2291 | int snd_ymfpci_suspend(struct pci_dev *pci, pm_message_t state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2292 | { |
Takashi Iwai | ded4623 | 2005-11-17 16:09:43 +0100 | [diff] [blame] | 2293 | struct snd_card *card = pci_get_drvdata(pci); |
| 2294 | struct snd_ymfpci *chip = card->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2295 | unsigned int i; |
| 2296 | |
Takashi Iwai | ded4623 | 2005-11-17 16:09:43 +0100 | [diff] [blame] | 2297 | snd_power_change_state(card, SNDRV_CTL_POWER_D3hot); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2298 | snd_pcm_suspend_all(chip->pcm); |
| 2299 | snd_pcm_suspend_all(chip->pcm2); |
| 2300 | snd_pcm_suspend_all(chip->pcm_spdif); |
| 2301 | snd_pcm_suspend_all(chip->pcm_4ch); |
| 2302 | snd_ac97_suspend(chip->ac97); |
| 2303 | for (i = 0; i < YDSXGR_NUM_SAVED_REGS; i++) |
| 2304 | chip->saved_regs[i] = snd_ymfpci_readl(chip, saved_regs_index[i]); |
| 2305 | chip->saved_ydsxgr_mode = snd_ymfpci_readl(chip, YDSXGR_MODE); |
| 2306 | snd_ymfpci_writel(chip, YDSXGR_NATIVEDACOUTVOL, 0); |
Takashi Iwai | 4a3b698 | 2008-06-25 17:17:00 +0200 | [diff] [blame] | 2307 | snd_ymfpci_writel(chip, YDSXGR_BUF441OUTVOL, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2308 | snd_ymfpci_disable_dsp(chip); |
Takashi Iwai | ded4623 | 2005-11-17 16:09:43 +0100 | [diff] [blame] | 2309 | pci_disable_device(pci); |
| 2310 | pci_save_state(pci); |
Takashi Iwai | 30b3539 | 2006-10-11 18:52:53 +0200 | [diff] [blame] | 2311 | pci_set_power_state(pci, pci_choose_state(pci, state)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2312 | return 0; |
| 2313 | } |
| 2314 | |
Takashi Iwai | ded4623 | 2005-11-17 16:09:43 +0100 | [diff] [blame] | 2315 | int snd_ymfpci_resume(struct pci_dev *pci) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2316 | { |
Takashi Iwai | ded4623 | 2005-11-17 16:09:43 +0100 | [diff] [blame] | 2317 | struct snd_card *card = pci_get_drvdata(pci); |
| 2318 | struct snd_ymfpci *chip = card->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2319 | unsigned int i; |
| 2320 | |
Takashi Iwai | 30b3539 | 2006-10-11 18:52:53 +0200 | [diff] [blame] | 2321 | pci_set_power_state(pci, PCI_D0); |
Takashi Iwai | ded4623 | 2005-11-17 16:09:43 +0100 | [diff] [blame] | 2322 | pci_restore_state(pci); |
Takashi Iwai | 30b3539 | 2006-10-11 18:52:53 +0200 | [diff] [blame] | 2323 | if (pci_enable_device(pci) < 0) { |
| 2324 | printk(KERN_ERR "ymfpci: pci_enable_device failed, " |
| 2325 | "disabling device\n"); |
| 2326 | snd_card_disconnect(card); |
| 2327 | return -EIO; |
| 2328 | } |
Takashi Iwai | ded4623 | 2005-11-17 16:09:43 +0100 | [diff] [blame] | 2329 | pci_set_master(pci); |
| 2330 | snd_ymfpci_aclink_reset(pci); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2331 | snd_ymfpci_codec_ready(chip, 0); |
| 2332 | snd_ymfpci_download_image(chip); |
| 2333 | udelay(100); |
| 2334 | |
| 2335 | for (i = 0; i < YDSXGR_NUM_SAVED_REGS; i++) |
| 2336 | snd_ymfpci_writel(chip, saved_regs_index[i], chip->saved_regs[i]); |
| 2337 | |
| 2338 | snd_ac97_resume(chip->ac97); |
| 2339 | |
| 2340 | /* start hw again */ |
| 2341 | if (chip->start_count > 0) { |
| 2342 | spin_lock_irq(&chip->reg_lock); |
| 2343 | snd_ymfpci_writel(chip, YDSXGR_MODE, chip->saved_ydsxgr_mode); |
| 2344 | chip->active_bank = snd_ymfpci_readl(chip, YDSXGR_CTRLSELECT); |
| 2345 | spin_unlock_irq(&chip->reg_lock); |
| 2346 | } |
Takashi Iwai | ded4623 | 2005-11-17 16:09:43 +0100 | [diff] [blame] | 2347 | snd_power_change_state(card, SNDRV_CTL_POWER_D0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2348 | return 0; |
| 2349 | } |
| 2350 | #endif /* CONFIG_PM */ |
| 2351 | |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 2352 | int __devinit snd_ymfpci_create(struct snd_card *card, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2353 | struct pci_dev * pci, |
| 2354 | unsigned short old_legacy_ctrl, |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 2355 | struct snd_ymfpci ** rchip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2356 | { |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 2357 | struct snd_ymfpci *chip; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2358 | int err; |
Takashi Iwai | 208a1b4 | 2005-11-17 14:53:41 +0100 | [diff] [blame] | 2359 | static struct snd_device_ops ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2360 | .dev_free = snd_ymfpci_dev_free, |
| 2361 | }; |
| 2362 | |
| 2363 | *rchip = NULL; |
| 2364 | |
| 2365 | /* enable PCI device */ |
| 2366 | if ((err = pci_enable_device(pci)) < 0) |
| 2367 | return err; |
| 2368 | |
Takashi Iwai | e560d8d | 2005-09-09 14:21:46 +0200 | [diff] [blame] | 2369 | chip = kzalloc(sizeof(*chip), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2370 | if (chip == NULL) { |
| 2371 | pci_disable_device(pci); |
| 2372 | return -ENOMEM; |
| 2373 | } |
| 2374 | chip->old_legacy_ctrl = old_legacy_ctrl; |
| 2375 | spin_lock_init(&chip->reg_lock); |
| 2376 | spin_lock_init(&chip->voice_lock); |
| 2377 | init_waitqueue_head(&chip->interrupt_sleep); |
| 2378 | atomic_set(&chip->interrupt_sleep_count, 0); |
| 2379 | chip->card = card; |
| 2380 | chip->pci = pci; |
| 2381 | chip->irq = -1; |
| 2382 | chip->device_id = pci->device; |
Auke Kok | 44c1013 | 2007-06-08 15:46:36 -0700 | [diff] [blame] | 2383 | chip->rev = pci->revision; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2384 | chip->reg_area_phys = pci_resource_start(pci, 0); |
| 2385 | chip->reg_area_virt = ioremap_nocache(chip->reg_area_phys, 0x8000); |
| 2386 | pci_set_master(pci); |
Teru KAMOGASHIRA | 9ed1261 | 2006-12-04 18:03:53 +0100 | [diff] [blame] | 2387 | chip->src441_used = -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2388 | |
| 2389 | if ((chip->res_reg_area = request_mem_region(chip->reg_area_phys, 0x8000, "YMFPCI")) == NULL) { |
Takashi Iwai | 99b359b | 2005-10-20 18:26:44 +0200 | [diff] [blame] | 2390 | snd_printk(KERN_ERR "unable to grab memory region 0x%lx-0x%lx\n", chip->reg_area_phys, chip->reg_area_phys + 0x8000 - 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2391 | snd_ymfpci_free(chip); |
| 2392 | return -EBUSY; |
| 2393 | } |
Takashi Iwai | 437a5a4 | 2006-11-21 12:14:23 +0100 | [diff] [blame] | 2394 | if (request_irq(pci->irq, snd_ymfpci_interrupt, IRQF_SHARED, |
Takashi Iwai | 934c2b6 | 2011-06-10 16:36:37 +0200 | [diff] [blame] | 2395 | KBUILD_MODNAME, chip)) { |
Takashi Iwai | 99b359b | 2005-10-20 18:26:44 +0200 | [diff] [blame] | 2396 | snd_printk(KERN_ERR "unable to grab IRQ %d\n", pci->irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2397 | snd_ymfpci_free(chip); |
| 2398 | return -EBUSY; |
| 2399 | } |
| 2400 | chip->irq = pci->irq; |
| 2401 | |
| 2402 | snd_ymfpci_aclink_reset(pci); |
| 2403 | if (snd_ymfpci_codec_ready(chip, 0) < 0) { |
| 2404 | snd_ymfpci_free(chip); |
| 2405 | return -EIO; |
| 2406 | } |
| 2407 | |
Clemens Ladisch | 102fa90 | 2006-10-11 12:05:59 +0200 | [diff] [blame] | 2408 | err = snd_ymfpci_request_firmware(chip); |
| 2409 | if (err < 0) { |
| 2410 | snd_printk(KERN_ERR "firmware request failed: %d\n", err); |
| 2411 | snd_ymfpci_free(chip); |
| 2412 | return err; |
| 2413 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2414 | snd_ymfpci_download_image(chip); |
| 2415 | |
| 2416 | udelay(100); /* seems we need a delay after downloading image.. */ |
| 2417 | |
| 2418 | if (snd_ymfpci_memalloc(chip) < 0) { |
| 2419 | snd_ymfpci_free(chip); |
| 2420 | return -EIO; |
| 2421 | } |
| 2422 | |
| 2423 | if ((err = snd_ymfpci_ac3_init(chip)) < 0) { |
| 2424 | snd_ymfpci_free(chip); |
| 2425 | return err; |
| 2426 | } |
| 2427 | |
| 2428 | #ifdef CONFIG_PM |
| 2429 | chip->saved_regs = vmalloc(YDSXGR_NUM_SAVED_REGS * sizeof(u32)); |
| 2430 | if (chip->saved_regs == NULL) { |
| 2431 | snd_ymfpci_free(chip); |
| 2432 | return -ENOMEM; |
| 2433 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2434 | #endif |
| 2435 | |
| 2436 | if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops)) < 0) { |
| 2437 | snd_ymfpci_free(chip); |
| 2438 | return err; |
| 2439 | } |
| 2440 | |
| 2441 | snd_ymfpci_proc_init(card, chip); |
| 2442 | |
| 2443 | snd_card_set_dev(card, &pci->dev); |
| 2444 | |
| 2445 | *rchip = chip; |
| 2446 | return 0; |
| 2447 | } |