blob: ea49ffe4d9ab4795e028576e0723e104ff499eec [file] [log] [blame]
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02001/*
Takashi Iwai763f3562005-06-03 11:25:34 +02002 * 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
Remy Bruno3cee5a62006-10-16 12:46:32 +02008 * Modified 2006-06-01 for AES32 support by Remy Bruno
9 * <remy.bruno@trinnov.com>
Takashi Iwai763f3562005-06-03 11:25:34 +020010 *
Adrian Knoth0dca1792011-01-26 19:32:14 +010011 * 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 *
Takashi Iwai763f3562005-06-03 11:25:34 +020026 * 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 */
Takashi Iwai763f3562005-06-03 11:25:34 +020041#include <linux/init.h>
42#include <linux/delay.h>
43#include <linux/interrupt.h>
44#include <linux/moduleparam.h>
45#include <linux/slab.h>
46#include <linux/pci.h>
Takashi Iwai3f7440a2009-06-05 17:40:04 +020047#include <linux/math64.h>
Takashi Iwai763f3562005-06-03 11:25:34 +020048#include <asm/io.h>
49
50#include <sound/core.h>
51#include <sound/control.h>
52#include <sound/pcm.h>
Adrian Knoth0dca1792011-01-26 19:32:14 +010053#include <sound/pcm_params.h>
Takashi Iwai763f3562005-06-03 11:25:34 +020054#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
62static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
63static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
64static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;/* Enable this card */
65
Takashi Iwai763f3562005-06-03 11:25:34 +020066module_param_array(index, int, NULL, 0444);
67MODULE_PARM_DESC(index, "Index value for RME HDSPM interface.");
68
69module_param_array(id, charp, NULL, 0444);
70MODULE_PARM_DESC(id, "ID string for RME HDSPM interface.");
71
72module_param_array(enable, bool, NULL, 0444);
73MODULE_PARM_DESC(enable, "Enable/disable specific HDSPM soundcards.");
74
Takashi Iwai763f3562005-06-03 11:25:34 +020075
76MODULE_AUTHOR
Adrian Knoth0dca1792011-01-26 19:32:14 +010077(
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);
Takashi Iwai763f3562005-06-03 11:25:34 +020085MODULE_DESCRIPTION("RME HDSPM");
86MODULE_LICENSE("GPL");
87MODULE_SUPPORTED_DEVICE("{{RME HDSPM-MADI}}");
88
Adrian Knoth0dca1792011-01-26 19:32:14 +010089/* --- Write registers. ---
Takashi Iwai763f3562005-06-03 11:25:34 +020090 These are defined as byte-offsets from the iobase value. */
91
Adrian Knoth0dca1792011-01-26 19:32:14 +010092#define HDSPM_WR_SETTINGS 0
93#define HDSPM_outputBufferAddress 32
94#define HDSPM_inputBufferAddress 36
Takashi Iwai763f3562005-06-03 11:25:34 +020095#define HDSPM_controlRegister 64
96#define HDSPM_interruptConfirmation 96
97#define HDSPM_control2Reg 256 /* not in specs ???????? */
Remy Brunoffb2c3c2007-03-07 19:08:46 +010098#define HDSPM_freqReg 256 /* for AES32 */
Adrian Knoth0dca1792011-01-26 19:32:14 +010099#define HDSPM_midiDataOut0 352 /* just believe in old code */
100#define HDSPM_midiDataOut1 356
Remy Brunoffb2c3c2007-03-07 19:08:46 +0100101#define HDSPM_eeprom_wr 384 /* for AES32 */
Takashi Iwai763f3562005-06-03 11:25:34 +0200102
103/* DMA enable for 64 channels, only Bit 0 is relevant */
Adrian Knoth0dca1792011-01-26 19:32:14 +0100104#define HDSPM_outputEnableBase 512 /* 512-767 input DMA */
Takashi Iwai763f3562005-06-03 11:25:34 +0200105#define HDSPM_inputEnableBase 768 /* 768-1023 output DMA */
106
Adrian Knoth0dca1792011-01-26 19:32:14 +0100107/* 16 page addresses for each of the 64 channels DMA buffer in and out
Takashi Iwai763f3562005-06-03 11:25:34 +0200108 (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
Remy Bruno3cee5a62006-10-16 12:46:32 +0200119/*#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
Takashi Iwai763f3562005-06-03 11:25:34 +0200125
Adrian Knoth0dca1792011-01-26 19:32:14 +0100126/* 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
Takashi Iwai763f3562005-06-03 11:25:34 +0200171#define HDSPM_midiDataIn0 360
172#define HDSPM_midiDataIn1 364
Adrian Knoth0dca1792011-01-26 19:32:14 +0100173#define HDSPM_midiDataIn2 372
174#define HDSPM_midiDataIn3 376
Takashi Iwai763f3562005-06-03 11:25:34 +0200175
176/* status is data bytes in MIDI-FIFO (0-128) */
Adrian Knoth0dca1792011-01-26 19:32:14 +0100177#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
Takashi Iwai763f3562005-06-03 11:25:34 +0200185
186
187/* the meters are regular i/o-mapped registers, but offset
188 considerably from the rest. the peak registers are reset
Adrian Knoth0dca1792011-01-26 19:32:14 +0100189 when read; the least-significant 4 bits are full-scale counters;
Takashi Iwai763f3562005-06-03 11:25:34 +0200190 the actual peak value is in the most-significant 24 bits.
191*/
Adrian Knoth0dca1792011-01-26 19:32:14 +0100192
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
Takashi Iwai763f3562005-06-03 11:25:34 +0200204
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
Adrian Knoth0dca1792011-01-26 19:32:14 +0100212#define HDSPM_ClockModeMaster (1<<4) /* 1=Master, 0=Autosync */
213#define HDSPM_c0Master 0x1 /* Master clock bit in settings
214 register [RayDAT, AIO] */
Takashi Iwai763f3562005-06-03 11:25:34 +0200215
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 */
Remy Bruno3cee5a62006-10-16 12:46:32 +0200221#define HDSPM_QuadSpeed (1<<31) /* quad speed bit */
Takashi Iwai763f3562005-06-03 11:25:34 +0200222
Remy Bruno3cee5a62006-10-16 12:46:32 +0200223#define HDSPM_Professional (1<<9) /* Professional */ /* AES32 ONLY */
Takashi Iwai763f3562005-06-03 11:25:34 +0200224#define HDSPM_TX_64ch (1<<10) /* Output 64channel MODE=1,
Remy Bruno3cee5a62006-10-16 12:46:32 +0200225 56channelMODE=0 */ /* MADI ONLY*/
226#define HDSPM_Emphasis (1<<10) /* Emphasis */ /* AES32 ONLY */
Takashi Iwai763f3562005-06-03 11:25:34 +0200227
Adrian Knoth0dca1792011-01-26 19:32:14 +0100228#define HDSPM_AutoInp (1<<11) /* Auto Input (takeover) == Safe Mode,
Remy Bruno3cee5a62006-10-16 12:46:32 +0200229 0=off, 1=on */ /* MADI ONLY */
230#define HDSPM_Dolby (1<<11) /* Dolby = "NonAudio" ?? */ /* AES32 ONLY */
Takashi Iwai763f3562005-06-03 11:25:34 +0200231
Takashi Iwaief5fa1a2007-07-27 16:52:46 +0200232#define HDSPM_InputSelect0 (1<<14) /* Input select 0= optical, 1=coax
233 * -- MADI ONLY
234 */
Takashi Iwai763f3562005-06-03 11:25:34 +0200235#define HDSPM_InputSelect1 (1<<15) /* should be 0 */
236
Remy Bruno3cee5a62006-10-16 12:46:32 +0200237#define HDSPM_SyncRef2 (1<<13)
238#define HDSPM_SyncRef3 (1<<25)
Takashi Iwai763f3562005-06-03 11:25:34 +0200239
Remy Bruno3cee5a62006-10-16 12:46:32 +0200240#define HDSPM_SMUX (1<<18) /* Frame ??? */ /* MADI ONY */
Adrian Knoth0dca1792011-01-26 19:32:14 +0100241#define HDSPM_clr_tms (1<<19) /* clear track marker, do not use
Takashi Iwai763f3562005-06-03 11:25:34 +0200242 AES additional bits in
243 lower 5 Audiodatabits ??? */
Remy Bruno3cee5a62006-10-16 12:46:32 +0200244#define HDSPM_taxi_reset (1<<20) /* ??? */ /* MADI ONLY ? */
245#define HDSPM_WCK48 (1<<20) /* Frame ??? = HDSPM_SMUX */ /* AES32 ONLY */
Takashi Iwai763f3562005-06-03 11:25:34 +0200246
Adrian Knoth0dca1792011-01-26 19:32:14 +0100247#define HDSPM_Midi0InterruptEnable 0x0400000
248#define HDSPM_Midi1InterruptEnable 0x0800000
249#define HDSPM_Midi2InterruptEnable 0x0200000
250#define HDSPM_Midi3InterruptEnable 0x4000000
Takashi Iwai763f3562005-06-03 11:25:34 +0200251
252#define HDSPM_LineOut (1<<24) /* Analog Out on channel 63/64 on=1, mute=0 */
Adrian Knoth0dca1792011-01-26 19:32:14 +0100253#define HDSPe_FLOAT_FORMAT 0x2000000
Takashi Iwai763f3562005-06-03 11:25:34 +0200254
Remy Bruno3cee5a62006-10-16 12:46:32 +0200255#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)
Takashi Iwai763f3562005-06-03 11:25:34 +0200260
261/* --- bit helper defines */
262#define HDSPM_LatencyMask (HDSPM_Latency0|HDSPM_Latency1|HDSPM_Latency2)
Takashi Iwaief5fa1a2007-07-27 16:52:46 +0200263#define HDSPM_FrequencyMask (HDSPM_Frequency0|HDSPM_Frequency1|\
264 HDSPM_DoubleSpeed|HDSPM_QuadSpeed)
Takashi Iwai763f3562005-06-03 11:25:34 +0200265#define HDSPM_InputMask (HDSPM_InputSelect0|HDSPM_InputSelect1)
266#define HDSPM_InputOptical 0
267#define HDSPM_InputCoaxial (HDSPM_InputSelect0)
Takashi Iwaief5fa1a2007-07-27 16:52:46 +0200268#define HDSPM_SyncRefMask (HDSPM_SyncRef0|HDSPM_SyncRef1|\
269 HDSPM_SyncRef2|HDSPM_SyncRef3)
Takashi Iwai763f3562005-06-03 11:25:34 +0200270
Adrian Knoth0dca1792011-01-26 19:32:14 +0100271#define HDSPM_c0_SyncRef0 0x2
272#define HDSPM_c0_SyncRef1 0x4
273#define HDSPM_c0_SyncRef2 0x8
274#define HDSPM_c0_SyncRef3 0x10
275#define HDSPM_c0_SyncRefMask (HDSPM_c0_SyncRef0 | HDSPM_c0_SyncRef1 |\
276 HDSPM_c0_SyncRef2 | HDSPM_c0_SyncRef3)
277
278#define HDSPM_SYNC_FROM_WORD 0 /* Preferred sync reference */
279#define HDSPM_SYNC_FROM_MADI 1 /* choices - used by "pref_sync_ref" */
280#define HDSPM_SYNC_FROM_TCO 2
281#define HDSPM_SYNC_FROM_SYNC_IN 3
Takashi Iwai763f3562005-06-03 11:25:34 +0200282
283#define HDSPM_Frequency32KHz HDSPM_Frequency0
284#define HDSPM_Frequency44_1KHz HDSPM_Frequency1
285#define HDSPM_Frequency48KHz (HDSPM_Frequency1|HDSPM_Frequency0)
286#define HDSPM_Frequency64KHz (HDSPM_DoubleSpeed|HDSPM_Frequency0)
287#define HDSPM_Frequency88_2KHz (HDSPM_DoubleSpeed|HDSPM_Frequency1)
Takashi Iwaief5fa1a2007-07-27 16:52:46 +0200288#define HDSPM_Frequency96KHz (HDSPM_DoubleSpeed|HDSPM_Frequency1|\
289 HDSPM_Frequency0)
Remy Bruno3cee5a62006-10-16 12:46:32 +0200290#define HDSPM_Frequency128KHz (HDSPM_QuadSpeed|HDSPM_Frequency0)
291#define HDSPM_Frequency176_4KHz (HDSPM_QuadSpeed|HDSPM_Frequency1)
Takashi Iwaief5fa1a2007-07-27 16:52:46 +0200292#define HDSPM_Frequency192KHz (HDSPM_QuadSpeed|HDSPM_Frequency1|\
293 HDSPM_Frequency0)
Takashi Iwai763f3562005-06-03 11:25:34 +0200294
Takashi Iwai763f3562005-06-03 11:25:34 +0200295
296/* Synccheck Status */
297#define HDSPM_SYNC_CHECK_NO_LOCK 0
298#define HDSPM_SYNC_CHECK_LOCK 1
299#define HDSPM_SYNC_CHECK_SYNC 2
300
301/* AutoSync References - used by "autosync_ref" control switch */
302#define HDSPM_AUTOSYNC_FROM_WORD 0
303#define HDSPM_AUTOSYNC_FROM_MADI 1
Adrian Knoth0dca1792011-01-26 19:32:14 +0100304#define HDSPM_AUTOSYNC_FROM_TCO 2
305#define HDSPM_AUTOSYNC_FROM_SYNC_IN 3
306#define HDSPM_AUTOSYNC_FROM_NONE 4
Takashi Iwai763f3562005-06-03 11:25:34 +0200307
308/* Possible sources of MADI input */
309#define HDSPM_OPTICAL 0 /* optical */
310#define HDSPM_COAXIAL 1 /* BNC */
311
312#define hdspm_encode_latency(x) (((x)<<1) & HDSPM_LatencyMask)
Adrian Knoth0dca1792011-01-26 19:32:14 +0100313#define hdspm_decode_latency(x) ((((x) & HDSPM_LatencyMask)>>1))
Takashi Iwai763f3562005-06-03 11:25:34 +0200314
315#define hdspm_encode_in(x) (((x)&0x3)<<14)
316#define hdspm_decode_in(x) (((x)>>14)&0x3)
317
318/* --- control2 register bits --- */
319#define HDSPM_TMS (1<<0)
320#define HDSPM_TCK (1<<1)
321#define HDSPM_TDI (1<<2)
322#define HDSPM_JTAG (1<<3)
323#define HDSPM_PWDN (1<<4)
324#define HDSPM_PROGRAM (1<<5)
325#define HDSPM_CONFIG_MODE_0 (1<<6)
326#define HDSPM_CONFIG_MODE_1 (1<<7)
327/*#define HDSPM_VERSION_BIT (1<<8) not defined any more*/
328#define HDSPM_BIGENDIAN_MODE (1<<9)
329#define HDSPM_RD_MULTIPLE (1<<10)
330
Remy Bruno3cee5a62006-10-16 12:46:32 +0200331/* --- Status Register bits --- */ /* MADI ONLY */ /* Bits defined here and
Takashi Iwaief5fa1a2007-07-27 16:52:46 +0200332 that do not conflict with specific bits for AES32 seem to be valid also
333 for the AES32
334 */
Takashi Iwai763f3562005-06-03 11:25:34 +0200335#define HDSPM_audioIRQPending (1<<0) /* IRQ is high and pending */
Takashi Iwaief5fa1a2007-07-27 16:52:46 +0200336#define HDSPM_RX_64ch (1<<1) /* Input 64chan. MODE=1, 56chn MODE=0 */
337#define HDSPM_AB_int (1<<2) /* InputChannel Opt=0, Coax=1
338 * (like inp0)
339 */
Adrian Knoth0dca1792011-01-26 19:32:14 +0100340
Takashi Iwai763f3562005-06-03 11:25:34 +0200341#define HDSPM_madiLock (1<<3) /* MADI Locked =1, no=0 */
Adrian Knoth0dca1792011-01-26 19:32:14 +0100342#define HDSPM_madiSync (1<<18) /* MADI is in sync */
343
344#define HDSPM_tcoLock 0x00000020 /* Optional TCO locked status FOR HDSPe MADI! */
345#define HDSPM_tcoSync 0x10000000 /* Optional TCO sync status */
346
347#define HDSPM_syncInLock 0x00010000 /* Sync In lock status FOR HDSPe MADI! */
348#define HDSPM_syncInSync 0x00020000 /* Sync In sync status FOR HDSPe MADI! */
Takashi Iwai763f3562005-06-03 11:25:34 +0200349
350#define HDSPM_BufferPositionMask 0x000FFC0 /* Bit 6..15 : h/w buffer pointer */
Adrian Knoth0dca1792011-01-26 19:32:14 +0100351 /* since 64byte accurate, last 6 bits are not used */
Takashi Iwai763f3562005-06-03 11:25:34 +0200352
Adrian Knoth0dca1792011-01-26 19:32:14 +0100353
354
Takashi Iwai763f3562005-06-03 11:25:34 +0200355#define HDSPM_DoubleSpeedStatus (1<<19) /* (input) card in double speed */
356
357#define HDSPM_madiFreq0 (1<<22) /* system freq 0=error */
358#define HDSPM_madiFreq1 (1<<23) /* 1=32, 2=44.1 3=48 */
359#define HDSPM_madiFreq2 (1<<24) /* 4=64, 5=88.2 6=96 */
360#define HDSPM_madiFreq3 (1<<25) /* 7=128, 8=176.4 9=192 */
361
Takashi Iwaief5fa1a2007-07-27 16:52:46 +0200362#define HDSPM_BufferID (1<<26) /* (Double)Buffer ID toggles with
363 * Interrupt
364 */
Adrian Knoth0dca1792011-01-26 19:32:14 +0100365#define HDSPM_tco_detect 0x08000000
366#define HDSPM_tco_lock 0x20000000
367
368#define HDSPM_s2_tco_detect 0x00000040
369#define HDSPM_s2_AEBO_D 0x00000080
370#define HDSPM_s2_AEBI_D 0x00000100
371
372
373#define HDSPM_midi0IRQPending 0x40000000
374#define HDSPM_midi1IRQPending 0x80000000
375#define HDSPM_midi2IRQPending 0x20000000
376#define HDSPM_midi2IRQPendingAES 0x00000020
377#define HDSPM_midi3IRQPending 0x00200000
Takashi Iwai763f3562005-06-03 11:25:34 +0200378
379/* --- status bit helpers */
Takashi Iwaief5fa1a2007-07-27 16:52:46 +0200380#define HDSPM_madiFreqMask (HDSPM_madiFreq0|HDSPM_madiFreq1|\
381 HDSPM_madiFreq2|HDSPM_madiFreq3)
Takashi Iwai763f3562005-06-03 11:25:34 +0200382#define HDSPM_madiFreq32 (HDSPM_madiFreq0)
383#define HDSPM_madiFreq44_1 (HDSPM_madiFreq1)
384#define HDSPM_madiFreq48 (HDSPM_madiFreq0|HDSPM_madiFreq1)
385#define HDSPM_madiFreq64 (HDSPM_madiFreq2)
386#define HDSPM_madiFreq88_2 (HDSPM_madiFreq0|HDSPM_madiFreq2)
387#define HDSPM_madiFreq96 (HDSPM_madiFreq1|HDSPM_madiFreq2)
388#define HDSPM_madiFreq128 (HDSPM_madiFreq0|HDSPM_madiFreq1|HDSPM_madiFreq2)
389#define HDSPM_madiFreq176_4 (HDSPM_madiFreq3)
390#define HDSPM_madiFreq192 (HDSPM_madiFreq3|HDSPM_madiFreq0)
391
Remy Bruno3cee5a62006-10-16 12:46:32 +0200392/* Status2 Register bits */ /* MADI ONLY */
Takashi Iwai763f3562005-06-03 11:25:34 +0200393
394#define HDSPM_version0 (1<<0) /* not realy defined but I guess */
395#define HDSPM_version1 (1<<1) /* in former cards it was ??? */
396#define HDSPM_version2 (1<<2)
397
398#define HDSPM_wcLock (1<<3) /* Wordclock is detected and locked */
399#define HDSPM_wcSync (1<<4) /* Wordclock is in sync with systemclock */
400
401#define HDSPM_wc_freq0 (1<<5) /* input freq detected via autosync */
402#define HDSPM_wc_freq1 (1<<6) /* 001=32, 010==44.1, 011=48, */
403#define HDSPM_wc_freq2 (1<<7) /* 100=64, 101=88.2, 110=96, */
404/* missing Bit for 111=128, 1000=176.4, 1001=192 */
405
Adrian Knoth0dca1792011-01-26 19:32:14 +0100406#define HDSPM_SyncRef0 0x10000 /* Sync Reference */
407#define HDSPM_SyncRef1 0x20000
408
409#define HDSPM_SelSyncRef0 (1<<8) /* AutoSync Source */
Takashi Iwai763f3562005-06-03 11:25:34 +0200410#define HDSPM_SelSyncRef1 (1<<9) /* 000=word, 001=MADI, */
411#define HDSPM_SelSyncRef2 (1<<10) /* 111=no valid signal */
412
413#define HDSPM_wc_valid (HDSPM_wcLock|HDSPM_wcSync)
414
415#define HDSPM_wcFreqMask (HDSPM_wc_freq0|HDSPM_wc_freq1|HDSPM_wc_freq2)
416#define HDSPM_wcFreq32 (HDSPM_wc_freq0)
417#define HDSPM_wcFreq44_1 (HDSPM_wc_freq1)
418#define HDSPM_wcFreq48 (HDSPM_wc_freq0|HDSPM_wc_freq1)
419#define HDSPM_wcFreq64 (HDSPM_wc_freq2)
420#define HDSPM_wcFreq88_2 (HDSPM_wc_freq0|HDSPM_wc_freq2)
421#define HDSPM_wcFreq96 (HDSPM_wc_freq1|HDSPM_wc_freq2)
422
Adrian Knoth0dca1792011-01-26 19:32:14 +0100423#define HDSPM_status1_F_0 0x0400000
424#define HDSPM_status1_F_1 0x0800000
425#define HDSPM_status1_F_2 0x1000000
426#define HDSPM_status1_F_3 0x2000000
427#define HDSPM_status1_freqMask (HDSPM_status1_F_0|HDSPM_status1_F_1|HDSPM_status1_F_2|HDSPM_status1_F_3)
428
Takashi Iwai763f3562005-06-03 11:25:34 +0200429
Takashi Iwaief5fa1a2007-07-27 16:52:46 +0200430#define HDSPM_SelSyncRefMask (HDSPM_SelSyncRef0|HDSPM_SelSyncRef1|\
431 HDSPM_SelSyncRef2)
Takashi Iwai763f3562005-06-03 11:25:34 +0200432#define HDSPM_SelSyncRef_WORD 0
433#define HDSPM_SelSyncRef_MADI (HDSPM_SelSyncRef0)
Adrian Knoth0dca1792011-01-26 19:32:14 +0100434#define HDSPM_SelSyncRef_TCO (HDSPM_SelSyncRef1)
435#define HDSPM_SelSyncRef_SyncIn (HDSPM_SelSyncRef0|HDSPM_SelSyncRef1)
Takashi Iwaief5fa1a2007-07-27 16:52:46 +0200436#define HDSPM_SelSyncRef_NVALID (HDSPM_SelSyncRef0|HDSPM_SelSyncRef1|\
437 HDSPM_SelSyncRef2)
Takashi Iwai763f3562005-06-03 11:25:34 +0200438
Remy Bruno3cee5a62006-10-16 12:46:32 +0200439/*
440 For AES32, bits for status, status2 and timecode are different
441*/
442/* status */
443#define HDSPM_AES32_wcLock 0x0200000
444#define HDSPM_AES32_wcFreq_bit 22
Adrian Knoth0dca1792011-01-26 19:32:14 +0100445/* (status >> HDSPM_AES32_wcFreq_bit) & 0xF gives WC frequency (cf function
Remy Bruno3cee5a62006-10-16 12:46:32 +0200446 HDSPM_bit2freq */
447#define HDSPM_AES32_syncref_bit 16
448/* (status >> HDSPM_AES32_syncref_bit) & 0xF gives sync source */
449
450#define HDSPM_AES32_AUTOSYNC_FROM_WORD 0
451#define HDSPM_AES32_AUTOSYNC_FROM_AES1 1
452#define HDSPM_AES32_AUTOSYNC_FROM_AES2 2
453#define HDSPM_AES32_AUTOSYNC_FROM_AES3 3
454#define HDSPM_AES32_AUTOSYNC_FROM_AES4 4
455#define HDSPM_AES32_AUTOSYNC_FROM_AES5 5
456#define HDSPM_AES32_AUTOSYNC_FROM_AES6 6
457#define HDSPM_AES32_AUTOSYNC_FROM_AES7 7
458#define HDSPM_AES32_AUTOSYNC_FROM_AES8 8
Remy Bruno65345992007-08-31 12:21:08 +0200459#define HDSPM_AES32_AUTOSYNC_FROM_NONE 9
Remy Bruno3cee5a62006-10-16 12:46:32 +0200460
461/* status2 */
462/* HDSPM_LockAES_bit is given by HDSPM_LockAES >> (AES# - 1) */
463#define HDSPM_LockAES 0x80
464#define HDSPM_LockAES1 0x80
465#define HDSPM_LockAES2 0x40
466#define HDSPM_LockAES3 0x20
467#define HDSPM_LockAES4 0x10
468#define HDSPM_LockAES5 0x8
469#define HDSPM_LockAES6 0x4
470#define HDSPM_LockAES7 0x2
471#define HDSPM_LockAES8 0x1
472/*
473 Timecode
474 After windows driver sources, bits 4*i to 4*i+3 give the input frequency on
475 AES i+1
476 bits 3210
477 0001 32kHz
478 0010 44.1kHz
479 0011 48kHz
480 0100 64kHz
481 0101 88.2kHz
482 0110 96kHz
483 0111 128kHz
484 1000 176.4kHz
485 1001 192kHz
486 NB: Timecode register doesn't seem to work on AES32 card revision 230
487*/
488
Takashi Iwai763f3562005-06-03 11:25:34 +0200489/* Mixer Values */
490#define UNITY_GAIN 32768 /* = 65536/2 */
491#define MINUS_INFINITY_GAIN 0
492
Takashi Iwai763f3562005-06-03 11:25:34 +0200493/* Number of channels for different Speed Modes */
494#define MADI_SS_CHANNELS 64
495#define MADI_DS_CHANNELS 32
496#define MADI_QS_CHANNELS 16
497
Adrian Knoth0dca1792011-01-26 19:32:14 +0100498#define RAYDAT_SS_CHANNELS 36
499#define RAYDAT_DS_CHANNELS 20
500#define RAYDAT_QS_CHANNELS 12
501
502#define AIO_IN_SS_CHANNELS 14
503#define AIO_IN_DS_CHANNELS 10
504#define AIO_IN_QS_CHANNELS 8
505#define AIO_OUT_SS_CHANNELS 16
506#define AIO_OUT_DS_CHANNELS 12
507#define AIO_OUT_QS_CHANNELS 10
508
Takashi Iwai763f3562005-06-03 11:25:34 +0200509/* the size of a substream (1 mono data stream) */
510#define HDSPM_CHANNEL_BUFFER_SAMPLES (16*1024)
511#define HDSPM_CHANNEL_BUFFER_BYTES (4*HDSPM_CHANNEL_BUFFER_SAMPLES)
512
513/* the size of the area we need to allocate for DMA transfers. the
514 size is the same regardless of the number of channels, and
Adrian Knoth0dca1792011-01-26 19:32:14 +0100515 also the latency to use.
Takashi Iwai763f3562005-06-03 11:25:34 +0200516 for one direction !!!
517*/
Remy Brunoffb2c3c2007-03-07 19:08:46 +0100518#define HDSPM_DMA_AREA_BYTES (HDSPM_MAX_CHANNELS * HDSPM_CHANNEL_BUFFER_BYTES)
Takashi Iwai763f3562005-06-03 11:25:34 +0200519#define HDSPM_DMA_AREA_KILOBYTES (HDSPM_DMA_AREA_BYTES/1024)
520
Remy Bruno3cee5a62006-10-16 12:46:32 +0200521/* revisions >= 230 indicate AES32 card */
Adrian Knoth0dca1792011-01-26 19:32:14 +0100522#define HDSPM_MADI_REV 210
523#define HDSPM_RAYDAT_REV 211
524#define HDSPM_AIO_REV 212
525#define HDSPM_MADIFACE_REV 213
526#define HDSPM_AES_REV 240
Remy Bruno3cee5a62006-10-16 12:46:32 +0200527
Remy Bruno65345992007-08-31 12:21:08 +0200528/* speed factor modes */
529#define HDSPM_SPEED_SINGLE 0
530#define HDSPM_SPEED_DOUBLE 1
531#define HDSPM_SPEED_QUAD 2
Adrian Knoth0dca1792011-01-26 19:32:14 +0100532
Remy Bruno65345992007-08-31 12:21:08 +0200533/* names for speed modes */
534static char *hdspm_speed_names[] = { "single", "double", "quad" };
535
Adrian Knoth0dca1792011-01-26 19:32:14 +0100536static char *texts_autosync_aes_tco[] = { "Word Clock",
537 "AES1", "AES2", "AES3", "AES4",
538 "AES5", "AES6", "AES7", "AES8",
539 "TCO" };
540static char *texts_autosync_aes[] = { "Word Clock",
541 "AES1", "AES2", "AES3", "AES4",
542 "AES5", "AES6", "AES7", "AES8" };
543static char *texts_autosync_madi_tco[] = { "Word Clock",
544 "MADI", "TCO", "Sync In" };
545static char *texts_autosync_madi[] = { "Word Clock",
546 "MADI", "Sync In" };
547
548static char *texts_autosync_raydat_tco[] = {
549 "Word Clock",
550 "ADAT 1", "ADAT 2", "ADAT 3", "ADAT 4",
551 "AES", "SPDIF", "TCO", "Sync In"
552};
553static char *texts_autosync_raydat[] = {
554 "Word Clock",
555 "ADAT 1", "ADAT 2", "ADAT 3", "ADAT 4",
556 "AES", "SPDIF", "Sync In"
557};
558static char *texts_autosync_aio_tco[] = {
559 "Word Clock",
560 "ADAT", "AES", "SPDIF", "TCO", "Sync In"
561};
562static char *texts_autosync_aio[] = { "Word Clock",
563 "ADAT", "AES", "SPDIF", "Sync In" };
564
565static char *texts_freq[] = {
566 "No Lock",
567 "32 kHz",
568 "44.1 kHz",
569 "48 kHz",
570 "64 kHz",
571 "88.2 kHz",
572 "96 kHz",
573 "128 kHz",
574 "176.4 kHz",
575 "192 kHz"
576};
577
Adrian Knoth0dca1792011-01-26 19:32:14 +0100578static char *texts_ports_madi[] = {
579 "MADI.1", "MADI.2", "MADI.3", "MADI.4", "MADI.5", "MADI.6",
580 "MADI.7", "MADI.8", "MADI.9", "MADI.10", "MADI.11", "MADI.12",
581 "MADI.13", "MADI.14", "MADI.15", "MADI.16", "MADI.17", "MADI.18",
582 "MADI.19", "MADI.20", "MADI.21", "MADI.22", "MADI.23", "MADI.24",
583 "MADI.25", "MADI.26", "MADI.27", "MADI.28", "MADI.29", "MADI.30",
584 "MADI.31", "MADI.32", "MADI.33", "MADI.34", "MADI.35", "MADI.36",
585 "MADI.37", "MADI.38", "MADI.39", "MADI.40", "MADI.41", "MADI.42",
586 "MADI.43", "MADI.44", "MADI.45", "MADI.46", "MADI.47", "MADI.48",
587 "MADI.49", "MADI.50", "MADI.51", "MADI.52", "MADI.53", "MADI.54",
588 "MADI.55", "MADI.56", "MADI.57", "MADI.58", "MADI.59", "MADI.60",
589 "MADI.61", "MADI.62", "MADI.63", "MADI.64",
590};
591
592
593static char *texts_ports_raydat_ss[] = {
594 "ADAT1.1", "ADAT1.2", "ADAT1.3", "ADAT1.4", "ADAT1.5", "ADAT1.6",
595 "ADAT1.7", "ADAT1.8", "ADAT2.1", "ADAT2.2", "ADAT2.3", "ADAT2.4",
596 "ADAT2.5", "ADAT2.6", "ADAT2.7", "ADAT2.8", "ADAT3.1", "ADAT3.2",
597 "ADAT3.3", "ADAT3.4", "ADAT3.5", "ADAT3.6", "ADAT3.7", "ADAT3.8",
598 "ADAT4.1", "ADAT4.2", "ADAT4.3", "ADAT4.4", "ADAT4.5", "ADAT4.6",
599 "ADAT4.7", "ADAT4.8",
600 "AES.L", "AES.R",
601 "SPDIF.L", "SPDIF.R"
602};
603
604static char *texts_ports_raydat_ds[] = {
605 "ADAT1.1", "ADAT1.2", "ADAT1.3", "ADAT1.4",
606 "ADAT2.1", "ADAT2.2", "ADAT2.3", "ADAT2.4",
607 "ADAT3.1", "ADAT3.2", "ADAT3.3", "ADAT3.4",
608 "ADAT4.1", "ADAT4.2", "ADAT4.3", "ADAT4.4",
609 "AES.L", "AES.R",
610 "SPDIF.L", "SPDIF.R"
611};
612
613static char *texts_ports_raydat_qs[] = {
614 "ADAT1.1", "ADAT1.2",
615 "ADAT2.1", "ADAT2.2",
616 "ADAT3.1", "ADAT3.2",
617 "ADAT4.1", "ADAT4.2",
618 "AES.L", "AES.R",
619 "SPDIF.L", "SPDIF.R"
620};
621
622
623static char *texts_ports_aio_in_ss[] = {
624 "Analogue.L", "Analogue.R",
625 "AES.L", "AES.R",
626 "SPDIF.L", "SPDIF.R",
627 "ADAT.1", "ADAT.2", "ADAT.3", "ADAT.4", "ADAT.5", "ADAT.6",
628 "ADAT.7", "ADAT.8"
629};
630
631static char *texts_ports_aio_out_ss[] = {
632 "Analogue.L", "Analogue.R",
633 "AES.L", "AES.R",
634 "SPDIF.L", "SPDIF.R",
635 "ADAT.1", "ADAT.2", "ADAT.3", "ADAT.4", "ADAT.5", "ADAT.6",
636 "ADAT.7", "ADAT.8",
637 "Phone.L", "Phone.R"
638};
639
640static char *texts_ports_aio_in_ds[] = {
641 "Analogue.L", "Analogue.R",
642 "AES.L", "AES.R",
643 "SPDIF.L", "SPDIF.R",
644 "ADAT.1", "ADAT.2", "ADAT.3", "ADAT.4"
645};
646
647static char *texts_ports_aio_out_ds[] = {
648 "Analogue.L", "Analogue.R",
649 "AES.L", "AES.R",
650 "SPDIF.L", "SPDIF.R",
651 "ADAT.1", "ADAT.2", "ADAT.3", "ADAT.4",
652 "Phone.L", "Phone.R"
653};
654
655static char *texts_ports_aio_in_qs[] = {
656 "Analogue.L", "Analogue.R",
657 "AES.L", "AES.R",
658 "SPDIF.L", "SPDIF.R",
659 "ADAT.1", "ADAT.2", "ADAT.3", "ADAT.4"
660};
661
662static char *texts_ports_aio_out_qs[] = {
663 "Analogue.L", "Analogue.R",
664 "AES.L", "AES.R",
665 "SPDIF.L", "SPDIF.R",
666 "ADAT.1", "ADAT.2", "ADAT.3", "ADAT.4",
667 "Phone.L", "Phone.R"
668};
669
Adrian Knoth432d2502011-02-23 11:43:08 +0100670static char *texts_ports_aes32[] = {
671 "AES.1", "AES.2", "AES.3", "AES.4", "AES.5", "AES.6", "AES.7",
672 "AES.8", "AES.9.", "AES.10", "AES.11", "AES.12", "AES.13", "AES.14",
673 "AES.15", "AES.16"
674};
675
Adrian Knoth55a57602011-01-27 11:23:15 +0100676/* These tables map the ALSA channels 1..N to the channels that we
677 need to use in order to find the relevant channel buffer. RME
678 refers to this kind of mapping as between "the ADAT channel and
679 the DMA channel." We index it using the logical audio channel,
680 and the value is the DMA channel (i.e. channel buffer number)
681 where the data for that channel can be read/written from/to.
682*/
683
684static char channel_map_unity_ss[HDSPM_MAX_CHANNELS] = {
685 0, 1, 2, 3, 4, 5, 6, 7,
686 8, 9, 10, 11, 12, 13, 14, 15,
687 16, 17, 18, 19, 20, 21, 22, 23,
688 24, 25, 26, 27, 28, 29, 30, 31,
689 32, 33, 34, 35, 36, 37, 38, 39,
690 40, 41, 42, 43, 44, 45, 46, 47,
691 48, 49, 50, 51, 52, 53, 54, 55,
692 56, 57, 58, 59, 60, 61, 62, 63
693};
694
Adrian Knoth55a57602011-01-27 11:23:15 +0100695static char channel_map_raydat_ss[HDSPM_MAX_CHANNELS] = {
696 4, 5, 6, 7, 8, 9, 10, 11, /* ADAT 1 */
697 12, 13, 14, 15, 16, 17, 18, 19, /* ADAT 2 */
698 20, 21, 22, 23, 24, 25, 26, 27, /* ADAT 3 */
699 28, 29, 30, 31, 32, 33, 34, 35, /* ADAT 4 */
700 0, 1, /* AES */
701 2, 3, /* SPDIF */
702 -1, -1, -1, -1,
703 -1, -1, -1, -1, -1, -1, -1, -1,
704 -1, -1, -1, -1, -1, -1, -1, -1,
705 -1, -1, -1, -1, -1, -1, -1, -1,
706};
707
708static char channel_map_raydat_ds[HDSPM_MAX_CHANNELS] = {
709 4, 5, 6, 7, /* ADAT 1 */
710 8, 9, 10, 11, /* ADAT 2 */
711 12, 13, 14, 15, /* ADAT 3 */
712 16, 17, 18, 19, /* ADAT 4 */
713 0, 1, /* AES */
714 2, 3, /* SPDIF */
715 -1, -1, -1, -1,
716 -1, -1, -1, -1, -1, -1, -1, -1,
717 -1, -1, -1, -1, -1, -1, -1, -1,
718 -1, -1, -1, -1, -1, -1, -1, -1,
719 -1, -1, -1, -1, -1, -1, -1, -1,
720 -1, -1, -1, -1, -1, -1, -1, -1,
721};
722
723static char channel_map_raydat_qs[HDSPM_MAX_CHANNELS] = {
724 4, 5, /* ADAT 1 */
725 6, 7, /* ADAT 2 */
726 8, 9, /* ADAT 3 */
727 10, 11, /* ADAT 4 */
728 0, 1, /* AES */
729 2, 3, /* SPDIF */
730 -1, -1, -1, -1,
731 -1, -1, -1, -1, -1, -1, -1, -1,
732 -1, -1, -1, -1, -1, -1, -1, -1,
733 -1, -1, -1, -1, -1, -1, -1, -1,
734 -1, -1, -1, -1, -1, -1, -1, -1,
735 -1, -1, -1, -1, -1, -1, -1, -1,
736 -1, -1, -1, -1, -1, -1, -1, -1,
737};
738
739static char channel_map_aio_in_ss[HDSPM_MAX_CHANNELS] = {
740 0, 1, /* line in */
741 8, 9, /* aes in, */
742 10, 11, /* spdif in */
743 12, 13, 14, 15, 16, 17, 18, 19, /* ADAT in */
744 -1, -1,
745 -1, -1, -1, -1, -1, -1, -1, -1,
746 -1, -1, -1, -1, -1, -1, -1, -1,
747 -1, -1, -1, -1, -1, -1, -1, -1,
748 -1, -1, -1, -1, -1, -1, -1, -1,
749 -1, -1, -1, -1, -1, -1, -1, -1,
750 -1, -1, -1, -1, -1, -1, -1, -1,
751};
752
753static char channel_map_aio_out_ss[HDSPM_MAX_CHANNELS] = {
754 0, 1, /* line out */
755 8, 9, /* aes out */
756 10, 11, /* spdif out */
757 12, 13, 14, 15, 16, 17, 18, 19, /* ADAT out */
758 6, 7, /* phone out */
759 -1, -1, -1, -1, -1, -1, -1, -1,
760 -1, -1, -1, -1, -1, -1, -1, -1,
761 -1, -1, -1, -1, -1, -1, -1, -1,
762 -1, -1, -1, -1, -1, -1, -1, -1,
763 -1, -1, -1, -1, -1, -1, -1, -1,
764 -1, -1, -1, -1, -1, -1, -1, -1,
765};
766
767static char channel_map_aio_in_ds[HDSPM_MAX_CHANNELS] = {
768 0, 1, /* line in */
769 8, 9, /* aes in */
770 10, 11, /* spdif in */
771 12, 14, 16, 18, /* adat in */
772 -1, -1, -1, -1, -1, -1,
773 -1, -1, -1, -1, -1, -1, -1, -1,
774 -1, -1, -1, -1, -1, -1, -1, -1,
775 -1, -1, -1, -1, -1, -1, -1, -1,
776 -1, -1, -1, -1, -1, -1, -1, -1,
777 -1, -1, -1, -1, -1, -1, -1, -1,
778 -1, -1, -1, -1, -1, -1, -1, -1
779};
780
781static char channel_map_aio_out_ds[HDSPM_MAX_CHANNELS] = {
782 0, 1, /* line out */
783 8, 9, /* aes out */
784 10, 11, /* spdif out */
785 12, 14, 16, 18, /* adat out */
786 6, 7, /* phone out */
787 -1, -1, -1, -1,
788 -1, -1, -1, -1, -1, -1, -1, -1,
789 -1, -1, -1, -1, -1, -1, -1, -1,
790 -1, -1, -1, -1, -1, -1, -1, -1,
791 -1, -1, -1, -1, -1, -1, -1, -1,
792 -1, -1, -1, -1, -1, -1, -1, -1,
793 -1, -1, -1, -1, -1, -1, -1, -1
794};
795
796static char channel_map_aio_in_qs[HDSPM_MAX_CHANNELS] = {
797 0, 1, /* line in */
798 8, 9, /* aes in */
799 10, 11, /* spdif in */
800 12, 16, /* adat in */
801 -1, -1, -1, -1, -1, -1, -1, -1,
802 -1, -1, -1, -1, -1, -1, -1, -1,
803 -1, -1, -1, -1, -1, -1, -1, -1,
804 -1, -1, -1, -1, -1, -1, -1, -1,
805 -1, -1, -1, -1, -1, -1, -1, -1,
806 -1, -1, -1, -1, -1, -1, -1, -1,
807 -1, -1, -1, -1, -1, -1, -1, -1
808};
809
810static char channel_map_aio_out_qs[HDSPM_MAX_CHANNELS] = {
811 0, 1, /* line out */
812 8, 9, /* aes out */
813 10, 11, /* spdif out */
814 12, 16, /* adat out */
815 6, 7, /* phone out */
816 -1, -1, -1, -1, -1, -1,
817 -1, -1, -1, -1, -1, -1, -1, -1,
818 -1, -1, -1, -1, -1, -1, -1, -1,
819 -1, -1, -1, -1, -1, -1, -1, -1,
820 -1, -1, -1, -1, -1, -1, -1, -1,
821 -1, -1, -1, -1, -1, -1, -1, -1,
822 -1, -1, -1, -1, -1, -1, -1, -1
823};
824
Adrian Knoth432d2502011-02-23 11:43:08 +0100825static char channel_map_aes32[HDSPM_MAX_CHANNELS] = {
826 0, 1, 2, 3, 4, 5, 6, 7,
827 8, 9, 10, 11, 12, 13, 14, 15,
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 -1, -1, -1, -1, -1, -1, -1, -1,
832 -1, -1, -1, -1, -1, -1, -1, -1,
833 -1, -1, -1, -1, -1, -1, -1, -1
834};
835
Takashi Iwai98274f02005-11-17 14:52:34 +0100836struct hdspm_midi {
837 struct hdspm *hdspm;
Takashi Iwai763f3562005-06-03 11:25:34 +0200838 int id;
Takashi Iwai98274f02005-11-17 14:52:34 +0100839 struct snd_rawmidi *rmidi;
840 struct snd_rawmidi_substream *input;
841 struct snd_rawmidi_substream *output;
Takashi Iwai763f3562005-06-03 11:25:34 +0200842 char istimer; /* timer in use */
843 struct timer_list timer;
844 spinlock_t lock;
845 int pending;
Adrian Knoth0dca1792011-01-26 19:32:14 +0100846 int dataIn;
847 int statusIn;
848 int dataOut;
849 int statusOut;
850 int ie;
851 int irq;
852};
853
854struct hdspm_tco {
855 int input;
856 int framerate;
857 int wordclock;
858 int samplerate;
859 int pull;
860 int term; /* 0 = off, 1 = on */
Takashi Iwai763f3562005-06-03 11:25:34 +0200861};
862
Takashi Iwai98274f02005-11-17 14:52:34 +0100863struct hdspm {
Takashi Iwai763f3562005-06-03 11:25:34 +0200864 spinlock_t lock;
Takashi Iwaief5fa1a2007-07-27 16:52:46 +0200865 /* only one playback and/or capture stream */
866 struct snd_pcm_substream *capture_substream;
867 struct snd_pcm_substream *playback_substream;
Takashi Iwai763f3562005-06-03 11:25:34 +0200868
869 char *card_name; /* for procinfo */
Remy Bruno3cee5a62006-10-16 12:46:32 +0200870 unsigned short firmware_rev; /* dont know if relevant (yes if AES32)*/
871
Adrian Knoth0dca1792011-01-26 19:32:14 +0100872 uint8_t io_type;
Takashi Iwai763f3562005-06-03 11:25:34 +0200873
Takashi Iwai763f3562005-06-03 11:25:34 +0200874 int monitor_outs; /* set up monitoring outs init flag */
875
876 u32 control_register; /* cached value */
877 u32 control2_register; /* cached value */
Adrian Knoth0dca1792011-01-26 19:32:14 +0100878 u32 settings_register;
Takashi Iwai763f3562005-06-03 11:25:34 +0200879
Adrian Knoth0dca1792011-01-26 19:32:14 +0100880 struct hdspm_midi midi[4];
Takashi Iwai763f3562005-06-03 11:25:34 +0200881 struct tasklet_struct midi_tasklet;
882
883 size_t period_bytes;
Adrian Knoth0dca1792011-01-26 19:32:14 +0100884 unsigned char ss_in_channels;
885 unsigned char ds_in_channels;
886 unsigned char qs_in_channels;
887 unsigned char ss_out_channels;
888 unsigned char ds_out_channels;
889 unsigned char qs_out_channels;
890
891 unsigned char max_channels_in;
892 unsigned char max_channels_out;
893
894 char *channel_map_in;
895 char *channel_map_out;
896
897 char *channel_map_in_ss, *channel_map_in_ds, *channel_map_in_qs;
898 char *channel_map_out_ss, *channel_map_out_ds, *channel_map_out_qs;
899
900 char **port_names_in;
901 char **port_names_out;
902
903 char **port_names_in_ss, **port_names_in_ds, **port_names_in_qs;
904 char **port_names_out_ss, **port_names_out_ds, **port_names_out_qs;
Takashi Iwai763f3562005-06-03 11:25:34 +0200905
906 unsigned char *playback_buffer; /* suitably aligned address */
907 unsigned char *capture_buffer; /* suitably aligned address */
908
909 pid_t capture_pid; /* process id which uses capture */
910 pid_t playback_pid; /* process id which uses capture */
911 int running; /* running status */
912
913 int last_external_sample_rate; /* samplerate mystic ... */
914 int last_internal_sample_rate;
915 int system_sample_rate;
916
Takashi Iwai763f3562005-06-03 11:25:34 +0200917 int dev; /* Hardware vars... */
918 int irq;
919 unsigned long port;
920 void __iomem *iobase;
921
922 int irq_count; /* for debug */
Adrian Knoth0dca1792011-01-26 19:32:14 +0100923 int midiPorts;
Takashi Iwai763f3562005-06-03 11:25:34 +0200924
Takashi Iwai98274f02005-11-17 14:52:34 +0100925 struct snd_card *card; /* one card */
926 struct snd_pcm *pcm; /* has one pcm */
927 struct snd_hwdep *hwdep; /* and a hwdep for additional ioctl */
Takashi Iwai763f3562005-06-03 11:25:34 +0200928 struct pci_dev *pci; /* and an pci info */
929
930 /* Mixer vars */
Takashi Iwaief5fa1a2007-07-27 16:52:46 +0200931 /* fast alsa mixer */
932 struct snd_kcontrol *playback_mixer_ctls[HDSPM_MAX_CHANNELS];
933 /* but input to much, so not used */
934 struct snd_kcontrol *input_mixer_ctls[HDSPM_MAX_CHANNELS];
Adrian Knoth0dca1792011-01-26 19:32:14 +0100935 /* full mixer accessable over mixer ioctl or hwdep-device */
Takashi Iwaief5fa1a2007-07-27 16:52:46 +0200936 struct hdspm_mixer *mixer;
Takashi Iwai763f3562005-06-03 11:25:34 +0200937
Adrian Knoth0dca1792011-01-26 19:32:14 +0100938 struct hdspm_tco *tco; /* NULL if no TCO detected */
Takashi Iwai763f3562005-06-03 11:25:34 +0200939
Adrian Knoth0dca1792011-01-26 19:32:14 +0100940 char **texts_autosync;
941 int texts_autosync_items;
Takashi Iwai763f3562005-06-03 11:25:34 +0200942
Adrian Knoth0dca1792011-01-26 19:32:14 +0100943 cycles_t last_interrupt;
Jaroslav Kysela730a5862011-01-27 13:03:15 +0100944
945 struct hdspm_peak_rms peak_rms;
Takashi Iwai763f3562005-06-03 11:25:34 +0200946};
947
Takashi Iwai763f3562005-06-03 11:25:34 +0200948
Alexey Dobriyancebe41d2010-02-06 00:21:03 +0200949static DEFINE_PCI_DEVICE_TABLE(snd_hdspm_ids) = {
Takashi Iwai763f3562005-06-03 11:25:34 +0200950 {
951 .vendor = PCI_VENDOR_ID_XILINX,
952 .device = PCI_DEVICE_ID_XILINX_HAMMERFALL_DSP_MADI,
953 .subvendor = PCI_ANY_ID,
954 .subdevice = PCI_ANY_ID,
955 .class = 0,
956 .class_mask = 0,
957 .driver_data = 0},
958 {0,}
959};
960
961MODULE_DEVICE_TABLE(pci, snd_hdspm_ids);
962
963/* prototypes */
Takashi Iwai98274f02005-11-17 14:52:34 +0100964static int __devinit snd_hdspm_create_alsa_devices(struct snd_card *card,
965 struct hdspm * hdspm);
966static int __devinit snd_hdspm_create_pcm(struct snd_card *card,
967 struct hdspm * hdspm);
Takashi Iwai763f3562005-06-03 11:25:34 +0200968
Adrian Knoth0dca1792011-01-26 19:32:14 +0100969static inline void snd_hdspm_initialize_midi_flush(struct hdspm *hdspm);
970static int hdspm_update_simple_mixer_controls(struct hdspm *hdspm);
971static int hdspm_autosync_ref(struct hdspm *hdspm);
972static int snd_hdspm_set_defaults(struct hdspm *hdspm);
973static void hdspm_set_sgbuf(struct hdspm *hdspm,
Takashi Iwai77a23f22008-08-21 13:00:13 +0200974 struct snd_pcm_substream *substream,
Takashi Iwai763f3562005-06-03 11:25:34 +0200975 unsigned int reg, int channels);
976
Remy Bruno3cee5a62006-10-16 12:46:32 +0200977static inline int HDSPM_bit2freq(int n)
978{
Denys Vlasenko62cef822008-04-14 13:04:18 +0200979 static const int bit2freq_tab[] = {
980 0, 32000, 44100, 48000, 64000, 88200,
Remy Bruno3cee5a62006-10-16 12:46:32 +0200981 96000, 128000, 176400, 192000 };
982 if (n < 1 || n > 9)
983 return 0;
984 return bit2freq_tab[n];
985}
986
Adrian Knoth0dca1792011-01-26 19:32:14 +0100987/* Write/read to/from HDSPM with Adresses in Bytes
Takashi Iwai763f3562005-06-03 11:25:34 +0200988 not words but only 32Bit writes are allowed */
989
Takashi Iwai98274f02005-11-17 14:52:34 +0100990static inline void hdspm_write(struct hdspm * hdspm, unsigned int reg,
Takashi Iwai763f3562005-06-03 11:25:34 +0200991 unsigned int val)
992{
993 writel(val, hdspm->iobase + reg);
994}
995
Takashi Iwai98274f02005-11-17 14:52:34 +0100996static inline unsigned int hdspm_read(struct hdspm * hdspm, unsigned int reg)
Takashi Iwai763f3562005-06-03 11:25:34 +0200997{
998 return readl(hdspm->iobase + reg);
999}
1000
Adrian Knoth0dca1792011-01-26 19:32:14 +01001001/* for each output channel (chan) I have an Input (in) and Playback (pb) Fader
1002 mixer is write only on hardware so we have to cache him for read
Takashi Iwai763f3562005-06-03 11:25:34 +02001003 each fader is a u32, but uses only the first 16 bit */
1004
Takashi Iwai98274f02005-11-17 14:52:34 +01001005static inline int hdspm_read_in_gain(struct hdspm * hdspm, unsigned int chan,
Takashi Iwai763f3562005-06-03 11:25:34 +02001006 unsigned int in)
1007{
Adrian Bunk5bab2482006-03-13 14:15:04 +01001008 if (chan >= HDSPM_MIXER_CHANNELS || in >= HDSPM_MIXER_CHANNELS)
Takashi Iwai763f3562005-06-03 11:25:34 +02001009 return 0;
1010
1011 return hdspm->mixer->ch[chan].in[in];
1012}
1013
Takashi Iwai98274f02005-11-17 14:52:34 +01001014static inline int hdspm_read_pb_gain(struct hdspm * hdspm, unsigned int chan,
Takashi Iwai763f3562005-06-03 11:25:34 +02001015 unsigned int pb)
1016{
Adrian Bunk5bab2482006-03-13 14:15:04 +01001017 if (chan >= HDSPM_MIXER_CHANNELS || pb >= HDSPM_MIXER_CHANNELS)
Takashi Iwai763f3562005-06-03 11:25:34 +02001018 return 0;
1019 return hdspm->mixer->ch[chan].pb[pb];
1020}
1021
Denys Vlasenko62cef822008-04-14 13:04:18 +02001022static int hdspm_write_in_gain(struct hdspm *hdspm, unsigned int chan,
Takashi Iwai763f3562005-06-03 11:25:34 +02001023 unsigned int in, unsigned short data)
1024{
1025 if (chan >= HDSPM_MIXER_CHANNELS || in >= HDSPM_MIXER_CHANNELS)
1026 return -1;
1027
1028 hdspm_write(hdspm,
1029 HDSPM_MADI_mixerBase +
1030 ((in + 128 * chan) * sizeof(u32)),
1031 (hdspm->mixer->ch[chan].in[in] = data & 0xFFFF));
1032 return 0;
1033}
1034
Denys Vlasenko62cef822008-04-14 13:04:18 +02001035static int hdspm_write_pb_gain(struct hdspm *hdspm, unsigned int chan,
Takashi Iwai763f3562005-06-03 11:25:34 +02001036 unsigned int pb, unsigned short data)
1037{
1038 if (chan >= HDSPM_MIXER_CHANNELS || pb >= HDSPM_MIXER_CHANNELS)
1039 return -1;
1040
1041 hdspm_write(hdspm,
1042 HDSPM_MADI_mixerBase +
1043 ((64 + pb + 128 * chan) * sizeof(u32)),
1044 (hdspm->mixer->ch[chan].pb[pb] = data & 0xFFFF));
1045 return 0;
1046}
1047
1048
1049/* enable DMA for specific channels, now available for DSP-MADI */
Takashi Iwai98274f02005-11-17 14:52:34 +01001050static inline void snd_hdspm_enable_in(struct hdspm * hdspm, int i, int v)
Takashi Iwai763f3562005-06-03 11:25:34 +02001051{
1052 hdspm_write(hdspm, HDSPM_inputEnableBase + (4 * i), v);
1053}
1054
Takashi Iwai98274f02005-11-17 14:52:34 +01001055static inline void snd_hdspm_enable_out(struct hdspm * hdspm, int i, int v)
Takashi Iwai763f3562005-06-03 11:25:34 +02001056{
1057 hdspm_write(hdspm, HDSPM_outputEnableBase + (4 * i), v);
1058}
1059
1060/* check if same process is writing and reading */
Denys Vlasenko62cef822008-04-14 13:04:18 +02001061static int snd_hdspm_use_is_exclusive(struct hdspm *hdspm)
Takashi Iwai763f3562005-06-03 11:25:34 +02001062{
1063 unsigned long flags;
1064 int ret = 1;
1065
1066 spin_lock_irqsave(&hdspm->lock, flags);
1067 if ((hdspm->playback_pid != hdspm->capture_pid) &&
1068 (hdspm->playback_pid >= 0) && (hdspm->capture_pid >= 0)) {
1069 ret = 0;
1070 }
1071 spin_unlock_irqrestore(&hdspm->lock, flags);
1072 return ret;
1073}
1074
1075/* check for external sample rate */
Denys Vlasenko62cef822008-04-14 13:04:18 +02001076static int hdspm_external_sample_rate(struct hdspm *hdspm)
Takashi Iwai763f3562005-06-03 11:25:34 +02001077{
Adrian Knoth0dca1792011-01-26 19:32:14 +01001078 unsigned int status, status2, timecode;
1079 int syncref, rate = 0, rate_bits;
Takashi Iwai763f3562005-06-03 11:25:34 +02001080
Adrian Knoth0dca1792011-01-26 19:32:14 +01001081 switch (hdspm->io_type) {
1082 case AES32:
1083 status2 = hdspm_read(hdspm, HDSPM_statusRegister2);
1084 status = hdspm_read(hdspm, HDSPM_statusRegister);
1085 timecode = hdspm_read(hdspm, HDSPM_timecodeRegister);
1086
1087 syncref = hdspm_autosync_ref(hdspm);
Takashi Iwai763f3562005-06-03 11:25:34 +02001088
Remy Bruno3cee5a62006-10-16 12:46:32 +02001089 if (syncref == HDSPM_AES32_AUTOSYNC_FROM_WORD &&
1090 status & HDSPM_AES32_wcLock)
Adrian Knoth0dca1792011-01-26 19:32:14 +01001091 return HDSPM_bit2freq((status >> HDSPM_AES32_wcFreq_bit) & 0xF);
1092
Remy Bruno3cee5a62006-10-16 12:46:32 +02001093 if (syncref >= HDSPM_AES32_AUTOSYNC_FROM_AES1 &&
Adrian Knoth0dca1792011-01-26 19:32:14 +01001094 syncref <= HDSPM_AES32_AUTOSYNC_FROM_AES8 &&
1095 status2 & (HDSPM_LockAES >>
1096 (syncref - HDSPM_AES32_AUTOSYNC_FROM_AES1)))
1097 return HDSPM_bit2freq((timecode >> (4*(syncref-HDSPM_AES32_AUTOSYNC_FROM_AES1))) & 0xF);
Remy Bruno3cee5a62006-10-16 12:46:32 +02001098 return 0;
Adrian Knoth0dca1792011-01-26 19:32:14 +01001099 break;
1100
1101 case MADIface:
1102 status = hdspm_read(hdspm, HDSPM_statusRegister);
1103
1104 if (!(status & HDSPM_madiLock)) {
1105 rate = 0; /* no lock */
1106 } else {
1107 switch (status & (HDSPM_status1_freqMask)) {
1108 case HDSPM_status1_F_0*1:
1109 rate = 32000; break;
1110 case HDSPM_status1_F_0*2:
1111 rate = 44100; break;
1112 case HDSPM_status1_F_0*3:
1113 rate = 48000; break;
1114 case HDSPM_status1_F_0*4:
1115 rate = 64000; break;
1116 case HDSPM_status1_F_0*5:
1117 rate = 88200; break;
1118 case HDSPM_status1_F_0*6:
1119 rate = 96000; break;
1120 case HDSPM_status1_F_0*7:
1121 rate = 128000; break;
1122 case HDSPM_status1_F_0*8:
1123 rate = 176400; break;
1124 case HDSPM_status1_F_0*9:
1125 rate = 192000; break;
1126 default:
1127 rate = 0; break;
1128 }
1129 }
1130
1131 break;
1132
1133 case MADI:
1134 case AIO:
1135 case RayDAT:
1136 status2 = hdspm_read(hdspm, HDSPM_statusRegister2);
1137 status = hdspm_read(hdspm, HDSPM_statusRegister);
1138 rate = 0;
Takashi Iwai763f3562005-06-03 11:25:34 +02001139
Remy Bruno3cee5a62006-10-16 12:46:32 +02001140 /* if wordclock has synced freq and wordclock is valid */
1141 if ((status2 & HDSPM_wcLock) != 0 &&
1142 (status & HDSPM_SelSyncRef0) == 0) {
1143
1144 rate_bits = status2 & HDSPM_wcFreqMask;
1145
Adrian Knoth0dca1792011-01-26 19:32:14 +01001146
Remy Bruno3cee5a62006-10-16 12:46:32 +02001147 switch (rate_bits) {
1148 case HDSPM_wcFreq32:
1149 rate = 32000;
1150 break;
1151 case HDSPM_wcFreq44_1:
1152 rate = 44100;
1153 break;
1154 case HDSPM_wcFreq48:
1155 rate = 48000;
1156 break;
1157 case HDSPM_wcFreq64:
1158 rate = 64000;
1159 break;
1160 case HDSPM_wcFreq88_2:
1161 rate = 88200;
1162 break;
1163 case HDSPM_wcFreq96:
1164 rate = 96000;
1165 break;
Remy Bruno3cee5a62006-10-16 12:46:32 +02001166 default:
1167 rate = 0;
1168 break;
1169 }
Takashi Iwai763f3562005-06-03 11:25:34 +02001170 }
Takashi Iwai763f3562005-06-03 11:25:34 +02001171
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02001172 /* if rate detected and Syncref is Word than have it,
1173 * word has priority to MADI
1174 */
Remy Bruno3cee5a62006-10-16 12:46:32 +02001175 if (rate != 0 &&
Adrian Knoth0dca1792011-01-26 19:32:14 +01001176 (status2 & HDSPM_SelSyncRefMask) == HDSPM_SelSyncRef_WORD)
Remy Bruno3cee5a62006-10-16 12:46:32 +02001177 return rate;
1178
Adrian Knoth0dca1792011-01-26 19:32:14 +01001179 /* maybe a madi input (which is taken if sel sync is madi) */
Remy Bruno3cee5a62006-10-16 12:46:32 +02001180 if (status & HDSPM_madiLock) {
1181 rate_bits = status & HDSPM_madiFreqMask;
1182
1183 switch (rate_bits) {
1184 case HDSPM_madiFreq32:
1185 rate = 32000;
1186 break;
1187 case HDSPM_madiFreq44_1:
1188 rate = 44100;
1189 break;
1190 case HDSPM_madiFreq48:
1191 rate = 48000;
1192 break;
1193 case HDSPM_madiFreq64:
1194 rate = 64000;
1195 break;
1196 case HDSPM_madiFreq88_2:
1197 rate = 88200;
1198 break;
1199 case HDSPM_madiFreq96:
1200 rate = 96000;
1201 break;
1202 case HDSPM_madiFreq128:
1203 rate = 128000;
1204 break;
1205 case HDSPM_madiFreq176_4:
1206 rate = 176400;
1207 break;
1208 case HDSPM_madiFreq192:
1209 rate = 192000;
1210 break;
1211 default:
1212 rate = 0;
1213 break;
1214 }
1215 }
Adrian Knoth0dca1792011-01-26 19:32:14 +01001216 break;
Takashi Iwai763f3562005-06-03 11:25:34 +02001217 }
Adrian Knoth0dca1792011-01-26 19:32:14 +01001218
1219 return rate;
Takashi Iwai763f3562005-06-03 11:25:34 +02001220}
1221
1222/* Latency function */
Adrian Knoth0dca1792011-01-26 19:32:14 +01001223static inline void hdspm_compute_period_size(struct hdspm *hdspm)
Takashi Iwai763f3562005-06-03 11:25:34 +02001224{
Adrian Knoth0dca1792011-01-26 19:32:14 +01001225 hdspm->period_bytes = 1 << ((hdspm_decode_latency(hdspm->control_register) + 8));
Takashi Iwai763f3562005-06-03 11:25:34 +02001226}
1227
Adrian Knoth0dca1792011-01-26 19:32:14 +01001228
1229static snd_pcm_uframes_t hdspm_hw_pointer(struct hdspm *hdspm)
Takashi Iwai763f3562005-06-03 11:25:34 +02001230{
1231 int position;
1232
1233 position = hdspm_read(hdspm, HDSPM_statusRegister);
Adrian Knoth483cee72011-02-23 11:43:09 +01001234
1235 switch (hdspm->io_type) {
1236 case RayDAT:
1237 case AIO:
1238 position &= HDSPM_BufferPositionMask;
1239 position /= 4; /* Bytes per sample */
1240 break;
1241 default:
1242 position = (position & HDSPM_BufferID) ?
1243 (hdspm->period_bytes / 4) : 0;
1244 }
Takashi Iwai763f3562005-06-03 11:25:34 +02001245
1246 return position;
1247}
1248
1249
Takashi Iwai98274f02005-11-17 14:52:34 +01001250static inline void hdspm_start_audio(struct hdspm * s)
Takashi Iwai763f3562005-06-03 11:25:34 +02001251{
1252 s->control_register |= (HDSPM_AudioInterruptEnable | HDSPM_Start);
1253 hdspm_write(s, HDSPM_controlRegister, s->control_register);
1254}
1255
Takashi Iwai98274f02005-11-17 14:52:34 +01001256static inline void hdspm_stop_audio(struct hdspm * s)
Takashi Iwai763f3562005-06-03 11:25:34 +02001257{
1258 s->control_register &= ~(HDSPM_Start | HDSPM_AudioInterruptEnable);
1259 hdspm_write(s, HDSPM_controlRegister, s->control_register);
1260}
1261
1262/* should I silence all or only opened ones ? doit all for first even is 4MB*/
Denys Vlasenko62cef822008-04-14 13:04:18 +02001263static void hdspm_silence_playback(struct hdspm *hdspm)
Takashi Iwai763f3562005-06-03 11:25:34 +02001264{
1265 int i;
1266 int n = hdspm->period_bytes;
1267 void *buf = hdspm->playback_buffer;
1268
Remy Bruno3cee5a62006-10-16 12:46:32 +02001269 if (buf == NULL)
1270 return;
Takashi Iwai763f3562005-06-03 11:25:34 +02001271
1272 for (i = 0; i < HDSPM_MAX_CHANNELS; i++) {
1273 memset(buf, 0, n);
1274 buf += HDSPM_CHANNEL_BUFFER_BYTES;
1275 }
1276}
1277
Adrian Knoth0dca1792011-01-26 19:32:14 +01001278static int hdspm_set_interrupt_interval(struct hdspm *s, unsigned int frames)
Takashi Iwai763f3562005-06-03 11:25:34 +02001279{
1280 int n;
1281
1282 spin_lock_irq(&s->lock);
1283
1284 frames >>= 7;
1285 n = 0;
1286 while (frames) {
1287 n++;
1288 frames >>= 1;
1289 }
1290 s->control_register &= ~HDSPM_LatencyMask;
1291 s->control_register |= hdspm_encode_latency(n);
1292
1293 hdspm_write(s, HDSPM_controlRegister, s->control_register);
1294
1295 hdspm_compute_period_size(s);
1296
1297 spin_unlock_irq(&s->lock);
1298
1299 return 0;
1300}
1301
Adrian Knoth0dca1792011-01-26 19:32:14 +01001302static u64 hdspm_calc_dds_value(struct hdspm *hdspm, u64 period)
1303{
1304 u64 freq_const;
1305
1306 if (period == 0)
1307 return 0;
1308
1309 switch (hdspm->io_type) {
1310 case MADI:
1311 case AES32:
1312 freq_const = 110069313433624ULL;
1313 break;
1314 case RayDAT:
1315 case AIO:
1316 freq_const = 104857600000000ULL;
1317 break;
1318 case MADIface:
1319 freq_const = 131072000000000ULL;
1320 }
1321
1322 return div_u64(freq_const, period);
1323}
1324
1325
Remy Brunoffb2c3c2007-03-07 19:08:46 +01001326static void hdspm_set_dds_value(struct hdspm *hdspm, int rate)
1327{
1328 u64 n;
Adrian Knoth0dca1792011-01-26 19:32:14 +01001329
Remy Brunoffb2c3c2007-03-07 19:08:46 +01001330 if (rate >= 112000)
1331 rate /= 4;
1332 else if (rate >= 56000)
1333 rate /= 2;
1334
Adrian Knoth0dca1792011-01-26 19:32:14 +01001335 switch (hdspm->io_type) {
1336 case MADIface:
1337 n = 131072000000000ULL; /* 125 MHz */
1338 break;
1339 case MADI:
1340 case AES32:
1341 n = 110069313433624ULL; /* 105 MHz */
1342 break;
1343 case RayDAT:
1344 case AIO:
1345 n = 104857600000000ULL; /* 100 MHz */
1346 break;
1347 }
1348
Takashi Iwai3f7440a2009-06-05 17:40:04 +02001349 n = div_u64(n, rate);
Remy Brunoffb2c3c2007-03-07 19:08:46 +01001350 /* n should be less than 2^32 for being written to FREQ register */
Takashi Iwaida3cec32008-08-08 17:12:14 +02001351 snd_BUG_ON(n >> 32);
Remy Brunoffb2c3c2007-03-07 19:08:46 +01001352 hdspm_write(hdspm, HDSPM_freqReg, (u32)n);
1353}
Takashi Iwai763f3562005-06-03 11:25:34 +02001354
1355/* dummy set rate lets see what happens */
Takashi Iwai98274f02005-11-17 14:52:34 +01001356static int hdspm_set_rate(struct hdspm * hdspm, int rate, int called_internally)
Takashi Iwai763f3562005-06-03 11:25:34 +02001357{
Takashi Iwai763f3562005-06-03 11:25:34 +02001358 int current_rate;
1359 int rate_bits;
1360 int not_set = 0;
Remy Bruno65345992007-08-31 12:21:08 +02001361 int current_speed, target_speed;
Takashi Iwai763f3562005-06-03 11:25:34 +02001362
1363 /* ASSUMPTION: hdspm->lock is either set, or there is no need for
1364 it (e.g. during module initialization).
1365 */
1366
1367 if (!(hdspm->control_register & HDSPM_ClockModeMaster)) {
1368
Adrian Knoth0dca1792011-01-26 19:32:14 +01001369 /* SLAVE --- */
Takashi Iwai763f3562005-06-03 11:25:34 +02001370 if (called_internally) {
1371
Adrian Knoth0dca1792011-01-26 19:32:14 +01001372 /* request from ctl or card initialization
1373 just make a warning an remember setting
1374 for future master mode switching */
1375
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02001376 snd_printk(KERN_WARNING "HDSPM: "
1377 "Warning: device is not running "
1378 "as a clock master.\n");
Takashi Iwai763f3562005-06-03 11:25:34 +02001379 not_set = 1;
1380 } else {
1381
1382 /* hw_param request while in AutoSync mode */
1383 int external_freq =
1384 hdspm_external_sample_rate(hdspm);
1385
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02001386 if (hdspm_autosync_ref(hdspm) ==
1387 HDSPM_AUTOSYNC_FROM_NONE) {
Takashi Iwai763f3562005-06-03 11:25:34 +02001388
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02001389 snd_printk(KERN_WARNING "HDSPM: "
1390 "Detected no Externel Sync \n");
Takashi Iwai763f3562005-06-03 11:25:34 +02001391 not_set = 1;
1392
1393 } else if (rate != external_freq) {
1394
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02001395 snd_printk(KERN_WARNING "HDSPM: "
1396 "Warning: No AutoSync source for "
1397 "requested rate\n");
Takashi Iwai763f3562005-06-03 11:25:34 +02001398 not_set = 1;
1399 }
1400 }
1401 }
1402
1403 current_rate = hdspm->system_sample_rate;
1404
1405 /* Changing between Singe, Double and Quad speed is not
1406 allowed if any substreams are open. This is because such a change
1407 causes a shift in the location of the DMA buffers and a reduction
1408 in the number of available buffers.
1409
1410 Note that a similar but essentially insoluble problem exists for
1411 externally-driven rate changes. All we can do is to flag rate
Adrian Knoth0dca1792011-01-26 19:32:14 +01001412 changes in the read/write routines.
Takashi Iwai763f3562005-06-03 11:25:34 +02001413 */
1414
Remy Bruno65345992007-08-31 12:21:08 +02001415 if (current_rate <= 48000)
1416 current_speed = HDSPM_SPEED_SINGLE;
1417 else if (current_rate <= 96000)
1418 current_speed = HDSPM_SPEED_DOUBLE;
1419 else
1420 current_speed = HDSPM_SPEED_QUAD;
1421
1422 if (rate <= 48000)
1423 target_speed = HDSPM_SPEED_SINGLE;
1424 else if (rate <= 96000)
1425 target_speed = HDSPM_SPEED_DOUBLE;
1426 else
1427 target_speed = HDSPM_SPEED_QUAD;
Remy Bruno3cee5a62006-10-16 12:46:32 +02001428
Takashi Iwai763f3562005-06-03 11:25:34 +02001429 switch (rate) {
1430 case 32000:
Takashi Iwai763f3562005-06-03 11:25:34 +02001431 rate_bits = HDSPM_Frequency32KHz;
1432 break;
1433 case 44100:
Takashi Iwai763f3562005-06-03 11:25:34 +02001434 rate_bits = HDSPM_Frequency44_1KHz;
1435 break;
1436 case 48000:
Takashi Iwai763f3562005-06-03 11:25:34 +02001437 rate_bits = HDSPM_Frequency48KHz;
1438 break;
1439 case 64000:
Takashi Iwai763f3562005-06-03 11:25:34 +02001440 rate_bits = HDSPM_Frequency64KHz;
1441 break;
1442 case 88200:
Takashi Iwai763f3562005-06-03 11:25:34 +02001443 rate_bits = HDSPM_Frequency88_2KHz;
1444 break;
1445 case 96000:
Takashi Iwai763f3562005-06-03 11:25:34 +02001446 rate_bits = HDSPM_Frequency96KHz;
1447 break;
Remy Bruno3cee5a62006-10-16 12:46:32 +02001448 case 128000:
Remy Bruno3cee5a62006-10-16 12:46:32 +02001449 rate_bits = HDSPM_Frequency128KHz;
1450 break;
1451 case 176400:
Remy Bruno3cee5a62006-10-16 12:46:32 +02001452 rate_bits = HDSPM_Frequency176_4KHz;
1453 break;
1454 case 192000:
Remy Bruno3cee5a62006-10-16 12:46:32 +02001455 rate_bits = HDSPM_Frequency192KHz;
1456 break;
Takashi Iwai763f3562005-06-03 11:25:34 +02001457 default:
1458 return -EINVAL;
1459 }
1460
Remy Bruno65345992007-08-31 12:21:08 +02001461 if (current_speed != target_speed
Takashi Iwai763f3562005-06-03 11:25:34 +02001462 && (hdspm->capture_pid >= 0 || hdspm->playback_pid >= 0)) {
1463 snd_printk
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02001464 (KERN_ERR "HDSPM: "
Remy Bruno65345992007-08-31 12:21:08 +02001465 "cannot change from %s speed to %s speed mode "
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02001466 "(capture PID = %d, playback PID = %d)\n",
Remy Bruno65345992007-08-31 12:21:08 +02001467 hdspm_speed_names[current_speed],
1468 hdspm_speed_names[target_speed],
Takashi Iwai763f3562005-06-03 11:25:34 +02001469 hdspm->capture_pid, hdspm->playback_pid);
1470 return -EBUSY;
1471 }
1472
1473 hdspm->control_register &= ~HDSPM_FrequencyMask;
1474 hdspm->control_register |= rate_bits;
1475 hdspm_write(hdspm, HDSPM_controlRegister, hdspm->control_register);
1476
Remy Brunoffb2c3c2007-03-07 19:08:46 +01001477 /* For AES32, need to set DDS value in FREQ register
1478 For MADI, also apparently */
1479 hdspm_set_dds_value(hdspm, rate);
Adrian Knoth0dca1792011-01-26 19:32:14 +01001480
1481 if (AES32 == hdspm->io_type && rate != current_rate)
Remy Brunoffb2c3c2007-03-07 19:08:46 +01001482 hdspm_write(hdspm, HDSPM_eeprom_wr, 0);
Takashi Iwai763f3562005-06-03 11:25:34 +02001483
1484 hdspm->system_sample_rate = rate;
1485
Adrian Knoth0dca1792011-01-26 19:32:14 +01001486 if (rate <= 48000) {
1487 hdspm->channel_map_in = hdspm->channel_map_in_ss;
1488 hdspm->channel_map_out = hdspm->channel_map_out_ss;
1489 hdspm->max_channels_in = hdspm->ss_in_channels;
1490 hdspm->max_channels_out = hdspm->ss_out_channels;
1491 hdspm->port_names_in = hdspm->port_names_in_ss;
1492 hdspm->port_names_out = hdspm->port_names_out_ss;
1493 } else if (rate <= 96000) {
1494 hdspm->channel_map_in = hdspm->channel_map_in_ds;
1495 hdspm->channel_map_out = hdspm->channel_map_out_ds;
1496 hdspm->max_channels_in = hdspm->ds_in_channels;
1497 hdspm->max_channels_out = hdspm->ds_out_channels;
1498 hdspm->port_names_in = hdspm->port_names_in_ds;
1499 hdspm->port_names_out = hdspm->port_names_out_ds;
1500 } else {
1501 hdspm->channel_map_in = hdspm->channel_map_in_qs;
1502 hdspm->channel_map_out = hdspm->channel_map_out_qs;
1503 hdspm->max_channels_in = hdspm->qs_in_channels;
1504 hdspm->max_channels_out = hdspm->qs_out_channels;
1505 hdspm->port_names_in = hdspm->port_names_in_qs;
1506 hdspm->port_names_out = hdspm->port_names_out_qs;
1507 }
1508
Takashi Iwai763f3562005-06-03 11:25:34 +02001509 if (not_set != 0)
1510 return -1;
1511
1512 return 0;
1513}
1514
1515/* mainly for init to 0 on load */
Takashi Iwai98274f02005-11-17 14:52:34 +01001516static void all_in_all_mixer(struct hdspm * hdspm, int sgain)
Takashi Iwai763f3562005-06-03 11:25:34 +02001517{
1518 int i, j;
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02001519 unsigned int gain;
1520
1521 if (sgain > UNITY_GAIN)
1522 gain = UNITY_GAIN;
1523 else if (sgain < 0)
1524 gain = 0;
1525 else
1526 gain = sgain;
Takashi Iwai763f3562005-06-03 11:25:34 +02001527
1528 for (i = 0; i < HDSPM_MIXER_CHANNELS; i++)
1529 for (j = 0; j < HDSPM_MIXER_CHANNELS; j++) {
1530 hdspm_write_in_gain(hdspm, i, j, gain);
1531 hdspm_write_pb_gain(hdspm, i, j, gain);
1532 }
1533}
1534
1535/*----------------------------------------------------------------------------
1536 MIDI
1537 ----------------------------------------------------------------------------*/
1538
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02001539static inline unsigned char snd_hdspm_midi_read_byte (struct hdspm *hdspm,
1540 int id)
Takashi Iwai763f3562005-06-03 11:25:34 +02001541{
1542 /* the hardware already does the relevant bit-mask with 0xff */
Adrian Knoth0dca1792011-01-26 19:32:14 +01001543 return hdspm_read(hdspm, hdspm->midi[id].dataIn);
Takashi Iwai763f3562005-06-03 11:25:34 +02001544}
1545
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02001546static inline void snd_hdspm_midi_write_byte (struct hdspm *hdspm, int id,
1547 int val)
Takashi Iwai763f3562005-06-03 11:25:34 +02001548{
1549 /* the hardware already does the relevant bit-mask with 0xff */
Adrian Knoth0dca1792011-01-26 19:32:14 +01001550 return hdspm_write(hdspm, hdspm->midi[id].dataOut, val);
Takashi Iwai763f3562005-06-03 11:25:34 +02001551}
1552
Takashi Iwai98274f02005-11-17 14:52:34 +01001553static inline int snd_hdspm_midi_input_available (struct hdspm *hdspm, int id)
Takashi Iwai763f3562005-06-03 11:25:34 +02001554{
Adrian Knoth0dca1792011-01-26 19:32:14 +01001555 return hdspm_read(hdspm, hdspm->midi[id].statusIn) & 0xFF;
Takashi Iwai763f3562005-06-03 11:25:34 +02001556}
1557
Takashi Iwai98274f02005-11-17 14:52:34 +01001558static inline int snd_hdspm_midi_output_possible (struct hdspm *hdspm, int id)
Takashi Iwai763f3562005-06-03 11:25:34 +02001559{
1560 int fifo_bytes_used;
1561
Adrian Knoth0dca1792011-01-26 19:32:14 +01001562 fifo_bytes_used = hdspm_read(hdspm, hdspm->midi[id].statusOut) & 0xFF;
Takashi Iwai763f3562005-06-03 11:25:34 +02001563
1564 if (fifo_bytes_used < 128)
1565 return 128 - fifo_bytes_used;
1566 else
1567 return 0;
1568}
1569
Denys Vlasenko62cef822008-04-14 13:04:18 +02001570static void snd_hdspm_flush_midi_input(struct hdspm *hdspm, int id)
Takashi Iwai763f3562005-06-03 11:25:34 +02001571{
1572 while (snd_hdspm_midi_input_available (hdspm, id))
1573 snd_hdspm_midi_read_byte (hdspm, id);
1574}
1575
Takashi Iwai98274f02005-11-17 14:52:34 +01001576static int snd_hdspm_midi_output_write (struct hdspm_midi *hmidi)
Takashi Iwai763f3562005-06-03 11:25:34 +02001577{
1578 unsigned long flags;
1579 int n_pending;
1580 int to_write;
1581 int i;
1582 unsigned char buf[128];
1583
1584 /* Output is not interrupt driven */
Adrian Knoth0dca1792011-01-26 19:32:14 +01001585
Takashi Iwai763f3562005-06-03 11:25:34 +02001586 spin_lock_irqsave (&hmidi->lock, flags);
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02001587 if (hmidi->output &&
1588 !snd_rawmidi_transmit_empty (hmidi->output)) {
1589 n_pending = snd_hdspm_midi_output_possible (hmidi->hdspm,
1590 hmidi->id);
1591 if (n_pending > 0) {
1592 if (n_pending > (int)sizeof (buf))
1593 n_pending = sizeof (buf);
Adrian Knoth0dca1792011-01-26 19:32:14 +01001594
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02001595 to_write = snd_rawmidi_transmit (hmidi->output, buf,
1596 n_pending);
1597 if (to_write > 0) {
Adrian Knoth0dca1792011-01-26 19:32:14 +01001598 for (i = 0; i < to_write; ++i)
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02001599 snd_hdspm_midi_write_byte (hmidi->hdspm,
1600 hmidi->id,
1601 buf[i]);
Takashi Iwai763f3562005-06-03 11:25:34 +02001602 }
1603 }
1604 }
1605 spin_unlock_irqrestore (&hmidi->lock, flags);
1606 return 0;
1607}
1608
Takashi Iwai98274f02005-11-17 14:52:34 +01001609static int snd_hdspm_midi_input_read (struct hdspm_midi *hmidi)
Takashi Iwai763f3562005-06-03 11:25:34 +02001610{
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02001611 unsigned char buf[128]; /* this buffer is designed to match the MIDI
1612 * input FIFO size
1613 */
Takashi Iwai763f3562005-06-03 11:25:34 +02001614 unsigned long flags;
1615 int n_pending;
1616 int i;
1617
1618 spin_lock_irqsave (&hmidi->lock, flags);
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02001619 n_pending = snd_hdspm_midi_input_available (hmidi->hdspm, hmidi->id);
1620 if (n_pending > 0) {
Takashi Iwai763f3562005-06-03 11:25:34 +02001621 if (hmidi->input) {
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02001622 if (n_pending > (int)sizeof (buf))
Takashi Iwai763f3562005-06-03 11:25:34 +02001623 n_pending = sizeof (buf);
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02001624 for (i = 0; i < n_pending; ++i)
1625 buf[i] = snd_hdspm_midi_read_byte (hmidi->hdspm,
1626 hmidi->id);
1627 if (n_pending)
1628 snd_rawmidi_receive (hmidi->input, buf,
1629 n_pending);
Takashi Iwai763f3562005-06-03 11:25:34 +02001630 } else {
1631 /* flush the MIDI input FIFO */
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02001632 while (n_pending--)
1633 snd_hdspm_midi_read_byte (hmidi->hdspm,
1634 hmidi->id);
Takashi Iwai763f3562005-06-03 11:25:34 +02001635 }
1636 }
1637 hmidi->pending = 0;
Adrian Knoth0dca1792011-01-26 19:32:14 +01001638
1639 hmidi->hdspm->control_register |= hmidi->ie;
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02001640 hdspm_write(hmidi->hdspm, HDSPM_controlRegister,
1641 hmidi->hdspm->control_register);
Adrian Knoth0dca1792011-01-26 19:32:14 +01001642
Takashi Iwai763f3562005-06-03 11:25:34 +02001643 spin_unlock_irqrestore (&hmidi->lock, flags);
1644 return snd_hdspm_midi_output_write (hmidi);
1645}
1646
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02001647static void
1648snd_hdspm_midi_input_trigger(struct snd_rawmidi_substream *substream, int up)
Takashi Iwai763f3562005-06-03 11:25:34 +02001649{
Takashi Iwai98274f02005-11-17 14:52:34 +01001650 struct hdspm *hdspm;
1651 struct hdspm_midi *hmidi;
Takashi Iwai763f3562005-06-03 11:25:34 +02001652 unsigned long flags;
Takashi Iwai763f3562005-06-03 11:25:34 +02001653
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02001654 hmidi = substream->rmidi->private_data;
Takashi Iwai763f3562005-06-03 11:25:34 +02001655 hdspm = hmidi->hdspm;
Adrian Knoth0dca1792011-01-26 19:32:14 +01001656
Takashi Iwai763f3562005-06-03 11:25:34 +02001657 spin_lock_irqsave (&hdspm->lock, flags);
1658 if (up) {
Adrian Knoth0dca1792011-01-26 19:32:14 +01001659 if (!(hdspm->control_register & hmidi->ie)) {
Takashi Iwai763f3562005-06-03 11:25:34 +02001660 snd_hdspm_flush_midi_input (hdspm, hmidi->id);
Adrian Knoth0dca1792011-01-26 19:32:14 +01001661 hdspm->control_register |= hmidi->ie;
Takashi Iwai763f3562005-06-03 11:25:34 +02001662 }
1663 } else {
Adrian Knoth0dca1792011-01-26 19:32:14 +01001664 hdspm->control_register &= ~hmidi->ie;
Takashi Iwai763f3562005-06-03 11:25:34 +02001665 }
1666
1667 hdspm_write(hdspm, HDSPM_controlRegister, hdspm->control_register);
1668 spin_unlock_irqrestore (&hdspm->lock, flags);
1669}
1670
1671static void snd_hdspm_midi_output_timer(unsigned long data)
1672{
Takashi Iwai98274f02005-11-17 14:52:34 +01001673 struct hdspm_midi *hmidi = (struct hdspm_midi *) data;
Takashi Iwai763f3562005-06-03 11:25:34 +02001674 unsigned long flags;
Adrian Knoth0dca1792011-01-26 19:32:14 +01001675
Takashi Iwai763f3562005-06-03 11:25:34 +02001676 snd_hdspm_midi_output_write(hmidi);
1677 spin_lock_irqsave (&hmidi->lock, flags);
1678
1679 /* this does not bump hmidi->istimer, because the
1680 kernel automatically removed the timer when it
1681 expired, and we are now adding it back, thus
Adrian Knoth0dca1792011-01-26 19:32:14 +01001682 leaving istimer wherever it was set before.
Takashi Iwai763f3562005-06-03 11:25:34 +02001683 */
1684
1685 if (hmidi->istimer) {
1686 hmidi->timer.expires = 1 + jiffies;
1687 add_timer(&hmidi->timer);
1688 }
1689
1690 spin_unlock_irqrestore (&hmidi->lock, flags);
1691}
1692
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02001693static void
1694snd_hdspm_midi_output_trigger(struct snd_rawmidi_substream *substream, int up)
Takashi Iwai763f3562005-06-03 11:25:34 +02001695{
Takashi Iwai98274f02005-11-17 14:52:34 +01001696 struct hdspm_midi *hmidi;
Takashi Iwai763f3562005-06-03 11:25:34 +02001697 unsigned long flags;
1698
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02001699 hmidi = substream->rmidi->private_data;
Takashi Iwai763f3562005-06-03 11:25:34 +02001700 spin_lock_irqsave (&hmidi->lock, flags);
1701 if (up) {
1702 if (!hmidi->istimer) {
1703 init_timer(&hmidi->timer);
1704 hmidi->timer.function = snd_hdspm_midi_output_timer;
1705 hmidi->timer.data = (unsigned long) hmidi;
1706 hmidi->timer.expires = 1 + jiffies;
1707 add_timer(&hmidi->timer);
1708 hmidi->istimer++;
1709 }
1710 } else {
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02001711 if (hmidi->istimer && --hmidi->istimer <= 0)
Takashi Iwai763f3562005-06-03 11:25:34 +02001712 del_timer (&hmidi->timer);
Takashi Iwai763f3562005-06-03 11:25:34 +02001713 }
1714 spin_unlock_irqrestore (&hmidi->lock, flags);
1715 if (up)
1716 snd_hdspm_midi_output_write(hmidi);
1717}
1718
Takashi Iwai98274f02005-11-17 14:52:34 +01001719static int snd_hdspm_midi_input_open(struct snd_rawmidi_substream *substream)
Takashi Iwai763f3562005-06-03 11:25:34 +02001720{
Takashi Iwai98274f02005-11-17 14:52:34 +01001721 struct hdspm_midi *hmidi;
Takashi Iwai763f3562005-06-03 11:25:34 +02001722
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02001723 hmidi = substream->rmidi->private_data;
Takashi Iwai763f3562005-06-03 11:25:34 +02001724 spin_lock_irq (&hmidi->lock);
1725 snd_hdspm_flush_midi_input (hmidi->hdspm, hmidi->id);
1726 hmidi->input = substream;
1727 spin_unlock_irq (&hmidi->lock);
1728
1729 return 0;
1730}
1731
Takashi Iwai98274f02005-11-17 14:52:34 +01001732static int snd_hdspm_midi_output_open(struct snd_rawmidi_substream *substream)
Takashi Iwai763f3562005-06-03 11:25:34 +02001733{
Takashi Iwai98274f02005-11-17 14:52:34 +01001734 struct hdspm_midi *hmidi;
Takashi Iwai763f3562005-06-03 11:25:34 +02001735
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02001736 hmidi = substream->rmidi->private_data;
Takashi Iwai763f3562005-06-03 11:25:34 +02001737 spin_lock_irq (&hmidi->lock);
1738 hmidi->output = substream;
1739 spin_unlock_irq (&hmidi->lock);
1740
1741 return 0;
1742}
1743
Takashi Iwai98274f02005-11-17 14:52:34 +01001744static int snd_hdspm_midi_input_close(struct snd_rawmidi_substream *substream)
Takashi Iwai763f3562005-06-03 11:25:34 +02001745{
Takashi Iwai98274f02005-11-17 14:52:34 +01001746 struct hdspm_midi *hmidi;
Takashi Iwai763f3562005-06-03 11:25:34 +02001747
1748 snd_hdspm_midi_input_trigger (substream, 0);
1749
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02001750 hmidi = substream->rmidi->private_data;
Takashi Iwai763f3562005-06-03 11:25:34 +02001751 spin_lock_irq (&hmidi->lock);
1752 hmidi->input = NULL;
1753 spin_unlock_irq (&hmidi->lock);
1754
1755 return 0;
1756}
1757
Takashi Iwai98274f02005-11-17 14:52:34 +01001758static int snd_hdspm_midi_output_close(struct snd_rawmidi_substream *substream)
Takashi Iwai763f3562005-06-03 11:25:34 +02001759{
Takashi Iwai98274f02005-11-17 14:52:34 +01001760 struct hdspm_midi *hmidi;
Takashi Iwai763f3562005-06-03 11:25:34 +02001761
1762 snd_hdspm_midi_output_trigger (substream, 0);
1763
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02001764 hmidi = substream->rmidi->private_data;
Takashi Iwai763f3562005-06-03 11:25:34 +02001765 spin_lock_irq (&hmidi->lock);
1766 hmidi->output = NULL;
1767 spin_unlock_irq (&hmidi->lock);
1768
1769 return 0;
1770}
1771
Takashi Iwai98274f02005-11-17 14:52:34 +01001772static struct snd_rawmidi_ops snd_hdspm_midi_output =
Takashi Iwai763f3562005-06-03 11:25:34 +02001773{
1774 .open = snd_hdspm_midi_output_open,
1775 .close = snd_hdspm_midi_output_close,
1776 .trigger = snd_hdspm_midi_output_trigger,
1777};
1778
Takashi Iwai98274f02005-11-17 14:52:34 +01001779static struct snd_rawmidi_ops snd_hdspm_midi_input =
Takashi Iwai763f3562005-06-03 11:25:34 +02001780{
1781 .open = snd_hdspm_midi_input_open,
1782 .close = snd_hdspm_midi_input_close,
1783 .trigger = snd_hdspm_midi_input_trigger,
1784};
1785
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02001786static int __devinit snd_hdspm_create_midi (struct snd_card *card,
1787 struct hdspm *hdspm, int id)
Takashi Iwai763f3562005-06-03 11:25:34 +02001788{
1789 int err;
1790 char buf[32];
1791
1792 hdspm->midi[id].id = id;
Takashi Iwai763f3562005-06-03 11:25:34 +02001793 hdspm->midi[id].hdspm = hdspm;
Takashi Iwai763f3562005-06-03 11:25:34 +02001794 spin_lock_init (&hdspm->midi[id].lock);
1795
Adrian Knoth0dca1792011-01-26 19:32:14 +01001796 if (0 == id) {
1797 if (MADIface == hdspm->io_type) {
1798 /* MIDI-over-MADI on HDSPe MADIface */
1799 hdspm->midi[0].dataIn = HDSPM_midiDataIn2;
1800 hdspm->midi[0].statusIn = HDSPM_midiStatusIn2;
1801 hdspm->midi[0].dataOut = HDSPM_midiDataOut2;
1802 hdspm->midi[0].statusOut = HDSPM_midiStatusOut2;
1803 hdspm->midi[0].ie = HDSPM_Midi2InterruptEnable;
1804 hdspm->midi[0].irq = HDSPM_midi2IRQPending;
1805 } else {
1806 hdspm->midi[0].dataIn = HDSPM_midiDataIn0;
1807 hdspm->midi[0].statusIn = HDSPM_midiStatusIn0;
1808 hdspm->midi[0].dataOut = HDSPM_midiDataOut0;
1809 hdspm->midi[0].statusOut = HDSPM_midiStatusOut0;
1810 hdspm->midi[0].ie = HDSPM_Midi0InterruptEnable;
1811 hdspm->midi[0].irq = HDSPM_midi0IRQPending;
1812 }
1813 } else if (1 == id) {
1814 hdspm->midi[1].dataIn = HDSPM_midiDataIn1;
1815 hdspm->midi[1].statusIn = HDSPM_midiStatusIn1;
1816 hdspm->midi[1].dataOut = HDSPM_midiDataOut1;
1817 hdspm->midi[1].statusOut = HDSPM_midiStatusOut1;
1818 hdspm->midi[1].ie = HDSPM_Midi1InterruptEnable;
1819 hdspm->midi[1].irq = HDSPM_midi1IRQPending;
1820 } else if ((2 == id) && (MADI == hdspm->io_type)) {
1821 /* MIDI-over-MADI on HDSPe MADI */
1822 hdspm->midi[2].dataIn = HDSPM_midiDataIn2;
1823 hdspm->midi[2].statusIn = HDSPM_midiStatusIn2;
1824 hdspm->midi[2].dataOut = HDSPM_midiDataOut2;
1825 hdspm->midi[2].statusOut = HDSPM_midiStatusOut2;
1826 hdspm->midi[2].ie = HDSPM_Midi2InterruptEnable;
1827 hdspm->midi[2].irq = HDSPM_midi2IRQPending;
1828 } else if (2 == id) {
1829 /* TCO MTC, read only */
1830 hdspm->midi[2].dataIn = HDSPM_midiDataIn2;
1831 hdspm->midi[2].statusIn = HDSPM_midiStatusIn2;
1832 hdspm->midi[2].dataOut = -1;
1833 hdspm->midi[2].statusOut = -1;
1834 hdspm->midi[2].ie = HDSPM_Midi2InterruptEnable;
1835 hdspm->midi[2].irq = HDSPM_midi2IRQPendingAES;
1836 } else if (3 == id) {
1837 /* TCO MTC on HDSPe MADI */
1838 hdspm->midi[3].dataIn = HDSPM_midiDataIn3;
1839 hdspm->midi[3].statusIn = HDSPM_midiStatusIn3;
1840 hdspm->midi[3].dataOut = -1;
1841 hdspm->midi[3].statusOut = -1;
1842 hdspm->midi[3].ie = HDSPM_Midi3InterruptEnable;
1843 hdspm->midi[3].irq = HDSPM_midi3IRQPending;
1844 }
Takashi Iwai763f3562005-06-03 11:25:34 +02001845
Adrian Knoth0dca1792011-01-26 19:32:14 +01001846 if ((id < 2) || ((2 == id) && ((MADI == hdspm->io_type) ||
1847 (MADIface == hdspm->io_type)))) {
1848 if ((id == 0) && (MADIface == hdspm->io_type)) {
1849 sprintf(buf, "%s MIDIoverMADI", card->shortname);
1850 } else if ((id == 2) && (MADI == hdspm->io_type)) {
1851 sprintf(buf, "%s MIDIoverMADI", card->shortname);
1852 } else {
1853 sprintf(buf, "%s MIDI %d", card->shortname, id+1);
1854 }
1855 err = snd_rawmidi_new(card, buf, id, 1, 1,
1856 &hdspm->midi[id].rmidi);
1857 if (err < 0)
1858 return err;
Takashi Iwai763f3562005-06-03 11:25:34 +02001859
Adrian Knoth0dca1792011-01-26 19:32:14 +01001860 sprintf(hdspm->midi[id].rmidi->name, "%s MIDI %d",
1861 card->id, id+1);
1862 hdspm->midi[id].rmidi->private_data = &hdspm->midi[id];
Takashi Iwai763f3562005-06-03 11:25:34 +02001863
Adrian Knoth0dca1792011-01-26 19:32:14 +01001864 snd_rawmidi_set_ops(hdspm->midi[id].rmidi,
1865 SNDRV_RAWMIDI_STREAM_OUTPUT,
1866 &snd_hdspm_midi_output);
1867 snd_rawmidi_set_ops(hdspm->midi[id].rmidi,
1868 SNDRV_RAWMIDI_STREAM_INPUT,
1869 &snd_hdspm_midi_input);
1870
1871 hdspm->midi[id].rmidi->info_flags |=
1872 SNDRV_RAWMIDI_INFO_OUTPUT |
1873 SNDRV_RAWMIDI_INFO_INPUT |
1874 SNDRV_RAWMIDI_INFO_DUPLEX;
1875 } else {
1876 /* TCO MTC, read only */
1877 sprintf(buf, "%s MTC %d", card->shortname, id+1);
1878 err = snd_rawmidi_new(card, buf, id, 1, 1,
1879 &hdspm->midi[id].rmidi);
1880 if (err < 0)
1881 return err;
1882
1883 sprintf(hdspm->midi[id].rmidi->name,
1884 "%s MTC %d", card->id, id+1);
1885 hdspm->midi[id].rmidi->private_data = &hdspm->midi[id];
1886
1887 snd_rawmidi_set_ops(hdspm->midi[id].rmidi,
1888 SNDRV_RAWMIDI_STREAM_INPUT,
1889 &snd_hdspm_midi_input);
1890
1891 hdspm->midi[id].rmidi->info_flags |= SNDRV_RAWMIDI_INFO_INPUT;
1892 }
Takashi Iwai763f3562005-06-03 11:25:34 +02001893
1894 return 0;
1895}
1896
1897
1898static void hdspm_midi_tasklet(unsigned long arg)
1899{
Takashi Iwai98274f02005-11-17 14:52:34 +01001900 struct hdspm *hdspm = (struct hdspm *)arg;
Adrian Knoth0dca1792011-01-26 19:32:14 +01001901 int i = 0;
1902
1903 while (i < hdspm->midiPorts) {
1904 if (hdspm->midi[i].pending)
1905 snd_hdspm_midi_input_read(&hdspm->midi[i]);
1906
1907 i++;
1908 }
1909}
Takashi Iwai763f3562005-06-03 11:25:34 +02001910
1911
1912/*-----------------------------------------------------------------------------
1913 Status Interface
1914 ----------------------------------------------------------------------------*/
1915
1916/* get the system sample rate which is set */
1917
Adrian Knoth0dca1792011-01-26 19:32:14 +01001918
1919/**
1920 * Calculate the real sample rate from the
1921 * current DDS value.
1922 **/
1923static int hdspm_get_system_sample_rate(struct hdspm *hdspm)
1924{
1925 unsigned int period, rate;
1926
1927 period = hdspm_read(hdspm, HDSPM_RD_PLL_FREQ);
1928 rate = hdspm_calc_dds_value(hdspm, period);
1929
1930 return rate;
1931}
1932
1933
Takashi Iwai763f3562005-06-03 11:25:34 +02001934#define HDSPM_SYSTEM_SAMPLE_RATE(xname, xindex) \
Clemens Ladisch67ed4162005-07-29 15:32:58 +02001935{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
Takashi Iwai763f3562005-06-03 11:25:34 +02001936 .name = xname, \
1937 .index = xindex, \
1938 .access = SNDRV_CTL_ELEM_ACCESS_READ, \
1939 .info = snd_hdspm_info_system_sample_rate, \
1940 .get = snd_hdspm_get_system_sample_rate \
1941}
1942
Takashi Iwai98274f02005-11-17 14:52:34 +01001943static int snd_hdspm_info_system_sample_rate(struct snd_kcontrol *kcontrol,
1944 struct snd_ctl_elem_info *uinfo)
Takashi Iwai763f3562005-06-03 11:25:34 +02001945{
1946 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
1947 uinfo->count = 1;
Adrian Knoth0dca1792011-01-26 19:32:14 +01001948 uinfo->value.integer.min = 27000;
1949 uinfo->value.integer.max = 207000;
1950 uinfo->value.integer.step = 1;
Takashi Iwai763f3562005-06-03 11:25:34 +02001951 return 0;
1952}
1953
Adrian Knoth0dca1792011-01-26 19:32:14 +01001954
Takashi Iwai98274f02005-11-17 14:52:34 +01001955static int snd_hdspm_get_system_sample_rate(struct snd_kcontrol *kcontrol,
1956 struct snd_ctl_elem_value *
Takashi Iwai763f3562005-06-03 11:25:34 +02001957 ucontrol)
1958{
Takashi Iwai98274f02005-11-17 14:52:34 +01001959 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
Takashi Iwai763f3562005-06-03 11:25:34 +02001960
Adrian Knoth0dca1792011-01-26 19:32:14 +01001961 ucontrol->value.integer.value[0] = hdspm_get_system_sample_rate(hdspm);
Takashi Iwai763f3562005-06-03 11:25:34 +02001962 return 0;
1963}
1964
Adrian Knoth0dca1792011-01-26 19:32:14 +01001965
1966/**
1967 * Returns the WordClock sample rate class for the given card.
1968 **/
1969static int hdspm_get_wc_sample_rate(struct hdspm *hdspm)
1970{
1971 int status;
1972
1973 switch (hdspm->io_type) {
1974 case RayDAT:
1975 case AIO:
1976 status = hdspm_read(hdspm, HDSPM_RD_STATUS_1);
1977 return (status >> 16) & 0xF;
1978 break;
1979 default:
1980 break;
1981 }
1982
1983
1984 return 0;
Takashi Iwai763f3562005-06-03 11:25:34 +02001985}
1986
Adrian Knoth0dca1792011-01-26 19:32:14 +01001987
1988/**
1989 * Returns the TCO sample rate class for the given card.
1990 **/
1991static int hdspm_get_tco_sample_rate(struct hdspm *hdspm)
1992{
1993 int status;
1994
1995 if (hdspm->tco) {
1996 switch (hdspm->io_type) {
1997 case RayDAT:
1998 case AIO:
1999 status = hdspm_read(hdspm, HDSPM_RD_STATUS_1);
2000 return (status >> 20) & 0xF;
2001 break;
2002 default:
2003 break;
2004 }
2005 }
2006
2007 return 0;
2008}
2009
2010
2011/**
2012 * Returns the SYNC_IN sample rate class for the given card.
2013 **/
2014static int hdspm_get_sync_in_sample_rate(struct hdspm *hdspm)
2015{
2016 int status;
2017
2018 if (hdspm->tco) {
2019 switch (hdspm->io_type) {
2020 case RayDAT:
2021 case AIO:
2022 status = hdspm_read(hdspm, HDSPM_RD_STATUS_2);
2023 return (status >> 12) & 0xF;
2024 break;
2025 default:
2026 break;
2027 }
2028 }
2029
2030 return 0;
2031}
2032
2033
2034/**
2035 * Returns the sample rate class for input source <idx> for
2036 * 'new style' cards like the AIO and RayDAT.
2037 **/
2038static int hdspm_get_s1_sample_rate(struct hdspm *hdspm, unsigned int idx)
2039{
2040 int status = hdspm_read(hdspm, HDSPM_RD_STATUS_2);
2041
2042 return (status >> (idx*4)) & 0xF;
2043}
2044
2045
2046
2047#define HDSPM_AUTOSYNC_SAMPLE_RATE(xname, xindex) \
2048{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2049 .name = xname, \
2050 .private_value = xindex, \
2051 .access = SNDRV_CTL_ELEM_ACCESS_READ, \
2052 .info = snd_hdspm_info_autosync_sample_rate, \
2053 .get = snd_hdspm_get_autosync_sample_rate \
2054}
2055
2056
Takashi Iwai98274f02005-11-17 14:52:34 +01002057static int snd_hdspm_info_autosync_sample_rate(struct snd_kcontrol *kcontrol,
2058 struct snd_ctl_elem_info *uinfo)
Takashi Iwai763f3562005-06-03 11:25:34 +02002059{
Takashi Iwai763f3562005-06-03 11:25:34 +02002060 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2061 uinfo->count = 1;
2062 uinfo->value.enumerated.items = 10;
Adrian Knoth0dca1792011-01-26 19:32:14 +01002063
Takashi Iwai763f3562005-06-03 11:25:34 +02002064 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
Adrian Knoth0dca1792011-01-26 19:32:14 +01002065 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
Takashi Iwai763f3562005-06-03 11:25:34 +02002066 strcpy(uinfo->value.enumerated.name,
Adrian Knoth0dca1792011-01-26 19:32:14 +01002067 texts_freq[uinfo->value.enumerated.item]);
Takashi Iwai763f3562005-06-03 11:25:34 +02002068 return 0;
2069}
2070
Adrian Knoth0dca1792011-01-26 19:32:14 +01002071
Takashi Iwai98274f02005-11-17 14:52:34 +01002072static int snd_hdspm_get_autosync_sample_rate(struct snd_kcontrol *kcontrol,
2073 struct snd_ctl_elem_value *
Takashi Iwai763f3562005-06-03 11:25:34 +02002074 ucontrol)
2075{
Takashi Iwai98274f02005-11-17 14:52:34 +01002076 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
Takashi Iwai763f3562005-06-03 11:25:34 +02002077
Adrian Knoth0dca1792011-01-26 19:32:14 +01002078 switch (hdspm->io_type) {
2079 case RayDAT:
2080 switch (kcontrol->private_value) {
2081 case 0:
2082 ucontrol->value.enumerated.item[0] =
2083 hdspm_get_wc_sample_rate(hdspm);
2084 break;
2085 case 7:
2086 ucontrol->value.enumerated.item[0] =
2087 hdspm_get_tco_sample_rate(hdspm);
2088 break;
2089 case 8:
2090 ucontrol->value.enumerated.item[0] =
2091 hdspm_get_sync_in_sample_rate(hdspm);
2092 break;
2093 default:
2094 ucontrol->value.enumerated.item[0] =
2095 hdspm_get_s1_sample_rate(hdspm,
2096 kcontrol->private_value-1);
2097 }
Takashi Iwai763f3562005-06-03 11:25:34 +02002098
Adrian Knoth0dca1792011-01-26 19:32:14 +01002099 case AIO:
2100 switch (kcontrol->private_value) {
2101 case 0: /* WC */
2102 ucontrol->value.enumerated.item[0] =
2103 hdspm_get_wc_sample_rate(hdspm);
2104 break;
2105 case 4: /* TCO */
2106 ucontrol->value.enumerated.item[0] =
2107 hdspm_get_tco_sample_rate(hdspm);
2108 break;
2109 case 5: /* SYNC_IN */
2110 ucontrol->value.enumerated.item[0] =
2111 hdspm_get_sync_in_sample_rate(hdspm);
2112 break;
2113 default:
2114 ucontrol->value.enumerated.item[0] =
2115 hdspm_get_s1_sample_rate(hdspm,
2116 ucontrol->id.index-1);
2117 }
Takashi Iwai763f3562005-06-03 11:25:34 +02002118 default:
Adrian Knoth0dca1792011-01-26 19:32:14 +01002119 break;
Takashi Iwai763f3562005-06-03 11:25:34 +02002120 }
Adrian Knoth0dca1792011-01-26 19:32:14 +01002121
Takashi Iwai763f3562005-06-03 11:25:34 +02002122 return 0;
2123}
2124
Adrian Knoth0dca1792011-01-26 19:32:14 +01002125
Takashi Iwai763f3562005-06-03 11:25:34 +02002126#define HDSPM_SYSTEM_CLOCK_MODE(xname, xindex) \
Adrian Knoth0dca1792011-01-26 19:32:14 +01002127{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2128 .name = xname, \
2129 .index = xindex, \
2130 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |\
2131 SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
2132 .info = snd_hdspm_info_system_clock_mode, \
2133 .get = snd_hdspm_get_system_clock_mode, \
2134 .put = snd_hdspm_put_system_clock_mode, \
Takashi Iwai763f3562005-06-03 11:25:34 +02002135}
2136
2137
Adrian Knoth0dca1792011-01-26 19:32:14 +01002138/**
2139 * Returns the system clock mode for the given card.
2140 * @returns 0 - master, 1 - slave
2141 **/
2142static int hdspm_system_clock_mode(struct hdspm *hdspm)
Takashi Iwai763f3562005-06-03 11:25:34 +02002143{
Adrian Knoth0dca1792011-01-26 19:32:14 +01002144 switch (hdspm->io_type) {
2145 case AIO:
2146 case RayDAT:
2147 if (hdspm->settings_register & HDSPM_c0Master)
2148 return 0;
2149 break;
Takashi Iwai763f3562005-06-03 11:25:34 +02002150
Adrian Knoth0dca1792011-01-26 19:32:14 +01002151 default:
2152 if (hdspm->control_register & HDSPM_ClockModeMaster)
2153 return 0;
2154 }
2155
Takashi Iwai763f3562005-06-03 11:25:34 +02002156 return 1;
2157}
2158
Adrian Knoth0dca1792011-01-26 19:32:14 +01002159
2160/**
2161 * Sets the system clock mode.
2162 * @param mode 0 - master, 1 - slave
2163 **/
2164static void hdspm_set_system_clock_mode(struct hdspm *hdspm, int mode)
2165{
2166 switch (hdspm->io_type) {
2167 case AIO:
2168 case RayDAT:
2169 if (0 == mode)
2170 hdspm->settings_register |= HDSPM_c0Master;
2171 else
2172 hdspm->settings_register &= ~HDSPM_c0Master;
2173
2174 hdspm_write(hdspm, HDSPM_WR_SETTINGS, hdspm->settings_register);
2175 break;
2176
2177 default:
2178 if (0 == mode)
2179 hdspm->control_register |= HDSPM_ClockModeMaster;
2180 else
2181 hdspm->control_register &= ~HDSPM_ClockModeMaster;
2182
2183 hdspm_write(hdspm, HDSPM_controlRegister,
2184 hdspm->control_register);
2185 }
2186}
2187
2188
Takashi Iwai98274f02005-11-17 14:52:34 +01002189static int snd_hdspm_info_system_clock_mode(struct snd_kcontrol *kcontrol,
2190 struct snd_ctl_elem_info *uinfo)
Takashi Iwai763f3562005-06-03 11:25:34 +02002191{
Adrian Knoth0dca1792011-01-26 19:32:14 +01002192 static char *texts[] = { "Master", "AutoSync" };
Takashi Iwai763f3562005-06-03 11:25:34 +02002193
2194 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2195 uinfo->count = 1;
2196 uinfo->value.enumerated.items = 2;
2197 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
2198 uinfo->value.enumerated.item =
2199 uinfo->value.enumerated.items - 1;
2200 strcpy(uinfo->value.enumerated.name,
2201 texts[uinfo->value.enumerated.item]);
2202 return 0;
2203}
2204
Takashi Iwai98274f02005-11-17 14:52:34 +01002205static int snd_hdspm_get_system_clock_mode(struct snd_kcontrol *kcontrol,
2206 struct snd_ctl_elem_value *ucontrol)
Takashi Iwai763f3562005-06-03 11:25:34 +02002207{
Takashi Iwai98274f02005-11-17 14:52:34 +01002208 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
Takashi Iwai763f3562005-06-03 11:25:34 +02002209
Adrian Knoth0dca1792011-01-26 19:32:14 +01002210 ucontrol->value.enumerated.item[0] = hdspm_system_clock_mode(hdspm);
Takashi Iwai763f3562005-06-03 11:25:34 +02002211 return 0;
2212}
2213
Adrian Knoth0dca1792011-01-26 19:32:14 +01002214static int snd_hdspm_put_system_clock_mode(struct snd_kcontrol *kcontrol,
2215 struct snd_ctl_elem_value *ucontrol)
2216{
2217 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
2218 int val;
2219
2220 if (!snd_hdspm_use_is_exclusive(hdspm))
2221 return -EBUSY;
2222
2223 val = ucontrol->value.enumerated.item[0];
2224 if (val < 0)
2225 val = 0;
2226 else if (val > 1)
2227 val = 1;
2228
2229 hdspm_set_system_clock_mode(hdspm, val);
2230
2231 return 0;
Takashi Iwai763f3562005-06-03 11:25:34 +02002232}
2233
Adrian Knoth0dca1792011-01-26 19:32:14 +01002234
2235#define HDSPM_INTERNAL_CLOCK(xname, xindex) \
2236{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2237 .name = xname, \
2238 .index = xindex, \
2239 .info = snd_hdspm_info_clock_source, \
2240 .get = snd_hdspm_get_clock_source, \
2241 .put = snd_hdspm_put_clock_source \
2242}
2243
2244
Takashi Iwai98274f02005-11-17 14:52:34 +01002245static int hdspm_clock_source(struct hdspm * hdspm)
Takashi Iwai763f3562005-06-03 11:25:34 +02002246{
Adrian Knoth0dca1792011-01-26 19:32:14 +01002247 switch (hdspm->system_sample_rate) {
2248 case 32000: return 0;
2249 case 44100: return 1;
2250 case 48000: return 2;
2251 case 64000: return 3;
2252 case 88200: return 4;
2253 case 96000: return 5;
2254 case 128000: return 6;
2255 case 176400: return 7;
2256 case 192000: return 8;
Takashi Iwai763f3562005-06-03 11:25:34 +02002257 }
Adrian Knoth0dca1792011-01-26 19:32:14 +01002258
2259 return -1;
Takashi Iwai763f3562005-06-03 11:25:34 +02002260}
2261
Takashi Iwai98274f02005-11-17 14:52:34 +01002262static int hdspm_set_clock_source(struct hdspm * hdspm, int mode)
Takashi Iwai763f3562005-06-03 11:25:34 +02002263{
2264 int rate;
2265 switch (mode) {
Adrian Knoth0dca1792011-01-26 19:32:14 +01002266 case 0:
2267 rate = 32000; break;
2268 case 1:
2269 rate = 44100; break;
2270 case 2:
2271 rate = 48000; break;
2272 case 3:
2273 rate = 64000; break;
2274 case 4:
2275 rate = 88200; break;
2276 case 5:
2277 rate = 96000; break;
2278 case 6:
2279 rate = 128000; break;
2280 case 7:
2281 rate = 176400; break;
2282 case 8:
2283 rate = 192000; break;
Takashi Iwai763f3562005-06-03 11:25:34 +02002284 default:
Adrian Knoth0dca1792011-01-26 19:32:14 +01002285 rate = 48000;
Takashi Iwai763f3562005-06-03 11:25:34 +02002286 }
Takashi Iwai763f3562005-06-03 11:25:34 +02002287 hdspm_set_rate(hdspm, rate, 1);
2288 return 0;
2289}
2290
Takashi Iwai98274f02005-11-17 14:52:34 +01002291static int snd_hdspm_info_clock_source(struct snd_kcontrol *kcontrol,
2292 struct snd_ctl_elem_info *uinfo)
Takashi Iwai763f3562005-06-03 11:25:34 +02002293{
Takashi Iwai763f3562005-06-03 11:25:34 +02002294 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2295 uinfo->count = 1;
Adrian Knoth0dca1792011-01-26 19:32:14 +01002296 uinfo->value.enumerated.items = 9;
Takashi Iwai763f3562005-06-03 11:25:34 +02002297
2298 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
2299 uinfo->value.enumerated.item =
2300 uinfo->value.enumerated.items - 1;
2301
2302 strcpy(uinfo->value.enumerated.name,
Adrian Knoth0dca1792011-01-26 19:32:14 +01002303 texts_freq[uinfo->value.enumerated.item+1]);
Takashi Iwai763f3562005-06-03 11:25:34 +02002304
2305 return 0;
2306}
2307
Takashi Iwai98274f02005-11-17 14:52:34 +01002308static int snd_hdspm_get_clock_source(struct snd_kcontrol *kcontrol,
2309 struct snd_ctl_elem_value *ucontrol)
Takashi Iwai763f3562005-06-03 11:25:34 +02002310{
Takashi Iwai98274f02005-11-17 14:52:34 +01002311 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
Takashi Iwai763f3562005-06-03 11:25:34 +02002312
2313 ucontrol->value.enumerated.item[0] = hdspm_clock_source(hdspm);
2314 return 0;
2315}
2316
Takashi Iwai98274f02005-11-17 14:52:34 +01002317static int snd_hdspm_put_clock_source(struct snd_kcontrol *kcontrol,
2318 struct snd_ctl_elem_value *ucontrol)
Takashi Iwai763f3562005-06-03 11:25:34 +02002319{
Takashi Iwai98274f02005-11-17 14:52:34 +01002320 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
Takashi Iwai763f3562005-06-03 11:25:34 +02002321 int change;
2322 int val;
2323
2324 if (!snd_hdspm_use_is_exclusive(hdspm))
2325 return -EBUSY;
2326 val = ucontrol->value.enumerated.item[0];
2327 if (val < 0)
2328 val = 0;
Remy Bruno65345992007-08-31 12:21:08 +02002329 if (val > 9)
2330 val = 9;
Takashi Iwai763f3562005-06-03 11:25:34 +02002331 spin_lock_irq(&hdspm->lock);
2332 if (val != hdspm_clock_source(hdspm))
2333 change = (hdspm_set_clock_source(hdspm, val) == 0) ? 1 : 0;
2334 else
2335 change = 0;
2336 spin_unlock_irq(&hdspm->lock);
2337 return change;
2338}
2339
Adrian Knoth0dca1792011-01-26 19:32:14 +01002340
Takashi Iwai763f3562005-06-03 11:25:34 +02002341#define HDSPM_PREF_SYNC_REF(xname, xindex) \
Adrian Knoth0dca1792011-01-26 19:32:14 +01002342{.iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2343 .name = xname, \
2344 .index = xindex, \
2345 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |\
2346 SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
2347 .info = snd_hdspm_info_pref_sync_ref, \
2348 .get = snd_hdspm_get_pref_sync_ref, \
2349 .put = snd_hdspm_put_pref_sync_ref \
Takashi Iwai763f3562005-06-03 11:25:34 +02002350}
2351
Adrian Knoth0dca1792011-01-26 19:32:14 +01002352
2353/**
2354 * Returns the current preferred sync reference setting.
2355 * The semantics of the return value are depending on the
2356 * card, please see the comments for clarification.
2357 **/
Takashi Iwai98274f02005-11-17 14:52:34 +01002358static int hdspm_pref_sync_ref(struct hdspm * hdspm)
Takashi Iwai763f3562005-06-03 11:25:34 +02002359{
Adrian Knoth0dca1792011-01-26 19:32:14 +01002360 switch (hdspm->io_type) {
2361 case AES32:
Remy Bruno3cee5a62006-10-16 12:46:32 +02002362 switch (hdspm->control_register & HDSPM_SyncRefMask) {
Adrian Knoth0dca1792011-01-26 19:32:14 +01002363 case 0: return 0; /* WC */
2364 case HDSPM_SyncRef0: return 1; /* AES 1 */
2365 case HDSPM_SyncRef1: return 2; /* AES 2 */
2366 case HDSPM_SyncRef1+HDSPM_SyncRef0: return 3; /* AES 3 */
2367 case HDSPM_SyncRef2: return 4; /* AES 4 */
2368 case HDSPM_SyncRef2+HDSPM_SyncRef0: return 5; /* AES 5 */
2369 case HDSPM_SyncRef2+HDSPM_SyncRef1: return 6; /* AES 6 */
2370 case HDSPM_SyncRef2+HDSPM_SyncRef1+HDSPM_SyncRef0:
2371 return 7; /* AES 7 */
2372 case HDSPM_SyncRef3: return 8; /* AES 8 */
2373 case HDSPM_SyncRef3+HDSPM_SyncRef0: return 9; /* TCO */
Remy Bruno3cee5a62006-10-16 12:46:32 +02002374 }
Adrian Knoth0dca1792011-01-26 19:32:14 +01002375 break;
2376
2377 case MADI:
2378 case MADIface:
2379 if (hdspm->tco) {
2380 switch (hdspm->control_register & HDSPM_SyncRefMask) {
2381 case 0: return 0; /* WC */
2382 case HDSPM_SyncRef0: return 1; /* MADI */
2383 case HDSPM_SyncRef1: return 2; /* TCO */
2384 case HDSPM_SyncRef1+HDSPM_SyncRef0:
2385 return 3; /* SYNC_IN */
2386 }
2387 } else {
2388 switch (hdspm->control_register & HDSPM_SyncRefMask) {
2389 case 0: return 0; /* WC */
2390 case HDSPM_SyncRef0: return 1; /* MADI */
2391 case HDSPM_SyncRef1+HDSPM_SyncRef0:
2392 return 2; /* SYNC_IN */
2393 }
Remy Bruno3cee5a62006-10-16 12:46:32 +02002394 }
Adrian Knoth0dca1792011-01-26 19:32:14 +01002395 break;
2396
2397 case RayDAT:
2398 if (hdspm->tco) {
2399 switch ((hdspm->settings_register &
2400 HDSPM_c0_SyncRefMask) / HDSPM_c0_SyncRef0) {
2401 case 0: return 0; /* WC */
2402 case 3: return 1; /* ADAT 1 */
2403 case 4: return 2; /* ADAT 2 */
2404 case 5: return 3; /* ADAT 3 */
2405 case 6: return 4; /* ADAT 4 */
2406 case 1: return 5; /* AES */
2407 case 2: return 6; /* SPDIF */
2408 case 9: return 7; /* TCO */
2409 case 10: return 8; /* SYNC_IN */
2410 }
2411 } else {
2412 switch ((hdspm->settings_register &
2413 HDSPM_c0_SyncRefMask) / HDSPM_c0_SyncRef0) {
2414 case 0: return 0; /* WC */
2415 case 3: return 1; /* ADAT 1 */
2416 case 4: return 2; /* ADAT 2 */
2417 case 5: return 3; /* ADAT 3 */
2418 case 6: return 4; /* ADAT 4 */
2419 case 1: return 5; /* AES */
2420 case 2: return 6; /* SPDIF */
2421 case 10: return 7; /* SYNC_IN */
2422 }
2423 }
2424
2425 break;
2426
2427 case AIO:
2428 if (hdspm->tco) {
2429 switch ((hdspm->settings_register &
2430 HDSPM_c0_SyncRefMask) / HDSPM_c0_SyncRef0) {
2431 case 0: return 0; /* WC */
2432 case 3: return 1; /* ADAT */
2433 case 1: return 2; /* AES */
2434 case 2: return 3; /* SPDIF */
2435 case 9: return 4; /* TCO */
2436 case 10: return 5; /* SYNC_IN */
2437 }
2438 } else {
2439 switch ((hdspm->settings_register &
2440 HDSPM_c0_SyncRefMask) / HDSPM_c0_SyncRef0) {
2441 case 0: return 0; /* WC */
2442 case 3: return 1; /* ADAT */
2443 case 1: return 2; /* AES */
2444 case 2: return 3; /* SPDIF */
2445 case 10: return 4; /* SYNC_IN */
2446 }
2447 }
2448
2449 break;
Takashi Iwai763f3562005-06-03 11:25:34 +02002450 }
2451
Adrian Knoth0dca1792011-01-26 19:32:14 +01002452 return -1;
Takashi Iwai763f3562005-06-03 11:25:34 +02002453}
2454
Adrian Knoth0dca1792011-01-26 19:32:14 +01002455
2456/**
2457 * Set the preferred sync reference to <pref>. The semantics
2458 * of <pref> are depending on the card type, see the comments
2459 * for clarification.
2460 **/
Takashi Iwai98274f02005-11-17 14:52:34 +01002461static int hdspm_set_pref_sync_ref(struct hdspm * hdspm, int pref)
Takashi Iwai763f3562005-06-03 11:25:34 +02002462{
Adrian Knoth0dca1792011-01-26 19:32:14 +01002463 int p = 0;
Takashi Iwai763f3562005-06-03 11:25:34 +02002464
Adrian Knoth0dca1792011-01-26 19:32:14 +01002465 switch (hdspm->io_type) {
2466 case AES32:
2467 hdspm->control_register &= ~HDSPM_SyncRefMask;
Remy Bruno3cee5a62006-10-16 12:46:32 +02002468 switch (pref) {
Adrian Knoth0dca1792011-01-26 19:32:14 +01002469 case 0: /* WC */
Remy Bruno3cee5a62006-10-16 12:46:32 +02002470 break;
Adrian Knoth0dca1792011-01-26 19:32:14 +01002471 case 1: /* AES 1 */
2472 hdspm->control_register |= HDSPM_SyncRef0;
2473 break;
2474 case 2: /* AES 2 */
2475 hdspm->control_register |= HDSPM_SyncRef1;
2476 break;
2477 case 3: /* AES 3 */
2478 hdspm->control_register |=
2479 HDSPM_SyncRef1+HDSPM_SyncRef0;
2480 break;
2481 case 4: /* AES 4 */
2482 hdspm->control_register |= HDSPM_SyncRef2;
2483 break;
2484 case 5: /* AES 5 */
2485 hdspm->control_register |=
2486 HDSPM_SyncRef2+HDSPM_SyncRef0;
2487 break;
2488 case 6: /* AES 6 */
2489 hdspm->control_register |=
2490 HDSPM_SyncRef2+HDSPM_SyncRef1;
2491 break;
2492 case 7: /* AES 7 */
2493 hdspm->control_register |=
2494 HDSPM_SyncRef2+HDSPM_SyncRef1+HDSPM_SyncRef0;
2495 break;
2496 case 8: /* AES 8 */
2497 hdspm->control_register |= HDSPM_SyncRef3;
2498 break;
2499 case 9: /* TCO */
2500 hdspm->control_register |=
2501 HDSPM_SyncRef3+HDSPM_SyncRef0;
Remy Bruno3cee5a62006-10-16 12:46:32 +02002502 break;
2503 default:
2504 return -1;
2505 }
Adrian Knoth0dca1792011-01-26 19:32:14 +01002506
2507 break;
2508
2509 case MADI:
2510 case MADIface:
2511 hdspm->control_register &= ~HDSPM_SyncRefMask;
2512 if (hdspm->tco) {
2513 switch (pref) {
2514 case 0: /* WC */
2515 break;
2516 case 1: /* MADI */
2517 hdspm->control_register |= HDSPM_SyncRef0;
2518 break;
2519 case 2: /* TCO */
2520 hdspm->control_register |= HDSPM_SyncRef1;
2521 break;
2522 case 3: /* SYNC_IN */
2523 hdspm->control_register |=
2524 HDSPM_SyncRef0+HDSPM_SyncRef1;
2525 break;
2526 default:
2527 return -1;
2528 }
2529 } else {
2530 switch (pref) {
2531 case 0: /* WC */
2532 break;
2533 case 1: /* MADI */
2534 hdspm->control_register |= HDSPM_SyncRef0;
2535 break;
2536 case 2: /* SYNC_IN */
2537 hdspm->control_register |=
2538 HDSPM_SyncRef0+HDSPM_SyncRef1;
2539 break;
2540 default:
2541 return -1;
2542 }
2543 }
2544
2545 break;
2546
2547 case RayDAT:
2548 if (hdspm->tco) {
2549 switch (pref) {
2550 case 0: p = 0; break; /* WC */
2551 case 1: p = 3; break; /* ADAT 1 */
2552 case 2: p = 4; break; /* ADAT 2 */
2553 case 3: p = 5; break; /* ADAT 3 */
2554 case 4: p = 6; break; /* ADAT 4 */
2555 case 5: p = 1; break; /* AES */
2556 case 6: p = 2; break; /* SPDIF */
2557 case 7: p = 9; break; /* TCO */
2558 case 8: p = 10; break; /* SYNC_IN */
2559 default: return -1;
2560 }
2561 } else {
2562 switch (pref) {
2563 case 0: p = 0; break; /* WC */
2564 case 1: p = 3; break; /* ADAT 1 */
2565 case 2: p = 4; break; /* ADAT 2 */
2566 case 3: p = 5; break; /* ADAT 3 */
2567 case 4: p = 6; break; /* ADAT 4 */
2568 case 5: p = 1; break; /* AES */
2569 case 6: p = 2; break; /* SPDIF */
2570 case 7: p = 10; break; /* SYNC_IN */
2571 default: return -1;
2572 }
2573 }
2574 break;
2575
2576 case AIO:
2577 if (hdspm->tco) {
2578 switch (pref) {
2579 case 0: p = 0; break; /* WC */
2580 case 1: p = 3; break; /* ADAT */
2581 case 2: p = 1; break; /* AES */
2582 case 3: p = 2; break; /* SPDIF */
2583 case 4: p = 9; break; /* TCO */
2584 case 5: p = 10; break; /* SYNC_IN */
2585 default: return -1;
2586 }
2587 } else {
2588 switch (pref) {
2589 case 0: p = 0; break; /* WC */
2590 case 1: p = 3; break; /* ADAT */
2591 case 2: p = 1; break; /* AES */
2592 case 3: p = 2; break; /* SPDIF */
2593 case 4: p = 10; break; /* SYNC_IN */
2594 default: return -1;
2595 }
2596 }
2597 break;
Takashi Iwai763f3562005-06-03 11:25:34 +02002598 }
Adrian Knoth0dca1792011-01-26 19:32:14 +01002599
2600 switch (hdspm->io_type) {
2601 case RayDAT:
2602 case AIO:
2603 hdspm->settings_register &= ~HDSPM_c0_SyncRefMask;
2604 hdspm->settings_register |= HDSPM_c0_SyncRef0 * p;
2605 hdspm_write(hdspm, HDSPM_WR_SETTINGS, hdspm->settings_register);
2606 break;
2607
2608 case MADI:
2609 case MADIface:
2610 case AES32:
2611 hdspm_write(hdspm, HDSPM_controlRegister,
2612 hdspm->control_register);
2613 }
2614
Takashi Iwai763f3562005-06-03 11:25:34 +02002615 return 0;
2616}
2617
Adrian Knoth0dca1792011-01-26 19:32:14 +01002618
Takashi Iwai98274f02005-11-17 14:52:34 +01002619static int snd_hdspm_info_pref_sync_ref(struct snd_kcontrol *kcontrol,
2620 struct snd_ctl_elem_info *uinfo)
Takashi Iwai763f3562005-06-03 11:25:34 +02002621{
Remy Bruno3cee5a62006-10-16 12:46:32 +02002622 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
Takashi Iwai763f3562005-06-03 11:25:34 +02002623
Adrian Knoth0dca1792011-01-26 19:32:14 +01002624 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2625 uinfo->count = 1;
2626 uinfo->value.enumerated.items = hdspm->texts_autosync_items;
Takashi Iwai763f3562005-06-03 11:25:34 +02002627
Adrian Knoth0dca1792011-01-26 19:32:14 +01002628 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
2629 uinfo->value.enumerated.item =
2630 uinfo->value.enumerated.items - 1;
Takashi Iwai763f3562005-06-03 11:25:34 +02002631
Adrian Knoth0dca1792011-01-26 19:32:14 +01002632 strcpy(uinfo->value.enumerated.name,
2633 hdspm->texts_autosync[uinfo->value.enumerated.item]);
Remy Bruno3cee5a62006-10-16 12:46:32 +02002634
Takashi Iwai763f3562005-06-03 11:25:34 +02002635 return 0;
2636}
2637
Takashi Iwai98274f02005-11-17 14:52:34 +01002638static int snd_hdspm_get_pref_sync_ref(struct snd_kcontrol *kcontrol,
2639 struct snd_ctl_elem_value *ucontrol)
Takashi Iwai763f3562005-06-03 11:25:34 +02002640{
Takashi Iwai98274f02005-11-17 14:52:34 +01002641 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
Adrian Knoth0dca1792011-01-26 19:32:14 +01002642 int psf = hdspm_pref_sync_ref(hdspm);
Takashi Iwai763f3562005-06-03 11:25:34 +02002643
Adrian Knoth0dca1792011-01-26 19:32:14 +01002644 if (psf >= 0) {
2645 ucontrol->value.enumerated.item[0] = psf;
2646 return 0;
2647 }
2648
2649 return -1;
Takashi Iwai763f3562005-06-03 11:25:34 +02002650}
2651
Takashi Iwai98274f02005-11-17 14:52:34 +01002652static int snd_hdspm_put_pref_sync_ref(struct snd_kcontrol *kcontrol,
2653 struct snd_ctl_elem_value *ucontrol)
Takashi Iwai763f3562005-06-03 11:25:34 +02002654{
Takashi Iwai98274f02005-11-17 14:52:34 +01002655 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
Adrian Knoth0dca1792011-01-26 19:32:14 +01002656 int val, change = 0;
Takashi Iwai763f3562005-06-03 11:25:34 +02002657
2658 if (!snd_hdspm_use_is_exclusive(hdspm))
2659 return -EBUSY;
2660
Adrian Knoth0dca1792011-01-26 19:32:14 +01002661 val = ucontrol->value.enumerated.item[0];
2662
2663 if (val < 0)
2664 val = 0;
2665 else if (val >= hdspm->texts_autosync_items)
2666 val = hdspm->texts_autosync_items-1;
Takashi Iwai763f3562005-06-03 11:25:34 +02002667
2668 spin_lock_irq(&hdspm->lock);
Adrian Knoth0dca1792011-01-26 19:32:14 +01002669 if (val != hdspm_pref_sync_ref(hdspm))
2670 change = (0 == hdspm_set_pref_sync_ref(hdspm, val)) ? 1 : 0;
2671
Takashi Iwai763f3562005-06-03 11:25:34 +02002672 spin_unlock_irq(&hdspm->lock);
2673 return change;
2674}
2675
Adrian Knoth0dca1792011-01-26 19:32:14 +01002676
Takashi Iwai763f3562005-06-03 11:25:34 +02002677#define HDSPM_AUTOSYNC_REF(xname, xindex) \
Clemens Ladisch67ed4162005-07-29 15:32:58 +02002678{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
Takashi Iwai763f3562005-06-03 11:25:34 +02002679 .name = xname, \
2680 .index = xindex, \
2681 .access = SNDRV_CTL_ELEM_ACCESS_READ, \
2682 .info = snd_hdspm_info_autosync_ref, \
2683 .get = snd_hdspm_get_autosync_ref, \
2684}
2685
Adrian Knoth0dca1792011-01-26 19:32:14 +01002686static int hdspm_autosync_ref(struct hdspm *hdspm)
Takashi Iwai763f3562005-06-03 11:25:34 +02002687{
Adrian Knoth0dca1792011-01-26 19:32:14 +01002688 if (AES32 == hdspm->io_type) {
Remy Bruno3cee5a62006-10-16 12:46:32 +02002689 unsigned int status = hdspm_read(hdspm, HDSPM_statusRegister);
Adrian Knoth0dca1792011-01-26 19:32:14 +01002690 unsigned int syncref =
2691 (status >> HDSPM_AES32_syncref_bit) & 0xF;
Remy Bruno3cee5a62006-10-16 12:46:32 +02002692 if (syncref == 0)
2693 return HDSPM_AES32_AUTOSYNC_FROM_WORD;
2694 if (syncref <= 8)
2695 return syncref;
2696 return HDSPM_AES32_AUTOSYNC_FROM_NONE;
Adrian Knoth0dca1792011-01-26 19:32:14 +01002697 } else if (MADI == hdspm->io_type) {
Remy Bruno3cee5a62006-10-16 12:46:32 +02002698 /* This looks at the autosync selected sync reference */
2699 unsigned int status2 = hdspm_read(hdspm, HDSPM_statusRegister2);
Takashi Iwai763f3562005-06-03 11:25:34 +02002700
Remy Bruno3cee5a62006-10-16 12:46:32 +02002701 switch (status2 & HDSPM_SelSyncRefMask) {
2702 case HDSPM_SelSyncRef_WORD:
2703 return HDSPM_AUTOSYNC_FROM_WORD;
2704 case HDSPM_SelSyncRef_MADI:
2705 return HDSPM_AUTOSYNC_FROM_MADI;
Adrian Knoth0dca1792011-01-26 19:32:14 +01002706 case HDSPM_SelSyncRef_TCO:
2707 return HDSPM_AUTOSYNC_FROM_TCO;
2708 case HDSPM_SelSyncRef_SyncIn:
2709 return HDSPM_AUTOSYNC_FROM_SYNC_IN;
Remy Bruno3cee5a62006-10-16 12:46:32 +02002710 case HDSPM_SelSyncRef_NVALID:
2711 return HDSPM_AUTOSYNC_FROM_NONE;
2712 default:
2713 return 0;
2714 }
Takashi Iwai763f3562005-06-03 11:25:34 +02002715
Takashi Iwai763f3562005-06-03 11:25:34 +02002716 }
Adrian Knoth0dca1792011-01-26 19:32:14 +01002717 return 0;
Takashi Iwai763f3562005-06-03 11:25:34 +02002718}
2719
Adrian Knoth0dca1792011-01-26 19:32:14 +01002720
Takashi Iwai98274f02005-11-17 14:52:34 +01002721static int snd_hdspm_info_autosync_ref(struct snd_kcontrol *kcontrol,
2722 struct snd_ctl_elem_info *uinfo)
Takashi Iwai763f3562005-06-03 11:25:34 +02002723{
Remy Bruno3cee5a62006-10-16 12:46:32 +02002724 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
Takashi Iwai763f3562005-06-03 11:25:34 +02002725
Adrian Knoth0dca1792011-01-26 19:32:14 +01002726 if (AES32 == hdspm->io_type) {
Remy Bruno3cee5a62006-10-16 12:46:32 +02002727 static char *texts[] = { "WordClock", "AES1", "AES2", "AES3",
2728 "AES4", "AES5", "AES6", "AES7", "AES8", "None"};
2729
2730 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2731 uinfo->count = 1;
2732 uinfo->value.enumerated.items = 10;
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02002733 if (uinfo->value.enumerated.item >=
2734 uinfo->value.enumerated.items)
Remy Bruno3cee5a62006-10-16 12:46:32 +02002735 uinfo->value.enumerated.item =
2736 uinfo->value.enumerated.items - 1;
2737 strcpy(uinfo->value.enumerated.name,
2738 texts[uinfo->value.enumerated.item]);
Adrian Knoth0dca1792011-01-26 19:32:14 +01002739 } else if (MADI == hdspm->io_type) {
2740 static char *texts[] = {"Word Clock", "MADI", "TCO",
2741 "Sync In", "None" };
Remy Bruno3cee5a62006-10-16 12:46:32 +02002742
2743 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
2744 uinfo->count = 1;
Adrian Knoth0dca1792011-01-26 19:32:14 +01002745 uinfo->value.enumerated.items = 5;
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02002746 if (uinfo->value.enumerated.item >=
Adrian Knoth0dca1792011-01-26 19:32:14 +01002747 uinfo->value.enumerated.items)
Remy Bruno3cee5a62006-10-16 12:46:32 +02002748 uinfo->value.enumerated.item =
2749 uinfo->value.enumerated.items - 1;
2750 strcpy(uinfo->value.enumerated.name,
2751 texts[uinfo->value.enumerated.item]);
2752 }
Takashi Iwai763f3562005-06-03 11:25:34 +02002753 return 0;
2754}
2755
Takashi Iwai98274f02005-11-17 14:52:34 +01002756static int snd_hdspm_get_autosync_ref(struct snd_kcontrol *kcontrol,
2757 struct snd_ctl_elem_value *ucontrol)
Takashi Iwai763f3562005-06-03 11:25:34 +02002758{
Takashi Iwai98274f02005-11-17 14:52:34 +01002759 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
Takashi Iwai763f3562005-06-03 11:25:34 +02002760
Remy Bruno65345992007-08-31 12:21:08 +02002761 ucontrol->value.enumerated.item[0] = hdspm_autosync_ref(hdspm);
Takashi Iwai763f3562005-06-03 11:25:34 +02002762 return 0;
2763}
2764
Adrian Knoth0dca1792011-01-26 19:32:14 +01002765
Takashi Iwai763f3562005-06-03 11:25:34 +02002766#define HDSPM_LINE_OUT(xname, xindex) \
Clemens Ladisch67ed4162005-07-29 15:32:58 +02002767{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
Takashi Iwai763f3562005-06-03 11:25:34 +02002768 .name = xname, \
2769 .index = xindex, \
2770 .info = snd_hdspm_info_line_out, \
2771 .get = snd_hdspm_get_line_out, \
2772 .put = snd_hdspm_put_line_out \
2773}
2774
Takashi Iwai98274f02005-11-17 14:52:34 +01002775static int hdspm_line_out(struct hdspm * hdspm)
Takashi Iwai763f3562005-06-03 11:25:34 +02002776{
2777 return (hdspm->control_register & HDSPM_LineOut) ? 1 : 0;
2778}
2779
2780
Takashi Iwai98274f02005-11-17 14:52:34 +01002781static int hdspm_set_line_output(struct hdspm * hdspm, int out)
Takashi Iwai763f3562005-06-03 11:25:34 +02002782{
2783 if (out)
2784 hdspm->control_register |= HDSPM_LineOut;
2785 else
2786 hdspm->control_register &= ~HDSPM_LineOut;
2787 hdspm_write(hdspm, HDSPM_controlRegister, hdspm->control_register);
2788
2789 return 0;
2790}
2791
Takashi Iwaia5ce8892007-07-23 15:42:26 +02002792#define snd_hdspm_info_line_out snd_ctl_boolean_mono_info
Takashi Iwai763f3562005-06-03 11:25:34 +02002793
Takashi Iwai98274f02005-11-17 14:52:34 +01002794static int snd_hdspm_get_line_out(struct snd_kcontrol *kcontrol,
2795 struct snd_ctl_elem_value *ucontrol)
Takashi Iwai763f3562005-06-03 11:25:34 +02002796{
Takashi Iwai98274f02005-11-17 14:52:34 +01002797 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
Takashi Iwai763f3562005-06-03 11:25:34 +02002798
2799 spin_lock_irq(&hdspm->lock);
2800 ucontrol->value.integer.value[0] = hdspm_line_out(hdspm);
2801 spin_unlock_irq(&hdspm->lock);
2802 return 0;
2803}
2804
Takashi Iwai98274f02005-11-17 14:52:34 +01002805static int snd_hdspm_put_line_out(struct snd_kcontrol *kcontrol,
2806 struct snd_ctl_elem_value *ucontrol)
Takashi Iwai763f3562005-06-03 11:25:34 +02002807{
Takashi Iwai98274f02005-11-17 14:52:34 +01002808 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
Takashi Iwai763f3562005-06-03 11:25:34 +02002809 int change;
2810 unsigned int val;
2811
2812 if (!snd_hdspm_use_is_exclusive(hdspm))
2813 return -EBUSY;
2814 val = ucontrol->value.integer.value[0] & 1;
2815 spin_lock_irq(&hdspm->lock);
2816 change = (int) val != hdspm_line_out(hdspm);
2817 hdspm_set_line_output(hdspm, val);
2818 spin_unlock_irq(&hdspm->lock);
2819 return change;
2820}
2821
Adrian Knoth0dca1792011-01-26 19:32:14 +01002822
Takashi Iwai763f3562005-06-03 11:25:34 +02002823#define HDSPM_TX_64(xname, xindex) \
Clemens Ladisch67ed4162005-07-29 15:32:58 +02002824{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
Takashi Iwai763f3562005-06-03 11:25:34 +02002825 .name = xname, \
2826 .index = xindex, \
2827 .info = snd_hdspm_info_tx_64, \
2828 .get = snd_hdspm_get_tx_64, \
2829 .put = snd_hdspm_put_tx_64 \
2830}
2831
Takashi Iwai98274f02005-11-17 14:52:34 +01002832static int hdspm_tx_64(struct hdspm * hdspm)
Takashi Iwai763f3562005-06-03 11:25:34 +02002833{
2834 return (hdspm->control_register & HDSPM_TX_64ch) ? 1 : 0;
2835}
2836
Takashi Iwai98274f02005-11-17 14:52:34 +01002837static int hdspm_set_tx_64(struct hdspm * hdspm, int out)
Takashi Iwai763f3562005-06-03 11:25:34 +02002838{
2839 if (out)
2840 hdspm->control_register |= HDSPM_TX_64ch;
2841 else
2842 hdspm->control_register &= ~HDSPM_TX_64ch;
2843 hdspm_write(hdspm, HDSPM_controlRegister, hdspm->control_register);
2844
2845 return 0;
2846}
2847
Takashi Iwaia5ce8892007-07-23 15:42:26 +02002848#define snd_hdspm_info_tx_64 snd_ctl_boolean_mono_info
Takashi Iwai763f3562005-06-03 11:25:34 +02002849
Takashi Iwai98274f02005-11-17 14:52:34 +01002850static int snd_hdspm_get_tx_64(struct snd_kcontrol *kcontrol,
2851 struct snd_ctl_elem_value *ucontrol)
Takashi Iwai763f3562005-06-03 11:25:34 +02002852{
Takashi Iwai98274f02005-11-17 14:52:34 +01002853 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
Takashi Iwai763f3562005-06-03 11:25:34 +02002854
2855 spin_lock_irq(&hdspm->lock);
2856 ucontrol->value.integer.value[0] = hdspm_tx_64(hdspm);
2857 spin_unlock_irq(&hdspm->lock);
2858 return 0;
2859}
2860
Takashi Iwai98274f02005-11-17 14:52:34 +01002861static int snd_hdspm_put_tx_64(struct snd_kcontrol *kcontrol,
2862 struct snd_ctl_elem_value *ucontrol)
Takashi Iwai763f3562005-06-03 11:25:34 +02002863{
Takashi Iwai98274f02005-11-17 14:52:34 +01002864 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
Takashi Iwai763f3562005-06-03 11:25:34 +02002865 int change;
2866 unsigned int val;
2867
2868 if (!snd_hdspm_use_is_exclusive(hdspm))
2869 return -EBUSY;
2870 val = ucontrol->value.integer.value[0] & 1;
2871 spin_lock_irq(&hdspm->lock);
2872 change = (int) val != hdspm_tx_64(hdspm);
2873 hdspm_set_tx_64(hdspm, val);
2874 spin_unlock_irq(&hdspm->lock);
2875 return change;
2876}
2877
Adrian Knoth0dca1792011-01-26 19:32:14 +01002878
Takashi Iwai763f3562005-06-03 11:25:34 +02002879#define HDSPM_C_TMS(xname, xindex) \
Clemens Ladisch67ed4162005-07-29 15:32:58 +02002880{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
Takashi Iwai763f3562005-06-03 11:25:34 +02002881 .name = xname, \
2882 .index = xindex, \
2883 .info = snd_hdspm_info_c_tms, \
2884 .get = snd_hdspm_get_c_tms, \
2885 .put = snd_hdspm_put_c_tms \
2886}
2887
Takashi Iwai98274f02005-11-17 14:52:34 +01002888static int hdspm_c_tms(struct hdspm * hdspm)
Takashi Iwai763f3562005-06-03 11:25:34 +02002889{
2890 return (hdspm->control_register & HDSPM_clr_tms) ? 1 : 0;
2891}
2892
Takashi Iwai98274f02005-11-17 14:52:34 +01002893static int hdspm_set_c_tms(struct hdspm * hdspm, int out)
Takashi Iwai763f3562005-06-03 11:25:34 +02002894{
2895 if (out)
2896 hdspm->control_register |= HDSPM_clr_tms;
2897 else
2898 hdspm->control_register &= ~HDSPM_clr_tms;
2899 hdspm_write(hdspm, HDSPM_controlRegister, hdspm->control_register);
2900
2901 return 0;
2902}
2903
Takashi Iwaia5ce8892007-07-23 15:42:26 +02002904#define snd_hdspm_info_c_tms snd_ctl_boolean_mono_info
Takashi Iwai763f3562005-06-03 11:25:34 +02002905
Takashi Iwai98274f02005-11-17 14:52:34 +01002906static int snd_hdspm_get_c_tms(struct snd_kcontrol *kcontrol,
2907 struct snd_ctl_elem_value *ucontrol)
Takashi Iwai763f3562005-06-03 11:25:34 +02002908{
Takashi Iwai98274f02005-11-17 14:52:34 +01002909 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
Takashi Iwai763f3562005-06-03 11:25:34 +02002910
2911 spin_lock_irq(&hdspm->lock);
2912 ucontrol->value.integer.value[0] = hdspm_c_tms(hdspm);
2913 spin_unlock_irq(&hdspm->lock);
2914 return 0;
2915}
2916
Takashi Iwai98274f02005-11-17 14:52:34 +01002917static int snd_hdspm_put_c_tms(struct snd_kcontrol *kcontrol,
2918 struct snd_ctl_elem_value *ucontrol)
Takashi Iwai763f3562005-06-03 11:25:34 +02002919{
Takashi Iwai98274f02005-11-17 14:52:34 +01002920 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
Takashi Iwai763f3562005-06-03 11:25:34 +02002921 int change;
2922 unsigned int val;
2923
2924 if (!snd_hdspm_use_is_exclusive(hdspm))
2925 return -EBUSY;
2926 val = ucontrol->value.integer.value[0] & 1;
2927 spin_lock_irq(&hdspm->lock);
2928 change = (int) val != hdspm_c_tms(hdspm);
2929 hdspm_set_c_tms(hdspm, val);
2930 spin_unlock_irq(&hdspm->lock);
2931 return change;
2932}
2933
Adrian Knoth0dca1792011-01-26 19:32:14 +01002934
Takashi Iwai763f3562005-06-03 11:25:34 +02002935#define HDSPM_SAFE_MODE(xname, xindex) \
Clemens Ladisch67ed4162005-07-29 15:32:58 +02002936{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
Takashi Iwai763f3562005-06-03 11:25:34 +02002937 .name = xname, \
2938 .index = xindex, \
2939 .info = snd_hdspm_info_safe_mode, \
2940 .get = snd_hdspm_get_safe_mode, \
2941 .put = snd_hdspm_put_safe_mode \
2942}
2943
Takashi Iwai98274f02005-11-17 14:52:34 +01002944static int hdspm_safe_mode(struct hdspm * hdspm)
Takashi Iwai763f3562005-06-03 11:25:34 +02002945{
2946 return (hdspm->control_register & HDSPM_AutoInp) ? 1 : 0;
2947}
2948
Takashi Iwai98274f02005-11-17 14:52:34 +01002949static int hdspm_set_safe_mode(struct hdspm * hdspm, int out)
Takashi Iwai763f3562005-06-03 11:25:34 +02002950{
2951 if (out)
2952 hdspm->control_register |= HDSPM_AutoInp;
2953 else
2954 hdspm->control_register &= ~HDSPM_AutoInp;
2955 hdspm_write(hdspm, HDSPM_controlRegister, hdspm->control_register);
2956
2957 return 0;
2958}
2959
Takashi Iwaia5ce8892007-07-23 15:42:26 +02002960#define snd_hdspm_info_safe_mode snd_ctl_boolean_mono_info
Takashi Iwai763f3562005-06-03 11:25:34 +02002961
Takashi Iwai98274f02005-11-17 14:52:34 +01002962static int snd_hdspm_get_safe_mode(struct snd_kcontrol *kcontrol,
2963 struct snd_ctl_elem_value *ucontrol)
Takashi Iwai763f3562005-06-03 11:25:34 +02002964{
Takashi Iwai98274f02005-11-17 14:52:34 +01002965 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
Takashi Iwai763f3562005-06-03 11:25:34 +02002966
2967 spin_lock_irq(&hdspm->lock);
2968 ucontrol->value.integer.value[0] = hdspm_safe_mode(hdspm);
2969 spin_unlock_irq(&hdspm->lock);
2970 return 0;
2971}
2972
Takashi Iwai98274f02005-11-17 14:52:34 +01002973static int snd_hdspm_put_safe_mode(struct snd_kcontrol *kcontrol,
2974 struct snd_ctl_elem_value *ucontrol)
Takashi Iwai763f3562005-06-03 11:25:34 +02002975{
Takashi Iwai98274f02005-11-17 14:52:34 +01002976 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
Takashi Iwai763f3562005-06-03 11:25:34 +02002977 int change;
2978 unsigned int val;
2979
2980 if (!snd_hdspm_use_is_exclusive(hdspm))
2981 return -EBUSY;
2982 val = ucontrol->value.integer.value[0] & 1;
2983 spin_lock_irq(&hdspm->lock);
2984 change = (int) val != hdspm_safe_mode(hdspm);
2985 hdspm_set_safe_mode(hdspm, val);
2986 spin_unlock_irq(&hdspm->lock);
2987 return change;
2988}
2989
Adrian Knoth0dca1792011-01-26 19:32:14 +01002990
Remy Bruno3cee5a62006-10-16 12:46:32 +02002991#define HDSPM_EMPHASIS(xname, xindex) \
2992{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2993 .name = xname, \
2994 .index = xindex, \
2995 .info = snd_hdspm_info_emphasis, \
2996 .get = snd_hdspm_get_emphasis, \
2997 .put = snd_hdspm_put_emphasis \
2998}
2999
3000static int hdspm_emphasis(struct hdspm * hdspm)
3001{
3002 return (hdspm->control_register & HDSPM_Emphasis) ? 1 : 0;
3003}
3004
3005static int hdspm_set_emphasis(struct hdspm * hdspm, int emp)
3006{
3007 if (emp)
3008 hdspm->control_register |= HDSPM_Emphasis;
3009 else
3010 hdspm->control_register &= ~HDSPM_Emphasis;
3011 hdspm_write(hdspm, HDSPM_controlRegister, hdspm->control_register);
3012
3013 return 0;
3014}
3015
Takashi Iwaia5ce8892007-07-23 15:42:26 +02003016#define snd_hdspm_info_emphasis snd_ctl_boolean_mono_info
Remy Bruno3cee5a62006-10-16 12:46:32 +02003017
3018static int snd_hdspm_get_emphasis(struct snd_kcontrol *kcontrol,
3019 struct snd_ctl_elem_value *ucontrol)
3020{
3021 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
3022
3023 spin_lock_irq(&hdspm->lock);
3024 ucontrol->value.enumerated.item[0] = hdspm_emphasis(hdspm);
3025 spin_unlock_irq(&hdspm->lock);
3026 return 0;
3027}
3028
3029static int snd_hdspm_put_emphasis(struct snd_kcontrol *kcontrol,
3030 struct snd_ctl_elem_value *ucontrol)
3031{
3032 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
3033 int change;
3034 unsigned int val;
3035
3036 if (!snd_hdspm_use_is_exclusive(hdspm))
3037 return -EBUSY;
3038 val = ucontrol->value.integer.value[0] & 1;
3039 spin_lock_irq(&hdspm->lock);
3040 change = (int) val != hdspm_emphasis(hdspm);
3041 hdspm_set_emphasis(hdspm, val);
3042 spin_unlock_irq(&hdspm->lock);
3043 return change;
3044}
3045
Adrian Knoth0dca1792011-01-26 19:32:14 +01003046
Remy Bruno3cee5a62006-10-16 12:46:32 +02003047#define HDSPM_DOLBY(xname, xindex) \
3048{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
3049 .name = xname, \
3050 .index = xindex, \
3051 .info = snd_hdspm_info_dolby, \
3052 .get = snd_hdspm_get_dolby, \
3053 .put = snd_hdspm_put_dolby \
3054}
3055
3056static int hdspm_dolby(struct hdspm * hdspm)
3057{
3058 return (hdspm->control_register & HDSPM_Dolby) ? 1 : 0;
3059}
3060
3061static int hdspm_set_dolby(struct hdspm * hdspm, int dol)
3062{
3063 if (dol)
3064 hdspm->control_register |= HDSPM_Dolby;
3065 else
3066 hdspm->control_register &= ~HDSPM_Dolby;
3067 hdspm_write(hdspm, HDSPM_controlRegister, hdspm->control_register);
3068
3069 return 0;
3070}
3071
Takashi Iwaia5ce8892007-07-23 15:42:26 +02003072#define snd_hdspm_info_dolby snd_ctl_boolean_mono_info
Remy Bruno3cee5a62006-10-16 12:46:32 +02003073
3074static int snd_hdspm_get_dolby(struct snd_kcontrol *kcontrol,
3075 struct snd_ctl_elem_value *ucontrol)
3076{
3077 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
3078
3079 spin_lock_irq(&hdspm->lock);
3080 ucontrol->value.enumerated.item[0] = hdspm_dolby(hdspm);
3081 spin_unlock_irq(&hdspm->lock);
3082 return 0;
3083}
3084
3085static int snd_hdspm_put_dolby(struct snd_kcontrol *kcontrol,
3086 struct snd_ctl_elem_value *ucontrol)
3087{
3088 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
3089 int change;
3090 unsigned int val;
3091
3092 if (!snd_hdspm_use_is_exclusive(hdspm))
3093 return -EBUSY;
3094 val = ucontrol->value.integer.value[0] & 1;
3095 spin_lock_irq(&hdspm->lock);
3096 change = (int) val != hdspm_dolby(hdspm);
3097 hdspm_set_dolby(hdspm, val);
3098 spin_unlock_irq(&hdspm->lock);
3099 return change;
3100}
3101
Adrian Knoth0dca1792011-01-26 19:32:14 +01003102
Remy Bruno3cee5a62006-10-16 12:46:32 +02003103#define HDSPM_PROFESSIONAL(xname, xindex) \
3104{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
3105 .name = xname, \
3106 .index = xindex, \
3107 .info = snd_hdspm_info_professional, \
3108 .get = snd_hdspm_get_professional, \
3109 .put = snd_hdspm_put_professional \
3110}
3111
3112static int hdspm_professional(struct hdspm * hdspm)
3113{
3114 return (hdspm->control_register & HDSPM_Professional) ? 1 : 0;
3115}
3116
3117static int hdspm_set_professional(struct hdspm * hdspm, int dol)
3118{
3119 if (dol)
3120 hdspm->control_register |= HDSPM_Professional;
3121 else
3122 hdspm->control_register &= ~HDSPM_Professional;
3123 hdspm_write(hdspm, HDSPM_controlRegister, hdspm->control_register);
3124
3125 return 0;
3126}
3127
Takashi Iwaia5ce8892007-07-23 15:42:26 +02003128#define snd_hdspm_info_professional snd_ctl_boolean_mono_info
Remy Bruno3cee5a62006-10-16 12:46:32 +02003129
3130static int snd_hdspm_get_professional(struct snd_kcontrol *kcontrol,
3131 struct snd_ctl_elem_value *ucontrol)
3132{
3133 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
3134
3135 spin_lock_irq(&hdspm->lock);
3136 ucontrol->value.enumerated.item[0] = hdspm_professional(hdspm);
3137 spin_unlock_irq(&hdspm->lock);
3138 return 0;
3139}
3140
3141static int snd_hdspm_put_professional(struct snd_kcontrol *kcontrol,
3142 struct snd_ctl_elem_value *ucontrol)
3143{
3144 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
3145 int change;
3146 unsigned int val;
3147
3148 if (!snd_hdspm_use_is_exclusive(hdspm))
3149 return -EBUSY;
3150 val = ucontrol->value.integer.value[0] & 1;
3151 spin_lock_irq(&hdspm->lock);
3152 change = (int) val != hdspm_professional(hdspm);
3153 hdspm_set_professional(hdspm, val);
3154 spin_unlock_irq(&hdspm->lock);
3155 return change;
3156}
3157
Takashi Iwai763f3562005-06-03 11:25:34 +02003158#define HDSPM_INPUT_SELECT(xname, xindex) \
Clemens Ladisch67ed4162005-07-29 15:32:58 +02003159{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
Takashi Iwai763f3562005-06-03 11:25:34 +02003160 .name = xname, \
3161 .index = xindex, \
3162 .info = snd_hdspm_info_input_select, \
3163 .get = snd_hdspm_get_input_select, \
3164 .put = snd_hdspm_put_input_select \
3165}
3166
Takashi Iwai98274f02005-11-17 14:52:34 +01003167static int hdspm_input_select(struct hdspm * hdspm)
Takashi Iwai763f3562005-06-03 11:25:34 +02003168{
3169 return (hdspm->control_register & HDSPM_InputSelect0) ? 1 : 0;
3170}
3171
Takashi Iwai98274f02005-11-17 14:52:34 +01003172static int hdspm_set_input_select(struct hdspm * hdspm, int out)
Takashi Iwai763f3562005-06-03 11:25:34 +02003173{
3174 if (out)
3175 hdspm->control_register |= HDSPM_InputSelect0;
3176 else
3177 hdspm->control_register &= ~HDSPM_InputSelect0;
3178 hdspm_write(hdspm, HDSPM_controlRegister, hdspm->control_register);
3179
3180 return 0;
3181}
3182
Takashi Iwai98274f02005-11-17 14:52:34 +01003183static int snd_hdspm_info_input_select(struct snd_kcontrol *kcontrol,
3184 struct snd_ctl_elem_info *uinfo)
Takashi Iwai763f3562005-06-03 11:25:34 +02003185{
3186 static char *texts[] = { "optical", "coaxial" };
3187
3188 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
3189 uinfo->count = 1;
3190 uinfo->value.enumerated.items = 2;
3191
3192 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
3193 uinfo->value.enumerated.item =
3194 uinfo->value.enumerated.items - 1;
3195 strcpy(uinfo->value.enumerated.name,
3196 texts[uinfo->value.enumerated.item]);
3197
3198 return 0;
3199}
3200
Takashi Iwai98274f02005-11-17 14:52:34 +01003201static int snd_hdspm_get_input_select(struct snd_kcontrol *kcontrol,
3202 struct snd_ctl_elem_value *ucontrol)
Takashi Iwai763f3562005-06-03 11:25:34 +02003203{
Takashi Iwai98274f02005-11-17 14:52:34 +01003204 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
Takashi Iwai763f3562005-06-03 11:25:34 +02003205
3206 spin_lock_irq(&hdspm->lock);
3207 ucontrol->value.enumerated.item[0] = hdspm_input_select(hdspm);
3208 spin_unlock_irq(&hdspm->lock);
3209 return 0;
3210}
3211
Takashi Iwai98274f02005-11-17 14:52:34 +01003212static int snd_hdspm_put_input_select(struct snd_kcontrol *kcontrol,
3213 struct snd_ctl_elem_value *ucontrol)
Takashi Iwai763f3562005-06-03 11:25:34 +02003214{
Takashi Iwai98274f02005-11-17 14:52:34 +01003215 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
Takashi Iwai763f3562005-06-03 11:25:34 +02003216 int change;
3217 unsigned int val;
3218
3219 if (!snd_hdspm_use_is_exclusive(hdspm))
3220 return -EBUSY;
3221 val = ucontrol->value.integer.value[0] & 1;
3222 spin_lock_irq(&hdspm->lock);
3223 change = (int) val != hdspm_input_select(hdspm);
3224 hdspm_set_input_select(hdspm, val);
3225 spin_unlock_irq(&hdspm->lock);
3226 return change;
3227}
3228
Adrian Knoth0dca1792011-01-26 19:32:14 +01003229
Remy Bruno3cee5a62006-10-16 12:46:32 +02003230#define HDSPM_DS_WIRE(xname, xindex) \
3231{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
3232 .name = xname, \
3233 .index = xindex, \
3234 .info = snd_hdspm_info_ds_wire, \
3235 .get = snd_hdspm_get_ds_wire, \
3236 .put = snd_hdspm_put_ds_wire \
3237}
3238
3239static int hdspm_ds_wire(struct hdspm * hdspm)
3240{
3241 return (hdspm->control_register & HDSPM_DS_DoubleWire) ? 1 : 0;
3242}
3243
3244static int hdspm_set_ds_wire(struct hdspm * hdspm, int ds)
3245{
3246 if (ds)
3247 hdspm->control_register |= HDSPM_DS_DoubleWire;
3248 else
3249 hdspm->control_register &= ~HDSPM_DS_DoubleWire;
3250 hdspm_write(hdspm, HDSPM_controlRegister, hdspm->control_register);
3251
3252 return 0;
3253}
3254
3255static int snd_hdspm_info_ds_wire(struct snd_kcontrol *kcontrol,
3256 struct snd_ctl_elem_info *uinfo)
3257{
3258 static char *texts[] = { "Single", "Double" };
3259
3260 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
3261 uinfo->count = 1;
3262 uinfo->value.enumerated.items = 2;
3263
3264 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
3265 uinfo->value.enumerated.item =
3266 uinfo->value.enumerated.items - 1;
3267 strcpy(uinfo->value.enumerated.name,
3268 texts[uinfo->value.enumerated.item]);
3269
3270 return 0;
3271}
3272
3273static int snd_hdspm_get_ds_wire(struct snd_kcontrol *kcontrol,
3274 struct snd_ctl_elem_value *ucontrol)
3275{
3276 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
3277
3278 spin_lock_irq(&hdspm->lock);
3279 ucontrol->value.enumerated.item[0] = hdspm_ds_wire(hdspm);
3280 spin_unlock_irq(&hdspm->lock);
3281 return 0;
3282}
3283
3284static int snd_hdspm_put_ds_wire(struct snd_kcontrol *kcontrol,
3285 struct snd_ctl_elem_value *ucontrol)
3286{
3287 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
3288 int change;
3289 unsigned int val;
3290
3291 if (!snd_hdspm_use_is_exclusive(hdspm))
3292 return -EBUSY;
3293 val = ucontrol->value.integer.value[0] & 1;
3294 spin_lock_irq(&hdspm->lock);
3295 change = (int) val != hdspm_ds_wire(hdspm);
3296 hdspm_set_ds_wire(hdspm, val);
3297 spin_unlock_irq(&hdspm->lock);
3298 return change;
3299}
3300
Adrian Knoth0dca1792011-01-26 19:32:14 +01003301
Remy Bruno3cee5a62006-10-16 12:46:32 +02003302#define HDSPM_QS_WIRE(xname, xindex) \
3303{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
3304 .name = xname, \
3305 .index = xindex, \
3306 .info = snd_hdspm_info_qs_wire, \
3307 .get = snd_hdspm_get_qs_wire, \
3308 .put = snd_hdspm_put_qs_wire \
3309}
3310
3311static int hdspm_qs_wire(struct hdspm * hdspm)
3312{
3313 if (hdspm->control_register & HDSPM_QS_DoubleWire)
3314 return 1;
3315 if (hdspm->control_register & HDSPM_QS_QuadWire)
3316 return 2;
3317 return 0;
3318}
3319
3320static int hdspm_set_qs_wire(struct hdspm * hdspm, int mode)
3321{
3322 hdspm->control_register &= ~(HDSPM_QS_DoubleWire | HDSPM_QS_QuadWire);
3323 switch (mode) {
3324 case 0:
3325 break;
3326 case 1:
3327 hdspm->control_register |= HDSPM_QS_DoubleWire;
3328 break;
3329 case 2:
3330 hdspm->control_register |= HDSPM_QS_QuadWire;
3331 break;
3332 }
3333 hdspm_write(hdspm, HDSPM_controlRegister, hdspm->control_register);
3334
3335 return 0;
3336}
3337
3338static int snd_hdspm_info_qs_wire(struct snd_kcontrol *kcontrol,
3339 struct snd_ctl_elem_info *uinfo)
3340{
3341 static char *texts[] = { "Single", "Double", "Quad" };
3342
3343 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
3344 uinfo->count = 1;
3345 uinfo->value.enumerated.items = 3;
3346
3347 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
3348 uinfo->value.enumerated.item =
3349 uinfo->value.enumerated.items - 1;
3350 strcpy(uinfo->value.enumerated.name,
3351 texts[uinfo->value.enumerated.item]);
3352
3353 return 0;
3354}
3355
3356static int snd_hdspm_get_qs_wire(struct snd_kcontrol *kcontrol,
3357 struct snd_ctl_elem_value *ucontrol)
3358{
3359 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
3360
3361 spin_lock_irq(&hdspm->lock);
3362 ucontrol->value.enumerated.item[0] = hdspm_qs_wire(hdspm);
3363 spin_unlock_irq(&hdspm->lock);
3364 return 0;
3365}
3366
3367static int snd_hdspm_put_qs_wire(struct snd_kcontrol *kcontrol,
3368 struct snd_ctl_elem_value *ucontrol)
3369{
3370 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
3371 int change;
3372 int val;
3373
3374 if (!snd_hdspm_use_is_exclusive(hdspm))
3375 return -EBUSY;
3376 val = ucontrol->value.integer.value[0];
3377 if (val < 0)
3378 val = 0;
3379 if (val > 2)
3380 val = 2;
3381 spin_lock_irq(&hdspm->lock);
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02003382 change = val != hdspm_qs_wire(hdspm);
Remy Bruno3cee5a62006-10-16 12:46:32 +02003383 hdspm_set_qs_wire(hdspm, val);
3384 spin_unlock_irq(&hdspm->lock);
3385 return change;
3386}
3387
Takashi Iwai763f3562005-06-03 11:25:34 +02003388
3389#define HDSPM_MIXER(xname, xindex) \
3390{ .iface = SNDRV_CTL_ELEM_IFACE_HWDEP, \
3391 .name = xname, \
3392 .index = xindex, \
Clemens Ladisch67ed4162005-07-29 15:32:58 +02003393 .device = 0, \
Takashi Iwai763f3562005-06-03 11:25:34 +02003394 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | \
3395 SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
3396 .info = snd_hdspm_info_mixer, \
3397 .get = snd_hdspm_get_mixer, \
3398 .put = snd_hdspm_put_mixer \
3399}
3400
Takashi Iwai98274f02005-11-17 14:52:34 +01003401static int snd_hdspm_info_mixer(struct snd_kcontrol *kcontrol,
3402 struct snd_ctl_elem_info *uinfo)
Takashi Iwai763f3562005-06-03 11:25:34 +02003403{
3404 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
3405 uinfo->count = 3;
3406 uinfo->value.integer.min = 0;
3407 uinfo->value.integer.max = 65535;
3408 uinfo->value.integer.step = 1;
3409 return 0;
3410}
3411
Takashi Iwai98274f02005-11-17 14:52:34 +01003412static int snd_hdspm_get_mixer(struct snd_kcontrol *kcontrol,
3413 struct snd_ctl_elem_value *ucontrol)
Takashi Iwai763f3562005-06-03 11:25:34 +02003414{
Takashi Iwai98274f02005-11-17 14:52:34 +01003415 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
Takashi Iwai763f3562005-06-03 11:25:34 +02003416 int source;
3417 int destination;
3418
3419 source = ucontrol->value.integer.value[0];
3420 if (source < 0)
3421 source = 0;
3422 else if (source >= 2 * HDSPM_MAX_CHANNELS)
3423 source = 2 * HDSPM_MAX_CHANNELS - 1;
3424
3425 destination = ucontrol->value.integer.value[1];
3426 if (destination < 0)
3427 destination = 0;
3428 else if (destination >= HDSPM_MAX_CHANNELS)
3429 destination = HDSPM_MAX_CHANNELS - 1;
3430
3431 spin_lock_irq(&hdspm->lock);
3432 if (source >= HDSPM_MAX_CHANNELS)
3433 ucontrol->value.integer.value[2] =
3434 hdspm_read_pb_gain(hdspm, destination,
3435 source - HDSPM_MAX_CHANNELS);
3436 else
3437 ucontrol->value.integer.value[2] =
3438 hdspm_read_in_gain(hdspm, destination, source);
3439
3440 spin_unlock_irq(&hdspm->lock);
3441
3442 return 0;
3443}
3444
Takashi Iwai98274f02005-11-17 14:52:34 +01003445static int snd_hdspm_put_mixer(struct snd_kcontrol *kcontrol,
3446 struct snd_ctl_elem_value *ucontrol)
Takashi Iwai763f3562005-06-03 11:25:34 +02003447{
Takashi Iwai98274f02005-11-17 14:52:34 +01003448 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
Takashi Iwai763f3562005-06-03 11:25:34 +02003449 int change;
3450 int source;
3451 int destination;
3452 int gain;
3453
3454 if (!snd_hdspm_use_is_exclusive(hdspm))
3455 return -EBUSY;
3456
3457 source = ucontrol->value.integer.value[0];
3458 destination = ucontrol->value.integer.value[1];
3459
3460 if (source < 0 || source >= 2 * HDSPM_MAX_CHANNELS)
3461 return -1;
3462 if (destination < 0 || destination >= HDSPM_MAX_CHANNELS)
3463 return -1;
3464
3465 gain = ucontrol->value.integer.value[2];
3466
3467 spin_lock_irq(&hdspm->lock);
3468
3469 if (source >= HDSPM_MAX_CHANNELS)
3470 change = gain != hdspm_read_pb_gain(hdspm, destination,
3471 source -
3472 HDSPM_MAX_CHANNELS);
3473 else
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02003474 change = gain != hdspm_read_in_gain(hdspm, destination,
3475 source);
Takashi Iwai763f3562005-06-03 11:25:34 +02003476
3477 if (change) {
3478 if (source >= HDSPM_MAX_CHANNELS)
3479 hdspm_write_pb_gain(hdspm, destination,
3480 source - HDSPM_MAX_CHANNELS,
3481 gain);
3482 else
3483 hdspm_write_in_gain(hdspm, destination, source,
3484 gain);
3485 }
3486 spin_unlock_irq(&hdspm->lock);
3487
3488 return change;
3489}
3490
3491/* The simple mixer control(s) provide gain control for the
3492 basic 1:1 mappings of playback streams to output
Adrian Knoth0dca1792011-01-26 19:32:14 +01003493 streams.
Takashi Iwai763f3562005-06-03 11:25:34 +02003494*/
3495
3496#define HDSPM_PLAYBACK_MIXER \
3497{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
3498 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_WRITE | \
3499 SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
3500 .info = snd_hdspm_info_playback_mixer, \
3501 .get = snd_hdspm_get_playback_mixer, \
3502 .put = snd_hdspm_put_playback_mixer \
3503}
3504
Takashi Iwai98274f02005-11-17 14:52:34 +01003505static int snd_hdspm_info_playback_mixer(struct snd_kcontrol *kcontrol,
3506 struct snd_ctl_elem_info *uinfo)
Takashi Iwai763f3562005-06-03 11:25:34 +02003507{
3508 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
3509 uinfo->count = 1;
3510 uinfo->value.integer.min = 0;
Adrian Knoth0dca1792011-01-26 19:32:14 +01003511 uinfo->value.integer.max = 64;
Takashi Iwai763f3562005-06-03 11:25:34 +02003512 uinfo->value.integer.step = 1;
3513 return 0;
3514}
3515
Takashi Iwai98274f02005-11-17 14:52:34 +01003516static int snd_hdspm_get_playback_mixer(struct snd_kcontrol *kcontrol,
3517 struct snd_ctl_elem_value *ucontrol)
Takashi Iwai763f3562005-06-03 11:25:34 +02003518{
Takashi Iwai98274f02005-11-17 14:52:34 +01003519 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
Takashi Iwai763f3562005-06-03 11:25:34 +02003520 int channel;
Takashi Iwai763f3562005-06-03 11:25:34 +02003521
3522 channel = ucontrol->id.index - 1;
3523
Takashi Iwaida3cec32008-08-08 17:12:14 +02003524 if (snd_BUG_ON(channel < 0 || channel >= HDSPM_MAX_CHANNELS))
3525 return -EINVAL;
Takashi Iwai763f3562005-06-03 11:25:34 +02003526
Takashi Iwai763f3562005-06-03 11:25:34 +02003527 spin_lock_irq(&hdspm->lock);
3528 ucontrol->value.integer.value[0] =
Adrian Knoth0dca1792011-01-26 19:32:14 +01003529 (hdspm_read_pb_gain(hdspm, channel, channel)*64)/UNITY_GAIN;
Takashi Iwai763f3562005-06-03 11:25:34 +02003530 spin_unlock_irq(&hdspm->lock);
3531
Takashi Iwai763f3562005-06-03 11:25:34 +02003532 return 0;
3533}
3534
Takashi Iwai98274f02005-11-17 14:52:34 +01003535static int snd_hdspm_put_playback_mixer(struct snd_kcontrol *kcontrol,
3536 struct snd_ctl_elem_value *ucontrol)
Takashi Iwai763f3562005-06-03 11:25:34 +02003537{
Takashi Iwai98274f02005-11-17 14:52:34 +01003538 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
Takashi Iwai763f3562005-06-03 11:25:34 +02003539 int change;
3540 int channel;
Takashi Iwai763f3562005-06-03 11:25:34 +02003541 int gain;
3542
3543 if (!snd_hdspm_use_is_exclusive(hdspm))
3544 return -EBUSY;
3545
3546 channel = ucontrol->id.index - 1;
3547
Takashi Iwaida3cec32008-08-08 17:12:14 +02003548 if (snd_BUG_ON(channel < 0 || channel >= HDSPM_MAX_CHANNELS))
3549 return -EINVAL;
Takashi Iwai763f3562005-06-03 11:25:34 +02003550
Adrian Knoth0dca1792011-01-26 19:32:14 +01003551 gain = ucontrol->value.integer.value[0]*UNITY_GAIN/64;
Takashi Iwai763f3562005-06-03 11:25:34 +02003552
3553 spin_lock_irq(&hdspm->lock);
3554 change =
Adrian Knoth0dca1792011-01-26 19:32:14 +01003555 gain != hdspm_read_pb_gain(hdspm, channel,
3556 channel);
Takashi Iwai763f3562005-06-03 11:25:34 +02003557 if (change)
Adrian Knoth0dca1792011-01-26 19:32:14 +01003558 hdspm_write_pb_gain(hdspm, channel, channel,
Takashi Iwai763f3562005-06-03 11:25:34 +02003559 gain);
3560 spin_unlock_irq(&hdspm->lock);
3561 return change;
3562}
3563
Adrian Knoth0dca1792011-01-26 19:32:14 +01003564#define HDSPM_SYNC_CHECK(xname, xindex) \
3565{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
3566 .name = xname, \
3567 .private_value = xindex, \
3568 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
3569 .info = snd_hdspm_info_sync_check, \
3570 .get = snd_hdspm_get_sync_check \
Takashi Iwai763f3562005-06-03 11:25:34 +02003571}
3572
Adrian Knoth0dca1792011-01-26 19:32:14 +01003573
Takashi Iwai98274f02005-11-17 14:52:34 +01003574static int snd_hdspm_info_sync_check(struct snd_kcontrol *kcontrol,
3575 struct snd_ctl_elem_info *uinfo)
Takashi Iwai763f3562005-06-03 11:25:34 +02003576{
Adrian Knoth0dca1792011-01-26 19:32:14 +01003577 static char *texts[] = { "No Lock", "Lock", "Sync", "N/A" };
Takashi Iwai763f3562005-06-03 11:25:34 +02003578 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
3579 uinfo->count = 1;
Adrian Knoth0dca1792011-01-26 19:32:14 +01003580 uinfo->value.enumerated.items = 4;
Takashi Iwai763f3562005-06-03 11:25:34 +02003581 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
3582 uinfo->value.enumerated.item =
Adrian Knoth0dca1792011-01-26 19:32:14 +01003583 uinfo->value.enumerated.items - 1;
Takashi Iwai763f3562005-06-03 11:25:34 +02003584 strcpy(uinfo->value.enumerated.name,
Adrian Knoth0dca1792011-01-26 19:32:14 +01003585 texts[uinfo->value.enumerated.item]);
Takashi Iwai763f3562005-06-03 11:25:34 +02003586 return 0;
3587}
3588
Adrian Knoth0dca1792011-01-26 19:32:14 +01003589static int hdspm_wc_sync_check(struct hdspm *hdspm)
Takashi Iwai763f3562005-06-03 11:25:34 +02003590{
Adrian Knoth0dca1792011-01-26 19:32:14 +01003591 int status, status2;
3592
3593 switch (hdspm->io_type) {
3594 case AES32:
3595 status = hdspm_read(hdspm, HDSPM_statusRegister);
3596 if (status & HDSPM_wcSync)
Takashi Iwai763f3562005-06-03 11:25:34 +02003597 return 2;
Adrian Knoth0dca1792011-01-26 19:32:14 +01003598 else if (status & HDSPM_wcLock)
3599 return 1;
Remy Bruno3cee5a62006-10-16 12:46:32 +02003600 return 0;
Adrian Knoth0dca1792011-01-26 19:32:14 +01003601 break;
3602
3603 case MADI:
3604 status2 = hdspm_read(hdspm, HDSPM_statusRegister2);
Remy Bruno3cee5a62006-10-16 12:46:32 +02003605 if (status2 & HDSPM_wcLock) {
3606 if (status2 & HDSPM_wcSync)
3607 return 2;
3608 else
3609 return 1;
3610 }
3611 return 0;
Adrian Knoth0dca1792011-01-26 19:32:14 +01003612 break;
3613
3614 case RayDAT:
3615 case AIO:
3616 status = hdspm_read(hdspm, HDSPM_statusRegister);
3617
3618 if (status & 0x2000000)
3619 return 2;
3620 else if (status & 0x1000000)
3621 return 1;
3622 return 0;
3623
3624 break;
3625
3626 case MADIface:
3627 break;
Takashi Iwai763f3562005-06-03 11:25:34 +02003628 }
Takashi Iwai763f3562005-06-03 11:25:34 +02003629
Takashi Iwai763f3562005-06-03 11:25:34 +02003630
Adrian Knoth0dca1792011-01-26 19:32:14 +01003631 return 3;
Takashi Iwai763f3562005-06-03 11:25:34 +02003632}
3633
3634
Adrian Knoth0dca1792011-01-26 19:32:14 +01003635static int hdspm_madi_sync_check(struct hdspm *hdspm)
Takashi Iwai763f3562005-06-03 11:25:34 +02003636{
3637 int status = hdspm_read(hdspm, HDSPM_statusRegister);
3638 if (status & HDSPM_madiLock) {
3639 if (status & HDSPM_madiSync)
3640 return 2;
3641 else
3642 return 1;
3643 }
3644 return 0;
3645}
3646
Adrian Knoth0dca1792011-01-26 19:32:14 +01003647
3648static int hdspm_s1_sync_check(struct hdspm *hdspm, int idx)
3649{
3650 int status, lock, sync;
3651
3652 status = hdspm_read(hdspm, HDSPM_RD_STATUS_1);
3653
3654 lock = (status & (0x1<<idx)) ? 1 : 0;
3655 sync = (status & (0x100<<idx)) ? 1 : 0;
3656
3657 if (lock && sync)
3658 return 2;
3659 else if (lock)
3660 return 1;
3661 return 0;
3662}
3663
3664
3665static int hdspm_sync_in_sync_check(struct hdspm *hdspm)
3666{
3667 int status, lock = 0, sync = 0;
3668
3669 switch (hdspm->io_type) {
3670 case RayDAT:
3671 case AIO:
3672 status = hdspm_read(hdspm, HDSPM_RD_STATUS_3);
3673 lock = (status & 0x400) ? 1 : 0;
3674 sync = (status & 0x800) ? 1 : 0;
3675 break;
3676
3677 case MADI:
3678 case AES32:
3679 status = hdspm_read(hdspm, HDSPM_statusRegister2);
3680 lock = (status & 0x400000) ? 1 : 0;
3681 sync = (status & 0x800000) ? 1 : 0;
3682 break;
3683
3684 case MADIface:
3685 break;
3686 }
3687
3688 if (lock && sync)
3689 return 2;
3690 else if (lock)
3691 return 1;
3692
3693 return 0;
3694}
3695
3696static int hdspm_aes_sync_check(struct hdspm *hdspm, int idx)
3697{
3698 int status2, lock, sync;
3699 status2 = hdspm_read(hdspm, HDSPM_statusRegister2);
3700
3701 lock = (status2 & (0x0080 >> idx)) ? 1 : 0;
3702 sync = (status2 & (0x8000 >> idx)) ? 1 : 0;
3703
3704 if (sync)
3705 return 2;
3706 else if (lock)
3707 return 1;
3708 return 0;
3709}
3710
3711
3712static int hdspm_tco_sync_check(struct hdspm *hdspm)
3713{
3714 int status;
3715
3716 if (hdspm->tco) {
3717 switch (hdspm->io_type) {
3718 case MADI:
3719 case AES32:
3720 status = hdspm_read(hdspm, HDSPM_statusRegister);
3721 if (status & HDSPM_tcoLock) {
3722 if (status & HDSPM_tcoSync)
3723 return 2;
3724 else
3725 return 1;
3726 }
3727 return 0;
3728
3729 break;
3730
3731 case RayDAT:
3732 case AIO:
3733 status = hdspm_read(hdspm, HDSPM_RD_STATUS_1);
3734
3735 if (status & 0x8000000)
3736 return 2; /* Sync */
3737 if (status & 0x4000000)
3738 return 1; /* Lock */
3739 return 0; /* No signal */
3740 break;
3741
3742 default:
3743 break;
3744 }
3745 }
3746
3747 return 3; /* N/A */
3748}
3749
3750
3751static int snd_hdspm_get_sync_check(struct snd_kcontrol *kcontrol,
3752 struct snd_ctl_elem_value *ucontrol)
3753{
3754 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
3755 int val = -1;
3756
3757 switch (hdspm->io_type) {
3758 case RayDAT:
3759 switch (kcontrol->private_value) {
3760 case 0: /* WC */
3761 val = hdspm_wc_sync_check(hdspm); break;
3762 case 7: /* TCO */
3763 val = hdspm_tco_sync_check(hdspm); break;
3764 case 8: /* SYNC IN */
3765 val = hdspm_sync_in_sync_check(hdspm); break;
3766 default:
3767 val = hdspm_s1_sync_check(hdspm, ucontrol->id.index-1);
3768 }
3769
3770 case AIO:
3771 switch (kcontrol->private_value) {
3772 case 0: /* WC */
3773 val = hdspm_wc_sync_check(hdspm); break;
3774 case 4: /* TCO */
3775 val = hdspm_tco_sync_check(hdspm); break;
3776 case 5: /* SYNC IN */
3777 val = hdspm_sync_in_sync_check(hdspm); break;
3778 default:
3779 val = hdspm_s1_sync_check(hdspm, ucontrol->id.index-1);
3780 }
3781
3782 case MADI:
3783 switch (kcontrol->private_value) {
3784 case 0: /* WC */
3785 val = hdspm_wc_sync_check(hdspm); break;
3786 case 1: /* MADI */
3787 val = hdspm_madi_sync_check(hdspm); break;
3788 case 2: /* TCO */
3789 val = hdspm_tco_sync_check(hdspm); break;
3790 case 3: /* SYNC_IN */
3791 val = hdspm_sync_in_sync_check(hdspm); break;
3792 }
3793
3794 case MADIface:
3795 val = hdspm_madi_sync_check(hdspm); /* MADI */
3796 break;
3797
3798 case AES32:
3799 switch (kcontrol->private_value) {
3800 case 0: /* WC */
3801 val = hdspm_wc_sync_check(hdspm); break;
3802 case 9: /* TCO */
3803 val = hdspm_tco_sync_check(hdspm); break;
3804 case 10 /* SYNC IN */:
3805 val = hdspm_sync_in_sync_check(hdspm); break;
3806 default:
3807 val = hdspm_aes_sync_check(hdspm,
3808 ucontrol->id.index-1);
3809 }
3810
3811 }
3812
3813 if (-1 == val)
3814 val = 3;
3815
3816 ucontrol->value.enumerated.item[0] = val;
3817 return 0;
3818}
3819
3820
3821
3822/**
3823 * TCO controls
3824 **/
3825static void hdspm_tco_write(struct hdspm *hdspm)
3826{
3827 unsigned int tc[4] = { 0, 0, 0, 0};
3828
3829 switch (hdspm->tco->input) {
3830 case 0:
3831 tc[2] |= HDSPM_TCO2_set_input_MSB;
3832 break;
3833 case 1:
3834 tc[2] |= HDSPM_TCO2_set_input_LSB;
3835 break;
3836 default:
3837 break;
3838 }
3839
3840 switch (hdspm->tco->framerate) {
3841 case 1:
3842 tc[1] |= HDSPM_TCO1_LTC_Format_LSB;
3843 break;
3844 case 2:
3845 tc[1] |= HDSPM_TCO1_LTC_Format_MSB;
3846 break;
3847 case 3:
3848 tc[1] |= HDSPM_TCO1_LTC_Format_MSB +
3849 HDSPM_TCO1_set_drop_frame_flag;
3850 break;
3851 case 4:
3852 tc[1] |= HDSPM_TCO1_LTC_Format_LSB +
3853 HDSPM_TCO1_LTC_Format_MSB;
3854 break;
3855 case 5:
3856 tc[1] |= HDSPM_TCO1_LTC_Format_LSB +
3857 HDSPM_TCO1_LTC_Format_MSB +
3858 HDSPM_TCO1_set_drop_frame_flag;
3859 break;
3860 default:
3861 break;
3862 }
3863
3864 switch (hdspm->tco->wordclock) {
3865 case 1:
3866 tc[2] |= HDSPM_TCO2_WCK_IO_ratio_LSB;
3867 break;
3868 case 2:
3869 tc[2] |= HDSPM_TCO2_WCK_IO_ratio_MSB;
3870 break;
3871 default:
3872 break;
3873 }
3874
3875 switch (hdspm->tco->samplerate) {
3876 case 1:
3877 tc[2] |= HDSPM_TCO2_set_freq;
3878 break;
3879 case 2:
3880 tc[2] |= HDSPM_TCO2_set_freq_from_app;
3881 break;
3882 default:
3883 break;
3884 }
3885
3886 switch (hdspm->tco->pull) {
3887 case 1:
3888 tc[2] |= HDSPM_TCO2_set_pull_up;
3889 break;
3890 case 2:
3891 tc[2] |= HDSPM_TCO2_set_pull_down;
3892 break;
3893 case 3:
3894 tc[2] |= HDSPM_TCO2_set_pull_up + HDSPM_TCO2_set_01_4;
3895 break;
3896 case 4:
3897 tc[2] |= HDSPM_TCO2_set_pull_down + HDSPM_TCO2_set_01_4;
3898 break;
3899 default:
3900 break;
3901 }
3902
3903 if (1 == hdspm->tco->term) {
3904 tc[2] |= HDSPM_TCO2_set_term_75R;
3905 }
3906
3907 hdspm_write(hdspm, HDSPM_WR_TCO, tc[0]);
3908 hdspm_write(hdspm, HDSPM_WR_TCO+4, tc[1]);
3909 hdspm_write(hdspm, HDSPM_WR_TCO+8, tc[2]);
3910 hdspm_write(hdspm, HDSPM_WR_TCO+12, tc[3]);
3911}
3912
3913
3914#define HDSPM_TCO_SAMPLE_RATE(xname, xindex) \
3915{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
3916 .name = xname, \
3917 .index = xindex, \
3918 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |\
3919 SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
3920 .info = snd_hdspm_info_tco_sample_rate, \
3921 .get = snd_hdspm_get_tco_sample_rate, \
3922 .put = snd_hdspm_put_tco_sample_rate \
3923}
3924
3925static int snd_hdspm_info_tco_sample_rate(struct snd_kcontrol *kcontrol,
3926 struct snd_ctl_elem_info *uinfo)
3927{
3928 static char *texts[] = { "44.1 kHz", "48 kHz" };
3929 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
3930 uinfo->count = 1;
3931 uinfo->value.enumerated.items = 2;
3932
3933 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
3934 uinfo->value.enumerated.item =
3935 uinfo->value.enumerated.items - 1;
3936
3937 strcpy(uinfo->value.enumerated.name,
3938 texts[uinfo->value.enumerated.item]);
3939
3940 return 0;
3941}
3942
3943static int snd_hdspm_get_tco_sample_rate(struct snd_kcontrol *kcontrol,
3944 struct snd_ctl_elem_value *ucontrol)
Takashi Iwai763f3562005-06-03 11:25:34 +02003945{
Takashi Iwai98274f02005-11-17 14:52:34 +01003946 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
Takashi Iwai763f3562005-06-03 11:25:34 +02003947
Adrian Knoth0dca1792011-01-26 19:32:14 +01003948 ucontrol->value.enumerated.item[0] = hdspm->tco->samplerate;
3949
Takashi Iwai763f3562005-06-03 11:25:34 +02003950 return 0;
3951}
3952
Adrian Knoth0dca1792011-01-26 19:32:14 +01003953static int snd_hdspm_put_tco_sample_rate(struct snd_kcontrol *kcontrol,
3954 struct snd_ctl_elem_value *ucontrol)
Remy Bruno3cee5a62006-10-16 12:46:32 +02003955{
Adrian Knoth0dca1792011-01-26 19:32:14 +01003956 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
3957
3958 if (hdspm->tco->samplerate != ucontrol->value.enumerated.item[0]) {
3959 hdspm->tco->samplerate = ucontrol->value.enumerated.item[0];
3960
3961 hdspm_tco_write(hdspm);
3962
3963 return 1;
Remy Bruno3cee5a62006-10-16 12:46:32 +02003964 }
Adrian Knoth0dca1792011-01-26 19:32:14 +01003965
Remy Bruno3cee5a62006-10-16 12:46:32 +02003966 return 0;
3967}
3968
Adrian Knoth0dca1792011-01-26 19:32:14 +01003969
3970#define HDSPM_TCO_PULL(xname, xindex) \
3971{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
3972 .name = xname, \
3973 .index = xindex, \
3974 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |\
3975 SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
3976 .info = snd_hdspm_info_tco_pull, \
3977 .get = snd_hdspm_get_tco_pull, \
3978 .put = snd_hdspm_put_tco_pull \
3979}
3980
3981static int snd_hdspm_info_tco_pull(struct snd_kcontrol *kcontrol,
3982 struct snd_ctl_elem_info *uinfo)
3983{
3984 static char *texts[] = { "0", "+ 0.1 %", "- 0.1 %", "+ 4 %", "- 4 %" };
3985 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
3986 uinfo->count = 1;
3987 uinfo->value.enumerated.items = 5;
3988
3989 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
3990 uinfo->value.enumerated.item =
3991 uinfo->value.enumerated.items - 1;
3992
3993 strcpy(uinfo->value.enumerated.name,
3994 texts[uinfo->value.enumerated.item]);
3995
3996 return 0;
3997}
3998
3999static int snd_hdspm_get_tco_pull(struct snd_kcontrol *kcontrol,
4000 struct snd_ctl_elem_value *ucontrol)
4001{
4002 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
4003
4004 ucontrol->value.enumerated.item[0] = hdspm->tco->pull;
4005
4006 return 0;
4007}
4008
4009static int snd_hdspm_put_tco_pull(struct snd_kcontrol *kcontrol,
4010 struct snd_ctl_elem_value *ucontrol)
4011{
4012 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
4013
4014 if (hdspm->tco->pull != ucontrol->value.enumerated.item[0]) {
4015 hdspm->tco->pull = ucontrol->value.enumerated.item[0];
4016
4017 hdspm_tco_write(hdspm);
4018
4019 return 1;
4020 }
4021
4022 return 0;
4023}
4024
4025#define HDSPM_TCO_WCK_CONVERSION(xname, xindex) \
4026{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
4027 .name = xname, \
4028 .index = xindex, \
4029 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |\
4030 SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
4031 .info = snd_hdspm_info_tco_wck_conversion, \
4032 .get = snd_hdspm_get_tco_wck_conversion, \
4033 .put = snd_hdspm_put_tco_wck_conversion \
4034}
4035
4036static int snd_hdspm_info_tco_wck_conversion(struct snd_kcontrol *kcontrol,
4037 struct snd_ctl_elem_info *uinfo)
4038{
4039 static char *texts[] = { "1:1", "44.1 -> 48", "48 -> 44.1" };
4040 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
4041 uinfo->count = 1;
4042 uinfo->value.enumerated.items = 3;
4043
4044 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
4045 uinfo->value.enumerated.item =
4046 uinfo->value.enumerated.items - 1;
4047
4048 strcpy(uinfo->value.enumerated.name,
4049 texts[uinfo->value.enumerated.item]);
4050
4051 return 0;
4052}
4053
4054static int snd_hdspm_get_tco_wck_conversion(struct snd_kcontrol *kcontrol,
4055 struct snd_ctl_elem_value *ucontrol)
4056{
4057 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
4058
4059 ucontrol->value.enumerated.item[0] = hdspm->tco->wordclock;
4060
4061 return 0;
4062}
4063
4064static int snd_hdspm_put_tco_wck_conversion(struct snd_kcontrol *kcontrol,
4065 struct snd_ctl_elem_value *ucontrol)
4066{
4067 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
4068
4069 if (hdspm->tco->wordclock != ucontrol->value.enumerated.item[0]) {
4070 hdspm->tco->wordclock = ucontrol->value.enumerated.item[0];
4071
4072 hdspm_tco_write(hdspm);
4073
4074 return 1;
4075 }
4076
4077 return 0;
4078}
4079
4080
4081#define HDSPM_TCO_FRAME_RATE(xname, xindex) \
4082{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
4083 .name = xname, \
4084 .index = xindex, \
4085 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |\
4086 SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
4087 .info = snd_hdspm_info_tco_frame_rate, \
4088 .get = snd_hdspm_get_tco_frame_rate, \
4089 .put = snd_hdspm_put_tco_frame_rate \
4090}
4091
4092static int snd_hdspm_info_tco_frame_rate(struct snd_kcontrol *kcontrol,
4093 struct snd_ctl_elem_info *uinfo)
4094{
4095 static char *texts[] = { "24 fps", "25 fps", "29.97fps",
4096 "29.97 dfps", "30 fps", "30 dfps" };
4097 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
4098 uinfo->count = 1;
4099 uinfo->value.enumerated.items = 6;
4100
4101 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
4102 uinfo->value.enumerated.item =
4103 uinfo->value.enumerated.items - 1;
4104
4105 strcpy(uinfo->value.enumerated.name,
4106 texts[uinfo->value.enumerated.item]);
4107
4108 return 0;
4109}
4110
4111static int snd_hdspm_get_tco_frame_rate(struct snd_kcontrol *kcontrol,
Remy Bruno3cee5a62006-10-16 12:46:32 +02004112 struct snd_ctl_elem_value *ucontrol)
4113{
Remy Bruno3cee5a62006-10-16 12:46:32 +02004114 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
4115
Adrian Knoth0dca1792011-01-26 19:32:14 +01004116 ucontrol->value.enumerated.item[0] = hdspm->tco->framerate;
Remy Bruno3cee5a62006-10-16 12:46:32 +02004117
Remy Bruno3cee5a62006-10-16 12:46:32 +02004118 return 0;
4119}
Takashi Iwai763f3562005-06-03 11:25:34 +02004120
Adrian Knoth0dca1792011-01-26 19:32:14 +01004121static int snd_hdspm_put_tco_frame_rate(struct snd_kcontrol *kcontrol,
4122 struct snd_ctl_elem_value *ucontrol)
4123{
4124 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
4125
4126 if (hdspm->tco->framerate != ucontrol->value.enumerated.item[0]) {
4127 hdspm->tco->framerate = ucontrol->value.enumerated.item[0];
4128
4129 hdspm_tco_write(hdspm);
4130
4131 return 1;
4132 }
4133
4134 return 0;
4135}
4136
4137
4138#define HDSPM_TCO_SYNC_SOURCE(xname, xindex) \
4139{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
4140 .name = xname, \
4141 .index = xindex, \
4142 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |\
4143 SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
4144 .info = snd_hdspm_info_tco_sync_source, \
4145 .get = snd_hdspm_get_tco_sync_source, \
4146 .put = snd_hdspm_put_tco_sync_source \
4147}
4148
4149static int snd_hdspm_info_tco_sync_source(struct snd_kcontrol *kcontrol,
4150 struct snd_ctl_elem_info *uinfo)
4151{
4152 static char *texts[] = { "LTC", "Video", "WCK" };
4153 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
4154 uinfo->count = 1;
4155 uinfo->value.enumerated.items = 3;
4156
4157 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
4158 uinfo->value.enumerated.item =
4159 uinfo->value.enumerated.items - 1;
4160
4161 strcpy(uinfo->value.enumerated.name,
4162 texts[uinfo->value.enumerated.item]);
4163
4164 return 0;
4165}
4166
4167static int snd_hdspm_get_tco_sync_source(struct snd_kcontrol *kcontrol,
4168 struct snd_ctl_elem_value *ucontrol)
4169{
4170 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
4171
4172 ucontrol->value.enumerated.item[0] = hdspm->tco->input;
4173
4174 return 0;
4175}
4176
4177static int snd_hdspm_put_tco_sync_source(struct snd_kcontrol *kcontrol,
4178 struct snd_ctl_elem_value *ucontrol)
4179{
4180 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
4181
4182 if (hdspm->tco->input != ucontrol->value.enumerated.item[0]) {
4183 hdspm->tco->input = ucontrol->value.enumerated.item[0];
4184
4185 hdspm_tco_write(hdspm);
4186
4187 return 1;
4188 }
4189
4190 return 0;
4191}
4192
4193
4194#define HDSPM_TCO_WORD_TERM(xname, xindex) \
4195{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
4196 .name = xname, \
4197 .index = xindex, \
4198 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |\
4199 SNDRV_CTL_ELEM_ACCESS_VOLATILE, \
4200 .info = snd_hdspm_info_tco_word_term, \
4201 .get = snd_hdspm_get_tco_word_term, \
4202 .put = snd_hdspm_put_tco_word_term \
4203}
4204
4205static int snd_hdspm_info_tco_word_term(struct snd_kcontrol *kcontrol,
4206 struct snd_ctl_elem_info *uinfo)
4207{
4208 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
4209 uinfo->count = 1;
4210 uinfo->value.integer.min = 0;
4211 uinfo->value.integer.max = 1;
4212
4213 return 0;
4214}
4215
4216
4217static int snd_hdspm_get_tco_word_term(struct snd_kcontrol *kcontrol,
4218 struct snd_ctl_elem_value *ucontrol)
4219{
4220 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
4221
4222 ucontrol->value.enumerated.item[0] = hdspm->tco->term;
4223
4224 return 0;
4225}
4226
4227
4228static int snd_hdspm_put_tco_word_term(struct snd_kcontrol *kcontrol,
4229 struct snd_ctl_elem_value *ucontrol)
4230{
4231 struct hdspm *hdspm = snd_kcontrol_chip(kcontrol);
4232
4233 if (hdspm->tco->term != ucontrol->value.enumerated.item[0]) {
4234 hdspm->tco->term = ucontrol->value.enumerated.item[0];
4235
4236 hdspm_tco_write(hdspm);
4237
4238 return 1;
4239 }
4240
4241 return 0;
4242}
4243
4244
4245
Takashi Iwai763f3562005-06-03 11:25:34 +02004246
Remy Bruno3cee5a62006-10-16 12:46:32 +02004247static struct snd_kcontrol_new snd_hdspm_controls_madi[] = {
Takashi Iwai763f3562005-06-03 11:25:34 +02004248 HDSPM_MIXER("Mixer", 0),
Adrian Knoth0dca1792011-01-26 19:32:14 +01004249 HDSPM_INTERNAL_CLOCK("Internal Clock", 0),
Takashi Iwai763f3562005-06-03 11:25:34 +02004250 HDSPM_SYSTEM_CLOCK_MODE("System Clock Mode", 0),
4251 HDSPM_PREF_SYNC_REF("Preferred Sync Reference", 0),
4252 HDSPM_AUTOSYNC_REF("AutoSync Reference", 0),
4253 HDSPM_SYSTEM_SAMPLE_RATE("System Sample Rate", 0),
Adrian Knoth0dca1792011-01-26 19:32:14 +01004254 HDSPM_SYNC_CHECK("WC SyncCheck", 0),
4255 HDSPM_SYNC_CHECK("MADI SyncCheck", 1),
4256 HDSPM_SYNC_CHECK("TCO SyncCHeck", 2),
4257 HDSPM_SYNC_CHECK("SYNC IN SyncCheck", 3),
Takashi Iwai763f3562005-06-03 11:25:34 +02004258 HDSPM_LINE_OUT("Line Out", 0),
4259 HDSPM_TX_64("TX 64 channels mode", 0),
4260 HDSPM_C_TMS("Clear Track Marker", 0),
4261 HDSPM_SAFE_MODE("Safe Mode", 0),
Adrian Knoth0dca1792011-01-26 19:32:14 +01004262 HDSPM_INPUT_SELECT("Input Select", 0)
4263};
4264
4265
4266static struct snd_kcontrol_new snd_hdspm_controls_madiface[] = {
4267 HDSPM_MIXER("Mixer", 0),
4268 HDSPM_INTERNAL_CLOCK("Internal Clock", 0),
4269 HDSPM_SYSTEM_CLOCK_MODE("System Clock Mode", 0),
4270 HDSPM_SYSTEM_SAMPLE_RATE("System Sample Rate", 0),
4271 HDSPM_AUTOSYNC_SAMPLE_RATE("External Rate", 0),
4272 HDSPM_SYNC_CHECK("MADI SyncCheck", 0),
4273 HDSPM_TX_64("TX 64 channels mode", 0),
4274 HDSPM_C_TMS("Clear Track Marker", 0),
Adrian Knothf6ea8052011-02-23 11:43:12 +01004275 HDSPM_SAFE_MODE("Safe Mode", 0)
Takashi Iwai763f3562005-06-03 11:25:34 +02004276};
4277
Adrian Knoth0dca1792011-01-26 19:32:14 +01004278static struct snd_kcontrol_new snd_hdspm_controls_aio[] = {
Remy Bruno3cee5a62006-10-16 12:46:32 +02004279 HDSPM_MIXER("Mixer", 0),
Adrian Knoth0dca1792011-01-26 19:32:14 +01004280 HDSPM_INTERNAL_CLOCK("Internal Clock", 0),
Remy Bruno3cee5a62006-10-16 12:46:32 +02004281 HDSPM_SYSTEM_CLOCK_MODE("System Clock Mode", 0),
4282 HDSPM_PREF_SYNC_REF("Preferred Sync Reference", 0),
4283 HDSPM_AUTOSYNC_REF("AutoSync Reference", 0),
4284 HDSPM_SYSTEM_SAMPLE_RATE("System Sample Rate", 0),
Remy Bruno3cee5a62006-10-16 12:46:32 +02004285 HDSPM_AUTOSYNC_SAMPLE_RATE("External Rate", 0),
Adrian Knoth0dca1792011-01-26 19:32:14 +01004286 HDSPM_SYNC_CHECK("WC SyncCheck", 0),
4287 HDSPM_SYNC_CHECK("AES SyncCheck", 1),
4288 HDSPM_SYNC_CHECK("SPDIF SyncCheck", 2),
4289 HDSPM_SYNC_CHECK("ADAT SyncCheck", 3),
4290 HDSPM_SYNC_CHECK("TCO SyncCheck", 4),
4291 HDSPM_SYNC_CHECK("SYNC IN SyncCheck", 5),
4292 HDSPM_AUTOSYNC_SAMPLE_RATE("WC Frequency", 0),
4293 HDSPM_AUTOSYNC_SAMPLE_RATE("AES Frequency", 1),
4294 HDSPM_AUTOSYNC_SAMPLE_RATE("SPDIF Frequency", 2),
4295 HDSPM_AUTOSYNC_SAMPLE_RATE("ADAT Frequency", 3),
4296 HDSPM_AUTOSYNC_SAMPLE_RATE("TCO Frequency", 4),
4297 HDSPM_AUTOSYNC_SAMPLE_RATE("SYNC IN Frequency", 5)
4298
4299 /*
4300 HDSPM_INPUT_SELECT("Input Select", 0),
4301 HDSPM_SPDIF_OPTICAL("SPDIF Out Optical", 0),
4302 HDSPM_PROFESSIONAL("SPDIF Out Professional", 0);
4303 HDSPM_SPDIF_IN("SPDIF In", 0);
4304 HDSPM_BREAKOUT_CABLE("Breakout Cable", 0);
4305 HDSPM_INPUT_LEVEL("Input Level", 0);
4306 HDSPM_OUTPUT_LEVEL("Output Level", 0);
4307 HDSPM_PHONES("Phones", 0);
4308 */
4309};
4310
4311static struct snd_kcontrol_new snd_hdspm_controls_raydat[] = {
4312 HDSPM_MIXER("Mixer", 0),
4313 HDSPM_INTERNAL_CLOCK("Internal Clock", 0),
4314 HDSPM_SYSTEM_CLOCK_MODE("Clock Mode", 0),
4315 HDSPM_PREF_SYNC_REF("Pref Sync Ref", 0),
4316 HDSPM_SYSTEM_SAMPLE_RATE("System Sample Rate", 0),
4317 HDSPM_SYNC_CHECK("WC SyncCheck", 0),
4318 HDSPM_SYNC_CHECK("AES SyncCheck", 1),
4319 HDSPM_SYNC_CHECK("SPDIF SyncCheck", 2),
4320 HDSPM_SYNC_CHECK("ADAT1 SyncCheck", 3),
4321 HDSPM_SYNC_CHECK("ADAT2 SyncCheck", 4),
4322 HDSPM_SYNC_CHECK("ADAT3 SyncCheck", 5),
4323 HDSPM_SYNC_CHECK("ADAT4 SyncCheck", 6),
4324 HDSPM_SYNC_CHECK("TCO SyncCheck", 7),
4325 HDSPM_SYNC_CHECK("SYNC IN SyncCheck", 8),
4326 HDSPM_AUTOSYNC_SAMPLE_RATE("WC Frequency", 0),
4327 HDSPM_AUTOSYNC_SAMPLE_RATE("AES Frequency", 1),
4328 HDSPM_AUTOSYNC_SAMPLE_RATE("SPDIF Frequency", 2),
4329 HDSPM_AUTOSYNC_SAMPLE_RATE("ADAT1 Frequency", 3),
4330 HDSPM_AUTOSYNC_SAMPLE_RATE("ADAT2 Frequency", 4),
4331 HDSPM_AUTOSYNC_SAMPLE_RATE("ADAT3 Frequency", 5),
4332 HDSPM_AUTOSYNC_SAMPLE_RATE("ADAT4 Frequency", 6),
4333 HDSPM_AUTOSYNC_SAMPLE_RATE("TCO Frequency", 7),
4334 HDSPM_AUTOSYNC_SAMPLE_RATE("SYNC IN Frequency", 8)
4335};
4336
4337static struct snd_kcontrol_new snd_hdspm_controls_aes32[] = {
4338 HDSPM_MIXER("Mixer", 0),
4339 HDSPM_INTERNAL_CLOCK("Internal Clock", 0),
4340 HDSPM_SYSTEM_CLOCK_MODE("System Clock Mode", 0),
4341 HDSPM_PREF_SYNC_REF("Preferred Sync Reference", 0),
4342 HDSPM_AUTOSYNC_REF("AutoSync Reference", 0),
4343 HDSPM_SYSTEM_SAMPLE_RATE("System Sample Rate", 0),
4344 HDSPM_AUTOSYNC_SAMPLE_RATE("External Rate", 0),
4345 HDSPM_SYNC_CHECK("WC Sync Check", 0),
4346 HDSPM_SYNC_CHECK("AES1 Sync Check", 1),
4347 HDSPM_SYNC_CHECK("AES2 Sync Check", 2),
4348 HDSPM_SYNC_CHECK("AES3 Sync Check", 3),
4349 HDSPM_SYNC_CHECK("AES4 Sync Check", 4),
4350 HDSPM_SYNC_CHECK("AES5 Sync Check", 5),
4351 HDSPM_SYNC_CHECK("AES6 Sync Check", 6),
4352 HDSPM_SYNC_CHECK("AES7 Sync Check", 7),
4353 HDSPM_SYNC_CHECK("AES8 Sync Check", 8),
4354 HDSPM_SYNC_CHECK("TCO Sync Check", 9),
4355 HDSPM_SYNC_CHECK("SYNC IN Sync Check", 10),
4356 HDSPM_AUTOSYNC_SAMPLE_RATE("WC Frequency", 0),
4357 HDSPM_AUTOSYNC_SAMPLE_RATE("AES1 Frequency", 1),
4358 HDSPM_AUTOSYNC_SAMPLE_RATE("AES2 Frequency", 2),
4359 HDSPM_AUTOSYNC_SAMPLE_RATE("AES3 Frequency", 3),
4360 HDSPM_AUTOSYNC_SAMPLE_RATE("AES4 Frequency", 4),
4361 HDSPM_AUTOSYNC_SAMPLE_RATE("AES5 Frequency", 5),
4362 HDSPM_AUTOSYNC_SAMPLE_RATE("AES6 Frequency", 6),
4363 HDSPM_AUTOSYNC_SAMPLE_RATE("AES7 Frequency", 7),
4364 HDSPM_AUTOSYNC_SAMPLE_RATE("AES8 Frequency", 8),
4365 HDSPM_AUTOSYNC_SAMPLE_RATE("TCO Frequency", 9),
4366 HDSPM_AUTOSYNC_SAMPLE_RATE("SYNC IN Frequency", 10),
Remy Bruno3cee5a62006-10-16 12:46:32 +02004367 HDSPM_LINE_OUT("Line Out", 0),
4368 HDSPM_EMPHASIS("Emphasis", 0),
4369 HDSPM_DOLBY("Non Audio", 0),
4370 HDSPM_PROFESSIONAL("Professional", 0),
4371 HDSPM_C_TMS("Clear Track Marker", 0),
4372 HDSPM_DS_WIRE("Double Speed Wire Mode", 0),
4373 HDSPM_QS_WIRE("Quad Speed Wire Mode", 0),
4374};
4375
Adrian Knoth0dca1792011-01-26 19:32:14 +01004376
4377
4378/* Control elements for the optional TCO module */
4379static struct snd_kcontrol_new snd_hdspm_controls_tco[] = {
4380 HDSPM_TCO_SAMPLE_RATE("TCO Sample Rate", 0),
4381 HDSPM_TCO_PULL("TCO Pull", 0),
4382 HDSPM_TCO_WCK_CONVERSION("TCO WCK Conversion", 0),
4383 HDSPM_TCO_FRAME_RATE("TCO Frame Rate", 0),
4384 HDSPM_TCO_SYNC_SOURCE("TCO Sync Source", 0),
4385 HDSPM_TCO_WORD_TERM("TCO Word Term", 0)
4386};
4387
4388
Takashi Iwai98274f02005-11-17 14:52:34 +01004389static struct snd_kcontrol_new snd_hdspm_playback_mixer = HDSPM_PLAYBACK_MIXER;
Takashi Iwai763f3562005-06-03 11:25:34 +02004390
4391
Takashi Iwai98274f02005-11-17 14:52:34 +01004392static int hdspm_update_simple_mixer_controls(struct hdspm * hdspm)
Takashi Iwai763f3562005-06-03 11:25:34 +02004393{
4394 int i;
4395
Adrian Knoth0dca1792011-01-26 19:32:14 +01004396 for (i = hdspm->ds_out_channels; i < hdspm->ss_out_channels; ++i) {
Takashi Iwai763f3562005-06-03 11:25:34 +02004397 if (hdspm->system_sample_rate > 48000) {
4398 hdspm->playback_mixer_ctls[i]->vd[0].access =
Adrian Knoth0dca1792011-01-26 19:32:14 +01004399 SNDRV_CTL_ELEM_ACCESS_INACTIVE |
4400 SNDRV_CTL_ELEM_ACCESS_READ |
4401 SNDRV_CTL_ELEM_ACCESS_VOLATILE;
Takashi Iwai763f3562005-06-03 11:25:34 +02004402 } else {
4403 hdspm->playback_mixer_ctls[i]->vd[0].access =
Adrian Knoth0dca1792011-01-26 19:32:14 +01004404 SNDRV_CTL_ELEM_ACCESS_READWRITE |
4405 SNDRV_CTL_ELEM_ACCESS_VOLATILE;
Takashi Iwai763f3562005-06-03 11:25:34 +02004406 }
4407 snd_ctl_notify(hdspm->card, SNDRV_CTL_EVENT_MASK_VALUE |
Adrian Knoth0dca1792011-01-26 19:32:14 +01004408 SNDRV_CTL_EVENT_MASK_INFO,
4409 &hdspm->playback_mixer_ctls[i]->id);
Takashi Iwai763f3562005-06-03 11:25:34 +02004410 }
4411
4412 return 0;
4413}
4414
4415
Adrian Knoth0dca1792011-01-26 19:32:14 +01004416static int snd_hdspm_create_controls(struct snd_card *card,
4417 struct hdspm *hdspm)
Takashi Iwai763f3562005-06-03 11:25:34 +02004418{
4419 unsigned int idx, limit;
4420 int err;
Takashi Iwai98274f02005-11-17 14:52:34 +01004421 struct snd_kcontrol *kctl;
Adrian Knoth0dca1792011-01-26 19:32:14 +01004422 struct snd_kcontrol_new *list = NULL;
Takashi Iwai763f3562005-06-03 11:25:34 +02004423
Adrian Knoth0dca1792011-01-26 19:32:14 +01004424 switch (hdspm->io_type) {
4425 case MADI:
4426 list = snd_hdspm_controls_madi;
4427 limit = ARRAY_SIZE(snd_hdspm_controls_madi);
4428 break;
4429 case MADIface:
4430 list = snd_hdspm_controls_madiface;
4431 limit = ARRAY_SIZE(snd_hdspm_controls_madiface);
4432 break;
4433 case AIO:
4434 list = snd_hdspm_controls_aio;
4435 limit = ARRAY_SIZE(snd_hdspm_controls_aio);
4436 break;
4437 case RayDAT:
4438 list = snd_hdspm_controls_raydat;
4439 limit = ARRAY_SIZE(snd_hdspm_controls_raydat);
4440 break;
4441 case AES32:
4442 list = snd_hdspm_controls_aes32;
4443 limit = ARRAY_SIZE(snd_hdspm_controls_aes32);
4444 break;
4445 }
Takashi Iwai763f3562005-06-03 11:25:34 +02004446
Adrian Knoth0dca1792011-01-26 19:32:14 +01004447 if (NULL != list) {
4448 for (idx = 0; idx < limit; idx++) {
Remy Bruno3cee5a62006-10-16 12:46:32 +02004449 err = snd_ctl_add(card,
Adrian Knoth0dca1792011-01-26 19:32:14 +01004450 snd_ctl_new1(&list[idx], hdspm));
Remy Bruno3cee5a62006-10-16 12:46:32 +02004451 if (err < 0)
4452 return err;
Takashi Iwai763f3562005-06-03 11:25:34 +02004453 }
4454 }
4455
Takashi Iwai763f3562005-06-03 11:25:34 +02004456
Adrian Knoth0dca1792011-01-26 19:32:14 +01004457 /* create simple 1:1 playback mixer controls */
Takashi Iwai763f3562005-06-03 11:25:34 +02004458 snd_hdspm_playback_mixer.name = "Chn";
Adrian Knoth0dca1792011-01-26 19:32:14 +01004459 if (hdspm->system_sample_rate >= 128000) {
4460 limit = hdspm->qs_out_channels;
4461 } else if (hdspm->system_sample_rate >= 64000) {
4462 limit = hdspm->ds_out_channels;
4463 } else {
4464 limit = hdspm->ss_out_channels;
4465 }
Takashi Iwai763f3562005-06-03 11:25:34 +02004466 for (idx = 0; idx < limit; ++idx) {
4467 snd_hdspm_playback_mixer.index = idx + 1;
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02004468 kctl = snd_ctl_new1(&snd_hdspm_playback_mixer, hdspm);
4469 err = snd_ctl_add(card, kctl);
4470 if (err < 0)
Takashi Iwai763f3562005-06-03 11:25:34 +02004471 return err;
Takashi Iwai763f3562005-06-03 11:25:34 +02004472 hdspm->playback_mixer_ctls[idx] = kctl;
4473 }
4474
Adrian Knoth0dca1792011-01-26 19:32:14 +01004475
4476 if (hdspm->tco) {
4477 /* add tco control elements */
4478 list = snd_hdspm_controls_tco;
4479 limit = ARRAY_SIZE(snd_hdspm_controls_tco);
4480 for (idx = 0; idx < limit; idx++) {
4481 err = snd_ctl_add(card,
4482 snd_ctl_new1(&list[idx], hdspm));
4483 if (err < 0)
4484 return err;
4485 }
4486 }
4487
Takashi Iwai763f3562005-06-03 11:25:34 +02004488 return 0;
4489}
4490
4491/*------------------------------------------------------------
Adrian Knoth0dca1792011-01-26 19:32:14 +01004492 /proc interface
Takashi Iwai763f3562005-06-03 11:25:34 +02004493 ------------------------------------------------------------*/
4494
4495static void
Remy Bruno3cee5a62006-10-16 12:46:32 +02004496snd_hdspm_proc_read_madi(struct snd_info_entry * entry,
4497 struct snd_info_buffer *buffer)
Takashi Iwai763f3562005-06-03 11:25:34 +02004498{
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02004499 struct hdspm *hdspm = entry->private_data;
Adrian Knoth0dca1792011-01-26 19:32:14 +01004500 unsigned int status, status2, control, freq;
4501
Takashi Iwai763f3562005-06-03 11:25:34 +02004502 char *pref_sync_ref;
4503 char *autosync_ref;
4504 char *system_clock_mode;
Takashi Iwai763f3562005-06-03 11:25:34 +02004505 char *insel;
Takashi Iwai763f3562005-06-03 11:25:34 +02004506 int x, x2;
4507
Adrian Knoth0dca1792011-01-26 19:32:14 +01004508 /* TCO stuff */
4509 int a, ltc, frames, seconds, minutes, hours;
4510 unsigned int period;
4511 u64 freq_const = 0;
4512 u32 rate;
4513
Takashi Iwai763f3562005-06-03 11:25:34 +02004514 status = hdspm_read(hdspm, HDSPM_statusRegister);
4515 status2 = hdspm_read(hdspm, HDSPM_statusRegister2);
Adrian Knoth0dca1792011-01-26 19:32:14 +01004516 control = hdspm->control_register;
4517 freq = hdspm_read(hdspm, HDSPM_timecodeRegister);
Takashi Iwai763f3562005-06-03 11:25:34 +02004518
4519 snd_iprintf(buffer, "%s (Card #%d) Rev.%x Status2first3bits: %x\n",
Adrian Knoth0dca1792011-01-26 19:32:14 +01004520 hdspm->card_name, hdspm->card->number + 1,
4521 hdspm->firmware_rev,
4522 (status2 & HDSPM_version0) |
4523 (status2 & HDSPM_version1) | (status2 &
4524 HDSPM_version2));
4525
4526 snd_iprintf(buffer, "HW Serial: 0x%06x%06x\n",
4527 (hdspm_read(hdspm, HDSPM_midiStatusIn1)>>8) & 0xFFFFFF,
4528 (hdspm_read(hdspm, HDSPM_midiStatusIn0)>>8) & 0xFFFFFF);
Takashi Iwai763f3562005-06-03 11:25:34 +02004529
4530 snd_iprintf(buffer, "IRQ: %d Registers bus: 0x%lx VM: 0x%lx\n",
Adrian Knoth0dca1792011-01-26 19:32:14 +01004531 hdspm->irq, hdspm->port, (unsigned long)hdspm->iobase);
Takashi Iwai763f3562005-06-03 11:25:34 +02004532
4533 snd_iprintf(buffer, "--- System ---\n");
4534
4535 snd_iprintf(buffer,
Adrian Knoth0dca1792011-01-26 19:32:14 +01004536 "IRQ Pending: Audio=%d, MIDI0=%d, MIDI1=%d, IRQcount=%d\n",
4537 status & HDSPM_audioIRQPending,
4538 (status & HDSPM_midi0IRQPending) ? 1 : 0,
4539 (status & HDSPM_midi1IRQPending) ? 1 : 0,
4540 hdspm->irq_count);
Takashi Iwai763f3562005-06-03 11:25:34 +02004541 snd_iprintf(buffer,
Adrian Knoth0dca1792011-01-26 19:32:14 +01004542 "HW pointer: id = %d, rawptr = %d (%d->%d) "
4543 "estimated= %ld (bytes)\n",
4544 ((status & HDSPM_BufferID) ? 1 : 0),
4545 (status & HDSPM_BufferPositionMask),
4546 (status & HDSPM_BufferPositionMask) %
4547 (2 * (int)hdspm->period_bytes),
4548 ((status & HDSPM_BufferPositionMask) - 64) %
4549 (2 * (int)hdspm->period_bytes),
4550 (long) hdspm_hw_pointer(hdspm) * 4);
Takashi Iwai763f3562005-06-03 11:25:34 +02004551
4552 snd_iprintf(buffer,
Adrian Knoth0dca1792011-01-26 19:32:14 +01004553 "MIDI FIFO: Out1=0x%x, Out2=0x%x, In1=0x%x, In2=0x%x \n",
4554 hdspm_read(hdspm, HDSPM_midiStatusOut0) & 0xFF,
4555 hdspm_read(hdspm, HDSPM_midiStatusOut1) & 0xFF,
4556 hdspm_read(hdspm, HDSPM_midiStatusIn0) & 0xFF,
4557 hdspm_read(hdspm, HDSPM_midiStatusIn1) & 0xFF);
Takashi Iwai763f3562005-06-03 11:25:34 +02004558 snd_iprintf(buffer,
Adrian Knoth0dca1792011-01-26 19:32:14 +01004559 "MIDIoverMADI FIFO: In=0x%x, Out=0x%x \n",
4560 hdspm_read(hdspm, HDSPM_midiStatusIn2) & 0xFF,
4561 hdspm_read(hdspm, HDSPM_midiStatusOut2) & 0xFF);
4562 snd_iprintf(buffer,
4563 "Register: ctrl1=0x%x, ctrl2=0x%x, status1=0x%x, "
4564 "status2=0x%x\n",
4565 hdspm->control_register, hdspm->control2_register,
4566 status, status2);
4567 if (status & HDSPM_tco_detect) {
4568 snd_iprintf(buffer, "TCO module detected.\n");
4569 a = hdspm_read(hdspm, HDSPM_RD_TCO+4);
4570 if (a & HDSPM_TCO1_LTC_Input_valid) {
4571 snd_iprintf(buffer, " LTC valid, ");
4572 switch (a & (HDSPM_TCO1_LTC_Format_LSB |
4573 HDSPM_TCO1_LTC_Format_MSB)) {
4574 case 0:
4575 snd_iprintf(buffer, "24 fps, ");
4576 break;
4577 case HDSPM_TCO1_LTC_Format_LSB:
4578 snd_iprintf(buffer, "25 fps, ");
4579 break;
4580 case HDSPM_TCO1_LTC_Format_MSB:
4581 snd_iprintf(buffer, "29.97 fps, ");
4582 break;
4583 default:
4584 snd_iprintf(buffer, "30 fps, ");
4585 break;
4586 }
4587 if (a & HDSPM_TCO1_set_drop_frame_flag) {
4588 snd_iprintf(buffer, "drop frame\n");
4589 } else {
4590 snd_iprintf(buffer, "full frame\n");
4591 }
4592 } else {
4593 snd_iprintf(buffer, " no LTC\n");
4594 }
4595 if (a & HDSPM_TCO1_Video_Input_Format_NTSC) {
4596 snd_iprintf(buffer, " Video: NTSC\n");
4597 } else if (a & HDSPM_TCO1_Video_Input_Format_PAL) {
4598 snd_iprintf(buffer, " Video: PAL\n");
4599 } else {
4600 snd_iprintf(buffer, " No video\n");
4601 }
4602 if (a & HDSPM_TCO1_TCO_lock) {
4603 snd_iprintf(buffer, " Sync: lock\n");
4604 } else {
4605 snd_iprintf(buffer, " Sync: no lock\n");
4606 }
4607
4608 switch (hdspm->io_type) {
4609 case MADI:
4610 case AES32:
4611 freq_const = 110069313433624ULL;
4612 break;
4613 case RayDAT:
4614 case AIO:
4615 freq_const = 104857600000000ULL;
4616 break;
4617 case MADIface:
4618 break; /* no TCO possible */
4619 }
4620
4621 period = hdspm_read(hdspm, HDSPM_RD_PLL_FREQ);
4622 snd_iprintf(buffer, " period: %u\n", period);
4623
4624
4625 /* rate = freq_const/period; */
4626 rate = div_u64(freq_const, period);
4627
4628 if (control & HDSPM_QuadSpeed) {
4629 rate *= 4;
4630 } else if (control & HDSPM_DoubleSpeed) {
4631 rate *= 2;
4632 }
4633
4634 snd_iprintf(buffer, " Frequency: %u Hz\n",
4635 (unsigned int) rate);
4636
4637 ltc = hdspm_read(hdspm, HDSPM_RD_TCO);
4638 frames = ltc & 0xF;
4639 ltc >>= 4;
4640 frames += (ltc & 0x3) * 10;
4641 ltc >>= 4;
4642 seconds = ltc & 0xF;
4643 ltc >>= 4;
4644 seconds += (ltc & 0x7) * 10;
4645 ltc >>= 4;
4646 minutes = ltc & 0xF;
4647 ltc >>= 4;
4648 minutes += (ltc & 0x7) * 10;
4649 ltc >>= 4;
4650 hours = ltc & 0xF;
4651 ltc >>= 4;
4652 hours += (ltc & 0x3) * 10;
4653 snd_iprintf(buffer,
4654 " LTC In: %02d:%02d:%02d:%02d\n",
4655 hours, minutes, seconds, frames);
4656
4657 } else {
4658 snd_iprintf(buffer, "No TCO module detected.\n");
4659 }
Takashi Iwai763f3562005-06-03 11:25:34 +02004660
4661 snd_iprintf(buffer, "--- Settings ---\n");
4662
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02004663 x = 1 << (6 + hdspm_decode_latency(hdspm->control_register &
Adrian Knoth0dca1792011-01-26 19:32:14 +01004664 HDSPM_LatencyMask));
Takashi Iwai763f3562005-06-03 11:25:34 +02004665
4666 snd_iprintf(buffer,
Adrian Knoth0dca1792011-01-26 19:32:14 +01004667 "Size (Latency): %d samples (2 periods of %lu bytes)\n",
4668 x, (unsigned long) hdspm->period_bytes);
Takashi Iwai763f3562005-06-03 11:25:34 +02004669
Adrian Knoth0dca1792011-01-26 19:32:14 +01004670 snd_iprintf(buffer, "Line out: %s\n",
4671 (hdspm->control_register & HDSPM_LineOut) ? "on " : "off");
Takashi Iwai763f3562005-06-03 11:25:34 +02004672
4673 switch (hdspm->control_register & HDSPM_InputMask) {
4674 case HDSPM_InputOptical:
4675 insel = "Optical";
4676 break;
4677 case HDSPM_InputCoaxial:
4678 insel = "Coaxial";
4679 break;
4680 default:
Adrian Knoth0dca1792011-01-26 19:32:14 +01004681 insel = "Unkown";
Takashi Iwai763f3562005-06-03 11:25:34 +02004682 }
4683
Takashi Iwai763f3562005-06-03 11:25:34 +02004684 snd_iprintf(buffer,
Adrian Knoth0dca1792011-01-26 19:32:14 +01004685 "ClearTrackMarker = %s, Transmit in %s Channel Mode, "
4686 "Auto Input %s\n",
4687 (hdspm->control_register & HDSPM_clr_tms) ? "on" : "off",
4688 (hdspm->control_register & HDSPM_TX_64ch) ? "64" : "56",
4689 (hdspm->control_register & HDSPM_AutoInp) ? "on" : "off");
Takashi Iwai763f3562005-06-03 11:25:34 +02004690
Adrian Knoth0dca1792011-01-26 19:32:14 +01004691
Remy Bruno3cee5a62006-10-16 12:46:32 +02004692 if (!(hdspm->control_register & HDSPM_ClockModeMaster))
Adrian Knoth0dca1792011-01-26 19:32:14 +01004693 system_clock_mode = "AutoSync";
Remy Bruno3cee5a62006-10-16 12:46:32 +02004694 else
Takashi Iwai763f3562005-06-03 11:25:34 +02004695 system_clock_mode = "Master";
Adrian Knoth0dca1792011-01-26 19:32:14 +01004696 snd_iprintf(buffer, "AutoSync Reference: %s\n", system_clock_mode);
Takashi Iwai763f3562005-06-03 11:25:34 +02004697
4698 switch (hdspm_pref_sync_ref(hdspm)) {
4699 case HDSPM_SYNC_FROM_WORD:
4700 pref_sync_ref = "Word Clock";
4701 break;
4702 case HDSPM_SYNC_FROM_MADI:
4703 pref_sync_ref = "MADI Sync";
4704 break;
Adrian Knoth0dca1792011-01-26 19:32:14 +01004705 case HDSPM_SYNC_FROM_TCO:
4706 pref_sync_ref = "TCO";
4707 break;
4708 case HDSPM_SYNC_FROM_SYNC_IN:
4709 pref_sync_ref = "Sync In";
4710 break;
Takashi Iwai763f3562005-06-03 11:25:34 +02004711 default:
4712 pref_sync_ref = "XXXX Clock";
4713 break;
4714 }
4715 snd_iprintf(buffer, "Preferred Sync Reference: %s\n",
Adrian Knoth0dca1792011-01-26 19:32:14 +01004716 pref_sync_ref);
Takashi Iwai763f3562005-06-03 11:25:34 +02004717
4718 snd_iprintf(buffer, "System Clock Frequency: %d\n",
Adrian Knoth0dca1792011-01-26 19:32:14 +01004719 hdspm->system_sample_rate);
Takashi Iwai763f3562005-06-03 11:25:34 +02004720
4721
4722 snd_iprintf(buffer, "--- Status:\n");
4723
4724 x = status & HDSPM_madiSync;
4725 x2 = status2 & HDSPM_wcSync;
4726
4727 snd_iprintf(buffer, "Inputs MADI=%s, WordClock=%s\n",
Adrian Knoth0dca1792011-01-26 19:32:14 +01004728 (status & HDSPM_madiLock) ? (x ? "Sync" : "Lock") :
4729 "NoLock",
4730 (status2 & HDSPM_wcLock) ? (x2 ? "Sync" : "Lock") :
4731 "NoLock");
Takashi Iwai763f3562005-06-03 11:25:34 +02004732
4733 switch (hdspm_autosync_ref(hdspm)) {
Adrian Knoth0dca1792011-01-26 19:32:14 +01004734 case HDSPM_AUTOSYNC_FROM_SYNC_IN:
4735 autosync_ref = "Sync In";
4736 break;
4737 case HDSPM_AUTOSYNC_FROM_TCO:
4738 autosync_ref = "TCO";
4739 break;
Takashi Iwai763f3562005-06-03 11:25:34 +02004740 case HDSPM_AUTOSYNC_FROM_WORD:
4741 autosync_ref = "Word Clock";
4742 break;
4743 case HDSPM_AUTOSYNC_FROM_MADI:
4744 autosync_ref = "MADI Sync";
4745 break;
4746 case HDSPM_AUTOSYNC_FROM_NONE:
4747 autosync_ref = "Input not valid";
4748 break;
4749 default:
4750 autosync_ref = "---";
4751 break;
4752 }
4753 snd_iprintf(buffer,
Adrian Knoth0dca1792011-01-26 19:32:14 +01004754 "AutoSync: Reference= %s, Freq=%d (MADI = %d, Word = %d)\n",
4755 autosync_ref, hdspm_external_sample_rate(hdspm),
4756 (status & HDSPM_madiFreqMask) >> 22,
4757 (status2 & HDSPM_wcFreqMask) >> 5);
Takashi Iwai763f3562005-06-03 11:25:34 +02004758
4759 snd_iprintf(buffer, "Input: %s, Mode=%s\n",
Adrian Knoth0dca1792011-01-26 19:32:14 +01004760 (status & HDSPM_AB_int) ? "Coax" : "Optical",
4761 (status & HDSPM_RX_64ch) ? "64 channels" :
4762 "56 channels");
Takashi Iwai763f3562005-06-03 11:25:34 +02004763
4764 snd_iprintf(buffer, "\n");
4765}
4766
Remy Bruno3cee5a62006-10-16 12:46:32 +02004767static void
4768snd_hdspm_proc_read_aes32(struct snd_info_entry * entry,
4769 struct snd_info_buffer *buffer)
4770{
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02004771 struct hdspm *hdspm = entry->private_data;
Remy Bruno3cee5a62006-10-16 12:46:32 +02004772 unsigned int status;
4773 unsigned int status2;
4774 unsigned int timecode;
4775 int pref_syncref;
4776 char *autosync_ref;
Remy Bruno3cee5a62006-10-16 12:46:32 +02004777 int x;
4778
4779 status = hdspm_read(hdspm, HDSPM_statusRegister);
4780 status2 = hdspm_read(hdspm, HDSPM_statusRegister2);
4781 timecode = hdspm_read(hdspm, HDSPM_timecodeRegister);
4782
4783 snd_iprintf(buffer, "%s (Card #%d) Rev.%x\n",
4784 hdspm->card_name, hdspm->card->number + 1,
4785 hdspm->firmware_rev);
4786
4787 snd_iprintf(buffer, "IRQ: %d Registers bus: 0x%lx VM: 0x%lx\n",
4788 hdspm->irq, hdspm->port, (unsigned long)hdspm->iobase);
4789
4790 snd_iprintf(buffer, "--- System ---\n");
4791
4792 snd_iprintf(buffer,
4793 "IRQ Pending: Audio=%d, MIDI0=%d, MIDI1=%d, IRQcount=%d\n",
4794 status & HDSPM_audioIRQPending,
4795 (status & HDSPM_midi0IRQPending) ? 1 : 0,
4796 (status & HDSPM_midi1IRQPending) ? 1 : 0,
4797 hdspm->irq_count);
4798 snd_iprintf(buffer,
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02004799 "HW pointer: id = %d, rawptr = %d (%d->%d) "
4800 "estimated= %ld (bytes)\n",
Remy Bruno3cee5a62006-10-16 12:46:32 +02004801 ((status & HDSPM_BufferID) ? 1 : 0),
4802 (status & HDSPM_BufferPositionMask),
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02004803 (status & HDSPM_BufferPositionMask) %
4804 (2 * (int)hdspm->period_bytes),
4805 ((status & HDSPM_BufferPositionMask) - 64) %
4806 (2 * (int)hdspm->period_bytes),
Remy Bruno3cee5a62006-10-16 12:46:32 +02004807 (long) hdspm_hw_pointer(hdspm) * 4);
4808
4809 snd_iprintf(buffer,
4810 "MIDI FIFO: Out1=0x%x, Out2=0x%x, In1=0x%x, In2=0x%x \n",
4811 hdspm_read(hdspm, HDSPM_midiStatusOut0) & 0xFF,
4812 hdspm_read(hdspm, HDSPM_midiStatusOut1) & 0xFF,
4813 hdspm_read(hdspm, HDSPM_midiStatusIn0) & 0xFF,
4814 hdspm_read(hdspm, HDSPM_midiStatusIn1) & 0xFF);
4815 snd_iprintf(buffer,
Adrian Knoth0dca1792011-01-26 19:32:14 +01004816 "MIDIoverMADI FIFO: In=0x%x, Out=0x%x \n",
4817 hdspm_read(hdspm, HDSPM_midiStatusIn2) & 0xFF,
4818 hdspm_read(hdspm, HDSPM_midiStatusOut2) & 0xFF);
4819 snd_iprintf(buffer,
4820 "Register: ctrl1=0x%x, ctrl2=0x%x, status1=0x%x, "
4821 "status2=0x%x\n",
4822 hdspm->control_register, hdspm->control2_register,
4823 status, status2);
Remy Bruno3cee5a62006-10-16 12:46:32 +02004824
4825 snd_iprintf(buffer, "--- Settings ---\n");
4826
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02004827 x = 1 << (6 + hdspm_decode_latency(hdspm->control_register &
Adrian Knoth0dca1792011-01-26 19:32:14 +01004828 HDSPM_LatencyMask));
Remy Bruno3cee5a62006-10-16 12:46:32 +02004829
4830 snd_iprintf(buffer,
4831 "Size (Latency): %d samples (2 periods of %lu bytes)\n",
4832 x, (unsigned long) hdspm->period_bytes);
4833
Adrian Knoth0dca1792011-01-26 19:32:14 +01004834 snd_iprintf(buffer, "Line out: %s\n",
Remy Bruno3cee5a62006-10-16 12:46:32 +02004835 (hdspm->
Adrian Knoth0dca1792011-01-26 19:32:14 +01004836 control_register & HDSPM_LineOut) ? "on " : "off");
Remy Bruno3cee5a62006-10-16 12:46:32 +02004837
4838 snd_iprintf(buffer,
4839 "ClearTrackMarker %s, Emphasis %s, Dolby %s\n",
4840 (hdspm->
4841 control_register & HDSPM_clr_tms) ? "on" : "off",
4842 (hdspm->
4843 control_register & HDSPM_Emphasis) ? "on" : "off",
4844 (hdspm->
4845 control_register & HDSPM_Dolby) ? "on" : "off");
4846
Remy Bruno3cee5a62006-10-16 12:46:32 +02004847
4848 pref_syncref = hdspm_pref_sync_ref(hdspm);
4849 if (pref_syncref == 0)
4850 snd_iprintf(buffer, "Preferred Sync Reference: Word Clock\n");
4851 else
4852 snd_iprintf(buffer, "Preferred Sync Reference: AES%d\n",
4853 pref_syncref);
4854
4855 snd_iprintf(buffer, "System Clock Frequency: %d\n",
4856 hdspm->system_sample_rate);
4857
4858 snd_iprintf(buffer, "Double speed: %s\n",
4859 hdspm->control_register & HDSPM_DS_DoubleWire?
4860 "Double wire" : "Single wire");
4861 snd_iprintf(buffer, "Quad speed: %s\n",
4862 hdspm->control_register & HDSPM_QS_DoubleWire?
4863 "Double wire" :
4864 hdspm->control_register & HDSPM_QS_QuadWire?
4865 "Quad wire" : "Single wire");
4866
4867 snd_iprintf(buffer, "--- Status:\n");
4868
4869 snd_iprintf(buffer, "Word: %s Frequency: %d\n",
Adrian Knoth0dca1792011-01-26 19:32:14 +01004870 (status & HDSPM_AES32_wcLock) ? "Sync " : "No Lock",
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02004871 HDSPM_bit2freq((status >> HDSPM_AES32_wcFreq_bit) & 0xF));
Remy Bruno3cee5a62006-10-16 12:46:32 +02004872
4873 for (x = 0; x < 8; x++) {
4874 snd_iprintf(buffer, "AES%d: %s Frequency: %d\n",
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02004875 x+1,
4876 (status2 & (HDSPM_LockAES >> x)) ?
Adrian Knoth0dca1792011-01-26 19:32:14 +01004877 "Sync " : "No Lock",
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02004878 HDSPM_bit2freq((timecode >> (4*x)) & 0xF));
Remy Bruno3cee5a62006-10-16 12:46:32 +02004879 }
4880
4881 switch (hdspm_autosync_ref(hdspm)) {
Adrian Knoth0dca1792011-01-26 19:32:14 +01004882 case HDSPM_AES32_AUTOSYNC_FROM_NONE:
4883 autosync_ref = "None"; break;
4884 case HDSPM_AES32_AUTOSYNC_FROM_WORD:
4885 autosync_ref = "Word Clock"; break;
4886 case HDSPM_AES32_AUTOSYNC_FROM_AES1:
4887 autosync_ref = "AES1"; break;
4888 case HDSPM_AES32_AUTOSYNC_FROM_AES2:
4889 autosync_ref = "AES2"; break;
4890 case HDSPM_AES32_AUTOSYNC_FROM_AES3:
4891 autosync_ref = "AES3"; break;
4892 case HDSPM_AES32_AUTOSYNC_FROM_AES4:
4893 autosync_ref = "AES4"; break;
4894 case HDSPM_AES32_AUTOSYNC_FROM_AES5:
4895 autosync_ref = "AES5"; break;
4896 case HDSPM_AES32_AUTOSYNC_FROM_AES6:
4897 autosync_ref = "AES6"; break;
4898 case HDSPM_AES32_AUTOSYNC_FROM_AES7:
4899 autosync_ref = "AES7"; break;
4900 case HDSPM_AES32_AUTOSYNC_FROM_AES8:
4901 autosync_ref = "AES8"; break;
4902 default:
4903 autosync_ref = "---"; break;
Remy Bruno3cee5a62006-10-16 12:46:32 +02004904 }
4905 snd_iprintf(buffer, "AutoSync ref = %s\n", autosync_ref);
4906
4907 snd_iprintf(buffer, "\n");
4908}
4909
Adrian Knoth0dca1792011-01-26 19:32:14 +01004910static void
4911snd_hdspm_proc_read_raydat(struct snd_info_entry *entry,
4912 struct snd_info_buffer *buffer)
4913{
4914 struct hdspm *hdspm = entry->private_data;
4915 unsigned int status1, status2, status3, control, i;
4916 unsigned int lock, sync;
4917
4918 status1 = hdspm_read(hdspm, HDSPM_RD_STATUS_1); /* s1 */
4919 status2 = hdspm_read(hdspm, HDSPM_RD_STATUS_2); /* freq */
4920 status3 = hdspm_read(hdspm, HDSPM_RD_STATUS_3); /* s2 */
4921
4922 control = hdspm->control_register;
4923
4924 snd_iprintf(buffer, "STATUS1: 0x%08x\n", status1);
4925 snd_iprintf(buffer, "STATUS2: 0x%08x\n", status2);
4926 snd_iprintf(buffer, "STATUS3: 0x%08x\n", status3);
4927
4928
4929 snd_iprintf(buffer, "\n*** CLOCK MODE\n\n");
4930
4931 snd_iprintf(buffer, "Clock mode : %s\n",
4932 (hdspm_system_clock_mode(hdspm) == 0) ? "master" : "slave");
4933 snd_iprintf(buffer, "System frequency: %d Hz\n",
4934 hdspm_get_system_sample_rate(hdspm));
4935
4936 snd_iprintf(buffer, "\n*** INPUT STATUS\n\n");
4937
4938 lock = 0x1;
4939 sync = 0x100;
4940
4941 for (i = 0; i < 8; i++) {
4942 snd_iprintf(buffer, "s1_input %d: Lock %d, Sync %d, Freq %s\n",
4943 i,
4944 (status1 & lock) ? 1 : 0,
4945 (status1 & sync) ? 1 : 0,
4946 texts_freq[(status2 >> (i * 4)) & 0xF]);
4947
4948 lock = lock<<1;
4949 sync = sync<<1;
4950 }
4951
4952 snd_iprintf(buffer, "WC input: Lock %d, Sync %d, Freq %s\n",
4953 (status1 & 0x1000000) ? 1 : 0,
4954 (status1 & 0x2000000) ? 1 : 0,
4955 texts_freq[(status1 >> 16) & 0xF]);
4956
4957 snd_iprintf(buffer, "TCO input: Lock %d, Sync %d, Freq %s\n",
4958 (status1 & 0x4000000) ? 1 : 0,
4959 (status1 & 0x8000000) ? 1 : 0,
4960 texts_freq[(status1 >> 20) & 0xF]);
4961
4962 snd_iprintf(buffer, "SYNC IN: Lock %d, Sync %d, Freq %s\n",
4963 (status3 & 0x400) ? 1 : 0,
4964 (status3 & 0x800) ? 1 : 0,
4965 texts_freq[(status2 >> 12) & 0xF]);
4966
4967}
4968
Remy Bruno3cee5a62006-10-16 12:46:32 +02004969#ifdef CONFIG_SND_DEBUG
4970static void
Adrian Knoth0dca1792011-01-26 19:32:14 +01004971snd_hdspm_proc_read_debug(struct snd_info_entry *entry,
Remy Bruno3cee5a62006-10-16 12:46:32 +02004972 struct snd_info_buffer *buffer)
4973{
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02004974 struct hdspm *hdspm = entry->private_data;
Remy Bruno3cee5a62006-10-16 12:46:32 +02004975
4976 int j,i;
4977
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02004978 for (i = 0; i < 256 /* 1024*64 */; i += j) {
Remy Bruno3cee5a62006-10-16 12:46:32 +02004979 snd_iprintf(buffer, "0x%08X: ", i);
4980 for (j = 0; j < 16; j += 4)
4981 snd_iprintf(buffer, "%08X ", hdspm_read(hdspm, i + j));
4982 snd_iprintf(buffer, "\n");
4983 }
4984}
4985#endif
4986
4987
Adrian Knoth0dca1792011-01-26 19:32:14 +01004988static void snd_hdspm_proc_ports_in(struct snd_info_entry *entry,
4989 struct snd_info_buffer *buffer)
4990{
4991 struct hdspm *hdspm = entry->private_data;
4992 int i;
Remy Bruno3cee5a62006-10-16 12:46:32 +02004993
Adrian Knoth0dca1792011-01-26 19:32:14 +01004994 snd_iprintf(buffer, "# generated by hdspm\n");
4995
4996 for (i = 0; i < hdspm->max_channels_in; i++) {
4997 snd_iprintf(buffer, "%d=%s\n", i+1, hdspm->port_names_in[i]);
4998 }
4999}
5000
5001static void snd_hdspm_proc_ports_out(struct snd_info_entry *entry,
5002 struct snd_info_buffer *buffer)
5003{
5004 struct hdspm *hdspm = entry->private_data;
5005 int i;
5006
5007 snd_iprintf(buffer, "# generated by hdspm\n");
5008
5009 for (i = 0; i < hdspm->max_channels_out; i++) {
5010 snd_iprintf(buffer, "%d=%s\n", i+1, hdspm->port_names_out[i]);
5011 }
5012}
5013
5014
5015static void __devinit snd_hdspm_proc_init(struct hdspm *hdspm)
Takashi Iwai763f3562005-06-03 11:25:34 +02005016{
Takashi Iwai98274f02005-11-17 14:52:34 +01005017 struct snd_info_entry *entry;
Takashi Iwai763f3562005-06-03 11:25:34 +02005018
Adrian Knoth0dca1792011-01-26 19:32:14 +01005019 if (!snd_card_proc_new(hdspm->card, "hdspm", &entry)) {
5020 switch (hdspm->io_type) {
5021 case AES32:
5022 snd_info_set_text_ops(entry, hdspm,
5023 snd_hdspm_proc_read_aes32);
5024 break;
5025 case MADI:
5026 snd_info_set_text_ops(entry, hdspm,
5027 snd_hdspm_proc_read_madi);
5028 break;
5029 case MADIface:
5030 /* snd_info_set_text_ops(entry, hdspm,
5031 snd_hdspm_proc_read_madiface); */
5032 break;
5033 case RayDAT:
5034 snd_info_set_text_ops(entry, hdspm,
5035 snd_hdspm_proc_read_raydat);
5036 break;
5037 case AIO:
5038 break;
5039 }
5040 }
5041
5042 if (!snd_card_proc_new(hdspm->card, "ports.in", &entry)) {
5043 snd_info_set_text_ops(entry, hdspm, snd_hdspm_proc_ports_in);
5044 }
5045
5046 if (!snd_card_proc_new(hdspm->card, "ports.out", &entry)) {
5047 snd_info_set_text_ops(entry, hdspm, snd_hdspm_proc_ports_out);
5048 }
5049
Remy Bruno3cee5a62006-10-16 12:46:32 +02005050#ifdef CONFIG_SND_DEBUG
5051 /* debug file to read all hdspm registers */
5052 if (!snd_card_proc_new(hdspm->card, "debug", &entry))
5053 snd_info_set_text_ops(entry, hdspm,
5054 snd_hdspm_proc_read_debug);
5055#endif
Takashi Iwai763f3562005-06-03 11:25:34 +02005056}
5057
5058/*------------------------------------------------------------
Adrian Knoth0dca1792011-01-26 19:32:14 +01005059 hdspm intitialize
Takashi Iwai763f3562005-06-03 11:25:34 +02005060 ------------------------------------------------------------*/
5061
Takashi Iwai98274f02005-11-17 14:52:34 +01005062static int snd_hdspm_set_defaults(struct hdspm * hdspm)
Takashi Iwai763f3562005-06-03 11:25:34 +02005063{
Takashi Iwai763f3562005-06-03 11:25:34 +02005064 /* ASSUMPTION: hdspm->lock is either held, or there is no need to
Joe Perches561de312007-12-18 13:13:47 +01005065 hold it (e.g. during module initialization).
Adrian Knoth0dca1792011-01-26 19:32:14 +01005066 */
Takashi Iwai763f3562005-06-03 11:25:34 +02005067
5068 /* set defaults: */
5069
Adrian Knoth0dca1792011-01-26 19:32:14 +01005070 hdspm->settings_register = 0;
5071
5072 switch (hdspm->io_type) {
5073 case MADI:
5074 case MADIface:
5075 hdspm->control_register =
5076 0x2 + 0x8 + 0x10 + 0x80 + 0x400 + 0x4000 + 0x1000000;
5077 break;
5078
5079 case RayDAT:
5080 case AIO:
5081 hdspm->settings_register = 0x1 + 0x1000;
5082 /* Magic values are: LAT_0, LAT_2, Master, freq1, tx64ch, inp_0,
5083 * line_out */
5084 hdspm->control_register =
5085 0x2 + 0x8 + 0x10 + 0x80 + 0x400 + 0x4000 + 0x1000000;
5086 break;
5087
5088 case AES32:
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02005089 hdspm->control_register =
5090 HDSPM_ClockModeMaster | /* Master Cloack Mode on */
Adrian Knoth0dca1792011-01-26 19:32:14 +01005091 hdspm_encode_latency(7) | /* latency max=8192samples */
Remy Bruno3cee5a62006-10-16 12:46:32 +02005092 HDSPM_SyncRef0 | /* AES1 is syncclock */
5093 HDSPM_LineOut | /* Analog output in */
5094 HDSPM_Professional; /* Professional mode */
Adrian Knoth0dca1792011-01-26 19:32:14 +01005095 break;
5096 }
Takashi Iwai763f3562005-06-03 11:25:34 +02005097
5098 hdspm_write(hdspm, HDSPM_controlRegister, hdspm->control_register);
5099
Adrian Knoth0dca1792011-01-26 19:32:14 +01005100 if (AES32 == hdspm->io_type) {
Remy Brunoffb2c3c2007-03-07 19:08:46 +01005101 /* No control2 register for AES32 */
Takashi Iwai763f3562005-06-03 11:25:34 +02005102#ifdef SNDRV_BIG_ENDIAN
Remy Brunoffb2c3c2007-03-07 19:08:46 +01005103 hdspm->control2_register = HDSPM_BIGENDIAN_MODE;
Takashi Iwai763f3562005-06-03 11:25:34 +02005104#else
Remy Brunoffb2c3c2007-03-07 19:08:46 +01005105 hdspm->control2_register = 0;
Takashi Iwai763f3562005-06-03 11:25:34 +02005106#endif
5107
Remy Brunoffb2c3c2007-03-07 19:08:46 +01005108 hdspm_write(hdspm, HDSPM_control2Reg, hdspm->control2_register);
5109 }
Takashi Iwai763f3562005-06-03 11:25:34 +02005110 hdspm_compute_period_size(hdspm);
5111
5112 /* silence everything */
5113
5114 all_in_all_mixer(hdspm, 0 * UNITY_GAIN);
5115
Adrian Knoth0dca1792011-01-26 19:32:14 +01005116 if (hdspm->io_type == AIO || hdspm->io_type == RayDAT) {
5117 hdspm_write(hdspm, HDSPM_WR_SETTINGS, hdspm->settings_register);
Takashi Iwai763f3562005-06-03 11:25:34 +02005118 }
5119
5120 /* set a default rate so that the channel map is set up. */
Adrian Knoth0dca1792011-01-26 19:32:14 +01005121 hdspm_set_rate(hdspm, 48000, 1);
Takashi Iwai763f3562005-06-03 11:25:34 +02005122
5123 return 0;
5124}
5125
5126
5127/*------------------------------------------------------------
Adrian Knoth0dca1792011-01-26 19:32:14 +01005128 interrupt
Takashi Iwai763f3562005-06-03 11:25:34 +02005129 ------------------------------------------------------------*/
5130
David Howells7d12e782006-10-05 14:55:46 +01005131static irqreturn_t snd_hdspm_interrupt(int irq, void *dev_id)
Takashi Iwai763f3562005-06-03 11:25:34 +02005132{
Takashi Iwai98274f02005-11-17 14:52:34 +01005133 struct hdspm *hdspm = (struct hdspm *) dev_id;
Takashi Iwai763f3562005-06-03 11:25:34 +02005134 unsigned int status;
Adrian Knoth0dca1792011-01-26 19:32:14 +01005135 int i, audio, midi, schedule = 0;
5136 /* cycles_t now; */
Takashi Iwai763f3562005-06-03 11:25:34 +02005137
5138 status = hdspm_read(hdspm, HDSPM_statusRegister);
5139
5140 audio = status & HDSPM_audioIRQPending;
Adrian Knoth0dca1792011-01-26 19:32:14 +01005141 midi = status & (HDSPM_midi0IRQPending | HDSPM_midi1IRQPending |
5142 HDSPM_midi2IRQPending | HDSPM_midi3IRQPending);
Takashi Iwai763f3562005-06-03 11:25:34 +02005143
Adrian Knoth0dca1792011-01-26 19:32:14 +01005144 /* now = get_cycles(); */
5145 /**
5146 * LAT_2..LAT_0 period counter (win) counter (mac)
5147 * 6 4096 ~256053425 ~514672358
5148 * 5 2048 ~128024983 ~257373821
5149 * 4 1024 ~64023706 ~128718089
5150 * 3 512 ~32005945 ~64385999
5151 * 2 256 ~16003039 ~32260176
5152 * 1 128 ~7998738 ~16194507
5153 * 0 64 ~3998231 ~8191558
5154 **/
5155 /*
5156 snd_printk(KERN_INFO "snd_hdspm_interrupt %llu @ %llx\n",
5157 now-hdspm->last_interrupt, status & 0xFFC0);
5158 hdspm->last_interrupt = now;
5159 */
5160
5161 if (!audio && !midi)
Takashi Iwai763f3562005-06-03 11:25:34 +02005162 return IRQ_NONE;
5163
5164 hdspm_write(hdspm, HDSPM_interruptConfirmation, 0);
5165 hdspm->irq_count++;
5166
Takashi Iwai763f3562005-06-03 11:25:34 +02005167
5168 if (audio) {
Takashi Iwai763f3562005-06-03 11:25:34 +02005169 if (hdspm->capture_substream)
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02005170 snd_pcm_period_elapsed(hdspm->capture_substream);
Takashi Iwai763f3562005-06-03 11:25:34 +02005171
5172 if (hdspm->playback_substream)
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02005173 snd_pcm_period_elapsed(hdspm->playback_substream);
Takashi Iwai763f3562005-06-03 11:25:34 +02005174 }
5175
Adrian Knoth0dca1792011-01-26 19:32:14 +01005176 if (midi) {
5177 i = 0;
5178 while (i < hdspm->midiPorts) {
5179 if ((hdspm_read(hdspm,
5180 hdspm->midi[i].statusIn) & 0xff) &&
5181 (status & hdspm->midi[i].irq)) {
5182 /* we disable interrupts for this input until
5183 * processing is done
5184 */
5185 hdspm->control_register &= ~hdspm->midi[i].ie;
5186 hdspm_write(hdspm, HDSPM_controlRegister,
5187 hdspm->control_register);
5188 hdspm->midi[i].pending = 1;
5189 schedule = 1;
5190 }
5191
5192 i++;
5193 }
5194
5195 if (schedule)
5196 tasklet_hi_schedule(&hdspm->midi_tasklet);
Takashi Iwai763f3562005-06-03 11:25:34 +02005197 }
Adrian Knoth0dca1792011-01-26 19:32:14 +01005198
Takashi Iwai763f3562005-06-03 11:25:34 +02005199 return IRQ_HANDLED;
5200}
5201
5202/*------------------------------------------------------------
Adrian Knoth0dca1792011-01-26 19:32:14 +01005203 pcm interface
Takashi Iwai763f3562005-06-03 11:25:34 +02005204 ------------------------------------------------------------*/
5205
5206
Adrian Knoth0dca1792011-01-26 19:32:14 +01005207static snd_pcm_uframes_t snd_hdspm_hw_pointer(struct snd_pcm_substream
5208 *substream)
Takashi Iwai763f3562005-06-03 11:25:34 +02005209{
Takashi Iwai98274f02005-11-17 14:52:34 +01005210 struct hdspm *hdspm = snd_pcm_substream_chip(substream);
Takashi Iwai763f3562005-06-03 11:25:34 +02005211 return hdspm_hw_pointer(hdspm);
5212}
5213
Takashi Iwai763f3562005-06-03 11:25:34 +02005214
Takashi Iwai98274f02005-11-17 14:52:34 +01005215static int snd_hdspm_reset(struct snd_pcm_substream *substream)
Takashi Iwai763f3562005-06-03 11:25:34 +02005216{
Takashi Iwai98274f02005-11-17 14:52:34 +01005217 struct snd_pcm_runtime *runtime = substream->runtime;
5218 struct hdspm *hdspm = snd_pcm_substream_chip(substream);
5219 struct snd_pcm_substream *other;
Takashi Iwai763f3562005-06-03 11:25:34 +02005220
5221 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
5222 other = hdspm->capture_substream;
5223 else
5224 other = hdspm->playback_substream;
5225
5226 if (hdspm->running)
5227 runtime->status->hw_ptr = hdspm_hw_pointer(hdspm);
5228 else
5229 runtime->status->hw_ptr = 0;
5230 if (other) {
Takashi Iwai98274f02005-11-17 14:52:34 +01005231 struct snd_pcm_substream *s;
5232 struct snd_pcm_runtime *oruntime = other->runtime;
Takashi Iwaief991b92007-02-22 12:52:53 +01005233 snd_pcm_group_for_each_entry(s, substream) {
Takashi Iwai763f3562005-06-03 11:25:34 +02005234 if (s == other) {
5235 oruntime->status->hw_ptr =
Adrian Knoth0dca1792011-01-26 19:32:14 +01005236 runtime->status->hw_ptr;
Takashi Iwai763f3562005-06-03 11:25:34 +02005237 break;
5238 }
5239 }
5240 }
5241 return 0;
5242}
5243
Takashi Iwai98274f02005-11-17 14:52:34 +01005244static int snd_hdspm_hw_params(struct snd_pcm_substream *substream,
5245 struct snd_pcm_hw_params *params)
Takashi Iwai763f3562005-06-03 11:25:34 +02005246{
Takashi Iwai98274f02005-11-17 14:52:34 +01005247 struct hdspm *hdspm = snd_pcm_substream_chip(substream);
Takashi Iwai763f3562005-06-03 11:25:34 +02005248 int err;
5249 int i;
5250 pid_t this_pid;
5251 pid_t other_pid;
Takashi Iwai763f3562005-06-03 11:25:34 +02005252
5253 spin_lock_irq(&hdspm->lock);
5254
5255 if (substream->pstr->stream == SNDRV_PCM_STREAM_PLAYBACK) {
5256 this_pid = hdspm->playback_pid;
5257 other_pid = hdspm->capture_pid;
5258 } else {
5259 this_pid = hdspm->capture_pid;
5260 other_pid = hdspm->playback_pid;
5261 }
5262
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02005263 if (other_pid > 0 && this_pid != other_pid) {
Takashi Iwai763f3562005-06-03 11:25:34 +02005264
5265 /* The other stream is open, and not by the same
5266 task as this one. Make sure that the parameters
5267 that matter are the same.
Adrian Knoth0dca1792011-01-26 19:32:14 +01005268 */
Takashi Iwai763f3562005-06-03 11:25:34 +02005269
5270 if (params_rate(params) != hdspm->system_sample_rate) {
5271 spin_unlock_irq(&hdspm->lock);
5272 _snd_pcm_hw_param_setempty(params,
Adrian Knoth0dca1792011-01-26 19:32:14 +01005273 SNDRV_PCM_HW_PARAM_RATE);
Takashi Iwai763f3562005-06-03 11:25:34 +02005274 return -EBUSY;
5275 }
5276
5277 if (params_period_size(params) != hdspm->period_bytes / 4) {
5278 spin_unlock_irq(&hdspm->lock);
5279 _snd_pcm_hw_param_setempty(params,
Adrian Knoth0dca1792011-01-26 19:32:14 +01005280 SNDRV_PCM_HW_PARAM_PERIOD_SIZE);
Takashi Iwai763f3562005-06-03 11:25:34 +02005281 return -EBUSY;
5282 }
5283
5284 }
5285 /* We're fine. */
5286 spin_unlock_irq(&hdspm->lock);
5287
5288 /* how to make sure that the rate matches an externally-set one ? */
5289
5290 spin_lock_irq(&hdspm->lock);
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02005291 err = hdspm_set_rate(hdspm, params_rate(params), 0);
5292 if (err < 0) {
Adrian Knoth0dca1792011-01-26 19:32:14 +01005293 snd_printk(KERN_INFO "err on hdspm_set_rate: %d\n", err);
Takashi Iwai763f3562005-06-03 11:25:34 +02005294 spin_unlock_irq(&hdspm->lock);
5295 _snd_pcm_hw_param_setempty(params,
Adrian Knoth0dca1792011-01-26 19:32:14 +01005296 SNDRV_PCM_HW_PARAM_RATE);
Takashi Iwai763f3562005-06-03 11:25:34 +02005297 return err;
5298 }
5299 spin_unlock_irq(&hdspm->lock);
5300
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02005301 err = hdspm_set_interrupt_interval(hdspm,
Adrian Knoth0dca1792011-01-26 19:32:14 +01005302 params_period_size(params));
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02005303 if (err < 0) {
Adrian Knoth0dca1792011-01-26 19:32:14 +01005304 snd_printk(KERN_INFO "err on hdspm_set_interrupt_interval: %d\n", err);
Takashi Iwai763f3562005-06-03 11:25:34 +02005305 _snd_pcm_hw_param_setempty(params,
Adrian Knoth0dca1792011-01-26 19:32:14 +01005306 SNDRV_PCM_HW_PARAM_PERIOD_SIZE);
Takashi Iwai763f3562005-06-03 11:25:34 +02005307 return err;
5308 }
5309
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02005310 /* Memory allocation, takashi's method, dont know if we should
5311 * spinlock
5312 */
Takashi Iwai763f3562005-06-03 11:25:34 +02005313 /* malloc all buffer even if not enabled to get sure */
Remy Brunoffb2c3c2007-03-07 19:08:46 +01005314 /* Update for MADI rev 204: we need to allocate for all channels,
5315 * otherwise it doesn't work at 96kHz */
Adrian Knoth0dca1792011-01-26 19:32:14 +01005316
Takashi Iwai763f3562005-06-03 11:25:34 +02005317 err =
Adrian Knoth0dca1792011-01-26 19:32:14 +01005318 snd_pcm_lib_malloc_pages(substream, HDSPM_DMA_AREA_BYTES);
5319 if (err < 0) {
5320 snd_printk(KERN_INFO "err on snd_pcm_lib_malloc_pages: %d\n", err);
Takashi Iwai763f3562005-06-03 11:25:34 +02005321 return err;
Adrian Knoth0dca1792011-01-26 19:32:14 +01005322 }
Takashi Iwai763f3562005-06-03 11:25:34 +02005323
Takashi Iwai763f3562005-06-03 11:25:34 +02005324 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
5325
Takashi Iwai77a23f22008-08-21 13:00:13 +02005326 hdspm_set_sgbuf(hdspm, substream, HDSPM_pageAddressBufferOut,
Takashi Iwai763f3562005-06-03 11:25:34 +02005327 params_channels(params));
5328
5329 for (i = 0; i < params_channels(params); ++i)
5330 snd_hdspm_enable_out(hdspm, i, 1);
5331
5332 hdspm->playback_buffer =
Adrian Knoth0dca1792011-01-26 19:32:14 +01005333 (unsigned char *) substream->runtime->dma_area;
Takashi Iwai54bf5dd2006-11-06 15:38:55 +01005334 snd_printdd("Allocated sample buffer for playback at %p\n",
Remy Bruno3cee5a62006-10-16 12:46:32 +02005335 hdspm->playback_buffer);
Takashi Iwai763f3562005-06-03 11:25:34 +02005336 } else {
Takashi Iwai77a23f22008-08-21 13:00:13 +02005337 hdspm_set_sgbuf(hdspm, substream, HDSPM_pageAddressBufferIn,
Takashi Iwai763f3562005-06-03 11:25:34 +02005338 params_channels(params));
5339
5340 for (i = 0; i < params_channels(params); ++i)
5341 snd_hdspm_enable_in(hdspm, i, 1);
5342
5343 hdspm->capture_buffer =
Adrian Knoth0dca1792011-01-26 19:32:14 +01005344 (unsigned char *) substream->runtime->dma_area;
Takashi Iwai54bf5dd2006-11-06 15:38:55 +01005345 snd_printdd("Allocated sample buffer for capture at %p\n",
Remy Bruno3cee5a62006-10-16 12:46:32 +02005346 hdspm->capture_buffer);
Takashi Iwai763f3562005-06-03 11:25:34 +02005347 }
Adrian Knoth0dca1792011-01-26 19:32:14 +01005348
Remy Bruno3cee5a62006-10-16 12:46:32 +02005349 /*
5350 snd_printdd("Allocated sample buffer for %s at 0x%08X\n",
5351 substream->stream == SNDRV_PCM_STREAM_PLAYBACK ?
5352 "playback" : "capture",
Takashi Iwai77a23f22008-08-21 13:00:13 +02005353 snd_pcm_sgbuf_get_addr(substream, 0));
Adrian Knoth0dca1792011-01-26 19:32:14 +01005354 */
Remy Brunoffb2c3c2007-03-07 19:08:46 +01005355 /*
Adrian Knoth0dca1792011-01-26 19:32:14 +01005356 snd_printdd("set_hwparams: %s %d Hz, %d channels, bs = %d\n",
5357 substream->stream == SNDRV_PCM_STREAM_PLAYBACK ?
5358 "playback" : "capture",
5359 params_rate(params), params_channels(params),
5360 params_buffer_size(params));
5361 */
5362
5363
5364 /* Switch to native float format if requested */
5365 if (SNDRV_PCM_FORMAT_FLOAT_LE == params_format(params)) {
5366 if (!(hdspm->control_register & HDSPe_FLOAT_FORMAT))
5367 snd_printk(KERN_INFO "hdspm: Switching to native 32bit LE float format.\n");
5368
5369 hdspm->control_register |= HDSPe_FLOAT_FORMAT;
5370 } else if (SNDRV_PCM_FORMAT_S32_LE == params_format(params)) {
5371 if (hdspm->control_register & HDSPe_FLOAT_FORMAT)
5372 snd_printk(KERN_INFO "hdspm: Switching to native 32bit LE integer format.\n");
5373
5374 hdspm->control_register &= ~HDSPe_FLOAT_FORMAT;
5375 }
5376 hdspm_write(hdspm, HDSPM_controlRegister, hdspm->control_register);
5377
Takashi Iwai763f3562005-06-03 11:25:34 +02005378 return 0;
5379}
5380
Takashi Iwai98274f02005-11-17 14:52:34 +01005381static int snd_hdspm_hw_free(struct snd_pcm_substream *substream)
Takashi Iwai763f3562005-06-03 11:25:34 +02005382{
5383 int i;
Takashi Iwai98274f02005-11-17 14:52:34 +01005384 struct hdspm *hdspm = snd_pcm_substream_chip(substream);
Takashi Iwai763f3562005-06-03 11:25:34 +02005385
5386 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
5387
Adrian Knoth0dca1792011-01-26 19:32:14 +01005388 /* params_channels(params) should be enough,
Takashi Iwai763f3562005-06-03 11:25:34 +02005389 but to get sure in case of error */
Adrian Knoth0dca1792011-01-26 19:32:14 +01005390 for (i = 0; i < hdspm->max_channels_out; ++i)
Takashi Iwai763f3562005-06-03 11:25:34 +02005391 snd_hdspm_enable_out(hdspm, i, 0);
5392
5393 hdspm->playback_buffer = NULL;
5394 } else {
Adrian Knoth0dca1792011-01-26 19:32:14 +01005395 for (i = 0; i < hdspm->max_channels_in; ++i)
Takashi Iwai763f3562005-06-03 11:25:34 +02005396 snd_hdspm_enable_in(hdspm, i, 0);
5397
5398 hdspm->capture_buffer = NULL;
5399
5400 }
5401
5402 snd_pcm_lib_free_pages(substream);
5403
5404 return 0;
5405}
5406
Adrian Knoth0dca1792011-01-26 19:32:14 +01005407
Takashi Iwai98274f02005-11-17 14:52:34 +01005408static int snd_hdspm_channel_info(struct snd_pcm_substream *substream,
Adrian Knoth0dca1792011-01-26 19:32:14 +01005409 struct snd_pcm_channel_info *info)
Takashi Iwai763f3562005-06-03 11:25:34 +02005410{
Takashi Iwai98274f02005-11-17 14:52:34 +01005411 struct hdspm *hdspm = snd_pcm_substream_chip(substream);
Takashi Iwai763f3562005-06-03 11:25:34 +02005412
Adrian Knoth0dca1792011-01-26 19:32:14 +01005413 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
5414 if (snd_BUG_ON(info->channel >= hdspm->max_channels_out)) {
5415 snd_printk(KERN_INFO "snd_hdspm_channel_info: output channel out of range (%d)\n", info->channel);
5416 return -EINVAL;
5417 }
Takashi Iwai763f3562005-06-03 11:25:34 +02005418
Adrian Knoth0dca1792011-01-26 19:32:14 +01005419 if (hdspm->channel_map_out[info->channel] < 0) {
5420 snd_printk(KERN_INFO "snd_hdspm_channel_info: output channel %d mapped out\n", info->channel);
5421 return -EINVAL;
5422 }
Takashi Iwai763f3562005-06-03 11:25:34 +02005423
Adrian Knoth0dca1792011-01-26 19:32:14 +01005424 info->offset = hdspm->channel_map_out[info->channel] *
5425 HDSPM_CHANNEL_BUFFER_BYTES;
5426 } else {
5427 if (snd_BUG_ON(info->channel >= hdspm->max_channels_in)) {
5428 snd_printk(KERN_INFO "snd_hdspm_channel_info: input channel out of range (%d)\n", info->channel);
5429 return -EINVAL;
5430 }
5431
5432 if (hdspm->channel_map_in[info->channel] < 0) {
5433 snd_printk(KERN_INFO "snd_hdspm_channel_info: input channel %d mapped out\n", info->channel);
5434 return -EINVAL;
5435 }
5436
5437 info->offset = hdspm->channel_map_in[info->channel] *
5438 HDSPM_CHANNEL_BUFFER_BYTES;
5439 }
5440
Takashi Iwai763f3562005-06-03 11:25:34 +02005441 info->first = 0;
5442 info->step = 32;
5443 return 0;
5444}
5445
Adrian Knoth0dca1792011-01-26 19:32:14 +01005446
Takashi Iwai98274f02005-11-17 14:52:34 +01005447static int snd_hdspm_ioctl(struct snd_pcm_substream *substream,
Adrian Knoth0dca1792011-01-26 19:32:14 +01005448 unsigned int cmd, void *arg)
Takashi Iwai763f3562005-06-03 11:25:34 +02005449{
5450 switch (cmd) {
5451 case SNDRV_PCM_IOCTL1_RESET:
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02005452 return snd_hdspm_reset(substream);
Takashi Iwai763f3562005-06-03 11:25:34 +02005453
5454 case SNDRV_PCM_IOCTL1_CHANNEL_INFO:
Adrian Knoth0dca1792011-01-26 19:32:14 +01005455 {
5456 struct snd_pcm_channel_info *info = arg;
5457 return snd_hdspm_channel_info(substream, info);
5458 }
Takashi Iwai763f3562005-06-03 11:25:34 +02005459 default:
5460 break;
5461 }
5462
5463 return snd_pcm_lib_ioctl(substream, cmd, arg);
5464}
5465
Takashi Iwai98274f02005-11-17 14:52:34 +01005466static int snd_hdspm_trigger(struct snd_pcm_substream *substream, int cmd)
Takashi Iwai763f3562005-06-03 11:25:34 +02005467{
Takashi Iwai98274f02005-11-17 14:52:34 +01005468 struct hdspm *hdspm = snd_pcm_substream_chip(substream);
5469 struct snd_pcm_substream *other;
Takashi Iwai763f3562005-06-03 11:25:34 +02005470 int running;
5471
5472 spin_lock(&hdspm->lock);
5473 running = hdspm->running;
5474 switch (cmd) {
5475 case SNDRV_PCM_TRIGGER_START:
5476 running |= 1 << substream->stream;
5477 break;
5478 case SNDRV_PCM_TRIGGER_STOP:
5479 running &= ~(1 << substream->stream);
5480 break;
5481 default:
5482 snd_BUG();
5483 spin_unlock(&hdspm->lock);
5484 return -EINVAL;
5485 }
5486 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
5487 other = hdspm->capture_substream;
5488 else
5489 other = hdspm->playback_substream;
5490
5491 if (other) {
Takashi Iwai98274f02005-11-17 14:52:34 +01005492 struct snd_pcm_substream *s;
Takashi Iwaief991b92007-02-22 12:52:53 +01005493 snd_pcm_group_for_each_entry(s, substream) {
Takashi Iwai763f3562005-06-03 11:25:34 +02005494 if (s == other) {
5495 snd_pcm_trigger_done(s, substream);
5496 if (cmd == SNDRV_PCM_TRIGGER_START)
5497 running |= 1 << s->stream;
5498 else
5499 running &= ~(1 << s->stream);
5500 goto _ok;
5501 }
5502 }
5503 if (cmd == SNDRV_PCM_TRIGGER_START) {
5504 if (!(running & (1 << SNDRV_PCM_STREAM_PLAYBACK))
Adrian Knoth0dca1792011-01-26 19:32:14 +01005505 && substream->stream ==
5506 SNDRV_PCM_STREAM_CAPTURE)
Takashi Iwai763f3562005-06-03 11:25:34 +02005507 hdspm_silence_playback(hdspm);
5508 } else {
5509 if (running &&
Adrian Knoth0dca1792011-01-26 19:32:14 +01005510 substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
Takashi Iwai763f3562005-06-03 11:25:34 +02005511 hdspm_silence_playback(hdspm);
5512 }
5513 } else {
5514 if (substream->stream == SNDRV_PCM_STREAM_CAPTURE)
5515 hdspm_silence_playback(hdspm);
5516 }
Adrian Knoth0dca1792011-01-26 19:32:14 +01005517_ok:
Takashi Iwai763f3562005-06-03 11:25:34 +02005518 snd_pcm_trigger_done(substream, substream);
5519 if (!hdspm->running && running)
5520 hdspm_start_audio(hdspm);
5521 else if (hdspm->running && !running)
5522 hdspm_stop_audio(hdspm);
5523 hdspm->running = running;
5524 spin_unlock(&hdspm->lock);
5525
5526 return 0;
5527}
5528
Takashi Iwai98274f02005-11-17 14:52:34 +01005529static int snd_hdspm_prepare(struct snd_pcm_substream *substream)
Takashi Iwai763f3562005-06-03 11:25:34 +02005530{
5531 return 0;
5532}
5533
Adrian Knoth0dca1792011-01-26 19:32:14 +01005534static unsigned int period_sizes_old[] = {
5535 64, 128, 256, 512, 1024, 2048, 4096
5536};
5537
5538static unsigned int period_sizes_new[] = {
5539 32, 64, 128, 256, 512, 1024, 2048, 4096
5540};
5541
5542/* RayDAT and AIO always have a buffer of 16384 samples per channel */
5543static unsigned int raydat_aio_buffer_sizes[] = {
5544 16384
5545};
Takashi Iwai763f3562005-06-03 11:25:34 +02005546
Takashi Iwai98274f02005-11-17 14:52:34 +01005547static struct snd_pcm_hardware snd_hdspm_playback_subinfo = {
Takashi Iwai763f3562005-06-03 11:25:34 +02005548 .info = (SNDRV_PCM_INFO_MMAP |
5549 SNDRV_PCM_INFO_MMAP_VALID |
5550 SNDRV_PCM_INFO_NONINTERLEAVED |
5551 SNDRV_PCM_INFO_SYNC_START | SNDRV_PCM_INFO_DOUBLE),
5552 .formats = SNDRV_PCM_FMTBIT_S32_LE,
5553 .rates = (SNDRV_PCM_RATE_32000 |
5554 SNDRV_PCM_RATE_44100 |
5555 SNDRV_PCM_RATE_48000 |
5556 SNDRV_PCM_RATE_64000 |
Remy Bruno3cee5a62006-10-16 12:46:32 +02005557 SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000 |
5558 SNDRV_PCM_RATE_176400 | SNDRV_PCM_RATE_192000 ),
Takashi Iwai763f3562005-06-03 11:25:34 +02005559 .rate_min = 32000,
Remy Bruno3cee5a62006-10-16 12:46:32 +02005560 .rate_max = 192000,
Takashi Iwai763f3562005-06-03 11:25:34 +02005561 .channels_min = 1,
5562 .channels_max = HDSPM_MAX_CHANNELS,
5563 .buffer_bytes_max =
5564 HDSPM_CHANNEL_BUFFER_BYTES * HDSPM_MAX_CHANNELS,
5565 .period_bytes_min = (64 * 4),
Adrian Knoth0dca1792011-01-26 19:32:14 +01005566 .period_bytes_max = (4096 * 4) * HDSPM_MAX_CHANNELS,
Takashi Iwai763f3562005-06-03 11:25:34 +02005567 .periods_min = 2,
Adrian Knoth0dca1792011-01-26 19:32:14 +01005568 .periods_max = 512,
Takashi Iwai763f3562005-06-03 11:25:34 +02005569 .fifo_size = 0
5570};
5571
Takashi Iwai98274f02005-11-17 14:52:34 +01005572static struct snd_pcm_hardware snd_hdspm_capture_subinfo = {
Takashi Iwai763f3562005-06-03 11:25:34 +02005573 .info = (SNDRV_PCM_INFO_MMAP |
5574 SNDRV_PCM_INFO_MMAP_VALID |
5575 SNDRV_PCM_INFO_NONINTERLEAVED |
5576 SNDRV_PCM_INFO_SYNC_START),
5577 .formats = SNDRV_PCM_FMTBIT_S32_LE,
5578 .rates = (SNDRV_PCM_RATE_32000 |
5579 SNDRV_PCM_RATE_44100 |
5580 SNDRV_PCM_RATE_48000 |
5581 SNDRV_PCM_RATE_64000 |
Remy Bruno3cee5a62006-10-16 12:46:32 +02005582 SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000 |
5583 SNDRV_PCM_RATE_176400 | SNDRV_PCM_RATE_192000),
Takashi Iwai763f3562005-06-03 11:25:34 +02005584 .rate_min = 32000,
Remy Bruno3cee5a62006-10-16 12:46:32 +02005585 .rate_max = 192000,
Takashi Iwai763f3562005-06-03 11:25:34 +02005586 .channels_min = 1,
5587 .channels_max = HDSPM_MAX_CHANNELS,
5588 .buffer_bytes_max =
5589 HDSPM_CHANNEL_BUFFER_BYTES * HDSPM_MAX_CHANNELS,
5590 .period_bytes_min = (64 * 4),
Adrian Knoth0dca1792011-01-26 19:32:14 +01005591 .period_bytes_max = (4096 * 4) * HDSPM_MAX_CHANNELS,
Takashi Iwai763f3562005-06-03 11:25:34 +02005592 .periods_min = 2,
Adrian Knoth0dca1792011-01-26 19:32:14 +01005593 .periods_max = 512,
Takashi Iwai763f3562005-06-03 11:25:34 +02005594 .fifo_size = 0
5595};
5596
Adrian Knoth0dca1792011-01-26 19:32:14 +01005597static struct snd_pcm_hw_constraint_list hw_constraints_period_sizes_old = {
5598 .count = ARRAY_SIZE(period_sizes_old),
5599 .list = period_sizes_old,
Takashi Iwai763f3562005-06-03 11:25:34 +02005600 .mask = 0
5601};
5602
Adrian Knoth0dca1792011-01-26 19:32:14 +01005603static struct snd_pcm_hw_constraint_list hw_constraints_period_sizes_new = {
5604 .count = ARRAY_SIZE(period_sizes_new),
5605 .list = period_sizes_new,
5606 .mask = 0
5607};
Takashi Iwai763f3562005-06-03 11:25:34 +02005608
Adrian Knoth0dca1792011-01-26 19:32:14 +01005609static struct snd_pcm_hw_constraint_list hw_constraints_raydat_io_buffer = {
5610 .count = ARRAY_SIZE(raydat_aio_buffer_sizes),
5611 .list = raydat_aio_buffer_sizes,
5612 .mask = 0
5613};
5614
5615static int snd_hdspm_hw_rule_in_channels_rate(struct snd_pcm_hw_params *params,
5616 struct snd_pcm_hw_rule *rule)
Takashi Iwai763f3562005-06-03 11:25:34 +02005617{
Takashi Iwai98274f02005-11-17 14:52:34 +01005618 struct hdspm *hdspm = rule->private;
5619 struct snd_interval *c =
Takashi Iwai763f3562005-06-03 11:25:34 +02005620 hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS);
Takashi Iwai98274f02005-11-17 14:52:34 +01005621 struct snd_interval *r =
Takashi Iwai763f3562005-06-03 11:25:34 +02005622 hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE);
5623
Adrian Knoth0dca1792011-01-26 19:32:14 +01005624 if (r->min > 96000 && r->max <= 192000) {
Takashi Iwai98274f02005-11-17 14:52:34 +01005625 struct snd_interval t = {
Adrian Knoth0dca1792011-01-26 19:32:14 +01005626 .min = hdspm->qs_in_channels,
5627 .max = hdspm->qs_in_channels,
5628 .integer = 1,
5629 };
5630 return snd_interval_refine(c, &t);
5631 } else if (r->min > 48000 && r->max <= 96000) {
5632 struct snd_interval t = {
5633 .min = hdspm->ds_in_channels,
5634 .max = hdspm->ds_in_channels,
Takashi Iwai763f3562005-06-03 11:25:34 +02005635 .integer = 1,
5636 };
5637 return snd_interval_refine(c, &t);
5638 } else if (r->max < 64000) {
Takashi Iwai98274f02005-11-17 14:52:34 +01005639 struct snd_interval t = {
Adrian Knoth0dca1792011-01-26 19:32:14 +01005640 .min = hdspm->ss_in_channels,
5641 .max = hdspm->ss_in_channels,
Takashi Iwai763f3562005-06-03 11:25:34 +02005642 .integer = 1,
5643 };
5644 return snd_interval_refine(c, &t);
5645 }
Adrian Knoth0dca1792011-01-26 19:32:14 +01005646
Takashi Iwai763f3562005-06-03 11:25:34 +02005647 return 0;
5648}
5649
Adrian Knoth0dca1792011-01-26 19:32:14 +01005650static int snd_hdspm_hw_rule_out_channels_rate(struct snd_pcm_hw_params *params,
Takashi Iwai98274f02005-11-17 14:52:34 +01005651 struct snd_pcm_hw_rule * rule)
Takashi Iwai763f3562005-06-03 11:25:34 +02005652{
Takashi Iwai98274f02005-11-17 14:52:34 +01005653 struct hdspm *hdspm = rule->private;
5654 struct snd_interval *c =
Takashi Iwai763f3562005-06-03 11:25:34 +02005655 hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS);
Takashi Iwai98274f02005-11-17 14:52:34 +01005656 struct snd_interval *r =
Takashi Iwai763f3562005-06-03 11:25:34 +02005657 hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE);
5658
Adrian Knoth0dca1792011-01-26 19:32:14 +01005659 if (r->min > 96000 && r->max <= 192000) {
5660 struct snd_interval t = {
5661 .min = hdspm->qs_out_channels,
5662 .max = hdspm->qs_out_channels,
5663 .integer = 1,
5664 };
5665 return snd_interval_refine(c, &t);
5666 } else if (r->min > 48000 && r->max <= 96000) {
5667 struct snd_interval t = {
5668 .min = hdspm->ds_out_channels,
5669 .max = hdspm->ds_out_channels,
5670 .integer = 1,
5671 };
5672 return snd_interval_refine(c, &t);
5673 } else if (r->max < 64000) {
5674 struct snd_interval t = {
5675 .min = hdspm->ss_out_channels,
5676 .max = hdspm->ss_out_channels,
5677 .integer = 1,
5678 };
5679 return snd_interval_refine(c, &t);
5680 } else {
5681 }
5682 return 0;
5683}
5684
5685static int snd_hdspm_hw_rule_rate_in_channels(struct snd_pcm_hw_params *params,
5686 struct snd_pcm_hw_rule * rule)
5687{
5688 struct hdspm *hdspm = rule->private;
5689 struct snd_interval *c =
5690 hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS);
5691 struct snd_interval *r =
5692 hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE);
5693
5694 if (c->min >= hdspm->ss_in_channels) {
Takashi Iwai98274f02005-11-17 14:52:34 +01005695 struct snd_interval t = {
Takashi Iwai763f3562005-06-03 11:25:34 +02005696 .min = 32000,
5697 .max = 48000,
5698 .integer = 1,
5699 };
5700 return snd_interval_refine(r, &t);
Adrian Knoth0dca1792011-01-26 19:32:14 +01005701 } else if (c->max <= hdspm->qs_in_channels) {
5702 struct snd_interval t = {
5703 .min = 128000,
5704 .max = 192000,
5705 .integer = 1,
5706 };
5707 return snd_interval_refine(r, &t);
5708 } else if (c->max <= hdspm->ds_in_channels) {
Takashi Iwai98274f02005-11-17 14:52:34 +01005709 struct snd_interval t = {
Takashi Iwai763f3562005-06-03 11:25:34 +02005710 .min = 64000,
5711 .max = 96000,
5712 .integer = 1,
5713 };
Takashi Iwai763f3562005-06-03 11:25:34 +02005714 return snd_interval_refine(r, &t);
5715 }
Adrian Knoth0dca1792011-01-26 19:32:14 +01005716
5717 return 0;
5718}
5719static int snd_hdspm_hw_rule_rate_out_channels(struct snd_pcm_hw_params *params,
5720 struct snd_pcm_hw_rule *rule)
5721{
5722 struct hdspm *hdspm = rule->private;
5723 struct snd_interval *c =
5724 hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS);
5725 struct snd_interval *r =
5726 hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE);
5727
5728 if (c->min >= hdspm->ss_out_channels) {
5729 struct snd_interval t = {
5730 .min = 32000,
5731 .max = 48000,
5732 .integer = 1,
5733 };
5734 return snd_interval_refine(r, &t);
5735 } else if (c->max <= hdspm->qs_out_channels) {
5736 struct snd_interval t = {
5737 .min = 128000,
5738 .max = 192000,
5739 .integer = 1,
5740 };
5741 return snd_interval_refine(r, &t);
5742 } else if (c->max <= hdspm->ds_out_channels) {
5743 struct snd_interval t = {
5744 .min = 64000,
5745 .max = 96000,
5746 .integer = 1,
5747 };
5748 return snd_interval_refine(r, &t);
5749 }
5750
Takashi Iwai763f3562005-06-03 11:25:34 +02005751 return 0;
5752}
5753
Adrian Knoth0dca1792011-01-26 19:32:14 +01005754static int snd_hdspm_hw_rule_in_channels(struct snd_pcm_hw_params *params,
Remy Brunoffb2c3c2007-03-07 19:08:46 +01005755 struct snd_pcm_hw_rule *rule)
5756{
5757 unsigned int list[3];
5758 struct hdspm *hdspm = rule->private;
5759 struct snd_interval *c = hw_param_interval(params,
5760 SNDRV_PCM_HW_PARAM_CHANNELS);
Adrian Knoth0dca1792011-01-26 19:32:14 +01005761
5762 list[0] = hdspm->qs_in_channels;
5763 list[1] = hdspm->ds_in_channels;
5764 list[2] = hdspm->ss_in_channels;
5765 return snd_interval_list(c, 3, list, 0);
5766}
5767
5768static int snd_hdspm_hw_rule_out_channels(struct snd_pcm_hw_params *params,
5769 struct snd_pcm_hw_rule *rule)
5770{
5771 unsigned int list[3];
5772 struct hdspm *hdspm = rule->private;
5773 struct snd_interval *c = hw_param_interval(params,
5774 SNDRV_PCM_HW_PARAM_CHANNELS);
5775
5776 list[0] = hdspm->qs_out_channels;
5777 list[1] = hdspm->ds_out_channels;
5778 list[2] = hdspm->ss_out_channels;
5779 return snd_interval_list(c, 3, list, 0);
Remy Brunoffb2c3c2007-03-07 19:08:46 +01005780}
5781
5782
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02005783static unsigned int hdspm_aes32_sample_rates[] = {
5784 32000, 44100, 48000, 64000, 88200, 96000, 128000, 176400, 192000
5785};
Remy Brunoffb2c3c2007-03-07 19:08:46 +01005786
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02005787static struct snd_pcm_hw_constraint_list
5788hdspm_hw_constraints_aes32_sample_rates = {
Remy Brunoffb2c3c2007-03-07 19:08:46 +01005789 .count = ARRAY_SIZE(hdspm_aes32_sample_rates),
5790 .list = hdspm_aes32_sample_rates,
5791 .mask = 0
5792};
5793
Takashi Iwai98274f02005-11-17 14:52:34 +01005794static int snd_hdspm_playback_open(struct snd_pcm_substream *substream)
Takashi Iwai763f3562005-06-03 11:25:34 +02005795{
Takashi Iwai98274f02005-11-17 14:52:34 +01005796 struct hdspm *hdspm = snd_pcm_substream_chip(substream);
5797 struct snd_pcm_runtime *runtime = substream->runtime;
Takashi Iwai763f3562005-06-03 11:25:34 +02005798
Takashi Iwai763f3562005-06-03 11:25:34 +02005799 spin_lock_irq(&hdspm->lock);
5800
5801 snd_pcm_set_sync(substream);
5802
Adrian Knoth0dca1792011-01-26 19:32:14 +01005803
Takashi Iwai763f3562005-06-03 11:25:34 +02005804 runtime->hw = snd_hdspm_playback_subinfo;
5805
5806 if (hdspm->capture_substream == NULL)
5807 hdspm_stop_audio(hdspm);
5808
5809 hdspm->playback_pid = current->pid;
5810 hdspm->playback_substream = substream;
5811
5812 spin_unlock_irq(&hdspm->lock);
5813
5814 snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24);
5815
Adrian Knoth0dca1792011-01-26 19:32:14 +01005816 switch (hdspm->io_type) {
5817 case AIO:
5818 case RayDAT:
5819 snd_pcm_hw_constraint_list(runtime, 0,
5820 SNDRV_PCM_HW_PARAM_PERIOD_SIZE,
5821 &hw_constraints_period_sizes_new);
5822 snd_pcm_hw_constraint_list(runtime, 0,
5823 SNDRV_PCM_HW_PARAM_BUFFER_SIZE,
5824 &hw_constraints_raydat_io_buffer);
Takashi Iwai763f3562005-06-03 11:25:34 +02005825
Adrian Knoth0dca1792011-01-26 19:32:14 +01005826 break;
5827
5828 default:
5829 snd_pcm_hw_constraint_list(runtime, 0,
5830 SNDRV_PCM_HW_PARAM_PERIOD_SIZE,
5831 &hw_constraints_period_sizes_old);
5832 }
5833
5834 if (AES32 == hdspm->io_type) {
Remy Brunoffb2c3c2007-03-07 19:08:46 +01005835 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
5836 &hdspm_hw_constraints_aes32_sample_rates);
5837 } else {
Remy Brunoffb2c3c2007-03-07 19:08:46 +01005838 snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
Adrian Knoth0dca1792011-01-26 19:32:14 +01005839 snd_hdspm_hw_rule_rate_out_channels, hdspm,
5840 SNDRV_PCM_HW_PARAM_CHANNELS, -1);
Remy Brunoffb2c3c2007-03-07 19:08:46 +01005841 }
Adrian Knoth88fabbf2011-02-23 11:43:10 +01005842
5843 snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
5844 snd_hdspm_hw_rule_out_channels, hdspm,
5845 SNDRV_PCM_HW_PARAM_CHANNELS, -1);
5846
5847 snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
5848 snd_hdspm_hw_rule_out_channels_rate, hdspm,
5849 SNDRV_PCM_HW_PARAM_RATE, -1);
5850
Takashi Iwai763f3562005-06-03 11:25:34 +02005851 return 0;
5852}
5853
Takashi Iwai98274f02005-11-17 14:52:34 +01005854static int snd_hdspm_playback_release(struct snd_pcm_substream *substream)
Takashi Iwai763f3562005-06-03 11:25:34 +02005855{
Takashi Iwai98274f02005-11-17 14:52:34 +01005856 struct hdspm *hdspm = snd_pcm_substream_chip(substream);
Takashi Iwai763f3562005-06-03 11:25:34 +02005857
5858 spin_lock_irq(&hdspm->lock);
5859
5860 hdspm->playback_pid = -1;
5861 hdspm->playback_substream = NULL;
5862
5863 spin_unlock_irq(&hdspm->lock);
5864
5865 return 0;
5866}
5867
5868
Takashi Iwai98274f02005-11-17 14:52:34 +01005869static int snd_hdspm_capture_open(struct snd_pcm_substream *substream)
Takashi Iwai763f3562005-06-03 11:25:34 +02005870{
Takashi Iwai98274f02005-11-17 14:52:34 +01005871 struct hdspm *hdspm = snd_pcm_substream_chip(substream);
5872 struct snd_pcm_runtime *runtime = substream->runtime;
Takashi Iwai763f3562005-06-03 11:25:34 +02005873
5874 spin_lock_irq(&hdspm->lock);
5875 snd_pcm_set_sync(substream);
5876 runtime->hw = snd_hdspm_capture_subinfo;
5877
5878 if (hdspm->playback_substream == NULL)
5879 hdspm_stop_audio(hdspm);
5880
5881 hdspm->capture_pid = current->pid;
5882 hdspm->capture_substream = substream;
5883
5884 spin_unlock_irq(&hdspm->lock);
5885
5886 snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24);
Adrian Knoth0dca1792011-01-26 19:32:14 +01005887 switch (hdspm->io_type) {
5888 case AIO:
5889 case RayDAT:
5890 snd_pcm_hw_constraint_list(runtime, 0,
5891 SNDRV_PCM_HW_PARAM_PERIOD_SIZE,
5892 &hw_constraints_period_sizes_new);
5893 snd_pcm_hw_constraint_list(runtime, 0,
5894 SNDRV_PCM_HW_PARAM_BUFFER_SIZE,
5895 &hw_constraints_raydat_io_buffer);
5896 break;
5897
5898 default:
5899 snd_pcm_hw_constraint_list(runtime, 0,
5900 SNDRV_PCM_HW_PARAM_PERIOD_SIZE,
5901 &hw_constraints_period_sizes_old);
5902 }
5903
5904 if (AES32 == hdspm->io_type) {
Remy Brunoffb2c3c2007-03-07 19:08:46 +01005905 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
5906 &hdspm_hw_constraints_aes32_sample_rates);
5907 } else {
Remy Brunoffb2c3c2007-03-07 19:08:46 +01005908 snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
Adrian Knoth88fabbf2011-02-23 11:43:10 +01005909 snd_hdspm_hw_rule_rate_in_channels, hdspm,
5910 SNDRV_PCM_HW_PARAM_CHANNELS, -1);
Remy Brunoffb2c3c2007-03-07 19:08:46 +01005911 }
Adrian Knoth88fabbf2011-02-23 11:43:10 +01005912
5913 snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
5914 snd_hdspm_hw_rule_in_channels, hdspm,
5915 SNDRV_PCM_HW_PARAM_CHANNELS, -1);
5916
5917 snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
5918 snd_hdspm_hw_rule_in_channels_rate, hdspm,
5919 SNDRV_PCM_HW_PARAM_RATE, -1);
5920
Takashi Iwai763f3562005-06-03 11:25:34 +02005921 return 0;
5922}
5923
Takashi Iwai98274f02005-11-17 14:52:34 +01005924static int snd_hdspm_capture_release(struct snd_pcm_substream *substream)
Takashi Iwai763f3562005-06-03 11:25:34 +02005925{
Takashi Iwai98274f02005-11-17 14:52:34 +01005926 struct hdspm *hdspm = snd_pcm_substream_chip(substream);
Takashi Iwai763f3562005-06-03 11:25:34 +02005927
5928 spin_lock_irq(&hdspm->lock);
5929
5930 hdspm->capture_pid = -1;
5931 hdspm->capture_substream = NULL;
5932
5933 spin_unlock_irq(&hdspm->lock);
5934 return 0;
5935}
5936
Adrian Knoth0dca1792011-01-26 19:32:14 +01005937static int snd_hdspm_hwdep_dummy_op(struct snd_hwdep *hw, struct file *file)
Takashi Iwai763f3562005-06-03 11:25:34 +02005938{
Adrian Knoth0dca1792011-01-26 19:32:14 +01005939 /* we have nothing to initialize but the call is required */
5940 return 0;
5941}
5942
5943static inline int copy_u32_le(void __user *dest, void __iomem *src)
5944{
5945 u32 val = readl(src);
5946 return copy_to_user(dest, &val, 4);
5947}
5948
5949static int snd_hdspm_hwdep_ioctl(struct snd_hwdep *hw, struct file *file,
5950 unsigned int cmd, unsigned long __user arg)
5951{
5952 void __user *argp = (void __user *)arg;
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02005953 struct hdspm *hdspm = hw->private_data;
Takashi Iwai98274f02005-11-17 14:52:34 +01005954 struct hdspm_mixer_ioctl mixer;
Adrian Knoth0dca1792011-01-26 19:32:14 +01005955 struct hdspm_config info;
5956 struct hdspm_status status;
Takashi Iwai98274f02005-11-17 14:52:34 +01005957 struct hdspm_version hdspm_version;
Jaroslav Kysela730a5862011-01-27 13:03:15 +01005958 struct hdspm_peak_rms *levels;
Adrian Knoth0dca1792011-01-26 19:32:14 +01005959 struct hdspm_ltc ltc;
5960 unsigned int statusregister;
5961 long unsigned int s;
5962 int i = 0;
Takashi Iwai763f3562005-06-03 11:25:34 +02005963
5964 switch (cmd) {
5965
Takashi Iwai763f3562005-06-03 11:25:34 +02005966 case SNDRV_HDSPM_IOCTL_GET_PEAK_RMS:
Jaroslav Kysela730a5862011-01-27 13:03:15 +01005967 levels = &hdspm->peak_rms;
Adrian Knoth0dca1792011-01-26 19:32:14 +01005968 for (i = 0; i < HDSPM_MAX_CHANNELS; i++) {
Jaroslav Kysela730a5862011-01-27 13:03:15 +01005969 levels->input_peaks[i] =
Adrian Knoth0dca1792011-01-26 19:32:14 +01005970 readl(hdspm->iobase +
5971 HDSPM_MADI_INPUT_PEAK + i*4);
Jaroslav Kysela730a5862011-01-27 13:03:15 +01005972 levels->playback_peaks[i] =
Adrian Knoth0dca1792011-01-26 19:32:14 +01005973 readl(hdspm->iobase +
5974 HDSPM_MADI_PLAYBACK_PEAK + i*4);
Jaroslav Kysela730a5862011-01-27 13:03:15 +01005975 levels->output_peaks[i] =
Adrian Knoth0dca1792011-01-26 19:32:14 +01005976 readl(hdspm->iobase +
5977 HDSPM_MADI_OUTPUT_PEAK + i*4);
5978
Jaroslav Kysela730a5862011-01-27 13:03:15 +01005979 levels->input_rms[i] =
Adrian Knoth0dca1792011-01-26 19:32:14 +01005980 ((uint64_t) readl(hdspm->iobase +
5981 HDSPM_MADI_INPUT_RMS_H + i*4) << 32) |
5982 (uint64_t) readl(hdspm->iobase +
5983 HDSPM_MADI_INPUT_RMS_L + i*4);
Jaroslav Kysela730a5862011-01-27 13:03:15 +01005984 levels->playback_rms[i] =
Adrian Knoth0dca1792011-01-26 19:32:14 +01005985 ((uint64_t)readl(hdspm->iobase +
5986 HDSPM_MADI_PLAYBACK_RMS_H+i*4) << 32) |
5987 (uint64_t)readl(hdspm->iobase +
5988 HDSPM_MADI_PLAYBACK_RMS_L + i*4);
Jaroslav Kysela730a5862011-01-27 13:03:15 +01005989 levels->output_rms[i] =
Adrian Knoth0dca1792011-01-26 19:32:14 +01005990 ((uint64_t)readl(hdspm->iobase +
5991 HDSPM_MADI_OUTPUT_RMS_H + i*4) << 32) |
5992 (uint64_t)readl(hdspm->iobase +
5993 HDSPM_MADI_OUTPUT_RMS_L + i*4);
5994 }
5995
5996 if (hdspm->system_sample_rate > 96000) {
Jaroslav Kysela730a5862011-01-27 13:03:15 +01005997 levels->speed = qs;
Adrian Knoth0dca1792011-01-26 19:32:14 +01005998 } else if (hdspm->system_sample_rate > 48000) {
Jaroslav Kysela730a5862011-01-27 13:03:15 +01005999 levels->speed = ds;
Adrian Knoth0dca1792011-01-26 19:32:14 +01006000 } else {
Jaroslav Kysela730a5862011-01-27 13:03:15 +01006001 levels->speed = ss;
Adrian Knoth0dca1792011-01-26 19:32:14 +01006002 }
Jaroslav Kysela730a5862011-01-27 13:03:15 +01006003 levels->status2 = hdspm_read(hdspm, HDSPM_statusRegister2);
Adrian Knoth0dca1792011-01-26 19:32:14 +01006004
Jaroslav Kysela730a5862011-01-27 13:03:15 +01006005 s = copy_to_user(argp, levels, sizeof(struct hdspm_peak_rms));
Adrian Knoth0dca1792011-01-26 19:32:14 +01006006 if (0 != s) {
6007 /* snd_printk(KERN_ERR "copy_to_user(.., .., %lu): %lu
6008 [Levels]\n", sizeof(struct hdspm_peak_rms), s);
6009 */
Takashi Iwai763f3562005-06-03 11:25:34 +02006010 return -EFAULT;
Adrian Knoth0dca1792011-01-26 19:32:14 +01006011 }
6012 break;
6013
6014 case SNDRV_HDSPM_IOCTL_GET_LTC:
6015 ltc.ltc = hdspm_read(hdspm, HDSPM_RD_TCO);
6016 i = hdspm_read(hdspm, HDSPM_RD_TCO + 4);
6017 if (i & HDSPM_TCO1_LTC_Input_valid) {
6018 switch (i & (HDSPM_TCO1_LTC_Format_LSB |
6019 HDSPM_TCO1_LTC_Format_MSB)) {
6020 case 0:
6021 ltc.format = fps_24;
6022 break;
6023 case HDSPM_TCO1_LTC_Format_LSB:
6024 ltc.format = fps_25;
6025 break;
6026 case HDSPM_TCO1_LTC_Format_MSB:
6027 ltc.format = fps_2997;
6028 break;
6029 default:
6030 ltc.format = 30;
6031 break;
6032 }
6033 if (i & HDSPM_TCO1_set_drop_frame_flag) {
6034 ltc.frame = drop_frame;
6035 } else {
6036 ltc.frame = full_frame;
6037 }
6038 } else {
6039 ltc.format = format_invalid;
6040 ltc.frame = frame_invalid;
6041 }
6042 if (i & HDSPM_TCO1_Video_Input_Format_NTSC) {
6043 ltc.input_format = ntsc;
6044 } else if (i & HDSPM_TCO1_Video_Input_Format_PAL) {
6045 ltc.input_format = pal;
6046 } else {
6047 ltc.input_format = no_video;
6048 }
6049
6050 s = copy_to_user(argp, &ltc, sizeof(struct hdspm_ltc));
6051 if (0 != s) {
6052 /*
6053 snd_printk(KERN_ERR "copy_to_user(.., .., %lu): %lu [LTC]\n", sizeof(struct hdspm_ltc), s); */
Takashi Iwai763f3562005-06-03 11:25:34 +02006054 return -EFAULT;
Adrian Knoth0dca1792011-01-26 19:32:14 +01006055 }
Takashi Iwai763f3562005-06-03 11:25:34 +02006056
6057 break;
Takashi Iwai763f3562005-06-03 11:25:34 +02006058
Adrian Knoth0dca1792011-01-26 19:32:14 +01006059 case SNDRV_HDSPM_IOCTL_GET_CONFIG:
Takashi Iwai763f3562005-06-03 11:25:34 +02006060
6061 spin_lock_irq(&hdspm->lock);
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02006062 info.pref_sync_ref = hdspm_pref_sync_ref(hdspm);
6063 info.wordclock_sync_check = hdspm_wc_sync_check(hdspm);
Takashi Iwai763f3562005-06-03 11:25:34 +02006064
6065 info.system_sample_rate = hdspm->system_sample_rate;
6066 info.autosync_sample_rate =
Adrian Knoth0dca1792011-01-26 19:32:14 +01006067 hdspm_external_sample_rate(hdspm);
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02006068 info.system_clock_mode = hdspm_system_clock_mode(hdspm);
6069 info.clock_source = hdspm_clock_source(hdspm);
6070 info.autosync_ref = hdspm_autosync_ref(hdspm);
6071 info.line_out = hdspm_line_out(hdspm);
Takashi Iwai763f3562005-06-03 11:25:34 +02006072 info.passthru = 0;
6073 spin_unlock_irq(&hdspm->lock);
6074 if (copy_to_user((void __user *) arg, &info, sizeof(info)))
6075 return -EFAULT;
6076 break;
6077
Adrian Knoth0dca1792011-01-26 19:32:14 +01006078 case SNDRV_HDSPM_IOCTL_GET_STATUS:
6079 status.card_type = hdspm->io_type;
6080
6081 status.autosync_source = hdspm_autosync_ref(hdspm);
6082
6083 status.card_clock = 110069313433624ULL;
6084 status.master_period = hdspm_read(hdspm, HDSPM_RD_PLL_FREQ);
6085
6086 switch (hdspm->io_type) {
6087 case MADI:
6088 case MADIface:
6089 status.card_specific.madi.sync_wc =
6090 hdspm_wc_sync_check(hdspm);
6091 status.card_specific.madi.sync_madi =
6092 hdspm_madi_sync_check(hdspm);
6093 status.card_specific.madi.sync_tco =
6094 hdspm_tco_sync_check(hdspm);
6095 status.card_specific.madi.sync_in =
6096 hdspm_sync_in_sync_check(hdspm);
6097
6098 statusregister =
6099 hdspm_read(hdspm, HDSPM_statusRegister);
6100 status.card_specific.madi.madi_input =
6101 (statusregister & HDSPM_AB_int) ? 1 : 0;
6102 status.card_specific.madi.channel_format =
6103 (statusregister & HDSPM_TX_64ch) ? 1 : 0;
6104 /* TODO: Mac driver sets it when f_s>48kHz */
6105 status.card_specific.madi.frame_format = 0;
6106
6107 default:
6108 break;
6109 }
6110
6111 if (copy_to_user((void __user *) arg, &status, sizeof(status)))
6112 return -EFAULT;
6113
6114
6115 break;
6116
Takashi Iwai763f3562005-06-03 11:25:34 +02006117 case SNDRV_HDSPM_IOCTL_GET_VERSION:
Adrian Knoth0dca1792011-01-26 19:32:14 +01006118 hdspm_version.card_type = hdspm->io_type;
6119 strncpy(hdspm_version.cardname, hdspm->card_name,
6120 sizeof(hdspm_version.cardname));
6121 hdspm_version.serial = (hdspm_read(hdspm,
6122 HDSPM_midiStatusIn0)>>8) & 0xFFFFFF;
Takashi Iwai763f3562005-06-03 11:25:34 +02006123 hdspm_version.firmware_rev = hdspm->firmware_rev;
Adrian Knoth0dca1792011-01-26 19:32:14 +01006124 hdspm_version.addons = 0;
6125 if (hdspm->tco)
6126 hdspm_version.addons |= HDSPM_ADDON_TCO;
6127
Takashi Iwai763f3562005-06-03 11:25:34 +02006128 if (copy_to_user((void __user *) arg, &hdspm_version,
Adrian Knoth0dca1792011-01-26 19:32:14 +01006129 sizeof(hdspm_version)))
Takashi Iwai763f3562005-06-03 11:25:34 +02006130 return -EFAULT;
6131 break;
6132
6133 case SNDRV_HDSPM_IOCTL_GET_MIXER:
6134 if (copy_from_user(&mixer, (void __user *)arg, sizeof(mixer)))
6135 return -EFAULT;
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02006136 if (copy_to_user((void __user *)mixer.mixer, hdspm->mixer,
Adrian Knoth0dca1792011-01-26 19:32:14 +01006137 sizeof(struct hdspm_mixer)))
Takashi Iwai763f3562005-06-03 11:25:34 +02006138 return -EFAULT;
6139 break;
6140
6141 default:
6142 return -EINVAL;
6143 }
6144 return 0;
6145}
6146
Takashi Iwai98274f02005-11-17 14:52:34 +01006147static struct snd_pcm_ops snd_hdspm_playback_ops = {
Takashi Iwai763f3562005-06-03 11:25:34 +02006148 .open = snd_hdspm_playback_open,
6149 .close = snd_hdspm_playback_release,
6150 .ioctl = snd_hdspm_ioctl,
6151 .hw_params = snd_hdspm_hw_params,
6152 .hw_free = snd_hdspm_hw_free,
6153 .prepare = snd_hdspm_prepare,
6154 .trigger = snd_hdspm_trigger,
6155 .pointer = snd_hdspm_hw_pointer,
Takashi Iwai763f3562005-06-03 11:25:34 +02006156 .page = snd_pcm_sgbuf_ops_page,
6157};
6158
Takashi Iwai98274f02005-11-17 14:52:34 +01006159static struct snd_pcm_ops snd_hdspm_capture_ops = {
Takashi Iwai763f3562005-06-03 11:25:34 +02006160 .open = snd_hdspm_capture_open,
6161 .close = snd_hdspm_capture_release,
6162 .ioctl = snd_hdspm_ioctl,
6163 .hw_params = snd_hdspm_hw_params,
6164 .hw_free = snd_hdspm_hw_free,
6165 .prepare = snd_hdspm_prepare,
6166 .trigger = snd_hdspm_trigger,
6167 .pointer = snd_hdspm_hw_pointer,
Takashi Iwai763f3562005-06-03 11:25:34 +02006168 .page = snd_pcm_sgbuf_ops_page,
6169};
6170
Takashi Iwai98274f02005-11-17 14:52:34 +01006171static int __devinit snd_hdspm_create_hwdep(struct snd_card *card,
6172 struct hdspm * hdspm)
Takashi Iwai763f3562005-06-03 11:25:34 +02006173{
Takashi Iwai98274f02005-11-17 14:52:34 +01006174 struct snd_hwdep *hw;
Takashi Iwai763f3562005-06-03 11:25:34 +02006175 int err;
6176
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02006177 err = snd_hwdep_new(card, "HDSPM hwdep", 0, &hw);
6178 if (err < 0)
Takashi Iwai763f3562005-06-03 11:25:34 +02006179 return err;
6180
6181 hdspm->hwdep = hw;
6182 hw->private_data = hdspm;
6183 strcpy(hw->name, "HDSPM hwdep interface");
6184
Adrian Knoth0dca1792011-01-26 19:32:14 +01006185 hw->ops.open = snd_hdspm_hwdep_dummy_op;
Takashi Iwai763f3562005-06-03 11:25:34 +02006186 hw->ops.ioctl = snd_hdspm_hwdep_ioctl;
Adrian Knoth0dca1792011-01-26 19:32:14 +01006187 hw->ops.release = snd_hdspm_hwdep_dummy_op;
Takashi Iwai763f3562005-06-03 11:25:34 +02006188
6189 return 0;
6190}
6191
6192
6193/*------------------------------------------------------------
Adrian Knoth0dca1792011-01-26 19:32:14 +01006194 memory interface
Takashi Iwai763f3562005-06-03 11:25:34 +02006195 ------------------------------------------------------------*/
Adrian Knoth0dca1792011-01-26 19:32:14 +01006196static int __devinit snd_hdspm_preallocate_memory(struct hdspm *hdspm)
Takashi Iwai763f3562005-06-03 11:25:34 +02006197{
6198 int err;
Takashi Iwai98274f02005-11-17 14:52:34 +01006199 struct snd_pcm *pcm;
Takashi Iwai763f3562005-06-03 11:25:34 +02006200 size_t wanted;
6201
6202 pcm = hdspm->pcm;
6203
Remy Bruno3cee5a62006-10-16 12:46:32 +02006204 wanted = HDSPM_DMA_AREA_BYTES;
Takashi Iwai763f3562005-06-03 11:25:34 +02006205
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02006206 err =
Takashi Iwai763f3562005-06-03 11:25:34 +02006207 snd_pcm_lib_preallocate_pages_for_all(pcm,
Adrian Knoth0dca1792011-01-26 19:32:14 +01006208 SNDRV_DMA_TYPE_DEV_SG,
Takashi Iwai763f3562005-06-03 11:25:34 +02006209 snd_dma_pci_data(hdspm->pci),
6210 wanted,
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02006211 wanted);
6212 if (err < 0) {
Andrew Mortone2eba3e2006-01-20 14:07:13 +01006213 snd_printdd("Could not preallocate %zd Bytes\n", wanted);
Takashi Iwai763f3562005-06-03 11:25:34 +02006214
6215 return err;
6216 } else
Andrew Mortone2eba3e2006-01-20 14:07:13 +01006217 snd_printdd(" Preallocated %zd Bytes\n", wanted);
Takashi Iwai763f3562005-06-03 11:25:34 +02006218
6219 return 0;
6220}
6221
Adrian Knoth0dca1792011-01-26 19:32:14 +01006222
6223static void hdspm_set_sgbuf(struct hdspm *hdspm,
Takashi Iwai77a23f22008-08-21 13:00:13 +02006224 struct snd_pcm_substream *substream,
Takashi Iwai763f3562005-06-03 11:25:34 +02006225 unsigned int reg, int channels)
6226{
6227 int i;
Adrian Knoth0dca1792011-01-26 19:32:14 +01006228
6229 /* continuous memory segment */
Takashi Iwai763f3562005-06-03 11:25:34 +02006230 for (i = 0; i < (channels * 16); i++)
6231 hdspm_write(hdspm, reg + 4 * i,
Adrian Knoth0dca1792011-01-26 19:32:14 +01006232 snd_pcm_sgbuf_get_addr(substream, 4096 * i));
Takashi Iwai763f3562005-06-03 11:25:34 +02006233}
6234
Adrian Knoth0dca1792011-01-26 19:32:14 +01006235
Takashi Iwai763f3562005-06-03 11:25:34 +02006236/* ------------- ALSA Devices ---------------------------- */
Takashi Iwai98274f02005-11-17 14:52:34 +01006237static int __devinit snd_hdspm_create_pcm(struct snd_card *card,
Adrian Knoth0dca1792011-01-26 19:32:14 +01006238 struct hdspm *hdspm)
Takashi Iwai763f3562005-06-03 11:25:34 +02006239{
Takashi Iwai98274f02005-11-17 14:52:34 +01006240 struct snd_pcm *pcm;
Takashi Iwai763f3562005-06-03 11:25:34 +02006241 int err;
6242
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02006243 err = snd_pcm_new(card, hdspm->card_name, 0, 1, 1, &pcm);
6244 if (err < 0)
Takashi Iwai763f3562005-06-03 11:25:34 +02006245 return err;
6246
6247 hdspm->pcm = pcm;
6248 pcm->private_data = hdspm;
6249 strcpy(pcm->name, hdspm->card_name);
6250
6251 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK,
6252 &snd_hdspm_playback_ops);
6253 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE,
6254 &snd_hdspm_capture_ops);
6255
6256 pcm->info_flags = SNDRV_PCM_INFO_JOINT_DUPLEX;
6257
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02006258 err = snd_hdspm_preallocate_memory(hdspm);
6259 if (err < 0)
Takashi Iwai763f3562005-06-03 11:25:34 +02006260 return err;
6261
6262 return 0;
6263}
6264
Takashi Iwai98274f02005-11-17 14:52:34 +01006265static inline void snd_hdspm_initialize_midi_flush(struct hdspm * hdspm)
Takashi Iwai763f3562005-06-03 11:25:34 +02006266{
6267 snd_hdspm_flush_midi_input(hdspm, 0);
6268 snd_hdspm_flush_midi_input(hdspm, 1);
6269}
6270
Takashi Iwai98274f02005-11-17 14:52:34 +01006271static int __devinit snd_hdspm_create_alsa_devices(struct snd_card *card,
6272 struct hdspm * hdspm)
Takashi Iwai763f3562005-06-03 11:25:34 +02006273{
Adrian Knoth0dca1792011-01-26 19:32:14 +01006274 int err, i;
Takashi Iwai763f3562005-06-03 11:25:34 +02006275
6276 snd_printdd("Create card...\n");
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02006277 err = snd_hdspm_create_pcm(card, hdspm);
6278 if (err < 0)
Takashi Iwai763f3562005-06-03 11:25:34 +02006279 return err;
6280
Adrian Knoth0dca1792011-01-26 19:32:14 +01006281 i = 0;
6282 while (i < hdspm->midiPorts) {
6283 err = snd_hdspm_create_midi(card, hdspm, i);
6284 if (err < 0) {
6285 return err;
6286 }
6287 i++;
6288 }
Takashi Iwai763f3562005-06-03 11:25:34 +02006289
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02006290 err = snd_hdspm_create_controls(card, hdspm);
6291 if (err < 0)
Takashi Iwai763f3562005-06-03 11:25:34 +02006292 return err;
6293
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02006294 err = snd_hdspm_create_hwdep(card, hdspm);
6295 if (err < 0)
Takashi Iwai763f3562005-06-03 11:25:34 +02006296 return err;
6297
6298 snd_printdd("proc init...\n");
6299 snd_hdspm_proc_init(hdspm);
6300
6301 hdspm->system_sample_rate = -1;
6302 hdspm->last_external_sample_rate = -1;
6303 hdspm->last_internal_sample_rate = -1;
6304 hdspm->playback_pid = -1;
6305 hdspm->capture_pid = -1;
6306 hdspm->capture_substream = NULL;
6307 hdspm->playback_substream = NULL;
6308
6309 snd_printdd("Set defaults...\n");
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02006310 err = snd_hdspm_set_defaults(hdspm);
6311 if (err < 0)
Takashi Iwai763f3562005-06-03 11:25:34 +02006312 return err;
6313
6314 snd_printdd("Update mixer controls...\n");
6315 hdspm_update_simple_mixer_controls(hdspm);
6316
6317 snd_printdd("Initializeing complete ???\n");
6318
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02006319 err = snd_card_register(card);
6320 if (err < 0) {
Takashi Iwai763f3562005-06-03 11:25:34 +02006321 snd_printk(KERN_ERR "HDSPM: error registering card\n");
6322 return err;
6323 }
6324
6325 snd_printdd("... yes now\n");
6326
6327 return 0;
6328}
6329
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02006330static int __devinit snd_hdspm_create(struct snd_card *card,
Adrian Knoth0dca1792011-01-26 19:32:14 +01006331 struct hdspm *hdspm) {
6332
Takashi Iwai763f3562005-06-03 11:25:34 +02006333 struct pci_dev *pci = hdspm->pci;
6334 int err;
Takashi Iwai763f3562005-06-03 11:25:34 +02006335 unsigned long io_extent;
6336
6337 hdspm->irq = -1;
Takashi Iwai763f3562005-06-03 11:25:34 +02006338 hdspm->card = card;
6339
6340 spin_lock_init(&hdspm->lock);
6341
Takashi Iwai763f3562005-06-03 11:25:34 +02006342 pci_read_config_word(hdspm->pci,
Adrian Knoth0dca1792011-01-26 19:32:14 +01006343 PCI_CLASS_REVISION, &hdspm->firmware_rev);
Remy Bruno3cee5a62006-10-16 12:46:32 +02006344
Takashi Iwai763f3562005-06-03 11:25:34 +02006345 strcpy(card->mixername, "Xilinx FPGA");
Adrian Knoth0dca1792011-01-26 19:32:14 +01006346 strcpy(card->driver, "HDSPM");
6347
6348 switch (hdspm->firmware_rev) {
6349 case HDSPM_MADI_REV:
6350 hdspm->io_type = MADI;
6351 hdspm->card_name = "RME MADI";
6352 hdspm->midiPorts = 3;
6353 break;
6354 case HDSPM_RAYDAT_REV:
6355 hdspm->io_type = RayDAT;
6356 hdspm->card_name = "RME RayDAT";
6357 hdspm->midiPorts = 2;
6358 break;
6359 case HDSPM_AIO_REV:
6360 hdspm->io_type = AIO;
6361 hdspm->card_name = "RME AIO";
6362 hdspm->midiPorts = 1;
6363 break;
6364 case HDSPM_MADIFACE_REV:
6365 hdspm->io_type = MADIface;
6366 hdspm->card_name = "RME MADIface";
6367 hdspm->midiPorts = 1;
6368 break;
6369 case HDSPM_AES_REV:
6370 hdspm->io_type = AES32;
6371 hdspm->card_name = "RME AES32";
6372 hdspm->midiPorts = 2;
6373 break;
Remy Bruno3cee5a62006-10-16 12:46:32 +02006374 }
Takashi Iwai763f3562005-06-03 11:25:34 +02006375
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02006376 err = pci_enable_device(pci);
6377 if (err < 0)
Takashi Iwai763f3562005-06-03 11:25:34 +02006378 return err;
6379
6380 pci_set_master(hdspm->pci);
6381
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02006382 err = pci_request_regions(pci, "hdspm");
6383 if (err < 0)
Takashi Iwai763f3562005-06-03 11:25:34 +02006384 return err;
6385
6386 hdspm->port = pci_resource_start(pci, 0);
6387 io_extent = pci_resource_len(pci, 0);
6388
6389 snd_printdd("grabbed memory region 0x%lx-0x%lx\n",
Adrian Knoth0dca1792011-01-26 19:32:14 +01006390 hdspm->port, hdspm->port + io_extent - 1);
Takashi Iwai763f3562005-06-03 11:25:34 +02006391
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02006392 hdspm->iobase = ioremap_nocache(hdspm->port, io_extent);
6393 if (!hdspm->iobase) {
6394 snd_printk(KERN_ERR "HDSPM: "
Adrian Knoth0dca1792011-01-26 19:32:14 +01006395 "unable to remap region 0x%lx-0x%lx\n",
6396 hdspm->port, hdspm->port + io_extent - 1);
Takashi Iwai763f3562005-06-03 11:25:34 +02006397 return -EBUSY;
6398 }
6399 snd_printdd("remapped region (0x%lx) 0x%lx-0x%lx\n",
Adrian Knoth0dca1792011-01-26 19:32:14 +01006400 (unsigned long)hdspm->iobase, hdspm->port,
6401 hdspm->port + io_extent - 1);
Takashi Iwai763f3562005-06-03 11:25:34 +02006402
6403 if (request_irq(pci->irq, snd_hdspm_interrupt,
Adrian Knoth0dca1792011-01-26 19:32:14 +01006404 IRQF_SHARED, "hdspm", hdspm)) {
Takashi Iwai763f3562005-06-03 11:25:34 +02006405 snd_printk(KERN_ERR "HDSPM: unable to use IRQ %d\n", pci->irq);
6406 return -EBUSY;
6407 }
6408
6409 snd_printdd("use IRQ %d\n", pci->irq);
6410
6411 hdspm->irq = pci->irq;
Takashi Iwai763f3562005-06-03 11:25:34 +02006412
Andrew Mortone2eba3e2006-01-20 14:07:13 +01006413 snd_printdd("kmalloc Mixer memory of %zd Bytes\n",
Adrian Knoth0dca1792011-01-26 19:32:14 +01006414 sizeof(struct hdspm_mixer));
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02006415 hdspm->mixer = kzalloc(sizeof(struct hdspm_mixer), GFP_KERNEL);
6416 if (!hdspm->mixer) {
6417 snd_printk(KERN_ERR "HDSPM: "
Adrian Knoth0dca1792011-01-26 19:32:14 +01006418 "unable to kmalloc Mixer memory of %d Bytes\n",
6419 (int)sizeof(struct hdspm_mixer));
Takashi Iwai763f3562005-06-03 11:25:34 +02006420 return err;
6421 }
6422
Adrian Knoth0dca1792011-01-26 19:32:14 +01006423 hdspm->port_names_in = NULL;
6424 hdspm->port_names_out = NULL;
6425
6426 switch (hdspm->io_type) {
6427 case AES32:
Adrian Knoth432d2502011-02-23 11:43:08 +01006428 hdspm->ss_in_channels = hdspm->ss_out_channels = 16;
6429 hdspm->ds_in_channels = hdspm->ds_out_channels = 16;
6430 hdspm->qs_in_channels = hdspm->qs_out_channels = 16;
6431
6432 hdspm->channel_map_in_ss = hdspm->channel_map_out_ss =
6433 channel_map_aes32;
6434 hdspm->channel_map_in_ds = hdspm->channel_map_out_ds =
6435 channel_map_aes32;
6436 hdspm->channel_map_in_qs = hdspm->channel_map_out_qs =
6437 channel_map_aes32;
6438 hdspm->port_names_in_ss = hdspm->port_names_out_ss =
6439 texts_ports_aes32;
6440 hdspm->port_names_in_ds = hdspm->port_names_out_ds =
6441 texts_ports_aes32;
6442 hdspm->port_names_in_qs = hdspm->port_names_out_qs =
6443 texts_ports_aes32;
6444
6445 hdspm->max_channels_out = hdspm->max_channels_in = 16;
6446 hdspm->port_names_in = hdspm->port_names_out =
6447 texts_ports_aes32;
6448 hdspm->channel_map_in = hdspm->channel_map_out =
6449 channel_map_aes32;
6450
Adrian Knoth0dca1792011-01-26 19:32:14 +01006451 break;
6452
6453 case MADI:
6454 case MADIface:
6455 hdspm->ss_in_channels = hdspm->ss_out_channels =
6456 MADI_SS_CHANNELS;
6457 hdspm->ds_in_channels = hdspm->ds_out_channels =
6458 MADI_DS_CHANNELS;
6459 hdspm->qs_in_channels = hdspm->qs_out_channels =
6460 MADI_QS_CHANNELS;
6461
6462 hdspm->channel_map_in_ss = hdspm->channel_map_out_ss =
6463 channel_map_unity_ss;
Adrian Knoth01e96072011-02-23 11:43:11 +01006464 hdspm->channel_map_in_ds = hdspm->channel_map_out_ds =
Adrian Knoth0dca1792011-01-26 19:32:14 +01006465 channel_map_unity_ss;
Adrian Knoth01e96072011-02-23 11:43:11 +01006466 hdspm->channel_map_in_qs = hdspm->channel_map_out_qs =
Adrian Knoth0dca1792011-01-26 19:32:14 +01006467 channel_map_unity_ss;
6468
6469 hdspm->port_names_in_ss = hdspm->port_names_out_ss =
6470 texts_ports_madi;
6471 hdspm->port_names_in_ds = hdspm->port_names_out_ds =
6472 texts_ports_madi;
6473 hdspm->port_names_in_qs = hdspm->port_names_out_qs =
6474 texts_ports_madi;
6475 break;
6476
6477 case AIO:
6478 if (0 == (hdspm_read(hdspm, HDSPM_statusRegister2) & HDSPM_s2_AEBI_D)) {
6479 snd_printk(KERN_INFO "HDSPM: AEB input board found, but not supported\n");
6480 }
6481
6482 hdspm->ss_in_channels = AIO_IN_SS_CHANNELS;
6483 hdspm->ds_in_channels = AIO_IN_DS_CHANNELS;
6484 hdspm->qs_in_channels = AIO_IN_QS_CHANNELS;
6485 hdspm->ss_out_channels = AIO_OUT_SS_CHANNELS;
6486 hdspm->ds_out_channels = AIO_OUT_DS_CHANNELS;
6487 hdspm->qs_out_channels = AIO_OUT_QS_CHANNELS;
6488
6489 hdspm->channel_map_out_ss = channel_map_aio_out_ss;
6490 hdspm->channel_map_out_ds = channel_map_aio_out_ds;
6491 hdspm->channel_map_out_qs = channel_map_aio_out_qs;
6492
6493 hdspm->channel_map_in_ss = channel_map_aio_in_ss;
6494 hdspm->channel_map_in_ds = channel_map_aio_in_ds;
6495 hdspm->channel_map_in_qs = channel_map_aio_in_qs;
6496
6497 hdspm->port_names_in_ss = texts_ports_aio_in_ss;
6498 hdspm->port_names_out_ss = texts_ports_aio_out_ss;
6499 hdspm->port_names_in_ds = texts_ports_aio_in_ds;
6500 hdspm->port_names_out_ds = texts_ports_aio_out_ds;
6501 hdspm->port_names_in_qs = texts_ports_aio_in_qs;
6502 hdspm->port_names_out_qs = texts_ports_aio_out_qs;
6503
6504 break;
6505
6506 case RayDAT:
6507 hdspm->ss_in_channels = hdspm->ss_out_channels =
6508 RAYDAT_SS_CHANNELS;
6509 hdspm->ds_in_channels = hdspm->ds_out_channels =
6510 RAYDAT_DS_CHANNELS;
6511 hdspm->qs_in_channels = hdspm->qs_out_channels =
6512 RAYDAT_QS_CHANNELS;
6513
6514 hdspm->max_channels_in = RAYDAT_SS_CHANNELS;
6515 hdspm->max_channels_out = RAYDAT_SS_CHANNELS;
6516
6517 hdspm->channel_map_in_ss = hdspm->channel_map_out_ss =
6518 channel_map_raydat_ss;
6519 hdspm->channel_map_in_ds = hdspm->channel_map_out_ds =
6520 channel_map_raydat_ds;
6521 hdspm->channel_map_in_qs = hdspm->channel_map_out_qs =
6522 channel_map_raydat_qs;
6523 hdspm->channel_map_in = hdspm->channel_map_out =
6524 channel_map_raydat_ss;
6525
6526 hdspm->port_names_in_ss = hdspm->port_names_out_ss =
6527 texts_ports_raydat_ss;
6528 hdspm->port_names_in_ds = hdspm->port_names_out_ds =
6529 texts_ports_raydat_ds;
6530 hdspm->port_names_in_qs = hdspm->port_names_out_qs =
6531 texts_ports_raydat_qs;
6532
6533
6534 break;
6535
6536 }
6537
6538 /* TCO detection */
6539 switch (hdspm->io_type) {
6540 case AIO:
6541 case RayDAT:
6542 if (hdspm_read(hdspm, HDSPM_statusRegister2) &
6543 HDSPM_s2_tco_detect) {
6544 hdspm->midiPorts++;
6545 hdspm->tco = kzalloc(sizeof(struct hdspm_tco),
6546 GFP_KERNEL);
6547 if (NULL != hdspm->tco) {
6548 hdspm_tco_write(hdspm);
6549 }
6550 snd_printk(KERN_INFO "HDSPM: AIO/RayDAT TCO module found\n");
6551 } else {
6552 hdspm->tco = NULL;
6553 }
6554 break;
6555
6556 case MADI:
6557 if (hdspm_read(hdspm, HDSPM_statusRegister) & HDSPM_tco_detect) {
6558 hdspm->midiPorts++;
6559 hdspm->tco = kzalloc(sizeof(struct hdspm_tco),
6560 GFP_KERNEL);
6561 if (NULL != hdspm->tco) {
6562 hdspm_tco_write(hdspm);
6563 }
6564 snd_printk(KERN_INFO "HDSPM: MADI TCO module found\n");
6565 } else {
6566 hdspm->tco = NULL;
6567 }
6568 break;
6569
6570 default:
6571 hdspm->tco = NULL;
6572 }
6573
6574 /* texts */
6575 switch (hdspm->io_type) {
6576 case AES32:
6577 if (hdspm->tco) {
6578 hdspm->texts_autosync = texts_autosync_aes_tco;
6579 hdspm->texts_autosync_items = 10;
6580 } else {
6581 hdspm->texts_autosync = texts_autosync_aes;
6582 hdspm->texts_autosync_items = 9;
6583 }
6584 break;
6585
6586 case MADI:
6587 if (hdspm->tco) {
6588 hdspm->texts_autosync = texts_autosync_madi_tco;
6589 hdspm->texts_autosync_items = 4;
6590 } else {
6591 hdspm->texts_autosync = texts_autosync_madi;
6592 hdspm->texts_autosync_items = 3;
6593 }
6594 break;
6595
6596 case MADIface:
6597
6598 break;
6599
6600 case RayDAT:
6601 if (hdspm->tco) {
6602 hdspm->texts_autosync = texts_autosync_raydat_tco;
6603 hdspm->texts_autosync_items = 9;
6604 } else {
6605 hdspm->texts_autosync = texts_autosync_raydat;
6606 hdspm->texts_autosync_items = 8;
6607 }
6608 break;
6609
6610 case AIO:
6611 if (hdspm->tco) {
6612 hdspm->texts_autosync = texts_autosync_aio_tco;
6613 hdspm->texts_autosync_items = 6;
6614 } else {
6615 hdspm->texts_autosync = texts_autosync_aio;
6616 hdspm->texts_autosync_items = 5;
6617 }
6618 break;
6619
6620 }
6621
6622 tasklet_init(&hdspm->midi_tasklet,
6623 hdspm_midi_tasklet, (unsigned long) hdspm);
Takashi Iwai763f3562005-06-03 11:25:34 +02006624
6625 snd_printdd("create alsa devices.\n");
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02006626 err = snd_hdspm_create_alsa_devices(card, hdspm);
6627 if (err < 0)
Takashi Iwai763f3562005-06-03 11:25:34 +02006628 return err;
6629
6630 snd_hdspm_initialize_midi_flush(hdspm);
6631
6632 return 0;
6633}
6634
Adrian Knoth0dca1792011-01-26 19:32:14 +01006635
Takashi Iwai98274f02005-11-17 14:52:34 +01006636static int snd_hdspm_free(struct hdspm * hdspm)
Takashi Iwai763f3562005-06-03 11:25:34 +02006637{
6638
6639 if (hdspm->port) {
6640
6641 /* stop th audio, and cancel all interrupts */
6642 hdspm->control_register &=
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02006643 ~(HDSPM_Start | HDSPM_AudioInterruptEnable |
Adrian Knoth0dca1792011-01-26 19:32:14 +01006644 HDSPM_Midi0InterruptEnable | HDSPM_Midi1InterruptEnable |
6645 HDSPM_Midi2InterruptEnable | HDSPM_Midi3InterruptEnable);
Takashi Iwai763f3562005-06-03 11:25:34 +02006646 hdspm_write(hdspm, HDSPM_controlRegister,
6647 hdspm->control_register);
6648 }
6649
6650 if (hdspm->irq >= 0)
6651 free_irq(hdspm->irq, (void *) hdspm);
6652
Jesper Juhlfc584222005-10-24 15:11:28 +02006653 kfree(hdspm->mixer);
Takashi Iwai763f3562005-06-03 11:25:34 +02006654
6655 if (hdspm->iobase)
6656 iounmap(hdspm->iobase);
6657
Takashi Iwai763f3562005-06-03 11:25:34 +02006658 if (hdspm->port)
6659 pci_release_regions(hdspm->pci);
6660
6661 pci_disable_device(hdspm->pci);
6662 return 0;
6663}
6664
Adrian Knoth0dca1792011-01-26 19:32:14 +01006665
Takashi Iwai98274f02005-11-17 14:52:34 +01006666static void snd_hdspm_card_free(struct snd_card *card)
Takashi Iwai763f3562005-06-03 11:25:34 +02006667{
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02006668 struct hdspm *hdspm = card->private_data;
Takashi Iwai763f3562005-06-03 11:25:34 +02006669
6670 if (hdspm)
6671 snd_hdspm_free(hdspm);
6672}
6673
Adrian Knoth0dca1792011-01-26 19:32:14 +01006674
Takashi Iwai763f3562005-06-03 11:25:34 +02006675static int __devinit snd_hdspm_probe(struct pci_dev *pci,
6676 const struct pci_device_id *pci_id)
6677{
6678 static int dev;
Takashi Iwai98274f02005-11-17 14:52:34 +01006679 struct hdspm *hdspm;
6680 struct snd_card *card;
Takashi Iwai763f3562005-06-03 11:25:34 +02006681 int err;
6682
6683 if (dev >= SNDRV_CARDS)
6684 return -ENODEV;
6685 if (!enable[dev]) {
6686 dev++;
6687 return -ENOENT;
6688 }
6689
Takashi Iwaie58de7b2008-12-28 16:44:30 +01006690 err = snd_card_create(index[dev], id[dev],
Adrian Knoth0dca1792011-01-26 19:32:14 +01006691 THIS_MODULE, sizeof(struct hdspm), &card);
Takashi Iwaie58de7b2008-12-28 16:44:30 +01006692 if (err < 0)
6693 return err;
Takashi Iwai763f3562005-06-03 11:25:34 +02006694
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02006695 hdspm = card->private_data;
Takashi Iwai763f3562005-06-03 11:25:34 +02006696 card->private_free = snd_hdspm_card_free;
6697 hdspm->dev = dev;
6698 hdspm->pci = pci;
6699
Takashi Iwaic187c042007-02-19 15:27:33 +01006700 snd_card_set_dev(card, &pci->dev);
6701
Adrian Knoth0dca1792011-01-26 19:32:14 +01006702 err = snd_hdspm_create(card, hdspm);
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02006703 if (err < 0) {
Takashi Iwai763f3562005-06-03 11:25:34 +02006704 snd_card_free(card);
6705 return err;
6706 }
6707
Adrian Knoth0dca1792011-01-26 19:32:14 +01006708 if (hdspm->io_type != MADIface) {
6709 sprintf(card->shortname, "%s_%x",
6710 hdspm->card_name,
6711 (hdspm_read(hdspm, HDSPM_midiStatusIn0)>>8) & 0xFFFFFF);
6712 sprintf(card->longname, "%s S/N 0x%x at 0x%lx, irq %d",
6713 hdspm->card_name,
6714 (hdspm_read(hdspm, HDSPM_midiStatusIn0)>>8) & 0xFFFFFF,
6715 hdspm->port, hdspm->irq);
6716 } else {
6717 sprintf(card->shortname, "%s", hdspm->card_name);
6718 sprintf(card->longname, "%s at 0x%lx, irq %d",
6719 hdspm->card_name, hdspm->port, hdspm->irq);
6720 }
Takashi Iwai763f3562005-06-03 11:25:34 +02006721
Takashi Iwaief5fa1a2007-07-27 16:52:46 +02006722 err = snd_card_register(card);
6723 if (err < 0) {
Takashi Iwai763f3562005-06-03 11:25:34 +02006724 snd_card_free(card);
6725 return err;
6726 }
6727
6728 pci_set_drvdata(pci, card);
6729
6730 dev++;
6731 return 0;
6732}
6733
6734static void __devexit snd_hdspm_remove(struct pci_dev *pci)
6735{
6736 snd_card_free(pci_get_drvdata(pci));
6737 pci_set_drvdata(pci, NULL);
6738}
6739
6740static struct pci_driver driver = {
6741 .name = "RME Hammerfall DSP MADI",
Takashi Iwai763f3562005-06-03 11:25:34 +02006742 .id_table = snd_hdspm_ids,
6743 .probe = snd_hdspm_probe,
6744 .remove = __devexit_p(snd_hdspm_remove),
6745};
6746
6747
6748static int __init alsa_card_hdspm_init(void)
6749{
6750 return pci_register_driver(&driver);
6751}
6752
6753static void __exit alsa_card_hdspm_exit(void)
6754{
6755 pci_unregister_driver(&driver);
6756}
6757
6758module_init(alsa_card_hdspm_init)
6759module_exit(alsa_card_hdspm_exit)