Blame view

sound/pci/rme32.c 58.4 KB
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
  /*
   *   ALSA driver for RME Digi32, Digi32/8 and Digi32 PRO audio interfaces
   *
   *      Copyright (c) 2002-2004 Martin Langer <martin-langer@gmx.de>,
   *                              Pilo Chambert <pilo.c@wanadoo.fr>
   *
   *      Thanks to :        Anders Torger <torger@ludd.luth.se>,
   *                         Henk Hesselink <henk@anda.nl>
   *                         for writing the digi96-driver 
   *                         and RME for all informations.
   *
   *   This program is free software; you can redistribute it and/or modify
   *   it under the terms of the GNU General Public License as published by
   *   the Free Software Foundation; either version 2 of the License, or
   *   (at your option) any later version.
   *
   *   This program is distributed in the hope that it will be useful,
   *   but WITHOUT ANY WARRANTY; without even the implied warranty of
   *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   *   GNU General Public License for more details.
   *
   *   You should have received a copy of the GNU General Public License
   *   along with this program; if not, write to the Free Software
   *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
   * 
   * 
   * ****************************************************************************
   * 
   * Note #1 "Sek'd models" ................................... martin 2002-12-07
   * 
   * Identical soundcards by Sek'd were labeled:
   * RME Digi 32     = Sek'd Prodif 32
   * RME Digi 32 Pro = Sek'd Prodif 96
   * RME Digi 32/8   = Sek'd Prodif Gold
   * 
   * ****************************************************************************
   * 
   * Note #2 "full duplex mode" ............................... martin 2002-12-07
   * 
   * Full duplex doesn't work. All cards (32, 32/8, 32Pro) are working identical
   * in this mode. Rec data and play data are using the same buffer therefore. At
   * first you have got the playing bits in the buffer and then (after playing
   * them) they were overwitten by the captured sound of the CS8412/14. Both 
   * modes (play/record) are running harmonically hand in hand in the same buffer
   * and you have only one start bit plus one interrupt bit to control this 
   * paired action.
   * This is opposite to the latter rme96 where playing and capturing is totally
   * separated and so their full duplex mode is supported by alsa (using two 
   * start bits and two interrupts for two different buffers). 
   * But due to the wrong sequence of playing and capturing ALSA shows no solved
   * full duplex support for the rme32 at the moment. That's bad, but I'm not
   * able to solve it. Are you motivated enough to solve this problem now? Your
   * patch would be welcome!
   * 
   * ****************************************************************************
   *
   * "The story after the long seeking" -- tiwai
   *
   * Ok, the situation regarding the full duplex is now improved a bit.
   * In the fullduplex mode (given by the module parameter), the hardware buffer
   * is split to halves for read and write directions at the DMA pointer.
   * That is, the half above the current DMA pointer is used for write, and
   * the half below is used for read.  To mangle this strange behavior, an
   * software intermediate buffer is introduced.  This is, of course, not good
   * from the viewpoint of the data transfer efficiency.  However, this allows
   * you to use arbitrary buffer sizes, instead of the fixed I/O buffer size.
   *
   * ****************************************************************************
   */
  
  
  #include <sound/driver.h>
  #include <linux/delay.h>
  #include <linux/init.h>
  #include <linux/interrupt.h>
  #include <linux/pci.h>
  #include <linux/slab.h>
  #include <linux/moduleparam.h>
  
  #include <sound/core.h>
  #include <sound/info.h>
  #include <sound/control.h>
  #include <sound/pcm.h>
  #include <sound/pcm_params.h>
  #include <sound/pcm-indirect.h>
  #include <sound/asoundef.h>
  #include <sound/initval.h>
  
  #include <asm/io.h>
  
  static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;	/* Index 0-MAX */
  static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;	/* ID for this card */
  static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;	/* Enable this card */
  static int fullduplex[SNDRV_CARDS]; // = {[0 ... (SNDRV_CARDS - 1)] = 1};
  
  module_param_array(index, int, NULL, 0444);
  MODULE_PARM_DESC(index, "Index value for RME Digi32 soundcard.");
  module_param_array(id, charp, NULL, 0444);
  MODULE_PARM_DESC(id, "ID string for RME Digi32 soundcard.");
  module_param_array(enable, bool, NULL, 0444);
  MODULE_PARM_DESC(enable, "Enable RME Digi32 soundcard.");
  module_param_array(fullduplex, bool, NULL, 0444);
  MODULE_PARM_DESC(fullduplex, "Support full-duplex mode.");
  MODULE_AUTHOR("Martin Langer <martin-langer@gmx.de>, Pilo Chambert <pilo.c@wanadoo.fr>");
  MODULE_DESCRIPTION("RME Digi32, Digi32/8, Digi32 PRO");
  MODULE_LICENSE("GPL");
  MODULE_SUPPORTED_DEVICE("{{RME,Digi32}," "{RME,Digi32/8}," "{RME,Digi32 PRO}}");
  
  /* Defines for RME Digi32 series */
  #define RME32_SPDIF_NCHANNELS 2
  
  /* Playback and capture buffer size */
  #define RME32_BUFFER_SIZE 0x20000
  
  /* IO area size */
  #define RME32_IO_SIZE 0x30000
  
  /* IO area offsets */
  #define RME32_IO_DATA_BUFFER        0x0
  #define RME32_IO_CONTROL_REGISTER   0x20000
  #define RME32_IO_GET_POS            0x20000
  #define RME32_IO_CONFIRM_ACTION_IRQ 0x20004
  #define RME32_IO_RESET_POS          0x20100
  
  /* Write control register bits */
  #define RME32_WCR_START     (1 << 0)    /* startbit */
  #define RME32_WCR_MONO      (1 << 1)    /* 0=stereo, 1=mono
                                             Setting the whole card to mono
                                             doesn't seem to be very useful.
                                             A software-solution can handle 
                                             full-duplex with one direction in
                                             stereo and the other way in mono. 
                                             So, the hardware should work all 
                                             the time in stereo! */
  #define RME32_WCR_MODE24    (1 << 2)    /* 0=16bit, 1=32bit */
  #define RME32_WCR_SEL       (1 << 3)    /* 0=input on output, 1=normal playback/capture */
  #define RME32_WCR_FREQ_0    (1 << 4)    /* frequency (play) */
  #define RME32_WCR_FREQ_1    (1 << 5)
  #define RME32_WCR_INP_0     (1 << 6)    /* input switch */
  #define RME32_WCR_INP_1     (1 << 7)
  #define RME32_WCR_RESET     (1 << 8)    /* Reset address */
  #define RME32_WCR_MUTE      (1 << 9)    /* digital mute for output */
  #define RME32_WCR_PRO       (1 << 10)   /* 1=professional, 0=consumer */
  #define RME32_WCR_DS_BM     (1 << 11)	/* 1=DoubleSpeed (only PRO-Version); 1=BlockMode (only Adat-Version) */
  #define RME32_WCR_ADAT      (1 << 12)	/* Adat Mode (only Adat-Version) */
  #define RME32_WCR_AUTOSYNC  (1 << 13)   /* AutoSync */
  #define RME32_WCR_PD        (1 << 14)	/* DAC Reset (only PRO-Version) */
  #define RME32_WCR_EMP       (1 << 15)	/* 1=Emphasis on (only PRO-Version) */
  
  #define RME32_WCR_BITPOS_FREQ_0 4
  #define RME32_WCR_BITPOS_FREQ_1 5
  #define RME32_WCR_BITPOS_INP_0 6
  #define RME32_WCR_BITPOS_INP_1 7
  
  /* Read control register bits */
  #define RME32_RCR_AUDIO_ADDR_MASK 0x1ffff
  #define RME32_RCR_LOCK      (1 << 23)   /* 1=locked, 0=not locked */
  #define RME32_RCR_ERF       (1 << 26)   /* 1=Error, 0=no Error */
  #define RME32_RCR_FREQ_0    (1 << 27)   /* CS841x frequency (record) */
  #define RME32_RCR_FREQ_1    (1 << 28)
  #define RME32_RCR_FREQ_2    (1 << 29)
  #define RME32_RCR_KMODE     (1 << 30)   /* card mode: 1=PLL, 0=quartz */
  #define RME32_RCR_IRQ       (1 << 31)   /* interrupt */
  
  #define RME32_RCR_BITPOS_F0 27
  #define RME32_RCR_BITPOS_F1 28
  #define RME32_RCR_BITPOS_F2 29
  
  /* Input types */
  #define RME32_INPUT_OPTICAL 0
  #define RME32_INPUT_COAXIAL 1
  #define RME32_INPUT_INTERNAL 2
  #define RME32_INPUT_XLR 3
  
  /* Clock modes */
  #define RME32_CLOCKMODE_SLAVE 0
  #define RME32_CLOCKMODE_MASTER_32 1
  #define RME32_CLOCKMODE_MASTER_44 2
  #define RME32_CLOCKMODE_MASTER_48 3
  
  /* Block sizes in bytes */
  #define RME32_BLOCK_SIZE 8192
  
  /* Software intermediate buffer (max) size */
  #define RME32_MID_BUFFER_SIZE (1024*1024)
  
  /* Hardware revisions */
  #define RME32_32_REVISION 192
  #define RME32_328_REVISION_OLD 100
  #define RME32_328_REVISION_NEW 101
  #define RME32_PRO_REVISION_WITH_8412 192
  #define RME32_PRO_REVISION_WITH_8414 150
017ce8023   Takashi Iwai   [ALSA] Remove xxx...
193
  struct rme32 {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
194
195
196
197
198
199
200
201
202
203
204
  	spinlock_t lock;
  	int irq;
  	unsigned long port;
  	void __iomem *iobase;
  
  	u32 wcreg;		/* cached write control register value */
  	u32 wcreg_spdif;	/* S/PDIF setup */
  	u32 wcreg_spdif_stream;	/* S/PDIF setup (temporary) */
  	u32 rcreg;		/* cached read control register value */
  
  	u8 rev;			/* card revision number */
017ce8023   Takashi Iwai   [ALSA] Remove xxx...
205
206
  	struct snd_pcm_substream *playback_substream;
  	struct snd_pcm_substream *capture_substream;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
207
208
209
210
211
212
213
214
215
  
  	int playback_frlog;	/* log2 of framesize */
  	int capture_frlog;
  
  	size_t playback_periodsize;	/* in bytes, zero if not used */
  	size_t capture_periodsize;	/* in bytes, zero if not used */
  
  	unsigned int fullduplex_mode;
  	int running;
017ce8023   Takashi Iwai   [ALSA] Remove xxx...
216
217
  	struct snd_pcm_indirect playback_pcm;
  	struct snd_pcm_indirect capture_pcm;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
218

017ce8023   Takashi Iwai   [ALSA] Remove xxx...
219
220
221
  	struct snd_card *card;
  	struct snd_pcm *spdif_pcm;
  	struct snd_pcm *adat_pcm;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
222
  	struct pci_dev *pci;
017ce8023   Takashi Iwai   [ALSA] Remove xxx...
223
224
  	struct snd_kcontrol *spdif_ctl;
  };
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
225

f40b68903   Takashi Iwai   [ALSA] Fix sectio...
226
  static struct pci_device_id snd_rme32_ids[] = {
8b7fc4214   Roland Dreier   [PATCH] add PCI I...
227
  	{PCI_VENDOR_ID_XILINX_RME, PCI_DEVICE_ID_RME_DIGI32,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
228
  	 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0,},
8b7fc4214   Roland Dreier   [PATCH] add PCI I...
229
  	{PCI_VENDOR_ID_XILINX_RME, PCI_DEVICE_ID_RME_DIGI32_8,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
230
  	 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0,},
8b7fc4214   Roland Dreier   [PATCH] add PCI I...
231
  	{PCI_VENDOR_ID_XILINX_RME, PCI_DEVICE_ID_RME_DIGI32_PRO,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
232
233
234
235
236
237
238
  	 PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0,},
  	{0,}
  };
  
  MODULE_DEVICE_TABLE(pci, snd_rme32_ids);
  
  #define RME32_ISWORKING(rme32) ((rme32)->wcreg & RME32_WCR_START)
8b7fc4214   Roland Dreier   [PATCH] add PCI I...
239
  #define RME32_PRO_WITH_8414(rme32) ((rme32)->pci->device == PCI_DEVICE_ID_RME_DIGI32_PRO && (rme32)->rev == RME32_PRO_REVISION_WITH_8414)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
240

017ce8023   Takashi Iwai   [ALSA] Remove xxx...
241
  static int snd_rme32_playback_prepare(struct snd_pcm_substream *substream);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
242

017ce8023   Takashi Iwai   [ALSA] Remove xxx...
243
  static int snd_rme32_capture_prepare(struct snd_pcm_substream *substream);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
