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) {
687 if (hdsp_fifo_wait (hdsp, 0, HDSP_LONG_WAIT)) {
688 snd_printk ("Hammerfall-DSP: timeout at end of firmware loading\n");
692 #ifdef SNDRV_BIG_ENDIAN
693 hdsp->control2_register = HDSP_BIGENDIAN_MODE;
695 hdsp->control2_register = 0;
697 hdsp_write (hdsp, HDSP_control2Reg, hdsp->control2_register);
698 snd_printk ("Hammerfall-DSP: finished firmware loading\n");
701 if (hdsp->state & HDSP_InitializationComplete) {
702 snd_printk("Hammerfall-DSP: firmware loaded from cache, restoring defaults\n");
703 spin_lock_irqsave(&hdsp->lock, flags);
704 snd_hdsp_set_defaults(hdsp);
705 spin_unlock_irqrestore(&hdsp->lock, flags);
708 hdsp->state |= HDSP_FirmwareLoaded;
713 static int hdsp_get_iobox_version (hdsp_t *hdsp)
715 if ((hdsp_read (hdsp, HDSP_statusRegister) & HDSP_DllError) != 0) {
717 hdsp_write (hdsp, HDSP_control2Reg, HDSP_PROGRAM);
718 hdsp_write (hdsp, HDSP_fifoData, 0);
719 if (hdsp_fifo_wait (hdsp, 0, HDSP_SHORT_WAIT) < 0) {
723 hdsp_write (hdsp, HDSP_control2Reg, HDSP_S_LOAD);
724 hdsp_write (hdsp, HDSP_fifoData, 0);
726 if (hdsp_fifo_wait (hdsp, 0, HDSP_SHORT_WAIT)) {
727 hdsp->io_type = Multiface;
728 hdsp_write (hdsp, HDSP_control2Reg, HDSP_VERSION_BIT);
729 hdsp_write (hdsp, HDSP_control2Reg, HDSP_S_LOAD);
730 hdsp_fifo_wait (hdsp, 0, HDSP_SHORT_WAIT);
732 hdsp->io_type = Digiface;
735 /* firmware was already loaded, get iobox type */
736 if (hdsp_read(hdsp, HDSP_status2Register) & HDSP_version1) {
737 hdsp->io_type = Multiface;
739 hdsp->io_type = Digiface;
746 static int hdsp_check_for_firmware (hdsp_t *hdsp)
748 if (hdsp->io_type == H9652 || hdsp->io_type == H9632) return 0;
749 if ((hdsp_read (hdsp, HDSP_statusRegister) & HDSP_DllError) != 0) {
750 snd_printk("Hammerfall-DSP: firmware not present.\n");
751 hdsp->state &= ~HDSP_FirmwareLoaded;
758 static int hdsp_fifo_wait(hdsp_t *hdsp, int count, int timeout)
762 /* the fifoStatus registers reports on how many words
763 are available in the command FIFO.
766 for (i = 0; i < timeout; i++) {
768 if ((int)(hdsp_read (hdsp, HDSP_fifoStatus) & 0xff) <= count)
771 /* not very friendly, but we only do this during a firmware
772 load and changing the mixer, so we just put up with it.
778 snd_printk ("Hammerfall-DSP: wait for FIFO status <= %d failed after %d iterations\n",
783 static int hdsp_read_gain (hdsp_t *hdsp, unsigned int addr)
785 if (addr >= HDSP_MATRIX_MIXER_SIZE) {
788 return hdsp->mixer_matrix[addr];
791 static int hdsp_write_gain(hdsp_t *hdsp, unsigned int addr, unsigned short data)
795 if (addr >= HDSP_MATRIX_MIXER_SIZE)
798 if (hdsp->io_type == H9652 || hdsp->io_type == H9632) {
800 /* from martin bjornsen:
802 "You can only write dwords to the
803 mixer memory which contain two
804 mixer values in the low and high
805 word. So if you want to change
806 value 0 you have to read value 1
807 from the cache and write both to
808 the first dword in the mixer
812 if (hdsp->io_type == H9632 && addr >= 512) {
816 if (hdsp->io_type == H9652 && addr >= 1352) {
820 hdsp->mixer_matrix[addr] = data;
823 /* `addr' addresses a 16-bit wide address, but
824 the address space accessed via hdsp_write
825 uses byte offsets. put another way, addr
826 varies from 0 to 1351, but to access the
827 corresponding memory location, we need
828 to access 0 to 2703 ...
832 hdsp_write (hdsp, 4096 + (ad*4),
833 (hdsp->mixer_matrix[(addr&0x7fe)+1] << 16) +
834 hdsp->mixer_matrix[addr&0x7fe]);
840 ad = (addr << 16) + data;
842 if (hdsp_fifo_wait(hdsp, 127, HDSP_LONG_WAIT)) {
846 hdsp_write (hdsp, HDSP_fifoData, ad);
847 hdsp->mixer_matrix[addr] = data;
854 static int snd_hdsp_use_is_exclusive(hdsp_t *hdsp)
859 spin_lock_irqsave(&hdsp->lock, flags);
860 if ((hdsp->playback_pid != hdsp->capture_pid) &&
861 (hdsp->playback_pid >= 0) && (hdsp->capture_pid >= 0)) {
864 spin_unlock_irqrestore(&hdsp->lock, flags);
868 static int hdsp_external_sample_rate (hdsp_t *hdsp)
870 unsigned int status2 = hdsp_read(hdsp, HDSP_status2Register);
871 unsigned int rate_bits = status2 & HDSP_systemFrequencyMask;
874 case HDSP_systemFrequency32: return 32000;
875 case HDSP_systemFrequency44_1: return 44100;
876 case HDSP_systemFrequency48: return 48000;
877 case HDSP_systemFrequency64: return 64000;
878 case HDSP_systemFrequency88_2: return 88200;
879 case HDSP_systemFrequency96: return 96000;
885 static int hdsp_spdif_sample_rate(hdsp_t *hdsp)
887 unsigned int status = hdsp_read(hdsp, HDSP_statusRegister);
888 unsigned int rate_bits = (status & HDSP_spdifFrequencyMask);
890 if (status & HDSP_SPDIFErrorFlag) {
895 case HDSP_spdifFrequency32KHz: return 32000;
896 case HDSP_spdifFrequency44_1KHz: return 44100;
897 case HDSP_spdifFrequency48KHz: return 48000;
898 case HDSP_spdifFrequency64KHz: return 64000;
899 case HDSP_spdifFrequency88_2KHz: return 88200;
900 case HDSP_spdifFrequency96KHz: return 96000;
901 case HDSP_spdifFrequency128KHz:
902 if (hdsp->io_type == H9632) return 128000;
904 case HDSP_spdifFrequency176_4KHz:
905 if (hdsp->io_type == H9632) return 176400;
907 case HDSP_spdifFrequency192KHz:
908 if (hdsp->io_type == H9632) return 192000;
913 snd_printk ("Hammerfall-DSP: unknown spdif frequency status; bits = 0x%x, status = 0x%x\n", rate_bits, status);
917 static void hdsp_compute_period_size(hdsp_t *hdsp)
919 hdsp->period_bytes = 1 << ((hdsp_decode_latency(hdsp->control_register) + 8));
922 static snd_pcm_uframes_t hdsp_hw_pointer(hdsp_t *hdsp)
926 position = hdsp_read(hdsp, HDSP_statusRegister);
928 if (!hdsp->precise_ptr) {
929 return (position & HDSP_BufferID) ? (hdsp->period_bytes / 4) : 0;
932 position &= HDSP_BufferPositionMask;
934 position &= (hdsp->period_bytes/2) - 1;
938 static void hdsp_reset_hw_pointer(hdsp_t *hdsp)
940 hdsp_write (hdsp, HDSP_resetPointer, 0);
943 static void hdsp_start_audio(hdsp_t *s)
945 s->control_register |= (HDSP_AudioInterruptEnable | HDSP_Start);
946 hdsp_write(s, HDSP_controlRegister, s->control_register);
949 static void hdsp_stop_audio(hdsp_t *s)
951 s->control_register &= ~(HDSP_Start | HDSP_AudioInterruptEnable);
952 hdsp_write(s, HDSP_controlRegister, s->control_register);
955 static void hdsp_silence_playback(hdsp_t *hdsp)
957 memset(hdsp->playback_buffer, 0, HDSP_DMA_AREA_BYTES);
960 static int hdsp_set_interrupt_interval(hdsp_t *s, unsigned int frames)
964 spin_lock_irq(&s->lock);
973 s->control_register &= ~HDSP_LatencyMask;
974 s->control_register |= hdsp_encode_latency(n);
976 hdsp_write(s, HDSP_controlRegister, s->control_register);
978 hdsp_compute_period_size(s);
980 spin_unlock_irq(&s->lock);
985 static int hdsp_set_rate(hdsp_t *hdsp, int rate, int called_internally)
987 int reject_if_open = 0;
991 /* ASSUMPTION: hdsp->lock is either held, or
992 there is no need for it (e.g. during module
996 if (!(hdsp->control_register & HDSP_ClockModeMaster)) {
997 if (called_internally) {
998 /* request from ctl or card initialization */
999 snd_printk("Hammerfall-DSP: device is not running as a clock master: cannot set sample rate.\n");
1002 /* hw_param request while in AutoSync mode */
1003 int external_freq = hdsp_external_sample_rate(hdsp);
1004 int spdif_freq = hdsp_spdif_sample_rate(hdsp);
1006 if ((spdif_freq == external_freq*2) && (hdsp_autosync_ref(hdsp) >= HDSP_AUTOSYNC_FROM_ADAT1)) {
1007 snd_printk("Hammerfall-DSP: Detected ADAT in double speed mode\n");
1008 } else if (hdsp->io_type == H9632 && (spdif_freq == external_freq*4) && (hdsp_autosync_ref(hdsp) >= HDSP_AUTOSYNC_FROM_ADAT1)) {
1009 snd_printk("Hammerfall-DSP: Detected ADAT in quad speed mode\n");
1010 } else if (rate != external_freq) {
1011 snd_printk("Hammerfall-DSP: No AutoSync source for requested rate\n");
1017 current_rate = hdsp->system_sample_rate;
1019 /* Changing from a "single speed" to a "double speed" rate is
1020 not allowed if any substreams are open. This is because
1021 such a change causes a shift in the location of
1022 the DMA buffers and a reduction in the number of available
1025 Note that a similar but essentially insoluble problem
1026 exists for externally-driven rate changes. All we can do
1027 is to flag rate changes in the read/write routines. */
1029 if (rate > 96000 && hdsp->io_type != H9632) {
1035 if (current_rate > 48000) {
1038 rate_bits = HDSP_Frequency32KHz;
1041 if (current_rate > 48000) {
1044 rate_bits = HDSP_Frequency44_1KHz;
1047 if (current_rate > 48000) {
1050 rate_bits = HDSP_Frequency48KHz;
1053 if (current_rate <= 48000 || current_rate > 96000) {
1056 rate_bits = HDSP_Frequency64KHz;
1059 if (current_rate <= 48000 || current_rate > 96000) {
1062 rate_bits = HDSP_Frequency88_2KHz;
1065 if (current_rate <= 48000 || current_rate > 96000) {
1068 rate_bits = HDSP_Frequency96KHz;
1071 if (current_rate < 128000) {
1074 rate_bits = HDSP_Frequency128KHz;
1077 if (current_rate < 128000) {
1080 rate_bits = HDSP_Frequency176_4KHz;
1083 if (current_rate < 128000) {
1086 rate_bits = HDSP_Frequency192KHz;
1092 if (reject_if_open && (hdsp->capture_pid >= 0 || hdsp->playback_pid >= 0)) {
1093 snd_printk ("Hammerfall-DSP: cannot change speed mode (capture PID = %d, playback PID = %d)\n",
1095 hdsp->playback_pid);
1099 hdsp->control_register &= ~HDSP_FrequencyMask;
1100 hdsp->control_register |= rate_bits;
1101 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
1103 if (rate >= 128000) {
1104 hdsp->channel_map = channel_map_H9632_qs;
1105 } else if (rate > 48000) {
1106 if (hdsp->io_type == H9632) {
1107 hdsp->channel_map = channel_map_H9632_ds;
1109 hdsp->channel_map = channel_map_ds;
1112 switch (hdsp->io_type) {
1114 hdsp->channel_map = channel_map_mf_ss;
1118 hdsp->channel_map = channel_map_df_ss;
1121 hdsp->channel_map = channel_map_H9632_ss;
1124 /* should never happen */
1129 hdsp->system_sample_rate = rate;
1134 /*----------------------------------------------------------------------------
1136 ----------------------------------------------------------------------------*/
1138 static unsigned char snd_hdsp_midi_read_byte (hdsp_t *hdsp, int id)
1140 /* the hardware already does the relevant bit-mask with 0xff */
1142 return hdsp_read(hdsp, HDSP_midiDataIn1);
1144 return hdsp_read(hdsp, HDSP_midiDataIn0);
1148 static void snd_hdsp_midi_write_byte (hdsp_t *hdsp, int id, int val)
1150 /* the hardware already does the relevant bit-mask with 0xff */
1152 hdsp_write(hdsp, HDSP_midiDataOut1, val);
1154 hdsp_write(hdsp, HDSP_midiDataOut0, val);
1158 static int snd_hdsp_midi_input_available (hdsp_t *hdsp, int id)
1161 return (hdsp_read(hdsp, HDSP_midiStatusIn1) & 0xff);
1163 return (hdsp_read(hdsp, HDSP_midiStatusIn0) & 0xff);
1167 static int snd_hdsp_midi_output_possible (hdsp_t *hdsp, int id)
1169 int fifo_bytes_used;
1172 fifo_bytes_used = hdsp_read(hdsp, HDSP_midiStatusOut1) & 0xff;
1174 fifo_bytes_used = hdsp_read(hdsp, HDSP_midiStatusOut0) & 0xff;
1177 if (fifo_bytes_used < 128) {
1178 return 128 - fifo_bytes_used;
1184 static void snd_hdsp_flush_midi_input (hdsp_t *hdsp, int id)
1186 while (snd_hdsp_midi_input_available (hdsp, id)) {
1187 snd_hdsp_midi_read_byte (hdsp, id);
1191 static int snd_hdsp_midi_output_write (hdsp_midi_t *hmidi)
1193 unsigned long flags;
1197 unsigned char buf[128];
1199 /* Output is not interrupt driven */
1201 spin_lock_irqsave (&hmidi->lock, flags);
1202 if (hmidi->output) {
1203 if (!snd_rawmidi_transmit_empty (hmidi->output)) {
1204 if ((n_pending = snd_hdsp_midi_output_possible (hmidi->hdsp, hmidi->id)) > 0) {
1205 if (n_pending > (int)sizeof (buf))
1206 n_pending = sizeof (buf);
1208 if ((to_write = snd_rawmidi_transmit (hmidi->output, buf, n_pending)) > 0) {
1209 for (i = 0; i < to_write; ++i)
1210 snd_hdsp_midi_write_byte (hmidi->hdsp, hmidi->id, buf[i]);
1215 spin_unlock_irqrestore (&hmidi->lock, flags);
1219 static int snd_hdsp_midi_input_read (hdsp_midi_t *hmidi)
1221 unsigned char buf[128]; /* this buffer is designed to match the MIDI input FIFO size */
1222 unsigned long flags;
1226 spin_lock_irqsave (&hmidi->lock, flags);
1227 if ((n_pending = snd_hdsp_midi_input_available (hmidi->hdsp, hmidi->id)) > 0) {
1229 if (n_pending > (int)sizeof (buf)) {
1230 n_pending = sizeof (buf);
1232 for (i = 0; i < n_pending; ++i) {
1233 buf[i] = snd_hdsp_midi_read_byte (hmidi->hdsp, hmidi->id);
1236 snd_rawmidi_receive (hmidi->input, buf, n_pending);
1239 /* flush the MIDI input FIFO */
1240 while (--n_pending) {
1241 snd_hdsp_midi_read_byte (hmidi->hdsp, hmidi->id);
1247 hmidi->hdsp->control_register |= HDSP_Midi1InterruptEnable;
1249 hmidi->hdsp->control_register |= HDSP_Midi0InterruptEnable;
1251 hdsp_write(hmidi->hdsp, HDSP_controlRegister, hmidi->hdsp->control_register);
1252 spin_unlock_irqrestore (&hmidi->lock, flags);
1253 return snd_hdsp_midi_output_write (hmidi);
1256 static void snd_hdsp_midi_input_trigger(snd_rawmidi_substream_t * substream, int up)
1260 unsigned long flags;
1263 hmidi = (hdsp_midi_t *) substream->rmidi->private_data;
1265 ie = hmidi->id ? HDSP_Midi1InterruptEnable : HDSP_Midi0InterruptEnable;
1266 spin_lock_irqsave (&hdsp->lock, flags);
1268 if (!(hdsp->control_register & ie)) {
1269 snd_hdsp_flush_midi_input (hdsp, hmidi->id);
1270 hdsp->control_register |= ie;
1273 hdsp->control_register &= ~ie;
1274 tasklet_kill(&hdsp->midi_tasklet);
1277 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
1278 spin_unlock_irqrestore (&hdsp->lock, flags);
1281 static void snd_hdsp_midi_output_timer(unsigned long data)
1283 hdsp_midi_t *hmidi = (hdsp_midi_t *) data;
1284 unsigned long flags;
1286 snd_hdsp_midi_output_write(hmidi);
1287 spin_lock_irqsave (&hmidi->lock, flags);
1289 /* this does not bump hmidi->istimer, because the
1290 kernel automatically removed the timer when it
1291 expired, and we are now adding it back, thus
1292 leaving istimer wherever it was set before.
1295 if (hmidi->istimer) {
1296 hmidi->timer.expires = 1 + jiffies;
1297 add_timer(&hmidi->timer);
1300 spin_unlock_irqrestore (&hmidi->lock, flags);
1303 static void snd_hdsp_midi_output_trigger(snd_rawmidi_substream_t * substream, int up)
1306 unsigned long flags;
1308 hmidi = (hdsp_midi_t *) substream->rmidi->private_data;
1309 spin_lock_irqsave (&hmidi->lock, flags);
1311 if (!hmidi->istimer) {
1312 init_timer(&hmidi->timer);
1313 hmidi->timer.function = snd_hdsp_midi_output_timer;
1314 hmidi->timer.data = (unsigned long) hmidi;
1315 hmidi->timer.expires = 1 + jiffies;
1316 add_timer(&hmidi->timer);
1320 if (hmidi->istimer && --hmidi->istimer <= 0) {
1321 del_timer (&hmidi->timer);
1324 spin_unlock_irqrestore (&hmidi->lock, flags);
1326 snd_hdsp_midi_output_write(hmidi);
1329 static int snd_hdsp_midi_input_open(snd_rawmidi_substream_t * substream)
1333 hmidi = (hdsp_midi_t *) substream->rmidi->private_data;
1334 spin_lock_irq (&hmidi->lock);
1335 snd_hdsp_flush_midi_input (hmidi->hdsp, hmidi->id);
1336 hmidi->input = substream;
1337 spin_unlock_irq (&hmidi->lock);
1342 static int snd_hdsp_midi_output_open(snd_rawmidi_substream_t * substream)
1346 hmidi = (hdsp_midi_t *) substream->rmidi->private_data;
1347 spin_lock_irq (&hmidi->lock);
1348 hmidi->output = substream;
1349 spin_unlock_irq (&hmidi->lock);
1354 static int snd_hdsp_midi_input_close(snd_rawmidi_substream_t * substream)
1358 snd_hdsp_midi_input_trigger (substream, 0);
1360 hmidi = (hdsp_midi_t *) substream->rmidi->private_data;
1361 spin_lock_irq (&hmidi->lock);
1362 hmidi->input = NULL;
1363 spin_unlock_irq (&hmidi->lock);
1368 static int snd_hdsp_midi_output_close(snd_rawmidi_substream_t * substream)
1372 snd_hdsp_midi_output_trigger (substream, 0);
1374 hmidi = (hdsp_midi_t *) substream->rmidi->private_data;
1375 spin_lock_irq (&hmidi->lock);
1376 hmidi->output = NULL;
1377 spin_unlock_irq (&hmidi->lock);
1382 static snd_rawmidi_ops_t snd_hdsp_midi_output =
1384 .open = snd_hdsp_midi_output_open,
1385 .close = snd_hdsp_midi_output_close,
1386 .trigger = snd_hdsp_midi_output_trigger,
1389 static snd_rawmidi_ops_t snd_hdsp_midi_input =
1391 .open = snd_hdsp_midi_input_open,
1392 .close = snd_hdsp_midi_input_close,
1393 .trigger = snd_hdsp_midi_input_trigger,
1396 static int __devinit snd_hdsp_create_midi (snd_card_t *card, hdsp_t *hdsp, int id)
1400 hdsp->midi[id].id = id;
1401 hdsp->midi[id].rmidi = NULL;
1402 hdsp->midi[id].input = NULL;
1403 hdsp->midi[id].output = NULL;
1404 hdsp->midi[id].hdsp = hdsp;
1405 hdsp->midi[id].istimer = 0;
1406 hdsp->midi[id].pending = 0;
1407 spin_lock_init (&hdsp->midi[id].lock);
1409 sprintf (buf, "%s MIDI %d", card->shortname, id+1);
1410 if (snd_rawmidi_new (card, buf, id, 1, 1, &hdsp->midi[id].rmidi) < 0) {
1414 sprintf (hdsp->midi[id].rmidi->name, "%s MIDI %d", card->id, id+1);
1415 hdsp->midi[id].rmidi->private_data = &hdsp->midi[id];
1417 snd_rawmidi_set_ops (hdsp->midi[id].rmidi, SNDRV_RAWMIDI_STREAM_OUTPUT, &snd_hdsp_midi_output);
1418 snd_rawmidi_set_ops (hdsp->midi[id].rmidi, SNDRV_RAWMIDI_STREAM_INPUT, &snd_hdsp_midi_input);
1420 hdsp->midi[id].rmidi->info_flags |= SNDRV_RAWMIDI_INFO_OUTPUT |
1421 SNDRV_RAWMIDI_INFO_INPUT |
1422 SNDRV_RAWMIDI_INFO_DUPLEX;
1427 /*-----------------------------------------------------------------------------
1429 ----------------------------------------------------------------------------*/
1431 static u32 snd_hdsp_convert_from_aes(snd_aes_iec958_t *aes)
1434 val |= (aes->status[0] & IEC958_AES0_PROFESSIONAL) ? HDSP_SPDIFProfessional : 0;
1435 val |= (aes->status[0] & IEC958_AES0_NONAUDIO) ? HDSP_SPDIFNonAudio : 0;
1436 if (val & HDSP_SPDIFProfessional)
1437 val |= (aes->status[0] & IEC958_AES0_PRO_EMPHASIS_5015) ? HDSP_SPDIFEmphasis : 0;
1439 val |= (aes->status[0] & IEC958_AES0_CON_EMPHASIS_5015) ? HDSP_SPDIFEmphasis : 0;
1443 static void snd_hdsp_convert_to_aes(snd_aes_iec958_t *aes, u32 val)
1445 aes->status[0] = ((val & HDSP_SPDIFProfessional) ? IEC958_AES0_PROFESSIONAL : 0) |
1446 ((val & HDSP_SPDIFNonAudio) ? IEC958_AES0_NONAUDIO : 0);
1447 if (val & HDSP_SPDIFProfessional)
1448 aes->status[0] |= (val & HDSP_SPDIFEmphasis) ? IEC958_AES0_PRO_EMPHASIS_5015 : 0;
1450 aes->status[0] |= (val & HDSP_SPDIFEmphasis) ? IEC958_AES0_CON_EMPHASIS_5015 : 0;
1453 static int snd_hdsp_control_spdif_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
1455 uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
1460 static int snd_hdsp_control_spdif_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1462 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
1464 snd_hdsp_convert_to_aes(&ucontrol->value.iec958, hdsp->creg_spdif);
1468 static int snd_hdsp_control_spdif_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1470 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
1474 val = snd_hdsp_convert_from_aes(&ucontrol->value.iec958);
1475 spin_lock_irq(&hdsp->lock);
1476 change = val != hdsp->creg_spdif;
1477 hdsp->creg_spdif = val;
1478 spin_unlock_irq(&hdsp->lock);
1482 static int snd_hdsp_control_spdif_stream_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
1484 uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
1489 static int snd_hdsp_control_spdif_stream_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1491 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
1493 snd_hdsp_convert_to_aes(&ucontrol->value.iec958, hdsp->creg_spdif_stream);
1497 static int snd_hdsp_control_spdif_stream_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1499 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
1503 val = snd_hdsp_convert_from_aes(&ucontrol->value.iec958);
1504 spin_lock_irq(&hdsp->lock);
1505 change = val != hdsp->creg_spdif_stream;
1506 hdsp->creg_spdif_stream = val;
1507 hdsp->control_register &= ~(HDSP_SPDIFProfessional | HDSP_SPDIFNonAudio | HDSP_SPDIFEmphasis);
1508 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register |= val);
1509 spin_unlock_irq(&hdsp->lock);
1513 static int snd_hdsp_control_spdif_mask_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
1515 uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
1520 static int snd_hdsp_control_spdif_mask_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1522 ucontrol->value.iec958.status[0] = kcontrol->private_value;
1526 #define HDSP_SPDIF_IN(xname, xindex) \
1527 { .iface = SNDRV_CTL_ELEM_IFACE_PCM, \
1530 .info = snd_hdsp_info_spdif_in, \
1531 .get = snd_hdsp_get_spdif_in, \
1532 .put = snd_hdsp_put_spdif_in }
1534 static unsigned int hdsp_spdif_in(hdsp_t *hdsp)
1536 return hdsp_decode_spdif_in(hdsp->control_register & HDSP_SPDIFInputMask);
1539 static int hdsp_set_spdif_input(hdsp_t *hdsp, int in)
1541 hdsp->control_register &= ~HDSP_SPDIFInputMask;
1542 hdsp->control_register |= hdsp_encode_spdif_in(in);
1543 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
1547 static int snd_hdsp_info_spdif_in(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
1549 static char *texts[4] = {"Optical", "Coaxial", "Internal", "AES"};
1550 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
1552 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1554 uinfo->value.enumerated.items = ((hdsp->io_type == H9632) ? 4 : 3);
1555 if (uinfo->value.enumerated.item > ((hdsp->io_type == H9632) ? 3 : 2))
1556 uinfo->value.enumerated.item = ((hdsp->io_type == H9632) ? 3 : 2);
1557 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1561 static int snd_hdsp_get_spdif_in(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1563 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
1565 ucontrol->value.enumerated.item[0] = hdsp_spdif_in(hdsp);
1569 static int snd_hdsp_put_spdif_in(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1571 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
1575 if (!snd_hdsp_use_is_exclusive(hdsp))
1577 val = ucontrol->value.enumerated.item[0] % ((hdsp->io_type == H9632) ? 4 : 3);
1578 spin_lock_irq(&hdsp->lock);
1579 change = val != hdsp_spdif_in(hdsp);
1581 hdsp_set_spdif_input(hdsp, val);
1582 spin_unlock_irq(&hdsp->lock);
1586 #define HDSP_SPDIF_OUT(xname, xindex) \
1587 { .iface = SNDRV_CTL_ELEM_IFACE_HWDEP, .name = xname, .index = xindex, \
1588 .info = snd_hdsp_info_spdif_bits, \
1589 .get = snd_hdsp_get_spdif_out, .put = snd_hdsp_put_spdif_out }
1591 static int hdsp_spdif_out(hdsp_t *hdsp)
1593 return (hdsp->control_register & HDSP_SPDIFOpticalOut) ? 1 : 0;
1596 static int hdsp_set_spdif_output(hdsp_t *hdsp, int out)
1599 hdsp->control_register |= HDSP_SPDIFOpticalOut;
1601 hdsp->control_register &= ~HDSP_SPDIFOpticalOut;
1603 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
1607 static int snd_hdsp_info_spdif_bits(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
1609 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
1611 uinfo->value.integer.min = 0;
1612 uinfo->value.integer.max = 1;
1616 static int snd_hdsp_get_spdif_out(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1618 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
1620 ucontrol->value.integer.value[0] = hdsp_spdif_out(hdsp);
1624 static int snd_hdsp_put_spdif_out(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1626 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
1630 if (!snd_hdsp_use_is_exclusive(hdsp))
1632 val = ucontrol->value.integer.value[0] & 1;
1633 spin_lock_irq(&hdsp->lock);
1634 change = (int)val != hdsp_spdif_out(hdsp);
1635 hdsp_set_spdif_output(hdsp, val);
1636 spin_unlock_irq(&hdsp->lock);
1640 #define HDSP_SPDIF_PROFESSIONAL(xname, xindex) \
1641 { .iface = SNDRV_CTL_ELEM_IFACE_HWDEP, .name = xname, .index = xindex, \
1642 .info = snd_hdsp_info_spdif_bits, \
1643 .get = snd_hdsp_get_spdif_professional, .put = snd_hdsp_put_spdif_professional }
1645 static int hdsp_spdif_professional(hdsp_t *hdsp)
1647 return (hdsp->control_register & HDSP_SPDIFProfessional) ? 1 : 0;
1650 static int hdsp_set_spdif_professional(hdsp_t *hdsp, int val)
1653 hdsp->control_register |= HDSP_SPDIFProfessional;
1655 hdsp->control_register &= ~HDSP_SPDIFProfessional;
1657 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
1661 static int snd_hdsp_get_spdif_professional(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1663 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
1665 ucontrol->value.integer.value[0] = hdsp_spdif_professional(hdsp);
1669 static int snd_hdsp_put_spdif_professional(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1671 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
1675 if (!snd_hdsp_use_is_exclusive(hdsp))
1677 val = ucontrol->value.integer.value[0] & 1;
1678 spin_lock_irq(&hdsp->lock);
1679 change = (int)val != hdsp_spdif_professional(hdsp);
1680 hdsp_set_spdif_professional(hdsp, val);
1681 spin_unlock_irq(&hdsp->lock);
1685 #define HDSP_SPDIF_EMPHASIS(xname, xindex) \
1686 { .iface = SNDRV_CTL_ELEM_IFACE_HWDEP, .name = xname, .index = xindex, \
1687 .info = snd_hdsp_info_spdif_bits, \
1688 .get = snd_hdsp_get_spdif_emphasis, .put = snd_hdsp_put_spdif_emphasis }
1690 static int hdsp_spdif_emphasis(hdsp_t *hdsp)
1692 return (hdsp->control_register & HDSP_SPDIFEmphasis) ? 1 : 0;
1695 static int hdsp_set_spdif_emphasis(hdsp_t *hdsp, int val)
1698 hdsp->control_register |= HDSP_SPDIFEmphasis;
1700 hdsp->control_register &= ~HDSP_SPDIFEmphasis;
1702 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
1706 static int snd_hdsp_get_spdif_emphasis(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1708 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
1710 ucontrol->value.integer.value[0] = hdsp_spdif_emphasis(hdsp);
1714 static int snd_hdsp_put_spdif_emphasis(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1716 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
1720 if (!snd_hdsp_use_is_exclusive(hdsp))
1722 val = ucontrol->value.integer.value[0] & 1;
1723 spin_lock_irq(&hdsp->lock);
1724 change = (int)val != hdsp_spdif_emphasis(hdsp);
1725 hdsp_set_spdif_emphasis(hdsp, val);
1726 spin_unlock_irq(&hdsp->lock);
1730 #define HDSP_SPDIF_NON_AUDIO(xname, xindex) \
1731 { .iface = SNDRV_CTL_ELEM_IFACE_HWDEP, .name = xname, .index = xindex, \
1732 .info = snd_hdsp_info_spdif_bits, \
1733 .get = snd_hdsp_get_spdif_nonaudio, .put = snd_hdsp_put_spdif_nonaudio }
1735 static int hdsp_spdif_nonaudio(hdsp_t *hdsp)
1737 return (hdsp->control_register & HDSP_SPDIFNonAudio) ? 1 : 0;
1740 static int hdsp_set_spdif_nonaudio(hdsp_t *hdsp, int val)
1743 hdsp->control_register |= HDSP_SPDIFNonAudio;
1745 hdsp->control_register &= ~HDSP_SPDIFNonAudio;
1747 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
1751 static int snd_hdsp_get_spdif_nonaudio(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1753 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
1755 ucontrol->value.integer.value[0] = hdsp_spdif_nonaudio(hdsp);
1759 static int snd_hdsp_put_spdif_nonaudio(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1761 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
1765 if (!snd_hdsp_use_is_exclusive(hdsp))
1767 val = ucontrol->value.integer.value[0] & 1;
1768 spin_lock_irq(&hdsp->lock);
1769 change = (int)val != hdsp_spdif_nonaudio(hdsp);
1770 hdsp_set_spdif_nonaudio(hdsp, val);
1771 spin_unlock_irq(&hdsp->lock);
1775 #define HDSP_SPDIF_SAMPLE_RATE(xname, xindex) \
1776 { .iface = SNDRV_CTL_ELEM_IFACE_HWDEP, \
1779 .access = SNDRV_CTL_ELEM_ACCESS_READ, \
1780 .info = snd_hdsp_info_spdif_sample_rate, \
1781 .get = snd_hdsp_get_spdif_sample_rate \
1784 static int snd_hdsp_info_spdif_sample_rate(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
1786 static char *texts[] = {"32000", "44100", "48000", "64000", "88200", "96000", "None", "128000", "176400", "192000"};
1787 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
1789 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1791 uinfo->value.enumerated.items = (hdsp->io_type == H9632) ? 10 : 7;
1792 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
1793 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
1794 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1798 static int snd_hdsp_get_spdif_sample_rate(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1800 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
1802 switch (hdsp_spdif_sample_rate(hdsp)) {
1804 ucontrol->value.enumerated.item[0] = 0;
1807 ucontrol->value.enumerated.item[0] = 1;
1810 ucontrol->value.enumerated.item[0] = 2;
1813 ucontrol->value.enumerated.item[0] = 3;
1816 ucontrol->value.enumerated.item[0] = 4;
1819 ucontrol->value.enumerated.item[0] = 5;
1822 ucontrol->value.enumerated.item[0] = 7;
1825 ucontrol->value.enumerated.item[0] = 8;
1828 ucontrol->value.enumerated.item[0] = 9;
1831 ucontrol->value.enumerated.item[0] = 6;
1836 #define HDSP_SYSTEM_SAMPLE_RATE(xname, xindex) \
1837 { .iface = SNDRV_CTL_ELEM_IFACE_HWDEP, \
1840 .access = SNDRV_CTL_ELEM_ACCESS_READ, \
1841 .info = snd_hdsp_info_system_sample_rate, \
1842 .get = snd_hdsp_get_system_sample_rate \
1845 static int snd_hdsp_info_system_sample_rate(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
1847 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1852 static int snd_hdsp_get_system_sample_rate(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1854 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
1856 ucontrol->value.enumerated.item[0] = hdsp->system_sample_rate;
1860 #define HDSP_AUTOSYNC_SAMPLE_RATE(xname, xindex) \
1861 { .iface = SNDRV_CTL_ELEM_IFACE_PCM, \
1864 .access = SNDRV_CTL_ELEM_ACCESS_READ, \
1865 .info = snd_hdsp_info_autosync_sample_rate, \
1866 .get = snd_hdsp_get_autosync_sample_rate \
1869 static int snd_hdsp_info_autosync_sample_rate(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
1871 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
1872 static char *texts[] = {"32000", "44100", "48000", "64000", "88200", "96000", "None", "128000", "176400", "192000"};
1873 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1875 uinfo->value.enumerated.items = (hdsp->io_type == H9632) ? 10 : 7 ;
1876 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
1877 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
1878 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1882 static int snd_hdsp_get_autosync_sample_rate(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1884 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
1886 switch (hdsp_external_sample_rate(hdsp)) {
1888 ucontrol->value.enumerated.item[0] = 0;
1891 ucontrol->value.enumerated.item[0] = 1;
1894 ucontrol->value.enumerated.item[0] = 2;
1897 ucontrol->value.enumerated.item[0] = 3;
1900 ucontrol->value.enumerated.item[0] = 4;
1903 ucontrol->value.enumerated.item[0] = 5;
1906 ucontrol->value.enumerated.item[0] = 7;
1909 ucontrol->value.enumerated.item[0] = 8;
1912 ucontrol->value.enumerated.item[0] = 9;
1915 ucontrol->value.enumerated.item[0] = 6;
1920 #define HDSP_SYSTEM_CLOCK_MODE(xname, xindex) \
1921 { .iface = SNDRV_CTL_ELEM_IFACE_HWDEP, \
1924 .access = SNDRV_CTL_ELEM_ACCESS_READ, \
1925 .info = snd_hdsp_info_system_clock_mode, \
1926 .get = snd_hdsp_get_system_clock_mode \
1929 static int hdsp_system_clock_mode(hdsp_t *hdsp)
1931 if (hdsp->control_register & HDSP_ClockModeMaster) {
1933 } else if (hdsp_external_sample_rate(hdsp) != hdsp->system_sample_rate) {
1939 static int snd_hdsp_info_system_clock_mode(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
1941 static char *texts[] = {"Master", "Slave" };
1943 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1945 uinfo->value.enumerated.items = 2;
1946 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
1947 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
1948 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1952 static int snd_hdsp_get_system_clock_mode(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1954 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
1956 ucontrol->value.enumerated.item[0] = hdsp_system_clock_mode(hdsp);
1960 #define HDSP_CLOCK_SOURCE(xname, xindex) \
1961 { .iface = SNDRV_CTL_ELEM_IFACE_PCM, \
1964 .info = snd_hdsp_info_clock_source, \
1965 .get = snd_hdsp_get_clock_source, \
1966 .put = snd_hdsp_put_clock_source \
1969 static int hdsp_clock_source(hdsp_t *hdsp)
1971 if (hdsp->control_register & HDSP_ClockModeMaster) {
1972 switch (hdsp->system_sample_rate) {
1999 static int hdsp_set_clock_source(hdsp_t *hdsp, int mode)
2003 case HDSP_CLOCK_SOURCE_AUTOSYNC:
2004 if (hdsp_external_sample_rate(hdsp) != 0) {
2005 if (!hdsp_set_rate(hdsp, hdsp_external_sample_rate(hdsp), 1)) {
2006 hdsp->control_register &= ~HDSP_ClockModeMaster;
2007 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
2012 case HDSP_CLOCK_SOURCE_INTERNAL_32KHZ:
2015 case HDSP_CLOCK_SOURCE_INTERNAL_44_1KHZ:
2018 case HDSP_CLOCK_SOURCE_INTERNAL_48KHZ:
2021 case HDSP_CLOCK_SOURCE_INTERNAL_64KHZ:
2024 case HDSP_CLOCK_SOURCE_INTERNAL_88_2KHZ:
2027 case HDSP_CLOCK_SOURCE_INTERNAL_96KHZ:
2030 case HDSP_CLOCK_SOURCE_INTERNAL_128KHZ:
2033 case HDSP_CLOCK_SOURCE_INTERNAL_176_4KHZ:
2036 case HDSP_CLOCK_SOURCE_INTERNAL_192KHZ:
2042 hdsp->control_register |= HDSP_ClockModeMaster;
2043 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
2044 hdsp_set_rate(hdsp, rate, 1);
2048 static int snd_hdsp_info_clock_source(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
2050 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" };
2051 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
2053 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2055 if (hdsp->io_type == H9632)
2056 uinfo->value.enumerated.items = 10;
2058 uinfo->value.enumerated.items = 7;
2059 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
2060 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
2061 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
2065 static int snd_hdsp_get_clock_source(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
2067 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
2069 ucontrol->value.enumerated.item[0] = hdsp_clock_source(hdsp);
2073 static int snd_hdsp_put_clock_source(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
2075 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
2079 if (!snd_hdsp_use_is_exclusive(hdsp))
2081 val = ucontrol->value.enumerated.item[0];
2082 if (val < 0) val = 0;
2083 if (hdsp->io_type == H9632) {
2084 if (val > 9) val = 9;
2086 if (val > 6) val = 6;
2088 spin_lock_irq(&hdsp->lock);
2089 if (val != hdsp_clock_source(hdsp)) {
2090 change = (hdsp_set_clock_source(hdsp, val) == 0) ? 1 : 0;
2094 spin_unlock_irq(&hdsp->lock);
2098 static int snd_hdsp_info_clock_source_lock(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
2100 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
2102 uinfo->value.integer.min = 0;
2103 uinfo->value.integer.max = 1;
2107 static int snd_hdsp_get_clock_source_lock(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
2109 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
2111 ucontrol->value.integer.value[0] = hdsp->clock_source_locked;
2115 static int snd_hdsp_put_clock_source_lock(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
2117 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
2120 change = (int)ucontrol->value.integer.value[0] != hdsp->clock_source_locked;
2122 hdsp->clock_source_locked = ucontrol->value.integer.value[0];
2126 #define HDSP_DA_GAIN(xname, xindex) \
2127 { .iface = SNDRV_CTL_ELEM_IFACE_HWDEP, \
2130 .info = snd_hdsp_info_da_gain, \
2131 .get = snd_hdsp_get_da_gain, \
2132 .put = snd_hdsp_put_da_gain \
2135 static int hdsp_da_gain(hdsp_t *hdsp)
2137 switch (hdsp->control_register & HDSP_DAGainMask) {
2138 case HDSP_DAGainHighGain:
2140 case HDSP_DAGainPlus4dBu:
2142 case HDSP_DAGainMinus10dBV:
2149 static int hdsp_set_da_gain(hdsp_t *hdsp, int mode)
2151 hdsp->control_register &= ~HDSP_DAGainMask;
2154 hdsp->control_register |= HDSP_DAGainHighGain;
2157 hdsp->control_register |= HDSP_DAGainPlus4dBu;
2160 hdsp->control_register |= HDSP_DAGainMinus10dBV;
2166 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
2170 static int snd_hdsp_info_da_gain(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
2172 static char *texts[] = {"Hi Gain", "+4 dBu", "-10 dbV"};
2174 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2176 uinfo->value.enumerated.items = 3;
2177 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
2178 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
2179 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
2183 static int snd_hdsp_get_da_gain(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
2185 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
2187 ucontrol->value.enumerated.item[0] = hdsp_da_gain(hdsp);
2191 static int snd_hdsp_put_da_gain(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
2193 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
2197 if (!snd_hdsp_use_is_exclusive(hdsp))
2199 val = ucontrol->value.enumerated.item[0];
2200 if (val < 0) val = 0;
2201 if (val > 2) val = 2;
2202 spin_lock_irq(&hdsp->lock);
2203 if (val != hdsp_da_gain(hdsp)) {
2204 change = (hdsp_set_da_gain(hdsp, val) == 0) ? 1 : 0;
2208 spin_unlock_irq(&hdsp->lock);
2212 #define HDSP_AD_GAIN(xname, xindex) \
2213 { .iface = SNDRV_CTL_ELEM_IFACE_HWDEP, \
2216 .info = snd_hdsp_info_ad_gain, \
2217 .get = snd_hdsp_get_ad_gain, \
2218 .put = snd_hdsp_put_ad_gain \
2221 static int hdsp_ad_gain(hdsp_t *hdsp)
2223 switch (hdsp->control_register & HDSP_ADGainMask) {
2224 case HDSP_ADGainMinus10dBV:
2226 case HDSP_ADGainPlus4dBu:
2228 case HDSP_ADGainLowGain:
2235 static int hdsp_set_ad_gain(hdsp_t *hdsp, int mode)
2237 hdsp->control_register &= ~HDSP_ADGainMask;
2240 hdsp->control_register |= HDSP_ADGainMinus10dBV;
2243 hdsp->control_register |= HDSP_ADGainPlus4dBu;
2246 hdsp->control_register |= HDSP_ADGainLowGain;
2252 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
2256 static int snd_hdsp_info_ad_gain(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
2258 static char *texts[] = {"-10 dBV", "+4 dBu", "Lo Gain"};
2260 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2262 uinfo->value.enumerated.items = 3;
2263 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
2264 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
2265 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
2269 static int snd_hdsp_get_ad_gain(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
2271 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
2273 ucontrol->value.enumerated.item[0] = hdsp_ad_gain(hdsp);
2277 static int snd_hdsp_put_ad_gain(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
2279 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
2283 if (!snd_hdsp_use_is_exclusive(hdsp))
2285 val = ucontrol->value.enumerated.item[0];
2286 if (val < 0) val = 0;
2287 if (val > 2) val = 2;
2288 spin_lock_irq(&hdsp->lock);
2289 if (val != hdsp_ad_gain(hdsp)) {
2290 change = (hdsp_set_ad_gain(hdsp, val) == 0) ? 1 : 0;
2294 spin_unlock_irq(&hdsp->lock);
2298 #define HDSP_PHONE_GAIN(xname, xindex) \
2299 { .iface = SNDRV_CTL_ELEM_IFACE_HWDEP, \
2302 .info = snd_hdsp_info_phone_gain, \
2303 .get = snd_hdsp_get_phone_gain, \
2304 .put = snd_hdsp_put_phone_gain \
2307 static int hdsp_phone_gain(hdsp_t *hdsp)
2309 switch (hdsp->control_register & HDSP_PhoneGainMask) {
2310 case HDSP_PhoneGain0dB:
2312 case HDSP_PhoneGainMinus6dB:
2314 case HDSP_PhoneGainMinus12dB:
2321 static int hdsp_set_phone_gain(hdsp_t *hdsp, int mode)
2323 hdsp->control_register &= ~HDSP_PhoneGainMask;
2326 hdsp->control_register |= HDSP_PhoneGain0dB;
2329 hdsp->control_register |= HDSP_PhoneGainMinus6dB;
2332 hdsp->control_register |= HDSP_PhoneGainMinus12dB;
2338 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
2342 static int snd_hdsp_info_phone_gain(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
2344 static char *texts[] = {"0 dB", "-6 dB", "-12 dB"};
2346 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2348 uinfo->value.enumerated.items = 3;
2349 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
2350 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
2351 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
2355 static int snd_hdsp_get_phone_gain(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
2357 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
2359 ucontrol->value.enumerated.item[0] = hdsp_phone_gain(hdsp);
2363 static int snd_hdsp_put_phone_gain(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
2365 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
2369 if (!snd_hdsp_use_is_exclusive(hdsp))
2371 val = ucontrol->value.enumerated.item[0];
2372 if (val < 0) val = 0;
2373 if (val > 2) val = 2;
2374 spin_lock_irq(&hdsp->lock);
2375 if (val != hdsp_phone_gain(hdsp)) {
2376 change = (hdsp_set_phone_gain(hdsp, val) == 0) ? 1 : 0;
2380 spin_unlock_irq(&hdsp->lock);
2384 #define HDSP_XLR_BREAKOUT_CABLE(xname, xindex) \
2385 { .iface = SNDRV_CTL_ELEM_IFACE_HWDEP, \
2388 .info = snd_hdsp_info_xlr_breakout_cable, \
2389 .get = snd_hdsp_get_xlr_breakout_cable, \
2390 .put = snd_hdsp_put_xlr_breakout_cable \
2393 static int hdsp_xlr_breakout_cable(hdsp_t *hdsp)
2395 if (hdsp->control_register & HDSP_XLRBreakoutCable) {
2401 static int hdsp_set_xlr_breakout_cable(hdsp_t *hdsp, int mode)
2404 hdsp->control_register |= HDSP_XLRBreakoutCable;
2406 hdsp->control_register &= ~HDSP_XLRBreakoutCable;
2408 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
2412 static int snd_hdsp_info_xlr_breakout_cable(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
2414 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
2416 uinfo->value.integer.min = 0;
2417 uinfo->value.integer.max = 1;
2421 static int snd_hdsp_get_xlr_breakout_cable(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
2423 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
2425 ucontrol->value.enumerated.item[0] = hdsp_xlr_breakout_cable(hdsp);
2429 static int snd_hdsp_put_xlr_breakout_cable(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
2431 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
2435 if (!snd_hdsp_use_is_exclusive(hdsp))
2437 val = ucontrol->value.integer.value[0] & 1;
2438 spin_lock_irq(&hdsp->lock);
2439 change = (int)val != hdsp_xlr_breakout_cable(hdsp);
2440 hdsp_set_xlr_breakout_cable(hdsp, val);
2441 spin_unlock_irq(&hdsp->lock);
2445 /* (De)activates old RME Analog Extension Board
2446 These are connected to the internal ADAT connector
2447 Switching this on desactivates external ADAT
2449 #define HDSP_AEB(xname, xindex) \
2450 { .iface = SNDRV_CTL_ELEM_IFACE_HWDEP, \
2453 .info = snd_hdsp_info_aeb, \
2454 .get = snd_hdsp_get_aeb, \
2455 .put = snd_hdsp_put_aeb \
2458 static int hdsp_aeb(hdsp_t *hdsp)
2460 if (hdsp->control_register & HDSP_AnalogExtensionBoard) {
2466 static int hdsp_set_aeb(hdsp_t *hdsp, int mode)
2469 hdsp->control_register |= HDSP_AnalogExtensionBoard;
2471 hdsp->control_register &= ~HDSP_AnalogExtensionBoard;
2473 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
2477 static int snd_hdsp_info_aeb(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
2479 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
2481 uinfo->value.integer.min = 0;
2482 uinfo->value.integer.max = 1;
2486 static int snd_hdsp_get_aeb(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
2488 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
2490 ucontrol->value.enumerated.item[0] = hdsp_aeb(hdsp);
2494 static int snd_hdsp_put_aeb(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
2496 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
2500 if (!snd_hdsp_use_is_exclusive(hdsp))
2502 val = ucontrol->value.integer.value[0] & 1;
2503 spin_lock_irq(&hdsp->lock);
2504 change = (int)val != hdsp_aeb(hdsp);
2505 hdsp_set_aeb(hdsp, val);
2506 spin_unlock_irq(&hdsp->lock);
2510 #define HDSP_PREF_SYNC_REF(xname, xindex) \
2511 { .iface = SNDRV_CTL_ELEM_IFACE_HWDEP, \
2514 .info = snd_hdsp_info_pref_sync_ref, \
2515 .get = snd_hdsp_get_pref_sync_ref, \
2516 .put = snd_hdsp_put_pref_sync_ref \
2519 static int hdsp_pref_sync_ref(hdsp_t *hdsp)
2521 /* Notice that this looks at the requested sync source,
2522 not the one actually in use.
2525 switch (hdsp->control_register & HDSP_SyncRefMask) {
2526 case HDSP_SyncRef_ADAT1:
2527 return HDSP_SYNC_FROM_ADAT1;
2528 case HDSP_SyncRef_ADAT2:
2529 return HDSP_SYNC_FROM_ADAT2;
2530 case HDSP_SyncRef_ADAT3:
2531 return HDSP_SYNC_FROM_ADAT3;
2532 case HDSP_SyncRef_SPDIF:
2533 return HDSP_SYNC_FROM_SPDIF;
2534 case HDSP_SyncRef_WORD:
2535 return HDSP_SYNC_FROM_WORD;
2536 case HDSP_SyncRef_ADAT_SYNC:
2537 return HDSP_SYNC_FROM_ADAT_SYNC;
2539 return HDSP_SYNC_FROM_WORD;
2544 static int hdsp_set_pref_sync_ref(hdsp_t *hdsp, int pref)
2546 hdsp->control_register &= ~HDSP_SyncRefMask;
2548 case HDSP_SYNC_FROM_ADAT1:
2549 hdsp->control_register &= ~HDSP_SyncRefMask; /* clear SyncRef bits */
2551 case HDSP_SYNC_FROM_ADAT2:
2552 hdsp->control_register |= HDSP_SyncRef_ADAT2;
2554 case HDSP_SYNC_FROM_ADAT3:
2555 hdsp->control_register |= HDSP_SyncRef_ADAT3;
2557 case HDSP_SYNC_FROM_SPDIF:
2558 hdsp->control_register |= HDSP_SyncRef_SPDIF;
2560 case HDSP_SYNC_FROM_WORD:
2561 hdsp->control_register |= HDSP_SyncRef_WORD;
2563 case HDSP_SYNC_FROM_ADAT_SYNC:
2564 hdsp->control_register |= HDSP_SyncRef_ADAT_SYNC;
2569 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
2573 static int snd_hdsp_info_pref_sync_ref(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
2575 static char *texts[] = {"Word", "IEC958", "ADAT1", "ADAT Sync", "ADAT2", "ADAT3" };
2576 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
2578 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2581 switch (hdsp->io_type) {
2584 uinfo->value.enumerated.items = 6;
2587 uinfo->value.enumerated.items = 4;
2590 uinfo->value.enumerated.items = 3;
2593 uinfo->value.enumerated.items = 0;
2597 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
2598 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
2599 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
2603 static int snd_hdsp_get_pref_sync_ref(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
2605 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
2607 ucontrol->value.enumerated.item[0] = hdsp_pref_sync_ref(hdsp);
2611 static int snd_hdsp_put_pref_sync_ref(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
2613 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
2617 if (!snd_hdsp_use_is_exclusive(hdsp))
2620 switch (hdsp->io_type) {
2635 val = ucontrol->value.enumerated.item[0] % max;
2636 spin_lock_irq(&hdsp->lock);
2637 change = (int)val != hdsp_pref_sync_ref(hdsp);
2638 hdsp_set_pref_sync_ref(hdsp, val);
2639 spin_unlock_irq(&hdsp->lock);
2643 #define HDSP_AUTOSYNC_REF(xname, xindex) \
2644 { .iface = SNDRV_CTL_ELEM_IFACE_HWDEP, \
2647 .access = SNDRV_CTL_ELEM_ACCESS_READ, \
2648 .info = snd_hdsp_info_autosync_ref, \
2649 .get = snd_hdsp_get_autosync_ref, \
2652 static int hdsp_autosync_ref(hdsp_t *hdsp)
2654 /* This looks at the autosync selected sync reference */
2655 unsigned int status2 = hdsp_read(hdsp, HDSP_status2Register);
2657 switch (status2 & HDSP_SelSyncRefMask) {
2658 case HDSP_SelSyncRef_WORD:
2659 return HDSP_AUTOSYNC_FROM_WORD;
2660 case HDSP_SelSyncRef_ADAT_SYNC:
2661 return HDSP_AUTOSYNC_FROM_ADAT_SYNC;
2662 case HDSP_SelSyncRef_SPDIF:
2663 return HDSP_AUTOSYNC_FROM_SPDIF;
2664 case HDSP_SelSyncRefMask:
2665 return HDSP_AUTOSYNC_FROM_NONE;
2666 case HDSP_SelSyncRef_ADAT1:
2667 return HDSP_AUTOSYNC_FROM_ADAT1;
2668 case HDSP_SelSyncRef_ADAT2:
2669 return HDSP_AUTOSYNC_FROM_ADAT2;
2670 case HDSP_SelSyncRef_ADAT3:
2671 return HDSP_AUTOSYNC_FROM_ADAT3;
2673 return HDSP_AUTOSYNC_FROM_WORD;
2678 static int snd_hdsp_info_autosync_ref(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
2680 static char *texts[] = {"Word", "ADAT Sync", "IEC958", "None", "ADAT1", "ADAT2", "ADAT3" };
2682 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2684 uinfo->value.enumerated.items = 7;
2685 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
2686 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
2687 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
2691 static int snd_hdsp_get_autosync_ref(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
2693 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
2695 ucontrol->value.enumerated.item[0] = hdsp_autosync_ref(hdsp);
2699 #define HDSP_LINE_OUT(xname, xindex) \
2700 { .iface = SNDRV_CTL_ELEM_IFACE_HWDEP, \
2703 .info = snd_hdsp_info_line_out, \
2704 .get = snd_hdsp_get_line_out, \
2705 .put = snd_hdsp_put_line_out \
2708 static int hdsp_line_out(hdsp_t *hdsp)
2710 return (hdsp->control_register & HDSP_LineOut) ? 1 : 0;
2713 static int hdsp_set_line_output(hdsp_t *hdsp, int out)
2716 hdsp->control_register |= HDSP_LineOut;
2718 hdsp->control_register &= ~HDSP_LineOut;
2720 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
2724 static int snd_hdsp_info_line_out(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
2726 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
2728 uinfo->value.integer.min = 0;
2729 uinfo->value.integer.max = 1;
2733 static int snd_hdsp_get_line_out(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
2735 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
2737 spin_lock_irq(&hdsp->lock);
2738 ucontrol->value.integer.value[0] = hdsp_line_out(hdsp);
2739 spin_unlock_irq(&hdsp->lock);
2743 static int snd_hdsp_put_line_out(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
2745 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
2749 if (!snd_hdsp_use_is_exclusive(hdsp))
2751 val = ucontrol->value.integer.value[0] & 1;
2752 spin_lock_irq(&hdsp->lock);
2753 change = (int)val != hdsp_line_out(hdsp);
2754 hdsp_set_line_output(hdsp, val);
2755 spin_unlock_irq(&hdsp->lock);
2759 #define HDSP_PRECISE_POINTER(xname, xindex) \
2760 { .iface = SNDRV_CTL_ELEM_IFACE_HWDEP, \
2763 .info = snd_hdsp_info_precise_pointer, \
2764 .get = snd_hdsp_get_precise_pointer, \
2765 .put = snd_hdsp_put_precise_pointer \
2768 static int hdsp_set_precise_pointer(hdsp_t *hdsp, int precise)
2771 hdsp->precise_ptr = 1;
2773 hdsp->precise_ptr = 0;
2778 static int snd_hdsp_info_precise_pointer(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
2780 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
2782 uinfo->value.integer.min = 0;
2783 uinfo->value.integer.max = 1;
2787 static int snd_hdsp_get_precise_pointer(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
2789 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
2791 spin_lock_irq(&hdsp->lock);
2792 ucontrol->value.integer.value[0] = hdsp->precise_ptr;
2793 spin_unlock_irq(&hdsp->lock);
2797 static int snd_hdsp_put_precise_pointer(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
2799 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
2803 if (!snd_hdsp_use_is_exclusive(hdsp))
2805 val = ucontrol->value.integer.value[0] & 1;
2806 spin_lock_irq(&hdsp->lock);
2807 change = (int)val != hdsp->precise_ptr;
2808 hdsp_set_precise_pointer(hdsp, val);
2809 spin_unlock_irq(&hdsp->lock);
2813 #define HDSP_USE_MIDI_TASKLET(xname, xindex) \
2814 { .iface = SNDRV_CTL_ELEM_IFACE_HWDEP, \
2817 .info = snd_hdsp_info_use_midi_tasklet, \
2818 .get = snd_hdsp_get_use_midi_tasklet, \
2819 .put = snd_hdsp_put_use_midi_tasklet \
2822 static int hdsp_set_use_midi_tasklet(hdsp_t *hdsp, int use_tasklet)
2825 hdsp->use_midi_tasklet = 1;
2827 hdsp->use_midi_tasklet = 0;
2832 static int snd_hdsp_info_use_midi_tasklet(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
2834 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
2836 uinfo->value.integer.min = 0;
2837 uinfo->value.integer.max = 1;
2841 static int snd_hdsp_get_use_midi_tasklet(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
2843 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
2845 spin_lock_irq(&hdsp->lock);
2846 ucontrol->value.integer.value[0] = hdsp->use_midi_tasklet;
2847 spin_unlock_irq(&hdsp->lock);
2851 static int snd_hdsp_put_use_midi_tasklet(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
2853 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
2857 if (!snd_hdsp_use_is_exclusive(hdsp))
2859 val = ucontrol->value.integer.value[0] & 1;
2860 spin_lock_irq(&hdsp->lock);
2861 change = (int)val != hdsp->use_midi_tasklet;
2862 hdsp_set_use_midi_tasklet(hdsp, val);
2863 spin_unlock_irq(&hdsp->lock);
2867 #define HDSP_MIXER(xname, xindex) \
2868 { .iface = SNDRV_CTL_ELEM_IFACE_HWDEP, \
2871 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | \
2872 SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
2873 .info = snd_hdsp_info_mixer, \
2874 .get = snd_hdsp_get_mixer, \
2875 .put = snd_hdsp_put_mixer \
2878 static int snd_hdsp_info_mixer(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
2880 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
2882 uinfo->value.integer.min = 0;
2883 uinfo->value.integer.max = 65536;
2884 uinfo->value.integer.step = 1;
2888 static int snd_hdsp_get_mixer(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
2890 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
2895 source = ucontrol->value.integer.value[0];
2896 destination = ucontrol->value.integer.value[1];
2898 if (source >= hdsp->max_channels) {
2899 addr = hdsp_playback_to_output_key(hdsp,source-hdsp->max_channels,destination);
2901 addr = hdsp_input_to_output_key(hdsp,source, destination);
2904 spin_lock_irq(&hdsp->lock);
2905 ucontrol->value.integer.value[2] = hdsp_read_gain (hdsp, addr);
2906 spin_unlock_irq(&hdsp->lock);
2910 static int snd_hdsp_put_mixer(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
2912 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
2919 if (!snd_hdsp_use_is_exclusive(hdsp))
2922 source = ucontrol->value.integer.value[0];
2923 destination = ucontrol->value.integer.value[1];
2925 if (source >= hdsp->max_channels) {
2926 addr = hdsp_playback_to_output_key(hdsp,source-hdsp->max_channels, destination);
2928 addr = hdsp_input_to_output_key(hdsp,source, destination);
2931 gain = ucontrol->value.integer.value[2];
2933 spin_lock_irq(&hdsp->lock);
2934 change = gain != hdsp_read_gain(hdsp, addr);
2936 hdsp_write_gain(hdsp, addr, gain);
2937 spin_unlock_irq(&hdsp->lock);
2941 #define HDSP_WC_SYNC_CHECK(xname, xindex) \
2942 { .iface = SNDRV_CTL_ELEM_IFACE_HWDEP, \
2945 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
2946 .info = snd_hdsp_info_sync_check, \
2947 .get = snd_hdsp_get_wc_sync_check \
2950 static int snd_hdsp_info_sync_check(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
2952 static char *texts[] = {"No Lock", "Lock", "Sync" };
2953 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2955 uinfo->value.enumerated.items = 3;
2956 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
2957 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
2958 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
2962 static int hdsp_wc_sync_check(hdsp_t *hdsp)
2964 int status2 = hdsp_read(hdsp, HDSP_status2Register);
2965 if (status2 & HDSP_wc_lock) {
2966 if (status2 & HDSP_wc_sync) {
2977 static int snd_hdsp_get_wc_sync_check(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
2979 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
2981 ucontrol->value.enumerated.item[0] = hdsp_wc_sync_check(hdsp);
2985 #define HDSP_SPDIF_SYNC_CHECK(xname, xindex) \
2986 { .iface = SNDRV_CTL_ELEM_IFACE_HWDEP, \
2989 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
2990 .info = snd_hdsp_info_sync_check, \
2991 .get = snd_hdsp_get_spdif_sync_check \
2994 static int hdsp_spdif_sync_check(hdsp_t *hdsp)
2996 int status = hdsp_read(hdsp, HDSP_statusRegister);
2997 if (status & HDSP_SPDIFErrorFlag) {
3000 if (status & HDSP_SPDIFSync) {
3009 static int snd_hdsp_get_spdif_sync_check(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
3011 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
3013 ucontrol->value.enumerated.item[0] = hdsp_spdif_sync_check(hdsp);
3017 #define HDSP_ADATSYNC_SYNC_CHECK(xname, xindex) \
3018 { .iface = SNDRV_CTL_ELEM_IFACE_HWDEP, \
3021 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
3022 .info = snd_hdsp_info_sync_check, \
3023 .get = snd_hdsp_get_adatsync_sync_check \
3026 static int hdsp_adatsync_sync_check(hdsp_t *hdsp)
3028 int status = hdsp_read(hdsp, HDSP_statusRegister);
3029 if (status & HDSP_TimecodeLock) {
3030 if (status & HDSP_TimecodeSync) {
3040 static int snd_hdsp_get_adatsync_sync_check(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
3042 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
3044 ucontrol->value.enumerated.item[0] = hdsp_adatsync_sync_check(hdsp);
3048 #define HDSP_ADAT_SYNC_CHECK \
3049 { .iface = SNDRV_CTL_ELEM_IFACE_HWDEP, \
3050 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
3051 .info = snd_hdsp_info_sync_check, \
3052 .get = snd_hdsp_get_adat_sync_check \
3055 static int hdsp_adat_sync_check(hdsp_t *hdsp, int idx)
3057 int status = hdsp_read(hdsp, HDSP_statusRegister);
3059 if (status & (HDSP_Lock0>>idx)) {
3060 if (status & (HDSP_Sync0>>idx)) {
3070 static int snd_hdsp_get_adat_sync_check(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
3073 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
3075 offset = ucontrol->id.index - 1;
3076 snd_assert(offset >= 0);
3078 switch (hdsp->io_type) {
3093 ucontrol->value.enumerated.item[0] = hdsp_adat_sync_check(hdsp, offset);
3097 static snd_kcontrol_new_t snd_hdsp_9632_controls[] = {
3098 HDSP_DA_GAIN("DA Gain", 0),
3099 HDSP_AD_GAIN("AD Gain", 0),
3100 HDSP_PHONE_GAIN("Phones Gain", 0),
3101 HDSP_XLR_BREAKOUT_CABLE("XLR Breakout Cable", 0)
3104 static snd_kcontrol_new_t snd_hdsp_controls[] = {
3106 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
3107 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,DEFAULT),
3108 .info = snd_hdsp_control_spdif_info,
3109 .get = snd_hdsp_control_spdif_get,
3110 .put = snd_hdsp_control_spdif_put,
3113 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_INACTIVE,
3114 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
3115 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,PCM_STREAM),
3116 .info = snd_hdsp_control_spdif_stream_info,
3117 .get = snd_hdsp_control_spdif_stream_get,
3118 .put = snd_hdsp_control_spdif_stream_put,
3121 .access = SNDRV_CTL_ELEM_ACCESS_READ,
3122 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3123 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,CON_MASK),
3124 .info = snd_hdsp_control_spdif_mask_info,
3125 .get = snd_hdsp_control_spdif_mask_get,
3126 .private_value = IEC958_AES0_NONAUDIO |
3127 IEC958_AES0_PROFESSIONAL |
3128 IEC958_AES0_CON_EMPHASIS,
3131 .access = SNDRV_CTL_ELEM_ACCESS_READ,
3132 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3133 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,PRO_MASK),
3134 .info = snd_hdsp_control_spdif_mask_info,
3135 .get = snd_hdsp_control_spdif_mask_get,
3136 .private_value = IEC958_AES0_NONAUDIO |
3137 IEC958_AES0_PROFESSIONAL |
3138 IEC958_AES0_PRO_EMPHASIS,
3140 HDSP_MIXER("Mixer", 0),
3141 HDSP_SPDIF_IN("IEC958 Input Connector", 0),
3142 HDSP_SPDIF_OUT("IEC958 Output also on ADAT1", 0),
3143 HDSP_SPDIF_PROFESSIONAL("IEC958 Professional Bit", 0),
3144 HDSP_SPDIF_EMPHASIS("IEC958 Emphasis Bit", 0),
3145 HDSP_SPDIF_NON_AUDIO("IEC958 Non-audio Bit", 0),
3146 /* 'Sample Clock Source' complies with the alsa control naming scheme */
3147 HDSP_CLOCK_SOURCE("Sample Clock Source", 0),
3149 /* FIXME: should be PCM or MIXER? */
3150 /* .iface = SNDRV_CTL_ELEM_IFACE_PCM, */
3151 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3152 .name = "Sample Clock Source Locking",
3153 .info = snd_hdsp_info_clock_source_lock,
3154 .get = snd_hdsp_get_clock_source_lock,
3155 .put = snd_hdsp_put_clock_source_lock,
3157 HDSP_SYSTEM_CLOCK_MODE("System Clock Mode", 0),
3158 HDSP_PREF_SYNC_REF("Preferred Sync Reference", 0),
3159 HDSP_AUTOSYNC_REF("AutoSync Reference", 0),
3160 HDSP_SPDIF_SAMPLE_RATE("SPDIF Sample Rate", 0),
3161 HDSP_SYSTEM_SAMPLE_RATE("System Sample Rate", 0),
3162 /* 'External Rate' complies with the alsa control naming scheme */
3163 HDSP_AUTOSYNC_SAMPLE_RATE("External Rate", 0),
3164 HDSP_WC_SYNC_CHECK("Word Clock Lock Status", 0),
3165 HDSP_SPDIF_SYNC_CHECK("SPDIF Lock Status", 0),
3166 HDSP_ADATSYNC_SYNC_CHECK("ADAT Sync Lock Status", 0),
3167 HDSP_LINE_OUT("Line Out", 0),
3168 HDSP_PRECISE_POINTER("Precise Pointer", 0),
3169 HDSP_USE_MIDI_TASKLET("Use Midi Tasklet", 0),
3172 static snd_kcontrol_new_t snd_hdsp_96xx_aeb = HDSP_AEB("Analog Extension Board", 0);
3173 static snd_kcontrol_new_t snd_hdsp_adat_sync_check = HDSP_ADAT_SYNC_CHECK;
3175 static int snd_hdsp_create_controls(snd_card_t *card, hdsp_t *hdsp)
3179 snd_kcontrol_t *kctl;
3181 for (idx = 0; idx < ARRAY_SIZE(snd_hdsp_controls); idx++) {
3182 if ((err = snd_ctl_add(card, kctl = snd_ctl_new1(&snd_hdsp_controls[idx], hdsp))) < 0) {
3185 if (idx == 1) /* IEC958 (S/PDIF) Stream */
3186 hdsp->spdif_ctl = kctl;
3189 /* ADAT SyncCheck status */
3190 snd_hdsp_adat_sync_check.name = "ADAT Lock Status";
3191 snd_hdsp_adat_sync_check.index = 1;
3192 if ((err = snd_ctl_add (card, kctl = snd_ctl_new1(&snd_hdsp_adat_sync_check, hdsp)))) {
3195 if (hdsp->io_type == Digiface || hdsp->io_type == H9652) {
3196 for (idx = 1; idx < 3; ++idx) {
3197 snd_hdsp_adat_sync_check.index = idx+1;
3198 if ((err = snd_ctl_add (card, kctl = snd_ctl_new1(&snd_hdsp_adat_sync_check, hdsp)))) {
3204 /* DA, AD and Phone gain and XLR breakout cable controls for H9632 cards */
3205 if (hdsp->io_type == H9632) {
3206 for (idx = 0; idx < ARRAY_SIZE(snd_hdsp_9632_controls); idx++) {
3207 if ((err = snd_ctl_add(card, kctl = snd_ctl_new1(&snd_hdsp_9632_controls[idx], hdsp))) < 0) {
3213 /* AEB control for H96xx card */
3214 if (hdsp->io_type == H9632 || hdsp->io_type == H9652) {
3215 if ((err = snd_ctl_add(card, kctl = snd_ctl_new1(&snd_hdsp_96xx_aeb, hdsp))) < 0) {
3223 /*------------------------------------------------------------
3225 ------------------------------------------------------------*/
3228 snd_hdsp_proc_read(snd_info_entry_t *entry, snd_info_buffer_t *buffer)
3230 hdsp_t *hdsp = (hdsp_t *) entry->private_data;
3231 unsigned int status;
3232 unsigned int status2;
3233 char *pref_sync_ref;
3235 char *system_clock_mode;
3239 if (hdsp_check_for_iobox (hdsp)) {
3240 snd_iprintf(buffer, "No I/O box connected.\nPlease connect one and upload firmware.\n");
3244 if (hdsp_check_for_firmware(hdsp)) {
3245 if (hdsp->state & HDSP_FirmwareCached) {
3246 if (snd_hdsp_load_firmware_from_cache(hdsp) != 0) {
3247 snd_iprintf(buffer, "Firmware loading from cache failed, please upload manually.\n");
3251 snd_iprintf(buffer, "No firmware loaded nor cached, please upload firmware.\n");
3256 status = hdsp_read(hdsp, HDSP_statusRegister);
3257 status2 = hdsp_read(hdsp, HDSP_status2Register);
3259 snd_iprintf(buffer, "%s (Card #%d)\n", hdsp->card_name, hdsp->card->number + 1);
3260 snd_iprintf(buffer, "Buffers: capture %p playback %p\n",
3261 hdsp->capture_buffer, hdsp->playback_buffer);
3262 snd_iprintf(buffer, "IRQ: %d Registers bus: 0x%lx VM: 0x%lx\n",
3263 hdsp->irq, hdsp->port, (unsigned long)hdsp->iobase);
3264 snd_iprintf(buffer, "Control register: 0x%x\n", hdsp->control_register);
3265 snd_iprintf(buffer, "Control2 register: 0x%x\n", hdsp->control2_register);
3266 snd_iprintf(buffer, "Status register: 0x%x\n", status);
3267 snd_iprintf(buffer, "Status2 register: 0x%x\n", status2);
3268 snd_iprintf(buffer, "FIFO status: %d\n", hdsp_read(hdsp, HDSP_fifoStatus) & 0xff);
3269 snd_iprintf(buffer, "MIDI1 Output status: 0x%x\n", hdsp_read(hdsp, HDSP_midiStatusOut0));
3270 snd_iprintf(buffer, "MIDI1 Input status: 0x%x\n", hdsp_read(hdsp, HDSP_midiStatusIn0));
3271 snd_iprintf(buffer, "MIDI2 Output status: 0x%x\n", hdsp_read(hdsp, HDSP_midiStatusOut1));
3272 snd_iprintf(buffer, "MIDI2 Input status: 0x%x\n", hdsp_read(hdsp, HDSP_midiStatusIn1));
3273 snd_iprintf(buffer, "Use Midi Tasklet: %s\n", hdsp->use_midi_tasklet ? "on" : "off");
3275 snd_iprintf(buffer, "\n");
3277 x = 1 << (6 + hdsp_decode_latency(hdsp->control_register & HDSP_LatencyMask));
3279 snd_iprintf(buffer, "Buffer Size (Latency): %d samples (2 periods of %lu bytes)\n", x, (unsigned long) hdsp->period_bytes);
3280 snd_iprintf(buffer, "Hardware pointer (frames): %ld\n", hdsp_hw_pointer(hdsp));
3281 snd_iprintf(buffer, "Precise pointer: %s\n", hdsp->precise_ptr ? "on" : "off");
3282 snd_iprintf(buffer, "Line out: %s\n", (hdsp->control_register & HDSP_LineOut) ? "on" : "off");
3284 snd_iprintf(buffer, "Firmware version: %d\n", (status2&HDSP_version0)|(status2&HDSP_version1)<<1|(status2&HDSP_version2)<<2);
3286 snd_iprintf(buffer, "\n");
3289 switch (hdsp_clock_source(hdsp)) {
3290 case HDSP_CLOCK_SOURCE_AUTOSYNC:
3291 clock_source = "AutoSync";
3293 case HDSP_CLOCK_SOURCE_INTERNAL_32KHZ:
3294 clock_source = "Internal 32 kHz";
3296 case HDSP_CLOCK_SOURCE_INTERNAL_44_1KHZ:
3297 clock_source = "Internal 44.1 kHz";
3299 case HDSP_CLOCK_SOURCE_INTERNAL_48KHZ:
3300 clock_source = "Internal 48 kHz";
3302 case HDSP_CLOCK_SOURCE_INTERNAL_64KHZ:
3303 clock_source = "Internal 64 kHz";
3305 case HDSP_CLOCK_SOURCE_INTERNAL_88_2KHZ:
3306 clock_source = "Internal 88.2 kHz";
3308 case HDSP_CLOCK_SOURCE_INTERNAL_96KHZ:
3309 clock_source = "Internal 96 kHz";
3311 case HDSP_CLOCK_SOURCE_INTERNAL_128KHZ:
3312 clock_source = "Internal 128 kHz";
3314 case HDSP_CLOCK_SOURCE_INTERNAL_176_4KHZ:
3315 clock_source = "Internal 176.4 kHz";
3317 case HDSP_CLOCK_SOURCE_INTERNAL_192KHZ:
3318 clock_source = "Internal 192 kHz";
3321 clock_source = "Error";
3323 snd_iprintf (buffer, "Sample Clock Source: %s\n", clock_source);
3325 if (hdsp_system_clock_mode(hdsp)) {
3326 system_clock_mode = "Slave";
3328 system_clock_mode = "Master";
3331 switch (hdsp_pref_sync_ref (hdsp)) {
3332 case HDSP_SYNC_FROM_WORD:
3333 pref_sync_ref = "Word Clock";
3335 case HDSP_SYNC_FROM_ADAT_SYNC:
3336 pref_sync_ref = "ADAT Sync";
3338 case HDSP_SYNC_FROM_SPDIF:
3339 pref_sync_ref = "SPDIF";
3341 case HDSP_SYNC_FROM_ADAT1:
3342 pref_sync_ref = "ADAT1";
3344 case HDSP_SYNC_FROM_ADAT2:
3345 pref_sync_ref = "ADAT2";
3347 case HDSP_SYNC_FROM_ADAT3:
3348 pref_sync_ref = "ADAT3";
3351 pref_sync_ref = "Word Clock";
3354 snd_iprintf (buffer, "Preferred Sync Reference: %s\n", pref_sync_ref);
3356 switch (hdsp_autosync_ref (hdsp)) {
3357 case HDSP_AUTOSYNC_FROM_WORD:
3358 autosync_ref = "Word Clock";
3360 case HDSP_AUTOSYNC_FROM_ADAT_SYNC:
3361 autosync_ref = "ADAT Sync";
3363 case HDSP_AUTOSYNC_FROM_SPDIF:
3364 autosync_ref = "SPDIF";
3366 case HDSP_AUTOSYNC_FROM_NONE:
3367 autosync_ref = "None";
3369 case HDSP_AUTOSYNC_FROM_ADAT1:
3370 autosync_ref = "ADAT1";
3372 case HDSP_AUTOSYNC_FROM_ADAT2:
3373 autosync_ref = "ADAT2";
3375 case HDSP_AUTOSYNC_FROM_ADAT3:
3376 autosync_ref = "ADAT3";
3379 autosync_ref = "---";
3382 snd_iprintf (buffer, "AutoSync Reference: %s\n", autosync_ref);
3384 snd_iprintf (buffer, "AutoSync Frequency: %d\n", hdsp_external_sample_rate(hdsp));
3386 snd_iprintf (buffer, "System Clock Mode: %s\n", system_clock_mode);
3388 snd_iprintf (buffer, "System Clock Frequency: %d\n", hdsp->system_sample_rate);
3389 snd_iprintf (buffer, "System Clock Locked: %s\n", hdsp->clock_source_locked ? "Yes" : "No");
3391 snd_iprintf(buffer, "\n");
3393 switch (hdsp_spdif_in(hdsp)) {
3394 case HDSP_SPDIFIN_OPTICAL:
3395 snd_iprintf(buffer, "IEC958 input: Optical\n");
3397 case HDSP_SPDIFIN_COAXIAL:
3398 snd_iprintf(buffer, "IEC958 input: Coaxial\n");
3400 case HDSP_SPDIFIN_INTERNAL:
3401 snd_iprintf(buffer, "IEC958 input: Internal\n");
3403 case HDSP_SPDIFIN_AES:
3404 snd_iprintf(buffer, "IEC958 input: AES\n");
3407 snd_iprintf(buffer, "IEC958 input: ???\n");
3411 if (hdsp->control_register & HDSP_SPDIFOpticalOut) {
3412 snd_iprintf(buffer, "IEC958 output: Coaxial & ADAT1\n");
3414 snd_iprintf(buffer, "IEC958 output: Coaxial only\n");
3417 if (hdsp->control_register & HDSP_SPDIFProfessional) {
3418 snd_iprintf(buffer, "IEC958 quality: Professional\n");
3420 snd_iprintf(buffer, "IEC958 quality: Consumer\n");
3423 if (hdsp->control_register & HDSP_SPDIFEmphasis) {
3424 snd_iprintf(buffer, "IEC958 emphasis: on\n");
3426 snd_iprintf(buffer, "IEC958 emphasis: off\n");
3429 if (hdsp->control_register & HDSP_SPDIFNonAudio) {
3430 snd_iprintf(buffer, "IEC958 NonAudio: on\n");
3432 snd_iprintf(buffer, "IEC958 NonAudio: off\n");