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 <linux/init.h>
25 #include <linux/delay.h>
26 #include <linux/interrupt.h>
27 #include <linux/slab.h>
28 #include <linux/pci.h>
29 #include <linux/firmware.h>
30 #include <linux/moduleparam.h>
31 #include <linux/math64.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 MODULE_FIRMWARE("multiface_firmware.bin");
65 MODULE_FIRMWARE("multiface_firmware_rev11.bin");
66 MODULE_FIRMWARE("digiface_firmware.bin");
67 MODULE_FIRMWARE("digiface_firmware_rev11.bin");
70 #define HDSP_MAX_CHANNELS 26
71 #define HDSP_MAX_DS_CHANNELS 14
72 #define HDSP_MAX_QS_CHANNELS 8
73 #define DIGIFACE_SS_CHANNELS 26
74 #define DIGIFACE_DS_CHANNELS 14
75 #define MULTIFACE_SS_CHANNELS 18
76 #define MULTIFACE_DS_CHANNELS 14
77 #define H9652_SS_CHANNELS 26
78 #define H9652_DS_CHANNELS 14
79 /* This does not include possible Analog Extension Boards
80 AEBs are detected at card initialization
82 #define H9632_SS_CHANNELS 12
83 #define H9632_DS_CHANNELS 8
84 #define H9632_QS_CHANNELS 4
86 /* Write registers. These are defined as byte-offsets from the iobase value.
88 #define HDSP_resetPointer 0
89 #define HDSP_freqReg 0
90 #define HDSP_outputBufferAddress 32
91 #define HDSP_inputBufferAddress 36
92 #define HDSP_controlRegister 64
93 #define HDSP_interruptConfirmation 96
94 #define HDSP_outputEnable 128
95 #define HDSP_control2Reg 256
96 #define HDSP_midiDataOut0 352
97 #define HDSP_midiDataOut1 356
98 #define HDSP_fifoData 368
99 #define HDSP_inputEnable 384
101 /* Read registers. These are defined as byte-offsets from the iobase value
104 #define HDSP_statusRegister 0
105 #define HDSP_timecode 128
106 #define HDSP_status2Register 192
107 #define HDSP_midiDataIn0 360
108 #define HDSP_midiDataIn1 364
109 #define HDSP_midiStatusOut0 384
110 #define HDSP_midiStatusOut1 388
111 #define HDSP_midiStatusIn0 392
112 #define HDSP_midiStatusIn1 396
113 #define HDSP_fifoStatus 400
115 /* the meters are regular i/o-mapped registers, but offset
116 considerably from the rest. the peak registers are reset
117 when read; the least-significant 4 bits are full-scale counters;
118 the actual peak value is in the most-significant 24 bits.
121 #define HDSP_playbackPeakLevel 4096 /* 26 * 32 bit values */
122 #define HDSP_inputPeakLevel 4224 /* 26 * 32 bit values */
123 #define HDSP_outputPeakLevel 4352 /* (26+2) * 32 bit values */
124 #define HDSP_playbackRmsLevel 4612 /* 26 * 64 bit values */
125 #define HDSP_inputRmsLevel 4868 /* 26 * 64 bit values */
128 /* This is for H9652 cards
129 Peak values are read downward from the base
130 Rms values are read upward
131 There are rms values for the outputs too
132 26*3 values are read in ss mode
133 14*3 in ds mode, with no gap between values
135 #define HDSP_9652_peakBase 7164
136 #define HDSP_9652_rmsBase 4096
138 /* c.f. the hdsp_9632_meters_t struct */
139 #define HDSP_9632_metersBase 4096
141 #define HDSP_IO_EXTENT 7168
143 /* control2 register bits */
145 #define HDSP_TMS 0x01
146 #define HDSP_TCK 0x02
147 #define HDSP_TDI 0x04
148 #define HDSP_JTAG 0x08
149 #define HDSP_PWDN 0x10
150 #define HDSP_PROGRAM 0x020
151 #define HDSP_CONFIG_MODE_0 0x040
152 #define HDSP_CONFIG_MODE_1 0x080
153 #define HDSP_VERSION_BIT 0x100
154 #define HDSP_BIGENDIAN_MODE 0x200
155 #define HDSP_RD_MULTIPLE 0x400
156 #define HDSP_9652_ENABLE_MIXER 0x800
157 #define HDSP_TDO 0x10000000
159 #define HDSP_S_PROGRAM (HDSP_PROGRAM|HDSP_CONFIG_MODE_0)
160 #define HDSP_S_LOAD (HDSP_PROGRAM|HDSP_CONFIG_MODE_1)
162 /* Control Register bits */
164 #define HDSP_Start (1<<0) /* start engine */
165 #define HDSP_Latency0 (1<<1) /* buffer size = 2^n where n is defined by Latency{2,1,0} */
166 #define HDSP_Latency1 (1<<2) /* [ see above ] */
167 #define HDSP_Latency2 (1<<3) /* [ see above ] */
168 #define HDSP_ClockModeMaster (1<<4) /* 1=Master, 0=Slave/Autosync */
169 #define HDSP_AudioInterruptEnable (1<<5) /* what do you think ? */
170 #define HDSP_Frequency0 (1<<6) /* 0=44.1kHz/88.2kHz/176.4kHz 1=48kHz/96kHz/192kHz */
171 #define HDSP_Frequency1 (1<<7) /* 0=32kHz/64kHz/128kHz */
172 #define HDSP_DoubleSpeed (1<<8) /* 0=normal speed, 1=double speed */
173 #define HDSP_SPDIFProfessional (1<<9) /* 0=consumer, 1=professional */
174 #define HDSP_SPDIFEmphasis (1<<10) /* 0=none, 1=on */
175 #define HDSP_SPDIFNonAudio (1<<11) /* 0=off, 1=on */
176 #define HDSP_SPDIFOpticalOut (1<<12) /* 1=use 1st ADAT connector for SPDIF, 0=do not */
177 #define HDSP_SyncRef2 (1<<13)
178 #define HDSP_SPDIFInputSelect0 (1<<14)
179 #define HDSP_SPDIFInputSelect1 (1<<15)
180 #define HDSP_SyncRef0 (1<<16)
181 #define HDSP_SyncRef1 (1<<17)
182 #define HDSP_AnalogExtensionBoard (1<<18) /* For H9632 cards */
183 #define HDSP_XLRBreakoutCable (1<<20) /* For H9632 cards */
184 #define HDSP_Midi0InterruptEnable (1<<22)
185 #define HDSP_Midi1InterruptEnable (1<<23)
186 #define HDSP_LineOut (1<<24)
187 #define HDSP_ADGain0 (1<<25) /* From here : H9632 specific */
188 #define HDSP_ADGain1 (1<<26)
189 #define HDSP_DAGain0 (1<<27)
190 #define HDSP_DAGain1 (1<<28)
191 #define HDSP_PhoneGain0 (1<<29)
192 #define HDSP_PhoneGain1 (1<<30)
193 #define HDSP_QuadSpeed (1<<31)
195 #define HDSP_ADGainMask (HDSP_ADGain0|HDSP_ADGain1)
196 #define HDSP_ADGainMinus10dBV HDSP_ADGainMask
197 #define HDSP_ADGainPlus4dBu (HDSP_ADGain0)
198 #define HDSP_ADGainLowGain 0
200 #define HDSP_DAGainMask (HDSP_DAGain0|HDSP_DAGain1)
201 #define HDSP_DAGainHighGain HDSP_DAGainMask
202 #define HDSP_DAGainPlus4dBu (HDSP_DAGain0)
203 #define HDSP_DAGainMinus10dBV 0
205 #define HDSP_PhoneGainMask (HDSP_PhoneGain0|HDSP_PhoneGain1)
206 #define HDSP_PhoneGain0dB HDSP_PhoneGainMask
207 #define HDSP_PhoneGainMinus6dB (HDSP_PhoneGain0)
208 #define HDSP_PhoneGainMinus12dB 0
210 #define HDSP_LatencyMask (HDSP_Latency0|HDSP_Latency1|HDSP_Latency2)
211 #define HDSP_FrequencyMask (HDSP_Frequency0|HDSP_Frequency1|HDSP_DoubleSpeed|HDSP_QuadSpeed)
213 #define HDSP_SPDIFInputMask (HDSP_SPDIFInputSelect0|HDSP_SPDIFInputSelect1)
214 #define HDSP_SPDIFInputADAT1 0
215 #define HDSP_SPDIFInputCoaxial (HDSP_SPDIFInputSelect0)
216 #define HDSP_SPDIFInputCdrom (HDSP_SPDIFInputSelect1)
217 #define HDSP_SPDIFInputAES (HDSP_SPDIFInputSelect0|HDSP_SPDIFInputSelect1)
219 #define HDSP_SyncRefMask (HDSP_SyncRef0|HDSP_SyncRef1|HDSP_SyncRef2)
220 #define HDSP_SyncRef_ADAT1 0
221 #define HDSP_SyncRef_ADAT2 (HDSP_SyncRef0)
222 #define HDSP_SyncRef_ADAT3 (HDSP_SyncRef1)
223 #define HDSP_SyncRef_SPDIF (HDSP_SyncRef0|HDSP_SyncRef1)
224 #define HDSP_SyncRef_WORD (HDSP_SyncRef2)
225 #define HDSP_SyncRef_ADAT_SYNC (HDSP_SyncRef0|HDSP_SyncRef2)
227 /* Sample Clock Sources */
229 #define HDSP_CLOCK_SOURCE_AUTOSYNC 0
230 #define HDSP_CLOCK_SOURCE_INTERNAL_32KHZ 1
231 #define HDSP_CLOCK_SOURCE_INTERNAL_44_1KHZ 2
232 #define HDSP_CLOCK_SOURCE_INTERNAL_48KHZ 3
233 #define HDSP_CLOCK_SOURCE_INTERNAL_64KHZ 4
234 #define HDSP_CLOCK_SOURCE_INTERNAL_88_2KHZ 5
235 #define HDSP_CLOCK_SOURCE_INTERNAL_96KHZ 6
236 #define HDSP_CLOCK_SOURCE_INTERNAL_128KHZ 7
237 #define HDSP_CLOCK_SOURCE_INTERNAL_176_4KHZ 8
238 #define HDSP_CLOCK_SOURCE_INTERNAL_192KHZ 9
240 /* Preferred sync reference choices - used by "pref_sync_ref" control switch */
242 #define HDSP_SYNC_FROM_WORD 0
243 #define HDSP_SYNC_FROM_SPDIF 1
244 #define HDSP_SYNC_FROM_ADAT1 2
245 #define HDSP_SYNC_FROM_ADAT_SYNC 3
246 #define HDSP_SYNC_FROM_ADAT2 4
247 #define HDSP_SYNC_FROM_ADAT3 5
249 /* SyncCheck status */
251 #define HDSP_SYNC_CHECK_NO_LOCK 0
252 #define HDSP_SYNC_CHECK_LOCK 1
253 #define HDSP_SYNC_CHECK_SYNC 2
255 /* AutoSync references - used by "autosync_ref" control switch */
257 #define HDSP_AUTOSYNC_FROM_WORD 0
258 #define HDSP_AUTOSYNC_FROM_ADAT_SYNC 1
259 #define HDSP_AUTOSYNC_FROM_SPDIF 2
260 #define HDSP_AUTOSYNC_FROM_NONE 3
261 #define HDSP_AUTOSYNC_FROM_ADAT1 4
262 #define HDSP_AUTOSYNC_FROM_ADAT2 5
263 #define HDSP_AUTOSYNC_FROM_ADAT3 6
265 /* Possible sources of S/PDIF input */
267 #define HDSP_SPDIFIN_OPTICAL 0 /* optical (ADAT1) */
268 #define HDSP_SPDIFIN_COAXIAL 1 /* coaxial (RCA) */
269 #define HDSP_SPDIFIN_INTERNAL 2 /* internal (CDROM) */
270 #define HDSP_SPDIFIN_AES 3 /* xlr for H9632 (AES)*/
272 #define HDSP_Frequency32KHz HDSP_Frequency0
273 #define HDSP_Frequency44_1KHz HDSP_Frequency1
274 #define HDSP_Frequency48KHz (HDSP_Frequency1|HDSP_Frequency0)
275 #define HDSP_Frequency64KHz (HDSP_DoubleSpeed|HDSP_Frequency0)
276 #define HDSP_Frequency88_2KHz (HDSP_DoubleSpeed|HDSP_Frequency1)
277 #define HDSP_Frequency96KHz (HDSP_DoubleSpeed|HDSP_Frequency1|HDSP_Frequency0)
278 /* For H9632 cards */
279 #define HDSP_Frequency128KHz (HDSP_QuadSpeed|HDSP_DoubleSpeed|HDSP_Frequency0)
280 #define HDSP_Frequency176_4KHz (HDSP_QuadSpeed|HDSP_DoubleSpeed|HDSP_Frequency1)
281 #define HDSP_Frequency192KHz (HDSP_QuadSpeed|HDSP_DoubleSpeed|HDSP_Frequency1|HDSP_Frequency0)
282 /* RME says n = 104857600000000, but in the windows MADI driver, I see:
283 return 104857600000000 / rate; // 100 MHz
284 return 110100480000000 / rate; // 105 MHz
286 #define DDS_NUMERATOR 104857600000000ULL; /* = 2^20 * 10^8 */
288 #define hdsp_encode_latency(x) (((x)<<1) & HDSP_LatencyMask)
289 #define hdsp_decode_latency(x) (((x) & HDSP_LatencyMask)>>1)
291 #define hdsp_encode_spdif_in(x) (((x)&0x3)<<14)
292 #define hdsp_decode_spdif_in(x) (((x)>>14)&0x3)
294 /* Status Register bits */
296 #define HDSP_audioIRQPending (1<<0)
297 #define HDSP_Lock2 (1<<1) /* this is for Digiface and H9652 */
298 #define HDSP_spdifFrequency3 HDSP_Lock2 /* this is for H9632 only */
299 #define HDSP_Lock1 (1<<2)
300 #define HDSP_Lock0 (1<<3)
301 #define HDSP_SPDIFSync (1<<4)
302 #define HDSP_TimecodeLock (1<<5)
303 #define HDSP_BufferPositionMask 0x000FFC0 /* Bit 6..15 : h/w buffer pointer */
304 #define HDSP_Sync2 (1<<16)
305 #define HDSP_Sync1 (1<<17)
306 #define HDSP_Sync0 (1<<18)
307 #define HDSP_DoubleSpeedStatus (1<<19)
308 #define HDSP_ConfigError (1<<20)
309 #define HDSP_DllError (1<<21)
310 #define HDSP_spdifFrequency0 (1<<22)
311 #define HDSP_spdifFrequency1 (1<<23)
312 #define HDSP_spdifFrequency2 (1<<24)
313 #define HDSP_SPDIFErrorFlag (1<<25)
314 #define HDSP_BufferID (1<<26)
315 #define HDSP_TimecodeSync (1<<27)
316 #define HDSP_AEBO (1<<28) /* H9632 specific Analog Extension Boards */
317 #define HDSP_AEBI (1<<29) /* 0 = present, 1 = absent */
318 #define HDSP_midi0IRQPending (1<<30)
319 #define HDSP_midi1IRQPending (1<<31)
321 #define HDSP_spdifFrequencyMask (HDSP_spdifFrequency0|HDSP_spdifFrequency1|HDSP_spdifFrequency2)
322 #define HDSP_spdifFrequencyMask_9632 (HDSP_spdifFrequency0|\
323 HDSP_spdifFrequency1|\
324 HDSP_spdifFrequency2|\
325 HDSP_spdifFrequency3)
327 #define HDSP_spdifFrequency32KHz (HDSP_spdifFrequency0)
328 #define HDSP_spdifFrequency44_1KHz (HDSP_spdifFrequency1)
329 #define HDSP_spdifFrequency48KHz (HDSP_spdifFrequency0|HDSP_spdifFrequency1)
331 #define HDSP_spdifFrequency64KHz (HDSP_spdifFrequency2)
332 #define HDSP_spdifFrequency88_2KHz (HDSP_spdifFrequency0|HDSP_spdifFrequency2)
333 #define HDSP_spdifFrequency96KHz (HDSP_spdifFrequency2|HDSP_spdifFrequency1)
335 /* This is for H9632 cards */
336 #define HDSP_spdifFrequency128KHz (HDSP_spdifFrequency0|\
337 HDSP_spdifFrequency1|\
338 HDSP_spdifFrequency2)
339 #define HDSP_spdifFrequency176_4KHz HDSP_spdifFrequency3
340 #define HDSP_spdifFrequency192KHz (HDSP_spdifFrequency3|HDSP_spdifFrequency0)
342 /* Status2 Register bits */
344 #define HDSP_version0 (1<<0)
345 #define HDSP_version1 (1<<1)
346 #define HDSP_version2 (1<<2)
347 #define HDSP_wc_lock (1<<3)
348 #define HDSP_wc_sync (1<<4)
349 #define HDSP_inp_freq0 (1<<5)
350 #define HDSP_inp_freq1 (1<<6)
351 #define HDSP_inp_freq2 (1<<7)
352 #define HDSP_SelSyncRef0 (1<<8)
353 #define HDSP_SelSyncRef1 (1<<9)
354 #define HDSP_SelSyncRef2 (1<<10)
356 #define HDSP_wc_valid (HDSP_wc_lock|HDSP_wc_sync)
358 #define HDSP_systemFrequencyMask (HDSP_inp_freq0|HDSP_inp_freq1|HDSP_inp_freq2)
359 #define HDSP_systemFrequency32 (HDSP_inp_freq0)
360 #define HDSP_systemFrequency44_1 (HDSP_inp_freq1)
361 #define HDSP_systemFrequency48 (HDSP_inp_freq0|HDSP_inp_freq1)
362 #define HDSP_systemFrequency64 (HDSP_inp_freq2)
363 #define HDSP_systemFrequency88_2 (HDSP_inp_freq0|HDSP_inp_freq2)
364 #define HDSP_systemFrequency96 (HDSP_inp_freq1|HDSP_inp_freq2)
365 /* FIXME : more values for 9632 cards ? */
367 #define HDSP_SelSyncRefMask (HDSP_SelSyncRef0|HDSP_SelSyncRef1|HDSP_SelSyncRef2)
368 #define HDSP_SelSyncRef_ADAT1 0
369 #define HDSP_SelSyncRef_ADAT2 (HDSP_SelSyncRef0)
370 #define HDSP_SelSyncRef_ADAT3 (HDSP_SelSyncRef1)
371 #define HDSP_SelSyncRef_SPDIF (HDSP_SelSyncRef0|HDSP_SelSyncRef1)
372 #define HDSP_SelSyncRef_WORD (HDSP_SelSyncRef2)
373 #define HDSP_SelSyncRef_ADAT_SYNC (HDSP_SelSyncRef0|HDSP_SelSyncRef2)
375 /* Card state flags */
377 #define HDSP_InitializationComplete (1<<0)
378 #define HDSP_FirmwareLoaded (1<<1)
379 #define HDSP_FirmwareCached (1<<2)
381 /* FIFO wait times, defined in terms of 1/10ths of msecs */
383 #define HDSP_LONG_WAIT 5000
384 #define HDSP_SHORT_WAIT 30
386 #define UNITY_GAIN 32768
387 #define MINUS_INFINITY_GAIN 0
389 /* the size of a substream (1 mono data stream) */
391 #define HDSP_CHANNEL_BUFFER_SAMPLES (16*1024)
392 #define HDSP_CHANNEL_BUFFER_BYTES (4*HDSP_CHANNEL_BUFFER_SAMPLES)
394 /* the size of the area we need to allocate for DMA transfers. the
395 size is the same regardless of the number of channels - the
396 Multiface still uses the same memory area.
398 Note that we allocate 1 more channel than is apparently needed
399 because the h/w seems to write 1 byte beyond the end of the last
403 #define HDSP_DMA_AREA_BYTES ((HDSP_MAX_CHANNELS+1) * HDSP_CHANNEL_BUFFER_BYTES)
404 #define HDSP_DMA_AREA_KILOBYTES (HDSP_DMA_AREA_BYTES/1024)
406 /* use hotplug firmware loader? */
407 #if defined(CONFIG_FW_LOADER) || defined(CONFIG_FW_LOADER_MODULE)
408 #if !defined(HDSP_USE_HWDEP_LOADER)
409 #define HDSP_FW_LOADER
413 struct hdsp_9632_meters {
415 u32 playback_peak[16];
419 u32 input_rms_low[16];
420 u32 playback_rms_low[16];
421 u32 output_rms_low[16];
423 u32 input_rms_high[16];
424 u32 playback_rms_high[16];
425 u32 output_rms_high[16];
426 u32 xxx_rms_high[16];
432 struct snd_rawmidi *rmidi;
433 struct snd_rawmidi_substream *input;
434 struct snd_rawmidi_substream *output;
435 char istimer; /* timer in use */
436 struct timer_list timer;
443 struct snd_pcm_substream *capture_substream;
444 struct snd_pcm_substream *playback_substream;
445 struct hdsp_midi midi[2];
446 struct tasklet_struct midi_tasklet;
447 int use_midi_tasklet;
449 u32 control_register; /* cached value */
450 u32 control2_register; /* cached value */
452 u32 creg_spdif_stream;
453 int clock_source_locked;
454 char *card_name; /* digiface/multiface */
455 enum HDSP_IO_Type io_type; /* ditto, but for code use */
456 unsigned short firmware_rev;
457 unsigned short state; /* stores state bits */
458 u32 firmware_cache[24413]; /* this helps recover from accidental iobox power failure */
459 size_t period_bytes; /* guess what this is */
460 unsigned char max_channels;
461 unsigned char qs_in_channels; /* quad speed mode for H9632 */
462 unsigned char ds_in_channels;
463 unsigned char ss_in_channels; /* different for multiface/digiface */
464 unsigned char qs_out_channels;
465 unsigned char ds_out_channels;
466 unsigned char ss_out_channels;
468 struct snd_dma_buffer capture_dma_buf;
469 struct snd_dma_buffer playback_dma_buf;
470 unsigned char *capture_buffer; /* suitably aligned address */
471 unsigned char *playback_buffer; /* suitably aligned address */
476 int system_sample_rate;
481 void __iomem *iobase;
482 struct snd_card *card;
484 struct snd_hwdep *hwdep;
486 struct snd_kcontrol *spdif_ctl;
487 unsigned short mixer_matrix[HDSP_MATRIX_MIXER_SIZE];
488 unsigned int dds_value; /* last value written to freq register */
491 /* These tables map the ALSA channels 1..N to the channels that we
492 need to use in order to find the relevant channel buffer. RME
493 refer to this kind of mapping as between "the ADAT channel and
494 the DMA channel." We index it using the logical audio channel,
495 and the value is the DMA channel (i.e. channel buffer number)
496 where the data for that channel can be read/written from/to.
499 static char channel_map_df_ss[HDSP_MAX_CHANNELS] = {
500 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
501 18, 19, 20, 21, 22, 23, 24, 25
504 static char channel_map_mf_ss[HDSP_MAX_CHANNELS] = { /* Multiface */
506 0, 1, 2, 3, 4, 5, 6, 7,
508 16, 17, 18, 19, 20, 21, 22, 23,
511 -1, -1, -1, -1, -1, -1, -1, -1
514 static char channel_map_ds[HDSP_MAX_CHANNELS] = {
515 /* ADAT channels are remapped */
516 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23,
517 /* channels 12 and 13 are S/PDIF */
519 /* others don't exist */
520 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
523 static char channel_map_H9632_ss[HDSP_MAX_CHANNELS] = {
525 0, 1, 2, 3, 4, 5, 6, 7,
530 /* AO4S-192 and AI4S-192 extension boards */
532 /* others don't exist */
533 -1, -1, -1, -1, -1, -1, -1, -1,
537 static char channel_map_H9632_ds[HDSP_MAX_CHANNELS] = {
544 /* AO4S-192 and AI4S-192 extension boards */
546 /* others don't exist */
547 -1, -1, -1, -1, -1, -1, -1, -1,
548 -1, -1, -1, -1, -1, -1
551 static char channel_map_H9632_qs[HDSP_MAX_CHANNELS] = {
552 /* ADAT is disabled in this mode */
557 /* AO4S-192 and AI4S-192 extension boards */
559 /* others don't exist */
560 -1, -1, -1, -1, -1, -1, -1, -1,
561 -1, -1, -1, -1, -1, -1, -1, -1,
565 static int snd_hammerfall_get_buffer(struct pci_dev *pci, struct snd_dma_buffer *dmab, size_t size)
567 dmab->dev.type = SNDRV_DMA_TYPE_DEV;
568 dmab->dev.dev = snd_dma_pci_data(pci);
569 if (snd_dma_get_reserved_buf(dmab, snd_dma_pci_buf_id(pci))) {
570 if (dmab->bytes >= size)
573 if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(pci),
579 static void snd_hammerfall_free_buffer(struct snd_dma_buffer *dmab, struct pci_dev *pci)
582 dmab->dev.dev = NULL; /* make it anonymous */
583 snd_dma_reserve_buf(dmab, snd_dma_pci_buf_id(pci));
588 static struct pci_device_id snd_hdsp_ids[] = {
590 .vendor = PCI_VENDOR_ID_XILINX,
591 .device = PCI_DEVICE_ID_XILINX_HAMMERFALL_DSP,
592 .subvendor = PCI_ANY_ID,
593 .subdevice = PCI_ANY_ID,
594 }, /* RME Hammerfall-DSP */
598 MODULE_DEVICE_TABLE(pci, snd_hdsp_ids);
601 static int snd_hdsp_create_alsa_devices(struct snd_card *card, struct hdsp *hdsp);
602 static int snd_hdsp_create_pcm(struct snd_card *card, struct hdsp *hdsp);
603 static int snd_hdsp_enable_io (struct hdsp *hdsp);
604 static void snd_hdsp_initialize_midi_flush (struct hdsp *hdsp);
605 static void snd_hdsp_initialize_channels (struct hdsp *hdsp);
606 static int hdsp_fifo_wait(struct hdsp *hdsp, int count, int timeout);
607 static int hdsp_autosync_ref(struct hdsp *hdsp);
608 static int snd_hdsp_set_defaults(struct hdsp *hdsp);
609 static void snd_hdsp_9652_enable_mixer (struct hdsp *hdsp);
611 static int hdsp_playback_to_output_key (struct hdsp *hdsp, int in, int out)
613 switch (hdsp->io_type) {
617 if (hdsp->firmware_rev == 0xa)
618 return (64 * out) + (32 + (in));
620 return (52 * out) + (26 + (in));
622 return (32 * out) + (16 + (in));
624 return (52 * out) + (26 + (in));
628 static int hdsp_input_to_output_key (struct hdsp *hdsp, int in, int out)
630 switch (hdsp->io_type) {
634 if (hdsp->firmware_rev == 0xa)
635 return (64 * out) + in;
637 return (52 * out) + in;
639 return (32 * out) + in;
641 return (52 * out) + in;
645 static void hdsp_write(struct hdsp *hdsp, int reg, int val)
647 writel(val, hdsp->iobase + reg);
650 static unsigned int hdsp_read(struct hdsp *hdsp, int reg)
652 return readl (hdsp->iobase + reg);
655 static int hdsp_check_for_iobox (struct hdsp *hdsp)
657 if (hdsp->io_type == H9652 || hdsp->io_type == H9632) return 0;
658 if (hdsp_read (hdsp, HDSP_statusRegister) & HDSP_ConfigError) {
659 snd_printk ("Hammerfall-DSP: no Digiface or Multiface connected!\n");
660 hdsp->state &= ~HDSP_FirmwareLoaded;
666 static int hdsp_wait_for_iobox(struct hdsp *hdsp, unsigned int loops,
671 if (hdsp->io_type == H9652 || hdsp->io_type == H9632)
674 for (i = 0; i != loops; ++i) {
675 if (hdsp_read(hdsp, HDSP_statusRegister) & HDSP_ConfigError)
678 snd_printd("Hammerfall-DSP: iobox found after %ums!\n",
684 snd_printk("Hammerfall-DSP: no Digiface or Multiface connected!\n");
685 hdsp->state &= ~HDSP_FirmwareLoaded;
689 static int snd_hdsp_load_firmware_from_cache(struct hdsp *hdsp) {
694 if ((hdsp_read (hdsp, HDSP_statusRegister) & HDSP_DllError) != 0) {
696 snd_printk ("Hammerfall-DSP: loading firmware\n");
698 hdsp_write (hdsp, HDSP_control2Reg, HDSP_S_PROGRAM);
699 hdsp_write (hdsp, HDSP_fifoData, 0);
701 if (hdsp_fifo_wait (hdsp, 0, HDSP_LONG_WAIT)) {
702 snd_printk ("Hammerfall-DSP: timeout waiting for download preparation\n");
706 hdsp_write (hdsp, HDSP_control2Reg, HDSP_S_LOAD);
708 for (i = 0; i < 24413; ++i) {
709 hdsp_write(hdsp, HDSP_fifoData, hdsp->firmware_cache[i]);
710 if (hdsp_fifo_wait (hdsp, 127, HDSP_LONG_WAIT)) {
711 snd_printk ("Hammerfall-DSP: timeout during firmware loading\n");
718 if (hdsp_fifo_wait (hdsp, 0, HDSP_LONG_WAIT)) {
719 snd_printk ("Hammerfall-DSP: timeout at end of firmware loading\n");
723 #ifdef SNDRV_BIG_ENDIAN
724 hdsp->control2_register = HDSP_BIGENDIAN_MODE;
726 hdsp->control2_register = 0;
728 hdsp_write (hdsp, HDSP_control2Reg, hdsp->control2_register);
729 snd_printk ("Hammerfall-DSP: finished firmware loading\n");
732 if (hdsp->state & HDSP_InitializationComplete) {
733 snd_printk(KERN_INFO "Hammerfall-DSP: firmware loaded from cache, restoring defaults\n");
734 spin_lock_irqsave(&hdsp->lock, flags);
735 snd_hdsp_set_defaults(hdsp);
736 spin_unlock_irqrestore(&hdsp->lock, flags);
739 hdsp->state |= HDSP_FirmwareLoaded;
744 static int hdsp_get_iobox_version (struct hdsp *hdsp)
746 if ((hdsp_read (hdsp, HDSP_statusRegister) & HDSP_DllError) != 0) {
748 hdsp_write (hdsp, HDSP_control2Reg, HDSP_PROGRAM);
749 hdsp_write (hdsp, HDSP_fifoData, 0);
750 if (hdsp_fifo_wait (hdsp, 0, HDSP_SHORT_WAIT) < 0)
753 hdsp_write (hdsp, HDSP_control2Reg, HDSP_S_LOAD);
754 hdsp_write (hdsp, HDSP_fifoData, 0);
756 if (hdsp_fifo_wait (hdsp, 0, HDSP_SHORT_WAIT)) {
757 hdsp->io_type = Multiface;
758 hdsp_write (hdsp, HDSP_control2Reg, HDSP_VERSION_BIT);
759 hdsp_write (hdsp, HDSP_control2Reg, HDSP_S_LOAD);
760 hdsp_fifo_wait (hdsp, 0, HDSP_SHORT_WAIT);
762 hdsp->io_type = Digiface;
765 /* firmware was already loaded, get iobox type */
766 if (hdsp_read(hdsp, HDSP_status2Register) & HDSP_version1)
767 hdsp->io_type = Multiface;
769 hdsp->io_type = Digiface;
775 #ifdef HDSP_FW_LOADER
776 static int hdsp_request_fw_loader(struct hdsp *hdsp);
779 static int hdsp_check_for_firmware (struct hdsp *hdsp, int load_on_demand)
781 if (hdsp->io_type == H9652 || hdsp->io_type == H9632)
783 if ((hdsp_read (hdsp, HDSP_statusRegister) & HDSP_DllError) != 0) {
784 hdsp->state &= ~HDSP_FirmwareLoaded;
785 if (! load_on_demand)
787 snd_printk(KERN_ERR "Hammerfall-DSP: firmware not present.\n");
788 /* try to load firmware */
789 if (! (hdsp->state & HDSP_FirmwareCached)) {
790 #ifdef HDSP_FW_LOADER
791 if (! hdsp_request_fw_loader(hdsp))
795 "Hammerfall-DSP: No firmware loaded nor "
796 "cached, please upload firmware.\n");
799 if (snd_hdsp_load_firmware_from_cache(hdsp) != 0) {
801 "Hammerfall-DSP: Firmware loading from "
802 "cache failed, please upload manually.\n");
810 static int hdsp_fifo_wait(struct hdsp *hdsp, int count, int timeout)
814 /* the fifoStatus registers reports on how many words
815 are available in the command FIFO.
818 for (i = 0; i < timeout; i++) {
820 if ((int)(hdsp_read (hdsp, HDSP_fifoStatus) & 0xff) <= count)
823 /* not very friendly, but we only do this during a firmware
824 load and changing the mixer, so we just put up with it.
830 snd_printk ("Hammerfall-DSP: wait for FIFO status <= %d failed after %d iterations\n",
835 static int hdsp_read_gain (struct hdsp *hdsp, unsigned int addr)
837 if (addr >= HDSP_MATRIX_MIXER_SIZE)
840 return hdsp->mixer_matrix[addr];
843 static int hdsp_write_gain(struct hdsp *hdsp, unsigned int addr, unsigned short data)
847 if (addr >= HDSP_MATRIX_MIXER_SIZE)
850 if (hdsp->io_type == H9652 || hdsp->io_type == H9632) {
852 /* from martin bjornsen:
854 "You can only write dwords to the
855 mixer memory which contain two
856 mixer values in the low and high
857 word. So if you want to change
858 value 0 you have to read value 1
859 from the cache and write both to
860 the first dword in the mixer
864 if (hdsp->io_type == H9632 && addr >= 512)
867 if (hdsp->io_type == H9652 && addr >= 1352)
870 hdsp->mixer_matrix[addr] = data;
873 /* `addr' addresses a 16-bit wide address, but
874 the address space accessed via hdsp_write
875 uses byte offsets. put another way, addr
876 varies from 0 to 1351, but to access the
877 corresponding memory location, we need
878 to access 0 to 2703 ...
882 hdsp_write (hdsp, 4096 + (ad*4),
883 (hdsp->mixer_matrix[(addr&0x7fe)+1] << 16) +
884 hdsp->mixer_matrix[addr&0x7fe]);
890 ad = (addr << 16) + data;
892 if (hdsp_fifo_wait(hdsp, 127, HDSP_LONG_WAIT))
895 hdsp_write (hdsp, HDSP_fifoData, ad);
896 hdsp->mixer_matrix[addr] = data;
903 static int snd_hdsp_use_is_exclusive(struct hdsp *hdsp)
908 spin_lock_irqsave(&hdsp->lock, flags);
909 if ((hdsp->playback_pid != hdsp->capture_pid) &&
910 (hdsp->playback_pid >= 0) && (hdsp->capture_pid >= 0))
912 spin_unlock_irqrestore(&hdsp->lock, flags);
916 static int hdsp_spdif_sample_rate(struct hdsp *hdsp)
918 unsigned int status = hdsp_read(hdsp, HDSP_statusRegister);
919 unsigned int rate_bits = (status & HDSP_spdifFrequencyMask);
921 /* For the 9632, the mask is different */
922 if (hdsp->io_type == H9632)
923 rate_bits = (status & HDSP_spdifFrequencyMask_9632);
925 if (status & HDSP_SPDIFErrorFlag)
929 case HDSP_spdifFrequency32KHz: return 32000;
930 case HDSP_spdifFrequency44_1KHz: return 44100;
931 case HDSP_spdifFrequency48KHz: return 48000;
932 case HDSP_spdifFrequency64KHz: return 64000;
933 case HDSP_spdifFrequency88_2KHz: return 88200;
934 case HDSP_spdifFrequency96KHz: return 96000;
935 case HDSP_spdifFrequency128KHz:
936 if (hdsp->io_type == H9632) return 128000;
938 case HDSP_spdifFrequency176_4KHz:
939 if (hdsp->io_type == H9632) return 176400;
941 case HDSP_spdifFrequency192KHz:
942 if (hdsp->io_type == H9632) return 192000;
947 snd_printk ("Hammerfall-DSP: unknown spdif frequency status; bits = 0x%x, status = 0x%x\n", rate_bits, status);
951 static int hdsp_external_sample_rate(struct hdsp *hdsp)
953 unsigned int status2 = hdsp_read(hdsp, HDSP_status2Register);
954 unsigned int rate_bits = status2 & HDSP_systemFrequencyMask;
956 /* For the 9632 card, there seems to be no bit for indicating external
957 * sample rate greater than 96kHz. The card reports the corresponding
958 * single speed. So the best means seems to get spdif rate when
959 * autosync reference is spdif */
960 if (hdsp->io_type == H9632 &&
961 hdsp_autosync_ref(hdsp) == HDSP_AUTOSYNC_FROM_SPDIF)
962 return hdsp_spdif_sample_rate(hdsp);
965 case HDSP_systemFrequency32: return 32000;
966 case HDSP_systemFrequency44_1: return 44100;
967 case HDSP_systemFrequency48: return 48000;
968 case HDSP_systemFrequency64: return 64000;
969 case HDSP_systemFrequency88_2: return 88200;
970 case HDSP_systemFrequency96: return 96000;
976 static void hdsp_compute_period_size(struct hdsp *hdsp)
978 hdsp->period_bytes = 1 << ((hdsp_decode_latency(hdsp->control_register) + 8));
981 static snd_pcm_uframes_t hdsp_hw_pointer(struct hdsp *hdsp)
985 position = hdsp_read(hdsp, HDSP_statusRegister);
987 if (!hdsp->precise_ptr)
988 return (position & HDSP_BufferID) ? (hdsp->period_bytes / 4) : 0;
990 position &= HDSP_BufferPositionMask;
992 position &= (hdsp->period_bytes/2) - 1;
996 static void hdsp_reset_hw_pointer(struct hdsp *hdsp)
998 hdsp_write (hdsp, HDSP_resetPointer, 0);
999 if (hdsp->io_type == H9632 && hdsp->firmware_rev >= 152)
1000 /* HDSP_resetPointer = HDSP_freqReg, which is strange and
1001 * requires (?) to write again DDS value after a reset pointer
1002 * (at least, it works like this) */
1003 hdsp_write (hdsp, HDSP_freqReg, hdsp->dds_value);
1006 static void hdsp_start_audio(struct hdsp *s)
1008 s->control_register |= (HDSP_AudioInterruptEnable | HDSP_Start);
1009 hdsp_write(s, HDSP_controlRegister, s->control_register);
1012 static void hdsp_stop_audio(struct hdsp *s)
1014 s->control_register &= ~(HDSP_Start | HDSP_AudioInterruptEnable);
1015 hdsp_write(s, HDSP_controlRegister, s->control_register);
1018 static void hdsp_silence_playback(struct hdsp *hdsp)
1020 memset(hdsp->playback_buffer, 0, HDSP_DMA_AREA_BYTES);
1023 static int hdsp_set_interrupt_interval(struct hdsp *s, unsigned int frames)
1027 spin_lock_irq(&s->lock);
1036 s->control_register &= ~HDSP_LatencyMask;
1037 s->control_register |= hdsp_encode_latency(n);
1039 hdsp_write(s, HDSP_controlRegister, s->control_register);
1041 hdsp_compute_period_size(s);
1043 spin_unlock_irq(&s->lock);
1048 static void hdsp_set_dds_value(struct hdsp *hdsp, int rate)
1054 else if (rate >= 56000)
1058 n = div_u64(n, rate);
1059 /* n should be less than 2^32 for being written to FREQ register */
1060 snd_BUG_ON(n >> 32);
1061 /* HDSP_freqReg and HDSP_resetPointer are the same, so keep the DDS
1062 value to write it after a reset */
1063 hdsp->dds_value = n;
1064 hdsp_write(hdsp, HDSP_freqReg, hdsp->dds_value);
1067 static int hdsp_set_rate(struct hdsp *hdsp, int rate, int called_internally)
1069 int reject_if_open = 0;
1073 /* ASSUMPTION: hdsp->lock is either held, or
1074 there is no need for it (e.g. during module
1078 if (!(hdsp->control_register & HDSP_ClockModeMaster)) {
1079 if (called_internally) {
1080 /* request from ctl or card initialization */
1081 snd_printk(KERN_ERR "Hammerfall-DSP: device is not running as a clock master: cannot set sample rate.\n");
1084 /* hw_param request while in AutoSync mode */
1085 int external_freq = hdsp_external_sample_rate(hdsp);
1086 int spdif_freq = hdsp_spdif_sample_rate(hdsp);
1088 if ((spdif_freq == external_freq*2) && (hdsp_autosync_ref(hdsp) >= HDSP_AUTOSYNC_FROM_ADAT1))
1089 snd_printk(KERN_INFO "Hammerfall-DSP: Detected ADAT in double speed mode\n");
1090 else if (hdsp->io_type == H9632 && (spdif_freq == external_freq*4) && (hdsp_autosync_ref(hdsp) >= HDSP_AUTOSYNC_FROM_ADAT1))
1091 snd_printk(KERN_INFO "Hammerfall-DSP: Detected ADAT in quad speed mode\n");
1092 else if (rate != external_freq) {
1093 snd_printk(KERN_INFO "Hammerfall-DSP: No AutoSync source for requested rate\n");
1099 current_rate = hdsp->system_sample_rate;
1101 /* Changing from a "single speed" to a "double speed" rate is
1102 not allowed if any substreams are open. This is because
1103 such a change causes a shift in the location of
1104 the DMA buffers and a reduction in the number of available
1107 Note that a similar but essentially insoluble problem
1108 exists for externally-driven rate changes. All we can do
1109 is to flag rate changes in the read/write routines. */
1111 if (rate > 96000 && hdsp->io_type != H9632)
1116 if (current_rate > 48000)
1118 rate_bits = HDSP_Frequency32KHz;
1121 if (current_rate > 48000)
1123 rate_bits = HDSP_Frequency44_1KHz;
1126 if (current_rate > 48000)
1128 rate_bits = HDSP_Frequency48KHz;
1131 if (current_rate <= 48000 || current_rate > 96000)
1133 rate_bits = HDSP_Frequency64KHz;
1136 if (current_rate <= 48000 || current_rate > 96000)
1138 rate_bits = HDSP_Frequency88_2KHz;
1141 if (current_rate <= 48000 || current_rate > 96000)
1143 rate_bits = HDSP_Frequency96KHz;
1146 if (current_rate < 128000)
1148 rate_bits = HDSP_Frequency128KHz;
1151 if (current_rate < 128000)
1153 rate_bits = HDSP_Frequency176_4KHz;
1156 if (current_rate < 128000)
1158 rate_bits = HDSP_Frequency192KHz;
1164 if (reject_if_open && (hdsp->capture_pid >= 0 || hdsp->playback_pid >= 0)) {
1165 snd_printk ("Hammerfall-DSP: cannot change speed mode (capture PID = %d, playback PID = %d)\n",
1167 hdsp->playback_pid);
1171 hdsp->control_register &= ~HDSP_FrequencyMask;
1172 hdsp->control_register |= rate_bits;
1173 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
1175 /* For HDSP9632 rev 152, need to set DDS value in FREQ register */
1176 if (hdsp->io_type == H9632 && hdsp->firmware_rev >= 152)
1177 hdsp_set_dds_value(hdsp, rate);
1179 if (rate >= 128000) {
1180 hdsp->channel_map = channel_map_H9632_qs;
1181 } else if (rate > 48000) {
1182 if (hdsp->io_type == H9632)
1183 hdsp->channel_map = channel_map_H9632_ds;
1185 hdsp->channel_map = channel_map_ds;
1187 switch (hdsp->io_type) {
1189 hdsp->channel_map = channel_map_mf_ss;
1193 hdsp->channel_map = channel_map_df_ss;
1196 hdsp->channel_map = channel_map_H9632_ss;
1199 /* should never happen */
1204 hdsp->system_sample_rate = rate;
1209 /*----------------------------------------------------------------------------
1211 ----------------------------------------------------------------------------*/
1213 static unsigned char snd_hdsp_midi_read_byte (struct hdsp *hdsp, int id)
1215 /* the hardware already does the relevant bit-mask with 0xff */
1217 return hdsp_read(hdsp, HDSP_midiDataIn1);
1219 return hdsp_read(hdsp, HDSP_midiDataIn0);
1222 static void snd_hdsp_midi_write_byte (struct hdsp *hdsp, int id, int val)
1224 /* the hardware already does the relevant bit-mask with 0xff */
1226 hdsp_write(hdsp, HDSP_midiDataOut1, val);
1228 hdsp_write(hdsp, HDSP_midiDataOut0, val);
1231 static int snd_hdsp_midi_input_available (struct hdsp *hdsp, int id)
1234 return (hdsp_read(hdsp, HDSP_midiStatusIn1) & 0xff);
1236 return (hdsp_read(hdsp, HDSP_midiStatusIn0) & 0xff);
1239 static int snd_hdsp_midi_output_possible (struct hdsp *hdsp, int id)
1241 int fifo_bytes_used;
1244 fifo_bytes_used = hdsp_read(hdsp, HDSP_midiStatusOut1) & 0xff;
1246 fifo_bytes_used = hdsp_read(hdsp, HDSP_midiStatusOut0) & 0xff;
1248 if (fifo_bytes_used < 128)
1249 return 128 - fifo_bytes_used;
1254 static void snd_hdsp_flush_midi_input (struct hdsp *hdsp, int id)
1256 while (snd_hdsp_midi_input_available (hdsp, id))
1257 snd_hdsp_midi_read_byte (hdsp, id);
1260 static int snd_hdsp_midi_output_write (struct hdsp_midi *hmidi)
1262 unsigned long flags;
1266 unsigned char buf[128];
1268 /* Output is not interrupt driven */
1270 spin_lock_irqsave (&hmidi->lock, flags);
1271 if (hmidi->output) {
1272 if (!snd_rawmidi_transmit_empty (hmidi->output)) {
1273 if ((n_pending = snd_hdsp_midi_output_possible (hmidi->hdsp, hmidi->id)) > 0) {
1274 if (n_pending > (int)sizeof (buf))
1275 n_pending = sizeof (buf);
1277 if ((to_write = snd_rawmidi_transmit (hmidi->output, buf, n_pending)) > 0) {
1278 for (i = 0; i < to_write; ++i)
1279 snd_hdsp_midi_write_byte (hmidi->hdsp, hmidi->id, buf[i]);
1284 spin_unlock_irqrestore (&hmidi->lock, flags);
1288 static int snd_hdsp_midi_input_read (struct hdsp_midi *hmidi)
1290 unsigned char buf[128]; /* this buffer is designed to match the MIDI input FIFO size */
1291 unsigned long flags;
1295 spin_lock_irqsave (&hmidi->lock, flags);
1296 if ((n_pending = snd_hdsp_midi_input_available (hmidi->hdsp, hmidi->id)) > 0) {
1298 if (n_pending > (int)sizeof (buf))
1299 n_pending = sizeof (buf);
1300 for (i = 0; i < n_pending; ++i)
1301 buf[i] = snd_hdsp_midi_read_byte (hmidi->hdsp, hmidi->id);
1303 snd_rawmidi_receive (hmidi->input, buf, n_pending);
1305 /* flush the MIDI input FIFO */
1307 snd_hdsp_midi_read_byte (hmidi->hdsp, hmidi->id);
1312 hmidi->hdsp->control_register |= HDSP_Midi1InterruptEnable;
1314 hmidi->hdsp->control_register |= HDSP_Midi0InterruptEnable;
1315 hdsp_write(hmidi->hdsp, HDSP_controlRegister, hmidi->hdsp->control_register);
1316 spin_unlock_irqrestore (&hmidi->lock, flags);
1317 return snd_hdsp_midi_output_write (hmidi);
1320 static void snd_hdsp_midi_input_trigger(struct snd_rawmidi_substream *substream, int up)
1323 struct hdsp_midi *hmidi;
1324 unsigned long flags;
1327 hmidi = (struct hdsp_midi *) substream->rmidi->private_data;
1329 ie = hmidi->id ? HDSP_Midi1InterruptEnable : HDSP_Midi0InterruptEnable;
1330 spin_lock_irqsave (&hdsp->lock, flags);
1332 if (!(hdsp->control_register & ie)) {
1333 snd_hdsp_flush_midi_input (hdsp, hmidi->id);
1334 hdsp->control_register |= ie;
1337 hdsp->control_register &= ~ie;
1338 tasklet_kill(&hdsp->midi_tasklet);
1341 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
1342 spin_unlock_irqrestore (&hdsp->lock, flags);
1345 static void snd_hdsp_midi_output_timer(unsigned long data)
1347 struct hdsp_midi *hmidi = (struct hdsp_midi *) data;
1348 unsigned long flags;
1350 snd_hdsp_midi_output_write(hmidi);
1351 spin_lock_irqsave (&hmidi->lock, flags);
1353 /* this does not bump hmidi->istimer, because the
1354 kernel automatically removed the timer when it
1355 expired, and we are now adding it back, thus
1356 leaving istimer wherever it was set before.
1359 if (hmidi->istimer) {
1360 hmidi->timer.expires = 1 + jiffies;
1361 add_timer(&hmidi->timer);
1364 spin_unlock_irqrestore (&hmidi->lock, flags);
1367 static void snd_hdsp_midi_output_trigger(struct snd_rawmidi_substream *substream, int up)
1369 struct hdsp_midi *hmidi;
1370 unsigned long flags;
1372 hmidi = (struct hdsp_midi *) substream->rmidi->private_data;
1373 spin_lock_irqsave (&hmidi->lock, flags);
1375 if (!hmidi->istimer) {
1376 init_timer(&hmidi->timer);
1377 hmidi->timer.function = snd_hdsp_midi_output_timer;
1378 hmidi->timer.data = (unsigned long) hmidi;
1379 hmidi->timer.expires = 1 + jiffies;
1380 add_timer(&hmidi->timer);
1384 if (hmidi->istimer && --hmidi->istimer <= 0)
1385 del_timer (&hmidi->timer);
1387 spin_unlock_irqrestore (&hmidi->lock, flags);
1389 snd_hdsp_midi_output_write(hmidi);
1392 static int snd_hdsp_midi_input_open(struct snd_rawmidi_substream *substream)
1394 struct hdsp_midi *hmidi;
1396 hmidi = (struct hdsp_midi *) substream->rmidi->private_data;
1397 spin_lock_irq (&hmidi->lock);
1398 snd_hdsp_flush_midi_input (hmidi->hdsp, hmidi->id);
1399 hmidi->input = substream;
1400 spin_unlock_irq (&hmidi->lock);
1405 static int snd_hdsp_midi_output_open(struct snd_rawmidi_substream *substream)
1407 struct hdsp_midi *hmidi;
1409 hmidi = (struct hdsp_midi *) substream->rmidi->private_data;
1410 spin_lock_irq (&hmidi->lock);
1411 hmidi->output = substream;
1412 spin_unlock_irq (&hmidi->lock);
1417 static int snd_hdsp_midi_input_close(struct snd_rawmidi_substream *substream)
1419 struct hdsp_midi *hmidi;
1421 snd_hdsp_midi_input_trigger (substream, 0);
1423 hmidi = (struct hdsp_midi *) substream->rmidi->private_data;
1424 spin_lock_irq (&hmidi->lock);
1425 hmidi->input = NULL;
1426 spin_unlock_irq (&hmidi->lock);
1431 static int snd_hdsp_midi_output_close(struct snd_rawmidi_substream *substream)
1433 struct hdsp_midi *hmidi;
1435 snd_hdsp_midi_output_trigger (substream, 0);
1437 hmidi = (struct hdsp_midi *) substream->rmidi->private_data;
1438 spin_lock_irq (&hmidi->lock);
1439 hmidi->output = NULL;
1440 spin_unlock_irq (&hmidi->lock);
1445 static struct snd_rawmidi_ops snd_hdsp_midi_output =
1447 .open = snd_hdsp_midi_output_open,
1448 .close = snd_hdsp_midi_output_close,
1449 .trigger = snd_hdsp_midi_output_trigger,
1452 static struct snd_rawmidi_ops snd_hdsp_midi_input =
1454 .open = snd_hdsp_midi_input_open,
1455 .close = snd_hdsp_midi_input_close,
1456 .trigger = snd_hdsp_midi_input_trigger,
1459 static int snd_hdsp_create_midi (struct snd_card *card, struct hdsp *hdsp, int id)
1463 hdsp->midi[id].id = id;
1464 hdsp->midi[id].rmidi = NULL;
1465 hdsp->midi[id].input = NULL;
1466 hdsp->midi[id].output = NULL;
1467 hdsp->midi[id].hdsp = hdsp;
1468 hdsp->midi[id].istimer = 0;
1469 hdsp->midi[id].pending = 0;
1470 spin_lock_init (&hdsp->midi[id].lock);
1472 sprintf (buf, "%s MIDI %d", card->shortname, id+1);
1473 if (snd_rawmidi_new (card, buf, id, 1, 1, &hdsp->midi[id].rmidi) < 0)
1476 sprintf(hdsp->midi[id].rmidi->name, "HDSP MIDI %d", id+1);
1477 hdsp->midi[id].rmidi->private_data = &hdsp->midi[id];
1479 snd_rawmidi_set_ops (hdsp->midi[id].rmidi, SNDRV_RAWMIDI_STREAM_OUTPUT, &snd_hdsp_midi_output);
1480 snd_rawmidi_set_ops (hdsp->midi[id].rmidi, SNDRV_RAWMIDI_STREAM_INPUT, &snd_hdsp_midi_input);
1482 hdsp->midi[id].rmidi->info_flags |= SNDRV_RAWMIDI_INFO_OUTPUT |
1483 SNDRV_RAWMIDI_INFO_INPUT |
1484 SNDRV_RAWMIDI_INFO_DUPLEX;
1489 /*-----------------------------------------------------------------------------
1491 ----------------------------------------------------------------------------*/
1493 static u32 snd_hdsp_convert_from_aes(struct snd_aes_iec958 *aes)
1496 val |= (aes->status[0] & IEC958_AES0_PROFESSIONAL) ? HDSP_SPDIFProfessional : 0;
1497 val |= (aes->status[0] & IEC958_AES0_NONAUDIO) ? HDSP_SPDIFNonAudio : 0;
1498 if (val & HDSP_SPDIFProfessional)
1499 val |= (aes->status[0] & IEC958_AES0_PRO_EMPHASIS_5015) ? HDSP_SPDIFEmphasis : 0;
1501 val |= (aes->status[0] & IEC958_AES0_CON_EMPHASIS_5015) ? HDSP_SPDIFEmphasis : 0;
1505 static void snd_hdsp_convert_to_aes(struct snd_aes_iec958 *aes, u32 val)
1507 aes->status[0] = ((val & HDSP_SPDIFProfessional) ? IEC958_AES0_PROFESSIONAL : 0) |
1508 ((val & HDSP_SPDIFNonAudio) ? IEC958_AES0_NONAUDIO : 0);
1509 if (val & HDSP_SPDIFProfessional)
1510 aes->status[0] |= (val & HDSP_SPDIFEmphasis) ? IEC958_AES0_PRO_EMPHASIS_5015 : 0;
1512 aes->status[0] |= (val & HDSP_SPDIFEmphasis) ? IEC958_AES0_CON_EMPHASIS_5015 : 0;
1515 static int snd_hdsp_control_spdif_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
1517 uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
1522 static int snd_hdsp_control_spdif_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1524 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1526 snd_hdsp_convert_to_aes(&ucontrol->value.iec958, hdsp->creg_spdif);
1530 static int snd_hdsp_control_spdif_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1532 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1536 val = snd_hdsp_convert_from_aes(&ucontrol->value.iec958);
1537 spin_lock_irq(&hdsp->lock);
1538 change = val != hdsp->creg_spdif;
1539 hdsp->creg_spdif = val;
1540 spin_unlock_irq(&hdsp->lock);
1544 static int snd_hdsp_control_spdif_stream_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
1546 uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
1551 static int snd_hdsp_control_spdif_stream_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1553 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1555 snd_hdsp_convert_to_aes(&ucontrol->value.iec958, hdsp->creg_spdif_stream);
1559 static int snd_hdsp_control_spdif_stream_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1561 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1565 val = snd_hdsp_convert_from_aes(&ucontrol->value.iec958);
1566 spin_lock_irq(&hdsp->lock);
1567 change = val != hdsp->creg_spdif_stream;
1568 hdsp->creg_spdif_stream = val;
1569 hdsp->control_register &= ~(HDSP_SPDIFProfessional | HDSP_SPDIFNonAudio | HDSP_SPDIFEmphasis);
1570 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register |= val);
1571 spin_unlock_irq(&hdsp->lock);
1575 static int snd_hdsp_control_spdif_mask_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
1577 uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
1582 static int snd_hdsp_control_spdif_mask_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1584 ucontrol->value.iec958.status[0] = kcontrol->private_value;
1588 #define HDSP_SPDIF_IN(xname, xindex) \
1589 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1592 .info = snd_hdsp_info_spdif_in, \
1593 .get = snd_hdsp_get_spdif_in, \
1594 .put = snd_hdsp_put_spdif_in }
1596 static unsigned int hdsp_spdif_in(struct hdsp *hdsp)
1598 return hdsp_decode_spdif_in(hdsp->control_register & HDSP_SPDIFInputMask);
1601 static int hdsp_set_spdif_input(struct hdsp *hdsp, int in)
1603 hdsp->control_register &= ~HDSP_SPDIFInputMask;
1604 hdsp->control_register |= hdsp_encode_spdif_in(in);
1605 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
1609 static int snd_hdsp_info_spdif_in(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
1611 static char *texts[4] = {"Optical", "Coaxial", "Internal", "AES"};
1612 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1614 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1616 uinfo->value.enumerated.items = ((hdsp->io_type == H9632) ? 4 : 3);
1617 if (uinfo->value.enumerated.item > ((hdsp->io_type == H9632) ? 3 : 2))
1618 uinfo->value.enumerated.item = ((hdsp->io_type == H9632) ? 3 : 2);
1619 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1623 static int snd_hdsp_get_spdif_in(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1625 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1627 ucontrol->value.enumerated.item[0] = hdsp_spdif_in(hdsp);
1631 static int snd_hdsp_put_spdif_in(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1633 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1637 if (!snd_hdsp_use_is_exclusive(hdsp))
1639 val = ucontrol->value.enumerated.item[0] % ((hdsp->io_type == H9632) ? 4 : 3);
1640 spin_lock_irq(&hdsp->lock);
1641 change = val != hdsp_spdif_in(hdsp);
1643 hdsp_set_spdif_input(hdsp, val);
1644 spin_unlock_irq(&hdsp->lock);
1648 #define HDSP_SPDIF_OUT(xname, xindex) \
1649 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \
1650 .info = snd_hdsp_info_spdif_bits, \
1651 .get = snd_hdsp_get_spdif_out, .put = snd_hdsp_put_spdif_out }
1653 static int hdsp_spdif_out(struct hdsp *hdsp)
1655 return (hdsp->control_register & HDSP_SPDIFOpticalOut) ? 1 : 0;
1658 static int hdsp_set_spdif_output(struct hdsp *hdsp, int out)
1661 hdsp->control_register |= HDSP_SPDIFOpticalOut;
1663 hdsp->control_register &= ~HDSP_SPDIFOpticalOut;
1664 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
1668 #define snd_hdsp_info_spdif_bits snd_ctl_boolean_mono_info
1670 static int snd_hdsp_get_spdif_out(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1672 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1674 ucontrol->value.integer.value[0] = hdsp_spdif_out(hdsp);
1678 static int snd_hdsp_put_spdif_out(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1680 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1684 if (!snd_hdsp_use_is_exclusive(hdsp))
1686 val = ucontrol->value.integer.value[0] & 1;
1687 spin_lock_irq(&hdsp->lock);
1688 change = (int)val != hdsp_spdif_out(hdsp);
1689 hdsp_set_spdif_output(hdsp, val);
1690 spin_unlock_irq(&hdsp->lock);
1694 #define HDSP_SPDIF_PROFESSIONAL(xname, xindex) \
1695 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \
1696 .info = snd_hdsp_info_spdif_bits, \
1697 .get = snd_hdsp_get_spdif_professional, .put = snd_hdsp_put_spdif_professional }
1699 static int hdsp_spdif_professional(struct hdsp *hdsp)
1701 return (hdsp->control_register & HDSP_SPDIFProfessional) ? 1 : 0;
1704 static int hdsp_set_spdif_professional(struct hdsp *hdsp, int val)
1707 hdsp->control_register |= HDSP_SPDIFProfessional;
1709 hdsp->control_register &= ~HDSP_SPDIFProfessional;
1710 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
1714 static int snd_hdsp_get_spdif_professional(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1716 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1718 ucontrol->value.integer.value[0] = hdsp_spdif_professional(hdsp);
1722 static int snd_hdsp_put_spdif_professional(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1724 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1728 if (!snd_hdsp_use_is_exclusive(hdsp))
1730 val = ucontrol->value.integer.value[0] & 1;
1731 spin_lock_irq(&hdsp->lock);
1732 change = (int)val != hdsp_spdif_professional(hdsp);
1733 hdsp_set_spdif_professional(hdsp, val);
1734 spin_unlock_irq(&hdsp->lock);
1738 #define HDSP_SPDIF_EMPHASIS(xname, xindex) \
1739 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \
1740 .info = snd_hdsp_info_spdif_bits, \
1741 .get = snd_hdsp_get_spdif_emphasis, .put = snd_hdsp_put_spdif_emphasis }
1743 static int hdsp_spdif_emphasis(struct hdsp *hdsp)
1745 return (hdsp->control_register & HDSP_SPDIFEmphasis) ? 1 : 0;
1748 static int hdsp_set_spdif_emphasis(struct hdsp *hdsp, int val)
1751 hdsp->control_register |= HDSP_SPDIFEmphasis;
1753 hdsp->control_register &= ~HDSP_SPDIFEmphasis;
1754 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
1758 static int snd_hdsp_get_spdif_emphasis(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1760 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1762 ucontrol->value.integer.value[0] = hdsp_spdif_emphasis(hdsp);
1766 static int snd_hdsp_put_spdif_emphasis(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1768 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1772 if (!snd_hdsp_use_is_exclusive(hdsp))
1774 val = ucontrol->value.integer.value[0] & 1;
1775 spin_lock_irq(&hdsp->lock);
1776 change = (int)val != hdsp_spdif_emphasis(hdsp);
1777 hdsp_set_spdif_emphasis(hdsp, val);
1778 spin_unlock_irq(&hdsp->lock);
1782 #define HDSP_SPDIF_NON_AUDIO(xname, xindex) \
1783 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \
1784 .info = snd_hdsp_info_spdif_bits, \
1785 .get = snd_hdsp_get_spdif_nonaudio, .put = snd_hdsp_put_spdif_nonaudio }
1787 static int hdsp_spdif_nonaudio(struct hdsp *hdsp)
1789 return (hdsp->control_register & HDSP_SPDIFNonAudio) ? 1 : 0;
1792 static int hdsp_set_spdif_nonaudio(struct hdsp *hdsp, int val)
1795 hdsp->control_register |= HDSP_SPDIFNonAudio;
1797 hdsp->control_register &= ~HDSP_SPDIFNonAudio;
1798 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
1802 static int snd_hdsp_get_spdif_nonaudio(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1804 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1806 ucontrol->value.integer.value[0] = hdsp_spdif_nonaudio(hdsp);
1810 static int snd_hdsp_put_spdif_nonaudio(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1812 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1816 if (!snd_hdsp_use_is_exclusive(hdsp))
1818 val = ucontrol->value.integer.value[0] & 1;
1819 spin_lock_irq(&hdsp->lock);
1820 change = (int)val != hdsp_spdif_nonaudio(hdsp);
1821 hdsp_set_spdif_nonaudio(hdsp, val);
1822 spin_unlock_irq(&hdsp->lock);
1826 #define HDSP_SPDIF_SAMPLE_RATE(xname, xindex) \
1827 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1830 .access = SNDRV_CTL_ELEM_ACCESS_READ, \
1831 .info = snd_hdsp_info_spdif_sample_rate, \
1832 .get = snd_hdsp_get_spdif_sample_rate \
1835 static int snd_hdsp_info_spdif_sample_rate(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
1837 static char *texts[] = {"32000", "44100", "48000", "64000", "88200", "96000", "None", "128000", "176400", "192000"};
1838 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1840 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1842 uinfo->value.enumerated.items = (hdsp->io_type == H9632) ? 10 : 7;
1843 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
1844 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
1845 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1849 static int snd_hdsp_get_spdif_sample_rate(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1851 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1853 switch (hdsp_spdif_sample_rate(hdsp)) {
1855 ucontrol->value.enumerated.item[0] = 0;
1858 ucontrol->value.enumerated.item[0] = 1;
1861 ucontrol->value.enumerated.item[0] = 2;
1864 ucontrol->value.enumerated.item[0] = 3;
1867 ucontrol->value.enumerated.item[0] = 4;
1870 ucontrol->value.enumerated.item[0] = 5;
1873 ucontrol->value.enumerated.item[0] = 7;
1876 ucontrol->value.enumerated.item[0] = 8;
1879 ucontrol->value.enumerated.item[0] = 9;
1882 ucontrol->value.enumerated.item[0] = 6;
1887 #define HDSP_SYSTEM_SAMPLE_RATE(xname, xindex) \
1888 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1891 .access = SNDRV_CTL_ELEM_ACCESS_READ, \
1892 .info = snd_hdsp_info_system_sample_rate, \
1893 .get = snd_hdsp_get_system_sample_rate \
1896 static int snd_hdsp_info_system_sample_rate(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
1898 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1903 static int snd_hdsp_get_system_sample_rate(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1905 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1907 ucontrol->value.enumerated.item[0] = hdsp->system_sample_rate;
1911 #define HDSP_AUTOSYNC_SAMPLE_RATE(xname, xindex) \
1912 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1915 .access = SNDRV_CTL_ELEM_ACCESS_READ, \
1916 .info = snd_hdsp_info_autosync_sample_rate, \
1917 .get = snd_hdsp_get_autosync_sample_rate \
1920 static int snd_hdsp_info_autosync_sample_rate(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
1922 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1923 static char *texts[] = {"32000", "44100", "48000", "64000", "88200", "96000", "None", "128000", "176400", "192000"};
1924 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1926 uinfo->value.enumerated.items = (hdsp->io_type == H9632) ? 10 : 7 ;
1927 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
1928 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
1929 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1933 static int snd_hdsp_get_autosync_sample_rate(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1935 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1937 switch (hdsp_external_sample_rate(hdsp)) {
1939 ucontrol->value.enumerated.item[0] = 0;
1942 ucontrol->value.enumerated.item[0] = 1;
1945 ucontrol->value.enumerated.item[0] = 2;
1948 ucontrol->value.enumerated.item[0] = 3;
1951 ucontrol->value.enumerated.item[0] = 4;
1954 ucontrol->value.enumerated.item[0] = 5;
1957 ucontrol->value.enumerated.item[0] = 7;
1960 ucontrol->value.enumerated.item[0] = 8;
1963 ucontrol->value.enumerated.item[0] = 9;
1966 ucontrol->value.enumerated.item[0] = 6;
1971 #define HDSP_SYSTEM_CLOCK_MODE(xname, xindex) \
1972 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1975 .access = SNDRV_CTL_ELEM_ACCESS_READ, \
1976 .info = snd_hdsp_info_system_clock_mode, \
1977 .get = snd_hdsp_get_system_clock_mode \
1980 static int hdsp_system_clock_mode(struct hdsp *hdsp)
1982 if (hdsp->control_register & HDSP_ClockModeMaster)
1984 else if (hdsp_external_sample_rate(hdsp) != hdsp->system_sample_rate)
1989 static int snd_hdsp_info_system_clock_mode(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
1991 static char *texts[] = {"Master", "Slave" };
1993 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1995 uinfo->value.enumerated.items = 2;
1996 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
1997 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
1998 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
2002 static int snd_hdsp_get_system_clock_mode(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2004 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2006 ucontrol->value.enumerated.item[0] = hdsp_system_clock_mode(hdsp);
2010 #define HDSP_CLOCK_SOURCE(xname, xindex) \
2011 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2014 .info = snd_hdsp_info_clock_source, \
2015 .get = snd_hdsp_get_clock_source, \
2016 .put = snd_hdsp_put_clock_source \
2019 static int hdsp_clock_source(struct hdsp *hdsp)
2021 if (hdsp->control_register & HDSP_ClockModeMaster) {
2022 switch (hdsp->system_sample_rate) {
2049 static int hdsp_set_clock_source(struct hdsp *hdsp, int mode)
2053 case HDSP_CLOCK_SOURCE_AUTOSYNC:
2054 if (hdsp_external_sample_rate(hdsp) != 0) {
2055 if (!hdsp_set_rate(hdsp, hdsp_external_sample_rate(hdsp), 1)) {
2056 hdsp->control_register &= ~HDSP_ClockModeMaster;
2057 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
2062 case HDSP_CLOCK_SOURCE_INTERNAL_32KHZ:
2065 case HDSP_CLOCK_SOURCE_INTERNAL_44_1KHZ:
2068 case HDSP_CLOCK_SOURCE_INTERNAL_48KHZ:
2071 case HDSP_CLOCK_SOURCE_INTERNAL_64KHZ:
2074 case HDSP_CLOCK_SOURCE_INTERNAL_88_2KHZ:
2077 case HDSP_CLOCK_SOURCE_INTERNAL_96KHZ:
2080 case HDSP_CLOCK_SOURCE_INTERNAL_128KHZ:
2083 case HDSP_CLOCK_SOURCE_INTERNAL_176_4KHZ:
2086 case HDSP_CLOCK_SOURCE_INTERNAL_192KHZ:
2092 hdsp->control_register |= HDSP_ClockModeMaster;
2093 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
2094 hdsp_set_rate(hdsp, rate, 1);
2098 static int snd_hdsp_info_clock_source(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
2100 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" };
2101 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2103 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2105 if (hdsp->io_type == H9632)
2106 uinfo->value.enumerated.items = 10;
2108 uinfo->value.enumerated.items = 7;
2109 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
2110 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
2111 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
2115 static int snd_hdsp_get_clock_source(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2117 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2119 ucontrol->value.enumerated.item[0] = hdsp_clock_source(hdsp);
2123 static int snd_hdsp_put_clock_source(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2125 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2129 if (!snd_hdsp_use_is_exclusive(hdsp))
2131 val = ucontrol->value.enumerated.item[0];
2132 if (val < 0) val = 0;
2133 if (hdsp->io_type == H9632) {
2140 spin_lock_irq(&hdsp->lock);
2141 if (val != hdsp_clock_source(hdsp))
2142 change = (hdsp_set_clock_source(hdsp, val) == 0) ? 1 : 0;
2145 spin_unlock_irq(&hdsp->lock);
2149 #define snd_hdsp_info_clock_source_lock snd_ctl_boolean_mono_info
2151 static int snd_hdsp_get_clock_source_lock(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2153 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2155 ucontrol->value.integer.value[0] = hdsp->clock_source_locked;
2159 static int snd_hdsp_put_clock_source_lock(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2161 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2164 change = (int)ucontrol->value.integer.value[0] != hdsp->clock_source_locked;
2166 hdsp->clock_source_locked = !!ucontrol->value.integer.value[0];
2170 #define HDSP_DA_GAIN(xname, xindex) \
2171 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2174 .info = snd_hdsp_info_da_gain, \
2175 .get = snd_hdsp_get_da_gain, \
2176 .put = snd_hdsp_put_da_gain \
2179 static int hdsp_da_gain(struct hdsp *hdsp)
2181 switch (hdsp->control_register & HDSP_DAGainMask) {
2182 case HDSP_DAGainHighGain:
2184 case HDSP_DAGainPlus4dBu:
2186 case HDSP_DAGainMinus10dBV:
2193 static int hdsp_set_da_gain(struct hdsp *hdsp, int mode)
2195 hdsp->control_register &= ~HDSP_DAGainMask;
2198 hdsp->control_register |= HDSP_DAGainHighGain;
2201 hdsp->control_register |= HDSP_DAGainPlus4dBu;
2204 hdsp->control_register |= HDSP_DAGainMinus10dBV;
2210 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
2214 static int snd_hdsp_info_da_gain(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
2216 static char *texts[] = {"Hi Gain", "+4 dBu", "-10 dbV"};
2218 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2220 uinfo->value.enumerated.items = 3;
2221 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
2222 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
2223 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
2227 static int snd_hdsp_get_da_gain(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2229 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2231 ucontrol->value.enumerated.item[0] = hdsp_da_gain(hdsp);
2235 static int snd_hdsp_put_da_gain(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2237 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2241 if (!snd_hdsp_use_is_exclusive(hdsp))
2243 val = ucontrol->value.enumerated.item[0];
2244 if (val < 0) val = 0;
2245 if (val > 2) val = 2;
2246 spin_lock_irq(&hdsp->lock);
2247 if (val != hdsp_da_gain(hdsp))
2248 change = (hdsp_set_da_gain(hdsp, val) == 0) ? 1 : 0;
2251 spin_unlock_irq(&hdsp->lock);
2255 #define HDSP_AD_GAIN(xname, xindex) \
2256 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2259 .info = snd_hdsp_info_ad_gain, \
2260 .get = snd_hdsp_get_ad_gain, \
2261 .put = snd_hdsp_put_ad_gain \
2264 static int hdsp_ad_gain(struct hdsp *hdsp)
2266 switch (hdsp->control_register & HDSP_ADGainMask) {
2267 case HDSP_ADGainMinus10dBV:
2269 case HDSP_ADGainPlus4dBu:
2271 case HDSP_ADGainLowGain:
2278 static int hdsp_set_ad_gain(struct hdsp *hdsp, int mode)
2280 hdsp->control_register &= ~HDSP_ADGainMask;
2283 hdsp->control_register |= HDSP_ADGainMinus10dBV;
2286 hdsp->control_register |= HDSP_ADGainPlus4dBu;
2289 hdsp->control_register |= HDSP_ADGainLowGain;
2295 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
2299 static int snd_hdsp_info_ad_gain(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
2301 static char *texts[] = {"-10 dBV", "+4 dBu", "Lo Gain"};
2303 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2305 uinfo->value.enumerated.items = 3;
2306 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
2307 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
2308 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
2312 static int snd_hdsp_get_ad_gain(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2314 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2316 ucontrol->value.enumerated.item[0] = hdsp_ad_gain(hdsp);
2320 static int snd_hdsp_put_ad_gain(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2322 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2326 if (!snd_hdsp_use_is_exclusive(hdsp))
2328 val = ucontrol->value.enumerated.item[0];
2329 if (val < 0) val = 0;
2330 if (val > 2) val = 2;
2331 spin_lock_irq(&hdsp->lock);
2332 if (val != hdsp_ad_gain(hdsp))
2333 change = (hdsp_set_ad_gain(hdsp, val) == 0) ? 1 : 0;
2336 spin_unlock_irq(&hdsp->lock);
2340 #define HDSP_PHONE_GAIN(xname, xindex) \
2341 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2344 .info = snd_hdsp_info_phone_gain, \
2345 .get = snd_hdsp_get_phone_gain, \
2346 .put = snd_hdsp_put_phone_gain \
2349 static int hdsp_phone_gain(struct hdsp *hdsp)
2351 switch (hdsp->control_register & HDSP_PhoneGainMask) {
2352 case HDSP_PhoneGain0dB:
2354 case HDSP_PhoneGainMinus6dB:
2356 case HDSP_PhoneGainMinus12dB:
2363 static int hdsp_set_phone_gain(struct hdsp *hdsp, int mode)
2365 hdsp->control_register &= ~HDSP_PhoneGainMask;
2368 hdsp->control_register |= HDSP_PhoneGain0dB;
2371 hdsp->control_register |= HDSP_PhoneGainMinus6dB;
2374 hdsp->control_register |= HDSP_PhoneGainMinus12dB;
2380 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
2384 static int snd_hdsp_info_phone_gain(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
2386 static char *texts[] = {"0 dB", "-6 dB", "-12 dB"};
2388 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2390 uinfo->value.enumerated.items = 3;
2391 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
2392 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
2393 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
2397 static int snd_hdsp_get_phone_gain(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2399 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2401 ucontrol->value.enumerated.item[0] = hdsp_phone_gain(hdsp);
2405 static int snd_hdsp_put_phone_gain(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2407 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2411 if (!snd_hdsp_use_is_exclusive(hdsp))
2413 val = ucontrol->value.enumerated.item[0];
2414 if (val < 0) val = 0;
2415 if (val > 2) val = 2;
2416 spin_lock_irq(&hdsp->lock);
2417 if (val != hdsp_phone_gain(hdsp))
2418 change = (hdsp_set_phone_gain(hdsp, val) == 0) ? 1 : 0;
2421 spin_unlock_irq(&hdsp->lock);
2425 #define HDSP_XLR_BREAKOUT_CABLE(xname, xindex) \
2426 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2429 .info = snd_hdsp_info_xlr_breakout_cable, \
2430 .get = snd_hdsp_get_xlr_breakout_cable, \
2431 .put = snd_hdsp_put_xlr_breakout_cable \
2434 static int hdsp_xlr_breakout_cable(struct hdsp *hdsp)
2436 if (hdsp->control_register & HDSP_XLRBreakoutCable)
2441 static int hdsp_set_xlr_breakout_cable(struct hdsp *hdsp, int mode)
2444 hdsp->control_register |= HDSP_XLRBreakoutCable;
2446 hdsp->control_register &= ~HDSP_XLRBreakoutCable;
2447 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
2451 #define snd_hdsp_info_xlr_breakout_cable snd_ctl_boolean_mono_info
2453 static int snd_hdsp_get_xlr_breakout_cable(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2455 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2457 ucontrol->value.enumerated.item[0] = hdsp_xlr_breakout_cable(hdsp);
2461 static int snd_hdsp_put_xlr_breakout_cable(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2463 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2467 if (!snd_hdsp_use_is_exclusive(hdsp))
2469 val = ucontrol->value.integer.value[0] & 1;
2470 spin_lock_irq(&hdsp->lock);
2471 change = (int)val != hdsp_xlr_breakout_cable(hdsp);
2472 hdsp_set_xlr_breakout_cable(hdsp, val);
2473 spin_unlock_irq(&hdsp->lock);
2477 /* (De)activates old RME Analog Extension Board
2478 These are connected to the internal ADAT connector
2479 Switching this on desactivates external ADAT
2481 #define HDSP_AEB(xname, xindex) \
2482 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2485 .info = snd_hdsp_info_aeb, \
2486 .get = snd_hdsp_get_aeb, \
2487 .put = snd_hdsp_put_aeb \
2490 static int hdsp_aeb(struct hdsp *hdsp)
2492 if (hdsp->control_register & HDSP_AnalogExtensionBoard)
2497 static int hdsp_set_aeb(struct hdsp *hdsp, int mode)
2500 hdsp->control_register |= HDSP_AnalogExtensionBoard;
2502 hdsp->control_register &= ~HDSP_AnalogExtensionBoard;
2503 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
2507 #define snd_hdsp_info_aeb snd_ctl_boolean_mono_info
2509 static int snd_hdsp_get_aeb(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2511 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2513 ucontrol->value.enumerated.item[0] = hdsp_aeb(hdsp);
2517 static int snd_hdsp_put_aeb(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2519 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2523 if (!snd_hdsp_use_is_exclusive(hdsp))
2525 val = ucontrol->value.integer.value[0] & 1;
2526 spin_lock_irq(&hdsp->lock);
2527 change = (int)val != hdsp_aeb(hdsp);
2528 hdsp_set_aeb(hdsp, val);
2529 spin_unlock_irq(&hdsp->lock);
2533 #define HDSP_PREF_SYNC_REF(xname, xindex) \
2534 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2537 .info = snd_hdsp_info_pref_sync_ref, \
2538 .get = snd_hdsp_get_pref_sync_ref, \
2539 .put = snd_hdsp_put_pref_sync_ref \
2542 static int hdsp_pref_sync_ref(struct hdsp *hdsp)
2544 /* Notice that this looks at the requested sync source,
2545 not the one actually in use.
2548 switch (hdsp->control_register & HDSP_SyncRefMask) {
2549 case HDSP_SyncRef_ADAT1:
2550 return HDSP_SYNC_FROM_ADAT1;
2551 case HDSP_SyncRef_ADAT2:
2552 return HDSP_SYNC_FROM_ADAT2;
2553 case HDSP_SyncRef_ADAT3:
2554 return HDSP_SYNC_FROM_ADAT3;
2555 case HDSP_SyncRef_SPDIF:
2556 return HDSP_SYNC_FROM_SPDIF;
2557 case HDSP_SyncRef_WORD:
2558 return HDSP_SYNC_FROM_WORD;
2559 case HDSP_SyncRef_ADAT_SYNC:
2560 return HDSP_SYNC_FROM_ADAT_SYNC;
2562 return HDSP_SYNC_FROM_WORD;
2567 static int hdsp_set_pref_sync_ref(struct hdsp *hdsp, int pref)
2569 hdsp->control_register &= ~HDSP_SyncRefMask;
2571 case HDSP_SYNC_FROM_ADAT1:
2572 hdsp->control_register &= ~HDSP_SyncRefMask; /* clear SyncRef bits */
2574 case HDSP_SYNC_FROM_ADAT2:
2575 hdsp->control_register |= HDSP_SyncRef_ADAT2;
2577 case HDSP_SYNC_FROM_ADAT3:
2578 hdsp->control_register |= HDSP_SyncRef_ADAT3;
2580 case HDSP_SYNC_FROM_SPDIF:
2581 hdsp->control_register |= HDSP_SyncRef_SPDIF;
2583 case HDSP_SYNC_FROM_WORD:
2584 hdsp->control_register |= HDSP_SyncRef_WORD;
2586 case HDSP_SYNC_FROM_ADAT_SYNC:
2587 hdsp->control_register |= HDSP_SyncRef_ADAT_SYNC;
2592 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
2596 static int snd_hdsp_info_pref_sync_ref(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
2598 static char *texts[] = {"Word", "IEC958", "ADAT1", "ADAT Sync", "ADAT2", "ADAT3" };
2599 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2601 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2604 switch (hdsp->io_type) {
2607 uinfo->value.enumerated.items = 6;
2610 uinfo->value.enumerated.items = 4;
2613 uinfo->value.enumerated.items = 3;
2616 uinfo->value.enumerated.items = 0;
2620 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
2621 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
2622 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
2626 static int snd_hdsp_get_pref_sync_ref(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2628 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2630 ucontrol->value.enumerated.item[0] = hdsp_pref_sync_ref(hdsp);
2634 static int snd_hdsp_put_pref_sync_ref(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2636 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2640 if (!snd_hdsp_use_is_exclusive(hdsp))
2643 switch (hdsp->io_type) {
2658 val = ucontrol->value.enumerated.item[0] % max;
2659 spin_lock_irq(&hdsp->lock);
2660 change = (int)val != hdsp_pref_sync_ref(hdsp);
2661 hdsp_set_pref_sync_ref(hdsp, val);
2662 spin_unlock_irq(&hdsp->lock);
2666 #define HDSP_AUTOSYNC_REF(xname, xindex) \
2667 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2670 .access = SNDRV_CTL_ELEM_ACCESS_READ, \
2671 .info = snd_hdsp_info_autosync_ref, \
2672 .get = snd_hdsp_get_autosync_ref, \
2675 static int hdsp_autosync_ref(struct hdsp *hdsp)
2677 /* This looks at the autosync selected sync reference */
2678 unsigned int status2 = hdsp_read(hdsp, HDSP_status2Register);
2680 switch (status2 & HDSP_SelSyncRefMask) {
2681 case HDSP_SelSyncRef_WORD:
2682 return HDSP_AUTOSYNC_FROM_WORD;
2683 case HDSP_SelSyncRef_ADAT_SYNC:
2684 return HDSP_AUTOSYNC_FROM_ADAT_SYNC;
2685 case HDSP_SelSyncRef_SPDIF:
2686 return HDSP_AUTOSYNC_FROM_SPDIF;
2687 case HDSP_SelSyncRefMask:
2688 return HDSP_AUTOSYNC_FROM_NONE;
2689 case HDSP_SelSyncRef_ADAT1:
2690 return HDSP_AUTOSYNC_FROM_ADAT1;
2691 case HDSP_SelSyncRef_ADAT2:
2692 return HDSP_AUTOSYNC_FROM_ADAT2;
2693 case HDSP_SelSyncRef_ADAT3:
2694 return HDSP_AUTOSYNC_FROM_ADAT3;
2696 return HDSP_AUTOSYNC_FROM_WORD;
2701 static int snd_hdsp_info_autosync_ref(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
2703 static char *texts[] = {"Word", "ADAT Sync", "IEC958", "None", "ADAT1", "ADAT2", "ADAT3" };
2705 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2707 uinfo->value.enumerated.items = 7;
2708 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
2709 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
2710 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
2714 static int snd_hdsp_get_autosync_ref(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2716 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2718 ucontrol->value.enumerated.item[0] = hdsp_autosync_ref(hdsp);
2722 #define HDSP_LINE_OUT(xname, xindex) \
2723 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2726 .info = snd_hdsp_info_line_out, \
2727 .get = snd_hdsp_get_line_out, \
2728 .put = snd_hdsp_put_line_out \
2731 static int hdsp_line_out(struct hdsp *hdsp)
2733 return (hdsp->control_register & HDSP_LineOut) ? 1 : 0;
2736 static int hdsp_set_line_output(struct hdsp *hdsp, int out)
2739 hdsp->control_register |= HDSP_LineOut;
2741 hdsp->control_register &= ~HDSP_LineOut;
2742 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
2746 #define snd_hdsp_info_line_out snd_ctl_boolean_mono_info
2748 static int snd_hdsp_get_line_out(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2750 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2752 spin_lock_irq(&hdsp->lock);
2753 ucontrol->value.integer.value[0] = hdsp_line_out(hdsp);
2754 spin_unlock_irq(&hdsp->lock);
2758 static int snd_hdsp_put_line_out(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2760 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2764 if (!snd_hdsp_use_is_exclusive(hdsp))
2766 val = ucontrol->value.integer.value[0] & 1;
2767 spin_lock_irq(&hdsp->lock);
2768 change = (int)val != hdsp_line_out(hdsp);
2769 hdsp_set_line_output(hdsp, val);
2770 spin_unlock_irq(&hdsp->lock);
2774 #define HDSP_PRECISE_POINTER(xname, xindex) \
2775 { .iface = SNDRV_CTL_ELEM_IFACE_CARD, \
2778 .info = snd_hdsp_info_precise_pointer, \
2779 .get = snd_hdsp_get_precise_pointer, \
2780 .put = snd_hdsp_put_precise_pointer \
2783 static int hdsp_set_precise_pointer(struct hdsp *hdsp, int precise)
2786 hdsp->precise_ptr = 1;
2788 hdsp->precise_ptr = 0;
2792 #define snd_hdsp_info_precise_pointer snd_ctl_boolean_mono_info
2794 static int snd_hdsp_get_precise_pointer(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2796 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2798 spin_lock_irq(&hdsp->lock);
2799 ucontrol->value.integer.value[0] = hdsp->precise_ptr;
2800 spin_unlock_irq(&hdsp->lock);
2804 static int snd_hdsp_put_precise_pointer(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2806 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2810 if (!snd_hdsp_use_is_exclusive(hdsp))
2812 val = ucontrol->value.integer.value[0] & 1;
2813 spin_lock_irq(&hdsp->lock);
2814 change = (int)val != hdsp->precise_ptr;
2815 hdsp_set_precise_pointer(hdsp, val);
2816 spin_unlock_irq(&hdsp->lock);
2820 #define HDSP_USE_MIDI_TASKLET(xname, xindex) \
2821 { .iface = SNDRV_CTL_ELEM_IFACE_CARD, \
2824 .info = snd_hdsp_info_use_midi_tasklet, \
2825 .get = snd_hdsp_get_use_midi_tasklet, \
2826 .put = snd_hdsp_put_use_midi_tasklet \
2829 static int hdsp_set_use_midi_tasklet(struct hdsp *hdsp, int use_tasklet)
2832 hdsp->use_midi_tasklet = 1;
2834 hdsp->use_midi_tasklet = 0;
2838 #define snd_hdsp_info_use_midi_tasklet snd_ctl_boolean_mono_info
2840 static int snd_hdsp_get_use_midi_tasklet(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2842 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2844 spin_lock_irq(&hdsp->lock);
2845 ucontrol->value.integer.value[0] = hdsp->use_midi_tasklet;
2846 spin_unlock_irq(&hdsp->lock);
2850 static int snd_hdsp_put_use_midi_tasklet(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2852 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2856 if (!snd_hdsp_use_is_exclusive(hdsp))
2858 val = ucontrol->value.integer.value[0] & 1;
2859 spin_lock_irq(&hdsp->lock);
2860 change = (int)val != hdsp->use_midi_tasklet;
2861 hdsp_set_use_midi_tasklet(hdsp, val);
2862 spin_unlock_irq(&hdsp->lock);
2866 #define HDSP_MIXER(xname, xindex) \
2867 { .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(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *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(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2890 struct hdsp *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);
2903 spin_lock_irq(&hdsp->lock);
2904 ucontrol->value.integer.value[2] = hdsp_read_gain (hdsp, addr);
2905 spin_unlock_irq(&hdsp->lock);
2909 static int snd_hdsp_put_mixer(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2911 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2918 if (!snd_hdsp_use_is_exclusive(hdsp))
2921 source = ucontrol->value.integer.value[0];
2922 destination = ucontrol->value.integer.value[1];
2924 if (source >= hdsp->max_channels)
2925 addr = hdsp_playback_to_output_key(hdsp,source-hdsp->max_channels, destination);
2927 addr = hdsp_input_to_output_key(hdsp,source, destination);
2929 gain = ucontrol->value.integer.value[2];
2931 spin_lock_irq(&hdsp->lock);
2932 change = gain != hdsp_read_gain(hdsp, addr);
2934 hdsp_write_gain(hdsp, addr, gain);
2935 spin_unlock_irq(&hdsp->lock);
2939 #define HDSP_WC_SYNC_CHECK(xname, xindex) \
2940 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2943 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
2944 .info = snd_hdsp_info_sync_check, \
2945 .get = snd_hdsp_get_wc_sync_check \
2948 static int snd_hdsp_info_sync_check(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
2950 static char *texts[] = {"No Lock", "Lock", "Sync" };
2951 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2953 uinfo->value.enumerated.items = 3;
2954 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
2955 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
2956 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
2960 static int hdsp_wc_sync_check(struct hdsp *hdsp)
2962 int status2 = hdsp_read(hdsp, HDSP_status2Register);
2963 if (status2 & HDSP_wc_lock) {
2964 if (status2 & HDSP_wc_sync)
2973 static int snd_hdsp_get_wc_sync_check(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2975 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2977 ucontrol->value.enumerated.item[0] = hdsp_wc_sync_check(hdsp);
2981 #define HDSP_SPDIF_SYNC_CHECK(xname, xindex) \
2982 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2985 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
2986 .info = snd_hdsp_info_sync_check, \
2987 .get = snd_hdsp_get_spdif_sync_check \
2990 static int hdsp_spdif_sync_check(struct hdsp *hdsp)
2992 int status = hdsp_read(hdsp, HDSP_statusRegister);
2993 if (status & HDSP_SPDIFErrorFlag)
2996 if (status & HDSP_SPDIFSync)
3004 static int snd_hdsp_get_spdif_sync_check(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
3006 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
3008 ucontrol->value.enumerated.item[0] = hdsp_spdif_sync_check(hdsp);
3012 #define HDSP_ADATSYNC_SYNC_CHECK(xname, xindex) \
3013 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
3016 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
3017 .info = snd_hdsp_info_sync_check, \
3018 .get = snd_hdsp_get_adatsync_sync_check \
3021 static int hdsp_adatsync_sync_check(struct hdsp *hdsp)
3023 int status = hdsp_read(hdsp, HDSP_statusRegister);
3024 if (status & HDSP_TimecodeLock) {
3025 if (status & HDSP_TimecodeSync)
3033 static int snd_hdsp_get_adatsync_sync_check(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
3035 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
3037 ucontrol->value.enumerated.item[0] = hdsp_adatsync_sync_check(hdsp);
3041 #define HDSP_ADAT_SYNC_CHECK \
3042 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
3043 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
3044 .info = snd_hdsp_info_sync_check, \
3045 .get = snd_hdsp_get_adat_sync_check \
3048 static int hdsp_adat_sync_check(struct hdsp *hdsp, int idx)
3050 int status = hdsp_read(hdsp, HDSP_statusRegister);
3052 if (status & (HDSP_Lock0>>idx)) {
3053 if (status & (HDSP_Sync0>>idx))
3061 static int snd_hdsp_get_adat_sync_check(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
3064 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
3066 offset = ucontrol->id.index - 1;
3067 snd_BUG_ON(offset < 0);
3069 switch (hdsp->io_type) {
3084 ucontrol->value.enumerated.item[0] = hdsp_adat_sync_check(hdsp, offset);
3088 #define HDSP_DDS_OFFSET(xname, xindex) \
3089 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
3092 .info = snd_hdsp_info_dds_offset, \
3093 .get = snd_hdsp_get_dds_offset, \
3094 .put = snd_hdsp_put_dds_offset \
3097 static int hdsp_dds_offset(struct hdsp *hdsp)
3100 unsigned int dds_value = hdsp->dds_value;
3101 int system_sample_rate = hdsp->system_sample_rate;
3108 * dds_value = n / rate
3109 * rate = n / dds_value
3111 n = div_u64(n, dds_value);
3112 if (system_sample_rate >= 112000)
3114 else if (system_sample_rate >= 56000)
3116 return ((int)n) - system_sample_rate;
3119 static int hdsp_set_dds_offset(struct hdsp *hdsp, int offset_hz)
3121 int rate = hdsp->system_sample_rate + offset_hz;
3122 hdsp_set_dds_value(hdsp, rate);
3126 static int snd_hdsp_info_dds_offset(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
3128 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
3130 uinfo->value.integer.min = -5000;
3131 uinfo->value.integer.max = 5000;
3135 static int snd_hdsp_get_dds_offset(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
3137 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
3139 ucontrol->value.enumerated.item[0] = hdsp_dds_offset(hdsp);
3143 static int snd_hdsp_put_dds_offset(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
3145 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
3149 if (!snd_hdsp_use_is_exclusive(hdsp))
3151 val = ucontrol->value.enumerated.item[0];
3152 spin_lock_irq(&hdsp->lock);
3153 if (val != hdsp_dds_offset(hdsp))
3154 change = (hdsp_set_dds_offset(hdsp, val) == 0) ? 1 : 0;
3157 spin_unlock_irq(&hdsp->lock);
3161 static struct snd_kcontrol_new snd_hdsp_9632_controls[] = {
3162 HDSP_DA_GAIN("DA Gain", 0),
3163 HDSP_AD_GAIN("AD Gain", 0),
3164 HDSP_PHONE_GAIN("Phones Gain", 0),
3165 HDSP_XLR_BREAKOUT_CABLE("XLR Breakout Cable", 0),
3166 HDSP_DDS_OFFSET("DDS Sample Rate Offset", 0)
3169 static struct snd_kcontrol_new snd_hdsp_controls[] = {
3171 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
3172 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,DEFAULT),
3173 .info = snd_hdsp_control_spdif_info,
3174 .get = snd_hdsp_control_spdif_get,
3175 .put = snd_hdsp_control_spdif_put,
3178 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_INACTIVE,
3179 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
3180 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,PCM_STREAM),
3181 .info = snd_hdsp_control_spdif_stream_info,
3182 .get = snd_hdsp_control_spdif_stream_get,
3183 .put = snd_hdsp_control_spdif_stream_put,
3186 .access = SNDRV_CTL_ELEM_ACCESS_READ,
3187 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
3188 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,CON_MASK),
3189 .info = snd_hdsp_control_spdif_mask_info,
3190 .get = snd_hdsp_control_spdif_mask_get,
3191 .private_value = IEC958_AES0_NONAUDIO |
3192 IEC958_AES0_PROFESSIONAL |
3193 IEC958_AES0_CON_EMPHASIS,
3196 .access = SNDRV_CTL_ELEM_ACCESS_READ,
3197 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
3198 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,PRO_MASK),
3199 .info = snd_hdsp_control_spdif_mask_info,
3200 .get = snd_hdsp_control_spdif_mask_get,
3201 .private_value = IEC958_AES0_NONAUDIO |
3202 IEC958_AES0_PROFESSIONAL |
3203 IEC958_AES0_PRO_EMPHASIS,
3205 HDSP_MIXER("Mixer", 0),
3206 HDSP_SPDIF_IN("IEC958 Input Connector", 0),
3207 HDSP_SPDIF_OUT("IEC958 Output also on ADAT1", 0),
3208 HDSP_SPDIF_PROFESSIONAL("IEC958 Professional Bit", 0),
3209 HDSP_SPDIF_EMPHASIS("IEC958 Emphasis Bit", 0),
3210 HDSP_SPDIF_NON_AUDIO("IEC958 Non-audio Bit", 0),
3211 /* 'Sample Clock Source' complies with the alsa control naming scheme */
3212 HDSP_CLOCK_SOURCE("Sample Clock Source", 0),
3214 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3215 .name = "Sample Clock Source Locking",
3216 .info = snd_hdsp_info_clock_source_lock,
3217 .get = snd_hdsp_get_clock_source_lock,
3218 .put = snd_hdsp_put_clock_source_lock,
3220 HDSP_SYSTEM_CLOCK_MODE("System Clock Mode", 0),
3221 HDSP_PREF_SYNC_REF("Preferred Sync Reference", 0),
3222 HDSP_AUTOSYNC_REF("AutoSync Reference", 0),
3223 HDSP_SPDIF_SAMPLE_RATE("SPDIF Sample Rate", 0),
3224 HDSP_SYSTEM_SAMPLE_RATE("System Sample Rate", 0),
3225 /* 'External Rate' complies with the alsa control naming scheme */
3226 HDSP_AUTOSYNC_SAMPLE_RATE("External Rate", 0),
3227 HDSP_WC_SYNC_CHECK("Word Clock Lock Status", 0),
3228 HDSP_SPDIF_SYNC_CHECK("SPDIF Lock Status", 0),
3229 HDSP_ADATSYNC_SYNC_CHECK("ADAT Sync Lock Status", 0),
3230 HDSP_LINE_OUT("Line Out", 0),
3231 HDSP_PRECISE_POINTER("Precise Pointer", 0),
3232 HDSP_USE_MIDI_TASKLET("Use Midi Tasklet", 0),
3235 static struct snd_kcontrol_new snd_hdsp_96xx_aeb = HDSP_AEB("Analog Extension Board", 0);
3236 static struct snd_kcontrol_new snd_hdsp_adat_sync_check = HDSP_ADAT_SYNC_CHECK;
3238 static int snd_hdsp_create_controls(struct snd_card *card, struct hdsp *hdsp)
3242 struct snd_kcontrol *kctl;
3244 for (idx = 0; idx < ARRAY_SIZE(snd_hdsp_controls); idx++) {
3245 if ((err = snd_ctl_add(card, kctl = snd_ctl_new1(&snd_hdsp_controls[idx], hdsp))) < 0)
3247 if (idx == 1) /* IEC958 (S/PDIF) Stream */
3248 hdsp->spdif_ctl = kctl;
3251 /* ADAT SyncCheck status */
3252 snd_hdsp_adat_sync_check.name = "ADAT Lock Status";
3253 snd_hdsp_adat_sync_check.index = 1;
3254 if ((err = snd_ctl_add (card, kctl = snd_ctl_new1(&snd_hdsp_adat_sync_check, hdsp))))
3256 if (hdsp->io_type == Digiface || hdsp->io_type == H9652) {
3257 for (idx = 1; idx < 3; ++idx) {
3258 snd_hdsp_adat_sync_check.index = idx+1;
3259 if ((err = snd_ctl_add (card, kctl = snd_ctl_new1(&snd_hdsp_adat_sync_check, hdsp))))
3264 /* DA, AD and Phone gain and XLR breakout cable controls for H9632 cards */
3265 if (hdsp->io_type == H9632) {
3266 for (idx = 0; idx < ARRAY_SIZE(snd_hdsp_9632_controls); idx++) {
3267 if ((err = snd_ctl_add(card, kctl = snd_ctl_new1(&snd_hdsp_9632_controls[idx], hdsp))) < 0)
3272 /* AEB control for H96xx card */
3273 if (hdsp->io_type == H9632 || hdsp->io_type == H9652) {
3274 if ((err = snd_ctl_add(card, kctl = snd_ctl_new1(&snd_hdsp_96xx_aeb, hdsp))) < 0)
3281 /*------------------------------------------------------------
3283 ------------------------------------------------------------*/
3286 snd_hdsp_proc_read(struct snd_info_entry *entry, struct snd_info_buffer *buffer)
3288 struct hdsp *hdsp = (struct hdsp *) entry->private_data;
3289 unsigned int status;
3290 unsigned int status2;
3291 char *pref_sync_ref;
3293 char *system_clock_mode;
3297 if (hdsp_check_for_iobox (hdsp)) {
3298 snd_iprintf(buffer, "No I/O box connected.\nPlease connect one and upload firmware.\n");
3302 if (hdsp_check_for_firmware(hdsp, 0)) {
3303 if (hdsp->state & HDSP_FirmwareCached) {
3304 if (snd_hdsp_load_firmware_from_cache(hdsp) != 0) {
3305 snd_iprintf(buffer, "Firmware loading from cache failed, please upload manually.\n");
3310 #ifdef HDSP_FW_LOADER
3311 err = hdsp_request_fw_loader(hdsp);
3315 "No firmware loaded nor cached, "
3316 "please upload firmware.\n");
3322 status = hdsp_read(hdsp, HDSP_statusRegister);
3323 status2 = hdsp_read(hdsp, HDSP_status2Register);
3325 snd_iprintf(buffer, "%s (Card #%d)\n", hdsp->card_name, hdsp->card->number + 1);
3326 snd_iprintf(buffer, "Buffers: capture %p playback %p\n",
3327 hdsp->capture_buffer, hdsp->playback_buffer);
3328 snd_iprintf(buffer, "IRQ: %d Registers bus: 0x%lx VM: 0x%lx\n",
3329 hdsp->irq, hdsp->port, (unsigned long)hdsp->iobase);
3330 snd_iprintf(buffer, "Control register: 0x%x\n", hdsp->control_register);
3331 snd_iprintf(buffer, "Control2 register: 0x%x\n", hdsp->control2_register);
3332 snd_iprintf(buffer, "Status register: 0x%x\n", status);
3333 snd_iprintf(buffer, "Status2 register: 0x%x\n", status2);
3334 snd_iprintf(buffer, "FIFO status: %d\n", hdsp_read(hdsp, HDSP_fifoStatus) & 0xff);
3335 snd_iprintf(buffer, "MIDI1 Output status: 0x%x\n", hdsp_read(hdsp, HDSP_midiStatusOut0));
3336 snd_iprintf(buffer, "MIDI1 Input status: 0x%x\n", hdsp_read(hdsp, HDSP_midiStatusIn0));
3337 snd_iprintf(buffer, "MIDI2 Output status: 0x%x\n", hdsp_read(hdsp, HDSP_midiStatusOut1));
3338 snd_iprintf(buffer, "MIDI2 Input status: 0x%x\n", hdsp_read(hdsp, HDSP_midiStatusIn1));
3339 snd_iprintf(buffer, "Use Midi Tasklet: %s\n", hdsp->use_midi_tasklet ? "on" : "off");
3341 snd_iprintf(buffer, "\n");
3343 x = 1 << (6 + hdsp_decode_latency(hdsp->control_register & HDSP_LatencyMask));
3345 snd_iprintf(buffer, "Buffer Size (Latency): %d samples (2 periods of %lu bytes)\n", x, (unsigned long) hdsp->period_bytes);
3346 snd_iprintf(buffer, "Hardware pointer (frames): %ld\n", hdsp_hw_pointer(hdsp));
3347 snd_iprintf(buffer, "Precise pointer: %s\n", hdsp->precise_ptr ? "on" : "off");
3348 snd_iprintf(buffer, "Line out: %s\n", (hdsp->control_register & HDSP_LineOut) ? "on" : "off");
3350 snd_iprintf(buffer, "Firmware version: %d\n", (status2&HDSP_version0)|(status2&HDSP_version1)<<1|(status2&HDSP_version2)<<2);
3352 snd_iprintf(buffer, "\n");
3355 switch (hdsp_clock_source(hdsp)) {
3356 case HDSP_CLOCK_SOURCE_AUTOSYNC:
3357 clock_source = "AutoSync";
3359 case HDSP_CLOCK_SOURCE_INTERNAL_32KHZ:
3360 clock_source = "Internal 32 kHz";
3362 case HDSP_CLOCK_SOURCE_INTERNAL_44_1KHZ:
3363 clock_source = "Internal 44.1 kHz";
3365 case HDSP_CLOCK_SOURCE_INTERNAL_48KHZ:
3366 clock_source = "Internal 48 kHz";
3368 case HDSP_CLOCK_SOURCE_INTERNAL_64KHZ:
3369 clock_source = "Internal 64 kHz";
3371 case HDSP_CLOCK_SOURCE_INTERNAL_88_2KHZ:
3372 clock_source = "Internal 88.2 kHz";
3374 case HDSP_CLOCK_SOURCE_INTERNAL_96KHZ:
3375 clock_source = "Internal 96 kHz";
3377 case HDSP_CLOCK_SOURCE_INTERNAL_128KHZ:
3378 clock_source = "Internal 128 kHz";
3380 case HDSP_CLOCK_SOURCE_INTERNAL_176_4KHZ:
3381 clock_source = "Internal 176.4 kHz";
3383 case HDSP_CLOCK_SOURCE_INTERNAL_192KHZ:
3384 clock_source = "Internal 192 kHz";
3387 clock_source = "Error";
3389 snd_iprintf (buffer, "Sample Clock Source: %s\n", clock_source);
3391 if (hdsp_system_clock_mode(hdsp))
3392 system_clock_mode = "Slave";
3394 system_clock_mode = "Master";
3396 switch (hdsp_pref_sync_ref (hdsp)) {
3397 case HDSP_SYNC_FROM_WORD:
3398 pref_sync_ref = "Word Clock";
3400 case HDSP_SYNC_FROM_ADAT_SYNC:
3401 pref_sync_ref = "ADAT Sync";
3403 case HDSP_SYNC_FROM_SPDIF:
3404 pref_sync_ref = "SPDIF";
3406 case HDSP_SYNC_FROM_ADAT1:
3407 pref_sync_ref = "ADAT1";
3409 case HDSP_SYNC_FROM_ADAT2:
3410 pref_sync_ref = "ADAT2";
3412 case HDSP_SYNC_FROM_ADAT3:
3413 pref_sync_ref = "ADAT3";
3416 pref_sync_ref = "Word Clock";
3419 snd_iprintf (buffer, "Preferred Sync Reference: %s\n", pref_sync_ref);
3421 switch (hdsp_autosync_ref (hdsp)) {
3422 case HDSP_AUTOSYNC_FROM_WORD:
3423 autosync_ref = "Word Clock";
3425 case HDSP_AUTOSYNC_FROM_ADAT_SYNC:
3426 autosync_ref = "ADAT Sync";
3428 case HDSP_AUTOSYNC_FROM_SPDIF:
3429 autosync_ref = "SPDIF";
3431 case HDSP_AUTOSYNC_FROM_NONE:
3432 autosync_ref = "None";
3434 case HDSP_AUTOSYNC_FROM_ADAT1:
3435 autosync_ref = "ADAT1";
3437 case HDSP_AUTOSYNC_FROM_ADAT2:
3438 autosync_ref = "ADAT2";
3440 case HDSP_AUTOSYNC_FROM_ADAT3: