Commit | Line | Data |
---|---|---|
ef5fa1a4 | 1 | /* |
763f356c TI |
2 | * ALSA driver for RME Hammerfall DSP MADI audio interface(s) |
3 | * | |
4 | * Copyright (c) 2003 Winfried Ritsch (IEM) | |
5 | * code based on hdsp.c Paul Davis | |
6 | * Marcus Andersson | |
7 | * Thomas Charbonnel | |
3cee5a60 RB |
8 | * Modified 2006-06-01 for AES32 support by Remy Bruno |
9 | * <remy.bruno@trinnov.com> | |
763f356c | 10 | * |
0dca1793 AK |
11 | * Modified 2009-04-13 for proper metering by Florian Faber |
12 | * <faber@faberman.de> | |
13 | * | |
14 | * Modified 2009-04-14 for native float support by Florian Faber | |
15 | * <faber@faberman.de> | |
16 | * | |
17 | * Modified 2009-04-26 fixed bug in rms metering by Florian Faber | |
18 | * <faber@faberman.de> | |
19 | * | |
20 | * Modified 2009-04-30 added hw serial number support by Florian Faber | |
21 | * | |
22 | * Modified 2011-01-14 added S/PDIF input on RayDATs by Adrian Knoth | |
23 | * | |
24 | * Modified 2011-01-25 variable period sizes on RayDAT/AIO by Adrian Knoth | |
25 | * | |
763f356c TI |
26 | * This program is free software; you can redistribute it and/or modify |
27 | * it under the terms of the GNU General Public License as published by | |
28 | * the Free Software Foundation; either version 2 of the License, or | |
29 | * (at your option) any later version. | |
30 | * | |
31 | * This program is distributed in the hope that it will be useful, | |
32 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
33 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
34 | * GNU General Public License for more details. | |
35 | * | |
36 | * You should have received a copy of the GNU General Public License | |
37 | * along with this program; if not, write to the Free Software | |
38 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
39 | * | |
40 | */ | |
763f356c TI |
41 | #include <linux/init.h> |
42 | #include <linux/delay.h> | |
43 | #include <linux/interrupt.h> | |
65a77217 | 44 | #include <linux/module.h> |
763f356c TI |
45 | #include <linux/slab.h> |
46 | #include <linux/pci.h> | |
3f7440a6 | 47 | #include <linux/math64.h> |
763f356c TI |
48 | #include <asm/io.h> |
49 | ||
50 | #include <sound/core.h> | |
51 | #include <sound/control.h> | |
52 | #include <sound/pcm.h> | |
0dca1793 | 53 | #include <sound/pcm_params.h> |
763f356c TI |
54 | #include <sound/info.h> |
55 | #include <sound/asoundef.h> | |
56 | #include <sound/rawmidi.h> | |
57 | #include <sound/hwdep.h> | |
58 | #include <sound/initval.h> | |
59 | ||
60 | #include <sound/hdspm.h> | |
61 | ||
62 | static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */ | |
63 | static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */ | |
a67ff6a5 | 64 | static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;/* Enable this card */ |
763f356c | 65 | |
763f356c TI |
66 | module_param_array(index, int, NULL, 0444); |
67 | MODULE_PARM_DESC(index, "Index value for RME HDSPM interface."); | |
68 | ||
69 | module_param_array(id, charp, NULL, 0444); | |
70 | MODULE_PARM_DESC(id, "ID string for RME HDSPM interface."); | |
71 | ||
72 | module_param_array(enable, bool, NULL, 0444); | |
73 | MODULE_PARM_DESC(enable, "Enable/disable specific HDSPM soundcards."); | |
74 | ||
763f356c TI |
75 | |
76 | MODULE_AUTHOR | |
0dca1793 AK |
77 | ( |
78 | "Winfried Ritsch <ritsch_AT_iem.at>, " | |
79 | "Paul Davis <paul@linuxaudiosystems.com>, " | |
80 | "Marcus Andersson, Thomas Charbonnel <thomas@undata.org>, " | |
81 | "Remy Bruno <remy.bruno@trinnov.com>, " | |
82 | "Florian Faber <faberman@linuxproaudio.org>, " | |
83 | "Adrian Knoth <adi@drcomp.erfurt.thur.de>" | |
84 | ); | |
763f356c TI |
85 | MODULE_DESCRIPTION("RME HDSPM"); |
86 | MODULE_LICENSE("GPL"); | |
87 | MODULE_SUPPORTED_DEVICE("{{RME HDSPM-MADI}}"); | |
88 | ||
0dca1793 | 89 | /* --- Write registers. --- |
763f356c TI |
90 | These are defined as byte-offsets from the iobase value. */ |
91 | ||
0dca1793 AK |
92 | #define HDSPM_WR_SETTINGS 0 |
93 | #define HDSPM_outputBufferAddress 32 | |
94 | #define HDSPM_inputBufferAddress 36 | |
763f356c TI |
95 | #define HDSPM_controlRegister 64 |
96 | #define HDSPM_interruptConfirmation 96 | |
97 | #define HDSPM_control2Reg 256 /* not in specs ???????? */ | |
ffb2c3c0 | 98 | #define HDSPM_freqReg 256 /* for AES32 */ |
0dca1793 AK |
99 | #define HDSPM_midiDataOut0 352 /* just believe in old code */ |
100 | #define HDSPM_midiDataOut1 356 | |
ffb2c3c0 | 101 | #define HDSPM_eeprom_wr 384 /* for AES32 */ |
763f356c TI |
102 | |
103 | /* DMA enable for 64 channels, only Bit 0 is relevant */ | |
0dca1793 | 104 | #define HDSPM_outputEnableBase 512 /* 512-767 input DMA */ |
763f356c TI |
105 | #define HDSPM_inputEnableBase 768 /* 768-1023 output DMA */ |
106 | ||
0dca1793 | 107 | /* 16 page addresses for each of the 64 channels DMA buffer in and out |
763f356c TI |
108 | (each 64k=16*4k) Buffer must be 4k aligned (which is default i386 ????) */ |
109 | #define HDSPM_pageAddressBufferOut 8192 | |
110 | #define HDSPM_pageAddressBufferIn (HDSPM_pageAddressBufferOut+64*16*4) | |
111 | ||
112 | #define HDSPM_MADI_mixerBase 32768 /* 32768-65535 for 2x64x64 Fader */ | |
113 | ||
114 | #define HDSPM_MATRIX_MIXER_SIZE 8192 /* = 2*64*64 * 4 Byte => 32kB */ | |
115 | ||
116 | /* --- Read registers. --- | |
117 | These are defined as byte-offsets from the iobase value */ | |
118 | #define HDSPM_statusRegister 0 | |
3cee5a60 RB |
119 | /*#define HDSPM_statusRegister2 96 */ |
120 | /* after RME Windows driver sources, status2 is 4-byte word # 48 = word at | |
121 | * offset 192, for AES32 *and* MADI | |
122 | * => need to check that offset 192 is working on MADI */ | |
123 | #define HDSPM_statusRegister2 192 | |
124 | #define HDSPM_timecodeRegister 128 | |
763f356c | 125 | |
0dca1793 AK |
126 | /* AIO, RayDAT */ |
127 | #define HDSPM_RD_STATUS_0 0 | |
128 | #define HDSPM_RD_STATUS_1 64 | |
129 | #define HDSPM_RD_STATUS_2 128 | |
130 | #define HDSPM_RD_STATUS_3 192 | |
131 | ||
132 | #define HDSPM_RD_TCO 256 | |
133 | #define HDSPM_RD_PLL_FREQ 512 | |
134 | #define HDSPM_WR_TCO 128 | |
135 | ||
136 | #define HDSPM_TCO1_TCO_lock 0x00000001 | |
137 | #define HDSPM_TCO1_WCK_Input_Range_LSB 0x00000002 | |
138 | #define HDSPM_TCO1_WCK_Input_Range_MSB 0x00000004 | |
139 | #define HDSPM_TCO1_LTC_Input_valid 0x00000008 | |
140 | #define HDSPM_TCO1_WCK_Input_valid 0x00000010 | |
141 | #define HDSPM_TCO1_Video_Input_Format_NTSC 0x00000020 | |
142 | #define HDSPM_TCO1_Video_Input_Format_PAL 0x00000040 | |
143 | ||
144 | #define HDSPM_TCO1_set_TC 0x00000100 | |
145 | #define HDSPM_TCO1_set_drop_frame_flag 0x00000200 | |
146 | #define HDSPM_TCO1_LTC_Format_LSB 0x00000400 | |
147 | #define HDSPM_TCO1_LTC_Format_MSB 0x00000800 | |
148 | ||
149 | #define HDSPM_TCO2_TC_run 0x00010000 | |
150 | #define HDSPM_TCO2_WCK_IO_ratio_LSB 0x00020000 | |
151 | #define HDSPM_TCO2_WCK_IO_ratio_MSB 0x00040000 | |
152 | #define HDSPM_TCO2_set_num_drop_frames_LSB 0x00080000 | |
153 | #define HDSPM_TCO2_set_num_drop_frames_MSB 0x00100000 | |
154 | #define HDSPM_TCO2_set_jam_sync 0x00200000 | |
155 | #define HDSPM_TCO2_set_flywheel 0x00400000 | |
156 | ||
157 | #define HDSPM_TCO2_set_01_4 0x01000000 | |
158 | #define HDSPM_TCO2_set_pull_down 0x02000000 | |
159 | #define HDSPM_TCO2_set_pull_up 0x04000000 | |
160 | #define HDSPM_TCO2_set_freq 0x08000000 | |
161 | #define HDSPM_TCO2_set_term_75R 0x10000000 | |
162 | #define HDSPM_TCO2_set_input_LSB 0x20000000 | |
163 | #define HDSPM_TCO2_set_input_MSB 0x40000000 | |
164 | #define HDSPM_TCO2_set_freq_from_app 0x80000000 | |
165 | ||
166 | ||
167 | #define HDSPM_midiDataOut0 352 | |
168 | #define HDSPM_midiDataOut1 356 | |
169 | #define HDSPM_midiDataOut2 368 | |
170 | ||
763f356c TI |
171 | #define HDSPM_midiDataIn0 360 |
172 | #define HDSPM_midiDataIn1 364 | |
0dca1793 AK |
173 | #define HDSPM_midiDataIn2 372 |
174 | #define HDSPM_midiDataIn3 376 | |
763f356c TI |
175 | |
176 | /* status is data bytes in MIDI-FIFO (0-128) */ | |
0dca1793 AK |
177 | #define HDSPM_midiStatusOut0 384 |
178 | #define HDSPM_midiStatusOut1 388 | |
179 | #define HDSPM_midiStatusOut2 400 | |
180 | ||
181 | #define HDSPM_midiStatusIn0 392 | |
182 | #define HDSPM_midiStatusIn1 396 | |
183 | #define HDSPM_midiStatusIn2 404 | |
184 | #define HDSPM_midiStatusIn3 408 | |
763f356c TI |
185 | |
186 | ||
187 | /* the meters are regular i/o-mapped registers, but offset | |
188 | considerably from the rest. the peak registers are reset | |
0dca1793 | 189 | when read; the least-significant 4 bits are full-scale counters; |
763f356c TI |
190 | the actual peak value is in the most-significant 24 bits. |
191 | */ | |
0dca1793 AK |
192 | |
193 | #define HDSPM_MADI_INPUT_PEAK 4096 | |
194 | #define HDSPM_MADI_PLAYBACK_PEAK 4352 | |
195 | #define HDSPM_MADI_OUTPUT_PEAK 4608 | |
196 | ||
197 | #define HDSPM_MADI_INPUT_RMS_L 6144 | |
198 | #define HDSPM_MADI_PLAYBACK_RMS_L 6400 | |
199 | #define HDSPM_MADI_OUTPUT_RMS_L 6656 | |
200 | ||
201 | #define HDSPM_MADI_INPUT_RMS_H 7168 | |
202 | #define HDSPM_MADI_PLAYBACK_RMS_H 7424 | |
203 | #define HDSPM_MADI_OUTPUT_RMS_H 7680 | |
763f356c TI |
204 | |
205 | /* --- Control Register bits --------- */ | |
206 | #define HDSPM_Start (1<<0) /* start engine */ | |
207 | ||
208 | #define HDSPM_Latency0 (1<<1) /* buffer size = 2^n */ | |
209 | #define HDSPM_Latency1 (1<<2) /* where n is defined */ | |
210 | #define HDSPM_Latency2 (1<<3) /* by Latency{2,1,0} */ | |
211 | ||
0dca1793 AK |
212 | #define HDSPM_ClockModeMaster (1<<4) /* 1=Master, 0=Autosync */ |
213 | #define HDSPM_c0Master 0x1 /* Master clock bit in settings | |
214 | register [RayDAT, AIO] */ | |
763f356c TI |
215 | |
216 | #define HDSPM_AudioInterruptEnable (1<<5) /* what do you think ? */ | |
217 | ||
218 | #define HDSPM_Frequency0 (1<<6) /* 0=44.1kHz/88.2kHz 1=48kHz/96kHz */ | |
219 | #define HDSPM_Frequency1 (1<<7) /* 0=32kHz/64kHz */ | |
220 | #define HDSPM_DoubleSpeed (1<<8) /* 0=normal speed, 1=double speed */ | |
3cee5a60 | 221 | #define HDSPM_QuadSpeed (1<<31) /* quad speed bit */ |
763f356c | 222 | |
3cee5a60 | 223 | #define HDSPM_Professional (1<<9) /* Professional */ /* AES32 ONLY */ |
763f356c | 224 | #define HDSPM_TX_64ch (1<<10) /* Output 64channel MODE=1, |
3cee5a60 RB |
225 | 56channelMODE=0 */ /* MADI ONLY*/ |
226 | #define HDSPM_Emphasis (1<<10) /* Emphasis */ /* AES32 ONLY */ | |
763f356c | 227 | |
0dca1793 | 228 | #define HDSPM_AutoInp (1<<11) /* Auto Input (takeover) == Safe Mode, |
3cee5a60 RB |
229 | 0=off, 1=on */ /* MADI ONLY */ |
230 | #define HDSPM_Dolby (1<<11) /* Dolby = "NonAudio" ?? */ /* AES32 ONLY */ | |
763f356c | 231 | |
ef5fa1a4 TI |
232 | #define HDSPM_InputSelect0 (1<<14) /* Input select 0= optical, 1=coax |
233 | * -- MADI ONLY | |
234 | */ | |
763f356c TI |
235 | #define HDSPM_InputSelect1 (1<<15) /* should be 0 */ |
236 | ||
3cee5a60 RB |
237 | #define HDSPM_SyncRef2 (1<<13) |
238 | #define HDSPM_SyncRef3 (1<<25) | |
763f356c | 239 | |
3cee5a60 | 240 | #define HDSPM_SMUX (1<<18) /* Frame ??? */ /* MADI ONY */ |
0dca1793 | 241 | #define HDSPM_clr_tms (1<<19) /* clear track marker, do not use |
763f356c TI |
242 | AES additional bits in |
243 | lower 5 Audiodatabits ??? */ | |
3cee5a60 RB |
244 | #define HDSPM_taxi_reset (1<<20) /* ??? */ /* MADI ONLY ? */ |
245 | #define HDSPM_WCK48 (1<<20) /* Frame ??? = HDSPM_SMUX */ /* AES32 ONLY */ | |
763f356c | 246 | |
0dca1793 AK |
247 | #define HDSPM_Midi0InterruptEnable 0x0400000 |
248 | #define HDSPM_Midi1InterruptEnable 0x0800000 | |
249 | #define HDSPM_Midi2InterruptEnable 0x0200000 | |
250 | #define HDSPM_Midi3InterruptEnable 0x4000000 | |
763f356c TI |
251 | |
252 | #define HDSPM_LineOut (1<<24) /* Analog Out on channel 63/64 on=1, mute=0 */ | |
0dca1793 | 253 | #define HDSPe_FLOAT_FORMAT 0x2000000 |
763f356c | 254 | |
3cee5a60 RB |
255 | #define HDSPM_DS_DoubleWire (1<<26) /* AES32 ONLY */ |
256 | #define HDSPM_QS_DoubleWire (1<<27) /* AES32 ONLY */ | |
257 | #define HDSPM_QS_QuadWire (1<<28) /* AES32 ONLY */ | |
258 | ||
259 | #define HDSPM_wclk_sel (1<<30) | |
763f356c | 260 | |
384f778f AK |
261 | /* additional control register bits for AIO*/ |
262 | #define HDSPM_c0_Wck48 0x20 /* also RayDAT */ | |
263 | #define HDSPM_c0_Input0 0x1000 | |
264 | #define HDSPM_c0_Input1 0x2000 | |
265 | #define HDSPM_c0_Spdif_Opt 0x4000 | |
266 | #define HDSPM_c0_Pro 0x8000 | |
267 | #define HDSPM_c0_clr_tms 0x10000 | |
268 | #define HDSPM_c0_AEB1 0x20000 | |
269 | #define HDSPM_c0_AEB2 0x40000 | |
270 | #define HDSPM_c0_LineOut 0x80000 | |
271 | #define HDSPM_c0_AD_GAIN0 0x100000 | |
272 | #define HDSPM_c0_AD_GAIN1 0x200000 | |
273 | #define HDSPM_c0_DA_GAIN0 0x400000 | |
274 | #define HDSPM_c0_DA_GAIN1 0x800000 | |
275 | #define HDSPM_c0_PH_GAIN0 0x1000000 | |
276 | #define HDSPM_c0_PH_GAIN1 0x2000000 | |
277 | #define HDSPM_c0_Sym6db 0x4000000 | |
278 | ||
279 | ||
763f356c TI |
280 | /* --- bit helper defines */ |
281 | #define HDSPM_LatencyMask (HDSPM_Latency0|HDSPM_Latency1|HDSPM_Latency2) | |
ef5fa1a4 TI |
282 | #define HDSPM_FrequencyMask (HDSPM_Frequency0|HDSPM_Frequency1|\ |
283 | HDSPM_DoubleSpeed|HDSPM_QuadSpeed) | |
763f356c TI |
284 | #define HDSPM_InputMask (HDSPM_InputSelect0|HDSPM_InputSelect1) |
285 | #define HDSPM_InputOptical 0 | |
286 | #define HDSPM_InputCoaxial (HDSPM_InputSelect0) | |
ef5fa1a4 TI |
287 | #define HDSPM_SyncRefMask (HDSPM_SyncRef0|HDSPM_SyncRef1|\ |
288 | HDSPM_SyncRef2|HDSPM_SyncRef3) | |
763f356c | 289 | |
0dca1793 AK |
290 | #define HDSPM_c0_SyncRef0 0x2 |
291 | #define HDSPM_c0_SyncRef1 0x4 | |
292 | #define HDSPM_c0_SyncRef2 0x8 | |
293 | #define HDSPM_c0_SyncRef3 0x10 | |
294 | #define HDSPM_c0_SyncRefMask (HDSPM_c0_SyncRef0 | HDSPM_c0_SyncRef1 |\ | |
295 | HDSPM_c0_SyncRef2 | HDSPM_c0_SyncRef3) | |
296 | ||
297 | #define HDSPM_SYNC_FROM_WORD 0 /* Preferred sync reference */ | |
298 | #define HDSPM_SYNC_FROM_MADI 1 /* choices - used by "pref_sync_ref" */ | |
299 | #define HDSPM_SYNC_FROM_TCO 2 | |
300 | #define HDSPM_SYNC_FROM_SYNC_IN 3 | |
763f356c TI |
301 | |
302 | #define HDSPM_Frequency32KHz HDSPM_Frequency0 | |
303 | #define HDSPM_Frequency44_1KHz HDSPM_Frequency1 | |
304 | #define HDSPM_Frequency48KHz (HDSPM_Frequency1|HDSPM_Frequency0) | |
305 | #define HDSPM_Frequency64KHz (HDSPM_DoubleSpeed|HDSPM_Frequency0) | |
306 | #define HDSPM_Frequency88_2KHz (HDSPM_DoubleSpeed|HDSPM_Frequency1) | |
ef5fa1a4 TI |
307 | #define HDSPM_Frequency96KHz (HDSPM_DoubleSpeed|HDSPM_Frequency1|\ |
308 | HDSPM_Frequency0) | |
3cee5a60 RB |
309 | #define HDSPM_Frequency128KHz (HDSPM_QuadSpeed|HDSPM_Frequency0) |
310 | #define HDSPM_Frequency176_4KHz (HDSPM_QuadSpeed|HDSPM_Frequency1) | |
ef5fa1a4 TI |
311 | #define HDSPM_Frequency192KHz (HDSPM_QuadSpeed|HDSPM_Frequency1|\ |
312 | HDSPM_Frequency0) | |
763f356c | 313 | |
763f356c TI |
314 | |
315 | /* Synccheck Status */ | |
316 | #define HDSPM_SYNC_CHECK_NO_LOCK 0 | |
317 | #define HDSPM_SYNC_CHECK_LOCK 1 | |
318 | #define HDSPM_SYNC_CHECK_SYNC 2 | |
319 | ||
320 | /* AutoSync References - used by "autosync_ref" control switch */ | |
321 | #define HDSPM_AUTOSYNC_FROM_WORD 0 | |
322 | #define HDSPM_AUTOSYNC_FROM_MADI 1 | |
0dca1793 AK |
323 | #define HDSPM_AUTOSYNC_FROM_TCO 2 |
324 | #define HDSPM_AUTOSYNC_FROM_SYNC_IN 3 | |
325 | #define HDSPM_AUTOSYNC_FROM_NONE 4 | |
763f356c TI |
326 | |
327 | /* Possible sources of MADI input */ | |
328 | #define HDSPM_OPTICAL 0 /* optical */ | |
329 | #define HDSPM_COAXIAL 1 /* BNC */ | |
330 | ||
331 | #define hdspm_encode_latency(x) (((x)<<1) & HDSPM_LatencyMask) | |
0dca1793 | 332 | #define hdspm_decode_latency(x) ((((x) & HDSPM_LatencyMask)>>1)) |
763f356c TI |
333 | |
334 | #define hdspm_encode_in(x) (((x)&0x3)<<14) | |
335 | #define hdspm_decode_in(x) (((x)>>14)&0x3) | |
336 | ||
337 | /* --- control2 register bits --- */ | |
338 | #define HDSPM_TMS (1<<0) | |
339 | #define HDSPM_TCK (1<<1) | |
340 | #define HDSPM_TDI (1<<2) | |
341 | #define HDSPM_JTAG (1<<3) | |
342 | #define HDSPM_PWDN (1<<4) | |
343 | #define HDSPM_PROGRAM (1<<5) | |
344 | #define HDSPM_CONFIG_MODE_0 (1<<6) | |
345 | #define HDSPM_CONFIG_MODE_1 (1<<7) | |
346 | /*#define HDSPM_VERSION_BIT (1<<8) not defined any more*/ | |
347 | #define HDSPM_BIGENDIAN_MODE (1<<9) | |
348 | #define HDSPM_RD_MULTIPLE (1<<10) | |
349 | ||
3cee5a60 | 350 | /* --- Status Register bits --- */ /* MADI ONLY */ /* Bits defined here and |
ef5fa1a4 TI |
351 | that do not conflict with specific bits for AES32 seem to be valid also |
352 | for the AES32 | |
353 | */ | |
763f356c | 354 | #define HDSPM_audioIRQPending (1<<0) /* IRQ is high and pending */ |
ef5fa1a4 TI |
355 | #define HDSPM_RX_64ch (1<<1) /* Input 64chan. MODE=1, 56chn MODE=0 */ |
356 | #define HDSPM_AB_int (1<<2) /* InputChannel Opt=0, Coax=1 | |
357 | * (like inp0) | |
358 | */ | |
0dca1793 | 359 | |
763f356c | 360 | #define HDSPM_madiLock (1<<3) /* MADI Locked =1, no=0 */ |
0dca1793 AK |
361 | #define HDSPM_madiSync (1<<18) /* MADI is in sync */ |
362 | ||
363 | #define HDSPM_tcoLock 0x00000020 /* Optional TCO locked status FOR HDSPe MADI! */ | |
364 | #define HDSPM_tcoSync 0x10000000 /* Optional TCO sync status */ | |
365 | ||
366 | #define HDSPM_syncInLock 0x00010000 /* Sync In lock status FOR HDSPe MADI! */ | |
367 | #define HDSPM_syncInSync 0x00020000 /* Sync In sync status FOR HDSPe MADI! */ | |
763f356c TI |
368 | |
369 | #define HDSPM_BufferPositionMask 0x000FFC0 /* Bit 6..15 : h/w buffer pointer */ | |
0dca1793 AK |
370 | /* since 64byte accurate, last 6 bits are not used */ |
371 | ||
372 | ||
763f356c | 373 | |
763f356c TI |
374 | #define HDSPM_DoubleSpeedStatus (1<<19) /* (input) card in double speed */ |
375 | ||
376 | #define HDSPM_madiFreq0 (1<<22) /* system freq 0=error */ | |
377 | #define HDSPM_madiFreq1 (1<<23) /* 1=32, 2=44.1 3=48 */ | |
378 | #define HDSPM_madiFreq2 (1<<24) /* 4=64, 5=88.2 6=96 */ | |
379 | #define HDSPM_madiFreq3 (1<<25) /* 7=128, 8=176.4 9=192 */ | |
380 | ||
ef5fa1a4 TI |
381 | #define HDSPM_BufferID (1<<26) /* (Double)Buffer ID toggles with |
382 | * Interrupt | |
383 | */ | |
0dca1793 AK |
384 | #define HDSPM_tco_detect 0x08000000 |
385 | #define HDSPM_tco_lock 0x20000000 | |
386 | ||
387 | #define HDSPM_s2_tco_detect 0x00000040 | |
388 | #define HDSPM_s2_AEBO_D 0x00000080 | |
389 | #define HDSPM_s2_AEBI_D 0x00000100 | |
390 | ||
391 | ||
392 | #define HDSPM_midi0IRQPending 0x40000000 | |
393 | #define HDSPM_midi1IRQPending 0x80000000 | |
394 | #define HDSPM_midi2IRQPending 0x20000000 | |
395 | #define HDSPM_midi2IRQPendingAES 0x00000020 | |
396 | #define HDSPM_midi3IRQPending 0x00200000 | |
763f356c TI |
397 | |
398 | /* --- status bit helpers */ | |
ef5fa1a4 TI |
399 | #define HDSPM_madiFreqMask (HDSPM_madiFreq0|HDSPM_madiFreq1|\ |
400 | HDSPM_madiFreq2|HDSPM_madiFreq3) | |
763f356c TI |
401 | #define HDSPM_madiFreq32 (HDSPM_madiFreq0) |
402 | #define HDSPM_madiFreq44_1 (HDSPM_madiFreq1) | |
403 | #define HDSPM_madiFreq48 (HDSPM_madiFreq0|HDSPM_madiFreq1) | |
404 | #define HDSPM_madiFreq64 (HDSPM_madiFreq2) | |
405 | #define HDSPM_madiFreq88_2 (HDSPM_madiFreq0|HDSPM_madiFreq2) | |
406 | #define HDSPM_madiFreq96 (HDSPM_madiFreq1|HDSPM_madiFreq2) | |
407 | #define HDSPM_madiFreq128 (HDSPM_madiFreq0|HDSPM_madiFreq1|HDSPM_madiFreq2) | |
408 | #define HDSPM_madiFreq176_4 (HDSPM_madiFreq3) | |
409 | #define HDSPM_madiFreq192 (HDSPM_madiFreq3|HDSPM_madiFreq0) | |
410 | ||
3cee5a60 | 411 | /* Status2 Register bits */ /* MADI ONLY */ |
763f356c | 412 | |
25985edc | 413 | #define HDSPM_version0 (1<<0) /* not really defined but I guess */ |
763f356c TI |
414 | #define HDSPM_version1 (1<<1) /* in former cards it was ??? */ |
415 | #define HDSPM_version2 (1<<2) | |
416 | ||
417 | #define HDSPM_wcLock (1<<3) /* Wordclock is detected and locked */ | |
418 | #define HDSPM_wcSync (1<<4) /* Wordclock is in sync with systemclock */ | |
419 | ||
420 | #define HDSPM_wc_freq0 (1<<5) /* input freq detected via autosync */ | |
421 | #define HDSPM_wc_freq1 (1<<6) /* 001=32, 010==44.1, 011=48, */ | |
a8cd7148 AK |
422 | #define HDSPM_wc_freq2 (1<<7) /* 100=64, 101=88.2, 110=96, 111=128 */ |
423 | #define HDSPM_wc_freq3 0x800 /* 1000=176.4, 1001=192 */ | |
763f356c | 424 | |
0dca1793 AK |
425 | #define HDSPM_SyncRef0 0x10000 /* Sync Reference */ |
426 | #define HDSPM_SyncRef1 0x20000 | |
427 | ||
428 | #define HDSPM_SelSyncRef0 (1<<8) /* AutoSync Source */ | |
763f356c TI |
429 | #define HDSPM_SelSyncRef1 (1<<9) /* 000=word, 001=MADI, */ |
430 | #define HDSPM_SelSyncRef2 (1<<10) /* 111=no valid signal */ | |
431 | ||
432 | #define HDSPM_wc_valid (HDSPM_wcLock|HDSPM_wcSync) | |
433 | ||
a8cd7148 AK |
434 | #define HDSPM_wcFreqMask (HDSPM_wc_freq0|HDSPM_wc_freq1|HDSPM_wc_freq2|\ |
435 | HDSPM_wc_freq3) | |
763f356c TI |
436 | #define HDSPM_wcFreq32 (HDSPM_wc_freq0) |
437 | #define HDSPM_wcFreq44_1 (HDSPM_wc_freq1) | |
438 | #define HDSPM_wcFreq48 (HDSPM_wc_freq0|HDSPM_wc_freq1) | |
439 | #define HDSPM_wcFreq64 (HDSPM_wc_freq2) | |
440 | #define HDSPM_wcFreq88_2 (HDSPM_wc_freq0|HDSPM_wc_freq2) | |
441 | #define HDSPM_wcFreq96 (HDSPM_wc_freq1|HDSPM_wc_freq2) | |
a8cd7148 AK |
442 | #define HDSPM_wcFreq128 (HDSPM_wc_freq0|HDSPM_wc_freq1|HDSPM_wc_freq2) |
443 | #define HDSPM_wcFreq176_4 (HDSPM_wc_freq3) | |
444 | #define HDSPM_wcFreq192 (HDSPM_wc_freq0|HDSPM_wc_freq3) | |
763f356c | 445 | |
0dca1793 AK |
446 | #define HDSPM_status1_F_0 0x0400000 |
447 | #define HDSPM_status1_F_1 0x0800000 | |
448 | #define HDSPM_status1_F_2 0x1000000 | |
449 | #define HDSPM_status1_F_3 0x2000000 | |
450 | #define HDSPM_status1_freqMask (HDSPM_status1_F_0|HDSPM_status1_F_1|HDSPM_status1_F_2|HDSPM_status1_F_3) | |
451 | ||
763f356c | 452 | |
ef5fa1a4 TI |
453 | #define HDSPM_SelSyncRefMask (HDSPM_SelSyncRef0|HDSPM_SelSyncRef1|\ |
454 | HDSPM_SelSyncRef2) | |
763f356c TI |
455 | #define HDSPM_SelSyncRef_WORD 0 |
456 | #define HDSPM_SelSyncRef_MADI (HDSPM_SelSyncRef0) | |
0dca1793 AK |
457 | #define HDSPM_SelSyncRef_TCO (HDSPM_SelSyncRef1) |
458 | #define HDSPM_SelSyncRef_SyncIn (HDSPM_SelSyncRef0|HDSPM_SelSyncRef1) | |
ef5fa1a4 TI |
459 | #define HDSPM_SelSyncRef_NVALID (HDSPM_SelSyncRef0|HDSPM_SelSyncRef1|\ |
460 | HDSPM_SelSyncRef2) | |
763f356c | 461 | |
3cee5a60 RB |
462 | /* |
463 | For AES32, bits for status, status2 and timecode are different | |
464 | */ | |
465 | /* status */ | |
466 | #define HDSPM_AES32_wcLock 0x0200000 | |
56bde0f3 | 467 | #define HDSPM_AES32_wcSync 0x0100000 |
3cee5a60 | 468 | #define HDSPM_AES32_wcFreq_bit 22 |
0dca1793 | 469 | /* (status >> HDSPM_AES32_wcFreq_bit) & 0xF gives WC frequency (cf function |
3cee5a60 RB |
470 | HDSPM_bit2freq */ |
471 | #define HDSPM_AES32_syncref_bit 16 | |
472 | /* (status >> HDSPM_AES32_syncref_bit) & 0xF gives sync source */ | |
473 | ||
474 | #define HDSPM_AES32_AUTOSYNC_FROM_WORD 0 | |
475 | #define HDSPM_AES32_AUTOSYNC_FROM_AES1 1 | |
476 | #define HDSPM_AES32_AUTOSYNC_FROM_AES2 2 | |
477 | #define HDSPM_AES32_AUTOSYNC_FROM_AES3 3 | |
478 | #define HDSPM_AES32_AUTOSYNC_FROM_AES4 4 | |
479 | #define HDSPM_AES32_AUTOSYNC_FROM_AES5 5 | |
480 | #define HDSPM_AES32_AUTOSYNC_FROM_AES6 6 | |
481 | #define HDSPM_AES32_AUTOSYNC_FROM_AES7 7 | |
482 | #define HDSPM_AES32_AUTOSYNC_FROM_AES8 8 | |
6534599d | 483 | #define HDSPM_AES32_AUTOSYNC_FROM_NONE 9 |
3cee5a60 RB |
484 | |
485 | /* status2 */ | |
486 | /* HDSPM_LockAES_bit is given by HDSPM_LockAES >> (AES# - 1) */ | |
487 | #define HDSPM_LockAES 0x80 | |
488 | #define HDSPM_LockAES1 0x80 | |
489 | #define HDSPM_LockAES2 0x40 | |
490 | #define HDSPM_LockAES3 0x20 | |
491 | #define HDSPM_LockAES4 0x10 | |
492 | #define HDSPM_LockAES5 0x8 | |
493 | #define HDSPM_LockAES6 0x4 | |
494 | #define HDSPM_LockAES7 0x2 | |
495 | #define HDSPM_LockAES8 0x1 | |
496 | /* | |
497 | Timecode | |
498 | After windows driver sources, bits 4*i to 4*i+3 give the input frequency on | |
499 | AES i+1 | |
500 | bits 3210 | |
501 | 0001 32kHz | |
502 | 0010 44.1kHz | |
503 | 0011 48kHz | |
504 | 0100 64kHz | |
505 | 0101 88.2kHz | |
506 | 0110 96kHz | |
507 | 0111 128kHz | |
508 | 1000 176.4kHz | |
509 | 1001 192kHz | |
510 | NB: Timecode register doesn't seem to work on AES32 card revision 230 | |
511 | */ | |
512 | ||
763f356c TI |
513 | /* Mixer Values */ |
514 | #define UNITY_GAIN 32768 /* = 65536/2 */ | |
515 | #define MINUS_INFINITY_GAIN 0 | |
516 | ||
763f356c TI |
517 | /* Number of channels for different Speed Modes */ |
518 | #define MADI_SS_CHANNELS 64 | |
519 | #define MADI_DS_CHANNELS 32 | |
520 | #define MADI_QS_CHANNELS 16 | |
521 | ||
0dca1793 AK |
522 | #define RAYDAT_SS_CHANNELS 36 |
523 | #define RAYDAT_DS_CHANNELS 20 | |
524 | #define RAYDAT_QS_CHANNELS 12 | |
525 | ||
526 | #define AIO_IN_SS_CHANNELS 14 | |
527 | #define AIO_IN_DS_CHANNELS 10 | |
528 | #define AIO_IN_QS_CHANNELS 8 | |
529 | #define AIO_OUT_SS_CHANNELS 16 | |
530 | #define AIO_OUT_DS_CHANNELS 12 | |
531 | #define AIO_OUT_QS_CHANNELS 10 | |
532 | ||
d2d10a21 AK |
533 | #define AES32_CHANNELS 16 |
534 | ||
763f356c TI |
535 | /* the size of a substream (1 mono data stream) */ |
536 | #define HDSPM_CHANNEL_BUFFER_SAMPLES (16*1024) | |
537 | #define HDSPM_CHANNEL_BUFFER_BYTES (4*HDSPM_CHANNEL_BUFFER_SAMPLES) | |
538 | ||
539 | /* the size of the area we need to allocate for DMA transfers. the | |
540 | size is the same regardless of the number of channels, and | |
0dca1793 | 541 | also the latency to use. |
763f356c TI |
542 | for one direction !!! |
543 | */ | |
ffb2c3c0 | 544 | #define HDSPM_DMA_AREA_BYTES (HDSPM_MAX_CHANNELS * HDSPM_CHANNEL_BUFFER_BYTES) |
763f356c TI |
545 | #define HDSPM_DMA_AREA_KILOBYTES (HDSPM_DMA_AREA_BYTES/1024) |
546 | ||
0dca1793 AK |
547 | #define HDSPM_RAYDAT_REV 211 |
548 | #define HDSPM_AIO_REV 212 | |
549 | #define HDSPM_MADIFACE_REV 213 | |
3cee5a60 | 550 | |
6534599d RB |
551 | /* speed factor modes */ |
552 | #define HDSPM_SPEED_SINGLE 0 | |
553 | #define HDSPM_SPEED_DOUBLE 1 | |
554 | #define HDSPM_SPEED_QUAD 2 | |
0dca1793 | 555 | |
6534599d RB |
556 | /* names for speed modes */ |
557 | static char *hdspm_speed_names[] = { "single", "double", "quad" }; | |
558 | ||
0dca1793 AK |
559 | static char *texts_autosync_aes_tco[] = { "Word Clock", |
560 | "AES1", "AES2", "AES3", "AES4", | |
561 | "AES5", "AES6", "AES7", "AES8", | |
562 | "TCO" }; | |
563 | static char *texts_autosync_aes[] = { "Word Clock", | |
564 | "AES1", "AES2", "AES3", "AES4", | |
565 | "AES5", "AES6", "AES7", "AES8" }; | |
566 | static char *texts_autosync_madi_tco[] = { "Word Clock", | |
567 | "MADI", "TCO", "Sync In" }; | |
568 | static char *texts_autosync_madi[] = { "Word Clock", | |
569 | "MADI", "Sync In" }; | |
570 | ||
571 | static char *texts_autosync_raydat_tco[] = { | |
572 | "Word Clock", | |
573 | "ADAT 1", "ADAT 2", "ADAT 3", "ADAT 4", | |
574 | "AES", "SPDIF", "TCO", "Sync In" | |
575 | }; | |
576 | static char *texts_autosync_raydat[] = { | |
577 | "Word Clock", | |
578 | "ADAT 1", "ADAT 2", "ADAT 3", "ADAT 4", | |
579 | "AES", "SPDIF", "Sync In" | |
580 | }; | |
581 | static char *texts_autosync_aio_tco[] = { | |
582 | "Word Clock", | |
583 | "ADAT", "AES", "SPDIF", "TCO", "Sync In" | |
584 | }; | |
585 | static char *texts_autosync_aio[] = { "Word Clock", | |
586 | "ADAT", "AES", "SPDIF", "Sync In" }; | |
587 | ||
588 | static char *texts_freq[] = { | |
589 | "No Lock", | |
590 | "32 kHz", | |
591 | "44.1 kHz", | |
592 | "48 kHz", | |
593 | "64 kHz", | |
594 | "88.2 kHz", | |
595 | "96 kHz", | |
596 | "128 kHz", | |
597 | "176.4 kHz", | |
598 | "192 kHz" | |
599 | }; | |
600 | ||
0dca1793 AK |
601 | static char *texts_ports_madi[] = { |
602 | "MADI.1", "MADI.2", "MADI.3", "MADI.4", "MADI.5", "MADI.6", | |
603 | "MADI.7", "MADI.8", "MADI.9", "MADI.10", "MADI.11", "MADI.12", | |
604 | "MADI.13", "MADI.14", "MADI.15", "MADI.16", "MADI.17", "MADI.18", | |
605 | "MADI.19", "MADI.20", "MADI.21", "MADI.22", "MADI.23", "MADI.24", | |
606 | "MADI.25", "MADI.26", "MADI.27", "MADI.28", "MADI.29", "MADI.30", | |
607 | "MADI.31", "MADI.32", "MADI.33", "MADI.34", "MADI.35", "MADI.36", | |
608 | "MADI.37", "MADI.38", "MADI.39", "MADI.40", "MADI.41", "MADI.42", | |
609 | "MADI.43", "MADI.44", "MADI.45", "MADI.46", "MADI.47", "MADI.48", | |
610 | "MADI.49", "MADI.50", "MADI.51", "MADI.52", "MADI.53", "MADI.54", | |
611 | "MADI.55", "MADI.56", "MADI.57", "MADI.58", "MADI.59", "MADI.60", | |
612 | "MADI.61", "MADI.62", "MADI.63", "MADI.64", | |
613 | }; | |
614 | ||
615 | ||
616 | static char *texts_ports_raydat_ss[] = { | |
617 | "ADAT1.1", "ADAT1.2", "ADAT1.3", "ADAT1.4", "ADAT1.5", "ADAT1.6", | |
618 | "ADAT1.7", "ADAT1.8", "ADAT2.1", "ADAT2.2", "ADAT2.3", "ADAT2.4", | |
619 | "ADAT2.5", "ADAT2.6", "ADAT2.7", "ADAT2.8", "ADAT3.1", "ADAT3.2", | |
620 | "ADAT3.3", "ADAT3.4", "ADAT3.5", "ADAT3.6", "ADAT3.7", "ADAT3.8", | |
621 | "ADAT4.1", "ADAT4.2", "ADAT4.3", "ADAT4.4", "ADAT4.5", "ADAT4.6", | |
622 | "ADAT4.7", "ADAT4.8", | |
623 | "AES.L", "AES.R", | |
624 | "SPDIF.L", "SPDIF.R" | |
625 | }; | |
626 | ||
627 | static char *texts_ports_raydat_ds[] = { | |
628 | "ADAT1.1", "ADAT1.2", "ADAT1.3", "ADAT1.4", | |
629 | "ADAT2.1", "ADAT2.2", "ADAT2.3", "ADAT2.4", | |
630 | "ADAT3.1", "ADAT3.2", "ADAT3.3", "ADAT3.4", | |
631 | "ADAT4.1", "ADAT4.2", "ADAT4.3", "ADAT4.4", | |
632 | "AES.L", "AES.R", | |
633 | "SPDIF.L", "SPDIF.R" | |
634 | }; | |
635 | ||
636 | static char *texts_ports_raydat_qs[] = { | |
637 | "ADAT1.1", "ADAT1.2", | |
638 | "ADAT2.1", "ADAT2.2", | |
639 | "ADAT3.1", "ADAT3.2", | |
640 | "ADAT4.1", "ADAT4.2", | |
641 | "AES.L", "AES.R", | |
642 | "SPDIF.L", "SPDIF.R" | |
643 | }; | |
644 | ||
645 | ||
646 | static char *texts_ports_aio_in_ss[] = { | |
647 | "Analogue.L", "Analogue.R", | |
648 | "AES.L", "AES.R", | |
649 | "SPDIF.L", "SPDIF.R", | |
650 | "ADAT.1", "ADAT.2", "ADAT.3", "ADAT.4", "ADAT.5", "ADAT.6", | |
651 | "ADAT.7", "ADAT.8" | |
652 | }; | |
653 | ||
654 | static char *texts_ports_aio_out_ss[] = { | |
655 | "Analogue.L", "Analogue.R", | |
656 | "AES.L", "AES.R", | |
657 | "SPDIF.L", "SPDIF.R", | |
658 | "ADAT.1", "ADAT.2", "ADAT.3", "ADAT.4", "ADAT.5", "ADAT.6", | |
659 | "ADAT.7", "ADAT.8", | |
660 | "Phone.L", "Phone.R" | |
661 | }; | |
662 | ||
663 | static char *texts_ports_aio_in_ds[] = { | |
664 | "Analogue.L", "Analogue.R", | |
665 | "AES.L", "AES.R", | |
666 | "SPDIF.L", "SPDIF.R", | |
667 | "ADAT.1", "ADAT.2", "ADAT.3", "ADAT.4" | |
668 | }; | |
669 | ||
670 | static char *texts_ports_aio_out_ds[] = { | |
671 | "Analogue.L", "Analogue.R", | |
672 | "AES.L", "AES.R", | |
673 | "SPDIF.L", "SPDIF.R", | |
674 | "ADAT.1", "ADAT.2", "ADAT.3", "ADAT.4", | |
675 | "Phone.L", "Phone.R" | |
676 | }; | |
677 | ||
678 | static char *texts_ports_aio_in_qs[] = { | |
679 | "Analogue.L", "Analogue.R", | |
680 | "AES.L", "AES.R", | |
681 | "SPDIF.L", "SPDIF.R", | |
682 | "ADAT.1", "ADAT.2", "ADAT.3", "ADAT.4" | |
683 | }; | |
684 | ||
685 | static char *texts_ports_aio_out_qs[] = { | |
686 | "Analogue.L", "Analogue.R", | |
687 | "AES.L", "AES.R", | |
688 | "SPDIF.L", "SPDIF.R", | |
689 | "ADAT.1", "ADAT.2", "ADAT.3", "ADAT.4", | |
690 | "Phone.L", "Phone.R" | |
691 | }; | |
692 | ||
432d2500 AK |
693 | static char *texts_ports_aes32[] = { |
694 | "AES.1", "AES.2", "AES.3", "AES.4", "AES.5", "AES.6", "AES.7", | |
695 | "AES.8", "AES.9.", "AES.10", "AES.11", "AES.12", "AES.13", "AES.14", | |
696 | "AES.15", "AES.16" | |
697 | }; | |
698 | ||
55a57606 AK |
699 | /* These tables map the ALSA channels 1..N to the channels that we |
700 | need to use in order to find the relevant channel buffer. RME | |
701 | refers to this kind of mapping as between "the ADAT channel and | |
702 | the DMA channel." We index it using the logical audio channel, | |
703 | and the value is the DMA channel (i.e. channel buffer number) | |
704 | where the data for that channel can be read/written from/to. | |
705 | */ | |
706 | ||
707 | static char channel_map_unity_ss[HDSPM_MAX_CHANNELS] = { | |
708 | 0, 1, 2, 3, 4, 5, 6, 7, | |
709 | 8, 9, 10, 11, 12, 13, 14, 15, | |
710 | 16, 17, 18, 19, 20, 21, 22, 23, | |
711 | 24, 25, 26, 27, 28, 29, 30, 31, | |
712 | 32, 33, 34, 35, 36, 37, 38, 39, | |
713 | 40, 41, 42, 43, 44, 45, 46, 47, | |
714 | 48, 49, 50, 51, 52, 53, 54, 55, | |
715 | 56, 57, 58, 59, 60, 61, 62, 63 | |
716 | }; | |
717 | ||
55a57606 AK |
718 | static char channel_map_raydat_ss[HDSPM_MAX_CHANNELS] = { |
719 | 4, 5, 6, 7, 8, 9, 10, 11, /* ADAT 1 */ | |
720 | 12, 13, 14, 15, 16, 17, 18, 19, /* ADAT 2 */ | |
721 | 20, 21, 22, 23, 24, 25, 26, 27, /* ADAT 3 */ | |
722 | 28, 29, 30, 31, 32, 33, 34, 35, /* ADAT 4 */ | |
723 | 0, 1, /* AES */ | |
724 | 2, 3, /* SPDIF */ | |
725 | -1, -1, -1, -1, | |
726 | -1, -1, -1, -1, -1, -1, -1, -1, | |
727 | -1, -1, -1, -1, -1, -1, -1, -1, | |
728 | -1, -1, -1, -1, -1, -1, -1, -1, | |
729 | }; | |
730 | ||
731 | static char channel_map_raydat_ds[HDSPM_MAX_CHANNELS] = { | |
732 | 4, 5, 6, 7, /* ADAT 1 */ | |
733 | 8, 9, 10, 11, /* ADAT 2 */ | |
734 | 12, 13, 14, 15, /* ADAT 3 */ | |
735 | 16, 17, 18, 19, /* ADAT 4 */ | |
736 | 0, 1, /* AES */ | |
737 | 2, 3, /* SPDIF */ | |
738 | -1, -1, -1, -1, | |
739 | -1, -1, -1, -1, -1, -1, -1, -1, | |
740 | -1, -1, -1, -1, -1, -1, -1, -1, | |
741 | -1, -1, -1, -1, -1, -1, -1, -1, | |
742 | -1, -1, -1, -1, -1, -1, -1, -1, | |
743 | -1, -1, -1, -1, -1, -1, -1, -1, | |
744 | }; | |
745 | ||
746 | static char channel_map_raydat_qs[HDSPM_MAX_CHANNELS] = { | |
747 | 4, 5, /* ADAT 1 */ | |
748 | 6, 7, /* ADAT 2 */ | |
749 | 8, 9, /* ADAT 3 */ | |
750 | 10, 11, /* ADAT 4 */ | |
751 | 0, 1, /* AES */ | |
752 | 2, 3, /* SPDIF */ | |
753 | -1, -1, -1, -1, | |
754 | -1, -1, -1, -1, -1, -1, -1, -1, | |
755 | -1, -1, -1, -1, -1, -1, -1, -1, | |
756 | -1, -1, -1, -1, -1, -1, -1, -1, | |
757 | -1, -1, -1, -1, -1, -1, -1, -1, | |
758 | -1, -1, -1, -1, -1, -1, -1, -1, | |
759 | -1, -1, -1, -1, -1, -1, -1, -1, | |
760 | }; | |
761 | ||
762 | static char channel_map_aio_in_ss[HDSPM_MAX_CHANNELS] = { | |
763 | 0, 1, /* line in */ | |
764 | 8, 9, /* aes in, */ | |
765 | 10, 11, /* spdif in */ | |
766 | 12, 13, 14, 15, 16, 17, 18, 19, /* ADAT in */ | |
767 | -1, -1, | |
768 | -1, -1, -1, -1, -1, -1, -1, -1, | |
769 | -1, -1, -1, -1, -1, -1, -1, -1, | |
770 | -1, -1, -1, -1, -1, -1, -1, -1, | |
771 | -1, -1, -1, -1, -1, -1, -1, -1, | |
772 | -1, -1, -1, -1, -1, -1, -1, -1, | |
773 | -1, -1, -1, -1, -1, -1, -1, -1, | |
774 | }; | |
775 | ||
776 | static char channel_map_aio_out_ss[HDSPM_MAX_CHANNELS] = { | |
777 | 0, 1, /* line out */ | |
778 | 8, 9, /* aes out */ | |
779 | 10, 11, /* spdif out */ | |
780 | 12, 13, 14, 15, 16, 17, 18, 19, /* ADAT out */ | |
781 | 6, 7, /* phone out */ | |
782 | -1, -1, -1, -1, -1, -1, -1, -1, | |
783 | -1, -1, -1, -1, -1, -1, -1, -1, | |
784 | -1, -1, -1, -1, -1, -1, -1, -1, | |
785 | -1, -1, -1, -1, -1, -1, -1, -1, | |
786 | -1, -1, -1, -1, -1, -1, -1, -1, | |
787 | -1, -1, -1, -1, -1, -1, -1, -1, | |
788 | }; | |
789 | ||
790 | static char channel_map_aio_in_ds[HDSPM_MAX_CHANNELS] = { | |
791 | 0, 1, /* line in */ | |
792 | 8, 9, /* aes in */ | |
793 | 10, 11, /* spdif in */ | |
794 | 12, 14, 16, 18, /* adat in */ | |
795 | -1, -1, -1, -1, -1, -1, | |
796 | -1, -1, -1, -1, -1, -1, -1, -1, | |
797 | -1, -1, -1, -1, -1, -1, -1, -1, | |
798 | -1, -1, -1, -1, -1, -1, -1, -1, | |
799 | -1, -1, -1, -1, -1, -1, -1, -1, | |
800 | -1, -1, -1, -1, -1, -1, -1, -1, | |
801 | -1, -1, -1, -1, -1, -1, -1, -1 | |
802 | }; | |
803 | ||
804 | static char channel_map_aio_out_ds[HDSPM_MAX_CHANNELS] = { | |
805 | 0, 1, /* line out */ | |
806 | 8, 9, /* aes out */ | |
807 | 10, 11, /* spdif out */ | |
808 | 12, 14, 16, 18, /* adat out */ | |
809 | 6, 7, /* phone out */ | |
810 | -1, -1, -1, -1, | |
811 | -1, -1, -1, -1, -1, -1, -1, -1, | |
812 | -1, -1, -1, -1, -1, -1, -1, -1, | |
813 | -1, -1, -1, -1, -1, -1, -1, -1, | |
814 | -1, -1, -1, -1, -1, -1, -1, -1, | |
815 | -1, -1, -1, -1, -1, -1, -1, -1, | |
816 | -1, -1, -1, -1, -1, -1, -1, -1 | |
817 | }; | |
818 | ||
819 | static char channel_map_aio_in_qs[HDSPM_MAX_CHANNELS] = { | |
820 | 0, 1, /* line in */ | |
821 | 8, 9, /* aes in */ | |
822 | 10, 11, /* spdif in */ | |
823 | 12, 16, /* adat in */ | |
824 | -1, -1, -1, -1, -1, -1, -1, -1, | |
825 | -1, -1, -1, -1, -1, -1, -1, -1, | |
826 | -1, -1, -1, -1, -1, -1, -1, -1, | |
827 | -1, -1, -1, -1, -1, -1, -1, -1, | |
828 | -1, -1, -1, -1, -1, -1, -1, -1, | |
829 | -1, -1, -1, -1, -1, -1, -1, -1, | |
830 | -1, -1, -1, -1, -1, -1, -1, -1 | |
831 | }; | |
832 | ||
833 | static char channel_map_aio_out_qs[HDSPM_MAX_CHANNELS] = { | |
834 | 0, 1, /* line out */ | |
835 | 8, 9, /* aes out */ | |
836 | 10, 11, /* spdif out */ | |
837 | 12, 16, /* adat out */ | |
838 | 6, 7, /* phone out */ | |
839 | -1, -1, -1, -1, -1, -1, | |
840 | -1, -1, -1, -1, -1, -1, -1, -1, | |
841 | -1, -1, -1, -1, -1, -1, -1, -1, | |
842 | -1, -1, -1, -1, -1, -1, -1, -1, | |
843 | -1, -1, -1, -1, -1, -1, -1, -1, | |
844 | -1, -1, -1, -1, -1, -1, -1, -1, | |
845 | -1, -1, -1, -1, -1, -1, -1, -1 | |
846 | }; | |
847 | ||
432d2500 AK |
848 | static char channel_map_aes32[HDSPM_MAX_CHANNELS] = { |
849 | 0, 1, 2, 3, 4, 5, 6, 7, | |
850 | 8, 9, 10, 11, 12, 13, 14, 15, | |
851 | -1, -1, -1, -1, -1, -1, -1, -1, | |
852 | -1, -1, -1, -1, -1, -1, -1, -1, | |
853 | -1, -1, -1, -1, -1, -1, -1, -1, | |
854 | -1, -1, -1, -1, -1, -1, -1, -1, | |
855 | -1, -1, -1, -1, -1, -1, -1, -1, | |
856 | -1, -1, -1, -1, -1, -1, -1, -1 | |
857 | }; | |
858 | ||
98274f07 TI |
859 | struct hdspm_midi { |
860 | struct hdspm *hdspm; | |
763f356c | 861 | int id; |
98274f07 TI |
862 | struct snd_rawmidi *rmidi; |
863 | struct snd_rawmidi_substream *input; | |
864 | struct snd_rawmidi_substream *output; | |
763f356c TI |
865 | char istimer; /* timer in use */ |
866 | struct timer_list timer; | |
867 | spinlock_t lock; | |
868 | int pending; | |
0dca1793 AK |
869 | int dataIn; |
870 | int statusIn; | |
871 | int dataOut; | |
872 | int statusOut; | |
873 | int ie; | |
874 | int irq; | |
875 | }; | |
876 | ||
877 | struct hdspm_tco { | |
878 | int input; | |
879 | int framerate; | |
880 | int wordclock; | |
881 | int samplerate; | |
882 | int pull; | |
883 | int term; /* 0 = off, 1 = on */ | |
763f356c TI |
884 | }; |
885 | ||
98274f07 | 886 | struct hdspm { |
763f356c | 887 | spinlock_t lock; |
ef5fa1a4 TI |
888 | /* only one playback and/or capture stream */ |
889 | struct snd_pcm_substream *capture_substream; | |
890 | struct snd_pcm_substream *playback_substream; | |
763f356c TI |
891 | |
892 | char *card_name; /* for procinfo */ | |
3cee5a60 RB |
893 | unsigned short firmware_rev; /* dont know if relevant (yes if AES32)*/ |
894 | ||
0dca1793 | 895 | uint8_t io_type; |
763f356c | 896 | |
763f356c TI |
897 | int monitor_outs; /* set up monitoring outs init flag */ |
898 | ||
899 | u32 control_register; /* cached value */ | |
900 | u32 control2_register; /* cached value */ | |
0dca1793 | 901 | u32 settings_register; |
763f356c | 902 | |
0dca1793 | 903 | struct hdspm_midi midi[4]; |
763f356c TI |
904 | struct tasklet_struct midi_tasklet; |
905 | ||
906 | size_t period_bytes; | |
0dca1793 AK |
907 | unsigned char ss_in_channels; |
908 | unsigned char ds_in_channels; | |
909 | unsigned char qs_in_channels; | |
910 | unsigned char ss_out_channels; | |
911 | unsigned char ds_out_channels; | |
912 | unsigned char qs_out_channels; | |
913 | ||
914 | unsigned char max_channels_in; | |
915 | unsigned char max_channels_out; | |
916 | ||
286bed0f TI |
917 | signed char *channel_map_in; |
918 | signed char *channel_map_out; | |
0dca1793 | 919 | |
286bed0f TI |
920 | signed char *channel_map_in_ss, *channel_map_in_ds, *channel_map_in_qs; |
921 | signed char *channel_map_out_ss, *channel_map_out_ds, *channel_map_out_qs; | |
0dca1793 AK |
922 | |
923 | char **port_names_in; | |
924 | char **port_names_out; | |
925 | ||
926 | char **port_names_in_ss, **port_names_in_ds, **port_names_in_qs; | |
927 | char **port_names_out_ss, **port_names_out_ds, **port_names_out_qs; | |
763f356c TI |
928 | |
929 | unsigned char *playback_buffer; /* suitably aligned address */ | |
930 | unsigned char *capture_buffer; /* suitably aligned address */ | |
931 | ||
932 | pid_t capture_pid; /* process id which uses capture */ | |
933 | pid_t playback_pid; /* process id which uses capture */ | |
934 | int running; /* running status */ | |
935 | ||
936 | int last_external_sample_rate; /* samplerate mystic ... */ | |
937 | int last_internal_sample_rate; | |
938 | int system_sample_rate; | |
939 | ||
763f356c TI |
940 | int dev; /* Hardware vars... */ |
941 | int irq; | |
942 | unsigned long port; | |
943 | void __iomem *iobase; | |
944 | ||
945 | int irq_count; /* for debug */ | |
0dca1793 | 946 | int midiPorts; |
763f356c | 947 | |
98274f07 TI |
948 | struct snd_card *card; /* one card */ |
949 | struct snd_pcm *pcm; /* has one pcm */ | |
950 | struct snd_hwdep *hwdep; /* and a hwdep for additional ioctl */ | |
763f356c TI |
951 | struct pci_dev *pci; /* and an pci info */ |
952 | ||
953 | /* Mixer vars */ | |
ef5fa1a4 TI |
954 | /* fast alsa mixer */ |
955 | struct snd_kcontrol *playback_mixer_ctls[HDSPM_MAX_CHANNELS]; | |
956 | /* but input to much, so not used */ | |
957 | struct snd_kcontrol *input_mixer_ctls[HDSPM_MAX_CHANNELS]; | |
25985edc | 958 | /* full mixer accessible over mixer ioctl or hwdep-device */ |
ef5fa1a4 | 959 | struct hdspm_mixer *mixer; |
763f356c | 960 | |
0dca1793 | 961 | struct hdspm_tco *tco; /* NULL if no TCO detected */ |
763f356c | 962 | |
0dca1793 AK |
963 | char **texts_autosync; |
964 | int texts_autosync_items; | |
763f356c | 965 | |
0dca1793 | 966 | cycles_t last_interrupt; |
730a5865 | 967 | |
7d53a631 AK |
968 | unsigned int serial; |
969 | ||
730a5865 | 970 | struct hdspm_peak_rms peak_rms; |
763f356c TI |
971 | }; |
972 | ||
763f356c | 973 | |
cebe41d4 | 974 | static DEFINE_PCI_DEVICE_TABLE(snd_hdspm_ids) = { |
763f356c TI |
975 | { |
976 | .vendor = PCI_VENDOR_ID_XILINX, | |
977 | .device = PCI_DEVICE_ID_XILINX_HAMMERFALL_DSP_MADI, | |
978 | .subvendor = PCI_ANY_ID, | |
979 | .subdevice = PCI_ANY_ID, | |
980 | .class = 0, | |
981 | .class_mask = 0, | |
982 | .driver_data = 0}, | |
983 | {0,} | |
984 | }; | |
985 | ||
986 | MODULE_DEVICE_TABLE(pci, snd_hdspm_ids); | |
987 | ||
988 | /* prototypes */ | |
e23e7a14 BP |
989 | static int snd_hdspm_create_alsa_devices(struct snd_card *card, |
990 | struct hdspm *hdspm); | |
991 | static int snd_hdspm_create_pcm(struct snd_card *card, | |
992 | struct hdspm *hdspm); | |
98274f07 | 993 | |
0dca1793 | 994 | static inline void snd_hdspm_initialize_midi_flush(struct hdspm *hdspm); |
3f7bf918 | 995 | static inline int hdspm_get_pll_freq(struct hdspm *hdspm); |
0dca1793 AK |
996 | static int hdspm_update_simple_mixer_controls(struct hdspm *hdspm); |
997 | static int hdspm_autosync_ref(struct hdspm *hdspm); | |
34be7ebb | 998 | static int hdspm_set_toggle_setting(struct hdspm *hdspm, u32 regmask, int out); |
0dca1793 | 999 | static int snd_hdspm_set_defaults(struct hdspm *hdspm); |
21a164df | 1000 | static int hdspm_system_clock_mode(struct hdspm *hdspm); |
0dca1793 | 1001 | static void hdspm_set_sgbuf(struct hdspm *hdspm, |
77a23f26 | 1002 | struct snd_pcm_substream *substream, |
763f356c TI |
1003 | unsigned int reg, int channels); |
1004 | ||
3cee5a60 RB |
1005 | static inline int HDSPM_bit2freq(int n) |
1006 | { | |
62cef821 DV |
1007 | static const int bit2freq_tab[] = { |
1008 | 0, 32000, 44100, 48000, 64000, 88200, | |
3cee5a60 RB |
1009 | 96000, 128000, 176400, 192000 }; |
1010 | if (n < 1 || n > 9) | |
1011 | return 0; | |
1012 | return bit2freq_tab[n]; | |
1013 | } | |
1014 | ||
b2ed6326 AK |
1015 | static bool hdspm_is_raydat_or_aio(struct hdspm *hdspm) |
1016 | { | |
1017 | return ((AIO == hdspm->io_type) || (RayDAT == hdspm->io_type)); | |
1018 | } | |
1019 | ||
1020 | ||
0dca1793 | 1021 | /* Write/read to/from HDSPM with Adresses in Bytes |
763f356c TI |
1022 | not words but only 32Bit writes are allowed */ |
1023 | ||
98274f07 | 1024 | static inline void hdspm_write(struct hdspm * hdspm, unsigned int reg, |
763f356c TI |
1025 | unsigned int val) |
1026 | { | |
1027 | writel(val, hdspm->iobase + reg); | |
1028 | } | |
1029 | ||
98274f07 | 1030 | static inline unsigned int hdspm_read(struct hdspm * hdspm, unsigned int reg) |
763f356c TI |
1031 | { |
1032 | return readl(hdspm->iobase + reg); | |
1033 | } | |
1034 | ||
0dca1793 AK |
1035 | /* for each output channel (chan) I have an Input (in) and Playback (pb) Fader |
1036 | mixer is write only on hardware so we have to cache him for read | |
763f356c TI |
1037 | each fader is a u32, but uses only the first 16 bit */ |
1038 | ||
98274f07 | 1039 | static inline int hdspm_read_in_gain(struct hdspm * hdspm, unsigned int chan, |
763f356c TI |
1040 | unsigned int in) |
1041 | { | |
5bab2482 | 1042 | if (chan >= HDSPM_MIXER_CHANNELS || in >= HDSPM_MIXER_CHANNELS) |
763f356c TI |
1043 | return 0; |
1044 | ||
1045 | return hdspm->mixer->ch[chan].in[in]; | |
1046 | } | |
1047 | ||
98274f07 | 1048 | static inline int hdspm_read_pb_gain(struct hdspm * hdspm, unsigned int chan, |
763f356c TI |
1049 | unsigned int pb) |
1050 | { | |
5bab2482 | 1051 | if (chan >= HDSPM_MIXER_CHANNELS || pb >= HDSPM_MIXER_CHANNELS) |
763f356c TI |
1052 | return 0; |
1053 | return hdspm->mixer->ch[chan].pb[pb]; | |
1054 | } | |
1055 | ||
62cef821 | 1056 | static int hdspm_write_in_gain(struct hdspm *hdspm, unsigned int chan, |
763f356c TI |
1057 | unsigned int in, unsigned short data) |
1058 | { | |
1059 | if (chan >= HDSPM_MIXER_CHANNELS || in >= HDSPM_MIXER_CHANNELS) | |
1060 | return -1; | |
1061 | ||
1062 | hdspm_write(hdspm, | |
1063 | HDSPM_MADI_mixerBase + | |
1064 | ((in + 128 * chan) * sizeof(u32)), | |
1065 | (hdspm->mixer->ch[chan].in[in] = data & 0xFFFF)); | |
1066 | return 0; | |
1067 | } | |
1068 | ||
62cef821 | 1069 | static int hdspm_write_pb_gain(struct hdspm *hdspm, unsigned int chan, |
763f356c TI |
1070 | unsigned int pb, unsigned short data) |
1071 | { | |
1072 | if (chan >= HDSPM_MIXER_CHANNELS || pb >= HDSPM_MIXER_CHANNELS) | |
1073 | return -1; | |
1074 | ||
1075 | hdspm_write(hdspm, | |
1076 | HDSPM_MADI_mixerBase + | |
1077 | ((64 + pb + 128 * chan) * sizeof(u32)), | |
1078 | (hdspm->mixer->ch[chan].pb[pb] = data & 0xFFFF)); | |
1079 | return 0; | |
1080 | } | |
1081 | ||
1082 | ||
1083 | /* enable DMA for specific channels, now available for DSP-MADI */ | |
98274f07 | 1084 | static inline void snd_hdspm_enable_in(struct hdspm * hdspm, int i, int v) |
763f356c TI |
1085 | { |
1086 | hdspm_write(hdspm, HDSPM_inputEnableBase + (4 * i), v); | |
1087 | } | |
1088 | ||
98274f07 | 1089 | static inline void snd_hdspm_enable_out(struct hdspm * hdspm, int i, int v) |
763f356c TI |
1090 | { |
1091 | hdspm_write(hdspm, HDSPM_outputEnableBase + (4 * i), v); | |
1092 | } | |
1093 | ||
1094 | /* check if same process is writing and reading */ | |
62cef821 | 1095 | static int snd_hdspm_use_is_exclusive(struct hdspm *hdspm) |
763f356c TI |
1096 | { |
1097 | unsigned long flags; | |
1098 | int ret = 1; | |
1099 | ||
1100 | spin_lock_irqsave(&hdspm->lock, flags); | |
1101 | if ((hdspm->playback_pid != hdspm->capture_pid) && | |
1102 | (hdspm->playback_pid >= 0) && (hdspm->capture_pid >= 0)) { | |
1103 | ret = 0; | |
1104 | } | |
1105 | spin_unlock_irqrestore(&hdspm->lock, flags); | |
1106 | return ret; | |
1107 | } | |
1108 | ||
fcdc4ba1 AK |
1109 | /* round arbitary sample rates to commonly known rates */ |
1110 | static int hdspm_round_frequency(int rate) | |
1111 | { | |
1112 | if (rate < 38050) | |
1113 | return 32000; | |
1114 | if (rate < 46008) | |
1115 | return 44100; | |
1116 | else | |
1117 | return 48000; | |
1118 | } | |
1119 | ||
a8a729fa AK |
1120 | /* QS and DS rates normally can not be detected |
1121 | * automatically by the card. Only exception is MADI | |
1122 | * in 96k frame mode. | |
1123 | * | |
1124 | * So if we read SS values (32 .. 48k), check for | |
1125 | * user-provided DS/QS bits in the control register | |
1126 | * and multiply the base frequency accordingly. | |
1127 | */ | |
1128 | static int hdspm_rate_multiplier(struct hdspm *hdspm, int rate) | |
1129 | { | |
1130 | if (rate <= 48000) { | |
1131 | if (hdspm->control_register & HDSPM_QuadSpeed) | |
1132 | return rate * 4; | |
1133 | else if (hdspm->control_register & | |
1134 | HDSPM_DoubleSpeed) | |
1135 | return rate * 2; | |
1136 | }; | |
1137 | return rate; | |
1138 | } | |
1139 | ||
fcdc4ba1 AK |
1140 | static int hdspm_tco_sync_check(struct hdspm *hdspm); |
1141 | static int hdspm_sync_in_sync_check(struct hdspm *hdspm); | |
1142 | ||
763f356c | 1143 | /* check for external sample rate */ |
62cef821 | 1144 | static int hdspm_external_sample_rate(struct hdspm *hdspm) |
763f356c | 1145 | { |
0dca1793 AK |
1146 | unsigned int status, status2, timecode; |
1147 | int syncref, rate = 0, rate_bits; | |
3cee5a60 | 1148 | |
0dca1793 AK |
1149 | switch (hdspm->io_type) { |
1150 | case AES32: | |
1151 | status2 = hdspm_read(hdspm, HDSPM_statusRegister2); | |
1152 | status = hdspm_read(hdspm, HDSPM_statusRegister); | |
7c4a95b5 | 1153 | timecode = hdspm_read(hdspm, HDSPM_timecodeRegister); |
0dca1793 AK |
1154 | |
1155 | syncref = hdspm_autosync_ref(hdspm); | |
3cee5a60 RB |
1156 | |
1157 | if (syncref == HDSPM_AES32_AUTOSYNC_FROM_WORD && | |
1158 | status & HDSPM_AES32_wcLock) | |
0dca1793 AK |
1159 | return HDSPM_bit2freq((status >> HDSPM_AES32_wcFreq_bit) & 0xF); |
1160 | ||
3cee5a60 | 1161 | if (syncref >= HDSPM_AES32_AUTOSYNC_FROM_AES1 && |
0dca1793 AK |
1162 | syncref <= HDSPM_AES32_AUTOSYNC_FROM_AES8 && |
1163 | status2 & (HDSPM_LockAES >> | |
1164 | (syncref - HDSPM_AES32_AUTOSYNC_FROM_AES1))) | |
1165 | return HDSPM_bit2freq((timecode >> (4*(syncref-HDSPM_AES32_AUTOSYNC_FROM_AES1))) & 0xF); | |
3cee5a60 | 1166 | return 0; |
0dca1793 AK |
1167 | break; |
1168 | ||
1169 | case MADIface: | |
1170 | status = hdspm_read(hdspm, HDSPM_statusRegister); | |
1171 | ||
1172 | if (!(status & HDSPM_madiLock)) { | |
1173 | rate = 0; /* no lock */ | |
1174 | } else { | |
1175 | switch (status & (HDSPM_status1_freqMask)) { | |
1176 | case HDSPM_status1_F_0*1: | |
1177 | rate = 32000; break; | |
1178 | case HDSPM_status1_F_0*2: | |
1179 | rate = 44100; break; | |
1180 | case HDSPM_status1_F_0*3: | |
1181 | rate = 48000; break; | |
1182 | case HDSPM_status1_F_0*4: | |
1183 | rate = 64000; break; | |
1184 | case HDSPM_status1_F_0*5: | |
1185 | rate = 88200; break; | |
1186 | case HDSPM_status1_F_0*6: | |
1187 | rate = 96000; break; | |
1188 | case HDSPM_status1_F_0*7: | |
1189 | rate = 128000; break; | |
1190 | case HDSPM_status1_F_0*8: | |
1191 | rate = 176400; break; | |
1192 | case HDSPM_status1_F_0*9: | |
1193 | rate = 192000; break; | |
1194 | default: | |
1195 | rate = 0; break; | |
1196 | } | |
1197 | } | |
1198 | ||
1199 | break; | |
1200 | ||
1201 | case MADI: | |
1202 | case AIO: | |
1203 | case RayDAT: | |
1204 | status2 = hdspm_read(hdspm, HDSPM_statusRegister2); | |
1205 | status = hdspm_read(hdspm, HDSPM_statusRegister); | |
1206 | rate = 0; | |
763f356c | 1207 | |
3cee5a60 RB |
1208 | /* if wordclock has synced freq and wordclock is valid */ |
1209 | if ((status2 & HDSPM_wcLock) != 0 && | |
fedf1535 | 1210 | (status2 & HDSPM_SelSyncRef0) == 0) { |
763f356c | 1211 | |
3cee5a60 | 1212 | rate_bits = status2 & HDSPM_wcFreqMask; |
763f356c | 1213 | |
0dca1793 | 1214 | |
3cee5a60 RB |
1215 | switch (rate_bits) { |
1216 | case HDSPM_wcFreq32: | |
1217 | rate = 32000; | |
1218 | break; | |
1219 | case HDSPM_wcFreq44_1: | |
1220 | rate = 44100; | |
1221 | break; | |
1222 | case HDSPM_wcFreq48: | |
1223 | rate = 48000; | |
1224 | break; | |
1225 | case HDSPM_wcFreq64: | |
1226 | rate = 64000; | |
1227 | break; | |
1228 | case HDSPM_wcFreq88_2: | |
1229 | rate = 88200; | |
1230 | break; | |
1231 | case HDSPM_wcFreq96: | |
1232 | rate = 96000; | |
1233 | break; | |
a8cd7148 AK |
1234 | case HDSPM_wcFreq128: |
1235 | rate = 128000; | |
1236 | break; | |
1237 | case HDSPM_wcFreq176_4: | |
1238 | rate = 176400; | |
1239 | break; | |
1240 | case HDSPM_wcFreq192: | |
1241 | rate = 192000; | |
1242 | break; | |
3cee5a60 RB |
1243 | default: |
1244 | rate = 0; | |
1245 | break; | |
1246 | } | |
763f356c | 1247 | } |
763f356c | 1248 | |
ef5fa1a4 TI |
1249 | /* if rate detected and Syncref is Word than have it, |
1250 | * word has priority to MADI | |
1251 | */ | |
3cee5a60 | 1252 | if (rate != 0 && |
0dca1793 | 1253 | (status2 & HDSPM_SelSyncRefMask) == HDSPM_SelSyncRef_WORD) |
7b559397 | 1254 | return hdspm_rate_multiplier(hdspm, rate); |
763f356c | 1255 | |
0dca1793 | 1256 | /* maybe a madi input (which is taken if sel sync is madi) */ |
3cee5a60 RB |
1257 | if (status & HDSPM_madiLock) { |
1258 | rate_bits = status & HDSPM_madiFreqMask; | |
763f356c | 1259 | |
3cee5a60 RB |
1260 | switch (rate_bits) { |
1261 | case HDSPM_madiFreq32: | |
1262 | rate = 32000; | |
1263 | break; | |
1264 | case HDSPM_madiFreq44_1: | |
1265 | rate = 44100; | |
1266 | break; | |
1267 | case HDSPM_madiFreq48: | |
1268 | rate = 48000; | |
1269 | break; | |
1270 | case HDSPM_madiFreq64: | |
1271 | rate = 64000; | |
1272 | break; | |
1273 | case HDSPM_madiFreq88_2: | |
1274 | rate = 88200; | |
1275 | break; | |
1276 | case HDSPM_madiFreq96: | |
1277 | rate = 96000; | |
1278 | break; | |
1279 | case HDSPM_madiFreq128: | |
1280 | rate = 128000; | |
1281 | break; | |
1282 | case HDSPM_madiFreq176_4: | |
1283 | rate = 176400; | |
1284 | break; | |
1285 | case HDSPM_madiFreq192: | |
1286 | rate = 192000; | |
1287 | break; | |
1288 | default: | |
1289 | rate = 0; | |
1290 | break; | |
1291 | } | |
d12c51d8 | 1292 | |
fcdc4ba1 AK |
1293 | } /* endif HDSPM_madiLock */ |
1294 | ||
1295 | /* check sample rate from TCO or SYNC_IN */ | |
1296 | { | |
1297 | bool is_valid_input = 0; | |
1298 | bool has_sync = 0; | |
1299 | ||
1300 | syncref = hdspm_autosync_ref(hdspm); | |
1301 | if (HDSPM_AUTOSYNC_FROM_TCO == syncref) { | |
1302 | is_valid_input = 1; | |
1303 | has_sync = (HDSPM_SYNC_CHECK_SYNC == | |
1304 | hdspm_tco_sync_check(hdspm)); | |
1305 | } else if (HDSPM_AUTOSYNC_FROM_SYNC_IN == syncref) { | |
1306 | is_valid_input = 1; | |
1307 | has_sync = (HDSPM_SYNC_CHECK_SYNC == | |
1308 | hdspm_sync_in_sync_check(hdspm)); | |
d12c51d8 | 1309 | } |
fcdc4ba1 AK |
1310 | |
1311 | if (is_valid_input && has_sync) { | |
1312 | rate = hdspm_round_frequency( | |
1313 | hdspm_get_pll_freq(hdspm)); | |
1314 | } | |
1315 | } | |
1316 | ||
a8a729fa AK |
1317 | rate = hdspm_rate_multiplier(hdspm, rate); |
1318 | ||
0dca1793 | 1319 | break; |
763f356c | 1320 | } |
0dca1793 AK |
1321 | |
1322 | return rate; | |
763f356c TI |
1323 | } |
1324 | ||
7cb155ff AK |
1325 | /* return latency in samples per period */ |
1326 | static int hdspm_get_latency(struct hdspm *hdspm) | |
1327 | { | |
1328 | int n; | |
1329 | ||
1330 | n = hdspm_decode_latency(hdspm->control_register); | |
1331 | ||
1332 | /* Special case for new RME cards with 32 samples period size. | |
1333 | * The three latency bits in the control register | |
1334 | * (HDSP_LatencyMask) encode latency values of 64 samples as | |
1335 | * 0, 128 samples as 1 ... 4096 samples as 6. For old cards, 7 | |
1336 | * denotes 8192 samples, but on new cards like RayDAT or AIO, | |
1337 | * it corresponds to 32 samples. | |
1338 | */ | |
1339 | if ((7 == n) && (RayDAT == hdspm->io_type || AIO == hdspm->io_type)) | |
1340 | n = -1; | |
1341 | ||
1342 | return 1 << (n + 6); | |
1343 | } | |
1344 | ||
763f356c | 1345 | /* Latency function */ |
0dca1793 | 1346 | static inline void hdspm_compute_period_size(struct hdspm *hdspm) |
763f356c | 1347 | { |
7cb155ff | 1348 | hdspm->period_bytes = 4 * hdspm_get_latency(hdspm); |
763f356c TI |
1349 | } |
1350 | ||
0dca1793 AK |
1351 | |
1352 | static snd_pcm_uframes_t hdspm_hw_pointer(struct hdspm *hdspm) | |
763f356c TI |
1353 | { |
1354 | int position; | |
1355 | ||
1356 | position = hdspm_read(hdspm, HDSPM_statusRegister); | |
483cee77 AK |
1357 | |
1358 | switch (hdspm->io_type) { | |
1359 | case RayDAT: | |
1360 | case AIO: | |
1361 | position &= HDSPM_BufferPositionMask; | |
1362 | position /= 4; /* Bytes per sample */ | |
1363 | break; | |
1364 | default: | |
1365 | position = (position & HDSPM_BufferID) ? | |
1366 | (hdspm->period_bytes / 4) : 0; | |
1367 | } | |
763f356c TI |
1368 | |
1369 | return position; | |
1370 | } | |
1371 | ||
1372 | ||
98274f07 | 1373 | static inline void hdspm_start_audio(struct hdspm * s) |
763f356c TI |
1374 | { |
1375 | s->control_register |= (HDSPM_AudioInterruptEnable | HDSPM_Start); | |
1376 | hdspm_write(s, HDSPM_controlRegister, s->control_register); | |
1377 | } | |
1378 | ||
98274f07 | 1379 | static inline void hdspm_stop_audio(struct hdspm * s) |
763f356c TI |
1380 | { |
1381 | s->control_register &= ~(HDSPM_Start | HDSPM_AudioInterruptEnable); | |
1382 | hdspm_write(s, HDSPM_controlRegister, s->control_register); | |
1383 | } | |
1384 | ||
1385 | /* should I silence all or only opened ones ? doit all for first even is 4MB*/ | |
62cef821 | 1386 | static void hdspm_silence_playback(struct hdspm *hdspm) |
763f356c TI |
1387 | { |
1388 | int i; | |
1389 | int n = hdspm->period_bytes; | |
1390 | void *buf = hdspm->playback_buffer; | |
1391 | ||
3cee5a60 RB |
1392 | if (buf == NULL) |
1393 | return; | |
763f356c TI |
1394 | |
1395 | for (i = 0; i < HDSPM_MAX_CHANNELS; i++) { | |
1396 | memset(buf, 0, n); | |
1397 | buf += HDSPM_CHANNEL_BUFFER_BYTES; | |
1398 | } | |
1399 | } | |
1400 | ||
0dca1793 | 1401 | static int hdspm_set_interrupt_interval(struct hdspm *s, unsigned int frames) |
763f356c TI |
1402 | { |
1403 | int n; | |
1404 | ||
1405 | spin_lock_irq(&s->lock); | |
1406 | ||
2e610270 AK |
1407 | if (32 == frames) { |
1408 | /* Special case for new RME cards like RayDAT/AIO which | |
1409 | * support period sizes of 32 samples. Since latency is | |
1410 | * encoded in the three bits of HDSP_LatencyMask, we can only | |
1411 | * have values from 0 .. 7. While 0 still means 64 samples and | |
1412 | * 6 represents 4096 samples on all cards, 7 represents 8192 | |
1413 | * on older cards and 32 samples on new cards. | |
1414 | * | |
1415 | * In other words, period size in samples is calculated by | |
1416 | * 2^(n+6) with n ranging from 0 .. 7. | |
1417 | */ | |
1418 | n = 7; | |
1419 | } else { | |
1420 | frames >>= 7; | |
1421 | n = 0; | |
1422 | while (frames) { | |
1423 | n++; | |
1424 | frames >>= 1; | |
1425 | } | |
763f356c | 1426 | } |
2e610270 | 1427 | |
763f356c TI |
1428 | s->control_register &= ~HDSPM_LatencyMask; |
1429 | s->control_register |= hdspm_encode_latency(n); | |
1430 | ||
1431 | hdspm_write(s, HDSPM_controlRegister, s->control_register); | |
1432 | ||
1433 | hdspm_compute_period_size(s); | |
1434 | ||
1435 | spin_unlock_irq(&s->lock); | |
1436 | ||
1437 | return 0; | |
1438 | } | |
1439 | ||
0dca1793 AK |
1440 | static u64 hdspm_calc_dds_value(struct hdspm *hdspm, u64 period) |
1441 | { | |
1442 | u64 freq_const; | |
1443 | ||
1444 | if (period == 0) | |
1445 | return 0; | |
1446 | ||
1447 | switch (hdspm->io_type) { | |
1448 | case MADI: | |
1449 | case AES32: | |
1450 | freq_const = 110069313433624ULL; | |
1451 | break; | |
1452 | case RayDAT: | |
1453 | case AIO: | |
1454 | freq_const = 104857600000000ULL; | |
1455 | break; | |
1456 | case MADIface: | |
1457 | freq_const = 131072000000000ULL; | |
3d56c8e6 TI |
1458 | break; |
1459 | default: | |
1460 | snd_BUG(); | |
1461 | return 0; | |
0dca1793 AK |
1462 | } |
1463 | ||
1464 | return div_u64(freq_const, period); | |
1465 | } | |
1466 | ||
1467 | ||
ffb2c3c0 RB |
1468 | static void hdspm_set_dds_value(struct hdspm *hdspm, int rate) |
1469 | { | |
1470 | u64 n; | |
0dca1793 | 1471 | |
ffb2c3c0 RB |
1472 | if (rate >= 112000) |
1473 | rate /= 4; | |
1474 | else if (rate >= 56000) | |
1475 | rate /= 2; | |
1476 | ||
0dca1793 AK |
1477 | switch (hdspm->io_type) { |
1478 | case MADIface: | |
3d56c8e6 TI |
1479 | n = 131072000000000ULL; /* 125 MHz */ |
1480 | break; | |
0dca1793 AK |
1481 | case MADI: |
1482 | case AES32: | |
3d56c8e6 TI |
1483 | n = 110069313433624ULL; /* 105 MHz */ |
1484 | break; | |
0dca1793 AK |
1485 | case RayDAT: |
1486 | case AIO: | |
3d56c8e6 TI |
1487 | n = 104857600000000ULL; /* 100 MHz */ |
1488 | break; | |
1489 | default: | |
1490 | snd_BUG(); | |
1491 | return; | |
0dca1793 AK |
1492 | } |
1493 | ||
3f7440a6 | 1494 | n = div_u64(n, rate); |
ffb2c3c0 | 1495 | /* n should be less than 2^32 for being written to FREQ register */ |
da3cec35 | 1496 | snd_BUG_ON(n >> 32); |
ffb2c3c0 RB |
1497 | hdspm_write(hdspm, HDSPM_freqReg, (u32)n); |
1498 | } | |
763f356c TI |
1499 | |
1500 | /* dummy set rate lets see what happens */ | |
98274f07 | 1501 | static int hdspm_set_rate(struct hdspm * hdspm, int rate, int called_internally) |
763f356c | 1502 | { |
763f356c TI |
1503 | int current_rate; |
1504 | int rate_bits; | |
1505 | int not_set = 0; | |
6534599d | 1506 | int current_speed, target_speed; |
763f356c TI |
1507 | |
1508 | /* ASSUMPTION: hdspm->lock is either set, or there is no need for | |
1509 | it (e.g. during module initialization). | |
1510 | */ | |
1511 | ||
1512 | if (!(hdspm->control_register & HDSPM_ClockModeMaster)) { | |
1513 | ||
0dca1793 | 1514 | /* SLAVE --- */ |
763f356c TI |
1515 | if (called_internally) { |
1516 | ||
0dca1793 AK |
1517 | /* request from ctl or card initialization |
1518 | just make a warning an remember setting | |
1519 | for future master mode switching */ | |
1520 | ||
ef5fa1a4 TI |
1521 | snd_printk(KERN_WARNING "HDSPM: " |
1522 | "Warning: device is not running " | |
1523 | "as a clock master.\n"); | |
763f356c TI |
1524 | not_set = 1; |
1525 | } else { | |
1526 | ||
1527 | /* hw_param request while in AutoSync mode */ | |
1528 | int external_freq = | |
1529 | hdspm_external_sample_rate(hdspm); | |
1530 | ||
ef5fa1a4 TI |
1531 | if (hdspm_autosync_ref(hdspm) == |
1532 | HDSPM_AUTOSYNC_FROM_NONE) { | |
763f356c | 1533 | |
ef5fa1a4 TI |
1534 | snd_printk(KERN_WARNING "HDSPM: " |
1535 | "Detected no Externel Sync \n"); | |
763f356c TI |
1536 | not_set = 1; |
1537 | ||
1538 | } else if (rate != external_freq) { | |
1539 | ||
ef5fa1a4 TI |
1540 | snd_printk(KERN_WARNING "HDSPM: " |
1541 | "Warning: No AutoSync source for " | |
1542 | "requested rate\n"); | |
763f356c TI |
1543 | not_set = 1; |
1544 | } | |
1545 | } | |
1546 | } | |
1547 | ||
1548 | current_rate = hdspm->system_sample_rate; | |
1549 | ||
1550 | /* Changing between Singe, Double and Quad speed is not | |
1551 | allowed if any substreams are open. This is because such a change | |
1552 | causes a shift in the location of the DMA buffers and a reduction | |
1553 | in the number of available buffers. | |
1554 | ||
1555 | Note that a similar but essentially insoluble problem exists for | |
1556 | externally-driven rate changes. All we can do is to flag rate | |
0dca1793 | 1557 | changes in the read/write routines. |
763f356c TI |
1558 | */ |
1559 | ||
6534599d RB |
1560 | if (current_rate <= 48000) |
1561 | current_speed = HDSPM_SPEED_SINGLE; | |
1562 | else if (current_rate <= 96000) | |
1563 | current_speed = HDSPM_SPEED_DOUBLE; | |
1564 | else | |
1565 | current_speed = HDSPM_SPEED_QUAD; | |
1566 | ||
1567 | if (rate <= 48000) | |
1568 | target_speed = HDSPM_SPEED_SINGLE; | |
1569 | else if (rate <= 96000) | |
1570 | target_speed = HDSPM_SPEED_DOUBLE; | |
1571 | else | |
1572 | target_speed = HDSPM_SPEED_QUAD; | |
3cee5a60 | 1573 | |
763f356c TI |
1574 | switch (rate) { |
1575 | case 32000: | |
763f356c TI |
1576 | rate_bits = HDSPM_Frequency32KHz; |
1577 | break; | |
1578 | case 44100: | |
763f356c TI |
1579 | rate_bits = HDSPM_Frequency44_1KHz; |
1580 | break; | |
1581 | case 48000: | |
763f356c TI |
1582 | rate_bits = HDSPM_Frequency48KHz; |
1583 | break; | |
1584 | case 64000: | |
763f356c TI |
1585 | rate_bits = HDSPM_Frequency64KHz; |
1586 | break; | |
1587 | case 88200: | |
763f356c TI |
1588 | rate_bits = HDSPM_Frequency88_2KHz; |
1589 | break; | |
1590 | case 96000: | |
763f356c TI |
1591 | rate_bits = HDSPM_Frequency96KHz; |
1592 | break; | |
3cee5a60 | 1593 | case 128000: |
3cee5a60 RB |
1594 | rate_bits = HDSPM_Frequency128KHz; |
1595 | break; | |
1596 | case 176400: | |
3cee5a60 RB |
1597 | rate_bits = HDSPM_Frequency176_4KHz; |
1598 | break; | |
1599 | case 192000: | |
3cee5a60 RB |
1600 | rate_bits = HDSPM_Frequency192KHz; |
1601 | break; | |
763f356c TI |
1602 | default: |
1603 | return -EINVAL; | |
1604 | } | |
1605 | ||
6534599d | 1606 | if (current_speed != target_speed |
763f356c TI |
1607 | && (hdspm->capture_pid >= 0 || hdspm->playback_pid >= 0)) { |
1608 | snd_printk | |
ef5fa1a4 | 1609 | (KERN_ERR "HDSPM: " |
6534599d | 1610 | "cannot change from %s speed to %s speed mode " |
ef5fa1a4 | 1611 | "(capture PID = %d, playback PID = %d)\n", |
6534599d RB |
1612 | hdspm_speed_names[current_speed], |
1613 | hdspm_speed_names[target_speed], | |
763f356c TI |
1614 | hdspm->capture_pid, hdspm->playback_pid); |
1615 | return -EBUSY; | |
1616 | } | |
1617 | ||
1618 | hdspm->control_register &= ~HDSPM_FrequencyMask; | |
1619 | hdspm->control_register |= rate_bits; | |
1620 | hdspm_write(hdspm, HDSPM_controlRegister, hdspm->control_register); | |
1621 | ||
ffb2c3c0 RB |
1622 | /* For AES32, need to set DDS value in FREQ register |
1623 | For MADI, also apparently */ | |
1624 | hdspm_set_dds_value(hdspm, rate); | |
0dca1793 AK |
1625 | |
1626 | if (AES32 == hdspm->io_type && rate != current_rate) | |
ffb2c3c0 | 1627 | hdspm_write(hdspm, HDSPM_eeprom_wr, 0); |
763f356c TI |
1628 | |
1629 | hdspm->system_sample_rate = rate; | |
1630 | ||
0dca1793 AK |
1631 | if (rate <= 48000) { |
1632 | hdspm->channel_map_in = hdspm->channel_map_in_ss; | |
1633 | hdspm->channel_map_out = hdspm->channel_map_out_ss; | |
1634 | hdspm->max_channels_in = hdspm->ss_in_channels; | |
1635 | hdspm->max_channels_out = hdspm->ss_out_channels; | |
1636 | hdspm->port_names_in = hdspm->port_names_in_ss; | |
1637 | hdspm->port_names_out = hdspm->port_names_out_ss; | |
1638 | } else if (rate <= 96000) { | |
1639 | hdspm->channel_map_in = hdspm->channel_map_in_ds; | |
1640 | hdspm->channel_map_out = hdspm->channel_map_out_ds; | |
1641 | hdspm->max_channels_in = hdspm->ds_in_channels; | |
1642 | hdspm->max_channels_out = hdspm->ds_out_channels; | |
1643 | hdspm->port_names_in = hdspm->port_names_in_ds; | |
1644 | hdspm->port_names_out = hdspm->port_names_out_ds; | |
1645 | } else { | |
1646 | hdspm->channel_map_in = hdspm->channel_map_in_qs; | |
1647 | hdspm->channel_map_out = hdspm->channel_map_out_qs; | |
1648 | hdspm->max_channels_in = hdspm->qs_in_channels; | |
1649 | hdspm->max_channels_out = hdspm->qs_out_channels; | |
1650 | hdspm->port_names_in = hdspm->port_names_in_qs; | |
1651 | hdspm->port_names_out = hdspm->port_names_out_qs; | |
1652 | } | |
1653 | ||
763f356c TI |
1654 | if (not_set != 0) |
1655 | return -1; | |
1656 | ||
1657 | return 0; | |
1658 | } | |
1659 | ||
1660 | /* mainly for init to 0 on load */ | |
98274f07 | 1661 | static void all_in_all_mixer(struct hdspm * hdspm, int sgain) |
763f356c TI |
1662 | { |
1663 | int i, j; | |
ef5fa1a4 TI |
1664 | unsigned int gain; |
1665 | ||
1666 | if (sgain > UNITY_GAIN) | |
1667 | gain = UNITY_GAIN; | |
1668 | else if (sgain < 0) | |
1669 | gain = 0; | |
1670 | else | |
1671 | gain = sgain; | |
763f356c TI |
1672 | |
1673 | for (i = 0; i < HDSPM_MIXER_CHANNELS; i++) | |
1674 | for (j = 0; j < HDSPM_MIXER_CHANNELS; j++) { | |
1675 | hdspm_write_in_gain(hdspm, i, j, gain); | |
1676 | hdspm_write_pb_gain(hdspm, i, j, gain); | |
1677 | } | |
1678 | } | |
1679 | ||
1680 | /*---------------------------------------------------------------------------- | |
1681 | MIDI | |
1682 | ----------------------------------------------------------------------------*/ | |
1683 | ||
ef5fa1a4 TI |
1684 | static inline unsigned char snd_hdspm_midi_read_byte (struct hdspm *hdspm, |
1685 | int id) | |
763f356c TI |
1686 | { |
1687 | /* the hardware already does the relevant bit-mask with 0xff */ | |
0dca1793 | 1688 | return hdspm_read(hdspm, hdspm->midi[id].dataIn); |
763f356c TI |
1689 | } |
1690 | ||
ef5fa1a4 TI |
1691 | static inline void snd_hdspm_midi_write_byte (struct hdspm *hdspm, int id, |
1692 | int val) | |
763f356c TI |
1693 | { |
1694 | /* the hardware already does the relevant bit-mask with 0xff */ | |
0dca1793 | 1695 | return hdspm_write(hdspm, hdspm->midi[id].dataOut, val); |
763f356c TI |
1696 | } |
1697 | ||
98274f07 | 1698 | static inline int snd_hdspm_midi_input_available (struct hdspm *hdspm, int id) |
763f356c | 1699 | { |
0dca1793 | 1700 | return hdspm_read(hdspm, hdspm->midi[id].statusIn) & 0xFF; |
763f356c TI |
1701 | } |
1702 | ||
98274f07 | 1703 | static inline int snd_hdspm_midi_output_possible (struct hdspm *hdspm, int id) |
763f356c TI |
1704 | { |
1705 | int fifo_bytes_used; | |
1706 | ||
0dca1793 | 1707 | fifo_bytes_used = hdspm_read(hdspm, hdspm->midi[id].statusOut) & 0xFF; |
763f356c TI |
1708 | |
1709 | if (fifo_bytes_used < 128) | |
1710 | return 128 - fifo_bytes_used; | |
1711 | else | |
1712 | return 0; | |
1713 | } | |
1714 | ||
62cef821 | 1715 | static void snd_hdspm_flush_midi_input(struct hdspm *hdspm, int id) |
763f356c TI |
1716 | { |
1717 | while (snd_hdspm_midi_input_available (hdspm, id)) | |
1718 | snd_hdspm_midi_read_byte (hdspm, id); | |
1719 | } | |
1720 | ||
98274f07 | 1721 | static int snd_hdspm_midi_output_write (struct hdspm_midi *hmidi) |
763f356c TI |
1722 | { |
1723 | unsigned long flags; | |
1724 | int n_pending; | |
1725 | int to_write; | |
1726 | int i; | |
1727 | unsigned char buf[128]; | |
1728 | ||
1729 | /* Output is not interrupt driven */ | |
0dca1793 | 1730 | |
763f356c | 1731 | spin_lock_irqsave (&hmidi->lock, flags); |
ef5fa1a4 TI |
1732 | if (hmidi->output && |
1733 | !snd_rawmidi_transmit_empty (hmidi->output)) { | |
1734 | n_pending = snd_hdspm_midi_output_possible (hmidi->hdspm, | |
1735 | hmidi->id); | |
1736 | if (n_pending > 0) { | |
1737 | if (n_pending > (int)sizeof (buf)) | |
1738 | n_pending = sizeof (buf); | |
0dca1793 | 1739 | |
ef5fa1a4 TI |
1740 | to_write = snd_rawmidi_transmit (hmidi->output, buf, |
1741 | n_pending); | |
1742 | if (to_write > 0) { | |
0dca1793 | 1743 | for (i = 0; i < to_write; ++i) |
ef5fa1a4 TI |
1744 | snd_hdspm_midi_write_byte (hmidi->hdspm, |
1745 | hmidi->id, | |
1746 | buf[i]); | |
763f356c TI |
1747 | } |
1748 | } | |
1749 | } | |
1750 | spin_unlock_irqrestore (&hmidi->lock, flags); | |
1751 | return 0; | |
1752 | } | |
1753 | ||
98274f07 | 1754 | static int snd_hdspm_midi_input_read (struct hdspm_midi *hmidi) |
763f356c | 1755 | { |
ef5fa1a4 TI |
1756 | unsigned char buf[128]; /* this buffer is designed to match the MIDI |
1757 | * input FIFO size | |
1758 | */ | |
763f356c TI |
1759 | unsigned long flags; |
1760 | int n_pending; | |
1761 | int i; | |
1762 | ||
1763 | spin_lock_irqsave (&hmidi->lock, flags); | |
ef5fa1a4 TI |
1764 | n_pending = snd_hdspm_midi_input_available (hmidi->hdspm, hmidi->id); |
1765 | if (n_pending > 0) { | |
763f356c | 1766 | if (hmidi->input) { |
ef5fa1a4 | 1767 | if (n_pending > (int)sizeof (buf)) |
763f356c | 1768 | n_pending = sizeof (buf); |
ef5fa1a4 TI |
1769 | for (i = 0; i < n_pending; ++i) |
1770 | buf[i] = snd_hdspm_midi_read_byte (hmidi->hdspm, | |
1771 | hmidi->id); | |
1772 | if (n_pending) | |
1773 | snd_rawmidi_receive (hmidi->input, buf, | |
1774 | n_pending); | |
763f356c TI |
1775 | } else { |
1776 | /* flush the MIDI input FIFO */ | |
ef5fa1a4 TI |
1777 | while (n_pending--) |
1778 | snd_hdspm_midi_read_byte (hmidi->hdspm, | |
1779 | hmidi->id); | |
763f356c TI |
1780 | } |
1781 | } | |
1782 | hmidi->pending = 0; | |
c0da0014 | 1783 | spin_unlock_irqrestore(&hmidi->lock, flags); |
0dca1793 | 1784 | |
c0da0014 | 1785 | spin_lock_irqsave(&hmidi->hdspm->lock, flags); |
0dca1793 | 1786 | hmidi->hdspm->control_register |= hmidi->ie; |
ef5fa1a4 TI |
1787 | hdspm_write(hmidi->hdspm, HDSPM_controlRegister, |
1788 | hmidi->hdspm->control_register); | |
c0da0014 | 1789 | spin_unlock_irqrestore(&hmidi->hdspm->lock, flags); |
0dca1793 | 1790 | |
763f356c TI |
1791 | return snd_hdspm_midi_output_write (hmidi); |
1792 | } | |
1793 | ||
ef5fa1a4 TI |
1794 | static void |
1795 | snd_hdspm_midi_input_trigger(struct snd_rawmidi_substream *substream, int up) | |
763f356c | 1796 | { |
98274f07 TI |
1797 | struct hdspm *hdspm; |
1798 | struct hdspm_midi *hmidi; | |
763f356c | 1799 | unsigned long flags; |
763f356c | 1800 | |
ef5fa1a4 | 1801 | hmidi = substream->rmidi->private_data; |
763f356c | 1802 | hdspm = hmidi->hdspm; |
0dca1793 | 1803 | |
763f356c TI |
1804 | spin_lock_irqsave (&hdspm->lock, flags); |
1805 | if (up) { | |
0dca1793 | 1806 | if (!(hdspm->control_register & hmidi->ie)) { |
763f356c | 1807 | snd_hdspm_flush_midi_input (hdspm, hmidi->id); |
0dca1793 | 1808 | hdspm->control_register |= hmidi->ie; |
763f356c TI |
1809 | } |
1810 | } else { | |
0dca1793 | 1811 | hdspm->control_register &= ~hmidi->ie; |
763f356c TI |
1812 | } |
1813 | ||
1814 | hdspm_write(hdspm, HDSPM_controlRegister, hdspm->control_register); | |
1815 | spin_unlock_irqrestore (&hdspm->lock, flags); | |
1816 | } | |
1817 | ||
1818 | static void snd_hdspm_midi_output_timer(unsigned long data) | |
1819 | { | |
98274f07 | 1820 | struct hdspm_midi *hmidi = (struct hdspm_midi *) data; |
763f356c | 1821 | unsigned long flags; |
0dca1793 | 1822 | |
763f356c TI |
1823 | snd_hdspm_midi_output_write(hmidi); |
1824 | spin_lock_irqsave (&hmidi->lock, flags); | |
1825 | ||
1826 | /* this does not bump hmidi->istimer, because the | |
1827 | kernel automatically removed the timer when it | |
1828 | expired, and we are now adding it back, thus | |
0dca1793 | 1829 | leaving istimer wherever it was set before. |
763f356c TI |
1830 | */ |
1831 | ||
1832 | if (hmidi->istimer) { | |
1833 | hmidi->timer.expires = 1 + jiffies; | |
1834 | add_timer(&hmidi->timer); | |
1835 | } | |
1836 | ||
1837 | spin_unlock_irqrestore (&hmidi->lock, flags); | |
1838 | } | |
1839 | ||
ef5fa1a4 TI |
1840 | static void |
1841 | snd_hdspm_midi_output_trigger(struct snd_rawmidi_substream *substream, int up) | |
763f356c | 1842 | { |
98274f07 | 1843 | struct hdspm_midi *hmidi; |
763f356c TI |
1844 | unsigned long flags; |
1845 | ||
ef5fa1a4 | 1846 | hmidi = substream->rmidi->private_data; |
763f356c TI |
1847 | spin_lock_irqsave (&hmidi->lock, flags); |
1848 | if (up) { | |
1849 | if (!hmidi->istimer) { | |
1850 | init_timer(&hmidi->timer); | |
1851 | hmidi->timer.function = snd_hdspm_midi_output_timer; | |
1852 | hmidi->timer.data = (unsigned long) hmidi; | |
1853 | hmidi->timer.expires = 1 + jiffies; | |
1854 | add_timer(&hmidi->timer); | |
1855 | hmidi->istimer++; | |
1856 | } | |
1857 | } else { | |
ef5fa1a4 | 1858 | if (hmidi->istimer && --hmidi->istimer <= 0) |
763f356c | 1859 | del_timer (&hmidi->timer); |
763f356c TI |
1860 | } |
1861 | spin_unlock_irqrestore (&hmidi->lock, flags); | |
1862 | if (up) | |
1863 | snd_hdspm_midi_output_write(hmidi); | |
1864 | } | |
1865 | ||
98274f07 | 1866 | static int snd_hdspm_midi_input_open(struct snd_rawmidi_substream *substream) |
763f356c | 1867 | { |
98274f07 | 1868 | struct hdspm_midi *hmidi; |
763f356c | 1869 | |
ef5fa1a4 | 1870 | hmidi = substream->rmidi->private_data; |
763f356c TI |
1871 | spin_lock_irq (&hmidi->lock); |
1872 | snd_hdspm_flush_midi_input (hmidi->hdspm, hmidi->id); | |
1873 | hmidi->input = substream; | |
1874 | spin_unlock_irq (&hmidi->lock); | |
1875 | ||
1876 | return 0; | |
1877 | } | |
1878 | ||
98274f07 | 1879 | static int snd_hdspm_midi_output_open(struct snd_rawmidi_substream *substream) |
763f356c | 1880 | { |
98274f07 | 1881 | struct hdspm_midi *hmidi; |
763f356c | 1882 | |
ef5fa1a4 | 1883 | hmidi = substream->rmidi->private_data; |
763f356c TI |
1884 | spin_lock_irq (&hmidi->lock); |
1885 | hmidi->output = substream; | |
1886 | spin_unlock_irq (&hmidi->lock); | |
1887 | ||
1888 | return 0; | |
1889 | } | |
1890 | ||
98274f07 | 1891 | static int snd_hdspm_midi_input_close(struct snd_rawmidi_substream *substream) |
763f356c | 1892 | { |
98274f07 | 1893 | struct hdspm_midi *hmidi; |
763f356c TI |
1894 | |
1895 | snd_hdspm_midi_input_trigger (substream, 0); | |
1896 | ||
ef5fa1a4 | 1897 | hmidi = substream->rmidi->private_data; |
763f356c TI |
1898 | spin_lock_irq (&hmidi->lock); |
1899 | hmidi->input = NULL; | |
1900 | spin_unlock_irq (&hmidi->lock); | |
1901 | ||
1902 | return 0; | |
1903 | } | |
1904 | ||
98274f07 | 1905 | static int snd_hdspm_midi_output_close(struct snd_rawmidi_substream *substream) |
763f356c | 1906 | { |
98274f07 | 1907 | struct hdspm_midi *hmidi; |
763f356c TI |
1908 | |
1909 | snd_hdspm_midi_output_trigger (substream, 0); | |
1910 | ||
ef5fa1a4 | 1911 | hmidi = substream->rmidi->private_data; |
763f356c TI |
1912 | spin_lock_irq (&hmidi->lock); |
1913 | hmidi->output = NULL; | |
1914 | spin_unlock_irq (&hmidi->lock); | |
1915 | ||
1916 | return 0; | |
1917 | } | |
1918 | ||
98274f07 | 1919 | static struct snd_rawmidi_ops snd_hdspm_midi_output = |
763f356c TI |
1920 | { |
1921 | .open = snd_hdspm_midi_output_open, | |
1922 | .close = snd_hdspm_midi_output_close, | |
1923 | .trigger = snd_hdspm_midi_output_trigger, | |
1924 | }; | |
1925 | ||
98274f07 | 1926 | static struct snd_rawmidi_ops snd_hdspm_midi_input = |
763f356c TI |
1927 | { |
1928 | .open = snd_hdspm_midi_input_open, | |
1929 | .close = snd_hdspm_midi_input_close, | |
1930 | .trigger = snd_hdspm_midi_input_trigger, | |
1931 | }; | |
1932 | ||
e23e7a14 BP |
1933 | static int snd_hdspm_create_midi(struct snd_card *card, |
1934 | struct hdspm *hdspm, int id) | |
763f356c TI |
1935 | { |
1936 | int err; | |
1937 | char buf[32]; | |
1938 | ||
1939 | hdspm->midi[id].id = id; | |
763f356c | 1940 | hdspm->midi[id].hdspm = hdspm; |
763f356c TI |
1941 | spin_lock_init (&hdspm->midi[id].lock); |
1942 | ||
0dca1793 AK |
1943 | if (0 == id) { |
1944 | if (MADIface == hdspm->io_type) { | |
1945 | /* MIDI-over-MADI on HDSPe MADIface */ | |
1946 | hdspm->midi[0].dataIn = HDSPM_midiDataIn2; | |
1947 | hdspm->midi[0].statusIn = HDSPM_midiStatusIn2; | |
1948 | hdspm->midi[0].dataOut = HDSPM_midiDataOut2; | |
1949 | hdspm->midi[0].statusOut = HDSPM_midiStatusOut2; | |
1950 | hdspm->midi[0].ie = HDSPM_Midi2InterruptEnable; | |
1951 | hdspm->midi[0].irq = HDSPM_midi2IRQPending; | |
1952 | } else { | |
1953 | hdspm->midi[0].dataIn = HDSPM_midiDataIn0; | |
1954 | hdspm->midi[0].statusIn = HDSPM_midiStatusIn0; | |
1955 | hdspm->midi[0].dataOut = HDSPM_midiDataOut0; | |
1956 | hdspm->midi[0].statusOut = HDSPM_midiStatusOut0; | |
1957 | hdspm->midi[0].ie = HDSPM_Midi0InterruptEnable; | |
1958 | hdspm->midi[0].irq = HDSPM_midi0IRQPending; | |
1959 | } | |
1960 | } else if (1 == id) { | |
1961 | hdspm->midi[1].dataIn = HDSPM_midiDataIn1; | |
1962 | hdspm->midi[1].statusIn = HDSPM_midiStatusIn1; | |
1963 | hdspm->midi[1].dataOut = HDSPM_midiDataOut1; | |
1964 | hdspm->midi[1].statusOut = HDSPM_midiStatusOut1; | |
1965 | hdspm->midi[1].ie = HDSPM_Midi1InterruptEnable; | |
1966 | hdspm->midi[1].irq = HDSPM_midi1IRQPending; | |
1967 | } else if ((2 == id) && (MADI == hdspm->io_type)) { | |
1968 | /* MIDI-over-MADI on HDSPe MADI */ | |
1969 | hdspm->midi[2].dataIn = HDSPM_midiDataIn2; | |
1970 | hdspm->midi[2].statusIn = HDSPM_midiStatusIn2; | |
1971 | hdspm->midi[2].dataOut = HDSPM_midiDataOut2; | |
1972 | hdspm->midi[2].statusOut = HDSPM_midiStatusOut2; | |
1973 | hdspm->midi[2].ie = HDSPM_Midi2InterruptEnable; | |
1974 | hdspm->midi[2].irq = HDSPM_midi2IRQPending; | |
1975 | } else if (2 == id) { | |
1976 | /* TCO MTC, read only */ | |
1977 | hdspm->midi[2].dataIn = HDSPM_midiDataIn2; | |
1978 | hdspm->midi[2].statusIn = HDSPM_midiStatusIn2; | |
1979 | hdspm->midi[2].dataOut = -1; | |
1980 | hdspm->midi[2].statusOut = -1; | |
1981 | hdspm->midi[2].ie = HDSPM_Midi2InterruptEnable; | |
1982 | hdspm->midi[2].irq = HDSPM_midi2IRQPendingAES; | |
1983 | } else if (3 == id) { | |
1984 | /* TCO MTC on HDSPe MADI */ | |
1985 | hdspm->midi[3].dataIn = HDSPM_midiDataIn3; | |
1986 | hdspm->midi[3].statusIn = HDSPM_midiStatusIn3; | |
1987 | hdspm->midi[3].dataOut = -1; | |
1988 | hdspm->midi[3].statusOut = -1; | |
1989 | hdspm->midi[3].ie = HDSPM_Midi3InterruptEnable; | |
1990 | hdspm->midi[3].irq = HDSPM_midi3IRQPending; | |
1991 | } | |
1992 | ||
1993 | if ((id < 2) || ((2 == id) && ((MADI == hdspm->io_type) || | |
1994 | (MADIface == hdspm->io_type)))) { | |
1995 | if ((id == 0) && (MADIface == hdspm->io_type)) { | |
1996 | sprintf(buf, "%s MIDIoverMADI", card->shortname); | |
1997 | } else if ((id == 2) && (MADI == hdspm->io_type)) { | |
1998 | sprintf(buf, "%s MIDIoverMADI", card->shortname); | |
1999 | } else { | |
2000 | sprintf(buf, "%s MIDI %d", card->shortname, id+1); | |
2001 | } | |
2002 | err = snd_rawmidi_new(card, buf, id, 1, 1, | |
2003 | &hdspm->midi[id].rmidi); | |
2004 | if (err < 0) | |
2005 | return err; | |
763f356c | 2006 | |
0dca1793 AK |
2007 | sprintf(hdspm->midi[id].rmidi->name, "%s MIDI %d", |
2008 | card->id, id+1); | |
2009 | hdspm->midi[id].rmidi->private_data = &hdspm->midi[id]; | |
2010 | ||
2011 | snd_rawmidi_set_ops(hdspm->midi[id].rmidi, | |
2012 | SNDRV_RAWMIDI_STREAM_OUTPUT, | |
2013 | &snd_hdspm_midi_output); | |
2014 | snd_rawmidi_set_ops(hdspm->midi[id].rmidi, | |
2015 | SNDRV_RAWMIDI_STREAM_INPUT, | |
2016 | &snd_hdspm_midi_input); | |
2017 | ||
2018 | hdspm->midi[id].rmidi->info_flags |= | |
2019 | SNDRV_RAWMIDI_INFO_OUTPUT | | |
2020 | SNDRV_RAWMIDI_INFO_INPUT | | |
2021 | SNDRV_RAWMIDI_INFO_DUPLEX; | |
2022 | } else { | |
2023 | /* TCO MTC, read only */ | |
2024 | sprintf(buf, "%s MTC %d", card->shortname, id+1); | |
2025 | err = snd_rawmidi_new(card, buf, id, 1, 1, | |
2026 | &hdspm->midi[id].rmidi); | |
2027 | if (err < 0) | |
2028 | return err; | |
2029 | ||
2030 | sprintf(hdspm->midi[id].rmidi->name, | |
2031 | "%s MTC %d", card->id, id+1); | |
2032 | hdspm->midi[id].rmidi->private_data = &hdspm->midi[id]; | |
763f356c | 2033 | |
0dca1793 AK |
2034 | snd_rawmidi_set_ops(hdspm->midi[id].rmidi, |
2035 | SNDRV_RAWMIDI_STREAM_INPUT, | |
2036 | &snd_hdspm_midi_input); | |
763f356c | 2037 | |
0dca1793 AK |
2038 | hdspm->midi[id].rmidi->info_flags |= SNDRV_RAWMIDI_INFO_INPUT; |
2039 | } | |
763f356c TI |
2040 | |
2041 | return 0; | |
2042 | } | |
2043 | ||
2044 | ||
2045 | static void hdspm_midi_tasklet(unsigned long arg) | |
2046 | { | |
98274f07 | 2047 | struct hdspm *hdspm = (struct hdspm *)arg; |
0dca1793 AK |
2048 | int i = 0; |
2049 | ||
2050 | while (i < hdspm->midiPorts) { | |
2051 | if (hdspm->midi[i].pending) | |
2052 | snd_hdspm_midi_input_read(&hdspm->midi[i]); | |
2053 | ||
2054 | i++; | |
2055 | } | |
2056 | } | |
763f356c TI |
2057 | |
2058 | ||
2059 | /*----------------------------------------------------------------------------- | |
2060 | Status Interface | |
2061 | ----------------------------------------------------------------------------*/ | |
2062 | ||
2063 | /* get the system sample rate which is set */ | |
2064 | ||
0dca1793 | 2065 | |
3f7bf918 AK |
2066 | static inline int hdspm_get_pll_freq(struct hdspm *hdspm) |
2067 | { | |
2068 | unsigned int period, rate; | |
2069 | ||
2070 | period = hdspm_read(hdspm, HDSPM_RD_PLL_FREQ); | |
2071 | rate = hdspm_calc_dds_value(hdspm, period); | |
2072 | ||
2073 | return rate; | |
2074 | } | |
2075 | ||
0dca1793 AK |
2076 | /** |
2077 | * Calculate the real sample rate from the | |
2078 | * current DDS value. | |
2079 | **/ | |
2080 | static int hdspm_get_system_sample_rate(struct hdspm *hdspm) | |
2081 | { | |
3f7bf918 | 2082 | unsigned int rate; |
0dca1793 | 2083 | |
3f7bf918 | 2084 | rate = hdspm_get_pll_freq(hdspm); |
0dca1793 | 2085 | |
a97bda7d | 2086 | if (rate > 207000) { |
21a164df AK |
2087 | /* Unreasonable high sample rate as seen on PCI MADI cards. */ |
2088 | if (0 == hdspm_system_clock_mode(hdspm)) { | |
2089 | /* master mode, return internal sample rate */ | |
2090 | rate = hdspm->system_sample_rate; | |
2091 | } else { | |
2092 | /* slave mode, return external sample rate */ | |
2093 | rate = hdspm_external_sample_rate(hdspm); | |
2094 | } | |
a97bda7d AK |
2095 | } |
2096 | ||
0dca1793 AK |
2097 | return rate; |
2098 | } | |
2099 | ||
2100 | ||
763f356c | 2101 | #define HDSPM_SYSTEM_SAMPLE_RATE(xname, xindex) \ |
f27a64f9 AK |
2102 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ |
2103 | .name = xname, \ | |
2104 | .index = xindex, \ | |
2105 | .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |\ | |
2106 | SNDRV_CTL_ELEM_ACCESS_VOLATILE, \ | |
2107 | .info = snd_hdspm_info_system_sample_rate, \ | |
2108 | .put = snd_hdspm_put_system_sample_rate, \ | |
2109 | .get = snd_hdspm_get_system_sample_rate \ | |
763f356c TI |
2110 | } |
2111 | ||
98274f07 TI |
2112 | static int snd_hdspm_info_system_sample_rate(struct snd_kcontrol *kcontrol, |
2113 | struct snd_ctl_elem_info *uinfo) | |
763f356c TI |
2114 | { |
2115 | uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; | |
2116 | uinfo->count = 1; | |
0dca1793 AK |
2117 | uinfo->value.integer.min = 27000; |
2118 | uinfo->value.integer.max = 207000; | |
2119 | uinfo->value.integer.step = 1; | |
763f356c TI |
2120 | return 0; |
2121 | } | |
2122 | ||
0dca1793 | 2123 | |
98274f07 TI |
2124 | static int snd_hdspm_get_system_sample_rate(struct snd_kcontrol *kcontrol, |
2125 | struct snd_ctl_elem_value * | |
763f356c TI |
2126 | ucontrol) |
2127 | { | |
98274f07 | 2128 | struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); |
763f356c | 2129 | |
0dca1793 AK |
2130 | ucontrol->value.integer.value[0] = hdspm_get_system_sample_rate(hdspm); |
2131 | return 0; | |
2132 | } | |
2133 | ||
41285a98 AK |
2134 | static int snd_hdspm_put_system_sample_rate(struct snd_kcontrol *kcontrol, |
2135 | struct snd_ctl_elem_value * | |
2136 | ucontrol) | |
2137 | { | |
2138 | struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); | |
2139 | ||
2140 | hdspm_set_dds_value(hdspm, ucontrol->value.enumerated.item[0]); | |
2141 | return 0; | |
2142 | } | |
2143 | ||
0dca1793 AK |
2144 | |
2145 | /** | |
2146 | * Returns the WordClock sample rate class for the given card. | |
2147 | **/ | |
2148 | static int hdspm_get_wc_sample_rate(struct hdspm *hdspm) | |
2149 | { | |
2150 | int status; | |
2151 | ||
2152 | switch (hdspm->io_type) { | |
2153 | case RayDAT: | |
2154 | case AIO: | |
2155 | status = hdspm_read(hdspm, HDSPM_RD_STATUS_1); | |
2156 | return (status >> 16) & 0xF; | |
2157 | break; | |
2158 | default: | |
2159 | break; | |
2160 | } | |
2161 | ||
2162 | ||
2163 | return 0; | |
2164 | } | |
2165 | ||
2166 | ||
2167 | /** | |
2168 | * Returns the TCO sample rate class for the given card. | |
2169 | **/ | |
2170 | static int hdspm_get_tco_sample_rate(struct hdspm *hdspm) | |
2171 | { | |
2172 | int status; | |
2173 | ||
2174 | if (hdspm->tco) { | |
2175 | switch (hdspm->io_type) { | |
2176 | case RayDAT: | |
2177 | case AIO: | |
2178 | status = hdspm_read(hdspm, HDSPM_RD_STATUS_1); | |
2179 | return (status >> 20) & 0xF; | |
2180 | break; | |
2181 | default: | |
2182 | break; | |
2183 | } | |
2184 | } | |
2185 | ||
2186 | return 0; | |
2187 | } | |
2188 | ||
2189 | ||
2190 | /** | |
2191 | * Returns the SYNC_IN sample rate class for the given card. | |
2192 | **/ | |
2193 | static int hdspm_get_sync_in_sample_rate(struct hdspm *hdspm) | |
2194 | { | |
2195 | int status; | |
2196 | ||
2197 | if (hdspm->tco) { | |
2198 | switch (hdspm->io_type) { | |
2199 | case RayDAT: | |
2200 | case AIO: | |
2201 | status = hdspm_read(hdspm, HDSPM_RD_STATUS_2); | |
2202 | return (status >> 12) & 0xF; | |
2203 | break; | |
2204 | default: | |
2205 | break; | |
2206 | } | |
2207 | } | |
2208 | ||
763f356c TI |
2209 | return 0; |
2210 | } | |
2211 | ||
0dca1793 AK |
2212 | |
2213 | /** | |
2214 | * Returns the sample rate class for input source <idx> for | |
2215 | * 'new style' cards like the AIO and RayDAT. | |
2216 | **/ | |
2217 | static int hdspm_get_s1_sample_rate(struct hdspm *hdspm, unsigned int idx) | |
2218 | { | |
2219 | int status = hdspm_read(hdspm, HDSPM_RD_STATUS_2); | |
2220 | ||
2221 | return (status >> (idx*4)) & 0xF; | |
2222 | } | |
2223 | ||
e5b7b1fe AK |
2224 | #define ENUMERATED_CTL_INFO(info, texts) \ |
2225 | { \ | |
2226 | uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; \ | |
2227 | uinfo->count = 1; \ | |
2228 | uinfo->value.enumerated.items = ARRAY_SIZE(texts); \ | |
2229 | if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items) \ | |
2230 | uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1; \ | |
2231 | strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]); \ | |
2232 | } | |
2233 | ||
0dca1793 AK |
2234 | |
2235 | ||
763f356c | 2236 | #define HDSPM_AUTOSYNC_SAMPLE_RATE(xname, xindex) \ |
0dca1793 AK |
2237 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ |
2238 | .name = xname, \ | |
2239 | .private_value = xindex, \ | |
2240 | .access = SNDRV_CTL_ELEM_ACCESS_READ, \ | |
2241 | .info = snd_hdspm_info_autosync_sample_rate, \ | |
2242 | .get = snd_hdspm_get_autosync_sample_rate \ | |
763f356c TI |
2243 | } |
2244 | ||
0dca1793 | 2245 | |
98274f07 TI |
2246 | static int snd_hdspm_info_autosync_sample_rate(struct snd_kcontrol *kcontrol, |
2247 | struct snd_ctl_elem_info *uinfo) | |
763f356c | 2248 | { |
e5b7b1fe | 2249 | ENUMERATED_CTL_INFO(uinfo, texts_freq); |
763f356c TI |
2250 | return 0; |
2251 | } | |
2252 | ||
0dca1793 | 2253 | |
98274f07 TI |
2254 | static int snd_hdspm_get_autosync_sample_rate(struct snd_kcontrol *kcontrol, |
2255 | struct snd_ctl_elem_value * | |
763f356c TI |
2256 | ucontrol) |
2257 | { | |
98274f07 | 2258 | struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); |
763f356c | 2259 | |
0dca1793 AK |
2260 | switch (hdspm->io_type) { |
2261 | case RayDAT: | |
2262 | switch (kcontrol->private_value) { | |
2263 | case 0: | |
2264 | ucontrol->value.enumerated.item[0] = | |
2265 | hdspm_get_wc_sample_rate(hdspm); | |
2266 | break; | |
2267 | case 7: | |
2268 | ucontrol->value.enumerated.item[0] = | |
2269 | hdspm_get_tco_sample_rate(hdspm); | |
2270 | break; | |
2271 | case 8: | |
2272 | ucontrol->value.enumerated.item[0] = | |
2273 | hdspm_get_sync_in_sample_rate(hdspm); | |
2274 | break; | |
2275 | default: | |
2276 | ucontrol->value.enumerated.item[0] = | |
2277 | hdspm_get_s1_sample_rate(hdspm, | |
2278 | kcontrol->private_value-1); | |
2279 | } | |
d681deaa | 2280 | break; |
763f356c | 2281 | |
0dca1793 AK |
2282 | case AIO: |
2283 | switch (kcontrol->private_value) { | |
2284 | case 0: /* WC */ | |
2285 | ucontrol->value.enumerated.item[0] = | |
2286 | hdspm_get_wc_sample_rate(hdspm); | |
2287 | break; | |
2288 | case 4: /* TCO */ | |
2289 | ucontrol->value.enumerated.item[0] = | |
2290 | hdspm_get_tco_sample_rate(hdspm); | |
2291 | break; | |
2292 | case 5: /* SYNC_IN */ | |
2293 | ucontrol->value.enumerated.item[0] = | |
2294 | hdspm_get_sync_in_sample_rate(hdspm); | |
2295 | break; | |
2296 | default: | |
2297 | ucontrol->value.enumerated.item[0] = | |
2298 | hdspm_get_s1_sample_rate(hdspm, | |
2299 | ucontrol->id.index-1); | |
2300 | } | |
d681deaa | 2301 | break; |
7c4a95b5 AK |
2302 | |
2303 | case AES32: | |
2304 | ||
2305 | switch (kcontrol->private_value) { | |
2306 | case 0: /* WC */ | |
2307 | ucontrol->value.enumerated.item[0] = | |
2308 | hdspm_get_wc_sample_rate(hdspm); | |
2309 | break; | |
2310 | case 9: /* TCO */ | |
2311 | ucontrol->value.enumerated.item[0] = | |
2312 | hdspm_get_tco_sample_rate(hdspm); | |
2313 | break; | |
2314 | case 10: /* SYNC_IN */ | |
2315 | ucontrol->value.enumerated.item[0] = | |
2316 | hdspm_get_sync_in_sample_rate(hdspm); | |
2317 | break; | |
2318 | default: /* AES1 to AES8 */ | |
2319 | ucontrol->value.enumerated.item[0] = | |
2320 | hdspm_get_s1_sample_rate(hdspm, | |
2321 | kcontrol->private_value-1); | |
2322 | break; | |
7c4a95b5 | 2323 | } |
d681deaa | 2324 | break; |
b8812c55 AK |
2325 | |
2326 | case MADI: | |
2327 | case MADIface: | |
2328 | { | |
2329 | int rate = hdspm_external_sample_rate(hdspm); | |
2330 | int i, selected_rate = 0; | |
2331 | for (i = 1; i < 10; i++) | |
2332 | if (HDSPM_bit2freq(i) == rate) { | |
2333 | selected_rate = i; | |
2334 | break; | |
2335 | } | |
2336 | ucontrol->value.enumerated.item[0] = selected_rate; | |
2337 | } | |
2338 | break; | |
2339 | ||
763f356c | 2340 | default: |
0dca1793 | 2341 | break; |
763f356c | 2342 | } |
763f356c | 2343 | |
0dca1793 | 2344 | return 0; |
763f356c TI |
2345 | } |
2346 | ||
2347 | ||
0dca1793 AK |
2348 | #define HDSPM_SYSTEM_CLOCK_MODE(xname, xindex) \ |
2349 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ | |
2350 | .name = xname, \ | |
2351 | .index = xindex, \ | |
2352 | .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |\ | |
2353 | SNDRV_CTL_ELEM_ACCESS_VOLATILE, \ | |
2354 | .info = snd_hdspm_info_system_clock_mode, \ | |
2355 | .get = snd_hdspm_get_system_clock_mode, \ | |
2356 | .put = snd_hdspm_put_system_clock_mode, \ | |
2357 | } | |
2358 | ||
2359 | ||
2360 | /** | |
2361 | * Returns the system clock mode for the given card. | |
2362 | * @returns 0 - master, 1 - slave | |
2363 | **/ | |
2364 | static int hdspm_system_clock_mode(struct hdspm *hdspm) | |
2365 | { | |
2366 | switch (hdspm->io_type) { | |
2367 | case AIO: | |
2368 | case RayDAT: | |
2369 | if (hdspm->settings_register & HDSPM_c0Master) | |
2370 | return 0; | |
2371 | break; | |
763f356c | 2372 | |
0dca1793 AK |
2373 | default: |
2374 | if (hdspm->control_register & HDSPM_ClockModeMaster) | |
2375 | return 0; | |
2376 | } | |
763f356c | 2377 | |
763f356c TI |
2378 | return 1; |
2379 | } | |
2380 | ||
0dca1793 AK |
2381 | |
2382 | /** | |
2383 | * Sets the system clock mode. | |
2384 | * @param mode 0 - master, 1 - slave | |
2385 | **/ | |
2386 | static void hdspm_set_system_clock_mode(struct hdspm *hdspm, int mode) | |
2387 | { | |
34be7ebb AK |
2388 | hdspm_set_toggle_setting(hdspm, |
2389 | (hdspm_is_raydat_or_aio(hdspm)) ? | |
2390 | HDSPM_c0Master : HDSPM_ClockModeMaster, | |
2391 | (0 == mode)); | |
0dca1793 AK |
2392 | } |
2393 | ||
2394 | ||
2395 | static int snd_hdspm_info_system_clock_mode(struct snd_kcontrol *kcontrol, | |
98274f07 | 2396 | struct snd_ctl_elem_info *uinfo) |
763f356c | 2397 | { |
0dca1793 | 2398 | static char *texts[] = { "Master", "AutoSync" }; |
e5b7b1fe | 2399 | ENUMERATED_CTL_INFO(uinfo, texts); |
763f356c TI |
2400 | return 0; |
2401 | } | |
2402 | ||
98274f07 TI |
2403 | static int snd_hdspm_get_system_clock_mode(struct snd_kcontrol *kcontrol, |
2404 | struct snd_ctl_elem_value *ucontrol) | |
763f356c | 2405 | { |
98274f07 | 2406 | struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); |
763f356c | 2407 | |
0dca1793 | 2408 | ucontrol->value.enumerated.item[0] = hdspm_system_clock_mode(hdspm); |
763f356c TI |
2409 | return 0; |
2410 | } | |
2411 | ||
0dca1793 AK |
2412 | static int snd_hdspm_put_system_clock_mode(struct snd_kcontrol *kcontrol, |
2413 | struct snd_ctl_elem_value *ucontrol) | |
2414 | { | |
2415 | struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); | |
2416 | int val; | |
2417 | ||
2418 | if (!snd_hdspm_use_is_exclusive(hdspm)) | |
2419 | return -EBUSY; | |
2420 | ||
2421 | val = ucontrol->value.enumerated.item[0]; | |
2422 | if (val < 0) | |
2423 | val = 0; | |
2424 | else if (val > 1) | |
2425 | val = 1; | |
2426 | ||
2427 | hdspm_set_system_clock_mode(hdspm, val); | |
2428 | ||
2429 | return 0; | |
2430 | } | |
2431 | ||
2432 | ||
2433 | #define HDSPM_INTERNAL_CLOCK(xname, xindex) \ | |
2434 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ | |
2435 | .name = xname, \ | |
2436 | .index = xindex, \ | |
2437 | .info = snd_hdspm_info_clock_source, \ | |
2438 | .get = snd_hdspm_get_clock_source, \ | |
2439 | .put = snd_hdspm_put_clock_source \ | |
763f356c TI |
2440 | } |
2441 | ||
0dca1793 | 2442 | |
98274f07 | 2443 | static int hdspm_clock_source(struct hdspm * hdspm) |
763f356c | 2444 | { |
0dca1793 AK |
2445 | switch (hdspm->system_sample_rate) { |
2446 | case 32000: return 0; | |
2447 | case 44100: return 1; | |
2448 | case 48000: return 2; | |
2449 | case 64000: return 3; | |
2450 | case 88200: return 4; | |
2451 | case 96000: return 5; | |
2452 | case 128000: return 6; | |
2453 | case 176400: return 7; | |
2454 | case 192000: return 8; | |
763f356c | 2455 | } |
0dca1793 AK |
2456 | |
2457 | return -1; | |
763f356c TI |
2458 | } |
2459 | ||
98274f07 | 2460 | static int hdspm_set_clock_source(struct hdspm * hdspm, int mode) |
763f356c TI |
2461 | { |
2462 | int rate; | |
2463 | switch (mode) { | |
0dca1793 AK |
2464 | case 0: |
2465 | rate = 32000; break; | |
2466 | case 1: | |
2467 | rate = 44100; break; | |
2468 | case 2: | |
2469 | rate = 48000; break; | |
2470 | case 3: | |
2471 | rate = 64000; break; | |
2472 | case 4: | |
2473 | rate = 88200; break; | |
2474 | case 5: | |
2475 | rate = 96000; break; | |
2476 | case 6: | |
2477 | rate = 128000; break; | |
2478 | case 7: | |
2479 | rate = 176400; break; | |
2480 | case 8: | |
2481 | rate = 192000; break; | |
763f356c | 2482 | default: |
0dca1793 | 2483 | rate = 48000; |
763f356c | 2484 | } |
763f356c TI |
2485 | hdspm_set_rate(hdspm, rate, 1); |
2486 | return 0; | |
2487 | } | |
2488 | ||
98274f07 TI |
2489 | static int snd_hdspm_info_clock_source(struct snd_kcontrol *kcontrol, |
2490 | struct snd_ctl_elem_info *uinfo) | |
763f356c | 2491 | { |
763f356c TI |
2492 | uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; |
2493 | uinfo->count = 1; | |
0dca1793 | 2494 | uinfo->value.enumerated.items = 9; |
763f356c TI |
2495 | |
2496 | if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items) | |
2497 | uinfo->value.enumerated.item = | |
2498 | uinfo->value.enumerated.items - 1; | |
2499 | ||
2500 | strcpy(uinfo->value.enumerated.name, | |
0dca1793 | 2501 | texts_freq[uinfo->value.enumerated.item+1]); |
763f356c TI |
2502 | |
2503 | return 0; | |
2504 | } | |
2505 | ||
98274f07 TI |
2506 | static int snd_hdspm_get_clock_source(struct snd_kcontrol *kcontrol, |
2507 | struct snd_ctl_elem_value *ucontrol) | |
763f356c | 2508 | { |
98274f07 | 2509 | struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); |
763f356c TI |
2510 | |
2511 | ucontrol->value.enumerated.item[0] = hdspm_clock_source(hdspm); | |
2512 | return 0; | |
2513 | } | |
2514 | ||
98274f07 TI |
2515 | static int snd_hdspm_put_clock_source(struct snd_kcontrol *kcontrol, |
2516 | struct snd_ctl_elem_value *ucontrol) | |
763f356c | 2517 | { |
98274f07 | 2518 | struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); |
763f356c TI |
2519 | int change; |
2520 | int val; | |
2521 | ||
2522 | if (!snd_hdspm_use_is_exclusive(hdspm)) | |
2523 | return -EBUSY; | |
2524 | val = ucontrol->value.enumerated.item[0]; | |
2525 | if (val < 0) | |
2526 | val = 0; | |
6534599d RB |
2527 | if (val > 9) |
2528 | val = 9; | |
763f356c TI |
2529 | spin_lock_irq(&hdspm->lock); |
2530 | if (val != hdspm_clock_source(hdspm)) | |
2531 | change = (hdspm_set_clock_source(hdspm, val) == 0) ? 1 : 0; | |
2532 | else | |
2533 | change = 0; | |
2534 | spin_unlock_irq(&hdspm->lock); | |
2535 | return change; | |
2536 | } | |
2537 | ||
763f356c | 2538 | |
0dca1793 | 2539 | #define HDSPM_PREF_SYNC_REF(xname, xindex) \ |
f27a64f9 | 2540 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ |
0dca1793 AK |
2541 | .name = xname, \ |
2542 | .index = xindex, \ | |
2543 | .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |\ | |
2544 | SNDRV_CTL_ELEM_ACCESS_VOLATILE, \ | |
2545 | .info = snd_hdspm_info_pref_sync_ref, \ | |
2546 | .get = snd_hdspm_get_pref_sync_ref, \ | |
2547 | .put = snd_hdspm_put_pref_sync_ref \ | |
2548 | } | |
2549 | ||
2550 | ||
2551 | /** | |
2552 | * Returns the current preferred sync reference setting. | |
2553 | * The semantics of the return value are depending on the | |
2554 | * card, please see the comments for clarification. | |
2555 | **/ | |
98274f07 | 2556 | static int hdspm_pref_sync_ref(struct hdspm * hdspm) |
763f356c | 2557 | { |
0dca1793 AK |
2558 | switch (hdspm->io_type) { |
2559 | case AES32: | |
3cee5a60 | 2560 | switch (hdspm->control_register & HDSPM_SyncRefMask) { |
0dca1793 AK |
2561 | case 0: return 0; /* WC */ |
2562 | case HDSPM_SyncRef0: return 1; /* AES 1 */ | |
2563 | case HDSPM_SyncRef1: return 2; /* AES 2 */ | |
2564 | case HDSPM_SyncRef1+HDSPM_SyncRef0: return 3; /* AES 3 */ | |
2565 | case HDSPM_SyncRef2: return 4; /* AES 4 */ | |
2566 | case HDSPM_SyncRef2+HDSPM_SyncRef0: return 5; /* AES 5 */ | |
2567 | case HDSPM_SyncRef2+HDSPM_SyncRef1: return 6; /* AES 6 */ | |
2568 | case HDSPM_SyncRef2+HDSPM_SyncRef1+HDSPM_SyncRef0: | |
2569 | return 7; /* AES 7 */ | |
2570 | case HDSPM_SyncRef3: return 8; /* AES 8 */ | |
2571 | case HDSPM_SyncRef3+HDSPM_SyncRef0: return 9; /* TCO */ | |
3cee5a60 | 2572 | } |
0dca1793 AK |
2573 | break; |
2574 | ||
2575 | case MADI: | |
2576 | case MADIface: | |
2577 | if (hdspm->tco) { | |
2578 | switch (hdspm->control_register & HDSPM_SyncRefMask) { | |
2579 | case 0: return 0; /* WC */ | |
2580 | case HDSPM_SyncRef0: return 1; /* MADI */ | |
2581 | case HDSPM_SyncRef1: return 2; /* TCO */ | |
2582 | case HDSPM_SyncRef1+HDSPM_SyncRef0: | |
2583 | return 3; /* SYNC_IN */ | |
2584 | } | |
2585 | } else { | |
2586 | switch (hdspm->control_register & HDSPM_SyncRefMask) { | |
2587 | case 0: return 0; /* WC */ | |
2588 | case HDSPM_SyncRef0: return 1; /* MADI */ | |
2589 | case HDSPM_SyncRef1+HDSPM_SyncRef0: | |
2590 | return 2; /* SYNC_IN */ | |
2591 | } | |
2592 | } | |
2593 | break; | |
2594 | ||
2595 | case RayDAT: | |
2596 | if (hdspm->tco) { | |
2597 | switch ((hdspm->settings_register & | |
2598 | HDSPM_c0_SyncRefMask) / HDSPM_c0_SyncRef0) { | |
2599 | case 0: return 0; /* WC */ | |
2600 | case 3: return 1; /* ADAT 1 */ | |
2601 | case 4: return 2; /* ADAT 2 */ | |
2602 | case 5: return 3; /* ADAT 3 */ | |
2603 | case 6: return 4; /* ADAT 4 */ | |
2604 | case 1: return 5; /* AES */ | |
2605 | case 2: return 6; /* SPDIF */ | |
2606 | case 9: return 7; /* TCO */ | |
2607 | case 10: return 8; /* SYNC_IN */ | |
2608 | } | |
2609 | } else { | |
2610 | switch ((hdspm->settings_register & | |
2611 | HDSPM_c0_SyncRefMask) / HDSPM_c0_SyncRef0) { | |
2612 | case 0: return 0; /* WC */ | |
2613 | case 3: return 1; /* ADAT 1 */ | |
2614 | case 4: return 2; /* ADAT 2 */ | |
2615 | case 5: return 3; /* ADAT 3 */ | |
2616 | case 6: return 4; /* ADAT 4 */ | |
2617 | case 1: return 5; /* AES */ | |
2618 | case 2: return 6; /* SPDIF */ | |
2619 | case 10: return 7; /* SYNC_IN */ | |
2620 | } | |
3cee5a60 | 2621 | } |
0dca1793 AK |
2622 | |
2623 | break; | |
2624 | ||
2625 | case AIO: | |
2626 | if (hdspm->tco) { | |
2627 | switch ((hdspm->settings_register & | |
2628 | HDSPM_c0_SyncRefMask) / HDSPM_c0_SyncRef0) { | |
2629 | case 0: return 0; /* WC */ | |
2630 | case 3: return 1; /* ADAT */ | |
2631 | case 1: return 2; /* AES */ | |
2632 | case 2: return 3; /* SPDIF */ | |
2633 | case 9: return 4; /* TCO */ | |
2634 | case 10: return 5; /* SYNC_IN */ | |
2635 | } | |
2636 | } else { | |
2637 | switch ((hdspm->settings_register & | |
2638 | HDSPM_c0_SyncRefMask) / HDSPM_c0_SyncRef0) { | |
2639 | case 0: return 0; /* WC */ | |
2640 | case 3: return 1; /* ADAT */ | |
2641 | case 1: return 2; /* AES */ | |
2642 | case 2: return 3; /* SPDIF */ | |
2643 | case 10: return 4; /* SYNC_IN */ | |
2644 | } | |
2645 | } | |
2646 | ||
2647 | break; | |
763f356c TI |
2648 | } |
2649 | ||
0dca1793 | 2650 | return -1; |
763f356c TI |
2651 | } |
2652 | ||
0dca1793 AK |
2653 | |
2654 | /** | |
2655 | * Set the preferred sync reference to <pref>. The semantics | |
2656 | * of <pref> are depending on the card type, see the comments | |
2657 | * for clarification. | |
2658 | **/ | |
98274f07 | 2659 | static int hdspm_set_pref_sync_ref(struct hdspm * hdspm, int pref) |
763f356c | 2660 | { |
0dca1793 | 2661 | int p = 0; |
763f356c | 2662 | |
0dca1793 AK |
2663 | switch (hdspm->io_type) { |
2664 | case AES32: | |
2665 | hdspm->control_register &= ~HDSPM_SyncRefMask; | |
3cee5a60 | 2666 | switch (pref) { |
0dca1793 AK |
2667 | case 0: /* WC */ |
2668 | break; | |
2669 | case 1: /* AES 1 */ | |
2670 | hdspm->control_register |= HDSPM_SyncRef0; | |
2671 | break; | |
2672 | case 2: /* AES 2 */ | |
2673 | hdspm->control_register |= HDSPM_SyncRef1; | |
2674 | break; | |
2675 | case 3: /* AES 3 */ | |
2676 | hdspm->control_register |= | |
2677 | HDSPM_SyncRef1+HDSPM_SyncRef0; | |
2678 | break; | |
2679 | case 4: /* AES 4 */ | |
2680 | hdspm->control_register |= HDSPM_SyncRef2; | |
2681 | break; | |
2682 | case 5: /* AES 5 */ | |
2683 | hdspm->control_register |= | |
2684 | HDSPM_SyncRef2+HDSPM_SyncRef0; | |
2685 | break; | |
2686 | case 6: /* AES 6 */ | |
2687 | hdspm->control_register |= | |
2688 | HDSPM_SyncRef2+HDSPM_SyncRef1; | |
2689 | break; | |
2690 | case 7: /* AES 7 */ | |
2691 | hdspm->control_register |= | |
2692 | HDSPM_SyncRef2+HDSPM_SyncRef1+HDSPM_SyncRef0; | |
3cee5a60 | 2693 | break; |
0dca1793 AK |
2694 | case 8: /* AES 8 */ |
2695 | hdspm->control_register |= HDSPM_SyncRef3; | |
2696 | break; | |
2697 | case 9: /* TCO */ | |
2698 | hdspm->control_register |= | |
2699 | HDSPM_SyncRef3+HDSPM_SyncRef0; | |
3cee5a60 RB |
2700 | break; |
2701 | default: | |
2702 | return -1; | |
2703 | } | |
0dca1793 AK |
2704 | |
2705 | break; | |
2706 | ||
2707 | case MADI: | |
2708 | case MADIface: | |
2709 | hdspm->control_register &= ~HDSPM_SyncRefMask; | |
2710 | if (hdspm->tco) { | |
2711 | switch (pref) { | |
2712 | case 0: /* WC */ | |
2713 | break; | |
2714 | case 1: /* MADI */ | |
2715 | hdspm->control_register |= HDSPM_SyncRef0; | |
2716 | break; | |
2717 | case 2: /* TCO */ | |
2718 | hdspm->control_register |= HDSPM_SyncRef1; | |
2719 | break; | |
2720 | case 3: /* SYNC_IN */ | |
2721 | hdspm->control_register |= | |
2722 | HDSPM_SyncRef0+HDSPM_SyncRef1; | |
2723 | break; | |
2724 | default: | |
2725 | return -1; | |
2726 | } | |
2727 | } else { | |
2728 | switch (pref) { | |
2729 | case 0: /* WC */ | |
2730 | break; | |
2731 | case 1: /* MADI */ | |
2732 | hdspm->control_register |= HDSPM_SyncRef0; | |
2733 | break; | |
2734 | case 2: /* SYNC_IN */ | |
2735 | hdspm->control_register |= | |
2736 | HDSPM_SyncRef0+HDSPM_SyncRef1; | |
2737 | break; | |
2738 | default: | |
2739 | return -1; | |
2740 | } | |
2741 | } | |
2742 | ||
2743 | break; | |
2744 | ||
2745 | case RayDAT: | |
2746 | if (hdspm->tco) { | |
2747 | switch (pref) { | |
2748 | case 0: p = 0; break; /* WC */ | |
2749 | case 1: p = 3; break; /* ADAT 1 */ | |
2750 | case 2: p = 4; break; /* ADAT 2 */ | |
2751 | case 3: p = 5; break; /* ADAT 3 */ | |
2752 | case 4: p = 6; break; /* ADAT 4 */ | |
2753 | case 5: p = 1; break; /* AES */ | |
2754 | case 6: p = 2; break; /* SPDIF */ | |
2755 | case 7: p = 9; break; /* TCO */ | |
2756 | case 8: p = 10; break; /* SYNC_IN */ | |
2757 | default: return -1; | |
2758 | } | |
2759 | } else { | |
2760 | switch (pref) { | |
2761 | case 0: p = 0; break; /* WC */ | |
2762 | case 1: p = 3; break; /* ADAT 1 */ | |
2763 | case 2: p = 4; break; /* ADAT 2 */ | |
2764 | case 3: p = 5; break; /* ADAT 3 */ | |
2765 | case 4: p = 6; break; /* ADAT 4 */ | |
2766 | case 5: p = 1; break; /* AES */ | |
2767 | case 6: p = 2; break; /* SPDIF */ | |
2768 | case 7: p = 10; break; /* SYNC_IN */ | |
2769 | default: return -1; | |
2770 | } | |
2771 | } | |
2772 | break; | |
2773 | ||
2774 | case AIO: | |
2775 | if (hdspm->tco) { | |
2776 | switch (pref) { | |
2777 | case 0: p = 0; break; /* WC */ | |
2778 | case 1: p = 3; break; /* ADAT */ | |
2779 | case 2: p = 1; break; /* AES */ | |
2780 | case 3: p = 2; break; /* SPDIF */ | |
2781 | case 4: p = 9; break; /* TCO */ | |
2782 | case 5: p = 10; break; /* SYNC_IN */ | |
2783 | default: return -1; | |
2784 | } | |
2785 | } else { | |
2786 | switch (pref) { | |
2787 | case 0: p = 0; break; /* WC */ | |
2788 | case 1: p = 3; break; /* ADAT */ | |
2789 | case 2: p = 1; break; /* AES */ | |
2790 | case 3: p = 2; break; /* SPDIF */ | |
2791 | case 4: p = 10; break; /* SYNC_IN */ | |
2792 | default: return -1; | |
2793 | } | |
2794 | } | |
2795 | break; | |
763f356c | 2796 | } |
0dca1793 AK |
2797 | |
2798 | switch (hdspm->io_type) { | |
2799 | case RayDAT: | |
2800 | case AIO: | |
2801 | hdspm->settings_register &= ~HDSPM_c0_SyncRefMask; | |
2802 | hdspm->settings_register |= HDSPM_c0_SyncRef0 * p; | |
2803 | hdspm_write(hdspm, HDSPM_WR_SETTINGS, hdspm->settings_register); | |
2804 | break; | |
2805 | ||
2806 | case MADI: | |
2807 | case MADIface: | |
2808 | case AES32: | |
2809 | hdspm_write(hdspm, HDSPM_controlRegister, | |
2810 | hdspm->control_register); | |
2811 | } | |
2812 | ||
763f356c TI |
2813 | return 0; |
2814 | } | |
2815 | ||
0dca1793 | 2816 | |
98274f07 TI |
2817 | static int snd_hdspm_info_pref_sync_ref(struct snd_kcontrol *kcontrol, |
2818 | struct snd_ctl_elem_info *uinfo) | |
763f356c | 2819 | { |
3cee5a60 | 2820 | struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); |
763f356c | 2821 | |
0dca1793 AK |
2822 | uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; |
2823 | uinfo->count = 1; | |
2824 | uinfo->value.enumerated.items = hdspm->texts_autosync_items; | |
3cee5a60 | 2825 | |
0dca1793 AK |
2826 | if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items) |
2827 | uinfo->value.enumerated.item = | |
2828 | uinfo->value.enumerated.items - 1; | |
3cee5a60 | 2829 | |
0dca1793 AK |
2830 | strcpy(uinfo->value.enumerated.name, |
2831 | hdspm->texts_autosync[uinfo->value.enumerated.item]); | |
3cee5a60 | 2832 | |
763f356c TI |
2833 | return 0; |
2834 | } | |
2835 | ||
98274f07 TI |
2836 | static int snd_hdspm_get_pref_sync_ref(struct snd_kcontrol *kcontrol, |
2837 | struct snd_ctl_elem_value *ucontrol) | |
763f356c | 2838 | { |
98274f07 | 2839 | struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); |
0dca1793 | 2840 | int psf = hdspm_pref_sync_ref(hdspm); |
763f356c | 2841 | |
0dca1793 AK |
2842 | if (psf >= 0) { |
2843 | ucontrol->value.enumerated.item[0] = psf; | |
2844 | return 0; | |
2845 | } | |
2846 | ||
2847 | return -1; | |
763f356c TI |
2848 | } |
2849 | ||
98274f07 TI |
2850 | static int snd_hdspm_put_pref_sync_ref(struct snd_kcontrol *kcontrol, |
2851 | struct snd_ctl_elem_value *ucontrol) | |
763f356c | 2852 | { |
98274f07 | 2853 | struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); |
0dca1793 | 2854 | int val, change = 0; |
763f356c TI |
2855 | |
2856 | if (!snd_hdspm_use_is_exclusive(hdspm)) | |
2857 | return -EBUSY; | |
2858 | ||
0dca1793 AK |
2859 | val = ucontrol->value.enumerated.item[0]; |
2860 | ||
2861 | if (val < 0) | |
2862 | val = 0; | |
2863 | else if (val >= hdspm->texts_autosync_items) | |
2864 | val = hdspm->texts_autosync_items-1; | |
763f356c TI |
2865 | |
2866 | spin_lock_irq(&hdspm->lock); | |
0dca1793 AK |
2867 | if (val != hdspm_pref_sync_ref(hdspm)) |
2868 | change = (0 == hdspm_set_pref_sync_ref(hdspm, val)) ? 1 : 0; | |
2869 | ||
763f356c TI |
2870 | spin_unlock_irq(&hdspm->lock); |
2871 | return change; | |
2872 | } | |
2873 | ||
0dca1793 | 2874 | |
763f356c | 2875 | #define HDSPM_AUTOSYNC_REF(xname, xindex) \ |
f27a64f9 AK |
2876 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ |
2877 | .name = xname, \ | |
2878 | .index = xindex, \ | |
2879 | .access = SNDRV_CTL_ELEM_ACCESS_READ, \ | |
2880 | .info = snd_hdspm_info_autosync_ref, \ | |
2881 | .get = snd_hdspm_get_autosync_ref, \ | |
763f356c TI |
2882 | } |
2883 | ||
0dca1793 | 2884 | static int hdspm_autosync_ref(struct hdspm *hdspm) |
763f356c | 2885 | { |
0dca1793 | 2886 | if (AES32 == hdspm->io_type) { |
3cee5a60 | 2887 | unsigned int status = hdspm_read(hdspm, HDSPM_statusRegister); |
0dca1793 AK |
2888 | unsigned int syncref = |
2889 | (status >> HDSPM_AES32_syncref_bit) & 0xF; | |
3cee5a60 RB |
2890 | if (syncref == 0) |
2891 | return HDSPM_AES32_AUTOSYNC_FROM_WORD; | |
2892 | if (syncref <= 8) | |
2893 | return syncref; | |
2894 | return HDSPM_AES32_AUTOSYNC_FROM_NONE; | |
0dca1793 | 2895 | } else if (MADI == hdspm->io_type) { |
3cee5a60 RB |
2896 | /* This looks at the autosync selected sync reference */ |
2897 | unsigned int status2 = hdspm_read(hdspm, HDSPM_statusRegister2); | |
2898 | ||
2899 | switch (status2 & HDSPM_SelSyncRefMask) { | |
2900 | case HDSPM_SelSyncRef_WORD: | |
2901 | return HDSPM_AUTOSYNC_FROM_WORD; | |
2902 | case HDSPM_SelSyncRef_MADI: | |
2903 | return HDSPM_AUTOSYNC_FROM_MADI; | |
0dca1793 AK |
2904 | case HDSPM_SelSyncRef_TCO: |
2905 | return HDSPM_AUTOSYNC_FROM_TCO; | |
2906 | case HDSPM_SelSyncRef_SyncIn: | |
2907 | return HDSPM_AUTOSYNC_FROM_SYNC_IN; | |
3cee5a60 RB |
2908 | case HDSPM_SelSyncRef_NVALID: |
2909 | return HDSPM_AUTOSYNC_FROM_NONE; | |
2910 | default: | |
2911 | return 0; | |
2912 | } | |
763f356c | 2913 | |
763f356c | 2914 | } |
0dca1793 | 2915 | return 0; |
763f356c TI |
2916 | } |
2917 | ||
0dca1793 | 2918 | |
98274f07 TI |
2919 | static int snd_hdspm_info_autosync_ref(struct snd_kcontrol *kcontrol, |
2920 | struct snd_ctl_elem_info *uinfo) | |
763f356c | 2921 | { |
3cee5a60 | 2922 | struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); |
763f356c | 2923 | |
0dca1793 | 2924 | if (AES32 == hdspm->io_type) { |
3cee5a60 RB |
2925 | static char *texts[] = { "WordClock", "AES1", "AES2", "AES3", |
2926 | "AES4", "AES5", "AES6", "AES7", "AES8", "None"}; | |
2927 | ||
2928 | uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; | |
2929 | uinfo->count = 1; | |
2930 | uinfo->value.enumerated.items = 10; | |
ef5fa1a4 TI |
2931 | if (uinfo->value.enumerated.item >= |
2932 | uinfo->value.enumerated.items) | |
3cee5a60 RB |
2933 | uinfo->value.enumerated.item = |
2934 | uinfo->value.enumerated.items - 1; | |
2935 | strcpy(uinfo->value.enumerated.name, | |
2936 | texts[uinfo->value.enumerated.item]); | |
0dca1793 AK |
2937 | } else if (MADI == hdspm->io_type) { |
2938 | static char *texts[] = {"Word Clock", "MADI", "TCO", | |
2939 | "Sync In", "None" }; | |
3cee5a60 RB |
2940 | |
2941 | uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; | |
2942 | uinfo->count = 1; | |
0dca1793 | 2943 | uinfo->value.enumerated.items = 5; |
ef5fa1a4 | 2944 | if (uinfo->value.enumerated.item >= |
0dca1793 | 2945 | uinfo->value.enumerated.items) |
3cee5a60 RB |
2946 | uinfo->value.enumerated.item = |
2947 | uinfo->value.enumerated.items - 1; | |
2948 | strcpy(uinfo->value.enumerated.name, | |
2949 | texts[uinfo->value.enumerated.item]); | |
2950 | } | |
763f356c TI |
2951 | return 0; |
2952 | } | |
2953 | ||
98274f07 TI |
2954 | static int snd_hdspm_get_autosync_ref(struct snd_kcontrol *kcontrol, |
2955 | struct snd_ctl_elem_value *ucontrol) | |
763f356c | 2956 | { |
98274f07 | 2957 | struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); |
763f356c | 2958 | |
6534599d | 2959 | ucontrol->value.enumerated.item[0] = hdspm_autosync_ref(hdspm); |
763f356c TI |
2960 | return 0; |
2961 | } | |
2962 | ||
f99c7881 AK |
2963 | |
2964 | ||
2965 | #define HDSPM_TCO_VIDEO_INPUT_FORMAT(xname, xindex) \ | |
2966 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ | |
2967 | .name = xname, \ | |
2968 | .access = SNDRV_CTL_ELEM_ACCESS_READ |\ | |
2969 | SNDRV_CTL_ELEM_ACCESS_VOLATILE, \ | |
2970 | .info = snd_hdspm_info_tco_video_input_format, \ | |
2971 | .get = snd_hdspm_get_tco_video_input_format, \ | |
2972 | } | |
2973 | ||
2974 | static int snd_hdspm_info_tco_video_input_format(struct snd_kcontrol *kcontrol, | |
2975 | struct snd_ctl_elem_info *uinfo) | |
2976 | { | |
2977 | static char *texts[] = {"No video", "NTSC", "PAL"}; | |
2978 | ENUMERATED_CTL_INFO(uinfo, texts); | |
2979 | return 0; | |
2980 | } | |
2981 | ||
2982 | static int snd_hdspm_get_tco_video_input_format(struct snd_kcontrol *kcontrol, | |
2983 | struct snd_ctl_elem_value *ucontrol) | |
2984 | { | |
2985 | u32 status; | |
2986 | int ret = 0; | |
2987 | ||
2988 | struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); | |
2989 | status = hdspm_read(hdspm, HDSPM_RD_TCO + 4); | |
2990 | switch (status & (HDSPM_TCO1_Video_Input_Format_NTSC | | |
2991 | HDSPM_TCO1_Video_Input_Format_PAL)) { | |
2992 | case HDSPM_TCO1_Video_Input_Format_NTSC: | |
2993 | /* ntsc */ | |
2994 | ret = 1; | |
2995 | break; | |
2996 | case HDSPM_TCO1_Video_Input_Format_PAL: | |
2997 | /* pal */ | |
2998 | ret = 2; | |
2999 | break; | |
3000 | default: | |
3001 | /* no video */ | |
3002 | ret = 0; | |
3003 | break; | |
3004 | } | |
3005 | ucontrol->value.enumerated.item[0] = ret; | |
3006 | return 0; | |
3007 | } | |
3008 | ||
3009 | ||
3010 | ||
3011 | #define HDSPM_TCO_LTC_FRAMES(xname, xindex) \ | |
3012 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ | |
3013 | .name = xname, \ | |
3014 | .access = SNDRV_CTL_ELEM_ACCESS_READ |\ | |
3015 | SNDRV_CTL_ELEM_ACCESS_VOLATILE, \ | |
3016 | .info = snd_hdspm_info_tco_ltc_frames, \ | |
3017 | .get = snd_hdspm_get_tco_ltc_frames, \ | |
3018 | } | |
3019 | ||
3020 | static int snd_hdspm_info_tco_ltc_frames(struct snd_kcontrol *kcontrol, | |
3021 | struct snd_ctl_elem_info *uinfo) | |
3022 | { | |
3023 | static char *texts[] = {"No lock", "24 fps", "25 fps", "29.97 fps", | |
3024 | "30 fps"}; | |
3025 | ENUMERATED_CTL_INFO(uinfo, texts); | |
3026 | return 0; | |
3027 | } | |
3028 | ||
3029 | static int hdspm_tco_ltc_frames(struct hdspm *hdspm) | |
3030 | { | |
3031 | u32 status; | |
3032 | int ret = 0; | |
3033 | ||
3034 | status = hdspm_read(hdspm, HDSPM_RD_TCO + 4); | |
3035 | if (status & HDSPM_TCO1_LTC_Input_valid) { | |
3036 | switch (status & (HDSPM_TCO1_LTC_Format_LSB | | |
3037 | HDSPM_TCO1_LTC_Format_MSB)) { | |
3038 | case 0: | |
3039 | /* 24 fps */ | |
3040 | ret = 1; | |
3041 | break; | |
3042 | case HDSPM_TCO1_LTC_Format_LSB: | |
3043 | /* 25 fps */ | |
3044 | ret = 2; | |
3045 | break; | |
3046 | case HDSPM_TCO1_LTC_Format_MSB: | |
3047 | /* 25 fps */ | |
3048 | ret = 3; | |
3049 | break; | |
3050 | default: | |
3051 | /* 30 fps */ | |
3052 | ret = 4; | |
3053 | break; | |
3054 | } | |
3055 | } | |
3056 | ||
3057 | return ret; | |
3058 | } | |
3059 | ||
3060 | static int snd_hdspm_get_tco_ltc_frames(struct snd_kcontrol *kcontrol, | |
3061 | struct snd_ctl_elem_value *ucontrol) | |
3062 | { | |
3063 | struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); | |
3064 | ||
3065 | ucontrol->value.enumerated.item[0] = hdspm_tco_ltc_frames(hdspm); | |
3066 | return 0; | |
3067 | } | |
3068 | ||
bf0ff87b AK |
3069 | #define HDSPM_TOGGLE_SETTING(xname, xindex) \ |
3070 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ | |
3071 | .name = xname, \ | |
3072 | .private_value = xindex, \ | |
3073 | .info = snd_hdspm_info_toggle_setting, \ | |
3074 | .get = snd_hdspm_get_toggle_setting, \ | |
3075 | .put = snd_hdspm_put_toggle_setting \ | |
3076 | } | |
3077 | ||
3078 | static int hdspm_toggle_setting(struct hdspm *hdspm, u32 regmask) | |
3079 | { | |
ce13f3f3 AK |
3080 | u32 reg; |
3081 | ||
3082 | if (hdspm_is_raydat_or_aio(hdspm)) | |
3083 | reg = hdspm->settings_register; | |
3084 | else | |
3085 | reg = hdspm->control_register; | |
3086 | ||
3087 | return (reg & regmask) ? 1 : 0; | |
bf0ff87b AK |
3088 | } |
3089 | ||
3090 | static int hdspm_set_toggle_setting(struct hdspm *hdspm, u32 regmask, int out) | |
3091 | { | |
ce13f3f3 AK |
3092 | u32 *reg; |
3093 | u32 target_reg; | |
3094 | ||
3095 | if (hdspm_is_raydat_or_aio(hdspm)) { | |
3096 | reg = &(hdspm->settings_register); | |
3097 | target_reg = HDSPM_WR_SETTINGS; | |
3098 | } else { | |
3099 | reg = &(hdspm->control_register); | |
3100 | target_reg = HDSPM_controlRegister; | |
3101 | } | |
3102 | ||
bf0ff87b | 3103 | if (out) |
ce13f3f3 | 3104 | *reg |= regmask; |
bf0ff87b | 3105 | else |
ce13f3f3 AK |
3106 | *reg &= ~regmask; |
3107 | ||
3108 | hdspm_write(hdspm, target_reg, *reg); | |
bf0ff87b AK |
3109 | |
3110 | return 0; | |
3111 | } | |
3112 | ||
3113 | #define snd_hdspm_info_toggle_setting snd_ctl_boolean_mono_info | |
3114 | ||
3115 | static int snd_hdspm_get_toggle_setting(struct snd_kcontrol *kcontrol, | |
3116 | struct snd_ctl_elem_value *ucontrol) | |
3117 | { | |
3118 | struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); | |
3119 | u32 regmask = kcontrol->private_value; | |
3120 | ||
3121 | spin_lock_irq(&hdspm->lock); | |
3122 | ucontrol->value.integer.value[0] = hdspm_toggle_setting(hdspm, regmask); | |
3123 | spin_unlock_irq(&hdspm->lock); | |
3124 | return 0; | |
3125 | } | |
3126 | ||
3127 | static int snd_hdspm_put_toggle_setting(struct snd_kcontrol *kcontrol, | |
3128 | struct snd_ctl_elem_value *ucontrol) | |
3129 | { | |
3130 | struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); | |
3131 | u32 regmask = kcontrol->private_value; | |
3132 | int change; | |
3133 | unsigned int val; | |
3134 | ||
3135 | if (!snd_hdspm_use_is_exclusive(hdspm)) | |
3136 | return -EBUSY; | |
3137 | val = ucontrol->value.integer.value[0] & 1; | |
3138 | spin_lock_irq(&hdspm->lock); | |
3139 | change = (int) val != hdspm_toggle_setting(hdspm, regmask); | |
3140 | hdspm_set_toggle_setting(hdspm, regmask, val); | |
3141 | spin_unlock_irq(&hdspm->lock); | |
3142 | return change; | |
3143 | } | |
3144 | ||
3cee5a60 | 3145 | #define HDSPM_INPUT_SELECT(xname, xindex) \ |
f27a64f9 AK |
3146 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ |
3147 | .name = xname, \ | |
3148 | .index = xindex, \ | |
3149 | .info = snd_hdspm_info_input_select, \ | |
3150 | .get = snd_hdspm_get_input_select, \ | |
3151 | .put = snd_hdspm_put_input_select \ | |
3cee5a60 RB |
3152 | } |
3153 | ||
3154 | static int hdspm_input_select(struct hdspm * hdspm) | |
3155 | { | |
3156 | return (hdspm->control_register & HDSPM_InputSelect0) ? 1 : 0; | |
3157 | } | |
3158 | ||
3159 | static int hdspm_set_input_select(struct hdspm * hdspm, int out) | |
3160 | { | |
3161 | if (out) | |
3162 | hdspm->control_register |= HDSPM_InputSelect0; | |
3163 | else | |
3164 | hdspm->control_register &= ~HDSPM_InputSelect0; | |
3165 | hdspm_write(hdspm, HDSPM_controlRegister, hdspm->control_register); | |
3166 | ||
3167 | return 0; | |
3168 | } | |
3169 | ||
3170 | static int snd_hdspm_info_input_select(struct snd_kcontrol *kcontrol, | |
3171 | struct snd_ctl_elem_info *uinfo) | |
3172 | { | |
3173 | static char *texts[] = { "optical", "coaxial" }; | |
e5b7b1fe | 3174 | ENUMERATED_CTL_INFO(uinfo, texts); |
3cee5a60 RB |
3175 | return 0; |
3176 | } | |
3177 | ||
3178 | static int snd_hdspm_get_input_select(struct snd_kcontrol *kcontrol, | |
3179 | struct snd_ctl_elem_value *ucontrol) | |
3180 | { | |
3181 | struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); | |
3182 | ||
3183 | spin_lock_irq(&hdspm->lock); | |
3184 | ucontrol->value.enumerated.item[0] = hdspm_input_select(hdspm); | |
3185 | spin_unlock_irq(&hdspm->lock); | |
3186 | return 0; | |
3187 | } | |
3188 | ||
3189 | static int snd_hdspm_put_input_select(struct snd_kcontrol *kcontrol, | |
3190 | struct snd_ctl_elem_value *ucontrol) | |
3191 | { | |
3192 | struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); | |
3193 | int change; | |
3194 | unsigned int val; | |
3195 | ||
3196 | if (!snd_hdspm_use_is_exclusive(hdspm)) | |
3197 | return -EBUSY; | |
3198 | val = ucontrol->value.integer.value[0] & 1; | |
3199 | spin_lock_irq(&hdspm->lock); | |
3200 | change = (int) val != hdspm_input_select(hdspm); | |
3201 | hdspm_set_input_select(hdspm, val); | |
3202 | spin_unlock_irq(&hdspm->lock); | |
3203 | return change; | |
3204 | } | |
3205 | ||
0dca1793 | 3206 | |
3cee5a60 | 3207 | #define HDSPM_DS_WIRE(xname, xindex) \ |
f27a64f9 AK |
3208 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ |
3209 | .name = xname, \ | |
3210 | .index = xindex, \ | |
3211 | .info = snd_hdspm_info_ds_wire, \ | |
3212 | .get = snd_hdspm_get_ds_wire, \ | |
3213 | .put = snd_hdspm_put_ds_wire \ | |
3cee5a60 RB |
3214 | } |
3215 | ||
3216 | static int hdspm_ds_wire(struct hdspm * hdspm) | |
763f356c | 3217 | { |
3cee5a60 | 3218 | return (hdspm->control_register & HDSPM_DS_DoubleWire) ? 1 : 0; |
763f356c TI |
3219 | } |
3220 | ||
3cee5a60 | 3221 | static int hdspm_set_ds_wire(struct hdspm * hdspm, int ds) |
763f356c | 3222 | { |
3cee5a60 RB |
3223 | if (ds) |
3224 | hdspm->control_register |= HDSPM_DS_DoubleWire; | |
763f356c | 3225 | else |
3cee5a60 | 3226 | hdspm->control_register &= ~HDSPM_DS_DoubleWire; |
763f356c TI |
3227 | hdspm_write(hdspm, HDSPM_controlRegister, hdspm->control_register); |
3228 | ||
3229 | return 0; | |
3230 | } | |
3231 | ||
3cee5a60 RB |
3232 | static int snd_hdspm_info_ds_wire(struct snd_kcontrol *kcontrol, |
3233 | struct snd_ctl_elem_info *uinfo) | |
763f356c | 3234 | { |
3cee5a60 | 3235 | static char *texts[] = { "Single", "Double" }; |
e5b7b1fe | 3236 | ENUMERATED_CTL_INFO(uinfo, texts); |
763f356c TI |
3237 | return 0; |
3238 | } | |
3239 | ||
3cee5a60 RB |
3240 | static int snd_hdspm_get_ds_wire(struct snd_kcontrol *kcontrol, |
3241 | struct snd_ctl_elem_value *ucontrol) | |
763f356c | 3242 | { |
98274f07 | 3243 | struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); |
763f356c TI |
3244 | |
3245 | spin_lock_irq(&hdspm->lock); | |
3cee5a60 | 3246 | ucontrol->value.enumerated.item[0] = hdspm_ds_wire(hdspm); |
763f356c TI |
3247 | spin_unlock_irq(&hdspm->lock); |
3248 | return 0; | |
3249 | } | |
3250 | ||
3cee5a60 RB |
3251 | static int snd_hdspm_put_ds_wire(struct snd_kcontrol *kcontrol, |
3252 | struct snd_ctl_elem_value *ucontrol) | |
763f356c | 3253 | { |
98274f07 | 3254 | struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); |
763f356c TI |
3255 | int change; |
3256 | unsigned int val; | |
3257 | ||
3258 | if (!snd_hdspm_use_is_exclusive(hdspm)) | |
3259 | return -EBUSY; | |
3260 | val = ucontrol->value.integer.value[0] & 1; | |
3261 | spin_lock_irq(&hdspm->lock); | |
3cee5a60 RB |
3262 | change = (int) val != hdspm_ds_wire(hdspm); |
3263 | hdspm_set_ds_wire(hdspm, val); | |
763f356c TI |
3264 | spin_unlock_irq(&hdspm->lock); |
3265 | return change; | |
3266 | } | |
3267 | ||
0dca1793 | 3268 | |
3cee5a60 | 3269 | #define HDSPM_QS_WIRE(xname, xindex) \ |
f27a64f9 AK |
3270 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ |
3271 | .name = xname, \ | |
3272 | .index = xindex, \ | |
3273 | .info = snd_hdspm_info_qs_wire, \ | |
3274 | .get = snd_hdspm_get_qs_wire, \ | |
3275 | .put = snd_hdspm_put_qs_wire \ | |
763f356c TI |
3276 | } |
3277 | ||
3cee5a60 | 3278 | static int hdspm_qs_wire(struct hdspm * hdspm) |
763f356c | 3279 | { |
3cee5a60 RB |
3280 | if (hdspm->control_register & HDSPM_QS_DoubleWire) |
3281 | return 1; | |
3282 | if (hdspm->control_register & HDSPM_QS_QuadWire) | |
3283 | return 2; | |
3284 | return 0; | |
763f356c TI |
3285 | } |
3286 | ||
3cee5a60 | 3287 | static int hdspm_set_qs_wire(struct hdspm * hdspm, int mode) |
763f356c | 3288 | { |
3cee5a60 RB |
3289 | hdspm->control_register &= ~(HDSPM_QS_DoubleWire | HDSPM_QS_QuadWire); |
3290 | switch (mode) { | |
3291 | case 0: | |
3292 | break; | |
3293 | case 1: | |
3294 | hdspm->control_register |= HDSPM_QS_DoubleWire; | |
3295 | break; | |
3296 | case 2: | |
3297 | hdspm->control_register |= HDSPM_QS_QuadWire; | |
3298 | break; | |
3299 | } | |
763f356c TI |
3300 | hdspm_write(hdspm, HDSPM_controlRegister, hdspm->control_register); |
3301 | ||
3302 | return 0; | |
3303 | } | |
3304 | ||
3cee5a60 | 3305 | static int snd_hdspm_info_qs_wire(struct snd_kcontrol *kcontrol, |
98274f07 | 3306 | struct snd_ctl_elem_info *uinfo) |
763f356c | 3307 | { |
3cee5a60 | 3308 | static char *texts[] = { "Single", "Double", "Quad" }; |
e5b7b1fe | 3309 | ENUMERATED_CTL_INFO(uinfo, texts); |
763f356c TI |
3310 | return 0; |
3311 | } | |
3312 | ||
3cee5a60 | 3313 | static int snd_hdspm_get_qs_wire(struct snd_kcontrol *kcontrol, |
98274f07 | 3314 | struct snd_ctl_elem_value *ucontrol) |
763f356c | 3315 | { |
98274f07 | 3316 | struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); |
763f356c TI |
3317 | |
3318 | spin_lock_irq(&hdspm->lock); | |
3cee5a60 | 3319 | ucontrol->value.enumerated.item[0] = hdspm_qs_wire(hdspm); |
763f356c TI |
3320 | spin_unlock_irq(&hdspm->lock); |
3321 | return 0; | |
3322 | } | |
3323 | ||
3cee5a60 | 3324 | static int snd_hdspm_put_qs_wire(struct snd_kcontrol *kcontrol, |
98274f07 | 3325 | struct snd_ctl_elem_value *ucontrol) |
763f356c | 3326 | { |
98274f07 | 3327 | struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); |
763f356c | 3328 | int change; |
3cee5a60 | 3329 | int val; |
763f356c TI |
3330 | |
3331 | if (!snd_hdspm_use_is_exclusive(hdspm)) | |
3332 | return -EBUSY; | |
3cee5a60 RB |
3333 | val = ucontrol->value.integer.value[0]; |
3334 | if (val < 0) | |
3335 | val = 0; | |
3336 | if (val > 2) | |
3337 | val = 2; | |
763f356c | 3338 | spin_lock_irq(&hdspm->lock); |
ef5fa1a4 | 3339 | change = val != hdspm_qs_wire(hdspm); |
3cee5a60 | 3340 | hdspm_set_qs_wire(hdspm, val); |
763f356c TI |
3341 | spin_unlock_irq(&hdspm->lock); |
3342 | return change; | |
3343 | } | |
3344 | ||
700d1ef3 AK |
3345 | #define HDSPM_MADI_SPEEDMODE(xname, xindex) \ |
3346 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ | |
3347 | .name = xname, \ | |
3348 | .index = xindex, \ | |
3349 | .info = snd_hdspm_info_madi_speedmode, \ | |
3350 | .get = snd_hdspm_get_madi_speedmode, \ | |
3351 | .put = snd_hdspm_put_madi_speedmode \ | |
3352 | } | |
3353 | ||
3354 | static int hdspm_madi_speedmode(struct hdspm *hdspm) | |
3355 | { | |
3356 | if (hdspm->control_register & HDSPM_QuadSpeed) | |
3357 | return 2; | |
3358 | if (hdspm->control_register & HDSPM_DoubleSpeed) | |
3359 | return 1; | |
3360 | return 0; | |
3361 | } | |
3362 | ||
3363 | static int hdspm_set_madi_speedmode(struct hdspm *hdspm, int mode) | |
3364 | { | |
3365 | hdspm->control_register &= ~(HDSPM_DoubleSpeed | HDSPM_QuadSpeed); | |
3366 | switch (mode) { | |
3367 | case 0: | |
3368 | break; | |
3369 | case 1: | |
3370 | hdspm->control_register |= HDSPM_DoubleSpeed; | |
3371 | break; | |
3372 | case 2: | |
3373 | hdspm->control_register |= HDSPM_QuadSpeed; | |
3374 | break; | |
3375 | } | |
3376 | hdspm_write(hdspm, HDSPM_controlRegister, hdspm->control_register); | |
3377 | ||
3378 | return 0; | |
3379 | } | |
3380 | ||
3381 | static int snd_hdspm_info_madi_speedmode(struct snd_kcontrol *kcontrol, | |
3382 | struct snd_ctl_elem_info *uinfo) | |
3383 | { | |
3384 | static char *texts[] = { "Single", "Double", "Quad" }; | |
e5b7b1fe | 3385 | ENUMERATED_CTL_INFO(uinfo, texts); |
700d1ef3 AK |
3386 | return 0; |
3387 | } | |
3388 | ||
3389 | static int snd_hdspm_get_madi_speedmode(struct snd_kcontrol *kcontrol, | |
3390 | struct snd_ctl_elem_value *ucontrol) | |
3391 | { | |
3392 | struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); | |
3393 | ||
3394 | spin_lock_irq(&hdspm->lock); | |
3395 | ucontrol->value.enumerated.item[0] = hdspm_madi_speedmode(hdspm); | |
3396 | spin_unlock_irq(&hdspm->lock); | |
3397 | return 0; | |
3398 | } | |
3399 | ||
3400 | static int snd_hdspm_put_madi_speedmode(struct snd_kcontrol *kcontrol, | |
3401 | struct snd_ctl_elem_value *ucontrol) | |
3402 | { | |
3403 | struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); | |
3404 | int change; | |
3405 | int val; | |
3406 | ||
3407 | if (!snd_hdspm_use_is_exclusive(hdspm)) | |
3408 | return -EBUSY; | |
3409 | val = ucontrol->value.integer.value[0]; | |
3410 | if (val < 0) | |
3411 | val = 0; | |
3412 | if (val > 2) | |
3413 | val = 2; | |
3414 | spin_lock_irq(&hdspm->lock); | |
3415 | change = val != hdspm_madi_speedmode(hdspm); | |
3416 | hdspm_set_madi_speedmode(hdspm, val); | |
3417 | spin_unlock_irq(&hdspm->lock); | |
3418 | return change; | |
3419 | } | |
763f356c TI |
3420 | |
3421 | #define HDSPM_MIXER(xname, xindex) \ | |
f27a64f9 AK |
3422 | { .iface = SNDRV_CTL_ELEM_IFACE_HWDEP, \ |
3423 | .name = xname, \ | |
3424 | .index = xindex, \ | |
3425 | .device = 0, \ | |
3426 | .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | \ | |
3427 | SNDRV_CTL_ELEM_ACCESS_VOLATILE, \ | |
3428 | .info = snd_hdspm_info_mixer, \ | |
3429 | .get = snd_hdspm_get_mixer, \ | |
3430 | .put = snd_hdspm_put_mixer \ | |
763f356c TI |
3431 | } |
3432 | ||
98274f07 TI |
3433 | static int snd_hdspm_info_mixer(struct snd_kcontrol *kcontrol, |
3434 | struct snd_ctl_elem_info *uinfo) | |
763f356c TI |
3435 | { |
3436 | uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; | |
3437 | uinfo->count = 3; | |
3438 | uinfo->value.integer.min = 0; | |
3439 | uinfo->value.integer.max = 65535; | |
3440 | uinfo->value.integer.step = 1; | |
3441 | return 0; | |
3442 | } | |
3443 | ||
98274f07 TI |
3444 | static int snd_hdspm_get_mixer(struct snd_kcontrol *kcontrol, |
3445 | struct snd_ctl_elem_value *ucontrol) | |
763f356c | 3446 | { |
98274f07 | 3447 | struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); |
763f356c TI |
3448 | int source; |
3449 | int destination; | |
3450 | ||
3451 | source = ucontrol->value.integer.value[0]; | |
3452 | if (source < 0) | |
3453 | source = 0; | |
3454 | else if (source >= 2 * HDSPM_MAX_CHANNELS) | |
3455 | source = 2 * HDSPM_MAX_CHANNELS - 1; | |
3456 | ||
3457 | destination = ucontrol->value.integer.value[1]; | |
3458 | if (destination < 0) | |
3459 | destination = 0; | |
3460 | else if (destination >= HDSPM_MAX_CHANNELS) | |
3461 | destination = HDSPM_MAX_CHANNELS - 1; | |
3462 | ||
3463 | spin_lock_irq(&hdspm->lock); | |
3464 | if (source >= HDSPM_MAX_CHANNELS) | |
3465 | ucontrol->value.integer.value[2] = | |
3466 | hdspm_read_pb_gain(hdspm, destination, | |
3467 | source - HDSPM_MAX_CHANNELS); | |
3468 | else | |
3469 | ucontrol->value.integer.value[2] = | |
3470 | hdspm_read_in_gain(hdspm, destination, source); | |
3471 | ||
3472 | spin_unlock_irq(&hdspm->lock); | |
3473 | ||
3474 | return 0; | |
3475 | } | |
3476 | ||
98274f07 TI |
3477 | static int snd_hdspm_put_mixer(struct snd_kcontrol *kcontrol, |
3478 | struct snd_ctl_elem_value *ucontrol) | |
763f356c | 3479 | { |
98274f07 | 3480 | struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); |
763f356c TI |
3481 | int change; |
3482 | int source; | |
3483 | int destination; | |
3484 | int gain; | |
3485 | ||
3486 | if (!snd_hdspm_use_is_exclusive(hdspm)) | |
3487 | return -EBUSY; | |
3488 | ||
3489 | source = ucontrol->value.integer.value[0]; | |
3490 | destination = ucontrol->value.integer.value[1]; | |
3491 | ||
3492 | if (source < 0 || source >= 2 * HDSPM_MAX_CHANNELS) | |
3493 | return -1; | |
3494 | if (destination < 0 || destination >= HDSPM_MAX_CHANNELS) | |
3495 | return -1; | |
3496 | ||
3497 | gain = ucontrol->value.integer.value[2]; | |
3498 | ||
3499 | spin_lock_irq(&hdspm->lock); | |
3500 | ||
3501 | if (source >= HDSPM_MAX_CHANNELS) | |
3502 | change = gain != hdspm_read_pb_gain(hdspm, destination, | |
3503 | source - | |
3504 | HDSPM_MAX_CHANNELS); | |
3505 | else | |
ef5fa1a4 TI |
3506 | change = gain != hdspm_read_in_gain(hdspm, destination, |
3507 | source); | |
763f356c TI |
3508 | |
3509 | if (change) { | |
3510 | if (source >= HDSPM_MAX_CHANNELS) | |
3511 | hdspm_write_pb_gain(hdspm, destination, | |
3512 | source - HDSPM_MAX_CHANNELS, | |
3513 | gain); | |
3514 | else | |
3515 | hdspm_write_in_gain(hdspm, destination, source, | |
3516 | gain); | |
3517 | } | |
3518 | spin_unlock_irq(&hdspm->lock); | |
3519 | ||
3520 | return change; | |
3521 | } | |
3522 | ||
3523 | /* The simple mixer control(s) provide gain control for the | |
3524 | basic 1:1 mappings of playback streams to output | |
0dca1793 | 3525 | streams. |
763f356c TI |
3526 | */ |
3527 | ||
3528 | #define HDSPM_PLAYBACK_MIXER \ | |
f27a64f9 AK |
3529 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ |
3530 | .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_WRITE | \ | |
3531 | SNDRV_CTL_ELEM_ACCESS_VOLATILE, \ | |
3532 | .info = snd_hdspm_info_playback_mixer, \ | |
3533 | .get = snd_hdspm_get_playback_mixer, \ | |
3534 | .put = snd_hdspm_put_playback_mixer \ | |
763f356c TI |
3535 | } |
3536 | ||
98274f07 TI |
3537 | static int snd_hdspm_info_playback_mixer(struct snd_kcontrol *kcontrol, |
3538 | struct snd_ctl_elem_info *uinfo) | |
763f356c TI |
3539 | { |
3540 | uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; | |
3541 | uinfo->count = 1; | |
3542 | uinfo->value.integer.min = 0; | |
0dca1793 | 3543 | uinfo->value.integer.max = 64; |
763f356c TI |
3544 | uinfo->value.integer.step = 1; |
3545 | return 0; | |
3546 | } | |
3547 | ||
98274f07 TI |
3548 | static int snd_hdspm_get_playback_mixer(struct snd_kcontrol *kcontrol, |
3549 | struct snd_ctl_elem_value *ucontrol) | |
763f356c | 3550 | { |
98274f07 | 3551 | struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); |
763f356c | 3552 | int channel; |
763f356c TI |
3553 | |
3554 | channel = ucontrol->id.index - 1; | |
3555 | ||
da3cec35 TI |
3556 | if (snd_BUG_ON(channel < 0 || channel >= HDSPM_MAX_CHANNELS)) |
3557 | return -EINVAL; | |
763f356c | 3558 | |
763f356c TI |
3559 | spin_lock_irq(&hdspm->lock); |
3560 | ucontrol->value.integer.value[0] = | |
0dca1793 | 3561 | (hdspm_read_pb_gain(hdspm, channel, channel)*64)/UNITY_GAIN; |
763f356c TI |
3562 | spin_unlock_irq(&hdspm->lock); |
3563 | ||
763f356c TI |
3564 | return 0; |
3565 | } | |
3566 | ||
98274f07 TI |
3567 | static int snd_hdspm_put_playback_mixer(struct snd_kcontrol *kcontrol, |
3568 | struct snd_ctl_elem_value *ucontrol) | |
763f356c | 3569 | { |
98274f07 | 3570 | struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); |
763f356c TI |
3571 | int change; |
3572 | int channel; | |
763f356c TI |
3573 | int gain; |
3574 | ||
3575 | if (!snd_hdspm_use_is_exclusive(hdspm)) | |
3576 | return -EBUSY; | |
3577 | ||
3578 | channel = ucontrol->id.index - 1; | |
3579 | ||
da3cec35 TI |
3580 | if (snd_BUG_ON(channel < 0 || channel >= HDSPM_MAX_CHANNELS)) |
3581 | return -EINVAL; | |
763f356c | 3582 | |
0dca1793 | 3583 | gain = ucontrol->value.integer.value[0]*UNITY_GAIN/64; |
763f356c TI |
3584 | |
3585 | spin_lock_irq(&hdspm->lock); | |
3586 | change = | |
0dca1793 AK |
3587 | gain != hdspm_read_pb_gain(hdspm, channel, |
3588 | channel); | |
763f356c | 3589 | if (change) |
0dca1793 | 3590 | hdspm_write_pb_gain(hdspm, channel, channel, |
763f356c TI |
3591 | gain); |
3592 | spin_unlock_irq(&hdspm->lock); | |
3593 | return change; | |
3594 | } | |
3595 | ||
0dca1793 AK |
3596 | #define HDSPM_SYNC_CHECK(xname, xindex) \ |
3597 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ | |
3598 | .name = xname, \ | |
3599 | .private_value = xindex, \ | |
3600 | .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, \ | |
3601 | .info = snd_hdspm_info_sync_check, \ | |
3602 | .get = snd_hdspm_get_sync_check \ | |
763f356c TI |
3603 | } |
3604 | ||
34542213 AK |
3605 | #define HDSPM_TCO_LOCK_CHECK(xname, xindex) \ |
3606 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ | |
3607 | .name = xname, \ | |
3608 | .private_value = xindex, \ | |
3609 | .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, \ | |
3610 | .info = snd_hdspm_tco_info_lock_check, \ | |
3611 | .get = snd_hdspm_get_sync_check \ | |
3612 | } | |
3613 | ||
3614 | ||
0dca1793 | 3615 | |
98274f07 TI |
3616 | static int snd_hdspm_info_sync_check(struct snd_kcontrol *kcontrol, |
3617 | struct snd_ctl_elem_info *uinfo) | |
763f356c | 3618 | { |
0dca1793 | 3619 | static char *texts[] = { "No Lock", "Lock", "Sync", "N/A" }; |
e5b7b1fe | 3620 | ENUMERATED_CTL_INFO(uinfo, texts); |
763f356c TI |
3621 | return 0; |
3622 | } | |
3623 | ||
34542213 AK |
3624 | static int snd_hdspm_tco_info_lock_check(struct snd_kcontrol *kcontrol, |
3625 | struct snd_ctl_elem_info *uinfo) | |
3626 | { | |
3627 | static char *texts[] = { "No Lock", "Lock" }; | |
3628 | ENUMERATED_CTL_INFO(uinfo, texts); | |
3629 | return 0; | |
3630 | } | |
3631 | ||
0dca1793 | 3632 | static int hdspm_wc_sync_check(struct hdspm *hdspm) |
763f356c | 3633 | { |
0dca1793 AK |
3634 | int status, status2; |
3635 | ||
3636 | switch (hdspm->io_type) { | |
3637 | case AES32: | |
3638 | status = hdspm_read(hdspm, HDSPM_statusRegister); | |
56bde0f3 AS |
3639 | if (status & HDSPM_AES32_wcLock) { |
3640 | if (status & HDSPM_AES32_wcSync) | |
3641 | return 2; | |
3642 | else | |
3643 | return 1; | |
3644 | } | |
3cee5a60 | 3645 | return 0; |
0dca1793 AK |
3646 | break; |
3647 | ||
3648 | case MADI: | |
3649 | status2 = hdspm_read(hdspm, HDSPM_statusRegister2); | |
3cee5a60 RB |
3650 | if (status2 & HDSPM_wcLock) { |
3651 | if (status2 & HDSPM_wcSync) | |
3652 | return 2; | |
3653 | else | |
3654 | return 1; | |
3655 | } | |
3656 | return 0; | |
0dca1793 | 3657 | break; |
763f356c | 3658 | |
0dca1793 AK |
3659 | case RayDAT: |
3660 | case AIO: | |
3661 | status = hdspm_read(hdspm, HDSPM_statusRegister); | |
763f356c | 3662 | |
0dca1793 AK |
3663 | if (status & 0x2000000) |
3664 | return 2; | |
3665 | else if (status & 0x1000000) | |
3666 | return 1; | |
3667 | return 0; | |
763f356c | 3668 | |
0dca1793 | 3669 | break; |
763f356c | 3670 | |
0dca1793 AK |
3671 | case MADIface: |
3672 | break; | |
3673 | } | |
3674 | ||
3675 | ||
3676 | return 3; | |
763f356c TI |
3677 | } |
3678 | ||
0dca1793 AK |
3679 | |
3680 | static int hdspm_madi_sync_check(struct hdspm *hdspm) | |
763f356c TI |
3681 | { |
3682 | int status = hdspm_read(hdspm, HDSPM_statusRegister); | |
3683 | if (status & HDSPM_madiLock) { | |
3684 | if (status & HDSPM_madiSync) | |
3685 | return 2; | |
3686 | else | |
3687 | return 1; | |
3688 | } | |
3689 | return 0; | |
3690 | } | |
3691 | ||
763f356c | 3692 | |
0dca1793 AK |
3693 | static int hdspm_s1_sync_check(struct hdspm *hdspm, int idx) |
3694 | { | |
3695 | int status, lock, sync; | |
763f356c | 3696 | |
0dca1793 | 3697 | status = hdspm_read(hdspm, HDSPM_RD_STATUS_1); |
763f356c | 3698 | |
0dca1793 AK |
3699 | lock = (status & (0x1<<idx)) ? 1 : 0; |
3700 | sync = (status & (0x100<<idx)) ? 1 : 0; | |
3cee5a60 | 3701 | |
0dca1793 | 3702 | if (lock && sync) |
3cee5a60 | 3703 | return 2; |
0dca1793 AK |
3704 | else if (lock) |
3705 | return 1; | |
3cee5a60 RB |
3706 | return 0; |
3707 | } | |
3708 | ||
0dca1793 AK |
3709 | |
3710 | static int hdspm_sync_in_sync_check(struct hdspm *hdspm) | |
3711 | { | |
3712 | int status, lock = 0, sync = 0; | |
3713 | ||
3714 | switch (hdspm->io_type) { | |
3715 | case RayDAT: | |
3716 | case AIO: | |
3717 | status = hdspm_read(hdspm, HDSPM_RD_STATUS_3); | |
3718 | lock = (status & 0x400) ? 1 : 0; | |
3719 | sync = (status & 0x800) ? 1 : 0; | |
3720 | break; | |
3721 | ||
3722 | case MADI: | |
2e0452f5 AK |
3723 | status = hdspm_read(hdspm, HDSPM_statusRegister); |
3724 | lock = (status & HDSPM_syncInLock) ? 1 : 0; | |
3725 | sync = (status & HDSPM_syncInSync) ? 1 : 0; | |
3726 | break; | |
3727 | ||
0dca1793 AK |
3728 | case AES32: |
3729 | status = hdspm_read(hdspm, HDSPM_statusRegister2); | |
9a215f47 AK |
3730 | lock = (status & 0x100000) ? 1 : 0; |
3731 | sync = (status & 0x200000) ? 1 : 0; | |
0dca1793 AK |
3732 | break; |
3733 | ||
3734 | case MADIface: | |
3735 | break; | |
3736 | } | |
3737 | ||
3738 | if (lock && sync) | |
3739 | return 2; | |
3740 | else if (lock) | |
3741 | return 1; | |
3742 | ||
3743 | return 0; | |
3744 | } | |
3745 | ||
3746 | static int hdspm_aes_sync_check(struct hdspm *hdspm, int idx) | |
3747 | { | |
3748 | int status2, lock, sync; | |
3749 | status2 = hdspm_read(hdspm, HDSPM_statusRegister2); | |
3750 | ||
3751 | lock = (status2 & (0x0080 >> idx)) ? 1 : 0; | |
3752 | sync = (status2 & (0x8000 >> idx)) ? 1 : 0; | |
3753 | ||
3754 | if (sync) | |
3755 | return 2; | |
3756 | else if (lock) | |
3757 | return 1; | |
3758 | return 0; | |
3759 | } | |
3760 | ||
34542213 AK |
3761 | static int hdspm_tco_input_check(struct hdspm *hdspm, u32 mask) |
3762 | { | |
3763 | u32 status; | |
3764 | status = hdspm_read(hdspm, HDSPM_RD_TCO + 4); | |
3765 | ||
3766 | return (status & mask) ? 1 : 0; | |
3767 | } | |
3768 | ||
0dca1793 AK |
3769 | |
3770 | static int hdspm_tco_sync_check(struct hdspm *hdspm) | |
3771 | { | |
3772 | int status; | |
3773 | ||
3774 | if (hdspm->tco) { | |
3775 | switch (hdspm->io_type) { | |
3776 | case MADI: | |
3777 | case AES32: | |
3778 | status = hdspm_read(hdspm, HDSPM_statusRegister); | |
3779 | if (status & HDSPM_tcoLock) { | |
3780 | if (status & HDSPM_tcoSync) | |
3781 | return 2; | |
3782 | else | |
3783 | return 1; | |
3784 | } | |
3785 | return 0; | |
3786 | ||
3787 | break; | |
3788 | ||
3789 | case RayDAT: | |
3790 | case AIO: | |
3791 | status = hdspm_read(hdspm, HDSPM_RD_STATUS_1); | |
3792 | ||
3793 | if (status & 0x8000000) | |
3794 | return 2; /* Sync */ | |
3795 | if (status & 0x4000000) | |
3796 | return 1; /* Lock */ | |
3797 | return 0; /* No signal */ | |
3798 | break; | |
3799 | ||
3800 | default: | |
3801 | break; | |
3802 | } | |
3803 | } | |
3804 | ||
3805 | return 3; /* N/A */ | |
3806 | } | |
3807 | ||
3808 | ||
3809 | static int snd_hdspm_get_sync_check(struct snd_kcontrol *kcontrol, | |
3810 | struct snd_ctl_elem_value *ucontrol) | |
3811 | { | |
3812 | struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); | |
3813 | int val = -1; | |
3814 | ||
3815 | switch (hdspm->io_type) { | |
3816 | case RayDAT: | |
3817 | switch (kcontrol->private_value) { | |
3818 | case 0: /* WC */ | |
3819 | val = hdspm_wc_sync_check(hdspm); break; | |
3820 | case 7: /* TCO */ | |
3821 | val = hdspm_tco_sync_check(hdspm); break; | |
3822 | case 8: /* SYNC IN */ | |
3823 | val = hdspm_sync_in_sync_check(hdspm); break; | |
3824 | default: | |
d1a3c98d AK |
3825 | val = hdspm_s1_sync_check(hdspm, |
3826 | kcontrol->private_value-1); | |
0dca1793 | 3827 | } |
fba30fd3 | 3828 | break; |
0dca1793 AK |
3829 | |
3830 | case AIO: | |
3831 | switch (kcontrol->private_value) { | |
3832 | case 0: /* WC */ | |
3833 | val = hdspm_wc_sync_check(hdspm); break; | |
3834 | case 4: /* TCO */ | |
3835 | val = hdspm_tco_sync_check(hdspm); break; | |
3836 | case 5: /* SYNC IN */ | |
3837 | val = hdspm_sync_in_sync_check(hdspm); break; | |
3838 | default: | |
3839 | val = hdspm_s1_sync_check(hdspm, ucontrol->id.index-1); | |
3840 | } | |
fba30fd3 | 3841 | break; |
0dca1793 AK |
3842 | |
3843 | case MADI: | |
3844 | switch (kcontrol->private_value) { | |
3845 | case 0: /* WC */ | |
3846 | val = hdspm_wc_sync_check(hdspm); break; | |
3847 | case 1: /* MADI */ | |
3848 | val = hdspm_madi_sync_check(hdspm); break; | |
3849 | case 2: /* TCO */ | |
3850 | val = hdspm_tco_sync_check(hdspm); break; | |
3851 | case 3: /* SYNC_IN */ | |
3852 | val = hdspm_sync_in_sync_check(hdspm); break; | |
3853 | } | |
fba30fd3 | 3854 | break; |
0dca1793 AK |
3855 | |
3856 | case MADIface: | |
3857 | val = hdspm_madi_sync_check(hdspm); /* MADI */ | |
3858 | break; | |
3859 | ||
3860 | case AES32: | |
3861 | switch (kcontrol->private_value) { | |
3862 | case 0: /* WC */ | |
3863 | val = hdspm_wc_sync_check(hdspm); break; | |
3864 | case 9: /* TCO */ | |
3865 | val = hdspm_tco_sync_check(hdspm); break; | |
3866 | case 10 /* SYNC IN */: | |
3867 | val = hdspm_sync_in_sync_check(hdspm); break; | |
7c4a95b5 | 3868 | default: /* AES1 to AES8 */ |
0dca1793 | 3869 | val = hdspm_aes_sync_check(hdspm, |
7c4a95b5 | 3870 | kcontrol->private_value-1); |
0dca1793 | 3871 | } |
fba30fd3 | 3872 | break; |
0dca1793 AK |
3873 | |
3874 | } | |
3875 | ||
34542213 AK |
3876 | if (hdspm->tco) { |
3877 | switch (kcontrol->private_value) { | |
3878 | case 11: | |
3879 | /* Check TCO for lock state of its current input */ | |
3880 | val = hdspm_tco_input_check(hdspm, HDSPM_TCO1_TCO_lock); | |
3881 | break; | |
3882 | case 12: | |
3883 | /* Check TCO for valid time code on LTC input. */ | |
3884 | val = hdspm_tco_input_check(hdspm, | |
3885 | HDSPM_TCO1_LTC_Input_valid); | |
3886 | break; | |
3887 | default: | |
3888 | break; | |
3889 | } | |
3890 | } | |
3891 | ||
0dca1793 AK |
3892 | if (-1 == val) |
3893 | val = 3; | |
3894 | ||
3895 | ucontrol->value.enumerated.item[0] = val; | |
3896 | return 0; | |
3897 | } | |
3898 | ||
3899 | ||
3900 | ||
3901 | /** | |
3902 | * TCO controls | |
3903 | **/ | |
3904 | static void hdspm_tco_write(struct hdspm *hdspm) | |
3905 | { | |
3906 | unsigned int tc[4] = { 0, 0, 0, 0}; | |
3907 | ||
3908 | switch (hdspm->tco->input) { | |
3909 | case 0: | |
3910 | tc[2] |= HDSPM_TCO2_set_input_MSB; | |
3911 | break; | |
3912 | case 1: | |
3913 | tc[2] |= HDSPM_TCO2_set_input_LSB; | |
3914 | break; | |
3915 | default: | |
3916 | break; | |
3917 | } | |
3918 | ||
3919 | switch (hdspm->tco->framerate) { | |
3920 | case 1: | |
3921 | tc[1] |= HDSPM_TCO1_LTC_Format_LSB; | |
3922 | break; | |
3923 | case 2: | |
3924 | tc[1] |= HDSPM_TCO1_LTC_Format_MSB; | |
3925 | break; | |
3926 | case 3: | |
3927 | tc[1] |= HDSPM_TCO1_LTC_Format_MSB + | |
3928 | HDSPM_TCO1_set_drop_frame_flag; | |
3929 | break; | |
3930 | case 4: | |
3931 | tc[1] |= HDSPM_TCO1_LTC_Format_LSB + | |
3932 | HDSPM_TCO1_LTC_Format_MSB; | |
3933 | break; | |
3934 | case 5: | |
3935 | tc[1] |= HDSPM_TCO1_LTC_Format_LSB + | |
3936 | HDSPM_TCO1_LTC_Format_MSB + | |
3937 | HDSPM_TCO1_set_drop_frame_flag; | |
3938 | break; | |
3939 | default: | |
3940 | break; | |
3941 | } | |
3942 | ||
3943 | switch (hdspm->tco->wordclock) { | |
3944 | case 1: | |
3945 | tc[2] |= HDSPM_TCO2_WCK_IO_ratio_LSB; | |
3946 | break; | |
3947 | case 2: | |
3948 | tc[2] |= HDSPM_TCO2_WCK_IO_ratio_MSB; | |
3949 | break; | |
3950 | default: | |
3951 | break; | |
3952 | } | |
3953 | ||
3954 | switch (hdspm->tco->samplerate) { | |
3955 | case 1: | |
3956 | tc[2] |= HDSPM_TCO2_set_freq; | |
3957 | break; | |
3958 | case 2: | |
3959 | tc[2] |= HDSPM_TCO2_set_freq_from_app; | |
3960 | break; | |
3961 | default: | |
3962 | break; | |
3963 | } | |
3964 | ||
3965 | switch (hdspm->tco->pull) { | |
3966 | case 1: | |
3967 | tc[2] |= HDSPM_TCO2_set_pull_up; | |
3968 | break; | |
3969 | case 2: | |
3970 | tc[2] |= HDSPM_TCO2_set_pull_down; | |
3971 | break; | |
3972 | case 3: | |
3973 | tc[2] |= HDSPM_TCO2_set_pull_up + HDSPM_TCO2_set_01_4; | |
3974 | break; | |
3975 | case 4: | |
3976 | tc[2] |= HDSPM_TCO2_set_pull_down + HDSPM_TCO2_set_01_4; | |
3977 | break; | |
3978 | default: | |
3979 | break; | |
3980 | } | |
3981 | ||
3982 | if (1 == hdspm->tco->term) { | |
3983 | tc[2] |= HDSPM_TCO2_set_term_75R; | |
3984 | } | |
3985 | ||
3986 | hdspm_write(hdspm, HDSPM_WR_TCO, tc[0]); | |
3987 | hdspm_write(hdspm, HDSPM_WR_TCO+4, tc[1]); | |
3988 | hdspm_write(hdspm, HDSPM_WR_TCO+8, tc[2]); | |
3989 | hdspm_write(hdspm, HDSPM_WR_TCO+12, tc[3]); | |
3990 | } | |
3991 | ||
3992 | ||
3993 | #define HDSPM_TCO_SAMPLE_RATE(xname, xindex) \ | |
3994 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ | |
3995 | .name = xname, \ | |
3996 | .index = xindex, \ | |
3997 | .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |\ | |
3998 | SNDRV_CTL_ELEM_ACCESS_VOLATILE, \ | |
3999 | .info = snd_hdspm_info_tco_sample_rate, \ | |
4000 | .get = snd_hdspm_get_tco_sample_rate, \ | |
4001 | .put = snd_hdspm_put_tco_sample_rate \ | |
4002 | } | |
4003 | ||
4004 | static int snd_hdspm_info_tco_sample_rate(struct snd_kcontrol *kcontrol, | |
4005 | struct snd_ctl_elem_info *uinfo) | |
4006 | { | |
4007 | static char *texts[] = { "44.1 kHz", "48 kHz" }; | |
e5b7b1fe | 4008 | ENUMERATED_CTL_INFO(uinfo, texts); |
0dca1793 AK |
4009 | return 0; |
4010 | } | |
4011 | ||
4012 | static int snd_hdspm_get_tco_sample_rate(struct snd_kcontrol *kcontrol, | |
4013 | struct snd_ctl_elem_value *ucontrol) | |
4014 | { | |
4015 | struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); | |
4016 | ||
4017 | ucontrol->value.enumerated.item[0] = hdspm->tco->samplerate; | |
4018 | ||
4019 | return 0; | |
4020 | } | |
4021 | ||
4022 | static int snd_hdspm_put_tco_sample_rate(struct snd_kcontrol *kcontrol, | |
4023 | struct snd_ctl_elem_value *ucontrol) | |
4024 | { | |
4025 | struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); | |
4026 | ||
4027 | if (hdspm->tco->samplerate != ucontrol->value.enumerated.item[0]) { | |
4028 | hdspm->tco->samplerate = ucontrol->value.enumerated.item[0]; | |
4029 | ||
4030 | hdspm_tco_write(hdspm); | |
4031 | ||
4032 | return 1; | |
4033 | } | |
4034 | ||
4035 | return 0; | |
4036 | } | |
4037 | ||
4038 | ||
4039 | #define HDSPM_TCO_PULL(xname, xindex) \ | |
4040 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ | |
4041 | .name = xname, \ | |
4042 | .index = xindex, \ | |
4043 | .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |\ | |
4044 | SNDRV_CTL_ELEM_ACCESS_VOLATILE, \ | |
4045 | .info = snd_hdspm_info_tco_pull, \ | |
4046 | .get = snd_hdspm_get_tco_pull, \ | |
4047 | .put = snd_hdspm_put_tco_pull \ | |
4048 | } | |
4049 | ||
4050 | static int snd_hdspm_info_tco_pull(struct snd_kcontrol *kcontrol, | |
4051 | struct snd_ctl_elem_info *uinfo) | |
4052 | { | |
4053 | static char *texts[] = { "0", "+ 0.1 %", "- 0.1 %", "+ 4 %", "- 4 %" }; | |
e5b7b1fe | 4054 | ENUMERATED_CTL_INFO(uinfo, texts); |
0dca1793 AK |
4055 | return 0; |
4056 | } | |
4057 | ||
4058 | static int snd_hdspm_get_tco_pull(struct snd_kcontrol *kcontrol, | |
4059 | struct snd_ctl_elem_value *ucontrol) | |
4060 | { | |
4061 | struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); | |
4062 | ||
4063 | ucontrol->value.enumerated.item[0] = hdspm->tco->pull; | |
4064 | ||
4065 | return 0; | |
4066 | } | |
4067 | ||
4068 | static int snd_hdspm_put_tco_pull(struct snd_kcontrol *kcontrol, | |
4069 | struct snd_ctl_elem_value *ucontrol) | |
4070 | { | |
4071 | struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); | |
4072 | ||
4073 | if (hdspm->tco->pull != ucontrol->value.enumerated.item[0]) { | |
4074 | hdspm->tco->pull = ucontrol->value.enumerated.item[0]; | |
4075 | ||
4076 | hdspm_tco_write(hdspm); | |
4077 | ||
4078 | return 1; | |
4079 | } | |
4080 | ||
4081 | return 0; | |
4082 | } | |
4083 | ||
4084 | #define HDSPM_TCO_WCK_CONVERSION(xname, xindex) \ | |
4085 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ | |
4086 | .name = xname, \ | |
4087 | .index = xindex, \ | |
4088 | .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |\ | |
4089 | SNDRV_CTL_ELEM_ACCESS_VOLATILE, \ | |
4090 | .info = snd_hdspm_info_tco_wck_conversion, \ | |
4091 | .get = snd_hdspm_get_tco_wck_conversion, \ | |
4092 | .put = snd_hdspm_put_tco_wck_conversion \ | |
4093 | } | |
4094 | ||
4095 | static int snd_hdspm_info_tco_wck_conversion(struct snd_kcontrol *kcontrol, | |
4096 | struct snd_ctl_elem_info *uinfo) | |
4097 | { | |
4098 | static char *texts[] = { "1:1", "44.1 -> 48", "48 -> 44.1" }; | |
e5b7b1fe | 4099 | ENUMERATED_CTL_INFO(uinfo, texts); |
0dca1793 AK |
4100 | return 0; |
4101 | } | |
4102 | ||
4103 | static int snd_hdspm_get_tco_wck_conversion(struct snd_kcontrol *kcontrol, | |
4104 | struct snd_ctl_elem_value *ucontrol) | |
4105 | { | |
4106 | struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); | |
4107 | ||
4108 | ucontrol->value.enumerated.item[0] = hdspm->tco->wordclock; | |
4109 | ||
4110 | return 0; | |
4111 | } | |
4112 | ||
4113 | static int snd_hdspm_put_tco_wck_conversion(struct snd_kcontrol *kcontrol, | |
4114 | struct snd_ctl_elem_value *ucontrol) | |
4115 | { | |
4116 | struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); | |
4117 | ||
4118 | if (hdspm->tco->wordclock != ucontrol->value.enumerated.item[0]) { | |
4119 | hdspm->tco->wordclock = ucontrol->value.enumerated.item[0]; | |
4120 | ||
4121 | hdspm_tco_write(hdspm); | |
4122 | ||
4123 | return 1; | |
4124 | } | |
4125 | ||
4126 | return 0; | |
4127 | } | |
4128 | ||
4129 | ||
4130 | #define HDSPM_TCO_FRAME_RATE(xname, xindex) \ | |
4131 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ | |
4132 | .name = xname, \ | |
4133 | .index = xindex, \ | |
4134 | .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |\ | |
4135 | SNDRV_CTL_ELEM_ACCESS_VOLATILE, \ | |
4136 | .info = snd_hdspm_info_tco_frame_rate, \ | |
4137 | .get = snd_hdspm_get_tco_frame_rate, \ | |
4138 | .put = snd_hdspm_put_tco_frame_rate \ | |
4139 | } | |
4140 | ||
4141 | static int snd_hdspm_info_tco_frame_rate(struct snd_kcontrol *kcontrol, | |
4142 | struct snd_ctl_elem_info *uinfo) | |
4143 | { | |
4144 | static char *texts[] = { "24 fps", "25 fps", "29.97fps", | |
4145 | "29.97 dfps", "30 fps", "30 dfps" }; | |
e5b7b1fe | 4146 | ENUMERATED_CTL_INFO(uinfo, texts); |
0dca1793 AK |
4147 | return 0; |
4148 | } | |
4149 | ||
4150 | static int snd_hdspm_get_tco_frame_rate(struct snd_kcontrol *kcontrol, | |
3cee5a60 RB |
4151 | struct snd_ctl_elem_value *ucontrol) |
4152 | { | |
3cee5a60 RB |
4153 | struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); |
4154 | ||
0dca1793 | 4155 | ucontrol->value.enumerated.item[0] = hdspm->tco->framerate; |
3cee5a60 | 4156 | |
3cee5a60 RB |
4157 | return 0; |
4158 | } | |
763f356c | 4159 | |
0dca1793 AK |
4160 | static int snd_hdspm_put_tco_frame_rate(struct snd_kcontrol *kcontrol, |
4161 | struct snd_ctl_elem_value *ucontrol) | |
4162 | { | |
4163 | struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); | |
763f356c | 4164 | |
0dca1793 AK |
4165 | if (hdspm->tco->framerate != ucontrol->value.enumerated.item[0]) { |
4166 | hdspm->tco->framerate = ucontrol->value.enumerated.item[0]; | |
763f356c | 4167 | |
0dca1793 AK |
4168 | hdspm_tco_write(hdspm); |
4169 | ||
4170 | return 1; | |
4171 | } | |
4172 | ||
4173 | return 0; | |
4174 | } | |
763f356c | 4175 | |
0dca1793 AK |
4176 | |
4177 | #define HDSPM_TCO_SYNC_SOURCE(xname, xindex) \ | |
4178 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ | |
4179 | .name = xname, \ | |
4180 | .index = xindex, \ | |
4181 | .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |\ | |
4182 | SNDRV_CTL_ELEM_ACCESS_VOLATILE, \ | |
4183 | .info = snd_hdspm_info_tco_sync_source, \ | |
4184 | .get = snd_hdspm_get_tco_sync_source, \ | |
4185 | .put = snd_hdspm_put_tco_sync_source \ | |
4186 | } | |
4187 | ||
4188 | static int snd_hdspm_info_tco_sync_source(struct snd_kcontrol *kcontrol, | |
4189 | struct snd_ctl_elem_info *uinfo) | |
4190 | { | |
4191 | static char *texts[] = { "LTC", "Video", "WCK" }; | |
e5b7b1fe | 4192 | ENUMERATED_CTL_INFO(uinfo, texts); |
0dca1793 AK |
4193 | return 0; |
4194 | } | |
4195 | ||
4196 | static int snd_hdspm_get_tco_sync_source(struct snd_kcontrol *kcontrol, | |
4197 | struct snd_ctl_elem_value *ucontrol) | |
4198 | { | |
4199 | struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); | |
4200 | ||
4201 | ucontrol->value.enumerated.item[0] = hdspm->tco->input; | |
4202 | ||
4203 | return 0; | |
4204 | } | |
4205 | ||
4206 | static int snd_hdspm_put_tco_sync_source(struct snd_kcontrol *kcontrol, | |
4207 | struct snd_ctl_elem_value *ucontrol) | |
4208 | { | |
4209 | struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); | |
4210 | ||
4211 | if (hdspm->tco->input != ucontrol->value.enumerated.item[0]) { | |
4212 | hdspm->tco->input = ucontrol->value.enumerated.item[0]; | |
4213 | ||
4214 | hdspm_tco_write(hdspm); | |
4215 | ||
4216 | return 1; | |
4217 | } | |
4218 | ||
4219 | return 0; | |
4220 | } | |
4221 | ||
4222 | ||
4223 | #define HDSPM_TCO_WORD_TERM(xname, xindex) \ | |
4224 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ | |
4225 | .name = xname, \ | |
4226 | .index = xindex, \ | |
4227 | .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |\ | |
4228 | SNDRV_CTL_ELEM_ACCESS_VOLATILE, \ | |
4229 | .info = snd_hdspm_info_tco_word_term, \ | |
4230 | .get = snd_hdspm_get_tco_word_term, \ | |
4231 | .put = snd_hdspm_put_tco_word_term \ | |
4232 | } | |
4233 | ||
4234 | static int snd_hdspm_info_tco_word_term(struct snd_kcontrol *kcontrol, | |
4235 | struct snd_ctl_elem_info *uinfo) | |
4236 | { | |
4237 | uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; | |
4238 | uinfo->count = 1; | |
4239 | uinfo->value.integer.min = 0; | |
4240 | uinfo->value.integer.max = 1; | |
4241 | ||
4242 | return 0; | |
4243 | } | |
4244 | ||
4245 | ||
4246 | static int snd_hdspm_get_tco_word_term(struct snd_kcontrol *kcontrol, | |
4247 | struct snd_ctl_elem_value *ucontrol) | |
4248 | { | |
4249 | struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); | |
4250 | ||
4251 | ucontrol->value.enumerated.item[0] = hdspm->tco->term; | |
4252 | ||
4253 | return 0; | |
4254 | } | |
4255 | ||
4256 | ||
4257 | static int snd_hdspm_put_tco_word_term(struct snd_kcontrol *kcontrol, | |
4258 | struct snd_ctl_elem_value *ucontrol) | |
4259 | { | |
4260 | struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); | |
4261 | ||
4262 | if (hdspm->tco->term != ucontrol->value.enumerated.item[0]) { | |
4263 | hdspm->tco->term = ucontrol->value.enumerated.item[0]; | |
4264 | ||
4265 | hdspm_tco_write(hdspm); | |
4266 | ||
4267 | return 1; | |
4268 | } | |
4269 | ||
4270 | return 0; | |
4271 | } | |
4272 | ||
4273 | ||
4274 | ||
4275 | ||
4276 | static struct snd_kcontrol_new snd_hdspm_controls_madi[] = { | |
4277 | HDSPM_MIXER("Mixer", 0), | |
4278 | HDSPM_INTERNAL_CLOCK("Internal Clock", 0), | |
763f356c TI |
4279 | HDSPM_SYSTEM_CLOCK_MODE("System Clock Mode", 0), |
4280 | HDSPM_PREF_SYNC_REF("Preferred Sync Reference", 0), | |
4281 | HDSPM_AUTOSYNC_REF("AutoSync Reference", 0), | |
4282 | HDSPM_SYSTEM_SAMPLE_RATE("System Sample Rate", 0), | |
b8812c55 | 4283 | HDSPM_AUTOSYNC_SAMPLE_RATE("External Rate", 0), |
0dca1793 AK |
4284 | HDSPM_SYNC_CHECK("WC SyncCheck", 0), |
4285 | HDSPM_SYNC_CHECK("MADI SyncCheck", 1), | |
930f4ff0 | 4286 | HDSPM_SYNC_CHECK("TCO SyncCheck", 2), |
0dca1793 | 4287 | HDSPM_SYNC_CHECK("SYNC IN SyncCheck", 3), |
c9e1668c AK |
4288 | HDSPM_TOGGLE_SETTING("Line Out", HDSPM_LineOut), |
4289 | HDSPM_TOGGLE_SETTING("TX 64 channels mode", HDSPM_TX_64ch), | |
696be0fb | 4290 | HDSPM_TOGGLE_SETTING("Disable 96K frames", HDSPM_SMUX), |
c9e1668c AK |
4291 | HDSPM_TOGGLE_SETTING("Clear Track Marker", HDSPM_clr_tms), |
4292 | HDSPM_TOGGLE_SETTING("Safe Mode", HDSPM_AutoInp), | |
700d1ef3 AK |
4293 | HDSPM_INPUT_SELECT("Input Select", 0), |
4294 | HDSPM_MADI_SPEEDMODE("MADI Speed Mode", 0) | |
0dca1793 AK |
4295 | }; |
4296 | ||
4297 | ||
4298 | static struct snd_kcontrol_new snd_hdspm_controls_madiface[] = { | |
4299 | HDSPM_MIXER("Mixer", 0), | |
4300 | HDSPM_INTERNAL_CLOCK("Internal Clock", 0), | |
4301 | HDSPM_SYSTEM_CLOCK_MODE("System Clock Mode", 0), | |
4302 | HDSPM_SYSTEM_SAMPLE_RATE("System Sample Rate", 0), | |
4303 | HDSPM_AUTOSYNC_SAMPLE_RATE("External Rate", 0), | |
4304 | HDSPM_SYNC_CHECK("MADI SyncCheck", 0), | |
c9e1668c AK |
4305 | HDSPM_TOGGLE_SETTING("TX 64 channels mode", HDSPM_TX_64ch), |
4306 | HDSPM_TOGGLE_SETTING("Clear Track Marker", HDSPM_clr_tms), | |
4307 | HDSPM_TOGGLE_SETTING("Safe Mode", HDSPM_AutoInp), | |
700d1ef3 | 4308 | HDSPM_MADI_SPEEDMODE("MADI Speed Mode", 0) |
763f356c TI |
4309 | }; |
4310 | ||
0dca1793 AK |
4311 | static struct snd_kcontrol_new snd_hdspm_controls_aio[] = { |
4312 | HDSPM_MIXER("Mixer", 0), | |
4313 | HDSPM_INTERNAL_CLOCK("Internal Clock", 0), | |
4314 | HDSPM_SYSTEM_CLOCK_MODE("System Clock Mode", 0), | |
4315 | HDSPM_PREF_SYNC_REF("Preferred Sync Reference", 0), | |
4316 | HDSPM_AUTOSYNC_REF("AutoSync Reference", 0), | |
4317 | HDSPM_SYSTEM_SAMPLE_RATE("System Sample Rate", 0), | |
4318 | HDSPM_AUTOSYNC_SAMPLE_RATE("External Rate", 0), | |
4319 | HDSPM_SYNC_CHECK("WC SyncCheck", 0), | |
4320 | HDSPM_SYNC_CHECK("AES SyncCheck", 1), | |
4321 | HDSPM_SYNC_CHECK("SPDIF SyncCheck", 2), | |
4322 | HDSPM_SYNC_CHECK("ADAT SyncCheck", 3), | |
4323 | HDSPM_SYNC_CHECK("TCO SyncCheck", 4), | |
4324 | HDSPM_SYNC_CHECK("SYNC IN SyncCheck", 5), | |
4325 | HDSPM_AUTOSYNC_SAMPLE_RATE("WC Frequency", 0), | |
4326 | HDSPM_AUTOSYNC_SAMPLE_RATE("AES Frequency", 1), | |
4327 | HDSPM_AUTOSYNC_SAMPLE_RATE("SPDIF Frequency", 2), | |
4328 | HDSPM_AUTOSYNC_SAMPLE_RATE("ADAT Frequency", 3), | |
4329 | HDSPM_AUTOSYNC_SAMPLE_RATE("TCO Frequency", 4), | |
4330 | HDSPM_AUTOSYNC_SAMPLE_RATE("SYNC IN Frequency", 5) | |
4331 | ||
4332 | /* | |
4333 | HDSPM_INPUT_SELECT("Input Select", 0), | |
4334 | HDSPM_SPDIF_OPTICAL("SPDIF Out Optical", 0), | |
4335 | HDSPM_PROFESSIONAL("SPDIF Out Professional", 0); | |
4336 | HDSPM_SPDIF_IN("SPDIF In", 0); | |
4337 | HDSPM_BREAKOUT_CABLE("Breakout Cable", 0); | |
4338 | HDSPM_INPUT_LEVEL("Input Level", 0); | |
4339 | HDSPM_OUTPUT_LEVEL("Output Level", 0); | |
4340 | HDSPM_PHONES("Phones", 0); | |
4341 | */ | |
4342 | }; | |
3cee5a60 | 4343 | |
0dca1793 AK |
4344 | static struct snd_kcontrol_new snd_hdspm_controls_raydat[] = { |
4345 | HDSPM_MIXER("Mixer", 0), | |
4346 | HDSPM_INTERNAL_CLOCK("Internal Clock", 0), | |
4347 | HDSPM_SYSTEM_CLOCK_MODE("Clock Mode", 0), | |
4348 | HDSPM_PREF_SYNC_REF("Pref Sync Ref", 0), | |
4349 | HDSPM_SYSTEM_SAMPLE_RATE("System Sample Rate", 0), | |
4350 | HDSPM_SYNC_CHECK("WC SyncCheck", 0), | |
4351 | HDSPM_SYNC_CHECK("AES SyncCheck", 1), | |
4352 | HDSPM_SYNC_CHECK("SPDIF SyncCheck", 2), | |
4353 | HDSPM_SYNC_CHECK("ADAT1 SyncCheck", 3), | |
4354 | HDSPM_SYNC_CHECK("ADAT2 SyncCheck", 4), | |
4355 | HDSPM_SYNC_CHECK("ADAT3 SyncCheck", 5), | |
4356 | HDSPM_SYNC_CHECK("ADAT4 SyncCheck", 6), | |
4357 | HDSPM_SYNC_CHECK("TCO SyncCheck", 7), | |
4358 | HDSPM_SYNC_CHECK("SYNC IN SyncCheck", 8), | |
4359 | HDSPM_AUTOSYNC_SAMPLE_RATE("WC Frequency", 0), | |
4360 | HDSPM_AUTOSYNC_SAMPLE_RATE("AES Frequency", 1), | |
4361 | HDSPM_AUTOSYNC_SAMPLE_RATE("SPDIF Frequency", 2), | |
4362 | HDSPM_AUTOSYNC_SAMPLE_RATE("ADAT1 Frequency", 3), | |
4363 | HDSPM_AUTOSYNC_SAMPLE_RATE("ADAT2 Frequency", 4), | |
4364 | HDSPM_AUTOSYNC_SAMPLE_RATE("ADAT3 Frequency", 5), | |
4365 | HDSPM_AUTOSYNC_SAMPLE_RATE("ADAT4 Frequency", 6), | |
4366 | HDSPM_AUTOSYNC_SAMPLE_RATE("TCO Frequency", 7), | |
11a5cd3c AK |
4367 | HDSPM_AUTOSYNC_SAMPLE_RATE("SYNC IN Frequency", 8), |
4368 | HDSPM_TOGGLE_SETTING("S/PDIF Out Professional", HDSPM_c0_Pro), | |
4369 | HDSPM_TOGGLE_SETTING("Single Speed WordClock Out", HDSPM_c0_Wck48) | |
0dca1793 AK |
4370 | }; |
4371 | ||
4372 | static struct snd_kcontrol_new snd_hdspm_controls_aes32[] = { | |
3cee5a60 | 4373 | HDSPM_MIXER("Mixer", 0), |
0dca1793 | 4374 | HDSPM_INTERNAL_CLOCK("Internal Clock", 0), |
3cee5a60 RB |
4375 | HDSPM_SYSTEM_CLOCK_MODE("System Clock Mode", 0), |
4376 | HDSPM_PREF_SYNC_REF("Preferred Sync Reference", 0), | |
4377 | HDSPM_AUTOSYNC_REF("AutoSync Reference", 0), | |
4378 | HDSPM_SYSTEM_SAMPLE_RATE("System Sample Rate", 0), | |
3cee5a60 | 4379 | HDSPM_AUTOSYNC_SAMPLE_RATE("External Rate", 0), |
0dca1793 AK |
4380 | HDSPM_SYNC_CHECK("WC Sync Check", 0), |
4381 | HDSPM_SYNC_CHECK("AES1 Sync Check", 1), | |
4382 | HDSPM_SYNC_CHECK("AES2 Sync Check", 2), | |
4383 | HDSPM_SYNC_CHECK("AES3 Sync Check", 3), | |
4384 | HDSPM_SYNC_CHECK("AES4 Sync Check", 4), | |
4385 | HDSPM_SYNC_CHECK("AES5 Sync Check", 5), | |
4386 | HDSPM_SYNC_CHECK("AES6 Sync Check", 6), | |
4387 | HDSPM_SYNC_CHECK("AES7 Sync Check", 7), | |
4388 | HDSPM_SYNC_CHECK("AES8 Sync Check", 8), | |
4389 | HDSPM_SYNC_CHECK("TCO Sync Check", 9), | |
4390 | HDSPM_SYNC_CHECK("SYNC IN Sync Check", 10), | |
4391 | HDSPM_AUTOSYNC_SAMPLE_RATE("WC Frequency", 0), | |
4392 | HDSPM_AUTOSYNC_SAMPLE_RATE("AES1 Frequency", 1), | |
4393 | HDSPM_AUTOSYNC_SAMPLE_RATE("AES2 Frequency", 2), | |
4394 | HDSPM_AUTOSYNC_SAMPLE_RATE("AES3 Frequency", 3), | |
4395 | HDSPM_AUTOSYNC_SAMPLE_RATE("AES4 Frequency", 4), | |
4396 | HDSPM_AUTOSYNC_SAMPLE_RATE("AES5 Frequency", 5), | |
4397 | HDSPM_AUTOSYNC_SAMPLE_RATE("AES6 Frequency", 6), | |
4398 | HDSPM_AUTOSYNC_SAMPLE_RATE("AES7 Frequency", 7), | |
4399 | HDSPM_AUTOSYNC_SAMPLE_RATE("AES8 Frequency", 8), | |
4400 | HDSPM_AUTOSYNC_SAMPLE_RATE("TCO Frequency", 9), | |
4401 | HDSPM_AUTOSYNC_SAMPLE_RATE("SYNC IN Frequency", 10), | |
c9e1668c AK |
4402 | HDSPM_TOGGLE_SETTING("Line Out", HDSPM_LineOut), |
4403 | HDSPM_TOGGLE_SETTING("Emphasis", HDSPM_Emphasis), | |
4404 | HDSPM_TOGGLE_SETTING("Non Audio", HDSPM_Dolby), | |
4405 | HDSPM_TOGGLE_SETTING("Professional", HDSPM_Professional), | |
4406 | HDSPM_TOGGLE_SETTING("Clear Track Marker", HDSPM_clr_tms), | |
3cee5a60 RB |
4407 | HDSPM_DS_WIRE("Double Speed Wire Mode", 0), |
4408 | HDSPM_QS_WIRE("Quad Speed Wire Mode", 0), | |
4409 | }; | |
4410 | ||
0dca1793 AK |
4411 | |
4412 | ||
4413 | /* Control elements for the optional TCO module */ | |
4414 | static struct snd_kcontrol_new snd_hdspm_controls_tco[] = { | |
4415 | HDSPM_TCO_SAMPLE_RATE("TCO Sample Rate", 0), | |
4416 | HDSPM_TCO_PULL("TCO Pull", 0), | |
4417 | HDSPM_TCO_WCK_CONVERSION("TCO WCK Conversion", 0), | |
4418 | HDSPM_TCO_FRAME_RATE("TCO Frame Rate", 0), | |
4419 | HDSPM_TCO_SYNC_SOURCE("TCO Sync Source", 0), | |
a817650e AK |
4420 | HDSPM_TCO_WORD_TERM("TCO Word Term", 0), |
4421 | HDSPM_TCO_LOCK_CHECK("TCO Input Check", 11), | |
4422 | HDSPM_TCO_LOCK_CHECK("TCO LTC Valid", 12), | |
4423 | HDSPM_TCO_LTC_FRAMES("TCO Detected Frame Rate", 0), | |
4424 | HDSPM_TCO_VIDEO_INPUT_FORMAT("Video Input Format", 0) | |
0dca1793 AK |
4425 | }; |
4426 | ||
4427 | ||
98274f07 | 4428 | static struct snd_kcontrol_new snd_hdspm_playback_mixer = HDSPM_PLAYBACK_MIXER; |
763f356c TI |
4429 | |
4430 | ||
98274f07 | 4431 | static int hdspm_update_simple_mixer_controls(struct hdspm * hdspm) |
763f356c TI |
4432 | { |
4433 | int i; | |
4434 | ||
0dca1793 | 4435 | for (i = hdspm->ds_out_channels; i < hdspm->ss_out_channels; ++i) { |
763f356c TI |
4436 | if (hdspm->system_sample_rate > 48000) { |
4437 | hdspm->playback_mixer_ctls[i]->vd[0].access = | |
0dca1793 AK |
4438 | SNDRV_CTL_ELEM_ACCESS_INACTIVE | |
4439 | SNDRV_CTL_ELEM_ACCESS_READ | | |
4440 | SNDRV_CTL_ELEM_ACCESS_VOLATILE; | |
763f356c TI |
4441 | } else { |
4442 | hdspm->playback_mixer_ctls[i]->vd[0].access = | |
0dca1793 AK |
4443 | SNDRV_CTL_ELEM_ACCESS_READWRITE | |
4444 | SNDRV_CTL_ELEM_ACCESS_VOLATILE; | |
763f356c TI |
4445 | } |
4446 | snd_ctl_notify(hdspm->card, SNDRV_CTL_EVENT_MASK_VALUE | | |
0dca1793 AK |
4447 | SNDRV_CTL_EVENT_MASK_INFO, |
4448 | &hdspm->playback_mixer_ctls[i]->id); | |
763f356c TI |
4449 | } |
4450 | ||
4451 | return 0; | |
4452 | } | |
4453 | ||
4454 | ||
0dca1793 AK |
4455 | static int snd_hdspm_create_controls(struct snd_card *card, |
4456 | struct hdspm *hdspm) | |
763f356c TI |
4457 | { |
4458 | unsigned int idx, limit; | |
4459 | int err; | |
98274f07 | 4460 | struct snd_kcontrol *kctl; |
0dca1793 | 4461 | struct snd_kcontrol_new *list = NULL; |
763f356c | 4462 | |
0dca1793 AK |
4463 | switch (hdspm->io_type) { |
4464 | case MADI: | |
4465 | list = snd_hdspm_controls_madi; | |
4466 | limit = ARRAY_SIZE(snd_hdspm_controls_madi); | |
4467 | break; | |
4468 | case MADIface: | |
4469 | list = snd_hdspm_controls_madiface; | |
4470 | limit = ARRAY_SIZE(snd_hdspm_controls_madiface); | |
4471 | break; | |
4472 | case AIO: | |
4473 | list = snd_hdspm_controls_aio; | |
4474 | limit = ARRAY_SIZE(snd_hdspm_controls_aio); | |
4475 | break; | |
4476 | case RayDAT: | |
4477 | list = snd_hdspm_controls_raydat; | |
4478 | limit = ARRAY_SIZE(snd_hdspm_controls_raydat); | |
4479 | break; | |
4480 | case AES32: | |
4481 | list = snd_hdspm_controls_aes32; | |
4482 | limit = ARRAY_SIZE(snd_hdspm_controls_aes32); | |
4483 | break; | |
4484 | } | |
3cee5a60 | 4485 | |
0dca1793 AK |
4486 | if (NULL != list) { |
4487 | for (idx = 0; idx < limit; idx++) { | |
3cee5a60 | 4488 | err = snd_ctl_add(card, |
0dca1793 | 4489 | snd_ctl_new1(&list[idx], hdspm)); |
3cee5a60 RB |
4490 | if (err < 0) |
4491 | return err; | |
763f356c TI |
4492 | } |
4493 | } | |
4494 | ||
763f356c | 4495 | |
0dca1793 | 4496 | /* create simple 1:1 playback mixer controls */ |
763f356c | 4497 | snd_hdspm_playback_mixer.name = "Chn"; |
0dca1793 AK |
4498 | if (hdspm->system_sample_rate >= 128000) { |
4499 | limit = hdspm->qs_out_channels; | |
4500 | } else if (hdspm->system_sample_rate >= 64000) { | |
4501 | limit = hdspm->ds_out_channels; | |
4502 | } else { | |
4503 | limit = hdspm->ss_out_channels; | |
4504 | } | |
763f356c TI |
4505 | for (idx = 0; idx < limit; ++idx) { |
4506 | snd_hdspm_playback_mixer.index = idx + 1; | |
ef5fa1a4 TI |
4507 | kctl = snd_ctl_new1(&snd_hdspm_playback_mixer, hdspm); |
4508 | err = snd_ctl_add(card, kctl); | |
4509 | if (err < 0) | |
763f356c | 4510 | return err; |
763f356c TI |
4511 | hdspm->playback_mixer_ctls[idx] = kctl; |
4512 | } | |
4513 | ||
0dca1793 AK |
4514 | |
4515 | if (hdspm->tco) { | |
4516 | /* add tco control elements */ | |
4517 | list = snd_hdspm_controls_tco; | |
4518 | limit = ARRAY_SIZE(snd_hdspm_controls_tco); | |
4519 | for (idx = 0; idx < limit; idx++) { | |
4520 | err = snd_ctl_add(card, | |
4521 | snd_ctl_new1(&list[idx], hdspm)); | |
4522 | if (err < 0) | |
4523 | return err; | |
4524 | } | |
4525 | } | |
4526 | ||
763f356c TI |
4527 | return 0; |
4528 | } | |
4529 | ||
4530 | /*------------------------------------------------------------ | |
0dca1793 | 4531 | /proc interface |
763f356c TI |
4532 | ------------------------------------------------------------*/ |
4533 | ||
4534 | static void | |
3cee5a60 RB |
4535 | snd_hdspm_proc_read_madi(struct snd_info_entry * entry, |
4536 | struct snd_info_buffer *buffer) | |
763f356c | 4537 | { |
ef5fa1a4 | 4538 | struct hdspm *hdspm = entry->private_data; |
0dca1793 AK |
4539 | unsigned int status, status2, control, freq; |
4540 | ||
763f356c TI |
4541 | char *pref_sync_ref; |
4542 | char *autosync_ref; | |
4543 | char *system_clock_mode; | |
763f356c | 4544 | char *insel; |
763f356c TI |
4545 | int x, x2; |
4546 | ||
0dca1793 AK |
4547 | /* TCO stuff */ |
4548 | int a, ltc, frames, seconds, minutes, hours; | |
4549 | unsigned int period; | |
4550 | u64 freq_const = 0; | |
4551 | u32 rate; | |
4552 | ||
763f356c TI |
4553 | status = hdspm_read(hdspm, HDSPM_statusRegister); |
4554 | status2 = hdspm_read(hdspm, HDSPM_statusRegister2); | |
0dca1793 AK |
4555 | control = hdspm->control_register; |
4556 | freq = hdspm_read(hdspm, HDSPM_timecodeRegister); | |
763f356c TI |
4557 | |
4558 | snd_iprintf(buffer, "%s (Card #%d) Rev.%x Status2first3bits: %x\n", | |
0dca1793 AK |
4559 | hdspm->card_name, hdspm->card->number + 1, |
4560 | hdspm->firmware_rev, | |
4561 | (status2 & HDSPM_version0) | | |
4562 | (status2 & HDSPM_version1) | (status2 & | |
4563 | HDSPM_version2)); | |
4564 | ||
4565 | snd_iprintf(buffer, "HW Serial: 0x%06x%06x\n", | |
4566 | (hdspm_read(hdspm, HDSPM_midiStatusIn1)>>8) & 0xFFFFFF, | |
7d53a631 | 4567 | hdspm->serial); |
763f356c TI |
4568 | |
4569 | snd_iprintf(buffer, "IRQ: %d Registers bus: 0x%lx VM: 0x%lx\n", | |
0dca1793 | 4570 | hdspm->irq, hdspm->port, (unsigned long)hdspm->iobase); |
763f356c TI |
4571 | |
4572 | snd_iprintf(buffer, "--- System ---\n"); | |
4573 | ||
4574 | snd_iprintf(buffer, | |
0dca1793 AK |
4575 | "IRQ Pending: Audio=%d, MIDI0=%d, MIDI1=%d, IRQcount=%d\n", |
4576 | status & HDSPM_audioIRQPending, | |
4577 | (status & HDSPM_midi0IRQPending) ? 1 : 0, | |
4578 | (status & HDSPM_midi1IRQPending) ? 1 : 0, | |
4579 | hdspm->irq_count); | |
763f356c | 4580 | snd_iprintf(buffer, |
0dca1793 AK |
4581 | "HW pointer: id = %d, rawptr = %d (%d->%d) " |
4582 | "estimated= %ld (bytes)\n", | |
4583 | ((status & HDSPM_BufferID) ? 1 : 0), | |
4584 | (status & HDSPM_BufferPositionMask), | |
4585 | (status & HDSPM_BufferPositionMask) % | |
4586 | (2 * (int)hdspm->period_bytes), | |
4587 | ((status & HDSPM_BufferPositionMask) - 64) % | |
4588 | (2 * (int)hdspm->period_bytes), | |
4589 | (long) hdspm_hw_pointer(hdspm) * 4); | |
763f356c TI |
4590 | |
4591 | snd_iprintf(buffer, | |
0dca1793 AK |
4592 | "MIDI FIFO: Out1=0x%x, Out2=0x%x, In1=0x%x, In2=0x%x \n", |
4593 | hdspm_read(hdspm, HDSPM_midiStatusOut0) & 0xFF, | |
4594 | hdspm_read(hdspm, HDSPM_midiStatusOut1) & 0xFF, | |
4595 | hdspm_read(hdspm, HDSPM_midiStatusIn0) & 0xFF, | |
4596 | hdspm_read(hdspm, HDSPM_midiStatusIn1) & 0xFF); | |
763f356c | 4597 | snd_iprintf(buffer, |
0dca1793 AK |
4598 | "MIDIoverMADI FIFO: In=0x%x, Out=0x%x \n", |
4599 | hdspm_read(hdspm, HDSPM_midiStatusIn2) & 0xFF, | |
4600 | hdspm_read(hdspm, HDSPM_midiStatusOut2) & 0xFF); | |
4601 | snd_iprintf(buffer, | |
4602 | "Register: ctrl1=0x%x, ctrl2=0x%x, status1=0x%x, " | |
4603 | "status2=0x%x\n", | |
4604 | hdspm->control_register, hdspm->control2_register, | |
4605 | status, status2); | |
4606 | if (status & HDSPM_tco_detect) { | |
4607 | snd_iprintf(buffer, "TCO module detected.\n"); | |
4608 | a = hdspm_read(hdspm, HDSPM_RD_TCO+4); | |
4609 | if (a & HDSPM_TCO1_LTC_Input_valid) { | |
4610 | snd_iprintf(buffer, " LTC valid, "); | |
4611 | switch (a & (HDSPM_TCO1_LTC_Format_LSB | | |
4612 | HDSPM_TCO1_LTC_Format_MSB)) { | |
4613 | case 0: | |
4614 | snd_iprintf(buffer, "24 fps, "); | |
4615 | break; | |
4616 | case HDSPM_TCO1_LTC_Format_LSB: | |
4617 | snd_iprintf(buffer, "25 fps, "); | |
4618 | break; | |
4619 | case HDSPM_TCO1_LTC_Format_MSB: | |
4620 | snd_iprintf(buffer, "29.97 fps, "); | |
4621 | break; | |
4622 | default: | |
4623 | snd_iprintf(buffer, "30 fps, "); | |
4624 | break; | |
4625 | } | |
4626 | if (a & HDSPM_TCO1_set_drop_frame_flag) { | |
4627 | snd_iprintf(buffer, "drop frame\n"); | |
4628 | } else { | |
4629 | snd_iprintf(buffer, "full frame\n"); | |
4630 | } | |
4631 | } else { | |
4632 | snd_iprintf(buffer, " no LTC\n"); | |
4633 | } | |
4634 | if (a & HDSPM_TCO1_Video_Input_Format_NTSC) { | |
4635 | snd_iprintf(buffer, " Video: NTSC\n"); | |
4636 | } else if (a & HDSPM_TCO1_Video_Input_Format_PAL) { | |
4637 | snd_iprintf(buffer, " Video: PAL\n"); | |
4638 | } else { | |
4639 | snd_iprintf(buffer, " No video\n"); | |
4640 | } | |
4641 | if (a & HDSPM_TCO1_TCO_lock) { | |
4642 | snd_iprintf(buffer, " Sync: lock\n"); | |
4643 | } else { | |
4644 | snd_iprintf(buffer, " Sync: no lock\n"); | |
4645 | } | |
4646 | ||
4647 | switch (hdspm->io_type) { | |
4648 | case MADI: | |
4649 | case AES32: | |
4650 | freq_const = 110069313433624ULL; | |
4651 | break; | |
4652 | case RayDAT: | |
4653 | case AIO: | |
4654 | freq_const = 104857600000000ULL; | |
4655 | break; | |
4656 | case MADIface: | |
4657 | break; /* no TCO possible */ | |
4658 | } | |
4659 | ||
4660 | period = hdspm_read(hdspm, HDSPM_RD_PLL_FREQ); | |
4661 | snd_iprintf(buffer, " period: %u\n", period); | |
4662 | ||
4663 | ||
4664 | /* rate = freq_const/period; */ | |
4665 | rate = div_u64(freq_const, period); | |
4666 | ||
4667 | if (control & HDSPM_QuadSpeed) { | |
4668 | rate *= 4; | |
4669 | } else if (control & HDSPM_DoubleSpeed) { | |
4670 | rate *= 2; | |
4671 | } | |
4672 | ||
4673 | snd_iprintf(buffer, " Frequency: %u Hz\n", | |
4674 | (unsigned int) rate); | |
4675 | ||
4676 | ltc = hdspm_read(hdspm, HDSPM_RD_TCO); | |
4677 | frames = ltc & 0xF; | |
4678 | ltc >>= 4; | |
4679 | frames += (ltc & 0x3) * 10; | |
4680 | ltc >>= 4; | |
4681 | seconds = ltc & 0xF; | |
4682 | ltc >>= 4; | |
4683 | seconds += (ltc & 0x7) * 10; | |
4684 | ltc >>= 4; | |
4685 | minutes = ltc & 0xF; | |
4686 | ltc >>= 4; | |
4687 | minutes += (ltc & 0x7) * 10; | |
4688 | ltc >>= 4; | |
4689 | hours = ltc & 0xF; | |
4690 | ltc >>= 4; | |
4691 | hours += (ltc & 0x3) * 10; | |
4692 | snd_iprintf(buffer, | |
4693 | " LTC In: %02d:%02d:%02d:%02d\n", | |
4694 | hours, minutes, seconds, frames); | |
4695 | ||
4696 | } else { | |
4697 | snd_iprintf(buffer, "No TCO module detected.\n"); | |
4698 | } | |
763f356c TI |
4699 | |
4700 | snd_iprintf(buffer, "--- Settings ---\n"); | |
4701 | ||
7cb155ff | 4702 | x = hdspm_get_latency(hdspm); |
763f356c TI |
4703 | |
4704 | snd_iprintf(buffer, | |
0dca1793 AK |
4705 | "Size (Latency): %d samples (2 periods of %lu bytes)\n", |
4706 | x, (unsigned long) hdspm->period_bytes); | |
763f356c | 4707 | |
0dca1793 AK |
4708 | snd_iprintf(buffer, "Line out: %s\n", |
4709 | (hdspm->control_register & HDSPM_LineOut) ? "on " : "off"); | |
763f356c TI |
4710 | |
4711 | switch (hdspm->control_register & HDSPM_InputMask) { | |
4712 | case HDSPM_InputOptical: | |
4713 | insel = "Optical"; | |
4714 | break; | |
4715 | case HDSPM_InputCoaxial: | |
4716 | insel = "Coaxial"; | |
4717 | break; | |
4718 | default: | |
ec8f53fb | 4719 | insel = "Unknown"; |
763f356c | 4720 | } |
763f356c TI |
4721 | |
4722 | snd_iprintf(buffer, | |
0dca1793 AK |
4723 | "ClearTrackMarker = %s, Transmit in %s Channel Mode, " |
4724 | "Auto Input %s\n", | |
4725 | (hdspm->control_register & HDSPM_clr_tms) ? "on" : "off", | |
4726 | (hdspm->control_register & HDSPM_TX_64ch) ? "64" : "56", | |
4727 | (hdspm->control_register & HDSPM_AutoInp) ? "on" : "off"); | |
4728 | ||
763f356c | 4729 | |
3cee5a60 | 4730 | if (!(hdspm->control_register & HDSPM_ClockModeMaster)) |
0dca1793 | 4731 | system_clock_mode = "AutoSync"; |
3cee5a60 | 4732 | else |
763f356c | 4733 | system_clock_mode = "Master"; |
0dca1793 | 4734 | snd_iprintf(buffer, "AutoSync Reference: %s\n", system_clock_mode); |
763f356c TI |
4735 | |
4736 | switch (hdspm_pref_sync_ref(hdspm)) { | |
4737 | case HDSPM_SYNC_FROM_WORD: | |
4738 | pref_sync_ref = "Word Clock"; | |
4739 | break; | |
4740 | case HDSPM_SYNC_FROM_MADI: | |
4741 | pref_sync_ref = "MADI Sync"; | |
4742 | break; | |
0dca1793 AK |
4743 | case HDSPM_SYNC_FROM_TCO: |
4744 | pref_sync_ref = "TCO"; | |
4745 | break; | |
4746 | case HDSPM_SYNC_FROM_SYNC_IN: | |
4747 | pref_sync_ref = "Sync In"; | |
4748 | break; | |
763f356c TI |
4749 | default: |
4750 | pref_sync_ref = "XXXX Clock"; | |
4751 | break; | |
4752 | } | |
4753 | snd_iprintf(buffer, "Preferred Sync Reference: %s\n", | |
0dca1793 | 4754 | pref_sync_ref); |
763f356c TI |
4755 | |
4756 | snd_iprintf(buffer, "System Clock Frequency: %d\n", | |
0dca1793 | 4757 | hdspm->system_sample_rate); |
763f356c TI |
4758 | |
4759 | ||
4760 | snd_iprintf(buffer, "--- Status:\n"); | |
4761 | ||
4762 | x = status & HDSPM_madiSync; | |
4763 | x2 = status2 & HDSPM_wcSync; | |
4764 | ||
4765 | snd_iprintf(buffer, "Inputs MADI=%s, WordClock=%s\n", | |
0dca1793 AK |
4766 | (status & HDSPM_madiLock) ? (x ? "Sync" : "Lock") : |
4767 | "NoLock", | |
4768 | (status2 & HDSPM_wcLock) ? (x2 ? "Sync" : "Lock") : | |
4769 | "NoLock"); | |
763f356c TI |
4770 | |
4771 | switch (hdspm_autosync_ref(hdspm)) { | |
0dca1793 AK |
4772 | case HDSPM_AUTOSYNC_FROM_SYNC_IN: |
4773 | autosync_ref = "Sync In"; | |
4774 | break; | |
4775 | case HDSPM_AUTOSYNC_FROM_TCO: | |
4776 | autosync_ref = "TCO"; | |
4777 | break; | |
763f356c TI |
4778 | case HDSPM_AUTOSYNC_FROM_WORD: |
4779 | autosync_ref = "Word Clock"; | |
4780 | break; | |
4781 | case HDSPM_AUTOSYNC_FROM_MADI: | |
4782 | autosync_ref = "MADI Sync"; | |
4783 | break; | |
4784 | case HDSPM_AUTOSYNC_FROM_NONE: | |
4785 | autosync_ref = "Input not valid"; | |
4786 | break; | |
4787 | default: | |
4788 | autosync_ref = "---"; | |
4789 | break; | |
4790 | } | |
4791 | snd_iprintf(buffer, | |
0dca1793 AK |
4792 | "AutoSync: Reference= %s, Freq=%d (MADI = %d, Word = %d)\n", |
4793 | autosync_ref, hdspm_external_sample_rate(hdspm), | |
4794 | (status & HDSPM_madiFreqMask) >> 22, | |
4795 | (status2 & HDSPM_wcFreqMask) >> 5); | |
763f356c TI |
4796 | |
4797 | snd_iprintf(buffer, "Input: %s, Mode=%s\n", | |
0dca1793 AK |
4798 | (status & HDSPM_AB_int) ? "Coax" : "Optical", |
4799 | (status & HDSPM_RX_64ch) ? "64 channels" : | |
4800 | "56 channels"); | |
763f356c TI |
4801 | |
4802 | snd_iprintf(buffer, "\n"); | |
4803 | } | |
4804 | ||
3cee5a60 RB |
4805 | static void |
4806 | snd_hdspm_proc_read_aes32(struct snd_info_entry * entry, | |
4807 | struct snd_info_buffer *buffer) | |
4808 | { | |
ef5fa1a4 | 4809 | struct hdspm *hdspm = entry->private_data; |
3cee5a60 RB |
4810 | unsigned int status; |
4811 | unsigned int status2; | |
4812 | unsigned int timecode; | |
56bde0f3 | 4813 | unsigned int wcLock, wcSync; |
3cee5a60 RB |
4814 | int pref_syncref; |
4815 | char *autosync_ref; | |
3cee5a60 RB |
4816 | int x; |
4817 | ||
4818 | status = hdspm_read(hdspm, HDSPM_statusRegister); | |
4819 | status2 = hdspm_read(hdspm, HDSPM_statusRegister2); | |
4820 | timecode = hdspm_read(hdspm, HDSPM_timecodeRegister); | |
4821 | ||
4822 | snd_iprintf(buffer, "%s (Card #%d) Rev.%x\n", | |
4823 | hdspm->card_name, hdspm->card->number + 1, | |
4824 | hdspm->firmware_rev); | |
4825 | ||
4826 | snd_iprintf(buffer, "IRQ: %d Registers bus: 0x%lx VM: 0x%lx\n", | |
4827 | hdspm->irq, hdspm->port, (unsigned long)hdspm->iobase); | |
4828 | ||
4829 | snd_iprintf(buffer, "--- System ---\n"); | |
4830 | ||
4831 | snd_iprintf(buffer, | |
4832 | "IRQ Pending: Audio=%d, MIDI0=%d, MIDI1=%d, IRQcount=%d\n", | |
4833 | status & HDSPM_audioIRQPending, | |
4834 | (status & HDSPM_midi0IRQPending) ? 1 : 0, | |
4835 | (status & HDSPM_midi1IRQPending) ? 1 : 0, | |
4836 | hdspm->irq_count); | |
4837 | snd_iprintf(buffer, | |
ef5fa1a4 TI |
4838 | "HW pointer: id = %d, rawptr = %d (%d->%d) " |
4839 | "estimated= %ld (bytes)\n", | |
3cee5a60 RB |
4840 | ((status & HDSPM_BufferID) ? 1 : 0), |
4841 | (status & HDSPM_BufferPositionMask), | |
ef5fa1a4 TI |
4842 | (status & HDSPM_BufferPositionMask) % |
4843 | (2 * (int)hdspm->period_bytes), | |
4844 | ((status & HDSPM_BufferPositionMask) - 64) % | |
4845 | (2 * (int)hdspm->period_bytes), | |
3cee5a60 RB |
4846 | (long) hdspm_hw_pointer(hdspm) * 4); |
4847 | ||
4848 | snd_iprintf(buffer, | |
4849 | "MIDI FIFO: Out1=0x%x, Out2=0x%x, In1=0x%x, In2=0x%x \n", | |
4850 | hdspm_read(hdspm, HDSPM_midiStatusOut0) & 0xFF, | |
4851 | hdspm_read(hdspm, HDSPM_midiStatusOut1) & 0xFF, | |
4852 | hdspm_read(hdspm, HDSPM_midiStatusIn0) & 0xFF, | |
4853 | hdspm_read(hdspm, HDSPM_midiStatusIn1) & 0xFF); | |
4854 | snd_iprintf(buffer, | |
0dca1793 AK |
4855 | "MIDIoverMADI FIFO: In=0x%x, Out=0x%x \n", |
4856 | hdspm_read(hdspm, HDSPM_midiStatusIn2) & 0xFF, | |
4857 | hdspm_read(hdspm, HDSPM_midiStatusOut2) & 0xFF); | |
4858 | snd_iprintf(buffer, | |
4859 | "Register: ctrl1=0x%x, ctrl2=0x%x, status1=0x%x, " | |
4860 | "status2=0x%x\n", | |
4861 | hdspm->control_register, hdspm->control2_register, | |
4862 | status, status2); | |
3cee5a60 RB |
4863 | |
4864 | snd_iprintf(buffer, "--- Settings ---\n"); | |
4865 | ||
7cb155ff | 4866 | x = hdspm_get_latency(hdspm); |
3cee5a60 RB |
4867 | |
4868 | snd_iprintf(buffer, | |
4869 | "Size (Latency): %d samples (2 periods of %lu bytes)\n", | |
4870 | x, (unsigned long) hdspm->period_bytes); | |
4871 | ||
0dca1793 | 4872 | snd_iprintf(buffer, "Line out: %s\n", |
3cee5a60 | 4873 | (hdspm-> |
0dca1793 | 4874 | control_register & HDSPM_LineOut) ? "on " : "off"); |
3cee5a60 RB |
4875 | |
4876 | snd_iprintf(buffer, | |
4877 | "ClearTrackMarker %s, Emphasis %s, Dolby %s\n", | |
4878 | (hdspm-> | |
4879 | control_register & HDSPM_clr_tms) ? "on" : "off", | |
4880 | (hdspm-> | |
4881 | control_register & HDSPM_Emphasis) ? "on" : "off", | |
4882 | (hdspm-> | |
4883 | control_register & HDSPM_Dolby) ? "on" : "off"); | |
4884 | ||
3cee5a60 RB |
4885 | |
4886 | pref_syncref = hdspm_pref_sync_ref(hdspm); | |
4887 | if (pref_syncref == 0) | |
4888 | snd_iprintf(buffer, "Preferred Sync Reference: Word Clock\n"); | |
4889 | else | |
4890 | snd_iprintf(buffer, "Preferred Sync Reference: AES%d\n", | |
4891 | pref_syncref); | |
4892 | ||
4893 | snd_iprintf(buffer, "System Clock Frequency: %d\n", | |
4894 | hdspm->system_sample_rate); | |
4895 | ||
4896 | snd_iprintf(buffer, "Double speed: %s\n", | |
4897 | hdspm->control_register & HDSPM_DS_DoubleWire? | |
4898 | "Double wire" : "Single wire"); | |
4899 | snd_iprintf(buffer, "Quad speed: %s\n", | |
4900 | hdspm->control_register & HDSPM_QS_DoubleWire? | |
4901 | "Double wire" : | |
4902 | hdspm->control_register & HDSPM_QS_QuadWire? | |
4903 | "Quad wire" : "Single wire"); | |
4904 | ||
4905 | snd_iprintf(buffer, "--- Status:\n"); | |
4906 | ||
56bde0f3 AS |
4907 | wcLock = status & HDSPM_AES32_wcLock; |
4908 | wcSync = wcLock && (status & HDSPM_AES32_wcSync); | |
4909 | ||
3cee5a60 | 4910 | snd_iprintf(buffer, "Word: %s Frequency: %d\n", |
56bde0f3 | 4911 | (wcLock) ? (wcSync ? "Sync " : "Lock ") : "No Lock", |
ef5fa1a4 | 4912 | HDSPM_bit2freq((status >> HDSPM_AES32_wcFreq_bit) & 0xF)); |
3cee5a60 RB |
4913 | |
4914 | for (x = 0; x < 8; x++) { | |
4915 | snd_iprintf(buffer, "AES%d: %s Frequency: %d\n", | |
ef5fa1a4 TI |
4916 | x+1, |
4917 | (status2 & (HDSPM_LockAES >> x)) ? | |
0dca1793 | 4918 | "Sync " : "No Lock", |
ef5fa1a4 | 4919 | HDSPM_bit2freq((timecode >> (4*x)) & 0xF)); |
3cee5a60 RB |
4920 | } |
4921 | ||
4922 | switch (hdspm_autosync_ref(hdspm)) { | |
0dca1793 AK |
4923 | case HDSPM_AES32_AUTOSYNC_FROM_NONE: |
4924 | autosync_ref = "None"; break; | |
4925 | case HDSPM_AES32_AUTOSYNC_FROM_WORD: | |
4926 | autosync_ref = "Word Clock"; break; | |
4927 | case HDSPM_AES32_AUTOSYNC_FROM_AES1: | |
4928 | autosync_ref = "AES1"; break; | |
4929 | case HDSPM_AES32_AUTOSYNC_FROM_AES2: | |
4930 | autosync_ref = "AES2"; break; | |
4931 | case HDSPM_AES32_AUTOSYNC_FROM_AES3: | |
4932 | autosync_ref = "AES3"; break; | |
4933 | case HDSPM_AES32_AUTOSYNC_FROM_AES4: | |
4934 | autosync_ref = "AES4"; break; | |
4935 | case HDSPM_AES32_AUTOSYNC_FROM_AES5: | |
4936 | autosync_ref = "AES5"; break; | |
4937 | case HDSPM_AES32_AUTOSYNC_FROM_AES6: | |
4938 | autosync_ref = "AES6"; break; | |
4939 | case HDSPM_AES32_AUTOSYNC_FROM_AES7: | |
4940 | autosync_ref = "AES7"; break; | |
4941 | case HDSPM_AES32_AUTOSYNC_FROM_AES8: | |
4942 | autosync_ref = "AES8"; break; | |
4943 | default: | |
4944 | autosync_ref = "---"; break; | |
3cee5a60 RB |
4945 | } |
4946 | snd_iprintf(buffer, "AutoSync ref = %s\n", autosync_ref); | |
4947 | ||
4948 | snd_iprintf(buffer, "\n"); | |
4949 | } | |
4950 | ||
0dca1793 AK |
4951 | static void |
4952 | snd_hdspm_proc_read_raydat(struct snd_info_entry *entry, | |
4953 | struct snd_info_buffer *buffer) | |
4954 | { | |
4955 | struct hdspm *hdspm = entry->private_data; | |
4956 | unsigned int status1, status2, status3, control, i; | |
4957 | unsigned int lock, sync; | |
4958 | ||
4959 | status1 = hdspm_read(hdspm, HDSPM_RD_STATUS_1); /* s1 */ | |
4960 | status2 = hdspm_read(hdspm, HDSPM_RD_STATUS_2); /* freq */ | |
4961 | status3 = hdspm_read(hdspm, HDSPM_RD_STATUS_3); /* s2 */ | |
4962 | ||
4963 | control = hdspm->control_register; | |
4964 | ||
4965 | snd_iprintf(buffer, "STATUS1: 0x%08x\n", status1); | |
4966 | snd_iprintf(buffer, "STATUS2: 0x%08x\n", status2); | |
4967 | snd_iprintf(buffer, "STATUS3: 0x%08x\n", status3); | |
4968 | ||
4969 | ||
4970 | snd_iprintf(buffer, "\n*** CLOCK MODE\n\n"); | |
4971 | ||
4972 | snd_iprintf(buffer, "Clock mode : %s\n", | |
4973 | (hdspm_system_clock_mode(hdspm) == 0) ? "master" : "slave"); | |
4974 | snd_iprintf(buffer, "System frequency: %d Hz\n", | |
4975 | hdspm_get_system_sample_rate(hdspm)); | |
4976 | ||
4977 | snd_iprintf(buffer, "\n*** INPUT STATUS\n\n"); | |
4978 | ||
4979 | lock = 0x1; | |
4980 | sync = 0x100; | |
4981 | ||
4982 | for (i = 0; i < 8; i++) { | |
4983 | snd_iprintf(buffer, "s1_input %d: Lock %d, Sync %d, Freq %s\n", | |
4984 | i, | |
4985 | (status1 & lock) ? 1 : 0, | |
4986 | (status1 & sync) ? 1 : 0, | |
4987 | texts_freq[(status2 >> (i * 4)) & 0xF]); | |
4988 | ||
4989 | lock = lock<<1; | |
4990 | sync = sync<<1; | |
4991 | } | |
4992 | ||
4993 | snd_iprintf(buffer, "WC input: Lock %d, Sync %d, Freq %s\n", | |
4994 | (status1 & 0x1000000) ? 1 : 0, | |
4995 | (status1 & 0x2000000) ? 1 : 0, | |
4996 | texts_freq[(status1 >> 16) & 0xF]); | |
4997 | ||
4998 | snd_iprintf(buffer, "TCO input: Lock %d, Sync %d, Freq %s\n", | |
4999 | (status1 & 0x4000000) ? 1 : 0, | |
5000 | (status1 & 0x8000000) ? 1 : 0, | |
5001 | texts_freq[(status1 >> 20) & 0xF]); | |
5002 | ||
5003 | snd_iprintf(buffer, "SYNC IN: Lock %d, Sync %d, Freq %s\n", | |
5004 | (status3 & 0x400) ? 1 : 0, | |
5005 | (status3 & 0x800) ? 1 : 0, | |
5006 | texts_freq[(status2 >> 12) & 0xF]); | |
5007 | ||
5008 | } | |
5009 | ||
3cee5a60 RB |
5010 | #ifdef CONFIG_SND_DEBUG |
5011 | static void | |
0dca1793 | 5012 | snd_hdspm_proc_read_debug(struct snd_info_entry *entry, |
3cee5a60 RB |
5013 | struct snd_info_buffer *buffer) |
5014 | { | |
ef5fa1a4 | 5015 | struct hdspm *hdspm = entry->private_data; |
3cee5a60 RB |
5016 | |
5017 | int j,i; | |
5018 | ||
ef5fa1a4 | 5019 | for (i = 0; i < 256 /* 1024*64 */; i += j) { |
3cee5a60 RB |
5020 | snd_iprintf(buffer, "0x%08X: ", i); |
5021 | for (j = 0; j < 16; j += 4) | |
5022 | snd_iprintf(buffer, "%08X ", hdspm_read(hdspm, i + j)); | |
5023 | snd_iprintf(buffer, "\n"); | |
5024 | } | |
5025 | } | |
5026 | #endif | |
5027 | ||
5028 | ||
0dca1793 AK |
5029 | static void snd_hdspm_proc_ports_in(struct snd_info_entry *entry, |
5030 | struct snd_info_buffer *buffer) | |
5031 | { | |
5032 | struct hdspm *hdspm = entry->private_data; | |
5033 | int i; | |
5034 | ||
5035 | snd_iprintf(buffer, "# generated by hdspm\n"); | |
5036 | ||
5037 | for (i = 0; i < hdspm->max_channels_in; i++) { | |
5038 | snd_iprintf(buffer, "%d=%s\n", i+1, hdspm->port_names_in[i]); | |
5039 | } | |
5040 | } | |
5041 | ||
5042 | static void snd_hdspm_proc_ports_out(struct snd_info_entry *entry, | |
5043 | struct snd_info_buffer *buffer) | |
5044 | { | |
5045 | struct hdspm *hdspm = entry->private_data; | |
5046 | int i; | |
5047 | ||
5048 | snd_iprintf(buffer, "# generated by hdspm\n"); | |
5049 | ||
5050 | for (i = 0; i < hdspm->max_channels_out; i++) { | |
5051 | snd_iprintf(buffer, "%d=%s\n", i+1, hdspm->port_names_out[i]); | |
5052 | } | |
5053 | } | |
5054 | ||
3cee5a60 | 5055 | |
e23e7a14 | 5056 | static void snd_hdspm_proc_init(struct hdspm *hdspm) |
763f356c | 5057 | { |
98274f07 | 5058 | struct snd_info_entry *entry; |
763f356c | 5059 | |
0dca1793 AK |
5060 | if (!snd_card_proc_new(hdspm->card, "hdspm", &entry)) { |
5061 | switch (hdspm->io_type) { | |
5062 | case AES32: | |
5063 | snd_info_set_text_ops(entry, hdspm, | |
5064 | snd_hdspm_proc_read_aes32); | |
5065 | break; | |
5066 | case MADI: | |
5067 | snd_info_set_text_ops(entry, hdspm, | |
5068 | snd_hdspm_proc_read_madi); | |
5069 | break; | |
5070 | case MADIface: | |
5071 | /* snd_info_set_text_ops(entry, hdspm, | |
5072 | snd_hdspm_proc_read_madiface); */ | |
5073 | break; | |
5074 | case RayDAT: | |
5075 | snd_info_set_text_ops(entry, hdspm, | |
5076 | snd_hdspm_proc_read_raydat); | |
5077 | break; | |
5078 | case AIO: | |
5079 | break; | |
5080 | } | |
5081 | } | |
5082 | ||
5083 | if (!snd_card_proc_new(hdspm->card, "ports.in", &entry)) { | |
5084 | snd_info_set_text_ops(entry, hdspm, snd_hdspm_proc_ports_in); | |
5085 | } | |
5086 | ||
5087 | if (!snd_card_proc_new(hdspm->card, "ports.out", &entry)) { | |
5088 | snd_info_set_text_ops(entry, hdspm, snd_hdspm_proc_ports_out); | |
5089 | } | |
5090 | ||
3cee5a60 RB |
5091 | #ifdef CONFIG_SND_DEBUG |
5092 | /* debug file to read all hdspm registers */ | |
5093 | if (!snd_card_proc_new(hdspm->card, "debug", &entry)) | |
5094 | snd_info_set_text_ops(entry, hdspm, | |
5095 | snd_hdspm_proc_read_debug); | |
5096 | #endif | |
763f356c TI |
5097 | } |
5098 | ||
5099 | /*------------------------------------------------------------ | |
0dca1793 | 5100 | hdspm intitialize |
763f356c TI |
5101 | ------------------------------------------------------------*/ |
5102 | ||
98274f07 | 5103 | static int snd_hdspm_set_defaults(struct hdspm * hdspm) |
763f356c | 5104 | { |
763f356c | 5105 | /* ASSUMPTION: hdspm->lock is either held, or there is no need to |
561de31a | 5106 | hold it (e.g. during module initialization). |
0dca1793 | 5107 | */ |
763f356c TI |
5108 | |
5109 | /* set defaults: */ | |
5110 | ||
0dca1793 AK |
5111 | hdspm->settings_register = 0; |
5112 | ||
5113 | switch (hdspm->io_type) { | |
5114 | case MADI: | |
5115 | case MADIface: | |
5116 | hdspm->control_register = | |
5117 | 0x2 + 0x8 + 0x10 + 0x80 + 0x400 + 0x4000 + 0x1000000; | |
5118 | break; | |
5119 | ||
5120 | case RayDAT: | |
5121 | case AIO: | |
5122 | hdspm->settings_register = 0x1 + 0x1000; | |
5123 | /* Magic values are: LAT_0, LAT_2, Master, freq1, tx64ch, inp_0, | |
5124 | * line_out */ | |
5125 | hdspm->control_register = | |
5126 | 0x2 + 0x8 + 0x10 + 0x80 + 0x400 + 0x4000 + 0x1000000; | |
5127 | break; | |
5128 | ||
5129 | case AES32: | |
ef5fa1a4 TI |
5130 | hdspm->control_register = |
5131 | HDSPM_ClockModeMaster | /* Master Cloack Mode on */ | |
0dca1793 | 5132 | hdspm_encode_latency(7) | /* latency max=8192samples */ |
3cee5a60 RB |
5133 | HDSPM_SyncRef0 | /* AES1 is syncclock */ |
5134 | HDSPM_LineOut | /* Analog output in */ | |
5135 | HDSPM_Professional; /* Professional mode */ | |
0dca1793 AK |
5136 | break; |
5137 | } | |
763f356c TI |
5138 | |
5139 | hdspm_write(hdspm, HDSPM_controlRegister, hdspm->control_register); | |
5140 | ||
0dca1793 | 5141 | if (AES32 == hdspm->io_type) { |
ffb2c3c0 | 5142 | /* No control2 register for AES32 */ |
763f356c | 5143 | #ifdef SNDRV_BIG_ENDIAN |
ffb2c3c0 | 5144 | hdspm->control2_register = HDSPM_BIGENDIAN_MODE; |
763f356c | 5145 | #else |
ffb2c3c0 | 5146 | hdspm->control2_register = 0; |
763f356c TI |
5147 | #endif |
5148 | ||
ffb2c3c0 RB |
5149 | hdspm_write(hdspm, HDSPM_control2Reg, hdspm->control2_register); |
5150 | } | |
763f356c TI |
5151 | hdspm_compute_period_size(hdspm); |
5152 | ||
5153 | /* silence everything */ | |
5154 | ||
5155 | all_in_all_mixer(hdspm, 0 * UNITY_GAIN); | |
5156 | ||
b2ed6326 | 5157 | if (hdspm_is_raydat_or_aio(hdspm)) |
0dca1793 | 5158 | hdspm_write(hdspm, HDSPM_WR_SETTINGS, hdspm->settings_register); |
763f356c TI |
5159 | |
5160 | /* set a default rate so that the channel map is set up. */ | |
0dca1793 | 5161 | hdspm_set_rate(hdspm, 48000, 1); |
763f356c TI |
5162 | |
5163 | return 0; | |
5164 | } | |
5165 | ||
5166 | ||
5167 | /*------------------------------------------------------------ | |
0dca1793 | 5168 | interrupt |
763f356c TI |
5169 | ------------------------------------------------------------*/ |
5170 | ||
7d12e780 | 5171 | static irqreturn_t snd_hdspm_interrupt(int irq, void *dev_id) |
763f356c | 5172 | { |
98274f07 | 5173 | struct hdspm *hdspm = (struct hdspm *) dev_id; |
763f356c | 5174 | unsigned int status; |
0dca1793 AK |
5175 | int i, audio, midi, schedule = 0; |
5176 | /* cycles_t now; */ | |
763f356c TI |
5177 | |
5178 | status = hdspm_read(hdspm, HDSPM_statusRegister); | |
5179 | ||
5180 | audio = status & HDSPM_audioIRQPending; | |
0dca1793 AK |
5181 | midi = status & (HDSPM_midi0IRQPending | HDSPM_midi1IRQPending | |
5182 | HDSPM_midi2IRQPending | HDSPM_midi3IRQPending); | |
5183 | ||
5184 | /* now = get_cycles(); */ | |
5185 | /** | |
5186 | * LAT_2..LAT_0 period counter (win) counter (mac) | |
5187 | * 6 4096 ~256053425 ~514672358 | |
5188 | * 5 2048 ~128024983 ~257373821 | |
5189 | * 4 1024 ~64023706 ~128718089 | |
5190 | * 3 512 ~32005945 ~64385999 | |
5191 | * 2 256 ~16003039 ~32260176 | |
5192 | * 1 128 ~7998738 ~16194507 | |
5193 | * 0 64 ~3998231 ~8191558 | |
5194 | **/ | |
5195 | /* | |
5196 | snd_printk(KERN_INFO "snd_hdspm_interrupt %llu @ %llx\n", | |
5197 | now-hdspm->last_interrupt, status & 0xFFC0); | |
5198 | hdspm->last_interrupt = now; | |
5199 | */ | |
763f356c | 5200 | |
0dca1793 | 5201 | if (!audio && !midi) |
763f356c TI |
5202 | return IRQ_NONE; |
5203 | ||
5204 | hdspm_write(hdspm, HDSPM_interruptConfirmation, 0); | |
5205 | hdspm->irq_count++; | |
5206 | ||
763f356c TI |
5207 | |
5208 | if (audio) { | |
763f356c | 5209 | if (hdspm->capture_substream) |
ef5fa1a4 | 5210 | snd_pcm_period_elapsed(hdspm->capture_substream); |
763f356c TI |
5211 | |
5212 | if (hdspm->playback_substream) | |
ef5fa1a4 | 5213 | snd_pcm_period_elapsed(hdspm->playback_substream); |
763f356c TI |
5214 | } |
5215 | ||
0dca1793 AK |
5216 | if (midi) { |
5217 | i = 0; | |
5218 | while (i < hdspm->midiPorts) { | |
5219 | if ((hdspm_read(hdspm, | |
5220 | hdspm->midi[i].statusIn) & 0xff) && | |
5221 | (status & hdspm->midi[i].irq)) { | |
5222 | /* we disable interrupts for this input until | |
5223 | * processing is done | |
5224 | */ | |
5225 | hdspm->control_register &= ~hdspm->midi[i].ie; | |
5226 | hdspm_write(hdspm, HDSPM_controlRegister, | |
5227 | hdspm->control_register); | |
5228 | hdspm->midi[i].pending = 1; | |
5229 | schedule = 1; | |
5230 | } | |
5231 | ||
5232 | i++; | |
5233 | } | |
5234 | ||
5235 | if (schedule) | |
5236 | tasklet_hi_schedule(&hdspm->midi_tasklet); | |
763f356c | 5237 | } |
0dca1793 | 5238 | |
763f356c TI |
5239 | return IRQ_HANDLED; |
5240 | } | |
5241 | ||
5242 | /*------------------------------------------------------------ | |
0dca1793 | 5243 | pcm interface |
763f356c TI |
5244 | ------------------------------------------------------------*/ |
5245 | ||
5246 | ||
0dca1793 AK |
5247 | static snd_pcm_uframes_t snd_hdspm_hw_pointer(struct snd_pcm_substream |
5248 | *substream) | |
763f356c | 5249 | { |
98274f07 | 5250 | struct hdspm *hdspm = snd_pcm_substream_chip(substream); |
763f356c TI |
5251 | return hdspm_hw_pointer(hdspm); |
5252 | } | |
5253 | ||
763f356c | 5254 | |
98274f07 | 5255 | static int snd_hdspm_reset(struct snd_pcm_substream *substream) |
763f356c | 5256 | { |
98274f07 TI |
5257 | struct snd_pcm_runtime *runtime = substream->runtime; |
5258 | struct hdspm *hdspm = snd_pcm_substream_chip(substream); | |
5259 | struct snd_pcm_substream *other; | |
763f356c TI |
5260 | |
5261 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) | |
5262 | other = hdspm->capture_substream; | |
5263 | else | |
5264 | other = hdspm->playback_substream; | |
5265 | ||
5266 | if (hdspm->running) | |
5267 | runtime->status->hw_ptr = hdspm_hw_pointer(hdspm); | |
5268 | else | |
5269 | runtime->status->hw_ptr = 0; | |
5270 | if (other) { | |
98274f07 TI |
5271 | struct snd_pcm_substream *s; |
5272 | struct snd_pcm_runtime *oruntime = other->runtime; | |
ef991b95 | 5273 | snd_pcm_group_for_each_entry(s, substream) { |
763f356c TI |
5274 | if (s == other) { |
5275 | oruntime->status->hw_ptr = | |
0dca1793 | 5276 | runtime->status->hw_ptr; |
763f356c TI |
5277 | break; |
5278 | } | |
5279 | } | |
5280 | } | |
5281 | return 0; | |
5282 | } | |
5283 | ||
98274f07 TI |
5284 | static int snd_hdspm_hw_params(struct snd_pcm_substream *substream, |
5285 | struct snd_pcm_hw_params *params) | |
763f356c | 5286 | { |
98274f07 | 5287 | struct hdspm *hdspm = snd_pcm_substream_chip(substream); |
763f356c TI |
5288 | int err; |
5289 | int i; | |
5290 | pid_t this_pid; | |
5291 | pid_t other_pid; | |
763f356c TI |
5292 | |
5293 | spin_lock_irq(&hdspm->lock); | |
5294 | ||
5295 | if (substream->pstr->stream == SNDRV_PCM_STREAM_PLAYBACK) { | |
5296 | this_pid = hdspm->playback_pid; | |
5297 | other_pid = hdspm->capture_pid; | |
5298 | } else { | |
5299 | this_pid = hdspm->capture_pid; | |
5300 | other_pid = hdspm->playback_pid; | |
5301 | } | |
5302 | ||
ef5fa1a4 | 5303 | if (other_pid > 0 && this_pid != other_pid) { |
763f356c TI |
5304 | |
5305 | /* The other stream is open, and not by the same | |
5306 | task as this one. Make sure that the parameters | |
5307 | that matter are the same. | |
0dca1793 | 5308 | */ |
763f356c TI |
5309 | |
5310 | if (params_rate(params) != hdspm->system_sample_rate) { | |
5311 | spin_unlock_irq(&hdspm->lock); | |
5312 | _snd_pcm_hw_param_setempty(params, | |
0dca1793 | 5313 | SNDRV_PCM_HW_PARAM_RATE); |
763f356c TI |
5314 | return -EBUSY; |
5315 | } | |
5316 | ||
5317 | if (params_period_size(params) != hdspm->period_bytes / 4) { | |
5318 | spin_unlock_irq(&hdspm->lock); | |
5319 | _snd_pcm_hw_param_setempty(params, | |
0dca1793 | 5320 | SNDRV_PCM_HW_PARAM_PERIOD_SIZE); |
763f356c TI |
5321 | return -EBUSY; |
5322 | } | |
5323 | ||
5324 | } | |
5325 | /* We're fine. */ | |
5326 | spin_unlock_irq(&hdspm->lock); | |
5327 | ||
5328 | /* how to make sure that the rate matches an externally-set one ? */ | |
5329 | ||
5330 | spin_lock_irq(&hdspm->lock); | |
ef5fa1a4 TI |
5331 | err = hdspm_set_rate(hdspm, params_rate(params), 0); |
5332 | if (err < 0) { | |
0dca1793 | 5333 | snd_printk(KERN_INFO "err on hdspm_set_rate: %d\n", err); |
763f356c TI |
5334 | spin_unlock_irq(&hdspm->lock); |
5335 | _snd_pcm_hw_param_setempty(params, | |
0dca1793 | 5336 | SNDRV_PCM_HW_PARAM_RATE); |
763f356c TI |
5337 | return err; |
5338 | } | |
5339 | spin_unlock_irq(&hdspm->lock); | |
5340 | ||
ef5fa1a4 | 5341 | err = hdspm_set_interrupt_interval(hdspm, |
0dca1793 | 5342 | params_period_size(params)); |
ef5fa1a4 | 5343 | if (err < 0) { |
0dca1793 | 5344 | snd_printk(KERN_INFO "err on hdspm_set_interrupt_interval: %d\n", err); |
763f356c | 5345 | _snd_pcm_hw_param_setempty(params, |
0dca1793 | 5346 | SNDRV_PCM_HW_PARAM_PERIOD_SIZE); |
763f356c TI |
5347 | return err; |
5348 | } | |
5349 | ||
ef5fa1a4 TI |
5350 | /* Memory allocation, takashi's method, dont know if we should |
5351 | * spinlock | |
5352 | */ | |
763f356c | 5353 | /* malloc all buffer even if not enabled to get sure */ |
ffb2c3c0 RB |
5354 | /* Update for MADI rev 204: we need to allocate for all channels, |
5355 | * otherwise it doesn't work at 96kHz */ | |
0dca1793 | 5356 | |
763f356c | 5357 | err = |
0dca1793 AK |
5358 | snd_pcm_lib_malloc_pages(substream, HDSPM_DMA_AREA_BYTES); |
5359 | if (err < 0) { | |
5360 | snd_printk(KERN_INFO "err on snd_pcm_lib_malloc_pages: %d\n", err); | |
763f356c | 5361 | return err; |
0dca1793 | 5362 | } |
763f356c | 5363 | |
763f356c TI |
5364 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { |
5365 | ||
77a23f26 | 5366 | hdspm_set_sgbuf(hdspm, substream, HDSPM_pageAddressBufferOut, |
763f356c TI |
5367 | params_channels(params)); |
5368 | ||
5369 | for (i = 0; i < params_channels(params); ++i) | |
5370 | snd_hdspm_enable_out(hdspm, i, 1); | |
5371 | ||
5372 | hdspm->playback_buffer = | |
0dca1793 | 5373 | (unsigned char *) substream->runtime->dma_area; |
54bf5dd9 | 5374 | snd_printdd("Allocated sample buffer for playback at %p\n", |
3cee5a60 | 5375 | hdspm->playback_buffer); |
763f356c | 5376 | } else { |
77a23f26 | 5377 | hdspm_set_sgbuf(hdspm, substream, HDSPM_pageAddressBufferIn, |
763f356c TI |
5378 | params_channels(params)); |
5379 | ||
5380 | for (i = 0; i < params_channels(params); ++i) | |
5381 | snd_hdspm_enable_in(hdspm, i, 1); | |
5382 | ||
5383 | hdspm->capture_buffer = | |
0dca1793 | 5384 | (unsigned char *) substream->runtime->dma_area; |
54bf5dd9 | 5385 | snd_printdd("Allocated sample buffer for capture at %p\n", |
3cee5a60 | 5386 | hdspm->capture_buffer); |
763f356c | 5387 | } |
0dca1793 | 5388 | |
3cee5a60 RB |
5389 | /* |
5390 | snd_printdd("Allocated sample buffer for %s at 0x%08X\n", | |
5391 | substream->stream == SNDRV_PCM_STREAM_PLAYBACK ? | |
5392 | "playback" : "capture", | |
77a23f26 | 5393 | snd_pcm_sgbuf_get_addr(substream, 0)); |
0dca1793 | 5394 | */ |
ffb2c3c0 | 5395 | /* |
0dca1793 AK |
5396 | snd_printdd("set_hwparams: %s %d Hz, %d channels, bs = %d\n", |
5397 | substream->stream == SNDRV_PCM_STREAM_PLAYBACK ? | |
5398 | "playback" : "capture", | |
5399 | params_rate(params), params_channels(params), | |
5400 | params_buffer_size(params)); | |
5401 | */ | |
5402 | ||
5403 | ||
5404 | /* Switch to native float format if requested */ | |
5405 | if (SNDRV_PCM_FORMAT_FLOAT_LE == params_format(params)) { | |
5406 | if (!(hdspm->control_register & HDSPe_FLOAT_FORMAT)) | |
5407 | snd_printk(KERN_INFO "hdspm: Switching to native 32bit LE float format.\n"); | |
5408 | ||
5409 | hdspm->control_register |= HDSPe_FLOAT_FORMAT; | |
5410 | } else if (SNDRV_PCM_FORMAT_S32_LE == params_format(params)) { | |
5411 | if (hdspm->control_register & HDSPe_FLOAT_FORMAT) | |
5412 | snd_printk(KERN_INFO "hdspm: Switching to native 32bit LE integer format.\n"); | |
5413 | ||
5414 | hdspm->control_register &= ~HDSPe_FLOAT_FORMAT; | |
5415 | } | |
5416 | hdspm_write(hdspm, HDSPM_controlRegister, hdspm->control_register); | |
5417 | ||
763f356c TI |
5418 | return 0; |
5419 | } | |
5420 | ||
98274f07 | 5421 | static int snd_hdspm_hw_free(struct snd_pcm_substream *substream) |
763f356c TI |
5422 | { |
5423 | int i; | |
98274f07 | 5424 | struct hdspm *hdspm = snd_pcm_substream_chip(substream); |
763f356c TI |
5425 | |
5426 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { | |
5427 | ||
0dca1793 | 5428 | /* params_channels(params) should be enough, |
763f356c | 5429 | but to get sure in case of error */ |
0dca1793 | 5430 | for (i = 0; i < hdspm->max_channels_out; ++i) |
763f356c TI |
5431 | snd_hdspm_enable_out(hdspm, i, 0); |
5432 | ||
5433 | hdspm->playback_buffer = NULL; | |
5434 | } else { | |
0dca1793 | 5435 | for (i = 0; i < hdspm->max_channels_in; ++i) |
763f356c TI |
5436 | snd_hdspm_enable_in(hdspm, i, 0); |
5437 | ||
5438 | hdspm->capture_buffer = NULL; | |
5439 | ||
5440 | } | |
5441 | ||
5442 | snd_pcm_lib_free_pages(substream); | |
5443 | ||
5444 | return 0; | |
5445 | } | |
5446 | ||
0dca1793 | 5447 | |
98274f07 | 5448 | static int snd_hdspm_channel_info(struct snd_pcm_substream *substream, |
0dca1793 | 5449 | struct snd_pcm_channel_info *info) |
763f356c | 5450 | { |
98274f07 | 5451 | struct hdspm *hdspm = snd_pcm_substream_chip(substream); |
763f356c | 5452 | |
0dca1793 AK |
5453 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { |
5454 | if (snd_BUG_ON(info->channel >= hdspm->max_channels_out)) { | |
5455 | snd_printk(KERN_INFO "snd_hdspm_channel_info: output channel out of range (%d)\n", info->channel); | |
5456 | return -EINVAL; | |
5457 | } | |
763f356c | 5458 | |
0dca1793 AK |
5459 | if (hdspm->channel_map_out[info->channel] < 0) { |
5460 | snd_printk(KERN_INFO "snd_hdspm_channel_info: output channel %d mapped out\n", info->channel); | |
5461 | return -EINVAL; | |
5462 | } | |
5463 | ||
5464 | info->offset = hdspm->channel_map_out[info->channel] * | |
5465 | HDSPM_CHANNEL_BUFFER_BYTES; | |
5466 | } else { | |
5467 | if (snd_BUG_ON(info->channel >= hdspm->max_channels_in)) { | |
5468 | snd_printk(KERN_INFO "snd_hdspm_channel_info: input channel out of range (%d)\n", info->channel); | |
5469 | return -EINVAL; | |
5470 | } | |
5471 | ||
5472 | if (hdspm->channel_map_in[info->channel] < 0) { | |
5473 | snd_printk(KERN_INFO "snd_hdspm_channel_info: input channel %d mapped out\n", info->channel); | |
5474 | return -EINVAL; | |
5475 | } | |
5476 | ||
5477 | info->offset = hdspm->channel_map_in[info->channel] * | |
5478 | HDSPM_CHANNEL_BUFFER_BYTES; | |
5479 | } | |
763f356c | 5480 | |
763f356c TI |
5481 | info->first = 0; |
5482 | info->step = 32; | |
5483 | return 0; | |
5484 | } | |
5485 | ||
0dca1793 | 5486 | |
98274f07 | 5487 | static int snd_hdspm_ioctl(struct snd_pcm_substream *substream, |
0dca1793 | 5488 | unsigned int cmd, void *arg) |
763f356c TI |
5489 | { |
5490 | switch (cmd) { | |
5491 | case SNDRV_PCM_IOCTL1_RESET: | |
ef5fa1a4 | 5492 | return snd_hdspm_reset(substream); |
763f356c TI |
5493 | |
5494 | case SNDRV_PCM_IOCTL1_CHANNEL_INFO: | |
0dca1793 AK |
5495 | { |
5496 | struct snd_pcm_channel_info *info = arg; | |
5497 | return snd_hdspm_channel_info(substream, info); | |
5498 | } | |
763f356c TI |
5499 | default: |
5500 | break; | |
5501 | } | |
5502 | ||
5503 | return snd_pcm_lib_ioctl(substream, cmd, arg); | |
5504 | } | |
5505 | ||
98274f07 | 5506 | static int snd_hdspm_trigger(struct snd_pcm_substream *substream, int cmd) |
763f356c | 5507 | { |
98274f07 TI |
5508 | struct hdspm *hdspm = snd_pcm_substream_chip(substream); |
5509 | struct snd_pcm_substream *other; | |
763f356c TI |
5510 | int running; |
5511 | ||
5512 | spin_lock(&hdspm->lock); | |
5513 | running = hdspm->running; | |
5514 | switch (cmd) { | |
5515 | case SNDRV_PCM_TRIGGER_START: | |
5516 | running |= 1 << substream->stream; | |
5517 | break; | |
5518 | case SNDRV_PCM_TRIGGER_STOP: | |
5519 | running &= ~(1 << substream->stream); | |
5520 | break; | |
5521 | default: | |
5522 | snd_BUG(); | |
5523 | spin_unlock(&hdspm->lock); | |
5524 | return -EINVAL; | |
5525 | } | |
5526 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) | |
5527 | other = hdspm->capture_substream; | |
5528 | else | |
5529 | other = hdspm->playback_substream; | |
5530 | ||
5531 | if (other) { | |
98274f07 | 5532 | struct snd_pcm_substream *s; |
ef991b95 | 5533 | snd_pcm_group_for_each_entry(s, substream) { |
763f356c TI |
5534 | if (s == other) { |
5535 | snd_pcm_trigger_done(s, substream); | |
5536 | if (cmd == SNDRV_PCM_TRIGGER_START) | |
5537 | running |= 1 << s->stream; | |
5538 | else | |
5539 | running &= ~(1 << s->stream); | |
5540 | goto _ok; | |
5541 | } | |
5542 | } | |
5543 | if (cmd == SNDRV_PCM_TRIGGER_START) { | |
5544 | if (!(running & (1 << SNDRV_PCM_STREAM_PLAYBACK)) | |
0dca1793 AK |
5545 | && substream->stream == |
5546 | SNDRV_PCM_STREAM_CAPTURE) | |
763f356c TI |
5547 | hdspm_silence_playback(hdspm); |
5548 | } else { | |
5549 | if (running && | |
0dca1793 | 5550 | substream->stream == SNDRV_PCM_STREAM_PLAYBACK) |
763f356c TI |
5551 | hdspm_silence_playback(hdspm); |
5552 | } | |
5553 | } else { | |
5554 | if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) | |
5555 | hdspm_silence_playback(hdspm); | |
5556 | } | |
0dca1793 | 5557 | _ok: |
763f356c TI |
5558 | snd_pcm_trigger_done(substream, substream); |
5559 | if (!hdspm->running && running) | |
5560 | hdspm_start_audio(hdspm); | |
5561 | else if (hdspm->running && !running) | |
5562 | hdspm_stop_audio(hdspm); | |
5563 | hdspm->running = running; | |
5564 | spin_unlock(&hdspm->lock); | |
5565 | ||
5566 | return 0; | |
5567 | } | |
5568 | ||
98274f07 | 5569 | static int snd_hdspm_prepare(struct snd_pcm_substream *substream) |
763f356c TI |
5570 | { |
5571 | return 0; | |
5572 | } | |
5573 | ||
98274f07 | 5574 | static struct snd_pcm_hardware snd_hdspm_playback_subinfo = { |
763f356c TI |
5575 | .info = (SNDRV_PCM_INFO_MMAP | |
5576 | SNDRV_PCM_INFO_MMAP_VALID | | |
5577 | SNDRV_PCM_INFO_NONINTERLEAVED | | |
5578 | SNDRV_PCM_INFO_SYNC_START | SNDRV_PCM_INFO_DOUBLE), | |
5579 | .formats = SNDRV_PCM_FMTBIT_S32_LE, | |
5580 | .rates = (SNDRV_PCM_RATE_32000 | | |
5581 | SNDRV_PCM_RATE_44100 | | |
5582 | SNDRV_PCM_RATE_48000 | | |
5583 | SNDRV_PCM_RATE_64000 | | |
3cee5a60 RB |
5584 | SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000 | |
5585 | SNDRV_PCM_RATE_176400 | SNDRV_PCM_RATE_192000 ), | |
763f356c | 5586 | .rate_min = 32000, |
3cee5a60 | 5587 | .rate_max = 192000, |
763f356c TI |
5588 | .channels_min = 1, |
5589 | .channels_max = HDSPM_MAX_CHANNELS, | |
5590 | .buffer_bytes_max = | |
5591 | HDSPM_CHANNEL_BUFFER_BYTES * HDSPM_MAX_CHANNELS, | |
1b6fa108 | 5592 | .period_bytes_min = (32 * 4), |
52e6fb48 | 5593 | .period_bytes_max = (8192 * 4) * HDSPM_MAX_CHANNELS, |
763f356c | 5594 | .periods_min = 2, |
0dca1793 | 5595 | .periods_max = 512, |
763f356c TI |
5596 | .fifo_size = 0 |
5597 | }; | |
5598 | ||
98274f07 | 5599 | static struct snd_pcm_hardware snd_hdspm_capture_subinfo = { |
763f356c TI |
5600 | .info = (SNDRV_PCM_INFO_MMAP | |
5601 | SNDRV_PCM_INFO_MMAP_VALID | | |
5602 | SNDRV_PCM_INFO_NONINTERLEAVED | | |
5603 | SNDRV_PCM_INFO_SYNC_START), | |
5604 | .formats = SNDRV_PCM_FMTBIT_S32_LE, | |
5605 | .rates = (SNDRV_PCM_RATE_32000 | | |
5606 | SNDRV_PCM_RATE_44100 | | |
5607 | SNDRV_PCM_RATE_48000 | | |
5608 | SNDRV_PCM_RATE_64000 | | |
3cee5a60 RB |
5609 | SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000 | |
5610 | SNDRV_PCM_RATE_176400 | SNDRV_PCM_RATE_192000), | |
763f356c | 5611 | .rate_min = 32000, |
3cee5a60 | 5612 | .rate_max = 192000, |
763f356c TI |
5613 | .channels_min = 1, |
5614 | .channels_max = HDSPM_MAX_CHANNELS, | |
5615 | .buffer_bytes_max = | |
5616 | HDSPM_CHANNEL_BUFFER_BYTES * HDSPM_MAX_CHANNELS, | |
1b6fa108 | 5617 | .period_bytes_min = (32 * 4), |
52e6fb48 | 5618 | .period_bytes_max = (8192 * 4) * HDSPM_MAX_CHANNELS, |
763f356c | 5619 | .periods_min = 2, |
0dca1793 | 5620 | .periods_max = 512, |
763f356c TI |
5621 | .fifo_size = 0 |
5622 | }; | |
5623 | ||
0dca1793 AK |
5624 | static int snd_hdspm_hw_rule_in_channels_rate(struct snd_pcm_hw_params *params, |
5625 | struct snd_pcm_hw_rule *rule) | |
5626 | { | |
5627 | struct hdspm *hdspm = rule->private; | |
5628 | struct snd_interval *c = | |
5629 | hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS); | |
5630 | struct snd_interval *r = | |
5631 | hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE); | |
5632 | ||
5633 | if (r->min > 96000 && r->max <= 192000) { | |
5634 | struct snd_interval t = { | |
5635 | .min = hdspm->qs_in_channels, | |
5636 | .max = hdspm->qs_in_channels, | |
5637 | .integer = 1, | |
5638 | }; | |
5639 | return snd_interval_refine(c, &t); | |
5640 | } else if (r->min > 48000 && r->max <= 96000) { | |
5641 | struct snd_interval t = { | |
5642 | .min = hdspm->ds_in_channels, | |
5643 | .max = hdspm->ds_in_channels, | |
5644 | .integer = 1, | |
5645 | }; | |
5646 | return snd_interval_refine(c, &t); | |
5647 | } else if (r->max < 64000) { | |
5648 | struct snd_interval t = { | |
5649 | .min = hdspm->ss_in_channels, | |
5650 | .max = hdspm->ss_in_channels, | |
5651 | .integer = 1, | |
5652 | }; | |
5653 | return snd_interval_refine(c, &t); | |
5654 | } | |
5655 | ||
5656 | return 0; | |
5657 | } | |
763f356c | 5658 | |
0dca1793 | 5659 | static int snd_hdspm_hw_rule_out_channels_rate(struct snd_pcm_hw_params *params, |
98274f07 | 5660 | struct snd_pcm_hw_rule * rule) |
763f356c | 5661 | { |
98274f07 TI |
5662 | struct hdspm *hdspm = rule->private; |
5663 | struct snd_interval *c = | |
763f356c | 5664 | hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS); |
98274f07 | 5665 | struct snd_interval *r = |
763f356c TI |
5666 | hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE); |
5667 | ||
0dca1793 AK |
5668 | if (r->min > 96000 && r->max <= 192000) { |
5669 | struct snd_interval t = { | |
5670 | .min = hdspm->qs_out_channels, | |
5671 | .max = hdspm->qs_out_channels, | |
5672 | .integer = 1, | |
5673 | }; | |
5674 | return snd_interval_refine(c, &t); | |
5675 | } else if (r->min > 48000 && r->max <= 96000) { | |
98274f07 | 5676 | struct snd_interval t = { |
0dca1793 AK |
5677 | .min = hdspm->ds_out_channels, |
5678 | .max = hdspm->ds_out_channels, | |
763f356c TI |
5679 | .integer = 1, |
5680 | }; | |
5681 | return snd_interval_refine(c, &t); | |
5682 | } else if (r->max < 64000) { | |
98274f07 | 5683 | struct snd_interval t = { |
0dca1793 AK |
5684 | .min = hdspm->ss_out_channels, |
5685 | .max = hdspm->ss_out_channels, | |
763f356c TI |
5686 | .integer = 1, |
5687 | }; | |
5688 | return snd_interval_refine(c, &t); | |
0dca1793 | 5689 | } else { |
763f356c TI |
5690 | } |
5691 | return 0; | |
5692 | } | |
5693 | ||
0dca1793 | 5694 | static int snd_hdspm_hw_rule_rate_in_channels(struct snd_pcm_hw_params *params, |
98274f07 | 5695 | struct snd_pcm_hw_rule * rule) |
763f356c | 5696 | { |
98274f07 TI |
5697 | struct hdspm *hdspm = rule->private; |
5698 | struct snd_interval *c = | |
763f356c | 5699 | hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS); |
98274f07 | 5700 | struct snd_interval *r = |
763f356c TI |
5701 | hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE); |
5702 | ||
0dca1793 | 5703 | if (c->min >= hdspm->ss_in_channels) { |
98274f07 | 5704 | struct snd_interval t = { |
763f356c TI |
5705 | .min = 32000, |
5706 | .max = 48000, | |
5707 | .integer = 1, | |
5708 | }; | |
5709 | return snd_interval_refine(r, &t); | |
0dca1793 AK |
5710 | } else if (c->max <= hdspm->qs_in_channels) { |
5711 | struct snd_interval t = { | |
5712 | .min = 128000, | |
5713 | .max = 192000, | |
5714 | .integer = 1, | |
5715 | }; | |
5716 | return snd_interval_refine(r, &t); | |
5717 | } else if (c->max <= hdspm->ds_in_channels) { | |
98274f07 | 5718 | struct snd_interval t = { |
763f356c TI |
5719 | .min = 64000, |
5720 | .max = 96000, | |
5721 | .integer = 1, | |
5722 | }; | |
0dca1793 AK |
5723 | return snd_interval_refine(r, &t); |
5724 | } | |
5725 | ||
5726 | return 0; | |
5727 | } | |
5728 | static int snd_hdspm_hw_rule_rate_out_channels(struct snd_pcm_hw_params *params, | |
5729 | struct snd_pcm_hw_rule *rule) | |
5730 | { | |
5731 | struct hdspm *hdspm = rule->private; | |
5732 | struct snd_interval *c = | |
5733 | hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS); | |
5734 | struct snd_interval *r = | |
5735 | hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE); | |
763f356c | 5736 | |
0dca1793 AK |
5737 | if (c->min >= hdspm->ss_out_channels) { |
5738 | struct snd_interval t = { | |
5739 | .min = 32000, | |
5740 | .max = 48000, | |
5741 | .integer = 1, | |
5742 | }; | |
5743 | return snd_interval_refine(r, &t); | |
5744 | } else if (c->max <= hdspm->qs_out_channels) { | |
5745 | struct snd_interval t = { | |
5746 | .min = 128000, | |
5747 | .max = 192000, | |
5748 | .integer = 1, | |
5749 | }; | |
5750 | return snd_interval_refine(r, &t); | |
5751 | } else if (c->max <= hdspm->ds_out_channels) { | |
5752 | struct snd_interval t = { | |
5753 | .min = 64000, | |
5754 | .max = 96000, | |
5755 | .integer = 1, | |
5756 | }; | |
763f356c TI |
5757 | return snd_interval_refine(r, &t); |
5758 | } | |
0dca1793 | 5759 | |
763f356c TI |
5760 | return 0; |
5761 | } | |
5762 | ||
0dca1793 | 5763 | static int snd_hdspm_hw_rule_in_channels(struct snd_pcm_hw_params *params, |
ffb2c3c0 RB |
5764 | struct snd_pcm_hw_rule *rule) |
5765 | { | |
5766 | unsigned int list[3]; | |
5767 | struct hdspm *hdspm = rule->private; | |
5768 | struct snd_interval *c = hw_param_interval(params, | |
5769 | SNDRV_PCM_HW_PARAM_CHANNELS); | |
0dca1793 AK |
5770 | |
5771 | list[0] = hdspm->qs_in_channels; | |
5772 | list[1] = hdspm->ds_in_channels; | |
5773 | list[2] = hdspm->ss_in_channels; | |
5774 | return snd_interval_list(c, 3, list, 0); | |
5775 | } | |
5776 | ||
5777 | static int snd_hdspm_hw_rule_out_channels(struct snd_pcm_hw_params *params, | |
5778 | struct snd_pcm_hw_rule *rule) | |
5779 | { | |
5780 | unsigned int list[3]; | |
5781 | struct hdspm *hdspm = rule->private; | |
5782 | struct snd_interval *c = hw_param_interval(params, | |
5783 | SNDRV_PCM_HW_PARAM_CHANNELS); | |
5784 | ||
5785 | list[0] = hdspm->qs_out_channels; | |
5786 | list[1] = hdspm->ds_out_channels; | |
5787 | list[2] = hdspm->ss_out_channels; | |
5788 | return snd_interval_list(c, 3, list, 0); | |
ffb2c3c0 RB |
5789 | } |
5790 | ||
5791 | ||
ef5fa1a4 TI |
5792 | static unsigned int hdspm_aes32_sample_rates[] = { |
5793 | 32000, 44100, 48000, 64000, 88200, 96000, 128000, 176400, 192000 | |
5794 | }; | |
ffb2c3c0 | 5795 | |
ef5fa1a4 TI |
5796 | static struct snd_pcm_hw_constraint_list |
5797 | hdspm_hw_constraints_aes32_sample_rates = { | |
ffb2c3c0 RB |
5798 | .count = ARRAY_SIZE(hdspm_aes32_sample_rates), |
5799 | .list = hdspm_aes32_sample_rates, | |
5800 | .mask = 0 | |
5801 | }; | |
5802 | ||
98274f07 | 5803 | static int snd_hdspm_playback_open(struct snd_pcm_substream *substream) |
763f356c | 5804 | { |
98274f07 TI |
5805 | struct hdspm *hdspm = snd_pcm_substream_chip(substream); |
5806 | struct snd_pcm_runtime *runtime = substream->runtime; | |
763f356c | 5807 | |
763f356c TI |
5808 | spin_lock_irq(&hdspm->lock); |
5809 | ||
5810 | snd_pcm_set_sync(substream); | |
5811 | ||
0dca1793 | 5812 | |
763f356c TI |
5813 | runtime->hw = snd_hdspm_playback_subinfo; |
5814 | ||
5815 | if (hdspm->capture_substream == NULL) | |
5816 | hdspm_stop_audio(hdspm); | |
5817 | ||
5818 | hdspm->playback_pid = current->pid; | |
5819 | hdspm->playback_substream = substream; | |
5820 | ||
5821 | spin_unlock_irq(&hdspm->lock); | |
5822 | ||
5823 | snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24); | |
d877681d | 5824 | snd_pcm_hw_constraint_pow2(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_SIZE); |
763f356c | 5825 | |
0dca1793 AK |
5826 | switch (hdspm->io_type) { |
5827 | case AIO: | |
5828 | case RayDAT: | |
d877681d TI |
5829 | snd_pcm_hw_constraint_minmax(runtime, |
5830 | SNDRV_PCM_HW_PARAM_PERIOD_SIZE, | |
5831 | 32, 4096); | |
5832 | /* RayDAT & AIO have a fixed buffer of 16384 samples per channel */ | |
5833 | snd_pcm_hw_constraint_minmax(runtime, | |
5834 | SNDRV_PCM_HW_PARAM_BUFFER_SIZE, | |
5835 | 16384, 16384); | |
0dca1793 AK |
5836 | break; |
5837 | ||
5838 | default: | |
d877681d TI |
5839 | snd_pcm_hw_constraint_minmax(runtime, |
5840 | SNDRV_PCM_HW_PARAM_PERIOD_SIZE, | |
5841 | 64, 8192); | |
5842 | break; | |
0dca1793 | 5843 | } |
763f356c | 5844 | |
0dca1793 | 5845 | if (AES32 == hdspm->io_type) { |
3fa9e3d2 | 5846 | runtime->hw.rates |= SNDRV_PCM_RATE_KNOT; |
ffb2c3c0 RB |
5847 | snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, |
5848 | &hdspm_hw_constraints_aes32_sample_rates); | |
5849 | } else { | |
ffb2c3c0 | 5850 | snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, |
0dca1793 AK |
5851 | snd_hdspm_hw_rule_rate_out_channels, hdspm, |
5852 | SNDRV_PCM_HW_PARAM_CHANNELS, -1); | |
ffb2c3c0 | 5853 | } |
88fabbfc AK |
5854 | |
5855 | snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS, | |
5856 | snd_hdspm_hw_rule_out_channels, hdspm, | |
5857 | SNDRV_PCM_HW_PARAM_CHANNELS, -1); | |
5858 | ||
5859 | snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS, | |
5860 | snd_hdspm_hw_rule_out_channels_rate, hdspm, | |
5861 | SNDRV_PCM_HW_PARAM_RATE, -1); | |
5862 | ||
763f356c TI |
5863 | return 0; |
5864 | } | |
5865 | ||
98274f07 | 5866 | static int snd_hdspm_playback_release(struct snd_pcm_substream *substream) |
763f356c | 5867 | { |
98274f07 | 5868 | struct hdspm *hdspm = snd_pcm_substream_chip(substream); |
763f356c TI |
5869 | |
5870 | spin_lock_irq(&hdspm->lock); | |
5871 | ||
5872 | hdspm->playback_pid = -1; | |
5873 | hdspm->playback_substream = NULL; | |
5874 | ||
5875 | spin_unlock_irq(&hdspm->lock); | |
5876 | ||
5877 | return 0; | |
5878 | } | |
5879 | ||
5880 | ||
98274f07 | 5881 | static int snd_hdspm_capture_open(struct snd_pcm_substream *substream) |
763f356c | 5882 | { |
98274f07 TI |
5883 | struct hdspm *hdspm = snd_pcm_substream_chip(substream); |
5884 | struct snd_pcm_runtime *runtime = substream->runtime; | |
763f356c TI |
5885 | |
5886 | spin_lock_irq(&hdspm->lock); | |
5887 | snd_pcm_set_sync(substream); | |
5888 | runtime->hw = snd_hdspm_capture_subinfo; | |
5889 | ||
5890 | if (hdspm->playback_substream == NULL) | |
5891 | hdspm_stop_audio(hdspm); | |
5892 | ||
5893 | hdspm->capture_pid = current->pid; | |
5894 | hdspm->capture_substream = substream; | |
5895 | ||
5896 | spin_unlock_irq(&hdspm->lock); | |
5897 | ||
5898 | snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24); | |
d877681d TI |
5899 | snd_pcm_hw_constraint_pow2(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_SIZE); |
5900 | ||
0dca1793 AK |
5901 | switch (hdspm->io_type) { |
5902 | case AIO: | |
5903 | case RayDAT: | |
d877681d TI |
5904 | snd_pcm_hw_constraint_minmax(runtime, |
5905 | SNDRV_PCM_HW_PARAM_PERIOD_SIZE, | |
5906 | 32, 4096); | |
5907 | snd_pcm_hw_constraint_minmax(runtime, | |
5908 | SNDRV_PCM_HW_PARAM_BUFFER_SIZE, | |
5909 | 16384, 16384); | |
5910 | break; | |
0dca1793 AK |
5911 | |
5912 | default: | |
d877681d TI |
5913 | snd_pcm_hw_constraint_minmax(runtime, |
5914 | SNDRV_PCM_HW_PARAM_PERIOD_SIZE, | |
5915 | 64, 8192); | |
5916 | break; | |
0dca1793 AK |
5917 | } |
5918 | ||
5919 | if (AES32 == hdspm->io_type) { | |
3fa9e3d2 | 5920 | runtime->hw.rates |= SNDRV_PCM_RATE_KNOT; |
ffb2c3c0 RB |
5921 | snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, |
5922 | &hdspm_hw_constraints_aes32_sample_rates); | |
5923 | } else { | |
ffb2c3c0 | 5924 | snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, |
88fabbfc AK |
5925 | snd_hdspm_hw_rule_rate_in_channels, hdspm, |
5926 | SNDRV_PCM_HW_PARAM_CHANNELS, -1); | |
ffb2c3c0 | 5927 | } |
88fabbfc AK |
5928 | |
5929 | snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS, | |
5930 | snd_hdspm_hw_rule_in_channels, hdspm, | |
5931 | SNDRV_PCM_HW_PARAM_CHANNELS, -1); | |
5932 | ||
5933 | snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS, | |
5934 | snd_hdspm_hw_rule_in_channels_rate, hdspm, | |
5935 | SNDRV_PCM_HW_PARAM_RATE, -1); | |
5936 | ||
763f356c TI |
5937 | return 0; |
5938 | } | |
5939 | ||
98274f07 | 5940 | static int snd_hdspm_capture_release(struct snd_pcm_substream *substream) |
763f356c | 5941 | { |
98274f07 | 5942 | struct hdspm *hdspm = snd_pcm_substream_chip(substream); |
763f356c TI |
5943 | |
5944 | spin_lock_irq(&hdspm->lock); | |
5945 | ||
5946 | hdspm->capture_pid = -1; | |
5947 | hdspm->capture_substream = NULL; | |
5948 | ||
5949 | spin_unlock_irq(&hdspm->lock); | |
5950 | return 0; | |
5951 | } | |
5952 | ||
0dca1793 AK |
5953 | static int snd_hdspm_hwdep_dummy_op(struct snd_hwdep *hw, struct file *file) |
5954 | { | |
5955 | /* we have nothing to initialize but the call is required */ | |
5956 | return 0; | |
5957 | } | |
5958 | ||
5959 | static inline int copy_u32_le(void __user *dest, void __iomem *src) | |
5960 | { | |
5961 | u32 val = readl(src); | |
5962 | return copy_to_user(dest, &val, 4); | |
5963 | } | |
5964 | ||
5965 | static int snd_hdspm_hwdep_ioctl(struct snd_hwdep *hw, struct file *file, | |
2ca595ab | 5966 | unsigned int cmd, unsigned long arg) |
763f356c | 5967 | { |
0dca1793 | 5968 | void __user *argp = (void __user *)arg; |
ef5fa1a4 | 5969 | struct hdspm *hdspm = hw->private_data; |
98274f07 | 5970 | struct hdspm_mixer_ioctl mixer; |
0dca1793 AK |
5971 | struct hdspm_config info; |
5972 | struct hdspm_status status; | |
98274f07 | 5973 | struct hdspm_version hdspm_version; |
730a5865 | 5974 | struct hdspm_peak_rms *levels; |
0dca1793 AK |
5975 | struct hdspm_ltc ltc; |
5976 | unsigned int statusregister; | |
5977 | long unsigned int s; | |
5978 | int i = 0; | |
763f356c TI |
5979 | |
5980 | switch (cmd) { | |
5981 | ||
763f356c | 5982 | case SNDRV_HDSPM_IOCTL_GET_PEAK_RMS: |
730a5865 | 5983 | levels = &hdspm->peak_rms; |
0dca1793 | 5984 | for (i = 0; i < HDSPM_MAX_CHANNELS; i++) { |
730a5865 | 5985 | levels->input_peaks[i] = |
0dca1793 AK |
5986 | readl(hdspm->iobase + |
5987 | HDSPM_MADI_INPUT_PEAK + i*4); | |
730a5865 | 5988 | levels->playback_peaks[i] = |
0dca1793 AK |
5989 | readl(hdspm->iobase + |
5990 | HDSPM_MADI_PLAYBACK_PEAK + i*4); | |
730a5865 | 5991 | levels->output_peaks[i] = |
0dca1793 AK |
5992 | readl(hdspm->iobase + |
5993 | HDSPM_MADI_OUTPUT_PEAK + i*4); | |
5994 | ||
730a5865 | 5995 | levels->input_rms[i] = |
0dca1793 AK |
5996 | ((uint64_t) readl(hdspm->iobase + |
5997 | HDSPM_MADI_INPUT_RMS_H + i*4) << 32) | | |
5998 | (uint64_t) readl(hdspm->iobase + | |
5999 | HDSPM_MADI_INPUT_RMS_L + i*4); | |
730a5865 | 6000 | levels->playback_rms[i] = |
0dca1793 AK |
6001 | ((uint64_t)readl(hdspm->iobase + |
6002 | HDSPM_MADI_PLAYBACK_RMS_H+i*4) << 32) | | |
6003 | (uint64_t)readl(hdspm->iobase + | |
6004 | HDSPM_MADI_PLAYBACK_RMS_L + i*4); | |
730a5865 | 6005 | levels->output_rms[i] = |
0dca1793 AK |
6006 | ((uint64_t)readl(hdspm->iobase + |
6007 | HDSPM_MADI_OUTPUT_RMS_H + i*4) << 32) | | |
6008 | (uint64_t)readl(hdspm->iobase + | |
6009 | HDSPM_MADI_OUTPUT_RMS_L + i*4); | |
6010 | } | |
6011 | ||
6012 | if (hdspm->system_sample_rate > 96000) { | |
730a5865 | 6013 | levels->speed = qs; |
0dca1793 | 6014 | } else if (hdspm->system_sample_rate > 48000) { |
730a5865 | 6015 | levels->speed = ds; |
0dca1793 | 6016 | } else { |
730a5865 | 6017 | levels->speed = ss; |
0dca1793 | 6018 | } |
730a5865 | 6019 | levels->status2 = hdspm_read(hdspm, HDSPM_statusRegister2); |
0dca1793 | 6020 | |
730a5865 | 6021 | s = copy_to_user(argp, levels, sizeof(struct hdspm_peak_rms)); |
0dca1793 AK |
6022 | if (0 != s) { |
6023 | /* snd_printk(KERN_ERR "copy_to_user(.., .., %lu): %lu | |
6024 | [Levels]\n", sizeof(struct hdspm_peak_rms), s); | |
6025 | */ | |
763f356c | 6026 | return -EFAULT; |
0dca1793 AK |
6027 | } |
6028 | break; | |
6029 | ||
6030 | case SNDRV_HDSPM_IOCTL_GET_LTC: | |
6031 | ltc.ltc = hdspm_read(hdspm, HDSPM_RD_TCO); | |
6032 | i = hdspm_read(hdspm, HDSPM_RD_TCO + 4); | |
6033 | if (i & HDSPM_TCO1_LTC_Input_valid) { | |
6034 | switch (i & (HDSPM_TCO1_LTC_Format_LSB | | |
6035 | HDSPM_TCO1_LTC_Format_MSB)) { | |
6036 | case 0: | |
6037 | ltc.format = fps_24; | |
6038 | break; | |
6039 | case HDSPM_TCO1_LTC_Format_LSB: | |
6040 | ltc.format = fps_25; | |
6041 | break; | |
6042 | case HDSPM_TCO1_LTC_Format_MSB: | |
6043 | ltc.format = fps_2997; | |
6044 | break; | |
6045 | default: | |
6046 | ltc.format = 30; | |
6047 | break; | |
6048 | } | |
6049 | if (i & HDSPM_TCO1_set_drop_frame_flag) { | |
6050 | ltc.frame = drop_frame; | |
6051 | } else { | |
6052 | ltc.frame = full_frame; | |
6053 | } | |
6054 | } else { | |
6055 | ltc.format = format_invalid; | |
6056 | ltc.frame = frame_invalid; | |
6057 | } | |
6058 | if (i & HDSPM_TCO1_Video_Input_Format_NTSC) { | |
6059 | ltc.input_format = ntsc; | |
6060 | } else if (i & HDSPM_TCO1_Video_Input_Format_PAL) { | |
6061 | ltc.input_format = pal; | |
6062 | } else { | |
6063 | ltc.input_format = no_video; | |
6064 | } | |
6065 | ||
6066 | s = copy_to_user(argp, <c, sizeof(struct hdspm_ltc)); | |
6067 | if (0 != s) { | |
6068 | /* | |
6069 | snd_printk(KERN_ERR "copy_to_user(.., .., %lu): %lu [LTC]\n", sizeof(struct hdspm_ltc), s); */ | |
763f356c | 6070 | return -EFAULT; |
0dca1793 | 6071 | } |
763f356c TI |
6072 | |
6073 | break; | |
763f356c | 6074 | |
0dca1793 | 6075 | case SNDRV_HDSPM_IOCTL_GET_CONFIG: |
763f356c | 6076 | |
4ab69a2b | 6077 | memset(&info, 0, sizeof(info)); |
763f356c | 6078 | spin_lock_irq(&hdspm->lock); |
ef5fa1a4 TI |
6079 | info.pref_sync_ref = hdspm_pref_sync_ref(hdspm); |
6080 | info.wordclock_sync_check = hdspm_wc_sync_check(hdspm); | |
763f356c TI |
6081 | |
6082 | info.system_sample_rate = hdspm->system_sample_rate; | |
6083 | info.autosync_sample_rate = | |
0dca1793 | 6084 | hdspm_external_sample_rate(hdspm); |
ef5fa1a4 TI |
6085 | info.system_clock_mode = hdspm_system_clock_mode(hdspm); |
6086 | info.clock_source = hdspm_clock_source(hdspm); | |
6087 | info.autosync_ref = hdspm_autosync_ref(hdspm); | |
c9e1668c | 6088 | info.line_out = hdspm_toggle_setting(hdspm, HDSPM_LineOut); |
763f356c TI |
6089 | info.passthru = 0; |
6090 | spin_unlock_irq(&hdspm->lock); | |
2ca595ab | 6091 | if (copy_to_user(argp, &info, sizeof(info))) |
763f356c TI |
6092 | return -EFAULT; |
6093 | break; | |
6094 | ||
0dca1793 | 6095 | case SNDRV_HDSPM_IOCTL_GET_STATUS: |
643d6bbb DC |
6096 | memset(&status, 0, sizeof(status)); |
6097 | ||
0dca1793 AK |
6098 | status.card_type = hdspm->io_type; |
6099 | ||
6100 | status.autosync_source = hdspm_autosync_ref(hdspm); | |
6101 | ||
6102 | status.card_clock = 110069313433624ULL; | |
6103 | status.master_period = hdspm_read(hdspm, HDSPM_RD_PLL_FREQ); | |
6104 | ||
6105 | switch (hdspm->io_type) { | |
6106 | case MADI: | |
6107 | case MADIface: | |
6108 | status.card_specific.madi.sync_wc = | |
6109 | hdspm_wc_sync_check(hdspm); | |
6110 | status.card_specific.madi.sync_madi = | |
6111 | hdspm_madi_sync_check(hdspm); | |
6112 | status.card_specific.madi.sync_tco = | |
6113 | hdspm_tco_sync_check(hdspm); | |
6114 | status.card_specific.madi.sync_in = | |
6115 | hdspm_sync_in_sync_check(hdspm); | |
6116 | ||
6117 | statusregister = | |
6118 | hdspm_read(hdspm, HDSPM_statusRegister); | |
6119 | status.card_specific.madi.madi_input = | |
6120 | (statusregister & HDSPM_AB_int) ? 1 : 0; | |
6121 | status.card_specific.madi.channel_format = | |
9e6ff520 | 6122 | (statusregister & HDSPM_RX_64ch) ? 1 : 0; |
0dca1793 AK |
6123 | /* TODO: Mac driver sets it when f_s>48kHz */ |
6124 | status.card_specific.madi.frame_format = 0; | |
6125 | ||
6126 | default: | |
6127 | break; | |
6128 | } | |
6129 | ||
2ca595ab | 6130 | if (copy_to_user(argp, &status, sizeof(status))) |
0dca1793 AK |
6131 | return -EFAULT; |
6132 | ||
6133 | ||
6134 | break; | |
6135 | ||
763f356c | 6136 | case SNDRV_HDSPM_IOCTL_GET_VERSION: |
643d6bbb DC |
6137 | memset(&hdspm_version, 0, sizeof(hdspm_version)); |
6138 | ||
0dca1793 AK |
6139 | hdspm_version.card_type = hdspm->io_type; |
6140 | strncpy(hdspm_version.cardname, hdspm->card_name, | |
6141 | sizeof(hdspm_version.cardname)); | |
7d53a631 | 6142 | hdspm_version.serial = hdspm->serial; |
763f356c | 6143 | hdspm_version.firmware_rev = hdspm->firmware_rev; |
0dca1793 AK |
6144 | hdspm_version.addons = 0; |
6145 | if (hdspm->tco) | |
6146 | hdspm_version.addons |= HDSPM_ADDON_TCO; | |
6147 | ||
2ca595ab | 6148 | if (copy_to_user(argp, &hdspm_version, |
0dca1793 | 6149 | sizeof(hdspm_version))) |
763f356c TI |
6150 | return -EFAULT; |
6151 | break; | |
6152 | ||
6153 | case SNDRV_HDSPM_IOCTL_GET_MIXER: | |
2ca595ab | 6154 | if (copy_from_user(&mixer, argp, sizeof(mixer))) |
763f356c | 6155 | return -EFAULT; |
ef5fa1a4 | 6156 | if (copy_to_user((void __user *)mixer.mixer, hdspm->mixer, |
0dca1793 | 6157 | sizeof(struct hdspm_mixer))) |
763f356c TI |
6158 | return -EFAULT; |
6159 | break; | |
6160 | ||
6161 | default: | |
6162 | return -EINVAL; | |
6163 | } | |
6164 | return 0; | |
6165 | } | |
6166 | ||
98274f07 | 6167 | static struct snd_pcm_ops snd_hdspm_playback_ops = { |
763f356c TI |
6168 | .open = snd_hdspm_playback_open, |
6169 | .close = snd_hdspm_playback_release, | |
6170 | .ioctl = snd_hdspm_ioctl, | |
6171 | .hw_params = snd_hdspm_hw_params, | |
6172 | .hw_free = snd_hdspm_hw_free, | |
6173 | .prepare = snd_hdspm_prepare, | |
6174 | .trigger = snd_hdspm_trigger, | |
6175 | .pointer = snd_hdspm_hw_pointer, | |
763f356c TI |
6176 | .page = snd_pcm_sgbuf_ops_page, |
6177 | }; | |
6178 | ||
98274f07 | 6179 | static struct snd_pcm_ops snd_hdspm_capture_ops = { |
763f356c TI |
6180 | .open = snd_hdspm_capture_open, |
6181 | .close = snd_hdspm_capture_release, | |
6182 | .ioctl = snd_hdspm_ioctl, | |
6183 | .hw_params = snd_hdspm_hw_params, | |
6184 | .hw_free = snd_hdspm_hw_free, | |
6185 | .prepare = snd_hdspm_prepare, | |
6186 | .trigger = snd_hdspm_trigger, | |
6187 | .pointer = snd_hdspm_hw_pointer, | |
763f356c TI |
6188 | .page = snd_pcm_sgbuf_ops_page, |
6189 | }; | |
6190 | ||
e23e7a14 BP |
6191 | static int snd_hdspm_create_hwdep(struct snd_card *card, |
6192 | struct hdspm *hdspm) | |
763f356c | 6193 | { |
98274f07 | 6194 | struct snd_hwdep *hw; |
763f356c TI |
6195 | int err; |
6196 | ||
ef5fa1a4 TI |
6197 | err = snd_hwdep_new(card, "HDSPM hwdep", 0, &hw); |
6198 | if (err < 0) | |
763f356c TI |
6199 | return err; |
6200 | ||
6201 | hdspm->hwdep = hw; | |
6202 | hw->private_data = hdspm; | |
6203 | strcpy(hw->name, "HDSPM hwdep interface"); | |
6204 | ||
0dca1793 | 6205 | hw->ops.open = snd_hdspm_hwdep_dummy_op; |
763f356c | 6206 | hw->ops.ioctl = snd_hdspm_hwdep_ioctl; |
8de5d6f1 | 6207 | hw->ops.ioctl_compat = snd_hdspm_hwdep_ioctl; |
0dca1793 | 6208 | hw->ops.release = snd_hdspm_hwdep_dummy_op; |
763f356c TI |
6209 | |
6210 | return 0; | |
6211 | } | |
6212 | ||
6213 | ||
6214 | /*------------------------------------------------------------ | |
0dca1793 | 6215 | memory interface |
763f356c | 6216 | ------------------------------------------------------------*/ |
e23e7a14 | 6217 | static int snd_hdspm_preallocate_memory(struct hdspm *hdspm) |
763f356c TI |
6218 | { |
6219 | int err; | |
98274f07 | 6220 | struct snd_pcm *pcm; |
763f356c TI |
6221 | size_t wanted; |
6222 | ||
6223 | pcm = hdspm->pcm; | |
6224 | ||
3cee5a60 | 6225 | wanted = HDSPM_DMA_AREA_BYTES; |
763f356c | 6226 | |
ef5fa1a4 | 6227 | err = |
763f356c | 6228 | snd_pcm_lib_preallocate_pages_for_all(pcm, |
0dca1793 | 6229 | SNDRV_DMA_TYPE_DEV_SG, |
763f356c TI |
6230 | snd_dma_pci_data(hdspm->pci), |
6231 | wanted, | |
ef5fa1a4 TI |
6232 | wanted); |
6233 | if (err < 0) { | |
e2eba3e7 | 6234 | snd_printdd("Could not preallocate %zd Bytes\n", wanted); |
763f356c TI |
6235 | |
6236 | return err; | |
6237 | } else | |
e2eba3e7 | 6238 | snd_printdd(" Preallocated %zd Bytes\n", wanted); |
763f356c TI |
6239 | |
6240 | return 0; | |
6241 | } | |
6242 | ||
0dca1793 AK |
6243 | |
6244 | static void hdspm_set_sgbuf(struct hdspm *hdspm, | |
77a23f26 | 6245 | struct snd_pcm_substream *substream, |
763f356c TI |
6246 | unsigned int reg, int channels) |
6247 | { | |
6248 | int i; | |
0dca1793 AK |
6249 | |
6250 | /* continuous memory segment */ | |
763f356c TI |
6251 | for (i = 0; i < (channels * 16); i++) |
6252 | hdspm_write(hdspm, reg + 4 * i, | |
0dca1793 | 6253 | snd_pcm_sgbuf_get_addr(substream, 4096 * i)); |
763f356c TI |
6254 | } |
6255 | ||
0dca1793 | 6256 | |
763f356c | 6257 | /* ------------- ALSA Devices ---------------------------- */ |
e23e7a14 BP |
6258 | static int snd_hdspm_create_pcm(struct snd_card *card, |
6259 | struct hdspm *hdspm) | |
763f356c | 6260 | { |
98274f07 | 6261 | struct snd_pcm *pcm; |
763f356c TI |
6262 | int err; |
6263 | ||
ef5fa1a4 TI |
6264 | err = snd_pcm_new(card, hdspm->card_name, 0, 1, 1, &pcm); |
6265 | if (err < 0) | |
763f356c TI |
6266 | return err; |
6267 | ||
6268 | hdspm->pcm = pcm; | |
6269 | pcm->private_data = hdspm; | |
6270 | strcpy(pcm->name, hdspm->card_name); | |
6271 | ||
6272 | snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, | |
6273 | &snd_hdspm_playback_ops); | |
6274 | snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, | |
6275 | &snd_hdspm_capture_ops); | |
6276 | ||
6277 | pcm->info_flags = SNDRV_PCM_INFO_JOINT_DUPLEX; | |
6278 | ||
ef5fa1a4 TI |
6279 | err = snd_hdspm_preallocate_memory(hdspm); |
6280 | if (err < 0) | |
763f356c TI |
6281 | return err; |
6282 | ||
6283 | return 0; | |
6284 | } | |
6285 | ||
98274f07 | 6286 | static inline void snd_hdspm_initialize_midi_flush(struct hdspm * hdspm) |
763f356c | 6287 | { |
7c7102b7 AK |
6288 | int i; |
6289 | ||
6290 | for (i = 0; i < hdspm->midiPorts; i++) | |
6291 | snd_hdspm_flush_midi_input(hdspm, i); | |
763f356c TI |
6292 | } |
6293 | ||
e23e7a14 BP |
6294 | static int snd_hdspm_create_alsa_devices(struct snd_card *card, |
6295 | struct hdspm *hdspm) | |
763f356c | 6296 | { |
0dca1793 | 6297 | int err, i; |
763f356c TI |
6298 | |
6299 | snd_printdd("Create card...\n"); | |
ef5fa1a4 TI |
6300 | err = snd_hdspm_create_pcm(card, hdspm); |
6301 | if (err < 0) | |
763f356c TI |
6302 | return err; |
6303 | ||
0dca1793 AK |
6304 | i = 0; |
6305 | while (i < hdspm->midiPorts) { | |
6306 | err = snd_hdspm_create_midi(card, hdspm, i); | |
6307 | if (err < 0) { | |
6308 | return err; | |
6309 | } | |
6310 | i++; | |
6311 | } | |
763f356c | 6312 | |
ef5fa1a4 TI |
6313 | err = snd_hdspm_create_controls(card, hdspm); |
6314 | if (err < 0) | |
763f356c TI |
6315 | return err; |
6316 | ||
ef5fa1a4 TI |
6317 | err = snd_hdspm_create_hwdep(card, hdspm); |
6318 | if (err < 0) | |
763f356c TI |
6319 | return err; |
6320 | ||
6321 | snd_printdd("proc init...\n"); | |
6322 | snd_hdspm_proc_init(hdspm); | |
6323 | ||
6324 | hdspm->system_sample_rate = -1; | |
6325 | hdspm->last_external_sample_rate = -1; | |
6326 | hdspm->last_internal_sample_rate = -1; | |
6327 | hdspm->playback_pid = -1; | |
6328 | hdspm->capture_pid = -1; | |
6329 | hdspm->capture_substream = NULL; | |
6330 | hdspm->playback_substream = NULL; | |
6331 | ||
6332 | snd_printdd("Set defaults...\n"); | |
ef5fa1a4 TI |
6333 | err = snd_hdspm_set_defaults(hdspm); |
6334 | if (err < 0) | |
763f356c TI |
6335 | return err; |
6336 | ||
6337 | snd_printdd("Update mixer controls...\n"); | |
6338 | hdspm_update_simple_mixer_controls(hdspm); | |
6339 | ||
6340 | snd_printdd("Initializeing complete ???\n"); | |
6341 | ||
ef5fa1a4 TI |
6342 | err = snd_card_register(card); |
6343 | if (err < 0) { | |
763f356c TI |
6344 | snd_printk(KERN_ERR "HDSPM: error registering card\n"); |
6345 | return err; | |
6346 | } | |
6347 | ||
6348 | snd_printdd("... yes now\n"); | |
6349 | ||
6350 | return 0; | |
6351 | } | |
6352 | ||
e23e7a14 BP |
6353 | static int snd_hdspm_create(struct snd_card *card, |
6354 | struct hdspm *hdspm) | |
6355 | { | |
0dca1793 | 6356 | |
763f356c TI |
6357 | struct pci_dev *pci = hdspm->pci; |
6358 | int err; | |
763f356c TI |
6359 | unsigned long io_extent; |
6360 | ||
6361 | hdspm->irq = -1; | |
763f356c TI |
6362 | hdspm->card = card; |
6363 | ||
6364 | spin_lock_init(&hdspm->lock); | |
6365 | ||
763f356c | 6366 | pci_read_config_word(hdspm->pci, |
0dca1793 | 6367 | PCI_CLASS_REVISION, &hdspm->firmware_rev); |
3cee5a60 | 6368 | |
763f356c | 6369 | strcpy(card->mixername, "Xilinx FPGA"); |
0dca1793 AK |
6370 | strcpy(card->driver, "HDSPM"); |
6371 | ||
6372 | switch (hdspm->firmware_rev) { | |
0dca1793 AK |
6373 | case HDSPM_RAYDAT_REV: |
6374 | hdspm->io_type = RayDAT; | |
6375 | hdspm->card_name = "RME RayDAT"; | |
6376 | hdspm->midiPorts = 2; | |
6377 | break; | |
6378 | case HDSPM_AIO_REV: | |
6379 | hdspm->io_type = AIO; | |
6380 | hdspm->card_name = "RME AIO"; | |
6381 | hdspm->midiPorts = 1; | |
6382 | break; | |
6383 | case HDSPM_MADIFACE_REV: | |
6384 | hdspm->io_type = MADIface; | |
6385 | hdspm->card_name = "RME MADIface"; | |
6386 | hdspm->midiPorts = 1; | |
6387 | break; | |
5027f347 | 6388 | default: |
c09403dc AK |
6389 | if ((hdspm->firmware_rev == 0xf0) || |
6390 | ((hdspm->firmware_rev >= 0xe6) && | |
6391 | (hdspm->firmware_rev <= 0xea))) { | |
6392 | hdspm->io_type = AES32; | |
6393 | hdspm->card_name = "RME AES32"; | |
6394 | hdspm->midiPorts = 2; | |
05c7cc9c | 6395 | } else if ((hdspm->firmware_rev == 0xd2) || |
c09403dc AK |
6396 | ((hdspm->firmware_rev >= 0xc8) && |
6397 | (hdspm->firmware_rev <= 0xcf))) { | |
6398 | hdspm->io_type = MADI; | |
6399 | hdspm->card_name = "RME MADI"; | |
6400 | hdspm->midiPorts = 3; | |
6401 | } else { | |
6402 | snd_printk(KERN_ERR | |
6403 | "HDSPM: unknown firmware revision %x\n", | |
5027f347 | 6404 | hdspm->firmware_rev); |
c09403dc AK |
6405 | return -ENODEV; |
6406 | } | |
3cee5a60 | 6407 | } |
763f356c | 6408 | |
ef5fa1a4 TI |
6409 | err = pci_enable_device(pci); |
6410 | if (err < 0) | |
763f356c TI |
6411 | return err; |
6412 | ||
6413 | pci_set_master(hdspm->pci); | |
6414 | ||
ef5fa1a4 TI |
6415 | err = pci_request_regions(pci, "hdspm"); |
6416 | if (err < 0) | |
763f356c TI |
6417 | return err; |
6418 | ||
6419 | hdspm->port = pci_resource_start(pci, 0); | |
6420 | io_extent = pci_resource_len(pci, 0); | |
6421 | ||
6422 | snd_printdd("grabbed memory region 0x%lx-0x%lx\n", | |
0dca1793 | 6423 | hdspm->port, hdspm->port + io_extent - 1); |
763f356c | 6424 | |
ef5fa1a4 TI |
6425 | hdspm->iobase = ioremap_nocache(hdspm->port, io_extent); |
6426 | if (!hdspm->iobase) { | |
6427 | snd_printk(KERN_ERR "HDSPM: " | |
0dca1793 AK |
6428 | "unable to remap region 0x%lx-0x%lx\n", |
6429 | hdspm->port, hdspm->port + io_extent - 1); | |
763f356c TI |
6430 | return -EBUSY; |
6431 | } | |
6432 | snd_printdd("remapped region (0x%lx) 0x%lx-0x%lx\n", | |
0dca1793 AK |
6433 | (unsigned long)hdspm->iobase, hdspm->port, |
6434 | hdspm->port + io_extent - 1); | |
763f356c TI |
6435 | |
6436 | if (request_irq(pci->irq, snd_hdspm_interrupt, | |
934c2b6d | 6437 | IRQF_SHARED, KBUILD_MODNAME, hdspm)) { |
763f356c TI |
6438 | snd_printk(KERN_ERR "HDSPM: unable to use IRQ %d\n", pci->irq); |
6439 | return -EBUSY; | |
6440 | } | |
6441 | ||
6442 | snd_printdd("use IRQ %d\n", pci->irq); | |
6443 | ||
6444 | hdspm->irq = pci->irq; | |
763f356c | 6445 | |
e2eba3e7 | 6446 | snd_printdd("kmalloc Mixer memory of %zd Bytes\n", |
0dca1793 | 6447 | sizeof(struct hdspm_mixer)); |
ef5fa1a4 TI |
6448 | hdspm->mixer = kzalloc(sizeof(struct hdspm_mixer), GFP_KERNEL); |
6449 | if (!hdspm->mixer) { | |
6450 | snd_printk(KERN_ERR "HDSPM: " | |
0dca1793 AK |
6451 | "unable to kmalloc Mixer memory of %d Bytes\n", |
6452 | (int)sizeof(struct hdspm_mixer)); | |
b17cbdd8 | 6453 | return -ENOMEM; |
763f356c TI |
6454 | } |
6455 | ||
0dca1793 AK |
6456 | hdspm->port_names_in = NULL; |
6457 | hdspm->port_names_out = NULL; | |
6458 | ||
6459 | switch (hdspm->io_type) { | |
6460 | case AES32: | |
d2d10a21 AK |
6461 | hdspm->ss_in_channels = hdspm->ss_out_channels = AES32_CHANNELS; |
6462 | hdspm->ds_in_channels = hdspm->ds_out_channels = AES32_CHANNELS; | |
6463 | hdspm->qs_in_channels = hdspm->qs_out_channels = AES32_CHANNELS; | |
432d2500 AK |
6464 | |
6465 | hdspm->channel_map_in_ss = hdspm->channel_map_out_ss = | |
6466 | channel_map_aes32; | |
6467 | hdspm->channel_map_in_ds = hdspm->channel_map_out_ds = | |
6468 | channel_map_aes32; | |
6469 | hdspm->channel_map_in_qs = hdspm->channel_map_out_qs = | |
6470 | channel_map_aes32; | |
6471 | hdspm->port_names_in_ss = hdspm->port_names_out_ss = | |
6472 | texts_ports_aes32; | |
6473 | hdspm->port_names_in_ds = hdspm->port_names_out_ds = | |
6474 | texts_ports_aes32; | |
6475 | hdspm->port_names_in_qs = hdspm->port_names_out_qs = | |
6476 | texts_ports_aes32; | |
6477 | ||
d2d10a21 AK |
6478 | hdspm->max_channels_out = hdspm->max_channels_in = |
6479 | AES32_CHANNELS; | |
432d2500 AK |
6480 | hdspm->port_names_in = hdspm->port_names_out = |
6481 | texts_ports_aes32; | |
6482 | hdspm->channel_map_in = hdspm->channel_map_out = | |
6483 | channel_map_aes32; | |
6484 | ||
0dca1793 AK |
6485 | break; |
6486 | ||
6487 | case MADI: | |
6488 | case MADIface: | |
6489 | hdspm->ss_in_channels = hdspm->ss_out_channels = | |
6490 | MADI_SS_CHANNELS; | |
6491 | hdspm->ds_in_channels = hdspm->ds_out_channels = | |
6492 | MADI_DS_CHANNELS; | |
6493 | hdspm->qs_in_channels = hdspm->qs_out_channels = | |
6494 | MADI_QS_CHANNELS; | |
6495 | ||
6496 | hdspm->channel_map_in_ss = hdspm->channel_map_out_ss = | |
6497 | channel_map_unity_ss; | |
01e96078 | 6498 | hdspm->channel_map_in_ds = hdspm->channel_map_out_ds = |
0dca1793 | 6499 | channel_map_unity_ss; |
01e96078 | 6500 | hdspm->channel_map_in_qs = hdspm->channel_map_out_qs = |
0dca1793 AK |
6501 | channel_map_unity_ss; |
6502 | ||
6503 | hdspm->port_names_in_ss = hdspm->port_names_out_ss = | |
6504 | texts_ports_madi; | |
6505 | hdspm->port_names_in_ds = hdspm->port_names_out_ds = | |
6506 | texts_ports_madi; | |
6507 | hdspm->port_names_in_qs = hdspm->port_names_out_qs = | |
6508 | texts_ports_madi; | |
6509 | break; | |
6510 | ||
6511 | case AIO: | |
6512 | if (0 == (hdspm_read(hdspm, HDSPM_statusRegister2) & HDSPM_s2_AEBI_D)) { | |
6513 | snd_printk(KERN_INFO "HDSPM: AEB input board found, but not supported\n"); | |
6514 | } | |
6515 | ||
6516 | hdspm->ss_in_channels = AIO_IN_SS_CHANNELS; | |
6517 | hdspm->ds_in_channels = AIO_IN_DS_CHANNELS; | |
6518 | hdspm->qs_in_channels = AIO_IN_QS_CHANNELS; | |
6519 | hdspm->ss_out_channels = AIO_OUT_SS_CHANNELS; | |
6520 | hdspm->ds_out_channels = AIO_OUT_DS_CHANNELS; | |
6521 | hdspm->qs_out_channels = AIO_OUT_QS_CHANNELS; | |
6522 | ||
6523 | hdspm->channel_map_out_ss = channel_map_aio_out_ss; | |
6524 | hdspm->channel_map_out_ds = channel_map_aio_out_ds; | |
6525 | hdspm->channel_map_out_qs = channel_map_aio_out_qs; | |
6526 | ||
6527 | hdspm->channel_map_in_ss = channel_map_aio_in_ss; | |
6528 | hdspm->channel_map_in_ds = channel_map_aio_in_ds; | |
6529 | hdspm->channel_map_in_qs = channel_map_aio_in_qs; | |
6530 | ||
6531 | hdspm->port_names_in_ss = texts_ports_aio_in_ss; | |
6532 | hdspm->port_names_out_ss = texts_ports_aio_out_ss; | |
6533 | hdspm->port_names_in_ds = texts_ports_aio_in_ds; | |
6534 | hdspm->port_names_out_ds = texts_ports_aio_out_ds; | |
6535 | hdspm->port_names_in_qs = texts_ports_aio_in_qs; | |
6536 | hdspm->port_names_out_qs = texts_ports_aio_out_qs; | |
6537 | ||
6538 | break; | |
6539 | ||
6540 | case RayDAT: | |
6541 | hdspm->ss_in_channels = hdspm->ss_out_channels = | |
6542 | RAYDAT_SS_CHANNELS; | |
6543 | hdspm->ds_in_channels = hdspm->ds_out_channels = | |
6544 | RAYDAT_DS_CHANNELS; | |
6545 | hdspm->qs_in_channels = hdspm->qs_out_channels = | |
6546 | RAYDAT_QS_CHANNELS; | |
6547 | ||
6548 | hdspm->max_channels_in = RAYDAT_SS_CHANNELS; | |
6549 | hdspm->max_channels_out = RAYDAT_SS_CHANNELS; | |
6550 | ||
6551 | hdspm->channel_map_in_ss = hdspm->channel_map_out_ss = | |
6552 | channel_map_raydat_ss; | |
6553 | hdspm->channel_map_in_ds = hdspm->channel_map_out_ds = | |
6554 | channel_map_raydat_ds; | |
6555 | hdspm->channel_map_in_qs = hdspm->channel_map_out_qs = | |
6556 | channel_map_raydat_qs; | |
6557 | hdspm->channel_map_in = hdspm->channel_map_out = | |
6558 | channel_map_raydat_ss; | |
6559 | ||
6560 | hdspm->port_names_in_ss = hdspm->port_names_out_ss = | |
6561 | texts_ports_raydat_ss; | |
6562 | hdspm->port_names_in_ds = hdspm->port_names_out_ds = | |
6563 | texts_ports_raydat_ds; | |
6564 | hdspm->port_names_in_qs = hdspm->port_names_out_qs = | |
6565 | texts_ports_raydat_qs; | |
6566 | ||
6567 | ||
6568 | break; | |
6569 | ||
6570 | } | |
6571 | ||
6572 | /* TCO detection */ | |
6573 | switch (hdspm->io_type) { | |
6574 | case AIO: | |
6575 | case RayDAT: | |
6576 | if (hdspm_read(hdspm, HDSPM_statusRegister2) & | |
6577 | HDSPM_s2_tco_detect) { | |
6578 | hdspm->midiPorts++; | |
6579 | hdspm->tco = kzalloc(sizeof(struct hdspm_tco), | |
6580 | GFP_KERNEL); | |
6581 | if (NULL != hdspm->tco) { | |
6582 | hdspm_tco_write(hdspm); | |
6583 | } | |
6584 | snd_printk(KERN_INFO "HDSPM: AIO/RayDAT TCO module found\n"); | |
6585 | } else { | |
6586 | hdspm->tco = NULL; | |
6587 | } | |
6588 | break; | |
6589 | ||
6590 | case MADI: | |
6591 | if (hdspm_read(hdspm, HDSPM_statusRegister) & HDSPM_tco_detect) { | |
6592 | hdspm->midiPorts++; | |
6593 | hdspm->tco = kzalloc(sizeof(struct hdspm_tco), | |
6594 | GFP_KERNEL); | |
6595 | if (NULL != hdspm->tco) { | |
6596 | hdspm_tco_write(hdspm); | |
6597 | } | |
6598 | snd_printk(KERN_INFO "HDSPM: MADI TCO module found\n"); | |
6599 | } else { | |
6600 | hdspm->tco = NULL; | |
6601 | } | |
6602 | break; | |
6603 | ||
6604 | default: | |
6605 | hdspm->tco = NULL; | |
6606 | } | |
6607 | ||
6608 | /* texts */ | |
6609 | switch (hdspm->io_type) { | |
6610 | case AES32: | |
6611 | if (hdspm->tco) { | |
6612 | hdspm->texts_autosync = texts_autosync_aes_tco; | |
6613 | hdspm->texts_autosync_items = 10; | |
6614 | } else { | |
6615 | hdspm->texts_autosync = texts_autosync_aes; | |
6616 | hdspm->texts_autosync_items = 9; | |
6617 | } | |
6618 | break; | |
6619 | ||
6620 | case MADI: | |
6621 | if (hdspm->tco) { | |
6622 | hdspm->texts_autosync = texts_autosync_madi_tco; | |
6623 | hdspm->texts_autosync_items = 4; | |
6624 | } else { | |
6625 | hdspm->texts_autosync = texts_autosync_madi; | |
6626 | hdspm->texts_autosync_items = 3; | |
6627 | } | |
6628 | break; | |
6629 | ||
6630 | case MADIface: | |
6631 | ||
6632 | break; | |
6633 | ||
6634 | case RayDAT: | |
6635 | if (hdspm->tco) { | |
6636 | hdspm->texts_autosync = texts_autosync_raydat_tco; | |
6637 | hdspm->texts_autosync_items = 9; | |
6638 | } else { | |
6639 | hdspm->texts_autosync = texts_autosync_raydat; | |
6640 | hdspm->texts_autosync_items = 8; | |
6641 | } | |
6642 | break; | |
6643 | ||
6644 | case AIO: | |
6645 | if (hdspm->tco) { | |
6646 | hdspm->texts_autosync = texts_autosync_aio_tco; | |
6647 | hdspm->texts_autosync_items = 6; | |
6648 | } else { | |
6649 | hdspm->texts_autosync = texts_autosync_aio; | |
6650 | hdspm->texts_autosync_items = 5; | |
6651 | } | |
6652 | break; | |
6653 | ||
6654 | } | |
6655 | ||
6656 | tasklet_init(&hdspm->midi_tasklet, | |
6657 | hdspm_midi_tasklet, (unsigned long) hdspm); | |
763f356c | 6658 | |
f7de8ba3 AK |
6659 | |
6660 | if (hdspm->io_type != MADIface) { | |
6661 | hdspm->serial = (hdspm_read(hdspm, | |
6662 | HDSPM_midiStatusIn0)>>8) & 0xFFFFFF; | |
6663 | /* id contains either a user-provided value or the default | |
6664 | * NULL. If it's the default, we're safe to | |
6665 | * fill card->id with the serial number. | |
6666 | * | |
6667 | * If the serial number is 0xFFFFFF, then we're dealing with | |
6668 | * an old PCI revision that comes without a sane number. In | |
6669 | * this case, we don't set card->id to avoid collisions | |
6670 | * when running with multiple cards. | |
6671 | */ | |
6672 | if (NULL == id[hdspm->dev] && hdspm->serial != 0xFFFFFF) { | |
6673 | sprintf(card->id, "HDSPMx%06x", hdspm->serial); | |
6674 | snd_card_set_id(card, card->id); | |
6675 | } | |
6676 | } | |
6677 | ||
763f356c | 6678 | snd_printdd("create alsa devices.\n"); |
ef5fa1a4 TI |
6679 | err = snd_hdspm_create_alsa_devices(card, hdspm); |
6680 | if (err < 0) | |
763f356c TI |
6681 | return err; |
6682 | ||
6683 | snd_hdspm_initialize_midi_flush(hdspm); | |
6684 | ||
6685 | return 0; | |
6686 | } | |
6687 | ||
0dca1793 | 6688 | |
98274f07 | 6689 | static int snd_hdspm_free(struct hdspm * hdspm) |
763f356c TI |
6690 | { |
6691 | ||
6692 | if (hdspm->port) { | |
6693 | ||
6694 | /* stop th audio, and cancel all interrupts */ | |
6695 | hdspm->control_register &= | |
ef5fa1a4 | 6696 | ~(HDSPM_Start | HDSPM_AudioInterruptEnable | |
0dca1793 AK |
6697 | HDSPM_Midi0InterruptEnable | HDSPM_Midi1InterruptEnable | |
6698 | HDSPM_Midi2InterruptEnable | HDSPM_Midi3InterruptEnable); | |
763f356c TI |
6699 | hdspm_write(hdspm, HDSPM_controlRegister, |
6700 | hdspm->control_register); | |
6701 | } | |
6702 | ||
6703 | if (hdspm->irq >= 0) | |
6704 | free_irq(hdspm->irq, (void *) hdspm); | |
6705 | ||
fc58422a | 6706 | kfree(hdspm->mixer); |
763f356c TI |
6707 | |
6708 | if (hdspm->iobase) | |
6709 | iounmap(hdspm->iobase); | |
6710 | ||
763f356c TI |
6711 | if (hdspm->port) |
6712 | pci_release_regions(hdspm->pci); | |
6713 | ||
6714 | pci_disable_device(hdspm->pci); | |
6715 | return 0; | |
6716 | } | |
6717 | ||
0dca1793 | 6718 | |
98274f07 | 6719 | static void snd_hdspm_card_free(struct snd_card *card) |
763f356c | 6720 | { |
ef5fa1a4 | 6721 | struct hdspm *hdspm = card->private_data; |
763f356c TI |
6722 | |
6723 | if (hdspm) | |
6724 | snd_hdspm_free(hdspm); | |
6725 | } | |
6726 | ||
0dca1793 | 6727 | |
e23e7a14 BP |
6728 | static int snd_hdspm_probe(struct pci_dev *pci, |
6729 | const struct pci_device_id *pci_id) | |
763f356c TI |
6730 | { |
6731 | static int dev; | |
98274f07 TI |
6732 | struct hdspm *hdspm; |
6733 | struct snd_card *card; | |
763f356c TI |
6734 | int err; |
6735 | ||
6736 | if (dev >= SNDRV_CARDS) | |
6737 | return -ENODEV; | |
6738 | if (!enable[dev]) { | |
6739 | dev++; | |
6740 | return -ENOENT; | |
6741 | } | |
6742 | ||
e58de7ba | 6743 | err = snd_card_create(index[dev], id[dev], |
0dca1793 | 6744 | THIS_MODULE, sizeof(struct hdspm), &card); |
e58de7ba TI |
6745 | if (err < 0) |
6746 | return err; | |
763f356c | 6747 | |
ef5fa1a4 | 6748 | hdspm = card->private_data; |
763f356c TI |
6749 | card->private_free = snd_hdspm_card_free; |
6750 | hdspm->dev = dev; | |
6751 | hdspm->pci = pci; | |
6752 | ||
c187c041 TI |
6753 | snd_card_set_dev(card, &pci->dev); |
6754 | ||
0dca1793 | 6755 | err = snd_hdspm_create(card, hdspm); |
ef5fa1a4 | 6756 | if (err < 0) { |
763f356c TI |
6757 | snd_card_free(card); |
6758 | return err; | |
6759 | } | |
6760 | ||
0dca1793 AK |
6761 | if (hdspm->io_type != MADIface) { |
6762 | sprintf(card->shortname, "%s_%x", | |
6763 | hdspm->card_name, | |
7d53a631 | 6764 | hdspm->serial); |
0dca1793 AK |
6765 | sprintf(card->longname, "%s S/N 0x%x at 0x%lx, irq %d", |
6766 | hdspm->card_name, | |
7d53a631 | 6767 | hdspm->serial, |
0dca1793 AK |
6768 | hdspm->port, hdspm->irq); |
6769 | } else { | |
6770 | sprintf(card->shortname, "%s", hdspm->card_name); | |
6771 | sprintf(card->longname, "%s at 0x%lx, irq %d", | |
6772 | hdspm->card_name, hdspm->port, hdspm->irq); | |
6773 | } | |
763f356c | 6774 | |
ef5fa1a4 TI |
6775 | err = snd_card_register(card); |
6776 | if (err < 0) { | |
763f356c TI |
6777 | snd_card_free(card); |
6778 | return err; | |
6779 | } | |
6780 | ||
6781 | pci_set_drvdata(pci, card); | |
6782 | ||
6783 | dev++; | |
6784 | return 0; | |
6785 | } | |
6786 | ||
e23e7a14 | 6787 | static void snd_hdspm_remove(struct pci_dev *pci) |
763f356c TI |
6788 | { |
6789 | snd_card_free(pci_get_drvdata(pci)); | |
763f356c TI |
6790 | } |
6791 | ||
e9f66d9b | 6792 | static struct pci_driver hdspm_driver = { |
3733e424 | 6793 | .name = KBUILD_MODNAME, |
763f356c TI |
6794 | .id_table = snd_hdspm_ids, |
6795 | .probe = snd_hdspm_probe, | |
e23e7a14 | 6796 | .remove = snd_hdspm_remove, |
763f356c TI |
6797 | }; |
6798 | ||
e9f66d9b | 6799 | module_pci_driver(hdspm_driver); |