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