3 * ALSA driver for RME Hammerfall DSP MADI audio interface(s)
5 * Copyright (c) 2003 Winfried Ritsch (IEM)
6 * code based on hdsp.c Paul Davis
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 #include <sound/driver.h>
26 #include <linux/init.h>
27 #include <linux/delay.h>
28 #include <linux/interrupt.h>
29 #include <linux/moduleparam.h>
30 #include <linux/slab.h>
31 #include <linux/pci.h>
34 #include <sound/core.h>
35 #include <sound/control.h>
36 #include <sound/pcm.h>
37 #include <sound/info.h>
38 #include <sound/asoundef.h>
39 #include <sound/rawmidi.h>
40 #include <sound/hwdep.h>
41 #include <sound/initval.h>
43 #include <sound/hdspm.h>
45 static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
46 static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
47 static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;/* Enable this card */
49 /* Disable precise pointer at start */
50 static int precise_ptr[SNDRV_CARDS];
52 /* Send all playback to line outs */
53 static int line_outs_monitor[SNDRV_CARDS];
55 /* Enable Analog Outs on Channel 63/64 by default */
56 static int enable_monitor[SNDRV_CARDS];
58 module_param_array(index, int, NULL, 0444);
59 MODULE_PARM_DESC(index, "Index value for RME HDSPM interface.");
61 module_param_array(id, charp, NULL, 0444);
62 MODULE_PARM_DESC(id, "ID string for RME HDSPM interface.");
64 module_param_array(enable, bool, NULL, 0444);
65 MODULE_PARM_DESC(enable, "Enable/disable specific HDSPM soundcards.");
67 module_param_array(precise_ptr, bool, NULL, 0444);
68 MODULE_PARM_DESC(precise_ptr, "Enable or disable precise pointer.");
70 module_param_array(line_outs_monitor, bool, NULL, 0444);
71 MODULE_PARM_DESC(line_outs_monitor,
72 "Send playback streams to analog outs by default.");
74 module_param_array(enable_monitor, bool, NULL, 0444);
75 MODULE_PARM_DESC(enable_monitor,
76 "Enable Analog Out on Channel 63/64 by default.");
79 ("Winfried Ritsch <ritsch_AT_iem.at>, Paul Davis <paul@linuxaudiosystems.com>, "
80 "Marcus Andersson, Thomas Charbonnel <thomas@undata.org>");
81 MODULE_DESCRIPTION("RME HDSPM");
82 MODULE_LICENSE("GPL");
83 MODULE_SUPPORTED_DEVICE("{{RME HDSPM-MADI}}");
85 /* --- Write registers. ---
86 These are defined as byte-offsets from the iobase value. */
88 #define HDSPM_controlRegister 64
89 #define HDSPM_interruptConfirmation 96
90 #define HDSPM_control2Reg 256 /* not in specs ???????? */
91 #define HDSPM_midiDataOut0 352 /* just believe in old code */
92 #define HDSPM_midiDataOut1 356
94 /* DMA enable for 64 channels, only Bit 0 is relevant */
95 #define HDSPM_outputEnableBase 512 /* 512-767 input DMA */
96 #define HDSPM_inputEnableBase 768 /* 768-1023 output DMA */
98 /* 16 page addresses for each of the 64 channels DMA buffer in and out
99 (each 64k=16*4k) Buffer must be 4k aligned (which is default i386 ????) */
100 #define HDSPM_pageAddressBufferOut 8192
101 #define HDSPM_pageAddressBufferIn (HDSPM_pageAddressBufferOut+64*16*4)
103 #define HDSPM_MADI_mixerBase 32768 /* 32768-65535 for 2x64x64 Fader */
105 #define HDSPM_MATRIX_MIXER_SIZE 8192 /* = 2*64*64 * 4 Byte => 32kB */
107 /* --- Read registers. ---
108 These are defined as byte-offsets from the iobase value */
109 #define HDSPM_statusRegister 0
110 #define HDSPM_statusRegister2 96
112 #define HDSPM_midiDataIn0 360
113 #define HDSPM_midiDataIn1 364
115 /* status is data bytes in MIDI-FIFO (0-128) */
116 #define HDSPM_midiStatusOut0 384
117 #define HDSPM_midiStatusOut1 388
118 #define HDSPM_midiStatusIn0 392
119 #define HDSPM_midiStatusIn1 396
122 /* the meters are regular i/o-mapped registers, but offset
123 considerably from the rest. the peak registers are reset
124 when read; the least-significant 4 bits are full-scale counters;
125 the actual peak value is in the most-significant 24 bits.
127 #define HDSPM_MADI_peakrmsbase 4096 /* 4096-8191 2x64x32Bit Meters */
129 /* --- Control Register bits --------- */
130 #define HDSPM_Start (1<<0) /* start engine */
132 #define HDSPM_Latency0 (1<<1) /* buffer size = 2^n */
133 #define HDSPM_Latency1 (1<<2) /* where n is defined */
134 #define HDSPM_Latency2 (1<<3) /* by Latency{2,1,0} */
136 #define HDSPM_ClockModeMaster (1<<4) /* 1=Master, 0=Slave/Autosync */
138 #define HDSPM_AudioInterruptEnable (1<<5) /* what do you think ? */
140 #define HDSPM_Frequency0 (1<<6) /* 0=44.1kHz/88.2kHz 1=48kHz/96kHz */
141 #define HDSPM_Frequency1 (1<<7) /* 0=32kHz/64kHz */
142 #define HDSPM_DoubleSpeed (1<<8) /* 0=normal speed, 1=double speed */
143 #define HDSPM_QuadSpeed (1<<31) /* quad speed bit, not implemented now */
145 #define HDSPM_TX_64ch (1<<10) /* Output 64channel MODE=1,
148 #define HDSPM_AutoInp (1<<11) /* Auto Input (takeover) == Safe Mode,
151 #define HDSPM_InputSelect0 (1<<14) /* Input select 0= optical, 1=coax */
152 #define HDSPM_InputSelect1 (1<<15) /* should be 0 */
154 #define HDSPM_SyncRef0 (1<<16) /* 0=WOrd, 1=MADI */
155 #define HDSPM_SyncRef1 (1<<17) /* should be 0 */
157 #define HDSPM_clr_tms (1<<19) /* clear track marker, do not use
158 AES additional bits in
159 lower 5 Audiodatabits ??? */
161 #define HDSPM_Midi0InterruptEnable (1<<22)
162 #define HDSPM_Midi1InterruptEnable (1<<23)
164 #define HDSPM_LineOut (1<<24) /* Analog Out on channel 63/64 on=1, mute=0 */
167 /* --- bit helper defines */
168 #define HDSPM_LatencyMask (HDSPM_Latency0|HDSPM_Latency1|HDSPM_Latency2)
169 #define HDSPM_FrequencyMask (HDSPM_Frequency0|HDSPM_Frequency1)
170 #define HDSPM_InputMask (HDSPM_InputSelect0|HDSPM_InputSelect1)
171 #define HDSPM_InputOptical 0
172 #define HDSPM_InputCoaxial (HDSPM_InputSelect0)
173 #define HDSPM_SyncRefMask (HDSPM_SyncRef0|HDSPM_SyncRef1)
174 #define HDSPM_SyncRef_Word 0
175 #define HDSPM_SyncRef_MADI (HDSPM_SyncRef0)
177 #define HDSPM_SYNC_FROM_WORD 0 /* Preferred sync reference */
178 #define HDSPM_SYNC_FROM_MADI 1 /* choices - used by "pref_sync_ref" */
180 #define HDSPM_Frequency32KHz HDSPM_Frequency0
181 #define HDSPM_Frequency44_1KHz HDSPM_Frequency1
182 #define HDSPM_Frequency48KHz (HDSPM_Frequency1|HDSPM_Frequency0)
183 #define HDSPM_Frequency64KHz (HDSPM_DoubleSpeed|HDSPM_Frequency0)
184 #define HDSPM_Frequency88_2KHz (HDSPM_DoubleSpeed|HDSPM_Frequency1)
185 #define HDSPM_Frequency96KHz (HDSPM_DoubleSpeed|HDSPM_Frequency1|HDSPM_Frequency0)
187 /* --- for internal discrimination */
188 #define HDSPM_CLOCK_SOURCE_AUTOSYNC 0 /* Sample Clock Sources */
189 #define HDSPM_CLOCK_SOURCE_INTERNAL_32KHZ 1
190 #define HDSPM_CLOCK_SOURCE_INTERNAL_44_1KHZ 2
191 #define HDSPM_CLOCK_SOURCE_INTERNAL_48KHZ 3
192 #define HDSPM_CLOCK_SOURCE_INTERNAL_64KHZ 4
193 #define HDSPM_CLOCK_SOURCE_INTERNAL_88_2KHZ 5
194 #define HDSPM_CLOCK_SOURCE_INTERNAL_96KHZ 6
195 #define HDSPM_CLOCK_SOURCE_INTERNAL_128KHZ 7
196 #define HDSPM_CLOCK_SOURCE_INTERNAL_176_4KHZ 8
197 #define HDSPM_CLOCK_SOURCE_INTERNAL_192KHZ 9
199 /* Synccheck Status */
200 #define HDSPM_SYNC_CHECK_NO_LOCK 0
201 #define HDSPM_SYNC_CHECK_LOCK 1
202 #define HDSPM_SYNC_CHECK_SYNC 2
204 /* AutoSync References - used by "autosync_ref" control switch */
205 #define HDSPM_AUTOSYNC_FROM_WORD 0
206 #define HDSPM_AUTOSYNC_FROM_MADI 1
207 #define HDSPM_AUTOSYNC_FROM_NONE 2
209 /* Possible sources of MADI input */
210 #define HDSPM_OPTICAL 0 /* optical */
211 #define HDSPM_COAXIAL 1 /* BNC */
213 #define hdspm_encode_latency(x) (((x)<<1) & HDSPM_LatencyMask)
214 #define hdspm_decode_latency(x) (((x) & HDSPM_LatencyMask)>>1)
216 #define hdspm_encode_in(x) (((x)&0x3)<<14)
217 #define hdspm_decode_in(x) (((x)>>14)&0x3)
219 /* --- control2 register bits --- */
220 #define HDSPM_TMS (1<<0)
221 #define HDSPM_TCK (1<<1)
222 #define HDSPM_TDI (1<<2)
223 #define HDSPM_JTAG (1<<3)
224 #define HDSPM_PWDN (1<<4)
225 #define HDSPM_PROGRAM (1<<5)
226 #define HDSPM_CONFIG_MODE_0 (1<<6)
227 #define HDSPM_CONFIG_MODE_1 (1<<7)
228 /*#define HDSPM_VERSION_BIT (1<<8) not defined any more*/
229 #define HDSPM_BIGENDIAN_MODE (1<<9)
230 #define HDSPM_RD_MULTIPLE (1<<10)
232 /* --- Status Register bits --- */
233 #define HDSPM_audioIRQPending (1<<0) /* IRQ is high and pending */
234 #define HDSPM_RX_64ch (1<<1) /* Input 64chan. MODE=1, 56chn. MODE=0 */
235 #define HDSPM_AB_int (1<<2) /* InputChannel Opt=0, Coax=1 (like inp0) */
236 #define HDSPM_madiLock (1<<3) /* MADI Locked =1, no=0 */
238 #define HDSPM_BufferPositionMask 0x000FFC0 /* Bit 6..15 : h/w buffer pointer */
239 /* since 64byte accurate last 6 bits
242 #define HDSPM_madiSync (1<<18) /* MADI is in sync */
243 #define HDSPM_DoubleSpeedStatus (1<<19) /* (input) card in double speed */
245 #define HDSPM_madiFreq0 (1<<22) /* system freq 0=error */
246 #define HDSPM_madiFreq1 (1<<23) /* 1=32, 2=44.1 3=48 */
247 #define HDSPM_madiFreq2 (1<<24) /* 4=64, 5=88.2 6=96 */
248 #define HDSPM_madiFreq3 (1<<25) /* 7=128, 8=176.4 9=192 */
250 #define HDSPM_BufferID (1<<26) /* (Double)Buffer ID toggles with Interrupt */
251 #define HDSPM_midi0IRQPending (1<<30) /* MIDI IRQ is pending */
252 #define HDSPM_midi1IRQPending (1<<31) /* and aktiv */
254 /* --- status bit helpers */
255 #define HDSPM_madiFreqMask (HDSPM_madiFreq0|HDSPM_madiFreq1|HDSPM_madiFreq2|HDSPM_madiFreq3)
256 #define HDSPM_madiFreq32 (HDSPM_madiFreq0)
257 #define HDSPM_madiFreq44_1 (HDSPM_madiFreq1)
258 #define HDSPM_madiFreq48 (HDSPM_madiFreq0|HDSPM_madiFreq1)
259 #define HDSPM_madiFreq64 (HDSPM_madiFreq2)
260 #define HDSPM_madiFreq88_2 (HDSPM_madiFreq0|HDSPM_madiFreq2)
261 #define HDSPM_madiFreq96 (HDSPM_madiFreq1|HDSPM_madiFreq2)
262 #define HDSPM_madiFreq128 (HDSPM_madiFreq0|HDSPM_madiFreq1|HDSPM_madiFreq2)
263 #define HDSPM_madiFreq176_4 (HDSPM_madiFreq3)
264 #define HDSPM_madiFreq192 (HDSPM_madiFreq3|HDSPM_madiFreq0)
266 /* Status2 Register bits */
268 #define HDSPM_version0 (1<<0) /* not realy defined but I guess */
269 #define HDSPM_version1 (1<<1) /* in former cards it was ??? */
270 #define HDSPM_version2 (1<<2)
272 #define HDSPM_wcLock (1<<3) /* Wordclock is detected and locked */
273 #define HDSPM_wcSync (1<<4) /* Wordclock is in sync with systemclock */
275 #define HDSPM_wc_freq0 (1<<5) /* input freq detected via autosync */
276 #define HDSPM_wc_freq1 (1<<6) /* 001=32, 010==44.1, 011=48, */
277 #define HDSPM_wc_freq2 (1<<7) /* 100=64, 101=88.2, 110=96, */
278 /* missing Bit for 111=128, 1000=176.4, 1001=192 */
280 #define HDSPM_SelSyncRef0 (1<<8) /* Sync Source in slave mode */
281 #define HDSPM_SelSyncRef1 (1<<9) /* 000=word, 001=MADI, */
282 #define HDSPM_SelSyncRef2 (1<<10) /* 111=no valid signal */
284 #define HDSPM_wc_valid (HDSPM_wcLock|HDSPM_wcSync)
286 #define HDSPM_wcFreqMask (HDSPM_wc_freq0|HDSPM_wc_freq1|HDSPM_wc_freq2)
287 #define HDSPM_wcFreq32 (HDSPM_wc_freq0)
288 #define HDSPM_wcFreq44_1 (HDSPM_wc_freq1)
289 #define HDSPM_wcFreq48 (HDSPM_wc_freq0|HDSPM_wc_freq1)
290 #define HDSPM_wcFreq64 (HDSPM_wc_freq2)
291 #define HDSPM_wcFreq88_2 (HDSPM_wc_freq0|HDSPM_wc_freq2)
292 #define HDSPM_wcFreq96 (HDSPM_wc_freq1|HDSPM_wc_freq2)
295 #define HDSPM_SelSyncRefMask (HDSPM_SelSyncRef0|HDSPM_SelSyncRef1|HDSPM_SelSyncRef2)
296 #define HDSPM_SelSyncRef_WORD 0
297 #define HDSPM_SelSyncRef_MADI (HDSPM_SelSyncRef0)
298 #define HDSPM_SelSyncRef_NVALID (HDSPM_SelSyncRef0|HDSPM_SelSyncRef1|HDSPM_SelSyncRef2)
301 #define UNITY_GAIN 32768 /* = 65536/2 */
302 #define MINUS_INFINITY_GAIN 0
305 #ifndef PCI_VENDOR_ID_XILINX
306 #define PCI_VENDOR_ID_XILINX 0x10ee
308 #ifndef PCI_DEVICE_ID_XILINX_HAMMERFALL_DSP
309 #define PCI_DEVICE_ID_XILINX_HAMMERFALL_DSP 0x3fc5
311 #ifndef PCI_DEVICE_ID_XILINX_HAMMERFALL_DSP_MADI
312 #define PCI_DEVICE_ID_XILINX_HAMMERFALL_DSP_MADI 0x3fc6
316 /* Number of channels for different Speed Modes */
317 #define MADI_SS_CHANNELS 64
318 #define MADI_DS_CHANNELS 32
319 #define MADI_QS_CHANNELS 16
321 /* the size of a substream (1 mono data stream) */
322 #define HDSPM_CHANNEL_BUFFER_SAMPLES (16*1024)
323 #define HDSPM_CHANNEL_BUFFER_BYTES (4*HDSPM_CHANNEL_BUFFER_SAMPLES)
325 /* the size of the area we need to allocate for DMA transfers. the
326 size is the same regardless of the number of channels, and
327 also the latency to use.
328 for one direction !!!
330 #define HDSPM_DMA_AREA_BYTES (HDSPM_MAX_CHANNELS * HDSPM_CHANNEL_BUFFER_BYTES)
331 #define HDSPM_DMA_AREA_KILOBYTES (HDSPM_DMA_AREA_BYTES/1024)
333 typedef struct _hdspm hdspm_t;
334 typedef struct _hdspm_midi hdspm_midi_t;
339 snd_rawmidi_t *rmidi;
340 snd_rawmidi_substream_t *input;
341 snd_rawmidi_substream_t *output;
342 char istimer; /* timer in use */
343 struct timer_list timer;
350 snd_pcm_substream_t *capture_substream; /* only one playback */
351 snd_pcm_substream_t *playback_substream; /* and/or capture stream */
353 char *card_name; /* for procinfo */
354 unsigned short firmware_rev; /* dont know if relevant */
356 int precise_ptr; /* use precise pointers, to be tested */
357 int monitor_outs; /* set up monitoring outs init flag */
359 u32 control_register; /* cached value */
360 u32 control2_register; /* cached value */
362 hdspm_midi_t midi[2];
363 struct tasklet_struct midi_tasklet;
366 unsigned char ss_channels; /* channels of card in single speed */
367 unsigned char ds_channels; /* Double Speed */
368 unsigned char qs_channels; /* Quad Speed */
370 unsigned char *playback_buffer; /* suitably aligned address */
371 unsigned char *capture_buffer; /* suitably aligned address */
373 pid_t capture_pid; /* process id which uses capture */
374 pid_t playback_pid; /* process id which uses capture */
375 int running; /* running status */
377 int last_external_sample_rate; /* samplerate mystic ... */
378 int last_internal_sample_rate;
379 int system_sample_rate;
381 char *channel_map; /* channel map for DS and Quadspeed */
383 int dev; /* Hardware vars... */
386 void __iomem *iobase;
388 int irq_count; /* for debug */
390 snd_card_t *card; /* one card */
391 snd_pcm_t *pcm; /* has one pcm */
392 snd_hwdep_t *hwdep; /* and a hwdep for additional ioctl */
393 struct pci_dev *pci; /* and an pci info */
396 snd_kcontrol_t *playback_mixer_ctls[HDSPM_MAX_CHANNELS]; /* fast alsa mixer */
397 snd_kcontrol_t *input_mixer_ctls[HDSPM_MAX_CHANNELS]; /* but input to much, so not used */
398 hdspm_mixer_t *mixer; /* full mixer accessable over mixer ioctl or hwdep-device */
402 /* These tables map the ALSA channels 1..N to the channels that we
403 need to use in order to find the relevant channel buffer. RME
404 refer to this kind of mapping as between "the ADAT channel and
405 the DMA channel." We index it using the logical audio channel,
406 and the value is the DMA channel (i.e. channel buffer number)
407 where the data for that channel can be read/written from/to.
410 static char channel_map_madi_ss[HDSPM_MAX_CHANNELS] = {
411 0, 1, 2, 3, 4, 5, 6, 7,
412 8, 9, 10, 11, 12, 13, 14, 15,
413 16, 17, 18, 19, 20, 21, 22, 23,
414 24, 25, 26, 27, 28, 29, 30, 31,
415 32, 33, 34, 35, 36, 37, 38, 39,
416 40, 41, 42, 43, 44, 45, 46, 47,
417 48, 49, 50, 51, 52, 53, 54, 55,
418 56, 57, 58, 59, 60, 61, 62, 63
421 static char channel_map_madi_ds[HDSPM_MAX_CHANNELS] = {
422 0, 2, 4, 6, 8, 10, 12, 14,
423 16, 18, 20, 22, 24, 26, 28, 30,
424 32, 34, 36, 38, 40, 42, 44, 46,
425 48, 50, 52, 54, 56, 58, 60, 62,
426 -1, -1, -1, -1, -1, -1, -1, -1,
427 -1, -1, -1, -1, -1, -1, -1, -1,
428 -1, -1, -1, -1, -1, -1, -1, -1,
429 -1, -1, -1, -1, -1, -1, -1, -1
432 static char channel_map_madi_qs[HDSPM_MAX_CHANNELS] = {
433 0, 4, 8, 12, 16, 20, 24, 28,
434 32, 36, 40, 44, 48, 52, 56, 60
435 -1, -1, -1, -1, -1, -1, -1, -1,
436 -1, -1, -1, -1, -1, -1, -1, -1,
437 -1, -1, -1, -1, -1, -1, -1, -1,
438 -1, -1, -1, -1, -1, -1, -1, -1,
439 -1, -1, -1, -1, -1, -1, -1, -1,
440 -1, -1, -1, -1, -1, -1, -1, -1
444 static struct pci_device_id snd_hdspm_ids[] = {
446 .vendor = PCI_VENDOR_ID_XILINX,
447 .device = PCI_DEVICE_ID_XILINX_HAMMERFALL_DSP_MADI,
448 .subvendor = PCI_ANY_ID,
449 .subdevice = PCI_ANY_ID,
456 MODULE_DEVICE_TABLE(pci, snd_hdspm_ids);
459 static int __devinit snd_hdspm_create_alsa_devices(snd_card_t * card,
461 static int __devinit snd_hdspm_create_pcm(snd_card_t * card,
464 static inline void snd_hdspm_initialize_midi_flush(hdspm_t * hdspm);
465 static int hdspm_update_simple_mixer_controls(hdspm_t * hdspm);
466 static int hdspm_autosync_ref(hdspm_t * hdspm);
467 static int snd_hdspm_set_defaults(hdspm_t * hdspm);
468 static void hdspm_set_sgbuf(hdspm_t * hdspm, struct snd_sg_buf *sgbuf,
469 unsigned int reg, int channels);
471 /* Write/read to/from HDSPM with Adresses in Bytes
472 not words but only 32Bit writes are allowed */
474 static inline void hdspm_write(hdspm_t * hdspm, unsigned int reg,
477 writel(val, hdspm->iobase + reg);
480 static inline unsigned int hdspm_read(hdspm_t * hdspm, unsigned int reg)
482 return readl(hdspm->iobase + reg);
485 /* for each output channel (chan) I have an Input (in) and Playback (pb) Fader
486 mixer is write only on hardware so we have to cache him for read
487 each fader is a u32, but uses only the first 16 bit */
489 static inline int hdspm_read_in_gain(hdspm_t * hdspm, unsigned int chan,
492 if (chan > HDSPM_MIXER_CHANNELS || in > HDSPM_MIXER_CHANNELS)
495 return hdspm->mixer->ch[chan].in[in];
498 static inline int hdspm_read_pb_gain(hdspm_t * hdspm, unsigned int chan,
501 if (chan > HDSPM_MIXER_CHANNELS || pb > HDSPM_MIXER_CHANNELS)
503 return hdspm->mixer->ch[chan].pb[pb];
506 static inline int hdspm_write_in_gain(hdspm_t * hdspm, unsigned int chan,
507 unsigned int in, unsigned short data)
509 if (chan >= HDSPM_MIXER_CHANNELS || in >= HDSPM_MIXER_CHANNELS)
513 HDSPM_MADI_mixerBase +
514 ((in + 128 * chan) * sizeof(u32)),
515 (hdspm->mixer->ch[chan].in[in] = data & 0xFFFF));
519 static inline int hdspm_write_pb_gain(hdspm_t * hdspm, unsigned int chan,
520 unsigned int pb, unsigned short data)
522 if (chan >= HDSPM_MIXER_CHANNELS || pb >= HDSPM_MIXER_CHANNELS)
526 HDSPM_MADI_mixerBase +
527 ((64 + pb + 128 * chan) * sizeof(u32)),
528 (hdspm->mixer->ch[chan].pb[pb] = data & 0xFFFF));
533 /* enable DMA for specific channels, now available for DSP-MADI */
534 static inline void snd_hdspm_enable_in(hdspm_t * hdspm, int i, int v)
536 hdspm_write(hdspm, HDSPM_inputEnableBase + (4 * i), v);
539 static inline void snd_hdspm_enable_out(hdspm_t * hdspm, int i, int v)
541 hdspm_write(hdspm, HDSPM_outputEnableBase + (4 * i), v);
544 /* check if same process is writing and reading */
545 static inline int snd_hdspm_use_is_exclusive(hdspm_t * hdspm)
550 spin_lock_irqsave(&hdspm->lock, flags);
551 if ((hdspm->playback_pid != hdspm->capture_pid) &&
552 (hdspm->playback_pid >= 0) && (hdspm->capture_pid >= 0)) {
555 spin_unlock_irqrestore(&hdspm->lock, flags);
559 /* check for external sample rate */
560 static inline int hdspm_external_sample_rate(hdspm_t * hdspm)
562 unsigned int status2 = hdspm_read(hdspm, HDSPM_statusRegister2);
563 unsigned int status = hdspm_read(hdspm, HDSPM_statusRegister);
564 unsigned int rate_bits;
567 /* if wordclock has synced freq and wordclock is valid */
568 if ((status2 & HDSPM_wcLock) != 0 &&
569 (status & HDSPM_SelSyncRef0) == 0) {
571 rate_bits = status2 & HDSPM_wcFreqMask;
577 case HDSPM_wcFreq44_1:
586 case HDSPM_wcFreq88_2:
592 /* Quadspeed Bit missing ???? */
599 /* if rate detected and Syncref is Word than have it, word has priority to MADI */
601 && (status2 & HDSPM_SelSyncRefMask) == HDSPM_SelSyncRef_WORD)
604 /* maby a madi input (which is taken if sel sync is madi) */
605 if (status & HDSPM_madiLock) {
606 rate_bits = status & HDSPM_madiFreqMask;
609 case HDSPM_madiFreq32:
612 case HDSPM_madiFreq44_1:
615 case HDSPM_madiFreq48:
618 case HDSPM_madiFreq64:
621 case HDSPM_madiFreq88_2:
624 case HDSPM_madiFreq96:
627 case HDSPM_madiFreq128:
630 case HDSPM_madiFreq176_4:
633 case HDSPM_madiFreq192:
644 /* Latency function */
645 static inline void hdspm_compute_period_size(hdspm_t * hdspm)
647 hdspm->period_bytes =
648 1 << ((hdspm_decode_latency(hdspm->control_register) + 8));
651 static snd_pcm_uframes_t hdspm_hw_pointer(hdspm_t * hdspm)
655 position = hdspm_read(hdspm, HDSPM_statusRegister);
657 if (!hdspm->precise_ptr) {
658 return (position & HDSPM_BufferID) ? (hdspm->period_bytes /
662 /* hwpointer comes in bytes and is 64Bytes accurate (by docu since PCI Burst)
663 i have experimented that it is at most 64 Byte to much for playing
664 so substraction of 64 byte should be ok for ALSA, but use it only
665 for application where you know what you do since if you come to
666 near with record pointer it can be a disaster */
668 position &= HDSPM_BufferPositionMask;
669 position = ((position - 64) % (2 * hdspm->period_bytes)) / 4;
675 static inline void hdspm_start_audio(hdspm_t * s)
677 s->control_register |= (HDSPM_AudioInterruptEnable | HDSPM_Start);
678 hdspm_write(s, HDSPM_controlRegister, s->control_register);
681 static inline void hdspm_stop_audio(hdspm_t * s)
683 s->control_register &= ~(HDSPM_Start | HDSPM_AudioInterruptEnable);
684 hdspm_write(s, HDSPM_controlRegister, s->control_register);
687 /* should I silence all or only opened ones ? doit all for first even is 4MB*/
688 static inline void hdspm_silence_playback(hdspm_t * hdspm)
691 int n = hdspm->period_bytes;
692 void *buf = hdspm->playback_buffer;
694 snd_assert(buf != NULL, return);
696 for (i = 0; i < HDSPM_MAX_CHANNELS; i++) {
698 buf += HDSPM_CHANNEL_BUFFER_BYTES;
702 static int hdspm_set_interrupt_interval(hdspm_t * s, unsigned int frames)
706 spin_lock_irq(&s->lock);
714 s->control_register &= ~HDSPM_LatencyMask;
715 s->control_register |= hdspm_encode_latency(n);
717 hdspm_write(s, HDSPM_controlRegister, s->control_register);
719 hdspm_compute_period_size(s);
721 spin_unlock_irq(&s->lock);
727 /* dummy set rate lets see what happens */
728 static int hdspm_set_rate(hdspm_t * hdspm, int rate, int called_internally)
730 int reject_if_open = 0;
735 /* ASSUMPTION: hdspm->lock is either set, or there is no need for
736 it (e.g. during module initialization).
739 if (!(hdspm->control_register & HDSPM_ClockModeMaster)) {
742 if (called_internally) {
744 /* request from ctl or card initialization
745 just make a warning an remember setting
746 for future master mode switching */
749 (KERN_WARNING "HDSPM: Warning: device is not running as a clock master.\n");
753 /* hw_param request while in AutoSync mode */
755 hdspm_external_sample_rate(hdspm);
757 if ((hdspm_autosync_ref(hdspm) ==
758 HDSPM_AUTOSYNC_FROM_NONE)) {
760 snd_printk(KERN_WARNING "HDSPM: Detected no Externel Sync \n");
763 } else if (rate != external_freq) {
766 (KERN_WARNING "HDSPM: Warning: No AutoSync source for requested rate\n");
772 current_rate = hdspm->system_sample_rate;
774 /* Changing between Singe, Double and Quad speed is not
775 allowed if any substreams are open. This is because such a change
776 causes a shift in the location of the DMA buffers and a reduction
777 in the number of available buffers.
779 Note that a similar but essentially insoluble problem exists for
780 externally-driven rate changes. All we can do is to flag rate
781 changes in the read/write routines.
786 if (current_rate > 48000) {
789 rate_bits = HDSPM_Frequency32KHz;
792 if (current_rate > 48000) {
795 rate_bits = HDSPM_Frequency44_1KHz;
798 if (current_rate > 48000) {
801 rate_bits = HDSPM_Frequency48KHz;
804 if (current_rate <= 48000) {
807 rate_bits = HDSPM_Frequency64KHz;
810 if (current_rate <= 48000) {
813 rate_bits = HDSPM_Frequency88_2KHz;
816 if (current_rate <= 48000) {
819 rate_bits = HDSPM_Frequency96KHz;
826 && (hdspm->capture_pid >= 0 || hdspm->playback_pid >= 0)) {
828 (KERN_ERR "HDSPM: cannot change between single- and double-speed mode (capture PID = %d, playback PID = %d)\n",
829 hdspm->capture_pid, hdspm->playback_pid);
833 hdspm->control_register &= ~HDSPM_FrequencyMask;
834 hdspm->control_register |= rate_bits;
835 hdspm_write(hdspm, HDSPM_controlRegister, hdspm->control_register);
838 hdspm->channel_map = channel_map_madi_qs;
839 else if (rate > 48000)
840 hdspm->channel_map = channel_map_madi_ds;
842 hdspm->channel_map = channel_map_madi_ss;
844 hdspm->system_sample_rate = rate;
852 /* mainly for init to 0 on load */
853 static void all_in_all_mixer(hdspm_t * hdspm, int sgain)
857 (sgain > UNITY_GAIN) ? UNITY_GAIN : (sgain < 0) ? 0 : sgain;
859 for (i = 0; i < HDSPM_MIXER_CHANNELS; i++)
860 for (j = 0; j < HDSPM_MIXER_CHANNELS; j++) {
861 hdspm_write_in_gain(hdspm, i, j, gain);
862 hdspm_write_pb_gain(hdspm, i, j, gain);
866 /*----------------------------------------------------------------------------
868 ----------------------------------------------------------------------------*/
870 static inline unsigned char snd_hdspm_midi_read_byte (hdspm_t *hdspm, int id)
872 /* the hardware already does the relevant bit-mask with 0xff */
874 return hdspm_read(hdspm, HDSPM_midiDataIn1);
876 return hdspm_read(hdspm, HDSPM_midiDataIn0);
879 static inline void snd_hdspm_midi_write_byte (hdspm_t *hdspm, int id, int val)
881 /* the hardware already does the relevant bit-mask with 0xff */
883 return hdspm_write(hdspm, HDSPM_midiDataOut1, val);
885 return hdspm_write(hdspm, HDSPM_midiDataOut0, val);
888 static inline int snd_hdspm_midi_input_available (hdspm_t *hdspm, int id)
891 return (hdspm_read(hdspm, HDSPM_midiStatusIn1) & 0xff);
893 return (hdspm_read(hdspm, HDSPM_midiStatusIn0) & 0xff);
896 static inline int snd_hdspm_midi_output_possible (hdspm_t *hdspm, int id)
901 fifo_bytes_used = hdspm_read(hdspm, HDSPM_midiStatusOut1) & 0xff;
903 fifo_bytes_used = hdspm_read(hdspm, HDSPM_midiStatusOut0) & 0xff;
905 if (fifo_bytes_used < 128)
906 return 128 - fifo_bytes_used;
911 static inline void snd_hdspm_flush_midi_input (hdspm_t *hdspm, int id)
913 while (snd_hdspm_midi_input_available (hdspm, id))
914 snd_hdspm_midi_read_byte (hdspm, id);
917 static int snd_hdspm_midi_output_write (hdspm_midi_t *hmidi)
923 unsigned char buf[128];
925 /* Output is not interrupt driven */
927 spin_lock_irqsave (&hmidi->lock, flags);
929 if (!snd_rawmidi_transmit_empty (hmidi->output)) {
930 if ((n_pending = snd_hdspm_midi_output_possible (hmidi->hdspm, hmidi->id)) > 0) {
931 if (n_pending > (int)sizeof (buf))
932 n_pending = sizeof (buf);
934 if ((to_write = snd_rawmidi_transmit (hmidi->output, buf, n_pending)) > 0) {
935 for (i = 0; i < to_write; ++i)
936 snd_hdspm_midi_write_byte (hmidi->hdspm, hmidi->id, buf[i]);
941 spin_unlock_irqrestore (&hmidi->lock, flags);
945 static int snd_hdspm_midi_input_read (hdspm_midi_t *hmidi)
947 unsigned char buf[128]; /* this buffer is designed to match the MIDI input FIFO size */
952 spin_lock_irqsave (&hmidi->lock, flags);
953 if ((n_pending = snd_hdspm_midi_input_available (hmidi->hdspm, hmidi->id)) > 0) {
955 if (n_pending > (int)sizeof (buf)) {
956 n_pending = sizeof (buf);
958 for (i = 0; i < n_pending; ++i) {
959 buf[i] = snd_hdspm_midi_read_byte (hmidi->hdspm, hmidi->id);
962 snd_rawmidi_receive (hmidi->input, buf, n_pending);
965 /* flush the MIDI input FIFO */
966 while (n_pending--) {
967 snd_hdspm_midi_read_byte (hmidi->hdspm, hmidi->id);
973 hmidi->hdspm->control_register |= HDSPM_Midi1InterruptEnable;
975 hmidi->hdspm->control_register |= HDSPM_Midi0InterruptEnable;
977 hdspm_write(hmidi->hdspm, HDSPM_controlRegister, hmidi->hdspm->control_register);
978 spin_unlock_irqrestore (&hmidi->lock, flags);
979 return snd_hdspm_midi_output_write (hmidi);
982 static void snd_hdspm_midi_input_trigger(snd_rawmidi_substream_t * substream, int up)
989 hmidi = (hdspm_midi_t *) substream->rmidi->private_data;
990 hdspm = hmidi->hdspm;
991 ie = hmidi->id ? HDSPM_Midi1InterruptEnable : HDSPM_Midi0InterruptEnable;
992 spin_lock_irqsave (&hdspm->lock, flags);
994 if (!(hdspm->control_register & ie)) {
995 snd_hdspm_flush_midi_input (hdspm, hmidi->id);
996 hdspm->control_register |= ie;
999 hdspm->control_register &= ~ie;
1002 hdspm_write(hdspm, HDSPM_controlRegister, hdspm->control_register);
1003 spin_unlock_irqrestore (&hdspm->lock, flags);
1006 static void snd_hdspm_midi_output_timer(unsigned long data)
1008 hdspm_midi_t *hmidi = (hdspm_midi_t *) data;
1009 unsigned long flags;
1011 snd_hdspm_midi_output_write(hmidi);
1012 spin_lock_irqsave (&hmidi->lock, flags);
1014 /* this does not bump hmidi->istimer, because the
1015 kernel automatically removed the timer when it
1016 expired, and we are now adding it back, thus
1017 leaving istimer wherever it was set before.
1020 if (hmidi->istimer) {
1021 hmidi->timer.expires = 1 + jiffies;
1022 add_timer(&hmidi->timer);
1025 spin_unlock_irqrestore (&hmidi->lock, flags);
1028 static void snd_hdspm_midi_output_trigger(snd_rawmidi_substream_t * substream, int up)
1030 hdspm_midi_t *hmidi;
1031 unsigned long flags;
1033 hmidi = (hdspm_midi_t *) substream->rmidi->private_data;
1034 spin_lock_irqsave (&hmidi->lock, flags);
1036 if (!hmidi->istimer) {
1037 init_timer(&hmidi->timer);
1038 hmidi->timer.function = snd_hdspm_midi_output_timer;
1039 hmidi->timer.data = (unsigned long) hmidi;
1040 hmidi->timer.expires = 1 + jiffies;
1041 add_timer(&hmidi->timer);
1045 if (hmidi->istimer && --hmidi->istimer <= 0) {
1046 del_timer (&hmidi->timer);
1049 spin_unlock_irqrestore (&hmidi->lock, flags);
1051 snd_hdspm_midi_output_write(hmidi);
1054 static int snd_hdspm_midi_input_open(snd_rawmidi_substream_t * substream)
1056 hdspm_midi_t *hmidi;
1058 hmidi = (hdspm_midi_t *) substream->rmidi->private_data;
1059 spin_lock_irq (&hmidi->lock);
1060 snd_hdspm_flush_midi_input (hmidi->hdspm, hmidi->id);
1061 hmidi->input = substream;
1062 spin_unlock_irq (&hmidi->lock);
1067 static int snd_hdspm_midi_output_open(snd_rawmidi_substream_t * substream)
1069 hdspm_midi_t *hmidi;
1071 hmidi = (hdspm_midi_t *) substream->rmidi->private_data;
1072 spin_lock_irq (&hmidi->lock);
1073 hmidi->output = substream;
1074 spin_unlock_irq (&hmidi->lock);
1079 static int snd_hdspm_midi_input_close(snd_rawmidi_substream_t * substream)
1081 hdspm_midi_t *hmidi;
1083 snd_hdspm_midi_input_trigger (substream, 0);
1085 hmidi = (hdspm_midi_t *) substream->rmidi->private_data;
1086 spin_lock_irq (&hmidi->lock);
1087 hmidi->input = NULL;
1088 spin_unlock_irq (&hmidi->lock);
1093 static int snd_hdspm_midi_output_close(snd_rawmidi_substream_t * substream)
1095 hdspm_midi_t *hmidi;
1097 snd_hdspm_midi_output_trigger (substream, 0);
1099 hmidi = (hdspm_midi_t *) substream->rmidi->private_data;
1100 spin_lock_irq (&hmidi->lock);
1101 hmidi->output = NULL;
1102 spin_unlock_irq (&hmidi->lock);
1107 static snd_rawmidi_ops_t snd_hdspm_midi_output =
1109 .open = snd_hdspm_midi_output_open,
1110 .close = snd_hdspm_midi_output_close,
1111 .trigger = snd_hdspm_midi_output_trigger,
1114 static snd_rawmidi_ops_t snd_hdspm_midi_input =
1116 .open = snd_hdspm_midi_input_open,
1117 .close = snd_hdspm_midi_input_close,
1118 .trigger = snd_hdspm_midi_input_trigger,
1121 static int __devinit snd_hdspm_create_midi (snd_card_t *card, hdspm_t *hdspm, int id)
1126 hdspm->midi[id].id = id;
1127 hdspm->midi[id].rmidi = NULL;
1128 hdspm->midi[id].input = NULL;
1129 hdspm->midi[id].output = NULL;
1130 hdspm->midi[id].hdspm = hdspm;
1131 hdspm->midi[id].istimer = 0;
1132 hdspm->midi[id].pending = 0;
1133 spin_lock_init (&hdspm->midi[id].lock);
1135 sprintf (buf, "%s MIDI %d", card->shortname, id+1);
1136 if ((err = snd_rawmidi_new (card, buf, id, 1, 1, &hdspm->midi[id].rmidi)) < 0)
1139 sprintf (hdspm->midi[id].rmidi->name, "%s MIDI %d", card->id, id+1);
1140 hdspm->midi[id].rmidi->private_data = &hdspm->midi[id];
1142 snd_rawmidi_set_ops (hdspm->midi[id].rmidi, SNDRV_RAWMIDI_STREAM_OUTPUT, &snd_hdspm_midi_output);
1143 snd_rawmidi_set_ops (hdspm->midi[id].rmidi, SNDRV_RAWMIDI_STREAM_INPUT, &snd_hdspm_midi_input);
1145 hdspm->midi[id].rmidi->info_flags |= SNDRV_RAWMIDI_INFO_OUTPUT |
1146 SNDRV_RAWMIDI_INFO_INPUT |
1147 SNDRV_RAWMIDI_INFO_DUPLEX;
1153 static void hdspm_midi_tasklet(unsigned long arg)
1155 hdspm_t *hdspm = (hdspm_t *)arg;
1157 if (hdspm->midi[0].pending)
1158 snd_hdspm_midi_input_read (&hdspm->midi[0]);
1159 if (hdspm->midi[1].pending)
1160 snd_hdspm_midi_input_read (&hdspm->midi[1]);
1164 /*-----------------------------------------------------------------------------
1166 ----------------------------------------------------------------------------*/
1168 /* get the system sample rate which is set */
1170 #define HDSPM_SYSTEM_SAMPLE_RATE(xname, xindex) \
1171 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1174 .access = SNDRV_CTL_ELEM_ACCESS_READ, \
1175 .info = snd_hdspm_info_system_sample_rate, \
1176 .get = snd_hdspm_get_system_sample_rate \
1179 static int snd_hdspm_info_system_sample_rate(snd_kcontrol_t * kcontrol,
1180 snd_ctl_elem_info_t * uinfo)
1182 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1187 static int snd_hdspm_get_system_sample_rate(snd_kcontrol_t * kcontrol,
1188 snd_ctl_elem_value_t *
1191 hdspm_t *hdspm = snd_kcontrol_chip(kcontrol);
1193 ucontrol->value.enumerated.item[0] = hdspm->system_sample_rate;
1197 #define HDSPM_AUTOSYNC_SAMPLE_RATE(xname, xindex) \
1198 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1201 .access = SNDRV_CTL_ELEM_ACCESS_READ, \
1202 .info = snd_hdspm_info_autosync_sample_rate, \
1203 .get = snd_hdspm_get_autosync_sample_rate \
1206 static int snd_hdspm_info_autosync_sample_rate(snd_kcontrol_t * kcontrol,
1207 snd_ctl_elem_info_t * uinfo)
1209 static char *texts[] = { "32000", "44100", "48000",
1210 "64000", "88200", "96000",
1211 "128000", "176400", "192000",
1214 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1216 uinfo->value.enumerated.items = 10;
1217 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
1218 uinfo->value.enumerated.item =
1219 uinfo->value.enumerated.items - 1;
1220 strcpy(uinfo->value.enumerated.name,
1221 texts[uinfo->value.enumerated.item]);
1225 static int snd_hdspm_get_autosync_sample_rate(snd_kcontrol_t * kcontrol,
1226 snd_ctl_elem_value_t *
1229 hdspm_t *hdspm = snd_kcontrol_chip(kcontrol);
1231 switch (hdspm_external_sample_rate(hdspm)) {
1233 ucontrol->value.enumerated.item[0] = 0;
1236 ucontrol->value.enumerated.item[0] = 1;
1239 ucontrol->value.enumerated.item[0] = 2;
1242 ucontrol->value.enumerated.item[0] = 3;
1245 ucontrol->value.enumerated.item[0] = 4;
1248 ucontrol->value.enumerated.item[0] = 5;
1251 ucontrol->value.enumerated.item[0] = 6;
1254 ucontrol->value.enumerated.item[0] = 7;
1257 ucontrol->value.enumerated.item[0] = 8;
1261 ucontrol->value.enumerated.item[0] = 9;
1266 #define HDSPM_SYSTEM_CLOCK_MODE(xname, xindex) \
1267 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1270 .access = SNDRV_CTL_ELEM_ACCESS_READ, \
1271 .info = snd_hdspm_info_system_clock_mode, \
1272 .get = snd_hdspm_get_system_clock_mode, \
1277 static int hdspm_system_clock_mode(hdspm_t * hdspm)
1279 /* Always reflect the hardware info, rme is never wrong !!!! */
1281 if (hdspm->control_register & HDSPM_ClockModeMaster)
1286 static int snd_hdspm_info_system_clock_mode(snd_kcontrol_t * kcontrol,
1287 snd_ctl_elem_info_t * uinfo)
1289 static char *texts[] = { "Master", "Slave" };
1291 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1293 uinfo->value.enumerated.items = 2;
1294 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
1295 uinfo->value.enumerated.item =
1296 uinfo->value.enumerated.items - 1;
1297 strcpy(uinfo->value.enumerated.name,
1298 texts[uinfo->value.enumerated.item]);
1302 static int snd_hdspm_get_system_clock_mode(snd_kcontrol_t * kcontrol,
1303 snd_ctl_elem_value_t * ucontrol)
1305 hdspm_t *hdspm = snd_kcontrol_chip(kcontrol);
1307 ucontrol->value.enumerated.item[0] =
1308 hdspm_system_clock_mode(hdspm);
1312 #define HDSPM_CLOCK_SOURCE(xname, xindex) \
1313 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1316 .info = snd_hdspm_info_clock_source, \
1317 .get = snd_hdspm_get_clock_source, \
1318 .put = snd_hdspm_put_clock_source \
1321 static int hdspm_clock_source(hdspm_t * hdspm)
1323 if (hdspm->control_register & HDSPM_ClockModeMaster) {
1324 switch (hdspm->system_sample_rate) {
1351 static int hdspm_set_clock_source(hdspm_t * hdspm, int mode)
1356 case HDSPM_CLOCK_SOURCE_AUTOSYNC:
1357 if (hdspm_external_sample_rate(hdspm) != 0) {
1358 hdspm->control_register &= ~HDSPM_ClockModeMaster;
1359 hdspm_write(hdspm, HDSPM_controlRegister,
1360 hdspm->control_register);
1364 case HDSPM_CLOCK_SOURCE_INTERNAL_32KHZ:
1367 case HDSPM_CLOCK_SOURCE_INTERNAL_44_1KHZ:
1370 case HDSPM_CLOCK_SOURCE_INTERNAL_48KHZ:
1373 case HDSPM_CLOCK_SOURCE_INTERNAL_64KHZ:
1376 case HDSPM_CLOCK_SOURCE_INTERNAL_88_2KHZ:
1379 case HDSPM_CLOCK_SOURCE_INTERNAL_96KHZ:
1382 case HDSPM_CLOCK_SOURCE_INTERNAL_128KHZ:
1385 case HDSPM_CLOCK_SOURCE_INTERNAL_176_4KHZ:
1388 case HDSPM_CLOCK_SOURCE_INTERNAL_192KHZ:
1395 hdspm->control_register |= HDSPM_ClockModeMaster;
1396 hdspm_write(hdspm, HDSPM_controlRegister, hdspm->control_register);
1397 hdspm_set_rate(hdspm, rate, 1);
1401 static int snd_hdspm_info_clock_source(snd_kcontrol_t * kcontrol,
1402 snd_ctl_elem_info_t * uinfo)
1404 static char *texts[] = { "AutoSync",
1405 "Internal 32.0 kHz", "Internal 44.1 kHz",
1406 "Internal 48.0 kHz",
1407 "Internal 64.0 kHz", "Internal 88.2 kHz",
1408 "Internal 96.0 kHz",
1409 "Internal 128.0 kHz", "Internal 176.4 kHz",
1410 "Internal 192.0 kHz"
1413 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1415 uinfo->value.enumerated.items = 10;
1417 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
1418 uinfo->value.enumerated.item =
1419 uinfo->value.enumerated.items - 1;
1421 strcpy(uinfo->value.enumerated.name,
1422 texts[uinfo->value.enumerated.item]);
1427 static int snd_hdspm_get_clock_source(snd_kcontrol_t * kcontrol,
1428 snd_ctl_elem_value_t * ucontrol)
1430 hdspm_t *hdspm = snd_kcontrol_chip(kcontrol);
1432 ucontrol->value.enumerated.item[0] = hdspm_clock_source(hdspm);
1436 static int snd_hdspm_put_clock_source(snd_kcontrol_t * kcontrol,
1437 snd_ctl_elem_value_t * ucontrol)
1439 hdspm_t *hdspm = snd_kcontrol_chip(kcontrol);
1443 if (!snd_hdspm_use_is_exclusive(hdspm))
1445 val = ucontrol->value.enumerated.item[0];
1450 spin_lock_irq(&hdspm->lock);
1451 if (val != hdspm_clock_source(hdspm))
1452 change = (hdspm_set_clock_source(hdspm, val) == 0) ? 1 : 0;
1455 spin_unlock_irq(&hdspm->lock);
1459 #define HDSPM_PREF_SYNC_REF(xname, xindex) \
1460 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1463 .info = snd_hdspm_info_pref_sync_ref, \
1464 .get = snd_hdspm_get_pref_sync_ref, \
1465 .put = snd_hdspm_put_pref_sync_ref \
1468 static int hdspm_pref_sync_ref(hdspm_t * hdspm)
1470 /* Notice that this looks at the requested sync source,
1471 not the one actually in use.
1473 switch (hdspm->control_register & HDSPM_SyncRefMask) {
1474 case HDSPM_SyncRef_Word:
1475 return HDSPM_SYNC_FROM_WORD;
1476 case HDSPM_SyncRef_MADI:
1477 return HDSPM_SYNC_FROM_MADI;
1480 return HDSPM_SYNC_FROM_WORD;
1483 static int hdspm_set_pref_sync_ref(hdspm_t * hdspm, int pref)
1485 hdspm->control_register &= ~HDSPM_SyncRefMask;
1488 case HDSPM_SYNC_FROM_MADI:
1489 hdspm->control_register |= HDSPM_SyncRef_MADI;
1491 case HDSPM_SYNC_FROM_WORD:
1492 hdspm->control_register |= HDSPM_SyncRef_Word;
1497 hdspm_write(hdspm, HDSPM_controlRegister, hdspm->control_register);
1501 static int snd_hdspm_info_pref_sync_ref(snd_kcontrol_t * kcontrol,
1502 snd_ctl_elem_info_t * uinfo)
1504 static char *texts[] = { "Word", "MADI" };
1506 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1509 uinfo->value.enumerated.items = 2;
1511 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
1512 uinfo->value.enumerated.item =
1513 uinfo->value.enumerated.items - 1;
1514 strcpy(uinfo->value.enumerated.name,
1515 texts[uinfo->value.enumerated.item]);
1519 static int snd_hdspm_get_pref_sync_ref(snd_kcontrol_t * kcontrol,
1520 snd_ctl_elem_value_t * ucontrol)
1522 hdspm_t *hdspm = snd_kcontrol_chip(kcontrol);
1524 ucontrol->value.enumerated.item[0] = hdspm_pref_sync_ref(hdspm);
1528 static int snd_hdspm_put_pref_sync_ref(snd_kcontrol_t * kcontrol,
1529 snd_ctl_elem_value_t * ucontrol)
1531 hdspm_t *hdspm = snd_kcontrol_chip(kcontrol);
1537 if (!snd_hdspm_use_is_exclusive(hdspm))
1540 val = ucontrol->value.enumerated.item[0] % max;
1542 spin_lock_irq(&hdspm->lock);
1543 change = (int) val != hdspm_pref_sync_ref(hdspm);
1544 hdspm_set_pref_sync_ref(hdspm, val);
1545 spin_unlock_irq(&hdspm->lock);
1549 #define HDSPM_AUTOSYNC_REF(xname, xindex) \
1550 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1553 .access = SNDRV_CTL_ELEM_ACCESS_READ, \
1554 .info = snd_hdspm_info_autosync_ref, \
1555 .get = snd_hdspm_get_autosync_ref, \
1558 static int hdspm_autosync_ref(hdspm_t * hdspm)
1560 /* This looks at the autosync selected sync reference */
1561 unsigned int status2 = hdspm_read(hdspm, HDSPM_statusRegister2);
1563 switch (status2 & HDSPM_SelSyncRefMask) {
1565 case HDSPM_SelSyncRef_WORD:
1566 return HDSPM_AUTOSYNC_FROM_WORD;
1568 case HDSPM_SelSyncRef_MADI:
1569 return HDSPM_AUTOSYNC_FROM_MADI;
1571 case HDSPM_SelSyncRef_NVALID:
1572 return HDSPM_AUTOSYNC_FROM_NONE;
1581 static int snd_hdspm_info_autosync_ref(snd_kcontrol_t * kcontrol,
1582 snd_ctl_elem_info_t * uinfo)
1584 static char *texts[] = { "WordClock", "MADI", "None" };
1586 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1588 uinfo->value.enumerated.items = 3;
1589 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
1590 uinfo->value.enumerated.item =
1591 uinfo->value.enumerated.items - 1;
1592 strcpy(uinfo->value.enumerated.name,
1593 texts[uinfo->value.enumerated.item]);
1597 static int snd_hdspm_get_autosync_ref(snd_kcontrol_t * kcontrol,
1598 snd_ctl_elem_value_t * ucontrol)
1600 hdspm_t *hdspm = snd_kcontrol_chip(kcontrol);
1602 ucontrol->value.enumerated.item[0] = hdspm_pref_sync_ref(hdspm);
1606 #define HDSPM_LINE_OUT(xname, xindex) \
1607 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1610 .info = snd_hdspm_info_line_out, \
1611 .get = snd_hdspm_get_line_out, \
1612 .put = snd_hdspm_put_line_out \
1615 static int hdspm_line_out(hdspm_t * hdspm)
1617 return (hdspm->control_register & HDSPM_LineOut) ? 1 : 0;
1621 static int hdspm_set_line_output(hdspm_t * hdspm, int out)
1624 hdspm->control_register |= HDSPM_LineOut;
1626 hdspm->control_register &= ~HDSPM_LineOut;
1627 hdspm_write(hdspm, HDSPM_controlRegister, hdspm->control_register);
1632 static int snd_hdspm_info_line_out(snd_kcontrol_t * kcontrol,
1633 snd_ctl_elem_info_t * uinfo)
1635 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
1637 uinfo->value.integer.min = 0;
1638 uinfo->value.integer.max = 1;
1642 static int snd_hdspm_get_line_out(snd_kcontrol_t * kcontrol,
1643 snd_ctl_elem_value_t * ucontrol)
1645 hdspm_t *hdspm = snd_kcontrol_chip(kcontrol);
1647 spin_lock_irq(&hdspm->lock);
1648 ucontrol->value.integer.value[0] = hdspm_line_out(hdspm);
1649 spin_unlock_irq(&hdspm->lock);
1653 static int snd_hdspm_put_line_out(snd_kcontrol_t * kcontrol,
1654 snd_ctl_elem_value_t * ucontrol)
1656 hdspm_t *hdspm = snd_kcontrol_chip(kcontrol);
1660 if (!snd_hdspm_use_is_exclusive(hdspm))
1662 val = ucontrol->value.integer.value[0] & 1;
1663 spin_lock_irq(&hdspm->lock);
1664 change = (int) val != hdspm_line_out(hdspm);
1665 hdspm_set_line_output(hdspm, val);
1666 spin_unlock_irq(&hdspm->lock);
1670 #define HDSPM_TX_64(xname, xindex) \
1671 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1674 .info = snd_hdspm_info_tx_64, \
1675 .get = snd_hdspm_get_tx_64, \
1676 .put = snd_hdspm_put_tx_64 \
1679 static int hdspm_tx_64(hdspm_t * hdspm)
1681 return (hdspm->control_register & HDSPM_TX_64ch) ? 1 : 0;
1684 static int hdspm_set_tx_64(hdspm_t * hdspm, int out)
1687 hdspm->control_register |= HDSPM_TX_64ch;
1689 hdspm->control_register &= ~HDSPM_TX_64ch;
1690 hdspm_write(hdspm, HDSPM_controlRegister, hdspm->control_register);
1695 static int snd_hdspm_info_tx_64(snd_kcontrol_t * kcontrol,
1696 snd_ctl_elem_info_t * uinfo)
1698 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
1700 uinfo->value.integer.min = 0;
1701 uinfo->value.integer.max = 1;
1705 static int snd_hdspm_get_tx_64(snd_kcontrol_t * kcontrol,
1706 snd_ctl_elem_value_t * ucontrol)
1708 hdspm_t *hdspm = snd_kcontrol_chip(kcontrol);
1710 spin_lock_irq(&hdspm->lock);
1711 ucontrol->value.integer.value[0] = hdspm_tx_64(hdspm);
1712 spin_unlock_irq(&hdspm->lock);
1716 static int snd_hdspm_put_tx_64(snd_kcontrol_t * kcontrol,
1717 snd_ctl_elem_value_t * ucontrol)
1719 hdspm_t *hdspm = snd_kcontrol_chip(kcontrol);
1723 if (!snd_hdspm_use_is_exclusive(hdspm))
1725 val = ucontrol->value.integer.value[0] & 1;
1726 spin_lock_irq(&hdspm->lock);
1727 change = (int) val != hdspm_tx_64(hdspm);
1728 hdspm_set_tx_64(hdspm, val);
1729 spin_unlock_irq(&hdspm->lock);
1733 #define HDSPM_C_TMS(xname, xindex) \
1734 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1737 .info = snd_hdspm_info_c_tms, \
1738 .get = snd_hdspm_get_c_tms, \
1739 .put = snd_hdspm_put_c_tms \
1742 static int hdspm_c_tms(hdspm_t * hdspm)
1744 return (hdspm->control_register & HDSPM_clr_tms) ? 1 : 0;
1747 static int hdspm_set_c_tms(hdspm_t * hdspm, int out)
1750 hdspm->control_register |= HDSPM_clr_tms;
1752 hdspm->control_register &= ~HDSPM_clr_tms;
1753 hdspm_write(hdspm, HDSPM_controlRegister, hdspm->control_register);
1758 static int snd_hdspm_info_c_tms(snd_kcontrol_t * kcontrol,
1759 snd_ctl_elem_info_t * uinfo)
1761 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
1763 uinfo->value.integer.min = 0;
1764 uinfo->value.integer.max = 1;
1768 static int snd_hdspm_get_c_tms(snd_kcontrol_t * kcontrol,
1769 snd_ctl_elem_value_t * ucontrol)
1771 hdspm_t *hdspm = snd_kcontrol_chip(kcontrol);
1773 spin_lock_irq(&hdspm->lock);
1774 ucontrol->value.integer.value[0] = hdspm_c_tms(hdspm);
1775 spin_unlock_irq(&hdspm->lock);
1779 static int snd_hdspm_put_c_tms(snd_kcontrol_t * kcontrol,
1780 snd_ctl_elem_value_t * ucontrol)
1782 hdspm_t *hdspm = snd_kcontrol_chip(kcontrol);
1786 if (!snd_hdspm_use_is_exclusive(hdspm))
1788 val = ucontrol->value.integer.value[0] & 1;
1789 spin_lock_irq(&hdspm->lock);
1790 change = (int) val != hdspm_c_tms(hdspm);
1791 hdspm_set_c_tms(hdspm, val);
1792 spin_unlock_irq(&hdspm->lock);
1796 #define HDSPM_SAFE_MODE(xname, xindex) \
1797 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1800 .info = snd_hdspm_info_safe_mode, \
1801 .get = snd_hdspm_get_safe_mode, \
1802 .put = snd_hdspm_put_safe_mode \
1805 static int hdspm_safe_mode(hdspm_t * hdspm)
1807 return (hdspm->control_register & HDSPM_AutoInp) ? 1 : 0;
1810 static int hdspm_set_safe_mode(hdspm_t * hdspm, int out)
1813 hdspm->control_register |= HDSPM_AutoInp;
1815 hdspm->control_register &= ~HDSPM_AutoInp;
1816 hdspm_write(hdspm, HDSPM_controlRegister, hdspm->control_register);
1821 static int snd_hdspm_info_safe_mode(snd_kcontrol_t * kcontrol,
1822 snd_ctl_elem_info_t * uinfo)
1824 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
1826 uinfo->value.integer.min = 0;
1827 uinfo->value.integer.max = 1;
1831 static int snd_hdspm_get_safe_mode(snd_kcontrol_t * kcontrol,
1832 snd_ctl_elem_value_t * ucontrol)
1834 hdspm_t *hdspm = snd_kcontrol_chip(kcontrol);
1836 spin_lock_irq(&hdspm->lock);
1837 ucontrol->value.integer.value[0] = hdspm_safe_mode(hdspm);
1838 spin_unlock_irq(&hdspm->lock);
1842 static int snd_hdspm_put_safe_mode(snd_kcontrol_t * kcontrol,
1843 snd_ctl_elem_value_t * ucontrol)
1845 hdspm_t *hdspm = snd_kcontrol_chip(kcontrol);
1849 if (!snd_hdspm_use_is_exclusive(hdspm))
1851 val = ucontrol->value.integer.value[0] & 1;
1852 spin_lock_irq(&hdspm->lock);
1853 change = (int) val != hdspm_safe_mode(hdspm);
1854 hdspm_set_safe_mode(hdspm, val);
1855 spin_unlock_irq(&hdspm->lock);
1859 #define HDSPM_INPUT_SELECT(xname, xindex) \
1860 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1863 .info = snd_hdspm_info_input_select, \
1864 .get = snd_hdspm_get_input_select, \
1865 .put = snd_hdspm_put_input_select \
1868 static int hdspm_input_select(hdspm_t * hdspm)
1870 return (hdspm->control_register & HDSPM_InputSelect0) ? 1 : 0;
1873 static int hdspm_set_input_select(hdspm_t * hdspm, int out)
1876 hdspm->control_register |= HDSPM_InputSelect0;
1878 hdspm->control_register &= ~HDSPM_InputSelect0;
1879 hdspm_write(hdspm, HDSPM_controlRegister, hdspm->control_register);
1884 static int snd_hdspm_info_input_select(snd_kcontrol_t * kcontrol,
1885 snd_ctl_elem_info_t * uinfo)
1887 static char *texts[] = { "optical", "coaxial" };
1889 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1891 uinfo->value.enumerated.items = 2;
1893 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
1894 uinfo->value.enumerated.item =
1895 uinfo->value.enumerated.items - 1;
1896 strcpy(uinfo->value.enumerated.name,
1897 texts[uinfo->value.enumerated.item]);
1902 static int snd_hdspm_get_input_select(snd_kcontrol_t * kcontrol,
1903 snd_ctl_elem_value_t * ucontrol)
1905 hdspm_t *hdspm = snd_kcontrol_chip(kcontrol);
1907 spin_lock_irq(&hdspm->lock);
1908 ucontrol->value.enumerated.item[0] = hdspm_input_select(hdspm);
1909 spin_unlock_irq(&hdspm->lock);
1913 static int snd_hdspm_put_input_select(snd_kcontrol_t * kcontrol,
1914 snd_ctl_elem_value_t * ucontrol)
1916 hdspm_t *hdspm = snd_kcontrol_chip(kcontrol);
1920 if (!snd_hdspm_use_is_exclusive(hdspm))
1922 val = ucontrol->value.integer.value[0] & 1;
1923 spin_lock_irq(&hdspm->lock);
1924 change = (int) val != hdspm_input_select(hdspm);
1925 hdspm_set_input_select(hdspm, val);
1926 spin_unlock_irq(&hdspm->lock);
1931 deprecated since to much faders ???
1932 MIXER interface says output (source, destination, value)
1933 where source > MAX_channels are playback channels
1935 - playback mixer matrix: [channelout+64] [output] [value]
1936 - input(thru) mixer matrix: [channelin] [output] [value]
1937 (better do 2 kontrols for seperation ?)
1940 #define HDSPM_MIXER(xname, xindex) \
1941 { .iface = SNDRV_CTL_ELEM_IFACE_HWDEP, \
1945 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | \
1946 SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
1947 .info = snd_hdspm_info_mixer, \
1948 .get = snd_hdspm_get_mixer, \
1949 .put = snd_hdspm_put_mixer \
1952 static int snd_hdspm_info_mixer(snd_kcontrol_t * kcontrol,
1953 snd_ctl_elem_info_t * uinfo)
1955 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1957 uinfo->value.integer.min = 0;
1958 uinfo->value.integer.max = 65535;
1959 uinfo->value.integer.step = 1;
1963 static int snd_hdspm_get_mixer(snd_kcontrol_t * kcontrol,
1964 snd_ctl_elem_value_t * ucontrol)
1966 hdspm_t *hdspm = snd_kcontrol_chip(kcontrol);
1970 source = ucontrol->value.integer.value[0];
1973 else if (source >= 2 * HDSPM_MAX_CHANNELS)
1974 source = 2 * HDSPM_MAX_CHANNELS - 1;
1976 destination = ucontrol->value.integer.value[1];
1977 if (destination < 0)
1979 else if (destination >= HDSPM_MAX_CHANNELS)
1980 destination = HDSPM_MAX_CHANNELS - 1;
1982 spin_lock_irq(&hdspm->lock);
1983 if (source >= HDSPM_MAX_CHANNELS)
1984 ucontrol->value.integer.value[2] =
1985 hdspm_read_pb_gain(hdspm, destination,
1986 source - HDSPM_MAX_CHANNELS);
1988 ucontrol->value.integer.value[2] =
1989 hdspm_read_in_gain(hdspm, destination, source);
1991 spin_unlock_irq(&hdspm->lock);
1996 static int snd_hdspm_put_mixer(snd_kcontrol_t * kcontrol,
1997 snd_ctl_elem_value_t * ucontrol)
1999 hdspm_t *hdspm = snd_kcontrol_chip(kcontrol);
2005 if (!snd_hdspm_use_is_exclusive(hdspm))
2008 source = ucontrol->value.integer.value[0];
2009 destination = ucontrol->value.integer.value[1];
2011 if (source < 0 || source >= 2 * HDSPM_MAX_CHANNELS)
2013 if (destination < 0 || destination >= HDSPM_MAX_CHANNELS)
2016 gain = ucontrol->value.integer.value[2];
2018 spin_lock_irq(&hdspm->lock);
2020 if (source >= HDSPM_MAX_CHANNELS)
2021 change = gain != hdspm_read_pb_gain(hdspm, destination,
2023 HDSPM_MAX_CHANNELS);
2026 gain != hdspm_read_in_gain(hdspm, destination, source);
2029 if (source >= HDSPM_MAX_CHANNELS)
2030 hdspm_write_pb_gain(hdspm, destination,
2031 source - HDSPM_MAX_CHANNELS,
2034 hdspm_write_in_gain(hdspm, destination, source,
2037 spin_unlock_irq(&hdspm->lock);
2042 /* The simple mixer control(s) provide gain control for the
2043 basic 1:1 mappings of playback streams to output
2047 #define HDSPM_PLAYBACK_MIXER \
2048 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2049 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_WRITE | \
2050 SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
2051 .info = snd_hdspm_info_playback_mixer, \
2052 .get = snd_hdspm_get_playback_mixer, \
2053 .put = snd_hdspm_put_playback_mixer \
2056 static int snd_hdspm_info_playback_mixer(snd_kcontrol_t * kcontrol,
2057 snd_ctl_elem_info_t * uinfo)
2059 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
2061 uinfo->value.integer.min = 0;
2062 uinfo->value.integer.max = 65536;
2063 uinfo->value.integer.step = 1;
2067 static int snd_hdspm_get_playback_mixer(snd_kcontrol_t * kcontrol,
2068 snd_ctl_elem_value_t * ucontrol)
2070 hdspm_t *hdspm = snd_kcontrol_chip(kcontrol);
2074 channel = ucontrol->id.index - 1;
2076 snd_assert(channel >= 0
2077 || channel < HDSPM_MAX_CHANNELS, return -EINVAL);
2079 if ((mapped_channel = hdspm->channel_map[channel]) < 0)
2082 spin_lock_irq(&hdspm->lock);
2083 ucontrol->value.integer.value[0] =
2084 hdspm_read_pb_gain(hdspm, mapped_channel, mapped_channel);
2085 spin_unlock_irq(&hdspm->lock);
2087 /* snd_printdd("get pb mixer index %d, channel %d, mapped_channel %d, value %d\n",
2088 ucontrol->id.index, channel, mapped_channel, ucontrol->value.integer.value[0]);
2094 static int snd_hdspm_put_playback_mixer(snd_kcontrol_t * kcontrol,
2095 snd_ctl_elem_value_t * ucontrol)
2097 hdspm_t *hdspm = snd_kcontrol_chip(kcontrol);
2103 if (!snd_hdspm_use_is_exclusive(hdspm))
2106 channel = ucontrol->id.index - 1;
2108 snd_assert(channel >= 0
2109 || channel < HDSPM_MAX_CHANNELS, return -EINVAL);
2111 if ((mapped_channel = hdspm->channel_map[channel]) < 0)
2114 gain = ucontrol->value.integer.value[0];
2116 spin_lock_irq(&hdspm->lock);
2118 gain != hdspm_read_pb_gain(hdspm, mapped_channel,
2121 hdspm_write_pb_gain(hdspm, mapped_channel, mapped_channel,
2123 spin_unlock_irq(&hdspm->lock);
2127 #define HDSPM_WC_SYNC_CHECK(xname, xindex) \
2128 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2131 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
2132 .info = snd_hdspm_info_sync_check, \
2133 .get = snd_hdspm_get_wc_sync_check \
2136 static int snd_hdspm_info_sync_check(snd_kcontrol_t * kcontrol,
2137 snd_ctl_elem_info_t * uinfo)
2139 static char *texts[] = { "No Lock", "Lock", "Sync" };
2140 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2142 uinfo->value.enumerated.items = 3;
2143 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
2144 uinfo->value.enumerated.item =
2145 uinfo->value.enumerated.items - 1;
2146 strcpy(uinfo->value.enumerated.name,
2147 texts[uinfo->value.enumerated.item]);
2151 static int hdspm_wc_sync_check(hdspm_t * hdspm)
2153 int status2 = hdspm_read(hdspm, HDSPM_statusRegister2);
2154 if (status2 & HDSPM_wcLock) {
2155 if (status2 & HDSPM_wcSync)
2163 static int snd_hdspm_get_wc_sync_check(snd_kcontrol_t * kcontrol,
2164 snd_ctl_elem_value_t * ucontrol)
2166 hdspm_t *hdspm = snd_kcontrol_chip(kcontrol);
2168 ucontrol->value.enumerated.item[0] = hdspm_wc_sync_check(hdspm);
2173 #define HDSPM_MADI_SYNC_CHECK(xname, xindex) \
2174 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2177 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
2178 .info = snd_hdspm_info_sync_check, \
2179 .get = snd_hdspm_get_madisync_sync_check \
2182 static int hdspm_madisync_sync_check(hdspm_t * hdspm)
2184 int status = hdspm_read(hdspm, HDSPM_statusRegister);
2185 if (status & HDSPM_madiLock) {
2186 if (status & HDSPM_madiSync)
2194 static int snd_hdspm_get_madisync_sync_check(snd_kcontrol_t * kcontrol,
2195 snd_ctl_elem_value_t *
2198 hdspm_t *hdspm = snd_kcontrol_chip(kcontrol);
2200 ucontrol->value.enumerated.item[0] =
2201 hdspm_madisync_sync_check(hdspm);
2208 static snd_kcontrol_new_t snd_hdspm_controls[] = {
2210 HDSPM_MIXER("Mixer", 0),
2211 /* 'Sample Clock Source' complies with the alsa control naming scheme */
2212 HDSPM_CLOCK_SOURCE("Sample Clock Source", 0),
2214 HDSPM_SYSTEM_CLOCK_MODE("System Clock Mode", 0),
2215 HDSPM_PREF_SYNC_REF("Preferred Sync Reference", 0),
2216 HDSPM_AUTOSYNC_REF("AutoSync Reference", 0),
2217 HDSPM_SYSTEM_SAMPLE_RATE("System Sample Rate", 0),
2218 /* 'External Rate' complies with the alsa control naming scheme */
2219 HDSPM_AUTOSYNC_SAMPLE_RATE("External Rate", 0),
2220 HDSPM_WC_SYNC_CHECK("Word Clock Lock Status", 0),
2221 HDSPM_MADI_SYNC_CHECK("MADI Sync Lock Status", 0),
2222 HDSPM_LINE_OUT("Line Out", 0),
2223 HDSPM_TX_64("TX 64 channels mode", 0),
2224 HDSPM_C_TMS("Clear Track Marker", 0),
2225 HDSPM_SAFE_MODE("Safe Mode", 0),
2226 HDSPM_INPUT_SELECT("Input Select", 0),
2229 static snd_kcontrol_new_t snd_hdspm_playback_mixer = HDSPM_PLAYBACK_MIXER;
2232 static int hdspm_update_simple_mixer_controls(hdspm_t * hdspm)
2236 for (i = hdspm->ds_channels; i < hdspm->ss_channels; ++i) {
2237 if (hdspm->system_sample_rate > 48000) {
2238 hdspm->playback_mixer_ctls[i]->vd[0].access =
2239 SNDRV_CTL_ELEM_ACCESS_INACTIVE |
2240 SNDRV_CTL_ELEM_ACCESS_READ |
2241 SNDRV_CTL_ELEM_ACCESS_VOLATILE;
2243 hdspm->playback_mixer_ctls[i]->vd[0].access =
2244 SNDRV_CTL_ELEM_ACCESS_READWRITE |
2245 SNDRV_CTL_ELEM_ACCESS_VOLATILE;
2247 snd_ctl_notify(hdspm->card, SNDRV_CTL_EVENT_MASK_VALUE |
2248 SNDRV_CTL_EVENT_MASK_INFO,
2249 &hdspm->playback_mixer_ctls[i]->id);
2256 static int snd_hdspm_create_controls(snd_card_t * card, hdspm_t * hdspm)
2258 unsigned int idx, limit;
2260 snd_kcontrol_t *kctl;
2262 /* add control list first */
2264 for (idx = 0; idx < ARRAY_SIZE(snd_hdspm_controls); idx++) {
2266 snd_ctl_add(card, kctl =
2267 snd_ctl_new1(&snd_hdspm_controls[idx],
2273 /* Channel playback mixer as default control
2274 Note: the whole matrix would be 128*HDSPM_MIXER_CHANNELS Faders, thats to big for any alsamixer
2275 they are accesible via special IOCTL on hwdep
2276 and the mixer 2dimensional mixer control */
2278 snd_hdspm_playback_mixer.name = "Chn";
2279 limit = HDSPM_MAX_CHANNELS;
2281 /* The index values are one greater than the channel ID so that alsamixer
2282 will display them correctly. We want to use the index for fast lookup
2283 of the relevant channel, but if we use it at all, most ALSA software
2284 does the wrong thing with it ...
2287 for (idx = 0; idx < limit; ++idx) {
2288 snd_hdspm_playback_mixer.index = idx + 1;
2289 if ((err = snd_ctl_add(card,
2292 (&snd_hdspm_playback_mixer,
2296 hdspm->playback_mixer_ctls[idx] = kctl;
2302 /*------------------------------------------------------------
2304 ------------------------------------------------------------*/
2307 snd_hdspm_proc_read(snd_info_entry_t * entry, snd_info_buffer_t * buffer)
2309 hdspm_t *hdspm = (hdspm_t *) entry->private_data;
2310 unsigned int status;
2311 unsigned int status2;
2312 char *pref_sync_ref;
2314 char *system_clock_mode;
2320 status = hdspm_read(hdspm, HDSPM_statusRegister);
2321 status2 = hdspm_read(hdspm, HDSPM_statusRegister2);
2323 snd_iprintf(buffer, "%s (Card #%d) Rev.%x Status2first3bits: %x\n",
2324 hdspm->card_name, hdspm->card->number + 1,
2325 hdspm->firmware_rev,
2326 (status2 & HDSPM_version0) |
2327 (status2 & HDSPM_version1) | (status2 &
2330 snd_iprintf(buffer, "IRQ: %d Registers bus: 0x%lx VM: 0x%lx\n",
2331 hdspm->irq, hdspm->port, (unsigned long)hdspm->iobase);
2333 snd_iprintf(buffer, "--- System ---\n");
2336 "IRQ Pending: Audio=%d, MIDI0=%d, MIDI1=%d, IRQcount=%d\n",
2337 status & HDSPM_audioIRQPending,
2338 (status & HDSPM_midi0IRQPending) ? 1 : 0,
2339 (status & HDSPM_midi1IRQPending) ? 1 : 0,
2342 "HW pointer: id = %d, rawptr = %d (%d->%d) estimated= %ld (bytes)\n",
2343 ((status & HDSPM_BufferID) ? 1 : 0),
2344 (status & HDSPM_BufferPositionMask),
2345 (status & HDSPM_BufferPositionMask) % (2 *
2348 ((status & HDSPM_BufferPositionMask) -
2349 64) % (2 * (int)hdspm->period_bytes),
2350 (long) hdspm_hw_pointer(hdspm) * 4);
2353 "MIDI FIFO: Out1=0x%x, Out2=0x%x, In1=0x%x, In2=0x%x \n",
2354 hdspm_read(hdspm, HDSPM_midiStatusOut0) & 0xFF,
2355 hdspm_read(hdspm, HDSPM_midiStatusOut1) & 0xFF,
2356 hdspm_read(hdspm, HDSPM_midiStatusIn0) & 0xFF,
2357 hdspm_read(hdspm, HDSPM_midiStatusIn1) & 0xFF);
2359 "Register: ctrl1=0x%x, ctrl2=0x%x, status1=0x%x, status2=0x%x\n",
2360 hdspm->control_register, hdspm->control2_register,
2363 snd_iprintf(buffer, "--- Settings ---\n");
2366 hdspm_decode_latency(hdspm->
2368 HDSPM_LatencyMask));
2371 "Size (Latency): %d samples (2 periods of %lu bytes)\n",
2372 x, (unsigned long) hdspm->period_bytes);
2374 snd_iprintf(buffer, "Line out: %s, Precise Pointer: %s\n",
2376 control_register & HDSPM_LineOut) ? "on " : "off",
2377 (hdspm->precise_ptr) ? "on" : "off");
2379 switch (hdspm->control_register & HDSPM_InputMask) {
2380 case HDSPM_InputOptical:
2383 case HDSPM_InputCoaxial:
2390 switch (hdspm->control_register & HDSPM_SyncRefMask) {
2391 case HDSPM_SyncRef_Word:
2392 syncref = "WordClock";
2394 case HDSPM_SyncRef_MADI:
2400 snd_iprintf(buffer, "Inputsel = %s, SyncRef = %s\n", insel,
2404 "ClearTrackMarker = %s, Transmit in %s Channel Mode, Auto Input %s\n",
2406 control_register & HDSPM_clr_tms) ? "on" : "off",
2408 control_register & HDSPM_TX_64ch) ? "64" : "56",
2410 control_register & HDSPM_AutoInp) ? "on" : "off");
2412 switch (hdspm_clock_source(hdspm)) {
2413 case HDSPM_CLOCK_SOURCE_AUTOSYNC:
2414 clock_source = "AutoSync";
2416 case HDSPM_CLOCK_SOURCE_INTERNAL_32KHZ:
2417 clock_source = "Internal 32 kHz";
2419 case HDSPM_CLOCK_SOURCE_INTERNAL_44_1KHZ:
2420 clock_source = "Internal 44.1 kHz";
2422 case HDSPM_CLOCK_SOURCE_INTERNAL_48KHZ:
2423 clock_source = "Internal 48 kHz";
2425 case HDSPM_CLOCK_SOURCE_INTERNAL_64KHZ:
2426 clock_source = "Internal 64 kHz";
2428 case HDSPM_CLOCK_SOURCE_INTERNAL_88_2KHZ:
2429 clock_source = "Internal 88.2 kHz";
2431 case HDSPM_CLOCK_SOURCE_INTERNAL_96KHZ:
2432 clock_source = "Internal 96 kHz";
2435 clock_source = "Error";
2437 snd_iprintf(buffer, "Sample Clock Source: %s\n", clock_source);
2438 if (!(hdspm->control_register & HDSPM_ClockModeMaster)) {
2439 system_clock_mode = "Slave";
2441 system_clock_mode = "Master";
2443 snd_iprintf(buffer, "System Clock Mode: %s\n", system_clock_mode);
2445 switch (hdspm_pref_sync_ref(hdspm)) {
2446 case HDSPM_SYNC_FROM_WORD:
2447 pref_sync_ref = "Word Clock";
2449 case HDSPM_SYNC_FROM_MADI:
2450 pref_sync_ref = "MADI Sync";
2453 pref_sync_ref = "XXXX Clock";
2456 snd_iprintf(buffer, "Preferred Sync Reference: %s\n",
2459 snd_iprintf(buffer, "System Clock Frequency: %d\n",
2460 hdspm->system_sample_rate);
2463 snd_iprintf(buffer, "--- Status:\n");
2465 x = status & HDSPM_madiSync;
2466 x2 = status2 & HDSPM_wcSync;
2468 snd_iprintf(buffer, "Inputs MADI=%s, WordClock=%s\n",
2469 (status & HDSPM_madiLock) ? (x ? "Sync" : "Lock") :
2471 (status2 & HDSPM_wcLock) ? (x2 ? "Sync" : "Lock") :
2474 switch (hdspm_autosync_ref(hdspm)) {
2475 case HDSPM_AUTOSYNC_FROM_WORD:
2476 autosync_ref = "Word Clock";
2478 case HDSPM_AUTOSYNC_FROM_MADI:
2479 autosync_ref = "MADI Sync";
2481 case HDSPM_AUTOSYNC_FROM_NONE:
2482 autosync_ref = "Input not valid";
2485 autosync_ref = "---";
2489 "AutoSync: Reference= %s, Freq=%d (MADI = %d, Word = %d)\n",
2490 autosync_ref, hdspm_external_sample_rate(hdspm),
2491 (status & HDSPM_madiFreqMask) >> 22,
2492 (status2 & HDSPM_wcFreqMask) >> 5);
2494 snd_iprintf(buffer, "Input: %s, Mode=%s\n",
2495 (status & HDSPM_AB_int) ? "Coax" : "Optical",
2496 (status & HDSPM_RX_64ch) ? "64 channels" :
2499 snd_iprintf(buffer, "\n");
2502 static void __devinit snd_hdspm_proc_init(hdspm_t * hdspm)
2504 snd_info_entry_t *entry;
2506 if (!snd_card_proc_new(hdspm->card, "hdspm", &entry))
2507 snd_info_set_text_ops(entry, hdspm, 1024,
2508 snd_hdspm_proc_read);
2511 /*------------------------------------------------------------
2513 ------------------------------------------------------------*/
2515 static int snd_hdspm_set_defaults(hdspm_t * hdspm)
2519 /* ASSUMPTION: hdspm->lock is either held, or there is no need to
2520 hold it (e.g. during module initalization).
2525 hdspm->control_register = HDSPM_ClockModeMaster | /* Master Cloack Mode on */
2526 hdspm_encode_latency(7) | /* latency maximum = 8192 samples */
2527 HDSPM_InputCoaxial | /* Input Coax not Optical */
2528 HDSPM_SyncRef_MADI | /* Madi is syncclock */
2529 HDSPM_LineOut | /* Analog output in */
2530 HDSPM_TX_64ch | /* transmit in 64ch mode */
2531 HDSPM_AutoInp; /* AutoInput chossing (takeover) */
2533 /* ! HDSPM_Frequency0|HDSPM_Frequency1 = 44.1khz */
2534 /* ! HDSPM_DoubleSpeed HDSPM_QuadSpeed = normal speed */
2535 /* ! HDSPM_clr_tms = do not clear bits in track marks */
2537 hdspm_write(hdspm, HDSPM_controlRegister, hdspm->control_register);
2539 #ifdef SNDRV_BIG_ENDIAN
2540 hdspm->control2_register = HDSPM_BIGENDIAN_MODE;
2542 hdspm->control2_register = 0;
2545 hdspm_write(hdspm, HDSPM_control2Reg, hdspm->control2_register);
2546 hdspm_compute_period_size(hdspm);
2548 /* silence everything */
2550 all_in_all_mixer(hdspm, 0 * UNITY_GAIN);
2552 if (line_outs_monitor[hdspm->dev]) {
2554 snd_printk(KERN_INFO "HDSPM: sending all playback streams to line outs.\n");
2556 for (i = 0; i < HDSPM_MIXER_CHANNELS; i++) {
2557 if (hdspm_write_pb_gain(hdspm, i, i, UNITY_GAIN))
2562 /* set a default rate so that the channel map is set up. */
2563 hdspm->channel_map = channel_map_madi_ss;
2564 hdspm_set_rate(hdspm, 44100, 1);
2570 /*------------------------------------------------------------
2572 ------------------------------------------------------------*/
2574 static irqreturn_t snd_hdspm_interrupt(int irq, void *dev_id,
2575 struct pt_regs *regs)
2577 hdspm_t *hdspm = (hdspm_t *) dev_id;
2578 unsigned int status;
2582 unsigned int midi0status;
2583 unsigned int midi1status;
2586 status = hdspm_read(hdspm, HDSPM_statusRegister);
2588 audio = status & HDSPM_audioIRQPending;
2589 midi0 = status & HDSPM_midi0IRQPending;
2590 midi1 = status & HDSPM_midi1IRQPending;
2592 if (!audio && !midi0 && !midi1)
2595 hdspm_write(hdspm, HDSPM_interruptConfirmation, 0);
2598 midi0status = hdspm_read(hdspm, HDSPM_midiStatusIn0) & 0xff;
2599 midi1status = hdspm_read(hdspm, HDSPM_midiStatusIn1) & 0xff;
2603 if (hdspm->capture_substream)
2604 snd_pcm_period_elapsed(hdspm->pcm->
2606 [SNDRV_PCM_STREAM_CAPTURE].
2609 if (hdspm->playback_substream)
2610 snd_pcm_period_elapsed(hdspm->pcm->
2612 [SNDRV_PCM_STREAM_PLAYBACK].
2616 if (midi0 && midi0status) {
2617 /* we disable interrupts for this input until processing is done */
2618 hdspm->control_register &= ~HDSPM_Midi0InterruptEnable;
2619 hdspm_write(hdspm, HDSPM_controlRegister,
2620 hdspm->control_register);
2621 hdspm->midi[0].pending = 1;
2624 if (midi1 && midi1status) {
2625 /* we disable interrupts for this input until processing is done */
2626 hdspm->control_register &= ~HDSPM_Midi1InterruptEnable;
2627 hdspm_write(hdspm, HDSPM_controlRegister,
2628 hdspm->control_register);
2629 hdspm->midi[1].pending = 1;
2633 tasklet_hi_schedule(&hdspm->midi_tasklet);
2637 /*------------------------------------------------------------
2639 ------------------------------------------------------------*/
2642 static snd_pcm_uframes_t snd_hdspm_hw_pointer(snd_pcm_substream_t *
2645 hdspm_t *hdspm = snd_pcm_substream_chip(substream);
2646 return hdspm_hw_pointer(hdspm);
2649 static char *hdspm_channel_buffer_location(hdspm_t * hdspm,
2650 int stream, int channel)
2654 snd_assert(channel >= 0
2655 || channel < HDSPM_MAX_CHANNELS, return NULL);
2657 if ((mapped_channel = hdspm->channel_map[channel]) < 0)
2660 if (stream == SNDRV_PCM_STREAM_CAPTURE) {
2661 return hdspm->capture_buffer +
2662 mapped_channel * HDSPM_CHANNEL_BUFFER_BYTES;
2664 return hdspm->playback_buffer +
2665 mapped_channel * HDSPM_CHANNEL_BUFFER_BYTES;
2670 /* dont know why need it ??? */
2671 static int snd_hdspm_playback_copy(snd_pcm_substream_t * substream,
2672 int channel, snd_pcm_uframes_t pos,
2673 void __user *src, snd_pcm_uframes_t count)
2675 hdspm_t *hdspm = snd_pcm_substream_chip(substream);
2678 snd_assert(pos + count <= HDSPM_CHANNEL_BUFFER_BYTES / 4,
2681 channel_buf = hdspm_channel_buffer_location(hdspm,
2685 snd_assert(channel_buf != NULL, return -EIO);
2687 return copy_from_user(channel_buf + pos * 4, src, count * 4);
2690 static int snd_hdspm_capture_copy(snd_pcm_substream_t * substream,
2691 int channel, snd_pcm_uframes_t pos,
2692 void __user *dst, snd_pcm_uframes_t count)
2694 hdspm_t *hdspm = snd_pcm_substream_chip(substream);
2697 snd_assert(pos + count <= HDSPM_CHANNEL_BUFFER_BYTES / 4,
2700 channel_buf = hdspm_channel_buffer_location(hdspm,
2703 snd_assert(channel_buf != NULL, return -EIO);
2704 return copy_to_user(dst, channel_buf + pos * 4, count * 4);
2707 static int snd_hdspm_hw_silence(snd_pcm_substream_t * substream,
2708 int channel, snd_pcm_uframes_t pos,
2709 snd_pcm_uframes_t count)
2711 hdspm_t *hdspm = snd_pcm_substream_chip(substream);
2715 hdspm_channel_buffer_location(hdspm, substream->pstr->stream,
2717 snd_assert(channel_buf != NULL, return -EIO);
2718 memset(channel_buf + pos * 4, 0, count * 4);
2722 static int snd_hdspm_reset(snd_pcm_substream_t * substream)
2724 snd_pcm_runtime_t *runtime = substream->runtime;
2725 hdspm_t *hdspm = snd_pcm_substream_chip(substream);
2726 snd_pcm_substream_t *other;
2728 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
2729 other = hdspm->capture_substream;
2731 other = hdspm->playback_substream;
2734 runtime->status->hw_ptr = hdspm_hw_pointer(hdspm);
2736 runtime->status->hw_ptr = 0;
2738 struct list_head *pos;
2739 snd_pcm_substream_t *s;
2740 snd_pcm_runtime_t *oruntime = other->runtime;
2741 snd_pcm_group_for_each(pos, substream) {
2742 s = snd_pcm_group_substream_entry(pos);
2744 oruntime->status->hw_ptr =
2745 runtime->status->hw_ptr;
2753 static int snd_hdspm_hw_params(snd_pcm_substream_t * substream,
2754 snd_pcm_hw_params_t * params)
2756 hdspm_t *hdspm = snd_pcm_substream_chip(substream);
2761 struct snd_sg_buf *sgbuf;
2764 spin_lock_irq(&hdspm->lock);
2766 if (substream->pstr->stream == SNDRV_PCM_STREAM_PLAYBACK) {
2767 this_pid = hdspm->playback_pid;
2768 other_pid = hdspm->capture_pid;
2770 this_pid = hdspm->capture_pid;
2771 other_pid = hdspm->playback_pid;
2774 if ((other_pid > 0) && (this_pid != other_pid)) {
2776 /* The other stream is open, and not by the same
2777 task as this one. Make sure that the parameters
2778 that matter are the same.
2781 if (params_rate(params) != hdspm->system_sample_rate) {
2782 spin_unlock_irq(&hdspm->lock);
2783 _snd_pcm_hw_param_setempty(params,
2784 SNDRV_PCM_HW_PARAM_RATE);
2788 if (params_period_size(params) != hdspm->period_bytes / 4) {
2789 spin_unlock_irq(&hdspm->lock);
2790 _snd_pcm_hw_param_setempty(params,
2791 SNDRV_PCM_HW_PARAM_PERIOD_SIZE);
2797 spin_unlock_irq(&hdspm->lock);
2799 /* how to make sure that the rate matches an externally-set one ? */
2801 spin_lock_irq(&hdspm->lock);
2802 if ((err = hdspm_set_rate(hdspm, params_rate(params), 0)) < 0) {
2803 spin_unlock_irq(&hdspm->lock);
2804 _snd_pcm_hw_param_setempty(params,
2805 SNDRV_PCM_HW_PARAM_RATE);
2808 spin_unlock_irq(&hdspm->lock);
2811 hdspm_set_interrupt_interval(hdspm,
2812 params_period_size(params))) <
2814 _snd_pcm_hw_param_setempty(params,
2815 SNDRV_PCM_HW_PARAM_PERIOD_SIZE);
2819 /* Memory allocation, takashi's method, dont know if we should spinlock */
2820 /* malloc all buffer even if not enabled to get sure */
2821 /* malloc only needed bytes */
2823 snd_pcm_lib_malloc_pages(substream,
2824 HDSPM_CHANNEL_BUFFER_BYTES *
2825 params_channels(params));
2829 sgbuf = snd_pcm_substream_sgbuf(substream);
2831 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
2833 hdspm_set_sgbuf(hdspm, sgbuf, HDSPM_pageAddressBufferOut,
2834 params_channels(params));
2836 for (i = 0; i < params_channels(params); ++i)
2837 snd_hdspm_enable_out(hdspm, i, 1);
2839 hdspm->playback_buffer =
2840 (unsigned char *) substream->runtime->dma_area;
2842 hdspm_set_sgbuf(hdspm, sgbuf, HDSPM_pageAddressBufferIn,
2843 params_channels(params));
2845 for (i = 0; i < params_channels(params); ++i)
2846 snd_hdspm_enable_in(hdspm, i, 1);
2848 hdspm->capture_buffer =
2849 (unsigned char *) substream->runtime->dma_area;
2854 static int snd_hdspm_hw_free(snd_pcm_substream_t * substream)
2857 hdspm_t *hdspm = snd_pcm_substream_chip(substream);
2859 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
2861 /* params_channels(params) should be enough,
2862 but to get sure in case of error */
2863 for (i = 0; i < HDSPM_MAX_CHANNELS; ++i)
2864 snd_hdspm_enable_out(hdspm, i, 0);
2866 hdspm->playback_buffer = NULL;
2868 for (i = 0; i < HDSPM_MAX_CHANNELS; ++i)
2869 snd_hdspm_enable_in(hdspm, i, 0);
2871 hdspm->capture_buffer = NULL;
2875 snd_pcm_lib_free_pages(substream);
2880 static int snd_hdspm_channel_info(snd_pcm_substream_t * substream,
2881 snd_pcm_channel_info_t * info)
2883 hdspm_t *hdspm = snd_pcm_substream_chip(substream);
2886 snd_assert(info->channel < HDSPM_MAX_CHANNELS, return -EINVAL);
2888 if ((mapped_channel = hdspm->channel_map[info->channel]) < 0)
2891 info->offset = mapped_channel * HDSPM_CHANNEL_BUFFER_BYTES;
2897 static int snd_hdspm_ioctl(snd_pcm_substream_t * substream,
2898 unsigned int cmd, void *arg)
2901 case SNDRV_PCM_IOCTL1_RESET:
2903 return snd_hdspm_reset(substream);
2906 case SNDRV_PCM_IOCTL1_CHANNEL_INFO:
2908 snd_pcm_channel_info_t *info = arg;
2909 return snd_hdspm_channel_info(substream, info);
2915 return snd_pcm_lib_ioctl(substream, cmd, arg);
2918 static int snd_hdspm_trigger(snd_pcm_substream_t * substream, int cmd)
2920 hdspm_t *hdspm = snd_pcm_substream_chip(substream);
2921 snd_pcm_substream_t *other;
2924 spin_lock(&hdspm->lock);
2925 running = hdspm->running;
2927 case SNDRV_PCM_TRIGGER_START:
2928 running |= 1 << substream->stream;
2930 case SNDRV_PCM_TRIGGER_STOP:
2931 running &= ~(1 << substream->stream);
2935 spin_unlock(&hdspm->lock);
2938 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
2939 other = hdspm->capture_substream;
2941 other = hdspm->playback_substream;
2944 struct list_head *pos;
2945 snd_pcm_substream_t *s;
2946 snd_pcm_group_for_each(pos, substream) {
2947 s = snd_pcm_group_substream_entry(pos);
2949 snd_pcm_trigger_done(s, substream);
2950 if (cmd == SNDRV_PCM_TRIGGER_START)
2951 running |= 1 << s->stream;
2953 running &= ~(1 << s->stream);
2957 if (cmd == SNDRV_PCM_TRIGGER_START) {
2958 if (!(running & (1 << SNDRV_PCM_STREAM_PLAYBACK))
2959 && substream->stream ==
2960 SNDRV_PCM_STREAM_CAPTURE)
2961 hdspm_silence_playback(hdspm);
2964 substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
2965 hdspm_silence_playback(hdspm);
2968 if (substream->stream == SNDRV_PCM_STREAM_CAPTURE)
2969 hdspm_silence_playback(hdspm);
2972 snd_pcm_trigger_done(substream, substream);
2973 if (!hdspm->running && running)
2974 hdspm_start_audio(hdspm);
2975 else if (hdspm->running && !running)
2976 hdspm_stop_audio(hdspm);
2977 hdspm->running = running;
2978 spin_unlock(&hdspm->lock);
2983 static int snd_hdspm_prepare(snd_pcm_substream_t * substream)
2988 static unsigned int period_sizes[] =
2989 { 64, 128, 256, 512, 1024, 2048, 4096, 8192 };
2991 static snd_pcm_hardware_t snd_hdspm_playback_subinfo = {
2992 .info = (SNDRV_PCM_INFO_MMAP |
2993 SNDRV_PCM_INFO_MMAP_VALID |
2994 SNDRV_PCM_INFO_NONINTERLEAVED |
2995 SNDRV_PCM_INFO_SYNC_START | SNDRV_PCM_INFO_DOUBLE),
2996 .formats = SNDRV_PCM_FMTBIT_S32_LE,
2997 .rates = (SNDRV_PCM_RATE_32000 |
2998 SNDRV_PCM_RATE_44100 |
2999 SNDRV_PCM_RATE_48000 |
3000 SNDRV_PCM_RATE_64000 |
3001 SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000),
3005 .channels_max = HDSPM_MAX_CHANNELS,
3007 HDSPM_CHANNEL_BUFFER_BYTES * HDSPM_MAX_CHANNELS,
3008 .period_bytes_min = (64 * 4),
3009 .period_bytes_max = (8192 * 4) * HDSPM_MAX_CHANNELS,
3015 static snd_pcm_hardware_t snd_hdspm_capture_subinfo = {
3016 .info = (SNDRV_PCM_INFO_MMAP |
3017 SNDRV_PCM_INFO_MMAP_VALID |
3018 SNDRV_PCM_INFO_NONINTERLEAVED |
3019 SNDRV_PCM_INFO_SYNC_START),
3020 .formats = SNDRV_PCM_FMTBIT_S32_LE,
3021 .rates = (SNDRV_PCM_RATE_32000 |
3022 SNDRV_PCM_RATE_44100 |
3023 SNDRV_PCM_RATE_48000 |
3024 SNDRV_PCM_RATE_64000 |
3025 SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000),
3029 .channels_max = HDSPM_MAX_CHANNELS,
3031 HDSPM_CHANNEL_BUFFER_BYTES * HDSPM_MAX_CHANNELS,
3032 .period_bytes_min = (64 * 4),
3033 .period_bytes_max = (8192 * 4) * HDSPM_MAX_CHANNELS,
3039 static snd_pcm_hw_constraint_list_t hw_constraints_period_sizes = {
3040 .count = ARRAY_SIZE(period_sizes),
3041 .list = period_sizes,
3046 static int snd_hdspm_hw_rule_channels_rate(snd_pcm_hw_params_t * params,
3047 snd_pcm_hw_rule_t * rule)
3049 hdspm_t *hdspm = rule->private;
3051 hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS);
3053 hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE);
3055 if (r->min > 48000) {
3056 snd_interval_t t = {
3058 .max = hdspm->ds_channels,
3061 return snd_interval_refine(c, &t);
3062 } else if (r->max < 64000) {
3063 snd_interval_t t = {
3065 .max = hdspm->ss_channels,
3068 return snd_interval_refine(c, &t);
3073 static int snd_hdspm_hw_rule_rate_channels(snd_pcm_hw_params_t * params,
3074 snd_pcm_hw_rule_t * rule)
3076 hdspm_t *hdspm = rule->private;
3078 hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS);
3080 hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE);
3082 if (c->min <= hdspm->ss_channels) {
3083 snd_interval_t t = {
3088 return snd_interval_refine(r, &t);
3089 } else if (c->max > hdspm->ss_channels) {
3090 snd_interval_t t = {
3096 return snd_interval_refine(r, &t);
3101 static int snd_hdspm_playback_open(snd_pcm_substream_t * substream)
3103 hdspm_t *hdspm = snd_pcm_substream_chip(substream);
3104 snd_pcm_runtime_t *runtime = substream->runtime;
3106 snd_printdd("Open device substream %d\n", substream->stream);
3108 spin_lock_irq(&hdspm->lock);
3110 snd_pcm_set_sync(substream);
3112 runtime->hw = snd_hdspm_playback_subinfo;
3114 if (hdspm->capture_substream == NULL)
3115 hdspm_stop_audio(hdspm);
3117 hdspm->playback_pid = current->pid;
3118 hdspm->playback_substream = substream;
3120 spin_unlock_irq(&hdspm->lock);
3122 snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24);
3124 snd_pcm_hw_constraint_list(runtime, 0,
3125 SNDRV_PCM_HW_PARAM_PERIOD_SIZE,
3126 &hw_constraints_period_sizes);
3128 snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
3129 snd_hdspm_hw_rule_channels_rate, hdspm,
3130 SNDRV_PCM_HW_PARAM_RATE, -1);
3132 snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
3133 snd_hdspm_hw_rule_rate_channels, hdspm,
3134 SNDRV_PCM_HW_PARAM_CHANNELS, -1);
3139 static int snd_hdspm_playback_release(snd_pcm_substream_t * substream)
3141 hdspm_t *hdspm = snd_pcm_substream_chip(substream);
3143 spin_lock_irq(&hdspm->lock);
3145 hdspm->playback_pid = -1;
3146 hdspm->playback_substream = NULL;
3148 spin_unlock_irq(&hdspm->lock);
3154 static int snd_hdspm_capture_open(snd_pcm_substream_t * substream)
3156 hdspm_t *hdspm = snd_pcm_substream_chip(substream);
3157 snd_pcm_runtime_t *runtime = substream->runtime;
3159 spin_lock_irq(&hdspm->lock);
3160 snd_pcm_set_sync(substream);
3161 runtime->hw = snd_hdspm_capture_subinfo;
3163 if (hdspm->playback_substream == NULL)
3164 hdspm_stop_audio(hdspm);
3166 hdspm->capture_pid = current->pid;
3167 hdspm->capture_substream = substream;
3169 spin_unlock_irq(&hdspm->lock);
3171 snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24);
3172 snd_pcm_hw_constraint_list(runtime, 0,
3173 SNDRV_PCM_HW_PARAM_PERIOD_SIZE,
3174 &hw_constraints_period_sizes);
3176 snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
3177 snd_hdspm_hw_rule_channels_rate, hdspm,
3178 SNDRV_PCM_HW_PARAM_RATE, -1);
3180 snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
3181 snd_hdspm_hw_rule_rate_channels, hdspm,
3182 SNDRV_PCM_HW_PARAM_CHANNELS, -1);
3186 static int snd_hdspm_capture_release(snd_pcm_substream_t * substream)
3188 hdspm_t *hdspm = snd_pcm_substream_chip(substream);
3190 spin_lock_irq(&hdspm->lock);
3192 hdspm->capture_pid = -1;
3193 hdspm->capture_substream = NULL;
3195 spin_unlock_irq(&hdspm->lock);
3199 static int snd_hdspm_hwdep_dummy_op(snd_hwdep_t * hw, struct file *file)
3201 /* we have nothing to initialize but the call is required */
3206 static int snd_hdspm_hwdep_ioctl(snd_hwdep_t * hw, struct file *file,
3207 unsigned int cmd, unsigned long arg)
3209 hdspm_t *hdspm = (hdspm_t *) hw->private_data;
3210 struct sndrv_hdspm_mixer_ioctl mixer;
3211 hdspm_config_info_t info;
3212 hdspm_version_t hdspm_version;
3213 struct sndrv_hdspm_peak_rms_ioctl rms;
3218 case SNDRV_HDSPM_IOCTL_GET_PEAK_RMS:
3219 if (copy_from_user(&rms, (void __user *)arg, sizeof(rms)))
3221 /* maybe there is a chance to memorymap in future so dont touch just copy */
3222 if(copy_to_user_fromio((void __user *)rms.peak,
3223 hdspm->iobase+HDSPM_MADI_peakrmsbase,
3224 sizeof(hdspm_peak_rms_t)) != 0 )
3230 case SNDRV_HDSPM_IOCTL_GET_CONFIG_INFO:
3232 spin_lock_irq(&hdspm->lock);
3233 info.pref_sync_ref =
3234 (unsigned char) hdspm_pref_sync_ref(hdspm);
3235 info.wordclock_sync_check =
3236 (unsigned char) hdspm_wc_sync_check(hdspm);
3238 info.system_sample_rate = hdspm->system_sample_rate;
3239 info.autosync_sample_rate =
3240 hdspm_external_sample_rate(hdspm);
3241 info.system_clock_mode =
3242 (unsigned char) hdspm_system_clock_mode(hdspm);
3244 (unsigned char) hdspm_clock_source(hdspm);
3246 (unsigned char) hdspm_autosync_ref(hdspm);
3247 info.line_out = (unsigned char) hdspm_line_out(hdspm);
3249 spin_unlock_irq(&hdspm->lock);
3250 if (copy_to_user((void __user *) arg, &info, sizeof(info)))
3254 case SNDRV_HDSPM_IOCTL_GET_VERSION:
3255 hdspm_version.firmware_rev = hdspm->firmware_rev;
3256 if (copy_to_user((void __user *) arg, &hdspm_version,
3257 sizeof(hdspm_version)))
3261 case SNDRV_HDSPM_IOCTL_GET_MIXER:
3262 if (copy_from_user(&mixer, (void __user *)arg, sizeof(mixer)))
3265 ((void __user *)mixer.mixer, hdspm->mixer, sizeof(hdspm_mixer_t)))
3275 static snd_pcm_ops_t snd_hdspm_playback_ops = {
3276 .open = snd_hdspm_playback_open,
3277 .close = snd_hdspm_playback_release,
3278 .ioctl = snd_hdspm_ioctl,
3279 .hw_params = snd_hdspm_hw_params,
3280 .hw_free = snd_hdspm_hw_free,
3281 .prepare = snd_hdspm_prepare,
3282 .trigger = snd_hdspm_trigger,
3283 .pointer = snd_hdspm_hw_pointer,
3284 .copy = snd_hdspm_playback_copy,
3285 .silence = snd_hdspm_hw_silence,
3286 .page = snd_pcm_sgbuf_ops_page,
3289 static snd_pcm_ops_t snd_hdspm_capture_ops = {
3290 .open = snd_hdspm_capture_open,
3291 .close = snd_hdspm_capture_release,
3292 .ioctl = snd_hdspm_ioctl,
3293 .hw_params = snd_hdspm_hw_params,
3294 .hw_free = snd_hdspm_hw_free,
3295 .prepare = snd_hdspm_prepare,
3296 .trigger = snd_hdspm_trigger,
3297 .pointer = snd_hdspm_hw_pointer,
3298 .copy = snd_hdspm_capture_copy,
3299 .page = snd_pcm_sgbuf_ops_page,
3302 static int __devinit snd_hdspm_create_hwdep(snd_card_t * card,
3308 if ((err = snd_hwdep_new(card, "HDSPM hwdep", 0, &hw)) < 0)
3312 hw->private_data = hdspm;
3313 strcpy(hw->name, "HDSPM hwdep interface");
3315 hw->ops.open = snd_hdspm_hwdep_dummy_op;
3316 hw->ops.ioctl = snd_hdspm_hwdep_ioctl;
3317 hw->ops.release = snd_hdspm_hwdep_dummy_op;
3323 /*------------------------------------------------------------
3325 ------------------------------------------------------------*/
3326 static int __devinit snd_hdspm_preallocate_memory(hdspm_t * hdspm)
3334 wanted = HDSPM_DMA_AREA_BYTES + 4096; /* dont know why, but it works */
3337 snd_pcm_lib_preallocate_pages_for_all(pcm,
3338 SNDRV_DMA_TYPE_DEV_SG,
3339 snd_dma_pci_data(hdspm->pci),
3342 snd_printdd("Could not preallocate %d Bytes\n", wanted);
3346 snd_printdd(" Preallocated %d Bytes\n", wanted);
3351 static int snd_hdspm_memory_free(hdspm_t * hdspm)
3353 snd_printdd("memory_free_for_all %p\n", hdspm->pcm);
3355 snd_pcm_lib_preallocate_free_for_all(hdspm->pcm);
3360 static void hdspm_set_sgbuf(hdspm_t * hdspm, struct snd_sg_buf *sgbuf,
3361 unsigned int reg, int channels)
3364 for (i = 0; i < (channels * 16); i++)
3365 hdspm_write(hdspm, reg + 4 * i,
3366 snd_pcm_sgbuf_get_addr(sgbuf,
3367 (size_t) 4096 * i));
3370 /* ------------- ALSA Devices ---------------------------- */
3371 static int __devinit snd_hdspm_create_pcm(snd_card_t * card,
3377 if ((err = snd_pcm_new(card, hdspm->card_name, 0, 1, 1, &pcm)) < 0)
3381 pcm->private_data = hdspm;
3382 strcpy(pcm->name, hdspm->card_name);
3384 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK,
3385 &snd_hdspm_playback_ops);
3386 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE,
3387 &snd_hdspm_capture_ops);
3389 pcm->info_flags = SNDRV_PCM_INFO_JOINT_DUPLEX;
3391 if ((err = snd_hdspm_preallocate_memory(hdspm)) < 0)
3397 static inline void snd_hdspm_initialize_midi_flush(hdspm_t * hdspm)
3399 snd_hdspm_flush_midi_input(hdspm, 0);
3400 snd_hdspm_flush_midi_input(hdspm, 1);
3403 static int __devinit snd_hdspm_create_alsa_devices(snd_card_t * card,
3408 snd_printdd("Create card...\n");
3409 if ((err = snd_hdspm_create_pcm(card, hdspm)) < 0)
3412 if ((err = snd_hdspm_create_midi(card, hdspm, 0)) < 0)
3415 if ((err = snd_hdspm_create_midi(card, hdspm, 1)) < 0)
3418 if ((err = snd_hdspm_create_controls(card, hdspm)) < 0)
3421 if ((err = snd_hdspm_create_hwdep(card, hdspm)) < 0)
3424 snd_printdd("proc init...\n");
3425 snd_hdspm_proc_init(hdspm);
3427 hdspm->system_sample_rate = -1;
3428 hdspm->last_external_sample_rate = -1;
3429 hdspm->last_internal_sample_rate = -1;
3430 hdspm->playback_pid = -1;
3431 hdspm->capture_pid = -1;
3432 hdspm->capture_substream = NULL;
3433 hdspm->playback_substream = NULL;
3435 snd_printdd("Set defaults...\n");
3436 if ((err = snd_hdspm_set_defaults(hdspm)) < 0)
3439 snd_printdd("Update mixer controls...\n");
3440 hdspm_update_simple_mixer_controls(hdspm);
3442 snd_printdd("Initializeing complete ???\n");
3444 if ((err = snd_card_register(card)) < 0) {
3445 snd_printk(KERN_ERR "HDSPM: error registering card\n");
3449 snd_printdd("... yes now\n");
3454 static int __devinit snd_hdspm_create(snd_card_t * card, hdspm_t * hdspm,
3455 int precise_ptr, int enable_monitor)
3457 struct pci_dev *pci = hdspm->pci;
3461 unsigned long io_extent;
3464 hdspm->irq_count = 0;
3466 hdspm->midi[0].rmidi = NULL;
3467 hdspm->midi[1].rmidi = NULL;
3468 hdspm->midi[0].input = NULL;
3469 hdspm->midi[1].input = NULL;
3470 hdspm->midi[0].output = NULL;
3471 hdspm->midi[1].output = NULL;
3472 spin_lock_init(&hdspm->midi[0].lock);
3473 spin_lock_init(&hdspm->midi[1].lock);
3474 hdspm->iobase = NULL;
3475 hdspm->control_register = 0;
3476 hdspm->control2_register = 0;
3478 hdspm->playback_buffer = NULL;
3479 hdspm->capture_buffer = NULL;
3481 for (i = 0; i < HDSPM_MAX_CHANNELS; ++i)
3482 hdspm->playback_mixer_ctls[i] = NULL;
3483 hdspm->mixer = NULL;
3487 spin_lock_init(&hdspm->lock);
3489 tasklet_init(&hdspm->midi_tasklet,
3490 hdspm_midi_tasklet, (unsigned long) hdspm);
3492 pci_read_config_word(hdspm->pci,
3493 PCI_CLASS_REVISION, &hdspm->firmware_rev);
3495 strcpy(card->driver, "HDSPM");
3496 strcpy(card->mixername, "Xilinx FPGA");
3497 hdspm->card_name = "RME HDSPM MADI";
3499 if ((err = pci_enable_device(pci)) < 0)
3502 pci_set_master(hdspm->pci);
3504 if ((err = pci_request_regions(pci, "hdspm")) < 0)
3507 hdspm->port = pci_resource_start(pci, 0);
3508 io_extent = pci_resource_len(pci, 0);
3510 snd_printdd("grabbed memory region 0x%lx-0x%lx\n",
3511 hdspm->port, hdspm->port + io_extent - 1);
3514 if ((hdspm->iobase = ioremap_nocache(hdspm->port, io_extent)) == NULL) {
3515 snd_printk(KERN_ERR "HDSPM: unable to remap region 0x%lx-0x%lx\n",
3516 hdspm->port, hdspm->port + io_extent - 1);
3519 snd_printdd("remapped region (0x%lx) 0x%lx-0x%lx\n",
3520 (unsigned long)hdspm->iobase, hdspm->port,
3521 hdspm->port + io_extent - 1);
3523 if (request_irq(pci->irq, snd_hdspm_interrupt,
3524 SA_INTERRUPT | SA_SHIRQ, "hdspm",
3526 snd_printk(KERN_ERR "HDSPM: unable to use IRQ %d\n", pci->irq);
3530 snd_printdd("use IRQ %d\n", pci->irq);
3532 hdspm->irq = pci->irq;
3533 hdspm->precise_ptr = precise_ptr;
3535 hdspm->monitor_outs = enable_monitor;
3537 snd_printdd("kmalloc Mixer memory of %d Bytes\n",
3538 sizeof(hdspm_mixer_t));
3540 (hdspm_mixer_t *) kmalloc(sizeof(hdspm_mixer_t), GFP_KERNEL))
3542 snd_printk(KERN_ERR "HDSPM: unable to kmalloc Mixer memory of %d Bytes\n",
3543 (int)sizeof(hdspm_mixer_t));
3547 hdspm->ss_channels = MADI_SS_CHANNELS;
3548 hdspm->ds_channels = MADI_DS_CHANNELS;
3549 hdspm->qs_channels = MADI_QS_CHANNELS;
3551 snd_printdd("create alsa devices.\n");
3552 if ((err = snd_hdspm_create_alsa_devices(card, hdspm)) < 0)
3555 snd_hdspm_initialize_midi_flush(hdspm);
3560 static int snd_hdspm_free(hdspm_t * hdspm)
3565 /* stop th audio, and cancel all interrupts */
3566 hdspm->control_register &=
3567 ~(HDSPM_Start | HDSPM_AudioInterruptEnable
3568 | HDSPM_Midi0InterruptEnable |
3569 HDSPM_Midi1InterruptEnable);
3570 hdspm_write(hdspm, HDSPM_controlRegister,
3571 hdspm->control_register);
3574 if (hdspm->irq >= 0)
3575 free_irq(hdspm->irq, (void *) hdspm);
3579 kfree(hdspm->mixer);
3582 iounmap(hdspm->iobase);
3584 snd_hdspm_memory_free(hdspm);
3587 pci_release_regions(hdspm->pci);
3589 pci_disable_device(hdspm->pci);
3593 static void snd_hdspm_card_free(snd_card_t * card)
3595 hdspm_t *hdspm = (hdspm_t *) card->private_data;
3598 snd_hdspm_free(hdspm);
3601 static int __devinit snd_hdspm_probe(struct pci_dev *pci,
3602 const struct pci_device_id *pci_id)
3609 if (dev >= SNDRV_CARDS)
3616 if (!(card = snd_card_new(index[dev], id[dev],
3617 THIS_MODULE, sizeof(hdspm_t))))
3620 hdspm = (hdspm_t *) card->private_data;
3621 card->private_free = snd_hdspm_card_free;
3626 snd_hdspm_create(card, hdspm, precise_ptr[dev],
3627 enable_monitor[dev])) < 0) {
3628 snd_card_free(card);
3632 strcpy(card->shortname, "HDSPM MADI");
3633 sprintf(card->longname, "%s at 0x%lx, irq %d", hdspm->card_name,
3634 hdspm->port, hdspm->irq);
3636 if ((err = snd_card_register(card)) < 0) {
3637 snd_card_free(card);
3641 pci_set_drvdata(pci, card);
3647 static void __devexit snd_hdspm_remove(struct pci_dev *pci)
3649 snd_card_free(pci_get_drvdata(pci));
3650 pci_set_drvdata(pci, NULL);
3653 static struct pci_driver driver = {
3654 .name = "RME Hammerfall DSP MADI",
3655 .id_table = snd_hdspm_ids,
3656 .probe = snd_hdspm_probe,
3657 .remove = __devexit_p(snd_hdspm_remove),
3661 static int __init alsa_card_hdspm_init(void)
3663 return pci_register_driver(&driver);
3666 static void __exit alsa_card_hdspm_exit(void)
3668 pci_unregister_driver(&driver);
3671 module_init(alsa_card_hdspm_init)
3672 module_exit(alsa_card_hdspm_exit)