1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * ALSA driver for RME Hammerfall DSP audio interface(s)
5 * Copyright (c) 2002 Paul Davis
10 #include <linux/init.h>
11 #include <linux/delay.h>
12 #include <linux/interrupt.h>
13 #include <linux/pci.h>
14 #include <linux/firmware.h>
15 #include <linux/module.h>
16 #include <linux/math64.h>
17 #include <linux/vmalloc.h>
19 #include <linux/nospec.h>
21 #include <sound/core.h>
22 #include <sound/control.h>
23 #include <sound/pcm.h>
24 #include <sound/info.h>
25 #include <sound/asoundef.h>
26 #include <sound/rawmidi.h>
27 #include <sound/hwdep.h>
28 #include <sound/initval.h>
29 #include <sound/hdsp.h>
31 #include <asm/byteorder.h>
32 #include <asm/current.h>
34 static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
35 static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
36 static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP; /* Enable this card */
38 module_param_array(index, int, NULL, 0444);
39 MODULE_PARM_DESC(index, "Index value for RME Hammerfall DSP interface.");
40 module_param_array(id, charp, NULL, 0444);
41 MODULE_PARM_DESC(id, "ID string for RME Hammerfall DSP interface.");
42 module_param_array(enable, bool, NULL, 0444);
43 MODULE_PARM_DESC(enable, "Enable/disable specific Hammerfall DSP soundcards.");
44 MODULE_AUTHOR("Paul Davis <paul@linuxaudiosystems.com>, Marcus Andersson, Thomas Charbonnel <thomas@undata.org>");
45 MODULE_DESCRIPTION("RME Hammerfall DSP");
46 MODULE_LICENSE("GPL");
47 MODULE_SUPPORTED_DEVICE("{{RME Hammerfall-DSP},"
50 MODULE_FIRMWARE("rpm_firmware.bin");
51 MODULE_FIRMWARE("multiface_firmware.bin");
52 MODULE_FIRMWARE("multiface_firmware_rev11.bin");
53 MODULE_FIRMWARE("digiface_firmware.bin");
54 MODULE_FIRMWARE("digiface_firmware_rev11.bin");
56 #define HDSP_MAX_CHANNELS 26
57 #define HDSP_MAX_DS_CHANNELS 14
58 #define HDSP_MAX_QS_CHANNELS 8
59 #define DIGIFACE_SS_CHANNELS 26
60 #define DIGIFACE_DS_CHANNELS 14
61 #define MULTIFACE_SS_CHANNELS 18
62 #define MULTIFACE_DS_CHANNELS 14
63 #define H9652_SS_CHANNELS 26
64 #define H9652_DS_CHANNELS 14
65 /* This does not include possible Analog Extension Boards
66 AEBs are detected at card initialization
68 #define H9632_SS_CHANNELS 12
69 #define H9632_DS_CHANNELS 8
70 #define H9632_QS_CHANNELS 4
71 #define RPM_CHANNELS 6
73 /* Write registers. These are defined as byte-offsets from the iobase value.
75 #define HDSP_resetPointer 0
76 #define HDSP_freqReg 0
77 #define HDSP_outputBufferAddress 32
78 #define HDSP_inputBufferAddress 36
79 #define HDSP_controlRegister 64
80 #define HDSP_interruptConfirmation 96
81 #define HDSP_outputEnable 128
82 #define HDSP_control2Reg 256
83 #define HDSP_midiDataOut0 352
84 #define HDSP_midiDataOut1 356
85 #define HDSP_fifoData 368
86 #define HDSP_inputEnable 384
88 /* Read registers. These are defined as byte-offsets from the iobase value
91 #define HDSP_statusRegister 0
92 #define HDSP_timecode 128
93 #define HDSP_status2Register 192
94 #define HDSP_midiDataIn0 360
95 #define HDSP_midiDataIn1 364
96 #define HDSP_midiStatusOut0 384
97 #define HDSP_midiStatusOut1 388
98 #define HDSP_midiStatusIn0 392
99 #define HDSP_midiStatusIn1 396
100 #define HDSP_fifoStatus 400
102 /* the meters are regular i/o-mapped registers, but offset
103 considerably from the rest. the peak registers are reset
104 when read; the least-significant 4 bits are full-scale counters;
105 the actual peak value is in the most-significant 24 bits.
108 #define HDSP_playbackPeakLevel 4096 /* 26 * 32 bit values */
109 #define HDSP_inputPeakLevel 4224 /* 26 * 32 bit values */
110 #define HDSP_outputPeakLevel 4352 /* (26+2) * 32 bit values */
111 #define HDSP_playbackRmsLevel 4612 /* 26 * 64 bit values */
112 #define HDSP_inputRmsLevel 4868 /* 26 * 64 bit values */
115 /* This is for H9652 cards
116 Peak values are read downward from the base
117 Rms values are read upward
118 There are rms values for the outputs too
119 26*3 values are read in ss mode
120 14*3 in ds mode, with no gap between values
122 #define HDSP_9652_peakBase 7164
123 #define HDSP_9652_rmsBase 4096
125 /* c.f. the hdsp_9632_meters_t struct */
126 #define HDSP_9632_metersBase 4096
128 #define HDSP_IO_EXTENT 7168
130 /* control2 register bits */
132 #define HDSP_TMS 0x01
133 #define HDSP_TCK 0x02
134 #define HDSP_TDI 0x04
135 #define HDSP_JTAG 0x08
136 #define HDSP_PWDN 0x10
137 #define HDSP_PROGRAM 0x020
138 #define HDSP_CONFIG_MODE_0 0x040
139 #define HDSP_CONFIG_MODE_1 0x080
140 #define HDSP_VERSION_BIT (0x100 | HDSP_S_LOAD)
141 #define HDSP_BIGENDIAN_MODE 0x200
142 #define HDSP_RD_MULTIPLE 0x400
143 #define HDSP_9652_ENABLE_MIXER 0x800
144 #define HDSP_S200 0x800
145 #define HDSP_S300 (0x100 | HDSP_S200) /* dummy, purpose of 0x100 unknown */
146 #define HDSP_CYCLIC_MODE 0x1000
147 #define HDSP_TDO 0x10000000
149 #define HDSP_S_PROGRAM (HDSP_CYCLIC_MODE|HDSP_PROGRAM|HDSP_CONFIG_MODE_0)
150 #define HDSP_S_LOAD (HDSP_CYCLIC_MODE|HDSP_PROGRAM|HDSP_CONFIG_MODE_1)
152 /* Control Register bits */
154 #define HDSP_Start (1<<0) /* start engine */
155 #define HDSP_Latency0 (1<<1) /* buffer size = 2^n where n is defined by Latency{2,1,0} */
156 #define HDSP_Latency1 (1<<2) /* [ see above ] */
157 #define HDSP_Latency2 (1<<3) /* [ see above ] */
158 #define HDSP_ClockModeMaster (1<<4) /* 1=Master, 0=Slave/Autosync */
159 #define HDSP_AudioInterruptEnable (1<<5) /* what do you think ? */
160 #define HDSP_Frequency0 (1<<6) /* 0=44.1kHz/88.2kHz/176.4kHz 1=48kHz/96kHz/192kHz */
161 #define HDSP_Frequency1 (1<<7) /* 0=32kHz/64kHz/128kHz */
162 #define HDSP_DoubleSpeed (1<<8) /* 0=normal speed, 1=double speed */
163 #define HDSP_SPDIFProfessional (1<<9) /* 0=consumer, 1=professional */
164 #define HDSP_SPDIFEmphasis (1<<10) /* 0=none, 1=on */
165 #define HDSP_SPDIFNonAudio (1<<11) /* 0=off, 1=on */
166 #define HDSP_SPDIFOpticalOut (1<<12) /* 1=use 1st ADAT connector for SPDIF, 0=do not */
167 #define HDSP_SyncRef2 (1<<13)
168 #define HDSP_SPDIFInputSelect0 (1<<14)
169 #define HDSP_SPDIFInputSelect1 (1<<15)
170 #define HDSP_SyncRef0 (1<<16)
171 #define HDSP_SyncRef1 (1<<17)
172 #define HDSP_AnalogExtensionBoard (1<<18) /* For H9632 cards */
173 #define HDSP_XLRBreakoutCable (1<<20) /* For H9632 cards */
174 #define HDSP_Midi0InterruptEnable (1<<22)
175 #define HDSP_Midi1InterruptEnable (1<<23)
176 #define HDSP_LineOut (1<<24)
177 #define HDSP_ADGain0 (1<<25) /* From here : H9632 specific */
178 #define HDSP_ADGain1 (1<<26)
179 #define HDSP_DAGain0 (1<<27)
180 #define HDSP_DAGain1 (1<<28)
181 #define HDSP_PhoneGain0 (1<<29)
182 #define HDSP_PhoneGain1 (1<<30)
183 #define HDSP_QuadSpeed (1<<31)
185 /* RPM uses some of the registers for special purposes */
186 #define HDSP_RPM_Inp12 0x04A00
187 #define HDSP_RPM_Inp12_Phon_6dB 0x00800 /* Dolby */
188 #define HDSP_RPM_Inp12_Phon_0dB 0x00000 /* .. */
189 #define HDSP_RPM_Inp12_Phon_n6dB 0x04000 /* inp_0 */
190 #define HDSP_RPM_Inp12_Line_0dB 0x04200 /* Dolby+PRO */
191 #define HDSP_RPM_Inp12_Line_n6dB 0x00200 /* PRO */
193 #define HDSP_RPM_Inp34 0x32000
194 #define HDSP_RPM_Inp34_Phon_6dB 0x20000 /* SyncRef1 */
195 #define HDSP_RPM_Inp34_Phon_0dB 0x00000 /* .. */
196 #define HDSP_RPM_Inp34_Phon_n6dB 0x02000 /* SyncRef2 */
197 #define HDSP_RPM_Inp34_Line_0dB 0x30000 /* SyncRef1+SyncRef0 */
198 #define HDSP_RPM_Inp34_Line_n6dB 0x10000 /* SyncRef0 */
200 #define HDSP_RPM_Bypass 0x01000
202 #define HDSP_RPM_Disconnect 0x00001
204 #define HDSP_ADGainMask (HDSP_ADGain0|HDSP_ADGain1)
205 #define HDSP_ADGainMinus10dBV HDSP_ADGainMask
206 #define HDSP_ADGainPlus4dBu (HDSP_ADGain0)
207 #define HDSP_ADGainLowGain 0
209 #define HDSP_DAGainMask (HDSP_DAGain0|HDSP_DAGain1)
210 #define HDSP_DAGainHighGain HDSP_DAGainMask
211 #define HDSP_DAGainPlus4dBu (HDSP_DAGain0)
212 #define HDSP_DAGainMinus10dBV 0
214 #define HDSP_PhoneGainMask (HDSP_PhoneGain0|HDSP_PhoneGain1)
215 #define HDSP_PhoneGain0dB HDSP_PhoneGainMask
216 #define HDSP_PhoneGainMinus6dB (HDSP_PhoneGain0)
217 #define HDSP_PhoneGainMinus12dB 0
219 #define HDSP_LatencyMask (HDSP_Latency0|HDSP_Latency1|HDSP_Latency2)
220 #define HDSP_FrequencyMask (HDSP_Frequency0|HDSP_Frequency1|HDSP_DoubleSpeed|HDSP_QuadSpeed)
222 #define HDSP_SPDIFInputMask (HDSP_SPDIFInputSelect0|HDSP_SPDIFInputSelect1)
223 #define HDSP_SPDIFInputADAT1 0
224 #define HDSP_SPDIFInputCoaxial (HDSP_SPDIFInputSelect0)
225 #define HDSP_SPDIFInputCdrom (HDSP_SPDIFInputSelect1)
226 #define HDSP_SPDIFInputAES (HDSP_SPDIFInputSelect0|HDSP_SPDIFInputSelect1)
228 #define HDSP_SyncRefMask (HDSP_SyncRef0|HDSP_SyncRef1|HDSP_SyncRef2)
229 #define HDSP_SyncRef_ADAT1 0
230 #define HDSP_SyncRef_ADAT2 (HDSP_SyncRef0)
231 #define HDSP_SyncRef_ADAT3 (HDSP_SyncRef1)
232 #define HDSP_SyncRef_SPDIF (HDSP_SyncRef0|HDSP_SyncRef1)
233 #define HDSP_SyncRef_WORD (HDSP_SyncRef2)
234 #define HDSP_SyncRef_ADAT_SYNC (HDSP_SyncRef0|HDSP_SyncRef2)
236 /* Sample Clock Sources */
238 #define HDSP_CLOCK_SOURCE_AUTOSYNC 0
239 #define HDSP_CLOCK_SOURCE_INTERNAL_32KHZ 1
240 #define HDSP_CLOCK_SOURCE_INTERNAL_44_1KHZ 2
241 #define HDSP_CLOCK_SOURCE_INTERNAL_48KHZ 3
242 #define HDSP_CLOCK_SOURCE_INTERNAL_64KHZ 4
243 #define HDSP_CLOCK_SOURCE_INTERNAL_88_2KHZ 5
244 #define HDSP_CLOCK_SOURCE_INTERNAL_96KHZ 6
245 #define HDSP_CLOCK_SOURCE_INTERNAL_128KHZ 7
246 #define HDSP_CLOCK_SOURCE_INTERNAL_176_4KHZ 8
247 #define HDSP_CLOCK_SOURCE_INTERNAL_192KHZ 9
249 /* Preferred sync reference choices - used by "pref_sync_ref" control switch */
251 #define HDSP_SYNC_FROM_WORD 0
252 #define HDSP_SYNC_FROM_SPDIF 1
253 #define HDSP_SYNC_FROM_ADAT1 2
254 #define HDSP_SYNC_FROM_ADAT_SYNC 3
255 #define HDSP_SYNC_FROM_ADAT2 4
256 #define HDSP_SYNC_FROM_ADAT3 5
258 /* SyncCheck status */
260 #define HDSP_SYNC_CHECK_NO_LOCK 0
261 #define HDSP_SYNC_CHECK_LOCK 1
262 #define HDSP_SYNC_CHECK_SYNC 2
264 /* AutoSync references - used by "autosync_ref" control switch */
266 #define HDSP_AUTOSYNC_FROM_WORD 0
267 #define HDSP_AUTOSYNC_FROM_ADAT_SYNC 1
268 #define HDSP_AUTOSYNC_FROM_SPDIF 2
269 #define HDSP_AUTOSYNC_FROM_NONE 3
270 #define HDSP_AUTOSYNC_FROM_ADAT1 4
271 #define HDSP_AUTOSYNC_FROM_ADAT2 5
272 #define HDSP_AUTOSYNC_FROM_ADAT3 6
274 /* Possible sources of S/PDIF input */
276 #define HDSP_SPDIFIN_OPTICAL 0 /* optical (ADAT1) */
277 #define HDSP_SPDIFIN_COAXIAL 1 /* coaxial (RCA) */
278 #define HDSP_SPDIFIN_INTERNAL 2 /* internal (CDROM) */
279 #define HDSP_SPDIFIN_AES 3 /* xlr for H9632 (AES)*/
281 #define HDSP_Frequency32KHz HDSP_Frequency0
282 #define HDSP_Frequency44_1KHz HDSP_Frequency1
283 #define HDSP_Frequency48KHz (HDSP_Frequency1|HDSP_Frequency0)
284 #define HDSP_Frequency64KHz (HDSP_DoubleSpeed|HDSP_Frequency0)
285 #define HDSP_Frequency88_2KHz (HDSP_DoubleSpeed|HDSP_Frequency1)
286 #define HDSP_Frequency96KHz (HDSP_DoubleSpeed|HDSP_Frequency1|HDSP_Frequency0)
287 /* For H9632 cards */
288 #define HDSP_Frequency128KHz (HDSP_QuadSpeed|HDSP_DoubleSpeed|HDSP_Frequency0)
289 #define HDSP_Frequency176_4KHz (HDSP_QuadSpeed|HDSP_DoubleSpeed|HDSP_Frequency1)
290 #define HDSP_Frequency192KHz (HDSP_QuadSpeed|HDSP_DoubleSpeed|HDSP_Frequency1|HDSP_Frequency0)
291 /* RME says n = 104857600000000, but in the windows MADI driver, I see:
292 return 104857600000000 / rate; // 100 MHz
293 return 110100480000000 / rate; // 105 MHz
295 #define DDS_NUMERATOR 104857600000000ULL; /* = 2^20 * 10^8 */
297 #define hdsp_encode_latency(x) (((x)<<1) & HDSP_LatencyMask)
298 #define hdsp_decode_latency(x) (((x) & HDSP_LatencyMask)>>1)
300 #define hdsp_encode_spdif_in(x) (((x)&0x3)<<14)
301 #define hdsp_decode_spdif_in(x) (((x)>>14)&0x3)
303 /* Status Register bits */
305 #define HDSP_audioIRQPending (1<<0)
306 #define HDSP_Lock2 (1<<1) /* this is for Digiface and H9652 */
307 #define HDSP_spdifFrequency3 HDSP_Lock2 /* this is for H9632 only */
308 #define HDSP_Lock1 (1<<2)
309 #define HDSP_Lock0 (1<<3)
310 #define HDSP_SPDIFSync (1<<4)
311 #define HDSP_TimecodeLock (1<<5)
312 #define HDSP_BufferPositionMask 0x000FFC0 /* Bit 6..15 : h/w buffer pointer */
313 #define HDSP_Sync2 (1<<16)
314 #define HDSP_Sync1 (1<<17)
315 #define HDSP_Sync0 (1<<18)
316 #define HDSP_DoubleSpeedStatus (1<<19)
317 #define HDSP_ConfigError (1<<20)
318 #define HDSP_DllError (1<<21)
319 #define HDSP_spdifFrequency0 (1<<22)
320 #define HDSP_spdifFrequency1 (1<<23)
321 #define HDSP_spdifFrequency2 (1<<24)
322 #define HDSP_SPDIFErrorFlag (1<<25)
323 #define HDSP_BufferID (1<<26)
324 #define HDSP_TimecodeSync (1<<27)
325 #define HDSP_AEBO (1<<28) /* H9632 specific Analog Extension Boards */
326 #define HDSP_AEBI (1<<29) /* 0 = present, 1 = absent */
327 #define HDSP_midi0IRQPending (1<<30)
328 #define HDSP_midi1IRQPending (1<<31)
330 #define HDSP_spdifFrequencyMask (HDSP_spdifFrequency0|HDSP_spdifFrequency1|HDSP_spdifFrequency2)
331 #define HDSP_spdifFrequencyMask_9632 (HDSP_spdifFrequency0|\
332 HDSP_spdifFrequency1|\
333 HDSP_spdifFrequency2|\
334 HDSP_spdifFrequency3)
336 #define HDSP_spdifFrequency32KHz (HDSP_spdifFrequency0)
337 #define HDSP_spdifFrequency44_1KHz (HDSP_spdifFrequency1)
338 #define HDSP_spdifFrequency48KHz (HDSP_spdifFrequency0|HDSP_spdifFrequency1)
340 #define HDSP_spdifFrequency64KHz (HDSP_spdifFrequency2)
341 #define HDSP_spdifFrequency88_2KHz (HDSP_spdifFrequency0|HDSP_spdifFrequency2)
342 #define HDSP_spdifFrequency96KHz (HDSP_spdifFrequency2|HDSP_spdifFrequency1)
344 /* This is for H9632 cards */
345 #define HDSP_spdifFrequency128KHz (HDSP_spdifFrequency0|\
346 HDSP_spdifFrequency1|\
347 HDSP_spdifFrequency2)
348 #define HDSP_spdifFrequency176_4KHz HDSP_spdifFrequency3
349 #define HDSP_spdifFrequency192KHz (HDSP_spdifFrequency3|HDSP_spdifFrequency0)
351 /* Status2 Register bits */
353 #define HDSP_version0 (1<<0)
354 #define HDSP_version1 (1<<1)
355 #define HDSP_version2 (1<<2)
356 #define HDSP_wc_lock (1<<3)
357 #define HDSP_wc_sync (1<<4)
358 #define HDSP_inp_freq0 (1<<5)
359 #define HDSP_inp_freq1 (1<<6)
360 #define HDSP_inp_freq2 (1<<7)
361 #define HDSP_SelSyncRef0 (1<<8)
362 #define HDSP_SelSyncRef1 (1<<9)
363 #define HDSP_SelSyncRef2 (1<<10)
365 #define HDSP_wc_valid (HDSP_wc_lock|HDSP_wc_sync)
367 #define HDSP_systemFrequencyMask (HDSP_inp_freq0|HDSP_inp_freq1|HDSP_inp_freq2)
368 #define HDSP_systemFrequency32 (HDSP_inp_freq0)
369 #define HDSP_systemFrequency44_1 (HDSP_inp_freq1)
370 #define HDSP_systemFrequency48 (HDSP_inp_freq0|HDSP_inp_freq1)
371 #define HDSP_systemFrequency64 (HDSP_inp_freq2)
372 #define HDSP_systemFrequency88_2 (HDSP_inp_freq0|HDSP_inp_freq2)
373 #define HDSP_systemFrequency96 (HDSP_inp_freq1|HDSP_inp_freq2)
374 /* FIXME : more values for 9632 cards ? */
376 #define HDSP_SelSyncRefMask (HDSP_SelSyncRef0|HDSP_SelSyncRef1|HDSP_SelSyncRef2)
377 #define HDSP_SelSyncRef_ADAT1 0
378 #define HDSP_SelSyncRef_ADAT2 (HDSP_SelSyncRef0)
379 #define HDSP_SelSyncRef_ADAT3 (HDSP_SelSyncRef1)
380 #define HDSP_SelSyncRef_SPDIF (HDSP_SelSyncRef0|HDSP_SelSyncRef1)
381 #define HDSP_SelSyncRef_WORD (HDSP_SelSyncRef2)
382 #define HDSP_SelSyncRef_ADAT_SYNC (HDSP_SelSyncRef0|HDSP_SelSyncRef2)
384 /* Card state flags */
386 #define HDSP_InitializationComplete (1<<0)
387 #define HDSP_FirmwareLoaded (1<<1)
388 #define HDSP_FirmwareCached (1<<2)
390 /* FIFO wait times, defined in terms of 1/10ths of msecs */
392 #define HDSP_LONG_WAIT 5000
393 #define HDSP_SHORT_WAIT 30
395 #define UNITY_GAIN 32768
396 #define MINUS_INFINITY_GAIN 0
398 /* the size of a substream (1 mono data stream) */
400 #define HDSP_CHANNEL_BUFFER_SAMPLES (16*1024)
401 #define HDSP_CHANNEL_BUFFER_BYTES (4*HDSP_CHANNEL_BUFFER_SAMPLES)
403 /* the size of the area we need to allocate for DMA transfers. the
404 size is the same regardless of the number of channels - the
405 Multiface still uses the same memory area.
407 Note that we allocate 1 more channel than is apparently needed
408 because the h/w seems to write 1 byte beyond the end of the last
412 #define HDSP_DMA_AREA_BYTES ((HDSP_MAX_CHANNELS+1) * HDSP_CHANNEL_BUFFER_BYTES)
413 #define HDSP_DMA_AREA_KILOBYTES (HDSP_DMA_AREA_BYTES/1024)
415 #define HDSP_FIRMWARE_SIZE (24413 * 4)
417 struct hdsp_9632_meters {
419 u32 playback_peak[16];
423 u32 input_rms_low[16];
424 u32 playback_rms_low[16];
425 u32 output_rms_low[16];
427 u32 input_rms_high[16];
428 u32 playback_rms_high[16];
429 u32 output_rms_high[16];
430 u32 xxx_rms_high[16];
436 struct snd_rawmidi *rmidi;
437 struct snd_rawmidi_substream *input;
438 struct snd_rawmidi_substream *output;
439 char istimer; /* timer in use */
440 struct timer_list timer;
447 struct snd_pcm_substream *capture_substream;
448 struct snd_pcm_substream *playback_substream;
449 struct hdsp_midi midi[2];
450 struct work_struct midi_work;
453 u32 control_register; /* cached value */
454 u32 control2_register; /* cached value */
456 u32 creg_spdif_stream;
457 int clock_source_locked;
458 char *card_name; /* digiface/multiface/rpm */
459 enum HDSP_IO_Type io_type; /* ditto, but for code use */
460 unsigned short firmware_rev;
461 unsigned short state; /* stores state bits */
462 const struct firmware *firmware;
464 size_t period_bytes; /* guess what this is */
465 unsigned char max_channels;
466 unsigned char qs_in_channels; /* quad speed mode for H9632 */
467 unsigned char ds_in_channels;
468 unsigned char ss_in_channels; /* different for multiface/digiface */
469 unsigned char qs_out_channels;
470 unsigned char ds_out_channels;
471 unsigned char ss_out_channels;
472 u32 io_loopback; /* output loopback channel states*/
474 struct snd_dma_buffer capture_dma_buf;
475 struct snd_dma_buffer playback_dma_buf;
476 unsigned char *capture_buffer; /* suitably aligned address */
477 unsigned char *playback_buffer; /* suitably aligned address */
482 int system_sample_rate;
483 const char *channel_map;
487 void __iomem *iobase;
488 struct snd_card *card;
490 struct snd_hwdep *hwdep;
492 struct snd_kcontrol *spdif_ctl;
493 unsigned short mixer_matrix[HDSP_MATRIX_MIXER_SIZE];
494 unsigned int dds_value; /* last value written to freq register */
497 /* These tables map the ALSA channels 1..N to the channels that we
498 need to use in order to find the relevant channel buffer. RME
499 refer to this kind of mapping as between "the ADAT channel and
500 the DMA channel." We index it using the logical audio channel,
501 and the value is the DMA channel (i.e. channel buffer number)
502 where the data for that channel can be read/written from/to.
505 static const char channel_map_df_ss[HDSP_MAX_CHANNELS] = {
506 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
507 18, 19, 20, 21, 22, 23, 24, 25
510 static const char channel_map_mf_ss[HDSP_MAX_CHANNELS] = { /* Multiface */
512 0, 1, 2, 3, 4, 5, 6, 7,
514 16, 17, 18, 19, 20, 21, 22, 23,
517 -1, -1, -1, -1, -1, -1, -1, -1
520 static const char channel_map_ds[HDSP_MAX_CHANNELS] = {
521 /* ADAT channels are remapped */
522 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23,
523 /* channels 12 and 13 are S/PDIF */
525 /* others don't exist */
526 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
529 static const char channel_map_H9632_ss[HDSP_MAX_CHANNELS] = {
531 0, 1, 2, 3, 4, 5, 6, 7,
536 /* AO4S-192 and AI4S-192 extension boards */
538 /* others don't exist */
539 -1, -1, -1, -1, -1, -1, -1, -1,
543 static const char channel_map_H9632_ds[HDSP_MAX_CHANNELS] = {
550 /* AO4S-192 and AI4S-192 extension boards */
552 /* others don't exist */
553 -1, -1, -1, -1, -1, -1, -1, -1,
554 -1, -1, -1, -1, -1, -1
557 static const char channel_map_H9632_qs[HDSP_MAX_CHANNELS] = {
558 /* ADAT is disabled in this mode */
563 /* AO4S-192 and AI4S-192 extension boards */
565 /* others don't exist */
566 -1, -1, -1, -1, -1, -1, -1, -1,
567 -1, -1, -1, -1, -1, -1, -1, -1,
571 static int snd_hammerfall_get_buffer(struct pci_dev *pci, struct snd_dma_buffer *dmab, size_t size)
573 return snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, &pci->dev, size, dmab);
576 static void snd_hammerfall_free_buffer(struct snd_dma_buffer *dmab, struct pci_dev *pci)
579 snd_dma_free_pages(dmab);
583 static const struct pci_device_id snd_hdsp_ids[] = {
585 .vendor = PCI_VENDOR_ID_XILINX,
586 .device = PCI_DEVICE_ID_XILINX_HAMMERFALL_DSP,
587 .subvendor = PCI_ANY_ID,
588 .subdevice = PCI_ANY_ID,
589 }, /* RME Hammerfall-DSP */
593 MODULE_DEVICE_TABLE(pci, snd_hdsp_ids);
596 static int snd_hdsp_create_alsa_devices(struct snd_card *card, struct hdsp *hdsp);
597 static int snd_hdsp_create_pcm(struct snd_card *card, struct hdsp *hdsp);
598 static int snd_hdsp_enable_io (struct hdsp *hdsp);
599 static void snd_hdsp_initialize_midi_flush (struct hdsp *hdsp);
600 static void snd_hdsp_initialize_channels (struct hdsp *hdsp);
601 static int hdsp_fifo_wait(struct hdsp *hdsp, int count, int timeout);
602 static int hdsp_autosync_ref(struct hdsp *hdsp);
603 static int snd_hdsp_set_defaults(struct hdsp *hdsp);
604 static void snd_hdsp_9652_enable_mixer (struct hdsp *hdsp);
606 static int hdsp_playback_to_output_key (struct hdsp *hdsp, int in, int out)
608 switch (hdsp->io_type) {
613 if (hdsp->firmware_rev == 0xa)
614 return (64 * out) + (32 + (in));
616 return (52 * out) + (26 + (in));
618 return (32 * out) + (16 + (in));
620 return (52 * out) + (26 + (in));
624 static int hdsp_input_to_output_key (struct hdsp *hdsp, int in, int out)
626 switch (hdsp->io_type) {
631 if (hdsp->firmware_rev == 0xa)
632 return (64 * out) + in;
634 return (52 * out) + in;
636 return (32 * out) + in;
638 return (52 * out) + in;
642 static void hdsp_write(struct hdsp *hdsp, int reg, int val)
644 writel(val, hdsp->iobase + reg);
647 static unsigned int hdsp_read(struct hdsp *hdsp, int reg)
649 return readl (hdsp->iobase + reg);
652 static int hdsp_check_for_iobox (struct hdsp *hdsp)
656 if (hdsp->io_type == H9652 || hdsp->io_type == H9632) return 0;
657 for (i = 0; i < 500; i++) {
658 if (0 == (hdsp_read(hdsp, HDSP_statusRegister) &
661 dev_dbg(hdsp->card->dev,
662 "IO box found after %d ms\n",
669 dev_err(hdsp->card->dev, "no IO box connected!\n");
670 hdsp->state &= ~HDSP_FirmwareLoaded;
674 static int hdsp_wait_for_iobox(struct hdsp *hdsp, unsigned int loops,
679 if (hdsp->io_type == H9652 || hdsp->io_type == H9632)
682 for (i = 0; i != loops; ++i) {
683 if (hdsp_read(hdsp, HDSP_statusRegister) & HDSP_ConfigError)
686 dev_dbg(hdsp->card->dev, "iobox found after %ums!\n",
692 dev_info(hdsp->card->dev, "no IO box connected!\n");
693 hdsp->state &= ~HDSP_FirmwareLoaded;
697 static int snd_hdsp_load_firmware_from_cache(struct hdsp *hdsp) {
703 if (hdsp->fw_uploaded)
704 cache = hdsp->fw_uploaded;
708 cache = (u32 *)hdsp->firmware->data;
713 if ((hdsp_read (hdsp, HDSP_statusRegister) & HDSP_DllError) != 0) {
715 dev_info(hdsp->card->dev, "loading firmware\n");
717 hdsp_write (hdsp, HDSP_control2Reg, HDSP_S_PROGRAM);
718 hdsp_write (hdsp, HDSP_fifoData, 0);
720 if (hdsp_fifo_wait (hdsp, 0, HDSP_LONG_WAIT)) {
721 dev_info(hdsp->card->dev,
722 "timeout waiting for download preparation\n");
723 hdsp_write(hdsp, HDSP_control2Reg, HDSP_S200);
727 hdsp_write (hdsp, HDSP_control2Reg, HDSP_S_LOAD);
729 for (i = 0; i < HDSP_FIRMWARE_SIZE / 4; ++i) {
730 hdsp_write(hdsp, HDSP_fifoData, cache[i]);
731 if (hdsp_fifo_wait (hdsp, 127, HDSP_LONG_WAIT)) {
732 dev_info(hdsp->card->dev,
733 "timeout during firmware loading\n");
734 hdsp_write(hdsp, HDSP_control2Reg, HDSP_S200);
739 hdsp_fifo_wait(hdsp, 3, HDSP_LONG_WAIT);
740 hdsp_write(hdsp, HDSP_control2Reg, HDSP_S200);
743 #ifdef SNDRV_BIG_ENDIAN
744 hdsp->control2_register = HDSP_BIGENDIAN_MODE;
746 hdsp->control2_register = 0;
748 hdsp_write (hdsp, HDSP_control2Reg, hdsp->control2_register);
749 dev_info(hdsp->card->dev, "finished firmware loading\n");
752 if (hdsp->state & HDSP_InitializationComplete) {
753 dev_info(hdsp->card->dev,
754 "firmware loaded from cache, restoring defaults\n");
755 spin_lock_irqsave(&hdsp->lock, flags);
756 snd_hdsp_set_defaults(hdsp);
757 spin_unlock_irqrestore(&hdsp->lock, flags);
760 hdsp->state |= HDSP_FirmwareLoaded;
765 static int hdsp_get_iobox_version (struct hdsp *hdsp)
767 if ((hdsp_read (hdsp, HDSP_statusRegister) & HDSP_DllError) != 0) {
769 hdsp_write(hdsp, HDSP_control2Reg, HDSP_S_LOAD);
770 hdsp_write(hdsp, HDSP_fifoData, 0);
772 if (hdsp_fifo_wait(hdsp, 0, HDSP_SHORT_WAIT) < 0) {
773 hdsp_write(hdsp, HDSP_control2Reg, HDSP_S300);
774 hdsp_write(hdsp, HDSP_control2Reg, HDSP_S_LOAD);
777 hdsp_write(hdsp, HDSP_control2Reg, HDSP_S200 | HDSP_PROGRAM);
778 hdsp_write (hdsp, HDSP_fifoData, 0);
779 if (hdsp_fifo_wait(hdsp, 0, HDSP_SHORT_WAIT) < 0)
782 hdsp_write(hdsp, HDSP_control2Reg, HDSP_S_LOAD);
783 hdsp_write(hdsp, HDSP_fifoData, 0);
784 if (hdsp_fifo_wait(hdsp, 0, HDSP_SHORT_WAIT) == 0) {
785 hdsp->io_type = Digiface;
786 dev_info(hdsp->card->dev, "Digiface found\n");
790 hdsp_write(hdsp, HDSP_control2Reg, HDSP_S300);
791 hdsp_write(hdsp, HDSP_control2Reg, HDSP_S_LOAD);
792 hdsp_write(hdsp, HDSP_fifoData, 0);
793 if (hdsp_fifo_wait(hdsp, 0, HDSP_SHORT_WAIT) == 0)
796 hdsp_write(hdsp, HDSP_control2Reg, HDSP_S300);
797 hdsp_write(hdsp, HDSP_control2Reg, HDSP_S_LOAD);
798 hdsp_write(hdsp, HDSP_fifoData, 0);
799 if (hdsp_fifo_wait(hdsp, 0, HDSP_SHORT_WAIT) < 0)
803 dev_info(hdsp->card->dev, "RPM found\n");
806 /* firmware was already loaded, get iobox type */
807 if (hdsp_read(hdsp, HDSP_status2Register) & HDSP_version2)
809 else if (hdsp_read(hdsp, HDSP_status2Register) & HDSP_version1)
810 hdsp->io_type = Multiface;
812 hdsp->io_type = Digiface;
817 hdsp->io_type = Multiface;
818 dev_info(hdsp->card->dev, "Multiface found\n");
823 static int hdsp_request_fw_loader(struct hdsp *hdsp);
825 static int hdsp_check_for_firmware (struct hdsp *hdsp, int load_on_demand)
827 if (hdsp->io_type == H9652 || hdsp->io_type == H9632)
829 if ((hdsp_read (hdsp, HDSP_statusRegister) & HDSP_DllError) != 0) {
830 hdsp->state &= ~HDSP_FirmwareLoaded;
831 if (! load_on_demand)
833 dev_err(hdsp->card->dev, "firmware not present.\n");
834 /* try to load firmware */
835 if (! (hdsp->state & HDSP_FirmwareCached)) {
836 if (! hdsp_request_fw_loader(hdsp))
838 dev_err(hdsp->card->dev,
839 "No firmware loaded nor cached, please upload firmware.\n");
842 if (snd_hdsp_load_firmware_from_cache(hdsp) != 0) {
843 dev_err(hdsp->card->dev,
844 "Firmware loading from cache failed, please upload manually.\n");
852 static int hdsp_fifo_wait(struct hdsp *hdsp, int count, int timeout)
856 /* the fifoStatus registers reports on how many words
857 are available in the command FIFO.
860 for (i = 0; i < timeout; i++) {
862 if ((int)(hdsp_read (hdsp, HDSP_fifoStatus) & 0xff) <= count)
865 /* not very friendly, but we only do this during a firmware
866 load and changing the mixer, so we just put up with it.
872 dev_warn(hdsp->card->dev,
873 "wait for FIFO status <= %d failed after %d iterations\n",
878 static int hdsp_read_gain (struct hdsp *hdsp, unsigned int addr)
880 if (addr >= HDSP_MATRIX_MIXER_SIZE)
883 return hdsp->mixer_matrix[addr];
886 static int hdsp_write_gain(struct hdsp *hdsp, unsigned int addr, unsigned short data)
890 if (addr >= HDSP_MATRIX_MIXER_SIZE)
893 if (hdsp->io_type == H9652 || hdsp->io_type == H9632) {
895 /* from martin bjornsen:
897 "You can only write dwords to the
898 mixer memory which contain two
899 mixer values in the low and high
900 word. So if you want to change
901 value 0 you have to read value 1
902 from the cache and write both to
903 the first dword in the mixer
907 if (hdsp->io_type == H9632 && addr >= 512)
910 if (hdsp->io_type == H9652 && addr >= 1352)
913 hdsp->mixer_matrix[addr] = data;
916 /* `addr' addresses a 16-bit wide address, but
917 the address space accessed via hdsp_write
918 uses byte offsets. put another way, addr
919 varies from 0 to 1351, but to access the
920 corresponding memory location, we need
921 to access 0 to 2703 ...
925 hdsp_write (hdsp, 4096 + (ad*4),
926 (hdsp->mixer_matrix[(addr&0x7fe)+1] << 16) +
927 hdsp->mixer_matrix[addr&0x7fe]);
933 ad = (addr << 16) + data;
935 if (hdsp_fifo_wait(hdsp, 127, HDSP_LONG_WAIT))
938 hdsp_write (hdsp, HDSP_fifoData, ad);
939 hdsp->mixer_matrix[addr] = data;
946 static int snd_hdsp_use_is_exclusive(struct hdsp *hdsp)
951 spin_lock_irqsave(&hdsp->lock, flags);
952 if ((hdsp->playback_pid != hdsp->capture_pid) &&
953 (hdsp->playback_pid >= 0) && (hdsp->capture_pid >= 0))
955 spin_unlock_irqrestore(&hdsp->lock, flags);
959 static int hdsp_spdif_sample_rate(struct hdsp *hdsp)
961 unsigned int status = hdsp_read(hdsp, HDSP_statusRegister);
962 unsigned int rate_bits = (status & HDSP_spdifFrequencyMask);
964 /* For the 9632, the mask is different */
965 if (hdsp->io_type == H9632)
966 rate_bits = (status & HDSP_spdifFrequencyMask_9632);
968 if (status & HDSP_SPDIFErrorFlag)
972 case HDSP_spdifFrequency32KHz: return 32000;
973 case HDSP_spdifFrequency44_1KHz: return 44100;
974 case HDSP_spdifFrequency48KHz: return 48000;
975 case HDSP_spdifFrequency64KHz: return 64000;
976 case HDSP_spdifFrequency88_2KHz: return 88200;
977 case HDSP_spdifFrequency96KHz: return 96000;
978 case HDSP_spdifFrequency128KHz:
979 if (hdsp->io_type == H9632) return 128000;
981 case HDSP_spdifFrequency176_4KHz:
982 if (hdsp->io_type == H9632) return 176400;
984 case HDSP_spdifFrequency192KHz:
985 if (hdsp->io_type == H9632) return 192000;
990 dev_warn(hdsp->card->dev,
991 "unknown spdif frequency status; bits = 0x%x, status = 0x%x\n",
996 static int hdsp_external_sample_rate(struct hdsp *hdsp)
998 unsigned int status2 = hdsp_read(hdsp, HDSP_status2Register);
999 unsigned int rate_bits = status2 & HDSP_systemFrequencyMask;
1001 /* For the 9632 card, there seems to be no bit for indicating external
1002 * sample rate greater than 96kHz. The card reports the corresponding
1003 * single speed. So the best means seems to get spdif rate when
1004 * autosync reference is spdif */
1005 if (hdsp->io_type == H9632 &&
1006 hdsp_autosync_ref(hdsp) == HDSP_AUTOSYNC_FROM_SPDIF)
1007 return hdsp_spdif_sample_rate(hdsp);
1009 switch (rate_bits) {
1010 case HDSP_systemFrequency32: return 32000;
1011 case HDSP_systemFrequency44_1: return 44100;
1012 case HDSP_systemFrequency48: return 48000;
1013 case HDSP_systemFrequency64: return 64000;
1014 case HDSP_systemFrequency88_2: return 88200;
1015 case HDSP_systemFrequency96: return 96000;
1021 static void hdsp_compute_period_size(struct hdsp *hdsp)
1023 hdsp->period_bytes = 1 << ((hdsp_decode_latency(hdsp->control_register) + 8));
1026 static snd_pcm_uframes_t hdsp_hw_pointer(struct hdsp *hdsp)
1030 position = hdsp_read(hdsp, HDSP_statusRegister);
1032 if (!hdsp->precise_ptr)
1033 return (position & HDSP_BufferID) ? (hdsp->period_bytes / 4) : 0;
1035 position &= HDSP_BufferPositionMask;
1037 position &= (hdsp->period_bytes/2) - 1;
1041 static void hdsp_reset_hw_pointer(struct hdsp *hdsp)
1043 hdsp_write (hdsp, HDSP_resetPointer, 0);
1044 if (hdsp->io_type == H9632 && hdsp->firmware_rev >= 152)
1045 /* HDSP_resetPointer = HDSP_freqReg, which is strange and
1046 * requires (?) to write again DDS value after a reset pointer
1047 * (at least, it works like this) */
1048 hdsp_write (hdsp, HDSP_freqReg, hdsp->dds_value);
1051 static void hdsp_start_audio(struct hdsp *s)
1053 s->control_register |= (HDSP_AudioInterruptEnable | HDSP_Start);
1054 hdsp_write(s, HDSP_controlRegister, s->control_register);
1057 static void hdsp_stop_audio(struct hdsp *s)
1059 s->control_register &= ~(HDSP_Start | HDSP_AudioInterruptEnable);
1060 hdsp_write(s, HDSP_controlRegister, s->control_register);
1063 static void hdsp_silence_playback(struct hdsp *hdsp)
1065 memset(hdsp->playback_buffer, 0, HDSP_DMA_AREA_BYTES);
1068 static int hdsp_set_interrupt_interval(struct hdsp *s, unsigned int frames)
1072 spin_lock_irq(&s->lock);
1081 s->control_register &= ~HDSP_LatencyMask;
1082 s->control_register |= hdsp_encode_latency(n);
1084 hdsp_write(s, HDSP_controlRegister, s->control_register);
1086 hdsp_compute_period_size(s);
1088 spin_unlock_irq(&s->lock);
1093 static void hdsp_set_dds_value(struct hdsp *hdsp, int rate)
1099 else if (rate >= 56000)
1103 n = div_u64(n, rate);
1104 /* n should be less than 2^32 for being written to FREQ register */
1105 snd_BUG_ON(n >> 32);
1106 /* HDSP_freqReg and HDSP_resetPointer are the same, so keep the DDS
1107 value to write it after a reset */
1108 hdsp->dds_value = n;
1109 hdsp_write(hdsp, HDSP_freqReg, hdsp->dds_value);
1112 static int hdsp_set_rate(struct hdsp *hdsp, int rate, int called_internally)
1114 int reject_if_open = 0;
1118 /* ASSUMPTION: hdsp->lock is either held, or
1119 there is no need for it (e.g. during module
1123 if (!(hdsp->control_register & HDSP_ClockModeMaster)) {
1124 if (called_internally) {
1125 /* request from ctl or card initialization */
1126 dev_err(hdsp->card->dev,
1127 "device is not running as a clock master: cannot set sample rate.\n");
1130 /* hw_param request while in AutoSync mode */
1131 int external_freq = hdsp_external_sample_rate(hdsp);
1132 int spdif_freq = hdsp_spdif_sample_rate(hdsp);
1134 if ((spdif_freq == external_freq*2) && (hdsp_autosync_ref(hdsp) >= HDSP_AUTOSYNC_FROM_ADAT1))
1135 dev_info(hdsp->card->dev,
1136 "Detected ADAT in double speed mode\n");
1137 else if (hdsp->io_type == H9632 && (spdif_freq == external_freq*4) && (hdsp_autosync_ref(hdsp) >= HDSP_AUTOSYNC_FROM_ADAT1))
1138 dev_info(hdsp->card->dev,
1139 "Detected ADAT in quad speed mode\n");
1140 else if (rate != external_freq) {
1141 dev_info(hdsp->card->dev,
1142 "No AutoSync source for requested rate\n");
1148 current_rate = hdsp->system_sample_rate;
1150 /* Changing from a "single speed" to a "double speed" rate is
1151 not allowed if any substreams are open. This is because
1152 such a change causes a shift in the location of
1153 the DMA buffers and a reduction in the number of available
1156 Note that a similar but essentially insoluble problem
1157 exists for externally-driven rate changes. All we can do
1158 is to flag rate changes in the read/write routines. */
1160 if (rate > 96000 && hdsp->io_type != H9632)
1165 if (current_rate > 48000)
1167 rate_bits = HDSP_Frequency32KHz;
1170 if (current_rate > 48000)
1172 rate_bits = HDSP_Frequency44_1KHz;
1175 if (current_rate > 48000)
1177 rate_bits = HDSP_Frequency48KHz;
1180 if (current_rate <= 48000 || current_rate > 96000)
1182 rate_bits = HDSP_Frequency64KHz;
1185 if (current_rate <= 48000 || current_rate > 96000)
1187 rate_bits = HDSP_Frequency88_2KHz;
1190 if (current_rate <= 48000 || current_rate > 96000)
1192 rate_bits = HDSP_Frequency96KHz;
1195 if (current_rate < 128000)
1197 rate_bits = HDSP_Frequency128KHz;
1200 if (current_rate < 128000)
1202 rate_bits = HDSP_Frequency176_4KHz;
1205 if (current_rate < 128000)
1207 rate_bits = HDSP_Frequency192KHz;
1213 if (reject_if_open && (hdsp->capture_pid >= 0 || hdsp->playback_pid >= 0)) {
1214 dev_warn(hdsp->card->dev,
1215 "cannot change speed mode (capture PID = %d, playback PID = %d)\n",
1217 hdsp->playback_pid);
1221 hdsp->control_register &= ~HDSP_FrequencyMask;
1222 hdsp->control_register |= rate_bits;
1223 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
1225 /* For HDSP9632 rev 152, need to set DDS value in FREQ register */
1226 if (hdsp->io_type == H9632 && hdsp->firmware_rev >= 152)
1227 hdsp_set_dds_value(hdsp, rate);
1229 if (rate >= 128000) {
1230 hdsp->channel_map = channel_map_H9632_qs;
1231 } else if (rate > 48000) {
1232 if (hdsp->io_type == H9632)
1233 hdsp->channel_map = channel_map_H9632_ds;
1235 hdsp->channel_map = channel_map_ds;
1237 switch (hdsp->io_type) {
1240 hdsp->channel_map = channel_map_mf_ss;
1244 hdsp->channel_map = channel_map_df_ss;
1247 hdsp->channel_map = channel_map_H9632_ss;
1250 /* should never happen */
1255 hdsp->system_sample_rate = rate;
1260 /*----------------------------------------------------------------------------
1262 ----------------------------------------------------------------------------*/
1264 static unsigned char snd_hdsp_midi_read_byte (struct hdsp *hdsp, int id)
1266 /* the hardware already does the relevant bit-mask with 0xff */
1268 return hdsp_read(hdsp, HDSP_midiDataIn1);
1270 return hdsp_read(hdsp, HDSP_midiDataIn0);
1273 static void snd_hdsp_midi_write_byte (struct hdsp *hdsp, int id, int val)
1275 /* the hardware already does the relevant bit-mask with 0xff */
1277 hdsp_write(hdsp, HDSP_midiDataOut1, val);
1279 hdsp_write(hdsp, HDSP_midiDataOut0, val);
1282 static int snd_hdsp_midi_input_available (struct hdsp *hdsp, int id)
1285 return (hdsp_read(hdsp, HDSP_midiStatusIn1) & 0xff);
1287 return (hdsp_read(hdsp, HDSP_midiStatusIn0) & 0xff);
1290 static int snd_hdsp_midi_output_possible (struct hdsp *hdsp, int id)
1292 int fifo_bytes_used;
1295 fifo_bytes_used = hdsp_read(hdsp, HDSP_midiStatusOut1) & 0xff;
1297 fifo_bytes_used = hdsp_read(hdsp, HDSP_midiStatusOut0) & 0xff;
1299 if (fifo_bytes_used < 128)
1300 return 128 - fifo_bytes_used;
1305 static void snd_hdsp_flush_midi_input (struct hdsp *hdsp, int id)
1307 while (snd_hdsp_midi_input_available (hdsp, id))
1308 snd_hdsp_midi_read_byte (hdsp, id);
1311 static int snd_hdsp_midi_output_write (struct hdsp_midi *hmidi)
1313 unsigned long flags;
1317 unsigned char buf[128];
1319 /* Output is not interrupt driven */
1321 spin_lock_irqsave (&hmidi->lock, flags);
1322 if (hmidi->output) {
1323 if (!snd_rawmidi_transmit_empty (hmidi->output)) {
1324 if ((n_pending = snd_hdsp_midi_output_possible (hmidi->hdsp, hmidi->id)) > 0) {
1325 if (n_pending > (int)sizeof (buf))
1326 n_pending = sizeof (buf);
1328 if ((to_write = snd_rawmidi_transmit (hmidi->output, buf, n_pending)) > 0) {
1329 for (i = 0; i < to_write; ++i)
1330 snd_hdsp_midi_write_byte (hmidi->hdsp, hmidi->id, buf[i]);
1335 spin_unlock_irqrestore (&hmidi->lock, flags);
1339 static int snd_hdsp_midi_input_read (struct hdsp_midi *hmidi)
1341 unsigned char buf[128]; /* this buffer is designed to match the MIDI input FIFO size */
1342 unsigned long flags;
1346 spin_lock_irqsave (&hmidi->lock, flags);
1347 if ((n_pending = snd_hdsp_midi_input_available (hmidi->hdsp, hmidi->id)) > 0) {
1349 if (n_pending > (int)sizeof (buf))
1350 n_pending = sizeof (buf);
1351 for (i = 0; i < n_pending; ++i)
1352 buf[i] = snd_hdsp_midi_read_byte (hmidi->hdsp, hmidi->id);
1354 snd_rawmidi_receive (hmidi->input, buf, n_pending);
1356 /* flush the MIDI input FIFO */
1358 snd_hdsp_midi_read_byte (hmidi->hdsp, hmidi->id);
1363 hmidi->hdsp->control_register |= HDSP_Midi1InterruptEnable;
1365 hmidi->hdsp->control_register |= HDSP_Midi0InterruptEnable;
1366 hdsp_write(hmidi->hdsp, HDSP_controlRegister, hmidi->hdsp->control_register);
1367 spin_unlock_irqrestore (&hmidi->lock, flags);
1368 return snd_hdsp_midi_output_write (hmidi);
1371 static void snd_hdsp_midi_input_trigger(struct snd_rawmidi_substream *substream, int up)
1374 struct hdsp_midi *hmidi;
1375 unsigned long flags;
1378 hmidi = (struct hdsp_midi *) substream->rmidi->private_data;
1380 ie = hmidi->id ? HDSP_Midi1InterruptEnable : HDSP_Midi0InterruptEnable;
1381 spin_lock_irqsave (&hdsp->lock, flags);
1383 if (!(hdsp->control_register & ie)) {
1384 snd_hdsp_flush_midi_input (hdsp, hmidi->id);
1385 hdsp->control_register |= ie;
1388 hdsp->control_register &= ~ie;
1391 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
1392 spin_unlock_irqrestore (&hdsp->lock, flags);
1395 static void snd_hdsp_midi_output_timer(struct timer_list *t)
1397 struct hdsp_midi *hmidi = from_timer(hmidi, t, timer);
1398 unsigned long flags;
1400 snd_hdsp_midi_output_write(hmidi);
1401 spin_lock_irqsave (&hmidi->lock, flags);
1403 /* this does not bump hmidi->istimer, because the
1404 kernel automatically removed the timer when it
1405 expired, and we are now adding it back, thus
1406 leaving istimer wherever it was set before.
1410 mod_timer(&hmidi->timer, 1 + jiffies);
1412 spin_unlock_irqrestore (&hmidi->lock, flags);
1415 static void snd_hdsp_midi_output_trigger(struct snd_rawmidi_substream *substream, int up)
1417 struct hdsp_midi *hmidi;
1418 unsigned long flags;
1420 hmidi = (struct hdsp_midi *) substream->rmidi->private_data;
1421 spin_lock_irqsave (&hmidi->lock, flags);
1423 if (!hmidi->istimer) {
1424 timer_setup(&hmidi->timer, snd_hdsp_midi_output_timer,
1426 mod_timer(&hmidi->timer, 1 + jiffies);
1430 if (hmidi->istimer && --hmidi->istimer <= 0)
1431 del_timer (&hmidi->timer);
1433 spin_unlock_irqrestore (&hmidi->lock, flags);
1435 snd_hdsp_midi_output_write(hmidi);
1438 static int snd_hdsp_midi_input_open(struct snd_rawmidi_substream *substream)
1440 struct hdsp_midi *hmidi;
1442 hmidi = (struct hdsp_midi *) substream->rmidi->private_data;
1443 spin_lock_irq (&hmidi->lock);
1444 snd_hdsp_flush_midi_input (hmidi->hdsp, hmidi->id);
1445 hmidi->input = substream;
1446 spin_unlock_irq (&hmidi->lock);
1451 static int snd_hdsp_midi_output_open(struct snd_rawmidi_substream *substream)
1453 struct hdsp_midi *hmidi;
1455 hmidi = (struct hdsp_midi *) substream->rmidi->private_data;
1456 spin_lock_irq (&hmidi->lock);
1457 hmidi->output = substream;
1458 spin_unlock_irq (&hmidi->lock);
1463 static int snd_hdsp_midi_input_close(struct snd_rawmidi_substream *substream)
1465 struct hdsp_midi *hmidi;
1467 snd_hdsp_midi_input_trigger (substream, 0);
1469 hmidi = (struct hdsp_midi *) substream->rmidi->private_data;
1470 spin_lock_irq (&hmidi->lock);
1471 hmidi->input = NULL;
1472 spin_unlock_irq (&hmidi->lock);
1477 static int snd_hdsp_midi_output_close(struct snd_rawmidi_substream *substream)
1479 struct hdsp_midi *hmidi;
1481 snd_hdsp_midi_output_trigger (substream, 0);
1483 hmidi = (struct hdsp_midi *) substream->rmidi->private_data;
1484 spin_lock_irq (&hmidi->lock);
1485 hmidi->output = NULL;
1486 spin_unlock_irq (&hmidi->lock);
1491 static const struct snd_rawmidi_ops snd_hdsp_midi_output =
1493 .open = snd_hdsp_midi_output_open,
1494 .close = snd_hdsp_midi_output_close,
1495 .trigger = snd_hdsp_midi_output_trigger,
1498 static const struct snd_rawmidi_ops snd_hdsp_midi_input =
1500 .open = snd_hdsp_midi_input_open,
1501 .close = snd_hdsp_midi_input_close,
1502 .trigger = snd_hdsp_midi_input_trigger,
1505 static int snd_hdsp_create_midi (struct snd_card *card, struct hdsp *hdsp, int id)
1509 hdsp->midi[id].id = id;
1510 hdsp->midi[id].rmidi = NULL;
1511 hdsp->midi[id].input = NULL;
1512 hdsp->midi[id].output = NULL;
1513 hdsp->midi[id].hdsp = hdsp;
1514 hdsp->midi[id].istimer = 0;
1515 hdsp->midi[id].pending = 0;
1516 spin_lock_init (&hdsp->midi[id].lock);
1518 snprintf(buf, sizeof(buf), "%s MIDI %d", card->shortname, id + 1);
1519 if (snd_rawmidi_new (card, buf, id, 1, 1, &hdsp->midi[id].rmidi) < 0)
1522 sprintf(hdsp->midi[id].rmidi->name, "HDSP MIDI %d", id+1);
1523 hdsp->midi[id].rmidi->private_data = &hdsp->midi[id];
1525 snd_rawmidi_set_ops (hdsp->midi[id].rmidi, SNDRV_RAWMIDI_STREAM_OUTPUT, &snd_hdsp_midi_output);
1526 snd_rawmidi_set_ops (hdsp->midi[id].rmidi, SNDRV_RAWMIDI_STREAM_INPUT, &snd_hdsp_midi_input);
1528 hdsp->midi[id].rmidi->info_flags |= SNDRV_RAWMIDI_INFO_OUTPUT |
1529 SNDRV_RAWMIDI_INFO_INPUT |
1530 SNDRV_RAWMIDI_INFO_DUPLEX;
1535 /*-----------------------------------------------------------------------------
1537 ----------------------------------------------------------------------------*/
1539 static u32 snd_hdsp_convert_from_aes(struct snd_aes_iec958 *aes)
1542 val |= (aes->status[0] & IEC958_AES0_PROFESSIONAL) ? HDSP_SPDIFProfessional : 0;
1543 val |= (aes->status[0] & IEC958_AES0_NONAUDIO) ? HDSP_SPDIFNonAudio : 0;
1544 if (val & HDSP_SPDIFProfessional)
1545 val |= (aes->status[0] & IEC958_AES0_PRO_EMPHASIS_5015) ? HDSP_SPDIFEmphasis : 0;
1547 val |= (aes->status[0] & IEC958_AES0_CON_EMPHASIS_5015) ? HDSP_SPDIFEmphasis : 0;
1551 static void snd_hdsp_convert_to_aes(struct snd_aes_iec958 *aes, u32 val)
1553 aes->status[0] = ((val & HDSP_SPDIFProfessional) ? IEC958_AES0_PROFESSIONAL : 0) |
1554 ((val & HDSP_SPDIFNonAudio) ? IEC958_AES0_NONAUDIO : 0);
1555 if (val & HDSP_SPDIFProfessional)
1556 aes->status[0] |= (val & HDSP_SPDIFEmphasis) ? IEC958_AES0_PRO_EMPHASIS_5015 : 0;
1558 aes->status[0] |= (val & HDSP_SPDIFEmphasis) ? IEC958_AES0_CON_EMPHASIS_5015 : 0;
1561 static int snd_hdsp_control_spdif_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
1563 uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
1568 static int snd_hdsp_control_spdif_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1570 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1572 snd_hdsp_convert_to_aes(&ucontrol->value.iec958, hdsp->creg_spdif);
1576 static int snd_hdsp_control_spdif_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1578 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1582 val = snd_hdsp_convert_from_aes(&ucontrol->value.iec958);
1583 spin_lock_irq(&hdsp->lock);
1584 change = val != hdsp->creg_spdif;
1585 hdsp->creg_spdif = val;
1586 spin_unlock_irq(&hdsp->lock);
1590 static int snd_hdsp_control_spdif_stream_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
1592 uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
1597 static int snd_hdsp_control_spdif_stream_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1599 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1601 snd_hdsp_convert_to_aes(&ucontrol->value.iec958, hdsp->creg_spdif_stream);
1605 static int snd_hdsp_control_spdif_stream_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1607 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1611 val = snd_hdsp_convert_from_aes(&ucontrol->value.iec958);
1612 spin_lock_irq(&hdsp->lock);
1613 change = val != hdsp->creg_spdif_stream;
1614 hdsp->creg_spdif_stream = val;
1615 hdsp->control_register &= ~(HDSP_SPDIFProfessional | HDSP_SPDIFNonAudio | HDSP_SPDIFEmphasis);
1616 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register |= val);
1617 spin_unlock_irq(&hdsp->lock);
1621 static int snd_hdsp_control_spdif_mask_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
1623 uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
1628 static int snd_hdsp_control_spdif_mask_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1630 ucontrol->value.iec958.status[0] = kcontrol->private_value;
1634 #define HDSP_SPDIF_IN(xname, xindex) \
1635 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1638 .info = snd_hdsp_info_spdif_in, \
1639 .get = snd_hdsp_get_spdif_in, \
1640 .put = snd_hdsp_put_spdif_in }
1642 static unsigned int hdsp_spdif_in(struct hdsp *hdsp)
1644 return hdsp_decode_spdif_in(hdsp->control_register & HDSP_SPDIFInputMask);
1647 static int hdsp_set_spdif_input(struct hdsp *hdsp, int in)
1649 hdsp->control_register &= ~HDSP_SPDIFInputMask;
1650 hdsp->control_register |= hdsp_encode_spdif_in(in);
1651 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
1655 static int snd_hdsp_info_spdif_in(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
1657 static const char * const texts[4] = {
1658 "Optical", "Coaxial", "Internal", "AES"
1660 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1662 return snd_ctl_enum_info(uinfo, 1, (hdsp->io_type == H9632) ? 4 : 3,
1666 static int snd_hdsp_get_spdif_in(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1668 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1670 ucontrol->value.enumerated.item[0] = hdsp_spdif_in(hdsp);
1674 static int snd_hdsp_put_spdif_in(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1676 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1680 if (!snd_hdsp_use_is_exclusive(hdsp))
1682 val = ucontrol->value.enumerated.item[0] % ((hdsp->io_type == H9632) ? 4 : 3);
1683 spin_lock_irq(&hdsp->lock);
1684 change = val != hdsp_spdif_in(hdsp);
1686 hdsp_set_spdif_input(hdsp, val);
1687 spin_unlock_irq(&hdsp->lock);
1691 #define HDSP_TOGGLE_SETTING(xname, xindex) \
1692 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1694 .private_value = xindex, \
1695 .info = snd_hdsp_info_toggle_setting, \
1696 .get = snd_hdsp_get_toggle_setting, \
1697 .put = snd_hdsp_put_toggle_setting \
1700 static int hdsp_toggle_setting(struct hdsp *hdsp, u32 regmask)
1702 return (hdsp->control_register & regmask) ? 1 : 0;
1705 static int hdsp_set_toggle_setting(struct hdsp *hdsp, u32 regmask, int out)
1708 hdsp->control_register |= regmask;
1710 hdsp->control_register &= ~regmask;
1711 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
1716 #define snd_hdsp_info_toggle_setting snd_ctl_boolean_mono_info
1718 static int snd_hdsp_get_toggle_setting(struct snd_kcontrol *kcontrol,
1719 struct snd_ctl_elem_value *ucontrol)
1721 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1722 u32 regmask = kcontrol->private_value;
1724 spin_lock_irq(&hdsp->lock);
1725 ucontrol->value.integer.value[0] = hdsp_toggle_setting(hdsp, regmask);
1726 spin_unlock_irq(&hdsp->lock);
1730 static int snd_hdsp_put_toggle_setting(struct snd_kcontrol *kcontrol,
1731 struct snd_ctl_elem_value *ucontrol)
1733 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1734 u32 regmask = kcontrol->private_value;
1738 if (!snd_hdsp_use_is_exclusive(hdsp))
1740 val = ucontrol->value.integer.value[0] & 1;
1741 spin_lock_irq(&hdsp->lock);
1742 change = (int) val != hdsp_toggle_setting(hdsp, regmask);
1744 hdsp_set_toggle_setting(hdsp, regmask, val);
1745 spin_unlock_irq(&hdsp->lock);
1749 #define HDSP_SPDIF_SAMPLE_RATE(xname, xindex) \
1750 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1753 .access = SNDRV_CTL_ELEM_ACCESS_READ, \
1754 .info = snd_hdsp_info_spdif_sample_rate, \
1755 .get = snd_hdsp_get_spdif_sample_rate \
1758 static int snd_hdsp_info_spdif_sample_rate(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
1760 static const char * const texts[] = {
1761 "32000", "44100", "48000", "64000", "88200", "96000",
1762 "None", "128000", "176400", "192000"
1764 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1766 return snd_ctl_enum_info(uinfo, 1, (hdsp->io_type == H9632) ? 10 : 7,
1770 static int snd_hdsp_get_spdif_sample_rate(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1772 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1774 switch (hdsp_spdif_sample_rate(hdsp)) {
1776 ucontrol->value.enumerated.item[0] = 0;
1779 ucontrol->value.enumerated.item[0] = 1;
1782 ucontrol->value.enumerated.item[0] = 2;
1785 ucontrol->value.enumerated.item[0] = 3;
1788 ucontrol->value.enumerated.item[0] = 4;
1791 ucontrol->value.enumerated.item[0] = 5;
1794 ucontrol->value.enumerated.item[0] = 7;
1797 ucontrol->value.enumerated.item[0] = 8;
1800 ucontrol->value.enumerated.item[0] = 9;
1803 ucontrol->value.enumerated.item[0] = 6;
1808 #define HDSP_SYSTEM_SAMPLE_RATE(xname, xindex) \
1809 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1812 .access = SNDRV_CTL_ELEM_ACCESS_READ, \
1813 .info = snd_hdsp_info_system_sample_rate, \
1814 .get = snd_hdsp_get_system_sample_rate \
1817 static int snd_hdsp_info_system_sample_rate(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
1819 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1824 static int snd_hdsp_get_system_sample_rate(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1826 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1828 ucontrol->value.enumerated.item[0] = hdsp->system_sample_rate;
1832 #define HDSP_AUTOSYNC_SAMPLE_RATE(xname, xindex) \
1833 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1836 .access = SNDRV_CTL_ELEM_ACCESS_READ, \
1837 .info = snd_hdsp_info_autosync_sample_rate, \
1838 .get = snd_hdsp_get_autosync_sample_rate \
1841 static int snd_hdsp_info_autosync_sample_rate(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
1843 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1844 static const char * const texts[] = {
1845 "32000", "44100", "48000", "64000", "88200", "96000",
1846 "None", "128000", "176400", "192000"
1849 return snd_ctl_enum_info(uinfo, 1, (hdsp->io_type == H9632) ? 10 : 7,
1853 static int snd_hdsp_get_autosync_sample_rate(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1855 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1857 switch (hdsp_external_sample_rate(hdsp)) {
1859 ucontrol->value.enumerated.item[0] = 0;
1862 ucontrol->value.enumerated.item[0] = 1;
1865 ucontrol->value.enumerated.item[0] = 2;
1868 ucontrol->value.enumerated.item[0] = 3;
1871 ucontrol->value.enumerated.item[0] = 4;
1874 ucontrol->value.enumerated.item[0] = 5;
1877 ucontrol->value.enumerated.item[0] = 7;
1880 ucontrol->value.enumerated.item[0] = 8;
1883 ucontrol->value.enumerated.item[0] = 9;
1886 ucontrol->value.enumerated.item[0] = 6;
1891 #define HDSP_SYSTEM_CLOCK_MODE(xname, xindex) \
1892 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1895 .access = SNDRV_CTL_ELEM_ACCESS_READ, \
1896 .info = snd_hdsp_info_system_clock_mode, \
1897 .get = snd_hdsp_get_system_clock_mode \
1900 static int hdsp_system_clock_mode(struct hdsp *hdsp)
1902 if (hdsp->control_register & HDSP_ClockModeMaster)
1904 else if (hdsp_external_sample_rate(hdsp) != hdsp->system_sample_rate)
1909 static int snd_hdsp_info_system_clock_mode(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
1911 static const char * const texts[] = {"Master", "Slave" };
1913 return snd_ctl_enum_info(uinfo, 1, 2, texts);
1916 static int snd_hdsp_get_system_clock_mode(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1918 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1920 ucontrol->value.enumerated.item[0] = hdsp_system_clock_mode(hdsp);
1924 #define HDSP_CLOCK_SOURCE(xname, xindex) \
1925 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1928 .info = snd_hdsp_info_clock_source, \
1929 .get = snd_hdsp_get_clock_source, \
1930 .put = snd_hdsp_put_clock_source \
1933 static int hdsp_clock_source(struct hdsp *hdsp)
1935 if (hdsp->control_register & HDSP_ClockModeMaster) {
1936 switch (hdsp->system_sample_rate) {
1963 static int hdsp_set_clock_source(struct hdsp *hdsp, int mode)
1967 case HDSP_CLOCK_SOURCE_AUTOSYNC:
1968 if (hdsp_external_sample_rate(hdsp) != 0) {
1969 if (!hdsp_set_rate(hdsp, hdsp_external_sample_rate(hdsp), 1)) {
1970 hdsp->control_register &= ~HDSP_ClockModeMaster;
1971 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
1976 case HDSP_CLOCK_SOURCE_INTERNAL_32KHZ:
1979 case HDSP_CLOCK_SOURCE_INTERNAL_44_1KHZ:
1982 case HDSP_CLOCK_SOURCE_INTERNAL_48KHZ:
1985 case HDSP_CLOCK_SOURCE_INTERNAL_64KHZ:
1988 case HDSP_CLOCK_SOURCE_INTERNAL_88_2KHZ:
1991 case HDSP_CLOCK_SOURCE_INTERNAL_96KHZ:
1994 case HDSP_CLOCK_SOURCE_INTERNAL_128KHZ:
1997 case HDSP_CLOCK_SOURCE_INTERNAL_176_4KHZ:
2000 case HDSP_CLOCK_SOURCE_INTERNAL_192KHZ:
2006 hdsp->control_register |= HDSP_ClockModeMaster;
2007 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
2008 hdsp_set_rate(hdsp, rate, 1);
2012 static int snd_hdsp_info_clock_source(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
2014 static const char * const texts[] = {
2015 "AutoSync", "Internal 32.0 kHz", "Internal 44.1 kHz",
2016 "Internal 48.0 kHz", "Internal 64.0 kHz", "Internal 88.2 kHz",
2017 "Internal 96.0 kHz", "Internal 128 kHz", "Internal 176.4 kHz",
2018 "Internal 192.0 KHz"
2020 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2022 return snd_ctl_enum_info(uinfo, 1, (hdsp->io_type == H9632) ? 10 : 7,
2026 static int snd_hdsp_get_clock_source(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2028 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2030 ucontrol->value.enumerated.item[0] = hdsp_clock_source(hdsp);
2034 static int snd_hdsp_put_clock_source(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2036 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2040 if (!snd_hdsp_use_is_exclusive(hdsp))
2042 val = ucontrol->value.enumerated.item[0];
2043 if (val < 0) val = 0;
2044 if (hdsp->io_type == H9632) {
2051 spin_lock_irq(&hdsp->lock);
2052 if (val != hdsp_clock_source(hdsp))
2053 change = (hdsp_set_clock_source(hdsp, val) == 0) ? 1 : 0;
2056 spin_unlock_irq(&hdsp->lock);
2060 #define snd_hdsp_info_clock_source_lock snd_ctl_boolean_mono_info
2062 static int snd_hdsp_get_clock_source_lock(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2064 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2066 ucontrol->value.integer.value[0] = hdsp->clock_source_locked;
2070 static int snd_hdsp_put_clock_source_lock(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2072 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2075 change = (int)ucontrol->value.integer.value[0] != hdsp->clock_source_locked;
2077 hdsp->clock_source_locked = !!ucontrol->value.integer.value[0];
2081 #define HDSP_DA_GAIN(xname, xindex) \
2082 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2085 .info = snd_hdsp_info_da_gain, \
2086 .get = snd_hdsp_get_da_gain, \
2087 .put = snd_hdsp_put_da_gain \
2090 static int hdsp_da_gain(struct hdsp *hdsp)
2092 switch (hdsp->control_register & HDSP_DAGainMask) {
2093 case HDSP_DAGainHighGain:
2095 case HDSP_DAGainPlus4dBu:
2097 case HDSP_DAGainMinus10dBV:
2104 static int hdsp_set_da_gain(struct hdsp *hdsp, int mode)
2106 hdsp->control_register &= ~HDSP_DAGainMask;
2109 hdsp->control_register |= HDSP_DAGainHighGain;
2112 hdsp->control_register |= HDSP_DAGainPlus4dBu;
2115 hdsp->control_register |= HDSP_DAGainMinus10dBV;
2121 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
2125 static int snd_hdsp_info_da_gain(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
2127 static const char * const texts[] = {"Hi Gain", "+4 dBu", "-10 dbV"};
2129 return snd_ctl_enum_info(uinfo, 1, 3, texts);
2132 static int snd_hdsp_get_da_gain(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2134 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2136 ucontrol->value.enumerated.item[0] = hdsp_da_gain(hdsp);
2140 static int snd_hdsp_put_da_gain(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2142 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2146 if (!snd_hdsp_use_is_exclusive(hdsp))
2148 val = ucontrol->value.enumerated.item[0];
2149 if (val < 0) val = 0;
2150 if (val > 2) val = 2;
2151 spin_lock_irq(&hdsp->lock);
2152 if (val != hdsp_da_gain(hdsp))
2153 change = (hdsp_set_da_gain(hdsp, val) == 0) ? 1 : 0;
2156 spin_unlock_irq(&hdsp->lock);
2160 #define HDSP_AD_GAIN(xname, xindex) \
2161 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2164 .info = snd_hdsp_info_ad_gain, \
2165 .get = snd_hdsp_get_ad_gain, \
2166 .put = snd_hdsp_put_ad_gain \
2169 static int hdsp_ad_gain(struct hdsp *hdsp)
2171 switch (hdsp->control_register & HDSP_ADGainMask) {
2172 case HDSP_ADGainMinus10dBV:
2174 case HDSP_ADGainPlus4dBu:
2176 case HDSP_ADGainLowGain:
2183 static int hdsp_set_ad_gain(struct hdsp *hdsp, int mode)
2185 hdsp->control_register &= ~HDSP_ADGainMask;
2188 hdsp->control_register |= HDSP_ADGainMinus10dBV;
2191 hdsp->control_register |= HDSP_ADGainPlus4dBu;
2194 hdsp->control_register |= HDSP_ADGainLowGain;
2200 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
2204 static int snd_hdsp_info_ad_gain(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
2206 static const char * const texts[] = {"-10 dBV", "+4 dBu", "Lo Gain"};
2208 return snd_ctl_enum_info(uinfo, 1, 3, texts);
2211 static int snd_hdsp_get_ad_gain(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2213 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2215 ucontrol->value.enumerated.item[0] = hdsp_ad_gain(hdsp);
2219 static int snd_hdsp_put_ad_gain(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2221 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2225 if (!snd_hdsp_use_is_exclusive(hdsp))
2227 val = ucontrol->value.enumerated.item[0];
2228 if (val < 0) val = 0;
2229 if (val > 2) val = 2;
2230 spin_lock_irq(&hdsp->lock);
2231 if (val != hdsp_ad_gain(hdsp))
2232 change = (hdsp_set_ad_gain(hdsp, val) == 0) ? 1 : 0;
2235 spin_unlock_irq(&hdsp->lock);
2239 #define HDSP_PHONE_GAIN(xname, xindex) \
2240 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2243 .info = snd_hdsp_info_phone_gain, \
2244 .get = snd_hdsp_get_phone_gain, \
2245 .put = snd_hdsp_put_phone_gain \
2248 static int hdsp_phone_gain(struct hdsp *hdsp)
2250 switch (hdsp->control_register & HDSP_PhoneGainMask) {
2251 case HDSP_PhoneGain0dB:
2253 case HDSP_PhoneGainMinus6dB:
2255 case HDSP_PhoneGainMinus12dB:
2262 static int hdsp_set_phone_gain(struct hdsp *hdsp, int mode)
2264 hdsp->control_register &= ~HDSP_PhoneGainMask;
2267 hdsp->control_register |= HDSP_PhoneGain0dB;
2270 hdsp->control_register |= HDSP_PhoneGainMinus6dB;
2273 hdsp->control_register |= HDSP_PhoneGainMinus12dB;
2279 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
2283 static int snd_hdsp_info_phone_gain(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
2285 static const char * const texts[] = {"0 dB", "-6 dB", "-12 dB"};
2287 return snd_ctl_enum_info(uinfo, 1, 3, texts);
2290 static int snd_hdsp_get_phone_gain(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2292 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2294 ucontrol->value.enumerated.item[0] = hdsp_phone_gain(hdsp);
2298 static int snd_hdsp_put_phone_gain(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2300 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2304 if (!snd_hdsp_use_is_exclusive(hdsp))
2306 val = ucontrol->value.enumerated.item[0];
2307 if (val < 0) val = 0;
2308 if (val > 2) val = 2;
2309 spin_lock_irq(&hdsp->lock);
2310 if (val != hdsp_phone_gain(hdsp))
2311 change = (hdsp_set_phone_gain(hdsp, val) == 0) ? 1 : 0;
2314 spin_unlock_irq(&hdsp->lock);
2318 #define HDSP_PREF_SYNC_REF(xname, xindex) \
2319 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2322 .info = snd_hdsp_info_pref_sync_ref, \
2323 .get = snd_hdsp_get_pref_sync_ref, \
2324 .put = snd_hdsp_put_pref_sync_ref \
2327 static int hdsp_pref_sync_ref(struct hdsp *hdsp)
2329 /* Notice that this looks at the requested sync source,
2330 not the one actually in use.
2333 switch (hdsp->control_register & HDSP_SyncRefMask) {
2334 case HDSP_SyncRef_ADAT1:
2335 return HDSP_SYNC_FROM_ADAT1;
2336 case HDSP_SyncRef_ADAT2:
2337 return HDSP_SYNC_FROM_ADAT2;
2338 case HDSP_SyncRef_ADAT3:
2339 return HDSP_SYNC_FROM_ADAT3;
2340 case HDSP_SyncRef_SPDIF:
2341 return HDSP_SYNC_FROM_SPDIF;
2342 case HDSP_SyncRef_WORD:
2343 return HDSP_SYNC_FROM_WORD;
2344 case HDSP_SyncRef_ADAT_SYNC:
2345 return HDSP_SYNC_FROM_ADAT_SYNC;
2347 return HDSP_SYNC_FROM_WORD;
2352 static int hdsp_set_pref_sync_ref(struct hdsp *hdsp, int pref)
2354 hdsp->control_register &= ~HDSP_SyncRefMask;
2356 case HDSP_SYNC_FROM_ADAT1:
2357 hdsp->control_register &= ~HDSP_SyncRefMask; /* clear SyncRef bits */
2359 case HDSP_SYNC_FROM_ADAT2:
2360 hdsp->control_register |= HDSP_SyncRef_ADAT2;
2362 case HDSP_SYNC_FROM_ADAT3:
2363 hdsp->control_register |= HDSP_SyncRef_ADAT3;
2365 case HDSP_SYNC_FROM_SPDIF:
2366 hdsp->control_register |= HDSP_SyncRef_SPDIF;
2368 case HDSP_SYNC_FROM_WORD:
2369 hdsp->control_register |= HDSP_SyncRef_WORD;
2371 case HDSP_SYNC_FROM_ADAT_SYNC:
2372 hdsp->control_register |= HDSP_SyncRef_ADAT_SYNC;
2377 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
2381 static int snd_hdsp_info_pref_sync_ref(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
2383 static const char * const texts[] = {
2384 "Word", "IEC958", "ADAT1", "ADAT Sync", "ADAT2", "ADAT3"
2386 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2389 switch (hdsp->io_type) {
2404 return snd_ctl_enum_info(uinfo, 1, num_items, texts);
2407 static int snd_hdsp_get_pref_sync_ref(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2409 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2411 ucontrol->value.enumerated.item[0] = hdsp_pref_sync_ref(hdsp);
2415 static int snd_hdsp_put_pref_sync_ref(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2417 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2421 if (!snd_hdsp_use_is_exclusive(hdsp))
2424 switch (hdsp->io_type) {
2439 val = ucontrol->value.enumerated.item[0] % max;
2440 spin_lock_irq(&hdsp->lock);
2441 change = (int)val != hdsp_pref_sync_ref(hdsp);
2442 hdsp_set_pref_sync_ref(hdsp, val);
2443 spin_unlock_irq(&hdsp->lock);
2447 #define HDSP_AUTOSYNC_REF(xname, xindex) \
2448 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2451 .access = SNDRV_CTL_ELEM_ACCESS_READ, \
2452 .info = snd_hdsp_info_autosync_ref, \
2453 .get = snd_hdsp_get_autosync_ref, \
2456 static int hdsp_autosync_ref(struct hdsp *hdsp)
2458 /* This looks at the autosync selected sync reference */
2459 unsigned int status2 = hdsp_read(hdsp, HDSP_status2Register);
2461 switch (status2 & HDSP_SelSyncRefMask) {
2462 case HDSP_SelSyncRef_WORD:
2463 return HDSP_AUTOSYNC_FROM_WORD;
2464 case HDSP_SelSyncRef_ADAT_SYNC:
2465 return HDSP_AUTOSYNC_FROM_ADAT_SYNC;
2466 case HDSP_SelSyncRef_SPDIF:
2467 return HDSP_AUTOSYNC_FROM_SPDIF;
2468 case HDSP_SelSyncRefMask:
2469 return HDSP_AUTOSYNC_FROM_NONE;
2470 case HDSP_SelSyncRef_ADAT1:
2471 return HDSP_AUTOSYNC_FROM_ADAT1;
2472 case HDSP_SelSyncRef_ADAT2:
2473 return HDSP_AUTOSYNC_FROM_ADAT2;
2474 case HDSP_SelSyncRef_ADAT3:
2475 return HDSP_AUTOSYNC_FROM_ADAT3;
2477 return HDSP_AUTOSYNC_FROM_WORD;
2482 static int snd_hdsp_info_autosync_ref(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
2484 static const char * const texts[] = {
2485 "Word", "ADAT Sync", "IEC958", "None", "ADAT1", "ADAT2", "ADAT3"
2488 return snd_ctl_enum_info(uinfo, 1, 7, texts);
2491 static int snd_hdsp_get_autosync_ref(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2493 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2495 ucontrol->value.enumerated.item[0] = hdsp_autosync_ref(hdsp);
2499 #define HDSP_PRECISE_POINTER(xname, xindex) \
2500 { .iface = SNDRV_CTL_ELEM_IFACE_CARD, \
2503 .info = snd_hdsp_info_precise_pointer, \
2504 .get = snd_hdsp_get_precise_pointer, \
2505 .put = snd_hdsp_put_precise_pointer \
2508 static int hdsp_set_precise_pointer(struct hdsp *hdsp, int precise)
2511 hdsp->precise_ptr = 1;
2513 hdsp->precise_ptr = 0;
2517 #define snd_hdsp_info_precise_pointer snd_ctl_boolean_mono_info
2519 static int snd_hdsp_get_precise_pointer(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2521 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2523 spin_lock_irq(&hdsp->lock);
2524 ucontrol->value.integer.value[0] = hdsp->precise_ptr;
2525 spin_unlock_irq(&hdsp->lock);
2529 static int snd_hdsp_put_precise_pointer(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2531 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2535 if (!snd_hdsp_use_is_exclusive(hdsp))
2537 val = ucontrol->value.integer.value[0] & 1;
2538 spin_lock_irq(&hdsp->lock);
2539 change = (int)val != hdsp->precise_ptr;
2540 hdsp_set_precise_pointer(hdsp, val);
2541 spin_unlock_irq(&hdsp->lock);
2545 #define HDSP_USE_MIDI_WORK(xname, xindex) \
2546 { .iface = SNDRV_CTL_ELEM_IFACE_CARD, \
2549 .info = snd_hdsp_info_use_midi_work, \
2550 .get = snd_hdsp_get_use_midi_work, \
2551 .put = snd_hdsp_put_use_midi_work \
2554 static int hdsp_set_use_midi_work(struct hdsp *hdsp, int use_work)
2557 hdsp->use_midi_work = 1;
2559 hdsp->use_midi_work = 0;
2563 #define snd_hdsp_info_use_midi_work snd_ctl_boolean_mono_info
2565 static int snd_hdsp_get_use_midi_work(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2567 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2569 spin_lock_irq(&hdsp->lock);
2570 ucontrol->value.integer.value[0] = hdsp->use_midi_work;
2571 spin_unlock_irq(&hdsp->lock);
2575 static int snd_hdsp_put_use_midi_work(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2577 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2581 if (!snd_hdsp_use_is_exclusive(hdsp))
2583 val = ucontrol->value.integer.value[0] & 1;
2584 spin_lock_irq(&hdsp->lock);
2585 change = (int)val != hdsp->use_midi_work;
2586 hdsp_set_use_midi_work(hdsp, val);
2587 spin_unlock_irq(&hdsp->lock);
2591 #define HDSP_MIXER(xname, xindex) \
2592 { .iface = SNDRV_CTL_ELEM_IFACE_HWDEP, \
2596 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | \
2597 SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
2598 .info = snd_hdsp_info_mixer, \
2599 .get = snd_hdsp_get_mixer, \
2600 .put = snd_hdsp_put_mixer \
2603 static int snd_hdsp_info_mixer(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
2605 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
2607 uinfo->value.integer.min = 0;
2608 uinfo->value.integer.max = 65536;
2609 uinfo->value.integer.step = 1;
2613 static int snd_hdsp_get_mixer(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2615 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2620 source = ucontrol->value.integer.value[0];
2621 destination = ucontrol->value.integer.value[1];
2623 if (source >= hdsp->max_channels)
2624 addr = hdsp_playback_to_output_key(hdsp,source-hdsp->max_channels,destination);
2626 addr = hdsp_input_to_output_key(hdsp,source, destination);
2628 spin_lock_irq(&hdsp->lock);
2629 ucontrol->value.integer.value[2] = hdsp_read_gain (hdsp, addr);
2630 spin_unlock_irq(&hdsp->lock);
2634 static int snd_hdsp_put_mixer(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2636 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2643 if (!snd_hdsp_use_is_exclusive(hdsp))
2646 source = ucontrol->value.integer.value[0];
2647 destination = ucontrol->value.integer.value[1];
2649 if (source >= hdsp->max_channels)
2650 addr = hdsp_playback_to_output_key(hdsp,source-hdsp->max_channels, destination);
2652 addr = hdsp_input_to_output_key(hdsp,source, destination);
2654 gain = ucontrol->value.integer.value[2];
2656 spin_lock_irq(&hdsp->lock);
2657 change = gain != hdsp_read_gain(hdsp, addr);
2659 hdsp_write_gain(hdsp, addr, gain);
2660 spin_unlock_irq(&hdsp->lock);
2664 #define HDSP_WC_SYNC_CHECK(xname, xindex) \
2665 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2668 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
2669 .info = snd_hdsp_info_sync_check, \
2670 .get = snd_hdsp_get_wc_sync_check \
2673 static int snd_hdsp_info_sync_check(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
2675 static const char * const texts[] = {"No Lock", "Lock", "Sync" };
2677 return snd_ctl_enum_info(uinfo, 1, 3, texts);
2680 static int hdsp_wc_sync_check(struct hdsp *hdsp)
2682 int status2 = hdsp_read(hdsp, HDSP_status2Register);
2683 if (status2 & HDSP_wc_lock) {
2684 if (status2 & HDSP_wc_sync)
2693 static int snd_hdsp_get_wc_sync_check(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2695 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2697 ucontrol->value.enumerated.item[0] = hdsp_wc_sync_check(hdsp);
2701 #define HDSP_SPDIF_SYNC_CHECK(xname, xindex) \
2702 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2705 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
2706 .info = snd_hdsp_info_sync_check, \
2707 .get = snd_hdsp_get_spdif_sync_check \
2710 static int hdsp_spdif_sync_check(struct hdsp *hdsp)
2712 int status = hdsp_read(hdsp, HDSP_statusRegister);
2713 if (status & HDSP_SPDIFErrorFlag)
2716 if (status & HDSP_SPDIFSync)
2724 static int snd_hdsp_get_spdif_sync_check(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2726 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2728 ucontrol->value.enumerated.item[0] = hdsp_spdif_sync_check(hdsp);
2732 #define HDSP_ADATSYNC_SYNC_CHECK(xname, xindex) \
2733 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2736 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
2737 .info = snd_hdsp_info_sync_check, \
2738 .get = snd_hdsp_get_adatsync_sync_check \
2741 static int hdsp_adatsync_sync_check(struct hdsp *hdsp)
2743 int status = hdsp_read(hdsp, HDSP_statusRegister);
2744 if (status & HDSP_TimecodeLock) {
2745 if (status & HDSP_TimecodeSync)
2753 static int snd_hdsp_get_adatsync_sync_check(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2755 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2757 ucontrol->value.enumerated.item[0] = hdsp_adatsync_sync_check(hdsp);
2761 #define HDSP_ADAT_SYNC_CHECK \
2762 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2763 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
2764 .info = snd_hdsp_info_sync_check, \
2765 .get = snd_hdsp_get_adat_sync_check \
2768 static int hdsp_adat_sync_check(struct hdsp *hdsp, int idx)
2770 int status = hdsp_read(hdsp, HDSP_statusRegister);
2772 if (status & (HDSP_Lock0>>idx)) {
2773 if (status & (HDSP_Sync0>>idx))
2781 static int snd_hdsp_get_adat_sync_check(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2784 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2786 offset = ucontrol->id.index - 1;
2787 if (snd_BUG_ON(offset < 0))
2790 switch (hdsp->io_type) {
2805 ucontrol->value.enumerated.item[0] = hdsp_adat_sync_check(hdsp, offset);
2809 #define HDSP_DDS_OFFSET(xname, xindex) \
2810 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2813 .info = snd_hdsp_info_dds_offset, \
2814 .get = snd_hdsp_get_dds_offset, \
2815 .put = snd_hdsp_put_dds_offset \
2818 static int hdsp_dds_offset(struct hdsp *hdsp)
2821 unsigned int dds_value = hdsp->dds_value;
2822 int system_sample_rate = hdsp->system_sample_rate;
2829 * dds_value = n / rate
2830 * rate = n / dds_value
2832 n = div_u64(n, dds_value);
2833 if (system_sample_rate >= 112000)
2835 else if (system_sample_rate >= 56000)
2837 return ((int)n) - system_sample_rate;
2840 static int hdsp_set_dds_offset(struct hdsp *hdsp, int offset_hz)
2842 int rate = hdsp->system_sample_rate + offset_hz;
2843 hdsp_set_dds_value(hdsp, rate);
2847 static int snd_hdsp_info_dds_offset(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
2849 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
2851 uinfo->value.integer.min = -5000;
2852 uinfo->value.integer.max = 5000;
2856 static int snd_hdsp_get_dds_offset(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2858 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2860 ucontrol->value.integer.value[0] = hdsp_dds_offset(hdsp);
2864 static int snd_hdsp_put_dds_offset(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2866 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2870 if (!snd_hdsp_use_is_exclusive(hdsp))
2872 val = ucontrol->value.integer.value[0];
2873 spin_lock_irq(&hdsp->lock);
2874 if (val != hdsp_dds_offset(hdsp))
2875 change = (hdsp_set_dds_offset(hdsp, val) == 0) ? 1 : 0;
2878 spin_unlock_irq(&hdsp->lock);
2882 static const struct snd_kcontrol_new snd_hdsp_9632_controls[] = {
2883 HDSP_DA_GAIN("DA Gain", 0),
2884 HDSP_AD_GAIN("AD Gain", 0),
2885 HDSP_PHONE_GAIN("Phones Gain", 0),
2886 HDSP_TOGGLE_SETTING("XLR Breakout Cable", HDSP_XLRBreakoutCable),
2887 HDSP_DDS_OFFSET("DDS Sample Rate Offset", 0)
2890 static const struct snd_kcontrol_new snd_hdsp_controls[] = {
2892 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
2893 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,DEFAULT),
2894 .info = snd_hdsp_control_spdif_info,
2895 .get = snd_hdsp_control_spdif_get,
2896 .put = snd_hdsp_control_spdif_put,
2899 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_INACTIVE,
2900 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
2901 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,PCM_STREAM),
2902 .info = snd_hdsp_control_spdif_stream_info,
2903 .get = snd_hdsp_control_spdif_stream_get,
2904 .put = snd_hdsp_control_spdif_stream_put,
2907 .access = SNDRV_CTL_ELEM_ACCESS_READ,
2908 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
2909 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,CON_MASK),
2910 .info = snd_hdsp_control_spdif_mask_info,
2911 .get = snd_hdsp_control_spdif_mask_get,
2912 .private_value = IEC958_AES0_NONAUDIO |
2913 IEC958_AES0_PROFESSIONAL |
2914 IEC958_AES0_CON_EMPHASIS,
2917 .access = SNDRV_CTL_ELEM_ACCESS_READ,
2918 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
2919 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,PRO_MASK),
2920 .info = snd_hdsp_control_spdif_mask_info,
2921 .get = snd_hdsp_control_spdif_mask_get,
2922 .private_value = IEC958_AES0_NONAUDIO |
2923 IEC958_AES0_PROFESSIONAL |
2924 IEC958_AES0_PRO_EMPHASIS,
2926 HDSP_MIXER("Mixer", 0),
2927 HDSP_SPDIF_IN("IEC958 Input Connector", 0),
2928 HDSP_TOGGLE_SETTING("IEC958 Output also on ADAT1", HDSP_SPDIFOpticalOut),
2929 HDSP_TOGGLE_SETTING("IEC958 Professional Bit", HDSP_SPDIFProfessional),
2930 HDSP_TOGGLE_SETTING("IEC958 Emphasis Bit", HDSP_SPDIFEmphasis),
2931 HDSP_TOGGLE_SETTING("IEC958 Non-audio Bit", HDSP_SPDIFNonAudio),
2932 /* 'Sample Clock Source' complies with the alsa control naming scheme */
2933 HDSP_CLOCK_SOURCE("Sample Clock Source", 0),
2935 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2936 .name = "Sample Clock Source Locking",
2937 .info = snd_hdsp_info_clock_source_lock,
2938 .get = snd_hdsp_get_clock_source_lock,
2939 .put = snd_hdsp_put_clock_source_lock,
2941 HDSP_SYSTEM_CLOCK_MODE("System Clock Mode", 0),
2942 HDSP_PREF_SYNC_REF("Preferred Sync Reference", 0),
2943 HDSP_AUTOSYNC_REF("AutoSync Reference", 0),
2944 HDSP_SPDIF_SAMPLE_RATE("SPDIF Sample Rate", 0),
2945 HDSP_SYSTEM_SAMPLE_RATE("System Sample Rate", 0),
2946 /* 'External Rate' complies with the alsa control naming scheme */
2947 HDSP_AUTOSYNC_SAMPLE_RATE("External Rate", 0),
2948 HDSP_WC_SYNC_CHECK("Word Clock Lock Status", 0),
2949 HDSP_SPDIF_SYNC_CHECK("SPDIF Lock Status", 0),
2950 HDSP_ADATSYNC_SYNC_CHECK("ADAT Sync Lock Status", 0),
2951 HDSP_TOGGLE_SETTING("Line Out", HDSP_LineOut),
2952 HDSP_PRECISE_POINTER("Precise Pointer", 0),
2953 HDSP_USE_MIDI_WORK("Use Midi Tasklet", 0),
2957 static int hdsp_rpm_input12(struct hdsp *hdsp)
2959 switch (hdsp->control_register & HDSP_RPM_Inp12) {
2960 case HDSP_RPM_Inp12_Phon_6dB:
2962 case HDSP_RPM_Inp12_Phon_n6dB:
2964 case HDSP_RPM_Inp12_Line_0dB:
2966 case HDSP_RPM_Inp12_Line_n6dB:
2973 static int snd_hdsp_get_rpm_input12(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_rpm_input12(hdsp);
2982 static int hdsp_set_rpm_input12(struct hdsp *hdsp, int mode)
2984 hdsp->control_register &= ~HDSP_RPM_Inp12;
2987 hdsp->control_register |= HDSP_RPM_Inp12_Phon_6dB;
2992 hdsp->control_register |= HDSP_RPM_Inp12_Phon_n6dB;
2995 hdsp->control_register |= HDSP_RPM_Inp12_Line_0dB;
2998 hdsp->control_register |= HDSP_RPM_Inp12_Line_n6dB;
3004 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
3009 static int snd_hdsp_put_rpm_input12(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
3011 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
3015 if (!snd_hdsp_use_is_exclusive(hdsp))
3017 val = ucontrol->value.enumerated.item[0];
3022 spin_lock_irq(&hdsp->lock);
3023 if (val != hdsp_rpm_input12(hdsp))
3024 change = (hdsp_set_rpm_input12(hdsp, val) == 0) ? 1 : 0;
3027 spin_unlock_irq(&hdsp->lock);
3032 static int snd_hdsp_info_rpm_input(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
3034 static const char * const texts[] = {
3035 "Phono +6dB", "Phono 0dB", "Phono -6dB", "Line 0dB", "Line -6dB"
3038 return snd_ctl_enum_info(uinfo, 1, 5, texts);
3042 static int hdsp_rpm_input34(struct hdsp *hdsp)
3044 switch (hdsp->control_register & HDSP_RPM_Inp34) {
3045 case HDSP_RPM_Inp34_Phon_6dB:
3047 case HDSP_RPM_Inp34_Phon_n6dB:
3049 case HDSP_RPM_Inp34_Line_0dB:
3051 case HDSP_RPM_Inp34_Line_n6dB:
3058 static int snd_hdsp_get_rpm_input34(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
3060 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
3062 ucontrol->value.enumerated.item[0] = hdsp_rpm_input34(hdsp);
3067 static int hdsp_set_rpm_input34(struct hdsp *hdsp, int mode)
3069 hdsp->control_register &= ~HDSP_RPM_Inp34;
3072 hdsp->control_register |= HDSP_RPM_Inp34_Phon_6dB;
3077 hdsp->control_register |= HDSP_RPM_Inp34_Phon_n6dB;
3080 hdsp->control_register |= HDSP_RPM_Inp34_Line_0dB;
3083 hdsp->control_register |= HDSP_RPM_Inp34_Line_n6dB;
3089 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
3094 static int snd_hdsp_put_rpm_input34(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
3096 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
3100 if (!snd_hdsp_use_is_exclusive(hdsp))
3102 val = ucontrol->value.enumerated.item[0];
3107 spin_lock_irq(&hdsp->lock);
3108 if (val != hdsp_rpm_input34(hdsp))
3109 change = (hdsp_set_rpm_input34(hdsp, val) == 0) ? 1 : 0;
3112 spin_unlock_irq(&hdsp->lock);
3117 /* RPM Bypass switch */
3118 static int hdsp_rpm_bypass(struct hdsp *hdsp)
3120 return (hdsp->control_register & HDSP_RPM_Bypass) ? 1 : 0;
3124 static int snd_hdsp_get_rpm_bypass(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
3126 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
3128 ucontrol->value.integer.value[0] = hdsp_rpm_bypass(hdsp);
3133 static int hdsp_set_rpm_bypass(struct hdsp *hdsp, int on)
3136 hdsp->control_register |= HDSP_RPM_Bypass;
3138 hdsp->control_register &= ~HDSP_RPM_Bypass;
3139 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
3144 static int snd_hdsp_put_rpm_bypass(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
3146 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
3150 if (!snd_hdsp_use_is_exclusive(hdsp))
3152 val = ucontrol->value.integer.value[0] & 1;
3153 spin_lock_irq(&hdsp->lock);
3154 change = (int)val != hdsp_rpm_bypass(hdsp);
3155 hdsp_set_rpm_bypass(hdsp, val);
3156 spin_unlock_irq(&hdsp->lock);
3161 static int snd_hdsp_info_rpm_bypass(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
3163 static const char * const texts[] = {"On", "Off"};
3165 return snd_ctl_enum_info(uinfo, 1, 2, texts);
3169 /* RPM Disconnect switch */
3170 static int hdsp_rpm_disconnect(struct hdsp *hdsp)
3172 return (hdsp->control_register & HDSP_RPM_Disconnect) ? 1 : 0;
3176 static int snd_hdsp_get_rpm_disconnect(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
3178 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
3180 ucontrol->value.integer.value[0] = hdsp_rpm_disconnect(hdsp);
3185 static int hdsp_set_rpm_disconnect(struct hdsp *hdsp, int on)
3188 hdsp->control_register |= HDSP_RPM_Disconnect;
3190 hdsp->control_register &= ~HDSP_RPM_Disconnect;
3191 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
3196 static int snd_hdsp_put_rpm_disconnect(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
3198 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
3202 if (!snd_hdsp_use_is_exclusive(hdsp))
3204 val = ucontrol->value.integer.value[0] & 1;
3205 spin_lock_irq(&hdsp->lock);
3206 change = (int)val != hdsp_rpm_disconnect(hdsp);
3207 hdsp_set_rpm_disconnect(hdsp, val);
3208 spin_unlock_irq(&hdsp->lock);
3212 static int snd_hdsp_info_rpm_disconnect(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
3214 static const char * const texts[] = {"On", "Off"};
3216 return snd_ctl_enum_info(uinfo, 1, 2, texts);
3219 static const struct snd_kcontrol_new snd_hdsp_rpm_controls[] = {
3221 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3222 .name = "RPM Bypass",
3223 .get = snd_hdsp_get_rpm_bypass,
3224 .put = snd_hdsp_put_rpm_bypass,
3225 .info = snd_hdsp_info_rpm_bypass
3228 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3229 .name = "RPM Disconnect",
3230 .get = snd_hdsp_get_rpm_disconnect,
3231 .put = snd_hdsp_put_rpm_disconnect,
3232 .info = snd_hdsp_info_rpm_disconnect
3235 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3236 .name = "Input 1/2",
3237 .get = snd_hdsp_get_rpm_input12,
3238 .put = snd_hdsp_put_rpm_input12,
3239 .info = snd_hdsp_info_rpm_input
3242 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3243 .name = "Input 3/4",
3244 .get = snd_hdsp_get_rpm_input34,
3245 .put = snd_hdsp_put_rpm_input34,
3246 .info = snd_hdsp_info_rpm_input
3248 HDSP_SYSTEM_SAMPLE_RATE("System Sample Rate", 0),
3249 HDSP_MIXER("Mixer", 0)
3252 static const struct snd_kcontrol_new snd_hdsp_96xx_aeb =
3253 HDSP_TOGGLE_SETTING("Analog Extension Board",
3254 HDSP_AnalogExtensionBoard);
3255 static struct snd_kcontrol_new snd_hdsp_adat_sync_check = HDSP_ADAT_SYNC_CHECK;
3258 static bool hdsp_loopback_get(struct hdsp *const hdsp, const u8 channel)
3260 return hdsp->io_loopback & (1 << channel);
3263 static int hdsp_loopback_set(struct hdsp *const hdsp, const u8 channel, const bool enable)
3265 if (hdsp_loopback_get(hdsp, channel) == enable)
3268 hdsp->io_loopback ^= (1 << channel);
3270 hdsp_write(hdsp, HDSP_inputEnable + (4 * (hdsp->max_channels + channel)), enable);
3275 static int snd_hdsp_loopback_get(struct snd_kcontrol *const kcontrol,
3276 struct snd_ctl_elem_value *const ucontrol)
3278 struct hdsp *const hdsp = snd_kcontrol_chip(kcontrol);
3279 const u8 channel = snd_ctl_get_ioff(kcontrol, &ucontrol->id);
3281 if (channel >= hdsp->max_channels)
3284 ucontrol->value.integer.value[0] = hdsp_loopback_get(hdsp, channel);
3289 static int snd_hdsp_loopback_put(struct snd_kcontrol *const kcontrol,
3290 struct snd_ctl_elem_value *const ucontrol)
3292 struct hdsp *const hdsp = snd_kcontrol_chip(kcontrol);
3293 const u8 channel = snd_ctl_get_ioff(kcontrol, &ucontrol->id);
3294 const bool enable = ucontrol->value.integer.value[0] & 1;
3296 if (channel >= hdsp->max_channels)
3299 return hdsp_loopback_set(hdsp, channel, enable);
3302 static struct snd_kcontrol_new snd_hdsp_loopback_control = {
3303 .iface = SNDRV_CTL_ELEM_IFACE_HWDEP,
3304 .name = "Output Loopback",
3305 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
3306 .info = snd_ctl_boolean_mono_info,
3307 .get = snd_hdsp_loopback_get,
3308 .put = snd_hdsp_loopback_put
3311 static int snd_hdsp_create_controls(struct snd_card *card, struct hdsp *hdsp)
3315 struct snd_kcontrol *kctl;
3317 if (hdsp->io_type == RPM) {
3318 /* RPM Bypass, Disconnect and Input switches */
3319 for (idx = 0; idx < ARRAY_SIZE(snd_hdsp_rpm_controls); idx++) {
3320 err = snd_ctl_add(card, kctl = snd_ctl_new1(&snd_hdsp_rpm_controls[idx], hdsp));
3327 for (idx = 0; idx < ARRAY_SIZE(snd_hdsp_controls); idx++) {
3328 if ((err = snd_ctl_add(card, kctl = snd_ctl_new1(&snd_hdsp_controls[idx], hdsp))) < 0)
3330 if (idx == 1) /* IEC958 (S/PDIF) Stream */
3331 hdsp->spdif_ctl = kctl;
3334 /* ADAT SyncCheck status */
3335 snd_hdsp_adat_sync_check.name = "ADAT Lock Status";
3336 snd_hdsp_adat_sync_check.index = 1;
3337 if ((err = snd_ctl_add (card, kctl = snd_ctl_new1(&snd_hdsp_adat_sync_check, hdsp))))
3339 if (hdsp->io_type == Digiface || hdsp->io_type == H9652) {
3340 for (idx = 1; idx < 3; ++idx) {
3341 snd_hdsp_adat_sync_check.index = idx+1;
3342 if ((err = snd_ctl_add (card, kctl = snd_ctl_new1(&snd_hdsp_adat_sync_check, hdsp))))
3347 /* DA, AD and Phone gain and XLR breakout cable controls for H9632 cards */
3348 if (hdsp->io_type == H9632) {
3349 for (idx = 0; idx < ARRAY_SIZE(snd_hdsp_9632_controls); idx++) {
3350 if ((err = snd_ctl_add(card, kctl = snd_ctl_new1(&snd_hdsp_9632_controls[idx], hdsp))) < 0)
3355 /* Output loopback controls for H9632 cards */
3356 if (hdsp->io_type == H9632) {
3357 snd_hdsp_loopback_control.count = hdsp->max_channels;
3358 kctl = snd_ctl_new1(&snd_hdsp_loopback_control, hdsp);
3361 err = snd_ctl_add(card, kctl);
3366 /* AEB control for H96xx card */
3367 if (hdsp->io_type == H9632 || hdsp->io_type == H9652) {
3368 if ((err = snd_ctl_add(card, kctl = snd_ctl_new1(&snd_hdsp_96xx_aeb, hdsp))) < 0)
3375 /*------------------------------------------------------------
3377 ------------------------------------------------------------*/
3380 snd_hdsp_proc_read(struct snd_info_entry *entry, struct snd_info_buffer *buffer)
3382 struct hdsp *hdsp = entry->private_data;
3383 unsigned int status;
3384 unsigned int status2;
3385 char *pref_sync_ref;
3387 char *system_clock_mode;
3391 status = hdsp_read(hdsp, HDSP_statusRegister);
3392 status2 = hdsp_read(hdsp, HDSP_status2Register);
3394 snd_iprintf(buffer, "%s (Card #%d)\n", hdsp->card_name,
3395 hdsp->card->number + 1);
3396 snd_iprintf(buffer, "Buffers: capture %p playback %p\n",
3397 hdsp->capture_buffer, hdsp->playback_buffer);
3398 snd_iprintf(buffer, "IRQ: %d Registers bus: 0x%lx VM: 0x%lx\n",
3399 hdsp->irq, hdsp->port, (unsigned long)hdsp->iobase);
3400 snd_iprintf(buffer, "Control register: 0x%x\n", hdsp->control_register);
3401 snd_iprintf(buffer, "Control2 register: 0x%x\n",
3402 hdsp->control2_register);
3403 snd_iprintf(buffer, "Status register: 0x%x\n", status);
3404 snd_iprintf(buffer, "Status2 register: 0x%x\n", status2);
3406 if (hdsp_check_for_iobox(hdsp)) {
3407 snd_iprintf(buffer, "No I/O box connected.\n"
3408 "Please connect one and upload firmware.\n");
3412 if (hdsp_check_for_firmware(hdsp, 0)) {
3413 if (hdsp->state & HDSP_FirmwareCached) {
3414 if (snd_hdsp_load_firmware_from_cache(hdsp) != 0) {
3415 snd_iprintf(buffer, "Firmware loading from "
3417 "please upload manually.\n");
3423 err = hdsp_request_fw_loader(hdsp);
3426 "No firmware loaded nor cached, "
3427 "please upload firmware.\n");
3433 snd_iprintf(buffer, "FIFO status: %d\n", hdsp_read(hdsp, HDSP_fifoStatus) & 0xff);
3434 snd_iprintf(buffer, "MIDI1 Output status: 0x%x\n", hdsp_read(hdsp, HDSP_midiStatusOut0));
3435 snd_iprintf(buffer, "MIDI1 Input status: 0x%x\n", hdsp_read(hdsp, HDSP_midiStatusIn0));
3436 snd_iprintf(buffer, "MIDI2 Output status: 0x%x\n", hdsp_read(hdsp, HDSP_midiStatusOut1));
3437 snd_iprintf(buffer, "MIDI2 Input status: 0x%x\n", hdsp_read(hdsp, HDSP_midiStatusIn1));
3438 snd_iprintf(buffer, "Use Midi Tasklet: %s\n", hdsp->use_midi_work ? "on" : "off");
3440 snd_iprintf(buffer, "\n");
3442 x = 1 << (6 + hdsp_decode_latency(hdsp->control_register & HDSP_LatencyMask));
3444 snd_iprintf(buffer, "Buffer Size (Latency): %d samples (2 periods of %lu bytes)\n", x, (unsigned long) hdsp->period_bytes);
3445 snd_iprintf(buffer, "Hardware pointer (frames): %ld\n", hdsp_hw_pointer(hdsp));
3446 snd_iprintf(buffer, "Precise pointer: %s\n", hdsp->precise_ptr ? "on" : "off");
3447 snd_iprintf(buffer, "Line out: %s\n", (hdsp->control_register & HDSP_LineOut) ? "on" : "off");
3449 snd_iprintf(buffer, "Firmware version: %d\n", (status2&HDSP_version0)|(status2&HDSP_version1)<<1|(status2&HDSP_version2)<<2);
3451 snd_iprintf(buffer, "\n");
3453 switch (hdsp_clock_source(hdsp)) {
3454 case HDSP_CLOCK_SOURCE_AUTOSYNC:
3455 clock_source = "AutoSync";
3457 case HDSP_CLOCK_SOURCE_INTERNAL_32KHZ:
3458 clock_source = "Internal 32 kHz";
3460 case HDSP_CLOCK_SOURCE_INTERNAL_44_1KHZ:
3461 clock_source = "Internal 44.1 kHz";
3463 case HDSP_CLOCK_SOURCE_INTERNAL_48KHZ:
3464 clock_source = "Internal 48 kHz";
3466 case HDSP_CLOCK_SOURCE_INTERNAL_64KHZ:
3467 clock_source = "Internal 64 kHz";
3469 case HDSP_CLOCK_SOURCE_INTERNAL_88_2KHZ:
3470 clock_source = "Internal 88.2 kHz";
3472 case HDSP_CLOCK_SOURCE_INTERNAL_96KHZ:
3473 clock_source = "Internal 96 kHz";
3475 case HDSP_CLOCK_SOURCE_INTERNAL_128KHZ:
3476 clock_source = "Internal 128 kHz";
3478 case HDSP_CLOCK_SOURCE_INTERNAL_176_4KHZ:
3479 clock_source = "Internal 176.4 kHz";
3481 case HDSP_CLOCK_SOURCE_INTERNAL_192KHZ:
3482 clock_source = "Internal 192 kHz";
3485 clock_source = "Error";
3487 snd_iprintf (buffer, "Sample Clock Source: %s\n", clock_source);
3489 if (hdsp_system_clock_mode(hdsp))
3490 system_clock_mode = "Slave";
3492 system_clock_mode = "Master";
3494 switch (hdsp_pref_sync_ref (hdsp)) {
3495 case HDSP_SYNC_FROM_WORD:
3496 pref_sync_ref = "Word Clock";
3498 case HDSP_SYNC_FROM_ADAT_SYNC:
3499 pref_sync_ref = "ADAT Sync";
3501 case HDSP_SYNC_FROM_SPDIF:
3502 pref_sync_ref = "SPDIF";
3504 case HDSP_SYNC_FROM_ADAT1:
3505 pref_sync_ref = "ADAT1";
3507 case HDSP_SYNC_FROM_ADAT2:
3508 pref_sync_ref = "ADAT2";
3510 case HDSP_SYNC_FROM_ADAT3:
3511 pref_sync_ref = "ADAT3";
3514 pref_sync_ref = "Word Clock";
3517 snd_iprintf (buffer, "Preferred Sync Reference: %s\n", pref_sync_ref);
3519 switch (hdsp_autosync_ref (hdsp)) {
3520 case HDSP_AUTOSYNC_FROM_WORD:
3521 autosync_ref = "Word Clock";
3523 case HDSP_AUTOSYNC_FROM_ADAT_SYNC:
3524 autosync_ref = "ADAT Sync";
3526 case HDSP_AUTOSYNC_FROM_SPDIF:
3527 autosync_ref = "SPDIF";
3529 case HDSP_AUTOSYNC_FROM_NONE:
3530 autosync_ref = "None";
3532 case HDSP_AUTOSYNC_FROM_ADAT1:
3533 autosync_ref = "ADAT1";
3535 case HDSP_AUTOSYNC_FROM_ADAT2:
3536 autosync_ref = "ADAT2";
3538 case HDSP_AUTOSYNC_FROM_ADAT3:
3539 autosync_ref = "ADAT3";
3542 autosync_ref = "---";
3545 snd_iprintf (buffer, "AutoSync Reference: %s\n", autosync_ref);
3547 snd_iprintf (buffer, "AutoSync Frequency: %d\n", hdsp_external_sample_rate(hdsp));
3549 snd_iprintf (buffer, "System Clock Mode: %s\n", system_clock_mode);
3551 snd_iprintf (buffer, "System Clock Frequency: %d\n", hdsp->system_sample_rate);
3552 snd_iprintf (buffer, "System Clock Locked: %s\n", hdsp->clock_source_locked ? "Yes" : "No");
3554 snd_iprintf(buffer, "\n");
3556 if (hdsp->io_type != RPM) {
3557 switch (hdsp_spdif_in(hdsp)) {
3558 case HDSP_SPDIFIN_OPTICAL:
3559 snd_iprintf(buffer, "IEC958 input: Optical\n");
3561 case HDSP_SPDIFIN_COAXIAL:
3562 snd_iprintf(buffer, "IEC958 input: Coaxial\n");
3564 case HDSP_SPDIFIN_INTERNAL:
3565 snd_iprintf(buffer, "IEC958 input: Internal\n");
3567 case HDSP_SPDIFIN_AES:
3568 snd_iprintf(buffer, "IEC958 input: AES\n");
3571 snd_iprintf(buffer, "IEC958 input: ???\n");
3576 if (RPM == hdsp->io_type) {
3577 if (hdsp->control_register & HDSP_RPM_Bypass)
3578 snd_iprintf(buffer, "RPM Bypass: disabled\n");
3580 snd_iprintf(buffer, "RPM Bypass: enabled\n");
3581 if (hdsp->control_register & HDSP_RPM_Disconnect)
3582 snd_iprintf(buffer, "RPM disconnected\n");
3584 snd_iprintf(buffer, "RPM connected\n");
3586 switch (hdsp->control_register & HDSP_RPM_Inp12) {
3587 case HDSP_RPM_Inp12_Phon_6dB:
3588 snd_iprintf(buffer, "Input 1/2: Phono, 6dB\n");
3590 case HDSP_RPM_Inp12_Phon_0dB:
3591 snd_iprintf(buffer, "Input 1/2: Phono, 0dB\n");
3593 case HDSP_RPM_Inp12_Phon_n6dB:
3594 snd_iprintf(buffer, "Input 1/2: Phono, -6dB\n");
3596 case HDSP_RPM_Inp12_Line_0dB:
3597 snd_iprintf(buffer, "Input 1/2: Line, 0dB\n");
3599 case HDSP_RPM_Inp12_Line_n6dB:
3600 snd_iprintf(buffer, "Input 1/2: Line, -6dB\n");
3603 snd_iprintf(buffer, "Input 1/2: ???\n");
3606 switch (hdsp->control_register & HDSP_RPM_Inp34) {
3607 case HDSP_RPM_Inp34_Phon_6dB:
3608 snd_iprintf(buffer, "Input 3/4: Phono, 6dB\n");
3610 case HDSP_RPM_Inp34_Phon_0dB:
3611 snd_iprintf(buffer, "Input 3/4: Phono, 0dB\n");
3613 case HDSP_RPM_Inp34_Phon_n6dB:
3614 snd_iprintf(buffer, "Input 3/4: Phono, -6dB\n");
3616 case HDSP_RPM_Inp34_Line_0dB:
3617 snd_iprintf(buffer, "Input 3/4: Line, 0dB\n");
3619 case HDSP_RPM_Inp34_Line_n6dB:
3620 snd_iprintf(buffer, "Input 3/4: Line, -6dB\n");
3623 snd_iprintf(buffer, "Input 3/4: ???\n");
3627 if (hdsp->control_register & HDSP_SPDIFOpticalOut)
3628 snd_iprintf(buffer, "IEC958 output: Coaxial & ADAT1\n");
3630 snd_iprintf(buffer, "IEC958 output: Coaxial only\n");
3632 if (hdsp->control_register & HDSP_SPDIFProfessional)
3633 snd_iprintf(buffer, "IEC958 quality: Professional\n");
3635 snd_iprintf(buffer, "IEC958 quality: Consumer\n");
3637 if (hdsp->control_register & HDSP_SPDIFEmphasis)
3638 snd_iprintf(buffer, "IEC958 emphasis: on\n");
3640 snd_iprintf(buffer, "IEC958 emphasis: off\n");
3642 if (hdsp->control_register & HDSP_SPDIFNonAudio)
3643 snd_iprintf(buffer, "IEC958 NonAudio: on\n");
3645 snd_iprintf(buffer, "IEC958 NonAudio: off\n");
3646 x = hdsp_spdif_sample_rate(hdsp);
3648 snd_iprintf(buffer, "IEC958 sample rate: %d\n", x);
3650 snd_iprintf(buffer, "IEC958 sample rate: Error flag set\n");
3652 snd_iprintf(buffer, "\n");
3655 x = status & HDSP_Sync0;
3656 if (status & HDSP_Lock0)
3657 snd_iprintf(buffer, "ADAT1: %s\n", x ? "Sync" : "Lock");
3659 snd_iprintf(buffer, "ADAT1: No Lock\n");
3661 switch (hdsp->io_type) {
3664 x = status & HDSP_Sync1;
3665 if (status & HDSP_Lock1)
3666 snd_iprintf(buffer, "ADAT2: %s\n", x ? "Sync" : "Lock");
3668 snd_iprintf(buffer, "ADAT2: No Lock\n");
3669 x = status & HDSP_Sync2;
3670 if (status & HDSP_Lock2)
3671 snd_iprintf(buffer, "ADAT3: %s\n", x ? "Sync" : "Lock");
3673 snd_iprintf(buffer, "ADAT3: No Lock\n");
3680 x = status & HDSP_SPDIFSync;
3681 if (status & HDSP_SPDIFErrorFlag)
3682 snd_iprintf (buffer, "SPDIF: No Lock\n");
3684 snd_iprintf (buffer, "SPDIF: %s\n", x ? "Sync" : "Lock");
3686 x = status2 & HDSP_wc_sync;
3687 if (status2 & HDSP_wc_lock)
3688 snd_iprintf (buffer, "Word Clock: %s\n", x ? "Sync" : "Lock");
3690 snd_iprintf (buffer, "Word Clock: No Lock\n");
3692 x = status & HDSP_TimecodeSync;
3693 if (status & HDSP_TimecodeLock)
3694 snd_iprintf(buffer, "ADAT Sync: %s\n", x ? "Sync" : "Lock");
3696 snd_iprintf(buffer, "ADAT Sync: No Lock\n");
3698 snd_iprintf(buffer, "\n");
3700 /* Informations about H9632 specific controls */
3701 if (hdsp->io_type == H9632) {
3704 switch (hdsp_ad_gain(hdsp)) {
3715 snd_iprintf(buffer, "AD Gain : %s\n", tmp);
3717 switch (hdsp_da_gain(hdsp)) {
3728 snd_iprintf(buffer, "DA Gain : %s\n", tmp);
3730 switch (hdsp_phone_gain(hdsp)) {
3741 snd_iprintf(buffer, "Phones Gain : %s\n", tmp);
3743 snd_iprintf(buffer, "XLR Breakout Cable : %s\n",
3744 hdsp_toggle_setting(hdsp, HDSP_XLRBreakoutCable) ?
3747 if (hdsp->control_register & HDSP_AnalogExtensionBoard)
3748 snd_iprintf(buffer, "AEB : on (ADAT1 internal)\n");
3750 snd_iprintf(buffer, "AEB : off (ADAT1 external)\n");
3751 snd_iprintf(buffer, "\n");
3756 static void snd_hdsp_proc_init(struct hdsp *hdsp)
3758 snd_card_ro_proc_new(hdsp->card, "hdsp", hdsp, snd_hdsp_proc_read);
3761 static void snd_hdsp_free_buffers(struct hdsp *hdsp)
3763 snd_hammerfall_free_buffer(&hdsp->capture_dma_buf, hdsp->pci);
3764 snd_hammerfall_free_buffer(&hdsp->playback_dma_buf, hdsp->pci);
3767 static int snd_hdsp_initialize_memory(struct hdsp *hdsp)
3769 unsigned long pb_bus, cb_bus;
3771 if (snd_hammerfall_get_buffer(hdsp->pci, &hdsp->capture_dma_buf, HDSP_DMA_AREA_BYTES) < 0 ||
3772 snd_hammerfall_get_buffer(hdsp->pci, &hdsp->playback_dma_buf, HDSP_DMA_AREA_BYTES) < 0) {
3773 if (hdsp->capture_dma_buf.area)
3774 snd_dma_free_pages(&hdsp->capture_dma_buf);
3775 dev_err(hdsp->card->dev,
3776 "%s: no buffers available\n", hdsp->card_name);
3780 /* Align to bus-space 64K boundary */
3782 cb_bus = ALIGN(hdsp->capture_dma_buf.addr, 0x10000ul);
3783 pb_bus = ALIGN(hdsp->playback_dma_buf.addr, 0x10000ul);
3785 /* Tell the card where it is */
3787 hdsp_write(hdsp, HDSP_inputBufferAddress, cb_bus);
3788 hdsp_write(hdsp, HDSP_outputBufferAddress, pb_bus);
3790 hdsp->capture_buffer = hdsp->capture_dma_buf.area + (cb_bus - hdsp->capture_dma_buf.addr);
3791 hdsp->playback_buffer = hdsp->playback_dma_buf.area + (pb_bus - hdsp->playback_dma_buf.addr);
3796 static int snd_hdsp_set_defaults(struct hdsp *hdsp)
3800 /* ASSUMPTION: hdsp->lock is either held, or
3801 there is no need to hold it (e.g. during module
3807 SPDIF Input via Coax
3809 maximum latency (7 => 2^7 = 8192 samples, 64Kbyte buffer,
3810 which implies 2 4096 sample, 32Kbyte periods).
3814 hdsp->control_register = HDSP_ClockModeMaster |
3815 HDSP_SPDIFInputCoaxial |
3816 hdsp_encode_latency(7) |
3820 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
3822 #ifdef SNDRV_BIG_ENDIAN
3823 hdsp->control2_register = HDSP_BIGENDIAN_MODE;
3825 hdsp->control2_register = 0;
3827 if (hdsp->io_type == H9652)
3828 snd_hdsp_9652_enable_mixer (hdsp);
3830 hdsp_write (hdsp, HDSP_control2Reg, hdsp->control2_register);
3832 hdsp_reset_hw_pointer(hdsp);
3833 hdsp_compute_period_size(hdsp);
3835 /* silence everything */
3837 for (i = 0; i < HDSP_MATRIX_MIXER_SIZE; ++i)
3838 hdsp->mixer_matrix[i] = MINUS_INFINITY_GAIN;
3840 for (i = 0; i < ((hdsp->io_type == H9652 || hdsp->io_type == H9632) ? 1352 : HDSP_MATRIX_MIXER_SIZE); ++i) {
3841 if (hdsp_write_gain (hdsp, i, MINUS_INFINITY_GAIN))
3845 /* H9632 specific defaults */
3846 if (hdsp->io_type == H9632) {
3847 hdsp->control_register |= (HDSP_DAGainPlus4dBu | HDSP_ADGainPlus4dBu | HDSP_PhoneGain0dB);
3848 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
3851 /* set a default rate so that the channel map is set up.
3854 hdsp_set_rate(hdsp, 48000, 1);
3859 static void hdsp_midi_work(struct work_struct *work)
3861 struct hdsp *hdsp = container_of(work, struct hdsp, midi_work);
3863 if (hdsp->midi[0].pending)
3864 snd_hdsp_midi_input_read (&hdsp->midi[0]);
3865 if (hdsp->midi[1].pending)
3866 snd_hdsp_midi_input_read (&hdsp->midi[1]);
3869 static irqreturn_t snd_hdsp_interrupt(int irq, void *dev_id)
3871 struct hdsp *hdsp = (struct hdsp *) dev_id;
3872 unsigned int status;
3876 unsigned int midi0status;
3877 unsigned int midi1status;
3880 status = hdsp_read(hdsp, HDSP_statusRegister);
3882 audio = status & HDSP_audioIRQPending;
3883 midi0 = status & HDSP_midi0IRQPending;
3884 midi1 = status & HDSP_midi1IRQPending;
3886 if (!audio && !midi0 && !midi1)
3889 hdsp_write(hdsp, HDSP_interruptConfirmation, 0);
3891 midi0status = hdsp_read (hdsp, HDSP_midiStatusIn0) & 0xff;
3892 midi1status = hdsp_read (hdsp, HDSP_midiStatusIn1) & 0xff;
3894 if (!(hdsp->state & HDSP_InitializationComplete))
3898 if (hdsp->capture_substream)
3899 snd_pcm_period_elapsed(hdsp->pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream);
3901 if (hdsp->playback_substream)
3902 snd_pcm_period_elapsed(hdsp->pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream);
3905 if (midi0 && midi0status) {
3906 if (hdsp->use_midi_work) {
3907 /* we disable interrupts for this input until processing is done */
3908 hdsp->control_register &= ~HDSP_Midi0InterruptEnable;
3909 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
3910 hdsp->midi[0].pending = 1;
3913 snd_hdsp_midi_input_read (&hdsp->midi[0]);
3916 if (hdsp->io_type != Multiface && hdsp->io_type != RPM && hdsp->io_type != H9632 && midi1 && midi1status) {
3917 if (hdsp->use_midi_work) {
3918 /* we disable interrupts for this input until processing is done */
3919 hdsp->control_register &= ~HDSP_Midi1InterruptEnable;
3920 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
3921 hdsp->midi[1].pending = 1;
3924 snd_hdsp_midi_input_read (&hdsp->midi[1]);
3927 if (hdsp->use_midi_work && schedule)
3928 queue_work(system_highpri_wq, &hdsp->midi_work);
3932 static snd_pcm_uframes_t snd_hdsp_hw_pointer(struct snd_pcm_substream *substream)
3934 struct hdsp *hdsp = snd_pcm_substream_chip(substream);
3935 return hdsp_hw_pointer(hdsp);
3938 static char *hdsp_channel_buffer_location(struct hdsp *hdsp,
3945 if (snd_BUG_ON(channel < 0 || channel >= hdsp->max_channels))
3948 if ((mapped_channel = hdsp->channel_map[channel]) < 0)
3951 if (stream == SNDRV_PCM_STREAM_CAPTURE)
3952 return hdsp->capture_buffer + (mapped_channel * HDSP_CHANNEL_BUFFER_BYTES);
3954 return hdsp->playback_buffer + (mapped_channel * HDSP_CHANNEL_BUFFER_BYTES);
3957 static int snd_hdsp_playback_copy(struct snd_pcm_substream *substream,
3958 int channel, unsigned long pos,
3959 void __user *src, unsigned long count)
3961 struct hdsp *hdsp = snd_pcm_substream_chip(substream);
3964 if (snd_BUG_ON(pos + count > HDSP_CHANNEL_BUFFER_BYTES))
3967 channel_buf = hdsp_channel_buffer_location (hdsp, substream->pstr->stream, channel);
3968 if (snd_BUG_ON(!channel_buf))
3970 if (copy_from_user(channel_buf + pos, src, count))
3975 static int snd_hdsp_playback_copy_kernel(struct snd_pcm_substream *substream,
3976 int channel, unsigned long pos,
3977 void *src, unsigned long count)
3979 struct hdsp *hdsp = snd_pcm_substream_chip(substream);
3982 channel_buf = hdsp_channel_buffer_location(hdsp, substream->pstr->stream, channel);
3983 if (snd_BUG_ON(!channel_buf))
3985 memcpy(channel_buf + pos, src, count);
3989 static int snd_hdsp_capture_copy(struct snd_pcm_substream *substream,
3990 int channel, unsigned long pos,
3991 void __user *dst, unsigned long count)
3993 struct hdsp *hdsp = snd_pcm_substream_chip(substream);
3996 if (snd_BUG_ON(pos + count > HDSP_CHANNEL_BUFFER_BYTES))
3999 channel_buf = hdsp_channel_buffer_location (hdsp, substream->pstr->stream, channel);
4000 if (snd_BUG_ON(!channel_buf))
4002 if (copy_to_user(dst, channel_buf + pos, count))
4007 static int snd_hdsp_capture_copy_kernel(struct snd_pcm_substream *substream,
4008 int channel, unsigned long pos,
4009 void *dst, unsigned long count)
4011 struct hdsp *hdsp = snd_pcm_substream_chip(substream);
4014 channel_buf = hdsp_channel_buffer_location(hdsp, substream->pstr->stream, channel);
4015 if (snd_BUG_ON(!channel_buf))
4017 memcpy(dst, channel_buf + pos, count);
4021 static int snd_hdsp_hw_silence(struct snd_pcm_substream *substream,
4022 int channel, unsigned long pos,
4023 unsigned long count)
4025 struct hdsp *hdsp = snd_pcm_substream_chip(substream);
4028 channel_buf = hdsp_channel_buffer_location (hdsp, substream->pstr->stream, channel);
4029 if (snd_BUG_ON(!channel_buf))
4031 memset(channel_buf + pos, 0, count);
4035 static int snd_hdsp_reset(struct snd_pcm_substream *substream)
4037 struct snd_pcm_runtime *runtime = substream->runtime;
4038 struct hdsp *hdsp = snd_pcm_substream_chip(substream);
4039 struct snd_pcm_substream *other;
4040 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
4041 other = hdsp->capture_substream;
4043 other = hdsp->playback_substream;
4045 runtime->status->hw_ptr = hdsp_hw_pointer(hdsp);
4047 runtime->status->hw_ptr = 0;
4049 struct snd_pcm_substream *s;
4050 struct snd_pcm_runtime *oruntime = other->runtime;
4051 snd_pcm_group_for_each_entry(s, substream) {
4053 oruntime->status->hw_ptr = runtime->status->hw_ptr;
4061 static int snd_hdsp_hw_params(struct snd_pcm_substream *substream,
4062 struct snd_pcm_hw_params *params)
4064 struct hdsp *hdsp = snd_pcm_substream_chip(substream);
4069 if (hdsp_check_for_iobox (hdsp))
4072 if (hdsp_check_for_firmware(hdsp, 1))
4075 spin_lock_irq(&hdsp->lock);
4077 if (substream->pstr->stream == SNDRV_PCM_STREAM_PLAYBACK) {
4078 hdsp->control_register &= ~(HDSP_SPDIFProfessional | HDSP_SPDIFNonAudio | HDSP_SPDIFEmphasis);
4079 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register |= hdsp->creg_spdif_stream);
4080 this_pid = hdsp->playback_pid;
4081 other_pid = hdsp->capture_pid;
4083 this_pid = hdsp->capture_pid;
4084 other_pid = hdsp->playback_pid;
4087 if ((other_pid > 0) && (this_pid != other_pid)) {
4089 /* The other stream is open, and not by the same
4090 task as this one. Make sure that the parameters
4091 that matter are the same.
4094 if (params_rate(params) != hdsp->system_sample_rate) {
4095 spin_unlock_irq(&hdsp->lock);
4096 _snd_pcm_hw_param_setempty(params, SNDRV_PCM_HW_PARAM_RATE);
4100 if (params_period_size(params) != hdsp->period_bytes / 4) {
4101 spin_unlock_irq(&hdsp->lock);
4102 _snd_pcm_hw_param_setempty(params, SNDRV_PCM_HW_PARAM_PERIOD_SIZE);
4108 spin_unlock_irq(&hdsp->lock);
4112 spin_unlock_irq(&hdsp->lock);
4115 /* how to make sure that the rate matches an externally-set one ?
4118 spin_lock_irq(&hdsp->lock);
4119 if (! hdsp->clock_source_locked) {
4120 if ((err = hdsp_set_rate(hdsp, params_rate(params), 0)) < 0) {
4121 spin_unlock_irq(&hdsp->lock);
4122 _snd_pcm_hw_param_setempty(params, SNDRV_PCM_HW_PARAM_RATE);
4126 spin_unlock_irq(&hdsp->lock);
4128 if ((err = hdsp_set_interrupt_interval(hdsp, params_period_size(params))) < 0) {
4129 _snd_pcm_hw_param_setempty(params, SNDRV_PCM_HW_PARAM_PERIOD_SIZE);
4136 static int snd_hdsp_channel_info(struct snd_pcm_substream *substream,
4137 struct snd_pcm_channel_info *info)
4139 struct hdsp *hdsp = snd_pcm_substream_chip(substream);
4140 unsigned int channel = info->channel;
4142 if (snd_BUG_ON(channel >= hdsp->max_channels))
4144 channel = array_index_nospec(channel, hdsp->max_channels);
4146 if (hdsp->channel_map[channel] < 0)
4149 info->offset = hdsp->channel_map[channel] * HDSP_CHANNEL_BUFFER_BYTES;
4155 static int snd_hdsp_ioctl(struct snd_pcm_substream *substream,
4156 unsigned int cmd, void *arg)
4159 case SNDRV_PCM_IOCTL1_RESET:
4160 return snd_hdsp_reset(substream);
4161 case SNDRV_PCM_IOCTL1_CHANNEL_INFO:
4162 return snd_hdsp_channel_info(substream, arg);
4167 return snd_pcm_lib_ioctl(substream, cmd, arg);
4170 static int snd_hdsp_trigger(struct snd_pcm_substream *substream, int cmd)
4172 struct hdsp *hdsp = snd_pcm_substream_chip(substream);
4173 struct snd_pcm_substream *other;
4176 if (hdsp_check_for_iobox (hdsp))
4179 if (hdsp_check_for_firmware(hdsp, 0)) /* no auto-loading in trigger */
4182 spin_lock(&hdsp->lock);
4183 running = hdsp->running;
4185 case SNDRV_PCM_TRIGGER_START:
4186 running |= 1 << substream->stream;
4188 case SNDRV_PCM_TRIGGER_STOP:
4189 running &= ~(1 << substream->stream);
4193 spin_unlock(&hdsp->lock);
4196 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
4197 other = hdsp->capture_substream;
4199 other = hdsp->playback_substream;
4202 struct snd_pcm_substream *s;
4203 snd_pcm_group_for_each_entry(s, substream) {
4205 snd_pcm_trigger_done(s, substream);
4206 if (cmd == SNDRV_PCM_TRIGGER_START)
4207 running |= 1 << s->stream;
4209 running &= ~(1 << s->stream);
4213 if (cmd == SNDRV_PCM_TRIGGER_START) {
4214 if (!(running & (1 << SNDRV_PCM_STREAM_PLAYBACK)) &&
4215 substream->stream == SNDRV_PCM_STREAM_CAPTURE)
4216 hdsp_silence_playback(hdsp);
4219 substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
4220 hdsp_silence_playback(hdsp);
4223 if (substream->stream == SNDRV_PCM_STREAM_CAPTURE)
4224 hdsp_silence_playback(hdsp);
4227 snd_pcm_trigger_done(substream, substream);
4228 if (!hdsp->running && running)
4229 hdsp_start_audio(hdsp);
4230 else if (hdsp->running && !running)
4231 hdsp_stop_audio(hdsp);
4232 hdsp->running = running;
4233 spin_unlock(&hdsp->lock);
4238 static int snd_hdsp_prepare(struct snd_pcm_substream *substream)
4240 struct hdsp *hdsp = snd_pcm_substream_chip(substream);
4243 if (hdsp_check_for_iobox (hdsp))
4246 if (hdsp_check_for_firmware(hdsp, 1))
4249 spin_lock_irq(&hdsp->lock);
4251 hdsp_reset_hw_pointer(hdsp);
4252 spin_unlock_irq(&hdsp->lock);
4256 static const struct snd_pcm_hardware snd_hdsp_playback_subinfo =
4258 .info = (SNDRV_PCM_INFO_MMAP |
4259 SNDRV_PCM_INFO_MMAP_VALID |
4260 SNDRV_PCM_INFO_NONINTERLEAVED |
4261 SNDRV_PCM_INFO_SYNC_START |
4262 SNDRV_PCM_INFO_DOUBLE),
4263 #ifdef SNDRV_BIG_ENDIAN
4264 .formats = SNDRV_PCM_FMTBIT_S32_BE,
4266 .formats = SNDRV_PCM_FMTBIT_S32_LE,
4268 .rates = (SNDRV_PCM_RATE_32000 |
4269 SNDRV_PCM_RATE_44100 |
4270 SNDRV_PCM_RATE_48000 |
4271 SNDRV_PCM_RATE_64000 |
4272 SNDRV_PCM_RATE_88200 |
4273 SNDRV_PCM_RATE_96000),
4277 .channels_max = HDSP_MAX_CHANNELS,
4278 .buffer_bytes_max = HDSP_CHANNEL_BUFFER_BYTES * HDSP_MAX_CHANNELS,
4279 .period_bytes_min = (64 * 4) * 10,
4280 .period_bytes_max = (8192 * 4) * HDSP_MAX_CHANNELS,
4286 static const struct snd_pcm_hardware snd_hdsp_capture_subinfo =
4288 .info = (SNDRV_PCM_INFO_MMAP |
4289 SNDRV_PCM_INFO_MMAP_VALID |
4290 SNDRV_PCM_INFO_NONINTERLEAVED |
4291 SNDRV_PCM_INFO_SYNC_START),
4292 #ifdef SNDRV_BIG_ENDIAN
4293 .formats = SNDRV_PCM_FMTBIT_S32_BE,
4295 .formats = SNDRV_PCM_FMTBIT_S32_LE,
4297 .rates = (SNDRV_PCM_RATE_32000 |
4298 SNDRV_PCM_RATE_44100 |
4299 SNDRV_PCM_RATE_48000 |
4300 SNDRV_PCM_RATE_64000 |
4301 SNDRV_PCM_RATE_88200 |
4302 SNDRV_PCM_RATE_96000),
4306 .channels_max = HDSP_MAX_CHANNELS,
4307 .buffer_bytes_max = HDSP_CHANNEL_BUFFER_BYTES * HDSP_MAX_CHANNELS,
4308 .period_bytes_min = (64 * 4) * 10,
4309 .period_bytes_max = (8192 * 4) * HDSP_MAX_CHANNELS,
4315 static const unsigned int hdsp_period_sizes[] = { 64, 128, 256, 512, 1024, 2048, 4096, 8192 };
4317 static const struct snd_pcm_hw_constraint_list hdsp_hw_constraints_period_sizes = {
4318 .count = ARRAY_SIZE(hdsp_period_sizes),
4319 .list = hdsp_period_sizes,
4323 static const unsigned int hdsp_9632_sample_rates[] = { 32000, 44100, 48000, 64000, 88200, 96000, 128000, 176400, 192000 };
4325 static const struct snd_pcm_hw_constraint_list hdsp_hw_constraints_9632_sample_rates = {
4326 .count = ARRAY_SIZE(hdsp_9632_sample_rates),
4327 .list = hdsp_9632_sample_rates,
4331 static int snd_hdsp_hw_rule_in_channels(struct snd_pcm_hw_params *params,
4332 struct snd_pcm_hw_rule *rule)
4334 struct hdsp *hdsp = rule->private;
4335 struct snd_interval *c = hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS);
4336 if (hdsp->io_type == H9632) {
4337 unsigned int list[3];
4338 list[0] = hdsp->qs_in_channels;
4339 list[1] = hdsp->ds_in_channels;
4340 list[2] = hdsp->ss_in_channels;
4341 return snd_interval_list(c, 3, list, 0);
4343 unsigned int list[2];
4344 list[0] = hdsp->ds_in_channels;
4345 list[1] = hdsp->ss_in_channels;
4346 return snd_interval_list(c, 2, list, 0);
4350 static int snd_hdsp_hw_rule_out_channels(struct snd_pcm_hw_params *params,
4351 struct snd_pcm_hw_rule *rule)
4353 unsigned int list[3];
4354 struct hdsp *hdsp = rule->private;
4355 struct snd_interval *c = hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS);
4356 if (hdsp->io_type == H9632) {
4357 list[0] = hdsp->qs_out_channels;
4358 list[1] = hdsp->ds_out_channels;
4359 list[2] = hdsp->ss_out_channels;
4360 return snd_interval_list(c, 3, list, 0);
4362 list[0] = hdsp->ds_out_channels;
4363 list[1] = hdsp->ss_out_channels;
4365 return snd_interval_list(c, 2, list, 0);
4368 static int snd_hdsp_hw_rule_in_channels_rate(struct snd_pcm_hw_params *params,
4369 struct snd_pcm_hw_rule *rule)
4371 struct hdsp *hdsp = rule->private;
4372 struct snd_interval *c = hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS);
4373 struct snd_interval *r = hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE);
4374 if (r->min > 96000 && hdsp->io_type == H9632) {
4375 struct snd_interval t = {
4376 .min = hdsp->qs_in_channels,
4377 .max = hdsp->qs_in_channels,
4380 return snd_interval_refine(c, &t);
4381 } else if (r->min > 48000 && r->max <= 96000) {
4382 struct snd_interval t = {
4383 .min = hdsp->ds_in_channels,
4384 .max = hdsp->ds_in_channels,
4387 return snd_interval_refine(c, &t);
4388 } else if (r->max < 64000) {
4389 struct snd_interval t = {
4390 .min = hdsp->ss_in_channels,
4391 .max = hdsp->ss_in_channels,
4394 return snd_interval_refine(c, &t);
4399 static int snd_hdsp_hw_rule_out_channels_rate(struct snd_pcm_hw_params *params,
4400 struct snd_pcm_hw_rule *rule)
4402 struct hdsp *hdsp = rule->private;
4403 struct snd_interval *c = hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS);
4404 struct snd_interval *r = hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE);
4405 if (r->min > 96000 && hdsp->io_type == H9632) {
4406 struct snd_interval t = {
4407 .min = hdsp->qs_out_channels,
4408 .max = hdsp->qs_out_channels,
4411 return snd_interval_refine(c, &t);
4412 } else if (r->min > 48000 && r->max <= 96000) {
4413 struct snd_interval t = {
4414 .min = hdsp->ds_out_channels,
4415 .max = hdsp->ds_out_channels,
4418 return snd_interval_refine(c, &t);
4419 } else if (r->max < 64000) {
4420 struct snd_interval t = {
4421 .min = hdsp->ss_out_channels,
4422 .max = hdsp->ss_out_channels,
4425 return snd_interval_refine(c, &t);
4430 static int snd_hdsp_hw_rule_rate_out_channels(struct snd_pcm_hw_params *params,
4431 struct snd_pcm_hw_rule *rule)
4433 struct hdsp *hdsp = rule->private;
4434 struct snd_interval *c = hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS);
4435 struct snd_interval *r = hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE);
4436 if (c->min >= hdsp->ss_out_channels) {
4437 struct snd_interval t = {
4442 return snd_interval_refine(r, &t);
4443 } else if (c->max <= hdsp->qs_out_channels && hdsp->io_type == H9632) {
4444 struct snd_interval t = {
4449 return snd_interval_refine(r, &t);
4450 } else if (c->max <= hdsp->ds_out_channels) {
4451 struct snd_interval t = {
4456 return snd_interval_refine(r, &t);
4461 static int snd_hdsp_hw_rule_rate_in_channels(struct snd_pcm_hw_params *params,
4462 struct snd_pcm_hw_rule *rule)
4464 struct hdsp *hdsp = rule->private;
4465 struct snd_interval *c = hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS);
4466 struct snd_interval *r = hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE);
4467 if (c->min >= hdsp->ss_in_channels) {
4468 struct snd_interval t = {
4473 return snd_interval_refine(r, &t);
4474 } else if (c->max <= hdsp->qs_in_channels && hdsp->io_type == H9632) {
4475 struct snd_interval t = {
4480 return snd_interval_refine(r, &t);
4481 } else if (c->max <= hdsp->ds_in_channels) {
4482 struct snd_interval t = {
4487 return snd_interval_refine(r, &t);
4492 static int snd_hdsp_playback_open(struct snd_pcm_substream *substream)
4494 struct hdsp *hdsp = snd_pcm_substream_chip(substream);
4495 struct snd_pcm_runtime *runtime = substream->runtime;
4497 if (hdsp_check_for_iobox (hdsp))
4500 if (hdsp_check_for_firmware(hdsp, 1))
4503 spin_lock_irq(&hdsp->lock);
4505 snd_pcm_set_sync(substream);
4507 runtime->hw = snd_hdsp_playback_subinfo;
4508 runtime->dma_area = hdsp->playback_buffer;
4509 runtime->dma_bytes = HDSP_DMA_AREA_BYTES;
4511 hdsp->playback_pid = current->pid;
4512 hdsp->playback_substream = substream;
4514 spin_unlock_irq(&hdsp->lock);
4516 snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24);
4517 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_SIZE, &hdsp_hw_constraints_period_sizes);
4518 if (hdsp->clock_source_locked) {
4519 runtime->hw.rate_min = runtime->hw.rate_max = hdsp->system_sample_rate;
4520 } else if (hdsp->io_type == H9632) {
4521 runtime->hw.rate_max = 192000;
4522 runtime->hw.rates = SNDRV_PCM_RATE_KNOT;
4523 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, &hdsp_hw_constraints_9632_sample_rates);
4525 if (hdsp->io_type == H9632) {
4526 runtime->hw.channels_min = hdsp->qs_out_channels;
4527 runtime->hw.channels_max = hdsp->ss_out_channels;
4530 snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
4531 snd_hdsp_hw_rule_out_channels, hdsp,
4532 SNDRV_PCM_HW_PARAM_CHANNELS, -1);
4533 snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
4534 snd_hdsp_hw_rule_out_channels_rate, hdsp,
4535 SNDRV_PCM_HW_PARAM_RATE, -1);
4536 snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
4537 snd_hdsp_hw_rule_rate_out_channels, hdsp,
4538 SNDRV_PCM_HW_PARAM_CHANNELS, -1);
4540 if (RPM != hdsp->io_type) {
4541 hdsp->creg_spdif_stream = hdsp->creg_spdif;
4542 hdsp->spdif_ctl->vd[0].access &= ~SNDRV_CTL_ELEM_ACCESS_INACTIVE;
4543 snd_ctl_notify(hdsp->card, SNDRV_CTL_EVENT_MASK_VALUE |
4544 SNDRV_CTL_EVENT_MASK_INFO, &hdsp->spdif_ctl->id);
4549 static int snd_hdsp_playback_release(struct snd_pcm_substream *substream)
4551 struct hdsp *hdsp = snd_pcm_substream_chip(substream);
4553 spin_lock_irq(&hdsp->lock);
4555 hdsp->playback_pid = -1;
4556 hdsp->playback_substream = NULL;
4558 spin_unlock_irq(&hdsp->lock);
4560 if (RPM != hdsp->io_type) {
4561 hdsp->spdif_ctl->vd[0].access |= SNDRV_CTL_ELEM_ACCESS_INACTIVE;
4562 snd_ctl_notify(hdsp->card, SNDRV_CTL_EVENT_MASK_VALUE |
4563 SNDRV_CTL_EVENT_MASK_INFO, &hdsp->spdif_ctl->id);
4569 static int snd_hdsp_capture_open(struct snd_pcm_substream *substream)
4571 struct hdsp *hdsp = snd_pcm_substream_chip(substream);
4572 struct snd_pcm_runtime *runtime = substream->runtime;
4574 if (hdsp_check_for_iobox (hdsp))
4577 if (hdsp_check_for_firmware(hdsp, 1))
4580 spin_lock_irq(&hdsp->lock);
4582 snd_pcm_set_sync(substream);
4584 runtime->hw = snd_hdsp_capture_subinfo;
4585 runtime->dma_area = hdsp->capture_buffer;
4586 runtime->dma_bytes = HDSP_DMA_AREA_BYTES;
4588 hdsp->capture_pid = current->pid;
4589 hdsp->capture_substream = substream;
4591 spin_unlock_irq(&hdsp->lock);
4593 snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24);
4594 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_SIZE, &hdsp_hw_constraints_period_sizes);
4595 if (hdsp->io_type == H9632) {
4596 runtime->hw.channels_min = hdsp->qs_in_channels;
4597 runtime->hw.channels_max = hdsp->ss_in_channels;
4598 runtime->hw.rate_max = 192000;
4599 runtime->hw.rates = SNDRV_PCM_RATE_KNOT;
4600 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, &hdsp_hw_constraints_9632_sample_rates);
4602 snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
4603 snd_hdsp_hw_rule_in_channels, hdsp,
4604 SNDRV_PCM_HW_PARAM_CHANNELS, -1);
4605 snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
4606 snd_hdsp_hw_rule_in_channels_rate, hdsp,
4607 SNDRV_PCM_HW_PARAM_RATE, -1);
4608 snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
4609 snd_hdsp_hw_rule_rate_in_channels, hdsp,
4610 SNDRV_PCM_HW_PARAM_CHANNELS, -1);
4614 static int snd_hdsp_capture_release(struct snd_pcm_substream *substream)
4616 struct hdsp *hdsp = snd_pcm_substream_chip(substream);
4618 spin_lock_irq(&hdsp->lock);
4620 hdsp->capture_pid = -1;
4621 hdsp->capture_substream = NULL;
4623 spin_unlock_irq(&hdsp->lock);
4627 /* helper functions for copying meter values */
4628 static inline int copy_u32_le(void __user *dest, void __iomem *src)
4630 u32 val = readl(src);
4631 return copy_to_user(dest, &val, 4);
4634 static inline int copy_u64_le(void __user *dest, void __iomem *src_low, void __iomem *src_high)
4636 u32 rms_low, rms_high;
4638 rms_low = readl(src_low);
4639 rms_high = readl(src_high);
4640 rms = ((u64)rms_high << 32) | rms_low;
4641 return copy_to_user(dest, &rms, 8);
4644 static inline int copy_u48_le(void __user *dest, void __iomem *src_low, void __iomem *src_high)
4646 u32 rms_low, rms_high;
4648 rms_low = readl(src_low) & 0xffffff00;
4649 rms_high = readl(src_high) & 0xffffff00;
4650 rms = ((u64)rms_high << 32) | rms_low;
4651 return copy_to_user(dest, &rms, 8);
4654 static int hdsp_9652_get_peak(struct hdsp *hdsp, struct hdsp_peak_rms __user *peak_rms)
4656 int doublespeed = 0;
4657 int i, j, channels, ofs;
4659 if (hdsp_read (hdsp, HDSP_statusRegister) & HDSP_DoubleSpeedStatus)
4661 channels = doublespeed ? 14 : 26;
4662 for (i = 0, j = 0; i < 26; ++i) {
4663 if (doublespeed && (i & 4))
4665 ofs = HDSP_9652_peakBase - j * 4;
4666 if (copy_u32_le(&peak_rms->input_peaks[i], hdsp->iobase + ofs))
4668 ofs -= channels * 4;
4669 if (copy_u32_le(&peak_rms->playback_peaks[i], hdsp->iobase + ofs))
4671 ofs -= channels * 4;
4672 if (copy_u32_le(&peak_rms->output_peaks[i], hdsp->iobase + ofs))
4674 ofs = HDSP_9652_rmsBase + j * 8;
4675 if (copy_u48_le(&peak_rms->input_rms[i], hdsp->iobase + ofs,
4676 hdsp->iobase + ofs + 4))
4678 ofs += channels * 8;
4679 if (copy_u48_le(&peak_rms->playback_rms[i], hdsp->iobase + ofs,
4680 hdsp->iobase + ofs + 4))
4682 ofs += channels * 8;
4683 if (copy_u48_le(&peak_rms->output_rms[i], hdsp->iobase + ofs,
4684 hdsp->iobase + ofs + 4))
4691 static int hdsp_9632_get_peak(struct hdsp *hdsp, struct hdsp_peak_rms __user *peak_rms)
4694 struct hdsp_9632_meters __iomem *m;
4695 int doublespeed = 0;
4697 if (hdsp_read (hdsp, HDSP_statusRegister) & HDSP_DoubleSpeedStatus)
4699 m = (struct hdsp_9632_meters __iomem *)(hdsp->iobase+HDSP_9632_metersBase);
4700 for (i = 0, j = 0; i < 16; ++i, ++j) {
4701 if (copy_u32_le(&peak_rms->input_peaks[i], &m->input_peak[j]))
4703 if (copy_u32_le(&peak_rms->playback_peaks[i], &m->playback_peak[j]))
4705 if (copy_u32_le(&peak_rms->output_peaks[i], &m->output_peak[j]))
4707 if (copy_u64_le(&peak_rms->input_rms[i], &m->input_rms_low[j],
4708 &m->input_rms_high[j]))
4710 if (copy_u64_le(&peak_rms->playback_rms[i], &m->playback_rms_low[j],
4711 &m->playback_rms_high[j]))
4713 if (copy_u64_le(&peak_rms->output_rms[i], &m->output_rms_low[j],
4714 &m->output_rms_high[j]))
4716 if (doublespeed && i == 3) i += 4;
4721 static int hdsp_get_peak(struct hdsp *hdsp, struct hdsp_peak_rms __user *peak_rms)
4725 for (i = 0; i < 26; i++) {
4726 if (copy_u32_le(&peak_rms->playback_peaks[i],
4727 hdsp->iobase + HDSP_playbackPeakLevel + i * 4))
4729 if (copy_u32_le(&peak_rms->input_peaks[i],
4730 hdsp->iobase + HDSP_inputPeakLevel + i * 4))
4733 for (i = 0; i < 28; i++) {
4734 if (copy_u32_le(&peak_rms->output_peaks[i],
4735 hdsp->iobase + HDSP_outputPeakLevel + i * 4))
4738 for (i = 0; i < 26; ++i) {
4739 if (copy_u64_le(&peak_rms->playback_rms[i],
4740 hdsp->iobase + HDSP_playbackRmsLevel + i * 8 + 4,
4741 hdsp->iobase + HDSP_playbackRmsLevel + i * 8))
4743 if (copy_u64_le(&peak_rms->input_rms[i],
4744 hdsp->iobase + HDSP_inputRmsLevel + i * 8 + 4,
4745 hdsp->iobase + HDSP_inputRmsLevel + i * 8))
4751 static int snd_hdsp_hwdep_ioctl(struct snd_hwdep *hw, struct file *file, unsigned int cmd, unsigned long arg)
4753 struct hdsp *hdsp = hw->private_data;
4754 void __user *argp = (void __user *)arg;
4758 case SNDRV_HDSP_IOCTL_GET_PEAK_RMS: {
4759 struct hdsp_peak_rms __user *peak_rms = (struct hdsp_peak_rms __user *)arg;
4761 err = hdsp_check_for_iobox(hdsp);
4765 err = hdsp_check_for_firmware(hdsp, 1);
4769 if (!(hdsp->state & HDSP_FirmwareLoaded)) {
4770 dev_err(hdsp->card->dev,
4771 "firmware needs to be uploaded to the card.\n");
4775 switch (hdsp->io_type) {
4777 return hdsp_9652_get_peak(hdsp, peak_rms);
4779 return hdsp_9632_get_peak(hdsp, peak_rms);
4781 return hdsp_get_peak(hdsp, peak_rms);
4784 case SNDRV_HDSP_IOCTL_GET_CONFIG_INFO: {
4785 struct hdsp_config_info info;
4786 unsigned long flags;
4789 err = hdsp_check_for_iobox(hdsp);
4793 err = hdsp_check_for_firmware(hdsp, 1);
4797 memset(&info, 0, sizeof(info));
4798 spin_lock_irqsave(&hdsp->lock, flags);
4799 info.pref_sync_ref = (unsigned char)hdsp_pref_sync_ref(hdsp);
4800 info.wordclock_sync_check = (unsigned char)hdsp_wc_sync_check(hdsp);
4801 if (hdsp->io_type != H9632)
4802 info.adatsync_sync_check = (unsigned char)hdsp_adatsync_sync_check(hdsp);
4803 info.spdif_sync_check = (unsigned char)hdsp_spdif_sync_check(hdsp);
4804 for (i = 0; i < ((hdsp->io_type != Multiface && hdsp->io_type != RPM && hdsp->io_type != H9632) ? 3 : 1); ++i)
4805 info.adat_sync_check[i] = (unsigned char)hdsp_adat_sync_check(hdsp, i);
4806 info.spdif_in = (unsigned char)hdsp_spdif_in(hdsp);
4807 info.spdif_out = (unsigned char)hdsp_toggle_setting(hdsp,
4808 HDSP_SPDIFOpticalOut);
4809 info.spdif_professional = (unsigned char)
4810 hdsp_toggle_setting(hdsp, HDSP_SPDIFProfessional);
4811 info.spdif_emphasis = (unsigned char)
4812 hdsp_toggle_setting(hdsp, HDSP_SPDIFEmphasis);
4813 info.spdif_nonaudio = (unsigned char)
4814 hdsp_toggle_setting(hdsp, HDSP_SPDIFNonAudio);
4815 info.spdif_sample_rate = hdsp_spdif_sample_rate(hdsp);
4816 info.system_sample_rate = hdsp->system_sample_rate;
4817 info.autosync_sample_rate = hdsp_external_sample_rate(hdsp);
4818 info.system_clock_mode = (unsigned char)hdsp_system_clock_mode(hdsp);
4819 info.clock_source = (unsigned char)hdsp_clock_source(hdsp);
4820 info.autosync_ref = (unsigned char)hdsp_autosync_ref(hdsp);
4821 info.line_out = (unsigned char)
4822 hdsp_toggle_setting(hdsp, HDSP_LineOut);
4823 if (hdsp->io_type == H9632) {
4824 info.da_gain = (unsigned char)hdsp_da_gain(hdsp);
4825 info.ad_gain = (unsigned char)hdsp_ad_gain(hdsp);
4826 info.phone_gain = (unsigned char)hdsp_phone_gain(hdsp);
4827 info.xlr_breakout_cable =
4828 (unsigned char)hdsp_toggle_setting(hdsp,
4829 HDSP_XLRBreakoutCable);
4831 } else if (hdsp->io_type == RPM) {
4832 info.da_gain = (unsigned char) hdsp_rpm_input12(hdsp);
4833 info.ad_gain = (unsigned char) hdsp_rpm_input34(hdsp);
4835 if (hdsp->io_type == H9632 || hdsp->io_type == H9652)
4836 info.analog_extension_board =
4837 (unsigned char)hdsp_toggle_setting(hdsp,
4838 HDSP_AnalogExtensionBoard);
4839 spin_unlock_irqrestore(&hdsp->lock, flags);
4840 if (copy_to_user(argp, &info, sizeof(info)))
4844 case SNDRV_HDSP_IOCTL_GET_9632_AEB: {
4845 struct hdsp_9632_aeb h9632_aeb;
4847 if (hdsp->io_type != H9632) return -EINVAL;
4848 h9632_aeb.aebi = hdsp->ss_in_channels - H9632_SS_CHANNELS;
4849 h9632_aeb.aebo = hdsp->ss_out_channels - H9632_SS_CHANNELS;
4850 if (copy_to_user(argp, &h9632_aeb, sizeof(h9632_aeb)))
4854 case SNDRV_HDSP_IOCTL_GET_VERSION: {
4855 struct hdsp_version hdsp_version;
4858 if (hdsp->io_type == H9652 || hdsp->io_type == H9632) return -EINVAL;
4859 if (hdsp->io_type == Undefined) {
4860 if ((err = hdsp_get_iobox_version(hdsp)) < 0)
4863 memset(&hdsp_version, 0, sizeof(hdsp_version));
4864 hdsp_version.io_type = hdsp->io_type;
4865 hdsp_version.firmware_rev = hdsp->firmware_rev;
4866 if ((err = copy_to_user(argp, &hdsp_version, sizeof(hdsp_version))))
4870 case SNDRV_HDSP_IOCTL_UPLOAD_FIRMWARE: {
4871 struct hdsp_firmware firmware;
4872 u32 __user *firmware_data;
4875 if (hdsp->io_type == H9652 || hdsp->io_type == H9632) return -EINVAL;
4876 /* SNDRV_HDSP_IOCTL_GET_VERSION must have been called */
4877 if (hdsp->io_type == Undefined) return -EINVAL;
4879 if (hdsp->state & (HDSP_FirmwareCached | HDSP_FirmwareLoaded))
4882 dev_info(hdsp->card->dev,
4883 "initializing firmware upload\n");
4884 if (copy_from_user(&firmware, argp, sizeof(firmware)))
4886 firmware_data = (u32 __user *)firmware.firmware_data;
4888 if (hdsp_check_for_iobox (hdsp))
4891 if (!hdsp->fw_uploaded) {
4892 hdsp->fw_uploaded = vmalloc(HDSP_FIRMWARE_SIZE);
4893 if (!hdsp->fw_uploaded)
4897 if (copy_from_user(hdsp->fw_uploaded, firmware_data,
4898 HDSP_FIRMWARE_SIZE)) {
4899 vfree(hdsp->fw_uploaded);
4900 hdsp->fw_uploaded = NULL;
4904 hdsp->state |= HDSP_FirmwareCached;
4906 if ((err = snd_hdsp_load_firmware_from_cache(hdsp)) < 0)
4909 if (!(hdsp->state & HDSP_InitializationComplete)) {
4910 if ((err = snd_hdsp_enable_io(hdsp)) < 0)
4913 snd_hdsp_initialize_channels(hdsp);
4914 snd_hdsp_initialize_midi_flush(hdsp);
4916 if ((err = snd_hdsp_create_alsa_devices(hdsp->card, hdsp)) < 0) {
4917 dev_err(hdsp->card->dev,
4918 "error creating alsa devices\n");
4924 case SNDRV_HDSP_IOCTL_GET_MIXER: {
4925 struct hdsp_mixer __user *mixer = (struct hdsp_mixer __user *)argp;
4926 if (copy_to_user(mixer->matrix, hdsp->mixer_matrix, sizeof(unsigned short)*HDSP_MATRIX_MIXER_SIZE))
4936 static const struct snd_pcm_ops snd_hdsp_playback_ops = {
4937 .open = snd_hdsp_playback_open,
4938 .close = snd_hdsp_playback_release,
4939 .ioctl = snd_hdsp_ioctl,
4940 .hw_params = snd_hdsp_hw_params,
4941 .prepare = snd_hdsp_prepare,
4942 .trigger = snd_hdsp_trigger,
4943 .pointer = snd_hdsp_hw_pointer,
4944 .copy_user = snd_hdsp_playback_copy,
4945 .copy_kernel = snd_hdsp_playback_copy_kernel,
4946 .fill_silence = snd_hdsp_hw_silence,
4949 static const struct snd_pcm_ops snd_hdsp_capture_ops = {
4950 .open = snd_hdsp_capture_open,
4951 .close = snd_hdsp_capture_release,
4952 .ioctl = snd_hdsp_ioctl,
4953 .hw_params = snd_hdsp_hw_params,
4954 .prepare = snd_hdsp_prepare,
4955 .trigger = snd_hdsp_trigger,
4956 .pointer = snd_hdsp_hw_pointer,
4957 .copy_user = snd_hdsp_capture_copy,
4958 .copy_kernel = snd_hdsp_capture_copy_kernel,
4961 static int snd_hdsp_create_hwdep(struct snd_card *card, struct hdsp *hdsp)
4963 struct snd_hwdep *hw;
4966 if ((err = snd_hwdep_new(card, "HDSP hwdep", 0, &hw)) < 0)
4970 hw->private_data = hdsp;
4971 strcpy(hw->name, "HDSP hwdep interface");
4973 hw->ops.ioctl = snd_hdsp_hwdep_ioctl;
4974 hw->ops.ioctl_compat = snd_hdsp_hwdep_ioctl;
4979 static int snd_hdsp_create_pcm(struct snd_card *card, struct hdsp *hdsp)
4981 struct snd_pcm *pcm;
4984 if ((err = snd_pcm_new(card, hdsp->card_name, 0, 1, 1, &pcm)) < 0)
4988 pcm->private_data = hdsp;
4989 strcpy(pcm->name, hdsp->card_name);
4991 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_hdsp_playback_ops);
4992 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_hdsp_capture_ops);
4994 pcm->info_flags = SNDRV_PCM_INFO_JOINT_DUPLEX;
4999 static void snd_hdsp_9652_enable_mixer (struct hdsp *hdsp)
5001 hdsp->control2_register |= HDSP_9652_ENABLE_MIXER;
5002 hdsp_write (hdsp, HDSP_control2Reg, hdsp->control2_register);
5005 static int snd_hdsp_enable_io (struct hdsp *hdsp)
5009 if (hdsp_fifo_wait (hdsp, 0, 100)) {
5010 dev_err(hdsp->card->dev,
5011 "enable_io fifo_wait failed\n");
5015 for (i = 0; i < hdsp->max_channels; ++i) {
5016 hdsp_write (hdsp, HDSP_inputEnable + (4 * i), 1);
5017 hdsp_write (hdsp, HDSP_outputEnable + (4 * i), 1);
5023 static void snd_hdsp_initialize_channels(struct hdsp *hdsp)
5025 int status, aebi_channels, aebo_channels, i;
5027 switch (hdsp->io_type) {
5029 hdsp->card_name = "RME Hammerfall DSP + Digiface";
5030 hdsp->ss_in_channels = hdsp->ss_out_channels = DIGIFACE_SS_CHANNELS;
5031 hdsp->ds_in_channels = hdsp->ds_out_channels = DIGIFACE_DS_CHANNELS;
5035 hdsp->card_name = "RME Hammerfall HDSP 9652";
5036 hdsp->ss_in_channels = hdsp->ss_out_channels = H9652_SS_CHANNELS;
5037 hdsp->ds_in_channels = hdsp->ds_out_channels = H9652_DS_CHANNELS;
5041 status = hdsp_read(hdsp, HDSP_statusRegister);
5042 /* HDSP_AEBx bits are low when AEB are connected */
5043 aebi_channels = (status & HDSP_AEBI) ? 0 : 4;
5044 aebo_channels = (status & HDSP_AEBO) ? 0 : 4;
5045 hdsp->card_name = "RME Hammerfall HDSP 9632";
5046 hdsp->ss_in_channels = H9632_SS_CHANNELS+aebi_channels;
5047 hdsp->ds_in_channels = H9632_DS_CHANNELS+aebi_channels;
5048 hdsp->qs_in_channels = H9632_QS_CHANNELS+aebi_channels;
5049 hdsp->ss_out_channels = H9632_SS_CHANNELS+aebo_channels;
5050 hdsp->ds_out_channels = H9632_DS_CHANNELS+aebo_channels;
5051 hdsp->qs_out_channels = H9632_QS_CHANNELS+aebo_channels;
5052 /* Disable loopback of output channels, as the set function
5053 * only sets on a change we fake all bits (channels) as enabled.
5055 hdsp->io_loopback = 0xffffffff;
5056 for (i = 0; i < hdsp->max_channels; ++i)
5057 hdsp_loopback_set(hdsp, i, false);
5061 hdsp->card_name = "RME Hammerfall DSP + Multiface";
5062 hdsp->ss_in_channels = hdsp->ss_out_channels = MULTIFACE_SS_CHANNELS;
5063 hdsp->ds_in_channels = hdsp->ds_out_channels = MULTIFACE_DS_CHANNELS;
5067 hdsp->card_name = "RME Hammerfall DSP + RPM";
5068 hdsp->ss_in_channels = RPM_CHANNELS-1;
5069 hdsp->ss_out_channels = RPM_CHANNELS;
5070 hdsp->ds_in_channels = RPM_CHANNELS-1;
5071 hdsp->ds_out_channels = RPM_CHANNELS;
5075 /* should never get here */
5080 static void snd_hdsp_initialize_midi_flush (struct hdsp *hdsp)
5082 snd_hdsp_flush_midi_input (hdsp, 0);
5083 snd_hdsp_flush_midi_input (hdsp, 1);
5086 static int snd_hdsp_create_alsa_devices(struct snd_card *card, struct hdsp *hdsp)
5090 if ((err = snd_hdsp_create_pcm(card, hdsp)) < 0) {
5092 "Error creating pcm interface\n");
5097 if ((err = snd_hdsp_create_midi(card, hdsp, 0)) < 0) {
5099 "Error creating first midi interface\n");
5103 if (hdsp->io_type == Digiface || hdsp->io_type == H9652) {
5104 if ((err = snd_hdsp_create_midi(card, hdsp, 1)) < 0) {
5106 "Error creating second midi interface\n");
5111 if ((err = snd_hdsp_create_controls(card, hdsp)) < 0) {
5113 "Error creating ctl interface\n");
5117 snd_hdsp_proc_init(hdsp);
5119 hdsp->system_sample_rate = -1;
5120 hdsp->playback_pid = -1;
5121 hdsp->capture_pid = -1;
5122 hdsp->capture_substream = NULL;
5123 hdsp->playback_substream = NULL;
5125 if ((err = snd_hdsp_set_defaults(hdsp)) < 0) {
5127 "Error setting default values\n");
5131 if (!(hdsp->state & HDSP_InitializationComplete)) {
5132 strcpy(card->shortname, "Hammerfall DSP");
5133 sprintf(card->longname, "%s at 0x%lx, irq %d", hdsp->card_name,
5134 hdsp->port, hdsp->irq);
5136 if ((err = snd_card_register(card)) < 0) {
5138 "error registering card\n");
5141 hdsp->state |= HDSP_InitializationComplete;
5147 /* load firmware via hotplug fw loader */
5148 static int hdsp_request_fw_loader(struct hdsp *hdsp)
5151 const struct firmware *fw;
5154 if (hdsp->io_type == H9652 || hdsp->io_type == H9632)
5156 if (hdsp->io_type == Undefined) {
5157 if ((err = hdsp_get_iobox_version(hdsp)) < 0)
5159 if (hdsp->io_type == H9652 || hdsp->io_type == H9632)
5163 /* caution: max length of firmware filename is 30! */
5164 switch (hdsp->io_type) {
5166 fwfile = "rpm_firmware.bin";
5169 if (hdsp->firmware_rev == 0xa)
5170 fwfile = "multiface_firmware.bin";
5172 fwfile = "multiface_firmware_rev11.bin";
5175 if (hdsp->firmware_rev == 0xa)
5176 fwfile = "digiface_firmware.bin";
5178 fwfile = "digiface_firmware_rev11.bin";
5181 dev_err(hdsp->card->dev,
5182 "invalid io_type %d\n", hdsp->io_type);
5186 if (request_firmware(&fw, fwfile, &hdsp->pci->dev)) {
5187 dev_err(hdsp->card->dev,
5188 "cannot load firmware %s\n", fwfile);
5191 if (fw->size < HDSP_FIRMWARE_SIZE) {
5192 dev_err(hdsp->card->dev,
5193 "too short firmware size %d (expected %d)\n",
5194 (int)fw->size, HDSP_FIRMWARE_SIZE);
5195 release_firmware(fw);
5199 hdsp->firmware = fw;
5201 hdsp->state |= HDSP_FirmwareCached;
5203 if ((err = snd_hdsp_load_firmware_from_cache(hdsp)) < 0)
5206 if (!(hdsp->state & HDSP_InitializationComplete)) {
5207 if ((err = snd_hdsp_enable_io(hdsp)) < 0)
5210 if ((err = snd_hdsp_create_hwdep(hdsp->card, hdsp)) < 0) {
5211 dev_err(hdsp->card->dev,
5212 "error creating hwdep device\n");
5215 snd_hdsp_initialize_channels(hdsp);
5216 snd_hdsp_initialize_midi_flush(hdsp);
5217 if ((err = snd_hdsp_create_alsa_devices(hdsp->card, hdsp)) < 0) {
5218 dev_err(hdsp->card->dev,
5219 "error creating alsa devices\n");
5226 static int snd_hdsp_create(struct snd_card *card,
5229 struct pci_dev *pci = hdsp->pci;
5236 hdsp->midi[0].rmidi = NULL;
5237 hdsp->midi[1].rmidi = NULL;
5238 hdsp->midi[0].input = NULL;
5239 hdsp->midi[1].input = NULL;
5240 hdsp->midi[0].output = NULL;
5241 hdsp->midi[1].output = NULL;
5242 hdsp->midi[0].pending = 0;
5243 hdsp->midi[1].pending = 0;
5244 spin_lock_init(&hdsp->midi[0].lock);
5245 spin_lock_init(&hdsp->midi[1].lock);
5246 hdsp->iobase = NULL;
5247 hdsp->control_register = 0;
5248 hdsp->control2_register = 0;
5249 hdsp->io_type = Undefined;
5250 hdsp->max_channels = 26;
5254 spin_lock_init(&hdsp->lock);
5256 INIT_WORK(&hdsp->midi_work, hdsp_midi_work);
5258 pci_read_config_word(hdsp->pci, PCI_CLASS_REVISION, &hdsp->firmware_rev);
5259 hdsp->firmware_rev &= 0xff;
5261 /* From Martin Bjoernsen :
5262 "It is important that the card's latency timer register in
5263 the PCI configuration space is set to a value much larger
5264 than 0 by the computer's BIOS or the driver.
5265 The windows driver always sets this 8 bit register [...]
5266 to its maximum 255 to avoid problems with some computers."
5268 pci_write_config_byte(hdsp->pci, PCI_LATENCY_TIMER, 0xFF);
5270 strcpy(card->driver, "H-DSP");
5271 strcpy(card->mixername, "Xilinx FPGA");
5273 if (hdsp->firmware_rev < 0xa)
5275 else if (hdsp->firmware_rev < 0x64)
5276 hdsp->card_name = "RME Hammerfall DSP";
5277 else if (hdsp->firmware_rev < 0x96) {
5278 hdsp->card_name = "RME HDSP 9652";
5281 hdsp->card_name = "RME HDSP 9632";
5282 hdsp->max_channels = 16;
5286 if ((err = pci_enable_device(pci)) < 0)
5289 pci_set_master(hdsp->pci);
5291 if ((err = pci_request_regions(pci, "hdsp")) < 0)
5293 hdsp->port = pci_resource_start(pci, 0);
5294 if ((hdsp->iobase = ioremap(hdsp->port, HDSP_IO_EXTENT)) == NULL) {
5295 dev_err(hdsp->card->dev, "unable to remap region 0x%lx-0x%lx\n",
5296 hdsp->port, hdsp->port + HDSP_IO_EXTENT - 1);
5300 if (request_irq(pci->irq, snd_hdsp_interrupt, IRQF_SHARED,
5301 KBUILD_MODNAME, hdsp)) {
5302 dev_err(hdsp->card->dev, "unable to use IRQ %d\n", pci->irq);
5306 hdsp->irq = pci->irq;
5307 card->sync_irq = hdsp->irq;
5308 hdsp->precise_ptr = 0;
5309 hdsp->use_midi_work = 1;
5310 hdsp->dds_value = 0;
5312 if ((err = snd_hdsp_initialize_memory(hdsp)) < 0)
5315 if (!is_9652 && !is_9632) {
5316 /* we wait a maximum of 10 seconds to let freshly
5317 * inserted cardbus cards do their hardware init */
5318 err = hdsp_wait_for_iobox(hdsp, 1000, 10);
5323 if ((hdsp_read (hdsp, HDSP_statusRegister) & HDSP_DllError) != 0) {
5324 if ((err = hdsp_request_fw_loader(hdsp)) < 0)
5325 /* we don't fail as this can happen
5326 if userspace is not ready for
5329 dev_err(hdsp->card->dev,
5330 "couldn't get firmware from userspace. try using hdsploader\n");
5332 /* init is complete, we return */
5334 /* we defer initialization */
5335 dev_info(hdsp->card->dev,
5336 "card initialization pending : waiting for firmware\n");
5337 if ((err = snd_hdsp_create_hwdep(card, hdsp)) < 0)
5341 dev_info(hdsp->card->dev,
5342 "Firmware already present, initializing card.\n");
5343 if (hdsp_read(hdsp, HDSP_status2Register) & HDSP_version2)
5344 hdsp->io_type = RPM;
5345 else if (hdsp_read(hdsp, HDSP_status2Register) & HDSP_version1)
5346 hdsp->io_type = Multiface;
5348 hdsp->io_type = Digiface;
5352 if ((err = snd_hdsp_enable_io(hdsp)) != 0)
5356 hdsp->io_type = H9652;
5359 hdsp->io_type = H9632;
5361 if ((err = snd_hdsp_create_hwdep(card, hdsp)) < 0)
5364 snd_hdsp_initialize_channels(hdsp);
5365 snd_hdsp_initialize_midi_flush(hdsp);
5367 hdsp->state |= HDSP_FirmwareLoaded;
5369 if ((err = snd_hdsp_create_alsa_devices(card, hdsp)) < 0)
5375 static int snd_hdsp_free(struct hdsp *hdsp)
5378 /* stop the audio, and cancel all interrupts */
5379 cancel_work_sync(&hdsp->midi_work);
5380 hdsp->control_register &= ~(HDSP_Start|HDSP_AudioInterruptEnable|HDSP_Midi0InterruptEnable|HDSP_Midi1InterruptEnable);
5381 hdsp_write (hdsp, HDSP_controlRegister, hdsp->control_register);
5385 free_irq(hdsp->irq, (void *)hdsp);
5387 snd_hdsp_free_buffers(hdsp);
5389 release_firmware(hdsp->firmware);
5390 vfree(hdsp->fw_uploaded);
5391 iounmap(hdsp->iobase);
5394 pci_release_regions(hdsp->pci);
5396 pci_disable_device(hdsp->pci);
5400 static void snd_hdsp_card_free(struct snd_card *card)
5402 struct hdsp *hdsp = card->private_data;
5405 snd_hdsp_free(hdsp);
5408 static int snd_hdsp_probe(struct pci_dev *pci,
5409 const struct pci_device_id *pci_id)
5413 struct snd_card *card;
5416 if (dev >= SNDRV_CARDS)
5423 err = snd_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE,
5424 sizeof(struct hdsp), &card);
5428 hdsp = card->private_data;
5429 card->private_free = snd_hdsp_card_free;
5432 err = snd_hdsp_create(card, hdsp);
5436 strcpy(card->shortname, "Hammerfall DSP");
5437 sprintf(card->longname, "%s at 0x%lx, irq %d", hdsp->card_name,
5438 hdsp->port, hdsp->irq);
5439 err = snd_card_register(card);
5442 snd_card_free(card);
5445 pci_set_drvdata(pci, card);
5450 static void snd_hdsp_remove(struct pci_dev *pci)
5452 snd_card_free(pci_get_drvdata(pci));
5455 static struct pci_driver hdsp_driver = {
5456 .name = KBUILD_MODNAME,
5457 .id_table = snd_hdsp_ids,
5458 .probe = snd_hdsp_probe,
5459 .remove = snd_hdsp_remove,
5462 module_pci_driver(hdsp_driver);