Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * ALSA driver for RME Digi32, Digi32/8 and Digi32 PRO audio interfaces |
| 3 | * |
| 4 | * Copyright (c) 2002-2004 Martin Langer <martin-langer@gmx.de>, |
| 5 | * Pilo Chambert <pilo.c@wanadoo.fr> |
| 6 | * |
| 7 | * Thanks to : Anders Torger <torger@ludd.luth.se>, |
| 8 | * Henk Hesselink <henk@anda.nl> |
| 9 | * for writing the digi96-driver |
| 10 | * and RME for all informations. |
| 11 | * |
| 12 | * This program is free software; you can redistribute it and/or modify |
| 13 | * it under the terms of the GNU General Public License as published by |
| 14 | * the Free Software Foundation; either version 2 of the License, or |
| 15 | * (at your option) any later version. |
| 16 | * |
| 17 | * This program is distributed in the hope that it will be useful, |
| 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 20 | * GNU General Public License for more details. |
| 21 | * |
| 22 | * You should have received a copy of the GNU General Public License |
| 23 | * along with this program; if not, write to the Free Software |
| 24 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 25 | * |
| 26 | * |
| 27 | * **************************************************************************** |
| 28 | * |
| 29 | * Note #1 "Sek'd models" ................................... martin 2002-12-07 |
| 30 | * |
| 31 | * Identical soundcards by Sek'd were labeled: |
| 32 | * RME Digi 32 = Sek'd Prodif 32 |
| 33 | * RME Digi 32 Pro = Sek'd Prodif 96 |
| 34 | * RME Digi 32/8 = Sek'd Prodif Gold |
| 35 | * |
| 36 | * **************************************************************************** |
| 37 | * |
| 38 | * Note #2 "full duplex mode" ............................... martin 2002-12-07 |
| 39 | * |
| 40 | * Full duplex doesn't work. All cards (32, 32/8, 32Pro) are working identical |
| 41 | * in this mode. Rec data and play data are using the same buffer therefore. At |
| 42 | * first you have got the playing bits in the buffer and then (after playing |
| 43 | * them) they were overwitten by the captured sound of the CS8412/14. Both |
| 44 | * modes (play/record) are running harmonically hand in hand in the same buffer |
| 45 | * and you have only one start bit plus one interrupt bit to control this |
| 46 | * paired action. |
| 47 | * This is opposite to the latter rme96 where playing and capturing is totally |
| 48 | * separated and so their full duplex mode is supported by alsa (using two |
| 49 | * start bits and two interrupts for two different buffers). |
| 50 | * But due to the wrong sequence of playing and capturing ALSA shows no solved |
| 51 | * full duplex support for the rme32 at the moment. That's bad, but I'm not |
| 52 | * able to solve it. Are you motivated enough to solve this problem now? Your |
| 53 | * patch would be welcome! |
| 54 | * |
| 55 | * **************************************************************************** |
| 56 | * |
| 57 | * "The story after the long seeking" -- tiwai |
| 58 | * |
| 59 | * Ok, the situation regarding the full duplex is now improved a bit. |
| 60 | * In the fullduplex mode (given by the module parameter), the hardware buffer |
| 61 | * is split to halves for read and write directions at the DMA pointer. |
| 62 | * That is, the half above the current DMA pointer is used for write, and |
| 63 | * the half below is used for read. To mangle this strange behavior, an |
| 64 | * software intermediate buffer is introduced. This is, of course, not good |
| 65 | * from the viewpoint of the data transfer efficiency. However, this allows |
| 66 | * you to use arbitrary buffer sizes, instead of the fixed I/O buffer size. |
| 67 | * |
| 68 | * **************************************************************************** |
| 69 | */ |
| 70 | |
| 71 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | #include <linux/delay.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 73 | #include <linux/gfp.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | #include <linux/init.h> |
| 75 | #include <linux/interrupt.h> |
| 76 | #include <linux/pci.h> |
Paul Gortmaker | 65a7721 | 2011-07-15 13:13:37 -0400 | [diff] [blame] | 77 | #include <linux/module.h> |
Takashi Iwai | 6cbbfe1 | 2015-01-28 16:49:33 +0100 | [diff] [blame] | 78 | #include <linux/io.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | |
| 80 | #include <sound/core.h> |
| 81 | #include <sound/info.h> |
| 82 | #include <sound/control.h> |
| 83 | #include <sound/pcm.h> |
| 84 | #include <sound/pcm_params.h> |
| 85 | #include <sound/pcm-indirect.h> |
| 86 | #include <sound/asoundef.h> |
| 87 | #include <sound/initval.h> |
| 88 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */ |
| 90 | static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */ |
Rusty Russell | a67ff6a | 2011-12-15 13:49:36 +1030 | [diff] [blame] | 91 | static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP; /* Enable this card */ |
| 92 | static bool fullduplex[SNDRV_CARDS]; // = {[0 ... (SNDRV_CARDS - 1)] = 1}; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | |
| 94 | module_param_array(index, int, NULL, 0444); |
| 95 | MODULE_PARM_DESC(index, "Index value for RME Digi32 soundcard."); |
| 96 | module_param_array(id, charp, NULL, 0444); |
| 97 | MODULE_PARM_DESC(id, "ID string for RME Digi32 soundcard."); |
| 98 | module_param_array(enable, bool, NULL, 0444); |
| 99 | MODULE_PARM_DESC(enable, "Enable RME Digi32 soundcard."); |
| 100 | module_param_array(fullduplex, bool, NULL, 0444); |
| 101 | MODULE_PARM_DESC(fullduplex, "Support full-duplex mode."); |
| 102 | MODULE_AUTHOR("Martin Langer <martin-langer@gmx.de>, Pilo Chambert <pilo.c@wanadoo.fr>"); |
| 103 | MODULE_DESCRIPTION("RME Digi32, Digi32/8, Digi32 PRO"); |
| 104 | MODULE_LICENSE("GPL"); |
| 105 | MODULE_SUPPORTED_DEVICE("{{RME,Digi32}," "{RME,Digi32/8}," "{RME,Digi32 PRO}}"); |
| 106 | |
| 107 | /* Defines for RME Digi32 series */ |
| 108 | #define RME32_SPDIF_NCHANNELS 2 |
| 109 | |
| 110 | /* Playback and capture buffer size */ |
| 111 | #define RME32_BUFFER_SIZE 0x20000 |
| 112 | |
| 113 | /* IO area size */ |
| 114 | #define RME32_IO_SIZE 0x30000 |
| 115 | |
| 116 | /* IO area offsets */ |
| 117 | #define RME32_IO_DATA_BUFFER 0x0 |
| 118 | #define RME32_IO_CONTROL_REGISTER 0x20000 |
| 119 | #define RME32_IO_GET_POS 0x20000 |
| 120 | #define RME32_IO_CONFIRM_ACTION_IRQ 0x20004 |
| 121 | #define RME32_IO_RESET_POS 0x20100 |
| 122 | |
| 123 | /* Write control register bits */ |
| 124 | #define RME32_WCR_START (1 << 0) /* startbit */ |
| 125 | #define RME32_WCR_MONO (1 << 1) /* 0=stereo, 1=mono |
| 126 | Setting the whole card to mono |
| 127 | doesn't seem to be very useful. |
| 128 | A software-solution can handle |
| 129 | full-duplex with one direction in |
| 130 | stereo and the other way in mono. |
| 131 | So, the hardware should work all |
| 132 | the time in stereo! */ |
| 133 | #define RME32_WCR_MODE24 (1 << 2) /* 0=16bit, 1=32bit */ |
| 134 | #define RME32_WCR_SEL (1 << 3) /* 0=input on output, 1=normal playback/capture */ |
| 135 | #define RME32_WCR_FREQ_0 (1 << 4) /* frequency (play) */ |
| 136 | #define RME32_WCR_FREQ_1 (1 << 5) |
| 137 | #define RME32_WCR_INP_0 (1 << 6) /* input switch */ |
| 138 | #define RME32_WCR_INP_1 (1 << 7) |
| 139 | #define RME32_WCR_RESET (1 << 8) /* Reset address */ |
| 140 | #define RME32_WCR_MUTE (1 << 9) /* digital mute for output */ |
| 141 | #define RME32_WCR_PRO (1 << 10) /* 1=professional, 0=consumer */ |
| 142 | #define RME32_WCR_DS_BM (1 << 11) /* 1=DoubleSpeed (only PRO-Version); 1=BlockMode (only Adat-Version) */ |
| 143 | #define RME32_WCR_ADAT (1 << 12) /* Adat Mode (only Adat-Version) */ |
| 144 | #define RME32_WCR_AUTOSYNC (1 << 13) /* AutoSync */ |
| 145 | #define RME32_WCR_PD (1 << 14) /* DAC Reset (only PRO-Version) */ |
| 146 | #define RME32_WCR_EMP (1 << 15) /* 1=Emphasis on (only PRO-Version) */ |
| 147 | |
| 148 | #define RME32_WCR_BITPOS_FREQ_0 4 |
| 149 | #define RME32_WCR_BITPOS_FREQ_1 5 |
| 150 | #define RME32_WCR_BITPOS_INP_0 6 |
| 151 | #define RME32_WCR_BITPOS_INP_1 7 |
| 152 | |
| 153 | /* Read control register bits */ |
| 154 | #define RME32_RCR_AUDIO_ADDR_MASK 0x1ffff |
| 155 | #define RME32_RCR_LOCK (1 << 23) /* 1=locked, 0=not locked */ |
| 156 | #define RME32_RCR_ERF (1 << 26) /* 1=Error, 0=no Error */ |
| 157 | #define RME32_RCR_FREQ_0 (1 << 27) /* CS841x frequency (record) */ |
| 158 | #define RME32_RCR_FREQ_1 (1 << 28) |
| 159 | #define RME32_RCR_FREQ_2 (1 << 29) |
| 160 | #define RME32_RCR_KMODE (1 << 30) /* card mode: 1=PLL, 0=quartz */ |
| 161 | #define RME32_RCR_IRQ (1 << 31) /* interrupt */ |
| 162 | |
| 163 | #define RME32_RCR_BITPOS_F0 27 |
| 164 | #define RME32_RCR_BITPOS_F1 28 |
| 165 | #define RME32_RCR_BITPOS_F2 29 |
| 166 | |
| 167 | /* Input types */ |
| 168 | #define RME32_INPUT_OPTICAL 0 |
| 169 | #define RME32_INPUT_COAXIAL 1 |
| 170 | #define RME32_INPUT_INTERNAL 2 |
| 171 | #define RME32_INPUT_XLR 3 |
| 172 | |
| 173 | /* Clock modes */ |
| 174 | #define RME32_CLOCKMODE_SLAVE 0 |
| 175 | #define RME32_CLOCKMODE_MASTER_32 1 |
| 176 | #define RME32_CLOCKMODE_MASTER_44 2 |
| 177 | #define RME32_CLOCKMODE_MASTER_48 3 |
| 178 | |
| 179 | /* Block sizes in bytes */ |
| 180 | #define RME32_BLOCK_SIZE 8192 |
| 181 | |
| 182 | /* Software intermediate buffer (max) size */ |
| 183 | #define RME32_MID_BUFFER_SIZE (1024*1024) |
| 184 | |
| 185 | /* Hardware revisions */ |
| 186 | #define RME32_32_REVISION 192 |
| 187 | #define RME32_328_REVISION_OLD 100 |
| 188 | #define RME32_328_REVISION_NEW 101 |
| 189 | #define RME32_PRO_REVISION_WITH_8412 192 |
| 190 | #define RME32_PRO_REVISION_WITH_8414 150 |
| 191 | |
| 192 | |
Takashi Iwai | 017ce80 | 2005-11-17 15:05:25 +0100 | [diff] [blame] | 193 | struct rme32 { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | spinlock_t lock; |
| 195 | int irq; |
| 196 | unsigned long port; |
| 197 | void __iomem *iobase; |
| 198 | |
| 199 | u32 wcreg; /* cached write control register value */ |
| 200 | u32 wcreg_spdif; /* S/PDIF setup */ |
| 201 | u32 wcreg_spdif_stream; /* S/PDIF setup (temporary) */ |
| 202 | u32 rcreg; /* cached read control register value */ |
| 203 | |
| 204 | u8 rev; /* card revision number */ |
| 205 | |
Takashi Iwai | 017ce80 | 2005-11-17 15:05:25 +0100 | [diff] [blame] | 206 | struct snd_pcm_substream *playback_substream; |
| 207 | struct snd_pcm_substream *capture_substream; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 208 | |
| 209 | int playback_frlog; /* log2 of framesize */ |
| 210 | int capture_frlog; |
| 211 | |
| 212 | size_t playback_periodsize; /* in bytes, zero if not used */ |
| 213 | size_t capture_periodsize; /* in bytes, zero if not used */ |
| 214 | |
| 215 | unsigned int fullduplex_mode; |
| 216 | int running; |
| 217 | |
Takashi Iwai | 017ce80 | 2005-11-17 15:05:25 +0100 | [diff] [blame] | 218 | struct snd_pcm_indirect playback_pcm; |
| 219 | struct snd_pcm_indirect capture_pcm; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | |
Takashi Iwai | 017ce80 | 2005-11-17 15:05:25 +0100 | [diff] [blame] | 221 | struct snd_card *card; |
| 222 | struct snd_pcm *spdif_pcm; |
| 223 | struct snd_pcm *adat_pcm; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 224 | struct pci_dev *pci; |
Takashi Iwai | 017ce80 | 2005-11-17 15:05:25 +0100 | [diff] [blame] | 225 | struct snd_kcontrol *spdif_ctl; |
| 226 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 | |
Benoit Taine | 9baa3c3 | 2014-08-08 15:56:03 +0200 | [diff] [blame] | 228 | static const struct pci_device_id snd_rme32_ids[] = { |
Joe Perches | 28d27aa | 2009-06-24 22:13:35 -0700 | [diff] [blame] | 229 | {PCI_VDEVICE(XILINX_RME, PCI_DEVICE_ID_RME_DIGI32), 0,}, |
| 230 | {PCI_VDEVICE(XILINX_RME, PCI_DEVICE_ID_RME_DIGI32_8), 0,}, |
| 231 | {PCI_VDEVICE(XILINX_RME, PCI_DEVICE_ID_RME_DIGI32_PRO), 0,}, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 232 | {0,} |
| 233 | }; |
| 234 | |
| 235 | MODULE_DEVICE_TABLE(pci, snd_rme32_ids); |
| 236 | |
| 237 | #define RME32_ISWORKING(rme32) ((rme32)->wcreg & RME32_WCR_START) |
Roland Dreier | 8b7fc42 | 2005-09-14 14:19:17 -0700 | [diff] [blame] | 238 | #define RME32_PRO_WITH_8414(rme32) ((rme32)->pci->device == PCI_DEVICE_ID_RME_DIGI32_PRO && (rme32)->rev == RME32_PRO_REVISION_WITH_8414) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 239 | |
Takashi Iwai | 017ce80 | 2005-11-17 15:05:25 +0100 | [diff] [blame] | 240 | static int snd_rme32_playback_prepare(struct snd_pcm_substream *substream); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 241 | |
Takashi Iwai | 017ce80 | 2005-11-17 15:05:25 +0100 | [diff] [blame] | 242 | static int snd_rme32_capture_prepare(struct snd_pcm_substream *substream); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 243 | |
Takashi Iwai | 017ce80 | 2005-11-17 15:05:25 +0100 | [diff] [blame] | 244 | static int snd_rme32_pcm_trigger(struct snd_pcm_substream *substream, int cmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 245 | |
Takashi Iwai | 017ce80 | 2005-11-17 15:05:25 +0100 | [diff] [blame] | 246 | static void snd_rme32_proc_init(struct rme32 * rme32); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | |
Takashi Iwai | 017ce80 | 2005-11-17 15:05:25 +0100 | [diff] [blame] | 248 | static int snd_rme32_create_switches(struct snd_card *card, struct rme32 * rme32); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 249 | |
Takashi Iwai | 017ce80 | 2005-11-17 15:05:25 +0100 | [diff] [blame] | 250 | static inline unsigned int snd_rme32_pcm_byteptr(struct rme32 * rme32) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 251 | { |
| 252 | return (readl(rme32->iobase + RME32_IO_GET_POS) |
| 253 | & RME32_RCR_AUDIO_ADDR_MASK); |
| 254 | } |
| 255 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 256 | /* silence callback for halfduplex mode */ |
Takashi Iwai | 032db75 | 2017-05-10 20:29:25 +0200 | [diff] [blame^] | 257 | static int snd_rme32_playback_silence(struct snd_pcm_substream *substream, |
| 258 | int channel, unsigned long pos, |
| 259 | unsigned long count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 260 | { |
Takashi Iwai | 017ce80 | 2005-11-17 15:05:25 +0100 | [diff] [blame] | 261 | struct rme32 *rme32 = snd_pcm_substream_chip(substream); |
Takashi Iwai | 032db75 | 2017-05-10 20:29:25 +0200 | [diff] [blame^] | 262 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 263 | memset_io(rme32->iobase + RME32_IO_DATA_BUFFER + pos, 0, count); |
| 264 | return 0; |
| 265 | } |
| 266 | |
| 267 | /* copy callback for halfduplex mode */ |
Takashi Iwai | 032db75 | 2017-05-10 20:29:25 +0200 | [diff] [blame^] | 268 | static int snd_rme32_playback_copy(struct snd_pcm_substream *substream, |
| 269 | int channel, unsigned long pos, |
| 270 | void __user *src, unsigned long count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 271 | { |
Takashi Iwai | 017ce80 | 2005-11-17 15:05:25 +0100 | [diff] [blame] | 272 | struct rme32 *rme32 = snd_pcm_substream_chip(substream); |
Takashi Iwai | 032db75 | 2017-05-10 20:29:25 +0200 | [diff] [blame^] | 273 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 274 | if (copy_from_user_toio(rme32->iobase + RME32_IO_DATA_BUFFER + pos, |
Takashi Iwai | 032db75 | 2017-05-10 20:29:25 +0200 | [diff] [blame^] | 275 | src, count)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 276 | return -EFAULT; |
| 277 | return 0; |
| 278 | } |
| 279 | |
Takashi Iwai | 032db75 | 2017-05-10 20:29:25 +0200 | [diff] [blame^] | 280 | static int snd_rme32_playback_copy_kernel(struct snd_pcm_substream *substream, |
| 281 | int channel, unsigned long pos, |
| 282 | void *src, unsigned long count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 283 | { |
Takashi Iwai | 017ce80 | 2005-11-17 15:05:25 +0100 | [diff] [blame] | 284 | struct rme32 *rme32 = snd_pcm_substream_chip(substream); |
Takashi Iwai | 032db75 | 2017-05-10 20:29:25 +0200 | [diff] [blame^] | 285 | |
| 286 | memcpy_toio(rme32->iobase + RME32_IO_DATA_BUFFER + pos, src, count); |
| 287 | return 0; |
| 288 | } |
| 289 | |
| 290 | /* copy callback for halfduplex mode */ |
| 291 | static int snd_rme32_capture_copy(struct snd_pcm_substream *substream, |
| 292 | int channel, unsigned long pos, |
| 293 | void __user *dst, unsigned long count) |
| 294 | { |
| 295 | struct rme32 *rme32 = snd_pcm_substream_chip(substream); |
| 296 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 297 | if (copy_to_user_fromio(dst, |
| 298 | rme32->iobase + RME32_IO_DATA_BUFFER + pos, |
| 299 | count)) |
| 300 | return -EFAULT; |
| 301 | return 0; |
| 302 | } |
| 303 | |
Takashi Iwai | 032db75 | 2017-05-10 20:29:25 +0200 | [diff] [blame^] | 304 | static int snd_rme32_capture_copy_kernel(struct snd_pcm_substream *substream, |
| 305 | int channel, unsigned long pos, |
| 306 | void *dst, unsigned long count) |
| 307 | { |
| 308 | struct rme32 *rme32 = snd_pcm_substream_chip(substream); |
| 309 | |
| 310 | memcpy_fromio(dst, rme32->iobase + RME32_IO_DATA_BUFFER + pos, count); |
| 311 | return 0; |
| 312 | } |
| 313 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 314 | /* |
Alexey Dobriyan | 7f927fc | 2006-03-28 01:56:53 -0800 | [diff] [blame] | 315 | * SPDIF I/O capabilities (half-duplex mode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 316 | */ |
Takashi Iwai | 017ce80 | 2005-11-17 15:05:25 +0100 | [diff] [blame] | 317 | static struct snd_pcm_hardware snd_rme32_spdif_info = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 318 | .info = (SNDRV_PCM_INFO_MMAP_IOMEM | |
| 319 | SNDRV_PCM_INFO_MMAP_VALID | |
| 320 | SNDRV_PCM_INFO_INTERLEAVED | |
| 321 | SNDRV_PCM_INFO_PAUSE | |
| 322 | SNDRV_PCM_INFO_SYNC_START), |
| 323 | .formats = (SNDRV_PCM_FMTBIT_S16_LE | |
| 324 | SNDRV_PCM_FMTBIT_S32_LE), |
| 325 | .rates = (SNDRV_PCM_RATE_32000 | |
| 326 | SNDRV_PCM_RATE_44100 | |
| 327 | SNDRV_PCM_RATE_48000), |
| 328 | .rate_min = 32000, |
| 329 | .rate_max = 48000, |
| 330 | .channels_min = 2, |
| 331 | .channels_max = 2, |
| 332 | .buffer_bytes_max = RME32_BUFFER_SIZE, |
| 333 | .period_bytes_min = RME32_BLOCK_SIZE, |
| 334 | .period_bytes_max = RME32_BLOCK_SIZE, |
| 335 | .periods_min = RME32_BUFFER_SIZE / RME32_BLOCK_SIZE, |
| 336 | .periods_max = RME32_BUFFER_SIZE / RME32_BLOCK_SIZE, |
| 337 | .fifo_size = 0, |
| 338 | }; |
| 339 | |
| 340 | /* |
Alexey Dobriyan | 7f927fc | 2006-03-28 01:56:53 -0800 | [diff] [blame] | 341 | * ADAT I/O capabilities (half-duplex mode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 342 | */ |
Takashi Iwai | 017ce80 | 2005-11-17 15:05:25 +0100 | [diff] [blame] | 343 | static struct snd_pcm_hardware snd_rme32_adat_info = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 344 | { |
| 345 | .info = (SNDRV_PCM_INFO_MMAP_IOMEM | |
| 346 | SNDRV_PCM_INFO_MMAP_VALID | |
| 347 | SNDRV_PCM_INFO_INTERLEAVED | |
| 348 | SNDRV_PCM_INFO_PAUSE | |
| 349 | SNDRV_PCM_INFO_SYNC_START), |
| 350 | .formats= SNDRV_PCM_FMTBIT_S16_LE, |
| 351 | .rates = (SNDRV_PCM_RATE_44100 | |
| 352 | SNDRV_PCM_RATE_48000), |
| 353 | .rate_min = 44100, |
| 354 | .rate_max = 48000, |
| 355 | .channels_min = 8, |
| 356 | .channels_max = 8, |
| 357 | .buffer_bytes_max = RME32_BUFFER_SIZE, |
| 358 | .period_bytes_min = RME32_BLOCK_SIZE, |
| 359 | .period_bytes_max = RME32_BLOCK_SIZE, |
| 360 | .periods_min = RME32_BUFFER_SIZE / RME32_BLOCK_SIZE, |
| 361 | .periods_max = RME32_BUFFER_SIZE / RME32_BLOCK_SIZE, |
| 362 | .fifo_size = 0, |
| 363 | }; |
| 364 | |
| 365 | /* |
Alexey Dobriyan | 7f927fc | 2006-03-28 01:56:53 -0800 | [diff] [blame] | 366 | * SPDIF I/O capabilities (full-duplex mode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 367 | */ |
Takashi Iwai | 017ce80 | 2005-11-17 15:05:25 +0100 | [diff] [blame] | 368 | static struct snd_pcm_hardware snd_rme32_spdif_fd_info = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 369 | .info = (SNDRV_PCM_INFO_MMAP | |
| 370 | SNDRV_PCM_INFO_MMAP_VALID | |
| 371 | SNDRV_PCM_INFO_INTERLEAVED | |
| 372 | SNDRV_PCM_INFO_PAUSE | |
| 373 | SNDRV_PCM_INFO_SYNC_START), |
| 374 | .formats = (SNDRV_PCM_FMTBIT_S16_LE | |
| 375 | SNDRV_PCM_FMTBIT_S32_LE), |
| 376 | .rates = (SNDRV_PCM_RATE_32000 | |
| 377 | SNDRV_PCM_RATE_44100 | |
| 378 | SNDRV_PCM_RATE_48000), |
| 379 | .rate_min = 32000, |
| 380 | .rate_max = 48000, |
| 381 | .channels_min = 2, |
| 382 | .channels_max = 2, |
| 383 | .buffer_bytes_max = RME32_MID_BUFFER_SIZE, |
| 384 | .period_bytes_min = RME32_BLOCK_SIZE, |
| 385 | .period_bytes_max = RME32_BLOCK_SIZE, |
| 386 | .periods_min = 2, |
| 387 | .periods_max = RME32_MID_BUFFER_SIZE / RME32_BLOCK_SIZE, |
| 388 | .fifo_size = 0, |
| 389 | }; |
| 390 | |
| 391 | /* |
Alexey Dobriyan | 7f927fc | 2006-03-28 01:56:53 -0800 | [diff] [blame] | 392 | * ADAT I/O capabilities (full-duplex mode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 393 | */ |
Takashi Iwai | 017ce80 | 2005-11-17 15:05:25 +0100 | [diff] [blame] | 394 | static struct snd_pcm_hardware snd_rme32_adat_fd_info = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 395 | { |
| 396 | .info = (SNDRV_PCM_INFO_MMAP | |
| 397 | SNDRV_PCM_INFO_MMAP_VALID | |
| 398 | SNDRV_PCM_INFO_INTERLEAVED | |
| 399 | SNDRV_PCM_INFO_PAUSE | |
| 400 | SNDRV_PCM_INFO_SYNC_START), |
| 401 | .formats= SNDRV_PCM_FMTBIT_S16_LE, |
| 402 | .rates = (SNDRV_PCM_RATE_44100 | |
| 403 | SNDRV_PCM_RATE_48000), |
| 404 | .rate_min = 44100, |
| 405 | .rate_max = 48000, |
| 406 | .channels_min = 8, |
| 407 | .channels_max = 8, |
| 408 | .buffer_bytes_max = RME32_MID_BUFFER_SIZE, |
| 409 | .period_bytes_min = RME32_BLOCK_SIZE, |
| 410 | .period_bytes_max = RME32_BLOCK_SIZE, |
| 411 | .periods_min = 2, |
| 412 | .periods_max = RME32_MID_BUFFER_SIZE / RME32_BLOCK_SIZE, |
| 413 | .fifo_size = 0, |
| 414 | }; |
| 415 | |
Takashi Iwai | 017ce80 | 2005-11-17 15:05:25 +0100 | [diff] [blame] | 416 | static void snd_rme32_reset_dac(struct rme32 *rme32) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 417 | { |
| 418 | writel(rme32->wcreg | RME32_WCR_PD, |
| 419 | rme32->iobase + RME32_IO_CONTROL_REGISTER); |
| 420 | writel(rme32->wcreg, rme32->iobase + RME32_IO_CONTROL_REGISTER); |
| 421 | } |
| 422 | |
Takashi Iwai | 017ce80 | 2005-11-17 15:05:25 +0100 | [diff] [blame] | 423 | static int snd_rme32_playback_getrate(struct rme32 * rme32) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 424 | { |
| 425 | int rate; |
| 426 | |
| 427 | rate = ((rme32->wcreg >> RME32_WCR_BITPOS_FREQ_0) & 1) + |
| 428 | (((rme32->wcreg >> RME32_WCR_BITPOS_FREQ_1) & 1) << 1); |
| 429 | switch (rate) { |
| 430 | case 1: |
| 431 | rate = 32000; |
| 432 | break; |
| 433 | case 2: |
| 434 | rate = 44100; |
| 435 | break; |
| 436 | case 3: |
| 437 | rate = 48000; |
| 438 | break; |
| 439 | default: |
| 440 | return -1; |
| 441 | } |
| 442 | return (rme32->wcreg & RME32_WCR_DS_BM) ? rate << 1 : rate; |
| 443 | } |
| 444 | |
Takashi Iwai | 017ce80 | 2005-11-17 15:05:25 +0100 | [diff] [blame] | 445 | static int snd_rme32_capture_getrate(struct rme32 * rme32, int *is_adat) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 446 | { |
| 447 | int n; |
| 448 | |
| 449 | *is_adat = 0; |
| 450 | if (rme32->rcreg & RME32_RCR_LOCK) { |
| 451 | /* ADAT rate */ |
| 452 | *is_adat = 1; |
| 453 | } |
| 454 | if (rme32->rcreg & RME32_RCR_ERF) { |
| 455 | return -1; |
| 456 | } |
| 457 | |
| 458 | /* S/PDIF rate */ |
| 459 | n = ((rme32->rcreg >> RME32_RCR_BITPOS_F0) & 1) + |
| 460 | (((rme32->rcreg >> RME32_RCR_BITPOS_F1) & 1) << 1) + |
| 461 | (((rme32->rcreg >> RME32_RCR_BITPOS_F2) & 1) << 2); |
| 462 | |
| 463 | if (RME32_PRO_WITH_8414(rme32)) |
| 464 | switch (n) { /* supporting the CS8414 */ |
| 465 | case 0: |
| 466 | case 1: |
| 467 | case 2: |
| 468 | return -1; |
| 469 | case 3: |
| 470 | return 96000; |
| 471 | case 4: |
| 472 | return 88200; |
| 473 | case 5: |
| 474 | return 48000; |
| 475 | case 6: |
| 476 | return 44100; |
| 477 | case 7: |
| 478 | return 32000; |
| 479 | default: |
| 480 | return -1; |
| 481 | break; |
| 482 | } |
| 483 | else |
| 484 | switch (n) { /* supporting the CS8412 */ |
| 485 | case 0: |
| 486 | return -1; |
| 487 | case 1: |
| 488 | return 48000; |
| 489 | case 2: |
| 490 | return 44100; |
| 491 | case 3: |
| 492 | return 32000; |
| 493 | case 4: |
| 494 | return 48000; |
| 495 | case 5: |
| 496 | return 44100; |
| 497 | case 6: |
| 498 | return 44056; |
| 499 | case 7: |
| 500 | return 32000; |
| 501 | default: |
| 502 | break; |
| 503 | } |
| 504 | return -1; |
| 505 | } |
| 506 | |
Takashi Iwai | 017ce80 | 2005-11-17 15:05:25 +0100 | [diff] [blame] | 507 | static int snd_rme32_playback_setrate(struct rme32 * rme32, int rate) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 508 | { |
| 509 | int ds; |
| 510 | |
| 511 | ds = rme32->wcreg & RME32_WCR_DS_BM; |
| 512 | switch (rate) { |
| 513 | case 32000: |
| 514 | rme32->wcreg &= ~RME32_WCR_DS_BM; |
| 515 | rme32->wcreg = (rme32->wcreg | RME32_WCR_FREQ_0) & |
| 516 | ~RME32_WCR_FREQ_1; |
| 517 | break; |
| 518 | case 44100: |
| 519 | rme32->wcreg &= ~RME32_WCR_DS_BM; |
| 520 | rme32->wcreg = (rme32->wcreg | RME32_WCR_FREQ_1) & |
| 521 | ~RME32_WCR_FREQ_0; |
| 522 | break; |
| 523 | case 48000: |
| 524 | rme32->wcreg &= ~RME32_WCR_DS_BM; |
| 525 | rme32->wcreg = (rme32->wcreg | RME32_WCR_FREQ_0) | |
| 526 | RME32_WCR_FREQ_1; |
| 527 | break; |
| 528 | case 64000: |
Roland Dreier | 8b7fc42 | 2005-09-14 14:19:17 -0700 | [diff] [blame] | 529 | if (rme32->pci->device != PCI_DEVICE_ID_RME_DIGI32_PRO) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 530 | return -EINVAL; |
| 531 | rme32->wcreg |= RME32_WCR_DS_BM; |
| 532 | rme32->wcreg = (rme32->wcreg | RME32_WCR_FREQ_0) & |
| 533 | ~RME32_WCR_FREQ_1; |
| 534 | break; |
| 535 | case 88200: |
Roland Dreier | 8b7fc42 | 2005-09-14 14:19:17 -0700 | [diff] [blame] | 536 | if (rme32->pci->device != PCI_DEVICE_ID_RME_DIGI32_PRO) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 537 | return -EINVAL; |
| 538 | rme32->wcreg |= RME32_WCR_DS_BM; |
| 539 | rme32->wcreg = (rme32->wcreg | RME32_WCR_FREQ_1) & |
| 540 | ~RME32_WCR_FREQ_0; |
| 541 | break; |
| 542 | case 96000: |
Roland Dreier | 8b7fc42 | 2005-09-14 14:19:17 -0700 | [diff] [blame] | 543 | if (rme32->pci->device != PCI_DEVICE_ID_RME_DIGI32_PRO) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 544 | return -EINVAL; |
| 545 | rme32->wcreg |= RME32_WCR_DS_BM; |
| 546 | rme32->wcreg = (rme32->wcreg | RME32_WCR_FREQ_0) | |
| 547 | RME32_WCR_FREQ_1; |
| 548 | break; |
| 549 | default: |
| 550 | return -EINVAL; |
| 551 | } |
| 552 | if ((!ds && rme32->wcreg & RME32_WCR_DS_BM) || |
| 553 | (ds && !(rme32->wcreg & RME32_WCR_DS_BM))) |
| 554 | { |
| 555 | /* change to/from double-speed: reset the DAC (if available) */ |
| 556 | snd_rme32_reset_dac(rme32); |
| 557 | } else { |
| 558 | writel(rme32->wcreg, rme32->iobase + RME32_IO_CONTROL_REGISTER); |
| 559 | } |
| 560 | return 0; |
| 561 | } |
| 562 | |
Takashi Iwai | 017ce80 | 2005-11-17 15:05:25 +0100 | [diff] [blame] | 563 | static int snd_rme32_setclockmode(struct rme32 * rme32, int mode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 564 | { |
| 565 | switch (mode) { |
| 566 | case RME32_CLOCKMODE_SLAVE: |
| 567 | /* AutoSync */ |
| 568 | rme32->wcreg = (rme32->wcreg & ~RME32_WCR_FREQ_0) & |
| 569 | ~RME32_WCR_FREQ_1; |
| 570 | break; |
| 571 | case RME32_CLOCKMODE_MASTER_32: |
| 572 | /* Internal 32.0kHz */ |
| 573 | rme32->wcreg = (rme32->wcreg | RME32_WCR_FREQ_0) & |
| 574 | ~RME32_WCR_FREQ_1; |
| 575 | break; |
| 576 | case RME32_CLOCKMODE_MASTER_44: |
| 577 | /* Internal 44.1kHz */ |
| 578 | rme32->wcreg = (rme32->wcreg & ~RME32_WCR_FREQ_0) | |
| 579 | RME32_WCR_FREQ_1; |
| 580 | break; |
| 581 | case RME32_CLOCKMODE_MASTER_48: |
| 582 | /* Internal 48.0kHz */ |
| 583 | rme32->wcreg = (rme32->wcreg | RME32_WCR_FREQ_0) | |
| 584 | RME32_WCR_FREQ_1; |
| 585 | break; |
| 586 | default: |
| 587 | return -EINVAL; |
| 588 | } |
| 589 | writel(rme32->wcreg, rme32->iobase + RME32_IO_CONTROL_REGISTER); |
| 590 | return 0; |
| 591 | } |
| 592 | |
Takashi Iwai | 017ce80 | 2005-11-17 15:05:25 +0100 | [diff] [blame] | 593 | static int snd_rme32_getclockmode(struct rme32 * rme32) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 594 | { |
| 595 | return ((rme32->wcreg >> RME32_WCR_BITPOS_FREQ_0) & 1) + |
| 596 | (((rme32->wcreg >> RME32_WCR_BITPOS_FREQ_1) & 1) << 1); |
| 597 | } |
| 598 | |
Takashi Iwai | 017ce80 | 2005-11-17 15:05:25 +0100 | [diff] [blame] | 599 | static int snd_rme32_setinputtype(struct rme32 * rme32, int type) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 600 | { |
| 601 | switch (type) { |
| 602 | case RME32_INPUT_OPTICAL: |
| 603 | rme32->wcreg = (rme32->wcreg & ~RME32_WCR_INP_0) & |
| 604 | ~RME32_WCR_INP_1; |
| 605 | break; |
| 606 | case RME32_INPUT_COAXIAL: |
| 607 | rme32->wcreg = (rme32->wcreg | RME32_WCR_INP_0) & |
| 608 | ~RME32_WCR_INP_1; |
| 609 | break; |
| 610 | case RME32_INPUT_INTERNAL: |
| 611 | rme32->wcreg = (rme32->wcreg & ~RME32_WCR_INP_0) | |
| 612 | RME32_WCR_INP_1; |
| 613 | break; |
| 614 | case RME32_INPUT_XLR: |
| 615 | rme32->wcreg = (rme32->wcreg | RME32_WCR_INP_0) | |
| 616 | RME32_WCR_INP_1; |
| 617 | break; |
| 618 | default: |
| 619 | return -EINVAL; |
| 620 | } |
| 621 | writel(rme32->wcreg, rme32->iobase + RME32_IO_CONTROL_REGISTER); |
| 622 | return 0; |
| 623 | } |
| 624 | |
Takashi Iwai | 017ce80 | 2005-11-17 15:05:25 +0100 | [diff] [blame] | 625 | static int snd_rme32_getinputtype(struct rme32 * rme32) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 626 | { |
| 627 | return ((rme32->wcreg >> RME32_WCR_BITPOS_INP_0) & 1) + |
| 628 | (((rme32->wcreg >> RME32_WCR_BITPOS_INP_1) & 1) << 1); |
| 629 | } |
| 630 | |
| 631 | static void |
Takashi Iwai | 017ce80 | 2005-11-17 15:05:25 +0100 | [diff] [blame] | 632 | snd_rme32_setframelog(struct rme32 * rme32, int n_channels, int is_playback) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 633 | { |
| 634 | int frlog; |
| 635 | |
| 636 | if (n_channels == 2) { |
| 637 | frlog = 1; |
| 638 | } else { |
| 639 | /* assume 8 channels */ |
| 640 | frlog = 3; |
| 641 | } |
| 642 | if (is_playback) { |
| 643 | frlog += (rme32->wcreg & RME32_WCR_MODE24) ? 2 : 1; |
| 644 | rme32->playback_frlog = frlog; |
| 645 | } else { |
| 646 | frlog += (rme32->wcreg & RME32_WCR_MODE24) ? 2 : 1; |
| 647 | rme32->capture_frlog = frlog; |
| 648 | } |
| 649 | } |
| 650 | |
Takashi Iwai | 6c869d3 | 2015-01-12 16:56:51 +0100 | [diff] [blame] | 651 | static int snd_rme32_setformat(struct rme32 *rme32, snd_pcm_format_t format) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 652 | { |
| 653 | switch (format) { |
| 654 | case SNDRV_PCM_FORMAT_S16_LE: |
| 655 | rme32->wcreg &= ~RME32_WCR_MODE24; |
| 656 | break; |
| 657 | case SNDRV_PCM_FORMAT_S32_LE: |
| 658 | rme32->wcreg |= RME32_WCR_MODE24; |
| 659 | break; |
| 660 | default: |
| 661 | return -EINVAL; |
| 662 | } |
| 663 | writel(rme32->wcreg, rme32->iobase + RME32_IO_CONTROL_REGISTER); |
| 664 | return 0; |
| 665 | } |
| 666 | |
| 667 | static int |
Takashi Iwai | 017ce80 | 2005-11-17 15:05:25 +0100 | [diff] [blame] | 668 | snd_rme32_playback_hw_params(struct snd_pcm_substream *substream, |
| 669 | struct snd_pcm_hw_params *params) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 670 | { |
| 671 | int err, rate, dummy; |
Takashi Iwai | 017ce80 | 2005-11-17 15:05:25 +0100 | [diff] [blame] | 672 | struct rme32 *rme32 = snd_pcm_substream_chip(substream); |
| 673 | struct snd_pcm_runtime *runtime = substream->runtime; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 674 | |
| 675 | if (rme32->fullduplex_mode) { |
| 676 | err = snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(params)); |
| 677 | if (err < 0) |
| 678 | return err; |
| 679 | } else { |
Clemens Ladisch | 4d23359 | 2005-09-05 10:35:20 +0200 | [diff] [blame] | 680 | runtime->dma_area = (void __force *)(rme32->iobase + |
| 681 | RME32_IO_DATA_BUFFER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 682 | runtime->dma_addr = rme32->port + RME32_IO_DATA_BUFFER; |
| 683 | runtime->dma_bytes = RME32_BUFFER_SIZE; |
| 684 | } |
| 685 | |
| 686 | spin_lock_irq(&rme32->lock); |
| 687 | if ((rme32->rcreg & RME32_RCR_KMODE) && |
| 688 | (rate = snd_rme32_capture_getrate(rme32, &dummy)) > 0) { |
| 689 | /* AutoSync */ |
| 690 | if ((int)params_rate(params) != rate) { |
| 691 | spin_unlock_irq(&rme32->lock); |
| 692 | return -EIO; |
| 693 | } |
| 694 | } else if ((err = snd_rme32_playback_setrate(rme32, params_rate(params))) < 0) { |
| 695 | spin_unlock_irq(&rme32->lock); |
| 696 | return err; |
| 697 | } |
| 698 | if ((err = snd_rme32_setformat(rme32, params_format(params))) < 0) { |
| 699 | spin_unlock_irq(&rme32->lock); |
| 700 | return err; |
| 701 | } |
| 702 | |
| 703 | snd_rme32_setframelog(rme32, params_channels(params), 1); |
| 704 | if (rme32->capture_periodsize != 0) { |
| 705 | if (params_period_size(params) << rme32->playback_frlog != rme32->capture_periodsize) { |
| 706 | spin_unlock_irq(&rme32->lock); |
| 707 | return -EBUSY; |
| 708 | } |
| 709 | } |
| 710 | rme32->playback_periodsize = params_period_size(params) << rme32->playback_frlog; |
| 711 | /* S/PDIF setup */ |
| 712 | if ((rme32->wcreg & RME32_WCR_ADAT) == 0) { |
| 713 | rme32->wcreg &= ~(RME32_WCR_PRO | RME32_WCR_EMP); |
| 714 | rme32->wcreg |= rme32->wcreg_spdif_stream; |
| 715 | writel(rme32->wcreg, rme32->iobase + RME32_IO_CONTROL_REGISTER); |
| 716 | } |
| 717 | spin_unlock_irq(&rme32->lock); |
| 718 | |
| 719 | return 0; |
| 720 | } |
| 721 | |
| 722 | static int |
Takashi Iwai | 017ce80 | 2005-11-17 15:05:25 +0100 | [diff] [blame] | 723 | snd_rme32_capture_hw_params(struct snd_pcm_substream *substream, |
| 724 | struct snd_pcm_hw_params *params) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 725 | { |
| 726 | int err, isadat, rate; |
Takashi Iwai | 017ce80 | 2005-11-17 15:05:25 +0100 | [diff] [blame] | 727 | struct rme32 *rme32 = snd_pcm_substream_chip(substream); |
| 728 | struct snd_pcm_runtime *runtime = substream->runtime; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 729 | |
| 730 | if (rme32->fullduplex_mode) { |
| 731 | err = snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(params)); |
| 732 | if (err < 0) |
| 733 | return err; |
| 734 | } else { |
Clemens Ladisch | 4d23359 | 2005-09-05 10:35:20 +0200 | [diff] [blame] | 735 | runtime->dma_area = (void __force *)rme32->iobase + |
| 736 | RME32_IO_DATA_BUFFER; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 737 | runtime->dma_addr = rme32->port + RME32_IO_DATA_BUFFER; |
| 738 | runtime->dma_bytes = RME32_BUFFER_SIZE; |
| 739 | } |
| 740 | |
| 741 | spin_lock_irq(&rme32->lock); |
| 742 | /* enable AutoSync for record-preparing */ |
| 743 | rme32->wcreg |= RME32_WCR_AUTOSYNC; |
| 744 | writel(rme32->wcreg, rme32->iobase + RME32_IO_CONTROL_REGISTER); |
| 745 | |
| 746 | if ((err = snd_rme32_setformat(rme32, params_format(params))) < 0) { |
| 747 | spin_unlock_irq(&rme32->lock); |
| 748 | return err; |
| 749 | } |
| 750 | if ((err = snd_rme32_playback_setrate(rme32, params_rate(params))) < 0) { |
| 751 | spin_unlock_irq(&rme32->lock); |
| 752 | return err; |
| 753 | } |
| 754 | if ((rate = snd_rme32_capture_getrate(rme32, &isadat)) > 0) { |
| 755 | if ((int)params_rate(params) != rate) { |
| 756 | spin_unlock_irq(&rme32->lock); |
| 757 | return -EIO; |
| 758 | } |
| 759 | if ((isadat && runtime->hw.channels_min == 2) || |
| 760 | (!isadat && runtime->hw.channels_min == 8)) { |
| 761 | spin_unlock_irq(&rme32->lock); |
| 762 | return -EIO; |
| 763 | } |
| 764 | } |
| 765 | /* AutoSync off for recording */ |
| 766 | rme32->wcreg &= ~RME32_WCR_AUTOSYNC; |
| 767 | writel(rme32->wcreg, rme32->iobase + RME32_IO_CONTROL_REGISTER); |
| 768 | |
| 769 | snd_rme32_setframelog(rme32, params_channels(params), 0); |
| 770 | if (rme32->playback_periodsize != 0) { |
| 771 | if (params_period_size(params) << rme32->capture_frlog != |
| 772 | rme32->playback_periodsize) { |
| 773 | spin_unlock_irq(&rme32->lock); |
| 774 | return -EBUSY; |
| 775 | } |
| 776 | } |
| 777 | rme32->capture_periodsize = |
| 778 | params_period_size(params) << rme32->capture_frlog; |
| 779 | spin_unlock_irq(&rme32->lock); |
| 780 | |
| 781 | return 0; |
| 782 | } |
| 783 | |
Takashi Iwai | 017ce80 | 2005-11-17 15:05:25 +0100 | [diff] [blame] | 784 | static int snd_rme32_pcm_hw_free(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 785 | { |
Takashi Iwai | 017ce80 | 2005-11-17 15:05:25 +0100 | [diff] [blame] | 786 | struct rme32 *rme32 = snd_pcm_substream_chip(substream); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 787 | if (! rme32->fullduplex_mode) |
| 788 | return 0; |
| 789 | return snd_pcm_lib_free_pages(substream); |
| 790 | } |
| 791 | |
Takashi Iwai | 017ce80 | 2005-11-17 15:05:25 +0100 | [diff] [blame] | 792 | static void snd_rme32_pcm_start(struct rme32 * rme32, int from_pause) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 793 | { |
| 794 | if (!from_pause) { |
| 795 | writel(0, rme32->iobase + RME32_IO_RESET_POS); |
| 796 | } |
| 797 | |
| 798 | rme32->wcreg |= RME32_WCR_START; |
| 799 | writel(rme32->wcreg, rme32->iobase + RME32_IO_CONTROL_REGISTER); |
| 800 | } |
| 801 | |
Takashi Iwai | 017ce80 | 2005-11-17 15:05:25 +0100 | [diff] [blame] | 802 | static void snd_rme32_pcm_stop(struct rme32 * rme32, int to_pause) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 803 | { |
| 804 | /* |
| 805 | * Check if there is an unconfirmed IRQ, if so confirm it, or else |
| 806 | * the hardware will not stop generating interrupts |
| 807 | */ |
| 808 | rme32->rcreg = readl(rme32->iobase + RME32_IO_CONTROL_REGISTER); |
| 809 | if (rme32->rcreg & RME32_RCR_IRQ) { |
| 810 | writel(0, rme32->iobase + RME32_IO_CONFIRM_ACTION_IRQ); |
| 811 | } |
| 812 | rme32->wcreg &= ~RME32_WCR_START; |
| 813 | if (rme32->wcreg & RME32_WCR_SEL) |
| 814 | rme32->wcreg |= RME32_WCR_MUTE; |
| 815 | writel(rme32->wcreg, rme32->iobase + RME32_IO_CONTROL_REGISTER); |
| 816 | if (! to_pause) |
| 817 | writel(0, rme32->iobase + RME32_IO_RESET_POS); |
| 818 | } |
| 819 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 820 | static irqreturn_t snd_rme32_interrupt(int irq, void *dev_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 821 | { |
Takashi Iwai | 017ce80 | 2005-11-17 15:05:25 +0100 | [diff] [blame] | 822 | struct rme32 *rme32 = (struct rme32 *) dev_id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 823 | |
| 824 | rme32->rcreg = readl(rme32->iobase + RME32_IO_CONTROL_REGISTER); |
| 825 | if (!(rme32->rcreg & RME32_RCR_IRQ)) { |
| 826 | return IRQ_NONE; |
| 827 | } else { |
| 828 | if (rme32->capture_substream) { |
| 829 | snd_pcm_period_elapsed(rme32->capture_substream); |
| 830 | } |
| 831 | if (rme32->playback_substream) { |
| 832 | snd_pcm_period_elapsed(rme32->playback_substream); |
| 833 | } |
| 834 | writel(0, rme32->iobase + RME32_IO_CONFIRM_ACTION_IRQ); |
| 835 | } |
| 836 | return IRQ_HANDLED; |
| 837 | } |
| 838 | |
| 839 | static unsigned int period_bytes[] = { RME32_BLOCK_SIZE }; |
| 840 | |
| 841 | |
Takashi Iwai | 017ce80 | 2005-11-17 15:05:25 +0100 | [diff] [blame] | 842 | static struct snd_pcm_hw_constraint_list hw_constraints_period_bytes = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 843 | .count = ARRAY_SIZE(period_bytes), |
| 844 | .list = period_bytes, |
| 845 | .mask = 0 |
| 846 | }; |
| 847 | |
Takashi Iwai | 017ce80 | 2005-11-17 15:05:25 +0100 | [diff] [blame] | 848 | static void snd_rme32_set_buffer_constraint(struct rme32 *rme32, struct snd_pcm_runtime *runtime) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 849 | { |
| 850 | if (! rme32->fullduplex_mode) { |
Lars-Peter Clausen | 80ec889 | 2015-10-18 15:39:19 +0200 | [diff] [blame] | 851 | snd_pcm_hw_constraint_single(runtime, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 852 | SNDRV_PCM_HW_PARAM_BUFFER_BYTES, |
Lars-Peter Clausen | 80ec889 | 2015-10-18 15:39:19 +0200 | [diff] [blame] | 853 | RME32_BUFFER_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 854 | snd_pcm_hw_constraint_list(runtime, 0, |
| 855 | SNDRV_PCM_HW_PARAM_PERIOD_BYTES, |
| 856 | &hw_constraints_period_bytes); |
| 857 | } |
| 858 | } |
| 859 | |
Takashi Iwai | 017ce80 | 2005-11-17 15:05:25 +0100 | [diff] [blame] | 860 | static int snd_rme32_playback_spdif_open(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 861 | { |
| 862 | int rate, dummy; |
Takashi Iwai | 017ce80 | 2005-11-17 15:05:25 +0100 | [diff] [blame] | 863 | struct rme32 *rme32 = snd_pcm_substream_chip(substream); |
| 864 | struct snd_pcm_runtime *runtime = substream->runtime; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 865 | |
| 866 | snd_pcm_set_sync(substream); |
| 867 | |
| 868 | spin_lock_irq(&rme32->lock); |
| 869 | if (rme32->playback_substream != NULL) { |
| 870 | spin_unlock_irq(&rme32->lock); |
| 871 | return -EBUSY; |
| 872 | } |
| 873 | rme32->wcreg &= ~RME32_WCR_ADAT; |
| 874 | writel(rme32->wcreg, rme32->iobase + RME32_IO_CONTROL_REGISTER); |
| 875 | rme32->playback_substream = substream; |
| 876 | spin_unlock_irq(&rme32->lock); |
| 877 | |
| 878 | if (rme32->fullduplex_mode) |
| 879 | runtime->hw = snd_rme32_spdif_fd_info; |
| 880 | else |
| 881 | runtime->hw = snd_rme32_spdif_info; |
Roland Dreier | 8b7fc42 | 2005-09-14 14:19:17 -0700 | [diff] [blame] | 882 | if (rme32->pci->device == PCI_DEVICE_ID_RME_DIGI32_PRO) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 883 | runtime->hw.rates |= SNDRV_PCM_RATE_64000 | SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000; |
| 884 | runtime->hw.rate_max = 96000; |
| 885 | } |
| 886 | if ((rme32->rcreg & RME32_RCR_KMODE) && |
| 887 | (rate = snd_rme32_capture_getrate(rme32, &dummy)) > 0) { |
| 888 | /* AutoSync */ |
Clemens Ladisch | 918f3a0 | 2007-08-13 17:40:54 +0200 | [diff] [blame] | 889 | runtime->hw.rates = snd_pcm_rate_to_rate_bit(rate); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 890 | runtime->hw.rate_min = rate; |
| 891 | runtime->hw.rate_max = rate; |
| 892 | } |
| 893 | |
| 894 | snd_rme32_set_buffer_constraint(rme32, runtime); |
| 895 | |
| 896 | rme32->wcreg_spdif_stream = rme32->wcreg_spdif; |
| 897 | rme32->spdif_ctl->vd[0].access &= ~SNDRV_CTL_ELEM_ACCESS_INACTIVE; |
| 898 | snd_ctl_notify(rme32->card, SNDRV_CTL_EVENT_MASK_VALUE | |
| 899 | SNDRV_CTL_EVENT_MASK_INFO, &rme32->spdif_ctl->id); |
| 900 | return 0; |
| 901 | } |
| 902 | |
Takashi Iwai | 017ce80 | 2005-11-17 15:05:25 +0100 | [diff] [blame] | 903 | static int snd_rme32_capture_spdif_open(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 904 | { |
| 905 | int isadat, rate; |
Takashi Iwai | 017ce80 | 2005-11-17 15:05:25 +0100 | [diff] [blame] | 906 | struct rme32 *rme32 = snd_pcm_substream_chip(substream); |
| 907 | struct snd_pcm_runtime *runtime = substream->runtime; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 908 | |
| 909 | snd_pcm_set_sync(substream); |
| 910 | |
| 911 | spin_lock_irq(&rme32->lock); |
| 912 | if (rme32->capture_substream != NULL) { |
| 913 | spin_unlock_irq(&rme32->lock); |
| 914 | return -EBUSY; |
| 915 | } |
| 916 | rme32->capture_substream = substream; |
| 917 | spin_unlock_irq(&rme32->lock); |
| 918 | |
| 919 | if (rme32->fullduplex_mode) |
| 920 | runtime->hw = snd_rme32_spdif_fd_info; |
| 921 | else |
| 922 | runtime->hw = snd_rme32_spdif_info; |
| 923 | if (RME32_PRO_WITH_8414(rme32)) { |
| 924 | runtime->hw.rates |= SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000; |
| 925 | runtime->hw.rate_max = 96000; |
| 926 | } |
| 927 | if ((rate = snd_rme32_capture_getrate(rme32, &isadat)) > 0) { |
| 928 | if (isadat) { |
| 929 | return -EIO; |
| 930 | } |
Clemens Ladisch | 918f3a0 | 2007-08-13 17:40:54 +0200 | [diff] [blame] | 931 | runtime->hw.rates = snd_pcm_rate_to_rate_bit(rate); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 932 | runtime->hw.rate_min = rate; |
| 933 | runtime->hw.rate_max = rate; |
| 934 | } |
| 935 | |
| 936 | snd_rme32_set_buffer_constraint(rme32, runtime); |
| 937 | |
| 938 | return 0; |
| 939 | } |
| 940 | |
| 941 | static int |
Takashi Iwai | 017ce80 | 2005-11-17 15:05:25 +0100 | [diff] [blame] | 942 | snd_rme32_playback_adat_open(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 943 | { |
| 944 | int rate, dummy; |
Takashi Iwai | 017ce80 | 2005-11-17 15:05:25 +0100 | [diff] [blame] | 945 | struct rme32 *rme32 = snd_pcm_substream_chip(substream); |
| 946 | struct snd_pcm_runtime *runtime = substream->runtime; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 947 | |
| 948 | snd_pcm_set_sync(substream); |
| 949 | |
| 950 | spin_lock_irq(&rme32->lock); |
| 951 | if (rme32->playback_substream != NULL) { |
| 952 | spin_unlock_irq(&rme32->lock); |
| 953 | return -EBUSY; |
| 954 | } |
| 955 | rme32->wcreg |= RME32_WCR_ADAT; |
| 956 | writel(rme32->wcreg, rme32->iobase + RME32_IO_CONTROL_REGISTER); |
| 957 | rme32->playback_substream = substream; |
| 958 | spin_unlock_irq(&rme32->lock); |
| 959 | |
| 960 | if (rme32->fullduplex_mode) |
| 961 | runtime->hw = snd_rme32_adat_fd_info; |
| 962 | else |
| 963 | runtime->hw = snd_rme32_adat_info; |
| 964 | if ((rme32->rcreg & RME32_RCR_KMODE) && |
| 965 | (rate = snd_rme32_capture_getrate(rme32, &dummy)) > 0) { |
| 966 | /* AutoSync */ |
Clemens Ladisch | 918f3a0 | 2007-08-13 17:40:54 +0200 | [diff] [blame] | 967 | runtime->hw.rates = snd_pcm_rate_to_rate_bit(rate); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 968 | runtime->hw.rate_min = rate; |
| 969 | runtime->hw.rate_max = rate; |
| 970 | } |
| 971 | |
| 972 | snd_rme32_set_buffer_constraint(rme32, runtime); |
| 973 | return 0; |
| 974 | } |
| 975 | |
| 976 | static int |
Takashi Iwai | 017ce80 | 2005-11-17 15:05:25 +0100 | [diff] [blame] | 977 | snd_rme32_capture_adat_open(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 978 | { |
| 979 | int isadat, rate; |
Takashi Iwai | 017ce80 | 2005-11-17 15:05:25 +0100 | [diff] [blame] | 980 | struct rme32 *rme32 = snd_pcm_substream_chip(substream); |
| 981 | struct snd_pcm_runtime *runtime = substream->runtime; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 982 | |
| 983 | if (rme32->fullduplex_mode) |
| 984 | runtime->hw = snd_rme32_adat_fd_info; |
| 985 | else |
| 986 | runtime->hw = snd_rme32_adat_info; |
| 987 | if ((rate = snd_rme32_capture_getrate(rme32, &isadat)) > 0) { |
| 988 | if (!isadat) { |
| 989 | return -EIO; |
| 990 | } |
Clemens Ladisch | 918f3a0 | 2007-08-13 17:40:54 +0200 | [diff] [blame] | 991 | runtime->hw.rates = snd_pcm_rate_to_rate_bit(rate); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 992 | runtime->hw.rate_min = rate; |
| 993 | runtime->hw.rate_max = rate; |
| 994 | } |
| 995 | |
| 996 | snd_pcm_set_sync(substream); |
| 997 | |
| 998 | spin_lock_irq(&rme32->lock); |
| 999 | if (rme32->capture_substream != NULL) { |
| 1000 | spin_unlock_irq(&rme32->lock); |
| 1001 | return -EBUSY; |
| 1002 | } |
| 1003 | rme32->capture_substream = substream; |
| 1004 | spin_unlock_irq(&rme32->lock); |
| 1005 | |
| 1006 | snd_rme32_set_buffer_constraint(rme32, runtime); |
| 1007 | return 0; |
| 1008 | } |
| 1009 | |
Takashi Iwai | 017ce80 | 2005-11-17 15:05:25 +0100 | [diff] [blame] | 1010 | static int snd_rme32_playback_close(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1011 | { |
Takashi Iwai | 017ce80 | 2005-11-17 15:05:25 +0100 | [diff] [blame] | 1012 | struct rme32 *rme32 = snd_pcm_substream_chip(substream); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1013 | int spdif = 0; |
| 1014 | |
| 1015 | spin_lock_irq(&rme32->lock); |
| 1016 | rme32->playback_substream = NULL; |
| 1017 | rme32->playback_periodsize = 0; |
| 1018 | spdif = (rme32->wcreg & RME32_WCR_ADAT) == 0; |
| 1019 | spin_unlock_irq(&rme32->lock); |
| 1020 | if (spdif) { |
| 1021 | rme32->spdif_ctl->vd[0].access |= SNDRV_CTL_ELEM_ACCESS_INACTIVE; |
| 1022 | snd_ctl_notify(rme32->card, SNDRV_CTL_EVENT_MASK_VALUE | |
| 1023 | SNDRV_CTL_EVENT_MASK_INFO, |
| 1024 | &rme32->spdif_ctl->id); |
| 1025 | } |
| 1026 | return 0; |
| 1027 | } |
| 1028 | |
Takashi Iwai | 017ce80 | 2005-11-17 15:05:25 +0100 | [diff] [blame] | 1029 | static int snd_rme32_capture_close(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1030 | { |
Takashi Iwai | 017ce80 | 2005-11-17 15:05:25 +0100 | [diff] [blame] | 1031 | struct rme32 *rme32 = snd_pcm_substream_chip(substream); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1032 | |
| 1033 | spin_lock_irq(&rme32->lock); |
| 1034 | rme32->capture_substream = NULL; |
| 1035 | rme32->capture_periodsize = 0; |
Denis Efremov | f49a59c | 2013-02-11 19:04:06 +0400 | [diff] [blame] | 1036 | spin_unlock_irq(&rme32->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1037 | return 0; |
| 1038 | } |
| 1039 | |
Takashi Iwai | 017ce80 | 2005-11-17 15:05:25 +0100 | [diff] [blame] | 1040 | static int snd_rme32_playback_prepare(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1041 | { |
Takashi Iwai | 017ce80 | 2005-11-17 15:05:25 +0100 | [diff] [blame] | 1042 | struct rme32 *rme32 = snd_pcm_substream_chip(substream); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1043 | |
| 1044 | spin_lock_irq(&rme32->lock); |
| 1045 | if (rme32->fullduplex_mode) { |
| 1046 | memset(&rme32->playback_pcm, 0, sizeof(rme32->playback_pcm)); |
| 1047 | rme32->playback_pcm.hw_buffer_size = RME32_BUFFER_SIZE; |
| 1048 | rme32->playback_pcm.sw_buffer_size = snd_pcm_lib_buffer_bytes(substream); |
| 1049 | } else { |
| 1050 | writel(0, rme32->iobase + RME32_IO_RESET_POS); |
| 1051 | } |
| 1052 | if (rme32->wcreg & RME32_WCR_SEL) |
| 1053 | rme32->wcreg &= ~RME32_WCR_MUTE; |
| 1054 | writel(rme32->wcreg, rme32->iobase + RME32_IO_CONTROL_REGISTER); |
| 1055 | spin_unlock_irq(&rme32->lock); |
| 1056 | return 0; |
| 1057 | } |
| 1058 | |
Takashi Iwai | 017ce80 | 2005-11-17 15:05:25 +0100 | [diff] [blame] | 1059 | static int snd_rme32_capture_prepare(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1060 | { |
Takashi Iwai | 017ce80 | 2005-11-17 15:05:25 +0100 | [diff] [blame] | 1061 | struct rme32 *rme32 = snd_pcm_substream_chip(substream); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1062 | |
| 1063 | spin_lock_irq(&rme32->lock); |
| 1064 | if (rme32->fullduplex_mode) { |
| 1065 | memset(&rme32->capture_pcm, 0, sizeof(rme32->capture_pcm)); |
| 1066 | rme32->capture_pcm.hw_buffer_size = RME32_BUFFER_SIZE; |
| 1067 | rme32->capture_pcm.hw_queue_size = RME32_BUFFER_SIZE / 2; |
| 1068 | rme32->capture_pcm.sw_buffer_size = snd_pcm_lib_buffer_bytes(substream); |
| 1069 | } else { |
| 1070 | writel(0, rme32->iobase + RME32_IO_RESET_POS); |
| 1071 | } |
| 1072 | spin_unlock_irq(&rme32->lock); |
| 1073 | return 0; |
| 1074 | } |
| 1075 | |
| 1076 | static int |
Takashi Iwai | 017ce80 | 2005-11-17 15:05:25 +0100 | [diff] [blame] | 1077 | snd_rme32_pcm_trigger(struct snd_pcm_substream *substream, int cmd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1078 | { |
Takashi Iwai | 017ce80 | 2005-11-17 15:05:25 +0100 | [diff] [blame] | 1079 | struct rme32 *rme32 = snd_pcm_substream_chip(substream); |
Takashi Iwai | 017ce80 | 2005-11-17 15:05:25 +0100 | [diff] [blame] | 1080 | struct snd_pcm_substream *s; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1081 | |
| 1082 | spin_lock(&rme32->lock); |
Takashi Iwai | ef991b9 | 2007-02-22 12:52:53 +0100 | [diff] [blame] | 1083 | snd_pcm_group_for_each_entry(s, substream) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1084 | if (s != rme32->playback_substream && |
| 1085 | s != rme32->capture_substream) |
| 1086 | continue; |
| 1087 | switch (cmd) { |
| 1088 | case SNDRV_PCM_TRIGGER_START: |
| 1089 | rme32->running |= (1 << s->stream); |
| 1090 | if (rme32->fullduplex_mode) { |
| 1091 | /* remember the current DMA position */ |
| 1092 | if (s == rme32->playback_substream) { |
| 1093 | rme32->playback_pcm.hw_io = |
| 1094 | rme32->playback_pcm.hw_data = snd_rme32_pcm_byteptr(rme32); |
| 1095 | } else { |
| 1096 | rme32->capture_pcm.hw_io = |
| 1097 | rme32->capture_pcm.hw_data = snd_rme32_pcm_byteptr(rme32); |
| 1098 | } |
| 1099 | } |
| 1100 | break; |
| 1101 | case SNDRV_PCM_TRIGGER_STOP: |
| 1102 | rme32->running &= ~(1 << s->stream); |
| 1103 | break; |
| 1104 | } |
| 1105 | snd_pcm_trigger_done(s, substream); |
| 1106 | } |
| 1107 | |
| 1108 | /* prefill playback buffer */ |
| 1109 | if (cmd == SNDRV_PCM_TRIGGER_START && rme32->fullduplex_mode) { |
Takashi Iwai | ef991b9 | 2007-02-22 12:52:53 +0100 | [diff] [blame] | 1110 | snd_pcm_group_for_each_entry(s, substream) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1111 | if (s == rme32->playback_substream) { |
| 1112 | s->ops->ack(s); |
| 1113 | break; |
| 1114 | } |
| 1115 | } |
| 1116 | } |
| 1117 | |
| 1118 | switch (cmd) { |
| 1119 | case SNDRV_PCM_TRIGGER_START: |
| 1120 | if (rme32->running && ! RME32_ISWORKING(rme32)) |
| 1121 | snd_rme32_pcm_start(rme32, 0); |
| 1122 | break; |
| 1123 | case SNDRV_PCM_TRIGGER_STOP: |
| 1124 | if (! rme32->running && RME32_ISWORKING(rme32)) |
| 1125 | snd_rme32_pcm_stop(rme32, 0); |
| 1126 | break; |
| 1127 | case SNDRV_PCM_TRIGGER_PAUSE_PUSH: |
| 1128 | if (rme32->running && RME32_ISWORKING(rme32)) |
| 1129 | snd_rme32_pcm_stop(rme32, 1); |
| 1130 | break; |
| 1131 | case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: |
| 1132 | if (rme32->running && ! RME32_ISWORKING(rme32)) |
| 1133 | snd_rme32_pcm_start(rme32, 1); |
| 1134 | break; |
| 1135 | } |
| 1136 | spin_unlock(&rme32->lock); |
| 1137 | return 0; |
| 1138 | } |
| 1139 | |
| 1140 | /* pointer callback for halfduplex mode */ |
| 1141 | static snd_pcm_uframes_t |
Takashi Iwai | 017ce80 | 2005-11-17 15:05:25 +0100 | [diff] [blame] | 1142 | snd_rme32_playback_pointer(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1143 | { |
Takashi Iwai | 017ce80 | 2005-11-17 15:05:25 +0100 | [diff] [blame] | 1144 | struct rme32 *rme32 = snd_pcm_substream_chip(substream); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1145 | return snd_rme32_pcm_byteptr(rme32) >> rme32->playback_frlog; |
| 1146 | } |
| 1147 | |
| 1148 | static snd_pcm_uframes_t |
Takashi Iwai | 017ce80 | 2005-11-17 15:05:25 +0100 | [diff] [blame] | 1149 | snd_rme32_capture_pointer(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1150 | { |
Takashi Iwai | 017ce80 | 2005-11-17 15:05:25 +0100 | [diff] [blame] | 1151 | struct rme32 *rme32 = snd_pcm_substream_chip(substream); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1152 | return snd_rme32_pcm_byteptr(rme32) >> rme32->capture_frlog; |
| 1153 | } |
| 1154 | |
| 1155 | |
| 1156 | /* ack and pointer callbacks for fullduplex mode */ |
Takashi Iwai | 017ce80 | 2005-11-17 15:05:25 +0100 | [diff] [blame] | 1157 | static void snd_rme32_pb_trans_copy(struct snd_pcm_substream *substream, |
| 1158 | struct snd_pcm_indirect *rec, size_t bytes) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1159 | { |
Takashi Iwai | 017ce80 | 2005-11-17 15:05:25 +0100 | [diff] [blame] | 1160 | struct rme32 *rme32 = snd_pcm_substream_chip(substream); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1161 | memcpy_toio(rme32->iobase + RME32_IO_DATA_BUFFER + rec->hw_data, |
| 1162 | substream->runtime->dma_area + rec->sw_data, bytes); |
| 1163 | } |
| 1164 | |
Takashi Iwai | 017ce80 | 2005-11-17 15:05:25 +0100 | [diff] [blame] | 1165 | static int snd_rme32_playback_fd_ack(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1166 | { |
Takashi Iwai | 017ce80 | 2005-11-17 15:05:25 +0100 | [diff] [blame] | 1167 | struct rme32 *rme32 = snd_pcm_substream_chip(substream); |
| 1168 | struct snd_pcm_indirect *rec, *cprec; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1169 | |
| 1170 | rec = &rme32->playback_pcm; |
| 1171 | cprec = &rme32->capture_pcm; |
| 1172 | spin_lock(&rme32->lock); |
| 1173 | rec->hw_queue_size = RME32_BUFFER_SIZE; |
| 1174 | if (rme32->running & (1 << SNDRV_PCM_STREAM_CAPTURE)) |
| 1175 | rec->hw_queue_size -= cprec->hw_ready; |
| 1176 | spin_unlock(&rme32->lock); |
Takashi Iwai | 3e02c5a | 2017-05-19 18:49:45 +0200 | [diff] [blame] | 1177 | return snd_pcm_indirect_playback_transfer(substream, rec, |
| 1178 | snd_rme32_pb_trans_copy); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1179 | } |
| 1180 | |
Takashi Iwai | 017ce80 | 2005-11-17 15:05:25 +0100 | [diff] [blame] | 1181 | static void snd_rme32_cp_trans_copy(struct snd_pcm_substream *substream, |
| 1182 | struct snd_pcm_indirect *rec, size_t bytes) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1183 | { |
Takashi Iwai | 017ce80 | 2005-11-17 15:05:25 +0100 | [diff] [blame] | 1184 | struct rme32 *rme32 = snd_pcm_substream_chip(substream); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1185 | memcpy_fromio(substream->runtime->dma_area + rec->sw_data, |
| 1186 | rme32->iobase + RME32_IO_DATA_BUFFER + rec->hw_data, |
| 1187 | bytes); |
| 1188 | } |
| 1189 | |
Takashi Iwai | 017ce80 | 2005-11-17 15:05:25 +0100 | [diff] [blame] | 1190 | static int snd_rme32_capture_fd_ack(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1191 | { |
Takashi Iwai | 017ce80 | 2005-11-17 15:05:25 +0100 | [diff] [blame] | 1192 | struct rme32 *rme32 = snd_pcm_substream_chip(substream); |
Takashi Iwai | 3e02c5a | 2017-05-19 18:49:45 +0200 | [diff] [blame] | 1193 | return snd_pcm_indirect_capture_transfer(substream, &rme32->capture_pcm, |
| 1194 | snd_rme32_cp_trans_copy); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1195 | } |
| 1196 | |
| 1197 | static snd_pcm_uframes_t |
Takashi Iwai | 017ce80 | 2005-11-17 15:05:25 +0100 | [diff] [blame] | 1198 | snd_rme32_playback_fd_pointer(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1199 | { |
Takashi Iwai | 017ce80 | 2005-11-17 15:05:25 +0100 | [diff] [blame] | 1200 | struct rme32 *rme32 = snd_pcm_substream_chip(substream); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1201 | return snd_pcm_indirect_playback_pointer(substream, &rme32->playback_pcm, |
| 1202 | snd_rme32_pcm_byteptr(rme32)); |
| 1203 | } |
| 1204 | |
| 1205 | static snd_pcm_uframes_t |
Takashi Iwai | 017ce80 | 2005-11-17 15:05:25 +0100 | [diff] [blame] | 1206 | snd_rme32_capture_fd_pointer(struct snd_pcm_substream *substream) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1207 | { |
Takashi Iwai | 017ce80 | 2005-11-17 15:05:25 +0100 | [diff] [blame] | 1208 | struct rme32 *rme32 = snd_pcm_substream_chip(substream); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1209 | return snd_pcm_indirect_capture_pointer(substream, &rme32->capture_pcm, |
| 1210 | snd_rme32_pcm_byteptr(rme32)); |
| 1211 | } |
| 1212 | |
| 1213 | /* for halfduplex mode */ |
Julia Lawall | 6769e988 | 2016-09-02 00:13:10 +0200 | [diff] [blame] | 1214 | static const struct snd_pcm_ops snd_rme32_playback_spdif_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1215 | .open = snd_rme32_playback_spdif_open, |
| 1216 | .close = snd_rme32_playback_close, |
| 1217 | .ioctl = snd_pcm_lib_ioctl, |
| 1218 | .hw_params = snd_rme32_playback_hw_params, |
| 1219 | .hw_free = snd_rme32_pcm_hw_free, |
| 1220 | .prepare = snd_rme32_playback_prepare, |
| 1221 | .trigger = snd_rme32_pcm_trigger, |
| 1222 | .pointer = snd_rme32_playback_pointer, |
Takashi Iwai | 032db75 | 2017-05-10 20:29:25 +0200 | [diff] [blame^] | 1223 | .copy_user = snd_rme32_playback_copy, |
| 1224 | .copy_kernel = snd_rme32_playback_copy_kernel, |
| 1225 | .fill_silence = snd_rme32_playback_silence, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1226 | .mmap = snd_pcm_lib_mmap_iomem, |
| 1227 | }; |
| 1228 | |
Julia Lawall | 6769e988 | 2016-09-02 00:13:10 +0200 | [diff] [blame] | 1229 | static const struct snd_pcm_ops snd_rme32_capture_spdif_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1230 | .open = snd_rme32_capture_spdif_open, |
| 1231 | .close = snd_rme32_capture_close, |
| 1232 | .ioctl = snd_pcm_lib_ioctl, |
| 1233 | .hw_params = snd_rme32_capture_hw_params, |
| 1234 | .hw_free = snd_rme32_pcm_hw_free, |
| 1235 | .prepare = snd_rme32_capture_prepare, |
| 1236 | .trigger = snd_rme32_pcm_trigger, |
| 1237 | .pointer = snd_rme32_capture_pointer, |
Takashi Iwai | 032db75 | 2017-05-10 20:29:25 +0200 | [diff] [blame^] | 1238 | .copy_user = snd_rme32_capture_copy, |
| 1239 | .copy_kernel = snd_rme32_capture_copy_kernel, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1240 | .mmap = snd_pcm_lib_mmap_iomem, |
| 1241 | }; |
| 1242 | |
Julia Lawall | 6769e988 | 2016-09-02 00:13:10 +0200 | [diff] [blame] | 1243 | static const struct snd_pcm_ops snd_rme32_playback_adat_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1244 | .open = snd_rme32_playback_adat_open, |
| 1245 | .close = snd_rme32_playback_close, |
| 1246 | .ioctl = snd_pcm_lib_ioctl, |
| 1247 | .hw_params = snd_rme32_playback_hw_params, |
| 1248 | .prepare = snd_rme32_playback_prepare, |
| 1249 | .trigger = snd_rme32_pcm_trigger, |
| 1250 | .pointer = snd_rme32_playback_pointer, |
Takashi Iwai | 032db75 | 2017-05-10 20:29:25 +0200 | [diff] [blame^] | 1251 | .copy_user = snd_rme32_playback_copy, |
| 1252 | .copy_kernel = snd_rme32_playback_copy_kernel, |
| 1253 | .fill_silence = snd_rme32_playback_silence, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1254 | .mmap = snd_pcm_lib_mmap_iomem, |
| 1255 | }; |
| 1256 | |
Julia Lawall | 6769e988 | 2016-09-02 00:13:10 +0200 | [diff] [blame] | 1257 | static const struct snd_pcm_ops snd_rme32_capture_adat_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1258 | .open = snd_rme32_capture_adat_open, |
| 1259 | .close = snd_rme32_capture_close, |
| 1260 | .ioctl = snd_pcm_lib_ioctl, |
| 1261 | .hw_params = snd_rme32_capture_hw_params, |
| 1262 | .prepare = snd_rme32_capture_prepare, |
| 1263 | .trigger = snd_rme32_pcm_trigger, |
| 1264 | .pointer = snd_rme32_capture_pointer, |
Takashi Iwai | 032db75 | 2017-05-10 20:29:25 +0200 | [diff] [blame^] | 1265 | .copy_user = snd_rme32_capture_copy, |
| 1266 | .copy_kernel = snd_rme32_capture_copy_kernel, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1267 | .mmap = snd_pcm_lib_mmap_iomem, |
| 1268 | }; |
| 1269 | |
| 1270 | /* for fullduplex mode */ |
Julia Lawall | 6769e988 | 2016-09-02 00:13:10 +0200 | [diff] [blame] | 1271 | static const struct snd_pcm_ops snd_rme32_playback_spdif_fd_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1272 | .open = snd_rme32_playback_spdif_open, |
| 1273 | .close = snd_rme32_playback_close, |
| 1274 | .ioctl = snd_pcm_lib_ioctl, |
| 1275 | .hw_params = snd_rme32_playback_hw_params, |
| 1276 | .hw_free = snd_rme32_pcm_hw_free, |
| 1277 | .prepare = snd_rme32_playback_prepare, |
| 1278 | .trigger = snd_rme32_pcm_trigger, |
| 1279 | .pointer = snd_rme32_playback_fd_pointer, |
| 1280 | .ack = snd_rme32_playback_fd_ack, |
| 1281 | }; |
| 1282 | |
Julia Lawall | 6769e988 | 2016-09-02 00:13:10 +0200 | [diff] [blame] | 1283 | static const struct snd_pcm_ops snd_rme32_capture_spdif_fd_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1284 | .open = snd_rme32_capture_spdif_open, |
| 1285 | .close = snd_rme32_capture_close, |
| 1286 | .ioctl = snd_pcm_lib_ioctl, |
| 1287 | .hw_params = snd_rme32_capture_hw_params, |
| 1288 | .hw_free = snd_rme32_pcm_hw_free, |
| 1289 | .prepare = snd_rme32_capture_prepare, |
| 1290 | .trigger = snd_rme32_pcm_trigger, |
| 1291 | .pointer = snd_rme32_capture_fd_pointer, |
| 1292 | .ack = snd_rme32_capture_fd_ack, |
| 1293 | }; |
| 1294 | |
Julia Lawall | 6769e988 | 2016-09-02 00:13:10 +0200 | [diff] [blame] | 1295 | static const struct snd_pcm_ops snd_rme32_playback_adat_fd_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1296 | .open = snd_rme32_playback_adat_open, |
| 1297 | .close = snd_rme32_playback_close, |
| 1298 | .ioctl = snd_pcm_lib_ioctl, |
| 1299 | .hw_params = snd_rme32_playback_hw_params, |
| 1300 | .prepare = snd_rme32_playback_prepare, |
| 1301 | .trigger = snd_rme32_pcm_trigger, |
| 1302 | .pointer = snd_rme32_playback_fd_pointer, |
| 1303 | .ack = snd_rme32_playback_fd_ack, |
| 1304 | }; |
| 1305 | |
Julia Lawall | 6769e988 | 2016-09-02 00:13:10 +0200 | [diff] [blame] | 1306 | static const struct snd_pcm_ops snd_rme32_capture_adat_fd_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1307 | .open = snd_rme32_capture_adat_open, |
| 1308 | .close = snd_rme32_capture_close, |
| 1309 | .ioctl = snd_pcm_lib_ioctl, |
| 1310 | .hw_params = snd_rme32_capture_hw_params, |
| 1311 | .prepare = snd_rme32_capture_prepare, |
| 1312 | .trigger = snd_rme32_pcm_trigger, |
| 1313 | .pointer = snd_rme32_capture_fd_pointer, |
| 1314 | .ack = snd_rme32_capture_fd_ack, |
| 1315 | }; |
| 1316 | |
| 1317 | static void snd_rme32_free(void *private_data) |
| 1318 | { |
Takashi Iwai | 017ce80 | 2005-11-17 15:05:25 +0100 | [diff] [blame] | 1319 | struct rme32 *rme32 = (struct rme32 *) private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1320 | |
| 1321 | if (rme32 == NULL) { |
| 1322 | return; |
| 1323 | } |
| 1324 | if (rme32->irq >= 0) { |
| 1325 | snd_rme32_pcm_stop(rme32, 0); |
| 1326 | free_irq(rme32->irq, (void *) rme32); |
| 1327 | rme32->irq = -1; |
| 1328 | } |
| 1329 | if (rme32->iobase) { |
| 1330 | iounmap(rme32->iobase); |
| 1331 | rme32->iobase = NULL; |
| 1332 | } |
| 1333 | if (rme32->port) { |
| 1334 | pci_release_regions(rme32->pci); |
| 1335 | rme32->port = 0; |
| 1336 | } |
| 1337 | pci_disable_device(rme32->pci); |
| 1338 | } |
| 1339 | |
Takashi Iwai | 017ce80 | 2005-11-17 15:05:25 +0100 | [diff] [blame] | 1340 | static void snd_rme32_free_spdif_pcm(struct snd_pcm *pcm) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1341 | { |
Takashi Iwai | 017ce80 | 2005-11-17 15:05:25 +0100 | [diff] [blame] | 1342 | struct rme32 *rme32 = (struct rme32 *) pcm->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1343 | rme32->spdif_pcm = NULL; |
| 1344 | } |
| 1345 | |
| 1346 | static void |
Takashi Iwai | 017ce80 | 2005-11-17 15:05:25 +0100 | [diff] [blame] | 1347 | snd_rme32_free_adat_pcm(struct snd_pcm *pcm) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1348 | { |
Takashi Iwai | 017ce80 | 2005-11-17 15:05:25 +0100 | [diff] [blame] | 1349 | struct rme32 *rme32 = (struct rme32 *) pcm->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1350 | rme32->adat_pcm = NULL; |
| 1351 | } |
| 1352 | |
Bill Pemberton | e23e7a1 | 2012-12-06 12:35:10 -0500 | [diff] [blame] | 1353 | static int snd_rme32_create(struct rme32 *rme32) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1354 | { |
| 1355 | struct pci_dev *pci = rme32->pci; |
| 1356 | int err; |
| 1357 | |
| 1358 | rme32->irq = -1; |
| 1359 | spin_lock_init(&rme32->lock); |
| 1360 | |
| 1361 | if ((err = pci_enable_device(pci)) < 0) |
| 1362 | return err; |
| 1363 | |
| 1364 | if ((err = pci_request_regions(pci, "RME32")) < 0) |
| 1365 | return err; |
| 1366 | rme32->port = pci_resource_start(rme32->pci, 0); |
| 1367 | |
Harvey Harrison | 4db9e4f | 2008-02-28 11:57:23 +0100 | [diff] [blame] | 1368 | rme32->iobase = ioremap_nocache(rme32->port, RME32_IO_SIZE); |
| 1369 | if (!rme32->iobase) { |
Takashi Iwai | 03952a3 | 2014-02-25 14:57:03 +0100 | [diff] [blame] | 1370 | dev_err(rme32->card->dev, |
| 1371 | "unable to remap memory region 0x%lx-0x%lx\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1372 | rme32->port, rme32->port + RME32_IO_SIZE - 1); |
| 1373 | return -ENOMEM; |
| 1374 | } |
| 1375 | |
Takashi Iwai | 437a5a4 | 2006-11-21 12:14:23 +0100 | [diff] [blame] | 1376 | if (request_irq(pci->irq, snd_rme32_interrupt, IRQF_SHARED, |
Takashi Iwai | 934c2b6 | 2011-06-10 16:36:37 +0200 | [diff] [blame] | 1377 | KBUILD_MODNAME, rme32)) { |
Takashi Iwai | 03952a3 | 2014-02-25 14:57:03 +0100 | [diff] [blame] | 1378 | dev_err(rme32->card->dev, "unable to grab IRQ %d\n", pci->irq); |
Takashi Iwai | 688956f2 | 2006-06-06 15:44:34 +0200 | [diff] [blame] | 1379 | return -EBUSY; |
| 1380 | } |
| 1381 | rme32->irq = pci->irq; |
| 1382 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1383 | /* read the card's revision number */ |
| 1384 | pci_read_config_byte(pci, 8, &rme32->rev); |
| 1385 | |
| 1386 | /* set up ALSA pcm device for S/PDIF */ |
| 1387 | if ((err = snd_pcm_new(rme32->card, "Digi32 IEC958", 0, 1, 1, &rme32->spdif_pcm)) < 0) { |
| 1388 | return err; |
| 1389 | } |
| 1390 | rme32->spdif_pcm->private_data = rme32; |
| 1391 | rme32->spdif_pcm->private_free = snd_rme32_free_spdif_pcm; |
| 1392 | strcpy(rme32->spdif_pcm->name, "Digi32 IEC958"); |
| 1393 | if (rme32->fullduplex_mode) { |
| 1394 | snd_pcm_set_ops(rme32->spdif_pcm, SNDRV_PCM_STREAM_PLAYBACK, |
| 1395 | &snd_rme32_playback_spdif_fd_ops); |
| 1396 | snd_pcm_set_ops(rme32->spdif_pcm, SNDRV_PCM_STREAM_CAPTURE, |
| 1397 | &snd_rme32_capture_spdif_fd_ops); |
| 1398 | snd_pcm_lib_preallocate_pages_for_all(rme32->spdif_pcm, SNDRV_DMA_TYPE_CONTINUOUS, |
| 1399 | snd_dma_continuous_data(GFP_KERNEL), |
| 1400 | 0, RME32_MID_BUFFER_SIZE); |
| 1401 | rme32->spdif_pcm->info_flags = SNDRV_PCM_INFO_JOINT_DUPLEX; |
| 1402 | } else { |
| 1403 | snd_pcm_set_ops(rme32->spdif_pcm, SNDRV_PCM_STREAM_PLAYBACK, |
| 1404 | &snd_rme32_playback_spdif_ops); |
| 1405 | snd_pcm_set_ops(rme32->spdif_pcm, SNDRV_PCM_STREAM_CAPTURE, |
| 1406 | &snd_rme32_capture_spdif_ops); |
| 1407 | rme32->spdif_pcm->info_flags = SNDRV_PCM_INFO_HALF_DUPLEX; |
| 1408 | } |
| 1409 | |
| 1410 | /* set up ALSA pcm device for ADAT */ |
Roland Dreier | 8b7fc42 | 2005-09-14 14:19:17 -0700 | [diff] [blame] | 1411 | if ((pci->device == PCI_DEVICE_ID_RME_DIGI32) || |
| 1412 | (pci->device == PCI_DEVICE_ID_RME_DIGI32_PRO)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1413 | /* ADAT is not available on DIGI32 and DIGI32 Pro */ |
| 1414 | rme32->adat_pcm = NULL; |
| 1415 | } |
| 1416 | else { |
| 1417 | if ((err = snd_pcm_new(rme32->card, "Digi32 ADAT", 1, |
| 1418 | 1, 1, &rme32->adat_pcm)) < 0) |
| 1419 | { |
| 1420 | return err; |
| 1421 | } |
| 1422 | rme32->adat_pcm->private_data = rme32; |
| 1423 | rme32->adat_pcm->private_free = snd_rme32_free_adat_pcm; |
| 1424 | strcpy(rme32->adat_pcm->name, "Digi32 ADAT"); |
| 1425 | if (rme32->fullduplex_mode) { |
| 1426 | snd_pcm_set_ops(rme32->adat_pcm, SNDRV_PCM_STREAM_PLAYBACK, |
| 1427 | &snd_rme32_playback_adat_fd_ops); |
| 1428 | snd_pcm_set_ops(rme32->adat_pcm, SNDRV_PCM_STREAM_CAPTURE, |
| 1429 | &snd_rme32_capture_adat_fd_ops); |
| 1430 | snd_pcm_lib_preallocate_pages_for_all(rme32->adat_pcm, SNDRV_DMA_TYPE_CONTINUOUS, |
| 1431 | snd_dma_continuous_data(GFP_KERNEL), |
| 1432 | 0, RME32_MID_BUFFER_SIZE); |
| 1433 | rme32->adat_pcm->info_flags = SNDRV_PCM_INFO_JOINT_DUPLEX; |
| 1434 | } else { |
| 1435 | snd_pcm_set_ops(rme32->adat_pcm, SNDRV_PCM_STREAM_PLAYBACK, |
| 1436 | &snd_rme32_playback_adat_ops); |
| 1437 | snd_pcm_set_ops(rme32->adat_pcm, SNDRV_PCM_STREAM_CAPTURE, |
| 1438 | &snd_rme32_capture_adat_ops); |
| 1439 | rme32->adat_pcm->info_flags = SNDRV_PCM_INFO_HALF_DUPLEX; |
| 1440 | } |
| 1441 | } |
| 1442 | |
| 1443 | |
| 1444 | rme32->playback_periodsize = 0; |
| 1445 | rme32->capture_periodsize = 0; |
| 1446 | |
| 1447 | /* make sure playback/capture is stopped, if by some reason active */ |
| 1448 | snd_rme32_pcm_stop(rme32, 0); |
| 1449 | |
| 1450 | /* reset DAC */ |
| 1451 | snd_rme32_reset_dac(rme32); |
| 1452 | |
| 1453 | /* reset buffer pointer */ |
| 1454 | writel(0, rme32->iobase + RME32_IO_RESET_POS); |
| 1455 | |
| 1456 | /* set default values in registers */ |
| 1457 | rme32->wcreg = RME32_WCR_SEL | /* normal playback */ |
| 1458 | RME32_WCR_INP_0 | /* input select */ |
| 1459 | RME32_WCR_MUTE; /* muting on */ |
| 1460 | writel(rme32->wcreg, rme32->iobase + RME32_IO_CONTROL_REGISTER); |
| 1461 | |
| 1462 | |
| 1463 | /* init switch interface */ |
| 1464 | if ((err = snd_rme32_create_switches(rme32->card, rme32)) < 0) { |
| 1465 | return err; |
| 1466 | } |
| 1467 | |
| 1468 | /* init proc interface */ |
| 1469 | snd_rme32_proc_init(rme32); |
| 1470 | |
| 1471 | rme32->capture_substream = NULL; |
| 1472 | rme32->playback_substream = NULL; |
| 1473 | |
| 1474 | return 0; |
| 1475 | } |
| 1476 | |
| 1477 | /* |
| 1478 | * proc interface |
| 1479 | */ |
| 1480 | |
| 1481 | static void |
Takashi Iwai | 017ce80 | 2005-11-17 15:05:25 +0100 | [diff] [blame] | 1482 | snd_rme32_proc_read(struct snd_info_entry * entry, struct snd_info_buffer *buffer) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1483 | { |
| 1484 | int n; |
Takashi Iwai | 017ce80 | 2005-11-17 15:05:25 +0100 | [diff] [blame] | 1485 | struct rme32 *rme32 = (struct rme32 *) entry->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1486 | |
| 1487 | rme32->rcreg = readl(rme32->iobase + RME32_IO_CONTROL_REGISTER); |
| 1488 | |
| 1489 | snd_iprintf(buffer, rme32->card->longname); |
| 1490 | snd_iprintf(buffer, " (index #%d)\n", rme32->card->number + 1); |
| 1491 | |
| 1492 | snd_iprintf(buffer, "\nGeneral settings\n"); |
| 1493 | if (rme32->fullduplex_mode) |
| 1494 | snd_iprintf(buffer, " Full-duplex mode\n"); |
| 1495 | else |
| 1496 | snd_iprintf(buffer, " Half-duplex mode\n"); |
| 1497 | if (RME32_PRO_WITH_8414(rme32)) { |
| 1498 | snd_iprintf(buffer, " receiver: CS8414\n"); |
| 1499 | } else { |
| 1500 | snd_iprintf(buffer, " receiver: CS8412\n"); |
| 1501 | } |
| 1502 | if (rme32->wcreg & RME32_WCR_MODE24) { |
| 1503 | snd_iprintf(buffer, " format: 24 bit"); |
| 1504 | } else { |
| 1505 | snd_iprintf(buffer, " format: 16 bit"); |
| 1506 | } |
| 1507 | if (rme32->wcreg & RME32_WCR_MONO) { |
| 1508 | snd_iprintf(buffer, ", Mono\n"); |
| 1509 | } else { |
| 1510 | snd_iprintf(buffer, ", Stereo\n"); |
| 1511 | } |
| 1512 | |
| 1513 | snd_iprintf(buffer, "\nInput settings\n"); |
| 1514 | switch (snd_rme32_getinputtype(rme32)) { |
| 1515 | case RME32_INPUT_OPTICAL: |
| 1516 | snd_iprintf(buffer, " input: optical"); |
| 1517 | break; |
| 1518 | case RME32_INPUT_COAXIAL: |
| 1519 | snd_iprintf(buffer, " input: coaxial"); |
| 1520 | break; |
| 1521 | case RME32_INPUT_INTERNAL: |
| 1522 | snd_iprintf(buffer, " input: internal"); |
| 1523 | break; |
| 1524 | case RME32_INPUT_XLR: |
| 1525 | snd_iprintf(buffer, " input: XLR"); |
| 1526 | break; |
| 1527 | } |
| 1528 | if (snd_rme32_capture_getrate(rme32, &n) < 0) { |
| 1529 | snd_iprintf(buffer, "\n sample rate: no valid signal\n"); |
| 1530 | } else { |
| 1531 | if (n) { |
| 1532 | snd_iprintf(buffer, " (8 channels)\n"); |
| 1533 | } else { |
| 1534 | snd_iprintf(buffer, " (2 channels)\n"); |
| 1535 | } |
| 1536 | snd_iprintf(buffer, " sample rate: %d Hz\n", |
| 1537 | snd_rme32_capture_getrate(rme32, &n)); |
| 1538 | } |
| 1539 | |
| 1540 | snd_iprintf(buffer, "\nOutput settings\n"); |
| 1541 | if (rme32->wcreg & RME32_WCR_SEL) { |
| 1542 | snd_iprintf(buffer, " output signal: normal playback"); |
| 1543 | } else { |
| 1544 | snd_iprintf(buffer, " output signal: same as input"); |
| 1545 | } |
| 1546 | if (rme32->wcreg & RME32_WCR_MUTE) { |
| 1547 | snd_iprintf(buffer, " (muted)\n"); |
| 1548 | } else { |
| 1549 | snd_iprintf(buffer, "\n"); |
| 1550 | } |
| 1551 | |
| 1552 | /* master output frequency */ |
| 1553 | if (! |
| 1554 | ((!(rme32->wcreg & RME32_WCR_FREQ_0)) |
| 1555 | && (!(rme32->wcreg & RME32_WCR_FREQ_1)))) { |
| 1556 | snd_iprintf(buffer, " sample rate: %d Hz\n", |
| 1557 | snd_rme32_playback_getrate(rme32)); |
| 1558 | } |
| 1559 | if (rme32->rcreg & RME32_RCR_KMODE) { |
| 1560 | snd_iprintf(buffer, " sample clock source: AutoSync\n"); |
| 1561 | } else { |
| 1562 | snd_iprintf(buffer, " sample clock source: Internal\n"); |
| 1563 | } |
| 1564 | if (rme32->wcreg & RME32_WCR_PRO) { |
| 1565 | snd_iprintf(buffer, " format: AES/EBU (professional)\n"); |
| 1566 | } else { |
| 1567 | snd_iprintf(buffer, " format: IEC958 (consumer)\n"); |
| 1568 | } |
| 1569 | if (rme32->wcreg & RME32_WCR_EMP) { |
| 1570 | snd_iprintf(buffer, " emphasis: on\n"); |
| 1571 | } else { |
| 1572 | snd_iprintf(buffer, " emphasis: off\n"); |
| 1573 | } |
| 1574 | } |
| 1575 | |
Bill Pemberton | e23e7a1 | 2012-12-06 12:35:10 -0500 | [diff] [blame] | 1576 | static void snd_rme32_proc_init(struct rme32 *rme32) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1577 | { |
Takashi Iwai | 017ce80 | 2005-11-17 15:05:25 +0100 | [diff] [blame] | 1578 | struct snd_info_entry *entry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1579 | |
| 1580 | if (! snd_card_proc_new(rme32->card, "rme32", &entry)) |
Takashi Iwai | bf85020 | 2006-04-28 15:13:41 +0200 | [diff] [blame] | 1581 | snd_info_set_text_ops(entry, rme32, snd_rme32_proc_read); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1582 | } |
| 1583 | |
| 1584 | /* |
| 1585 | * control interface |
| 1586 | */ |
| 1587 | |
Takashi Iwai | a5ce889 | 2007-07-23 15:42:26 +0200 | [diff] [blame] | 1588 | #define snd_rme32_info_loopback_control snd_ctl_boolean_mono_info |
| 1589 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1590 | static int |
Takashi Iwai | 017ce80 | 2005-11-17 15:05:25 +0100 | [diff] [blame] | 1591 | snd_rme32_get_loopback_control(struct snd_kcontrol *kcontrol, |
| 1592 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1593 | { |
Takashi Iwai | 017ce80 | 2005-11-17 15:05:25 +0100 | [diff] [blame] | 1594 | struct rme32 *rme32 = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1595 | |
| 1596 | spin_lock_irq(&rme32->lock); |
| 1597 | ucontrol->value.integer.value[0] = |
| 1598 | rme32->wcreg & RME32_WCR_SEL ? 0 : 1; |
| 1599 | spin_unlock_irq(&rme32->lock); |
| 1600 | return 0; |
| 1601 | } |
| 1602 | static int |
Takashi Iwai | 017ce80 | 2005-11-17 15:05:25 +0100 | [diff] [blame] | 1603 | snd_rme32_put_loopback_control(struct snd_kcontrol *kcontrol, |
| 1604 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1605 | { |
Takashi Iwai | 017ce80 | 2005-11-17 15:05:25 +0100 | [diff] [blame] | 1606 | struct rme32 *rme32 = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1607 | unsigned int val; |
| 1608 | int change; |
| 1609 | |
| 1610 | val = ucontrol->value.integer.value[0] ? 0 : RME32_WCR_SEL; |
| 1611 | spin_lock_irq(&rme32->lock); |
| 1612 | val = (rme32->wcreg & ~RME32_WCR_SEL) | val; |
| 1613 | change = val != rme32->wcreg; |
| 1614 | if (ucontrol->value.integer.value[0]) |
| 1615 | val &= ~RME32_WCR_MUTE; |
| 1616 | else |
| 1617 | val |= RME32_WCR_MUTE; |
| 1618 | rme32->wcreg = val; |
| 1619 | writel(val, rme32->iobase + RME32_IO_CONTROL_REGISTER); |
| 1620 | spin_unlock_irq(&rme32->lock); |
| 1621 | return change; |
| 1622 | } |
| 1623 | |
| 1624 | static int |
Takashi Iwai | 017ce80 | 2005-11-17 15:05:25 +0100 | [diff] [blame] | 1625 | snd_rme32_info_inputtype_control(struct snd_kcontrol *kcontrol, |
| 1626 | struct snd_ctl_elem_info *uinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1627 | { |
Takashi Iwai | 017ce80 | 2005-11-17 15:05:25 +0100 | [diff] [blame] | 1628 | struct rme32 *rme32 = snd_kcontrol_chip(kcontrol); |
Takashi Iwai | 11c6ef7 | 2014-10-20 18:19:12 +0200 | [diff] [blame] | 1629 | static const char * const texts[4] = { |
| 1630 | "Optical", "Coaxial", "Internal", "XLR" |
| 1631 | }; |
| 1632 | int num_items; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1633 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1634 | switch (rme32->pci->device) { |
Roland Dreier | 8b7fc42 | 2005-09-14 14:19:17 -0700 | [diff] [blame] | 1635 | case PCI_DEVICE_ID_RME_DIGI32: |
| 1636 | case PCI_DEVICE_ID_RME_DIGI32_8: |
Takashi Iwai | 11c6ef7 | 2014-10-20 18:19:12 +0200 | [diff] [blame] | 1637 | num_items = 3; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1638 | break; |
Roland Dreier | 8b7fc42 | 2005-09-14 14:19:17 -0700 | [diff] [blame] | 1639 | case PCI_DEVICE_ID_RME_DIGI32_PRO: |
Takashi Iwai | 11c6ef7 | 2014-10-20 18:19:12 +0200 | [diff] [blame] | 1640 | num_items = 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1641 | break; |
| 1642 | default: |
| 1643 | snd_BUG(); |
Takashi Iwai | 11c6ef7 | 2014-10-20 18:19:12 +0200 | [diff] [blame] | 1644 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1645 | } |
Takashi Iwai | 11c6ef7 | 2014-10-20 18:19:12 +0200 | [diff] [blame] | 1646 | return snd_ctl_enum_info(uinfo, 1, num_items, texts); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1647 | } |
| 1648 | static int |
Takashi Iwai | 017ce80 | 2005-11-17 15:05:25 +0100 | [diff] [blame] | 1649 | snd_rme32_get_inputtype_control(struct snd_kcontrol *kcontrol, |
| 1650 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1651 | { |
Takashi Iwai | 017ce80 | 2005-11-17 15:05:25 +0100 | [diff] [blame] | 1652 | struct rme32 *rme32 = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1653 | unsigned int items = 3; |
| 1654 | |
| 1655 | spin_lock_irq(&rme32->lock); |
| 1656 | ucontrol->value.enumerated.item[0] = snd_rme32_getinputtype(rme32); |
| 1657 | |
| 1658 | switch (rme32->pci->device) { |
Roland Dreier | 8b7fc42 | 2005-09-14 14:19:17 -0700 | [diff] [blame] | 1659 | case PCI_DEVICE_ID_RME_DIGI32: |
| 1660 | case PCI_DEVICE_ID_RME_DIGI32_8: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1661 | items = 3; |
| 1662 | break; |
Roland Dreier | 8b7fc42 | 2005-09-14 14:19:17 -0700 | [diff] [blame] | 1663 | case PCI_DEVICE_ID_RME_DIGI32_PRO: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1664 | items = 4; |
| 1665 | break; |
| 1666 | default: |
| 1667 | snd_BUG(); |
| 1668 | break; |
| 1669 | } |
| 1670 | if (ucontrol->value.enumerated.item[0] >= items) { |
| 1671 | ucontrol->value.enumerated.item[0] = items - 1; |
| 1672 | } |
| 1673 | |
| 1674 | spin_unlock_irq(&rme32->lock); |
| 1675 | return 0; |
| 1676 | } |
| 1677 | static int |
Takashi Iwai | 017ce80 | 2005-11-17 15:05:25 +0100 | [diff] [blame] | 1678 | snd_rme32_put_inputtype_control(struct snd_kcontrol *kcontrol, |
| 1679 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1680 | { |
Takashi Iwai | 017ce80 | 2005-11-17 15:05:25 +0100 | [diff] [blame] | 1681 | struct rme32 *rme32 = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1682 | unsigned int val; |
| 1683 | int change, items = 3; |
| 1684 | |
| 1685 | switch (rme32->pci->device) { |
Roland Dreier | 8b7fc42 | 2005-09-14 14:19:17 -0700 | [diff] [blame] | 1686 | case PCI_DEVICE_ID_RME_DIGI32: |
| 1687 | case PCI_DEVICE_ID_RME_DIGI32_8: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1688 | items = 3; |
| 1689 | break; |
Roland Dreier | 8b7fc42 | 2005-09-14 14:19:17 -0700 | [diff] [blame] | 1690 | case PCI_DEVICE_ID_RME_DIGI32_PRO: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1691 | items = 4; |
| 1692 | break; |
| 1693 | default: |
| 1694 | snd_BUG(); |
| 1695 | break; |
| 1696 | } |
| 1697 | val = ucontrol->value.enumerated.item[0] % items; |
| 1698 | |
| 1699 | spin_lock_irq(&rme32->lock); |
| 1700 | change = val != (unsigned int)snd_rme32_getinputtype(rme32); |
| 1701 | snd_rme32_setinputtype(rme32, val); |
| 1702 | spin_unlock_irq(&rme32->lock); |
| 1703 | return change; |
| 1704 | } |
| 1705 | |
| 1706 | static int |
Takashi Iwai | 017ce80 | 2005-11-17 15:05:25 +0100 | [diff] [blame] | 1707 | snd_rme32_info_clockmode_control(struct snd_kcontrol *kcontrol, |
| 1708 | struct snd_ctl_elem_info *uinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1709 | { |
Takashi Iwai | 11c6ef7 | 2014-10-20 18:19:12 +0200 | [diff] [blame] | 1710 | static const char * const texts[4] = { "AutoSync", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1711 | "Internal 32.0kHz", |
| 1712 | "Internal 44.1kHz", |
| 1713 | "Internal 48.0kHz" }; |
| 1714 | |
Takashi Iwai | 11c6ef7 | 2014-10-20 18:19:12 +0200 | [diff] [blame] | 1715 | return snd_ctl_enum_info(uinfo, 1, 4, texts); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1716 | } |
| 1717 | static int |
Takashi Iwai | 017ce80 | 2005-11-17 15:05:25 +0100 | [diff] [blame] | 1718 | snd_rme32_get_clockmode_control(struct snd_kcontrol *kcontrol, |
| 1719 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1720 | { |
Takashi Iwai | 017ce80 | 2005-11-17 15:05:25 +0100 | [diff] [blame] | 1721 | struct rme32 *rme32 = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1722 | |
| 1723 | spin_lock_irq(&rme32->lock); |
| 1724 | ucontrol->value.enumerated.item[0] = snd_rme32_getclockmode(rme32); |
| 1725 | spin_unlock_irq(&rme32->lock); |
| 1726 | return 0; |
| 1727 | } |
| 1728 | static int |
Takashi Iwai | 017ce80 | 2005-11-17 15:05:25 +0100 | [diff] [blame] | 1729 | snd_rme32_put_clockmode_control(struct snd_kcontrol *kcontrol, |
| 1730 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1731 | { |
Takashi Iwai | 017ce80 | 2005-11-17 15:05:25 +0100 | [diff] [blame] | 1732 | struct rme32 *rme32 = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1733 | unsigned int val; |
| 1734 | int change; |
| 1735 | |
| 1736 | val = ucontrol->value.enumerated.item[0] % 3; |
| 1737 | spin_lock_irq(&rme32->lock); |
| 1738 | change = val != (unsigned int)snd_rme32_getclockmode(rme32); |
| 1739 | snd_rme32_setclockmode(rme32, val); |
| 1740 | spin_unlock_irq(&rme32->lock); |
| 1741 | return change; |
| 1742 | } |
| 1743 | |
Takashi Iwai | 017ce80 | 2005-11-17 15:05:25 +0100 | [diff] [blame] | 1744 | static u32 snd_rme32_convert_from_aes(struct snd_aes_iec958 * aes) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1745 | { |
| 1746 | u32 val = 0; |
| 1747 | val |= (aes->status[0] & IEC958_AES0_PROFESSIONAL) ? RME32_WCR_PRO : 0; |
| 1748 | if (val & RME32_WCR_PRO) |
| 1749 | val |= (aes->status[0] & IEC958_AES0_PRO_EMPHASIS_5015) ? RME32_WCR_EMP : 0; |
| 1750 | else |
| 1751 | val |= (aes->status[0] & IEC958_AES0_CON_EMPHASIS_5015) ? RME32_WCR_EMP : 0; |
| 1752 | return val; |
| 1753 | } |
| 1754 | |
Takashi Iwai | 017ce80 | 2005-11-17 15:05:25 +0100 | [diff] [blame] | 1755 | static void snd_rme32_convert_to_aes(struct snd_aes_iec958 * aes, u32 val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1756 | { |
| 1757 | aes->status[0] = ((val & RME32_WCR_PRO) ? IEC958_AES0_PROFESSIONAL : 0); |
| 1758 | if (val & RME32_WCR_PRO) |
| 1759 | aes->status[0] |= (val & RME32_WCR_EMP) ? IEC958_AES0_PRO_EMPHASIS_5015 : 0; |
| 1760 | else |
| 1761 | aes->status[0] |= (val & RME32_WCR_EMP) ? IEC958_AES0_CON_EMPHASIS_5015 : 0; |
| 1762 | } |
| 1763 | |
Takashi Iwai | 017ce80 | 2005-11-17 15:05:25 +0100 | [diff] [blame] | 1764 | static int snd_rme32_control_spdif_info(struct snd_kcontrol *kcontrol, |
| 1765 | struct snd_ctl_elem_info *uinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1766 | { |
| 1767 | uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958; |
| 1768 | uinfo->count = 1; |
| 1769 | return 0; |
| 1770 | } |
| 1771 | |
Takashi Iwai | 017ce80 | 2005-11-17 15:05:25 +0100 | [diff] [blame] | 1772 | static int snd_rme32_control_spdif_get(struct snd_kcontrol *kcontrol, |
| 1773 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1774 | { |
Takashi Iwai | 017ce80 | 2005-11-17 15:05:25 +0100 | [diff] [blame] | 1775 | struct rme32 *rme32 = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1776 | |
| 1777 | snd_rme32_convert_to_aes(&ucontrol->value.iec958, |
| 1778 | rme32->wcreg_spdif); |
| 1779 | return 0; |
| 1780 | } |
| 1781 | |
Takashi Iwai | 017ce80 | 2005-11-17 15:05:25 +0100 | [diff] [blame] | 1782 | static int snd_rme32_control_spdif_put(struct snd_kcontrol *kcontrol, |
| 1783 | struct snd_ctl_elem_value *ucontrol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1784 | { |
Takashi Iwai | 017ce80 | 2005-11-17 15:05:25 +0100 | [diff] [blame] | 1785 | struct rme32 *rme32 = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1786 | int change; |
| 1787 | u32 val; |
| 1788 | |
| 1789 | val = snd_rme32_convert_from_aes(&ucontrol->value.iec958); |
| 1790 | spin_lock_irq(&rme32->lock); |
| 1791 | change = val != rme32->wcreg_spdif; |
| 1792 | rme32->wcreg_spdif = val; |
| 1793 | spin_unlock_irq(&rme32->lock); |
| 1794 | return change; |
| 1795 | } |
| 1796 | |
Takashi Iwai | 017ce80 | 2005-11-17 15:05:25 +0100 | [diff] [blame] | 1797 | static int snd_rme32_control_spdif_stream_info(struct snd_kcontrol *kcontrol, |
| 1798 | struct snd_ctl_elem_info *uinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1799 | { |
| 1800 | uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958; |
| 1801 | uinfo->count = 1; |
| 1802 | return 0; |
| 1803 | } |
| 1804 | |
Takashi Iwai | 017ce80 | 2005-11-17 15:05:25 +0100 | [diff] [blame] | 1805 | static int snd_rme32_control_spdif_stream_get(struct snd_kcontrol *kcontrol, |
| 1806 | struct snd_ctl_elem_value * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1807 | ucontrol) |
| 1808 | { |
Takashi Iwai | 017ce80 | 2005-11-17 15:05:25 +0100 | [diff] [blame] | 1809 | struct rme32 *rme32 = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1810 | |
| 1811 | snd_rme32_convert_to_aes(&ucontrol->value.iec958, |
| 1812 | rme32->wcreg_spdif_stream); |
| 1813 | return 0; |
| 1814 | } |
| 1815 | |
Takashi Iwai | 017ce80 | 2005-11-17 15:05:25 +0100 | [diff] [blame] | 1816 | static int snd_rme32_control_spdif_stream_put(struct snd_kcontrol *kcontrol, |
| 1817 | struct snd_ctl_elem_value * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1818 | ucontrol) |
| 1819 | { |
Takashi Iwai | 017ce80 | 2005-11-17 15:05:25 +0100 | [diff] [blame] | 1820 | struct rme32 *rme32 = snd_kcontrol_chip(kcontrol); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1821 | int change; |
| 1822 | u32 val; |
| 1823 | |
| 1824 | val = snd_rme32_convert_from_aes(&ucontrol->value.iec958); |
| 1825 | spin_lock_irq(&rme32->lock); |
| 1826 | change = val != rme32->wcreg_spdif_stream; |
| 1827 | rme32->wcreg_spdif_stream = val; |
| 1828 | rme32->wcreg &= ~(RME32_WCR_PRO | RME32_WCR_EMP); |
| 1829 | rme32->wcreg |= val; |
| 1830 | writel(rme32->wcreg, rme32->iobase + RME32_IO_CONTROL_REGISTER); |
| 1831 | spin_unlock_irq(&rme32->lock); |
| 1832 | return change; |
| 1833 | } |
| 1834 | |
Takashi Iwai | 017ce80 | 2005-11-17 15:05:25 +0100 | [diff] [blame] | 1835 | static int snd_rme32_control_spdif_mask_info(struct snd_kcontrol *kcontrol, |
| 1836 | struct snd_ctl_elem_info *uinfo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1837 | { |
| 1838 | uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958; |
| 1839 | uinfo->count = 1; |
| 1840 | return 0; |
| 1841 | } |
| 1842 | |
Takashi Iwai | 017ce80 | 2005-11-17 15:05:25 +0100 | [diff] [blame] | 1843 | static int snd_rme32_control_spdif_mask_get(struct snd_kcontrol *kcontrol, |
| 1844 | struct snd_ctl_elem_value * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1845 | ucontrol) |
| 1846 | { |
| 1847 | ucontrol->value.iec958.status[0] = kcontrol->private_value; |
| 1848 | return 0; |
| 1849 | } |
| 1850 | |
Takashi Iwai | 017ce80 | 2005-11-17 15:05:25 +0100 | [diff] [blame] | 1851 | static struct snd_kcontrol_new snd_rme32_controls[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1852 | { |
| 1853 | .iface = SNDRV_CTL_ELEM_IFACE_PCM, |
| 1854 | .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, DEFAULT), |
| 1855 | .info = snd_rme32_control_spdif_info, |
| 1856 | .get = snd_rme32_control_spdif_get, |
| 1857 | .put = snd_rme32_control_spdif_put |
| 1858 | }, |
| 1859 | { |
| 1860 | .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_INACTIVE, |
| 1861 | .iface = SNDRV_CTL_ELEM_IFACE_PCM, |
| 1862 | .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, PCM_STREAM), |
| 1863 | .info = snd_rme32_control_spdif_stream_info, |
| 1864 | .get = snd_rme32_control_spdif_stream_get, |
| 1865 | .put = snd_rme32_control_spdif_stream_put |
| 1866 | }, |
| 1867 | { |
| 1868 | .access = SNDRV_CTL_ELEM_ACCESS_READ, |
Clemens Ladisch | 67ed416 | 2005-07-29 15:32:58 +0200 | [diff] [blame] | 1869 | .iface = SNDRV_CTL_ELEM_IFACE_PCM, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1870 | .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, CON_MASK), |
| 1871 | .info = snd_rme32_control_spdif_mask_info, |
| 1872 | .get = snd_rme32_control_spdif_mask_get, |
| 1873 | .private_value = IEC958_AES0_PROFESSIONAL | IEC958_AES0_CON_EMPHASIS |
| 1874 | }, |
| 1875 | { |
| 1876 | .access = SNDRV_CTL_ELEM_ACCESS_READ, |
Clemens Ladisch | 67ed416 | 2005-07-29 15:32:58 +0200 | [diff] [blame] | 1877 | .iface = SNDRV_CTL_ELEM_IFACE_PCM, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1878 | .name = SNDRV_CTL_NAME_IEC958("", PLAYBACK, PRO_MASK), |
| 1879 | .info = snd_rme32_control_spdif_mask_info, |
| 1880 | .get = snd_rme32_control_spdif_mask_get, |
| 1881 | .private_value = IEC958_AES0_PROFESSIONAL | IEC958_AES0_PRO_EMPHASIS |
| 1882 | }, |
| 1883 | { |
| 1884 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 1885 | .name = "Input Connector", |
| 1886 | .info = snd_rme32_info_inputtype_control, |
| 1887 | .get = snd_rme32_get_inputtype_control, |
| 1888 | .put = snd_rme32_put_inputtype_control |
| 1889 | }, |
| 1890 | { |
| 1891 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 1892 | .name = "Loopback Input", |
| 1893 | .info = snd_rme32_info_loopback_control, |
| 1894 | .get = snd_rme32_get_loopback_control, |
| 1895 | .put = snd_rme32_put_loopback_control |
| 1896 | }, |
| 1897 | { |
| 1898 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, |
| 1899 | .name = "Sample Clock Source", |
| 1900 | .info = snd_rme32_info_clockmode_control, |
| 1901 | .get = snd_rme32_get_clockmode_control, |
| 1902 | .put = snd_rme32_put_clockmode_control |
| 1903 | } |
| 1904 | }; |
| 1905 | |
Takashi Iwai | 017ce80 | 2005-11-17 15:05:25 +0100 | [diff] [blame] | 1906 | static int snd_rme32_create_switches(struct snd_card *card, struct rme32 * rme32) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1907 | { |
| 1908 | int idx, err; |
Takashi Iwai | 017ce80 | 2005-11-17 15:05:25 +0100 | [diff] [blame] | 1909 | struct snd_kcontrol *kctl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1910 | |
| 1911 | for (idx = 0; idx < (int)ARRAY_SIZE(snd_rme32_controls); idx++) { |
| 1912 | if ((err = snd_ctl_add(card, kctl = snd_ctl_new1(&snd_rme32_controls[idx], rme32))) < 0) |
| 1913 | return err; |
| 1914 | if (idx == 1) /* IEC958 (S/PDIF) Stream */ |
| 1915 | rme32->spdif_ctl = kctl; |
| 1916 | } |
| 1917 | |
| 1918 | return 0; |
| 1919 | } |
| 1920 | |
| 1921 | /* |
| 1922 | * Card initialisation |
| 1923 | */ |
| 1924 | |
Takashi Iwai | 017ce80 | 2005-11-17 15:05:25 +0100 | [diff] [blame] | 1925 | static void snd_rme32_card_free(struct snd_card *card) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1926 | { |
| 1927 | snd_rme32_free(card->private_data); |
| 1928 | } |
| 1929 | |
Bill Pemberton | e23e7a1 | 2012-12-06 12:35:10 -0500 | [diff] [blame] | 1930 | static int |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1931 | snd_rme32_probe(struct pci_dev *pci, const struct pci_device_id *pci_id) |
| 1932 | { |
| 1933 | static int dev; |
Takashi Iwai | 017ce80 | 2005-11-17 15:05:25 +0100 | [diff] [blame] | 1934 | struct rme32 *rme32; |
| 1935 | struct snd_card *card; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1936 | int err; |
| 1937 | |
| 1938 | if (dev >= SNDRV_CARDS) { |
| 1939 | return -ENODEV; |
| 1940 | } |
| 1941 | if (!enable[dev]) { |
| 1942 | dev++; |
| 1943 | return -ENOENT; |
| 1944 | } |
| 1945 | |
Takashi Iwai | 60c5772 | 2014-01-29 14:20:19 +0100 | [diff] [blame] | 1946 | err = snd_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE, |
| 1947 | sizeof(struct rme32), &card); |
Takashi Iwai | e58de7b | 2008-12-28 16:44:30 +0100 | [diff] [blame] | 1948 | if (err < 0) |
| 1949 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1950 | card->private_free = snd_rme32_card_free; |
Takashi Iwai | 017ce80 | 2005-11-17 15:05:25 +0100 | [diff] [blame] | 1951 | rme32 = (struct rme32 *) card->private_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1952 | rme32->card = card; |
| 1953 | rme32->pci = pci; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1954 | if (fullduplex[dev]) |
| 1955 | rme32->fullduplex_mode = 1; |
| 1956 | if ((err = snd_rme32_create(rme32)) < 0) { |
| 1957 | snd_card_free(card); |
| 1958 | return err; |
| 1959 | } |
| 1960 | |
| 1961 | strcpy(card->driver, "Digi32"); |
| 1962 | switch (rme32->pci->device) { |
Roland Dreier | 8b7fc42 | 2005-09-14 14:19:17 -0700 | [diff] [blame] | 1963 | case PCI_DEVICE_ID_RME_DIGI32: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1964 | strcpy(card->shortname, "RME Digi32"); |
| 1965 | break; |
Roland Dreier | 8b7fc42 | 2005-09-14 14:19:17 -0700 | [diff] [blame] | 1966 | case PCI_DEVICE_ID_RME_DIGI32_8: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1967 | strcpy(card->shortname, "RME Digi32/8"); |
| 1968 | break; |
Roland Dreier | 8b7fc42 | 2005-09-14 14:19:17 -0700 | [diff] [blame] | 1969 | case PCI_DEVICE_ID_RME_DIGI32_PRO: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1970 | strcpy(card->shortname, "RME Digi32 PRO"); |
| 1971 | break; |
| 1972 | } |
| 1973 | sprintf(card->longname, "%s (Rev. %d) at 0x%lx, irq %d", |
| 1974 | card->shortname, rme32->rev, rme32->port, rme32->irq); |
| 1975 | |
| 1976 | if ((err = snd_card_register(card)) < 0) { |
| 1977 | snd_card_free(card); |
| 1978 | return err; |
| 1979 | } |
| 1980 | pci_set_drvdata(pci, card); |
| 1981 | dev++; |
| 1982 | return 0; |
| 1983 | } |
| 1984 | |
Bill Pemberton | e23e7a1 | 2012-12-06 12:35:10 -0500 | [diff] [blame] | 1985 | static void snd_rme32_remove(struct pci_dev *pci) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1986 | { |
| 1987 | snd_card_free(pci_get_drvdata(pci)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1988 | } |
| 1989 | |
Takashi Iwai | e9f66d9 | 2012-04-24 12:25:00 +0200 | [diff] [blame] | 1990 | static struct pci_driver rme32_driver = { |
Takashi Iwai | 3733e42 | 2011-06-10 16:20:20 +0200 | [diff] [blame] | 1991 | .name = KBUILD_MODNAME, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1992 | .id_table = snd_rme32_ids, |
| 1993 | .probe = snd_rme32_probe, |
Bill Pemberton | e23e7a1 | 2012-12-06 12:35:10 -0500 | [diff] [blame] | 1994 | .remove = snd_rme32_remove, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1995 | }; |
| 1996 | |
Takashi Iwai | e9f66d9 | 2012-04-24 12:25:00 +0200 | [diff] [blame] | 1997 | module_pci_driver(rme32_driver); |