2 * ALSA driver for RME Hammerfall DSP audio interface(s)
4 * Copyright (c) 2002 Paul Davis
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 #include <linux/init.h>
25 #include <linux/delay.h>
26 #include <linux/interrupt.h>
27 #include <linux/slab.h>
28 #include <linux/pci.h>
29 #include <linux/firmware.h>
30 #include <linux/moduleparam.h>
32 #include <sound/core.h>
33 #include <sound/control.h>
34 #include <sound/pcm.h>
35 #include <sound/info.h>
36 #include <sound/asoundef.h>
37 #include <sound/rawmidi.h>
38 #include <sound/hwdep.h>
39 #include <sound/initval.h>
40 #include <sound/hdsp.h>
42 #include <asm/byteorder.h>
43 #include <asm/current.h>
46 static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
47 static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
48 static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP; /* Enable this card */
50 module_param_array(index, int, NULL, 0444);
51 MODULE_PARM_DESC(index, "Index value for RME Hammerfall DSP interface.");
52 module_param_array(id, charp, NULL, 0444);
53 MODULE_PARM_DESC(id, "ID string for RME Hammerfall DSP interface.");
54 module_param_array(enable, bool, NULL, 0444);
55 MODULE_PARM_DESC(enable, "Enable/disable specific Hammerfall DSP soundcards.");
56 MODULE_AUTHOR("Paul Davis <paul@linuxaudiosystems.com>, Marcus Andersson, Thomas Charbonnel <thomas@undata.org>");
57 MODULE_DESCRIPTION("RME Hammerfall DSP");
58 MODULE_LICENSE("GPL");
59 MODULE_SUPPORTED_DEVICE("{{RME Hammerfall-DSP},"
63 MODULE_FIRMWARE("multiface_firmware.bin");
64 MODULE_FIRMWARE("multiface_firmware_rev11.bin");
65 MODULE_FIRMWARE("digiface_firmware.bin");
66 MODULE_FIRMWARE("digiface_firmware_rev11.bin");
69 #define HDSP_MAX_CHANNELS 26
70 #define HDSP_MAX_DS_CHANNELS 14
71 #define HDSP_MAX_QS_CHANNELS 8
72 #define DIGIFACE_SS_CHANNELS 26
73 #define DIGIFACE_DS_CHANNELS 14
74 #define MULTIFACE_SS_CHANNELS 18
75 #define MULTIFACE_DS_CHANNELS 14
76 #define H9652_SS_CHANNELS 26
77 #define H9652_DS_CHANNELS 14
78 /* This does not include possible Analog Extension Boards
79 AEBs are detected at card initialization
81 #define H9632_SS_CHANNELS 12
82 #define H9632_DS_CHANNELS 8
83 #define H9632_QS_CHANNELS 4
85 /* Write registers. These are defined as byte-offsets from the iobase value.
87 #define HDSP_resetPointer 0
88 #define HDSP_freqReg 0
89 #define HDSP_outputBufferAddress 32
90 #define HDSP_inputBufferAddress 36
91 #define HDSP_controlRegister 64
92 #define HDSP_interruptConfirmation 96
93 #define HDSP_outputEnable 128
94 #define HDSP_control2Reg 256
95 #define HDSP_midiDataOut0 352
96 #define HDSP_midiDataOut1 356
97 #define HDSP_fifoData 368
98 #define HDSP_inputEnable 384
100 /* Read registers. These are defined as byte-offsets from the iobase value
103 #define HDSP_statusRegister 0
104 #define HDSP_timecode 128
105 #define HDSP_status2Register 192
106 #define HDSP_midiDataIn0 360
107 #define HDSP_midiDataIn1 364
108 #define HDSP_midiStatusOut0 384
109 #define HDSP_midiStatusOut1 388
110 #define HDSP_midiStatusIn0 392
111 #define HDSP_midiStatusIn1 396
112 #define HDSP_fifoStatus 400
114 /* the meters are regular i/o-mapped registers, but offset
115 considerably from the rest. the peak registers are reset
116 when read; the least-significant 4 bits are full-scale counters;
117 the actual peak value is in the most-significant 24 bits.
120 #define HDSP_playbackPeakLevel 4096 /* 26 * 32 bit values */
121 #define HDSP_inputPeakLevel 4224 /* 26 * 32 bit values */
122 #define HDSP_outputPeakLevel 4352 /* (26+2) * 32 bit values */
123 #define HDSP_playbackRmsLevel 4612 /* 26 * 64 bit values */
124 #define HDSP_inputRmsLevel 4868 /* 26 * 64 bit values */
127 /* This is for H9652 cards
128 Peak values are read downward from the base
129 Rms values are read upward
130 There are rms values for the outputs too
131 26*3 values are read in ss mode
132 14*3 in ds mode, with no gap between values
134 #define HDSP_9652_peakBase 7164
135 #define HDSP_9652_rmsBase 4096
137 /* c.f. the hdsp_9632_meters_t struct */
138 #define HDSP_9632_metersBase 4096
140 #define HDSP_IO_EXTENT 7168
142 /* control2 register bits */
144 #define HDSP_TMS 0x01
145 #define HDSP_TCK 0x02
146 #define HDSP_TDI 0x04
147 #define HDSP_JTAG 0x08
148 #define HDSP_PWDN 0x10
149 #define HDSP_PROGRAM 0x020
150 #define HDSP_CONFIG_MODE_0 0x040
151 #define HDSP_CONFIG_MODE_1 0x080
152 #define HDSP_VERSION_BIT 0x100
153 #define HDSP_BIGENDIAN_MODE 0x200
154 #define HDSP_RD_MULTIPLE 0x400
155 #define HDSP_9652_ENABLE_MIXER 0x800
156 #define HDSP_TDO 0x10000000
158 #define HDSP_S_PROGRAM (HDSP_PROGRAM|HDSP_CONFIG_MODE_0)
159 #define HDSP_S_LOAD (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 #define HDSP_ADGainMask (HDSP_ADGain0|HDSP_ADGain1)
195 #define HDSP_ADGainMinus10dBV HDSP_ADGainMask
196 #define HDSP_ADGainPlus4dBu (HDSP_ADGain0)
197 #define HDSP_ADGainLowGain 0
199 #define HDSP_DAGainMask (HDSP_DAGain0|HDSP_DAGain1)
200 #define HDSP_DAGainHighGain HDSP_DAGainMask
201 #define HDSP_DAGainPlus4dBu (HDSP_DAGain0)
202 #define HDSP_DAGainMinus10dBV 0
204 #define HDSP_PhoneGainMask (HDSP_PhoneGain0|HDSP_PhoneGain1)
205 #define HDSP_PhoneGain0dB HDSP_PhoneGainMask
206 #define HDSP_PhoneGainMinus6dB (HDSP_PhoneGain0)
207 #define HDSP_PhoneGainMinus12dB 0
209 #define HDSP_LatencyMask (HDSP_Latency0|HDSP_Latency1|HDSP_Latency2)
210 #define HDSP_FrequencyMask (HDSP_Frequency0|HDSP_Frequency1|HDSP_DoubleSpeed|HDSP_QuadSpeed)
212 #define HDSP_SPDIFInputMask (HDSP_SPDIFInputSelect0|HDSP_SPDIFInputSelect1)
213 #define HDSP_SPDIFInputADAT1 0
214 #define HDSP_SPDIFInputCoaxial (HDSP_SPDIFInputSelect0)
215 #define HDSP_SPDIFInputCdrom (HDSP_SPDIFInputSelect1)
216 #define HDSP_SPDIFInputAES (HDSP_SPDIFInputSelect0|HDSP_SPDIFInputSelect1)
218 #define HDSP_SyncRefMask (HDSP_SyncRef0|HDSP_SyncRef1|HDSP_SyncRef2)
219 #define HDSP_SyncRef_ADAT1 0
220 #define HDSP_SyncRef_ADAT2 (HDSP_SyncRef0)
221 #define HDSP_SyncRef_ADAT3 (HDSP_SyncRef1)
222 #define HDSP_SyncRef_SPDIF (HDSP_SyncRef0|HDSP_SyncRef1)
223 #define HDSP_SyncRef_WORD (HDSP_SyncRef2)
224 #define HDSP_SyncRef_ADAT_SYNC (HDSP_SyncRef0|HDSP_SyncRef2)
226 /* Sample Clock Sources */
228 #define HDSP_CLOCK_SOURCE_AUTOSYNC 0
229 #define HDSP_CLOCK_SOURCE_INTERNAL_32KHZ 1
230 #define HDSP_CLOCK_SOURCE_INTERNAL_44_1KHZ 2
231 #define HDSP_CLOCK_SOURCE_INTERNAL_48KHZ 3
232 #define HDSP_CLOCK_SOURCE_INTERNAL_64KHZ 4
233 #define HDSP_CLOCK_SOURCE_INTERNAL_88_2KHZ 5
234 #define HDSP_CLOCK_SOURCE_INTERNAL_96KHZ 6
235 #define HDSP_CLOCK_SOURCE_INTERNAL_128KHZ 7
236 #define HDSP_CLOCK_SOURCE_INTERNAL_176_4KHZ 8
237 #define HDSP_CLOCK_SOURCE_INTERNAL_192KHZ 9
239 /* Preferred sync reference choices - used by "pref_sync_ref" control switch */
241 #define HDSP_SYNC_FROM_WORD 0
242 #define HDSP_SYNC_FROM_SPDIF 1
243 #define HDSP_SYNC_FROM_ADAT1 2
244 #define HDSP_SYNC_FROM_ADAT_SYNC 3
245 #define HDSP_SYNC_FROM_ADAT2 4
246 #define HDSP_SYNC_FROM_ADAT3 5
248 /* SyncCheck status */
250 #define HDSP_SYNC_CHECK_NO_LOCK 0
251 #define HDSP_SYNC_CHECK_LOCK 1
252 #define HDSP_SYNC_CHECK_SYNC 2
254 /* AutoSync references - used by "autosync_ref" control switch */
256 #define HDSP_AUTOSYNC_FROM_WORD 0
257 #define HDSP_AUTOSYNC_FROM_ADAT_SYNC 1
258 #define HDSP_AUTOSYNC_FROM_SPDIF 2
259 #define HDSP_AUTOSYNC_FROM_NONE 3
260 #define HDSP_AUTOSYNC_FROM_ADAT1 4
261 #define HDSP_AUTOSYNC_FROM_ADAT2 5
262 #define HDSP_AUTOSYNC_FROM_ADAT3 6
264 /* Possible sources of S/PDIF input */
266 #define HDSP_SPDIFIN_OPTICAL 0 /* optical (ADAT1) */
267 #define HDSP_SPDIFIN_COAXIAL 1 /* coaxial (RCA) */
268 #define HDSP_SPDIFIN_INTERNAL 2 /* internal (CDROM) */
269 #define HDSP_SPDIFIN_AES 3 /* xlr for H9632 (AES)*/
271 #define HDSP_Frequency32KHz HDSP_Frequency0
272 #define HDSP_Frequency44_1KHz HDSP_Frequency1
273 #define HDSP_Frequency48KHz (HDSP_Frequency1|HDSP_Frequency0)
274 #define HDSP_Frequency64KHz (HDSP_DoubleSpeed|HDSP_Frequency0)
275 #define HDSP_Frequency88_2KHz (HDSP_DoubleSpeed|HDSP_Frequency1)
276 #define HDSP_Frequency96KHz (HDSP_DoubleSpeed|HDSP_Frequency1|HDSP_Frequency0)
277 /* For H9632 cards */
278 #define HDSP_Frequency128KHz (HDSP_QuadSpeed|HDSP_DoubleSpeed|HDSP_Frequency0)
279 #define HDSP_Frequency176_4KHz (HDSP_QuadSpeed|HDSP_DoubleSpeed|HDSP_Frequency1)
280 #define HDSP_Frequency192KHz (HDSP_QuadSpeed|HDSP_DoubleSpeed|HDSP_Frequency1|HDSP_Frequency0)
281 /* RME says n = 104857600000000, but in the windows MADI driver, I see:
282 return 104857600000000 / rate; // 100 MHz
283 return 110100480000000 / rate; // 105 MHz
285 #define DDS_NUMERATOR 104857600000000ULL; /* = 2^20 * 10^8 */
287 #define hdsp_encode_latency(x) (((x)<<1) & HDSP_LatencyMask)
288 #define hdsp_decode_latency(x) (((x) & HDSP_LatencyMask)>>1)
290 #define hdsp_encode_spdif_in(x) (((x)&0x3)<<14)
291 #define hdsp_decode_spdif_in(x) (((x)>>14)&0x3)
293 /* Status Register bits */
295 #define HDSP_audioIRQPending (1<<0)
296 #define HDSP_Lock2 (1<<1) /* this is for Digiface and H9652 */
297 #define HDSP_spdifFrequency3 HDSP_Lock2 /* this is for H9632 only */
298 #define HDSP_Lock1 (1<<2)
299 #define HDSP_Lock0 (1<<3)
300 #define HDSP_SPDIFSync (1<<4)
301 #define HDSP_TimecodeLock (1<<5)
302 #define HDSP_BufferPositionMask 0x000FFC0 /* Bit 6..15 : h/w buffer pointer */
303 #define HDSP_Sync2 (1<<16)
304 #define HDSP_Sync1 (1<<17)
305 #define HDSP_Sync0 (1<<18)
306 #define HDSP_DoubleSpeedStatus (1<<19)
307 #define HDSP_ConfigError (1<<20)
308 #define HDSP_DllError (1<<21)
309 #define HDSP_spdifFrequency0 (1<<22)
310 #define HDSP_spdifFrequency1 (1<<23)
311 #define HDSP_spdifFrequency2 (1<<24)
312 #define HDSP_SPDIFErrorFlag (1<<25)
313 #define HDSP_BufferID (1<<26)
314 #define HDSP_TimecodeSync (1<<27)
315 #define HDSP_AEBO (1<<28) /* H9632 specific Analog Extension Boards */
316 #define HDSP_AEBI (1<<29) /* 0 = present, 1 = absent */
317 #define HDSP_midi0IRQPending (1<<30)
318 #define HDSP_midi1IRQPending (1<<31)
320 #define HDSP_spdifFrequencyMask (HDSP_spdifFrequency0|HDSP_spdifFrequency1|HDSP_spdifFrequency2)
321 #define HDSP_spdifFrequencyMask_9632 (HDSP_spdifFrequency0|\
322 HDSP_spdifFrequency1|\
323 HDSP_spdifFrequency2|\
324 HDSP_spdifFrequency3)
326 #define HDSP_spdifFrequency32KHz (HDSP_spdifFrequency0)
327 #define HDSP_spdifFrequency44_1KHz (HDSP_spdifFrequency1)
328 #define HDSP_spdifFrequency48KHz (HDSP_spdifFrequency0|HDSP_spdifFrequency1)
330 #define HDSP_spdifFrequency64KHz (HDSP_spdifFrequency2)
331 #define HDSP_spdifFrequency88_2KHz (HDSP_spdifFrequency0|HDSP_spdifFrequency2)
332 #define HDSP_spdifFrequency96KHz (HDSP_spdifFrequency2|HDSP_spdifFrequency1)
334 /* This is for H9632 cards */
335 #define HDSP_spdifFrequency128KHz (HDSP_spdifFrequency0|\
336 HDSP_spdifFrequency1|\
337 HDSP_spdifFrequency2)
338 #define HDSP_spdifFrequency176_4KHz HDSP_spdifFrequency3
339 #define HDSP_spdifFrequency192KHz (HDSP_spdifFrequency3|HDSP_spdifFrequency0)
341 /* Status2 Register bits */
343 #define HDSP_version0 (1<<0)
344 #define HDSP_version1 (1<<1)
345 #define HDSP_version2 (1<<2)
346 #define HDSP_wc_lock (1<<3)
347 #define HDSP_wc_sync (1<<4)
348 #define HDSP_inp_freq0 (1<<5)
349 #define HDSP_inp_freq1 (1<<6)
350 #define HDSP_inp_freq2 (1<<7)
351 #define HDSP_SelSyncRef0 (1<<8)
352 #define HDSP_SelSyncRef1 (1<<9)
353 #define HDSP_SelSyncRef2 (1<<10)
355 #define HDSP_wc_valid (HDSP_wc_lock|HDSP_wc_sync)
357 #define HDSP_systemFrequencyMask (HDSP_inp_freq0|HDSP_inp_freq1|HDSP_inp_freq2)
358 #define HDSP_systemFrequency32 (HDSP_inp_freq0)
359 #define HDSP_systemFrequency44_1 (HDSP_inp_freq1)
360 #define HDSP_systemFrequency48 (HDSP_inp_freq0|HDSP_inp_freq1)
361 #define HDSP_systemFrequency64 (HDSP_inp_freq2)
362 #define HDSP_systemFrequency88_2 (HDSP_inp_freq0|HDSP_inp_freq2)
363 #define HDSP_systemFrequency96 (HDSP_inp_freq1|HDSP_inp_freq2)
364 /* FIXME : more values for 9632 cards ? */
366 #define HDSP_SelSyncRefMask (HDSP_SelSyncRef0|HDSP_SelSyncRef1|HDSP_SelSyncRef2)
367 #define HDSP_SelSyncRef_ADAT1 0
368 #define HDSP_SelSyncRef_ADAT2 (HDSP_SelSyncRef0)
369 #define HDSP_SelSyncRef_ADAT3 (HDSP_SelSyncRef1)
370 #define HDSP_SelSyncRef_SPDIF (HDSP_SelSyncRef0|HDSP_SelSyncRef1)
371 #define HDSP_SelSyncRef_WORD (HDSP_SelSyncRef2)
372 #define HDSP_SelSyncRef_ADAT_SYNC (HDSP_SelSyncRef0|HDSP_SelSyncRef2)
374 /* Card state flags */
376 #define HDSP_InitializationComplete (1<<0)
377 #define HDSP_FirmwareLoaded (1<<1)
378 #define HDSP_FirmwareCached (1<<2)
380 /* FIFO wait times, defined in terms of 1/10ths of msecs */
382 #define HDSP_LONG_WAIT 5000
383 #define HDSP_SHORT_WAIT 30
385 #define UNITY_GAIN 32768
386 #define MINUS_INFINITY_GAIN 0
388 /* the size of a substream (1 mono data stream) */
390 #define HDSP_CHANNEL_BUFFER_SAMPLES (16*1024)
391 #define HDSP_CHANNEL_BUFFER_BYTES (4*HDSP_CHANNEL_BUFFER_SAMPLES)
393 /* the size of the area we need to allocate for DMA transfers. the
394 size is the same regardless of the number of channels - the
395 Multiface still uses the same memory area.
397 Note that we allocate 1 more channel than is apparently needed
398 because the h/w seems to write 1 byte beyond the end of the last
402 #define HDSP_DMA_AREA_BYTES ((HDSP_MAX_CHANNELS+1) * HDSP_CHANNEL_BUFFER_BYTES)
403 #define HDSP_DMA_AREA_KILOBYTES (HDSP_DMA_AREA_BYTES/1024)
405 /* use hotplug firmeare loader? */
406 #if defined(CONFIG_FW_LOADER) || defined(CONFIG_FW_LOADER_MODULE)
407 #if !defined(HDSP_USE_HWDEP_LOADER) && !defined(CONFIG_SND_HDSP)
408 #define HDSP_FW_LOADER
412 struct hdsp_9632_meters {
414 u32 playback_peak[16];
418 u32 input_rms_low[16];
419 u32 playback_rms_low[16];
420 u32 output_rms_low[16];
422 u32 input_rms_high[16];
423 u32 playback_rms_high[16];
424 u32 output_rms_high[16];
425 u32 xxx_rms_high[16];
431 struct snd_rawmidi *rmidi;
432 struct snd_rawmidi_substream *input;
433 struct snd_rawmidi_substream *output;
434 char istimer; /* timer in use */
435 struct timer_list timer;
442 struct snd_pcm_substream *capture_substream;
443 struct snd_pcm_substream *playback_substream;
444 struct hdsp_midi midi[2];
445 struct tasklet_struct midi_tasklet;
446 int use_midi_tasklet;
448 u32 control_register; /* cached value */
449 u32 control2_register; /* cached value */
451 u32 creg_spdif_stream;
452 int clock_source_locked;
453 char *card_name; /* digiface/multiface */
454 enum HDSP_IO_Type io_type; /* ditto, but for code use */
455 unsigned short firmware_rev;
456 unsigned short state; /* stores state bits */
457 u32 firmware_cache[24413]; /* this helps recover from accidental iobox power failure */
458 size_t period_bytes; /* guess what this is */
459 unsigned char max_channels;
460 unsigned char qs_in_channels; /* quad speed mode for H9632 */
461 unsigned char ds_in_channels;
462 unsigned char ss_in_channels; /* different for multiface/digiface */
463 unsigned char qs_out_channels;
464 unsigned char ds_out_channels;
465 unsigned char ss_out_channels;
467 struct snd_dma_buffer capture_dma_buf;
468 struct snd_dma_buffer playback_dma_buf;
469 unsigned char *capture_buffer; /* suitably aligned address */
470 unsigned char *playback_buffer; /* suitably aligned address */
475 int system_sample_rate;
480 void __iomem *iobase;
481 struct snd_card *card;
483 struct snd_hwdep *hwdep;
485 struct snd_kcontrol *spdif_ctl;
486 unsigned short mixer_matrix[HDSP_MATRIX_MIXER_SIZE];
487 unsigned int dds_value; /* last value written to freq register */
490 /* These tables map the ALSA channels 1..N to the channels that we
491 need to use in order to find the relevant channel buffer. RME
492 refer to this kind of mapping as between "the ADAT channel and
493 the DMA channel." We index it using the logical audio channel,
494 and the value is the DMA channel (i.e. channel buffer number)
495 where the data for that channel can be read/written from/to.
498 static char channel_map_df_ss[HDSP_MAX_CHANNELS] = {
499 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
500 18, 19, 20, 21, 22, 23, 24, 25
503 static char channel_map_mf_ss[HDSP_MAX_CHANNELS] = { /* Multiface */
505 0, 1, 2, 3, 4, 5, 6, 7,
507 16, 17, 18, 19, 20, 21, 22, 23,
510 -1, -1, -1, -1, -1, -1, -1, -1
513 static char channel_map_ds[HDSP_MAX_CHANNELS] = {
514 /* ADAT channels are remapped */
515 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23,
516 /* channels 12 and 13 are S/PDIF */
518 /* others don't exist */
519 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
522 static char channel_map_H9632_ss[HDSP_MAX_CHANNELS] = {
524 0, 1, 2, 3, 4, 5, 6, 7,
529 /* AO4S-192 and AI4S-192 extension boards */
531 /* others don't exist */
532 -1, -1, -1, -1, -1, -1, -1, -1,
536 static char channel_map_H9632_ds[HDSP_MAX_CHANNELS] = {
543 /* AO4S-192 and AI4S-192 extension boards */
545 /* others don't exist */
546 -1, -1, -1, -1, -1, -1, -1, -1,
547 -1, -1, -1, -1, -1, -1
550 static char channel_map_H9632_qs[HDSP_MAX_CHANNELS] = {
551 /* ADAT is disabled in this mode */
556 /* AO4S-192 and AI4S-192 extension boards */
558 /* others don't exist */
559 -1, -1, -1, -1, -1, -1, -1, -1,
560 -1, -1, -1, -1, -1, -1, -1, -1,
564 static int snd_hammerfall_get_buffer(struct pci_dev *pci, struct snd_dma_buffer *dmab, size_t size)
566 dmab->dev.type = SNDRV_DMA_TYPE_DEV;
567 dmab->dev.dev = snd_dma_pci_data(pci);
568 if (snd_dma_get_reserved_buf(dmab, snd_dma_pci_buf_id(pci))) {
569 if (dmab->bytes >= size)
572 if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(pci),
578 static void snd_hammerfall_free_buffer(struct snd_dma_buffer *dmab, struct pci_dev *pci)
581 dmab->dev.dev = NULL; /* make it anonymous */
582 snd_dma_reserve_buf(dmab, snd_dma_pci_buf_id(pci));
587 static struct pci_device_id snd_hdsp_ids[] = {
589 .vendor = PCI_VENDOR_ID_XILINX,
590 .device = PCI_DEVICE_ID_XILINX_HAMMERFALL_DSP,
591 .subvendor = PCI_ANY_ID,
592 .subdevice = PCI_ANY_ID,
593 }, /* RME Hammerfall-DSP */
597 MODULE_DEVICE_TABLE(pci, snd_hdsp_ids);
600 static int snd_hdsp_create_alsa_devices(struct snd_card *card, struct hdsp *hdsp);
601 static int snd_hdsp_create_pcm(struct snd_card *card, struct hdsp *hdsp);
602 static int snd_hdsp_enable_io (struct hdsp *hdsp);
603 static void snd_hdsp_initialize_midi_flush (struct hdsp *hdsp);
604 static void snd_hdsp_initialize_channels (struct hdsp *hdsp);
605 static int hdsp_fifo_wait(struct hdsp *hdsp, int count, int timeout);
606 static int hdsp_autosync_ref(struct hdsp *hdsp);
607 static int snd_hdsp_set_defaults(struct hdsp *hdsp);
608 static void snd_hdsp_9652_enable_mixer (struct hdsp *hdsp);
610 static int hdsp_playback_to_output_key (struct hdsp *hdsp, int in, int out)
612 switch (hdsp->io_type) {
616 if (hdsp->firmware_rev == 0xa)
617 return (64 * out) + (32 + (in));
619 return (52 * out) + (26 + (in));
621 return (32 * out) + (16 + (in));
623 return (52 * out) + (26 + (in));
627 static int hdsp_input_to_output_key (struct hdsp *hdsp, int in, int out)
629 switch (hdsp->io_type) {
633 if (hdsp->firmware_rev == 0xa)
634 return (64 * out) + in;
636 return (52 * out) + in;
638 return (32 * out) + in;
640 return (52 * out) + in;
644 static void hdsp_write(struct hdsp *hdsp, int reg, int val)
646 writel(val, hdsp->iobase + reg);
649 static unsigned int hdsp_read(struct hdsp *hdsp, int reg)
651 return readl (hdsp->iobase + reg);
654 static int hdsp_check_for_iobox (struct hdsp *hdsp)
657 if (hdsp->io_type == H9652 || hdsp->io_type == H9632) return 0;
658 if (hdsp_read (hdsp, HDSP_statusRegister) & HDSP_ConfigError) {
659 snd_printk ("Hammerfall-DSP: no Digiface or Multiface connected!\n");
660 hdsp->state &= ~HDSP_FirmwareLoaded;
667 static int snd_hdsp_load_firmware_from_cache(struct hdsp *hdsp) {
672 if ((hdsp_read (hdsp, HDSP_statusRegister) & HDSP_DllError) != 0) {
674 snd_printk ("Hammerfall-DSP: loading firmware\n");
676 hdsp_write (hdsp, HDSP_control2Reg, HDSP_S_PROGRAM);
677 hdsp_write (hdsp, HDSP_fifoData, 0);
679 if (hdsp_fifo_wait (hdsp, 0, HDSP_LONG_WAIT)) {
680 snd_printk ("Hammerfall-DSP: timeout waiting for download preparation\n");
684 hdsp_write (hdsp, HDSP_control2Reg, HDSP_S_LOAD);
686 for (i = 0; i < 24413; ++i) {
687 hdsp_write(hdsp, HDSP_fifoData, hdsp->firmware_cache[i]);
688 if (hdsp_fifo_wait (hdsp, 127, HDSP_LONG_WAIT)) {
689 snd_printk ("Hammerfall-DSP: timeout during firmware loading\n");
696 if (hdsp_fifo_wait (hdsp, 0, HDSP_LONG_WAIT)) {
697 snd_printk ("Hammerfall-DSP: timeout at end of firmware loading\n");
701 #ifdef SNDRV_BIG_ENDIAN
702 hdsp->control2_register = HDSP_BIGENDIAN_MODE;
704 hdsp->control2_register = 0;
706 hdsp_write (hdsp, HDSP_control2Reg, hdsp->control2_register);
707 snd_printk ("Hammerfall-DSP: finished firmware loading\n");
710 if (hdsp->state & HDSP_InitializationComplete) {
711 snd_printk(KERN_INFO "Hammerfall-DSP: firmware loaded from cache, restoring defaults\n");
712 spin_lock_irqsave(&hdsp->lock, flags);
713 snd_hdsp_set_defaults(hdsp);
714 spin_unlock_irqrestore(&hdsp->lock, flags);
717 hdsp->state |= HDSP_FirmwareLoaded;
722 static int hdsp_get_iobox_version (struct hdsp *hdsp)
724 if ((hdsp_read (hdsp, HDSP_statusRegister) & HDSP_DllError) != 0) {
726 hdsp_write (hdsp, HDSP_control2Reg, HDSP_PROGRAM);
727 hdsp_write (hdsp, HDSP_fifoData, 0);
728 if (hdsp_fifo_wait (hdsp, 0, HDSP_SHORT_WAIT) < 0)
731 hdsp_write (hdsp, HDSP_control2Reg, HDSP_S_LOAD);
732 hdsp_write (hdsp, HDSP_fifoData, 0);
734 if (hdsp_fifo_wait (hdsp, 0, HDSP_SHORT_WAIT)) {
735 hdsp->io_type = Multiface;
736 hdsp_write (hdsp, HDSP_control2Reg, HDSP_VERSION_BIT);
737 hdsp_write (hdsp, HDSP_control2Reg, HDSP_S_LOAD);
738 hdsp_fifo_wait (hdsp, 0, HDSP_SHORT_WAIT);
740 hdsp->io_type = Digiface;
743 /* firmware was already loaded, get iobox type */
744 if (hdsp_read(hdsp, HDSP_status2Register) & HDSP_version1)
745 hdsp->io_type = Multiface;
747 hdsp->io_type = Digiface;
753 #ifdef HDSP_FW_LOADER
754 static int hdsp_request_fw_loader(struct hdsp *hdsp);
757 static int hdsp_check_for_firmware (struct hdsp *hdsp, int load_on_demand)
759 if (hdsp->io_type == H9652 || hdsp->io_type == H9632)
761 if ((hdsp_read (hdsp, HDSP_statusRegister) & HDSP_DllError) != 0) {
762 hdsp->state &= ~HDSP_FirmwareLoaded;
763 if (! load_on_demand)
765 snd_printk(KERN_ERR "Hammerfall-DSP: firmware not present.\n");
766 /* try to load firmware */
767 if (! (hdsp->state & HDSP_FirmwareCached)) {
768 #ifdef HDSP_FW_LOADER
769 if (! hdsp_request_fw_loader(hdsp))
773 "Hammerfall-DSP: No firmware loaded nor "
774 "cached, please upload firmware.\n");
777 if (snd_hdsp_load_firmware_from_cache(hdsp) != 0) {
779 "Hammerfall-DSP: Firmware loading from "
780 "cache failed, please upload manually.\n");
788 static int hdsp_fifo_wait(struct hdsp *hdsp, int count, int timeout)
792 /* the fifoStatus registers reports on how many words
793 are available in the command FIFO.
796 for (i = 0; i < timeout; i++) {
798 if ((int)(hdsp_read (hdsp, HDSP_fifoStatus) & 0xff) <= count)
801 /* not very friendly, but we only do this during a firmware
802 load and changing the mixer, so we just put up with it.
808 snd_printk ("Hammerfall-DSP: wait for FIFO status <= %d failed after %d iterations\n",
813 static int hdsp_read_gain (struct hdsp *hdsp, unsigned int addr)
815 if (addr >= HDSP_MATRIX_MIXER_SIZE)
818 return hdsp->mixer_matrix[addr];
821 static int hdsp_write_gain(struct hdsp *hdsp, unsigned int addr, unsigned short data)
825 if (addr >= HDSP_MATRIX_MIXER_SIZE)
828 if (hdsp->io_type == H9652 || hdsp->io_type == H9632) {
830 /* from martin bjornsen:
832 "You can only write dwords to the
833 mixer memory which contain two
834 mixer values in the low and high
835 word. So if you want to change
836 value 0 you have to read value 1
837 from the cache and write both to
838 the first dword in the mixer
842 if (hdsp->io_type == H9632 && addr >= 512)
845 if (hdsp->io_type == H9652 && addr >= 1352)
848 hdsp->mixer_matrix[addr] = data;
851 /* `addr' addresses a 16-bit wide address, but
852 the address space accessed via hdsp_write
853 uses byte offsets. put another way, addr
854 varies from 0 to 1351, but to access the
855 corresponding memory location, we need
856 to access 0 to 2703 ...
860 hdsp_write (hdsp, 4096 + (ad*4),
861 (hdsp->mixer_matrix[(addr&0x7fe)+1] << 16) +
862 hdsp->mixer_matrix[addr&0x7fe]);
868 ad = (addr << 16) + data;
870 if (hdsp_fifo_wait(hdsp, 127, HDSP_LONG_WAIT))
873 hdsp_write (hdsp, HDSP_fifoData, ad);
874 hdsp->mixer_matrix[addr] = data;
881 static int snd_hdsp_use_is_exclusive(struct hdsp *hdsp)
886 spin_lock_irqsave(&hdsp->lock, flags);
887 if ((hdsp->playback_pid != hdsp->capture_pid) &&
888 (hdsp->playback_pid >= 0) && (hdsp->capture_pid >= 0))
890 spin_unlock_irqrestore(&hdsp->lock, flags);
894 static int hdsp_spdif_sample_rate(struct hdsp *hdsp)
896 unsigned int status = hdsp_read(hdsp, HDSP_statusRegister);
897 unsigned int rate_bits = (status & HDSP_spdifFrequencyMask);
899 /* For the 9632, the mask is different */
900 if (hdsp->io_type == H9632)
901 rate_bits = (status & HDSP_spdifFrequencyMask_9632);
903 if (status & HDSP_SPDIFErrorFlag)
907 case HDSP_spdifFrequency32KHz: return 32000;
908 case HDSP_spdifFrequency44_1KHz: return 44100;
909 case HDSP_spdifFrequency48KHz: return 48000;
910 case HDSP_spdifFrequency64KHz: return 64000;
911 case HDSP_spdifFrequency88_2KHz: return 88200;
912 case HDSP_spdifFrequency96KHz: return 96000;
913 case HDSP_spdifFrequency128KHz:
914 if (hdsp->io_type == H9632) return 128000;
916 case HDSP_spdifFrequency176_4KHz:
917 if (hdsp->io_type == H9632) return 176400;
919 case HDSP_spdifFrequency192KHz:
920 if (hdsp->io_type == H9632) return 192000;
925 snd_printk ("Hammerfall-DSP: unknown spdif frequency status; bits = 0x%x, status = 0x%x\n", rate_bits, status);
929 static int hdsp_external_sample_rate(struct hdsp *hdsp)
931 unsigned int status2 = hdsp_read(hdsp, HDSP_status2Register);
932 unsigned int rate_bits = status2 & HDSP_systemFrequencyMask;
934 /* For the 9632 card, there seems to be no bit for indicating external
935 * sample rate greater than 96kHz. The card reports the corresponding
936 * single speed. So the best means seems to get spdif rate when
937 * autosync reference is spdif */
938 if (hdsp->io_type == H9632 &&
939 hdsp_autosync_ref(hdsp) == HDSP_AUTOSYNC_FROM_SPDIF)
940 return hdsp_spdif_sample_rate(hdsp);
943 case HDSP_systemFrequency32: return 32000;
944 case HDSP_systemFrequency44_1: return 44100;
945 case HDSP_systemFrequency48: return 48000;
946 case HDSP_systemFrequency64: return 64000;
947 case HDSP_systemFrequency88_2: return 88200;
948 case HDSP_systemFrequency96: return 96000;
954 static void hdsp_compute_period_size(struct hdsp *hdsp)
956 hdsp->period_bytes = 1 << ((hdsp_decode_latency(hdsp->control_register) + 8));
959 static snd_pcm_uframes_t hdsp_hw_pointer(struct hdsp *hdsp)
963 position = hdsp_read(hdsp, HDSP_statusRegister);
965 if (!hdsp->precise_ptr)
966 return (position & HDSP_BufferID) ? (hdsp->period_bytes / 4) : 0;
968 position &= HDSP_BufferPositionMask;
970 position &= (hdsp->period_bytes/2) - 1;
974 static void hdsp_reset_hw_pointer(struct hdsp *hdsp)
976 hdsp_write (hdsp, HDSP_resetPointer, 0);
977 if (hdsp->io_type == H9632 && hdsp->firmware_rev >= 152)
978 /* HDSP_resetPointer = HDSP_freqReg, which is strange and
979 * requires (?) to write again DDS value after a reset pointer
980 * (at least, it works like this) */
981 hdsp_write (hdsp, HDSP_freqReg, hdsp->dds_value);
984 static void hdsp_start_audio(struct hdsp *s)
986 s->control_register |= (HDSP_AudioInterruptEnable | HDSP_Start);
987 hdsp_write(s, HDSP_controlRegister, s->control_register);
990 static void hdsp_stop_audio(struct hdsp *s)
992 s->control_register &= ~(HDSP_Start | HDSP_AudioInterruptEnable);
993 hdsp_write(s, HDSP_controlRegister, s->control_register);
996 static void hdsp_silence_playback(struct hdsp *hdsp)
998 memset(hdsp->playback_buffer, 0, HDSP_DMA_AREA_BYTES);
1001 static int hdsp_set_interrupt_interval(struct hdsp *s, unsigned int frames)
1005 spin_lock_irq(&s->lock);
1014 s->control_register &= ~HDSP_LatencyMask;
1015 s->control_register |= hdsp_encode_latency(n);
1017 hdsp_write(s, HDSP_controlRegister, s->control_register);
1019 hdsp_compute_period_size(s);
1021 spin_unlock_irq(&s->lock);
1026 static void hdsp_set_dds_value(struct hdsp *hdsp, int rate)
1033 else if (rate >= 56000)
1037 div64_32(&n, rate, &r);
1038 /* n should be less than 2^32 for being written to FREQ register */
1039 snd_BUG_ON(n >> 32);
1040 /* HDSP_freqReg and HDSP_resetPointer are the same, so keep the DDS
1041 value to write it after a reset */
1042 hdsp->dds_value = n;
1043 hdsp_write(hdsp, HDSP_freqReg, hdsp->dds_value);
1046 static int hdsp_set_rate(struct hdsp *hdsp, int rate, int called_internally)
1048 int reject_if_open = 0;
1052 /* ASSUMPTION: hdsp->lock is either held, or
1053 there is no need for it (e.g. during module
1057 if (!(hdsp->control_register & HDSP_ClockModeMaster)) {
1058 if (called_internally) {
1059 /* request from ctl or card initialization */
1060 snd_printk(KERN_ERR "Hammerfall-DSP: device is not running as a clock master: cannot set sample rate.\n");
1063 /* hw_param request while in AutoSync mode */
1064 int external_freq = hdsp_external_sample_rate(hdsp);
1065 int spdif_freq = hdsp_spdif_sample_rate(hdsp);
1067 if ((spdif_freq == external_freq*2) && (hdsp_autosync_ref(hdsp) >= HDSP_AUTOSYNC_FROM_ADAT1))
1068 snd_printk(KERN_INFO "Hammerfall-DSP: Detected ADAT in double speed mode\n");
1069 else if (hdsp->io_type == H9632 && (spdif_freq == external_freq*4) && (hdsp_autosync_ref(hdsp) >= HDSP_AUTOSYNC_FROM_ADAT1))
1070 snd_printk(KERN_INFO "Hammerfall-DSP: Detected ADAT in quad speed mode\n");
1071 else if (rate != external_freq) {
1072 snd_printk(KERN_INFO "Hammerfall-DSP: No AutoSync source for requested rate\n");
1078 current_rate = hdsp->system_sample_rate;
1080 /* Changing from a "single speed" to a "double speed" rate is
1081 not allowed if any substreams are open. This is because
1082 such a change causes a shift in the location of
1083 the DMA buffers and a reduction in the number of available
1086 Note that a similar but essentially insoluble problem
1087 exists for externally-driven rate changes. All we can do
1088 is to flag rate changes in the read/write routines. */
1090 if (rate > 96000 && hdsp->io_type != H9632)
1095 if (current_rate > 48000)
1097 rate_bits = HDSP_Frequency32KHz;
1100 if (current_rate > 48000)
1102 rate_bits = HDSP_Frequency44_1KHz;
1105 if (current_rate > 48000)
1107 rate_bits = HDSP_Frequency48KHz;
1110 if (current_rate <= 48000 || current_rate > 96000)
1112 rate_bits = HDSP_Frequency64KHz;
1115 if (current_rate <= 48000 || current_rate > 96000)
1117 rate_bits = HDSP_Frequency88_2KHz;
1120 if (current_rate <= 48000 || current_rate > 96000)
1122 rate_bits = HDSP_Frequency96KHz;
1125 if (current_rate < 128000)
1127 rate_bits = HDSP_Frequency128KHz;
1130 if (current_rate < 128000)
1132 rate_bits = HDSP_Frequency176_4KHz;
1135 if (current_rate < 128000)
1137 rate_bits = HDSP_Frequency192KHz;
1143 if (reject_if_open && (hdsp->capture_pid >= 0 || hdsp->playback_pid >= 0)) {
1144 snd_printk ("Hammerfall-DSP: cannot change speed mode (capture PID = %d, playback PID = %d)\n",
1146 hdsp->playback_pid);
1150 hdsp->control_register &= ~HDSP_FrequencyMask;
1151 hdsp->control_register |= rate_bits;
1152 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
1154 /* For HDSP9632 rev 152, need to set DDS value in FREQ register */
1155 if (hdsp->io_type == H9632 && hdsp->firmware_rev >= 152)
1156 hdsp_set_dds_value(hdsp, rate);
1158 if (rate >= 128000) {
1159 hdsp->channel_map = channel_map_H9632_qs;
1160 } else if (rate > 48000) {
1161 if (hdsp->io_type == H9632)
1162 hdsp->channel_map = channel_map_H9632_ds;
1164 hdsp->channel_map = channel_map_ds;
1166 switch (hdsp->io_type) {
1168 hdsp->channel_map = channel_map_mf_ss;
1172 hdsp->channel_map = channel_map_df_ss;
1175 hdsp->channel_map = channel_map_H9632_ss;
1178 /* should never happen */
1183 hdsp->system_sample_rate = rate;
1188 /*----------------------------------------------------------------------------
1190 ----------------------------------------------------------------------------*/
1192 static unsigned char snd_hdsp_midi_read_byte (struct hdsp *hdsp, int id)
1194 /* the hardware already does the relevant bit-mask with 0xff */
1196 return hdsp_read(hdsp, HDSP_midiDataIn1);
1198 return hdsp_read(hdsp, HDSP_midiDataIn0);
1201 static void snd_hdsp_midi_write_byte (struct hdsp *hdsp, int id, int val)
1203 /* the hardware already does the relevant bit-mask with 0xff */
1205 hdsp_write(hdsp, HDSP_midiDataOut1, val);
1207 hdsp_write(hdsp, HDSP_midiDataOut0, val);
1210 static int snd_hdsp_midi_input_available (struct hdsp *hdsp, int id)
1213 return (hdsp_read(hdsp, HDSP_midiStatusIn1) & 0xff);
1215 return (hdsp_read(hdsp, HDSP_midiStatusIn0) & 0xff);
1218 static int snd_hdsp_midi_output_possible (struct hdsp *hdsp, int id)
1220 int fifo_bytes_used;
1223 fifo_bytes_used = hdsp_read(hdsp, HDSP_midiStatusOut1) & 0xff;
1225 fifo_bytes_used = hdsp_read(hdsp, HDSP_midiStatusOut0) & 0xff;
1227 if (fifo_bytes_used < 128)
1228 return 128 - fifo_bytes_used;
1233 static void snd_hdsp_flush_midi_input (struct hdsp *hdsp, int id)
1235 while (snd_hdsp_midi_input_available (hdsp, id))
1236 snd_hdsp_midi_read_byte (hdsp, id);
1239 static int snd_hdsp_midi_output_write (struct hdsp_midi *hmidi)
1241 unsigned long flags;
1245 unsigned char buf[128];
1247 /* Output is not interrupt driven */
1249 spin_lock_irqsave (&hmidi->lock, flags);
1250 if (hmidi->output) {
1251 if (!snd_rawmidi_transmit_empty (hmidi->output)) {
1252 if ((n_pending = snd_hdsp_midi_output_possible (hmidi->hdsp, hmidi->id)) > 0) {
1253 if (n_pending > (int)sizeof (buf))
1254 n_pending = sizeof (buf);
1256 if ((to_write = snd_rawmidi_transmit (hmidi->output, buf, n_pending)) > 0) {
1257 for (i = 0; i < to_write; ++i)
1258 snd_hdsp_midi_write_byte (hmidi->hdsp, hmidi->id, buf[i]);
1263 spin_unlock_irqrestore (&hmidi->lock, flags);
1267 static int snd_hdsp_midi_input_read (struct hdsp_midi *hmidi)
1269 unsigned char buf[128]; /* this buffer is designed to match the MIDI input FIFO size */
1270 unsigned long flags;
1274 spin_lock_irqsave (&hmidi->lock, flags);
1275 if ((n_pending = snd_hdsp_midi_input_available (hmidi->hdsp, hmidi->id)) > 0) {
1277 if (n_pending > (int)sizeof (buf))
1278 n_pending = sizeof (buf);
1279 for (i = 0; i < n_pending; ++i)
1280 buf[i] = snd_hdsp_midi_read_byte (hmidi->hdsp, hmidi->id);
1282 snd_rawmidi_receive (hmidi->input, buf, n_pending);
1284 /* flush the MIDI input FIFO */
1286 snd_hdsp_midi_read_byte (hmidi->hdsp, hmidi->id);
1291 hmidi->hdsp->control_register |= HDSP_Midi1InterruptEnable;
1293 hmidi->hdsp->control_register |= HDSP_Midi0InterruptEnable;
1294 hdsp_write(hmidi->hdsp, HDSP_controlRegister, hmidi->hdsp->control_register);
1295 spin_unlock_irqrestore (&hmidi->lock, flags);
1296 return snd_hdsp_midi_output_write (hmidi);
1299 static void snd_hdsp_midi_input_trigger(struct snd_rawmidi_substream *substream, int up)
1302 struct hdsp_midi *hmidi;
1303 unsigned long flags;
1306 hmidi = (struct hdsp_midi *) substream->rmidi->private_data;
1308 ie = hmidi->id ? HDSP_Midi1InterruptEnable : HDSP_Midi0InterruptEnable;
1309 spin_lock_irqsave (&hdsp->lock, flags);
1311 if (!(hdsp->control_register & ie)) {
1312 snd_hdsp_flush_midi_input (hdsp, hmidi->id);
1313 hdsp->control_register |= ie;
1316 hdsp->control_register &= ~ie;
1317 tasklet_kill(&hdsp->midi_tasklet);
1320 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
1321 spin_unlock_irqrestore (&hdsp->lock, flags);
1324 static void snd_hdsp_midi_output_timer(unsigned long data)
1326 struct hdsp_midi *hmidi = (struct hdsp_midi *) data;
1327 unsigned long flags;
1329 snd_hdsp_midi_output_write(hmidi);
1330 spin_lock_irqsave (&hmidi->lock, flags);
1332 /* this does not bump hmidi->istimer, because the
1333 kernel automatically removed the timer when it
1334 expired, and we are now adding it back, thus
1335 leaving istimer wherever it was set before.
1338 if (hmidi->istimer) {
1339 hmidi->timer.expires = 1 + jiffies;
1340 add_timer(&hmidi->timer);
1343 spin_unlock_irqrestore (&hmidi->lock, flags);
1346 static void snd_hdsp_midi_output_trigger(struct snd_rawmidi_substream *substream, int up)
1348 struct hdsp_midi *hmidi;
1349 unsigned long flags;
1351 hmidi = (struct hdsp_midi *) substream->rmidi->private_data;
1352 spin_lock_irqsave (&hmidi->lock, flags);
1354 if (!hmidi->istimer) {
1355 init_timer(&hmidi->timer);
1356 hmidi->timer.function = snd_hdsp_midi_output_timer;
1357 hmidi->timer.data = (unsigned long) hmidi;
1358 hmidi->timer.expires = 1 + jiffies;
1359 add_timer(&hmidi->timer);
1363 if (hmidi->istimer && --hmidi->istimer <= 0)
1364 del_timer (&hmidi->timer);
1366 spin_unlock_irqrestore (&hmidi->lock, flags);
1368 snd_hdsp_midi_output_write(hmidi);
1371 static int snd_hdsp_midi_input_open(struct snd_rawmidi_substream *substream)
1373 struct hdsp_midi *hmidi;
1375 hmidi = (struct hdsp_midi *) substream->rmidi->private_data;
1376 spin_lock_irq (&hmidi->lock);
1377 snd_hdsp_flush_midi_input (hmidi->hdsp, hmidi->id);
1378 hmidi->input = substream;
1379 spin_unlock_irq (&hmidi->lock);
1384 static int snd_hdsp_midi_output_open(struct snd_rawmidi_substream *substream)
1386 struct hdsp_midi *hmidi;
1388 hmidi = (struct hdsp_midi *) substream->rmidi->private_data;
1389 spin_lock_irq (&hmidi->lock);
1390 hmidi->output = substream;
1391 spin_unlock_irq (&hmidi->lock);
1396 static int snd_hdsp_midi_input_close(struct snd_rawmidi_substream *substream)
1398 struct hdsp_midi *hmidi;
1400 snd_hdsp_midi_input_trigger (substream, 0);
1402 hmidi = (struct hdsp_midi *) substream->rmidi->private_data;
1403 spin_lock_irq (&hmidi->lock);
1404 hmidi->input = NULL;
1405 spin_unlock_irq (&hmidi->lock);
1410 static int snd_hdsp_midi_output_close(struct snd_rawmidi_substream *substream)
1412 struct hdsp_midi *hmidi;
1414 snd_hdsp_midi_output_trigger (substream, 0);
1416 hmidi = (struct hdsp_midi *) substream->rmidi->private_data;
1417 spin_lock_irq (&hmidi->lock);
1418 hmidi->output = NULL;
1419 spin_unlock_irq (&hmidi->lock);
1424 static struct snd_rawmidi_ops snd_hdsp_midi_output =
1426 .open = snd_hdsp_midi_output_open,
1427 .close = snd_hdsp_midi_output_close,
1428 .trigger = snd_hdsp_midi_output_trigger,
1431 static struct snd_rawmidi_ops snd_hdsp_midi_input =
1433 .open = snd_hdsp_midi_input_open,
1434 .close = snd_hdsp_midi_input_close,
1435 .trigger = snd_hdsp_midi_input_trigger,
1438 static int snd_hdsp_create_midi (struct snd_card *card, struct hdsp *hdsp, int id)
1442 hdsp->midi[id].id = id;
1443 hdsp->midi[id].rmidi = NULL;
1444 hdsp->midi[id].input = NULL;
1445 hdsp->midi[id].output = NULL;
1446 hdsp->midi[id].hdsp = hdsp;
1447 hdsp->midi[id].istimer = 0;
1448 hdsp->midi[id].pending = 0;
1449 spin_lock_init (&hdsp->midi[id].lock);
1451 sprintf (buf, "%s MIDI %d", card->shortname, id+1);
1452 if (snd_rawmidi_new (card, buf, id, 1, 1, &hdsp->midi[id].rmidi) < 0)
1455 sprintf (hdsp->midi[id].rmidi->name, "%s MIDI %d", card->id, id+1);
1456 hdsp->midi[id].rmidi->private_data = &hdsp->midi[id];
1458 snd_rawmidi_set_ops (hdsp->midi[id].rmidi, SNDRV_RAWMIDI_STREAM_OUTPUT, &snd_hdsp_midi_output);
1459 snd_rawmidi_set_ops (hdsp->midi[id].rmidi, SNDRV_RAWMIDI_STREAM_INPUT, &snd_hdsp_midi_input);
1461 hdsp->midi[id].rmidi->info_flags |= SNDRV_RAWMIDI_INFO_OUTPUT |
1462 SNDRV_RAWMIDI_INFO_INPUT |
1463 SNDRV_RAWMIDI_INFO_DUPLEX;
1468 /*-----------------------------------------------------------------------------
1470 ----------------------------------------------------------------------------*/
1472 static u32 snd_hdsp_convert_from_aes(struct snd_aes_iec958 *aes)
1475 val |= (aes->status[0] & IEC958_AES0_PROFESSIONAL) ? HDSP_SPDIFProfessional : 0;
1476 val |= (aes->status[0] & IEC958_AES0_NONAUDIO) ? HDSP_SPDIFNonAudio : 0;
1477 if (val & HDSP_SPDIFProfessional)
1478 val |= (aes->status[0] & IEC958_AES0_PRO_EMPHASIS_5015) ? HDSP_SPDIFEmphasis : 0;
1480 val |= (aes->status[0] & IEC958_AES0_CON_EMPHASIS_5015) ? HDSP_SPDIFEmphasis : 0;
1484 static void snd_hdsp_convert_to_aes(struct snd_aes_iec958 *aes, u32 val)
1486 aes->status[0] = ((val & HDSP_SPDIFProfessional) ? IEC958_AES0_PROFESSIONAL : 0) |
1487 ((val & HDSP_SPDIFNonAudio) ? IEC958_AES0_NONAUDIO : 0);
1488 if (val & HDSP_SPDIFProfessional)
1489 aes->status[0] |= (val & HDSP_SPDIFEmphasis) ? IEC958_AES0_PRO_EMPHASIS_5015 : 0;
1491 aes->status[0] |= (val & HDSP_SPDIFEmphasis) ? IEC958_AES0_CON_EMPHASIS_5015 : 0;
1494 static int snd_hdsp_control_spdif_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
1496 uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
1501 static int snd_hdsp_control_spdif_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1503 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1505 snd_hdsp_convert_to_aes(&ucontrol->value.iec958, hdsp->creg_spdif);
1509 static int snd_hdsp_control_spdif_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1511 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1515 val = snd_hdsp_convert_from_aes(&ucontrol->value.iec958);
1516 spin_lock_irq(&hdsp->lock);
1517 change = val != hdsp->creg_spdif;
1518 hdsp->creg_spdif = val;
1519 spin_unlock_irq(&hdsp->lock);
1523 static int snd_hdsp_control_spdif_stream_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
1525 uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
1530 static int snd_hdsp_control_spdif_stream_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1532 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1534 snd_hdsp_convert_to_aes(&ucontrol->value.iec958, hdsp->creg_spdif_stream);
1538 static int snd_hdsp_control_spdif_stream_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1540 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1544 val = snd_hdsp_convert_from_aes(&ucontrol->value.iec958);
1545 spin_lock_irq(&hdsp->lock);
1546 change = val != hdsp->creg_spdif_stream;
1547 hdsp->creg_spdif_stream = val;
1548 hdsp->control_register &= ~(HDSP_SPDIFProfessional | HDSP_SPDIFNonAudio | HDSP_SPDIFEmphasis);
1549 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register |= val);
1550 spin_unlock_irq(&hdsp->lock);
1554 static int snd_hdsp_control_spdif_mask_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
1556 uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
1561 static int snd_hdsp_control_spdif_mask_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1563 ucontrol->value.iec958.status[0] = kcontrol->private_value;
1567 #define HDSP_SPDIF_IN(xname, xindex) \
1568 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1571 .info = snd_hdsp_info_spdif_in, \
1572 .get = snd_hdsp_get_spdif_in, \
1573 .put = snd_hdsp_put_spdif_in }
1575 static unsigned int hdsp_spdif_in(struct hdsp *hdsp)
1577 return hdsp_decode_spdif_in(hdsp->control_register & HDSP_SPDIFInputMask);
1580 static int hdsp_set_spdif_input(struct hdsp *hdsp, int in)
1582 hdsp->control_register &= ~HDSP_SPDIFInputMask;
1583 hdsp->control_register |= hdsp_encode_spdif_in(in);
1584 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
1588 static int snd_hdsp_info_spdif_in(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
1590 static char *texts[4] = {"Optical", "Coaxial", "Internal", "AES"};
1591 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1593 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1595 uinfo->value.enumerated.items = ((hdsp->io_type == H9632) ? 4 : 3);
1596 if (uinfo->value.enumerated.item > ((hdsp->io_type == H9632) ? 3 : 2))
1597 uinfo->value.enumerated.item = ((hdsp->io_type == H9632) ? 3 : 2);
1598 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1602 static int snd_hdsp_get_spdif_in(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1604 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1606 ucontrol->value.enumerated.item[0] = hdsp_spdif_in(hdsp);
1610 static int snd_hdsp_put_spdif_in(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1612 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1616 if (!snd_hdsp_use_is_exclusive(hdsp))
1618 val = ucontrol->value.enumerated.item[0] % ((hdsp->io_type == H9632) ? 4 : 3);
1619 spin_lock_irq(&hdsp->lock);
1620 change = val != hdsp_spdif_in(hdsp);
1622 hdsp_set_spdif_input(hdsp, val);
1623 spin_unlock_irq(&hdsp->lock);
1627 #define HDSP_SPDIF_OUT(xname, xindex) \
1628 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \
1629 .info = snd_hdsp_info_spdif_bits, \
1630 .get = snd_hdsp_get_spdif_out, .put = snd_hdsp_put_spdif_out }
1632 static int hdsp_spdif_out(struct hdsp *hdsp)
1634 return (hdsp->control_register & HDSP_SPDIFOpticalOut) ? 1 : 0;
1637 static int hdsp_set_spdif_output(struct hdsp *hdsp, int out)
1640 hdsp->control_register |= HDSP_SPDIFOpticalOut;
1642 hdsp->control_register &= ~HDSP_SPDIFOpticalOut;
1643 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
1647 #define snd_hdsp_info_spdif_bits snd_ctl_boolean_mono_info
1649 static int snd_hdsp_get_spdif_out(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1651 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1653 ucontrol->value.integer.value[0] = hdsp_spdif_out(hdsp);
1657 static int snd_hdsp_put_spdif_out(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1659 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1663 if (!snd_hdsp_use_is_exclusive(hdsp))
1665 val = ucontrol->value.integer.value[0] & 1;
1666 spin_lock_irq(&hdsp->lock);
1667 change = (int)val != hdsp_spdif_out(hdsp);
1668 hdsp_set_spdif_output(hdsp, val);
1669 spin_unlock_irq(&hdsp->lock);
1673 #define HDSP_SPDIF_PROFESSIONAL(xname, xindex) \
1674 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \
1675 .info = snd_hdsp_info_spdif_bits, \
1676 .get = snd_hdsp_get_spdif_professional, .put = snd_hdsp_put_spdif_professional }
1678 static int hdsp_spdif_professional(struct hdsp *hdsp)
1680 return (hdsp->control_register & HDSP_SPDIFProfessional) ? 1 : 0;
1683 static int hdsp_set_spdif_professional(struct hdsp *hdsp, int val)
1686 hdsp->control_register |= HDSP_SPDIFProfessional;
1688 hdsp->control_register &= ~HDSP_SPDIFProfessional;
1689 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
1693 static int snd_hdsp_get_spdif_professional(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1695 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1697 ucontrol->value.integer.value[0] = hdsp_spdif_professional(hdsp);
1701 static int snd_hdsp_put_spdif_professional(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1703 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1707 if (!snd_hdsp_use_is_exclusive(hdsp))
1709 val = ucontrol->value.integer.value[0] & 1;
1710 spin_lock_irq(&hdsp->lock);
1711 change = (int)val != hdsp_spdif_professional(hdsp);
1712 hdsp_set_spdif_professional(hdsp, val);
1713 spin_unlock_irq(&hdsp->lock);
1717 #define HDSP_SPDIF_EMPHASIS(xname, xindex) \
1718 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \
1719 .info = snd_hdsp_info_spdif_bits, \
1720 .get = snd_hdsp_get_spdif_emphasis, .put = snd_hdsp_put_spdif_emphasis }
1722 static int hdsp_spdif_emphasis(struct hdsp *hdsp)
1724 return (hdsp->control_register & HDSP_SPDIFEmphasis) ? 1 : 0;
1727 static int hdsp_set_spdif_emphasis(struct hdsp *hdsp, int val)
1730 hdsp->control_register |= HDSP_SPDIFEmphasis;
1732 hdsp->control_register &= ~HDSP_SPDIFEmphasis;
1733 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
1737 static int snd_hdsp_get_spdif_emphasis(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1739 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1741 ucontrol->value.integer.value[0] = hdsp_spdif_emphasis(hdsp);
1745 static int snd_hdsp_put_spdif_emphasis(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1747 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1751 if (!snd_hdsp_use_is_exclusive(hdsp))
1753 val = ucontrol->value.integer.value[0] & 1;
1754 spin_lock_irq(&hdsp->lock);
1755 change = (int)val != hdsp_spdif_emphasis(hdsp);
1756 hdsp_set_spdif_emphasis(hdsp, val);
1757 spin_unlock_irq(&hdsp->lock);
1761 #define HDSP_SPDIF_NON_AUDIO(xname, xindex) \
1762 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \
1763 .info = snd_hdsp_info_spdif_bits, \
1764 .get = snd_hdsp_get_spdif_nonaudio, .put = snd_hdsp_put_spdif_nonaudio }
1766 static int hdsp_spdif_nonaudio(struct hdsp *hdsp)
1768 return (hdsp->control_register & HDSP_SPDIFNonAudio) ? 1 : 0;
1771 static int hdsp_set_spdif_nonaudio(struct hdsp *hdsp, int val)
1774 hdsp->control_register |= HDSP_SPDIFNonAudio;
1776 hdsp->control_register &= ~HDSP_SPDIFNonAudio;
1777 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
1781 static int snd_hdsp_get_spdif_nonaudio(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1783 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1785 ucontrol->value.integer.value[0] = hdsp_spdif_nonaudio(hdsp);
1789 static int snd_hdsp_put_spdif_nonaudio(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1791 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1795 if (!snd_hdsp_use_is_exclusive(hdsp))
1797 val = ucontrol->value.integer.value[0] & 1;
1798 spin_lock_irq(&hdsp->lock);
1799 change = (int)val != hdsp_spdif_nonaudio(hdsp);
1800 hdsp_set_spdif_nonaudio(hdsp, val);
1801 spin_unlock_irq(&hdsp->lock);
1805 #define HDSP_SPDIF_SAMPLE_RATE(xname, xindex) \
1806 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1809 .access = SNDRV_CTL_ELEM_ACCESS_READ, \
1810 .info = snd_hdsp_info_spdif_sample_rate, \
1811 .get = snd_hdsp_get_spdif_sample_rate \
1814 static int snd_hdsp_info_spdif_sample_rate(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
1816 static char *texts[] = {"32000", "44100", "48000", "64000", "88200", "96000", "None", "128000", "176400", "192000"};
1817 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1819 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1821 uinfo->value.enumerated.items = (hdsp->io_type == H9632) ? 10 : 7;
1822 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
1823 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
1824 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1828 static int snd_hdsp_get_spdif_sample_rate(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1830 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1832 switch (hdsp_spdif_sample_rate(hdsp)) {
1834 ucontrol->value.enumerated.item[0] = 0;
1837 ucontrol->value.enumerated.item[0] = 1;
1840 ucontrol->value.enumerated.item[0] = 2;
1843 ucontrol->value.enumerated.item[0] = 3;
1846 ucontrol->value.enumerated.item[0] = 4;
1849 ucontrol->value.enumerated.item[0] = 5;
1852 ucontrol->value.enumerated.item[0] = 7;
1855 ucontrol->value.enumerated.item[0] = 8;
1858 ucontrol->value.enumerated.item[0] = 9;
1861 ucontrol->value.enumerated.item[0] = 6;
1866 #define HDSP_SYSTEM_SAMPLE_RATE(xname, xindex) \
1867 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1870 .access = SNDRV_CTL_ELEM_ACCESS_READ, \
1871 .info = snd_hdsp_info_system_sample_rate, \
1872 .get = snd_hdsp_get_system_sample_rate \
1875 static int snd_hdsp_info_system_sample_rate(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
1877 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1882 static int snd_hdsp_get_system_sample_rate(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1884 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1886 ucontrol->value.enumerated.item[0] = hdsp->system_sample_rate;
1890 #define HDSP_AUTOSYNC_SAMPLE_RATE(xname, xindex) \
1891 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1894 .access = SNDRV_CTL_ELEM_ACCESS_READ, \
1895 .info = snd_hdsp_info_autosync_sample_rate, \
1896 .get = snd_hdsp_get_autosync_sample_rate \
1899 static int snd_hdsp_info_autosync_sample_rate(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
1901 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1902 static char *texts[] = {"32000", "44100", "48000", "64000", "88200", "96000", "None", "128000", "176400", "192000"};
1903 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1905 uinfo->value.enumerated.items = (hdsp->io_type == H9632) ? 10 : 7 ;
1906 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
1907 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
1908 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1912 static int snd_hdsp_get_autosync_sample_rate(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1914 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1916 switch (hdsp_external_sample_rate(hdsp)) {
1918 ucontrol->value.enumerated.item[0] = 0;
1921 ucontrol->value.enumerated.item[0] = 1;
1924 ucontrol->value.enumerated.item[0] = 2;
1927 ucontrol->value.enumerated.item[0] = 3;
1930 ucontrol->value.enumerated.item[0] = 4;
1933 ucontrol->value.enumerated.item[0] = 5;
1936 ucontrol->value.enumerated.item[0] = 7;
1939 ucontrol->value.enumerated.item[0] = 8;
1942 ucontrol->value.enumerated.item[0] = 9;
1945 ucontrol->value.enumerated.item[0] = 6;
1950 #define HDSP_SYSTEM_CLOCK_MODE(xname, xindex) \
1951 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1954 .access = SNDRV_CTL_ELEM_ACCESS_READ, \
1955 .info = snd_hdsp_info_system_clock_mode, \
1956 .get = snd_hdsp_get_system_clock_mode \
1959 static int hdsp_system_clock_mode(struct hdsp *hdsp)
1961 if (hdsp->control_register & HDSP_ClockModeMaster)
1963 else if (hdsp_external_sample_rate(hdsp) != hdsp->system_sample_rate)
1968 static int snd_hdsp_info_system_clock_mode(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
1970 static char *texts[] = {"Master", "Slave" };
1972 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1974 uinfo->value.enumerated.items = 2;
1975 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
1976 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
1977 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1981 static int snd_hdsp_get_system_clock_mode(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1983 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
1985 ucontrol->value.enumerated.item[0] = hdsp_system_clock_mode(hdsp);
1989 #define HDSP_CLOCK_SOURCE(xname, xindex) \
1990 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1993 .info = snd_hdsp_info_clock_source, \
1994 .get = snd_hdsp_get_clock_source, \
1995 .put = snd_hdsp_put_clock_source \
1998 static int hdsp_clock_source(struct hdsp *hdsp)
2000 if (hdsp->control_register & HDSP_ClockModeMaster) {
2001 switch (hdsp->system_sample_rate) {
2028 static int hdsp_set_clock_source(struct hdsp *hdsp, int mode)
2032 case HDSP_CLOCK_SOURCE_AUTOSYNC:
2033 if (hdsp_external_sample_rate(hdsp) != 0) {
2034 if (!hdsp_set_rate(hdsp, hdsp_external_sample_rate(hdsp), 1)) {
2035 hdsp->control_register &= ~HDSP_ClockModeMaster;
2036 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
2041 case HDSP_CLOCK_SOURCE_INTERNAL_32KHZ:
2044 case HDSP_CLOCK_SOURCE_INTERNAL_44_1KHZ:
2047 case HDSP_CLOCK_SOURCE_INTERNAL_48KHZ:
2050 case HDSP_CLOCK_SOURCE_INTERNAL_64KHZ:
2053 case HDSP_CLOCK_SOURCE_INTERNAL_88_2KHZ:
2056 case HDSP_CLOCK_SOURCE_INTERNAL_96KHZ:
2059 case HDSP_CLOCK_SOURCE_INTERNAL_128KHZ:
2062 case HDSP_CLOCK_SOURCE_INTERNAL_176_4KHZ:
2065 case HDSP_CLOCK_SOURCE_INTERNAL_192KHZ:
2071 hdsp->control_register |= HDSP_ClockModeMaster;
2072 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
2073 hdsp_set_rate(hdsp, rate, 1);
2077 static int snd_hdsp_info_clock_source(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
2079 static char *texts[] = {"AutoSync", "Internal 32.0 kHz", "Internal 44.1 kHz", "Internal 48.0 kHz", "Internal 64.0 kHz", "Internal 88.2 kHz", "Internal 96.0 kHz", "Internal 128 kHz", "Internal 176.4 kHz", "Internal 192.0 KHz" };
2080 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2082 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2084 if (hdsp->io_type == H9632)
2085 uinfo->value.enumerated.items = 10;
2087 uinfo->value.enumerated.items = 7;
2088 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
2089 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
2090 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
2094 static int snd_hdsp_get_clock_source(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2096 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2098 ucontrol->value.enumerated.item[0] = hdsp_clock_source(hdsp);
2102 static int snd_hdsp_put_clock_source(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2104 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2108 if (!snd_hdsp_use_is_exclusive(hdsp))
2110 val = ucontrol->value.enumerated.item[0];
2111 if (val < 0) val = 0;
2112 if (hdsp->io_type == H9632) {
2119 spin_lock_irq(&hdsp->lock);
2120 if (val != hdsp_clock_source(hdsp))
2121 change = (hdsp_set_clock_source(hdsp, val) == 0) ? 1 : 0;
2124 spin_unlock_irq(&hdsp->lock);
2128 #define snd_hdsp_info_clock_source_lock snd_ctl_boolean_mono_info
2130 static int snd_hdsp_get_clock_source_lock(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2132 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2134 ucontrol->value.integer.value[0] = hdsp->clock_source_locked;
2138 static int snd_hdsp_put_clock_source_lock(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2140 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2143 change = (int)ucontrol->value.integer.value[0] != hdsp->clock_source_locked;
2145 hdsp->clock_source_locked = !!ucontrol->value.integer.value[0];
2149 #define HDSP_DA_GAIN(xname, xindex) \
2150 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2153 .info = snd_hdsp_info_da_gain, \
2154 .get = snd_hdsp_get_da_gain, \
2155 .put = snd_hdsp_put_da_gain \
2158 static int hdsp_da_gain(struct hdsp *hdsp)
2160 switch (hdsp->control_register & HDSP_DAGainMask) {
2161 case HDSP_DAGainHighGain:
2163 case HDSP_DAGainPlus4dBu:
2165 case HDSP_DAGainMinus10dBV:
2172 static int hdsp_set_da_gain(struct hdsp *hdsp, int mode)
2174 hdsp->control_register &= ~HDSP_DAGainMask;
2177 hdsp->control_register |= HDSP_DAGainHighGain;
2180 hdsp->control_register |= HDSP_DAGainPlus4dBu;
2183 hdsp->control_register |= HDSP_DAGainMinus10dBV;
2189 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
2193 static int snd_hdsp_info_da_gain(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
2195 static char *texts[] = {"Hi Gain", "+4 dBu", "-10 dbV"};
2197 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2199 uinfo->value.enumerated.items = 3;
2200 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
2201 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
2202 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
2206 static int snd_hdsp_get_da_gain(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2208 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2210 ucontrol->value.enumerated.item[0] = hdsp_da_gain(hdsp);
2214 static int snd_hdsp_put_da_gain(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2216 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2220 if (!snd_hdsp_use_is_exclusive(hdsp))
2222 val = ucontrol->value.enumerated.item[0];
2223 if (val < 0) val = 0;
2224 if (val > 2) val = 2;
2225 spin_lock_irq(&hdsp->lock);
2226 if (val != hdsp_da_gain(hdsp))
2227 change = (hdsp_set_da_gain(hdsp, val) == 0) ? 1 : 0;
2230 spin_unlock_irq(&hdsp->lock);
2234 #define HDSP_AD_GAIN(xname, xindex) \
2235 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2238 .info = snd_hdsp_info_ad_gain, \
2239 .get = snd_hdsp_get_ad_gain, \
2240 .put = snd_hdsp_put_ad_gain \
2243 static int hdsp_ad_gain(struct hdsp *hdsp)
2245 switch (hdsp->control_register & HDSP_ADGainMask) {
2246 case HDSP_ADGainMinus10dBV:
2248 case HDSP_ADGainPlus4dBu:
2250 case HDSP_ADGainLowGain:
2257 static int hdsp_set_ad_gain(struct hdsp *hdsp, int mode)
2259 hdsp->control_register &= ~HDSP_ADGainMask;
2262 hdsp->control_register |= HDSP_ADGainMinus10dBV;
2265 hdsp->control_register |= HDSP_ADGainPlus4dBu;
2268 hdsp->control_register |= HDSP_ADGainLowGain;
2274 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
2278 static int snd_hdsp_info_ad_gain(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
2280 static char *texts[] = {"-10 dBV", "+4 dBu", "Lo Gain"};
2282 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2284 uinfo->value.enumerated.items = 3;
2285 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
2286 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
2287 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
2291 static int snd_hdsp_get_ad_gain(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2293 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2295 ucontrol->value.enumerated.item[0] = hdsp_ad_gain(hdsp);
2299 static int snd_hdsp_put_ad_gain(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2301 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2305 if (!snd_hdsp_use_is_exclusive(hdsp))
2307 val = ucontrol->value.enumerated.item[0];
2308 if (val < 0) val = 0;
2309 if (val > 2) val = 2;
2310 spin_lock_irq(&hdsp->lock);
2311 if (val != hdsp_ad_gain(hdsp))
2312 change = (hdsp_set_ad_gain(hdsp, val) == 0) ? 1 : 0;
2315 spin_unlock_irq(&hdsp->lock);
2319 #define HDSP_PHONE_GAIN(xname, xindex) \
2320 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2323 .info = snd_hdsp_info_phone_gain, \
2324 .get = snd_hdsp_get_phone_gain, \
2325 .put = snd_hdsp_put_phone_gain \
2328 static int hdsp_phone_gain(struct hdsp *hdsp)
2330 switch (hdsp->control_register & HDSP_PhoneGainMask) {
2331 case HDSP_PhoneGain0dB:
2333 case HDSP_PhoneGainMinus6dB:
2335 case HDSP_PhoneGainMinus12dB:
2342 static int hdsp_set_phone_gain(struct hdsp *hdsp, int mode)
2344 hdsp->control_register &= ~HDSP_PhoneGainMask;
2347 hdsp->control_register |= HDSP_PhoneGain0dB;
2350 hdsp->control_register |= HDSP_PhoneGainMinus6dB;
2353 hdsp->control_register |= HDSP_PhoneGainMinus12dB;
2359 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
2363 static int snd_hdsp_info_phone_gain(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
2365 static char *texts[] = {"0 dB", "-6 dB", "-12 dB"};
2367 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2369 uinfo->value.enumerated.items = 3;
2370 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
2371 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
2372 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
2376 static int snd_hdsp_get_phone_gain(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2378 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2380 ucontrol->value.enumerated.item[0] = hdsp_phone_gain(hdsp);
2384 static int snd_hdsp_put_phone_gain(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2386 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2390 if (!snd_hdsp_use_is_exclusive(hdsp))
2392 val = ucontrol->value.enumerated.item[0];
2393 if (val < 0) val = 0;
2394 if (val > 2) val = 2;
2395 spin_lock_irq(&hdsp->lock);
2396 if (val != hdsp_phone_gain(hdsp))
2397 change = (hdsp_set_phone_gain(hdsp, val) == 0) ? 1 : 0;
2400 spin_unlock_irq(&hdsp->lock);
2404 #define HDSP_XLR_BREAKOUT_CABLE(xname, xindex) \
2405 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2408 .info = snd_hdsp_info_xlr_breakout_cable, \
2409 .get = snd_hdsp_get_xlr_breakout_cable, \
2410 .put = snd_hdsp_put_xlr_breakout_cable \
2413 static int hdsp_xlr_breakout_cable(struct hdsp *hdsp)
2415 if (hdsp->control_register & HDSP_XLRBreakoutCable)
2420 static int hdsp_set_xlr_breakout_cable(struct hdsp *hdsp, int mode)
2423 hdsp->control_register |= HDSP_XLRBreakoutCable;
2425 hdsp->control_register &= ~HDSP_XLRBreakoutCable;
2426 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
2430 #define snd_hdsp_info_xlr_breakout_cable snd_ctl_boolean_mono_info
2432 static int snd_hdsp_get_xlr_breakout_cable(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2434 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2436 ucontrol->value.enumerated.item[0] = hdsp_xlr_breakout_cable(hdsp);
2440 static int snd_hdsp_put_xlr_breakout_cable(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2442 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2446 if (!snd_hdsp_use_is_exclusive(hdsp))
2448 val = ucontrol->value.integer.value[0] & 1;
2449 spin_lock_irq(&hdsp->lock);
2450 change = (int)val != hdsp_xlr_breakout_cable(hdsp);
2451 hdsp_set_xlr_breakout_cable(hdsp, val);
2452 spin_unlock_irq(&hdsp->lock);
2456 /* (De)activates old RME Analog Extension Board
2457 These are connected to the internal ADAT connector
2458 Switching this on desactivates external ADAT
2460 #define HDSP_AEB(xname, xindex) \
2461 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2464 .info = snd_hdsp_info_aeb, \
2465 .get = snd_hdsp_get_aeb, \
2466 .put = snd_hdsp_put_aeb \
2469 static int hdsp_aeb(struct hdsp *hdsp)
2471 if (hdsp->control_register & HDSP_AnalogExtensionBoard)
2476 static int hdsp_set_aeb(struct hdsp *hdsp, int mode)
2479 hdsp->control_register |= HDSP_AnalogExtensionBoard;
2481 hdsp->control_register &= ~HDSP_AnalogExtensionBoard;
2482 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
2486 #define snd_hdsp_info_aeb snd_ctl_boolean_mono_info
2488 static int snd_hdsp_get_aeb(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2490 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2492 ucontrol->value.enumerated.item[0] = hdsp_aeb(hdsp);
2496 static int snd_hdsp_put_aeb(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2498 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2502 if (!snd_hdsp_use_is_exclusive(hdsp))
2504 val = ucontrol->value.integer.value[0] & 1;
2505 spin_lock_irq(&hdsp->lock);
2506 change = (int)val != hdsp_aeb(hdsp);
2507 hdsp_set_aeb(hdsp, val);
2508 spin_unlock_irq(&hdsp->lock);
2512 #define HDSP_PREF_SYNC_REF(xname, xindex) \
2513 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2516 .info = snd_hdsp_info_pref_sync_ref, \
2517 .get = snd_hdsp_get_pref_sync_ref, \
2518 .put = snd_hdsp_put_pref_sync_ref \
2521 static int hdsp_pref_sync_ref(struct hdsp *hdsp)
2523 /* Notice that this looks at the requested sync source,
2524 not the one actually in use.
2527 switch (hdsp->control_register & HDSP_SyncRefMask) {
2528 case HDSP_SyncRef_ADAT1:
2529 return HDSP_SYNC_FROM_ADAT1;
2530 case HDSP_SyncRef_ADAT2:
2531 return HDSP_SYNC_FROM_ADAT2;
2532 case HDSP_SyncRef_ADAT3:
2533 return HDSP_SYNC_FROM_ADAT3;
2534 case HDSP_SyncRef_SPDIF:
2535 return HDSP_SYNC_FROM_SPDIF;
2536 case HDSP_SyncRef_WORD:
2537 return HDSP_SYNC_FROM_WORD;
2538 case HDSP_SyncRef_ADAT_SYNC:
2539 return HDSP_SYNC_FROM_ADAT_SYNC;
2541 return HDSP_SYNC_FROM_WORD;
2546 static int hdsp_set_pref_sync_ref(struct hdsp *hdsp, int pref)
2548 hdsp->control_register &= ~HDSP_SyncRefMask;
2550 case HDSP_SYNC_FROM_ADAT1:
2551 hdsp->control_register &= ~HDSP_SyncRefMask; /* clear SyncRef bits */
2553 case HDSP_SYNC_FROM_ADAT2:
2554 hdsp->control_register |= HDSP_SyncRef_ADAT2;
2556 case HDSP_SYNC_FROM_ADAT3:
2557 hdsp->control_register |= HDSP_SyncRef_ADAT3;
2559 case HDSP_SYNC_FROM_SPDIF:
2560 hdsp->control_register |= HDSP_SyncRef_SPDIF;
2562 case HDSP_SYNC_FROM_WORD:
2563 hdsp->control_register |= HDSP_SyncRef_WORD;
2565 case HDSP_SYNC_FROM_ADAT_SYNC:
2566 hdsp->control_register |= HDSP_SyncRef_ADAT_SYNC;
2571 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
2575 static int snd_hdsp_info_pref_sync_ref(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
2577 static char *texts[] = {"Word", "IEC958", "ADAT1", "ADAT Sync", "ADAT2", "ADAT3" };
2578 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2580 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2583 switch (hdsp->io_type) {
2586 uinfo->value.enumerated.items = 6;
2589 uinfo->value.enumerated.items = 4;
2592 uinfo->value.enumerated.items = 3;
2595 uinfo->value.enumerated.items = 0;
2599 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
2600 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
2601 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
2605 static int snd_hdsp_get_pref_sync_ref(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2607 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2609 ucontrol->value.enumerated.item[0] = hdsp_pref_sync_ref(hdsp);
2613 static int snd_hdsp_put_pref_sync_ref(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2615 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2619 if (!snd_hdsp_use_is_exclusive(hdsp))
2622 switch (hdsp->io_type) {
2637 val = ucontrol->value.enumerated.item[0] % max;
2638 spin_lock_irq(&hdsp->lock);
2639 change = (int)val != hdsp_pref_sync_ref(hdsp);
2640 hdsp_set_pref_sync_ref(hdsp, val);
2641 spin_unlock_irq(&hdsp->lock);
2645 #define HDSP_AUTOSYNC_REF(xname, xindex) \
2646 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2649 .access = SNDRV_CTL_ELEM_ACCESS_READ, \
2650 .info = snd_hdsp_info_autosync_ref, \
2651 .get = snd_hdsp_get_autosync_ref, \
2654 static int hdsp_autosync_ref(struct hdsp *hdsp)
2656 /* This looks at the autosync selected sync reference */
2657 unsigned int status2 = hdsp_read(hdsp, HDSP_status2Register);
2659 switch (status2 & HDSP_SelSyncRefMask) {
2660 case HDSP_SelSyncRef_WORD:
2661 return HDSP_AUTOSYNC_FROM_WORD;
2662 case HDSP_SelSyncRef_ADAT_SYNC:
2663 return HDSP_AUTOSYNC_FROM_ADAT_SYNC;
2664 case HDSP_SelSyncRef_SPDIF:
2665 return HDSP_AUTOSYNC_FROM_SPDIF;
2666 case HDSP_SelSyncRefMask:
2667 return HDSP_AUTOSYNC_FROM_NONE;
2668 case HDSP_SelSyncRef_ADAT1:
2669 return HDSP_AUTOSYNC_FROM_ADAT1;
2670 case HDSP_SelSyncRef_ADAT2:
2671 return HDSP_AUTOSYNC_FROM_ADAT2;
2672 case HDSP_SelSyncRef_ADAT3:
2673 return HDSP_AUTOSYNC_FROM_ADAT3;
2675 return HDSP_AUTOSYNC_FROM_WORD;
2680 static int snd_hdsp_info_autosync_ref(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
2682 static char *texts[] = {"Word", "ADAT Sync", "IEC958", "None", "ADAT1", "ADAT2", "ADAT3" };
2684 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2686 uinfo->value.enumerated.items = 7;
2687 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
2688 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
2689 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
2693 static int snd_hdsp_get_autosync_ref(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2695 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2697 ucontrol->value.enumerated.item[0] = hdsp_autosync_ref(hdsp);
2701 #define HDSP_LINE_OUT(xname, xindex) \
2702 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2705 .info = snd_hdsp_info_line_out, \
2706 .get = snd_hdsp_get_line_out, \
2707 .put = snd_hdsp_put_line_out \
2710 static int hdsp_line_out(struct hdsp *hdsp)
2712 return (hdsp->control_register & HDSP_LineOut) ? 1 : 0;
2715 static int hdsp_set_line_output(struct hdsp *hdsp, int out)
2718 hdsp->control_register |= HDSP_LineOut;
2720 hdsp->control_register &= ~HDSP_LineOut;
2721 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
2725 #define snd_hdsp_info_line_out snd_ctl_boolean_mono_info
2727 static int snd_hdsp_get_line_out(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2729 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2731 spin_lock_irq(&hdsp->lock);
2732 ucontrol->value.integer.value[0] = hdsp_line_out(hdsp);
2733 spin_unlock_irq(&hdsp->lock);
2737 static int snd_hdsp_put_line_out(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2739 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2743 if (!snd_hdsp_use_is_exclusive(hdsp))
2745 val = ucontrol->value.integer.value[0] & 1;
2746 spin_lock_irq(&hdsp->lock);
2747 change = (int)val != hdsp_line_out(hdsp);
2748 hdsp_set_line_output(hdsp, val);
2749 spin_unlock_irq(&hdsp->lock);
2753 #define HDSP_PRECISE_POINTER(xname, xindex) \
2754 { .iface = SNDRV_CTL_ELEM_IFACE_CARD, \
2757 .info = snd_hdsp_info_precise_pointer, \
2758 .get = snd_hdsp_get_precise_pointer, \
2759 .put = snd_hdsp_put_precise_pointer \
2762 static int hdsp_set_precise_pointer(struct hdsp *hdsp, int precise)
2765 hdsp->precise_ptr = 1;
2767 hdsp->precise_ptr = 0;
2771 #define snd_hdsp_info_precise_pointer snd_ctl_boolean_mono_info
2773 static int snd_hdsp_get_precise_pointer(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2775 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2777 spin_lock_irq(&hdsp->lock);
2778 ucontrol->value.integer.value[0] = hdsp->precise_ptr;
2779 spin_unlock_irq(&hdsp->lock);
2783 static int snd_hdsp_put_precise_pointer(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2785 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2789 if (!snd_hdsp_use_is_exclusive(hdsp))
2791 val = ucontrol->value.integer.value[0] & 1;
2792 spin_lock_irq(&hdsp->lock);
2793 change = (int)val != hdsp->precise_ptr;
2794 hdsp_set_precise_pointer(hdsp, val);
2795 spin_unlock_irq(&hdsp->lock);
2799 #define HDSP_USE_MIDI_TASKLET(xname, xindex) \
2800 { .iface = SNDRV_CTL_ELEM_IFACE_CARD, \
2803 .info = snd_hdsp_info_use_midi_tasklet, \
2804 .get = snd_hdsp_get_use_midi_tasklet, \
2805 .put = snd_hdsp_put_use_midi_tasklet \
2808 static int hdsp_set_use_midi_tasklet(struct hdsp *hdsp, int use_tasklet)
2811 hdsp->use_midi_tasklet = 1;
2813 hdsp->use_midi_tasklet = 0;
2817 #define snd_hdsp_info_use_midi_tasklet snd_ctl_boolean_mono_info
2819 static int snd_hdsp_get_use_midi_tasklet(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2821 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2823 spin_lock_irq(&hdsp->lock);
2824 ucontrol->value.integer.value[0] = hdsp->use_midi_tasklet;
2825 spin_unlock_irq(&hdsp->lock);
2829 static int snd_hdsp_put_use_midi_tasklet(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2831 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2835 if (!snd_hdsp_use_is_exclusive(hdsp))
2837 val = ucontrol->value.integer.value[0] & 1;
2838 spin_lock_irq(&hdsp->lock);
2839 change = (int)val != hdsp->use_midi_tasklet;
2840 hdsp_set_use_midi_tasklet(hdsp, val);
2841 spin_unlock_irq(&hdsp->lock);
2845 #define HDSP_MIXER(xname, xindex) \
2846 { .iface = SNDRV_CTL_ELEM_IFACE_HWDEP, \
2850 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | \
2851 SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
2852 .info = snd_hdsp_info_mixer, \
2853 .get = snd_hdsp_get_mixer, \
2854 .put = snd_hdsp_put_mixer \
2857 static int snd_hdsp_info_mixer(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
2859 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
2861 uinfo->value.integer.min = 0;
2862 uinfo->value.integer.max = 65536;
2863 uinfo->value.integer.step = 1;
2867 static int snd_hdsp_get_mixer(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2869 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2874 source = ucontrol->value.integer.value[0];
2875 destination = ucontrol->value.integer.value[1];
2877 if (source >= hdsp->max_channels)
2878 addr = hdsp_playback_to_output_key(hdsp,source-hdsp->max_channels,destination);
2880 addr = hdsp_input_to_output_key(hdsp,source, destination);
2882 spin_lock_irq(&hdsp->lock);
2883 ucontrol->value.integer.value[2] = hdsp_read_gain (hdsp, addr);
2884 spin_unlock_irq(&hdsp->lock);
2888 static int snd_hdsp_put_mixer(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2890 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2897 if (!snd_hdsp_use_is_exclusive(hdsp))
2900 source = ucontrol->value.integer.value[0];
2901 destination = ucontrol->value.integer.value[1];
2903 if (source >= hdsp->max_channels)
2904 addr = hdsp_playback_to_output_key(hdsp,source-hdsp->max_channels, destination);
2906 addr = hdsp_input_to_output_key(hdsp,source, destination);
2908 gain = ucontrol->value.integer.value[2];
2910 spin_lock_irq(&hdsp->lock);
2911 change = gain != hdsp_read_gain(hdsp, addr);
2913 hdsp_write_gain(hdsp, addr, gain);
2914 spin_unlock_irq(&hdsp->lock);
2918 #define HDSP_WC_SYNC_CHECK(xname, xindex) \
2919 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2922 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
2923 .info = snd_hdsp_info_sync_check, \
2924 .get = snd_hdsp_get_wc_sync_check \
2927 static int snd_hdsp_info_sync_check(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
2929 static char *texts[] = {"No Lock", "Lock", "Sync" };
2930 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2932 uinfo->value.enumerated.items = 3;
2933 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
2934 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
2935 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
2939 static int hdsp_wc_sync_check(struct hdsp *hdsp)
2941 int status2 = hdsp_read(hdsp, HDSP_status2Register);
2942 if (status2 & HDSP_wc_lock) {
2943 if (status2 & HDSP_wc_sync)
2952 static int snd_hdsp_get_wc_sync_check(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2954 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2956 ucontrol->value.enumerated.item[0] = hdsp_wc_sync_check(hdsp);
2960 #define HDSP_SPDIF_SYNC_CHECK(xname, xindex) \
2961 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2964 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
2965 .info = snd_hdsp_info_sync_check, \
2966 .get = snd_hdsp_get_spdif_sync_check \
2969 static int hdsp_spdif_sync_check(struct hdsp *hdsp)
2971 int status = hdsp_read(hdsp, HDSP_statusRegister);
2972 if (status & HDSP_SPDIFErrorFlag)
2975 if (status & HDSP_SPDIFSync)
2983 static int snd_hdsp_get_spdif_sync_check(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
2985 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
2987 ucontrol->value.enumerated.item[0] = hdsp_spdif_sync_check(hdsp);
2991 #define HDSP_ADATSYNC_SYNC_CHECK(xname, xindex) \
2992 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2995 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
2996 .info = snd_hdsp_info_sync_check, \
2997 .get = snd_hdsp_get_adatsync_sync_check \
3000 static int hdsp_adatsync_sync_check(struct hdsp *hdsp)
3002 int status = hdsp_read(hdsp, HDSP_statusRegister);
3003 if (status & HDSP_TimecodeLock) {
3004 if (status & HDSP_TimecodeSync)
3012 static int snd_hdsp_get_adatsync_sync_check(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
3014 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
3016 ucontrol->value.enumerated.item[0] = hdsp_adatsync_sync_check(hdsp);
3020 #define HDSP_ADAT_SYNC_CHECK \
3021 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
3022 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
3023 .info = snd_hdsp_info_sync_check, \
3024 .get = snd_hdsp_get_adat_sync_check \
3027 static int hdsp_adat_sync_check(struct hdsp *hdsp, int idx)
3029 int status = hdsp_read(hdsp, HDSP_statusRegister);
3031 if (status & (HDSP_Lock0>>idx)) {
3032 if (status & (HDSP_Sync0>>idx))
3040 static int snd_hdsp_get_adat_sync_check(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
3043 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
3045 offset = ucontrol->id.index - 1;
3046 snd_BUG_ON(offset < 0);
3048 switch (hdsp->io_type) {
3063 ucontrol->value.enumerated.item[0] = hdsp_adat_sync_check(hdsp, offset);
3067 #define HDSP_DDS_OFFSET(xname, xindex) \
3068 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
3071 .info = snd_hdsp_info_dds_offset, \
3072 .get = snd_hdsp_get_dds_offset, \
3073 .put = snd_hdsp_put_dds_offset \
3076 static int hdsp_dds_offset(struct hdsp *hdsp)
3080 unsigned int dds_value = hdsp->dds_value;
3081 int system_sample_rate = hdsp->system_sample_rate;
3088 * dds_value = n / rate
3089 * rate = n / dds_value
3091 div64_32(&n, dds_value, &r);
3092 if (system_sample_rate >= 112000)
3094 else if (system_sample_rate >= 56000)
3096 return ((int)n) - system_sample_rate;
3099 static int hdsp_set_dds_offset(struct hdsp *hdsp, int offset_hz)
3101 int rate = hdsp->system_sample_rate + offset_hz;
3102 hdsp_set_dds_value(hdsp, rate);
3106 static int snd_hdsp_info_dds_offset(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
3108 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
3110 uinfo->value.integer.min = -5000;
3111 uinfo->value.integer.max = 5000;
3115 static int snd_hdsp_get_dds_offset(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
3117 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
3119 ucontrol->value.enumerated.item[0] = hdsp_dds_offset(hdsp);
3123 static int snd_hdsp_put_dds_offset(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
3125 struct hdsp *hdsp = snd_kcontrol_chip(kcontrol);
3129 if (!snd_hdsp_use_is_exclusive(hdsp))
3131 val = ucontrol->value.enumerated.item[0];
3132 spin_lock_irq(&hdsp->lock);
3133 if (val != hdsp_dds_offset(hdsp))
3134 change = (hdsp_set_dds_offset(hdsp, val) == 0) ? 1 : 0;
3137 spin_unlock_irq(&hdsp->lock);
3141 static struct snd_kcontrol_new snd_hdsp_9632_controls[] = {
3142 HDSP_DA_GAIN("DA Gain", 0),
3143 HDSP_AD_GAIN("AD Gain", 0),
3144 HDSP_PHONE_GAIN("Phones Gain", 0),
3145 HDSP_XLR_BREAKOUT_CABLE("XLR Breakout Cable", 0),
3146 HDSP_DDS_OFFSET("DDS Sample Rate Offset", 0)
3149 static struct snd_kcontrol_new snd_hdsp_controls[] = {
3151 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
3152 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,DEFAULT),
3153 .info = snd_hdsp_control_spdif_info,
3154 .get = snd_hdsp_control_spdif_get,
3155 .put = snd_hdsp_control_spdif_put,
3158 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_INACTIVE,
3159 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
3160 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,PCM_STREAM),
3161 .info = snd_hdsp_control_spdif_stream_info,
3162 .get = snd_hdsp_control_spdif_stream_get,
3163 .put = snd_hdsp_control_spdif_stream_put,
3166 .access = SNDRV_CTL_ELEM_ACCESS_READ,
3167 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
3168 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,CON_MASK),
3169 .info = snd_hdsp_control_spdif_mask_info,
3170 .get = snd_hdsp_control_spdif_mask_get,
3171 .private_value = IEC958_AES0_NONAUDIO |
3172 IEC958_AES0_PROFESSIONAL |
3173 IEC958_AES0_CON_EMPHASIS,
3176 .access = SNDRV_CTL_ELEM_ACCESS_READ,
3177 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
3178 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,PRO_MASK),
3179 .info = snd_hdsp_control_spdif_mask_info,
3180 .get = snd_hdsp_control_spdif_mask_get,
3181 .private_value = IEC958_AES0_NONAUDIO |
3182 IEC958_AES0_PROFESSIONAL |
3183 IEC958_AES0_PRO_EMPHASIS,
3185 HDSP_MIXER("Mixer", 0),
3186 HDSP_SPDIF_IN("IEC958 Input Connector", 0),
3187 HDSP_SPDIF_OUT("IEC958 Output also on ADAT1", 0),
3188 HDSP_SPDIF_PROFESSIONAL("IEC958 Professional Bit", 0),
3189 HDSP_SPDIF_EMPHASIS("IEC958 Emphasis Bit", 0),
3190 HDSP_SPDIF_NON_AUDIO("IEC958 Non-audio Bit", 0),
3191 /* 'Sample Clock Source' complies with the alsa control naming scheme */
3192 HDSP_CLOCK_SOURCE("Sample Clock Source", 0),
3194 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3195 .name = "Sample Clock Source Locking",
3196 .info = snd_hdsp_info_clock_source_lock,
3197 .get = snd_hdsp_get_clock_source_lock,
3198 .put = snd_hdsp_put_clock_source_lock,
3200 HDSP_SYSTEM_CLOCK_MODE("System Clock Mode", 0),
3201 HDSP_PREF_SYNC_REF("Preferred Sync Reference", 0),
3202 HDSP_AUTOSYNC_REF("AutoSync Reference", 0),
3203 HDSP_SPDIF_SAMPLE_RATE("SPDIF Sample Rate", 0),
3204 HDSP_SYSTEM_SAMPLE_RATE("System Sample Rate", 0),
3205 /* 'External Rate' complies with the alsa control naming scheme */
3206 HDSP_AUTOSYNC_SAMPLE_RATE("External Rate", 0),
3207 HDSP_WC_SYNC_CHECK("Word Clock Lock Status", 0),
3208 HDSP_SPDIF_SYNC_CHECK("SPDIF Lock Status", 0),
3209 HDSP_ADATSYNC_SYNC_CHECK("ADAT Sync Lock Status", 0),
3210 HDSP_LINE_OUT("Line Out", 0),
3211 HDSP_PRECISE_POINTER("Precise Pointer", 0),
3212 HDSP_USE_MIDI_TASKLET("Use Midi Tasklet", 0),
3215 static struct snd_kcontrol_new snd_hdsp_96xx_aeb = HDSP_AEB("Analog Extension Board", 0);
3216 static struct snd_kcontrol_new snd_hdsp_adat_sync_check = HDSP_ADAT_SYNC_CHECK;
3218 static int snd_hdsp_create_controls(struct snd_card *card, struct hdsp *hdsp)
3222 struct snd_kcontrol *kctl;
3224 for (idx = 0; idx < ARRAY_SIZE(snd_hdsp_controls); idx++) {
3225 if ((err = snd_ctl_add(card, kctl = snd_ctl_new1(&snd_hdsp_controls[idx], hdsp))) < 0)
3227 if (idx == 1) /* IEC958 (S/PDIF) Stream */
3228 hdsp->spdif_ctl = kctl;
3231 /* ADAT SyncCheck status */
3232 snd_hdsp_adat_sync_check.name = "ADAT Lock Status";
3233 snd_hdsp_adat_sync_check.index = 1;
3234 if ((err = snd_ctl_add (card, kctl = snd_ctl_new1(&snd_hdsp_adat_sync_check, hdsp))))
3236 if (hdsp->io_type == Digiface || hdsp->io_type == H9652) {
3237 for (idx = 1; idx < 3; ++idx) {
3238 snd_hdsp_adat_sync_check.index = idx+1;
3239 if ((err = snd_ctl_add (card, kctl = snd_ctl_new1(&snd_hdsp_adat_sync_check, hdsp))))
3244 /* DA, AD and Phone gain and XLR breakout cable controls for H9632 cards */
3245 if (hdsp->io_type == H9632) {
3246 for (idx = 0; idx < ARRAY_SIZE(snd_hdsp_9632_controls); idx++) {
3247 if ((err = snd_ctl_add(card, kctl = snd_ctl_new1(&snd_hdsp_9632_controls[idx], hdsp))) < 0)
3252 /* AEB control for H96xx card */
3253 if (hdsp->io_type == H9632 || hdsp->io_type == H9652) {
3254 if ((err = snd_ctl_add(card, kctl = snd_ctl_new1(&snd_hdsp_96xx_aeb, hdsp))) < 0)
3261 /*------------------------------------------------------------
3263 ------------------------------------------------------------*/
3266 snd_hdsp_proc_read(struct snd_info_entry *entry, struct snd_info_buffer *buffer)
3268 struct hdsp *hdsp = (struct hdsp *) entry->private_data;
3269 unsigned int status;
3270 unsigned int status2;
3271 char *pref_sync_ref;
3273 char *system_clock_mode;
3277 if (hdsp_check_for_iobox (hdsp)) {
3278 snd_iprintf(buffer, "No I/O box connected.\nPlease connect one and upload firmware.\n");
3282 if (hdsp_check_for_firmware(hdsp, 0)) {
3283 if (hdsp->state & HDSP_FirmwareCached) {
3284 if (snd_hdsp_load_firmware_from_cache(hdsp) != 0) {
3285 snd_iprintf(buffer, "Firmware loading from cache failed, please upload manually.\n");
3290 #ifdef HDSP_FW_LOADER
3291 err = hdsp_request_fw_loader(hdsp);
3295 "No firmware loaded nor cached, "
3296 "please upload firmware.\n");
3302 status = hdsp_read(hdsp, HDSP_statusRegister);
3303 status2 = hdsp_read(hdsp, HDSP_status2Register);
3305 snd_iprintf(buffer, "%s (Card #%d)\n", hdsp->card_name, hdsp->card->number + 1);
3306 snd_iprintf(buffer, "Buffers: capture %p playback %p\n",
3307 hdsp->capture_buffer, hdsp->playback_buffer);
3308 snd_iprintf(buffer, "IRQ: %d Registers bus: 0x%lx VM: 0x%lx\n",
3309 hdsp->irq, hdsp->port, (unsigned long)hdsp->iobase);
3310 snd_iprintf(buffer, "Control register: 0x%x\n", hdsp->control_register);
3311 snd_iprintf(buffer, "Control2 register: 0x%x\n", hdsp->control2_register);
3312 snd_iprintf(buffer, "Status register: 0x%x\n", status);
3313 snd_iprintf(buffer, "Status2 register: 0x%x\n", status2);
3314 snd_iprintf(buffer, "FIFO status: %d\n", hdsp_read(hdsp, HDSP_fifoStatus) & 0xff);
3315 snd_iprintf(buffer, "MIDI1 Output status: 0x%x\n", hdsp_read(hdsp, HDSP_midiStatusOut0));
3316 snd_iprintf(buffer, "MIDI1 Input status: 0x%x\n", hdsp_read(hdsp, HDSP_midiStatusIn0));
3317 snd_iprintf(buffer, "MIDI2 Output status: 0x%x\n", hdsp_read(hdsp, HDSP_midiStatusOut1));
3318 snd_iprintf(buffer, "MIDI2 Input status: 0x%x\n", hdsp_read(hdsp, HDSP_midiStatusIn1));
3319 snd_iprintf(buffer, "Use Midi Tasklet: %s\n", hdsp->use_midi_tasklet ? "on" : "off");
3321 snd_iprintf(buffer, "\n");
3323 x = 1 << (6 + hdsp_decode_latency(hdsp->control_register & HDSP_LatencyMask));
3325 snd_iprintf(buffer, "Buffer Size (Latency): %d samples (2 periods of %lu bytes)\n", x, (unsigned long) hdsp->period_bytes);
3326 snd_iprintf(buffer, "Hardware pointer (frames): %ld\n", hdsp_hw_pointer(hdsp));
3327 snd_iprintf(buffer, "Precise pointer: %s\n", hdsp->precise_ptr ? "on" : "off");
3328 snd_iprintf(buffer, "Line out: %s\n", (hdsp->control_register & HDSP_LineOut) ? "on" : "off");
3330 snd_iprintf(buffer, "Firmware version: %d\n", (status2&HDSP_version0)|(status2&HDSP_version1)<<1|(status2&HDSP_version2)<<2);
3332 snd_iprintf(buffer, "\n");
3335 switch (hdsp_clock_source(hdsp)) {
3336 case HDSP_CLOCK_SOURCE_AUTOSYNC:
3337 clock_source = "AutoSync";
3339 case HDSP_CLOCK_SOURCE_INTERNAL_32KHZ:
3340 clock_source = "Internal 32 kHz";
3342 case HDSP_CLOCK_SOURCE_INTERNAL_44_1KHZ:
3343 clock_source = "Internal 44.1 kHz";
3345 case HDSP_CLOCK_SOURCE_INTERNAL_48KHZ:
3346 clock_source = "Internal 48 kHz";
3348 case HDSP_CLOCK_SOURCE_INTERNAL_64KHZ:
3349 clock_source = "Internal 64 kHz";
3351 case HDSP_CLOCK_SOURCE_INTERNAL_88_2KHZ:
3352 clock_source = "Internal 88.2 kHz";
3354 case HDSP_CLOCK_SOURCE_INTERNAL_96KHZ:
3355 clock_source = "Internal 96 kHz";
3357 case HDSP_CLOCK_SOURCE_INTERNAL_128KHZ:
3358 clock_source = "Internal 128 kHz";
3360 case HDSP_CLOCK_SOURCE_INTERNAL_176_4KHZ:
3361 clock_source = "Internal 176.4 kHz";
3363 case HDSP_CLOCK_SOURCE_INTERNAL_192KHZ:
3364 clock_source = "Internal 192 kHz";
3367 clock_source = "Error";
3369 snd_iprintf (buffer, "Sample Clock Source: %s\n", clock_source);
3371 if (hdsp_system_clock_mode(hdsp))
3372 system_clock_mode = "Slave";
3374 system_clock_mode = "Master";
3376 switch (hdsp_pref_sync_ref (hdsp)) {
3377 case HDSP_SYNC_FROM_WORD:
3378 pref_sync_ref = "Word Clock";
3380 case HDSP_SYNC_FROM_ADAT_SYNC:
3381 pref_sync_ref = "ADAT Sync";
3383 case HDSP_SYNC_FROM_SPDIF:
3384 pref_sync_ref = "SPDIF";
3386 case HDSP_SYNC_FROM_ADAT1:
3387 pref_sync_ref = "ADAT1";
3389 case HDSP_SYNC_FROM_ADAT2:
3390 pref_sync_ref = "ADAT2";
3392 case HDSP_SYNC_FROM_ADAT3:
3393 pref_sync_ref = "ADAT3";
3396 pref_sync_ref = "Word Clock";
3399 snd_iprintf (buffer, "Preferred Sync Reference: %s\n", pref_sync_ref);
3401 switch (hdsp_autosync_ref (hdsp)) {
3402 case HDSP_AUTOSYNC_FROM_WORD:
3403 autosync_ref = "Word Clock";
3405 case HDSP_AUTOSYNC_FROM_ADAT_SYNC:
3406 autosync_ref = "ADAT Sync";
3408 case HDSP_AUTOSYNC_FROM_SPDIF:
3409 autosync_ref = "SPDIF";
3411 case HDSP_AUTOSYNC_FROM_NONE:
3412 autosync_ref = "None";
3414 case HDSP_AUTOSYNC_FROM_ADAT1:
3415 autosync_ref = "ADAT1";
3417 case HDSP_AUTOSYNC_FROM_ADAT2:
3418 autosync_ref = "ADAT2";
3420 case HDSP_AUTOSYNC_FROM_ADAT3:
3421 autosync_ref = "ADAT3";
3424 autosync_ref = "---";
3427 snd_iprintf (buffer, "AutoSync Reference: %s\n", autosync_ref);
3429 snd_iprintf (buffer, "AutoSync Frequency: %d\n", hdsp_external_sample_rate(hdsp));
3431 snd_iprintf (buffer, "System Clock Mode: %s\n", system_clock_mode);
3433 snd_iprintf (buffer, "System Clock Frequency: %d\n", hdsp->system_sample_rate);
3434 snd_iprintf (buffer, "System Clock Locked: %s\n", hdsp->clock_source_locked ? "Yes" : "No");
3436 snd_iprintf(buffer, "\n");
3438 switch (hdsp_spdif_in(hdsp)) {
3439 case HDSP_SPDIFIN_OPTICAL:
3440 snd_iprintf(buffer, "IEC958 input: Optical\n");
3442 case HDSP_SPDIFIN_COAXIAL:
3443 snd_iprintf(buffer, "IEC958 input: Coaxial\n");
3445 case HDSP_SPDIFIN_INTERNAL:
3446 snd_iprintf(buffer, "IEC958 input: Internal\n");
3448 case HDSP_SPDIFIN_AES:
3449 snd_iprintf(buffer, "IEC958 input: AES\n");
3452 snd_iprintf(buffer, "IEC958 input: ???\n");
3456 if (hdsp->control_register & HDSP_SPDIFOpticalOut)
3457 snd_iprintf(buffer, "IEC958 output: Coaxial & ADAT1\n");
3459 snd_iprintf(buffer, "IEC958 output: Coaxial only\n");
3461 if (hdsp->control_register & HDSP_SPDIFProfessional)
3462 snd_iprintf(buffer, "IEC958 quality: Professional\n");
3464 snd_iprintf(buffer, "IEC958 quality: Consumer\n");
3466 if (hdsp->control_register & HDSP_SPDIFEmphasis)
3467 snd_iprintf(buffer, "IEC958 emphasis: on\n");
3469 snd_iprintf(buffer, "IEC958 emphasis: off\n");
3471 if (hdsp->control_register & HDSP_SPDIFNonAudio)
3472 snd_iprintf(buffer, "IEC958 NonAudio: on\n");
3474 snd_iprintf(buffer, "IEC958 NonAudio: off\n");
3475 if ((x = hdsp_spdif_sample_rate (hdsp)) != 0)
3476 snd_iprintf (buffer, "IEC958 sample rate: %d\n", x);
3478 snd_iprintf (buffer, "IEC958 sample rate: Error flag set\n");
3480 snd_iprintf(buffer, "\n");
3483 x = status & HDSP_Sync0;
3484 if (status & HDSP_Lock0)
3485 snd_iprintf(buffer, "ADAT1: %s\n", x ? "Sync" : "Lock");
3487 snd_iprintf(buffer, "ADAT1: No Lock\n");
3489 switch (hdsp->io_type) {
3492 x = status & HDSP_Sync1;
3493 if (status & HDSP_Lock1)
3494 snd_iprintf(buffer, "ADAT2: %s\n", x ? "Sync" : "Lock");
3496 snd_iprintf(buffer, "ADAT2: No Lock\n");
3497 x = status & HDSP_Sync2;
3498 if (status & HDSP_Lock2)
3499 snd_iprintf(buffer, "ADAT3: %s\n", x ? "Sync" : "Lock");
3501 snd_iprintf(buffer, "ADAT3: No Lock\n");
3508 x = status & HDSP_SPDIFSync;
3509 if (status & HDSP_SPDIFErrorFlag)
3510 snd_iprintf (buffer, "SPDIF: No Lock\n");
3512 snd_iprintf (buffer, "SPDIF: %s\n", x ? "Sync" : "Lock");
3514 x = status2 & HDSP_wc_sync;
3515 if (status2 & HDSP_wc_lock)
3516 snd_iprintf (buffer, "Word Clock: %s\n", x ? "Sync" : "Lock");
3518 snd_iprintf (buffer, "Word Clock: No Lock\n");
3520 x = status & HDSP_TimecodeSync;
3521 if (status & HDSP_TimecodeLock)
3522 snd_iprintf(buffer, "ADAT Sync: %s\n", x ? "Sync" : "Lock");
3524 snd_iprintf(buffer, "ADAT Sync: No Lock\n");
3526 snd_iprintf(buffer, "\n");
3528 /* Informations about H9632 specific controls */
3529 if (hdsp->io_type == H9632) {
3532 switch (hdsp_ad_gain(hdsp)) {
3543 snd_iprintf(buffer, "AD Gain : %s\n", tmp);
3545 switch (hdsp_da_gain(hdsp)) {
3556 snd_iprintf(buffer, "DA Gain : %s\n", tmp);
3558 switch (hdsp_phone_gain(hdsp)) {
3569 snd_iprintf(buffer, "Phones Gain : %s\n", tmp);
3571 snd_iprintf(buffer, "XLR Breakout Cable : %s\n", hdsp_xlr_breakout_cable(hdsp) ? "yes" : "no");
3573 if (hdsp->control_register & HDSP_AnalogExtensionBoard)
3574 snd_iprintf(buffer, "AEB : on (ADAT1 internal)\n");
3576 snd_iprintf(buffer, "AEB : off (ADAT1 external)\n");
3577 snd_iprintf(buffer, "\n");
3582 static void snd_hdsp_proc_init(struct hdsp *hdsp)
3584 struct snd_info_entry *entry;
3586 if (! snd_card_proc_new(hdsp->card, "hdsp", &entry))
3587 snd_info_set_text_ops(entry, hdsp, snd_hdsp_proc_read);
3590 static void snd_hdsp_free_buffers(struct hdsp *hdsp)
3592 snd_hammerfall_free_buffer(&hdsp->capture_dma_buf, hdsp->pci);
3593 snd_hammerfall_free_buffer(&hdsp->playback_dma_buf, hdsp->pci);
3596 static int __devinit snd_hdsp_initialize_memory(struct hdsp *hdsp)
3598 unsigned long pb_bus, cb_bus;
3600 if (snd_hammerfall_get_buffer(hdsp->pci, &hdsp->capture_dma_buf, HDSP_DMA_AREA_BYTES) < 0 ||
3601 snd_hammerfall_get_buffer(hdsp->pci, &hdsp->playback_dma_buf, HDSP_DMA_AREA_BYTES) < 0) {
3602 if (hdsp->capture_dma_buf.area)
3603 snd_dma_free_pages(&hdsp->capture_dma_buf);
3604 printk(KERN_ERR "%s: no buffers available\n", hdsp->card_name);
3608 /* Align to bus-space 64K boundary */
3610 cb_bus = ALIGN(hdsp->capture_dma_buf.addr, 0x10000ul);
3611 pb_bus = ALIGN(hdsp->playback_dma_buf.addr, 0x10000ul);
3613 /* Tell the card where it is */
3615 hdsp_write(hdsp, HDSP_inputBufferAddress, cb_bus);
3616 hdsp_write(hdsp, HDSP_outputBufferAddress, pb_bus);
3618 hdsp->capture_buffer = hdsp->capture_dma_buf.area + (cb_bus - hdsp->capture_dma_buf.addr);
3619 hdsp->playback_buffer = hdsp->playback_dma_buf.area + (pb_bus - hdsp->playback_dma_buf.addr);
3624 static int snd_hdsp_set_defaults(struct hdsp *hdsp)
3628 /* ASSUMPTION: hdsp->lock is either held, or
3629 there is no need to hold it (e.g. during module
3635 SPDIF Input via Coax
3637 maximum latency (7 => 2^7 = 8192 samples, 64Kbyte buffer,
3638 which implies 2 4096 sample, 32Kbyte periods).
3642 hdsp->control_register = HDSP_ClockModeMaster |
3643 HDSP_SPDIFInputCoaxial |
3644 hdsp_encode_latency(7) |
3648 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
3650 #ifdef SNDRV_BIG_ENDIAN
3651 hdsp->control2_register = HDSP_BIGENDIAN_MODE;
3653 hdsp->control2_register = 0;
3655 if (hdsp->io_type == H9652)
3656 snd_hdsp_9652_enable_mixer (hdsp);
3658 hdsp_write (hdsp, HDSP_control2Reg, hdsp->control2_register);
3660 hdsp_reset_hw_pointer(hdsp);
3661 hdsp_compute_period_size(hdsp);
3663 /* silence everything */
3665 for (i = 0; i < HDSP_MATRIX_MIXER_SIZE; ++i)
3666 hdsp->mixer_matrix[i] = MINUS_INFINITY_GAIN;
3668 for (i = 0; i < ((hdsp->io_type == H9652 || hdsp->io_type == H9632) ? 1352 : HDSP_MATRIX_MIXER_SIZE); ++i) {
3669 if (hdsp_write_gain (hdsp, i, MINUS_INFINITY_GAIN))
3673 /* H9632 specific defaults */
3674 if (hdsp->io_type == H9632) {
3675 hdsp->control_register |= (HDSP_DAGainPlus4dBu | HDSP_ADGainPlus4dBu | HDSP_PhoneGain0dB);
3676 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
3679 /* set a default rate so that the channel map is set up.
3682 hdsp_set_rate(hdsp, 48000, 1);
3687 static void hdsp_midi_tasklet(unsigned long arg)
3689 struct hdsp *hdsp = (struct hdsp *)arg;
3691 if (hdsp->midi[0].pending)
3692 snd_hdsp_midi_input_read (&hdsp->midi[0]);
3693 if (hdsp->midi[1].pending)
3694 snd_hdsp_midi_input_read (&hdsp->midi[1]);
3697 static irqreturn_t snd_hdsp_interrupt(int irq, void *dev_id)
3699 struct hdsp *hdsp = (struct hdsp *) dev_id;
3700 unsigned int status;
3704 unsigned int midi0status;
3705 unsigned int midi1status;
3708 status = hdsp_read(hdsp, HDSP_statusRegister);
3710 audio = status & HDSP_audioIRQPending;
3711 midi0 = status & HDSP_midi0IRQPending;
3712 midi1 = status & HDSP_midi1IRQPending;
3714 if (!audio && !midi0 && !midi1)
3717 hdsp_write(hdsp, HDSP_interruptConfirmation, 0);
3719 midi0status = hdsp_read (hdsp, HDSP_midiStatusIn0) & 0xff;
3720 midi1status = hdsp_read (hdsp, HDSP_midiStatusIn1) & 0xff;
3723 if (hdsp->capture_substream)
3724 snd_pcm_period_elapsed(hdsp->pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream);
3726 if (hdsp->playback_substream)
3727 snd_pcm_period_elapsed(hdsp->pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream);
3730 if (midi0 && midi0status) {
3731 if (hdsp->use_midi_tasklet) {
3732 /* we disable interrupts for this input until processing is done */
3733 hdsp->control_register &= ~HDSP_Midi0InterruptEnable;
3734 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
3735 hdsp->midi[0].pending = 1;
3738 snd_hdsp_midi_input_read (&hdsp->midi[0]);
3741 if (hdsp->io_type != Multiface && hdsp->io_type != H9632 && midi1 && midi1status) {
3742 if (hdsp->use_midi_tasklet) {
3743 /* we disable interrupts for this input until processing is done */
3744 hdsp->control_register &= ~HDSP_Midi1InterruptEnable;
3745 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
3746 hdsp->midi[1].pending = 1;
3749 snd_hdsp_midi_input_read (&hdsp->midi[1]);
3752 if (hdsp->use_midi_tasklet && schedule)
3753 tasklet_hi_schedule(&hdsp->midi_tasklet);
3757 static snd_pcm_uframes_t snd_hdsp_hw_pointer(struct snd_pcm_substream *substream)
3759 struct hdsp *hdsp = snd_pcm_substream_chip(substream);
3760 return hdsp_hw_pointer(hdsp);
3763 static char *hdsp_channel_buffer_location(struct hdsp *hdsp,
3770 if (snd_BUG_ON(channel < 0 || channel >= hdsp->max_channels))
3773 if ((mapped_channel = hdsp->channel_map[channel]) < 0)
3776 if (stream == SNDRV_PCM_STREAM_CAPTURE)
3777 return hdsp->capture_buffer + (mapped_channel * HDSP_CHANNEL_BUFFER_BYTES);
3779 return hdsp->playback_buffer + (mapped_channel * HDSP_CHANNEL_BUFFER_BYTES);
3782 static int snd_hdsp_playback_copy(struct snd_pcm_substream *substream, int channel,
3783 snd_pcm_uframes_t pos, void __user *src, snd_pcm_uframes_t count)
3785 struct hdsp *hdsp = snd_pcm_substream_chip(substream);
3788 if (snd_BUG_ON(pos + count > HDSP_CHANNEL_BUFFER_BYTES / 4))
3791 channel_buf = hdsp_channel_buffer_location (hdsp, substream->pstr->stream, channel);
3792 if (snd_BUG_ON(!channel_buf))
3794 if (copy_from_user(channel_buf + pos * 4, src, count * 4))
3799 static int snd_hdsp_capture_copy(struct snd_pcm_substream *substream, int channel,
3800 snd_pcm_uframes_t pos, void __user *dst, snd_pcm_uframes_t count)
3802 struct hdsp *hdsp = snd_pcm_substream_chip(substream);
3805 if (snd_BUG_ON(pos + count > HDSP_CHANNEL_BUFFER_BYTES / 4))
3808 channel_buf = hdsp_channel_buffer_location (hdsp, substream->pstr->stream, channel);
3809 if (snd_BUG_ON(!channel_buf))
3811 if (copy_to_user(dst, channel_buf + pos * 4, count * 4))
3816 static int snd_hdsp_hw_silence(struct snd_pcm_substream *substream, int channel,
3817 snd_pcm_uframes_t pos, snd_pcm_uframes_t count)
3819 struct hdsp *hdsp = snd_pcm_substream_chip(substream);
3822 channel_buf = hdsp_channel_buffer_location (hdsp, substream->pstr->stream, channel);
3823 if (snd_BUG_ON(!channel_buf))
3825 memset(channel_buf + pos * 4, 0, count * 4);
3829 static int snd_hdsp_reset(struct snd_pcm_substream *substream)
3831 struct snd_pcm_runtime *runtime = substream->runtime;
3832 struct hdsp *hdsp = snd_pcm_substream_chip(substream);
3833 struct snd_pcm_substream *other;
3834 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
3835 other = hdsp->capture_substream;
3837 other = hdsp->playback_substream;
3839 runtime->status->hw_ptr = hdsp_hw_pointer(hdsp);
3841 runtime->status->hw_ptr = 0;
3843 struct snd_pcm_substream *s;
3844 struct snd_pcm_runtime *oruntime = other->runtime;
3845 snd_pcm_group_for_each_entry(s, substream) {
3847 oruntime->status->hw_ptr = runtime->status->hw_ptr;
3855 static int snd_hdsp_hw_params(struct snd_pcm_substream *substream,
3856 struct snd_pcm_hw_params *params)
3858 struct hdsp *hdsp = snd_pcm_substream_chip(substream);
3863 if (hdsp_check_for_iobox (hdsp))
3866 if (hdsp_check_for_firmware(hdsp, 1))
3869 spin_lock_irq(&hdsp->lock);
3871 if (substream->pstr->stream == SNDRV_PCM_STREAM_PLAYBACK) {
3872 hdsp->control_register &= ~(HDSP_SPDIFProfessional | HDSP_SPDIFNonAudio | HDSP_SPDIFEmphasis);
3873 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register |= hdsp->creg_spdif_stream);
3874 this_pid = hdsp->playback_pid;
3875 other_pid = hdsp->capture_pid;
3877 this_pid = hdsp->capture_pid;
3878 other_pid = hdsp->playback_pid;
3881 if ((other_pid > 0) && (this_pid != other_pid)) {
3883 /* The other stream is open, and not by the same
3884 task as this one. Make sure that the parameters
3885 that matter are the same.
3888 if (params_rate(params) != hdsp->system_sample_rate) {
3889 spin_unlock_irq(&hdsp->lock);
3890 _snd_pcm_hw_param_setempty(params, SNDRV_PCM_HW_PARAM_RATE);
3894 if (params_period_size(params) != hdsp->period_bytes / 4) {
3895 spin_unlock_irq(&hdsp->lock);
3896 _snd_pcm_hw_param_setempty(params, SNDRV_PCM_HW_PARAM_PERIOD_SIZE);
3902 spin_unlock_irq(&hdsp->lock);
3906 spin_unlock_irq(&hdsp->lock);
3909 /* how to make sure that the rate matches an externally-set one ?
3912 spin_lock_irq(&hdsp->lock);
3913 if (! hdsp->clock_source_locked) {
3914 if ((err = hdsp_set_rate(hdsp, params_rate(params), 0)) < 0) {
3915 spin_unlock_irq(&hdsp->lock);
3916 _snd_pcm_hw_param_setempty(params, SNDRV_PCM_HW_PARAM_RATE);
3920 spin_unlock_irq(&hdsp->lock);
3922 if ((err = hdsp_set_interrupt_interval(hdsp, params_period_size(params))) < 0) {
3923 _snd_pcm_hw_param_setempty(params, SNDRV_PCM_HW_PARAM_PERIOD_SIZE);
3930 static int snd_hdsp_channel_info(struct snd_pcm_substream *substream,
3931 struct snd_pcm_channel_info *info)
3933 struct hdsp *hdsp = snd_pcm_substream_chip(substream);
3936 if (snd_BUG_ON(info->channel >= hdsp->max_channels))
3939 if ((mapped_channel = hdsp->channel_map[info->channel]) < 0)
3942 info->offset = mapped_channel * HDSP_CHANNEL_BUFFER_BYTES;
3948 static int snd_hdsp_ioctl(struct snd_pcm_substream *substream,
3949 unsigned int cmd, void *arg)
3952 case SNDRV_PCM_IOCTL1_RESET:
3953 return snd_hdsp_reset(substream);
3954 case SNDRV_PCM_IOCTL1_CHANNEL_INFO:
3955 return snd_hdsp_channel_info(substream, arg);
3960 return snd_pcm_lib_ioctl(substream, cmd, arg);
3963 static int snd_hdsp_trigger(struct snd_pcm_substream *substream, int cmd)
3965 struct hdsp *hdsp = snd_pcm_substream_chip(substream);
3966 struct snd_pcm_substream *other;
3969 if (hdsp_check_for_iobox (hdsp))
3972 if (hdsp_check_for_firmware(hdsp, 0)) /* no auto-loading in trigger */
3975 spin_lock(&hdsp->lock);
3976 running = hdsp->running;
3978 case SNDRV_PCM_TRIGGER_START:
3979 running |= 1 << substream->stream;
3981 case SNDRV_PCM_TRIGGER_STOP:
3982 running &= ~(1 << substream->stream);
3986 spin_unlock(&hdsp->lock);
3989 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
3990 other = hdsp->capture_substream;
3992 other = hdsp->playback_substream;
3995 struct snd_pcm_substream *s;
3996 snd_pcm_group_for_each_entry(s, substream) {
3998 snd_pcm_trigger_done(s, substream);
3999 if (cmd == SNDRV_PCM_TRIGGER_START)
4000 running |= 1 << s->stream;
4002 running &= ~(1 << s->stream);
4006 if (cmd == SNDRV_PCM_TRIGGER_START) {
4007 if (!(running & (1 << SNDRV_PCM_STREAM_PLAYBACK)) &&
4008 substream->stream == SNDRV_PCM_STREAM_CAPTURE)
4009 hdsp_silence_playback(hdsp);
4012 substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
4013 hdsp_silence_playback(hdsp);
4016 if (substream->stream == SNDRV_PCM_STREAM_CAPTURE)
4017 hdsp_silence_playback(hdsp);
4020 snd_pcm_trigger_done(substream, substream);
4021 if (!hdsp->running && running)
4022 hdsp_start_audio(hdsp);
4023 else if (hdsp->running && !running)
4024 hdsp_stop_audio(hdsp);
4025 hdsp->running = running;
4026 spin_unlock(&hdsp->lock);
4031 static int snd_hdsp_prepare(struct snd_pcm_substream *substream)
4033 struct hdsp *hdsp = snd_pcm_substream_chip(substream);
4036 if (hdsp_check_for_iobox (hdsp))
4039 if (hdsp_check_for_firmware(hdsp, 1))
4042 spin_lock_irq(&hdsp->lock);
4044 hdsp_reset_hw_pointer(hdsp);
4045 spin_unlock_irq(&hdsp->lock);
4049 static struct snd_pcm_hardware snd_hdsp_playback_subinfo =
4051 .info = (SNDRV_PCM_INFO_MMAP |
4052 SNDRV_PCM_INFO_MMAP_VALID |
4053 SNDRV_PCM_INFO_NONINTERLEAVED |
4054 SNDRV_PCM_INFO_SYNC_START |
4055 SNDRV_PCM_INFO_DOUBLE),
4056 #ifdef SNDRV_BIG_ENDIAN
4057 .formats = SNDRV_PCM_FMTBIT_S32_BE,
4059 .formats = SNDRV_PCM_FMTBIT_S32_LE,
4061 .rates = (SNDRV_PCM_RATE_32000 |
4062 SNDRV_PCM_RATE_44100 |
4063 SNDRV_PCM_RATE_48000 |
4064 SNDRV_PCM_RATE_64000 |
4065 SNDRV_PCM_RATE_88200 |
4066 SNDRV_PCM_RATE_96000),
4070 .channels_max = HDSP_MAX_CHANNELS,
4071 .buffer_bytes_max = HDSP_CHANNEL_BUFFER_BYTES * HDSP_MAX_CHANNELS,
4072 .period_bytes_min = (64 * 4) * 10,
4073 .period_bytes_max = (8192 * 4) * HDSP_MAX_CHANNELS,
4079 static struct snd_pcm_hardware snd_hdsp_capture_subinfo =
4081 .info = (SNDRV_PCM_INFO_MMAP |
4082 SNDRV_PCM_INFO_MMAP_VALID |
4083 SNDRV_PCM_INFO_NONINTERLEAVED |
4084 SNDRV_PCM_INFO_SYNC_START),
4085 #ifdef SNDRV_BIG_ENDIAN
4086 .formats = SNDRV_PCM_FMTBIT_S32_BE,
4088 .formats = SNDRV_PCM_FMTBIT_S32_LE,
4090 .rates = (SNDRV_PCM_RATE_32000 |
4091 SNDRV_PCM_RATE_44100 |
4092 SNDRV_PCM_RATE_48000 |
4093 SNDRV_PCM_RATE_64000 |
4094 SNDRV_PCM_RATE_88200 |
4095 SNDRV_PCM_RATE_96000),
4099 .channels_max = HDSP_MAX_CHANNELS,
4100 .buffer_bytes_max = HDSP_CHANNEL_BUFFER_BYTES * HDSP_MAX_CHANNELS,
4101 .period_bytes_min = (64 * 4) * 10,
4102 .period_bytes_max = (8192 * 4) * HDSP_MAX_CHANNELS,
4108 static unsigned int hdsp_period_sizes[] = { 64, 128, 256, 512, 1024, 2048, 4096, 8192 };
4110 static struct snd_pcm_hw_constraint_list hdsp_hw_constraints_period_sizes = {
4111 .count = ARRAY_SIZE(hdsp_period_sizes),
4112 .list = hdsp_period_sizes,
4116 static unsigned int hdsp_9632_sample_rates[] = { 32000, 44100, 48000, 64000, 88200, 96000, 128000, 176400, 192000 };
4118 static struct snd_pcm_hw_constraint_list hdsp_hw_constraints_9632_sample_rates = {
4119 .count = ARRAY_SIZE(hdsp_9632_sample_rates),
4120 .list = hdsp_9632_sample_rates,
4124 static int snd_hdsp_hw_rule_in_channels(struct snd_pcm_hw_params *params,
4125 struct snd_pcm_hw_rule *rule)
4127 struct hdsp *hdsp = rule->private;
4128 struct snd_interval *c = hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS);
4129 if (hdsp->io_type == H9632) {
4130 unsigned int list[3];
4131 list[0] = hdsp->qs_in_channels;
4132 list[1] = hdsp->ds_in_channels;
4133 list[2] = hdsp->ss_in_channels;
4134 return snd_interval_list(c, 3, list, 0);
4136 unsigned int list[2];
4137 list[0] = hdsp->ds_in_channels;
4138 list[1] = hdsp->ss_in_channels;
4139 return snd_interval_list(c, 2, list, 0);
4143 static int snd_hdsp_hw_rule_out_channels(struct snd_pcm_hw_params *params,
4144 struct snd_pcm_hw_rule *rule)
4146 unsigned int list[3];
4147 struct hdsp *hdsp = rule->private;
4148 struct snd_interval *c = hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS);
4149 if (hdsp->io_type == H9632) {
4150 list[0] = hdsp->qs_out_channels;
4151 list[1] = hdsp->ds_out_channels;
4152 list[2] = hdsp->ss_out_channels;
4153 return snd_interval_list(c, 3, list, 0);
4155 list[0] = hdsp->ds_out_channels;
4156 list[1] = hdsp->ss_out_channels;
4158 return snd_interval_list(c, 2, list, 0);
4161 static int snd_hdsp_hw_rule_in_channels_rate(struct snd_pcm_hw_params *params,
4162 struct snd_pcm_hw_rule *rule)
4164 struct hdsp *hdsp = rule->private;
4165 struct snd_interval *c = hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS);
4166 struct snd_interval *r = hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE);
4167 if (r->min > 96000 && hdsp->io_type == H9632) {
4168 struct snd_interval t = {
4169 .min = hdsp->qs_in_channels,
4170 .max = hdsp->qs_in_channels,
4173 return snd_interval_refine(c, &t);
4174 } else if (r->min > 48000 && r->max <= 96000) {
4175 struct snd_interval t = {
4176 .min = hdsp->ds_in_channels,
4177 .max = hdsp->ds_in_channels,
4180 return snd_interval_refine(c, &t);
4181 } else if (r->max < 64000) {
4182 struct snd_interval t = {
4183 .min = hdsp->ss_in_channels,
4184 .max = hdsp->ss_in_channels,
4187 return snd_interval_refine(c, &t);
4192 static int snd_hdsp_hw_rule_out_channels_rate(struct snd_pcm_hw_params *params,
4193 struct snd_pcm_hw_rule *rule)
4195 struct hdsp *hdsp = rule->private;
4196 struct snd_interval *c = hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS);
4197 struct snd_interval *r = hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE);
4198 if (r->min > 96000 && hdsp->io_type == H9632) {
4199 struct snd_interval t = {
4200 .min = hdsp->qs_out_channels,
4201 .max = hdsp->qs_out_channels,
4204 return snd_interval_refine(c, &t);
4205 } else if (r->min > 48000 && r->max <= 96000) {
4206 struct snd_interval t = {
4207 .min = hdsp->ds_out_channels,
4208 .max = hdsp->ds_out_channels,
4211 return snd_interval_refine(c, &t);
4212 } else if (r->max < 64000) {
4213 struct snd_interval t = {
4214 .min = hdsp->ss_out_channels,
4215 .max = hdsp->ss_out_channels,
4218 return snd_interval_refine(c, &t);
4223 static int snd_hdsp_hw_rule_rate_out_channels(struct snd_pcm_hw_params *params,
4224 struct snd_pcm_hw_rule *rule)
4226 struct hdsp *hdsp = rule->private;
4227 struct snd_interval *c = hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS);
4228 struct snd_interval *r = hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE);
4229 if (c->min >= hdsp->ss_out_channels) {
4230 struct snd_interval t = {
4235 return snd_interval_refine(r, &t);
4236 } else if (c->max <= hdsp->qs_out_channels && hdsp->io_type == H9632) {
4237 struct snd_interval t = {
4242 return snd_interval_refine(r, &t);
4243 } else if (c->max <= hdsp->ds_out_channels) {
4244 struct snd_interval t = {
4249 return snd_interval_refine(r, &t);
4254 static int snd_hdsp_hw_rule_rate_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 struct snd_interval *r = hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE);
4260 if (c->min >= hdsp->ss_in_channels) {
4261 struct snd_interval t = {
4266 return snd_interval_refine(r, &t);
4267 } else if (c->max <= hdsp->qs_in_channels && hdsp->io_type == H9632) {
4268 struct snd_interval t = {
4273 return snd_interval_refine(r, &t);
4274 } else if (c->max <= hdsp->ds_in_channels) {
4275 struct snd_interval t = {
4280 return snd_interval_refine(r, &t);
4285 static int snd_hdsp_playback_open(struct snd_pcm_substream *substream)
4287 struct hdsp *hdsp = snd_pcm_substream_chip(substream);
4288 struct snd_pcm_runtime *runtime = substream->runtime;
4290 if (hdsp_check_for_iobox (hdsp))
4293 if (hdsp_check_for_firmware(hdsp, 1))
4296 spin_lock_irq(&hdsp->lock);
4298 snd_pcm_set_sync(substream);
4300 runtime->hw = snd_hdsp_playback_subinfo;
4301 runtime->dma_area = hdsp->playback_buffer;
4302 runtime->dma_bytes = HDSP_DMA_AREA_BYTES;
4304 hdsp->playback_pid = current->pid;
4305 hdsp->playback_substream = substream;
4307 spin_unlock_irq(&hdsp->lock);
4309 snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24);
4310 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_SIZE, &hdsp_hw_constraints_period_sizes);
4311 if (hdsp->clock_source_locked) {
4312 runtime->hw.rate_min = runtime->hw.rate_max = hdsp->system_sample_rate;
4313 } else if (hdsp->io_type == H9632) {
4314 runtime->hw.rate_max = 192000;
4315 runtime->hw.rates = SNDRV_PCM_RATE_KNOT;
4316 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, &hdsp_hw_constraints_9632_sample_rates);
4318 if (hdsp->io_type == H9632) {
4319 runtime->hw.channels_min = hdsp->qs_out_channels;
4320 runtime->hw.channels_max = hdsp->ss_out_channels;
4323 snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
4324 snd_hdsp_hw_rule_out_channels, hdsp,
4325 SNDRV_PCM_HW_PARAM_CHANNELS, -1);
4326 snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
4327 snd_hdsp_hw_rule_out_channels_rate, hdsp,
4328 SNDRV_PCM_HW_PARAM_RATE, -1);
4329 snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
4330 snd_hdsp_hw_rule_rate_out_channels, hdsp,
4331 SNDRV_PCM_HW_PARAM_CHANNELS, -1);
4333 hdsp->creg_spdif_stream = hdsp->creg_spdif;
4334 hdsp->spdif_ctl->vd[0].access &= ~SNDRV_CTL_ELEM_ACCESS_INACTIVE;
4335 snd_ctl_notify(hdsp->card, SNDRV_CTL_EVENT_MASK_VALUE |
4336 SNDRV_CTL_EVENT_MASK_INFO, &hdsp->spdif_ctl->id);
4340 static int snd_hdsp_playback_release(struct snd_pcm_substream *substream)
4342 struct hdsp *hdsp = snd_pcm_substream_chip(substream);
4344 spin_lock_irq(&hdsp->lock);
4346 hdsp->playback_pid = -1;
4347 hdsp->playback_substream = NULL;
4349 spin_unlock_irq(&hdsp->lock);
4351 hdsp->spdif_ctl->vd[0].access |= SNDRV_CTL_ELEM_ACCESS_INACTIVE;
4352 snd_ctl_notify(hdsp->card, SNDRV_CTL_EVENT_MASK_VALUE |
4353 SNDRV_CTL_EVENT_MASK_INFO, &hdsp->spdif_ctl->id);
4358 static int snd_hdsp_capture_open(struct snd_pcm_substream *substream)
4360 struct hdsp *hdsp = snd_pcm_substream_chip(substream);
4361 struct snd_pcm_runtime *runtime = substream->runtime;
4363 if (hdsp_check_for_iobox (hdsp))
4366 if (hdsp_check_for_firmware(hdsp, 1))
4369 spin_lock_irq(&hdsp->lock);
4371 snd_pcm_set_sync(substream);
4373 runtime->hw = snd_hdsp_capture_subinfo;
4374 runtime->dma_area = hdsp->capture_buffer;
4375 runtime->dma_bytes = HDSP_DMA_AREA_BYTES;
4377 hdsp->capture_pid = current->pid;
4378 hdsp->capture_substream = substream;
4380 spin_unlock_irq(&hdsp->lock);
4382 snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24);
4383 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_SIZE, &hdsp_hw_constraints_period_sizes);
4384 if (hdsp->io_type == H9632) {
4385 runtime->hw.channels_min = hdsp->qs_in_channels;
4386 runtime->hw.channels_max = hdsp->ss_in_channels;
4387 runtime->hw.rate_max = 192000;
4388 runtime->hw.rates = SNDRV_PCM_RATE_KNOT;
4389 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, &hdsp_hw_constraints_9632_sample_rates);
4391 snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
4392 snd_hdsp_hw_rule_in_channels, hdsp,
4393 SNDRV_PCM_HW_PARAM_CHANNELS, -1);
4394 snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
4395 snd_hdsp_hw_rule_in_channels_rate, hdsp,
4396 SNDRV_PCM_HW_PARAM_RATE, -1);
4397 snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
4398 snd_hdsp_hw_rule_rate_in_channels, hdsp,
4399 SNDRV_PCM_HW_PARAM_CHANNELS, -1);
4403 static int snd_hdsp_capture_release(struct snd_pcm_substream *substream)
4405 struct hdsp *hdsp = snd_pcm_substream_chip(substream);
4407 spin_lock_irq(&hdsp->lock);
4409 hdsp->capture_pid = -1;
4410 hdsp->capture_substream = NULL;
4412 spin_unlock_irq(&hdsp->lock);
4416 static int snd_hdsp_hwdep_dummy_op(struct snd_hwdep *hw, struct file *file)
4418 /* we have nothing to initialize but the call is required */
4423 /* helper functions for copying meter values */
4424 static inline int copy_u32_le(void __user *dest, void __iomem *src)
4426 u32 val = readl(src);
4427 return copy_to_user(dest, &val, 4);
4430 static inline int copy_u64_le(void __user *dest, void __iomem *src_low, void __iomem *src_high)
4432 u32 rms_low, rms_high;
4434 rms_low = readl(src_low);
4435 rms_high = readl(src_high);
4436 rms = ((u64)rms_high << 32) | rms_low;
4437 return copy_to_user(dest, &rms, 8);
4440 static inline int copy_u48_le(void __user *dest, void __iomem *src_low, void __iomem *src_high)
4442 u32 rms_low, rms_high;
4444 rms_low = readl(src_low) & 0xffffff00;
4445 rms_high = readl(src_high) & 0xffffff00;
4446 rms = ((u64)rms_high << 32) | rms_low;
4447 return copy_to_user(dest, &rms, 8);
4450 static int hdsp_9652_get_peak(struct hdsp *hdsp, struct hdsp_peak_rms __user *peak_rms)
4452 int doublespeed = 0;
4453 int i, j, channels, ofs;
4455 if (hdsp_read (hdsp, HDSP_statusRegister) & HDSP_DoubleSpeedStatus)
4457 channels = doublespeed ? 14 : 26;
4458 for (i = 0, j = 0; i < 26; ++i) {
4459 if (doublespeed && (i & 4))
4461 ofs = HDSP_9652_peakBase - j * 4;
4462 if (copy_u32_le(&peak_rms->input_peaks[i], hdsp->iobase + ofs))
4464 ofs -= channels * 4;
4465 if (copy_u32_le(&peak_rms->playback_peaks[i], hdsp->iobase + ofs))
4467 ofs -= channels * 4;
4468 if (copy_u32_le(&peak_rms->output_peaks[i], hdsp->iobase + ofs))
4470 ofs = HDSP_9652_rmsBase + j * 8;
4471 if (copy_u48_le(&peak_rms->input_rms[i], hdsp->iobase + ofs,
4472 hdsp->iobase + ofs + 4))
4474 ofs += channels * 8;
4475 if (copy_u48_le(&peak_rms->playback_rms[i], hdsp->iobase + ofs,
4476 hdsp->iobase + ofs + 4))
4478 ofs += channels * 8;
4479 if (copy_u48_le(&peak_rms->output_rms[i], hdsp->iobase + ofs,
4480 hdsp->iobase + ofs + 4))
4487 static int hdsp_9632_get_peak(struct hdsp *hdsp, struct hdsp_peak_rms __user *peak_rms)
4490 struct hdsp_9632_meters __iomem *m;
4491 int doublespeed = 0;
4493 if (hdsp_read (hdsp, HDSP_statusRegister) & HDSP_DoubleSpeedStatus)
4495 m = (struct hdsp_9632_meters __iomem *)(hdsp->iobase+HDSP_9632_metersBase);
4496 for (i = 0, j = 0; i < 16; ++i, ++j) {
4497 if (copy_u32_le(&peak_rms->input_peaks[i], &m->input_peak[j]))
4499 if (copy_u32_le(&peak_rms->playback_peaks[i], &m->playback_peak[j]))
4501 if (copy_u32_le(&peak_rms->output_peaks[i], &m->output_peak[j]))
4503 if (copy_u64_le(&peak_rms->input_rms[i], &m->input_rms_low[j],
4504 &m->input_rms_high[j]))
4506 if (copy_u64_le(&peak_rms->playback_rms[i], &m->playback_rms_low[j],
4507 &m->playback_rms_high[j]))
4509 if (copy_u64_le(&peak_rms->output_rms[i], &m->output_rms_low[j],
4510 &m->output_rms_high[j]))
4512 if (doublespeed && i == 3) i += 4;
4517 static int hdsp_get_peak(struct hdsp *hdsp, struct hdsp_peak_rms __user *peak_rms)
4521 for (i = 0; i < 26; i++) {
4522 if (copy_u32_le(&peak_rms->playback_peaks[i],
4523 hdsp->iobase + HDSP_playbackPeakLevel + i * 4))
4525 if (copy_u32_le(&peak_rms->input_peaks[i],
4526 hdsp->iobase + HDSP_inputPeakLevel + i * 4))
4529 for (i = 0; i < 28; i++) {
4530 if (copy_u32_le(&peak_rms->output_peaks[i],
4531 hdsp->iobase + HDSP_outputPeakLevel + i * 4))
4534 for (i = 0; i < 26; ++i) {
4535 if (copy_u64_le(&peak_rms->playback_rms[i],
4536 hdsp->iobase + HDSP_playbackRmsLevel + i * 8 + 4,
4537 hdsp->iobase + HDSP_playbackRmsLevel + i * 8))
4539 if (copy_u64_le(&peak_rms->input_rms[i],
4540 hdsp->iobase + HDSP_inputRmsLevel + i * 8 + 4,
4541 hdsp->iobase + HDSP_inputRmsLevel + i * 8))
4547 static int snd_hdsp_hwdep_ioctl(struct snd_hwdep *hw, struct file *file, unsigned int cmd, unsigned long arg)
4549 struct hdsp *hdsp = (struct hdsp *)hw->private_data;
4550 void __user *argp = (void __user *)arg;
4554 case SNDRV_HDSP_IOCTL_GET_PEAK_RMS: {
4555 struct hdsp_peak_rms __user *peak_rms = (struct hdsp_peak_rms __user *)arg;
4557 err = hdsp_check_for_iobox(hdsp);
4561 err = hdsp_check_for_firmware(hdsp, 1);
4565 if (!(hdsp->state & HDSP_FirmwareLoaded)) {
4566 snd_printk(KERN_ERR "Hammerfall-DSP: firmware needs to be uploaded to the card.\n");
4570 switch (hdsp->io_type) {
4572 return hdsp_9652_get_peak(hdsp, peak_rms);
4574 return hdsp_9632_get_peak(hdsp, peak_rms);
4576 return hdsp_get_peak(hdsp, peak_rms);
4579 case SNDRV_HDSP_IOCTL_GET_CONFIG_INFO: {
4580 struct hdsp_config_info info;
4581 unsigned long flags;
4584 err = hdsp_check_for_iobox(hdsp);
4588 err = hdsp_check_for_firmware(hdsp, 1);
4592 spin_lock_irqsave(&hdsp->lock, flags);
4593 info.pref_sync_ref = (unsigned char)hdsp_pref_sync_ref(hdsp);
4594 info.wordclock_sync_check = (unsigned char)hdsp_wc_sync_check(hdsp);
4595 if (hdsp->io_type != H9632)
4596 info.adatsync_sync_check = (unsigned char)hdsp_adatsync_sync_check(hdsp);
4597 info.spdif_sync_check = (unsigned char)hdsp_spdif_sync_check(hdsp);
4598 for (i = 0; i < ((hdsp->io_type != Multiface && hdsp->io_type != H9632) ? 3 : 1); ++i)
4599 info.adat_sync_check[i] = (unsigned char)hdsp_adat_sync_check(hdsp, i);
4600 info.spdif_in = (unsigned char)hdsp_spdif_in(hdsp);
4601 info.spdif_out = (unsigned char)hdsp_spdif_out(hdsp);
4602 info.spdif_professional = (unsigned char)hdsp_spdif_professional(hdsp);
4603 info.spdif_emphasis = (unsigned char)hdsp_spdif_emphasis(hdsp);
4604 info.spdif_nonaudio = (unsigned char)hdsp_spdif_nonaudio(hdsp);
4605 info.spdif_sample_rate = hdsp_spdif_sample_rate(hdsp);
4606 info.system_sample_rate = hdsp->system_sample_rate;
4607 info.autosync_sample_rate = hdsp_external_sample_rate(hdsp);
4608 info.system_clock_mode = (unsigned char)hdsp_system_clock_mode(hdsp);
4609 info.clock_source = (unsigned char)hdsp_clock_source(hdsp);
4610 info.autosync_ref = (unsigned char)hdsp_autosync_ref(hdsp);
4611 info.line_out = (unsigned char)hdsp_line_out(hdsp);
4612 if (hdsp->io_type == H9632) {
4613 info.da_gain = (unsigned char)hdsp_da_gain(hdsp);
4614 info.ad_gain = (unsigned char)hdsp_ad_gain(hdsp);
4615 info.phone_gain = (unsigned char)hdsp_phone_gain(hdsp);
4616 info.xlr_breakout_cable = (unsigned char)hdsp_xlr_breakout_cable(hdsp);
4619 if (hdsp->io_type == H9632 || hdsp->io_type == H9652)
4620 info.analog_extension_board = (unsigned char)hdsp_aeb(hdsp);
4621 spin_unlock_irqrestore(&hdsp->lock, flags);
4622 if (copy_to_user(argp, &info, sizeof(info)))
4626 case SNDRV_HDSP_IOCTL_GET_9632_AEB: {
4627 struct hdsp_9632_aeb h9632_aeb;
4629 if (hdsp->io_type != H9632) return -EINVAL;
4630 h9632_aeb.aebi = hdsp->ss_in_channels - H9632_SS_CHANNELS;
4631 h9632_aeb.aebo = hdsp->ss_out_channels - H9632_SS_CHANNELS;
4632 if (copy_to_user(argp, &h9632_aeb, sizeof(h9632_aeb)))
4636 case SNDRV_HDSP_IOCTL_GET_VERSION: {
4637 struct hdsp_version hdsp_version;
4640 if (hdsp->io_type == H9652 || hdsp->io_type == H9632) return -EINVAL;
4641 if (hdsp->io_type == Undefined) {
4642 if ((err = hdsp_get_iobox_version(hdsp)) < 0)
4645 hdsp_version.io_type = hdsp->io_type;
4646 hdsp_version.firmware_rev = hdsp->firmware_rev;
4647 if ((err = copy_to_user(argp, &hdsp_version, sizeof(hdsp_version))))
4651 case SNDRV_HDSP_IOCTL_UPLOAD_FIRMWARE: {
4652 struct hdsp_firmware __user *firmware;
4653 u32 __user *firmware_data;
4656 if (hdsp->io_type == H9652 || hdsp->io_type == H9632) return -EINVAL;
4657 /* SNDRV_HDSP_IOCTL_GET_VERSION must have been called */
4658 if (hdsp->io_type == Undefined) return -EINVAL;
4660 if (hdsp->state & (HDSP_FirmwareCached | HDSP_FirmwareLoaded))
4663 snd_printk(KERN_INFO "Hammerfall-DSP: initializing firmware upload\n");
4664 firmware = (struct hdsp_firmware __user *)argp;
4666 if (get_user(firmware_data, &firmware->firmware_data))
4669 if (hdsp_check_for_iobox (hdsp))
4672 if (copy_from_user(hdsp->firmware_cache, firmware_data, sizeof(hdsp->firmware_cache)) != 0)
4675 hdsp->state |= HDSP_FirmwareCached;
4677 if ((err = snd_hdsp_load_firmware_from_cache(hdsp)) < 0)
4680 if (!(hdsp->state & HDSP_InitializationComplete)) {
4681 if ((err = snd_hdsp_enable_io(hdsp)) < 0)
4684 snd_hdsp_initialize_channels(hdsp);
4685 snd_hdsp_initialize_midi_flush(hdsp);
4687 if ((err = snd_hdsp_create_alsa_devices(hdsp->card, hdsp)) < 0) {
4688 snd_printk(KERN_ERR "Hammerfall-DSP: error creating alsa devices\n");
4694 case SNDRV_HDSP_IOCTL_GET_MIXER: {
4695 struct hdsp_mixer __user *mixer = (struct hdsp_mixer __user *)argp;
4696 if (copy_to_user(mixer->matrix, hdsp->mixer_matrix, sizeof(unsigned short)*HDSP_MATRIX_MIXER_SIZE))
4706 static struct snd_pcm_ops snd_hdsp_playback_ops = {
4707 .open = snd_hdsp_playback_open,
4708 .close = snd_hdsp_playback_release,
4709 .ioctl = snd_hdsp_ioctl,
4710 .hw_params = snd_hdsp_hw_params,
4711 .prepare = snd_hdsp_prepare,
4712 .trigger = snd_hdsp_trigger,
4713 .pointer = snd_hdsp_hw_pointer,
4714 .copy = snd_hdsp_playback_copy,
4715 .silence = snd_hdsp_hw_silence,
4718 static struct snd_pcm_ops snd_hdsp_capture_ops = {
4719 .open = snd_hdsp_capture_open,
4720 .close = snd_hdsp_capture_release,
4721 .ioctl = snd_hdsp_ioctl,
4722 .hw_params = snd_hdsp_hw_params,
4723 .prepare = snd_hdsp_prepare,
4724 .trigger = snd_hdsp_trigger,
4725 .pointer = snd_hdsp_hw_pointer,
4726 .copy = snd_hdsp_capture_copy,
4729 static int snd_hdsp_create_hwdep(struct snd_card *card, struct hdsp *hdsp)
4731 struct snd_hwdep *hw;
4734 if ((err = snd_hwdep_new(card, "HDSP hwdep", 0, &hw)) < 0)
4738 hw->private_data = hdsp;
4739 strcpy(hw->name, "HDSP hwdep interface");
4741 hw->ops.open = snd_hdsp_hwdep_dummy_op;
4742 hw->ops.ioctl = snd_hdsp_hwdep_ioctl;
4743 hw->ops.release = snd_hdsp_hwdep_dummy_op;
4748 static int snd_hdsp_create_pcm(struct snd_card *card, struct hdsp *hdsp)
4750 struct snd_pcm *pcm;
4753 if ((err = snd_pcm_new(card, hdsp->card_name, 0, 1, 1, &pcm)) < 0)
4757 pcm->private_data = hdsp;
4758 strcpy(pcm->name, hdsp->card_name);
4760 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_hdsp_playback_ops);
4761 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_hdsp_capture_ops);
4763 pcm->info_flags = SNDRV_PCM_INFO_JOINT_DUPLEX;
4768 static void snd_hdsp_9652_enable_mixer (struct hdsp *hdsp)
4770 hdsp->control2_register |= HDSP_9652_ENABLE_MIXER;
4771 hdsp_write (hdsp, HDSP_control2Reg, hdsp->control2_register);
4774 static int snd_hdsp_enable_io (struct hdsp *hdsp)
4778 if (hdsp_fifo_wait (hdsp, 0, 100)) {
4779 snd_printk(KERN_ERR "Hammerfall-DSP: enable_io fifo_wait failed\n");
4783 for (i = 0; i < hdsp->max_channels; ++i) {
4784 hdsp_write (hdsp, HDSP_inputEnable + (4 * i), 1);
4785 hdsp_write (hdsp, HDSP_outputEnable + (4 * i), 1);
4791 static void snd_hdsp_initialize_channels(struct hdsp *hdsp)
4793 int status, aebi_channels, aebo_channels;
4795 switch (hdsp->io_type) {
4797 hdsp->card_name = "RME Hammerfall DSP + Digiface";
4798 hdsp->ss_in_channels = hdsp->ss_out_channels = DIGIFACE_SS_CHANNELS;
4799 hdsp->ds_in_channels = hdsp->ds_out_channels = DIGIFACE_DS_CHANNELS;
4803 hdsp->card_name = "RME Hammerfall HDSP 9652";
4804 hdsp->ss_in_channels = hdsp->ss_out_channels = H9652_SS_CHANNELS;
4805 hdsp->ds_in_channels = hdsp->ds_out_channels = H9652_DS_CHANNELS;
4809 status = hdsp_read(hdsp, HDSP_statusRegister);
4810 /* HDSP_AEBx bits are low when AEB are connected */
4811 aebi_channels = (status & HDSP_AEBI) ? 0 : 4;
4812 aebo_channels = (status & HDSP_AEBO) ? 0 : 4;
4813 hdsp->card_name = "RME Hammerfall HDSP 9632";
4814 hdsp->ss_in_channels = H9632_SS_CHANNELS+aebi_channels;
4815 hdsp->ds_in_channels = H9632_DS_CHANNELS+aebi_channels;
4816 hdsp->qs_in_channels = H9632_QS_CHANNELS+aebi_channels;
4817 hdsp->ss_out_channels = H9632_SS_CHANNELS+aebo_channels;
4818 hdsp->ds_out_channels = H9632_DS_CHANNELS+aebo_channels;
4819 hdsp->qs_out_channels = H9632_QS_CHANNELS+aebo_channels;
4823 hdsp->card_name = "RME Hammerfall DSP + Multiface";
4824 hdsp->ss_in_channels = hdsp->ss_out_channels = MULTIFACE_SS_CHANNELS;
4825 hdsp->ds_in_channels = hdsp->ds_out_channels = MULTIFACE_DS_CHANNELS;
4829 /* should never get here */
4834 static void snd_hdsp_initialize_midi_flush (struct hdsp *hdsp)
4836 snd_hdsp_flush_midi_input (hdsp, 0);
4837 snd_hdsp_flush_midi_input (hdsp, 1);
4840 static int snd_hdsp_create_alsa_devices(struct snd_card *card, struct hdsp *hdsp)
4844 if ((err = snd_hdsp_create_pcm(card, hdsp)) < 0) {
4845 snd_printk(KERN_ERR "Hammerfall-DSP: Error creating pcm interface\n");
4850 if ((err = snd_hdsp_create_midi(card, hdsp, 0)) < 0) {
4851 snd_printk(KERN_ERR "Hammerfall-DSP: Error creating first midi interface\n");
4855 if (hdsp->io_type == Digiface || hdsp->io_type == H9652) {
4856 if ((err = snd_hdsp_create_midi(card, hdsp, 1)) < 0) {
4857 snd_printk(KERN_ERR "Hammerfall-DSP: Error creating second midi interface\n");
4862 if ((err = snd_hdsp_create_controls(card, hdsp)) < 0) {
4863 snd_printk(KERN_ERR "Hammerfall-DSP: Error creating ctl interface\n");
4867 snd_hdsp_proc_init(hdsp);
4869 hdsp->system_sample_rate = -1;
4870 hdsp->playback_pid = -1;
4871 hdsp->capture_pid = -1;
4872 hdsp->capture_substream = NULL;
4873 hdsp->playback_substream = NULL;
4875 if ((err = snd_hdsp_set_defaults(hdsp)) < 0) {
4876 snd_printk(KERN_ERR "Hammerfall-DSP: Error setting default values\n");
4880 if (!(hdsp->state & HDSP_InitializationComplete)) {
4881 strcpy(card->shortname, "Hammerfall DSP");
4882 sprintf(card->longname, "%s at 0x%lx, irq %d", hdsp->card_name,
4883 hdsp->port, hdsp->irq);
4885 if ((err = snd_card_register(card)) < 0) {
4886 snd_printk(KERN_ERR "Hammerfall-DSP: error registering card\n");
4889 hdsp->state |= HDSP_InitializationComplete;
4895 #ifdef HDSP_FW_LOADER
4896 /* load firmware via hotplug fw loader */
4897 static int hdsp_request_fw_loader(struct hdsp *hdsp)
4900 const struct firmware *fw;
4903 if (hdsp->io_type == H9652 || hdsp->io_type == H9632)
4905 if (hdsp->io_type == Undefined) {
4906 if ((err = hdsp_get_iobox_version(hdsp)) < 0)
4908 if (hdsp->io_type == H9652 || hdsp->io_type == H9632)
4912 /* caution: max length of firmware filename is 30! */
4913 switch (hdsp->io_type) {
4915 if (hdsp->firmware_rev == 0xa)
4916 fwfile = "multiface_firmware.bin";
4918 fwfile = "multiface_firmware_rev11.bin";
4921 if (hdsp->firmware_rev == 0xa)
4922 fwfile = "digiface_firmware.bin";
4924 fwfile = "digiface_firmware_rev11.bin";
4927 snd_printk(KERN_ERR "Hammerfall-DSP: invalid io_type %d\n", hdsp->io_type);
4931 if (request_firmware(&fw, fwfile, &hdsp->pci->dev)) {
4932 snd_printk(KERN_ERR "Hammerfall-DSP: cannot load firmware %s\n", fwfile);
4935 if (fw->size < sizeof(hdsp->firmware_cache)) {
4936 snd_printk(KERN_ERR "Hammerfall-DSP: too short firmware size %d (expected %d)\n",
4937 (int)fw->size, (int)sizeof(hdsp->firmware_cache));
4938 release_firmware(fw);
4942 memcpy(hdsp->firmware_cache, fw->data, sizeof(hdsp->firmware_cache));
4944 release_firmware(fw);
4946 hdsp->state |= HDSP_FirmwareCached;
4948 if ((err = snd_hdsp_load_firmware_from_cache(hdsp)) < 0)
4951 if (!(hdsp->state & HDSP_InitializationComplete)) {
4952 if ((err = snd_hdsp_enable_io(hdsp)) < 0)
4955 if ((err = snd_hdsp_create_hwdep(hdsp->card, hdsp)) < 0) {
4956 snd_printk(KERN_ERR "Hammerfall-DSP: error creating hwdep device\n");
4959 snd_hdsp_initialize_channels(hdsp);
4960 snd_hdsp_initialize_midi_flush(hdsp);
4961 if ((err = snd_hdsp_create_alsa_devices(hdsp->card, hdsp)) < 0) {
4962 snd_printk(KERN_ERR "Hammerfall-DSP: error creating alsa devices\n");
4970 static int __devinit snd_hdsp_create(struct snd_card *card,
4973 struct pci_dev *pci = hdsp->pci;
4980 hdsp->midi[0].rmidi = NULL;
4981 hdsp->midi[1].rmidi = NULL;
4982 hdsp->midi[0].input = NULL;
4983 hdsp->midi[1].input = NULL;
4984 hdsp->midi[0].output = NULL;
4985 hdsp->midi[1].output = NULL;
4986 hdsp->midi[0].pending = 0;
4987 hdsp->midi[1].pending = 0;
4988 spin_lock_init(&hdsp->midi[0].lock);
4989 spin_lock_init(&hdsp->midi[1].lock);
4990 hdsp->iobase = NULL;
4991 hdsp->control_register = 0;
4992 hdsp->control2_register = 0;
4993 hdsp->io_type = Undefined;
4994 hdsp->max_channels = 26;
4998 spin_lock_init(&hdsp->lock);
5000 tasklet_init(&hdsp->midi_tasklet, hdsp_midi_tasklet, (unsigned long)hdsp);
5002 pci_read_config_word(hdsp->pci, PCI_CLASS_REVISION, &hdsp->firmware_rev);
5003 hdsp->firmware_rev &= 0xff;
5005 /* From Martin Bjoernsen :
5006 "It is important that the card's latency timer register in
5007 the PCI configuration space is set to a value much larger
5008 than 0 by the computer's BIOS or the driver.
5009 The windows driver always sets this 8 bit register [...]
5010 to its maximum 255 to avoid problems with some computers."
5012 pci_write_config_byte(hdsp->pci, PCI_LATENCY_TIMER, 0xFF);
5014 strcpy(card->driver, "H-DSP");
5015 strcpy(card->mixername, "Xilinx FPGA");
5017 if (hdsp->firmware_rev < 0xa)
5019 else if (hdsp->firmware_rev < 0x64)
5020 hdsp->card_name = "RME Hammerfall DSP";
5021 else if (hdsp->firmware_rev < 0x96) {
5022 hdsp->card_name = "RME HDSP 9652";
5025 hdsp->card_name = "RME HDSP 9632";
5026 hdsp->max_channels = 16;
5030 if ((err = pci_enable_device(pci)) < 0)
5033 pci_set_master(hdsp->pci);
5035 if ((err = pci_request_regions(pci, "hdsp")) < 0)
5037 hdsp->port = pci_resource_start(pci, 0);
5038 if ((hdsp->iobase = ioremap_nocache(hdsp->port, HDSP_IO_EXTENT)) == NULL) {
5039 snd_printk(KERN_ERR "Hammerfall-DSP: unable to remap region 0x%lx-0x%lx\n", hdsp->port, hdsp->port + HDSP_IO_EXTENT - 1);
5043 if (request_irq(pci->irq, snd_hdsp_interrupt, IRQF_SHARED,
5045 snd_printk(KERN_ERR "Hammerfall-DSP: unable to use IRQ %d\n", pci->irq);
5049 hdsp->irq = pci->irq;
5050 hdsp->precise_ptr = 0;
5051 hdsp->use_midi_tasklet = 1;
5052 hdsp->dds_value = 0;
5054 if ((err = snd_hdsp_initialize_memory(hdsp)) < 0)
5057 if (!is_9652 && !is_9632) {
5058 /* we wait 2 seconds to let freshly inserted cardbus cards do their hardware init */
5061 err = hdsp_check_for_iobox(hdsp);
5065 if ((hdsp_read (hdsp, HDSP_statusRegister) & HDSP_DllError) != 0) {
5066 #ifdef HDSP_FW_LOADER
5067 if ((err = hdsp_request_fw_loader(hdsp)) < 0)
5068 /* we don't fail as this can happen
5069 if userspace is not ready for
5072 snd_printk(KERN_ERR "Hammerfall-DSP: couldn't get firmware from userspace. try using hdsploader\n");
5074 /* init is complete, we return */
5077 /* we defer initialization */
5078 snd_printk(KERN_INFO "Hammerfall-DSP: card initialization pending : waiting for firmware\n");
5079 if ((err = snd_hdsp_create_hwdep(card, hdsp)) < 0)
5083 snd_printk(KERN_INFO "Hammerfall-DSP: Firmware already present, initializing card.\n");
5084 if (hdsp_read(hdsp, HDSP_status2Register) & HDSP_version1)
5085 hdsp->io_type = Multiface;
5087 hdsp->io_type = Digiface;
5091 if ((err = snd_hdsp_enable_io(hdsp)) != 0)
5095 hdsp->io_type = H9652;
5098 hdsp->io_type = H9632;
5100 if ((err = snd_hdsp_create_hwdep(card, hdsp)) < 0)
5103 snd_hdsp_initialize_channels(hdsp);
5104 snd_hdsp_initialize_midi_flush(hdsp);
5106 hdsp->state |= HDSP_FirmwareLoaded;
5108 if ((err = snd_hdsp_create_alsa_devices(card, hdsp)) < 0)
5114 static int snd_hdsp_free(struct hdsp *hdsp)
5117 /* stop the audio, and cancel all interrupts */
5118 tasklet_kill(&hdsp->midi_tasklet);
5119 hdsp->control_register &= ~(HDSP_Start|HDSP_AudioInterruptEnable|HDSP_Midi0InterruptEnable|HDSP_Midi1InterruptEnable);
5120 hdsp_write (hdsp, HDSP_controlRegister, hdsp->control_register);
5124 free_irq(hdsp->irq, (void *)hdsp);
5126 snd_hdsp_free_buffers(hdsp);
5129 iounmap(hdsp->iobase);
5132 pci_release_regions(hdsp->pci);
5134 pci_disable_device(hdsp->pci);
5138 static void snd_hdsp_card_free(struct snd_card *card)
5140 struct hdsp *hdsp = (struct hdsp *) card->private_data;
5143 snd_hdsp_free(hdsp);
5146 static int __devinit snd_hdsp_probe(struct pci_dev *pci,
5147 const struct pci_device_id *pci_id)
5151 struct snd_card *card;
5154 if (dev >= SNDRV_CARDS)
5161 if (!(card = snd_card_new(index[dev], id[dev], THIS_MODULE, sizeof(struct hdsp))))
5164 hdsp = (struct hdsp *) card->private_data;
5165 card->private_free = snd_hdsp_card_free;
5168 snd_card_set_dev(card, &pci->dev);
5170 if ((err = snd_hdsp_create(card, hdsp)) < 0) {
5171 snd_card_free(card);
5175 strcpy(card->shortname, "Hammerfall DSP");
5176 sprintf(card->longname, "%s at 0x%lx, irq %d", hdsp->card_name,
5177 hdsp->port, hdsp->irq);
5179 if ((err = snd_card_register(card)) < 0) {
5180 snd_card_free(card);
5183 pci_set_drvdata(pci, card);
5188 static void __devexit snd_hdsp_remove(struct pci_dev *pci)
5190 snd_card_free(pci_get_drvdata(pci));
5191 pci_set_drvdata(pci, NULL);
5194 static struct pci_driver driver = {
5195 .name = "RME Hammerfall DSP",
5196 .id_table = snd_hdsp_ids,
5197 .probe = snd_hdsp_probe,
5198 .remove = __devexit_p(snd_hdsp_remove),
5201 static int __init alsa_card_hdsp_init(void)
5203 return pci_register_driver(&driver);
5206 static void __exit alsa_card_hdsp_exit(void)
5208 pci_unregister_driver(&driver);
5211 module_init(alsa_card_hdsp_init)
5212 module_exit(alsa_card_hdsp_exit)