2 * ALSA driver for RME Hammerfall DSP audio interface(s)
4 * Copyright (c) 2002 Paul Davis
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 #include <linux/init.h>
25 #include <linux/delay.h>
26 #include <linux/interrupt.h>
27 #include <linux/pci.h>
28 #include <linux/firmware.h>
29 #include <linux/module.h>
30 #include <linux/math64.h>
31 #include <linux/vmalloc.h>
33 #include <sound/core.h>
34 #include <sound/control.h>
35 #include <sound/pcm.h>
36 #include <sound/info.h>
37 #include <sound/asoundef.h>
38 #include <sound/rawmidi.h>
39 #include <sound/hwdep.h>
40 #include <sound/initval.h>
41 #include <sound/hdsp.h>
43 #include <asm/byteorder.h>
44 #include <asm/current.h>
47 static int index
[SNDRV_CARDS
] = SNDRV_DEFAULT_IDX
; /* Index 0-MAX */
48 static char *id
[SNDRV_CARDS
] = SNDRV_DEFAULT_STR
; /* ID for this card */
49 static bool enable
[SNDRV_CARDS
] = SNDRV_DEFAULT_ENABLE_PNP
; /* Enable this card */
51 module_param_array(index
, int, NULL
, 0444);
52 MODULE_PARM_DESC(index
, "Index value for RME Hammerfall DSP interface.");
53 module_param_array(id
, charp
, NULL
, 0444);
54 MODULE_PARM_DESC(id
, "ID string for RME Hammerfall DSP interface.");
55 module_param_array(enable
, bool, NULL
, 0444);
56 MODULE_PARM_DESC(enable
, "Enable/disable specific Hammerfall DSP soundcards.");
57 MODULE_AUTHOR("Paul Davis <paul@linuxaudiosystems.com>, Marcus Andersson, Thomas Charbonnel <thomas@undata.org>");
58 MODULE_DESCRIPTION("RME Hammerfall DSP");
59 MODULE_LICENSE("GPL");
60 MODULE_SUPPORTED_DEVICE("{{RME Hammerfall-DSP},"
63 MODULE_FIRMWARE("rpm_firmware.bin");
64 MODULE_FIRMWARE("multiface_firmware.bin");
65 MODULE_FIRMWARE("multiface_firmware_rev11.bin");
66 MODULE_FIRMWARE("digiface_firmware.bin");
67 MODULE_FIRMWARE("digiface_firmware_rev11.bin");
69 #define HDSP_MAX_CHANNELS 26
70 #define HDSP_MAX_DS_CHANNELS 14
71 #define HDSP_MAX_QS_CHANNELS 8
72 #define DIGIFACE_SS_CHANNELS 26
73 #define DIGIFACE_DS_CHANNELS 14
74 #define MULTIFACE_SS_CHANNELS 18
75 #define MULTIFACE_DS_CHANNELS 14
76 #define H9652_SS_CHANNELS 26
77 #define H9652_DS_CHANNELS 14
78 /* This does not include possible Analog Extension Boards
79 AEBs are detected at card initialization
81 #define H9632_SS_CHANNELS 12
82 #define H9632_DS_CHANNELS 8
83 #define H9632_QS_CHANNELS 4
84 #define RPM_CHANNELS 6
86 /* Write registers. These are defined as byte-offsets from the iobase value.
88 #define HDSP_resetPointer 0
89 #define HDSP_freqReg 0
90 #define HDSP_outputBufferAddress 32
91 #define HDSP_inputBufferAddress 36
92 #define HDSP_controlRegister 64
93 #define HDSP_interruptConfirmation 96
94 #define HDSP_outputEnable 128
95 #define HDSP_control2Reg 256
96 #define HDSP_midiDataOut0 352
97 #define HDSP_midiDataOut1 356
98 #define HDSP_fifoData 368
99 #define HDSP_inputEnable 384
101 /* Read registers. These are defined as byte-offsets from the iobase value
104 #define HDSP_statusRegister 0
105 #define HDSP_timecode 128
106 #define HDSP_status2Register 192
107 #define HDSP_midiDataIn0 360
108 #define HDSP_midiDataIn1 364
109 #define HDSP_midiStatusOut0 384
110 #define HDSP_midiStatusOut1 388
111 #define HDSP_midiStatusIn0 392
112 #define HDSP_midiStatusIn1 396
113 #define HDSP_fifoStatus 400
115 /* the meters are regular i/o-mapped registers, but offset
116 considerably from the rest. the peak registers are reset
117 when read; the least-significant 4 bits are full-scale counters;
118 the actual peak value is in the most-significant 24 bits.
121 #define HDSP_playbackPeakLevel 4096 /* 26 * 32 bit values */
122 #define HDSP_inputPeakLevel 4224 /* 26 * 32 bit values */
123 #define HDSP_outputPeakLevel 4352 /* (26+2) * 32 bit values */
124 #define HDSP_playbackRmsLevel 4612 /* 26 * 64 bit values */
125 #define HDSP_inputRmsLevel 4868 /* 26 * 64 bit values */
128 /* This is for H9652 cards
129 Peak values are read downward from the base
130 Rms values are read upward
131 There are rms values for the outputs too
132 26*3 values are read in ss mode
133 14*3 in ds mode, with no gap between values
135 #define HDSP_9652_peakBase 7164
136 #define HDSP_9652_rmsBase 4096
138 /* c.f. the hdsp_9632_meters_t struct */
139 #define HDSP_9632_metersBase 4096
141 #define HDSP_IO_EXTENT 7168
143 /* control2 register bits */
145 #define HDSP_TMS 0x01
146 #define HDSP_TCK 0x02
147 #define HDSP_TDI 0x04
148 #define HDSP_JTAG 0x08
149 #define HDSP_PWDN 0x10
150 #define HDSP_PROGRAM 0x020
151 #define HDSP_CONFIG_MODE_0 0x040
152 #define HDSP_CONFIG_MODE_1 0x080
153 #define HDSP_VERSION_BIT (0x100 | HDSP_S_LOAD)
154 #define HDSP_BIGENDIAN_MODE 0x200
155 #define HDSP_RD_MULTIPLE 0x400
156 #define HDSP_9652_ENABLE_MIXER 0x800
157 #define HDSP_S200 0x800
158 #define HDSP_S300 (0x100 | HDSP_S200) /* dummy, purpose of 0x100 unknown */
159 #define HDSP_CYCLIC_MODE 0x1000
160 #define HDSP_TDO 0x10000000
162 #define HDSP_S_PROGRAM (HDSP_CYCLIC_MODE|HDSP_PROGRAM|HDSP_CONFIG_MODE_0)
163 #define HDSP_S_LOAD (HDSP_CYCLIC_MODE|HDSP_PROGRAM|HDSP_CONFIG_MODE_1)
165 /* Control Register bits */
167 #define HDSP_Start (1<<0) /* start engine */
168 #define HDSP_Latency0 (1<<1) /* buffer size = 2^n where n is defined by Latency{2,1,0} */
169 #define HDSP_Latency1 (1<<2) /* [ see above ] */
170 #define HDSP_Latency2 (1<<3) /* [ see above ] */
171 #define HDSP_ClockModeMaster (1<<4) /* 1=Master, 0=Slave/Autosync */
172 #define HDSP_AudioInterruptEnable (1<<5) /* what do you think ? */
173 #define HDSP_Frequency0 (1<<6) /* 0=44.1kHz/88.2kHz/176.4kHz 1=48kHz/96kHz/192kHz */
174 #define HDSP_Frequency1 (1<<7) /* 0=32kHz/64kHz/128kHz */
175 #define HDSP_DoubleSpeed (1<<8) /* 0=normal speed, 1=double speed */
176 #define HDSP_SPDIFProfessional (1<<9) /* 0=consumer, 1=professional */
177 #define HDSP_SPDIFEmphasis (1<<10) /* 0=none, 1=on */
178 #define HDSP_SPDIFNonAudio (1<<11) /* 0=off, 1=on */
179 #define HDSP_SPDIFOpticalOut (1<<12) /* 1=use 1st ADAT connector for SPDIF, 0=do not */
180 #define HDSP_SyncRef2 (1<<13)
181 #define HDSP_SPDIFInputSelect0 (1<<14)
182 #define HDSP_SPDIFInputSelect1 (1<<15)
183 #define HDSP_SyncRef0 (1<<16)
184 #define HDSP_SyncRef1 (1<<17)
185 #define HDSP_AnalogExtensionBoard (1<<18) /* For H9632 cards */
186 #define HDSP_XLRBreakoutCable (1<<20) /* For H9632 cards */
187 #define HDSP_Midi0InterruptEnable (1<<22)
188 #define HDSP_Midi1InterruptEnable (1<<23)
189 #define HDSP_LineOut (1<<24)
190 #define HDSP_ADGain0 (1<<25) /* From here : H9632 specific */
191 #define HDSP_ADGain1 (1<<26)
192 #define HDSP_DAGain0 (1<<27)
193 #define HDSP_DAGain1 (1<<28)
194 #define HDSP_PhoneGain0 (1<<29)
195 #define HDSP_PhoneGain1 (1<<30)
196 #define HDSP_QuadSpeed (1<<31)
198 /* RPM uses some of the registers for special purposes */
199 #define HDSP_RPM_Inp12 0x04A00
200 #define HDSP_RPM_Inp12_Phon_6dB 0x00800 /* Dolby */
201 #define HDSP_RPM_Inp12_Phon_0dB 0x00000 /* .. */
202 #define HDSP_RPM_Inp12_Phon_n6dB 0x04000 /* inp_0 */
203 #define HDSP_RPM_Inp12_Line_0dB 0x04200 /* Dolby+PRO */
204 #define HDSP_RPM_Inp12_Line_n6dB 0x00200 /* PRO */
206 #define HDSP_RPM_Inp34 0x32000
207 #define HDSP_RPM_Inp34_Phon_6dB 0x20000 /* SyncRef1 */
208 #define HDSP_RPM_Inp34_Phon_0dB 0x00000 /* .. */
209 #define HDSP_RPM_Inp34_Phon_n6dB 0x02000 /* SyncRef2 */
210 #define HDSP_RPM_Inp34_Line_0dB 0x30000 /* SyncRef1+SyncRef0 */
211 #define HDSP_RPM_Inp34_Line_n6dB 0x10000 /* SyncRef0 */
213 #define HDSP_RPM_Bypass 0x01000
215 #define HDSP_RPM_Disconnect 0x00001
217 #define HDSP_ADGainMask (HDSP_ADGain0|HDSP_ADGain1)
218 #define HDSP_ADGainMinus10dBV HDSP_ADGainMask
219 #define HDSP_ADGainPlus4dBu (HDSP_ADGain0)
220 #define HDSP_ADGainLowGain 0
222 #define HDSP_DAGainMask (HDSP_DAGain0|HDSP_DAGain1)
223 #define HDSP_DAGainHighGain HDSP_DAGainMask
224 #define HDSP_DAGainPlus4dBu (HDSP_DAGain0)
225 #define HDSP_DAGainMinus10dBV 0
227 #define HDSP_PhoneGainMask (HDSP_PhoneGain0|HDSP_PhoneGain1)
228 #define HDSP_PhoneGain0dB HDSP_PhoneGainMask
229 #define HDSP_PhoneGainMinus6dB (HDSP_PhoneGain0)
230 #define HDSP_PhoneGainMinus12dB 0
232 #define HDSP_LatencyMask (HDSP_Latency0|HDSP_Latency1|HDSP_Latency2)
233 #define HDSP_FrequencyMask (HDSP_Frequency0|HDSP_Frequency1|HDSP_DoubleSpeed|HDSP_QuadSpeed)
235 #define HDSP_SPDIFInputMask (HDSP_SPDIFInputSelect0|HDSP_SPDIFInputSelect1)
236 #define HDSP_SPDIFInputADAT1 0
237 #define HDSP_SPDIFInputCoaxial (HDSP_SPDIFInputSelect0)
238 #define HDSP_SPDIFInputCdrom (HDSP_SPDIFInputSelect1)
239 #define HDSP_SPDIFInputAES (HDSP_SPDIFInputSelect0|HDSP_SPDIFInputSelect1)
241 #define HDSP_SyncRefMask (HDSP_SyncRef0|HDSP_SyncRef1|HDSP_SyncRef2)
242 #define HDSP_SyncRef_ADAT1 0
243 #define HDSP_SyncRef_ADAT2 (HDSP_SyncRef0)
244 #define HDSP_SyncRef_ADAT3 (HDSP_SyncRef1)
245 #define HDSP_SyncRef_SPDIF (HDSP_SyncRef0|HDSP_SyncRef1)
246 #define HDSP_SyncRef_WORD (HDSP_SyncRef2)
247 #define HDSP_SyncRef_ADAT_SYNC (HDSP_SyncRef0|HDSP_SyncRef2)
249 /* Sample Clock Sources */
251 #define HDSP_CLOCK_SOURCE_AUTOSYNC 0
252 #define HDSP_CLOCK_SOURCE_INTERNAL_32KHZ 1
253 #define HDSP_CLOCK_SOURCE_INTERNAL_44_1KHZ 2
254 #define HDSP_CLOCK_SOURCE_INTERNAL_48KHZ 3
255 #define HDSP_CLOCK_SOURCE_INTERNAL_64KHZ 4
256 #define HDSP_CLOCK_SOURCE_INTERNAL_88_2KHZ 5
257 #define HDSP_CLOCK_SOURCE_INTERNAL_96KHZ 6
258 #define HDSP_CLOCK_SOURCE_INTERNAL_128KHZ 7
259 #define HDSP_CLOCK_SOURCE_INTERNAL_176_4KHZ 8
260 #define HDSP_CLOCK_SOURCE_INTERNAL_192KHZ 9
262 /* Preferred sync reference choices - used by "pref_sync_ref" control switch */
264 #define HDSP_SYNC_FROM_WORD 0
265 #define HDSP_SYNC_FROM_SPDIF 1
266 #define HDSP_SYNC_FROM_ADAT1 2
267 #define HDSP_SYNC_FROM_ADAT_SYNC 3
268 #define HDSP_SYNC_FROM_ADAT2 4
269 #define HDSP_SYNC_FROM_ADAT3 5
271 /* SyncCheck status */
273 #define HDSP_SYNC_CHECK_NO_LOCK 0
274 #define HDSP_SYNC_CHECK_LOCK 1
275 #define HDSP_SYNC_CHECK_SYNC 2
277 /* AutoSync references - used by "autosync_ref" control switch */
279 #define HDSP_AUTOSYNC_FROM_WORD 0
280 #define HDSP_AUTOSYNC_FROM_ADAT_SYNC 1
281 #define HDSP_AUTOSYNC_FROM_SPDIF 2
282 #define HDSP_AUTOSYNC_FROM_NONE 3
283 #define HDSP_AUTOSYNC_FROM_ADAT1 4
284 #define HDSP_AUTOSYNC_FROM_ADAT2 5
285 #define HDSP_AUTOSYNC_FROM_ADAT3 6
287 /* Possible sources of S/PDIF input */
289 #define HDSP_SPDIFIN_OPTICAL 0 /* optical (ADAT1) */
290 #define HDSP_SPDIFIN_COAXIAL 1 /* coaxial (RCA) */
291 #define HDSP_SPDIFIN_INTERNAL 2 /* internal (CDROM) */
292 #define HDSP_SPDIFIN_AES 3 /* xlr for H9632 (AES)*/
294 #define HDSP_Frequency32KHz HDSP_Frequency0
295 #define HDSP_Frequency44_1KHz HDSP_Frequency1
296 #define HDSP_Frequency48KHz (HDSP_Frequency1|HDSP_Frequency0)
297 #define HDSP_Frequency64KHz (HDSP_DoubleSpeed|HDSP_Frequency0)
298 #define HDSP_Frequency88_2KHz (HDSP_DoubleSpeed|HDSP_Frequency1)
299 #define HDSP_Frequency96KHz (HDSP_DoubleSpeed|HDSP_Frequency1|HDSP_Frequency0)
300 /* For H9632 cards */
301 #define HDSP_Frequency128KHz (HDSP_QuadSpeed|HDSP_DoubleSpeed|HDSP_Frequency0)
302 #define HDSP_Frequency176_4KHz (HDSP_QuadSpeed|HDSP_DoubleSpeed|HDSP_Frequency1)
303 #define HDSP_Frequency192KHz (HDSP_QuadSpeed|HDSP_DoubleSpeed|HDSP_Frequency1|HDSP_Frequency0)
304 /* RME says n = 104857600000000, but in the windows MADI driver, I see:
305 return 104857600000000 / rate; // 100 MHz
306 return 110100480000000 / rate; // 105 MHz
308 #define DDS_NUMERATOR 104857600000000ULL; /* = 2^20 * 10^8 */
310 #define hdsp_encode_latency(x) (((x)<<1) & HDSP_LatencyMask)
311 #define hdsp_decode_latency(x) (((x) & HDSP_LatencyMask)>>1)
313 #define hdsp_encode_spdif_in(x) (((x)&0x3)<<14)
314 #define hdsp_decode_spdif_in(x) (((x)>>14)&0x3)
316 /* Status Register bits */
318 #define HDSP_audioIRQPending (1<<0)
319 #define HDSP_Lock2 (1<<1) /* this is for Digiface and H9652 */
320 #define HDSP_spdifFrequency3 HDSP_Lock2 /* this is for H9632 only */
321 #define HDSP_Lock1 (1<<2)
322 #define HDSP_Lock0 (1<<3)
323 #define HDSP_SPDIFSync (1<<4)
324 #define HDSP_TimecodeLock (1<<5)
325 #define HDSP_BufferPositionMask 0x000FFC0 /* Bit 6..15 : h/w buffer pointer */
326 #define HDSP_Sync2 (1<<16)
327 #define HDSP_Sync1 (1<<17)
328 #define HDSP_Sync0 (1<<18)
329 #define HDSP_DoubleSpeedStatus (1<<19)
330 #define HDSP_ConfigError (1<<20)
331 #define HDSP_DllError (1<<21)
332 #define HDSP_spdifFrequency0 (1<<22)
333 #define HDSP_spdifFrequency1 (1<<23)
334 #define HDSP_spdifFrequency2 (1<<24)
335 #define HDSP_SPDIFErrorFlag (1<<25)
336 #define HDSP_BufferID (1<<26)
337 #define HDSP_TimecodeSync (1<<27)
338 #define HDSP_AEBO (1<<28) /* H9632 specific Analog Extension Boards */
339 #define HDSP_AEBI (1<<29) /* 0 = present, 1 = absent */
340 #define HDSP_midi0IRQPending (1<<30)
341 #define HDSP_midi1IRQPending (1<<31)
343 #define HDSP_spdifFrequencyMask (HDSP_spdifFrequency0|HDSP_spdifFrequency1|HDSP_spdifFrequency2)
344 #define HDSP_spdifFrequencyMask_9632 (HDSP_spdifFrequency0|\
345 HDSP_spdifFrequency1|\
346 HDSP_spdifFrequency2|\
347 HDSP_spdifFrequency3)
349 #define HDSP_spdifFrequency32KHz (HDSP_spdifFrequency0)
350 #define HDSP_spdifFrequency44_1KHz (HDSP_spdifFrequency1)
351 #define HDSP_spdifFrequency48KHz (HDSP_spdifFrequency0|HDSP_spdifFrequency1)
353 #define HDSP_spdifFrequency64KHz (HDSP_spdifFrequency2)
354 #define HDSP_spdifFrequency88_2KHz (HDSP_spdifFrequency0|HDSP_spdifFrequency2)
355 #define HDSP_spdifFrequency96KHz (HDSP_spdifFrequency2|HDSP_spdifFrequency1)
357 /* This is for H9632 cards */
358 #define HDSP_spdifFrequency128KHz (HDSP_spdifFrequency0|\
359 HDSP_spdifFrequency1|\
360 HDSP_spdifFrequency2)
361 #define HDSP_spdifFrequency176_4KHz HDSP_spdifFrequency3
362 #define HDSP_spdifFrequency192KHz (HDSP_spdifFrequency3|HDSP_spdifFrequency0)
364 /* Status2 Register bits */
366 #define HDSP_version0 (1<<0)
367 #define HDSP_version1 (1<<1)
368 #define HDSP_version2 (1<<2)
369 #define HDSP_wc_lock (1<<3)
370 #define HDSP_wc_sync (1<<4)
371 #define HDSP_inp_freq0 (1<<5)
372 #define HDSP_inp_freq1 (1<<6)
373 #define HDSP_inp_freq2 (1<<7)
374 #define HDSP_SelSyncRef0 (1<<8)
375 #define HDSP_SelSyncRef1 (1<<9)
376 #define HDSP_SelSyncRef2 (1<<10)
378 #define HDSP_wc_valid (HDSP_wc_lock|HDSP_wc_sync)
380 #define HDSP_systemFrequencyMask (HDSP_inp_freq0|HDSP_inp_freq1|HDSP_inp_freq2)
381 #define HDSP_systemFrequency32 (HDSP_inp_freq0)
382 #define HDSP_systemFrequency44_1 (HDSP_inp_freq1)
383 #define HDSP_systemFrequency48 (HDSP_inp_freq0|HDSP_inp_freq1)
384 #define HDSP_systemFrequency64 (HDSP_inp_freq2)
385 #define HDSP_systemFrequency88_2 (HDSP_inp_freq0|HDSP_inp_freq2)
386 #define HDSP_systemFrequency96 (HDSP_inp_freq1|HDSP_inp_freq2)
387 /* FIXME : more values for 9632 cards ? */
389 #define HDSP_SelSyncRefMask (HDSP_SelSyncRef0|HDSP_SelSyncRef1|HDSP_SelSyncRef2)
390 #define HDSP_SelSyncRef_ADAT1 0
391 #define HDSP_SelSyncRef_ADAT2 (HDSP_SelSyncRef0)
392 #define HDSP_SelSyncRef_ADAT3 (HDSP_SelSyncRef1)
393 #define HDSP_SelSyncRef_SPDIF (HDSP_SelSyncRef0|HDSP_SelSyncRef1)
394 #define HDSP_SelSyncRef_WORD (HDSP_SelSyncRef2)
395 #define HDSP_SelSyncRef_ADAT_SYNC (HDSP_SelSyncRef0|HDSP_SelSyncRef2)
397 /* Card state flags */
399 #define HDSP_InitializationComplete (1<<0)
400 #define HDSP_FirmwareLoaded (1<<1)
401 #define HDSP_FirmwareCached (1<<2)
403 /* FIFO wait times, defined in terms of 1/10ths of msecs */
405 #define HDSP_LONG_WAIT 5000
406 #define HDSP_SHORT_WAIT 30
408 #define UNITY_GAIN 32768
409 #define MINUS_INFINITY_GAIN 0
411 /* the size of a substream (1 mono data stream) */
413 #define HDSP_CHANNEL_BUFFER_SAMPLES (16*1024)
414 #define HDSP_CHANNEL_BUFFER_BYTES (4*HDSP_CHANNEL_BUFFER_SAMPLES)
416 /* the size of the area we need to allocate for DMA transfers. the
417 size is the same regardless of the number of channels - the
418 Multiface still uses the same memory area.
420 Note that we allocate 1 more channel than is apparently needed
421 because the h/w seems to write 1 byte beyond the end of the last
425 #define HDSP_DMA_AREA_BYTES ((HDSP_MAX_CHANNELS+1) * HDSP_CHANNEL_BUFFER_BYTES)
426 #define HDSP_DMA_AREA_KILOBYTES (HDSP_DMA_AREA_BYTES/1024)
428 #define HDSP_FIRMWARE_SIZE (24413 * 4)
430 struct hdsp_9632_meters
{
432 u32 playback_peak
[16];
436 u32 input_rms_low
[16];
437 u32 playback_rms_low
[16];
438 u32 output_rms_low
[16];
440 u32 input_rms_high
[16];
441 u32 playback_rms_high
[16];
442 u32 output_rms_high
[16];
443 u32 xxx_rms_high
[16];
449 struct snd_rawmidi
*rmidi
;
450 struct snd_rawmidi_substream
*input
;
451 struct snd_rawmidi_substream
*output
;
452 char istimer
; /* timer in use */
453 struct timer_list timer
;
460 struct snd_pcm_substream
*capture_substream
;
461 struct snd_pcm_substream
*playback_substream
;
462 struct hdsp_midi midi
[2];
463 struct tasklet_struct midi_tasklet
;
464 int use_midi_tasklet
;
466 u32 control_register
; /* cached value */
467 u32 control2_register
; /* cached value */
469 u32 creg_spdif_stream
;
470 int clock_source_locked
;
471 char *card_name
; /* digiface/multiface/rpm */
472 enum HDSP_IO_Type io_type
; /* ditto, but for code use */
473 unsigned short firmware_rev
;
474 unsigned short state
; /* stores state bits */
475 const struct firmware
*firmware
;
477 size_t period_bytes
; /* guess what this is */
478 unsigned char max_channels
;
479 unsigned char qs_in_channels
; /* quad speed mode for H9632 */
480 unsigned char ds_in_channels
;
481 unsigned char ss_in_channels
; /* different for multiface/digiface */
482 unsigned char qs_out_channels
;
483 unsigned char ds_out_channels
;
484 unsigned char ss_out_channels
;
486 struct snd_dma_buffer capture_dma_buf
;
487 struct snd_dma_buffer playback_dma_buf
;
488 unsigned char *capture_buffer
; /* suitably aligned address */
489 unsigned char *playback_buffer
; /* suitably aligned address */
494 int system_sample_rate
;
499 void __iomem
*iobase
;
500 struct snd_card
*card
;
502 struct snd_hwdep
*hwdep
;
504 struct snd_kcontrol
*spdif_ctl
;
505 unsigned short mixer_matrix
[HDSP_MATRIX_MIXER_SIZE
];
506 unsigned int dds_value
; /* last value written to freq register */
509 /* These tables map the ALSA channels 1..N to the channels that we
510 need to use in order to find the relevant channel buffer. RME
511 refer to this kind of mapping as between "the ADAT channel and
512 the DMA channel." We index it using the logical audio channel,
513 and the value is the DMA channel (i.e. channel buffer number)
514 where the data for that channel can be read/written from/to.
517 static char channel_map_df_ss
[HDSP_MAX_CHANNELS
] = {
518 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
519 18, 19, 20, 21, 22, 23, 24, 25
522 static char channel_map_mf_ss
[HDSP_MAX_CHANNELS
] = { /* Multiface */
524 0, 1, 2, 3, 4, 5, 6, 7,
526 16, 17, 18, 19, 20, 21, 22, 23,
529 -1, -1, -1, -1, -1, -1, -1, -1
532 static char channel_map_ds
[HDSP_MAX_CHANNELS
] = {
533 /* ADAT channels are remapped */
534 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23,
535 /* channels 12 and 13 are S/PDIF */
537 /* others don't exist */
538 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
541 static char channel_map_H9632_ss
[HDSP_MAX_CHANNELS
] = {
543 0, 1, 2, 3, 4, 5, 6, 7,
548 /* AO4S-192 and AI4S-192 extension boards */
550 /* others don't exist */
551 -1, -1, -1, -1, -1, -1, -1, -1,
555 static char channel_map_H9632_ds
[HDSP_MAX_CHANNELS
] = {
562 /* AO4S-192 and AI4S-192 extension boards */
564 /* others don't exist */
565 -1, -1, -1, -1, -1, -1, -1, -1,
566 -1, -1, -1, -1, -1, -1
569 static char channel_map_H9632_qs
[HDSP_MAX_CHANNELS
] = {
570 /* ADAT is disabled in this mode */
575 /* AO4S-192 and AI4S-192 extension boards */
577 /* others don't exist */
578 -1, -1, -1, -1, -1, -1, -1, -1,
579 -1, -1, -1, -1, -1, -1, -1, -1,
583 static int snd_hammerfall_get_buffer(struct pci_dev
*pci
, struct snd_dma_buffer
*dmab
, size_t size
)
585 dmab
->dev
.type
= SNDRV_DMA_TYPE_DEV
;
586 dmab
->dev
.dev
= snd_dma_pci_data(pci
);
587 if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV
, snd_dma_pci_data(pci
),
593 static void snd_hammerfall_free_buffer(struct snd_dma_buffer
*dmab
, struct pci_dev
*pci
)
596 snd_dma_free_pages(dmab
);
600 static DEFINE_PCI_DEVICE_TABLE(snd_hdsp_ids
) = {
602 .vendor
= PCI_VENDOR_ID_XILINX
,
603 .device
= PCI_DEVICE_ID_XILINX_HAMMERFALL_DSP
,
604 .subvendor
= PCI_ANY_ID
,
605 .subdevice
= PCI_ANY_ID
,
606 }, /* RME Hammerfall-DSP */
610 MODULE_DEVICE_TABLE(pci
, snd_hdsp_ids
);
613 static int snd_hdsp_create_alsa_devices(struct snd_card
*card
, struct hdsp
*hdsp
);
614 static int snd_hdsp_create_pcm(struct snd_card
*card
, struct hdsp
*hdsp
);
615 static int snd_hdsp_enable_io (struct hdsp
*hdsp
);
616 static void snd_hdsp_initialize_midi_flush (struct hdsp
*hdsp
);
617 static void snd_hdsp_initialize_channels (struct hdsp
*hdsp
);
618 static int hdsp_fifo_wait(struct hdsp
*hdsp
, int count
, int timeout
);
619 static int hdsp_autosync_ref(struct hdsp
*hdsp
);
620 static int snd_hdsp_set_defaults(struct hdsp
*hdsp
);
621 static void snd_hdsp_9652_enable_mixer (struct hdsp
*hdsp
);
623 static int hdsp_playback_to_output_key (struct hdsp
*hdsp
, int in
, int out
)
625 switch (hdsp
->io_type
) {
630 if (hdsp
->firmware_rev
== 0xa)
631 return (64 * out
) + (32 + (in
));
633 return (52 * out
) + (26 + (in
));
635 return (32 * out
) + (16 + (in
));
637 return (52 * out
) + (26 + (in
));
641 static int hdsp_input_to_output_key (struct hdsp
*hdsp
, int in
, int out
)
643 switch (hdsp
->io_type
) {
648 if (hdsp
->firmware_rev
== 0xa)
649 return (64 * out
) + in
;
651 return (52 * out
) + in
;
653 return (32 * out
) + in
;
655 return (52 * out
) + in
;
659 static void hdsp_write(struct hdsp
*hdsp
, int reg
, int val
)
661 writel(val
, hdsp
->iobase
+ reg
);
664 static unsigned int hdsp_read(struct hdsp
*hdsp
, int reg
)
666 return readl (hdsp
->iobase
+ reg
);
669 static int hdsp_check_for_iobox (struct hdsp
*hdsp
)
673 if (hdsp
->io_type
== H9652
|| hdsp
->io_type
== H9632
) return 0;
674 for (i
= 0; i
< 500; i
++) {
675 if (0 == (hdsp_read(hdsp
, HDSP_statusRegister
) &
678 snd_printd("Hammerfall-DSP: IO box found after %d ms\n",
685 snd_printk(KERN_ERR
"Hammerfall-DSP: no IO box connected!\n");
686 hdsp
->state
&= ~HDSP_FirmwareLoaded
;
690 static int hdsp_wait_for_iobox(struct hdsp
*hdsp
, unsigned int loops
,
695 if (hdsp
->io_type
== H9652
|| hdsp
->io_type
== H9632
)
698 for (i
= 0; i
!= loops
; ++i
) {
699 if (hdsp_read(hdsp
, HDSP_statusRegister
) & HDSP_ConfigError
)
702 snd_printd("Hammerfall-DSP: iobox found after %ums!\n",
708 snd_printk("Hammerfall-DSP: no IO box connected!\n");
709 hdsp
->state
&= ~HDSP_FirmwareLoaded
;
713 static int snd_hdsp_load_firmware_from_cache(struct hdsp
*hdsp
) {
719 if (hdsp
->fw_uploaded
)
720 cache
= hdsp
->fw_uploaded
;
724 cache
= (u32
*)hdsp
->firmware
->data
;
729 if ((hdsp_read (hdsp
, HDSP_statusRegister
) & HDSP_DllError
) != 0) {
731 snd_printk ("Hammerfall-DSP: loading firmware\n");
733 hdsp_write (hdsp
, HDSP_control2Reg
, HDSP_S_PROGRAM
);
734 hdsp_write (hdsp
, HDSP_fifoData
, 0);
736 if (hdsp_fifo_wait (hdsp
, 0, HDSP_LONG_WAIT
)) {
737 snd_printk ("Hammerfall-DSP: timeout waiting for download preparation\n");
738 hdsp_write(hdsp
, HDSP_control2Reg
, HDSP_S200
);
742 hdsp_write (hdsp
, HDSP_control2Reg
, HDSP_S_LOAD
);
744 for (i
= 0; i
< HDSP_FIRMWARE_SIZE
/ 4; ++i
) {
745 hdsp_write(hdsp
, HDSP_fifoData
, cache
[i
]);
746 if (hdsp_fifo_wait (hdsp
, 127, HDSP_LONG_WAIT
)) {
747 snd_printk ("Hammerfall-DSP: timeout during firmware loading\n");
748 hdsp_write(hdsp
, HDSP_control2Reg
, HDSP_S200
);
753 hdsp_fifo_wait(hdsp
, 3, HDSP_LONG_WAIT
);
754 hdsp_write(hdsp
, HDSP_control2Reg
, HDSP_S200
);
757 #ifdef SNDRV_BIG_ENDIAN
758 hdsp
->control2_register
= HDSP_BIGENDIAN_MODE
;
760 hdsp
->control2_register
= 0;
762 hdsp_write (hdsp
, HDSP_control2Reg
, hdsp
->control2_register
);
763 snd_printk ("Hammerfall-DSP: finished firmware loading\n");
766 if (hdsp
->state
& HDSP_InitializationComplete
) {
767 snd_printk(KERN_INFO
"Hammerfall-DSP: firmware loaded from cache, restoring defaults\n");
768 spin_lock_irqsave(&hdsp
->lock
, flags
);
769 snd_hdsp_set_defaults(hdsp
);
770 spin_unlock_irqrestore(&hdsp
->lock
, flags
);
773 hdsp
->state
|= HDSP_FirmwareLoaded
;
778 static int hdsp_get_iobox_version (struct hdsp
*hdsp
)
780 if ((hdsp_read (hdsp
, HDSP_statusRegister
) & HDSP_DllError
) != 0) {
782 hdsp_write(hdsp
, HDSP_control2Reg
, HDSP_S_LOAD
);
783 hdsp_write(hdsp
, HDSP_fifoData
, 0);
785 if (hdsp_fifo_wait(hdsp
, 0, HDSP_SHORT_WAIT
) < 0) {
786 hdsp_write(hdsp
, HDSP_control2Reg
, HDSP_S300
);
787 hdsp_write(hdsp
, HDSP_control2Reg
, HDSP_S_LOAD
);
790 hdsp_write(hdsp
, HDSP_control2Reg
, HDSP_S200
| HDSP_PROGRAM
);
791 hdsp_write (hdsp
, HDSP_fifoData
, 0);
792 if (hdsp_fifo_wait(hdsp
, 0, HDSP_SHORT_WAIT
) < 0) {
793 hdsp
->io_type
= Multiface
;
794 snd_printk("Hammerfall-DSP: Multiface found\n");
798 hdsp_write(hdsp
, HDSP_control2Reg
, HDSP_S_LOAD
);
799 hdsp_write(hdsp
, HDSP_fifoData
, 0);
800 if (hdsp_fifo_wait(hdsp
, 0, HDSP_SHORT_WAIT
) == 0) {
801 hdsp
->io_type
= Digiface
;
802 snd_printk("Hammerfall-DSP: Digiface found\n");
806 hdsp_write(hdsp
, HDSP_control2Reg
, HDSP_S300
);
807 hdsp_write(hdsp
, HDSP_control2Reg
, HDSP_S_LOAD
);
808 hdsp_write(hdsp
, HDSP_fifoData
, 0);
809 if (hdsp_fifo_wait(hdsp
, 0, HDSP_SHORT_WAIT
) == 0) {
810 hdsp
->io_type
= Multiface
;
811 snd_printk("Hammerfall-DSP: Multiface found\n");
815 hdsp_write(hdsp
, HDSP_control2Reg
, HDSP_S300
);
816 hdsp_write(hdsp
, HDSP_control2Reg
, HDSP_S_LOAD
);
817 hdsp_write(hdsp
, HDSP_fifoData
, 0);
818 if (hdsp_fifo_wait(hdsp
, 0, HDSP_SHORT_WAIT
) < 0) {
819 hdsp
->io_type
= Multiface
;
820 snd_printk("Hammerfall-DSP: Multiface found\n");
825 snd_printk("Hammerfall-DSP: RPM found\n");
828 /* firmware was already loaded, get iobox type */
829 if (hdsp_read(hdsp
, HDSP_status2Register
) & HDSP_version2
)
831 else if (hdsp_read(hdsp
, HDSP_status2Register
) & HDSP_version1
)
832 hdsp
->io_type
= Multiface
;
834 hdsp
->io_type
= Digiface
;
840 static int hdsp_request_fw_loader(struct hdsp
*hdsp
);
842 static int hdsp_check_for_firmware (struct hdsp
*hdsp
, int load_on_demand
)
844 if (hdsp
->io_type
== H9652
|| hdsp
->io_type
== H9632
)
846 if ((hdsp_read (hdsp
, HDSP_statusRegister
) & HDSP_DllError
) != 0) {
847 hdsp
->state
&= ~HDSP_FirmwareLoaded
;
848 if (! load_on_demand
)
850 snd_printk(KERN_ERR
"Hammerfall-DSP: firmware not present.\n");
851 /* try to load firmware */
852 if (! (hdsp
->state
& HDSP_FirmwareCached
)) {
853 if (! hdsp_request_fw_loader(hdsp
))
856 "Hammerfall-DSP: No firmware loaded nor "
857 "cached, please upload firmware.\n");
860 if (snd_hdsp_load_firmware_from_cache(hdsp
) != 0) {
862 "Hammerfall-DSP: Firmware loading from "
863 "cache failed, please upload manually.\n");
871 static int hdsp_fifo_wait(struct hdsp
*hdsp
, int count
, int timeout
)
875 /* the fifoStatus registers reports on how many words
876 are available in the command FIFO.
879 for (i
= 0; i
< timeout
; i
++) {
881 if ((int)(hdsp_read (hdsp
, HDSP_fifoStatus
) & 0xff) <= count
)
884 /* not very friendly, but we only do this during a firmware
885 load and changing the mixer, so we just put up with it.
891 snd_printk ("Hammerfall-DSP: wait for FIFO status <= %d failed after %d iterations\n",
896 static int hdsp_read_gain (struct hdsp
*hdsp
, unsigned int addr
)
898 if (addr
>= HDSP_MATRIX_MIXER_SIZE
)
901 return hdsp
->mixer_matrix
[addr
];
904 static int hdsp_write_gain(struct hdsp
*hdsp
, unsigned int addr
, unsigned short data
)
908 if (addr
>= HDSP_MATRIX_MIXER_SIZE
)
911 if (hdsp
->io_type
== H9652
|| hdsp
->io_type
== H9632
) {
913 /* from martin bjornsen:
915 "You can only write dwords to the
916 mixer memory which contain two
917 mixer values in the low and high
918 word. So if you want to change
919 value 0 you have to read value 1
920 from the cache and write both to
921 the first dword in the mixer
925 if (hdsp
->io_type
== H9632
&& addr
>= 512)
928 if (hdsp
->io_type
== H9652
&& addr
>= 1352)
931 hdsp
->mixer_matrix
[addr
] = data
;
934 /* `addr' addresses a 16-bit wide address, but
935 the address space accessed via hdsp_write
936 uses byte offsets. put another way, addr
937 varies from 0 to 1351, but to access the
938 corresponding memory location, we need
939 to access 0 to 2703 ...
943 hdsp_write (hdsp
, 4096 + (ad
*4),
944 (hdsp
->mixer_matrix
[(addr
&0x7fe)+1] << 16) +
945 hdsp
->mixer_matrix
[addr
&0x7fe]);
951 ad
= (addr
<< 16) + data
;
953 if (hdsp_fifo_wait(hdsp
, 127, HDSP_LONG_WAIT
))
956 hdsp_write (hdsp
, HDSP_fifoData
, ad
);
957 hdsp
->mixer_matrix
[addr
] = data
;
964 static int snd_hdsp_use_is_exclusive(struct hdsp
*hdsp
)
969 spin_lock_irqsave(&hdsp
->lock
, flags
);
970 if ((hdsp
->playback_pid
!= hdsp
->capture_pid
) &&
971 (hdsp
->playback_pid
>= 0) && (hdsp
->capture_pid
>= 0))
973 spin_unlock_irqrestore(&hdsp
->lock
, flags
);
977 static int hdsp_spdif_sample_rate(struct hdsp
*hdsp
)
979 unsigned int status
= hdsp_read(hdsp
, HDSP_statusRegister
);
980 unsigned int rate_bits
= (status
& HDSP_spdifFrequencyMask
);
982 /* For the 9632, the mask is different */
983 if (hdsp
->io_type
== H9632
)
984 rate_bits
= (status
& HDSP_spdifFrequencyMask_9632
);
986 if (status
& HDSP_SPDIFErrorFlag
)
990 case HDSP_spdifFrequency32KHz
: return 32000;
991 case HDSP_spdifFrequency44_1KHz
: return 44100;
992 case HDSP_spdifFrequency48KHz
: return 48000;
993 case HDSP_spdifFrequency64KHz
: return 64000;
994 case HDSP_spdifFrequency88_2KHz
: return 88200;
995 case HDSP_spdifFrequency96KHz
: return 96000;
996 case HDSP_spdifFrequency128KHz
:
997 if (hdsp
->io_type
== H9632
) return 128000;
999 case HDSP_spdifFrequency176_4KHz
:
1000 if (hdsp
->io_type
== H9632
) return 176400;
1002 case HDSP_spdifFrequency192KHz
:
1003 if (hdsp
->io_type
== H9632
) return 192000;
1008 snd_printk ("Hammerfall-DSP: unknown spdif frequency status; bits = 0x%x, status = 0x%x\n", rate_bits
, status
);
1012 static int hdsp_external_sample_rate(struct hdsp
*hdsp
)
1014 unsigned int status2
= hdsp_read(hdsp
, HDSP_status2Register
);
1015 unsigned int rate_bits
= status2
& HDSP_systemFrequencyMask
;
1017 /* For the 9632 card, there seems to be no bit for indicating external
1018 * sample rate greater than 96kHz. The card reports the corresponding
1019 * single speed. So the best means seems to get spdif rate when
1020 * autosync reference is spdif */
1021 if (hdsp
->io_type
== H9632
&&
1022 hdsp_autosync_ref(hdsp
) == HDSP_AUTOSYNC_FROM_SPDIF
)
1023 return hdsp_spdif_sample_rate(hdsp
);
1025 switch (rate_bits
) {
1026 case HDSP_systemFrequency32
: return 32000;
1027 case HDSP_systemFrequency44_1
: return 44100;
1028 case HDSP_systemFrequency48
: return 48000;
1029 case HDSP_systemFrequency64
: return 64000;
1030 case HDSP_systemFrequency88_2
: return 88200;
1031 case HDSP_systemFrequency96
: return 96000;
1037 static void hdsp_compute_period_size(struct hdsp
*hdsp
)
1039 hdsp
->period_bytes
= 1 << ((hdsp_decode_latency(hdsp
->control_register
) + 8));
1042 static snd_pcm_uframes_t
hdsp_hw_pointer(struct hdsp
*hdsp
)
1046 position
= hdsp_read(hdsp
, HDSP_statusRegister
);
1048 if (!hdsp
->precise_ptr
)
1049 return (position
& HDSP_BufferID
) ? (hdsp
->period_bytes
/ 4) : 0;
1051 position
&= HDSP_BufferPositionMask
;
1053 position
&= (hdsp
->period_bytes
/2) - 1;
1057 static void hdsp_reset_hw_pointer(struct hdsp
*hdsp
)
1059 hdsp_write (hdsp
, HDSP_resetPointer
, 0);
1060 if (hdsp
->io_type
== H9632
&& hdsp
->firmware_rev
>= 152)
1061 /* HDSP_resetPointer = HDSP_freqReg, which is strange and
1062 * requires (?) to write again DDS value after a reset pointer
1063 * (at least, it works like this) */
1064 hdsp_write (hdsp
, HDSP_freqReg
, hdsp
->dds_value
);
1067 static void hdsp_start_audio(struct hdsp
*s
)
1069 s
->control_register
|= (HDSP_AudioInterruptEnable
| HDSP_Start
);
1070 hdsp_write(s
, HDSP_controlRegister
, s
->control_register
);
1073 static void hdsp_stop_audio(struct hdsp
*s
)
1075 s
->control_register
&= ~(HDSP_Start
| HDSP_AudioInterruptEnable
);
1076 hdsp_write(s
, HDSP_controlRegister
, s
->control_register
);
1079 static void hdsp_silence_playback(struct hdsp
*hdsp
)
1081 memset(hdsp
->playback_buffer
, 0, HDSP_DMA_AREA_BYTES
);
1084 static int hdsp_set_interrupt_interval(struct hdsp
*s
, unsigned int frames
)
1088 spin_lock_irq(&s
->lock
);
1097 s
->control_register
&= ~HDSP_LatencyMask
;
1098 s
->control_register
|= hdsp_encode_latency(n
);
1100 hdsp_write(s
, HDSP_controlRegister
, s
->control_register
);
1102 hdsp_compute_period_size(s
);
1104 spin_unlock_irq(&s
->lock
);
1109 static void hdsp_set_dds_value(struct hdsp
*hdsp
, int rate
)
1115 else if (rate
>= 56000)
1119 n
= div_u64(n
, rate
);
1120 /* n should be less than 2^32 for being written to FREQ register */
1121 snd_BUG_ON(n
>> 32);
1122 /* HDSP_freqReg and HDSP_resetPointer are the same, so keep the DDS
1123 value to write it after a reset */
1124 hdsp
->dds_value
= n
;
1125 hdsp_write(hdsp
, HDSP_freqReg
, hdsp
->dds_value
);
1128 static int hdsp_set_rate(struct hdsp
*hdsp
, int rate
, int called_internally
)
1130 int reject_if_open
= 0;
1134 /* ASSUMPTION: hdsp->lock is either held, or
1135 there is no need for it (e.g. during module
1139 if (!(hdsp
->control_register
& HDSP_ClockModeMaster
)) {
1140 if (called_internally
) {
1141 /* request from ctl or card initialization */
1142 snd_printk(KERN_ERR
"Hammerfall-DSP: device is not running as a clock master: cannot set sample rate.\n");
1145 /* hw_param request while in AutoSync mode */
1146 int external_freq
= hdsp_external_sample_rate(hdsp
);
1147 int spdif_freq
= hdsp_spdif_sample_rate(hdsp
);
1149 if ((spdif_freq
== external_freq
*2) && (hdsp_autosync_ref(hdsp
) >= HDSP_AUTOSYNC_FROM_ADAT1
))
1150 snd_printk(KERN_INFO
"Hammerfall-DSP: Detected ADAT in double speed mode\n");
1151 else if (hdsp
->io_type
== H9632
&& (spdif_freq
== external_freq
*4) && (hdsp_autosync_ref(hdsp
) >= HDSP_AUTOSYNC_FROM_ADAT1
))
1152 snd_printk(KERN_INFO
"Hammerfall-DSP: Detected ADAT in quad speed mode\n");
1153 else if (rate
!= external_freq
) {
1154 snd_printk(KERN_INFO
"Hammerfall-DSP: No AutoSync source for requested rate\n");
1160 current_rate
= hdsp
->system_sample_rate
;
1162 /* Changing from a "single speed" to a "double speed" rate is
1163 not allowed if any substreams are open. This is because
1164 such a change causes a shift in the location of
1165 the DMA buffers and a reduction in the number of available
1168 Note that a similar but essentially insoluble problem
1169 exists for externally-driven rate changes. All we can do
1170 is to flag rate changes in the read/write routines. */
1172 if (rate
> 96000 && hdsp
->io_type
!= H9632
)
1177 if (current_rate
> 48000)
1179 rate_bits
= HDSP_Frequency32KHz
;
1182 if (current_rate
> 48000)
1184 rate_bits
= HDSP_Frequency44_1KHz
;
1187 if (current_rate
> 48000)
1189 rate_bits
= HDSP_Frequency48KHz
;
1192 if (current_rate
<= 48000 || current_rate
> 96000)
1194 rate_bits
= HDSP_Frequency64KHz
;
1197 if (current_rate
<= 48000 || current_rate
> 96000)
1199 rate_bits
= HDSP_Frequency88_2KHz
;
1202 if (current_rate
<= 48000 || current_rate
> 96000)
1204 rate_bits
= HDSP_Frequency96KHz
;
1207 if (current_rate
< 128000)
1209 rate_bits
= HDSP_Frequency128KHz
;
1212 if (current_rate
< 128000)
1214 rate_bits
= HDSP_Frequency176_4KHz
;
1217 if (current_rate
< 128000)
1219 rate_bits
= HDSP_Frequency192KHz
;
1225 if (reject_if_open
&& (hdsp
->capture_pid
>= 0 || hdsp
->playback_pid
>= 0)) {
1226 snd_printk ("Hammerfall-DSP: cannot change speed mode (capture PID = %d, playback PID = %d)\n",
1228 hdsp
->playback_pid
);
1232 hdsp
->control_register
&= ~HDSP_FrequencyMask
;
1233 hdsp
->control_register
|= rate_bits
;
1234 hdsp_write(hdsp
, HDSP_controlRegister
, hdsp
->control_register
);
1236 /* For HDSP9632 rev 152, need to set DDS value in FREQ register */
1237 if (hdsp
->io_type
== H9632
&& hdsp
->firmware_rev
>= 152)
1238 hdsp_set_dds_value(hdsp
, rate
);
1240 if (rate
>= 128000) {
1241 hdsp
->channel_map
= channel_map_H9632_qs
;
1242 } else if (rate
> 48000) {
1243 if (hdsp
->io_type
== H9632
)
1244 hdsp
->channel_map
= channel_map_H9632_ds
;
1246 hdsp
->channel_map
= channel_map_ds
;
1248 switch (hdsp
->io_type
) {
1251 hdsp
->channel_map
= channel_map_mf_ss
;
1255 hdsp
->channel_map
= channel_map_df_ss
;
1258 hdsp
->channel_map
= channel_map_H9632_ss
;
1261 /* should never happen */
1266 hdsp
->system_sample_rate
= rate
;
1271 /*----------------------------------------------------------------------------
1273 ----------------------------------------------------------------------------*/
1275 static unsigned char snd_hdsp_midi_read_byte (struct hdsp
*hdsp
, int id
)
1277 /* the hardware already does the relevant bit-mask with 0xff */
1279 return hdsp_read(hdsp
, HDSP_midiDataIn1
);
1281 return hdsp_read(hdsp
, HDSP_midiDataIn0
);
1284 static void snd_hdsp_midi_write_byte (struct hdsp
*hdsp
, int id
, int val
)
1286 /* the hardware already does the relevant bit-mask with 0xff */
1288 hdsp_write(hdsp
, HDSP_midiDataOut1
, val
);
1290 hdsp_write(hdsp
, HDSP_midiDataOut0
, val
);
1293 static int snd_hdsp_midi_input_available (struct hdsp
*hdsp
, int id
)
1296 return (hdsp_read(hdsp
, HDSP_midiStatusIn1
) & 0xff);
1298 return (hdsp_read(hdsp
, HDSP_midiStatusIn0
) & 0xff);
1301 static int snd_hdsp_midi_output_possible (struct hdsp
*hdsp
, int id
)
1303 int fifo_bytes_used
;
1306 fifo_bytes_used
= hdsp_read(hdsp
, HDSP_midiStatusOut1
) & 0xff;
1308 fifo_bytes_used
= hdsp_read(hdsp
, HDSP_midiStatusOut0
) & 0xff;
1310 if (fifo_bytes_used
< 128)
1311 return 128 - fifo_bytes_used
;
1316 static void snd_hdsp_flush_midi_input (struct hdsp
*hdsp
, int id
)
1318 while (snd_hdsp_midi_input_available (hdsp
, id
))
1319 snd_hdsp_midi_read_byte (hdsp
, id
);
1322 static int snd_hdsp_midi_output_write (struct hdsp_midi
*hmidi
)
1324 unsigned long flags
;
1328 unsigned char buf
[128];
1330 /* Output is not interrupt driven */
1332 spin_lock_irqsave (&hmidi
->lock
, flags
);
1333 if (hmidi
->output
) {
1334 if (!snd_rawmidi_transmit_empty (hmidi
->output
)) {
1335 if ((n_pending
= snd_hdsp_midi_output_possible (hmidi
->hdsp
, hmidi
->id
)) > 0) {
1336 if (n_pending
> (int)sizeof (buf
))
1337 n_pending
= sizeof (buf
);
1339 if ((to_write
= snd_rawmidi_transmit (hmidi
->output
, buf
, n_pending
)) > 0) {
1340 for (i
= 0; i
< to_write
; ++i
)
1341 snd_hdsp_midi_write_byte (hmidi
->hdsp
, hmidi
->id
, buf
[i
]);
1346 spin_unlock_irqrestore (&hmidi
->lock
, flags
);
1350 static int snd_hdsp_midi_input_read (struct hdsp_midi
*hmidi
)
1352 unsigned char buf
[128]; /* this buffer is designed to match the MIDI input FIFO size */
1353 unsigned long flags
;
1357 spin_lock_irqsave (&hmidi
->lock
, flags
);
1358 if ((n_pending
= snd_hdsp_midi_input_available (hmidi
->hdsp
, hmidi
->id
)) > 0) {
1360 if (n_pending
> (int)sizeof (buf
))
1361 n_pending
= sizeof (buf
);
1362 for (i
= 0; i
< n_pending
; ++i
)
1363 buf
[i
] = snd_hdsp_midi_read_byte (hmidi
->hdsp
, hmidi
->id
);
1365 snd_rawmidi_receive (hmidi
->input
, buf
, n_pending
);
1367 /* flush the MIDI input FIFO */
1369 snd_hdsp_midi_read_byte (hmidi
->hdsp
, hmidi
->id
);
1374 hmidi
->hdsp
->control_register
|= HDSP_Midi1InterruptEnable
;
1376 hmidi
->hdsp
->control_register
|= HDSP_Midi0InterruptEnable
;
1377 hdsp_write(hmidi
->hdsp
, HDSP_controlRegister
, hmidi
->hdsp
->control_register
);
1378 spin_unlock_irqrestore (&hmidi
->lock
, flags
);
1379 return snd_hdsp_midi_output_write (hmidi
);
1382 static void snd_hdsp_midi_input_trigger(struct snd_rawmidi_substream
*substream
, int up
)
1385 struct hdsp_midi
*hmidi
;
1386 unsigned long flags
;
1389 hmidi
= (struct hdsp_midi
*) substream
->rmidi
->private_data
;
1391 ie
= hmidi
->id
? HDSP_Midi1InterruptEnable
: HDSP_Midi0InterruptEnable
;
1392 spin_lock_irqsave (&hdsp
->lock
, flags
);
1394 if (!(hdsp
->control_register
& ie
)) {
1395 snd_hdsp_flush_midi_input (hdsp
, hmidi
->id
);
1396 hdsp
->control_register
|= ie
;
1399 hdsp
->control_register
&= ~ie
;
1400 tasklet_kill(&hdsp
->midi_tasklet
);
1403 hdsp_write(hdsp
, HDSP_controlRegister
, hdsp
->control_register
);
1404 spin_unlock_irqrestore (&hdsp
->lock
, flags
);
1407 static void snd_hdsp_midi_output_timer(unsigned long data
)
1409 struct hdsp_midi
*hmidi
= (struct hdsp_midi
*) data
;
1410 unsigned long flags
;
1412 snd_hdsp_midi_output_write(hmidi
);
1413 spin_lock_irqsave (&hmidi
->lock
, flags
);
1415 /* this does not bump hmidi->istimer, because the
1416 kernel automatically removed the timer when it
1417 expired, and we are now adding it back, thus
1418 leaving istimer wherever it was set before.
1421 if (hmidi
->istimer
) {
1422 hmidi
->timer
.expires
= 1 + jiffies
;
1423 add_timer(&hmidi
->timer
);
1426 spin_unlock_irqrestore (&hmidi
->lock
, flags
);
1429 static void snd_hdsp_midi_output_trigger(struct snd_rawmidi_substream
*substream
, int up
)
1431 struct hdsp_midi
*hmidi
;
1432 unsigned long flags
;
1434 hmidi
= (struct hdsp_midi
*) substream
->rmidi
->private_data
;
1435 spin_lock_irqsave (&hmidi
->lock
, flags
);
1437 if (!hmidi
->istimer
) {
1438 init_timer(&hmidi
->timer
);
1439 hmidi
->timer
.function
= snd_hdsp_midi_output_timer
;
1440 hmidi
->timer
.data
= (unsigned long) hmidi
;
1441 hmidi
->timer
.expires
= 1 + jiffies
;
1442 add_timer(&hmidi
->timer
);
1446 if (hmidi
->istimer
&& --hmidi
->istimer
<= 0)
1447 del_timer (&hmidi
->timer
);
1449 spin_unlock_irqrestore (&hmidi
->lock
, flags
);
1451 snd_hdsp_midi_output_write(hmidi
);
1454 static int snd_hdsp_midi_input_open(struct snd_rawmidi_substream
*substream
)
1456 struct hdsp_midi
*hmidi
;
1458 hmidi
= (struct hdsp_midi
*) substream
->rmidi
->private_data
;
1459 spin_lock_irq (&hmidi
->lock
);
1460 snd_hdsp_flush_midi_input (hmidi
->hdsp
, hmidi
->id
);
1461 hmidi
->input
= substream
;
1462 spin_unlock_irq (&hmidi
->lock
);
1467 static int snd_hdsp_midi_output_open(struct snd_rawmidi_substream
*substream
)
1469 struct hdsp_midi
*hmidi
;
1471 hmidi
= (struct hdsp_midi
*) substream
->rmidi
->private_data
;
1472 spin_lock_irq (&hmidi
->lock
);
1473 hmidi
->output
= substream
;
1474 spin_unlock_irq (&hmidi
->lock
);
1479 static int snd_hdsp_midi_input_close(struct snd_rawmidi_substream
*substream
)
1481 struct hdsp_midi
*hmidi
;
1483 snd_hdsp_midi_input_trigger (substream
, 0);
1485 hmidi
= (struct hdsp_midi
*) substream
->rmidi
->private_data
;
1486 spin_lock_irq (&hmidi
->lock
);
1487 hmidi
->input
= NULL
;
1488 spin_unlock_irq (&hmidi
->lock
);
1493 static int snd_hdsp_midi_output_close(struct snd_rawmidi_substream
*substream
)
1495 struct hdsp_midi
*hmidi
;
1497 snd_hdsp_midi_output_trigger (substream
, 0);
1499 hmidi
= (struct hdsp_midi
*) substream
->rmidi
->private_data
;
1500 spin_lock_irq (&hmidi
->lock
);
1501 hmidi
->output
= NULL
;
1502 spin_unlock_irq (&hmidi
->lock
);
1507 static struct snd_rawmidi_ops snd_hdsp_midi_output
=
1509 .open
= snd_hdsp_midi_output_open
,
1510 .close
= snd_hdsp_midi_output_close
,
1511 .trigger
= snd_hdsp_midi_output_trigger
,
1514 static struct snd_rawmidi_ops snd_hdsp_midi_input
=
1516 .open
= snd_hdsp_midi_input_open
,
1517 .close
= snd_hdsp_midi_input_close
,
1518 .trigger
= snd_hdsp_midi_input_trigger
,
1521 static int snd_hdsp_create_midi (struct snd_card
*card
, struct hdsp
*hdsp
, int id
)
1525 hdsp
->midi
[id
].id
= id
;
1526 hdsp
->midi
[id
].rmidi
= NULL
;
1527 hdsp
->midi
[id
].input
= NULL
;
1528 hdsp
->midi
[id
].output
= NULL
;
1529 hdsp
->midi
[id
].hdsp
= hdsp
;
1530 hdsp
->midi
[id
].istimer
= 0;
1531 hdsp
->midi
[id
].pending
= 0;
1532 spin_lock_init (&hdsp
->midi
[id
].lock
);
1534 sprintf (buf
, "%s MIDI %d", card
->shortname
, id
+1);
1535 if (snd_rawmidi_new (card
, buf
, id
, 1, 1, &hdsp
->midi
[id
].rmidi
) < 0)
1538 sprintf(hdsp
->midi
[id
].rmidi
->name
, "HDSP MIDI %d", id
+1);
1539 hdsp
->midi
[id
].rmidi
->private_data
= &hdsp
->midi
[id
];
1541 snd_rawmidi_set_ops (hdsp
->midi
[id
].rmidi
, SNDRV_RAWMIDI_STREAM_OUTPUT
, &snd_hdsp_midi_output
);
1542 snd_rawmidi_set_ops (hdsp
->midi
[id
].rmidi
, SNDRV_RAWMIDI_STREAM_INPUT
, &snd_hdsp_midi_input
);
1544 hdsp
->midi
[id
].rmidi
->info_flags
|= SNDRV_RAWMIDI_INFO_OUTPUT
|
1545 SNDRV_RAWMIDI_INFO_INPUT
|
1546 SNDRV_RAWMIDI_INFO_DUPLEX
;
1551 /*-----------------------------------------------------------------------------
1553 ----------------------------------------------------------------------------*/
1555 static u32
snd_hdsp_convert_from_aes(struct snd_aes_iec958
*aes
)
1558 val
|= (aes
->status
[0] & IEC958_AES0_PROFESSIONAL
) ? HDSP_SPDIFProfessional
: 0;
1559 val
|= (aes
->status
[0] & IEC958_AES0_NONAUDIO
) ? HDSP_SPDIFNonAudio
: 0;
1560 if (val
& HDSP_SPDIFProfessional
)
1561 val
|= (aes
->status
[0] & IEC958_AES0_PRO_EMPHASIS_5015
) ? HDSP_SPDIFEmphasis
: 0;
1563 val
|= (aes
->status
[0] & IEC958_AES0_CON_EMPHASIS_5015
) ? HDSP_SPDIFEmphasis
: 0;
1567 static void snd_hdsp_convert_to_aes(struct snd_aes_iec958
*aes
, u32 val
)
1569 aes
->status
[0] = ((val
& HDSP_SPDIFProfessional
) ? IEC958_AES0_PROFESSIONAL
: 0) |
1570 ((val
& HDSP_SPDIFNonAudio
) ? IEC958_AES0_NONAUDIO
: 0);
1571 if (val
& HDSP_SPDIFProfessional
)
1572 aes
->status
[0] |= (val
& HDSP_SPDIFEmphasis
) ? IEC958_AES0_PRO_EMPHASIS_5015
: 0;
1574 aes
->status
[0] |= (val
& HDSP_SPDIFEmphasis
) ? IEC958_AES0_CON_EMPHASIS_5015
: 0;
1577 static int snd_hdsp_control_spdif_info(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_info
*uinfo
)
1579 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_IEC958
;
1584 static int snd_hdsp_control_spdif_get(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
1586 struct hdsp
*hdsp
= snd_kcontrol_chip(kcontrol
);
1588 snd_hdsp_convert_to_aes(&ucontrol
->value
.iec958
, hdsp
->creg_spdif
);
1592 static int snd_hdsp_control_spdif_put(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
1594 struct hdsp
*hdsp
= snd_kcontrol_chip(kcontrol
);
1598 val
= snd_hdsp_convert_from_aes(&ucontrol
->value
.iec958
);
1599 spin_lock_irq(&hdsp
->lock
);
1600 change
= val
!= hdsp
->creg_spdif
;
1601 hdsp
->creg_spdif
= val
;
1602 spin_unlock_irq(&hdsp
->lock
);
1606 static int snd_hdsp_control_spdif_stream_info(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_info
*uinfo
)
1608 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_IEC958
;
1613 static int snd_hdsp_control_spdif_stream_get(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
1615 struct hdsp
*hdsp
= snd_kcontrol_chip(kcontrol
);
1617 snd_hdsp_convert_to_aes(&ucontrol
->value
.iec958
, hdsp
->creg_spdif_stream
);
1621 static int snd_hdsp_control_spdif_stream_put(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
1623 struct hdsp
*hdsp
= snd_kcontrol_chip(kcontrol
);
1627 val
= snd_hdsp_convert_from_aes(&ucontrol
->value
.iec958
);
1628 spin_lock_irq(&hdsp
->lock
);
1629 change
= val
!= hdsp
->creg_spdif_stream
;
1630 hdsp
->creg_spdif_stream
= val
;
1631 hdsp
->control_register
&= ~(HDSP_SPDIFProfessional
| HDSP_SPDIFNonAudio
| HDSP_SPDIFEmphasis
);
1632 hdsp_write(hdsp
, HDSP_controlRegister
, hdsp
->control_register
|= val
);
1633 spin_unlock_irq(&hdsp
->lock
);
1637 static int snd_hdsp_control_spdif_mask_info(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_info
*uinfo
)
1639 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_IEC958
;
1644 static int snd_hdsp_control_spdif_mask_get(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
1646 ucontrol
->value
.iec958
.status
[0] = kcontrol
->private_value
;
1650 #define HDSP_SPDIF_IN(xname, xindex) \
1651 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1654 .info = snd_hdsp_info_spdif_in, \
1655 .get = snd_hdsp_get_spdif_in, \
1656 .put = snd_hdsp_put_spdif_in }
1658 static unsigned int hdsp_spdif_in(struct hdsp
*hdsp
)
1660 return hdsp_decode_spdif_in(hdsp
->control_register
& HDSP_SPDIFInputMask
);
1663 static int hdsp_set_spdif_input(struct hdsp
*hdsp
, int in
)
1665 hdsp
->control_register
&= ~HDSP_SPDIFInputMask
;
1666 hdsp
->control_register
|= hdsp_encode_spdif_in(in
);
1667 hdsp_write(hdsp
, HDSP_controlRegister
, hdsp
->control_register
);
1671 static int snd_hdsp_info_spdif_in(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_info
*uinfo
)
1673 static char *texts
[4] = {"Optical", "Coaxial", "Internal", "AES"};
1674 struct hdsp
*hdsp
= snd_kcontrol_chip(kcontrol
);
1676 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
1678 uinfo
->value
.enumerated
.items
= ((hdsp
->io_type
== H9632
) ? 4 : 3);
1679 if (uinfo
->value
.enumerated
.item
> ((hdsp
->io_type
== H9632
) ? 3 : 2))
1680 uinfo
->value
.enumerated
.item
= ((hdsp
->io_type
== H9632
) ? 3 : 2);
1681 strcpy(uinfo
->value
.enumerated
.name
, texts
[uinfo
->value
.enumerated
.item
]);
1685 static int snd_hdsp_get_spdif_in(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
1687 struct hdsp
*hdsp
= snd_kcontrol_chip(kcontrol
);
1689 ucontrol
->value
.enumerated
.item
[0] = hdsp_spdif_in(hdsp
);
1693 static int snd_hdsp_put_spdif_in(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
1695 struct hdsp
*hdsp
= snd_kcontrol_chip(kcontrol
);
1699 if (!snd_hdsp_use_is_exclusive(hdsp
))
1701 val
= ucontrol
->value
.enumerated
.item
[0] % ((hdsp
->io_type
== H9632
) ? 4 : 3);
1702 spin_lock_irq(&hdsp
->lock
);
1703 change
= val
!= hdsp_spdif_in(hdsp
);
1705 hdsp_set_spdif_input(hdsp
, val
);
1706 spin_unlock_irq(&hdsp
->lock
);
1710 #define HDSP_TOGGLE_SETTING(xname, xindex) \
1711 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1713 .private_value = xindex, \
1714 .info = snd_hdsp_info_toggle_setting, \
1715 .get = snd_hdsp_get_toggle_setting, \
1716 .put = snd_hdsp_put_toggle_setting \
1719 static int hdsp_toggle_setting(struct hdsp
*hdsp
, u32 regmask
)
1721 return (hdsp
->control_register
& regmask
) ? 1 : 0;
1724 static int hdsp_set_toggle_setting(struct hdsp
*hdsp
, u32 regmask
, int out
)
1727 hdsp
->control_register
|= regmask
;
1729 hdsp
->control_register
&= ~regmask
;
1730 hdsp_write(hdsp
, HDSP_controlRegister
, hdsp
->control_register
);
1735 #define snd_hdsp_info_toggle_setting snd_ctl_boolean_mono_info
1737 static int snd_hdsp_get_toggle_setting(struct snd_kcontrol
*kcontrol
,
1738 struct snd_ctl_elem_value
*ucontrol
)
1740 struct hdsp
*hdsp
= snd_kcontrol_chip(kcontrol
);
1741 u32 regmask
= kcontrol
->private_value
;
1743 spin_lock_irq(&hdsp
->lock
);
1744 ucontrol
->value
.integer
.value
[0] = hdsp_toggle_setting(hdsp
, regmask
);
1745 spin_unlock_irq(&hdsp
->lock
);
1749 static int snd_hdsp_put_toggle_setting(struct snd_kcontrol
*kcontrol
,
1750 struct snd_ctl_elem_value
*ucontrol
)
1752 struct hdsp
*hdsp
= snd_kcontrol_chip(kcontrol
);
1753 u32 regmask
= kcontrol
->private_value
;
1757 if (!snd_hdsp_use_is_exclusive(hdsp
))
1759 val
= ucontrol
->value
.integer
.value
[0] & 1;
1760 spin_lock_irq(&hdsp
->lock
);
1761 change
= (int) val
!= hdsp_toggle_setting(hdsp
, regmask
);
1763 hdsp_set_toggle_setting(hdsp
, regmask
, val
);
1764 spin_unlock_irq(&hdsp
->lock
);
1768 #define HDSP_SPDIF_SAMPLE_RATE(xname, xindex) \
1769 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1772 .access = SNDRV_CTL_ELEM_ACCESS_READ, \
1773 .info = snd_hdsp_info_spdif_sample_rate, \
1774 .get = snd_hdsp_get_spdif_sample_rate \
1777 static int snd_hdsp_info_spdif_sample_rate(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_info
*uinfo
)
1779 static char *texts
[] = {"32000", "44100", "48000", "64000", "88200", "96000", "None", "128000", "176400", "192000"};
1780 struct hdsp
*hdsp
= snd_kcontrol_chip(kcontrol
);
1782 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
1784 uinfo
->value
.enumerated
.items
= (hdsp
->io_type
== H9632
) ? 10 : 7;
1785 if (uinfo
->value
.enumerated
.item
>= uinfo
->value
.enumerated
.items
)
1786 uinfo
->value
.enumerated
.item
= uinfo
->value
.enumerated
.items
- 1;
1787 strcpy(uinfo
->value
.enumerated
.name
, texts
[uinfo
->value
.enumerated
.item
]);
1791 static int snd_hdsp_get_spdif_sample_rate(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
1793 struct hdsp
*hdsp
= snd_kcontrol_chip(kcontrol
);
1795 switch (hdsp_spdif_sample_rate(hdsp
)) {
1797 ucontrol
->value
.enumerated
.item
[0] = 0;
1800 ucontrol
->value
.enumerated
.item
[0] = 1;
1803 ucontrol
->value
.enumerated
.item
[0] = 2;
1806 ucontrol
->value
.enumerated
.item
[0] = 3;
1809 ucontrol
->value
.enumerated
.item
[0] = 4;
1812 ucontrol
->value
.enumerated
.item
[0] = 5;
1815 ucontrol
->value
.enumerated
.item
[0] = 7;
1818 ucontrol
->value
.enumerated
.item
[0] = 8;
1821 ucontrol
->value
.enumerated
.item
[0] = 9;
1824 ucontrol
->value
.enumerated
.item
[0] = 6;
1829 #define HDSP_SYSTEM_SAMPLE_RATE(xname, xindex) \
1830 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1833 .access = SNDRV_CTL_ELEM_ACCESS_READ, \
1834 .info = snd_hdsp_info_system_sample_rate, \
1835 .get = snd_hdsp_get_system_sample_rate \
1838 static int snd_hdsp_info_system_sample_rate(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_info
*uinfo
)
1840 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
1845 static int snd_hdsp_get_system_sample_rate(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
1847 struct hdsp
*hdsp
= snd_kcontrol_chip(kcontrol
);
1849 ucontrol
->value
.enumerated
.item
[0] = hdsp
->system_sample_rate
;
1853 #define HDSP_AUTOSYNC_SAMPLE_RATE(xname, xindex) \
1854 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1857 .access = SNDRV_CTL_ELEM_ACCESS_READ, \
1858 .info = snd_hdsp_info_autosync_sample_rate, \
1859 .get = snd_hdsp_get_autosync_sample_rate \
1862 static int snd_hdsp_info_autosync_sample_rate(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_info
*uinfo
)
1864 struct hdsp
*hdsp
= snd_kcontrol_chip(kcontrol
);
1865 static char *texts
[] = {"32000", "44100", "48000", "64000", "88200", "96000", "None", "128000", "176400", "192000"};
1866 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
1868 uinfo
->value
.enumerated
.items
= (hdsp
->io_type
== H9632
) ? 10 : 7 ;
1869 if (uinfo
->value
.enumerated
.item
>= uinfo
->value
.enumerated
.items
)
1870 uinfo
->value
.enumerated
.item
= uinfo
->value
.enumerated
.items
- 1;
1871 strcpy(uinfo
->value
.enumerated
.name
, texts
[uinfo
->value
.enumerated
.item
]);
1875 static int snd_hdsp_get_autosync_sample_rate(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
1877 struct hdsp
*hdsp
= snd_kcontrol_chip(kcontrol
);
1879 switch (hdsp_external_sample_rate(hdsp
)) {
1881 ucontrol
->value
.enumerated
.item
[0] = 0;
1884 ucontrol
->value
.enumerated
.item
[0] = 1;
1887 ucontrol
->value
.enumerated
.item
[0] = 2;
1890 ucontrol
->value
.enumerated
.item
[0] = 3;
1893 ucontrol
->value
.enumerated
.item
[0] = 4;
1896 ucontrol
->value
.enumerated
.item
[0] = 5;
1899 ucontrol
->value
.enumerated
.item
[0] = 7;
1902 ucontrol
->value
.enumerated
.item
[0] = 8;
1905 ucontrol
->value
.enumerated
.item
[0] = 9;
1908 ucontrol
->value
.enumerated
.item
[0] = 6;
1913 #define HDSP_SYSTEM_CLOCK_MODE(xname, xindex) \
1914 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1917 .access = SNDRV_CTL_ELEM_ACCESS_READ, \
1918 .info = snd_hdsp_info_system_clock_mode, \
1919 .get = snd_hdsp_get_system_clock_mode \
1922 static int hdsp_system_clock_mode(struct hdsp
*hdsp
)
1924 if (hdsp
->control_register
& HDSP_ClockModeMaster
)
1926 else if (hdsp_external_sample_rate(hdsp
) != hdsp
->system_sample_rate
)
1931 static int snd_hdsp_info_system_clock_mode(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_info
*uinfo
)
1933 static char *texts
[] = {"Master", "Slave" };
1935 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
1937 uinfo
->value
.enumerated
.items
= 2;
1938 if (uinfo
->value
.enumerated
.item
>= uinfo
->value
.enumerated
.items
)
1939 uinfo
->value
.enumerated
.item
= uinfo
->value
.enumerated
.items
- 1;
1940 strcpy(uinfo
->value
.enumerated
.name
, texts
[uinfo
->value
.enumerated
.item
]);
1944 static int snd_hdsp_get_system_clock_mode(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
1946 struct hdsp
*hdsp
= snd_kcontrol_chip(kcontrol
);
1948 ucontrol
->value
.enumerated
.item
[0] = hdsp_system_clock_mode(hdsp
);
1952 #define HDSP_CLOCK_SOURCE(xname, xindex) \
1953 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1956 .info = snd_hdsp_info_clock_source, \
1957 .get = snd_hdsp_get_clock_source, \
1958 .put = snd_hdsp_put_clock_source \
1961 static int hdsp_clock_source(struct hdsp
*hdsp
)
1963 if (hdsp
->control_register
& HDSP_ClockModeMaster
) {
1964 switch (hdsp
->system_sample_rate
) {
1991 static int hdsp_set_clock_source(struct hdsp
*hdsp
, int mode
)
1995 case HDSP_CLOCK_SOURCE_AUTOSYNC
:
1996 if (hdsp_external_sample_rate(hdsp
) != 0) {
1997 if (!hdsp_set_rate(hdsp
, hdsp_external_sample_rate(hdsp
), 1)) {
1998 hdsp
->control_register
&= ~HDSP_ClockModeMaster
;
1999 hdsp_write(hdsp
, HDSP_controlRegister
, hdsp
->control_register
);
2004 case HDSP_CLOCK_SOURCE_INTERNAL_32KHZ
:
2007 case HDSP_CLOCK_SOURCE_INTERNAL_44_1KHZ
:
2010 case HDSP_CLOCK_SOURCE_INTERNAL_48KHZ
:
2013 case HDSP_CLOCK_SOURCE_INTERNAL_64KHZ
:
2016 case HDSP_CLOCK_SOURCE_INTERNAL_88_2KHZ
:
2019 case HDSP_CLOCK_SOURCE_INTERNAL_96KHZ
:
2022 case HDSP_CLOCK_SOURCE_INTERNAL_128KHZ
:
2025 case HDSP_CLOCK_SOURCE_INTERNAL_176_4KHZ
:
2028 case HDSP_CLOCK_SOURCE_INTERNAL_192KHZ
:
2034 hdsp
->control_register
|= HDSP_ClockModeMaster
;
2035 hdsp_write(hdsp
, HDSP_controlRegister
, hdsp
->control_register
);
2036 hdsp_set_rate(hdsp
, rate
, 1);
2040 static int snd_hdsp_info_clock_source(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_info
*uinfo
)
2042 static char *texts
[] = {"AutoSync", "Internal 32.0 kHz", "Internal 44.1 kHz", "Internal 48.0 kHz", "Internal 64.0 kHz", "Internal 88.2 kHz", "Internal 96.0 kHz", "Internal 128 kHz", "Internal 176.4 kHz", "Internal 192.0 KHz" };
2043 struct hdsp
*hdsp
= snd_kcontrol_chip(kcontrol
);
2045 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
2047 if (hdsp
->io_type
== H9632
)
2048 uinfo
->value
.enumerated
.items
= 10;
2050 uinfo
->value
.enumerated
.items
= 7;
2051 if (uinfo
->value
.enumerated
.item
>= uinfo
->value
.enumerated
.items
)
2052 uinfo
->value
.enumerated
.item
= uinfo
->value
.enumerated
.items
- 1;
2053 strcpy(uinfo
->value
.enumerated
.name
, texts
[uinfo
->value
.enumerated
.item
]);
2057 static int snd_hdsp_get_clock_source(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
2059 struct hdsp
*hdsp
= snd_kcontrol_chip(kcontrol
);
2061 ucontrol
->value
.enumerated
.item
[0] = hdsp_clock_source(hdsp
);
2065 static int snd_hdsp_put_clock_source(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
2067 struct hdsp
*hdsp
= snd_kcontrol_chip(kcontrol
);
2071 if (!snd_hdsp_use_is_exclusive(hdsp
))
2073 val
= ucontrol
->value
.enumerated
.item
[0];
2074 if (val
< 0) val
= 0;
2075 if (hdsp
->io_type
== H9632
) {
2082 spin_lock_irq(&hdsp
->lock
);
2083 if (val
!= hdsp_clock_source(hdsp
))
2084 change
= (hdsp_set_clock_source(hdsp
, val
) == 0) ? 1 : 0;
2087 spin_unlock_irq(&hdsp
->lock
);
2091 #define snd_hdsp_info_clock_source_lock snd_ctl_boolean_mono_info
2093 static int snd_hdsp_get_clock_source_lock(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
2095 struct hdsp
*hdsp
= snd_kcontrol_chip(kcontrol
);
2097 ucontrol
->value
.integer
.value
[0] = hdsp
->clock_source_locked
;
2101 static int snd_hdsp_put_clock_source_lock(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
2103 struct hdsp
*hdsp
= snd_kcontrol_chip(kcontrol
);
2106 change
= (int)ucontrol
->value
.integer
.value
[0] != hdsp
->clock_source_locked
;
2108 hdsp
->clock_source_locked
= !!ucontrol
->value
.integer
.value
[0];
2112 #define HDSP_DA_GAIN(xname, xindex) \
2113 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2116 .info = snd_hdsp_info_da_gain, \
2117 .get = snd_hdsp_get_da_gain, \
2118 .put = snd_hdsp_put_da_gain \
2121 static int hdsp_da_gain(struct hdsp
*hdsp
)
2123 switch (hdsp
->control_register
& HDSP_DAGainMask
) {
2124 case HDSP_DAGainHighGain
:
2126 case HDSP_DAGainPlus4dBu
:
2128 case HDSP_DAGainMinus10dBV
:
2135 static int hdsp_set_da_gain(struct hdsp
*hdsp
, int mode
)
2137 hdsp
->control_register
&= ~HDSP_DAGainMask
;
2140 hdsp
->control_register
|= HDSP_DAGainHighGain
;
2143 hdsp
->control_register
|= HDSP_DAGainPlus4dBu
;
2146 hdsp
->control_register
|= HDSP_DAGainMinus10dBV
;
2152 hdsp_write(hdsp
, HDSP_controlRegister
, hdsp
->control_register
);
2156 static int snd_hdsp_info_da_gain(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_info
*uinfo
)
2158 static char *texts
[] = {"Hi Gain", "+4 dBu", "-10 dbV"};
2160 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
2162 uinfo
->value
.enumerated
.items
= 3;
2163 if (uinfo
->value
.enumerated
.item
>= uinfo
->value
.enumerated
.items
)
2164 uinfo
->value
.enumerated
.item
= uinfo
->value
.enumerated
.items
- 1;
2165 strcpy(uinfo
->value
.enumerated
.name
, texts
[uinfo
->value
.enumerated
.item
]);
2169 static int snd_hdsp_get_da_gain(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
2171 struct hdsp
*hdsp
= snd_kcontrol_chip(kcontrol
);
2173 ucontrol
->value
.enumerated
.item
[0] = hdsp_da_gain(hdsp
);
2177 static int snd_hdsp_put_da_gain(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
2179 struct hdsp
*hdsp
= snd_kcontrol_chip(kcontrol
);
2183 if (!snd_hdsp_use_is_exclusive(hdsp
))
2185 val
= ucontrol
->value
.enumerated
.item
[0];
2186 if (val
< 0) val
= 0;
2187 if (val
> 2) val
= 2;
2188 spin_lock_irq(&hdsp
->lock
);
2189 if (val
!= hdsp_da_gain(hdsp
))
2190 change
= (hdsp_set_da_gain(hdsp
, val
) == 0) ? 1 : 0;
2193 spin_unlock_irq(&hdsp
->lock
);
2197 #define HDSP_AD_GAIN(xname, xindex) \
2198 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2201 .info = snd_hdsp_info_ad_gain, \
2202 .get = snd_hdsp_get_ad_gain, \
2203 .put = snd_hdsp_put_ad_gain \
2206 static int hdsp_ad_gain(struct hdsp
*hdsp
)
2208 switch (hdsp
->control_register
& HDSP_ADGainMask
) {
2209 case HDSP_ADGainMinus10dBV
:
2211 case HDSP_ADGainPlus4dBu
:
2213 case HDSP_ADGainLowGain
:
2220 static int hdsp_set_ad_gain(struct hdsp
*hdsp
, int mode
)
2222 hdsp
->control_register
&= ~HDSP_ADGainMask
;
2225 hdsp
->control_register
|= HDSP_ADGainMinus10dBV
;
2228 hdsp
->control_register
|= HDSP_ADGainPlus4dBu
;
2231 hdsp
->control_register
|= HDSP_ADGainLowGain
;
2237 hdsp_write(hdsp
, HDSP_controlRegister
, hdsp
->control_register
);
2241 static int snd_hdsp_info_ad_gain(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_info
*uinfo
)
2243 static char *texts
[] = {"-10 dBV", "+4 dBu", "Lo Gain"};
2245 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
2247 uinfo
->value
.enumerated
.items
= 3;
2248 if (uinfo
->value
.enumerated
.item
>= uinfo
->value
.enumerated
.items
)
2249 uinfo
->value
.enumerated
.item
= uinfo
->value
.enumerated
.items
- 1;
2250 strcpy(uinfo
->value
.enumerated
.name
, texts
[uinfo
->value
.enumerated
.item
]);
2254 static int snd_hdsp_get_ad_gain(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
2256 struct hdsp
*hdsp
= snd_kcontrol_chip(kcontrol
);
2258 ucontrol
->value
.enumerated
.item
[0] = hdsp_ad_gain(hdsp
);
2262 static int snd_hdsp_put_ad_gain(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
2264 struct hdsp
*hdsp
= snd_kcontrol_chip(kcontrol
);
2268 if (!snd_hdsp_use_is_exclusive(hdsp
))
2270 val
= ucontrol
->value
.enumerated
.item
[0];
2271 if (val
< 0) val
= 0;
2272 if (val
> 2) val
= 2;
2273 spin_lock_irq(&hdsp
->lock
);
2274 if (val
!= hdsp_ad_gain(hdsp
))
2275 change
= (hdsp_set_ad_gain(hdsp
, val
) == 0) ? 1 : 0;
2278 spin_unlock_irq(&hdsp
->lock
);
2282 #define HDSP_PHONE_GAIN(xname, xindex) \
2283 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2286 .info = snd_hdsp_info_phone_gain, \
2287 .get = snd_hdsp_get_phone_gain, \
2288 .put = snd_hdsp_put_phone_gain \
2291 static int hdsp_phone_gain(struct hdsp
*hdsp
)
2293 switch (hdsp
->control_register
& HDSP_PhoneGainMask
) {
2294 case HDSP_PhoneGain0dB
:
2296 case HDSP_PhoneGainMinus6dB
:
2298 case HDSP_PhoneGainMinus12dB
:
2305 static int hdsp_set_phone_gain(struct hdsp
*hdsp
, int mode
)
2307 hdsp
->control_register
&= ~HDSP_PhoneGainMask
;
2310 hdsp
->control_register
|= HDSP_PhoneGain0dB
;
2313 hdsp
->control_register
|= HDSP_PhoneGainMinus6dB
;
2316 hdsp
->control_register
|= HDSP_PhoneGainMinus12dB
;
2322 hdsp_write(hdsp
, HDSP_controlRegister
, hdsp
->control_register
);
2326 static int snd_hdsp_info_phone_gain(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_info
*uinfo
)
2328 static char *texts
[] = {"0 dB", "-6 dB", "-12 dB"};
2330 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
2332 uinfo
->value
.enumerated
.items
= 3;
2333 if (uinfo
->value
.enumerated
.item
>= uinfo
->value
.enumerated
.items
)
2334 uinfo
->value
.enumerated
.item
= uinfo
->value
.enumerated
.items
- 1;
2335 strcpy(uinfo
->value
.enumerated
.name
, texts
[uinfo
->value
.enumerated
.item
]);
2339 static int snd_hdsp_get_phone_gain(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
2341 struct hdsp
*hdsp
= snd_kcontrol_chip(kcontrol
);
2343 ucontrol
->value
.enumerated
.item
[0] = hdsp_phone_gain(hdsp
);
2347 static int snd_hdsp_put_phone_gain(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
2349 struct hdsp
*hdsp
= snd_kcontrol_chip(kcontrol
);
2353 if (!snd_hdsp_use_is_exclusive(hdsp
))
2355 val
= ucontrol
->value
.enumerated
.item
[0];
2356 if (val
< 0) val
= 0;
2357 if (val
> 2) val
= 2;
2358 spin_lock_irq(&hdsp
->lock
);
2359 if (val
!= hdsp_phone_gain(hdsp
))
2360 change
= (hdsp_set_phone_gain(hdsp
, val
) == 0) ? 1 : 0;
2363 spin_unlock_irq(&hdsp
->lock
);
2367 #define HDSP_PREF_SYNC_REF(xname, xindex) \
2368 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2371 .info = snd_hdsp_info_pref_sync_ref, \
2372 .get = snd_hdsp_get_pref_sync_ref, \
2373 .put = snd_hdsp_put_pref_sync_ref \
2376 static int hdsp_pref_sync_ref(struct hdsp
*hdsp
)
2378 /* Notice that this looks at the requested sync source,
2379 not the one actually in use.
2382 switch (hdsp
->control_register
& HDSP_SyncRefMask
) {
2383 case HDSP_SyncRef_ADAT1
:
2384 return HDSP_SYNC_FROM_ADAT1
;
2385 case HDSP_SyncRef_ADAT2
:
2386 return HDSP_SYNC_FROM_ADAT2
;
2387 case HDSP_SyncRef_ADAT3
:
2388 return HDSP_SYNC_FROM_ADAT3
;
2389 case HDSP_SyncRef_SPDIF
:
2390 return HDSP_SYNC_FROM_SPDIF
;
2391 case HDSP_SyncRef_WORD
:
2392 return HDSP_SYNC_FROM_WORD
;
2393 case HDSP_SyncRef_ADAT_SYNC
:
2394 return HDSP_SYNC_FROM_ADAT_SYNC
;
2396 return HDSP_SYNC_FROM_WORD
;
2401 static int hdsp_set_pref_sync_ref(struct hdsp
*hdsp
, int pref
)
2403 hdsp
->control_register
&= ~HDSP_SyncRefMask
;
2405 case HDSP_SYNC_FROM_ADAT1
:
2406 hdsp
->control_register
&= ~HDSP_SyncRefMask
; /* clear SyncRef bits */
2408 case HDSP_SYNC_FROM_ADAT2
:
2409 hdsp
->control_register
|= HDSP_SyncRef_ADAT2
;
2411 case HDSP_SYNC_FROM_ADAT3
:
2412 hdsp
->control_register
|= HDSP_SyncRef_ADAT3
;
2414 case HDSP_SYNC_FROM_SPDIF
:
2415 hdsp
->control_register
|= HDSP_SyncRef_SPDIF
;
2417 case HDSP_SYNC_FROM_WORD
:
2418 hdsp
->control_register
|= HDSP_SyncRef_WORD
;
2420 case HDSP_SYNC_FROM_ADAT_SYNC
:
2421 hdsp
->control_register
|= HDSP_SyncRef_ADAT_SYNC
;
2426 hdsp_write(hdsp
, HDSP_controlRegister
, hdsp
->control_register
);
2430 static int snd_hdsp_info_pref_sync_ref(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_info
*uinfo
)
2432 static char *texts
[] = {"Word", "IEC958", "ADAT1", "ADAT Sync", "ADAT2", "ADAT3" };
2433 struct hdsp
*hdsp
= snd_kcontrol_chip(kcontrol
);
2435 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
2438 switch (hdsp
->io_type
) {
2441 uinfo
->value
.enumerated
.items
= 6;
2444 uinfo
->value
.enumerated
.items
= 4;
2447 uinfo
->value
.enumerated
.items
= 3;
2453 if (uinfo
->value
.enumerated
.item
>= uinfo
->value
.enumerated
.items
)
2454 uinfo
->value
.enumerated
.item
= uinfo
->value
.enumerated
.items
- 1;
2455 strcpy(uinfo
->value
.enumerated
.name
, texts
[uinfo
->value
.enumerated
.item
]);
2459 static int snd_hdsp_get_pref_sync_ref(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
2461 struct hdsp
*hdsp
= snd_kcontrol_chip(kcontrol
);
2463 ucontrol
->value
.enumerated
.item
[0] = hdsp_pref_sync_ref(hdsp
);
2467 static int snd_hdsp_put_pref_sync_ref(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
2469 struct hdsp
*hdsp
= snd_kcontrol_chip(kcontrol
);
2473 if (!snd_hdsp_use_is_exclusive(hdsp
))
2476 switch (hdsp
->io_type
) {
2491 val
= ucontrol
->value
.enumerated
.item
[0] % max
;
2492 spin_lock_irq(&hdsp
->lock
);
2493 change
= (int)val
!= hdsp_pref_sync_ref(hdsp
);
2494 hdsp_set_pref_sync_ref(hdsp
, val
);
2495 spin_unlock_irq(&hdsp
->lock
);
2499 #define HDSP_AUTOSYNC_REF(xname, xindex) \
2500 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2503 .access = SNDRV_CTL_ELEM_ACCESS_READ, \
2504 .info = snd_hdsp_info_autosync_ref, \
2505 .get = snd_hdsp_get_autosync_ref, \
2508 static int hdsp_autosync_ref(struct hdsp
*hdsp
)
2510 /* This looks at the autosync selected sync reference */
2511 unsigned int status2
= hdsp_read(hdsp
, HDSP_status2Register
);
2513 switch (status2
& HDSP_SelSyncRefMask
) {
2514 case HDSP_SelSyncRef_WORD
:
2515 return HDSP_AUTOSYNC_FROM_WORD
;
2516 case HDSP_SelSyncRef_ADAT_SYNC
:
2517 return HDSP_AUTOSYNC_FROM_ADAT_SYNC
;
2518 case HDSP_SelSyncRef_SPDIF
:
2519 return HDSP_AUTOSYNC_FROM_SPDIF
;
2520 case HDSP_SelSyncRefMask
:
2521 return HDSP_AUTOSYNC_FROM_NONE
;
2522 case HDSP_SelSyncRef_ADAT1
:
2523 return HDSP_AUTOSYNC_FROM_ADAT1
;
2524 case HDSP_SelSyncRef_ADAT2
:
2525 return HDSP_AUTOSYNC_FROM_ADAT2
;
2526 case HDSP_SelSyncRef_ADAT3
:
2527 return HDSP_AUTOSYNC_FROM_ADAT3
;
2529 return HDSP_AUTOSYNC_FROM_WORD
;
2534 static int snd_hdsp_info_autosync_ref(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_info
*uinfo
)
2536 static char *texts
[] = {"Word", "ADAT Sync", "IEC958", "None", "ADAT1", "ADAT2", "ADAT3" };
2538 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
2540 uinfo
->value
.enumerated
.items
= 7;
2541 if (uinfo
->value
.enumerated
.item
>= uinfo
->value
.enumerated
.items
)
2542 uinfo
->value
.enumerated
.item
= uinfo
->value
.enumerated
.items
- 1;
2543 strcpy(uinfo
->value
.enumerated
.name
, texts
[uinfo
->value
.enumerated
.item
]);
2547 static int snd_hdsp_get_autosync_ref(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
2549 struct hdsp
*hdsp
= snd_kcontrol_chip(kcontrol
);
2551 ucontrol
->value
.enumerated
.item
[0] = hdsp_autosync_ref(hdsp
);
2555 #define HDSP_PRECISE_POINTER(xname, xindex) \
2556 { .iface = SNDRV_CTL_ELEM_IFACE_CARD, \
2559 .info = snd_hdsp_info_precise_pointer, \
2560 .get = snd_hdsp_get_precise_pointer, \
2561 .put = snd_hdsp_put_precise_pointer \
2564 static int hdsp_set_precise_pointer(struct hdsp
*hdsp
, int precise
)
2567 hdsp
->precise_ptr
= 1;
2569 hdsp
->precise_ptr
= 0;
2573 #define snd_hdsp_info_precise_pointer snd_ctl_boolean_mono_info
2575 static int snd_hdsp_get_precise_pointer(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
2577 struct hdsp
*hdsp
= snd_kcontrol_chip(kcontrol
);
2579 spin_lock_irq(&hdsp
->lock
);
2580 ucontrol
->value
.integer
.value
[0] = hdsp
->precise_ptr
;
2581 spin_unlock_irq(&hdsp
->lock
);
2585 static int snd_hdsp_put_precise_pointer(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
2587 struct hdsp
*hdsp
= snd_kcontrol_chip(kcontrol
);
2591 if (!snd_hdsp_use_is_exclusive(hdsp
))
2593 val
= ucontrol
->value
.integer
.value
[0] & 1;
2594 spin_lock_irq(&hdsp
->lock
);
2595 change
= (int)val
!= hdsp
->precise_ptr
;
2596 hdsp_set_precise_pointer(hdsp
, val
);
2597 spin_unlock_irq(&hdsp
->lock
);
2601 #define HDSP_USE_MIDI_TASKLET(xname, xindex) \
2602 { .iface = SNDRV_CTL_ELEM_IFACE_CARD, \
2605 .info = snd_hdsp_info_use_midi_tasklet, \
2606 .get = snd_hdsp_get_use_midi_tasklet, \
2607 .put = snd_hdsp_put_use_midi_tasklet \
2610 static int hdsp_set_use_midi_tasklet(struct hdsp
*hdsp
, int use_tasklet
)
2613 hdsp
->use_midi_tasklet
= 1;
2615 hdsp
->use_midi_tasklet
= 0;
2619 #define snd_hdsp_info_use_midi_tasklet snd_ctl_boolean_mono_info
2621 static int snd_hdsp_get_use_midi_tasklet(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
2623 struct hdsp
*hdsp
= snd_kcontrol_chip(kcontrol
);
2625 spin_lock_irq(&hdsp
->lock
);
2626 ucontrol
->value
.integer
.value
[0] = hdsp
->use_midi_tasklet
;
2627 spin_unlock_irq(&hdsp
->lock
);
2631 static int snd_hdsp_put_use_midi_tasklet(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
2633 struct hdsp
*hdsp
= snd_kcontrol_chip(kcontrol
);
2637 if (!snd_hdsp_use_is_exclusive(hdsp
))
2639 val
= ucontrol
->value
.integer
.value
[0] & 1;
2640 spin_lock_irq(&hdsp
->lock
);
2641 change
= (int)val
!= hdsp
->use_midi_tasklet
;
2642 hdsp_set_use_midi_tasklet(hdsp
, val
);
2643 spin_unlock_irq(&hdsp
->lock
);
2647 #define HDSP_MIXER(xname, xindex) \
2648 { .iface = SNDRV_CTL_ELEM_IFACE_HWDEP, \
2652 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | \
2653 SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
2654 .info = snd_hdsp_info_mixer, \
2655 .get = snd_hdsp_get_mixer, \
2656 .put = snd_hdsp_put_mixer \
2659 static int snd_hdsp_info_mixer(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_info
*uinfo
)
2661 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
2663 uinfo
->value
.integer
.min
= 0;
2664 uinfo
->value
.integer
.max
= 65536;
2665 uinfo
->value
.integer
.step
= 1;
2669 static int snd_hdsp_get_mixer(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
2671 struct hdsp
*hdsp
= snd_kcontrol_chip(kcontrol
);
2676 source
= ucontrol
->value
.integer
.value
[0];
2677 destination
= ucontrol
->value
.integer
.value
[1];
2679 if (source
>= hdsp
->max_channels
)
2680 addr
= hdsp_playback_to_output_key(hdsp
,source
-hdsp
->max_channels
,destination
);
2682 addr
= hdsp_input_to_output_key(hdsp
,source
, destination
);
2684 spin_lock_irq(&hdsp
->lock
);
2685 ucontrol
->value
.integer
.value
[2] = hdsp_read_gain (hdsp
, addr
);
2686 spin_unlock_irq(&hdsp
->lock
);
2690 static int snd_hdsp_put_mixer(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
2692 struct hdsp
*hdsp
= snd_kcontrol_chip(kcontrol
);
2699 if (!snd_hdsp_use_is_exclusive(hdsp
))
2702 source
= ucontrol
->value
.integer
.value
[0];
2703 destination
= ucontrol
->value
.integer
.value
[1];
2705 if (source
>= hdsp
->max_channels
)
2706 addr
= hdsp_playback_to_output_key(hdsp
,source
-hdsp
->max_channels
, destination
);
2708 addr
= hdsp_input_to_output_key(hdsp
,source
, destination
);
2710 gain
= ucontrol
->value
.integer
.value
[2];
2712 spin_lock_irq(&hdsp
->lock
);
2713 change
= gain
!= hdsp_read_gain(hdsp
, addr
);
2715 hdsp_write_gain(hdsp
, addr
, gain
);
2716 spin_unlock_irq(&hdsp
->lock
);
2720 #define HDSP_WC_SYNC_CHECK(xname, xindex) \
2721 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2724 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
2725 .info = snd_hdsp_info_sync_check, \
2726 .get = snd_hdsp_get_wc_sync_check \
2729 static int snd_hdsp_info_sync_check(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_info
*uinfo
)
2731 static char *texts
[] = {"No Lock", "Lock", "Sync" };
2732 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
2734 uinfo
->value
.enumerated
.items
= 3;
2735 if (uinfo
->value
.enumerated
.item
>= uinfo
->value
.enumerated
.items
)
2736 uinfo
->value
.enumerated
.item
= uinfo
->value
.enumerated
.items
- 1;
2737 strcpy(uinfo
->value
.enumerated
.name
, texts
[uinfo
->value
.enumerated
.item
]);
2741 static int hdsp_wc_sync_check(struct hdsp
*hdsp
)
2743 int status2
= hdsp_read(hdsp
, HDSP_status2Register
);
2744 if (status2
& HDSP_wc_lock
) {
2745 if (status2
& HDSP_wc_sync
)
2754 static int snd_hdsp_get_wc_sync_check(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
2756 struct hdsp
*hdsp
= snd_kcontrol_chip(kcontrol
);
2758 ucontrol
->value
.enumerated
.item
[0] = hdsp_wc_sync_check(hdsp
);
2762 #define HDSP_SPDIF_SYNC_CHECK(xname, xindex) \
2763 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2766 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
2767 .info = snd_hdsp_info_sync_check, \
2768 .get = snd_hdsp_get_spdif_sync_check \
2771 static int hdsp_spdif_sync_check(struct hdsp
*hdsp
)
2773 int status
= hdsp_read(hdsp
, HDSP_statusRegister
);
2774 if (status
& HDSP_SPDIFErrorFlag
)
2777 if (status
& HDSP_SPDIFSync
)
2785 static int snd_hdsp_get_spdif_sync_check(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
2787 struct hdsp
*hdsp
= snd_kcontrol_chip(kcontrol
);
2789 ucontrol
->value
.enumerated
.item
[0] = hdsp_spdif_sync_check(hdsp
);
2793 #define HDSP_ADATSYNC_SYNC_CHECK(xname, xindex) \
2794 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2797 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
2798 .info = snd_hdsp_info_sync_check, \
2799 .get = snd_hdsp_get_adatsync_sync_check \
2802 static int hdsp_adatsync_sync_check(struct hdsp
*hdsp
)
2804 int status
= hdsp_read(hdsp
, HDSP_statusRegister
);
2805 if (status
& HDSP_TimecodeLock
) {
2806 if (status
& HDSP_TimecodeSync
)
2814 static int snd_hdsp_get_adatsync_sync_check(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
2816 struct hdsp
*hdsp
= snd_kcontrol_chip(kcontrol
);
2818 ucontrol
->value
.enumerated
.item
[0] = hdsp_adatsync_sync_check(hdsp
);
2822 #define HDSP_ADAT_SYNC_CHECK \
2823 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2824 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
2825 .info = snd_hdsp_info_sync_check, \
2826 .get = snd_hdsp_get_adat_sync_check \
2829 static int hdsp_adat_sync_check(struct hdsp
*hdsp
, int idx
)
2831 int status
= hdsp_read(hdsp
, HDSP_statusRegister
);
2833 if (status
& (HDSP_Lock0
>>idx
)) {
2834 if (status
& (HDSP_Sync0
>>idx
))
2842 static int snd_hdsp_get_adat_sync_check(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
2845 struct hdsp
*hdsp
= snd_kcontrol_chip(kcontrol
);
2847 offset
= ucontrol
->id
.index
- 1;
2848 snd_BUG_ON(offset
< 0);
2850 switch (hdsp
->io_type
) {
2865 ucontrol
->value
.enumerated
.item
[0] = hdsp_adat_sync_check(hdsp
, offset
);
2869 #define HDSP_DDS_OFFSET(xname, xindex) \
2870 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2873 .info = snd_hdsp_info_dds_offset, \
2874 .get = snd_hdsp_get_dds_offset, \
2875 .put = snd_hdsp_put_dds_offset \
2878 static int hdsp_dds_offset(struct hdsp
*hdsp
)
2881 unsigned int dds_value
= hdsp
->dds_value
;
2882 int system_sample_rate
= hdsp
->system_sample_rate
;
2889 * dds_value = n / rate
2890 * rate = n / dds_value
2892 n
= div_u64(n
, dds_value
);
2893 if (system_sample_rate
>= 112000)
2895 else if (system_sample_rate
>= 56000)
2897 return ((int)n
) - system_sample_rate
;
2900 static int hdsp_set_dds_offset(struct hdsp
*hdsp
, int offset_hz
)
2902 int rate
= hdsp
->system_sample_rate
+ offset_hz
;
2903 hdsp_set_dds_value(hdsp
, rate
);
2907 static int snd_hdsp_info_dds_offset(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_info
*uinfo
)
2909 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
2911 uinfo
->value
.integer
.min
= -5000;
2912 uinfo
->value
.integer
.max
= 5000;
2916 static int snd_hdsp_get_dds_offset(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
2918 struct hdsp
*hdsp
= snd_kcontrol_chip(kcontrol
);
2920 ucontrol
->value
.enumerated
.item
[0] = hdsp_dds_offset(hdsp
);
2924 static int snd_hdsp_put_dds_offset(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
2926 struct hdsp
*hdsp
= snd_kcontrol_chip(kcontrol
);
2930 if (!snd_hdsp_use_is_exclusive(hdsp
))
2932 val
= ucontrol
->value
.enumerated
.item
[0];
2933 spin_lock_irq(&hdsp
->lock
);
2934 if (val
!= hdsp_dds_offset(hdsp
))
2935 change
= (hdsp_set_dds_offset(hdsp
, val
) == 0) ? 1 : 0;
2938 spin_unlock_irq(&hdsp
->lock
);
2942 static struct snd_kcontrol_new snd_hdsp_9632_controls
[] = {
2943 HDSP_DA_GAIN("DA Gain", 0),
2944 HDSP_AD_GAIN("AD Gain", 0),
2945 HDSP_PHONE_GAIN("Phones Gain", 0),
2946 HDSP_TOGGLE_SETTING("XLR Breakout Cable", HDSP_XLRBreakoutCable
),
2947 HDSP_DDS_OFFSET("DDS Sample Rate Offset", 0)
2950 static struct snd_kcontrol_new snd_hdsp_controls
[] = {
2952 .iface
= SNDRV_CTL_ELEM_IFACE_PCM
,
2953 .name
= SNDRV_CTL_NAME_IEC958("",PLAYBACK
,DEFAULT
),
2954 .info
= snd_hdsp_control_spdif_info
,
2955 .get
= snd_hdsp_control_spdif_get
,
2956 .put
= snd_hdsp_control_spdif_put
,
2959 .access
= SNDRV_CTL_ELEM_ACCESS_READWRITE
| SNDRV_CTL_ELEM_ACCESS_INACTIVE
,
2960 .iface
= SNDRV_CTL_ELEM_IFACE_PCM
,
2961 .name
= SNDRV_CTL_NAME_IEC958("",PLAYBACK
,PCM_STREAM
),
2962 .info
= snd_hdsp_control_spdif_stream_info
,
2963 .get
= snd_hdsp_control_spdif_stream_get
,
2964 .put
= snd_hdsp_control_spdif_stream_put
,
2967 .access
= SNDRV_CTL_ELEM_ACCESS_READ
,
2968 .iface
= SNDRV_CTL_ELEM_IFACE_PCM
,
2969 .name
= SNDRV_CTL_NAME_IEC958("",PLAYBACK
,CON_MASK
),
2970 .info
= snd_hdsp_control_spdif_mask_info
,
2971 .get
= snd_hdsp_control_spdif_mask_get
,
2972 .private_value
= IEC958_AES0_NONAUDIO
|
2973 IEC958_AES0_PROFESSIONAL
|
2974 IEC958_AES0_CON_EMPHASIS
,
2977 .access
= SNDRV_CTL_ELEM_ACCESS_READ
,
2978 .iface
= SNDRV_CTL_ELEM_IFACE_PCM
,
2979 .name
= SNDRV_CTL_NAME_IEC958("",PLAYBACK
,PRO_MASK
),
2980 .info
= snd_hdsp_control_spdif_mask_info
,
2981 .get
= snd_hdsp_control_spdif_mask_get
,
2982 .private_value
= IEC958_AES0_NONAUDIO
|
2983 IEC958_AES0_PROFESSIONAL
|
2984 IEC958_AES0_PRO_EMPHASIS
,
2986 HDSP_MIXER("Mixer", 0),
2987 HDSP_SPDIF_IN("IEC958 Input Connector", 0),
2988 HDSP_TOGGLE_SETTING("IEC958 Output also on ADAT1", HDSP_SPDIFOpticalOut
),
2989 HDSP_TOGGLE_SETTING("IEC958 Professional Bit", HDSP_SPDIFProfessional
),
2990 HDSP_TOGGLE_SETTING("IEC958 Emphasis Bit", HDSP_SPDIFEmphasis
),
2991 HDSP_TOGGLE_SETTING("IEC958 Non-audio Bit", HDSP_SPDIFNonAudio
),
2992 /* 'Sample Clock Source' complies with the alsa control naming scheme */
2993 HDSP_CLOCK_SOURCE("Sample Clock Source", 0),
2995 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
2996 .name
= "Sample Clock Source Locking",
2997 .info
= snd_hdsp_info_clock_source_lock
,
2998 .get
= snd_hdsp_get_clock_source_lock
,
2999 .put
= snd_hdsp_put_clock_source_lock
,
3001 HDSP_SYSTEM_CLOCK_MODE("System Clock Mode", 0),
3002 HDSP_PREF_SYNC_REF("Preferred Sync Reference", 0),
3003 HDSP_AUTOSYNC_REF("AutoSync Reference", 0),
3004 HDSP_SPDIF_SAMPLE_RATE("SPDIF Sample Rate", 0),
3005 HDSP_SYSTEM_SAMPLE_RATE("System Sample Rate", 0),
3006 /* 'External Rate' complies with the alsa control naming scheme */
3007 HDSP_AUTOSYNC_SAMPLE_RATE("External Rate", 0),
3008 HDSP_WC_SYNC_CHECK("Word Clock Lock Status", 0),
3009 HDSP_SPDIF_SYNC_CHECK("SPDIF Lock Status", 0),
3010 HDSP_ADATSYNC_SYNC_CHECK("ADAT Sync Lock Status", 0),
3011 HDSP_TOGGLE_SETTING("Line Out", HDSP_LineOut
),
3012 HDSP_PRECISE_POINTER("Precise Pointer", 0),
3013 HDSP_USE_MIDI_TASKLET("Use Midi Tasklet", 0),
3017 static int hdsp_rpm_input12(struct hdsp
*hdsp
)
3019 switch (hdsp
->control_register
& HDSP_RPM_Inp12
) {
3020 case HDSP_RPM_Inp12_Phon_6dB
:
3022 case HDSP_RPM_Inp12_Phon_n6dB
:
3024 case HDSP_RPM_Inp12_Line_0dB
:
3026 case HDSP_RPM_Inp12_Line_n6dB
:
3033 static int snd_hdsp_get_rpm_input12(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
3035 struct hdsp
*hdsp
= snd_kcontrol_chip(kcontrol
);
3037 ucontrol
->value
.enumerated
.item
[0] = hdsp_rpm_input12(hdsp
);
3042 static int hdsp_set_rpm_input12(struct hdsp
*hdsp
, int mode
)
3044 hdsp
->control_register
&= ~HDSP_RPM_Inp12
;
3047 hdsp
->control_register
|= HDSP_RPM_Inp12_Phon_6dB
;
3052 hdsp
->control_register
|= HDSP_RPM_Inp12_Phon_n6dB
;
3055 hdsp
->control_register
|= HDSP_RPM_Inp12_Line_0dB
;
3058 hdsp
->control_register
|= HDSP_RPM_Inp12_Line_n6dB
;
3064 hdsp_write(hdsp
, HDSP_controlRegister
, hdsp
->control_register
);
3069 static int snd_hdsp_put_rpm_input12(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
3071 struct hdsp
*hdsp
= snd_kcontrol_chip(kcontrol
);
3075 if (!snd_hdsp_use_is_exclusive(hdsp
))
3077 val
= ucontrol
->value
.enumerated
.item
[0];
3082 spin_lock_irq(&hdsp
->lock
);
3083 if (val
!= hdsp_rpm_input12(hdsp
))
3084 change
= (hdsp_set_rpm_input12(hdsp
, val
) == 0) ? 1 : 0;
3087 spin_unlock_irq(&hdsp
->lock
);
3092 static int snd_hdsp_info_rpm_input(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_info
*uinfo
)
3094 static char *texts
[] = {"Phono +6dB", "Phono 0dB", "Phono -6dB", "Line 0dB", "Line -6dB"};
3096 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
3098 uinfo
->value
.enumerated
.items
= 5;
3099 if (uinfo
->value
.enumerated
.item
>= uinfo
->value
.enumerated
.items
)
3100 uinfo
->value
.enumerated
.item
= uinfo
->value
.enumerated
.items
- 1;
3101 strcpy(uinfo
->value
.enumerated
.name
, texts
[uinfo
->value
.enumerated
.item
]);
3106 static int hdsp_rpm_input34(struct hdsp
*hdsp
)
3108 switch (hdsp
->control_register
& HDSP_RPM_Inp34
) {
3109 case HDSP_RPM_Inp34_Phon_6dB
:
3111 case HDSP_RPM_Inp34_Phon_n6dB
:
3113 case HDSP_RPM_Inp34_Line_0dB
:
3115 case HDSP_RPM_Inp34_Line_n6dB
:
3122 static int snd_hdsp_get_rpm_input34(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
3124 struct hdsp
*hdsp
= snd_kcontrol_chip(kcontrol
);
3126 ucontrol
->value
.enumerated
.item
[0] = hdsp_rpm_input34(hdsp
);
3131 static int hdsp_set_rpm_input34(struct hdsp
*hdsp
, int mode
)
3133 hdsp
->control_register
&= ~HDSP_RPM_Inp34
;
3136 hdsp
->control_register
|= HDSP_RPM_Inp34_Phon_6dB
;
3141 hdsp
->control_register
|= HDSP_RPM_Inp34_Phon_n6dB
;
3144 hdsp
->control_register
|= HDSP_RPM_Inp34_Line_0dB
;
3147 hdsp
->control_register
|= HDSP_RPM_Inp34_Line_n6dB
;
3153 hdsp_write(hdsp
, HDSP_controlRegister
, hdsp
->control_register
);
3158 static int snd_hdsp_put_rpm_input34(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
3160 struct hdsp
*hdsp
= snd_kcontrol_chip(kcontrol
);
3164 if (!snd_hdsp_use_is_exclusive(hdsp
))
3166 val
= ucontrol
->value
.enumerated
.item
[0];
3171 spin_lock_irq(&hdsp
->lock
);
3172 if (val
!= hdsp_rpm_input34(hdsp
))
3173 change
= (hdsp_set_rpm_input34(hdsp
, val
) == 0) ? 1 : 0;
3176 spin_unlock_irq(&hdsp
->lock
);
3181 /* RPM Bypass switch */
3182 static int hdsp_rpm_bypass(struct hdsp
*hdsp
)
3184 return (hdsp
->control_register
& HDSP_RPM_Bypass
) ? 1 : 0;
3188 static int snd_hdsp_get_rpm_bypass(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
3190 struct hdsp
*hdsp
= snd_kcontrol_chip(kcontrol
);
3192 ucontrol
->value
.integer
.value
[0] = hdsp_rpm_bypass(hdsp
);
3197 static int hdsp_set_rpm_bypass(struct hdsp
*hdsp
, int on
)
3200 hdsp
->control_register
|= HDSP_RPM_Bypass
;
3202 hdsp
->control_register
&= ~HDSP_RPM_Bypass
;
3203 hdsp_write(hdsp
, HDSP_controlRegister
, hdsp
->control_register
);
3208 static int snd_hdsp_put_rpm_bypass(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
3210 struct hdsp
*hdsp
= snd_kcontrol_chip(kcontrol
);
3214 if (!snd_hdsp_use_is_exclusive(hdsp
))
3216 val
= ucontrol
->value
.integer
.value
[0] & 1;
3217 spin_lock_irq(&hdsp
->lock
);
3218 change
= (int)val
!= hdsp_rpm_bypass(hdsp
);
3219 hdsp_set_rpm_bypass(hdsp
, val
);
3220 spin_unlock_irq(&hdsp
->lock
);
3225 static int snd_hdsp_info_rpm_bypass(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_info
*uinfo
)
3227 static char *texts
[] = {"On", "Off"};
3229 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
3231 uinfo
->value
.enumerated
.items
= 2;
3232 if (uinfo
->value
.enumerated
.item
>= uinfo
->value
.enumerated
.items
)
3233 uinfo
->value
.enumerated
.item
= uinfo
->value
.enumerated
.items
- 1;
3234 strcpy(uinfo
->value
.enumerated
.name
, texts
[uinfo
->value
.enumerated
.item
]);
3239 /* RPM Disconnect switch */
3240 static int hdsp_rpm_disconnect(struct hdsp
*hdsp
)
3242 return (hdsp
->control_register
& HDSP_RPM_Disconnect
) ? 1 : 0;
3246 static int snd_hdsp_get_rpm_disconnect(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
3248 struct hdsp
*hdsp
= snd_kcontrol_chip(kcontrol
);
3250 ucontrol
->value
.integer
.value
[0] = hdsp_rpm_disconnect(hdsp
);
3255 static int hdsp_set_rpm_disconnect(struct hdsp
*hdsp
, int on
)
3258 hdsp
->control_register
|= HDSP_RPM_Disconnect
;
3260 hdsp
->control_register
&= ~HDSP_RPM_Disconnect
;
3261 hdsp_write(hdsp
, HDSP_controlRegister
, hdsp
->control_register
);
3266 static int snd_hdsp_put_rpm_disconnect(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
3268 struct hdsp
*hdsp
= snd_kcontrol_chip(kcontrol
);
3272 if (!snd_hdsp_use_is_exclusive(hdsp
))
3274 val
= ucontrol
->value
.integer
.value
[0] & 1;
3275 spin_lock_irq(&hdsp
->lock
);
3276 change
= (int)val
!= hdsp_rpm_disconnect(hdsp
);
3277 hdsp_set_rpm_disconnect(hdsp
, val
);
3278 spin_unlock_irq(&hdsp
->lock
);
3282 static int snd_hdsp_info_rpm_disconnect(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_info
*uinfo
)
3284 static char *texts
[] = {"On", "Off"};
3286 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
3288 uinfo
->value
.enumerated
.items
= 2;
3289 if (uinfo
->value
.enumerated
.item
>= uinfo
->value
.enumerated
.items
)
3290 uinfo
->value
.enumerated
.item
= uinfo
->value
.enumerated
.items
- 1;
3291 strcpy(uinfo
->value
.enumerated
.name
, texts
[uinfo
->value
.enumerated
.item
]);
3295 static struct snd_kcontrol_new snd_hdsp_rpm_controls
[] = {
3297 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
3298 .name
= "RPM Bypass",
3299 .get
= snd_hdsp_get_rpm_bypass
,
3300 .put
= snd_hdsp_put_rpm_bypass
,
3301 .info
= snd_hdsp_info_rpm_bypass
3304 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
3305 .name
= "RPM Disconnect",
3306 .get
= snd_hdsp_get_rpm_disconnect
,
3307 .put
= snd_hdsp_put_rpm_disconnect
,
3308 .info
= snd_hdsp_info_rpm_disconnect
3311 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
3312 .name
= "Input 1/2",
3313 .get
= snd_hdsp_get_rpm_input12
,
3314 .put
= snd_hdsp_put_rpm_input12
,
3315 .info
= snd_hdsp_info_rpm_input
3318 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
3319 .name
= "Input 3/4",
3320 .get
= snd_hdsp_get_rpm_input34
,
3321 .put
= snd_hdsp_put_rpm_input34
,
3322 .info
= snd_hdsp_info_rpm_input
3324 HDSP_SYSTEM_SAMPLE_RATE("System Sample Rate", 0),
3325 HDSP_MIXER("Mixer", 0)
3328 static struct snd_kcontrol_new snd_hdsp_96xx_aeb
=
3329 HDSP_TOGGLE_SETTING("Analog Extension Board",
3330 HDSP_AnalogExtensionBoard
);
3331 static struct snd_kcontrol_new snd_hdsp_adat_sync_check
= HDSP_ADAT_SYNC_CHECK
;
3333 static int snd_hdsp_create_controls(struct snd_card
*card
, struct hdsp
*hdsp
)
3337 struct snd_kcontrol
*kctl
;
3339 if (hdsp
->io_type
== RPM
) {
3340 /* RPM Bypass, Disconnect and Input switches */
3341 for (idx
= 0; idx
< ARRAY_SIZE(snd_hdsp_rpm_controls
); idx
++) {
3342 err
= snd_ctl_add(card
, kctl
= snd_ctl_new1(&snd_hdsp_rpm_controls
[idx
], hdsp
));
3349 for (idx
= 0; idx
< ARRAY_SIZE(snd_hdsp_controls
); idx
++) {
3350 if ((err
= snd_ctl_add(card
, kctl
= snd_ctl_new1(&snd_hdsp_controls
[idx
], hdsp
))) < 0)
3352 if (idx
== 1) /* IEC958 (S/PDIF) Stream */
3353 hdsp
->spdif_ctl
= kctl
;
3356 /* ADAT SyncCheck status */
3357 snd_hdsp_adat_sync_check
.name
= "ADAT Lock Status";
3358 snd_hdsp_adat_sync_check
.index
= 1;
3359 if ((err
= snd_ctl_add (card
, kctl
= snd_ctl_new1(&snd_hdsp_adat_sync_check
, hdsp
))))
3361 if (hdsp
->io_type
== Digiface
|| hdsp
->io_type
== H9652
) {
3362 for (idx
= 1; idx
< 3; ++idx
) {
3363 snd_hdsp_adat_sync_check
.index
= idx
+1;
3364 if ((err
= snd_ctl_add (card
, kctl
= snd_ctl_new1(&snd_hdsp_adat_sync_check
, hdsp
))))
3369 /* DA, AD and Phone gain and XLR breakout cable controls for H9632 cards */
3370 if (hdsp
->io_type
== H9632
) {
3371 for (idx
= 0; idx
< ARRAY_SIZE(snd_hdsp_9632_controls
); idx
++) {
3372 if ((err
= snd_ctl_add(card
, kctl
= snd_ctl_new1(&snd_hdsp_9632_controls
[idx
], hdsp
))) < 0)
3377 /* AEB control for H96xx card */
3378 if (hdsp
->io_type
== H9632
|| hdsp
->io_type
== H9652
) {
3379 if ((err
= snd_ctl_add(card
, kctl
= snd_ctl_new1(&snd_hdsp_96xx_aeb
, hdsp
))) < 0)
3386 /*------------------------------------------------------------
3388 ------------------------------------------------------------*/
3391 snd_hdsp_proc_read(struct snd_info_entry
*entry
, struct snd_info_buffer
*buffer
)
3393 struct hdsp
*hdsp
= entry
->private_data
;
3394 unsigned int status
;
3395 unsigned int status2
;
3396 char *pref_sync_ref
;
3398 char *system_clock_mode
;
3402 status
= hdsp_read(hdsp
, HDSP_statusRegister
);
3403 status2
= hdsp_read(hdsp
, HDSP_status2Register
);
3405 snd_iprintf(buffer
, "%s (Card #%d)\n", hdsp
->card_name
,
3406 hdsp
->card
->number
+ 1);
3407 snd_iprintf(buffer
, "Buffers: capture %p playback %p\n",
3408 hdsp
->capture_buffer
, hdsp
->playback_buffer
);
3409 snd_iprintf(buffer
, "IRQ: %d Registers bus: 0x%lx VM: 0x%lx\n",
3410 hdsp
->irq
, hdsp
->port
, (unsigned long)hdsp
->iobase
);
3411 snd_iprintf(buffer
, "Control register: 0x%x\n", hdsp
->control_register
);
3412 snd_iprintf(buffer
, "Control2 register: 0x%x\n",
3413 hdsp
->control2_register
);
3414 snd_iprintf(buffer
, "Status register: 0x%x\n", status
);
3415 snd_iprintf(buffer
, "Status2 register: 0x%x\n", status2
);
3417 if (hdsp_check_for_iobox(hdsp
)) {
3418 snd_iprintf(buffer
, "No I/O box connected.\n"
3419 "Please connect one and upload firmware.\n");
3423 if (hdsp_check_for_firmware(hdsp
, 0)) {
3424 if (hdsp
->state
& HDSP_FirmwareCached
) {
3425 if (snd_hdsp_load_firmware_from_cache(hdsp
) != 0) {
3426 snd_iprintf(buffer
, "Firmware loading from "
3428 "please upload manually.\n");
3433 err
= hdsp_request_fw_loader(hdsp
);
3436 "No firmware loaded nor cached, "
3437 "please upload firmware.\n");
3443 snd_iprintf(buffer
, "FIFO status: %d\n", hdsp_read(hdsp
, HDSP_fifoStatus
) & 0xff);
3444 snd_iprintf(buffer
, "MIDI1 Output status: 0x%x\n", hdsp_read(hdsp
, HDSP_midiStatusOut0
));
3445 snd_iprintf(buffer
, "MIDI1 Input status: 0x%x\n", hdsp_read(hdsp
, HDSP_midiStatusIn0
));
3446 snd_iprintf(buffer
, "MIDI2 Output status: 0x%x\n", hdsp_read(hdsp
, HDSP_midiStatusOut1
));
3447 snd_iprintf(buffer
, "MIDI2 Input status: 0x%x\n", hdsp_read(hdsp
, HDSP_midiStatusIn1
));
3448 snd_iprintf(buffer
, "Use Midi Tasklet: %s\n", hdsp
->use_midi_tasklet
? "on" : "off");
3450 snd_iprintf(buffer
, "\n");
3452 x
= 1 << (6 + hdsp_decode_latency(hdsp
->control_register
& HDSP_LatencyMask
));
3454 snd_iprintf(buffer
, "Buffer Size (Latency): %d samples (2 periods of %lu bytes)\n", x
, (unsigned long) hdsp
->period_bytes
);
3455 snd_iprintf(buffer
, "Hardware pointer (frames): %ld\n", hdsp_hw_pointer(hdsp
));
3456 snd_iprintf(buffer
, "Precise pointer: %s\n", hdsp
->precise_ptr
? "on" : "off");
3457 snd_iprintf(buffer
, "Line out: %s\n", (hdsp
->control_register
& HDSP_LineOut
) ? "on" : "off");
3459 snd_iprintf(buffer
, "Firmware version: %d\n", (status2
&HDSP_version0
)|(status2
&HDSP_version1
)<<1|(status2
&HDSP_version2
)<<2);
3461 snd_iprintf(buffer
, "\n");
3463 switch (hdsp_clock_source(hdsp
)) {
3464 case HDSP_CLOCK_SOURCE_AUTOSYNC
:
3465 clock_source
= "AutoSync";
3467 case HDSP_CLOCK_SOURCE_INTERNAL_32KHZ
:
3468 clock_source
= "Internal 32 kHz";
3470 case HDSP_CLOCK_SOURCE_INTERNAL_44_1KHZ
:
3471 clock_source
= "Internal 44.1 kHz";
3473 case HDSP_CLOCK_SOURCE_INTERNAL_48KHZ
:
3474 clock_source
= "Internal 48 kHz";
3476 case HDSP_CLOCK_SOURCE_INTERNAL_64KHZ
:
3477 clock_source
= "Internal 64 kHz";
3479 case HDSP_CLOCK_SOURCE_INTERNAL_88_2KHZ
:
3480 clock_source
= "Internal 88.2 kHz";
3482 case HDSP_CLOCK_SOURCE_INTERNAL_96KHZ
:
3483 clock_source
= "Internal 96 kHz";
3485 case HDSP_CLOCK_SOURCE_INTERNAL_128KHZ
:
3486 clock_source
= "Internal 128 kHz";
3488 case HDSP_CLOCK_SOURCE_INTERNAL_176_4KHZ
:
3489 clock_source
= "Internal 176.4 kHz";
3491 case HDSP_CLOCK_SOURCE_INTERNAL_192KHZ
:
3492 clock_source
= "Internal 192 kHz";
3495 clock_source
= "Error";
3497 snd_iprintf (buffer
, "Sample Clock Source: %s\n", clock_source
);
3499 if (hdsp_system_clock_mode(hdsp
))
3500 system_clock_mode
= "Slave";
3502 system_clock_mode
= "Master";
3504 switch (hdsp_pref_sync_ref (hdsp
)) {
3505 case HDSP_SYNC_FROM_WORD
:
3506 pref_sync_ref
= "Word Clock";
3508 case HDSP_SYNC_FROM_ADAT_SYNC
:
3509 pref_sync_ref
= "ADAT Sync";
3511 case HDSP_SYNC_FROM_SPDIF
:
3512 pref_sync_ref
= "SPDIF";
3514 case HDSP_SYNC_FROM_ADAT1
:
3515 pref_sync_ref
= "ADAT1";
3517 case HDSP_SYNC_FROM_ADAT2
:
3518 pref_sync_ref
= "ADAT2";
3520 case HDSP_SYNC_FROM_ADAT3
:
3521 pref_sync_ref
= "ADAT3";
3524 pref_sync_ref
= "Word Clock";
3527 snd_iprintf (buffer
, "Preferred Sync Reference: %s\n", pref_sync_ref
);
3529 switch (hdsp_autosync_ref (hdsp
)) {
3530 case HDSP_AUTOSYNC_FROM_WORD
:
3531 autosync_ref
= "Word Clock";
3533 case HDSP_AUTOSYNC_FROM_ADAT_SYNC
:
3534 autosync_ref
= "ADAT Sync";
3536 case HDSP_AUTOSYNC_FROM_SPDIF
:
3537 autosync_ref
= "SPDIF";
3539 case HDSP_AUTOSYNC_FROM_NONE
:
3540 autosync_ref
= "None";
3542 case HDSP_AUTOSYNC_FROM_ADAT1
:
3543 autosync_ref
= "ADAT1";
3545 case HDSP_AUTOSYNC_FROM_ADAT2
:
3546 autosync_ref
= "ADAT2";
3548 case HDSP_AUTOSYNC_FROM_ADAT3
:
3549 autosync_ref
= "ADAT3";
3552 autosync_ref
= "---";
3555 snd_iprintf (buffer
, "AutoSync Reference: %s\n", autosync_ref
);
3557 snd_iprintf (buffer
, "AutoSync Frequency: %d\n", hdsp_external_sample_rate(hdsp
));
3559 snd_iprintf (buffer
, "System Clock Mode: %s\n", system_clock_mode
);
3561 snd_iprintf (buffer
, "System Clock Frequency: %d\n", hdsp
->system_sample_rate
);
3562 snd_iprintf (buffer
, "System Clock Locked: %s\n", hdsp
->clock_source_locked
? "Yes" : "No");
3564 snd_iprintf(buffer
, "\n");
3566 if (hdsp
->io_type
!= RPM
) {
3567 switch (hdsp_spdif_in(hdsp
)) {
3568 case HDSP_SPDIFIN_OPTICAL
:
3569 snd_iprintf(buffer
, "IEC958 input: Optical\n");
3571 case HDSP_SPDIFIN_COAXIAL
:
3572 snd_iprintf(buffer
, "IEC958 input: Coaxial\n");
3574 case HDSP_SPDIFIN_INTERNAL
:
3575 snd_iprintf(buffer
, "IEC958 input: Internal\n");
3577 case HDSP_SPDIFIN_AES
:
3578 snd_iprintf(buffer
, "IEC958 input: AES\n");
3581 snd_iprintf(buffer
, "IEC958 input: ???\n");
3586 if (RPM
== hdsp
->io_type
) {
3587 if (hdsp
->control_register
& HDSP_RPM_Bypass
)
3588 snd_iprintf(buffer
, "RPM Bypass: disabled\n");
3590 snd_iprintf(buffer
, "RPM Bypass: enabled\n");
3591 if (hdsp
->control_register
& HDSP_RPM_Disconnect
)
3592 snd_iprintf(buffer
, "RPM disconnected\n");
3594 snd_iprintf(buffer
, "RPM connected\n");
3596 switch (hdsp
->control_register
& HDSP_RPM_Inp12
) {
3597 case HDSP_RPM_Inp12_Phon_6dB
:
3598 snd_iprintf(buffer
, "Input 1/2: Phono, 6dB\n");
3600 case HDSP_RPM_Inp12_Phon_0dB
:
3601 snd_iprintf(buffer
, "Input 1/2: Phono, 0dB\n");
3603 case HDSP_RPM_Inp12_Phon_n6dB
:
3604 snd_iprintf(buffer
, "Input 1/2: Phono, -6dB\n");
3606 case HDSP_RPM_Inp12_Line_0dB
:
3607 snd_iprintf(buffer
, "Input 1/2: Line, 0dB\n");
3609 case HDSP_RPM_Inp12_Line_n6dB
:
3610 snd_iprintf(buffer
, "Input 1/2: Line, -6dB\n");
3613 snd_iprintf(buffer
, "Input 1/2: ???\n");
3616 switch (hdsp
->control_register
& HDSP_RPM_Inp34
) {
3617 case HDSP_RPM_Inp34_Phon_6dB
:
3618 snd_iprintf(buffer
, "Input 3/4: Phono, 6dB\n");
3620 case HDSP_RPM_Inp34_Phon_0dB
:
3621 snd_iprintf(buffer
, "Input 3/4: Phono, 0dB\n");
3623 case HDSP_RPM_Inp34_Phon_n6dB
:
3624 snd_iprintf(buffer
, "Input 3/4: Phono, -6dB\n");
3626 case HDSP_RPM_Inp34_Line_0dB
:
3627 snd_iprintf(buffer
, "Input 3/4: Line, 0dB\n");
3629 case HDSP_RPM_Inp34_Line_n6dB
:
3630 snd_iprintf(buffer
, "Input 3/4: Line, -6dB\n");
3633 snd_iprintf(buffer
, "Input 3/4: ???\n");
3637 if (hdsp
->control_register
& HDSP_SPDIFOpticalOut
)
3638 snd_iprintf(buffer
, "IEC958 output: Coaxial & ADAT1\n");
3640 snd_iprintf(buffer
, "IEC958 output: Coaxial only\n");
3642 if (hdsp
->control_register
& HDSP_SPDIFProfessional
)
3643 snd_iprintf(buffer
, "IEC958 quality: Professional\n");
3645 snd_iprintf(buffer
, "IEC958 quality: Consumer\n");
3647 if (hdsp
->control_register
& HDSP_SPDIFEmphasis
)
3648 snd_iprintf(buffer
, "IEC958 emphasis: on\n");
3650 snd_iprintf(buffer
, "IEC958 emphasis: off\n");
3652 if (hdsp
->control_register
& HDSP_SPDIFNonAudio
)
3653 snd_iprintf(buffer
, "IEC958 NonAudio: on\n");
3655 snd_iprintf(buffer
, "IEC958 NonAudio: off\n");
3656 x
= hdsp_spdif_sample_rate(hdsp
);
3658 snd_iprintf(buffer
, "IEC958 sample rate: %d\n", x
);
3660 snd_iprintf(buffer
, "IEC958 sample rate: Error flag set\n");
3662 snd_iprintf(buffer
, "\n");
3665 x
= status
& HDSP_Sync0
;
3666 if (status
& HDSP_Lock0
)
3667 snd_iprintf(buffer
, "ADAT1: %s\n", x
? "Sync" : "Lock");
3669 snd_iprintf(buffer
, "ADAT1: No Lock\n");
3671 switch (hdsp
->io_type
) {
3674 x
= status
& HDSP_Sync1
;
3675 if (status
& HDSP_Lock1
)
3676 snd_iprintf(buffer
, "ADAT2: %s\n", x
? "Sync" : "Lock");
3678 snd_iprintf(buffer
, "ADAT2: No Lock\n");
3679 x
= status
& HDSP_Sync2
;
3680 if (status
& HDSP_Lock2
)
3681 snd_iprintf(buffer
, "ADAT3: %s\n", x
? "Sync" : "Lock");
3683 snd_iprintf(buffer
, "ADAT3: No Lock\n");
3690 x
= status
& HDSP_SPDIFSync
;
3691 if (status
& HDSP_SPDIFErrorFlag
)
3692 snd_iprintf (buffer
, "SPDIF: No Lock\n");
3694 snd_iprintf (buffer
, "SPDIF: %s\n", x
? "Sync" : "Lock");
3696 x
= status2
& HDSP_wc_sync
;
3697 if (status2
& HDSP_wc_lock
)
3698 snd_iprintf (buffer
, "Word Clock: %s\n", x
? "Sync" : "Lock");
3700 snd_iprintf (buffer
, "Word Clock: No Lock\n");
3702 x
= status
& HDSP_TimecodeSync
;
3703 if (status
& HDSP_TimecodeLock
)
3704 snd_iprintf(buffer
, "ADAT Sync: %s\n", x
? "Sync" : "Lock");
3706 snd_iprintf(buffer
, "ADAT Sync: No Lock\n");
3708 snd_iprintf(buffer
, "\n");
3710 /* Informations about H9632 specific controls */
3711 if (hdsp
->io_type
== H9632
) {
3714 switch (hdsp_ad_gain(hdsp
)) {
3725 snd_iprintf(buffer
, "AD Gain : %s\n", tmp
);
3727 switch (hdsp_da_gain(hdsp
)) {
3738 snd_iprintf(buffer
, "DA Gain : %s\n", tmp
);
3740 switch (hdsp_phone_gain(hdsp
)) {
3751 snd_iprintf(buffer
, "Phones Gain : %s\n", tmp
);
3753 snd_iprintf(buffer
, "XLR Breakout Cable : %s\n",
3754 hdsp_toggle_setting(hdsp
, HDSP_XLRBreakoutCable
) ?
3757 if (hdsp
->control_register
& HDSP_AnalogExtensionBoard
)
3758 snd_iprintf(buffer
, "AEB : on (ADAT1 internal)\n");
3760 snd_iprintf(buffer
, "AEB : off (ADAT1 external)\n");
3761 snd_iprintf(buffer
, "\n");
3766 static void snd_hdsp_proc_init(struct hdsp
*hdsp
)
3768 struct snd_info_entry
*entry
;
3770 if (! snd_card_proc_new(hdsp
->card
, "hdsp", &entry
))
3771 snd_info_set_text_ops(entry
, hdsp
, snd_hdsp_proc_read
);
3774 static void snd_hdsp_free_buffers(struct hdsp
*hdsp
)
3776 snd_hammerfall_free_buffer(&hdsp
->capture_dma_buf
, hdsp
->pci
);
3777 snd_hammerfall_free_buffer(&hdsp
->playback_dma_buf
, hdsp
->pci
);
3780 static int snd_hdsp_initialize_memory(struct hdsp
*hdsp
)
3782 unsigned long pb_bus
, cb_bus
;
3784 if (snd_hammerfall_get_buffer(hdsp
->pci
, &hdsp
->capture_dma_buf
, HDSP_DMA_AREA_BYTES
) < 0 ||
3785 snd_hammerfall_get_buffer(hdsp
->pci
, &hdsp
->playback_dma_buf
, HDSP_DMA_AREA_BYTES
) < 0) {
3786 if (hdsp
->capture_dma_buf
.area
)
3787 snd_dma_free_pages(&hdsp
->capture_dma_buf
);
3788 printk(KERN_ERR
"%s: no buffers available\n", hdsp
->card_name
);
3792 /* Align to bus-space 64K boundary */
3794 cb_bus
= ALIGN(hdsp
->capture_dma_buf
.addr
, 0x10000ul
);
3795 pb_bus
= ALIGN(hdsp
->playback_dma_buf
.addr
, 0x10000ul
);
3797 /* Tell the card where it is */
3799 hdsp_write(hdsp
, HDSP_inputBufferAddress
, cb_bus
);
3800 hdsp_write(hdsp
, HDSP_outputBufferAddress
, pb_bus
);
3802 hdsp
->capture_buffer
= hdsp
->capture_dma_buf
.area
+ (cb_bus
- hdsp
->capture_dma_buf
.addr
);
3803 hdsp
->playback_buffer
= hdsp
->playback_dma_buf
.area
+ (pb_bus
- hdsp
->playback_dma_buf
.addr
);
3808 static int snd_hdsp_set_defaults(struct hdsp
*hdsp
)
3812 /* ASSUMPTION: hdsp->lock is either held, or
3813 there is no need to hold it (e.g. during module
3819 SPDIF Input via Coax
3821 maximum latency (7 => 2^7 = 8192 samples, 64Kbyte buffer,
3822 which implies 2 4096 sample, 32Kbyte periods).
3826 hdsp
->control_register
= HDSP_ClockModeMaster
|
3827 HDSP_SPDIFInputCoaxial
|
3828 hdsp_encode_latency(7) |
3832 hdsp_write(hdsp
, HDSP_controlRegister
, hdsp
->control_register
);
3834 #ifdef SNDRV_BIG_ENDIAN
3835 hdsp
->control2_register
= HDSP_BIGENDIAN_MODE
;
3837 hdsp
->control2_register
= 0;
3839 if (hdsp
->io_type
== H9652
)
3840 snd_hdsp_9652_enable_mixer (hdsp
);
3842 hdsp_write (hdsp
, HDSP_control2Reg
, hdsp
->control2_register
);
3844 hdsp_reset_hw_pointer(hdsp
);
3845 hdsp_compute_period_size(hdsp
);
3847 /* silence everything */
3849 for (i
= 0; i
< HDSP_MATRIX_MIXER_SIZE
; ++i
)
3850 hdsp
->mixer_matrix
[i
] = MINUS_INFINITY_GAIN
;
3852 for (i
= 0; i
< ((hdsp
->io_type
== H9652
|| hdsp
->io_type
== H9632
) ? 1352 : HDSP_MATRIX_MIXER_SIZE
); ++i
) {
3853 if (hdsp_write_gain (hdsp
, i
, MINUS_INFINITY_GAIN
))
3857 /* H9632 specific defaults */
3858 if (hdsp
->io_type
== H9632
) {
3859 hdsp
->control_register
|= (HDSP_DAGainPlus4dBu
| HDSP_ADGainPlus4dBu
| HDSP_PhoneGain0dB
);
3860 hdsp_write(hdsp
, HDSP_controlRegister
, hdsp
->control_register
);
3863 /* set a default rate so that the channel map is set up.
3866 hdsp_set_rate(hdsp
, 48000, 1);
3871 static void hdsp_midi_tasklet(unsigned long arg
)
3873 struct hdsp
*hdsp
= (struct hdsp
*)arg
;
3875 if (hdsp
->midi
[0].pending
)
3876 snd_hdsp_midi_input_read (&hdsp
->midi
[0]);
3877 if (hdsp
->midi
[1].pending
)
3878 snd_hdsp_midi_input_read (&hdsp
->midi
[1]);
3881 static irqreturn_t
snd_hdsp_interrupt(int irq
, void *dev_id
)
3883 struct hdsp
*hdsp
= (struct hdsp
*) dev_id
;
3884 unsigned int status
;
3888 unsigned int midi0status
;
3889 unsigned int midi1status
;
3892 status
= hdsp_read(hdsp
, HDSP_statusRegister
);
3894 audio
= status
& HDSP_audioIRQPending
;
3895 midi0
= status
& HDSP_midi0IRQPending
;
3896 midi1
= status
& HDSP_midi1IRQPending
;
3898 if (!audio
&& !midi0
&& !midi1
)
3901 hdsp_write(hdsp
, HDSP_interruptConfirmation
, 0);
3903 midi0status
= hdsp_read (hdsp
, HDSP_midiStatusIn0
) & 0xff;
3904 midi1status
= hdsp_read (hdsp
, HDSP_midiStatusIn1
) & 0xff;
3906 if (!(hdsp
->state
& HDSP_InitializationComplete
))
3910 if (hdsp
->capture_substream
)
3911 snd_pcm_period_elapsed(hdsp
->pcm
->streams
[SNDRV_PCM_STREAM_CAPTURE
].substream
);
3913 if (hdsp
->playback_substream
)
3914 snd_pcm_period_elapsed(hdsp
->pcm
->streams
[SNDRV_PCM_STREAM_PLAYBACK
].substream
);
3917 if (midi0
&& midi0status
) {
3918 if (hdsp
->use_midi_tasklet
) {
3919 /* we disable interrupts for this input until processing is done */
3920 hdsp
->control_register
&= ~HDSP_Midi0InterruptEnable
;
3921 hdsp_write(hdsp
, HDSP_controlRegister
, hdsp
->control_register
);
3922 hdsp
->midi
[0].pending
= 1;
3925 snd_hdsp_midi_input_read (&hdsp
->midi
[0]);
3928 if (hdsp
->io_type
!= Multiface
&& hdsp
->io_type
!= RPM
&& hdsp
->io_type
!= H9632
&& midi1
&& midi1status
) {
3929 if (hdsp
->use_midi_tasklet
) {
3930 /* we disable interrupts for this input until processing is done */
3931 hdsp
->control_register
&= ~HDSP_Midi1InterruptEnable
;
3932 hdsp_write(hdsp
, HDSP_controlRegister
, hdsp
->control_register
);
3933 hdsp
->midi
[1].pending
= 1;
3936 snd_hdsp_midi_input_read (&hdsp
->midi
[1]);
3939 if (hdsp
->use_midi_tasklet
&& schedule
)
3940 tasklet_schedule(&hdsp
->midi_tasklet
);
3944 static snd_pcm_uframes_t
snd_hdsp_hw_pointer(struct snd_pcm_substream
*substream
)
3946 struct hdsp
*hdsp
= snd_pcm_substream_chip(substream
);
3947 return hdsp_hw_pointer(hdsp
);
3950 static char *hdsp_channel_buffer_location(struct hdsp
*hdsp
,
3957 if (snd_BUG_ON(channel
< 0 || channel
>= hdsp
->max_channels
))
3960 if ((mapped_channel
= hdsp
->channel_map
[channel
]) < 0)
3963 if (stream
== SNDRV_PCM_STREAM_CAPTURE
)
3964 return hdsp
->capture_buffer
+ (mapped_channel
* HDSP_CHANNEL_BUFFER_BYTES
);
3966 return hdsp
->playback_buffer
+ (mapped_channel
* HDSP_CHANNEL_BUFFER_BYTES
);
3969 static int snd_hdsp_playback_copy(struct snd_pcm_substream
*substream
, int channel
,
3970 snd_pcm_uframes_t pos
, void __user
*src
, snd_pcm_uframes_t count
)
3972 struct hdsp
*hdsp
= snd_pcm_substream_chip(substream
);
3975 if (snd_BUG_ON(pos
+ count
> HDSP_CHANNEL_BUFFER_BYTES
/ 4))
3978 channel_buf
= hdsp_channel_buffer_location (hdsp
, substream
->pstr
->stream
, channel
);
3979 if (snd_BUG_ON(!channel_buf
))
3981 if (copy_from_user(channel_buf
+ pos
* 4, src
, count
* 4))
3986 static int snd_hdsp_capture_copy(struct snd_pcm_substream
*substream
, int channel
,
3987 snd_pcm_uframes_t pos
, void __user
*dst
, snd_pcm_uframes_t count
)
3989 struct hdsp
*hdsp
= snd_pcm_substream_chip(substream
);
3992 if (snd_BUG_ON(pos
+ count
> HDSP_CHANNEL_BUFFER_BYTES
/ 4))
3995 channel_buf
= hdsp_channel_buffer_location (hdsp
, substream
->pstr
->stream
, channel
);
3996 if (snd_BUG_ON(!channel_buf
))
3998 if (copy_to_user(dst
, channel_buf
+ pos
* 4, count
* 4))
4003 static int snd_hdsp_hw_silence(struct snd_pcm_substream
*substream
, int channel
,
4004 snd_pcm_uframes_t pos
, snd_pcm_uframes_t count
)
4006 struct hdsp
*hdsp
= snd_pcm_substream_chip(substream
);
4009 channel_buf
= hdsp_channel_buffer_location (hdsp
, substream
->pstr
->stream
, channel
);
4010 if (snd_BUG_ON(!channel_buf
))
4012 memset(channel_buf
+ pos
* 4, 0, count
* 4);
4016 static int snd_hdsp_reset(struct snd_pcm_substream
*substream
)
4018 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
4019 struct hdsp
*hdsp
= snd_pcm_substream_chip(substream
);
4020 struct snd_pcm_substream
*other
;
4021 if (substream
->stream
== SNDRV_PCM_STREAM_PLAYBACK
)
4022 other
= hdsp
->capture_substream
;
4024 other
= hdsp
->playback_substream
;
4026 runtime
->status
->hw_ptr
= hdsp_hw_pointer(hdsp
);
4028 runtime
->status
->hw_ptr
= 0;
4030 struct snd_pcm_substream
*s
;
4031 struct snd_pcm_runtime
*oruntime
= other
->runtime
;
4032 snd_pcm_group_for_each_entry(s
, substream
) {
4034 oruntime
->status
->hw_ptr
= runtime
->status
->hw_ptr
;
4042 static int snd_hdsp_hw_params(struct snd_pcm_substream
*substream
,
4043 struct snd_pcm_hw_params
*params
)
4045 struct hdsp
*hdsp
= snd_pcm_substream_chip(substream
);
4050 if (hdsp_check_for_iobox (hdsp
))
4053 if (hdsp_check_for_firmware(hdsp
, 1))
4056 spin_lock_irq(&hdsp
->lock
);
4058 if (substream
->pstr
->stream
== SNDRV_PCM_STREAM_PLAYBACK
) {
4059 hdsp
->control_register
&= ~(HDSP_SPDIFProfessional
| HDSP_SPDIFNonAudio
| HDSP_SPDIFEmphasis
);
4060 hdsp_write(hdsp
, HDSP_controlRegister
, hdsp
->control_register
|= hdsp
->creg_spdif_stream
);
4061 this_pid
= hdsp
->playback_pid
;
4062 other_pid
= hdsp
->capture_pid
;
4064 this_pid
= hdsp
->capture_pid
;
4065 other_pid
= hdsp
->playback_pid
;
4068 if ((other_pid
> 0) && (this_pid
!= other_pid
)) {
4070 /* The other stream is open, and not by the same
4071 task as this one. Make sure that the parameters
4072 that matter are the same.
4075 if (params_rate(params
) != hdsp
->system_sample_rate
) {
4076 spin_unlock_irq(&hdsp
->lock
);
4077 _snd_pcm_hw_param_setempty(params
, SNDRV_PCM_HW_PARAM_RATE
);
4081 if (params_period_size(params
) != hdsp
->period_bytes
/ 4) {
4082 spin_unlock_irq(&hdsp
->lock
);
4083 _snd_pcm_hw_param_setempty(params
, SNDRV_PCM_HW_PARAM_PERIOD_SIZE
);
4089 spin_unlock_irq(&hdsp
->lock
);
4093 spin_unlock_irq(&hdsp
->lock
);
4096 /* how to make sure that the rate matches an externally-set one ?
4099 spin_lock_irq(&hdsp
->lock
);
4100 if (! hdsp
->clock_source_locked
) {
4101 if ((err
= hdsp_set_rate(hdsp
, params_rate(params
), 0)) < 0) {
4102 spin_unlock_irq(&hdsp
->lock
);
4103 _snd_pcm_hw_param_setempty(params
, SNDRV_PCM_HW_PARAM_RATE
);
4107 spin_unlock_irq(&hdsp
->lock
);
4109 if ((err
= hdsp_set_interrupt_interval(hdsp
, params_period_size(params
))) < 0) {
4110 _snd_pcm_hw_param_setempty(params
, SNDRV_PCM_HW_PARAM_PERIOD_SIZE
);
4117 static int snd_hdsp_channel_info(struct snd_pcm_substream
*substream
,
4118 struct snd_pcm_channel_info
*info
)
4120 struct hdsp
*hdsp
= snd_pcm_substream_chip(substream
);
4123 if (snd_BUG_ON(info
->channel
>= hdsp
->max_channels
))
4126 if ((mapped_channel
= hdsp
->channel_map
[info
->channel
]) < 0)
4129 info
->offset
= mapped_channel
* HDSP_CHANNEL_BUFFER_BYTES
;
4135 static int snd_hdsp_ioctl(struct snd_pcm_substream
*substream
,
4136 unsigned int cmd
, void *arg
)
4139 case SNDRV_PCM_IOCTL1_RESET
:
4140 return snd_hdsp_reset(substream
);
4141 case SNDRV_PCM_IOCTL1_CHANNEL_INFO
:
4142 return snd_hdsp_channel_info(substream
, arg
);
4147 return snd_pcm_lib_ioctl(substream
, cmd
, arg
);
4150 static int snd_hdsp_trigger(struct snd_pcm_substream
*substream
, int cmd
)
4152 struct hdsp
*hdsp
= snd_pcm_substream_chip(substream
);
4153 struct snd_pcm_substream
*other
;
4156 if (hdsp_check_for_iobox (hdsp
))
4159 if (hdsp_check_for_firmware(hdsp
, 0)) /* no auto-loading in trigger */
4162 spin_lock(&hdsp
->lock
);
4163 running
= hdsp
->running
;
4165 case SNDRV_PCM_TRIGGER_START
:
4166 running
|= 1 << substream
->stream
;
4168 case SNDRV_PCM_TRIGGER_STOP
:
4169 running
&= ~(1 << substream
->stream
);
4173 spin_unlock(&hdsp
->lock
);
4176 if (substream
->stream
== SNDRV_PCM_STREAM_PLAYBACK
)
4177 other
= hdsp
->capture_substream
;
4179 other
= hdsp
->playback_substream
;
4182 struct snd_pcm_substream
*s
;
4183 snd_pcm_group_for_each_entry(s
, substream
) {
4185 snd_pcm_trigger_done(s
, substream
);
4186 if (cmd
== SNDRV_PCM_TRIGGER_START
)
4187 running
|= 1 << s
->stream
;
4189 running
&= ~(1 << s
->stream
);
4193 if (cmd
== SNDRV_PCM_TRIGGER_START
) {
4194 if (!(running
& (1 << SNDRV_PCM_STREAM_PLAYBACK
)) &&
4195 substream
->stream
== SNDRV_PCM_STREAM_CAPTURE
)
4196 hdsp_silence_playback(hdsp
);
4199 substream
->stream
== SNDRV_PCM_STREAM_PLAYBACK
)
4200 hdsp_silence_playback(hdsp
);
4203 if (substream
->stream
== SNDRV_PCM_STREAM_CAPTURE
)
4204 hdsp_silence_playback(hdsp
);
4207 snd_pcm_trigger_done(substream
, substream
);
4208 if (!hdsp
->running
&& running
)
4209 hdsp_start_audio(hdsp
);
4210 else if (hdsp
->running
&& !running
)
4211 hdsp_stop_audio(hdsp
);
4212 hdsp
->running
= running
;
4213 spin_unlock(&hdsp
->lock
);
4218 static int snd_hdsp_prepare(struct snd_pcm_substream
*substream
)
4220 struct hdsp
*hdsp
= snd_pcm_substream_chip(substream
);
4223 if (hdsp_check_for_iobox (hdsp
))
4226 if (hdsp_check_for_firmware(hdsp
, 1))
4229 spin_lock_irq(&hdsp
->lock
);
4231 hdsp_reset_hw_pointer(hdsp
);
4232 spin_unlock_irq(&hdsp
->lock
);
4236 static struct snd_pcm_hardware snd_hdsp_playback_subinfo
=
4238 .info
= (SNDRV_PCM_INFO_MMAP
|
4239 SNDRV_PCM_INFO_MMAP_VALID
|
4240 SNDRV_PCM_INFO_NONINTERLEAVED
|
4241 SNDRV_PCM_INFO_SYNC_START
|
4242 SNDRV_PCM_INFO_DOUBLE
),
4243 #ifdef SNDRV_BIG_ENDIAN
4244 .formats
= SNDRV_PCM_FMTBIT_S32_BE
,
4246 .formats
= SNDRV_PCM_FMTBIT_S32_LE
,
4248 .rates
= (SNDRV_PCM_RATE_32000
|
4249 SNDRV_PCM_RATE_44100
|
4250 SNDRV_PCM_RATE_48000
|
4251 SNDRV_PCM_RATE_64000
|
4252 SNDRV_PCM_RATE_88200
|
4253 SNDRV_PCM_RATE_96000
),
4257 .channels_max
= HDSP_MAX_CHANNELS
,
4258 .buffer_bytes_max
= HDSP_CHANNEL_BUFFER_BYTES
* HDSP_MAX_CHANNELS
,
4259 .period_bytes_min
= (64 * 4) * 10,
4260 .period_bytes_max
= (8192 * 4) * HDSP_MAX_CHANNELS
,
4266 static struct snd_pcm_hardware snd_hdsp_capture_subinfo
=
4268 .info
= (SNDRV_PCM_INFO_MMAP
|
4269 SNDRV_PCM_INFO_MMAP_VALID
|
4270 SNDRV_PCM_INFO_NONINTERLEAVED
|
4271 SNDRV_PCM_INFO_SYNC_START
),
4272 #ifdef SNDRV_BIG_ENDIAN
4273 .formats
= SNDRV_PCM_FMTBIT_S32_BE
,
4275 .formats
= SNDRV_PCM_FMTBIT_S32_LE
,
4277 .rates
= (SNDRV_PCM_RATE_32000
|
4278 SNDRV_PCM_RATE_44100
|
4279 SNDRV_PCM_RATE_48000
|
4280 SNDRV_PCM_RATE_64000
|
4281 SNDRV_PCM_RATE_88200
|
4282 SNDRV_PCM_RATE_96000
),
4286 .channels_max
= HDSP_MAX_CHANNELS
,
4287 .buffer_bytes_max
= HDSP_CHANNEL_BUFFER_BYTES
* HDSP_MAX_CHANNELS
,
4288 .period_bytes_min
= (64 * 4) * 10,
4289 .period_bytes_max
= (8192 * 4) * HDSP_MAX_CHANNELS
,
4295 static unsigned int hdsp_period_sizes
[] = { 64, 128, 256, 512, 1024, 2048, 4096, 8192 };
4297 static struct snd_pcm_hw_constraint_list hdsp_hw_constraints_period_sizes
= {
4298 .count
= ARRAY_SIZE(hdsp_period_sizes
),
4299 .list
= hdsp_period_sizes
,
4303 static unsigned int hdsp_9632_sample_rates
[] = { 32000, 44100, 48000, 64000, 88200, 96000, 128000, 176400, 192000 };
4305 static struct snd_pcm_hw_constraint_list hdsp_hw_constraints_9632_sample_rates
= {
4306 .count
= ARRAY_SIZE(hdsp_9632_sample_rates
),
4307 .list
= hdsp_9632_sample_rates
,
4311 static int snd_hdsp_hw_rule_in_channels(struct snd_pcm_hw_params
*params
,
4312 struct snd_pcm_hw_rule
*rule
)
4314 struct hdsp
*hdsp
= rule
->private;
4315 struct snd_interval
*c
= hw_param_interval(params
, SNDRV_PCM_HW_PARAM_CHANNELS
);
4316 if (hdsp
->io_type
== H9632
) {
4317 unsigned int list
[3];
4318 list
[0] = hdsp
->qs_in_channels
;
4319 list
[1] = hdsp
->ds_in_channels
;
4320 list
[2] = hdsp
->ss_in_channels
;
4321 return snd_interval_list(c
, 3, list
, 0);
4323 unsigned int list
[2];
4324 list
[0] = hdsp
->ds_in_channels
;
4325 list
[1] = hdsp
->ss_in_channels
;
4326 return snd_interval_list(c
, 2, list
, 0);
4330 static int snd_hdsp_hw_rule_out_channels(struct snd_pcm_hw_params
*params
,
4331 struct snd_pcm_hw_rule
*rule
)
4333 unsigned int list
[3];
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 list
[0] = hdsp
->qs_out_channels
;
4338 list
[1] = hdsp
->ds_out_channels
;
4339 list
[2] = hdsp
->ss_out_channels
;
4340 return snd_interval_list(c
, 3, list
, 0);
4342 list
[0] = hdsp
->ds_out_channels
;
4343 list
[1] = hdsp
->ss_out_channels
;
4345 return snd_interval_list(c
, 2, list
, 0);
4348 static int snd_hdsp_hw_rule_in_channels_rate(struct snd_pcm_hw_params
*params
,
4349 struct snd_pcm_hw_rule
*rule
)
4351 struct hdsp
*hdsp
= rule
->private;
4352 struct snd_interval
*c
= hw_param_interval(params
, SNDRV_PCM_HW_PARAM_CHANNELS
);
4353 struct snd_interval
*r
= hw_param_interval(params
, SNDRV_PCM_HW_PARAM_RATE
);
4354 if (r
->min
> 96000 && hdsp
->io_type
== H9632
) {
4355 struct snd_interval t
= {
4356 .min
= hdsp
->qs_in_channels
,
4357 .max
= hdsp
->qs_in_channels
,
4360 return snd_interval_refine(c
, &t
);
4361 } else if (r
->min
> 48000 && r
->max
<= 96000) {
4362 struct snd_interval t
= {
4363 .min
= hdsp
->ds_in_channels
,
4364 .max
= hdsp
->ds_in_channels
,
4367 return snd_interval_refine(c
, &t
);
4368 } else if (r
->max
< 64000) {
4369 struct snd_interval t
= {
4370 .min
= hdsp
->ss_in_channels
,
4371 .max
= hdsp
->ss_in_channels
,
4374 return snd_interval_refine(c
, &t
);
4379 static int snd_hdsp_hw_rule_out_channels_rate(struct snd_pcm_hw_params
*params
,
4380 struct snd_pcm_hw_rule
*rule
)
4382 struct hdsp
*hdsp
= rule
->private;
4383 struct snd_interval
*c
= hw_param_interval(params
, SNDRV_PCM_HW_PARAM_CHANNELS
);
4384 struct snd_interval
*r
= hw_param_interval(params
, SNDRV_PCM_HW_PARAM_RATE
);
4385 if (r
->min
> 96000 && hdsp
->io_type
== H9632
) {
4386 struct snd_interval t
= {
4387 .min
= hdsp
->qs_out_channels
,
4388 .max
= hdsp
->qs_out_channels
,
4391 return snd_interval_refine(c
, &t
);
4392 } else if (r
->min
> 48000 && r
->max
<= 96000) {
4393 struct snd_interval t
= {
4394 .min
= hdsp
->ds_out_channels
,
4395 .max
= hdsp
->ds_out_channels
,
4398 return snd_interval_refine(c
, &t
);
4399 } else if (r
->max
< 64000) {
4400 struct snd_interval t
= {
4401 .min
= hdsp
->ss_out_channels
,
4402 .max
= hdsp
->ss_out_channels
,
4405 return snd_interval_refine(c
, &t
);
4410 static int snd_hdsp_hw_rule_rate_out_channels(struct snd_pcm_hw_params
*params
,
4411 struct snd_pcm_hw_rule
*rule
)
4413 struct hdsp
*hdsp
= rule
->private;
4414 struct snd_interval
*c
= hw_param_interval(params
, SNDRV_PCM_HW_PARAM_CHANNELS
);
4415 struct snd_interval
*r
= hw_param_interval(params
, SNDRV_PCM_HW_PARAM_RATE
);
4416 if (c
->min
>= hdsp
->ss_out_channels
) {
4417 struct snd_interval t
= {
4422 return snd_interval_refine(r
, &t
);
4423 } else if (c
->max
<= hdsp
->qs_out_channels
&& hdsp
->io_type
== H9632
) {
4424 struct snd_interval t
= {
4429 return snd_interval_refine(r
, &t
);
4430 } else if (c
->max
<= hdsp
->ds_out_channels
) {
4431 struct snd_interval t
= {
4436 return snd_interval_refine(r
, &t
);
4441 static int snd_hdsp_hw_rule_rate_in_channels(struct snd_pcm_hw_params
*params
,
4442 struct snd_pcm_hw_rule
*rule
)
4444 struct hdsp
*hdsp
= rule
->private;
4445 struct snd_interval
*c
= hw_param_interval(params
, SNDRV_PCM_HW_PARAM_CHANNELS
);
4446 struct snd_interval
*r
= hw_param_interval(params
, SNDRV_PCM_HW_PARAM_RATE
);
4447 if (c
->min
>= hdsp
->ss_in_channels
) {
4448 struct snd_interval t
= {
4453 return snd_interval_refine(r
, &t
);
4454 } else if (c
->max
<= hdsp
->qs_in_channels
&& hdsp
->io_type
== H9632
) {
4455 struct snd_interval t
= {
4460 return snd_interval_refine(r
, &t
);
4461 } else if (c
->max
<= hdsp
->ds_in_channels
) {
4462 struct snd_interval t
= {
4467 return snd_interval_refine(r
, &t
);
4472 static int snd_hdsp_playback_open(struct snd_pcm_substream
*substream
)
4474 struct hdsp
*hdsp
= snd_pcm_substream_chip(substream
);
4475 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
4477 if (hdsp_check_for_iobox (hdsp
))
4480 if (hdsp_check_for_firmware(hdsp
, 1))
4483 spin_lock_irq(&hdsp
->lock
);
4485 snd_pcm_set_sync(substream
);
4487 runtime
->hw
= snd_hdsp_playback_subinfo
;
4488 runtime
->dma_area
= hdsp
->playback_buffer
;
4489 runtime
->dma_bytes
= HDSP_DMA_AREA_BYTES
;
4491 hdsp
->playback_pid
= current
->pid
;
4492 hdsp
->playback_substream
= substream
;
4494 spin_unlock_irq(&hdsp
->lock
);
4496 snd_pcm_hw_constraint_msbits(runtime
, 0, 32, 24);
4497 snd_pcm_hw_constraint_list(runtime
, 0, SNDRV_PCM_HW_PARAM_PERIOD_SIZE
, &hdsp_hw_constraints_period_sizes
);
4498 if (hdsp
->clock_source_locked
) {
4499 runtime
->hw
.rate_min
= runtime
->hw
.rate_max
= hdsp
->system_sample_rate
;
4500 } else if (hdsp
->io_type
== H9632
) {
4501 runtime
->hw
.rate_max
= 192000;
4502 runtime
->hw
.rates
= SNDRV_PCM_RATE_KNOT
;
4503 snd_pcm_hw_constraint_list(runtime
, 0, SNDRV_PCM_HW_PARAM_RATE
, &hdsp_hw_constraints_9632_sample_rates
);
4505 if (hdsp
->io_type
== H9632
) {
4506 runtime
->hw
.channels_min
= hdsp
->qs_out_channels
;
4507 runtime
->hw
.channels_max
= hdsp
->ss_out_channels
;
4510 snd_pcm_hw_rule_add(runtime
, 0, SNDRV_PCM_HW_PARAM_CHANNELS
,
4511 snd_hdsp_hw_rule_out_channels
, hdsp
,
4512 SNDRV_PCM_HW_PARAM_CHANNELS
, -1);
4513 snd_pcm_hw_rule_add(runtime
, 0, SNDRV_PCM_HW_PARAM_CHANNELS
,
4514 snd_hdsp_hw_rule_out_channels_rate
, hdsp
,
4515 SNDRV_PCM_HW_PARAM_RATE
, -1);
4516 snd_pcm_hw_rule_add(runtime
, 0, SNDRV_PCM_HW_PARAM_RATE
,
4517 snd_hdsp_hw_rule_rate_out_channels
, hdsp
,
4518 SNDRV_PCM_HW_PARAM_CHANNELS
, -1);
4520 if (RPM
!= hdsp
->io_type
) {
4521 hdsp
->creg_spdif_stream
= hdsp
->creg_spdif
;
4522 hdsp
->spdif_ctl
->vd
[0].access
&= ~SNDRV_CTL_ELEM_ACCESS_INACTIVE
;
4523 snd_ctl_notify(hdsp
->card
, SNDRV_CTL_EVENT_MASK_VALUE
|
4524 SNDRV_CTL_EVENT_MASK_INFO
, &hdsp
->spdif_ctl
->id
);
4529 static int snd_hdsp_playback_release(struct snd_pcm_substream
*substream
)
4531 struct hdsp
*hdsp
= snd_pcm_substream_chip(substream
);
4533 spin_lock_irq(&hdsp
->lock
);
4535 hdsp
->playback_pid
= -1;
4536 hdsp
->playback_substream
= NULL
;
4538 spin_unlock_irq(&hdsp
->lock
);
4540 if (RPM
!= hdsp
->io_type
) {
4541 hdsp
->spdif_ctl
->vd
[0].access
|= SNDRV_CTL_ELEM_ACCESS_INACTIVE
;
4542 snd_ctl_notify(hdsp
->card
, SNDRV_CTL_EVENT_MASK_VALUE
|
4543 SNDRV_CTL_EVENT_MASK_INFO
, &hdsp
->spdif_ctl
->id
);
4549 static int snd_hdsp_capture_open(struct snd_pcm_substream
*substream
)
4551 struct hdsp
*hdsp
= snd_pcm_substream_chip(substream
);
4552 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
4554 if (hdsp_check_for_iobox (hdsp
))
4557 if (hdsp_check_for_firmware(hdsp
, 1))
4560 spin_lock_irq(&hdsp
->lock
);
4562 snd_pcm_set_sync(substream
);
4564 runtime
->hw
= snd_hdsp_capture_subinfo
;
4565 runtime
->dma_area
= hdsp
->capture_buffer
;
4566 runtime
->dma_bytes
= HDSP_DMA_AREA_BYTES
;
4568 hdsp
->capture_pid
= current
->pid
;
4569 hdsp
->capture_substream
= substream
;
4571 spin_unlock_irq(&hdsp
->lock
);
4573 snd_pcm_hw_constraint_msbits(runtime
, 0, 32, 24);
4574 snd_pcm_hw_constraint_list(runtime
, 0, SNDRV_PCM_HW_PARAM_PERIOD_SIZE
, &hdsp_hw_constraints_period_sizes
);
4575 if (hdsp
->io_type
== H9632
) {
4576 runtime
->hw
.channels_min
= hdsp
->qs_in_channels
;
4577 runtime
->hw
.channels_max
= hdsp
->ss_in_channels
;
4578 runtime
->hw
.rate_max
= 192000;
4579 runtime
->hw
.rates
= SNDRV_PCM_RATE_KNOT
;
4580 snd_pcm_hw_constraint_list(runtime
, 0, SNDRV_PCM_HW_PARAM_RATE
, &hdsp_hw_constraints_9632_sample_rates
);
4582 snd_pcm_hw_rule_add(runtime
, 0, SNDRV_PCM_HW_PARAM_CHANNELS
,
4583 snd_hdsp_hw_rule_in_channels
, hdsp
,
4584 SNDRV_PCM_HW_PARAM_CHANNELS
, -1);
4585 snd_pcm_hw_rule_add(runtime
, 0, SNDRV_PCM_HW_PARAM_CHANNELS
,
4586 snd_hdsp_hw_rule_in_channels_rate
, hdsp
,
4587 SNDRV_PCM_HW_PARAM_RATE
, -1);
4588 snd_pcm_hw_rule_add(runtime
, 0, SNDRV_PCM_HW_PARAM_RATE
,
4589 snd_hdsp_hw_rule_rate_in_channels
, hdsp
,
4590 SNDRV_PCM_HW_PARAM_CHANNELS
, -1);
4594 static int snd_hdsp_capture_release(struct snd_pcm_substream
*substream
)
4596 struct hdsp
*hdsp
= snd_pcm_substream_chip(substream
);
4598 spin_lock_irq(&hdsp
->lock
);
4600 hdsp
->capture_pid
= -1;
4601 hdsp
->capture_substream
= NULL
;
4603 spin_unlock_irq(&hdsp
->lock
);
4607 /* helper functions for copying meter values */
4608 static inline int copy_u32_le(void __user
*dest
, void __iomem
*src
)
4610 u32 val
= readl(src
);
4611 return copy_to_user(dest
, &val
, 4);
4614 static inline int copy_u64_le(void __user
*dest
, void __iomem
*src_low
, void __iomem
*src_high
)
4616 u32 rms_low
, rms_high
;
4618 rms_low
= readl(src_low
);
4619 rms_high
= readl(src_high
);
4620 rms
= ((u64
)rms_high
<< 32) | rms_low
;
4621 return copy_to_user(dest
, &rms
, 8);
4624 static inline int copy_u48_le(void __user
*dest
, void __iomem
*src_low
, void __iomem
*src_high
)
4626 u32 rms_low
, rms_high
;
4628 rms_low
= readl(src_low
) & 0xffffff00;
4629 rms_high
= readl(src_high
) & 0xffffff00;
4630 rms
= ((u64
)rms_high
<< 32) | rms_low
;
4631 return copy_to_user(dest
, &rms
, 8);
4634 static int hdsp_9652_get_peak(struct hdsp
*hdsp
, struct hdsp_peak_rms __user
*peak_rms
)
4636 int doublespeed
= 0;
4637 int i
, j
, channels
, ofs
;
4639 if (hdsp_read (hdsp
, HDSP_statusRegister
) & HDSP_DoubleSpeedStatus
)
4641 channels
= doublespeed
? 14 : 26;
4642 for (i
= 0, j
= 0; i
< 26; ++i
) {
4643 if (doublespeed
&& (i
& 4))
4645 ofs
= HDSP_9652_peakBase
- j
* 4;
4646 if (copy_u32_le(&peak_rms
->input_peaks
[i
], hdsp
->iobase
+ ofs
))
4648 ofs
-= channels
* 4;
4649 if (copy_u32_le(&peak_rms
->playback_peaks
[i
], hdsp
->iobase
+ ofs
))
4651 ofs
-= channels
* 4;
4652 if (copy_u32_le(&peak_rms
->output_peaks
[i
], hdsp
->iobase
+ ofs
))
4654 ofs
= HDSP_9652_rmsBase
+ j
* 8;
4655 if (copy_u48_le(&peak_rms
->input_rms
[i
], hdsp
->iobase
+ ofs
,
4656 hdsp
->iobase
+ ofs
+ 4))
4658 ofs
+= channels
* 8;
4659 if (copy_u48_le(&peak_rms
->playback_rms
[i
], hdsp
->iobase
+ ofs
,
4660 hdsp
->iobase
+ ofs
+ 4))
4662 ofs
+= channels
* 8;
4663 if (copy_u48_le(&peak_rms
->output_rms
[i
], hdsp
->iobase
+ ofs
,
4664 hdsp
->iobase
+ ofs
+ 4))
4671 static int hdsp_9632_get_peak(struct hdsp
*hdsp
, struct hdsp_peak_rms __user
*peak_rms
)
4674 struct hdsp_9632_meters __iomem
*m
;
4675 int doublespeed
= 0;
4677 if (hdsp_read (hdsp
, HDSP_statusRegister
) & HDSP_DoubleSpeedStatus
)
4679 m
= (struct hdsp_9632_meters __iomem
*)(hdsp
->iobase
+HDSP_9632_metersBase
);
4680 for (i
= 0, j
= 0; i
< 16; ++i
, ++j
) {
4681 if (copy_u32_le(&peak_rms
->input_peaks
[i
], &m
->input_peak
[j
]))
4683 if (copy_u32_le(&peak_rms
->playback_peaks
[i
], &m
->playback_peak
[j
]))
4685 if (copy_u32_le(&peak_rms
->output_peaks
[i
], &m
->output_peak
[j
]))
4687 if (copy_u64_le(&peak_rms
->input_rms
[i
], &m
->input_rms_low
[j
],
4688 &m
->input_rms_high
[j
]))
4690 if (copy_u64_le(&peak_rms
->playback_rms
[i
], &m
->playback_rms_low
[j
],
4691 &m
->playback_rms_high
[j
]))
4693 if (copy_u64_le(&peak_rms
->output_rms
[i
], &m
->output_rms_low
[j
],
4694 &m
->output_rms_high
[j
]))
4696 if (doublespeed
&& i
== 3) i
+= 4;
4701 static int hdsp_get_peak(struct hdsp
*hdsp
, struct hdsp_peak_rms __user
*peak_rms
)
4705 for (i
= 0; i
< 26; i
++) {
4706 if (copy_u32_le(&peak_rms
->playback_peaks
[i
],
4707 hdsp
->iobase
+ HDSP_playbackPeakLevel
+ i
* 4))
4709 if (copy_u32_le(&peak_rms
->input_peaks
[i
],
4710 hdsp
->iobase
+ HDSP_inputPeakLevel
+ i
* 4))
4713 for (i
= 0; i
< 28; i
++) {
4714 if (copy_u32_le(&peak_rms
->output_peaks
[i
],
4715 hdsp
->iobase
+ HDSP_outputPeakLevel
+ i
* 4))
4718 for (i
= 0; i
< 26; ++i
) {
4719 if (copy_u64_le(&peak_rms
->playback_rms
[i
],
4720 hdsp
->iobase
+ HDSP_playbackRmsLevel
+ i
* 8 + 4,
4721 hdsp
->iobase
+ HDSP_playbackRmsLevel
+ i
* 8))
4723 if (copy_u64_le(&peak_rms
->input_rms
[i
],
4724 hdsp
->iobase
+ HDSP_inputRmsLevel
+ i
* 8 + 4,
4725 hdsp
->iobase
+ HDSP_inputRmsLevel
+ i
* 8))
4731 static int snd_hdsp_hwdep_ioctl(struct snd_hwdep
*hw
, struct file
*file
, unsigned int cmd
, unsigned long arg
)
4733 struct hdsp
*hdsp
= hw
->private_data
;
4734 void __user
*argp
= (void __user
*)arg
;
4738 case SNDRV_HDSP_IOCTL_GET_PEAK_RMS
: {
4739 struct hdsp_peak_rms __user
*peak_rms
= (struct hdsp_peak_rms __user
*)arg
;
4741 err
= hdsp_check_for_iobox(hdsp
);
4745 err
= hdsp_check_for_firmware(hdsp
, 1);
4749 if (!(hdsp
->state
& HDSP_FirmwareLoaded
)) {
4750 snd_printk(KERN_ERR
"Hammerfall-DSP: firmware needs to be uploaded to the card.\n");
4754 switch (hdsp
->io_type
) {
4756 return hdsp_9652_get_peak(hdsp
, peak_rms
);
4758 return hdsp_9632_get_peak(hdsp
, peak_rms
);
4760 return hdsp_get_peak(hdsp
, peak_rms
);
4763 case SNDRV_HDSP_IOCTL_GET_CONFIG_INFO
: {
4764 struct hdsp_config_info info
;
4765 unsigned long flags
;
4768 err
= hdsp_check_for_iobox(hdsp
);
4772 err
= hdsp_check_for_firmware(hdsp
, 1);
4776 memset(&info
, 0, sizeof(info
));
4777 spin_lock_irqsave(&hdsp
->lock
, flags
);
4778 info
.pref_sync_ref
= (unsigned char)hdsp_pref_sync_ref(hdsp
);
4779 info
.wordclock_sync_check
= (unsigned char)hdsp_wc_sync_check(hdsp
);
4780 if (hdsp
->io_type
!= H9632
)
4781 info
.adatsync_sync_check
= (unsigned char)hdsp_adatsync_sync_check(hdsp
);
4782 info
.spdif_sync_check
= (unsigned char)hdsp_spdif_sync_check(hdsp
);
4783 for (i
= 0; i
< ((hdsp
->io_type
!= Multiface
&& hdsp
->io_type
!= RPM
&& hdsp
->io_type
!= H9632
) ? 3 : 1); ++i
)
4784 info
.adat_sync_check
[i
] = (unsigned char)hdsp_adat_sync_check(hdsp
, i
);
4785 info
.spdif_in
= (unsigned char)hdsp_spdif_in(hdsp
);
4786 info
.spdif_out
= (unsigned char)hdsp_toggle_setting(hdsp
,
4787 HDSP_SPDIFOpticalOut
);
4788 info
.spdif_professional
= (unsigned char)
4789 hdsp_toggle_setting(hdsp
, HDSP_SPDIFProfessional
);
4790 info
.spdif_emphasis
= (unsigned char)
4791 hdsp_toggle_setting(hdsp
, HDSP_SPDIFEmphasis
);
4792 info
.spdif_nonaudio
= (unsigned char)
4793 hdsp_toggle_setting(hdsp
, HDSP_SPDIFNonAudio
);
4794 info
.spdif_sample_rate
= hdsp_spdif_sample_rate(hdsp
);
4795 info
.system_sample_rate
= hdsp
->system_sample_rate
;
4796 info
.autosync_sample_rate
= hdsp_external_sample_rate(hdsp
);
4797 info
.system_clock_mode
= (unsigned char)hdsp_system_clock_mode(hdsp
);
4798 info
.clock_source
= (unsigned char)hdsp_clock_source(hdsp
);
4799 info
.autosync_ref
= (unsigned char)hdsp_autosync_ref(hdsp
);
4800 info
.line_out
= (unsigned char)
4801 hdsp_toggle_setting(hdsp
, HDSP_LineOut
);
4802 if (hdsp
->io_type
== H9632
) {
4803 info
.da_gain
= (unsigned char)hdsp_da_gain(hdsp
);
4804 info
.ad_gain
= (unsigned char)hdsp_ad_gain(hdsp
);
4805 info
.phone_gain
= (unsigned char)hdsp_phone_gain(hdsp
);
4806 info
.xlr_breakout_cable
=
4807 (unsigned char)hdsp_toggle_setting(hdsp
,
4808 HDSP_XLRBreakoutCable
);
4810 } else if (hdsp
->io_type
== RPM
) {
4811 info
.da_gain
= (unsigned char) hdsp_rpm_input12(hdsp
);
4812 info
.ad_gain
= (unsigned char) hdsp_rpm_input34(hdsp
);
4814 if (hdsp
->io_type
== H9632
|| hdsp
->io_type
== H9652
)
4815 info
.analog_extension_board
=
4816 (unsigned char)hdsp_toggle_setting(hdsp
,
4817 HDSP_AnalogExtensionBoard
);
4818 spin_unlock_irqrestore(&hdsp
->lock
, flags
);
4819 if (copy_to_user(argp
, &info
, sizeof(info
)))
4823 case SNDRV_HDSP_IOCTL_GET_9632_AEB
: {
4824 struct hdsp_9632_aeb h9632_aeb
;
4826 if (hdsp
->io_type
!= H9632
) return -EINVAL
;
4827 h9632_aeb
.aebi
= hdsp
->ss_in_channels
- H9632_SS_CHANNELS
;
4828 h9632_aeb
.aebo
= hdsp
->ss_out_channels
- H9632_SS_CHANNELS
;
4829 if (copy_to_user(argp
, &h9632_aeb
, sizeof(h9632_aeb
)))
4833 case SNDRV_HDSP_IOCTL_GET_VERSION
: {
4834 struct hdsp_version hdsp_version
;
4837 if (hdsp
->io_type
== H9652
|| hdsp
->io_type
== H9632
) return -EINVAL
;
4838 if (hdsp
->io_type
== Undefined
) {
4839 if ((err
= hdsp_get_iobox_version(hdsp
)) < 0)
4842 memset(&hdsp_version
, 0, sizeof(hdsp_version
));
4843 hdsp_version
.io_type
= hdsp
->io_type
;
4844 hdsp_version
.firmware_rev
= hdsp
->firmware_rev
;
4845 if ((err
= copy_to_user(argp
, &hdsp_version
, sizeof(hdsp_version
))))
4849 case SNDRV_HDSP_IOCTL_UPLOAD_FIRMWARE
: {
4850 struct hdsp_firmware __user
*firmware
;
4851 u32 __user
*firmware_data
;
4854 if (hdsp
->io_type
== H9652
|| hdsp
->io_type
== H9632
) return -EINVAL
;
4855 /* SNDRV_HDSP_IOCTL_GET_VERSION must have been called */
4856 if (hdsp
->io_type
== Undefined
) return -EINVAL
;
4858 if (hdsp
->state
& (HDSP_FirmwareCached
| HDSP_FirmwareLoaded
))
4861 snd_printk(KERN_INFO
"Hammerfall-DSP: initializing firmware upload\n");
4862 firmware
= (struct hdsp_firmware __user
*)argp
;
4864 if (get_user(firmware_data
, &firmware
->firmware_data
))
4867 if (hdsp_check_for_iobox (hdsp
))
4870 if (!hdsp
->fw_uploaded
) {
4871 hdsp
->fw_uploaded
= vmalloc(HDSP_FIRMWARE_SIZE
);
4872 if (!hdsp
->fw_uploaded
)
4876 if (copy_from_user(hdsp
->fw_uploaded
, firmware_data
,
4877 HDSP_FIRMWARE_SIZE
)) {
4878 vfree(hdsp
->fw_uploaded
);
4879 hdsp
->fw_uploaded
= NULL
;
4883 hdsp
->state
|= HDSP_FirmwareCached
;
4885 if ((err
= snd_hdsp_load_firmware_from_cache(hdsp
)) < 0)
4888 if (!(hdsp
->state
& HDSP_InitializationComplete
)) {
4889 if ((err
= snd_hdsp_enable_io(hdsp
)) < 0)
4892 snd_hdsp_initialize_channels(hdsp
);
4893 snd_hdsp_initialize_midi_flush(hdsp
);
4895 if ((err
= snd_hdsp_create_alsa_devices(hdsp
->card
, hdsp
)) < 0) {
4896 snd_printk(KERN_ERR
"Hammerfall-DSP: error creating alsa devices\n");
4902 case SNDRV_HDSP_IOCTL_GET_MIXER
: {
4903 struct hdsp_mixer __user
*mixer
= (struct hdsp_mixer __user
*)argp
;
4904 if (copy_to_user(mixer
->matrix
, hdsp
->mixer_matrix
, sizeof(unsigned short)*HDSP_MATRIX_MIXER_SIZE
))
4914 static struct snd_pcm_ops snd_hdsp_playback_ops
= {
4915 .open
= snd_hdsp_playback_open
,
4916 .close
= snd_hdsp_playback_release
,
4917 .ioctl
= snd_hdsp_ioctl
,
4918 .hw_params
= snd_hdsp_hw_params
,
4919 .prepare
= snd_hdsp_prepare
,
4920 .trigger
= snd_hdsp_trigger
,
4921 .pointer
= snd_hdsp_hw_pointer
,
4922 .copy
= snd_hdsp_playback_copy
,
4923 .silence
= snd_hdsp_hw_silence
,
4926 static struct snd_pcm_ops snd_hdsp_capture_ops
= {
4927 .open
= snd_hdsp_capture_open
,
4928 .close
= snd_hdsp_capture_release
,
4929 .ioctl
= snd_hdsp_ioctl
,
4930 .hw_params
= snd_hdsp_hw_params
,
4931 .prepare
= snd_hdsp_prepare
,
4932 .trigger
= snd_hdsp_trigger
,
4933 .pointer
= snd_hdsp_hw_pointer
,
4934 .copy
= snd_hdsp_capture_copy
,
4937 static int snd_hdsp_create_hwdep(struct snd_card
*card
, struct hdsp
*hdsp
)
4939 struct snd_hwdep
*hw
;
4942 if ((err
= snd_hwdep_new(card
, "HDSP hwdep", 0, &hw
)) < 0)
4946 hw
->private_data
= hdsp
;
4947 strcpy(hw
->name
, "HDSP hwdep interface");
4949 hw
->ops
.ioctl
= snd_hdsp_hwdep_ioctl
;
4950 hw
->ops
.ioctl_compat
= snd_hdsp_hwdep_ioctl
;
4955 static int snd_hdsp_create_pcm(struct snd_card
*card
, struct hdsp
*hdsp
)
4957 struct snd_pcm
*pcm
;
4960 if ((err
= snd_pcm_new(card
, hdsp
->card_name
, 0, 1, 1, &pcm
)) < 0)
4964 pcm
->private_data
= hdsp
;
4965 strcpy(pcm
->name
, hdsp
->card_name
);
4967 snd_pcm_set_ops(pcm
, SNDRV_PCM_STREAM_PLAYBACK
, &snd_hdsp_playback_ops
);
4968 snd_pcm_set_ops(pcm
, SNDRV_PCM_STREAM_CAPTURE
, &snd_hdsp_capture_ops
);
4970 pcm
->info_flags
= SNDRV_PCM_INFO_JOINT_DUPLEX
;
4975 static void snd_hdsp_9652_enable_mixer (struct hdsp
*hdsp
)
4977 hdsp
->control2_register
|= HDSP_9652_ENABLE_MIXER
;
4978 hdsp_write (hdsp
, HDSP_control2Reg
, hdsp
->control2_register
);
4981 static int snd_hdsp_enable_io (struct hdsp
*hdsp
)
4985 if (hdsp_fifo_wait (hdsp
, 0, 100)) {
4986 snd_printk(KERN_ERR
"Hammerfall-DSP: enable_io fifo_wait failed\n");
4990 for (i
= 0; i
< hdsp
->max_channels
; ++i
) {
4991 hdsp_write (hdsp
, HDSP_inputEnable
+ (4 * i
), 1);
4992 hdsp_write (hdsp
, HDSP_outputEnable
+ (4 * i
), 1);
4998 static void snd_hdsp_initialize_channels(struct hdsp
*hdsp
)
5000 int status
, aebi_channels
, aebo_channels
;
5002 switch (hdsp
->io_type
) {
5004 hdsp
->card_name
= "RME Hammerfall DSP + Digiface";
5005 hdsp
->ss_in_channels
= hdsp
->ss_out_channels
= DIGIFACE_SS_CHANNELS
;
5006 hdsp
->ds_in_channels
= hdsp
->ds_out_channels
= DIGIFACE_DS_CHANNELS
;
5010 hdsp
->card_name
= "RME Hammerfall HDSP 9652";
5011 hdsp
->ss_in_channels
= hdsp
->ss_out_channels
= H9652_SS_CHANNELS
;
5012 hdsp
->ds_in_channels
= hdsp
->ds_out_channels
= H9652_DS_CHANNELS
;
5016 status
= hdsp_read(hdsp
, HDSP_statusRegister
);
5017 /* HDSP_AEBx bits are low when AEB are connected */
5018 aebi_channels
= (status
& HDSP_AEBI
) ? 0 : 4;
5019 aebo_channels
= (status
& HDSP_AEBO
) ? 0 : 4;
5020 hdsp
->card_name
= "RME Hammerfall HDSP 9632";
5021 hdsp
->ss_in_channels
= H9632_SS_CHANNELS
+aebi_channels
;
5022 hdsp
->ds_in_channels
= H9632_DS_CHANNELS
+aebi_channels
;
5023 hdsp
->qs_in_channels
= H9632_QS_CHANNELS
+aebi_channels
;
5024 hdsp
->ss_out_channels
= H9632_SS_CHANNELS
+aebo_channels
;
5025 hdsp
->ds_out_channels
= H9632_DS_CHANNELS
+aebo_channels
;
5026 hdsp
->qs_out_channels
= H9632_QS_CHANNELS
+aebo_channels
;
5030 hdsp
->card_name
= "RME Hammerfall DSP + Multiface";
5031 hdsp
->ss_in_channels
= hdsp
->ss_out_channels
= MULTIFACE_SS_CHANNELS
;
5032 hdsp
->ds_in_channels
= hdsp
->ds_out_channels
= MULTIFACE_DS_CHANNELS
;
5036 hdsp
->card_name
= "RME Hammerfall DSP + RPM";
5037 hdsp
->ss_in_channels
= RPM_CHANNELS
-1;
5038 hdsp
->ss_out_channels
= RPM_CHANNELS
;
5039 hdsp
->ds_in_channels
= RPM_CHANNELS
-1;
5040 hdsp
->ds_out_channels
= RPM_CHANNELS
;
5044 /* should never get here */
5049 static void snd_hdsp_initialize_midi_flush (struct hdsp
*hdsp
)
5051 snd_hdsp_flush_midi_input (hdsp
, 0);
5052 snd_hdsp_flush_midi_input (hdsp
, 1);
5055 static int snd_hdsp_create_alsa_devices(struct snd_card
*card
, struct hdsp
*hdsp
)
5059 if ((err
= snd_hdsp_create_pcm(card
, hdsp
)) < 0) {
5060 snd_printk(KERN_ERR
"Hammerfall-DSP: Error creating pcm interface\n");
5065 if ((err
= snd_hdsp_create_midi(card
, hdsp
, 0)) < 0) {
5066 snd_printk(KERN_ERR
"Hammerfall-DSP: Error creating first midi interface\n");
5070 if (hdsp
->io_type
== Digiface
|| hdsp
->io_type
== H9652
) {
5071 if ((err
= snd_hdsp_create_midi(card
, hdsp
, 1)) < 0) {
5072 snd_printk(KERN_ERR
"Hammerfall-DSP: Error creating second midi interface\n");
5077 if ((err
= snd_hdsp_create_controls(card
, hdsp
)) < 0) {
5078 snd_printk(KERN_ERR
"Hammerfall-DSP: Error creating ctl interface\n");
5082 snd_hdsp_proc_init(hdsp
);
5084 hdsp
->system_sample_rate
= -1;
5085 hdsp
->playback_pid
= -1;
5086 hdsp
->capture_pid
= -1;
5087 hdsp
->capture_substream
= NULL
;
5088 hdsp
->playback_substream
= NULL
;
5090 if ((err
= snd_hdsp_set_defaults(hdsp
)) < 0) {
5091 snd_printk(KERN_ERR
"Hammerfall-DSP: Error setting default values\n");
5095 if (!(hdsp
->state
& HDSP_InitializationComplete
)) {
5096 strcpy(card
->shortname
, "Hammerfall DSP");
5097 sprintf(card
->longname
, "%s at 0x%lx, irq %d", hdsp
->card_name
,
5098 hdsp
->port
, hdsp
->irq
);
5100 if ((err
= snd_card_register(card
)) < 0) {
5101 snd_printk(KERN_ERR
"Hammerfall-DSP: error registering card\n");
5104 hdsp
->state
|= HDSP_InitializationComplete
;
5110 /* load firmware via hotplug fw loader */
5111 static int hdsp_request_fw_loader(struct hdsp
*hdsp
)
5114 const struct firmware
*fw
;
5117 if (hdsp
->io_type
== H9652
|| hdsp
->io_type
== H9632
)
5119 if (hdsp
->io_type
== Undefined
) {
5120 if ((err
= hdsp_get_iobox_version(hdsp
)) < 0)
5122 if (hdsp
->io_type
== H9652
|| hdsp
->io_type
== H9632
)
5126 /* caution: max length of firmware filename is 30! */
5127 switch (hdsp
->io_type
) {
5129 fwfile
= "rpm_firmware.bin";
5132 if (hdsp
->firmware_rev
== 0xa)
5133 fwfile
= "multiface_firmware.bin";
5135 fwfile
= "multiface_firmware_rev11.bin";
5138 if (hdsp
->firmware_rev
== 0xa)
5139 fwfile
= "digiface_firmware.bin";
5141 fwfile
= "digiface_firmware_rev11.bin";
5144 snd_printk(KERN_ERR
"Hammerfall-DSP: invalid io_type %d\n", hdsp
->io_type
);
5148 if (request_firmware(&fw
, fwfile
, &hdsp
->pci
->dev
)) {
5149 snd_printk(KERN_ERR
"Hammerfall-DSP: cannot load firmware %s\n", fwfile
);
5152 if (fw
->size
< HDSP_FIRMWARE_SIZE
) {
5153 snd_printk(KERN_ERR
"Hammerfall-DSP: too short firmware size %d (expected %d)\n",
5154 (int)fw
->size
, HDSP_FIRMWARE_SIZE
);
5158 hdsp
->firmware
= fw
;
5160 hdsp
->state
|= HDSP_FirmwareCached
;
5162 if ((err
= snd_hdsp_load_firmware_from_cache(hdsp
)) < 0)
5165 if (!(hdsp
->state
& HDSP_InitializationComplete
)) {
5166 if ((err
= snd_hdsp_enable_io(hdsp
)) < 0)
5169 if ((err
= snd_hdsp_create_hwdep(hdsp
->card
, hdsp
)) < 0) {
5170 snd_printk(KERN_ERR
"Hammerfall-DSP: error creating hwdep device\n");
5173 snd_hdsp_initialize_channels(hdsp
);
5174 snd_hdsp_initialize_midi_flush(hdsp
);
5175 if ((err
= snd_hdsp_create_alsa_devices(hdsp
->card
, hdsp
)) < 0) {
5176 snd_printk(KERN_ERR
"Hammerfall-DSP: error creating alsa devices\n");
5183 static int snd_hdsp_create(struct snd_card
*card
,
5186 struct pci_dev
*pci
= hdsp
->pci
;
5193 hdsp
->midi
[0].rmidi
= NULL
;
5194 hdsp
->midi
[1].rmidi
= NULL
;
5195 hdsp
->midi
[0].input
= NULL
;
5196 hdsp
->midi
[1].input
= NULL
;
5197 hdsp
->midi
[0].output
= NULL
;
5198 hdsp
->midi
[1].output
= NULL
;
5199 hdsp
->midi
[0].pending
= 0;
5200 hdsp
->midi
[1].pending
= 0;
5201 spin_lock_init(&hdsp
->midi
[0].lock
);
5202 spin_lock_init(&hdsp
->midi
[1].lock
);
5203 hdsp
->iobase
= NULL
;
5204 hdsp
->control_register
= 0;
5205 hdsp
->control2_register
= 0;
5206 hdsp
->io_type
= Undefined
;
5207 hdsp
->max_channels
= 26;
5211 spin_lock_init(&hdsp
->lock
);
5213 tasklet_init(&hdsp
->midi_tasklet
, hdsp_midi_tasklet
, (unsigned long)hdsp
);
5215 pci_read_config_word(hdsp
->pci
, PCI_CLASS_REVISION
, &hdsp
->firmware_rev
);
5216 hdsp
->firmware_rev
&= 0xff;
5218 /* From Martin Bjoernsen :
5219 "It is important that the card's latency timer register in
5220 the PCI configuration space is set to a value much larger
5221 than 0 by the computer's BIOS or the driver.
5222 The windows driver always sets this 8 bit register [...]
5223 to its maximum 255 to avoid problems with some computers."
5225 pci_write_config_byte(hdsp
->pci
, PCI_LATENCY_TIMER
, 0xFF);
5227 strcpy(card
->driver
, "H-DSP");
5228 strcpy(card
->mixername
, "Xilinx FPGA");
5230 if (hdsp
->firmware_rev
< 0xa)
5232 else if (hdsp
->firmware_rev
< 0x64)
5233 hdsp
->card_name
= "RME Hammerfall DSP";
5234 else if (hdsp
->firmware_rev
< 0x96) {
5235 hdsp
->card_name
= "RME HDSP 9652";
5238 hdsp
->card_name
= "RME HDSP 9632";
5239 hdsp
->max_channels
= 16;
5243 if ((err
= pci_enable_device(pci
)) < 0)
5246 pci_set_master(hdsp
->pci
);
5248 if ((err
= pci_request_regions(pci
, "hdsp")) < 0)
5250 hdsp
->port
= pci_resource_start(pci
, 0);
5251 if ((hdsp
->iobase
= ioremap_nocache(hdsp
->port
, HDSP_IO_EXTENT
)) == NULL
) {
5252 snd_printk(KERN_ERR
"Hammerfall-DSP: unable to remap region 0x%lx-0x%lx\n", hdsp
->port
, hdsp
->port
+ HDSP_IO_EXTENT
- 1);
5256 if (request_irq(pci
->irq
, snd_hdsp_interrupt
, IRQF_SHARED
,
5257 KBUILD_MODNAME
, hdsp
)) {
5258 snd_printk(KERN_ERR
"Hammerfall-DSP: unable to use IRQ %d\n", pci
->irq
);
5262 hdsp
->irq
= pci
->irq
;
5263 hdsp
->precise_ptr
= 0;
5264 hdsp
->use_midi_tasklet
= 1;
5265 hdsp
->dds_value
= 0;
5267 if ((err
= snd_hdsp_initialize_memory(hdsp
)) < 0)
5270 if (!is_9652
&& !is_9632
) {
5271 /* we wait a maximum of 10 seconds to let freshly
5272 * inserted cardbus cards do their hardware init */
5273 err
= hdsp_wait_for_iobox(hdsp
, 1000, 10);
5278 if ((hdsp_read (hdsp
, HDSP_statusRegister
) & HDSP_DllError
) != 0) {
5279 if ((err
= hdsp_request_fw_loader(hdsp
)) < 0)
5280 /* we don't fail as this can happen
5281 if userspace is not ready for
5284 snd_printk(KERN_ERR
"Hammerfall-DSP: couldn't get firmware from userspace. try using hdsploader\n");
5286 /* init is complete, we return */
5288 /* we defer initialization */
5289 snd_printk(KERN_INFO
"Hammerfall-DSP: card initialization pending : waiting for firmware\n");
5290 if ((err
= snd_hdsp_create_hwdep(card
, hdsp
)) < 0)
5294 snd_printk(KERN_INFO
"Hammerfall-DSP: Firmware already present, initializing card.\n");
5295 if (hdsp_read(hdsp
, HDSP_status2Register
) & HDSP_version2
)
5296 hdsp
->io_type
= RPM
;
5297 else if (hdsp_read(hdsp
, HDSP_status2Register
) & HDSP_version1
)
5298 hdsp
->io_type
= Multiface
;
5300 hdsp
->io_type
= Digiface
;
5304 if ((err
= snd_hdsp_enable_io(hdsp
)) != 0)
5308 hdsp
->io_type
= H9652
;
5311 hdsp
->io_type
= H9632
;
5313 if ((err
= snd_hdsp_create_hwdep(card
, hdsp
)) < 0)
5316 snd_hdsp_initialize_channels(hdsp
);
5317 snd_hdsp_initialize_midi_flush(hdsp
);
5319 hdsp
->state
|= HDSP_FirmwareLoaded
;
5321 if ((err
= snd_hdsp_create_alsa_devices(card
, hdsp
)) < 0)
5327 static int snd_hdsp_free(struct hdsp
*hdsp
)
5330 /* stop the audio, and cancel all interrupts */
5331 tasklet_kill(&hdsp
->midi_tasklet
);
5332 hdsp
->control_register
&= ~(HDSP_Start
|HDSP_AudioInterruptEnable
|HDSP_Midi0InterruptEnable
|HDSP_Midi1InterruptEnable
);
5333 hdsp_write (hdsp
, HDSP_controlRegister
, hdsp
->control_register
);
5337 free_irq(hdsp
->irq
, (void *)hdsp
);
5339 snd_hdsp_free_buffers(hdsp
);
5342 release_firmware(hdsp
->firmware
);
5343 vfree(hdsp
->fw_uploaded
);
5346 iounmap(hdsp
->iobase
);
5349 pci_release_regions(hdsp
->pci
);
5351 pci_disable_device(hdsp
->pci
);
5355 static void snd_hdsp_card_free(struct snd_card
*card
)
5357 struct hdsp
*hdsp
= card
->private_data
;
5360 snd_hdsp_free(hdsp
);
5363 static int snd_hdsp_probe(struct pci_dev
*pci
,
5364 const struct pci_device_id
*pci_id
)
5368 struct snd_card
*card
;
5371 if (dev
>= SNDRV_CARDS
)
5378 err
= snd_card_create(index
[dev
], id
[dev
], THIS_MODULE
,
5379 sizeof(struct hdsp
), &card
);
5383 hdsp
= card
->private_data
;
5384 card
->private_free
= snd_hdsp_card_free
;
5387 snd_card_set_dev(card
, &pci
->dev
);
5389 if ((err
= snd_hdsp_create(card
, hdsp
)) < 0) {
5390 snd_card_free(card
);
5394 strcpy(card
->shortname
, "Hammerfall DSP");
5395 sprintf(card
->longname
, "%s at 0x%lx, irq %d", hdsp
->card_name
,
5396 hdsp
->port
, hdsp
->irq
);
5398 if ((err
= snd_card_register(card
)) < 0) {
5399 snd_card_free(card
);
5402 pci_set_drvdata(pci
, card
);
5407 static void snd_hdsp_remove(struct pci_dev
*pci
)
5409 snd_card_free(pci_get_drvdata(pci
));
5412 static struct pci_driver hdsp_driver
= {
5413 .name
= KBUILD_MODNAME
,
5414 .id_table
= snd_hdsp_ids
,
5415 .probe
= snd_hdsp_probe
,
5416 .remove
= snd_hdsp_remove
,
5419 module_pci_driver(hdsp_driver
);