244

017ce8023   Takashi Iwai   [ALSA] Remove xxx...
245
  static int snd_rme32_pcm_trigger(struct snd_pcm_substream *substream, int cmd);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
246

017ce8023   Takashi Iwai   [ALSA] Remove xxx...
247
  static void snd_rme32_proc_init(struct rme32 * rme32);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
248

017ce8023   Takashi Iwai   [ALSA] Remove xxx...
249
  static int snd_rme32_create_switches(struct snd_card *card, struct rme32 * rme32);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
250

017ce8023   Takashi Iwai   [ALSA] Remove xxx...
251
  static inline unsigned int snd_rme32_pcm_byteptr(struct rme32 * rme32)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
  {
  	return (readl(rme32->iobase + RME32_IO_GET_POS)
  		& RME32_RCR_AUDIO_ADDR_MASK);
  }
  
  static int snd_rme32_ratecode(int rate)
  {
  	switch (rate) {
  	case 32000: return SNDRV_PCM_RATE_32000;
  	case 44100: return SNDRV_PCM_RATE_44100;
  	case 48000: return SNDRV_PCM_RATE_48000;
  	case 64000: return SNDRV_PCM_RATE_64000;
  	case 88200: return SNDRV_PCM_RATE_88200;
  	case 96000: return SNDRV_PCM_RATE_96000;
  	}
  	return 0;
  }
  
  /* silence callback for halfduplex mode */
017ce8023   Takashi Iwai   [ALSA] Remove xxx...
271
  static int snd_rme32_playback_silence(struct snd_pcm_substream *substream, int channel,	/* not used (interleaved data) */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
272
273
274
  				      snd_pcm_uframes_t pos,
  				      snd_pcm_uframes_t count)
  {
017ce8023   Takashi Iwai   [ALSA] Remove xxx...
275
  	struct rme32 *rme32 = snd_pcm_substream_chip(substream);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
276
277
278
279
280
281
282
  	count <<= rme32->playback_frlog;
  	pos <<= rme32->playback_frlog;
  	memset_io(rme32->iobase + RME32_IO_DATA_BUFFER + pos, 0, count);
  	return 0;
  }
  
  /* copy callback for halfduplex mode */
017ce8023   Takashi Iwai   [ALSA] Remove xxx...
283
  static int snd_rme32_playback_copy(struct snd_pcm_substream *substream, int channel,	/* not used (interleaved data) */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
284
285
286
  				   snd_pcm_uframes_t pos,
  				   void __user *src, snd_pcm_uframes_t count)
  {
017ce8023   Takashi Iwai   [ALSA] Remove xxx...
287
  	struct rme32 *rme32 = snd_pcm_substream_chip(substream);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
288
289
290
291
292
293
294
295
296
  	count <<= rme32->playback_frlog;
  	pos <<= rme32->playback_frlog;
  	if (copy_from_user_toio(rme32->iobase + RME32_IO_DATA_BUFFER + pos,
  			    src, count))
  		return -EFAULT;
  	return 0;
  }
  
  /* copy callback for halfduplex mode */
017ce8023   Takashi Iwai   [ALSA] Remove xxx...
297
  static int snd_rme32_capture_copy(struct snd_pcm_substream *substream, int channel,	/* not used (interleaved data) */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
298
299
300
  				  snd_pcm_uframes_t pos,
  				  void __user *dst, snd_pcm_uframes_t count)
  {
017ce8023   Takashi Iwai   [ALSA] Remove xxx...
301
  	struct rme32 *rme32 = snd_pcm_substream_chip(substream);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
302
303
304
305
306
307
308
309
310
311
  	count <<= rme32->capture_frlog;
  	pos <<= rme32->capture_frlog;
  	if (copy_to_user_fromio(dst,
  			    rme32->iobase + RME32_IO_DATA_BUFFER + pos,
  			    count))
  		return -EFAULT;
  	return 0;
  }
  
  /*
7f927fcc2   Alexey Dobriyan   [PATCH] Typo fixes
312
   * SPDIF I/O capabilities (half-duplex mode)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
313
   */
017ce8023   Takashi Iwai   [ALSA] Remove xxx...
314
  static struct snd_pcm_hardware snd_rme32_spdif_info = {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
  	.info =		(SNDRV_PCM_INFO_MMAP_IOMEM |
  			 SNDRV_PCM_INFO_MMAP_VALID |
  			 SNDRV_PCM_INFO_INTERLEAVED | 
  			 SNDRV_PCM_INFO_PAUSE |
  			 SNDRV_PCM_INFO_SYNC_START),
  	.formats =	(SNDRV_PCM_FMTBIT_S16_LE | 
  			 SNDRV_PCM_FMTBIT_S32_LE),
  	.rates =	(SNDRV_PCM_RATE_32000 |
  			 SNDRV_PCM_RATE_44100 | 
  			 SNDRV_PCM_RATE_48000),
  	.rate_min =	32000,
  	.rate_max =	48000,
  	.channels_min =	2,
  	.channels_max =	2,
  	.buffer_bytes_max = RME32_BUFFER_SIZE,
  	.period_bytes_min = RME32_BLOCK_SIZE,
  	.period_bytes_max = RME32_BLOCK_SIZE,
  	.periods_min =	RME32_BUFFER_SIZE / RME32_BLOCK_SIZE,
  	.periods_max =	RME32_BUFFER_SIZE / RME32_BLOCK_SIZE,
  	.fifo_size =	0,
  };
  
  /*
7f927fcc2   Alexey Dobriyan   [PATCH] Typo fixes
338
   * ADAT I/O capabilities (half-duplex mode)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
339
   */
017ce8023   Takashi Iwai   [ALSA] Remove xxx...
340
  static struct snd_pcm_hardware snd_rme32_adat_info =
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
  {
  	.info =		     (SNDRV_PCM_INFO_MMAP_IOMEM |
  			      SNDRV_PCM_INFO_MMAP_VALID |
  			      SNDRV_PCM_INFO_INTERLEAVED |
  			      SNDRV_PCM_INFO_PAUSE |
  			      SNDRV_PCM_INFO_SYNC_START),
  	.formats=            SNDRV_PCM_FMTBIT_S16_LE,
  	.rates =             (SNDRV_PCM_RATE_44100 | 
  			      SNDRV_PCM_RATE_48000),
  	.rate_min =          44100,
  	.rate_max =          48000,
  	.channels_min =      8,
  	.channels_max =	     8,
  	.buffer_bytes_max =  RME32_BUFFER_SIZE,
  	.period_bytes_min =  RME32_BLOCK_SIZE,
  	.period_bytes_max =  RME32_BLOCK_SIZE,
  	.periods_min =	    RME32_BUFFER_SIZE / RME32_BLOCK_SIZE,
  	.periods_max =	    RME32_BUFFER_SIZE / RME32_BLOCK_SIZE,
  	.fifo_size =	    0,
  };
  
  /*
7f927fcc2   Alexey Dobriyan   [PATCH] Typo fixes
363
   * SPDIF I/O capabilities (full-duplex mode)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
364
   */
017ce8023   Takashi Iwai   [ALSA] Remove xxx...
365
  static struct snd_pcm_hardware snd_rme32_spdif_fd_info = {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
  	.info =		(SNDRV_PCM_INFO_MMAP |
  			 SNDRV_PCM_INFO_MMAP_VALID |
  			 SNDRV_PCM_INFO_INTERLEAVED | 
  			 SNDRV_PCM_INFO_PAUSE |
  			 SNDRV_PCM_INFO_SYNC_START),
  	.formats =	(SNDRV_PCM_FMTBIT_S16_LE | 
  			 SNDRV_PCM_FMTBIT_S32_LE),
  	.rates =	(SNDRV_PCM_RATE_32000 |
  			 SNDRV_PCM_RATE_44100 | 
  			 SNDRV_PCM_RATE_48000),
  	.rate_min =	32000,
  	.rate_max =	48000,
  	.channels_min =	2,
  	.channels_max =	2,
  	.buffer_bytes_max = RME32_MID_BUFFER_SIZE,
  	.period_bytes_min = RME32_BLOCK_SIZE,
  	.period_bytes_max = RME32_BLOCK_SIZE,
  	.periods_min =	2,
  	.periods_max =	RME32_MID_BUFFER_SIZE / RME32_BLOCK_SIZE,
  	.fifo_size =	0,
  };
  
  /*
7f927fcc2   Alexey Dobriyan   [PATCH] Typo fixes
389
   * ADAT I/O capabilities (full-duplex mode)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
390
   */
017ce8023   Takashi Iwai   [ALSA] Remove xxx...
391
  static struct snd_pcm_hardware snd_rme32_adat_fd_info =
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
  {
  	.info =		     (SNDRV_PCM_INFO_MMAP |
  			      SNDRV_PCM_INFO_MMAP_VALID |
  			      SNDRV_PCM_INFO_INTERLEAVED |
  			      SNDRV_PCM_INFO_PAUSE |
  			      SNDRV_PCM_INFO_SYNC_START),
  	.formats=            SNDRV_PCM_FMTBIT_S16_LE,
  	.rates =             (SNDRV_PCM_RATE_44100 | 
  			      SNDRV_PCM_RATE_48000),
  	.rate_min =          44100,
  	.rate_max =          48000,
  	.channels_min =      8,
  	.channels_max =	     8,
  	.buffer_bytes_max =  RME32_MID_BUFFER_SIZE,
  	.period_bytes_min =  RME32_BLOCK_SIZE,
  	.period_bytes_max =  RME32_BLOCK_SIZE,
  	.periods_min =	    2,
  	.periods_max =	    RME32_MID_BUFFER_SIZE / RME32_BLOCK_SIZE,
  	.fifo_size =	    0,
  };
017ce8023   Takashi Iwai   [ALSA] Remove xxx...
412
  static void snd_rme32_reset_dac(struct rme32 *rme32)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
413
414
415
416
417
  {
          writel(rme32->wcreg | RME32_WCR_PD,
                 rme32->iobase + RME32_IO_CONTROL_REGISTER);
          writel(rme32->wcreg, rme32->iobase + RME32_IO_CONTROL_REGISTER);
  }
017ce8023   Takashi Iwai   [ALSA] Remove xxx...
418
  static int snd_rme32_playback_getrate(struct rme32 * rme32)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
  {
  	int rate;
  
  	rate = ((rme32->wcreg >> RME32_WCR_BITPOS_FREQ_0) & 1) +
  	       (((rme32->wcreg >> RME32_WCR_BITPOS_FREQ_1) & 1) << 1);
  	switch (rate) {
  	case 1:
  		rate = 32000;
  		break;
  	case 2:
  		rate = 44100;
  		break;
  	case 3:
  		rate = 48000;
  		break;
  	default:
  		return -1;
  	}
  	return (rme32->wcreg & RME32_WCR_DS_BM) ? rate << 1 : rate;
  }
017ce8023   Takashi Iwai   [ALSA] Remove xxx...
439
  static int snd_rme32_capture_getrate(struct rme32 * rme32, int *is_adat)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
  {
  	int n;
  
  	*is_adat = 0;
  	if (rme32->rcreg & RME32_RCR_LOCK) { 
                  /* ADAT rate */
                  *is_adat = 1;
  	}
  	if (rme32->rcreg & RME32_RCR_ERF) {
  		return -1;
  	}
  
          /* S/PDIF rate */
  	n = ((rme32->rcreg >> RME32_RCR_BITPOS_F0) & 1) +
  		(((rme32->rcreg >> RME32_RCR_BITPOS_F1) & 1) << 1) +
  		(((rme32->rcreg >> RME32_RCR_BITPOS_F2) & 1) << 2);
  
  	if (RME32_PRO_WITH_8414(rme32))
  		switch (n) {	/* supporting the CS8414 */
  		case 0:
  		case 1:
  		case 2:
  			return -1;
  		case 3:
  			return 96000;
  		case 4:
  			return 88200;
  		case 5:
  			return 48000;
  		case 6:
  			return 44100;
  		case 7:
  			return 32000;
  		default:
  			return -1;
  			break;
  		} 
  	else
  		switch (n) {	/* supporting the CS8412 */
  		case 0:
  			return -1;
  		case 1:
  			return 48000;
  		case 2:
  			return 44100;
  		case 3:
  			return 32000;
  		case 4:
  			return 48000;
  		case 5:
  			return 44100;
  		case 6:
  			return 44056;
  		case 7:
  			return 32000;
  		default:
  			break;
  		}
  	return -1;
  }
