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 */
51 module_param_array(index, int, NULL, 0444);
52 MODULE_PARM_DESC(index, "Index value for RME Hammerfall DSP interface.");
53 module_param_array(id, charp, NULL, 0444);
54 MODULE_PARM_DESC(id, "ID string for RME Hammerfall DSP interface.");
55 module_param_array(enable, bool, NULL, 0444);
56 MODULE_PARM_DESC(enable, "Enable/disable specific Hammerfall DSP soundcards.");
57 MODULE_AUTHOR("Paul Davis <paul@linuxaudiosystems.com>, Marcus Andersson, Thomas Charbonnel <thomas@undata.org>");
58 MODULE_DESCRIPTION("RME Hammerfall DSP");
59 MODULE_LICENSE("GPL");
60 MODULE_SUPPORTED_DEVICE("{{RME Hammerfall-DSP},"
64 #define HDSP_MAX_CHANNELS 26
65 #define HDSP_MAX_DS_CHANNELS 14
66 #define HDSP_MAX_QS_CHANNELS 8
67 #define DIGIFACE_SS_CHANNELS 26
68 #define DIGIFACE_DS_CHANNELS 14
69 #define MULTIFACE_SS_CHANNELS 18
70 #define MULTIFACE_DS_CHANNELS 14
71 #define H9652_SS_CHANNELS 26
72 #define H9652_DS_CHANNELS 14
73 /* This does not include possible Analog Extension Boards
74 AEBs are detected at card initialization
76 #define H9632_SS_CHANNELS 12
77 #define H9632_DS_CHANNELS 8
78 #define H9632_QS_CHANNELS 4
80 /* Write registers. These are defined as byte-offsets from the iobase value.
82 #define HDSP_resetPointer 0
83 #define HDSP_outputBufferAddress 32
84 #define HDSP_inputBufferAddress 36
85 #define HDSP_controlRegister 64
86 #define HDSP_interruptConfirmation 96
87 #define HDSP_outputEnable 128
88 #define HDSP_control2Reg 256
89 #define HDSP_midiDataOut0 352
90 #define HDSP_midiDataOut1 356
91 #define HDSP_fifoData 368
92 #define HDSP_inputEnable 384
94 /* Read registers. These are defined as byte-offsets from the iobase value
97 #define HDSP_statusRegister 0
98 #define HDSP_timecode 128
99 #define HDSP_status2Register 192
100 #define HDSP_midiDataOut0 352
101 #define HDSP_midiDataOut1 356
102 #define HDSP_midiDataIn0 360
103 #define HDSP_midiDataIn1 364
104 #define HDSP_midiStatusOut0 384
105 #define HDSP_midiStatusOut1 388
106 #define HDSP_midiStatusIn0 392
107 #define HDSP_midiStatusIn1 396
108 #define HDSP_fifoStatus 400
110 /* the meters are regular i/o-mapped registers, but offset
111 considerably from the rest. the peak registers are reset
112 when read; the least-significant 4 bits are full-scale counters;
113 the actual peak value is in the most-significant 24 bits.
116 #define HDSP_playbackPeakLevel 4096 /* 26 * 32 bit values */
117 #define HDSP_inputPeakLevel 4224 /* 26 * 32 bit values */
118 #define HDSP_outputPeakLevel 4352 /* (26+2) * 32 bit values */
119 #define HDSP_playbackRmsLevel 4612 /* 26 * 64 bit values */
120 #define HDSP_inputRmsLevel 4868 /* 26 * 64 bit values */
123 /* This is for H9652 cards
124 Peak values are read downward from the base
125 Rms values are read upward
126 There are rms values for the outputs too
127 26*3 values are read in ss mode
128 14*3 in ds mode, with no gap between values
130 #define HDSP_9652_peakBase 7164
131 #define HDSP_9652_rmsBase 4096
133 /* c.f. the hdsp_9632_meters_t struct */
134 #define HDSP_9632_metersBase 4096
136 #define HDSP_IO_EXTENT 7168
138 /* control2 register bits */
140 #define HDSP_TMS 0x01
141 #define HDSP_TCK 0x02
142 #define HDSP_TDI 0x04
143 #define HDSP_JTAG 0x08
144 #define HDSP_PWDN 0x10
145 #define HDSP_PROGRAM 0x020
146 #define HDSP_CONFIG_MODE_0 0x040
147 #define HDSP_CONFIG_MODE_1 0x080
148 #define HDSP_VERSION_BIT 0x100
149 #define HDSP_BIGENDIAN_MODE 0x200
150 #define HDSP_RD_MULTIPLE 0x400
151 #define HDSP_9652_ENABLE_MIXER 0x800
152 #define HDSP_TDO 0x10000000
154 #define HDSP_S_PROGRAM (HDSP_PROGRAM|HDSP_CONFIG_MODE_0)
155 #define HDSP_S_LOAD (HDSP_PROGRAM|HDSP_CONFIG_MODE_1)
157 /* Control Register bits */
159 #define HDSP_Start (1<<0) /* start engine */
160 #define HDSP_Latency0 (1<<1) /* buffer size = 2^n where n is defined by Latency{2,1,0} */
161 #define HDSP_Latency1 (1<<2) /* [ see above ] */
162 #define HDSP_Latency2 (1<<3) /* [ see above ] */
163 #define HDSP_ClockModeMaster (1<<4) /* 1=Master, 0=Slave/Autosync */
164 #define HDSP_AudioInterruptEnable (1<<5) /* what do you think ? */
165 #define HDSP_Frequency0 (1<<6) /* 0=44.1kHz/88.2kHz/176.4kHz 1=48kHz/96kHz/192kHz */
166 #define HDSP_Frequency1 (1<<7) /* 0=32kHz/64kHz/128kHz */
167 #define HDSP_DoubleSpeed (1<<8) /* 0=normal speed, 1=double speed */
168 #define HDSP_SPDIFProfessional (1<<9) /* 0=consumer, 1=professional */
169 #define HDSP_SPDIFEmphasis (1<<10) /* 0=none, 1=on */
170 #define HDSP_SPDIFNonAudio (1<<11) /* 0=off, 1=on */
171 #define HDSP_SPDIFOpticalOut (1<<12) /* 1=use 1st ADAT connector for SPDIF, 0=do not */
172 #define HDSP_SyncRef2 (1<<13)
173 #define HDSP_SPDIFInputSelect0 (1<<14)
174 #define HDSP_SPDIFInputSelect1 (1<<15)
175 #define HDSP_SyncRef0 (1<<16)
176 #define HDSP_SyncRef1 (1<<17)
177 #define HDSP_AnalogExtensionBoard (1<<18) /* For H9632 cards */
178 #define HDSP_XLRBreakoutCable (1<<20) /* For H9632 cards */
179 #define HDSP_Midi0InterruptEnable (1<<22)
180 #define HDSP_Midi1InterruptEnable (1<<23)
181 #define HDSP_LineOut (1<<24)
182 #define HDSP_ADGain0 (1<<25) /* From here : H9632 specific */
183 #define HDSP_ADGain1 (1<<26)
184 #define HDSP_DAGain0 (1<<27)
185 #define HDSP_DAGain1 (1<<28)
186 #define HDSP_PhoneGain0 (1<<29)
187 #define HDSP_PhoneGain1 (1<<30)
188 #define HDSP_QuadSpeed (1<<31)
190 #define HDSP_ADGainMask (HDSP_ADGain0|HDSP_ADGain1)
191 #define HDSP_ADGainMinus10dBV HDSP_ADGainMask
192 #define HDSP_ADGainPlus4dBu (HDSP_ADGain0)
193 #define HDSP_ADGainLowGain 0
195 #define HDSP_DAGainMask (HDSP_DAGain0|HDSP_DAGain1)
196 #define HDSP_DAGainHighGain HDSP_DAGainMask
197 #define HDSP_DAGainPlus4dBu (HDSP_DAGain0)
198 #define HDSP_DAGainMinus10dBV 0
200 #define HDSP_PhoneGainMask (HDSP_PhoneGain0|HDSP_PhoneGain1)
201 #define HDSP_PhoneGain0dB HDSP_PhoneGainMask
202 #define HDSP_PhoneGainMinus6dB (HDSP_PhoneGain0)
203 #define HDSP_PhoneGainMinus12dB 0
205 #define HDSP_LatencyMask (HDSP_Latency0|HDSP_Latency1|HDSP_Latency2)
206 #define HDSP_FrequencyMask (HDSP_Frequency0|HDSP_Frequency1|HDSP_DoubleSpeed|HDSP_QuadSpeed)
208 #define HDSP_SPDIFInputMask (HDSP_SPDIFInputSelect0|HDSP_SPDIFInputSelect1)
209 #define HDSP_SPDIFInputADAT1 0
210 #define HDSP_SPDIFInputCoaxial (HDSP_SPDIFInputSelect0)
211 #define HDSP_SPDIFInputCdrom (HDSP_SPDIFInputSelect1)
212 #define HDSP_SPDIFInputAES (HDSP_SPDIFInputSelect0|HDSP_SPDIFInputSelect1)
214 #define HDSP_SyncRefMask (HDSP_SyncRef0|HDSP_SyncRef1|HDSP_SyncRef2)
215 #define HDSP_SyncRef_ADAT1 0
216 #define HDSP_SyncRef_ADAT2 (HDSP_SyncRef0)
217 #define HDSP_SyncRef_ADAT3 (HDSP_SyncRef1)
218 #define HDSP_SyncRef_SPDIF (HDSP_SyncRef0|HDSP_SyncRef1)
219 #define HDSP_SyncRef_WORD (HDSP_SyncRef2)
220 #define HDSP_SyncRef_ADAT_SYNC (HDSP_SyncRef0|HDSP_SyncRef2)
222 /* Sample Clock Sources */
224 #define HDSP_CLOCK_SOURCE_AUTOSYNC 0
225 #define HDSP_CLOCK_SOURCE_INTERNAL_32KHZ 1
226 #define HDSP_CLOCK_SOURCE_INTERNAL_44_1KHZ 2
227 #define HDSP_CLOCK_SOURCE_INTERNAL_48KHZ 3
228 #define HDSP_CLOCK_SOURCE_INTERNAL_64KHZ 4
229 #define HDSP_CLOCK_SOURCE_INTERNAL_88_2KHZ 5
230 #define HDSP_CLOCK_SOURCE_INTERNAL_96KHZ 6
231 #define HDSP_CLOCK_SOURCE_INTERNAL_128KHZ 7
232 #define HDSP_CLOCK_SOURCE_INTERNAL_176_4KHZ 8
233 #define HDSP_CLOCK_SOURCE_INTERNAL_192KHZ 9
235 /* Preferred sync reference choices - used by "pref_sync_ref" control switch */
237 #define HDSP_SYNC_FROM_WORD 0
238 #define HDSP_SYNC_FROM_SPDIF 1
239 #define HDSP_SYNC_FROM_ADAT1 2
240 #define HDSP_SYNC_FROM_ADAT_SYNC 3
241 #define HDSP_SYNC_FROM_ADAT2 4
242 #define HDSP_SYNC_FROM_ADAT3 5
244 /* SyncCheck status */
246 #define HDSP_SYNC_CHECK_NO_LOCK 0
247 #define HDSP_SYNC_CHECK_LOCK 1
248 #define HDSP_SYNC_CHECK_SYNC 2
250 /* AutoSync references - used by "autosync_ref" control switch */
252 #define HDSP_AUTOSYNC_FROM_WORD 0
253 #define HDSP_AUTOSYNC_FROM_ADAT_SYNC 1
254 #define HDSP_AUTOSYNC_FROM_SPDIF 2
255 #define HDSP_AUTOSYNC_FROM_NONE 3
256 #define HDSP_AUTOSYNC_FROM_ADAT1 4
257 #define HDSP_AUTOSYNC_FROM_ADAT2 5
258 #define HDSP_AUTOSYNC_FROM_ADAT3 6
260 /* Possible sources of S/PDIF input */
262 #define HDSP_SPDIFIN_OPTICAL 0 /* optical (ADAT1) */
263 #define HDSP_SPDIFIN_COAXIAL 1 /* coaxial (RCA) */
264 #define HDSP_SPDIFIN_INTERNAL 2 /* internal (CDROM) */
265 #define HDSP_SPDIFIN_AES 3 /* xlr for H9632 (AES)*/
267 #define HDSP_Frequency32KHz HDSP_Frequency0
268 #define HDSP_Frequency44_1KHz HDSP_Frequency1
269 #define HDSP_Frequency48KHz (HDSP_Frequency1|HDSP_Frequency0)
270 #define HDSP_Frequency64KHz (HDSP_DoubleSpeed|HDSP_Frequency0)
271 #define HDSP_Frequency88_2KHz (HDSP_DoubleSpeed|HDSP_Frequency1)
272 #define HDSP_Frequency96KHz (HDSP_DoubleSpeed|HDSP_Frequency1|HDSP_Frequency0)
273 /* For H9632 cards */
274 #define HDSP_Frequency128KHz (HDSP_QuadSpeed|HDSP_DoubleSpeed|HDSP_Frequency0)
275 #define HDSP_Frequency176_4KHz (HDSP_QuadSpeed|HDSP_DoubleSpeed|HDSP_Frequency1)
276 #define HDSP_Frequency192KHz (HDSP_QuadSpeed|HDSP_DoubleSpeed|HDSP_Frequency1|HDSP_Frequency0)
278 #define hdsp_encode_latency(x) (((x)<<1) & HDSP_LatencyMask)
279 #define hdsp_decode_latency(x) (((x) & HDSP_LatencyMask)>>1)
281 #define hdsp_encode_spdif_in(x) (((x)&0x3)<<14)
282 #define hdsp_decode_spdif_in(x) (((x)>>14)&0x3)
284 /* Status Register bits */
286 #define HDSP_audioIRQPending (1<<0)
287 #define HDSP_Lock2 (1<<1) /* this is for Digiface and H9652 */
288 #define HDSP_spdifFrequency3 HDSP_Lock2 /* this is for H9632 only */
289 #define HDSP_Lock1 (1<<2)
290 #define HDSP_Lock0 (1<<3)
291 #define HDSP_SPDIFSync (1<<4)
292 #define HDSP_TimecodeLock (1<<5)
293 #define HDSP_BufferPositionMask 0x000FFC0 /* Bit 6..15 : h/w buffer pointer */
294 #define HDSP_Sync2 (1<<16)
295 #define HDSP_Sync1 (1<<17)
296 #define HDSP_Sync0 (1<<18)
297 #define HDSP_DoubleSpeedStatus (1<<19)
298 #define HDSP_ConfigError (1<<20)
299 #define HDSP_DllError (1<<21)
300 #define HDSP_spdifFrequency0 (1<<22)
301 #define HDSP_spdifFrequency1 (1<<23)
302 #define HDSP_spdifFrequency2 (1<<24)
303 #define HDSP_SPDIFErrorFlag (1<<25)
304 #define HDSP_BufferID (1<<26)
305 #define HDSP_TimecodeSync (1<<27)
306 #define HDSP_AEBO (1<<28) /* H9632 specific Analog Extension Boards */
307 #define HDSP_AEBI (1<<29) /* 0 = present, 1 = absent */
308 #define HDSP_midi0IRQPending (1<<30)
309 #define HDSP_midi1IRQPending (1<<31)
311 #define HDSP_spdifFrequencyMask (HDSP_spdifFrequency0|HDSP_spdifFrequency1|HDSP_spdifFrequency2)
313 #define HDSP_spdifFrequency32KHz (HDSP_spdifFrequency0)
314 #define HDSP_spdifFrequency44_1KHz (HDSP_spdifFrequency1)
315 #define HDSP_spdifFrequency48KHz (HDSP_spdifFrequency0|HDSP_spdifFrequency1)
317 #define HDSP_spdifFrequency64KHz (HDSP_spdifFrequency2)
318 #define HDSP_spdifFrequency88_2KHz (HDSP_spdifFrequency0|HDSP_spdifFrequency2)
319 #define HDSP_spdifFrequency96KHz (HDSP_spdifFrequency2|HDSP_spdifFrequency1)
321 /* This is for H9632 cards */
322 #define HDSP_spdifFrequency128KHz HDSP_spdifFrequencyMask
323 #define HDSP_spdifFrequency176_4KHz HDSP_spdifFrequency3
324 #define HDSP_spdifFrequency192KHz (HDSP_spdifFrequency3|HDSP_spdifFrequency0)
326 /* Status2 Register bits */
328 #define HDSP_version0 (1<<0)
329 #define HDSP_version1 (1<<1)
330 #define HDSP_version2 (1<<2)
331 #define HDSP_wc_lock (1<<3)
332 #define HDSP_wc_sync (1<<4)
333 #define HDSP_inp_freq0 (1<<5)
334 #define HDSP_inp_freq1 (1<<6)
335 #define HDSP_inp_freq2 (1<<7)
336 #define HDSP_SelSyncRef0 (1<<8)
337 #define HDSP_SelSyncRef1 (1<<9)
338 #define HDSP_SelSyncRef2 (1<<10)
340 #define HDSP_wc_valid (HDSP_wc_lock|HDSP_wc_sync)
342 #define HDSP_systemFrequencyMask (HDSP_inp_freq0|HDSP_inp_freq1|HDSP_inp_freq2)
343 #define HDSP_systemFrequency32 (HDSP_inp_freq0)
344 #define HDSP_systemFrequency44_1 (HDSP_inp_freq1)
345 #define HDSP_systemFrequency48 (HDSP_inp_freq0|HDSP_inp_freq1)
346 #define HDSP_systemFrequency64 (HDSP_inp_freq2)
347 #define HDSP_systemFrequency88_2 (HDSP_inp_freq0|HDSP_inp_freq2)
348 #define HDSP_systemFrequency96 (HDSP_inp_freq1|HDSP_inp_freq2)
349 /* FIXME : more values for 9632 cards ? */
351 #define HDSP_SelSyncRefMask (HDSP_SelSyncRef0|HDSP_SelSyncRef1|HDSP_SelSyncRef2)
352 #define HDSP_SelSyncRef_ADAT1 0
353 #define HDSP_SelSyncRef_ADAT2 (HDSP_SelSyncRef0)
354 #define HDSP_SelSyncRef_ADAT3 (HDSP_SelSyncRef1)
355 #define HDSP_SelSyncRef_SPDIF (HDSP_SelSyncRef0|HDSP_SelSyncRef1)
356 #define HDSP_SelSyncRef_WORD (HDSP_SelSyncRef2)
357 #define HDSP_SelSyncRef_ADAT_SYNC (HDSP_SelSyncRef0|HDSP_SelSyncRef2)
359 /* Card state flags */
361 #define HDSP_InitializationComplete (1<<0)
362 #define HDSP_FirmwareLoaded (1<<1)
363 #define HDSP_FirmwareCached (1<<2)
365 /* FIFO wait times, defined in terms of 1/10ths of msecs */
367 #define HDSP_LONG_WAIT 5000
368 #define HDSP_SHORT_WAIT 30
370 #define UNITY_GAIN 32768
371 #define MINUS_INFINITY_GAIN 0
373 #ifndef PCI_VENDOR_ID_XILINX
374 #define PCI_VENDOR_ID_XILINX 0x10ee
376 #ifndef PCI_DEVICE_ID_XILINX_HAMMERFALL_DSP
377 #define PCI_DEVICE_ID_XILINX_HAMMERFALL_DSP 0x3fc5
380 /* the size of a substream (1 mono data stream) */
382 #define HDSP_CHANNEL_BUFFER_SAMPLES (16*1024)
383 #define HDSP_CHANNEL_BUFFER_BYTES (4*HDSP_CHANNEL_BUFFER_SAMPLES)
385 /* the size of the area we need to allocate for DMA transfers. the
386 size is the same regardless of the number of channels - the
387 Multiface still uses the same memory area.
389 Note that we allocate 1 more channel than is apparently needed
390 because the h/w seems to write 1 byte beyond the end of the last
394 #define HDSP_DMA_AREA_BYTES ((HDSP_MAX_CHANNELS+1) * HDSP_CHANNEL_BUFFER_BYTES)
395 #define HDSP_DMA_AREA_KILOBYTES (HDSP_DMA_AREA_BYTES/1024)
397 /* use hotplug firmeare loader? */
398 #if defined(CONFIG_FW_LOADER) || defined(CONFIG_FW_LOADER_MODULE)
399 #ifndef HDSP_USE_HWDEP_LOADER
400 #define HDSP_FW_LOADER
404 typedef struct _hdsp hdsp_t;
405 typedef struct _hdsp_midi hdsp_midi_t;
406 typedef struct _hdsp_9632_meters hdsp_9632_meters_t;
408 struct _hdsp_9632_meters {
410 u32 playback_peak[16];
414 u32 input_rms_low[16];
415 u32 playback_rms_low[16];
416 u32 output_rms_low[16];
418 u32 input_rms_high[16];
419 u32 playback_rms_high[16];
420 u32 output_rms_high[16];
421 u32 xxx_rms_high[16];
427 snd_rawmidi_t *rmidi;
428 snd_rawmidi_substream_t *input;
429 snd_rawmidi_substream_t *output;
430 char istimer; /* timer in use */
431 struct timer_list timer;
438 snd_pcm_substream_t *capture_substream;
439 snd_pcm_substream_t *playback_substream;
441 struct tasklet_struct midi_tasklet;
442 int use_midi_tasklet;
444 u32 control_register; /* cached value */
445 u32 control2_register; /* cached value */
447 u32 creg_spdif_stream;
448 int clock_source_locked;
449 char *card_name; /* digiface/multiface */
450 HDSP_IO_Type io_type; /* ditto, but for code use */
451 unsigned short firmware_rev;
452 unsigned short state; /* stores state bits */
453 u32 firmware_cache[24413]; /* this helps recover from accidental iobox power failure */
454 size_t period_bytes; /* guess what this is */
455 unsigned char max_channels;
456 unsigned char qs_in_channels; /* quad speed mode for H9632 */
457 unsigned char ds_in_channels;
458 unsigned char ss_in_channels; /* different for multiface/digiface */
459 unsigned char qs_out_channels;
460 unsigned char ds_out_channels;
461 unsigned char ss_out_channels;
463 struct snd_dma_buffer capture_dma_buf;
464 struct snd_dma_buffer playback_dma_buf;
465 unsigned char *capture_buffer; /* suitably aligned address */
466 unsigned char *playback_buffer; /* suitably aligned address */
471 int system_sample_rate;
476 void __iomem *iobase;
481 snd_kcontrol_t *spdif_ctl;
482 unsigned short mixer_matrix[HDSP_MATRIX_MIXER_SIZE];
485 /* These tables map the ALSA channels 1..N to the channels that we
486 need to use in order to find the relevant channel buffer. RME
487 refer to this kind of mapping as between "the ADAT channel and
488 the DMA channel." We index it using the logical audio channel,
489 and the value is the DMA channel (i.e. channel buffer number)
490 where the data for that channel can be read/written from/to.
493 static char channel_map_df_ss[HDSP_MAX_CHANNELS] = {
494 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
495 18, 19, 20, 21, 22, 23, 24, 25
498 static char channel_map_mf_ss[HDSP_MAX_CHANNELS] = { /* Multiface */
500 0, 1, 2, 3, 4, 5, 6, 7,
502 16, 17, 18, 19, 20, 21, 22, 23,
505 -1, -1, -1, -1, -1, -1, -1, -1
508 static char channel_map_ds[HDSP_MAX_CHANNELS] = {
509 /* ADAT channels are remapped */
510 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23,
511 /* channels 12 and 13 are S/PDIF */
513 /* others don't exist */
514 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
517 static char channel_map_H9632_ss[HDSP_MAX_CHANNELS] = {
519 0, 1, 2, 3, 4, 5, 6, 7,
524 /* AO4S-192 and AI4S-192 extension boards */
526 /* others don't exist */
527 -1, -1, -1, -1, -1, -1, -1, -1,
531 static char channel_map_H9632_ds[HDSP_MAX_CHANNELS] = {
538 /* AO4S-192 and AI4S-192 extension boards */
540 /* others don't exist */
541 -1, -1, -1, -1, -1, -1, -1, -1,
542 -1, -1, -1, -1, -1, -1
545 static char channel_map_H9632_qs[HDSP_MAX_CHANNELS] = {
546 /* ADAT is disabled in this mode */
551 /* AO4S-192 and AI4S-192 extension boards */
553 /* others don't exist */
554 -1, -1, -1, -1, -1, -1, -1, -1,
555 -1, -1, -1, -1, -1, -1, -1, -1,
559 static int snd_hammerfall_get_buffer(struct pci_dev *pci, struct snd_dma_buffer *dmab, size_t size)
561 dmab->dev.type = SNDRV_DMA_TYPE_DEV;
562 dmab->dev.dev = snd_dma_pci_data(pci);
563 if (snd_dma_get_reserved_buf(dmab, snd_dma_pci_buf_id(pci))) {
564 if (dmab->bytes >= size)
567 if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(pci),
573 static void snd_hammerfall_free_buffer(struct snd_dma_buffer *dmab, struct pci_dev *pci)
576 dmab->dev.dev = NULL; /* make it anonymous */
577 snd_dma_reserve_buf(dmab, snd_dma_pci_buf_id(pci));
582 static struct pci_device_id snd_hdsp_ids[] = {
584 .vendor = PCI_VENDOR_ID_XILINX,
585 .device = PCI_DEVICE_ID_XILINX_HAMMERFALL_DSP,
586 .subvendor = PCI_ANY_ID,
587 .subdevice = PCI_ANY_ID,
588 }, /* RME Hammerfall-DSP */
592 MODULE_DEVICE_TABLE(pci, snd_hdsp_ids);
595 static int snd_hdsp_create_alsa_devices(snd_card_t *card, hdsp_t *hdsp);
596 static int snd_hdsp_create_pcm(snd_card_t *card, hdsp_t *hdsp);
597 static int snd_hdsp_enable_io (hdsp_t *hdsp);
598 static void snd_hdsp_initialize_midi_flush (hdsp_t *hdsp);
599 static void snd_hdsp_initialize_channels (hdsp_t *hdsp);
600 static int hdsp_fifo_wait(hdsp_t *hdsp, int count, int timeout);
601 static int hdsp_autosync_ref(hdsp_t *hdsp);
602 static int snd_hdsp_set_defaults(hdsp_t *hdsp);
603 static void snd_hdsp_9652_enable_mixer (hdsp_t *hdsp);
605 static int hdsp_playback_to_output_key (hdsp_t *hdsp, int in, int out)
607 switch (hdsp->firmware_rev) {
609 return (64 * out) + (32 + (in));
612 return (32 * out) + (16 + (in));
614 return (52 * out) + (26 + (in));
618 static int hdsp_input_to_output_key (hdsp_t *hdsp, int in, int out)
620 switch (hdsp->firmware_rev) {
622 return (64 * out) + in;
625 return (32 * out) + in;
627 return (52 * out) + in;
631 static void hdsp_write(hdsp_t *hdsp, int reg, int val)
633 writel(val, hdsp->iobase + reg);
636 static unsigned int hdsp_read(hdsp_t *hdsp, int reg)
638 return readl (hdsp->iobase + reg);
641 static int hdsp_check_for_iobox (hdsp_t *hdsp)
644 if (hdsp->io_type == H9652 || hdsp->io_type == H9632) return 0;
645 if (hdsp_read (hdsp, HDSP_statusRegister) & HDSP_ConfigError) {
646 snd_printk ("Hammerfall-DSP: no Digiface or Multiface connected!\n");
647 hdsp->state &= ~HDSP_FirmwareLoaded;
654 static int snd_hdsp_load_firmware_from_cache(hdsp_t *hdsp) {
659 if ((hdsp_read (hdsp, HDSP_statusRegister) & HDSP_DllError) != 0) {
661 snd_printk ("Hammerfall-DSP: loading firmware\n");
663 hdsp_write (hdsp, HDSP_control2Reg, HDSP_S_PROGRAM);
664 hdsp_write (hdsp, HDSP_fifoData, 0);
666 if (hdsp_fifo_wait (hdsp, 0, HDSP_LONG_WAIT)) {
667 snd_printk ("Hammerfall-DSP: timeout waiting for download preparation\n");
671 hdsp_write (hdsp, HDSP_control2Reg, HDSP_S_LOAD);
673 for (i = 0; i < 24413; ++i) {
674 hdsp_write(hdsp, HDSP_fifoData, hdsp->firmware_cache[i]);
675 if (hdsp_fifo_wait (hdsp, 127, HDSP_LONG_WAIT)) {
676 snd_printk ("Hammerfall-DSP: timeout during firmware loading\n");
681 if ((1000 / HZ) < 3000) {
682 set_current_state(TASK_UNINTERRUPTIBLE);
683 schedule_timeout((3000 * HZ + 999) / 1000);
688 if (hdsp_fifo_wait (hdsp, 0, HDSP_LONG_WAIT)) {
689 snd_printk ("Hammerfall-DSP: timeout at end of firmware loading\n");
693 #ifdef SNDRV_BIG_ENDIAN
694 hdsp->control2_register = HDSP_BIGENDIAN_MODE;
696 hdsp->control2_register = 0;
698 hdsp_write (hdsp, HDSP_control2Reg, hdsp->control2_register);
699 snd_printk ("Hammerfall-DSP: finished firmware loading\n");
702 if (hdsp->state & HDSP_InitializationComplete) {
703 snd_printk("Hammerfall-DSP: firmware loaded from cache, restoring defaults\n");
704 spin_lock_irqsave(&hdsp->lock, flags);
705 snd_hdsp_set_defaults(hdsp);
706 spin_unlock_irqrestore(&hdsp->lock, flags);
709 hdsp->state |= HDSP_FirmwareLoaded;
714 static int hdsp_get_iobox_version (hdsp_t *hdsp)
716 if ((hdsp_read (hdsp, HDSP_statusRegister) & HDSP_DllError) != 0) {
718 hdsp_write (hdsp, HDSP_control2Reg, HDSP_PROGRAM);
719 hdsp_write (hdsp, HDSP_fifoData, 0);
720 if (hdsp_fifo_wait (hdsp, 0, HDSP_SHORT_WAIT) < 0) {
724 hdsp_write (hdsp, HDSP_control2Reg, HDSP_S_LOAD);
725 hdsp_write (hdsp, HDSP_fifoData, 0);
727 if (hdsp_fifo_wait (hdsp, 0, HDSP_SHORT_WAIT)) {
728 hdsp->io_type = Multiface;
729 hdsp_write (hdsp, HDSP_control2Reg, HDSP_VERSION_BIT);
730 hdsp_write (hdsp, HDSP_control2Reg, HDSP_S_LOAD);
731 hdsp_fifo_wait (hdsp, 0, HDSP_SHORT_WAIT);
733 hdsp->io_type = Digiface;
736 /* firmware was already loaded, get iobox type */
737 if (hdsp_read(hdsp, HDSP_status2Register) & HDSP_version1) {
738 hdsp->io_type = Multiface;
740 hdsp->io_type = Digiface;
747 static int hdsp_check_for_firmware (hdsp_t *hdsp)
749 if (hdsp->io_type == H9652 || hdsp->io_type == H9632) return 0;
750 if ((hdsp_read (hdsp, HDSP_statusRegister) & HDSP_DllError) != 0) {
751 snd_printk("Hammerfall-DSP: firmware not present.\n");
752 hdsp->state &= ~HDSP_FirmwareLoaded;
759 static int hdsp_fifo_wait(hdsp_t *hdsp, int count, int timeout)
763 /* the fifoStatus registers reports on how many words
764 are available in the command FIFO.
767 for (i = 0; i < timeout; i++) {
769 if ((int)(hdsp_read (hdsp, HDSP_fifoStatus) & 0xff) <= count)
772 /* not very friendly, but we only do this during a firmware
773 load and changing the mixer, so we just put up with it.
779 snd_printk ("Hammerfall-DSP: wait for FIFO status <= %d failed after %d iterations\n",
784 static int hdsp_read_gain (hdsp_t *hdsp, unsigned int addr)
786 if (addr >= HDSP_MATRIX_MIXER_SIZE) {
789 return hdsp->mixer_matrix[addr];
792 static int hdsp_write_gain(hdsp_t *hdsp, unsigned int addr, unsigned short data)
796 if (addr >= HDSP_MATRIX_MIXER_SIZE)
799 if (hdsp->io_type == H9652 || hdsp->io_type == H9632) {
801 /* from martin bjornsen:
803 "You can only write dwords to the
804 mixer memory which contain two
805 mixer values in the low and high
806 word. So if you want to change
807 value 0 you have to read value 1
808 from the cache and write both to
809 the first dword in the mixer
813 if (hdsp->io_type == H9632 && addr >= 512) {
817 if (hdsp->io_type == H9652 && addr >= 1352) {
821 hdsp->mixer_matrix[addr] = data;
824 /* `addr' addresses a 16-bit wide address, but
825 the address space accessed via hdsp_write
826 uses byte offsets. put another way, addr
827 varies from 0 to 1351, but to access the
828 corresponding memory location, we need
829 to access 0 to 2703 ...
833 hdsp_write (hdsp, 4096 + (ad*4),
834 (hdsp->mixer_matrix[(addr&0x7fe)+1] << 16) +
835 hdsp->mixer_matrix[addr&0x7fe]);
841 ad = (addr << 16) + data;
843 if (hdsp_fifo_wait(hdsp, 127, HDSP_LONG_WAIT)) {
847 hdsp_write (hdsp, HDSP_fifoData, ad);
848 hdsp->mixer_matrix[addr] = data;
855 static int snd_hdsp_use_is_exclusive(hdsp_t *hdsp)
860 spin_lock_irqsave(&hdsp->lock, flags);
861 if ((hdsp->playback_pid != hdsp->capture_pid) &&
862 (hdsp->playback_pid >= 0) && (hdsp->capture_pid >= 0)) {
865 spin_unlock_irqrestore(&hdsp->lock, flags);
869 static int hdsp_external_sample_rate (hdsp_t *hdsp)
871 unsigned int status2 = hdsp_read(hdsp, HDSP_status2Register);
872 unsigned int rate_bits = status2 & HDSP_systemFrequencyMask;
875 case HDSP_systemFrequency32: return 32000;
876 case HDSP_systemFrequency44_1: return 44100;
877 case HDSP_systemFrequency48: return 48000;
878 case HDSP_systemFrequency64: return 64000;
879 case HDSP_systemFrequency88_2: return 88200;
880 case HDSP_systemFrequency96: return 96000;
886 static int hdsp_spdif_sample_rate(hdsp_t *hdsp)
888 unsigned int status = hdsp_read(hdsp, HDSP_statusRegister);
889 unsigned int rate_bits = (status & HDSP_spdifFrequencyMask);
891 if (status & HDSP_SPDIFErrorFlag) {
896 case HDSP_spdifFrequency32KHz: return 32000;
897 case HDSP_spdifFrequency44_1KHz: return 44100;
898 case HDSP_spdifFrequency48KHz: return 48000;
899 case HDSP_spdifFrequency64KHz: return 64000;
900 case HDSP_spdifFrequency88_2KHz: return 88200;
901 case HDSP_spdifFrequency96KHz: return 96000;
902 case HDSP_spdifFrequency128KHz:
903 if (hdsp->io_type == H9632) return 128000;
905 case HDSP_spdifFrequency176_4KHz:
906 if (hdsp->io_type == H9632) return 176400;
908 case HDSP_spdifFrequency192KHz:
909 if (hdsp->io_type == H9632) return 192000;
914 snd_printk ("Hammerfall-DSP: unknown spdif frequency status; bits = 0x%x, status = 0x%x\n", rate_bits, status);
918 static void hdsp_compute_period_size(hdsp_t *hdsp)
920 hdsp->period_bytes = 1 << ((hdsp_decode_latency(hdsp->control_register) + 8));
923 static snd_pcm_uframes_t hdsp_hw_pointer(hdsp_t *hdsp)
927 position = hdsp_read(hdsp, HDSP_statusRegister);
929 if (!hdsp->precise_ptr) {
930 return (position & HDSP_BufferID) ? (hdsp->period_bytes / 4) : 0;
933 position &= HDSP_BufferPositionMask;
935 position &= (hdsp->period_bytes/2) - 1;
939 static void hdsp_reset_hw_pointer(hdsp_t *hdsp)
941 hdsp_write (hdsp, HDSP_resetPointer, 0);
944 static void hdsp_start_audio(hdsp_t *s)
946 s->control_register |= (HDSP_AudioInterruptEnable | HDSP_Start);
947 hdsp_write(s, HDSP_controlRegister, s->control_register);
950 static void hdsp_stop_audio(hdsp_t *s)
952 s->control_register &= ~(HDSP_Start | HDSP_AudioInterruptEnable);
953 hdsp_write(s, HDSP_controlRegister, s->control_register);
956 static void hdsp_silence_playback(hdsp_t *hdsp)
958 memset(hdsp->playback_buffer, 0, HDSP_DMA_AREA_BYTES);
961 static int hdsp_set_interrupt_interval(hdsp_t *s, unsigned int frames)
965 spin_lock_irq(&s->lock);
974 s->control_register &= ~HDSP_LatencyMask;
975 s->control_register |= hdsp_encode_latency(n);
977 hdsp_write(s, HDSP_controlRegister, s->control_register);
979 hdsp_compute_period_size(s);
981 spin_unlock_irq(&s->lock);
986 static int hdsp_set_rate(hdsp_t *hdsp, int rate, int called_internally)
988 int reject_if_open = 0;
992 /* ASSUMPTION: hdsp->lock is either held, or
993 there is no need for it (e.g. during module
997 if (!(hdsp->control_register & HDSP_ClockModeMaster)) {
998 if (called_internally) {
999 /* request from ctl or card initialization */
1000 snd_printk("Hammerfall-DSP: device is not running as a clock master: cannot set sample rate.\n");
1003 /* hw_param request while in AutoSync mode */
1004 int external_freq = hdsp_external_sample_rate(hdsp);
1005 int spdif_freq = hdsp_spdif_sample_rate(hdsp);
1007 if ((spdif_freq == external_freq*2) && (hdsp_autosync_ref(hdsp) >= HDSP_AUTOSYNC_FROM_ADAT1)) {
1008 snd_printk("Hammerfall-DSP: Detected ADAT in double speed mode\n");
1009 } else if (hdsp->io_type == H9632 && (spdif_freq == external_freq*4) && (hdsp_autosync_ref(hdsp) >= HDSP_AUTOSYNC_FROM_ADAT1)) {
1010 snd_printk("Hammerfall-DSP: Detected ADAT in quad speed mode\n");
1011 } else if (rate != external_freq) {
1012 snd_printk("Hammerfall-DSP: No AutoSync source for requested rate\n");
1018 current_rate = hdsp->system_sample_rate;
1020 /* Changing from a "single speed" to a "double speed" rate is
1021 not allowed if any substreams are open. This is because
1022 such a change causes a shift in the location of
1023 the DMA buffers and a reduction in the number of available
1026 Note that a similar but essentially insoluble problem
1027 exists for externally-driven rate changes. All we can do
1028 is to flag rate changes in the read/write routines. */
1030 if (rate > 96000 && hdsp->io_type != H9632) {
1036 if (current_rate > 48000) {
1039 rate_bits = HDSP_Frequency32KHz;
1042 if (current_rate > 48000) {
1045 rate_bits = HDSP_Frequency44_1KHz;
1048 if (current_rate > 48000) {
1051 rate_bits = HDSP_Frequency48KHz;
1054 if (current_rate <= 48000 || current_rate > 96000) {
1057 rate_bits = HDSP_Frequency64KHz;
1060 if (current_rate <= 48000 || current_rate > 96000) {
1063 rate_bits = HDSP_Frequency88_2KHz;
1066 if (current_rate <= 48000 || current_rate > 96000) {
1069 rate_bits = HDSP_Frequency96KHz;
1072 if (current_rate < 128000) {
1075 rate_bits = HDSP_Frequency128KHz;
1078 if (current_rate < 128000) {
1081 rate_bits = HDSP_Frequency176_4KHz;
1084 if (current_rate < 128000) {
1087 rate_bits = HDSP_Frequency192KHz;
1093 if (reject_if_open && (hdsp->capture_pid >= 0 || hdsp->playback_pid >= 0)) {
1094 snd_printk ("Hammerfall-DSP: cannot change speed mode (capture PID = %d, playback PID = %d)\n",
1096 hdsp->playback_pid);
1100 hdsp->control_register &= ~HDSP_FrequencyMask;
1101 hdsp->control_register |= rate_bits;
1102 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
1104 if (rate >= 128000) {
1105 hdsp->channel_map = channel_map_H9632_qs;
1106 } else if (rate > 48000) {
1107 if (hdsp->io_type == H9632) {
1108 hdsp->channel_map = channel_map_H9632_ds;
1110 hdsp->channel_map = channel_map_ds;
1113 switch (hdsp->io_type) {
1115 hdsp->channel_map = channel_map_mf_ss;
1119 hdsp->channel_map = channel_map_df_ss;
1122 hdsp->channel_map = channel_map_H9632_ss;
1125 /* should never happen */
1130 hdsp->system_sample_rate = rate;
1135 /*----------------------------------------------------------------------------
1137 ----------------------------------------------------------------------------*/
1139 static unsigned char snd_hdsp_midi_read_byte (hdsp_t *hdsp, int id)
1141 /* the hardware already does the relevant bit-mask with 0xff */
1143 return hdsp_read(hdsp, HDSP_midiDataIn1);
1145 return hdsp_read(hdsp, HDSP_midiDataIn0);
1149 static void snd_hdsp_midi_write_byte (hdsp_t *hdsp, int id, int val)
1151 /* the hardware already does the relevant bit-mask with 0xff */
1153 hdsp_write(hdsp, HDSP_midiDataOut1, val);
1155 hdsp_write(hdsp, HDSP_midiDataOut0, val);
1159 static int snd_hdsp_midi_input_available (hdsp_t *hdsp, int id)
1162 return (hdsp_read(hdsp, HDSP_midiStatusIn1) & 0xff);
1164 return (hdsp_read(hdsp, HDSP_midiStatusIn0) & 0xff);
1168 static int snd_hdsp_midi_output_possible (hdsp_t *hdsp, int id)
1170 int fifo_bytes_used;
1173 fifo_bytes_used = hdsp_read(hdsp, HDSP_midiStatusOut1) & 0xff;
1175 fifo_bytes_used = hdsp_read(hdsp, HDSP_midiStatusOut0) & 0xff;
1178 if (fifo_bytes_used < 128) {
1179 return 128 - fifo_bytes_used;
1185 static void snd_hdsp_flush_midi_input (hdsp_t *hdsp, int id)
1187 while (snd_hdsp_midi_input_available (hdsp, id)) {
1188 snd_hdsp_midi_read_byte (hdsp, id);
1192 static int snd_hdsp_midi_output_write (hdsp_midi_t *hmidi)
1194 unsigned long flags;
1198 unsigned char buf[128];
1200 /* Output is not interrupt driven */
1202 spin_lock_irqsave (&hmidi->lock, flags);
1203 if (hmidi->output) {
1204 if (!snd_rawmidi_transmit_empty (hmidi->output)) {
1205 if ((n_pending = snd_hdsp_midi_output_possible (hmidi->hdsp, hmidi->id)) > 0) {
1206 if (n_pending > (int)sizeof (buf))
1207 n_pending = sizeof (buf);
1209 if ((to_write = snd_rawmidi_transmit (hmidi->output, buf, n_pending)) > 0) {
1210 for (i = 0; i < to_write; ++i)
1211 snd_hdsp_midi_write_byte (hmidi->hdsp, hmidi->id, buf[i]);
1216 spin_unlock_irqrestore (&hmidi->lock, flags);
1220 static int snd_hdsp_midi_input_read (hdsp_midi_t *hmidi)
1222 unsigned char buf[128]; /* this buffer is designed to match the MIDI input FIFO size */
1223 unsigned long flags;
1227 spin_lock_irqsave (&hmidi->lock, flags);
1228 if ((n_pending = snd_hdsp_midi_input_available (hmidi->hdsp, hmidi->id)) > 0) {
1230 if (n_pending > (int)sizeof (buf)) {
1231 n_pending = sizeof (buf);
1233 for (i = 0; i < n_pending; ++i) {
1234 buf[i] = snd_hdsp_midi_read_byte (hmidi->hdsp, hmidi->id);
1237 snd_rawmidi_receive (hmidi->input, buf, n_pending);
1240 /* flush the MIDI input FIFO */
1241 while (--n_pending) {
1242 snd_hdsp_midi_read_byte (hmidi->hdsp, hmidi->id);
1248 hmidi->hdsp->control_register |= HDSP_Midi1InterruptEnable;
1250 hmidi->hdsp->control_register |= HDSP_Midi0InterruptEnable;
1252 hdsp_write(hmidi->hdsp, HDSP_controlRegister, hmidi->hdsp->control_register);
1253 spin_unlock_irqrestore (&hmidi->lock, flags);
1254 return snd_hdsp_midi_output_write (hmidi);
1257 static void snd_hdsp_midi_input_trigger(snd_rawmidi_substream_t * substream, int up)
1261 unsigned long flags;
1264 hmidi = (hdsp_midi_t *) substream->rmidi->private_data;
1266 ie = hmidi->id ? HDSP_Midi1InterruptEnable : HDSP_Midi0InterruptEnable;
1267 spin_lock_irqsave (&hdsp->lock, flags);
1269 if (!(hdsp->control_register & ie)) {
1270 snd_hdsp_flush_midi_input (hdsp, hmidi->id);
1271 hdsp->control_register |= ie;
1274 hdsp->control_register &= ~ie;
1275 tasklet_kill(&hdsp->midi_tasklet);
1278 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
1279 spin_unlock_irqrestore (&hdsp->lock, flags);
1282 static void snd_hdsp_midi_output_timer(unsigned long data)
1284 hdsp_midi_t *hmidi = (hdsp_midi_t *) data;
1285 unsigned long flags;
1287 snd_hdsp_midi_output_write(hmidi);
1288 spin_lock_irqsave (&hmidi->lock, flags);
1290 /* this does not bump hmidi->istimer, because the
1291 kernel automatically removed the timer when it
1292 expired, and we are now adding it back, thus
1293 leaving istimer wherever it was set before.
1296 if (hmidi->istimer) {
1297 hmidi->timer.expires = 1 + jiffies;
1298 add_timer(&hmidi->timer);
1301 spin_unlock_irqrestore (&hmidi->lock, flags);
1304 static void snd_hdsp_midi_output_trigger(snd_rawmidi_substream_t * substream, int up)
1307 unsigned long flags;
1309 hmidi = (hdsp_midi_t *) substream->rmidi->private_data;
1310 spin_lock_irqsave (&hmidi->lock, flags);
1312 if (!hmidi->istimer) {
1313 init_timer(&hmidi->timer);
1314 hmidi->timer.function = snd_hdsp_midi_output_timer;
1315 hmidi->timer.data = (unsigned long) hmidi;
1316 hmidi->timer.expires = 1 + jiffies;
1317 add_timer(&hmidi->timer);
1321 if (hmidi->istimer && --hmidi->istimer <= 0) {
1322 del_timer (&hmidi->timer);
1325 spin_unlock_irqrestore (&hmidi->lock, flags);
1327 snd_hdsp_midi_output_write(hmidi);
1330 static int snd_hdsp_midi_input_open(snd_rawmidi_substream_t * substream)
1334 hmidi = (hdsp_midi_t *) substream->rmidi->private_data;
1335 spin_lock_irq (&hmidi->lock);
1336 snd_hdsp_flush_midi_input (hmidi->hdsp, hmidi->id);
1337 hmidi->input = substream;
1338 spin_unlock_irq (&hmidi->lock);
1343 static int snd_hdsp_midi_output_open(snd_rawmidi_substream_t * substream)
1347 hmidi = (hdsp_midi_t *) substream->rmidi->private_data;
1348 spin_lock_irq (&hmidi->lock);
1349 hmidi->output = substream;
1350 spin_unlock_irq (&hmidi->lock);
1355 static int snd_hdsp_midi_input_close(snd_rawmidi_substream_t * substream)
1359 snd_hdsp_midi_input_trigger (substream, 0);
1361 hmidi = (hdsp_midi_t *) substream->rmidi->private_data;
1362 spin_lock_irq (&hmidi->lock);
1363 hmidi->input = NULL;
1364 spin_unlock_irq (&hmidi->lock);
1369 static int snd_hdsp_midi_output_close(snd_rawmidi_substream_t * substream)
1373 snd_hdsp_midi_output_trigger (substream, 0);
1375 hmidi = (hdsp_midi_t *) substream->rmidi->private_data;
1376 spin_lock_irq (&hmidi->lock);
1377 hmidi->output = NULL;
1378 spin_unlock_irq (&hmidi->lock);
1383 static snd_rawmidi_ops_t snd_hdsp_midi_output =
1385 .open = snd_hdsp_midi_output_open,
1386 .close = snd_hdsp_midi_output_close,
1387 .trigger = snd_hdsp_midi_output_trigger,
1390 static snd_rawmidi_ops_t snd_hdsp_midi_input =
1392 .open = snd_hdsp_midi_input_open,
1393 .close = snd_hdsp_midi_input_close,
1394 .trigger = snd_hdsp_midi_input_trigger,
1397 static int __devinit snd_hdsp_create_midi (snd_card_t *card, hdsp_t *hdsp, int id)
1401 hdsp->midi[id].id = id;
1402 hdsp->midi[id].rmidi = NULL;
1403 hdsp->midi[id].input = NULL;
1404 hdsp->midi[id].output = NULL;
1405 hdsp->midi[id].hdsp = hdsp;
1406 hdsp->midi[id].istimer = 0;
1407 hdsp->midi[id].pending = 0;
1408 spin_lock_init (&hdsp->midi[id].lock);
1410 sprintf (buf, "%s MIDI %d", card->shortname, id+1);
1411 if (snd_rawmidi_new (card, buf, id, 1, 1, &hdsp->midi[id].rmidi) < 0) {
1415 sprintf (hdsp->midi[id].rmidi->name, "%s MIDI %d", card->id, id+1);
1416 hdsp->midi[id].rmidi->private_data = &hdsp->midi[id];
1418 snd_rawmidi_set_ops (hdsp->midi[id].rmidi, SNDRV_RAWMIDI_STREAM_OUTPUT, &snd_hdsp_midi_output);
1419 snd_rawmidi_set_ops (hdsp->midi[id].rmidi, SNDRV_RAWMIDI_STREAM_INPUT, &snd_hdsp_midi_input);
1421 hdsp->midi[id].rmidi->info_flags |= SNDRV_RAWMIDI_INFO_OUTPUT |
1422 SNDRV_RAWMIDI_INFO_INPUT |
1423 SNDRV_RAWMIDI_INFO_DUPLEX;
1428 /*-----------------------------------------------------------------------------
1430 ----------------------------------------------------------------------------*/
1432 static u32 snd_hdsp_convert_from_aes(snd_aes_iec958_t *aes)
1435 val |= (aes->status[0] & IEC958_AES0_PROFESSIONAL) ? HDSP_SPDIFProfessional : 0;
1436 val |= (aes->status[0] & IEC958_AES0_NONAUDIO) ? HDSP_SPDIFNonAudio : 0;
1437 if (val & HDSP_SPDIFProfessional)
1438 val |= (aes->status[0] & IEC958_AES0_PRO_EMPHASIS_5015) ? HDSP_SPDIFEmphasis : 0;
1440 val |= (aes->status[0] & IEC958_AES0_CON_EMPHASIS_5015) ? HDSP_SPDIFEmphasis : 0;
1444 static void snd_hdsp_convert_to_aes(snd_aes_iec958_t *aes, u32 val)
1446 aes->status[0] = ((val & HDSP_SPDIFProfessional) ? IEC958_AES0_PROFESSIONAL : 0) |
1447 ((val & HDSP_SPDIFNonAudio) ? IEC958_AES0_NONAUDIO : 0);
1448 if (val & HDSP_SPDIFProfessional)
1449 aes->status[0] |= (val & HDSP_SPDIFEmphasis) ? IEC958_AES0_PRO_EMPHASIS_5015 : 0;
1451 aes->status[0] |= (val & HDSP_SPDIFEmphasis) ? IEC958_AES0_CON_EMPHASIS_5015 : 0;
1454 static int snd_hdsp_control_spdif_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
1456 uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
1461 static int snd_hdsp_control_spdif_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1463 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
1465 snd_hdsp_convert_to_aes(&ucontrol->value.iec958, hdsp->creg_spdif);
1469 static int snd_hdsp_control_spdif_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1471 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
1475 val = snd_hdsp_convert_from_aes(&ucontrol->value.iec958);
1476 spin_lock_irq(&hdsp->lock);
1477 change = val != hdsp->creg_spdif;
1478 hdsp->creg_spdif = val;
1479 spin_unlock_irq(&hdsp->lock);
1483 static int snd_hdsp_control_spdif_stream_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
1485 uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
1490 static int snd_hdsp_control_spdif_stream_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1492 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
1494 snd_hdsp_convert_to_aes(&ucontrol->value.iec958, hdsp->creg_spdif_stream);
1498 static int snd_hdsp_control_spdif_stream_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1500 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
1504 val = snd_hdsp_convert_from_aes(&ucontrol->value.iec958);
1505 spin_lock_irq(&hdsp->lock);
1506 change = val != hdsp->creg_spdif_stream;
1507 hdsp->creg_spdif_stream = val;
1508 hdsp->control_register &= ~(HDSP_SPDIFProfessional | HDSP_SPDIFNonAudio | HDSP_SPDIFEmphasis);
1509 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register |= val);
1510 spin_unlock_irq(&hdsp->lock);
1514 static int snd_hdsp_control_spdif_mask_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
1516 uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
1521 static int snd_hdsp_control_spdif_mask_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1523 ucontrol->value.iec958.status[0] = kcontrol->private_value;
1527 #define HDSP_SPDIF_IN(xname, xindex) \
1528 { .iface = SNDRV_CTL_ELEM_IFACE_PCM, \
1531 .info = snd_hdsp_info_spdif_in, \
1532 .get = snd_hdsp_get_spdif_in, \
1533 .put = snd_hdsp_put_spdif_in }
1535 static unsigned int hdsp_spdif_in(hdsp_t *hdsp)
1537 return hdsp_decode_spdif_in(hdsp->control_register & HDSP_SPDIFInputMask);
1540 static int hdsp_set_spdif_input(hdsp_t *hdsp, int in)
1542 hdsp->control_register &= ~HDSP_SPDIFInputMask;
1543 hdsp->control_register |= hdsp_encode_spdif_in(in);
1544 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
1548 static int snd_hdsp_info_spdif_in(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
1550 static char *texts[4] = {"Optical", "Coaxial", "Internal", "AES"};
1551 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
1553 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1555 uinfo->value.enumerated.items = ((hdsp->io_type == H9632) ? 4 : 3);
1556 if (uinfo->value.enumerated.item > ((hdsp->io_type == H9632) ? 3 : 2))
1557 uinfo->value.enumerated.item = ((hdsp->io_type == H9632) ? 3 : 2);
1558 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1562 static int snd_hdsp_get_spdif_in(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1564 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
1566 ucontrol->value.enumerated.item[0] = hdsp_spdif_in(hdsp);
1570 static int snd_hdsp_put_spdif_in(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1572 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
1576 if (!snd_hdsp_use_is_exclusive(hdsp))
1578 val = ucontrol->value.enumerated.item[0] % ((hdsp->io_type == H9632) ? 4 : 3);
1579 spin_lock_irq(&hdsp->lock);
1580 change = val != hdsp_spdif_in(hdsp);
1582 hdsp_set_spdif_input(hdsp, val);
1583 spin_unlock_irq(&hdsp->lock);
1587 #define HDSP_SPDIF_OUT(xname, xindex) \
1588 { .iface = SNDRV_CTL_ELEM_IFACE_HWDEP, .name = xname, .index = xindex, \
1589 .info = snd_hdsp_info_spdif_bits, \
1590 .get = snd_hdsp_get_spdif_out, .put = snd_hdsp_put_spdif_out }
1592 static int hdsp_spdif_out(hdsp_t *hdsp)
1594 return (hdsp->control_register & HDSP_SPDIFOpticalOut) ? 1 : 0;
1597 static int hdsp_set_spdif_output(hdsp_t *hdsp, int out)
1600 hdsp->control_register |= HDSP_SPDIFOpticalOut;
1602 hdsp->control_register &= ~HDSP_SPDIFOpticalOut;
1604 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
1608 static int snd_hdsp_info_spdif_bits(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
1610 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
1612 uinfo->value.integer.min = 0;
1613 uinfo->value.integer.max = 1;
1617 static int snd_hdsp_get_spdif_out(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1619 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
1621 ucontrol->value.integer.value[0] = hdsp_spdif_out(hdsp);
1625 static int snd_hdsp_put_spdif_out(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1627 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
1631 if (!snd_hdsp_use_is_exclusive(hdsp))
1633 val = ucontrol->value.integer.value[0] & 1;
1634 spin_lock_irq(&hdsp->lock);
1635 change = (int)val != hdsp_spdif_out(hdsp);
1636 hdsp_set_spdif_output(hdsp, val);
1637 spin_unlock_irq(&hdsp->lock);
1641 #define HDSP_SPDIF_PROFESSIONAL(xname, xindex) \
1642 { .iface = SNDRV_CTL_ELEM_IFACE_HWDEP, .name = xname, .index = xindex, \
1643 .info = snd_hdsp_info_spdif_bits, \
1644 .get = snd_hdsp_get_spdif_professional, .put = snd_hdsp_put_spdif_professional }
1646 static int hdsp_spdif_professional(hdsp_t *hdsp)
1648 return (hdsp->control_register & HDSP_SPDIFProfessional) ? 1 : 0;
1651 static int hdsp_set_spdif_professional(hdsp_t *hdsp, int val)
1654 hdsp->control_register |= HDSP_SPDIFProfessional;
1656 hdsp->control_register &= ~HDSP_SPDIFProfessional;
1658 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
1662 static int snd_hdsp_get_spdif_professional(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1664 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
1666 ucontrol->value.integer.value[0] = hdsp_spdif_professional(hdsp);
1670 static int snd_hdsp_put_spdif_professional(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1672 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
1676 if (!snd_hdsp_use_is_exclusive(hdsp))
1678 val = ucontrol->value.integer.value[0] & 1;
1679 spin_lock_irq(&hdsp->lock);
1680 change = (int)val != hdsp_spdif_professional(hdsp);
1681 hdsp_set_spdif_professional(hdsp, val);
1682 spin_unlock_irq(&hdsp->lock);
1686 #define HDSP_SPDIF_EMPHASIS(xname, xindex) \
1687 { .iface = SNDRV_CTL_ELEM_IFACE_HWDEP, .name = xname, .index = xindex, \
1688 .info = snd_hdsp_info_spdif_bits, \
1689 .get = snd_hdsp_get_spdif_emphasis, .put = snd_hdsp_put_spdif_emphasis }
1691 static int hdsp_spdif_emphasis(hdsp_t *hdsp)
1693 return (hdsp->control_register & HDSP_SPDIFEmphasis) ? 1 : 0;
1696 static int hdsp_set_spdif_emphasis(hdsp_t *hdsp, int val)
1699 hdsp->control_register |= HDSP_SPDIFEmphasis;
1701 hdsp->control_register &= ~HDSP_SPDIFEmphasis;
1703 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
1707 static int snd_hdsp_get_spdif_emphasis(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1709 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
1711 ucontrol->value.integer.value[0] = hdsp_spdif_emphasis(hdsp);
1715 static int snd_hdsp_put_spdif_emphasis(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1717 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
1721 if (!snd_hdsp_use_is_exclusive(hdsp))
1723 val = ucontrol->value.integer.value[0] & 1;
1724 spin_lock_irq(&hdsp->lock);
1725 change = (int)val != hdsp_spdif_emphasis(hdsp);
1726 hdsp_set_spdif_emphasis(hdsp, val);
1727 spin_unlock_irq(&hdsp->lock);
1731 #define HDSP_SPDIF_NON_AUDIO(xname, xindex) \
1732 { .iface = SNDRV_CTL_ELEM_IFACE_HWDEP, .name = xname, .index = xindex, \
1733 .info = snd_hdsp_info_spdif_bits, \
1734 .get = snd_hdsp_get_spdif_nonaudio, .put = snd_hdsp_put_spdif_nonaudio }
1736 static int hdsp_spdif_nonaudio(hdsp_t *hdsp)
1738 return (hdsp->control_register & HDSP_SPDIFNonAudio) ? 1 : 0;
1741 static int hdsp_set_spdif_nonaudio(hdsp_t *hdsp, int val)
1744 hdsp->control_register |= HDSP_SPDIFNonAudio;
1746 hdsp->control_register &= ~HDSP_SPDIFNonAudio;
1748 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
1752 static int snd_hdsp_get_spdif_nonaudio(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1754 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
1756 ucontrol->value.integer.value[0] = hdsp_spdif_nonaudio(hdsp);
1760 static int snd_hdsp_put_spdif_nonaudio(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1762 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
1766 if (!snd_hdsp_use_is_exclusive(hdsp))
1768 val = ucontrol->value.integer.value[0] & 1;
1769 spin_lock_irq(&hdsp->lock);
1770 change = (int)val != hdsp_spdif_nonaudio(hdsp);
1771 hdsp_set_spdif_nonaudio(hdsp, val);
1772 spin_unlock_irq(&hdsp->lock);
1776 #define HDSP_SPDIF_SAMPLE_RATE(xname, xindex) \
1777 { .iface = SNDRV_CTL_ELEM_IFACE_HWDEP, \
1780 .access = SNDRV_CTL_ELEM_ACCESS_READ, \
1781 .info = snd_hdsp_info_spdif_sample_rate, \
1782 .get = snd_hdsp_get_spdif_sample_rate \
1785 static int snd_hdsp_info_spdif_sample_rate(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
1787 static char *texts[] = {"32000", "44100", "48000", "64000", "88200", "96000", "None", "128000", "176400", "192000"};
1788 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
1790 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1792 uinfo->value.enumerated.items = (hdsp->io_type == H9632) ? 10 : 7;
1793 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
1794 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
1795 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1799 static int snd_hdsp_get_spdif_sample_rate(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1801 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
1803 switch (hdsp_spdif_sample_rate(hdsp)) {
1805 ucontrol->value.enumerated.item[0] = 0;
1808 ucontrol->value.enumerated.item[0] = 1;
1811 ucontrol->value.enumerated.item[0] = 2;
1814 ucontrol->value.enumerated.item[0] = 3;
1817 ucontrol->value.enumerated.item[0] = 4;
1820 ucontrol->value.enumerated.item[0] = 5;
1823 ucontrol->value.enumerated.item[0] = 7;
1826 ucontrol->value.enumerated.item[0] = 8;
1829 ucontrol->value.enumerated.item[0] = 9;
1832 ucontrol->value.enumerated.item[0] = 6;
1837 #define HDSP_SYSTEM_SAMPLE_RATE(xname, xindex) \
1838 { .iface = SNDRV_CTL_ELEM_IFACE_HWDEP, \
1841 .access = SNDRV_CTL_ELEM_ACCESS_READ, \
1842 .info = snd_hdsp_info_system_sample_rate, \
1843 .get = snd_hdsp_get_system_sample_rate \
1846 static int snd_hdsp_info_system_sample_rate(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
1848 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1853 static int snd_hdsp_get_system_sample_rate(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1855 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
1857 ucontrol->value.enumerated.item[0] = hdsp->system_sample_rate;
1861 #define HDSP_AUTOSYNC_SAMPLE_RATE(xname, xindex) \
1862 { .iface = SNDRV_CTL_ELEM_IFACE_PCM, \
1865 .access = SNDRV_CTL_ELEM_ACCESS_READ, \
1866 .info = snd_hdsp_info_autosync_sample_rate, \
1867 .get = snd_hdsp_get_autosync_sample_rate \
1870 static int snd_hdsp_info_autosync_sample_rate(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
1872 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
1873 static char *texts[] = {"32000", "44100", "48000", "64000", "88200", "96000", "None", "128000", "176400", "192000"};
1874 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1876 uinfo->value.enumerated.items = (hdsp->io_type == H9632) ? 10 : 7 ;
1877 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
1878 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
1879 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1883 static int snd_hdsp_get_autosync_sample_rate(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1885 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
1887 switch (hdsp_external_sample_rate(hdsp)) {
1889 ucontrol->value.enumerated.item[0] = 0;
1892 ucontrol->value.enumerated.item[0] = 1;
1895 ucontrol->value.enumerated.item[0] = 2;
1898 ucontrol->value.enumerated.item[0] = 3;
1901 ucontrol->value.enumerated.item[0] = 4;
1904 ucontrol->value.enumerated.item[0] = 5;
1907 ucontrol->value.enumerated.item[0] = 7;
1910 ucontrol->value.enumerated.item[0] = 8;
1913 ucontrol->value.enumerated.item[0] = 9;
1916 ucontrol->value.enumerated.item[0] = 6;
1921 #define HDSP_SYSTEM_CLOCK_MODE(xname, xindex) \
1922 { .iface = SNDRV_CTL_ELEM_IFACE_HWDEP, \
1925 .access = SNDRV_CTL_ELEM_ACCESS_READ, \
1926 .info = snd_hdsp_info_system_clock_mode, \
1927 .get = snd_hdsp_get_system_clock_mode \
1930 static int hdsp_system_clock_mode(hdsp_t *hdsp)
1932 if (hdsp->control_register & HDSP_ClockModeMaster) {
1934 } else if (hdsp_external_sample_rate(hdsp) != hdsp->system_sample_rate) {
1940 static int snd_hdsp_info_system_clock_mode(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
1942 static char *texts[] = {"Master", "Slave" };
1944 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1946 uinfo->value.enumerated.items = 2;
1947 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
1948 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
1949 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1953 static int snd_hdsp_get_system_clock_mode(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1955 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
1957 ucontrol->value.enumerated.item[0] = hdsp_system_clock_mode(hdsp);
1961 #define HDSP_CLOCK_SOURCE(xname, xindex) \
1962 { .iface = SNDRV_CTL_ELEM_IFACE_PCM, \
1965 .info = snd_hdsp_info_clock_source, \
1966 .get = snd_hdsp_get_clock_source, \
1967 .put = snd_hdsp_put_clock_source \
1970 static int hdsp_clock_source(hdsp_t *hdsp)
1972 if (hdsp->control_register & HDSP_ClockModeMaster) {
1973 switch (hdsp->system_sample_rate) {
2000 static int hdsp_set_clock_source(hdsp_t *hdsp, int mode)
2004 case HDSP_CLOCK_SOURCE_AUTOSYNC:
2005 if (hdsp_external_sample_rate(hdsp) != 0) {
2006 if (!hdsp_set_rate(hdsp, hdsp_external_sample_rate(hdsp), 1)) {
2007 hdsp->control_register &= ~HDSP_ClockModeMaster;
2008 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
2013 case HDSP_CLOCK_SOURCE_INTERNAL_32KHZ:
2016 case HDSP_CLOCK_SOURCE_INTERNAL_44_1KHZ:
2019 case HDSP_CLOCK_SOURCE_INTERNAL_48KHZ:
2022 case HDSP_CLOCK_SOURCE_INTERNAL_64KHZ:
2025 case HDSP_CLOCK_SOURCE_INTERNAL_88_2KHZ:
2028 case HDSP_CLOCK_SOURCE_INTERNAL_96KHZ:
2031 case HDSP_CLOCK_SOURCE_INTERNAL_128KHZ:
2034 case HDSP_CLOCK_SOURCE_INTERNAL_176_4KHZ:
2037 case HDSP_CLOCK_SOURCE_INTERNAL_192KHZ:
2043 hdsp->control_register |= HDSP_ClockModeMaster;
2044 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
2045 hdsp_set_rate(hdsp, rate, 1);
2049 static int snd_hdsp_info_clock_source(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
2051 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" };
2052 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
2054 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2056 if (hdsp->io_type == H9632)
2057 uinfo->value.enumerated.items = 10;
2059 uinfo->value.enumerated.items = 7;
2060 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
2061 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
2062 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
2066 static int snd_hdsp_get_clock_source(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
2068 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
2070 ucontrol->value.enumerated.item[0] = hdsp_clock_source(hdsp);
2074 static int snd_hdsp_put_clock_source(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
2076 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
2080 if (!snd_hdsp_use_is_exclusive(hdsp))
2082 val = ucontrol->value.enumerated.item[0];
2083 if (val < 0) val = 0;
2084 if (hdsp->io_type == H9632) {
2085 if (val > 9) val = 9;
2087 if (val > 6) val = 6;
2089 spin_lock_irq(&hdsp->lock);
2090 if (val != hdsp_clock_source(hdsp)) {
2091 change = (hdsp_set_clock_source(hdsp, val) == 0) ? 1 : 0;
2095 spin_unlock_irq(&hdsp->lock);
2099 static int snd_hdsp_info_clock_source_lock(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
2101 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
2103 uinfo->value.integer.min = 0;
2104 uinfo->value.integer.max = 1;
2108 static int snd_hdsp_get_clock_source_lock(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
2110 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
2112 ucontrol->value.integer.value[0] = hdsp->clock_source_locked;
2116 static int snd_hdsp_put_clock_source_lock(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
2118 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
2121 change = (int)ucontrol->value.integer.value[0] != hdsp->clock_source_locked;
2123 hdsp->clock_source_locked = ucontrol->value.integer.value[0];
2127 #define HDSP_DA_GAIN(xname, xindex) \
2128 { .iface = SNDRV_CTL_ELEM_IFACE_HWDEP, \
2131 .info = snd_hdsp_info_da_gain, \
2132 .get = snd_hdsp_get_da_gain, \
2133 .put = snd_hdsp_put_da_gain \
2136 static int hdsp_da_gain(hdsp_t *hdsp)
2138 switch (hdsp->control_register & HDSP_DAGainMask) {
2139 case HDSP_DAGainHighGain:
2141 case HDSP_DAGainPlus4dBu:
2143 case HDSP_DAGainMinus10dBV:
2150 static int hdsp_set_da_gain(hdsp_t *hdsp, int mode)
2152 hdsp->control_register &= ~HDSP_DAGainMask;
2155 hdsp->control_register |= HDSP_DAGainHighGain;
2158 hdsp->control_register |= HDSP_DAGainPlus4dBu;
2161 hdsp->control_register |= HDSP_DAGainMinus10dBV;
2167 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
2171 static int snd_hdsp_info_da_gain(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
2173 static char *texts[] = {"Hi Gain", "+4 dBu", "-10 dbV"};
2175 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2177 uinfo->value.enumerated.items = 3;
2178 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
2179 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
2180 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
2184 static int snd_hdsp_get_da_gain(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
2186 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
2188 ucontrol->value.enumerated.item[0] = hdsp_da_gain(hdsp);
2192 static int snd_hdsp_put_da_gain(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
2194 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
2198 if (!snd_hdsp_use_is_exclusive(hdsp))
2200 val = ucontrol->value.enumerated.item[0];
2201 if (val < 0) val = 0;
2202 if (val > 2) val = 2;
2203 spin_lock_irq(&hdsp->lock);
2204 if (val != hdsp_da_gain(hdsp)) {
2205 change = (hdsp_set_da_gain(hdsp, val) == 0) ? 1 : 0;
2209 spin_unlock_irq(&hdsp->lock);
2213 #define HDSP_AD_GAIN(xname, xindex) \
2214 { .iface = SNDRV_CTL_ELEM_IFACE_HWDEP, \
2217 .info = snd_hdsp_info_ad_gain, \
2218 .get = snd_hdsp_get_ad_gain, \
2219 .put = snd_hdsp_put_ad_gain \
2222 static int hdsp_ad_gain(hdsp_t *hdsp)
2224 switch (hdsp->control_register & HDSP_ADGainMask) {
2225 case HDSP_ADGainMinus10dBV:
2227 case HDSP_ADGainPlus4dBu:
2229 case HDSP_ADGainLowGain:
2236 static int hdsp_set_ad_gain(hdsp_t *hdsp, int mode)
2238 hdsp->control_register &= ~HDSP_ADGainMask;
2241 hdsp->control_register |= HDSP_ADGainMinus10dBV;
2244 hdsp->control_register |= HDSP_ADGainPlus4dBu;
2247 hdsp->control_register |= HDSP_ADGainLowGain;
2253 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
2257 static int snd_hdsp_info_ad_gain(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
2259 static char *texts[] = {"-10 dBV", "+4 dBu", "Lo Gain"};
2261 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2263 uinfo->value.enumerated.items = 3;
2264 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
2265 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
2266 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
2270 static int snd_hdsp_get_ad_gain(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
2272 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
2274 ucontrol->value.enumerated.item[0] = hdsp_ad_gain(hdsp);
2278 static int snd_hdsp_put_ad_gain(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
2280 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
2284 if (!snd_hdsp_use_is_exclusive(hdsp))
2286 val = ucontrol->value.enumerated.item[0];
2287 if (val < 0) val = 0;
2288 if (val > 2) val = 2;
2289 spin_lock_irq(&hdsp->lock);
2290 if (val != hdsp_ad_gain(hdsp)) {
2291 change = (hdsp_set_ad_gain(hdsp, val) == 0) ? 1 : 0;
2295 spin_unlock_irq(&hdsp->lock);
2299 #define HDSP_PHONE_GAIN(xname, xindex) \
2300 { .iface = SNDRV_CTL_ELEM_IFACE_HWDEP, \
2303 .info = snd_hdsp_info_phone_gain, \
2304 .get = snd_hdsp_get_phone_gain, \
2305 .put = snd_hdsp_put_phone_gain \
2308 static int hdsp_phone_gain(hdsp_t *hdsp)
2310 switch (hdsp->control_register & HDSP_PhoneGainMask) {
2311 case HDSP_PhoneGain0dB:
2313 case HDSP_PhoneGainMinus6dB:
2315 case HDSP_PhoneGainMinus12dB:
2322 static int hdsp_set_phone_gain(hdsp_t *hdsp, int mode)
2324 hdsp->control_register &= ~HDSP_PhoneGainMask;
2327 hdsp->control_register |= HDSP_PhoneGain0dB;
2330 hdsp->control_register |= HDSP_PhoneGainMinus6dB;
2333 hdsp->control_register |= HDSP_PhoneGainMinus12dB;
2339 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
2343 static int snd_hdsp_info_phone_gain(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
2345 static char *texts[] = {"0 dB", "-6 dB", "-12 dB"};
2347 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2349 uinfo->value.enumerated.items = 3;
2350 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
2351 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
2352 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
2356 static int snd_hdsp_get_phone_gain(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
2358 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
2360 ucontrol->value.enumerated.item[0] = hdsp_phone_gain(hdsp);
2364 static int snd_hdsp_put_phone_gain(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
2366 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
2370 if (!snd_hdsp_use_is_exclusive(hdsp))
2372 val = ucontrol->value.enumerated.item[0];
2373 if (val < 0) val = 0;
2374 if (val > 2) val = 2;
2375 spin_lock_irq(&hdsp->lock);
2376 if (val != hdsp_phone_gain(hdsp)) {
2377 change = (hdsp_set_phone_gain(hdsp, val) == 0) ? 1 : 0;
2381 spin_unlock_irq(&hdsp->lock);
2385 #define HDSP_XLR_BREAKOUT_CABLE(xname, xindex) \
2386 { .iface = SNDRV_CTL_ELEM_IFACE_HWDEP, \
2389 .info = snd_hdsp_info_xlr_breakout_cable, \
2390 .get = snd_hdsp_get_xlr_breakout_cable, \
2391 .put = snd_hdsp_put_xlr_breakout_cable \
2394 static int hdsp_xlr_breakout_cable(hdsp_t *hdsp)
2396 if (hdsp->control_register & HDSP_XLRBreakoutCable) {
2402 static int hdsp_set_xlr_breakout_cable(hdsp_t *hdsp, int mode)
2405 hdsp->control_register |= HDSP_XLRBreakoutCable;
2407 hdsp->control_register &= ~HDSP_XLRBreakoutCable;
2409 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
2413 static int snd_hdsp_info_xlr_breakout_cable(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
2415 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
2417 uinfo->value.integer.min = 0;
2418 uinfo->value.integer.max = 1;
2422 static int snd_hdsp_get_xlr_breakout_cable(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
2424 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
2426 ucontrol->value.enumerated.item[0] = hdsp_xlr_breakout_cable(hdsp);
2430 static int snd_hdsp_put_xlr_breakout_cable(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
2432 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
2436 if (!snd_hdsp_use_is_exclusive(hdsp))
2438 val = ucontrol->value.integer.value[0] & 1;
2439 spin_lock_irq(&hdsp->lock);
2440 change = (int)val != hdsp_xlr_breakout_cable(hdsp);
2441 hdsp_set_xlr_breakout_cable(hdsp, val);
2442 spin_unlock_irq(&hdsp->lock);
2446 /* (De)activates old RME Analog Extension Board
2447 These are connected to the internal ADAT connector
2448 Switching this on desactivates external ADAT
2450 #define HDSP_AEB(xname, xindex) \
2451 { .iface = SNDRV_CTL_ELEM_IFACE_HWDEP, \
2454 .info = snd_hdsp_info_aeb, \
2455 .get = snd_hdsp_get_aeb, \
2456 .put = snd_hdsp_put_aeb \
2459 static int hdsp_aeb(hdsp_t *hdsp)
2461 if (hdsp->control_register & HDSP_AnalogExtensionBoard) {
2467 static int hdsp_set_aeb(hdsp_t *hdsp, int mode)
2470 hdsp->control_register |= HDSP_AnalogExtensionBoard;
2472 hdsp->control_register &= ~HDSP_AnalogExtensionBoard;
2474 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
2478 static int snd_hdsp_info_aeb(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
2480 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
2482 uinfo->value.integer.min = 0;
2483 uinfo->value.integer.max = 1;
2487 static int snd_hdsp_get_aeb(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
2489 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
2491 ucontrol->value.enumerated.item[0] = hdsp_aeb(hdsp);
2495 static int snd_hdsp_put_aeb(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
2497 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
2501 if (!snd_hdsp_use_is_exclusive(hdsp))
2503 val = ucontrol->value.integer.value[0] & 1;
2504 spin_lock_irq(&hdsp->lock);
2505 change = (int)val != hdsp_aeb(hdsp);
2506 hdsp_set_aeb(hdsp, val);
2507 spin_unlock_irq(&hdsp->lock);
2511 #define HDSP_PREF_SYNC_REF(xname, xindex) \
2512 { .iface = SNDRV_CTL_ELEM_IFACE_HWDEP, \
2515 .info = snd_hdsp_info_pref_sync_ref, \
2516 .get = snd_hdsp_get_pref_sync_ref, \
2517 .put = snd_hdsp_put_pref_sync_ref \
2520 static int hdsp_pref_sync_ref(hdsp_t *hdsp)
2522 /* Notice that this looks at the requested sync source,
2523 not the one actually in use.
2526 switch (hdsp->control_register & HDSP_SyncRefMask) {
2527 case HDSP_SyncRef_ADAT1:
2528 return HDSP_SYNC_FROM_ADAT1;
2529 case HDSP_SyncRef_ADAT2:
2530 return HDSP_SYNC_FROM_ADAT2;
2531 case HDSP_SyncRef_ADAT3:
2532 return HDSP_SYNC_FROM_ADAT3;
2533 case HDSP_SyncRef_SPDIF:
2534 return HDSP_SYNC_FROM_SPDIF;
2535 case HDSP_SyncRef_WORD:
2536 return HDSP_SYNC_FROM_WORD;
2537 case HDSP_SyncRef_ADAT_SYNC:
2538 return HDSP_SYNC_FROM_ADAT_SYNC;
2540 return HDSP_SYNC_FROM_WORD;
2545 static int hdsp_set_pref_sync_ref(hdsp_t *hdsp, int pref)
2547 hdsp->control_register &= ~HDSP_SyncRefMask;
2549 case HDSP_SYNC_FROM_ADAT1:
2550 hdsp->control_register &= ~HDSP_SyncRefMask; /* clear SyncRef bits */
2552 case HDSP_SYNC_FROM_ADAT2:
2553 hdsp->control_register |= HDSP_SyncRef_ADAT2;
2555 case HDSP_SYNC_FROM_ADAT3:
2556 hdsp->control_register |= HDSP_SyncRef_ADAT3;
2558 case HDSP_SYNC_FROM_SPDIF:
2559 hdsp->control_register |= HDSP_SyncRef_SPDIF;
2561 case HDSP_SYNC_FROM_WORD:
2562 hdsp->control_register |= HDSP_SyncRef_WORD;
2564 case HDSP_SYNC_FROM_ADAT_SYNC:
2565 hdsp->control_register |= HDSP_SyncRef_ADAT_SYNC;
2570 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
2574 static int snd_hdsp_info_pref_sync_ref(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
2576 static char *texts[] = {"Word", "IEC958", "ADAT1", "ADAT Sync", "ADAT2", "ADAT3" };
2577 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
2579 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2582 switch (hdsp->io_type) {
2585 uinfo->value.enumerated.items = 6;
2588 uinfo->value.enumerated.items = 4;
2591 uinfo->value.enumerated.items = 3;
2594 uinfo->value.enumerated.items = 0;
2598 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
2599 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
2600 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
2604 static int snd_hdsp_get_pref_sync_ref(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
2606 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
2608 ucontrol->value.enumerated.item[0] = hdsp_pref_sync_ref(hdsp);
2612 static int snd_hdsp_put_pref_sync_ref(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
2614 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
2618 if (!snd_hdsp_use_is_exclusive(hdsp))
2621 switch (hdsp->io_type) {
2636 val = ucontrol->value.enumerated.item[0] % max;
2637 spin_lock_irq(&hdsp->lock);
2638 change = (int)val != hdsp_pref_sync_ref(hdsp);
2639 hdsp_set_pref_sync_ref(hdsp, val);
2640 spin_unlock_irq(&hdsp->lock);
2644 #define HDSP_AUTOSYNC_REF(xname, xindex) \
2645 { .iface = SNDRV_CTL_ELEM_IFACE_HWDEP, \
2648 .access = SNDRV_CTL_ELEM_ACCESS_READ, \
2649 .info = snd_hdsp_info_autosync_ref, \
2650 .get = snd_hdsp_get_autosync_ref, \
2653 static int hdsp_autosync_ref(hdsp_t *hdsp)
2655 /* This looks at the autosync selected sync reference */
2656 unsigned int status2 = hdsp_read(hdsp, HDSP_status2Register);
2658 switch (status2 & HDSP_SelSyncRefMask) {
2659 case HDSP_SelSyncRef_WORD:
2660 return HDSP_AUTOSYNC_FROM_WORD;
2661 case HDSP_SelSyncRef_ADAT_SYNC:
2662 return HDSP_AUTOSYNC_FROM_ADAT_SYNC;
2663 case HDSP_SelSyncRef_SPDIF:
2664 return HDSP_AUTOSYNC_FROM_SPDIF;
2665 case HDSP_SelSyncRefMask:
2666 return HDSP_AUTOSYNC_FROM_NONE;
2667 case HDSP_SelSyncRef_ADAT1:
2668 return HDSP_AUTOSYNC_FROM_ADAT1;
2669 case HDSP_SelSyncRef_ADAT2:
2670 return HDSP_AUTOSYNC_FROM_ADAT2;
2671 case HDSP_SelSyncRef_ADAT3:
2672 return HDSP_AUTOSYNC_FROM_ADAT3;
2674 return HDSP_AUTOSYNC_FROM_WORD;
2679 static int snd_hdsp_info_autosync_ref(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
2681 static char *texts[] = {"Word", "ADAT Sync", "IEC958", "None", "ADAT1", "ADAT2", "ADAT3" };
2683 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2685 uinfo->value.enumerated.items = 7;
2686 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
2687 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
2688 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
2692 static int snd_hdsp_get_autosync_ref(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
2694 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
2696 ucontrol->value.enumerated.item[0] = hdsp_autosync_ref(hdsp);
2700 #define HDSP_LINE_OUT(xname, xindex) \
2701 { .iface = SNDRV_CTL_ELEM_IFACE_HWDEP, \
2704 .info = snd_hdsp_info_line_out, \
2705 .get = snd_hdsp_get_line_out, \
2706 .put = snd_hdsp_put_line_out \
2709 static int hdsp_line_out(hdsp_t *hdsp)
2711 return (hdsp->control_register & HDSP_LineOut) ? 1 : 0;
2714 static int hdsp_set_line_output(hdsp_t *hdsp, int out)
2717 hdsp->control_register |= HDSP_LineOut;
2719 hdsp->control_register &= ~HDSP_LineOut;
2721 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
2725 static int snd_hdsp_info_line_out(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
2727 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
2729 uinfo->value.integer.min = 0;
2730 uinfo->value.integer.max = 1;
2734 static int snd_hdsp_get_line_out(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
2736 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
2738 spin_lock_irq(&hdsp->lock);
2739 ucontrol->value.integer.value[0] = hdsp_line_out(hdsp);
2740 spin_unlock_irq(&hdsp->lock);
2744 static int snd_hdsp_put_line_out(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
2746 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
2750 if (!snd_hdsp_use_is_exclusive(hdsp))
2752 val = ucontrol->value.integer.value[0] & 1;
2753 spin_lock_irq(&hdsp->lock);
2754 change = (int)val != hdsp_line_out(hdsp);
2755 hdsp_set_line_output(hdsp, val);
2756 spin_unlock_irq(&hdsp->lock);
2760 #define HDSP_PRECISE_POINTER(xname, xindex) \
2761 { .iface = SNDRV_CTL_ELEM_IFACE_HWDEP, \
2764 .info = snd_hdsp_info_precise_pointer, \
2765 .get = snd_hdsp_get_precise_pointer, \
2766 .put = snd_hdsp_put_precise_pointer \
2769 static int hdsp_set_precise_pointer(hdsp_t *hdsp, int precise)
2772 hdsp->precise_ptr = 1;
2774 hdsp->precise_ptr = 0;
2779 static int snd_hdsp_info_precise_pointer(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
2781 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
2783 uinfo->value.integer.min = 0;
2784 uinfo->value.integer.max = 1;
2788 static int snd_hdsp_get_precise_pointer(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
2790 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
2792 spin_lock_irq(&hdsp->lock);
2793 ucontrol->value.integer.value[0] = hdsp->precise_ptr;
2794 spin_unlock_irq(&hdsp->lock);
2798 static int snd_hdsp_put_precise_pointer(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
2800 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
2804 if (!snd_hdsp_use_is_exclusive(hdsp))
2806 val = ucontrol->value.integer.value[0] & 1;
2807 spin_lock_irq(&hdsp->lock);
2808 change = (int)val != hdsp->precise_ptr;
2809 hdsp_set_precise_pointer(hdsp, val);
2810 spin_unlock_irq(&hdsp->lock);
2814 #define HDSP_USE_MIDI_TASKLET(xname, xindex) \
2815 { .iface = SNDRV_CTL_ELEM_IFACE_HWDEP, \
2818 .info = snd_hdsp_info_use_midi_tasklet, \
2819 .get = snd_hdsp_get_use_midi_tasklet, \
2820 .put = snd_hdsp_put_use_midi_tasklet \
2823 static int hdsp_set_use_midi_tasklet(hdsp_t *hdsp, int use_tasklet)
2826 hdsp->use_midi_tasklet = 1;
2828 hdsp->use_midi_tasklet = 0;
2833 static int snd_hdsp_info_use_midi_tasklet(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
2835 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
2837 uinfo->value.integer.min = 0;
2838 uinfo->value.integer.max = 1;
2842 static int snd_hdsp_get_use_midi_tasklet(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
2844 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
2846 spin_lock_irq(&hdsp->lock);
2847 ucontrol->value.integer.value[0] = hdsp->use_midi_tasklet;
2848 spin_unlock_irq(&hdsp->lock);
2852 static int snd_hdsp_put_use_midi_tasklet(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
2854 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
2858 if (!snd_hdsp_use_is_exclusive(hdsp))
2860 val = ucontrol->value.integer.value[0] & 1;
2861 spin_lock_irq(&hdsp->lock);
2862 change = (int)val != hdsp->use_midi_tasklet;
2863 hdsp_set_use_midi_tasklet(hdsp, val);
2864 spin_unlock_irq(&hdsp->lock);
2868 #define HDSP_MIXER(xname, xindex) \
2869 { .iface = SNDRV_CTL_ELEM_IFACE_HWDEP, \
2872 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | \
2873 SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
2874 .info = snd_hdsp_info_mixer, \
2875 .get = snd_hdsp_get_mixer, \
2876 .put = snd_hdsp_put_mixer \
2879 static int snd_hdsp_info_mixer(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
2881 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
2883 uinfo->value.integer.min = 0;
2884 uinfo->value.integer.max = 65536;
2885 uinfo->value.integer.step = 1;
2889 static int snd_hdsp_get_mixer(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
2891 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
2896 source = ucontrol->value.integer.value[0];
2897 destination = ucontrol->value.integer.value[1];
2899 if (source >= hdsp->max_channels) {
2900 addr = hdsp_playback_to_output_key(hdsp,source-hdsp->max_channels,destination);
2902 addr = hdsp_input_to_output_key(hdsp,source, destination);
2905 spin_lock_irq(&hdsp->lock);
2906 ucontrol->value.integer.value[2] = hdsp_read_gain (hdsp, addr);
2907 spin_unlock_irq(&hdsp->lock);
2911 static int snd_hdsp_put_mixer(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
2913 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
2920 if (!snd_hdsp_use_is_exclusive(hdsp))
2923 source = ucontrol->value.integer.value[0];
2924 destination = ucontrol->value.integer.value[1];
2926 if (source >= hdsp->max_channels) {
2927 addr = hdsp_playback_to_output_key(hdsp,source-hdsp->max_channels, destination);
2929 addr = hdsp_input_to_output_key(hdsp,source, destination);
2932 gain = ucontrol->value.integer.value[2];
2934 spin_lock_irq(&hdsp->lock);
2935 change = gain != hdsp_read_gain(hdsp, addr);
2937 hdsp_write_gain(hdsp, addr, gain);
2938 spin_unlock_irq(&hdsp->lock);
2942 #define HDSP_WC_SYNC_CHECK(xname, xindex) \
2943 { .iface = SNDRV_CTL_ELEM_IFACE_HWDEP, \
2946 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
2947 .info = snd_hdsp_info_sync_check, \
2948 .get = snd_hdsp_get_wc_sync_check \
2951 static int snd_hdsp_info_sync_check(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
2953 static char *texts[] = {"No Lock", "Lock", "Sync" };
2954 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2956 uinfo->value.enumerated.items = 3;
2957 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
2958 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
2959 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
2963 static int hdsp_wc_sync_check(hdsp_t *hdsp)
2965 int status2 = hdsp_read(hdsp, HDSP_status2Register);
2966 if (status2 & HDSP_wc_lock) {
2967 if (status2 & HDSP_wc_sync) {
2978 static int snd_hdsp_get_wc_sync_check(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
2980 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
2982 ucontrol->value.enumerated.item[0] = hdsp_wc_sync_check(hdsp);
2986 #define HDSP_SPDIF_SYNC_CHECK(xname, xindex) \
2987 { .iface = SNDRV_CTL_ELEM_IFACE_HWDEP, \
2990 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
2991 .info = snd_hdsp_info_sync_check, \
2992 .get = snd_hdsp_get_spdif_sync_check \
2995 static int hdsp_spdif_sync_check(hdsp_t *hdsp)
2997 int status = hdsp_read(hdsp, HDSP_statusRegister);
2998 if (status & HDSP_SPDIFErrorFlag) {
3001 if (status & HDSP_SPDIFSync) {
3010 static int snd_hdsp_get_spdif_sync_check(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
3012 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
3014 ucontrol->value.enumerated.item[0] = hdsp_spdif_sync_check(hdsp);
3018 #define HDSP_ADATSYNC_SYNC_CHECK(xname, xindex) \
3019 { .iface = SNDRV_CTL_ELEM_IFACE_HWDEP, \
3022 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
3023 .info = snd_hdsp_info_sync_check, \
3024 .get = snd_hdsp_get_adatsync_sync_check \
3027 static int hdsp_adatsync_sync_check(hdsp_t *hdsp)
3029 int status = hdsp_read(hdsp, HDSP_statusRegister);
3030 if (status & HDSP_TimecodeLock) {
3031 if (status & HDSP_TimecodeSync) {
3041 static int snd_hdsp_get_adatsync_sync_check(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
3043 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
3045 ucontrol->value.enumerated.item[0] = hdsp_adatsync_sync_check(hdsp);
3049 #define HDSP_ADAT_SYNC_CHECK \
3050 { .iface = SNDRV_CTL_ELEM_IFACE_HWDEP, \
3051 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
3052 .info = snd_hdsp_info_sync_check, \
3053 .get = snd_hdsp_get_adat_sync_check \
3056 static int hdsp_adat_sync_check(hdsp_t *hdsp, int idx)
3058 int status = hdsp_read(hdsp, HDSP_statusRegister);
3060 if (status & (HDSP_Lock0>>idx)) {
3061 if (status & (HDSP_Sync0>>idx)) {
3071 static int snd_hdsp_get_adat_sync_check(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
3074 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
3076 offset = ucontrol->id.index - 1;
3077 snd_assert(offset >= 0);
3079 switch (hdsp->io_type) {
3094 ucontrol->value.enumerated.item[0] = hdsp_adat_sync_check(hdsp, offset);
3098 static snd_kcontrol_new_t snd_hdsp_9632_controls[] = {
3099 HDSP_DA_GAIN("DA Gain", 0),
3100 HDSP_AD_GAIN("AD Gain", 0),
3101 HDSP_PHONE_GAIN("Phones Gain", 0),
3102 HDSP_XLR_BREAKOUT_CABLE("XLR Breakout Cable", 0)
3105 static snd_kcontrol_new_t snd_hdsp_controls[] = {
3107 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
3108 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,DEFAULT),
3109 .info = snd_hdsp_control_spdif_info,
3110 .get = snd_hdsp_control_spdif_get,
3111 .put = snd_hdsp_control_spdif_put,
3114 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_INACTIVE,
3115 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
3116 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,PCM_STREAM),
3117 .info = snd_hdsp_control_spdif_stream_info,
3118 .get = snd_hdsp_control_spdif_stream_get,
3119 .put = snd_hdsp_control_spdif_stream_put,
3122 .access = SNDRV_CTL_ELEM_ACCESS_READ,
3123 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3124 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,CON_MASK),
3125 .info = snd_hdsp_control_spdif_mask_info,
3126 .get = snd_hdsp_control_spdif_mask_get,
3127 .private_value = IEC958_AES0_NONAUDIO |
3128 IEC958_AES0_PROFESSIONAL |
3129 IEC958_AES0_CON_EMPHASIS,
3132 .access = SNDRV_CTL_ELEM_ACCESS_READ,
3133 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3134 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,PRO_MASK),
3135 .info = snd_hdsp_control_spdif_mask_info,
3136 .get = snd_hdsp_control_spdif_mask_get,
3137 .private_value = IEC958_AES0_NONAUDIO |
3138 IEC958_AES0_PROFESSIONAL |
3139 IEC958_AES0_PRO_EMPHASIS,
3141 HDSP_MIXER("Mixer", 0),
3142 HDSP_SPDIF_IN("IEC958 Input Connector", 0),
3143 HDSP_SPDIF_OUT("IEC958 Output also on ADAT1", 0),
3144 HDSP_SPDIF_PROFESSIONAL("IEC958 Professional Bit", 0),
3145 HDSP_SPDIF_EMPHASIS("IEC958 Emphasis Bit", 0),
3146 HDSP_SPDIF_NON_AUDIO("IEC958 Non-audio Bit", 0),
3147 /* 'Sample Clock Source' complies with the alsa control naming scheme */
3148 HDSP_CLOCK_SOURCE("Sample Clock Source", 0),
3150 /* FIXME: should be PCM or MIXER? */
3151 /* .iface = SNDRV_CTL_ELEM_IFACE_PCM, */
3152 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3153 .name = "Sample Clock Source Locking",
3154 .info = snd_hdsp_info_clock_source_lock,
3155 .get = snd_hdsp_get_clock_source_lock,
3156 .put = snd_hdsp_put_clock_source_lock,
3158 HDSP_SYSTEM_CLOCK_MODE("System Clock Mode", 0),
3159 HDSP_PREF_SYNC_REF("Preferred Sync Reference", 0),
3160 HDSP_AUTOSYNC_REF("AutoSync Reference", 0),
3161 HDSP_SPDIF_SAMPLE_RATE("SPDIF Sample Rate", 0),
3162 HDSP_SYSTEM_SAMPLE_RATE("System Sample Rate", 0),
3163 /* 'External Rate' complies with the alsa control naming scheme */
3164 HDSP_AUTOSYNC_SAMPLE_RATE("External Rate", 0),
3165 HDSP_WC_SYNC_CHECK("Word Clock Lock Status", 0),
3166 HDSP_SPDIF_SYNC_CHECK("SPDIF Lock Status", 0),
3167 HDSP_ADATSYNC_SYNC_CHECK("ADAT Sync Lock Status", 0),
3168 HDSP_LINE_OUT("Line Out", 0),
3169 HDSP_PRECISE_POINTER("Precise Pointer", 0),
3170 HDSP_USE_MIDI_TASKLET("Use Midi Tasklet", 0),
3173 static snd_kcontrol_new_t snd_hdsp_96xx_aeb = HDSP_AEB("Analog Extension Board", 0);
3174 static snd_kcontrol_new_t snd_hdsp_adat_sync_check = HDSP_ADAT_SYNC_CHECK;
3176 static int snd_hdsp_create_controls(snd_card_t *card, hdsp_t *hdsp)
3180 snd_kcontrol_t *kctl;
3182 for (idx = 0; idx < ARRAY_SIZE(snd_hdsp_controls); idx++) {
3183 if ((err = snd_ctl_add(card, kctl = snd_ctl_new1(&snd_hdsp_controls[idx], hdsp))) < 0) {
3186 if (idx == 1) /* IEC958 (S/PDIF) Stream */
3187 hdsp->spdif_ctl = kctl;
3190 /* ADAT SyncCheck status */
3191 snd_hdsp_adat_sync_check.name = "ADAT Lock Status";
3192 snd_hdsp_adat_sync_check.index = 1;
3193 if ((err = snd_ctl_add (card, kctl = snd_ctl_new1(&snd_hdsp_adat_sync_check, hdsp)))) {
3196 if (hdsp->io_type == Digiface || hdsp->io_type == H9652) {
3197 for (idx = 1; idx < 3; ++idx) {
3198 snd_hdsp_adat_sync_check.index = idx+1;
3199 if ((err = snd_ctl_add (card, kctl = snd_ctl_new1(&snd_hdsp_adat_sync_check, hdsp)))) {
3205 /* DA, AD and Phone gain and XLR breakout cable controls for H9632 cards */
3206 if (hdsp->io_type == H9632) {
3207 for (idx = 0; idx < ARRAY_SIZE(snd_hdsp_9632_controls); idx++) {
3208 if ((err = snd_ctl_add(card, kctl = snd_ctl_new1(&snd_hdsp_9632_controls[idx], hdsp))) < 0) {
3214 /* AEB control for H96xx card */
3215 if (hdsp->io_type == H9632 || hdsp->io_type == H9652) {
3216 if ((err = snd_ctl_add(card, kctl = snd_ctl_new1(&snd_hdsp_96xx_aeb, hdsp))) < 0) {
3224 /*------------------------------------------------------------
3226 ------------------------------------------------------------*/
3229 snd_hdsp_proc_read(snd_info_entry_t *entry, snd_info_buffer_t *buffer)
3231 hdsp_t *hdsp = (hdsp_t *) entry->private_data;
3232 unsigned int status;
3233 unsigned int status2;
3234 char *pref_sync_ref;
3236 char *system_clock_mode;
3240 if (hdsp_check_for_iobox (hdsp)) {
3241 snd_iprintf(buffer, "No I/O box connected.\nPlease connect one and upload firmware.\n");
3245 if (hdsp_check_for_firmware(hdsp)) {
3246 if (hdsp->state & HDSP_FirmwareCached) {
3247 if (snd_hdsp_load_firmware_from_cache(hdsp) != 0) {
3248 snd_iprintf(buffer, "Firmware loading from cache failed, please upload manually.\n");
3252 snd_iprintf(buffer, "No firmware loaded nor cached, please upload firmware.\n");
3257 status = hdsp_read(hdsp, HDSP_statusRegister);
3258 status2 = hdsp_read(hdsp, HDSP_status2Register);
3260 snd_iprintf(buffer, "%s (Card #%d)\n", hdsp->card_name, hdsp->card->number + 1);
3261 snd_iprintf(buffer, "Buffers: capture %p playback %p\n",
3262 hdsp->capture_buffer, hdsp->playback_buffer);
3263 snd_iprintf(buffer, "IRQ: %d Registers bus: 0x%lx VM: 0x%lx\n",
3264 hdsp->irq, hdsp->port, (unsigned long)hdsp->iobase);
3265 snd_iprintf(buffer, "Control register: 0x%x\n", hdsp->control_register);
3266 snd_iprintf(buffer, "Control2 register: 0x%x\n", hdsp->control2_register);
3267 snd_iprintf(buffer, "Status register: 0x%x\n", status);
3268 snd_iprintf(buffer, "Status2 register: 0x%x\n", status2);
3269 snd_iprintf(buffer, "FIFO status: %d\n", hdsp_read(hdsp, HDSP_fifoStatus) & 0xff);
3270 snd_iprintf(buffer, "MIDI1 Output status: 0x%x\n", hdsp_read(hdsp, HDSP_midiStatusOut0));
3271 snd_iprintf(buffer, "MIDI1 Input status: 0x%x\n", hdsp_read(hdsp, HDSP_midiStatusIn0));
3272 snd_iprintf(buffer, "MIDI2 Output status: 0x%x\n", hdsp_read(hdsp, HDSP_midiStatusOut1));
3273 snd_iprintf(buffer, "MIDI2 Input status: 0x%x\n", hdsp_read(hdsp, HDSP_midiStatusIn1));
3274 snd_iprintf(buffer, "Use Midi Tasklet: %s\n", hdsp->use_midi_tasklet ? "on" : "off");
3276 snd_iprintf(buffer, "\n");
3278 x = 1 << (6 + hdsp_decode_latency(hdsp->control_register & HDSP_LatencyMask));
3280 snd_iprintf(buffer, "Buffer Size (Latency): %d samples (2 periods of %lu bytes)\n", x, (unsigned long) hdsp->period_bytes);
3281 snd_iprintf(buffer, "Hardware pointer (frames): %ld\n", hdsp_hw_pointer(hdsp));
3282 snd_iprintf(buffer, "Precise pointer: %s\n", hdsp->precise_ptr ? "on" : "off");
3283 snd_iprintf(buffer, "Line out: %s\n", (hdsp->control_register & HDSP_LineOut) ? "on" : "off");
3285 snd_iprintf(buffer, "Firmware version: %d\n", (status2&HDSP_version0)|(status2&HDSP_version1)<<1|(status2&HDSP_version2)<<2);
3287 snd_iprintf(buffer, "\n");
3290 switch (hdsp_clock_source(hdsp)) {
3291 case HDSP_CLOCK_SOURCE_AUTOSYNC:
3292 clock_source = "AutoSync";
3294 case HDSP_CLOCK_SOURCE_INTERNAL_32KHZ:
3295 clock_source = "Internal 32 kHz";
3297 case HDSP_CLOCK_SOURCE_INTERNAL_44_1KHZ:
3298 clock_source = "Internal 44.1 kHz";
3300 case HDSP_CLOCK_SOURCE_INTERNAL_48KHZ:
3301 clock_source = "Internal 48 kHz";
3303 case HDSP_CLOCK_SOURCE_INTERNAL_64KHZ:
3304 clock_source = "Internal 64 kHz";
3306 case HDSP_CLOCK_SOURCE_INTERNAL_88_2KHZ:
3307 clock_source = "Internal 88.2 kHz";
3309 case HDSP_CLOCK_SOURCE_INTERNAL_96KHZ:
3310 clock_source = "Internal 96 kHz";
3312 case HDSP_CLOCK_SOURCE_INTERNAL_128KHZ:
3313 clock_source = "Internal 128 kHz";
3315 case HDSP_CLOCK_SOURCE_INTERNAL_176_4KHZ:
3316 clock_source = "Internal 176.4 kHz";
3318 case HDSP_CLOCK_SOURCE_INTERNAL_192KHZ:
3319 clock_source = "Internal 192 kHz";
3322 clock_source = "Error";
3324 snd_iprintf (buffer, "Sample Clock Source: %s\n", clock_source);
3326 if (hdsp_system_clock_mode(hdsp)) {
3327 system_clock_mode = "Slave";
3329 system_clock_mode = "Master";
3332 switch (hdsp_pref_sync_ref (hdsp)) {
3333 case HDSP_SYNC_FROM_WORD:
3334 pref_sync_ref = "Word Clock";
3336 case HDSP_SYNC_FROM_ADAT_SYNC:
3337 pref_sync_ref = "ADAT Sync";
3339 case HDSP_SYNC_FROM_SPDIF:
3340 pref_sync_ref = "SPDIF";
3342 case HDSP_SYNC_FROM_ADAT1:
3343 pref_sync_ref = "ADAT1";
3345 case HDSP_SYNC_FROM_ADAT2:
3346 pref_sync_ref = "ADAT2";
3348 case HDSP_SYNC_FROM_ADAT3:
3349 pref_sync_ref = "ADAT3";
3352 pref_sync_ref = "Word Clock";
3355 snd_iprintf (buffer, "Preferred Sync Reference: %s\n", pref_sync_ref);
3357 switch (hdsp_autosync_ref (hdsp)) {
3358 case HDSP_AUTOSYNC_FROM_WORD:
3359 autosync_ref = "Word Clock";
3361 case HDSP_AUTOSYNC_FROM_ADAT_SYNC:
3362 autosync_ref = "ADAT Sync";
3364 case HDSP_AUTOSYNC_FROM_SPDIF:
3365 autosync_ref = "SPDIF";
3367 case HDSP_AUTOSYNC_FROM_NONE:
3368 autosync_ref = "None";
3370 case HDSP_AUTOSYNC_FROM_ADAT1:
3371 autosync_ref = "ADAT1";
3373 case HDSP_AUTOSYNC_FROM_ADAT2:
3374 autosync_ref = "ADAT2";
3376 case HDSP_AUTOSYNC_FROM_ADAT3:
3377 autosync_ref = "ADAT3";
3380 autosync_ref = "---";
3383 snd_iprintf (buffer, "AutoSync Reference: %s\n", autosync_ref);
3385 snd_iprintf (buffer, "AutoSync Frequency: %d\n", hdsp_external_sample_rate(hdsp));
3387 snd_iprintf (buffer, "System Clock Mode: %s\n", system_clock_mode);
3389 snd_iprintf (buffer, "System Clock Frequency: %d\n", hdsp->system_sample_rate);
3390 snd_iprintf (buffer, "System Clock Locked: %s\n", hdsp->clock_source_locked ? "Yes" : "No");
3392 snd_iprintf(buffer, "\n");
3394 switch (hdsp_spdif_in(hdsp)) {
3395 case HDSP_SPDIFIN_OPTICAL:
3396 snd_iprintf(buffer, "IEC958 input: Optical\n");
3398 case HDSP_SPDIFIN_COAXIAL:
3399 snd_iprintf(buffer, "IEC958 input: Coaxial\n");
3401 case HDSP_SPDIFIN_INTERNAL:
3402 snd_iprintf(buffer, "IEC958 input: Internal\n");
3404 case HDSP_SPDIFIN_AES:
3405 snd_iprintf(buffer, "IEC958 input: AES\n");
3408 snd_iprintf(buffer, "IEC958 input: ???\n");
3412 if (hdsp->control_register & HDSP_SPDIFOpticalOut) {
3413 snd_iprintf(buffer, "IEC958 output: Coaxial & ADAT1\n");
3415 snd_iprintf(buffer, "IEC958 output: Coaxial only\n");
3418 if (hdsp->control_register & HDSP_SPDIFProfessional) {
3419 snd_iprintf(buffer, "IEC958 quality: Professional\n");
3421 snd_iprintf(buffer, "IEC958 quality: Consumer\n");
3424 if (hdsp->control_register & HDSP_SPDIFEmphasis) {
3425 snd_iprintf(buffer, "IEC958 emphasis: on\n");
3427 snd_iprintf(buffer, "IEC958 emphasis: off\n");
3430 if (hdsp->control_register & HDSP_SPDIFNonAudio) {
3431 snd_iprintf(buffer, "IEC958 NonAudio: on\n");
3433 snd_iprintf(buffer, "IEC958 NonAudio: off\n");
3435 if ((x = hdsp_spdif_sample_rate (hdsp)) != 0) {
3436 snd_iprintf (buffer, "IEC958 sample rate: %d\n", x);
3438 snd_iprintf (buffer, "IEC958 sample rate: Error flag set\n");
3441 snd_iprintf(buffer, "\n");
3444 x = status & HDSP_Sync0;
3445 if (status & HDSP_Lock0) {
3446 snd_iprintf(buffer, "ADAT1: %s\n", x ? "Sync" : "Lock");
3448 snd_iprintf(buffer, "ADAT1: No Lock\n");
3451 switch (hdsp->io_type) {
3454 x = status & HDSP_Sync1;
3455 if (status & HDSP_Lock1) {
3456 snd_iprintf(buffer, "ADAT2: %s\n", x ? "Sync" : "Lock");
3458 snd_iprintf(buffer, "ADAT2: No Lock\n");
3460 x = status & HDSP_Sync2;
3461 if (status & HDSP_Lock2) {
3462 snd_iprintf(buffer, "ADAT3: %s\n", x ? "Sync" : "Lock");
3464 snd_iprintf(buffer, "ADAT3: No Lock\n");
3471 x = status & HDSP_SPDIFSync;
3472 if (status & HDSP_SPDIFErrorFlag) {
3473 snd_iprintf (buffer, "SPDIF: No Lock\n");
3475 snd_iprintf (buffer, "SPDIF: %s\n", x ? "Sync" : "Lock");
3478 x = status2 & HDSP_wc_sync;
3479 if (status2 & HDSP_wc_lock) {
3480 snd_iprintf (buffer, "Word Clock: %s\n", x ? "Sync" : "Lock");
3482 snd_iprintf (buffer, "Word Clock: No Lock\n");
3485 x = status & HDSP_TimecodeSync;
3486 if (status & HDSP_TimecodeLock) {
3487 snd_iprintf(buffer, "ADAT Sync: %s\n", x ? "Sync" : "Lock");
3489 snd_iprintf(buffer, "ADAT Sync: No Lock\n");
3492 snd_iprintf(buffer, "\n");
3494 /* Informations about H9632 specific controls */
3495 if (hdsp->io_type == H9632) {
3498 switch (hdsp_ad_gain(hdsp)) {
3509 snd_iprintf(buffer, "AD Gain : %s\n", tmp);
3511 switch (hdsp_da_gain(hdsp)) {
3522 snd_iprintf(buffer, "DA Gain : %s\n", tmp);
3524 switch (hdsp_phone_gain(hdsp)) {
3535 snd_iprintf(buffer, "Phones Gain : %s\n", tmp);
3537 snd_iprintf(buffer, "XLR Breakout Cable : %s\n", hdsp_xlr_breakout_cable(hdsp) ? "yes" : "no");
3539 if (hdsp->control_register & HDSP_AnalogExtensionBoard) {
3540 snd_iprintf(buffer, "AEB : on (ADAT1 internal)\n");
3542 snd_iprintf(buffer, "AEB : off (ADAT1 external)\n");
3544 snd_iprintf(buffer, "\n");
3549 static void __devinit snd_hdsp_proc_init(hdsp_t *hdsp)
3551 snd_info_entry_t *entry;
3553 if (! snd_card_proc_new(hdsp->card, "hdsp", &entry))
3554 snd_info_set_text_ops(entry, hdsp, 1024, snd_hdsp_proc_read);
3557 static void snd_hdsp_free_buffers(hdsp_t *hdsp)
3559 snd_hammerfall_free_buffer(&hdsp->capture_dma_buf, hdsp->pci);
3560 snd_hammerfall_free_buffer(&hdsp->playback_dma_buf, hdsp->pci);
3563 static int __devinit snd_hdsp_initialize_memory(hdsp_t *hdsp)
3565 unsigned long pb_bus, cb_bus;
3567 if (snd_hammerfall_get_buffer(hdsp->pci, &hdsp->capture_dma_buf, HDSP_DMA_AREA_BYTES) < 0 ||
3568 snd_hammerfall_get_buffer(hdsp->pci, &hdsp->playback_dma_buf, HDSP_DMA_AREA_BYTES) < 0) {
3569 if (hdsp->capture_dma_buf.area)
3570 snd_dma_free_pages(&hdsp->capture_dma_buf);
3571 printk(KERN_ERR "%s: no buffers available\n", hdsp->card_name);
3575 /* Align to bus-space 64K boundary */
3577 cb_bus = (hdsp->capture_dma_buf.addr + 0xFFFF) & ~0xFFFFl;
3578 pb_bus = (hdsp->playback_dma_buf.addr + 0xFFFF) & ~0xFFFFl;
3580 /* Tell the card where it is */
3582 hdsp_write(hdsp, HDSP_inputBufferAddress, cb_bus);
3583 hdsp_write(hdsp, HDSP_outputBufferAddress, pb_bus);
3585 hdsp->capture_buffer = hdsp->capture_dma_buf.area + (cb_bus - hdsp->capture_dma_buf.addr);
3586 hdsp->playback_buffer = hdsp->playback_dma_buf.area + (pb_bus - hdsp->playback_dma_buf.addr);
3591 static int snd_hdsp_set_defaults(hdsp_t *hdsp)
3595 /* ASSUMPTION: hdsp->lock is either held, or
3596 there is no need to hold it (e.g. during module
3602 SPDIF Input via Coax
3604 maximum latency (7 => 2^7 = 8192 samples, 64Kbyte buffer,
3605 which implies 2 4096 sample, 32Kbyte periods).
3609 hdsp->control_register = HDSP_ClockModeMaster |
3610 HDSP_SPDIFInputCoaxial |
3611 hdsp_encode_latency(7) |
3615 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
3617 #ifdef SNDRV_BIG_ENDIAN
3618 hdsp->control2_register = HDSP_BIGENDIAN_MODE;
3620 hdsp->control2_register = 0;
3622 if (hdsp->io_type == H9652) {
3623 snd_hdsp_9652_enable_mixer (hdsp);
3625 hdsp_write (hdsp, HDSP_control2Reg, hdsp->control2_register);
3628 hdsp_reset_hw_pointer(hdsp);
3629 hdsp_compute_period_size(hdsp);
3631 /* silence everything */
3633 for (i = 0; i < HDSP_MATRIX_MIXER_SIZE; ++i) {
3634 hdsp->mixer_matrix[i] = MINUS_INFINITY_GAIN;
3637 for (i = 0; i < ((hdsp->io_type == H9652 || hdsp->io_type == H9632) ? 1352 : HDSP_MATRIX_MIXER_SIZE); ++i) {
3638 if (hdsp_write_gain (hdsp, i, MINUS_INFINITY_GAIN)) {
3643 /* H9632 specific defaults */
3644 if (hdsp->io_type == H9632) {
3645 hdsp->control_register |= (HDSP_DAGainPlus4dBu | HDSP_ADGainPlus4dBu | HDSP_PhoneGain0dB);
3646 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
3649 /* set a default rate so that the channel map is set up.
3652 hdsp_set_rate(hdsp, 48000, 1);
3657 static void hdsp_midi_tasklet(unsigned long arg)
3659 hdsp_t *hdsp = (hdsp_t *)arg;
3661 if (hdsp->midi[0].pending) {
3662 snd_hdsp_midi_input_read (&hdsp->midi[0]);
3664 if (hdsp->midi[1].pending) {
3665 snd_hdsp_midi_input_read (&hdsp->midi[1]);
3669 static irqreturn_t snd_hdsp_interrupt(int irq, void *dev_id, struct pt_regs *regs)
3671 hdsp_t *hdsp = (hdsp_t *) dev_id;
3672 unsigned int status;
3676 unsigned int midi0status;
3677 unsigned int midi1status;
3680 status = hdsp_read(hdsp, HDSP_statusRegister);
3682 audio = status & HDSP_audioIRQPending;
3683 midi0 = status & HDSP_midi0IRQPending;
3684 midi1 = status & HDSP_midi1IRQPending;
3686 if (!audio && !midi0 && !midi1) {
3690 hdsp_write(hdsp, HDSP_interruptConfirmation, 0);
3692 midi0status = hdsp_read (hdsp, HDSP_midiStatusIn0) & 0xff;
3693 midi1status = hdsp_read (hdsp, HDSP_midiStatusIn1) & 0xff;
3696 if (hdsp->capture_substream) {
3697 snd_pcm_period_elapsed(hdsp->pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream);
3700 if (hdsp->playback_substream) {
3701 snd_pcm_period_elapsed(hdsp->pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream);
3705 if (midi0 && midi0status) {
3706 if (hdsp->use_midi_tasklet) {
3707 /* we disable interrupts for this input until processing is done */
3708 hdsp->control_register &= ~HDSP_Midi0InterruptEnable;
3709 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
3710 hdsp->midi[0].pending = 1;
3713 snd_hdsp_midi_input_read (&hdsp->midi[0]);
3716 if (hdsp->io_type != Multiface && hdsp->io_type != H9632 && midi1 && midi1status) {
3717 if (hdsp->use_midi_tasklet) {
3718 /* we disable interrupts for this input until processing is done */
3719 hdsp->control_register &= ~HDSP_Midi1InterruptEnable;
3720 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
3721 hdsp->midi[1].pending = 1;
3724 snd_hdsp_midi_input_read (&hdsp->midi[1]);
3727 if (hdsp->use_midi_tasklet && schedule)
3728 tasklet_hi_schedule(&hdsp->midi_tasklet);
3732 static snd_pcm_uframes_t snd_hdsp_hw_pointer(snd_pcm_substream_t *substream)
3734 hdsp_t *hdsp = snd_pcm_substream_chip(substream);
3735 return hdsp_hw_pointer(hdsp);
3738 static char *hdsp_channel_buffer_location(hdsp_t *hdsp,
3745 snd_assert(channel >= 0 && channel < hdsp->max_channels, return NULL);
3747 if ((mapped_channel = hdsp->channel_map[channel]) < 0) {
3751 if (stream == SNDRV_PCM_STREAM_CAPTURE) {
3752 return hdsp->capture_buffer + (mapped_channel * HDSP_CHANNEL_BUFFER_BYTES);
3754 return hdsp->playback_buffer + (mapped_channel * HDSP_CHANNEL_BUFFER_BYTES);
3758 static int snd_hdsp_playback_copy(snd_pcm_substream_t *substream, int channel,
3759 snd_pcm_uframes_t pos, void __user *src, snd_pcm_uframes_t count)
3761 hdsp_t *hdsp = snd_pcm_substream_chip(substream);
3764 snd_assert(pos + count <= HDSP_CHANNEL_BUFFER_BYTES / 4, return -EINVAL);
3766 channel_buf = hdsp_channel_buffer_location (hdsp, substream->pstr->stream, channel);
3767 snd_assert(channel_buf != NULL, return -EIO);
3768 if (copy_from_user(channel_buf + pos * 4, src, count * 4))
3773 static int snd_hdsp_capture_copy(snd_pcm_substream_t *substream, int channel,
3774 snd_pcm_uframes_t pos, void __user *dst, snd_pcm_uframes_t count)
3776 hdsp_t *hdsp = snd_pcm_substream_chip(substream);
3779 snd_assert(pos + count <= HDSP_CHANNEL_BUFFER_BYTES / 4, return -EINVAL);
3781 channel_buf = hdsp_channel_buffer_location (hdsp, substream->pstr->stream, channel);
3782 snd_assert(channel_buf != NULL, return -EIO);
3783 if (copy_to_user(dst, channel_buf + pos * 4, count * 4))
3788 static int snd_hdsp_hw_silence(snd_pcm_substream_t *substream, int channel,
3789 snd_pcm_uframes_t pos, snd_pcm_uframes_t count)
3791 hdsp_t *hdsp = snd_pcm_substream_chip(substream);
3794 channel_buf = hdsp_channel_buffer_location (hdsp, substream->pstr->stream, channel);
3795 snd_assert(channel_buf != NULL, return -EIO);
3796 memset(channel_buf + pos * 4, 0, count * 4);
3800 static int snd_hdsp_reset(snd_pcm_substream_t *substream)
3802 snd_pcm_runtime_t *runtime = substream->runtime;
3803 hdsp_t *hdsp = snd_pcm_substream_chip(substream);
3804 snd_pcm_substream_t *other;
3805 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
3806 other = hdsp->capture_substream;
3808 other = hdsp->playback_substream;
3810 runtime->status->hw_ptr = hdsp_hw_pointer(hdsp);
3812 runtime->status->hw_ptr = 0;
3814 struct list_head *pos;
3815 snd_pcm_substream_t *s;
3816 snd_pcm_runtime_t *oruntime = other->runtime;
3817 snd_pcm_group_for_each(pos, substream) {
3818 s = snd_pcm_group_substream_entry(pos);
3820 oruntime->status->hw_ptr = runtime->status->hw_ptr;
3828 static int snd_hdsp_hw_params(snd_pcm_substream_t *substream,
3829 snd_pcm_hw_params_t *params)
3831 hdsp_t *hdsp = snd_pcm_substream_chip(substream);
3836 if (hdsp_check_for_iobox (hdsp)) {
3840 if (hdsp_check_for_firmware(hdsp)) {
3841 if (hdsp->state & HDSP_FirmwareCached) {
3842 if (snd_hdsp_load_firmware_from_cache(hdsp) != 0) {
3843 snd_printk("Hammerfall-DSP: Firmware loading from cache failed, please upload manually.\n");
3846 snd_printk("Hammerfall-DSP: No firmware loaded nor cached, please upload firmware.\n");
3851 spin_lock_irq(&hdsp->lock);
3853 if (substream->pstr->stream == SNDRV_PCM_STREAM_PLAYBACK) {
3854 hdsp->control_register &= ~(HDSP_SPDIFProfessional | HDSP_SPDIFNonAudio | HDSP_SPDIFEmphasis);
3855 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register |= hdsp->creg_spdif_stream);
3856 this_pid = hdsp->playback_pid;
3857 other_pid = hdsp->capture_pid;
3859 this_pid = hdsp->capture_pid;
3860 other_pid = hdsp->playback_pid;
3863 if ((other_pid > 0) && (this_pid != other_pid)) {
3865 /* The other stream is open, and not by the same
3866 task as this one. Make sure that the parameters
3867 that matter are the same.
3870 if (params_rate(params) != hdsp->system_sample_rate) {
3871 spin_unlock_irq(&hdsp->lock);
3872 _snd_pcm_hw_param_setempty(params, SNDRV_PCM_HW_PARAM_RATE);
3876 if (params_period_size(params) != hdsp->period_bytes / 4) {
3877 spin_unlock_irq(&hdsp->lock);
3878 _snd_pcm_hw_param_setempty(params, SNDRV_PCM_HW_PARAM_PERIOD_SIZE);
3884 spin_unlock_irq(&hdsp->lock);
3888 spin_unlock_irq(&hdsp->lock);
3891 /* how to make sure that the rate matches an externally-set one ?
3894 spin_lock_irq(&hdsp->lock);
3895 if (! hdsp->clock_source_locked) {
3896 if ((err = hdsp_set_rate(hdsp, params_rate(params), 0)) < 0) {
3897 spin_unlock_irq(&hdsp->lock);
3898 _snd_pcm_hw_param_setempty(params, SNDRV_PCM_HW_PARAM_RATE);
3902 spin_unlock_irq(&hdsp->lock);
3904 if ((err = hdsp_set_interrupt_interval(hdsp, params_period_size(params))) < 0) {
3905 _snd_pcm_hw_param_setempty(params, SNDRV_PCM_HW_PARAM_PERIOD_SIZE);
3912 static int snd_hdsp_channel_info(snd_pcm_substream_t *substream,
3913 snd_pcm_channel_info_t *info)
3915 hdsp_t *hdsp = snd_pcm_substream_chip(substream);
3918 snd_assert(info->channel < hdsp->max_channels, return -EINVAL);
3920 if ((mapped_channel = hdsp->channel_map[info->channel]) < 0) {
3924 info->offset = mapped_channel * HDSP_CHANNEL_BUFFER_BYTES;
3930 static int snd_hdsp_ioctl(snd_pcm_substream_t *substream,
3931 unsigned int cmd, void *arg)
3934 case SNDRV_PCM_IOCTL1_RESET:
3936 return snd_hdsp_reset(substream);
3938 case SNDRV_PCM_IOCTL1_CHANNEL_INFO:
3940 snd_pcm_channel_info_t *info = arg;
3941 return snd_hdsp_channel_info(substream, info);
3947 return snd_pcm_lib_ioctl(substream, cmd, arg);
3950 static int snd_hdsp_trigger(snd_pcm_substream_t *substream, int cmd)
3952 hdsp_t *hdsp = snd_pcm_substream_chip(substream);
3953 snd_pcm_substream_t *other;
3956 if (hdsp_check_for_iobox (hdsp)) {
3960 if (hdsp_check_for_firmware(hdsp)) {
3961 if (hdsp->state & HDSP_FirmwareCached) {
3962 if (snd_hdsp_load_firmware_from_cache(hdsp) != 0) {
3963 snd_printk("Hammerfall-DSP: Firmware loading from cache failed, please upload manually.\n");
3966 snd_printk("Hammerfall-DSP: No firmware loaded nor cached, please upload firmware.\n");
3971 spin_lock(&hdsp->lock);
3972 running = hdsp->running;
3974 case SNDRV_PCM_TRIGGER_START:
3975 running |= 1 << substream->stream;
3977 case SNDRV_PCM_TRIGGER_STOP:
3978 running &= ~(1 << substream->stream);
3982 spin_unlock(&hdsp->lock);
3985 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
3986 other = hdsp->capture_substream;
3988 other = hdsp->playback_substream;
3991 struct list_head *pos;
3992 snd_pcm_substream_t *s;
3993 snd_pcm_group_for_each(pos, substream) {
3994 s = snd_pcm_group_substream_entry(pos);
3996 snd_pcm_trigger_done(s, substream);
3997 if (cmd == SNDRV_PCM_TRIGGER_START)
3998 running |= 1 << s->stream;
4000 running &= ~(1 << s->stream);
4004 if (cmd == SNDRV_PCM_TRIGGER_START) {
4005 if (!(running & (1 << SNDRV_PCM_STREAM_PLAYBACK)) &&
4006 substream->stream == SNDRV_PCM_STREAM_CAPTURE)
4007 hdsp_silence_playback(hdsp);
4010 substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
4011 hdsp_silence_playback(hdsp);
4014 if (substream->stream == SNDRV_PCM_STREAM_CAPTURE)
4015 hdsp_silence_playback(hdsp);
4018 snd_pcm_trigger_done(substream, substream);
4019 if (!hdsp->running && running)
4020 hdsp_start_audio(hdsp);
4021 else if (hdsp->running && !running)
4022 hdsp_stop_audio(hdsp);
4023 hdsp->running = running;
4024 spin_unlock(&hdsp->lock);
4029 static int snd_hdsp_prepare(snd_pcm_substream_t *substream)
4031 hdsp_t *hdsp = snd_pcm_substream_chip(substream);
4034 if (hdsp_check_for_iobox (hdsp)) {
4038 if (hdsp_check_for_firmware(hdsp)) {
4039 if (hdsp->state & HDSP_FirmwareCached) {
4040 if (snd_hdsp_load_firmware_from_cache(hdsp) != 0) {
4041 snd_printk("Hammerfall-DSP: Firmware loading from cache failed, please upload manually.\n");
4044 snd_printk("Hammerfall-DSP: No firmware loaded nor cached, please upload firmware.\n");
4049 spin_lock_irq(&hdsp->lock);
4051 hdsp_reset_hw_pointer(hdsp);
4052 spin_unlock_irq(&hdsp->lock);
4056 static snd_pcm_hardware_t snd_hdsp_playback_subinfo =
4058 .info = (SNDRV_PCM_INFO_MMAP |
4059 SNDRV_PCM_INFO_MMAP_VALID |
4060 SNDRV_PCM_INFO_NONINTERLEAVED |
4061 SNDRV_PCM_INFO_SYNC_START |
4062 SNDRV_PCM_INFO_DOUBLE),
4063 #ifdef SNDRV_BIG_ENDIAN
4064 .formats = SNDRV_PCM_FMTBIT_S32_BE,
4066 .formats = SNDRV_PCM_FMTBIT_S32_LE,
4068 .rates = (SNDRV_PCM_RATE_32000 |
4069 SNDRV_PCM_RATE_44100 |
4070 SNDRV_PCM_RATE_48000 |
4071 SNDRV_PCM_RATE_64000 |
4072 SNDRV_PCM_RATE_88200 |
4073 SNDRV_PCM_RATE_96000),
4077 .channels_max = HDSP_MAX_CHANNELS,
4078 .buffer_bytes_max = HDSP_CHANNEL_BUFFER_BYTES * HDSP_MAX_CHANNELS,
4079 .period_bytes_min = (64 * 4) * 10,
4080 .period_bytes_max = (8192 * 4) * HDSP_MAX_CHANNELS,
4086 static snd_pcm_hardware_t snd_hdsp_capture_subinfo =
4088 .info = (SNDRV_PCM_INFO_MMAP |
4089 SNDRV_PCM_INFO_MMAP_VALID |
4090 SNDRV_PCM_INFO_NONINTERLEAVED |
4091 SNDRV_PCM_INFO_SYNC_START),
4092 #ifdef SNDRV_BIG_ENDIAN
4093 .formats = SNDRV_PCM_FMTBIT_S32_BE,
4095 .formats = SNDRV_PCM_FMTBIT_S32_LE,
4097 .rates = (SNDRV_PCM_RATE_32000 |
4098 SNDRV_PCM_RATE_44100 |
4099 SNDRV_PCM_RATE_48000 |
4100 SNDRV_PCM_RATE_64000 |
4101 SNDRV_PCM_RATE_88200 |
4102 SNDRV_PCM_RATE_96000),
4106 .channels_max = HDSP_MAX_CHANNELS,
4107 .buffer_bytes_max = HDSP_CHANNEL_BUFFER_BYTES * HDSP_MAX_CHANNELS,
4108 .period_bytes_min = (64 * 4) * 10,
4109 .period_bytes_max = (8192 * 4) * HDSP_MAX_CHANNELS,
4115 static unsigned int hdsp_period_sizes[] = { 64, 128, 256, 512, 1024, 2048, 4096, 8192 };
4117 static snd_pcm_hw_constraint_list_t hdsp_hw_constraints_period_sizes = {
4118 .count = ARRAY_SIZE(hdsp_period_sizes),
4119 .list = hdsp_period_sizes,
4123 static unsigned int hdsp_9632_sample_rates[] = { 32000, 44100, 48000, 64000, 88200, 96000, 128000, 176400, 192000 };
4125 static snd_pcm_hw_constraint_list_t hdsp_hw_constraints_9632_sample_rates = {
4126 .count = ARRAY_SIZE(hdsp_9632_sample_rates),
4127 .list = hdsp_9632_sample_rates,
4131 static int snd_hdsp_hw_rule_in_channels(snd_pcm_hw_params_t *params,
4132 snd_pcm_hw_rule_t *rule)
4134 hdsp_t *hdsp = rule->private;
4135 snd_interval_t *c = hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS);
4136 if (hdsp->io_type == H9632) {
4137 unsigned int list[3];
4138 list[0] = hdsp->qs_in_channels;
4139 list[1] = hdsp->ds_in_channels;
4140 list[2] = hdsp->ss_in_channels;
4141 return snd_interval_list(c, 3, list, 0);
4143 unsigned int list[2];
4144 list[0] = hdsp->ds_in_channels;
4145 list[1] = hdsp->ss_in_channels;
4146 return snd_interval_list(c, 2, list, 0);
4150 static int snd_hdsp_hw_rule_out_channels(snd_pcm_hw_params_t *params,
4151 snd_pcm_hw_rule_t *rule)
4153 unsigned int list[3];
4154 hdsp_t *hdsp = rule->private;
4155 snd_interval_t *c = hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS);
4156 if (hdsp->io_type == H9632) {
4157 list[0] = hdsp->qs_out_channels;
4158 list[1] = hdsp->ds_out_channels;
4159 list[2] = hdsp->ss_out_channels;
4160 return snd_interval_list(c, 3, list, 0);
4162 list[0] = hdsp->ds_out_channels;
4163 list[1] = hdsp->ss_out_channels;
4165 return snd_interval_list(c, 2, list, 0);
4168 static int snd_hdsp_hw_rule_in_channels_rate(snd_pcm_hw_params_t *params,
4169 snd_pcm_hw_rule_t *rule)
4171 hdsp_t *hdsp = rule->private;
4172 snd_interval_t *c = hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS);
4173 snd_interval_t *r = hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE);
4174 if (r->min > 96000 && hdsp->io_type == H9632) {
4175 snd_interval_t t = {
4176 .min = hdsp->qs_in_channels,
4177 .max = hdsp->qs_in_channels,
4180 return snd_interval_refine(c, &t);
4181 } else if (r->min > 48000 && r->max <= 96000) {
4182 snd_interval_t t = {
4183 .min = hdsp->ds_in_channels,
4184 .max = hdsp->ds_in_channels,
4187 return snd_interval_refine(c, &t);
4188 } else if (r->max < 64000) {
4189 snd_interval_t t = {
4190 .min = hdsp->ss_in_channels,
4191 .max = hdsp->ss_in_channels,
4194 return snd_interval_refine(c, &t);
4199 static int snd_hdsp_hw_rule_out_channels_rate(snd_pcm_hw_params_t *params,
4200 snd_pcm_hw_rule_t *rule)
4202 hdsp_t *hdsp = rule->private;
4203 snd_interval_t *c = hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS);
4204 snd_interval_t *r = hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE);
4205 if (r->min > 96000 && hdsp->io_type == H9632) {
4206 snd_interval_t t = {
4207 .min = hdsp->qs_out_channels,
4208 .max = hdsp->qs_out_channels,
4211 return snd_interval_refine(c, &t);
4212 } else if (r->min > 48000 && r->max <= 96000) {
4213 snd_interval_t t = {
4214 .min = hdsp->ds_out_channels,
4215 .max = hdsp->ds_out_channels,
4218 return snd_interval_refine(c, &t);
4219 } else if (r->max < 64000) {
4220 snd_interval_t t = {
4221 .min = hdsp->ss_out_channels,
4222 .max = hdsp->ss_out_channels,
4225 return snd_interval_refine(c, &t);
4230 static int snd_hdsp_hw_rule_rate_out_channels(snd_pcm_hw_params_t *params,
4231 snd_pcm_hw_rule_t *rule)
4233 hdsp_t *hdsp = rule->private;
4234 snd_interval_t *c = hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS);
4235 snd_interval_t *r = hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE);
4236 if (c->min >= hdsp->ss_out_channels) {
4237 snd_interval_t t = {
4242 return snd_interval_refine(r, &t);
4243 } else if (c->max <= hdsp->qs_out_channels && hdsp->io_type == H9632) {
4244 snd_interval_t t = {
4249 return snd_interval_refine(r, &t);
4250 } else if (c->max <= hdsp->ds_out_channels) {
4251 snd_interval_t t = {
4256 return snd_interval_refine(r, &t);
4261 static int snd_hdsp_hw_rule_rate_in_channels(snd_pcm_hw_params_t *params,
4262 snd_pcm_hw_rule_t *rule)
4264 hdsp_t *hdsp = rule->private;
4265 snd_interval_t *c = hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS);
4266 snd_interval_t *r = hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE);
4267 if (c->min >= hdsp->ss_in_channels) {
4268 snd_interval_t t = {
4273 return snd_interval_refine(r, &t);
4274 } else if (c->max <= hdsp->qs_in_channels && hdsp->io_type == H9632) {
4275 snd_interval_t t = {
4280 return snd_interval_refine(r, &t);
4281 } else if (c->max <= hdsp->ds_in_channels) {
4282 snd_interval_t t = {
4287 return snd_interval_refine(r, &t);
4292 static int snd_hdsp_playback_open(snd_pcm_substream_t *substream)
4294 hdsp_t *hdsp = snd_pcm_substream_chip(substream);
4295 snd_pcm_runtime_t *runtime = substream->runtime;
4297 if (hdsp_check_for_iobox (hdsp)) {
4301 if (hdsp_check_for_firmware(hdsp)) {
4302 if (hdsp->state & HDSP_FirmwareCached) {
4303 if (snd_hdsp_load_firmware_from_cache(hdsp) != 0) {
4304 snd_printk("Hammerfall-DSP: Firmware loading from cache failed, please upload manually.\n");
4307 snd_printk("Hammerfall-DSP: No firmware loaded nor cached, please upload firmware.\n");
4312 spin_lock_irq(&hdsp->lock);
4314 snd_pcm_set_sync(substream);
4316 runtime->hw = snd_hdsp_playback_subinfo;
4317 runtime->dma_area = hdsp->playback_buffer;
4318 runtime->dma_bytes = HDSP_DMA_AREA_BYTES;
4320 hdsp->playback_pid = current->pid;
4321 hdsp->playback_substream = substream;
4323 spin_unlock_irq(&hdsp->lock);
4325 snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24);
4326 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_SIZE, &hdsp_hw_constraints_period_sizes);
4327 if (hdsp->clock_source_locked) {
4328 runtime->hw.rate_min = runtime->hw.rate_max = hdsp->system_sample_rate;
4329 } else if (hdsp->io_type == H9632) {
4330 runtime->hw.rate_max = 192000;
4331 runtime->hw.rates = SNDRV_PCM_RATE_KNOT;
4332 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, &hdsp_hw_constraints_9632_sample_rates);
4334 if (hdsp->io_type == H9632) {
4335 runtime->hw.channels_min = hdsp->qs_out_channels;
4336 runtime->hw.channels_max = hdsp->ss_out_channels;
4339 snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
4340 snd_hdsp_hw_rule_out_channels, hdsp,
4341 SNDRV_PCM_HW_PARAM_CHANNELS, -1);
4342 snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
4343 snd_hdsp_hw_rule_out_channels_rate, hdsp,
4344 SNDRV_PCM_HW_PARAM_RATE, -1);
4345 snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
4346 snd_hdsp_hw_rule_rate_out_channels, hdsp,
4347 SNDRV_PCM_HW_PARAM_CHANNELS, -1);
4349 hdsp->creg_spdif_stream = hdsp->creg_spdif;
4350 hdsp->spdif_ctl->vd[0].access &= ~SNDRV_CTL_ELEM_ACCESS_INACTIVE;
4351 snd_ctl_notify(hdsp->card, SNDRV_CTL_EVENT_MASK_VALUE |
4352 SNDRV_CTL_EVENT_MASK_INFO, &hdsp->spdif_ctl->id);
4356 static int snd_hdsp_playback_release(snd_pcm_substream_t *substream)
4358 hdsp_t *hdsp = snd_pcm_substream_chip(substream);
4360 spin_lock_irq(&hdsp->lock);
4362 hdsp->playback_pid = -1;
4363 hdsp->playback_substream = NULL;
4365 spin_unlock_irq(&hdsp->lock);
4367 hdsp->spdif_ctl->vd[0].access |= SNDRV_CTL_ELEM_ACCESS_INACTIVE;
4368 snd_ctl_notify(hdsp->card, SNDRV_CTL_EVENT_MASK_VALUE |
4369 SNDRV_CTL_EVENT_MASK_INFO, &hdsp->spdif_ctl->id);
4374 static int snd_hdsp_capture_open(snd_pcm_substream_t *substream)
4376 hdsp_t *hdsp = snd_pcm_substream_chip(substream);
4377 snd_pcm_runtime_t *runtime = substream->runtime;
4379 if (hdsp_check_for_iobox (hdsp)) {
4383 if (hdsp_check_for_firmware(hdsp)) {
4384 if (hdsp->state & HDSP_FirmwareCached) {
4385 if (snd_hdsp_load_firmware_from_cache(hdsp) != 0) {
4386 snd_printk("Hammerfall-DSP: Firmware loading from cache failed, please upload manually.\n");
4389 snd_printk("Hammerfall-DSP: No firmware loaded nor cached, please upload firmware.\n");
4394 spin_lock_irq(&hdsp->lock);
4396 snd_pcm_set_sync(substream);
4398 runtime->hw = snd_hdsp_capture_subinfo;
4399 runtime->dma_area = hdsp->capture_buffer;
4400 runtime->dma_bytes = HDSP_DMA_AREA_BYTES;
4402 hdsp->capture_pid = current->pid;
4403 hdsp->capture_substream = substream;
4405 spin_unlock_irq(&hdsp->lock);
4407 snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24);
4408 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_SIZE, &hdsp_hw_constraints_period_sizes);
4409 if (hdsp->io_type == H9632) {
4410 runtime->hw.channels_min = hdsp->qs_in_channels;
4411 runtime->hw.channels_max = hdsp->ss_in_channels;
4412 runtime->hw.rate_max = 192000;
4413 runtime->hw.rates = SNDRV_PCM_RATE_KNOT;
4414 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, &hdsp_hw_constraints_9632_sample_rates);
4416 snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
4417 snd_hdsp_hw_rule_in_channels, hdsp,
4418 SNDRV_PCM_HW_PARAM_CHANNELS, -1);
4419 snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
4420 snd_hdsp_hw_rule_in_channels_rate, hdsp,
4421 SNDRV_PCM_HW_PARAM_RATE, -1);
4422 snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
4423 snd_hdsp_hw_rule_rate_in_channels, hdsp,
4424 SNDRV_PCM_HW_PARAM_CHANNELS, -1);
4428 static int snd_hdsp_capture_release(snd_pcm_substream_t *substream)
4430 hdsp_t *hdsp = snd_pcm_substream_chip(substream);
4432 spin_lock_irq(&hdsp->lock);
4434 hdsp->capture_pid = -1;
4435 hdsp->capture_substream = NULL;
4437 spin_unlock_irq(&hdsp->lock);
4441 static int snd_hdsp_hwdep_dummy_op(snd_hwdep_t *hw, struct file *file)
4443 /* we have nothing to initialize but the call is required */
4448 /* helper functions for copying meter values */
4449 static inline int copy_u32_le(void __user *dest, void __iomem *src)
4451 u32 val = readl(src);
4452 return copy_to_user(dest, &val, 4);
4455 static inline int copy_u64_le(void __user *dest, void __iomem *src_low, void __iomem *src_high)
4457 u32 rms_low, rms_high;
4459 rms_low = readl(src_low);
4460 rms_high = readl(src_high);
4461 rms = ((u64)rms_high << 32) | rms_low;
4462 return copy_to_user(dest, &rms, 8);
4465 static inline int copy_u48_le(void __user *dest, void __iomem *src_low, void __iomem *src_high)
4467 u32 rms_low, rms_high;
4469 rms_low = readl(src_low) & 0xffffff00;
4470 rms_high = readl(src_high) & 0xffffff00;
4471 rms = ((u64)rms_high << 32) | rms_low;
4472 return copy_to_user(dest, &rms, 8);
4475 static int hdsp_9652_get_peak(hdsp_t *hdsp, hdsp_peak_rms_t __user *peak_rms)
4477 int doublespeed = 0;
4478 int i, j, channels, ofs;
4480 if (hdsp_read (hdsp, HDSP_statusRegister) & HDSP_DoubleSpeedStatus)
4482 channels = doublespeed ? 14 : 26;
4483 for (i = 0, j = 0; i < 26; ++i) {
4484 if (doublespeed && (i & 4))
4486 ofs = HDSP_9652_peakBase - j * 4;
4487 if (copy_u32_le(&peak_rms->input_peaks[i], hdsp->iobase + ofs))
4489 ofs -= channels * 4;
4490 if (copy_u32_le(&peak_rms->playback_peaks[i], hdsp->iobase + ofs))
4492 ofs -= channels * 4;
4493 if (copy_u32_le(&peak_rms->output_peaks[i], hdsp->iobase + ofs))
4495 ofs = HDSP_9652_rmsBase + j * 8;
4496 if (copy_u48_le(&peak_rms->input_rms[i], hdsp->iobase + ofs,
4497 hdsp->iobase + ofs + 4))
4499 ofs += channels * 8;
4500 if (copy_u48_le(&peak_rms->playback_rms[i], hdsp->iobase + ofs,
4501 hdsp->iobase + ofs + 4))
4503 ofs += channels * 8;
4504 if (copy_u48_le(&peak_rms->output_rms[i], hdsp->iobase + ofs,
4505 hdsp->iobase + ofs + 4))
4512 static int hdsp_9632_get_peak(hdsp_t *hdsp, hdsp_peak_rms_t __user *peak_rms)
4515 hdsp_9632_meters_t __iomem *m;
4516 int doublespeed = 0;
4518 if (hdsp_read (hdsp, HDSP_statusRegister) & HDSP_DoubleSpeedStatus)
4520 m = (hdsp_9632_meters_t __iomem *)(hdsp->iobase+HDSP_9632_metersBase);
4521 for (i = 0, j = 0; i < 16; ++i, ++j) {
4522 if (copy_u32_le(&peak_rms->input_peaks[i], &m->input_peak[j]))
4524 if (copy_u32_le(&peak_rms->playback_peaks[i], &m->playback_peak[j]))
4526 if (copy_u32_le(&peak_rms->output_peaks[i], &m->output_peak[j]))
4528 if (copy_u64_le(&peak_rms->input_rms[i], &m->input_rms_low[j],
4529 &m->input_rms_high[j]))
4531 if (copy_u64_le(&peak_rms->playback_rms[i], &m->playback_rms_low[j],
4532 &m->playback_rms_high[j]))
4534 if (copy_u64_le(&peak_rms->output_rms[i], &m->output_rms_low[j],
4535 &m->output_rms_high[j]))
4537 if (doublespeed && i == 3) i += 4;
4542 static int hdsp_get_peak(hdsp_t *hdsp, hdsp_peak_rms_t __user *peak_rms)
4546 for (i = 0; i < 26; i++) {
4547 if (copy_u32_le(&peak_rms->playback_peaks[i],
4548 hdsp->iobase + HDSP_playbackPeakLevel + i * 4))
4550 if (copy_u32_le(&peak_rms->input_peaks[i],
4551 hdsp->iobase + HDSP_inputPeakLevel + i * 4))
4554 for (i = 0; i < 28; i++) {
4555 if (copy_u32_le(&peak_rms->output_peaks[i],
4556 hdsp->iobase + HDSP_outputPeakLevel + i * 4))
4559 for (i = 0; i < 26; ++i) {
4560 if (copy_u64_le(&peak_rms->playback_rms[i],
4561 hdsp->iobase + HDSP_playbackRmsLevel + i * 8 + 4,
4562 hdsp->iobase + HDSP_playbackRmsLevel + i * 8))
4564 if (copy_u64_le(&peak_rms->input_rms[i],
4565 hdsp->iobase + HDSP_inputRmsLevel + i * 8 + 4,
4566 hdsp->iobase + HDSP_inputRmsLevel + i * 8))
4572 static int snd_hdsp_hwdep_ioctl(snd_hwdep_t *hw, struct file *file, unsigned int cmd, unsigned long arg)
4574 hdsp_t *hdsp = (hdsp_t *)hw->private_data;
4575 void __user *argp = (void __user *)arg;
4578 case SNDRV_HDSP_IOCTL_GET_PEAK_RMS: {
4579 hdsp_peak_rms_t __user *peak_rms = (hdsp_peak_rms_t __user *)arg;
4581 if (!(hdsp->state & HDSP_FirmwareLoaded)) {
4582 snd_printk(KERN_ERR "Hammerfall-DSP: firmware needs to be uploaded to the card.\n");
4586 switch (hdsp->io_type) {
4588 return hdsp_9652_get_peak(hdsp, peak_rms);
4590 return hdsp_9632_get_peak(hdsp, peak_rms);
4592 return hdsp_get_peak(hdsp, peak_rms);
4595 case SNDRV_HDSP_IOCTL_GET_CONFIG_INFO: {
4596 hdsp_config_info_t info;
4597 unsigned long flags;
4600 if (!(hdsp->state & HDSP_FirmwareLoaded)) {
4601 snd_printk("Hammerfall-DSP: Firmware needs to be uploaded to the card.\n");
4604 spin_lock_irqsave(&hdsp->lock, flags);
4605 info.pref_sync_ref = (unsigned char)hdsp_pref_sync_ref(hdsp);
4606 info.wordclock_sync_check = (unsigned char)hdsp_wc_sync_check(hdsp);
4607 if (hdsp->io_type != H9632) {
4608 info.adatsync_sync_check = (unsigned char)hdsp_adatsync_sync_check(hdsp);
4610 info.spdif_sync_check = (unsigned char)hdsp_spdif_sync_check(hdsp);
4611 for (i = 0; i < ((hdsp->io_type != Multiface && hdsp->io_type != H9632) ? 3 : 1); ++i) {
4612 info.adat_sync_check[i] = (unsigned char)hdsp_adat_sync_check(hdsp, i);
4614 info.spdif_in = (unsigned char)hdsp_spdif_in(hdsp);
4615 info.spdif_out = (unsigned char)hdsp_spdif_out(hdsp);
4616 info.spdif_professional = (unsigned char)hdsp_spdif_professional(hdsp);
4617 info.spdif_emphasis = (unsigned char)hdsp_spdif_emphasis(hdsp);
4618 info.spdif_nonaudio = (unsigned char)hdsp_spdif_nonaudio(hdsp);
4619 info.spdif_sample_rate = hdsp_spdif_sample_rate(hdsp);
4620 info.system_sample_rate = hdsp->system_sample_rate;
4621 info.autosync_sample_rate = hdsp_external_sample_rate(hdsp);
4622 info.system_clock_mode = (unsigned char)hdsp_system_clock_mode(hdsp);
4623 info.clock_source = (unsigned char)hdsp_clock_source(hdsp);
4624 info.autosync_ref = (unsigned char)hdsp_autosync_ref(hdsp);
4625 info.line_out = (unsigned char)hdsp_line_out(hdsp);
4626 if (hdsp->io_type == H9632) {
4627 info.da_gain = (unsigned char)hdsp_da_gain(hdsp);
4628 info.ad_gain = (unsigned char)hdsp_ad_gain(hdsp);
4629 info.phone_gain = (unsigned char)hdsp_phone_gain(hdsp);
4630 info.xlr_breakout_cable = (unsigned char)hdsp_xlr_breakout_cable(hdsp);
4633 if (hdsp->io_type == H9632 || hdsp->io_type == H9652) {
4634 info.analog_extension_board = (unsigned char)hdsp_aeb(hdsp);
4636 spin_unlock_irqrestore(&hdsp->lock, flags);
4637 if (copy_to_user(argp, &info, sizeof(info)))
4641 case SNDRV_HDSP_IOCTL_GET_9632_AEB: {
4642 hdsp_9632_aeb_t h9632_aeb;
4644 if (hdsp->io_type != H9632) return -EINVAL;
4645 h9632_aeb.aebi = hdsp->ss_in_channels - H9632_SS_CHANNELS;
4646 h9632_aeb.aebo = hdsp->ss_out_channels - H9632_SS_CHANNELS;
4647 if (copy_to_user(argp, &h9632_aeb, sizeof(h9632_aeb)))
4651 case SNDRV_HDSP_IOCTL_GET_VERSION: {
4652 hdsp_version_t hdsp_version;
4655 if (hdsp->io_type == H9652 || hdsp->io_type == H9632) return -EINVAL;
4656 if (hdsp->io_type == Undefined) {
4657 if ((err = hdsp_get_iobox_version(hdsp)) < 0) {
4661 hdsp_version.io_type = hdsp->io_type;
4662 hdsp_version.firmware_rev = hdsp->firmware_rev;
4663 if ((err = copy_to_user(argp, &hdsp_version, sizeof(hdsp_version)))) {
4668 case SNDRV_HDSP_IOCTL_UPLOAD_FIRMWARE: {
4669 hdsp_firmware_t __user *firmware;
4670 u32 __user *firmware_data;
4673 if (hdsp->io_type == H9652 || hdsp->io_type == H9632) return -EINVAL;
4674 /* SNDRV_HDSP_IOCTL_GET_VERSION must have been called */
4675 if (hdsp->io_type == Undefined) return -EINVAL;
4677 if (hdsp->state & (HDSP_FirmwareCached | HDSP_FirmwareLoaded))
4680 snd_printk("Hammerfall-DSP: initializing firmware upload\n");
4681 firmware = (hdsp_firmware_t __user *)argp;
4683 if (get_user(firmware_data, &firmware->firmware_data)) {
4687 if (hdsp_check_for_iobox (hdsp)) {
4691 if (copy_from_user(hdsp->firmware_cache, firmware_data, sizeof(hdsp->firmware_cache)) != 0) {
4695 hdsp->state |= HDSP_FirmwareCached;
4697 if ((err = snd_hdsp_load_firmware_from_cache(hdsp)) < 0) {
4701 if (!(hdsp->state & HDSP_InitializationComplete)) {
4702 if ((err = snd_hdsp_enable_io(hdsp)) < 0) {
4706 snd_hdsp_initialize_channels(hdsp);
4707 snd_hdsp_initialize_midi_flush(hdsp);
4709 if ((err = snd_hdsp_create_alsa_devices(hdsp->card, hdsp)) < 0) {
4710 snd_printk("Hammerfall-DSP: error creating alsa devices\n");
4716 case SNDRV_HDSP_IOCTL_GET_MIXER: {
4717 hdsp_mixer_t __user *mixer = (hdsp_mixer_t __user *)argp;
4718 if (copy_to_user(mixer->matrix, hdsp->mixer_matrix, sizeof(unsigned short)*HDSP_MATRIX_MIXER_SIZE))
4728 static snd_pcm_ops_t snd_hdsp_playback_ops = {
4729 .open = snd_hdsp_playback_open,
4730 .close = snd_hdsp_playback_release,
4731 .ioctl = snd_hdsp_ioctl,
4732 .hw_params = snd_hdsp_hw_params,
4733 .prepare = snd_hdsp_prepare,
4734 .trigger = snd_hdsp_trigger,
4735 .pointer = snd_hdsp_hw_pointer,
4736 .copy = snd_hdsp_playback_copy,
4737 .silence = snd_hdsp_hw_silence,
4740 static snd_pcm_ops_t snd_hdsp_capture_ops = {
4741 .open = snd_hdsp_capture_open,
4742 .close = snd_hdsp_capture_release,
4743 .ioctl = snd_hdsp_ioctl,
4744 .hw_params = snd_hdsp_hw_params,
4745 .prepare = snd_hdsp_prepare,
4746 .trigger = snd_hdsp_trigger,
4747 .pointer = snd_hdsp_hw_pointer,
4748 .copy = snd_hdsp_capture_copy,
4751 static int __devinit snd_hdsp_create_hwdep(snd_card_t *card,
4757 if ((err = snd_hwdep_new(card, "HDSP hwdep", 0, &hw)) < 0)
4761 hw->private_data = hdsp;
4762 strcpy(hw->name, "HDSP hwdep interface");
4764 hw->ops.open = snd_hdsp_hwdep_dummy_op;
4765 hw->ops.ioctl = snd_hdsp_hwdep_ioctl;
4766 hw->ops.release = snd_hdsp_hwdep_dummy_op;
4771 static int snd_hdsp_create_pcm(snd_card_t *card, hdsp_t *hdsp)
4776 if ((err = snd_pcm_new(card, hdsp->card_name, 0, 1, 1, &pcm)) < 0)
4780 pcm->private_data = hdsp;
4781 strcpy(pcm->name, hdsp->card_name);
4783 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_hdsp_playback_ops);
4784 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_hdsp_capture_ops);
4786 pcm->info_flags = SNDRV_PCM_INFO_JOINT_DUPLEX;
4791 static void snd_hdsp_9652_enable_mixer (hdsp_t *hdsp)
4793 hdsp->control2_register |= HDSP_9652_ENABLE_MIXER;
4794 hdsp_write (hdsp, HDSP_control2Reg, hdsp->control2_register);
4797 static int snd_hdsp_enable_io (hdsp_t *hdsp)
4801 if (hdsp_fifo_wait (hdsp, 0, 100)) {
4802 snd_printk("Hammerfall-DSP: enable_io fifo_wait failed\n");
4806 for (i = 0; i < hdsp->max_channels; ++i) {
4807 hdsp_write (hdsp, HDSP_inputEnable + (4 * i), 1);
4808 hdsp_write (hdsp, HDSP_outputEnable + (4 * i), 1);
4814 static void snd_hdsp_initialize_channels(hdsp_t *hdsp)
4816 int status, aebi_channels, aebo_channels;
4818 switch (hdsp->io_type) {
4820 hdsp->card_name = "RME Hammerfall DSP + Digiface";
4821 hdsp->ss_in_channels = hdsp->ss_out_channels = DIGIFACE_SS_CHANNELS;
4822 hdsp->ds_in_channels = hdsp->ds_out_channels = DIGIFACE_DS_CHANNELS;
4826 hdsp->card_name = "RME Hammerfall HDSP 9652";
4827 hdsp->ss_in_channels = hdsp->ss_out_channels = H9652_SS_CHANNELS;
4828 hdsp->ds_in_channels = hdsp->ds_out_channels = H9652_DS_CHANNELS;
4832 status = hdsp_read(hdsp, HDSP_statusRegister);
4833 /* HDSP_AEBx bits are low when AEB are connected */
4834 aebi_channels = (status & HDSP_AEBI) ? 0 : 4;
4835 aebo_channels = (status & HDSP_AEBO) ? 0 : 4;
4836 hdsp->card_name = "RME Hammerfall HDSP 9632";
4837 hdsp->ss_in_channels = H9632_SS_CHANNELS+aebi_channels;
4838 hdsp->ds_in_channels = H9632_DS_CHANNELS+aebi_channels;
4839 hdsp->qs_in_channels = H9632_QS_CHANNELS+aebi_channels;
4840 hdsp->ss_out_channels = H9632_SS_CHANNELS+aebo_channels;
4841 hdsp->ds_out_channels = H9632_DS_CHANNELS+aebo_channels;
4842 hdsp->qs_out_channels = H9632_QS_CHANNELS+aebo_channels;
4846 hdsp->card_name = "RME Hammerfall DSP + Multiface";
4847 hdsp->ss_in_channels = hdsp->ss_out_channels = MULTIFACE_SS_CHANNELS;
4848 hdsp->ds_in_channels = hdsp->ds_out_channels = MULTIFACE_DS_CHANNELS;
4852 /* should never get here */
4857 static void snd_hdsp_initialize_midi_flush (hdsp_t *hdsp)
4859 snd_hdsp_flush_midi_input (hdsp, 0);
4860 snd_hdsp_flush_midi_input (hdsp, 1);
4863 static int snd_hdsp_create_alsa_devices(snd_card_t *card, hdsp_t *hdsp)
4867 if ((err = snd_hdsp_create_pcm(card, hdsp)) < 0) {
4868 snd_printk("Hammerfall-DSP: Error creating pcm interface\n");
4873 if ((err = snd_hdsp_create_midi(card, hdsp, 0)) < 0) {
4874 snd_printk("Hammerfall-DSP: Error creating first midi interface\n");
4878 if (hdsp->io_type == Digiface || hdsp->io_type == H9652) {
4879 if ((err = snd_hdsp_create_midi(card, hdsp, 1)) < 0) {
4880 snd_printk("Hammerfall-DSP: Error creating second midi interface\n");
4885 if ((err = snd_hdsp_create_controls(card, hdsp)) < 0) {
4886 snd_printk("Hammerfall-DSP: Error creating ctl interface\n");
4890 snd_hdsp_proc_init(hdsp);
4892 hdsp->system_sample_rate = -1;
4893 hdsp->playback_pid = -1;
4894 hdsp->capture_pid = -1;
4895 hdsp->capture_substream = NULL;
4896 hdsp->playback_substream = NULL;
4898 if ((err = snd_hdsp_set_defaults(hdsp)) < 0) {
4899 snd_printk("Hammerfall-DSP: Error setting default values\n");
4903 if (!(hdsp->state & HDSP_InitializationComplete)) {
4904 sprintf(card->longname, "%s at 0x%lx, irq %d", hdsp->card_name,
4905 hdsp->port, hdsp->irq);
4907 if ((err = snd_card_register(card)) < 0) {
4908 snd_printk("Hammerfall-DSP: error registering card\n");
4911 hdsp->state |= HDSP_InitializationComplete;
4917 #ifdef HDSP_FW_LOADER
4918 /* load firmware via hotplug fw loader */
4919 static int __devinit hdsp_request_fw_loader(hdsp_t *hdsp)
4922 const struct firmware *fw;
4925 if (hdsp->io_type == H9652 || hdsp->io_type == H9632)
4927 if (hdsp->io_type == Undefined) {
4928 if ((err = hdsp_get_iobox_version(hdsp)) < 0)
4930 if (hdsp->io_type == H9652 || hdsp->io_type == H9632)
4934 /* caution: max length of firmware filename is 30! */
4935 switch (hdsp->io_type) {
4937 if (hdsp->firmware_rev == 0xa)
4938 fwfile = "multiface_firmware.bin";
4940 fwfile = "multiface_firmware_rev11.bin";
4943 if (hdsp->firmware_rev == 0xa)
4944 fwfile = "digiface_firmware.bin";
4946 fwfile = "digiface_firmware_rev11.bin";
4949 snd_printk(KERN_ERR "Hammerfall-DSP: invalid io_type %d\n", hdsp->io_type);
4953 if (request_firmware(&fw, fwfile, &hdsp->pci->dev)) {
4954 snd_printk(KERN_ERR "Hammerfall-DSP: cannot load firmware %s\n", fwfile);
4957 if (fw->size < sizeof(hdsp->firmware_cache)) {
4958 snd_printk(KERN_ERR "Hammerfall-DSP: too short firmware size %d (expected %d)\n",
4959 (int)fw->size, (int)sizeof(hdsp->firmware_cache));
4960 release_firmware(fw);
4964 memcpy(hdsp->firmware_cache, fw->data, sizeof(hdsp->firmware_cache));
4966 release_firmware(fw);
4968 hdsp->state |= HDSP_FirmwareCached;
4970 if ((err = snd_hdsp_load_firmware_from_cache(hdsp)) < 0)
4973 if (!(hdsp->state & HDSP_InitializationComplete)) {
4974 if ((err = snd_hdsp_enable_io(hdsp)) < 0) {
4978 if ((err = snd_hdsp_create_hwdep(hdsp->card, hdsp)) < 0) {
4979 snd_printk("Hammerfall-DSP: error creating hwdep device\n");
4982 snd_hdsp_initialize_channels(hdsp);
4983 snd_hdsp_initialize_midi_flush(hdsp);
4984 if ((err = snd_hdsp_create_alsa_devices(hdsp->card, hdsp)) < 0) {
4985 snd_printk("Hammerfall-DSP: error creating alsa devices\n");
4993 static int __devinit snd_hdsp_create(snd_card_t *card,
4996 struct pci_dev *pci = hdsp->pci;
5003 hdsp->midi[0].rmidi = NULL;
5004 hdsp->midi[1].rmidi = NULL;
5005 hdsp->midi[0].input = NULL;
5006 hdsp->midi[1].input = NULL;
5007 hdsp->midi[0].output = NULL;
5008 hdsp->midi[1].output = NULL;
5009 hdsp->midi[0].pending = 0;
5010 hdsp->midi[1].pending = 0;
5011 spin_lock_init(&hdsp->midi[0].lock);
5012 spin_lock_init(&hdsp->midi[1].lock);
5013 hdsp->iobase = NULL;
5014 hdsp->control_register = 0;
5015 hdsp->control2_register = 0;
5016 hdsp->io_type = Undefined;
5017 hdsp->max_channels = 26;
5021 spin_lock_init(&hdsp->lock);
5023 tasklet_init(&hdsp->midi_tasklet, hdsp_midi_tasklet, (unsigned long)hdsp);
5025 pci_read_config_word(hdsp->pci, PCI_CLASS_REVISION, &hdsp->firmware_rev);
5026 hdsp->firmware_rev &= 0xff;
5028 /* From Martin Bjoernsen :
5029 "It is important that the card's latency timer register in
5030 the PCI configuration space is set to a value much larger
5031 than 0 by the computer's BIOS or the driver.
5032 The windows driver always sets this 8 bit register [...]
5033 to its maximum 255 to avoid problems with some computers."
5035 pci_write_config_byte(hdsp->pci, PCI_LATENCY_TIMER, 0xFF);
5037 strcpy(card->driver, "H-DSP");
5038 strcpy(card->mixername, "Xilinx FPGA");
5040 if (hdsp->firmware_rev < 0xa) {
5042 } else if (hdsp->firmware_rev < 0x64) {
5043 hdsp->card_name = "RME Hammerfall DSP";
5044 } else if (hdsp->firmware_rev < 0x96) {
5045 hdsp->card_name = "RME HDSP 9652";
5048 hdsp->card_name = "RME HDSP 9632";
5049 hdsp->max_channels = 16;
5053 if ((err = pci_enable_device(pci)) < 0) {
5057 pci_set_master(hdsp->pci);
5059 if ((err = pci_request_regions(pci, "hdsp")) < 0)
5061 hdsp->port = pci_resource_start(pci, 0);
5062 if ((hdsp->iobase = ioremap_nocache(hdsp->port, HDSP_IO_EXTENT)) == NULL) {
5063 snd_printk("Hammerfall-DSP: unable to remap region 0x%lx-0x%lx\n", hdsp->port, hdsp->port + HDSP_IO_EXTENT - 1);
5067 if (request_irq(pci->irq, snd_hdsp_interrupt, SA_INTERRUPT|SA_SHIRQ, "hdsp", (void *)hdsp)) {
5068 snd_printk("Hammerfall-DSP: unable to use IRQ %d\n", pci->irq);
5072 hdsp->irq = pci->irq;
5073 hdsp->precise_ptr = 1;
5074 hdsp->use_midi_tasklet = 1;
5076 if ((err = snd_hdsp_initialize_memory(hdsp)) < 0) {
5080 if (!is_9652 && !is_9632) {
5081 /* we wait 2 seconds to let freshly inserted cardbus cards do their hardware init */
5082 if ((1000 / HZ) < 2000) {
5083 set_current_state(TASK_UNINTERRUPTIBLE);
5084 schedule_timeout((2000 * HZ + 999) / 1000);
5089 if ((hdsp_read (hdsp, HDSP_statusRegister) & HDSP_DllError) != 0) {
5090 #ifdef HDSP_FW_LOADER
5091 if ((err = hdsp_request_fw_loader(hdsp)) < 0) {
5092 /* we don't fail as this can happen
5093 if userspace is not ready for
5096 snd_printk("Hammerfall-DSP: couldn't get firmware from userspace. try using hdsploader\n");
5098 /* init is complete, we return */
5102 /* no iobox connected, we defer initialization */
5103 snd_printk("Hammerfall-DSP: card initialization pending : waiting for firmware\n");
5104 if ((err = snd_hdsp_create_hwdep(card, hdsp)) < 0) {
5109 snd_printk("Hammerfall-DSP: Firmware already present, initializing card.\n");
5110 if (hdsp_read(hdsp, HDSP_status2Register) & HDSP_version1) {
5111 hdsp->io_type = Multiface;
5113 hdsp->io_type = Digiface;
5118 if ((err = snd_hdsp_enable_io(hdsp)) != 0) {
5123 hdsp->io_type = H9652;
5127 hdsp->io_type = H9632;
5130 if ((err = snd_hdsp_create_hwdep(card, hdsp)) < 0) {
5134 snd_hdsp_initialize_channels(hdsp);
5135 snd_hdsp_initialize_midi_flush(hdsp);
5137 hdsp->state |= HDSP_FirmwareLoaded;
5139 if ((err = snd_hdsp_create_alsa_devices(card, hdsp)) < 0) {
5146 static int snd_hdsp_free(hdsp_t *hdsp)
5149 /* stop the audio, and cancel all interrupts */
5150 tasklet_kill(&hdsp->midi_tasklet);
5151 hdsp->control_register &= ~(HDSP_Start|HDSP_AudioInterruptEnable|HDSP_Midi0InterruptEnable|HDSP_Midi1InterruptEnable);
5152 hdsp_write (hdsp, HDSP_controlRegister, hdsp->control_register);
5156 free_irq(hdsp->irq, (void *)hdsp);
5158 snd_hdsp_free_buffers(hdsp);
5161 iounmap(hdsp->iobase);
5164 pci_release_regions(hdsp->pci);
5166 pci_disable_device(hdsp->pci);
5170 static void snd_hdsp_card_free(snd_card_t *card)
5172 hdsp_t *hdsp = (hdsp_t *) card->private_data;
5175 snd_hdsp_free(hdsp);
5178 static int __devinit snd_hdsp_probe(struct pci_dev *pci,
5179 const struct pci_device_id *pci_id)
5186 if (dev >= SNDRV_CARDS)
5193 if (!(card = snd_card_new(index[dev], id[dev], THIS_MODULE, sizeof(hdsp_t))))
5196 hdsp = (hdsp_t *) card->private_data;
5197 card->private_free = snd_hdsp_card_free;
5200 snd_card_set_dev(card, &pci->dev);
5202 if ((err = snd_hdsp_create(card, hdsp)) < 0) {
5203 snd_card_free(card);
5207 strcpy(card->shortname, "Hammerfall DSP");
5208 sprintf(card->longname, "%s at 0x%lx, irq %d", hdsp->card_name,
5209 hdsp->port, hdsp->irq);
5211 if ((err = snd_card_register(card)) < 0) {
5212 snd_card_free(card);
5215 pci_set_drvdata(pci, card);
5220 static void __devexit snd_hdsp_remove(struct pci_dev *pci)
5222 snd_card_free(pci_get_drvdata(pci));
5223 pci_set_drvdata(pci, NULL);
5226 static struct pci_driver driver = {
5227 .name = "RME Hammerfall DSP",
5228 .id_table = snd_hdsp_ids,
5229 .probe = snd_hdsp_probe,
5230 .remove = __devexit_p(snd_hdsp_remove),
5233 static int __init alsa_card_hdsp_init(void)
5235 return pci_register_driver(&driver);
5238 static void __exit alsa_card_hdsp_exit(void)
5240 pci_unregister_driver(&driver);
5243 module_init(alsa_card_hdsp_init)
5244 module_exit(alsa_card_hdsp_exit)