2 * ALSA driver for RME Hammerfall DSP audio interface(s)
4 * Copyright (c) 2002 Paul Davis
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 #include <sound/driver.h>
25 #include <linux/init.h>
26 #include <linux/delay.h>
27 #include <linux/interrupt.h>
28 #include <linux/slab.h>
29 #include <linux/pci.h>
30 #include <linux/moduleparam.h>
32 #include <sound/core.h>
33 #include <sound/control.h>
34 #include <sound/pcm.h>
35 #include <sound/info.h>
36 #include <sound/asoundef.h>
37 #include <sound/rawmidi.h>
38 #include <sound/hwdep.h>
39 #include <sound/initval.h>
40 #include <sound/hdsp.h>
42 #include <asm/byteorder.h>
43 #include <asm/current.h>
46 static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
47 static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
48 static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP; /* Enable this card */
49 static int precise_ptr[SNDRV_CARDS] = { [0 ... (SNDRV_CARDS-1)] = 0 }; /* Enable precise pointer */
50 static int line_outs_monitor[SNDRV_CARDS] = { [0 ... (SNDRV_CARDS-1)] = 0}; /* Send all inputs/playback to line outs */
53 module_param_array(index, int, boot_devs, 0444);
54 MODULE_PARM_DESC(index, "Index value for RME Hammerfall DSP interface.");
55 module_param_array(id, charp, boot_devs, 0444);
56 MODULE_PARM_DESC(id, "ID string for RME Hammerfall DSP interface.");
57 module_param_array(enable, bool, boot_devs, 0444);
58 MODULE_PARM_DESC(enable, "Enable/disable specific Hammerfall DSP soundcards.");
59 module_param_array(precise_ptr, bool, boot_devs, 0444);
60 MODULE_PARM_DESC(precise_ptr, "Enable precise pointer (doesn't work reliably).");
61 module_param_array(line_outs_monitor, bool, boot_devs, 0444);
62 MODULE_PARM_DESC(line_outs_monitor, "Send all input and playback streams to line outs by default.");
63 MODULE_AUTHOR("Paul Davis <paul@linuxaudiosystems.com>, Marcus Andersson, Thomas Charbonnel <thomas@undata.org>");
64 MODULE_DESCRIPTION("RME Hammerfall DSP");
65 MODULE_LICENSE("GPL");
66 MODULE_SUPPORTED_DEVICE("{{RME Hammerfall-DSP},"
70 #define HDSP_MAX_CHANNELS 26
71 #define HDSP_MAX_DS_CHANNELS 14
72 #define HDSP_MAX_QS_CHANNELS 8
73 #define DIGIFACE_SS_CHANNELS 26
74 #define DIGIFACE_DS_CHANNELS 14
75 #define MULTIFACE_SS_CHANNELS 18
76 #define MULTIFACE_DS_CHANNELS 14
77 #define H9652_SS_CHANNELS 26
78 #define H9652_DS_CHANNELS 14
79 /* This does not include possible Analog Extension Boards
80 AEBs are detected at card initialization
82 #define H9632_SS_CHANNELS 12
83 #define H9632_DS_CHANNELS 8
84 #define H9632_QS_CHANNELS 4
86 /* Write registers. These are defined as byte-offsets from the iobase value.
88 #define HDSP_resetPointer 0
89 #define HDSP_outputBufferAddress 32
90 #define HDSP_inputBufferAddress 36
91 #define HDSP_controlRegister 64
92 #define HDSP_interruptConfirmation 96
93 #define HDSP_outputEnable 128
94 #define HDSP_control2Reg 256
95 #define HDSP_midiDataOut0 352
96 #define HDSP_midiDataOut1 356
97 #define HDSP_fifoData 368
98 #define HDSP_inputEnable 384
100 /* Read registers. These are defined as byte-offsets from the iobase value
103 #define HDSP_statusRegister 0
104 #define HDSP_timecode 128
105 #define HDSP_status2Register 192
106 #define HDSP_midiDataOut0 352
107 #define HDSP_midiDataOut1 356
108 #define HDSP_midiDataIn0 360
109 #define HDSP_midiDataIn1 364
110 #define HDSP_midiStatusOut0 384
111 #define HDSP_midiStatusOut1 388
112 #define HDSP_midiStatusIn0 392
113 #define HDSP_midiStatusIn1 396
114 #define HDSP_fifoStatus 400
116 /* the meters are regular i/o-mapped registers, but offset
117 considerably from the rest. the peak registers are reset
118 when read; the least-significant 4 bits are full-scale counters;
119 the actual peak value is in the most-significant 24 bits.
122 #define HDSP_playbackPeakLevel 4096 /* 26 * 32 bit values */
123 #define HDSP_inputPeakLevel 4224 /* 26 * 32 bit values */
124 #define HDSP_outputPeakLevel 4352 /* (26+2) * 32 bit values */
125 #define HDSP_playbackRmsLevel 4612 /* 26 * 64 bit values */
126 #define HDSP_inputRmsLevel 4868 /* 26 * 64 bit values */
129 /* This is for H9652 cards
130 Peak values are read downward from the base
131 Rms values are read upward
132 There are rms values for the outputs too
133 26*3 values are read in ss mode
134 14*3 in ds mode, with no gap between values
136 #define HDSP_9652_peakBase 7164
137 #define HDSP_9652_rmsBase 4096
139 /* c.f. the hdsp_9632_meters_t struct */
140 #define HDSP_9632_metersBase 4096
142 #define HDSP_IO_EXTENT 7168
144 /* control2 register bits */
146 #define HDSP_TMS 0x01
147 #define HDSP_TCK 0x02
148 #define HDSP_TDI 0x04
149 #define HDSP_JTAG 0x08
150 #define HDSP_PWDN 0x10
151 #define HDSP_PROGRAM 0x020
152 #define HDSP_CONFIG_MODE_0 0x040
153 #define HDSP_CONFIG_MODE_1 0x080
154 #define HDSP_VERSION_BIT 0x100
155 #define HDSP_BIGENDIAN_MODE 0x200
156 #define HDSP_RD_MULTIPLE 0x400
157 #define HDSP_9652_ENABLE_MIXER 0x800
158 #define HDSP_TDO 0x10000000
160 #define HDSP_S_PROGRAM (HDSP_PROGRAM|HDSP_CONFIG_MODE_0)
161 #define HDSP_S_LOAD (HDSP_PROGRAM|HDSP_CONFIG_MODE_1)
163 /* Control Register bits */
165 #define HDSP_Start (1<<0) /* start engine */
166 #define HDSP_Latency0 (1<<1) /* buffer size = 2^n where n is defined by Latency{2,1,0} */
167 #define HDSP_Latency1 (1<<2) /* [ see above ] */
168 #define HDSP_Latency2 (1<<3) /* [ see above ] */
169 #define HDSP_ClockModeMaster (1<<4) /* 1=Master, 0=Slave/Autosync */
170 #define HDSP_AudioInterruptEnable (1<<5) /* what do you think ? */
171 #define HDSP_Frequency0 (1<<6) /* 0=44.1kHz/88.2kHz/176.4kHz 1=48kHz/96kHz/192kHz */
172 #define HDSP_Frequency1 (1<<7) /* 0=32kHz/64kHz/128kHz */
173 #define HDSP_DoubleSpeed (1<<8) /* 0=normal speed, 1=double speed */
174 #define HDSP_SPDIFProfessional (1<<9) /* 0=consumer, 1=professional */
175 #define HDSP_SPDIFEmphasis (1<<10) /* 0=none, 1=on */
176 #define HDSP_SPDIFNonAudio (1<<11) /* 0=off, 1=on */
177 #define HDSP_SPDIFOpticalOut (1<<12) /* 1=use 1st ADAT connector for SPDIF, 0=do not */
178 #define HDSP_SyncRef2 (1<<13)
179 #define HDSP_SPDIFInputSelect0 (1<<14)
180 #define HDSP_SPDIFInputSelect1 (1<<15)
181 #define HDSP_SyncRef0 (1<<16)
182 #define HDSP_SyncRef1 (1<<17)
183 #define HDSP_AnalogExtensionBoard (1<<18) /* For H9632 cards */
184 #define HDSP_XLRBreakoutCable (1<<20) /* For H9632 cards */
185 #define HDSP_Midi0InterruptEnable (1<<22)
186 #define HDSP_Midi1InterruptEnable (1<<23)
187 #define HDSP_LineOut (1<<24)
188 #define HDSP_ADGain0 (1<<25) /* From here : H9632 specific */
189 #define HDSP_ADGain1 (1<<26)
190 #define HDSP_DAGain0 (1<<27)
191 #define HDSP_DAGain1 (1<<28)
192 #define HDSP_PhoneGain0 (1<<29)
193 #define HDSP_PhoneGain1 (1<<30)
194 #define HDSP_QuadSpeed (1<<31)
196 #define HDSP_ADGainMask (HDSP_ADGain0|HDSP_ADGain1)
197 #define HDSP_ADGainMinus10dBV HDSP_ADGainMask
198 #define HDSP_ADGainPlus4dBu (HDSP_ADGain0)
199 #define HDSP_ADGainLowGain 0
201 #define HDSP_DAGainMask (HDSP_DAGain0|HDSP_DAGain1)
202 #define HDSP_DAGainHighGain HDSP_DAGainMask
203 #define HDSP_DAGainPlus4dBu (HDSP_DAGain0)
204 #define HDSP_DAGainMinus10dBV 0
206 #define HDSP_PhoneGainMask (HDSP_PhoneGain0|HDSP_PhoneGain1)
207 #define HDSP_PhoneGain0dB HDSP_PhoneGainMask
208 #define HDSP_PhoneGainMinus6dB (HDSP_PhoneGain0)
209 #define HDSP_PhoneGainMinus12dB 0
211 #define HDSP_LatencyMask (HDSP_Latency0|HDSP_Latency1|HDSP_Latency2)
212 #define HDSP_FrequencyMask (HDSP_Frequency0|HDSP_Frequency1|HDSP_DoubleSpeed|HDSP_QuadSpeed)
214 #define HDSP_SPDIFInputMask (HDSP_SPDIFInputSelect0|HDSP_SPDIFInputSelect1)
215 #define HDSP_SPDIFInputADAT1 0
216 #define HDSP_SPDIFInputCoaxial (HDSP_SPDIFInputSelect0)
217 #define HDSP_SPDIFInputCdrom (HDSP_SPDIFInputSelect1)
218 #define HDSP_SPDIFInputAES (HDSP_SPDIFInputSelect0|HDSP_SPDIFInputSelect1)
220 #define HDSP_SyncRefMask (HDSP_SyncRef0|HDSP_SyncRef1|HDSP_SyncRef2)
221 #define HDSP_SyncRef_ADAT1 0
222 #define HDSP_SyncRef_ADAT2 (HDSP_SyncRef0)
223 #define HDSP_SyncRef_ADAT3 (HDSP_SyncRef1)
224 #define HDSP_SyncRef_SPDIF (HDSP_SyncRef0|HDSP_SyncRef1)
225 #define HDSP_SyncRef_WORD (HDSP_SyncRef2)
226 #define HDSP_SyncRef_ADAT_SYNC (HDSP_SyncRef0|HDSP_SyncRef2)
228 /* Sample Clock Sources */
230 #define HDSP_CLOCK_SOURCE_AUTOSYNC 0
231 #define HDSP_CLOCK_SOURCE_INTERNAL_32KHZ 1
232 #define HDSP_CLOCK_SOURCE_INTERNAL_44_1KHZ 2
233 #define HDSP_CLOCK_SOURCE_INTERNAL_48KHZ 3
234 #define HDSP_CLOCK_SOURCE_INTERNAL_64KHZ 4
235 #define HDSP_CLOCK_SOURCE_INTERNAL_88_2KHZ 5
236 #define HDSP_CLOCK_SOURCE_INTERNAL_96KHZ 6
237 #define HDSP_CLOCK_SOURCE_INTERNAL_128KHZ 7
238 #define HDSP_CLOCK_SOURCE_INTERNAL_176_4KHZ 8
239 #define HDSP_CLOCK_SOURCE_INTERNAL_192KHZ 9
241 /* Preferred sync reference choices - used by "pref_sync_ref" control switch */
243 #define HDSP_SYNC_FROM_WORD 0
244 #define HDSP_SYNC_FROM_SPDIF 1
245 #define HDSP_SYNC_FROM_ADAT1 2
246 #define HDSP_SYNC_FROM_ADAT_SYNC 3
247 #define HDSP_SYNC_FROM_ADAT2 4
248 #define HDSP_SYNC_FROM_ADAT3 5
250 /* SyncCheck status */
252 #define HDSP_SYNC_CHECK_NO_LOCK 0
253 #define HDSP_SYNC_CHECK_LOCK 1
254 #define HDSP_SYNC_CHECK_SYNC 2
256 /* AutoSync references - used by "autosync_ref" control switch */
258 #define HDSP_AUTOSYNC_FROM_WORD 0
259 #define HDSP_AUTOSYNC_FROM_ADAT_SYNC 1
260 #define HDSP_AUTOSYNC_FROM_SPDIF 2
261 #define HDSP_AUTOSYNC_FROM_NONE 3
262 #define HDSP_AUTOSYNC_FROM_ADAT1 4
263 #define HDSP_AUTOSYNC_FROM_ADAT2 5
264 #define HDSP_AUTOSYNC_FROM_ADAT3 6
266 /* Possible sources of S/PDIF input */
268 #define HDSP_SPDIFIN_OPTICAL 0 /* optical (ADAT1) */
269 #define HDSP_SPDIFIN_COAXIAL 1 /* coaxial (RCA) */
270 #define HDSP_SPDIFIN_INTERNAL 2 /* internal (CDROM) */
271 #define HDSP_SPDIFIN_AES 3 /* xlr for H9632 (AES)*/
273 #define HDSP_Frequency32KHz HDSP_Frequency0
274 #define HDSP_Frequency44_1KHz HDSP_Frequency1
275 #define HDSP_Frequency48KHz (HDSP_Frequency1|HDSP_Frequency0)
276 #define HDSP_Frequency64KHz (HDSP_DoubleSpeed|HDSP_Frequency0)
277 #define HDSP_Frequency88_2KHz (HDSP_DoubleSpeed|HDSP_Frequency1)
278 #define HDSP_Frequency96KHz (HDSP_DoubleSpeed|HDSP_Frequency1|HDSP_Frequency0)
279 /* For H9632 cards */
280 #define HDSP_Frequency128KHz (HDSP_QuadSpeed|HDSP_DoubleSpeed|HDSP_Frequency0)
281 #define HDSP_Frequency176_4KHz (HDSP_QuadSpeed|HDSP_DoubleSpeed|HDSP_Frequency1)
282 #define HDSP_Frequency192KHz (HDSP_QuadSpeed|HDSP_DoubleSpeed|HDSP_Frequency1|HDSP_Frequency0)
284 #define hdsp_encode_latency(x) (((x)<<1) & HDSP_LatencyMask)
285 #define hdsp_decode_latency(x) (((x) & HDSP_LatencyMask)>>1)
287 #define hdsp_encode_spdif_in(x) (((x)&0x3)<<14)
288 #define hdsp_decode_spdif_in(x) (((x)>>14)&0x3)
290 /* Status Register bits */
292 #define HDSP_audioIRQPending (1<<0)
293 #define HDSP_Lock2 (1<<1) /* this is for Digiface and H9652 */
294 #define HDSP_spdifFrequency3 HDSP_Lock2 /* this is for H9632 only */
295 #define HDSP_Lock1 (1<<2)
296 #define HDSP_Lock0 (1<<3)
297 #define HDSP_SPDIFSync (1<<4)
298 #define HDSP_TimecodeLock (1<<5)
299 #define HDSP_BufferPositionMask 0x000FFC0 /* Bit 6..15 : h/w buffer pointer */
300 #define HDSP_Sync2 (1<<16)
301 #define HDSP_Sync1 (1<<17)
302 #define HDSP_Sync0 (1<<18)
303 #define HDSP_DoubleSpeedStatus (1<<19)
304 #define HDSP_ConfigError (1<<20)
305 #define HDSP_DllError (1<<21)
306 #define HDSP_spdifFrequency0 (1<<22)
307 #define HDSP_spdifFrequency1 (1<<23)
308 #define HDSP_spdifFrequency2 (1<<24)
309 #define HDSP_SPDIFErrorFlag (1<<25)
310 #define HDSP_BufferID (1<<26)
311 #define HDSP_TimecodeSync (1<<27)
312 #define HDSP_AEBO (1<<28) /* H9632 specific Analog Extension Boards */
313 #define HDSP_AEBI (1<<29) /* 0 = present, 1 = absent */
314 #define HDSP_midi0IRQPending (1<<30)
315 #define HDSP_midi1IRQPending (1<<31)
317 #define HDSP_spdifFrequencyMask (HDSP_spdifFrequency0|HDSP_spdifFrequency1|HDSP_spdifFrequency2)
319 #define HDSP_spdifFrequency32KHz (HDSP_spdifFrequency0)
320 #define HDSP_spdifFrequency44_1KHz (HDSP_spdifFrequency1)
321 #define HDSP_spdifFrequency48KHz (HDSP_spdifFrequency0|HDSP_spdifFrequency1)
323 #define HDSP_spdifFrequency64KHz (HDSP_spdifFrequency2)
324 #define HDSP_spdifFrequency88_2KHz (HDSP_spdifFrequency0|HDSP_spdifFrequency2)
325 #define HDSP_spdifFrequency96KHz (HDSP_spdifFrequency2|HDSP_spdifFrequency1)
327 /* This is for H9632 cards */
328 #define HDSP_spdifFrequency128KHz HDSP_spdifFrequencyMask
329 #define HDSP_spdifFrequency176_4KHz HDSP_spdifFrequency3
330 #define HDSP_spdifFrequency192KHz (HDSP_spdifFrequency3|HDSP_spdifFrequency0)
332 /* Status2 Register bits */
334 #define HDSP_version0 (1<<0)
335 #define HDSP_version1 (1<<1)
336 #define HDSP_version2 (1<<2)
337 #define HDSP_wc_lock (1<<3)
338 #define HDSP_wc_sync (1<<4)
339 #define HDSP_inp_freq0 (1<<5)
340 #define HDSP_inp_freq1 (1<<6)
341 #define HDSP_inp_freq2 (1<<7)
342 #define HDSP_SelSyncRef0 (1<<8)
343 #define HDSP_SelSyncRef1 (1<<9)
344 #define HDSP_SelSyncRef2 (1<<10)
346 #define HDSP_wc_valid (HDSP_wc_lock|HDSP_wc_sync)
348 #define HDSP_systemFrequencyMask (HDSP_inp_freq0|HDSP_inp_freq1|HDSP_inp_freq2)
349 #define HDSP_systemFrequency32 (HDSP_inp_freq0)
350 #define HDSP_systemFrequency44_1 (HDSP_inp_freq1)
351 #define HDSP_systemFrequency48 (HDSP_inp_freq0|HDSP_inp_freq1)
352 #define HDSP_systemFrequency64 (HDSP_inp_freq2)
353 #define HDSP_systemFrequency88_2 (HDSP_inp_freq0|HDSP_inp_freq2)
354 #define HDSP_systemFrequency96 (HDSP_inp_freq1|HDSP_inp_freq2)
355 /* FIXME : more values for 9632 cards ? */
357 #define HDSP_SelSyncRefMask (HDSP_SelSyncRef0|HDSP_SelSyncRef1|HDSP_SelSyncRef2)
358 #define HDSP_SelSyncRef_ADAT1 0
359 #define HDSP_SelSyncRef_ADAT2 (HDSP_SelSyncRef0)
360 #define HDSP_SelSyncRef_ADAT3 (HDSP_SelSyncRef1)
361 #define HDSP_SelSyncRef_SPDIF (HDSP_SelSyncRef0|HDSP_SelSyncRef1)
362 #define HDSP_SelSyncRef_WORD (HDSP_SelSyncRef2)
363 #define HDSP_SelSyncRef_ADAT_SYNC (HDSP_SelSyncRef0|HDSP_SelSyncRef2)
365 /* Card state flags */
367 #define HDSP_InitializationComplete (1<<0)
368 #define HDSP_FirmwareLoaded (1<<1)
369 #define HDSP_FirmwareCached (1<<2)
371 /* FIFO wait times, defined in terms of 1/10ths of msecs */
373 #define HDSP_LONG_WAIT 5000
374 #define HDSP_SHORT_WAIT 30
376 #define UNITY_GAIN 32768
377 #define MINUS_INFINITY_GAIN 0
379 #ifndef PCI_VENDOR_ID_XILINX
380 #define PCI_VENDOR_ID_XILINX 0x10ee
382 #ifndef PCI_DEVICE_ID_XILINX_HAMMERFALL_DSP
383 #define PCI_DEVICE_ID_XILINX_HAMMERFALL_DSP 0x3fc5
386 /* the size of a substream (1 mono data stream) */
388 #define HDSP_CHANNEL_BUFFER_SAMPLES (16*1024)
389 #define HDSP_CHANNEL_BUFFER_BYTES (4*HDSP_CHANNEL_BUFFER_SAMPLES)
391 /* the size of the area we need to allocate for DMA transfers. the
392 size is the same regardless of the number of channels - the
393 Multiface still uses the same memory area.
395 Note that we allocate 1 more channel than is apparently needed
396 because the h/w seems to write 1 byte beyond the end of the last
400 #define HDSP_DMA_AREA_BYTES ((HDSP_MAX_CHANNELS+1) * HDSP_CHANNEL_BUFFER_BYTES)
401 #define HDSP_DMA_AREA_KILOBYTES (HDSP_DMA_AREA_BYTES/1024)
403 typedef struct _hdsp hdsp_t;
404 typedef struct _hdsp_midi hdsp_midi_t;
405 typedef struct _hdsp_9632_meters hdsp_9632_meters_t;
407 struct _hdsp_9632_meters {
409 u32 playback_peak[16];
413 u32 input_rms_low[16];
414 u32 playback_rms_low[16];
415 u32 output_rms_low[16];
417 u32 input_rms_high[16];
418 u32 playback_rms_high[16];
419 u32 output_rms_high[16];
420 u32 xxx_rms_high[16];
426 snd_rawmidi_t *rmidi;
427 snd_rawmidi_substream_t *input;
428 snd_rawmidi_substream_t *output;
429 char istimer; /* timer in use */
430 struct timer_list timer;
437 snd_pcm_substream_t *capture_substream;
438 snd_pcm_substream_t *playback_substream;
440 struct tasklet_struct midi_tasklet;
442 u32 control_register; /* cached value */
443 u32 control2_register; /* cached value */
445 u32 creg_spdif_stream;
446 char *card_name; /* digiface/multiface */
447 HDSP_IO_Type io_type; /* ditto, but for code use */
448 unsigned short firmware_rev;
449 unsigned short state; /* stores state bits */
450 u32 firmware_cache[24413]; /* this helps recover from accidental iobox power failure */
451 size_t period_bytes; /* guess what this is */
452 unsigned char max_channels;
453 unsigned char qs_in_channels; /* quad speed mode for H9632 */
454 unsigned char ds_in_channels;
455 unsigned char ss_in_channels; /* different for multiface/digiface */
456 unsigned char qs_out_channels;
457 unsigned char ds_out_channels;
458 unsigned char ss_out_channels;
460 struct snd_dma_buffer capture_dma_buf;
461 struct snd_dma_buffer playback_dma_buf;
462 unsigned char *capture_buffer; /* suitably aligned address */
463 unsigned char *playback_buffer; /* suitably aligned address */
468 int passthru; /* non-zero if doing pass-thru */
469 int system_sample_rate;
474 unsigned long iobase;
479 snd_kcontrol_t *spdif_ctl;
480 unsigned short mixer_matrix[HDSP_MATRIX_MIXER_SIZE];
483 /* These tables map the ALSA channels 1..N to the channels that we
484 need to use in order to find the relevant channel buffer. RME
485 refer to this kind of mapping as between "the ADAT channel and
486 the DMA channel." We index it using the logical audio channel,
487 and the value is the DMA channel (i.e. channel buffer number)
488 where the data for that channel can be read/written from/to.
491 static char channel_map_df_ss[HDSP_MAX_CHANNELS] = {
492 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
493 18, 19, 20, 21, 22, 23, 24, 25
496 static char channel_map_mf_ss[HDSP_MAX_CHANNELS] = { /* Multiface */
498 0, 1, 2, 3, 4, 5, 6, 7,
500 16, 17, 18, 19, 20, 21, 22, 23,
503 -1, -1, -1, -1, -1, -1, -1, -1
506 static char channel_map_ds[HDSP_MAX_CHANNELS] = {
507 /* ADAT channels are remapped */
508 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23,
509 /* channels 12 and 13 are S/PDIF */
511 /* others don't exist */
512 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
515 static char channel_map_H9632_ss[HDSP_MAX_CHANNELS] = {
517 0, 1, 2, 3, 4, 5, 6, 7,
522 /* AO4S-192 and AI4S-192 extension boards */
524 /* others don't exist */
525 -1, -1, -1, -1, -1, -1, -1, -1,
529 static char channel_map_H9632_ds[HDSP_MAX_CHANNELS] = {
536 /* AO4S-192 and AI4S-192 extension boards */
538 /* others don't exist */
539 -1, -1, -1, -1, -1, -1, -1, -1,
540 -1, -1, -1, -1, -1, -1
543 static char channel_map_H9632_qs[HDSP_MAX_CHANNELS] = {
544 /* ADAT is disabled in this mode */
549 /* AO4S-192 and AI4S-192 extension boards */
551 /* others don't exist */
552 -1, -1, -1, -1, -1, -1, -1, -1,
553 -1, -1, -1, -1, -1, -1, -1, -1,
557 static int snd_hammerfall_get_buffer(struct pci_dev *pci, struct snd_dma_buffer *dmab, size_t size)
559 dmab->dev.type = SNDRV_DMA_TYPE_DEV;
560 dmab->dev.dev = snd_dma_pci_data(pci);
561 if (! snd_dma_get_reserved_buf(dmab, snd_dma_pci_buf_id(pci))) {
562 if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(pci),
569 static void snd_hammerfall_free_buffer(struct snd_dma_buffer *dmab, struct pci_dev *pci)
572 snd_dma_reserve_buf(dmab, snd_dma_pci_buf_id(pci));
576 static struct pci_device_id snd_hdsp_ids[] = {
578 .vendor = PCI_VENDOR_ID_XILINX,
579 .device = PCI_DEVICE_ID_XILINX_HAMMERFALL_DSP,
580 .subvendor = PCI_ANY_ID,
581 .subdevice = PCI_ANY_ID,
582 }, /* RME Hammerfall-DSP */
586 MODULE_DEVICE_TABLE(pci, snd_hdsp_ids);
589 static int __devinit snd_hdsp_create_alsa_devices(snd_card_t *card, hdsp_t *hdsp);
590 static int __devinit snd_hdsp_create_pcm(snd_card_t *card, hdsp_t *hdsp);
591 static int snd_hdsp_enable_io (hdsp_t *hdsp);
592 static void snd_hdsp_initialize_midi_flush (hdsp_t *hdsp);
593 static void snd_hdsp_initialize_channels (hdsp_t *hdsp);
594 static int hdsp_fifo_wait(hdsp_t *hdsp, int count, int timeout);
595 static int hdsp_autosync_ref(hdsp_t *hdsp);
596 static int snd_hdsp_set_defaults(hdsp_t *hdsp);
597 static void snd_hdsp_9652_enable_mixer (hdsp_t *hdsp);
599 static int hdsp_playback_to_output_key (hdsp_t *hdsp, int in, int out)
601 switch (hdsp->firmware_rev) {
603 return (64 * out) + (32 + (in));
606 return (32 * out) + (16 + (in));
608 return (52 * out) + (26 + (in));
612 static int hdsp_input_to_output_key (hdsp_t *hdsp, int in, int out)
614 switch (hdsp->firmware_rev) {
616 return (64 * out) + in;
619 return (32 * out) + in;
621 return (52 * out) + in;
625 static void hdsp_write(hdsp_t *hdsp, int reg, int val)
627 writel(val, hdsp->iobase + reg);
630 static unsigned int hdsp_read(hdsp_t *hdsp, int reg)
632 return readl (hdsp->iobase + reg);
635 static int hdsp_check_for_iobox (hdsp_t *hdsp)
638 if (hdsp->io_type == H9652 || hdsp->io_type == H9632) return 0;
639 if (hdsp_read (hdsp, HDSP_statusRegister) & HDSP_ConfigError) {
640 snd_printk ("Hammerfall-DSP: no Digiface or Multiface connected!\n");
641 hdsp->state &= ~HDSP_FirmwareLoaded;
648 static int snd_hdsp_load_firmware_from_cache(hdsp_t *hdsp) {
653 if ((hdsp_read (hdsp, HDSP_statusRegister) & HDSP_DllError) != 0) {
655 snd_printk ("loading firmware\n");
657 hdsp_write (hdsp, HDSP_control2Reg, HDSP_S_PROGRAM);
658 hdsp_write (hdsp, HDSP_fifoData, 0);
660 if (hdsp_fifo_wait (hdsp, 0, HDSP_LONG_WAIT)) {
661 snd_printk ("timeout waiting for download preparation\n");
665 hdsp_write (hdsp, HDSP_control2Reg, HDSP_S_LOAD);
667 for (i = 0; i < 24413; ++i) {
668 hdsp_write(hdsp, HDSP_fifoData, hdsp->firmware_cache[i]);
669 if (hdsp_fifo_wait (hdsp, 127, HDSP_LONG_WAIT)) {
670 snd_printk ("timeout during firmware loading\n");
675 if ((1000 / HZ) < 3000) {
676 set_current_state(TASK_UNINTERRUPTIBLE);
677 schedule_timeout((3000 * HZ + 999) / 1000);
682 if (hdsp_fifo_wait (hdsp, 0, HDSP_LONG_WAIT)) {
683 snd_printk ("timeout at end of firmware loading\n");
687 #ifdef SNDRV_BIG_ENDIAN
688 hdsp->control2_register = HDSP_BIGENDIAN_MODE;
690 hdsp->control2_register = 0;
692 hdsp_write (hdsp, HDSP_control2Reg, hdsp->control2_register);
693 snd_printk ("finished firmware loading\n");
696 if (hdsp->state & HDSP_InitializationComplete) {
697 snd_printk("firmware loaded from cache, restoring defaults\n");
698 spin_lock_irqsave(&hdsp->lock, flags);
699 snd_hdsp_set_defaults(hdsp);
700 spin_unlock_irqrestore(&hdsp->lock, flags);
703 hdsp->state |= HDSP_FirmwareLoaded;
708 static int hdsp_get_iobox_version (hdsp_t *hdsp)
712 if (hdsp_check_for_iobox (hdsp)) {
716 if ((err = snd_hdsp_enable_io(hdsp)) < 0) {
720 if ((hdsp_read (hdsp, HDSP_statusRegister) & HDSP_DllError) != 0) {
722 hdsp_write (hdsp, HDSP_control2Reg, HDSP_PROGRAM);
723 hdsp_write (hdsp, HDSP_fifoData, 0);
724 if (hdsp_fifo_wait (hdsp, 0, HDSP_SHORT_WAIT) < 0) {
728 hdsp_write (hdsp, HDSP_control2Reg, HDSP_S_LOAD);
729 hdsp_write (hdsp, HDSP_fifoData, 0);
731 if (hdsp_fifo_wait (hdsp, 0, HDSP_SHORT_WAIT)) {
732 hdsp->io_type = Multiface;
733 hdsp_write (hdsp, HDSP_control2Reg, HDSP_VERSION_BIT);
734 hdsp_write (hdsp, HDSP_control2Reg, HDSP_S_LOAD);
735 hdsp_fifo_wait (hdsp, 0, HDSP_SHORT_WAIT);
737 hdsp->io_type = Digiface;
740 /* firmware was already loaded, get iobox type */
741 if (hdsp_read(hdsp, HDSP_status2Register) & HDSP_version1) {
742 hdsp->io_type = Multiface;
744 hdsp->io_type = Digiface;
751 static int hdsp_check_for_firmware (hdsp_t *hdsp)
753 if (hdsp->io_type == H9652 || hdsp->io_type == H9632) return 0;
754 if ((hdsp_read (hdsp, HDSP_statusRegister) & HDSP_DllError) != 0) {
755 snd_printk("firmware not present.\n");
756 hdsp->state &= ~HDSP_FirmwareLoaded;
763 static int hdsp_fifo_wait(hdsp_t *hdsp, int count, int timeout)
767 /* the fifoStatus registers reports on how many words
768 are available in the command FIFO.
771 for (i = 0; i < timeout; i++) {
773 if ((int)(hdsp_read (hdsp, HDSP_fifoStatus) & 0xff) <= count)
776 /* not very friendly, but we only do this during a firmware
777 load and changing the mixer, so we just put up with it.
783 snd_printk ("wait for FIFO status <= %d failed after %d iterations\n",
788 static int hdsp_read_gain (hdsp_t *hdsp, unsigned int addr)
790 if (addr >= HDSP_MATRIX_MIXER_SIZE) {
793 return hdsp->mixer_matrix[addr];
796 static int hdsp_write_gain(hdsp_t *hdsp, unsigned int addr, unsigned short data)
800 if (addr >= HDSP_MATRIX_MIXER_SIZE)
803 if (hdsp->io_type == H9652 || hdsp->io_type == H9632) {
805 /* from martin björnsen:
807 "You can only write dwords to the
808 mixer memory which contain two
809 mixer values in the low and high
810 word. So if you want to change
811 value 0 you have to read value 1
812 from the cache and write both to
813 the first dword in the mixer
817 if (hdsp->io_type == H9632 && addr >= 512) {
821 if (hdsp->io_type == H9652 && addr >= 1352) {
825 hdsp->mixer_matrix[addr] = data;
828 /* `addr' addresses a 16-bit wide address, but
829 the address space accessed via hdsp_write
830 uses byte offsets. put another way, addr
831 varies from 0 to 1351, but to access the
832 corresponding memory location, we need
833 to access 0 to 2703 ...
837 hdsp_write (hdsp, 4096 + (ad*4),
838 (hdsp->mixer_matrix[(addr&0x7fe)+1] << 16) +
839 hdsp->mixer_matrix[addr&0x7fe]);
845 ad = (addr << 16) + data;
847 if (hdsp_fifo_wait(hdsp, 127, HDSP_LONG_WAIT)) {
851 hdsp_write (hdsp, HDSP_fifoData, ad);
852 hdsp->mixer_matrix[addr] = data;
859 static int snd_hdsp_use_is_exclusive(hdsp_t *hdsp)
864 spin_lock_irqsave(&hdsp->lock, flags);
865 if ((hdsp->playback_pid != hdsp->capture_pid) &&
866 (hdsp->playback_pid >= 0) && (hdsp->capture_pid >= 0)) {
869 spin_unlock_irqrestore(&hdsp->lock, flags);
873 static int hdsp_external_sample_rate (hdsp_t *hdsp)
875 unsigned int status2 = hdsp_read(hdsp, HDSP_status2Register);
876 unsigned int rate_bits = status2 & HDSP_systemFrequencyMask;
879 case HDSP_systemFrequency32: return 32000;
880 case HDSP_systemFrequency44_1: return 44100;
881 case HDSP_systemFrequency48: return 48000;
882 case HDSP_systemFrequency64: return 64000;
883 case HDSP_systemFrequency88_2: return 88200;
884 case HDSP_systemFrequency96: return 96000;
890 static int hdsp_spdif_sample_rate(hdsp_t *hdsp)
892 unsigned int status = hdsp_read(hdsp, HDSP_statusRegister);
893 unsigned int rate_bits = (status & HDSP_spdifFrequencyMask);
895 if (status & HDSP_SPDIFErrorFlag) {
900 case HDSP_spdifFrequency32KHz: return 32000;
901 case HDSP_spdifFrequency44_1KHz: return 44100;
902 case HDSP_spdifFrequency48KHz: return 48000;
903 case HDSP_spdifFrequency64KHz: return 64000;
904 case HDSP_spdifFrequency88_2KHz: return 88200;
905 case HDSP_spdifFrequency96KHz: return 96000;
906 case HDSP_spdifFrequency128KHz:
907 if (hdsp->io_type == H9632) return 128000;
909 case HDSP_spdifFrequency176_4KHz:
910 if (hdsp->io_type == H9632) return 176400;
912 case HDSP_spdifFrequency192KHz:
913 if (hdsp->io_type == H9632) return 192000;
918 snd_printk ("unknown spdif frequency status; bits = 0x%x, status = 0x%x\n", rate_bits, status);
922 static void hdsp_compute_period_size(hdsp_t *hdsp)
924 hdsp->period_bytes = 1 << ((hdsp_decode_latency(hdsp->control_register) + 8));
927 static snd_pcm_uframes_t hdsp_hw_pointer(hdsp_t *hdsp)
931 position = hdsp_read(hdsp, HDSP_statusRegister);
933 if (!hdsp->precise_ptr) {
934 return (position & HDSP_BufferID) ? (hdsp->period_bytes / 4) : 0;
937 position &= HDSP_BufferPositionMask;
940 position &= (HDSP_CHANNEL_BUFFER_SAMPLES-1);
944 static void hdsp_reset_hw_pointer(hdsp_t *hdsp)
946 hdsp_write (hdsp, HDSP_resetPointer, 0);
949 static void hdsp_start_audio(hdsp_t *s)
951 s->control_register |= (HDSP_AudioInterruptEnable | HDSP_Start);
952 hdsp_write(s, HDSP_controlRegister, s->control_register);
955 static void hdsp_stop_audio(hdsp_t *s)
957 s->control_register &= ~(HDSP_Start | HDSP_AudioInterruptEnable);
958 hdsp_write(s, HDSP_controlRegister, s->control_register);
961 static void hdsp_silence_playback(hdsp_t *hdsp)
963 memset(hdsp->playback_buffer, 0, HDSP_DMA_AREA_BYTES);
966 static int hdsp_set_interrupt_interval(hdsp_t *s, unsigned int frames)
970 spin_lock_irq(&s->lock);
979 s->control_register &= ~HDSP_LatencyMask;
980 s->control_register |= hdsp_encode_latency(n);
982 hdsp_write(s, HDSP_controlRegister, s->control_register);
984 hdsp_compute_period_size(s);
986 spin_unlock_irq(&s->lock);
991 static int hdsp_set_rate(hdsp_t *hdsp, int rate, int called_internally)
993 int reject_if_open = 0;
997 /* ASSUMPTION: hdsp->lock is either held, or
998 there is no need for it (e.g. during module
1002 if (!(hdsp->control_register & HDSP_ClockModeMaster)) {
1003 if (called_internally) {
1004 /* request from ctl or card initialization */
1005 snd_printk("device is not running as a clock master: cannot set sample rate.\n");
1008 /* hw_param request while in AutoSync mode */
1009 int external_freq = hdsp_external_sample_rate(hdsp);
1010 int spdif_freq = hdsp_spdif_sample_rate(hdsp);
1012 if ((spdif_freq == external_freq*2) && (hdsp_autosync_ref(hdsp) >= HDSP_AUTOSYNC_FROM_ADAT1)) {
1013 snd_printk("Detected ADAT in double speed mode\n");
1014 } else if (hdsp->io_type == H9632 && (spdif_freq == external_freq*4) && (hdsp_autosync_ref(hdsp) >= HDSP_AUTOSYNC_FROM_ADAT1)) {
1015 snd_printk("Detected ADAT in quad speed mode\n");
1016 } else if (rate != external_freq) {
1017 snd_printk("No AutoSync source for requested rate\n");
1023 current_rate = hdsp->system_sample_rate;
1025 /* Changing from a "single speed" to a "double speed" rate is
1026 not allowed if any substreams are open. This is because
1027 such a change causes a shift in the location of
1028 the DMA buffers and a reduction in the number of available
1031 Note that a similar but essentially insoluble problem
1032 exists for externally-driven rate changes. All we can do
1033 is to flag rate changes in the read/write routines. */
1035 if (rate > 96000 && hdsp->io_type != H9632) {
1041 if (current_rate > 48000) {
1044 rate_bits = HDSP_Frequency32KHz;
1047 if (current_rate > 48000) {
1050 rate_bits = HDSP_Frequency44_1KHz;
1053 if (current_rate > 48000) {
1056 rate_bits = HDSP_Frequency48KHz;
1059 if (current_rate <= 48000 || current_rate > 96000) {
1062 rate_bits = HDSP_Frequency64KHz;
1065 if (current_rate <= 48000 || current_rate > 96000) {
1068 rate_bits = HDSP_Frequency88_2KHz;
1071 if (current_rate <= 48000 || current_rate > 96000) {
1074 rate_bits = HDSP_Frequency96KHz;
1077 if (current_rate < 128000) {
1080 rate_bits = HDSP_Frequency128KHz;
1083 if (current_rate < 128000) {
1086 rate_bits = HDSP_Frequency176_4KHz;
1089 if (current_rate < 128000) {
1092 rate_bits = HDSP_Frequency192KHz;
1098 if (reject_if_open && (hdsp->capture_pid >= 0 || hdsp->playback_pid >= 0)) {
1099 snd_printk ("cannot change speed mode (capture PID = %d, playback PID = %d)\n",
1101 hdsp->playback_pid);
1105 hdsp->control_register &= ~HDSP_FrequencyMask;
1106 hdsp->control_register |= rate_bits;
1107 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
1109 if (rate >= 128000) {
1110 hdsp->channel_map = channel_map_H9632_qs;
1111 } else if (rate > 48000) {
1112 if (hdsp->io_type == H9632) {
1113 hdsp->channel_map = channel_map_H9632_ds;
1115 hdsp->channel_map = channel_map_ds;
1118 switch (hdsp->io_type) {
1120 hdsp->channel_map = channel_map_mf_ss;
1124 hdsp->channel_map = channel_map_df_ss;
1127 hdsp->channel_map = channel_map_H9632_ss;
1130 /* should never happen */
1135 hdsp->system_sample_rate = rate;
1140 static void hdsp_set_thru(hdsp_t *hdsp, int channel, int enable)
1149 /* set thru for all channels */
1152 for (i = 0; i < hdsp->max_channels; i++) {
1153 hdsp_write_gain (hdsp, hdsp_input_to_output_key(hdsp,i,i), UNITY_GAIN);
1156 for (i = 0; i < hdsp->max_channels; i++) {
1157 hdsp_write_gain (hdsp, hdsp_input_to_output_key(hdsp,i,i), MINUS_INFINITY_GAIN);
1164 snd_assert(channel < hdsp->max_channels, return);
1166 mapped_channel = hdsp->channel_map[channel];
1168 snd_assert(mapped_channel > -1, return);
1171 hdsp_write_gain (hdsp, hdsp_input_to_output_key(hdsp,mapped_channel,mapped_channel), UNITY_GAIN);
1173 hdsp_write_gain (hdsp, hdsp_input_to_output_key(hdsp,mapped_channel,mapped_channel), MINUS_INFINITY_GAIN);
1178 static int hdsp_set_passthru(hdsp_t *hdsp, int onoff)
1181 hdsp_set_thru(hdsp, -1, 1);
1182 hdsp_reset_hw_pointer(hdsp);
1183 hdsp_silence_playback(hdsp);
1185 /* we don't want interrupts, so do a
1186 custom version of hdsp_start_audio().
1189 hdsp->control_register |= (HDSP_Start|HDSP_AudioInterruptEnable|hdsp_encode_latency(7));
1191 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
1194 hdsp_set_thru(hdsp, -1, 0);
1195 hdsp_stop_audio(hdsp);
1202 /*----------------------------------------------------------------------------
1204 ----------------------------------------------------------------------------*/
1206 static unsigned char snd_hdsp_midi_read_byte (hdsp_t *hdsp, int id)
1208 /* the hardware already does the relevant bit-mask with 0xff */
1210 return hdsp_read(hdsp, HDSP_midiDataIn1);
1212 return hdsp_read(hdsp, HDSP_midiDataIn0);
1216 static void snd_hdsp_midi_write_byte (hdsp_t *hdsp, int id, int val)
1218 /* the hardware already does the relevant bit-mask with 0xff */
1220 hdsp_write(hdsp, HDSP_midiDataOut1, val);
1222 hdsp_write(hdsp, HDSP_midiDataOut0, val);
1226 static int snd_hdsp_midi_input_available (hdsp_t *hdsp, int id)
1229 return (hdsp_read(hdsp, HDSP_midiStatusIn1) & 0xff);
1231 return (hdsp_read(hdsp, HDSP_midiStatusIn0) & 0xff);
1235 static int snd_hdsp_midi_output_possible (hdsp_t *hdsp, int id)
1237 int fifo_bytes_used;
1240 fifo_bytes_used = hdsp_read(hdsp, HDSP_midiStatusOut1) & 0xff;
1242 fifo_bytes_used = hdsp_read(hdsp, HDSP_midiStatusOut0) & 0xff;
1245 if (fifo_bytes_used < 128) {
1246 return 128 - fifo_bytes_used;
1252 static void snd_hdsp_flush_midi_input (hdsp_t *hdsp, int id)
1254 while (snd_hdsp_midi_input_available (hdsp, id)) {
1255 snd_hdsp_midi_read_byte (hdsp, id);
1259 static int snd_hdsp_midi_output_write (hdsp_midi_t *hmidi)
1261 unsigned long flags;
1265 unsigned char buf[128];
1267 /* Output is not interrupt driven */
1269 spin_lock_irqsave (&hmidi->lock, flags);
1270 if (hmidi->output) {
1271 if (!snd_rawmidi_transmit_empty (hmidi->output)) {
1272 if ((n_pending = snd_hdsp_midi_output_possible (hmidi->hdsp, hmidi->id)) > 0) {
1273 if (n_pending > (int)sizeof (buf))
1274 n_pending = sizeof (buf);
1276 if ((to_write = snd_rawmidi_transmit (hmidi->output, buf, n_pending)) > 0) {
1277 for (i = 0; i < to_write; ++i)
1278 snd_hdsp_midi_write_byte (hmidi->hdsp, hmidi->id, buf[i]);
1283 spin_unlock_irqrestore (&hmidi->lock, flags);
1287 static int snd_hdsp_midi_input_read (hdsp_midi_t *hmidi)
1289 unsigned char buf[128]; /* this buffer is designed to match the MIDI input FIFO size */
1290 unsigned long flags;
1294 spin_lock_irqsave (&hmidi->lock, flags);
1295 if ((n_pending = snd_hdsp_midi_input_available (hmidi->hdsp, hmidi->id)) > 0) {
1297 if (n_pending > (int)sizeof (buf)) {
1298 n_pending = sizeof (buf);
1300 for (i = 0; i < n_pending; ++i) {
1301 buf[i] = snd_hdsp_midi_read_byte (hmidi->hdsp, hmidi->id);
1304 snd_rawmidi_receive (hmidi->input, buf, n_pending);
1307 /* flush the MIDI input FIFO */
1308 while (--n_pending) {
1309 snd_hdsp_midi_read_byte (hmidi->hdsp, hmidi->id);
1315 hmidi->hdsp->control_register |= HDSP_Midi1InterruptEnable;
1317 hmidi->hdsp->control_register |= HDSP_Midi0InterruptEnable;
1319 hdsp_write(hmidi->hdsp, HDSP_controlRegister, hmidi->hdsp->control_register);
1320 spin_unlock_irqrestore (&hmidi->lock, flags);
1321 return snd_hdsp_midi_output_write (hmidi);
1324 static void snd_hdsp_midi_input_trigger(snd_rawmidi_substream_t * substream, int up)
1328 unsigned long flags;
1331 hmidi = (hdsp_midi_t *) substream->rmidi->private_data;
1333 ie = hmidi->id ? HDSP_Midi1InterruptEnable : HDSP_Midi0InterruptEnable;
1334 spin_lock_irqsave (&hdsp->lock, flags);
1336 if (!(hdsp->control_register & ie)) {
1337 snd_hdsp_flush_midi_input (hdsp, hmidi->id);
1338 hdsp->control_register |= ie;
1341 hdsp->control_register &= ~ie;
1344 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
1345 spin_unlock_irqrestore (&hdsp->lock, flags);
1348 static void snd_hdsp_midi_output_timer(unsigned long data)
1350 hdsp_midi_t *hmidi = (hdsp_midi_t *) data;
1351 unsigned long flags;
1353 snd_hdsp_midi_output_write(hmidi);
1354 spin_lock_irqsave (&hmidi->lock, flags);
1356 /* this does not bump hmidi->istimer, because the
1357 kernel automatically removed the timer when it
1358 expired, and we are now adding it back, thus
1359 leaving istimer wherever it was set before.
1362 if (hmidi->istimer) {
1363 hmidi->timer.expires = 1 + jiffies;
1364 add_timer(&hmidi->timer);
1367 spin_unlock_irqrestore (&hmidi->lock, flags);
1370 static void snd_hdsp_midi_output_trigger(snd_rawmidi_substream_t * substream, int up)
1373 unsigned long flags;
1375 hmidi = (hdsp_midi_t *) substream->rmidi->private_data;
1376 spin_lock_irqsave (&hmidi->lock, flags);
1378 if (!hmidi->istimer) {
1379 init_timer(&hmidi->timer);
1380 hmidi->timer.function = snd_hdsp_midi_output_timer;
1381 hmidi->timer.data = (unsigned long) hmidi;
1382 hmidi->timer.expires = 1 + jiffies;
1383 add_timer(&hmidi->timer);
1387 if (hmidi->istimer && --hmidi->istimer <= 0) {
1388 del_timer (&hmidi->timer);
1391 spin_unlock_irqrestore (&hmidi->lock, flags);
1393 snd_hdsp_midi_output_write(hmidi);
1396 static int snd_hdsp_midi_input_open(snd_rawmidi_substream_t * substream)
1400 hmidi = (hdsp_midi_t *) substream->rmidi->private_data;
1401 spin_lock_irq (&hmidi->lock);
1402 snd_hdsp_flush_midi_input (hmidi->hdsp, hmidi->id);
1403 hmidi->input = substream;
1404 spin_unlock_irq (&hmidi->lock);
1409 static int snd_hdsp_midi_output_open(snd_rawmidi_substream_t * substream)
1413 hmidi = (hdsp_midi_t *) substream->rmidi->private_data;
1414 spin_lock_irq (&hmidi->lock);
1415 hmidi->output = substream;
1416 spin_unlock_irq (&hmidi->lock);
1421 static int snd_hdsp_midi_input_close(snd_rawmidi_substream_t * substream)
1425 snd_hdsp_midi_input_trigger (substream, 0);
1427 hmidi = (hdsp_midi_t *) substream->rmidi->private_data;
1428 spin_lock_irq (&hmidi->lock);
1429 hmidi->input = NULL;
1430 spin_unlock_irq (&hmidi->lock);
1435 static int snd_hdsp_midi_output_close(snd_rawmidi_substream_t * substream)
1439 snd_hdsp_midi_output_trigger (substream, 0);
1441 hmidi = (hdsp_midi_t *) substream->rmidi->private_data;
1442 spin_lock_irq (&hmidi->lock);
1443 hmidi->output = NULL;
1444 spin_unlock_irq (&hmidi->lock);
1449 snd_rawmidi_ops_t snd_hdsp_midi_output =
1451 .open = snd_hdsp_midi_output_open,
1452 .close = snd_hdsp_midi_output_close,
1453 .trigger = snd_hdsp_midi_output_trigger,
1456 snd_rawmidi_ops_t snd_hdsp_midi_input =
1458 .open = snd_hdsp_midi_input_open,
1459 .close = snd_hdsp_midi_input_close,
1460 .trigger = snd_hdsp_midi_input_trigger,
1463 static int __devinit snd_hdsp_create_midi (snd_card_t *card, hdsp_t *hdsp, int id)
1467 hdsp->midi[id].id = id;
1468 hdsp->midi[id].rmidi = NULL;
1469 hdsp->midi[id].input = NULL;
1470 hdsp->midi[id].output = NULL;
1471 hdsp->midi[id].hdsp = hdsp;
1472 hdsp->midi[id].istimer = 0;
1473 hdsp->midi[id].pending = 0;
1474 spin_lock_init (&hdsp->midi[id].lock);
1476 sprintf (buf, "%s MIDI %d", card->shortname, id+1);
1477 if (snd_rawmidi_new (card, buf, id, 1, 1, &hdsp->midi[id].rmidi) < 0) {
1481 sprintf (hdsp->midi[id].rmidi->name, "%s MIDI %d", card->id, id+1);
1482 hdsp->midi[id].rmidi->private_data = &hdsp->midi[id];
1484 snd_rawmidi_set_ops (hdsp->midi[id].rmidi, SNDRV_RAWMIDI_STREAM_OUTPUT, &snd_hdsp_midi_output);
1485 snd_rawmidi_set_ops (hdsp->midi[id].rmidi, SNDRV_RAWMIDI_STREAM_INPUT, &snd_hdsp_midi_input);
1487 hdsp->midi[id].rmidi->info_flags |= SNDRV_RAWMIDI_INFO_OUTPUT |
1488 SNDRV_RAWMIDI_INFO_INPUT |
1489 SNDRV_RAWMIDI_INFO_DUPLEX;
1494 /*-----------------------------------------------------------------------------
1496 ----------------------------------------------------------------------------*/
1498 static u32 snd_hdsp_convert_from_aes(snd_aes_iec958_t *aes)
1501 val |= (aes->status[0] & IEC958_AES0_PROFESSIONAL) ? HDSP_SPDIFProfessional : 0;
1502 val |= (aes->status[0] & IEC958_AES0_NONAUDIO) ? HDSP_SPDIFNonAudio : 0;
1503 if (val & HDSP_SPDIFProfessional)
1504 val |= (aes->status[0] & IEC958_AES0_PRO_EMPHASIS_5015) ? HDSP_SPDIFEmphasis : 0;
1506 val |= (aes->status[0] & IEC958_AES0_CON_EMPHASIS_5015) ? HDSP_SPDIFEmphasis : 0;
1510 static void snd_hdsp_convert_to_aes(snd_aes_iec958_t *aes, u32 val)
1512 aes->status[0] = ((val & HDSP_SPDIFProfessional) ? IEC958_AES0_PROFESSIONAL : 0) |
1513 ((val & HDSP_SPDIFNonAudio) ? IEC958_AES0_NONAUDIO : 0);
1514 if (val & HDSP_SPDIFProfessional)
1515 aes->status[0] |= (val & HDSP_SPDIFEmphasis) ? IEC958_AES0_PRO_EMPHASIS_5015 : 0;
1517 aes->status[0] |= (val & HDSP_SPDIFEmphasis) ? IEC958_AES0_CON_EMPHASIS_5015 : 0;
1520 static int snd_hdsp_control_spdif_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
1522 uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
1527 static int snd_hdsp_control_spdif_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1529 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
1531 snd_hdsp_convert_to_aes(&ucontrol->value.iec958, hdsp->creg_spdif);
1535 static int snd_hdsp_control_spdif_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1537 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
1541 val = snd_hdsp_convert_from_aes(&ucontrol->value.iec958);
1542 spin_lock_irq(&hdsp->lock);
1543 change = val != hdsp->creg_spdif;
1544 hdsp->creg_spdif = val;
1545 spin_unlock_irq(&hdsp->lock);
1549 static int snd_hdsp_control_spdif_stream_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
1551 uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
1556 static int snd_hdsp_control_spdif_stream_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1558 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
1560 snd_hdsp_convert_to_aes(&ucontrol->value.iec958, hdsp->creg_spdif_stream);
1564 static int snd_hdsp_control_spdif_stream_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1566 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
1570 val = snd_hdsp_convert_from_aes(&ucontrol->value.iec958);
1571 spin_lock_irq(&hdsp->lock);
1572 change = val != hdsp->creg_spdif_stream;
1573 hdsp->creg_spdif_stream = val;
1574 hdsp->control_register &= ~(HDSP_SPDIFProfessional | HDSP_SPDIFNonAudio | HDSP_SPDIFEmphasis);
1575 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register |= val);
1576 spin_unlock_irq(&hdsp->lock);
1580 static int snd_hdsp_control_spdif_mask_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
1582 uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
1587 static int snd_hdsp_control_spdif_mask_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1589 ucontrol->value.iec958.status[0] = kcontrol->private_value;
1593 #define HDSP_SPDIF_IN(xname, xindex) \
1594 { .iface = SNDRV_CTL_ELEM_IFACE_PCM, \
1597 .info = snd_hdsp_info_spdif_in, \
1598 .get = snd_hdsp_get_spdif_in, \
1599 .put = snd_hdsp_put_spdif_in }
1601 static unsigned int hdsp_spdif_in(hdsp_t *hdsp)
1603 return hdsp_decode_spdif_in(hdsp->control_register & HDSP_SPDIFInputMask);
1606 static int hdsp_set_spdif_input(hdsp_t *hdsp, int in)
1608 hdsp->control_register &= ~HDSP_SPDIFInputMask;
1609 hdsp->control_register |= hdsp_encode_spdif_in(in);
1610 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
1614 static int snd_hdsp_info_spdif_in(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
1616 static char *texts[4] = {"Optical", "Coaxial", "Internal", "AES"};
1617 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
1619 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1621 uinfo->value.enumerated.items = ((hdsp->io_type == H9632) ? 4 : 3);
1622 if (uinfo->value.enumerated.item > ((hdsp->io_type == H9632) ? 3 : 2))
1623 uinfo->value.enumerated.item = ((hdsp->io_type == H9632) ? 3 : 2);
1624 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1628 static int snd_hdsp_get_spdif_in(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1630 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
1632 ucontrol->value.enumerated.item[0] = hdsp_spdif_in(hdsp);
1636 static int snd_hdsp_put_spdif_in(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1638 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
1642 if (!snd_hdsp_use_is_exclusive(hdsp))
1644 val = ucontrol->value.enumerated.item[0] % ((hdsp->io_type == H9632) ? 4 : 3);
1645 spin_lock_irq(&hdsp->lock);
1646 change = val != hdsp_spdif_in(hdsp);
1648 hdsp_set_spdif_input(hdsp, val);
1649 spin_unlock_irq(&hdsp->lock);
1653 #define HDSP_SPDIF_OUT(xname, xindex) \
1654 { .iface = SNDRV_CTL_ELEM_IFACE_HWDEP, .name = xname, .index = xindex, \
1655 .info = snd_hdsp_info_spdif_bits, \
1656 .get = snd_hdsp_get_spdif_out, .put = snd_hdsp_put_spdif_out }
1658 static int hdsp_spdif_out(hdsp_t *hdsp)
1660 return (hdsp->control_register & HDSP_SPDIFOpticalOut) ? 1 : 0;
1663 static int hdsp_set_spdif_output(hdsp_t *hdsp, int out)
1666 hdsp->control_register |= HDSP_SPDIFOpticalOut;
1668 hdsp->control_register &= ~HDSP_SPDIFOpticalOut;
1670 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
1674 static int snd_hdsp_info_spdif_bits(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
1676 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
1678 uinfo->value.integer.min = 0;
1679 uinfo->value.integer.max = 1;
1683 static int snd_hdsp_get_spdif_out(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1685 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
1687 ucontrol->value.integer.value[0] = hdsp_spdif_out(hdsp);
1691 static int snd_hdsp_put_spdif_out(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1693 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
1697 if (!snd_hdsp_use_is_exclusive(hdsp))
1699 val = ucontrol->value.integer.value[0] & 1;
1700 spin_lock_irq(&hdsp->lock);
1701 change = (int)val != hdsp_spdif_out(hdsp);
1702 hdsp_set_spdif_output(hdsp, val);
1703 spin_unlock_irq(&hdsp->lock);
1707 #define HDSP_SPDIF_PROFESSIONAL(xname, xindex) \
1708 { .iface = SNDRV_CTL_ELEM_IFACE_HWDEP, .name = xname, .index = xindex, \
1709 .info = snd_hdsp_info_spdif_bits, \
1710 .get = snd_hdsp_get_spdif_professional, .put = snd_hdsp_put_spdif_professional }
1712 static int hdsp_spdif_professional(hdsp_t *hdsp)
1714 return (hdsp->control_register & HDSP_SPDIFProfessional) ? 1 : 0;
1717 static int hdsp_set_spdif_professional(hdsp_t *hdsp, int val)
1720 hdsp->control_register |= HDSP_SPDIFProfessional;
1722 hdsp->control_register &= ~HDSP_SPDIFProfessional;
1724 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
1728 static int snd_hdsp_get_spdif_professional(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1730 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
1732 ucontrol->value.integer.value[0] = hdsp_spdif_professional(hdsp);
1736 static int snd_hdsp_put_spdif_professional(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1738 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
1742 if (!snd_hdsp_use_is_exclusive(hdsp))
1744 val = ucontrol->value.integer.value[0] & 1;
1745 spin_lock_irq(&hdsp->lock);
1746 change = (int)val != hdsp_spdif_professional(hdsp);
1747 hdsp_set_spdif_professional(hdsp, val);
1748 spin_unlock_irq(&hdsp->lock);
1752 #define HDSP_SPDIF_EMPHASIS(xname, xindex) \
1753 { .iface = SNDRV_CTL_ELEM_IFACE_HWDEP, .name = xname, .index = xindex, \
1754 .info = snd_hdsp_info_spdif_bits, \
1755 .get = snd_hdsp_get_spdif_emphasis, .put = snd_hdsp_put_spdif_emphasis }
1757 static int hdsp_spdif_emphasis(hdsp_t *hdsp)
1759 return (hdsp->control_register & HDSP_SPDIFEmphasis) ? 1 : 0;
1762 static int hdsp_set_spdif_emphasis(hdsp_t *hdsp, int val)
1765 hdsp->control_register |= HDSP_SPDIFEmphasis;
1767 hdsp->control_register &= ~HDSP_SPDIFEmphasis;
1769 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
1773 static int snd_hdsp_get_spdif_emphasis(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1775 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
1777 ucontrol->value.integer.value[0] = hdsp_spdif_emphasis(hdsp);
1781 static int snd_hdsp_put_spdif_emphasis(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1783 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
1787 if (!snd_hdsp_use_is_exclusive(hdsp))
1789 val = ucontrol->value.integer.value[0] & 1;
1790 spin_lock_irq(&hdsp->lock);
1791 change = (int)val != hdsp_spdif_emphasis(hdsp);
1792 hdsp_set_spdif_emphasis(hdsp, val);
1793 spin_unlock_irq(&hdsp->lock);
1797 #define HDSP_SPDIF_NON_AUDIO(xname, xindex) \
1798 { .iface = SNDRV_CTL_ELEM_IFACE_HWDEP, .name = xname, .index = xindex, \
1799 .info = snd_hdsp_info_spdif_bits, \
1800 .get = snd_hdsp_get_spdif_nonaudio, .put = snd_hdsp_put_spdif_nonaudio }
1802 static int hdsp_spdif_nonaudio(hdsp_t *hdsp)
1804 return (hdsp->control_register & HDSP_SPDIFNonAudio) ? 1 : 0;
1807 static int hdsp_set_spdif_nonaudio(hdsp_t *hdsp, int val)
1810 hdsp->control_register |= HDSP_SPDIFNonAudio;
1812 hdsp->control_register &= ~HDSP_SPDIFNonAudio;
1814 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
1818 static int snd_hdsp_get_spdif_nonaudio(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1820 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
1822 ucontrol->value.integer.value[0] = hdsp_spdif_nonaudio(hdsp);
1826 static int snd_hdsp_put_spdif_nonaudio(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1828 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
1832 if (!snd_hdsp_use_is_exclusive(hdsp))
1834 val = ucontrol->value.integer.value[0] & 1;
1835 spin_lock_irq(&hdsp->lock);
1836 change = (int)val != hdsp_spdif_nonaudio(hdsp);
1837 hdsp_set_spdif_nonaudio(hdsp, val);
1838 spin_unlock_irq(&hdsp->lock);
1842 #define HDSP_SPDIF_SAMPLE_RATE(xname, xindex) \
1843 { .iface = SNDRV_CTL_ELEM_IFACE_HWDEP, \
1846 .access = SNDRV_CTL_ELEM_ACCESS_READ, \
1847 .info = snd_hdsp_info_spdif_sample_rate, \
1848 .get = snd_hdsp_get_spdif_sample_rate \
1851 static int snd_hdsp_info_spdif_sample_rate(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
1853 static char *texts[] = {"32000", "44100", "48000", "64000", "88200", "96000", "None", "128000", "176400", "192000"};
1854 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
1856 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1858 uinfo->value.enumerated.items = (hdsp->io_type == H9632) ? 10 : 7;
1859 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
1860 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
1861 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1865 static int snd_hdsp_get_spdif_sample_rate(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1867 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
1869 switch (hdsp_spdif_sample_rate(hdsp)) {
1871 ucontrol->value.enumerated.item[0] = 0;
1874 ucontrol->value.enumerated.item[0] = 1;
1877 ucontrol->value.enumerated.item[0] = 2;
1880 ucontrol->value.enumerated.item[0] = 3;
1883 ucontrol->value.enumerated.item[0] = 4;
1886 ucontrol->value.enumerated.item[0] = 5;
1889 ucontrol->value.enumerated.item[0] = 7;
1892 ucontrol->value.enumerated.item[0] = 8;
1895 ucontrol->value.enumerated.item[0] = 9;
1898 ucontrol->value.enumerated.item[0] = 6;
1903 #define HDSP_SYSTEM_SAMPLE_RATE(xname, xindex) \
1904 { .iface = SNDRV_CTL_ELEM_IFACE_HWDEP, \
1907 .access = SNDRV_CTL_ELEM_ACCESS_READ, \
1908 .info = snd_hdsp_info_system_sample_rate, \
1909 .get = snd_hdsp_get_system_sample_rate \
1912 static int snd_hdsp_info_system_sample_rate(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
1914 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1919 static int snd_hdsp_get_system_sample_rate(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1921 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
1923 ucontrol->value.enumerated.item[0] = hdsp->system_sample_rate;
1927 #define HDSP_AUTOSYNC_SAMPLE_RATE(xname, xindex) \
1928 { .iface = SNDRV_CTL_ELEM_IFACE_PCM, \
1931 .access = SNDRV_CTL_ELEM_ACCESS_READ, \
1932 .info = snd_hdsp_info_autosync_sample_rate, \
1933 .get = snd_hdsp_get_autosync_sample_rate \
1936 static int snd_hdsp_info_autosync_sample_rate(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
1938 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
1939 static char *texts[] = {"32000", "44100", "48000", "64000", "88200", "96000", "None", "128000", "176400", "192000"};
1940 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1942 uinfo->value.enumerated.items = (hdsp->io_type == H9632) ? 10 : 7 ;
1943 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
1944 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
1945 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1949 static int snd_hdsp_get_autosync_sample_rate(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1951 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
1953 switch (hdsp_external_sample_rate(hdsp)) {
1955 ucontrol->value.enumerated.item[0] = 0;
1958 ucontrol->value.enumerated.item[0] = 1;
1961 ucontrol->value.enumerated.item[0] = 2;
1964 ucontrol->value.enumerated.item[0] = 3;
1967 ucontrol->value.enumerated.item[0] = 4;
1970 ucontrol->value.enumerated.item[0] = 5;
1973 ucontrol->value.enumerated.item[0] = 7;
1976 ucontrol->value.enumerated.item[0] = 8;
1979 ucontrol->value.enumerated.item[0] = 9;
1982 ucontrol->value.enumerated.item[0] = 6;
1987 #define HDSP_SYSTEM_CLOCK_MODE(xname, xindex) \
1988 { .iface = SNDRV_CTL_ELEM_IFACE_HWDEP, \
1991 .access = SNDRV_CTL_ELEM_ACCESS_READ, \
1992 .info = snd_hdsp_info_system_clock_mode, \
1993 .get = snd_hdsp_get_system_clock_mode \
1996 static int hdsp_system_clock_mode(hdsp_t *hdsp)
1998 if (hdsp->control_register & HDSP_ClockModeMaster) {
2000 } else if (hdsp_external_sample_rate(hdsp) != hdsp->system_sample_rate) {
2006 static int snd_hdsp_info_system_clock_mode(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
2008 static char *texts[] = {"Master", "Slave" };
2010 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2012 uinfo->value.enumerated.items = 2;
2013 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
2014 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
2015 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
2019 static int snd_hdsp_get_system_clock_mode(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
2021 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
2023 ucontrol->value.enumerated.item[0] = hdsp_system_clock_mode(hdsp);
2027 #define HDSP_CLOCK_SOURCE(xname, xindex) \
2028 { .iface = SNDRV_CTL_ELEM_IFACE_PCM, \
2031 .info = snd_hdsp_info_clock_source, \
2032 .get = snd_hdsp_get_clock_source, \
2033 .put = snd_hdsp_put_clock_source \
2036 static int hdsp_clock_source(hdsp_t *hdsp)
2038 if (hdsp->control_register & HDSP_ClockModeMaster) {
2039 switch (hdsp->system_sample_rate) {
2066 static int hdsp_set_clock_source(hdsp_t *hdsp, int mode)
2070 case HDSP_CLOCK_SOURCE_AUTOSYNC:
2071 if (hdsp_external_sample_rate(hdsp) != 0) {
2072 if (!hdsp_set_rate(hdsp, hdsp_external_sample_rate(hdsp), 1)) {
2073 hdsp->control_register &= ~HDSP_ClockModeMaster;
2074 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
2079 case HDSP_CLOCK_SOURCE_INTERNAL_32KHZ:
2082 case HDSP_CLOCK_SOURCE_INTERNAL_44_1KHZ:
2085 case HDSP_CLOCK_SOURCE_INTERNAL_48KHZ:
2088 case HDSP_CLOCK_SOURCE_INTERNAL_64KHZ:
2091 case HDSP_CLOCK_SOURCE_INTERNAL_88_2KHZ:
2094 case HDSP_CLOCK_SOURCE_INTERNAL_96KHZ:
2097 case HDSP_CLOCK_SOURCE_INTERNAL_128KHZ:
2100 case HDSP_CLOCK_SOURCE_INTERNAL_176_4KHZ:
2103 case HDSP_CLOCK_SOURCE_INTERNAL_192KHZ:
2109 hdsp->control_register |= HDSP_ClockModeMaster;
2110 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
2111 hdsp_set_rate(hdsp, rate, 1);
2115 static int snd_hdsp_info_clock_source(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
2117 static char *texts[] = {"AutoSync", "Internal 32.0 kHz", "Internal 44.1 kHz", "Internal 48.0 kHz", "Internal 64.0 kHz", "Internal 88.2 kHz", "Internal 96.0 kHz", "Internal 128 kHz", "Internal 176.4 kHz", "Internal 192.0 KHz" };
2118 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
2120 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2122 if (hdsp->io_type == H9632)
2123 uinfo->value.enumerated.items = 10;
2125 uinfo->value.enumerated.items = 7;
2126 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
2127 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
2128 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
2132 static int snd_hdsp_get_clock_source(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
2134 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
2136 ucontrol->value.enumerated.item[0] = hdsp_clock_source(hdsp);
2140 static int snd_hdsp_put_clock_source(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
2142 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
2146 if (!snd_hdsp_use_is_exclusive(hdsp))
2148 val = ucontrol->value.enumerated.item[0];
2149 if (val < 0) val = 0;
2150 if (hdsp->io_type == H9632) {
2151 if (val > 9) val = 9;
2153 if (val > 6) val = 6;
2155 spin_lock_irq(&hdsp->lock);
2156 if (val != hdsp_clock_source(hdsp)) {
2157 change = (hdsp_set_clock_source(hdsp, val) == 0) ? 1 : 0;
2161 spin_unlock_irq(&hdsp->lock);
2165 #define HDSP_DA_GAIN(xname, xindex) \
2166 { .iface = SNDRV_CTL_ELEM_IFACE_HWDEP, \
2169 .info = snd_hdsp_info_da_gain, \
2170 .get = snd_hdsp_get_da_gain, \
2171 .put = snd_hdsp_put_da_gain \
2174 static int hdsp_da_gain(hdsp_t *hdsp)
2176 switch (hdsp->control_register & HDSP_DAGainMask) {
2177 case HDSP_DAGainHighGain:
2179 case HDSP_DAGainPlus4dBu:
2181 case HDSP_DAGainMinus10dBV:
2188 static int hdsp_set_da_gain(hdsp_t *hdsp, int mode)
2190 hdsp->control_register &= ~HDSP_DAGainMask;
2193 hdsp->control_register |= HDSP_DAGainHighGain;
2196 hdsp->control_register |= HDSP_DAGainPlus4dBu;
2199 hdsp->control_register |= HDSP_DAGainMinus10dBV;
2205 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
2209 static int snd_hdsp_info_da_gain(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
2211 static char *texts[] = {"Hi Gain", "+4 dBu", "-10 dbV"};
2213 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2215 uinfo->value.enumerated.items = 3;
2216 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
2217 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
2218 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
2222 static int snd_hdsp_get_da_gain(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
2224 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
2226 ucontrol->value.enumerated.item[0] = hdsp_da_gain(hdsp);
2230 static int snd_hdsp_put_da_gain(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
2232 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
2236 if (!snd_hdsp_use_is_exclusive(hdsp))
2238 val = ucontrol->value.enumerated.item[0];
2239 if (val < 0) val = 0;
2240 if (val > 2) val = 2;
2241 spin_lock_irq(&hdsp->lock);
2242 if (val != hdsp_da_gain(hdsp)) {
2243 change = (hdsp_set_da_gain(hdsp, val) == 0) ? 1 : 0;
2247 spin_unlock_irq(&hdsp->lock);
2251 #define HDSP_AD_GAIN(xname, xindex) \
2252 { .iface = SNDRV_CTL_ELEM_IFACE_HWDEP, \
2255 .info = snd_hdsp_info_ad_gain, \
2256 .get = snd_hdsp_get_ad_gain, \
2257 .put = snd_hdsp_put_ad_gain \
2260 static int hdsp_ad_gain(hdsp_t *hdsp)
2262 switch (hdsp->control_register & HDSP_ADGainMask) {
2263 case HDSP_ADGainMinus10dBV:
2265 case HDSP_ADGainPlus4dBu:
2267 case HDSP_ADGainLowGain:
2274 static int hdsp_set_ad_gain(hdsp_t *hdsp, int mode)
2276 hdsp->control_register &= ~HDSP_ADGainMask;
2279 hdsp->control_register |= HDSP_ADGainMinus10dBV;
2282 hdsp->control_register |= HDSP_ADGainPlus4dBu;
2285 hdsp->control_register |= HDSP_ADGainLowGain;
2291 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
2295 static int snd_hdsp_info_ad_gain(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
2297 static char *texts[] = {"-10 dBV", "+4 dBu", "Lo Gain"};
2299 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2301 uinfo->value.enumerated.items = 3;
2302 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
2303 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
2304 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
2308 static int snd_hdsp_get_ad_gain(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
2310 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
2312 ucontrol->value.enumerated.item[0] = hdsp_ad_gain(hdsp);
2316 static int snd_hdsp_put_ad_gain(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
2318 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
2322 if (!snd_hdsp_use_is_exclusive(hdsp))
2324 val = ucontrol->value.enumerated.item[0];
2325 if (val < 0) val = 0;
2326 if (val > 2) val = 2;
2327 spin_lock_irq(&hdsp->lock);
2328 if (val != hdsp_ad_gain(hdsp)) {
2329 change = (hdsp_set_ad_gain(hdsp, val) == 0) ? 1 : 0;
2333 spin_unlock_irq(&hdsp->lock);
2337 #define HDSP_PHONE_GAIN(xname, xindex) \
2338 { .iface = SNDRV_CTL_ELEM_IFACE_HWDEP, \
2341 .info = snd_hdsp_info_phone_gain, \
2342 .get = snd_hdsp_get_phone_gain, \
2343 .put = snd_hdsp_put_phone_gain \
2346 static int hdsp_phone_gain(hdsp_t *hdsp)
2348 switch (hdsp->control_register & HDSP_PhoneGainMask) {
2349 case HDSP_PhoneGain0dB:
2351 case HDSP_PhoneGainMinus6dB:
2353 case HDSP_PhoneGainMinus12dB:
2360 static int hdsp_set_phone_gain(hdsp_t *hdsp, int mode)
2362 hdsp->control_register &= ~HDSP_PhoneGainMask;
2365 hdsp->control_register |= HDSP_PhoneGain0dB;
2368 hdsp->control_register |= HDSP_PhoneGainMinus6dB;
2371 hdsp->control_register |= HDSP_PhoneGainMinus12dB;
2377 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
2381 static int snd_hdsp_info_phone_gain(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
2383 static char *texts[] = {"0 dB", "-6 dB", "-12 dB"};
2385 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2387 uinfo->value.enumerated.items = 3;
2388 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
2389 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
2390 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
2394 static int snd_hdsp_get_phone_gain(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
2396 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
2398 ucontrol->value.enumerated.item[0] = hdsp_phone_gain(hdsp);
2402 static int snd_hdsp_put_phone_gain(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
2404 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
2408 if (!snd_hdsp_use_is_exclusive(hdsp))
2410 val = ucontrol->value.enumerated.item[0];
2411 if (val < 0) val = 0;
2412 if (val > 2) val = 2;
2413 spin_lock_irq(&hdsp->lock);
2414 if (val != hdsp_phone_gain(hdsp)) {
2415 change = (hdsp_set_phone_gain(hdsp, val) == 0) ? 1 : 0;
2419 spin_unlock_irq(&hdsp->lock);
2423 #define HDSP_XLR_BREAKOUT_CABLE(xname, xindex) \
2424 { .iface = SNDRV_CTL_ELEM_IFACE_HWDEP, \
2427 .info = snd_hdsp_info_xlr_breakout_cable, \
2428 .get = snd_hdsp_get_xlr_breakout_cable, \
2429 .put = snd_hdsp_put_xlr_breakout_cable \
2432 static int hdsp_xlr_breakout_cable(hdsp_t *hdsp)
2434 if (hdsp->control_register & HDSP_XLRBreakoutCable) {
2440 static int hdsp_set_xlr_breakout_cable(hdsp_t *hdsp, int mode)
2443 hdsp->control_register |= HDSP_XLRBreakoutCable;
2445 hdsp->control_register &= ~HDSP_XLRBreakoutCable;
2447 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
2451 static int snd_hdsp_info_xlr_breakout_cable(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
2453 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
2455 uinfo->value.integer.min = 0;
2456 uinfo->value.integer.max = 1;
2460 static int snd_hdsp_get_xlr_breakout_cable(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
2462 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
2464 ucontrol->value.enumerated.item[0] = hdsp_xlr_breakout_cable(hdsp);
2468 static int snd_hdsp_put_xlr_breakout_cable(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
2470 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
2474 if (!snd_hdsp_use_is_exclusive(hdsp))
2476 val = ucontrol->value.integer.value[0] & 1;
2477 spin_lock_irq(&hdsp->lock);
2478 change = (int)val != hdsp_xlr_breakout_cable(hdsp);
2479 hdsp_set_xlr_breakout_cable(hdsp, val);
2480 spin_unlock_irq(&hdsp->lock);
2484 /* (De)activates old RME Analog Extension Board
2485 These are connected to the internal ADAT connector
2486 Switching this on desactivates external ADAT
2488 #define HDSP_AEB(xname, xindex) \
2489 { .iface = SNDRV_CTL_ELEM_IFACE_HWDEP, \
2492 .info = snd_hdsp_info_aeb, \
2493 .get = snd_hdsp_get_aeb, \
2494 .put = snd_hdsp_put_aeb \
2497 static int hdsp_aeb(hdsp_t *hdsp)
2499 if (hdsp->control_register & HDSP_AnalogExtensionBoard) {
2505 static int hdsp_set_aeb(hdsp_t *hdsp, int mode)
2508 hdsp->control_register |= HDSP_AnalogExtensionBoard;
2510 hdsp->control_register &= ~HDSP_AnalogExtensionBoard;
2512 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
2516 static int snd_hdsp_info_aeb(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
2518 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
2520 uinfo->value.integer.min = 0;
2521 uinfo->value.integer.max = 1;
2525 static int snd_hdsp_get_aeb(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
2527 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
2529 ucontrol->value.enumerated.item[0] = hdsp_aeb(hdsp);
2533 static int snd_hdsp_put_aeb(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
2535 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
2539 if (!snd_hdsp_use_is_exclusive(hdsp))
2541 val = ucontrol->value.integer.value[0] & 1;
2542 spin_lock_irq(&hdsp->lock);
2543 change = (int)val != hdsp_aeb(hdsp);
2544 hdsp_set_aeb(hdsp, val);
2545 spin_unlock_irq(&hdsp->lock);
2549 #define HDSP_PREF_SYNC_REF(xname, xindex) \
2550 { .iface = SNDRV_CTL_ELEM_IFACE_HWDEP, \
2553 .info = snd_hdsp_info_pref_sync_ref, \
2554 .get = snd_hdsp_get_pref_sync_ref, \
2555 .put = snd_hdsp_put_pref_sync_ref \
2558 static int hdsp_pref_sync_ref(hdsp_t *hdsp)
2560 /* Notice that this looks at the requested sync source,
2561 not the one actually in use.
2564 switch (hdsp->control_register & HDSP_SyncRefMask) {
2565 case HDSP_SyncRef_ADAT1:
2566 return HDSP_SYNC_FROM_ADAT1;
2567 case HDSP_SyncRef_ADAT2:
2568 return HDSP_SYNC_FROM_ADAT2;
2569 case HDSP_SyncRef_ADAT3:
2570 return HDSP_SYNC_FROM_ADAT3;
2571 case HDSP_SyncRef_SPDIF:
2572 return HDSP_SYNC_FROM_SPDIF;
2573 case HDSP_SyncRef_WORD:
2574 return HDSP_SYNC_FROM_WORD;
2575 case HDSP_SyncRef_ADAT_SYNC:
2576 return HDSP_SYNC_FROM_ADAT_SYNC;
2578 return HDSP_SYNC_FROM_WORD;
2583 static int hdsp_set_pref_sync_ref(hdsp_t *hdsp, int pref)
2585 hdsp->control_register &= ~HDSP_SyncRefMask;
2587 case HDSP_SYNC_FROM_ADAT1:
2588 hdsp->control_register &= ~HDSP_SyncRefMask; /* clear SyncRef bits */
2590 case HDSP_SYNC_FROM_ADAT2:
2591 hdsp->control_register |= HDSP_SyncRef_ADAT2;
2593 case HDSP_SYNC_FROM_ADAT3:
2594 hdsp->control_register |= HDSP_SyncRef_ADAT3;
2596 case HDSP_SYNC_FROM_SPDIF:
2597 hdsp->control_register |= HDSP_SyncRef_SPDIF;
2599 case HDSP_SYNC_FROM_WORD:
2600 hdsp->control_register |= HDSP_SyncRef_WORD;
2602 case HDSP_SYNC_FROM_ADAT_SYNC:
2603 hdsp->control_register |= HDSP_SyncRef_ADAT_SYNC;
2608 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
2612 static int snd_hdsp_info_pref_sync_ref(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
2614 static char *texts[] = {"Word", "IEC958", "ADAT1", "ADAT Sync", "ADAT2", "ADAT3" };
2615 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
2617 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2620 switch (hdsp->io_type) {
2623 uinfo->value.enumerated.items = 6;
2626 uinfo->value.enumerated.items = 4;
2629 uinfo->value.enumerated.items = 3;
2632 uinfo->value.enumerated.items = 0;
2636 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
2637 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
2638 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
2642 static int snd_hdsp_get_pref_sync_ref(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
2644 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
2646 ucontrol->value.enumerated.item[0] = hdsp_pref_sync_ref(hdsp);
2650 static int snd_hdsp_put_pref_sync_ref(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
2652 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
2656 if (!snd_hdsp_use_is_exclusive(hdsp))
2659 switch (hdsp->io_type) {
2674 val = ucontrol->value.enumerated.item[0] % max;
2675 spin_lock_irq(&hdsp->lock);
2676 change = (int)val != hdsp_pref_sync_ref(hdsp);
2677 hdsp_set_pref_sync_ref(hdsp, val);
2678 spin_unlock_irq(&hdsp->lock);
2682 #define HDSP_AUTOSYNC_REF(xname, xindex) \
2683 { .iface = SNDRV_CTL_ELEM_IFACE_HWDEP, \
2686 .access = SNDRV_CTL_ELEM_ACCESS_READ, \
2687 .info = snd_hdsp_info_autosync_ref, \
2688 .get = snd_hdsp_get_autosync_ref, \
2691 static int hdsp_autosync_ref(hdsp_t *hdsp)
2693 /* This looks at the autosync selected sync reference */
2694 unsigned int status2 = hdsp_read(hdsp, HDSP_status2Register);
2696 switch (status2 & HDSP_SelSyncRefMask) {
2697 case HDSP_SelSyncRef_WORD:
2698 return HDSP_AUTOSYNC_FROM_WORD;
2699 case HDSP_SelSyncRef_ADAT_SYNC:
2700 return HDSP_AUTOSYNC_FROM_ADAT_SYNC;
2701 case HDSP_SelSyncRef_SPDIF:
2702 return HDSP_AUTOSYNC_FROM_SPDIF;
2703 case HDSP_SelSyncRefMask:
2704 return HDSP_AUTOSYNC_FROM_NONE;
2705 case HDSP_SelSyncRef_ADAT1:
2706 return HDSP_AUTOSYNC_FROM_ADAT1;
2707 case HDSP_SelSyncRef_ADAT2:
2708 return HDSP_AUTOSYNC_FROM_ADAT2;
2709 case HDSP_SelSyncRef_ADAT3:
2710 return HDSP_AUTOSYNC_FROM_ADAT3;
2712 return HDSP_AUTOSYNC_FROM_WORD;
2717 static int snd_hdsp_info_autosync_ref(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
2719 static char *texts[] = {"Word", "ADAT Sync", "IEC958", "None", "ADAT1", "ADAT2", "ADAT3" };
2721 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2723 uinfo->value.enumerated.items = 7;
2724 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
2725 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
2726 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
2730 static int snd_hdsp_get_autosync_ref(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
2732 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
2734 ucontrol->value.enumerated.item[0] = hdsp_pref_sync_ref(hdsp);
2738 #define HDSP_PASSTHRU(xname, xindex) \
2739 { .iface = SNDRV_CTL_ELEM_IFACE_HWDEP, \
2742 .info = snd_hdsp_info_passthru, \
2743 .put = snd_hdsp_put_passthru, \
2744 .get = snd_hdsp_get_passthru \
2747 static int snd_hdsp_info_passthru(snd_kcontrol_t * kcontrol, snd_ctl_elem_info_t * uinfo)
2749 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
2751 uinfo->value.integer.min = 0;
2752 uinfo->value.integer.max = 1;
2756 static int snd_hdsp_get_passthru(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
2758 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
2760 spin_lock_irq(&hdsp->lock);
2761 ucontrol->value.integer.value[0] = hdsp->passthru;
2762 spin_unlock_irq(&hdsp->lock);
2766 static int snd_hdsp_put_passthru(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
2768 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
2773 if (!snd_hdsp_use_is_exclusive(hdsp))
2776 val = ucontrol->value.integer.value[0] & 1;
2777 spin_lock_irq(&hdsp->lock);
2778 change = (ucontrol->value.integer.value[0] != hdsp->passthru);
2780 err = hdsp_set_passthru(hdsp, val);
2781 spin_unlock_irq(&hdsp->lock);
2782 return err ? err : change;
2785 #define HDSP_LINE_OUT(xname, xindex) \
2786 { .iface = SNDRV_CTL_ELEM_IFACE_HWDEP, \
2789 .info = snd_hdsp_info_line_out, \
2790 .get = snd_hdsp_get_line_out, \
2791 .put = snd_hdsp_put_line_out \
2794 static int hdsp_line_out(hdsp_t *hdsp)
2796 return (hdsp->control_register & HDSP_LineOut) ? 1 : 0;
2799 static int hdsp_set_line_output(hdsp_t *hdsp, int out)
2802 hdsp->control_register |= HDSP_LineOut;
2804 hdsp->control_register &= ~HDSP_LineOut;
2806 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
2810 static int snd_hdsp_info_line_out(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
2812 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
2814 uinfo->value.integer.min = 0;
2815 uinfo->value.integer.max = 1;
2819 static int snd_hdsp_get_line_out(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
2821 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
2823 spin_lock_irq(&hdsp->lock);
2824 ucontrol->value.integer.value[0] = hdsp_line_out(hdsp);
2825 spin_unlock_irq(&hdsp->lock);
2829 static int snd_hdsp_put_line_out(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
2831 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
2835 if (!snd_hdsp_use_is_exclusive(hdsp))
2837 val = ucontrol->value.integer.value[0] & 1;
2838 spin_lock_irq(&hdsp->lock);
2839 change = (int)val != hdsp_line_out(hdsp);
2840 hdsp_set_line_output(hdsp, val);
2841 spin_unlock_irq(&hdsp->lock);
2845 #define HDSP_MIXER(xname, xindex) \
2846 { .iface = SNDRV_CTL_ELEM_IFACE_HWDEP, \
2849 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | \
2850 SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
2851 .info = snd_hdsp_info_mixer, \
2852 .get = snd_hdsp_get_mixer, \
2853 .put = snd_hdsp_put_mixer \
2856 static int snd_hdsp_info_mixer(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
2858 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
2860 uinfo->value.integer.min = 0;
2861 uinfo->value.integer.max = 65536;
2862 uinfo->value.integer.step = 1;
2866 static int snd_hdsp_get_mixer(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
2868 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
2873 source = ucontrol->value.integer.value[0];
2874 destination = ucontrol->value.integer.value[1];
2876 if (source >= hdsp->max_channels) {
2877 addr = hdsp_playback_to_output_key(hdsp,source-hdsp->max_channels,destination);
2879 addr = hdsp_input_to_output_key(hdsp,source, destination);
2882 spin_lock_irq(&hdsp->lock);
2883 ucontrol->value.integer.value[2] = hdsp_read_gain (hdsp, addr);
2884 spin_unlock_irq(&hdsp->lock);
2888 static int snd_hdsp_put_mixer(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
2890 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
2897 if (!snd_hdsp_use_is_exclusive(hdsp))
2900 source = ucontrol->value.integer.value[0];
2901 destination = ucontrol->value.integer.value[1];
2903 if (source >= hdsp->max_channels) {
2904 addr = hdsp_playback_to_output_key(hdsp,source-hdsp->max_channels, destination);
2906 addr = hdsp_input_to_output_key(hdsp,source, destination);
2909 gain = ucontrol->value.integer.value[2];
2911 spin_lock_irq(&hdsp->lock);
2912 change = gain != hdsp_read_gain(hdsp, addr);
2914 hdsp_write_gain(hdsp, addr, gain);
2915 spin_unlock_irq(&hdsp->lock);
2919 #define HDSP_WC_SYNC_CHECK(xname, xindex) \
2920 { .iface = SNDRV_CTL_ELEM_IFACE_HWDEP, \
2923 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
2924 .info = snd_hdsp_info_sync_check, \
2925 .get = snd_hdsp_get_wc_sync_check \
2928 static int snd_hdsp_info_sync_check(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
2930 static char *texts[] = {"No Lock", "Lock", "Sync" };
2931 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2933 uinfo->value.enumerated.items = 3;
2934 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
2935 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
2936 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
2940 static int hdsp_wc_sync_check(hdsp_t *hdsp)
2942 int status2 = hdsp_read(hdsp, HDSP_status2Register);
2943 if (status2 & HDSP_wc_lock) {
2944 if (status2 & HDSP_wc_sync) {
2955 static int snd_hdsp_get_wc_sync_check(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
2957 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
2959 ucontrol->value.enumerated.item[0] = hdsp_wc_sync_check(hdsp);
2963 #define HDSP_SPDIF_SYNC_CHECK(xname, xindex) \
2964 { .iface = SNDRV_CTL_ELEM_IFACE_HWDEP, \
2967 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
2968 .info = snd_hdsp_info_sync_check, \
2969 .get = snd_hdsp_get_spdif_sync_check \
2972 static int hdsp_spdif_sync_check(hdsp_t *hdsp)
2974 int status = hdsp_read(hdsp, HDSP_statusRegister);
2975 if (status & HDSP_SPDIFErrorFlag) {
2978 if (status & HDSP_SPDIFSync) {
2987 static int snd_hdsp_get_spdif_sync_check(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
2989 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
2991 ucontrol->value.enumerated.item[0] = hdsp_spdif_sync_check(hdsp);
2995 #define HDSP_ADATSYNC_SYNC_CHECK(xname, xindex) \
2996 { .iface = SNDRV_CTL_ELEM_IFACE_HWDEP, \
2999 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
3000 .info = snd_hdsp_info_sync_check, \
3001 .get = snd_hdsp_get_adatsync_sync_check \
3004 static int hdsp_adatsync_sync_check(hdsp_t *hdsp)
3006 int status = hdsp_read(hdsp, HDSP_statusRegister);
3007 if (status & HDSP_TimecodeLock) {
3008 if (status & HDSP_TimecodeSync) {
3018 static int snd_hdsp_get_adatsync_sync_check(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
3020 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
3022 ucontrol->value.enumerated.item[0] = hdsp_adatsync_sync_check(hdsp);
3026 #define HDSP_ADAT_SYNC_CHECK \
3027 { .iface = SNDRV_CTL_ELEM_IFACE_HWDEP, \
3028 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
3029 .info = snd_hdsp_info_sync_check, \
3030 .get = snd_hdsp_get_adat_sync_check \
3033 static int hdsp_adat_sync_check(hdsp_t *hdsp, int idx)
3035 int status = hdsp_read(hdsp, HDSP_statusRegister);
3037 if (status & (HDSP_Lock0>>idx)) {
3038 if (status & (HDSP_Sync0>>idx)) {
3048 static int snd_hdsp_get_adat_sync_check(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
3051 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
3053 offset = ucontrol->id.index - 1;
3054 snd_assert(offset >= 0);
3056 switch (hdsp->io_type) {
3071 ucontrol->value.enumerated.item[0] = hdsp_adat_sync_check(hdsp, offset);
3075 static snd_kcontrol_new_t snd_hdsp_9632_controls[] = {
3076 HDSP_DA_GAIN("DA Gain", 0),
3077 HDSP_AD_GAIN("AD Gain", 0),
3078 HDSP_PHONE_GAIN("Phones Gain", 0),
3079 HDSP_XLR_BREAKOUT_CABLE("XLR Breakout Cable", 0)
3082 static snd_kcontrol_new_t snd_hdsp_controls[] = {
3084 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
3085 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,DEFAULT),
3086 .info = snd_hdsp_control_spdif_info,
3087 .get = snd_hdsp_control_spdif_get,
3088 .put = snd_hdsp_control_spdif_put,
3091 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_INACTIVE,
3092 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
3093 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,PCM_STREAM),
3094 .info = snd_hdsp_control_spdif_stream_info,
3095 .get = snd_hdsp_control_spdif_stream_get,
3096 .put = snd_hdsp_control_spdif_stream_put,
3099 .access = SNDRV_CTL_ELEM_ACCESS_READ,
3100 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3101 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,CON_MASK),
3102 .info = snd_hdsp_control_spdif_mask_info,
3103 .get = snd_hdsp_control_spdif_mask_get,
3104 .private_value = IEC958_AES0_NONAUDIO |
3105 IEC958_AES0_PROFESSIONAL |
3106 IEC958_AES0_CON_EMPHASIS,
3109 .access = SNDRV_CTL_ELEM_ACCESS_READ,
3110 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3111 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,PRO_MASK),
3112 .info = snd_hdsp_control_spdif_mask_info,
3113 .get = snd_hdsp_control_spdif_mask_get,
3114 .private_value = IEC958_AES0_NONAUDIO |
3115 IEC958_AES0_PROFESSIONAL |
3116 IEC958_AES0_PRO_EMPHASIS,
3118 HDSP_MIXER("Mixer", 0),
3119 HDSP_SPDIF_IN("IEC958 Input Connector", 0),
3120 HDSP_SPDIF_OUT("IEC958 Output also on ADAT1", 0),
3121 HDSP_SPDIF_PROFESSIONAL("IEC958 Professional Bit", 0),
3122 HDSP_SPDIF_EMPHASIS("IEC958 Emphasis Bit", 0),
3123 HDSP_SPDIF_NON_AUDIO("IEC958 Non-audio Bit", 0),
3124 /* 'Sample Clock Source' complies with the alsa control naming scheme */
3125 HDSP_CLOCK_SOURCE("Sample Clock Source", 0),
3126 HDSP_SYSTEM_CLOCK_MODE("System Clock Mode", 0),
3127 HDSP_PREF_SYNC_REF("Preferred Sync Reference", 0),
3128 HDSP_AUTOSYNC_REF("AutoSync Reference", 0),
3129 HDSP_SPDIF_SAMPLE_RATE("SPDIF Sample Rate", 0),
3130 HDSP_SYSTEM_SAMPLE_RATE("System Sample Rate", 0),
3131 /* 'External Rate' complies with the alsa control naming scheme */
3132 HDSP_AUTOSYNC_SAMPLE_RATE("External Rate", 0),
3133 HDSP_WC_SYNC_CHECK("Word Clock Lock Status", 0),
3134 HDSP_SPDIF_SYNC_CHECK("SPDIF Lock Status", 0),
3135 HDSP_ADATSYNC_SYNC_CHECK("ADAT Sync Lock Status", 0),
3136 HDSP_PASSTHRU("Passthru", 0),
3137 HDSP_LINE_OUT("Line Out", 0),
3140 static snd_kcontrol_new_t snd_hdsp_96xx_aeb = HDSP_AEB("Analog Extension Board", 0);
3141 static snd_kcontrol_new_t snd_hdsp_adat_sync_check = HDSP_ADAT_SYNC_CHECK;
3143 int snd_hdsp_create_controls(snd_card_t *card, hdsp_t *hdsp)
3147 snd_kcontrol_t *kctl;
3149 for (idx = 0; idx < ARRAY_SIZE(snd_hdsp_controls); idx++) {
3150 if ((err = snd_ctl_add(card, kctl = snd_ctl_new1(&snd_hdsp_controls[idx], hdsp))) < 0) {
3153 if (idx == 1) /* IEC958 (S/PDIF) Stream */
3154 hdsp->spdif_ctl = kctl;
3157 /* ADAT SyncCheck status */
3158 snd_hdsp_adat_sync_check.name = "ADAT Lock Status";
3159 snd_hdsp_adat_sync_check.index = 1;
3160 if ((err = snd_ctl_add (card, kctl = snd_ctl_new1(&snd_hdsp_adat_sync_check, hdsp)))) {
3163 if (hdsp->io_type == Digiface || hdsp->io_type == H9652) {
3164 for (idx = 1; idx < 3; ++idx) {
3165 snd_hdsp_adat_sync_check.index = idx+1;
3166 if ((err = snd_ctl_add (card, kctl = snd_ctl_new1(&snd_hdsp_adat_sync_check, hdsp)))) {
3172 /* DA, AD and Phone gain and XLR breakout cable controls for H9632 cards */
3173 if (hdsp->io_type == H9632) {
3174 for (idx = 0; idx < ARRAY_SIZE(snd_hdsp_9632_controls); idx++) {
3175 if ((err = snd_ctl_add(card, kctl = snd_ctl_new1(&snd_hdsp_9632_controls[idx], hdsp))) < 0) {
3181 /* AEB control for H96xx card */
3182 if (hdsp->io_type == H9632 || hdsp->io_type == H9652) {
3183 if ((err = snd_ctl_add(card, kctl = snd_ctl_new1(&snd_hdsp_96xx_aeb, hdsp))) < 0) {
3191 /*------------------------------------------------------------
3193 ------------------------------------------------------------*/
3196 snd_hdsp_proc_read(snd_info_entry_t *entry, snd_info_buffer_t *buffer)
3198 hdsp_t *hdsp = (hdsp_t *) entry->private_data;
3199 unsigned int status;
3200 unsigned int status2;
3201 char *pref_sync_ref;
3203 char *system_clock_mode;
3207 if (hdsp_check_for_iobox (hdsp)) {
3208 snd_iprintf(buffer, "No I/O box connected.\nPlease connect one and upload firmware.\n");
3212 if (hdsp_check_for_firmware(hdsp)) {
3213 if (hdsp->state & HDSP_FirmwareCached) {
3214 if (snd_hdsp_load_firmware_from_cache(hdsp) != 0) {
3215 snd_iprintf(buffer, "Firmware loading from cache failed, please upload manually.\n");
3219 snd_iprintf(buffer, "No firmware loaded nor cached, please upload firmware.\n");
3224 status = hdsp_read(hdsp, HDSP_statusRegister);
3225 status2 = hdsp_read(hdsp, HDSP_status2Register);
3227 snd_iprintf(buffer, "%s (Card #%d)\n", hdsp->card_name, hdsp->card->number + 1);
3228 snd_iprintf(buffer, "Buffers: capture %p playback %p\n",
3229 hdsp->capture_buffer, hdsp->playback_buffer);
3230 snd_iprintf(buffer, "IRQ: %d Registers bus: 0x%lx VM: 0x%lx\n",
3231 hdsp->irq, hdsp->port, hdsp->iobase);
3232 snd_iprintf(buffer, "Control register: 0x%x\n", hdsp->control_register);
3233 snd_iprintf(buffer, "Control2 register: 0x%x\n", hdsp->control2_register);
3234 snd_iprintf(buffer, "Status register: 0x%x\n", status);
3235 snd_iprintf(buffer, "Status2 register: 0x%x\n", status2);
3236 snd_iprintf(buffer, "FIFO status: %d\n", hdsp_read(hdsp, HDSP_fifoStatus) & 0xff);
3238 snd_iprintf(buffer, "MIDI1 Output status: 0x%x\n", hdsp_read(hdsp, HDSP_midiStatusOut0));
3239 snd_iprintf(buffer, "MIDI1 Input status: 0x%x\n", hdsp_read(hdsp, HDSP_midiStatusIn0));
3240 snd_iprintf(buffer, "MIDI2 Output status: 0x%x\n", hdsp_read(hdsp, HDSP_midiStatusOut1));
3241 snd_iprintf(buffer, "MIDI2 Input status: 0x%x\n", hdsp_read(hdsp, HDSP_midiStatusIn1));
3243 snd_iprintf(buffer, "\n");
3245 x = 1 << (6 + hdsp_decode_latency(hdsp->control_register & HDSP_LatencyMask));
3247 snd_iprintf(buffer, "Buffer Size (Latency): %d samples (2 periods of %lu bytes)\n", x, (unsigned long) hdsp->period_bytes);
3248 snd_iprintf(buffer, "Hardware pointer (frames): %ld\n", hdsp_hw_pointer(hdsp));
3249 snd_iprintf(buffer, "Passthru: %s\n", hdsp->passthru ? "yes" : "no");
3250 snd_iprintf(buffer, "Line out: %s\n", (hdsp->control_register & HDSP_LineOut) ? "on" : "off");
3252 snd_iprintf(buffer, "Firmware version: %d\n", (status2&HDSP_version0)|(status2&HDSP_version1)<<1|(status2&HDSP_version2)<<2);
3254 snd_iprintf(buffer, "\n");
3257 switch (hdsp_clock_source(hdsp)) {
3258 case HDSP_CLOCK_SOURCE_AUTOSYNC:
3259 clock_source = "AutoSync";
3261 case HDSP_CLOCK_SOURCE_INTERNAL_32KHZ:
3262 clock_source = "Internal 32 kHz";
3264 case HDSP_CLOCK_SOURCE_INTERNAL_44_1KHZ:
3265 clock_source = "Internal 44.1 kHz";
3267 case HDSP_CLOCK_SOURCE_INTERNAL_48KHZ:
3268 clock_source = "Internal 48 kHz";
3270 case HDSP_CLOCK_SOURCE_INTERNAL_64KHZ:
3271 clock_source = "Internal 64 kHz";
3273 case HDSP_CLOCK_SOURCE_INTERNAL_88_2KHZ:
3274 clock_source = "Internal 88.2 kHz";
3276 case HDSP_CLOCK_SOURCE_INTERNAL_96KHZ:
3277 clock_source = "Internal 96 kHz";
3279 case HDSP_CLOCK_SOURCE_INTERNAL_128KHZ:
3280 clock_source = "Internal 128 kHz";
3282 case HDSP_CLOCK_SOURCE_INTERNAL_176_4KHZ:
3283 clock_source = "Internal 176.4 kHz";
3285 case HDSP_CLOCK_SOURCE_INTERNAL_192KHZ:
3286 clock_source = "Internal 192 kHz";
3289 clock_source = "Error";
3291 snd_iprintf (buffer, "Sample Clock Source: %s\n", clock_source);
3293 if (hdsp_system_clock_mode(hdsp)) {
3294 system_clock_mode = "Slave";
3296 system_clock_mode = "Master";
3299 switch (hdsp_pref_sync_ref (hdsp)) {
3300 case HDSP_SYNC_FROM_WORD:
3301 pref_sync_ref = "Word Clock";
3303 case HDSP_SYNC_FROM_ADAT_SYNC:
3304 pref_sync_ref = "ADAT Sync";
3306 case HDSP_SYNC_FROM_SPDIF:
3307 pref_sync_ref = "SPDIF";
3309 case HDSP_SYNC_FROM_ADAT1:
3310 pref_sync_ref = "ADAT1";
3312 case HDSP_SYNC_FROM_ADAT2:
3313 pref_sync_ref = "ADAT2";
3315 case HDSP_SYNC_FROM_ADAT3:
3316 pref_sync_ref = "ADAT3";
3319 pref_sync_ref = "Word Clock";
3322 snd_iprintf (buffer, "Preferred Sync Reference: %s\n", pref_sync_ref);
3324 switch (hdsp_autosync_ref (hdsp)) {
3325 case HDSP_AUTOSYNC_FROM_WORD:
3326 autosync_ref = "Word Clock";
3328 case HDSP_AUTOSYNC_FROM_ADAT_SYNC:
3329 autosync_ref = "ADAT Sync";
3331 case HDSP_AUTOSYNC_FROM_SPDIF:
3332 autosync_ref = "SPDIF";
3334 case HDSP_AUTOSYNC_FROM_NONE:
3335 autosync_ref = "None";
3337 case HDSP_AUTOSYNC_FROM_ADAT1:
3338 autosync_ref = "ADAT1";
3340 case HDSP_AUTOSYNC_FROM_ADAT2:
3341 autosync_ref = "ADAT2";
3343 case HDSP_AUTOSYNC_FROM_ADAT3:
3344 autosync_ref = "ADAT3";
3347 autosync_ref = "---";
3350 snd_iprintf (buffer, "AutoSync Reference: %s\n", autosync_ref);
3352 snd_iprintf (buffer, "AutoSync Frequency: %d\n", hdsp_external_sample_rate(hdsp));
3354 snd_iprintf (buffer, "System Clock Mode: %s\n", system_clock_mode);
3356 snd_iprintf (buffer, "System Clock Frequency: %d\n", hdsp->system_sample_rate);
3358 snd_iprintf(buffer, "\n");
3360 switch (hdsp_spdif_in(hdsp)) {
3361 case HDSP_SPDIFIN_OPTICAL:
3362 snd_iprintf(buffer, "IEC958 input: Optical\n");
3364 case HDSP_SPDIFIN_COAXIAL:
3365 snd_iprintf(buffer, "IEC958 input: Coaxial\n");
3367 case HDSP_SPDIFIN_INTERNAL:
3368 snd_iprintf(buffer, "IEC958 input: Internal\n");
3370 case HDSP_SPDIFIN_AES:
3371 snd_iprintf(buffer, "IEC958 input: AES\n");
3374 snd_iprintf(buffer, "IEC958 input: ???\n");
3378 if (hdsp->control_register & HDSP_SPDIFOpticalOut) {
3379 snd_iprintf(buffer, "IEC958 output: Coaxial & ADAT1\n");
3381 snd_iprintf(buffer, "IEC958 output: Coaxial only\n");
3384 if (hdsp->control_register & HDSP_SPDIFProfessional) {
3385 snd_iprintf(buffer, "IEC958 quality: Professional\n");
3387 snd_iprintf(buffer, "IEC958 quality: Consumer\n");
3390 if (hdsp->control_register & HDSP_SPDIFEmphasis) {
3391 snd_iprintf(buffer, "IEC958 emphasis: on\n");
3393 snd_iprintf(buffer, "IEC958 emphasis: off\n");
3396 if (hdsp->control_register & HDSP_SPDIFNonAudio) {
3397 snd_iprintf(buffer, "IEC958 NonAudio: on\n");
3399 snd_iprintf(buffer, "IEC958 NonAudio: off\n");
3401 if ((x = hdsp_spdif_sample_rate (hdsp)) != 0) {
3402 snd_iprintf (buffer, "IEC958 sample rate: %d\n", x);
3404 snd_iprintf (buffer, "IEC958 sample rate: Error flag set\n");
3407 snd_iprintf(buffer, "\n");
3410 x = status & HDSP_Sync0;
3411 if (status & HDSP_Lock0) {
3412 snd_iprintf(buffer, "ADAT1: %s\n", x ? "Sync" : "Lock");
3414 snd_iprintf(buffer, "ADAT1: No Lock\n");
3417 switch (hdsp->io_type) {
3420 x = status & HDSP_Sync1;
3421 if (status & HDSP_Lock1) {
3422 snd_iprintf(buffer, "ADAT2: %s\n", x ? "Sync" : "Lock");
3424 snd_iprintf(buffer, "ADAT2: No Lock\n");
3426 x = status & HDSP_Sync2;
3427 if (status & HDSP_Lock2) {
3428 snd_iprintf(buffer, "ADAT3: %s\n", x ? "Sync" : "Lock");
3430 snd_iprintf(buffer, "ADAT3: No Lock\n");
3437 x = status & HDSP_SPDIFSync;
3438 if (status & HDSP_SPDIFErrorFlag) {
3439 snd_iprintf (buffer, "SPDIF: No Lock\n");
3441 snd_iprintf (buffer, "SPDIF: %s\n", x ? "Sync" : "Lock");
3444 x = status2 & HDSP_wc_sync;
3445 if (status2 & HDSP_wc_lock) {
3446 snd_iprintf (buffer, "Word Clock: %s\n", x ? "Sync" : "Lock");
3448 snd_iprintf (buffer, "Word Clock: No Lock\n");
3451 x = status & HDSP_TimecodeSync;
3452 if (status & HDSP_TimecodeLock) {
3453 snd_iprintf(buffer, "ADAT Sync: %s\n", x ? "Sync" : "Lock");
3455 snd_iprintf(buffer, "ADAT Sync: No Lock\n");
3458 snd_iprintf(buffer, "\n");
3460 /* Informations about H9632 specific controls */
3461 if (hdsp->io_type == H9632) {
3464 switch (hdsp_ad_gain(hdsp)) {
3475 snd_iprintf(buffer, "AD Gain : %s\n", tmp);
3477 switch (hdsp_da_gain(hdsp)) {
3488 snd_iprintf(buffer, "DA Gain : %s\n", tmp);
3490 switch (hdsp_phone_gain(hdsp)) {
3501 snd_iprintf(buffer, "Phones Gain : %s\n", tmp);
3503 snd_iprintf(buffer, "XLR Breakout Cable : %s\n", hdsp_xlr_breakout_cable(hdsp) ? "yes" : "no");
3505 if (hdsp->control_register & HDSP_AnalogExtensionBoard) {
3506 snd_iprintf(buffer, "AEB : on (ADAT1 internal)\n");
3508 snd_iprintf(buffer, "AEB : off (ADAT1 external)\n");
3510 snd_iprintf(buffer, "\n");
3515 static void __devinit snd_hdsp_proc_init(hdsp_t *hdsp)
3517 snd_info_entry_t *entry;
3519 if (! snd_card_proc_new(hdsp->card, "hdsp", &entry))
3520 snd_info_set_text_ops(entry, hdsp, 1024, snd_hdsp_proc_read);
3523 static void snd_hdsp_free_buffers(hdsp_t *hdsp)
3525 snd_hammerfall_free_buffer(&hdsp->capture_dma_buf, hdsp->pci);
3526 snd_hammerfall_free_buffer(&hdsp->playback_dma_buf, hdsp->pci);
3529 static int __devinit snd_hdsp_initialize_memory(hdsp_t *hdsp)
3531 unsigned long pb_bus, cb_bus;
3533 if (snd_hammerfall_get_buffer(hdsp->pci, &hdsp->capture_dma_buf, HDSP_DMA_AREA_BYTES) < 0 ||
3534 snd_hammerfall_get_buffer(hdsp->pci, &hdsp->playback_dma_buf, HDSP_DMA_AREA_BYTES) < 0) {
3535 if (hdsp->capture_dma_buf.area)
3536 snd_dma_free_pages(&hdsp->capture_dma_buf);
3537 printk(KERN_ERR "%s: no buffers available\n", hdsp->card_name);
3541 /* Align to bus-space 64K boundary */
3543 cb_bus = (hdsp->capture_dma_buf.addr + 0xFFFF) & ~0xFFFFl;
3544 pb_bus = (hdsp->playback_dma_buf.addr + 0xFFFF) & ~0xFFFFl;
3546 /* Tell the card where it is */
3548 hdsp_write(hdsp, HDSP_inputBufferAddress, cb_bus);
3549 hdsp_write(hdsp, HDSP_outputBufferAddress, pb_bus);
3551 hdsp->capture_buffer = hdsp->capture_dma_buf.area + (cb_bus - hdsp->capture_dma_buf.addr);
3552 hdsp->playback_buffer = hdsp->playback_dma_buf.area + (pb_bus - hdsp->playback_dma_buf.addr);
3557 static int snd_hdsp_set_defaults(hdsp_t *hdsp)
3561 /* ASSUMPTION: hdsp->lock is either held, or
3562 there is no need to hold it (e.g. during module
3568 SPDIF Input via Coax
3570 maximum latency (7 => 2^7 = 8192 samples, 64Kbyte buffer,
3571 which implies 2 4096 sample, 32Kbyte periods).
3575 hdsp->control_register = HDSP_ClockModeMaster |
3576 HDSP_SPDIFInputCoaxial |
3577 hdsp_encode_latency(7) |
3581 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
3583 #ifdef SNDRV_BIG_ENDIAN
3584 hdsp->control2_register = HDSP_BIGENDIAN_MODE;
3586 hdsp->control2_register = 0;
3588 if (hdsp->io_type == H9652) {
3589 snd_hdsp_9652_enable_mixer (hdsp);
3591 hdsp_write (hdsp, HDSP_control2Reg, hdsp->control2_register);
3594 hdsp_reset_hw_pointer(hdsp);
3595 hdsp_compute_period_size(hdsp);
3597 /* silence everything */
3599 for (i = 0; i < HDSP_MATRIX_MIXER_SIZE; ++i) {
3600 hdsp->mixer_matrix[i] = MINUS_INFINITY_GAIN;
3603 for (i = 0; i < ((hdsp->io_type == H9652 || hdsp->io_type == H9632) ? 1352 : HDSP_MATRIX_MIXER_SIZE); ++i) {
3604 if (hdsp_write_gain (hdsp, i, MINUS_INFINITY_GAIN)) {
3609 if ((hdsp->io_type != H9652) && line_outs_monitor[hdsp->dev]) {
3613 snd_printk ("sending all inputs and playback streams to line outs.\n");
3615 /* route all inputs to the line outs for easy monitoring. send
3616 odd numbered channels to right, even to left.
3618 if (hdsp->io_type == H9632) {
3619 /* this is the phones/analog output */
3625 for (i = 0; i < hdsp->max_channels; i++) {
3627 if (hdsp_write_gain (hdsp, hdsp_input_to_output_key (hdsp, i, lineouts_base), UNITY_GAIN) ||
3628 hdsp_write_gain (hdsp, hdsp_playback_to_output_key (hdsp, i, lineouts_base), UNITY_GAIN)) {
3632 if (hdsp_write_gain (hdsp, hdsp_input_to_output_key (hdsp, i, lineouts_base+1), UNITY_GAIN) ||
3633 hdsp_write_gain (hdsp, hdsp_playback_to_output_key (hdsp, i, lineouts_base+1), UNITY_GAIN)) {
3643 /* H9632 specific defaults */
3644 if (hdsp->io_type == H9632) {
3645 hdsp->control_register |= (HDSP_DAGainPlus4dBu | HDSP_ADGainPlus4dBu | HDSP_PhoneGain0dB);
3646 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
3649 /* set a default rate so that the channel map is set up.
3652 hdsp_set_rate(hdsp, 48000, 1);
3657 void hdsp_midi_tasklet(unsigned long arg)
3659 hdsp_t *hdsp = (hdsp_t *)arg;
3661 if (hdsp->midi[0].pending) {
3662 snd_hdsp_midi_input_read (&hdsp->midi[0]);
3664 if (hdsp->midi[1].pending) {
3665 snd_hdsp_midi_input_read (&hdsp->midi[1]);
3669 static irqreturn_t snd_hdsp_interrupt(int irq, void *dev_id, struct pt_regs *regs)
3671 hdsp_t *hdsp = (hdsp_t *) dev_id;
3672 unsigned int status;
3676 unsigned int midi0status;
3677 unsigned int midi1status;
3680 status = hdsp_read(hdsp, HDSP_statusRegister);
3682 audio = status & HDSP_audioIRQPending;
3683 midi0 = status & HDSP_midi0IRQPending;
3684 midi1 = status & HDSP_midi1IRQPending;
3686 if (!audio && !midi0 && !midi1) {
3690 hdsp_write(hdsp, HDSP_interruptConfirmation, 0);
3692 midi0status = hdsp_read (hdsp, HDSP_midiStatusIn0) & 0xff;
3693 midi1status = hdsp_read (hdsp, HDSP_midiStatusIn1) & 0xff;
3696 if (hdsp->capture_substream) {
3697 snd_pcm_period_elapsed(hdsp->pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream);
3700 if (hdsp->playback_substream) {
3701 snd_pcm_period_elapsed(hdsp->pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream);
3705 if (midi0 && midi0status) {
3706 /* we disable interrupts for this input until processing is done */
3707 hdsp->control_register &= ~HDSP_Midi0InterruptEnable;
3708 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
3709 hdsp->midi[0].pending = 1;
3712 if (midi1 && midi1status) {
3713 /* we disable interrupts for this input until processing is done */
3714 hdsp->control_register &= ~HDSP_Midi1InterruptEnable;
3715 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
3716 hdsp->midi[1].pending = 1;
3720 tasklet_hi_schedule(&hdsp->midi_tasklet);
3724 static snd_pcm_uframes_t snd_hdsp_hw_pointer(snd_pcm_substream_t *substream)
3726 hdsp_t *hdsp = snd_pcm_substream_chip(substream);
3727 return hdsp_hw_pointer(hdsp);
3730 static char *hdsp_channel_buffer_location(hdsp_t *hdsp,
3737 snd_assert(channel >= 0 && channel < hdsp->max_channels, return NULL);
3739 if ((mapped_channel = hdsp->channel_map[channel]) < 0) {
3743 if (stream == SNDRV_PCM_STREAM_CAPTURE) {
3744 return hdsp->capture_buffer + (mapped_channel * HDSP_CHANNEL_BUFFER_BYTES);
3746 return hdsp->playback_buffer + (mapped_channel * HDSP_CHANNEL_BUFFER_BYTES);
3750 static int snd_hdsp_playback_copy(snd_pcm_substream_t *substream, int channel,
3751 snd_pcm_uframes_t pos, void __user *src, snd_pcm_uframes_t count)
3753 hdsp_t *hdsp = snd_pcm_substream_chip(substream);
3756 snd_assert(pos + count <= HDSP_CHANNEL_BUFFER_BYTES / 4, return -EINVAL);
3758 channel_buf = hdsp_channel_buffer_location (hdsp, substream->pstr->stream, channel);
3759 snd_assert(channel_buf != NULL, return -EIO);
3760 if (copy_from_user(channel_buf + pos * 4, src, count * 4))
3765 static int snd_hdsp_capture_copy(snd_pcm_substream_t *substream, int channel,
3766 snd_pcm_uframes_t pos, void __user *dst, snd_pcm_uframes_t count)
3768 hdsp_t *hdsp = snd_pcm_substream_chip(substream);
3771 snd_assert(pos + count <= HDSP_CHANNEL_BUFFER_BYTES / 4, return -EINVAL);
3773 channel_buf = hdsp_channel_buffer_location (hdsp, substream->pstr->stream, channel);
3774 snd_assert(channel_buf != NULL, return -EIO);
3775 if (copy_to_user(dst, channel_buf + pos * 4, count * 4))
3780 static int snd_hdsp_hw_silence(snd_pcm_substream_t *substream, int channel,
3781 snd_pcm_uframes_t pos, snd_pcm_uframes_t count)
3783 hdsp_t *hdsp = snd_pcm_substream_chip(substream);
3786 channel_buf = hdsp_channel_buffer_location (hdsp, substream->pstr->stream, channel);
3787 snd_assert(channel_buf != NULL, return -EIO);
3788 memset(channel_buf + pos * 4, 0, count * 4);
3792 static int snd_hdsp_reset(snd_pcm_substream_t *substream)
3794 snd_pcm_runtime_t *runtime = substream->runtime;
3795 hdsp_t *hdsp = snd_pcm_substream_chip(substream);
3796 snd_pcm_substream_t *other;
3797 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
3798 other = hdsp->capture_substream;
3800 other = hdsp->playback_substream;
3802 runtime->status->hw_ptr = hdsp_hw_pointer(hdsp);
3804 runtime->status->hw_ptr = 0;
3806 struct list_head *pos;
3807 snd_pcm_substream_t *s;
3808 snd_pcm_runtime_t *oruntime = other->runtime;
3809 snd_pcm_group_for_each(pos, substream) {
3810 s = snd_pcm_group_substream_entry(pos);
3812 oruntime->status->hw_ptr = runtime->status->hw_ptr;
3820 static int snd_hdsp_hw_params(snd_pcm_substream_t *substream,
3821 snd_pcm_hw_params_t *params)
3823 hdsp_t *hdsp = snd_pcm_substream_chip(substream);
3828 if (hdsp_check_for_iobox (hdsp)) {
3832 if (hdsp_check_for_firmware(hdsp)) {
3833 if (hdsp->state & HDSP_FirmwareCached) {
3834 if (snd_hdsp_load_firmware_from_cache(hdsp) != 0) {
3835 snd_printk("Firmware loading from cache failed, please upload manually.\n");
3838 snd_printk("No firmware loaded nor cached, please upload firmware.\n");
3843 spin_lock_irq(&hdsp->lock);
3845 if (substream->pstr->stream == SNDRV_PCM_STREAM_PLAYBACK) {
3846 hdsp->control_register &= ~(HDSP_SPDIFProfessional | HDSP_SPDIFNonAudio | HDSP_SPDIFEmphasis);
3847 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register |= hdsp->creg_spdif_stream);
3848 this_pid = hdsp->playback_pid;
3849 other_pid = hdsp->capture_pid;
3851 this_pid = hdsp->capture_pid;
3852 other_pid = hdsp->playback_pid;
3855 if ((other_pid > 0) && (this_pid != other_pid)) {
3857 /* The other stream is open, and not by the same
3858 task as this one. Make sure that the parameters
3859 that matter are the same.
3862 if (params_rate(params) != hdsp->system_sample_rate) {
3863 spin_unlock_irq(&hdsp->lock);
3864 _snd_pcm_hw_param_setempty(params, SNDRV_PCM_HW_PARAM_RATE);
3868 if (params_period_size(params) != hdsp->period_bytes / 4) {
3869 spin_unlock_irq(&hdsp->lock);
3870 _snd_pcm_hw_param_setempty(params, SNDRV_PCM_HW_PARAM_PERIOD_SIZE);
3876 spin_unlock_irq(&hdsp->lock);
3880 spin_unlock_irq(&hdsp->lock);
3883 /* how to make sure that the rate matches an externally-set one ?
3886 spin_lock_irq(&hdsp->lock);
3887 if ((err = hdsp_set_rate(hdsp, params_rate(params), 0)) < 0) {
3888 spin_unlock_irq(&hdsp->lock);
3889 _snd_pcm_hw_param_setempty(params, SNDRV_PCM_HW_PARAM_RATE);
3892 spin_unlock_irq(&hdsp->lock);
3895 if ((err = hdsp_set_interrupt_interval(hdsp, params_period_size(params))) < 0) {
3896 _snd_pcm_hw_param_setempty(params, SNDRV_PCM_HW_PARAM_PERIOD_SIZE);
3903 static int snd_hdsp_channel_info(snd_pcm_substream_t *substream,
3904 snd_pcm_channel_info_t *info)
3906 hdsp_t *hdsp = snd_pcm_substream_chip(substream);
3909 snd_assert(info->channel < hdsp->max_channels, return -EINVAL);
3911 if ((mapped_channel = hdsp->channel_map[info->channel]) < 0) {
3915 info->offset = mapped_channel * HDSP_CHANNEL_BUFFER_BYTES;
3921 static int snd_hdsp_ioctl(snd_pcm_substream_t *substream,
3922 unsigned int cmd, void *arg)
3925 case SNDRV_PCM_IOCTL1_RESET:
3927 return snd_hdsp_reset(substream);
3929 case SNDRV_PCM_IOCTL1_CHANNEL_INFO:
3931 snd_pcm_channel_info_t *info = arg;
3932 return snd_hdsp_channel_info(substream, info);
3938 return snd_pcm_lib_ioctl(substream, cmd, arg);
3941 static int snd_hdsp_trigger(snd_pcm_substream_t *substream, int cmd)
3943 hdsp_t *hdsp = snd_pcm_substream_chip(substream);
3944 snd_pcm_substream_t *other;
3947 if (hdsp_check_for_iobox (hdsp)) {
3951 if (hdsp_check_for_firmware(hdsp)) {
3952 if (hdsp->state & HDSP_FirmwareCached) {
3953 if (snd_hdsp_load_firmware_from_cache(hdsp) != 0) {
3954 snd_printk("Firmware loading from cache failed, please upload manually.\n");
3957 snd_printk("No firmware loaded nor cached, please upload firmware.\n");
3962 spin_lock(&hdsp->lock);
3963 running = hdsp->running;
3965 case SNDRV_PCM_TRIGGER_START:
3966 running |= 1 << substream->stream;
3968 case SNDRV_PCM_TRIGGER_STOP:
3969 running &= ~(1 << substream->stream);
3973 spin_unlock(&hdsp->lock);
3976 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
3977 other = hdsp->capture_substream;
3979 other = hdsp->playback_substream;
3982 struct list_head *pos;
3983 snd_pcm_substream_t *s;
3984 snd_pcm_group_for_each(pos, substream) {
3985 s = snd_pcm_group_substream_entry(pos);
3987 snd_pcm_trigger_done(s, substream);
3988 if (cmd == SNDRV_PCM_TRIGGER_START)
3989 running |= 1 << s->stream;
3991 running &= ~(1 << s->stream);
3995 if (cmd == SNDRV_PCM_TRIGGER_START) {
3996 if (!(running & (1 << SNDRV_PCM_STREAM_PLAYBACK)) &&
3997 substream->stream == SNDRV_PCM_STREAM_CAPTURE)
3998 hdsp_silence_playback(hdsp);
4001 substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
4002 hdsp_silence_playback(hdsp);
4005 if (substream->stream == SNDRV_PCM_STREAM_CAPTURE)
4006 hdsp_silence_playback(hdsp);
4009 snd_pcm_trigger_done(substream, substream);
4010 if (!hdsp->running && running)
4011 hdsp_start_audio(hdsp);
4012 else if (hdsp->running && !running)
4013 hdsp_stop_audio(hdsp);
4014 hdsp->running = running;
4015 spin_unlock(&hdsp->lock);
4020 static int snd_hdsp_prepare(snd_pcm_substream_t *substream)
4022 hdsp_t *hdsp = snd_pcm_substream_chip(substream);
4025 if (hdsp_check_for_iobox (hdsp)) {
4029 if (hdsp_check_for_firmware(hdsp)) {
4030 if (hdsp->state & HDSP_FirmwareCached) {
4031 if (snd_hdsp_load_firmware_from_cache(hdsp) != 0) {
4032 snd_printk("Firmware loading from cache failed, please upload manually.\n");
4035 snd_printk("No firmware loaded nor cached, please upload firmware.\n");
4040 spin_lock_irq(&hdsp->lock);
4042 hdsp_reset_hw_pointer(hdsp);
4043 spin_unlock_irq(&hdsp->lock);
4047 static snd_pcm_hardware_t snd_hdsp_playback_subinfo =
4049 .info = (SNDRV_PCM_INFO_MMAP |
4050 SNDRV_PCM_INFO_MMAP_VALID |
4051 SNDRV_PCM_INFO_NONINTERLEAVED |
4052 SNDRV_PCM_INFO_SYNC_START |
4053 SNDRV_PCM_INFO_DOUBLE),
4054 .formats = SNDRV_PCM_FMTBIT_S32_LE,
4055 .rates = (SNDRV_PCM_RATE_32000 |
4056 SNDRV_PCM_RATE_44100 |
4057 SNDRV_PCM_RATE_48000 |
4058 SNDRV_PCM_RATE_64000 |
4059 SNDRV_PCM_RATE_88200 |
4060 SNDRV_PCM_RATE_96000),
4064 .channels_max = HDSP_MAX_CHANNELS,
4065 .buffer_bytes_max = HDSP_CHANNEL_BUFFER_BYTES * HDSP_MAX_CHANNELS,
4066 .period_bytes_min = (64 * 4) * 10,
4067 .period_bytes_max = (8192 * 4) * HDSP_MAX_CHANNELS,
4073 static snd_pcm_hardware_t snd_hdsp_capture_subinfo =
4075 .info = (SNDRV_PCM_INFO_MMAP |
4076 SNDRV_PCM_INFO_MMAP_VALID |
4077 SNDRV_PCM_INFO_NONINTERLEAVED |
4078 SNDRV_PCM_INFO_SYNC_START),
4079 .formats = SNDRV_PCM_FMTBIT_S32_LE,
4080 .rates = (SNDRV_PCM_RATE_32000 |
4081 SNDRV_PCM_RATE_44100 |
4082 SNDRV_PCM_RATE_48000 |
4083 SNDRV_PCM_RATE_64000 |
4084 SNDRV_PCM_RATE_88200 |
4085 SNDRV_PCM_RATE_96000),
4089 .channels_max = HDSP_MAX_CHANNELS,
4090 .buffer_bytes_max = HDSP_CHANNEL_BUFFER_BYTES * HDSP_MAX_CHANNELS,
4091 .period_bytes_min = (64 * 4) * 10,
4092 .period_bytes_max = (8192 * 4) * HDSP_MAX_CHANNELS,
4098 static unsigned int hdsp_period_sizes[] = { 64, 128, 256, 512, 1024, 2048, 4096, 8192 };
4100 static snd_pcm_hw_constraint_list_t hdsp_hw_constraints_period_sizes = {
4101 .count = ARRAY_SIZE(hdsp_period_sizes),
4102 .list = hdsp_period_sizes,
4106 static unsigned int hdsp_9632_sample_rates[] = { 32000, 44100, 48000, 64000, 88200, 96000, 128000, 176400, 192000 };
4108 static snd_pcm_hw_constraint_list_t hdsp_hw_constraints_9632_sample_rates = {
4109 .count = ARRAY_SIZE(hdsp_9632_sample_rates),
4110 .list = hdsp_9632_sample_rates,
4114 static int snd_hdsp_hw_rule_in_channels(snd_pcm_hw_params_t *params,
4115 snd_pcm_hw_rule_t *rule)
4117 hdsp_t *hdsp = rule->private;
4118 snd_interval_t *c = hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS);
4119 if (hdsp->io_type == H9632) {
4120 unsigned int list[3];
4121 list[0] = hdsp->qs_in_channels;
4122 list[1] = hdsp->ds_in_channels;
4123 list[2] = hdsp->ss_in_channels;
4124 return snd_interval_list(c, 3, list, 0);
4126 unsigned int list[2];
4127 list[0] = hdsp->ds_in_channels;
4128 list[1] = hdsp->ss_in_channels;
4129 return snd_interval_list(c, 2, list, 0);
4133 static int snd_hdsp_hw_rule_out_channels(snd_pcm_hw_params_t *params,
4134 snd_pcm_hw_rule_t *rule)
4136 unsigned int list[3];
4137 hdsp_t *hdsp = rule->private;
4138 snd_interval_t *c = hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS);
4139 if (hdsp->io_type == H9632) {
4140 list[0] = hdsp->qs_out_channels;
4141 list[1] = hdsp->ds_out_channels;
4142 list[2] = hdsp->ss_out_channels;
4143 return snd_interval_list(c, 3, list, 0);
4145 list[0] = hdsp->ds_out_channels;
4146 list[1] = hdsp->ss_out_channels;
4148 return snd_interval_list(c, 2, list, 0);
4151 static int snd_hdsp_hw_rule_in_channels_rate(snd_pcm_hw_params_t *params,
4152 snd_pcm_hw_rule_t *rule)
4154 hdsp_t *hdsp = rule->private;
4155 snd_interval_t *c = hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS);
4156 snd_interval_t *r = hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE);
4157 if (r->min > 96000 && hdsp->io_type == H9632) {
4158 snd_interval_t t = {
4159 .min = hdsp->qs_in_channels,
4160 .max = hdsp->qs_in_channels,
4163 return snd_interval_refine(c, &t);
4164 } else if (r->min > 48000 && r->max <= 96000) {
4165 snd_interval_t t = {
4166 .min = hdsp->ds_in_channels,
4167 .max = hdsp->ds_in_channels,
4170 return snd_interval_refine(c, &t);
4171 } else if (r->max < 64000) {
4172 snd_interval_t t = {
4173 .min = hdsp->ss_in_channels,
4174 .max = hdsp->ss_in_channels,
4177 return snd_interval_refine(c, &t);
4182 static int snd_hdsp_hw_rule_out_channels_rate(snd_pcm_hw_params_t *params,
4183 snd_pcm_hw_rule_t *rule)
4185 hdsp_t *hdsp = rule->private;
4186 snd_interval_t *c = hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS);
4187 snd_interval_t *r = hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE);
4188 if (r->min > 96000 && hdsp->io_type == H9632) {
4189 snd_interval_t t = {
4190 .min = hdsp->qs_out_channels,
4191 .max = hdsp->qs_out_channels,
4194 return snd_interval_refine(c, &t);
4195 } else if (r->min > 48000 && r->max <= 96000) {
4196 snd_interval_t t = {
4197 .min = hdsp->ds_out_channels,
4198 .max = hdsp->ds_out_channels,
4201 return snd_interval_refine(c, &t);
4202 } else if (r->max < 64000) {
4203 snd_interval_t t = {
4204 .min = hdsp->ss_out_channels,
4205 .max = hdsp->ss_out_channels,
4208 return snd_interval_refine(c, &t);
4213 static int snd_hdsp_hw_rule_rate_out_channels(snd_pcm_hw_params_t *params,
4214 snd_pcm_hw_rule_t *rule)
4216 hdsp_t *hdsp = rule->private;
4217 snd_interval_t *c = hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS);
4218 snd_interval_t *r = hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE);
4219 if (c->min >= hdsp->ss_out_channels) {
4220 snd_interval_t t = {
4225 return snd_interval_refine(r, &t);
4226 } else if (c->max <= hdsp->qs_out_channels && hdsp->io_type == H9632) {
4227 snd_interval_t t = {
4232 return snd_interval_refine(r, &t);
4233 } else if (c->max <= hdsp->ds_out_channels) {
4234 snd_interval_t t = {
4239 return snd_interval_refine(r, &t);
4244 static int snd_hdsp_hw_rule_rate_in_channels(snd_pcm_hw_params_t *params,
4245 snd_pcm_hw_rule_t *rule)
4247 hdsp_t *hdsp = rule->private;
4248 snd_interval_t *c = hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS);
4249 snd_interval_t *r = hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE);
4250 if (c->min >= hdsp->ss_in_channels) {
4251 snd_interval_t t = {
4256 return snd_interval_refine(r, &t);
4257 } else if (c->max <= hdsp->qs_in_channels && hdsp->io_type == H9632) {
4258 snd_interval_t t = {
4263 return snd_interval_refine(r, &t);
4264 } else if (c->max <= hdsp->ds_in_channels) {
4265 snd_interval_t t = {
4270 return snd_interval_refine(r, &t);
4275 static int snd_hdsp_playback_open(snd_pcm_substream_t *substream)
4277 hdsp_t *hdsp = snd_pcm_substream_chip(substream);
4278 snd_pcm_runtime_t *runtime = substream->runtime;
4280 if (hdsp_check_for_iobox (hdsp)) {
4284 if (hdsp_check_for_firmware(hdsp)) {
4285 if (hdsp->state & HDSP_FirmwareCached) {
4286 if (snd_hdsp_load_firmware_from_cache(hdsp) != 0) {
4287 snd_printk("Firmware loading from cache failed, please upload manually.\n");
4290 snd_printk("No firmware loaded nor cached, please upload firmware.\n");
4295 spin_lock_irq(&hdsp->lock);
4297 snd_pcm_set_sync(substream);
4299 runtime->hw = snd_hdsp_playback_subinfo;
4300 runtime->dma_area = hdsp->playback_buffer;
4301 runtime->dma_bytes = HDSP_DMA_AREA_BYTES;
4303 if (hdsp->capture_substream == NULL) {
4304 hdsp_stop_audio(hdsp);
4305 hdsp_set_thru(hdsp, -1, 0);
4308 hdsp->playback_pid = current->pid;
4309 hdsp->playback_substream = substream;
4311 spin_unlock_irq(&hdsp->lock);
4313 snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24);
4314 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_SIZE, &hdsp_hw_constraints_period_sizes);
4315 if (hdsp->io_type == H9632) {
4316 runtime->hw.channels_min = hdsp->qs_out_channels;
4317 runtime->hw.channels_max = hdsp->ss_out_channels;
4318 runtime->hw.rate_max = 192000;
4319 runtime->hw.rates = SNDRV_PCM_RATE_KNOT;
4320 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, &hdsp_hw_constraints_9632_sample_rates);
4323 snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
4324 snd_hdsp_hw_rule_out_channels, hdsp,
4325 SNDRV_PCM_HW_PARAM_CHANNELS, -1);
4326 snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
4327 snd_hdsp_hw_rule_out_channels_rate, hdsp,
4328 SNDRV_PCM_HW_PARAM_RATE, -1);
4329 snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
4330 snd_hdsp_hw_rule_rate_out_channels, hdsp,
4331 SNDRV_PCM_HW_PARAM_CHANNELS, -1);
4333 hdsp->creg_spdif_stream = hdsp->creg_spdif;
4334 hdsp->spdif_ctl->vd[0].access &= ~SNDRV_CTL_ELEM_ACCESS_INACTIVE;
4335 snd_ctl_notify(hdsp->card, SNDRV_CTL_EVENT_MASK_VALUE |
4336 SNDRV_CTL_EVENT_MASK_INFO, &hdsp->spdif_ctl->id);
4340 static int snd_hdsp_playback_release(snd_pcm_substream_t *substream)
4342 hdsp_t *hdsp = snd_pcm_substream_chip(substream);
4344 spin_lock_irq(&hdsp->lock);
4346 hdsp->playback_pid = -1;
4347 hdsp->playback_substream = NULL;
4349 spin_unlock_irq(&hdsp->lock);
4351 hdsp->spdif_ctl->vd[0].access |= SNDRV_CTL_ELEM_ACCESS_INACTIVE;
4352 snd_ctl_notify(hdsp->card, SNDRV_CTL_EVENT_MASK_VALUE |
4353 SNDRV_CTL_EVENT_MASK_INFO, &hdsp->spdif_ctl->id);
4358 static int snd_hdsp_capture_open(snd_pcm_substream_t *substream)
4360 hdsp_t *hdsp = snd_pcm_substream_chip(substream);
4361 snd_pcm_runtime_t *runtime = substream->runtime;
4363 if (hdsp_check_for_iobox (hdsp)) {
4367 if (hdsp_check_for_firmware(hdsp)) {
4368 if (hdsp->state & HDSP_FirmwareCached) {
4369 if (snd_hdsp_load_firmware_from_cache(hdsp) != 0) {
4370 snd_printk("Firmware loading from cache failed, please upload manually.\n");
4373 snd_printk("No firmware loaded nor cached, please upload firmware.\n");
4378 spin_lock_irq(&hdsp->lock);
4380 snd_pcm_set_sync(substream);
4382 runtime->hw = snd_hdsp_capture_subinfo;
4383 runtime->dma_area = hdsp->capture_buffer;
4384 runtime->dma_bytes = HDSP_DMA_AREA_BYTES;
4386 if (hdsp->playback_substream == NULL) {
4387 hdsp_stop_audio(hdsp);
4388 hdsp_set_thru(hdsp, -1, 0);
4391 hdsp->capture_pid = current->pid;
4392 hdsp->capture_substream = substream;
4394 spin_unlock_irq(&hdsp->lock);
4396 snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24);
4397 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_SIZE, &hdsp_hw_constraints_period_sizes);
4398 if (hdsp->io_type == H9632) {
4399 runtime->hw.channels_min = hdsp->qs_in_channels;
4400 runtime->hw.channels_max = hdsp->ss_in_channels;
4401 runtime->hw.rate_max = 192000;
4402 runtime->hw.rates = SNDRV_PCM_RATE_KNOT;
4403 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, &hdsp_hw_constraints_9632_sample_rates);
4405 snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
4406 snd_hdsp_hw_rule_in_channels, hdsp,
4407 SNDRV_PCM_HW_PARAM_CHANNELS, -1);
4408 snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
4409 snd_hdsp_hw_rule_in_channels_rate, hdsp,
4410 SNDRV_PCM_HW_PARAM_RATE, -1);
4411 snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
4412 snd_hdsp_hw_rule_rate_in_channels, hdsp,
4413 SNDRV_PCM_HW_PARAM_CHANNELS, -1);
4417 static int snd_hdsp_capture_release(snd_pcm_substream_t *substream)
4419 hdsp_t *hdsp = snd_pcm_substream_chip(substream);
4421 spin_lock_irq(&hdsp->lock);
4423 hdsp->capture_pid = -1;
4424 hdsp->capture_substream = NULL;
4426 spin_unlock_irq(&hdsp->lock);
4430 static int snd_hdsp_hwdep_dummy_op(snd_hwdep_t *hw, struct file *file)
4432 /* we have nothing to initialize but the call is required */
4437 static int snd_hdsp_hwdep_ioctl(snd_hwdep_t *hw, struct file *file, unsigned int cmd, unsigned long arg)
4439 hdsp_t *hdsp = (hdsp_t *)hw->private_data;
4440 void __user *argp = (void __user *)arg;
4443 case SNDRV_HDSP_IOCTL_GET_PEAK_RMS: {
4444 hdsp_peak_rms_t __user *peak_rms;
4447 if (hdsp->io_type == H9652) {
4448 unsigned long rms_low, rms_high;
4449 int doublespeed = 0;
4450 if (hdsp_read (hdsp, HDSP_statusRegister) & HDSP_DoubleSpeedStatus)
4452 peak_rms = (hdsp_peak_rms_t __user *)arg;
4453 for (i = 0; i < 26; ++i) {
4454 if (!(doublespeed && (i & 4))) {
4455 if (copy_to_user_fromio((void __user *)peak_rms->input_peaks+i*4, hdsp->iobase+HDSP_9652_peakBase-i*4, 4) != 0)
4457 if (copy_to_user_fromio((void __user *)peak_rms->playback_peaks+i*4, hdsp->iobase+HDSP_9652_peakBase-(doublespeed ? 14 : 26)*4-i*4, 4) != 0)
4459 if (copy_to_user_fromio((void __user *)peak_rms->output_peaks+i*4, hdsp->iobase+HDSP_9652_peakBase-2*(doublespeed ? 14 : 26)*4-i*4, 4) != 0)
4461 rms_low = *(u32 *)(hdsp->iobase+HDSP_9652_rmsBase+i*8) & 0xFFFFFF00;
4462 rms_high = *(u32 *)(hdsp->iobase+HDSP_9652_rmsBase+i*8+4) & 0xFFFFFF00;
4463 rms_high += (rms_low >> 24);
4465 if (copy_to_user((void __user *)peak_rms->input_rms+i*8, &rms_low, 4) != 0)
4467 if (copy_to_user((void __user *)peak_rms->input_rms+i*8+4, &rms_high, 4) != 0)
4469 rms_low = *(u32 *)(hdsp->iobase+HDSP_9652_rmsBase+(doublespeed ? 14 : 26)*8+i*8) & 0xFFFFFF00;
4470 rms_high = *(u32 *)(hdsp->iobase+HDSP_9652_rmsBase+(doublespeed ? 14 : 26)*8+i*8+4) & 0xFFFFFF00;
4471 rms_high += (rms_low >> 24);
4473 if (copy_to_user((void __user *)peak_rms->playback_rms+i*8, &rms_low, 4) != 0)
4475 if (copy_to_user((void __user *)peak_rms->playback_rms+i*8+4, &rms_high, 4) != 0)
4477 rms_low = *(u32 *)(hdsp->iobase+HDSP_9652_rmsBase+2*(doublespeed ? 14 : 26)*8+i*8) & 0xFFFFFF00;
4478 rms_high = *(u32 *)(hdsp->iobase+HDSP_9652_rmsBase+2*(doublespeed ? 14 : 26)*8+i*8+4) & 0xFFFFFF00;
4479 rms_high += (rms_low >> 24);
4481 if (copy_to_user((void __user *)peak_rms->output_rms+i*8, &rms_low, 4) != 0)
4483 if (copy_to_user((void __user *)peak_rms->output_rms+i*8+4, &rms_high, 4) != 0)
4489 if (hdsp->io_type == H9632) {
4491 hdsp_9632_meters_t *m;
4492 int doublespeed = 0;
4493 if (hdsp_read (hdsp, HDSP_statusRegister) & HDSP_DoubleSpeedStatus)
4495 m = (hdsp_9632_meters_t *)(hdsp->iobase+HDSP_9632_metersBase);
4496 peak_rms = (hdsp_peak_rms_t __user *)arg;
4497 for (i = 0, j = 0; i < 16; ++i, ++j) {
4498 if (copy_to_user((void __user *)peak_rms->input_peaks+i*4, &(m->input_peak[j]), 4) != 0)
4500 if (copy_to_user((void __user *)peak_rms->playback_peaks+i*4, &(m->playback_peak[j]), 4) != 0)
4502 if (copy_to_user((void __user *)peak_rms->output_peaks+i*4, &(m->output_peak[j]), 4) != 0)
4504 if (copy_to_user((void __user *)peak_rms->input_rms+i*8, &(m->input_rms_low[j]), 4) != 0)
4506 if (copy_to_user((void __user *)peak_rms->playback_rms+i*8, &(m->playback_rms_low[j]), 4) != 0)
4508 if (copy_to_user((void __user *)peak_rms->output_rms+i*8, &(m->output_rms_low[j]), 4) != 0)
4510 if (copy_to_user((void __user *)peak_rms->input_rms+i*8+4, &(m->input_rms_high[j]), 4) != 0)
4512 if (copy_to_user((void __user *)peak_rms->playback_rms+i*8+4, &(m->playback_rms_high[j]), 4) != 0)
4514 if (copy_to_user((void __user *)peak_rms->output_rms+i*8+4, &(m->output_rms_high[j]), 4) != 0)
4516 if (doublespeed && i == 3) i += 4;
4520 if (!(hdsp->state & HDSP_FirmwareLoaded)) {
4521 snd_printk("firmware needs to be uploaded to the card.\n");
4524 peak_rms = (hdsp_peak_rms_t __user *)arg;
4525 for (i = 0; i < 26; ++i) {
4526 if (copy_to_user((void __user *)peak_rms->playback_peaks+i*4, (void *)hdsp->iobase+HDSP_playbackPeakLevel+i*4, 4) != 0)
4528 if (copy_to_user((void __user *)peak_rms->input_peaks+i*4, (void *)hdsp->iobase+HDSP_inputPeakLevel+i*4, 4) != 0)
4531 for (i = 0; i < 26; ++i) {
4532 if (copy_to_user((void __user *)peak_rms->playback_rms+i*8+4, (void *)hdsp->iobase+HDSP_playbackRmsLevel+i*8, 4) != 0)
4534 if (copy_to_user((void __user *)peak_rms->playback_rms+i*8, (void *)hdsp->iobase+HDSP_playbackRmsLevel+i*8+4, 4) != 0)
4536 if (copy_to_user((void __user *)peak_rms->input_rms+i*8+4, (void *)hdsp->iobase+HDSP_inputRmsLevel+i*8, 4) != 0)
4538 if (copy_to_user((void __user *)peak_rms->input_rms+i*8, (void *)hdsp->iobase+HDSP_inputRmsLevel+i*8+4, 4) != 0)
4541 for (i = 0; i < 28; ++i) {
4542 if (copy_to_user((void __user *)peak_rms->output_peaks+i*4, (void *)hdsp->iobase+HDSP_outputPeakLevel+i*4, 4) != 0)
4547 case SNDRV_HDSP_IOCTL_GET_CONFIG_INFO: {
4548 hdsp_config_info_t info;
4549 unsigned long flags;
4552 if (!(hdsp->state & HDSP_FirmwareLoaded)) {
4553 snd_printk("Firmware needs to be uploaded to the card.\n");
4556 spin_lock_irqsave(&hdsp->lock, flags);
4557 info.pref_sync_ref = (unsigned char)hdsp_pref_sync_ref(hdsp);
4558 info.wordclock_sync_check = (unsigned char)hdsp_wc_sync_check(hdsp);
4559 if (hdsp->io_type != H9632) {
4560 info.adatsync_sync_check = (unsigned char)hdsp_adatsync_sync_check(hdsp);
4562 info.spdif_sync_check = (unsigned char)hdsp_spdif_sync_check(hdsp);
4563 for (i = 0; i < ((hdsp->io_type != Multiface && hdsp->io_type != H9632) ? 3 : 1); ++i) {
4564 info.adat_sync_check[i] = (unsigned char)hdsp_adat_sync_check(hdsp, i);
4566 info.spdif_in = (unsigned char)hdsp_spdif_in(hdsp);
4567 info.spdif_out = (unsigned char)hdsp_spdif_out(hdsp);
4568 info.spdif_professional = (unsigned char)hdsp_spdif_professional(hdsp);
4569 info.spdif_emphasis = (unsigned char)hdsp_spdif_emphasis(hdsp);
4570 info.spdif_nonaudio = (unsigned char)hdsp_spdif_nonaudio(hdsp);
4571 info.spdif_sample_rate = hdsp_spdif_sample_rate(hdsp);
4572 info.system_sample_rate = hdsp->system_sample_rate;
4573 info.autosync_sample_rate = hdsp_external_sample_rate(hdsp);
4574 info.system_clock_mode = (unsigned char)hdsp_system_clock_mode(hdsp);
4575 info.clock_source = (unsigned char)hdsp_clock_source(hdsp);
4576 info.autosync_ref = (unsigned char)hdsp_autosync_ref(hdsp);
4577 info.line_out = (unsigned char)hdsp_line_out(hdsp);
4578 info.passthru = (unsigned char)hdsp->passthru;
4579 if (hdsp->io_type == H9632) {
4580 info.da_gain = (unsigned char)hdsp_da_gain(hdsp);
4581 info.ad_gain = (unsigned char)hdsp_ad_gain(hdsp);
4582 info.phone_gain = (unsigned char)hdsp_phone_gain(hdsp);
4583 info.xlr_breakout_cable = (unsigned char)hdsp_xlr_breakout_cable(hdsp);
4586 if (hdsp->io_type == H9632 || hdsp->io_type == H9652) {
4587 info.analog_extension_board = (unsigned char)hdsp_aeb(hdsp);
4589 spin_unlock_irqrestore(&hdsp->lock, flags);
4590 if (copy_to_user(argp, &info, sizeof(info)))
4594 case SNDRV_HDSP_IOCTL_GET_9632_AEB: {
4595 hdsp_9632_aeb_t h9632_aeb;
4597 if (hdsp->io_type != H9632) return -EINVAL;
4598 h9632_aeb.aebi = hdsp->ss_in_channels - H9632_SS_CHANNELS;
4599 h9632_aeb.aebo = hdsp->ss_out_channels - H9632_SS_CHANNELS;
4600 if (copy_to_user(argp, &h9632_aeb, sizeof(h9632_aeb)))
4604 case SNDRV_HDSP_IOCTL_GET_VERSION: {
4605 hdsp_version_t hdsp_version;
4608 if (hdsp->io_type == H9652 || hdsp->io_type == H9632) return -EINVAL;
4609 if (hdsp->io_type == Undefined) {
4610 if ((err = hdsp_get_iobox_version(hdsp)) < 0) {
4614 hdsp_version.io_type = hdsp->io_type;
4615 hdsp_version.firmware_rev = hdsp->firmware_rev;
4616 if ((err = copy_to_user(argp, &hdsp_version, sizeof(hdsp_version)))) {
4621 case SNDRV_HDSP_IOCTL_UPLOAD_FIRMWARE: {
4622 hdsp_firmware_t __user *firmware;
4623 unsigned long __user *firmware_data;
4626 if (hdsp->io_type == H9652 || hdsp->io_type == H9632) return -EINVAL;
4627 /* SNDRV_HDSP_IOCTL_GET_VERSION must have been called */
4628 if (hdsp->io_type == Undefined) return -EINVAL;
4630 snd_printk("initializing firmware upload\n");
4631 firmware = (hdsp_firmware_t __user *)argp;
4633 if (get_user(firmware_data, &firmware->firmware_data)) {
4637 if (hdsp_check_for_iobox (hdsp)) {
4641 if (copy_from_user(hdsp->firmware_cache, firmware_data, sizeof(unsigned long)*24413) != 0) {
4645 hdsp->state |= HDSP_FirmwareCached;
4647 if ((err = snd_hdsp_load_firmware_from_cache(hdsp)) < 0) {
4651 if (!(hdsp->state & HDSP_InitializationComplete)) {
4652 snd_hdsp_initialize_channels(hdsp);
4654 snd_hdsp_initialize_midi_flush(hdsp);
4656 if ((err = snd_hdsp_create_alsa_devices(hdsp->card, hdsp)) < 0) {
4657 snd_printk("error creating alsa devices\n");
4663 case SNDRV_HDSP_IOCTL_GET_MIXER: {
4664 hdsp_mixer_t __user *mixer = (hdsp_mixer_t __user *)argp;
4665 if (copy_to_user(mixer->matrix, hdsp->mixer_matrix, sizeof(unsigned short)*HDSP_MATRIX_MIXER_SIZE))
4675 static snd_pcm_ops_t snd_hdsp_playback_ops = {
4676 .open = snd_hdsp_playback_open,
4677 .close = snd_hdsp_playback_release,
4678 .ioctl = snd_hdsp_ioctl,
4679 .hw_params = snd_hdsp_hw_params,
4680 .prepare = snd_hdsp_prepare,
4681 .trigger = snd_hdsp_trigger,
4682 .pointer = snd_hdsp_hw_pointer,
4683 .copy = snd_hdsp_playback_copy,
4684 .silence = snd_hdsp_hw_silence,
4687 static snd_pcm_ops_t snd_hdsp_capture_ops = {
4688 .open = snd_hdsp_capture_open,
4689 .close = snd_hdsp_capture_release,
4690 .ioctl = snd_hdsp_ioctl,
4691 .hw_params = snd_hdsp_hw_params,
4692 .prepare = snd_hdsp_prepare,
4693 .trigger = snd_hdsp_trigger,
4694 .pointer = snd_hdsp_hw_pointer,
4695 .copy = snd_hdsp_capture_copy,
4698 static int __devinit snd_hdsp_create_hwdep(snd_card_t *card,
4704 if ((err = snd_hwdep_new(card, "HDSP hwdep", 0, &hw)) < 0)
4708 hw->private_data = hdsp;
4709 strcpy(hw->name, "HDSP hwdep interface");
4711 hw->ops.open = snd_hdsp_hwdep_dummy_op;
4712 hw->ops.ioctl = snd_hdsp_hwdep_ioctl;
4713 hw->ops.release = snd_hdsp_hwdep_dummy_op;
4718 static int __devinit snd_hdsp_create_pcm(snd_card_t *card,
4724 if ((err = snd_pcm_new(card, hdsp->card_name, 0, 1, 1, &pcm)) < 0)
4728 pcm->private_data = hdsp;
4729 strcpy(pcm->name, hdsp->card_name);
4731 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_hdsp_playback_ops);
4732 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_hdsp_capture_ops);
4734 pcm->info_flags = SNDRV_PCM_INFO_JOINT_DUPLEX;
4739 static void snd_hdsp_9652_enable_mixer (hdsp_t *hdsp)
4741 hdsp->control2_register |= HDSP_9652_ENABLE_MIXER;
4742 hdsp_write (hdsp, HDSP_control2Reg, hdsp->control2_register);
4745 static int snd_hdsp_enable_io (hdsp_t *hdsp)
4749 if (hdsp_fifo_wait (hdsp, 0, 100)) {
4753 for (i = 0; i < hdsp->max_channels; ++i) {
4754 hdsp_write (hdsp, HDSP_inputEnable + (4 * i), 1);
4755 hdsp_write (hdsp, HDSP_outputEnable + (4 * i), 1);
4761 static void snd_hdsp_initialize_channels(hdsp_t *hdsp)
4763 int status, aebi_channels, aebo_channels;
4765 switch (hdsp->io_type) {
4767 hdsp->card_name = "RME Hammerfall DSP + Digiface";
4768 hdsp->ss_in_channels = hdsp->ss_out_channels = DIGIFACE_SS_CHANNELS;
4769 hdsp->ds_in_channels = hdsp->ds_out_channels = DIGIFACE_DS_CHANNELS;
4773 hdsp->card_name = "RME Hammerfall HDSP 9652";
4774 hdsp->ss_in_channels = hdsp->ss_out_channels = H9652_SS_CHANNELS;
4775 hdsp->ds_in_channels = hdsp->ds_out_channels = H9652_DS_CHANNELS;
4779 status = hdsp_read(hdsp, HDSP_statusRegister);
4780 /* HDSP_AEBx bits are low when AEB are connected */
4781 aebi_channels = (status & HDSP_AEBI) ? 0 : 4;
4782 aebo_channels = (status & HDSP_AEBO) ? 0 : 4;
4783 hdsp->card_name = "RME Hammerfall HDSP 9632";
4784 hdsp->ss_in_channels = H9632_SS_CHANNELS+aebi_channels;
4785 hdsp->ds_in_channels = H9632_DS_CHANNELS+aebi_channels;
4786 hdsp->qs_in_channels = H9632_QS_CHANNELS+aebi_channels;
4787 hdsp->ss_out_channels = H9632_SS_CHANNELS+aebo_channels;
4788 hdsp->ds_out_channels = H9632_DS_CHANNELS+aebo_channels;
4789 hdsp->qs_out_channels = H9632_QS_CHANNELS+aebo_channels;
4793 hdsp->card_name = "RME Hammerfall DSP + Multiface";
4794 hdsp->ss_in_channels = hdsp->ss_out_channels = MULTIFACE_SS_CHANNELS;
4795 hdsp->ds_in_channels = hdsp->ds_out_channels = MULTIFACE_DS_CHANNELS;
4799 /* should never get here */
4804 static void snd_hdsp_initialize_midi_flush (hdsp_t *hdsp)
4806 snd_hdsp_flush_midi_input (hdsp, 0);
4807 snd_hdsp_flush_midi_input (hdsp, 1);
4810 static int __devinit snd_hdsp_create_alsa_devices(snd_card_t *card, hdsp_t *hdsp)
4814 if ((err = snd_hdsp_create_pcm(card, hdsp)) < 0) {
4815 snd_printk("Error creating pcm interface\n");
4820 if ((err = snd_hdsp_create_midi(card, hdsp, 0)) < 0) {
4821 snd_printk("Error creating first midi interface\n");
4826 if ((err = snd_hdsp_create_midi(card, hdsp, 1)) < 0) {
4827 snd_printk("Error creating second midi interface\n");
4831 if ((err = snd_hdsp_create_controls(card, hdsp)) < 0) {
4832 snd_printk("Error creating ctl interface\n");
4836 snd_hdsp_proc_init(hdsp);
4838 hdsp->system_sample_rate = -1;
4839 hdsp->playback_pid = -1;
4840 hdsp->capture_pid = -1;
4841 hdsp->capture_substream = NULL;
4842 hdsp->playback_substream = NULL;
4844 if ((err = snd_hdsp_set_defaults(hdsp)) < 0) {
4845 snd_printk("Error setting default values\n");
4849 if (!(hdsp->state & HDSP_InitializationComplete)) {
4850 sprintf(card->longname, "%s at 0x%lx, irq %d", hdsp->card_name,
4851 hdsp->port, hdsp->irq);
4853 if ((err = snd_card_register(card)) < 0) {
4854 snd_printk("error registering card\n");
4857 hdsp->state |= HDSP_InitializationComplete;
4863 static int __devinit snd_hdsp_create(snd_card_t *card,
4867 struct pci_dev *pci = hdsp->pci;
4874 hdsp->midi[0].rmidi = NULL;
4875 hdsp->midi[1].rmidi = NULL;
4876 hdsp->midi[0].input = NULL;
4877 hdsp->midi[1].input = NULL;
4878 hdsp->midi[0].output = NULL;
4879 hdsp->midi[1].output = NULL;
4880 spin_lock_init(&hdsp->midi[0].lock);
4881 spin_lock_init(&hdsp->midi[1].lock);
4883 hdsp->control_register = 0;
4884 hdsp->control2_register = 0;
4885 hdsp->io_type = Undefined;
4886 hdsp->max_channels = 26;
4890 spin_lock_init(&hdsp->lock);
4892 tasklet_init(&hdsp->midi_tasklet, hdsp_midi_tasklet, (unsigned long)hdsp);
4894 pci_read_config_word(hdsp->pci, PCI_CLASS_REVISION, &hdsp->firmware_rev);
4896 /* From Martin Bjoernsen :
4897 "It is important that the card's latency timer register in
4898 the PCI configuration space is set to a value much larger
4899 than 0 by the computer's BIOS or the driver.
4900 The windows driver always sets this 8 bit register [...]
4901 to its maximum 255 to avoid problems with some computers."
4903 pci_write_config_byte(hdsp->pci, PCI_LATENCY_TIMER, 0xFF);
4905 strcpy(card->driver, "H-DSP");
4906 strcpy(card->mixername, "Xilinx FPGA");
4908 switch (hdsp->firmware_rev & 0xff) {
4912 hdsp->card_name = "RME Hammerfall DSP";
4918 hdsp->card_name = "RME HDSP 9652";
4923 hdsp->card_name = "RME HDSP 9632";
4924 hdsp->max_channels = 16;
4931 if ((err = pci_enable_device(pci)) < 0) {
4935 pci_set_master(hdsp->pci);
4937 if ((err = pci_request_regions(pci, "hdsp")) < 0)
4939 hdsp->port = pci_resource_start(pci, 0);
4940 if ((hdsp->iobase = (unsigned long) ioremap_nocache(hdsp->port, HDSP_IO_EXTENT)) == 0) {
4941 snd_printk("unable to remap region 0x%lx-0x%lx\n", hdsp->port, hdsp->port + HDSP_IO_EXTENT - 1);
4945 if (request_irq(pci->irq, snd_hdsp_interrupt, SA_INTERRUPT|SA_SHIRQ, "hdsp", (void *)hdsp)) {
4946 snd_printk("unable to use IRQ %d\n", pci->irq);
4950 hdsp->irq = pci->irq;
4951 hdsp->precise_ptr = precise_ptr;
4953 if ((err = snd_hdsp_initialize_memory(hdsp)) < 0) {
4957 if (!is_9652 && !is_9632 && hdsp_check_for_iobox (hdsp)) {
4958 /* no iobox connected, we defer initialization */
4959 snd_printk("card initialization pending : waiting for firmware\n");
4960 if ((err = snd_hdsp_create_hwdep(card, hdsp)) < 0) {
4966 if ((err = snd_hdsp_enable_io(hdsp)) != 0) {
4970 if ((hdsp_read (hdsp, HDSP_statusRegister) & HDSP_DllError) != 0) {
4971 snd_printk("card initialization pending : waiting for firmware\n");
4972 if ((err = snd_hdsp_create_hwdep(card, hdsp)) < 0) {
4978 snd_printk("Firmware already loaded, initializing card.\n");
4980 if (hdsp_read(hdsp, HDSP_status2Register) & HDSP_version1) {
4981 hdsp->io_type = Multiface;
4983 hdsp->io_type = Digiface;
4987 hdsp->io_type = H9652;
4991 hdsp->io_type = H9632;
4994 if ((err = snd_hdsp_create_hwdep(card, hdsp)) < 0) {
4998 snd_hdsp_initialize_channels(hdsp);
4999 snd_hdsp_initialize_midi_flush(hdsp);
5001 hdsp->state |= HDSP_FirmwareLoaded;
5003 if ((err = snd_hdsp_create_alsa_devices(card, hdsp)) < 0) {
5010 static int snd_hdsp_free(hdsp_t *hdsp)
5013 /* stop the audio, and cancel all interrupts */
5014 hdsp->control_register &= ~(HDSP_Start|HDSP_AudioInterruptEnable|HDSP_Midi0InterruptEnable|HDSP_Midi1InterruptEnable);
5015 hdsp_write (hdsp, HDSP_controlRegister, hdsp->control_register);
5019 free_irq(hdsp->irq, (void *)hdsp);
5021 snd_hdsp_free_buffers(hdsp);
5024 iounmap((void *) hdsp->iobase);
5027 pci_release_regions(hdsp->pci);
5032 static void snd_hdsp_card_free(snd_card_t *card)
5034 hdsp_t *hdsp = (hdsp_t *) card->private_data;
5037 snd_hdsp_free(hdsp);
5040 static int __devinit snd_hdsp_probe(struct pci_dev *pci,
5041 const struct pci_device_id *pci_id)
5048 if (dev >= SNDRV_CARDS)
5055 if (!(card = snd_card_new(index[dev], id[dev], THIS_MODULE, sizeof(hdsp_t))))
5058 hdsp = (hdsp_t *) card->private_data;
5059 card->private_free = snd_hdsp_card_free;
5062 snd_card_set_dev(card, &pci->dev);
5064 if ((err = snd_hdsp_create(card, hdsp, precise_ptr[dev])) < 0) {
5065 snd_card_free(card);
5069 strcpy(card->shortname, "Hammerfall DSP");
5070 sprintf(card->longname, "%s at 0x%lx, irq %d", hdsp->card_name,
5071 hdsp->port, hdsp->irq);
5073 if ((err = snd_card_register(card)) < 0) {
5074 snd_card_free(card);
5077 pci_set_drvdata(pci, card);
5082 static void __devexit snd_hdsp_remove(struct pci_dev *pci)
5084 snd_card_free(pci_get_drvdata(pci));
5085 pci_set_drvdata(pci, NULL);
5088 static struct pci_driver driver = {
5089 .name = "RME Hammerfall DSP",
5090 .id_table = snd_hdsp_ids,
5091 .probe = snd_hdsp_probe,
5092 .remove = __devexit_p(snd_hdsp_remove),
5095 static int __init alsa_card_hdsp_init(void)
5097 return pci_module_init(&driver);
5100 static void __exit alsa_card_hdsp_exit(void)
5102 pci_unregister_driver(&driver);
5105 module_init(alsa_card_hdsp_init)
5106 module_exit(alsa_card_hdsp_exit)