017ce8023   Takashi Iwai   [ALSA] Remove xxx...
500
  static int snd_rme32_playback_setrate(struct rme32 * rme32, int rate)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
  {
          int ds;
  
          ds = rme32->wcreg & RME32_WCR_DS_BM;
  	switch (rate) {
  	case 32000:
  		rme32->wcreg &= ~RME32_WCR_DS_BM;
  		rme32->wcreg = (rme32->wcreg | RME32_WCR_FREQ_0) & 
  			~RME32_WCR_FREQ_1;
  		break;
  	case 44100:
  		rme32->wcreg &= ~RME32_WCR_DS_BM;
  		rme32->wcreg = (rme32->wcreg | RME32_WCR_FREQ_1) & 
  			~RME32_WCR_FREQ_0;
  		break;
  	case 48000:
  		rme32->wcreg &= ~RME32_WCR_DS_BM;
  		rme32->wcreg = (rme32->wcreg | RME32_WCR_FREQ_0) | 
  			RME32_WCR_FREQ_1;
  		break;
  	case 64000:
8b7fc4214   Roland Dreier   [PATCH] add PCI I...
522
  		if (rme32->pci->device != PCI_DEVICE_ID_RME_DIGI32_PRO)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
523
524
525
526
527
528
  			return -EINVAL;
  		rme32->wcreg |= RME32_WCR_DS_BM;
  		rme32->wcreg = (rme32->wcreg | RME32_WCR_FREQ_0) & 
  			~RME32_WCR_FREQ_1;
  		break;
  	case 88200:
8b7fc4214   Roland Dreier   [PATCH] add PCI I...
529
  		if (rme32->pci->device != PCI_DEVICE_ID_RME_DIGI32_PRO)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
530
531
532
533
534
535
  			return -EINVAL;
  		rme32->wcreg |= RME32_WCR_DS_BM;
  		rme32->wcreg = (rme32->wcreg | RME32_WCR_FREQ_1) & 
  			~RME32_WCR_FREQ_0;
  		break;
  	case 96000:
8b7fc4214   Roland Dreier   [PATCH] add PCI I...
536
  		if (rme32->pci->device != PCI_DEVICE_ID_RME_DIGI32_PRO)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
  			return -EINVAL;
  		rme32->wcreg |= RME32_WCR_DS_BM;
  		rme32->wcreg = (rme32->wcreg | RME32_WCR_FREQ_0) | 
  			RME32_WCR_FREQ_1;
  		break;
  	default:
  		return -EINVAL;
  	}
          if ((!ds && rme32->wcreg & RME32_WCR_DS_BM) ||
              (ds && !(rme32->wcreg & RME32_WCR_DS_BM)))
          {
                  /* change to/from double-speed: reset the DAC (if available) */
                  snd_rme32_reset_dac(rme32);
          } else {
                  writel(rme32->wcreg, rme32->iobase + RME32_IO_CONTROL_REGISTER);
  	}
  	return 0;
  }
017ce8023   Takashi Iwai   [ALSA] Remove xxx...
555
  static int snd_rme32_setclockmode(struct rme32 * rme32, int mode)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
  {
  	switch (mode) {
  	case RME32_CLOCKMODE_SLAVE:
  		/* AutoSync */
  		rme32->wcreg = (rme32->wcreg & ~RME32_WCR_FREQ_0) & 
  			~RME32_WCR_FREQ_1;
  		break;
  	case RME32_CLOCKMODE_MASTER_32:
  		/* Internal 32.0kHz */
  		rme32->wcreg = (rme32->wcreg | RME32_WCR_FREQ_0) & 
  			~RME32_WCR_FREQ_1;
  		break;
  	case RME32_CLOCKMODE_MASTER_44:
  		/* Internal 44.1kHz */
  		rme32->wcreg = (rme32->wcreg & ~RME32_WCR_FREQ_0) | 
  			RME32_WCR_FREQ_1;
  		break;
  	case RME32_CLOCKMODE_MASTER_48:
  		/* Internal 48.0kHz */
  		rme32->wcreg = (rme32->wcreg | RME32_WCR_FREQ_0) | 
  			RME32_WCR_FREQ_1;
  		break;
  	default:
  		return -EINVAL;
  	}
  	writel(rme32->wcreg, rme32->iobase + RME32_IO_CONTROL_REGISTER);
  	return 0;
  }
017ce8023   Takashi Iwai   [ALSA] Remove xxx...
584
  static int snd_rme32_getclockmode(struct rme32 * rme32)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
585
586
587
588
  {
  	return ((rme32->wcreg >> RME32_WCR_BITPOS_FREQ_0) & 1) +
  	    (((rme32->wcreg >> RME32_WCR_BITPOS_FREQ_1) & 1) << 1);
  }
017ce8023   Takashi Iwai   [ALSA] Remove xxx...
589
  static int snd_rme32_setinputtype(struct rme32 * rme32, int type)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
  {
  	switch (type) {
  	case RME32_INPUT_OPTICAL:
  		rme32->wcreg = (rme32->wcreg & ~RME32_WCR_INP_0) & 
  			~RME32_WCR_INP_1;
  		break;
  	case RME32_INPUT_COAXIAL:
  		rme32->wcreg = (rme32->wcreg | RME32_WCR_INP_0) & 
  			~RME32_WCR_INP_1;
  		break;
  	case RME32_INPUT_INTERNAL:
  		rme32->wcreg = (rme32->wcreg & ~RME32_WCR_INP_0) | 
  			RME32_WCR_INP_1;
  		break;
  	case RME32_INPUT_XLR:
  		rme32->wcreg = (rme32->wcreg | RME32_WCR_INP_0) | 
  			RME32_WCR_INP_1;
  		break;
  	default:
  		return -EINVAL;
  	}
  	writel(rme32->wcreg, rme32->iobase + RME32_IO_CONTROL_REGISTER);
  	return 0;
  }
017ce8023   Takashi Iwai   [ALSA] Remove xxx...
614
  static int snd_rme32_getinputtype(struct rme32 * rme32)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
615
616
617
618
619
620
  {
  	return ((rme32->wcreg >> RME32_WCR_BITPOS_INP_0) & 1) +
  	    (((rme32->wcreg >> RME32_WCR_BITPOS_INP_1) & 1) << 1);
  }
  
  static void
017ce8023   Takashi Iwai   [ALSA] Remove xxx...
621
  snd_rme32_setframelog(struct rme32 * rme32, int n_channels, int is_playback)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
  {
  	int frlog;
  
  	if (n_channels == 2) {
  		frlog = 1;
  	} else {
  		/* assume 8 channels */
  		frlog = 3;
  	}
  	if (is_playback) {
  		frlog += (rme32->wcreg & RME32_WCR_MODE24) ? 2 : 1;
  		rme32->playback_frlog = frlog;
  	} else {
  		frlog += (rme32->wcreg & RME32_WCR_MODE24) ? 2 : 1;
  		rme32->capture_frlog = frlog;
  	}
  }
017ce8023   Takashi Iwai   [ALSA] Remove xxx...
639
  static int snd_rme32_setformat(struct rme32 * rme32, int format)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
  {
  	switch (format) {
  	case SNDRV_PCM_FORMAT_S16_LE:
  		rme32->wcreg &= ~RME32_WCR_MODE24;
  		break;
  	case SNDRV_PCM_FORMAT_S32_LE:
  		rme32->wcreg |= RME32_WCR_MODE24;
  		break;
  	default:
  		return -EINVAL;
  	}
  	writel(rme32->wcreg, rme32->iobase + RME32_IO_CONTROL_REGISTER);
  	return 0;
  }
  
  static int
017ce8023   Takashi Iwai   [ALSA] Remove xxx...
656
657
  snd_rme32_playback_hw_params(struct snd_pcm_substream *substream,
  			     struct snd_pcm_hw_params *params)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
658
659
  {
  	int err, rate, dummy;
017ce8023   Takashi Iwai   [ALSA] Remove xxx...
660
661
  	struct rme32 *rme32 = snd_pcm_substream_chip(substream);
  	struct snd_pcm_runtime *runtime = substream->runtime;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
662
663
664
665
666
667
  
  	if (rme32->fullduplex_mode) {
  		err = snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(params));
  		if (err < 0)
  			return err;
  	} else {
4d23359b7   Clemens Ladisch   [ALSA] sparse add...
668
669
  		runtime->dma_area = (void __force *)(rme32->iobase +
  						     RME32_IO_DATA_BUFFER);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
  		runtime->dma_addr = rme32->port + RME32_IO_DATA_BUFFER;
  		runtime->dma_bytes = RME32_BUFFER_SIZE;
  	}
  
  	spin_lock_irq(&rme32->lock);
  	if ((rme32->rcreg & RME32_RCR_KMODE) &&
  	    (rate = snd_rme32_capture_getrate(rme32, &dummy)) > 0) {
  		/* AutoSync */
  		if ((int)params_rate(params) != rate) {
  			spin_unlock_irq(&rme32->lock);
  			return -EIO;
  		}
  	} else if ((err = snd_rme32_playback_setrate(rme32, params_rate(params))) < 0) {
  		spin_unlock_irq(&rme32->lock);
  		return err;
  	}
  	if ((err = snd_rme32_setformat(rme32, params_format(params))) < 0) {
  		spin_unlock_irq(&rme32->lock);
  		return err;
  	}
  
  	snd_rme32_setframelog(rme32, params_channels(params), 1);
  	if (rme32->capture_periodsize != 0) {
  		if (params_period_size(params) << rme32->playback_frlog != rme32->capture_periodsize) {
  			spin_unlock_irq(&rme32->lock);
  			return -EBUSY;
  		}
  	}
  	rme32->playback_periodsize = params_period_size(params) << rme32->playback_frlog;
  	/* S/PDIF setup */
  	if ((rme32->wcreg & RME32_WCR_ADAT) == 0) {
  		rme32->wcreg &= ~(RME32_WCR_PRO | RME32_WCR_EMP);
  		rme32->wcreg |= rme32->wcreg_spdif_stream;
  		writel(rme32->wcreg, rme32->iobase + RME32_IO_CONTROL_REGISTER);
  	}
  	spin_unlock_irq(&rme32->lock);
  
  	return 0;
  }
  
  static int
017ce8023   Takashi Iwai   [ALSA] Remove xxx...
711
712
  snd_rme32_capture_hw_params(struct snd_pcm_substream *substream,
  			    struct snd_pcm_hw_params *params)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
713
714
  {
  	int err, isadat, rate;
017ce8023   Takashi Iwai   [ALSA] Remove xxx...
715
716
  	struct rme32 *rme32 = snd_pcm_substream_chip(substream);
  	struct snd_pcm_runtime *runtime = substream->runtime;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
717
718
719
720
721
722
  
  	if (rme32->fullduplex_mode) {
  		err = snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(params));
  		if (err < 0)
  			return err;
  	} else {
4d23359b7   Clemens Ladisch   [ALSA] sparse add...
723
724
  		runtime->dma_area = (void __force *)rme32->iobase +
  					RME32_IO_DATA_BUFFER;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
  		runtime->dma_addr = rme32->port + RME32_IO_DATA_BUFFER;
  		runtime->dma_bytes = RME32_BUFFER_SIZE;
  	}
  
  	spin_lock_irq(&rme32->lock);
  	/* enable AutoSync for record-preparing */
  	rme32->wcreg |= RME32_WCR_AUTOSYNC;
  	writel(rme32->wcreg, rme32->iobase + RME32_IO_CONTROL_REGISTER);
  
  	if ((err = snd_rme32_setformat(rme32, params_format(params))) < 0) {
  		spin_unlock_irq(&rme32->lock);
  		return err;
  	}
  	if ((err = snd_rme32_playback_setrate(rme32, params_rate(params))) < 0) {
  		spin_unlock_irq(&rme32->lock);
  		return err;
  	}
  	if ((rate = snd_rme32_capture_getrate(rme32, &isadat)) > 0) {
                  if ((int)params_rate(params) != rate) {
  			spin_unlock_irq(&rme32->lock);
                          return -EIO;                    
                  }
                  if ((isadat && runtime->hw.channels_min == 2) ||
                      (!isadat && runtime->hw.channels_min == 8)) {
  			spin_unlock_irq(&rme32->lock);
                          return -EIO;
                  }
  	}
  	/* AutoSync off for recording */
  	rme32->wcreg &= ~RME32_WCR_AUTOSYNC;
  	writel(rme32->wcreg, rme32->iobase + RME32_IO_CONTROL_REGISTER);
  
  	snd_rme32_setframelog(rme32, params_channels(params), 0);
  	if (rme32->playback_periodsize != 0) {
  		if (params_period_size(params) << rme32->capture_frlog !=
  		    rme32->playback_periodsize) {
  			spin_unlock_irq(&rme32->lock);
  			return -EBUSY;
  		}
  	}
  	rme32->capture_periodsize =
  	    params_period_size(params) << rme32->capture_frlog;
  	spin_unlock_irq(&rme32->lock);
  
  	return 0;
  }
