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>
34 #include <sound/core.h>
35 #include <sound/control.h>
36 #include <sound/pcm.h>
37 #include <sound/info.h>
38 #include <sound/asoundef.h>
39 #include <sound/rawmidi.h>
40 #include <sound/hwdep.h>
41 #include <sound/initval.h>
42 #include <sound/hdsp.h>
44 #include <asm/byteorder.h>
45 #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},"
65 #define HDSP_MAX_CHANNELS 26
66 #define HDSP_MAX_DS_CHANNELS 14
67 #define HDSP_MAX_QS_CHANNELS 8
68 #define DIGIFACE_SS_CHANNELS 26
69 #define DIGIFACE_DS_CHANNELS 14
70 #define MULTIFACE_SS_CHANNELS 18
71 #define MULTIFACE_DS_CHANNELS 14
72 #define H9652_SS_CHANNELS 26
73 #define H9652_DS_CHANNELS 14
74 /* This does not include possible Analog Extension Boards
75 AEBs are detected at card initialization
77 #define H9632_SS_CHANNELS 12
78 #define H9632_DS_CHANNELS 8
79 #define H9632_QS_CHANNELS 4
80 #define RPM_CHANNELS 6
82 /* Write registers. These are defined as byte-offsets from the iobase value.
84 #define HDSP_resetPointer 0
85 #define HDSP_freqReg 0
86 #define HDSP_outputBufferAddress 32
87 #define HDSP_inputBufferAddress 36
88 #define HDSP_controlRegister 64
89 #define HDSP_interruptConfirmation 96
90 #define HDSP_outputEnable 128
91 #define HDSP_control2Reg 256
92 #define HDSP_midiDataOut0 352
93 #define HDSP_midiDataOut1 356
94 #define HDSP_fifoData 368
95 #define HDSP_inputEnable 384
97 /* Read registers. These are defined as byte-offsets from the iobase value
100 #define HDSP_statusRegister 0
101 #define HDSP_timecode 128
102 #define HDSP_status2Register 192
103 #define HDSP_midiDataIn0 360
104 #define HDSP_midiDataIn1 364
105 #define HDSP_midiStatusOut0 384
106 #define HDSP_midiStatusOut1 388
107 #define HDSP_midiStatusIn0 392
108 #define HDSP_midiStatusIn1 396
109 #define HDSP_fifoStatus 400
111 /* the meters are regular i/o-mapped registers, but offset
112 considerably from the rest. the peak registers are reset
113 when read; the least-significant 4 bits are full-scale counters;
114 the actual peak value is in the most-significant 24 bits.
117 #define HDSP_playbackPeakLevel 4096 /* 26 * 32 bit values */
118 #define HDSP_inputPeakLevel 4224 /* 26 * 32 bit values */
119 #define HDSP_outputPeakLevel 4352 /* (26+2) * 32 bit values */
120 #define HDSP_playbackRmsLevel 4612 /* 26 * 64 bit values */
121 #define HDSP_inputRmsLevel 4868 /* 26 * 64 bit values */
124 /* This is for H9652 cards
125 Peak values are read downward from the base
126 Rms values are read upward
127 There are rms values for the outputs too
128 26*3 values are read in ss mode
129 14*3 in ds mode, with no gap between values
131 #define HDSP_9652_peakBase 7164
132 #define HDSP_9652_rmsBase 4096
134 /* c.f. the hdsp_9632_meters_t struct */
135 #define HDSP_9632_metersBase 4096
137 #define HDSP_IO_EXTENT 7168
139 /* control2 register bits */
141 #define HDSP_TMS 0x01
142 #define HDSP_TCK 0x02
143 #define HDSP_TDI 0x04
144 #define HDSP_JTAG 0x08
145 #define HDSP_PWDN 0x10
146 #define HDSP_PROGRAM 0x020
147 #define HDSP_CONFIG_MODE_0 0x040
148 #define HDSP_CONFIG_MODE_1 0x080
149 #define HDSP_VERSION_BIT (0x100 | HDSP_S_LOAD)
150 #define HDSP_BIGENDIAN_MODE 0x200
151 #define HDSP_RD_MULTIPLE 0x400
152 #define HDSP_9652_ENABLE_MIXER 0x800
153 #define HDSP_S200 0x800
154 #define HDSP_S300 (0x100 | HDSP_S200) /* dummy, purpose of 0x100 unknown */
155 #define HDSP_CYCLIC_MODE 0x1000
156 #define HDSP_TDO 0x10000000
158 #define HDSP_S_PROGRAM (HDSP_CYCLIC_MODE|HDSP_PROGRAM|HDSP_CONFIG_MODE_0)
159 #define HDSP_S_LOAD (HDSP_CYCLIC_MODE|HDSP_PROGRAM|HDSP_CONFIG_MODE_1)
161 /* Control Register bits */
163 #define HDSP_Start (1<<0) /* start engine */
164 #define HDSP_Latency0 (1<<1) /* buffer size = 2^n where n is defined by Latency{2,1,0} */
165 #define HDSP_Latency1 (1<<2) /* [ see above ] */
166 #define HDSP_Latency2 (1<<3) /* [ see above ] */
167 #define HDSP_ClockModeMaster (1<<4) /* 1=Master, 0=Slave/Autosync */
168 #define HDSP_AudioInterruptEnable (1<<5) /* what do you think ? */
169 #define HDSP_Frequency0 (1<<6) /* 0=44.1kHz/88.2kHz/176.4kHz 1=48kHz/96kHz/192kHz */
170 #define HDSP_Frequency1 (1<<7) /* 0=32kHz/64kHz/128kHz */
171 #define HDSP_DoubleSpeed (1<<8) /* 0=normal speed, 1=double speed */
172 #define HDSP_SPDIFProfessional (1<<9) /* 0=consumer, 1=professional */
173 #define HDSP_SPDIFEmphasis (1<<10) /* 0=none, 1=on */
174 #define HDSP_SPDIFNonAudio (1<<11) /* 0=off, 1=on */
175 #define HDSP_SPDIFOpticalOut (1<<12) /* 1=use 1st ADAT connector for SPDIF, 0=do not */
176 #define HDSP_SyncRef2 (1<<13)
177 #define HDSP_SPDIFInputSelect0 (1<<14)
178 #define HDSP_SPDIFInputSelect1 (1<<15)
179 #define HDSP_SyncRef0 (1<<16)
180 #define HDSP_SyncRef1 (1<<17)
181 #define HDSP_AnalogExtensionBoard (1<<18) /* For H9632 cards */
182 #define HDSP_XLRBreakoutCable (1<<20) /* For H9632 cards */
183 #define HDSP_Midi0InterruptEnable (1<<22)
184 #define HDSP_Midi1InterruptEnable (1<<23)
185 #define HDSP_LineOut (1<<24)
186 #define HDSP_ADGain0 (1<<25) /* From here : H9632 specific */
187 #define HDSP_ADGain1 (1<<26)
188 #define HDSP_DAGain0 (1<<27)
189 #define HDSP_DAGain1 (1<<28)
190 #define HDSP_PhoneGain0 (1<<29)
191 #define HDSP_PhoneGain1 (1<<30)
192 #define HDSP_QuadSpeed (1<<31)
194 /* RPM uses some of the registers for special purposes */
195 #define HDSP_RPM_Inp12 0x04A00
196 #define HDSP_RPM_Inp12_Phon_6dB 0x00800 /* Dolby */
197 #define HDSP_RPM_Inp12_Phon_0dB 0x00000 /* .. */
198 #define HDSP_RPM_Inp12_Phon_n6dB 0x04000 /* inp_0 */
199 #define HDSP_RPM_Inp12_Line_0dB 0x04200 /* Dolby+PRO */
200 #define HDSP_RPM_Inp12_Line_n6dB 0x00200 /* PRO */
202 #define HDSP_RPM_Inp34 0x32000
203 #define HDSP_RPM_Inp34_Phon_6dB 0x20000 /* SyncRef1 */
204 #define HDSP_RPM_Inp34_Phon_0dB 0x00000 /* .. */
205 #define HDSP_RPM_Inp34_Phon_n6dB 0x02000 /* SyncRef2 */
206 #define HDSP_RPM_Inp34_Line_0dB 0x30000 /* SyncRef1+SyncRef0 */
207 #define HDSP_RPM_Inp34_Line_n6dB 0x10000 /* SyncRef0 */
209 #define HDSP_RPM_Bypass 0x01000
211 #define HDSP_RPM_Disconnect 0x00001
213 #define HDSP_ADGainMask (HDSP_ADGain0|HDSP_ADGain1)
214 #define HDSP_ADGainMinus10dBV HDSP_ADGainMask
215 #define HDSP_ADGainPlus4dBu (HDSP_ADGain0)
216 #define HDSP_ADGainLowGain 0
218 #define HDSP_DAGainMask (HDSP_DAGain0|HDSP_DAGain1)
219 #define HDSP_DAGainHighGain HDSP_DAGainMask
220 #define HDSP_DAGainPlus4dBu (HDSP_DAGain0)
221 #define HDSP_DAGainMinus10dBV 0
223 #define HDSP_PhoneGainMask (HDSP_PhoneGain0|HDSP_PhoneGain1)
224 #define HDSP_PhoneGain0dB HDSP_PhoneGainMask
225 #define HDSP_PhoneGainMinus6dB (HDSP_PhoneGain0)
226 #define HDSP_PhoneGainMinus12dB 0
228 #define HDSP_LatencyMask (HDSP_Latency0|HDSP_Latency1|HDSP_Latency2)
229 #define HDSP_FrequencyMask (HDSP_Frequency0|HDSP_Frequency1|HDSP_DoubleSpeed|HDSP_QuadSpeed)
231 #define HDSP_SPDIFInputMask (HDSP_SPDIFInputSelect0|HDSP_SPDIFInputSelect1)
232 #define HDSP_SPDIFInputADAT1 0
233 #define HDSP_SPDIFInputCoaxial (HDSP_SPDIFInputSelect0)
234 #define HDSP_SPDIFInputCdrom (HDSP_SPDIFInputSelect1)
235 #define HDSP_SPDIFInputAES (HDSP_SPDIFInputSelect0|HDSP_SPDIFInputSelect1)
237 #define HDSP_SyncRefMask (HDSP_SyncRef0|HDSP_SyncRef1|HDSP_SyncRef2)
238 #define HDSP_SyncRef_ADAT1 0
239 #define HDSP_SyncRef_ADAT2 (HDSP_SyncRef0)
240 #define HDSP_SyncRef_ADAT3 (HDSP_SyncRef1)
241 #define HDSP_SyncRef_SPDIF (HDSP_SyncRef0|HDSP_SyncRef1)
242 #define HDSP_SyncRef_WORD (HDSP_SyncRef2)
243 #define HDSP_SyncRef_ADAT_SYNC (HDSP_SyncRef0|HDSP_SyncRef2)
245 /* Sample Clock Sources */
247 #define HDSP_CLOCK_SOURCE_AUTOSYNC 0
248 #define HDSP_CLOCK_SOURCE_INTERNAL_32KHZ 1
249 #define HDSP_CLOCK_SOURCE_INTERNAL_44_1KHZ 2
250 #define HDSP_CLOCK_SOURCE_INTERNAL_48KHZ 3
251 #define HDSP_CLOCK_SOURCE_INTERNAL_64KHZ 4
252 #define HDSP_CLOCK_SOURCE_INTERNAL_88_2KHZ 5
253 #define HDSP_CLOCK_SOURCE_INTERNAL_96KHZ 6
254 #define HDSP_CLOCK_SOURCE_INTERNAL_128KHZ 7
255 #define HDSP_CLOCK_SOURCE_INTERNAL_176_4KHZ 8
256 #define HDSP_CLOCK_SOURCE_INTERNAL_192KHZ 9
258 /* Preferred sync reference choices - used by "pref_sync_ref" control switch */
260 #define HDSP_SYNC_FROM_WORD 0
261 #define HDSP_SYNC_FROM_SPDIF 1
262 #define HDSP_SYNC_FROM_ADAT1 2
263 #define HDSP_SYNC_FROM_ADAT_SYNC 3
264 #define HDSP_SYNC_FROM_ADAT2 4
265 #define HDSP_SYNC_FROM_ADAT3 5
267 /* SyncCheck status */
269 #define HDSP_SYNC_CHECK_NO_LOCK 0
270 #define HDSP_SYNC_CHECK_LOCK 1
271 #define HDSP_SYNC_CHECK_SYNC 2
273 /* AutoSync references - used by "autosync_ref" control switch */
275 #define HDSP_AUTOSYNC_FROM_WORD 0
276 #define HDSP_AUTOSYNC_FROM_ADAT_SYNC 1
277 #define HDSP_AUTOSYNC_FROM_SPDIF 2
278 #define HDSP_AUTOSYNC_FROM_NONE 3
279 #define HDSP_AUTOSYNC_FROM_ADAT1 4
280 #define HDSP_AUTOSYNC_FROM_ADAT2 5
281 #define HDSP_AUTOSYNC_FROM_ADAT3 6
283 /* Possible sources of S/PDIF input */
285 #define HDSP_SPDIFIN_OPTICAL 0 /* optical (ADAT1) */
286 #define HDSP_SPDIFIN_COAXIAL 1 /* coaxial (RCA) */
287 #define HDSP_SPDIFIN_INTERNAL 2 /* internal (CDROM) */
288 #define HDSP_SPDIFIN_AES 3 /* xlr for H9632 (AES)*/
290 #define HDSP_Frequency32KHz HDSP_Frequency0
291 #define HDSP_Frequency44_1KHz HDSP_Frequency1
292 #define HDSP_Frequency48KHz (HDSP_Frequency1|HDSP_Frequency0)
293 #define HDSP_Frequency64KHz (HDSP_DoubleSpeed|HDSP_Frequency0)
294 #define HDSP_Frequency88_2KHz (HDSP_DoubleSpeed|HDSP_Frequency1)
295 #define HDSP_Frequency96KHz (HDSP_DoubleSpeed|HDSP_Frequency1|HDSP_Frequency0)
296 /* For H9632 cards */
297 #define HDSP_Frequency128KHz (HDSP_QuadSpeed|HDSP_DoubleSpeed|HDSP_Frequency0)
298 #define HDSP_Frequency176_4KHz (HDSP_QuadSpeed|HDSP_DoubleSpeed|HDSP_Frequency1)
299 #define HDSP_Frequency192KHz (HDSP_QuadSpeed|HDSP_DoubleSpeed|HDSP_Frequency1|HDSP_Frequency0)
300 /* RME says n = 104857600000000, but in the windows MADI driver, I see:
301 return 104857600000000 / rate; // 100 MHz
302 return 110100480000000 / rate; // 105 MHz
304 #define DDS_NUMERATOR 104857600000000ULL; /* = 2^20 * 10^8 */
306 #define hdsp_encode_latency(x) (((x)<<1) & HDSP_LatencyMask)
307 #define hdsp_decode_latency(x) (((x) & HDSP_LatencyMask)>>1)
309 #define hdsp_encode_spdif_in(x) (((x)&0x3)<<14)
310 #define hdsp_decode_spdif_in(x) (((x)>>14)&0x3)
312 /* Status Register bits */
314 #define HDSP_audioIRQPending (1<<0)
315 #define HDSP_Lock2 (1<<1) /* this is for Digiface and H9652 */
316 #define HDSP_spdifFrequency3 HDSP_Lock2 /* this is for H9632 only */
317 #define HDSP_Lock1 (1<<2)
318 #define HDSP_Lock0 (1<<3)
319 #define HDSP_SPDIFSync (1<<4)
320 #define HDSP_TimecodeLock (1<<5)
321 #define HDSP_BufferPositionMask 0x000FFC0 /* Bit 6..15 : h/w buffer pointer */
322 #define HDSP_Sync2 (1<<16)
323 #define HDSP_Sync1 (1<<17)
324 #define HDSP_Sync0 (1<<18)
325 #define HDSP_DoubleSpeedStatus (1<<19)
326 #define HDSP_ConfigError (1<<20)
327 #define HDSP_DllError (1<<21)
328 #define HDSP_spdifFrequency0 (1<<22)
329 #define HDSP_spdifFrequency1 (1<<23)
330 #define HDSP_spdifFrequency2 (1<<24)
331 #define HDSP_SPDIFErrorFlag (1<<25)
332 #define HDSP_BufferID (1<<26)
333 #define HDSP_TimecodeSync (1<<27)
334 #define HDSP_AEBO (1<<28) /* H9632 specific Analog Extension Boards */
335 #define HDSP_AEBI (1<<29) /* 0 = present, 1 = absent */
336 #define HDSP_midi0IRQPending (1<<30)
337 #define HDSP_midi1IRQPending (1<<31)
339 #define HDSP_spdifFrequencyMask (HDSP_spdifFrequency0|HDSP_spdifFrequency1|HDSP_spdifFrequency2)
340 #define HDSP_spdifFrequencyMask_9632 (HDSP_spdifFrequency0|\
341 HDSP_spdifFrequency1|\
342 HDSP_spdifFrequency2|\
343 HDSP_spdifFrequency3)
345 #define HDSP_spdifFrequency32KHz (HDSP_spdifFrequency0)
346 #define HDSP_spdifFrequency44_1KHz (HDSP_spdifFrequency1)
347 #define HDSP_spdifFrequency48KHz (HDSP_spdifFrequency0|HDSP_spdifFrequency1)
349 #define HDSP_spdifFrequency64KHz (HDSP_spdifFrequency2)
350 #define HDSP_spdifFrequency88_2KHz (HDSP_spdifFrequency0|HDSP_spdifFrequency2)
351 #define HDSP_spdifFrequency96KHz (HDSP_spdifFrequency2|HDSP_spdifFrequency1)
353 /* This is for H9632 cards */
354 #define HDSP_spdifFrequency128KHz (HDSP_spdifFrequency0|\
355 HDSP_spdifFrequency1|\
356 HDSP_spdifFrequency2)
357 #define HDSP_spdifFrequency176_4KHz HDSP_spdifFrequency3
358 #define HDSP_spdifFrequency192KHz (HDSP_spdifFrequency3|HDSP_spdifFrequency0)
360 /* Status2 Register bits */
362 #define HDSP_version0 (1<<0)
363 #define HDSP_version1 (1<<1)
364 #define HDSP_version2 (1<<2)
365 #define HDSP_wc_lock (1<<3)
366 #define HDSP_wc_sync (1<<4)
367 #define HDSP_inp_freq0 (1<<5)
368 #define HDSP_inp_freq1 (1<<6)
369 #define HDSP_inp_freq2 (1<<7)
370 #define HDSP_SelSyncRef0 (1<<8)
371 #define HDSP_SelSyncRef1 (1<<9)
372 #define HDSP_SelSyncRef2 (1<<10)
374 #define HDSP_wc_valid (HDSP_wc_lock|HDSP_wc_sync)
376 #define HDSP_systemFrequencyMask (HDSP_inp_freq0|HDSP_inp_freq1|HDSP_inp_freq2)
377 #define HDSP_systemFrequency32 (HDSP_inp_freq0)
378 #define HDSP_systemFrequency44_1 (HDSP_inp_freq1)
379 #define HDSP_systemFrequency48 (HDSP_inp_freq0|HDSP_inp_freq1)
380 #define HDSP_systemFrequency64 (HDSP_inp_freq2)
381 #define HDSP_systemFrequency88_2 (HDSP_inp_freq0|HDSP_inp_freq2)
382 #define HDSP_systemFrequency96 (HDSP_inp_freq1|HDSP_inp_freq2)
383 /* FIXME : more values for 9632 cards ? */
385 #define HDSP_SelSyncRefMask (HDSP_SelSyncRef0|HDSP_SelSyncRef1|HDSP_SelSyncRef2)
386 #define HDSP_SelSyncRef_ADAT1 0
387 #define HDSP_SelSyncRef_ADAT2 (HDSP_SelSyncRef0)
388 #define HDSP_SelSyncRef_ADAT3 (HDSP_SelSyncRef1)
389 #define HDSP_SelSyncRef_SPDIF (HDSP_SelSyncRef0|HDSP_SelSyncRef1)
390 #define HDSP_SelSyncRef_WORD (HDSP_SelSyncRef2)
391 #define HDSP_SelSyncRef_ADAT_SYNC (HDSP_SelSyncRef0|HDSP_SelSyncRef2)
393 /* Card state flags */
395 #define HDSP_InitializationComplete (1<<0)
396 #define HDSP_FirmwareLoaded (1<<1)
397 #define HDSP_FirmwareCached (1<<2)
399 /* FIFO wait times, defined in terms of 1/10ths of msecs */
401 #define HDSP_LONG_WAIT 5000
402 #define HDSP_SHORT_WAIT 30
404 #define UNITY_GAIN 32768
405 #define MINUS_INFINITY_GAIN 0
407 /* the size of a substream (1 mono data stream) */
409 #define HDSP_CHANNEL_BUFFER_SAMPLES (16*1024)
410 #define HDSP_CHANNEL_BUFFER_BYTES (4*HDSP_CHANNEL_BUFFER_SAMPLES)
412 /* the size of the area we need to allocate for DMA transfers. the
413 size is the same regardless of the number of channels - the
414 Multiface still uses the same memory area.
416 Note that we allocate 1 more channel than is apparently needed
417 because the h/w seems to write 1 byte beyond the end of the last
421 #define HDSP_DMA_AREA_BYTES ((HDSP_MAX_CHANNELS+1) * HDSP_CHANNEL_BUFFER_BYTES)
422 #define HDSP_DMA_AREA_KILOBYTES (HDSP_DMA_AREA_BYTES/1024)
424 #define HDSP_FIRMWARE_SIZE (24413 * 4)
426 struct hdsp_9632_meters {
428 u32 playback_peak[16];
432 u32 input_rms_low[16];
433 u32 playback_rms_low[16];
434 u32 output_rms_low[16];
436 u32 input_rms_high[16];
437 u32 playback_rms_high[16];
438 u32 output_rms_high[16];
439 u32 xxx_rms_high[16];
445 struct snd_rawmidi *rmidi;
446 struct snd_rawmidi_substream *input;
447 struct snd_rawmidi_substream *output;
448 char istimer; /* timer in use */
449 struct timer_list timer;
456 struct snd_pcm_substream *capture_substream;
457 struct snd_pcm_substream *playback_substream;
458 struct hdsp_midi midi[2];
459 struct tasklet_struct midi_tasklet;
460 int use_midi_tasklet;
462 u32 control_register; /* cached value */
463 u32 control2_register; /* cached value */
465 u32 creg_spdif_stream;
466 int clock_source_locked;
467 char *card_name; /* digiface/multiface/rpm */
468 enum HDSP_IO_Type io_type; /* ditto, but for code use */
469 unsigned short firmware_rev;
470 unsigned short state; /* stores state bits */
471 const struct firmware *firmware;
473 size_t period_bytes; /* guess what this is */
474 unsigned char max_channels;
475 unsigned char qs_in_channels; /* quad speed mode for H9632 */
476 unsigned char ds_in_channels;
477 unsigned char ss_in_channels; /* different for multiface/digiface */
478 unsigned char qs_out_channels;
479 unsigned char ds_out_channels;
480 unsigned char ss_out_channels;
482 struct snd_dma_buffer capture_dma_buf;
483 struct snd_dma_buffer playback_dma_buf;
484 unsigned char *capture_buffer; /* suitably aligned address */
485 unsigned char *playback_buffer; /* suitably aligned address */
490 int system_sample_rate;
495 void __iomem *iobase;
496 struct snd_card *card;
498 struct snd_hwdep *hwdep;
500 struct snd_kcontrol *spdif_ctl;
501 unsigned short mixer_matrix[HDSP_MATRIX_MIXER_SIZE];
502 unsigned int dds_value; /* last value written to freq register */
505 /* These tables map the ALSA channels 1..N to the channels that we
506 need to use in order to find the relevant channel buffer. RME
507 refer to this kind of mapping as between "the ADAT channel and
508 the DMA channel." We index it using the logical audio channel,
509 and the value is the DMA channel (i.e. channel buffer number)
510 where the data for that channel can be read/written from/to.
513 static char channel_map_df_ss[HDSP_MAX_CHANNELS] = {
514 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
515 18, 19, 20, 21, 22, 23, 24, 25
518 static char channel_map_mf_ss[HDSP_MAX_CHANNELS] = { /* Multiface */
520 0, 1, 2, 3, 4, 5, 6, 7,
522 16, 17, 18, 19, 20, 21, 22, 23,
525 -1, -1, -1, -1, -1, -1, -1, -1
528 static char channel_map_ds[HDSP_MAX_CHANNELS] = {
529 /* ADAT channels are remapped */
530 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23,
531 /* channels 12 and 13 are S/PDIF */
533 /* others don't exist */
534 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
537 static char channel_map_H9632_ss[HDSP_MAX_CHANNELS] = {
539 0, 1, 2, 3, 4, 5, 6, 7,
544 /* AO4S-192 and AI4S-192 extension boards */
546 /* others don't exist */
547 -1, -1, -1, -1, -1, -1, -1, -1,
551 static char channel_map_H9632_ds[HDSP_MAX_CHANNELS] = {
558 /* AO4S-192 and AI4S-192 extension boards */
560 /* others don't exist */
561 -1, -1, -1, -1, -1, -1, -1, -1,
562 -1, -1, -1, -1, -1, -1
565 static char channel_map_H9632_qs[HDSP_MAX_CHANNELS] = {
566 /* ADAT is disabled in this mode */
571 /* AO4S-192 and AI4S-192 extension boards */
573 /* others don't exist */
574 -1, -1, -1, -1, -1, -1, -1, -1,
575 -1, -1, -1, -1, -1, -1, -1, -1,
579 static int snd_hammerfall_get_buffer(struct pci_dev *pci, struct snd_dma_buffer *dmab, size_t size)
581 dmab->dev.type = SNDRV_DMA_TYPE_DEV;
582 dmab->dev.dev = snd_dma_pci_data(pci);
583 if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(pci),
589 static void snd_hammerfall_free_buffer(struct snd_dma_buffer *dmab, struct pci_dev *pci)
592 snd_dma_free_pages(dmab);
596 static const struct pci_device_id snd_hdsp_ids[] = {
598 .vendor = PCI_VENDOR_ID_XILINX,
599 .device = PCI_DEVICE_ID_XILINX_HAMMERFALL_DSP,
600 .subvendor = PCI_ANY_ID,
601 .subdevice = PCI_ANY_ID,
602 }, /* RME Hammerfall-DSP */
606 MODULE_DEVICE_TABLE(pci, snd_hdsp_ids);
609 static int snd_hdsp_create_alsa_devices(struct snd_card *card, struct hdsp *hdsp);
610 static int snd_hdsp_create_pcm(struct snd_card *card, struct hdsp *hdsp);
611 static int snd_hdsp_enable_io (struct hdsp *hdsp);
612 static void snd_hdsp_initialize_midi_flush (struct hdsp *hdsp);
613 static void snd_hdsp_initialize_channels (struct hdsp *hdsp);
614 static int hdsp_fifo_wait(struct hdsp *hdsp, int count, int timeout);
615 static int hdsp_autosync_ref(struct hdsp *hdsp);
616 static int snd_hdsp_set_defaults(struct hdsp *hdsp);
617 static void snd_hdsp_9652_enable_mixer (struct hdsp *hdsp);
619 static int hdsp_playback_to_output_key (struct hdsp *hdsp, int in, int out)
621 switch (hdsp->io_type) {
626 if (hdsp->firmware_rev == 0xa)
627 return (64 * out) + (32 + (in));
629 return (52 * out) + (26 + (in));
631 return (32 * out) + (16 + (in));
633 return (52 * out) + (26 + (in));
637 static int hdsp_input_to_output_key (struct hdsp *hdsp, int in, int out)
639 switch (hdsp->io_type) {
644 if (hdsp->firmware_rev == 0xa)
645 return (64 * out) + in;
647 return (52 * out) + in;
649 return (32 * out) + in;
651 return (52 * out) + in;
655 static void hdsp_write(struct hdsp *hdsp, int reg, int val)
657 writel(val, hdsp->iobase + reg);
660 static unsigned int hdsp_read(struct hdsp *hdsp, int reg)
662 return readl (hdsp->iobase + reg);
665 static int hdsp_check_for_iobox (struct hdsp *hdsp)
669 if (hdsp->io_type == H9652 || hdsp->io_type == H9632) return 0;
670 for (i = 0; i < 500; i++) {
671 if (0 == (hdsp_read(hdsp, HDSP_statusRegister) &
674 dev_dbg(hdsp->card->dev,
675 "IO box found after %d ms\n",
682 dev_err(hdsp->card->dev, "no IO box connected!\n");
683 hdsp->state &= ~HDSP_FirmwareLoaded;
687 static int hdsp_wait_for_iobox(struct hdsp *hdsp, unsigned int loops,
692 if (hdsp->io_type == H9652 || hdsp->io_type == H9632)
695 for (i = 0; i != loops; ++i) {
696 if (hdsp_read(hdsp, HDSP_statusRegister) & HDSP_ConfigError)
699 dev_dbg(hdsp->card->dev, "iobox found after %ums!\n",
705 dev_info(hdsp->card->dev, "no IO box connected!\n");
706 hdsp->state &= ~HDSP_FirmwareLoaded;
710 static int snd_hdsp_load_firmware_from_cache(struct hdsp *hdsp) {
716 if (hdsp->fw_uploaded)
717 cache = hdsp->fw_uploaded;
721 cache = (u32 *)hdsp->firmware->data;
726 if ((hdsp_read (hdsp, HDSP_statusRegister) & HDSP_DllError) != 0) {
728 dev_info(hdsp->card->dev, "loading firmware\n");
730 hdsp_write (hdsp, HDSP_control2Reg, HDSP_S_PROGRAM);
731 hdsp_write (hdsp, HDSP_fifoData, 0);
733 if (hdsp_fifo_wait (hdsp, 0, HDSP_LONG_WAIT)) {
734 dev_info(hdsp->card->dev,
735 "timeout waiting for download preparation\n");
736 hdsp_write(hdsp, HDSP_control2Reg, HDSP_S200);
740 hdsp_write (hdsp, HDSP_control2Reg, HDSP_S_LOAD);
742 for (i = 0; i < HDSP_FIRMWARE_SIZE / 4; ++i) {
743 hdsp_write(hdsp, HDSP_fifoData, cache[i]);
744 if (hdsp_fifo_wait (hdsp, 127, HDSP_LONG_WAIT)) {
745 dev_info(hdsp->card->dev,
746 "timeout during firmware loading\n");
747 hdsp_write(hdsp, HDSP_control2Reg, HDSP_S200);
752 hdsp_fifo_wait(hdsp, 3, HDSP_LONG_WAIT);
753 hdsp_write(hdsp, HDSP_control2Reg, HDSP_S200);
756 #ifdef SNDRV_BIG_ENDIAN
757 hdsp->control2_register = HDSP_BIGENDIAN_MODE;
759 hdsp->control2_register = 0;
761 hdsp_write (hdsp, HDSP_control2Reg, hdsp->control2_register);
762 dev_info(hdsp->card->dev, "finished firmware loading\n");
765 if (hdsp->state & HDSP_InitializationComplete) {
766 dev_info(hdsp->card->dev,
767 "firmware loaded from cache, restoring defaults\n");
768 spin_lock_irqsave(&hdsp->lock, flags);
769 snd_hdsp_set_defaults(hdsp);
770 spin_unlock_irqrestore(&hdsp->lock, flags);
773 hdsp->state |= HDSP_FirmwareLoaded;
778 static int hdsp_get_iobox_version (struct hdsp *hdsp)
780 if ((hdsp_read (hdsp, HDSP_statusRegister) & HDSP_DllError) != 0) {
782 hdsp_write(hdsp, HDSP_control2Reg, HDSP_S_LOAD);
783 hdsp_write(hdsp, HDSP_fifoData, 0);
785 if (hdsp_fifo_wait(hdsp, 0, HDSP_SHORT_WAIT) < 0) {
786 hdsp_write(hdsp, HDSP_control2Reg, HDSP_S300);
787 hdsp_write(hdsp, HDSP_control2Reg, HDSP_S_LOAD);
790 hdsp_write(hdsp, HDSP_control2Reg, HDSP_S200 | HDSP_PROGRAM);
791 hdsp_write (hdsp, HDSP_fifoData, 0);
792 if (hdsp_fifo_wait(hdsp, 0, HDSP_SHORT_WAIT) < 0) {
793 hdsp->io_type = Multiface;
794 dev_info(hdsp->card->dev, "Multiface found\n");
798 hdsp_write(hdsp, HDSP_control2Reg, HDSP_S_LOAD);
799 hdsp_write(hdsp, HDSP_fifoData, 0);
800 if (hdsp_fifo_wait(hdsp, 0, HDSP_SHORT_WAIT) == 0) {
801 hdsp->io_type = Digiface;
802 dev_info(hdsp->card->dev, "Digiface found\n");
806 hdsp_write(hdsp, HDSP_control2Reg, HDSP_S300);
807 hdsp_write(hdsp, HDSP_control2Reg, HDSP_S_LOAD);
808 hdsp_write(hdsp, HDSP_fifoData, 0);
809 if (hdsp_fifo_wait(hdsp, 0, HDSP_SHORT_WAIT) == 0) {
810 hdsp->io_type = Multiface;
811 dev_info(hdsp->card->dev, "Multiface found\n");
815 hdsp_write(hdsp, HDSP_control2Reg, HDSP_S300);
816 hdsp_write(hdsp, HDSP_control2Reg, HDSP_S_LOAD);
817 hdsp_write(hdsp, HDSP_fifoData, 0);
818 if (hdsp_fifo_wait(hdsp, 0, HDSP_SHORT_WAIT) < 0) {
819 hdsp->io_type = Multiface;
820 dev_info(hdsp->card->dev, "Multiface found\n");
825 dev_info(hdsp->card->dev, "RPM found\n");
828 /* firmware was already loaded, get iobox type */
829 if (hdsp_read(hdsp, HDSP_status2Register) & HDSP_version2)
831 else if (hdsp_read(hdsp, HDSP_status2Register) & HDSP_version1)
832 hdsp->io_type = Multiface;
834 hdsp->io_type = Digiface;
840 static int hdsp_request_fw_loader(struct hdsp *hdsp);
842 static int hdsp_check_for_firmware (struct hdsp *hdsp, int load_on_demand)
844 if (hdsp->io_type == H9652 || hdsp->io_type == H9632)
846 if ((hdsp_read (hdsp, HDSP_statusRegister) & HDSP_DllError) != 0) {
847 hdsp->state &= ~HDSP_FirmwareLoaded;
848 if (! load_on_demand)
850 dev_err(hdsp->card->dev, "firmware not present.\n");
851 /* try to load firmware */
852 if (! (hdsp->state & HDSP_FirmwareCached)) {
853 if (! hdsp_request_fw_loader(hdsp))
855 dev_err(hdsp->card->dev,
856 "No firmware loaded nor cached, please upload firmware.\n");
859 if (snd_hdsp_load_firmware_from_cache(hdsp) != 0) {
860 dev_err(hdsp->card->dev,
861 "Firmware loading from cache failed, please upload manually.\n");
869 static int hdsp_fifo_wait(struct hdsp *hdsp, int count, int timeout)
873 /* the fifoStatus registers reports on how many words
874 are available in the command FIFO.
877 for (i = 0; i < timeout; i++) {
879 if ((int)(hdsp_read (hdsp, HDSP_fifoStatus) & 0xff) <= count)
882 /* not very friendly, but we only do this during a firmware
883 load and changing the mixer, so we just put up with it.
889 dev_warn(hdsp->card->dev,
890 "wait for FIFO status <= %d failed after %d iterations\n",
895 static int hdsp_read_gain (struct hdsp *hdsp, unsigned int addr)
897 if (addr >= HDSP_MATRIX_MIXER_SIZE)
900 return hdsp->mixer_matrix[addr];
903 static int hdsp_write_gain(struct hdsp *hdsp, unsigned int addr, unsigned short data)
907 if (addr >= HDSP_MATRIX_MIXER_SIZE)
910 if (hdsp->io_type == H9652 || hdsp->io_type == H9632) {
912 /* from martin bjornsen:
914 "You can only write dwords to the
915 mixer memory which contain two
916 mixer values in the low and high
917 word. So if you want to change
918 value 0 you have to read value 1
919 from the cache and write both to
920 the first dword in the mixer
924 if (hdsp->io_type == H9632 && addr >= 512)
927 if (hdsp->io_type == H9652 && addr >= 1352)
930 hdsp->mixer_matrix[addr] = data;
933 /* `addr' addresses a 16-bit wide address, but
934 the address space accessed via hdsp_write
935 uses byte offsets. put another way, addr
936 varies from 0 to 1351, but to access the
937 corresponding memory location, we need
938 to access 0 to 2703 ...
942 hdsp_write (hdsp, 4096 + (ad*4),
943 (hdsp->mixer_matrix[(addr&0x7fe)+1] << 16) +
944 hdsp->mixer_matrix[addr&0x7fe]);
950 ad = (addr << 16) + data;
952 if (hdsp_fifo_wait(hdsp, 127, HDSP_LONG_WAIT))
955 hdsp_write (hdsp, HDSP_fifoData, ad);
956 hdsp->mixer_matrix[addr] = data;
963 static int snd_hdsp_use_is_exclusive(struct hdsp *hdsp)
968 spin_lock_irqsave(&hdsp->lock, flags);
969 if ((hdsp->playback_pid != hdsp->capture_pid) &&
970 (hdsp->playback_pid >= 0) && (hdsp->capture_pid >= 0))
972 spin_unlock_irqrestore(&hdsp->lock, flags);
976 static int hdsp_spdif_sample_rate(struct hdsp *hdsp)
978 unsigned int status = hdsp_read(hdsp, HDSP_statusRegister);
979 unsigned int rate_bits = (status & HDSP_spdifFrequencyMask);
981 /* For the 9632, the mask is different */
982 if (hdsp->io_type == H9632)
983 rate_bits = (status & HDSP_spdifFrequencyMask_9632);
985 if (status & HDSP_SPDIFErrorFlag)
989 case HDSP_spdifFrequency32KHz: return 32000;
990 case HDSP_spdifFrequency44_1KHz: return 44100;
991 case HDSP_spdifFrequency48KHz: return 48000;
992 case HDSP_spdifFrequency64KHz: return 64000;
993 case HDSP_spdifFrequency88_2KHz: return 88200;
994 case HDSP_spdifFrequency96KHz: return 96000;
995 case HDSP_spdifFrequency128KHz:
996 if (hdsp->io_type == H9632) return 128000;
998 case HDSP_spdifFrequency176_4KHz:
999 if (hdsp->io_type == H9632) return 176400;
1001 case HDSP_spdifFrequency192KHz:
1002 if (hdsp->io_type == H9632) return 192000;
1007 dev_warn(hdsp->card->dev,
1008 "unknown spdif frequency status; bits = 0x%x, status = 0x%x\n",
1013 static int hdsp_external_sample_rate(struct hdsp *hdsp)
1015 unsigned int status2 = hdsp_read(hdsp, HDSP_status2Register);
1016 unsigned int rate_bits = status2 & HDSP_systemFrequencyMask;
1018 /* For the 9632 card, there seems to be no bit for indicating external
1019 * sample rate greater than 96kHz. The card reports the corresponding
1020 * single speed. So the best means seems to get spdif rate when
1021 * autosync reference is spdif */
1022 if (hdsp->io_type == H9632 &&
1023 hdsp_autosync_ref(hdsp) == HDSP_AUTOSYNC_FROM_SPDIF)
1024 return hdsp_spdif_sample_rate(hdsp);
1026 switch (rate_bits) {
1027 case HDSP_systemFrequency32: return 32000;
1028 case HDSP_systemFrequency44_1: return 44100;
1029 case HDSP_systemFrequency48: return 48000;
1030 case HDSP_systemFrequency64: return 64000;
1031 case HDSP_systemFrequency88_2: return 88200;
1032 case HDSP_systemFrequency96: return 96000;
1038 static void hdsp_compute_period_size(struct hdsp *hdsp)
1040 hdsp->period_bytes = 1 << ((hdsp_decode_latency(hdsp->control_register) + 8));
1043 static snd_pcm_uframes_t hdsp_hw_pointer(struct hdsp *hdsp)
1047 position = hdsp_read(hdsp, HDSP_statusRegister);
1049 if (!hdsp->precise_ptr)
1050 return (position & HDSP_BufferID) ? (hdsp->period_bytes / 4) : 0;
1052 position &= HDSP_BufferPositionMask;
1054 position &= (hdsp->period_bytes/2) - 1;
1058 static void hdsp_reset_hw_pointer(struct hdsp *hdsp)
1060 hdsp_write (hdsp, HDSP_resetPointer, 0);
1061 if (hdsp->io_type == H9632 && hdsp->firmware_rev >= 152)
1062 /* HDSP_resetPointer = HDSP_freqReg, which is strange and
1063 * requires (?) to write again DDS value after a reset pointer
1064 * (at least, it works like this) */
1065 hdsp_write (hdsp, HDSP_freqReg, hdsp->dds_value);
1068 static void hdsp_start_audio(struct hdsp *s)
1070 s->control_register |= (HDSP_AudioInterruptEnable | HDSP_Start);
1071 hdsp_write(s, HDSP_controlRegister, s->control_register);
1074 static void hdsp_stop_audio(struct hdsp *s)
1076 s->control_register &= ~(HDSP_Start | HDSP_AudioInterruptEnable);
1077 hdsp_write(s, HDSP_controlRegister, s->control_register);
1080 static void hdsp_silence_playback(struct hdsp *hdsp)
1082 memset(hdsp->playback_buffer, 0, HDSP_DMA_AREA_BYTES);
1085 static int hdsp_set_interrupt_interval(struct hdsp *s, unsigned int frames)
1089 spin_lock_irq(&s->lock);
1098 s->control_register &= ~HDSP_LatencyMask;
1099 s->control_register |= hdsp_encode_latency(n);
1101 hdsp_write(s, HDSP_controlRegister, s->control_register);
1103 hdsp_compute_period_size(s);
1105 spin_unlock_irq(&s->lock);
1110 static void hdsp_set_dds_value(struct hdsp *hdsp, int rate)
1116 else if (rate >= 56000)
1120 n = div_u64(n, rate);
1121 /* n should be less than 2^32 for being written to FREQ register */
1122 snd_BUG_ON(n >> 32);
1123 /* HDSP_freqReg and HDSP_resetPointer are the same, so keep the DDS
1124 value to write it after a reset */
1125 hdsp->dds_value = n;
1126 hdsp_write(hdsp, HDSP_freqReg, hdsp->dds_value);
1129 static int hdsp_set_rate(struct hdsp *hdsp, int rate, int called_internally)
1131 int reject_if_open = 0;
1135 /* ASSUMPTION: hdsp->lock is either held, or
1136 there is no need for it (e.g. during module
1140 if (!(hdsp->control_register & HDSP_ClockModeMaster)) {
1141 if (called_internally) {
1142 /* request from ctl or card initialization */
1143 dev_err(hdsp->card->dev,
1144 "device is not running as a clock master: cannot set sample rate.\n");
1147 /* hw_param request while in AutoSync mode */
1148 int external_freq = hdsp_external_sample_rate(hdsp);
1149 int spdif_freq = hdsp_spdif_sample_rate(hdsp);
1151 if ((spdif_freq == external_freq*2) && (hdsp_autosync_ref(hdsp) >= HDSP_AUTOSYNC_FROM_ADAT1))
1152 dev_info(hdsp->card->dev,
1153 "Detected ADAT in double speed mode\n");
1154 else if (hdsp->io_type == H9632 && (spdif_freq == external_freq*4) && (hdsp_autosync_ref(hdsp) >= HDSP_AUTOSYNC_FROM_ADAT1))
1155 dev_info(hdsp->card->dev,
1156 "Detected ADAT in quad speed mode\n");
1157 else if (rate != external_freq) {
1158 dev_info(hdsp->card->dev,
1159 "No AutoSync source for requested rate\n");
1165 current_rate = hdsp->system_sample_rate;
1167 /* Changing from a "single speed" to a "double speed" rate is
1168 not allowed if any substreams are open. This is because
1169 such a change causes a shift in the location of
1170 the DMA buffers and a reduction in the number of available
1173 Note that a similar but essentially insoluble problem
1174 exists for externally-driven rate changes. All we can do
1175 is to flag rate changes in the read/write routines. */
1177 if (rate > 96000 && hdsp->io_type != H9632)
1182 if (current_rate > 48000)
1184 rate_bits = HDSP_Frequency32KHz;
1187 if (current_rate > 48000)
1189 rate_bits = HDSP_Frequency44_1KHz;
1192 if (current_rate > 48000)
1194 rate_bits = HDSP_Frequency48KHz;
1197 if (current_rate <= 48000 || current_rate > 96000)
1199 rate_bits = HDSP_Frequency64KHz;
1202 if (current_rate <= 48000 || current_rate > 96000)
1204 rate_bits = HDSP_Frequency88_2KHz;
1207 if (current_rate <= 48000 || current_rate > 96000)
1209 rate_bits = HDSP_Frequency96KHz;
1212 if (current_rate < 128000)
1214 rate_bits = HDSP_Frequency128KHz;
1217 if (current_rate < 128000)
1219 rate_bits = HDSP_Frequency176_4KHz;
1222 if (current_rate < 128000)
1224 rate_bits = HDSP_Frequency192KHz;
1230 if (reject_if_open && (hdsp->capture_pid >= 0 || hdsp->playback_pid >= 0)) {
1231 dev_warn(hdsp->card->dev,
1232 "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.
1428 mod_timer(&hmidi->timer, 1 + jiffies);
1430 spin_unlock_irqrestore (&hmidi->lock, flags);
1433 static void snd_hdsp_midi_output_trigger(struct snd_rawmidi_substream *substream, int up)
1435 struct hdsp_midi *hmidi;
1436 unsigned long flags;
1438 hmidi = (struct hdsp_midi *) substream->rmidi->private_data;
1439 spin_lock_irqsave (&hmidi->lock, flags);
1441 if (!hmidi->istimer) {
1442 setup_timer(&hmidi->timer, snd_hdsp_midi_output_timer,
1443 (unsigned long) hmidi);
1444 mod_timer(&hmidi->timer, 1 + jiffies);
1448 if (hmidi->istimer && --hmidi->istimer <= 0)
1449 del_timer (&hmidi->timer);
1451 spin_unlock_irqrestore (&hmidi->lock, flags);
1453 snd_hdsp_midi_output_write(hmidi);
1456 static int snd_hdsp_midi_input_open(struct snd_rawmidi_substream *substream)
1458 struct hdsp_midi *hmidi;
1460 hmidi = (struct hdsp_midi *) substream->rmidi->private_data;
1461 spin_lock_irq (&hmidi->lock);
1462 snd_hdsp_flush_midi_input (hmidi->hdsp, hmidi->id);
1463 hmidi->input = substream;
1464 spin_unlock_irq (&hmidi->lock);
1469 static int snd_hdsp_midi_output_open(struct snd_rawmidi_substream *substream)
1471 struct hdsp_midi *hmidi;
1473 hmidi = (struct hdsp_midi *) substream->rmidi->private_data;
1474 spin_lock_irq (&hmidi->lock);
1475 hmidi->output = substream;
1476 spin_unlock_irq (&hmidi->lock);
1481 static int snd_hdsp_midi_input_close(struct snd_rawmidi_substream *substream)
1483 struct hdsp_midi *hmidi;
1485 snd_hdsp_midi_input_trigger (substream, 0);
1487 hmidi = (struct hdsp_midi *) substream->rmidi->private_data;
1488 spin_lock_irq (&hmidi->lock);
1489 hmidi->input = NULL;
1490 spin_unlock_irq (&hmidi->lock);
1495 static int snd_hdsp_midi_output_close(struct snd_rawmidi_substream *substream)
1497 struct hdsp_midi *hmidi;
1499 snd_hdsp_midi_output_trigger (substream, 0);
1501 hmidi = (struct hdsp_midi *) substream->rmidi->private_data;
1502 spin_lock_irq (&hmidi->lock);
1503 hmidi->output = NULL;
1504 spin_unlock_irq (&hmidi->lock);
1509 static struct snd_rawmidi_ops snd_hdsp_midi_output =
1511 .open = snd_hdsp_midi_output_open,
1512 .close = snd_hdsp_midi_output_close,
1513 .trigger = snd_hdsp_midi_output_trigger,
1516 static struct snd_rawmidi_ops snd_hdsp_midi_input =
1518 .open = snd_hdsp_midi_input_open,
1519 .close = snd_hdsp_midi_input_close,
1520 .trigger = snd_hdsp_midi_input_trigger,
1523 static int snd_hdsp_create_midi (struct snd_card *card, struct hdsp *hdsp, int id)
1527 hdsp->midi[id].id = id;
1528 hdsp->midi[id].rmidi = NULL;
1529 hdsp->midi[id].input = NULL;
1530 hdsp->midi[id].output = NULL;
1531 hdsp->midi[id].hdsp = hdsp;
1532 hdsp->midi[id].istimer = 0;
1533 hdsp->midi[id].pending = 0;
1534 spin_lock_init (&hdsp->midi[id].lock);
1536 snprintf(buf, sizeof(buf), "%s MIDI %d", card->shortname, id + 1);
1537 if (snd_rawmidi_new (card, buf, id, 1, 1, &hdsp->midi[id].rmidi) < 0)
1540 sprintf(hdsp->midi[id].rmidi->name, "HDSP MIDI %d", id+1);
1541 hdsp->midi[id].rmidi->private_data = &hdsp->midi[id];
1543 snd_rawmidi_set_ops (hdsp->midi[id].rmidi, SNDRV_RAWMIDI_STREAM_OUTPUT, &snd_hdsp_midi_output);
1544 snd_rawmidi_set_ops (hdsp->midi[id].rmidi, SNDRV_RAWMIDI_STREAM_INPUT, &snd_hdsp_midi_input);
1546 hdsp->midi[id].rmidi->info_flags |= SNDRV_RAWMIDI_INFO_OUTPUT |
1547 SNDRV_RAWMIDI_INFO_INPUT |
1548 SNDRV_RAWMIDI_INFO_DUPLEX;
1553 /*-----------------------------------------------------------------------------
1555 ----------------------------------------------------------------------------*/
1557 static u32 snd_hdsp_convert_from_aes(struct snd_aes_iec958 *aes)
1560 val |= (aes->status[0] & IEC958_AES0_PROFESSIONAL) ? HDSP_SPDIFProfessional : 0;
1561 val |= (aes->status[0] & IEC958_AES0_NONAUDIO) ? HDSP_SPDIFNonAudio : 0;
1562 if (val & HDSP_SPDIFProfessional)
1563 val |= (aes->status[0] & IEC958_AES0_PRO_EMPHASIS_5015) ? HDSP_SPDIFEmphasis : 0;
1565 val |= (aes->status[0] & IEC958_AES0_CON_EMPHASIS_5015) ? HDSP_SPDIFEmphasis : 0;
1569 static void snd_hdsp_convert_to_aes(struct snd_aes_iec958 *aes, u32 val)
1571 aes->status[0] = ((val & HDSP_SPDIFProfessional) ? IEC958_AES0_PROFESSIONAL : 0) |
1572 ((val & HDSP_SPDIFNonAudio) ? IEC958_AES0_NONAUDIO : 0);
1573 if (val & HDSP_SPDIFProfessional)
1574 aes->status[0] |= (val & HDSP_SPDIFEmphasis) ? IEC958_AES0_PRO_EMPHASIS_5015 : 0;
1576 aes->status[0] |= (val & HDSP_SPDIFEmphasis) ? IEC958_AES0_CON_EMPHASIS_5015 : 0;
1579 static int snd_hdsp_control_spdif_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
1581 uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
1586 static int snd_hdsp_control_spdif_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1588 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1590 snd_hdsp_convert_to_aes(&ucontrol->value.iec958, hdsp->creg_spdif);
1594 static int snd_hdsp_control_spdif_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1596 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1600 val = snd_hdsp_convert_from_aes(&ucontrol->value.iec958);
1601 spin_lock_irq(&hdsp->lock);
1602 change = val != hdsp->creg_spdif;
1603 hdsp->creg_spdif = val;
1604 spin_unlock_irq(&hdsp->lock);
1608 static int snd_hdsp_control_spdif_stream_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
1610 uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
1615 static int snd_hdsp_control_spdif_stream_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1617 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1619 snd_hdsp_convert_to_aes(&ucontrol->value.iec958, hdsp->creg_spdif_stream);
1623 static int snd_hdsp_control_spdif_stream_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1625 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1629 val = snd_hdsp_convert_from_aes(&ucontrol->value.iec958);
1630 spin_lock_irq(&hdsp->lock);
1631 change = val != hdsp->creg_spdif_stream;
1632 hdsp->creg_spdif_stream = val;
1633 hdsp->control_register &= ~(HDSP_SPDIFProfessional | HDSP_SPDIFNonAudio | HDSP_SPDIFEmphasis);
1634 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register |= val);
1635 spin_unlock_irq(&hdsp->lock);
1639 static int snd_hdsp_control_spdif_mask_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
1641 uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
1646 static int snd_hdsp_control_spdif_mask_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1648 ucontrol->value.iec958.status[0] = kcontrol->private_value;
1652 #define HDSP_SPDIF_IN(xname, xindex) \
1653 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1656 .info = snd_hdsp_info_spdif_in, \
1657 .get = snd_hdsp_get_spdif_in, \
1658 .put = snd_hdsp_put_spdif_in }
1660 static unsigned int hdsp_spdif_in(struct hdsp *hdsp)
1662 return hdsp_decode_spdif_in(hdsp->control_register & HDSP_SPDIFInputMask);
1665 static int hdsp_set_spdif_input(struct hdsp *hdsp, int in)
1667 hdsp->control_register &= ~HDSP_SPDIFInputMask;
1668 hdsp->control_register |= hdsp_encode_spdif_in(in);
1669 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
1673 static int snd_hdsp_info_spdif_in(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
1675 static const char * const texts[4] = {
1676 "Optical", "Coaxial", "Internal", "AES"
1678 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1680 return snd_ctl_enum_info(uinfo, 1, (hdsp->io_type == H9632) ? 4 : 3,
1684 static int snd_hdsp_get_spdif_in(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1686 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1688 ucontrol->value.enumerated.item[0] = hdsp_spdif_in(hdsp);
1692 static int snd_hdsp_put_spdif_in(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1694 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1698 if (!snd_hdsp_use_is_exclusive(hdsp))
1700 val = ucontrol->value.enumerated.item[0] % ((hdsp->io_type == H9632) ? 4 : 3);
1701 spin_lock_irq(&hdsp->lock);
1702 change = val != hdsp_spdif_in(hdsp);
1704 hdsp_set_spdif_input(hdsp, val);
1705 spin_unlock_irq(&hdsp->lock);
1709 #define HDSP_TOGGLE_SETTING(xname, xindex) \
1710 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1712 .private_value = xindex, \
1713 .info = snd_hdsp_info_toggle_setting, \
1714 .get = snd_hdsp_get_toggle_setting, \
1715 .put = snd_hdsp_put_toggle_setting \
1718 static int hdsp_toggle_setting(struct hdsp *hdsp, u32 regmask)
1720 return (hdsp->control_register & regmask) ? 1 : 0;
1723 static int hdsp_set_toggle_setting(struct hdsp *hdsp, u32 regmask, int out)
1726 hdsp->control_register |= regmask;
1728 hdsp->control_register &= ~regmask;
1729 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
1734 #define snd_hdsp_info_toggle_setting snd_ctl_boolean_mono_info
1736 static int snd_hdsp_get_toggle_setting(struct snd_kcontrol *kcontrol,
1737 struct snd_ctl_elem_value *ucontrol)
1739 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1740 u32 regmask = kcontrol->private_value;
1742 spin_lock_irq(&hdsp->lock);
1743 ucontrol->value.integer.value[0] = hdsp_toggle_setting(hdsp, regmask);
1744 spin_unlock_irq(&hdsp->lock);
1748 static int snd_hdsp_put_toggle_setting(struct snd_kcontrol *kcontrol,
1749 struct snd_ctl_elem_value *ucontrol)
1751 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1752 u32 regmask = kcontrol->private_value;
1756 if (!snd_hdsp_use_is_exclusive(hdsp))
1758 val = ucontrol->value.integer.value[0] & 1;
1759 spin_lock_irq(&hdsp->lock);
1760 change = (int) val != hdsp_toggle_setting(hdsp, regmask);
1762 hdsp_set_toggle_setting(hdsp, regmask, val);
1763 spin_unlock_irq(&hdsp->lock);
1767 #define HDSP_SPDIF_SAMPLE_RATE(xname, xindex) \
1768 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1771 .access = SNDRV_CTL_ELEM_ACCESS_READ, \
1772 .info = snd_hdsp_info_spdif_sample_rate, \
1773 .get = snd_hdsp_get_spdif_sample_rate \
1776 static int snd_hdsp_info_spdif_sample_rate(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
1778 static const char * const texts[] = {
1779 "32000", "44100", "48000", "64000", "88200", "96000",
1780 "None", "128000", "176400", "192000"
1782 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1784 return snd_ctl_enum_info(uinfo, 1, (hdsp->io_type == H9632) ? 10 : 7,
1788 static int snd_hdsp_get_spdif_sample_rate(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1790 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1792 switch (hdsp_spdif_sample_rate(hdsp)) {
1794 ucontrol->value.enumerated.item[0] = 0;
1797 ucontrol->value.enumerated.item[0] = 1;
1800 ucontrol->value.enumerated.item[0] = 2;
1803 ucontrol->value.enumerated.item[0] = 3;
1806 ucontrol->value.enumerated.item[0] = 4;
1809 ucontrol->value.enumerated.item[0] = 5;
1812 ucontrol->value.enumerated.item[0] = 7;
1815 ucontrol->value.enumerated.item[0] = 8;
1818 ucontrol->value.enumerated.item[0] = 9;
1821 ucontrol->value.enumerated.item[0] = 6;
1826 #define HDSP_SYSTEM_SAMPLE_RATE(xname, xindex) \
1827 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1830 .access = SNDRV_CTL_ELEM_ACCESS_READ, \
1831 .info = snd_hdsp_info_system_sample_rate, \
1832 .get = snd_hdsp_get_system_sample_rate \
1835 static int snd_hdsp_info_system_sample_rate(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
1837 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1842 static int snd_hdsp_get_system_sample_rate(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1844 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1846 ucontrol->value.enumerated.item[0] = hdsp->system_sample_rate;
1850 #define HDSP_AUTOSYNC_SAMPLE_RATE(xname, xindex) \
1851 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1854 .access = SNDRV_CTL_ELEM_ACCESS_READ, \
1855 .info = snd_hdsp_info_autosync_sample_rate, \
1856 .get = snd_hdsp_get_autosync_sample_rate \
1859 static int snd_hdsp_info_autosync_sample_rate(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
1861 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1862 static const char * const texts[] = {
1863 "32000", "44100", "48000", "64000", "88200", "96000",
1864 "None", "128000", "176400", "192000"
1867 return snd_ctl_enum_info(uinfo, 1, (hdsp->io_type == H9632) ? 10 : 7,
1871 static int snd_hdsp_get_autosync_sample_rate(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1873 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1875 switch (hdsp_external_sample_rate(hdsp)) {
1877 ucontrol->value.enumerated.item[0] = 0;
1880 ucontrol->value.enumerated.item[0] = 1;
1883 ucontrol->value.enumerated.item[0] = 2;
1886 ucontrol->value.enumerated.item[0] = 3;
1889 ucontrol->value.enumerated.item[0] = 4;
1892 ucontrol->value.enumerated.item[0] = 5;
1895 ucontrol->value.enumerated.item[0] = 7;
1898 ucontrol->value.enumerated.item[0] = 8;
1901 ucontrol->value.enumerated.item[0] = 9;
1904 ucontrol->value.enumerated.item[0] = 6;
1909 #define HDSP_SYSTEM_CLOCK_MODE(xname, xindex) \
1910 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1913 .access = SNDRV_CTL_ELEM_ACCESS_READ, \
1914 .info = snd_hdsp_info_system_clock_mode, \
1915 .get = snd_hdsp_get_system_clock_mode \
1918 static int hdsp_system_clock_mode(struct hdsp *hdsp)
1920 if (hdsp->control_register & HDSP_ClockModeMaster)
1922 else if (hdsp_external_sample_rate(hdsp) != hdsp->system_sample_rate)
1927 static int snd_hdsp_info_system_clock_mode(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
1929 static const char * const texts[] = {"Master", "Slave" };
1931 return snd_ctl_enum_info(uinfo, 1, 2, texts);
1934 static int snd_hdsp_get_system_clock_mode(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1936 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1938 ucontrol->value.enumerated.item[0] = hdsp_system_clock_mode(hdsp);
1942 #define HDSP_CLOCK_SOURCE(xname, xindex) \
1943 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1946 .info = snd_hdsp_info_clock_source, \
1947 .get = snd_hdsp_get_clock_source, \
1948 .put = snd_hdsp_put_clock_source \
1951 static int hdsp_clock_source(struct hdsp *hdsp)
1953 if (hdsp->control_register & HDSP_ClockModeMaster) {
1954 switch (hdsp->system_sample_rate) {
1981 static int hdsp_set_clock_source(struct hdsp *hdsp, int mode)
1985 case HDSP_CLOCK_SOURCE_AUTOSYNC:
1986 if (hdsp_external_sample_rate(hdsp) != 0) {
1987 if (!hdsp_set_rate(hdsp, hdsp_external_sample_rate(hdsp), 1)) {
1988 hdsp->control_register &= ~HDSP_ClockModeMaster;
1989 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
1994 case HDSP_CLOCK_SOURCE_INTERNAL_32KHZ:
1997 case HDSP_CLOCK_SOURCE_INTERNAL_44_1KHZ:
2000 case HDSP_CLOCK_SOURCE_INTERNAL_48KHZ:
2003 case HDSP_CLOCK_SOURCE_INTERNAL_64KHZ:
2006 case HDSP_CLOCK_SOURCE_INTERNAL_88_2KHZ:
2009 case HDSP_CLOCK_SOURCE_INTERNAL_96KHZ:
2012 case HDSP_CLOCK_SOURCE_INTERNAL_128KHZ:
2015 case HDSP_CLOCK_SOURCE_INTERNAL_176_4KHZ:
2018 case HDSP_CLOCK_SOURCE_INTERNAL_192KHZ:
2024 hdsp->control_register |= HDSP_ClockModeMaster;
2025 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
2026 hdsp_set_rate(hdsp, rate, 1);
2030 static int snd_hdsp_info_clock_source(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
2032 static const char * const texts[] = {
2033 "AutoSync", "Internal 32.0 kHz", "Internal 44.1 kHz",
2034 "Internal 48.0 kHz", "Internal 64.0 kHz", "Internal 88.2 kHz",
2035 "Internal 96.0 kHz", "Internal 128 kHz", "Internal 176.4 kHz",
2036 "Internal 192.0 KHz"
2038 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2040 return snd_ctl_enum_info(uinfo, 1, (hdsp->io_type == H9632) ? 10 : 7,
2044 static int snd_hdsp_get_clock_source(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2046 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2048 ucontrol->value.enumerated.item[0] = hdsp_clock_source(hdsp);
2052 static int snd_hdsp_put_clock_source(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2054 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2058 if (!snd_hdsp_use_is_exclusive(hdsp))
2060 val = ucontrol->value.enumerated.item[0];
2061 if (val < 0) val = 0;
2062 if (hdsp->io_type == H9632) {
2069 spin_lock_irq(&hdsp->lock);
2070 if (val != hdsp_clock_source(hdsp))
2071 change = (hdsp_set_clock_source(hdsp, val) == 0) ? 1 : 0;
2074 spin_unlock_irq(&hdsp->lock);
2078 #define snd_hdsp_info_clock_source_lock snd_ctl_boolean_mono_info
2080 static int snd_hdsp_get_clock_source_lock(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2082 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2084 ucontrol->value.integer.value[0] = hdsp->clock_source_locked;
2088 static int snd_hdsp_put_clock_source_lock(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2090 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2093 change = (int)ucontrol->value.integer.value[0] != hdsp->clock_source_locked;
2095 hdsp->clock_source_locked = !!ucontrol->value.integer.value[0];
2099 #define HDSP_DA_GAIN(xname, xindex) \
2100 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2103 .info = snd_hdsp_info_da_gain, \
2104 .get = snd_hdsp_get_da_gain, \
2105 .put = snd_hdsp_put_da_gain \
2108 static int hdsp_da_gain(struct hdsp *hdsp)
2110 switch (hdsp->control_register & HDSP_DAGainMask) {
2111 case HDSP_DAGainHighGain:
2113 case HDSP_DAGainPlus4dBu:
2115 case HDSP_DAGainMinus10dBV:
2122 static int hdsp_set_da_gain(struct hdsp *hdsp, int mode)
2124 hdsp->control_register &= ~HDSP_DAGainMask;
2127 hdsp->control_register |= HDSP_DAGainHighGain;
2130 hdsp->control_register |= HDSP_DAGainPlus4dBu;
2133 hdsp->control_register |= HDSP_DAGainMinus10dBV;
2139 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
2143 static int snd_hdsp_info_da_gain(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
2145 static const char * const texts[] = {"Hi Gain", "+4 dBu", "-10 dbV"};
2147 return snd_ctl_enum_info(uinfo, 1, 3, texts);
2150 static int snd_hdsp_get_da_gain(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2152 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2154 ucontrol->value.enumerated.item[0] = hdsp_da_gain(hdsp);
2158 static int snd_hdsp_put_da_gain(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2160 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2164 if (!snd_hdsp_use_is_exclusive(hdsp))
2166 val = ucontrol->value.enumerated.item[0];
2167 if (val < 0) val = 0;
2168 if (val > 2) val = 2;
2169 spin_lock_irq(&hdsp->lock);
2170 if (val != hdsp_da_gain(hdsp))
2171 change = (hdsp_set_da_gain(hdsp, val) == 0) ? 1 : 0;
2174 spin_unlock_irq(&hdsp->lock);
2178 #define HDSP_AD_GAIN(xname, xindex) \
2179 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2182 .info = snd_hdsp_info_ad_gain, \
2183 .get = snd_hdsp_get_ad_gain, \
2184 .put = snd_hdsp_put_ad_gain \
2187 static int hdsp_ad_gain(struct hdsp *hdsp)
2189 switch (hdsp->control_register & HDSP_ADGainMask) {
2190 case HDSP_ADGainMinus10dBV:
2192 case HDSP_ADGainPlus4dBu:
2194 case HDSP_ADGainLowGain:
2201 static int hdsp_set_ad_gain(struct hdsp *hdsp, int mode)
2203 hdsp->control_register &= ~HDSP_ADGainMask;
2206 hdsp->control_register |= HDSP_ADGainMinus10dBV;
2209 hdsp->control_register |= HDSP_ADGainPlus4dBu;
2212 hdsp->control_register |= HDSP_ADGainLowGain;
2218 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
2222 static int snd_hdsp_info_ad_gain(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
2224 static const char * const texts[] = {"-10 dBV", "+4 dBu", "Lo Gain"};
2226 return snd_ctl_enum_info(uinfo, 1, 3, texts);
2229 static int snd_hdsp_get_ad_gain(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2231 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2233 ucontrol->value.enumerated.item[0] = hdsp_ad_gain(hdsp);
2237 static int snd_hdsp_put_ad_gain(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2239 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2243 if (!snd_hdsp_use_is_exclusive(hdsp))
2245 val = ucontrol->value.enumerated.item[0];
2246 if (val < 0) val = 0;
2247 if (val > 2) val = 2;
2248 spin_lock_irq(&hdsp->lock);
2249 if (val != hdsp_ad_gain(hdsp))
2250 change = (hdsp_set_ad_gain(hdsp, val) == 0) ? 1 : 0;
2253 spin_unlock_irq(&hdsp->lock);
2257 #define HDSP_PHONE_GAIN(xname, xindex) \
2258 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2261 .info = snd_hdsp_info_phone_gain, \
2262 .get = snd_hdsp_get_phone_gain, \
2263 .put = snd_hdsp_put_phone_gain \
2266 static int hdsp_phone_gain(struct hdsp *hdsp)
2268 switch (hdsp->control_register & HDSP_PhoneGainMask) {
2269 case HDSP_PhoneGain0dB:
2271 case HDSP_PhoneGainMinus6dB:
2273 case HDSP_PhoneGainMinus12dB:
2280 static int hdsp_set_phone_gain(struct hdsp *hdsp, int mode)
2282 hdsp->control_register &= ~HDSP_PhoneGainMask;
2285 hdsp->control_register |= HDSP_PhoneGain0dB;
2288 hdsp->control_register |= HDSP_PhoneGainMinus6dB;
2291 hdsp->control_register |= HDSP_PhoneGainMinus12dB;
2297 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
2301 static int snd_hdsp_info_phone_gain(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
2303 static const char * const texts[] = {"0 dB", "-6 dB", "-12 dB"};
2305 return snd_ctl_enum_info(uinfo, 1, 3, texts);
2308 static int snd_hdsp_get_phone_gain(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2310 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2312 ucontrol->value.enumerated.item[0] = hdsp_phone_gain(hdsp);
2316 static int snd_hdsp_put_phone_gain(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2318 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2322 if (!snd_hdsp_use_is_exclusive(hdsp))
2324 val = ucontrol->value.enumerated.item[0];
2325 if (val < 0) val = 0;
2326 if (val > 2) val = 2;
2327 spin_lock_irq(&hdsp->lock);
2328 if (val != hdsp_phone_gain(hdsp))
2329 change = (hdsp_set_phone_gain(hdsp, val) == 0) ? 1 : 0;
2332 spin_unlock_irq(&hdsp->lock);
2336 #define HDSP_PREF_SYNC_REF(xname, xindex) \
2337 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2340 .info = snd_hdsp_info_pref_sync_ref, \
2341 .get = snd_hdsp_get_pref_sync_ref, \
2342 .put = snd_hdsp_put_pref_sync_ref \
2345 static int hdsp_pref_sync_ref(struct hdsp *hdsp)
2347 /* Notice that this looks at the requested sync source,
2348 not the one actually in use.
2351 switch (hdsp->control_register & HDSP_SyncRefMask) {
2352 case HDSP_SyncRef_ADAT1:
2353 return HDSP_SYNC_FROM_ADAT1;
2354 case HDSP_SyncRef_ADAT2:
2355 return HDSP_SYNC_FROM_ADAT2;
2356 case HDSP_SyncRef_ADAT3:
2357 return HDSP_SYNC_FROM_ADAT3;
2358 case HDSP_SyncRef_SPDIF:
2359 return HDSP_SYNC_FROM_SPDIF;
2360 case HDSP_SyncRef_WORD:
2361 return HDSP_SYNC_FROM_WORD;
2362 case HDSP_SyncRef_ADAT_SYNC:
2363 return HDSP_SYNC_FROM_ADAT_SYNC;
2365 return HDSP_SYNC_FROM_WORD;
2370 static int hdsp_set_pref_sync_ref(struct hdsp *hdsp, int pref)
2372 hdsp->control_register &= ~HDSP_SyncRefMask;
2374 case HDSP_SYNC_FROM_ADAT1:
2375 hdsp->control_register &= ~HDSP_SyncRefMask; /* clear SyncRef bits */
2377 case HDSP_SYNC_FROM_ADAT2:
2378 hdsp->control_register |= HDSP_SyncRef_ADAT2;
2380 case HDSP_SYNC_FROM_ADAT3:
2381 hdsp->control_register |= HDSP_SyncRef_ADAT3;
2383 case HDSP_SYNC_FROM_SPDIF:
2384 hdsp->control_register |= HDSP_SyncRef_SPDIF;
2386 case HDSP_SYNC_FROM_WORD:
2387 hdsp->control_register |= HDSP_SyncRef_WORD;
2389 case HDSP_SYNC_FROM_ADAT_SYNC:
2390 hdsp->control_register |= HDSP_SyncRef_ADAT_SYNC;
2395 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
2399 static int snd_hdsp_info_pref_sync_ref(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
2401 static const char * const texts[] = {
2402 "Word", "IEC958", "ADAT1", "ADAT Sync", "ADAT2", "ADAT3"
2404 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2407 switch (hdsp->io_type) {
2422 return snd_ctl_enum_info(uinfo, 1, num_items, texts);
2425 static int snd_hdsp_get_pref_sync_ref(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2427 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2429 ucontrol->value.enumerated.item[0] = hdsp_pref_sync_ref(hdsp);
2433 static int snd_hdsp_put_pref_sync_ref(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2435 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2439 if (!snd_hdsp_use_is_exclusive(hdsp))
2442 switch (hdsp->io_type) {
2457 val = ucontrol->value.enumerated.item[0] % max;
2458 spin_lock_irq(&hdsp->lock);
2459 change = (int)val != hdsp_pref_sync_ref(hdsp);
2460 hdsp_set_pref_sync_ref(hdsp, val);
2461 spin_unlock_irq(&hdsp->lock);
2465 #define HDSP_AUTOSYNC_REF(xname, xindex) \
2466 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2469 .access = SNDRV_CTL_ELEM_ACCESS_READ, \
2470 .info = snd_hdsp_info_autosync_ref, \
2471 .get = snd_hdsp_get_autosync_ref, \
2474 static int hdsp_autosync_ref(struct hdsp *hdsp)
2476 /* This looks at the autosync selected sync reference */
2477 unsigned int status2 = hdsp_read(hdsp, HDSP_status2Register);
2479 switch (status2 & HDSP_SelSyncRefMask) {
2480 case HDSP_SelSyncRef_WORD:
2481 return HDSP_AUTOSYNC_FROM_WORD;
2482 case HDSP_SelSyncRef_ADAT_SYNC:
2483 return HDSP_AUTOSYNC_FROM_ADAT_SYNC;
2484 case HDSP_SelSyncRef_SPDIF:
2485 return HDSP_AUTOSYNC_FROM_SPDIF;
2486 case HDSP_SelSyncRefMask:
2487 return HDSP_AUTOSYNC_FROM_NONE;
2488 case HDSP_SelSyncRef_ADAT1:
2489 return HDSP_AUTOSYNC_FROM_ADAT1;
2490 case HDSP_SelSyncRef_ADAT2:
2491 return HDSP_AUTOSYNC_FROM_ADAT2;
2492 case HDSP_SelSyncRef_ADAT3:
2493 return HDSP_AUTOSYNC_FROM_ADAT3;
2495 return HDSP_AUTOSYNC_FROM_WORD;
2500 static int snd_hdsp_info_autosync_ref(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
2502 static const char * const texts[] = {
2503 "Word", "ADAT Sync", "IEC958", "None", "ADAT1", "ADAT2", "ADAT3"
2506 return snd_ctl_enum_info(uinfo, 1, 7, texts);
2509 static int snd_hdsp_get_autosync_ref(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2511 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2513 ucontrol->value.enumerated.item[0] = hdsp_autosync_ref(hdsp);
2517 #define HDSP_PRECISE_POINTER(xname, xindex) \
2518 { .iface = SNDRV_CTL_ELEM_IFACE_CARD, \
2521 .info = snd_hdsp_info_precise_pointer, \
2522 .get = snd_hdsp_get_precise_pointer, \
2523 .put = snd_hdsp_put_precise_pointer \
2526 static int hdsp_set_precise_pointer(struct hdsp *hdsp, int precise)
2529 hdsp->precise_ptr = 1;
2531 hdsp->precise_ptr = 0;
2535 #define snd_hdsp_info_precise_pointer snd_ctl_boolean_mono_info
2537 static int snd_hdsp_get_precise_pointer(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2539 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2541 spin_lock_irq(&hdsp->lock);
2542 ucontrol->value.integer.value[0] = hdsp->precise_ptr;
2543 spin_unlock_irq(&hdsp->lock);
2547 static int snd_hdsp_put_precise_pointer(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2549 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2553 if (!snd_hdsp_use_is_exclusive(hdsp))
2555 val = ucontrol->value.integer.value[0] & 1;
2556 spin_lock_irq(&hdsp->lock);
2557 change = (int)val != hdsp->precise_ptr;
2558 hdsp_set_precise_pointer(hdsp, val);
2559 spin_unlock_irq(&hdsp->lock);
2563 #define HDSP_USE_MIDI_TASKLET(xname, xindex) \
2564 { .iface = SNDRV_CTL_ELEM_IFACE_CARD, \
2567 .info = snd_hdsp_info_use_midi_tasklet, \
2568 .get = snd_hdsp_get_use_midi_tasklet, \
2569 .put = snd_hdsp_put_use_midi_tasklet \
2572 static int hdsp_set_use_midi_tasklet(struct hdsp *hdsp, int use_tasklet)
2575 hdsp->use_midi_tasklet = 1;
2577 hdsp->use_midi_tasklet = 0;
2581 #define snd_hdsp_info_use_midi_tasklet snd_ctl_boolean_mono_info
2583 static int snd_hdsp_get_use_midi_tasklet(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2585 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2587 spin_lock_irq(&hdsp->lock);
2588 ucontrol->value.integer.value[0] = hdsp->use_midi_tasklet;
2589 spin_unlock_irq(&hdsp->lock);
2593 static int snd_hdsp_put_use_midi_tasklet(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2595 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2599 if (!snd_hdsp_use_is_exclusive(hdsp))
2601 val = ucontrol->value.integer.value[0] & 1;
2602 spin_lock_irq(&hdsp->lock);
2603 change = (int)val != hdsp->use_midi_tasklet;
2604 hdsp_set_use_midi_tasklet(hdsp, val);
2605 spin_unlock_irq(&hdsp->lock);
2609 #define HDSP_MIXER(xname, xindex) \
2610 { .iface = SNDRV_CTL_ELEM_IFACE_HWDEP, \
2614 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | \
2615 SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
2616 .info = snd_hdsp_info_mixer, \
2617 .get = snd_hdsp_get_mixer, \
2618 .put = snd_hdsp_put_mixer \
2621 static int snd_hdsp_info_mixer(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
2623 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
2625 uinfo->value.integer.min = 0;
2626 uinfo->value.integer.max = 65536;
2627 uinfo->value.integer.step = 1;
2631 static int snd_hdsp_get_mixer(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2633 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2638 source = ucontrol->value.integer.value[0];
2639 destination = ucontrol->value.integer.value[1];
2641 if (source >= hdsp->max_channels)
2642 addr = hdsp_playback_to_output_key(hdsp,source-hdsp->max_channels,destination);
2644 addr = hdsp_input_to_output_key(hdsp,source, destination);
2646 spin_lock_irq(&hdsp->lock);
2647 ucontrol->value.integer.value[2] = hdsp_read_gain (hdsp, addr);
2648 spin_unlock_irq(&hdsp->lock);
2652 static int snd_hdsp_put_mixer(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2654 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2661 if (!snd_hdsp_use_is_exclusive(hdsp))
2664 source = ucontrol->value.integer.value[0];
2665 destination = ucontrol->value.integer.value[1];
2667 if (source >= hdsp->max_channels)
2668 addr = hdsp_playback_to_output_key(hdsp,source-hdsp->max_channels, destination);
2670 addr = hdsp_input_to_output_key(hdsp,source, destination);
2672 gain = ucontrol->value.integer.value[2];
2674 spin_lock_irq(&hdsp->lock);
2675 change = gain != hdsp_read_gain(hdsp, addr);
2677 hdsp_write_gain(hdsp, addr, gain);
2678 spin_unlock_irq(&hdsp->lock);
2682 #define HDSP_WC_SYNC_CHECK(xname, xindex) \
2683 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2686 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
2687 .info = snd_hdsp_info_sync_check, \
2688 .get = snd_hdsp_get_wc_sync_check \
2691 static int snd_hdsp_info_sync_check(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
2693 static const char * const texts[] = {"No Lock", "Lock", "Sync" };
2695 return snd_ctl_enum_info(uinfo, 1, 3, texts);
2698 static int hdsp_wc_sync_check(struct hdsp *hdsp)
2700 int status2 = hdsp_read(hdsp, HDSP_status2Register);
2701 if (status2 & HDSP_wc_lock) {
2702 if (status2 & HDSP_wc_sync)
2711 static int snd_hdsp_get_wc_sync_check(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2713 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2715 ucontrol->value.enumerated.item[0] = hdsp_wc_sync_check(hdsp);
2719 #define HDSP_SPDIF_SYNC_CHECK(xname, xindex) \
2720 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2723 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
2724 .info = snd_hdsp_info_sync_check, \
2725 .get = snd_hdsp_get_spdif_sync_check \
2728 static int hdsp_spdif_sync_check(struct hdsp *hdsp)
2730 int status = hdsp_read(hdsp, HDSP_statusRegister);
2731 if (status & HDSP_SPDIFErrorFlag)
2734 if (status & HDSP_SPDIFSync)
2742 static int snd_hdsp_get_spdif_sync_check(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2744 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2746 ucontrol->value.enumerated.item[0] = hdsp_spdif_sync_check(hdsp);
2750 #define HDSP_ADATSYNC_SYNC_CHECK(xname, xindex) \
2751 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2754 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
2755 .info = snd_hdsp_info_sync_check, \
2756 .get = snd_hdsp_get_adatsync_sync_check \
2759 static int hdsp_adatsync_sync_check(struct hdsp *hdsp)
2761 int status = hdsp_read(hdsp, HDSP_statusRegister);
2762 if (status & HDSP_TimecodeLock) {
2763 if (status & HDSP_TimecodeSync)
2771 static int snd_hdsp_get_adatsync_sync_check(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2773 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2775 ucontrol->value.enumerated.item[0] = hdsp_adatsync_sync_check(hdsp);
2779 #define HDSP_ADAT_SYNC_CHECK \
2780 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2781 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
2782 .info = snd_hdsp_info_sync_check, \
2783 .get = snd_hdsp_get_adat_sync_check \
2786 static int hdsp_adat_sync_check(struct hdsp *hdsp, int idx)
2788 int status = hdsp_read(hdsp, HDSP_statusRegister);
2790 if (status & (HDSP_Lock0>>idx)) {
2791 if (status & (HDSP_Sync0>>idx))
2799 static int snd_hdsp_get_adat_sync_check(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2802 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2804 offset = ucontrol->id.index - 1;
2805 if (snd_BUG_ON(offset < 0))
2808 switch (hdsp->io_type) {
2823 ucontrol->value.enumerated.item[0] = hdsp_adat_sync_check(hdsp, offset);
2827 #define HDSP_DDS_OFFSET(xname, xindex) \
2828 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2831 .info = snd_hdsp_info_dds_offset, \
2832 .get = snd_hdsp_get_dds_offset, \
2833 .put = snd_hdsp_put_dds_offset \
2836 static int hdsp_dds_offset(struct hdsp *hdsp)
2839 unsigned int dds_value = hdsp->dds_value;
2840 int system_sample_rate = hdsp->system_sample_rate;
2847 * dds_value = n / rate
2848 * rate = n / dds_value
2850 n = div_u64(n, dds_value);
2851 if (system_sample_rate >= 112000)
2853 else if (system_sample_rate >= 56000)
2855 return ((int)n) - system_sample_rate;
2858 static int hdsp_set_dds_offset(struct hdsp *hdsp, int offset_hz)
2860 int rate = hdsp->system_sample_rate + offset_hz;
2861 hdsp_set_dds_value(hdsp, rate);
2865 static int snd_hdsp_info_dds_offset(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
2867 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
2869 uinfo->value.integer.min = -5000;
2870 uinfo->value.integer.max = 5000;
2874 static int snd_hdsp_get_dds_offset(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2876 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2878 ucontrol->value.integer.value[0] = hdsp_dds_offset(hdsp);
2882 static int snd_hdsp_put_dds_offset(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2884 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2888 if (!snd_hdsp_use_is_exclusive(hdsp))
2890 val = ucontrol->value.integer.value[0];
2891 spin_lock_irq(&hdsp->lock);
2892 if (val != hdsp_dds_offset(hdsp))
2893 change = (hdsp_set_dds_offset(hdsp, val) == 0) ? 1 : 0;
2896 spin_unlock_irq(&hdsp->lock);
2900 static struct snd_kcontrol_new snd_hdsp_9632_controls[] = {
2901 HDSP_DA_GAIN("DA Gain", 0),
2902 HDSP_AD_GAIN("AD Gain", 0),
2903 HDSP_PHONE_GAIN("Phones Gain", 0),
2904 HDSP_TOGGLE_SETTING("XLR Breakout Cable", HDSP_XLRBreakoutCable),
2905 HDSP_DDS_OFFSET("DDS Sample Rate Offset", 0)
2908 static struct snd_kcontrol_new snd_hdsp_controls[] = {
2910 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
2911 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,DEFAULT),
2912 .info = snd_hdsp_control_spdif_info,
2913 .get = snd_hdsp_control_spdif_get,
2914 .put = snd_hdsp_control_spdif_put,
2917 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_INACTIVE,
2918 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
2919 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,PCM_STREAM),
2920 .info = snd_hdsp_control_spdif_stream_info,
2921 .get = snd_hdsp_control_spdif_stream_get,
2922 .put = snd_hdsp_control_spdif_stream_put,
2925 .access = SNDRV_CTL_ELEM_ACCESS_READ,
2926 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
2927 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,CON_MASK),
2928 .info = snd_hdsp_control_spdif_mask_info,
2929 .get = snd_hdsp_control_spdif_mask_get,
2930 .private_value = IEC958_AES0_NONAUDIO |
2931 IEC958_AES0_PROFESSIONAL |
2932 IEC958_AES0_CON_EMPHASIS,
2935 .access = SNDRV_CTL_ELEM_ACCESS_READ,
2936 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
2937 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,PRO_MASK),
2938 .info = snd_hdsp_control_spdif_mask_info,
2939 .get = snd_hdsp_control_spdif_mask_get,
2940 .private_value = IEC958_AES0_NONAUDIO |
2941 IEC958_AES0_PROFESSIONAL |
2942 IEC958_AES0_PRO_EMPHASIS,
2944 HDSP_MIXER("Mixer", 0),
2945 HDSP_SPDIF_IN("IEC958 Input Connector", 0),
2946 HDSP_TOGGLE_SETTING("IEC958 Output also on ADAT1", HDSP_SPDIFOpticalOut),
2947 HDSP_TOGGLE_SETTING("IEC958 Professional Bit", HDSP_SPDIFProfessional),
2948 HDSP_TOGGLE_SETTING("IEC958 Emphasis Bit", HDSP_SPDIFEmphasis),
2949 HDSP_TOGGLE_SETTING("IEC958 Non-audio Bit", HDSP_SPDIFNonAudio),
2950 /* 'Sample Clock Source' complies with the alsa control naming scheme */
2951 HDSP_CLOCK_SOURCE("Sample Clock Source", 0),
2953 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2954 .name = "Sample Clock Source Locking",
2955 .info = snd_hdsp_info_clock_source_lock,
2956 .get = snd_hdsp_get_clock_source_lock,
2957 .put = snd_hdsp_put_clock_source_lock,
2959 HDSP_SYSTEM_CLOCK_MODE("System Clock Mode", 0),
2960 HDSP_PREF_SYNC_REF("Preferred Sync Reference", 0),
2961 HDSP_AUTOSYNC_REF("AutoSync Reference", 0),
2962 HDSP_SPDIF_SAMPLE_RATE("SPDIF Sample Rate", 0),
2963 HDSP_SYSTEM_SAMPLE_RATE("System Sample Rate", 0),
2964 /* 'External Rate' complies with the alsa control naming scheme */
2965 HDSP_AUTOSYNC_SAMPLE_RATE("External Rate", 0),
2966 HDSP_WC_SYNC_CHECK("Word Clock Lock Status", 0),
2967 HDSP_SPDIF_SYNC_CHECK("SPDIF Lock Status", 0),
2968 HDSP_ADATSYNC_SYNC_CHECK("ADAT Sync Lock Status", 0),
2969 HDSP_TOGGLE_SETTING("Line Out", HDSP_LineOut),
2970 HDSP_PRECISE_POINTER("Precise Pointer", 0),
2971 HDSP_USE_MIDI_TASKLET("Use Midi Tasklet", 0),
2975 static int hdsp_rpm_input12(struct hdsp *hdsp)
2977 switch (hdsp->control_register & HDSP_RPM_Inp12) {
2978 case HDSP_RPM_Inp12_Phon_6dB:
2980 case HDSP_RPM_Inp12_Phon_n6dB:
2982 case HDSP_RPM_Inp12_Line_0dB:
2984 case HDSP_RPM_Inp12_Line_n6dB:
2991 static int snd_hdsp_get_rpm_input12(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2993 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2995 ucontrol->value.enumerated.item[0] = hdsp_rpm_input12(hdsp);
3000 static int hdsp_set_rpm_input12(struct hdsp *hdsp, int mode)
3002 hdsp->control_register &= ~HDSP_RPM_Inp12;
3005 hdsp->control_register |= HDSP_RPM_Inp12_Phon_6dB;
3010 hdsp->control_register |= HDSP_RPM_Inp12_Phon_n6dB;
3013 hdsp->control_register |= HDSP_RPM_Inp12_Line_0dB;
3016 hdsp->control_register |= HDSP_RPM_Inp12_Line_n6dB;
3022 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
3027 static int snd_hdsp_put_rpm_input12(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
3029 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
3033 if (!snd_hdsp_use_is_exclusive(hdsp))
3035 val = ucontrol->value.enumerated.item[0];
3040 spin_lock_irq(&hdsp->lock);
3041 if (val != hdsp_rpm_input12(hdsp))
3042 change = (hdsp_set_rpm_input12(hdsp, val) == 0) ? 1 : 0;
3045 spin_unlock_irq(&hdsp->lock);
3050 static int snd_hdsp_info_rpm_input(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
3052 static const char * const texts[] = {
3053 "Phono +6dB", "Phono 0dB", "Phono -6dB", "Line 0dB", "Line -6dB"
3056 return snd_ctl_enum_info(uinfo, 1, 5, texts);
3060 static int hdsp_rpm_input34(struct hdsp *hdsp)
3062 switch (hdsp->control_register & HDSP_RPM_Inp34) {
3063 case HDSP_RPM_Inp34_Phon_6dB:
3065 case HDSP_RPM_Inp34_Phon_n6dB:
3067 case HDSP_RPM_Inp34_Line_0dB:
3069 case HDSP_RPM_Inp34_Line_n6dB:
3076 static int snd_hdsp_get_rpm_input34(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
3078 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
3080 ucontrol->value.enumerated.item[0] = hdsp_rpm_input34(hdsp);
3085 static int hdsp_set_rpm_input34(struct hdsp *hdsp, int mode)
3087 hdsp->control_register &= ~HDSP_RPM_Inp34;
3090 hdsp->control_register |= HDSP_RPM_Inp34_Phon_6dB;
3095 hdsp->control_register |= HDSP_RPM_Inp34_Phon_n6dB;
3098 hdsp->control_register |= HDSP_RPM_Inp34_Line_0dB;
3101 hdsp->control_register |= HDSP_RPM_Inp34_Line_n6dB;
3107 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
3112 static int snd_hdsp_put_rpm_input34(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
3114 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
3118 if (!snd_hdsp_use_is_exclusive(hdsp))
3120 val = ucontrol->value.enumerated.item[0];
3125 spin_lock_irq(&hdsp->lock);
3126 if (val != hdsp_rpm_input34(hdsp))
3127 change = (hdsp_set_rpm_input34(hdsp, val) == 0) ? 1 : 0;
3130 spin_unlock_irq(&hdsp->lock);
3135 /* RPM Bypass switch */
3136 static int hdsp_rpm_bypass(struct hdsp *hdsp)
3138 return (hdsp->control_register & HDSP_RPM_Bypass) ? 1 : 0;
3142 static int snd_hdsp_get_rpm_bypass(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
3144 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
3146 ucontrol->value.integer.value[0] = hdsp_rpm_bypass(hdsp);
3151 static int hdsp_set_rpm_bypass(struct hdsp *hdsp, int on)
3154 hdsp->control_register |= HDSP_RPM_Bypass;
3156 hdsp->control_register &= ~HDSP_RPM_Bypass;
3157 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
3162 static int snd_hdsp_put_rpm_bypass(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
3164 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
3168 if (!snd_hdsp_use_is_exclusive(hdsp))
3170 val = ucontrol->value.integer.value[0] & 1;
3171 spin_lock_irq(&hdsp->lock);
3172 change = (int)val != hdsp_rpm_bypass(hdsp);
3173 hdsp_set_rpm_bypass(hdsp, val);
3174 spin_unlock_irq(&hdsp->lock);
3179 static int snd_hdsp_info_rpm_bypass(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
3181 static const char * const texts[] = {"On", "Off"};
3183 return snd_ctl_enum_info(uinfo, 1, 2, texts);
3187 /* RPM Disconnect switch */
3188 static int hdsp_rpm_disconnect(struct hdsp *hdsp)
3190 return (hdsp->control_register & HDSP_RPM_Disconnect) ? 1 : 0;
3194 static int snd_hdsp_get_rpm_disconnect(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
3196 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
3198 ucontrol->value.integer.value[0] = hdsp_rpm_disconnect(hdsp);
3203 static int hdsp_set_rpm_disconnect(struct hdsp *hdsp, int on)
3206 hdsp->control_register |= HDSP_RPM_Disconnect;
3208 hdsp->control_register &= ~HDSP_RPM_Disconnect;
3209 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
3214 static int snd_hdsp_put_rpm_disconnect(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
3216 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
3220 if (!snd_hdsp_use_is_exclusive(hdsp))
3222 val = ucontrol->value.integer.value[0] & 1;
3223 spin_lock_irq(&hdsp->lock);
3224 change = (int)val != hdsp_rpm_disconnect(hdsp);
3225 hdsp_set_rpm_disconnect(hdsp, val);
3226 spin_unlock_irq(&hdsp->lock);
3230 static int snd_hdsp_info_rpm_disconnect(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
3232 static const char * const texts[] = {"On", "Off"};
3234 return snd_ctl_enum_info(uinfo, 1, 2, texts);
3237 static struct snd_kcontrol_new snd_hdsp_rpm_controls[] = {
3239 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3240 .name = "RPM Bypass",
3241 .get = snd_hdsp_get_rpm_bypass,
3242 .put = snd_hdsp_put_rpm_bypass,
3243 .info = snd_hdsp_info_rpm_bypass
3246 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3247 .name = "RPM Disconnect",
3248 .get = snd_hdsp_get_rpm_disconnect,
3249 .put = snd_hdsp_put_rpm_disconnect,
3250 .info = snd_hdsp_info_rpm_disconnect
3253 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3254 .name = "Input 1/2",
3255 .get = snd_hdsp_get_rpm_input12,
3256 .put = snd_hdsp_put_rpm_input12,
3257 .info = snd_hdsp_info_rpm_input
3260 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3261 .name = "Input 3/4",
3262 .get = snd_hdsp_get_rpm_input34,
3263 .put = snd_hdsp_put_rpm_input34,
3264 .info = snd_hdsp_info_rpm_input
3266 HDSP_SYSTEM_SAMPLE_RATE("System Sample Rate", 0),
3267 HDSP_MIXER("Mixer", 0)
3270 static struct snd_kcontrol_new snd_hdsp_96xx_aeb =
3271 HDSP_TOGGLE_SETTING("Analog Extension Board",
3272 HDSP_AnalogExtensionBoard);
3273 static struct snd_kcontrol_new snd_hdsp_adat_sync_check = HDSP_ADAT_SYNC_CHECK;
3275 static int snd_hdsp_create_controls(struct snd_card *card, struct hdsp *hdsp)
3279 struct snd_kcontrol *kctl;
3281 if (hdsp->io_type == RPM) {
3282 /* RPM Bypass, Disconnect and Input switches */
3283 for (idx = 0; idx < ARRAY_SIZE(snd_hdsp_rpm_controls); idx++) {
3284 err = snd_ctl_add(card, kctl = snd_ctl_new1(&snd_hdsp_rpm_controls[idx], hdsp));
3291 for (idx = 0; idx < ARRAY_SIZE(snd_hdsp_controls); idx++) {
3292 if ((err = snd_ctl_add(card, kctl = snd_ctl_new1(&snd_hdsp_controls[idx], hdsp))) < 0)
3294 if (idx == 1) /* IEC958 (S/PDIF) Stream */
3295 hdsp->spdif_ctl = kctl;
3298 /* ADAT SyncCheck status */
3299 snd_hdsp_adat_sync_check.name = "ADAT Lock Status";
3300 snd_hdsp_adat_sync_check.index = 1;
3301 if ((err = snd_ctl_add (card, kctl = snd_ctl_new1(&snd_hdsp_adat_sync_check, hdsp))))
3303 if (hdsp->io_type == Digiface || hdsp->io_type == H9652) {
3304 for (idx = 1; idx < 3; ++idx) {
3305 snd_hdsp_adat_sync_check.index = idx+1;
3306 if ((err = snd_ctl_add (card, kctl = snd_ctl_new1(&snd_hdsp_adat_sync_check, hdsp))))
3311 /* DA, AD and Phone gain and XLR breakout cable controls for H9632 cards */
3312 if (hdsp->io_type == H9632) {
3313 for (idx = 0; idx < ARRAY_SIZE(snd_hdsp_9632_controls); idx++) {
3314 if ((err = snd_ctl_add(card, kctl = snd_ctl_new1(&snd_hdsp_9632_controls[idx], hdsp))) < 0)
3319 /* AEB control for H96xx card */
3320 if (hdsp->io_type == H9632 || hdsp->io_type == H9652) {
3321 if ((err = snd_ctl_add(card, kctl = snd_ctl_new1(&snd_hdsp_96xx_aeb, hdsp))) < 0)
3328 /*------------------------------------------------------------
3330 ------------------------------------------------------------*/
3333 snd_hdsp_proc_read(struct snd_info_entry *entry, struct snd_info_buffer *buffer)
3335 struct hdsp *hdsp = entry->private_data;
3336 unsigned int status;
3337 unsigned int status2;
3338 char *pref_sync_ref;
3340 char *system_clock_mode;
3344 status = hdsp_read(hdsp, HDSP_statusRegister);
3345 status2 = hdsp_read(hdsp, HDSP_status2Register);
3347 snd_iprintf(buffer, "%s (Card #%d)\n", hdsp->card_name,
3348 hdsp->card->number + 1);
3349 snd_iprintf(buffer, "Buffers: capture %p playback %p\n",
3350 hdsp->capture_buffer, hdsp->playback_buffer);
3351 snd_iprintf(buffer, "IRQ: %d Registers bus: 0x%lx VM: 0x%lx\n",
3352 hdsp->irq, hdsp->port, (unsigned long)hdsp->iobase);
3353 snd_iprintf(buffer, "Control register: 0x%x\n", hdsp->control_register);
3354 snd_iprintf(buffer, "Control2 register: 0x%x\n",
3355 hdsp->control2_register);
3356 snd_iprintf(buffer, "Status register: 0x%x\n", status);
3357 snd_iprintf(buffer, "Status2 register: 0x%x\n", status2);
3359 if (hdsp_check_for_iobox(hdsp)) {
3360 snd_iprintf(buffer, "No I/O box connected.\n"
3361 "Please connect one and upload firmware.\n");
3365 if (hdsp_check_for_firmware(hdsp, 0)) {
3366 if (hdsp->state & HDSP_FirmwareCached) {
3367 if (snd_hdsp_load_firmware_from_cache(hdsp) != 0) {
3368 snd_iprintf(buffer, "Firmware loading from "
3370 "please upload manually.\n");
3375 err = hdsp_request_fw_loader(hdsp);
3378 "No firmware loaded nor cached, "
3379 "please upload firmware.\n");
3385 snd_iprintf(buffer, "FIFO status: %d\n", hdsp_read(hdsp, HDSP_fifoStatus) & 0xff);
3386 snd_iprintf(buffer, "MIDI1 Output status: 0x%x\n", hdsp_read(hdsp, HDSP_midiStatusOut0));
3387 snd_iprintf(buffer, "MIDI1 Input status: 0x%x\n", hdsp_read(hdsp, HDSP_midiStatusIn0));
3388 snd_iprintf(buffer, "MIDI2 Output status: 0x%x\n", hdsp_read(hdsp, HDSP_midiStatusOut1));
3389 snd_iprintf(buffer, "MIDI2 Input status: 0x%x\n", hdsp_read(hdsp, HDSP_midiStatusIn1));
3390 snd_iprintf(buffer, "Use Midi Tasklet: %s\n", hdsp->use_midi_tasklet ? "on" : "off");
3392 snd_iprintf(buffer, "\n");
3394 x = 1 << (6 + hdsp_decode_latency(hdsp->control_register & HDSP_LatencyMask));
3396 snd_iprintf(buffer, "Buffer Size (Latency): %d samples (2 periods of %lu bytes)\n", x, (unsigned long) hdsp->period_bytes);
3397 snd_iprintf(buffer, "Hardware pointer (frames): %ld\n", hdsp_hw_pointer(hdsp));
3398 snd_iprintf(buffer, "Precise pointer: %s\n", hdsp->precise_ptr ? "on" : "off");
3399 snd_iprintf(buffer, "Line out: %s\n", (hdsp->control_register & HDSP_LineOut) ? "on" : "off");
3401 snd_iprintf(buffer, "Firmware version: %d\n", (status2&HDSP_version0)|(status2&HDSP_version1)<<1|(status2&HDSP_version2)<<2);
3403 snd_iprintf(buffer, "\n");
3405 switch (hdsp_clock_source(hdsp)) {
3406 case HDSP_CLOCK_SOURCE_AUTOSYNC:
3407 clock_source = "AutoSync";
3409 case HDSP_CLOCK_SOURCE_INTERNAL_32KHZ:
3410 clock_source = "Internal 32 kHz";
3412 case HDSP_CLOCK_SOURCE_INTERNAL_44_1KHZ:
3413 clock_source = "Internal 44.1 kHz";
3415 case HDSP_CLOCK_SOURCE_INTERNAL_48KHZ:
3416 clock_source = "Internal 48 kHz";
3418 case HDSP_CLOCK_SOURCE_INTERNAL_64KHZ:
3419 clock_source = "Internal 64 kHz";
3421 case HDSP_CLOCK_SOURCE_INTERNAL_88_2KHZ:
3422 clock_source = "Internal 88.2 kHz";
3424 case HDSP_CLOCK_SOURCE_INTERNAL_96KHZ:
3425 clock_source = "Internal 96 kHz";
3427 case HDSP_CLOCK_SOURCE_INTERNAL_128KHZ:
3428 clock_source = "Internal 128 kHz";
3430 case HDSP_CLOCK_SOURCE_INTERNAL_176_4KHZ:
3431 clock_source = "Internal 176.4 kHz";
3433 case HDSP_CLOCK_SOURCE_INTERNAL_192KHZ:
3434 clock_source = "Internal 192 kHz";
3437 clock_source = "Error";
3439 snd_iprintf (buffer, "Sample Clock Source: %s\n", clock_source);
3441 if (hdsp_system_clock_mode(hdsp))
3442 system_clock_mode = "Slave";
3444 system_clock_mode = "Master";
3446 switch (hdsp_pref_sync_ref (hdsp)) {
3447 case HDSP_SYNC_FROM_WORD:
3448 pref_sync_ref = "Word Clock";
3450 case HDSP_SYNC_FROM_ADAT_SYNC:
3451 pref_sync_ref = "ADAT Sync";
3453 case HDSP_SYNC_FROM_SPDIF:
3454 pref_sync_ref = "SPDIF";
3456 case HDSP_SYNC_FROM_ADAT1:
3457 pref_sync_ref = "ADAT1";
3459 case HDSP_SYNC_FROM_ADAT2:
3460 pref_sync_ref = "ADAT2";
3462 case HDSP_SYNC_FROM_ADAT3:
3463 pref_sync_ref = "ADAT3";
3466 pref_sync_ref = "Word Clock";
3469 snd_iprintf (buffer, "Preferred Sync Reference: %s\n", pref_sync_ref);
3471 switch (hdsp_autosync_ref (hdsp)) {
3472 case HDSP_AUTOSYNC_FROM_WORD:
3473 autosync_ref = "Word Clock";
3475 case HDSP_AUTOSYNC_FROM_ADAT_SYNC:
3476 autosync_ref = "ADAT Sync";
3478 case HDSP_AUTOSYNC_FROM_SPDIF:
3479 autosync_ref = "SPDIF";
3481 case HDSP_AUTOSYNC_FROM_NONE:
3482 autosync_ref = "None";
3484 case HDSP_AUTOSYNC_FROM_ADAT1:
3485 autosync_ref = "ADAT1";
3487 case HDSP_AUTOSYNC_FROM_ADAT2:
3488 autosync_ref = "ADAT2";
3490 case HDSP_AUTOSYNC_FROM_ADAT3:
3491 autosync_ref = "ADAT3";
3494 autosync_ref = "---";
3497 snd_iprintf (buffer, "AutoSync Reference: %s\n", autosync_ref);
3499 snd_iprintf (buffer, "AutoSync Frequency: %d\n", hdsp_external_sample_rate(hdsp));
3501 snd_iprintf (buffer, "System Clock Mode: %s\n", system_clock_mode);
3503 snd_iprintf (buffer, "System Clock Frequency: %d\n", hdsp->system_sample_rate);
3504 snd_iprintf (buffer, "System Clock Locked: %s\n", hdsp->clock_source_locked ? "Yes" : "No");
3506 snd_iprintf(buffer, "\n");
3508 if (hdsp->io_type != RPM) {
3509 switch (hdsp_spdif_in(hdsp)) {
3510 case HDSP_SPDIFIN_OPTICAL:
3511 snd_iprintf(buffer, "IEC958 input: Optical\n");
3513 case HDSP_SPDIFIN_COAXIAL:
3514 snd_iprintf(buffer, "IEC958 input: Coaxial\n");
3516 case HDSP_SPDIFIN_INTERNAL:
3517 snd_iprintf(buffer, "IEC958 input: Internal\n");
3519 case HDSP_SPDIFIN_AES:
3520 snd_iprintf(buffer, "IEC958 input: AES\n");
3523 snd_iprintf(buffer, "IEC958 input: ???\n");
3528 if (RPM == hdsp->io_type) {
3529 if (hdsp->control_register & HDSP_RPM_Bypass)
3530 snd_iprintf(buffer, "RPM Bypass: disabled\n");
3532 snd_iprintf(buffer, "RPM Bypass: enabled\n");
3533 if (hdsp->control_register & HDSP_RPM_Disconnect)
3534 snd_iprintf(buffer, "RPM disconnected\n");
3536 snd_iprintf(buffer, "RPM connected\n");
3538 switch (hdsp->control_register & HDSP_RPM_Inp12) {
3539 case HDSP_RPM_Inp12_Phon_6dB:
3540 snd_iprintf(buffer, "Input 1/2: Phono, 6dB\n");
3542 case HDSP_RPM_Inp12_Phon_0dB:
3543 snd_iprintf(buffer, "Input 1/2: Phono, 0dB\n");
3545 case HDSP_RPM_Inp12_Phon_n6dB:
3546 snd_iprintf(buffer, "Input 1/2: Phono, -6dB\n");
3548 case HDSP_RPM_Inp12_Line_0dB:
3549 snd_iprintf(buffer, "Input 1/2: Line, 0dB\n");
3551 case HDSP_RPM_Inp12_Line_n6dB:
3552 snd_iprintf(buffer, "Input 1/2: Line, -6dB\n");
3555 snd_iprintf(buffer, "Input 1/2: ???\n");
3558 switch (hdsp->control_register & HDSP_RPM_Inp34) {
3559 case HDSP_RPM_Inp34_Phon_6dB:
3560 snd_iprintf(buffer, "Input 3/4: Phono, 6dB\n");
3562 case HDSP_RPM_Inp34_Phon_0dB:
3563 snd_iprintf(buffer, "Input 3/4: Phono, 0dB\n");
3565 case HDSP_RPM_Inp34_Phon_n6dB:
3566 snd_iprintf(buffer, "Input 3/4: Phono, -6dB\n");
3568 case HDSP_RPM_Inp34_Line_0dB:
3569 snd_iprintf(buffer, "Input 3/4: Line, 0dB\n");
3571 case HDSP_RPM_Inp34_Line_n6dB:
3572 snd_iprintf(buffer, "Input 3/4: Line, -6dB\n");
3575 snd_iprintf(buffer, "Input 3/4: ???\n");
3579 if (hdsp->control_register & HDSP_SPDIFOpticalOut)
3580 snd_iprintf(buffer, "IEC958 output: Coaxial & ADAT1\n");
3582 snd_iprintf(buffer, "IEC958 output: Coaxial only\n");
3584 if (hdsp->control_register & HDSP_SPDIFProfessional)
3585 snd_iprintf(buffer, "IEC958 quality: Professional\n");
3587 snd_iprintf(buffer, "IEC958 quality: Consumer\n");
3589 if (hdsp->control_register & HDSP_SPDIFEmphasis)
3590 snd_iprintf(buffer, "IEC958 emphasis: on\n");
3592 snd_iprintf(buffer, "IEC958 emphasis: off\n");
3594 if (hdsp->control_register & HDSP_SPDIFNonAudio)
3595 snd_iprintf(buffer, "IEC958 NonAudio: on\n");
3597 snd_iprintf(buffer, "IEC958 NonAudio: off\n");
3598 x = hdsp_spdif_sample_rate(hdsp);
3600 snd_iprintf(buffer, "IEC958 sample rate: %d\n", x);
3602 snd_iprintf(buffer, "IEC958 sample rate: Error flag set\n");
3604 snd_iprintf(buffer, "\n");
3607 x = status & HDSP_Sync0;
3608 if (status & HDSP_Lock0)
3609 snd_iprintf(buffer, "ADAT1: %s\n", x ? "Sync" : "Lock");
3611 snd_iprintf(buffer, "ADAT1: No Lock\n");
3613 switch (hdsp->io_type) {
3616 x = status & HDSP_Sync1;
3617 if (status & HDSP_Lock1)
3618 snd_iprintf(buffer, "ADAT2: %s\n", x ? "Sync" : "Lock");
3620 snd_iprintf(buffer, "ADAT2: No Lock\n");
3621 x = status & HDSP_Sync2;
3622 if (status & HDSP_Lock2)
3623 snd_iprintf(buffer, "ADAT3: %s\n", x ? "Sync" : "Lock");
3625 snd_iprintf(buffer, "ADAT3: No Lock\n");
3632 x = status & HDSP_SPDIFSync;
3633 if (status & HDSP_SPDIFErrorFlag)
3634 snd_iprintf (buffer, "SPDIF: No Lock\n");
3636 snd_iprintf (buffer, "SPDIF: %s\n", x ? "Sync" : "Lock");
3638 x = status2 & HDSP_wc_sync;
3639 if (status2 & HDSP_wc_lock)
3640 snd_iprintf (buffer, "Word Clock: %s\n", x ? "Sync" : "Lock");
3642 snd_iprintf (buffer, "Word Clock: No Lock\n");
3644 x = status & HDSP_TimecodeSync;
3645 if (status & HDSP_TimecodeLock)
3646 snd_iprintf(buffer, "ADAT Sync: %s\n", x ? "Sync" : "Lock");
3648 snd_iprintf(buffer, "ADAT Sync: No Lock\n");
3650 snd_iprintf(buffer, "\n");
3652 /* Informations about H9632 specific controls */
3653 if (hdsp->io_type == H9632) {
3656 switch (hdsp_ad_gain(hdsp)) {
3667 snd_iprintf(buffer, "AD Gain : %s\n", tmp);
3669 switch (hdsp_da_gain(hdsp)) {
3680 snd_iprintf(buffer, "DA Gain : %s\n", tmp);
3682 switch (hdsp_phone_gain(hdsp)) {
3693 snd_iprintf(buffer, "Phones Gain : %s\n", tmp);
3695 snd_iprintf(buffer, "XLR Breakout Cable : %s\n",
3696 hdsp_toggle_setting(hdsp, HDSP_XLRBreakoutCable) ?
3699 if (hdsp->control_register & HDSP_AnalogExtensionBoard)
3700 snd_iprintf(buffer, "AEB : on (ADAT1 internal)\n");
3702 snd_iprintf(buffer, "AEB : off (ADAT1 external)\n");
3703 snd_iprintf(buffer, "\n");
3708 static void snd_hdsp_proc_init(struct hdsp *hdsp)
3710 struct snd_info_entry *entry;
3712 if (! snd_card_proc_new(hdsp->card, "hdsp", &entry))
3713 snd_info_set_text_ops(entry, hdsp, snd_hdsp_proc_read);
3716 static void snd_hdsp_free_buffers(struct hdsp *hdsp)
3718 snd_hammerfall_free_buffer(&hdsp->capture_dma_buf, hdsp->pci);
3719 snd_hammerfall_free_buffer(&hdsp->playback_dma_buf, hdsp->pci);
3722 static int snd_hdsp_initialize_memory(struct hdsp *hdsp)
3724 unsigned long pb_bus, cb_bus;
3726 if (snd_hammerfall_get_buffer(hdsp->pci, &hdsp->capture_dma_buf, HDSP_DMA_AREA_BYTES) < 0 ||
3727 snd_hammerfall_get_buffer(hdsp->pci, &hdsp->playback_dma_buf, HDSP_DMA_AREA_BYTES) < 0) {
3728 if (hdsp->capture_dma_buf.area)
3729 snd_dma_free_pages(&hdsp->capture_dma_buf);
3730 dev_err(hdsp->card->dev,
3731 "%s: no buffers available\n", hdsp->card_name);
3735 /* Align to bus-space 64K boundary */
3737 cb_bus = ALIGN(hdsp->capture_dma_buf.addr, 0x10000ul);
3738 pb_bus = ALIGN(hdsp->playback_dma_buf.addr, 0x10000ul);
3740 /* Tell the card where it is */
3742 hdsp_write(hdsp, HDSP_inputBufferAddress, cb_bus);
3743 hdsp_write(hdsp, HDSP_outputBufferAddress, pb_bus);
3745 hdsp->capture_buffer = hdsp->capture_dma_buf.area + (cb_bus - hdsp->capture_dma_buf.addr);
3746 hdsp->playback_buffer = hdsp->playback_dma_buf.area + (pb_bus - hdsp->playback_dma_buf.addr);
3751 static int snd_hdsp_set_defaults(struct hdsp *hdsp)
3755 /* ASSUMPTION: hdsp->lock is either held, or
3756 there is no need to hold it (e.g. during module
3762 SPDIF Input via Coax
3764 maximum latency (7 => 2^7 = 8192 samples, 64Kbyte buffer,
3765 which implies 2 4096 sample, 32Kbyte periods).
3769 hdsp->control_register = HDSP_ClockModeMaster |
3770 HDSP_SPDIFInputCoaxial |
3771 hdsp_encode_latency(7) |
3775 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
3777 #ifdef SNDRV_BIG_ENDIAN
3778 hdsp->control2_register = HDSP_BIGENDIAN_MODE;
3780 hdsp->control2_register = 0;
3782 if (hdsp->io_type == H9652)
3783 snd_hdsp_9652_enable_mixer (hdsp);
3785 hdsp_write (hdsp, HDSP_control2Reg, hdsp->control2_register);
3787 hdsp_reset_hw_pointer(hdsp);
3788 hdsp_compute_period_size(hdsp);
3790 /* silence everything */
3792 for (i = 0; i < HDSP_MATRIX_MIXER_SIZE; ++i)
3793 hdsp->mixer_matrix[i] = MINUS_INFINITY_GAIN;
3795 for (i = 0; i < ((hdsp->io_type == H9652 || hdsp->io_type == H9632) ? 1352 : HDSP_MATRIX_MIXER_SIZE); ++i) {
3796 if (hdsp_write_gain (hdsp, i, MINUS_INFINITY_GAIN))
3800 /* H9632 specific defaults */
3801 if (hdsp->io_type == H9632) {
3802 hdsp->control_register |= (HDSP_DAGainPlus4dBu | HDSP_ADGainPlus4dBu | HDSP_PhoneGain0dB);
3803 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
3806 /* set a default rate so that the channel map is set up.
3809 hdsp_set_rate(hdsp, 48000, 1);
3814 static void hdsp_midi_tasklet(unsigned long arg)
3816 struct hdsp *hdsp = (struct hdsp *)arg;
3818 if (hdsp->midi[0].pending)
3819 snd_hdsp_midi_input_read (&hdsp->midi[0]);
3820 if (hdsp->midi[1].pending)
3821 snd_hdsp_midi_input_read (&hdsp->midi[1]);
3824 static irqreturn_t snd_hdsp_interrupt(int irq, void *dev_id)
3826 struct hdsp *hdsp = (struct hdsp *) dev_id;
3827 unsigned int status;
3831 unsigned int midi0status;
3832 unsigned int midi1status;
3835 status = hdsp_read(hdsp, HDSP_statusRegister);
3837 audio = status & HDSP_audioIRQPending;
3838 midi0 = status & HDSP_midi0IRQPending;
3839 midi1 = status & HDSP_midi1IRQPending;
3841 if (!audio && !midi0 && !midi1)
3844 hdsp_write(hdsp, HDSP_interruptConfirmation, 0);
3846 midi0status = hdsp_read (hdsp, HDSP_midiStatusIn0) & 0xff;
3847 midi1status = hdsp_read (hdsp, HDSP_midiStatusIn1) & 0xff;
3849 if (!(hdsp->state & HDSP_InitializationComplete))
3853 if (hdsp->capture_substream)
3854 snd_pcm_period_elapsed(hdsp->pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream);
3856 if (hdsp->playback_substream)
3857 snd_pcm_period_elapsed(hdsp->pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream);
3860 if (midi0 && midi0status) {
3861 if (hdsp->use_midi_tasklet) {
3862 /* we disable interrupts for this input until processing is done */
3863 hdsp->control_register &= ~HDSP_Midi0InterruptEnable;
3864 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
3865 hdsp->midi[0].pending = 1;
3868 snd_hdsp_midi_input_read (&hdsp->midi[0]);
3871 if (hdsp->io_type != Multiface && hdsp->io_type != RPM && hdsp->io_type != H9632 && midi1 && midi1status) {
3872 if (hdsp->use_midi_tasklet) {
3873 /* we disable interrupts for this input until processing is done */
3874 hdsp->control_register &= ~HDSP_Midi1InterruptEnable;
3875 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
3876 hdsp->midi[1].pending = 1;
3879 snd_hdsp_midi_input_read (&hdsp->midi[1]);
3882 if (hdsp->use_midi_tasklet && schedule)
3883 tasklet_schedule(&hdsp->midi_tasklet);
3887 static snd_pcm_uframes_t snd_hdsp_hw_pointer(struct snd_pcm_substream *substream)
3889 struct hdsp *hdsp = snd_pcm_substream_chip(substream);
3890 return hdsp_hw_pointer(hdsp);
3893 static char *hdsp_channel_buffer_location(struct hdsp *hdsp,
3900 if (snd_BUG_ON(channel < 0 || channel >= hdsp->max_channels))
3903 if ((mapped_channel = hdsp->channel_map[channel]) < 0)
3906 if (stream == SNDRV_PCM_STREAM_CAPTURE)
3907 return hdsp->capture_buffer + (mapped_channel * HDSP_CHANNEL_BUFFER_BYTES);
3909 return hdsp->playback_buffer + (mapped_channel * HDSP_CHANNEL_BUFFER_BYTES);
3912 static int snd_hdsp_playback_copy(struct snd_pcm_substream *substream, int channel,
3913 snd_pcm_uframes_t pos, void __user *src, snd_pcm_uframes_t count)
3915 struct hdsp *hdsp = snd_pcm_substream_chip(substream);
3918 if (snd_BUG_ON(pos + count > HDSP_CHANNEL_BUFFER_BYTES / 4))
3921 channel_buf = hdsp_channel_buffer_location (hdsp, substream->pstr->stream, channel);
3922 if (snd_BUG_ON(!channel_buf))
3924 if (copy_from_user(channel_buf + pos * 4, src, count * 4))
3929 static int snd_hdsp_capture_copy(struct snd_pcm_substream *substream, int channel,
3930 snd_pcm_uframes_t pos, void __user *dst, snd_pcm_uframes_t count)
3932 struct hdsp *hdsp = snd_pcm_substream_chip(substream);
3935 if (snd_BUG_ON(pos + count > HDSP_CHANNEL_BUFFER_BYTES / 4))
3938 channel_buf = hdsp_channel_buffer_location (hdsp, substream->pstr->stream, channel);
3939 if (snd_BUG_ON(!channel_buf))
3941 if (copy_to_user(dst, channel_buf + pos * 4, count * 4))
3946 static int snd_hdsp_hw_silence(struct snd_pcm_substream *substream, int channel,
3947 snd_pcm_uframes_t pos, snd_pcm_uframes_t count)
3949 struct hdsp *hdsp = snd_pcm_substream_chip(substream);
3952 channel_buf = hdsp_channel_buffer_location (hdsp, substream->pstr->stream, channel);
3953 if (snd_BUG_ON(!channel_buf))
3955 memset(channel_buf + pos * 4, 0, count * 4);
3959 static int snd_hdsp_reset(struct snd_pcm_substream *substream)
3961 struct snd_pcm_runtime *runtime = substream->runtime;
3962 struct hdsp *hdsp = snd_pcm_substream_chip(substream);
3963 struct snd_pcm_substream *other;
3964 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
3965 other = hdsp->capture_substream;
3967 other = hdsp->playback_substream;
3969 runtime->status->hw_ptr = hdsp_hw_pointer(hdsp);
3971 runtime->status->hw_ptr = 0;
3973 struct snd_pcm_substream *s;
3974 struct snd_pcm_runtime *oruntime = other->runtime;
3975 snd_pcm_group_for_each_entry(s, substream) {
3977 oruntime->status->hw_ptr = runtime->status->hw_ptr;
3985 static int snd_hdsp_hw_params(struct snd_pcm_substream *substream,
3986 struct snd_pcm_hw_params *params)
3988 struct hdsp *hdsp = snd_pcm_substream_chip(substream);
3993 if (hdsp_check_for_iobox (hdsp))
3996 if (hdsp_check_for_firmware(hdsp, 1))
3999 spin_lock_irq(&hdsp->lock);
4001 if (substream->pstr->stream == SNDRV_PCM_STREAM_PLAYBACK) {
4002 hdsp->control_register &= ~(HDSP_SPDIFProfessional | HDSP_SPDIFNonAudio | HDSP_SPDIFEmphasis);
4003 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register |= hdsp->creg_spdif_stream);
4004 this_pid = hdsp->playback_pid;
4005 other_pid = hdsp->capture_pid;
4007 this_pid = hdsp->capture_pid;
4008 other_pid = hdsp->playback_pid;
4011 if ((other_pid > 0) && (this_pid != other_pid)) {
4013 /* The other stream is open, and not by the same
4014 task as this one. Make sure that the parameters
4015 that matter are the same.
4018 if (params_rate(params) != hdsp->system_sample_rate) {
4019 spin_unlock_irq(&hdsp->lock);
4020 _snd_pcm_hw_param_setempty(params, SNDRV_PCM_HW_PARAM_RATE);
4024 if (params_period_size(params) != hdsp->period_bytes / 4) {
4025 spin_unlock_irq(&hdsp->lock);
4026 _snd_pcm_hw_param_setempty(params, SNDRV_PCM_HW_PARAM_PERIOD_SIZE);
4032 spin_unlock_irq(&hdsp->lock);
4036 spin_unlock_irq(&hdsp->lock);
4039 /* how to make sure that the rate matches an externally-set one ?
4042 spin_lock_irq(&hdsp->lock);
4043 if (! hdsp->clock_source_locked) {
4044 if ((err = hdsp_set_rate(hdsp, params_rate(params), 0)) < 0) {
4045 spin_unlock_irq(&hdsp->lock);
4046 _snd_pcm_hw_param_setempty(params, SNDRV_PCM_HW_PARAM_RATE);
4050 spin_unlock_irq(&hdsp->lock);
4052 if ((err = hdsp_set_interrupt_interval(hdsp, params_period_size(params))) < 0) {
4053 _snd_pcm_hw_param_setempty(params, SNDRV_PCM_HW_PARAM_PERIOD_SIZE);
4060 static int snd_hdsp_channel_info(struct snd_pcm_substream *substream,
4061 struct snd_pcm_channel_info *info)
4063 struct hdsp *hdsp = snd_pcm_substream_chip(substream);
4066 if (snd_BUG_ON(info->channel >= hdsp->max_channels))
4069 if ((mapped_channel = hdsp->channel_map[info->channel]) < 0)
4072 info->offset = mapped_channel * HDSP_CHANNEL_BUFFER_BYTES;
4078 static int snd_hdsp_ioctl(struct snd_pcm_substream *substream,
4079 unsigned int cmd, void *arg)
4082 case SNDRV_PCM_IOCTL1_RESET:
4083 return snd_hdsp_reset(substream);
4084 case SNDRV_PCM_IOCTL1_CHANNEL_INFO:
4085 return snd_hdsp_channel_info(substream, arg);
4090 return snd_pcm_lib_ioctl(substream, cmd, arg);
4093 static int snd_hdsp_trigger(struct snd_pcm_substream *substream, int cmd)
4095 struct hdsp *hdsp = snd_pcm_substream_chip(substream);
4096 struct snd_pcm_substream *other;
4099 if (hdsp_check_for_iobox (hdsp))
4102 if (hdsp_check_for_firmware(hdsp, 0)) /* no auto-loading in trigger */
4105 spin_lock(&hdsp->lock);
4106 running = hdsp->running;
4108 case SNDRV_PCM_TRIGGER_START:
4109 running |= 1 << substream->stream;
4111 case SNDRV_PCM_TRIGGER_STOP:
4112 running &= ~(1 << substream->stream);
4116 spin_unlock(&hdsp->lock);
4119 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
4120 other = hdsp->capture_substream;
4122 other = hdsp->playback_substream;
4125 struct snd_pcm_substream *s;
4126 snd_pcm_group_for_each_entry(s, substream) {
4128 snd_pcm_trigger_done(s, substream);
4129 if (cmd == SNDRV_PCM_TRIGGER_START)
4130 running |= 1 << s->stream;
4132 running &= ~(1 << s->stream);
4136 if (cmd == SNDRV_PCM_TRIGGER_START) {
4137 if (!(running & (1 << SNDRV_PCM_STREAM_PLAYBACK)) &&
4138 substream->stream == SNDRV_PCM_STREAM_CAPTURE)
4139 hdsp_silence_playback(hdsp);
4142 substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
4143 hdsp_silence_playback(hdsp);
4146 if (substream->stream == SNDRV_PCM_STREAM_CAPTURE)
4147 hdsp_silence_playback(hdsp);
4150 snd_pcm_trigger_done(substream, substream);
4151 if (!hdsp->running && running)
4152 hdsp_start_audio(hdsp);
4153 else if (hdsp->running && !running)
4154 hdsp_stop_audio(hdsp);
4155 hdsp->running = running;
4156 spin_unlock(&hdsp->lock);
4161 static int snd_hdsp_prepare(struct snd_pcm_substream *substream)
4163 struct hdsp *hdsp = snd_pcm_substream_chip(substream);
4166 if (hdsp_check_for_iobox (hdsp))
4169 if (hdsp_check_for_firmware(hdsp, 1))
4172 spin_lock_irq(&hdsp->lock);
4174 hdsp_reset_hw_pointer(hdsp);
4175 spin_unlock_irq(&hdsp->lock);
4179 static struct snd_pcm_hardware snd_hdsp_playback_subinfo =
4181 .info = (SNDRV_PCM_INFO_MMAP |
4182 SNDRV_PCM_INFO_MMAP_VALID |
4183 SNDRV_PCM_INFO_NONINTERLEAVED |
4184 SNDRV_PCM_INFO_SYNC_START |
4185 SNDRV_PCM_INFO_DOUBLE),
4186 #ifdef SNDRV_BIG_ENDIAN
4187 .formats = SNDRV_PCM_FMTBIT_S32_BE,
4189 .formats = SNDRV_PCM_FMTBIT_S32_LE,
4191 .rates = (SNDRV_PCM_RATE_32000 |
4192 SNDRV_PCM_RATE_44100 |
4193 SNDRV_PCM_RATE_48000 |
4194 SNDRV_PCM_RATE_64000 |
4195 SNDRV_PCM_RATE_88200 |
4196 SNDRV_PCM_RATE_96000),
4200 .channels_max = HDSP_MAX_CHANNELS,
4201 .buffer_bytes_max = HDSP_CHANNEL_BUFFER_BYTES * HDSP_MAX_CHANNELS,
4202 .period_bytes_min = (64 * 4) * 10,
4203 .period_bytes_max = (8192 * 4) * HDSP_MAX_CHANNELS,
4209 static struct snd_pcm_hardware snd_hdsp_capture_subinfo =
4211 .info = (SNDRV_PCM_INFO_MMAP |
4212 SNDRV_PCM_INFO_MMAP_VALID |
4213 SNDRV_PCM_INFO_NONINTERLEAVED |
4214 SNDRV_PCM_INFO_SYNC_START),
4215 #ifdef SNDRV_BIG_ENDIAN
4216 .formats = SNDRV_PCM_FMTBIT_S32_BE,
4218 .formats = SNDRV_PCM_FMTBIT_S32_LE,
4220 .rates = (SNDRV_PCM_RATE_32000 |
4221 SNDRV_PCM_RATE_44100 |
4222 SNDRV_PCM_RATE_48000 |
4223 SNDRV_PCM_RATE_64000 |
4224 SNDRV_PCM_RATE_88200 |
4225 SNDRV_PCM_RATE_96000),
4229 .channels_max = HDSP_MAX_CHANNELS,
4230 .buffer_bytes_max = HDSP_CHANNEL_BUFFER_BYTES * HDSP_MAX_CHANNELS,
4231 .period_bytes_min = (64 * 4) * 10,
4232 .period_bytes_max = (8192 * 4) * HDSP_MAX_CHANNELS,
4238 static unsigned int hdsp_period_sizes[] = { 64, 128, 256, 512, 1024, 2048, 4096, 8192 };
4240 static struct snd_pcm_hw_constraint_list hdsp_hw_constraints_period_sizes = {
4241 .count = ARRAY_SIZE(hdsp_period_sizes),
4242 .list = hdsp_period_sizes,
4246 static unsigned int hdsp_9632_sample_rates[] = { 32000, 44100, 48000, 64000, 88200, 96000, 128000, 176400, 192000 };
4248 static struct snd_pcm_hw_constraint_list hdsp_hw_constraints_9632_sample_rates = {
4249 .count = ARRAY_SIZE(hdsp_9632_sample_rates),
4250 .list = hdsp_9632_sample_rates,
4254 static int snd_hdsp_hw_rule_in_channels(struct snd_pcm_hw_params *params,
4255 struct snd_pcm_hw_rule *rule)
4257 struct hdsp *hdsp = rule->private;
4258 struct snd_interval *c = hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS);
4259 if (hdsp->io_type == H9632) {
4260 unsigned int list[3];
4261 list[0] = hdsp->qs_in_channels;
4262 list[1] = hdsp->ds_in_channels;
4263 list[2] = hdsp->ss_in_channels;
4264 return snd_interval_list(c, 3, list, 0);
4266 unsigned int list[2];
4267 list[0] = hdsp->ds_in_channels;
4268 list[1] = hdsp->ss_in_channels;
4269 return snd_interval_list(c, 2, list, 0);
4273 static int snd_hdsp_hw_rule_out_channels(struct snd_pcm_hw_params *params,
4274 struct snd_pcm_hw_rule *rule)
4276 unsigned int list[3];
4277 struct hdsp *hdsp = rule->private;
4278 struct snd_interval *c = hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS);
4279 if (hdsp->io_type == H9632) {
4280 list[0] = hdsp->qs_out_channels;
4281 list[1] = hdsp->ds_out_channels;
4282 list[2] = hdsp->ss_out_channels;
4283 return snd_interval_list(c, 3, list, 0);
4285 list[0] = hdsp->ds_out_channels;
4286 list[1] = hdsp->ss_out_channels;
4288 return snd_interval_list(c, 2, list, 0);
4291 static int snd_hdsp_hw_rule_in_channels_rate(struct snd_pcm_hw_params *params,
4292 struct snd_pcm_hw_rule *rule)
4294 struct hdsp *hdsp = rule->private;
4295 struct snd_interval *c = hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS);
4296 struct snd_interval *r = hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE);
4297 if (r->min > 96000 && hdsp->io_type == H9632) {
4298 struct snd_interval t = {
4299 .min = hdsp->qs_in_channels,
4300 .max = hdsp->qs_in_channels,
4303 return snd_interval_refine(c, &t);
4304 } else if (r->min > 48000 && r->max <= 96000) {
4305 struct snd_interval t = {
4306 .min = hdsp->ds_in_channels,
4307 .max = hdsp->ds_in_channels,
4310 return snd_interval_refine(c, &t);
4311 } else if (r->max < 64000) {
4312 struct snd_interval t = {
4313 .min = hdsp->ss_in_channels,
4314 .max = hdsp->ss_in_channels,
4317 return snd_interval_refine(c, &t);
4322 static int snd_hdsp_hw_rule_out_channels_rate(struct snd_pcm_hw_params *params,
4323 struct snd_pcm_hw_rule *rule)
4325 struct hdsp *hdsp = rule->private;
4326 struct snd_interval *c = hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS);
4327 struct snd_interval *r = hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE);
4328 if (r->min > 96000 && hdsp->io_type == H9632) {
4329 struct snd_interval t = {
4330 .min = hdsp->qs_out_channels,
4331 .max = hdsp->qs_out_channels,
4334 return snd_interval_refine(c, &t);
4335 } else if (r->min > 48000 && r->max <= 96000) {
4336 struct snd_interval t = {
4337 .min = hdsp->ds_out_channels,
4338 .max = hdsp->ds_out_channels,
4341 return snd_interval_refine(c, &t);
4342 } else if (r->max < 64000) {
4343 struct snd_interval t = {
4344 .min = hdsp->ss_out_channels,
4345 .max = hdsp->ss_out_channels,
4348 return snd_interval_refine(c, &t);
4353 static int snd_hdsp_hw_rule_rate_out_channels(struct snd_pcm_hw_params *params,
4354 struct snd_pcm_hw_rule *rule)
4356 struct hdsp *hdsp = rule->private;
4357 struct snd_interval *c = hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS);
4358 struct snd_interval *r = hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE);
4359 if (c->min >= hdsp->ss_out_channels) {
4360 struct snd_interval t = {
4365 return snd_interval_refine(r, &t);
4366 } else if (c->max <= hdsp->qs_out_channels && hdsp->io_type == H9632) {
4367 struct snd_interval t = {
4372 return snd_interval_refine(r, &t);
4373 } else if (c->max <= hdsp->ds_out_channels) {
4374 struct snd_interval t = {
4379 return snd_interval_refine(r, &t);
4384 static int snd_hdsp_hw_rule_rate_in_channels(struct snd_pcm_hw_params *params,
4385 struct snd_pcm_hw_rule *rule)
4387 struct hdsp *hdsp = rule->private;
4388 struct snd_interval *c = hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS);
4389 struct snd_interval *r = hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE);
4390 if (c->min >= hdsp->ss_in_channels) {
4391 struct snd_interval t = {
4396 return snd_interval_refine(r, &t);
4397 } else if (c->max <= hdsp->qs_in_channels && hdsp->io_type == H9632) {
4398 struct snd_interval t = {
4403 return snd_interval_refine(r, &t);
4404 } else if (c->max <= hdsp->ds_in_channels) {
4405 struct snd_interval t = {
4410 return snd_interval_refine(r, &t);
4415 static int snd_hdsp_playback_open(struct snd_pcm_substream *substream)
4417 struct hdsp *hdsp = snd_pcm_substream_chip(substream);
4418 struct snd_pcm_runtime *runtime = substream->runtime;
4420 if (hdsp_check_for_iobox (hdsp))
4423 if (hdsp_check_for_firmware(hdsp, 1))
4426 spin_lock_irq(&hdsp->lock);
4428 snd_pcm_set_sync(substream);
4430 runtime->hw = snd_hdsp_playback_subinfo;
4431 runtime->dma_area = hdsp->playback_buffer;
4432 runtime->dma_bytes = HDSP_DMA_AREA_BYTES;
4434 hdsp->playback_pid = current->pid;
4435 hdsp->playback_substream = substream;
4437 spin_unlock_irq(&hdsp->lock);
4439 snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24);
4440 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_SIZE, &hdsp_hw_constraints_period_sizes);
4441 if (hdsp->clock_source_locked) {
4442 runtime->hw.rate_min = runtime->hw.rate_max = hdsp->system_sample_rate;
4443 } else if (hdsp->io_type == H9632) {
4444 runtime->hw.rate_max = 192000;
4445 runtime->hw.rates = SNDRV_PCM_RATE_KNOT;
4446 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, &hdsp_hw_constraints_9632_sample_rates);
4448 if (hdsp->io_type == H9632) {
4449 runtime->hw.channels_min = hdsp->qs_out_channels;
4450 runtime->hw.channels_max = hdsp->ss_out_channels;
4453 snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
4454 snd_hdsp_hw_rule_out_channels, hdsp,
4455 SNDRV_PCM_HW_PARAM_CHANNELS, -1);
4456 snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
4457 snd_hdsp_hw_rule_out_channels_rate, hdsp,
4458 SNDRV_PCM_HW_PARAM_RATE, -1);
4459 snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
4460 snd_hdsp_hw_rule_rate_out_channels, hdsp,
4461 SNDRV_PCM_HW_PARAM_CHANNELS, -1);
4463 if (RPM != hdsp->io_type) {
4464 hdsp->creg_spdif_stream = hdsp->creg_spdif;
4465 hdsp->spdif_ctl->vd[0].access &= ~SNDRV_CTL_ELEM_ACCESS_INACTIVE;
4466 snd_ctl_notify(hdsp->card, SNDRV_CTL_EVENT_MASK_VALUE |
4467 SNDRV_CTL_EVENT_MASK_INFO, &hdsp->spdif_ctl->id);
4472 static int snd_hdsp_playback_release(struct snd_pcm_substream *substream)
4474 struct hdsp *hdsp = snd_pcm_substream_chip(substream);
4476 spin_lock_irq(&hdsp->lock);
4478 hdsp->playback_pid = -1;
4479 hdsp->playback_substream = NULL;
4481 spin_unlock_irq(&hdsp->lock);
4483 if (RPM != hdsp->io_type) {
4484 hdsp->spdif_ctl->vd[0].access |= SNDRV_CTL_ELEM_ACCESS_INACTIVE;
4485 snd_ctl_notify(hdsp->card, SNDRV_CTL_EVENT_MASK_VALUE |
4486 SNDRV_CTL_EVENT_MASK_INFO, &hdsp->spdif_ctl->id);
4492 static int snd_hdsp_capture_open(struct snd_pcm_substream *substream)
4494 struct hdsp *hdsp = snd_pcm_substream_chip(substream);
4495 struct snd_pcm_runtime *runtime = substream->runtime;
4497 if (hdsp_check_for_iobox (hdsp))
4500 if (hdsp_check_for_firmware(hdsp, 1))
4503 spin_lock_irq(&hdsp->lock);
4505 snd_pcm_set_sync(substream);
4507 runtime->hw = snd_hdsp_capture_subinfo;
4508 runtime->dma_area = hdsp->capture_buffer;
4509 runtime->dma_bytes = HDSP_DMA_AREA_BYTES;
4511 hdsp->capture_pid = current->pid;
4512 hdsp->capture_substream = substream;
4514 spin_unlock_irq(&hdsp->lock);
4516 snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24);
4517 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_SIZE, &hdsp_hw_constraints_period_sizes);
4518 if (hdsp->io_type == H9632) {
4519 runtime->hw.channels_min = hdsp->qs_in_channels;
4520 runtime->hw.channels_max = hdsp->ss_in_channels;
4521 runtime->hw.rate_max = 192000;
4522 runtime->hw.rates = SNDRV_PCM_RATE_KNOT;
4523 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, &hdsp_hw_constraints_9632_sample_rates);
4525 snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
4526 snd_hdsp_hw_rule_in_channels, hdsp,
4527 SNDRV_PCM_HW_PARAM_CHANNELS, -1);
4528 snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
4529 snd_hdsp_hw_rule_in_channels_rate, hdsp,
4530 SNDRV_PCM_HW_PARAM_RATE, -1);
4531 snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
4532 snd_hdsp_hw_rule_rate_in_channels, hdsp,
4533 SNDRV_PCM_HW_PARAM_CHANNELS, -1);
4537 static int snd_hdsp_capture_release(struct snd_pcm_substream *substream)
4539 struct hdsp *hdsp = snd_pcm_substream_chip(substream);
4541 spin_lock_irq(&hdsp->lock);
4543 hdsp->capture_pid = -1;
4544 hdsp->capture_substream = NULL;
4546 spin_unlock_irq(&hdsp->lock);
4550 /* helper functions for copying meter values */
4551 static inline int copy_u32_le(void __user *dest, void __iomem *src)
4553 u32 val = readl(src);
4554 return copy_to_user(dest, &val, 4);
4557 static inline int copy_u64_le(void __user *dest, void __iomem *src_low, void __iomem *src_high)
4559 u32 rms_low, rms_high;
4561 rms_low = readl(src_low);
4562 rms_high = readl(src_high);
4563 rms = ((u64)rms_high << 32) | rms_low;
4564 return copy_to_user(dest, &rms, 8);
4567 static inline int copy_u48_le(void __user *dest, void __iomem *src_low, void __iomem *src_high)
4569 u32 rms_low, rms_high;
4571 rms_low = readl(src_low) & 0xffffff00;
4572 rms_high = readl(src_high) & 0xffffff00;
4573 rms = ((u64)rms_high << 32) | rms_low;
4574 return copy_to_user(dest, &rms, 8);
4577 static int hdsp_9652_get_peak(struct hdsp *hdsp, struct hdsp_peak_rms __user *peak_rms)
4579 int doublespeed = 0;
4580 int i, j, channels, ofs;
4582 if (hdsp_read (hdsp, HDSP_statusRegister) & HDSP_DoubleSpeedStatus)
4584 channels = doublespeed ? 14 : 26;
4585 for (i = 0, j = 0; i < 26; ++i) {
4586 if (doublespeed && (i & 4))
4588 ofs = HDSP_9652_peakBase - j * 4;
4589 if (copy_u32_le(&peak_rms->input_peaks[i], hdsp->iobase + ofs))
4591 ofs -= channels * 4;
4592 if (copy_u32_le(&peak_rms->playback_peaks[i], hdsp->iobase + ofs))
4594 ofs -= channels * 4;
4595 if (copy_u32_le(&peak_rms->output_peaks[i], hdsp->iobase + ofs))
4597 ofs = HDSP_9652_rmsBase + j * 8;
4598 if (copy_u48_le(&peak_rms->input_rms[i], hdsp->iobase + ofs,
4599 hdsp->iobase + ofs + 4))
4601 ofs += channels * 8;
4602 if (copy_u48_le(&peak_rms->playback_rms[i], hdsp->iobase + ofs,
4603 hdsp->iobase + ofs + 4))
4605 ofs += channels * 8;
4606 if (copy_u48_le(&peak_rms->output_rms[i], hdsp->iobase + ofs,
4607 hdsp->iobase + ofs + 4))
4614 static int hdsp_9632_get_peak(struct hdsp *hdsp, struct hdsp_peak_rms __user *peak_rms)
4617 struct hdsp_9632_meters __iomem *m;
4618 int doublespeed = 0;
4620 if (hdsp_read (hdsp, HDSP_statusRegister) & HDSP_DoubleSpeedStatus)
4622 m = (struct hdsp_9632_meters __iomem *)(hdsp->iobase+HDSP_9632_metersBase);
4623 for (i = 0, j = 0; i < 16; ++i, ++j) {
4624 if (copy_u32_le(&peak_rms->input_peaks[i], &m->input_peak[j]))
4626 if (copy_u32_le(&peak_rms->playback_peaks[i], &m->playback_peak[j]))
4628 if (copy_u32_le(&peak_rms->output_peaks[i], &m->output_peak[j]))
4630 if (copy_u64_le(&peak_rms->input_rms[i], &m->input_rms_low[j],
4631 &m->input_rms_high[j]))
4633 if (copy_u64_le(&peak_rms->playback_rms[i], &m->playback_rms_low[j],
4634 &m->playback_rms_high[j]))
4636 if (copy_u64_le(&peak_rms->output_rms[i], &m->output_rms_low[j],
4637 &m->output_rms_high[j]))
4639 if (doublespeed && i == 3) i += 4;
4644 static int hdsp_get_peak(struct hdsp *hdsp, struct hdsp_peak_rms __user *peak_rms)
4648 for (i = 0; i < 26; i++) {
4649 if (copy_u32_le(&peak_rms->playback_peaks[i],
4650 hdsp->iobase + HDSP_playbackPeakLevel + i * 4))
4652 if (copy_u32_le(&peak_rms->input_peaks[i],
4653 hdsp->iobase + HDSP_inputPeakLevel + i * 4))
4656 for (i = 0; i < 28; i++) {
4657 if (copy_u32_le(&peak_rms->output_peaks[i],
4658 hdsp->iobase + HDSP_outputPeakLevel + i * 4))
4661 for (i = 0; i < 26; ++i) {
4662 if (copy_u64_le(&peak_rms->playback_rms[i],
4663 hdsp->iobase + HDSP_playbackRmsLevel + i * 8 + 4,
4664 hdsp->iobase + HDSP_playbackRmsLevel + i * 8))
4666 if (copy_u64_le(&peak_rms->input_rms[i],
4667 hdsp->iobase + HDSP_inputRmsLevel + i * 8 + 4,
4668 hdsp->iobase + HDSP_inputRmsLevel + i * 8))
4674 static int snd_hdsp_hwdep_ioctl(struct snd_hwdep *hw, struct file *file, unsigned int cmd, unsigned long arg)
4676 struct hdsp *hdsp = hw->private_data;
4677 void __user *argp = (void __user *)arg;
4681 case SNDRV_HDSP_IOCTL_GET_PEAK_RMS: {
4682 struct hdsp_peak_rms __user *peak_rms = (struct hdsp_peak_rms __user *)arg;
4684 err = hdsp_check_for_iobox(hdsp);
4688 err = hdsp_check_for_firmware(hdsp, 1);
4692 if (!(hdsp->state & HDSP_FirmwareLoaded)) {
4693 dev_err(hdsp->card->dev,
4694 "firmware needs to be uploaded to the card.\n");
4698 switch (hdsp->io_type) {
4700 return hdsp_9652_get_peak(hdsp, peak_rms);
4702 return hdsp_9632_get_peak(hdsp, peak_rms);
4704 return hdsp_get_peak(hdsp, peak_rms);
4707 case SNDRV_HDSP_IOCTL_GET_CONFIG_INFO: {
4708 struct hdsp_config_info info;
4709 unsigned long flags;
4712 err = hdsp_check_for_iobox(hdsp);
4716 err = hdsp_check_for_firmware(hdsp, 1);
4720 memset(&info, 0, sizeof(info));
4721 spin_lock_irqsave(&hdsp->lock, flags);
4722 info.pref_sync_ref = (unsigned char)hdsp_pref_sync_ref(hdsp);
4723 info.wordclock_sync_check = (unsigned char)hdsp_wc_sync_check(hdsp);
4724 if (hdsp->io_type != H9632)
4725 info.adatsync_sync_check = (unsigned char)hdsp_adatsync_sync_check(hdsp);
4726 info.spdif_sync_check = (unsigned char)hdsp_spdif_sync_check(hdsp);
4727 for (i = 0; i < ((hdsp->io_type != Multiface && hdsp->io_type != RPM && hdsp->io_type != H9632) ? 3 : 1); ++i)
4728 info.adat_sync_check[i] = (unsigned char)hdsp_adat_sync_check(hdsp, i);
4729 info.spdif_in = (unsigned char)hdsp_spdif_in(hdsp);
4730 info.spdif_out = (unsigned char)hdsp_toggle_setting(hdsp,
4731 HDSP_SPDIFOpticalOut);
4732 info.spdif_professional = (unsigned char)
4733 hdsp_toggle_setting(hdsp, HDSP_SPDIFProfessional);
4734 info.spdif_emphasis = (unsigned char)
4735 hdsp_toggle_setting(hdsp, HDSP_SPDIFEmphasis);
4736 info.spdif_nonaudio = (unsigned char)
4737 hdsp_toggle_setting(hdsp, HDSP_SPDIFNonAudio);
4738 info.spdif_sample_rate = hdsp_spdif_sample_rate(hdsp);
4739 info.system_sample_rate = hdsp->system_sample_rate;
4740 info.autosync_sample_rate = hdsp_external_sample_rate(hdsp);
4741 info.system_clock_mode = (unsigned char)hdsp_system_clock_mode(hdsp);
4742 info.clock_source = (unsigned char)hdsp_clock_source(hdsp);
4743 info.autosync_ref = (unsigned char)hdsp_autosync_ref(hdsp);
4744 info.line_out = (unsigned char)
4745 hdsp_toggle_setting(hdsp, HDSP_LineOut);
4746 if (hdsp->io_type == H9632) {
4747 info.da_gain = (unsigned char)hdsp_da_gain(hdsp);
4748 info.ad_gain = (unsigned char)hdsp_ad_gain(hdsp);
4749 info.phone_gain = (unsigned char)hdsp_phone_gain(hdsp);
4750 info.xlr_breakout_cable =
4751 (unsigned char)hdsp_toggle_setting(hdsp,
4752 HDSP_XLRBreakoutCable);
4754 } else if (hdsp->io_type == RPM) {
4755 info.da_gain = (unsigned char) hdsp_rpm_input12(hdsp);
4756 info.ad_gain = (unsigned char) hdsp_rpm_input34(hdsp);
4758 if (hdsp->io_type == H9632 || hdsp->io_type == H9652)
4759 info.analog_extension_board =
4760 (unsigned char)hdsp_toggle_setting(hdsp,
4761 HDSP_AnalogExtensionBoard);
4762 spin_unlock_irqrestore(&hdsp->lock, flags);
4763 if (copy_to_user(argp, &info, sizeof(info)))
4767 case SNDRV_HDSP_IOCTL_GET_9632_AEB: {
4768 struct hdsp_9632_aeb h9632_aeb;
4770 if (hdsp->io_type != H9632) return -EINVAL;
4771 h9632_aeb.aebi = hdsp->ss_in_channels - H9632_SS_CHANNELS;
4772 h9632_aeb.aebo = hdsp->ss_out_channels - H9632_SS_CHANNELS;
4773 if (copy_to_user(argp, &h9632_aeb, sizeof(h9632_aeb)))
4777 case SNDRV_HDSP_IOCTL_GET_VERSION: {
4778 struct hdsp_version hdsp_version;
4781 if (hdsp->io_type == H9652 || hdsp->io_type == H9632) return -EINVAL;
4782 if (hdsp->io_type == Undefined) {
4783 if ((err = hdsp_get_iobox_version(hdsp)) < 0)
4786 memset(&hdsp_version, 0, sizeof(hdsp_version));
4787 hdsp_version.io_type = hdsp->io_type;
4788 hdsp_version.firmware_rev = hdsp->firmware_rev;
4789 if ((err = copy_to_user(argp, &hdsp_version, sizeof(hdsp_version))))
4793 case SNDRV_HDSP_IOCTL_UPLOAD_FIRMWARE: {
4794 struct hdsp_firmware __user *firmware;
4795 u32 __user *firmware_data;
4798 if (hdsp->io_type == H9652 || hdsp->io_type == H9632) return -EINVAL;
4799 /* SNDRV_HDSP_IOCTL_GET_VERSION must have been called */
4800 if (hdsp->io_type == Undefined) return -EINVAL;
4802 if (hdsp->state & (HDSP_FirmwareCached | HDSP_FirmwareLoaded))
4805 dev_info(hdsp->card->dev,
4806 "initializing firmware upload\n");
4807 firmware = (struct hdsp_firmware __user *)argp;
4809 if (get_user(firmware_data, &firmware->firmware_data))
4812 if (hdsp_check_for_iobox (hdsp))
4815 if (!hdsp->fw_uploaded) {
4816 hdsp->fw_uploaded = vmalloc(HDSP_FIRMWARE_SIZE);
4817 if (!hdsp->fw_uploaded)
4821 if (copy_from_user(hdsp->fw_uploaded, firmware_data,
4822 HDSP_FIRMWARE_SIZE)) {
4823 vfree(hdsp->fw_uploaded);
4824 hdsp->fw_uploaded = NULL;
4828 hdsp->state |= HDSP_FirmwareCached;
4830 if ((err = snd_hdsp_load_firmware_from_cache(hdsp)) < 0)
4833 if (!(hdsp->state & HDSP_InitializationComplete)) {
4834 if ((err = snd_hdsp_enable_io(hdsp)) < 0)
4837 snd_hdsp_initialize_channels(hdsp);
4838 snd_hdsp_initialize_midi_flush(hdsp);
4840 if ((err = snd_hdsp_create_alsa_devices(hdsp->card, hdsp)) < 0) {
4841 dev_err(hdsp->card->dev,
4842 "error creating alsa devices\n");
4848 case SNDRV_HDSP_IOCTL_GET_MIXER: {
4849 struct hdsp_mixer __user *mixer = (struct hdsp_mixer __user *)argp;
4850 if (copy_to_user(mixer->matrix, hdsp->mixer_matrix, sizeof(unsigned short)*HDSP_MATRIX_MIXER_SIZE))
4860 static const struct snd_pcm_ops snd_hdsp_playback_ops = {
4861 .open = snd_hdsp_playback_open,
4862 .close = snd_hdsp_playback_release,
4863 .ioctl = snd_hdsp_ioctl,
4864 .hw_params = snd_hdsp_hw_params,
4865 .prepare = snd_hdsp_prepare,
4866 .trigger = snd_hdsp_trigger,
4867 .pointer = snd_hdsp_hw_pointer,
4868 .copy = snd_hdsp_playback_copy,
4869 .silence = snd_hdsp_hw_silence,
4872 static const struct snd_pcm_ops snd_hdsp_capture_ops = {
4873 .open = snd_hdsp_capture_open,
4874 .close = snd_hdsp_capture_release,
4875 .ioctl = snd_hdsp_ioctl,
4876 .hw_params = snd_hdsp_hw_params,
4877 .prepare = snd_hdsp_prepare,
4878 .trigger = snd_hdsp_trigger,
4879 .pointer = snd_hdsp_hw_pointer,
4880 .copy = snd_hdsp_capture_copy,
4883 static int snd_hdsp_create_hwdep(struct snd_card *card, struct hdsp *hdsp)
4885 struct snd_hwdep *hw;
4888 if ((err = snd_hwdep_new(card, "HDSP hwdep", 0, &hw)) < 0)
4892 hw->private_data = hdsp;
4893 strcpy(hw->name, "HDSP hwdep interface");
4895 hw->ops.ioctl = snd_hdsp_hwdep_ioctl;
4896 hw->ops.ioctl_compat = snd_hdsp_hwdep_ioctl;
4901 static int snd_hdsp_create_pcm(struct snd_card *card, struct hdsp *hdsp)
4903 struct snd_pcm *pcm;
4906 if ((err = snd_pcm_new(card, hdsp->card_name, 0, 1, 1, &pcm)) < 0)
4910 pcm->private_data = hdsp;
4911 strcpy(pcm->name, hdsp->card_name);
4913 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_hdsp_playback_ops);
4914 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_hdsp_capture_ops);
4916 pcm->info_flags = SNDRV_PCM_INFO_JOINT_DUPLEX;
4921 static void snd_hdsp_9652_enable_mixer (struct hdsp *hdsp)
4923 hdsp->control2_register |= HDSP_9652_ENABLE_MIXER;
4924 hdsp_write (hdsp, HDSP_control2Reg, hdsp->control2_register);
4927 static int snd_hdsp_enable_io (struct hdsp *hdsp)
4931 if (hdsp_fifo_wait (hdsp, 0, 100)) {
4932 dev_err(hdsp->card->dev,
4933 "enable_io fifo_wait failed\n");
4937 for (i = 0; i < hdsp->max_channels; ++i) {
4938 hdsp_write (hdsp, HDSP_inputEnable + (4 * i), 1);
4939 hdsp_write (hdsp, HDSP_outputEnable + (4 * i), 1);
4945 static void snd_hdsp_initialize_channels(struct hdsp *hdsp)
4947 int status, aebi_channels, aebo_channels;
4949 switch (hdsp->io_type) {
4951 hdsp->card_name = "RME Hammerfall DSP + Digiface";
4952 hdsp->ss_in_channels = hdsp->ss_out_channels = DIGIFACE_SS_CHANNELS;
4953 hdsp->ds_in_channels = hdsp->ds_out_channels = DIGIFACE_DS_CHANNELS;
4957 hdsp->card_name = "RME Hammerfall HDSP 9652";
4958 hdsp->ss_in_channels = hdsp->ss_out_channels = H9652_SS_CHANNELS;
4959 hdsp->ds_in_channels = hdsp->ds_out_channels = H9652_DS_CHANNELS;
4963 status = hdsp_read(hdsp, HDSP_statusRegister);
4964 /* HDSP_AEBx bits are low when AEB are connected */
4965 aebi_channels = (status & HDSP_AEBI) ? 0 : 4;
4966 aebo_channels = (status & HDSP_AEBO) ? 0 : 4;
4967 hdsp->card_name = "RME Hammerfall HDSP 9632";
4968 hdsp->ss_in_channels = H9632_SS_CHANNELS+aebi_channels;
4969 hdsp->ds_in_channels = H9632_DS_CHANNELS+aebi_channels;
4970 hdsp->qs_in_channels = H9632_QS_CHANNELS+aebi_channels;
4971 hdsp->ss_out_channels = H9632_SS_CHANNELS+aebo_channels;
4972 hdsp->ds_out_channels = H9632_DS_CHANNELS+aebo_channels;
4973 hdsp->qs_out_channels = H9632_QS_CHANNELS+aebo_channels;
4977 hdsp->card_name = "RME Hammerfall DSP + Multiface";
4978 hdsp->ss_in_channels = hdsp->ss_out_channels = MULTIFACE_SS_CHANNELS;
4979 hdsp->ds_in_channels = hdsp->ds_out_channels = MULTIFACE_DS_CHANNELS;
4983 hdsp->card_name = "RME Hammerfall DSP + RPM";
4984 hdsp->ss_in_channels = RPM_CHANNELS-1;
4985 hdsp->ss_out_channels = RPM_CHANNELS;
4986 hdsp->ds_in_channels = RPM_CHANNELS-1;
4987 hdsp->ds_out_channels = RPM_CHANNELS;
4991 /* should never get here */
4996 static void snd_hdsp_initialize_midi_flush (struct hdsp *hdsp)
4998 snd_hdsp_flush_midi_input (hdsp, 0);
4999 snd_hdsp_flush_midi_input (hdsp, 1);
5002 static int snd_hdsp_create_alsa_devices(struct snd_card *card, struct hdsp *hdsp)
5006 if ((err = snd_hdsp_create_pcm(card, hdsp)) < 0) {
5008 "Error creating pcm interface\n");
5013 if ((err = snd_hdsp_create_midi(card, hdsp, 0)) < 0) {
5015 "Error creating first midi interface\n");
5019 if (hdsp->io_type == Digiface || hdsp->io_type == H9652) {
5020 if ((err = snd_hdsp_create_midi(card, hdsp, 1)) < 0) {
5022 "Error creating second midi interface\n");
5027 if ((err = snd_hdsp_create_controls(card, hdsp)) < 0) {
5029 "Error creating ctl interface\n");
5033 snd_hdsp_proc_init(hdsp);
5035 hdsp->system_sample_rate = -1;
5036 hdsp->playback_pid = -1;
5037 hdsp->capture_pid = -1;
5038 hdsp->capture_substream = NULL;
5039 hdsp->playback_substream = NULL;
5041 if ((err = snd_hdsp_set_defaults(hdsp)) < 0) {
5043 "Error setting default values\n");
5047 if (!(hdsp->state & HDSP_InitializationComplete)) {
5048 strcpy(card->shortname, "Hammerfall DSP");
5049 sprintf(card->longname, "%s at 0x%lx, irq %d", hdsp->card_name,
5050 hdsp->port, hdsp->irq);
5052 if ((err = snd_card_register(card)) < 0) {
5054 "error registering card\n");
5057 hdsp->state |= HDSP_InitializationComplete;
5063 /* load firmware via hotplug fw loader */
5064 static int hdsp_request_fw_loader(struct hdsp *hdsp)
5067 const struct firmware *fw;
5070 if (hdsp->io_type == H9652 || hdsp->io_type == H9632)
5072 if (hdsp->io_type == Undefined) {
5073 if ((err = hdsp_get_iobox_version(hdsp)) < 0)
5075 if (hdsp->io_type == H9652 || hdsp->io_type == H9632)
5079 /* caution: max length of firmware filename is 30! */
5080 switch (hdsp->io_type) {
5082 fwfile = "/*(DEBLOBBED)*/";
5085 if (hdsp->firmware_rev == 0xa)
5086 fwfile = "/*(DEBLOBBED)*/";
5088 fwfile = "/*(DEBLOBBED)*/";
5091 if (hdsp->firmware_rev == 0xa)
5092 fwfile = "/*(DEBLOBBED)*/";
5094 fwfile = "/*(DEBLOBBED)*/";
5097 dev_err(hdsp->card->dev,
5098 "invalid io_type %d\n", hdsp->io_type);
5102 if (reject_firmware(&fw, fwfile, &hdsp->pci->dev)) {
5103 dev_err(hdsp->card->dev,
5104 "cannot load firmware %s\n", fwfile);
5107 if (fw->size < HDSP_FIRMWARE_SIZE) {
5108 dev_err(hdsp->card->dev,
5109 "too short firmware size %d (expected %d)\n",
5110 (int)fw->size, HDSP_FIRMWARE_SIZE);
5111 release_firmware(fw);
5115 hdsp->firmware = fw;
5117 hdsp->state |= HDSP_FirmwareCached;
5119 if ((err = snd_hdsp_load_firmware_from_cache(hdsp)) < 0)
5122 if (!(hdsp->state & HDSP_InitializationComplete)) {
5123 if ((err = snd_hdsp_enable_io(hdsp)) < 0)
5126 if ((err = snd_hdsp_create_hwdep(hdsp->card, hdsp)) < 0) {
5127 dev_err(hdsp->card->dev,
5128 "error creating hwdep device\n");
5131 snd_hdsp_initialize_channels(hdsp);
5132 snd_hdsp_initialize_midi_flush(hdsp);
5133 if ((err = snd_hdsp_create_alsa_devices(hdsp->card, hdsp)) < 0) {
5134 dev_err(hdsp->card->dev,
5135 "error creating alsa devices\n");
5142 static int snd_hdsp_create(struct snd_card *card,
5145 struct pci_dev *pci = hdsp->pci;
5152 hdsp->midi[0].rmidi = NULL;
5153 hdsp->midi[1].rmidi = NULL;
5154 hdsp->midi[0].input = NULL;
5155 hdsp->midi[1].input = NULL;
5156 hdsp->midi[0].output = NULL;
5157 hdsp->midi[1].output = NULL;
5158 hdsp->midi[0].pending = 0;
5159 hdsp->midi[1].pending = 0;
5160 spin_lock_init(&hdsp->midi[0].lock);
5161 spin_lock_init(&hdsp->midi[1].lock);
5162 hdsp->iobase = NULL;
5163 hdsp->control_register = 0;
5164 hdsp->control2_register = 0;
5165 hdsp->io_type = Undefined;
5166 hdsp->max_channels = 26;
5170 spin_lock_init(&hdsp->lock);
5172 tasklet_init(&hdsp->midi_tasklet, hdsp_midi_tasklet, (unsigned long)hdsp);
5174 pci_read_config_word(hdsp->pci, PCI_CLASS_REVISION, &hdsp->firmware_rev);
5175 hdsp->firmware_rev &= 0xff;
5177 /* From Martin Bjoernsen :
5178 "It is important that the card's latency timer register in
5179 the PCI configuration space is set to a value much larger
5180 than 0 by the computer's BIOS or the driver.
5181 The windows driver always sets this 8 bit register [...]
5182 to its maximum 255 to avoid problems with some computers."
5184 pci_write_config_byte(hdsp->pci, PCI_LATENCY_TIMER, 0xFF);
5186 strcpy(card->driver, "H-DSP");
5187 strcpy(card->mixername, "Xilinx FPGA");
5189 if (hdsp->firmware_rev < 0xa)
5191 else if (hdsp->firmware_rev < 0x64)
5192 hdsp->card_name = "RME Hammerfall DSP";
5193 else if (hdsp->firmware_rev < 0x96) {
5194 hdsp->card_name = "RME HDSP 9652";
5197 hdsp->card_name = "RME HDSP 9632";
5198 hdsp->max_channels = 16;
5202 if ((err = pci_enable_device(pci)) < 0)
5205 pci_set_master(hdsp->pci);
5207 if ((err = pci_request_regions(pci, "hdsp")) < 0)
5209 hdsp->port = pci_resource_start(pci, 0);
5210 if ((hdsp->iobase = ioremap_nocache(hdsp->port, HDSP_IO_EXTENT)) == NULL) {
5211 dev_err(hdsp->card->dev, "unable to remap region 0x%lx-0x%lx\n",
5212 hdsp->port, hdsp->port + HDSP_IO_EXTENT - 1);
5216 if (request_irq(pci->irq, snd_hdsp_interrupt, IRQF_SHARED,
5217 KBUILD_MODNAME, hdsp)) {
5218 dev_err(hdsp->card->dev, "unable to use IRQ %d\n", pci->irq);
5222 hdsp->irq = pci->irq;
5223 hdsp->precise_ptr = 0;
5224 hdsp->use_midi_tasklet = 1;
5225 hdsp->dds_value = 0;
5227 if ((err = snd_hdsp_initialize_memory(hdsp)) < 0)
5230 if (!is_9652 && !is_9632) {
5231 /* we wait a maximum of 10 seconds to let freshly
5232 * inserted cardbus cards do their hardware init */
5233 err = hdsp_wait_for_iobox(hdsp, 1000, 10);
5238 if ((hdsp_read (hdsp, HDSP_statusRegister) & HDSP_DllError) != 0) {
5239 if ((err = hdsp_request_fw_loader(hdsp)) < 0)
5240 /* we don't fail as this can happen
5241 if userspace is not ready for
5244 dev_err(hdsp->card->dev,
5245 "couldn't get firmware from userspace. try using hdsploader\n");
5247 /* init is complete, we return */
5249 /* we defer initialization */
5250 dev_info(hdsp->card->dev,
5251 "card initialization pending : waiting for firmware\n");
5252 if ((err = snd_hdsp_create_hwdep(card, hdsp)) < 0)
5256 dev_info(hdsp->card->dev,
5257 "Firmware already present, initializing card.\n");
5258 if (hdsp_read(hdsp, HDSP_status2Register) & HDSP_version2)
5259 hdsp->io_type = RPM;
5260 else if (hdsp_read(hdsp, HDSP_status2Register) & HDSP_version1)
5261 hdsp->io_type = Multiface;
5263 hdsp->io_type = Digiface;
5267 if ((err = snd_hdsp_enable_io(hdsp)) != 0)
5271 hdsp->io_type = H9652;
5274 hdsp->io_type = H9632;
5276 if ((err = snd_hdsp_create_hwdep(card, hdsp)) < 0)
5279 snd_hdsp_initialize_channels(hdsp);
5280 snd_hdsp_initialize_midi_flush(hdsp);
5282 hdsp->state |= HDSP_FirmwareLoaded;
5284 if ((err = snd_hdsp_create_alsa_devices(card, hdsp)) < 0)
5290 static int snd_hdsp_free(struct hdsp *hdsp)
5293 /* stop the audio, and cancel all interrupts */
5294 tasklet_kill(&hdsp->midi_tasklet);
5295 hdsp->control_register &= ~(HDSP_Start|HDSP_AudioInterruptEnable|HDSP_Midi0InterruptEnable|HDSP_Midi1InterruptEnable);
5296 hdsp_write (hdsp, HDSP_controlRegister, hdsp->control_register);
5300 free_irq(hdsp->irq, (void *)hdsp);
5302 snd_hdsp_free_buffers(hdsp);
5304 release_firmware(hdsp->firmware);
5305 vfree(hdsp->fw_uploaded);
5306 iounmap(hdsp->iobase);
5309 pci_release_regions(hdsp->pci);
5311 pci_disable_device(hdsp->pci);
5315 static void snd_hdsp_card_free(struct snd_card *card)
5317 struct hdsp *hdsp = card->private_data;
5320 snd_hdsp_free(hdsp);
5323 static int snd_hdsp_probe(struct pci_dev *pci,
5324 const struct pci_device_id *pci_id)
5328 struct snd_card *card;
5331 if (dev >= SNDRV_CARDS)
5338 err = snd_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE,
5339 sizeof(struct hdsp), &card);
5343 hdsp = card->private_data;
5344 card->private_free = snd_hdsp_card_free;
5348 if ((err = snd_hdsp_create(card, hdsp)) < 0) {
5349 snd_card_free(card);
5353 strcpy(card->shortname, "Hammerfall DSP");
5354 sprintf(card->longname, "%s at 0x%lx, irq %d", hdsp->card_name,
5355 hdsp->port, hdsp->irq);
5357 if ((err = snd_card_register(card)) < 0) {
5358 snd_card_free(card);
5361 pci_set_drvdata(pci, card);
5366 static void snd_hdsp_remove(struct pci_dev *pci)
5368 snd_card_free(pci_get_drvdata(pci));
5371 static struct pci_driver hdsp_driver = {
5372 .name = KBUILD_MODNAME,
5373 .id_table = snd_hdsp_ids,
5374 .probe = snd_hdsp_probe,
5375 .remove = snd_hdsp_remove,
5378 module_pci_driver(hdsp_driver);