xref: /openbmc/linux/sound/pci/rme96.c (revision 1da177e4c3f41524e886b7f1b8a0c1fc7321cac2)
1*1da177e4SLinus Torvalds /*
2*1da177e4SLinus Torvalds  *   ALSA driver for RME Digi96, Digi96/8 and Digi96/8 PRO/PAD/PST audio
3*1da177e4SLinus Torvalds  *   interfaces
4*1da177e4SLinus Torvalds  *
5*1da177e4SLinus Torvalds  *	Copyright (c) 2000, 2001 Anders Torger <torger@ludd.luth.se>
6*1da177e4SLinus Torvalds  *
7*1da177e4SLinus Torvalds  *      Thanks to Henk Hesselink <henk@anda.nl> for the analog volume control
8*1da177e4SLinus Torvalds  *      code.
9*1da177e4SLinus Torvalds  *
10*1da177e4SLinus Torvalds  *   This program is free software; you can redistribute it and/or modify
11*1da177e4SLinus Torvalds  *   it under the terms of the GNU General Public License as published by
12*1da177e4SLinus Torvalds  *   the Free Software Foundation; either version 2 of the License, or
13*1da177e4SLinus Torvalds  *   (at your option) any later version.
14*1da177e4SLinus Torvalds  *
15*1da177e4SLinus Torvalds  *   This program is distributed in the hope that it will be useful,
16*1da177e4SLinus Torvalds  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
17*1da177e4SLinus Torvalds  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*1da177e4SLinus Torvalds  *   GNU General Public License for more details.
19*1da177e4SLinus Torvalds  *
20*1da177e4SLinus Torvalds  *   You should have received a copy of the GNU General Public License
21*1da177e4SLinus Torvalds  *   along with this program; if not, write to the Free Software
22*1da177e4SLinus Torvalds  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
23*1da177e4SLinus Torvalds  *
24*1da177e4SLinus Torvalds  */
25*1da177e4SLinus Torvalds 
26*1da177e4SLinus Torvalds #include <sound/driver.h>
27*1da177e4SLinus Torvalds #include <linux/delay.h>
28*1da177e4SLinus Torvalds #include <linux/init.h>
29*1da177e4SLinus Torvalds #include <linux/interrupt.h>
30*1da177e4SLinus Torvalds #include <linux/pci.h>
31*1da177e4SLinus Torvalds #include <linux/slab.h>
32*1da177e4SLinus Torvalds #include <linux/moduleparam.h>
33*1da177e4SLinus Torvalds 
34*1da177e4SLinus Torvalds #include <sound/core.h>
35*1da177e4SLinus Torvalds #include <sound/info.h>
36*1da177e4SLinus Torvalds #include <sound/control.h>
37*1da177e4SLinus Torvalds #include <sound/pcm.h>
38*1da177e4SLinus Torvalds #include <sound/pcm_params.h>
39*1da177e4SLinus Torvalds #include <sound/asoundef.h>
40*1da177e4SLinus Torvalds #include <sound/initval.h>
41*1da177e4SLinus Torvalds 
42*1da177e4SLinus Torvalds #include <asm/io.h>
43*1da177e4SLinus Torvalds 
44*1da177e4SLinus Torvalds /* note, two last pcis should be equal, it is not a bug */
45*1da177e4SLinus Torvalds 
46*1da177e4SLinus Torvalds MODULE_AUTHOR("Anders Torger <torger@ludd.luth.se>");
47*1da177e4SLinus Torvalds MODULE_DESCRIPTION("RME Digi96, Digi96/8, Digi96/8 PRO, Digi96/8 PST, "
48*1da177e4SLinus Torvalds 		   "Digi96/8 PAD");
49*1da177e4SLinus Torvalds MODULE_LICENSE("GPL");
50*1da177e4SLinus Torvalds MODULE_SUPPORTED_DEVICE("{{RME,Digi96},"
51*1da177e4SLinus Torvalds 		"{RME,Digi96/8},"
52*1da177e4SLinus Torvalds 		"{RME,Digi96/8 PRO},"
53*1da177e4SLinus Torvalds 		"{RME,Digi96/8 PST},"
54*1da177e4SLinus Torvalds 		"{RME,Digi96/8 PAD}}");
55*1da177e4SLinus Torvalds 
56*1da177e4SLinus Torvalds static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;	/* Index 0-MAX */
57*1da177e4SLinus Torvalds static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;	/* ID for this card */
58*1da177e4SLinus Torvalds static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;	/* Enable this card */
59*1da177e4SLinus Torvalds 
60*1da177e4SLinus Torvalds module_param_array(index, int, NULL, 0444);
61*1da177e4SLinus Torvalds MODULE_PARM_DESC(index, "Index value for RME Digi96 soundcard.");
62*1da177e4SLinus Torvalds module_param_array(id, charp, NULL, 0444);
63*1da177e4SLinus Torvalds MODULE_PARM_DESC(id, "ID string for RME Digi96 soundcard.");
64*1da177e4SLinus Torvalds module_param_array(enable, bool, NULL, 0444);
65*1da177e4SLinus Torvalds MODULE_PARM_DESC(enable, "Enable RME Digi96 soundcard.");
66*1da177e4SLinus Torvalds 
67*1da177e4SLinus Torvalds /*
68*1da177e4SLinus Torvalds  * Defines for RME Digi96 series, from internal RME reference documents
69*1da177e4SLinus Torvalds  * dated 12.01.00
70*1da177e4SLinus Torvalds  */
71*1da177e4SLinus Torvalds 
72*1da177e4SLinus Torvalds #define RME96_SPDIF_NCHANNELS 2
73*1da177e4SLinus Torvalds 
74*1da177e4SLinus Torvalds /* Playback and capture buffer size */
75*1da177e4SLinus Torvalds #define RME96_BUFFER_SIZE 0x10000
76*1da177e4SLinus Torvalds 
77*1da177e4SLinus Torvalds /* IO area size */
78*1da177e4SLinus Torvalds #define RME96_IO_SIZE 0x60000
79*1da177e4SLinus Torvalds 
80*1da177e4SLinus Torvalds /* IO area offsets */
81*1da177e4SLinus Torvalds #define RME96_IO_PLAY_BUFFER      0x0
82*1da177e4SLinus Torvalds #define RME96_IO_REC_BUFFER       0x10000
83*1da177e4SLinus Torvalds #define RME96_IO_CONTROL_REGISTER 0x20000
84*1da177e4SLinus Torvalds #define RME96_IO_ADDITIONAL_REG   0x20004
85*1da177e4SLinus Torvalds #define RME96_IO_CONFIRM_PLAY_IRQ 0x20008
86*1da177e4SLinus Torvalds #define RME96_IO_CONFIRM_REC_IRQ  0x2000C
87*1da177e4SLinus Torvalds #define RME96_IO_SET_PLAY_POS     0x40000
88*1da177e4SLinus Torvalds #define RME96_IO_RESET_PLAY_POS   0x4FFFC
89*1da177e4SLinus Torvalds #define RME96_IO_SET_REC_POS      0x50000
90*1da177e4SLinus Torvalds #define RME96_IO_RESET_REC_POS    0x5FFFC
91*1da177e4SLinus Torvalds #define RME96_IO_GET_PLAY_POS     0x20000
92*1da177e4SLinus Torvalds #define RME96_IO_GET_REC_POS      0x30000
93*1da177e4SLinus Torvalds 
94*1da177e4SLinus Torvalds /* Write control register bits */
95*1da177e4SLinus Torvalds #define RME96_WCR_START     (1 << 0)
96*1da177e4SLinus Torvalds #define RME96_WCR_START_2   (1 << 1)
97*1da177e4SLinus Torvalds #define RME96_WCR_GAIN_0    (1 << 2)
98*1da177e4SLinus Torvalds #define RME96_WCR_GAIN_1    (1 << 3)
99*1da177e4SLinus Torvalds #define RME96_WCR_MODE24    (1 << 4)
100*1da177e4SLinus Torvalds #define RME96_WCR_MODE24_2  (1 << 5)
101*1da177e4SLinus Torvalds #define RME96_WCR_BM        (1 << 6)
102*1da177e4SLinus Torvalds #define RME96_WCR_BM_2      (1 << 7)
103*1da177e4SLinus Torvalds #define RME96_WCR_ADAT      (1 << 8)
104*1da177e4SLinus Torvalds #define RME96_WCR_FREQ_0    (1 << 9)
105*1da177e4SLinus Torvalds #define RME96_WCR_FREQ_1    (1 << 10)
106*1da177e4SLinus Torvalds #define RME96_WCR_DS        (1 << 11)
107*1da177e4SLinus Torvalds #define RME96_WCR_PRO       (1 << 12)
108*1da177e4SLinus Torvalds #define RME96_WCR_EMP       (1 << 13)
109*1da177e4SLinus Torvalds #define RME96_WCR_SEL       (1 << 14)
110*1da177e4SLinus Torvalds #define RME96_WCR_MASTER    (1 << 15)
111*1da177e4SLinus Torvalds #define RME96_WCR_PD        (1 << 16)
112*1da177e4SLinus Torvalds #define RME96_WCR_INP_0     (1 << 17)
113*1da177e4SLinus Torvalds #define RME96_WCR_INP_1     (1 << 18)
114*1da177e4SLinus Torvalds #define RME96_WCR_THRU_0    (1 << 19)
115*1da177e4SLinus Torvalds #define RME96_WCR_THRU_1    (1 << 20)
116*1da177e4SLinus Torvalds #define RME96_WCR_THRU_2    (1 << 21)
117*1da177e4SLinus Torvalds #define RME96_WCR_THRU_3    (1 << 22)
118*1da177e4SLinus Torvalds #define RME96_WCR_THRU_4    (1 << 23)
119*1da177e4SLinus Torvalds #define RME96_WCR_THRU_5    (1 << 24)
120*1da177e4SLinus Torvalds #define RME96_WCR_THRU_6    (1 << 25)
121*1da177e4SLinus Torvalds #define RME96_WCR_THRU_7    (1 << 26)
122*1da177e4SLinus Torvalds #define RME96_WCR_DOLBY     (1 << 27)
123*1da177e4SLinus Torvalds #define RME96_WCR_MONITOR_0 (1 << 28)
124*1da177e4SLinus Torvalds #define RME96_WCR_MONITOR_1 (1 << 29)
125*1da177e4SLinus Torvalds #define RME96_WCR_ISEL      (1 << 30)
126*1da177e4SLinus Torvalds #define RME96_WCR_IDIS      (1 << 31)
127*1da177e4SLinus Torvalds 
128*1da177e4SLinus Torvalds #define RME96_WCR_BITPOS_GAIN_0 2
129*1da177e4SLinus Torvalds #define RME96_WCR_BITPOS_GAIN_1 3
130*1da177e4SLinus Torvalds #define RME96_WCR_BITPOS_FREQ_0 9
131*1da177e4SLinus Torvalds #define RME96_WCR_BITPOS_FREQ_1 10
132*1da177e4SLinus Torvalds #define RME96_WCR_BITPOS_INP_0 17
133*1da177e4SLinus Torvalds #define RME96_WCR_BITPOS_INP_1 18
134*1da177e4SLinus Torvalds #define RME96_WCR_BITPOS_MONITOR_0 28
135*1da177e4SLinus Torvalds #define RME96_WCR_BITPOS_MONITOR_1 29
136*1da177e4SLinus Torvalds 
137*1da177e4SLinus Torvalds /* Read control register bits */
138*1da177e4SLinus Torvalds #define RME96_RCR_AUDIO_ADDR_MASK 0xFFFF
139*1da177e4SLinus Torvalds #define RME96_RCR_IRQ_2     (1 << 16)
140*1da177e4SLinus Torvalds #define RME96_RCR_T_OUT     (1 << 17)
141*1da177e4SLinus Torvalds #define RME96_RCR_DEV_ID_0  (1 << 21)
142*1da177e4SLinus Torvalds #define RME96_RCR_DEV_ID_1  (1 << 22)
143*1da177e4SLinus Torvalds #define RME96_RCR_LOCK      (1 << 23)
144*1da177e4SLinus Torvalds #define RME96_RCR_VERF      (1 << 26)
145*1da177e4SLinus Torvalds #define RME96_RCR_F0        (1 << 27)
146*1da177e4SLinus Torvalds #define RME96_RCR_F1        (1 << 28)
147*1da177e4SLinus Torvalds #define RME96_RCR_F2        (1 << 29)
148*1da177e4SLinus Torvalds #define RME96_RCR_AUTOSYNC  (1 << 30)
149*1da177e4SLinus Torvalds #define RME96_RCR_IRQ       (1 << 31)
150*1da177e4SLinus Torvalds 
151*1da177e4SLinus Torvalds #define RME96_RCR_BITPOS_F0 27
152*1da177e4SLinus Torvalds #define RME96_RCR_BITPOS_F1 28
153*1da177e4SLinus Torvalds #define RME96_RCR_BITPOS_F2 29
154*1da177e4SLinus Torvalds 
155*1da177e4SLinus Torvalds /* Additonal register bits */
156*1da177e4SLinus Torvalds #define RME96_AR_WSEL       (1 << 0)
157*1da177e4SLinus Torvalds #define RME96_AR_ANALOG     (1 << 1)
158*1da177e4SLinus Torvalds #define RME96_AR_FREQPAD_0  (1 << 2)
159*1da177e4SLinus Torvalds #define RME96_AR_FREQPAD_1  (1 << 3)
160*1da177e4SLinus Torvalds #define RME96_AR_FREQPAD_2  (1 << 4)
161*1da177e4SLinus Torvalds #define RME96_AR_PD2        (1 << 5)
162*1da177e4SLinus Torvalds #define RME96_AR_DAC_EN     (1 << 6)
163*1da177e4SLinus Torvalds #define RME96_AR_CLATCH     (1 << 7)
164*1da177e4SLinus Torvalds #define RME96_AR_CCLK       (1 << 8)
165*1da177e4SLinus Torvalds #define RME96_AR_CDATA      (1 << 9)
166*1da177e4SLinus Torvalds 
167*1da177e4SLinus Torvalds #define RME96_AR_BITPOS_F0 2
168*1da177e4SLinus Torvalds #define RME96_AR_BITPOS_F1 3
169*1da177e4SLinus Torvalds #define RME96_AR_BITPOS_F2 4
170*1da177e4SLinus Torvalds 
171*1da177e4SLinus Torvalds /* Monitor tracks */
172*1da177e4SLinus Torvalds #define RME96_MONITOR_TRACKS_1_2 0
173*1da177e4SLinus Torvalds #define RME96_MONITOR_TRACKS_3_4 1
174*1da177e4SLinus Torvalds #define RME96_MONITOR_TRACKS_5_6 2
175*1da177e4SLinus Torvalds #define RME96_MONITOR_TRACKS_7_8 3
176*1da177e4SLinus Torvalds 
177*1da177e4SLinus Torvalds /* Attenuation */
178*1da177e4SLinus Torvalds #define RME96_ATTENUATION_0 0
179*1da177e4SLinus Torvalds #define RME96_ATTENUATION_6 1
180*1da177e4SLinus Torvalds #define RME96_ATTENUATION_12 2
181*1da177e4SLinus Torvalds #define RME96_ATTENUATION_18 3
182*1da177e4SLinus Torvalds 
183*1da177e4SLinus Torvalds /* Input types */
184*1da177e4SLinus Torvalds #define RME96_INPUT_OPTICAL 0
185*1da177e4SLinus Torvalds #define RME96_INPUT_COAXIAL 1
186*1da177e4SLinus Torvalds #define RME96_INPUT_INTERNAL 2
187*1da177e4SLinus Torvalds #define RME96_INPUT_XLR 3
188*1da177e4SLinus Torvalds #define RME96_INPUT_ANALOG 4
189*1da177e4SLinus Torvalds 
190*1da177e4SLinus Torvalds /* Clock modes */
191*1da177e4SLinus Torvalds #define RME96_CLOCKMODE_SLAVE 0
192*1da177e4SLinus Torvalds #define RME96_CLOCKMODE_MASTER 1
193*1da177e4SLinus Torvalds #define RME96_CLOCKMODE_WORDCLOCK 2
194*1da177e4SLinus Torvalds 
195*1da177e4SLinus Torvalds /* Block sizes in bytes */
196*1da177e4SLinus Torvalds #define RME96_SMALL_BLOCK_SIZE 2048
197*1da177e4SLinus Torvalds #define RME96_LARGE_BLOCK_SIZE 8192
198*1da177e4SLinus Torvalds 
199*1da177e4SLinus Torvalds /* Volume control */
200*1da177e4SLinus Torvalds #define RME96_AD1852_VOL_BITS 14
201*1da177e4SLinus Torvalds #define RME96_AD1855_VOL_BITS 10
202*1da177e4SLinus Torvalds 
203*1da177e4SLinus Torvalds /*
204*1da177e4SLinus Torvalds  * PCI vendor/device ids, could in the future be defined in <linux/pci.h>,
205*1da177e4SLinus Torvalds  * therefore #ifndef is used.
206*1da177e4SLinus Torvalds  */
207*1da177e4SLinus Torvalds #ifndef PCI_VENDOR_ID_XILINX
208*1da177e4SLinus Torvalds #define PCI_VENDOR_ID_XILINX 0x10ee
209*1da177e4SLinus Torvalds #endif
210*1da177e4SLinus Torvalds #ifndef PCI_DEVICE_ID_DIGI96
211*1da177e4SLinus Torvalds #define PCI_DEVICE_ID_DIGI96 0x3fc0
212*1da177e4SLinus Torvalds #endif
213*1da177e4SLinus Torvalds #ifndef PCI_DEVICE_ID_DIGI96_8
214*1da177e4SLinus Torvalds #define PCI_DEVICE_ID_DIGI96_8 0x3fc1
215*1da177e4SLinus Torvalds #endif
216*1da177e4SLinus Torvalds #ifndef PCI_DEVICE_ID_DIGI96_8_PRO
217*1da177e4SLinus Torvalds #define PCI_DEVICE_ID_DIGI96_8_PRO 0x3fc2
218*1da177e4SLinus Torvalds #endif
219*1da177e4SLinus Torvalds #ifndef PCI_DEVICE_ID_DIGI96_8_PAD_OR_PST
220*1da177e4SLinus Torvalds #define PCI_DEVICE_ID_DIGI96_8_PAD_OR_PST 0x3fc3
221*1da177e4SLinus Torvalds #endif
222*1da177e4SLinus Torvalds 
223*1da177e4SLinus Torvalds typedef struct snd_rme96 {
224*1da177e4SLinus Torvalds 	spinlock_t    lock;
225*1da177e4SLinus Torvalds 	int irq;
226*1da177e4SLinus Torvalds 	unsigned long port;
227*1da177e4SLinus Torvalds 	void __iomem *iobase;
228*1da177e4SLinus Torvalds 
229*1da177e4SLinus Torvalds 	u32 wcreg;    /* cached write control register value */
230*1da177e4SLinus Torvalds 	u32 wcreg_spdif;		/* S/PDIF setup */
231*1da177e4SLinus Torvalds 	u32 wcreg_spdif_stream;		/* S/PDIF setup (temporary) */
232*1da177e4SLinus Torvalds 	u32 rcreg;    /* cached read control register value */
233*1da177e4SLinus Torvalds 	u32 areg;     /* cached additional register value */
234*1da177e4SLinus Torvalds 	u16 vol[2]; /* cached volume of analog output */
235*1da177e4SLinus Torvalds 
236*1da177e4SLinus Torvalds 	u8 rev; /* card revision number */
237*1da177e4SLinus Torvalds 
238*1da177e4SLinus Torvalds 	snd_pcm_substream_t *playback_substream;
239*1da177e4SLinus Torvalds 	snd_pcm_substream_t *capture_substream;
240*1da177e4SLinus Torvalds 
241*1da177e4SLinus Torvalds 	int playback_frlog; /* log2 of framesize */
242*1da177e4SLinus Torvalds 	int capture_frlog;
243*1da177e4SLinus Torvalds 
244*1da177e4SLinus Torvalds         size_t playback_periodsize; /* in bytes, zero if not used */
245*1da177e4SLinus Torvalds 	size_t capture_periodsize; /* in bytes, zero if not used */
246*1da177e4SLinus Torvalds 
247*1da177e4SLinus Torvalds 	snd_card_t         *card;
248*1da177e4SLinus Torvalds 	snd_pcm_t          *spdif_pcm;
249*1da177e4SLinus Torvalds 	snd_pcm_t          *adat_pcm;
250*1da177e4SLinus Torvalds 	struct pci_dev     *pci;
251*1da177e4SLinus Torvalds 	snd_kcontrol_t	   *spdif_ctl;
252*1da177e4SLinus Torvalds } rme96_t;
253*1da177e4SLinus Torvalds 
254*1da177e4SLinus Torvalds static struct pci_device_id snd_rme96_ids[] = {
255*1da177e4SLinus Torvalds 	{ PCI_VENDOR_ID_XILINX, PCI_DEVICE_ID_DIGI96,
256*1da177e4SLinus Torvalds 	  PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, },
257*1da177e4SLinus Torvalds 	{ PCI_VENDOR_ID_XILINX, PCI_DEVICE_ID_DIGI96_8,
258*1da177e4SLinus Torvalds 	  PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, },
259*1da177e4SLinus Torvalds 	{ PCI_VENDOR_ID_XILINX, PCI_DEVICE_ID_DIGI96_8_PRO,
260*1da177e4SLinus Torvalds 	  PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, },
261*1da177e4SLinus Torvalds 	{ PCI_VENDOR_ID_XILINX, PCI_DEVICE_ID_DIGI96_8_PAD_OR_PST,
262*1da177e4SLinus Torvalds 	  PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, },
263*1da177e4SLinus Torvalds 	{ 0, }
264*1da177e4SLinus Torvalds };
265*1da177e4SLinus Torvalds 
266*1da177e4SLinus Torvalds MODULE_DEVICE_TABLE(pci, snd_rme96_ids);
267*1da177e4SLinus Torvalds 
268*1da177e4SLinus Torvalds #define RME96_ISPLAYING(rme96) ((rme96)->wcreg & RME96_WCR_START)
269*1da177e4SLinus Torvalds #define RME96_ISRECORDING(rme96) ((rme96)->wcreg & RME96_WCR_START_2)
270*1da177e4SLinus Torvalds #define	RME96_HAS_ANALOG_IN(rme96) ((rme96)->pci->device == PCI_DEVICE_ID_DIGI96_8_PAD_OR_PST)
271*1da177e4SLinus Torvalds #define	RME96_HAS_ANALOG_OUT(rme96) ((rme96)->pci->device == PCI_DEVICE_ID_DIGI96_8_PRO || \
272*1da177e4SLinus Torvalds 				     (rme96)->pci->device == PCI_DEVICE_ID_DIGI96_8_PAD_OR_PST)
273*1da177e4SLinus Torvalds #define	RME96_DAC_IS_1852(rme96) (RME96_HAS_ANALOG_OUT(rme96) && (rme96)->rev >= 4)
274*1da177e4SLinus Torvalds #define	RME96_DAC_IS_1855(rme96) (((rme96)->pci->device == PCI_DEVICE_ID_DIGI96_8_PAD_OR_PST && (rme96)->rev < 4) || \
275*1da177e4SLinus Torvalds 			          ((rme96)->pci->device == PCI_DEVICE_ID_DIGI96_8_PRO && (rme96)->rev == 2))
276*1da177e4SLinus Torvalds #define	RME96_185X_MAX_OUT(rme96) ((1 << (RME96_DAC_IS_1852(rme96) ? RME96_AD1852_VOL_BITS : RME96_AD1855_VOL_BITS)) - 1)
277*1da177e4SLinus Torvalds 
278*1da177e4SLinus Torvalds static int
279*1da177e4SLinus Torvalds snd_rme96_playback_prepare(snd_pcm_substream_t *substream);
280*1da177e4SLinus Torvalds 
281*1da177e4SLinus Torvalds static int
282*1da177e4SLinus Torvalds snd_rme96_capture_prepare(snd_pcm_substream_t *substream);
283*1da177e4SLinus Torvalds 
284*1da177e4SLinus Torvalds static int
285*1da177e4SLinus Torvalds snd_rme96_playback_trigger(snd_pcm_substream_t *substream,
286*1da177e4SLinus Torvalds 			   int cmd);
287*1da177e4SLinus Torvalds 
288*1da177e4SLinus Torvalds static int
289*1da177e4SLinus Torvalds snd_rme96_capture_trigger(snd_pcm_substream_t *substream,
290*1da177e4SLinus Torvalds 			  int cmd);
291*1da177e4SLinus Torvalds 
292*1da177e4SLinus Torvalds static snd_pcm_uframes_t
293*1da177e4SLinus Torvalds snd_rme96_playback_pointer(snd_pcm_substream_t *substream);
294*1da177e4SLinus Torvalds 
295*1da177e4SLinus Torvalds static snd_pcm_uframes_t
296*1da177e4SLinus Torvalds snd_rme96_capture_pointer(snd_pcm_substream_t *substream);
297*1da177e4SLinus Torvalds 
298*1da177e4SLinus Torvalds static void __devinit
299*1da177e4SLinus Torvalds snd_rme96_proc_init(rme96_t *rme96);
300*1da177e4SLinus Torvalds 
301*1da177e4SLinus Torvalds static int
302*1da177e4SLinus Torvalds snd_rme96_create_switches(snd_card_t *card,
303*1da177e4SLinus Torvalds 			  rme96_t *rme96);
304*1da177e4SLinus Torvalds 
305*1da177e4SLinus Torvalds static int
306*1da177e4SLinus Torvalds snd_rme96_getinputtype(rme96_t *rme96);
307*1da177e4SLinus Torvalds 
308*1da177e4SLinus Torvalds static inline unsigned int
309*1da177e4SLinus Torvalds snd_rme96_playback_ptr(rme96_t *rme96)
310*1da177e4SLinus Torvalds {
311*1da177e4SLinus Torvalds 	return (readl(rme96->iobase + RME96_IO_GET_PLAY_POS)
312*1da177e4SLinus Torvalds 		& RME96_RCR_AUDIO_ADDR_MASK) >> rme96->playback_frlog;
313*1da177e4SLinus Torvalds }
314*1da177e4SLinus Torvalds 
315*1da177e4SLinus Torvalds static inline unsigned int
316*1da177e4SLinus Torvalds snd_rme96_capture_ptr(rme96_t *rme96)
317*1da177e4SLinus Torvalds {
318*1da177e4SLinus Torvalds 	return (readl(rme96->iobase + RME96_IO_GET_REC_POS)
319*1da177e4SLinus Torvalds 		& RME96_RCR_AUDIO_ADDR_MASK) >> rme96->capture_frlog;
320*1da177e4SLinus Torvalds }
321*1da177e4SLinus Torvalds 
322*1da177e4SLinus Torvalds static int
323*1da177e4SLinus Torvalds snd_rme96_ratecode(int rate)
324*1da177e4SLinus Torvalds {
325*1da177e4SLinus Torvalds     switch (rate) {
326*1da177e4SLinus Torvalds     case 32000: return SNDRV_PCM_RATE_32000;
327*1da177e4SLinus Torvalds     case 44100: return SNDRV_PCM_RATE_44100;
328*1da177e4SLinus Torvalds     case 48000: return SNDRV_PCM_RATE_48000;
329*1da177e4SLinus Torvalds     case 64000: return SNDRV_PCM_RATE_64000;
330*1da177e4SLinus Torvalds     case 88200: return SNDRV_PCM_RATE_88200;
331*1da177e4SLinus Torvalds     case 96000: return SNDRV_PCM_RATE_96000;
332*1da177e4SLinus Torvalds     }
333*1da177e4SLinus Torvalds     return 0;
334*1da177e4SLinus Torvalds }
335*1da177e4SLinus Torvalds 
336*1da177e4SLinus Torvalds static int
337*1da177e4SLinus Torvalds snd_rme96_playback_silence(snd_pcm_substream_t *substream,
338*1da177e4SLinus Torvalds 			   int channel, /* not used (interleaved data) */
339*1da177e4SLinus Torvalds 			   snd_pcm_uframes_t pos,
340*1da177e4SLinus Torvalds 			   snd_pcm_uframes_t count)
341*1da177e4SLinus Torvalds {
342*1da177e4SLinus Torvalds 	rme96_t *rme96 = snd_pcm_substream_chip(substream);
343*1da177e4SLinus Torvalds 	count <<= rme96->playback_frlog;
344*1da177e4SLinus Torvalds 	pos <<= rme96->playback_frlog;
345*1da177e4SLinus Torvalds 	memset_io(rme96->iobase + RME96_IO_PLAY_BUFFER + pos,
346*1da177e4SLinus Torvalds 		  0, count);
347*1da177e4SLinus Torvalds 	return 0;
348*1da177e4SLinus Torvalds }
349*1da177e4SLinus Torvalds 
350*1da177e4SLinus Torvalds static int
351*1da177e4SLinus Torvalds snd_rme96_playback_copy(snd_pcm_substream_t *substream,
352*1da177e4SLinus Torvalds 			int channel, /* not used (interleaved data) */
353*1da177e4SLinus Torvalds 			snd_pcm_uframes_t pos,
354*1da177e4SLinus Torvalds 			void __user *src,
355*1da177e4SLinus Torvalds 			snd_pcm_uframes_t count)
356*1da177e4SLinus Torvalds {
357*1da177e4SLinus Torvalds 	rme96_t *rme96 = snd_pcm_substream_chip(substream);
358*1da177e4SLinus Torvalds 	count <<= rme96->playback_frlog;
359*1da177e4SLinus Torvalds 	pos <<= rme96->playback_frlog;
360*1da177e4SLinus Torvalds 	copy_from_user_toio(rme96->iobase + RME96_IO_PLAY_BUFFER + pos, src,
361*1da177e4SLinus Torvalds 			    count);
362*1da177e4SLinus Torvalds 	return 0;
363*1da177e4SLinus Torvalds }
364*1da177e4SLinus Torvalds 
365*1da177e4SLinus Torvalds static int
366*1da177e4SLinus Torvalds snd_rme96_capture_copy(snd_pcm_substream_t *substream,
367*1da177e4SLinus Torvalds 		       int channel, /* not used (interleaved data) */
368*1da177e4SLinus Torvalds 		       snd_pcm_uframes_t pos,
369*1da177e4SLinus Torvalds 		       void __user *dst,
370*1da177e4SLinus Torvalds 		       snd_pcm_uframes_t count)
371*1da177e4SLinus Torvalds {
372*1da177e4SLinus Torvalds 	rme96_t *rme96 = snd_pcm_substream_chip(substream);
373*1da177e4SLinus Torvalds 	count <<= rme96->capture_frlog;
374*1da177e4SLinus Torvalds 	pos <<= rme96->capture_frlog;
375*1da177e4SLinus Torvalds 	copy_to_user_fromio(dst, rme96->iobase + RME96_IO_REC_BUFFER + pos,
376*1da177e4SLinus Torvalds 			    count);
377*1da177e4SLinus Torvalds         return 0;
378*1da177e4SLinus Torvalds }
379*1da177e4SLinus Torvalds 
380*1da177e4SLinus Torvalds /*
381*1da177e4SLinus Torvalds  * Digital output capabilites (S/PDIF)
382*1da177e4SLinus Torvalds  */
383*1da177e4SLinus Torvalds static snd_pcm_hardware_t snd_rme96_playback_spdif_info =
384*1da177e4SLinus Torvalds {
385*1da177e4SLinus Torvalds 	.info =		     (SNDRV_PCM_INFO_MMAP_IOMEM |
386*1da177e4SLinus Torvalds 			      SNDRV_PCM_INFO_MMAP_VALID |
387*1da177e4SLinus Torvalds 			      SNDRV_PCM_INFO_INTERLEAVED |
388*1da177e4SLinus Torvalds 			      SNDRV_PCM_INFO_PAUSE),
389*1da177e4SLinus Torvalds 	.formats =	     (SNDRV_PCM_FMTBIT_S16_LE |
390*1da177e4SLinus Torvalds 			      SNDRV_PCM_FMTBIT_S32_LE),
391*1da177e4SLinus Torvalds 	.rates =	     (SNDRV_PCM_RATE_32000 |
392*1da177e4SLinus Torvalds 			      SNDRV_PCM_RATE_44100 |
393*1da177e4SLinus Torvalds 			      SNDRV_PCM_RATE_48000 |
394*1da177e4SLinus Torvalds 			      SNDRV_PCM_RATE_64000 |
395*1da177e4SLinus Torvalds 			      SNDRV_PCM_RATE_88200 |
396*1da177e4SLinus Torvalds 			      SNDRV_PCM_RATE_96000),
397*1da177e4SLinus Torvalds 	.rate_min =	     32000,
398*1da177e4SLinus Torvalds 	.rate_max =	     96000,
399*1da177e4SLinus Torvalds 	.channels_min =	     2,
400*1da177e4SLinus Torvalds 	.channels_max =	     2,
401*1da177e4SLinus Torvalds 	.buffer_bytes_max =  RME96_BUFFER_SIZE,
402*1da177e4SLinus Torvalds 	.period_bytes_min =  RME96_SMALL_BLOCK_SIZE,
403*1da177e4SLinus Torvalds 	.period_bytes_max =  RME96_LARGE_BLOCK_SIZE,
404*1da177e4SLinus Torvalds 	.periods_min =	     RME96_BUFFER_SIZE / RME96_LARGE_BLOCK_SIZE,
405*1da177e4SLinus Torvalds 	.periods_max =	     RME96_BUFFER_SIZE / RME96_SMALL_BLOCK_SIZE,
406*1da177e4SLinus Torvalds 	.fifo_size =	     0,
407*1da177e4SLinus Torvalds };
408*1da177e4SLinus Torvalds 
409*1da177e4SLinus Torvalds /*
410*1da177e4SLinus Torvalds  * Digital input capabilites (S/PDIF)
411*1da177e4SLinus Torvalds  */
412*1da177e4SLinus Torvalds static snd_pcm_hardware_t snd_rme96_capture_spdif_info =
413*1da177e4SLinus Torvalds {
414*1da177e4SLinus Torvalds 	.info =		     (SNDRV_PCM_INFO_MMAP_IOMEM |
415*1da177e4SLinus Torvalds 			      SNDRV_PCM_INFO_MMAP_VALID |
416*1da177e4SLinus Torvalds 			      SNDRV_PCM_INFO_INTERLEAVED |
417*1da177e4SLinus Torvalds 			      SNDRV_PCM_INFO_PAUSE),
418*1da177e4SLinus Torvalds 	.formats =	     (SNDRV_PCM_FMTBIT_S16_LE |
419*1da177e4SLinus Torvalds 			      SNDRV_PCM_FMTBIT_S32_LE),
420*1da177e4SLinus Torvalds 	.rates =	     (SNDRV_PCM_RATE_32000 |
421*1da177e4SLinus Torvalds 			      SNDRV_PCM_RATE_44100 |
422*1da177e4SLinus Torvalds 			      SNDRV_PCM_RATE_48000 |
423*1da177e4SLinus Torvalds 			      SNDRV_PCM_RATE_64000 |
424*1da177e4SLinus Torvalds 			      SNDRV_PCM_RATE_88200 |
425*1da177e4SLinus Torvalds 			      SNDRV_PCM_RATE_96000),
426*1da177e4SLinus Torvalds 	.rate_min =	     32000,
427*1da177e4SLinus Torvalds 	.rate_max =	     96000,
428*1da177e4SLinus Torvalds 	.channels_min =	     2,
429*1da177e4SLinus Torvalds 	.channels_max =	     2,
430*1da177e4SLinus Torvalds 	.buffer_bytes_max =  RME96_BUFFER_SIZE,
431*1da177e4SLinus Torvalds 	.period_bytes_min =  RME96_SMALL_BLOCK_SIZE,
432*1da177e4SLinus Torvalds 	.period_bytes_max =  RME96_LARGE_BLOCK_SIZE,
433*1da177e4SLinus Torvalds 	.periods_min =	     RME96_BUFFER_SIZE / RME96_LARGE_BLOCK_SIZE,
434*1da177e4SLinus Torvalds 	.periods_max =	     RME96_BUFFER_SIZE / RME96_SMALL_BLOCK_SIZE,
435*1da177e4SLinus Torvalds 	.fifo_size =	     0,
436*1da177e4SLinus Torvalds };
437*1da177e4SLinus Torvalds 
438*1da177e4SLinus Torvalds /*
439*1da177e4SLinus Torvalds  * Digital output capabilites (ADAT)
440*1da177e4SLinus Torvalds  */
441*1da177e4SLinus Torvalds static snd_pcm_hardware_t snd_rme96_playback_adat_info =
442*1da177e4SLinus Torvalds {
443*1da177e4SLinus Torvalds 	.info =		     (SNDRV_PCM_INFO_MMAP_IOMEM |
444*1da177e4SLinus Torvalds 			      SNDRV_PCM_INFO_MMAP_VALID |
445*1da177e4SLinus Torvalds 			      SNDRV_PCM_INFO_INTERLEAVED |
446*1da177e4SLinus Torvalds 			      SNDRV_PCM_INFO_PAUSE),
447*1da177e4SLinus Torvalds 	.formats =	     (SNDRV_PCM_FMTBIT_S16_LE |
448*1da177e4SLinus Torvalds 			      SNDRV_PCM_FMTBIT_S32_LE),
449*1da177e4SLinus Torvalds 	.rates =             (SNDRV_PCM_RATE_44100 |
450*1da177e4SLinus Torvalds 			      SNDRV_PCM_RATE_48000),
451*1da177e4SLinus Torvalds 	.rate_min =          44100,
452*1da177e4SLinus Torvalds 	.rate_max =          48000,
453*1da177e4SLinus Torvalds 	.channels_min =      8,
454*1da177e4SLinus Torvalds 	.channels_max =	     8,
455*1da177e4SLinus Torvalds 	.buffer_bytes_max =  RME96_BUFFER_SIZE,
456*1da177e4SLinus Torvalds 	.period_bytes_min =  RME96_SMALL_BLOCK_SIZE,
457*1da177e4SLinus Torvalds 	.period_bytes_max =  RME96_LARGE_BLOCK_SIZE,
458*1da177e4SLinus Torvalds 	.periods_min =	     RME96_BUFFER_SIZE / RME96_LARGE_BLOCK_SIZE,
459*1da177e4SLinus Torvalds 	.periods_max =	     RME96_BUFFER_SIZE / RME96_SMALL_BLOCK_SIZE,
460*1da177e4SLinus Torvalds 	.fifo_size =	     0,
461*1da177e4SLinus Torvalds };
462*1da177e4SLinus Torvalds 
463*1da177e4SLinus Torvalds /*
464*1da177e4SLinus Torvalds  * Digital input capabilites (ADAT)
465*1da177e4SLinus Torvalds  */
466*1da177e4SLinus Torvalds static snd_pcm_hardware_t snd_rme96_capture_adat_info =
467*1da177e4SLinus Torvalds {
468*1da177e4SLinus Torvalds 	.info =		     (SNDRV_PCM_INFO_MMAP_IOMEM |
469*1da177e4SLinus Torvalds 			      SNDRV_PCM_INFO_MMAP_VALID |
470*1da177e4SLinus Torvalds 			      SNDRV_PCM_INFO_INTERLEAVED |
471*1da177e4SLinus Torvalds 			      SNDRV_PCM_INFO_PAUSE),
472*1da177e4SLinus Torvalds 	.formats =	     (SNDRV_PCM_FMTBIT_S16_LE |
473*1da177e4SLinus Torvalds 			      SNDRV_PCM_FMTBIT_S32_LE),
474*1da177e4SLinus Torvalds 	.rates =	     (SNDRV_PCM_RATE_44100 |
475*1da177e4SLinus Torvalds 			      SNDRV_PCM_RATE_48000),
476*1da177e4SLinus Torvalds 	.rate_min =          44100,
477*1da177e4SLinus Torvalds 	.rate_max =          48000,
478*1da177e4SLinus Torvalds 	.channels_min =      8,
479*1da177e4SLinus Torvalds 	.channels_max =	     8,
480*1da177e4SLinus Torvalds 	.buffer_bytes_max =  RME96_BUFFER_SIZE,
481*1da177e4SLinus Torvalds 	.period_bytes_min =  RME96_SMALL_BLOCK_SIZE,
482*1da177e4SLinus Torvalds 	.period_bytes_max =  RME96_LARGE_BLOCK_SIZE,
483*1da177e4SLinus Torvalds 	.periods_min =	     RME96_BUFFER_SIZE / RME96_LARGE_BLOCK_SIZE,
484*1da177e4SLinus Torvalds 	.periods_max =	     RME96_BUFFER_SIZE / RME96_SMALL_BLOCK_SIZE,
485*1da177e4SLinus Torvalds 	.fifo_size =         0,
486*1da177e4SLinus Torvalds };
487*1da177e4SLinus Torvalds 
488*1da177e4SLinus Torvalds /*
489*1da177e4SLinus Torvalds  * The CDATA, CCLK and CLATCH bits can be used to write to the SPI interface
490*1da177e4SLinus Torvalds  * of the AD1852 or AD1852 D/A converter on the board.  CDATA must be set up
491*1da177e4SLinus Torvalds  * on the falling edge of CCLK and be stable on the rising edge.  The rising
492*1da177e4SLinus Torvalds  * edge of CLATCH after the last data bit clocks in the whole data word.
493*1da177e4SLinus Torvalds  * A fast processor could probably drive the SPI interface faster than the
494*1da177e4SLinus Torvalds  * DAC can handle (3MHz for the 1855, unknown for the 1852).  The udelay(1)
495*1da177e4SLinus Torvalds  * limits the data rate to 500KHz and only causes a delay of 33 microsecs.
496*1da177e4SLinus Torvalds  *
497*1da177e4SLinus Torvalds  * NOTE: increased delay from 1 to 10, since there where problems setting
498*1da177e4SLinus Torvalds  * the volume.
499*1da177e4SLinus Torvalds  */
500*1da177e4SLinus Torvalds static void
501*1da177e4SLinus Torvalds snd_rme96_write_SPI(rme96_t *rme96, u16 val)
502*1da177e4SLinus Torvalds {
503*1da177e4SLinus Torvalds 	int i;
504*1da177e4SLinus Torvalds 
505*1da177e4SLinus Torvalds 	for (i = 0; i < 16; i++) {
506*1da177e4SLinus Torvalds 		if (val & 0x8000) {
507*1da177e4SLinus Torvalds 			rme96->areg |= RME96_AR_CDATA;
508*1da177e4SLinus Torvalds 		} else {
509*1da177e4SLinus Torvalds 			rme96->areg &= ~RME96_AR_CDATA;
510*1da177e4SLinus Torvalds 		}
511*1da177e4SLinus Torvalds 		rme96->areg &= ~(RME96_AR_CCLK | RME96_AR_CLATCH);
512*1da177e4SLinus Torvalds 		writel(rme96->areg, rme96->iobase + RME96_IO_ADDITIONAL_REG);
513*1da177e4SLinus Torvalds 		udelay(10);
514*1da177e4SLinus Torvalds 		rme96->areg |= RME96_AR_CCLK;
515*1da177e4SLinus Torvalds 		writel(rme96->areg, rme96->iobase + RME96_IO_ADDITIONAL_REG);
516*1da177e4SLinus Torvalds 		udelay(10);
517*1da177e4SLinus Torvalds 		val <<= 1;
518*1da177e4SLinus Torvalds 	}
519*1da177e4SLinus Torvalds 	rme96->areg &= ~(RME96_AR_CCLK | RME96_AR_CDATA);
520*1da177e4SLinus Torvalds 	rme96->areg |= RME96_AR_CLATCH;
521*1da177e4SLinus Torvalds 	writel(rme96->areg, rme96->iobase + RME96_IO_ADDITIONAL_REG);
522*1da177e4SLinus Torvalds 	udelay(10);
523*1da177e4SLinus Torvalds 	rme96->areg &= ~RME96_AR_CLATCH;
524*1da177e4SLinus Torvalds 	writel(rme96->areg, rme96->iobase + RME96_IO_ADDITIONAL_REG);
525*1da177e4SLinus Torvalds }
526*1da177e4SLinus Torvalds 
527*1da177e4SLinus Torvalds static void
528*1da177e4SLinus Torvalds snd_rme96_apply_dac_volume(rme96_t *rme96)
529*1da177e4SLinus Torvalds {
530*1da177e4SLinus Torvalds 	if (RME96_DAC_IS_1852(rme96)) {
531*1da177e4SLinus Torvalds 		snd_rme96_write_SPI(rme96, (rme96->vol[0] << 2) | 0x0);
532*1da177e4SLinus Torvalds 		snd_rme96_write_SPI(rme96, (rme96->vol[1] << 2) | 0x2);
533*1da177e4SLinus Torvalds 	} else if (RME96_DAC_IS_1855(rme96)) {
534*1da177e4SLinus Torvalds 		snd_rme96_write_SPI(rme96, (rme96->vol[0] & 0x3FF) | 0x000);
535*1da177e4SLinus Torvalds 		snd_rme96_write_SPI(rme96, (rme96->vol[1] & 0x3FF) | 0x400);
536*1da177e4SLinus Torvalds 	}
537*1da177e4SLinus Torvalds }
538*1da177e4SLinus Torvalds 
539*1da177e4SLinus Torvalds static void
540*1da177e4SLinus Torvalds snd_rme96_reset_dac(rme96_t *rme96)
541*1da177e4SLinus Torvalds {
542*1da177e4SLinus Torvalds 	writel(rme96->wcreg | RME96_WCR_PD,
543*1da177e4SLinus Torvalds 	       rme96->iobase + RME96_IO_CONTROL_REGISTER);
544*1da177e4SLinus Torvalds 	writel(rme96->wcreg, rme96->iobase + RME96_IO_CONTROL_REGISTER);
545*1da177e4SLinus Torvalds }
546*1da177e4SLinus Torvalds 
547*1da177e4SLinus Torvalds static int
548*1da177e4SLinus Torvalds snd_rme96_getmontracks(rme96_t *rme96)
549*1da177e4SLinus Torvalds {
550*1da177e4SLinus Torvalds 	return ((rme96->wcreg >> RME96_WCR_BITPOS_MONITOR_0) & 1) +
551*1da177e4SLinus Torvalds 		(((rme96->wcreg >> RME96_WCR_BITPOS_MONITOR_1) & 1) << 1);
552*1da177e4SLinus Torvalds }
553*1da177e4SLinus Torvalds 
554*1da177e4SLinus Torvalds static int
555*1da177e4SLinus Torvalds snd_rme96_setmontracks(rme96_t *rme96,
556*1da177e4SLinus Torvalds 		       int montracks)
557*1da177e4SLinus Torvalds {
558*1da177e4SLinus Torvalds 	if (montracks & 1) {
559*1da177e4SLinus Torvalds 		rme96->wcreg |= RME96_WCR_MONITOR_0;
560*1da177e4SLinus Torvalds 	} else {
561*1da177e4SLinus Torvalds 		rme96->wcreg &= ~RME96_WCR_MONITOR_0;
562*1da177e4SLinus Torvalds 	}
563*1da177e4SLinus Torvalds 	if (montracks & 2) {
564*1da177e4SLinus Torvalds 		rme96->wcreg |= RME96_WCR_MONITOR_1;
565*1da177e4SLinus Torvalds 	} else {
566*1da177e4SLinus Torvalds 		rme96->wcreg &= ~RME96_WCR_MONITOR_1;
567*1da177e4SLinus Torvalds 	}
568*1da177e4SLinus Torvalds 	writel(rme96->wcreg, rme96->iobase + RME96_IO_CONTROL_REGISTER);
569*1da177e4SLinus Torvalds 	return 0;
570*1da177e4SLinus Torvalds }
571*1da177e4SLinus Torvalds 
572*1da177e4SLinus Torvalds static int
573*1da177e4SLinus Torvalds snd_rme96_getattenuation(rme96_t *rme96)
574*1da177e4SLinus Torvalds {
575*1da177e4SLinus Torvalds 	return ((rme96->wcreg >> RME96_WCR_BITPOS_GAIN_0) & 1) +
576*1da177e4SLinus Torvalds 		(((rme96->wcreg >> RME96_WCR_BITPOS_GAIN_1) & 1) << 1);
577*1da177e4SLinus Torvalds }
578*1da177e4SLinus Torvalds 
579*1da177e4SLinus Torvalds static int
580*1da177e4SLinus Torvalds snd_rme96_setattenuation(rme96_t *rme96,
581*1da177e4SLinus Torvalds 			 int attenuation)
582*1da177e4SLinus Torvalds {
583*1da177e4SLinus Torvalds 	switch (attenuation) {
584*1da177e4SLinus Torvalds 	case 0:
585*1da177e4SLinus Torvalds 		rme96->wcreg = (rme96->wcreg & ~RME96_WCR_GAIN_0) &
586*1da177e4SLinus Torvalds 			~RME96_WCR_GAIN_1;
587*1da177e4SLinus Torvalds 		break;
588*1da177e4SLinus Torvalds 	case 1:
589*1da177e4SLinus Torvalds 		rme96->wcreg = (rme96->wcreg | RME96_WCR_GAIN_0) &
590*1da177e4SLinus Torvalds 			~RME96_WCR_GAIN_1;
591*1da177e4SLinus Torvalds 		break;
592*1da177e4SLinus Torvalds 	case 2:
593*1da177e4SLinus Torvalds 		rme96->wcreg = (rme96->wcreg & ~RME96_WCR_GAIN_0) |
594*1da177e4SLinus Torvalds 			RME96_WCR_GAIN_1;
595*1da177e4SLinus Torvalds 		break;
596*1da177e4SLinus Torvalds 	case 3:
597*1da177e4SLinus Torvalds 		rme96->wcreg = (rme96->wcreg | RME96_WCR_GAIN_0) |
598*1da177e4SLinus Torvalds 			RME96_WCR_GAIN_1;
599*1da177e4SLinus Torvalds 		break;
600*1da177e4SLinus Torvalds 	default:
601*1da177e4SLinus Torvalds 		return -EINVAL;
602*1da177e4SLinus Torvalds 	}
603*1da177e4SLinus Torvalds 	writel(rme96->wcreg, rme96->iobase + RME96_IO_CONTROL_REGISTER);
604*1da177e4SLinus Torvalds 	return 0;
605*1da177e4SLinus Torvalds }
606*1da177e4SLinus Torvalds 
607*1da177e4SLinus Torvalds static int
608*1da177e4SLinus Torvalds snd_rme96_capture_getrate(rme96_t *rme96,
609*1da177e4SLinus Torvalds 			  int *is_adat)
610*1da177e4SLinus Torvalds {
611*1da177e4SLinus Torvalds 	int n, rate;
612*1da177e4SLinus Torvalds 
613*1da177e4SLinus Torvalds 	*is_adat = 0;
614*1da177e4SLinus Torvalds 	if (rme96->areg & RME96_AR_ANALOG) {
615*1da177e4SLinus Torvalds 		/* Analog input, overrides S/PDIF setting */
616*1da177e4SLinus Torvalds 		n = ((rme96->areg >> RME96_AR_BITPOS_F0) & 1) +
617*1da177e4SLinus Torvalds 			(((rme96->areg >> RME96_AR_BITPOS_F1) & 1) << 1);
618*1da177e4SLinus Torvalds 		switch (n) {
619*1da177e4SLinus Torvalds 		case 1:
620*1da177e4SLinus Torvalds 			rate = 32000;
621*1da177e4SLinus Torvalds 			break;
622*1da177e4SLinus Torvalds 		case 2:
623*1da177e4SLinus Torvalds 			rate = 44100;
624*1da177e4SLinus Torvalds 			break;
625*1da177e4SLinus Torvalds 		case 3:
626*1da177e4SLinus Torvalds 			rate = 48000;
627*1da177e4SLinus Torvalds 			break;
628*1da177e4SLinus Torvalds 		default:
629*1da177e4SLinus Torvalds 			return -1;
630*1da177e4SLinus Torvalds 		}
631*1da177e4SLinus Torvalds 		return (rme96->areg & RME96_AR_BITPOS_F2) ? rate << 1 : rate;
632*1da177e4SLinus Torvalds 	}
633*1da177e4SLinus Torvalds 
634*1da177e4SLinus Torvalds 	rme96->rcreg = readl(rme96->iobase + RME96_IO_CONTROL_REGISTER);
635*1da177e4SLinus Torvalds 	if (rme96->rcreg & RME96_RCR_LOCK) {
636*1da177e4SLinus Torvalds 		/* ADAT rate */
637*1da177e4SLinus Torvalds 		*is_adat = 1;
638*1da177e4SLinus Torvalds 		if (rme96->rcreg & RME96_RCR_T_OUT) {
639*1da177e4SLinus Torvalds 			return 48000;
640*1da177e4SLinus Torvalds 		}
641*1da177e4SLinus Torvalds 		return 44100;
642*1da177e4SLinus Torvalds 	}
643*1da177e4SLinus Torvalds 
644*1da177e4SLinus Torvalds 	if (rme96->rcreg & RME96_RCR_VERF) {
645*1da177e4SLinus Torvalds 		return -1;
646*1da177e4SLinus Torvalds 	}
647*1da177e4SLinus Torvalds 
648*1da177e4SLinus Torvalds 	/* S/PDIF rate */
649*1da177e4SLinus Torvalds 	n = ((rme96->rcreg >> RME96_RCR_BITPOS_F0) & 1) +
650*1da177e4SLinus Torvalds 		(((rme96->rcreg >> RME96_RCR_BITPOS_F1) & 1) << 1) +
651*1da177e4SLinus Torvalds 		(((rme96->rcreg >> RME96_RCR_BITPOS_F2) & 1) << 2);
652*1da177e4SLinus Torvalds 
653*1da177e4SLinus Torvalds 	switch (n) {
654*1da177e4SLinus Torvalds 	case 0:
655*1da177e4SLinus Torvalds 		if (rme96->rcreg & RME96_RCR_T_OUT) {
656*1da177e4SLinus Torvalds 			return 64000;
657*1da177e4SLinus Torvalds 		}
658*1da177e4SLinus Torvalds 		return -1;
659*1da177e4SLinus Torvalds 	case 3: return 96000;
660*1da177e4SLinus Torvalds 	case 4: return 88200;
661*1da177e4SLinus Torvalds 	case 5: return 48000;
662*1da177e4SLinus Torvalds 	case 6: return 44100;
663*1da177e4SLinus Torvalds 	case 7: return 32000;
664*1da177e4SLinus Torvalds 	default:
665*1da177e4SLinus Torvalds 		break;
666*1da177e4SLinus Torvalds 	}
667*1da177e4SLinus Torvalds 	return -1;
668*1da177e4SLinus Torvalds }
669*1da177e4SLinus Torvalds 
670*1da177e4SLinus Torvalds static int
671*1da177e4SLinus Torvalds snd_rme96_playback_getrate(rme96_t *rme96)
672*1da177e4SLinus Torvalds {
673*1da177e4SLinus Torvalds 	int rate, dummy;
674*1da177e4SLinus Torvalds 
675*1da177e4SLinus Torvalds 	if (!(rme96->wcreg & RME96_WCR_MASTER) &&
676*1da177e4SLinus Torvalds             snd_rme96_getinputtype(rme96) != RME96_INPUT_ANALOG &&
677*1da177e4SLinus Torvalds 	    (rate = snd_rme96_capture_getrate(rme96, &dummy)) > 0)
678*1da177e4SLinus Torvalds 	{
679*1da177e4SLinus Torvalds 	        /* slave clock */
680*1da177e4SLinus Torvalds 	        return rate;
681*1da177e4SLinus Torvalds 	}
682*1da177e4SLinus Torvalds 	rate = ((rme96->wcreg >> RME96_WCR_BITPOS_FREQ_0) & 1) +
683*1da177e4SLinus Torvalds 		(((rme96->wcreg >> RME96_WCR_BITPOS_FREQ_1) & 1) << 1);
684*1da177e4SLinus Torvalds 	switch (rate) {
685*1da177e4SLinus Torvalds 	case 1:
686*1da177e4SLinus Torvalds 		rate = 32000;
687*1da177e4SLinus Torvalds 		break;
688*1da177e4SLinus Torvalds 	case 2:
689*1da177e4SLinus Torvalds 		rate = 44100;
690*1da177e4SLinus Torvalds 		break;
691*1da177e4SLinus Torvalds 	case 3:
692*1da177e4SLinus Torvalds 		rate = 48000;
693*1da177e4SLinus Torvalds 		break;
694*1da177e4SLinus Torvalds 	default:
695*1da177e4SLinus Torvalds 		return -1;
696*1da177e4SLinus Torvalds 	}
697*1da177e4SLinus Torvalds 	return (rme96->wcreg & RME96_WCR_DS) ? rate << 1 : rate;
698*1da177e4SLinus Torvalds }
699*1da177e4SLinus Torvalds 
700*1da177e4SLinus Torvalds static int
701*1da177e4SLinus Torvalds snd_rme96_playback_setrate(rme96_t *rme96,
702*1da177e4SLinus Torvalds 			   int rate)
703*1da177e4SLinus Torvalds {
704*1da177e4SLinus Torvalds 	int ds;
705*1da177e4SLinus Torvalds 
706*1da177e4SLinus Torvalds 	ds = rme96->wcreg & RME96_WCR_DS;
707*1da177e4SLinus Torvalds 	switch (rate) {
708*1da177e4SLinus Torvalds 	case 32000:
709*1da177e4SLinus Torvalds 		rme96->wcreg &= ~RME96_WCR_DS;
710*1da177e4SLinus Torvalds 		rme96->wcreg = (rme96->wcreg | RME96_WCR_FREQ_0) &
711*1da177e4SLinus Torvalds 			~RME96_WCR_FREQ_1;
712*1da177e4SLinus Torvalds 		break;
713*1da177e4SLinus Torvalds 	case 44100:
714*1da177e4SLinus Torvalds 		rme96->wcreg &= ~RME96_WCR_DS;
715*1da177e4SLinus Torvalds 		rme96->wcreg = (rme96->wcreg | RME96_WCR_FREQ_1) &
716*1da177e4SLinus Torvalds 			~RME96_WCR_FREQ_0;
717*1da177e4SLinus Torvalds 		break;
718*1da177e4SLinus Torvalds 	case 48000:
719*1da177e4SLinus Torvalds 		rme96->wcreg &= ~RME96_WCR_DS;
720*1da177e4SLinus Torvalds 		rme96->wcreg = (rme96->wcreg | RME96_WCR_FREQ_0) |
721*1da177e4SLinus Torvalds 			RME96_WCR_FREQ_1;
722*1da177e4SLinus Torvalds 		break;
723*1da177e4SLinus Torvalds 	case 64000:
724*1da177e4SLinus Torvalds 		rme96->wcreg |= RME96_WCR_DS;
725*1da177e4SLinus Torvalds 		rme96->wcreg = (rme96->wcreg | RME96_WCR_FREQ_0) &
726*1da177e4SLinus Torvalds 			~RME96_WCR_FREQ_1;
727*1da177e4SLinus Torvalds 		break;
728*1da177e4SLinus Torvalds 	case 88200:
729*1da177e4SLinus Torvalds 		rme96->wcreg |= RME96_WCR_DS;
730*1da177e4SLinus Torvalds 		rme96->wcreg = (rme96->wcreg | RME96_WCR_FREQ_1) &
731*1da177e4SLinus Torvalds 			~RME96_WCR_FREQ_0;
732*1da177e4SLinus Torvalds 		break;
733*1da177e4SLinus Torvalds 	case 96000:
734*1da177e4SLinus Torvalds 		rme96->wcreg |= RME96_WCR_DS;
735*1da177e4SLinus Torvalds 		rme96->wcreg = (rme96->wcreg | RME96_WCR_FREQ_0) |
736*1da177e4SLinus Torvalds 			RME96_WCR_FREQ_1;
737*1da177e4SLinus Torvalds 		break;
738*1da177e4SLinus Torvalds 	default:
739*1da177e4SLinus Torvalds 		return -EINVAL;
740*1da177e4SLinus Torvalds 	}
741*1da177e4SLinus Torvalds 	if ((!ds && rme96->wcreg & RME96_WCR_DS) ||
742*1da177e4SLinus Torvalds 	    (ds && !(rme96->wcreg & RME96_WCR_DS)))
743*1da177e4SLinus Torvalds 	{
744*1da177e4SLinus Torvalds 		/* change to/from double-speed: reset the DAC (if available) */
745*1da177e4SLinus Torvalds 		snd_rme96_reset_dac(rme96);
746*1da177e4SLinus Torvalds 	} else {
747*1da177e4SLinus Torvalds 		writel(rme96->wcreg, rme96->iobase + RME96_IO_CONTROL_REGISTER);
748*1da177e4SLinus Torvalds 	}
749*1da177e4SLinus Torvalds 	return 0;
750*1da177e4SLinus Torvalds }
751*1da177e4SLinus Torvalds 
752*1da177e4SLinus Torvalds static int
753*1da177e4SLinus Torvalds snd_rme96_capture_analog_setrate(rme96_t *rme96,
754*1da177e4SLinus Torvalds 				 int rate)
755*1da177e4SLinus Torvalds {
756*1da177e4SLinus Torvalds 	switch (rate) {
757*1da177e4SLinus Torvalds 	case 32000:
758*1da177e4SLinus Torvalds 		rme96->areg = ((rme96->areg | RME96_AR_FREQPAD_0) &
759*1da177e4SLinus Torvalds 			       ~RME96_AR_FREQPAD_1) & ~RME96_AR_FREQPAD_2;
760*1da177e4SLinus Torvalds 		break;
761*1da177e4SLinus Torvalds 	case 44100:
762*1da177e4SLinus Torvalds 		rme96->areg = ((rme96->areg & ~RME96_AR_FREQPAD_0) |
763*1da177e4SLinus Torvalds 			       RME96_AR_FREQPAD_1) & ~RME96_AR_FREQPAD_2;
764*1da177e4SLinus Torvalds 		break;
765*1da177e4SLinus Torvalds 	case 48000:
766*1da177e4SLinus Torvalds 		rme96->areg = ((rme96->areg | RME96_AR_FREQPAD_0) |
767*1da177e4SLinus Torvalds 			       RME96_AR_FREQPAD_1) & ~RME96_AR_FREQPAD_2;
768*1da177e4SLinus Torvalds 		break;
769*1da177e4SLinus Torvalds 	case 64000:
770*1da177e4SLinus Torvalds 		if (rme96->rev < 4) {
771*1da177e4SLinus Torvalds 			return -EINVAL;
772*1da177e4SLinus Torvalds 		}
773*1da177e4SLinus Torvalds 		rme96->areg = ((rme96->areg | RME96_AR_FREQPAD_0) &
774*1da177e4SLinus Torvalds 			       ~RME96_AR_FREQPAD_1) | RME96_AR_FREQPAD_2;
775*1da177e4SLinus Torvalds 		break;
776*1da177e4SLinus Torvalds 	case 88200:
777*1da177e4SLinus Torvalds 		if (rme96->rev < 4) {
778*1da177e4SLinus Torvalds 			return -EINVAL;
779*1da177e4SLinus Torvalds 		}
780*1da177e4SLinus Torvalds 		rme96->areg = ((rme96->areg & ~RME96_AR_FREQPAD_0) |
781*1da177e4SLinus Torvalds 			       RME96_AR_FREQPAD_1) | RME96_AR_FREQPAD_2;
782*1da177e4SLinus Torvalds 		break;
783*1da177e4SLinus Torvalds 	case 96000:
784*1da177e4SLinus Torvalds 		rme96->areg = ((rme96->areg | RME96_AR_FREQPAD_0) |
785*1da177e4SLinus Torvalds 			       RME96_AR_FREQPAD_1) | RME96_AR_FREQPAD_2;
786*1da177e4SLinus Torvalds 		break;
787*1da177e4SLinus Torvalds 	default:
788*1da177e4SLinus Torvalds 		return -EINVAL;
789*1da177e4SLinus Torvalds 	}
790*1da177e4SLinus Torvalds 	writel(rme96->areg, rme96->iobase + RME96_IO_ADDITIONAL_REG);
791*1da177e4SLinus Torvalds 	return 0;
792*1da177e4SLinus Torvalds }
793*1da177e4SLinus Torvalds 
794*1da177e4SLinus Torvalds static int
795*1da177e4SLinus Torvalds snd_rme96_setclockmode(rme96_t *rme96,
796*1da177e4SLinus Torvalds 		       int mode)
797*1da177e4SLinus Torvalds {
798*1da177e4SLinus Torvalds 	switch (mode) {
799*1da177e4SLinus Torvalds 	case RME96_CLOCKMODE_SLAVE:
800*1da177e4SLinus Torvalds 	        /* AutoSync */
801*1da177e4SLinus Torvalds 		rme96->wcreg &= ~RME96_WCR_MASTER;
802*1da177e4SLinus Torvalds 		rme96->areg &= ~RME96_AR_WSEL;
803*1da177e4SLinus Torvalds 		break;
804*1da177e4SLinus Torvalds 	case RME96_CLOCKMODE_MASTER:
805*1da177e4SLinus Torvalds 	        /* Internal */
806*1da177e4SLinus Torvalds 		rme96->wcreg |= RME96_WCR_MASTER;
807*1da177e4SLinus Torvalds 		rme96->areg &= ~RME96_AR_WSEL;
808*1da177e4SLinus Torvalds 		break;
809*1da177e4SLinus Torvalds 	case RME96_CLOCKMODE_WORDCLOCK:
810*1da177e4SLinus Torvalds 		/* Word clock is a master mode */
811*1da177e4SLinus Torvalds 		rme96->wcreg |= RME96_WCR_MASTER;
812*1da177e4SLinus Torvalds 		rme96->areg |= RME96_AR_WSEL;
813*1da177e4SLinus Torvalds 		break;
814*1da177e4SLinus Torvalds 	default:
815*1da177e4SLinus Torvalds 		return -EINVAL;
816*1da177e4SLinus Torvalds 	}
817*1da177e4SLinus Torvalds 	writel(rme96->wcreg, rme96->iobase + RME96_IO_CONTROL_REGISTER);
818*1da177e4SLinus Torvalds 	writel(rme96->areg, rme96->iobase + RME96_IO_ADDITIONAL_REG);
819*1da177e4SLinus Torvalds 	return 0;
820*1da177e4SLinus Torvalds }
821*1da177e4SLinus Torvalds 
822*1da177e4SLinus Torvalds static int
823*1da177e4SLinus Torvalds snd_rme96_getclockmode(rme96_t *rme96)
824*1da177e4SLinus Torvalds {
825*1da177e4SLinus Torvalds 	if (rme96->areg & RME96_AR_WSEL) {
826*1da177e4SLinus Torvalds 		return RME96_CLOCKMODE_WORDCLOCK;
827*1da177e4SLinus Torvalds 	}
828*1da177e4SLinus Torvalds 	return (rme96->wcreg & RME96_WCR_MASTER) ? RME96_CLOCKMODE_MASTER :
829*1da177e4SLinus Torvalds 		RME96_CLOCKMODE_SLAVE;
830*1da177e4SLinus Torvalds }
831*1da177e4SLinus Torvalds 
832*1da177e4SLinus Torvalds static int
833*1da177e4SLinus Torvalds snd_rme96_setinputtype(rme96_t *rme96,
834*1da177e4SLinus Torvalds 		       int type)
835*1da177e4SLinus Torvalds {
836*1da177e4SLinus Torvalds 	int n;
837*1da177e4SLinus Torvalds 
838*1da177e4SLinus Torvalds 	switch (type) {
839*1da177e4SLinus Torvalds 	case RME96_INPUT_OPTICAL:
840*1da177e4SLinus Torvalds 		rme96->wcreg = (rme96->wcreg & ~RME96_WCR_INP_0) &
841*1da177e4SLinus Torvalds 			~RME96_WCR_INP_1;
842*1da177e4SLinus Torvalds 		break;
843*1da177e4SLinus Torvalds 	case RME96_INPUT_COAXIAL:
844*1da177e4SLinus Torvalds 		rme96->wcreg = (rme96->wcreg | RME96_WCR_INP_0) &
845*1da177e4SLinus Torvalds 			~RME96_WCR_INP_1;
846*1da177e4SLinus Torvalds 		break;
847*1da177e4SLinus Torvalds 	case RME96_INPUT_INTERNAL:
848*1da177e4SLinus Torvalds 		rme96->wcreg = (rme96->wcreg & ~RME96_WCR_INP_0) |
849*1da177e4SLinus Torvalds 			RME96_WCR_INP_1;
850*1da177e4SLinus Torvalds 		break;
851*1da177e4SLinus Torvalds 	case RME96_INPUT_XLR:
852*1da177e4SLinus Torvalds 		if ((rme96->pci->device != PCI_DEVICE_ID_DIGI96_8_PAD_OR_PST &&
853*1da177e4SLinus Torvalds 		     rme96->pci->device != PCI_DEVICE_ID_DIGI96_8_PRO) ||
854*1da177e4SLinus Torvalds 		    (rme96->pci->device == PCI_DEVICE_ID_DIGI96_8_PAD_OR_PST &&
855*1da177e4SLinus Torvalds 		     rme96->rev > 4))
856*1da177e4SLinus Torvalds 		{
857*1da177e4SLinus Torvalds 			/* Only Digi96/8 PRO and Digi96/8 PAD supports XLR */
858*1da177e4SLinus Torvalds 			return -EINVAL;
859*1da177e4SLinus Torvalds 		}
860*1da177e4SLinus Torvalds 		rme96->wcreg = (rme96->wcreg | RME96_WCR_INP_0) |
861*1da177e4SLinus Torvalds 			RME96_WCR_INP_1;
862*1da177e4SLinus Torvalds 		break;
863*1da177e4SLinus Torvalds 	case RME96_INPUT_ANALOG:
864*1da177e4SLinus Torvalds 		if (!RME96_HAS_ANALOG_IN(rme96)) {
865*1da177e4SLinus Torvalds 			return -EINVAL;
866*1da177e4SLinus Torvalds 		}
867*1da177e4SLinus Torvalds 		rme96->areg |= RME96_AR_ANALOG;
868*1da177e4SLinus Torvalds 		writel(rme96->areg, rme96->iobase + RME96_IO_ADDITIONAL_REG);
869*1da177e4SLinus Torvalds 		if (rme96->rev < 4) {
870*1da177e4SLinus Torvalds 			/*
871*1da177e4SLinus Torvalds 			 * Revision less than 004 does not support 64 and
872*1da177e4SLinus Torvalds 			 * 88.2 kHz
873*1da177e4SLinus Torvalds 			 */
874*1da177e4SLinus Torvalds 			if (snd_rme96_capture_getrate(rme96, &n) == 88200) {
875*1da177e4SLinus Torvalds 				snd_rme96_capture_analog_setrate(rme96, 44100);
876*1da177e4SLinus Torvalds 			}
877*1da177e4SLinus Torvalds 			if (snd_rme96_capture_getrate(rme96, &n) == 64000) {
878*1da177e4SLinus Torvalds 				snd_rme96_capture_analog_setrate(rme96, 32000);
879*1da177e4SLinus Torvalds 			}
880*1da177e4SLinus Torvalds 		}
881*1da177e4SLinus Torvalds 		return 0;
882*1da177e4SLinus Torvalds 	default:
883*1da177e4SLinus Torvalds 		return -EINVAL;
884*1da177e4SLinus Torvalds 	}
885*1da177e4SLinus Torvalds 	if (type != RME96_INPUT_ANALOG && RME96_HAS_ANALOG_IN(rme96)) {
886*1da177e4SLinus Torvalds 		rme96->areg &= ~RME96_AR_ANALOG;
887*1da177e4SLinus Torvalds 		writel(rme96->areg, rme96->iobase + RME96_IO_ADDITIONAL_REG);
888*1da177e4SLinus Torvalds 	}
889*1da177e4SLinus Torvalds 	writel(rme96->wcreg, rme96->iobase + RME96_IO_CONTROL_REGISTER);
890*1da177e4SLinus Torvalds 	return 0;
891*1da177e4SLinus Torvalds }
892*1da177e4SLinus Torvalds 
893*1da177e4SLinus Torvalds static int
894*1da177e4SLinus Torvalds snd_rme96_getinputtype(rme96_t *rme96)
895*1da177e4SLinus Torvalds {
896*1da177e4SLinus Torvalds 	if (rme96->areg & RME96_AR_ANALOG) {
897*1da177e4SLinus Torvalds 		return RME96_INPUT_ANALOG;
898*1da177e4SLinus Torvalds 	}
899*1da177e4SLinus Torvalds 	return ((rme96->wcreg >> RME96_WCR_BITPOS_INP_0) & 1) +
900*1da177e4SLinus Torvalds 		(((rme96->wcreg >> RME96_WCR_BITPOS_INP_1) & 1) << 1);
901*1da177e4SLinus Torvalds }
902*1da177e4SLinus Torvalds 
903*1da177e4SLinus Torvalds static void
904*1da177e4SLinus Torvalds snd_rme96_setframelog(rme96_t *rme96,
905*1da177e4SLinus Torvalds 		      int n_channels,
906*1da177e4SLinus Torvalds 		      int is_playback)
907*1da177e4SLinus Torvalds {
908*1da177e4SLinus Torvalds 	int frlog;
909*1da177e4SLinus Torvalds 
910*1da177e4SLinus Torvalds 	if (n_channels == 2) {
911*1da177e4SLinus Torvalds 		frlog = 1;
912*1da177e4SLinus Torvalds 	} else {
913*1da177e4SLinus Torvalds 		/* assume 8 channels */
914*1da177e4SLinus Torvalds 		frlog = 3;
915*1da177e4SLinus Torvalds 	}
916*1da177e4SLinus Torvalds 	if (is_playback) {
917*1da177e4SLinus Torvalds 		frlog += (rme96->wcreg & RME96_WCR_MODE24) ? 2 : 1;
918*1da177e4SLinus Torvalds 		rme96->playback_frlog = frlog;
919*1da177e4SLinus Torvalds 	} else {
920*1da177e4SLinus Torvalds 		frlog += (rme96->wcreg & RME96_WCR_MODE24_2) ? 2 : 1;
921*1da177e4SLinus Torvalds 		rme96->capture_frlog = frlog;
922*1da177e4SLinus Torvalds 	}
923*1da177e4SLinus Torvalds }
924*1da177e4SLinus Torvalds 
925*1da177e4SLinus Torvalds static int
926*1da177e4SLinus Torvalds snd_rme96_playback_setformat(rme96_t *rme96,
927*1da177e4SLinus Torvalds 			     int format)
928*1da177e4SLinus Torvalds {
929*1da177e4SLinus Torvalds 	switch (format) {
930*1da177e4SLinus Torvalds 	case SNDRV_PCM_FORMAT_S16_LE:
931*1da177e4SLinus Torvalds 		rme96->wcreg &= ~RME96_WCR_MODE24;
932*1da177e4SLinus Torvalds 		break;
933*1da177e4SLinus Torvalds 	case SNDRV_PCM_FORMAT_S32_LE:
934*1da177e4SLinus Torvalds 		rme96->wcreg |= RME96_WCR_MODE24;
935*1da177e4SLinus Torvalds 		break;
936*1da177e4SLinus Torvalds 	default:
937*1da177e4SLinus Torvalds 		return -EINVAL;
938*1da177e4SLinus Torvalds 	}
939*1da177e4SLinus Torvalds 	writel(rme96->wcreg, rme96->iobase + RME96_IO_CONTROL_REGISTER);
940*1da177e4SLinus Torvalds 	return 0;
941*1da177e4SLinus Torvalds }
942*1da177e4SLinus Torvalds 
943*1da177e4SLinus Torvalds static int
944*1da177e4SLinus Torvalds snd_rme96_capture_setformat(rme96_t *rme96,
945*1da177e4SLinus Torvalds 			    int format)
946*1da177e4SLinus Torvalds {
947*1da177e4SLinus Torvalds 	switch (format) {
948*1da177e4SLinus Torvalds 	case SNDRV_PCM_FORMAT_S16_LE:
949*1da177e4SLinus Torvalds 		rme96->wcreg &= ~RME96_WCR_MODE24_2;
950*1da177e4SLinus Torvalds 		break;
951*1da177e4SLinus Torvalds 	case SNDRV_PCM_FORMAT_S32_LE:
952*1da177e4SLinus Torvalds 		rme96->wcreg |= RME96_WCR_MODE24_2;
953*1da177e4SLinus Torvalds 		break;
954*1da177e4SLinus Torvalds 	default:
955*1da177e4SLinus Torvalds 		return -EINVAL;
956*1da177e4SLinus Torvalds 	}
957*1da177e4SLinus Torvalds 	writel(rme96->wcreg, rme96->iobase + RME96_IO_CONTROL_REGISTER);
958*1da177e4SLinus Torvalds 	return 0;
959*1da177e4SLinus Torvalds }
960*1da177e4SLinus Torvalds 
961*1da177e4SLinus Torvalds static void
962*1da177e4SLinus Torvalds snd_rme96_set_period_properties(rme96_t *rme96,
963*1da177e4SLinus Torvalds 				size_t period_bytes)
964*1da177e4SLinus Torvalds {
965*1da177e4SLinus Torvalds 	switch (period_bytes) {
966*1da177e4SLinus Torvalds 	case RME96_LARGE_BLOCK_SIZE:
967*1da177e4SLinus Torvalds 		rme96->wcreg &= ~RME96_WCR_ISEL;
968*1da177e4SLinus Torvalds 		break;
969*1da177e4SLinus Torvalds 	case RME96_SMALL_BLOCK_SIZE:
970*1da177e4SLinus Torvalds 		rme96->wcreg |= RME96_WCR_ISEL;
971*1da177e4SLinus Torvalds 		break;
972*1da177e4SLinus Torvalds 	default:
973*1da177e4SLinus Torvalds 		snd_BUG();
974*1da177e4SLinus Torvalds 		break;
975*1da177e4SLinus Torvalds 	}
976*1da177e4SLinus Torvalds 	rme96->wcreg &= ~RME96_WCR_IDIS;
977*1da177e4SLinus Torvalds 	writel(rme96->wcreg, rme96->iobase + RME96_IO_CONTROL_REGISTER);
978*1da177e4SLinus Torvalds }
979*1da177e4SLinus Torvalds 
980*1da177e4SLinus Torvalds static int
981*1da177e4SLinus Torvalds snd_rme96_playback_hw_params(snd_pcm_substream_t *substream,
982*1da177e4SLinus Torvalds 			     snd_pcm_hw_params_t *params)
983*1da177e4SLinus Torvalds {
984*1da177e4SLinus Torvalds 	rme96_t *rme96 = snd_pcm_substream_chip(substream);
985*1da177e4SLinus Torvalds 	snd_pcm_runtime_t *runtime = substream->runtime;
986*1da177e4SLinus Torvalds 	int err, rate, dummy;
987*1da177e4SLinus Torvalds 
988*1da177e4SLinus Torvalds 	runtime->dma_area = (void *)(rme96->iobase + RME96_IO_PLAY_BUFFER);
989*1da177e4SLinus Torvalds 	runtime->dma_addr = rme96->port + RME96_IO_PLAY_BUFFER;
990*1da177e4SLinus Torvalds 	runtime->dma_bytes = RME96_BUFFER_SIZE;
991*1da177e4SLinus Torvalds 
992*1da177e4SLinus Torvalds 	spin_lock_irq(&rme96->lock);
993*1da177e4SLinus Torvalds 	if (!(rme96->wcreg & RME96_WCR_MASTER) &&
994*1da177e4SLinus Torvalds             snd_rme96_getinputtype(rme96) != RME96_INPUT_ANALOG &&
995*1da177e4SLinus Torvalds 	    (rate = snd_rme96_capture_getrate(rme96, &dummy)) > 0)
996*1da177e4SLinus Torvalds 	{
997*1da177e4SLinus Torvalds                 /* slave clock */
998*1da177e4SLinus Torvalds                 if ((int)params_rate(params) != rate) {
999*1da177e4SLinus Torvalds 			spin_unlock_irq(&rme96->lock);
1000*1da177e4SLinus Torvalds 			return -EIO;
1001*1da177e4SLinus Torvalds                 }
1002*1da177e4SLinus Torvalds 	} else if ((err = snd_rme96_playback_setrate(rme96, params_rate(params))) < 0) {
1003*1da177e4SLinus Torvalds 		spin_unlock_irq(&rme96->lock);
1004*1da177e4SLinus Torvalds 		return err;
1005*1da177e4SLinus Torvalds 	}
1006*1da177e4SLinus Torvalds 	if ((err = snd_rme96_playback_setformat(rme96, params_format(params))) < 0) {
1007*1da177e4SLinus Torvalds 		spin_unlock_irq(&rme96->lock);
1008*1da177e4SLinus Torvalds 		return err;
1009*1da177e4SLinus Torvalds 	}
1010*1da177e4SLinus Torvalds 	snd_rme96_setframelog(rme96, params_channels(params), 1);
1011*1da177e4SLinus Torvalds 	if (rme96->capture_periodsize != 0) {
1012*1da177e4SLinus Torvalds 		if (params_period_size(params) << rme96->playback_frlog !=
1013*1da177e4SLinus Torvalds 		    rme96->capture_periodsize)
1014*1da177e4SLinus Torvalds 		{
1015*1da177e4SLinus Torvalds 			spin_unlock_irq(&rme96->lock);
1016*1da177e4SLinus Torvalds 			return -EBUSY;
1017*1da177e4SLinus Torvalds 		}
1018*1da177e4SLinus Torvalds 	}
1019*1da177e4SLinus Torvalds 	rme96->playback_periodsize =
1020*1da177e4SLinus Torvalds 		params_period_size(params) << rme96->playback_frlog;
1021*1da177e4SLinus Torvalds 	snd_rme96_set_period_properties(rme96, rme96->playback_periodsize);
1022*1da177e4SLinus Torvalds 	/* S/PDIF setup */
1023*1da177e4SLinus Torvalds 	if ((rme96->wcreg & RME96_WCR_ADAT) == 0) {
1024*1da177e4SLinus Torvalds 		rme96->wcreg &= ~(RME96_WCR_PRO | RME96_WCR_DOLBY | RME96_WCR_EMP);
1025*1da177e4SLinus Torvalds 		writel(rme96->wcreg |= rme96->wcreg_spdif_stream, rme96->iobase + RME96_IO_CONTROL_REGISTER);
1026*1da177e4SLinus Torvalds 	}
1027*1da177e4SLinus Torvalds 	spin_unlock_irq(&rme96->lock);
1028*1da177e4SLinus Torvalds 
1029*1da177e4SLinus Torvalds 	return 0;
1030*1da177e4SLinus Torvalds }
1031*1da177e4SLinus Torvalds 
1032*1da177e4SLinus Torvalds static int
1033*1da177e4SLinus Torvalds snd_rme96_capture_hw_params(snd_pcm_substream_t *substream,
1034*1da177e4SLinus Torvalds 			    snd_pcm_hw_params_t *params)
1035*1da177e4SLinus Torvalds {
1036*1da177e4SLinus Torvalds 	rme96_t *rme96 = snd_pcm_substream_chip(substream);
1037*1da177e4SLinus Torvalds 	snd_pcm_runtime_t *runtime = substream->runtime;
1038*1da177e4SLinus Torvalds 	int err, isadat, rate;
1039*1da177e4SLinus Torvalds 
1040*1da177e4SLinus Torvalds 	runtime->dma_area = (void *)(rme96->iobase + RME96_IO_REC_BUFFER);
1041*1da177e4SLinus Torvalds 	runtime->dma_addr = rme96->port + RME96_IO_REC_BUFFER;
1042*1da177e4SLinus Torvalds 	runtime->dma_bytes = RME96_BUFFER_SIZE;
1043*1da177e4SLinus Torvalds 
1044*1da177e4SLinus Torvalds 	spin_lock_irq(&rme96->lock);
1045*1da177e4SLinus Torvalds 	if ((err = snd_rme96_capture_setformat(rme96, params_format(params))) < 0) {
1046*1da177e4SLinus Torvalds 		spin_unlock_irq(&rme96->lock);
1047*1da177e4SLinus Torvalds 		return err;
1048*1da177e4SLinus Torvalds 	}
1049*1da177e4SLinus Torvalds 	if (snd_rme96_getinputtype(rme96) == RME96_INPUT_ANALOG) {
1050*1da177e4SLinus Torvalds 		if ((err = snd_rme96_capture_analog_setrate(rme96,
1051*1da177e4SLinus Torvalds 							    params_rate(params))) < 0)
1052*1da177e4SLinus Torvalds 		{
1053*1da177e4SLinus Torvalds 			spin_unlock_irq(&rme96->lock);
1054*1da177e4SLinus Torvalds 			return err;
1055*1da177e4SLinus Torvalds 		}
1056*1da177e4SLinus Torvalds 	} else if ((rate = snd_rme96_capture_getrate(rme96, &isadat)) > 0) {
1057*1da177e4SLinus Torvalds                 if ((int)params_rate(params) != rate) {
1058*1da177e4SLinus Torvalds 			spin_unlock_irq(&rme96->lock);
1059*1da177e4SLinus Torvalds 			return -EIO;
1060*1da177e4SLinus Torvalds                 }
1061*1da177e4SLinus Torvalds                 if ((isadat && runtime->hw.channels_min == 2) ||
1062*1da177e4SLinus Torvalds                     (!isadat && runtime->hw.channels_min == 8))
1063*1da177e4SLinus Torvalds                 {
1064*1da177e4SLinus Torvalds 			spin_unlock_irq(&rme96->lock);
1065*1da177e4SLinus Torvalds 			return -EIO;
1066*1da177e4SLinus Torvalds                 }
1067*1da177e4SLinus Torvalds         }
1068*1da177e4SLinus Torvalds 	snd_rme96_setframelog(rme96, params_channels(params), 0);
1069*1da177e4SLinus Torvalds 	if (rme96->playback_periodsize != 0) {
1070*1da177e4SLinus Torvalds 		if (params_period_size(params) << rme96->capture_frlog !=
1071*1da177e4SLinus Torvalds 		    rme96->playback_periodsize)
1072*1da177e4SLinus Torvalds 		{
1073*1da177e4SLinus Torvalds 			spin_unlock_irq(&rme96->lock);
1074*1da177e4SLinus Torvalds 			return -EBUSY;
1075*1da177e4SLinus Torvalds 		}
1076*1da177e4SLinus Torvalds 	}
1077*1da177e4SLinus Torvalds 	rme96->capture_periodsize =
1078*1da177e4SLinus Torvalds 		params_period_size(params) << rme96->capture_frlog;
1079*1da177e4SLinus Torvalds 	snd_rme96_set_period_properties(rme96, rme96->capture_periodsize);
1080*1da177e4SLinus Torvalds 	spin_unlock_irq(&rme96->lock);
1081*1da177e4SLinus Torvalds 
1082*1da177e4SLinus Torvalds 	return 0;
1083*1da177e4SLinus Torvalds }
1084*1da177e4SLinus Torvalds 
1085*1da177e4SLinus Torvalds static void
1086*1da177e4SLinus Torvalds snd_rme96_playback_start(rme96_t *rme96,
1087*1da177e4SLinus Torvalds 			 int from_pause)
1088*1da177e4SLinus Torvalds {
1089*1da177e4SLinus Torvalds 	if (!from_pause) {
1090*1da177e4SLinus Torvalds 		writel(0, rme96->iobase + RME96_IO_RESET_PLAY_POS);
1091*1da177e4SLinus Torvalds 	}
1092*1da177e4SLinus Torvalds 
1093*1da177e4SLinus Torvalds 	rme96->wcreg |= RME96_WCR_START;
1094*1da177e4SLinus Torvalds 	writel(rme96->wcreg, rme96->iobase + RME96_IO_CONTROL_REGISTER);
1095*1da177e4SLinus Torvalds }
1096*1da177e4SLinus Torvalds 
1097*1da177e4SLinus Torvalds static void
1098*1da177e4SLinus Torvalds snd_rme96_capture_start(rme96_t *rme96,
1099*1da177e4SLinus Torvalds 			int from_pause)
1100*1da177e4SLinus Torvalds {
1101*1da177e4SLinus Torvalds 	if (!from_pause) {
1102*1da177e4SLinus Torvalds 		writel(0, rme96->iobase + RME96_IO_RESET_REC_POS);
1103*1da177e4SLinus Torvalds 	}
1104*1da177e4SLinus Torvalds 
1105*1da177e4SLinus Torvalds 	rme96->wcreg |= RME96_WCR_START_2;
1106*1da177e4SLinus Torvalds 	writel(rme96->wcreg, rme96->iobase + RME96_IO_CONTROL_REGISTER);
1107*1da177e4SLinus Torvalds }
1108*1da177e4SLinus Torvalds 
1109*1da177e4SLinus Torvalds static void
1110*1da177e4SLinus Torvalds snd_rme96_playback_stop(rme96_t *rme96)
1111*1da177e4SLinus Torvalds {
1112*1da177e4SLinus Torvalds 	/*
1113*1da177e4SLinus Torvalds 	 * Check if there is an unconfirmed IRQ, if so confirm it, or else
1114*1da177e4SLinus Torvalds 	 * the hardware will not stop generating interrupts
1115*1da177e4SLinus Torvalds 	 */
1116*1da177e4SLinus Torvalds 	rme96->rcreg = readl(rme96->iobase + RME96_IO_CONTROL_REGISTER);
1117*1da177e4SLinus Torvalds 	if (rme96->rcreg & RME96_RCR_IRQ) {
1118*1da177e4SLinus Torvalds 		writel(0, rme96->iobase + RME96_IO_CONFIRM_PLAY_IRQ);
1119*1da177e4SLinus Torvalds 	}
1120*1da177e4SLinus Torvalds 	rme96->wcreg &= ~RME96_WCR_START;
1121*1da177e4SLinus Torvalds 	writel(rme96->wcreg, rme96->iobase + RME96_IO_CONTROL_REGISTER);
1122*1da177e4SLinus Torvalds }
1123*1da177e4SLinus Torvalds 
1124*1da177e4SLinus Torvalds static void
1125*1da177e4SLinus Torvalds snd_rme96_capture_stop(rme96_t *rme96)
1126*1da177e4SLinus Torvalds {
1127*1da177e4SLinus Torvalds 	rme96->rcreg = readl(rme96->iobase + RME96_IO_CONTROL_REGISTER);
1128*1da177e4SLinus Torvalds 	if (rme96->rcreg & RME96_RCR_IRQ_2) {
1129*1da177e4SLinus Torvalds 		writel(0, rme96->iobase + RME96_IO_CONFIRM_REC_IRQ);
1130*1da177e4SLinus Torvalds 	}
1131*1da177e4SLinus Torvalds 	rme96->wcreg &= ~RME96_WCR_START_2;
1132*1da177e4SLinus Torvalds 	writel(rme96->wcreg, rme96->iobase + RME96_IO_CONTROL_REGISTER);
1133*1da177e4SLinus Torvalds }
1134*1da177e4SLinus Torvalds 
1135*1da177e4SLinus Torvalds static irqreturn_t
1136*1da177e4SLinus Torvalds snd_rme96_interrupt(int irq,
1137*1da177e4SLinus Torvalds 		    void *dev_id,
1138*1da177e4SLinus Torvalds 		    struct pt_regs *regs)
1139*1da177e4SLinus Torvalds {
1140*1da177e4SLinus Torvalds 	rme96_t *rme96 = (rme96_t *)dev_id;
1141*1da177e4SLinus Torvalds 
1142*1da177e4SLinus Torvalds 	rme96->rcreg = readl(rme96->iobase + RME96_IO_CONTROL_REGISTER);
1143*1da177e4SLinus Torvalds 	/* fastpath out, to ease interrupt sharing */
1144*1da177e4SLinus Torvalds 	if (!((rme96->rcreg & RME96_RCR_IRQ) ||
1145*1da177e4SLinus Torvalds 	      (rme96->rcreg & RME96_RCR_IRQ_2)))
1146*1da177e4SLinus Torvalds 	{
1147*1da177e4SLinus Torvalds 		return IRQ_NONE;
1148*1da177e4SLinus Torvalds 	}
1149*1da177e4SLinus Torvalds 
1150*1da177e4SLinus Torvalds 	if (rme96->rcreg & RME96_RCR_IRQ) {
1151*1da177e4SLinus Torvalds 		/* playback */
1152*1da177e4SLinus Torvalds                 snd_pcm_period_elapsed(rme96->playback_substream);
1153*1da177e4SLinus Torvalds 		writel(0, rme96->iobase + RME96_IO_CONFIRM_PLAY_IRQ);
1154*1da177e4SLinus Torvalds 	}
1155*1da177e4SLinus Torvalds 	if (rme96->rcreg & RME96_RCR_IRQ_2) {
1156*1da177e4SLinus Torvalds 		/* capture */
1157*1da177e4SLinus Torvalds 		snd_pcm_period_elapsed(rme96->capture_substream);
1158*1da177e4SLinus Torvalds 		writel(0, rme96->iobase + RME96_IO_CONFIRM_REC_IRQ);
1159*1da177e4SLinus Torvalds 	}
1160*1da177e4SLinus Torvalds 	return IRQ_HANDLED;
1161*1da177e4SLinus Torvalds }
1162*1da177e4SLinus Torvalds 
1163*1da177e4SLinus Torvalds static unsigned int period_bytes[] = { RME96_SMALL_BLOCK_SIZE, RME96_LARGE_BLOCK_SIZE };
1164*1da177e4SLinus Torvalds 
1165*1da177e4SLinus Torvalds static snd_pcm_hw_constraint_list_t hw_constraints_period_bytes = {
1166*1da177e4SLinus Torvalds 	.count = ARRAY_SIZE(period_bytes),
1167*1da177e4SLinus Torvalds 	.list = period_bytes,
1168*1da177e4SLinus Torvalds 	.mask = 0
1169*1da177e4SLinus Torvalds };
1170*1da177e4SLinus Torvalds 
1171*1da177e4SLinus Torvalds static int
1172*1da177e4SLinus Torvalds snd_rme96_playback_spdif_open(snd_pcm_substream_t *substream)
1173*1da177e4SLinus Torvalds {
1174*1da177e4SLinus Torvalds         int rate, dummy;
1175*1da177e4SLinus Torvalds 	rme96_t *rme96 = snd_pcm_substream_chip(substream);
1176*1da177e4SLinus Torvalds 	snd_pcm_runtime_t *runtime = substream->runtime;
1177*1da177e4SLinus Torvalds 
1178*1da177e4SLinus Torvalds 	snd_pcm_set_sync(substream);
1179*1da177e4SLinus Torvalds 
1180*1da177e4SLinus Torvalds 	spin_lock_irq(&rme96->lock);
1181*1da177e4SLinus Torvalds         if (rme96->playback_substream != NULL) {
1182*1da177e4SLinus Torvalds 		spin_unlock_irq(&rme96->lock);
1183*1da177e4SLinus Torvalds                 return -EBUSY;
1184*1da177e4SLinus Torvalds         }
1185*1da177e4SLinus Torvalds 	rme96->wcreg &= ~RME96_WCR_ADAT;
1186*1da177e4SLinus Torvalds 	writel(rme96->wcreg, rme96->iobase + RME96_IO_CONTROL_REGISTER);
1187*1da177e4SLinus Torvalds 	rme96->playback_substream = substream;
1188*1da177e4SLinus Torvalds 	spin_unlock_irq(&rme96->lock);
1189*1da177e4SLinus Torvalds 
1190*1da177e4SLinus Torvalds 	runtime->hw = snd_rme96_playback_spdif_info;
1191*1da177e4SLinus Torvalds 	if (!(rme96->wcreg & RME96_WCR_MASTER) &&
1192*1da177e4SLinus Torvalds             snd_rme96_getinputtype(rme96) != RME96_INPUT_ANALOG &&
1193*1da177e4SLinus Torvalds 	    (rate = snd_rme96_capture_getrate(rme96, &dummy)) > 0)
1194*1da177e4SLinus Torvalds 	{
1195*1da177e4SLinus Torvalds                 /* slave clock */
1196*1da177e4SLinus Torvalds                 runtime->hw.rates = snd_rme96_ratecode(rate);
1197*1da177e4SLinus Torvalds                 runtime->hw.rate_min = rate;
1198*1da177e4SLinus Torvalds                 runtime->hw.rate_max = rate;
1199*1da177e4SLinus Torvalds 	}
1200*1da177e4SLinus Torvalds 	snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_BUFFER_BYTES, RME96_BUFFER_SIZE, RME96_BUFFER_SIZE);
1201*1da177e4SLinus Torvalds 	snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES, &hw_constraints_period_bytes);
1202*1da177e4SLinus Torvalds 
1203*1da177e4SLinus Torvalds 	rme96->wcreg_spdif_stream = rme96->wcreg_spdif;
1204*1da177e4SLinus Torvalds 	rme96->spdif_ctl->vd[0].access &= ~SNDRV_CTL_ELEM_ACCESS_INACTIVE;
1205*1da177e4SLinus Torvalds 	snd_ctl_notify(rme96->card, SNDRV_CTL_EVENT_MASK_VALUE |
1206*1da177e4SLinus Torvalds 		       SNDRV_CTL_EVENT_MASK_INFO, &rme96->spdif_ctl->id);
1207*1da177e4SLinus Torvalds 	return 0;
1208*1da177e4SLinus Torvalds }
1209*1da177e4SLinus Torvalds 
1210*1da177e4SLinus Torvalds static int
1211*1da177e4SLinus Torvalds snd_rme96_capture_spdif_open(snd_pcm_substream_t *substream)
1212*1da177e4SLinus Torvalds {
1213*1da177e4SLinus Torvalds         int isadat, rate;
1214*1da177e4SLinus Torvalds 	rme96_t *rme96 = snd_pcm_substream_chip(substream);
1215*1da177e4SLinus Torvalds 	snd_pcm_runtime_t *runtime = substream->runtime;
1216*1da177e4SLinus Torvalds 
1217*1da177e4SLinus Torvalds 	snd_pcm_set_sync(substream);
1218*1da177e4SLinus Torvalds 
1219*1da177e4SLinus Torvalds 	runtime->hw = snd_rme96_capture_spdif_info;
1220*1da177e4SLinus Torvalds         if (snd_rme96_getinputtype(rme96) != RME96_INPUT_ANALOG &&
1221*1da177e4SLinus Torvalds             (rate = snd_rme96_capture_getrate(rme96, &isadat)) > 0)
1222*1da177e4SLinus Torvalds         {
1223*1da177e4SLinus Torvalds                 if (isadat) {
1224*1da177e4SLinus Torvalds                         return -EIO;
1225*1da177e4SLinus Torvalds                 }
1226*1da177e4SLinus Torvalds                 runtime->hw.rates = snd_rme96_ratecode(rate);
1227*1da177e4SLinus Torvalds                 runtime->hw.rate_min = rate;
1228*1da177e4SLinus Torvalds                 runtime->hw.rate_max = rate;
1229*1da177e4SLinus Torvalds         }
1230*1da177e4SLinus Torvalds 
1231*1da177e4SLinus Torvalds 	spin_lock_irq(&rme96->lock);
1232*1da177e4SLinus Torvalds         if (rme96->capture_substream != NULL) {
1233*1da177e4SLinus Torvalds 		spin_unlock_irq(&rme96->lock);
1234*1da177e4SLinus Torvalds                 return -EBUSY;
1235*1da177e4SLinus Torvalds         }
1236*1da177e4SLinus Torvalds 	rme96->capture_substream = substream;
1237*1da177e4SLinus Torvalds 	spin_unlock_irq(&rme96->lock);
1238*1da177e4SLinus Torvalds 
1239*1da177e4SLinus Torvalds 	snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_BUFFER_BYTES, RME96_BUFFER_SIZE, RME96_BUFFER_SIZE);
1240*1da177e4SLinus Torvalds 	snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES, &hw_constraints_period_bytes);
1241*1da177e4SLinus Torvalds 
1242*1da177e4SLinus Torvalds 	return 0;
1243*1da177e4SLinus Torvalds }
1244*1da177e4SLinus Torvalds 
1245*1da177e4SLinus Torvalds static int
1246*1da177e4SLinus Torvalds snd_rme96_playback_adat_open(snd_pcm_substream_t *substream)
1247*1da177e4SLinus Torvalds {
1248*1da177e4SLinus Torvalds         int rate, dummy;
1249*1da177e4SLinus Torvalds 	rme96_t *rme96 = snd_pcm_substream_chip(substream);
1250*1da177e4SLinus Torvalds 	snd_pcm_runtime_t *runtime = substream->runtime;
1251*1da177e4SLinus Torvalds 
1252*1da177e4SLinus Torvalds 	snd_pcm_set_sync(substream);
1253*1da177e4SLinus Torvalds 
1254*1da177e4SLinus Torvalds 	spin_lock_irq(&rme96->lock);
1255*1da177e4SLinus Torvalds         if (rme96->playback_substream != NULL) {
1256*1da177e4SLinus Torvalds 		spin_unlock_irq(&rme96->lock);
1257*1da177e4SLinus Torvalds                 return -EBUSY;
1258*1da177e4SLinus Torvalds         }
1259*1da177e4SLinus Torvalds 	rme96->wcreg |= RME96_WCR_ADAT;
1260*1da177e4SLinus Torvalds 	writel(rme96->wcreg, rme96->iobase + RME96_IO_CONTROL_REGISTER);
1261*1da177e4SLinus Torvalds 	rme96->playback_substream = substream;
1262*1da177e4SLinus Torvalds 	spin_unlock_irq(&rme96->lock);
1263*1da177e4SLinus Torvalds 
1264*1da177e4SLinus Torvalds 	runtime->hw = snd_rme96_playback_adat_info;
1265*1da177e4SLinus Torvalds 	if (!(rme96->wcreg & RME96_WCR_MASTER) &&
1266*1da177e4SLinus Torvalds             snd_rme96_getinputtype(rme96) != RME96_INPUT_ANALOG &&
1267*1da177e4SLinus Torvalds 	    (rate = snd_rme96_capture_getrate(rme96, &dummy)) > 0)
1268*1da177e4SLinus Torvalds 	{
1269*1da177e4SLinus Torvalds                 /* slave clock */
1270*1da177e4SLinus Torvalds                 runtime->hw.rates = snd_rme96_ratecode(rate);
1271*1da177e4SLinus Torvalds                 runtime->hw.rate_min = rate;
1272*1da177e4SLinus Torvalds                 runtime->hw.rate_max = rate;
1273*1da177e4SLinus Torvalds 	}
1274*1da177e4SLinus Torvalds 	snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_BUFFER_BYTES, RME96_BUFFER_SIZE, RME96_BUFFER_SIZE);
1275*1da177e4SLinus Torvalds 	snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES, &hw_constraints_period_bytes);
1276*1da177e4SLinus Torvalds 	return 0;
1277*1da177e4SLinus Torvalds }
1278*1da177e4SLinus Torvalds 
1279*1da177e4SLinus Torvalds static int
1280*1da177e4SLinus Torvalds snd_rme96_capture_adat_open(snd_pcm_substream_t *substream)
1281*1da177e4SLinus Torvalds {
1282*1da177e4SLinus Torvalds         int isadat, rate;
1283*1da177e4SLinus Torvalds 	rme96_t *rme96 = snd_pcm_substream_chip(substream);
1284*1da177e4SLinus Torvalds 	snd_pcm_runtime_t *runtime = substream->runtime;
1285*1da177e4SLinus Torvalds 
1286*1da177e4SLinus Torvalds 	snd_pcm_set_sync(substream);
1287*1da177e4SLinus Torvalds 
1288*1da177e4SLinus Torvalds 	runtime->hw = snd_rme96_capture_adat_info;
1289*1da177e4SLinus Torvalds         if (snd_rme96_getinputtype(rme96) == RME96_INPUT_ANALOG) {
1290*1da177e4SLinus Torvalds                 /* makes no sense to use analog input. Note that analog
1291*1da177e4SLinus Torvalds                    expension cards AEB4/8-I are RME96_INPUT_INTERNAL */
1292*1da177e4SLinus Torvalds                 return -EIO;
1293*1da177e4SLinus Torvalds         }
1294*1da177e4SLinus Torvalds         if ((rate = snd_rme96_capture_getrate(rme96, &isadat)) > 0) {
1295*1da177e4SLinus Torvalds                 if (!isadat) {
1296*1da177e4SLinus Torvalds                         return -EIO;
1297*1da177e4SLinus Torvalds                 }
1298*1da177e4SLinus Torvalds                 runtime->hw.rates = snd_rme96_ratecode(rate);
1299*1da177e4SLinus Torvalds                 runtime->hw.rate_min = rate;
1300*1da177e4SLinus Torvalds                 runtime->hw.rate_max = rate;
1301*1da177e4SLinus Torvalds         }
1302*1da177e4SLinus Torvalds 
1303*1da177e4SLinus Torvalds 	spin_lock_irq(&rme96->lock);
1304*1da177e4SLinus Torvalds         if (rme96->capture_substream != NULL) {
1305*1da177e4SLinus Torvalds 		spin_unlock_irq(&rme96->lock);
1306*1da177e4SLinus Torvalds                 return -EBUSY;
1307*1da177e4SLinus Torvalds         }
1308*1da177e4SLinus Torvalds 	rme96->capture_substream = substream;
1309*1da177e4SLinus Torvalds 	spin_unlock_irq(&rme96->lock);
1310*1da177e4SLinus Torvalds 
1311*1da177e4SLinus Torvalds 	snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_BUFFER_BYTES, RME96_BUFFER_SIZE, RME96_BUFFER_SIZE);
1312*1da177e4SLinus Torvalds 	snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES, &hw_constraints_period_bytes);
1313*1da177e4SLinus Torvalds 	return 0;
1314*1da177e4SLinus Torvalds }
1315*1da177e4SLinus Torvalds 
1316*1da177e4SLinus Torvalds static int
1317*1da177e4SLinus Torvalds snd_rme96_playback_close(snd_pcm_substream_t *substream)
1318*1da177e4SLinus Torvalds {
1319*1da177e4SLinus Torvalds 	rme96_t *rme96 = snd_pcm_substream_chip(substream);
1320*1da177e4SLinus Torvalds 	int spdif = 0;
1321*1da177e4SLinus Torvalds 
1322*1da177e4SLinus Torvalds 	spin_lock_irq(&rme96->lock);
1323*1da177e4SLinus Torvalds 	if (RME96_ISPLAYING(rme96)) {
1324*1da177e4SLinus Torvalds 		snd_rme96_playback_stop(rme96);
1325*1da177e4SLinus Torvalds 	}
1326*1da177e4SLinus Torvalds 	rme96->playback_substream = NULL;
1327*1da177e4SLinus Torvalds 	rme96->playback_periodsize = 0;
1328*1da177e4SLinus Torvalds 	spdif = (rme96->wcreg & RME96_WCR_ADAT) == 0;
1329*1da177e4SLinus Torvalds 	spin_unlock_irq(&rme96->lock);
1330*1da177e4SLinus Torvalds 	if (spdif) {
1331*1da177e4SLinus Torvalds 		rme96->spdif_ctl->vd[0].access |= SNDRV_CTL_ELEM_ACCESS_INACTIVE;
1332*1da177e4SLinus Torvalds 		snd_ctl_notify(rme96->card, SNDRV_CTL_EVENT_MASK_VALUE |
1333*1da177e4SLinus Torvalds 			       SNDRV_CTL_EVENT_MASK_INFO, &rme96->spdif_ctl->id);
1334*1da177e4SLinus Torvalds 	}
1335*1da177e4SLinus Torvalds 	return 0;
1336*1da177e4SLinus Torvalds }
1337*1da177e4SLinus Torvalds 
1338*1da177e4SLinus Torvalds static int
1339*1da177e4SLinus Torvalds snd_rme96_capture_close(snd_pcm_substream_t *substream)
1340*1da177e4SLinus Torvalds {
1341*1da177e4SLinus Torvalds 	rme96_t *rme96 = snd_pcm_substream_chip(substream);
1342*1da177e4SLinus Torvalds 
1343*1da177e4SLinus Torvalds 	spin_lock_irq(&rme96->lock);
1344*1da177e4SLinus Torvalds 	if (RME96_ISRECORDING(rme96)) {
1345*1da177e4SLinus Torvalds 		snd_rme96_capture_stop(rme96);
1346*1da177e4SLinus Torvalds 	}
1347*1da177e4SLinus Torvalds 	rme96->capture_substream = NULL;
1348*1da177e4SLinus Torvalds 	rme96->capture_periodsize = 0;
1349*1da177e4SLinus Torvalds 	spin_unlock_irq(&rme96->lock);
1350*1da177e4SLinus Torvalds 	return 0;
1351*1da177e4SLinus Torvalds }
1352*1da177e4SLinus Torvalds 
1353*1da177e4SLinus Torvalds static int
1354*1da177e4SLinus Torvalds snd_rme96_playback_prepare(snd_pcm_substream_t *substream)
1355*1da177e4SLinus Torvalds {
1356*1da177e4SLinus Torvalds 	rme96_t *rme96 = snd_pcm_substream_chip(substream);
1357*1da177e4SLinus Torvalds 
1358*1da177e4SLinus Torvalds 	spin_lock_irq(&rme96->lock);
1359*1da177e4SLinus Torvalds 	if (RME96_ISPLAYING(rme96)) {
1360*1da177e4SLinus Torvalds 		snd_rme96_playback_stop(rme96);
1361*1da177e4SLinus Torvalds 	}
1362*1da177e4SLinus Torvalds 	writel(0, rme96->iobase + RME96_IO_RESET_PLAY_POS);
1363*1da177e4SLinus Torvalds 	spin_unlock_irq(&rme96->lock);
1364*1da177e4SLinus Torvalds 	return 0;
1365*1da177e4SLinus Torvalds }
1366*1da177e4SLinus Torvalds 
1367*1da177e4SLinus Torvalds static int
1368*1da177e4SLinus Torvalds snd_rme96_capture_prepare(snd_pcm_substream_t *substream)
1369*1da177e4SLinus Torvalds {
1370*1da177e4SLinus Torvalds 	rme96_t *rme96 = snd_pcm_substream_chip(substream);
1371*1da177e4SLinus Torvalds 
1372*1da177e4SLinus Torvalds 	spin_lock_irq(&rme96->lock);
1373*1da177e4SLinus Torvalds 	if (RME96_ISRECORDING(rme96)) {
1374*1da177e4SLinus Torvalds 		snd_rme96_capture_stop(rme96);
1375*1da177e4SLinus Torvalds 	}
1376*1da177e4SLinus Torvalds 	writel(0, rme96->iobase + RME96_IO_RESET_REC_POS);
1377*1da177e4SLinus Torvalds 	spin_unlock_irq(&rme96->lock);
1378*1da177e4SLinus Torvalds 	return 0;
1379*1da177e4SLinus Torvalds }
1380*1da177e4SLinus Torvalds 
1381*1da177e4SLinus Torvalds static int
1382*1da177e4SLinus Torvalds snd_rme96_playback_trigger(snd_pcm_substream_t *substream,
1383*1da177e4SLinus Torvalds 			   int cmd)
1384*1da177e4SLinus Torvalds {
1385*1da177e4SLinus Torvalds 	rme96_t *rme96 = snd_pcm_substream_chip(substream);
1386*1da177e4SLinus Torvalds 
1387*1da177e4SLinus Torvalds 	switch (cmd) {
1388*1da177e4SLinus Torvalds 	case SNDRV_PCM_TRIGGER_START:
1389*1da177e4SLinus Torvalds 		if (!RME96_ISPLAYING(rme96)) {
1390*1da177e4SLinus Torvalds 			if (substream != rme96->playback_substream) {
1391*1da177e4SLinus Torvalds 				return -EBUSY;
1392*1da177e4SLinus Torvalds 			}
1393*1da177e4SLinus Torvalds 			snd_rme96_playback_start(rme96, 0);
1394*1da177e4SLinus Torvalds 		}
1395*1da177e4SLinus Torvalds 		break;
1396*1da177e4SLinus Torvalds 
1397*1da177e4SLinus Torvalds 	case SNDRV_PCM_TRIGGER_STOP:
1398*1da177e4SLinus Torvalds 		if (RME96_ISPLAYING(rme96)) {
1399*1da177e4SLinus Torvalds 			if (substream != rme96->playback_substream) {
1400*1da177e4SLinus Torvalds 				return -EBUSY;
1401*1da177e4SLinus Torvalds 			}
1402*1da177e4SLinus Torvalds 			snd_rme96_playback_stop(rme96);
1403*1da177e4SLinus Torvalds 		}
1404*1da177e4SLinus Torvalds 		break;
1405*1da177e4SLinus Torvalds 
1406*1da177e4SLinus Torvalds 	case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
1407*1da177e4SLinus Torvalds 		if (RME96_ISPLAYING(rme96)) {
1408*1da177e4SLinus Torvalds 			snd_rme96_playback_stop(rme96);
1409*1da177e4SLinus Torvalds 		}
1410*1da177e4SLinus Torvalds 		break;
1411*1da177e4SLinus Torvalds 
1412*1da177e4SLinus Torvalds 	case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
1413*1da177e4SLinus Torvalds 		if (!RME96_ISPLAYING(rme96)) {
1414*1da177e4SLinus Torvalds 			snd_rme96_playback_start(rme96, 1);
1415*1da177e4SLinus Torvalds 		}
1416*1da177e4SLinus Torvalds 		break;
1417*1da177e4SLinus Torvalds 
1418*1da177e4SLinus Torvalds 	default:
1419*1da177e4SLinus Torvalds 		return -EINVAL;
1420*1da177e4SLinus Torvalds 	}
1421*1da177e4SLinus Torvalds 	return 0;
1422*1da177e4SLinus Torvalds }
1423*1da177e4SLinus Torvalds 
1424*1da177e4SLinus Torvalds static int
1425*1da177e4SLinus Torvalds snd_rme96_capture_trigger(snd_pcm_substream_t *substream,
1426*1da177e4SLinus Torvalds 			  int cmd)
1427*1da177e4SLinus Torvalds {
1428*1da177e4SLinus Torvalds 	rme96_t *rme96 = snd_pcm_substream_chip(substream);
1429*1da177e4SLinus Torvalds 
1430*1da177e4SLinus Torvalds 	switch (cmd) {
1431*1da177e4SLinus Torvalds 	case SNDRV_PCM_TRIGGER_START:
1432*1da177e4SLinus Torvalds 		if (!RME96_ISRECORDING(rme96)) {
1433*1da177e4SLinus Torvalds 			if (substream != rme96->capture_substream) {
1434*1da177e4SLinus Torvalds 				return -EBUSY;
1435*1da177e4SLinus Torvalds 			}
1436*1da177e4SLinus Torvalds 			snd_rme96_capture_start(rme96, 0);
1437*1da177e4SLinus Torvalds 		}
1438*1da177e4SLinus Torvalds 		break;
1439*1da177e4SLinus Torvalds 
1440*1da177e4SLinus Torvalds 	case SNDRV_PCM_TRIGGER_STOP:
1441*1da177e4SLinus Torvalds 		if (RME96_ISRECORDING(rme96)) {
1442*1da177e4SLinus Torvalds 			if (substream != rme96->capture_substream) {
1443*1da177e4SLinus Torvalds 				return -EBUSY;
1444*1da177e4SLinus Torvalds 			}
1445*1da177e4SLinus Torvalds 			snd_rme96_capture_stop(rme96);
1446*1da177e4SLinus Torvalds 		}
1447*1da177e4SLinus Torvalds 		break;
1448*1da177e4SLinus Torvalds 
1449*1da177e4SLinus Torvalds 	case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
1450*1da177e4SLinus Torvalds 		if (RME96_ISRECORDING(rme96)) {
1451*1da177e4SLinus Torvalds 			snd_rme96_capture_stop(rme96);
1452*1da177e4SLinus Torvalds 		}
1453*1da177e4SLinus Torvalds 		break;
1454*1da177e4SLinus Torvalds 
1455*1da177e4SLinus Torvalds 	case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
1456*1da177e4SLinus Torvalds 		if (!RME96_ISRECORDING(rme96)) {
1457*1da177e4SLinus Torvalds 			snd_rme96_capture_start(rme96, 1);
1458*1da177e4SLinus Torvalds 		}
1459*1da177e4SLinus Torvalds 		break;
1460*1da177e4SLinus Torvalds 
1461*1da177e4SLinus Torvalds 	default:
1462*1da177e4SLinus Torvalds 		return -EINVAL;
1463*1da177e4SLinus Torvalds 	}
1464*1da177e4SLinus Torvalds 
1465*1da177e4SLinus Torvalds 	return 0;
1466*1da177e4SLinus Torvalds }
1467*1da177e4SLinus Torvalds 
1468*1da177e4SLinus Torvalds static snd_pcm_uframes_t
1469*1da177e4SLinus Torvalds snd_rme96_playback_pointer(snd_pcm_substream_t *substream)
1470*1da177e4SLinus Torvalds {
1471*1da177e4SLinus Torvalds 	rme96_t *rme96 = snd_pcm_substream_chip(substream);
1472*1da177e4SLinus Torvalds 	return snd_rme96_playback_ptr(rme96);
1473*1da177e4SLinus Torvalds }
1474*1da177e4SLinus Torvalds 
1475*1da177e4SLinus Torvalds static snd_pcm_uframes_t
1476*1da177e4SLinus Torvalds snd_rme96_capture_pointer(snd_pcm_substream_t *substream)
1477*1da177e4SLinus Torvalds {
1478*1da177e4SLinus Torvalds 	rme96_t *rme96 = snd_pcm_substream_chip(substream);
1479*1da177e4SLinus Torvalds 	return snd_rme96_capture_ptr(rme96);
1480*1da177e4SLinus Torvalds }
1481*1da177e4SLinus Torvalds 
1482*1da177e4SLinus Torvalds static snd_pcm_ops_t snd_rme96_playback_spdif_ops = {
1483*1da177e4SLinus Torvalds 	.open =		snd_rme96_playback_spdif_open,
1484*1da177e4SLinus Torvalds 	.close =	snd_rme96_playback_close,
1485*1da177e4SLinus Torvalds 	.ioctl =	snd_pcm_lib_ioctl,
1486*1da177e4SLinus Torvalds 	.hw_params =	snd_rme96_playback_hw_params,
1487*1da177e4SLinus Torvalds 	.prepare =	snd_rme96_playback_prepare,
1488*1da177e4SLinus Torvalds 	.trigger =	snd_rme96_playback_trigger,
1489*1da177e4SLinus Torvalds 	.pointer =	snd_rme96_playback_pointer,
1490*1da177e4SLinus Torvalds 	.copy =		snd_rme96_playback_copy,
1491*1da177e4SLinus Torvalds 	.silence =	snd_rme96_playback_silence,
1492*1da177e4SLinus Torvalds 	.mmap =		snd_pcm_lib_mmap_iomem,
1493*1da177e4SLinus Torvalds };
1494*1da177e4SLinus Torvalds 
1495*1da177e4SLinus Torvalds static snd_pcm_ops_t snd_rme96_capture_spdif_ops = {
1496*1da177e4SLinus Torvalds 	.open =		snd_rme96_capture_spdif_open,
1497*1da177e4SLinus Torvalds 	.close =	snd_rme96_capture_close,
1498*1da177e4SLinus Torvalds 	.ioctl =	snd_pcm_lib_ioctl,
1499*1da177e4SLinus Torvalds 	.hw_params =	snd_rme96_capture_hw_params,
1500*1da177e4SLinus Torvalds 	.prepare =	snd_rme96_capture_prepare,
1501*1da177e4SLinus Torvalds 	.trigger =	snd_rme96_capture_trigger,
1502*1da177e4SLinus Torvalds 	.pointer =	snd_rme96_capture_pointer,
1503*1da177e4SLinus Torvalds 	.copy =		snd_rme96_capture_copy,
1504*1da177e4SLinus Torvalds 	.mmap =		snd_pcm_lib_mmap_iomem,
1505*1da177e4SLinus Torvalds };
1506*1da177e4SLinus Torvalds 
1507*1da177e4SLinus Torvalds static snd_pcm_ops_t snd_rme96_playback_adat_ops = {
1508*1da177e4SLinus Torvalds 	.open =		snd_rme96_playback_adat_open,
1509*1da177e4SLinus Torvalds 	.close =	snd_rme96_playback_close,
1510*1da177e4SLinus Torvalds 	.ioctl =	snd_pcm_lib_ioctl,
1511*1da177e4SLinus Torvalds 	.hw_params =	snd_rme96_playback_hw_params,
1512*1da177e4SLinus Torvalds 	.prepare =	snd_rme96_playback_prepare,
1513*1da177e4SLinus Torvalds 	.trigger =	snd_rme96_playback_trigger,
1514*1da177e4SLinus Torvalds 	.pointer =	snd_rme96_playback_pointer,
1515*1da177e4SLinus Torvalds 	.copy =		snd_rme96_playback_copy,
1516*1da177e4SLinus Torvalds 	.silence =	snd_rme96_playback_silence,
1517*1da177e4SLinus Torvalds 	.mmap =		snd_pcm_lib_mmap_iomem,
1518*1da177e4SLinus Torvalds };
1519*1da177e4SLinus Torvalds 
1520*1da177e4SLinus Torvalds static snd_pcm_ops_t snd_rme96_capture_adat_ops = {
1521*1da177e4SLinus Torvalds 	.open =		snd_rme96_capture_adat_open,
1522*1da177e4SLinus Torvalds 	.close =	snd_rme96_capture_close,
1523*1da177e4SLinus Torvalds 	.ioctl =	snd_pcm_lib_ioctl,
1524*1da177e4SLinus Torvalds 	.hw_params =	snd_rme96_capture_hw_params,
1525*1da177e4SLinus Torvalds 	.prepare =	snd_rme96_capture_prepare,
1526*1da177e4SLinus Torvalds 	.trigger =	snd_rme96_capture_trigger,
1527*1da177e4SLinus Torvalds 	.pointer =	snd_rme96_capture_pointer,
1528*1da177e4SLinus Torvalds 	.copy =		snd_rme96_capture_copy,
1529*1da177e4SLinus Torvalds 	.mmap =		snd_pcm_lib_mmap_iomem,
1530*1da177e4SLinus Torvalds };
1531*1da177e4SLinus Torvalds 
1532*1da177e4SLinus Torvalds static void
1533*1da177e4SLinus Torvalds snd_rme96_free(void *private_data)
1534*1da177e4SLinus Torvalds {
1535*1da177e4SLinus Torvalds 	rme96_t *rme96 = (rme96_t *)private_data;
1536*1da177e4SLinus Torvalds 
1537*1da177e4SLinus Torvalds 	if (rme96 == NULL) {
1538*1da177e4SLinus Torvalds 	        return;
1539*1da177e4SLinus Torvalds 	}
1540*1da177e4SLinus Torvalds 	if (rme96->irq >= 0) {
1541*1da177e4SLinus Torvalds 		snd_rme96_playback_stop(rme96);
1542*1da177e4SLinus Torvalds 		snd_rme96_capture_stop(rme96);
1543*1da177e4SLinus Torvalds 		rme96->areg &= ~RME96_AR_DAC_EN;
1544*1da177e4SLinus Torvalds 		writel(rme96->areg, rme96->iobase + RME96_IO_ADDITIONAL_REG);
1545*1da177e4SLinus Torvalds 		free_irq(rme96->irq, (void *)rme96);
1546*1da177e4SLinus Torvalds 		rme96->irq = -1;
1547*1da177e4SLinus Torvalds 	}
1548*1da177e4SLinus Torvalds 	if (rme96->iobase) {
1549*1da177e4SLinus Torvalds 		iounmap(rme96->iobase);
1550*1da177e4SLinus Torvalds 		rme96->iobase = NULL;
1551*1da177e4SLinus Torvalds 	}
1552*1da177e4SLinus Torvalds 	if (rme96->port) {
1553*1da177e4SLinus Torvalds 		pci_release_regions(rme96->pci);
1554*1da177e4SLinus Torvalds 		rme96->port = 0;
1555*1da177e4SLinus Torvalds 	}
1556*1da177e4SLinus Torvalds 	pci_disable_device(rme96->pci);
1557*1da177e4SLinus Torvalds }
1558*1da177e4SLinus Torvalds 
1559*1da177e4SLinus Torvalds static void
1560*1da177e4SLinus Torvalds snd_rme96_free_spdif_pcm(snd_pcm_t *pcm)
1561*1da177e4SLinus Torvalds {
1562*1da177e4SLinus Torvalds 	rme96_t *rme96 = (rme96_t *) pcm->private_data;
1563*1da177e4SLinus Torvalds 	rme96->spdif_pcm = NULL;
1564*1da177e4SLinus Torvalds }
1565*1da177e4SLinus Torvalds 
1566*1da177e4SLinus Torvalds static void
1567*1da177e4SLinus Torvalds snd_rme96_free_adat_pcm(snd_pcm_t *pcm)
1568*1da177e4SLinus Torvalds {
1569*1da177e4SLinus Torvalds 	rme96_t *rme96 = (rme96_t *) pcm->private_data;
1570*1da177e4SLinus Torvalds 	rme96->adat_pcm = NULL;
1571*1da177e4SLinus Torvalds }
1572*1da177e4SLinus Torvalds 
1573*1da177e4SLinus Torvalds static int __devinit
1574*1da177e4SLinus Torvalds snd_rme96_create(rme96_t *rme96)
1575*1da177e4SLinus Torvalds {
1576*1da177e4SLinus Torvalds 	struct pci_dev *pci = rme96->pci;
1577*1da177e4SLinus Torvalds 	int err;
1578*1da177e4SLinus Torvalds 
1579*1da177e4SLinus Torvalds 	rme96->irq = -1;
1580*1da177e4SLinus Torvalds 	spin_lock_init(&rme96->lock);
1581*1da177e4SLinus Torvalds 
1582*1da177e4SLinus Torvalds 	if ((err = pci_enable_device(pci)) < 0)
1583*1da177e4SLinus Torvalds 		return err;
1584*1da177e4SLinus Torvalds 
1585*1da177e4SLinus Torvalds 	if ((err = pci_request_regions(pci, "RME96")) < 0)
1586*1da177e4SLinus Torvalds 		return err;
1587*1da177e4SLinus Torvalds 	rme96->port = pci_resource_start(rme96->pci, 0);
1588*1da177e4SLinus Torvalds 
1589*1da177e4SLinus Torvalds 	if (request_irq(pci->irq, snd_rme96_interrupt, SA_INTERRUPT|SA_SHIRQ, "RME96", (void *)rme96)) {
1590*1da177e4SLinus Torvalds 		snd_printk("unable to grab IRQ %d\n", pci->irq);
1591*1da177e4SLinus Torvalds 		return -EBUSY;
1592*1da177e4SLinus Torvalds 	}
1593*1da177e4SLinus Torvalds 	rme96->irq = pci->irq;
1594*1da177e4SLinus Torvalds 
1595*1da177e4SLinus Torvalds 	if ((rme96->iobase = ioremap_nocache(rme96->port, RME96_IO_SIZE)) == 0) {
1596*1da177e4SLinus Torvalds 		snd_printk("unable to remap memory region 0x%lx-0x%lx\n", rme96->port, rme96->port + RME96_IO_SIZE - 1);
1597*1da177e4SLinus Torvalds 		return -ENOMEM;
1598*1da177e4SLinus Torvalds 	}
1599*1da177e4SLinus Torvalds 
1600*1da177e4SLinus Torvalds 	/* read the card's revision number */
1601*1da177e4SLinus Torvalds 	pci_read_config_byte(pci, 8, &rme96->rev);
1602*1da177e4SLinus Torvalds 
1603*1da177e4SLinus Torvalds 	/* set up ALSA pcm device for S/PDIF */
1604*1da177e4SLinus Torvalds 	if ((err = snd_pcm_new(rme96->card, "Digi96 IEC958", 0,
1605*1da177e4SLinus Torvalds 			       1, 1, &rme96->spdif_pcm)) < 0)
1606*1da177e4SLinus Torvalds 	{
1607*1da177e4SLinus Torvalds 		return err;
1608*1da177e4SLinus Torvalds 	}
1609*1da177e4SLinus Torvalds 	rme96->spdif_pcm->private_data = rme96;
1610*1da177e4SLinus Torvalds 	rme96->spdif_pcm->private_free = snd_rme96_free_spdif_pcm;
1611*1da177e4SLinus Torvalds 	strcpy(rme96->spdif_pcm->name, "Digi96 IEC958");
1612*1da177e4SLinus Torvalds 	snd_pcm_set_ops(rme96->spdif_pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_rme96_playback_spdif_ops);
1613*1da177e4SLinus Torvalds 	snd_pcm_set_ops(rme96->spdif_pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_rme96_capture_spdif_ops);
1614*1da177e4SLinus Torvalds 
1615*1da177e4SLinus Torvalds 	rme96->spdif_pcm->info_flags = 0;
1616*1da177e4SLinus Torvalds 
1617*1da177e4SLinus Torvalds 	/* set up ALSA pcm device for ADAT */
1618*1da177e4SLinus Torvalds 	if (pci->device == PCI_DEVICE_ID_DIGI96) {
1619*1da177e4SLinus Torvalds 		/* ADAT is not available on the base model */
1620*1da177e4SLinus Torvalds 		rme96->adat_pcm = NULL;
1621*1da177e4SLinus Torvalds 	} else {
1622*1da177e4SLinus Torvalds 		if ((err = snd_pcm_new(rme96->card, "Digi96 ADAT", 1,
1623*1da177e4SLinus Torvalds 				       1, 1, &rme96->adat_pcm)) < 0)
1624*1da177e4SLinus Torvalds 		{
1625*1da177e4SLinus Torvalds 			return err;
1626*1da177e4SLinus Torvalds 		}
1627*1da177e4SLinus Torvalds 		rme96->adat_pcm->private_data = rme96;
1628*1da177e4SLinus Torvalds 		rme96->adat_pcm->private_free = snd_rme96_free_adat_pcm;
1629*1da177e4SLinus Torvalds 		strcpy(rme96->adat_pcm->name, "Digi96 ADAT");
1630*1da177e4SLinus Torvalds 		snd_pcm_set_ops(rme96->adat_pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_rme96_playback_adat_ops);
1631*1da177e4SLinus Torvalds 		snd_pcm_set_ops(rme96->adat_pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_rme96_capture_adat_ops);
1632*1da177e4SLinus Torvalds 
1633*1da177e4SLinus Torvalds 		rme96->adat_pcm->info_flags = 0;
1634*1da177e4SLinus Torvalds 	}
1635*1da177e4SLinus Torvalds 
1636*1da177e4SLinus Torvalds 	rme96->playback_periodsize = 0;
1637*1da177e4SLinus Torvalds 	rme96->capture_periodsize = 0;
1638*1da177e4SLinus Torvalds 
1639*1da177e4SLinus Torvalds 	/* make sure playback/capture is stopped, if by some reason active */
1640*1da177e4SLinus Torvalds 	snd_rme96_playback_stop(rme96);
1641*1da177e4SLinus Torvalds 	snd_rme96_capture_stop(rme96);
1642*1da177e4SLinus Torvalds 
1643*1da177e4SLinus Torvalds 	/* set default values in registers */
1644*1da177e4SLinus Torvalds 	rme96->wcreg =
1645*1da177e4SLinus Torvalds 		RME96_WCR_FREQ_1 | /* set 44.1 kHz playback */
1646*1da177e4SLinus Torvalds 		RME96_WCR_SEL |    /* normal playback */
1647*1da177e4SLinus Torvalds 		RME96_WCR_MASTER | /* set to master clock mode */
1648*1da177e4SLinus Torvalds 		RME96_WCR_INP_0;   /* set coaxial input */
1649*1da177e4SLinus Torvalds 
1650*1da177e4SLinus Torvalds 	rme96->areg = RME96_AR_FREQPAD_1; /* set 44.1 kHz analog capture */
1651*1da177e4SLinus Torvalds 
1652*1da177e4SLinus Torvalds 	writel(rme96->wcreg, rme96->iobase + RME96_IO_CONTROL_REGISTER);
1653*1da177e4SLinus Torvalds 	writel(rme96->areg, rme96->iobase + RME96_IO_ADDITIONAL_REG);
1654*1da177e4SLinus Torvalds 
1655*1da177e4SLinus Torvalds 	/* reset the ADC */
1656*1da177e4SLinus Torvalds 	writel(rme96->areg | RME96_AR_PD2,
1657*1da177e4SLinus Torvalds 	       rme96->iobase + RME96_IO_ADDITIONAL_REG);
1658*1da177e4SLinus Torvalds 	writel(rme96->areg, rme96->iobase + RME96_IO_ADDITIONAL_REG);
1659*1da177e4SLinus Torvalds 
1660*1da177e4SLinus Torvalds 	/* reset and enable the DAC (order is important). */
1661*1da177e4SLinus Torvalds 	snd_rme96_reset_dac(rme96);
1662*1da177e4SLinus Torvalds 	rme96->areg |= RME96_AR_DAC_EN;
1663*1da177e4SLinus Torvalds 	writel(rme96->areg, rme96->iobase + RME96_IO_ADDITIONAL_REG);
1664*1da177e4SLinus Torvalds 
1665*1da177e4SLinus Torvalds 	/* reset playback and record buffer pointers */
1666*1da177e4SLinus Torvalds 	writel(0, rme96->iobase + RME96_IO_RESET_PLAY_POS);
1667*1da177e4SLinus Torvalds 	writel(0, rme96->iobase + RME96_IO_RESET_REC_POS);
1668*1da177e4SLinus Torvalds 
1669*1da177e4SLinus Torvalds 	/* reset volume */
1670*1da177e4SLinus Torvalds 	rme96->vol[0] = rme96->vol[1] = 0;
1671*1da177e4SLinus Torvalds 	if (RME96_HAS_ANALOG_OUT(rme96)) {
1672*1da177e4SLinus Torvalds 		snd_rme96_apply_dac_volume(rme96);
1673*1da177e4SLinus Torvalds 	}
1674*1da177e4SLinus Torvalds 
1675*1da177e4SLinus Torvalds 	/* init switch interface */
1676*1da177e4SLinus Torvalds 	if ((err = snd_rme96_create_switches(rme96->card, rme96)) < 0) {
1677*1da177e4SLinus Torvalds 		return err;
1678*1da177e4SLinus Torvalds 	}
1679*1da177e4SLinus Torvalds 
1680*1da177e4SLinus Torvalds         /* init proc interface */
1681*1da177e4SLinus Torvalds 	snd_rme96_proc_init(rme96);
1682*1da177e4SLinus Torvalds 
1683*1da177e4SLinus Torvalds 	return 0;
1684*1da177e4SLinus Torvalds }
1685*1da177e4SLinus Torvalds 
1686*1da177e4SLinus Torvalds /*
1687*1da177e4SLinus Torvalds  * proc interface
1688*1da177e4SLinus Torvalds  */
1689*1da177e4SLinus Torvalds 
1690*1da177e4SLinus Torvalds static void
1691*1da177e4SLinus Torvalds snd_rme96_proc_read(snd_info_entry_t *entry, snd_info_buffer_t *buffer)
1692*1da177e4SLinus Torvalds {
1693*1da177e4SLinus Torvalds 	int n;
1694*1da177e4SLinus Torvalds 	rme96_t *rme96 = (rme96_t *)entry->private_data;
1695*1da177e4SLinus Torvalds 
1696*1da177e4SLinus Torvalds 	rme96->rcreg = readl(rme96->iobase + RME96_IO_CONTROL_REGISTER);
1697*1da177e4SLinus Torvalds 
1698*1da177e4SLinus Torvalds 	snd_iprintf(buffer, rme96->card->longname);
1699*1da177e4SLinus Torvalds 	snd_iprintf(buffer, " (index #%d)\n", rme96->card->number + 1);
1700*1da177e4SLinus Torvalds 
1701*1da177e4SLinus Torvalds 	snd_iprintf(buffer, "\nGeneral settings\n");
1702*1da177e4SLinus Torvalds 	if (rme96->wcreg & RME96_WCR_IDIS) {
1703*1da177e4SLinus Torvalds 		snd_iprintf(buffer, "  period size: N/A (interrupts "
1704*1da177e4SLinus Torvalds 			    "disabled)\n");
1705*1da177e4SLinus Torvalds 	} else if (rme96->wcreg & RME96_WCR_ISEL) {
1706*1da177e4SLinus Torvalds 		snd_iprintf(buffer, "  period size: 2048 bytes\n");
1707*1da177e4SLinus Torvalds 	} else {
1708*1da177e4SLinus Torvalds 		snd_iprintf(buffer, "  period size: 8192 bytes\n");
1709*1da177e4SLinus Torvalds 	}
1710*1da177e4SLinus Torvalds 	snd_iprintf(buffer, "\nInput settings\n");
1711*1da177e4SLinus Torvalds 	switch (snd_rme96_getinputtype(rme96)) {
1712*1da177e4SLinus Torvalds 	case RME96_INPUT_OPTICAL:
1713*1da177e4SLinus Torvalds 		snd_iprintf(buffer, "  input: optical");
1714*1da177e4SLinus Torvalds 		break;
1715*1da177e4SLinus Torvalds 	case RME96_INPUT_COAXIAL:
1716*1da177e4SLinus Torvalds 		snd_iprintf(buffer, "  input: coaxial");
1717*1da177e4SLinus Torvalds 		break;
1718*1da177e4SLinus Torvalds 	case RME96_INPUT_INTERNAL:
1719*1da177e4SLinus Torvalds 		snd_iprintf(buffer, "  input: internal");
1720*1da177e4SLinus Torvalds 		break;
1721*1da177e4SLinus Torvalds 	case RME96_INPUT_XLR:
1722*1da177e4SLinus Torvalds 		snd_iprintf(buffer, "  input: XLR");
1723*1da177e4SLinus Torvalds 		break;
1724*1da177e4SLinus Torvalds 	case RME96_INPUT_ANALOG:
1725*1da177e4SLinus Torvalds 		snd_iprintf(buffer, "  input: analog");
1726*1da177e4SLinus Torvalds 		break;
1727*1da177e4SLinus Torvalds 	}
1728*1da177e4SLinus Torvalds 	if (snd_rme96_capture_getrate(rme96, &n) < 0) {
1729*1da177e4SLinus Torvalds 		snd_iprintf(buffer, "\n  sample rate: no valid signal\n");
1730*1da177e4SLinus Torvalds 	} else {
1731*1da177e4SLinus Torvalds 		if (n) {
1732*1da177e4SLinus Torvalds 			snd_iprintf(buffer, " (8 channels)\n");
1733*1da177e4SLinus Torvalds 		} else {
1734*1da177e4SLinus Torvalds 			snd_iprintf(buffer, " (2 channels)\n");
1735*1da177e4SLinus Torvalds 		}
1736*1da177e4SLinus Torvalds 		snd_iprintf(buffer, "  sample rate: %d Hz\n",
1737*1da177e4SLinus Torvalds 			    snd_rme96_capture_getrate(rme96, &n));
1738*1da177e4SLinus Torvalds 	}
1739*1da177e4SLinus Torvalds 	if (rme96->wcreg & RME96_WCR_MODE24_2) {
1740*1da177e4SLinus Torvalds 		snd_iprintf(buffer, "  sample format: 24 bit\n");
1741*1da177e4SLinus Torvalds 	} else {
1742*1da177e4SLinus Torvalds 		snd_iprintf(buffer, "  sample format: 16 bit\n");
1743*1da177e4SLinus Torvalds 	}
1744*1da177e4SLinus Torvalds 
1745*1da177e4SLinus Torvalds 	snd_iprintf(buffer, "\nOutput settings\n");
1746*1da177e4SLinus Torvalds 	if (rme96->wcreg & RME96_WCR_SEL) {
1747*1da177e4SLinus Torvalds 		snd_iprintf(buffer, "  output signal: normal playback\n");
1748*1da177e4SLinus Torvalds 	} else {
1749*1da177e4SLinus Torvalds 		snd_iprintf(buffer, "  output signal: same as input\n");
1750*1da177e4SLinus Torvalds 	}
1751*1da177e4SLinus Torvalds 	snd_iprintf(buffer, "  sample rate: %d Hz\n",
1752*1da177e4SLinus Torvalds 		    snd_rme96_playback_getrate(rme96));
1753*1da177e4SLinus Torvalds 	if (rme96->wcreg & RME96_WCR_MODE24) {
1754*1da177e4SLinus Torvalds 		snd_iprintf(buffer, "  sample format: 24 bit\n");
1755*1da177e4SLinus Torvalds 	} else {
1756*1da177e4SLinus Torvalds 		snd_iprintf(buffer, "  sample format: 16 bit\n");
1757*1da177e4SLinus Torvalds 	}
1758*1da177e4SLinus Torvalds 	if (rme96->areg & RME96_AR_WSEL) {
1759*1da177e4SLinus Torvalds 		snd_iprintf(buffer, "  sample clock source: word clock\n");
1760*1da177e4SLinus Torvalds 	} else if (rme96->wcreg & RME96_WCR_MASTER) {
1761*1da177e4SLinus Torvalds 		snd_iprintf(buffer, "  sample clock source: internal\n");
1762*1da177e4SLinus Torvalds 	} else if (snd_rme96_getinputtype(rme96) == RME96_INPUT_ANALOG) {
1763*1da177e4SLinus Torvalds 		snd_iprintf(buffer, "  sample clock source: autosync (internal anyway due to analog input setting)\n");
1764*1da177e4SLinus Torvalds 	} else if (snd_rme96_capture_getrate(rme96, &n) < 0) {
1765*1da177e4SLinus Torvalds 		snd_iprintf(buffer, "  sample clock source: autosync (internal anyway due to no valid signal)\n");
1766*1da177e4SLinus Torvalds 	} else {
1767*1da177e4SLinus Torvalds 		snd_iprintf(buffer, "  sample clock source: autosync\n");
1768*1da177e4SLinus Torvalds 	}
1769*1da177e4SLinus Torvalds 	if (rme96->wcreg & RME96_WCR_PRO) {
1770*1da177e4SLinus Torvalds 		snd_iprintf(buffer, "  format: AES/EBU (professional)\n");
1771*1da177e4SLinus Torvalds 	} else {
1772*1da177e4SLinus Torvalds 		snd_iprintf(buffer, "  format: IEC958 (consumer)\n");
1773*1da177e4SLinus Torvalds 	}
1774*1da177e4SLinus Torvalds 	if (rme96->wcreg & RME96_WCR_EMP) {
1775*1da177e4SLinus Torvalds 		snd_iprintf(buffer, "  emphasis: on\n");
1776*1da177e4SLinus Torvalds 	} else {
1777*1da177e4SLinus Torvalds 		snd_iprintf(buffer, "  emphasis: off\n");
1778*1da177e4SLinus Torvalds 	}
1779*1da177e4SLinus Torvalds 	if (rme96->wcreg & RME96_WCR_DOLBY) {
1780*1da177e4SLinus Torvalds 		snd_iprintf(buffer, "  non-audio (dolby): on\n");
1781*1da177e4SLinus Torvalds 	} else {
1782*1da177e4SLinus Torvalds 		snd_iprintf(buffer, "  non-audio (dolby): off\n");
1783*1da177e4SLinus Torvalds 	}
1784*1da177e4SLinus Torvalds 	if (RME96_HAS_ANALOG_IN(rme96)) {
1785*1da177e4SLinus Torvalds 		snd_iprintf(buffer, "\nAnalog output settings\n");
1786*1da177e4SLinus Torvalds 		switch (snd_rme96_getmontracks(rme96)) {
1787*1da177e4SLinus Torvalds 		case RME96_MONITOR_TRACKS_1_2:
1788*1da177e4SLinus Torvalds 			snd_iprintf(buffer, "  monitored ADAT tracks: 1+2\n");
1789*1da177e4SLinus Torvalds 			break;
1790*1da177e4SLinus Torvalds 		case RME96_MONITOR_TRACKS_3_4:
1791*1da177e4SLinus Torvalds 			snd_iprintf(buffer, "  monitored ADAT tracks: 3+4\n");
1792*1da177e4SLinus Torvalds 			break;
1793*1da177e4SLinus Torvalds 		case RME96_MONITOR_TRACKS_5_6:
1794*1da177e4SLinus Torvalds 			snd_iprintf(buffer, "  monitored ADAT tracks: 5+6\n");
1795*1da177e4SLinus Torvalds 			break;
1796*1da177e4SLinus Torvalds 		case RME96_MONITOR_TRACKS_7_8:
1797*1da177e4SLinus Torvalds 			snd_iprintf(buffer, "  monitored ADAT tracks: 7+8\n");
1798*1da177e4SLinus Torvalds 			break;
1799*1da177e4SLinus Torvalds 		}
1800*1da177e4SLinus Torvalds 		switch (snd_rme96_getattenuation(rme96)) {
1801*1da177e4SLinus Torvalds 		case RME96_ATTENUATION_0:
1802*1da177e4SLinus Torvalds 			snd_iprintf(buffer, "  attenuation: 0 dB\n");
1803*1da177e4SLinus Torvalds 			break;
1804*1da177e4SLinus Torvalds 		case RME96_ATTENUATION_6:
1805*1da177e4SLinus Torvalds 			snd_iprintf(buffer, "  attenuation: -6 dB\n");
1806*1da177e4SLinus Torvalds 			break;
1807*1da177e4SLinus Torvalds 		case RME96_ATTENUATION_12:
1808*1da177e4SLinus Torvalds 			snd_iprintf(buffer, "  attenuation: -12 dB\n");
1809*1da177e4SLinus Torvalds 			break;
1810*1da177e4SLinus Torvalds 		case RME96_ATTENUATION_18:
1811*1da177e4SLinus Torvalds 			snd_iprintf(buffer, "  attenuation: -18 dB\n");
1812*1da177e4SLinus Torvalds 			break;
1813*1da177e4SLinus Torvalds 		}
1814*1da177e4SLinus Torvalds 		snd_iprintf(buffer, "  volume left: %u\n", rme96->vol[0]);
1815*1da177e4SLinus Torvalds 		snd_iprintf(buffer, "  volume right: %u\n", rme96->vol[1]);
1816*1da177e4SLinus Torvalds 	}
1817*1da177e4SLinus Torvalds }
1818*1da177e4SLinus Torvalds 
1819*1da177e4SLinus Torvalds static void __devinit
1820*1da177e4SLinus Torvalds snd_rme96_proc_init(rme96_t *rme96)
1821*1da177e4SLinus Torvalds {
1822*1da177e4SLinus Torvalds 	snd_info_entry_t *entry;
1823*1da177e4SLinus Torvalds 
1824*1da177e4SLinus Torvalds 	if (! snd_card_proc_new(rme96->card, "rme96", &entry))
1825*1da177e4SLinus Torvalds 		snd_info_set_text_ops(entry, rme96, 1024, snd_rme96_proc_read);
1826*1da177e4SLinus Torvalds }
1827*1da177e4SLinus Torvalds 
1828*1da177e4SLinus Torvalds /*
1829*1da177e4SLinus Torvalds  * control interface
1830*1da177e4SLinus Torvalds  */
1831*1da177e4SLinus Torvalds 
1832*1da177e4SLinus Torvalds static int
1833*1da177e4SLinus Torvalds snd_rme96_info_loopback_control(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
1834*1da177e4SLinus Torvalds {
1835*1da177e4SLinus Torvalds 	uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
1836*1da177e4SLinus Torvalds 	uinfo->count = 1;
1837*1da177e4SLinus Torvalds 	uinfo->value.integer.min = 0;
1838*1da177e4SLinus Torvalds 	uinfo->value.integer.max = 1;
1839*1da177e4SLinus Torvalds 	return 0;
1840*1da177e4SLinus Torvalds }
1841*1da177e4SLinus Torvalds static int
1842*1da177e4SLinus Torvalds snd_rme96_get_loopback_control(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1843*1da177e4SLinus Torvalds {
1844*1da177e4SLinus Torvalds 	rme96_t *rme96 = snd_kcontrol_chip(kcontrol);
1845*1da177e4SLinus Torvalds 
1846*1da177e4SLinus Torvalds 	spin_lock_irq(&rme96->lock);
1847*1da177e4SLinus Torvalds 	ucontrol->value.integer.value[0] = rme96->wcreg & RME96_WCR_SEL ? 0 : 1;
1848*1da177e4SLinus Torvalds 	spin_unlock_irq(&rme96->lock);
1849*1da177e4SLinus Torvalds 	return 0;
1850*1da177e4SLinus Torvalds }
1851*1da177e4SLinus Torvalds static int
1852*1da177e4SLinus Torvalds snd_rme96_put_loopback_control(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1853*1da177e4SLinus Torvalds {
1854*1da177e4SLinus Torvalds 	rme96_t *rme96 = snd_kcontrol_chip(kcontrol);
1855*1da177e4SLinus Torvalds 	unsigned int val;
1856*1da177e4SLinus Torvalds 	int change;
1857*1da177e4SLinus Torvalds 
1858*1da177e4SLinus Torvalds 	val = ucontrol->value.integer.value[0] ? 0 : RME96_WCR_SEL;
1859*1da177e4SLinus Torvalds 	spin_lock_irq(&rme96->lock);
1860*1da177e4SLinus Torvalds 	val = (rme96->wcreg & ~RME96_WCR_SEL) | val;
1861*1da177e4SLinus Torvalds 	change = val != rme96->wcreg;
1862*1da177e4SLinus Torvalds 	rme96->wcreg = val;
1863*1da177e4SLinus Torvalds 	writel(val, rme96->iobase + RME96_IO_CONTROL_REGISTER);
1864*1da177e4SLinus Torvalds 	spin_unlock_irq(&rme96->lock);
1865*1da177e4SLinus Torvalds 	return change;
1866*1da177e4SLinus Torvalds }
1867*1da177e4SLinus Torvalds 
1868*1da177e4SLinus Torvalds static int
1869*1da177e4SLinus Torvalds snd_rme96_info_inputtype_control(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
1870*1da177e4SLinus Torvalds {
1871*1da177e4SLinus Torvalds 	static char *_texts[5] = { "Optical", "Coaxial", "Internal", "XLR", "Analog" };
1872*1da177e4SLinus Torvalds 	rme96_t *rme96 = snd_kcontrol_chip(kcontrol);
1873*1da177e4SLinus Torvalds 	char *texts[5] = { _texts[0], _texts[1], _texts[2], _texts[3], _texts[4] };
1874*1da177e4SLinus Torvalds 
1875*1da177e4SLinus Torvalds 	uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1876*1da177e4SLinus Torvalds 	uinfo->count = 1;
1877*1da177e4SLinus Torvalds 	switch (rme96->pci->device) {
1878*1da177e4SLinus Torvalds 	case PCI_DEVICE_ID_DIGI96:
1879*1da177e4SLinus Torvalds 	case PCI_DEVICE_ID_DIGI96_8:
1880*1da177e4SLinus Torvalds 		uinfo->value.enumerated.items = 3;
1881*1da177e4SLinus Torvalds 		break;
1882*1da177e4SLinus Torvalds 	case PCI_DEVICE_ID_DIGI96_8_PRO:
1883*1da177e4SLinus Torvalds 		uinfo->value.enumerated.items = 4;
1884*1da177e4SLinus Torvalds 		break;
1885*1da177e4SLinus Torvalds 	case PCI_DEVICE_ID_DIGI96_8_PAD_OR_PST:
1886*1da177e4SLinus Torvalds 		if (rme96->rev > 4) {
1887*1da177e4SLinus Torvalds 			/* PST */
1888*1da177e4SLinus Torvalds 			uinfo->value.enumerated.items = 4;
1889*1da177e4SLinus Torvalds 			texts[3] = _texts[4]; /* Analog instead of XLR */
1890*1da177e4SLinus Torvalds 		} else {
1891*1da177e4SLinus Torvalds 			/* PAD */
1892*1da177e4SLinus Torvalds 			uinfo->value.enumerated.items = 5;
1893*1da177e4SLinus Torvalds 		}
1894*1da177e4SLinus Torvalds 		break;
1895*1da177e4SLinus Torvalds 	default:
1896*1da177e4SLinus Torvalds 		snd_BUG();
1897*1da177e4SLinus Torvalds 		break;
1898*1da177e4SLinus Torvalds 	}
1899*1da177e4SLinus Torvalds 	if (uinfo->value.enumerated.item > uinfo->value.enumerated.items - 1) {
1900*1da177e4SLinus Torvalds 		uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
1901*1da177e4SLinus Torvalds 	}
1902*1da177e4SLinus Torvalds 	strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1903*1da177e4SLinus Torvalds 	return 0;
1904*1da177e4SLinus Torvalds }
1905*1da177e4SLinus Torvalds static int
1906*1da177e4SLinus Torvalds snd_rme96_get_inputtype_control(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1907*1da177e4SLinus Torvalds {
1908*1da177e4SLinus Torvalds 	rme96_t *rme96 = snd_kcontrol_chip(kcontrol);
1909*1da177e4SLinus Torvalds 	unsigned int items = 3;
1910*1da177e4SLinus Torvalds 
1911*1da177e4SLinus Torvalds 	spin_lock_irq(&rme96->lock);
1912*1da177e4SLinus Torvalds 	ucontrol->value.enumerated.item[0] = snd_rme96_getinputtype(rme96);
1913*1da177e4SLinus Torvalds 
1914*1da177e4SLinus Torvalds 	switch (rme96->pci->device) {
1915*1da177e4SLinus Torvalds 	case PCI_DEVICE_ID_DIGI96:
1916*1da177e4SLinus Torvalds 	case PCI_DEVICE_ID_DIGI96_8:
1917*1da177e4SLinus Torvalds 		items = 3;
1918*1da177e4SLinus Torvalds 		break;
1919*1da177e4SLinus Torvalds 	case PCI_DEVICE_ID_DIGI96_8_PRO:
1920*1da177e4SLinus Torvalds 		items = 4;
1921*1da177e4SLinus Torvalds 		break;
1922*1da177e4SLinus Torvalds 	case PCI_DEVICE_ID_DIGI96_8_PAD_OR_PST:
1923*1da177e4SLinus Torvalds 		if (rme96->rev > 4) {
1924*1da177e4SLinus Torvalds 			/* for handling PST case, (INPUT_ANALOG is moved to INPUT_XLR */
1925*1da177e4SLinus Torvalds 			if (ucontrol->value.enumerated.item[0] == RME96_INPUT_ANALOG) {
1926*1da177e4SLinus Torvalds 				ucontrol->value.enumerated.item[0] = RME96_INPUT_XLR;
1927*1da177e4SLinus Torvalds 			}
1928*1da177e4SLinus Torvalds 			items = 4;
1929*1da177e4SLinus Torvalds 		} else {
1930*1da177e4SLinus Torvalds 			items = 5;
1931*1da177e4SLinus Torvalds 		}
1932*1da177e4SLinus Torvalds 		break;
1933*1da177e4SLinus Torvalds 	default:
1934*1da177e4SLinus Torvalds 		snd_BUG();
1935*1da177e4SLinus Torvalds 		break;
1936*1da177e4SLinus Torvalds 	}
1937*1da177e4SLinus Torvalds 	if (ucontrol->value.enumerated.item[0] >= items) {
1938*1da177e4SLinus Torvalds 		ucontrol->value.enumerated.item[0] = items - 1;
1939*1da177e4SLinus Torvalds 	}
1940*1da177e4SLinus Torvalds 
1941*1da177e4SLinus Torvalds 	spin_unlock_irq(&rme96->lock);
1942*1da177e4SLinus Torvalds 	return 0;
1943*1da177e4SLinus Torvalds }
1944*1da177e4SLinus Torvalds static int
1945*1da177e4SLinus Torvalds snd_rme96_put_inputtype_control(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1946*1da177e4SLinus Torvalds {
1947*1da177e4SLinus Torvalds 	rme96_t *rme96 = snd_kcontrol_chip(kcontrol);
1948*1da177e4SLinus Torvalds 	unsigned int val;
1949*1da177e4SLinus Torvalds 	int change, items = 3;
1950*1da177e4SLinus Torvalds 
1951*1da177e4SLinus Torvalds 	switch (rme96->pci->device) {
1952*1da177e4SLinus Torvalds 	case PCI_DEVICE_ID_DIGI96:
1953*1da177e4SLinus Torvalds 	case PCI_DEVICE_ID_DIGI96_8:
1954*1da177e4SLinus Torvalds 		items = 3;
1955*1da177e4SLinus Torvalds 		break;
1956*1da177e4SLinus Torvalds 	case PCI_DEVICE_ID_DIGI96_8_PRO:
1957*1da177e4SLinus Torvalds 		items = 4;
1958*1da177e4SLinus Torvalds 		break;
1959*1da177e4SLinus Torvalds 	case PCI_DEVICE_ID_DIGI96_8_PAD_OR_PST:
1960*1da177e4SLinus Torvalds 		if (rme96->rev > 4) {
1961*1da177e4SLinus Torvalds 			items = 4;
1962*1da177e4SLinus Torvalds 		} else {
1963*1da177e4SLinus Torvalds 			items = 5;
1964*1da177e4SLinus Torvalds 		}
1965*1da177e4SLinus Torvalds 		break;
1966*1da177e4SLinus Torvalds 	default:
1967*1da177e4SLinus Torvalds 		snd_BUG();
1968*1da177e4SLinus Torvalds 		break;
1969*1da177e4SLinus Torvalds 	}
1970*1da177e4SLinus Torvalds 	val = ucontrol->value.enumerated.item[0] % items;
1971*1da177e4SLinus Torvalds 
1972*1da177e4SLinus Torvalds 	/* special case for PST */
1973*1da177e4SLinus Torvalds 	if (rme96->pci->device == PCI_DEVICE_ID_DIGI96_8_PAD_OR_PST && rme96->rev > 4) {
1974*1da177e4SLinus Torvalds 		if (val == RME96_INPUT_XLR) {
1975*1da177e4SLinus Torvalds 			val = RME96_INPUT_ANALOG;
1976*1da177e4SLinus Torvalds 		}
1977*1da177e4SLinus Torvalds 	}
1978*1da177e4SLinus Torvalds 
1979*1da177e4SLinus Torvalds 	spin_lock_irq(&rme96->lock);
1980*1da177e4SLinus Torvalds 	change = (int)val != snd_rme96_getinputtype(rme96);
1981*1da177e4SLinus Torvalds 	snd_rme96_setinputtype(rme96, val);
1982*1da177e4SLinus Torvalds 	spin_unlock_irq(&rme96->lock);
1983*1da177e4SLinus Torvalds 	return change;
1984*1da177e4SLinus Torvalds }
1985*1da177e4SLinus Torvalds 
1986*1da177e4SLinus Torvalds static int
1987*1da177e4SLinus Torvalds snd_rme96_info_clockmode_control(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
1988*1da177e4SLinus Torvalds {
1989*1da177e4SLinus Torvalds 	static char *texts[3] = { "AutoSync", "Internal", "Word" };
1990*1da177e4SLinus Torvalds 
1991*1da177e4SLinus Torvalds 	uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1992*1da177e4SLinus Torvalds 	uinfo->count = 1;
1993*1da177e4SLinus Torvalds 	uinfo->value.enumerated.items = 3;
1994*1da177e4SLinus Torvalds 	if (uinfo->value.enumerated.item > 2) {
1995*1da177e4SLinus Torvalds 		uinfo->value.enumerated.item = 2;
1996*1da177e4SLinus Torvalds 	}
1997*1da177e4SLinus Torvalds 	strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1998*1da177e4SLinus Torvalds 	return 0;
1999*1da177e4SLinus Torvalds }
2000*1da177e4SLinus Torvalds static int
2001*1da177e4SLinus Torvalds snd_rme96_get_clockmode_control(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
2002*1da177e4SLinus Torvalds {
2003*1da177e4SLinus Torvalds 	rme96_t *rme96 = snd_kcontrol_chip(kcontrol);
2004*1da177e4SLinus Torvalds 
2005*1da177e4SLinus Torvalds 	spin_lock_irq(&rme96->lock);
2006*1da177e4SLinus Torvalds 	ucontrol->value.enumerated.item[0] = snd_rme96_getclockmode(rme96);
2007*1da177e4SLinus Torvalds 	spin_unlock_irq(&rme96->lock);
2008*1da177e4SLinus Torvalds 	return 0;
2009*1da177e4SLinus Torvalds }
2010*1da177e4SLinus Torvalds static int
2011*1da177e4SLinus Torvalds snd_rme96_put_clockmode_control(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
2012*1da177e4SLinus Torvalds {
2013*1da177e4SLinus Torvalds 	rme96_t *rme96 = snd_kcontrol_chip(kcontrol);
2014*1da177e4SLinus Torvalds 	unsigned int val;
2015*1da177e4SLinus Torvalds 	int change;
2016*1da177e4SLinus Torvalds 
2017*1da177e4SLinus Torvalds 	val = ucontrol->value.enumerated.item[0] % 3;
2018*1da177e4SLinus Torvalds 	spin_lock_irq(&rme96->lock);
2019*1da177e4SLinus Torvalds 	change = (int)val != snd_rme96_getclockmode(rme96);
2020*1da177e4SLinus Torvalds 	snd_rme96_setclockmode(rme96, val);
2021*1da177e4SLinus Torvalds 	spin_unlock_irq(&rme96->lock);
2022*1da177e4SLinus Torvalds 	return change;
2023*1da177e4SLinus Torvalds }
2024*1da177e4SLinus Torvalds 
2025*1da177e4SLinus Torvalds static int
2026*1da177e4SLinus Torvalds snd_rme96_info_attenuation_control(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
2027*1da177e4SLinus Torvalds {
2028*1da177e4SLinus Torvalds 	static char *texts[4] = { "0 dB", "-6 dB", "-12 dB", "-18 dB" };
2029*1da177e4SLinus Torvalds 
2030*1da177e4SLinus Torvalds 	uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2031*1da177e4SLinus Torvalds 	uinfo->count = 1;
2032*1da177e4SLinus Torvalds 	uinfo->value.enumerated.items = 4;
2033*1da177e4SLinus Torvalds 	if (uinfo->value.enumerated.item > 3) {
2034*1da177e4SLinus Torvalds 		uinfo->value.enumerated.item = 3;
2035*1da177e4SLinus Torvalds 	}
2036*1da177e4SLinus Torvalds 	strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
2037*1da177e4SLinus Torvalds 	return 0;
2038*1da177e4SLinus Torvalds }
2039*1da177e4SLinus Torvalds static int
2040*1da177e4SLinus Torvalds snd_rme96_get_attenuation_control(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
2041*1da177e4SLinus Torvalds {
2042*1da177e4SLinus Torvalds 	rme96_t *rme96 = snd_kcontrol_chip(kcontrol);
2043*1da177e4SLinus Torvalds 
2044*1da177e4SLinus Torvalds 	spin_lock_irq(&rme96->lock);
2045*1da177e4SLinus Torvalds 	ucontrol->value.enumerated.item[0] = snd_rme96_getattenuation(rme96);
2046*1da177e4SLinus Torvalds 	spin_unlock_irq(&rme96->lock);
2047*1da177e4SLinus Torvalds 	return 0;
2048*1da177e4SLinus Torvalds }
2049*1da177e4SLinus Torvalds static int
2050*1da177e4SLinus Torvalds snd_rme96_put_attenuation_control(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
2051*1da177e4SLinus Torvalds {
2052*1da177e4SLinus Torvalds 	rme96_t *rme96 = snd_kcontrol_chip(kcontrol);
2053*1da177e4SLinus Torvalds 	unsigned int val;
2054*1da177e4SLinus Torvalds 	int change;
2055*1da177e4SLinus Torvalds 
2056*1da177e4SLinus Torvalds 	val = ucontrol->value.enumerated.item[0] % 4;
2057*1da177e4SLinus Torvalds 	spin_lock_irq(&rme96->lock);
2058*1da177e4SLinus Torvalds 
2059*1da177e4SLinus Torvalds 	change = (int)val != snd_rme96_getattenuation(rme96);
2060*1da177e4SLinus Torvalds 	snd_rme96_setattenuation(rme96, val);
2061*1da177e4SLinus Torvalds 	spin_unlock_irq(&rme96->lock);
2062*1da177e4SLinus Torvalds 	return change;
2063*1da177e4SLinus Torvalds }
2064*1da177e4SLinus Torvalds 
2065*1da177e4SLinus Torvalds static int
2066*1da177e4SLinus Torvalds snd_rme96_info_montracks_control(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
2067*1da177e4SLinus Torvalds {
2068*1da177e4SLinus Torvalds 	static char *texts[4] = { "1+2", "3+4", "5+6", "7+8" };
2069*1da177e4SLinus Torvalds 
2070*1da177e4SLinus Torvalds 	uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2071*1da177e4SLinus Torvalds 	uinfo->count = 1;
2072*1da177e4SLinus Torvalds 	uinfo->value.enumerated.items = 4;
2073*1da177e4SLinus Torvalds 	if (uinfo->value.enumerated.item > 3) {
2074*1da177e4SLinus Torvalds 		uinfo->value.enumerated.item = 3;
2075*1da177e4SLinus Torvalds 	}
2076*1da177e4SLinus Torvalds 	strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
2077*1da177e4SLinus Torvalds 	return 0;
2078*1da177e4SLinus Torvalds }
2079*1da177e4SLinus Torvalds static int
2080*1da177e4SLinus Torvalds snd_rme96_get_montracks_control(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
2081*1da177e4SLinus Torvalds {
2082*1da177e4SLinus Torvalds 	rme96_t *rme96 = snd_kcontrol_chip(kcontrol);
2083*1da177e4SLinus Torvalds 
2084*1da177e4SLinus Torvalds 	spin_lock_irq(&rme96->lock);
2085*1da177e4SLinus Torvalds 	ucontrol->value.enumerated.item[0] = snd_rme96_getmontracks(rme96);
2086*1da177e4SLinus Torvalds 	spin_unlock_irq(&rme96->lock);
2087*1da177e4SLinus Torvalds 	return 0;
2088*1da177e4SLinus Torvalds }
2089*1da177e4SLinus Torvalds static int
2090*1da177e4SLinus Torvalds snd_rme96_put_montracks_control(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
2091*1da177e4SLinus Torvalds {
2092*1da177e4SLinus Torvalds 	rme96_t *rme96 = snd_kcontrol_chip(kcontrol);
2093*1da177e4SLinus Torvalds 	unsigned int val;
2094*1da177e4SLinus Torvalds 	int change;
2095*1da177e4SLinus Torvalds 
2096*1da177e4SLinus Torvalds 	val = ucontrol->value.enumerated.item[0] % 4;
2097*1da177e4SLinus Torvalds 	spin_lock_irq(&rme96->lock);
2098*1da177e4SLinus Torvalds 	change = (int)val != snd_rme96_getmontracks(rme96);
2099*1da177e4SLinus Torvalds 	snd_rme96_setmontracks(rme96, val);
2100*1da177e4SLinus Torvalds 	spin_unlock_irq(&rme96->lock);
2101*1da177e4SLinus Torvalds 	return change;
2102*1da177e4SLinus Torvalds }
2103*1da177e4SLinus Torvalds 
2104*1da177e4SLinus Torvalds static u32 snd_rme96_convert_from_aes(snd_aes_iec958_t *aes)
2105*1da177e4SLinus Torvalds {
2106*1da177e4SLinus Torvalds 	u32 val = 0;
2107*1da177e4SLinus Torvalds 	val |= (aes->status[0] & IEC958_AES0_PROFESSIONAL) ? RME96_WCR_PRO : 0;
2108*1da177e4SLinus Torvalds 	val |= (aes->status[0] & IEC958_AES0_NONAUDIO) ? RME96_WCR_DOLBY : 0;
2109*1da177e4SLinus Torvalds 	if (val & RME96_WCR_PRO)
2110*1da177e4SLinus Torvalds 		val |= (aes->status[0] & IEC958_AES0_PRO_EMPHASIS_5015) ? RME96_WCR_EMP : 0;
2111*1da177e4SLinus Torvalds 	else
2112*1da177e4SLinus Torvalds 		val |= (aes->status[0] & IEC958_AES0_CON_EMPHASIS_5015) ? RME96_WCR_EMP : 0;
2113*1da177e4SLinus Torvalds 	return val;
2114*1da177e4SLinus Torvalds }
2115*1da177e4SLinus Torvalds 
2116*1da177e4SLinus Torvalds static void snd_rme96_convert_to_aes(snd_aes_iec958_t *aes, u32 val)
2117*1da177e4SLinus Torvalds {
2118*1da177e4SLinus Torvalds 	aes->status[0] = ((val & RME96_WCR_PRO) ? IEC958_AES0_PROFESSIONAL : 0) |
2119*1da177e4SLinus Torvalds 			 ((val & RME96_WCR_DOLBY) ? IEC958_AES0_NONAUDIO : 0);
2120*1da177e4SLinus Torvalds 	if (val & RME96_WCR_PRO)
2121*1da177e4SLinus Torvalds 		aes->status[0] |= (val & RME96_WCR_EMP) ? IEC958_AES0_PRO_EMPHASIS_5015 : 0;
2122*1da177e4SLinus Torvalds 	else
2123*1da177e4SLinus Torvalds 		aes->status[0] |= (val & RME96_WCR_EMP) ? IEC958_AES0_CON_EMPHASIS_5015 : 0;
2124*1da177e4SLinus Torvalds }
2125*1da177e4SLinus Torvalds 
2126*1da177e4SLinus Torvalds static int snd_rme96_control_spdif_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
2127*1da177e4SLinus Torvalds {
2128*1da177e4SLinus Torvalds 	uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
2129*1da177e4SLinus Torvalds 	uinfo->count = 1;
2130*1da177e4SLinus Torvalds 	return 0;
2131*1da177e4SLinus Torvalds }
2132*1da177e4SLinus Torvalds 
2133*1da177e4SLinus Torvalds static int snd_rme96_control_spdif_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
2134*1da177e4SLinus Torvalds {
2135*1da177e4SLinus Torvalds 	rme96_t *rme96 = snd_kcontrol_chip(kcontrol);
2136*1da177e4SLinus Torvalds 
2137*1da177e4SLinus Torvalds 	snd_rme96_convert_to_aes(&ucontrol->value.iec958, rme96->wcreg_spdif);
2138*1da177e4SLinus Torvalds 	return 0;
2139*1da177e4SLinus Torvalds }
2140*1da177e4SLinus Torvalds 
2141*1da177e4SLinus Torvalds static int snd_rme96_control_spdif_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
2142*1da177e4SLinus Torvalds {
2143*1da177e4SLinus Torvalds 	rme96_t *rme96 = snd_kcontrol_chip(kcontrol);
2144*1da177e4SLinus Torvalds 	int change;
2145*1da177e4SLinus Torvalds 	u32 val;
2146*1da177e4SLinus Torvalds 
2147*1da177e4SLinus Torvalds 	val = snd_rme96_convert_from_aes(&ucontrol->value.iec958);
2148*1da177e4SLinus Torvalds 	spin_lock_irq(&rme96->lock);
2149*1da177e4SLinus Torvalds 	change = val != rme96->wcreg_spdif;
2150*1da177e4SLinus Torvalds 	rme96->wcreg_spdif = val;
2151*1da177e4SLinus Torvalds 	spin_unlock_irq(&rme96->lock);
2152*1da177e4SLinus Torvalds 	return change;
2153*1da177e4SLinus Torvalds }
2154*1da177e4SLinus Torvalds 
2155*1da177e4SLinus Torvalds static int snd_rme96_control_spdif_stream_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
2156*1da177e4SLinus Torvalds {
2157*1da177e4SLinus Torvalds 	uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
2158*1da177e4SLinus Torvalds 	uinfo->count = 1;
2159*1da177e4SLinus Torvalds 	return 0;
2160*1da177e4SLinus Torvalds }
2161*1da177e4SLinus Torvalds 
2162*1da177e4SLinus Torvalds static int snd_rme96_control_spdif_stream_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
2163*1da177e4SLinus Torvalds {
2164*1da177e4SLinus Torvalds 	rme96_t *rme96 = snd_kcontrol_chip(kcontrol);
2165*1da177e4SLinus Torvalds 
2166*1da177e4SLinus Torvalds 	snd_rme96_convert_to_aes(&ucontrol->value.iec958, rme96->wcreg_spdif_stream);
2167*1da177e4SLinus Torvalds 	return 0;
2168*1da177e4SLinus Torvalds }
2169*1da177e4SLinus Torvalds 
2170*1da177e4SLinus Torvalds static int snd_rme96_control_spdif_stream_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
2171*1da177e4SLinus Torvalds {
2172*1da177e4SLinus Torvalds 	rme96_t *rme96 = snd_kcontrol_chip(kcontrol);
2173*1da177e4SLinus Torvalds 	int change;
2174*1da177e4SLinus Torvalds 	u32 val;
2175*1da177e4SLinus Torvalds 
2176*1da177e4SLinus Torvalds 	val = snd_rme96_convert_from_aes(&ucontrol->value.iec958);
2177*1da177e4SLinus Torvalds 	spin_lock_irq(&rme96->lock);
2178*1da177e4SLinus Torvalds 	change = val != rme96->wcreg_spdif_stream;
2179*1da177e4SLinus Torvalds 	rme96->wcreg_spdif_stream = val;
2180*1da177e4SLinus Torvalds 	rme96->wcreg &= ~(RME96_WCR_PRO | RME96_WCR_DOLBY | RME96_WCR_EMP);
2181*1da177e4SLinus Torvalds 	rme96->wcreg |= val;
2182*1da177e4SLinus Torvalds 	writel(rme96->wcreg, rme96->iobase + RME96_IO_CONTROL_REGISTER);
2183*1da177e4SLinus Torvalds 	spin_unlock_irq(&rme96->lock);
2184*1da177e4SLinus Torvalds 	return change;
2185*1da177e4SLinus Torvalds }
2186*1da177e4SLinus Torvalds 
2187*1da177e4SLinus Torvalds static int snd_rme96_control_spdif_mask_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
2188*1da177e4SLinus Torvalds {
2189*1da177e4SLinus Torvalds 	uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
2190*1da177e4SLinus Torvalds 	uinfo->count = 1;
2191*1da177e4SLinus Torvalds 	return 0;
2192*1da177e4SLinus Torvalds }
2193*1da177e4SLinus Torvalds 
2194*1da177e4SLinus Torvalds static int snd_rme96_control_spdif_mask_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
2195*1da177e4SLinus Torvalds {
2196*1da177e4SLinus Torvalds 	ucontrol->value.iec958.status[0] = kcontrol->private_value;
2197*1da177e4SLinus Torvalds 	return 0;
2198*1da177e4SLinus Torvalds }
2199*1da177e4SLinus Torvalds 
2200*1da177e4SLinus Torvalds static int
2201*1da177e4SLinus Torvalds snd_rme96_dac_volume_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
2202*1da177e4SLinus Torvalds {
2203*1da177e4SLinus Torvalds 	rme96_t *rme96 = snd_kcontrol_chip(kcontrol);
2204*1da177e4SLinus Torvalds 
2205*1da177e4SLinus Torvalds         uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
2206*1da177e4SLinus Torvalds         uinfo->count = 2;
2207*1da177e4SLinus Torvalds         uinfo->value.integer.min = 0;
2208*1da177e4SLinus Torvalds 	uinfo->value.integer.max = RME96_185X_MAX_OUT(rme96);
2209*1da177e4SLinus Torvalds         return 0;
2210*1da177e4SLinus Torvalds }
2211*1da177e4SLinus Torvalds 
2212*1da177e4SLinus Torvalds static int
2213*1da177e4SLinus Torvalds snd_rme96_dac_volume_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *u)
2214*1da177e4SLinus Torvalds {
2215*1da177e4SLinus Torvalds 	rme96_t *rme96 = snd_kcontrol_chip(kcontrol);
2216*1da177e4SLinus Torvalds 
2217*1da177e4SLinus Torvalds 	spin_lock_irq(&rme96->lock);
2218*1da177e4SLinus Torvalds         u->value.integer.value[0] = rme96->vol[0];
2219*1da177e4SLinus Torvalds         u->value.integer.value[1] = rme96->vol[1];
2220*1da177e4SLinus Torvalds 	spin_unlock_irq(&rme96->lock);
2221*1da177e4SLinus Torvalds 
2222*1da177e4SLinus Torvalds         return 0;
2223*1da177e4SLinus Torvalds }
2224*1da177e4SLinus Torvalds 
2225*1da177e4SLinus Torvalds static int
2226*1da177e4SLinus Torvalds snd_rme96_dac_volume_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *u)
2227*1da177e4SLinus Torvalds {
2228*1da177e4SLinus Torvalds 	rme96_t *rme96 = snd_kcontrol_chip(kcontrol);
2229*1da177e4SLinus Torvalds         int change = 0;
2230*1da177e4SLinus Torvalds 
2231*1da177e4SLinus Torvalds 	if (!RME96_HAS_ANALOG_OUT(rme96)) {
2232*1da177e4SLinus Torvalds 		return -EINVAL;
2233*1da177e4SLinus Torvalds 	}
2234*1da177e4SLinus Torvalds 	spin_lock_irq(&rme96->lock);
2235*1da177e4SLinus Torvalds         if (u->value.integer.value[0] != rme96->vol[0]) {
2236*1da177e4SLinus Torvalds 		rme96->vol[0] = u->value.integer.value[0];
2237*1da177e4SLinus Torvalds                 change = 1;
2238*1da177e4SLinus Torvalds         }
2239*1da177e4SLinus Torvalds         if (u->value.integer.value[1] != rme96->vol[1]) {
2240*1da177e4SLinus Torvalds 		rme96->vol[1] = u->value.integer.value[1];
2241*1da177e4SLinus Torvalds                 change = 1;
2242*1da177e4SLinus Torvalds         }
2243*1da177e4SLinus Torvalds 	if (change) {
2244*1da177e4SLinus Torvalds 		snd_rme96_apply_dac_volume(rme96);
2245*1da177e4SLinus Torvalds 	}
2246*1da177e4SLinus Torvalds 	spin_unlock_irq(&rme96->lock);
2247*1da177e4SLinus Torvalds 
2248*1da177e4SLinus Torvalds         return change;
2249*1da177e4SLinus Torvalds }
2250*1da177e4SLinus Torvalds 
2251*1da177e4SLinus Torvalds static snd_kcontrol_new_t snd_rme96_controls[] = {
2252*1da177e4SLinus Torvalds {
2253*1da177e4SLinus Torvalds 	.iface =	SNDRV_CTL_ELEM_IFACE_PCM,
2254*1da177e4SLinus Torvalds 	.name =		SNDRV_CTL_NAME_IEC958("",PLAYBACK,DEFAULT),
2255*1da177e4SLinus Torvalds 	.info =		snd_rme96_control_spdif_info,
2256*1da177e4SLinus Torvalds 	.get =		snd_rme96_control_spdif_get,
2257*1da177e4SLinus Torvalds 	.put =		snd_rme96_control_spdif_put
2258*1da177e4SLinus Torvalds },
2259*1da177e4SLinus Torvalds {
2260*1da177e4SLinus Torvalds 	.access =	SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_INACTIVE,
2261*1da177e4SLinus Torvalds 	.iface =	SNDRV_CTL_ELEM_IFACE_PCM,
2262*1da177e4SLinus Torvalds 	.name =		SNDRV_CTL_NAME_IEC958("",PLAYBACK,PCM_STREAM),
2263*1da177e4SLinus Torvalds 	.info =		snd_rme96_control_spdif_stream_info,
2264*1da177e4SLinus Torvalds 	.get =		snd_rme96_control_spdif_stream_get,
2265*1da177e4SLinus Torvalds 	.put =		snd_rme96_control_spdif_stream_put
2266*1da177e4SLinus Torvalds },
2267*1da177e4SLinus Torvalds {
2268*1da177e4SLinus Torvalds 	.access =	SNDRV_CTL_ELEM_ACCESS_READ,
2269*1da177e4SLinus Torvalds 	.iface =	SNDRV_CTL_ELEM_IFACE_MIXER,
2270*1da177e4SLinus Torvalds 	.name =		SNDRV_CTL_NAME_IEC958("",PLAYBACK,CON_MASK),
2271*1da177e4SLinus Torvalds 	.info =		snd_rme96_control_spdif_mask_info,
2272*1da177e4SLinus Torvalds 	.get =		snd_rme96_control_spdif_mask_get,
2273*1da177e4SLinus Torvalds 	.private_value = IEC958_AES0_NONAUDIO |
2274*1da177e4SLinus Torvalds 			IEC958_AES0_PROFESSIONAL |
2275*1da177e4SLinus Torvalds 			IEC958_AES0_CON_EMPHASIS
2276*1da177e4SLinus Torvalds },
2277*1da177e4SLinus Torvalds {
2278*1da177e4SLinus Torvalds 	.access =	SNDRV_CTL_ELEM_ACCESS_READ,
2279*1da177e4SLinus Torvalds 	.iface =	SNDRV_CTL_ELEM_IFACE_MIXER,
2280*1da177e4SLinus Torvalds 	.name =		SNDRV_CTL_NAME_IEC958("",PLAYBACK,PRO_MASK),
2281*1da177e4SLinus Torvalds 	.info =		snd_rme96_control_spdif_mask_info,
2282*1da177e4SLinus Torvalds 	.get =		snd_rme96_control_spdif_mask_get,
2283*1da177e4SLinus Torvalds 	.private_value = IEC958_AES0_NONAUDIO |
2284*1da177e4SLinus Torvalds 			IEC958_AES0_PROFESSIONAL |
2285*1da177e4SLinus Torvalds 			IEC958_AES0_PRO_EMPHASIS
2286*1da177e4SLinus Torvalds },
2287*1da177e4SLinus Torvalds {
2288*1da177e4SLinus Torvalds         .iface =        SNDRV_CTL_ELEM_IFACE_MIXER,
2289*1da177e4SLinus Torvalds 	.name =         "Input Connector",
2290*1da177e4SLinus Torvalds 	.info =         snd_rme96_info_inputtype_control,
2291*1da177e4SLinus Torvalds 	.get =          snd_rme96_get_inputtype_control,
2292*1da177e4SLinus Torvalds 	.put =          snd_rme96_put_inputtype_control
2293*1da177e4SLinus Torvalds },
2294*1da177e4SLinus Torvalds {
2295*1da177e4SLinus Torvalds         .iface =        SNDRV_CTL_ELEM_IFACE_MIXER,
2296*1da177e4SLinus Torvalds 	.name =         "Loopback Input",
2297*1da177e4SLinus Torvalds 	.info =         snd_rme96_info_loopback_control,
2298*1da177e4SLinus Torvalds 	.get =          snd_rme96_get_loopback_control,
2299*1da177e4SLinus Torvalds 	.put =          snd_rme96_put_loopback_control
2300*1da177e4SLinus Torvalds },
2301*1da177e4SLinus Torvalds {
2302*1da177e4SLinus Torvalds         .iface =        SNDRV_CTL_ELEM_IFACE_MIXER,
2303*1da177e4SLinus Torvalds 	.name =         "Sample Clock Source",
2304*1da177e4SLinus Torvalds 	.info =         snd_rme96_info_clockmode_control,
2305*1da177e4SLinus Torvalds 	.get =          snd_rme96_get_clockmode_control,
2306*1da177e4SLinus Torvalds 	.put =          snd_rme96_put_clockmode_control
2307*1da177e4SLinus Torvalds },
2308*1da177e4SLinus Torvalds {
2309*1da177e4SLinus Torvalds         .iface =        SNDRV_CTL_ELEM_IFACE_MIXER,
2310*1da177e4SLinus Torvalds 	.name =         "Monitor Tracks",
2311*1da177e4SLinus Torvalds 	.info =         snd_rme96_info_montracks_control,
2312*1da177e4SLinus Torvalds 	.get =          snd_rme96_get_montracks_control,
2313*1da177e4SLinus Torvalds 	.put =          snd_rme96_put_montracks_control
2314*1da177e4SLinus Torvalds },
2315*1da177e4SLinus Torvalds {
2316*1da177e4SLinus Torvalds         .iface =        SNDRV_CTL_ELEM_IFACE_MIXER,
2317*1da177e4SLinus Torvalds 	.name =         "Attenuation",
2318*1da177e4SLinus Torvalds 	.info =         snd_rme96_info_attenuation_control,
2319*1da177e4SLinus Torvalds 	.get =          snd_rme96_get_attenuation_control,
2320*1da177e4SLinus Torvalds 	.put =          snd_rme96_put_attenuation_control
2321*1da177e4SLinus Torvalds },
2322*1da177e4SLinus Torvalds {
2323*1da177e4SLinus Torvalds         .iface =        SNDRV_CTL_ELEM_IFACE_MIXER,
2324*1da177e4SLinus Torvalds 	.name =         "DAC Playback Volume",
2325*1da177e4SLinus Torvalds 	.info =         snd_rme96_dac_volume_info,
2326*1da177e4SLinus Torvalds 	.get =          snd_rme96_dac_volume_get,
2327*1da177e4SLinus Torvalds 	.put =          snd_rme96_dac_volume_put
2328*1da177e4SLinus Torvalds }
2329*1da177e4SLinus Torvalds };
2330*1da177e4SLinus Torvalds 
2331*1da177e4SLinus Torvalds static int
2332*1da177e4SLinus Torvalds snd_rme96_create_switches(snd_card_t *card,
2333*1da177e4SLinus Torvalds 			  rme96_t *rme96)
2334*1da177e4SLinus Torvalds {
2335*1da177e4SLinus Torvalds 	int idx, err;
2336*1da177e4SLinus Torvalds 	snd_kcontrol_t *kctl;
2337*1da177e4SLinus Torvalds 
2338*1da177e4SLinus Torvalds 	for (idx = 0; idx < 7; idx++) {
2339*1da177e4SLinus Torvalds 		if ((err = snd_ctl_add(card, kctl = snd_ctl_new1(&snd_rme96_controls[idx], rme96))) < 0)
2340*1da177e4SLinus Torvalds 			return err;
2341*1da177e4SLinus Torvalds 		if (idx == 1)	/* IEC958 (S/PDIF) Stream */
2342*1da177e4SLinus Torvalds 			rme96->spdif_ctl = kctl;
2343*1da177e4SLinus Torvalds 	}
2344*1da177e4SLinus Torvalds 
2345*1da177e4SLinus Torvalds 	if (RME96_HAS_ANALOG_OUT(rme96)) {
2346*1da177e4SLinus Torvalds 		for (idx = 7; idx < 10; idx++)
2347*1da177e4SLinus Torvalds 			if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_rme96_controls[idx], rme96))) < 0)
2348*1da177e4SLinus Torvalds 				return err;
2349*1da177e4SLinus Torvalds 	}
2350*1da177e4SLinus Torvalds 
2351*1da177e4SLinus Torvalds 	return 0;
2352*1da177e4SLinus Torvalds }
2353*1da177e4SLinus Torvalds 
2354*1da177e4SLinus Torvalds /*
2355*1da177e4SLinus Torvalds  * Card initialisation
2356*1da177e4SLinus Torvalds  */
2357*1da177e4SLinus Torvalds 
2358*1da177e4SLinus Torvalds static void snd_rme96_card_free(snd_card_t *card)
2359*1da177e4SLinus Torvalds {
2360*1da177e4SLinus Torvalds 	snd_rme96_free(card->private_data);
2361*1da177e4SLinus Torvalds }
2362*1da177e4SLinus Torvalds 
2363*1da177e4SLinus Torvalds static int __devinit
2364*1da177e4SLinus Torvalds snd_rme96_probe(struct pci_dev *pci,
2365*1da177e4SLinus Torvalds 		const struct pci_device_id *pci_id)
2366*1da177e4SLinus Torvalds {
2367*1da177e4SLinus Torvalds 	static int dev;
2368*1da177e4SLinus Torvalds 	rme96_t *rme96;
2369*1da177e4SLinus Torvalds 	snd_card_t *card;
2370*1da177e4SLinus Torvalds 	int err;
2371*1da177e4SLinus Torvalds 	u8 val;
2372*1da177e4SLinus Torvalds 
2373*1da177e4SLinus Torvalds 	if (dev >= SNDRV_CARDS) {
2374*1da177e4SLinus Torvalds 		return -ENODEV;
2375*1da177e4SLinus Torvalds 	}
2376*1da177e4SLinus Torvalds 	if (!enable[dev]) {
2377*1da177e4SLinus Torvalds 		dev++;
2378*1da177e4SLinus Torvalds 		return -ENOENT;
2379*1da177e4SLinus Torvalds 	}
2380*1da177e4SLinus Torvalds 	if ((card = snd_card_new(index[dev], id[dev], THIS_MODULE,
2381*1da177e4SLinus Torvalds 				 sizeof(rme96_t))) == NULL)
2382*1da177e4SLinus Torvalds 		return -ENOMEM;
2383*1da177e4SLinus Torvalds 	card->private_free = snd_rme96_card_free;
2384*1da177e4SLinus Torvalds 	rme96 = (rme96_t *)card->private_data;
2385*1da177e4SLinus Torvalds 	rme96->card = card;
2386*1da177e4SLinus Torvalds 	rme96->pci = pci;
2387*1da177e4SLinus Torvalds 	snd_card_set_dev(card, &pci->dev);
2388*1da177e4SLinus Torvalds 	if ((err = snd_rme96_create(rme96)) < 0) {
2389*1da177e4SLinus Torvalds 		snd_card_free(card);
2390*1da177e4SLinus Torvalds 		return err;
2391*1da177e4SLinus Torvalds 	}
2392*1da177e4SLinus Torvalds 
2393*1da177e4SLinus Torvalds 	strcpy(card->driver, "Digi96");
2394*1da177e4SLinus Torvalds 	switch (rme96->pci->device) {
2395*1da177e4SLinus Torvalds 	case PCI_DEVICE_ID_DIGI96:
2396*1da177e4SLinus Torvalds 		strcpy(card->shortname, "RME Digi96");
2397*1da177e4SLinus Torvalds 		break;
2398*1da177e4SLinus Torvalds 	case PCI_DEVICE_ID_DIGI96_8:
2399*1da177e4SLinus Torvalds 		strcpy(card->shortname, "RME Digi96/8");
2400*1da177e4SLinus Torvalds 		break;
2401*1da177e4SLinus Torvalds 	case PCI_DEVICE_ID_DIGI96_8_PRO:
2402*1da177e4SLinus Torvalds 		strcpy(card->shortname, "RME Digi96/8 PRO");
2403*1da177e4SLinus Torvalds 		break;
2404*1da177e4SLinus Torvalds 	case PCI_DEVICE_ID_DIGI96_8_PAD_OR_PST:
2405*1da177e4SLinus Torvalds 		pci_read_config_byte(rme96->pci, 8, &val);
2406*1da177e4SLinus Torvalds 		if (val < 5) {
2407*1da177e4SLinus Torvalds 			strcpy(card->shortname, "RME Digi96/8 PAD");
2408*1da177e4SLinus Torvalds 		} else {
2409*1da177e4SLinus Torvalds 			strcpy(card->shortname, "RME Digi96/8 PST");
2410*1da177e4SLinus Torvalds 		}
2411*1da177e4SLinus Torvalds 		break;
2412*1da177e4SLinus Torvalds 	}
2413*1da177e4SLinus Torvalds 	sprintf(card->longname, "%s at 0x%lx, irq %d", card->shortname,
2414*1da177e4SLinus Torvalds 		rme96->port, rme96->irq);
2415*1da177e4SLinus Torvalds 
2416*1da177e4SLinus Torvalds 	if ((err = snd_card_register(card)) < 0) {
2417*1da177e4SLinus Torvalds 		snd_card_free(card);
2418*1da177e4SLinus Torvalds 		return err;
2419*1da177e4SLinus Torvalds 	}
2420*1da177e4SLinus Torvalds 	pci_set_drvdata(pci, card);
2421*1da177e4SLinus Torvalds 	dev++;
2422*1da177e4SLinus Torvalds 	return 0;
2423*1da177e4SLinus Torvalds }
2424*1da177e4SLinus Torvalds 
2425*1da177e4SLinus Torvalds static void __devexit snd_rme96_remove(struct pci_dev *pci)
2426*1da177e4SLinus Torvalds {
2427*1da177e4SLinus Torvalds 	snd_card_free(pci_get_drvdata(pci));
2428*1da177e4SLinus Torvalds 	pci_set_drvdata(pci, NULL);
2429*1da177e4SLinus Torvalds }
2430*1da177e4SLinus Torvalds 
2431*1da177e4SLinus Torvalds static struct pci_driver driver = {
2432*1da177e4SLinus Torvalds 	.name = "RME Digi96",
2433*1da177e4SLinus Torvalds 	.id_table = snd_rme96_ids,
2434*1da177e4SLinus Torvalds 	.probe = snd_rme96_probe,
2435*1da177e4SLinus Torvalds 	.remove = __devexit_p(snd_rme96_remove),
2436*1da177e4SLinus Torvalds };
2437*1da177e4SLinus Torvalds 
2438*1da177e4SLinus Torvalds static int __init alsa_card_rme96_init(void)
2439*1da177e4SLinus Torvalds {
2440*1da177e4SLinus Torvalds 	return pci_module_init(&driver);
2441*1da177e4SLinus Torvalds }
2442*1da177e4SLinus Torvalds 
2443*1da177e4SLinus Torvalds static void __exit alsa_card_rme96_exit(void)
2444*1da177e4SLinus Torvalds {
2445*1da177e4SLinus Torvalds 	pci_unregister_driver(&driver);
2446*1da177e4SLinus Torvalds }
2447*1da177e4SLinus Torvalds 
2448*1da177e4SLinus Torvalds module_init(alsa_card_rme96_init)
2449*1da177e4SLinus Torvalds module_exit(alsa_card_rme96_exit)
2450