017ce8023   Takashi Iwai   [ALSA] Remove xxx...
771
  static int snd_rme32_pcm_hw_free(struct snd_pcm_substream *substream)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
772
  {
017ce8023   Takashi Iwai   [ALSA] Remove xxx...
773
  	struct rme32 *rme32 = snd_pcm_substream_chip(substream);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
774
775
776
777
  	if (! rme32->fullduplex_mode)
  		return 0;
  	return snd_pcm_lib_free_pages(substream);
  }
017ce8023   Takashi Iwai   [ALSA] Remove xxx...
778
  static void snd_rme32_pcm_start(struct rme32 * rme32, int from_pause)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
779
780
781
782
783
784
785
786
  {
  	if (!from_pause) {
  		writel(0, rme32->iobase + RME32_IO_RESET_POS);
  	}
  
  	rme32->wcreg |= RME32_WCR_START;
  	writel(rme32->wcreg, rme32->iobase + RME32_IO_CONTROL_REGISTER);
  }
017ce8023   Takashi Iwai   [ALSA] Remove xxx...
787
  static void snd_rme32_pcm_stop(struct rme32 * rme32, int to_pause)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
  {
  	/*
  	 * Check if there is an unconfirmed IRQ, if so confirm it, or else
  	 * the hardware will not stop generating interrupts
  	 */
  	rme32->rcreg = readl(rme32->iobase + RME32_IO_CONTROL_REGISTER);
  	if (rme32->rcreg & RME32_RCR_IRQ) {
  		writel(0, rme32->iobase + RME32_IO_CONFIRM_ACTION_IRQ);
  	}
  	rme32->wcreg &= ~RME32_WCR_START;
  	if (rme32->wcreg & RME32_WCR_SEL)
  		rme32->wcreg |= RME32_WCR_MUTE;
  	writel(rme32->wcreg, rme32->iobase + RME32_IO_CONTROL_REGISTER);
  	if (! to_pause)
  		writel(0, rme32->iobase + RME32_IO_RESET_POS);
  }
7d12e780e   David Howells   IRQ: Maintain reg...
804
  static irqreturn_t snd_rme32_interrupt(int irq, void *dev_id)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
805
  {
017ce8023   Takashi Iwai   [ALSA] Remove xxx...
806
  	struct rme32 *rme32 = (struct rme32 *) dev_id;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
  
  	rme32->rcreg = readl(rme32->iobase + RME32_IO_CONTROL_REGISTER);
  	if (!(rme32->rcreg & RME32_RCR_IRQ)) {
  		return IRQ_NONE;
  	} else {
  		if (rme32->capture_substream) {
  			snd_pcm_period_elapsed(rme32->capture_substream);
  		}
  		if (rme32->playback_substream) {
  			snd_pcm_period_elapsed(rme32->playback_substream);
  		}
  		writel(0, rme32->iobase + RME32_IO_CONFIRM_ACTION_IRQ);
  	}
  	return IRQ_HANDLED;
  }
  
  static unsigned int period_bytes[] = { RME32_BLOCK_SIZE };
017ce8023   Takashi Iwai   [ALSA] Remove xxx...
824
  static struct snd_pcm_hw_constraint_list hw_constraints_period_bytes = {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
825
826
827
828
  	.count = ARRAY_SIZE(period_bytes),
  	.list = period_bytes,
  	.mask = 0
  };
017ce8023   Takashi Iwai   [ALSA] Remove xxx...
829
  static void snd_rme32_set_buffer_constraint(struct rme32 *rme32, struct snd_pcm_runtime *runtime)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
830
831
832
833
834
835
836
837
838
839
  {
  	if (! rme32->fullduplex_mode) {
  		snd_pcm_hw_constraint_minmax(runtime,
  					     SNDRV_PCM_HW_PARAM_BUFFER_BYTES,
  					     RME32_BUFFER_SIZE, RME32_BUFFER_SIZE);
  		snd_pcm_hw_constraint_list(runtime, 0,
  					   SNDRV_PCM_HW_PARAM_PERIOD_BYTES,
  					   &hw_constraints_period_bytes);
  	}
  }
017ce8023   Takashi Iwai   [ALSA] Remove xxx...
840
  static int snd_rme32_playback_spdif_open(struct snd_pcm_substream *substream)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
841
842
  {
  	int rate, dummy;
017ce8023   Takashi Iwai   [ALSA] Remove xxx...
843
844
  	struct rme32 *rme32 = snd_pcm_substream_chip(substream);
  	struct snd_pcm_runtime *runtime = substream->runtime;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
  
  	snd_pcm_set_sync(substream);
  
  	spin_lock_irq(&rme32->lock);
  	if (rme32->playback_substream != NULL) {
  		spin_unlock_irq(&rme32->lock);
  		return -EBUSY;
  	}
  	rme32->wcreg &= ~RME32_WCR_ADAT;
  	writel(rme32->wcreg, rme32->iobase + RME32_IO_CONTROL_REGISTER);
  	rme32->playback_substream = substream;
  	spin_unlock_irq(&rme32->lock);
  
  	if (rme32->fullduplex_mode)
  		runtime->hw = snd_rme32_spdif_fd_info;
  	else
  		runtime->hw = snd_rme32_spdif_info;
8b7fc4214   Roland Dreier   [PATCH] add PCI I...
862
  	if (rme32->pci->device == PCI_DEVICE_ID_RME_DIGI32_PRO) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
  		runtime->hw.rates |= SNDRV_PCM_RATE_64000 | SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000;
  		runtime->hw.rate_max = 96000;
  	}
  	if ((rme32->rcreg & RME32_RCR_KMODE) &&
  	    (rate = snd_rme32_capture_getrate(rme32, &dummy)) > 0) {
  		/* AutoSync */
  		runtime->hw.rates = snd_rme32_ratecode(rate);
  		runtime->hw.rate_min = rate;
  		runtime->hw.rate_max = rate;
  	}       
  
  	snd_rme32_set_buffer_constraint(rme32, runtime);
  
  	rme32->wcreg_spdif_stream = rme32->wcreg_spdif;
  	rme32->spdif_ctl->vd[0].access &= ~SNDRV_CTL_ELEM_ACCESS_INACTIVE;
  	snd_ctl_notify(rme32->card, SNDRV_CTL_EVENT_MASK_VALUE |
  		       SNDRV_CTL_EVENT_MASK_INFO, &rme32->spdif_ctl->id);
  	return 0;
  }
017ce8023   Takashi Iwai   [ALSA] Remove xxx...
882
  static int snd_rme32_capture_spdif_open(struct snd_pcm_substream *substream)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
883
884
  {
  	int isadat, rate;
017ce8023   Takashi Iwai   [ALSA] Remove xxx...
885
886
  	struct rme32 *rme32 = snd_pcm_substream_chip(substream);
  	struct snd_pcm_runtime *runtime = substream->runtime;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
  
  	snd_pcm_set_sync(substream);
  
  	spin_lock_irq(&rme32->lock);
          if (rme32->capture_substream != NULL) {
  		spin_unlock_irq(&rme32->lock);
                  return -EBUSY;
          }
  	rme32->capture_substream = substream;
  	spin_unlock_irq(&rme32->lock);
  
  	if (rme32->fullduplex_mode)
  		runtime->hw = snd_rme32_spdif_fd_info;
  	else
  		runtime->hw = snd_rme32_spdif_info;
  	if (RME32_PRO_WITH_8414(rme32)) {
  		runtime->hw.rates |= SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000;
  		runtime->hw.rate_max = 96000;
  	}
  	if ((rate = snd_rme32_capture_getrate(rme32, &isadat)) > 0) {
  		if (isadat) {
  			return -EIO;
  		}
  		runtime->hw.rates = snd_rme32_ratecode(rate);
  		runtime->hw.rate_min = rate;
  		runtime->hw.rate_max = rate;
  	}
  
  	snd_rme32_set_buffer_constraint(rme32, runtime);
  
  	return 0;
  }
  
  static int
017ce8023   Takashi Iwai   [ALSA] Remove xxx...
921
  snd_rme32_playback_adat_open(struct snd_pcm_substream *substream)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
922
923
  {
  	int rate, dummy;
017ce8023   Takashi Iwai   [ALSA] Remove xxx...
924
925
  	struct rme32 *rme32 = snd_pcm_substream_chip(substream);
  	struct snd_pcm_runtime *runtime = substream->runtime;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
  	
  	snd_pcm_set_sync(substream);
  
  	spin_lock_irq(&rme32->lock);	
          if (rme32->playback_substream != NULL) {
  		spin_unlock_irq(&rme32->lock);
                  return -EBUSY;
          }
  	rme32->wcreg |= RME32_WCR_ADAT;
  	writel(rme32->wcreg, rme32->iobase + RME32_IO_CONTROL_REGISTER);
  	rme32->playback_substream = substream;
  	spin_unlock_irq(&rme32->lock);
  	
  	if (rme32->fullduplex_mode)
  		runtime->hw = snd_rme32_adat_fd_info;
  	else
  		runtime->hw = snd_rme32_adat_info;
  	if ((rme32->rcreg & RME32_RCR_KMODE) &&
  	    (rate = snd_rme32_capture_getrate(rme32, &dummy)) > 0) {
                  /* AutoSync */
                  runtime->hw.rates = snd_rme32_ratecode(rate);
                  runtime->hw.rate_min = rate;
                  runtime->hw.rate_max = rate;
  	}        
  
  	snd_rme32_set_buffer_constraint(rme32, runtime);
  	return 0;
  }
  
  static int
017ce8023   Takashi Iwai   [ALSA] Remove xxx...
956
  snd_rme32_capture_adat_open(struct snd_pcm_substream *substream)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
957
958
  {
  	int isadat, rate;
017ce8023   Takashi Iwai   [ALSA] Remove xxx...
959
960
  	struct rme32 *rme32 = snd_pcm_substream_chip(substream);
  	struct snd_pcm_runtime *runtime = substream->runtime;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
  
  	if (rme32->fullduplex_mode)
  		runtime->hw = snd_rme32_adat_fd_info;
  	else
  		runtime->hw = snd_rme32_adat_info;
  	if ((rate = snd_rme32_capture_getrate(rme32, &isadat)) > 0) {
  		if (!isadat) {
  			return -EIO;
  		}
                  runtime->hw.rates = snd_rme32_ratecode(rate);
                  runtime->hw.rate_min = rate;
                  runtime->hw.rate_max = rate;
          }
  
  	snd_pcm_set_sync(substream);
          
  	spin_lock_irq(&rme32->lock);	
  	if (rme32->capture_substream != NULL) {
  		spin_unlock_irq(&rme32->lock);
  		return -EBUSY;
          }
  	rme32->capture_substream = substream;
  	spin_unlock_irq(&rme32->lock);
  
  	snd_rme32_set_buffer_constraint(rme32, runtime);
  	return 0;
  }
017ce8023   Takashi Iwai   [ALSA] Remove xxx...
988
  static int snd_rme32_playback_close(struct snd_pcm_substream *substream)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
989
  {
017ce8023   Takashi Iwai   [ALSA] Remove xxx...
990
  	struct rme32 *rme32 = snd_pcm_substream_chip(substream);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
  	int spdif = 0;
  
  	spin_lock_irq(&rme32->lock);
  	rme32->playback_substream = NULL;
  	rme32->playback_periodsize = 0;
  	spdif = (rme32->wcreg & RME32_WCR_ADAT) == 0;
  	spin_unlock_irq(&rme32->lock);
  	if (spdif) {
  		rme32->spdif_ctl->vd[0].access |= SNDRV_CTL_ELEM_ACCESS_INACTIVE;
  		snd_ctl_notify(rme32->card, SNDRV_CTL_EVENT_MASK_VALUE |
  			       SNDRV_CTL_EVENT_MASK_INFO,
  			       &rme32->spdif_ctl->id);
  	}
  	return 0;
  }
017ce8023   Takashi Iwai   [ALSA] Remove xxx...
1006
  static int snd_rme32_capture_close(struct snd_pcm_substream *substream)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1007
  {
017ce8023   Takashi Iwai   [ALSA] Remove xxx...
1008
  	struct rme32 *rme32 = snd_pcm_substream_chip(substream);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1009
1010
1011
1012
1013
1014
1015
  
  	spin_lock_irq(&rme32->lock);
  	rme32->capture_substream = NULL;
  	rme32->capture_periodsize = 0;
  	spin_unlock(&rme32->lock);
  	return 0;
  }
