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/firmware.h>
31 #include <linux/moduleparam.h>
33 #include <sound/core.h>
34 #include <sound/control.h>
35 #include <sound/pcm.h>
36 #include <sound/info.h>
37 #include <sound/asoundef.h>
38 #include <sound/rawmidi.h>
39 #include <sound/hwdep.h>
40 #include <sound/initval.h>
41 #include <sound/hdsp.h>
43 #include <asm/byteorder.h>
44 #include <asm/current.h>
47 static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
48 static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
49 static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP; /* Enable this card */
50 static int precise_ptr[SNDRV_CARDS] = { [0 ... (SNDRV_CARDS-1)] = 0 }; /* Enable precise pointer */
51 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, NULL, 0444);
54 MODULE_PARM_DESC(index, "Index value for RME Hammerfall DSP interface.");
55 module_param_array(id, charp, NULL, 0444);
56 MODULE_PARM_DESC(id, "ID string for RME Hammerfall DSP interface.");
57 module_param_array(enable, bool, NULL, 0444);
58 MODULE_PARM_DESC(enable, "Enable/disable specific Hammerfall DSP soundcards.");
59 module_param_array(precise_ptr, bool, NULL, 0444);
60 MODULE_PARM_DESC(precise_ptr, "Enable precise pointer (doesn't work reliably).");
61 module_param_array(line_outs_monitor, bool, NULL, 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 /* use hotplug firmeare loader? */
404 #if defined(CONFIG_FW_LOADER) || defined(CONFIG_FW_LOADER_MODULE)
405 #ifndef HDSP_USE_HWDEP_LOADER
406 #define HDSP_FW_LOADER
410 typedef struct _hdsp hdsp_t;
411 typedef struct _hdsp_midi hdsp_midi_t;
412 typedef struct _hdsp_9632_meters hdsp_9632_meters_t;
414 struct _hdsp_9632_meters {
416 u32 playback_peak[16];
420 u32 input_rms_low[16];
421 u32 playback_rms_low[16];
422 u32 output_rms_low[16];
424 u32 input_rms_high[16];
425 u32 playback_rms_high[16];
426 u32 output_rms_high[16];
427 u32 xxx_rms_high[16];
433 snd_rawmidi_t *rmidi;
434 snd_rawmidi_substream_t *input;
435 snd_rawmidi_substream_t *output;
436 char istimer; /* timer in use */
437 struct timer_list timer;
444 snd_pcm_substream_t *capture_substream;
445 snd_pcm_substream_t *playback_substream;
447 struct tasklet_struct midi_tasklet;
449 u32 control_register; /* cached value */
450 u32 control2_register; /* cached value */
452 u32 creg_spdif_stream;
453 char *card_name; /* digiface/multiface */
454 HDSP_IO_Type io_type; /* ditto, but for code use */
455 unsigned short firmware_rev;
456 unsigned short state; /* stores state bits */
457 u32 firmware_cache[24413]; /* this helps recover from accidental iobox power failure */
458 size_t period_bytes; /* guess what this is */
459 unsigned char max_channels;
460 unsigned char qs_in_channels; /* quad speed mode for H9632 */
461 unsigned char ds_in_channels;
462 unsigned char ss_in_channels; /* different for multiface/digiface */
463 unsigned char qs_out_channels;
464 unsigned char ds_out_channels;
465 unsigned char ss_out_channels;
467 struct snd_dma_buffer capture_dma_buf;
468 struct snd_dma_buffer playback_dma_buf;
469 unsigned char *capture_buffer; /* suitably aligned address */
470 unsigned char *playback_buffer; /* suitably aligned address */
475 int passthru; /* non-zero if doing pass-thru */
476 int system_sample_rate;
481 void __iomem *iobase;
486 snd_kcontrol_t *spdif_ctl;
487 unsigned short mixer_matrix[HDSP_MATRIX_MIXER_SIZE];
490 /* These tables map the ALSA channels 1..N to the channels that we
491 need to use in order to find the relevant channel buffer. RME
492 refer to this kind of mapping as between "the ADAT channel and
493 the DMA channel." We index it using the logical audio channel,
494 and the value is the DMA channel (i.e. channel buffer number)
495 where the data for that channel can be read/written from/to.
498 static char channel_map_df_ss[HDSP_MAX_CHANNELS] = {
499 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
500 18, 19, 20, 21, 22, 23, 24, 25
503 static char channel_map_mf_ss[HDSP_MAX_CHANNELS] = { /* Multiface */
505 0, 1, 2, 3, 4, 5, 6, 7,
507 16, 17, 18, 19, 20, 21, 22, 23,
510 -1, -1, -1, -1, -1, -1, -1, -1
513 static char channel_map_ds[HDSP_MAX_CHANNELS] = {
514 /* ADAT channels are remapped */
515 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23,
516 /* channels 12 and 13 are S/PDIF */
518 /* others don't exist */
519 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
522 static char channel_map_H9632_ss[HDSP_MAX_CHANNELS] = {
524 0, 1, 2, 3, 4, 5, 6, 7,
529 /* AO4S-192 and AI4S-192 extension boards */
531 /* others don't exist */
532 -1, -1, -1, -1, -1, -1, -1, -1,
536 static char channel_map_H9632_ds[HDSP_MAX_CHANNELS] = {
543 /* AO4S-192 and AI4S-192 extension boards */
545 /* others don't exist */
546 -1, -1, -1, -1, -1, -1, -1, -1,
547 -1, -1, -1, -1, -1, -1
550 static char channel_map_H9632_qs[HDSP_MAX_CHANNELS] = {
551 /* ADAT is disabled in this mode */
556 /* AO4S-192 and AI4S-192 extension boards */
558 /* others don't exist */
559 -1, -1, -1, -1, -1, -1, -1, -1,
560 -1, -1, -1, -1, -1, -1, -1, -1,
564 static int snd_hammerfall_get_buffer(struct pci_dev *pci, struct snd_dma_buffer *dmab, size_t size)
566 dmab->dev.type = SNDRV_DMA_TYPE_DEV;
567 dmab->dev.dev = snd_dma_pci_data(pci);
568 if (! snd_dma_get_reserved_buf(dmab, snd_dma_pci_buf_id(pci))) {
569 if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(pci),
576 static void snd_hammerfall_free_buffer(struct snd_dma_buffer *dmab, struct pci_dev *pci)
579 snd_dma_reserve_buf(dmab, snd_dma_pci_buf_id(pci));
583 static struct pci_device_id snd_hdsp_ids[] = {
585 .vendor = PCI_VENDOR_ID_XILINX,
586 .device = PCI_DEVICE_ID_XILINX_HAMMERFALL_DSP,
587 .subvendor = PCI_ANY_ID,
588 .subdevice = PCI_ANY_ID,
589 }, /* RME Hammerfall-DSP */
593 MODULE_DEVICE_TABLE(pci, snd_hdsp_ids);
596 static int snd_hdsp_create_alsa_devices(snd_card_t *card, hdsp_t *hdsp);
597 static int snd_hdsp_create_pcm(snd_card_t *card, hdsp_t *hdsp);
598 static int snd_hdsp_enable_io (hdsp_t *hdsp);
599 static void snd_hdsp_initialize_midi_flush (hdsp_t *hdsp);
600 static void snd_hdsp_initialize_channels (hdsp_t *hdsp);
601 static int hdsp_fifo_wait(hdsp_t *hdsp, int count, int timeout);
602 static int hdsp_autosync_ref(hdsp_t *hdsp);
603 static int snd_hdsp_set_defaults(hdsp_t *hdsp);
604 static void snd_hdsp_9652_enable_mixer (hdsp_t *hdsp);
606 static int hdsp_playback_to_output_key (hdsp_t *hdsp, int in, int out)
608 switch (hdsp->firmware_rev) {
610 return (64 * out) + (32 + (in));
613 return (32 * out) + (16 + (in));
615 return (52 * out) + (26 + (in));
619 static int hdsp_input_to_output_key (hdsp_t *hdsp, int in, int out)
621 switch (hdsp->firmware_rev) {
623 return (64 * out) + in;
626 return (32 * out) + in;
628 return (52 * out) + in;
632 static void hdsp_write(hdsp_t *hdsp, int reg, int val)
634 writel(val, hdsp->iobase + reg);
637 static unsigned int hdsp_read(hdsp_t *hdsp, int reg)
639 return readl (hdsp->iobase + reg);
642 static int hdsp_check_for_iobox (hdsp_t *hdsp)
645 if (hdsp->io_type == H9652 || hdsp->io_type == H9632) return 0;
646 if (hdsp_read (hdsp, HDSP_statusRegister) & HDSP_ConfigError) {
647 snd_printk ("Hammerfall-DSP: no Digiface or Multiface connected!\n");
648 hdsp->state &= ~HDSP_FirmwareLoaded;
655 static int snd_hdsp_load_firmware_from_cache(hdsp_t *hdsp) {
660 if ((hdsp_read (hdsp, HDSP_statusRegister) & HDSP_DllError) != 0) {
662 snd_printk ("loading firmware\n");
664 hdsp_write (hdsp, HDSP_control2Reg, HDSP_S_PROGRAM);
665 hdsp_write (hdsp, HDSP_fifoData, 0);
667 if (hdsp_fifo_wait (hdsp, 0, HDSP_LONG_WAIT)) {
668 snd_printk ("timeout waiting for download preparation\n");
672 hdsp_write (hdsp, HDSP_control2Reg, HDSP_S_LOAD);
674 for (i = 0; i < 24413; ++i) {
675 hdsp_write(hdsp, HDSP_fifoData, hdsp->firmware_cache[i]);
676 if (hdsp_fifo_wait (hdsp, 127, HDSP_LONG_WAIT)) {
677 snd_printk ("timeout during firmware loading\n");
682 if ((1000 / HZ) < 3000) {
683 set_current_state(TASK_UNINTERRUPTIBLE);
684 schedule_timeout((3000 * HZ + 999) / 1000);
689 if (hdsp_fifo_wait (hdsp, 0, HDSP_LONG_WAIT)) {
690 snd_printk ("timeout at end of firmware loading\n");
694 #ifdef SNDRV_BIG_ENDIAN
695 hdsp->control2_register = HDSP_BIGENDIAN_MODE;
697 hdsp->control2_register = 0;
699 hdsp_write (hdsp, HDSP_control2Reg, hdsp->control2_register);
700 snd_printk ("finished firmware loading\n");
703 if (hdsp->state & HDSP_InitializationComplete) {
704 snd_printk("firmware loaded from cache, restoring defaults\n");
705 spin_lock_irqsave(&hdsp->lock, flags);
706 snd_hdsp_set_defaults(hdsp);
707 spin_unlock_irqrestore(&hdsp->lock, flags);
710 hdsp->state |= HDSP_FirmwareLoaded;
715 static int hdsp_get_iobox_version (hdsp_t *hdsp)
719 if (hdsp_check_for_iobox (hdsp)) {
723 if ((err = snd_hdsp_enable_io(hdsp)) < 0) {
727 if ((hdsp_read (hdsp, HDSP_statusRegister) & HDSP_DllError) != 0) {
729 hdsp_write (hdsp, HDSP_control2Reg, HDSP_PROGRAM);
730 hdsp_write (hdsp, HDSP_fifoData, 0);
731 if (hdsp_fifo_wait (hdsp, 0, HDSP_SHORT_WAIT) < 0) {
735 hdsp_write (hdsp, HDSP_control2Reg, HDSP_S_LOAD);
736 hdsp_write (hdsp, HDSP_fifoData, 0);
738 if (hdsp_fifo_wait (hdsp, 0, HDSP_SHORT_WAIT)) {
739 hdsp->io_type = Multiface;
740 hdsp_write (hdsp, HDSP_control2Reg, HDSP_VERSION_BIT);
741 hdsp_write (hdsp, HDSP_control2Reg, HDSP_S_LOAD);
742 hdsp_fifo_wait (hdsp, 0, HDSP_SHORT_WAIT);
744 hdsp->io_type = Digiface;
747 /* firmware was already loaded, get iobox type */
748 if (hdsp_read(hdsp, HDSP_status2Register) & HDSP_version1) {
749 hdsp->io_type = Multiface;
751 hdsp->io_type = Digiface;
758 static int hdsp_check_for_firmware (hdsp_t *hdsp)
760 if (hdsp->io_type == H9652 || hdsp->io_type == H9632) return 0;
761 if ((hdsp_read (hdsp, HDSP_statusRegister) & HDSP_DllError) != 0) {
762 snd_printk("firmware not present.\n");
763 hdsp->state &= ~HDSP_FirmwareLoaded;
770 static int hdsp_fifo_wait(hdsp_t *hdsp, int count, int timeout)
774 /* the fifoStatus registers reports on how many words
775 are available in the command FIFO.
778 for (i = 0; i < timeout; i++) {
780 if ((int)(hdsp_read (hdsp, HDSP_fifoStatus) & 0xff) <= count)
783 /* not very friendly, but we only do this during a firmware
784 load and changing the mixer, so we just put up with it.
790 snd_printk ("wait for FIFO status <= %d failed after %d iterations\n",
795 static int hdsp_read_gain (hdsp_t *hdsp, unsigned int addr)
797 if (addr >= HDSP_MATRIX_MIXER_SIZE) {
800 return hdsp->mixer_matrix[addr];
803 static int hdsp_write_gain(hdsp_t *hdsp, unsigned int addr, unsigned short data)
807 if (addr >= HDSP_MATRIX_MIXER_SIZE)
810 if (hdsp->io_type == H9652 || hdsp->io_type == H9632) {
812 /* from martin björnsen:
814 "You can only write dwords to the
815 mixer memory which contain two
816 mixer values in the low and high
817 word. So if you want to change
818 value 0 you have to read value 1
819 from the cache and write both to
820 the first dword in the mixer
824 if (hdsp->io_type == H9632 && addr >= 512) {
828 if (hdsp->io_type == H9652 && addr >= 1352) {
832 hdsp->mixer_matrix[addr] = data;
835 /* `addr' addresses a 16-bit wide address, but
836 the address space accessed via hdsp_write
837 uses byte offsets. put another way, addr
838 varies from 0 to 1351, but to access the
839 corresponding memory location, we need
840 to access 0 to 2703 ...
844 hdsp_write (hdsp, 4096 + (ad*4),
845 (hdsp->mixer_matrix[(addr&0x7fe)+1] << 16) +
846 hdsp->mixer_matrix[addr&0x7fe]);
852 ad = (addr << 16) + data;
854 if (hdsp_fifo_wait(hdsp, 127, HDSP_LONG_WAIT)) {
858 hdsp_write (hdsp, HDSP_fifoData, ad);
859 hdsp->mixer_matrix[addr] = data;
866 static int snd_hdsp_use_is_exclusive(hdsp_t *hdsp)
871 spin_lock_irqsave(&hdsp->lock, flags);
872 if ((hdsp->playback_pid != hdsp->capture_pid) &&
873 (hdsp->playback_pid >= 0) && (hdsp->capture_pid >= 0)) {
876 spin_unlock_irqrestore(&hdsp->lock, flags);
880 static int hdsp_external_sample_rate (hdsp_t *hdsp)
882 unsigned int status2 = hdsp_read(hdsp, HDSP_status2Register);
883 unsigned int rate_bits = status2 & HDSP_systemFrequencyMask;
886 case HDSP_systemFrequency32: return 32000;
887 case HDSP_systemFrequency44_1: return 44100;
888 case HDSP_systemFrequency48: return 48000;
889 case HDSP_systemFrequency64: return 64000;
890 case HDSP_systemFrequency88_2: return 88200;
891 case HDSP_systemFrequency96: return 96000;
897 static int hdsp_spdif_sample_rate(hdsp_t *hdsp)
899 unsigned int status = hdsp_read(hdsp, HDSP_statusRegister);
900 unsigned int rate_bits = (status & HDSP_spdifFrequencyMask);
902 if (status & HDSP_SPDIFErrorFlag) {
907 case HDSP_spdifFrequency32KHz: return 32000;
908 case HDSP_spdifFrequency44_1KHz: return 44100;
909 case HDSP_spdifFrequency48KHz: return 48000;
910 case HDSP_spdifFrequency64KHz: return 64000;
911 case HDSP_spdifFrequency88_2KHz: return 88200;
912 case HDSP_spdifFrequency96KHz: return 96000;
913 case HDSP_spdifFrequency128KHz:
914 if (hdsp->io_type == H9632) return 128000;
916 case HDSP_spdifFrequency176_4KHz:
917 if (hdsp->io_type == H9632) return 176400;
919 case HDSP_spdifFrequency192KHz:
920 if (hdsp->io_type == H9632) return 192000;
925 snd_printk ("unknown spdif frequency status; bits = 0x%x, status = 0x%x\n", rate_bits, status);
929 static void hdsp_compute_period_size(hdsp_t *hdsp)
931 hdsp->period_bytes = 1 << ((hdsp_decode_latency(hdsp->control_register) + 8));
934 static snd_pcm_uframes_t hdsp_hw_pointer(hdsp_t *hdsp)
938 position = hdsp_read(hdsp, HDSP_statusRegister);
940 if (!hdsp->precise_ptr) {
941 return (position & HDSP_BufferID) ? (hdsp->period_bytes / 4) : 0;
944 position &= HDSP_BufferPositionMask;
946 position &= (hdsp->period_bytes/2) - 1;
950 static void hdsp_reset_hw_pointer(hdsp_t *hdsp)
952 hdsp_write (hdsp, HDSP_resetPointer, 0);
955 static void hdsp_start_audio(hdsp_t *s)
957 s->control_register |= (HDSP_AudioInterruptEnable | HDSP_Start);
958 hdsp_write(s, HDSP_controlRegister, s->control_register);
961 static void hdsp_stop_audio(hdsp_t *s)
963 s->control_register &= ~(HDSP_Start | HDSP_AudioInterruptEnable);
964 hdsp_write(s, HDSP_controlRegister, s->control_register);
967 static void hdsp_silence_playback(hdsp_t *hdsp)
969 memset(hdsp->playback_buffer, 0, HDSP_DMA_AREA_BYTES);
972 static int hdsp_set_interrupt_interval(hdsp_t *s, unsigned int frames)
976 spin_lock_irq(&s->lock);
985 s->control_register &= ~HDSP_LatencyMask;
986 s->control_register |= hdsp_encode_latency(n);
988 hdsp_write(s, HDSP_controlRegister, s->control_register);
990 hdsp_compute_period_size(s);
992 spin_unlock_irq(&s->lock);
997 static int hdsp_set_rate(hdsp_t *hdsp, int rate, int called_internally)
999 int reject_if_open = 0;
1003 /* ASSUMPTION: hdsp->lock is either held, or
1004 there is no need for it (e.g. during module
1008 if (!(hdsp->control_register & HDSP_ClockModeMaster)) {
1009 if (called_internally) {
1010 /* request from ctl or card initialization */
1011 snd_printk("device is not running as a clock master: cannot set sample rate.\n");
1014 /* hw_param request while in AutoSync mode */
1015 int external_freq = hdsp_external_sample_rate(hdsp);
1016 int spdif_freq = hdsp_spdif_sample_rate(hdsp);
1018 if ((spdif_freq == external_freq*2) && (hdsp_autosync_ref(hdsp) >= HDSP_AUTOSYNC_FROM_ADAT1)) {
1019 snd_printk("Detected ADAT in double speed mode\n");
1020 } else if (hdsp->io_type == H9632 && (spdif_freq == external_freq*4) && (hdsp_autosync_ref(hdsp) >= HDSP_AUTOSYNC_FROM_ADAT1)) {
1021 snd_printk("Detected ADAT in quad speed mode\n");
1022 } else if (rate != external_freq) {
1023 snd_printk("No AutoSync source for requested rate\n");
1029 current_rate = hdsp->system_sample_rate;
1031 /* Changing from a "single speed" to a "double speed" rate is
1032 not allowed if any substreams are open. This is because
1033 such a change causes a shift in the location of
1034 the DMA buffers and a reduction in the number of available
1037 Note that a similar but essentially insoluble problem
1038 exists for externally-driven rate changes. All we can do
1039 is to flag rate changes in the read/write routines. */
1041 if (rate > 96000 && hdsp->io_type != H9632) {
1047 if (current_rate > 48000) {
1050 rate_bits = HDSP_Frequency32KHz;
1053 if (current_rate > 48000) {
1056 rate_bits = HDSP_Frequency44_1KHz;
1059 if (current_rate > 48000) {
1062 rate_bits = HDSP_Frequency48KHz;
1065 if (current_rate <= 48000 || current_rate > 96000) {
1068 rate_bits = HDSP_Frequency64KHz;
1071 if (current_rate <= 48000 || current_rate > 96000) {
1074 rate_bits = HDSP_Frequency88_2KHz;
1077 if (current_rate <= 48000 || current_rate > 96000) {
1080 rate_bits = HDSP_Frequency96KHz;
1083 if (current_rate < 128000) {
1086 rate_bits = HDSP_Frequency128KHz;
1089 if (current_rate < 128000) {
1092 rate_bits = HDSP_Frequency176_4KHz;
1095 if (current_rate < 128000) {
1098 rate_bits = HDSP_Frequency192KHz;
1104 if (reject_if_open && (hdsp->capture_pid >= 0 || hdsp->playback_pid >= 0)) {
1105 snd_printk ("cannot change speed mode (capture PID = %d, playback PID = %d)\n",
1107 hdsp->playback_pid);
1111 hdsp->control_register &= ~HDSP_FrequencyMask;
1112 hdsp->control_register |= rate_bits;
1113 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
1115 if (rate >= 128000) {
1116 hdsp->channel_map = channel_map_H9632_qs;
1117 } else if (rate > 48000) {
1118 if (hdsp->io_type == H9632) {
1119 hdsp->channel_map = channel_map_H9632_ds;
1121 hdsp->channel_map = channel_map_ds;
1124 switch (hdsp->io_type) {
1126 hdsp->channel_map = channel_map_mf_ss;
1130 hdsp->channel_map = channel_map_df_ss;
1133 hdsp->channel_map = channel_map_H9632_ss;
1136 /* should never happen */
1141 hdsp->system_sample_rate = rate;
1146 static void hdsp_set_thru(hdsp_t *hdsp, int channel, int enable)
1155 /* set thru for all channels */
1158 for (i = 0; i < hdsp->max_channels; i++) {
1159 hdsp_write_gain (hdsp, hdsp_input_to_output_key(hdsp,i,i), UNITY_GAIN);
1162 for (i = 0; i < hdsp->max_channels; i++) {
1163 hdsp_write_gain (hdsp, hdsp_input_to_output_key(hdsp,i,i), MINUS_INFINITY_GAIN);
1170 snd_assert(channel < hdsp->max_channels, return);
1172 mapped_channel = hdsp->channel_map[channel];
1174 snd_assert(mapped_channel > -1, return);
1177 hdsp_write_gain (hdsp, hdsp_input_to_output_key(hdsp,mapped_channel,mapped_channel), UNITY_GAIN);
1179 hdsp_write_gain (hdsp, hdsp_input_to_output_key(hdsp,mapped_channel,mapped_channel), MINUS_INFINITY_GAIN);
1184 static int hdsp_set_passthru(hdsp_t *hdsp, int onoff)
1187 hdsp_set_thru(hdsp, -1, 1);
1188 hdsp_reset_hw_pointer(hdsp);
1189 hdsp_silence_playback(hdsp);
1191 /* we don't want interrupts, so do a
1192 custom version of hdsp_start_audio().
1195 hdsp->control_register |= (HDSP_Start|HDSP_AudioInterruptEnable|hdsp_encode_latency(7));
1197 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
1200 hdsp_set_thru(hdsp, -1, 0);
1201 hdsp_stop_audio(hdsp);
1208 /*----------------------------------------------------------------------------
1210 ----------------------------------------------------------------------------*/
1212 static unsigned char snd_hdsp_midi_read_byte (hdsp_t *hdsp, int id)
1214 /* the hardware already does the relevant bit-mask with 0xff */
1216 return hdsp_read(hdsp, HDSP_midiDataIn1);
1218 return hdsp_read(hdsp, HDSP_midiDataIn0);
1222 static void snd_hdsp_midi_write_byte (hdsp_t *hdsp, int id, int val)
1224 /* the hardware already does the relevant bit-mask with 0xff */
1226 hdsp_write(hdsp, HDSP_midiDataOut1, val);
1228 hdsp_write(hdsp, HDSP_midiDataOut0, val);
1232 static int snd_hdsp_midi_input_available (hdsp_t *hdsp, int id)
1235 return (hdsp_read(hdsp, HDSP_midiStatusIn1) & 0xff);
1237 return (hdsp_read(hdsp, HDSP_midiStatusIn0) & 0xff);
1241 static int snd_hdsp_midi_output_possible (hdsp_t *hdsp, int id)
1243 int fifo_bytes_used;
1246 fifo_bytes_used = hdsp_read(hdsp, HDSP_midiStatusOut1) & 0xff;
1248 fifo_bytes_used = hdsp_read(hdsp, HDSP_midiStatusOut0) & 0xff;
1251 if (fifo_bytes_used < 128) {
1252 return 128 - fifo_bytes_used;
1258 static void snd_hdsp_flush_midi_input (hdsp_t *hdsp, int id)
1260 while (snd_hdsp_midi_input_available (hdsp, id)) {
1261 snd_hdsp_midi_read_byte (hdsp, id);
1265 static int snd_hdsp_midi_output_write (hdsp_midi_t *hmidi)
1267 unsigned long flags;
1271 unsigned char buf[128];
1273 /* Output is not interrupt driven */
1275 spin_lock_irqsave (&hmidi->lock, flags);
1276 if (hmidi->output) {
1277 if (!snd_rawmidi_transmit_empty (hmidi->output)) {
1278 if ((n_pending = snd_hdsp_midi_output_possible (hmidi->hdsp, hmidi->id)) > 0) {
1279 if (n_pending > (int)sizeof (buf))
1280 n_pending = sizeof (buf);
1282 if ((to_write = snd_rawmidi_transmit (hmidi->output, buf, n_pending)) > 0) {
1283 for (i = 0; i < to_write; ++i)
1284 snd_hdsp_midi_write_byte (hmidi->hdsp, hmidi->id, buf[i]);
1289 spin_unlock_irqrestore (&hmidi->lock, flags);
1293 static int snd_hdsp_midi_input_read (hdsp_midi_t *hmidi)
1295 unsigned char buf[128]; /* this buffer is designed to match the MIDI input FIFO size */
1296 unsigned long flags;
1300 spin_lock_irqsave (&hmidi->lock, flags);
1301 if ((n_pending = snd_hdsp_midi_input_available (hmidi->hdsp, hmidi->id)) > 0) {
1303 if (n_pending > (int)sizeof (buf)) {
1304 n_pending = sizeof (buf);
1306 for (i = 0; i < n_pending; ++i) {
1307 buf[i] = snd_hdsp_midi_read_byte (hmidi->hdsp, hmidi->id);
1310 snd_rawmidi_receive (hmidi->input, buf, n_pending);
1313 /* flush the MIDI input FIFO */
1314 while (--n_pending) {
1315 snd_hdsp_midi_read_byte (hmidi->hdsp, hmidi->id);
1321 hmidi->hdsp->control_register |= HDSP_Midi1InterruptEnable;
1323 hmidi->hdsp->control_register |= HDSP_Midi0InterruptEnable;
1325 hdsp_write(hmidi->hdsp, HDSP_controlRegister, hmidi->hdsp->control_register);
1326 spin_unlock_irqrestore (&hmidi->lock, flags);
1327 return snd_hdsp_midi_output_write (hmidi);
1330 static void snd_hdsp_midi_input_trigger(snd_rawmidi_substream_t * substream, int up)
1334 unsigned long flags;
1337 hmidi = (hdsp_midi_t *) substream->rmidi->private_data;
1339 ie = hmidi->id ? HDSP_Midi1InterruptEnable : HDSP_Midi0InterruptEnable;
1340 spin_lock_irqsave (&hdsp->lock, flags);
1342 if (!(hdsp->control_register & ie)) {
1343 snd_hdsp_flush_midi_input (hdsp, hmidi->id);
1344 hdsp->control_register |= ie;
1347 hdsp->control_register &= ~ie;
1350 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
1351 spin_unlock_irqrestore (&hdsp->lock, flags);
1354 static void snd_hdsp_midi_output_timer(unsigned long data)
1356 hdsp_midi_t *hmidi = (hdsp_midi_t *) data;
1357 unsigned long flags;
1359 snd_hdsp_midi_output_write(hmidi);
1360 spin_lock_irqsave (&hmidi->lock, flags);
1362 /* this does not bump hmidi->istimer, because the
1363 kernel automatically removed the timer when it
1364 expired, and we are now adding it back, thus
1365 leaving istimer wherever it was set before.
1368 if (hmidi->istimer) {
1369 hmidi->timer.expires = 1 + jiffies;
1370 add_timer(&hmidi->timer);
1373 spin_unlock_irqrestore (&hmidi->lock, flags);
1376 static void snd_hdsp_midi_output_trigger(snd_rawmidi_substream_t * substream, int up)
1379 unsigned long flags;
1381 hmidi = (hdsp_midi_t *) substream->rmidi->private_data;
1382 spin_lock_irqsave (&hmidi->lock, flags);
1384 if (!hmidi->istimer) {
1385 init_timer(&hmidi->timer);
1386 hmidi->timer.function = snd_hdsp_midi_output_timer;
1387 hmidi->timer.data = (unsigned long) hmidi;
1388 hmidi->timer.expires = 1 + jiffies;
1389 add_timer(&hmidi->timer);
1393 if (hmidi->istimer && --hmidi->istimer <= 0) {
1394 del_timer (&hmidi->timer);
1397 spin_unlock_irqrestore (&hmidi->lock, flags);
1399 snd_hdsp_midi_output_write(hmidi);
1402 static int snd_hdsp_midi_input_open(snd_rawmidi_substream_t * substream)
1406 hmidi = (hdsp_midi_t *) substream->rmidi->private_data;
1407 spin_lock_irq (&hmidi->lock);
1408 snd_hdsp_flush_midi_input (hmidi->hdsp, hmidi->id);
1409 hmidi->input = substream;
1410 spin_unlock_irq (&hmidi->lock);
1415 static int snd_hdsp_midi_output_open(snd_rawmidi_substream_t * substream)
1419 hmidi = (hdsp_midi_t *) substream->rmidi->private_data;
1420 spin_lock_irq (&hmidi->lock);
1421 hmidi->output = substream;
1422 spin_unlock_irq (&hmidi->lock);
1427 static int snd_hdsp_midi_input_close(snd_rawmidi_substream_t * substream)
1431 snd_hdsp_midi_input_trigger (substream, 0);
1433 hmidi = (hdsp_midi_t *) substream->rmidi->private_data;
1434 spin_lock_irq (&hmidi->lock);
1435 hmidi->input = NULL;
1436 spin_unlock_irq (&hmidi->lock);
1441 static int snd_hdsp_midi_output_close(snd_rawmidi_substream_t * substream)
1445 snd_hdsp_midi_output_trigger (substream, 0);
1447 hmidi = (hdsp_midi_t *) substream->rmidi->private_data;
1448 spin_lock_irq (&hmidi->lock);
1449 hmidi->output = NULL;
1450 spin_unlock_irq (&hmidi->lock);
1455 static snd_rawmidi_ops_t snd_hdsp_midi_output =
1457 .open = snd_hdsp_midi_output_open,
1458 .close = snd_hdsp_midi_output_close,
1459 .trigger = snd_hdsp_midi_output_trigger,
1462 static snd_rawmidi_ops_t snd_hdsp_midi_input =
1464 .open = snd_hdsp_midi_input_open,
1465 .close = snd_hdsp_midi_input_close,
1466 .trigger = snd_hdsp_midi_input_trigger,
1469 static int __devinit snd_hdsp_create_midi (snd_card_t *card, hdsp_t *hdsp, int id)
1473 hdsp->midi[id].id = id;
1474 hdsp->midi[id].rmidi = NULL;
1475 hdsp->midi[id].input = NULL;
1476 hdsp->midi[id].output = NULL;
1477 hdsp->midi[id].hdsp = hdsp;
1478 hdsp->midi[id].istimer = 0;
1479 hdsp->midi[id].pending = 0;
1480 spin_lock_init (&hdsp->midi[id].lock);
1482 sprintf (buf, "%s MIDI %d", card->shortname, id+1);
1483 if (snd_rawmidi_new (card, buf, id, 1, 1, &hdsp->midi[id].rmidi) < 0) {
1487 sprintf (hdsp->midi[id].rmidi->name, "%s MIDI %d", card->id, id+1);
1488 hdsp->midi[id].rmidi->private_data = &hdsp->midi[id];
1490 snd_rawmidi_set_ops (hdsp->midi[id].rmidi, SNDRV_RAWMIDI_STREAM_OUTPUT, &snd_hdsp_midi_output);
1491 snd_rawmidi_set_ops (hdsp->midi[id].rmidi, SNDRV_RAWMIDI_STREAM_INPUT, &snd_hdsp_midi_input);
1493 hdsp->midi[id].rmidi->info_flags |= SNDRV_RAWMIDI_INFO_OUTPUT |
1494 SNDRV_RAWMIDI_INFO_INPUT |
1495 SNDRV_RAWMIDI_INFO_DUPLEX;
1500 /*-----------------------------------------------------------------------------
1502 ----------------------------------------------------------------------------*/
1504 static u32 snd_hdsp_convert_from_aes(snd_aes_iec958_t *aes)
1507 val |= (aes->status[0] & IEC958_AES0_PROFESSIONAL) ? HDSP_SPDIFProfessional : 0;
1508 val |= (aes->status[0] & IEC958_AES0_NONAUDIO) ? HDSP_SPDIFNonAudio : 0;
1509 if (val & HDSP_SPDIFProfessional)
1510 val |= (aes->status[0] & IEC958_AES0_PRO_EMPHASIS_5015) ? HDSP_SPDIFEmphasis : 0;
1512 val |= (aes->status[0] & IEC958_AES0_CON_EMPHASIS_5015) ? HDSP_SPDIFEmphasis : 0;
1516 static void snd_hdsp_convert_to_aes(snd_aes_iec958_t *aes, u32 val)
1518 aes->status[0] = ((val & HDSP_SPDIFProfessional) ? IEC958_AES0_PROFESSIONAL : 0) |
1519 ((val & HDSP_SPDIFNonAudio) ? IEC958_AES0_NONAUDIO : 0);
1520 if (val & HDSP_SPDIFProfessional)
1521 aes->status[0] |= (val & HDSP_SPDIFEmphasis) ? IEC958_AES0_PRO_EMPHASIS_5015 : 0;
1523 aes->status[0] |= (val & HDSP_SPDIFEmphasis) ? IEC958_AES0_CON_EMPHASIS_5015 : 0;
1526 static int snd_hdsp_control_spdif_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
1528 uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
1533 static int snd_hdsp_control_spdif_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1535 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
1537 snd_hdsp_convert_to_aes(&ucontrol->value.iec958, hdsp->creg_spdif);
1541 static int snd_hdsp_control_spdif_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1543 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
1547 val = snd_hdsp_convert_from_aes(&ucontrol->value.iec958);
1548 spin_lock_irq(&hdsp->lock);
1549 change = val != hdsp->creg_spdif;
1550 hdsp->creg_spdif = val;
1551 spin_unlock_irq(&hdsp->lock);
1555 static int snd_hdsp_control_spdif_stream_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
1557 uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
1562 static int snd_hdsp_control_spdif_stream_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1564 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
1566 snd_hdsp_convert_to_aes(&ucontrol->value.iec958, hdsp->creg_spdif_stream);
1570 static int snd_hdsp_control_spdif_stream_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1572 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
1576 val = snd_hdsp_convert_from_aes(&ucontrol->value.iec958);
1577 spin_lock_irq(&hdsp->lock);
1578 change = val != hdsp->creg_spdif_stream;
1579 hdsp->creg_spdif_stream = val;
1580 hdsp->control_register &= ~(HDSP_SPDIFProfessional | HDSP_SPDIFNonAudio | HDSP_SPDIFEmphasis);
1581 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register |= val);
1582 spin_unlock_irq(&hdsp->lock);
1586 static int snd_hdsp_control_spdif_mask_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
1588 uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
1593 static int snd_hdsp_control_spdif_mask_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1595 ucontrol->value.iec958.status[0] = kcontrol->private_value;
1599 #define HDSP_SPDIF_IN(xname, xindex) \
1600 { .iface = SNDRV_CTL_ELEM_IFACE_PCM, \
1603 .info = snd_hdsp_info_spdif_in, \
1604 .get = snd_hdsp_get_spdif_in, \
1605 .put = snd_hdsp_put_spdif_in }
1607 static unsigned int hdsp_spdif_in(hdsp_t *hdsp)
1609 return hdsp_decode_spdif_in(hdsp->control_register & HDSP_SPDIFInputMask);
1612 static int hdsp_set_spdif_input(hdsp_t *hdsp, int in)
1614 hdsp->control_register &= ~HDSP_SPDIFInputMask;
1615 hdsp->control_register |= hdsp_encode_spdif_in(in);
1616 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
1620 static int snd_hdsp_info_spdif_in(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
1622 static char *texts[4] = {"Optical", "Coaxial", "Internal", "AES"};
1623 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
1625 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1627 uinfo->value.enumerated.items = ((hdsp->io_type == H9632) ? 4 : 3);
1628 if (uinfo->value.enumerated.item > ((hdsp->io_type == H9632) ? 3 : 2))
1629 uinfo->value.enumerated.item = ((hdsp->io_type == H9632) ? 3 : 2);
1630 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1634 static int snd_hdsp_get_spdif_in(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1636 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
1638 ucontrol->value.enumerated.item[0] = hdsp_spdif_in(hdsp);
1642 static int snd_hdsp_put_spdif_in(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1644 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
1648 if (!snd_hdsp_use_is_exclusive(hdsp))
1650 val = ucontrol->value.enumerated.item[0] % ((hdsp->io_type == H9632) ? 4 : 3);
1651 spin_lock_irq(&hdsp->lock);
1652 change = val != hdsp_spdif_in(hdsp);
1654 hdsp_set_spdif_input(hdsp, val);
1655 spin_unlock_irq(&hdsp->lock);
1659 #define HDSP_SPDIF_OUT(xname, xindex) \
1660 { .iface = SNDRV_CTL_ELEM_IFACE_HWDEP, .name = xname, .index = xindex, \
1661 .info = snd_hdsp_info_spdif_bits, \
1662 .get = snd_hdsp_get_spdif_out, .put = snd_hdsp_put_spdif_out }
1664 static int hdsp_spdif_out(hdsp_t *hdsp)
1666 return (hdsp->control_register & HDSP_SPDIFOpticalOut) ? 1 : 0;
1669 static int hdsp_set_spdif_output(hdsp_t *hdsp, int out)
1672 hdsp->control_register |= HDSP_SPDIFOpticalOut;
1674 hdsp->control_register &= ~HDSP_SPDIFOpticalOut;
1676 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
1680 static int snd_hdsp_info_spdif_bits(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
1682 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
1684 uinfo->value.integer.min = 0;
1685 uinfo->value.integer.max = 1;
1689 static int snd_hdsp_get_spdif_out(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1691 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
1693 ucontrol->value.integer.value[0] = hdsp_spdif_out(hdsp);
1697 static int snd_hdsp_put_spdif_out(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1699 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
1703 if (!snd_hdsp_use_is_exclusive(hdsp))
1705 val = ucontrol->value.integer.value[0] & 1;
1706 spin_lock_irq(&hdsp->lock);
1707 change = (int)val != hdsp_spdif_out(hdsp);
1708 hdsp_set_spdif_output(hdsp, val);
1709 spin_unlock_irq(&hdsp->lock);
1713 #define HDSP_SPDIF_PROFESSIONAL(xname, xindex) \
1714 { .iface = SNDRV_CTL_ELEM_IFACE_HWDEP, .name = xname, .index = xindex, \
1715 .info = snd_hdsp_info_spdif_bits, \
1716 .get = snd_hdsp_get_spdif_professional, .put = snd_hdsp_put_spdif_professional }
1718 static int hdsp_spdif_professional(hdsp_t *hdsp)
1720 return (hdsp->control_register & HDSP_SPDIFProfessional) ? 1 : 0;
1723 static int hdsp_set_spdif_professional(hdsp_t *hdsp, int val)
1726 hdsp->control_register |= HDSP_SPDIFProfessional;
1728 hdsp->control_register &= ~HDSP_SPDIFProfessional;
1730 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
1734 static int snd_hdsp_get_spdif_professional(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1736 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
1738 ucontrol->value.integer.value[0] = hdsp_spdif_professional(hdsp);
1742 static int snd_hdsp_put_spdif_professional(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1744 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
1748 if (!snd_hdsp_use_is_exclusive(hdsp))
1750 val = ucontrol->value.integer.value[0] & 1;
1751 spin_lock_irq(&hdsp->lock);
1752 change = (int)val != hdsp_spdif_professional(hdsp);
1753 hdsp_set_spdif_professional(hdsp, val);
1754 spin_unlock_irq(&hdsp->lock);
1758 #define HDSP_SPDIF_EMPHASIS(xname, xindex) \
1759 { .iface = SNDRV_CTL_ELEM_IFACE_HWDEP, .name = xname, .index = xindex, \
1760 .info = snd_hdsp_info_spdif_bits, \
1761 .get = snd_hdsp_get_spdif_emphasis, .put = snd_hdsp_put_spdif_emphasis }
1763 static int hdsp_spdif_emphasis(hdsp_t *hdsp)
1765 return (hdsp->control_register & HDSP_SPDIFEmphasis) ? 1 : 0;
1768 static int hdsp_set_spdif_emphasis(hdsp_t *hdsp, int val)
1771 hdsp->control_register |= HDSP_SPDIFEmphasis;
1773 hdsp->control_register &= ~HDSP_SPDIFEmphasis;
1775 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
1779 static int snd_hdsp_get_spdif_emphasis(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1781 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
1783 ucontrol->value.integer.value[0] = hdsp_spdif_emphasis(hdsp);
1787 static int snd_hdsp_put_spdif_emphasis(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1789 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
1793 if (!snd_hdsp_use_is_exclusive(hdsp))
1795 val = ucontrol->value.integer.value[0] & 1;
1796 spin_lock_irq(&hdsp->lock);
1797 change = (int)val != hdsp_spdif_emphasis(hdsp);
1798 hdsp_set_spdif_emphasis(hdsp, val);
1799 spin_unlock_irq(&hdsp->lock);
1803 #define HDSP_SPDIF_NON_AUDIO(xname, xindex) \
1804 { .iface = SNDRV_CTL_ELEM_IFACE_HWDEP, .name = xname, .index = xindex, \
1805 .info = snd_hdsp_info_spdif_bits, \
1806 .get = snd_hdsp_get_spdif_nonaudio, .put = snd_hdsp_put_spdif_nonaudio }
1808 static int hdsp_spdif_nonaudio(hdsp_t *hdsp)
1810 return (hdsp->control_register & HDSP_SPDIFNonAudio) ? 1 : 0;
1813 static int hdsp_set_spdif_nonaudio(hdsp_t *hdsp, int val)
1816 hdsp->control_register |= HDSP_SPDIFNonAudio;
1818 hdsp->control_register &= ~HDSP_SPDIFNonAudio;
1820 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
1824 static int snd_hdsp_get_spdif_nonaudio(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1826 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
1828 ucontrol->value.integer.value[0] = hdsp_spdif_nonaudio(hdsp);
1832 static int snd_hdsp_put_spdif_nonaudio(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1834 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
1838 if (!snd_hdsp_use_is_exclusive(hdsp))
1840 val = ucontrol->value.integer.value[0] & 1;
1841 spin_lock_irq(&hdsp->lock);
1842 change = (int)val != hdsp_spdif_nonaudio(hdsp);
1843 hdsp_set_spdif_nonaudio(hdsp, val);
1844 spin_unlock_irq(&hdsp->lock);
1848 #define HDSP_SPDIF_SAMPLE_RATE(xname, xindex) \
1849 { .iface = SNDRV_CTL_ELEM_IFACE_HWDEP, \
1852 .access = SNDRV_CTL_ELEM_ACCESS_READ, \
1853 .info = snd_hdsp_info_spdif_sample_rate, \
1854 .get = snd_hdsp_get_spdif_sample_rate \
1857 static int snd_hdsp_info_spdif_sample_rate(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
1859 static char *texts[] = {"32000", "44100", "48000", "64000", "88200", "96000", "None", "128000", "176400", "192000"};
1860 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
1862 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1864 uinfo->value.enumerated.items = (hdsp->io_type == H9632) ? 10 : 7;
1865 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
1866 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
1867 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1871 static int snd_hdsp_get_spdif_sample_rate(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1873 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
1875 switch (hdsp_spdif_sample_rate(hdsp)) {
1877 ucontrol->value.enumerated.item[0] = 0;
1880 ucontrol->value.enumerated.item[0] = 1;
1883 ucontrol->value.enumerated.item[0] = 2;
1886 ucontrol->value.enumerated.item[0] = 3;
1889 ucontrol->value.enumerated.item[0] = 4;
1892 ucontrol->value.enumerated.item[0] = 5;
1895 ucontrol->value.enumerated.item[0] = 7;
1898 ucontrol->value.enumerated.item[0] = 8;
1901 ucontrol->value.enumerated.item[0] = 9;
1904 ucontrol->value.enumerated.item[0] = 6;
1909 #define HDSP_SYSTEM_SAMPLE_RATE(xname, xindex) \
1910 { .iface = SNDRV_CTL_ELEM_IFACE_HWDEP, \
1913 .access = SNDRV_CTL_ELEM_ACCESS_READ, \
1914 .info = snd_hdsp_info_system_sample_rate, \
1915 .get = snd_hdsp_get_system_sample_rate \
1918 static int snd_hdsp_info_system_sample_rate(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
1920 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1925 static int snd_hdsp_get_system_sample_rate(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1927 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
1929 ucontrol->value.enumerated.item[0] = hdsp->system_sample_rate;
1933 #define HDSP_AUTOSYNC_SAMPLE_RATE(xname, xindex) \
1934 { .iface = SNDRV_CTL_ELEM_IFACE_PCM, \
1937 .access = SNDRV_CTL_ELEM_ACCESS_READ, \
1938 .info = snd_hdsp_info_autosync_sample_rate, \
1939 .get = snd_hdsp_get_autosync_sample_rate \
1942 static int snd_hdsp_info_autosync_sample_rate(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
1944 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
1945 static char *texts[] = {"32000", "44100", "48000", "64000", "88200", "96000", "None", "128000", "176400", "192000"};
1946 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1948 uinfo->value.enumerated.items = (hdsp->io_type == H9632) ? 10 : 7 ;
1949 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
1950 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
1951 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1955 static int snd_hdsp_get_autosync_sample_rate(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1957 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
1959 switch (hdsp_external_sample_rate(hdsp)) {
1961 ucontrol->value.enumerated.item[0] = 0;
1964 ucontrol->value.enumerated.item[0] = 1;
1967 ucontrol->value.enumerated.item[0] = 2;
1970 ucontrol->value.enumerated.item[0] = 3;
1973 ucontrol->value.enumerated.item[0] = 4;
1976 ucontrol->value.enumerated.item[0] = 5;
1979 ucontrol->value.enumerated.item[0] = 7;
1982 ucontrol->value.enumerated.item[0] = 8;
1985 ucontrol->value.enumerated.item[0] = 9;
1988 ucontrol->value.enumerated.item[0] = 6;
1993 #define HDSP_SYSTEM_CLOCK_MODE(xname, xindex) \
1994 { .iface = SNDRV_CTL_ELEM_IFACE_HWDEP, \
1997 .access = SNDRV_CTL_ELEM_ACCESS_READ, \
1998 .info = snd_hdsp_info_system_clock_mode, \
1999 .get = snd_hdsp_get_system_clock_mode \
2002 static int hdsp_system_clock_mode(hdsp_t *hdsp)
2004 if (hdsp->control_register & HDSP_ClockModeMaster) {
2006 } else if (hdsp_external_sample_rate(hdsp) != hdsp->system_sample_rate) {
2012 static int snd_hdsp_info_system_clock_mode(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
2014 static char *texts[] = {"Master", "Slave" };
2016 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2018 uinfo->value.enumerated.items = 2;
2019 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
2020 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
2021 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
2025 static int snd_hdsp_get_system_clock_mode(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
2027 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
2029 ucontrol->value.enumerated.item[0] = hdsp_system_clock_mode(hdsp);
2033 #define HDSP_CLOCK_SOURCE(xname, xindex) \
2034 { .iface = SNDRV_CTL_ELEM_IFACE_PCM, \
2037 .info = snd_hdsp_info_clock_source, \
2038 .get = snd_hdsp_get_clock_source, \
2039 .put = snd_hdsp_put_clock_source \
2042 static int hdsp_clock_source(hdsp_t *hdsp)
2044 if (hdsp->control_register & HDSP_ClockModeMaster) {
2045 switch (hdsp->system_sample_rate) {
2072 static int hdsp_set_clock_source(hdsp_t *hdsp, int mode)
2076 case HDSP_CLOCK_SOURCE_AUTOSYNC:
2077 if (hdsp_external_sample_rate(hdsp) != 0) {
2078 if (!hdsp_set_rate(hdsp, hdsp_external_sample_rate(hdsp), 1)) {
2079 hdsp->control_register &= ~HDSP_ClockModeMaster;
2080 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
2085 case HDSP_CLOCK_SOURCE_INTERNAL_32KHZ:
2088 case HDSP_CLOCK_SOURCE_INTERNAL_44_1KHZ:
2091 case HDSP_CLOCK_SOURCE_INTERNAL_48KHZ:
2094 case HDSP_CLOCK_SOURCE_INTERNAL_64KHZ:
2097 case HDSP_CLOCK_SOURCE_INTERNAL_88_2KHZ:
2100 case HDSP_CLOCK_SOURCE_INTERNAL_96KHZ:
2103 case HDSP_CLOCK_SOURCE_INTERNAL_128KHZ:
2106 case HDSP_CLOCK_SOURCE_INTERNAL_176_4KHZ:
2109 case HDSP_CLOCK_SOURCE_INTERNAL_192KHZ:
2115 hdsp->control_register |= HDSP_ClockModeMaster;
2116 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
2117 hdsp_set_rate(hdsp, rate, 1);
2121 static int snd_hdsp_info_clock_source(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
2123 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" };
2124 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
2126 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2128 if (hdsp->io_type == H9632)
2129 uinfo->value.enumerated.items = 10;
2131 uinfo->value.enumerated.items = 7;
2132 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
2133 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
2134 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
2138 static int snd_hdsp_get_clock_source(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
2140 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
2142 ucontrol->value.enumerated.item[0] = hdsp_clock_source(hdsp);
2146 static int snd_hdsp_put_clock_source(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
2148 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
2152 if (!snd_hdsp_use_is_exclusive(hdsp))
2154 val = ucontrol->value.enumerated.item[0];
2155 if (val < 0) val = 0;
2156 if (hdsp->io_type == H9632) {
2157 if (val > 9) val = 9;
2159 if (val > 6) val = 6;
2161 spin_lock_irq(&hdsp->lock);
2162 if (val != hdsp_clock_source(hdsp)) {
2163 change = (hdsp_set_clock_source(hdsp, val) == 0) ? 1 : 0;
2167 spin_unlock_irq(&hdsp->lock);
2171 #define HDSP_DA_GAIN(xname, xindex) \
2172 { .iface = SNDRV_CTL_ELEM_IFACE_HWDEP, \
2175 .info = snd_hdsp_info_da_gain, \
2176 .get = snd_hdsp_get_da_gain, \
2177 .put = snd_hdsp_put_da_gain \
2180 static int hdsp_da_gain(hdsp_t *hdsp)
2182 switch (hdsp->control_register & HDSP_DAGainMask) {
2183 case HDSP_DAGainHighGain:
2185 case HDSP_DAGainPlus4dBu:
2187 case HDSP_DAGainMinus10dBV:
2194 static int hdsp_set_da_gain(hdsp_t *hdsp, int mode)
2196 hdsp->control_register &= ~HDSP_DAGainMask;
2199 hdsp->control_register |= HDSP_DAGainHighGain;
2202 hdsp->control_register |= HDSP_DAGainPlus4dBu;
2205 hdsp->control_register |= HDSP_DAGainMinus10dBV;
2211 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
2215 static int snd_hdsp_info_da_gain(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
2217 static char *texts[] = {"Hi Gain", "+4 dBu", "-10 dbV"};
2219 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2221 uinfo->value.enumerated.items = 3;
2222 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
2223 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
2224 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
2228 static int snd_hdsp_get_da_gain(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
2230 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
2232 ucontrol->value.enumerated.item[0] = hdsp_da_gain(hdsp);
2236 static int snd_hdsp_put_da_gain(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
2238 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
2242 if (!snd_hdsp_use_is_exclusive(hdsp))
2244 val = ucontrol->value.enumerated.item[0];
2245 if (val < 0) val = 0;
2246 if (val > 2) val = 2;
2247 spin_lock_irq(&hdsp->lock);
2248 if (val != hdsp_da_gain(hdsp)) {
2249 change = (hdsp_set_da_gain(hdsp, val) == 0) ? 1 : 0;
2253 spin_unlock_irq(&hdsp->lock);
2257 #define HDSP_AD_GAIN(xname, xindex) \
2258 { .iface = SNDRV_CTL_ELEM_IFACE_HWDEP, \
2261 .info = snd_hdsp_info_ad_gain, \
2262 .get = snd_hdsp_get_ad_gain, \
2263 .put = snd_hdsp_put_ad_gain \
2266 static int hdsp_ad_gain(hdsp_t *hdsp)
2268 switch (hdsp->control_register & HDSP_ADGainMask) {
2269 case HDSP_ADGainMinus10dBV:
2271 case HDSP_ADGainPlus4dBu:
2273 case HDSP_ADGainLowGain:
2280 static int hdsp_set_ad_gain(hdsp_t *hdsp, int mode)
2282 hdsp->control_register &= ~HDSP_ADGainMask;
2285 hdsp->control_register |= HDSP_ADGainMinus10dBV;
2288 hdsp->control_register |= HDSP_ADGainPlus4dBu;
2291 hdsp->control_register |= HDSP_ADGainLowGain;
2297 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
2301 static int snd_hdsp_info_ad_gain(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
2303 static char *texts[] = {"-10 dBV", "+4 dBu", "Lo Gain"};
2305 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2307 uinfo->value.enumerated.items = 3;
2308 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
2309 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
2310 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
2314 static int snd_hdsp_get_ad_gain(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
2316 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
2318 ucontrol->value.enumerated.item[0] = hdsp_ad_gain(hdsp);
2322 static int snd_hdsp_put_ad_gain(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
2324 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
2328 if (!snd_hdsp_use_is_exclusive(hdsp))
2330 val = ucontrol->value.enumerated.item[0];
2331 if (val < 0) val = 0;
2332 if (val > 2) val = 2;
2333 spin_lock_irq(&hdsp->lock);
2334 if (val != hdsp_ad_gain(hdsp)) {
2335 change = (hdsp_set_ad_gain(hdsp, val) == 0) ? 1 : 0;
2339 spin_unlock_irq(&hdsp->lock);
2343 #define HDSP_PHONE_GAIN(xname, xindex) \
2344 { .iface = SNDRV_CTL_ELEM_IFACE_HWDEP, \
2347 .info = snd_hdsp_info_phone_gain, \
2348 .get = snd_hdsp_get_phone_gain, \
2349 .put = snd_hdsp_put_phone_gain \
2352 static int hdsp_phone_gain(hdsp_t *hdsp)
2354 switch (hdsp->control_register & HDSP_PhoneGainMask) {
2355 case HDSP_PhoneGain0dB:
2357 case HDSP_PhoneGainMinus6dB:
2359 case HDSP_PhoneGainMinus12dB:
2366 static int hdsp_set_phone_gain(hdsp_t *hdsp, int mode)
2368 hdsp->control_register &= ~HDSP_PhoneGainMask;
2371 hdsp->control_register |= HDSP_PhoneGain0dB;
2374 hdsp->control_register |= HDSP_PhoneGainMinus6dB;
2377 hdsp->control_register |= HDSP_PhoneGainMinus12dB;
2383 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
2387 static int snd_hdsp_info_phone_gain(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
2389 static char *texts[] = {"0 dB", "-6 dB", "-12 dB"};
2391 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2393 uinfo->value.enumerated.items = 3;
2394 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
2395 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
2396 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
2400 static int snd_hdsp_get_phone_gain(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
2402 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
2404 ucontrol->value.enumerated.item[0] = hdsp_phone_gain(hdsp);
2408 static int snd_hdsp_put_phone_gain(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
2410 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
2414 if (!snd_hdsp_use_is_exclusive(hdsp))
2416 val = ucontrol->value.enumerated.item[0];
2417 if (val < 0) val = 0;
2418 if (val > 2) val = 2;
2419 spin_lock_irq(&hdsp->lock);
2420 if (val != hdsp_phone_gain(hdsp)) {
2421 change = (hdsp_set_phone_gain(hdsp, val) == 0) ? 1 : 0;
2425 spin_unlock_irq(&hdsp->lock);
2429 #define HDSP_XLR_BREAKOUT_CABLE(xname, xindex) \
2430 { .iface = SNDRV_CTL_ELEM_IFACE_HWDEP, \
2433 .info = snd_hdsp_info_xlr_breakout_cable, \
2434 .get = snd_hdsp_get_xlr_breakout_cable, \
2435 .put = snd_hdsp_put_xlr_breakout_cable \
2438 static int hdsp_xlr_breakout_cable(hdsp_t *hdsp)
2440 if (hdsp->control_register & HDSP_XLRBreakoutCable) {
2446 static int hdsp_set_xlr_breakout_cable(hdsp_t *hdsp, int mode)
2449 hdsp->control_register |= HDSP_XLRBreakoutCable;
2451 hdsp->control_register &= ~HDSP_XLRBreakoutCable;
2453 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
2457 static int snd_hdsp_info_xlr_breakout_cable(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
2459 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
2461 uinfo->value.integer.min = 0;
2462 uinfo->value.integer.max = 1;
2466 static int snd_hdsp_get_xlr_breakout_cable(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
2468 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
2470 ucontrol->value.enumerated.item[0] = hdsp_xlr_breakout_cable(hdsp);
2474 static int snd_hdsp_put_xlr_breakout_cable(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
2476 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
2480 if (!snd_hdsp_use_is_exclusive(hdsp))
2482 val = ucontrol->value.integer.value[0] & 1;
2483 spin_lock_irq(&hdsp->lock);
2484 change = (int)val != hdsp_xlr_breakout_cable(hdsp);
2485 hdsp_set_xlr_breakout_cable(hdsp, val);
2486 spin_unlock_irq(&hdsp->lock);
2490 /* (De)activates old RME Analog Extension Board
2491 These are connected to the internal ADAT connector
2492 Switching this on desactivates external ADAT
2494 #define HDSP_AEB(xname, xindex) \
2495 { .iface = SNDRV_CTL_ELEM_IFACE_HWDEP, \
2498 .info = snd_hdsp_info_aeb, \
2499 .get = snd_hdsp_get_aeb, \
2500 .put = snd_hdsp_put_aeb \
2503 static int hdsp_aeb(hdsp_t *hdsp)
2505 if (hdsp->control_register & HDSP_AnalogExtensionBoard) {
2511 static int hdsp_set_aeb(hdsp_t *hdsp, int mode)
2514 hdsp->control_register |= HDSP_AnalogExtensionBoard;
2516 hdsp->control_register &= ~HDSP_AnalogExtensionBoard;
2518 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
2522 static int snd_hdsp_info_aeb(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
2524 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
2526 uinfo->value.integer.min = 0;
2527 uinfo->value.integer.max = 1;
2531 static int snd_hdsp_get_aeb(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
2533 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
2535 ucontrol->value.enumerated.item[0] = hdsp_aeb(hdsp);
2539 static int snd_hdsp_put_aeb(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
2541 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
2545 if (!snd_hdsp_use_is_exclusive(hdsp))
2547 val = ucontrol->value.integer.value[0] & 1;
2548 spin_lock_irq(&hdsp->lock);
2549 change = (int)val != hdsp_aeb(hdsp);
2550 hdsp_set_aeb(hdsp, val);
2551 spin_unlock_irq(&hdsp->lock);
2555 #define HDSP_PREF_SYNC_REF(xname, xindex) \
2556 { .iface = SNDRV_CTL_ELEM_IFACE_HWDEP, \
2559 .info = snd_hdsp_info_pref_sync_ref, \
2560 .get = snd_hdsp_get_pref_sync_ref, \
2561 .put = snd_hdsp_put_pref_sync_ref \
2564 static int hdsp_pref_sync_ref(hdsp_t *hdsp)
2566 /* Notice that this looks at the requested sync source,
2567 not the one actually in use.
2570 switch (hdsp->control_register & HDSP_SyncRefMask) {
2571 case HDSP_SyncRef_ADAT1:
2572 return HDSP_SYNC_FROM_ADAT1;
2573 case HDSP_SyncRef_ADAT2:
2574 return HDSP_SYNC_FROM_ADAT2;
2575 case HDSP_SyncRef_ADAT3:
2576 return HDSP_SYNC_FROM_ADAT3;
2577 case HDSP_SyncRef_SPDIF:
2578 return HDSP_SYNC_FROM_SPDIF;
2579 case HDSP_SyncRef_WORD:
2580 return HDSP_SYNC_FROM_WORD;
2581 case HDSP_SyncRef_ADAT_SYNC:
2582 return HDSP_SYNC_FROM_ADAT_SYNC;
2584 return HDSP_SYNC_FROM_WORD;
2589 static int hdsp_set_pref_sync_ref(hdsp_t *hdsp, int pref)
2591 hdsp->control_register &= ~HDSP_SyncRefMask;
2593 case HDSP_SYNC_FROM_ADAT1:
2594 hdsp->control_register &= ~HDSP_SyncRefMask; /* clear SyncRef bits */
2596 case HDSP_SYNC_FROM_ADAT2:
2597 hdsp->control_register |= HDSP_SyncRef_ADAT2;
2599 case HDSP_SYNC_FROM_ADAT3:
2600 hdsp->control_register |= HDSP_SyncRef_ADAT3;
2602 case HDSP_SYNC_FROM_SPDIF:
2603 hdsp->control_register |= HDSP_SyncRef_SPDIF;
2605 case HDSP_SYNC_FROM_WORD:
2606 hdsp->control_register |= HDSP_SyncRef_WORD;
2608 case HDSP_SYNC_FROM_ADAT_SYNC:
2609 hdsp->control_register |= HDSP_SyncRef_ADAT_SYNC;
2614 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
2618 static int snd_hdsp_info_pref_sync_ref(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
2620 static char *texts[] = {"Word", "IEC958", "ADAT1", "ADAT Sync", "ADAT2", "ADAT3" };
2621 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
2623 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2626 switch (hdsp->io_type) {
2629 uinfo->value.enumerated.items = 6;
2632 uinfo->value.enumerated.items = 4;
2635 uinfo->value.enumerated.items = 3;
2638 uinfo->value.enumerated.items = 0;
2642 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
2643 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
2644 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
2648 static int snd_hdsp_get_pref_sync_ref(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
2650 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
2652 ucontrol->value.enumerated.item[0] = hdsp_pref_sync_ref(hdsp);
2656 static int snd_hdsp_put_pref_sync_ref(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
2658 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
2662 if (!snd_hdsp_use_is_exclusive(hdsp))
2665 switch (hdsp->io_type) {
2680 val = ucontrol->value.enumerated.item[0] % max;
2681 spin_lock_irq(&hdsp->lock);
2682 change = (int)val != hdsp_pref_sync_ref(hdsp);
2683 hdsp_set_pref_sync_ref(hdsp, val);
2684 spin_unlock_irq(&hdsp->lock);
2688 #define HDSP_AUTOSYNC_REF(xname, xindex) \
2689 { .iface = SNDRV_CTL_ELEM_IFACE_HWDEP, \
2692 .access = SNDRV_CTL_ELEM_ACCESS_READ, \
2693 .info = snd_hdsp_info_autosync_ref, \
2694 .get = snd_hdsp_get_autosync_ref, \
2697 static int hdsp_autosync_ref(hdsp_t *hdsp)
2699 /* This looks at the autosync selected sync reference */
2700 unsigned int status2 = hdsp_read(hdsp, HDSP_status2Register);
2702 switch (status2 & HDSP_SelSyncRefMask) {
2703 case HDSP_SelSyncRef_WORD:
2704 return HDSP_AUTOSYNC_FROM_WORD;
2705 case HDSP_SelSyncRef_ADAT_SYNC:
2706 return HDSP_AUTOSYNC_FROM_ADAT_SYNC;
2707 case HDSP_SelSyncRef_SPDIF:
2708 return HDSP_AUTOSYNC_FROM_SPDIF;
2709 case HDSP_SelSyncRefMask:
2710 return HDSP_AUTOSYNC_FROM_NONE;
2711 case HDSP_SelSyncRef_ADAT1:
2712 return HDSP_AUTOSYNC_FROM_ADAT1;
2713 case HDSP_SelSyncRef_ADAT2:
2714 return HDSP_AUTOSYNC_FROM_ADAT2;
2715 case HDSP_SelSyncRef_ADAT3:
2716 return HDSP_AUTOSYNC_FROM_ADAT3;
2718 return HDSP_AUTOSYNC_FROM_WORD;
2723 static int snd_hdsp_info_autosync_ref(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
2725 static char *texts[] = {"Word", "ADAT Sync", "IEC958", "None", "ADAT1", "ADAT2", "ADAT3" };
2727 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2729 uinfo->value.enumerated.items = 7;
2730 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
2731 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
2732 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
2736 static int snd_hdsp_get_autosync_ref(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
2738 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
2740 ucontrol->value.enumerated.item[0] = hdsp_autosync_ref(hdsp);
2744 #define HDSP_PASSTHRU(xname, xindex) \
2745 { .iface = SNDRV_CTL_ELEM_IFACE_HWDEP, \
2748 .info = snd_hdsp_info_passthru, \
2749 .put = snd_hdsp_put_passthru, \
2750 .get = snd_hdsp_get_passthru \
2753 static int snd_hdsp_info_passthru(snd_kcontrol_t * kcontrol, snd_ctl_elem_info_t * uinfo)
2755 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
2757 uinfo->value.integer.min = 0;
2758 uinfo->value.integer.max = 1;
2762 static int snd_hdsp_get_passthru(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
2764 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
2766 spin_lock_irq(&hdsp->lock);
2767 ucontrol->value.integer.value[0] = hdsp->passthru;
2768 spin_unlock_irq(&hdsp->lock);
2772 static int snd_hdsp_put_passthru(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
2774 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
2779 if (!snd_hdsp_use_is_exclusive(hdsp))
2782 val = ucontrol->value.integer.value[0] & 1;
2783 spin_lock_irq(&hdsp->lock);
2784 change = (ucontrol->value.integer.value[0] != hdsp->passthru);
2786 err = hdsp_set_passthru(hdsp, val);
2787 spin_unlock_irq(&hdsp->lock);
2788 return err ? err : change;
2791 #define HDSP_LINE_OUT(xname, xindex) \
2792 { .iface = SNDRV_CTL_ELEM_IFACE_HWDEP, \
2795 .info = snd_hdsp_info_line_out, \
2796 .get = snd_hdsp_get_line_out, \
2797 .put = snd_hdsp_put_line_out \
2800 static int hdsp_line_out(hdsp_t *hdsp)
2802 return (hdsp->control_register & HDSP_LineOut) ? 1 : 0;
2805 static int hdsp_set_line_output(hdsp_t *hdsp, int out)
2808 hdsp->control_register |= HDSP_LineOut;
2810 hdsp->control_register &= ~HDSP_LineOut;
2812 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
2816 static int snd_hdsp_info_line_out(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
2818 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
2820 uinfo->value.integer.min = 0;
2821 uinfo->value.integer.max = 1;
2825 static int snd_hdsp_get_line_out(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
2827 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
2829 spin_lock_irq(&hdsp->lock);
2830 ucontrol->value.integer.value[0] = hdsp_line_out(hdsp);
2831 spin_unlock_irq(&hdsp->lock);
2835 static int snd_hdsp_put_line_out(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
2837 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
2841 if (!snd_hdsp_use_is_exclusive(hdsp))
2843 val = ucontrol->value.integer.value[0] & 1;
2844 spin_lock_irq(&hdsp->lock);
2845 change = (int)val != hdsp_line_out(hdsp);
2846 hdsp_set_line_output(hdsp, val);
2847 spin_unlock_irq(&hdsp->lock);
2851 #define HDSP_MIXER(xname, xindex) \
2852 { .iface = SNDRV_CTL_ELEM_IFACE_HWDEP, \
2855 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | \
2856 SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
2857 .info = snd_hdsp_info_mixer, \
2858 .get = snd_hdsp_get_mixer, \
2859 .put = snd_hdsp_put_mixer \
2862 static int snd_hdsp_info_mixer(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
2864 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
2866 uinfo->value.integer.min = 0;
2867 uinfo->value.integer.max = 65536;
2868 uinfo->value.integer.step = 1;
2872 static int snd_hdsp_get_mixer(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
2874 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
2879 source = ucontrol->value.integer.value[0];
2880 destination = ucontrol->value.integer.value[1];
2882 if (source >= hdsp->max_channels) {
2883 addr = hdsp_playback_to_output_key(hdsp,source-hdsp->max_channels,destination);
2885 addr = hdsp_input_to_output_key(hdsp,source, destination);
2888 spin_lock_irq(&hdsp->lock);
2889 ucontrol->value.integer.value[2] = hdsp_read_gain (hdsp, addr);
2890 spin_unlock_irq(&hdsp->lock);
2894 static int snd_hdsp_put_mixer(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
2896 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
2903 if (!snd_hdsp_use_is_exclusive(hdsp))
2906 source = ucontrol->value.integer.value[0];
2907 destination = ucontrol->value.integer.value[1];
2909 if (source >= hdsp->max_channels) {
2910 addr = hdsp_playback_to_output_key(hdsp,source-hdsp->max_channels, destination);
2912 addr = hdsp_input_to_output_key(hdsp,source, destination);
2915 gain = ucontrol->value.integer.value[2];
2917 spin_lock_irq(&hdsp->lock);
2918 change = gain != hdsp_read_gain(hdsp, addr);
2920 hdsp_write_gain(hdsp, addr, gain);
2921 spin_unlock_irq(&hdsp->lock);
2925 #define HDSP_WC_SYNC_CHECK(xname, xindex) \
2926 { .iface = SNDRV_CTL_ELEM_IFACE_HWDEP, \
2929 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
2930 .info = snd_hdsp_info_sync_check, \
2931 .get = snd_hdsp_get_wc_sync_check \
2934 static int snd_hdsp_info_sync_check(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
2936 static char *texts[] = {"No Lock", "Lock", "Sync" };
2937 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2939 uinfo->value.enumerated.items = 3;
2940 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
2941 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
2942 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
2946 static int hdsp_wc_sync_check(hdsp_t *hdsp)
2948 int status2 = hdsp_read(hdsp, HDSP_status2Register);
2949 if (status2 & HDSP_wc_lock) {
2950 if (status2 & HDSP_wc_sync) {
2961 static int snd_hdsp_get_wc_sync_check(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
2963 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
2965 ucontrol->value.enumerated.item[0] = hdsp_wc_sync_check(hdsp);
2969 #define HDSP_SPDIF_SYNC_CHECK(xname, xindex) \
2970 { .iface = SNDRV_CTL_ELEM_IFACE_HWDEP, \
2973 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
2974 .info = snd_hdsp_info_sync_check, \
2975 .get = snd_hdsp_get_spdif_sync_check \
2978 static int hdsp_spdif_sync_check(hdsp_t *hdsp)
2980 int status = hdsp_read(hdsp, HDSP_statusRegister);
2981 if (status & HDSP_SPDIFErrorFlag) {
2984 if (status & HDSP_SPDIFSync) {
2993 static int snd_hdsp_get_spdif_sync_check(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
2995 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
2997 ucontrol->value.enumerated.item[0] = hdsp_spdif_sync_check(hdsp);
3001 #define HDSP_ADATSYNC_SYNC_CHECK(xname, xindex) \
3002 { .iface = SNDRV_CTL_ELEM_IFACE_HWDEP, \
3005 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
3006 .info = snd_hdsp_info_sync_check, \
3007 .get = snd_hdsp_get_adatsync_sync_check \
3010 static int hdsp_adatsync_sync_check(hdsp_t *hdsp)
3012 int status = hdsp_read(hdsp, HDSP_statusRegister);
3013 if (status & HDSP_TimecodeLock) {
3014 if (status & HDSP_TimecodeSync) {
3024 static int snd_hdsp_get_adatsync_sync_check(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
3026 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
3028 ucontrol->value.enumerated.item[0] = hdsp_adatsync_sync_check(hdsp);
3032 #define HDSP_ADAT_SYNC_CHECK \
3033 { .iface = SNDRV_CTL_ELEM_IFACE_HWDEP, \
3034 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
3035 .info = snd_hdsp_info_sync_check, \
3036 .get = snd_hdsp_get_adat_sync_check \
3039 static int hdsp_adat_sync_check(hdsp_t *hdsp, int idx)
3041 int status = hdsp_read(hdsp, HDSP_statusRegister);
3043 if (status & (HDSP_Lock0>>idx)) {
3044 if (status & (HDSP_Sync0>>idx)) {
3054 static int snd_hdsp_get_adat_sync_check(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
3057 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
3059 offset = ucontrol->id.index - 1;
3060 snd_assert(offset >= 0);
3062 switch (hdsp->io_type) {
3077 ucontrol->value.enumerated.item[0] = hdsp_adat_sync_check(hdsp, offset);
3081 static snd_kcontrol_new_t snd_hdsp_9632_controls[] = {
3082 HDSP_DA_GAIN("DA Gain", 0),
3083 HDSP_AD_GAIN("AD Gain", 0),
3084 HDSP_PHONE_GAIN("Phones Gain", 0),
3085 HDSP_XLR_BREAKOUT_CABLE("XLR Breakout Cable", 0)
3088 static snd_kcontrol_new_t snd_hdsp_controls[] = {
3090 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
3091 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,DEFAULT),
3092 .info = snd_hdsp_control_spdif_info,
3093 .get = snd_hdsp_control_spdif_get,
3094 .put = snd_hdsp_control_spdif_put,
3097 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_INACTIVE,
3098 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
3099 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,PCM_STREAM),
3100 .info = snd_hdsp_control_spdif_stream_info,
3101 .get = snd_hdsp_control_spdif_stream_get,
3102 .put = snd_hdsp_control_spdif_stream_put,
3105 .access = SNDRV_CTL_ELEM_ACCESS_READ,
3106 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3107 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,CON_MASK),
3108 .info = snd_hdsp_control_spdif_mask_info,
3109 .get = snd_hdsp_control_spdif_mask_get,
3110 .private_value = IEC958_AES0_NONAUDIO |
3111 IEC958_AES0_PROFESSIONAL |
3112 IEC958_AES0_CON_EMPHASIS,
3115 .access = SNDRV_CTL_ELEM_ACCESS_READ,
3116 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3117 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,PRO_MASK),
3118 .info = snd_hdsp_control_spdif_mask_info,
3119 .get = snd_hdsp_control_spdif_mask_get,
3120 .private_value = IEC958_AES0_NONAUDIO |
3121 IEC958_AES0_PROFESSIONAL |
3122 IEC958_AES0_PRO_EMPHASIS,
3124 HDSP_MIXER("Mixer", 0),
3125 HDSP_SPDIF_IN("IEC958 Input Connector", 0),
3126 HDSP_SPDIF_OUT("IEC958 Output also on ADAT1", 0),
3127 HDSP_SPDIF_PROFESSIONAL("IEC958 Professional Bit", 0),
3128 HDSP_SPDIF_EMPHASIS("IEC958 Emphasis Bit", 0),
3129 HDSP_SPDIF_NON_AUDIO("IEC958 Non-audio Bit", 0),
3130 /* 'Sample Clock Source' complies with the alsa control naming scheme */
3131 HDSP_CLOCK_SOURCE("Sample Clock Source", 0),
3132 HDSP_SYSTEM_CLOCK_MODE("System Clock Mode", 0),
3133 HDSP_PREF_SYNC_REF("Preferred Sync Reference", 0),
3134 HDSP_AUTOSYNC_REF("AutoSync Reference", 0),
3135 HDSP_SPDIF_SAMPLE_RATE("SPDIF Sample Rate", 0),
3136 HDSP_SYSTEM_SAMPLE_RATE("System Sample Rate", 0),
3137 /* 'External Rate' complies with the alsa control naming scheme */
3138 HDSP_AUTOSYNC_SAMPLE_RATE("External Rate", 0),
3139 HDSP_WC_SYNC_CHECK("Word Clock Lock Status", 0),
3140 HDSP_SPDIF_SYNC_CHECK("SPDIF Lock Status", 0),
3141 HDSP_ADATSYNC_SYNC_CHECK("ADAT Sync Lock Status", 0),
3142 HDSP_PASSTHRU("Passthru", 0),
3143 HDSP_LINE_OUT("Line Out", 0),
3146 static snd_kcontrol_new_t snd_hdsp_96xx_aeb = HDSP_AEB("Analog Extension Board", 0);
3147 static snd_kcontrol_new_t snd_hdsp_adat_sync_check = HDSP_ADAT_SYNC_CHECK;
3149 static int snd_hdsp_create_controls(snd_card_t *card, hdsp_t *hdsp)
3153 snd_kcontrol_t *kctl;
3155 for (idx = 0; idx < ARRAY_SIZE(snd_hdsp_controls); idx++) {
3156 if ((err = snd_ctl_add(card, kctl = snd_ctl_new1(&snd_hdsp_controls[idx], hdsp))) < 0) {
3159 if (idx == 1) /* IEC958 (S/PDIF) Stream */
3160 hdsp->spdif_ctl = kctl;
3163 /* ADAT SyncCheck status */
3164 snd_hdsp_adat_sync_check.name = "ADAT Lock Status";
3165 snd_hdsp_adat_sync_check.index = 1;
3166 if ((err = snd_ctl_add (card, kctl = snd_ctl_new1(&snd_hdsp_adat_sync_check, hdsp)))) {
3169 if (hdsp->io_type == Digiface || hdsp->io_type == H9652) {
3170 for (idx = 1; idx < 3; ++idx) {
3171 snd_hdsp_adat_sync_check.index = idx+1;
3172 if ((err = snd_ctl_add (card, kctl = snd_ctl_new1(&snd_hdsp_adat_sync_check, hdsp)))) {
3178 /* DA, AD and Phone gain and XLR breakout cable controls for H9632 cards */
3179 if (hdsp->io_type == H9632) {
3180 for (idx = 0; idx < ARRAY_SIZE(snd_hdsp_9632_controls); idx++) {
3181 if ((err = snd_ctl_add(card, kctl = snd_ctl_new1(&snd_hdsp_9632_controls[idx], hdsp))) < 0) {
3187 /* AEB control for H96xx card */
3188 if (hdsp->io_type == H9632 || hdsp->io_type == H9652) {
3189 if ((err = snd_ctl_add(card, kctl = snd_ctl_new1(&snd_hdsp_96xx_aeb, hdsp))) < 0) {
3197 /*------------------------------------------------------------
3199 ------------------------------------------------------------*/
3202 snd_hdsp_proc_read(snd_info_entry_t *entry, snd_info_buffer_t *buffer)
3204 hdsp_t *hdsp = (hdsp_t *) entry->private_data;
3205 unsigned int status;
3206 unsigned int status2;
3207 char *pref_sync_ref;
3209 char *system_clock_mode;
3213 if (hdsp_check_for_iobox (hdsp)) {
3214 snd_iprintf(buffer, "No I/O box connected.\nPlease connect one and upload firmware.\n");
3218 if (hdsp_check_for_firmware(hdsp)) {
3219 if (hdsp->state & HDSP_FirmwareCached) {
3220 if (snd_hdsp_load_firmware_from_cache(hdsp) != 0) {
3221 snd_iprintf(buffer, "Firmware loading from cache failed, please upload manually.\n");
3225 snd_iprintf(buffer, "No firmware loaded nor cached, please upload firmware.\n");
3230 status = hdsp_read(hdsp, HDSP_statusRegister);
3231 status2 = hdsp_read(hdsp, HDSP_status2Register);
3233 snd_iprintf(buffer, "%s (Card #%d)\n", hdsp->card_name, hdsp->card->number + 1);
3234 snd_iprintf(buffer, "Buffers: capture %p playback %p\n",
3235 hdsp->capture_buffer, hdsp->playback_buffer);
3236 snd_iprintf(buffer, "IRQ: %d Registers bus: 0x%lx VM: 0x%lx\n",
3237 hdsp->irq, hdsp->port, (unsigned long)hdsp->iobase);
3238 snd_iprintf(buffer, "Control register: 0x%x\n", hdsp->control_register);
3239 snd_iprintf(buffer, "Control2 register: 0x%x\n", hdsp->control2_register);
3240 snd_iprintf(buffer, "Status register: 0x%x\n", status);
3241 snd_iprintf(buffer, "Status2 register: 0x%x\n", status2);
3242 snd_iprintf(buffer, "FIFO status: %d\n", hdsp_read(hdsp, HDSP_fifoStatus) & 0xff);
3244 snd_iprintf(buffer, "MIDI1 Output status: 0x%x\n", hdsp_read(hdsp, HDSP_midiStatusOut0));
3245 snd_iprintf(buffer, "MIDI1 Input status: 0x%x\n", hdsp_read(hdsp, HDSP_midiStatusIn0));
3246 snd_iprintf(buffer, "MIDI2 Output status: 0x%x\n", hdsp_read(hdsp, HDSP_midiStatusOut1));
3247 snd_iprintf(buffer, "MIDI2 Input status: 0x%x\n", hdsp_read(hdsp, HDSP_midiStatusIn1));
3249 snd_iprintf(buffer, "\n");
3251 x = 1 << (6 + hdsp_decode_latency(hdsp->control_register & HDSP_LatencyMask));
3253 snd_iprintf(buffer, "Buffer Size (Latency): %d samples (2 periods of %lu bytes)\n", x, (unsigned long) hdsp->period_bytes);
3254 snd_iprintf(buffer, "Hardware pointer (frames): %ld\n", hdsp_hw_pointer(hdsp));
3255 snd_iprintf(buffer, "Passthru: %s\n", hdsp->passthru ? "yes" : "no");
3256 snd_iprintf(buffer, "Line out: %s\n", (hdsp->control_register & HDSP_LineOut) ? "on" : "off");
3258 snd_iprintf(buffer, "Firmware version: %d\n", (status2&HDSP_version0)|(status2&HDSP_version1)<<1|(status2&HDSP_version2)<<2);
3260 snd_iprintf(buffer, "\n");
3263 switch (hdsp_clock_source(hdsp)) {
3264 case HDSP_CLOCK_SOURCE_AUTOSYNC:
3265 clock_source = "AutoSync";
3267 case HDSP_CLOCK_SOURCE_INTERNAL_32KHZ:
3268 clock_source = "Internal 32 kHz";
3270 case HDSP_CLOCK_SOURCE_INTERNAL_44_1KHZ:
3271 clock_source = "Internal 44.1 kHz";
3273 case HDSP_CLOCK_SOURCE_INTERNAL_48KHZ:
3274 clock_source = "Internal 48 kHz";
3276 case HDSP_CLOCK_SOURCE_INTERNAL_64KHZ:
3277 clock_source = "Internal 64 kHz";
3279 case HDSP_CLOCK_SOURCE_INTERNAL_88_2KHZ:
3280 clock_source = "Internal 88.2 kHz";
3282 case HDSP_CLOCK_SOURCE_INTERNAL_96KHZ:
3283 clock_source = "Internal 96 kHz";
3285 case HDSP_CLOCK_SOURCE_INTERNAL_128KHZ:
3286 clock_source = "Internal 128 kHz";
3288 case HDSP_CLOCK_SOURCE_INTERNAL_176_4KHZ:
3289 clock_source = "Internal 176.4 kHz";
3291 case HDSP_CLOCK_SOURCE_INTERNAL_192KHZ:
3292 clock_source = "Internal 192 kHz";
3295 clock_source = "Error";
3297 snd_iprintf (buffer, "Sample Clock Source: %s\n", clock_source);
3299 if (hdsp_system_clock_mode(hdsp)) {
3300 system_clock_mode = "Slave";
3302 system_clock_mode = "Master";
3305 switch (hdsp_pref_sync_ref (hdsp)) {
3306 case HDSP_SYNC_FROM_WORD:
3307 pref_sync_ref = "Word Clock";
3309 case HDSP_SYNC_FROM_ADAT_SYNC:
3310 pref_sync_ref = "ADAT Sync";
3312 case HDSP_SYNC_FROM_SPDIF:
3313 pref_sync_ref = "SPDIF";
3315 case HDSP_SYNC_FROM_ADAT1:
3316 pref_sync_ref = "ADAT1";
3318 case HDSP_SYNC_FROM_ADAT2:
3319 pref_sync_ref = "ADAT2";
3321 case HDSP_SYNC_FROM_ADAT3:
3322 pref_sync_ref = "ADAT3";
3325 pref_sync_ref = "Word Clock";
3328 snd_iprintf (buffer, "Preferred Sync Reference: %s\n", pref_sync_ref);
3330 switch (hdsp_autosync_ref (hdsp)) {
3331 case HDSP_AUTOSYNC_FROM_WORD:
3332 autosync_ref = "Word Clock";
3334 case HDSP_AUTOSYNC_FROM_ADAT_SYNC:
3335 autosync_ref = "ADAT Sync";
3337 case HDSP_AUTOSYNC_FROM_SPDIF:
3338 autosync_ref = "SPDIF";
3340 case HDSP_AUTOSYNC_FROM_NONE:
3341 autosync_ref = "None";
3343 case HDSP_AUTOSYNC_FROM_ADAT1:
3344 autosync_ref = "ADAT1";
3346 case HDSP_AUTOSYNC_FROM_ADAT2:
3347 autosync_ref = "ADAT2";
3349 case HDSP_AUTOSYNC_FROM_ADAT3:
3350 autosync_ref = "ADAT3";
3353 autosync_ref = "---";
3356 snd_iprintf (buffer, "AutoSync Reference: %s\n", autosync_ref);
3358 snd_iprintf (buffer, "AutoSync Frequency: %d\n", hdsp_external_sample_rate(hdsp));
3360 snd_iprintf (buffer, "System Clock Mode: %s\n", system_clock_mode);
3362 snd_iprintf (buffer, "System Clock Frequency: %d\n", hdsp->system_sample_rate);
3364 snd_iprintf(buffer, "\n");
3366 switch (hdsp_spdif_in(hdsp)) {
3367 case HDSP_SPDIFIN_OPTICAL:
3368 snd_iprintf(buffer, "IEC958 input: Optical\n");
3370 case HDSP_SPDIFIN_COAXIAL:
3371 snd_iprintf(buffer, "IEC958 input: Coaxial\n");
3373 case HDSP_SPDIFIN_INTERNAL:
3374 snd_iprintf(buffer, "IEC958 input: Internal\n");
3376 case HDSP_SPDIFIN_AES:
3377 snd_iprintf(buffer, "IEC958 input: AES\n");
3380 snd_iprintf(buffer, "IEC958 input: ???\n");
3384 if (hdsp->control_register & HDSP_SPDIFOpticalOut) {
3385 snd_iprintf(buffer, "IEC958 output: Coaxial & ADAT1\n");
3387 snd_iprintf(buffer, "IEC958 output: Coaxial only\n");
3390 if (hdsp->control_register & HDSP_SPDIFProfessional) {
3391 snd_iprintf(buffer, "IEC958 quality: Professional\n");
3393 snd_iprintf(buffer, "IEC958 quality: Consumer\n");
3396 if (hdsp->control_register & HDSP_SPDIFEmphasis) {
3397 snd_iprintf(buffer, "IEC958 emphasis: on\n");
3399 snd_iprintf(buffer, "IEC958 emphasis: off\n");
3402 if (hdsp->control_register & HDSP_SPDIFNonAudio) {
3403 snd_iprintf(buffer, "IEC958 NonAudio: on\n");
3405 snd_iprintf(buffer, "IEC958 NonAudio: off\n");
3407 if ((x = hdsp_spdif_sample_rate (hdsp)) != 0) {
3408 snd_iprintf (buffer, "IEC958 sample rate: %d\n", x);
3410 snd_iprintf (buffer, "IEC958 sample rate: Error flag set\n");
3413 snd_iprintf(buffer, "\n");
3416 x = status & HDSP_Sync0;
3417 if (status & HDSP_Lock0) {
3418 snd_iprintf(buffer, "ADAT1: %s\n", x ? "Sync" : "Lock");
3420 snd_iprintf(buffer, "ADAT1: No Lock\n");
3423 switch (hdsp->io_type) {
3426 x = status & HDSP_Sync1;
3427 if (status & HDSP_Lock1) {
3428 snd_iprintf(buffer, "ADAT2: %s\n", x ? "Sync" : "Lock");
3430 snd_iprintf(buffer, "ADAT2: No Lock\n");
3432 x = status & HDSP_Sync2;
3433 if (status & HDSP_Lock2) {
3434 snd_iprintf(buffer, "ADAT3: %s\n", x ? "Sync" : "Lock");
3436 snd_iprintf(buffer, "ADAT3: No Lock\n");
3443 x = status & HDSP_SPDIFSync;
3444 if (status & HDSP_SPDIFErrorFlag) {
3445 snd_iprintf (buffer, "SPDIF: No Lock\n");
3447 snd_iprintf (buffer, "SPDIF: %s\n", x ? "Sync" : "Lock");
3450 x = status2 & HDSP_wc_sync;
3451 if (status2 & HDSP_wc_lock) {
3452 snd_iprintf (buffer, "Word Clock: %s\n", x ? "Sync" : "Lock");
3454 snd_iprintf (buffer, "Word Clock: No Lock\n");
3457 x = status & HDSP_TimecodeSync;
3458 if (status & HDSP_TimecodeLock) {
3459 snd_iprintf(buffer, "ADAT Sync: %s\n", x ? "Sync" : "Lock");
3461 snd_iprintf(buffer, "ADAT Sync: No Lock\n");
3464 snd_iprintf(buffer, "\n");
3466 /* Informations about H9632 specific controls */
3467 if (hdsp->io_type == H9632) {
3470 switch (hdsp_ad_gain(hdsp)) {
3481 snd_iprintf(buffer, "AD Gain : %s\n", tmp);
3483 switch (hdsp_da_gain(hdsp)) {
3494 snd_iprintf(buffer, "DA Gain : %s\n", tmp);
3496 switch (hdsp_phone_gain(hdsp)) {
3507 snd_iprintf(buffer, "Phones Gain : %s\n", tmp);
3509 snd_iprintf(buffer, "XLR Breakout Cable : %s\n", hdsp_xlr_breakout_cable(hdsp) ? "yes" : "no");
3511 if (hdsp->control_register & HDSP_AnalogExtensionBoard) {
3512 snd_iprintf(buffer, "AEB : on (ADAT1 internal)\n");
3514 snd_iprintf(buffer, "AEB : off (ADAT1 external)\n");
3516 snd_iprintf(buffer, "\n");
3521 static void __devinit snd_hdsp_proc_init(hdsp_t *hdsp)
3523 snd_info_entry_t *entry;
3525 if (! snd_card_proc_new(hdsp->card, "hdsp", &entry))
3526 snd_info_set_text_ops(entry, hdsp, 1024, snd_hdsp_proc_read);
3529 static void snd_hdsp_free_buffers(hdsp_t *hdsp)
3531 snd_hammerfall_free_buffer(&hdsp->capture_dma_buf, hdsp->pci);
3532 snd_hammerfall_free_buffer(&hdsp->playback_dma_buf, hdsp->pci);
3535 static int __devinit snd_hdsp_initialize_memory(hdsp_t *hdsp)
3537 unsigned long pb_bus, cb_bus;
3539 if (snd_hammerfall_get_buffer(hdsp->pci, &hdsp->capture_dma_buf, HDSP_DMA_AREA_BYTES) < 0 ||
3540 snd_hammerfall_get_buffer(hdsp->pci, &hdsp->playback_dma_buf, HDSP_DMA_AREA_BYTES) < 0) {
3541 if (hdsp->capture_dma_buf.area)
3542 snd_dma_free_pages(&hdsp->capture_dma_buf);
3543 printk(KERN_ERR "%s: no buffers available\n", hdsp->card_name);
3547 /* Align to bus-space 64K boundary */
3549 cb_bus = (hdsp->capture_dma_buf.addr + 0xFFFF) & ~0xFFFFl;
3550 pb_bus = (hdsp->playback_dma_buf.addr + 0xFFFF) & ~0xFFFFl;
3552 /* Tell the card where it is */
3554 hdsp_write(hdsp, HDSP_inputBufferAddress, cb_bus);
3555 hdsp_write(hdsp, HDSP_outputBufferAddress, pb_bus);
3557 hdsp->capture_buffer = hdsp->capture_dma_buf.area + (cb_bus - hdsp->capture_dma_buf.addr);
3558 hdsp->playback_buffer = hdsp->playback_dma_buf.area + (pb_bus - hdsp->playback_dma_buf.addr);
3563 static int snd_hdsp_set_defaults(hdsp_t *hdsp)
3567 /* ASSUMPTION: hdsp->lock is either held, or
3568 there is no need to hold it (e.g. during module
3574 SPDIF Input via Coax
3576 maximum latency (7 => 2^7 = 8192 samples, 64Kbyte buffer,
3577 which implies 2 4096 sample, 32Kbyte periods).
3581 hdsp->control_register = HDSP_ClockModeMaster |
3582 HDSP_SPDIFInputCoaxial |
3583 hdsp_encode_latency(7) |
3587 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
3589 #ifdef SNDRV_BIG_ENDIAN
3590 hdsp->control2_register = HDSP_BIGENDIAN_MODE;
3592 hdsp->control2_register = 0;
3594 if (hdsp->io_type == H9652) {
3595 snd_hdsp_9652_enable_mixer (hdsp);
3597 hdsp_write (hdsp, HDSP_control2Reg, hdsp->control2_register);
3600 hdsp_reset_hw_pointer(hdsp);
3601 hdsp_compute_period_size(hdsp);
3603 /* silence everything */
3605 for (i = 0; i < HDSP_MATRIX_MIXER_SIZE; ++i) {
3606 hdsp->mixer_matrix[i] = MINUS_INFINITY_GAIN;
3609 for (i = 0; i < ((hdsp->io_type == H9652 || hdsp->io_type == H9632) ? 1352 : HDSP_MATRIX_MIXER_SIZE); ++i) {
3610 if (hdsp_write_gain (hdsp, i, MINUS_INFINITY_GAIN)) {
3615 if ((hdsp->io_type != H9652) && line_outs_monitor[hdsp->dev]) {
3619 snd_printk ("sending all inputs and playback streams to line outs.\n");
3621 /* route all inputs to the line outs for easy monitoring. send
3622 odd numbered channels to right, even to left.
3624 if (hdsp->io_type == H9632) {
3625 /* this is the phones/analog output */
3631 for (i = 0; i < hdsp->max_channels; i++) {
3633 if (hdsp_write_gain (hdsp, hdsp_input_to_output_key (hdsp, i, lineouts_base), UNITY_GAIN) ||
3634 hdsp_write_gain (hdsp, hdsp_playback_to_output_key (hdsp, i, lineouts_base), UNITY_GAIN)) {
3638 if (hdsp_write_gain (hdsp, hdsp_input_to_output_key (hdsp, i, lineouts_base+1), UNITY_GAIN) ||
3639 hdsp_write_gain (hdsp, hdsp_playback_to_output_key (hdsp, i, lineouts_base+1), UNITY_GAIN)) {
3649 /* H9632 specific defaults */
3650 if (hdsp->io_type == H9632) {
3651 hdsp->control_register |= (HDSP_DAGainPlus4dBu | HDSP_ADGainPlus4dBu | HDSP_PhoneGain0dB);
3652 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
3655 /* set a default rate so that the channel map is set up.
3658 hdsp_set_rate(hdsp, 48000, 1);
3663 static void hdsp_midi_tasklet(unsigned long arg)
3665 hdsp_t *hdsp = (hdsp_t *)arg;
3667 if (hdsp->midi[0].pending) {
3668 snd_hdsp_midi_input_read (&hdsp->midi[0]);
3670 if (hdsp->midi[1].pending) {
3671 snd_hdsp_midi_input_read (&hdsp->midi[1]);
3675 static irqreturn_t snd_hdsp_interrupt(int irq, void *dev_id, struct pt_regs *regs)
3677 hdsp_t *hdsp = (hdsp_t *) dev_id;
3678 unsigned int status;
3682 unsigned int midi0status;
3683 unsigned int midi1status;
3686 status = hdsp_read(hdsp, HDSP_statusRegister);
3688 audio = status & HDSP_audioIRQPending;
3689 midi0 = status & HDSP_midi0IRQPending;
3690 midi1 = status & HDSP_midi1IRQPending;
3692 if (!audio && !midi0 && !midi1) {
3696 hdsp_write(hdsp, HDSP_interruptConfirmation, 0);
3698 midi0status = hdsp_read (hdsp, HDSP_midiStatusIn0) & 0xff;
3699 midi1status = hdsp_read (hdsp, HDSP_midiStatusIn1) & 0xff;
3702 if (hdsp->capture_substream) {
3703 snd_pcm_period_elapsed(hdsp->pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream);
3706 if (hdsp->playback_substream) {
3707 snd_pcm_period_elapsed(hdsp->pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream);
3711 if (midi0 && midi0status) {
3712 /* we disable interrupts for this input until processing is done */
3713 hdsp->control_register &= ~HDSP_Midi0InterruptEnable;
3714 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
3715 hdsp->midi[0].pending = 1;
3718 if (midi1 && midi1status) {
3719 /* we disable interrupts for this input until processing is done */
3720 hdsp->control_register &= ~HDSP_Midi1InterruptEnable;
3721 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
3722 hdsp->midi[1].pending = 1;
3726 tasklet_hi_schedule(&hdsp->midi_tasklet);
3730 static snd_pcm_uframes_t snd_hdsp_hw_pointer(snd_pcm_substream_t *substream)
3732 hdsp_t *hdsp = snd_pcm_substream_chip(substream);
3733 return hdsp_hw_pointer(hdsp);
3736 static char *hdsp_channel_buffer_location(hdsp_t *hdsp,
3743 snd_assert(channel >= 0 && channel < hdsp->max_channels, return NULL);
3745 if ((mapped_channel = hdsp->channel_map[channel]) < 0) {
3749 if (stream == SNDRV_PCM_STREAM_CAPTURE) {
3750 return hdsp->capture_buffer + (mapped_channel * HDSP_CHANNEL_BUFFER_BYTES);
3752 return hdsp->playback_buffer + (mapped_channel * HDSP_CHANNEL_BUFFER_BYTES);
3756 static int snd_hdsp_playback_copy(snd_pcm_substream_t *substream, int channel,
3757 snd_pcm_uframes_t pos, void __user *src, snd_pcm_uframes_t count)
3759 hdsp_t *hdsp = snd_pcm_substream_chip(substream);
3762 snd_assert(pos + count <= HDSP_CHANNEL_BUFFER_BYTES / 4, return -EINVAL);
3764 channel_buf = hdsp_channel_buffer_location (hdsp, substream->pstr->stream, channel);
3765 snd_assert(channel_buf != NULL, return -EIO);
3766 if (copy_from_user(channel_buf + pos * 4, src, count * 4))
3771 static int snd_hdsp_capture_copy(snd_pcm_substream_t *substream, int channel,
3772 snd_pcm_uframes_t pos, void __user *dst, snd_pcm_uframes_t count)
3774 hdsp_t *hdsp = snd_pcm_substream_chip(substream);
3777 snd_assert(pos + count <= HDSP_CHANNEL_BUFFER_BYTES / 4, return -EINVAL);
3779 channel_buf = hdsp_channel_buffer_location (hdsp, substream->pstr->stream, channel);
3780 snd_assert(channel_buf != NULL, return -EIO);
3781 if (copy_to_user(dst, channel_buf + pos * 4, count * 4))
3786 static int snd_hdsp_hw_silence(snd_pcm_substream_t *substream, int channel,
3787 snd_pcm_uframes_t pos, snd_pcm_uframes_t count)
3789 hdsp_t *hdsp = snd_pcm_substream_chip(substream);
3792 channel_buf = hdsp_channel_buffer_location (hdsp, substream->pstr->stream, channel);
3793 snd_assert(channel_buf != NULL, return -EIO);
3794 memset(channel_buf + pos * 4, 0, count * 4);
3798 static int snd_hdsp_reset(snd_pcm_substream_t *substream)
3800 snd_pcm_runtime_t *runtime = substream->runtime;
3801 hdsp_t *hdsp = snd_pcm_substream_chip(substream);
3802 snd_pcm_substream_t *other;
3803 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
3804 other = hdsp->capture_substream;
3806 other = hdsp->playback_substream;
3808 runtime->status->hw_ptr = hdsp_hw_pointer(hdsp);
3810 runtime->status->hw_ptr = 0;
3812 struct list_head *pos;
3813 snd_pcm_substream_t *s;
3814 snd_pcm_runtime_t *oruntime = other->runtime;
3815 snd_pcm_group_for_each(pos, substream) {
3816 s = snd_pcm_group_substream_entry(pos);
3818 oruntime->status->hw_ptr = runtime->status->hw_ptr;
3826 static int snd_hdsp_hw_params(snd_pcm_substream_t *substream,
3827 snd_pcm_hw_params_t *params)
3829 hdsp_t *hdsp = snd_pcm_substream_chip(substream);
3834 if (hdsp_check_for_iobox (hdsp)) {
3838 if (hdsp_check_for_firmware(hdsp)) {
3839 if (hdsp->state & HDSP_FirmwareCached) {
3840 if (snd_hdsp_load_firmware_from_cache(hdsp) != 0) {
3841 snd_printk("Firmware loading from cache failed, please upload manually.\n");
3844 snd_printk("No firmware loaded nor cached, please upload firmware.\n");
3849 spin_lock_irq(&hdsp->lock);
3851 if (substream->pstr->stream == SNDRV_PCM_STREAM_PLAYBACK) {
3852 hdsp->control_register &= ~(HDSP_SPDIFProfessional | HDSP_SPDIFNonAudio | HDSP_SPDIFEmphasis);
3853 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register |= hdsp->creg_spdif_stream);
3854 this_pid = hdsp->playback_pid;
3855 other_pid = hdsp->capture_pid;
3857 this_pid = hdsp->capture_pid;
3858 other_pid = hdsp->playback_pid;
3861 if ((other_pid > 0) && (this_pid != other_pid)) {
3863 /* The other stream is open, and not by the same
3864 task as this one. Make sure that the parameters
3865 that matter are the same.
3868 if (params_rate(params) != hdsp->system_sample_rate) {
3869 spin_unlock_irq(&hdsp->lock);
3870 _snd_pcm_hw_param_setempty(params, SNDRV_PCM_HW_PARAM_RATE);
3874 if (params_period_size(params) != hdsp->period_bytes / 4) {
3875 spin_unlock_irq(&hdsp->lock);
3876 _snd_pcm_hw_param_setempty(params, SNDRV_PCM_HW_PARAM_PERIOD_SIZE);
3882 spin_unlock_irq(&hdsp->lock);
3886 spin_unlock_irq(&hdsp->lock);
3889 /* how to make sure that the rate matches an externally-set one ?
3892 spin_lock_irq(&hdsp->lock);
3893 if ((err = hdsp_set_rate(hdsp, params_rate(params), 0)) < 0) {
3894 spin_unlock_irq(&hdsp->lock);
3895 _snd_pcm_hw_param_setempty(params, SNDRV_PCM_HW_PARAM_RATE);
3898 spin_unlock_irq(&hdsp->lock);
3901 if ((err = hdsp_set_interrupt_interval(hdsp, params_period_size(params))) < 0) {
3902 _snd_pcm_hw_param_setempty(params, SNDRV_PCM_HW_PARAM_PERIOD_SIZE);
3909 static int snd_hdsp_channel_info(snd_pcm_substream_t *substream,
3910 snd_pcm_channel_info_t *info)
3912 hdsp_t *hdsp = snd_pcm_substream_chip(substream);
3915 snd_assert(info->channel < hdsp->max_channels, return -EINVAL);
3917 if ((mapped_channel = hdsp->channel_map[info->channel]) < 0) {
3921 info->offset = mapped_channel * HDSP_CHANNEL_BUFFER_BYTES;
3927 static int snd_hdsp_ioctl(snd_pcm_substream_t *substream,
3928 unsigned int cmd, void *arg)
3931 case SNDRV_PCM_IOCTL1_RESET:
3933 return snd_hdsp_reset(substream);
3935 case SNDRV_PCM_IOCTL1_CHANNEL_INFO:
3937 snd_pcm_channel_info_t *info = arg;
3938 return snd_hdsp_channel_info(substream, info);
3944 return snd_pcm_lib_ioctl(substream, cmd, arg);
3947 static int snd_hdsp_trigger(snd_pcm_substream_t *substream, int cmd)
3949 hdsp_t *hdsp = snd_pcm_substream_chip(substream);
3950 snd_pcm_substream_t *other;
3953 if (hdsp_check_for_iobox (hdsp)) {
3957 if (hdsp_check_for_firmware(hdsp)) {
3958 if (hdsp->state & HDSP_FirmwareCached) {
3959 if (snd_hdsp_load_firmware_from_cache(hdsp) != 0) {
3960 snd_printk("Firmware loading from cache failed, please upload manually.\n");
3963 snd_printk("No firmware loaded nor cached, please upload firmware.\n");
3968 spin_lock(&hdsp->lock);
3969 running = hdsp->running;
3971 case SNDRV_PCM_TRIGGER_START:
3972 running |= 1 << substream->stream;
3974 case SNDRV_PCM_TRIGGER_STOP:
3975 running &= ~(1 << substream->stream);
3979 spin_unlock(&hdsp->lock);
3982 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
3983 other = hdsp->capture_substream;
3985 other = hdsp->playback_substream;
3988 struct list_head *pos;
3989 snd_pcm_substream_t *s;
3990 snd_pcm_group_for_each(pos, substream) {
3991 s = snd_pcm_group_substream_entry(pos);
3993 snd_pcm_trigger_done(s, substream);
3994 if (cmd == SNDRV_PCM_TRIGGER_START)
3995 running |= 1 << s->stream;
3997 running &= ~(1 << s->stream);
4001 if (cmd == SNDRV_PCM_TRIGGER_START) {
4002 if (!(running & (1 << SNDRV_PCM_STREAM_PLAYBACK)) &&
4003 substream->stream == SNDRV_PCM_STREAM_CAPTURE)
4004 hdsp_silence_playback(hdsp);
4007 substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
4008 hdsp_silence_playback(hdsp);
4011 if (substream->stream == SNDRV_PCM_STREAM_CAPTURE)
4012 hdsp_silence_playback(hdsp);
4015 snd_pcm_trigger_done(substream, substream);
4016 if (!hdsp->running && running)
4017 hdsp_start_audio(hdsp);
4018 else if (hdsp->running && !running)
4019 hdsp_stop_audio(hdsp);
4020 hdsp->running = running;
4021 spin_unlock(&hdsp->lock);
4026 static int snd_hdsp_prepare(snd_pcm_substream_t *substream)
4028 hdsp_t *hdsp = snd_pcm_substream_chip(substream);
4031 if (hdsp_check_for_iobox (hdsp)) {
4035 if (hdsp_check_for_firmware(hdsp)) {
4036 if (hdsp->state & HDSP_FirmwareCached) {
4037 if (snd_hdsp_load_firmware_from_cache(hdsp) != 0) {
4038 snd_printk("Firmware loading from cache failed, please upload manually.\n");
4041 snd_printk("No firmware loaded nor cached, please upload firmware.\n");
4046 spin_lock_irq(&hdsp->lock);
4048 hdsp_reset_hw_pointer(hdsp);
4049 spin_unlock_irq(&hdsp->lock);
4053 static snd_pcm_hardware_t snd_hdsp_playback_subinfo =
4055 .info = (SNDRV_PCM_INFO_MMAP |
4056 SNDRV_PCM_INFO_MMAP_VALID |
4057 SNDRV_PCM_INFO_NONINTERLEAVED |
4058 SNDRV_PCM_INFO_SYNC_START |
4059 SNDRV_PCM_INFO_DOUBLE),
4060 .formats = SNDRV_PCM_FMTBIT_S32_LE,
4061 .rates = (SNDRV_PCM_RATE_32000 |
4062 SNDRV_PCM_RATE_44100 |
4063 SNDRV_PCM_RATE_48000 |
4064 SNDRV_PCM_RATE_64000 |
4065 SNDRV_PCM_RATE_88200 |
4066 SNDRV_PCM_RATE_96000),
4070 .channels_max = HDSP_MAX_CHANNELS,
4071 .buffer_bytes_max = HDSP_CHANNEL_BUFFER_BYTES * HDSP_MAX_CHANNELS,
4072 .period_bytes_min = (64 * 4) * 10,
4073 .period_bytes_max = (8192 * 4) * HDSP_MAX_CHANNELS,
4079 static snd_pcm_hardware_t snd_hdsp_capture_subinfo =
4081 .info = (SNDRV_PCM_INFO_MMAP |
4082 SNDRV_PCM_INFO_MMAP_VALID |
4083 SNDRV_PCM_INFO_NONINTERLEAVED |
4084 SNDRV_PCM_INFO_SYNC_START),
4085 .formats = SNDRV_PCM_FMTBIT_S32_LE,
4086 .rates = (SNDRV_PCM_RATE_32000 |
4087 SNDRV_PCM_RATE_44100 |
4088 SNDRV_PCM_RATE_48000 |
4089 SNDRV_PCM_RATE_64000 |
4090 SNDRV_PCM_RATE_88200 |
4091 SNDRV_PCM_RATE_96000),
4095 .channels_max = HDSP_MAX_CHANNELS,
4096 .buffer_bytes_max = HDSP_CHANNEL_BUFFER_BYTES * HDSP_MAX_CHANNELS,
4097 .period_bytes_min = (64 * 4) * 10,
4098 .period_bytes_max = (8192 * 4) * HDSP_MAX_CHANNELS,
4104 static unsigned int hdsp_period_sizes[] = { 64, 128, 256, 512, 1024, 2048, 4096, 8192 };
4106 static snd_pcm_hw_constraint_list_t hdsp_hw_constraints_period_sizes = {
4107 .count = ARRAY_SIZE(hdsp_period_sizes),
4108 .list = hdsp_period_sizes,
4112 static unsigned int hdsp_9632_sample_rates[] = { 32000, 44100, 48000, 64000, 88200, 96000, 128000, 176400, 192000 };
4114 static snd_pcm_hw_constraint_list_t hdsp_hw_constraints_9632_sample_rates = {
4115 .count = ARRAY_SIZE(hdsp_9632_sample_rates),
4116 .list = hdsp_9632_sample_rates,
4120 static int snd_hdsp_hw_rule_in_channels(snd_pcm_hw_params_t *params,
4121 snd_pcm_hw_rule_t *rule)
4123 hdsp_t *hdsp = rule->private;
4124 snd_interval_t *c = hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS);
4125 if (hdsp->io_type == H9632) {
4126 unsigned int list[3];
4127 list[0] = hdsp->qs_in_channels;
4128 list[1] = hdsp->ds_in_channels;
4129 list[2] = hdsp->ss_in_channels;
4130 return snd_interval_list(c, 3, list, 0);
4132 unsigned int list[2];
4133 list[0] = hdsp->ds_in_channels;
4134 list[1] = hdsp->ss_in_channels;
4135 return snd_interval_list(c, 2, list, 0);
4139 static int snd_hdsp_hw_rule_out_channels(snd_pcm_hw_params_t *params,
4140 snd_pcm_hw_rule_t *rule)
4142 unsigned int list[3];
4143 hdsp_t *hdsp = rule->private;
4144 snd_interval_t *c = hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS);
4145 if (hdsp->io_type == H9632) {
4146 list[0] = hdsp->qs_out_channels;
4147 list[1] = hdsp->ds_out_channels;
4148 list[2] = hdsp->ss_out_channels;
4149 return snd_interval_list(c, 3, list, 0);
4151 list[0] = hdsp->ds_out_channels;
4152 list[1] = hdsp->ss_out_channels;
4154 return snd_interval_list(c, 2, list, 0);
4157 static int snd_hdsp_hw_rule_in_channels_rate(snd_pcm_hw_params_t *params,
4158 snd_pcm_hw_rule_t *rule)
4160 hdsp_t *hdsp = rule->private;
4161 snd_interval_t *c = hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS);
4162 snd_interval_t *r = hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE);
4163 if (r->min > 96000 && hdsp->io_type == H9632) {
4164 snd_interval_t t = {
4165 .min = hdsp->qs_in_channels,
4166 .max = hdsp->qs_in_channels,
4169 return snd_interval_refine(c, &t);
4170 } else if (r->min > 48000 && r->max <= 96000) {
4171 snd_interval_t t = {
4172 .min = hdsp->ds_in_channels,
4173 .max = hdsp->ds_in_channels,
4176 return snd_interval_refine(c, &t);
4177 } else if (r->max < 64000) {
4178 snd_interval_t t = {
4179 .min = hdsp->ss_in_channels,
4180 .max = hdsp->ss_in_channels,
4183 return snd_interval_refine(c, &t);
4188 static int snd_hdsp_hw_rule_out_channels_rate(snd_pcm_hw_params_t *params,
4189 snd_pcm_hw_rule_t *rule)
4191 hdsp_t *hdsp = rule->private;
4192 snd_interval_t *c = hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS);
4193 snd_interval_t *r = hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE);
4194 if (r->min > 96000 && hdsp->io_type == H9632) {
4195 snd_interval_t t = {
4196 .min = hdsp->qs_out_channels,
4197 .max = hdsp->qs_out_channels,
4200 return snd_interval_refine(c, &t);
4201 } else if (r->min > 48000 && r->max <= 96000) {
4202 snd_interval_t t = {
4203 .min = hdsp->ds_out_channels,
4204 .max = hdsp->ds_out_channels,
4207 return snd_interval_refine(c, &t);
4208 } else if (r->max < 64000) {
4209 snd_interval_t t = {
4210 .min = hdsp->ss_out_channels,
4211 .max = hdsp->ss_out_channels,
4214 return snd_interval_refine(c, &t);
4219 static int snd_hdsp_hw_rule_rate_out_channels(snd_pcm_hw_params_t *params,
4220 snd_pcm_hw_rule_t *rule)
4222 hdsp_t *hdsp = rule->private;
4223 snd_interval_t *c = hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS);
4224 snd_interval_t *r = hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE);
4225 if (c->min >= hdsp->ss_out_channels) {
4226 snd_interval_t t = {
4231 return snd_interval_refine(r, &t);
4232 } else if (c->max <= hdsp->qs_out_channels && hdsp->io_type == H9632) {
4233 snd_interval_t t = {
4238 return snd_interval_refine(r, &t);
4239 } else if (c->max <= hdsp->ds_out_channels) {
4240 snd_interval_t t = {
4245 return snd_interval_refine(r, &t);
4250 static int snd_hdsp_hw_rule_rate_in_channels(snd_pcm_hw_params_t *params,
4251 snd_pcm_hw_rule_t *rule)
4253 hdsp_t *hdsp = rule->private;
4254 snd_interval_t *c = hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS);
4255 snd_interval_t *r = hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE);
4256 if (c->min >= hdsp->ss_in_channels) {
4257 snd_interval_t t = {
4262 return snd_interval_refine(r, &t);
4263 } else if (c->max <= hdsp->qs_in_channels && hdsp->io_type == H9632) {
4264 snd_interval_t t = {
4269 return snd_interval_refine(r, &t);
4270 } else if (c->max <= hdsp->ds_in_channels) {
4271 snd_interval_t t = {
4276 return snd_interval_refine(r, &t);
4281 static int snd_hdsp_playback_open(snd_pcm_substream_t *substream)
4283 hdsp_t *hdsp = snd_pcm_substream_chip(substream);
4284 snd_pcm_runtime_t *runtime = substream->runtime;
4286 if (hdsp_check_for_iobox (hdsp)) {
4290 if (hdsp_check_for_firmware(hdsp)) {
4291 if (hdsp->state & HDSP_FirmwareCached) {
4292 if (snd_hdsp_load_firmware_from_cache(hdsp) != 0) {
4293 snd_printk("Firmware loading from cache failed, please upload manually.\n");
4296 snd_printk("No firmware loaded nor cached, please upload firmware.\n");
4301 spin_lock_irq(&hdsp->lock);
4303 snd_pcm_set_sync(substream);
4305 runtime->hw = snd_hdsp_playback_subinfo;
4306 runtime->dma_area = hdsp->playback_buffer;
4307 runtime->dma_bytes = HDSP_DMA_AREA_BYTES;
4309 if (hdsp->capture_substream == NULL) {
4310 hdsp_stop_audio(hdsp);
4311 hdsp_set_thru(hdsp, -1, 0);
4314 hdsp->playback_pid = current->pid;
4315 hdsp->playback_substream = substream;
4317 spin_unlock_irq(&hdsp->lock);
4319 snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24);
4320 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_SIZE, &hdsp_hw_constraints_period_sizes);
4321 if (hdsp->io_type == H9632) {
4322 runtime->hw.channels_min = hdsp->qs_out_channels;
4323 runtime->hw.channels_max = hdsp->ss_out_channels;
4324 runtime->hw.rate_max = 192000;
4325 runtime->hw.rates = SNDRV_PCM_RATE_KNOT;
4326 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, &hdsp_hw_constraints_9632_sample_rates);
4329 snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
4330 snd_hdsp_hw_rule_out_channels, hdsp,
4331 SNDRV_PCM_HW_PARAM_CHANNELS, -1);
4332 snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
4333 snd_hdsp_hw_rule_out_channels_rate, hdsp,
4334 SNDRV_PCM_HW_PARAM_RATE, -1);
4335 snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
4336 snd_hdsp_hw_rule_rate_out_channels, hdsp,
4337 SNDRV_PCM_HW_PARAM_CHANNELS, -1);
4339 hdsp->creg_spdif_stream = hdsp->creg_spdif;
4340 hdsp->spdif_ctl->vd[0].access &= ~SNDRV_CTL_ELEM_ACCESS_INACTIVE;
4341 snd_ctl_notify(hdsp->card, SNDRV_CTL_EVENT_MASK_VALUE |
4342 SNDRV_CTL_EVENT_MASK_INFO, &hdsp->spdif_ctl->id);
4346 static int snd_hdsp_playback_release(snd_pcm_substream_t *substream)
4348 hdsp_t *hdsp = snd_pcm_substream_chip(substream);
4350 spin_lock_irq(&hdsp->lock);
4352 hdsp->playback_pid = -1;
4353 hdsp->playback_substream = NULL;
4355 spin_unlock_irq(&hdsp->lock);
4357 hdsp->spdif_ctl->vd[0].access |= SNDRV_CTL_ELEM_ACCESS_INACTIVE;
4358 snd_ctl_notify(hdsp->card, SNDRV_CTL_EVENT_MASK_VALUE |
4359 SNDRV_CTL_EVENT_MASK_INFO, &hdsp->spdif_ctl->id);
4364 static int snd_hdsp_capture_open(snd_pcm_substream_t *substream)
4366 hdsp_t *hdsp = snd_pcm_substream_chip(substream);
4367 snd_pcm_runtime_t *runtime = substream->runtime;
4369 if (hdsp_check_for_iobox (hdsp)) {
4373 if (hdsp_check_for_firmware(hdsp)) {
4374 if (hdsp->state & HDSP_FirmwareCached) {
4375 if (snd_hdsp_load_firmware_from_cache(hdsp) != 0) {
4376 snd_printk("Firmware loading from cache failed, please upload manually.\n");
4379 snd_printk("No firmware loaded nor cached, please upload firmware.\n");
4384 spin_lock_irq(&hdsp->lock);
4386 snd_pcm_set_sync(substream);
4388 runtime->hw = snd_hdsp_capture_subinfo;
4389 runtime->dma_area = hdsp->capture_buffer;
4390 runtime->dma_bytes = HDSP_DMA_AREA_BYTES;
4392 if (hdsp->playback_substream == NULL) {
4393 hdsp_stop_audio(hdsp);
4394 hdsp_set_thru(hdsp, -1, 0);
4397 hdsp->capture_pid = current->pid;
4398 hdsp->capture_substream = substream;
4400 spin_unlock_irq(&hdsp->lock);
4402 snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24);
4403 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_SIZE, &hdsp_hw_constraints_period_sizes);
4404 if (hdsp->io_type == H9632) {
4405 runtime->hw.channels_min = hdsp->qs_in_channels;
4406 runtime->hw.channels_max = hdsp->ss_in_channels;
4407 runtime->hw.rate_max = 192000;
4408 runtime->hw.rates = SNDRV_PCM_RATE_KNOT;
4409 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, &hdsp_hw_constraints_9632_sample_rates);
4411 snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
4412 snd_hdsp_hw_rule_in_channels, hdsp,
4413 SNDRV_PCM_HW_PARAM_CHANNELS, -1);
4414 snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
4415 snd_hdsp_hw_rule_in_channels_rate, hdsp,
4416 SNDRV_PCM_HW_PARAM_RATE, -1);
4417 snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
4418 snd_hdsp_hw_rule_rate_in_channels, hdsp,
4419 SNDRV_PCM_HW_PARAM_CHANNELS, -1);
4423 static int snd_hdsp_capture_release(snd_pcm_substream_t *substream)
4425 hdsp_t *hdsp = snd_pcm_substream_chip(substream);
4427 spin_lock_irq(&hdsp->lock);
4429 hdsp->capture_pid = -1;
4430 hdsp->capture_substream = NULL;
4432 spin_unlock_irq(&hdsp->lock);
4436 static int snd_hdsp_hwdep_dummy_op(snd_hwdep_t *hw, struct file *file)
4438 /* we have nothing to initialize but the call is required */
4443 /* helper functions for copying meter values */
4444 static inline int copy_u32_le(void __user *dest, void __iomem *src)
4446 u32 val = readl(src);
4447 return copy_to_user(dest, &val, 4);
4450 static inline int copy_u64_le(void __user *dest, void __iomem *src_low, void __iomem *src_high)
4452 u32 rms_low, rms_high;
4454 rms_low = readl(src_low);
4455 rms_high = readl(src_high);
4456 rms = ((u64)rms_high << 32) | rms_low;
4457 return copy_to_user(dest, &rms, 8);
4460 static inline int copy_u48_le(void __user *dest, void __iomem *src_low, void __iomem *src_high)
4462 u32 rms_low, rms_high;
4464 rms_low = readl(src_low) & 0xffffff00;
4465 rms_high = readl(src_high) & 0xffffff00;
4466 rms = ((u64)rms_high << 32) | rms_low;
4467 return copy_to_user(dest, &rms, 8);
4470 static int hdsp_9652_get_peak(hdsp_t *hdsp, hdsp_peak_rms_t __user *peak_rms)
4472 int doublespeed = 0;
4473 int i, j, channels, ofs;
4475 if (hdsp_read (hdsp, HDSP_statusRegister) & HDSP_DoubleSpeedStatus)
4477 channels = doublespeed ? 14 : 26;
4478 for (i = 0, j = 0; i < 26; ++i) {
4479 if (doublespeed && (i & 4))
4481 ofs = HDSP_9652_peakBase - j * 4;
4482 if (copy_u32_le(&peak_rms->input_peaks[i], hdsp->iobase + ofs))
4484 ofs -= channels * 4;
4485 if (copy_u32_le(&peak_rms->playback_peaks[i], hdsp->iobase + ofs))
4487 ofs -= channels * 4;
4488 if (copy_u32_le(&peak_rms->output_peaks[i], hdsp->iobase + ofs))
4490 ofs = HDSP_9652_rmsBase + j * 8;
4491 if (copy_u48_le(&peak_rms->input_rms[i], hdsp->iobase + ofs,
4492 hdsp->iobase + ofs + 4))
4494 ofs += channels * 8;
4495 if (copy_u48_le(&peak_rms->playback_rms[i], hdsp->iobase + ofs,
4496 hdsp->iobase + ofs + 4))
4498 ofs += channels * 8;
4499 if (copy_u48_le(&peak_rms->output_rms[i], hdsp->iobase + ofs,
4500 hdsp->iobase + ofs + 4))
4507 static int hdsp_9632_get_peak(hdsp_t *hdsp, hdsp_peak_rms_t __user *peak_rms)
4510 hdsp_9632_meters_t __iomem *m;
4511 int doublespeed = 0;
4513 if (hdsp_read (hdsp, HDSP_statusRegister) & HDSP_DoubleSpeedStatus)
4515 m = (hdsp_9632_meters_t __iomem *)(hdsp->iobase+HDSP_9632_metersBase);
4516 for (i = 0, j = 0; i < 16; ++i, ++j) {
4517 if (copy_u32_le(&peak_rms->input_peaks[i], &m->input_peak[j]))
4519 if (copy_u32_le(&peak_rms->playback_peaks[i], &m->playback_peak[j]))
4521 if (copy_u32_le(&peak_rms->output_peaks[i], &m->output_peak[j]))
4523 if (copy_u64_le(&peak_rms->input_rms[i], &m->input_rms_low[j],
4524 &m->input_rms_high[j]))
4526 if (copy_u64_le(&peak_rms->playback_rms[i], &m->playback_rms_low[j],
4527 &m->playback_rms_high[j]))
4529 if (copy_u64_le(&peak_rms->output_rms[i], &m->output_rms_low[j],
4530 &m->output_rms_high[j]))
4532 if (doublespeed && i == 3) i += 4;
4537 static int hdsp_get_peak(hdsp_t *hdsp, hdsp_peak_rms_t __user *peak_rms)
4541 for (i = 0; i < 26; i++) {
4542 if (copy_u32_le(&peak_rms->playback_peaks[i],
4543 hdsp->iobase + HDSP_playbackPeakLevel + i * 4))
4545 if (copy_u32_le(&peak_rms->input_peaks[i],
4546 hdsp->iobase + HDSP_inputPeakLevel + i * 4))
4549 for (i = 0; i < 28; i++) {
4550 if (copy_u32_le(&peak_rms->output_peaks[i],
4551 hdsp->iobase + HDSP_outputPeakLevel + i * 4))
4554 for (i = 0; i < 26; ++i) {
4555 if (copy_u64_le(&peak_rms->playback_rms[i],
4556 hdsp->iobase + HDSP_playbackRmsLevel + i * 8,
4557 hdsp->iobase + HDSP_playbackRmsLevel + i * 8 + 4))
4559 if (copy_u64_le(&peak_rms->input_rms[i],
4560 hdsp->iobase + HDSP_inputRmsLevel + i * 8,
4561 hdsp->iobase + HDSP_inputRmsLevel + i * 8 + 4))
4567 static int snd_hdsp_hwdep_ioctl(snd_hwdep_t *hw, struct file *file, unsigned int cmd, unsigned long arg)
4569 hdsp_t *hdsp = (hdsp_t *)hw->private_data;
4570 void __user *argp = (void __user *)arg;
4573 case SNDRV_HDSP_IOCTL_GET_PEAK_RMS: {
4574 hdsp_peak_rms_t __user *peak_rms = (hdsp_peak_rms_t __user *)arg;
4576 if (!(hdsp->state & HDSP_FirmwareLoaded)) {
4577 snd_printk(KERN_ERR "firmware needs to be uploaded to the card.\n");
4581 switch (hdsp->io_type) {
4583 return hdsp_9652_get_peak(hdsp, peak_rms);
4585 return hdsp_9632_get_peak(hdsp, peak_rms);
4587 return hdsp_get_peak(hdsp, peak_rms);
4590 case SNDRV_HDSP_IOCTL_GET_CONFIG_INFO: {
4591 hdsp_config_info_t info;
4592 unsigned long flags;
4595 if (!(hdsp->state & HDSP_FirmwareLoaded)) {
4596 snd_printk("Firmware needs to be uploaded to the card.\n");
4599 spin_lock_irqsave(&hdsp->lock, flags);
4600 info.pref_sync_ref = (unsigned char)hdsp_pref_sync_ref(hdsp);
4601 info.wordclock_sync_check = (unsigned char)hdsp_wc_sync_check(hdsp);
4602 if (hdsp->io_type != H9632) {
4603 info.adatsync_sync_check = (unsigned char)hdsp_adatsync_sync_check(hdsp);
4605 info.spdif_sync_check = (unsigned char)hdsp_spdif_sync_check(hdsp);
4606 for (i = 0; i < ((hdsp->io_type != Multiface && hdsp->io_type != H9632) ? 3 : 1); ++i) {
4607 info.adat_sync_check[i] = (unsigned char)hdsp_adat_sync_check(hdsp, i);
4609 info.spdif_in = (unsigned char)hdsp_spdif_in(hdsp);
4610 info.spdif_out = (unsigned char)hdsp_spdif_out(hdsp);
4611 info.spdif_professional = (unsigned char)hdsp_spdif_professional(hdsp);
4612 info.spdif_emphasis = (unsigned char)hdsp_spdif_emphasis(hdsp);
4613 info.spdif_nonaudio = (unsigned char)hdsp_spdif_nonaudio(hdsp);
4614 info.spdif_sample_rate = hdsp_spdif_sample_rate(hdsp);
4615 info.system_sample_rate = hdsp->system_sample_rate;
4616 info.autosync_sample_rate = hdsp_external_sample_rate(hdsp);
4617 info.system_clock_mode = (unsigned char)hdsp_system_clock_mode(hdsp);
4618 info.clock_source = (unsigned char)hdsp_clock_source(hdsp);
4619 info.autosync_ref = (unsigned char)hdsp_autosync_ref(hdsp);
4620 info.line_out = (unsigned char)hdsp_line_out(hdsp);
4621 info.passthru = (unsigned char)hdsp->passthru;
4622 if (hdsp->io_type == H9632) {
4623 info.da_gain = (unsigned char)hdsp_da_gain(hdsp);
4624 info.ad_gain = (unsigned char)hdsp_ad_gain(hdsp);
4625 info.phone_gain = (unsigned char)hdsp_phone_gain(hdsp);
4626 info.xlr_breakout_cable = (unsigned char)hdsp_xlr_breakout_cable(hdsp);
4629 if (hdsp->io_type == H9632 || hdsp->io_type == H9652) {
4630 info.analog_extension_board = (unsigned char)hdsp_aeb(hdsp);
4632 spin_unlock_irqrestore(&hdsp->lock, flags);
4633 if (copy_to_user(argp, &info, sizeof(info)))
4637 case SNDRV_HDSP_IOCTL_GET_9632_AEB: {
4638 hdsp_9632_aeb_t h9632_aeb;
4640 if (hdsp->io_type != H9632) return -EINVAL;
4641 h9632_aeb.aebi = hdsp->ss_in_channels - H9632_SS_CHANNELS;
4642 h9632_aeb.aebo = hdsp->ss_out_channels - H9632_SS_CHANNELS;
4643 if (copy_to_user(argp, &h9632_aeb, sizeof(h9632_aeb)))
4647 case SNDRV_HDSP_IOCTL_GET_VERSION: {
4648 hdsp_version_t hdsp_version;
4651 if (hdsp->io_type == H9652 || hdsp->io_type == H9632) return -EINVAL;
4652 if (hdsp->io_type == Undefined) {
4653 if ((err = hdsp_get_iobox_version(hdsp)) < 0) {
4657 hdsp_version.io_type = hdsp->io_type;
4658 hdsp_version.firmware_rev = hdsp->firmware_rev;
4659 if ((err = copy_to_user(argp, &hdsp_version, sizeof(hdsp_version)))) {
4664 #ifndef HDSP_FW_LOADER
4665 case SNDRV_HDSP_IOCTL_UPLOAD_FIRMWARE: {
4666 hdsp_firmware_t __user *firmware;
4667 u32 __user *firmware_data;
4670 if (hdsp->io_type == H9652 || hdsp->io_type == H9632) return -EINVAL;
4671 /* SNDRV_HDSP_IOCTL_GET_VERSION must have been called */
4672 if (hdsp->io_type == Undefined) return -EINVAL;
4674 if (hdsp->state & (HDSP_FirmwareCached | HDSP_FirmwareLoaded))
4677 snd_printk("initializing firmware upload\n");
4678 firmware = (hdsp_firmware_t __user *)argp;
4680 if (get_user(firmware_data, &firmware->firmware_data)) {
4684 if (hdsp_check_for_iobox (hdsp)) {
4688 if (copy_from_user(hdsp->firmware_cache, firmware_data, sizeof(hdsp->firmware_cache)) != 0) {
4692 hdsp->state |= HDSP_FirmwareCached;
4694 if ((err = snd_hdsp_load_firmware_from_cache(hdsp)) < 0) {
4698 if (!(hdsp->state & HDSP_InitializationComplete)) {
4699 snd_hdsp_initialize_channels(hdsp);
4701 snd_hdsp_initialize_midi_flush(hdsp);
4703 if ((err = snd_hdsp_create_alsa_devices(hdsp->card, hdsp)) < 0) {
4704 snd_printk("error creating alsa devices\n");
4711 case SNDRV_HDSP_IOCTL_GET_MIXER: {
4712 hdsp_mixer_t __user *mixer = (hdsp_mixer_t __user *)argp;
4713 if (copy_to_user(mixer->matrix, hdsp->mixer_matrix, sizeof(unsigned short)*HDSP_MATRIX_MIXER_SIZE))
4723 static snd_pcm_ops_t snd_hdsp_playback_ops = {
4724 .open = snd_hdsp_playback_open,
4725 .close = snd_hdsp_playback_release,
4726 .ioctl = snd_hdsp_ioctl,
4727 .hw_params = snd_hdsp_hw_params,
4728 .prepare = snd_hdsp_prepare,
4729 .trigger = snd_hdsp_trigger,
4730 .pointer = snd_hdsp_hw_pointer,
4731 .copy = snd_hdsp_playback_copy,
4732 .silence = snd_hdsp_hw_silence,
4735 static snd_pcm_ops_t snd_hdsp_capture_ops = {
4736 .open = snd_hdsp_capture_open,
4737 .close = snd_hdsp_capture_release,
4738 .ioctl = snd_hdsp_ioctl,
4739 .hw_params = snd_hdsp_hw_params,
4740 .prepare = snd_hdsp_prepare,
4741 .trigger = snd_hdsp_trigger,
4742 .pointer = snd_hdsp_hw_pointer,
4743 .copy = snd_hdsp_capture_copy,
4746 static int __devinit snd_hdsp_create_hwdep(snd_card_t *card,
4752 if ((err = snd_hwdep_new(card, "HDSP hwdep", 0, &hw)) < 0)
4756 hw->private_data = hdsp;
4757 strcpy(hw->name, "HDSP hwdep interface");
4759 hw->ops.open = snd_hdsp_hwdep_dummy_op;
4760 hw->ops.ioctl = snd_hdsp_hwdep_ioctl;
4761 hw->ops.release = snd_hdsp_hwdep_dummy_op;
4766 static int snd_hdsp_create_pcm(snd_card_t *card, hdsp_t *hdsp)
4771 if ((err = snd_pcm_new(card, hdsp->card_name, 0, 1, 1, &pcm)) < 0)
4775 pcm->private_data = hdsp;
4776 strcpy(pcm->name, hdsp->card_name);
4778 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_hdsp_playback_ops);
4779 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_hdsp_capture_ops);
4781 pcm->info_flags = SNDRV_PCM_INFO_JOINT_DUPLEX;
4786 static void snd_hdsp_9652_enable_mixer (hdsp_t *hdsp)
4788 hdsp->control2_register |= HDSP_9652_ENABLE_MIXER;
4789 hdsp_write (hdsp, HDSP_control2Reg, hdsp->control2_register);
4792 static int snd_hdsp_enable_io (hdsp_t *hdsp)
4796 if (hdsp_fifo_wait (hdsp, 0, 100)) {
4800 for (i = 0; i < hdsp->max_channels; ++i) {
4801 hdsp_write (hdsp, HDSP_inputEnable + (4 * i), 1);
4802 hdsp_write (hdsp, HDSP_outputEnable + (4 * i), 1);
4808 static void snd_hdsp_initialize_channels(hdsp_t *hdsp)
4810 int status, aebi_channels, aebo_channels;
4812 switch (hdsp->io_type) {
4814 hdsp->card_name = "RME Hammerfall DSP + Digiface";
4815 hdsp->ss_in_channels = hdsp->ss_out_channels = DIGIFACE_SS_CHANNELS;
4816 hdsp->ds_in_channels = hdsp->ds_out_channels = DIGIFACE_DS_CHANNELS;
4820 hdsp->card_name = "RME Hammerfall HDSP 9652";
4821 hdsp->ss_in_channels = hdsp->ss_out_channels = H9652_SS_CHANNELS;
4822 hdsp->ds_in_channels = hdsp->ds_out_channels = H9652_DS_CHANNELS;
4826 status = hdsp_read(hdsp, HDSP_statusRegister);
4827 /* HDSP_AEBx bits are low when AEB are connected */
4828 aebi_channels = (status & HDSP_AEBI) ? 0 : 4;
4829 aebo_channels = (status & HDSP_AEBO) ? 0 : 4;
4830 hdsp->card_name = "RME Hammerfall HDSP 9632";
4831 hdsp->ss_in_channels = H9632_SS_CHANNELS+aebi_channels;
4832 hdsp->ds_in_channels = H9632_DS_CHANNELS+aebi_channels;
4833 hdsp->qs_in_channels = H9632_QS_CHANNELS+aebi_channels;
4834 hdsp->ss_out_channels = H9632_SS_CHANNELS+aebo_channels;
4835 hdsp->ds_out_channels = H9632_DS_CHANNELS+aebo_channels;
4836 hdsp->qs_out_channels = H9632_QS_CHANNELS+aebo_channels;
4840 hdsp->card_name = "RME Hammerfall DSP + Multiface";
4841 hdsp->ss_in_channels = hdsp->ss_out_channels = MULTIFACE_SS_CHANNELS;
4842 hdsp->ds_in_channels = hdsp->ds_out_channels = MULTIFACE_DS_CHANNELS;
4846 /* should never get here */
4851 static void snd_hdsp_initialize_midi_flush (hdsp_t *hdsp)
4853 snd_hdsp_flush_midi_input (hdsp, 0);
4854 snd_hdsp_flush_midi_input (hdsp, 1);
4857 static int snd_hdsp_create_alsa_devices(snd_card_t *card, hdsp_t *hdsp)
4861 if ((err = snd_hdsp_create_pcm(card, hdsp)) < 0) {
4862 snd_printk("Error creating pcm interface\n");
4867 if ((err = snd_hdsp_create_midi(card, hdsp, 0)) < 0) {
4868 snd_printk("Error creating first midi interface\n");
4873 if ((err = snd_hdsp_create_midi(card, hdsp, 1)) < 0) {
4874 snd_printk("Error creating second midi interface\n");
4878 if ((err = snd_hdsp_create_controls(card, hdsp)) < 0) {
4879 snd_printk("Error creating ctl interface\n");
4883 snd_hdsp_proc_init(hdsp);
4885 hdsp->system_sample_rate = -1;
4886 hdsp->playback_pid = -1;
4887 hdsp->capture_pid = -1;
4888 hdsp->capture_substream = NULL;
4889 hdsp->playback_substream = NULL;
4891 if ((err = snd_hdsp_set_defaults(hdsp)) < 0) {
4892 snd_printk("Error setting default values\n");
4896 if (!(hdsp->state & HDSP_InitializationComplete)) {
4897 sprintf(card->longname, "%s at 0x%lx, irq %d", hdsp->card_name,
4898 hdsp->port, hdsp->irq);
4900 if ((err = snd_card_register(card)) < 0) {
4901 snd_printk("error registering card\n");
4904 hdsp->state |= HDSP_InitializationComplete;
4910 #ifdef HDSP_FW_LOADER
4911 /* load firmware via hotplug fw loader */
4912 static int __devinit hdsp_request_fw_loader(hdsp_t *hdsp)
4915 const struct firmware *fw;
4918 if (hdsp->io_type == H9652 || hdsp->io_type == H9632)
4920 if (hdsp->io_type == Undefined) {
4921 if ((err = hdsp_get_iobox_version(hdsp)) < 0)
4923 if (hdsp->io_type == H9652 || hdsp->io_type == H9632)
4926 if (hdsp_check_for_iobox (hdsp))
4929 /* caution: max length of firmware filename is 30! */
4930 switch (hdsp->io_type) {
4932 if (hdsp->firmware_rev == 0xa)
4933 fwfile = "multiface_firmware.bin";
4935 fwfile = "multiface_firmware_rev11.bin";
4938 if (hdsp->firmware_rev == 0xa)
4939 fwfile = "digiface_firmware.bin";
4941 fwfile = "digiface_firmware_rev11.bin";
4944 snd_printk(KERN_ERR "hdsp: invalid io_type %d\n", hdsp->io_type);
4948 if (request_firmware(&fw, fwfile, &hdsp->pci->dev)) {
4949 snd_printk(KERN_ERR "hdsp: cannot load firmware %s\n", fwfile);
4952 if (fw->size < sizeof(hdsp->firmware_cache)) {
4953 snd_printk(KERN_ERR "hdsp: too short firmware size %d (expected %d)\n",
4954 (int)fw->size, (int)sizeof(hdsp->firmware_cache));
4955 release_firmware(fw);
4958 #ifdef SNDRV_BIG_ENDIAN
4961 u32 *src = (void *)fw->data;
4962 for (i = 0; i < ARRAY_SIZE(hdsp->firmware_cache); i++, src++)
4963 hdsp->firmware_cache[i] = ((*src & 0x000000ff) << 16) |
4964 ((*src & 0x0000ff00) << 8) |
4965 ((*src & 0x00ff0000) >> 8) |
4966 ((*src & 0xff000000) >> 16);
4969 memcpy(hdsp->firmware_cache, fw->data, sizeof(hdsp->firmware_cache));
4971 release_firmware(fw);
4973 hdsp->state |= HDSP_FirmwareCached;
4975 if ((err = snd_hdsp_load_firmware_from_cache(hdsp)) < 0)
4978 if (!(hdsp->state & HDSP_InitializationComplete)) {
4979 snd_hdsp_initialize_channels(hdsp);
4980 snd_hdsp_initialize_midi_flush(hdsp);
4981 if ((err = snd_hdsp_create_alsa_devices(hdsp->card, hdsp)) < 0) {
4982 snd_printk("error creating alsa devices\n");
4990 static int __devinit snd_hdsp_create(snd_card_t *card,
4994 struct pci_dev *pci = hdsp->pci;
5001 hdsp->midi[0].rmidi = NULL;
5002 hdsp->midi[1].rmidi = NULL;
5003 hdsp->midi[0].input = NULL;
5004 hdsp->midi[1].input = NULL;
5005 hdsp->midi[0].output = NULL;
5006 hdsp->midi[1].output = NULL;
5007 spin_lock_init(&hdsp->midi[0].lock);
5008 spin_lock_init(&hdsp->midi[1].lock);
5009 hdsp->iobase = NULL;
5010 hdsp->control_register = 0;
5011 hdsp->control2_register = 0;
5012 hdsp->io_type = Undefined;
5013 hdsp->max_channels = 26;
5017 spin_lock_init(&hdsp->lock);
5019 tasklet_init(&hdsp->midi_tasklet, hdsp_midi_tasklet, (unsigned long)hdsp);
5021 pci_read_config_word(hdsp->pci, PCI_CLASS_REVISION, &hdsp->firmware_rev);
5023 /* From Martin Bjoernsen :
5024 "It is important that the card's latency timer register in
5025 the PCI configuration space is set to a value much larger
5026 than 0 by the computer's BIOS or the driver.
5027 The windows driver always sets this 8 bit register [...]
5028 to its maximum 255 to avoid problems with some computers."
5030 pci_write_config_byte(hdsp->pci, PCI_LATENCY_TIMER, 0xFF);
5032 strcpy(card->driver, "H-DSP");
5033 strcpy(card->mixername, "Xilinx FPGA");
5035 switch (hdsp->firmware_rev & 0xff) {
5039 hdsp->card_name = "RME Hammerfall DSP";
5045 hdsp->card_name = "RME HDSP 9652";
5050 hdsp->card_name = "RME HDSP 9632";
5051 hdsp->max_channels = 16;
5058 if ((err = pci_enable_device(pci)) < 0) {
5062 pci_set_master(hdsp->pci);
5064 if ((err = pci_request_regions(pci, "hdsp")) < 0)
5066 hdsp->port = pci_resource_start(pci, 0);
5067 if ((hdsp->iobase = ioremap_nocache(hdsp->port, HDSP_IO_EXTENT)) == NULL) {
5068 snd_printk("unable to remap region 0x%lx-0x%lx\n", hdsp->port, hdsp->port + HDSP_IO_EXTENT - 1);
5072 if (request_irq(pci->irq, snd_hdsp_interrupt, SA_INTERRUPT|SA_SHIRQ, "hdsp", (void *)hdsp)) {
5073 snd_printk("unable to use IRQ %d\n", pci->irq);
5077 hdsp->irq = pci->irq;
5078 hdsp->precise_ptr = precise_ptr;
5080 if ((err = snd_hdsp_initialize_memory(hdsp)) < 0) {
5084 if (!is_9652 && !is_9632 && hdsp_check_for_iobox (hdsp)) {
5085 /* no iobox connected, we defer initialization */
5086 snd_printk("card initialization pending : waiting for firmware\n");
5087 if ((err = snd_hdsp_create_hwdep(card, hdsp)) < 0) {
5093 if ((err = snd_hdsp_enable_io(hdsp)) != 0) {
5097 if ((hdsp_read (hdsp, HDSP_statusRegister) & HDSP_DllError) != 0) {
5098 #ifdef HDSP_FW_LOADER
5099 if ((err = hdsp_request_fw_loader(hdsp)) < 0)
5102 snd_printk("card initialization pending : waiting for firmware\n");
5103 if ((err = snd_hdsp_create_hwdep(card, hdsp)) < 0) {
5110 snd_printk("Firmware already loaded, initializing card.\n");
5112 if (hdsp_read(hdsp, HDSP_status2Register) & HDSP_version1) {
5113 hdsp->io_type = Multiface;
5115 hdsp->io_type = Digiface;
5119 hdsp->io_type = H9652;
5123 hdsp->io_type = H9632;
5126 if ((err = snd_hdsp_create_hwdep(card, hdsp)) < 0) {
5130 snd_hdsp_initialize_channels(hdsp);
5131 snd_hdsp_initialize_midi_flush(hdsp);
5133 hdsp->state |= HDSP_FirmwareLoaded;
5135 if ((err = snd_hdsp_create_alsa_devices(card, hdsp)) < 0) {
5142 static int snd_hdsp_free(hdsp_t *hdsp)
5145 /* stop the audio, and cancel all interrupts */
5146 hdsp->control_register &= ~(HDSP_Start|HDSP_AudioInterruptEnable|HDSP_Midi0InterruptEnable|HDSP_Midi1InterruptEnable);
5147 hdsp_write (hdsp, HDSP_controlRegister, hdsp->control_register);
5151 free_irq(hdsp->irq, (void *)hdsp);
5153 snd_hdsp_free_buffers(hdsp);
5156 iounmap(hdsp->iobase);
5159 pci_release_regions(hdsp->pci);
5161 pci_disable_device(hdsp->pci);
5165 static void snd_hdsp_card_free(snd_card_t *card)
5167 hdsp_t *hdsp = (hdsp_t *) card->private_data;
5170 snd_hdsp_free(hdsp);
5173 static int __devinit snd_hdsp_probe(struct pci_dev *pci,
5174 const struct pci_device_id *pci_id)
5181 if (dev >= SNDRV_CARDS)
5188 if (!(card = snd_card_new(index[dev], id[dev], THIS_MODULE, sizeof(hdsp_t))))
5191 hdsp = (hdsp_t *) card->private_data;
5192 card->private_free = snd_hdsp_card_free;
5195 snd_card_set_dev(card, &pci->dev);
5197 if ((err = snd_hdsp_create(card, hdsp, precise_ptr[dev])) < 0) {
5198 snd_card_free(card);
5202 strcpy(card->shortname, "Hammerfall DSP");
5203 sprintf(card->longname, "%s at 0x%lx, irq %d", hdsp->card_name,
5204 hdsp->port, hdsp->irq);
5206 if ((err = snd_card_register(card)) < 0) {
5207 snd_card_free(card);
5210 pci_set_drvdata(pci, card);
5215 static void __devexit snd_hdsp_remove(struct pci_dev *pci)
5217 snd_card_free(pci_get_drvdata(pci));
5218 pci_set_drvdata(pci, NULL);
5221 static struct pci_driver driver = {
5222 .name = "RME Hammerfall DSP",
5223 .id_table = snd_hdsp_ids,
5224 .probe = snd_hdsp_probe,
5225 .remove = __devexit_p(snd_hdsp_remove),
5228 static int __init alsa_card_hdsp_init(void)
5230 return pci_module_init(&driver);
5233 static void __exit alsa_card_hdsp_exit(void)
5235 pci_unregister_driver(&driver);
5238 module_init(alsa_card_hdsp_init)
5239 module_exit(alsa_card_hdsp_exit)