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_get_reserved_buf(dmab
, snd_dma_pci_buf_id(pci
))) {
588 if (dmab
->bytes
>= size
)
591 if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV
, snd_dma_pci_data(pci
),
597 static void snd_hammerfall_free_buffer(struct snd_dma_buffer
*dmab
, struct pci_dev
*pci
)
600 dmab
->dev
.dev
= NULL
; /* make it anonymous */
601 snd_dma_reserve_buf(dmab
, snd_dma_pci_buf_id(pci
));
606 static DEFINE_PCI_DEVICE_TABLE(snd_hdsp_ids
) = {
608 .vendor
= PCI_VENDOR_ID_XILINX
,
609 .device
= PCI_DEVICE_ID_XILINX_HAMMERFALL_DSP
,
610 .subvendor
= PCI_ANY_ID
,
611 .subdevice
= PCI_ANY_ID
,
612 }, /* RME Hammerfall-DSP */
616 MODULE_DEVICE_TABLE(pci
, snd_hdsp_ids
);
619 static int snd_hdsp_create_alsa_devices(struct snd_card
*card
, struct hdsp
*hdsp
);
620 static int snd_hdsp_create_pcm(struct snd_card
*card
, struct hdsp
*hdsp
);
621 static int snd_hdsp_enable_io (struct hdsp
*hdsp
);
622 static void snd_hdsp_initialize_midi_flush (struct hdsp
*hdsp
);
623 static void snd_hdsp_initialize_channels (struct hdsp
*hdsp
);
624 static int hdsp_fifo_wait(struct hdsp
*hdsp
, int count
, int timeout
);
625 static int hdsp_autosync_ref(struct hdsp
*hdsp
);
626 static int snd_hdsp_set_defaults(struct hdsp
*hdsp
);
627 static void snd_hdsp_9652_enable_mixer (struct hdsp
*hdsp
);
629 static int hdsp_playback_to_output_key (struct hdsp
*hdsp
, int in
, int out
)
631 switch (hdsp
->io_type
) {
636 if (hdsp
->firmware_rev
== 0xa)
637 return (64 * out
) + (32 + (in
));
639 return (52 * out
) + (26 + (in
));
641 return (32 * out
) + (16 + (in
));
643 return (52 * out
) + (26 + (in
));
647 static int hdsp_input_to_output_key (struct hdsp
*hdsp
, int in
, int out
)
649 switch (hdsp
->io_type
) {
654 if (hdsp
->firmware_rev
== 0xa)
655 return (64 * out
) + in
;
657 return (52 * out
) + in
;
659 return (32 * out
) + in
;
661 return (52 * out
) + in
;
665 static void hdsp_write(struct hdsp
*hdsp
, int reg
, int val
)
667 writel(val
, hdsp
->iobase
+ reg
);
670 static unsigned int hdsp_read(struct hdsp
*hdsp
, int reg
)
672 return readl (hdsp
->iobase
+ reg
);
675 static int hdsp_check_for_iobox (struct hdsp
*hdsp
)
679 if (hdsp
->io_type
== H9652
|| hdsp
->io_type
== H9632
) return 0;
680 for (i
= 0; i
< 500; i
++) {
681 if (0 == (hdsp_read(hdsp
, HDSP_statusRegister
) &
684 snd_printd("Hammerfall-DSP: IO box found after %d ms\n",
691 snd_printk(KERN_ERR
"Hammerfall-DSP: no IO box connected!\n");
692 hdsp
->state
&= ~HDSP_FirmwareLoaded
;
696 static int hdsp_wait_for_iobox(struct hdsp
*hdsp
, unsigned int loops
,
701 if (hdsp
->io_type
== H9652
|| hdsp
->io_type
== H9632
)
704 for (i
= 0; i
!= loops
; ++i
) {
705 if (hdsp_read(hdsp
, HDSP_statusRegister
) & HDSP_ConfigError
)
708 snd_printd("Hammerfall-DSP: iobox found after %ums!\n",
714 snd_printk("Hammerfall-DSP: no IO box connected!\n");
715 hdsp
->state
&= ~HDSP_FirmwareLoaded
;
719 static int snd_hdsp_load_firmware_from_cache(struct hdsp
*hdsp
) {
725 if (hdsp
->fw_uploaded
)
726 cache
= hdsp
->fw_uploaded
;
730 cache
= (u32
*)hdsp
->firmware
->data
;
735 if ((hdsp_read (hdsp
, HDSP_statusRegister
) & HDSP_DllError
) != 0) {
737 snd_printk ("Hammerfall-DSP: loading firmware\n");
739 hdsp_write (hdsp
, HDSP_control2Reg
, HDSP_S_PROGRAM
);
740 hdsp_write (hdsp
, HDSP_fifoData
, 0);
742 if (hdsp_fifo_wait (hdsp
, 0, HDSP_LONG_WAIT
)) {
743 snd_printk ("Hammerfall-DSP: timeout waiting for download preparation\n");
744 hdsp_write(hdsp
, HDSP_control2Reg
, HDSP_S200
);
748 hdsp_write (hdsp
, HDSP_control2Reg
, HDSP_S_LOAD
);
750 for (i
= 0; i
< HDSP_FIRMWARE_SIZE
/ 4; ++i
) {
751 hdsp_write(hdsp
, HDSP_fifoData
, cache
[i
]);
752 if (hdsp_fifo_wait (hdsp
, 127, HDSP_LONG_WAIT
)) {
753 snd_printk ("Hammerfall-DSP: timeout during firmware loading\n");
754 hdsp_write(hdsp
, HDSP_control2Reg
, HDSP_S200
);
759 hdsp_fifo_wait(hdsp
, 3, HDSP_LONG_WAIT
);
760 hdsp_write(hdsp
, HDSP_control2Reg
, HDSP_S200
);
763 #ifdef SNDRV_BIG_ENDIAN
764 hdsp
->control2_register
= HDSP_BIGENDIAN_MODE
;
766 hdsp
->control2_register
= 0;
768 hdsp_write (hdsp
, HDSP_control2Reg
, hdsp
->control2_register
);
769 snd_printk ("Hammerfall-DSP: finished firmware loading\n");
772 if (hdsp
->state
& HDSP_InitializationComplete
) {
773 snd_printk(KERN_INFO
"Hammerfall-DSP: firmware loaded from cache, restoring defaults\n");
774 spin_lock_irqsave(&hdsp
->lock
, flags
);
775 snd_hdsp_set_defaults(hdsp
);
776 spin_unlock_irqrestore(&hdsp
->lock
, flags
);
779 hdsp
->state
|= HDSP_FirmwareLoaded
;
784 static int hdsp_get_iobox_version (struct hdsp
*hdsp
)
786 if ((hdsp_read (hdsp
, HDSP_statusRegister
) & HDSP_DllError
) != 0) {
788 hdsp_write(hdsp
, HDSP_control2Reg
, HDSP_S_LOAD
);
789 hdsp_write(hdsp
, HDSP_fifoData
, 0);
791 if (hdsp_fifo_wait(hdsp
, 0, HDSP_SHORT_WAIT
) < 0) {
792 hdsp_write(hdsp
, HDSP_control2Reg
, HDSP_S300
);
793 hdsp_write(hdsp
, HDSP_control2Reg
, HDSP_S_LOAD
);
796 hdsp_write(hdsp
, HDSP_control2Reg
, HDSP_S200
| HDSP_PROGRAM
);
797 hdsp_write (hdsp
, HDSP_fifoData
, 0);
798 if (hdsp_fifo_wait(hdsp
, 0, HDSP_SHORT_WAIT
) < 0) {
799 hdsp
->io_type
= Multiface
;
800 snd_printk("Hammerfall-DSP: Multiface found\n");
804 hdsp_write(hdsp
, HDSP_control2Reg
, HDSP_S_LOAD
);
805 hdsp_write(hdsp
, HDSP_fifoData
, 0);
806 if (hdsp_fifo_wait(hdsp
, 0, HDSP_SHORT_WAIT
) == 0) {
807 hdsp
->io_type
= Digiface
;
808 snd_printk("Hammerfall-DSP: Digiface found\n");
812 hdsp_write(hdsp
, HDSP_control2Reg
, HDSP_S300
);
813 hdsp_write(hdsp
, HDSP_control2Reg
, HDSP_S_LOAD
);
814 hdsp_write(hdsp
, HDSP_fifoData
, 0);
815 if (hdsp_fifo_wait(hdsp
, 0, HDSP_SHORT_WAIT
) == 0) {
816 hdsp
->io_type
= Multiface
;
817 snd_printk("Hammerfall-DSP: Multiface found\n");
821 hdsp_write(hdsp
, HDSP_control2Reg
, HDSP_S300
);
822 hdsp_write(hdsp
, HDSP_control2Reg
, HDSP_S_LOAD
);
823 hdsp_write(hdsp
, HDSP_fifoData
, 0);
824 if (hdsp_fifo_wait(hdsp
, 0, HDSP_SHORT_WAIT
) < 0) {
825 hdsp
->io_type
= Multiface
;
826 snd_printk("Hammerfall-DSP: Multiface found\n");
831 snd_printk("Hammerfall-DSP: RPM found\n");
834 /* firmware was already loaded, get iobox type */
835 if (hdsp_read(hdsp
, HDSP_status2Register
) & HDSP_version2
)
837 else if (hdsp_read(hdsp
, HDSP_status2Register
) & HDSP_version1
)
838 hdsp
->io_type
= Multiface
;
840 hdsp
->io_type
= Digiface
;
846 static int hdsp_request_fw_loader(struct hdsp
*hdsp
);
848 static int hdsp_check_for_firmware (struct hdsp
*hdsp
, int load_on_demand
)
850 if (hdsp
->io_type
== H9652
|| hdsp
->io_type
== H9632
)
852 if ((hdsp_read (hdsp
, HDSP_statusRegister
) & HDSP_DllError
) != 0) {
853 hdsp
->state
&= ~HDSP_FirmwareLoaded
;
854 if (! load_on_demand
)
856 snd_printk(KERN_ERR
"Hammerfall-DSP: firmware not present.\n");
857 /* try to load firmware */
858 if (! (hdsp
->state
& HDSP_FirmwareCached
)) {
859 if (! hdsp_request_fw_loader(hdsp
))
862 "Hammerfall-DSP: No firmware loaded nor "
863 "cached, please upload firmware.\n");
866 if (snd_hdsp_load_firmware_from_cache(hdsp
) != 0) {
868 "Hammerfall-DSP: Firmware loading from "
869 "cache failed, please upload manually.\n");
877 static int hdsp_fifo_wait(struct hdsp
*hdsp
, int count
, int timeout
)
881 /* the fifoStatus registers reports on how many words
882 are available in the command FIFO.
885 for (i
= 0; i
< timeout
; i
++) {
887 if ((int)(hdsp_read (hdsp
, HDSP_fifoStatus
) & 0xff) <= count
)
890 /* not very friendly, but we only do this during a firmware
891 load and changing the mixer, so we just put up with it.
897 snd_printk ("Hammerfall-DSP: wait for FIFO status <= %d failed after %d iterations\n",
902 static int hdsp_read_gain (struct hdsp
*hdsp
, unsigned int addr
)
904 if (addr
>= HDSP_MATRIX_MIXER_SIZE
)
907 return hdsp
->mixer_matrix
[addr
];
910 static int hdsp_write_gain(struct hdsp
*hdsp
, unsigned int addr
, unsigned short data
)
914 if (addr
>= HDSP_MATRIX_MIXER_SIZE
)
917 if (hdsp
->io_type
== H9652
|| hdsp
->io_type
== H9632
) {
919 /* from martin bjornsen:
921 "You can only write dwords to the
922 mixer memory which contain two
923 mixer values in the low and high
924 word. So if you want to change
925 value 0 you have to read value 1
926 from the cache and write both to
927 the first dword in the mixer
931 if (hdsp
->io_type
== H9632
&& addr
>= 512)
934 if (hdsp
->io_type
== H9652
&& addr
>= 1352)
937 hdsp
->mixer_matrix
[addr
] = data
;
940 /* `addr' addresses a 16-bit wide address, but
941 the address space accessed via hdsp_write
942 uses byte offsets. put another way, addr
943 varies from 0 to 1351, but to access the
944 corresponding memory location, we need
945 to access 0 to 2703 ...
949 hdsp_write (hdsp
, 4096 + (ad
*4),
950 (hdsp
->mixer_matrix
[(addr
&0x7fe)+1] << 16) +
951 hdsp
->mixer_matrix
[addr
&0x7fe]);
957 ad
= (addr
<< 16) + data
;
959 if (hdsp_fifo_wait(hdsp
, 127, HDSP_LONG_WAIT
))
962 hdsp_write (hdsp
, HDSP_fifoData
, ad
);
963 hdsp
->mixer_matrix
[addr
] = data
;
970 static int snd_hdsp_use_is_exclusive(struct hdsp
*hdsp
)
975 spin_lock_irqsave(&hdsp
->lock
, flags
);
976 if ((hdsp
->playback_pid
!= hdsp
->capture_pid
) &&
977 (hdsp
->playback_pid
>= 0) && (hdsp
->capture_pid
>= 0))
979 spin_unlock_irqrestore(&hdsp
->lock
, flags
);
983 static int hdsp_spdif_sample_rate(struct hdsp
*hdsp
)
985 unsigned int status
= hdsp_read(hdsp
, HDSP_statusRegister
);
986 unsigned int rate_bits
= (status
& HDSP_spdifFrequencyMask
);
988 /* For the 9632, the mask is different */
989 if (hdsp
->io_type
== H9632
)
990 rate_bits
= (status
& HDSP_spdifFrequencyMask_9632
);
992 if (status
& HDSP_SPDIFErrorFlag
)
996 case HDSP_spdifFrequency32KHz
: return 32000;
997 case HDSP_spdifFrequency44_1KHz
: return 44100;
998 case HDSP_spdifFrequency48KHz
: return 48000;
999 case HDSP_spdifFrequency64KHz
: return 64000;
1000 case HDSP_spdifFrequency88_2KHz
: return 88200;
1001 case HDSP_spdifFrequency96KHz
: return 96000;
1002 case HDSP_spdifFrequency128KHz
:
1003 if (hdsp
->io_type
== H9632
) return 128000;
1005 case HDSP_spdifFrequency176_4KHz
:
1006 if (hdsp
->io_type
== H9632
) return 176400;
1008 case HDSP_spdifFrequency192KHz
:
1009 if (hdsp
->io_type
== H9632
) return 192000;
1014 snd_printk ("Hammerfall-DSP: unknown spdif frequency status; bits = 0x%x, status = 0x%x\n", rate_bits
, status
);
1018 static int hdsp_external_sample_rate(struct hdsp
*hdsp
)
1020 unsigned int status2
= hdsp_read(hdsp
, HDSP_status2Register
);
1021 unsigned int rate_bits
= status2
& HDSP_systemFrequencyMask
;
1023 /* For the 9632 card, there seems to be no bit for indicating external
1024 * sample rate greater than 96kHz. The card reports the corresponding
1025 * single speed. So the best means seems to get spdif rate when
1026 * autosync reference is spdif */
1027 if (hdsp
->io_type
== H9632
&&
1028 hdsp_autosync_ref(hdsp
) == HDSP_AUTOSYNC_FROM_SPDIF
)
1029 return hdsp_spdif_sample_rate(hdsp
);
1031 switch (rate_bits
) {
1032 case HDSP_systemFrequency32
: return 32000;
1033 case HDSP_systemFrequency44_1
: return 44100;
1034 case HDSP_systemFrequency48
: return 48000;
1035 case HDSP_systemFrequency64
: return 64000;
1036 case HDSP_systemFrequency88_2
: return 88200;
1037 case HDSP_systemFrequency96
: return 96000;
1043 static void hdsp_compute_period_size(struct hdsp
*hdsp
)
1045 hdsp
->period_bytes
= 1 << ((hdsp_decode_latency(hdsp
->control_register
) + 8));
1048 static snd_pcm_uframes_t
hdsp_hw_pointer(struct hdsp
*hdsp
)
1052 position
= hdsp_read(hdsp
, HDSP_statusRegister
);
1054 if (!hdsp
->precise_ptr
)
1055 return (position
& HDSP_BufferID
) ? (hdsp
->period_bytes
/ 4) : 0;
1057 position
&= HDSP_BufferPositionMask
;
1059 position
&= (hdsp
->period_bytes
/2) - 1;
1063 static void hdsp_reset_hw_pointer(struct hdsp
*hdsp
)
1065 hdsp_write (hdsp
, HDSP_resetPointer
, 0);
1066 if (hdsp
->io_type
== H9632
&& hdsp
->firmware_rev
>= 152)
1067 /* HDSP_resetPointer = HDSP_freqReg, which is strange and
1068 * requires (?) to write again DDS value after a reset pointer
1069 * (at least, it works like this) */
1070 hdsp_write (hdsp
, HDSP_freqReg
, hdsp
->dds_value
);
1073 static void hdsp_start_audio(struct hdsp
*s
)
1075 s
->control_register
|= (HDSP_AudioInterruptEnable
| HDSP_Start
);
1076 hdsp_write(s
, HDSP_controlRegister
, s
->control_register
);
1079 static void hdsp_stop_audio(struct hdsp
*s
)
1081 s
->control_register
&= ~(HDSP_Start
| HDSP_AudioInterruptEnable
);
1082 hdsp_write(s
, HDSP_controlRegister
, s
->control_register
);
1085 static void hdsp_silence_playback(struct hdsp
*hdsp
)
1087 memset(hdsp
->playback_buffer
, 0, HDSP_DMA_AREA_BYTES
);
1090 static int hdsp_set_interrupt_interval(struct hdsp
*s
, unsigned int frames
)
1094 spin_lock_irq(&s
->lock
);
1103 s
->control_register
&= ~HDSP_LatencyMask
;
1104 s
->control_register
|= hdsp_encode_latency(n
);
1106 hdsp_write(s
, HDSP_controlRegister
, s
->control_register
);
1108 hdsp_compute_period_size(s
);
1110 spin_unlock_irq(&s
->lock
);
1115 static void hdsp_set_dds_value(struct hdsp
*hdsp
, int rate
)
1121 else if (rate
>= 56000)
1125 n
= div_u64(n
, rate
);
1126 /* n should be less than 2^32 for being written to FREQ register */
1127 snd_BUG_ON(n
>> 32);
1128 /* HDSP_freqReg and HDSP_resetPointer are the same, so keep the DDS
1129 value to write it after a reset */
1130 hdsp
->dds_value
= n
;
1131 hdsp_write(hdsp
, HDSP_freqReg
, hdsp
->dds_value
);
1134 static int hdsp_set_rate(struct hdsp
*hdsp
, int rate
, int called_internally
)
1136 int reject_if_open
= 0;
1140 /* ASSUMPTION: hdsp->lock is either held, or
1141 there is no need for it (e.g. during module
1145 if (!(hdsp
->control_register
& HDSP_ClockModeMaster
)) {
1146 if (called_internally
) {
1147 /* request from ctl or card initialization */
1148 snd_printk(KERN_ERR
"Hammerfall-DSP: device is not running as a clock master: cannot set sample rate.\n");
1151 /* hw_param request while in AutoSync mode */
1152 int external_freq
= hdsp_external_sample_rate(hdsp
);
1153 int spdif_freq
= hdsp_spdif_sample_rate(hdsp
);
1155 if ((spdif_freq
== external_freq
*2) && (hdsp_autosync_ref(hdsp
) >= HDSP_AUTOSYNC_FROM_ADAT1
))
1156 snd_printk(KERN_INFO
"Hammerfall-DSP: Detected ADAT in double speed mode\n");
1157 else if (hdsp
->io_type
== H9632
&& (spdif_freq
== external_freq
*4) && (hdsp_autosync_ref(hdsp
) >= HDSP_AUTOSYNC_FROM_ADAT1
))
1158 snd_printk(KERN_INFO
"Hammerfall-DSP: Detected ADAT in quad speed mode\n");
1159 else if (rate
!= external_freq
) {
1160 snd_printk(KERN_INFO
"Hammerfall-DSP: No AutoSync source for requested rate\n");
1166 current_rate
= hdsp
->system_sample_rate
;
1168 /* Changing from a "single speed" to a "double speed" rate is
1169 not allowed if any substreams are open. This is because
1170 such a change causes a shift in the location of
1171 the DMA buffers and a reduction in the number of available
1174 Note that a similar but essentially insoluble problem
1175 exists for externally-driven rate changes. All we can do
1176 is to flag rate changes in the read/write routines. */
1178 if (rate
> 96000 && hdsp
->io_type
!= H9632
)
1183 if (current_rate
> 48000)
1185 rate_bits
= HDSP_Frequency32KHz
;
1188 if (current_rate
> 48000)
1190 rate_bits
= HDSP_Frequency44_1KHz
;
1193 if (current_rate
> 48000)
1195 rate_bits
= HDSP_Frequency48KHz
;
1198 if (current_rate
<= 48000 || current_rate
> 96000)
1200 rate_bits
= HDSP_Frequency64KHz
;
1203 if (current_rate
<= 48000 || current_rate
> 96000)
1205 rate_bits
= HDSP_Frequency88_2KHz
;
1208 if (current_rate
<= 48000 || current_rate
> 96000)
1210 rate_bits
= HDSP_Frequency96KHz
;
1213 if (current_rate
< 128000)
1215 rate_bits
= HDSP_Frequency128KHz
;
1218 if (current_rate
< 128000)
1220 rate_bits
= HDSP_Frequency176_4KHz
;
1223 if (current_rate
< 128000)
1225 rate_bits
= HDSP_Frequency192KHz
;
1231 if (reject_if_open
&& (hdsp
->capture_pid
>= 0 || hdsp
->playback_pid
>= 0)) {
1232 snd_printk ("Hammerfall-DSP: cannot change speed mode (capture PID = %d, playback PID = %d)\n",
1234 hdsp
->playback_pid
);
1238 hdsp
->control_register
&= ~HDSP_FrequencyMask
;
1239 hdsp
->control_register
|= rate_bits
;
1240 hdsp_write(hdsp
, HDSP_controlRegister
, hdsp
->control_register
);
1242 /* For HDSP9632 rev 152, need to set DDS value in FREQ register */
1243 if (hdsp
->io_type
== H9632
&& hdsp
->firmware_rev
>= 152)
1244 hdsp_set_dds_value(hdsp
, rate
);
1246 if (rate
>= 128000) {
1247 hdsp
->channel_map
= channel_map_H9632_qs
;
1248 } else if (rate
> 48000) {
1249 if (hdsp
->io_type
== H9632
)
1250 hdsp
->channel_map
= channel_map_H9632_ds
;
1252 hdsp
->channel_map
= channel_map_ds
;
1254 switch (hdsp
->io_type
) {
1257 hdsp
->channel_map
= channel_map_mf_ss
;
1261 hdsp
->channel_map
= channel_map_df_ss
;
1264 hdsp
->channel_map
= channel_map_H9632_ss
;
1267 /* should never happen */
1272 hdsp
->system_sample_rate
= rate
;
1277 /*----------------------------------------------------------------------------
1279 ----------------------------------------------------------------------------*/
1281 static unsigned char snd_hdsp_midi_read_byte (struct hdsp
*hdsp
, int id
)
1283 /* the hardware already does the relevant bit-mask with 0xff */
1285 return hdsp_read(hdsp
, HDSP_midiDataIn1
);
1287 return hdsp_read(hdsp
, HDSP_midiDataIn0
);
1290 static void snd_hdsp_midi_write_byte (struct hdsp
*hdsp
, int id
, int val
)
1292 /* the hardware already does the relevant bit-mask with 0xff */
1294 hdsp_write(hdsp
, HDSP_midiDataOut1
, val
);
1296 hdsp_write(hdsp
, HDSP_midiDataOut0
, val
);
1299 static int snd_hdsp_midi_input_available (struct hdsp
*hdsp
, int id
)
1302 return (hdsp_read(hdsp
, HDSP_midiStatusIn1
) & 0xff);
1304 return (hdsp_read(hdsp
, HDSP_midiStatusIn0
) & 0xff);
1307 static int snd_hdsp_midi_output_possible (struct hdsp
*hdsp
, int id
)
1309 int fifo_bytes_used
;
1312 fifo_bytes_used
= hdsp_read(hdsp
, HDSP_midiStatusOut1
) & 0xff;
1314 fifo_bytes_used
= hdsp_read(hdsp
, HDSP_midiStatusOut0
) & 0xff;
1316 if (fifo_bytes_used
< 128)
1317 return 128 - fifo_bytes_used
;
1322 static void snd_hdsp_flush_midi_input (struct hdsp
*hdsp
, int id
)
1324 while (snd_hdsp_midi_input_available (hdsp
, id
))
1325 snd_hdsp_midi_read_byte (hdsp
, id
);
1328 static int snd_hdsp_midi_output_write (struct hdsp_midi
*hmidi
)
1330 unsigned long flags
;
1334 unsigned char buf
[128];
1336 /* Output is not interrupt driven */
1338 spin_lock_irqsave (&hmidi
->lock
, flags
);
1339 if (hmidi
->output
) {
1340 if (!snd_rawmidi_transmit_empty (hmidi
->output
)) {
1341 if ((n_pending
= snd_hdsp_midi_output_possible (hmidi
->hdsp
, hmidi
->id
)) > 0) {
1342 if (n_pending
> (int)sizeof (buf
))
1343 n_pending
= sizeof (buf
);
1345 if ((to_write
= snd_rawmidi_transmit (hmidi
->output
, buf
, n_pending
)) > 0) {
1346 for (i
= 0; i
< to_write
; ++i
)
1347 snd_hdsp_midi_write_byte (hmidi
->hdsp
, hmidi
->id
, buf
[i
]);
1352 spin_unlock_irqrestore (&hmidi
->lock
, flags
);
1356 static int snd_hdsp_midi_input_read (struct hdsp_midi
*hmidi
)
1358 unsigned char buf
[128]; /* this buffer is designed to match the MIDI input FIFO size */
1359 unsigned long flags
;
1363 spin_lock_irqsave (&hmidi
->lock
, flags
);
1364 if ((n_pending
= snd_hdsp_midi_input_available (hmidi
->hdsp
, hmidi
->id
)) > 0) {
1366 if (n_pending
> (int)sizeof (buf
))
1367 n_pending
= sizeof (buf
);
1368 for (i
= 0; i
< n_pending
; ++i
)
1369 buf
[i
] = snd_hdsp_midi_read_byte (hmidi
->hdsp
, hmidi
->id
);
1371 snd_rawmidi_receive (hmidi
->input
, buf
, n_pending
);
1373 /* flush the MIDI input FIFO */
1375 snd_hdsp_midi_read_byte (hmidi
->hdsp
, hmidi
->id
);
1380 hmidi
->hdsp
->control_register
|= HDSP_Midi1InterruptEnable
;
1382 hmidi
->hdsp
->control_register
|= HDSP_Midi0InterruptEnable
;
1383 hdsp_write(hmidi
->hdsp
, HDSP_controlRegister
, hmidi
->hdsp
->control_register
);
1384 spin_unlock_irqrestore (&hmidi
->lock
, flags
);
1385 return snd_hdsp_midi_output_write (hmidi
);
1388 static void snd_hdsp_midi_input_trigger(struct snd_rawmidi_substream
*substream
, int up
)
1391 struct hdsp_midi
*hmidi
;
1392 unsigned long flags
;
1395 hmidi
= (struct hdsp_midi
*) substream
->rmidi
->private_data
;
1397 ie
= hmidi
->id
? HDSP_Midi1InterruptEnable
: HDSP_Midi0InterruptEnable
;
1398 spin_lock_irqsave (&hdsp
->lock
, flags
);
1400 if (!(hdsp
->control_register
& ie
)) {
1401 snd_hdsp_flush_midi_input (hdsp
, hmidi
->id
);
1402 hdsp
->control_register
|= ie
;
1405 hdsp
->control_register
&= ~ie
;
1406 tasklet_kill(&hdsp
->midi_tasklet
);
1409 hdsp_write(hdsp
, HDSP_controlRegister
, hdsp
->control_register
);
1410 spin_unlock_irqrestore (&hdsp
->lock
, flags
);
1413 static void snd_hdsp_midi_output_timer(unsigned long data
)
1415 struct hdsp_midi
*hmidi
= (struct hdsp_midi
*) data
;
1416 unsigned long flags
;
1418 snd_hdsp_midi_output_write(hmidi
);
1419 spin_lock_irqsave (&hmidi
->lock
, flags
);
1421 /* this does not bump hmidi->istimer, because the
1422 kernel automatically removed the timer when it
1423 expired, and we are now adding it back, thus
1424 leaving istimer wherever it was set before.
1427 if (hmidi
->istimer
) {
1428 hmidi
->timer
.expires
= 1 + jiffies
;
1429 add_timer(&hmidi
->timer
);
1432 spin_unlock_irqrestore (&hmidi
->lock
, flags
);
1435 static void snd_hdsp_midi_output_trigger(struct snd_rawmidi_substream
*substream
, int up
)
1437 struct hdsp_midi
*hmidi
;
1438 unsigned long flags
;
1440 hmidi
= (struct hdsp_midi
*) substream
->rmidi
->private_data
;
1441 spin_lock_irqsave (&hmidi
->lock
, flags
);
1443 if (!hmidi
->istimer
) {
1444 init_timer(&hmidi
->timer
);
1445 hmidi
->timer
.function
= snd_hdsp_midi_output_timer
;
1446 hmidi
->timer
.data
= (unsigned long) hmidi
;
1447 hmidi
->timer
.expires
= 1 + jiffies
;
1448 add_timer(&hmidi
->timer
);
1452 if (hmidi
->istimer
&& --hmidi
->istimer
<= 0)
1453 del_timer (&hmidi
->timer
);
1455 spin_unlock_irqrestore (&hmidi
->lock
, flags
);
1457 snd_hdsp_midi_output_write(hmidi
);
1460 static int snd_hdsp_midi_input_open(struct snd_rawmidi_substream
*substream
)
1462 struct hdsp_midi
*hmidi
;
1464 hmidi
= (struct hdsp_midi
*) substream
->rmidi
->private_data
;
1465 spin_lock_irq (&hmidi
->lock
);
1466 snd_hdsp_flush_midi_input (hmidi
->hdsp
, hmidi
->id
);
1467 hmidi
->input
= substream
;
1468 spin_unlock_irq (&hmidi
->lock
);
1473 static int snd_hdsp_midi_output_open(struct snd_rawmidi_substream
*substream
)
1475 struct hdsp_midi
*hmidi
;
1477 hmidi
= (struct hdsp_midi
*) substream
->rmidi
->private_data
;
1478 spin_lock_irq (&hmidi
->lock
);
1479 hmidi
->output
= substream
;
1480 spin_unlock_irq (&hmidi
->lock
);
1485 static int snd_hdsp_midi_input_close(struct snd_rawmidi_substream
*substream
)
1487 struct hdsp_midi
*hmidi
;
1489 snd_hdsp_midi_input_trigger (substream
, 0);
1491 hmidi
= (struct hdsp_midi
*) substream
->rmidi
->private_data
;
1492 spin_lock_irq (&hmidi
->lock
);
1493 hmidi
->input
= NULL
;
1494 spin_unlock_irq (&hmidi
->lock
);
1499 static int snd_hdsp_midi_output_close(struct snd_rawmidi_substream
*substream
)
1501 struct hdsp_midi
*hmidi
;
1503 snd_hdsp_midi_output_trigger (substream
, 0);
1505 hmidi
= (struct hdsp_midi
*) substream
->rmidi
->private_data
;
1506 spin_lock_irq (&hmidi
->lock
);
1507 hmidi
->output
= NULL
;
1508 spin_unlock_irq (&hmidi
->lock
);
1513 static struct snd_rawmidi_ops snd_hdsp_midi_output
=
1515 .open
= snd_hdsp_midi_output_open
,
1516 .close
= snd_hdsp_midi_output_close
,
1517 .trigger
= snd_hdsp_midi_output_trigger
,
1520 static struct snd_rawmidi_ops snd_hdsp_midi_input
=
1522 .open
= snd_hdsp_midi_input_open
,
1523 .close
= snd_hdsp_midi_input_close
,
1524 .trigger
= snd_hdsp_midi_input_trigger
,
1527 static int snd_hdsp_create_midi (struct snd_card
*card
, struct hdsp
*hdsp
, int id
)
1531 hdsp
->midi
[id
].id
= id
;
1532 hdsp
->midi
[id
].rmidi
= NULL
;
1533 hdsp
->midi
[id
].input
= NULL
;
1534 hdsp
->midi
[id
].output
= NULL
;
1535 hdsp
->midi
[id
].hdsp
= hdsp
;
1536 hdsp
->midi
[id
].istimer
= 0;
1537 hdsp
->midi
[id
].pending
= 0;
1538 spin_lock_init (&hdsp
->midi
[id
].lock
);
1540 sprintf (buf
, "%s MIDI %d", card
->shortname
, id
+1);
1541 if (snd_rawmidi_new (card
, buf
, id
, 1, 1, &hdsp
->midi
[id
].rmidi
) < 0)
1544 sprintf(hdsp
->midi
[id
].rmidi
->name
, "HDSP MIDI %d", id
+1);
1545 hdsp
->midi
[id
].rmidi
->private_data
= &hdsp
->midi
[id
];
1547 snd_rawmidi_set_ops (hdsp
->midi
[id
].rmidi
, SNDRV_RAWMIDI_STREAM_OUTPUT
, &snd_hdsp_midi_output
);
1548 snd_rawmidi_set_ops (hdsp
->midi
[id
].rmidi
, SNDRV_RAWMIDI_STREAM_INPUT
, &snd_hdsp_midi_input
);
1550 hdsp
->midi
[id
].rmidi
->info_flags
|= SNDRV_RAWMIDI_INFO_OUTPUT
|
1551 SNDRV_RAWMIDI_INFO_INPUT
|
1552 SNDRV_RAWMIDI_INFO_DUPLEX
;
1557 /*-----------------------------------------------------------------------------
1559 ----------------------------------------------------------------------------*/
1561 static u32
snd_hdsp_convert_from_aes(struct snd_aes_iec958
*aes
)
1564 val
|= (aes
->status
[0] & IEC958_AES0_PROFESSIONAL
) ? HDSP_SPDIFProfessional
: 0;
1565 val
|= (aes
->status
[0] & IEC958_AES0_NONAUDIO
) ? HDSP_SPDIFNonAudio
: 0;
1566 if (val
& HDSP_SPDIFProfessional
)
1567 val
|= (aes
->status
[0] & IEC958_AES0_PRO_EMPHASIS_5015
) ? HDSP_SPDIFEmphasis
: 0;
1569 val
|= (aes
->status
[0] & IEC958_AES0_CON_EMPHASIS_5015
) ? HDSP_SPDIFEmphasis
: 0;
1573 static void snd_hdsp_convert_to_aes(struct snd_aes_iec958
*aes
, u32 val
)
1575 aes
->status
[0] = ((val
& HDSP_SPDIFProfessional
) ? IEC958_AES0_PROFESSIONAL
: 0) |
1576 ((val
& HDSP_SPDIFNonAudio
) ? IEC958_AES0_NONAUDIO
: 0);
1577 if (val
& HDSP_SPDIFProfessional
)
1578 aes
->status
[0] |= (val
& HDSP_SPDIFEmphasis
) ? IEC958_AES0_PRO_EMPHASIS_5015
: 0;
1580 aes
->status
[0] |= (val
& HDSP_SPDIFEmphasis
) ? IEC958_AES0_CON_EMPHASIS_5015
: 0;
1583 static int snd_hdsp_control_spdif_info(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_info
*uinfo
)
1585 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_IEC958
;
1590 static int snd_hdsp_control_spdif_get(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
1592 struct hdsp
*hdsp
= snd_kcontrol_chip(kcontrol
);
1594 snd_hdsp_convert_to_aes(&ucontrol
->value
.iec958
, hdsp
->creg_spdif
);
1598 static int snd_hdsp_control_spdif_put(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
1600 struct hdsp
*hdsp
= snd_kcontrol_chip(kcontrol
);
1604 val
= snd_hdsp_convert_from_aes(&ucontrol
->value
.iec958
);
1605 spin_lock_irq(&hdsp
->lock
);
1606 change
= val
!= hdsp
->creg_spdif
;
1607 hdsp
->creg_spdif
= val
;
1608 spin_unlock_irq(&hdsp
->lock
);
1612 static int snd_hdsp_control_spdif_stream_info(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_info
*uinfo
)
1614 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_IEC958
;
1619 static int snd_hdsp_control_spdif_stream_get(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
1621 struct hdsp
*hdsp
= snd_kcontrol_chip(kcontrol
);
1623 snd_hdsp_convert_to_aes(&ucontrol
->value
.iec958
, hdsp
->creg_spdif_stream
);
1627 static int snd_hdsp_control_spdif_stream_put(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
1629 struct hdsp
*hdsp
= snd_kcontrol_chip(kcontrol
);
1633 val
= snd_hdsp_convert_from_aes(&ucontrol
->value
.iec958
);
1634 spin_lock_irq(&hdsp
->lock
);
1635 change
= val
!= hdsp
->creg_spdif_stream
;
1636 hdsp
->creg_spdif_stream
= val
;
1637 hdsp
->control_register
&= ~(HDSP_SPDIFProfessional
| HDSP_SPDIFNonAudio
| HDSP_SPDIFEmphasis
);
1638 hdsp_write(hdsp
, HDSP_controlRegister
, hdsp
->control_register
|= val
);
1639 spin_unlock_irq(&hdsp
->lock
);
1643 static int snd_hdsp_control_spdif_mask_info(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_info
*uinfo
)
1645 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_IEC958
;
1650 static int snd_hdsp_control_spdif_mask_get(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
1652 ucontrol
->value
.iec958
.status
[0] = kcontrol
->private_value
;
1656 #define HDSP_SPDIF_IN(xname, xindex) \
1657 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1660 .info = snd_hdsp_info_spdif_in, \
1661 .get = snd_hdsp_get_spdif_in, \
1662 .put = snd_hdsp_put_spdif_in }
1664 static unsigned int hdsp_spdif_in(struct hdsp
*hdsp
)
1666 return hdsp_decode_spdif_in(hdsp
->control_register
& HDSP_SPDIFInputMask
);
1669 static int hdsp_set_spdif_input(struct hdsp
*hdsp
, int in
)
1671 hdsp
->control_register
&= ~HDSP_SPDIFInputMask
;
1672 hdsp
->control_register
|= hdsp_encode_spdif_in(in
);
1673 hdsp_write(hdsp
, HDSP_controlRegister
, hdsp
->control_register
);
1677 static int snd_hdsp_info_spdif_in(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_info
*uinfo
)
1679 static char *texts
[4] = {"Optical", "Coaxial", "Internal", "AES"};
1680 struct hdsp
*hdsp
= snd_kcontrol_chip(kcontrol
);
1682 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
1684 uinfo
->value
.enumerated
.items
= ((hdsp
->io_type
== H9632
) ? 4 : 3);
1685 if (uinfo
->value
.enumerated
.item
> ((hdsp
->io_type
== H9632
) ? 3 : 2))
1686 uinfo
->value
.enumerated
.item
= ((hdsp
->io_type
== H9632
) ? 3 : 2);
1687 strcpy(uinfo
->value
.enumerated
.name
, texts
[uinfo
->value
.enumerated
.item
]);
1691 static int snd_hdsp_get_spdif_in(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
1693 struct hdsp
*hdsp
= snd_kcontrol_chip(kcontrol
);
1695 ucontrol
->value
.enumerated
.item
[0] = hdsp_spdif_in(hdsp
);
1699 static int snd_hdsp_put_spdif_in(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
1701 struct hdsp
*hdsp
= snd_kcontrol_chip(kcontrol
);
1705 if (!snd_hdsp_use_is_exclusive(hdsp
))
1707 val
= ucontrol
->value
.enumerated
.item
[0] % ((hdsp
->io_type
== H9632
) ? 4 : 3);
1708 spin_lock_irq(&hdsp
->lock
);
1709 change
= val
!= hdsp_spdif_in(hdsp
);
1711 hdsp_set_spdif_input(hdsp
, val
);
1712 spin_unlock_irq(&hdsp
->lock
);
1716 #define HDSP_SPDIF_OUT(xname, xindex) \
1717 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \
1718 .info = snd_hdsp_info_spdif_bits, \
1719 .get = snd_hdsp_get_spdif_out, .put = snd_hdsp_put_spdif_out }
1721 static int hdsp_spdif_out(struct hdsp
*hdsp
)
1723 return (hdsp
->control_register
& HDSP_SPDIFOpticalOut
) ? 1 : 0;
1726 static int hdsp_set_spdif_output(struct hdsp
*hdsp
, int out
)
1729 hdsp
->control_register
|= HDSP_SPDIFOpticalOut
;
1731 hdsp
->control_register
&= ~HDSP_SPDIFOpticalOut
;
1732 hdsp_write(hdsp
, HDSP_controlRegister
, hdsp
->control_register
);
1736 #define snd_hdsp_info_spdif_bits snd_ctl_boolean_mono_info
1738 static int snd_hdsp_get_spdif_out(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
1740 struct hdsp
*hdsp
= snd_kcontrol_chip(kcontrol
);
1742 ucontrol
->value
.integer
.value
[0] = hdsp_spdif_out(hdsp
);
1746 static int snd_hdsp_put_spdif_out(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
1748 struct hdsp
*hdsp
= snd_kcontrol_chip(kcontrol
);
1752 if (!snd_hdsp_use_is_exclusive(hdsp
))
1754 val
= ucontrol
->value
.integer
.value
[0] & 1;
1755 spin_lock_irq(&hdsp
->lock
);
1756 change
= (int)val
!= hdsp_spdif_out(hdsp
);
1757 hdsp_set_spdif_output(hdsp
, val
);
1758 spin_unlock_irq(&hdsp
->lock
);
1762 #define HDSP_SPDIF_PROFESSIONAL(xname, xindex) \
1763 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \
1764 .info = snd_hdsp_info_spdif_bits, \
1765 .get = snd_hdsp_get_spdif_professional, .put = snd_hdsp_put_spdif_professional }
1767 static int hdsp_spdif_professional(struct hdsp
*hdsp
)
1769 return (hdsp
->control_register
& HDSP_SPDIFProfessional
) ? 1 : 0;
1772 static int hdsp_set_spdif_professional(struct hdsp
*hdsp
, int val
)
1775 hdsp
->control_register
|= HDSP_SPDIFProfessional
;
1777 hdsp
->control_register
&= ~HDSP_SPDIFProfessional
;
1778 hdsp_write(hdsp
, HDSP_controlRegister
, hdsp
->control_register
);
1782 static int snd_hdsp_get_spdif_professional(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
1784 struct hdsp
*hdsp
= snd_kcontrol_chip(kcontrol
);
1786 ucontrol
->value
.integer
.value
[0] = hdsp_spdif_professional(hdsp
);
1790 static int snd_hdsp_put_spdif_professional(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
1792 struct hdsp
*hdsp
= snd_kcontrol_chip(kcontrol
);
1796 if (!snd_hdsp_use_is_exclusive(hdsp
))
1798 val
= ucontrol
->value
.integer
.value
[0] & 1;
1799 spin_lock_irq(&hdsp
->lock
);
1800 change
= (int)val
!= hdsp_spdif_professional(hdsp
);
1801 hdsp_set_spdif_professional(hdsp
, val
);
1802 spin_unlock_irq(&hdsp
->lock
);
1806 #define HDSP_SPDIF_EMPHASIS(xname, xindex) \
1807 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \
1808 .info = snd_hdsp_info_spdif_bits, \
1809 .get = snd_hdsp_get_spdif_emphasis, .put = snd_hdsp_put_spdif_emphasis }
1811 static int hdsp_spdif_emphasis(struct hdsp
*hdsp
)
1813 return (hdsp
->control_register
& HDSP_SPDIFEmphasis
) ? 1 : 0;
1816 static int hdsp_set_spdif_emphasis(struct hdsp
*hdsp
, int val
)
1819 hdsp
->control_register
|= HDSP_SPDIFEmphasis
;
1821 hdsp
->control_register
&= ~HDSP_SPDIFEmphasis
;
1822 hdsp_write(hdsp
, HDSP_controlRegister
, hdsp
->control_register
);
1826 static int snd_hdsp_get_spdif_emphasis(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
1828 struct hdsp
*hdsp
= snd_kcontrol_chip(kcontrol
);
1830 ucontrol
->value
.integer
.value
[0] = hdsp_spdif_emphasis(hdsp
);
1834 static int snd_hdsp_put_spdif_emphasis(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
1836 struct hdsp
*hdsp
= snd_kcontrol_chip(kcontrol
);
1840 if (!snd_hdsp_use_is_exclusive(hdsp
))
1842 val
= ucontrol
->value
.integer
.value
[0] & 1;
1843 spin_lock_irq(&hdsp
->lock
);
1844 change
= (int)val
!= hdsp_spdif_emphasis(hdsp
);
1845 hdsp_set_spdif_emphasis(hdsp
, val
);
1846 spin_unlock_irq(&hdsp
->lock
);
1850 #define HDSP_SPDIF_NON_AUDIO(xname, xindex) \
1851 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \
1852 .info = snd_hdsp_info_spdif_bits, \
1853 .get = snd_hdsp_get_spdif_nonaudio, .put = snd_hdsp_put_spdif_nonaudio }
1855 static int hdsp_spdif_nonaudio(struct hdsp
*hdsp
)
1857 return (hdsp
->control_register
& HDSP_SPDIFNonAudio
) ? 1 : 0;
1860 static int hdsp_set_spdif_nonaudio(struct hdsp
*hdsp
, int val
)
1863 hdsp
->control_register
|= HDSP_SPDIFNonAudio
;
1865 hdsp
->control_register
&= ~HDSP_SPDIFNonAudio
;
1866 hdsp_write(hdsp
, HDSP_controlRegister
, hdsp
->control_register
);
1870 static int snd_hdsp_get_spdif_nonaudio(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
1872 struct hdsp
*hdsp
= snd_kcontrol_chip(kcontrol
);
1874 ucontrol
->value
.integer
.value
[0] = hdsp_spdif_nonaudio(hdsp
);
1878 static int snd_hdsp_put_spdif_nonaudio(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
1880 struct hdsp
*hdsp
= snd_kcontrol_chip(kcontrol
);
1884 if (!snd_hdsp_use_is_exclusive(hdsp
))
1886 val
= ucontrol
->value
.integer
.value
[0] & 1;
1887 spin_lock_irq(&hdsp
->lock
);
1888 change
= (int)val
!= hdsp_spdif_nonaudio(hdsp
);
1889 hdsp_set_spdif_nonaudio(hdsp
, val
);
1890 spin_unlock_irq(&hdsp
->lock
);
1894 #define HDSP_SPDIF_SAMPLE_RATE(xname, xindex) \
1895 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1898 .access = SNDRV_CTL_ELEM_ACCESS_READ, \
1899 .info = snd_hdsp_info_spdif_sample_rate, \
1900 .get = snd_hdsp_get_spdif_sample_rate \
1903 static int snd_hdsp_info_spdif_sample_rate(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_info
*uinfo
)
1905 static char *texts
[] = {"32000", "44100", "48000", "64000", "88200", "96000", "None", "128000", "176400", "192000"};
1906 struct hdsp
*hdsp
= snd_kcontrol_chip(kcontrol
);
1908 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
1910 uinfo
->value
.enumerated
.items
= (hdsp
->io_type
== H9632
) ? 10 : 7;
1911 if (uinfo
->value
.enumerated
.item
>= uinfo
->value
.enumerated
.items
)
1912 uinfo
->value
.enumerated
.item
= uinfo
->value
.enumerated
.items
- 1;
1913 strcpy(uinfo
->value
.enumerated
.name
, texts
[uinfo
->value
.enumerated
.item
]);
1917 static int snd_hdsp_get_spdif_sample_rate(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
1919 struct hdsp
*hdsp
= snd_kcontrol_chip(kcontrol
);
1921 switch (hdsp_spdif_sample_rate(hdsp
)) {
1923 ucontrol
->value
.enumerated
.item
[0] = 0;
1926 ucontrol
->value
.enumerated
.item
[0] = 1;
1929 ucontrol
->value
.enumerated
.item
[0] = 2;
1932 ucontrol
->value
.enumerated
.item
[0] = 3;
1935 ucontrol
->value
.enumerated
.item
[0] = 4;
1938 ucontrol
->value
.enumerated
.item
[0] = 5;
1941 ucontrol
->value
.enumerated
.item
[0] = 7;
1944 ucontrol
->value
.enumerated
.item
[0] = 8;
1947 ucontrol
->value
.enumerated
.item
[0] = 9;
1950 ucontrol
->value
.enumerated
.item
[0] = 6;
1955 #define HDSP_SYSTEM_SAMPLE_RATE(xname, xindex) \
1956 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1959 .access = SNDRV_CTL_ELEM_ACCESS_READ, \
1960 .info = snd_hdsp_info_system_sample_rate, \
1961 .get = snd_hdsp_get_system_sample_rate \
1964 static int snd_hdsp_info_system_sample_rate(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_info
*uinfo
)
1966 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
1971 static int snd_hdsp_get_system_sample_rate(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
1973 struct hdsp
*hdsp
= snd_kcontrol_chip(kcontrol
);
1975 ucontrol
->value
.enumerated
.item
[0] = hdsp
->system_sample_rate
;
1979 #define HDSP_AUTOSYNC_SAMPLE_RATE(xname, xindex) \
1980 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1983 .access = SNDRV_CTL_ELEM_ACCESS_READ, \
1984 .info = snd_hdsp_info_autosync_sample_rate, \
1985 .get = snd_hdsp_get_autosync_sample_rate \
1988 static int snd_hdsp_info_autosync_sample_rate(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_info
*uinfo
)
1990 struct hdsp
*hdsp
= snd_kcontrol_chip(kcontrol
);
1991 static char *texts
[] = {"32000", "44100", "48000", "64000", "88200", "96000", "None", "128000", "176400", "192000"};
1992 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
1994 uinfo
->value
.enumerated
.items
= (hdsp
->io_type
== H9632
) ? 10 : 7 ;
1995 if (uinfo
->value
.enumerated
.item
>= uinfo
->value
.enumerated
.items
)
1996 uinfo
->value
.enumerated
.item
= uinfo
->value
.enumerated
.items
- 1;
1997 strcpy(uinfo
->value
.enumerated
.name
, texts
[uinfo
->value
.enumerated
.item
]);
2001 static int snd_hdsp_get_autosync_sample_rate(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
2003 struct hdsp
*hdsp
= snd_kcontrol_chip(kcontrol
);
2005 switch (hdsp_external_sample_rate(hdsp
)) {
2007 ucontrol
->value
.enumerated
.item
[0] = 0;
2010 ucontrol
->value
.enumerated
.item
[0] = 1;
2013 ucontrol
->value
.enumerated
.item
[0] = 2;
2016 ucontrol
->value
.enumerated
.item
[0] = 3;
2019 ucontrol
->value
.enumerated
.item
[0] = 4;
2022 ucontrol
->value
.enumerated
.item
[0] = 5;
2025 ucontrol
->value
.enumerated
.item
[0] = 7;
2028 ucontrol
->value
.enumerated
.item
[0] = 8;
2031 ucontrol
->value
.enumerated
.item
[0] = 9;
2034 ucontrol
->value
.enumerated
.item
[0] = 6;
2039 #define HDSP_SYSTEM_CLOCK_MODE(xname, xindex) \
2040 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2043 .access = SNDRV_CTL_ELEM_ACCESS_READ, \
2044 .info = snd_hdsp_info_system_clock_mode, \
2045 .get = snd_hdsp_get_system_clock_mode \
2048 static int hdsp_system_clock_mode(struct hdsp
*hdsp
)
2050 if (hdsp
->control_register
& HDSP_ClockModeMaster
)
2052 else if (hdsp_external_sample_rate(hdsp
) != hdsp
->system_sample_rate
)
2057 static int snd_hdsp_info_system_clock_mode(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_info
*uinfo
)
2059 static char *texts
[] = {"Master", "Slave" };
2061 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
2063 uinfo
->value
.enumerated
.items
= 2;
2064 if (uinfo
->value
.enumerated
.item
>= uinfo
->value
.enumerated
.items
)
2065 uinfo
->value
.enumerated
.item
= uinfo
->value
.enumerated
.items
- 1;
2066 strcpy(uinfo
->value
.enumerated
.name
, texts
[uinfo
->value
.enumerated
.item
]);
2070 static int snd_hdsp_get_system_clock_mode(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
2072 struct hdsp
*hdsp
= snd_kcontrol_chip(kcontrol
);
2074 ucontrol
->value
.enumerated
.item
[0] = hdsp_system_clock_mode(hdsp
);
2078 #define HDSP_CLOCK_SOURCE(xname, xindex) \
2079 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2082 .info = snd_hdsp_info_clock_source, \
2083 .get = snd_hdsp_get_clock_source, \
2084 .put = snd_hdsp_put_clock_source \
2087 static int hdsp_clock_source(struct hdsp
*hdsp
)
2089 if (hdsp
->control_register
& HDSP_ClockModeMaster
) {
2090 switch (hdsp
->system_sample_rate
) {
2117 static int hdsp_set_clock_source(struct hdsp
*hdsp
, int mode
)
2121 case HDSP_CLOCK_SOURCE_AUTOSYNC
:
2122 if (hdsp_external_sample_rate(hdsp
) != 0) {
2123 if (!hdsp_set_rate(hdsp
, hdsp_external_sample_rate(hdsp
), 1)) {
2124 hdsp
->control_register
&= ~HDSP_ClockModeMaster
;
2125 hdsp_write(hdsp
, HDSP_controlRegister
, hdsp
->control_register
);
2130 case HDSP_CLOCK_SOURCE_INTERNAL_32KHZ
:
2133 case HDSP_CLOCK_SOURCE_INTERNAL_44_1KHZ
:
2136 case HDSP_CLOCK_SOURCE_INTERNAL_48KHZ
:
2139 case HDSP_CLOCK_SOURCE_INTERNAL_64KHZ
:
2142 case HDSP_CLOCK_SOURCE_INTERNAL_88_2KHZ
:
2145 case HDSP_CLOCK_SOURCE_INTERNAL_96KHZ
:
2148 case HDSP_CLOCK_SOURCE_INTERNAL_128KHZ
:
2151 case HDSP_CLOCK_SOURCE_INTERNAL_176_4KHZ
:
2154 case HDSP_CLOCK_SOURCE_INTERNAL_192KHZ
:
2160 hdsp
->control_register
|= HDSP_ClockModeMaster
;
2161 hdsp_write(hdsp
, HDSP_controlRegister
, hdsp
->control_register
);
2162 hdsp_set_rate(hdsp
, rate
, 1);
2166 static int snd_hdsp_info_clock_source(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_info
*uinfo
)
2168 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" };
2169 struct hdsp
*hdsp
= snd_kcontrol_chip(kcontrol
);
2171 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
2173 if (hdsp
->io_type
== H9632
)
2174 uinfo
->value
.enumerated
.items
= 10;
2176 uinfo
->value
.enumerated
.items
= 7;
2177 if (uinfo
->value
.enumerated
.item
>= uinfo
->value
.enumerated
.items
)
2178 uinfo
->value
.enumerated
.item
= uinfo
->value
.enumerated
.items
- 1;
2179 strcpy(uinfo
->value
.enumerated
.name
, texts
[uinfo
->value
.enumerated
.item
]);
2183 static int snd_hdsp_get_clock_source(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
2185 struct hdsp
*hdsp
= snd_kcontrol_chip(kcontrol
);
2187 ucontrol
->value
.enumerated
.item
[0] = hdsp_clock_source(hdsp
);
2191 static int snd_hdsp_put_clock_source(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
2193 struct hdsp
*hdsp
= snd_kcontrol_chip(kcontrol
);
2197 if (!snd_hdsp_use_is_exclusive(hdsp
))
2199 val
= ucontrol
->value
.enumerated
.item
[0];
2200 if (val
< 0) val
= 0;
2201 if (hdsp
->io_type
== H9632
) {
2208 spin_lock_irq(&hdsp
->lock
);
2209 if (val
!= hdsp_clock_source(hdsp
))
2210 change
= (hdsp_set_clock_source(hdsp
, val
) == 0) ? 1 : 0;
2213 spin_unlock_irq(&hdsp
->lock
);
2217 #define snd_hdsp_info_clock_source_lock snd_ctl_boolean_mono_info
2219 static int snd_hdsp_get_clock_source_lock(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
2221 struct hdsp
*hdsp
= snd_kcontrol_chip(kcontrol
);
2223 ucontrol
->value
.integer
.value
[0] = hdsp
->clock_source_locked
;
2227 static int snd_hdsp_put_clock_source_lock(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
2229 struct hdsp
*hdsp
= snd_kcontrol_chip(kcontrol
);
2232 change
= (int)ucontrol
->value
.integer
.value
[0] != hdsp
->clock_source_locked
;
2234 hdsp
->clock_source_locked
= !!ucontrol
->value
.integer
.value
[0];
2238 #define HDSP_DA_GAIN(xname, xindex) \
2239 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2242 .info = snd_hdsp_info_da_gain, \
2243 .get = snd_hdsp_get_da_gain, \
2244 .put = snd_hdsp_put_da_gain \
2247 static int hdsp_da_gain(struct hdsp
*hdsp
)
2249 switch (hdsp
->control_register
& HDSP_DAGainMask
) {
2250 case HDSP_DAGainHighGain
:
2252 case HDSP_DAGainPlus4dBu
:
2254 case HDSP_DAGainMinus10dBV
:
2261 static int hdsp_set_da_gain(struct hdsp
*hdsp
, int mode
)
2263 hdsp
->control_register
&= ~HDSP_DAGainMask
;
2266 hdsp
->control_register
|= HDSP_DAGainHighGain
;
2269 hdsp
->control_register
|= HDSP_DAGainPlus4dBu
;
2272 hdsp
->control_register
|= HDSP_DAGainMinus10dBV
;
2278 hdsp_write(hdsp
, HDSP_controlRegister
, hdsp
->control_register
);
2282 static int snd_hdsp_info_da_gain(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_info
*uinfo
)
2284 static char *texts
[] = {"Hi Gain", "+4 dBu", "-10 dbV"};
2286 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
2288 uinfo
->value
.enumerated
.items
= 3;
2289 if (uinfo
->value
.enumerated
.item
>= uinfo
->value
.enumerated
.items
)
2290 uinfo
->value
.enumerated
.item
= uinfo
->value
.enumerated
.items
- 1;
2291 strcpy(uinfo
->value
.enumerated
.name
, texts
[uinfo
->value
.enumerated
.item
]);
2295 static int snd_hdsp_get_da_gain(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
2297 struct hdsp
*hdsp
= snd_kcontrol_chip(kcontrol
);
2299 ucontrol
->value
.enumerated
.item
[0] = hdsp_da_gain(hdsp
);
2303 static int snd_hdsp_put_da_gain(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
2305 struct hdsp
*hdsp
= snd_kcontrol_chip(kcontrol
);
2309 if (!snd_hdsp_use_is_exclusive(hdsp
))
2311 val
= ucontrol
->value
.enumerated
.item
[0];
2312 if (val
< 0) val
= 0;
2313 if (val
> 2) val
= 2;
2314 spin_lock_irq(&hdsp
->lock
);
2315 if (val
!= hdsp_da_gain(hdsp
))
2316 change
= (hdsp_set_da_gain(hdsp
, val
) == 0) ? 1 : 0;
2319 spin_unlock_irq(&hdsp
->lock
);
2323 #define HDSP_AD_GAIN(xname, xindex) \
2324 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2327 .info = snd_hdsp_info_ad_gain, \
2328 .get = snd_hdsp_get_ad_gain, \
2329 .put = snd_hdsp_put_ad_gain \
2332 static int hdsp_ad_gain(struct hdsp
*hdsp
)
2334 switch (hdsp
->control_register
& HDSP_ADGainMask
) {
2335 case HDSP_ADGainMinus10dBV
:
2337 case HDSP_ADGainPlus4dBu
:
2339 case HDSP_ADGainLowGain
:
2346 static int hdsp_set_ad_gain(struct hdsp
*hdsp
, int mode
)
2348 hdsp
->control_register
&= ~HDSP_ADGainMask
;
2351 hdsp
->control_register
|= HDSP_ADGainMinus10dBV
;
2354 hdsp
->control_register
|= HDSP_ADGainPlus4dBu
;
2357 hdsp
->control_register
|= HDSP_ADGainLowGain
;
2363 hdsp_write(hdsp
, HDSP_controlRegister
, hdsp
->control_register
);
2367 static int snd_hdsp_info_ad_gain(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_info
*uinfo
)
2369 static char *texts
[] = {"-10 dBV", "+4 dBu", "Lo Gain"};
2371 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
2373 uinfo
->value
.enumerated
.items
= 3;
2374 if (uinfo
->value
.enumerated
.item
>= uinfo
->value
.enumerated
.items
)
2375 uinfo
->value
.enumerated
.item
= uinfo
->value
.enumerated
.items
- 1;
2376 strcpy(uinfo
->value
.enumerated
.name
, texts
[uinfo
->value
.enumerated
.item
]);
2380 static int snd_hdsp_get_ad_gain(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
2382 struct hdsp
*hdsp
= snd_kcontrol_chip(kcontrol
);
2384 ucontrol
->value
.enumerated
.item
[0] = hdsp_ad_gain(hdsp
);
2388 static int snd_hdsp_put_ad_gain(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
2390 struct hdsp
*hdsp
= snd_kcontrol_chip(kcontrol
);
2394 if (!snd_hdsp_use_is_exclusive(hdsp
))
2396 val
= ucontrol
->value
.enumerated
.item
[0];
2397 if (val
< 0) val
= 0;
2398 if (val
> 2) val
= 2;
2399 spin_lock_irq(&hdsp
->lock
);
2400 if (val
!= hdsp_ad_gain(hdsp
))
2401 change
= (hdsp_set_ad_gain(hdsp
, val
) == 0) ? 1 : 0;
2404 spin_unlock_irq(&hdsp
->lock
);
2408 #define HDSP_PHONE_GAIN(xname, xindex) \
2409 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2412 .info = snd_hdsp_info_phone_gain, \
2413 .get = snd_hdsp_get_phone_gain, \
2414 .put = snd_hdsp_put_phone_gain \
2417 static int hdsp_phone_gain(struct hdsp
*hdsp
)
2419 switch (hdsp
->control_register
& HDSP_PhoneGainMask
) {
2420 case HDSP_PhoneGain0dB
:
2422 case HDSP_PhoneGainMinus6dB
:
2424 case HDSP_PhoneGainMinus12dB
:
2431 static int hdsp_set_phone_gain(struct hdsp
*hdsp
, int mode
)
2433 hdsp
->control_register
&= ~HDSP_PhoneGainMask
;
2436 hdsp
->control_register
|= HDSP_PhoneGain0dB
;
2439 hdsp
->control_register
|= HDSP_PhoneGainMinus6dB
;
2442 hdsp
->control_register
|= HDSP_PhoneGainMinus12dB
;
2448 hdsp_write(hdsp
, HDSP_controlRegister
, hdsp
->control_register
);
2452 static int snd_hdsp_info_phone_gain(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_info
*uinfo
)
2454 static char *texts
[] = {"0 dB", "-6 dB", "-12 dB"};
2456 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
2458 uinfo
->value
.enumerated
.items
= 3;
2459 if (uinfo
->value
.enumerated
.item
>= uinfo
->value
.enumerated
.items
)
2460 uinfo
->value
.enumerated
.item
= uinfo
->value
.enumerated
.items
- 1;
2461 strcpy(uinfo
->value
.enumerated
.name
, texts
[uinfo
->value
.enumerated
.item
]);
2465 static int snd_hdsp_get_phone_gain(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
2467 struct hdsp
*hdsp
= snd_kcontrol_chip(kcontrol
);
2469 ucontrol
->value
.enumerated
.item
[0] = hdsp_phone_gain(hdsp
);
2473 static int snd_hdsp_put_phone_gain(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
2475 struct hdsp
*hdsp
= snd_kcontrol_chip(kcontrol
);
2479 if (!snd_hdsp_use_is_exclusive(hdsp
))
2481 val
= ucontrol
->value
.enumerated
.item
[0];
2482 if (val
< 0) val
= 0;
2483 if (val
> 2) val
= 2;
2484 spin_lock_irq(&hdsp
->lock
);
2485 if (val
!= hdsp_phone_gain(hdsp
))
2486 change
= (hdsp_set_phone_gain(hdsp
, val
) == 0) ? 1 : 0;
2489 spin_unlock_irq(&hdsp
->lock
);
2493 #define HDSP_XLR_BREAKOUT_CABLE(xname, xindex) \
2494 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2497 .info = snd_hdsp_info_xlr_breakout_cable, \
2498 .get = snd_hdsp_get_xlr_breakout_cable, \
2499 .put = snd_hdsp_put_xlr_breakout_cable \
2502 static int hdsp_xlr_breakout_cable(struct hdsp
*hdsp
)
2504 if (hdsp
->control_register
& HDSP_XLRBreakoutCable
)
2509 static int hdsp_set_xlr_breakout_cable(struct hdsp
*hdsp
, int mode
)
2512 hdsp
->control_register
|= HDSP_XLRBreakoutCable
;
2514 hdsp
->control_register
&= ~HDSP_XLRBreakoutCable
;
2515 hdsp_write(hdsp
, HDSP_controlRegister
, hdsp
->control_register
);
2519 #define snd_hdsp_info_xlr_breakout_cable snd_ctl_boolean_mono_info
2521 static int snd_hdsp_get_xlr_breakout_cable(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
2523 struct hdsp
*hdsp
= snd_kcontrol_chip(kcontrol
);
2525 ucontrol
->value
.enumerated
.item
[0] = hdsp_xlr_breakout_cable(hdsp
);
2529 static int snd_hdsp_put_xlr_breakout_cable(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
2531 struct hdsp
*hdsp
= snd_kcontrol_chip(kcontrol
);
2535 if (!snd_hdsp_use_is_exclusive(hdsp
))
2537 val
= ucontrol
->value
.integer
.value
[0] & 1;
2538 spin_lock_irq(&hdsp
->lock
);
2539 change
= (int)val
!= hdsp_xlr_breakout_cable(hdsp
);
2540 hdsp_set_xlr_breakout_cable(hdsp
, val
);
2541 spin_unlock_irq(&hdsp
->lock
);
2545 /* (De)activates old RME Analog Extension Board
2546 These are connected to the internal ADAT connector
2547 Switching this on desactivates external ADAT
2549 #define HDSP_AEB(xname, xindex) \
2550 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2553 .info = snd_hdsp_info_aeb, \
2554 .get = snd_hdsp_get_aeb, \
2555 .put = snd_hdsp_put_aeb \
2558 static int hdsp_aeb(struct hdsp
*hdsp
)
2560 if (hdsp
->control_register
& HDSP_AnalogExtensionBoard
)
2565 static int hdsp_set_aeb(struct hdsp
*hdsp
, int mode
)
2568 hdsp
->control_register
|= HDSP_AnalogExtensionBoard
;
2570 hdsp
->control_register
&= ~HDSP_AnalogExtensionBoard
;
2571 hdsp_write(hdsp
, HDSP_controlRegister
, hdsp
->control_register
);
2575 #define snd_hdsp_info_aeb snd_ctl_boolean_mono_info
2577 static int snd_hdsp_get_aeb(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
2579 struct hdsp
*hdsp
= snd_kcontrol_chip(kcontrol
);
2581 ucontrol
->value
.enumerated
.item
[0] = hdsp_aeb(hdsp
);
2585 static int snd_hdsp_put_aeb(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_aeb(hdsp
);
2596 hdsp_set_aeb(hdsp
, val
);
2597 spin_unlock_irq(&hdsp
->lock
);
2601 #define HDSP_PREF_SYNC_REF(xname, xindex) \
2602 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2605 .info = snd_hdsp_info_pref_sync_ref, \
2606 .get = snd_hdsp_get_pref_sync_ref, \
2607 .put = snd_hdsp_put_pref_sync_ref \
2610 static int hdsp_pref_sync_ref(struct hdsp
*hdsp
)
2612 /* Notice that this looks at the requested sync source,
2613 not the one actually in use.
2616 switch (hdsp
->control_register
& HDSP_SyncRefMask
) {
2617 case HDSP_SyncRef_ADAT1
:
2618 return HDSP_SYNC_FROM_ADAT1
;
2619 case HDSP_SyncRef_ADAT2
:
2620 return HDSP_SYNC_FROM_ADAT2
;
2621 case HDSP_SyncRef_ADAT3
:
2622 return HDSP_SYNC_FROM_ADAT3
;
2623 case HDSP_SyncRef_SPDIF
:
2624 return HDSP_SYNC_FROM_SPDIF
;
2625 case HDSP_SyncRef_WORD
:
2626 return HDSP_SYNC_FROM_WORD
;
2627 case HDSP_SyncRef_ADAT_SYNC
:
2628 return HDSP_SYNC_FROM_ADAT_SYNC
;
2630 return HDSP_SYNC_FROM_WORD
;
2635 static int hdsp_set_pref_sync_ref(struct hdsp
*hdsp
, int pref
)
2637 hdsp
->control_register
&= ~HDSP_SyncRefMask
;
2639 case HDSP_SYNC_FROM_ADAT1
:
2640 hdsp
->control_register
&= ~HDSP_SyncRefMask
; /* clear SyncRef bits */
2642 case HDSP_SYNC_FROM_ADAT2
:
2643 hdsp
->control_register
|= HDSP_SyncRef_ADAT2
;
2645 case HDSP_SYNC_FROM_ADAT3
:
2646 hdsp
->control_register
|= HDSP_SyncRef_ADAT3
;
2648 case HDSP_SYNC_FROM_SPDIF
:
2649 hdsp
->control_register
|= HDSP_SyncRef_SPDIF
;
2651 case HDSP_SYNC_FROM_WORD
:
2652 hdsp
->control_register
|= HDSP_SyncRef_WORD
;
2654 case HDSP_SYNC_FROM_ADAT_SYNC
:
2655 hdsp
->control_register
|= HDSP_SyncRef_ADAT_SYNC
;
2660 hdsp_write(hdsp
, HDSP_controlRegister
, hdsp
->control_register
);
2664 static int snd_hdsp_info_pref_sync_ref(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_info
*uinfo
)
2666 static char *texts
[] = {"Word", "IEC958", "ADAT1", "ADAT Sync", "ADAT2", "ADAT3" };
2667 struct hdsp
*hdsp
= snd_kcontrol_chip(kcontrol
);
2669 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
2672 switch (hdsp
->io_type
) {
2675 uinfo
->value
.enumerated
.items
= 6;
2678 uinfo
->value
.enumerated
.items
= 4;
2681 uinfo
->value
.enumerated
.items
= 3;
2687 if (uinfo
->value
.enumerated
.item
>= uinfo
->value
.enumerated
.items
)
2688 uinfo
->value
.enumerated
.item
= uinfo
->value
.enumerated
.items
- 1;
2689 strcpy(uinfo
->value
.enumerated
.name
, texts
[uinfo
->value
.enumerated
.item
]);
2693 static int snd_hdsp_get_pref_sync_ref(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
2695 struct hdsp
*hdsp
= snd_kcontrol_chip(kcontrol
);
2697 ucontrol
->value
.enumerated
.item
[0] = hdsp_pref_sync_ref(hdsp
);
2701 static int snd_hdsp_put_pref_sync_ref(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
2703 struct hdsp
*hdsp
= snd_kcontrol_chip(kcontrol
);
2707 if (!snd_hdsp_use_is_exclusive(hdsp
))
2710 switch (hdsp
->io_type
) {
2725 val
= ucontrol
->value
.enumerated
.item
[0] % max
;
2726 spin_lock_irq(&hdsp
->lock
);
2727 change
= (int)val
!= hdsp_pref_sync_ref(hdsp
);
2728 hdsp_set_pref_sync_ref(hdsp
, val
);
2729 spin_unlock_irq(&hdsp
->lock
);
2733 #define HDSP_AUTOSYNC_REF(xname, xindex) \
2734 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2737 .access = SNDRV_CTL_ELEM_ACCESS_READ, \
2738 .info = snd_hdsp_info_autosync_ref, \
2739 .get = snd_hdsp_get_autosync_ref, \
2742 static int hdsp_autosync_ref(struct hdsp
*hdsp
)
2744 /* This looks at the autosync selected sync reference */
2745 unsigned int status2
= hdsp_read(hdsp
, HDSP_status2Register
);
2747 switch (status2
& HDSP_SelSyncRefMask
) {
2748 case HDSP_SelSyncRef_WORD
:
2749 return HDSP_AUTOSYNC_FROM_WORD
;
2750 case HDSP_SelSyncRef_ADAT_SYNC
:
2751 return HDSP_AUTOSYNC_FROM_ADAT_SYNC
;
2752 case HDSP_SelSyncRef_SPDIF
:
2753 return HDSP_AUTOSYNC_FROM_SPDIF
;
2754 case HDSP_SelSyncRefMask
:
2755 return HDSP_AUTOSYNC_FROM_NONE
;
2756 case HDSP_SelSyncRef_ADAT1
:
2757 return HDSP_AUTOSYNC_FROM_ADAT1
;
2758 case HDSP_SelSyncRef_ADAT2
:
2759 return HDSP_AUTOSYNC_FROM_ADAT2
;
2760 case HDSP_SelSyncRef_ADAT3
:
2761 return HDSP_AUTOSYNC_FROM_ADAT3
;
2763 return HDSP_AUTOSYNC_FROM_WORD
;
2768 static int snd_hdsp_info_autosync_ref(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_info
*uinfo
)
2770 static char *texts
[] = {"Word", "ADAT Sync", "IEC958", "None", "ADAT1", "ADAT2", "ADAT3" };
2772 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
2774 uinfo
->value
.enumerated
.items
= 7;
2775 if (uinfo
->value
.enumerated
.item
>= uinfo
->value
.enumerated
.items
)
2776 uinfo
->value
.enumerated
.item
= uinfo
->value
.enumerated
.items
- 1;
2777 strcpy(uinfo
->value
.enumerated
.name
, texts
[uinfo
->value
.enumerated
.item
]);
2781 static int snd_hdsp_get_autosync_ref(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
2783 struct hdsp
*hdsp
= snd_kcontrol_chip(kcontrol
);
2785 ucontrol
->value
.enumerated
.item
[0] = hdsp_autosync_ref(hdsp
);
2789 #define HDSP_LINE_OUT(xname, xindex) \
2790 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2793 .info = snd_hdsp_info_line_out, \
2794 .get = snd_hdsp_get_line_out, \
2795 .put = snd_hdsp_put_line_out \
2798 static int hdsp_line_out(struct hdsp
*hdsp
)
2800 return (hdsp
->control_register
& HDSP_LineOut
) ? 1 : 0;
2803 static int hdsp_set_line_output(struct hdsp
*hdsp
, int out
)
2806 hdsp
->control_register
|= HDSP_LineOut
;
2808 hdsp
->control_register
&= ~HDSP_LineOut
;
2809 hdsp_write(hdsp
, HDSP_controlRegister
, hdsp
->control_register
);
2813 #define snd_hdsp_info_line_out snd_ctl_boolean_mono_info
2815 static int snd_hdsp_get_line_out(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
2817 struct hdsp
*hdsp
= snd_kcontrol_chip(kcontrol
);
2819 spin_lock_irq(&hdsp
->lock
);
2820 ucontrol
->value
.integer
.value
[0] = hdsp_line_out(hdsp
);
2821 spin_unlock_irq(&hdsp
->lock
);
2825 static int snd_hdsp_put_line_out(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
2827 struct hdsp
*hdsp
= snd_kcontrol_chip(kcontrol
);
2831 if (!snd_hdsp_use_is_exclusive(hdsp
))
2833 val
= ucontrol
->value
.integer
.value
[0] & 1;
2834 spin_lock_irq(&hdsp
->lock
);
2835 change
= (int)val
!= hdsp_line_out(hdsp
);
2836 hdsp_set_line_output(hdsp
, val
);
2837 spin_unlock_irq(&hdsp
->lock
);
2841 #define HDSP_PRECISE_POINTER(xname, xindex) \
2842 { .iface = SNDRV_CTL_ELEM_IFACE_CARD, \
2845 .info = snd_hdsp_info_precise_pointer, \
2846 .get = snd_hdsp_get_precise_pointer, \
2847 .put = snd_hdsp_put_precise_pointer \
2850 static int hdsp_set_precise_pointer(struct hdsp
*hdsp
, int precise
)
2853 hdsp
->precise_ptr
= 1;
2855 hdsp
->precise_ptr
= 0;
2859 #define snd_hdsp_info_precise_pointer snd_ctl_boolean_mono_info
2861 static int snd_hdsp_get_precise_pointer(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
2863 struct hdsp
*hdsp
= snd_kcontrol_chip(kcontrol
);
2865 spin_lock_irq(&hdsp
->lock
);
2866 ucontrol
->value
.integer
.value
[0] = hdsp
->precise_ptr
;
2867 spin_unlock_irq(&hdsp
->lock
);
2871 static int snd_hdsp_put_precise_pointer(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
2873 struct hdsp
*hdsp
= snd_kcontrol_chip(kcontrol
);
2877 if (!snd_hdsp_use_is_exclusive(hdsp
))
2879 val
= ucontrol
->value
.integer
.value
[0] & 1;
2880 spin_lock_irq(&hdsp
->lock
);
2881 change
= (int)val
!= hdsp
->precise_ptr
;
2882 hdsp_set_precise_pointer(hdsp
, val
);
2883 spin_unlock_irq(&hdsp
->lock
);
2887 #define HDSP_USE_MIDI_TASKLET(xname, xindex) \
2888 { .iface = SNDRV_CTL_ELEM_IFACE_CARD, \
2891 .info = snd_hdsp_info_use_midi_tasklet, \
2892 .get = snd_hdsp_get_use_midi_tasklet, \
2893 .put = snd_hdsp_put_use_midi_tasklet \
2896 static int hdsp_set_use_midi_tasklet(struct hdsp
*hdsp
, int use_tasklet
)
2899 hdsp
->use_midi_tasklet
= 1;
2901 hdsp
->use_midi_tasklet
= 0;
2905 #define snd_hdsp_info_use_midi_tasklet snd_ctl_boolean_mono_info
2907 static int snd_hdsp_get_use_midi_tasklet(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
2909 struct hdsp
*hdsp
= snd_kcontrol_chip(kcontrol
);
2911 spin_lock_irq(&hdsp
->lock
);
2912 ucontrol
->value
.integer
.value
[0] = hdsp
->use_midi_tasklet
;
2913 spin_unlock_irq(&hdsp
->lock
);
2917 static int snd_hdsp_put_use_midi_tasklet(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
2919 struct hdsp
*hdsp
= snd_kcontrol_chip(kcontrol
);
2923 if (!snd_hdsp_use_is_exclusive(hdsp
))
2925 val
= ucontrol
->value
.integer
.value
[0] & 1;
2926 spin_lock_irq(&hdsp
->lock
);
2927 change
= (int)val
!= hdsp
->use_midi_tasklet
;
2928 hdsp_set_use_midi_tasklet(hdsp
, val
);
2929 spin_unlock_irq(&hdsp
->lock
);
2933 #define HDSP_MIXER(xname, xindex) \
2934 { .iface = SNDRV_CTL_ELEM_IFACE_HWDEP, \
2938 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | \
2939 SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
2940 .info = snd_hdsp_info_mixer, \
2941 .get = snd_hdsp_get_mixer, \
2942 .put = snd_hdsp_put_mixer \
2945 static int snd_hdsp_info_mixer(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_info
*uinfo
)
2947 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
2949 uinfo
->value
.integer
.min
= 0;
2950 uinfo
->value
.integer
.max
= 65536;
2951 uinfo
->value
.integer
.step
= 1;
2955 static int snd_hdsp_get_mixer(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
2957 struct hdsp
*hdsp
= snd_kcontrol_chip(kcontrol
);
2962 source
= ucontrol
->value
.integer
.value
[0];
2963 destination
= ucontrol
->value
.integer
.value
[1];
2965 if (source
>= hdsp
->max_channels
)
2966 addr
= hdsp_playback_to_output_key(hdsp
,source
-hdsp
->max_channels
,destination
);
2968 addr
= hdsp_input_to_output_key(hdsp
,source
, destination
);
2970 spin_lock_irq(&hdsp
->lock
);
2971 ucontrol
->value
.integer
.value
[2] = hdsp_read_gain (hdsp
, addr
);
2972 spin_unlock_irq(&hdsp
->lock
);
2976 static int snd_hdsp_put_mixer(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
2978 struct hdsp
*hdsp
= snd_kcontrol_chip(kcontrol
);
2985 if (!snd_hdsp_use_is_exclusive(hdsp
))
2988 source
= ucontrol
->value
.integer
.value
[0];
2989 destination
= ucontrol
->value
.integer
.value
[1];
2991 if (source
>= hdsp
->max_channels
)
2992 addr
= hdsp_playback_to_output_key(hdsp
,source
-hdsp
->max_channels
, destination
);
2994 addr
= hdsp_input_to_output_key(hdsp
,source
, destination
);
2996 gain
= ucontrol
->value
.integer
.value
[2];
2998 spin_lock_irq(&hdsp
->lock
);
2999 change
= gain
!= hdsp_read_gain(hdsp
, addr
);
3001 hdsp_write_gain(hdsp
, addr
, gain
);
3002 spin_unlock_irq(&hdsp
->lock
);
3006 #define HDSP_WC_SYNC_CHECK(xname, xindex) \
3007 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
3010 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
3011 .info = snd_hdsp_info_sync_check, \
3012 .get = snd_hdsp_get_wc_sync_check \
3015 static int snd_hdsp_info_sync_check(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_info
*uinfo
)
3017 static char *texts
[] = {"No Lock", "Lock", "Sync" };
3018 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
3020 uinfo
->value
.enumerated
.items
= 3;
3021 if (uinfo
->value
.enumerated
.item
>= uinfo
->value
.enumerated
.items
)
3022 uinfo
->value
.enumerated
.item
= uinfo
->value
.enumerated
.items
- 1;
3023 strcpy(uinfo
->value
.enumerated
.name
, texts
[uinfo
->value
.enumerated
.item
]);
3027 static int hdsp_wc_sync_check(struct hdsp
*hdsp
)
3029 int status2
= hdsp_read(hdsp
, HDSP_status2Register
);
3030 if (status2
& HDSP_wc_lock
) {
3031 if (status2
& HDSP_wc_sync
)
3040 static int snd_hdsp_get_wc_sync_check(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
3042 struct hdsp
*hdsp
= snd_kcontrol_chip(kcontrol
);
3044 ucontrol
->value
.enumerated
.item
[0] = hdsp_wc_sync_check(hdsp
);
3048 #define HDSP_SPDIF_SYNC_CHECK(xname, xindex) \
3049 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
3052 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
3053 .info = snd_hdsp_info_sync_check, \
3054 .get = snd_hdsp_get_spdif_sync_check \
3057 static int hdsp_spdif_sync_check(struct hdsp
*hdsp
)
3059 int status
= hdsp_read(hdsp
, HDSP_statusRegister
);
3060 if (status
& HDSP_SPDIFErrorFlag
)
3063 if (status
& HDSP_SPDIFSync
)
3071 static int snd_hdsp_get_spdif_sync_check(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
3073 struct hdsp
*hdsp
= snd_kcontrol_chip(kcontrol
);
3075 ucontrol
->value
.enumerated
.item
[0] = hdsp_spdif_sync_check(hdsp
);
3079 #define HDSP_ADATSYNC_SYNC_CHECK(xname, xindex) \
3080 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
3083 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
3084 .info = snd_hdsp_info_sync_check, \
3085 .get = snd_hdsp_get_adatsync_sync_check \
3088 static int hdsp_adatsync_sync_check(struct hdsp
*hdsp
)
3090 int status
= hdsp_read(hdsp
, HDSP_statusRegister
);
3091 if (status
& HDSP_TimecodeLock
) {
3092 if (status
& HDSP_TimecodeSync
)
3100 static int snd_hdsp_get_adatsync_sync_check(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
3102 struct hdsp
*hdsp
= snd_kcontrol_chip(kcontrol
);
3104 ucontrol
->value
.enumerated
.item
[0] = hdsp_adatsync_sync_check(hdsp
);
3108 #define HDSP_ADAT_SYNC_CHECK \
3109 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
3110 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
3111 .info = snd_hdsp_info_sync_check, \
3112 .get = snd_hdsp_get_adat_sync_check \
3115 static int hdsp_adat_sync_check(struct hdsp
*hdsp
, int idx
)
3117 int status
= hdsp_read(hdsp
, HDSP_statusRegister
);
3119 if (status
& (HDSP_Lock0
>>idx
)) {
3120 if (status
& (HDSP_Sync0
>>idx
))
3128 static int snd_hdsp_get_adat_sync_check(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
3131 struct hdsp
*hdsp
= snd_kcontrol_chip(kcontrol
);
3133 offset
= ucontrol
->id
.index
- 1;
3134 snd_BUG_ON(offset
< 0);
3136 switch (hdsp
->io_type
) {
3151 ucontrol
->value
.enumerated
.item
[0] = hdsp_adat_sync_check(hdsp
, offset
);
3155 #define HDSP_DDS_OFFSET(xname, xindex) \
3156 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
3159 .info = snd_hdsp_info_dds_offset, \
3160 .get = snd_hdsp_get_dds_offset, \
3161 .put = snd_hdsp_put_dds_offset \
3164 static int hdsp_dds_offset(struct hdsp
*hdsp
)
3167 unsigned int dds_value
= hdsp
->dds_value
;
3168 int system_sample_rate
= hdsp
->system_sample_rate
;
3175 * dds_value = n / rate
3176 * rate = n / dds_value
3178 n
= div_u64(n
, dds_value
);
3179 if (system_sample_rate
>= 112000)
3181 else if (system_sample_rate
>= 56000)
3183 return ((int)n
) - system_sample_rate
;
3186 static int hdsp_set_dds_offset(struct hdsp
*hdsp
, int offset_hz
)
3188 int rate
= hdsp
->system_sample_rate
+ offset_hz
;
3189 hdsp_set_dds_value(hdsp
, rate
);
3193 static int snd_hdsp_info_dds_offset(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_info
*uinfo
)
3195 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_INTEGER
;
3197 uinfo
->value
.integer
.min
= -5000;
3198 uinfo
->value
.integer
.max
= 5000;
3202 static int snd_hdsp_get_dds_offset(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
3204 struct hdsp
*hdsp
= snd_kcontrol_chip(kcontrol
);
3206 ucontrol
->value
.enumerated
.item
[0] = hdsp_dds_offset(hdsp
);
3210 static int snd_hdsp_put_dds_offset(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
3212 struct hdsp
*hdsp
= snd_kcontrol_chip(kcontrol
);
3216 if (!snd_hdsp_use_is_exclusive(hdsp
))
3218 val
= ucontrol
->value
.enumerated
.item
[0];
3219 spin_lock_irq(&hdsp
->lock
);
3220 if (val
!= hdsp_dds_offset(hdsp
))
3221 change
= (hdsp_set_dds_offset(hdsp
, val
) == 0) ? 1 : 0;
3224 spin_unlock_irq(&hdsp
->lock
);
3228 static struct snd_kcontrol_new snd_hdsp_9632_controls
[] = {
3229 HDSP_DA_GAIN("DA Gain", 0),
3230 HDSP_AD_GAIN("AD Gain", 0),
3231 HDSP_PHONE_GAIN("Phones Gain", 0),
3232 HDSP_XLR_BREAKOUT_CABLE("XLR Breakout Cable", 0),
3233 HDSP_DDS_OFFSET("DDS Sample Rate Offset", 0)
3236 static struct snd_kcontrol_new snd_hdsp_controls
[] = {
3238 .iface
= SNDRV_CTL_ELEM_IFACE_PCM
,
3239 .name
= SNDRV_CTL_NAME_IEC958("",PLAYBACK
,DEFAULT
),
3240 .info
= snd_hdsp_control_spdif_info
,
3241 .get
= snd_hdsp_control_spdif_get
,
3242 .put
= snd_hdsp_control_spdif_put
,
3245 .access
= SNDRV_CTL_ELEM_ACCESS_READWRITE
| SNDRV_CTL_ELEM_ACCESS_INACTIVE
,
3246 .iface
= SNDRV_CTL_ELEM_IFACE_PCM
,
3247 .name
= SNDRV_CTL_NAME_IEC958("",PLAYBACK
,PCM_STREAM
),
3248 .info
= snd_hdsp_control_spdif_stream_info
,
3249 .get
= snd_hdsp_control_spdif_stream_get
,
3250 .put
= snd_hdsp_control_spdif_stream_put
,
3253 .access
= SNDRV_CTL_ELEM_ACCESS_READ
,
3254 .iface
= SNDRV_CTL_ELEM_IFACE_PCM
,
3255 .name
= SNDRV_CTL_NAME_IEC958("",PLAYBACK
,CON_MASK
),
3256 .info
= snd_hdsp_control_spdif_mask_info
,
3257 .get
= snd_hdsp_control_spdif_mask_get
,
3258 .private_value
= IEC958_AES0_NONAUDIO
|
3259 IEC958_AES0_PROFESSIONAL
|
3260 IEC958_AES0_CON_EMPHASIS
,
3263 .access
= SNDRV_CTL_ELEM_ACCESS_READ
,
3264 .iface
= SNDRV_CTL_ELEM_IFACE_PCM
,
3265 .name
= SNDRV_CTL_NAME_IEC958("",PLAYBACK
,PRO_MASK
),
3266 .info
= snd_hdsp_control_spdif_mask_info
,
3267 .get
= snd_hdsp_control_spdif_mask_get
,
3268 .private_value
= IEC958_AES0_NONAUDIO
|
3269 IEC958_AES0_PROFESSIONAL
|
3270 IEC958_AES0_PRO_EMPHASIS
,
3272 HDSP_MIXER("Mixer", 0),
3273 HDSP_SPDIF_IN("IEC958 Input Connector", 0),
3274 HDSP_SPDIF_OUT("IEC958 Output also on ADAT1", 0),
3275 HDSP_SPDIF_PROFESSIONAL("IEC958 Professional Bit", 0),
3276 HDSP_SPDIF_EMPHASIS("IEC958 Emphasis Bit", 0),
3277 HDSP_SPDIF_NON_AUDIO("IEC958 Non-audio Bit", 0),
3278 /* 'Sample Clock Source' complies with the alsa control naming scheme */
3279 HDSP_CLOCK_SOURCE("Sample Clock Source", 0),
3281 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
3282 .name
= "Sample Clock Source Locking",
3283 .info
= snd_hdsp_info_clock_source_lock
,
3284 .get
= snd_hdsp_get_clock_source_lock
,
3285 .put
= snd_hdsp_put_clock_source_lock
,
3287 HDSP_SYSTEM_CLOCK_MODE("System Clock Mode", 0),
3288 HDSP_PREF_SYNC_REF("Preferred Sync Reference", 0),
3289 HDSP_AUTOSYNC_REF("AutoSync Reference", 0),
3290 HDSP_SPDIF_SAMPLE_RATE("SPDIF Sample Rate", 0),
3291 HDSP_SYSTEM_SAMPLE_RATE("System Sample Rate", 0),
3292 /* 'External Rate' complies with the alsa control naming scheme */
3293 HDSP_AUTOSYNC_SAMPLE_RATE("External Rate", 0),
3294 HDSP_WC_SYNC_CHECK("Word Clock Lock Status", 0),
3295 HDSP_SPDIF_SYNC_CHECK("SPDIF Lock Status", 0),
3296 HDSP_ADATSYNC_SYNC_CHECK("ADAT Sync Lock Status", 0),
3297 HDSP_LINE_OUT("Line Out", 0),
3298 HDSP_PRECISE_POINTER("Precise Pointer", 0),
3299 HDSP_USE_MIDI_TASKLET("Use Midi Tasklet", 0),
3303 static int hdsp_rpm_input12(struct hdsp
*hdsp
)
3305 switch (hdsp
->control_register
& HDSP_RPM_Inp12
) {
3306 case HDSP_RPM_Inp12_Phon_6dB
:
3308 case HDSP_RPM_Inp12_Phon_n6dB
:
3310 case HDSP_RPM_Inp12_Line_0dB
:
3312 case HDSP_RPM_Inp12_Line_n6dB
:
3319 static int snd_hdsp_get_rpm_input12(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
3321 struct hdsp
*hdsp
= snd_kcontrol_chip(kcontrol
);
3323 ucontrol
->value
.enumerated
.item
[0] = hdsp_rpm_input12(hdsp
);
3328 static int hdsp_set_rpm_input12(struct hdsp
*hdsp
, int mode
)
3330 hdsp
->control_register
&= ~HDSP_RPM_Inp12
;
3333 hdsp
->control_register
|= HDSP_RPM_Inp12_Phon_6dB
;
3338 hdsp
->control_register
|= HDSP_RPM_Inp12_Phon_n6dB
;
3341 hdsp
->control_register
|= HDSP_RPM_Inp12_Line_0dB
;
3344 hdsp
->control_register
|= HDSP_RPM_Inp12_Line_n6dB
;
3350 hdsp_write(hdsp
, HDSP_controlRegister
, hdsp
->control_register
);
3355 static int snd_hdsp_put_rpm_input12(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
3357 struct hdsp
*hdsp
= snd_kcontrol_chip(kcontrol
);
3361 if (!snd_hdsp_use_is_exclusive(hdsp
))
3363 val
= ucontrol
->value
.enumerated
.item
[0];
3368 spin_lock_irq(&hdsp
->lock
);
3369 if (val
!= hdsp_rpm_input12(hdsp
))
3370 change
= (hdsp_set_rpm_input12(hdsp
, val
) == 0) ? 1 : 0;
3373 spin_unlock_irq(&hdsp
->lock
);
3378 static int snd_hdsp_info_rpm_input(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_info
*uinfo
)
3380 static char *texts
[] = {"Phono +6dB", "Phono 0dB", "Phono -6dB", "Line 0dB", "Line -6dB"};
3382 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
3384 uinfo
->value
.enumerated
.items
= 5;
3385 if (uinfo
->value
.enumerated
.item
>= uinfo
->value
.enumerated
.items
)
3386 uinfo
->value
.enumerated
.item
= uinfo
->value
.enumerated
.items
- 1;
3387 strcpy(uinfo
->value
.enumerated
.name
, texts
[uinfo
->value
.enumerated
.item
]);
3392 static int hdsp_rpm_input34(struct hdsp
*hdsp
)
3394 switch (hdsp
->control_register
& HDSP_RPM_Inp34
) {
3395 case HDSP_RPM_Inp34_Phon_6dB
:
3397 case HDSP_RPM_Inp34_Phon_n6dB
:
3399 case HDSP_RPM_Inp34_Line_0dB
:
3401 case HDSP_RPM_Inp34_Line_n6dB
:
3408 static int snd_hdsp_get_rpm_input34(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
3410 struct hdsp
*hdsp
= snd_kcontrol_chip(kcontrol
);
3412 ucontrol
->value
.enumerated
.item
[0] = hdsp_rpm_input34(hdsp
);
3417 static int hdsp_set_rpm_input34(struct hdsp
*hdsp
, int mode
)
3419 hdsp
->control_register
&= ~HDSP_RPM_Inp34
;
3422 hdsp
->control_register
|= HDSP_RPM_Inp34_Phon_6dB
;
3427 hdsp
->control_register
|= HDSP_RPM_Inp34_Phon_n6dB
;
3430 hdsp
->control_register
|= HDSP_RPM_Inp34_Line_0dB
;
3433 hdsp
->control_register
|= HDSP_RPM_Inp34_Line_n6dB
;
3439 hdsp_write(hdsp
, HDSP_controlRegister
, hdsp
->control_register
);
3444 static int snd_hdsp_put_rpm_input34(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
3446 struct hdsp
*hdsp
= snd_kcontrol_chip(kcontrol
);
3450 if (!snd_hdsp_use_is_exclusive(hdsp
))
3452 val
= ucontrol
->value
.enumerated
.item
[0];
3457 spin_lock_irq(&hdsp
->lock
);
3458 if (val
!= hdsp_rpm_input34(hdsp
))
3459 change
= (hdsp_set_rpm_input34(hdsp
, val
) == 0) ? 1 : 0;
3462 spin_unlock_irq(&hdsp
->lock
);
3467 /* RPM Bypass switch */
3468 static int hdsp_rpm_bypass(struct hdsp
*hdsp
)
3470 return (hdsp
->control_register
& HDSP_RPM_Bypass
) ? 1 : 0;
3474 static int snd_hdsp_get_rpm_bypass(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
3476 struct hdsp
*hdsp
= snd_kcontrol_chip(kcontrol
);
3478 ucontrol
->value
.integer
.value
[0] = hdsp_rpm_bypass(hdsp
);
3483 static int hdsp_set_rpm_bypass(struct hdsp
*hdsp
, int on
)
3486 hdsp
->control_register
|= HDSP_RPM_Bypass
;
3488 hdsp
->control_register
&= ~HDSP_RPM_Bypass
;
3489 hdsp_write(hdsp
, HDSP_controlRegister
, hdsp
->control_register
);
3494 static int snd_hdsp_put_rpm_bypass(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
3496 struct hdsp
*hdsp
= snd_kcontrol_chip(kcontrol
);
3500 if (!snd_hdsp_use_is_exclusive(hdsp
))
3502 val
= ucontrol
->value
.integer
.value
[0] & 1;
3503 spin_lock_irq(&hdsp
->lock
);
3504 change
= (int)val
!= hdsp_rpm_bypass(hdsp
);
3505 hdsp_set_rpm_bypass(hdsp
, val
);
3506 spin_unlock_irq(&hdsp
->lock
);
3511 static int snd_hdsp_info_rpm_bypass(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_info
*uinfo
)
3513 static char *texts
[] = {"On", "Off"};
3515 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
3517 uinfo
->value
.enumerated
.items
= 2;
3518 if (uinfo
->value
.enumerated
.item
>= uinfo
->value
.enumerated
.items
)
3519 uinfo
->value
.enumerated
.item
= uinfo
->value
.enumerated
.items
- 1;
3520 strcpy(uinfo
->value
.enumerated
.name
, texts
[uinfo
->value
.enumerated
.item
]);
3525 /* RPM Disconnect switch */
3526 static int hdsp_rpm_disconnect(struct hdsp
*hdsp
)
3528 return (hdsp
->control_register
& HDSP_RPM_Disconnect
) ? 1 : 0;
3532 static int snd_hdsp_get_rpm_disconnect(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
3534 struct hdsp
*hdsp
= snd_kcontrol_chip(kcontrol
);
3536 ucontrol
->value
.integer
.value
[0] = hdsp_rpm_disconnect(hdsp
);
3541 static int hdsp_set_rpm_disconnect(struct hdsp
*hdsp
, int on
)
3544 hdsp
->control_register
|= HDSP_RPM_Disconnect
;
3546 hdsp
->control_register
&= ~HDSP_RPM_Disconnect
;
3547 hdsp_write(hdsp
, HDSP_controlRegister
, hdsp
->control_register
);
3552 static int snd_hdsp_put_rpm_disconnect(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_value
*ucontrol
)
3554 struct hdsp
*hdsp
= snd_kcontrol_chip(kcontrol
);
3558 if (!snd_hdsp_use_is_exclusive(hdsp
))
3560 val
= ucontrol
->value
.integer
.value
[0] & 1;
3561 spin_lock_irq(&hdsp
->lock
);
3562 change
= (int)val
!= hdsp_rpm_disconnect(hdsp
);
3563 hdsp_set_rpm_disconnect(hdsp
, val
);
3564 spin_unlock_irq(&hdsp
->lock
);
3568 static int snd_hdsp_info_rpm_disconnect(struct snd_kcontrol
*kcontrol
, struct snd_ctl_elem_info
*uinfo
)
3570 static char *texts
[] = {"On", "Off"};
3572 uinfo
->type
= SNDRV_CTL_ELEM_TYPE_ENUMERATED
;
3574 uinfo
->value
.enumerated
.items
= 2;
3575 if (uinfo
->value
.enumerated
.item
>= uinfo
->value
.enumerated
.items
)
3576 uinfo
->value
.enumerated
.item
= uinfo
->value
.enumerated
.items
- 1;
3577 strcpy(uinfo
->value
.enumerated
.name
, texts
[uinfo
->value
.enumerated
.item
]);
3581 static struct snd_kcontrol_new snd_hdsp_rpm_controls
[] = {
3583 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
3584 .name
= "RPM Bypass",
3585 .get
= snd_hdsp_get_rpm_bypass
,
3586 .put
= snd_hdsp_put_rpm_bypass
,
3587 .info
= snd_hdsp_info_rpm_bypass
3590 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
3591 .name
= "RPM Disconnect",
3592 .get
= snd_hdsp_get_rpm_disconnect
,
3593 .put
= snd_hdsp_put_rpm_disconnect
,
3594 .info
= snd_hdsp_info_rpm_disconnect
3597 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
3598 .name
= "Input 1/2",
3599 .get
= snd_hdsp_get_rpm_input12
,
3600 .put
= snd_hdsp_put_rpm_input12
,
3601 .info
= snd_hdsp_info_rpm_input
3604 .iface
= SNDRV_CTL_ELEM_IFACE_MIXER
,
3605 .name
= "Input 3/4",
3606 .get
= snd_hdsp_get_rpm_input34
,
3607 .put
= snd_hdsp_put_rpm_input34
,
3608 .info
= snd_hdsp_info_rpm_input
3610 HDSP_SYSTEM_SAMPLE_RATE("System Sample Rate", 0),
3611 HDSP_MIXER("Mixer", 0)
3614 static struct snd_kcontrol_new snd_hdsp_96xx_aeb
= HDSP_AEB("Analog Extension Board", 0);
3615 static struct snd_kcontrol_new snd_hdsp_adat_sync_check
= HDSP_ADAT_SYNC_CHECK
;
3617 static int snd_hdsp_create_controls(struct snd_card
*card
, struct hdsp
*hdsp
)
3621 struct snd_kcontrol
*kctl
;
3623 if (hdsp
->io_type
== RPM
) {
3624 /* RPM Bypass, Disconnect and Input switches */
3625 for (idx
= 0; idx
< ARRAY_SIZE(snd_hdsp_rpm_controls
); idx
++) {
3626 err
= snd_ctl_add(card
, kctl
= snd_ctl_new1(&snd_hdsp_rpm_controls
[idx
], hdsp
));
3633 for (idx
= 0; idx
< ARRAY_SIZE(snd_hdsp_controls
); idx
++) {
3634 if ((err
= snd_ctl_add(card
, kctl
= snd_ctl_new1(&snd_hdsp_controls
[idx
], hdsp
))) < 0)
3636 if (idx
== 1) /* IEC958 (S/PDIF) Stream */
3637 hdsp
->spdif_ctl
= kctl
;
3640 /* ADAT SyncCheck status */
3641 snd_hdsp_adat_sync_check
.name
= "ADAT Lock Status";
3642 snd_hdsp_adat_sync_check
.index
= 1;
3643 if ((err
= snd_ctl_add (card
, kctl
= snd_ctl_new1(&snd_hdsp_adat_sync_check
, hdsp
))))
3645 if (hdsp
->io_type
== Digiface
|| hdsp
->io_type
== H9652
) {
3646 for (idx
= 1; idx
< 3; ++idx
) {
3647 snd_hdsp_adat_sync_check
.index
= idx
+1;
3648 if ((err
= snd_ctl_add (card
, kctl
= snd_ctl_new1(&snd_hdsp_adat_sync_check
, hdsp
))))
3653 /* DA, AD and Phone gain and XLR breakout cable controls for H9632 cards */
3654 if (hdsp
->io_type
== H9632
) {
3655 for (idx
= 0; idx
< ARRAY_SIZE(snd_hdsp_9632_controls
); idx
++) {
3656 if ((err
= snd_ctl_add(card
, kctl
= snd_ctl_new1(&snd_hdsp_9632_controls
[idx
], hdsp
))) < 0)
3661 /* AEB control for H96xx card */
3662 if (hdsp
->io_type
== H9632
|| hdsp
->io_type
== H9652
) {
3663 if ((err
= snd_ctl_add(card
, kctl
= snd_ctl_new1(&snd_hdsp_96xx_aeb
, hdsp
))) < 0)
3670 /*------------------------------------------------------------
3672 ------------------------------------------------------------*/
3675 snd_hdsp_proc_read(struct snd_info_entry
*entry
, struct snd_info_buffer
*buffer
)
3677 struct hdsp
*hdsp
= entry
->private_data
;
3678 unsigned int status
;
3679 unsigned int status2
;
3680 char *pref_sync_ref
;
3682 char *system_clock_mode
;
3686 status
= hdsp_read(hdsp
, HDSP_statusRegister
);
3687 status2
= hdsp_read(hdsp
, HDSP_status2Register
);
3689 snd_iprintf(buffer
, "%s (Card #%d)\n", hdsp
->card_name
,
3690 hdsp
->card
->number
+ 1);
3691 snd_iprintf(buffer
, "Buffers: capture %p playback %p\n",
3692 hdsp
->capture_buffer
, hdsp
->playback_buffer
);
3693 snd_iprintf(buffer
, "IRQ: %d Registers bus: 0x%lx VM: 0x%lx\n",
3694 hdsp
->irq
, hdsp
->port
, (unsigned long)hdsp
->iobase
);
3695 snd_iprintf(buffer
, "Control register: 0x%x\n", hdsp
->control_register
);
3696 snd_iprintf(buffer
, "Control2 register: 0x%x\n",
3697 hdsp
->control2_register
);
3698 snd_iprintf(buffer
, "Status register: 0x%x\n", status
);
3699 snd_iprintf(buffer
, "Status2 register: 0x%x\n", status2
);
3701 if (hdsp_check_for_iobox(hdsp
)) {
3702 snd_iprintf(buffer
, "No I/O box connected.\n"
3703 "Please connect one and upload firmware.\n");
3707 if (hdsp_check_for_firmware(hdsp
, 0)) {
3708 if (hdsp
->state
& HDSP_FirmwareCached
) {
3709 if (snd_hdsp_load_firmware_from_cache(hdsp
) != 0) {
3710 snd_iprintf(buffer
, "Firmware loading from "
3712 "please upload manually.\n");
3717 err
= hdsp_request_fw_loader(hdsp
);
3720 "No firmware loaded nor cached, "
3721 "please upload firmware.\n");
3727 snd_iprintf(buffer
, "FIFO status: %d\n", hdsp_read(hdsp
, HDSP_fifoStatus
) & 0xff);
3728 snd_iprintf(buffer
, "MIDI1 Output status: 0x%x\n", hdsp_read(hdsp
, HDSP_midiStatusOut0
));
3729 snd_iprintf(buffer
, "MIDI1 Input status: 0x%x\n", hdsp_read(hdsp
, HDSP_midiStatusIn0
));
3730 snd_iprintf(buffer
, "MIDI2 Output status: 0x%x\n", hdsp_read(hdsp
, HDSP_midiStatusOut1
));
3731 snd_iprintf(buffer
, "MIDI2 Input status: 0x%x\n", hdsp_read(hdsp
, HDSP_midiStatusIn1
));
3732 snd_iprintf(buffer
, "Use Midi Tasklet: %s\n", hdsp
->use_midi_tasklet
? "on" : "off");
3734 snd_iprintf(buffer
, "\n");
3736 x
= 1 << (6 + hdsp_decode_latency(hdsp
->control_register
& HDSP_LatencyMask
));
3738 snd_iprintf(buffer
, "Buffer Size (Latency): %d samples (2 periods of %lu bytes)\n", x
, (unsigned long) hdsp
->period_bytes
);
3739 snd_iprintf(buffer
, "Hardware pointer (frames): %ld\n", hdsp_hw_pointer(hdsp
));
3740 snd_iprintf(buffer
, "Precise pointer: %s\n", hdsp
->precise_ptr
? "on" : "off");
3741 snd_iprintf(buffer
, "Line out: %s\n", (hdsp
->control_register
& HDSP_LineOut
) ? "on" : "off");
3743 snd_iprintf(buffer
, "Firmware version: %d\n", (status2
&HDSP_version0
)|(status2
&HDSP_version1
)<<1|(status2
&HDSP_version2
)<<2);
3745 snd_iprintf(buffer
, "\n");
3747 switch (hdsp_clock_source(hdsp
)) {
3748 case HDSP_CLOCK_SOURCE_AUTOSYNC
:
3749 clock_source
= "AutoSync";
3751 case HDSP_CLOCK_SOURCE_INTERNAL_32KHZ
:
3752 clock_source
= "Internal 32 kHz";
3754 case HDSP_CLOCK_SOURCE_INTERNAL_44_1KHZ
:
3755 clock_source
= "Internal 44.1 kHz";
3757 case HDSP_CLOCK_SOURCE_INTERNAL_48KHZ
:
3758 clock_source
= "Internal 48 kHz";
3760 case HDSP_CLOCK_SOURCE_INTERNAL_64KHZ
:
3761 clock_source
= "Internal 64 kHz";
3763 case HDSP_CLOCK_SOURCE_INTERNAL_88_2KHZ
:
3764 clock_source
= "Internal 88.2 kHz";
3766 case HDSP_CLOCK_SOURCE_INTERNAL_96KHZ
:
3767 clock_source
= "Internal 96 kHz";
3769 case HDSP_CLOCK_SOURCE_INTERNAL_128KHZ
:
3770 clock_source
= "Internal 128 kHz";
3772 case HDSP_CLOCK_SOURCE_INTERNAL_176_4KHZ
:
3773 clock_source
= "Internal 176.4 kHz";
3775 case HDSP_CLOCK_SOURCE_INTERNAL_192KHZ
:
3776 clock_source
= "Internal 192 kHz";
3779 clock_source
= "Error";
3781 snd_iprintf (buffer
, "Sample Clock Source: %s\n", clock_source
);
3783 if (hdsp_system_clock_mode(hdsp
))
3784 system_clock_mode
= "Slave";
3786 system_clock_mode
= "Master";
3788 switch (hdsp_pref_sync_ref (hdsp
)) {
3789 case HDSP_SYNC_FROM_WORD
:
3790 pref_sync_ref
= "Word Clock";
3792 case HDSP_SYNC_FROM_ADAT_SYNC
:
3793 pref_sync_ref
= "ADAT Sync";
3795 case HDSP_SYNC_FROM_SPDIF
:
3796 pref_sync_ref
= "SPDIF";
3798 case HDSP_SYNC_FROM_ADAT1
:
3799 pref_sync_ref
= "ADAT1";
3801 case HDSP_SYNC_FROM_ADAT2
:
3802 pref_sync_ref
= "ADAT2";
3804 case HDSP_SYNC_FROM_ADAT3
:
3805 pref_sync_ref
= "ADAT3";
3808 pref_sync_ref
= "Word Clock";
3811 snd_iprintf (buffer
, "Preferred Sync Reference: %s\n", pref_sync_ref
);
3813 switch (hdsp_autosync_ref (hdsp
)) {
3814 case HDSP_AUTOSYNC_FROM_WORD
:
3815 autosync_ref
= "Word Clock";
3817 case HDSP_AUTOSYNC_FROM_ADAT_SYNC
:
3818 autosync_ref
= "ADAT Sync";
3820 case HDSP_AUTOSYNC_FROM_SPDIF
:
3821 autosync_ref
= "SPDIF";
3823 case HDSP_AUTOSYNC_FROM_NONE
:
3824 autosync_ref
= "None";
3826 case HDSP_AUTOSYNC_FROM_ADAT1
:
3827 autosync_ref
= "ADAT1";
3829 case HDSP_AUTOSYNC_FROM_ADAT2
:
3830 autosync_ref
= "ADAT2";
3832 case HDSP_AUTOSYNC_FROM_ADAT3
:
3833 autosync_ref
= "ADAT3";
3836 autosync_ref
= "---";
3839 snd_iprintf (buffer
, "AutoSync Reference: %s\n", autosync_ref
);
3841 snd_iprintf (buffer
, "AutoSync Frequency: %d\n", hdsp_external_sample_rate(hdsp
));
3843 snd_iprintf (buffer
, "System Clock Mode: %s\n", system_clock_mode
);
3845 snd_iprintf (buffer
, "System Clock Frequency: %d\n", hdsp
->system_sample_rate
);
3846 snd_iprintf (buffer
, "System Clock Locked: %s\n", hdsp
->clock_source_locked
? "Yes" : "No");
3848 snd_iprintf(buffer
, "\n");
3850 if (hdsp
->io_type
!= RPM
) {
3851 switch (hdsp_spdif_in(hdsp
)) {
3852 case HDSP_SPDIFIN_OPTICAL
:
3853 snd_iprintf(buffer
, "IEC958 input: Optical\n");
3855 case HDSP_SPDIFIN_COAXIAL
:
3856 snd_iprintf(buffer
, "IEC958 input: Coaxial\n");
3858 case HDSP_SPDIFIN_INTERNAL
:
3859 snd_iprintf(buffer
, "IEC958 input: Internal\n");
3861 case HDSP_SPDIFIN_AES
:
3862 snd_iprintf(buffer
, "IEC958 input: AES\n");
3865 snd_iprintf(buffer
, "IEC958 input: ???\n");
3870 if (RPM
== hdsp
->io_type
) {
3871 if (hdsp
->control_register
& HDSP_RPM_Bypass
)
3872 snd_iprintf(buffer
, "RPM Bypass: disabled\n");
3874 snd_iprintf(buffer
, "RPM Bypass: enabled\n");
3875 if (hdsp
->control_register
& HDSP_RPM_Disconnect
)
3876 snd_iprintf(buffer
, "RPM disconnected\n");
3878 snd_iprintf(buffer
, "RPM connected\n");
3880 switch (hdsp
->control_register
& HDSP_RPM_Inp12
) {
3881 case HDSP_RPM_Inp12_Phon_6dB
:
3882 snd_iprintf(buffer
, "Input 1/2: Phono, 6dB\n");
3884 case HDSP_RPM_Inp12_Phon_0dB
:
3885 snd_iprintf(buffer
, "Input 1/2: Phono, 0dB\n");
3887 case HDSP_RPM_Inp12_Phon_n6dB
:
3888 snd_iprintf(buffer
, "Input 1/2: Phono, -6dB\n");
3890 case HDSP_RPM_Inp12_Line_0dB
:
3891 snd_iprintf(buffer
, "Input 1/2: Line, 0dB\n");
3893 case HDSP_RPM_Inp12_Line_n6dB
:
3894 snd_iprintf(buffer
, "Input 1/2: Line, -6dB\n");
3897 snd_iprintf(buffer
, "Input 1/2: ???\n");
3900 switch (hdsp
->control_register
& HDSP_RPM_Inp34
) {
3901 case HDSP_RPM_Inp34_Phon_6dB
:
3902 snd_iprintf(buffer
, "Input 3/4: Phono, 6dB\n");
3904 case HDSP_RPM_Inp34_Phon_0dB
:
3905 snd_iprintf(buffer
, "Input 3/4: Phono, 0dB\n");
3907 case HDSP_RPM_Inp34_Phon_n6dB
:
3908 snd_iprintf(buffer
, "Input 3/4: Phono, -6dB\n");
3910 case HDSP_RPM_Inp34_Line_0dB
:
3911 snd_iprintf(buffer
, "Input 3/4: Line, 0dB\n");
3913 case HDSP_RPM_Inp34_Line_n6dB
:
3914 snd_iprintf(buffer
, "Input 3/4: Line, -6dB\n");
3917 snd_iprintf(buffer
, "Input 3/4: ???\n");
3921 if (hdsp
->control_register
& HDSP_SPDIFOpticalOut
)
3922 snd_iprintf(buffer
, "IEC958 output: Coaxial & ADAT1\n");
3924 snd_iprintf(buffer
, "IEC958 output: Coaxial only\n");
3926 if (hdsp
->control_register
& HDSP_SPDIFProfessional
)
3927 snd_iprintf(buffer
, "IEC958 quality: Professional\n");
3929 snd_iprintf(buffer
, "IEC958 quality: Consumer\n");
3931 if (hdsp
->control_register
& HDSP_SPDIFEmphasis
)
3932 snd_iprintf(buffer
, "IEC958 emphasis: on\n");
3934 snd_iprintf(buffer
, "IEC958 emphasis: off\n");
3936 if (hdsp
->control_register
& HDSP_SPDIFNonAudio
)
3937 snd_iprintf(buffer
, "IEC958 NonAudio: on\n");
3939 snd_iprintf(buffer
, "IEC958 NonAudio: off\n");
3940 x
= hdsp_spdif_sample_rate(hdsp
);
3942 snd_iprintf(buffer
, "IEC958 sample rate: %d\n", x
);
3944 snd_iprintf(buffer
, "IEC958 sample rate: Error flag set\n");
3946 snd_iprintf(buffer
, "\n");
3949 x
= status
& HDSP_Sync0
;
3950 if (status
& HDSP_Lock0
)
3951 snd_iprintf(buffer
, "ADAT1: %s\n", x
? "Sync" : "Lock");
3953 snd_iprintf(buffer
, "ADAT1: No Lock\n");
3955 switch (hdsp
->io_type
) {
3958 x
= status
& HDSP_Sync1
;
3959 if (status
& HDSP_Lock1
)
3960 snd_iprintf(buffer
, "ADAT2: %s\n", x
? "Sync" : "Lock");
3962 snd_iprintf(buffer
, "ADAT2: No Lock\n");
3963 x
= status
& HDSP_Sync2
;
3964 if (status
& HDSP_Lock2
)
3965 snd_iprintf(buffer
, "ADAT3: %s\n", x
? "Sync" : "Lock");
3967 snd_iprintf(buffer
, "ADAT3: No Lock\n");
3974 x
= status
& HDSP_SPDIFSync
;
3975 if (status
& HDSP_SPDIFErrorFlag
)
3976 snd_iprintf (buffer
, "SPDIF: No Lock\n");
3978 snd_iprintf (buffer
, "SPDIF: %s\n", x
? "Sync" : "Lock");
3980 x
= status2
& HDSP_wc_sync
;
3981 if (status2
& HDSP_wc_lock
)
3982 snd_iprintf (buffer
, "Word Clock: %s\n", x
? "Sync" : "Lock");
3984 snd_iprintf (buffer
, "Word Clock: No Lock\n");
3986 x
= status
& HDSP_TimecodeSync
;
3987 if (status
& HDSP_TimecodeLock
)
3988 snd_iprintf(buffer
, "ADAT Sync: %s\n", x
? "Sync" : "Lock");
3990 snd_iprintf(buffer
, "ADAT Sync: No Lock\n");
3992 snd_iprintf(buffer
, "\n");
3994 /* Informations about H9632 specific controls */
3995 if (hdsp
->io_type
== H9632
) {
3998 switch (hdsp_ad_gain(hdsp
)) {
4009 snd_iprintf(buffer
, "AD Gain : %s\n", tmp
);
4011 switch (hdsp_da_gain(hdsp
)) {
4022 snd_iprintf(buffer
, "DA Gain : %s\n", tmp
);
4024 switch (hdsp_phone_gain(hdsp
)) {
4035 snd_iprintf(buffer
, "Phones Gain : %s\n", tmp
);
4037 snd_iprintf(buffer
, "XLR Breakout Cable : %s\n", hdsp_xlr_breakout_cable(hdsp
) ? "yes" : "no");
4039 if (hdsp
->control_register
& HDSP_AnalogExtensionBoard
)
4040 snd_iprintf(buffer
, "AEB : on (ADAT1 internal)\n");
4042 snd_iprintf(buffer
, "AEB : off (ADAT1 external)\n");
4043 snd_iprintf(buffer
, "\n");
4048 static void snd_hdsp_proc_init(struct hdsp
*hdsp
)
4050 struct snd_info_entry
*entry
;
4052 if (! snd_card_proc_new(hdsp
->card
, "hdsp", &entry
))
4053 snd_info_set_text_ops(entry
, hdsp
, snd_hdsp_proc_read
);
4056 static void snd_hdsp_free_buffers(struct hdsp
*hdsp
)
4058 snd_hammerfall_free_buffer(&hdsp
->capture_dma_buf
, hdsp
->pci
);
4059 snd_hammerfall_free_buffer(&hdsp
->playback_dma_buf
, hdsp
->pci
);
4062 static int snd_hdsp_initialize_memory(struct hdsp
*hdsp
)
4064 unsigned long pb_bus
, cb_bus
;
4066 if (snd_hammerfall_get_buffer(hdsp
->pci
, &hdsp
->capture_dma_buf
, HDSP_DMA_AREA_BYTES
) < 0 ||
4067 snd_hammerfall_get_buffer(hdsp
->pci
, &hdsp
->playback_dma_buf
, HDSP_DMA_AREA_BYTES
) < 0) {
4068 if (hdsp
->capture_dma_buf
.area
)
4069 snd_dma_free_pages(&hdsp
->capture_dma_buf
);
4070 printk(KERN_ERR
"%s: no buffers available\n", hdsp
->card_name
);
4074 /* Align to bus-space 64K boundary */
4076 cb_bus
= ALIGN(hdsp
->capture_dma_buf
.addr
, 0x10000ul
);
4077 pb_bus
= ALIGN(hdsp
->playback_dma_buf
.addr
, 0x10000ul
);
4079 /* Tell the card where it is */
4081 hdsp_write(hdsp
, HDSP_inputBufferAddress
, cb_bus
);
4082 hdsp_write(hdsp
, HDSP_outputBufferAddress
, pb_bus
);
4084 hdsp
->capture_buffer
= hdsp
->capture_dma_buf
.area
+ (cb_bus
- hdsp
->capture_dma_buf
.addr
);
4085 hdsp
->playback_buffer
= hdsp
->playback_dma_buf
.area
+ (pb_bus
- hdsp
->playback_dma_buf
.addr
);
4090 static int snd_hdsp_set_defaults(struct hdsp
*hdsp
)
4094 /* ASSUMPTION: hdsp->lock is either held, or
4095 there is no need to hold it (e.g. during module
4101 SPDIF Input via Coax
4103 maximum latency (7 => 2^7 = 8192 samples, 64Kbyte buffer,
4104 which implies 2 4096 sample, 32Kbyte periods).
4108 hdsp
->control_register
= HDSP_ClockModeMaster
|
4109 HDSP_SPDIFInputCoaxial
|
4110 hdsp_encode_latency(7) |
4114 hdsp_write(hdsp
, HDSP_controlRegister
, hdsp
->control_register
);
4116 #ifdef SNDRV_BIG_ENDIAN
4117 hdsp
->control2_register
= HDSP_BIGENDIAN_MODE
;
4119 hdsp
->control2_register
= 0;
4121 if (hdsp
->io_type
== H9652
)
4122 snd_hdsp_9652_enable_mixer (hdsp
);
4124 hdsp_write (hdsp
, HDSP_control2Reg
, hdsp
->control2_register
);
4126 hdsp_reset_hw_pointer(hdsp
);
4127 hdsp_compute_period_size(hdsp
);
4129 /* silence everything */
4131 for (i
= 0; i
< HDSP_MATRIX_MIXER_SIZE
; ++i
)
4132 hdsp
->mixer_matrix
[i
] = MINUS_INFINITY_GAIN
;
4134 for (i
= 0; i
< ((hdsp
->io_type
== H9652
|| hdsp
->io_type
== H9632
) ? 1352 : HDSP_MATRIX_MIXER_SIZE
); ++i
) {
4135 if (hdsp_write_gain (hdsp
, i
, MINUS_INFINITY_GAIN
))
4139 /* H9632 specific defaults */
4140 if (hdsp
->io_type
== H9632
) {
4141 hdsp
->control_register
|= (HDSP_DAGainPlus4dBu
| HDSP_ADGainPlus4dBu
| HDSP_PhoneGain0dB
);
4142 hdsp_write(hdsp
, HDSP_controlRegister
, hdsp
->control_register
);
4145 /* set a default rate so that the channel map is set up.
4148 hdsp_set_rate(hdsp
, 48000, 1);
4153 static void hdsp_midi_tasklet(unsigned long arg
)
4155 struct hdsp
*hdsp
= (struct hdsp
*)arg
;
4157 if (hdsp
->midi
[0].pending
)
4158 snd_hdsp_midi_input_read (&hdsp
->midi
[0]);
4159 if (hdsp
->midi
[1].pending
)
4160 snd_hdsp_midi_input_read (&hdsp
->midi
[1]);
4163 static irqreturn_t
snd_hdsp_interrupt(int irq
, void *dev_id
)
4165 struct hdsp
*hdsp
= (struct hdsp
*) dev_id
;
4166 unsigned int status
;
4170 unsigned int midi0status
;
4171 unsigned int midi1status
;
4174 status
= hdsp_read(hdsp
, HDSP_statusRegister
);
4176 audio
= status
& HDSP_audioIRQPending
;
4177 midi0
= status
& HDSP_midi0IRQPending
;
4178 midi1
= status
& HDSP_midi1IRQPending
;
4180 if (!audio
&& !midi0
&& !midi1
)
4183 hdsp_write(hdsp
, HDSP_interruptConfirmation
, 0);
4185 midi0status
= hdsp_read (hdsp
, HDSP_midiStatusIn0
) & 0xff;
4186 midi1status
= hdsp_read (hdsp
, HDSP_midiStatusIn1
) & 0xff;
4188 if (!(hdsp
->state
& HDSP_InitializationComplete
))
4192 if (hdsp
->capture_substream
)
4193 snd_pcm_period_elapsed(hdsp
->pcm
->streams
[SNDRV_PCM_STREAM_CAPTURE
].substream
);
4195 if (hdsp
->playback_substream
)
4196 snd_pcm_period_elapsed(hdsp
->pcm
->streams
[SNDRV_PCM_STREAM_PLAYBACK
].substream
);
4199 if (midi0
&& midi0status
) {
4200 if (hdsp
->use_midi_tasklet
) {
4201 /* we disable interrupts for this input until processing is done */
4202 hdsp
->control_register
&= ~HDSP_Midi0InterruptEnable
;
4203 hdsp_write(hdsp
, HDSP_controlRegister
, hdsp
->control_register
);
4204 hdsp
->midi
[0].pending
= 1;
4207 snd_hdsp_midi_input_read (&hdsp
->midi
[0]);
4210 if (hdsp
->io_type
!= Multiface
&& hdsp
->io_type
!= RPM
&& hdsp
->io_type
!= H9632
&& midi1
&& midi1status
) {
4211 if (hdsp
->use_midi_tasklet
) {
4212 /* we disable interrupts for this input until processing is done */
4213 hdsp
->control_register
&= ~HDSP_Midi1InterruptEnable
;
4214 hdsp_write(hdsp
, HDSP_controlRegister
, hdsp
->control_register
);
4215 hdsp
->midi
[1].pending
= 1;
4218 snd_hdsp_midi_input_read (&hdsp
->midi
[1]);
4221 if (hdsp
->use_midi_tasklet
&& schedule
)
4222 tasklet_schedule(&hdsp
->midi_tasklet
);
4226 static snd_pcm_uframes_t
snd_hdsp_hw_pointer(struct snd_pcm_substream
*substream
)
4228 struct hdsp
*hdsp
= snd_pcm_substream_chip(substream
);
4229 return hdsp_hw_pointer(hdsp
);
4232 static char *hdsp_channel_buffer_location(struct hdsp
*hdsp
,
4239 if (snd_BUG_ON(channel
< 0 || channel
>= hdsp
->max_channels
))
4242 if ((mapped_channel
= hdsp
->channel_map
[channel
]) < 0)
4245 if (stream
== SNDRV_PCM_STREAM_CAPTURE
)
4246 return hdsp
->capture_buffer
+ (mapped_channel
* HDSP_CHANNEL_BUFFER_BYTES
);
4248 return hdsp
->playback_buffer
+ (mapped_channel
* HDSP_CHANNEL_BUFFER_BYTES
);
4251 static int snd_hdsp_playback_copy(struct snd_pcm_substream
*substream
, int channel
,
4252 snd_pcm_uframes_t pos
, void __user
*src
, snd_pcm_uframes_t count
)
4254 struct hdsp
*hdsp
= snd_pcm_substream_chip(substream
);
4257 if (snd_BUG_ON(pos
+ count
> HDSP_CHANNEL_BUFFER_BYTES
/ 4))
4260 channel_buf
= hdsp_channel_buffer_location (hdsp
, substream
->pstr
->stream
, channel
);
4261 if (snd_BUG_ON(!channel_buf
))
4263 if (copy_from_user(channel_buf
+ pos
* 4, src
, count
* 4))
4268 static int snd_hdsp_capture_copy(struct snd_pcm_substream
*substream
, int channel
,
4269 snd_pcm_uframes_t pos
, void __user
*dst
, snd_pcm_uframes_t count
)
4271 struct hdsp
*hdsp
= snd_pcm_substream_chip(substream
);
4274 if (snd_BUG_ON(pos
+ count
> HDSP_CHANNEL_BUFFER_BYTES
/ 4))
4277 channel_buf
= hdsp_channel_buffer_location (hdsp
, substream
->pstr
->stream
, channel
);
4278 if (snd_BUG_ON(!channel_buf
))
4280 if (copy_to_user(dst
, channel_buf
+ pos
* 4, count
* 4))
4285 static int snd_hdsp_hw_silence(struct snd_pcm_substream
*substream
, int channel
,
4286 snd_pcm_uframes_t pos
, snd_pcm_uframes_t count
)
4288 struct hdsp
*hdsp
= snd_pcm_substream_chip(substream
);
4291 channel_buf
= hdsp_channel_buffer_location (hdsp
, substream
->pstr
->stream
, channel
);
4292 if (snd_BUG_ON(!channel_buf
))
4294 memset(channel_buf
+ pos
* 4, 0, count
* 4);
4298 static int snd_hdsp_reset(struct snd_pcm_substream
*substream
)
4300 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
4301 struct hdsp
*hdsp
= snd_pcm_substream_chip(substream
);
4302 struct snd_pcm_substream
*other
;
4303 if (substream
->stream
== SNDRV_PCM_STREAM_PLAYBACK
)
4304 other
= hdsp
->capture_substream
;
4306 other
= hdsp
->playback_substream
;
4308 runtime
->status
->hw_ptr
= hdsp_hw_pointer(hdsp
);
4310 runtime
->status
->hw_ptr
= 0;
4312 struct snd_pcm_substream
*s
;
4313 struct snd_pcm_runtime
*oruntime
= other
->runtime
;
4314 snd_pcm_group_for_each_entry(s
, substream
) {
4316 oruntime
->status
->hw_ptr
= runtime
->status
->hw_ptr
;
4324 static int snd_hdsp_hw_params(struct snd_pcm_substream
*substream
,
4325 struct snd_pcm_hw_params
*params
)
4327 struct hdsp
*hdsp
= snd_pcm_substream_chip(substream
);
4332 if (hdsp_check_for_iobox (hdsp
))
4335 if (hdsp_check_for_firmware(hdsp
, 1))
4338 spin_lock_irq(&hdsp
->lock
);
4340 if (substream
->pstr
->stream
== SNDRV_PCM_STREAM_PLAYBACK
) {
4341 hdsp
->control_register
&= ~(HDSP_SPDIFProfessional
| HDSP_SPDIFNonAudio
| HDSP_SPDIFEmphasis
);
4342 hdsp_write(hdsp
, HDSP_controlRegister
, hdsp
->control_register
|= hdsp
->creg_spdif_stream
);
4343 this_pid
= hdsp
->playback_pid
;
4344 other_pid
= hdsp
->capture_pid
;
4346 this_pid
= hdsp
->capture_pid
;
4347 other_pid
= hdsp
->playback_pid
;
4350 if ((other_pid
> 0) && (this_pid
!= other_pid
)) {
4352 /* The other stream is open, and not by the same
4353 task as this one. Make sure that the parameters
4354 that matter are the same.
4357 if (params_rate(params
) != hdsp
->system_sample_rate
) {
4358 spin_unlock_irq(&hdsp
->lock
);
4359 _snd_pcm_hw_param_setempty(params
, SNDRV_PCM_HW_PARAM_RATE
);
4363 if (params_period_size(params
) != hdsp
->period_bytes
/ 4) {
4364 spin_unlock_irq(&hdsp
->lock
);
4365 _snd_pcm_hw_param_setempty(params
, SNDRV_PCM_HW_PARAM_PERIOD_SIZE
);
4371 spin_unlock_irq(&hdsp
->lock
);
4375 spin_unlock_irq(&hdsp
->lock
);
4378 /* how to make sure that the rate matches an externally-set one ?
4381 spin_lock_irq(&hdsp
->lock
);
4382 if (! hdsp
->clock_source_locked
) {
4383 if ((err
= hdsp_set_rate(hdsp
, params_rate(params
), 0)) < 0) {
4384 spin_unlock_irq(&hdsp
->lock
);
4385 _snd_pcm_hw_param_setempty(params
, SNDRV_PCM_HW_PARAM_RATE
);
4389 spin_unlock_irq(&hdsp
->lock
);
4391 if ((err
= hdsp_set_interrupt_interval(hdsp
, params_period_size(params
))) < 0) {
4392 _snd_pcm_hw_param_setempty(params
, SNDRV_PCM_HW_PARAM_PERIOD_SIZE
);
4399 static int snd_hdsp_channel_info(struct snd_pcm_substream
*substream
,
4400 struct snd_pcm_channel_info
*info
)
4402 struct hdsp
*hdsp
= snd_pcm_substream_chip(substream
);
4405 if (snd_BUG_ON(info
->channel
>= hdsp
->max_channels
))
4408 if ((mapped_channel
= hdsp
->channel_map
[info
->channel
]) < 0)
4411 info
->offset
= mapped_channel
* HDSP_CHANNEL_BUFFER_BYTES
;
4417 static int snd_hdsp_ioctl(struct snd_pcm_substream
*substream
,
4418 unsigned int cmd
, void *arg
)
4421 case SNDRV_PCM_IOCTL1_RESET
:
4422 return snd_hdsp_reset(substream
);
4423 case SNDRV_PCM_IOCTL1_CHANNEL_INFO
:
4424 return snd_hdsp_channel_info(substream
, arg
);
4429 return snd_pcm_lib_ioctl(substream
, cmd
, arg
);
4432 static int snd_hdsp_trigger(struct snd_pcm_substream
*substream
, int cmd
)
4434 struct hdsp
*hdsp
= snd_pcm_substream_chip(substream
);
4435 struct snd_pcm_substream
*other
;
4438 if (hdsp_check_for_iobox (hdsp
))
4441 if (hdsp_check_for_firmware(hdsp
, 0)) /* no auto-loading in trigger */
4444 spin_lock(&hdsp
->lock
);
4445 running
= hdsp
->running
;
4447 case SNDRV_PCM_TRIGGER_START
:
4448 running
|= 1 << substream
->stream
;
4450 case SNDRV_PCM_TRIGGER_STOP
:
4451 running
&= ~(1 << substream
->stream
);
4455 spin_unlock(&hdsp
->lock
);
4458 if (substream
->stream
== SNDRV_PCM_STREAM_PLAYBACK
)
4459 other
= hdsp
->capture_substream
;
4461 other
= hdsp
->playback_substream
;
4464 struct snd_pcm_substream
*s
;
4465 snd_pcm_group_for_each_entry(s
, substream
) {
4467 snd_pcm_trigger_done(s
, substream
);
4468 if (cmd
== SNDRV_PCM_TRIGGER_START
)
4469 running
|= 1 << s
->stream
;
4471 running
&= ~(1 << s
->stream
);
4475 if (cmd
== SNDRV_PCM_TRIGGER_START
) {
4476 if (!(running
& (1 << SNDRV_PCM_STREAM_PLAYBACK
)) &&
4477 substream
->stream
== SNDRV_PCM_STREAM_CAPTURE
)
4478 hdsp_silence_playback(hdsp
);
4481 substream
->stream
== SNDRV_PCM_STREAM_PLAYBACK
)
4482 hdsp_silence_playback(hdsp
);
4485 if (substream
->stream
== SNDRV_PCM_STREAM_CAPTURE
)
4486 hdsp_silence_playback(hdsp
);
4489 snd_pcm_trigger_done(substream
, substream
);
4490 if (!hdsp
->running
&& running
)
4491 hdsp_start_audio(hdsp
);
4492 else if (hdsp
->running
&& !running
)
4493 hdsp_stop_audio(hdsp
);
4494 hdsp
->running
= running
;
4495 spin_unlock(&hdsp
->lock
);
4500 static int snd_hdsp_prepare(struct snd_pcm_substream
*substream
)
4502 struct hdsp
*hdsp
= snd_pcm_substream_chip(substream
);
4505 if (hdsp_check_for_iobox (hdsp
))
4508 if (hdsp_check_for_firmware(hdsp
, 1))
4511 spin_lock_irq(&hdsp
->lock
);
4513 hdsp_reset_hw_pointer(hdsp
);
4514 spin_unlock_irq(&hdsp
->lock
);
4518 static struct snd_pcm_hardware snd_hdsp_playback_subinfo
=
4520 .info
= (SNDRV_PCM_INFO_MMAP
|
4521 SNDRV_PCM_INFO_MMAP_VALID
|
4522 SNDRV_PCM_INFO_NONINTERLEAVED
|
4523 SNDRV_PCM_INFO_SYNC_START
|
4524 SNDRV_PCM_INFO_DOUBLE
),
4525 #ifdef SNDRV_BIG_ENDIAN
4526 .formats
= SNDRV_PCM_FMTBIT_S32_BE
,
4528 .formats
= SNDRV_PCM_FMTBIT_S32_LE
,
4530 .rates
= (SNDRV_PCM_RATE_32000
|
4531 SNDRV_PCM_RATE_44100
|
4532 SNDRV_PCM_RATE_48000
|
4533 SNDRV_PCM_RATE_64000
|
4534 SNDRV_PCM_RATE_88200
|
4535 SNDRV_PCM_RATE_96000
),
4539 .channels_max
= HDSP_MAX_CHANNELS
,
4540 .buffer_bytes_max
= HDSP_CHANNEL_BUFFER_BYTES
* HDSP_MAX_CHANNELS
,
4541 .period_bytes_min
= (64 * 4) * 10,
4542 .period_bytes_max
= (8192 * 4) * HDSP_MAX_CHANNELS
,
4548 static struct snd_pcm_hardware snd_hdsp_capture_subinfo
=
4550 .info
= (SNDRV_PCM_INFO_MMAP
|
4551 SNDRV_PCM_INFO_MMAP_VALID
|
4552 SNDRV_PCM_INFO_NONINTERLEAVED
|
4553 SNDRV_PCM_INFO_SYNC_START
),
4554 #ifdef SNDRV_BIG_ENDIAN
4555 .formats
= SNDRV_PCM_FMTBIT_S32_BE
,
4557 .formats
= SNDRV_PCM_FMTBIT_S32_LE
,
4559 .rates
= (SNDRV_PCM_RATE_32000
|
4560 SNDRV_PCM_RATE_44100
|
4561 SNDRV_PCM_RATE_48000
|
4562 SNDRV_PCM_RATE_64000
|
4563 SNDRV_PCM_RATE_88200
|
4564 SNDRV_PCM_RATE_96000
),
4568 .channels_max
= HDSP_MAX_CHANNELS
,
4569 .buffer_bytes_max
= HDSP_CHANNEL_BUFFER_BYTES
* HDSP_MAX_CHANNELS
,
4570 .period_bytes_min
= (64 * 4) * 10,
4571 .period_bytes_max
= (8192 * 4) * HDSP_MAX_CHANNELS
,
4577 static unsigned int hdsp_period_sizes
[] = { 64, 128, 256, 512, 1024, 2048, 4096, 8192 };
4579 static struct snd_pcm_hw_constraint_list hdsp_hw_constraints_period_sizes
= {
4580 .count
= ARRAY_SIZE(hdsp_period_sizes
),
4581 .list
= hdsp_period_sizes
,
4585 static unsigned int hdsp_9632_sample_rates
[] = { 32000, 44100, 48000, 64000, 88200, 96000, 128000, 176400, 192000 };
4587 static struct snd_pcm_hw_constraint_list hdsp_hw_constraints_9632_sample_rates
= {
4588 .count
= ARRAY_SIZE(hdsp_9632_sample_rates
),
4589 .list
= hdsp_9632_sample_rates
,
4593 static int snd_hdsp_hw_rule_in_channels(struct snd_pcm_hw_params
*params
,
4594 struct snd_pcm_hw_rule
*rule
)
4596 struct hdsp
*hdsp
= rule
->private;
4597 struct snd_interval
*c
= hw_param_interval(params
, SNDRV_PCM_HW_PARAM_CHANNELS
);
4598 if (hdsp
->io_type
== H9632
) {
4599 unsigned int list
[3];
4600 list
[0] = hdsp
->qs_in_channels
;
4601 list
[1] = hdsp
->ds_in_channels
;
4602 list
[2] = hdsp
->ss_in_channels
;
4603 return snd_interval_list(c
, 3, list
, 0);
4605 unsigned int list
[2];
4606 list
[0] = hdsp
->ds_in_channels
;
4607 list
[1] = hdsp
->ss_in_channels
;
4608 return snd_interval_list(c
, 2, list
, 0);
4612 static int snd_hdsp_hw_rule_out_channels(struct snd_pcm_hw_params
*params
,
4613 struct snd_pcm_hw_rule
*rule
)
4615 unsigned int list
[3];
4616 struct hdsp
*hdsp
= rule
->private;
4617 struct snd_interval
*c
= hw_param_interval(params
, SNDRV_PCM_HW_PARAM_CHANNELS
);
4618 if (hdsp
->io_type
== H9632
) {
4619 list
[0] = hdsp
->qs_out_channels
;
4620 list
[1] = hdsp
->ds_out_channels
;
4621 list
[2] = hdsp
->ss_out_channels
;
4622 return snd_interval_list(c
, 3, list
, 0);
4624 list
[0] = hdsp
->ds_out_channels
;
4625 list
[1] = hdsp
->ss_out_channels
;
4627 return snd_interval_list(c
, 2, list
, 0);
4630 static int snd_hdsp_hw_rule_in_channels_rate(struct snd_pcm_hw_params
*params
,
4631 struct snd_pcm_hw_rule
*rule
)
4633 struct hdsp
*hdsp
= rule
->private;
4634 struct snd_interval
*c
= hw_param_interval(params
, SNDRV_PCM_HW_PARAM_CHANNELS
);
4635 struct snd_interval
*r
= hw_param_interval(params
, SNDRV_PCM_HW_PARAM_RATE
);
4636 if (r
->min
> 96000 && hdsp
->io_type
== H9632
) {
4637 struct snd_interval t
= {
4638 .min
= hdsp
->qs_in_channels
,
4639 .max
= hdsp
->qs_in_channels
,
4642 return snd_interval_refine(c
, &t
);
4643 } else if (r
->min
> 48000 && r
->max
<= 96000) {
4644 struct snd_interval t
= {
4645 .min
= hdsp
->ds_in_channels
,
4646 .max
= hdsp
->ds_in_channels
,
4649 return snd_interval_refine(c
, &t
);
4650 } else if (r
->max
< 64000) {
4651 struct snd_interval t
= {
4652 .min
= hdsp
->ss_in_channels
,
4653 .max
= hdsp
->ss_in_channels
,
4656 return snd_interval_refine(c
, &t
);
4661 static int snd_hdsp_hw_rule_out_channels_rate(struct snd_pcm_hw_params
*params
,
4662 struct snd_pcm_hw_rule
*rule
)
4664 struct hdsp
*hdsp
= rule
->private;
4665 struct snd_interval
*c
= hw_param_interval(params
, SNDRV_PCM_HW_PARAM_CHANNELS
);
4666 struct snd_interval
*r
= hw_param_interval(params
, SNDRV_PCM_HW_PARAM_RATE
);
4667 if (r
->min
> 96000 && hdsp
->io_type
== H9632
) {
4668 struct snd_interval t
= {
4669 .min
= hdsp
->qs_out_channels
,
4670 .max
= hdsp
->qs_out_channels
,
4673 return snd_interval_refine(c
, &t
);
4674 } else if (r
->min
> 48000 && r
->max
<= 96000) {
4675 struct snd_interval t
= {
4676 .min
= hdsp
->ds_out_channels
,
4677 .max
= hdsp
->ds_out_channels
,
4680 return snd_interval_refine(c
, &t
);
4681 } else if (r
->max
< 64000) {
4682 struct snd_interval t
= {
4683 .min
= hdsp
->ss_out_channels
,
4684 .max
= hdsp
->ss_out_channels
,
4687 return snd_interval_refine(c
, &t
);
4692 static int snd_hdsp_hw_rule_rate_out_channels(struct snd_pcm_hw_params
*params
,
4693 struct snd_pcm_hw_rule
*rule
)
4695 struct hdsp
*hdsp
= rule
->private;
4696 struct snd_interval
*c
= hw_param_interval(params
, SNDRV_PCM_HW_PARAM_CHANNELS
);
4697 struct snd_interval
*r
= hw_param_interval(params
, SNDRV_PCM_HW_PARAM_RATE
);
4698 if (c
->min
>= hdsp
->ss_out_channels
) {
4699 struct snd_interval t
= {
4704 return snd_interval_refine(r
, &t
);
4705 } else if (c
->max
<= hdsp
->qs_out_channels
&& hdsp
->io_type
== H9632
) {
4706 struct snd_interval t
= {
4711 return snd_interval_refine(r
, &t
);
4712 } else if (c
->max
<= hdsp
->ds_out_channels
) {
4713 struct snd_interval t
= {
4718 return snd_interval_refine(r
, &t
);
4723 static int snd_hdsp_hw_rule_rate_in_channels(struct snd_pcm_hw_params
*params
,
4724 struct snd_pcm_hw_rule
*rule
)
4726 struct hdsp
*hdsp
= rule
->private;
4727 struct snd_interval
*c
= hw_param_interval(params
, SNDRV_PCM_HW_PARAM_CHANNELS
);
4728 struct snd_interval
*r
= hw_param_interval(params
, SNDRV_PCM_HW_PARAM_RATE
);
4729 if (c
->min
>= hdsp
->ss_in_channels
) {
4730 struct snd_interval t
= {
4735 return snd_interval_refine(r
, &t
);
4736 } else if (c
->max
<= hdsp
->qs_in_channels
&& hdsp
->io_type
== H9632
) {
4737 struct snd_interval t
= {
4742 return snd_interval_refine(r
, &t
);
4743 } else if (c
->max
<= hdsp
->ds_in_channels
) {
4744 struct snd_interval t
= {
4749 return snd_interval_refine(r
, &t
);
4754 static int snd_hdsp_playback_open(struct snd_pcm_substream
*substream
)
4756 struct hdsp
*hdsp
= snd_pcm_substream_chip(substream
);
4757 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
4759 if (hdsp_check_for_iobox (hdsp
))
4762 if (hdsp_check_for_firmware(hdsp
, 1))
4765 spin_lock_irq(&hdsp
->lock
);
4767 snd_pcm_set_sync(substream
);
4769 runtime
->hw
= snd_hdsp_playback_subinfo
;
4770 runtime
->dma_area
= hdsp
->playback_buffer
;
4771 runtime
->dma_bytes
= HDSP_DMA_AREA_BYTES
;
4773 hdsp
->playback_pid
= current
->pid
;
4774 hdsp
->playback_substream
= substream
;
4776 spin_unlock_irq(&hdsp
->lock
);
4778 snd_pcm_hw_constraint_msbits(runtime
, 0, 32, 24);
4779 snd_pcm_hw_constraint_list(runtime
, 0, SNDRV_PCM_HW_PARAM_PERIOD_SIZE
, &hdsp_hw_constraints_period_sizes
);
4780 if (hdsp
->clock_source_locked
) {
4781 runtime
->hw
.rate_min
= runtime
->hw
.rate_max
= hdsp
->system_sample_rate
;
4782 } else if (hdsp
->io_type
== H9632
) {
4783 runtime
->hw
.rate_max
= 192000;
4784 runtime
->hw
.rates
= SNDRV_PCM_RATE_KNOT
;
4785 snd_pcm_hw_constraint_list(runtime
, 0, SNDRV_PCM_HW_PARAM_RATE
, &hdsp_hw_constraints_9632_sample_rates
);
4787 if (hdsp
->io_type
== H9632
) {
4788 runtime
->hw
.channels_min
= hdsp
->qs_out_channels
;
4789 runtime
->hw
.channels_max
= hdsp
->ss_out_channels
;
4792 snd_pcm_hw_rule_add(runtime
, 0, SNDRV_PCM_HW_PARAM_CHANNELS
,
4793 snd_hdsp_hw_rule_out_channels
, hdsp
,
4794 SNDRV_PCM_HW_PARAM_CHANNELS
, -1);
4795 snd_pcm_hw_rule_add(runtime
, 0, SNDRV_PCM_HW_PARAM_CHANNELS
,
4796 snd_hdsp_hw_rule_out_channels_rate
, hdsp
,
4797 SNDRV_PCM_HW_PARAM_RATE
, -1);
4798 snd_pcm_hw_rule_add(runtime
, 0, SNDRV_PCM_HW_PARAM_RATE
,
4799 snd_hdsp_hw_rule_rate_out_channels
, hdsp
,
4800 SNDRV_PCM_HW_PARAM_CHANNELS
, -1);
4802 if (RPM
!= hdsp
->io_type
) {
4803 hdsp
->creg_spdif_stream
= hdsp
->creg_spdif
;
4804 hdsp
->spdif_ctl
->vd
[0].access
&= ~SNDRV_CTL_ELEM_ACCESS_INACTIVE
;
4805 snd_ctl_notify(hdsp
->card
, SNDRV_CTL_EVENT_MASK_VALUE
|
4806 SNDRV_CTL_EVENT_MASK_INFO
, &hdsp
->spdif_ctl
->id
);
4811 static int snd_hdsp_playback_release(struct snd_pcm_substream
*substream
)
4813 struct hdsp
*hdsp
= snd_pcm_substream_chip(substream
);
4815 spin_lock_irq(&hdsp
->lock
);
4817 hdsp
->playback_pid
= -1;
4818 hdsp
->playback_substream
= NULL
;
4820 spin_unlock_irq(&hdsp
->lock
);
4822 if (RPM
!= hdsp
->io_type
) {
4823 hdsp
->spdif_ctl
->vd
[0].access
|= SNDRV_CTL_ELEM_ACCESS_INACTIVE
;
4824 snd_ctl_notify(hdsp
->card
, SNDRV_CTL_EVENT_MASK_VALUE
|
4825 SNDRV_CTL_EVENT_MASK_INFO
, &hdsp
->spdif_ctl
->id
);
4831 static int snd_hdsp_capture_open(struct snd_pcm_substream
*substream
)
4833 struct hdsp
*hdsp
= snd_pcm_substream_chip(substream
);
4834 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
4836 if (hdsp_check_for_iobox (hdsp
))
4839 if (hdsp_check_for_firmware(hdsp
, 1))
4842 spin_lock_irq(&hdsp
->lock
);
4844 snd_pcm_set_sync(substream
);
4846 runtime
->hw
= snd_hdsp_capture_subinfo
;
4847 runtime
->dma_area
= hdsp
->capture_buffer
;
4848 runtime
->dma_bytes
= HDSP_DMA_AREA_BYTES
;
4850 hdsp
->capture_pid
= current
->pid
;
4851 hdsp
->capture_substream
= substream
;
4853 spin_unlock_irq(&hdsp
->lock
);
4855 snd_pcm_hw_constraint_msbits(runtime
, 0, 32, 24);
4856 snd_pcm_hw_constraint_list(runtime
, 0, SNDRV_PCM_HW_PARAM_PERIOD_SIZE
, &hdsp_hw_constraints_period_sizes
);
4857 if (hdsp
->io_type
== H9632
) {
4858 runtime
->hw
.channels_min
= hdsp
->qs_in_channels
;
4859 runtime
->hw
.channels_max
= hdsp
->ss_in_channels
;
4860 runtime
->hw
.rate_max
= 192000;
4861 runtime
->hw
.rates
= SNDRV_PCM_RATE_KNOT
;
4862 snd_pcm_hw_constraint_list(runtime
, 0, SNDRV_PCM_HW_PARAM_RATE
, &hdsp_hw_constraints_9632_sample_rates
);
4864 snd_pcm_hw_rule_add(runtime
, 0, SNDRV_PCM_HW_PARAM_CHANNELS
,
4865 snd_hdsp_hw_rule_in_channels
, hdsp
,
4866 SNDRV_PCM_HW_PARAM_CHANNELS
, -1);
4867 snd_pcm_hw_rule_add(runtime
, 0, SNDRV_PCM_HW_PARAM_CHANNELS
,
4868 snd_hdsp_hw_rule_in_channels_rate
, hdsp
,
4869 SNDRV_PCM_HW_PARAM_RATE
, -1);
4870 snd_pcm_hw_rule_add(runtime
, 0, SNDRV_PCM_HW_PARAM_RATE
,
4871 snd_hdsp_hw_rule_rate_in_channels
, hdsp
,
4872 SNDRV_PCM_HW_PARAM_CHANNELS
, -1);
4876 static int snd_hdsp_capture_release(struct snd_pcm_substream
*substream
)
4878 struct hdsp
*hdsp
= snd_pcm_substream_chip(substream
);
4880 spin_lock_irq(&hdsp
->lock
);
4882 hdsp
->capture_pid
= -1;
4883 hdsp
->capture_substream
= NULL
;
4885 spin_unlock_irq(&hdsp
->lock
);
4889 /* helper functions for copying meter values */
4890 static inline int copy_u32_le(void __user
*dest
, void __iomem
*src
)
4892 u32 val
= readl(src
);
4893 return copy_to_user(dest
, &val
, 4);
4896 static inline int copy_u64_le(void __user
*dest
, void __iomem
*src_low
, void __iomem
*src_high
)
4898 u32 rms_low
, rms_high
;
4900 rms_low
= readl(src_low
);
4901 rms_high
= readl(src_high
);
4902 rms
= ((u64
)rms_high
<< 32) | rms_low
;
4903 return copy_to_user(dest
, &rms
, 8);
4906 static inline int copy_u48_le(void __user
*dest
, void __iomem
*src_low
, void __iomem
*src_high
)
4908 u32 rms_low
, rms_high
;
4910 rms_low
= readl(src_low
) & 0xffffff00;
4911 rms_high
= readl(src_high
) & 0xffffff00;
4912 rms
= ((u64
)rms_high
<< 32) | rms_low
;
4913 return copy_to_user(dest
, &rms
, 8);
4916 static int hdsp_9652_get_peak(struct hdsp
*hdsp
, struct hdsp_peak_rms __user
*peak_rms
)
4918 int doublespeed
= 0;
4919 int i
, j
, channels
, ofs
;
4921 if (hdsp_read (hdsp
, HDSP_statusRegister
) & HDSP_DoubleSpeedStatus
)
4923 channels
= doublespeed
? 14 : 26;
4924 for (i
= 0, j
= 0; i
< 26; ++i
) {
4925 if (doublespeed
&& (i
& 4))
4927 ofs
= HDSP_9652_peakBase
- j
* 4;
4928 if (copy_u32_le(&peak_rms
->input_peaks
[i
], hdsp
->iobase
+ ofs
))
4930 ofs
-= channels
* 4;
4931 if (copy_u32_le(&peak_rms
->playback_peaks
[i
], hdsp
->iobase
+ ofs
))
4933 ofs
-= channels
* 4;
4934 if (copy_u32_le(&peak_rms
->output_peaks
[i
], hdsp
->iobase
+ ofs
))
4936 ofs
= HDSP_9652_rmsBase
+ j
* 8;
4937 if (copy_u48_le(&peak_rms
->input_rms
[i
], hdsp
->iobase
+ ofs
,
4938 hdsp
->iobase
+ ofs
+ 4))
4940 ofs
+= channels
* 8;
4941 if (copy_u48_le(&peak_rms
->playback_rms
[i
], hdsp
->iobase
+ ofs
,
4942 hdsp
->iobase
+ ofs
+ 4))
4944 ofs
+= channels
* 8;
4945 if (copy_u48_le(&peak_rms
->output_rms
[i
], hdsp
->iobase
+ ofs
,
4946 hdsp
->iobase
+ ofs
+ 4))
4953 static int hdsp_9632_get_peak(struct hdsp
*hdsp
, struct hdsp_peak_rms __user
*peak_rms
)
4956 struct hdsp_9632_meters __iomem
*m
;
4957 int doublespeed
= 0;
4959 if (hdsp_read (hdsp
, HDSP_statusRegister
) & HDSP_DoubleSpeedStatus
)
4961 m
= (struct hdsp_9632_meters __iomem
*)(hdsp
->iobase
+HDSP_9632_metersBase
);
4962 for (i
= 0, j
= 0; i
< 16; ++i
, ++j
) {
4963 if (copy_u32_le(&peak_rms
->input_peaks
[i
], &m
->input_peak
[j
]))
4965 if (copy_u32_le(&peak_rms
->playback_peaks
[i
], &m
->playback_peak
[j
]))
4967 if (copy_u32_le(&peak_rms
->output_peaks
[i
], &m
->output_peak
[j
]))
4969 if (copy_u64_le(&peak_rms
->input_rms
[i
], &m
->input_rms_low
[j
],
4970 &m
->input_rms_high
[j
]))
4972 if (copy_u64_le(&peak_rms
->playback_rms
[i
], &m
->playback_rms_low
[j
],
4973 &m
->playback_rms_high
[j
]))
4975 if (copy_u64_le(&peak_rms
->output_rms
[i
], &m
->output_rms_low
[j
],
4976 &m
->output_rms_high
[j
]))
4978 if (doublespeed
&& i
== 3) i
+= 4;
4983 static int hdsp_get_peak(struct hdsp
*hdsp
, struct hdsp_peak_rms __user
*peak_rms
)
4987 for (i
= 0; i
< 26; i
++) {
4988 if (copy_u32_le(&peak_rms
->playback_peaks
[i
],
4989 hdsp
->iobase
+ HDSP_playbackPeakLevel
+ i
* 4))
4991 if (copy_u32_le(&peak_rms
->input_peaks
[i
],
4992 hdsp
->iobase
+ HDSP_inputPeakLevel
+ i
* 4))
4995 for (i
= 0; i
< 28; i
++) {
4996 if (copy_u32_le(&peak_rms
->output_peaks
[i
],
4997 hdsp
->iobase
+ HDSP_outputPeakLevel
+ i
* 4))
5000 for (i
= 0; i
< 26; ++i
) {
5001 if (copy_u64_le(&peak_rms
->playback_rms
[i
],
5002 hdsp
->iobase
+ HDSP_playbackRmsLevel
+ i
* 8 + 4,
5003 hdsp
->iobase
+ HDSP_playbackRmsLevel
+ i
* 8))
5005 if (copy_u64_le(&peak_rms
->input_rms
[i
],
5006 hdsp
->iobase
+ HDSP_inputRmsLevel
+ i
* 8 + 4,
5007 hdsp
->iobase
+ HDSP_inputRmsLevel
+ i
* 8))
5013 static int snd_hdsp_hwdep_ioctl(struct snd_hwdep
*hw
, struct file
*file
, unsigned int cmd
, unsigned long arg
)
5015 struct hdsp
*hdsp
= hw
->private_data
;
5016 void __user
*argp
= (void __user
*)arg
;
5020 case SNDRV_HDSP_IOCTL_GET_PEAK_RMS
: {
5021 struct hdsp_peak_rms __user
*peak_rms
= (struct hdsp_peak_rms __user
*)arg
;
5023 err
= hdsp_check_for_iobox(hdsp
);
5027 err
= hdsp_check_for_firmware(hdsp
, 1);
5031 if (!(hdsp
->state
& HDSP_FirmwareLoaded
)) {
5032 snd_printk(KERN_ERR
"Hammerfall-DSP: firmware needs to be uploaded to the card.\n");
5036 switch (hdsp
->io_type
) {
5038 return hdsp_9652_get_peak(hdsp
, peak_rms
);
5040 return hdsp_9632_get_peak(hdsp
, peak_rms
);
5042 return hdsp_get_peak(hdsp
, peak_rms
);
5045 case SNDRV_HDSP_IOCTL_GET_CONFIG_INFO
: {
5046 struct hdsp_config_info info
;
5047 unsigned long flags
;
5050 err
= hdsp_check_for_iobox(hdsp
);
5054 err
= hdsp_check_for_firmware(hdsp
, 1);
5058 memset(&info
, 0, sizeof(info
));
5059 spin_lock_irqsave(&hdsp
->lock
, flags
);
5060 info
.pref_sync_ref
= (unsigned char)hdsp_pref_sync_ref(hdsp
);
5061 info
.wordclock_sync_check
= (unsigned char)hdsp_wc_sync_check(hdsp
);
5062 if (hdsp
->io_type
!= H9632
)
5063 info
.adatsync_sync_check
= (unsigned char)hdsp_adatsync_sync_check(hdsp
);
5064 info
.spdif_sync_check
= (unsigned char)hdsp_spdif_sync_check(hdsp
);
5065 for (i
= 0; i
< ((hdsp
->io_type
!= Multiface
&& hdsp
->io_type
!= RPM
&& hdsp
->io_type
!= H9632
) ? 3 : 1); ++i
)
5066 info
.adat_sync_check
[i
] = (unsigned char)hdsp_adat_sync_check(hdsp
, i
);
5067 info
.spdif_in
= (unsigned char)hdsp_spdif_in(hdsp
);
5068 info
.spdif_out
= (unsigned char)hdsp_spdif_out(hdsp
);
5069 info
.spdif_professional
= (unsigned char)hdsp_spdif_professional(hdsp
);
5070 info
.spdif_emphasis
= (unsigned char)hdsp_spdif_emphasis(hdsp
);
5071 info
.spdif_nonaudio
= (unsigned char)hdsp_spdif_nonaudio(hdsp
);
5072 info
.spdif_sample_rate
= hdsp_spdif_sample_rate(hdsp
);
5073 info
.system_sample_rate
= hdsp
->system_sample_rate
;
5074 info
.autosync_sample_rate
= hdsp_external_sample_rate(hdsp
);
5075 info
.system_clock_mode
= (unsigned char)hdsp_system_clock_mode(hdsp
);
5076 info
.clock_source
= (unsigned char)hdsp_clock_source(hdsp
);
5077 info
.autosync_ref
= (unsigned char)hdsp_autosync_ref(hdsp
);
5078 info
.line_out
= (unsigned char)hdsp_line_out(hdsp
);
5079 if (hdsp
->io_type
== H9632
) {
5080 info
.da_gain
= (unsigned char)hdsp_da_gain(hdsp
);
5081 info
.ad_gain
= (unsigned char)hdsp_ad_gain(hdsp
);
5082 info
.phone_gain
= (unsigned char)hdsp_phone_gain(hdsp
);
5083 info
.xlr_breakout_cable
= (unsigned char)hdsp_xlr_breakout_cable(hdsp
);
5085 } else if (hdsp
->io_type
== RPM
) {
5086 info
.da_gain
= (unsigned char) hdsp_rpm_input12(hdsp
);
5087 info
.ad_gain
= (unsigned char) hdsp_rpm_input34(hdsp
);
5089 if (hdsp
->io_type
== H9632
|| hdsp
->io_type
== H9652
)
5090 info
.analog_extension_board
= (unsigned char)hdsp_aeb(hdsp
);
5091 spin_unlock_irqrestore(&hdsp
->lock
, flags
);
5092 if (copy_to_user(argp
, &info
, sizeof(info
)))
5096 case SNDRV_HDSP_IOCTL_GET_9632_AEB
: {
5097 struct hdsp_9632_aeb h9632_aeb
;
5099 if (hdsp
->io_type
!= H9632
) return -EINVAL
;
5100 h9632_aeb
.aebi
= hdsp
->ss_in_channels
- H9632_SS_CHANNELS
;
5101 h9632_aeb
.aebo
= hdsp
->ss_out_channels
- H9632_SS_CHANNELS
;
5102 if (copy_to_user(argp
, &h9632_aeb
, sizeof(h9632_aeb
)))
5106 case SNDRV_HDSP_IOCTL_GET_VERSION
: {
5107 struct hdsp_version hdsp_version
;
5110 if (hdsp
->io_type
== H9652
|| hdsp
->io_type
== H9632
) return -EINVAL
;
5111 if (hdsp
->io_type
== Undefined
) {
5112 if ((err
= hdsp_get_iobox_version(hdsp
)) < 0)
5115 hdsp_version
.io_type
= hdsp
->io_type
;
5116 hdsp_version
.firmware_rev
= hdsp
->firmware_rev
;
5117 if ((err
= copy_to_user(argp
, &hdsp_version
, sizeof(hdsp_version
))))
5121 case SNDRV_HDSP_IOCTL_UPLOAD_FIRMWARE
: {
5122 struct hdsp_firmware __user
*firmware
;
5123 u32 __user
*firmware_data
;
5126 if (hdsp
->io_type
== H9652
|| hdsp
->io_type
== H9632
) return -EINVAL
;
5127 /* SNDRV_HDSP_IOCTL_GET_VERSION must have been called */
5128 if (hdsp
->io_type
== Undefined
) return -EINVAL
;
5130 if (hdsp
->state
& (HDSP_FirmwareCached
| HDSP_FirmwareLoaded
))
5133 snd_printk(KERN_INFO
"Hammerfall-DSP: initializing firmware upload\n");
5134 firmware
= (struct hdsp_firmware __user
*)argp
;
5136 if (get_user(firmware_data
, &firmware
->firmware_data
))
5139 if (hdsp_check_for_iobox (hdsp
))
5142 if (!hdsp
->fw_uploaded
) {
5143 hdsp
->fw_uploaded
= vmalloc(HDSP_FIRMWARE_SIZE
);
5144 if (!hdsp
->fw_uploaded
)
5148 if (copy_from_user(hdsp
->fw_uploaded
, firmware_data
,
5149 HDSP_FIRMWARE_SIZE
)) {
5150 vfree(hdsp
->fw_uploaded
);
5151 hdsp
->fw_uploaded
= NULL
;
5155 hdsp
->state
|= HDSP_FirmwareCached
;
5157 if ((err
= snd_hdsp_load_firmware_from_cache(hdsp
)) < 0)
5160 if (!(hdsp
->state
& HDSP_InitializationComplete
)) {
5161 if ((err
= snd_hdsp_enable_io(hdsp
)) < 0)
5164 snd_hdsp_initialize_channels(hdsp
);
5165 snd_hdsp_initialize_midi_flush(hdsp
);
5167 if ((err
= snd_hdsp_create_alsa_devices(hdsp
->card
, hdsp
)) < 0) {
5168 snd_printk(KERN_ERR
"Hammerfall-DSP: error creating alsa devices\n");
5174 case SNDRV_HDSP_IOCTL_GET_MIXER
: {
5175 struct hdsp_mixer __user
*mixer
= (struct hdsp_mixer __user
*)argp
;
5176 if (copy_to_user(mixer
->matrix
, hdsp
->mixer_matrix
, sizeof(unsigned short)*HDSP_MATRIX_MIXER_SIZE
))
5186 static struct snd_pcm_ops snd_hdsp_playback_ops
= {
5187 .open
= snd_hdsp_playback_open
,
5188 .close
= snd_hdsp_playback_release
,
5189 .ioctl
= snd_hdsp_ioctl
,
5190 .hw_params
= snd_hdsp_hw_params
,
5191 .prepare
= snd_hdsp_prepare
,
5192 .trigger
= snd_hdsp_trigger
,
5193 .pointer
= snd_hdsp_hw_pointer
,
5194 .copy
= snd_hdsp_playback_copy
,
5195 .silence
= snd_hdsp_hw_silence
,
5198 static struct snd_pcm_ops snd_hdsp_capture_ops
= {
5199 .open
= snd_hdsp_capture_open
,
5200 .close
= snd_hdsp_capture_release
,
5201 .ioctl
= snd_hdsp_ioctl
,
5202 .hw_params
= snd_hdsp_hw_params
,
5203 .prepare
= snd_hdsp_prepare
,
5204 .trigger
= snd_hdsp_trigger
,
5205 .pointer
= snd_hdsp_hw_pointer
,
5206 .copy
= snd_hdsp_capture_copy
,
5209 static int snd_hdsp_create_hwdep(struct snd_card
*card
, struct hdsp
*hdsp
)
5211 struct snd_hwdep
*hw
;
5214 if ((err
= snd_hwdep_new(card
, "HDSP hwdep", 0, &hw
)) < 0)
5218 hw
->private_data
= hdsp
;
5219 strcpy(hw
->name
, "HDSP hwdep interface");
5221 hw
->ops
.ioctl
= snd_hdsp_hwdep_ioctl
;
5222 hw
->ops
.ioctl_compat
= snd_hdsp_hwdep_ioctl
;
5227 static int snd_hdsp_create_pcm(struct snd_card
*card
, struct hdsp
*hdsp
)
5229 struct snd_pcm
*pcm
;
5232 if ((err
= snd_pcm_new(card
, hdsp
->card_name
, 0, 1, 1, &pcm
)) < 0)
5236 pcm
->private_data
= hdsp
;
5237 strcpy(pcm
->name
, hdsp
->card_name
);
5239 snd_pcm_set_ops(pcm
, SNDRV_PCM_STREAM_PLAYBACK
, &snd_hdsp_playback_ops
);
5240 snd_pcm_set_ops(pcm
, SNDRV_PCM_STREAM_CAPTURE
, &snd_hdsp_capture_ops
);
5242 pcm
->info_flags
= SNDRV_PCM_INFO_JOINT_DUPLEX
;
5247 static void snd_hdsp_9652_enable_mixer (struct hdsp
*hdsp
)
5249 hdsp
->control2_register
|= HDSP_9652_ENABLE_MIXER
;
5250 hdsp_write (hdsp
, HDSP_control2Reg
, hdsp
->control2_register
);
5253 static int snd_hdsp_enable_io (struct hdsp
*hdsp
)
5257 if (hdsp_fifo_wait (hdsp
, 0, 100)) {
5258 snd_printk(KERN_ERR
"Hammerfall-DSP: enable_io fifo_wait failed\n");
5262 for (i
= 0; i
< hdsp
->max_channels
; ++i
) {
5263 hdsp_write (hdsp
, HDSP_inputEnable
+ (4 * i
), 1);
5264 hdsp_write (hdsp
, HDSP_outputEnable
+ (4 * i
), 1);
5270 static void snd_hdsp_initialize_channels(struct hdsp
*hdsp
)
5272 int status
, aebi_channels
, aebo_channels
;
5274 switch (hdsp
->io_type
) {
5276 hdsp
->card_name
= "RME Hammerfall DSP + Digiface";
5277 hdsp
->ss_in_channels
= hdsp
->ss_out_channels
= DIGIFACE_SS_CHANNELS
;
5278 hdsp
->ds_in_channels
= hdsp
->ds_out_channels
= DIGIFACE_DS_CHANNELS
;
5282 hdsp
->card_name
= "RME Hammerfall HDSP 9652";
5283 hdsp
->ss_in_channels
= hdsp
->ss_out_channels
= H9652_SS_CHANNELS
;
5284 hdsp
->ds_in_channels
= hdsp
->ds_out_channels
= H9652_DS_CHANNELS
;
5288 status
= hdsp_read(hdsp
, HDSP_statusRegister
);
5289 /* HDSP_AEBx bits are low when AEB are connected */
5290 aebi_channels
= (status
& HDSP_AEBI
) ? 0 : 4;
5291 aebo_channels
= (status
& HDSP_AEBO
) ? 0 : 4;
5292 hdsp
->card_name
= "RME Hammerfall HDSP 9632";
5293 hdsp
->ss_in_channels
= H9632_SS_CHANNELS
+aebi_channels
;
5294 hdsp
->ds_in_channels
= H9632_DS_CHANNELS
+aebi_channels
;
5295 hdsp
->qs_in_channels
= H9632_QS_CHANNELS
+aebi_channels
;
5296 hdsp
->ss_out_channels
= H9632_SS_CHANNELS
+aebo_channels
;
5297 hdsp
->ds_out_channels
= H9632_DS_CHANNELS
+aebo_channels
;
5298 hdsp
->qs_out_channels
= H9632_QS_CHANNELS
+aebo_channels
;
5302 hdsp
->card_name
= "RME Hammerfall DSP + Multiface";
5303 hdsp
->ss_in_channels
= hdsp
->ss_out_channels
= MULTIFACE_SS_CHANNELS
;
5304 hdsp
->ds_in_channels
= hdsp
->ds_out_channels
= MULTIFACE_DS_CHANNELS
;
5308 hdsp
->card_name
= "RME Hammerfall DSP + RPM";
5309 hdsp
->ss_in_channels
= RPM_CHANNELS
-1;
5310 hdsp
->ss_out_channels
= RPM_CHANNELS
;
5311 hdsp
->ds_in_channels
= RPM_CHANNELS
-1;
5312 hdsp
->ds_out_channels
= RPM_CHANNELS
;
5316 /* should never get here */
5321 static void snd_hdsp_initialize_midi_flush (struct hdsp
*hdsp
)
5323 snd_hdsp_flush_midi_input (hdsp
, 0);
5324 snd_hdsp_flush_midi_input (hdsp
, 1);
5327 static int snd_hdsp_create_alsa_devices(struct snd_card
*card
, struct hdsp
*hdsp
)
5331 if ((err
= snd_hdsp_create_pcm(card
, hdsp
)) < 0) {
5332 snd_printk(KERN_ERR
"Hammerfall-DSP: Error creating pcm interface\n");
5337 if ((err
= snd_hdsp_create_midi(card
, hdsp
, 0)) < 0) {
5338 snd_printk(KERN_ERR
"Hammerfall-DSP: Error creating first midi interface\n");
5342 if (hdsp
->io_type
== Digiface
|| hdsp
->io_type
== H9652
) {
5343 if ((err
= snd_hdsp_create_midi(card
, hdsp
, 1)) < 0) {
5344 snd_printk(KERN_ERR
"Hammerfall-DSP: Error creating second midi interface\n");
5349 if ((err
= snd_hdsp_create_controls(card
, hdsp
)) < 0) {
5350 snd_printk(KERN_ERR
"Hammerfall-DSP: Error creating ctl interface\n");
5354 snd_hdsp_proc_init(hdsp
);
5356 hdsp
->system_sample_rate
= -1;
5357 hdsp
->playback_pid
= -1;
5358 hdsp
->capture_pid
= -1;
5359 hdsp
->capture_substream
= NULL
;
5360 hdsp
->playback_substream
= NULL
;
5362 if ((err
= snd_hdsp_set_defaults(hdsp
)) < 0) {
5363 snd_printk(KERN_ERR
"Hammerfall-DSP: Error setting default values\n");
5367 if (!(hdsp
->state
& HDSP_InitializationComplete
)) {
5368 strcpy(card
->shortname
, "Hammerfall DSP");
5369 sprintf(card
->longname
, "%s at 0x%lx, irq %d", hdsp
->card_name
,
5370 hdsp
->port
, hdsp
->irq
);
5372 if ((err
= snd_card_register(card
)) < 0) {
5373 snd_printk(KERN_ERR
"Hammerfall-DSP: error registering card\n");
5376 hdsp
->state
|= HDSP_InitializationComplete
;
5382 /* load firmware via hotplug fw loader */
5383 static int hdsp_request_fw_loader(struct hdsp
*hdsp
)
5386 const struct firmware
*fw
;
5389 if (hdsp
->io_type
== H9652
|| hdsp
->io_type
== H9632
)
5391 if (hdsp
->io_type
== Undefined
) {
5392 if ((err
= hdsp_get_iobox_version(hdsp
)) < 0)
5394 if (hdsp
->io_type
== H9652
|| hdsp
->io_type
== H9632
)
5398 /* caution: max length of firmware filename is 30! */
5399 switch (hdsp
->io_type
) {
5401 fwfile
= "rpm_firmware.bin";
5404 if (hdsp
->firmware_rev
== 0xa)
5405 fwfile
= "multiface_firmware.bin";
5407 fwfile
= "multiface_firmware_rev11.bin";
5410 if (hdsp
->firmware_rev
== 0xa)
5411 fwfile
= "digiface_firmware.bin";
5413 fwfile
= "digiface_firmware_rev11.bin";
5416 snd_printk(KERN_ERR
"Hammerfall-DSP: invalid io_type %d\n", hdsp
->io_type
);
5420 if (request_firmware(&fw
, fwfile
, &hdsp
->pci
->dev
)) {
5421 snd_printk(KERN_ERR
"Hammerfall-DSP: cannot load firmware %s\n", fwfile
);
5424 if (fw
->size
< HDSP_FIRMWARE_SIZE
) {
5425 snd_printk(KERN_ERR
"Hammerfall-DSP: too short firmware size %d (expected %d)\n",
5426 (int)fw
->size
, HDSP_FIRMWARE_SIZE
);
5430 hdsp
->firmware
= fw
;
5432 hdsp
->state
|= HDSP_FirmwareCached
;
5434 if ((err
= snd_hdsp_load_firmware_from_cache(hdsp
)) < 0)
5437 if (!(hdsp
->state
& HDSP_InitializationComplete
)) {
5438 if ((err
= snd_hdsp_enable_io(hdsp
)) < 0)
5441 if ((err
= snd_hdsp_create_hwdep(hdsp
->card
, hdsp
)) < 0) {
5442 snd_printk(KERN_ERR
"Hammerfall-DSP: error creating hwdep device\n");
5445 snd_hdsp_initialize_channels(hdsp
);
5446 snd_hdsp_initialize_midi_flush(hdsp
);
5447 if ((err
= snd_hdsp_create_alsa_devices(hdsp
->card
, hdsp
)) < 0) {
5448 snd_printk(KERN_ERR
"Hammerfall-DSP: error creating alsa devices\n");
5455 static int snd_hdsp_create(struct snd_card
*card
,
5458 struct pci_dev
*pci
= hdsp
->pci
;
5465 hdsp
->midi
[0].rmidi
= NULL
;
5466 hdsp
->midi
[1].rmidi
= NULL
;
5467 hdsp
->midi
[0].input
= NULL
;
5468 hdsp
->midi
[1].input
= NULL
;
5469 hdsp
->midi
[0].output
= NULL
;
5470 hdsp
->midi
[1].output
= NULL
;
5471 hdsp
->midi
[0].pending
= 0;
5472 hdsp
->midi
[1].pending
= 0;
5473 spin_lock_init(&hdsp
->midi
[0].lock
);
5474 spin_lock_init(&hdsp
->midi
[1].lock
);
5475 hdsp
->iobase
= NULL
;
5476 hdsp
->control_register
= 0;
5477 hdsp
->control2_register
= 0;
5478 hdsp
->io_type
= Undefined
;
5479 hdsp
->max_channels
= 26;
5483 spin_lock_init(&hdsp
->lock
);
5485 tasklet_init(&hdsp
->midi_tasklet
, hdsp_midi_tasklet
, (unsigned long)hdsp
);
5487 pci_read_config_word(hdsp
->pci
, PCI_CLASS_REVISION
, &hdsp
->firmware_rev
);
5488 hdsp
->firmware_rev
&= 0xff;
5490 /* From Martin Bjoernsen :
5491 "It is important that the card's latency timer register in
5492 the PCI configuration space is set to a value much larger
5493 than 0 by the computer's BIOS or the driver.
5494 The windows driver always sets this 8 bit register [...]
5495 to its maximum 255 to avoid problems with some computers."
5497 pci_write_config_byte(hdsp
->pci
, PCI_LATENCY_TIMER
, 0xFF);
5499 strcpy(card
->driver
, "H-DSP");
5500 strcpy(card
->mixername
, "Xilinx FPGA");
5502 if (hdsp
->firmware_rev
< 0xa)
5504 else if (hdsp
->firmware_rev
< 0x64)
5505 hdsp
->card_name
= "RME Hammerfall DSP";
5506 else if (hdsp
->firmware_rev
< 0x96) {
5507 hdsp
->card_name
= "RME HDSP 9652";
5510 hdsp
->card_name
= "RME HDSP 9632";
5511 hdsp
->max_channels
= 16;
5515 if ((err
= pci_enable_device(pci
)) < 0)
5518 pci_set_master(hdsp
->pci
);
5520 if ((err
= pci_request_regions(pci
, "hdsp")) < 0)
5522 hdsp
->port
= pci_resource_start(pci
, 0);
5523 if ((hdsp
->iobase
= ioremap_nocache(hdsp
->port
, HDSP_IO_EXTENT
)) == NULL
) {
5524 snd_printk(KERN_ERR
"Hammerfall-DSP: unable to remap region 0x%lx-0x%lx\n", hdsp
->port
, hdsp
->port
+ HDSP_IO_EXTENT
- 1);
5528 if (request_irq(pci
->irq
, snd_hdsp_interrupt
, IRQF_SHARED
,
5529 KBUILD_MODNAME
, hdsp
)) {
5530 snd_printk(KERN_ERR
"Hammerfall-DSP: unable to use IRQ %d\n", pci
->irq
);
5534 hdsp
->irq
= pci
->irq
;
5535 hdsp
->precise_ptr
= 0;
5536 hdsp
->use_midi_tasklet
= 1;
5537 hdsp
->dds_value
= 0;
5539 if ((err
= snd_hdsp_initialize_memory(hdsp
)) < 0)
5542 if (!is_9652
&& !is_9632
) {
5543 /* we wait a maximum of 10 seconds to let freshly
5544 * inserted cardbus cards do their hardware init */
5545 err
= hdsp_wait_for_iobox(hdsp
, 1000, 10);
5550 if ((hdsp_read (hdsp
, HDSP_statusRegister
) & HDSP_DllError
) != 0) {
5551 if ((err
= hdsp_request_fw_loader(hdsp
)) < 0)
5552 /* we don't fail as this can happen
5553 if userspace is not ready for
5556 snd_printk(KERN_ERR
"Hammerfall-DSP: couldn't get firmware from userspace. try using hdsploader\n");
5558 /* init is complete, we return */
5560 /* we defer initialization */
5561 snd_printk(KERN_INFO
"Hammerfall-DSP: card initialization pending : waiting for firmware\n");
5562 if ((err
= snd_hdsp_create_hwdep(card
, hdsp
)) < 0)
5566 snd_printk(KERN_INFO
"Hammerfall-DSP: Firmware already present, initializing card.\n");
5567 if (hdsp_read(hdsp
, HDSP_status2Register
) & HDSP_version2
)
5568 hdsp
->io_type
= RPM
;
5569 else if (hdsp_read(hdsp
, HDSP_status2Register
) & HDSP_version1
)
5570 hdsp
->io_type
= Multiface
;
5572 hdsp
->io_type
= Digiface
;
5576 if ((err
= snd_hdsp_enable_io(hdsp
)) != 0)
5580 hdsp
->io_type
= H9652
;
5583 hdsp
->io_type
= H9632
;
5585 if ((err
= snd_hdsp_create_hwdep(card
, hdsp
)) < 0)
5588 snd_hdsp_initialize_channels(hdsp
);
5589 snd_hdsp_initialize_midi_flush(hdsp
);
5591 hdsp
->state
|= HDSP_FirmwareLoaded
;
5593 if ((err
= snd_hdsp_create_alsa_devices(card
, hdsp
)) < 0)
5599 static int snd_hdsp_free(struct hdsp
*hdsp
)
5602 /* stop the audio, and cancel all interrupts */
5603 tasklet_kill(&hdsp
->midi_tasklet
);
5604 hdsp
->control_register
&= ~(HDSP_Start
|HDSP_AudioInterruptEnable
|HDSP_Midi0InterruptEnable
|HDSP_Midi1InterruptEnable
);
5605 hdsp_write (hdsp
, HDSP_controlRegister
, hdsp
->control_register
);
5609 free_irq(hdsp
->irq
, (void *)hdsp
);
5611 snd_hdsp_free_buffers(hdsp
);
5614 release_firmware(hdsp
->firmware
);
5615 vfree(hdsp
->fw_uploaded
);
5618 iounmap(hdsp
->iobase
);
5621 pci_release_regions(hdsp
->pci
);
5623 pci_disable_device(hdsp
->pci
);
5627 static void snd_hdsp_card_free(struct snd_card
*card
)
5629 struct hdsp
*hdsp
= card
->private_data
;
5632 snd_hdsp_free(hdsp
);
5635 static int snd_hdsp_probe(struct pci_dev
*pci
,
5636 const struct pci_device_id
*pci_id
)
5640 struct snd_card
*card
;
5643 if (dev
>= SNDRV_CARDS
)
5650 err
= snd_card_create(index
[dev
], id
[dev
], THIS_MODULE
,
5651 sizeof(struct hdsp
), &card
);
5655 hdsp
= card
->private_data
;
5656 card
->private_free
= snd_hdsp_card_free
;
5659 snd_card_set_dev(card
, &pci
->dev
);
5661 if ((err
= snd_hdsp_create(card
, hdsp
)) < 0) {
5662 snd_card_free(card
);
5666 strcpy(card
->shortname
, "Hammerfall DSP");
5667 sprintf(card
->longname
, "%s at 0x%lx, irq %d", hdsp
->card_name
,
5668 hdsp
->port
, hdsp
->irq
);
5670 if ((err
= snd_card_register(card
)) < 0) {
5671 snd_card_free(card
);
5674 pci_set_drvdata(pci
, card
);
5679 static void snd_hdsp_remove(struct pci_dev
*pci
)
5681 snd_card_free(pci_get_drvdata(pci
));
5682 pci_set_drvdata(pci
, NULL
);
5685 static struct pci_driver hdsp_driver
= {
5686 .name
= KBUILD_MODNAME
,
5687 .id_table
= snd_hdsp_ids
,
5688 .probe
= snd_hdsp_probe
,
5689 .remove
= snd_hdsp_remove
,
5692 module_pci_driver(hdsp_driver
);