017ce8023   Takashi Iwai   [ALSA] Remove xxx...
1016
  static int snd_rme32_playback_prepare(struct snd_pcm_substream *substream)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1017
  {
017ce8023   Takashi Iwai   [ALSA] Remove xxx...
1018
  	struct rme32 *rme32 = snd_pcm_substream_chip(substream);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
  
  	spin_lock_irq(&rme32->lock);
  	if (rme32->fullduplex_mode) {
  		memset(&rme32->playback_pcm, 0, sizeof(rme32->playback_pcm));
  		rme32->playback_pcm.hw_buffer_size = RME32_BUFFER_SIZE;
  		rme32->playback_pcm.sw_buffer_size = snd_pcm_lib_buffer_bytes(substream);
  	} else {
  		writel(0, rme32->iobase + RME32_IO_RESET_POS);
  	}
  	if (rme32->wcreg & RME32_WCR_SEL)
  		rme32->wcreg &= ~RME32_WCR_MUTE;
  	writel(rme32->wcreg, rme32->iobase + RME32_IO_CONTROL_REGISTER);
  	spin_unlock_irq(&rme32->lock);
  	return 0;
  }
017ce8023   Takashi Iwai   [ALSA] Remove xxx...
1034
  static int snd_rme32_capture_prepare(struct snd_pcm_substream *substream)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1035
  {
017ce8023   Takashi Iwai   [ALSA] Remove xxx...
1036
  	struct rme32 *rme32 = snd_pcm_substream_chip(substream);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
  
  	spin_lock_irq(&rme32->lock);
  	if (rme32->fullduplex_mode) {
  		memset(&rme32->capture_pcm, 0, sizeof(rme32->capture_pcm));
  		rme32->capture_pcm.hw_buffer_size = RME32_BUFFER_SIZE;
  		rme32->capture_pcm.hw_queue_size = RME32_BUFFER_SIZE / 2;
  		rme32->capture_pcm.sw_buffer_size = snd_pcm_lib_buffer_bytes(substream);
  	} else {
  		writel(0, rme32->iobase + RME32_IO_RESET_POS);
  	}
  	spin_unlock_irq(&rme32->lock);
  	return 0;
  }
  
  static int
017ce8023   Takashi Iwai   [ALSA] Remove xxx...
1052
  snd_rme32_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1053
  {
017ce8023   Takashi Iwai   [ALSA] Remove xxx...
1054
  	struct rme32 *rme32 = snd_pcm_substream_chip(substream);
017ce8023   Takashi Iwai   [ALSA] Remove xxx...
1055
  	struct snd_pcm_substream *s;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1056
1057
  
  	spin_lock(&rme32->lock);
ef991b95a   Takashi Iwai   [ALSA] Add snd_pc...
1058
  	snd_pcm_group_for_each_entry(s, substream) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
  		if (s != rme32->playback_substream &&
  		    s != rme32->capture_substream)
  			continue;
  		switch (cmd) {
  		case SNDRV_PCM_TRIGGER_START:
  			rme32->running |= (1 << s->stream);
  			if (rme32->fullduplex_mode) {
  				/* remember the current DMA position */
  				if (s == rme32->playback_substream) {
  					rme32->playback_pcm.hw_io =
  					rme32->playback_pcm.hw_data = snd_rme32_pcm_byteptr(rme32);
  				} else {
  					rme32->capture_pcm.hw_io =
  					rme32->capture_pcm.hw_data = snd_rme32_pcm_byteptr(rme32);
  				}
  			}
  			break;
  		case SNDRV_PCM_TRIGGER_STOP:
  			rme32->running &= ~(1 << s->stream);
  			break;
  		}
  		snd_pcm_trigger_done(s, substream);
  	}
  	
  	/* prefill playback buffer */
  	if (cmd == SNDRV_PCM_TRIGGER_START && rme32->fullduplex_mode) {
ef991b95a   Takashi Iwai   [ALSA] Add snd_pc...
1085
  		snd_pcm_group_for_each_entry(s, substream) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
  			if (s == rme32->playback_substream) {
  				s->ops->ack(s);
  				break;
  			}
  		}
  	}
  
  	switch (cmd) {
  	case SNDRV_PCM_TRIGGER_START:
  		if (rme32->running && ! RME32_ISWORKING(rme32))
  			snd_rme32_pcm_start(rme32, 0);
  		break;
  	case SNDRV_PCM_TRIGGER_STOP:
  		if (! rme32->running && RME32_ISWORKING(rme32))
  			snd_rme32_pcm_stop(rme32, 0);
  		break;
  	case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
  		if (rme32->running && RME32_ISWORKING(rme32))
  			snd_rme32_pcm_stop(rme32, 1);
  		break;
  	case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
  		if (rme32->running && ! RME32_ISWORKING(rme32))
  			snd_rme32_pcm_start(rme32, 1);
  		break;
  	}
  	spin_unlock(&rme32->lock);
  	return 0;
  }
  
  /* pointer callback for halfduplex mode */
  static snd_pcm_uframes_t
017ce8023   Takashi Iwai   [ALSA] Remove xxx...
1117
  snd_rme32_playback_pointer(struct snd_pcm_substream *substream)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1118
  {
017ce8023   Takashi Iwai   [ALSA] Remove xxx...
1119
  	struct rme32 *rme32 = snd_pcm_substream_chip(substream);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1120
1121
1122
1123
  	return snd_rme32_pcm_byteptr(rme32) >> rme32->playback_frlog;
  }
  
  static snd_pcm_uframes_t
017ce8023   Takashi Iwai   [ALSA] Remove xxx...
1124
  snd_rme32_capture_pointer(struct snd_pcm_substream *substream)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1125
  {
017ce8023   Takashi Iwai   [ALSA] Remove xxx...
1126
  	struct rme32 *rme32 = snd_pcm_substream_chip(substream);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1127
1128
1129
1130
1131
  	return snd_rme32_pcm_byteptr(rme32) >> rme32->capture_frlog;
  }
  
  
  /* ack and pointer callbacks for fullduplex mode */
017ce8023   Takashi Iwai   [ALSA] Remove xxx...
1132
1133
  static void snd_rme32_pb_trans_copy(struct snd_pcm_substream *substream,
  				    struct snd_pcm_indirect *rec, size_t bytes)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1134
  {
017ce8023   Takashi Iwai   [ALSA] Remove xxx...
1135
  	struct rme32 *rme32 = snd_pcm_substream_chip(substream);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1136
1137
1138
  	memcpy_toio(rme32->iobase + RME32_IO_DATA_BUFFER + rec->hw_data,
  		    substream->runtime->dma_area + rec->sw_data, bytes);
  }
017ce8023   Takashi Iwai   [ALSA] Remove xxx...
1139
  static int snd_rme32_playback_fd_ack(struct snd_pcm_substream *substream)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1140
  {
017ce8023   Takashi Iwai   [ALSA] Remove xxx...
1141
1142
  	struct rme32 *rme32 = snd_pcm_substream_chip(substream);
  	struct snd_pcm_indirect *rec, *cprec;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
  
  	rec = &rme32->playback_pcm;
  	cprec = &rme32->capture_pcm;
  	spin_lock(&rme32->lock);
  	rec->hw_queue_size = RME32_BUFFER_SIZE;
  	if (rme32->running & (1 << SNDRV_PCM_STREAM_CAPTURE))
  		rec->hw_queue_size -= cprec->hw_ready;
  	spin_unlock(&rme32->lock);
  	snd_pcm_indirect_playback_transfer(substream, rec,
  					   snd_rme32_pb_trans_copy);
  	return 0;
  }
017ce8023   Takashi Iwai   [ALSA] Remove xxx...
1155
1156
  static void snd_rme32_cp_trans_copy(struct snd_pcm_substream *substream,
  				    struct snd_pcm_indirect *rec, size_t bytes)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1157
  {
017ce8023   Takashi Iwai   [ALSA] Remove xxx...
1158
  	struct rme32 *rme32 = snd_pcm_substream_chip(substream);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1159
1160
1161
1162
  	memcpy_fromio(substream->runtime->dma_area + rec->sw_data,
  		      rme32->iobase + RME32_IO_DATA_BUFFER + rec->hw_data,
  		      bytes);
  }
017ce8023   Takashi Iwai   [ALSA] Remove xxx...
1163
  static int snd_rme32_capture_fd_ack(struct snd_pcm_substream *substream)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1164
  {
017ce8023   Takashi Iwai   [ALSA] Remove xxx...
1165
  	struct rme32 *rme32 = snd_pcm_substream_chip(substream);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1166
1167
1168
1169
1170
1171
  	snd_pcm_indirect_capture_transfer(substream, &rme32->capture_pcm,
  					  snd_rme32_cp_trans_copy);
  	return 0;
  }
  
  static snd_pcm_uframes_t
017ce8023   Takashi Iwai   [ALSA] Remove xxx...
1172
  snd_rme32_playback_fd_pointer(struct snd_pcm_substream *substream)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1173
  {
017ce8023   Takashi Iwai   [ALSA] Remove xxx...
1174
  	struct rme32 *rme32 = snd_pcm_substream_chip(substream);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1175
1176
1177
1178
1179
  	return snd_pcm_indirect_playback_pointer(substream, &rme32->playback_pcm,
  						 snd_rme32_pcm_byteptr(rme32));
  }
  
  static snd_pcm_uframes_t
017ce8023   Takashi Iwai   [ALSA] Remove xxx...
1180
  snd_rme32_capture_fd_pointer(struct snd_pcm_substream *substream)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1181
  {
017ce8023   Takashi Iwai   [ALSA] Remove xxx...
1182
  	struct rme32 *rme32 = snd_pcm_substream_chip(substream);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1183
1184
1185
1186
1187
  	return snd_pcm_indirect_capture_pointer(substream, &rme32->capture_pcm,
  						snd_rme32_pcm_byteptr(rme32));
  }
  
  /* for halfduplex mode */
017ce8023   Takashi Iwai   [ALSA] Remove xxx...
1188
  static struct snd_pcm_ops snd_rme32_playback_spdif_ops = {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
  	.open =		snd_rme32_playback_spdif_open,
  	.close =	snd_rme32_playback_close,
  	.ioctl =	snd_pcm_lib_ioctl,
  	.hw_params =	snd_rme32_playback_hw_params,
  	.hw_free =	snd_rme32_pcm_hw_free,
  	.prepare =	snd_rme32_playback_prepare,
  	.trigger =	snd_rme32_pcm_trigger,
  	.pointer =	snd_rme32_playback_pointer,
  	.copy =		snd_rme32_playback_copy,
  	.silence =	snd_rme32_playback_silence,
  	.mmap =		snd_pcm_lib_mmap_iomem,
  };
017ce8023   Takashi Iwai   [ALSA] Remove xxx...
1201
  static struct snd_pcm_ops snd_rme32_capture_spdif_ops = {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
  	.open =		snd_rme32_capture_spdif_open,
  	.close =	snd_rme32_capture_close,
  	.ioctl =	snd_pcm_lib_ioctl,
  	.hw_params =	snd_rme32_capture_hw_params,
  	.hw_free =	snd_rme32_pcm_hw_free,
  	.prepare =	snd_rme32_capture_prepare,
  	.trigger =	snd_rme32_pcm_trigger,
  	.pointer =	snd_rme32_capture_pointer,
  	.copy =		snd_rme32_capture_copy,
  	.mmap =		snd_pcm_lib_mmap_iomem,
  };
017ce8023   Takashi Iwai   [ALSA] Remove xxx...
1213
  static struct snd_pcm_ops snd_rme32_playback_adat_ops = {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
  	.open =		snd_rme32_playback_adat_open,
  	.close =	snd_rme32_playback_close,
  	.ioctl =	snd_pcm_lib_ioctl,
  	.hw_params =	snd_rme32_playback_hw_params,
  	.prepare =	snd_rme32_playback_prepare,
  	.trigger =	snd_rme32_pcm_trigger,
  	.pointer =	snd_rme32_playback_pointer,
  	.copy =		snd_rme32_playback_copy,
  	.silence =	snd_rme32_playback_silence,
  	.mmap =		snd_pcm_lib_mmap_iomem,
  };
017ce8023   Takashi Iwai   [ALSA] Remove xxx...
1225
  static struct snd_pcm_ops snd_rme32_capture_adat_ops = {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
  	.open =		snd_rme32_capture_adat_open,
  	.close =	snd_rme32_capture_close,
  	.ioctl =	snd_pcm_lib_ioctl,
  	.hw_params =	snd_rme32_capture_hw_params,
  	.prepare =	snd_rme32_capture_prepare,
  	.trigger =	snd_rme32_pcm_trigger,
  	.pointer =	snd_rme32_capture_pointer,
  	.copy =		snd_rme32_capture_copy,
  	.mmap =		snd_pcm_lib_mmap_iomem,
  };
  
  /* for fullduplex mode */
