2 * ALSA driver for RME Digi96, Digi96/8 and Digi96/8 PRO/PAD/PST audio
5 * Copyright (c) 2000, 2001 Anders Torger <torger@ludd.luth.se>
7 * Thanks to Henk Hesselink <henk@anda.nl> for the analog volume control
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 #include <linux/delay.h>
27 #include <linux/init.h>
28 #include <linux/interrupt.h>
29 #include <linux/pci.h>
30 #include <linux/module.h>
32 #include <sound/core.h>
33 #include <sound/info.h>
34 #include <sound/control.h>
35 #include <sound/pcm.h>
36 #include <sound/pcm_params.h>
37 #include <sound/asoundef.h>
38 #include <sound/initval.h>
42 /* note, two last pcis should be equal, it is not a bug */
44 MODULE_AUTHOR("Anders Torger <torger@ludd.luth.se>");
45 MODULE_DESCRIPTION("RME Digi96, Digi96/8, Digi96/8 PRO, Digi96/8 PST, "
47 MODULE_LICENSE("GPL");
48 MODULE_SUPPORTED_DEVICE("{{RME,Digi96},"
52 "{RME,Digi96/8 PAD}}");
54 static int index
[SNDRV_CARDS
] = SNDRV_DEFAULT_IDX
; /* Index 0-MAX */
55 static char *id
[SNDRV_CARDS
] = SNDRV_DEFAULT_STR
; /* ID for this card */
56 static bool enable
[SNDRV_CARDS
] = SNDRV_DEFAULT_ENABLE_PNP
; /* Enable this card */
58 module_param_array(index
, int, NULL
, 0444);
59 MODULE_PARM_DESC(index
, "Index value for RME Digi96 soundcard.");
60 module_param_array(id
, charp
, NULL
, 0444);
61 MODULE_PARM_DESC(id
, "ID string for RME Digi96 soundcard.");
62 module_param_array(enable
, bool, NULL
, 0444);
63 MODULE_PARM_DESC(enable
, "Enable RME Digi96 soundcard.");
66 * Defines for RME Digi96 series, from internal RME reference documents
70 #define RME96_SPDIF_NCHANNELS 2
72 /* Playback and capture buffer size */
73 #define RME96_BUFFER_SIZE 0x10000
76 #define RME96_IO_SIZE 0x60000
79 #define RME96_IO_PLAY_BUFFER 0x0
80 #define RME96_IO_REC_BUFFER 0x10000
81 #define RME96_IO_CONTROL_REGISTER 0x20000
82 #define RME96_IO_ADDITIONAL_REG 0x20004
83 #define RME96_IO_CONFIRM_PLAY_IRQ 0x20008
84 #define RME96_IO_CONFIRM_REC_IRQ 0x2000C
85 #define RME96_IO_SET_PLAY_POS 0x40000
86 #define RME96_IO_RESET_PLAY_POS 0x4FFFC
87 #define RME96_IO_SET_REC_POS 0x50000
88 #define RME96_IO_RESET_REC_POS 0x5FFFC
89 #define RME96_IO_GET_PLAY_POS 0x20000
90 #define RME96_IO_GET_REC_POS 0x30000
92 /* Write control register bits */
93 #define RME96_WCR_START (1 << 0)
94 #define RME96_WCR_START_2 (1 << 1)
95 #define RME96_WCR_GAIN_0 (1 << 2)
96 #define RME96_WCR_GAIN_1 (1 << 3)
97 #define RME96_WCR_MODE24 (1 << 4)
98 #define RME96_WCR_MODE24_2 (1 << 5)
99 #define RME96_WCR_BM (1 << 6)
100 #define RME96_WCR_BM_2 (1 << 7)
101 #define RME96_WCR_ADAT (1 << 8)
102 #define RME96_WCR_FREQ_0 (1 << 9)
103 #define RME96_WCR_FREQ_1 (1 << 10)
104 #define RME96_WCR_DS (1 << 11)
105 #define RME96_WCR_PRO (1 << 12)
106 #define RME96_WCR_EMP (1 << 13)
107 #define RME96_WCR_SEL (1 << 14)
108 #define RME96_WCR_MASTER (1 << 15)
109 #define RME96_WCR_PD (1 << 16)
110 #define RME96_WCR_INP_0 (1 << 17)
111 #define RME96_WCR_INP_1 (1 << 18)
112 #define RME96_WCR_THRU_0 (1 << 19)
113 #define RME96_WCR_THRU_1 (1 << 20)
114 #define RME96_WCR_THRU_2 (1 << 21)
115 #define RME96_WCR_THRU_3 (1 << 22)
116 #define RME96_WCR_THRU_4 (1 << 23)
117 #define RME96_WCR_THRU_5 (1 << 24)
118 #define RME96_WCR_THRU_6 (1 << 25)
119 #define RME96_WCR_THRU_7 (1 << 26)
120 #define RME96_WCR_DOLBY (1 << 27)
121 #define RME96_WCR_MONITOR_0 (1 << 28)
122 #define RME96_WCR_MONITOR_1 (1 << 29)
123 #define RME96_WCR_ISEL (1 << 30)
124 #define RME96_WCR_IDIS (1 << 31)
126 #define RME96_WCR_BITPOS_GAIN_0 2
127 #define RME96_WCR_BITPOS_GAIN_1 3
128 #define RME96_WCR_BITPOS_FREQ_0 9
129 #define RME96_WCR_BITPOS_FREQ_1 10
130 #define RME96_WCR_BITPOS_INP_0 17
131 #define RME96_WCR_BITPOS_INP_1 18
132 #define RME96_WCR_BITPOS_MONITOR_0 28
133 #define RME96_WCR_BITPOS_MONITOR_1 29
135 /* Read control register bits */
136 #define RME96_RCR_AUDIO_ADDR_MASK 0xFFFF
137 #define RME96_RCR_IRQ_2 (1 << 16)
138 #define RME96_RCR_T_OUT (1 << 17)
139 #define RME96_RCR_DEV_ID_0 (1 << 21)
140 #define RME96_RCR_DEV_ID_1 (1 << 22)
141 #define RME96_RCR_LOCK (1 << 23)
142 #define RME96_RCR_VERF (1 << 26)
143 #define RME96_RCR_F0 (1 << 27)
144 #define RME96_RCR_F1 (1 << 28)
145 #define RME96_RCR_F2 (1 << 29)
146 #define RME96_RCR_AUTOSYNC (1 << 30)
147 #define RME96_RCR_IRQ (1 << 31)
149 #define RME96_RCR_BITPOS_F0 27
150 #define RME96_RCR_BITPOS_F1 28
151 #define RME96_RCR_BITPOS_F2 29
153 /* Additional register bits */
154 #define RME96_AR_WSEL (1 << 0)
155 #define RME96_AR_ANALOG (1 << 1)
156 #define RME96_AR_FREQPAD_0 (1 << 2)
157 #define RME96_AR_FREQPAD_1 (1 << 3)
158 #define RME96_AR_FREQPAD_2 (1 << 4)
159 #define RME96_AR_PD2 (1 << 5)
160 #define RME96_AR_DAC_EN (1 << 6)
161 #define RME96_AR_CLATCH (1 << 7)
162 #define RME96_AR_CCLK (1 << 8)
163 #define RME96_AR_CDATA (1 << 9)
165 #define RME96_AR_BITPOS_F0 2
166 #define RME96_AR_BITPOS_F1 3
167 #define RME96_AR_BITPOS_F2 4
170 #define RME96_MONITOR_TRACKS_1_2 0
171 #define RME96_MONITOR_TRACKS_3_4 1
172 #define RME96_MONITOR_TRACKS_5_6 2
173 #define RME96_MONITOR_TRACKS_7_8 3
176 #define RME96_ATTENUATION_0 0
177 #define RME96_ATTENUATION_6 1
178 #define RME96_ATTENUATION_12 2
179 #define RME96_ATTENUATION_18 3
182 #define RME96_INPUT_OPTICAL 0
183 #define RME96_INPUT_COAXIAL 1
184 #define RME96_INPUT_INTERNAL 2
185 #define RME96_INPUT_XLR 3
186 #define RME96_INPUT_ANALOG 4
189 #define RME96_CLOCKMODE_SLAVE 0
190 #define RME96_CLOCKMODE_MASTER 1
191 #define RME96_CLOCKMODE_WORDCLOCK 2
193 /* Block sizes in bytes */
194 #define RME96_SMALL_BLOCK_SIZE 2048
195 #define RME96_LARGE_BLOCK_SIZE 8192
198 #define RME96_AD1852_VOL_BITS 14
199 #define RME96_AD1855_VOL_BITS 10
206 void __iomem
*iobase
;
208 u32 wcreg
; /* cached write control register value */
209 u32 wcreg_spdif
; /* S/PDIF setup */
210 u32 wcreg_spdif_stream
; /* S/PDIF setup (temporary) */
211 u32 rcreg
; /* cached read control register value */
212 u32 areg
; /* cached additional register value */
213 u16 vol
[2]; /* cached volume of analog output */
215 u8 rev
; /* card revision number */
217 struct snd_pcm_substream
*playback_substream
;
218 struct snd_pcm_substream
*capture_substream
;
220 int playback_frlog
; /* log2 of framesize */
223 size_t playback_periodsize
; /* in bytes, zero if not used */
224 size_t capture_periodsize
; /* in bytes, zero if not used */
226 struct snd_card
*card
;
227 struct snd_pcm
*spdif_pcm
;
228 struct snd_pcm
*adat_pcm
;
230 struct snd_kcontrol
*spdif_ctl
;
233 static DEFINE_PCI_DEVICE_TABLE(snd_rme96_ids
) = {
234 { PCI_VDEVICE(XILINX
, PCI_DEVICE_ID_RME_DIGI96
), 0, },
235 { PCI_VDEVICE(XILINX
, PCI_DEVICE_ID_RME_DIGI96_8
), 0, },
236 { PCI_VDEVICE(XILINX
, PCI_DEVICE_ID_RME_DIGI96_8_PRO
), 0, },
237 { PCI_VDEVICE(XILINX
, PCI_DEVICE_ID_RME_DIGI96_8_PAD_OR_PST
), 0, },
241 MODULE_DEVICE_TABLE(pci
, snd_rme96_ids
);
243 #define RME96_ISPLAYING(rme96) ((rme96)->wcreg & RME96_WCR_START)
244 #define RME96_ISRECORDING(rme96) ((rme96)->wcreg & RME96_WCR_START_2)
245 #define RME96_HAS_ANALOG_IN(rme96) ((rme96)->pci->device == PCI_DEVICE_ID_RME_DIGI96_8_PAD_OR_PST)
246 #define RME96_HAS_ANALOG_OUT(rme96) ((rme96)->pci->device == PCI_DEVICE_ID_RME_DIGI96_8_PRO || \
247 (rme96)->pci->device == PCI_DEVICE_ID_RME_DIGI96_8_PAD_OR_PST)
248 #define RME96_DAC_IS_1852(rme96) (RME96_HAS_ANALOG_OUT(rme96) && (rme96)->rev >= 4)
249 #define RME96_DAC_IS_1855(rme96) (((rme96)->pci->device == PCI_DEVICE_ID_RME_DIGI96_8_PAD_OR_PST && (rme96)->rev < 4) || \
250 ((rme96)->pci->device == PCI_DEVICE_ID_RME_DIGI96_8_PRO && (rme96)->rev == 2))
251 #define RME96_185X_MAX_OUT(rme96) ((1 << (RME96_DAC_IS_1852(rme96) ? RME96_AD1852_VOL_BITS : RME96_AD1855_VOL_BITS)) - 1)
254 snd_rme96_playback_prepare(struct snd_pcm_substream
*substream
);
257 snd_rme96_capture_prepare(struct snd_pcm_substream
*substream
);
260 snd_rme96_playback_trigger(struct snd_pcm_substream
*substream
,
264 snd_rme96_capture_trigger(struct snd_pcm_substream
*substream
,
267 static snd_pcm_uframes_t
268 snd_rme96_playback_pointer(struct snd_pcm_substream
*substream
);
270 static snd_pcm_uframes_t
271 snd_rme96_capture_pointer(struct snd_pcm_substream
*substream
);
273 static void snd_rme96_proc_init(struct rme96
*rme96
);
276 snd_rme96_create_switches(struct snd_card
*card
,
277 struct rme96
*rme96
);
280 snd_rme96_getinputtype(struct rme96
*rme96
);
282 static inline unsigned int
283 snd_rme96_playback_ptr(struct rme96
*rme96
)
285 return (readl(rme96
->iobase
+ RME96_IO_GET_PLAY_POS
)
286 & RME96_RCR_AUDIO_ADDR_MASK
) >> rme96
->playback_frlog
;
289 static inline unsigned int
290 snd_rme96_capture_ptr(struct rme96
*rme96
)
292 return (readl(rme96
->iobase
+ RME96_IO_GET_REC_POS
)
293 & RME96_RCR_AUDIO_ADDR_MASK
) >> rme96
->capture_frlog
;
297 snd_rme96_playback_silence(struct snd_pcm_substream
*substream
,
298 int channel
, /* not used (interleaved data) */
299 snd_pcm_uframes_t pos
,
300 snd_pcm_uframes_t count
)
302 struct rme96
*rme96
= snd_pcm_substream_chip(substream
);
303 count
<<= rme96
->playback_frlog
;
304 pos
<<= rme96
->playback_frlog
;
305 memset_io(rme96
->iobase
+ RME96_IO_PLAY_BUFFER
+ pos
,
311 snd_rme96_playback_copy(struct snd_pcm_substream
*substream
,
312 int channel
, /* not used (interleaved data) */
313 snd_pcm_uframes_t pos
,
315 snd_pcm_uframes_t count
)
317 struct rme96
*rme96
= snd_pcm_substream_chip(substream
);
318 count
<<= rme96
->playback_frlog
;
319 pos
<<= rme96
->playback_frlog
;
320 copy_from_user_toio(rme96
->iobase
+ RME96_IO_PLAY_BUFFER
+ pos
, src
,
326 snd_rme96_capture_copy(struct snd_pcm_substream
*substream
,
327 int channel
, /* not used (interleaved data) */
328 snd_pcm_uframes_t pos
,
330 snd_pcm_uframes_t count
)
332 struct rme96
*rme96
= snd_pcm_substream_chip(substream
);
333 count
<<= rme96
->capture_frlog
;
334 pos
<<= rme96
->capture_frlog
;
335 copy_to_user_fromio(dst
, rme96
->iobase
+ RME96_IO_REC_BUFFER
+ pos
,
341 * Digital output capabilities (S/PDIF)
343 static struct snd_pcm_hardware snd_rme96_playback_spdif_info
=
345 .info
= (SNDRV_PCM_INFO_MMAP_IOMEM
|
346 SNDRV_PCM_INFO_MMAP_VALID
|
347 SNDRV_PCM_INFO_INTERLEAVED
|
348 SNDRV_PCM_INFO_PAUSE
),
349 .formats
= (SNDRV_PCM_FMTBIT_S16_LE
|
350 SNDRV_PCM_FMTBIT_S32_LE
),
351 .rates
= (SNDRV_PCM_RATE_32000
|
352 SNDRV_PCM_RATE_44100
|
353 SNDRV_PCM_RATE_48000
|
354 SNDRV_PCM_RATE_64000
|
355 SNDRV_PCM_RATE_88200
|
356 SNDRV_PCM_RATE_96000
),
361 .buffer_bytes_max
= RME96_BUFFER_SIZE
,
362 .period_bytes_min
= RME96_SMALL_BLOCK_SIZE
,
363 .period_bytes_max
= RME96_LARGE_BLOCK_SIZE
,
364 .periods_min
= RME96_BUFFER_SIZE
/ RME96_LARGE_BLOCK_SIZE
,
365 .periods_max
= RME96_BUFFER_SIZE
/ RME96_SMALL_BLOCK_SIZE
,
370 * Digital input capabilities (S/PDIF)
372 static struct snd_pcm_hardware snd_rme96_capture_spdif_info
=
374 .info
= (SNDRV_PCM_INFO_MMAP_IOMEM
|
375 SNDRV_PCM_INFO_MMAP_VALID
|
376 SNDRV_PCM_INFO_INTERLEAVED
|
377 SNDRV_PCM_INFO_PAUSE
),
378 .formats
= (SNDRV_PCM_FMTBIT_S16_LE
|
379 SNDRV_PCM_FMTBIT_S32_LE
),
380 .rates
= (SNDRV_PCM_RATE_32000
|
381 SNDRV_PCM_RATE_44100
|
382 SNDRV_PCM_RATE_48000
|
383 SNDRV_PCM_RATE_64000
|
384 SNDRV_PCM_RATE_88200
|
385 SNDRV_PCM_RATE_96000
),
390 .buffer_bytes_max
= RME96_BUFFER_SIZE
,
391 .period_bytes_min
= RME96_SMALL_BLOCK_SIZE
,
392 .period_bytes_max
= RME96_LARGE_BLOCK_SIZE
,
393 .periods_min
= RME96_BUFFER_SIZE
/ RME96_LARGE_BLOCK_SIZE
,
394 .periods_max
= RME96_BUFFER_SIZE
/ RME96_SMALL_BLOCK_SIZE
,
399 * Digital output capabilities (ADAT)
401 static struct snd_pcm_hardware snd_rme96_playback_adat_info
=
403 .info
= (SNDRV_PCM_INFO_MMAP_IOMEM
|
404 SNDRV_PCM_INFO_MMAP_VALID
|
405 SNDRV_PCM_INFO_INTERLEAVED
|
406 SNDRV_PCM_INFO_PAUSE
),
407 .formats
= (SNDRV_PCM_FMTBIT_S16_LE
|
408 SNDRV_PCM_FMTBIT_S32_LE
),
409 .rates
= (SNDRV_PCM_RATE_44100
|
410 SNDRV_PCM_RATE_48000
),
415 .buffer_bytes_max
= RME96_BUFFER_SIZE
,
416 .period_bytes_min
= RME96_SMALL_BLOCK_SIZE
,
417 .period_bytes_max
= RME96_LARGE_BLOCK_SIZE
,
418 .periods_min
= RME96_BUFFER_SIZE
/ RME96_LARGE_BLOCK_SIZE
,
419 .periods_max
= RME96_BUFFER_SIZE
/ RME96_SMALL_BLOCK_SIZE
,
424 * Digital input capabilities (ADAT)
426 static struct snd_pcm_hardware snd_rme96_capture_adat_info
=
428 .info
= (SNDRV_PCM_INFO_MMAP_IOMEM
|
429 SNDRV_PCM_INFO_MMAP_VALID
|
430 SNDRV_PCM_INFO_INTERLEAVED
|
431 SNDRV_PCM_INFO_PAUSE
),
432 .formats
= (SNDRV_PCM_FMTBIT_S16_LE
|
433 SNDRV_PCM_FMTBIT_S32_LE
),
434 .rates
= (SNDRV_PCM_RATE_44100
|
435 SNDRV_PCM_RATE_48000
),
440 .buffer_bytes_max
= RME96_BUFFER_SIZE
,
441 .period_bytes_min
= RME96_SMALL_BLOCK_SIZE
,
442 .period_bytes_max
= RME96_LARGE_BLOCK_SIZE
,
443 .periods_min
= RME96_BUFFER_SIZE
/ RME96_LARGE_BLOCK_SIZE
,
444 .periods_max
= RME96_BUFFER_SIZE
/ RME96_SMALL_BLOCK_SIZE
,
449 * The CDATA, CCLK and CLATCH bits can be used to write to the SPI interface
450 * of the AD1852 or AD1852 D/A converter on the board. CDATA must be set up
451 * on the falling edge of CCLK and be stable on the rising edge. The rising
452 * edge of CLATCH after the last data bit clocks in the whole data word.
453 * A fast processor could probably drive the SPI interface faster than the
454 * DAC can handle (3MHz for the 1855, unknown for the 1852). The udelay(1)
455 * limits the data rate to 500KHz and only causes a delay of 33 microsecs.
457 * NOTE: increased delay from 1 to 10, since there where problems setting
461 snd_rme96_write_SPI(struct rme96
*rme96
, u16 val
)
465 for (i
= 0; i
< 16; i
++) {
467 rme96
->areg
|= RME96_AR_CDATA
;
469 rme96
->areg
&= ~RME96_AR_CDATA
;
471 rme96
->areg
&= ~(RME96_AR_CCLK
| RME96_AR_CLATCH
);
472 writel(rme96
->areg
, rme96
->iobase
+ RME96_IO_ADDITIONAL_REG
);
474 rme96
->areg
|= RME96_AR_CCLK
;
475 writel(rme96
->areg
, rme96
->iobase
+ RME96_IO_ADDITIONAL_REG
);
479 rme96
->areg
&= ~(RME96_AR_CCLK
| RME96_AR_CDATA
);
480 rme96
->areg
|= RME96_AR_CLATCH
;
481 writel(rme96
->areg
, rme96
->iobase
+ RME96_IO_ADDITIONAL_REG
);
483 rme96
->areg
&= ~RME96_AR_CLATCH
;
484 writel(rme96
->areg
, rme96
->iobase
+ RME96_IO_ADDITIONAL_REG
);
488 snd_rme96_apply_dac_volume(struct rme96
*rme96
)
490 if (RME96_DAC_IS_1852(rme96
)) {
491 snd_rme96_write_SPI(rme96
, (rme96
->vol
[0] << 2) | 0x0);
492 snd_rme96_write_SPI(rme96
, (rme96
->vol
[1] << 2) | 0x2);
493 } else if (RME96_DAC_IS_1855(rme96
)) {
494 snd_rme96_write_SPI(rme96
, (rme96
->vol
[0] & 0x3FF) | 0x000);
495 snd_rme96_write_SPI(rme96
, (rme96
->vol
[1] & 0x3FF) | 0x400);
500 snd_rme96_reset_dac(struct rme96
*rme96
)
502 writel(rme96
->wcreg
| RME96_WCR_PD
,
503 rme96
->iobase
+ RME96_IO_CONTROL_REGISTER
);
504 writel(rme96
->wcreg
, rme96
->iobase
+ RME96_IO_CONTROL_REGISTER
);
508 snd_rme96_getmontracks(struct rme96
*rme96
)
510 return ((rme96
->wcreg
>> RME96_WCR_BITPOS_MONITOR_0
) & 1) +
511 (((rme96
->wcreg
>> RME96_WCR_BITPOS_MONITOR_1
) & 1) << 1);
515 snd_rme96_setmontracks(struct rme96
*rme96
,
519 rme96
->wcreg
|= RME96_WCR_MONITOR_0
;
521 rme96
->wcreg
&= ~RME96_WCR_MONITOR_0
;
524 rme96
->wcreg
|= RME96_WCR_MONITOR_1
;
526 rme96
->wcreg
&= ~RME96_WCR_MONITOR_1
;
528 writel(rme96
->wcreg
, rme96
->iobase
+ RME96_IO_CONTROL_REGISTER
);
533 snd_rme96_getattenuation(struct rme96
*rme96
)
535 return ((rme96
->wcreg
>> RME96_WCR_BITPOS_GAIN_0
) & 1) +
536 (((rme96
->wcreg
>> RME96_WCR_BITPOS_GAIN_1
) & 1) << 1);
540 snd_rme96_setattenuation(struct rme96
*rme96
,
543 switch (attenuation
) {
545 rme96
->wcreg
= (rme96
->wcreg
& ~RME96_WCR_GAIN_0
) &
549 rme96
->wcreg
= (rme96
->wcreg
| RME96_WCR_GAIN_0
) &
553 rme96
->wcreg
= (rme96
->wcreg
& ~RME96_WCR_GAIN_0
) |
557 rme96
->wcreg
= (rme96
->wcreg
| RME96_WCR_GAIN_0
) |
563 writel(rme96
->wcreg
, rme96
->iobase
+ RME96_IO_CONTROL_REGISTER
);
568 snd_rme96_capture_getrate(struct rme96
*rme96
,
574 if (rme96
->areg
& RME96_AR_ANALOG
) {
575 /* Analog input, overrides S/PDIF setting */
576 n
= ((rme96
->areg
>> RME96_AR_BITPOS_F0
) & 1) +
577 (((rme96
->areg
>> RME96_AR_BITPOS_F1
) & 1) << 1);
591 return (rme96
->areg
& RME96_AR_BITPOS_F2
) ? rate
<< 1 : rate
;
594 rme96
->rcreg
= readl(rme96
->iobase
+ RME96_IO_CONTROL_REGISTER
);
595 if (rme96
->rcreg
& RME96_RCR_LOCK
) {
598 if (rme96
->rcreg
& RME96_RCR_T_OUT
) {
604 if (rme96
->rcreg
& RME96_RCR_VERF
) {
609 n
= ((rme96
->rcreg
>> RME96_RCR_BITPOS_F0
) & 1) +
610 (((rme96
->rcreg
>> RME96_RCR_BITPOS_F1
) & 1) << 1) +
611 (((rme96
->rcreg
>> RME96_RCR_BITPOS_F2
) & 1) << 2);
615 if (rme96
->rcreg
& RME96_RCR_T_OUT
) {
619 case 3: return 96000;
620 case 4: return 88200;
621 case 5: return 48000;
622 case 6: return 44100;
623 case 7: return 32000;
631 snd_rme96_playback_getrate(struct rme96
*rme96
)
635 if (!(rme96
->wcreg
& RME96_WCR_MASTER
) &&
636 snd_rme96_getinputtype(rme96
) != RME96_INPUT_ANALOG
&&
637 (rate
= snd_rme96_capture_getrate(rme96
, &dummy
)) > 0)
642 rate
= ((rme96
->wcreg
>> RME96_WCR_BITPOS_FREQ_0
) & 1) +
643 (((rme96
->wcreg
>> RME96_WCR_BITPOS_FREQ_1
) & 1) << 1);
657 return (rme96
->wcreg
& RME96_WCR_DS
) ? rate
<< 1 : rate
;
661 snd_rme96_playback_setrate(struct rme96
*rme96
,
666 ds
= rme96
->wcreg
& RME96_WCR_DS
;
669 rme96
->wcreg
&= ~RME96_WCR_DS
;
670 rme96
->wcreg
= (rme96
->wcreg
| RME96_WCR_FREQ_0
) &
674 rme96
->wcreg
&= ~RME96_WCR_DS
;
675 rme96
->wcreg
= (rme96
->wcreg
| RME96_WCR_FREQ_1
) &
679 rme96
->wcreg
&= ~RME96_WCR_DS
;
680 rme96
->wcreg
= (rme96
->wcreg
| RME96_WCR_FREQ_0
) |
684 rme96
->wcreg
|= RME96_WCR_DS
;
685 rme96
->wcreg
= (rme96
->wcreg
| RME96_WCR_FREQ_0
) &
689 rme96
->wcreg
|= RME96_WCR_DS
;
690 rme96
->wcreg
= (rme96
->wcreg
| RME96_WCR_FREQ_1
) &
694 rme96
->wcreg
|= RME96_WCR_DS
;
695 rme96
->wcreg
= (rme96
->wcreg
| RME96_WCR_FREQ_0
) |
701 if ((!ds
&& rme96
->wcreg
& RME96_WCR_DS
) ||
702 (ds
&& !(rme96
->wcreg
& RME96_WCR_DS
)))
704 /* change to/from double-speed: reset the DAC (if available) */
705 snd_rme96_reset_dac(rme96
);
707 writel(rme96
->wcreg
, rme96
->iobase
+ RME96_IO_CONTROL_REGISTER
);
713 snd_rme96_capture_analog_setrate(struct rme96
*rme96
,
718 rme96
->areg
= ((rme96
->areg
| RME96_AR_FREQPAD_0
) &
719 ~RME96_AR_FREQPAD_1
) & ~RME96_AR_FREQPAD_2
;
722 rme96
->areg
= ((rme96
->areg
& ~RME96_AR_FREQPAD_0
) |
723 RME96_AR_FREQPAD_1
) & ~RME96_AR_FREQPAD_2
;
726 rme96
->areg
= ((rme96
->areg
| RME96_AR_FREQPAD_0
) |
727 RME96_AR_FREQPAD_1
) & ~RME96_AR_FREQPAD_2
;
730 if (rme96
->rev
< 4) {
733 rme96
->areg
= ((rme96
->areg
| RME96_AR_FREQPAD_0
) &
734 ~RME96_AR_FREQPAD_1
) | RME96_AR_FREQPAD_2
;
737 if (rme96
->rev
< 4) {
740 rme96
->areg
= ((rme96
->areg
& ~RME96_AR_FREQPAD_0
) |
741 RME96_AR_FREQPAD_1
) | RME96_AR_FREQPAD_2
;
744 rme96
->areg
= ((rme96
->areg
| RME96_AR_FREQPAD_0
) |
745 RME96_AR_FREQPAD_1
) | RME96_AR_FREQPAD_2
;
750 writel(rme96
->areg
, rme96
->iobase
+ RME96_IO_ADDITIONAL_REG
);
755 snd_rme96_setclockmode(struct rme96
*rme96
,
759 case RME96_CLOCKMODE_SLAVE
:
761 rme96
->wcreg
&= ~RME96_WCR_MASTER
;
762 rme96
->areg
&= ~RME96_AR_WSEL
;
764 case RME96_CLOCKMODE_MASTER
:
766 rme96
->wcreg
|= RME96_WCR_MASTER
;
767 rme96
->areg
&= ~RME96_AR_WSEL
;
769 case RME96_CLOCKMODE_WORDCLOCK
:
770 /* Word clock is a master mode */
771 rme96
->wcreg
|= RME96_WCR_MASTER
;
772 rme96
->areg
|= RME96_AR_WSEL
;
777 writel(rme96
->wcreg
, rme96
->iobase
+ RME96_IO_CONTROL_REGISTER
);
778 writel(rme96
->areg
, rme96
->iobase
+ RME96_IO_ADDITIONAL_REG
);
783 snd_rme96_getclockmode(struct rme96
*rme96
)
785 if (rme96
->areg
& RME96_AR_WSEL
) {
786 return RME96_CLOCKMODE_WORDCLOCK
;
788 return (rme96
->wcreg
& RME96_WCR_MASTER
) ? RME96_CLOCKMODE_MASTER
:
789 RME96_CLOCKMODE_SLAVE
;
793 snd_rme96_setinputtype(struct rme96
*rme96
,
799 case RME96_INPUT_OPTICAL
:
800 rme96
->wcreg
= (rme96
->wcreg
& ~RME96_WCR_INP_0
) &
803 case RME96_INPUT_COAXIAL
:
804 rme96
->wcreg
= (rme96
->wcreg
| RME96_WCR_INP_0
) &
807 case RME96_INPUT_INTERNAL
:
808 rme96
->wcreg
= (rme96
->wcreg
& ~RME96_WCR_INP_0
) |
811 case RME96_INPUT_XLR
:
812 if ((rme96
->pci
->device
!= PCI_DEVICE_ID_RME_DIGI96_8_PAD_OR_PST
&&
813 rme96
->pci
->device
!= PCI_DEVICE_ID_RME_DIGI96_8_PRO
) ||
814 (rme96
->pci
->device
== PCI_DEVICE_ID_RME_DIGI96_8_PAD_OR_PST
&&
817 /* Only Digi96/8 PRO and Digi96/8 PAD supports XLR */
820 rme96
->wcreg
= (rme96
->wcreg
| RME96_WCR_INP_0
) |
823 case RME96_INPUT_ANALOG
:
824 if (!RME96_HAS_ANALOG_IN(rme96
)) {
827 rme96
->areg
|= RME96_AR_ANALOG
;
828 writel(rme96
->areg
, rme96
->iobase
+ RME96_IO_ADDITIONAL_REG
);
829 if (rme96
->rev
< 4) {
831 * Revision less than 004 does not support 64 and
834 if (snd_rme96_capture_getrate(rme96
, &n
) == 88200) {
835 snd_rme96_capture_analog_setrate(rme96
, 44100);
837 if (snd_rme96_capture_getrate(rme96
, &n
) == 64000) {
838 snd_rme96_capture_analog_setrate(rme96
, 32000);
845 if (type
!= RME96_INPUT_ANALOG
&& RME96_HAS_ANALOG_IN(rme96
)) {
846 rme96
->areg
&= ~RME96_AR_ANALOG
;
847 writel(rme96
->areg
, rme96
->iobase
+ RME96_IO_ADDITIONAL_REG
);
849 writel(rme96
->wcreg
, rme96
->iobase
+ RME96_IO_CONTROL_REGISTER
);
854 snd_rme96_getinputtype(struct rme96
*rme96
)
856 if (rme96
->areg
& RME96_AR_ANALOG
) {
857 return RME96_INPUT_ANALOG
;
859 return ((rme96
->wcreg
>> RME96_WCR_BITPOS_INP_0
) & 1) +
860 (((rme96
->wcreg
>> RME96_WCR_BITPOS_INP_1
) & 1) << 1);
864 snd_rme96_setframelog(struct rme96
*rme96
,
870 if (n_channels
== 2) {
873 /* assume 8 channels */
877 frlog
+= (rme96
->wcreg
& RME96_WCR_MODE24
) ? 2 : 1;
878 rme96
->playback_frlog
= frlog
;
880 frlog
+= (rme96
->wcreg
& RME96_WCR_MODE24_2
) ? 2 : 1;
881 rme96
->capture_frlog
= frlog
;
886 snd_rme96_playback_setformat(struct rme96
*rme96
,
890 case SNDRV_PCM_FORMAT_S16_LE
:
891 rme96
->wcreg
&= ~RME96_WCR_MODE24
;
893 case SNDRV_PCM_FORMAT_S32_LE
:
894 rme96
->wcreg
|= RME96_WCR_MODE24
;
899 writel(rme96
->wcreg
, rme96
->iobase
+ RME96_IO_CONTROL_REGISTER
);
904 snd_rme96_capture_setformat(struct rme96
*rme96
,
908 case SNDRV_PCM_FORMAT_S16_LE
:
909 rme96
->wcreg
&= ~RME96_WCR_MODE24_2
;
911 case SNDRV_PCM_FORMAT_S32_LE
:
912 rme96
->wcreg
|= RME96_WCR_MODE24_2
;
917 writel(rme96
->wcreg
, rme96
->iobase
+ RME96_IO_CONTROL_REGISTER
);
922 snd_rme96_set_period_properties(struct rme96
*rme96
,
925 switch (period_bytes
) {
926 case RME96_LARGE_BLOCK_SIZE
:
927 rme96
->wcreg
&= ~RME96_WCR_ISEL
;
929 case RME96_SMALL_BLOCK_SIZE
:
930 rme96
->wcreg
|= RME96_WCR_ISEL
;
936 rme96
->wcreg
&= ~RME96_WCR_IDIS
;
937 writel(rme96
->wcreg
, rme96
->iobase
+ RME96_IO_CONTROL_REGISTER
);
941 snd_rme96_playback_hw_params(struct snd_pcm_substream
*substream
,
942 struct snd_pcm_hw_params
*params
)
944 struct rme96
*rme96
= snd_pcm_substream_chip(substream
);
945 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
946 int err
, rate
, dummy
;
948 runtime
->dma_area
= (void __force
*)(rme96
->iobase
+
949 RME96_IO_PLAY_BUFFER
);
950 runtime
->dma_addr
= rme96
->port
+ RME96_IO_PLAY_BUFFER
;
951 runtime
->dma_bytes
= RME96_BUFFER_SIZE
;
953 spin_lock_irq(&rme96
->lock
);
954 if (!(rme96
->wcreg
& RME96_WCR_MASTER
) &&
955 snd_rme96_getinputtype(rme96
) != RME96_INPUT_ANALOG
&&
956 (rate
= snd_rme96_capture_getrate(rme96
, &dummy
)) > 0)
959 if ((int)params_rate(params
) != rate
) {
960 spin_unlock_irq(&rme96
->lock
);
963 } else if ((err
= snd_rme96_playback_setrate(rme96
, params_rate(params
))) < 0) {
964 spin_unlock_irq(&rme96
->lock
);
967 if ((err
= snd_rme96_playback_setformat(rme96
, params_format(params
))) < 0) {
968 spin_unlock_irq(&rme96
->lock
);
971 snd_rme96_setframelog(rme96
, params_channels(params
), 1);
972 if (rme96
->capture_periodsize
!= 0) {
973 if (params_period_size(params
) << rme96
->playback_frlog
!=
974 rme96
->capture_periodsize
)
976 spin_unlock_irq(&rme96
->lock
);
980 rme96
->playback_periodsize
=
981 params_period_size(params
) << rme96
->playback_frlog
;
982 snd_rme96_set_period_properties(rme96
, rme96
->playback_periodsize
);
984 if ((rme96
->wcreg
& RME96_WCR_ADAT
) == 0) {
985 rme96
->wcreg
&= ~(RME96_WCR_PRO
| RME96_WCR_DOLBY
| RME96_WCR_EMP
);
986 writel(rme96
->wcreg
|= rme96
->wcreg_spdif_stream
, rme96
->iobase
+ RME96_IO_CONTROL_REGISTER
);
988 spin_unlock_irq(&rme96
->lock
);
994 snd_rme96_capture_hw_params(struct snd_pcm_substream
*substream
,
995 struct snd_pcm_hw_params
*params
)
997 struct rme96
*rme96
= snd_pcm_substream_chip(substream
);
998 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
999 int err
, isadat
, rate
;
1001 runtime
->dma_area
= (void __force
*)(rme96
->iobase
+
1002 RME96_IO_REC_BUFFER
);
1003 runtime
->dma_addr
= rme96
->port
+ RME96_IO_REC_BUFFER
;
1004 runtime
->dma_bytes
= RME96_BUFFER_SIZE
;
1006 spin_lock_irq(&rme96
->lock
);
1007 if ((err
= snd_rme96_capture_setformat(rme96
, params_format(params
))) < 0) {
1008 spin_unlock_irq(&rme96
->lock
);
1011 if (snd_rme96_getinputtype(rme96
) == RME96_INPUT_ANALOG
) {
1012 if ((err
= snd_rme96_capture_analog_setrate(rme96
,
1013 params_rate(params
))) < 0)
1015 spin_unlock_irq(&rme96
->lock
);
1018 } else if ((rate
= snd_rme96_capture_getrate(rme96
, &isadat
)) > 0) {
1019 if ((int)params_rate(params
) != rate
) {
1020 spin_unlock_irq(&rme96
->lock
);
1023 if ((isadat
&& runtime
->hw
.channels_min
== 2) ||
1024 (!isadat
&& runtime
->hw
.channels_min
== 8))
1026 spin_unlock_irq(&rme96
->lock
);
1030 snd_rme96_setframelog(rme96
, params_channels(params
), 0);
1031 if (rme96
->playback_periodsize
!= 0) {
1032 if (params_period_size(params
) << rme96
->capture_frlog
!=
1033 rme96
->playback_periodsize
)
1035 spin_unlock_irq(&rme96
->lock
);
1039 rme96
->capture_periodsize
=
1040 params_period_size(params
) << rme96
->capture_frlog
;
1041 snd_rme96_set_period_properties(rme96
, rme96
->capture_periodsize
);
1042 spin_unlock_irq(&rme96
->lock
);
1048 snd_rme96_playback_start(struct rme96
*rme96
,
1052 writel(0, rme96
->iobase
+ RME96_IO_RESET_PLAY_POS
);
1055 rme96
->wcreg
|= RME96_WCR_START
;
1056 writel(rme96
->wcreg
, rme96
->iobase
+ RME96_IO_CONTROL_REGISTER
);
1060 snd_rme96_capture_start(struct rme96
*rme96
,
1064 writel(0, rme96
->iobase
+ RME96_IO_RESET_REC_POS
);
1067 rme96
->wcreg
|= RME96_WCR_START_2
;
1068 writel(rme96
->wcreg
, rme96
->iobase
+ RME96_IO_CONTROL_REGISTER
);
1072 snd_rme96_playback_stop(struct rme96
*rme96
)
1075 * Check if there is an unconfirmed IRQ, if so confirm it, or else
1076 * the hardware will not stop generating interrupts
1078 rme96
->rcreg
= readl(rme96
->iobase
+ RME96_IO_CONTROL_REGISTER
);
1079 if (rme96
->rcreg
& RME96_RCR_IRQ
) {
1080 writel(0, rme96
->iobase
+ RME96_IO_CONFIRM_PLAY_IRQ
);
1082 rme96
->wcreg
&= ~RME96_WCR_START
;
1083 writel(rme96
->wcreg
, rme96
->iobase
+ RME96_IO_CONTROL_REGISTER
);
1087 snd_rme96_capture_stop(struct rme96
*rme96
)
1089 rme96
->rcreg
= readl(rme96
->iobase
+ RME96_IO_CONTROL_REGISTER
);
1090 if (rme96
->rcreg
& RME96_RCR_IRQ_2
) {
1091 writel(0, rme96
->iobase
+ RME96_IO_CONFIRM_REC_IRQ
);
1093 rme96
->wcreg
&= ~RME96_WCR_START_2
;
1094 writel(rme96
->wcreg
, rme96
->iobase
+ RME96_IO_CONTROL_REGISTER
);
1098 snd_rme96_interrupt(int irq
,
1101 struct rme96
*rme96
= (struct rme96
*)dev_id
;
1103 rme96
->rcreg
= readl(rme96
->iobase
+ RME96_IO_CONTROL_REGISTER
);
1104 /* fastpath out, to ease interrupt sharing */
1105 if (!((rme96
->rcreg
& RME96_RCR_IRQ
) ||
1106 (rme96
->rcreg
& RME96_RCR_IRQ_2
)))
1111 if (rme96
->rcreg
& RME96_RCR_IRQ
) {
1113 snd_pcm_period_elapsed(rme96
->playback_substream
);
1114 writel(0, rme96
->iobase
+ RME96_IO_CONFIRM_PLAY_IRQ
);
1116 if (rme96
->rcreg
& RME96_RCR_IRQ_2
) {
1118 snd_pcm_period_elapsed(rme96
->capture_substream
);
1119 writel(0, rme96
->iobase
+ RME96_IO_CONFIRM_REC_IRQ
);
1124 static unsigned int period_bytes
[] = { RME96_SMALL_BLOCK_SIZE
, RME96_LARGE_BLOCK_SIZE
};
1126 static struct snd_pcm_hw_constraint_list hw_constraints_period_bytes
= {
1127 .count
= ARRAY_SIZE(period_bytes
),
1128 .list
= period_bytes
,
1133 rme96_set_buffer_size_constraint(struct rme96
*rme96
,
1134 struct snd_pcm_runtime
*runtime
)
1138 snd_pcm_hw_constraint_minmax(runtime
, SNDRV_PCM_HW_PARAM_BUFFER_BYTES
,
1139 RME96_BUFFER_SIZE
, RME96_BUFFER_SIZE
);
1140 if ((size
= rme96
->playback_periodsize
) != 0 ||
1141 (size
= rme96
->capture_periodsize
) != 0)
1142 snd_pcm_hw_constraint_minmax(runtime
,
1143 SNDRV_PCM_HW_PARAM_PERIOD_BYTES
,
1146 snd_pcm_hw_constraint_list(runtime
, 0,
1147 SNDRV_PCM_HW_PARAM_PERIOD_BYTES
,
1148 &hw_constraints_period_bytes
);
1152 snd_rme96_playback_spdif_open(struct snd_pcm_substream
*substream
)
1155 struct rme96
*rme96
= snd_pcm_substream_chip(substream
);
1156 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1158 spin_lock_irq(&rme96
->lock
);
1159 if (rme96
->playback_substream
!= NULL
) {
1160 spin_unlock_irq(&rme96
->lock
);
1163 rme96
->wcreg
&= ~RME96_WCR_ADAT
;
1164 writel(rme96
->wcreg
, rme96
->iobase
+ RME96_IO_CONTROL_REGISTER
);
1165 rme96
->playback_substream
= substream
;
1166 spin_unlock_irq(&rme96
->lock
);
1168 runtime
->hw
= snd_rme96_playback_spdif_info
;
1169 if (!(rme96
->wcreg
& RME96_WCR_MASTER
) &&
1170 snd_rme96_getinputtype(rme96
) != RME96_INPUT_ANALOG
&&
1171 (rate
= snd_rme96_capture_getrate(rme96
, &dummy
)) > 0)
1174 runtime
->hw
.rates
= snd_pcm_rate_to_rate_bit(rate
);
1175 runtime
->hw
.rate_min
= rate
;
1176 runtime
->hw
.rate_max
= rate
;
1178 rme96_set_buffer_size_constraint(rme96
, runtime
);
1180 rme96
->wcreg_spdif_stream
= rme96
->wcreg_spdif
;
1181 rme96
->spdif_ctl
->vd
[0].access
&= ~SNDRV_CTL_ELEM_ACCESS_INACTIVE
;
1182 snd_ctl_notify(rme96
->card
, SNDRV_CTL_EVENT_MASK_VALUE
|
1183 SNDRV_CTL_EVENT_MASK_INFO
, &rme96
->spdif_ctl
->id
);
1188 snd_rme96_capture_spdif_open(struct snd_pcm_substream
*substream
)
1191 struct rme96
*rme96
= snd_pcm_substream_chip(substream
);
1192 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1194 runtime
->hw
= snd_rme96_capture_spdif_info
;
1195 if (snd_rme96_getinputtype(rme96
) != RME96_INPUT_ANALOG
&&
1196 (rate
= snd_rme96_capture_getrate(rme96
, &isadat
)) > 0)
1201 runtime
->hw
.rates
= snd_pcm_rate_to_rate_bit(rate
);
1202 runtime
->hw
.rate_min
= rate
;
1203 runtime
->hw
.rate_max
= rate
;
1206 spin_lock_irq(&rme96
->lock
);
1207 if (rme96
->capture_substream
!= NULL
) {
1208 spin_unlock_irq(&rme96
->lock
);
1211 rme96
->capture_substream
= substream
;
1212 spin_unlock_irq(&rme96
->lock
);
1214 rme96_set_buffer_size_constraint(rme96
, runtime
);
1219 snd_rme96_playback_adat_open(struct snd_pcm_substream
*substream
)
1222 struct rme96
*rme96
= snd_pcm_substream_chip(substream
);
1223 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1225 spin_lock_irq(&rme96
->lock
);
1226 if (rme96
->playback_substream
!= NULL
) {
1227 spin_unlock_irq(&rme96
->lock
);
1230 rme96
->wcreg
|= RME96_WCR_ADAT
;
1231 writel(rme96
->wcreg
, rme96
->iobase
+ RME96_IO_CONTROL_REGISTER
);
1232 rme96
->playback_substream
= substream
;
1233 spin_unlock_irq(&rme96
->lock
);
1235 runtime
->hw
= snd_rme96_playback_adat_info
;
1236 if (!(rme96
->wcreg
& RME96_WCR_MASTER
) &&
1237 snd_rme96_getinputtype(rme96
) != RME96_INPUT_ANALOG
&&
1238 (rate
= snd_rme96_capture_getrate(rme96
, &dummy
)) > 0)
1241 runtime
->hw
.rates
= snd_pcm_rate_to_rate_bit(rate
);
1242 runtime
->hw
.rate_min
= rate
;
1243 runtime
->hw
.rate_max
= rate
;
1245 rme96_set_buffer_size_constraint(rme96
, runtime
);
1250 snd_rme96_capture_adat_open(struct snd_pcm_substream
*substream
)
1253 struct rme96
*rme96
= snd_pcm_substream_chip(substream
);
1254 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
1256 runtime
->hw
= snd_rme96_capture_adat_info
;
1257 if (snd_rme96_getinputtype(rme96
) == RME96_INPUT_ANALOG
) {
1258 /* makes no sense to use analog input. Note that analog
1259 expension cards AEB4/8-I are RME96_INPUT_INTERNAL */
1262 if ((rate
= snd_rme96_capture_getrate(rme96
, &isadat
)) > 0) {
1266 runtime
->hw
.rates
= snd_pcm_rate_to_rate_bit(rate
);
1267 runtime
->hw
.rate_min
= rate
;
1268 runtime
->hw
.rate_max
= rate
;
1271 spin_lock_irq(&rme96
->lock
);
1272 if (rme96
->capture_substream
!= NULL
) {
1273 spin_unlock_irq(&rme96
->lock
);
1276 rme96
->capture_substream
= substream
;
1277 spin_unlock_irq(&rme96
->lock
);
1279 rme96_set_buffer_size_constraint(rme96
, runtime
);
1284 snd_rme96_playback_close(struct snd_pcm_substream
*substream
)
1286 struct rme96
*rme96
= snd_pcm_substream_chip(substream
);
1289 spin_lock_irq(&rme96
->lock
);
1290 if (RME96_ISPLAYING(rme96
)) {
1291 snd_rme96_playback_stop(rme96
);
1293 rme96
->playback_substream
= NULL
;
1294 rme96
->playback_periodsize
= 0;
1295 spdif
= (rme96
->wcreg
& RME96_WCR_ADAT
) == 0;
1296 spin_unlock_irq(&rme96
->lock
);
1298 rme96
->spdif_ctl
->vd
[0].access
|= SNDRV_CTL_ELEM_ACCESS_INACTIVE
;
1299 snd_ctl_notify(rme96
->card
, SNDRV_CTL_EVENT_MASK_VALUE
|
1300 SNDRV_CTL_EVENT_MASK_INFO
, &rme96
->spdif_ctl
->id
);
1306 snd_rme96_capture_close(struct snd_pcm_substream
*substream
)
1308 struct rme96
*rme96
= snd_pcm_substream_chip(substream
);
1310 spin_lock_irq(&rme96
->lock
);
1311 if (RME96_ISRECORDING(rme96
)) {
1312 snd_rme96_capture_stop(rme96
);
1314 rme96
->capture_substream
= NULL
;
1315 rme96
->capture_periodsize
= 0;
1316 spin_unlock_irq(&rme96
->lock
);
1321 snd_rme96_playback_prepare(struct snd_pcm_substream
*substream
)
1323 struct rme96
*rme96
= snd_pcm_substream_chip(substream
);
1325 spin_lock_irq(&rme96
->lock
);
1326 if (RME96_ISPLAYING(rme96
)) {
1327 snd_rme96_playback_stop(rme96
);
1329 writel(0, rme96
->iobase
+ RME96_IO_RESET_PLAY_POS
);
1330 spin_unlock_irq(&rme96
->lock
);
1335 snd_rme96_capture_prepare(struct snd_pcm_substream
*substream
)
1337 struct rme96
*rme96
= snd_pcm_substream_chip(substream
);
1339 spin_lock_irq(&rme96
->lock
);
1340 if (RME96_ISRECORDING(rme96
)) {
1341 snd_rme96_capture_stop(rme96
);
1343 writel(0, rme96
->iobase
+ RME96_IO_RESET_REC_POS
);
1344 spin_unlock_irq(&rme96
->lock
);
1349 snd_rme96_playback_trigger(struct snd_pcm_substream
*substream
,
1352 struct rme96
*rme96
= snd_pcm_substream_chip(substream
);
1355 case SNDRV_PCM_TRIGGER_START
:
1356 if (!RME96_ISPLAYING(rme96
)) {
1357 if (substream
!= rme96
->playback_substream
) {
1360 snd_rme96_playback_start(rme96
, 0);
1364 case SNDRV_PCM_TRIGGER_STOP
:
1365 if (RME96_ISPLAYING(rme96
)) {
1366 if (substream
!= rme96
->playback_substream
) {
1369 snd_rme96_playback_stop(rme96
);
1373 case SNDRV_PCM_TRIGGER_PAUSE_PUSH
:
1374 if (RME96_ISPLAYING(rme96
)) {
1375 snd_rme96_playback_stop(rme96
);
1379 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE
:
1380 if (!RME96_ISPLAYING(rme96
)) {
1381 snd_rme96_playback_start(rme96
, 1);
1392 snd_rme96_capture_trigger(struct snd_pcm_substream
*substream
,
1395 struct rme96
*rme96
= snd_pcm_substream_chip(substream
);
1398 case SNDRV_PCM_TRIGGER_START
:
1399 if (!RME96_ISRECORDING(rme96
)) {
1400 if (substream
!= rme96
->capture_substream
) {
1403 snd_rme96_capture_start(rme96
, 0);
1407 case SNDRV_PCM_TRIGGER_STOP
:
1408 if (RME96_ISRECORDING(rme96
)) {
1409 if (substream
!= rme96
->capture_substream
) {
1412 snd_rme96_capture_stop(rme96
);
1416 case SNDRV_PCM_TRIGGER_PAUSE_PUSH
:
1417 if (RME96_ISRECORDING(rme96
)) {
1418 snd_rme96_capture_stop(rme96
);
1422 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE
:
1423 if (!RME96_ISRECORDING(rme96
)) {
1424 snd_rme96_capture_start(rme96
, 1);
1435 static snd_pcm_uframes_t
1436 snd_rme96_playback_pointer(struct snd_pcm_substream
*substream
)
1438 struct rme96
*rme96
= snd_pcm_substream_chip(substream
);
1439 return snd_rme96_playback_ptr(rme96
);
1442 static snd_pcm_uframes_t
1443 snd_rme96_capture_pointer(struct snd_pcm_substream
*substream
)
1445 struct rme96
*rme96
= snd_pcm_substream_chip(substream
);
1446 return snd_rme96_capture_ptr(rme96
);
1449 static struct snd_pcm_ops snd_rme96_playback_spdif_ops
= {
1450 .open
= snd_rme96_playback_spdif_open
,
1451 .close
= snd_rme96_playback_close
,
1452 .ioctl
= snd_pcm_lib_ioctl
,
1453 .hw_params
= snd_rme96_playback_hw_params
,
1454 .prepare
= snd_rme96_playback_prepare
,
1455 .trigger
= snd_rme96_playback_trigger
,
1456 .pointer
= snd_rme96_playback_pointer
,
1457 .copy
= snd_rme96_playback_copy
,
1458 .silence
= snd_rme96_playback_silence
,
1459 .mmap
= snd_pcm_lib_mmap_iomem
,
1462 static struct snd_pcm_ops snd_rme96_capture_spdif_ops
= {
1463 .open
= snd_rme96_capture_spdif_open
,
1464 .close
= snd_rme96_capture_close
,
1465 .ioctl
= snd_pcm_lib_ioctl
,
1466 .hw_params
= snd_rme96_capture_hw_params
,
1467 .prepare
= snd_rme96_capture_prepare
,
1468 .trigger
= snd_rme96_capture_trigger
,
1469 .pointer
= snd_rme96_capture_pointer
,
1470 .copy
= snd_rme96_capture_copy
,
1471 .mmap
= snd_pcm_lib_mmap_iomem
,
1474 static struct snd_pcm_ops snd_rme96_playback_adat_ops
= {
1475 .open
= snd_rme96_playback_adat_open
,
1476 .close
= snd_rme96_playback_close
,
1477 .ioctl
= snd_pcm_lib_ioctl
,
1478 .hw_params
= snd_rme96_playback_hw_params
,
1479 .prepare
= snd_rme96_playback_prepare
,
1480 .trigger
= snd_rme96_playback_trigger
,
1481 .pointer
= snd_rme96_playback_pointer
,
1482 .copy
= snd_rme96_playback_copy
,
1483 .silence
= snd_rme96_playback_silence
,
1484 .mmap
= snd_pcm_lib_mmap_iomem
,
1487 static struct snd_pcm_ops snd_rme96_capture_adat_ops
= {
1488 .open
= snd_rme96_capture_adat_open
,
1489 .close
= snd_rme96_capture_close
,
1490 .ioctl
= snd_pcm_lib_ioctl
,
1491 .hw_params
= snd_rme96_capture_hw_params
,
1492 .prepare
= snd_rme96_capture_prepare
,
1493 .trigger
= snd_rme96_capture_trigger
,
1494 .pointer
= snd_rme96_capture_pointer
,
1495 .copy
= snd_rme96_capture_copy
,
1496 .mmap
= snd_pcm_lib_mmap_iomem
,
1500 snd_rme96_free(void *private_data
)
1502 struct rme96
*rme96
= (struct rme96
*)private_data
;
1504 if (rme96
== NULL
) {
1507 if (rme96
->irq
>= 0) {
1508 snd_rme96_playback_stop(rme96
);
1509 snd_rme96_capture_stop(rme96
);
1510 rme96
->areg
&= ~RME96_AR_DAC_EN
;
1511 writel(rme96
->areg
, rme96
->iobase
+ RME96_IO_ADDITIONAL_REG
);
1512 free_irq(rme96
->irq
, (void *)rme96
);
1515 if (rme96
->iobase
) {
1516 iounmap(rme96
->iobase
);
1517 rme96
->iobase
= NULL
;
1520 pci_release_regions(rme96
->pci
);
1523 pci_disable_device(rme96
->pci
);
1527 snd_rme96_free_spdif_pcm(struct snd_pcm
*pcm
)
1529 struct rme96
*rme96
= pcm
->private_data
;
1530 rme96
->spdif_pcm
= NULL
;
1534 snd_rme96_free_adat_pcm(struct snd_pcm
*pcm
)
1536 struct rme96
*rme96
= pcm
->private_data
;
1537 rme96
->adat_pcm
= NULL
;
1541 snd_rme96_create(struct rme96
*rme96
)
1543 struct pci_dev
*pci
= rme96
->pci
;
1547 spin_lock_init(&rme96
->lock
);
1549 if ((err
= pci_enable_device(pci
)) < 0)
1552 if ((err
= pci_request_regions(pci
, "RME96")) < 0)
1554 rme96
->port
= pci_resource_start(rme96
->pci
, 0);
1556 rme96
->iobase
= ioremap_nocache(rme96
->port
, RME96_IO_SIZE
);
1557 if (!rme96
->iobase
) {
1558 snd_printk(KERN_ERR
"unable to remap memory region 0x%lx-0x%lx\n", rme96
->port
, rme96
->port
+ RME96_IO_SIZE
- 1);
1562 if (request_irq(pci
->irq
, snd_rme96_interrupt
, IRQF_SHARED
,
1563 KBUILD_MODNAME
, rme96
)) {
1564 snd_printk(KERN_ERR
"unable to grab IRQ %d\n", pci
->irq
);
1567 rme96
->irq
= pci
->irq
;
1569 /* read the card's revision number */
1570 pci_read_config_byte(pci
, 8, &rme96
->rev
);
1572 /* set up ALSA pcm device for S/PDIF */
1573 if ((err
= snd_pcm_new(rme96
->card
, "Digi96 IEC958", 0,
1574 1, 1, &rme96
->spdif_pcm
)) < 0)
1578 rme96
->spdif_pcm
->private_data
= rme96
;
1579 rme96
->spdif_pcm
->private_free
= snd_rme96_free_spdif_pcm
;
1580 strcpy(rme96
->spdif_pcm
->name
, "Digi96 IEC958");
1581 snd_pcm_set_ops(rme96
->spdif_pcm
, SNDRV_PCM_STREAM_PLAYBACK
, &snd_rme96_playback_spdif_ops
);
1582 snd_pcm_set_ops(rme96
->spdif_pcm
, SNDRV_PCM_STREAM_CAPTURE
, &snd_rme96_capture_spdif_ops
);
1584 rme96
->spdif_pcm
->info_flags
= 0;
1586 /* set up ALSA pcm device for ADAT */
1587 if (pci
->device
== PCI_DEVICE_ID_RME_DIGI96
) {
1588 /* ADAT is not available on the base model */
1589 rme96
->adat_pcm
= NULL
;
1591 if ((err
= snd_pcm_new(rme96
->card
, "Digi96 ADAT", 1,
1592 1, 1, &rme96
->adat_pcm
)) < 0)
1596 rme96
->adat_pcm
->private_data
= rme96
;
1597 rme96
->adat_pcm
->private_free
= snd_rme96_free_adat_pcm
;
1598 strcpy(rme96
->adat_pcm
->name
, "Digi96 ADAT");
1599 snd_pcm_set_ops(rme96
->adat_pcm
, SNDRV_PCM_STREAM_PLAYBACK
, &snd_rme96_playback_adat_ops
);
1600 snd_pcm_set_ops(rme96
->adat_pcm
, SNDRV_PCM_STREAM_CAPTURE
, &snd_rme96_capture_adat_ops
);
1602 rme96
->adat_pcm
->info_flags
= 0;
1605 rme96
->playback_periodsize
= 0;
1606 rme96
->capture_periodsize
= 0;
1608 /* make sure playback/capture is stopped, if by some reason active */
1609 snd_rme96_playback_stop(rme96
);
1610 snd_rme96_capture_stop(rme96
);
1612 /* set default values in registers */
1614 RME96_WCR_FREQ_1
| /* set 44.1 kHz playback */
1615 RME96_WCR_SEL
| /* normal playback */
1616 RME96_WCR_MASTER
| /* set to master clock mode */
1617 RME96_WCR_INP_0
; /* set coaxial input */
1619 rme96
->areg
= RME96_AR_FREQPAD_1
; /* set 44.1 kHz analog capture */
1621 writel(rme96
->wcreg
, rme96
->iobase
+ RME96_IO_CONTROL_REGISTER
);
1622 writel(rme96
->areg
, rme96
->iobase
+ RME96_IO_ADDITIONAL_REG
);
1625 writel(rme96
->areg
| RME96_AR_PD2
,
1626 rme96
->iobase
+ RME96_IO_ADDITIONAL_REG
);
1627 writel(rme96
->areg
, rme96
->iobase
+ RME96_IO_ADDITIONAL_REG
);
1629 /* reset and enable the DAC (order is important). */
1630 snd_rme96_reset_dac(rme96
);
1631 rme96
->areg
|= RME96_AR_DAC_EN
;
1632 writel(rme96
->areg
, rme96
->iobase
+ RME96_IO_ADDITIONAL_REG
);
1634 /* reset playback and record buffer pointers */
1635 writel(0, rme96
->iobase
+ RME96_IO_RESET_PLAY_POS
);
1636 writel(0, rme96
->iobase
+ RME96_IO_RESET_REC_POS
);
1639 rme96
->vol
[0] = rme96
->vol
[1] = 0;
1640 if (RME96_HAS_ANALOG_OUT(rme96
)) {
1641 snd_rme96_apply_dac_volume(rme96
);
1644 /* init switch interface */
1645 if ((err
= snd_rme96_create_switches(rme96
->card
, rme96
)) < 0) {
1649 /* init proc interface */
1650 snd_rme96_proc_init(rme96
);
1660 snd_rme96_proc_read(struct snd_info_entry
*entry
, struct snd_info_buffer
*buffer
)
1663 struct rme96
*rme96
= entry
->private_data
;
1665 rme96
->rcreg
= readl(rme96
->iobase
+ RME96_IO_CONTROL_REGISTER
);
1667 snd_iprintf(buffer
, rme96
->card
->longname
);
1668 snd_iprintf(buffer
, " (index #%d)\n", rme96
->card
->number
+ 1);
1670 snd_iprintf(buffer
, "\nGeneral settings\n");
1671 if (rme96
->wcreg
& RME96_WCR_IDIS
) {
1672 snd_iprintf(buffer
, " period size: N/A (interrupts "
1674 } else if (rme96
->wcreg
& RME96_WCR_ISEL
) {
1675 snd_iprintf(buffer
, " period size: 2048 bytes\n");
1677 snd_iprintf(buffer
, " period size: 8192 bytes\n");
1679 snd_iprintf(buffer
, "\nInput settings\n");
1680 switch (snd_rme96_getinputtype(rme96
)) {
1681 case RME96_INPUT_OPTICAL
:
1682 snd_iprintf(buffer
, " input: optical");
1684 case RME96_INPUT_COAXIAL
:
1685 snd_iprintf(buffer
, " input: coaxial");
1687 case RME96_INPUT_INTERNAL
:
1688 snd_iprintf(buffer
, " input: internal");
1690 case RME96_INPUT_XLR
:
1691 snd_iprintf(buffer
, " input: XLR");
1693 case RME96_INPUT_ANALOG
:
1694 snd_iprintf(buffer
, " input: analog");
1697 if (snd_rme96_capture_getrate(rme96
, &n
) < 0) {
1698 snd_iprintf(buffer
, "\n sample rate: no valid signal\n");
1701 snd_iprintf(buffer
, " (8 channels)\n");
1703 snd_iprintf(buffer
, " (2 channels)\n");
1705 snd_iprintf(buffer
, " sample rate: %d Hz\n",
1706 snd_rme96_capture_getrate(rme96
, &n
));
1708 if (rme96
->wcreg
& RME96_WCR_MODE24_2
) {
1709 snd_iprintf(buffer
, " sample format: 24 bit\n");
1711 snd_iprintf(buffer
, " sample format: 16 bit\n");
1714 snd_iprintf(buffer
, "\nOutput settings\n");
1715 if (rme96
->wcreg
& RME96_WCR_SEL
) {
1716 snd_iprintf(buffer
, " output signal: normal playback\n");
1718 snd_iprintf(buffer
, " output signal: same as input\n");
1720 snd_iprintf(buffer
, " sample rate: %d Hz\n",
1721 snd_rme96_playback_getrate(rme96
));
1722 if (rme96
->wcreg
& RME96_WCR_MODE24
) {
1723 snd_iprintf(buffer
, " sample format: 24 bit\n");
1725 snd_iprintf(buffer
, " sample format: 16 bit\n");
1727 if (rme96
->areg
& RME96_AR_WSEL
) {
1728 snd_iprintf(buffer
, " sample clock source: word clock\n");
1729 } else if (rme96
->wcreg
& RME96_WCR_MASTER
) {
1730 snd_iprintf(buffer
, " sample clock source: internal\n");
1731 } else if (snd_rme96_getinputtype(rme96
) == RME96_INPUT_ANALOG
) {
1732 snd_iprintf(buffer
, " sample clock source: autosync (internal anyway due to analog input setting)\n");
1733 } else if (snd_rme96_capture_getrate(rme96
, &n
) < 0) {
1734 snd_iprintf(buffer
, " sample clock source: autosync (internal anyway due to no valid signal)\n");
1736 snd_iprintf(buffer
, " sample clock source: autosync\n");
1738 if (rme96
->wcreg
& RME96_WCR_PRO
) {
1739 snd_iprintf(buffer
, " format: AES/EBU (professional)\n");
1741 snd_iprintf(buffer
, " format: IEC958 (consumer)\n");
1743 if (rme96
->wcreg
& RME96_WCR_EMP
) {
1744 snd_iprintf(buffer
, " emphasis: on\n");
1746 snd_iprintf(buffer
, " emphasis: off\n");
1748 if (rme96
->wcreg
& RME96_WCR_DOLBY
) {
1749 snd_iprintf(buffer
, " non-audio (dolby): on\n");
1751 snd_iprintf(buffer
, " non-audio (dolby): off\n");
1753 if (RME96_HAS_ANALOG_IN(rme96
)) {
1754 snd_iprintf(buffer
, "\nAnalog output settings\n");
1755 switch (snd_rme96_getmontracks(rme96
)) {
1756 case RME96_MONITOR_TRACKS_1_2
:
1757 snd_iprintf(buffer
, " monitored ADAT tracks: 1+2\n");
1759 case RME96_MONITOR_TRACKS_3_4
:
1760 snd_iprintf(buffer
, " monitored ADAT tracks: 3+4\n");
1762 case RME96_MONITOR_TRACKS_5_6
:
1763 snd_iprintf(buffer
, " monitored ADAT tracks: 5+6\n");
1765 case RME96_MONITOR_TRACKS_7_8
:
1766 snd_iprintf(buffer
, " monitored ADAT tracks: 7+8\n");
1769 switch (snd_rme96_getattenuation(rme96
)) {
1770 case RME96_ATTENUATION_0
:
1771 snd_iprintf(buffer
, " attenuation: 0 dB\n");
1773 case RME96_ATTENUATION_6
:
1774 snd_iprintf(buffer
, " attenuation: -6 dB\n");
1776 case RME96_ATTENUATION_12
:
1777 snd_iprintf(buffer
, " attenuation: -12 dB\n");
1779 case RME96_ATTENUATION_18
:
1780 snd_iprintf(buffer
, " attenuation: -18 dB\n");
1783 snd_iprintf(buffer
, " volume left: %u\n", rme96
->vol
[0]);
1784 snd_iprintf(buffer
, " volume right: %u\n", rme96
->vol
[1]);
1788 static void snd_rme96_proc_init(struct rme96
*rme96
)
1790 struct snd_info_entry
*entry
;
1792 if (! snd_card_proc_new(rme96
->card
, "rme96", &entry
))
1793 snd_info_set_text_ops(entry
, rme96
, snd_rme96_proc_read
);
1800 #define snd_rme96_info_loopback_control snd_ctl_boolean_mono_info
1803 snd_rme96_get_loopback_control(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
1805 struct rme96
*rme96
= snd_kcontrol_chip(kcontrol
);
1807 spin_lock_irq(&rme96
->lock
);
1808 ucontrol
->value
.integer
.value
[0] = rme96
->wcreg
& RME96_WCR_SEL
? 0 : 1;
1809 spin_unlock_irq(&rme96
->lock
);
1813 snd_rme96_put_loopback_control(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
1815 struct rme96
*rme96
= snd_kcontrol_chip(kcontrol
);
1819 val
= ucontrol
->value
.integer
.value
[0] ? 0 : RME96_WCR_SEL
;
1820 spin_lock_irq(&rme96
->lock
);
1821 val
= (rme96
->wcreg
& ~RME96_WCR_SEL
) | val
;
1822 change
= val
!= rme96
->wcreg
;
1824 writel(val
, rme96
->iobase
+ RME96_IO_CONTROL_REGISTER
);
1825 spin_unlock_irq(&rme96
->lock
);
1830 snd_rme96_info_inputtype_control(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_info
*uinfo
)
1832 static char *_texts
[5] = { "Optical", "Coaxial", "Internal", "XLR", "Analog" };
1833 struct rme96
*rme96
= snd_kcontrol_chip(kcontrol
);
1834 char *texts
[5] = { _texts
[0], _texts
[1], _texts
[2], _texts
[3], _texts
[4] };
1836 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
1838 switch (rme96
->pci
->device
) {
1839 case PCI_DEVICE_ID_RME_DIGI96
:
1840 case PCI_DEVICE_ID_RME_DIGI96_8
:
1841 uinfo
->value
.enumerated
.items
= 3;
1843 case PCI_DEVICE_ID_RME_DIGI96_8_PRO
:
1844 uinfo
->value
.enumerated
.items
= 4;
1846 case PCI_DEVICE_ID_RME_DIGI96_8_PAD_OR_PST
:
1847 if (rme96
->rev
> 4) {
1849 uinfo
->value
.enumerated
.items
= 4;
1850 texts
[3] = _texts
[4]; /* Analog instead of XLR */
1853 uinfo
->value
.enumerated
.items
= 5;
1860 if (uinfo
->value
.enumerated
.item
> uinfo
->value
.enumerated
.items
- 1) {
1861 uinfo
->value
.enumerated
.item
= uinfo
->value
.enumerated
.items
- 1;
1863 strcpy(uinfo
->value
.enumerated
.name
, texts
[uinfo
->value
.enumerated
.item
]);
1867 snd_rme96_get_inputtype_control(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
1869 struct rme96
*rme96
= snd_kcontrol_chip(kcontrol
);
1870 unsigned int items
= 3;
1872 spin_lock_irq(&rme96
->lock
);
1873 ucontrol
->value
.enumerated
.item
[0] = snd_rme96_getinputtype(rme96
);
1875 switch (rme96
->pci
->device
) {
1876 case PCI_DEVICE_ID_RME_DIGI96
:
1877 case PCI_DEVICE_ID_RME_DIGI96_8
:
1880 case PCI_DEVICE_ID_RME_DIGI96_8_PRO
:
1883 case PCI_DEVICE_ID_RME_DIGI96_8_PAD_OR_PST
:
1884 if (rme96
->rev
> 4) {
1885 /* for handling PST case, (INPUT_ANALOG is moved to INPUT_XLR */
1886 if (ucontrol
->value
.enumerated
.item
[0] == RME96_INPUT_ANALOG
) {
1887 ucontrol
->value
.enumerated
.item
[0] = RME96_INPUT_XLR
;
1898 if (ucontrol
->value
.enumerated
.item
[0] >= items
) {
1899 ucontrol
->value
.enumerated
.item
[0] = items
- 1;
1902 spin_unlock_irq(&rme96
->lock
);
1906 snd_rme96_put_inputtype_control(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
1908 struct rme96
*rme96
= snd_kcontrol_chip(kcontrol
);
1910 int change
, items
= 3;
1912 switch (rme96
->pci
->device
) {
1913 case PCI_DEVICE_ID_RME_DIGI96
:
1914 case PCI_DEVICE_ID_RME_DIGI96_8
:
1917 case PCI_DEVICE_ID_RME_DIGI96_8_PRO
:
1920 case PCI_DEVICE_ID_RME_DIGI96_8_PAD_OR_PST
:
1921 if (rme96
->rev
> 4) {
1931 val
= ucontrol
->value
.enumerated
.item
[0] % items
;
1933 /* special case for PST */
1934 if (rme96
->pci
->device
== PCI_DEVICE_ID_RME_DIGI96_8_PAD_OR_PST
&& rme96
->rev
> 4) {
1935 if (val
== RME96_INPUT_XLR
) {
1936 val
= RME96_INPUT_ANALOG
;
1940 spin_lock_irq(&rme96
->lock
);
1941 change
= (int)val
!= snd_rme96_getinputtype(rme96
);
1942 snd_rme96_setinputtype(rme96
, val
);
1943 spin_unlock_irq(&rme96
->lock
);
1948 snd_rme96_info_clockmode_control(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_info
*uinfo
)
1950 static char *texts
[3] = { "AutoSync", "Internal", "Word" };
1952 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
1954 uinfo
->value
.enumerated
.items
= 3;
1955 if (uinfo
->value
.enumerated
.item
> 2) {
1956 uinfo
->value
.enumerated
.item
= 2;
1958 strcpy(uinfo
->value
.enumerated
.name
, texts
[uinfo
->value
.enumerated
.item
]);
1962 snd_rme96_get_clockmode_control(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
1964 struct rme96
*rme96
= snd_kcontrol_chip(kcontrol
);
1966 spin_lock_irq(&rme96
->lock
);
1967 ucontrol
->value
.enumerated
.item
[0] = snd_rme96_getclockmode(rme96
);
1968 spin_unlock_irq(&rme96
->lock
);
1972 snd_rme96_put_clockmode_control(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
1974 struct rme96
*rme96
= snd_kcontrol_chip(kcontrol
);
1978 val
= ucontrol
->value
.enumerated
.item
[0] % 3;
1979 spin_lock_irq(&rme96
->lock
);
1980 change
= (int)val
!= snd_rme96_getclockmode(rme96
);
1981 snd_rme96_setclockmode(rme96
, val
);
1982 spin_unlock_irq(&rme96
->lock
);
1987 snd_rme96_info_attenuation_control(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_info
*uinfo
)
1989 static char *texts
[4] = { "0 dB", "-6 dB", "-12 dB", "-18 dB" };
1991 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
1993 uinfo
->value
.enumerated
.items
= 4;
1994 if (uinfo
->value
.enumerated
.item
> 3) {
1995 uinfo
->value
.enumerated
.item
= 3;
1997 strcpy(uinfo
->value
.enumerated
.name
, texts
[uinfo
->value
.enumerated
.item
]);
2001 snd_rme96_get_attenuation_control(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
2003 struct rme96
*rme96
= snd_kcontrol_chip(kcontrol
);
2005 spin_lock_irq(&rme96
->lock
);
2006 ucontrol
->value
.enumerated
.item
[0] = snd_rme96_getattenuation(rme96
);
2007 spin_unlock_irq(&rme96
->lock
);
2011 snd_rme96_put_attenuation_control(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
2013 struct rme96
*rme96
= snd_kcontrol_chip(kcontrol
);
2017 val
= ucontrol
->value
.enumerated
.item
[0] % 4;
2018 spin_lock_irq(&rme96
->lock
);
2020 change
= (int)val
!= snd_rme96_getattenuation(rme96
);
2021 snd_rme96_setattenuation(rme96
, val
);
2022 spin_unlock_irq(&rme96
->lock
);
2027 snd_rme96_info_montracks_control(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_info
*uinfo
)
2029 static char *texts
[4] = { "1+2", "3+4", "5+6", "7+8" };
2031 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
2033 uinfo
->value
.enumerated
.items
= 4;
2034 if (uinfo
->value
.enumerated
.item
> 3) {
2035 uinfo
->value
.enumerated
.item
= 3;
2037 strcpy(uinfo
->value
.enumerated
.name
, texts
[uinfo
->value
.enumerated
.item
]);
2041 snd_rme96_get_montracks_control(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
2043 struct rme96
*rme96
= snd_kcontrol_chip(kcontrol
);
2045 spin_lock_irq(&rme96
->lock
);
2046 ucontrol
->value
.enumerated
.item
[0] = snd_rme96_getmontracks(rme96
);
2047 spin_unlock_irq(&rme96
->lock
);
2051 snd_rme96_put_montracks_control(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
2053 struct rme96
*rme96
= snd_kcontrol_chip(kcontrol
);
2057 val
= ucontrol
->value
.enumerated
.item
[0] % 4;
2058 spin_lock_irq(&rme96
->lock
);
2059 change
= (int)val
!= snd_rme96_getmontracks(rme96
);
2060 snd_rme96_setmontracks(rme96
, val
);
2061 spin_unlock_irq(&rme96
->lock
);
2065 static u32
snd_rme96_convert_from_aes(struct snd_aes_iec958
*aes
)
2068 val
|= (aes
->status
[0] & IEC958_AES0_PROFESSIONAL
) ? RME96_WCR_PRO
: 0;
2069 val
|= (aes
->status
[0] & IEC958_AES0_NONAUDIO
) ? RME96_WCR_DOLBY
: 0;
2070 if (val
& RME96_WCR_PRO
)
2071 val
|= (aes
->status
[0] & IEC958_AES0_PRO_EMPHASIS_5015
) ? RME96_WCR_EMP
: 0;
2073 val
|= (aes
->status
[0] & IEC958_AES0_CON_EMPHASIS_5015
) ? RME96_WCR_EMP
: 0;
2077 static void snd_rme96_convert_to_aes(struct snd_aes_iec958
*aes
, u32 val
)
2079 aes
->status
[0] = ((val
& RME96_WCR_PRO
) ? IEC958_AES0_PROFESSIONAL
: 0) |
2080 ((val
& RME96_WCR_DOLBY
) ? IEC958_AES0_NONAUDIO
: 0);
2081 if (val
& RME96_WCR_PRO
)
2082 aes
->status
[0] |= (val
& RME96_WCR_EMP
) ? IEC958_AES0_PRO_EMPHASIS_5015
: 0;
2084 aes
->status
[0] |= (val
& RME96_WCR_EMP
) ? IEC958_AES0_CON_EMPHASIS_5015
: 0;
2087 static int snd_rme96_control_spdif_info(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_info
*uinfo
)
2089 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_IEC958
;
2094 static int snd_rme96_control_spdif_get(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
2096 struct rme96
*rme96
= snd_kcontrol_chip(kcontrol
);
2098 snd_rme96_convert_to_aes(&ucontrol
->value
.iec958
, rme96
->wcreg_spdif
);
2102 static int snd_rme96_control_spdif_put(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
2104 struct rme96
*rme96
= snd_kcontrol_chip(kcontrol
);
2108 val
= snd_rme96_convert_from_aes(&ucontrol
->value
.iec958
);
2109 spin_lock_irq(&rme96
->lock
);
2110 change
= val
!= rme96
->wcreg_spdif
;
2111 rme96
->wcreg_spdif
= val
;
2112 spin_unlock_irq(&rme96
->lock
);
2116 static int snd_rme96_control_spdif_stream_info(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_info
*uinfo
)
2118 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_IEC958
;
2123 static int snd_rme96_control_spdif_stream_get(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
2125 struct rme96
*rme96
= snd_kcontrol_chip(kcontrol
);
2127 snd_rme96_convert_to_aes(&ucontrol
->value
.iec958
, rme96
->wcreg_spdif_stream
);
2131 static int snd_rme96_control_spdif_stream_put(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
2133 struct rme96
*rme96
= snd_kcontrol_chip(kcontrol
);
2137 val
= snd_rme96_convert_from_aes(&ucontrol
->value
.iec958
);
2138 spin_lock_irq(&rme96
->lock
);
2139 change
= val
!= rme96
->wcreg_spdif_stream
;
2140 rme96
->wcreg_spdif_stream
= val
;
2141 rme96
->wcreg
&= ~(RME96_WCR_PRO
| RME96_WCR_DOLBY
| RME96_WCR_EMP
);
2142 rme96
->wcreg
|= val
;
2143 writel(rme96
->wcreg
, rme96
->iobase
+ RME96_IO_CONTROL_REGISTER
);
2144 spin_unlock_irq(&rme96
->lock
);
2148 static int snd_rme96_control_spdif_mask_info(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_info
*uinfo
)
2150 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_IEC958
;
2155 static int snd_rme96_control_spdif_mask_get(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
2157 ucontrol
->value
.iec958
.status
[0] = kcontrol
->private_value
;
2162 snd_rme96_dac_volume_info(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_info
*uinfo
)
2164 struct rme96
*rme96
= snd_kcontrol_chip(kcontrol
);
2166 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
2168 uinfo
->value
.integer
.min
= 0;
2169 uinfo
->value
.integer
.max
= RME96_185X_MAX_OUT(rme96
);
2174 snd_rme96_dac_volume_get(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*u
)
2176 struct rme96
*rme96
= snd_kcontrol_chip(kcontrol
);
2178 spin_lock_irq(&rme96
->lock
);
2179 u
->value
.integer
.value
[0] = rme96
->vol
[0];
2180 u
->value
.integer
.value
[1] = rme96
->vol
[1];
2181 spin_unlock_irq(&rme96
->lock
);
2187 snd_rme96_dac_volume_put(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*u
)
2189 struct rme96
*rme96
= snd_kcontrol_chip(kcontrol
);
2191 unsigned int vol
, maxvol
;
2194 if (!RME96_HAS_ANALOG_OUT(rme96
))
2196 maxvol
= RME96_185X_MAX_OUT(rme96
);
2197 spin_lock_irq(&rme96
->lock
);
2198 vol
= u
->value
.integer
.value
[0];
2199 if (vol
!= rme96
->vol
[0] && vol
<= maxvol
) {
2200 rme96
->vol
[0] = vol
;
2203 vol
= u
->value
.integer
.value
[1];
2204 if (vol
!= rme96
->vol
[1] && vol
<= maxvol
) {
2205 rme96
->vol
[1] = vol
;
2209 snd_rme96_apply_dac_volume(rme96
);
2210 spin_unlock_irq(&rme96
->lock
);
2215 static struct snd_kcontrol_new snd_rme96_controls
[] = {
2217 .iface
= SNDRV_CTL_ELEM_IFACE_PCM
,
2218 .name
= SNDRV_CTL_NAME_IEC958("",PLAYBACK
,DEFAULT
),
2219 .info
= snd_rme96_control_spdif_info
,
2220 .get
= snd_rme96_control_spdif_get
,
2221 .put
= snd_rme96_control_spdif_put
2224 .access
= SNDRV_CTL_ELEM_ACCESS_READWRITE
| SNDRV_CTL_ELEM_ACCESS_INACTIVE
,
2225 .iface
= SNDRV_CTL_ELEM_IFACE_PCM
,
2226 .name
= SNDRV_CTL_NAME_IEC958("",PLAYBACK
,PCM_STREAM
),
2227 .info
= snd_rme96_control_spdif_stream_info
,
2228 .get
= snd_rme96_control_spdif_stream_get
,
2229 .put
= snd_rme96_control_spdif_stream_put
2232 .access
= SNDRV_CTL_ELEM_ACCESS_READ
,
2233 .iface
= SNDRV_CTL_ELEM_IFACE_PCM
,
2234 .name
= SNDRV_CTL_NAME_IEC958("",PLAYBACK
,CON_MASK
),
2235 .info
= snd_rme96_control_spdif_mask_info
,
2236 .get
= snd_rme96_control_spdif_mask_get
,
2237 .private_value
= IEC958_AES0_NONAUDIO
|
2238 IEC958_AES0_PROFESSIONAL
|
2239 IEC958_AES0_CON_EMPHASIS
2242 .access
= SNDRV_CTL_ELEM_ACCESS_READ
,
2243 .iface
= SNDRV_CTL_ELEM_IFACE_PCM
,
2244 .name
= SNDRV_CTL_NAME_IEC958("",PLAYBACK
,PRO_MASK
),
2245 .info
= snd_rme96_control_spdif_mask_info
,
2246 .get
= snd_rme96_control_spdif_mask_get
,
2247 .private_value
= IEC958_AES0_NONAUDIO
|
2248 IEC958_AES0_PROFESSIONAL
|
2249 IEC958_AES0_PRO_EMPHASIS
2252 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
2253 .name
= "Input Connector",
2254 .info
= snd_rme96_info_inputtype_control
,
2255 .get
= snd_rme96_get_inputtype_control
,
2256 .put
= snd_rme96_put_inputtype_control
2259 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
2260 .name
= "Loopback Input",
2261 .info
= snd_rme96_info_loopback_control
,
2262 .get
= snd_rme96_get_loopback_control
,
2263 .put
= snd_rme96_put_loopback_control
2266 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
2267 .name
= "Sample Clock Source",
2268 .info
= snd_rme96_info_clockmode_control
,
2269 .get
= snd_rme96_get_clockmode_control
,
2270 .put
= snd_rme96_put_clockmode_control
2273 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
2274 .name
= "Monitor Tracks",
2275 .info
= snd_rme96_info_montracks_control
,
2276 .get
= snd_rme96_get_montracks_control
,
2277 .put
= snd_rme96_put_montracks_control
2280 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
2281 .name
= "Attenuation",
2282 .info
= snd_rme96_info_attenuation_control
,
2283 .get
= snd_rme96_get_attenuation_control
,
2284 .put
= snd_rme96_put_attenuation_control
2287 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
2288 .name
= "DAC Playback Volume",
2289 .info
= snd_rme96_dac_volume_info
,
2290 .get
= snd_rme96_dac_volume_get
,
2291 .put
= snd_rme96_dac_volume_put
2296 snd_rme96_create_switches(struct snd_card
*card
,
2297 struct rme96
*rme96
)
2300 struct snd_kcontrol
*kctl
;
2302 for (idx
= 0; idx
< 7; idx
++) {
2303 if ((err
= snd_ctl_add(card
, kctl
= snd_ctl_new1(&snd_rme96_controls
[idx
], rme96
))) < 0)
2305 if (idx
== 1) /* IEC958 (S/PDIF) Stream */
2306 rme96
->spdif_ctl
= kctl
;
2309 if (RME96_HAS_ANALOG_OUT(rme96
)) {
2310 for (idx
= 7; idx
< 10; idx
++)
2311 if ((err
= snd_ctl_add(card
, snd_ctl_new1(&snd_rme96_controls
[idx
], rme96
))) < 0)
2319 * Card initialisation
2322 static void snd_rme96_card_free(struct snd_card
*card
)
2324 snd_rme96_free(card
->private_data
);
2328 snd_rme96_probe(struct pci_dev
*pci
,
2329 const struct pci_device_id
*pci_id
)
2332 struct rme96
*rme96
;
2333 struct snd_card
*card
;
2337 if (dev
>= SNDRV_CARDS
) {
2344 err
= snd_card_create(index
[dev
], id
[dev
], THIS_MODULE
,
2345 sizeof(struct rme96
), &card
);
2348 card
->private_free
= snd_rme96_card_free
;
2349 rme96
= card
->private_data
;
2352 snd_card_set_dev(card
, &pci
->dev
);
2353 if ((err
= snd_rme96_create(rme96
)) < 0) {
2354 snd_card_free(card
);
2358 strcpy(card
->driver
, "Digi96");
2359 switch (rme96
->pci
->device
) {
2360 case PCI_DEVICE_ID_RME_DIGI96
:
2361 strcpy(card
->shortname
, "RME Digi96");
2363 case PCI_DEVICE_ID_RME_DIGI96_8
:
2364 strcpy(card
->shortname
, "RME Digi96/8");
2366 case PCI_DEVICE_ID_RME_DIGI96_8_PRO
:
2367 strcpy(card
->shortname
, "RME Digi96/8 PRO");
2369 case PCI_DEVICE_ID_RME_DIGI96_8_PAD_OR_PST
:
2370 pci_read_config_byte(rme96
->pci
, 8, &val
);
2372 strcpy(card
->shortname
, "RME Digi96/8 PAD");
2374 strcpy(card
->shortname
, "RME Digi96/8 PST");
2378 sprintf(card
->longname
, "%s at 0x%lx, irq %d", card
->shortname
,
2379 rme96
->port
, rme96
->irq
);
2381 if ((err
= snd_card_register(card
)) < 0) {
2382 snd_card_free(card
);
2385 pci_set_drvdata(pci
, card
);
2390 static void snd_rme96_remove(struct pci_dev
*pci
)
2392 snd_card_free(pci_get_drvdata(pci
));
2393 pci_set_drvdata(pci
, NULL
);
2396 static struct pci_driver rme96_driver
= {
2397 .name
= KBUILD_MODNAME
,
2398 .id_table
= snd_rme96_ids
,
2399 .probe
= snd_rme96_probe
,
2400 .remove
= snd_rme96_remove
,
2403 module_pci_driver(rme96_driver
);