27 #include <linux/pci.h>
29 #include <linux/module.h>
42 #include <asm/byteorder.h>
43 #include <asm/current.h>
70 #define HDSP_MAX_CHANNELS 26
71 #define HDSP_MAX_DS_CHANNELS 14
72 #define HDSP_MAX_QS_CHANNELS 8
73 #define DIGIFACE_SS_CHANNELS 26
74 #define DIGIFACE_DS_CHANNELS 14
75 #define MULTIFACE_SS_CHANNELS 18
76 #define MULTIFACE_DS_CHANNELS 14
77 #define H9652_SS_CHANNELS 26
78 #define H9652_DS_CHANNELS 14
82 #define H9632_SS_CHANNELS 12
83 #define H9632_DS_CHANNELS 8
84 #define H9632_QS_CHANNELS 4
85 #define RPM_CHANNELS 6
89 #define HDSP_resetPointer 0
90 #define HDSP_freqReg 0
91 #define HDSP_outputBufferAddress 32
92 #define HDSP_inputBufferAddress 36
93 #define HDSP_controlRegister 64
94 #define HDSP_interruptConfirmation 96
95 #define HDSP_outputEnable 128
96 #define HDSP_control2Reg 256
97 #define HDSP_midiDataOut0 352
98 #define HDSP_midiDataOut1 356
99 #define HDSP_fifoData 368
100 #define HDSP_inputEnable 384
105 #define HDSP_statusRegister 0
106 #define HDSP_timecode 128
107 #define HDSP_status2Register 192
108 #define HDSP_midiDataIn0 360
109 #define HDSP_midiDataIn1 364
110 #define HDSP_midiStatusOut0 384
111 #define HDSP_midiStatusOut1 388
112 #define HDSP_midiStatusIn0 392
113 #define HDSP_midiStatusIn1 396
114 #define HDSP_fifoStatus 400
122 #define HDSP_playbackPeakLevel 4096
123 #define HDSP_inputPeakLevel 4224
124 #define HDSP_outputPeakLevel 4352
125 #define HDSP_playbackRmsLevel 4612
126 #define HDSP_inputRmsLevel 4868
136 #define HDSP_9652_peakBase 7164
137 #define HDSP_9652_rmsBase 4096
140 #define HDSP_9632_metersBase 4096
142 #define HDSP_IO_EXTENT 7168
146 #define HDSP_TMS 0x01
147 #define HDSP_TCK 0x02
148 #define HDSP_TDI 0x04
149 #define HDSP_JTAG 0x08
150 #define HDSP_PWDN 0x10
151 #define HDSP_PROGRAM 0x020
152 #define HDSP_CONFIG_MODE_0 0x040
153 #define HDSP_CONFIG_MODE_1 0x080
154 #define HDSP_VERSION_BIT (0x100 | HDSP_S_LOAD)
155 #define HDSP_BIGENDIAN_MODE 0x200
156 #define HDSP_RD_MULTIPLE 0x400
157 #define HDSP_9652_ENABLE_MIXER 0x800
158 #define HDSP_TDO 0x10000000
160 #define HDSP_S_PROGRAM (HDSP_PROGRAM|HDSP_CONFIG_MODE_0)
161 #define HDSP_S_LOAD (HDSP_PROGRAM|HDSP_CONFIG_MODE_1)
165 #define HDSP_Start (1<<0)
166 #define HDSP_Latency0 (1<<1)
167 #define HDSP_Latency1 (1<<2)
168 #define HDSP_Latency2 (1<<3)
169 #define HDSP_ClockModeMaster (1<<4)
170 #define HDSP_AudioInterruptEnable (1<<5)
171 #define HDSP_Frequency0 (1<<6)
172 #define HDSP_Frequency1 (1<<7)
173 #define HDSP_DoubleSpeed (1<<8)
174 #define HDSP_SPDIFProfessional (1<<9)
175 #define HDSP_SPDIFEmphasis (1<<10)
176 #define HDSP_SPDIFNonAudio (1<<11)
177 #define HDSP_SPDIFOpticalOut (1<<12)
178 #define HDSP_SyncRef2 (1<<13)
179 #define HDSP_SPDIFInputSelect0 (1<<14)
180 #define HDSP_SPDIFInputSelect1 (1<<15)
181 #define HDSP_SyncRef0 (1<<16)
182 #define HDSP_SyncRef1 (1<<17)
183 #define HDSP_AnalogExtensionBoard (1<<18)
184 #define HDSP_XLRBreakoutCable (1<<20)
185 #define HDSP_Midi0InterruptEnable (1<<22)
186 #define HDSP_Midi1InterruptEnable (1<<23)
187 #define HDSP_LineOut (1<<24)
188 #define HDSP_ADGain0 (1<<25)
189 #define HDSP_ADGain1 (1<<26)
190 #define HDSP_DAGain0 (1<<27)
191 #define HDSP_DAGain1 (1<<28)
192 #define HDSP_PhoneGain0 (1<<29)
193 #define HDSP_PhoneGain1 (1<<30)
194 #define HDSP_QuadSpeed (1<<31)
197 #define HDSP_RPM_Inp12 0x04A00
198 #define HDSP_RPM_Inp12_Phon_6dB 0x00800
199 #define HDSP_RPM_Inp12_Phon_0dB 0x00000
200 #define HDSP_RPM_Inp12_Phon_n6dB 0x04000
201 #define HDSP_RPM_Inp12_Line_0dB 0x04200
202 #define HDSP_RPM_Inp12_Line_n6dB 0x00200
204 #define HDSP_RPM_Inp34 0x32000
205 #define HDSP_RPM_Inp34_Phon_6dB 0x20000
206 #define HDSP_RPM_Inp34_Phon_0dB 0x00000
207 #define HDSP_RPM_Inp34_Phon_n6dB 0x02000
208 #define HDSP_RPM_Inp34_Line_0dB 0x30000
209 #define HDSP_RPM_Inp34_Line_n6dB 0x10000
211 #define HDSP_RPM_Bypass 0x01000
213 #define HDSP_RPM_Disconnect 0x00001
215 #define HDSP_ADGainMask (HDSP_ADGain0|HDSP_ADGain1)
216 #define HDSP_ADGainMinus10dBV HDSP_ADGainMask
217 #define HDSP_ADGainPlus4dBu (HDSP_ADGain0)
218 #define HDSP_ADGainLowGain 0
220 #define HDSP_DAGainMask (HDSP_DAGain0|HDSP_DAGain1)
221 #define HDSP_DAGainHighGain HDSP_DAGainMask
222 #define HDSP_DAGainPlus4dBu (HDSP_DAGain0)
223 #define HDSP_DAGainMinus10dBV 0
225 #define HDSP_PhoneGainMask (HDSP_PhoneGain0|HDSP_PhoneGain1)
226 #define HDSP_PhoneGain0dB HDSP_PhoneGainMask
227 #define HDSP_PhoneGainMinus6dB (HDSP_PhoneGain0)
228 #define HDSP_PhoneGainMinus12dB 0
230 #define HDSP_LatencyMask (HDSP_Latency0|HDSP_Latency1|HDSP_Latency2)
231 #define HDSP_FrequencyMask (HDSP_Frequency0|HDSP_Frequency1|HDSP_DoubleSpeed|HDSP_QuadSpeed)
233 #define HDSP_SPDIFInputMask (HDSP_SPDIFInputSelect0|HDSP_SPDIFInputSelect1)
234 #define HDSP_SPDIFInputADAT1 0
235 #define HDSP_SPDIFInputCoaxial (HDSP_SPDIFInputSelect0)
236 #define HDSP_SPDIFInputCdrom (HDSP_SPDIFInputSelect1)
237 #define HDSP_SPDIFInputAES (HDSP_SPDIFInputSelect0|HDSP_SPDIFInputSelect1)
239 #define HDSP_SyncRefMask (HDSP_SyncRef0|HDSP_SyncRef1|HDSP_SyncRef2)
240 #define HDSP_SyncRef_ADAT1 0
241 #define HDSP_SyncRef_ADAT2 (HDSP_SyncRef0)
242 #define HDSP_SyncRef_ADAT3 (HDSP_SyncRef1)
243 #define HDSP_SyncRef_SPDIF (HDSP_SyncRef0|HDSP_SyncRef1)
244 #define HDSP_SyncRef_WORD (HDSP_SyncRef2)
245 #define HDSP_SyncRef_ADAT_SYNC (HDSP_SyncRef0|HDSP_SyncRef2)
249 #define HDSP_CLOCK_SOURCE_AUTOSYNC 0
250 #define HDSP_CLOCK_SOURCE_INTERNAL_32KHZ 1
251 #define HDSP_CLOCK_SOURCE_INTERNAL_44_1KHZ 2
252 #define HDSP_CLOCK_SOURCE_INTERNAL_48KHZ 3
253 #define HDSP_CLOCK_SOURCE_INTERNAL_64KHZ 4
254 #define HDSP_CLOCK_SOURCE_INTERNAL_88_2KHZ 5
255 #define HDSP_CLOCK_SOURCE_INTERNAL_96KHZ 6
256 #define HDSP_CLOCK_SOURCE_INTERNAL_128KHZ 7
257 #define HDSP_CLOCK_SOURCE_INTERNAL_176_4KHZ 8
258 #define HDSP_CLOCK_SOURCE_INTERNAL_192KHZ 9
262 #define HDSP_SYNC_FROM_WORD 0
263 #define HDSP_SYNC_FROM_SPDIF 1
264 #define HDSP_SYNC_FROM_ADAT1 2
265 #define HDSP_SYNC_FROM_ADAT_SYNC 3
266 #define HDSP_SYNC_FROM_ADAT2 4
267 #define HDSP_SYNC_FROM_ADAT3 5
271 #define HDSP_SYNC_CHECK_NO_LOCK 0
272 #define HDSP_SYNC_CHECK_LOCK 1
273 #define HDSP_SYNC_CHECK_SYNC 2
277 #define HDSP_AUTOSYNC_FROM_WORD 0
278 #define HDSP_AUTOSYNC_FROM_ADAT_SYNC 1
279 #define HDSP_AUTOSYNC_FROM_SPDIF 2
280 #define HDSP_AUTOSYNC_FROM_NONE 3
281 #define HDSP_AUTOSYNC_FROM_ADAT1 4
282 #define HDSP_AUTOSYNC_FROM_ADAT2 5
283 #define HDSP_AUTOSYNC_FROM_ADAT3 6
287 #define HDSP_SPDIFIN_OPTICAL 0
288 #define HDSP_SPDIFIN_COAXIAL 1
289 #define HDSP_SPDIFIN_INTERNAL 2
290 #define HDSP_SPDIFIN_AES 3
292 #define HDSP_Frequency32KHz HDSP_Frequency0
293 #define HDSP_Frequency44_1KHz HDSP_Frequency1
294 #define HDSP_Frequency48KHz (HDSP_Frequency1|HDSP_Frequency0)
295 #define HDSP_Frequency64KHz (HDSP_DoubleSpeed|HDSP_Frequency0)
296 #define HDSP_Frequency88_2KHz (HDSP_DoubleSpeed|HDSP_Frequency1)
297 #define HDSP_Frequency96KHz (HDSP_DoubleSpeed|HDSP_Frequency1|HDSP_Frequency0)
299 #define HDSP_Frequency128KHz (HDSP_QuadSpeed|HDSP_DoubleSpeed|HDSP_Frequency0)
300 #define HDSP_Frequency176_4KHz (HDSP_QuadSpeed|HDSP_DoubleSpeed|HDSP_Frequency1)
301 #define HDSP_Frequency192KHz (HDSP_QuadSpeed|HDSP_DoubleSpeed|HDSP_Frequency1|HDSP_Frequency0)
306 #define DDS_NUMERATOR 104857600000000ULL;
308 #define hdsp_encode_latency(x) (((x)<<1) & HDSP_LatencyMask)
309 #define hdsp_decode_latency(x) (((x) & HDSP_LatencyMask)>>1)
311 #define hdsp_encode_spdif_in(x) (((x)&0x3)<<14)
312 #define hdsp_decode_spdif_in(x) (((x)>>14)&0x3)
316 #define HDSP_audioIRQPending (1<<0)
317 #define HDSP_Lock2 (1<<1)
318 #define HDSP_spdifFrequency3 HDSP_Lock2
319 #define HDSP_Lock1 (1<<2)
320 #define HDSP_Lock0 (1<<3)
321 #define HDSP_SPDIFSync (1<<4)
322 #define HDSP_TimecodeLock (1<<5)
323 #define HDSP_BufferPositionMask 0x000FFC0
324 #define HDSP_Sync2 (1<<16)
325 #define HDSP_Sync1 (1<<17)
326 #define HDSP_Sync0 (1<<18)
327 #define HDSP_DoubleSpeedStatus (1<<19)
328 #define HDSP_ConfigError (1<<20)
329 #define HDSP_DllError (1<<21)
330 #define HDSP_spdifFrequency0 (1<<22)
331 #define HDSP_spdifFrequency1 (1<<23)
332 #define HDSP_spdifFrequency2 (1<<24)
333 #define HDSP_SPDIFErrorFlag (1<<25)
334 #define HDSP_BufferID (1<<26)
335 #define HDSP_TimecodeSync (1<<27)
336 #define HDSP_AEBO (1<<28)
337 #define HDSP_AEBI (1<<29)
338 #define HDSP_midi0IRQPending (1<<30)
339 #define HDSP_midi1IRQPending (1<<31)
341 #define HDSP_spdifFrequencyMask (HDSP_spdifFrequency0|HDSP_spdifFrequency1|HDSP_spdifFrequency2)
342 #define HDSP_spdifFrequencyMask_9632 (HDSP_spdifFrequency0|\
343 HDSP_spdifFrequency1|\
344 HDSP_spdifFrequency2|\
345 HDSP_spdifFrequency3)
347 #define HDSP_spdifFrequency32KHz (HDSP_spdifFrequency0)
348 #define HDSP_spdifFrequency44_1KHz (HDSP_spdifFrequency1)
349 #define HDSP_spdifFrequency48KHz (HDSP_spdifFrequency0|HDSP_spdifFrequency1)
351 #define HDSP_spdifFrequency64KHz (HDSP_spdifFrequency2)
352 #define HDSP_spdifFrequency88_2KHz (HDSP_spdifFrequency0|HDSP_spdifFrequency2)
353 #define HDSP_spdifFrequency96KHz (HDSP_spdifFrequency2|HDSP_spdifFrequency1)
356 #define HDSP_spdifFrequency128KHz (HDSP_spdifFrequency0|\
357 HDSP_spdifFrequency1|\
358 HDSP_spdifFrequency2)
359 #define HDSP_spdifFrequency176_4KHz HDSP_spdifFrequency3
360 #define HDSP_spdifFrequency192KHz (HDSP_spdifFrequency3|HDSP_spdifFrequency0)
364 #define HDSP_version0 (1<<0)
365 #define HDSP_version1 (1<<1)
366 #define HDSP_version2 (1<<2)
367 #define HDSP_wc_lock (1<<3)
368 #define HDSP_wc_sync (1<<4)
369 #define HDSP_inp_freq0 (1<<5)
370 #define HDSP_inp_freq1 (1<<6)
371 #define HDSP_inp_freq2 (1<<7)
372 #define HDSP_SelSyncRef0 (1<<8)
373 #define HDSP_SelSyncRef1 (1<<9)
374 #define HDSP_SelSyncRef2 (1<<10)
376 #define HDSP_wc_valid (HDSP_wc_lock|HDSP_wc_sync)
378 #define HDSP_systemFrequencyMask (HDSP_inp_freq0|HDSP_inp_freq1|HDSP_inp_freq2)
379 #define HDSP_systemFrequency32 (HDSP_inp_freq0)
380 #define HDSP_systemFrequency44_1 (HDSP_inp_freq1)
381 #define HDSP_systemFrequency48 (HDSP_inp_freq0|HDSP_inp_freq1)
382 #define HDSP_systemFrequency64 (HDSP_inp_freq2)
383 #define HDSP_systemFrequency88_2 (HDSP_inp_freq0|HDSP_inp_freq2)
384 #define HDSP_systemFrequency96 (HDSP_inp_freq1|HDSP_inp_freq2)
387 #define HDSP_SelSyncRefMask (HDSP_SelSyncRef0|HDSP_SelSyncRef1|HDSP_SelSyncRef2)
388 #define HDSP_SelSyncRef_ADAT1 0
389 #define HDSP_SelSyncRef_ADAT2 (HDSP_SelSyncRef0)
390 #define HDSP_SelSyncRef_ADAT3 (HDSP_SelSyncRef1)
391 #define HDSP_SelSyncRef_SPDIF (HDSP_SelSyncRef0|HDSP_SelSyncRef1)
392 #define HDSP_SelSyncRef_WORD (HDSP_SelSyncRef2)
393 #define HDSP_SelSyncRef_ADAT_SYNC (HDSP_SelSyncRef0|HDSP_SelSyncRef2)
397 #define HDSP_InitializationComplete (1<<0)
398 #define HDSP_FirmwareLoaded (1<<1)
399 #define HDSP_FirmwareCached (1<<2)
403 #define HDSP_LONG_WAIT 5000
404 #define HDSP_SHORT_WAIT 30
406 #define UNITY_GAIN 32768
407 #define MINUS_INFINITY_GAIN 0
411 #define HDSP_CHANNEL_BUFFER_SAMPLES (16*1024)
412 #define HDSP_CHANNEL_BUFFER_BYTES (4*HDSP_CHANNEL_BUFFER_SAMPLES)
423 #define HDSP_DMA_AREA_BYTES ((HDSP_MAX_CHANNELS+1) * HDSP_CHANNEL_BUFFER_BYTES)
424 #define HDSP_DMA_AREA_KILOBYTES (HDSP_DMA_AREA_BYTES/1024)
427 #if defined(CONFIG_FW_LOADER) || defined(CONFIG_FW_LOADER_MODULE)
428 #if !defined(HDSP_USE_HWDEP_LOADER)
429 #define HDSP_FW_LOADER
520 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17,
521 18, 19, 20, 21, 22, 23, 24, 25
526 0, 1, 2, 3, 4, 5, 6, 7,
528 16, 17, 18, 19, 20, 21, 22, 23,
531 -1, -1, -1, -1, -1, -1, -1, -1
536 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23,
540 -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
545 0, 1, 2, 3, 4, 5, 6, 7,
553 -1, -1, -1, -1, -1, -1, -1, -1,
567 -1, -1, -1, -1, -1, -1, -1, -1,
568 -1, -1, -1, -1, -1, -1
580 -1, -1, -1, -1, -1, -1, -1, -1,
581 -1, -1, -1, -1, -1, -1, -1, -1,
590 if (dmab->
bytes >= size)
623 static int snd_hdsp_enable_io (
struct hdsp *
hdsp);
624 static void snd_hdsp_initialize_midi_flush (
struct hdsp *
hdsp);
625 static void snd_hdsp_initialize_channels (
struct hdsp *
hdsp);
626 static int hdsp_fifo_wait(
struct hdsp *
hdsp,
int count,
int timeout);
627 static int hdsp_autosync_ref(
struct hdsp *
hdsp);
628 static int snd_hdsp_set_defaults(
struct hdsp *
hdsp);
629 static void snd_hdsp_9652_enable_mixer (
struct hdsp *
hdsp);
631 static int hdsp_playback_to_output_key (
struct hdsp *
hdsp,
int in,
int out)
639 return (64 * out) + (32 + (
in));
641 return (52 * out) + (26 + (
in));
643 return (32 * out) + (16 + (
in));
645 return (52 * out) + (26 + (
in));
649 static int hdsp_input_to_output_key (
struct hdsp *hdsp,
int in,
int out)
657 return (64 * out) +
in;
659 return (52 * out) +
in;
661 return (32 * out) +
in;
663 return (52 * out) +
in;
667 static void hdsp_write(
struct hdsp *hdsp,
int reg,
int val)
672 static unsigned int hdsp_read(
struct hdsp *hdsp,
int reg)
677 static int hdsp_check_for_iobox (
struct hdsp *hdsp)
681 snd_printk(
"Hammerfall-DSP: no IO box connected!\n");
688 static int hdsp_wait_for_iobox(
struct hdsp *hdsp,
unsigned int loops,
696 for (i = 0; i != loops; ++
i) {
700 snd_printd(
"Hammerfall-DSP: iobox found after %ums!\n",
706 snd_printk(
"Hammerfall-DSP: no IO box connected!\n");
711 static int snd_hdsp_load_firmware_from_cache(
struct hdsp *hdsp) {
718 snd_printk (
"Hammerfall-DSP: loading firmware\n");
724 snd_printk (
"Hammerfall-DSP: timeout waiting for download preparation\n");
730 for (i = 0; i < 24413; ++
i) {
733 snd_printk (
"Hammerfall-DSP: timeout during firmware loading\n");
741 snd_printk (
"Hammerfall-DSP: timeout at end of firmware loading\n");
745 #ifdef SNDRV_BIG_ENDIAN
751 snd_printk (
"Hammerfall-DSP: finished firmware loading\n");
757 snd_hdsp_set_defaults(hdsp);
758 spin_unlock_irqrestore(&hdsp->
lock, flags);
766 static int hdsp_get_iobox_version (
struct hdsp *hdsp)
801 #ifdef HDSP_FW_LOADER
802 static int hdsp_request_fw_loader(
struct hdsp *hdsp);
805 static int hdsp_check_for_firmware (
struct hdsp *hdsp,
int load_on_demand)
811 if (! load_on_demand)
816 #ifdef HDSP_FW_LOADER
817 if (! hdsp_request_fw_loader(hdsp))
821 "Hammerfall-DSP: No firmware loaded nor "
822 "cached, please upload firmware.\n");
825 if (snd_hdsp_load_firmware_from_cache(hdsp) != 0) {
827 "Hammerfall-DSP: Firmware loading from "
828 "cache failed, please upload manually.\n");
836 static int hdsp_fifo_wait(
struct hdsp *hdsp,
int count,
int timeout)
844 for (i = 0; i < timeout; i++) {
856 snd_printk (
"Hammerfall-DSP: wait for FIFO status <= %d failed after %d iterations\n",
861 static int hdsp_read_gain (
struct hdsp *hdsp,
unsigned int addr)
869 static int hdsp_write_gain(
struct hdsp *hdsp,
unsigned int addr,
unsigned short data)
908 hdsp_write (hdsp, 4096 + (ad*4),
916 ad = (addr << 16) + data;
929 static int snd_hdsp_use_is_exclusive(
struct hdsp *hdsp)
938 spin_unlock_irqrestore(&hdsp->
lock, flags);
942 static int hdsp_spdif_sample_rate(
struct hdsp *hdsp)
973 snd_printk (
"Hammerfall-DSP: unknown spdif frequency status; bits = 0x%x, status = 0x%x\n", rate_bits, status);
977 static int hdsp_external_sample_rate(
struct hdsp *hdsp)
988 return hdsp_spdif_sample_rate(hdsp);
1002 static void hdsp_compute_period_size(
struct hdsp *hdsp)
1022 static void hdsp_reset_hw_pointer(
struct hdsp *hdsp)
1032 static void hdsp_start_audio(
struct hdsp *
s)
1038 static void hdsp_stop_audio(
struct hdsp *
s)
1044 static void hdsp_silence_playback(
struct hdsp *hdsp)
1049 static int hdsp_set_interrupt_interval(
struct hdsp *
s,
unsigned int frames)
1053 spin_lock_irq(&s->
lock);
1067 hdsp_compute_period_size(s);
1069 spin_unlock_irq(&s->
lock);
1074 static void hdsp_set_dds_value(
struct hdsp *hdsp,
int rate)
1080 else if (rate >= 56000)
1084 n = div_u64(n, rate);
1093 static int hdsp_set_rate(
struct hdsp *hdsp,
int rate,
int called_internally)
1095 int reject_if_open = 0;
1105 if (called_internally) {
1107 snd_printk(
KERN_ERR "Hammerfall-DSP: device is not running as a clock master: cannot set sample rate.\n");
1111 int external_freq = hdsp_external_sample_rate(hdsp);
1112 int spdif_freq = hdsp_spdif_sample_rate(hdsp);
1118 else if (rate != external_freq) {
1142 if (current_rate > 48000)
1147 if (current_rate > 48000)
1152 if (current_rate > 48000)
1157 if (current_rate <= 48000 || current_rate > 96000)
1162 if (current_rate <= 48000 || current_rate > 96000)
1167 if (current_rate <= 48000 || current_rate > 96000)
1172 if (current_rate < 128000)
1177 if (current_rate < 128000)
1182 if (current_rate < 128000)
1191 snd_printk (
"Hammerfall-DSP: cannot change speed mode (capture PID = %d, playback PID = %d)\n",
1203 hdsp_set_dds_value(hdsp, rate);
1205 if (rate >= 128000) {
1207 }
else if (rate > 48000) {
1240 static unsigned char snd_hdsp_midi_read_byte (
struct hdsp *hdsp,
int id)
1249 static void snd_hdsp_midi_write_byte (
struct hdsp *hdsp,
int id,
int val)
1258 static int snd_hdsp_midi_input_available (
struct hdsp *hdsp,
int id)
1266 static int snd_hdsp_midi_output_possible (
struct hdsp *hdsp,
int id)
1268 int fifo_bytes_used;
1275 if (fifo_bytes_used < 128)
1276 return 128 - fifo_bytes_used;
1281 static void snd_hdsp_flush_midi_input (
struct hdsp *hdsp,
int id)
1283 while (snd_hdsp_midi_input_available (hdsp,
id))
1284 snd_hdsp_midi_read_byte (hdsp,
id);
1287 static int snd_hdsp_midi_output_write (
struct hdsp_midi *hmidi)
1289 unsigned long flags;
1293 unsigned char buf[128];
1300 if ((n_pending = snd_hdsp_midi_output_possible (hmidi->
hdsp, hmidi->
id)) > 0) {
1301 if (n_pending > (
int)
sizeof (buf))
1302 n_pending =
sizeof (
buf);
1305 for (i = 0; i < to_write; ++
i)
1306 snd_hdsp_midi_write_byte (hmidi->
hdsp, hmidi->
id, buf[i]);
1311 spin_unlock_irqrestore (&hmidi->
lock, flags);
1315 static int snd_hdsp_midi_input_read (
struct hdsp_midi *hmidi)
1317 unsigned char buf[128];
1318 unsigned long flags;
1323 if ((n_pending = snd_hdsp_midi_input_available (hmidi->
hdsp, hmidi->
id)) > 0) {
1325 if (n_pending > (
int)
sizeof (buf))
1326 n_pending =
sizeof (
buf);
1327 for (i = 0; i < n_pending; ++
i)
1328 buf[i] = snd_hdsp_midi_read_byte (hmidi->
hdsp, hmidi->
id);
1334 snd_hdsp_midi_read_byte (hmidi->
hdsp, hmidi->
id);
1343 spin_unlock_irqrestore (&hmidi->
lock, flags);
1344 return snd_hdsp_midi_output_write (hmidi);
1351 unsigned long flags;
1360 snd_hdsp_flush_midi_input (hdsp, hmidi->
id);
1369 spin_unlock_irqrestore (&hdsp->
lock, flags);
1372 static void snd_hdsp_midi_output_timer(
unsigned long data)
1375 unsigned long flags;
1377 snd_hdsp_midi_output_write(hmidi);
1391 spin_unlock_irqrestore (&hmidi->
lock, flags);
1397 unsigned long flags;
1404 hmidi->
timer.function = snd_hdsp_midi_output_timer;
1405 hmidi->
timer.data = (
unsigned long) hmidi;
1414 spin_unlock_irqrestore (&hmidi->
lock, flags);
1416 snd_hdsp_midi_output_write(hmidi);
1424 spin_lock_irq (&hmidi->
lock);
1425 snd_hdsp_flush_midi_input (hmidi->
hdsp, hmidi->
id);
1426 hmidi->
input = substream;
1427 spin_unlock_irq (&hmidi->
lock);
1437 spin_lock_irq (&hmidi->
lock);
1438 hmidi->
output = substream;
1439 spin_unlock_irq (&hmidi->
lock);
1448 snd_hdsp_midi_input_trigger (substream, 0);
1451 spin_lock_irq (&hmidi->
lock);
1453 spin_unlock_irq (&hmidi->
lock);
1462 snd_hdsp_midi_output_trigger (substream, 0);
1465 spin_lock_irq (&hmidi->
lock);
1467 spin_unlock_irq (&hmidi->
lock);
1474 .open = snd_hdsp_midi_output_open,
1475 .close = snd_hdsp_midi_output_close,
1476 .trigger = snd_hdsp_midi_output_trigger,
1481 .open = snd_hdsp_midi_input_open,
1482 .close = snd_hdsp_midi_input_close,
1483 .trigger = snd_hdsp_midi_input_trigger,
1486 static int snd_hdsp_create_midi (
struct snd_card *
card,
struct hdsp *hdsp,
int id)
1494 hdsp->
midi[
id].hdsp = hdsp;
1495 hdsp->
midi[
id].istimer = 0;
1496 hdsp->
midi[
id].pending = 0;
1503 sprintf(hdsp->
midi[
id].rmidi->name,
"HDSP MIDI %d",
id+1);
1563 val = snd_hdsp_convert_from_aes(&ucontrol->
value.iec958);
1564 spin_lock_irq(&hdsp->
lock);
1567 spin_unlock_irq(&hdsp->
lock);
1592 val = snd_hdsp_convert_from_aes(&ucontrol->
value.iec958);
1593 spin_lock_irq(&hdsp->
lock);
1598 spin_unlock_irq(&hdsp->
lock);
1615 #define HDSP_SPDIF_IN(xname, xindex) \
1616 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1619 .info = snd_hdsp_info_spdif_in, \
1620 .get = snd_hdsp_get_spdif_in, \
1621 .put = snd_hdsp_put_spdif_in }
1623 static unsigned int hdsp_spdif_in(
struct hdsp *hdsp)
1628 static int hdsp_set_spdif_input(
struct hdsp *hdsp,
int in)
1638 static char *texts[4] = {
"Optical",
"Coaxial",
"Internal",
"AES"};
1654 ucontrol->
value.enumerated.item[0] = hdsp_spdif_in(hdsp);
1664 if (!snd_hdsp_use_is_exclusive(hdsp))
1667 spin_lock_irq(&hdsp->
lock);
1668 change = val != hdsp_spdif_in(hdsp);
1670 hdsp_set_spdif_input(hdsp, val);
1671 spin_unlock_irq(&hdsp->
lock);
1675 #define HDSP_SPDIF_OUT(xname, xindex) \
1676 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \
1677 .info = snd_hdsp_info_spdif_bits, \
1678 .get = snd_hdsp_get_spdif_out, .put = snd_hdsp_put_spdif_out }
1680 static int hdsp_spdif_out(
struct hdsp *hdsp)
1685 static int hdsp_set_spdif_output(
struct hdsp *hdsp,
int out)
1695 #define snd_hdsp_info_spdif_bits snd_ctl_boolean_mono_info
1701 ucontrol->
value.integer.value[0] = hdsp_spdif_out(hdsp);
1711 if (!snd_hdsp_use_is_exclusive(hdsp))
1713 val = ucontrol->
value.integer.value[0] & 1;
1714 spin_lock_irq(&hdsp->
lock);
1715 change = (
int)val != hdsp_spdif_out(hdsp);
1716 hdsp_set_spdif_output(hdsp, val);
1717 spin_unlock_irq(&hdsp->
lock);
1721 #define HDSP_SPDIF_PROFESSIONAL(xname, xindex) \
1722 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \
1723 .info = snd_hdsp_info_spdif_bits, \
1724 .get = snd_hdsp_get_spdif_professional, .put = snd_hdsp_put_spdif_professional }
1726 static int hdsp_spdif_professional(
struct hdsp *hdsp)
1731 static int hdsp_set_spdif_professional(
struct hdsp *hdsp,
int val)
1745 ucontrol->
value.integer.value[0] = hdsp_spdif_professional(hdsp);
1755 if (!snd_hdsp_use_is_exclusive(hdsp))
1757 val = ucontrol->
value.integer.value[0] & 1;
1758 spin_lock_irq(&hdsp->
lock);
1759 change = (
int)val != hdsp_spdif_professional(hdsp);
1760 hdsp_set_spdif_professional(hdsp, val);
1761 spin_unlock_irq(&hdsp->
lock);
1765 #define HDSP_SPDIF_EMPHASIS(xname, xindex) \
1766 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \
1767 .info = snd_hdsp_info_spdif_bits, \
1768 .get = snd_hdsp_get_spdif_emphasis, .put = snd_hdsp_put_spdif_emphasis }
1770 static int hdsp_spdif_emphasis(
struct hdsp *hdsp)
1775 static int hdsp_set_spdif_emphasis(
struct hdsp *hdsp,
int val)
1789 ucontrol->
value.integer.value[0] = hdsp_spdif_emphasis(hdsp);
1799 if (!snd_hdsp_use_is_exclusive(hdsp))
1801 val = ucontrol->
value.integer.value[0] & 1;
1802 spin_lock_irq(&hdsp->
lock);
1803 change = (
int)val != hdsp_spdif_emphasis(hdsp);
1804 hdsp_set_spdif_emphasis(hdsp, val);
1805 spin_unlock_irq(&hdsp->
lock);
1809 #define HDSP_SPDIF_NON_AUDIO(xname, xindex) \
1810 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \
1811 .info = snd_hdsp_info_spdif_bits, \
1812 .get = snd_hdsp_get_spdif_nonaudio, .put = snd_hdsp_put_spdif_nonaudio }
1814 static int hdsp_spdif_nonaudio(
struct hdsp *hdsp)
1819 static int hdsp_set_spdif_nonaudio(
struct hdsp *hdsp,
int val)
1833 ucontrol->
value.integer.value[0] = hdsp_spdif_nonaudio(hdsp);
1843 if (!snd_hdsp_use_is_exclusive(hdsp))
1845 val = ucontrol->
value.integer.value[0] & 1;
1846 spin_lock_irq(&hdsp->
lock);
1847 change = (
int)val != hdsp_spdif_nonaudio(hdsp);
1848 hdsp_set_spdif_nonaudio(hdsp, val);
1849 spin_unlock_irq(&hdsp->
lock);
1853 #define HDSP_SPDIF_SAMPLE_RATE(xname, xindex) \
1854 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1857 .access = SNDRV_CTL_ELEM_ACCESS_READ, \
1858 .info = snd_hdsp_info_spdif_sample_rate, \
1859 .get = snd_hdsp_get_spdif_sample_rate \
1864 static char *texts[] = {
"32000",
"44100",
"48000",
"64000",
"88200",
"96000",
"None",
"128000",
"176400",
"192000"};
1880 switch (hdsp_spdif_sample_rate(hdsp)) {
1882 ucontrol->
value.enumerated.item[0] = 0;
1885 ucontrol->
value.enumerated.item[0] = 1;
1888 ucontrol->
value.enumerated.item[0] = 2;
1891 ucontrol->
value.enumerated.item[0] = 3;
1894 ucontrol->
value.enumerated.item[0] = 4;
1897 ucontrol->
value.enumerated.item[0] = 5;
1900 ucontrol->
value.enumerated.item[0] = 7;
1903 ucontrol->
value.enumerated.item[0] = 8;
1906 ucontrol->
value.enumerated.item[0] = 9;
1909 ucontrol->
value.enumerated.item[0] = 6;
1914 #define HDSP_SYSTEM_SAMPLE_RATE(xname, xindex) \
1915 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1918 .access = SNDRV_CTL_ELEM_ACCESS_READ, \
1919 .info = snd_hdsp_info_system_sample_rate, \
1920 .get = snd_hdsp_get_system_sample_rate \
1938 #define HDSP_AUTOSYNC_SAMPLE_RATE(xname, xindex) \
1939 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
1942 .access = SNDRV_CTL_ELEM_ACCESS_READ, \
1943 .info = snd_hdsp_info_autosync_sample_rate, \
1944 .get = snd_hdsp_get_autosync_sample_rate \
1950 static char *texts[] = {
"32000",
"44100",
"48000",
"64000",
"88200",
"96000",
"None",
"128000",
"176400",
"192000"};
1964 switch (hdsp_external_sample_rate(hdsp)) {
1966 ucontrol->
value.enumerated.item[0] = 0;
1969 ucontrol->
value.enumerated.item[0] = 1;
1972 ucontrol->
value.enumerated.item[0] = 2;
1975 ucontrol->
value.enumerated.item[0] = 3;
1978 ucontrol->
value.enumerated.item[0] = 4;
1981 ucontrol->
value.enumerated.item[0] = 5;
1984 ucontrol->
value.enumerated.item[0] = 7;
1987 ucontrol->
value.enumerated.item[0] = 8;
1990 ucontrol->
value.enumerated.item[0] = 9;
1993 ucontrol->
value.enumerated.item[0] = 6;
1998 #define HDSP_SYSTEM_CLOCK_MODE(xname, xindex) \
1999 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2002 .access = SNDRV_CTL_ELEM_ACCESS_READ, \
2003 .info = snd_hdsp_info_system_clock_mode, \
2004 .get = snd_hdsp_get_system_clock_mode \
2007 static int hdsp_system_clock_mode(
struct hdsp *hdsp)
2018 static char *texts[] = {
"Master",
"Slave" };
2033 ucontrol->
value.enumerated.item[0] = hdsp_system_clock_mode(hdsp);
2037 #define HDSP_CLOCK_SOURCE(xname, xindex) \
2038 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2041 .info = snd_hdsp_info_clock_source, \
2042 .get = snd_hdsp_get_clock_source, \
2043 .put = snd_hdsp_put_clock_source \
2046 static int hdsp_clock_source(
struct hdsp *hdsp)
2076 static int hdsp_set_clock_source(
struct hdsp *hdsp,
int mode)
2081 if (hdsp_external_sample_rate(hdsp) != 0) {
2082 if (!hdsp_set_rate(hdsp, hdsp_external_sample_rate(hdsp), 1)) {
2121 hdsp_set_rate(hdsp, rate, 1);
2127 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" };
2146 ucontrol->
value.enumerated.item[0] = hdsp_clock_source(hdsp);
2156 if (!snd_hdsp_use_is_exclusive(hdsp))
2158 val = ucontrol->
value.enumerated.item[0];
2159 if (val < 0) val = 0;
2167 spin_lock_irq(&hdsp->
lock);
2168 if (val != hdsp_clock_source(hdsp))
2169 change = (hdsp_set_clock_source(hdsp, val) == 0) ? 1 : 0;
2172 spin_unlock_irq(&hdsp->
lock);
2176 #define snd_hdsp_info_clock_source_lock snd_ctl_boolean_mono_info
2197 #define HDSP_DA_GAIN(xname, xindex) \
2198 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2201 .info = snd_hdsp_info_da_gain, \
2202 .get = snd_hdsp_get_da_gain, \
2203 .put = snd_hdsp_put_da_gain \
2206 static int hdsp_da_gain(
struct hdsp *hdsp)
2220 static int hdsp_set_da_gain(
struct hdsp *hdsp,
int mode)
2243 static char *texts[] = {
"Hi Gain",
"+4 dBu",
"-10 dbV"};
2258 ucontrol->
value.enumerated.item[0] = hdsp_da_gain(hdsp);
2268 if (!snd_hdsp_use_is_exclusive(hdsp))
2270 val = ucontrol->
value.enumerated.item[0];
2271 if (val < 0) val = 0;
2272 if (val > 2) val = 2;
2273 spin_lock_irq(&hdsp->
lock);
2274 if (val != hdsp_da_gain(hdsp))
2275 change = (hdsp_set_da_gain(hdsp, val) == 0) ? 1 : 0;
2278 spin_unlock_irq(&hdsp->
lock);
2282 #define HDSP_AD_GAIN(xname, xindex) \
2283 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2286 .info = snd_hdsp_info_ad_gain, \
2287 .get = snd_hdsp_get_ad_gain, \
2288 .put = snd_hdsp_put_ad_gain \
2291 static int hdsp_ad_gain(
struct hdsp *hdsp)
2305 static int hdsp_set_ad_gain(
struct hdsp *hdsp,
int mode)
2328 static char *texts[] = {
"-10 dBV",
"+4 dBu",
"Lo Gain"};
2343 ucontrol->
value.enumerated.item[0] = hdsp_ad_gain(hdsp);
2353 if (!snd_hdsp_use_is_exclusive(hdsp))
2355 val = ucontrol->
value.enumerated.item[0];
2356 if (val < 0) val = 0;
2357 if (val > 2) val = 2;
2358 spin_lock_irq(&hdsp->
lock);
2359 if (val != hdsp_ad_gain(hdsp))
2360 change = (hdsp_set_ad_gain(hdsp, val) == 0) ? 1 : 0;
2363 spin_unlock_irq(&hdsp->
lock);
2367 #define HDSP_PHONE_GAIN(xname, xindex) \
2368 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2371 .info = snd_hdsp_info_phone_gain, \
2372 .get = snd_hdsp_get_phone_gain, \
2373 .put = snd_hdsp_put_phone_gain \
2376 static int hdsp_phone_gain(
struct hdsp *hdsp)
2390 static int hdsp_set_phone_gain(
struct hdsp *hdsp,
int mode)
2413 static char *texts[] = {
"0 dB",
"-6 dB",
"-12 dB"};
2428 ucontrol->
value.enumerated.item[0] = hdsp_phone_gain(hdsp);
2438 if (!snd_hdsp_use_is_exclusive(hdsp))
2440 val = ucontrol->
value.enumerated.item[0];
2441 if (val < 0) val = 0;
2442 if (val > 2) val = 2;
2443 spin_lock_irq(&hdsp->
lock);
2444 if (val != hdsp_phone_gain(hdsp))
2445 change = (hdsp_set_phone_gain(hdsp, val) == 0) ? 1 : 0;
2448 spin_unlock_irq(&hdsp->
lock);
2452 #define HDSP_XLR_BREAKOUT_CABLE(xname, xindex) \
2453 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2456 .info = snd_hdsp_info_xlr_breakout_cable, \
2457 .get = snd_hdsp_get_xlr_breakout_cable, \
2458 .put = snd_hdsp_put_xlr_breakout_cable \
2461 static int hdsp_xlr_breakout_cable(
struct hdsp *hdsp)
2468 static int hdsp_set_xlr_breakout_cable(
struct hdsp *hdsp,
int mode)
2478 #define snd_hdsp_info_xlr_breakout_cable snd_ctl_boolean_mono_info
2484 ucontrol->
value.enumerated.item[0] = hdsp_xlr_breakout_cable(hdsp);
2494 if (!snd_hdsp_use_is_exclusive(hdsp))
2496 val = ucontrol->
value.integer.value[0] & 1;
2497 spin_lock_irq(&hdsp->
lock);
2498 change = (
int)val != hdsp_xlr_breakout_cable(hdsp);
2499 hdsp_set_xlr_breakout_cable(hdsp, val);
2500 spin_unlock_irq(&hdsp->
lock);
2508 #define HDSP_AEB(xname, xindex) \
2509 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2512 .info = snd_hdsp_info_aeb, \
2513 .get = snd_hdsp_get_aeb, \
2514 .put = snd_hdsp_put_aeb \
2517 static int hdsp_aeb(
struct hdsp *hdsp)
2524 static int hdsp_set_aeb(
struct hdsp *hdsp,
int mode)
2534 #define snd_hdsp_info_aeb snd_ctl_boolean_mono_info
2540 ucontrol->
value.enumerated.item[0] = hdsp_aeb(hdsp);
2550 if (!snd_hdsp_use_is_exclusive(hdsp))
2552 val = ucontrol->
value.integer.value[0] & 1;
2553 spin_lock_irq(&hdsp->
lock);
2554 change = (
int)val != hdsp_aeb(hdsp);
2555 hdsp_set_aeb(hdsp, val);
2556 spin_unlock_irq(&hdsp->
lock);
2560 #define HDSP_PREF_SYNC_REF(xname, xindex) \
2561 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2564 .info = snd_hdsp_info_pref_sync_ref, \
2565 .get = snd_hdsp_get_pref_sync_ref, \
2566 .put = snd_hdsp_put_pref_sync_ref \
2569 static int hdsp_pref_sync_ref(
struct hdsp *hdsp)
2594 static int hdsp_set_pref_sync_ref(
struct hdsp *hdsp,
int pref)
2625 static char *texts[] = {
"Word",
"IEC958",
"ADAT1",
"ADAT Sync",
"ADAT2",
"ADAT3" };
2656 ucontrol->
value.enumerated.item[0] = hdsp_pref_sync_ref(hdsp);
2666 if (!snd_hdsp_use_is_exclusive(hdsp))
2684 val = ucontrol->
value.enumerated.item[0] %
max;
2685 spin_lock_irq(&hdsp->
lock);
2686 change = (
int)val != hdsp_pref_sync_ref(hdsp);
2687 hdsp_set_pref_sync_ref(hdsp, val);
2688 spin_unlock_irq(&hdsp->
lock);
2692 #define HDSP_AUTOSYNC_REF(xname, xindex) \
2693 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2696 .access = SNDRV_CTL_ELEM_ACCESS_READ, \
2697 .info = snd_hdsp_info_autosync_ref, \
2698 .get = snd_hdsp_get_autosync_ref, \
2701 static int hdsp_autosync_ref(
struct hdsp *hdsp)
2713 case HDSP_SelSyncRefMask:
2729 static char *texts[] = {
"Word",
"ADAT Sync",
"IEC958",
"None",
"ADAT1",
"ADAT2",
"ADAT3" };
2744 ucontrol->
value.enumerated.item[0] = hdsp_autosync_ref(hdsp);
2748 #define HDSP_LINE_OUT(xname, xindex) \
2749 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2752 .info = snd_hdsp_info_line_out, \
2753 .get = snd_hdsp_get_line_out, \
2754 .put = snd_hdsp_put_line_out \
2757 static int hdsp_line_out(
struct hdsp *hdsp)
2762 static int hdsp_set_line_output(
struct hdsp *hdsp,
int out)
2772 #define snd_hdsp_info_line_out snd_ctl_boolean_mono_info
2778 spin_lock_irq(&hdsp->
lock);
2779 ucontrol->
value.integer.value[0] = hdsp_line_out(hdsp);
2780 spin_unlock_irq(&hdsp->
lock);
2790 if (!snd_hdsp_use_is_exclusive(hdsp))
2792 val = ucontrol->
value.integer.value[0] & 1;
2793 spin_lock_irq(&hdsp->
lock);
2794 change = (
int)val != hdsp_line_out(hdsp);
2795 hdsp_set_line_output(hdsp, val);
2796 spin_unlock_irq(&hdsp->
lock);
2800 #define HDSP_PRECISE_POINTER(xname, xindex) \
2801 { .iface = SNDRV_CTL_ELEM_IFACE_CARD, \
2804 .info = snd_hdsp_info_precise_pointer, \
2805 .get = snd_hdsp_get_precise_pointer, \
2806 .put = snd_hdsp_put_precise_pointer \
2809 static int hdsp_set_precise_pointer(
struct hdsp *hdsp,
int precise)
2818 #define snd_hdsp_info_precise_pointer snd_ctl_boolean_mono_info
2824 spin_lock_irq(&hdsp->
lock);
2826 spin_unlock_irq(&hdsp->
lock);
2836 if (!snd_hdsp_use_is_exclusive(hdsp))
2838 val = ucontrol->
value.integer.value[0] & 1;
2839 spin_lock_irq(&hdsp->
lock);
2841 hdsp_set_precise_pointer(hdsp, val);
2842 spin_unlock_irq(&hdsp->
lock);
2846 #define HDSP_USE_MIDI_TASKLET(xname, xindex) \
2847 { .iface = SNDRV_CTL_ELEM_IFACE_CARD, \
2850 .info = snd_hdsp_info_use_midi_tasklet, \
2851 .get = snd_hdsp_get_use_midi_tasklet, \
2852 .put = snd_hdsp_put_use_midi_tasklet \
2855 static int hdsp_set_use_midi_tasklet(
struct hdsp *hdsp,
int use_tasklet)
2864 #define snd_hdsp_info_use_midi_tasklet snd_ctl_boolean_mono_info
2870 spin_lock_irq(&hdsp->
lock);
2872 spin_unlock_irq(&hdsp->
lock);
2882 if (!snd_hdsp_use_is_exclusive(hdsp))
2884 val = ucontrol->
value.integer.value[0] & 1;
2885 spin_lock_irq(&hdsp->
lock);
2887 hdsp_set_use_midi_tasklet(hdsp, val);
2888 spin_unlock_irq(&hdsp->
lock);
2892 #define HDSP_MIXER(xname, xindex) \
2893 { .iface = SNDRV_CTL_ELEM_IFACE_HWDEP, \
2897 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | \
2898 SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
2899 .info = snd_hdsp_info_mixer, \
2900 .get = snd_hdsp_get_mixer, \
2901 .put = snd_hdsp_put_mixer \
2921 source = ucontrol->
value.integer.value[0];
2922 destination = ucontrol->
value.integer.value[1];
2925 addr = hdsp_playback_to_output_key(hdsp,source-hdsp->
max_channels,destination);
2927 addr = hdsp_input_to_output_key(hdsp,source, destination);
2929 spin_lock_irq(&hdsp->
lock);
2930 ucontrol->
value.integer.value[2] = hdsp_read_gain (hdsp, addr);
2931 spin_unlock_irq(&hdsp->
lock);
2944 if (!snd_hdsp_use_is_exclusive(hdsp))
2947 source = ucontrol->
value.integer.value[0];
2948 destination = ucontrol->
value.integer.value[1];
2951 addr = hdsp_playback_to_output_key(hdsp,source-hdsp->
max_channels, destination);
2953 addr = hdsp_input_to_output_key(hdsp,source, destination);
2955 gain = ucontrol->
value.integer.value[2];
2957 spin_lock_irq(&hdsp->
lock);
2958 change = gain != hdsp_read_gain(hdsp, addr);
2960 hdsp_write_gain(hdsp, addr, gain);
2961 spin_unlock_irq(&hdsp->
lock);
2965 #define HDSP_WC_SYNC_CHECK(xname, xindex) \
2966 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2969 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
2970 .info = snd_hdsp_info_sync_check, \
2971 .get = snd_hdsp_get_wc_sync_check \
2976 static char *texts[] = {
"No Lock",
"Lock",
"Sync" };
2986 static int hdsp_wc_sync_check(
struct hdsp *hdsp)
3003 ucontrol->
value.enumerated.item[0] = hdsp_wc_sync_check(hdsp);
3007 #define HDSP_SPDIF_SYNC_CHECK(xname, xindex) \
3008 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
3011 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
3012 .info = snd_hdsp_info_sync_check, \
3013 .get = snd_hdsp_get_spdif_sync_check \
3016 static int hdsp_spdif_sync_check(
struct hdsp *hdsp)
3019 if (status & HDSP_SPDIFErrorFlag)
3034 ucontrol->
value.enumerated.item[0] = hdsp_spdif_sync_check(hdsp);
3038 #define HDSP_ADATSYNC_SYNC_CHECK(xname, xindex) \
3039 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
3042 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
3043 .info = snd_hdsp_info_sync_check, \
3044 .get = snd_hdsp_get_adatsync_sync_check \
3047 static int hdsp_adatsync_sync_check(
struct hdsp *hdsp)
3063 ucontrol->
value.enumerated.item[0] = hdsp_adatsync_sync_check(hdsp);
3067 #define HDSP_ADAT_SYNC_CHECK \
3068 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
3069 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
3070 .info = snd_hdsp_info_sync_check, \
3071 .get = snd_hdsp_get_adat_sync_check \
3074 static int hdsp_adat_sync_check(
struct hdsp *hdsp,
int idx)
3092 offset = ucontrol->
id.index - 1;
3110 ucontrol->
value.enumerated.item[0] = hdsp_adat_sync_check(hdsp, offset);
3114 #define HDSP_DDS_OFFSET(xname, xindex) \
3115 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
3118 .info = snd_hdsp_info_dds_offset, \
3119 .get = snd_hdsp_get_dds_offset, \
3120 .put = snd_hdsp_put_dds_offset \
3123 static int hdsp_dds_offset(
struct hdsp *hdsp)
3137 n = div_u64(n, dds_value);
3138 if (system_sample_rate >= 112000)
3140 else if (system_sample_rate >= 56000)
3145 static int hdsp_set_dds_offset(
struct hdsp *hdsp,
int offset_hz)
3148 hdsp_set_dds_value(hdsp, rate);
3165 ucontrol->
value.enumerated.item[0] = hdsp_dds_offset(hdsp);
3175 if (!snd_hdsp_use_is_exclusive(hdsp))
3177 val = ucontrol->
value.enumerated.item[0];
3178 spin_lock_irq(&hdsp->
lock);
3179 if (val != hdsp_dds_offset(hdsp))
3180 change = (hdsp_set_dds_offset(hdsp, val) == 0) ? 1 : 0;
3183 spin_unlock_irq(&hdsp->
lock);
3199 .info = snd_hdsp_control_spdif_info,
3200 .get = snd_hdsp_control_spdif_get,
3201 .put = snd_hdsp_control_spdif_put,
3207 .info = snd_hdsp_control_spdif_stream_info,
3208 .get = snd_hdsp_control_spdif_stream_get,
3209 .put = snd_hdsp_control_spdif_stream_put,
3215 .info = snd_hdsp_control_spdif_mask_info,
3216 .get = snd_hdsp_control_spdif_mask_get,
3217 .private_value = IEC958_AES0_NONAUDIO |
3225 .info = snd_hdsp_control_spdif_mask_info,
3226 .get = snd_hdsp_control_spdif_mask_get,
3227 .private_value = IEC958_AES0_NONAUDIO |
3241 .name =
"Sample Clock Source Locking",
3243 .get = snd_hdsp_get_clock_source_lock,
3244 .put = snd_hdsp_put_clock_source_lock,
3262 static int hdsp_rpm_input12(
struct hdsp *hdsp)
3282 ucontrol->
value.enumerated.item[0] = hdsp_rpm_input12(hdsp);
3287 static int hdsp_set_rpm_input12(
struct hdsp *hdsp,
int mode)
3320 if (!snd_hdsp_use_is_exclusive(hdsp))
3322 val = ucontrol->
value.enumerated.item[0];
3327 spin_lock_irq(&hdsp->
lock);
3328 if (val != hdsp_rpm_input12(hdsp))
3329 change = (hdsp_set_rpm_input12(hdsp, val) == 0) ? 1 : 0;
3332 spin_unlock_irq(&hdsp->
lock);
3339 static char *texts[] = {
"Phono +6dB",
"Phono 0dB",
"Phono -6dB",
"Line 0dB",
"Line -6dB"};
3351 static int hdsp_rpm_input34(
struct hdsp *hdsp)
3371 ucontrol->
value.enumerated.item[0] = hdsp_rpm_input34(hdsp);
3376 static int hdsp_set_rpm_input34(
struct hdsp *hdsp,
int mode)
3409 if (!snd_hdsp_use_is_exclusive(hdsp))
3411 val = ucontrol->
value.enumerated.item[0];
3416 spin_lock_irq(&hdsp->
lock);
3417 if (val != hdsp_rpm_input34(hdsp))
3418 change = (hdsp_set_rpm_input34(hdsp, val) == 0) ? 1 : 0;
3421 spin_unlock_irq(&hdsp->
lock);
3427 static int hdsp_rpm_bypass(
struct hdsp *hdsp)
3437 ucontrol->
value.integer.value[0] = hdsp_rpm_bypass(hdsp);
3442 static int hdsp_set_rpm_bypass(
struct hdsp *hdsp,
int on)
3459 if (!snd_hdsp_use_is_exclusive(hdsp))
3461 val = ucontrol->
value.integer.value[0] & 1;
3462 spin_lock_irq(&hdsp->
lock);
3463 change = (
int)val != hdsp_rpm_bypass(hdsp);
3464 hdsp_set_rpm_bypass(hdsp, val);
3465 spin_unlock_irq(&hdsp->
lock);
3472 static char *texts[] = {
"On",
"Off"};
3485 static int hdsp_rpm_disconnect(
struct hdsp *hdsp)
3495 ucontrol->
value.integer.value[0] = hdsp_rpm_disconnect(hdsp);
3500 static int hdsp_set_rpm_disconnect(
struct hdsp *hdsp,
int on)
3517 if (!snd_hdsp_use_is_exclusive(hdsp))
3519 val = ucontrol->
value.integer.value[0] & 1;
3520 spin_lock_irq(&hdsp->
lock);
3521 change = (
int)val != hdsp_rpm_disconnect(hdsp);
3522 hdsp_set_rpm_disconnect(hdsp, val);
3523 spin_unlock_irq(&hdsp->
lock);
3529 static char *texts[] = {
"On",
"Off"};
3543 .name =
"RPM Bypass",
3544 .get = snd_hdsp_get_rpm_bypass,
3545 .put = snd_hdsp_put_rpm_bypass,
3546 .info = snd_hdsp_info_rpm_bypass
3550 .name =
"RPM Disconnect",
3551 .get = snd_hdsp_get_rpm_disconnect,
3552 .put = snd_hdsp_put_rpm_disconnect,
3553 .info = snd_hdsp_info_rpm_disconnect
3557 .name =
"Input 1/2",
3558 .get = snd_hdsp_get_rpm_input12,
3559 .put = snd_hdsp_put_rpm_input12,
3560 .info = snd_hdsp_info_rpm_input
3564 .name =
"Input 3/4",
3565 .get = snd_hdsp_get_rpm_input34,
3566 .put = snd_hdsp_put_rpm_input34,
3567 .info = snd_hdsp_info_rpm_input
3576 static int snd_hdsp_create_controls(
struct snd_card *card,
struct hdsp *hdsp)
3584 for (idx = 0; idx <
ARRAY_SIZE(snd_hdsp_rpm_controls); idx++) {
3592 for (idx = 0; idx <
ARRAY_SIZE(snd_hdsp_controls); idx++) {
3600 snd_hdsp_adat_sync_check.
name =
"ADAT Lock Status";
3601 snd_hdsp_adat_sync_check.
index = 1;
3605 for (idx = 1; idx < 3; ++
idx) {
3606 snd_hdsp_adat_sync_check.
index = idx+1;
3614 for (idx = 0; idx <
ARRAY_SIZE(snd_hdsp_9632_controls); idx++) {
3639 char *pref_sync_ref;
3641 char *system_clock_mode;
3648 snd_iprintf(buffer,
"%s (Card #%d)\n", hdsp->
card_name,
3649 hdsp->
card->number + 1);
3650 snd_iprintf(buffer,
"Buffers: capture %p playback %p\n",
3652 snd_iprintf(buffer,
"IRQ: %d Registers bus: 0x%lx VM: 0x%lx\n",
3655 snd_iprintf(buffer,
"Control2 register: 0x%x\n",
3657 snd_iprintf(buffer,
"Status register: 0x%x\n", status);
3658 snd_iprintf(buffer,
"Status2 register: 0x%x\n", status2);
3660 if (hdsp_check_for_iobox(hdsp)) {
3661 snd_iprintf(buffer,
"No I/O box connected.\n"
3662 "Please connect one and upload firmware.\n");
3666 if (hdsp_check_for_firmware(hdsp, 0)) {
3668 if (snd_hdsp_load_firmware_from_cache(hdsp) != 0) {
3669 snd_iprintf(buffer,
"Firmware loading from "
3671 "please upload manually.\n");
3676 #ifdef HDSP_FW_LOADER
3677 err = hdsp_request_fw_loader(hdsp);
3681 "No firmware loaded nor cached, "
3682 "please upload firmware.\n");
3688 snd_iprintf(buffer,
"FIFO status: %d\n", hdsp_read(hdsp,
HDSP_fifoStatus) & 0xff);
3690 snd_iprintf(buffer,
"MIDI1 Input status: 0x%x\n", hdsp_read(hdsp,
HDSP_midiStatusIn0));
3692 snd_iprintf(buffer,
"MIDI2 Input status: 0x%x\n", hdsp_read(hdsp,
HDSP_midiStatusIn1));
3693 snd_iprintf(buffer,
"Use Midi Tasklet: %s\n", hdsp->
use_midi_tasklet ?
"on" :
"off");
3695 snd_iprintf(buffer,
"\n");
3699 snd_iprintf(buffer,
"Buffer Size (Latency): %d samples (2 periods of %lu bytes)\n", x, (
unsigned long) hdsp->
period_bytes);
3700 snd_iprintf(buffer,
"Hardware pointer (frames): %ld\n", hdsp_hw_pointer(hdsp));
3701 snd_iprintf(buffer,
"Precise pointer: %s\n", hdsp->
precise_ptr ?
"on" :
"off");
3704 snd_iprintf(buffer,
"Firmware version: %d\n", (status2&
HDSP_version0)|(status2&
HDSP_version1)<<1|(status2&HDSP_version2)<<2);
3706 snd_iprintf(buffer,
"\n");
3708 switch (hdsp_clock_source(hdsp)) {
3710 clock_source =
"AutoSync";
3713 clock_source =
"Internal 32 kHz";
3716 clock_source =
"Internal 44.1 kHz";
3719 clock_source =
"Internal 48 kHz";
3722 clock_source =
"Internal 64 kHz";
3725 clock_source =
"Internal 88.2 kHz";
3728 clock_source =
"Internal 96 kHz";
3731 clock_source =
"Internal 128 kHz";
3734 clock_source =
"Internal 176.4 kHz";
3737 clock_source =
"Internal 192 kHz";
3740 clock_source =
"Error";
3742 snd_iprintf (buffer,
"Sample Clock Source: %s\n", clock_source);
3744 if (hdsp_system_clock_mode(hdsp))
3745 system_clock_mode =
"Slave";
3747 system_clock_mode =
"Master";
3749 switch (hdsp_pref_sync_ref (hdsp)) {
3751 pref_sync_ref =
"Word Clock";
3754 pref_sync_ref =
"ADAT Sync";
3757 pref_sync_ref =
"SPDIF";
3760 pref_sync_ref =
"ADAT1";
3763 pref_sync_ref =
"ADAT2";
3766 pref_sync_ref =
"ADAT3";
3769 pref_sync_ref =
"Word Clock";
3772 snd_iprintf (buffer,
"Preferred Sync Reference: %s\n", pref_sync_ref);
3774 switch (hdsp_autosync_ref (hdsp)) {
3776 autosync_ref =
"Word Clock";
3779 autosync_ref =
"ADAT Sync";
3782 autosync_ref =
"SPDIF";
3785 autosync_ref =
"None";
3788 autosync_ref =
"ADAT1";
3791 autosync_ref =
"ADAT2";
3794 autosync_ref =
"ADAT3";
3797 autosync_ref =
"---";
3800 snd_iprintf (buffer,
"AutoSync Reference: %s\n", autosync_ref);
3802 snd_iprintf (buffer,
"AutoSync Frequency: %d\n", hdsp_external_sample_rate(hdsp));
3804 snd_iprintf (buffer,
"System Clock Mode: %s\n", system_clock_mode);
3807 snd_iprintf (buffer,
"System Clock Locked: %s\n", hdsp->
clock_source_locked ?
"Yes" :
"No");
3809 snd_iprintf(buffer,
"\n");
3812 switch (hdsp_spdif_in(hdsp)) {
3814 snd_iprintf(buffer,
"IEC958 input: Optical\n");
3817 snd_iprintf(buffer,
"IEC958 input: Coaxial\n");
3820 snd_iprintf(buffer,
"IEC958 input: Internal\n");
3823 snd_iprintf(buffer,
"IEC958 input: AES\n");
3826 snd_iprintf(buffer,
"IEC958 input: ???\n");
3833 snd_iprintf(buffer,
"RPM Bypass: disabled\n");
3835 snd_iprintf(buffer,
"RPM Bypass: enabled\n");
3837 snd_iprintf(buffer,
"RPM disconnected\n");
3839 snd_iprintf(buffer,
"RPM connected\n");
3843 snd_iprintf(buffer,
"Input 1/2: Phono, 6dB\n");
3846 snd_iprintf(buffer,
"Input 1/2: Phono, 0dB\n");
3849 snd_iprintf(buffer,
"Input 1/2: Phono, -6dB\n");
3852 snd_iprintf(buffer,
"Input 1/2: Line, 0dB\n");
3855 snd_iprintf(buffer,
"Input 1/2: Line, -6dB\n");
3858 snd_iprintf(buffer,
"Input 1/2: ???\n");
3863 snd_iprintf(buffer,
"Input 3/4: Phono, 6dB\n");
3866 snd_iprintf(buffer,
"Input 3/4: Phono, 0dB\n");
3869 snd_iprintf(buffer,
"Input 3/4: Phono, -6dB\n");
3872 snd_iprintf(buffer,
"Input 3/4: Line, 0dB\n");
3875 snd_iprintf(buffer,
"Input 3/4: Line, -6dB\n");
3878 snd_iprintf(buffer,
"Input 3/4: ???\n");
3883 snd_iprintf(buffer,
"IEC958 output: Coaxial & ADAT1\n");
3885 snd_iprintf(buffer,
"IEC958 output: Coaxial only\n");
3888 snd_iprintf(buffer,
"IEC958 quality: Professional\n");
3890 snd_iprintf(buffer,
"IEC958 quality: Consumer\n");
3893 snd_iprintf(buffer,
"IEC958 emphasis: on\n");
3895 snd_iprintf(buffer,
"IEC958 emphasis: off\n");
3898 snd_iprintf(buffer,
"IEC958 NonAudio: on\n");
3900 snd_iprintf(buffer,
"IEC958 NonAudio: off\n");
3901 x = hdsp_spdif_sample_rate(hdsp);
3903 snd_iprintf(buffer,
"IEC958 sample rate: %d\n", x);
3905 snd_iprintf(buffer,
"IEC958 sample rate: Error flag set\n");
3907 snd_iprintf(buffer,
"\n");
3912 snd_iprintf(buffer,
"ADAT1: %s\n", x ?
"Sync" :
"Lock");
3914 snd_iprintf(buffer,
"ADAT1: No Lock\n");
3921 snd_iprintf(buffer,
"ADAT2: %s\n", x ?
"Sync" :
"Lock");
3923 snd_iprintf(buffer,
"ADAT2: No Lock\n");
3926 snd_iprintf(buffer,
"ADAT3: %s\n", x ?
"Sync" :
"Lock");
3928 snd_iprintf(buffer,
"ADAT3: No Lock\n");
3936 if (status & HDSP_SPDIFErrorFlag)
3937 snd_iprintf (buffer,
"SPDIF: No Lock\n");
3939 snd_iprintf (buffer,
"SPDIF: %s\n", x ?
"Sync" :
"Lock");
3942 if (status2 & HDSP_wc_lock)
3943 snd_iprintf (buffer,
"Word Clock: %s\n", x ?
"Sync" :
"Lock");
3945 snd_iprintf (buffer,
"Word Clock: No Lock\n");
3949 snd_iprintf(buffer,
"ADAT Sync: %s\n", x ?
"Sync" :
"Lock");
3951 snd_iprintf(buffer,
"ADAT Sync: No Lock\n");
3953 snd_iprintf(buffer,
"\n");
3959 switch (hdsp_ad_gain(hdsp)) {
3970 snd_iprintf(buffer,
"AD Gain : %s\n", tmp);
3972 switch (hdsp_da_gain(hdsp)) {
3983 snd_iprintf(buffer,
"DA Gain : %s\n", tmp);
3985 switch (hdsp_phone_gain(hdsp)) {
3996 snd_iprintf(buffer,
"Phones Gain : %s\n", tmp);
3998 snd_iprintf(buffer,
"XLR Breakout Cable : %s\n", hdsp_xlr_breakout_cable(hdsp) ?
"yes" :
"no");
4001 snd_iprintf(buffer,
"AEB : on (ADAT1 internal)\n");
4003 snd_iprintf(buffer,
"AEB : off (ADAT1 external)\n");
4004 snd_iprintf(buffer,
"\n");
4009 static void snd_hdsp_proc_init(
struct hdsp *hdsp)
4013 if (! snd_card_proc_new(hdsp->
card,
"hdsp", &entry))
4014 snd_info_set_text_ops(entry, hdsp, snd_hdsp_proc_read);
4017 static void snd_hdsp_free_buffers(
struct hdsp *hdsp)
4023 static int __devinit snd_hdsp_initialize_memory(
struct hdsp *hdsp)
4025 unsigned long pb_bus, cb_bus;
4051 static int snd_hdsp_set_defaults(
struct hdsp *hdsp)
4077 #ifdef SNDRV_BIG_ENDIAN
4083 snd_hdsp_9652_enable_mixer (hdsp);
4087 hdsp_reset_hw_pointer(hdsp);
4088 hdsp_compute_period_size(hdsp);
4109 hdsp_set_rate(hdsp, 48000, 1);
4114 static void hdsp_midi_tasklet(
unsigned long arg)
4116 struct hdsp *hdsp = (
struct hdsp *)arg;
4118 if (hdsp->
midi[0].pending)
4119 snd_hdsp_midi_input_read (&hdsp->
midi[0]);
4120 if (hdsp->
midi[1].pending)
4121 snd_hdsp_midi_input_read (&hdsp->
midi[1]);
4126 struct hdsp *hdsp = (
struct hdsp *) dev_id;
4131 unsigned int midi0status;
4132 unsigned int midi1status;
4141 if (!audio && !midi0 && !midi1)
4160 if (midi0 && midi0status) {
4165 hdsp->
midi[0].pending = 1;
4168 snd_hdsp_midi_input_read (&hdsp->
midi[0]);
4176 hdsp->
midi[1].pending = 1;
4179 snd_hdsp_midi_input_read (&hdsp->
midi[1]);
4190 return hdsp_hw_pointer(hdsp);
4193 static char *hdsp_channel_buffer_location(
struct hdsp *hdsp,
4203 if ((mapped_channel = hdsp->
channel_map[channel]) < 0)
4212 static int snd_hdsp_playback_copy(
struct snd_pcm_substream *substream,
int channel,
4221 channel_buf = hdsp_channel_buffer_location (hdsp, substream->
pstr->stream, channel);
4229 static int snd_hdsp_capture_copy(
struct snd_pcm_substream *substream,
int channel,
4238 channel_buf = hdsp_channel_buffer_location (hdsp, substream->
pstr->stream, channel);
4241 if (
copy_to_user(dst, channel_buf + pos * 4, count * 4))
4246 static int snd_hdsp_hw_silence(
struct snd_pcm_substream *substream,
int channel,
4252 channel_buf = hdsp_channel_buffer_location (hdsp, substream->
pstr->stream, channel);
4255 memset(channel_buf + pos * 4, 0, count * 4);
4269 runtime->
status->hw_ptr = hdsp_hw_pointer(hdsp);
4271 runtime->
status->hw_ptr = 0;
4293 if (hdsp_check_for_iobox (hdsp))
4296 if (hdsp_check_for_firmware(hdsp, 1))
4299 spin_lock_irq(&hdsp->
lock);
4311 if ((other_pid > 0) && (this_pid != other_pid)) {
4319 spin_unlock_irq(&hdsp->
lock);
4325 spin_unlock_irq(&hdsp->
lock);
4332 spin_unlock_irq(&hdsp->
lock);
4336 spin_unlock_irq(&hdsp->
lock);
4342 spin_lock_irq(&hdsp->
lock);
4344 if ((err = hdsp_set_rate(hdsp,
params_rate(params), 0)) < 0) {
4345 spin_unlock_irq(&hdsp->
lock);
4350 spin_unlock_irq(&hdsp->
lock);
4379 unsigned int cmd,
void *arg)
4383 return snd_hdsp_reset(substream);
4385 return snd_hdsp_channel_info(substream, arg);
4399 if (hdsp_check_for_iobox (hdsp))
4402 if (hdsp_check_for_firmware(hdsp, 0))
4405 spin_lock(&hdsp->
lock);
4409 running |= 1 << substream->
stream;
4412 running &= ~(1 << substream->
stream);
4416 spin_unlock(&hdsp->
lock);
4428 snd_pcm_trigger_done(s, substream);
4430 running |= 1 << s->
stream;
4432 running &= ~(1 << s->
stream);
4439 hdsp_silence_playback(hdsp);
4443 hdsp_silence_playback(hdsp);
4447 hdsp_silence_playback(hdsp);
4450 snd_pcm_trigger_done(substream, substream);
4451 if (!hdsp->
running && running)
4452 hdsp_start_audio(hdsp);
4453 else if (hdsp->
running && !running)
4454 hdsp_stop_audio(hdsp);
4456 spin_unlock(&hdsp->
lock);
4466 if (hdsp_check_for_iobox (hdsp))
4469 if (hdsp_check_for_firmware(hdsp, 1))
4472 spin_lock_irq(&hdsp->
lock);
4474 hdsp_reset_hw_pointer(hdsp);
4475 spin_unlock_irq(&hdsp->
lock);
4486 #ifdef SNDRV_BIG_ENDIAN
4502 .period_bytes_min = (64 * 4) * 10,
4515 #ifdef SNDRV_BIG_ENDIAN
4531 .period_bytes_min = (64 * 4) * 10,
4538 static unsigned int hdsp_period_sizes[] = { 64, 128, 256, 512, 1024, 2048, 4096, 8192 };
4542 .list = hdsp_period_sizes,
4546 static unsigned int hdsp_9632_sample_rates[] = { 32000, 44100, 48000, 64000, 88200, 96000, 128000, 176400, 192000 };
4550 .list = hdsp_9632_sample_rates,
4557 struct hdsp *hdsp = rule->
private;
4560 unsigned int list[3];
4566 unsigned int list[2];
4576 unsigned int list[3];
4577 struct hdsp *hdsp = rule->
private;
4594 struct hdsp *hdsp = rule->
private;
4604 }
else if (r->
min > 48000 && r->
max <= 96000) {
4611 }
else if (r->
max < 64000) {
4625 struct hdsp *hdsp = rule->
private;
4635 }
else if (r->
min > 48000 && r->
max <= 96000) {
4642 }
else if (r->
max < 64000) {
4656 struct hdsp *hdsp = rule->
private;
4687 struct hdsp *hdsp = rule->
private;
4720 if (hdsp_check_for_iobox (hdsp))
4723 if (hdsp_check_for_firmware(hdsp, 1))
4726 spin_lock_irq(&hdsp->
lock);
4730 runtime->
hw = snd_hdsp_playback_subinfo;
4737 spin_unlock_irq(&hdsp->
lock);
4744 runtime->
hw.rate_max = 192000;
4754 snd_hdsp_hw_rule_out_channels, hdsp,
4757 snd_hdsp_hw_rule_out_channels_rate, hdsp,
4760 snd_hdsp_hw_rule_rate_out_channels, hdsp,
4776 spin_lock_irq(&hdsp->
lock);
4781 spin_unlock_irq(&hdsp->
lock);
4797 if (hdsp_check_for_iobox (hdsp))
4800 if (hdsp_check_for_firmware(hdsp, 1))
4803 spin_lock_irq(&hdsp->
lock);
4807 runtime->
hw = snd_hdsp_capture_subinfo;
4814 spin_unlock_irq(&hdsp->
lock);
4821 runtime->
hw.rate_max = 192000;
4826 snd_hdsp_hw_rule_in_channels, hdsp,
4829 snd_hdsp_hw_rule_in_channels_rate, hdsp,
4832 snd_hdsp_hw_rule_rate_in_channels, hdsp,
4841 spin_lock_irq(&hdsp->
lock);
4846 spin_unlock_irq(&hdsp->
lock);
4851 static inline int copy_u32_le(
void __user *
dest,
void __iomem *src)
4857 static inline int copy_u64_le(
void __user *
dest,
void __iomem *src_low,
void __iomem *src_high)
4859 u32 rms_low, rms_high;
4861 rms_low =
readl(src_low);
4862 rms_high =
readl(src_high);
4863 rms = ((
u64)rms_high << 32) | rms_low;
4867 static inline int copy_u48_le(
void __user *
dest,
void __iomem *src_low,
void __iomem *src_high)
4869 u32 rms_low, rms_high;
4871 rms_low =
readl(src_low) & 0xffffff00;
4872 rms_high =
readl(src_high) & 0xffffff00;
4873 rms = ((
u64)rms_high << 32) | rms_low;
4877 static int hdsp_9652_get_peak(
struct hdsp *hdsp,
struct hdsp_peak_rms __user *peak_rms)
4879 int doublespeed = 0;
4884 channels = doublespeed ? 14 : 26;
4885 for (i = 0, j = 0; i < 26; ++
i) {
4886 if (doublespeed && (i & 4))
4889 if (copy_u32_le(&peak_rms->input_peaks[i], hdsp->
iobase + ofs))
4891 ofs -= channels * 4;
4892 if (copy_u32_le(&peak_rms->playback_peaks[i], hdsp->
iobase + ofs))
4894 ofs -= channels * 4;
4895 if (copy_u32_le(&peak_rms->output_peaks[i], hdsp->
iobase + ofs))
4898 if (copy_u48_le(&peak_rms->input_rms[i], hdsp->
iobase + ofs,
4901 ofs += channels * 8;
4902 if (copy_u48_le(&peak_rms->playback_rms[i], hdsp->
iobase + ofs,
4905 ofs += channels * 8;
4906 if (copy_u48_le(&peak_rms->output_rms[i], hdsp->
iobase + ofs,
4914 static int hdsp_9632_get_peak(
struct hdsp *hdsp,
struct hdsp_peak_rms __user *peak_rms)
4918 int doublespeed = 0;
4923 for (i = 0, j = 0; i < 16; ++
i, ++
j) {
4924 if (copy_u32_le(&peak_rms->input_peaks[i], &m->
input_peak[j]))
4926 if (copy_u32_le(&peak_rms->playback_peaks[i], &m->
playback_peak[j]))
4928 if (copy_u32_le(&peak_rms->output_peaks[i], &m->
output_peak[j]))
4930 if (copy_u64_le(&peak_rms->input_rms[i], &m->
input_rms_low[j],
4939 if (doublespeed && i == 3) i += 4;
4944 static int hdsp_get_peak(
struct hdsp *hdsp,
struct hdsp_peak_rms __user *peak_rms)
4948 for (i = 0; i < 26; i++) {
4949 if (copy_u32_le(&peak_rms->playback_peaks[i],
4952 if (copy_u32_le(&peak_rms->input_peaks[i],
4956 for (i = 0; i < 28; i++) {
4957 if (copy_u32_le(&peak_rms->output_peaks[i],
4961 for (i = 0; i < 26; ++
i) {
4962 if (copy_u64_le(&peak_rms->playback_rms[i],
4966 if (copy_u64_le(&peak_rms->input_rms[i],
4974 static int snd_hdsp_hwdep_ioctl(
struct snd_hwdep *
hw,
struct file *
file,
unsigned int cmd,
unsigned long arg)
4984 err = hdsp_check_for_iobox(hdsp);
4988 err = hdsp_check_for_firmware(hdsp, 1);
4999 return hdsp_9652_get_peak(hdsp, peak_rms);
5001 return hdsp_9632_get_peak(hdsp, peak_rms);
5003 return hdsp_get_peak(hdsp, peak_rms);
5008 unsigned long flags;
5011 err = hdsp_check_for_iobox(hdsp);
5015 err = hdsp_check_for_firmware(hdsp, 1);
5019 memset(&info, 0,
sizeof(info));
5021 info.pref_sync_ref = (
unsigned char)hdsp_pref_sync_ref(hdsp);
5022 info.wordclock_sync_check = (
unsigned char)hdsp_wc_sync_check(hdsp);
5024 info.adatsync_sync_check = (
unsigned char)hdsp_adatsync_sync_check(hdsp);
5025 info.spdif_sync_check = (
unsigned char)hdsp_spdif_sync_check(hdsp);
5027 info.adat_sync_check[i] = (
unsigned char)hdsp_adat_sync_check(hdsp, i);
5028 info.spdif_in = (
unsigned char)hdsp_spdif_in(hdsp);
5029 info.spdif_out = (
unsigned char)hdsp_spdif_out(hdsp);
5030 info.spdif_professional = (
unsigned char)hdsp_spdif_professional(hdsp);
5031 info.spdif_emphasis = (
unsigned char)hdsp_spdif_emphasis(hdsp);
5032 info.spdif_nonaudio = (
unsigned char)hdsp_spdif_nonaudio(hdsp);
5033 info.spdif_sample_rate = hdsp_spdif_sample_rate(hdsp);
5035 info.autosync_sample_rate = hdsp_external_sample_rate(hdsp);
5036 info.system_clock_mode = (
unsigned char)hdsp_system_clock_mode(hdsp);
5037 info.clock_source = (
unsigned char)hdsp_clock_source(hdsp);
5038 info.autosync_ref = (
unsigned char)hdsp_autosync_ref(hdsp);
5039 info.line_out = (
unsigned char)hdsp_line_out(hdsp);
5041 info.da_gain = (
unsigned char)hdsp_da_gain(hdsp);
5042 info.ad_gain = (
unsigned char)hdsp_ad_gain(hdsp);
5043 info.phone_gain = (
unsigned char)hdsp_phone_gain(hdsp);
5044 info.xlr_breakout_cable = (
unsigned char)hdsp_xlr_breakout_cable(hdsp);
5047 info.da_gain = (
unsigned char) hdsp_rpm_input12(hdsp);
5048 info.ad_gain = (
unsigned char) hdsp_rpm_input34(hdsp);
5051 info.analog_extension_board = (
unsigned char)hdsp_aeb(hdsp);
5052 spin_unlock_irqrestore(&hdsp->
lock, flags);
5073 if ((err = hdsp_get_iobox_version(hdsp)) < 0)
5100 if (hdsp_check_for_iobox (hdsp))
5108 if ((err = snd_hdsp_load_firmware_from_cache(hdsp)) < 0)
5112 if ((err = snd_hdsp_enable_io(hdsp)) < 0)
5115 snd_hdsp_initialize_channels(hdsp);
5116 snd_hdsp_initialize_midi_flush(hdsp);
5118 if ((err = snd_hdsp_create_alsa_devices(hdsp->
card, hdsp)) < 0) {
5137 static struct snd_pcm_ops snd_hdsp_playback_ops = {
5138 .open = snd_hdsp_playback_open,
5139 .close = snd_hdsp_playback_release,
5140 .ioctl = snd_hdsp_ioctl,
5141 .hw_params = snd_hdsp_hw_params,
5142 .prepare = snd_hdsp_prepare,
5143 .trigger = snd_hdsp_trigger,
5144 .pointer = snd_hdsp_hw_pointer,
5145 .copy = snd_hdsp_playback_copy,
5146 .silence = snd_hdsp_hw_silence,
5149 static struct snd_pcm_ops snd_hdsp_capture_ops = {
5150 .open = snd_hdsp_capture_open,
5151 .close = snd_hdsp_capture_release,
5152 .ioctl = snd_hdsp_ioctl,
5153 .hw_params = snd_hdsp_hw_params,
5154 .prepare = snd_hdsp_prepare,
5155 .trigger = snd_hdsp_trigger,
5156 .pointer = snd_hdsp_hw_pointer,
5157 .copy = snd_hdsp_capture_copy,
5160 static int snd_hdsp_create_hwdep(
struct snd_card *card,
struct hdsp *hdsp)
5172 hw->
ops.ioctl = snd_hdsp_hwdep_ioctl;
5173 hw->
ops.ioctl_compat = snd_hdsp_hwdep_ioctl;
5178 static int snd_hdsp_create_pcm(
struct snd_card *card,
struct hdsp *hdsp)
5198 static void snd_hdsp_9652_enable_mixer (
struct hdsp *hdsp)
5204 static int snd_hdsp_enable_io (
struct hdsp *hdsp)
5208 if (hdsp_fifo_wait (hdsp, 0, 100)) {
5221 static void snd_hdsp_initialize_channels(
struct hdsp *hdsp)
5223 int status, aebi_channels, aebo_channels;
5227 hdsp->
card_name =
"RME Hammerfall DSP + Digiface";
5233 hdsp->
card_name =
"RME Hammerfall HDSP 9652";
5241 aebi_channels = (status &
HDSP_AEBI) ? 0 : 4;
5242 aebo_channels = (status &
HDSP_AEBO) ? 0 : 4;
5243 hdsp->
card_name =
"RME Hammerfall HDSP 9632";
5253 hdsp->
card_name =
"RME Hammerfall DSP + Multiface";
5259 hdsp->
card_name =
"RME Hammerfall DSP + RPM";
5272 static void snd_hdsp_initialize_midi_flush (
struct hdsp *hdsp)
5274 snd_hdsp_flush_midi_input (hdsp, 0);
5275 snd_hdsp_flush_midi_input (hdsp, 1);
5278 static int snd_hdsp_create_alsa_devices(
struct snd_card *card,
struct hdsp *hdsp)
5282 if ((err = snd_hdsp_create_pcm(card, hdsp)) < 0) {
5288 if ((err = snd_hdsp_create_midi(card, hdsp, 0)) < 0) {
5294 if ((err = snd_hdsp_create_midi(card, hdsp, 1)) < 0) {
5300 if ((err = snd_hdsp_create_controls(card, hdsp)) < 0) {
5305 snd_hdsp_proc_init(hdsp);
5313 if ((err = snd_hdsp_set_defaults(hdsp)) < 0) {
5333 #ifdef HDSP_FW_LOADER
5335 static int hdsp_request_fw_loader(
struct hdsp *hdsp)
5338 const struct firmware *
fw;
5344 if ((err = hdsp_get_iobox_version(hdsp)) < 0)
5353 fwfile =
"rpm_firmware.bin";
5357 fwfile =
"multiface_firmware.bin";
5359 fwfile =
"multiface_firmware_rev11.bin";
5363 fwfile =
"digiface_firmware.bin";
5365 fwfile =
"digiface_firmware_rev11.bin";
5389 if ((err = snd_hdsp_load_firmware_from_cache(hdsp)) < 0)
5393 if ((err = snd_hdsp_enable_io(hdsp)) < 0)
5396 if ((err = snd_hdsp_create_hwdep(hdsp->
card, hdsp)) < 0) {
5400 snd_hdsp_initialize_channels(hdsp);
5401 snd_hdsp_initialize_midi_flush(hdsp);
5402 if ((err = snd_hdsp_create_alsa_devices(hdsp->
card, hdsp)) < 0) {
5427 hdsp->
midi[0].pending = 0;
5428 hdsp->
midi[1].pending = 0;
5485 KBUILD_MODNAME, hdsp)) {
5495 if ((err = snd_hdsp_initialize_memory(hdsp)) < 0)
5498 if (!is_9652 && !is_9632) {
5501 err = hdsp_wait_for_iobox(hdsp, 1000, 10);
5507 #ifdef HDSP_FW_LOADER
5508 if ((err = hdsp_request_fw_loader(hdsp)) < 0)
5513 snd_printk(
KERN_ERR "Hammerfall-DSP: couldn't get firmware from userspace. try using hdsploader\n");
5519 snd_printk(
KERN_INFO "Hammerfall-DSP: card initialization pending : waiting for firmware\n");
5520 if ((err = snd_hdsp_create_hwdep(card, hdsp)) < 0)
5534 if ((err = snd_hdsp_enable_io(hdsp)) != 0)
5543 if ((err = snd_hdsp_create_hwdep(card, hdsp)) < 0)
5546 snd_hdsp_initialize_channels(hdsp);
5547 snd_hdsp_initialize_midi_flush(hdsp);
5551 if ((err = snd_hdsp_create_alsa_devices(card, hdsp)) < 0)
5557 static int snd_hdsp_free(
struct hdsp *hdsp)
5569 snd_hdsp_free_buffers(hdsp);
5581 static void snd_hdsp_card_free(
struct snd_card *card)
5586 snd_hdsp_free(hdsp);
5605 sizeof(
struct hdsp), &card);
5615 if ((err = snd_hdsp_create(card, hdsp)) < 0) {
5628 pci_set_drvdata(pci, card);
5636 pci_set_drvdata(pci,
NULL);
5640 .name = KBUILD_MODNAME,
5641 .id_table = snd_hdsp_ids,
5642 .probe = snd_hdsp_probe,