017ce8023   Takashi Iwai   [ALSA] Remove xxx...
1238
  static struct snd_pcm_ops snd_rme32_playback_spdif_fd_ops = {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
  	.open =		snd_rme32_playback_spdif_open,
  	.close =	snd_rme32_playback_close,
  	.ioctl =	snd_pcm_lib_ioctl,
  	.hw_params =	snd_rme32_playback_hw_params,
  	.hw_free =	snd_rme32_pcm_hw_free,
  	.prepare =	snd_rme32_playback_prepare,
  	.trigger =	snd_rme32_pcm_trigger,
  	.pointer =	snd_rme32_playback_fd_pointer,
  	.ack =		snd_rme32_playback_fd_ack,
  };
017ce8023   Takashi Iwai   [ALSA] Remove xxx...
1249
  static struct snd_pcm_ops snd_rme32_capture_spdif_fd_ops = {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
  	.open =		snd_rme32_capture_spdif_open,
  	.close =	snd_rme32_capture_close,
  	.ioctl =	snd_pcm_lib_ioctl,
  	.hw_params =	snd_rme32_capture_hw_params,
  	.hw_free =	snd_rme32_pcm_hw_free,
  	.prepare =	snd_rme32_capture_prepare,
  	.trigger =	snd_rme32_pcm_trigger,
  	.pointer =	snd_rme32_capture_fd_pointer,
  	.ack =		snd_rme32_capture_fd_ack,
  };
017ce8023   Takashi Iwai   [ALSA] Remove xxx...
1260
  static struct snd_pcm_ops snd_rme32_playback_adat_fd_ops = {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1261
1262
1263
1264
1265
1266
1267
1268
1269
  	.open =		snd_rme32_playback_adat_open,
  	.close =	snd_rme32_playback_close,
  	.ioctl =	snd_pcm_lib_ioctl,
  	.hw_params =	snd_rme32_playback_hw_params,
  	.prepare =	snd_rme32_playback_prepare,
  	.trigger =	snd_rme32_pcm_trigger,
  	.pointer =	snd_rme32_playback_fd_pointer,
  	.ack =		snd_rme32_playback_fd_ack,
  };
017ce8023   Takashi Iwai   [ALSA] Remove xxx...
1270
  static struct snd_pcm_ops snd_rme32_capture_adat_fd_ops = {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
  	.open =		snd_rme32_capture_adat_open,
  	.close =	snd_rme32_capture_close,
  	.ioctl =	snd_pcm_lib_ioctl,
  	.hw_params =	snd_rme32_capture_hw_params,
  	.prepare =	snd_rme32_capture_prepare,
  	.trigger =	snd_rme32_pcm_trigger,
  	.pointer =	snd_rme32_capture_fd_pointer,
  	.ack =		snd_rme32_capture_fd_ack,
  };
  
  static void snd_rme32_free(void *private_data)
  {
017ce8023   Takashi Iwai   [ALSA] Remove xxx...
1283
  	struct rme32 *rme32 = (struct rme32 *) private_data;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
  
  	if (rme32 == NULL) {
  		return;
  	}
  	if (rme32->irq >= 0) {
  		snd_rme32_pcm_stop(rme32, 0);
  		free_irq(rme32->irq, (void *) rme32);
  		rme32->irq = -1;
  	}
  	if (rme32->iobase) {
  		iounmap(rme32->iobase);
  		rme32->iobase = NULL;
  	}
  	if (rme32->port) {
  		pci_release_regions(rme32->pci);
  		rme32->port = 0;
  	}
  	pci_disable_device(rme32->pci);
  }
017ce8023   Takashi Iwai   [ALSA] Remove xxx...
1303
  static void snd_rme32_free_spdif_pcm(struct snd_pcm *pcm)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1304
  {
017ce8023   Takashi Iwai   [ALSA] Remove xxx...
1305
  	struct rme32 *rme32 = (struct rme32 *) pcm->private_data;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1306
1307
1308
1309
  	rme32->spdif_pcm = NULL;
  }
  
  static void
017ce8023   Takashi Iwai   [ALSA] Remove xxx...
1310
  snd_rme32_free_adat_pcm(struct snd_pcm *pcm)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1311
  {
017ce8023   Takashi Iwai   [ALSA] Remove xxx...
1312
  	struct rme32 *rme32 = (struct rme32 *) pcm->private_data;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1313
1314
  	rme32->adat_pcm = NULL;
  }
017ce8023   Takashi Iwai   [ALSA] Remove xxx...
1315
  static int __devinit snd_rme32_create(struct rme32 * rme32)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
  {
  	struct pci_dev *pci = rme32->pci;
  	int err;
  
  	rme32->irq = -1;
  	spin_lock_init(&rme32->lock);
  
  	if ((err = pci_enable_device(pci)) < 0)
  		return err;
  
  	if ((err = pci_request_regions(pci, "RME32")) < 0)
  		return err;
  	rme32->port = pci_resource_start(rme32->pci, 0);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1329
  	if ((rme32->iobase = ioremap_nocache(rme32->port, RME32_IO_SIZE)) == 0) {
99b359ba1   Takashi Iwai   [ALSA] Add missin...
1330
1331
  		snd_printk(KERN_ERR "unable to remap memory region 0x%lx-0x%lx
  ",
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1332
1333
1334
  			   rme32->port, rme32->port + RME32_IO_SIZE - 1);
  		return -ENOMEM;
  	}
437a5a460   Takashi Iwai   [ALSA] Remove IRQ...
1335
1336
  	if (request_irq(pci->irq, snd_rme32_interrupt, IRQF_SHARED,
  			"RME32", rme32)) {
688956f23   Takashi Iwai   [ALSA] Fix races ...
1337
1338
1339
1340
1341
  		snd_printk(KERN_ERR "unable to grab IRQ %d
  ", pci->irq);
  		return -EBUSY;
  	}
  	rme32->irq = pci->irq;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
  	/* read the card's revision number */
  	pci_read_config_byte(pci, 8, &rme32->rev);
  
  	/* set up ALSA pcm device for S/PDIF */
  	if ((err = snd_pcm_new(rme32->card, "Digi32 IEC958", 0, 1, 1, &rme32->spdif_pcm)) < 0) {
  		return err;
  	}
  	rme32->spdif_pcm->private_data = rme32;
  	rme32->spdif_pcm->private_free = snd_rme32_free_spdif_pcm;
  	strcpy(rme32->spdif_pcm->name, "Digi32 IEC958");
  	if (rme32->fullduplex_mode) {
  		snd_pcm_set_ops(rme32->spdif_pcm, SNDRV_PCM_STREAM_PLAYBACK,
  				&snd_rme32_playback_spdif_fd_ops);
  		snd_pcm_set_ops(rme32->spdif_pcm, SNDRV_PCM_STREAM_CAPTURE,
  				&snd_rme32_capture_spdif_fd_ops);
  		snd_pcm_lib_preallocate_pages_for_all(rme32->spdif_pcm, SNDRV_DMA_TYPE_CONTINUOUS,
  						      snd_dma_continuous_data(GFP_KERNEL),
  						      0, RME32_MID_BUFFER_SIZE);
  		rme32->spdif_pcm->info_flags = SNDRV_PCM_INFO_JOINT_DUPLEX;
  	} else {
  		snd_pcm_set_ops(rme32->spdif_pcm, SNDRV_PCM_STREAM_PLAYBACK,
  				&snd_rme32_playback_spdif_ops);
  		snd_pcm_set_ops(rme32->spdif_pcm, SNDRV_PCM_STREAM_CAPTURE,
  				&snd_rme32_capture_spdif_ops);
  		rme32->spdif_pcm->info_flags = SNDRV_PCM_INFO_HALF_DUPLEX;
  	}
  
  	/* set up ALSA pcm device for ADAT */
8b7fc4214   Roland Dreier   [PATCH] add PCI I...
1370
1371
  	if ((pci->device == PCI_DEVICE_ID_RME_DIGI32) ||
  	    (pci->device == PCI_DEVICE_ID_RME_DIGI32_PRO)) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
  		/* ADAT is not available on DIGI32 and DIGI32 Pro */
  		rme32->adat_pcm = NULL;
  	}
  	else {
  		if ((err = snd_pcm_new(rme32->card, "Digi32 ADAT", 1,
  				       1, 1, &rme32->adat_pcm)) < 0)
  		{
  			return err;
  		}		
  		rme32->adat_pcm->private_data = rme32;
  		rme32->adat_pcm->private_free = snd_rme32_free_adat_pcm;
  		strcpy(rme32->adat_pcm->name, "Digi32 ADAT");
  		if (rme32->fullduplex_mode) {
  			snd_pcm_set_ops(rme32->adat_pcm, SNDRV_PCM_STREAM_PLAYBACK, 
  					&snd_rme32_playback_adat_fd_ops);
  			snd_pcm_set_ops(rme32->adat_pcm, SNDRV_PCM_STREAM_CAPTURE, 
  					&snd_rme32_capture_adat_fd_ops);
  			snd_pcm_lib_preallocate_pages_for_all(rme32->adat_pcm, SNDRV_DMA_TYPE_CONTINUOUS,
  							      snd_dma_continuous_data(GFP_KERNEL),
  							      0, RME32_MID_BUFFER_SIZE);
  			rme32->adat_pcm->info_flags = SNDRV_PCM_INFO_JOINT_DUPLEX;
  		} else {
  			snd_pcm_set_ops(rme32->adat_pcm, SNDRV_PCM_STREAM_PLAYBACK, 
  					&snd_rme32_playback_adat_ops);
  			snd_pcm_set_ops(rme32->adat_pcm, SNDRV_PCM_STREAM_CAPTURE, 
  					&snd_rme32_capture_adat_ops);
  			rme32->adat_pcm->info_flags = SNDRV_PCM_INFO_HALF_DUPLEX;
  		}
  	}
  
  
  	rme32->playback_periodsize = 0;
  	rme32->capture_periodsize = 0;
  
  	/* make sure playback/capture is stopped, if by some reason active */
  	snd_rme32_pcm_stop(rme32, 0);
  
          /* reset DAC */
          snd_rme32_reset_dac(rme32);
  
  	/* reset buffer pointer */
  	writel(0, rme32->iobase + RME32_IO_RESET_POS);
  
  	/* set default values in registers */
  	rme32->wcreg = RME32_WCR_SEL |	 /* normal playback */
  		RME32_WCR_INP_0 | /* input select */
  		RME32_WCR_MUTE;	 /* muting on */
  	writel(rme32->wcreg, rme32->iobase + RME32_IO_CONTROL_REGISTER);
  
  
  	/* init switch interface */
  	if ((err = snd_rme32_create_switches(rme32->card, rme32)) < 0) {
  		return err;
  	}
  
  	/* init proc interface */
  	snd_rme32_proc_init(rme32);
  
  	rme32->capture_substream = NULL;
  	rme32->playback_substream = NULL;
  
  	return 0;
  }
  
  /*
   * proc interface
   */
  
  static void
017ce8023   Takashi Iwai   [ALSA] Remove xxx...
1441
  snd_rme32_proc_read(struct snd_info_entry * entry, struct snd_info_buffer *buffer)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1442
