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 <sound/driver.h>
25 #include <linux/init.h>
26 #include <linux/delay.h>
27 #include <linux/interrupt.h>
28 #include <linux/slab.h>
29 #include <linux/pci.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 */
49 static int precise_ptr[SNDRV_CARDS] = { [0 ... (SNDRV_CARDS-1)] = 0 }; /* Enable precise pointer */
50 static int line_outs_monitor[SNDRV_CARDS] = { [0 ... (SNDRV_CARDS-1)] = 0}; /* Send all inputs/playback to line outs */
52 module_param_array(index, int, NULL, 0444);
53 MODULE_PARM_DESC(index, "Index value for RME Hammerfall DSP interface.");
54 module_param_array(id, charp, NULL, 0444);
55 MODULE_PARM_DESC(id, "ID string for RME Hammerfall DSP interface.");
56 module_param_array(enable, bool, NULL, 0444);
57 MODULE_PARM_DESC(enable, "Enable/disable specific Hammerfall DSP soundcards.");
58 module_param_array(precise_ptr, bool, NULL, 0444);
59 MODULE_PARM_DESC(precise_ptr, "Enable precise pointer (doesn't work reliably).");
60 module_param_array(line_outs_monitor, bool, NULL, 0444);
61 MODULE_PARM_DESC(line_outs_monitor, "Send all input and playback streams to line outs by default.");
62 MODULE_AUTHOR("Paul Davis <paul@linuxaudiosystems.com>, Marcus Andersson, Thomas Charbonnel <thomas@undata.org>");
63 MODULE_DESCRIPTION("RME Hammerfall DSP");
64 MODULE_LICENSE("GPL");
65 MODULE_SUPPORTED_DEVICE("{{RME Hammerfall-DSP},"
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_outputBufferAddress 32
89 #define HDSP_inputBufferAddress 36
90 #define HDSP_controlRegister 64
91 #define HDSP_interruptConfirmation 96
92 #define HDSP_outputEnable 128
93 #define HDSP_control2Reg 256
94 #define HDSP_midiDataOut0 352
95 #define HDSP_midiDataOut1 356
96 #define HDSP_fifoData 368
97 #define HDSP_inputEnable 384
99 /* Read registers. These are defined as byte-offsets from the iobase value
102 #define HDSP_statusRegister 0
103 #define HDSP_timecode 128
104 #define HDSP_status2Register 192
105 #define HDSP_midiDataOut0 352
106 #define HDSP_midiDataOut1 356
107 #define HDSP_midiDataIn0 360
108 #define HDSP_midiDataIn1 364
109 #define HDSP_midiStatusOut0 384
110 #define HDSP_midiStatusOut1 388
111 #define HDSP_midiStatusIn0 392
112 #define HDSP_midiStatusIn1 396
113 #define HDSP_fifoStatus 400
115 /* the meters are regular i/o-mapped registers, but offset
116 considerably from the rest. the peak registers are reset
117 when read; the least-significant 4 bits are full-scale counters;
118 the actual peak value is in the most-significant 24 bits.
121 #define HDSP_playbackPeakLevel 4096 /* 26 * 32 bit values */
122 #define HDSP_inputPeakLevel 4224 /* 26 * 32 bit values */
123 #define HDSP_outputPeakLevel 4352 /* (26+2) * 32 bit values */
124 #define HDSP_playbackRmsLevel 4612 /* 26 * 64 bit values */
125 #define HDSP_inputRmsLevel 4868 /* 26 * 64 bit values */
128 /* This is for H9652 cards
129 Peak values are read downward from the base
130 Rms values are read upward
131 There are rms values for the outputs too
132 26*3 values are read in ss mode
133 14*3 in ds mode, with no gap between values
135 #define HDSP_9652_peakBase 7164
136 #define HDSP_9652_rmsBase 4096
138 /* c.f. the hdsp_9632_meters_t struct */
139 #define HDSP_9632_metersBase 4096
141 #define HDSP_IO_EXTENT 7168
143 /* control2 register bits */
145 #define HDSP_TMS 0x01
146 #define HDSP_TCK 0x02
147 #define HDSP_TDI 0x04
148 #define HDSP_JTAG 0x08
149 #define HDSP_PWDN 0x10
150 #define HDSP_PROGRAM 0x020
151 #define HDSP_CONFIG_MODE_0 0x040
152 #define HDSP_CONFIG_MODE_1 0x080
153 #define HDSP_VERSION_BIT 0x100
154 #define HDSP_BIGENDIAN_MODE 0x200
155 #define HDSP_RD_MULTIPLE 0x400
156 #define HDSP_9652_ENABLE_MIXER 0x800
157 #define HDSP_TDO 0x10000000
159 #define HDSP_S_PROGRAM (HDSP_PROGRAM|HDSP_CONFIG_MODE_0)
160 #define HDSP_S_LOAD (HDSP_PROGRAM|HDSP_CONFIG_MODE_1)
162 /* Control Register bits */
164 #define HDSP_Start (1<<0) /* start engine */
165 #define HDSP_Latency0 (1<<1) /* buffer size = 2^n where n is defined by Latency{2,1,0} */
166 #define HDSP_Latency1 (1<<2) /* [ see above ] */
167 #define HDSP_Latency2 (1<<3) /* [ see above ] */
168 #define HDSP_ClockModeMaster (1<<4) /* 1=Master, 0=Slave/Autosync */
169 #define HDSP_AudioInterruptEnable (1<<5) /* what do you think ? */
170 #define HDSP_Frequency0 (1<<6) /* 0=44.1kHz/88.2kHz/176.4kHz 1=48kHz/96kHz/192kHz */
171 #define HDSP_Frequency1 (1<<7) /* 0=32kHz/64kHz/128kHz */
172 #define HDSP_DoubleSpeed (1<<8) /* 0=normal speed, 1=double speed */
173 #define HDSP_SPDIFProfessional (1<<9) /* 0=consumer, 1=professional */
174 #define HDSP_SPDIFEmphasis (1<<10) /* 0=none, 1=on */
175 #define HDSP_SPDIFNonAudio (1<<11) /* 0=off, 1=on */
176 #define HDSP_SPDIFOpticalOut (1<<12) /* 1=use 1st ADAT connector for SPDIF, 0=do not */
177 #define HDSP_SyncRef2 (1<<13)
178 #define HDSP_SPDIFInputSelect0 (1<<14)
179 #define HDSP_SPDIFInputSelect1 (1<<15)
180 #define HDSP_SyncRef0 (1<<16)
181 #define HDSP_SyncRef1 (1<<17)
182 #define HDSP_AnalogExtensionBoard (1<<18) /* For H9632 cards */
183 #define HDSP_XLRBreakoutCable (1<<20) /* For H9632 cards */
184 #define HDSP_Midi0InterruptEnable (1<<22)
185 #define HDSP_Midi1InterruptEnable (1<<23)
186 #define HDSP_LineOut (1<<24)
187 #define HDSP_ADGain0 (1<<25) /* From here : H9632 specific */
188 #define HDSP_ADGain1 (1<<26)
189 #define HDSP_DAGain0 (1<<27)
190 #define HDSP_DAGain1 (1<<28)
191 #define HDSP_PhoneGain0 (1<<29)
192 #define HDSP_PhoneGain1 (1<<30)
193 #define HDSP_QuadSpeed (1<<31)
195 #define HDSP_ADGainMask (HDSP_ADGain0|HDSP_ADGain1)
196 #define HDSP_ADGainMinus10dBV HDSP_ADGainMask
197 #define HDSP_ADGainPlus4dBu (HDSP_ADGain0)
198 #define HDSP_ADGainLowGain 0
200 #define HDSP_DAGainMask (HDSP_DAGain0|HDSP_DAGain1)
201 #define HDSP_DAGainHighGain HDSP_DAGainMask
202 #define HDSP_DAGainPlus4dBu (HDSP_DAGain0)
203 #define HDSP_DAGainMinus10dBV 0
205 #define HDSP_PhoneGainMask (HDSP_PhoneGain0|HDSP_PhoneGain1)
206 #define HDSP_PhoneGain0dB HDSP_PhoneGainMask
207 #define HDSP_PhoneGainMinus6dB (HDSP_PhoneGain0)
208 #define HDSP_PhoneGainMinus12dB 0
210 #define HDSP_LatencyMask (HDSP_Latency0|HDSP_Latency1|HDSP_Latency2)
211 #define HDSP_FrequencyMask (HDSP_Frequency0|HDSP_Frequency1|HDSP_DoubleSpeed|HDSP_QuadSpeed)
213 #define HDSP_SPDIFInputMask (HDSP_SPDIFInputSelect0|HDSP_SPDIFInputSelect1)
214 #define HDSP_SPDIFInputADAT1 0
215 #define HDSP_SPDIFInputCoaxial (HDSP_SPDIFInputSelect0)
216 #define HDSP_SPDIFInputCdrom (HDSP_SPDIFInputSelect1)
217 #define HDSP_SPDIFInputAES (HDSP_SPDIFInputSelect0|HDSP_SPDIFInputSelect1)
219 #define HDSP_SyncRefMask (HDSP_SyncRef0|HDSP_SyncRef1|HDSP_SyncRef2)
220 #define HDSP_SyncRef_ADAT1 0
221 #define HDSP_SyncRef_ADAT2 (HDSP_SyncRef0)
222 #define HDSP_SyncRef_ADAT3 (HDSP_SyncRef1)
223 #define HDSP_SyncRef_SPDIF (HDSP_SyncRef0|HDSP_SyncRef1)
224 #define HDSP_SyncRef_WORD (HDSP_SyncRef2)
225 #define HDSP_SyncRef_ADAT_SYNC (HDSP_SyncRef0|HDSP_SyncRef2)
227 /* Sample Clock Sources */
229 #define HDSP_CLOCK_SOURCE_AUTOSYNC 0
230 #define HDSP_CLOCK_SOURCE_INTERNAL_32KHZ 1
231 #define HDSP_CLOCK_SOURCE_INTERNAL_44_1KHZ 2
232 #define HDSP_CLOCK_SOURCE_INTERNAL_48KHZ 3
233 #define HDSP_CLOCK_SOURCE_INTERNAL_64KHZ 4
234 #define HDSP_CLOCK_SOURCE_INTERNAL_88_2KHZ 5
235 #define HDSP_CLOCK_SOURCE_INTERNAL_96KHZ 6
236 #define HDSP_CLOCK_SOURCE_INTERNAL_128KHZ 7
237 #define HDSP_CLOCK_SOURCE_INTERNAL_176_4KHZ 8
238 #define HDSP_CLOCK_SOURCE_INTERNAL_192KHZ 9
240 /* Preferred sync reference choices - used by "pref_sync_ref" control switch */
242 #define HDSP_SYNC_FROM_WORD 0
243 #define HDSP_SYNC_FROM_SPDIF 1
244 #define HDSP_SYNC_FROM_ADAT1 2
245 #define HDSP_SYNC_FROM_ADAT_SYNC 3
246 #define HDSP_SYNC_FROM_ADAT2 4
247 #define HDSP_SYNC_FROM_ADAT3 5
249 /* SyncCheck status */
251 #define HDSP_SYNC_CHECK_NO_LOCK 0
252 #define HDSP_SYNC_CHECK_LOCK 1
253 #define HDSP_SYNC_CHECK_SYNC 2
255 /* AutoSync references - used by "autosync_ref" control switch */
257 #define HDSP_AUTOSYNC_FROM_WORD 0
258 #define HDSP_AUTOSYNC_FROM_ADAT_SYNC 1
259 #define HDSP_AUTOSYNC_FROM_SPDIF 2
260 #define HDSP_AUTOSYNC_FROM_NONE 3
261 #define HDSP_AUTOSYNC_FROM_ADAT1 4
262 #define HDSP_AUTOSYNC_FROM_ADAT2 5
263 #define HDSP_AUTOSYNC_FROM_ADAT3 6
265 /* Possible sources of S/PDIF input */
267 #define HDSP_SPDIFIN_OPTICAL 0 /* optical (ADAT1) */
268 #define HDSP_SPDIFIN_COAXIAL 1 /* coaxial (RCA) */
269 #define HDSP_SPDIFIN_INTERNAL 2 /* internal (CDROM) */
270 #define HDSP_SPDIFIN_AES 3 /* xlr for H9632 (AES)*/
272 #define HDSP_Frequency32KHz HDSP_Frequency0
273 #define HDSP_Frequency44_1KHz HDSP_Frequency1
274 #define HDSP_Frequency48KHz (HDSP_Frequency1|HDSP_Frequency0)
275 #define HDSP_Frequency64KHz (HDSP_DoubleSpeed|HDSP_Frequency0)
276 #define HDSP_Frequency88_2KHz (HDSP_DoubleSpeed|HDSP_Frequency1)
277 #define HDSP_Frequency96KHz (HDSP_DoubleSpeed|HDSP_Frequency1|HDSP_Frequency0)
278 /* For H9632 cards */
279 #define HDSP_Frequency128KHz (HDSP_QuadSpeed|HDSP_DoubleSpeed|HDSP_Frequency0)
280 #define HDSP_Frequency176_4KHz (HDSP_QuadSpeed|HDSP_DoubleSpeed|HDSP_Frequency1)
281 #define HDSP_Frequency192KHz (HDSP_QuadSpeed|HDSP_DoubleSpeed|HDSP_Frequency1|HDSP_Frequency0)
283 #define hdsp_encode_latency(x) (((x)<<1) & HDSP_LatencyMask)
284 #define hdsp_decode_latency(x) (((x) & HDSP_LatencyMask)>>1)
286 #define hdsp_encode_spdif_in(x) (((x)&0x3)<<14)
287 #define hdsp_decode_spdif_in(x) (((x)>>14)&0x3)
289 /* Status Register bits */
291 #define HDSP_audioIRQPending (1<<0)
292 #define HDSP_Lock2 (1<<1) /* this is for Digiface and H9652 */
293 #define HDSP_spdifFrequency3 HDSP_Lock2 /* this is for H9632 only */
294 #define HDSP_Lock1 (1<<2)
295 #define HDSP_Lock0 (1<<3)
296 #define HDSP_SPDIFSync (1<<4)
297 #define HDSP_TimecodeLock (1<<5)
298 #define HDSP_BufferPositionMask 0x000FFC0 /* Bit 6..15 : h/w buffer pointer */
299 #define HDSP_Sync2 (1<<16)
300 #define HDSP_Sync1 (1<<17)
301 #define HDSP_Sync0 (1<<18)
302 #define HDSP_DoubleSpeedStatus (1<<19)
303 #define HDSP_ConfigError (1<<20)
304 #define HDSP_DllError (1<<21)
305 #define HDSP_spdifFrequency0 (1<<22)
306 #define HDSP_spdifFrequency1 (1<<23)
307 #define HDSP_spdifFrequency2 (1<<24)
308 #define HDSP_SPDIFErrorFlag (1<<25)
309 #define HDSP_BufferID (1<<26)
310 #define HDSP_TimecodeSync (1<<27)
311 #define HDSP_AEBO (1<<28) /* H9632 specific Analog Extension Boards */
312 #define HDSP_AEBI (1<<29) /* 0 = present, 1 = absent */
313 #define HDSP_midi0IRQPending (1<<30)
314 #define HDSP_midi1IRQPending (1<<31)
316 #define HDSP_spdifFrequencyMask (HDSP_spdifFrequency0|HDSP_spdifFrequency1|HDSP_spdifFrequency2)
318 #define HDSP_spdifFrequency32KHz (HDSP_spdifFrequency0)
319 #define HDSP_spdifFrequency44_1KHz (HDSP_spdifFrequency1)
320 #define HDSP_spdifFrequency48KHz (HDSP_spdifFrequency0|HDSP_spdifFrequency1)
322 #define HDSP_spdifFrequency64KHz (HDSP_spdifFrequency2)
323 #define HDSP_spdifFrequency88_2KHz (HDSP_spdifFrequency0|HDSP_spdifFrequency2)
324 #define HDSP_spdifFrequency96KHz (HDSP_spdifFrequency2|HDSP_spdifFrequency1)
326 /* This is for H9632 cards */
327 #define HDSP_spdifFrequency128KHz HDSP_spdifFrequencyMask
328 #define HDSP_spdifFrequency176_4KHz HDSP_spdifFrequency3
329 #define HDSP_spdifFrequency192KHz (HDSP_spdifFrequency3|HDSP_spdifFrequency0)
331 /* Status2 Register bits */
333 #define HDSP_version0 (1<<0)
334 #define HDSP_version1 (1<<1)
335 #define HDSP_version2 (1<<2)
336 #define HDSP_wc_lock (1<<3)
337 #define HDSP_wc_sync (1<<4)
338 #define HDSP_inp_freq0 (1<<5)
339 #define HDSP_inp_freq1 (1<<6)
340 #define HDSP_inp_freq2 (1<<7)
341 #define HDSP_SelSyncRef0 (1<<8)
342 #define HDSP_SelSyncRef1 (1<<9)
343 #define HDSP_SelSyncRef2 (1<<10)
345 #define HDSP_wc_valid (HDSP_wc_lock|HDSP_wc_sync)
347 #define HDSP_systemFrequencyMask (HDSP_inp_freq0|HDSP_inp_freq1|HDSP_inp_freq2)
348 #define HDSP_systemFrequency32 (HDSP_inp_freq0)
349 #define HDSP_systemFrequency44_1 (HDSP_inp_freq1)
350 #define HDSP_systemFrequency48 (HDSP_inp_freq0|HDSP_inp_freq1)
351 #define HDSP_systemFrequency64 (HDSP_inp_freq2)
352 #define HDSP_systemFrequency88_2 (HDSP_inp_freq0|HDSP_inp_freq2)
353 #define HDSP_systemFrequency96 (HDSP_inp_freq1|HDSP_inp_freq2)
354 /* FIXME : more values for 9632 cards ? */
356 #define HDSP_SelSyncRefMask (HDSP_SelSyncRef0|HDSP_SelSyncRef1|HDSP_SelSyncRef2)
357 #define HDSP_SelSyncRef_ADAT1 0
358 #define HDSP_SelSyncRef_ADAT2 (HDSP_SelSyncRef0)
359 #define HDSP_SelSyncRef_ADAT3 (HDSP_SelSyncRef1)
360 #define HDSP_SelSyncRef_SPDIF (HDSP_SelSyncRef0|HDSP_SelSyncRef1)
361 #define HDSP_SelSyncRef_WORD (HDSP_SelSyncRef2)
362 #define HDSP_SelSyncRef_ADAT_SYNC (HDSP_SelSyncRef0|HDSP_SelSyncRef2)
364 /* Card state flags */
366 #define HDSP_InitializationComplete (1<<0)
367 #define HDSP_FirmwareLoaded (1<<1)
368 #define HDSP_FirmwareCached (1<<2)
370 /* FIFO wait times, defined in terms of 1/10ths of msecs */
372 #define HDSP_LONG_WAIT 5000
373 #define HDSP_SHORT_WAIT 30
375 #define UNITY_GAIN 32768
376 #define MINUS_INFINITY_GAIN 0
378 #ifndef PCI_VENDOR_ID_XILINX
379 #define PCI_VENDOR_ID_XILINX 0x10ee
381 #ifndef PCI_DEVICE_ID_XILINX_HAMMERFALL_DSP
382 #define PCI_DEVICE_ID_XILINX_HAMMERFALL_DSP 0x3fc5
385 /* the size of a substream (1 mono data stream) */
387 #define HDSP_CHANNEL_BUFFER_SAMPLES (16*1024)
388 #define HDSP_CHANNEL_BUFFER_BYTES (4*HDSP_CHANNEL_BUFFER_SAMPLES)
390 /* the size of the area we need to allocate for DMA transfers. the
391 size is the same regardless of the number of channels - the
392 Multiface still uses the same memory area.
394 Note that we allocate 1 more channel than is apparently needed
395 because the h/w seems to write 1 byte beyond the end of the last
399 #define HDSP_DMA_AREA_BYTES ((HDSP_MAX_CHANNELS+1) * HDSP_CHANNEL_BUFFER_BYTES)
400 #define HDSP_DMA_AREA_KILOBYTES (HDSP_DMA_AREA_BYTES/1024)
402 typedef struct _hdsp hdsp_t;
403 typedef struct _hdsp_midi hdsp_midi_t;
404 typedef struct _hdsp_9632_meters hdsp_9632_meters_t;
406 struct _hdsp_9632_meters {
408 u32 playback_peak[16];
412 u32 input_rms_low[16];
413 u32 playback_rms_low[16];
414 u32 output_rms_low[16];
416 u32 input_rms_high[16];
417 u32 playback_rms_high[16];
418 u32 output_rms_high[16];
419 u32 xxx_rms_high[16];
425 snd_rawmidi_t *rmidi;
426 snd_rawmidi_substream_t *input;
427 snd_rawmidi_substream_t *output;
428 char istimer; /* timer in use */
429 struct timer_list timer;
436 snd_pcm_substream_t *capture_substream;
437 snd_pcm_substream_t *playback_substream;
439 struct tasklet_struct midi_tasklet;
441 u32 control_register; /* cached value */
442 u32 control2_register; /* cached value */
444 u32 creg_spdif_stream;
445 char *card_name; /* digiface/multiface */
446 HDSP_IO_Type io_type; /* ditto, but for code use */
447 unsigned short firmware_rev;
448 unsigned short state; /* stores state bits */
449 u32 firmware_cache[24413]; /* this helps recover from accidental iobox power failure */
450 size_t period_bytes; /* guess what this is */
451 unsigned char max_channels;
452 unsigned char qs_in_channels; /* quad speed mode for H9632 */
453 unsigned char ds_in_channels;
454 unsigned char ss_in_channels; /* different for multiface/digiface */
455 unsigned char qs_out_channels;
456 unsigned char ds_out_channels;
457 unsigned char ss_out_channels;
459 struct snd_dma_buffer capture_dma_buf;
460 struct snd_dma_buffer playback_dma_buf;
461 unsigned char *capture_buffer; /* suitably aligned address */
462 unsigned char *playback_buffer; /* suitably aligned address */
467 int passthru; /* non-zero if doing pass-thru */
468 int system_sample_rate;
473 void __iomem *iobase;
478 snd_kcontrol_t *spdif_ctl;
479 unsigned short mixer_matrix[HDSP_MATRIX_MIXER_SIZE];
482 /* These tables map the ALSA channels 1..N to the channels that we
483 need to use in order to find the relevant channel buffer. RME
484 refer to this kind of mapping as between "the ADAT channel and
485 the DMA channel." We index it using the logical audio channel,
486 and the value is the DMA channel (i.e. channel buffer number)
487 where the data for that channel can be read/written from/to.
490 static char channel_map_df_ss[HDSP_MAX_CHANNELS] = {
491 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
492 18, 19, 20, 21, 22, 23, 24, 25
495 static char channel_map_mf_ss[HDSP_MAX_CHANNELS] = { /* Multiface */
497 0, 1, 2, 3, 4, 5, 6, 7,
499 16, 17, 18, 19, 20, 21, 22, 23,
502 -1, -1, -1, -1, -1, -1, -1, -1
505 static char channel_map_ds[HDSP_MAX_CHANNELS] = {
506 /* ADAT channels are remapped */
507 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23,
508 /* channels 12 and 13 are S/PDIF */
510 /* others don't exist */
511 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
514 static char channel_map_H9632_ss[HDSP_MAX_CHANNELS] = {
516 0, 1, 2, 3, 4, 5, 6, 7,
521 /* AO4S-192 and AI4S-192 extension boards */
523 /* others don't exist */
524 -1, -1, -1, -1, -1, -1, -1, -1,
528 static char channel_map_H9632_ds[HDSP_MAX_CHANNELS] = {
535 /* AO4S-192 and AI4S-192 extension boards */
537 /* others don't exist */
538 -1, -1, -1, -1, -1, -1, -1, -1,
539 -1, -1, -1, -1, -1, -1
542 static char channel_map_H9632_qs[HDSP_MAX_CHANNELS] = {
543 /* ADAT is disabled in this mode */
548 /* AO4S-192 and AI4S-192 extension boards */
550 /* others don't exist */
551 -1, -1, -1, -1, -1, -1, -1, -1,
552 -1, -1, -1, -1, -1, -1, -1, -1,
556 static int snd_hammerfall_get_buffer(struct pci_dev *pci, struct snd_dma_buffer *dmab, size_t size)
558 dmab->dev.type = SNDRV_DMA_TYPE_DEV;
559 dmab->dev.dev = snd_dma_pci_data(pci);
560 if (! snd_dma_get_reserved_buf(dmab, snd_dma_pci_buf_id(pci))) {
561 if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(pci),
568 static void snd_hammerfall_free_buffer(struct snd_dma_buffer *dmab, struct pci_dev *pci)
571 snd_dma_reserve_buf(dmab, snd_dma_pci_buf_id(pci));
575 static struct pci_device_id snd_hdsp_ids[] = {
577 .vendor = PCI_VENDOR_ID_XILINX,
578 .device = PCI_DEVICE_ID_XILINX_HAMMERFALL_DSP,
579 .subvendor = PCI_ANY_ID,
580 .subdevice = PCI_ANY_ID,
581 }, /* RME Hammerfall-DSP */
585 MODULE_DEVICE_TABLE(pci, snd_hdsp_ids);
588 static int __devinit snd_hdsp_create_alsa_devices(snd_card_t *card, hdsp_t *hdsp);
589 static int __devinit snd_hdsp_create_pcm(snd_card_t *card, hdsp_t *hdsp);
590 static int snd_hdsp_enable_io (hdsp_t *hdsp);
591 static void snd_hdsp_initialize_midi_flush (hdsp_t *hdsp);
592 static void snd_hdsp_initialize_channels (hdsp_t *hdsp);
593 static int hdsp_fifo_wait(hdsp_t *hdsp, int count, int timeout);
594 static int hdsp_autosync_ref(hdsp_t *hdsp);
595 static int snd_hdsp_set_defaults(hdsp_t *hdsp);
596 static void snd_hdsp_9652_enable_mixer (hdsp_t *hdsp);
598 static int hdsp_playback_to_output_key (hdsp_t *hdsp, int in, int out)
600 switch (hdsp->firmware_rev) {
602 return (64 * out) + (32 + (in));
605 return (32 * out) + (16 + (in));
607 return (52 * out) + (26 + (in));
611 static int hdsp_input_to_output_key (hdsp_t *hdsp, int in, int out)
613 switch (hdsp->firmware_rev) {
615 return (64 * out) + in;
618 return (32 * out) + in;
620 return (52 * out) + in;
624 static void hdsp_write(hdsp_t *hdsp, int reg, int val)
626 writel(val, hdsp->iobase + reg);
629 static unsigned int hdsp_read(hdsp_t *hdsp, int reg)
631 return readl (hdsp->iobase + reg);
634 static int hdsp_check_for_iobox (hdsp_t *hdsp)
637 if (hdsp->io_type == H9652 || hdsp->io_type == H9632) return 0;
638 if (hdsp_read (hdsp, HDSP_statusRegister) & HDSP_ConfigError) {
639 snd_printk ("Hammerfall-DSP: no Digiface or Multiface connected!\n");
640 hdsp->state &= ~HDSP_FirmwareLoaded;
647 static int snd_hdsp_load_firmware_from_cache(hdsp_t *hdsp) {
652 if ((hdsp_read (hdsp, HDSP_statusRegister) & HDSP_DllError) != 0) {
654 snd_printk ("loading firmware\n");
656 hdsp_write (hdsp, HDSP_control2Reg, HDSP_S_PROGRAM);
657 hdsp_write (hdsp, HDSP_fifoData, 0);
659 if (hdsp_fifo_wait (hdsp, 0, HDSP_LONG_WAIT)) {
660 snd_printk ("timeout waiting for download preparation\n");
664 hdsp_write (hdsp, HDSP_control2Reg, HDSP_S_LOAD);
666 for (i = 0; i < 24413; ++i) {
667 hdsp_write(hdsp, HDSP_fifoData, hdsp->firmware_cache[i]);
668 if (hdsp_fifo_wait (hdsp, 127, HDSP_LONG_WAIT)) {
669 snd_printk ("timeout during firmware loading\n");
674 if ((1000 / HZ) < 3000) {
675 set_current_state(TASK_UNINTERRUPTIBLE);
676 schedule_timeout((3000 * HZ + 999) / 1000);
681 if (hdsp_fifo_wait (hdsp, 0, HDSP_LONG_WAIT)) {
682 snd_printk ("timeout at end of firmware loading\n");
686 #ifdef SNDRV_BIG_ENDIAN
687 hdsp->control2_register = HDSP_BIGENDIAN_MODE;
689 hdsp->control2_register = 0;
691 hdsp_write (hdsp, HDSP_control2Reg, hdsp->control2_register);
692 snd_printk ("finished firmware loading\n");
695 if (hdsp->state & HDSP_InitializationComplete) {
696 snd_printk("firmware loaded from cache, restoring defaults\n");
697 spin_lock_irqsave(&hdsp->lock, flags);
698 snd_hdsp_set_defaults(hdsp);
699 spin_unlock_irqrestore(&hdsp->lock, flags);
702 hdsp->state |= HDSP_FirmwareLoaded;
707 static int hdsp_get_iobox_version (hdsp_t *hdsp)
711 if (hdsp_check_for_iobox (hdsp)) {
715 if ((err = snd_hdsp_enable_io(hdsp)) < 0) {
719 if ((hdsp_read (hdsp, HDSP_statusRegister) & HDSP_DllError) != 0) {
721 hdsp_write (hdsp, HDSP_control2Reg, HDSP_PROGRAM);
722 hdsp_write (hdsp, HDSP_fifoData, 0);
723 if (hdsp_fifo_wait (hdsp, 0, HDSP_SHORT_WAIT) < 0) {
727 hdsp_write (hdsp, HDSP_control2Reg, HDSP_S_LOAD);
728 hdsp_write (hdsp, HDSP_fifoData, 0);
730 if (hdsp_fifo_wait (hdsp, 0, HDSP_SHORT_WAIT)) {
731 hdsp->io_type = Multiface;
732 hdsp_write (hdsp, HDSP_control2Reg, HDSP_VERSION_BIT);
733 hdsp_write (hdsp, HDSP_control2Reg, HDSP_S_LOAD);
734 hdsp_fifo_wait (hdsp, 0, HDSP_SHORT_WAIT);
736 hdsp->io_type = Digiface;
739 /* firmware was already loaded, get iobox type */
740 if (hdsp_read(hdsp, HDSP_status2Register) & HDSP_version1) {
741 hdsp->io_type = Multiface;
743 hdsp->io_type = Digiface;
750 static int hdsp_check_for_firmware (hdsp_t *hdsp)
752 if (hdsp->io_type == H9652 || hdsp->io_type == H9632) return 0;
753 if ((hdsp_read (hdsp, HDSP_statusRegister) & HDSP_DllError) != 0) {
754 snd_printk("firmware not present.\n");
755 hdsp->state &= ~HDSP_FirmwareLoaded;
762 static int hdsp_fifo_wait(hdsp_t *hdsp, int count, int timeout)
766 /* the fifoStatus registers reports on how many words
767 are available in the command FIFO.
770 for (i = 0; i < timeout; i++) {
772 if ((int)(hdsp_read (hdsp, HDSP_fifoStatus) & 0xff) <= count)
775 /* not very friendly, but we only do this during a firmware
776 load and changing the mixer, so we just put up with it.
782 snd_printk ("wait for FIFO status <= %d failed after %d iterations\n",
787 static int hdsp_read_gain (hdsp_t *hdsp, unsigned int addr)
789 if (addr >= HDSP_MATRIX_MIXER_SIZE) {
792 return hdsp->mixer_matrix[addr];
795 static int hdsp_write_gain(hdsp_t *hdsp, unsigned int addr, unsigned short data)
799 if (addr >= HDSP_MATRIX_MIXER_SIZE)
802 if (hdsp->io_type == H9652 || hdsp->io_type == H9632) {
804 /* from martin björnsen:
806 "You can only write dwords to the
807 mixer memory which contain two
808 mixer values in the low and high
809 word. So if you want to change
810 value 0 you have to read value 1
811 from the cache and write both to
812 the first dword in the mixer
816 if (hdsp->io_type == H9632 && addr >= 512) {
820 if (hdsp->io_type == H9652 && addr >= 1352) {
824 hdsp->mixer_matrix[addr] = data;
827 /* `addr' addresses a 16-bit wide address, but
828 the address space accessed via hdsp_write
829 uses byte offsets. put another way, addr
830 varies from 0 to 1351, but to access the
831 corresponding memory location, we need
832 to access 0 to 2703 ...
836 hdsp_write (hdsp, 4096 + (ad*4),
837 (hdsp->mixer_matrix[(addr&0x7fe)+1] << 16) +
838 hdsp->mixer_matrix[addr&0x7fe]);
844 ad = (addr << 16) + data;
846 if (hdsp_fifo_wait(hdsp, 127, HDSP_LONG_WAIT)) {
850 hdsp_write (hdsp, HDSP_fifoData, ad);
851 hdsp->mixer_matrix[addr] = data;
858 static int snd_hdsp_use_is_exclusive(hdsp_t *hdsp)
863 spin_lock_irqsave(&hdsp->lock, flags);
864 if ((hdsp->playback_pid != hdsp->capture_pid) &&
865 (hdsp->playback_pid >= 0) && (hdsp->capture_pid >= 0)) {
868 spin_unlock_irqrestore(&hdsp->lock, flags);
872 static int hdsp_external_sample_rate (hdsp_t *hdsp)
874 unsigned int status2 = hdsp_read(hdsp, HDSP_status2Register);
875 unsigned int rate_bits = status2 & HDSP_systemFrequencyMask;
878 case HDSP_systemFrequency32: return 32000;
879 case HDSP_systemFrequency44_1: return 44100;
880 case HDSP_systemFrequency48: return 48000;
881 case HDSP_systemFrequency64: return 64000;
882 case HDSP_systemFrequency88_2: return 88200;
883 case HDSP_systemFrequency96: return 96000;
889 static int hdsp_spdif_sample_rate(hdsp_t *hdsp)
891 unsigned int status = hdsp_read(hdsp, HDSP_statusRegister);
892 unsigned int rate_bits = (status & HDSP_spdifFrequencyMask);
894 if (status & HDSP_SPDIFErrorFlag) {
899 case HDSP_spdifFrequency32KHz: return 32000;
900 case HDSP_spdifFrequency44_1KHz: return 44100;
901 case HDSP_spdifFrequency48KHz: return 48000;
902 case HDSP_spdifFrequency64KHz: return 64000;
903 case HDSP_spdifFrequency88_2KHz: return 88200;
904 case HDSP_spdifFrequency96KHz: return 96000;
905 case HDSP_spdifFrequency128KHz:
906 if (hdsp->io_type == H9632) return 128000;
908 case HDSP_spdifFrequency176_4KHz:
909 if (hdsp->io_type == H9632) return 176400;
911 case HDSP_spdifFrequency192KHz:
912 if (hdsp->io_type == H9632) return 192000;
917 snd_printk ("unknown spdif frequency status; bits = 0x%x, status = 0x%x\n", rate_bits, status);
921 static void hdsp_compute_period_size(hdsp_t *hdsp)
923 hdsp->period_bytes = 1 << ((hdsp_decode_latency(hdsp->control_register) + 8));
926 static snd_pcm_uframes_t hdsp_hw_pointer(hdsp_t *hdsp)
930 position = hdsp_read(hdsp, HDSP_statusRegister);
932 if (!hdsp->precise_ptr) {
933 return (position & HDSP_BufferID) ? (hdsp->period_bytes / 4) : 0;
936 position &= HDSP_BufferPositionMask;
938 position &= (hdsp->period_bytes/2) - 1;
942 static void hdsp_reset_hw_pointer(hdsp_t *hdsp)
944 hdsp_write (hdsp, HDSP_resetPointer, 0);
947 static void hdsp_start_audio(hdsp_t *s)
949 s->control_register |= (HDSP_AudioInterruptEnable | HDSP_Start);
950 hdsp_write(s, HDSP_controlRegister, s->control_register);
953 static void hdsp_stop_audio(hdsp_t *s)
955 s->control_register &= ~(HDSP_Start | HDSP_AudioInterruptEnable);
956 hdsp_write(s, HDSP_controlRegister, s->control_register);
959 static void hdsp_silence_playback(hdsp_t *hdsp)
961 memset(hdsp->playback_buffer, 0, HDSP_DMA_AREA_BYTES);
964 static int hdsp_set_interrupt_interval(hdsp_t *s, unsigned int frames)
968 spin_lock_irq(&s->lock);
977 s->control_register &= ~HDSP_LatencyMask;
978 s->control_register |= hdsp_encode_latency(n);
980 hdsp_write(s, HDSP_controlRegister, s->control_register);
982 hdsp_compute_period_size(s);
984 spin_unlock_irq(&s->lock);
989 static int hdsp_set_rate(hdsp_t *hdsp, int rate, int called_internally)
991 int reject_if_open = 0;
995 /* ASSUMPTION: hdsp->lock is either held, or
996 there is no need for it (e.g. during module
1000 if (!(hdsp->control_register & HDSP_ClockModeMaster)) {
1001 if (called_internally) {
1002 /* request from ctl or card initialization */
1003 snd_printk("device is not running as a clock master: cannot set sample rate.\n");
1006 /* hw_param request while in AutoSync mode */
1007 int external_freq = hdsp_external_sample_rate(hdsp);
1008 int spdif_freq = hdsp_spdif_sample_rate(hdsp);
1010 if ((spdif_freq == external_freq*2) && (hdsp_autosync_ref(hdsp) >= HDSP_AUTOSYNC_FROM_ADAT1)) {
1011 snd_printk("Detected ADAT in double speed mode\n");
1012 } else if (hdsp->io_type == H9632 && (spdif_freq == external_freq*4) && (hdsp_autosync_ref(hdsp) >= HDSP_AUTOSYNC_FROM_ADAT1)) {
1013 snd_printk("Detected ADAT in quad speed mode\n");
1014 } else if (rate != external_freq) {
1015 snd_printk("No AutoSync source for requested rate\n");
1021 current_rate = hdsp->system_sample_rate;
1023 /* Changing from a "single speed" to a "double speed" rate is
1024 not allowed if any substreams are open. This is because
1025 such a change causes a shift in the location of
1026 the DMA buffers and a reduction in the number of available
1029 Note that a similar but essentially insoluble problem
1030 exists for externally-driven rate changes. All we can do
1031 is to flag rate changes in the read/write routines. */
1033 if (rate > 96000 && hdsp->io_type != H9632) {
1039 if (current_rate > 48000) {
1042 rate_bits = HDSP_Frequency32KHz;
1045 if (current_rate > 48000) {
1048 rate_bits = HDSP_Frequency44_1KHz;
1051 if (current_rate > 48000) {
1054 rate_bits = HDSP_Frequency48KHz;
1057 if (current_rate <= 48000 || current_rate > 96000) {
1060 rate_bits = HDSP_Frequency64KHz;
1063 if (current_rate <= 48000 || current_rate > 96000) {
1066 rate_bits = HDSP_Frequency88_2KHz;
1069 if (current_rate <= 48000 || current_rate > 96000) {
1072 rate_bits = HDSP_Frequency96KHz;
1075 if (current_rate < 128000) {
1078 rate_bits = HDSP_Frequency128KHz;
1081 if (current_rate < 128000) {
1084 rate_bits = HDSP_Frequency176_4KHz;
1087 if (current_rate < 128000) {
1090 rate_bits = HDSP_Frequency192KHz;
1096 if (reject_if_open && (hdsp->capture_pid >= 0 || hdsp->playback_pid >= 0)) {
1097 snd_printk ("cannot change speed mode (capture PID = %d, playback PID = %d)\n",
1099 hdsp->playback_pid);
1103 hdsp->control_register &= ~HDSP_FrequencyMask;
1104 hdsp->control_register |= rate_bits;
1105 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
1107 if (rate >= 128000) {
1108 hdsp->channel_map = channel_map_H9632_qs;
1109 } else if (rate > 48000) {
1110 if (hdsp->io_type == H9632) {
1111 hdsp->channel_map = channel_map_H9632_ds;
1113 hdsp->channel_map = channel_map_ds;
1116 switch (hdsp->io_type) {
1118 hdsp->channel_map = channel_map_mf_ss;
1122 hdsp->channel_map = channel_map_df_ss;
1125 hdsp->channel_map = channel_map_H9632_ss;
1128 /* should never happen */
1133 hdsp->system_sample_rate = rate;
1138 static void hdsp_set_thru(hdsp_t *hdsp, int channel, int enable)
1147 /* set thru for all channels */
1150 for (i = 0; i < hdsp->max_channels; i++) {
1151 hdsp_write_gain (hdsp, hdsp_input_to_output_key(hdsp,i,i), UNITY_GAIN);
1154 for (i = 0; i < hdsp->max_channels; i++) {
1155 hdsp_write_gain (hdsp, hdsp_input_to_output_key(hdsp,i,i), MINUS_INFINITY_GAIN);
1162 snd_assert(channel < hdsp->max_channels, return);
1164 mapped_channel = hdsp->channel_map[channel];
1166 snd_assert(mapped_channel > -1, return);
1169 hdsp_write_gain (hdsp, hdsp_input_to_output_key(hdsp,mapped_channel,mapped_channel), UNITY_GAIN);
1171 hdsp_write_gain (hdsp, hdsp_input_to_output_key(hdsp,mapped_channel,mapped_channel), MINUS_INFINITY_GAIN);
1176 static int hdsp_set_passthru(hdsp_t *hdsp, int onoff)
1179 hdsp_set_thru(hdsp, -1, 1);
1180 hdsp_reset_hw_pointer(hdsp);
1181 hdsp_silence_playback(hdsp);
1183 /* we don't want interrupts, so do a
1184 custom version of hdsp_start_audio().
1187 hdsp->control_register |= (HDSP_Start|HDSP_AudioInterruptEnable|hdsp_encode_latency(7));
1189 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
1192 hdsp_set_thru(hdsp, -1, 0);
1193 hdsp_stop_audio(hdsp);
1200 /*----------------------------------------------------------------------------
1202 ----------------------------------------------------------------------------*/
1204 static unsigned char snd_hdsp_midi_read_byte (hdsp_t *hdsp, int id)
1206 /* the hardware already does the relevant bit-mask with 0xff */
1208 return hdsp_read(hdsp, HDSP_midiDataIn1);
1210 return hdsp_read(hdsp, HDSP_midiDataIn0);
1214 static void snd_hdsp_midi_write_byte (hdsp_t *hdsp, int id, int val)
1216 /* the hardware already does the relevant bit-mask with 0xff */
1218 hdsp_write(hdsp, HDSP_midiDataOut1, val);
1220 hdsp_write(hdsp, HDSP_midiDataOut0, val);
1224 static int snd_hdsp_midi_input_available (hdsp_t *hdsp, int id)
1227 return (hdsp_read(hdsp, HDSP_midiStatusIn1) & 0xff);
1229 return (hdsp_read(hdsp, HDSP_midiStatusIn0) & 0xff);
1233 static int snd_hdsp_midi_output_possible (hdsp_t *hdsp, int id)
1235 int fifo_bytes_used;
1238 fifo_bytes_used = hdsp_read(hdsp, HDSP_midiStatusOut1) & 0xff;
1240 fifo_bytes_used = hdsp_read(hdsp, HDSP_midiStatusOut0) & 0xff;
1243 if (fifo_bytes_used < 128) {
1244 return 128 - fifo_bytes_used;
1250 static void snd_hdsp_flush_midi_input (hdsp_t *hdsp, int id)
1252 while (snd_hdsp_midi_input_available (hdsp, id)) {
1253 snd_hdsp_midi_read_byte (hdsp, id);
1257 static int snd_hdsp_midi_output_write (hdsp_midi_t *hmidi)
1259 unsigned long flags;
1263 unsigned char buf[128];
1265 /* Output is not interrupt driven */
1267 spin_lock_irqsave (&hmidi->lock, flags);
1268 if (hmidi->output) {
1269 if (!snd_rawmidi_transmit_empty (hmidi->output)) {
1270 if ((n_pending = snd_hdsp_midi_output_possible (hmidi->hdsp, hmidi->id)) > 0) {
1271 if (n_pending > (int)sizeof (buf))
1272 n_pending = sizeof (buf);
1274 if ((to_write = snd_rawmidi_transmit (hmidi->output, buf, n_pending)) > 0) {
1275 for (i = 0; i < to_write; ++i)
1276 snd_hdsp_midi_write_byte (hmidi->hdsp, hmidi->id, buf[i]);
1281 spin_unlock_irqrestore (&hmidi->lock, flags);
1285 static int snd_hdsp_midi_input_read (hdsp_midi_t *hmidi)
1287 unsigned char buf[128]; /* this buffer is designed to match the MIDI input FIFO size */
1288 unsigned long flags;
1292 spin_lock_irqsave (&hmidi->lock, flags);
1293 if ((n_pending = snd_hdsp_midi_input_available (hmidi->hdsp, hmidi->id)) > 0) {
1295 if (n_pending > (int)sizeof (buf)) {
1296 n_pending = sizeof (buf);
1298 for (i = 0; i < n_pending; ++i) {
1299 buf[i] = snd_hdsp_midi_read_byte (hmidi->hdsp, hmidi->id);
1302 snd_rawmidi_receive (hmidi->input, buf, n_pending);
1305 /* flush the MIDI input FIFO */
1306 while (--n_pending) {
1307 snd_hdsp_midi_read_byte (hmidi->hdsp, hmidi->id);
1313 hmidi->hdsp->control_register |= HDSP_Midi1InterruptEnable;
1315 hmidi->hdsp->control_register |= HDSP_Midi0InterruptEnable;
1317 hdsp_write(hmidi->hdsp, HDSP_controlRegister, hmidi->hdsp->control_register);
1318 spin_unlock_irqrestore (&hmidi->lock, flags);
1319 return snd_hdsp_midi_output_write (hmidi);
1322 static void snd_hdsp_midi_input_trigger(snd_rawmidi_substream_t * substream, int up)
1326 unsigned long flags;
1329 hmidi = (hdsp_midi_t *) substream->rmidi->private_data;
1331 ie = hmidi->id ? HDSP_Midi1InterruptEnable : HDSP_Midi0InterruptEnable;
1332 spin_lock_irqsave (&hdsp->lock, flags);
1334 if (!(hdsp->control_register & ie)) {
1335 snd_hdsp_flush_midi_input (hdsp, hmidi->id);
1336 hdsp->control_register |= ie;
1339 hdsp->control_register &= ~ie;
1342 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
1343 spin_unlock_irqrestore (&hdsp->lock, flags);
1346 static void snd_hdsp_midi_output_timer(unsigned long data)
1348 hdsp_midi_t *hmidi = (hdsp_midi_t *) data;
1349 unsigned long flags;
1351 snd_hdsp_midi_output_write(hmidi);
1352 spin_lock_irqsave (&hmidi->lock, flags);
1354 /* this does not bump hmidi->istimer, because the
1355 kernel automatically removed the timer when it
1356 expired, and we are now adding it back, thus
1357 leaving istimer wherever it was set before.
1360 if (hmidi->istimer) {
1361 hmidi->timer.expires = 1 + jiffies;
1362 add_timer(&hmidi->timer);
1365 spin_unlock_irqrestore (&hmidi->lock, flags);
1368 static void snd_hdsp_midi_output_trigger(snd_rawmidi_substream_t * substream, int up)
1371 unsigned long flags;
1373 hmidi = (hdsp_midi_t *) substream->rmidi->private_data;
1374 spin_lock_irqsave (&hmidi->lock, flags);
1376 if (!hmidi->istimer) {
1377 init_timer(&hmidi->timer);
1378 hmidi->timer.function = snd_hdsp_midi_output_timer;
1379 hmidi->timer.data = (unsigned long) hmidi;
1380 hmidi->timer.expires = 1 + jiffies;
1381 add_timer(&hmidi->timer);
1385 if (hmidi->istimer && --hmidi->istimer <= 0) {
1386 del_timer (&hmidi->timer);
1389 spin_unlock_irqrestore (&hmidi->lock, flags);
1391 snd_hdsp_midi_output_write(hmidi);
1394 static int snd_hdsp_midi_input_open(snd_rawmidi_substream_t * substream)
1398 hmidi = (hdsp_midi_t *) substream->rmidi->private_data;
1399 spin_lock_irq (&hmidi->lock);
1400 snd_hdsp_flush_midi_input (hmidi->hdsp, hmidi->id);
1401 hmidi->input = substream;
1402 spin_unlock_irq (&hmidi->lock);
1407 static int snd_hdsp_midi_output_open(snd_rawmidi_substream_t * substream)
1411 hmidi = (hdsp_midi_t *) substream->rmidi->private_data;
1412 spin_lock_irq (&hmidi->lock);
1413 hmidi->output = substream;
1414 spin_unlock_irq (&hmidi->lock);
1419 static int snd_hdsp_midi_input_close(snd_rawmidi_substream_t * substream)
1423 snd_hdsp_midi_input_trigger (substream, 0);
1425 hmidi = (hdsp_midi_t *) substream->rmidi->private_data;
1426 spin_lock_irq (&hmidi->lock);
1427 hmidi->input = NULL;
1428 spin_unlock_irq (&hmidi->lock);
1433 static int snd_hdsp_midi_output_close(snd_rawmidi_substream_t * substream)
1437 snd_hdsp_midi_output_trigger (substream, 0);
1439 hmidi = (hdsp_midi_t *) substream->rmidi->private_data;
1440 spin_lock_irq (&hmidi->lock);
1441 hmidi->output = NULL;
1442 spin_unlock_irq (&hmidi->lock);
1447 snd_rawmidi_ops_t snd_hdsp_midi_output =
1449 .open = snd_hdsp_midi_output_open,
1450 .close = snd_hdsp_midi_output_close,
1451 .trigger = snd_hdsp_midi_output_trigger,
1454 snd_rawmidi_ops_t snd_hdsp_midi_input =
1456 .open = snd_hdsp_midi_input_open,
1457 .close = snd_hdsp_midi_input_close,
1458 .trigger = snd_hdsp_midi_input_trigger,
1461 static int __devinit snd_hdsp_create_midi (snd_card_t *card, hdsp_t *hdsp, int id)
1465 hdsp->midi[id].id = id;
1466 hdsp->midi[id].rmidi = NULL;
1467 hdsp->midi[id].input = NULL;
1468 hdsp->midi[id].output = NULL;
1469 hdsp->midi[id].hdsp = hdsp;
1470 hdsp->midi[id].istimer = 0;
1471 hdsp->midi[id].pending = 0;
1472 spin_lock_init (&hdsp->midi[id].lock);
1474 sprintf (buf, "%s MIDI %d", card->shortname, id+1);
1475 if (snd_rawmidi_new (card, buf, id, 1, 1, &hdsp->midi[id].rmidi) < 0) {
1479 sprintf (hdsp->midi[id].rmidi->name, "%s MIDI %d", card->id, id+1);
1480 hdsp->midi[id].rmidi->private_data = &hdsp->midi[id];
1482 snd_rawmidi_set_ops (hdsp->midi[id].rmidi, SNDRV_RAWMIDI_STREAM_OUTPUT, &snd_hdsp_midi_output);
1483 snd_rawmidi_set_ops (hdsp->midi[id].rmidi, SNDRV_RAWMIDI_STREAM_INPUT, &snd_hdsp_midi_input);
1485 hdsp->midi[id].rmidi->info_flags |= SNDRV_RAWMIDI_INFO_OUTPUT |
1486 SNDRV_RAWMIDI_INFO_INPUT |
1487 SNDRV_RAWMIDI_INFO_DUPLEX;
1492 /*-----------------------------------------------------------------------------
1494 ----------------------------------------------------------------------------*/
1496 static u32 snd_hdsp_convert_from_aes(snd_aes_iec958_t *aes)
1499 val |= (aes->status[0] & IEC958_AES0_PROFESSIONAL) ? HDSP_SPDIFProfessional : 0;
1500 val |= (aes->status[0] & IEC958_AES0_NONAUDIO) ? HDSP_SPDIFNonAudio : 0;
1501 if (val & HDSP_SPDIFProfessional)
1502 val |= (aes->status[0] & IEC958_AES0_PRO_EMPHASIS_5015) ? HDSP_SPDIFEmphasis : 0;
1504 val |= (aes->status[0] & IEC958_AES0_CON_EMPHASIS_5015) ? HDSP_SPDIFEmphasis : 0;
1508 static void snd_hdsp_convert_to_aes(snd_aes_iec958_t *aes, u32 val)
1510 aes->status[0] = ((val & HDSP_SPDIFProfessional) ? IEC958_AES0_PROFESSIONAL : 0) |
1511 ((val & HDSP_SPDIFNonAudio) ? IEC958_AES0_NONAUDIO : 0);
1512 if (val & HDSP_SPDIFProfessional)
1513 aes->status[0] |= (val & HDSP_SPDIFEmphasis) ? IEC958_AES0_PRO_EMPHASIS_5015 : 0;
1515 aes->status[0] |= (val & HDSP_SPDIFEmphasis) ? IEC958_AES0_CON_EMPHASIS_5015 : 0;
1518 static int snd_hdsp_control_spdif_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
1520 uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
1525 static int snd_hdsp_control_spdif_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1527 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
1529 snd_hdsp_convert_to_aes(&ucontrol->value.iec958, hdsp->creg_spdif);
1533 static int snd_hdsp_control_spdif_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1535 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
1539 val = snd_hdsp_convert_from_aes(&ucontrol->value.iec958);
1540 spin_lock_irq(&hdsp->lock);
1541 change = val != hdsp->creg_spdif;
1542 hdsp->creg_spdif = val;
1543 spin_unlock_irq(&hdsp->lock);
1547 static int snd_hdsp_control_spdif_stream_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
1549 uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
1554 static int snd_hdsp_control_spdif_stream_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1556 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
1558 snd_hdsp_convert_to_aes(&ucontrol->value.iec958, hdsp->creg_spdif_stream);
1562 static int snd_hdsp_control_spdif_stream_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1564 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
1568 val = snd_hdsp_convert_from_aes(&ucontrol->value.iec958);
1569 spin_lock_irq(&hdsp->lock);
1570 change = val != hdsp->creg_spdif_stream;
1571 hdsp->creg_spdif_stream = val;
1572 hdsp->control_register &= ~(HDSP_SPDIFProfessional | HDSP_SPDIFNonAudio | HDSP_SPDIFEmphasis);
1573 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register |= val);
1574 spin_unlock_irq(&hdsp->lock);
1578 static int snd_hdsp_control_spdif_mask_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
1580 uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
1585 static int snd_hdsp_control_spdif_mask_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1587 ucontrol->value.iec958.status[0] = kcontrol->private_value;
1591 #define HDSP_SPDIF_IN(xname, xindex) \
1592 { .iface = SNDRV_CTL_ELEM_IFACE_PCM, \
1595 .info = snd_hdsp_info_spdif_in, \
1596 .get = snd_hdsp_get_spdif_in, \
1597 .put = snd_hdsp_put_spdif_in }
1599 static unsigned int hdsp_spdif_in(hdsp_t *hdsp)
1601 return hdsp_decode_spdif_in(hdsp->control_register & HDSP_SPDIFInputMask);
1604 static int hdsp_set_spdif_input(hdsp_t *hdsp, int in)
1606 hdsp->control_register &= ~HDSP_SPDIFInputMask;
1607 hdsp->control_register |= hdsp_encode_spdif_in(in);
1608 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
1612 static int snd_hdsp_info_spdif_in(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
1614 static char *texts[4] = {"Optical", "Coaxial", "Internal", "AES"};
1615 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
1617 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1619 uinfo->value.enumerated.items = ((hdsp->io_type == H9632) ? 4 : 3);
1620 if (uinfo->value.enumerated.item > ((hdsp->io_type == H9632) ? 3 : 2))
1621 uinfo->value.enumerated.item = ((hdsp->io_type == H9632) ? 3 : 2);
1622 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1626 static int snd_hdsp_get_spdif_in(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1628 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
1630 ucontrol->value.enumerated.item[0] = hdsp_spdif_in(hdsp);
1634 static int snd_hdsp_put_spdif_in(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1636 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
1640 if (!snd_hdsp_use_is_exclusive(hdsp))
1642 val = ucontrol->value.enumerated.item[0] % ((hdsp->io_type == H9632) ? 4 : 3);
1643 spin_lock_irq(&hdsp->lock);
1644 change = val != hdsp_spdif_in(hdsp);
1646 hdsp_set_spdif_input(hdsp, val);
1647 spin_unlock_irq(&hdsp->lock);
1651 #define HDSP_SPDIF_OUT(xname, xindex) \
1652 { .iface = SNDRV_CTL_ELEM_IFACE_HWDEP, .name = xname, .index = xindex, \
1653 .info = snd_hdsp_info_spdif_bits, \
1654 .get = snd_hdsp_get_spdif_out, .put = snd_hdsp_put_spdif_out }
1656 static int hdsp_spdif_out(hdsp_t *hdsp)
1658 return (hdsp->control_register & HDSP_SPDIFOpticalOut) ? 1 : 0;
1661 static int hdsp_set_spdif_output(hdsp_t *hdsp, int out)
1664 hdsp->control_register |= HDSP_SPDIFOpticalOut;
1666 hdsp->control_register &= ~HDSP_SPDIFOpticalOut;
1668 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
1672 static int snd_hdsp_info_spdif_bits(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
1674 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
1676 uinfo->value.integer.min = 0;
1677 uinfo->value.integer.max = 1;
1681 static int snd_hdsp_get_spdif_out(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1683 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
1685 ucontrol->value.integer.value[0] = hdsp_spdif_out(hdsp);
1689 static int snd_hdsp_put_spdif_out(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1691 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
1695 if (!snd_hdsp_use_is_exclusive(hdsp))
1697 val = ucontrol->value.integer.value[0] & 1;
1698 spin_lock_irq(&hdsp->lock);
1699 change = (int)val != hdsp_spdif_out(hdsp);
1700 hdsp_set_spdif_output(hdsp, val);
1701 spin_unlock_irq(&hdsp->lock);
1705 #define HDSP_SPDIF_PROFESSIONAL(xname, xindex) \
1706 { .iface = SNDRV_CTL_ELEM_IFACE_HWDEP, .name = xname, .index = xindex, \
1707 .info = snd_hdsp_info_spdif_bits, \
1708 .get = snd_hdsp_get_spdif_professional, .put = snd_hdsp_put_spdif_professional }
1710 static int hdsp_spdif_professional(hdsp_t *hdsp)
1712 return (hdsp->control_register & HDSP_SPDIFProfessional) ? 1 : 0;
1715 static int hdsp_set_spdif_professional(hdsp_t *hdsp, int val)
1718 hdsp->control_register |= HDSP_SPDIFProfessional;
1720 hdsp->control_register &= ~HDSP_SPDIFProfessional;
1722 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
1726 static int snd_hdsp_get_spdif_professional(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1728 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
1730 ucontrol->value.integer.value[0] = hdsp_spdif_professional(hdsp);
1734 static int snd_hdsp_put_spdif_professional(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1736 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
1740 if (!snd_hdsp_use_is_exclusive(hdsp))
1742 val = ucontrol->value.integer.value[0] & 1;
1743 spin_lock_irq(&hdsp->lock);
1744 change = (int)val != hdsp_spdif_professional(hdsp);
1745 hdsp_set_spdif_professional(hdsp, val);
1746 spin_unlock_irq(&hdsp->lock);
1750 #define HDSP_SPDIF_EMPHASIS(xname, xindex) \
1751 { .iface = SNDRV_CTL_ELEM_IFACE_HWDEP, .name = xname, .index = xindex, \
1752 .info = snd_hdsp_info_spdif_bits, \
1753 .get = snd_hdsp_get_spdif_emphasis, .put = snd_hdsp_put_spdif_emphasis }
1755 static int hdsp_spdif_emphasis(hdsp_t *hdsp)
1757 return (hdsp->control_register & HDSP_SPDIFEmphasis) ? 1 : 0;
1760 static int hdsp_set_spdif_emphasis(hdsp_t *hdsp, int val)
1763 hdsp->control_register |= HDSP_SPDIFEmphasis;
1765 hdsp->control_register &= ~HDSP_SPDIFEmphasis;
1767 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
1771 static int snd_hdsp_get_spdif_emphasis(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1773 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
1775 ucontrol->value.integer.value[0] = hdsp_spdif_emphasis(hdsp);
1779 static int snd_hdsp_put_spdif_emphasis(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1781 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
1785 if (!snd_hdsp_use_is_exclusive(hdsp))
1787 val = ucontrol->value.integer.value[0] & 1;
1788 spin_lock_irq(&hdsp->lock);
1789 change = (int)val != hdsp_spdif_emphasis(hdsp);
1790 hdsp_set_spdif_emphasis(hdsp, val);
1791 spin_unlock_irq(&hdsp->lock);
1795 #define HDSP_SPDIF_NON_AUDIO(xname, xindex) \
1796 { .iface = SNDRV_CTL_ELEM_IFACE_HWDEP, .name = xname, .index = xindex, \
1797 .info = snd_hdsp_info_spdif_bits, \
1798 .get = snd_hdsp_get_spdif_nonaudio, .put = snd_hdsp_put_spdif_nonaudio }
1800 static int hdsp_spdif_nonaudio(hdsp_t *hdsp)
1802 return (hdsp->control_register & HDSP_SPDIFNonAudio) ? 1 : 0;
1805 static int hdsp_set_spdif_nonaudio(hdsp_t *hdsp, int val)
1808 hdsp->control_register |= HDSP_SPDIFNonAudio;
1810 hdsp->control_register &= ~HDSP_SPDIFNonAudio;
1812 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
1816 static int snd_hdsp_get_spdif_nonaudio(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1818 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
1820 ucontrol->value.integer.value[0] = hdsp_spdif_nonaudio(hdsp);
1824 static int snd_hdsp_put_spdif_nonaudio(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1826 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
1830 if (!snd_hdsp_use_is_exclusive(hdsp))
1832 val = ucontrol->value.integer.value[0] & 1;
1833 spin_lock_irq(&hdsp->lock);
1834 change = (int)val != hdsp_spdif_nonaudio(hdsp);
1835 hdsp_set_spdif_nonaudio(hdsp, val);
1836 spin_unlock_irq(&hdsp->lock);
1840 #define HDSP_SPDIF_SAMPLE_RATE(xname, xindex) \
1841 { .iface = SNDRV_CTL_ELEM_IFACE_HWDEP, \
1844 .access = SNDRV_CTL_ELEM_ACCESS_READ, \
1845 .info = snd_hdsp_info_spdif_sample_rate, \
1846 .get = snd_hdsp_get_spdif_sample_rate \
1849 static int snd_hdsp_info_spdif_sample_rate(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
1851 static char *texts[] = {"32000", "44100", "48000", "64000", "88200", "96000", "None", "128000", "176400", "192000"};
1852 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
1854 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1856 uinfo->value.enumerated.items = (hdsp->io_type == H9632) ? 10 : 7;
1857 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
1858 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
1859 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1863 static int snd_hdsp_get_spdif_sample_rate(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1865 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
1867 switch (hdsp_spdif_sample_rate(hdsp)) {
1869 ucontrol->value.enumerated.item[0] = 0;
1872 ucontrol->value.enumerated.item[0] = 1;
1875 ucontrol->value.enumerated.item[0] = 2;
1878 ucontrol->value.enumerated.item[0] = 3;
1881 ucontrol->value.enumerated.item[0] = 4;
1884 ucontrol->value.enumerated.item[0] = 5;
1887 ucontrol->value.enumerated.item[0] = 7;
1890 ucontrol->value.enumerated.item[0] = 8;
1893 ucontrol->value.enumerated.item[0] = 9;
1896 ucontrol->value.enumerated.item[0] = 6;
1901 #define HDSP_SYSTEM_SAMPLE_RATE(xname, xindex) \
1902 { .iface = SNDRV_CTL_ELEM_IFACE_HWDEP, \
1905 .access = SNDRV_CTL_ELEM_ACCESS_READ, \
1906 .info = snd_hdsp_info_system_sample_rate, \
1907 .get = snd_hdsp_get_system_sample_rate \
1910 static int snd_hdsp_info_system_sample_rate(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
1912 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1917 static int snd_hdsp_get_system_sample_rate(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1919 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
1921 ucontrol->value.enumerated.item[0] = hdsp->system_sample_rate;
1925 #define HDSP_AUTOSYNC_SAMPLE_RATE(xname, xindex) \
1926 { .iface = SNDRV_CTL_ELEM_IFACE_PCM, \
1929 .access = SNDRV_CTL_ELEM_ACCESS_READ, \
1930 .info = snd_hdsp_info_autosync_sample_rate, \
1931 .get = snd_hdsp_get_autosync_sample_rate \
1934 static int snd_hdsp_info_autosync_sample_rate(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
1936 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
1937 static char *texts[] = {"32000", "44100", "48000", "64000", "88200", "96000", "None", "128000", "176400", "192000"};
1938 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1940 uinfo->value.enumerated.items = (hdsp->io_type == H9632) ? 10 : 7 ;
1941 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
1942 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
1943 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
1947 static int snd_hdsp_get_autosync_sample_rate(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
1949 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
1951 switch (hdsp_external_sample_rate(hdsp)) {
1953 ucontrol->value.enumerated.item[0] = 0;
1956 ucontrol->value.enumerated.item[0] = 1;
1959 ucontrol->value.enumerated.item[0] = 2;
1962 ucontrol->value.enumerated.item[0] = 3;
1965 ucontrol->value.enumerated.item[0] = 4;
1968 ucontrol->value.enumerated.item[0] = 5;
1971 ucontrol->value.enumerated.item[0] = 7;
1974 ucontrol->value.enumerated.item[0] = 8;
1977 ucontrol->value.enumerated.item[0] = 9;
1980 ucontrol->value.enumerated.item[0] = 6;
1985 #define HDSP_SYSTEM_CLOCK_MODE(xname, xindex) \
1986 { .iface = SNDRV_CTL_ELEM_IFACE_HWDEP, \
1989 .access = SNDRV_CTL_ELEM_ACCESS_READ, \
1990 .info = snd_hdsp_info_system_clock_mode, \
1991 .get = snd_hdsp_get_system_clock_mode \
1994 static int hdsp_system_clock_mode(hdsp_t *hdsp)
1996 if (hdsp->control_register & HDSP_ClockModeMaster) {
1998 } else if (hdsp_external_sample_rate(hdsp) != hdsp->system_sample_rate) {
2004 static int snd_hdsp_info_system_clock_mode(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
2006 static char *texts[] = {"Master", "Slave" };
2008 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2010 uinfo->value.enumerated.items = 2;
2011 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
2012 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
2013 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
2017 static int snd_hdsp_get_system_clock_mode(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
2019 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
2021 ucontrol->value.enumerated.item[0] = hdsp_system_clock_mode(hdsp);
2025 #define HDSP_CLOCK_SOURCE(xname, xindex) \
2026 { .iface = SNDRV_CTL_ELEM_IFACE_PCM, \
2029 .info = snd_hdsp_info_clock_source, \
2030 .get = snd_hdsp_get_clock_source, \
2031 .put = snd_hdsp_put_clock_source \
2034 static int hdsp_clock_source(hdsp_t *hdsp)
2036 if (hdsp->control_register & HDSP_ClockModeMaster) {
2037 switch (hdsp->system_sample_rate) {
2064 static int hdsp_set_clock_source(hdsp_t *hdsp, int mode)
2068 case HDSP_CLOCK_SOURCE_AUTOSYNC:
2069 if (hdsp_external_sample_rate(hdsp) != 0) {
2070 if (!hdsp_set_rate(hdsp, hdsp_external_sample_rate(hdsp), 1)) {
2071 hdsp->control_register &= ~HDSP_ClockModeMaster;
2072 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
2077 case HDSP_CLOCK_SOURCE_INTERNAL_32KHZ:
2080 case HDSP_CLOCK_SOURCE_INTERNAL_44_1KHZ:
2083 case HDSP_CLOCK_SOURCE_INTERNAL_48KHZ:
2086 case HDSP_CLOCK_SOURCE_INTERNAL_64KHZ:
2089 case HDSP_CLOCK_SOURCE_INTERNAL_88_2KHZ:
2092 case HDSP_CLOCK_SOURCE_INTERNAL_96KHZ:
2095 case HDSP_CLOCK_SOURCE_INTERNAL_128KHZ:
2098 case HDSP_CLOCK_SOURCE_INTERNAL_176_4KHZ:
2101 case HDSP_CLOCK_SOURCE_INTERNAL_192KHZ:
2107 hdsp->control_register |= HDSP_ClockModeMaster;
2108 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
2109 hdsp_set_rate(hdsp, rate, 1);
2113 static int snd_hdsp_info_clock_source(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
2115 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" };
2116 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
2118 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2120 if (hdsp->io_type == H9632)
2121 uinfo->value.enumerated.items = 10;
2123 uinfo->value.enumerated.items = 7;
2124 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
2125 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
2126 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
2130 static int snd_hdsp_get_clock_source(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
2132 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
2134 ucontrol->value.enumerated.item[0] = hdsp_clock_source(hdsp);
2138 static int snd_hdsp_put_clock_source(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
2140 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
2144 if (!snd_hdsp_use_is_exclusive(hdsp))
2146 val = ucontrol->value.enumerated.item[0];
2147 if (val < 0) val = 0;
2148 if (hdsp->io_type == H9632) {
2149 if (val > 9) val = 9;
2151 if (val > 6) val = 6;
2153 spin_lock_irq(&hdsp->lock);
2154 if (val != hdsp_clock_source(hdsp)) {
2155 change = (hdsp_set_clock_source(hdsp, val) == 0) ? 1 : 0;
2159 spin_unlock_irq(&hdsp->lock);
2163 #define HDSP_DA_GAIN(xname, xindex) \
2164 { .iface = SNDRV_CTL_ELEM_IFACE_HWDEP, \
2167 .info = snd_hdsp_info_da_gain, \
2168 .get = snd_hdsp_get_da_gain, \
2169 .put = snd_hdsp_put_da_gain \
2172 static int hdsp_da_gain(hdsp_t *hdsp)
2174 switch (hdsp->control_register & HDSP_DAGainMask) {
2175 case HDSP_DAGainHighGain:
2177 case HDSP_DAGainPlus4dBu:
2179 case HDSP_DAGainMinus10dBV:
2186 static int hdsp_set_da_gain(hdsp_t *hdsp, int mode)
2188 hdsp->control_register &= ~HDSP_DAGainMask;
2191 hdsp->control_register |= HDSP_DAGainHighGain;
2194 hdsp->control_register |= HDSP_DAGainPlus4dBu;
2197 hdsp->control_register |= HDSP_DAGainMinus10dBV;
2203 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
2207 static int snd_hdsp_info_da_gain(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
2209 static char *texts[] = {"Hi Gain", "+4 dBu", "-10 dbV"};
2211 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2213 uinfo->value.enumerated.items = 3;
2214 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
2215 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
2216 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
2220 static int snd_hdsp_get_da_gain(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
2222 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
2224 ucontrol->value.enumerated.item[0] = hdsp_da_gain(hdsp);
2228 static int snd_hdsp_put_da_gain(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
2230 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
2234 if (!snd_hdsp_use_is_exclusive(hdsp))
2236 val = ucontrol->value.enumerated.item[0];
2237 if (val < 0) val = 0;
2238 if (val > 2) val = 2;
2239 spin_lock_irq(&hdsp->lock);
2240 if (val != hdsp_da_gain(hdsp)) {
2241 change = (hdsp_set_da_gain(hdsp, val) == 0) ? 1 : 0;
2245 spin_unlock_irq(&hdsp->lock);
2249 #define HDSP_AD_GAIN(xname, xindex) \
2250 { .iface = SNDRV_CTL_ELEM_IFACE_HWDEP, \
2253 .info = snd_hdsp_info_ad_gain, \
2254 .get = snd_hdsp_get_ad_gain, \
2255 .put = snd_hdsp_put_ad_gain \
2258 static int hdsp_ad_gain(hdsp_t *hdsp)
2260 switch (hdsp->control_register & HDSP_ADGainMask) {
2261 case HDSP_ADGainMinus10dBV:
2263 case HDSP_ADGainPlus4dBu:
2265 case HDSP_ADGainLowGain:
2272 static int hdsp_set_ad_gain(hdsp_t *hdsp, int mode)
2274 hdsp->control_register &= ~HDSP_ADGainMask;
2277 hdsp->control_register |= HDSP_ADGainMinus10dBV;
2280 hdsp->control_register |= HDSP_ADGainPlus4dBu;
2283 hdsp->control_register |= HDSP_ADGainLowGain;
2289 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
2293 static int snd_hdsp_info_ad_gain(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
2295 static char *texts[] = {"-10 dBV", "+4 dBu", "Lo Gain"};
2297 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2299 uinfo->value.enumerated.items = 3;
2300 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
2301 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
2302 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
2306 static int snd_hdsp_get_ad_gain(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
2308 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
2310 ucontrol->value.enumerated.item[0] = hdsp_ad_gain(hdsp);
2314 static int snd_hdsp_put_ad_gain(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
2316 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
2320 if (!snd_hdsp_use_is_exclusive(hdsp))
2322 val = ucontrol->value.enumerated.item[0];
2323 if (val < 0) val = 0;
2324 if (val > 2) val = 2;
2325 spin_lock_irq(&hdsp->lock);
2326 if (val != hdsp_ad_gain(hdsp)) {
2327 change = (hdsp_set_ad_gain(hdsp, val) == 0) ? 1 : 0;
2331 spin_unlock_irq(&hdsp->lock);
2335 #define HDSP_PHONE_GAIN(xname, xindex) \
2336 { .iface = SNDRV_CTL_ELEM_IFACE_HWDEP, \
2339 .info = snd_hdsp_info_phone_gain, \
2340 .get = snd_hdsp_get_phone_gain, \
2341 .put = snd_hdsp_put_phone_gain \
2344 static int hdsp_phone_gain(hdsp_t *hdsp)
2346 switch (hdsp->control_register & HDSP_PhoneGainMask) {
2347 case HDSP_PhoneGain0dB:
2349 case HDSP_PhoneGainMinus6dB:
2351 case HDSP_PhoneGainMinus12dB:
2358 static int hdsp_set_phone_gain(hdsp_t *hdsp, int mode)
2360 hdsp->control_register &= ~HDSP_PhoneGainMask;
2363 hdsp->control_register |= HDSP_PhoneGain0dB;
2366 hdsp->control_register |= HDSP_PhoneGainMinus6dB;
2369 hdsp->control_register |= HDSP_PhoneGainMinus12dB;
2375 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
2379 static int snd_hdsp_info_phone_gain(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
2381 static char *texts[] = {"0 dB", "-6 dB", "-12 dB"};
2383 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2385 uinfo->value.enumerated.items = 3;
2386 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
2387 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
2388 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
2392 static int snd_hdsp_get_phone_gain(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
2394 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
2396 ucontrol->value.enumerated.item[0] = hdsp_phone_gain(hdsp);
2400 static int snd_hdsp_put_phone_gain(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
2402 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
2406 if (!snd_hdsp_use_is_exclusive(hdsp))
2408 val = ucontrol->value.enumerated.item[0];
2409 if (val < 0) val = 0;
2410 if (val > 2) val = 2;
2411 spin_lock_irq(&hdsp->lock);
2412 if (val != hdsp_phone_gain(hdsp)) {
2413 change = (hdsp_set_phone_gain(hdsp, val) == 0) ? 1 : 0;
2417 spin_unlock_irq(&hdsp->lock);
2421 #define HDSP_XLR_BREAKOUT_CABLE(xname, xindex) \
2422 { .iface = SNDRV_CTL_ELEM_IFACE_HWDEP, \
2425 .info = snd_hdsp_info_xlr_breakout_cable, \
2426 .get = snd_hdsp_get_xlr_breakout_cable, \
2427 .put = snd_hdsp_put_xlr_breakout_cable \
2430 static int hdsp_xlr_breakout_cable(hdsp_t *hdsp)
2432 if (hdsp->control_register & HDSP_XLRBreakoutCable) {
2438 static int hdsp_set_xlr_breakout_cable(hdsp_t *hdsp, int mode)
2441 hdsp->control_register |= HDSP_XLRBreakoutCable;
2443 hdsp->control_register &= ~HDSP_XLRBreakoutCable;
2445 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
2449 static int snd_hdsp_info_xlr_breakout_cable(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
2451 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
2453 uinfo->value.integer.min = 0;
2454 uinfo->value.integer.max = 1;
2458 static int snd_hdsp_get_xlr_breakout_cable(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
2460 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
2462 ucontrol->value.enumerated.item[0] = hdsp_xlr_breakout_cable(hdsp);
2466 static int snd_hdsp_put_xlr_breakout_cable(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
2468 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
2472 if (!snd_hdsp_use_is_exclusive(hdsp))
2474 val = ucontrol->value.integer.value[0] & 1;
2475 spin_lock_irq(&hdsp->lock);
2476 change = (int)val != hdsp_xlr_breakout_cable(hdsp);
2477 hdsp_set_xlr_breakout_cable(hdsp, val);
2478 spin_unlock_irq(&hdsp->lock);
2482 /* (De)activates old RME Analog Extension Board
2483 These are connected to the internal ADAT connector
2484 Switching this on desactivates external ADAT
2486 #define HDSP_AEB(xname, xindex) \
2487 { .iface = SNDRV_CTL_ELEM_IFACE_HWDEP, \
2490 .info = snd_hdsp_info_aeb, \
2491 .get = snd_hdsp_get_aeb, \
2492 .put = snd_hdsp_put_aeb \
2495 static int hdsp_aeb(hdsp_t *hdsp)
2497 if (hdsp->control_register & HDSP_AnalogExtensionBoard) {
2503 static int hdsp_set_aeb(hdsp_t *hdsp, int mode)
2506 hdsp->control_register |= HDSP_AnalogExtensionBoard;
2508 hdsp->control_register &= ~HDSP_AnalogExtensionBoard;
2510 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
2514 static int snd_hdsp_info_aeb(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
2516 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
2518 uinfo->value.integer.min = 0;
2519 uinfo->value.integer.max = 1;
2523 static int snd_hdsp_get_aeb(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
2525 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
2527 ucontrol->value.enumerated.item[0] = hdsp_aeb(hdsp);
2531 static int snd_hdsp_put_aeb(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
2533 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
2537 if (!snd_hdsp_use_is_exclusive(hdsp))
2539 val = ucontrol->value.integer.value[0] & 1;
2540 spin_lock_irq(&hdsp->lock);
2541 change = (int)val != hdsp_aeb(hdsp);
2542 hdsp_set_aeb(hdsp, val);
2543 spin_unlock_irq(&hdsp->lock);
2547 #define HDSP_PREF_SYNC_REF(xname, xindex) \
2548 { .iface = SNDRV_CTL_ELEM_IFACE_HWDEP, \
2551 .info = snd_hdsp_info_pref_sync_ref, \
2552 .get = snd_hdsp_get_pref_sync_ref, \
2553 .put = snd_hdsp_put_pref_sync_ref \
2556 static int hdsp_pref_sync_ref(hdsp_t *hdsp)
2558 /* Notice that this looks at the requested sync source,
2559 not the one actually in use.
2562 switch (hdsp->control_register & HDSP_SyncRefMask) {
2563 case HDSP_SyncRef_ADAT1:
2564 return HDSP_SYNC_FROM_ADAT1;
2565 case HDSP_SyncRef_ADAT2:
2566 return HDSP_SYNC_FROM_ADAT2;
2567 case HDSP_SyncRef_ADAT3:
2568 return HDSP_SYNC_FROM_ADAT3;
2569 case HDSP_SyncRef_SPDIF:
2570 return HDSP_SYNC_FROM_SPDIF;
2571 case HDSP_SyncRef_WORD:
2572 return HDSP_SYNC_FROM_WORD;
2573 case HDSP_SyncRef_ADAT_SYNC:
2574 return HDSP_SYNC_FROM_ADAT_SYNC;
2576 return HDSP_SYNC_FROM_WORD;
2581 static int hdsp_set_pref_sync_ref(hdsp_t *hdsp, int pref)
2583 hdsp->control_register &= ~HDSP_SyncRefMask;
2585 case HDSP_SYNC_FROM_ADAT1:
2586 hdsp->control_register &= ~HDSP_SyncRefMask; /* clear SyncRef bits */
2588 case HDSP_SYNC_FROM_ADAT2:
2589 hdsp->control_register |= HDSP_SyncRef_ADAT2;
2591 case HDSP_SYNC_FROM_ADAT3:
2592 hdsp->control_register |= HDSP_SyncRef_ADAT3;
2594 case HDSP_SYNC_FROM_SPDIF:
2595 hdsp->control_register |= HDSP_SyncRef_SPDIF;
2597 case HDSP_SYNC_FROM_WORD:
2598 hdsp->control_register |= HDSP_SyncRef_WORD;
2600 case HDSP_SYNC_FROM_ADAT_SYNC:
2601 hdsp->control_register |= HDSP_SyncRef_ADAT_SYNC;
2606 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
2610 static int snd_hdsp_info_pref_sync_ref(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
2612 static char *texts[] = {"Word", "IEC958", "ADAT1", "ADAT Sync", "ADAT2", "ADAT3" };
2613 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
2615 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2618 switch (hdsp->io_type) {
2621 uinfo->value.enumerated.items = 6;
2624 uinfo->value.enumerated.items = 4;
2627 uinfo->value.enumerated.items = 3;
2630 uinfo->value.enumerated.items = 0;
2634 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
2635 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
2636 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
2640 static int snd_hdsp_get_pref_sync_ref(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
2642 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
2644 ucontrol->value.enumerated.item[0] = hdsp_pref_sync_ref(hdsp);
2648 static int snd_hdsp_put_pref_sync_ref(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
2650 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
2654 if (!snd_hdsp_use_is_exclusive(hdsp))
2657 switch (hdsp->io_type) {
2672 val = ucontrol->value.enumerated.item[0] % max;
2673 spin_lock_irq(&hdsp->lock);
2674 change = (int)val != hdsp_pref_sync_ref(hdsp);
2675 hdsp_set_pref_sync_ref(hdsp, val);
2676 spin_unlock_irq(&hdsp->lock);
2680 #define HDSP_AUTOSYNC_REF(xname, xindex) \
2681 { .iface = SNDRV_CTL_ELEM_IFACE_HWDEP, \
2684 .access = SNDRV_CTL_ELEM_ACCESS_READ, \
2685 .info = snd_hdsp_info_autosync_ref, \
2686 .get = snd_hdsp_get_autosync_ref, \
2689 static int hdsp_autosync_ref(hdsp_t *hdsp)
2691 /* This looks at the autosync selected sync reference */
2692 unsigned int status2 = hdsp_read(hdsp, HDSP_status2Register);
2694 switch (status2 & HDSP_SelSyncRefMask) {
2695 case HDSP_SelSyncRef_WORD:
2696 return HDSP_AUTOSYNC_FROM_WORD;
2697 case HDSP_SelSyncRef_ADAT_SYNC:
2698 return HDSP_AUTOSYNC_FROM_ADAT_SYNC;
2699 case HDSP_SelSyncRef_SPDIF:
2700 return HDSP_AUTOSYNC_FROM_SPDIF;
2701 case HDSP_SelSyncRefMask:
2702 return HDSP_AUTOSYNC_FROM_NONE;
2703 case HDSP_SelSyncRef_ADAT1:
2704 return HDSP_AUTOSYNC_FROM_ADAT1;
2705 case HDSP_SelSyncRef_ADAT2:
2706 return HDSP_AUTOSYNC_FROM_ADAT2;
2707 case HDSP_SelSyncRef_ADAT3:
2708 return HDSP_AUTOSYNC_FROM_ADAT3;
2710 return HDSP_AUTOSYNC_FROM_WORD;
2715 static int snd_hdsp_info_autosync_ref(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
2717 static char *texts[] = {"Word", "ADAT Sync", "IEC958", "None", "ADAT1", "ADAT2", "ADAT3" };
2719 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2721 uinfo->value.enumerated.items = 7;
2722 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
2723 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
2724 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
2728 static int snd_hdsp_get_autosync_ref(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
2730 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
2732 ucontrol->value.enumerated.item[0] = hdsp_pref_sync_ref(hdsp);
2736 #define HDSP_PASSTHRU(xname, xindex) \
2737 { .iface = SNDRV_CTL_ELEM_IFACE_HWDEP, \
2740 .info = snd_hdsp_info_passthru, \
2741 .put = snd_hdsp_put_passthru, \
2742 .get = snd_hdsp_get_passthru \
2745 static int snd_hdsp_info_passthru(snd_kcontrol_t * kcontrol, snd_ctl_elem_info_t * uinfo)
2747 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
2749 uinfo->value.integer.min = 0;
2750 uinfo->value.integer.max = 1;
2754 static int snd_hdsp_get_passthru(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
2756 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
2758 spin_lock_irq(&hdsp->lock);
2759 ucontrol->value.integer.value[0] = hdsp->passthru;
2760 spin_unlock_irq(&hdsp->lock);
2764 static int snd_hdsp_put_passthru(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
2766 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
2771 if (!snd_hdsp_use_is_exclusive(hdsp))
2774 val = ucontrol->value.integer.value[0] & 1;
2775 spin_lock_irq(&hdsp->lock);
2776 change = (ucontrol->value.integer.value[0] != hdsp->passthru);
2778 err = hdsp_set_passthru(hdsp, val);
2779 spin_unlock_irq(&hdsp->lock);
2780 return err ? err : change;
2783 #define HDSP_LINE_OUT(xname, xindex) \
2784 { .iface = SNDRV_CTL_ELEM_IFACE_HWDEP, \
2787 .info = snd_hdsp_info_line_out, \
2788 .get = snd_hdsp_get_line_out, \
2789 .put = snd_hdsp_put_line_out \
2792 static int hdsp_line_out(hdsp_t *hdsp)
2794 return (hdsp->control_register & HDSP_LineOut) ? 1 : 0;
2797 static int hdsp_set_line_output(hdsp_t *hdsp, int out)
2800 hdsp->control_register |= HDSP_LineOut;
2802 hdsp->control_register &= ~HDSP_LineOut;
2804 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
2808 static int snd_hdsp_info_line_out(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
2810 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
2812 uinfo->value.integer.min = 0;
2813 uinfo->value.integer.max = 1;
2817 static int snd_hdsp_get_line_out(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
2819 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
2821 spin_lock_irq(&hdsp->lock);
2822 ucontrol->value.integer.value[0] = hdsp_line_out(hdsp);
2823 spin_unlock_irq(&hdsp->lock);
2827 static int snd_hdsp_put_line_out(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
2829 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
2833 if (!snd_hdsp_use_is_exclusive(hdsp))
2835 val = ucontrol->value.integer.value[0] & 1;
2836 spin_lock_irq(&hdsp->lock);
2837 change = (int)val != hdsp_line_out(hdsp);
2838 hdsp_set_line_output(hdsp, val);
2839 spin_unlock_irq(&hdsp->lock);
2843 #define HDSP_MIXER(xname, xindex) \
2844 { .iface = SNDRV_CTL_ELEM_IFACE_HWDEP, \
2847 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | \
2848 SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
2849 .info = snd_hdsp_info_mixer, \
2850 .get = snd_hdsp_get_mixer, \
2851 .put = snd_hdsp_put_mixer \
2854 static int snd_hdsp_info_mixer(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
2856 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
2858 uinfo->value.integer.min = 0;
2859 uinfo->value.integer.max = 65536;
2860 uinfo->value.integer.step = 1;
2864 static int snd_hdsp_get_mixer(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
2866 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
2871 source = ucontrol->value.integer.value[0];
2872 destination = ucontrol->value.integer.value[1];
2874 if (source >= hdsp->max_channels) {
2875 addr = hdsp_playback_to_output_key(hdsp,source-hdsp->max_channels,destination);
2877 addr = hdsp_input_to_output_key(hdsp,source, destination);
2880 spin_lock_irq(&hdsp->lock);
2881 ucontrol->value.integer.value[2] = hdsp_read_gain (hdsp, addr);
2882 spin_unlock_irq(&hdsp->lock);
2886 static int snd_hdsp_put_mixer(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
2888 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
2895 if (!snd_hdsp_use_is_exclusive(hdsp))
2898 source = ucontrol->value.integer.value[0];
2899 destination = ucontrol->value.integer.value[1];
2901 if (source >= hdsp->max_channels) {
2902 addr = hdsp_playback_to_output_key(hdsp,source-hdsp->max_channels, destination);
2904 addr = hdsp_input_to_output_key(hdsp,source, destination);
2907 gain = ucontrol->value.integer.value[2];
2909 spin_lock_irq(&hdsp->lock);
2910 change = gain != hdsp_read_gain(hdsp, addr);
2912 hdsp_write_gain(hdsp, addr, gain);
2913 spin_unlock_irq(&hdsp->lock);
2917 #define HDSP_WC_SYNC_CHECK(xname, xindex) \
2918 { .iface = SNDRV_CTL_ELEM_IFACE_HWDEP, \
2921 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
2922 .info = snd_hdsp_info_sync_check, \
2923 .get = snd_hdsp_get_wc_sync_check \
2926 static int snd_hdsp_info_sync_check(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
2928 static char *texts[] = {"No Lock", "Lock", "Sync" };
2929 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2931 uinfo->value.enumerated.items = 3;
2932 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
2933 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
2934 strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
2938 static int hdsp_wc_sync_check(hdsp_t *hdsp)
2940 int status2 = hdsp_read(hdsp, HDSP_status2Register);
2941 if (status2 & HDSP_wc_lock) {
2942 if (status2 & HDSP_wc_sync) {
2953 static int snd_hdsp_get_wc_sync_check(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
2955 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
2957 ucontrol->value.enumerated.item[0] = hdsp_wc_sync_check(hdsp);
2961 #define HDSP_SPDIF_SYNC_CHECK(xname, xindex) \
2962 { .iface = SNDRV_CTL_ELEM_IFACE_HWDEP, \
2965 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
2966 .info = snd_hdsp_info_sync_check, \
2967 .get = snd_hdsp_get_spdif_sync_check \
2970 static int hdsp_spdif_sync_check(hdsp_t *hdsp)
2972 int status = hdsp_read(hdsp, HDSP_statusRegister);
2973 if (status & HDSP_SPDIFErrorFlag) {
2976 if (status & HDSP_SPDIFSync) {
2985 static int snd_hdsp_get_spdif_sync_check(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
2987 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
2989 ucontrol->value.enumerated.item[0] = hdsp_spdif_sync_check(hdsp);
2993 #define HDSP_ADATSYNC_SYNC_CHECK(xname, xindex) \
2994 { .iface = SNDRV_CTL_ELEM_IFACE_HWDEP, \
2997 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
2998 .info = snd_hdsp_info_sync_check, \
2999 .get = snd_hdsp_get_adatsync_sync_check \
3002 static int hdsp_adatsync_sync_check(hdsp_t *hdsp)
3004 int status = hdsp_read(hdsp, HDSP_statusRegister);
3005 if (status & HDSP_TimecodeLock) {
3006 if (status & HDSP_TimecodeSync) {
3016 static int snd_hdsp_get_adatsync_sync_check(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
3018 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
3020 ucontrol->value.enumerated.item[0] = hdsp_adatsync_sync_check(hdsp);
3024 #define HDSP_ADAT_SYNC_CHECK \
3025 { .iface = SNDRV_CTL_ELEM_IFACE_HWDEP, \
3026 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
3027 .info = snd_hdsp_info_sync_check, \
3028 .get = snd_hdsp_get_adat_sync_check \
3031 static int hdsp_adat_sync_check(hdsp_t *hdsp, int idx)
3033 int status = hdsp_read(hdsp, HDSP_statusRegister);
3035 if (status & (HDSP_Lock0>>idx)) {
3036 if (status & (HDSP_Sync0>>idx)) {
3046 static int snd_hdsp_get_adat_sync_check(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
3049 hdsp_t *hdsp = snd_kcontrol_chip(kcontrol);
3051 offset = ucontrol->id.index - 1;
3052 snd_assert(offset >= 0);
3054 switch (hdsp->io_type) {
3069 ucontrol->value.enumerated.item[0] = hdsp_adat_sync_check(hdsp, offset);
3073 static snd_kcontrol_new_t snd_hdsp_9632_controls[] = {
3074 HDSP_DA_GAIN("DA Gain", 0),
3075 HDSP_AD_GAIN("AD Gain", 0),
3076 HDSP_PHONE_GAIN("Phones Gain", 0),
3077 HDSP_XLR_BREAKOUT_CABLE("XLR Breakout Cable", 0)
3080 static snd_kcontrol_new_t snd_hdsp_controls[] = {
3082 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
3083 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,DEFAULT),
3084 .info = snd_hdsp_control_spdif_info,
3085 .get = snd_hdsp_control_spdif_get,
3086 .put = snd_hdsp_control_spdif_put,
3089 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_INACTIVE,
3090 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
3091 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,PCM_STREAM),
3092 .info = snd_hdsp_control_spdif_stream_info,
3093 .get = snd_hdsp_control_spdif_stream_get,
3094 .put = snd_hdsp_control_spdif_stream_put,
3097 .access = SNDRV_CTL_ELEM_ACCESS_READ,
3098 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3099 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,CON_MASK),
3100 .info = snd_hdsp_control_spdif_mask_info,
3101 .get = snd_hdsp_control_spdif_mask_get,
3102 .private_value = IEC958_AES0_NONAUDIO |
3103 IEC958_AES0_PROFESSIONAL |
3104 IEC958_AES0_CON_EMPHASIS,
3107 .access = SNDRV_CTL_ELEM_ACCESS_READ,
3108 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3109 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,PRO_MASK),
3110 .info = snd_hdsp_control_spdif_mask_info,
3111 .get = snd_hdsp_control_spdif_mask_get,
3112 .private_value = IEC958_AES0_NONAUDIO |
3113 IEC958_AES0_PROFESSIONAL |
3114 IEC958_AES0_PRO_EMPHASIS,
3116 HDSP_MIXER("Mixer", 0),
3117 HDSP_SPDIF_IN("IEC958 Input Connector", 0),
3118 HDSP_SPDIF_OUT("IEC958 Output also on ADAT1", 0),
3119 HDSP_SPDIF_PROFESSIONAL("IEC958 Professional Bit", 0),
3120 HDSP_SPDIF_EMPHASIS("IEC958 Emphasis Bit", 0),
3121 HDSP_SPDIF_NON_AUDIO("IEC958 Non-audio Bit", 0),
3122 /* 'Sample Clock Source' complies with the alsa control naming scheme */
3123 HDSP_CLOCK_SOURCE("Sample Clock Source", 0),
3124 HDSP_SYSTEM_CLOCK_MODE("System Clock Mode", 0),
3125 HDSP_PREF_SYNC_REF("Preferred Sync Reference", 0),
3126 HDSP_AUTOSYNC_REF("AutoSync Reference", 0),
3127 HDSP_SPDIF_SAMPLE_RATE("SPDIF Sample Rate", 0),
3128 HDSP_SYSTEM_SAMPLE_RATE("System Sample Rate", 0),
3129 /* 'External Rate' complies with the alsa control naming scheme */
3130 HDSP_AUTOSYNC_SAMPLE_RATE("External Rate", 0),
3131 HDSP_WC_SYNC_CHECK("Word Clock Lock Status", 0),
3132 HDSP_SPDIF_SYNC_CHECK("SPDIF Lock Status", 0),
3133 HDSP_ADATSYNC_SYNC_CHECK("ADAT Sync Lock Status", 0),
3134 HDSP_PASSTHRU("Passthru", 0),
3135 HDSP_LINE_OUT("Line Out", 0),
3138 static snd_kcontrol_new_t snd_hdsp_96xx_aeb = HDSP_AEB("Analog Extension Board", 0);
3139 static snd_kcontrol_new_t snd_hdsp_adat_sync_check = HDSP_ADAT_SYNC_CHECK;
3141 int snd_hdsp_create_controls(snd_card_t *card, hdsp_t *hdsp)
3145 snd_kcontrol_t *kctl;
3147 for (idx = 0; idx < ARRAY_SIZE(snd_hdsp_controls); idx++) {
3148 if ((err = snd_ctl_add(card, kctl = snd_ctl_new1(&snd_hdsp_controls[idx], hdsp))) < 0) {
3151 if (idx == 1) /* IEC958 (S/PDIF) Stream */
3152 hdsp->spdif_ctl = kctl;
3155 /* ADAT SyncCheck status */
3156 snd_hdsp_adat_sync_check.name = "ADAT Lock Status";
3157 snd_hdsp_adat_sync_check.index = 1;
3158 if ((err = snd_ctl_add (card, kctl = snd_ctl_new1(&snd_hdsp_adat_sync_check, hdsp)))) {
3161 if (hdsp->io_type == Digiface || hdsp->io_type == H9652) {
3162 for (idx = 1; idx < 3; ++idx) {
3163 snd_hdsp_adat_sync_check.index = idx+1;
3164 if ((err = snd_ctl_add (card, kctl = snd_ctl_new1(&snd_hdsp_adat_sync_check, hdsp)))) {
3170 /* DA, AD and Phone gain and XLR breakout cable controls for H9632 cards */
3171 if (hdsp->io_type == H9632) {
3172 for (idx = 0; idx < ARRAY_SIZE(snd_hdsp_9632_controls); idx++) {
3173 if ((err = snd_ctl_add(card, kctl = snd_ctl_new1(&snd_hdsp_9632_controls[idx], hdsp))) < 0) {
3179 /* AEB control for H96xx card */
3180 if (hdsp->io_type == H9632 || hdsp->io_type == H9652) {
3181 if ((err = snd_ctl_add(card, kctl = snd_ctl_new1(&snd_hdsp_96xx_aeb, hdsp))) < 0) {
3189 /*------------------------------------------------------------
3191 ------------------------------------------------------------*/
3194 snd_hdsp_proc_read(snd_info_entry_t *entry, snd_info_buffer_t *buffer)
3196 hdsp_t *hdsp = (hdsp_t *) entry->private_data;
3197 unsigned int status;
3198 unsigned int status2;
3199 char *pref_sync_ref;
3201 char *system_clock_mode;
3205 if (hdsp_check_for_iobox (hdsp)) {
3206 snd_iprintf(buffer, "No I/O box connected.\nPlease connect one and upload firmware.\n");
3210 if (hdsp_check_for_firmware(hdsp)) {
3211 if (hdsp->state & HDSP_FirmwareCached) {
3212 if (snd_hdsp_load_firmware_from_cache(hdsp) != 0) {
3213 snd_iprintf(buffer, "Firmware loading from cache failed, please upload manually.\n");
3217 snd_iprintf(buffer, "No firmware loaded nor cached, please upload firmware.\n");
3222 status = hdsp_read(hdsp, HDSP_statusRegister);
3223 status2 = hdsp_read(hdsp, HDSP_status2Register);
3225 snd_iprintf(buffer, "%s (Card #%d)\n", hdsp->card_name, hdsp->card->number + 1);
3226 snd_iprintf(buffer, "Buffers: capture %p playback %p\n",
3227 hdsp->capture_buffer, hdsp->playback_buffer);
3228 snd_iprintf(buffer, "IRQ: %d Registers bus: 0x%lx VM: 0x%lx\n",
3229 hdsp->irq, hdsp->port, (unsigned long)hdsp->iobase);
3230 snd_iprintf(buffer, "Control register: 0x%x\n", hdsp->control_register);
3231 snd_iprintf(buffer, "Control2 register: 0x%x\n", hdsp->control2_register);
3232 snd_iprintf(buffer, "Status register: 0x%x\n", status);
3233 snd_iprintf(buffer, "Status2 register: 0x%x\n", status2);
3234 snd_iprintf(buffer, "FIFO status: %d\n", hdsp_read(hdsp, HDSP_fifoStatus) & 0xff);
3236 snd_iprintf(buffer, "MIDI1 Output status: 0x%x\n", hdsp_read(hdsp, HDSP_midiStatusOut0));
3237 snd_iprintf(buffer, "MIDI1 Input status: 0x%x\n", hdsp_read(hdsp, HDSP_midiStatusIn0));
3238 snd_iprintf(buffer, "MIDI2 Output status: 0x%x\n", hdsp_read(hdsp, HDSP_midiStatusOut1));
3239 snd_iprintf(buffer, "MIDI2 Input status: 0x%x\n", hdsp_read(hdsp, HDSP_midiStatusIn1));
3241 snd_iprintf(buffer, "\n");
3243 x = 1 << (6 + hdsp_decode_latency(hdsp->control_register & HDSP_LatencyMask));
3245 snd_iprintf(buffer, "Buffer Size (Latency): %d samples (2 periods of %lu bytes)\n", x, (unsigned long) hdsp->period_bytes);
3246 snd_iprintf(buffer, "Hardware pointer (frames): %ld\n", hdsp_hw_pointer(hdsp));
3247 snd_iprintf(buffer, "Passthru: %s\n", hdsp->passthru ? "yes" : "no");
3248 snd_iprintf(buffer, "Line out: %s\n", (hdsp->control_register & HDSP_LineOut) ? "on" : "off");
3250 snd_iprintf(buffer, "Firmware version: %d\n", (status2&HDSP_version0)|(status2&HDSP_version1)<<1|(status2&HDSP_version2)<<2);
3252 snd_iprintf(buffer, "\n");
3255 switch (hdsp_clock_source(hdsp)) {
3256 case HDSP_CLOCK_SOURCE_AUTOSYNC:
3257 clock_source = "AutoSync";
3259 case HDSP_CLOCK_SOURCE_INTERNAL_32KHZ:
3260 clock_source = "Internal 32 kHz";
3262 case HDSP_CLOCK_SOURCE_INTERNAL_44_1KHZ:
3263 clock_source = "Internal 44.1 kHz";
3265 case HDSP_CLOCK_SOURCE_INTERNAL_48KHZ:
3266 clock_source = "Internal 48 kHz";
3268 case HDSP_CLOCK_SOURCE_INTERNAL_64KHZ:
3269 clock_source = "Internal 64 kHz";
3271 case HDSP_CLOCK_SOURCE_INTERNAL_88_2KHZ:
3272 clock_source = "Internal 88.2 kHz";
3274 case HDSP_CLOCK_SOURCE_INTERNAL_96KHZ:
3275 clock_source = "Internal 96 kHz";
3277 case HDSP_CLOCK_SOURCE_INTERNAL_128KHZ:
3278 clock_source = "Internal 128 kHz";
3280 case HDSP_CLOCK_SOURCE_INTERNAL_176_4KHZ:
3281 clock_source = "Internal 176.4 kHz";
3283 case HDSP_CLOCK_SOURCE_INTERNAL_192KHZ:
3284 clock_source = "Internal 192 kHz";
3287 clock_source = "Error";
3289 snd_iprintf (buffer, "Sample Clock Source: %s\n", clock_source);
3291 if (hdsp_system_clock_mode(hdsp)) {
3292 system_clock_mode = "Slave";
3294 system_clock_mode = "Master";
3297 switch (hdsp_pref_sync_ref (hdsp)) {
3298 case HDSP_SYNC_FROM_WORD:
3299 pref_sync_ref = "Word Clock";
3301 case HDSP_SYNC_FROM_ADAT_SYNC:
3302 pref_sync_ref = "ADAT Sync";
3304 case HDSP_SYNC_FROM_SPDIF:
3305 pref_sync_ref = "SPDIF";
3307 case HDSP_SYNC_FROM_ADAT1:
3308 pref_sync_ref = "ADAT1";
3310 case HDSP_SYNC_FROM_ADAT2:
3311 pref_sync_ref = "ADAT2";
3313 case HDSP_SYNC_FROM_ADAT3:
3314 pref_sync_ref = "ADAT3";
3317 pref_sync_ref = "Word Clock";
3320 snd_iprintf (buffer, "Preferred Sync Reference: %s\n", pref_sync_ref);
3322 switch (hdsp_autosync_ref (hdsp)) {
3323 case HDSP_AUTOSYNC_FROM_WORD:
3324 autosync_ref = "Word Clock";
3326 case HDSP_AUTOSYNC_FROM_ADAT_SYNC:
3327 autosync_ref = "ADAT Sync";
3329 case HDSP_AUTOSYNC_FROM_SPDIF:
3330 autosync_ref = "SPDIF";
3332 case HDSP_AUTOSYNC_FROM_NONE:
3333 autosync_ref = "None";
3335 case HDSP_AUTOSYNC_FROM_ADAT1:
3336 autosync_ref = "ADAT1";
3338 case HDSP_AUTOSYNC_FROM_ADAT2:
3339 autosync_ref = "ADAT2";
3341 case HDSP_AUTOSYNC_FROM_ADAT3:
3342 autosync_ref = "ADAT3";
3345 autosync_ref = "---";
3348 snd_iprintf (buffer, "AutoSync Reference: %s\n", autosync_ref);
3350 snd_iprintf (buffer, "AutoSync Frequency: %d\n", hdsp_external_sample_rate(hdsp));
3352 snd_iprintf (buffer, "System Clock Mode: %s\n", system_clock_mode);
3354 snd_iprintf (buffer, "System Clock Frequency: %d\n", hdsp->system_sample_rate);
3356 snd_iprintf(buffer, "\n");
3358 switch (hdsp_spdif_in(hdsp)) {
3359 case HDSP_SPDIFIN_OPTICAL:
3360 snd_iprintf(buffer, "IEC958 input: Optical\n");
3362 case HDSP_SPDIFIN_COAXIAL:
3363 snd_iprintf(buffer, "IEC958 input: Coaxial\n");
3365 case HDSP_SPDIFIN_INTERNAL:
3366 snd_iprintf(buffer, "IEC958 input: Internal\n");
3368 case HDSP_SPDIFIN_AES:
3369 snd_iprintf(buffer, "IEC958 input: AES\n");
3372 snd_iprintf(buffer, "IEC958 input: ???\n");
3376 if (hdsp->control_register & HDSP_SPDIFOpticalOut) {
3377 snd_iprintf(buffer, "IEC958 output: Coaxial & ADAT1\n");
3379 snd_iprintf(buffer, "IEC958 output: Coaxial only\n");
3382 if (hdsp->control_register & HDSP_SPDIFProfessional) {
3383 snd_iprintf(buffer, "IEC958 quality: Professional\n");
3385 snd_iprintf(buffer, "IEC958 quality: Consumer\n");
3388 if (hdsp->control_register & HDSP_SPDIFEmphasis) {
3389 snd_iprintf(buffer, "IEC958 emphasis: on\n");
3391 snd_iprintf(buffer, "IEC958 emphasis: off\n");
3394 if (hdsp->control_register & HDSP_SPDIFNonAudio) {
3395 snd_iprintf(buffer, "IEC958 NonAudio: on\n");
3397 snd_iprintf(buffer, "IEC958 NonAudio: off\n");
3399 if ((x = hdsp_spdif_sample_rate (hdsp)) != 0) {
3400 snd_iprintf (buffer, "IEC958 sample rate: %d\n", x);
3402 snd_iprintf (buffer, "IEC958 sample rate: Error flag set\n");
3405 snd_iprintf(buffer, "\n");
3408 x = status & HDSP_Sync0;
3409 if (status & HDSP_Lock0) {
3410 snd_iprintf(buffer, "ADAT1: %s\n", x ? "Sync" : "Lock");
3412 snd_iprintf(buffer, "ADAT1: No Lock\n");
3415 switch (hdsp->io_type) {
3418 x = status & HDSP_Sync1;
3419 if (status & HDSP_Lock1) {
3420 snd_iprintf(buffer, "ADAT2: %s\n", x ? "Sync" : "Lock");
3422 snd_iprintf(buffer, "ADAT2: No Lock\n");
3424 x = status & HDSP_Sync2;
3425 if (status & HDSP_Lock2) {
3426 snd_iprintf(buffer, "ADAT3: %s\n", x ? "Sync" : "Lock");
3428 snd_iprintf(buffer, "ADAT3: No Lock\n");
3435 x = status & HDSP_SPDIFSync;
3436 if (status & HDSP_SPDIFErrorFlag) {
3437 snd_iprintf (buffer, "SPDIF: No Lock\n");
3439 snd_iprintf (buffer, "SPDIF: %s\n", x ? "Sync" : "Lock");
3442 x = status2 & HDSP_wc_sync;
3443 if (status2 & HDSP_wc_lock) {
3444 snd_iprintf (buffer, "Word Clock: %s\n", x ? "Sync" : "Lock");
3446 snd_iprintf (buffer, "Word Clock: No Lock\n");
3449 x = status & HDSP_TimecodeSync;
3450 if (status & HDSP_TimecodeLock) {
3451 snd_iprintf(buffer, "ADAT Sync: %s\n", x ? "Sync" : "Lock");
3453 snd_iprintf(buffer, "ADAT Sync: No Lock\n");
3456 snd_iprintf(buffer, "\n");
3458 /* Informations about H9632 specific controls */
3459 if (hdsp->io_type == H9632) {
3462 switch (hdsp_ad_gain(hdsp)) {
3473 snd_iprintf(buffer, "AD Gain : %s\n", tmp);
3475 switch (hdsp_da_gain(hdsp)) {
3486 snd_iprintf(buffer, "DA Gain : %s\n", tmp);
3488 switch (hdsp_phone_gain(hdsp)) {
3499 snd_iprintf(buffer, "Phones Gain : %s\n", tmp);
3501 snd_iprintf(buffer, "XLR Breakout Cable : %s\n", hdsp_xlr_breakout_cable(hdsp) ? "yes" : "no");
3503 if (hdsp->control_register & HDSP_AnalogExtensionBoard) {
3504 snd_iprintf(buffer, "AEB : on (ADAT1 internal)\n");
3506 snd_iprintf(buffer, "AEB : off (ADAT1 external)\n");
3508 snd_iprintf(buffer, "\n");
3513 static void __devinit snd_hdsp_proc_init(hdsp_t *hdsp)
3515 snd_info_entry_t *entry;
3517 if (! snd_card_proc_new(hdsp->card, "hdsp", &entry))
3518 snd_info_set_text_ops(entry, hdsp, 1024, snd_hdsp_proc_read);
3521 static void snd_hdsp_free_buffers(hdsp_t *hdsp)
3523 snd_hammerfall_free_buffer(&hdsp->capture_dma_buf, hdsp->pci);
3524 snd_hammerfall_free_buffer(&hdsp->playback_dma_buf, hdsp->pci);
3527 static int __devinit snd_hdsp_initialize_memory(hdsp_t *hdsp)
3529 unsigned long pb_bus, cb_bus;
3531 if (snd_hammerfall_get_buffer(hdsp->pci, &hdsp->capture_dma_buf, HDSP_DMA_AREA_BYTES) < 0 ||
3532 snd_hammerfall_get_buffer(hdsp->pci, &hdsp->playback_dma_buf, HDSP_DMA_AREA_BYTES) < 0) {
3533 if (hdsp->capture_dma_buf.area)
3534 snd_dma_free_pages(&hdsp->capture_dma_buf);
3535 printk(KERN_ERR "%s: no buffers available\n", hdsp->card_name);
3539 /* Align to bus-space 64K boundary */
3541 cb_bus = (hdsp->capture_dma_buf.addr + 0xFFFF) & ~0xFFFFl;
3542 pb_bus = (hdsp->playback_dma_buf.addr + 0xFFFF) & ~0xFFFFl;
3544 /* Tell the card where it is */
3546 hdsp_write(hdsp, HDSP_inputBufferAddress, cb_bus);
3547 hdsp_write(hdsp, HDSP_outputBufferAddress, pb_bus);
3549 hdsp->capture_buffer = hdsp->capture_dma_buf.area + (cb_bus - hdsp->capture_dma_buf.addr);
3550 hdsp->playback_buffer = hdsp->playback_dma_buf.area + (pb_bus - hdsp->playback_dma_buf.addr);
3555 static int snd_hdsp_set_defaults(hdsp_t *hdsp)
3559 /* ASSUMPTION: hdsp->lock is either held, or
3560 there is no need to hold it (e.g. during module
3566 SPDIF Input via Coax
3568 maximum latency (7 => 2^7 = 8192 samples, 64Kbyte buffer,
3569 which implies 2 4096 sample, 32Kbyte periods).
3573 hdsp->control_register = HDSP_ClockModeMaster |
3574 HDSP_SPDIFInputCoaxial |
3575 hdsp_encode_latency(7) |
3579 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
3581 #ifdef SNDRV_BIG_ENDIAN
3582 hdsp->control2_register = HDSP_BIGENDIAN_MODE;
3584 hdsp->control2_register = 0;
3586 if (hdsp->io_type == H9652) {
3587 snd_hdsp_9652_enable_mixer (hdsp);
3589 hdsp_write (hdsp, HDSP_control2Reg, hdsp->control2_register);
3592 hdsp_reset_hw_pointer(hdsp);
3593 hdsp_compute_period_size(hdsp);
3595 /* silence everything */
3597 for (i = 0; i < HDSP_MATRIX_MIXER_SIZE; ++i) {
3598 hdsp->mixer_matrix[i] = MINUS_INFINITY_GAIN;
3601 for (i = 0; i < ((hdsp->io_type == H9652 || hdsp->io_type == H9632) ? 1352 : HDSP_MATRIX_MIXER_SIZE); ++i) {
3602 if (hdsp_write_gain (hdsp, i, MINUS_INFINITY_GAIN)) {
3607 if ((hdsp->io_type != H9652) && line_outs_monitor[hdsp->dev]) {
3611 snd_printk ("sending all inputs and playback streams to line outs.\n");
3613 /* route all inputs to the line outs for easy monitoring. send
3614 odd numbered channels to right, even to left.
3616 if (hdsp->io_type == H9632) {
3617 /* this is the phones/analog output */
3623 for (i = 0; i < hdsp->max_channels; i++) {
3625 if (hdsp_write_gain (hdsp, hdsp_input_to_output_key (hdsp, i, lineouts_base), UNITY_GAIN) ||
3626 hdsp_write_gain (hdsp, hdsp_playback_to_output_key (hdsp, i, lineouts_base), UNITY_GAIN)) {
3630 if (hdsp_write_gain (hdsp, hdsp_input_to_output_key (hdsp, i, lineouts_base+1), UNITY_GAIN) ||
3631 hdsp_write_gain (hdsp, hdsp_playback_to_output_key (hdsp, i, lineouts_base+1), UNITY_GAIN)) {
3641 /* H9632 specific defaults */
3642 if (hdsp->io_type == H9632) {
3643 hdsp->control_register |= (HDSP_DAGainPlus4dBu | HDSP_ADGainPlus4dBu | HDSP_PhoneGain0dB);
3644 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
3647 /* set a default rate so that the channel map is set up.
3650 hdsp_set_rate(hdsp, 48000, 1);
3655 void hdsp_midi_tasklet(unsigned long arg)
3657 hdsp_t *hdsp = (hdsp_t *)arg;
3659 if (hdsp->midi[0].pending) {
3660 snd_hdsp_midi_input_read (&hdsp->midi[0]);
3662 if (hdsp->midi[1].pending) {
3663 snd_hdsp_midi_input_read (&hdsp->midi[1]);
3667 static irqreturn_t snd_hdsp_interrupt(int irq, void *dev_id, struct pt_regs *regs)
3669 hdsp_t *hdsp = (hdsp_t *) dev_id;
3670 unsigned int status;
3674 unsigned int midi0status;
3675 unsigned int midi1status;
3678 status = hdsp_read(hdsp, HDSP_statusRegister);
3680 audio = status & HDSP_audioIRQPending;
3681 midi0 = status & HDSP_midi0IRQPending;
3682 midi1 = status & HDSP_midi1IRQPending;
3684 if (!audio && !midi0 && !midi1) {
3688 hdsp_write(hdsp, HDSP_interruptConfirmation, 0);
3690 midi0status = hdsp_read (hdsp, HDSP_midiStatusIn0) & 0xff;
3691 midi1status = hdsp_read (hdsp, HDSP_midiStatusIn1) & 0xff;
3694 if (hdsp->capture_substream) {
3695 snd_pcm_period_elapsed(hdsp->pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream);
3698 if (hdsp->playback_substream) {
3699 snd_pcm_period_elapsed(hdsp->pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream);
3703 if (midi0 && midi0status) {
3704 /* we disable interrupts for this input until processing is done */
3705 hdsp->control_register &= ~HDSP_Midi0InterruptEnable;
3706 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
3707 hdsp->midi[0].pending = 1;
3710 if (midi1 && midi1status) {
3711 /* we disable interrupts for this input until processing is done */
3712 hdsp->control_register &= ~HDSP_Midi1InterruptEnable;
3713 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register);
3714 hdsp->midi[1].pending = 1;
3718 tasklet_hi_schedule(&hdsp->midi_tasklet);
3722 static snd_pcm_uframes_t snd_hdsp_hw_pointer(snd_pcm_substream_t *substream)
3724 hdsp_t *hdsp = snd_pcm_substream_chip(substream);
3725 return hdsp_hw_pointer(hdsp);
3728 static char *hdsp_channel_buffer_location(hdsp_t *hdsp,
3735 snd_assert(channel >= 0 && channel < hdsp->max_channels, return NULL);
3737 if ((mapped_channel = hdsp->channel_map[channel]) < 0) {
3741 if (stream == SNDRV_PCM_STREAM_CAPTURE) {
3742 return hdsp->capture_buffer + (mapped_channel * HDSP_CHANNEL_BUFFER_BYTES);
3744 return hdsp->playback_buffer + (mapped_channel * HDSP_CHANNEL_BUFFER_BYTES);
3748 static int snd_hdsp_playback_copy(snd_pcm_substream_t *substream, int channel,
3749 snd_pcm_uframes_t pos, void __user *src, snd_pcm_uframes_t count)
3751 hdsp_t *hdsp = snd_pcm_substream_chip(substream);
3754 snd_assert(pos + count <= HDSP_CHANNEL_BUFFER_BYTES / 4, return -EINVAL);
3756 channel_buf = hdsp_channel_buffer_location (hdsp, substream->pstr->stream, channel);
3757 snd_assert(channel_buf != NULL, return -EIO);
3758 if (copy_from_user(channel_buf + pos * 4, src, count * 4))
3763 static int snd_hdsp_capture_copy(snd_pcm_substream_t *substream, int channel,
3764 snd_pcm_uframes_t pos, void __user *dst, snd_pcm_uframes_t count)
3766 hdsp_t *hdsp = snd_pcm_substream_chip(substream);
3769 snd_assert(pos + count <= HDSP_CHANNEL_BUFFER_BYTES / 4, return -EINVAL);
3771 channel_buf = hdsp_channel_buffer_location (hdsp, substream->pstr->stream, channel);
3772 snd_assert(channel_buf != NULL, return -EIO);
3773 if (copy_to_user(dst, channel_buf + pos * 4, count * 4))
3778 static int snd_hdsp_hw_silence(snd_pcm_substream_t *substream, int channel,
3779 snd_pcm_uframes_t pos, snd_pcm_uframes_t count)
3781 hdsp_t *hdsp = snd_pcm_substream_chip(substream);
3784 channel_buf = hdsp_channel_buffer_location (hdsp, substream->pstr->stream, channel);
3785 snd_assert(channel_buf != NULL, return -EIO);
3786 memset(channel_buf + pos * 4, 0, count * 4);
3790 static int snd_hdsp_reset(snd_pcm_substream_t *substream)
3792 snd_pcm_runtime_t *runtime = substream->runtime;
3793 hdsp_t *hdsp = snd_pcm_substream_chip(substream);
3794 snd_pcm_substream_t *other;
3795 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
3796 other = hdsp->capture_substream;
3798 other = hdsp->playback_substream;
3800 runtime->status->hw_ptr = hdsp_hw_pointer(hdsp);
3802 runtime->status->hw_ptr = 0;
3804 struct list_head *pos;
3805 snd_pcm_substream_t *s;
3806 snd_pcm_runtime_t *oruntime = other->runtime;
3807 snd_pcm_group_for_each(pos, substream) {
3808 s = snd_pcm_group_substream_entry(pos);
3810 oruntime->status->hw_ptr = runtime->status->hw_ptr;
3818 static int snd_hdsp_hw_params(snd_pcm_substream_t *substream,
3819 snd_pcm_hw_params_t *params)
3821 hdsp_t *hdsp = snd_pcm_substream_chip(substream);
3826 if (hdsp_check_for_iobox (hdsp)) {
3830 if (hdsp_check_for_firmware(hdsp)) {
3831 if (hdsp->state & HDSP_FirmwareCached) {
3832 if (snd_hdsp_load_firmware_from_cache(hdsp) != 0) {
3833 snd_printk("Firmware loading from cache failed, please upload manually.\n");
3836 snd_printk("No firmware loaded nor cached, please upload firmware.\n");
3841 spin_lock_irq(&hdsp->lock);
3843 if (substream->pstr->stream == SNDRV_PCM_STREAM_PLAYBACK) {
3844 hdsp->control_register &= ~(HDSP_SPDIFProfessional | HDSP_SPDIFNonAudio | HDSP_SPDIFEmphasis);
3845 hdsp_write(hdsp, HDSP_controlRegister, hdsp->control_register |= hdsp->creg_spdif_stream);
3846 this_pid = hdsp->playback_pid;
3847 other_pid = hdsp->capture_pid;
3849 this_pid = hdsp->capture_pid;
3850 other_pid = hdsp->playback_pid;
3853 if ((other_pid > 0) && (this_pid != other_pid)) {
3855 /* The other stream is open, and not by the same
3856 task as this one. Make sure that the parameters
3857 that matter are the same.
3860 if (params_rate(params) != hdsp->system_sample_rate) {
3861 spin_unlock_irq(&hdsp->lock);
3862 _snd_pcm_hw_param_setempty(params, SNDRV_PCM_HW_PARAM_RATE);
3866 if (params_period_size(params) != hdsp->period_bytes / 4) {
3867 spin_unlock_irq(&hdsp->lock);
3868 _snd_pcm_hw_param_setempty(params, SNDRV_PCM_HW_PARAM_PERIOD_SIZE);
3874 spin_unlock_irq(&hdsp->lock);
3878 spin_unlock_irq(&hdsp->lock);
3881 /* how to make sure that the rate matches an externally-set one ?
3884 spin_lock_irq(&hdsp->lock);
3885 if ((err = hdsp_set_rate(hdsp, params_rate(params), 0)) < 0) {
3886 spin_unlock_irq(&hdsp->lock);
3887 _snd_pcm_hw_param_setempty(params, SNDRV_PCM_HW_PARAM_RATE);
3890 spin_unlock_irq(&hdsp->lock);
3893 if ((err = hdsp_set_interrupt_interval(hdsp, params_period_size(params))) < 0) {
3894 _snd_pcm_hw_param_setempty(params, SNDRV_PCM_HW_PARAM_PERIOD_SIZE);
3901 static int snd_hdsp_channel_info(snd_pcm_substream_t *substream,
3902 snd_pcm_channel_info_t *info)
3904 hdsp_t *hdsp = snd_pcm_substream_chip(substream);
3907 snd_assert(info->channel < hdsp->max_channels, return -EINVAL);
3909 if ((mapped_channel = hdsp->channel_map[info->channel]) < 0) {
3913 info->offset = mapped_channel * HDSP_CHANNEL_BUFFER_BYTES;
3919 static int snd_hdsp_ioctl(snd_pcm_substream_t *substream,
3920 unsigned int cmd, void *arg)
3923 case SNDRV_PCM_IOCTL1_RESET:
3925 return snd_hdsp_reset(substream);
3927 case SNDRV_PCM_IOCTL1_CHANNEL_INFO:
3929 snd_pcm_channel_info_t *info = arg;
3930 return snd_hdsp_channel_info(substream, info);
3936 return snd_pcm_lib_ioctl(substream, cmd, arg);
3939 static int snd_hdsp_trigger(snd_pcm_substream_t *substream, int cmd)
3941 hdsp_t *hdsp = snd_pcm_substream_chip(substream);
3942 snd_pcm_substream_t *other;
3945 if (hdsp_check_for_iobox (hdsp)) {
3949 if (hdsp_check_for_firmware(hdsp)) {
3950 if (hdsp->state & HDSP_FirmwareCached) {
3951 if (snd_hdsp_load_firmware_from_cache(hdsp) != 0) {
3952 snd_printk("Firmware loading from cache failed, please upload manually.\n");
3955 snd_printk("No firmware loaded nor cached, please upload firmware.\n");
3960 spin_lock(&hdsp->lock);
3961 running = hdsp->running;
3963 case SNDRV_PCM_TRIGGER_START:
3964 running |= 1 << substream->stream;
3966 case SNDRV_PCM_TRIGGER_STOP:
3967 running &= ~(1 << substream->stream);
3971 spin_unlock(&hdsp->lock);
3974 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
3975 other = hdsp->capture_substream;
3977 other = hdsp->playback_substream;
3980 struct list_head *pos;
3981 snd_pcm_substream_t *s;
3982 snd_pcm_group_for_each(pos, substream) {
3983 s = snd_pcm_group_substream_entry(pos);
3985 snd_pcm_trigger_done(s, substream);
3986 if (cmd == SNDRV_PCM_TRIGGER_START)
3987 running |= 1 << s->stream;
3989 running &= ~(1 << s->stream);
3993 if (cmd == SNDRV_PCM_TRIGGER_START) {
3994 if (!(running & (1 << SNDRV_PCM_STREAM_PLAYBACK)) &&
3995 substream->stream == SNDRV_PCM_STREAM_CAPTURE)
3996 hdsp_silence_playback(hdsp);
3999 substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
4000 hdsp_silence_playback(hdsp);
4003 if (substream->stream == SNDRV_PCM_STREAM_CAPTURE)
4004 hdsp_silence_playback(hdsp);
4007 snd_pcm_trigger_done(substream, substream);
4008 if (!hdsp->running && running)
4009 hdsp_start_audio(hdsp);
4010 else if (hdsp->running && !running)
4011 hdsp_stop_audio(hdsp);
4012 hdsp->running = running;
4013 spin_unlock(&hdsp->lock);
4018 static int snd_hdsp_prepare(snd_pcm_substream_t *substream)
4020 hdsp_t *hdsp = snd_pcm_substream_chip(substream);
4023 if (hdsp_check_for_iobox (hdsp)) {
4027 if (hdsp_check_for_firmware(hdsp)) {
4028 if (hdsp->state & HDSP_FirmwareCached) {
4029 if (snd_hdsp_load_firmware_from_cache(hdsp) != 0) {
4030 snd_printk("Firmware loading from cache failed, please upload manually.\n");
4033 snd_printk("No firmware loaded nor cached, please upload firmware.\n");
4038 spin_lock_irq(&hdsp->lock);
4040 hdsp_reset_hw_pointer(hdsp);
4041 spin_unlock_irq(&hdsp->lock);
4045 static snd_pcm_hardware_t snd_hdsp_playback_subinfo =
4047 .info = (SNDRV_PCM_INFO_MMAP |
4048 SNDRV_PCM_INFO_MMAP_VALID |
4049 SNDRV_PCM_INFO_NONINTERLEAVED |
4050 SNDRV_PCM_INFO_SYNC_START |
4051 SNDRV_PCM_INFO_DOUBLE),
4052 .formats = SNDRV_PCM_FMTBIT_S32_LE,
4053 .rates = (SNDRV_PCM_RATE_32000 |
4054 SNDRV_PCM_RATE_44100 |
4055 SNDRV_PCM_RATE_48000 |
4056 SNDRV_PCM_RATE_64000 |
4057 SNDRV_PCM_RATE_88200 |
4058 SNDRV_PCM_RATE_96000),
4062 .channels_max = HDSP_MAX_CHANNELS,
4063 .buffer_bytes_max = HDSP_CHANNEL_BUFFER_BYTES * HDSP_MAX_CHANNELS,
4064 .period_bytes_min = (64 * 4) * 10,
4065 .period_bytes_max = (8192 * 4) * HDSP_MAX_CHANNELS,
4071 static snd_pcm_hardware_t snd_hdsp_capture_subinfo =
4073 .info = (SNDRV_PCM_INFO_MMAP |
4074 SNDRV_PCM_INFO_MMAP_VALID |
4075 SNDRV_PCM_INFO_NONINTERLEAVED |
4076 SNDRV_PCM_INFO_SYNC_START),
4077 .formats = SNDRV_PCM_FMTBIT_S32_LE,
4078 .rates = (SNDRV_PCM_RATE_32000 |
4079 SNDRV_PCM_RATE_44100 |
4080 SNDRV_PCM_RATE_48000 |
4081 SNDRV_PCM_RATE_64000 |
4082 SNDRV_PCM_RATE_88200 |
4083 SNDRV_PCM_RATE_96000),
4087 .channels_max = HDSP_MAX_CHANNELS,
4088 .buffer_bytes_max = HDSP_CHANNEL_BUFFER_BYTES * HDSP_MAX_CHANNELS,
4089 .period_bytes_min = (64 * 4) * 10,
4090 .period_bytes_max = (8192 * 4) * HDSP_MAX_CHANNELS,
4096 static unsigned int hdsp_period_sizes[] = { 64, 128, 256, 512, 1024, 2048, 4096, 8192 };
4098 static snd_pcm_hw_constraint_list_t hdsp_hw_constraints_period_sizes = {
4099 .count = ARRAY_SIZE(hdsp_period_sizes),
4100 .list = hdsp_period_sizes,
4104 static unsigned int hdsp_9632_sample_rates[] = { 32000, 44100, 48000, 64000, 88200, 96000, 128000, 176400, 192000 };
4106 static snd_pcm_hw_constraint_list_t hdsp_hw_constraints_9632_sample_rates = {
4107 .count = ARRAY_SIZE(hdsp_9632_sample_rates),
4108 .list = hdsp_9632_sample_rates,
4112 static int snd_hdsp_hw_rule_in_channels(snd_pcm_hw_params_t *params,
4113 snd_pcm_hw_rule_t *rule)
4115 hdsp_t *hdsp = rule->private;
4116 snd_interval_t *c = hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS);
4117 if (hdsp->io_type == H9632) {
4118 unsigned int list[3];
4119 list[0] = hdsp->qs_in_channels;
4120 list[1] = hdsp->ds_in_channels;
4121 list[2] = hdsp->ss_in_channels;
4122 return snd_interval_list(c, 3, list, 0);
4124 unsigned int list[2];
4125 list[0] = hdsp->ds_in_channels;
4126 list[1] = hdsp->ss_in_channels;
4127 return snd_interval_list(c, 2, list, 0);
4131 static int snd_hdsp_hw_rule_out_channels(snd_pcm_hw_params_t *params,
4132 snd_pcm_hw_rule_t *rule)
4134 unsigned int list[3];
4135 hdsp_t *hdsp = rule->private;
4136 snd_interval_t *c = hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS);
4137 if (hdsp->io_type == H9632) {
4138 list[0] = hdsp->qs_out_channels;
4139 list[1] = hdsp->ds_out_channels;
4140 list[2] = hdsp->ss_out_channels;
4141 return snd_interval_list(c, 3, list, 0);
4143 list[0] = hdsp->ds_out_channels;
4144 list[1] = hdsp->ss_out_channels;
4146 return snd_interval_list(c, 2, list, 0);
4149 static int snd_hdsp_hw_rule_in_channels_rate(snd_pcm_hw_params_t *params,
4150 snd_pcm_hw_rule_t *rule)
4152 hdsp_t *hdsp = rule->private;
4153 snd_interval_t *c = hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS);
4154 snd_interval_t *r = hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE);
4155 if (r->min > 96000 && hdsp->io_type == H9632) {
4156 snd_interval_t t = {
4157 .min = hdsp->qs_in_channels,
4158 .max = hdsp->qs_in_channels,
4161 return snd_interval_refine(c, &t);
4162 } else if (r->min > 48000 && r->max <= 96000) {
4163 snd_interval_t t = {
4164 .min = hdsp->ds_in_channels,
4165 .max = hdsp->ds_in_channels,
4168 return snd_interval_refine(c, &t);
4169 } else if (r->max < 64000) {
4170 snd_interval_t t = {
4171 .min = hdsp->ss_in_channels,
4172 .max = hdsp->ss_in_channels,
4175 return snd_interval_refine(c, &t);
4180 static int snd_hdsp_hw_rule_out_channels_rate(snd_pcm_hw_params_t *params,
4181 snd_pcm_hw_rule_t *rule)
4183 hdsp_t *hdsp = rule->private;
4184 snd_interval_t *c = hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS);
4185 snd_interval_t *r = hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE);
4186 if (r->min > 96000 && hdsp->io_type == H9632) {
4187 snd_interval_t t = {
4188 .min = hdsp->qs_out_channels,
4189 .max = hdsp->qs_out_channels,
4192 return snd_interval_refine(c, &t);
4193 } else if (r->min > 48000 && r->max <= 96000) {
4194 snd_interval_t t = {
4195 .min = hdsp->ds_out_channels,
4196 .max = hdsp->ds_out_channels,
4199 return snd_interval_refine(c, &t);
4200 } else if (r->max < 64000) {
4201 snd_interval_t t = {
4202 .min = hdsp->ss_out_channels,
4203 .max = hdsp->ss_out_channels,
4206 return snd_interval_refine(c, &t);
4211 static int snd_hdsp_hw_rule_rate_out_channels(snd_pcm_hw_params_t *params,
4212 snd_pcm_hw_rule_t *rule)
4214 hdsp_t *hdsp = rule->private;
4215 snd_interval_t *c = hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS);
4216 snd_interval_t *r = hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE);
4217 if (c->min >= hdsp->ss_out_channels) {
4218 snd_interval_t t = {
4223 return snd_interval_refine(r, &t);
4224 } else if (c->max <= hdsp->qs_out_channels && hdsp->io_type == H9632) {
4225 snd_interval_t t = {
4230 return snd_interval_refine(r, &t);
4231 } else if (c->max <= hdsp->ds_out_channels) {
4232 snd_interval_t t = {
4237 return snd_interval_refine(r, &t);
4242 static int snd_hdsp_hw_rule_rate_in_channels(snd_pcm_hw_params_t *params,
4243 snd_pcm_hw_rule_t *rule)
4245 hdsp_t *hdsp = rule->private;
4246 snd_interval_t *c = hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS);
4247 snd_interval_t *r = hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE);
4248 if (c->min >= hdsp->ss_in_channels) {
4249 snd_interval_t t = {
4254 return snd_interval_refine(r, &t);
4255 } else if (c->max <= hdsp->qs_in_channels && hdsp->io_type == H9632) {
4256 snd_interval_t t = {
4261 return snd_interval_refine(r, &t);
4262 } else if (c->max <= hdsp->ds_in_channels) {
4263 snd_interval_t t = {
4268 return snd_interval_refine(r, &t);
4273 static int snd_hdsp_playback_open(snd_pcm_substream_t *substream)
4275 hdsp_t *hdsp = snd_pcm_substream_chip(substream);
4276 snd_pcm_runtime_t *runtime = substream->runtime;
4278 if (hdsp_check_for_iobox (hdsp)) {
4282 if (hdsp_check_for_firmware(hdsp)) {
4283 if (hdsp->state & HDSP_FirmwareCached) {
4284 if (snd_hdsp_load_firmware_from_cache(hdsp) != 0) {
4285 snd_printk("Firmware loading from cache failed, please upload manually.\n");
4288 snd_printk("No firmware loaded nor cached, please upload firmware.\n");
4293 spin_lock_irq(&hdsp->lock);
4295 snd_pcm_set_sync(substream);
4297 runtime->hw = snd_hdsp_playback_subinfo;
4298 runtime->dma_area = hdsp->playback_buffer;
4299 runtime->dma_bytes = HDSP_DMA_AREA_BYTES;
4301 if (hdsp->capture_substream == NULL) {
4302 hdsp_stop_audio(hdsp);
4303 hdsp_set_thru(hdsp, -1, 0);
4306 hdsp->playback_pid = current->pid;
4307 hdsp->playback_substream = substream;
4309 spin_unlock_irq(&hdsp->lock);
4311 snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24);
4312 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_SIZE, &hdsp_hw_constraints_period_sizes);
4313 if (hdsp->io_type == H9632) {
4314 runtime->hw.channels_min = hdsp->qs_out_channels;
4315 runtime->hw.channels_max = hdsp->ss_out_channels;
4316 runtime->hw.rate_max = 192000;
4317 runtime->hw.rates = SNDRV_PCM_RATE_KNOT;
4318 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, &hdsp_hw_constraints_9632_sample_rates);
4321 snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
4322 snd_hdsp_hw_rule_out_channels, hdsp,
4323 SNDRV_PCM_HW_PARAM_CHANNELS, -1);
4324 snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
4325 snd_hdsp_hw_rule_out_channels_rate, hdsp,
4326 SNDRV_PCM_HW_PARAM_RATE, -1);
4327 snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
4328 snd_hdsp_hw_rule_rate_out_channels, hdsp,
4329 SNDRV_PCM_HW_PARAM_CHANNELS, -1);
4331 hdsp->creg_spdif_stream = hdsp->creg_spdif;
4332 hdsp->spdif_ctl->vd[0].access &= ~SNDRV_CTL_ELEM_ACCESS_INACTIVE;
4333 snd_ctl_notify(hdsp->card, SNDRV_CTL_EVENT_MASK_VALUE |
4334 SNDRV_CTL_EVENT_MASK_INFO, &hdsp->spdif_ctl->id);
4338 static int snd_hdsp_playback_release(snd_pcm_substream_t *substream)
4340 hdsp_t *hdsp = snd_pcm_substream_chip(substream);
4342 spin_lock_irq(&hdsp->lock);
4344 hdsp->playback_pid = -1;
4345 hdsp->playback_substream = NULL;
4347 spin_unlock_irq(&hdsp->lock);
4349 hdsp->spdif_ctl->vd[0].access |= SNDRV_CTL_ELEM_ACCESS_INACTIVE;
4350 snd_ctl_notify(hdsp->card, SNDRV_CTL_EVENT_MASK_VALUE |
4351 SNDRV_CTL_EVENT_MASK_INFO, &hdsp->spdif_ctl->id);
4356 static int snd_hdsp_capture_open(snd_pcm_substream_t *substream)
4358 hdsp_t *hdsp = snd_pcm_substream_chip(substream);
4359 snd_pcm_runtime_t *runtime = substream->runtime;
4361 if (hdsp_check_for_iobox (hdsp)) {
4365 if (hdsp_check_for_firmware(hdsp)) {
4366 if (hdsp->state & HDSP_FirmwareCached) {
4367 if (snd_hdsp_load_firmware_from_cache(hdsp) != 0) {
4368 snd_printk("Firmware loading from cache failed, please upload manually.\n");
4371 snd_printk("No firmware loaded nor cached, please upload firmware.\n");
4376 spin_lock_irq(&hdsp->lock);
4378 snd_pcm_set_sync(substream);
4380 runtime->hw = snd_hdsp_capture_subinfo;
4381 runtime->dma_area = hdsp->capture_buffer;
4382 runtime->dma_bytes = HDSP_DMA_AREA_BYTES;
4384 if (hdsp->playback_substream == NULL) {
4385 hdsp_stop_audio(hdsp);
4386 hdsp_set_thru(hdsp, -1, 0);
4389 hdsp->capture_pid = current->pid;
4390 hdsp->capture_substream = substream;
4392 spin_unlock_irq(&hdsp->lock);
4394 snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24);
4395 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_SIZE, &hdsp_hw_constraints_period_sizes);
4396 if (hdsp->io_type == H9632) {
4397 runtime->hw.channels_min = hdsp->qs_in_channels;
4398 runtime->hw.channels_max = hdsp->ss_in_channels;
4399 runtime->hw.rate_max = 192000;
4400 runtime->hw.rates = SNDRV_PCM_RATE_KNOT;
4401 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, &hdsp_hw_constraints_9632_sample_rates);
4403 snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
4404 snd_hdsp_hw_rule_in_channels, hdsp,
4405 SNDRV_PCM_HW_PARAM_CHANNELS, -1);
4406 snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
4407 snd_hdsp_hw_rule_in_channels_rate, hdsp,
4408 SNDRV_PCM_HW_PARAM_RATE, -1);
4409 snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
4410 snd_hdsp_hw_rule_rate_in_channels, hdsp,
4411 SNDRV_PCM_HW_PARAM_CHANNELS, -1);
4415 static int snd_hdsp_capture_release(snd_pcm_substream_t *substream)
4417 hdsp_t *hdsp = snd_pcm_substream_chip(substream);
4419 spin_lock_irq(&hdsp->lock);
4421 hdsp->capture_pid = -1;
4422 hdsp->capture_substream = NULL;
4424 spin_unlock_irq(&hdsp->lock);
4428 static int snd_hdsp_hwdep_dummy_op(snd_hwdep_t *hw, struct file *file)
4430 /* we have nothing to initialize but the call is required */
4435 /* helper functions for copying meter values */
4436 static inline int copy_u32_le(void __user *dest, void __iomem *src)
4438 u32 val = readl(src);
4439 return copy_to_user(dest, &val, 4);
4442 static inline int copy_u64_le(void __user *dest, void __iomem *src_low, void __iomem *src_high)
4444 u32 rms_low, rms_high;
4446 rms_low = readl(src_low);
4447 rms_high = readl(src_high);
4448 rms = ((u64)rms_high << 32) | rms_low;
4449 return copy_to_user(dest, &rms, 8);
4452 static inline int copy_u48_le(void __user *dest, void __iomem *src_low, void __iomem *src_high)
4454 u32 rms_low, rms_high;
4456 rms_low = readl(src_low) & 0xffffff00;
4457 rms_high = readl(src_high) & 0xffffff00;
4458 rms = ((u64)rms_high << 32) | rms_low;
4459 return copy_to_user(dest, &rms, 8);
4462 static int hdsp_9652_get_peak(hdsp_t *hdsp, hdsp_peak_rms_t __user *peak_rms)
4464 int doublespeed = 0;
4465 int i, j, channels, ofs;
4467 if (hdsp_read (hdsp, HDSP_statusRegister) & HDSP_DoubleSpeedStatus)
4469 channels = doublespeed ? 14 : 26;
4470 for (i = 0, j = 0; i < 26; ++i) {
4471 if (doublespeed && (i & 4))
4473 ofs = HDSP_9652_peakBase - j * 4;
4474 if (copy_u32_le(&peak_rms->input_peaks[i], hdsp->iobase + ofs))
4476 ofs -= channels * 4;
4477 if (copy_u32_le(&peak_rms->playback_peaks[i], hdsp->iobase + ofs))
4479 ofs -= channels * 4;
4480 if (copy_u32_le(&peak_rms->output_peaks[i], hdsp->iobase + ofs))
4482 ofs = HDSP_9652_rmsBase + j * 8;
4483 if (copy_u48_le(&peak_rms->input_rms[i], hdsp->iobase + ofs,
4484 hdsp->iobase + ofs + 4))
4486 ofs += channels * 8;
4487 if (copy_u48_le(&peak_rms->playback_rms[i], hdsp->iobase + ofs,
4488 hdsp->iobase + ofs + 4))
4490 ofs += channels * 8;
4491 if (copy_u48_le(&peak_rms->output_rms[i], hdsp->iobase + ofs,
4492 hdsp->iobase + ofs + 4))
4499 static int hdsp_9632_get_peak(hdsp_t *hdsp, hdsp_peak_rms_t __user *peak_rms)
4502 hdsp_9632_meters_t __iomem *m;
4503 int doublespeed = 0;
4505 if (hdsp_read (hdsp, HDSP_statusRegister) & HDSP_DoubleSpeedStatus)
4507 m = (hdsp_9632_meters_t __iomem *)(hdsp->iobase+HDSP_9632_metersBase);
4508 for (i = 0, j = 0; i < 16; ++i, ++j) {
4509 if (copy_u32_le(&peak_rms->input_peaks[i], &m->input_peak[j]))
4511 if (copy_u32_le(&peak_rms->playback_peaks[i], &m->playback_peak[j]))
4513 if (copy_u32_le(&peak_rms->output_peaks[i], &m->output_peak[j]))
4515 if (copy_u64_le(&peak_rms->input_rms[i], &m->input_rms_low[j],
4516 &m->input_rms_high[j]))
4518 if (copy_u64_le(&peak_rms->playback_rms[i], &m->playback_rms_low[j],
4519 &m->playback_rms_high[j]))
4521 if (copy_u64_le(&peak_rms->output_rms[i], &m->output_rms_low[j],
4522 &m->output_rms_high[j]))
4524 if (doublespeed && i == 3) i += 4;
4529 static int hdsp_get_peak(hdsp_t *hdsp, hdsp_peak_rms_t __user *peak_rms)
4533 for (i = 0; i < 26; i++) {
4534 if (copy_u32_le(&peak_rms->playback_peaks[i],
4535 hdsp->iobase + HDSP_playbackPeakLevel + i * 4))
4537 if (copy_u32_le(&peak_rms->input_peaks[i],
4538 hdsp->iobase + HDSP_inputPeakLevel + i * 4))
4541 for (i = 0; i < 28; i++) {
4542 if (copy_u32_le(&peak_rms->output_peaks[i],
4543 hdsp->iobase + HDSP_outputPeakLevel + i * 4))
4546 for (i = 0; i < 26; ++i) {
4547 if (copy_u64_le(&peak_rms->playback_rms[i],
4548 hdsp->iobase + HDSP_playbackRmsLevel + i * 8,
4549 hdsp->iobase + HDSP_playbackRmsLevel + i * 8 + 4))
4551 if (copy_u64_le(&peak_rms->input_rms[i],
4552 hdsp->iobase + HDSP_inputRmsLevel + i * 8,
4553 hdsp->iobase + HDSP_inputRmsLevel + i * 8 + 4))
4559 static int snd_hdsp_hwdep_ioctl(snd_hwdep_t *hw, struct file *file, unsigned int cmd, unsigned long arg)
4561 hdsp_t *hdsp = (hdsp_t *)hw->private_data;
4562 void __user *argp = (void __user *)arg;
4565 case SNDRV_HDSP_IOCTL_GET_PEAK_RMS: {
4566 hdsp_peak_rms_t __user *peak_rms = (hdsp_peak_rms_t __user *)arg;
4568 if (!(hdsp->state & HDSP_FirmwareLoaded)) {
4569 snd_printk(KERN_ERR "firmware needs to be uploaded to the card.\n");
4573 switch (hdsp->io_type) {
4575 return hdsp_9652_get_peak(hdsp, peak_rms);
4577 return hdsp_9632_get_peak(hdsp, peak_rms);
4579 return hdsp_get_peak(hdsp, peak_rms);
4582 case SNDRV_HDSP_IOCTL_GET_CONFIG_INFO: {
4583 hdsp_config_info_t info;
4584 unsigned long flags;
4587 if (!(hdsp->state & HDSP_FirmwareLoaded)) {
4588 snd_printk("Firmware needs to be uploaded to the card.\n");
4591 spin_lock_irqsave(&hdsp->lock, flags);
4592 info.pref_sync_ref = (unsigned char)hdsp_pref_sync_ref(hdsp);
4593 info.wordclock_sync_check = (unsigned char)hdsp_wc_sync_check(hdsp);
4594 if (hdsp->io_type != H9632) {
4595 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);
4601 info.spdif_in = (unsigned char)hdsp_spdif_in(hdsp);
4602 info.spdif_out = (unsigned char)hdsp_spdif_out(hdsp);
4603 info.spdif_professional = (unsigned char)hdsp_spdif_professional(hdsp);
4604 info.spdif_emphasis = (unsigned char)hdsp_spdif_emphasis(hdsp);
4605 info.spdif_nonaudio = (unsigned char)hdsp_spdif_nonaudio(hdsp);
4606 info.spdif_sample_rate = hdsp_spdif_sample_rate(hdsp);
4607 info.system_sample_rate = hdsp->system_sample_rate;
4608 info.autosync_sample_rate = hdsp_external_sample_rate(hdsp);
4609 info.system_clock_mode = (unsigned char)hdsp_system_clock_mode(hdsp);
4610 info.clock_source = (unsigned char)hdsp_clock_source(hdsp);
4611 info.autosync_ref = (unsigned char)hdsp_autosync_ref(hdsp);
4612 info.line_out = (unsigned char)hdsp_line_out(hdsp);
4613 info.passthru = (unsigned char)hdsp->passthru;
4614 if (hdsp->io_type == H9632) {
4615 info.da_gain = (unsigned char)hdsp_da_gain(hdsp);
4616 info.ad_gain = (unsigned char)hdsp_ad_gain(hdsp);
4617 info.phone_gain = (unsigned char)hdsp_phone_gain(hdsp);
4618 info.xlr_breakout_cable = (unsigned char)hdsp_xlr_breakout_cable(hdsp);
4621 if (hdsp->io_type == H9632 || hdsp->io_type == H9652) {
4622 info.analog_extension_board = (unsigned char)hdsp_aeb(hdsp);
4624 spin_unlock_irqrestore(&hdsp->lock, flags);
4625 if (copy_to_user(argp, &info, sizeof(info)))
4629 case SNDRV_HDSP_IOCTL_GET_9632_AEB: {
4630 hdsp_9632_aeb_t h9632_aeb;
4632 if (hdsp->io_type != H9632) return -EINVAL;
4633 h9632_aeb.aebi = hdsp->ss_in_channels - H9632_SS_CHANNELS;
4634 h9632_aeb.aebo = hdsp->ss_out_channels - H9632_SS_CHANNELS;
4635 if (copy_to_user(argp, &h9632_aeb, sizeof(h9632_aeb)))
4639 case SNDRV_HDSP_IOCTL_GET_VERSION: {
4640 hdsp_version_t hdsp_version;
4643 if (hdsp->io_type == H9652 || hdsp->io_type == H9632) return -EINVAL;
4644 if (hdsp->io_type == Undefined) {
4645 if ((err = hdsp_get_iobox_version(hdsp)) < 0) {
4649 hdsp_version.io_type = hdsp->io_type;
4650 hdsp_version.firmware_rev = hdsp->firmware_rev;
4651 if ((err = copy_to_user(argp, &hdsp_version, sizeof(hdsp_version)))) {
4656 case SNDRV_HDSP_IOCTL_UPLOAD_FIRMWARE: {
4657 hdsp_firmware_t __user *firmware;
4658 u32 __user *firmware_data;
4661 if (hdsp->io_type == H9652 || hdsp->io_type == H9632) return -EINVAL;
4662 /* SNDRV_HDSP_IOCTL_GET_VERSION must have been called */
4663 if (hdsp->io_type == Undefined) return -EINVAL;
4665 snd_printk("initializing firmware upload\n");
4666 firmware = (hdsp_firmware_t __user *)argp;
4668 if (get_user(firmware_data, &firmware->firmware_data)) {
4672 if (hdsp_check_for_iobox (hdsp)) {
4676 if (copy_from_user(hdsp->firmware_cache, firmware_data, sizeof(hdsp->firmware_cache)) != 0) {
4680 hdsp->state |= HDSP_FirmwareCached;
4682 if ((err = snd_hdsp_load_firmware_from_cache(hdsp)) < 0) {
4686 if (!(hdsp->state & HDSP_InitializationComplete)) {
4687 snd_hdsp_initialize_channels(hdsp);
4689 snd_hdsp_initialize_midi_flush(hdsp);
4691 if ((err = snd_hdsp_create_alsa_devices(hdsp->card, hdsp)) < 0) {
4692 snd_printk("error creating alsa devices\n");
4698 case SNDRV_HDSP_IOCTL_GET_MIXER: {
4699 hdsp_mixer_t __user *mixer = (hdsp_mixer_t __user *)argp;
4700 if (copy_to_user(mixer->matrix, hdsp->mixer_matrix, sizeof(unsigned short)*HDSP_MATRIX_MIXER_SIZE))
4710 static snd_pcm_ops_t snd_hdsp_playback_ops = {
4711 .open = snd_hdsp_playback_open,
4712 .close = snd_hdsp_playback_release,
4713 .ioctl = snd_hdsp_ioctl,
4714 .hw_params = snd_hdsp_hw_params,
4715 .prepare = snd_hdsp_prepare,
4716 .trigger = snd_hdsp_trigger,
4717 .pointer = snd_hdsp_hw_pointer,
4718 .copy = snd_hdsp_playback_copy,
4719 .silence = snd_hdsp_hw_silence,
4722 static snd_pcm_ops_t snd_hdsp_capture_ops = {
4723 .open = snd_hdsp_capture_open,
4724 .close = snd_hdsp_capture_release,
4725 .ioctl = snd_hdsp_ioctl,
4726 .hw_params = snd_hdsp_hw_params,
4727 .prepare = snd_hdsp_prepare,
4728 .trigger = snd_hdsp_trigger,
4729 .pointer = snd_hdsp_hw_pointer,
4730 .copy = snd_hdsp_capture_copy,
4733 static int __devinit snd_hdsp_create_hwdep(snd_card_t *card,
4739 if ((err = snd_hwdep_new(card, "HDSP hwdep", 0, &hw)) < 0)
4743 hw->private_data = hdsp;
4744 strcpy(hw->name, "HDSP hwdep interface");
4746 hw->ops.open = snd_hdsp_hwdep_dummy_op;
4747 hw->ops.ioctl = snd_hdsp_hwdep_ioctl;
4748 hw->ops.release = snd_hdsp_hwdep_dummy_op;
4753 static int __devinit snd_hdsp_create_pcm(snd_card_t *card,
4759 if ((err = snd_pcm_new(card, hdsp->card_name, 0, 1, 1, &pcm)) < 0)
4763 pcm->private_data = hdsp;
4764 strcpy(pcm->name, hdsp->card_name);
4766 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_hdsp_playback_ops);
4767 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_hdsp_capture_ops);
4769 pcm->info_flags = SNDRV_PCM_INFO_JOINT_DUPLEX;
4774 static void snd_hdsp_9652_enable_mixer (hdsp_t *hdsp)
4776 hdsp->control2_register |= HDSP_9652_ENABLE_MIXER;
4777 hdsp_write (hdsp, HDSP_control2Reg, hdsp->control2_register);
4780 static int snd_hdsp_enable_io (hdsp_t *hdsp)
4784 if (hdsp_fifo_wait (hdsp, 0, 100)) {
4788 for (i = 0; i < hdsp->max_channels; ++i) {
4789 hdsp_write (hdsp, HDSP_inputEnable + (4 * i), 1);
4790 hdsp_write (hdsp, HDSP_outputEnable + (4 * i), 1);
4796 static void snd_hdsp_initialize_channels(hdsp_t *hdsp)
4798 int status, aebi_channels, aebo_channels;
4800 switch (hdsp->io_type) {
4802 hdsp->card_name = "RME Hammerfall DSP + Digiface";
4803 hdsp->ss_in_channels = hdsp->ss_out_channels = DIGIFACE_SS_CHANNELS;
4804 hdsp->ds_in_channels = hdsp->ds_out_channels = DIGIFACE_DS_CHANNELS;
4808 hdsp->card_name = "RME Hammerfall HDSP 9652";
4809 hdsp->ss_in_channels = hdsp->ss_out_channels = H9652_SS_CHANNELS;
4810 hdsp->ds_in_channels = hdsp->ds_out_channels = H9652_DS_CHANNELS;
4814 status = hdsp_read(hdsp, HDSP_statusRegister);
4815 /* HDSP_AEBx bits are low when AEB are connected */
4816 aebi_channels = (status & HDSP_AEBI) ? 0 : 4;
4817 aebo_channels = (status & HDSP_AEBO) ? 0 : 4;
4818 hdsp->card_name = "RME Hammerfall HDSP 9632";
4819 hdsp->ss_in_channels = H9632_SS_CHANNELS+aebi_channels;
4820 hdsp->ds_in_channels = H9632_DS_CHANNELS+aebi_channels;
4821 hdsp->qs_in_channels = H9632_QS_CHANNELS+aebi_channels;
4822 hdsp->ss_out_channels = H9632_SS_CHANNELS+aebo_channels;
4823 hdsp->ds_out_channels = H9632_DS_CHANNELS+aebo_channels;
4824 hdsp->qs_out_channels = H9632_QS_CHANNELS+aebo_channels;
4828 hdsp->card_name = "RME Hammerfall DSP + Multiface";
4829 hdsp->ss_in_channels = hdsp->ss_out_channels = MULTIFACE_SS_CHANNELS;
4830 hdsp->ds_in_channels = hdsp->ds_out_channels = MULTIFACE_DS_CHANNELS;
4834 /* should never get here */
4839 static void snd_hdsp_initialize_midi_flush (hdsp_t *hdsp)
4841 snd_hdsp_flush_midi_input (hdsp, 0);
4842 snd_hdsp_flush_midi_input (hdsp, 1);
4845 static int __devinit snd_hdsp_create_alsa_devices(snd_card_t *card, hdsp_t *hdsp)
4849 if ((err = snd_hdsp_create_pcm(card, hdsp)) < 0) {
4850 snd_printk("Error creating pcm interface\n");
4855 if ((err = snd_hdsp_create_midi(card, hdsp, 0)) < 0) {
4856 snd_printk("Error creating first midi interface\n");
4861 if ((err = snd_hdsp_create_midi(card, hdsp, 1)) < 0) {
4862 snd_printk("Error creating second midi interface\n");
4866 if ((err = snd_hdsp_create_controls(card, hdsp)) < 0) {
4867 snd_printk("Error creating ctl interface\n");
4871 snd_hdsp_proc_init(hdsp);
4873 hdsp->system_sample_rate = -1;
4874 hdsp->playback_pid = -1;
4875 hdsp->capture_pid = -1;
4876 hdsp->capture_substream = NULL;
4877 hdsp->playback_substream = NULL;
4879 if ((err = snd_hdsp_set_defaults(hdsp)) < 0) {
4880 snd_printk("Error setting default values\n");
4884 if (!(hdsp->state & HDSP_InitializationComplete)) {
4885 sprintf(card->longname, "%s at 0x%lx, irq %d", hdsp->card_name,
4886 hdsp->port, hdsp->irq);
4888 if ((err = snd_card_register(card)) < 0) {
4889 snd_printk("error registering card\n");
4892 hdsp->state |= HDSP_InitializationComplete;
4898 static int __devinit snd_hdsp_create(snd_card_t *card,
4902 struct pci_dev *pci = hdsp->pci;
4909 hdsp->midi[0].rmidi = NULL;
4910 hdsp->midi[1].rmidi = NULL;
4911 hdsp->midi[0].input = NULL;
4912 hdsp->midi[1].input = NULL;
4913 hdsp->midi[0].output = NULL;
4914 hdsp->midi[1].output = NULL;
4915 spin_lock_init(&hdsp->midi[0].lock);
4916 spin_lock_init(&hdsp->midi[1].lock);
4917 hdsp->iobase = NULL;
4918 hdsp->control_register = 0;
4919 hdsp->control2_register = 0;
4920 hdsp->io_type = Undefined;
4921 hdsp->max_channels = 26;
4925 spin_lock_init(&hdsp->lock);
4927 tasklet_init(&hdsp->midi_tasklet, hdsp_midi_tasklet, (unsigned long)hdsp);
4929 pci_read_config_word(hdsp->pci, PCI_CLASS_REVISION, &hdsp->firmware_rev);
4931 /* From Martin Bjoernsen :
4932 "It is important that the card's latency timer register in
4933 the PCI configuration space is set to a value much larger
4934 than 0 by the computer's BIOS or the driver.
4935 The windows driver always sets this 8 bit register [...]
4936 to its maximum 255 to avoid problems with some computers."
4938 pci_write_config_byte(hdsp->pci, PCI_LATENCY_TIMER, 0xFF);
4940 strcpy(card->driver, "H-DSP");
4941 strcpy(card->mixername, "Xilinx FPGA");
4943 switch (hdsp->firmware_rev & 0xff) {
4947 hdsp->card_name = "RME Hammerfall DSP";
4953 hdsp->card_name = "RME HDSP 9652";
4958 hdsp->card_name = "RME HDSP 9632";
4959 hdsp->max_channels = 16;
4966 if ((err = pci_enable_device(pci)) < 0) {
4970 pci_set_master(hdsp->pci);
4972 if ((err = pci_request_regions(pci, "hdsp")) < 0)
4974 hdsp->port = pci_resource_start(pci, 0);
4975 if ((hdsp->iobase = ioremap_nocache(hdsp->port, HDSP_IO_EXTENT)) == NULL) {
4976 snd_printk("unable to remap region 0x%lx-0x%lx\n", hdsp->port, hdsp->port + HDSP_IO_EXTENT - 1);
4980 if (request_irq(pci->irq, snd_hdsp_interrupt, SA_INTERRUPT|SA_SHIRQ, "hdsp", (void *)hdsp)) {
4981 snd_printk("unable to use IRQ %d\n", pci->irq);
4985 hdsp->irq = pci->irq;
4986 hdsp->precise_ptr = precise_ptr;
4988 if ((err = snd_hdsp_initialize_memory(hdsp)) < 0) {
4992 if (!is_9652 && !is_9632 && hdsp_check_for_iobox (hdsp)) {
4993 /* no iobox connected, we defer initialization */
4994 snd_printk("card initialization pending : waiting for firmware\n");
4995 if ((err = snd_hdsp_create_hwdep(card, hdsp)) < 0) {
5001 if ((err = snd_hdsp_enable_io(hdsp)) != 0) {
5005 if ((hdsp_read (hdsp, HDSP_statusRegister) & HDSP_DllError) != 0) {
5006 snd_printk("card initialization pending : waiting for firmware\n");
5007 if ((err = snd_hdsp_create_hwdep(card, hdsp)) < 0) {
5013 snd_printk("Firmware already loaded, initializing card.\n");
5015 if (hdsp_read(hdsp, HDSP_status2Register) & HDSP_version1) {
5016 hdsp->io_type = Multiface;
5018 hdsp->io_type = Digiface;
5022 hdsp->io_type = H9652;
5026 hdsp->io_type = H9632;
5029 if ((err = snd_hdsp_create_hwdep(card, hdsp)) < 0) {
5033 snd_hdsp_initialize_channels(hdsp);
5034 snd_hdsp_initialize_midi_flush(hdsp);
5036 hdsp->state |= HDSP_FirmwareLoaded;
5038 if ((err = snd_hdsp_create_alsa_devices(card, hdsp)) < 0) {
5045 static int snd_hdsp_free(hdsp_t *hdsp)
5048 /* stop the audio, and cancel all interrupts */
5049 hdsp->control_register &= ~(HDSP_Start|HDSP_AudioInterruptEnable|HDSP_Midi0InterruptEnable|HDSP_Midi1InterruptEnable);
5050 hdsp_write (hdsp, HDSP_controlRegister, hdsp->control_register);
5054 free_irq(hdsp->irq, (void *)hdsp);
5056 snd_hdsp_free_buffers(hdsp);
5059 iounmap(hdsp->iobase);
5062 pci_release_regions(hdsp->pci);
5064 pci_disable_device(hdsp->pci);
5068 static void snd_hdsp_card_free(snd_card_t *card)
5070 hdsp_t *hdsp = (hdsp_t *) card->private_data;
5073 snd_hdsp_free(hdsp);
5076 static int __devinit snd_hdsp_probe(struct pci_dev *pci,
5077 const struct pci_device_id *pci_id)
5084 if (dev >= SNDRV_CARDS)
5091 if (!(card = snd_card_new(index[dev], id[dev], THIS_MODULE, sizeof(hdsp_t))))
5094 hdsp = (hdsp_t *) card->private_data;
5095 card->private_free = snd_hdsp_card_free;
5098 snd_card_set_dev(card, &pci->dev);
5100 if ((err = snd_hdsp_create(card, hdsp, precise_ptr[dev])) < 0) {
5101 snd_card_free(card);
5105 strcpy(card->shortname, "Hammerfall DSP");
5106 sprintf(card->longname, "%s at 0x%lx, irq %d", hdsp->card_name,
5107 hdsp->port, hdsp->irq);
5109 if ((err = snd_card_register(card)) < 0) {
5110 snd_card_free(card);
5113 pci_set_drvdata(pci, card);
5118 static void __devexit snd_hdsp_remove(struct pci_dev *pci)
5120 snd_card_free(pci_get_drvdata(pci));
5121 pci_set_drvdata(pci, NULL);
5124 static struct pci_driver driver = {
5125 .name = "RME Hammerfall DSP",
5126 .id_table = snd_hdsp_ids,
5127 .probe = snd_hdsp_probe,
5128 .remove = __devexit_p(snd_hdsp_remove),
5131 static int __init alsa_card_hdsp_init(void)
5133 return pci_module_init(&driver);
5136 static void __exit alsa_card_hdsp_exit(void)
5138 pci_unregister_driver(&driver);
5141 module_init(alsa_card_hdsp_init)
5142 module_exit(alsa_card_hdsp_exit)