1443
  {
  	int n;
017ce8023   Takashi Iwai   [ALSA] Remove xxx...
1444
  	struct rme32 *rme32 = (struct rme32 *) entry->private_data;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
  
  	rme32->rcreg = readl(rme32->iobase + RME32_IO_CONTROL_REGISTER);
  
  	snd_iprintf(buffer, rme32->card->longname);
  	snd_iprintf(buffer, " (index #%d)
  ", rme32->card->number + 1);
  
  	snd_iprintf(buffer, "
  General settings
  ");
  	if (rme32->fullduplex_mode)
  		snd_iprintf(buffer, "  Full-duplex mode
  ");
  	else
  		snd_iprintf(buffer, "  Half-duplex mode
  ");
  	if (RME32_PRO_WITH_8414(rme32)) {
  		snd_iprintf(buffer, "  receiver: CS8414
  ");
  	} else {
  		snd_iprintf(buffer, "  receiver: CS8412
  ");
  	}
  	if (rme32->wcreg & RME32_WCR_MODE24) {
  		snd_iprintf(buffer, "  format: 24 bit");
  	} else {
  		snd_iprintf(buffer, "  format: 16 bit");
  	}
  	if (rme32->wcreg & RME32_WCR_MONO) {
  		snd_iprintf(buffer, ", Mono
  ");
  	} else {
  		snd_iprintf(buffer, ", Stereo
  ");
  	}
  
  	snd_iprintf(buffer, "
  Input settings
  ");
  	switch (snd_rme32_getinputtype(rme32)) {
  	case RME32_INPUT_OPTICAL:
  		snd_iprintf(buffer, "  input: optical");
  		break;
  	case RME32_INPUT_COAXIAL:
  		snd_iprintf(buffer, "  input: coaxial");
  		break;
  	case RME32_INPUT_INTERNAL:
  		snd_iprintf(buffer, "  input: internal");
  		break;
  	case RME32_INPUT_XLR:
  		snd_iprintf(buffer, "  input: XLR");
  		break;
  	}
  	if (snd_rme32_capture_getrate(rme32, &n) < 0) {
  		snd_iprintf(buffer, "
    sample rate: no valid signal
  ");
  	} else {
  		if (n) {
  			snd_iprintf(buffer, " (8 channels)
  ");
  		} else {
  			snd_iprintf(buffer, " (2 channels)
  ");
  		}
  		snd_iprintf(buffer, "  sample rate: %d Hz
  ",
  			    snd_rme32_capture_getrate(rme32, &n));
  	}
  
  	snd_iprintf(buffer, "
  Output settings
  ");
  	if (rme32->wcreg & RME32_WCR_SEL) {
  		snd_iprintf(buffer, "  output signal: normal playback");
  	} else {
  		snd_iprintf(buffer, "  output signal: same as input");
  	}
  	if (rme32->wcreg & RME32_WCR_MUTE) {
  		snd_iprintf(buffer, " (muted)
  ");
  	} else {
  		snd_iprintf(buffer, "
  ");
  	}
  
  	/* master output frequency */
  	if (!
  	    ((!(rme32->wcreg & RME32_WCR_FREQ_0))
  	     && (!(rme32->wcreg & RME32_WCR_FREQ_1)))) {
  		snd_iprintf(buffer, "  sample rate: %d Hz
  ",
  			    snd_rme32_playback_getrate(rme32));
  	}
  	if (rme32->rcreg & RME32_RCR_KMODE) {
  		snd_iprintf(buffer, "  sample clock source: AutoSync
  ");
  	} else {
  		snd_iprintf(buffer, "  sample clock source: Internal
  ");
  	}
  	if (rme32->wcreg & RME32_WCR_PRO) {
  		snd_iprintf(buffer, "  format: AES/EBU (professional)
  ");
  	} else {
  		snd_iprintf(buffer, "  format: IEC958 (consumer)
  ");
  	}
  	if (rme32->wcreg & RME32_WCR_EMP) {
  		snd_iprintf(buffer, "  emphasis: on
  ");
  	} else {
  		snd_iprintf(buffer, "  emphasis: off
  ");
  	}
  }
017ce8023   Takashi Iwai   [ALSA] Remove xxx...
1561
  static void __devinit snd_rme32_proc_init(struct rme32 * rme32)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1562
  {
017ce8023   Takashi Iwai   [ALSA] Remove xxx...
1563
  	struct snd_info_entry *entry;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1564
1565
  
  	if (! snd_card_proc_new(rme32->card, "rme32", &entry))
bf850204a   Takashi Iwai   [ALSA] Remove unn...
1566
  		snd_info_set_text_ops(entry, rme32, snd_rme32_proc_read);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1567
1568
1569
1570
1571
1572
1573
  }
  
  /*
   * control interface
   */
  
  static int
017ce8023   Takashi Iwai   [ALSA] Remove xxx...
1574
1575
  snd_rme32_info_loopback_control(struct snd_kcontrol *kcontrol,
  				struct snd_ctl_elem_info *uinfo)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1576
1577
1578
1579
1580
1581
1582
1583
  {
  	uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
  	uinfo->count = 1;
  	uinfo->value.integer.min = 0;
  	uinfo->value.integer.max = 1;
  	return 0;
  }
  static int
017ce8023   Takashi Iwai   [ALSA] Remove xxx...
1584
1585
  snd_rme32_get_loopback_control(struct snd_kcontrol *kcontrol,
  			       struct snd_ctl_elem_value *ucontrol)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1586
  {
017ce8023   Takashi Iwai   [ALSA] Remove xxx...
1587
  	struct rme32 *rme32 = snd_kcontrol_chip(kcontrol);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1588
1589
1590
1591
1592
1593
1594
1595
  
  	spin_lock_irq(&rme32->lock);
  	ucontrol->value.integer.value[0] =
  	    rme32->wcreg & RME32_WCR_SEL ? 0 : 1;
  	spin_unlock_irq(&rme32->lock);
  	return 0;
  }
  static int
017ce8023   Takashi Iwai   [ALSA] Remove xxx...
1596
1597
  snd_rme32_put_loopback_control(struct snd_kcontrol *kcontrol,
  			       struct snd_ctl_elem_value *ucontrol)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1598
  {
017ce8023   Takashi Iwai   [ALSA] Remove xxx...
1599
  	struct rme32 *rme32 = snd_kcontrol_chip(kcontrol);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
  	unsigned int val;
  	int change;
  
  	val = ucontrol->value.integer.value[0] ? 0 : RME32_WCR_SEL;
  	spin_lock_irq(&rme32->lock);
  	val = (rme32->wcreg & ~RME32_WCR_SEL) | val;
  	change = val != rme32->wcreg;
  	if (ucontrol->value.integer.value[0])
  		val &= ~RME32_WCR_MUTE;
  	else
  		val |= RME32_WCR_MUTE;
  	rme32->wcreg = val;
  	writel(val, rme32->iobase + RME32_IO_CONTROL_REGISTER);
  	spin_unlock_irq(&rme32->lock);
  	return change;
  }
  
  static int
017ce8023   Takashi Iwai   [ALSA] Remove xxx...
1618
1619
  snd_rme32_info_inputtype_control(struct snd_kcontrol *kcontrol,
  				 struct snd_ctl_elem_info *uinfo)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1620
  {
017ce8023   Takashi Iwai   [ALSA] Remove xxx...
1621
  	struct rme32 *rme32 = snd_kcontrol_chip(kcontrol);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1622
1623
1624
1625
1626
  	static char *texts[4] = { "Optical", "Coaxial", "Internal", "XLR" };
  
  	uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
  	uinfo->count = 1;
  	switch (rme32->pci->device) {
8b7fc4214   Roland Dreier   [PATCH] add PCI I...
1627
1628
  	case PCI_DEVICE_ID_RME_DIGI32:
  	case PCI_DEVICE_ID_RME_DIGI32_8:
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1629
1630
  		uinfo->value.enumerated.items = 3;
  		break;
8b7fc4214   Roland Dreier   [PATCH] add PCI I...
1631
  	case PCI_DEVICE_ID_RME_DIGI32_PRO:
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
  		uinfo->value.enumerated.items = 4;
  		break;
  	default:
  		snd_BUG();
  		break;
  	}
  	if (uinfo->value.enumerated.item >
  	    uinfo->value.enumerated.items - 1) {
  		uinfo->value.enumerated.item =
  		    uinfo->value.enumerated.items - 1;
  	}
  	strcpy(uinfo->value.enumerated.name,
  	       texts[uinfo->value.enumerated.item]);
  	return 0;
  }
  static int
017ce8023   Takashi Iwai   [ALSA] Remove xxx...
1648
1649
  snd_rme32_get_inputtype_control(struct snd_kcontrol *kcontrol,
  				struct snd_ctl_elem_value *ucontrol)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1650
  {
017ce8023   Takashi Iwai   [ALSA] Remove xxx...
1651
  	struct rme32 *rme32 = snd_kcontrol_chip(kcontrol);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1652
1653
1654
1655
1656
1657
  	unsigned int items = 3;
  
  	spin_lock_irq(&rme32->lock);
  	ucontrol->value.enumerated.item[0] = snd_rme32_getinputtype(rme32);
  
  	switch (rme32->pci->device) {
8b7fc4214   Roland Dreier   [PATCH] add PCI I...
1658
1659
  	case PCI_DEVICE_ID_RME_DIGI32:
  	case PCI_DEVICE_ID_RME_DIGI32_8:
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1660
1661
  		items = 3;
  		break;
8b7fc4214   Roland Dreier   [PATCH] add PCI I...
1662
  	case PCI_DEVICE_ID_RME_DIGI32_PRO:
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
  		items = 4;
  		break;
  	default:
  		snd_BUG();
  		break;
  	}
  	if (ucontrol->value.enumerated.item[0] >= items) {
  		ucontrol->value.enumerated.item[0] = items - 1;
  	}
  
  	spin_unlock_irq(&rme32->lock);
  	return 0;
  }
  static int
017ce8023   Takashi Iwai   [ALSA] Remove xxx...
1677
1678
  snd_rme32_put_inputtype_control(struct snd_kcontrol *kcontrol,
  				struct snd_ctl_elem_value *ucontrol)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1679
  {
017ce8023   Takashi Iwai   [ALSA] Remove xxx...
1680
  	struct rme32 *rme32 = snd_kcontrol_chip(kcontrol);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1681
1682
1683
1684
  	unsigned int val;
  	int change, items = 3;
  
  	switch (rme32->pci->device) {
8b7fc4214   Roland Dreier   [PATCH] add PCI I...
1685
1686
  	case PCI_DEVICE_ID_RME_DIGI32:
  	case PCI_DEVICE_ID_RME_DIGI32_8:
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1687
1688
  		items = 3;
  		break;
8b7fc4214   Roland Dreier   [PATCH] add PCI I...
1689
  	case PCI_DEVICE_ID_RME_DIGI32_PRO:
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
  		items = 4;
  		break;
  	default:
  		snd_BUG();
  		break;
  	}
  	val = ucontrol->value.enumerated.item[0] % items;
  
  	spin_lock_irq(&rme32->lock);
  	change = val != (unsigned int)snd_rme32_getinputtype(rme32);
  	snd_rme32_setinputtype(rme32, val);
  	spin_unlock_irq(&rme32->lock);
  	return change;
  }
  
  static int
017ce8023   Takashi Iwai   [ALSA] Remove xxx...
1706
1707
  snd_rme32_info_clockmode_control(struct snd_kcontrol *kcontrol,
  				 struct snd_ctl_elem_info *uinfo)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
  {
  	static char *texts[4] = { "AutoSync", 
  				  "Internal 32.0kHz", 
  				  "Internal 44.1kHz", 
  				  "Internal 48.0kHz" };
  
  	uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
  	uinfo->count = 1;
  	uinfo->value.enumerated.items = 4;
  	if (uinfo->value.enumerated.item > 3) {
  		uinfo->value.enumerated.item = 3;
  	}
  	strcpy(uinfo->value.enumerated.name,
  	       texts[uinfo->value.enumerated.item]);
  	return 0;
  }
  static int
017ce8023   Takashi Iwai   [ALSA] Remove xxx...
1725
1726
  snd_rme32_get_clockmode_control(struct snd_kcontrol *kcontrol,
  				struct snd_ctl_elem_value *ucontrol)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1727
  {
017ce8023   Takashi Iwai   [ALSA] Remove xxx...
1728
  	struct rme32 *rme32 = snd_kcontrol_chip(kcontrol);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1729
1730
1731
1732
1733
1734
1735
  
  	spin_lock_irq(&rme32->lock);
  	ucontrol->value.enumerated.item[0] = snd_rme32_getclockmode(rme32);
  	spin_unlock_irq(&rme32->lock);
  	return 0;
  }
  static int
017ce8023   Takashi Iwai   [ALSA] Remove xxx...
1736
1737
  snd_rme32_put_clockmode_control(struct snd_kcontrol *kcontrol,
  				struct snd_ctl_elem_value *ucontrol)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1738
  {
017ce8023   Takashi Iwai   [ALSA] Remove xxx...
1739
  	struct rme32 *rme32 = snd_kcontrol_chip(kcontrol);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
  	unsigned int val;
  	int change;
  
  	val = ucontrol->value.enumerated.item[0] % 3;
  	spin_lock_irq(&rme32->lock);
  	change = val != (unsigned int)snd_rme32_getclockmode(rme32);
  	snd_rme32_setclockmode(rme32, val);
  	spin_unlock_irq(&rme32->lock);
  	return change;
  }
017ce8023   Takashi Iwai   [ALSA] Remove xxx...
1750
  static u32 snd_rme32_convert_from_aes(struct snd_aes_iec958 * aes)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1751
1752
1753
1754
1755
1756
1757
1758
1759
  {
  	u32 val = 0;
  	val |= (aes->status[0] & IEC958_AES0_PROFESSIONAL) ? RME32_WCR_PRO : 0;
  	if (val & RME32_WCR_PRO)
  		val |= (aes->status[0] & IEC958_AES0_PRO_EMPHASIS_5015) ? RME32_WCR_EMP : 0;
  	else
  		val |= (aes->status[0] & IEC958_AES0_CON_EMPHASIS_5015) ? RME32_WCR_EMP : 0;
  	return val;
  }
017ce8023   Takashi Iwai   [ALSA] Remove xxx...
1760
  static void snd_rme32_convert_to_aes(struct snd_aes_iec958 * aes, u32 val)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1761
1762
1763
1764
1765
1766
1767
  {
  	aes->status[0] = ((val & RME32_WCR_PRO) ? IEC958_AES0_PROFESSIONAL : 0);
  	if (val & RME32_WCR_PRO)
  		aes->status[0] |= (val & RME32_WCR_EMP) ? IEC958_AES0_PRO_EMPHASIS_5015 : 0;
  	else
  		aes->status[0] |= (val & RME32_WCR_EMP) ? IEC958_AES0_CON_EMPHASIS_5015 : 0;
  }
017ce8023   Takashi Iwai   [ALSA] Remove xxx...
1768
1769
  static int snd_rme32_control_spdif_info(struct snd_kcontrol *kcontrol,
  					struct snd_ctl_elem_info *uinfo)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1770
1771
1772
1773
1774
  {
  	uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
  	uinfo->count = 1;
  	return 0;
  }
017ce8023   Takashi Iwai   [ALSA] Remove xxx...
1775
1776
  static int snd_rme32_control_spdif_get(struct snd_kcontrol *kcontrol,
  				       struct snd_ctl_elem_value *ucontrol)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1777
  {
017ce8023   Takashi Iwai   [ALSA] Remove xxx...
1778
  	struct rme32 *rme32 = snd_kcontrol_chip(kcontrol);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1779
1780
1781
1782
1783
  
  	snd_rme32_convert_to_aes(&ucontrol->value.iec958,
  				 rme32->wcreg_spdif);
  	return 0;
  }
017ce8023   Takashi Iwai   [ALSA] Remove xxx...
1784
1785
  static int snd_rme32_control_spdif_put(struct snd_kcontrol *kcontrol,
  				       struct snd_ctl_elem_value *ucontrol)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1786
  {
017ce8023   Takashi Iwai   [ALSA] Remove xxx...
1787
  	struct rme32 *rme32 = snd_kcontrol_chip(kcontrol);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
  	int change;
  	u32 val;
  
  	val = snd_rme32_convert_from_aes(&ucontrol->value.iec958);
  	spin_lock_irq(&rme32->lock);
  	change = val != rme32->wcreg_spdif;
  	rme32->wcreg_spdif = val;
  	spin_unlock_irq(&rme32->lock);
  	return change;
  }
017ce8023   Takashi Iwai   [ALSA] Remove xxx...
1798
1799
  static int snd_rme32_control_spdif_stream_info(struct snd_kcontrol *kcontrol,
  					       struct snd_ctl_elem_info *uinfo)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1800
1801
1802
1803
1804
  {
  	uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
  	uinfo->count = 1;
  	return 0;
  }
017ce8023   Takashi Iwai   [ALSA] Remove xxx...
1805
1806
  static int snd_rme32_control_spdif_stream_get(struct snd_kcontrol *kcontrol,
  					      struct snd_ctl_elem_value *
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1807
1808
  					      ucontrol)
  {
017ce8023   Takashi Iwai   [ALSA] Remove xxx...
1809
  	struct rme32 *rme32 = snd_kcontrol_chip(kcontrol);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1810
1811
1812
1813
1814
  
  	snd_rme32_convert_to_aes(&ucontrol->value.iec958,
  				 rme32->wcreg_spdif_stream);
  	return 0;
  }
017ce8023   Takashi Iwai   [ALSA] Remove xxx...
1815
1816
  static int snd_rme32_control_spdif_stream_put(struct snd_kcontrol *kcontrol,
  					      struct snd_ctl_elem_value *
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1817
1818
  					      ucontrol)
  {
017ce8023   Takashi Iwai   [ALSA] Remove xxx...
1819
  	struct rme32 *rme32 = snd_kcontrol_chip(kcontrol);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
  	int change;
  	u32 val;
  
  	val = snd_rme32_convert_from_aes(&ucontrol->value.iec958);
  	spin_lock_irq(&rme32->lock);
  	change = val != rme32->wcreg_spdif_stream;
  	rme32->wcreg_spdif_stream = val;
  	rme32->wcreg &= ~(RME32_WCR_PRO | RME32_WCR_EMP);
  	rme32->wcreg |= val;
  	writel(rme32->wcreg, rme32->iobase + RME32_IO_CONTROL_REGISTER);
  	spin_unlock_irq(&rme32->lock);
  	return change;
  }
017ce8023   Takashi Iwai   [ALSA] Remove xxx...
1833
1834
  static int snd_rme32_control_spdif_mask_info(struct snd_kcontrol *kcontrol,
  					     struct snd_ctl_elem_info *uinfo)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1835
1836
1837
1838
1839
  {
  	uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
  	uinfo->count = 1;
  	return 0;
  }
017ce8023   Takashi Iwai   [ALSA] Remove xxx...
1840
1841
  static int snd_rme32_control_spdif_mask_get(struct snd_kcontrol *kcontrol,
  					    struct snd_ctl_elem_value *
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1842
1843
1844
1845
1846
  					    ucontrol)
  {
  	ucontrol->value.iec958.status[0] = kcontrol->private_value;
  	return 0;
  }
017ce8023   Takashi Iwai   [ALSA] Remove xxx...
1847
  static struct snd_kcontrol_new snd_rme32_controls[] = {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
  	{
  		.iface = SNDRV_CTL_ELEM_IFACE_PCM,
  		.name =	SNDRV_CTL_NAME_IEC958("", PLAYBACK, DEFAULT),
  		.info =	snd_rme32_control_spdif_info,
  		.get =	snd_rme32_control_spdif_get,
  		.put =	snd_rme32_control_spdif_put
  	},
  	{
  		.access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_INACTIVE,
  		.iface = SNDRV_CTL_ELEM_IFACE_PCM,
  		.name =	SNDRV_CTL_NAME_IEC958("", PLAYBACK, PCM_STREAM),
  		.info =	snd_rme32_control_spdif_stream_info,
  		.get =	snd_rme32_control_spdif_stream_get,
  		.put =	snd_rme32_control_spdif_stream_put
  	},
  	{
  		.access = SNDRV_CTL_ELEM_ACCESS_READ,
67ed4161f   Clemens Ladisch   [ALSA] sound - fi...
1865
  		.iface = SNDRV_CTL_ELEM_IFACE_PCM,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1866
1867
1868
1869
1870
1871
1872
  		.name =	SNDRV_CTL_NAME_IEC958("", PLAYBACK, CON_MASK),
  		.info =	snd_rme32_control_spdif_mask_info,
  		.get =	snd_rme32_control_spdif_mask_get,
  		.private_value = IEC958_AES0_PROFESSIONAL | IEC958_AES0_CON_EMPHASIS
  	},
  	{
  		.access = SNDRV_CTL_ELEM_ACCESS_READ,
67ed4161f   Clemens Ladisch   [ALSA] sound - fi...
1873
  		.iface = SNDRV_CTL_ELEM_IFACE_PCM,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
  		.name =	SNDRV_CTL_NAME_IEC958("", PLAYBACK, PRO_MASK),
  		.info =	snd_rme32_control_spdif_mask_info,
  		.get =	snd_rme32_control_spdif_mask_get,
  		.private_value = IEC958_AES0_PROFESSIONAL | IEC958_AES0_PRO_EMPHASIS
  	},
  	{
  		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  		.name =	"Input Connector",
  		.info =	snd_rme32_info_inputtype_control,
  		.get =	snd_rme32_get_inputtype_control,
  		.put =	snd_rme32_put_inputtype_control
  	},
  	{
  		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  		.name =	"Loopback Input",
  		.info =	snd_rme32_info_loopback_control,
  		.get =	snd_rme32_get_loopback_control,
  		.put =	snd_rme32_put_loopback_control
  	},
  	{
  		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  		.name =	"Sample Clock Source",
  		.info =	snd_rme32_info_clockmode_control,
  		.get =	snd_rme32_get_clockmode_control,
  		.put =	snd_rme32_put_clockmode_control
  	}
  };
017ce8023   Takashi Iwai   [ALSA] Remove xxx...
1901
  static int snd_rme32_create_switches(struct snd_card *card, struct rme32 * rme32)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1902
1903
  {
  	int idx, err;
017ce8023   Takashi Iwai   [ALSA] Remove xxx...
1904
  	struct snd_kcontrol *kctl;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
  
  	for (idx = 0; idx < (int)ARRAY_SIZE(snd_rme32_controls); idx++) {
  		if ((err = snd_ctl_add(card, kctl = snd_ctl_new1(&snd_rme32_controls[idx], rme32))) < 0)
  			return err;
  		if (idx == 1)	/* IEC958 (S/PDIF) Stream */
  			rme32->spdif_ctl = kctl;
  	}
  
  	return 0;
  }
  
  /*
   * Card initialisation
   */
017ce8023   Takashi Iwai   [ALSA] Remove xxx...
1919
  static void snd_rme32_card_free(struct snd_card *card)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1920
1921
1922
1923
1924
1925
1926
1927
  {
  	snd_rme32_free(card->private_data);
  }
  
  static int __devinit
  snd_rme32_probe(struct pci_dev *pci, const struct pci_device_id *pci_id)
  {
  	static int dev;
017ce8023   Takashi Iwai   [ALSA] Remove xxx...
1928
1929
  	struct rme32 *rme32;
  	struct snd_card *card;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
  	int err;
  
  	if (dev >= SNDRV_CARDS) {
  		return -ENODEV;
  	}
  	if (!enable[dev]) {
  		dev++;
  		return -ENOENT;
  	}
  
  	if ((card = snd_card_new(index[dev], id[dev], THIS_MODULE,
017ce8023   Takashi Iwai   [ALSA] Remove xxx...
1941
  				 sizeof(struct rme32))) == NULL)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1942
1943
  		return -ENOMEM;
  	card->private_free = snd_rme32_card_free;
017ce8023   Takashi Iwai   [ALSA] Remove xxx...
1944
  	rme32 = (struct rme32 *) card->private_data;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
  	rme32->card = card;
  	rme32->pci = pci;
  	snd_card_set_dev(card, &pci->dev);
          if (fullduplex[dev])
  		rme32->fullduplex_mode = 1;
  	if ((err = snd_rme32_create(rme32)) < 0) {
  		snd_card_free(card);
  		return err;
  	}
  
  	strcpy(card->driver, "Digi32");
  	switch (rme32->pci->device) {
8b7fc4214   Roland Dreier   [PATCH] add PCI I...
1957
  	case PCI_DEVICE_ID_RME_DIGI32:
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1958
1959
  		strcpy(card->shortname, "RME Digi32");
  		break;
8b7fc4214   Roland Dreier   [PATCH] add PCI I...
1960
  	case PCI_DEVICE_ID_RME_DIGI32_8:
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1961
1962
  		strcpy(card->shortname, "RME Digi32/8");
  		break;
8b7fc4214   Roland Dreier   [PATCH] add PCI I...
1963
  	case PCI_DEVICE_ID_RME_DIGI32_PRO:
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
  		strcpy(card->shortname, "RME Digi32 PRO");
  		break;
  	}
  	sprintf(card->longname, "%s (Rev. %d) at 0x%lx, irq %d",
  		card->shortname, rme32->rev, rme32->port, rme32->irq);
  
  	if ((err = snd_card_register(card)) < 0) {
  		snd_card_free(card);
  		return err;
  	}
  	pci_set_drvdata(pci, card);
  	dev++;
  	return 0;
  }
  
  static void __devexit snd_rme32_remove(struct pci_dev *pci)
  {
  	snd_card_free(pci_get_drvdata(pci));
  	pci_set_drvdata(pci, NULL);
  }
  
  static struct pci_driver driver = {
  	.name =		"RME Digi32",
  	.id_table =	snd_rme32_ids,
  	.probe =	snd_rme32_probe,
  	.remove =	__devexit_p(snd_rme32_remove),
  };
  
  static int __init alsa_card_rme32_init(void)
  {
01d25d460   Takashi Iwai   [ALSA] Replace pc...
1994
  	return pci_register_driver(&driver);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1995
1996
1997
1998
1999
2000
2001
2002
2003
  }
  
  static void __exit alsa_card_rme32_exit(void)
  {
  	pci_unregister_driver(&driver);
  }
  
  module_init(alsa_card_rme32_init)
  module_exit(alsa_card_rme32_exit)