Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 1 | /* |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2 | * ALSA driver for RME Hammerfall DSP MADI audio interface(s) |
| 3 | * |
| 4 | * Copyright (c) 2003 Winfried Ritsch (IEM) |
| 5 | * code based on hdsp.c Paul Davis |
| 6 | * Marcus Andersson |
| 7 | * Thomas Charbonnel |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 8 | * Modified 2006-06-01 for AES32 support by Remy Bruno |
| 9 | * <remy.bruno@trinnov.com> |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 10 | * |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 11 | * Modified 2009-04-13 for proper metering by Florian Faber |
| 12 | * <faber@faberman.de> |
| 13 | * |
| 14 | * Modified 2009-04-14 for native float support by Florian Faber |
| 15 | * <faber@faberman.de> |
| 16 | * |
| 17 | * Modified 2009-04-26 fixed bug in rms metering by Florian Faber |
| 18 | * <faber@faberman.de> |
| 19 | * |
| 20 | * Modified 2009-04-30 added hw serial number support by Florian Faber |
| 21 | * |
| 22 | * Modified 2011-01-14 added S/PDIF input on RayDATs by Adrian Knoth |
| 23 | * |
| 24 | * Modified 2011-01-25 variable period sizes on RayDAT/AIO by Adrian Knoth |
| 25 | * |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 26 | * This program is free software; you can redistribute it and/or modify |
| 27 | * it under the terms of the GNU General Public License as published by |
| 28 | * the Free Software Foundation; either version 2 of the License, or |
| 29 | * (at your option) any later version. |
| 30 | * |
| 31 | * This program is distributed in the hope that it will be useful, |
| 32 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 33 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 34 | * GNU General Public License for more details. |
| 35 | * |
| 36 | * You should have received a copy of the GNU General Public License |
| 37 | * along with this program; if not, write to the Free Software |
| 38 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 39 | * |
| 40 | */ |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 41 | #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 Iwai | 3f7440a | 2009-06-05 17:40:04 +0200 | [diff] [blame] | 47 | #include <linux/math64.h> |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 48 | #include <asm/io.h> |
| 49 | |
| 50 | #include <sound/core.h> |
| 51 | #include <sound/control.h> |
| 52 | #include <sound/pcm.h> |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 53 | #include <sound/pcm_params.h> |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 54 | #include <sound/info.h> |
| 55 | #include <sound/asoundef.h> |
| 56 | #include <sound/rawmidi.h> |
| 57 | #include <sound/hwdep.h> |
| 58 | #include <sound/initval.h> |
| 59 | |
| 60 | #include <sound/hdspm.h> |
| 61 | |
| 62 | static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */ |
| 63 | static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */ |
| 64 | static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;/* Enable this card */ |
| 65 | |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 66 | module_param_array(index, int, NULL, 0444); |
| 67 | MODULE_PARM_DESC(index, "Index value for RME HDSPM interface."); |
| 68 | |
| 69 | module_param_array(id, charp, NULL, 0444); |
| 70 | MODULE_PARM_DESC(id, "ID string for RME HDSPM interface."); |
| 71 | |
| 72 | module_param_array(enable, bool, NULL, 0444); |
| 73 | MODULE_PARM_DESC(enable, "Enable/disable specific HDSPM soundcards."); |
| 74 | |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 75 | |
| 76 | MODULE_AUTHOR |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 77 | ( |
| 78 | "Winfried Ritsch <ritsch_AT_iem.at>, " |
| 79 | "Paul Davis <paul@linuxaudiosystems.com>, " |
| 80 | "Marcus Andersson, Thomas Charbonnel <thomas@undata.org>, " |
| 81 | "Remy Bruno <remy.bruno@trinnov.com>, " |
| 82 | "Florian Faber <faberman@linuxproaudio.org>, " |
| 83 | "Adrian Knoth <adi@drcomp.erfurt.thur.de>" |
| 84 | ); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 85 | MODULE_DESCRIPTION("RME HDSPM"); |
| 86 | MODULE_LICENSE("GPL"); |
| 87 | MODULE_SUPPORTED_DEVICE("{{RME HDSPM-MADI}}"); |
| 88 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 89 | /* --- Write registers. --- |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 90 | These are defined as byte-offsets from the iobase value. */ |
| 91 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 92 | #define HDSPM_WR_SETTINGS 0 |
| 93 | #define HDSPM_outputBufferAddress 32 |
| 94 | #define HDSPM_inputBufferAddress 36 |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 95 | #define HDSPM_controlRegister 64 |
| 96 | #define HDSPM_interruptConfirmation 96 |
| 97 | #define HDSPM_control2Reg 256 /* not in specs ???????? */ |
Remy Bruno | ffb2c3c | 2007-03-07 19:08:46 +0100 | [diff] [blame] | 98 | #define HDSPM_freqReg 256 /* for AES32 */ |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 99 | #define HDSPM_midiDataOut0 352 /* just believe in old code */ |
| 100 | #define HDSPM_midiDataOut1 356 |
Remy Bruno | ffb2c3c | 2007-03-07 19:08:46 +0100 | [diff] [blame] | 101 | #define HDSPM_eeprom_wr 384 /* for AES32 */ |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 102 | |
| 103 | /* DMA enable for 64 channels, only Bit 0 is relevant */ |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 104 | #define HDSPM_outputEnableBase 512 /* 512-767 input DMA */ |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 105 | #define HDSPM_inputEnableBase 768 /* 768-1023 output DMA */ |
| 106 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 107 | /* 16 page addresses for each of the 64 channels DMA buffer in and out |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 108 | (each 64k=16*4k) Buffer must be 4k aligned (which is default i386 ????) */ |
| 109 | #define HDSPM_pageAddressBufferOut 8192 |
| 110 | #define HDSPM_pageAddressBufferIn (HDSPM_pageAddressBufferOut+64*16*4) |
| 111 | |
| 112 | #define HDSPM_MADI_mixerBase 32768 /* 32768-65535 for 2x64x64 Fader */ |
| 113 | |
| 114 | #define HDSPM_MATRIX_MIXER_SIZE 8192 /* = 2*64*64 * 4 Byte => 32kB */ |
| 115 | |
| 116 | /* --- Read registers. --- |
| 117 | These are defined as byte-offsets from the iobase value */ |
| 118 | #define HDSPM_statusRegister 0 |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 119 | /*#define HDSPM_statusRegister2 96 */ |
| 120 | /* after RME Windows driver sources, status2 is 4-byte word # 48 = word at |
| 121 | * offset 192, for AES32 *and* MADI |
| 122 | * => need to check that offset 192 is working on MADI */ |
| 123 | #define HDSPM_statusRegister2 192 |
| 124 | #define HDSPM_timecodeRegister 128 |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 125 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 126 | /* AIO, RayDAT */ |
| 127 | #define HDSPM_RD_STATUS_0 0 |
| 128 | #define HDSPM_RD_STATUS_1 64 |
| 129 | #define HDSPM_RD_STATUS_2 128 |
| 130 | #define HDSPM_RD_STATUS_3 192 |
| 131 | |
| 132 | #define HDSPM_RD_TCO 256 |
| 133 | #define HDSPM_RD_PLL_FREQ 512 |
| 134 | #define HDSPM_WR_TCO 128 |
| 135 | |
| 136 | #define HDSPM_TCO1_TCO_lock 0x00000001 |
| 137 | #define HDSPM_TCO1_WCK_Input_Range_LSB 0x00000002 |
| 138 | #define HDSPM_TCO1_WCK_Input_Range_MSB 0x00000004 |
| 139 | #define HDSPM_TCO1_LTC_Input_valid 0x00000008 |
| 140 | #define HDSPM_TCO1_WCK_Input_valid 0x00000010 |
| 141 | #define HDSPM_TCO1_Video_Input_Format_NTSC 0x00000020 |
| 142 | #define HDSPM_TCO1_Video_Input_Format_PAL 0x00000040 |
| 143 | |
| 144 | #define HDSPM_TCO1_set_TC 0x00000100 |
| 145 | #define HDSPM_TCO1_set_drop_frame_flag 0x00000200 |
| 146 | #define HDSPM_TCO1_LTC_Format_LSB 0x00000400 |
| 147 | #define HDSPM_TCO1_LTC_Format_MSB 0x00000800 |
| 148 | |
| 149 | #define HDSPM_TCO2_TC_run 0x00010000 |
| 150 | #define HDSPM_TCO2_WCK_IO_ratio_LSB 0x00020000 |
| 151 | #define HDSPM_TCO2_WCK_IO_ratio_MSB 0x00040000 |
| 152 | #define HDSPM_TCO2_set_num_drop_frames_LSB 0x00080000 |
| 153 | #define HDSPM_TCO2_set_num_drop_frames_MSB 0x00100000 |
| 154 | #define HDSPM_TCO2_set_jam_sync 0x00200000 |
| 155 | #define HDSPM_TCO2_set_flywheel 0x00400000 |
| 156 | |
| 157 | #define HDSPM_TCO2_set_01_4 0x01000000 |
| 158 | #define HDSPM_TCO2_set_pull_down 0x02000000 |
| 159 | #define HDSPM_TCO2_set_pull_up 0x04000000 |
| 160 | #define HDSPM_TCO2_set_freq 0x08000000 |
| 161 | #define HDSPM_TCO2_set_term_75R 0x10000000 |
| 162 | #define HDSPM_TCO2_set_input_LSB 0x20000000 |
| 163 | #define HDSPM_TCO2_set_input_MSB 0x40000000 |
| 164 | #define HDSPM_TCO2_set_freq_from_app 0x80000000 |
| 165 | |
| 166 | |
| 167 | #define HDSPM_midiDataOut0 352 |
| 168 | #define HDSPM_midiDataOut1 356 |
| 169 | #define HDSPM_midiDataOut2 368 |
| 170 | |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 171 | #define HDSPM_midiDataIn0 360 |
| 172 | #define HDSPM_midiDataIn1 364 |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 173 | #define HDSPM_midiDataIn2 372 |
| 174 | #define HDSPM_midiDataIn3 376 |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 175 | |
| 176 | /* status is data bytes in MIDI-FIFO (0-128) */ |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 177 | #define HDSPM_midiStatusOut0 384 |
| 178 | #define HDSPM_midiStatusOut1 388 |
| 179 | #define HDSPM_midiStatusOut2 400 |
| 180 | |
| 181 | #define HDSPM_midiStatusIn0 392 |
| 182 | #define HDSPM_midiStatusIn1 396 |
| 183 | #define HDSPM_midiStatusIn2 404 |
| 184 | #define HDSPM_midiStatusIn3 408 |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 185 | |
| 186 | |
| 187 | /* the meters are regular i/o-mapped registers, but offset |
| 188 | considerably from the rest. the peak registers are reset |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 189 | when read; the least-significant 4 bits are full-scale counters; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 190 | the actual peak value is in the most-significant 24 bits. |
| 191 | */ |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 192 | |
| 193 | #define HDSPM_MADI_INPUT_PEAK 4096 |
| 194 | #define HDSPM_MADI_PLAYBACK_PEAK 4352 |
| 195 | #define HDSPM_MADI_OUTPUT_PEAK 4608 |
| 196 | |
| 197 | #define HDSPM_MADI_INPUT_RMS_L 6144 |
| 198 | #define HDSPM_MADI_PLAYBACK_RMS_L 6400 |
| 199 | #define HDSPM_MADI_OUTPUT_RMS_L 6656 |
| 200 | |
| 201 | #define HDSPM_MADI_INPUT_RMS_H 7168 |
| 202 | #define HDSPM_MADI_PLAYBACK_RMS_H 7424 |
| 203 | #define HDSPM_MADI_OUTPUT_RMS_H 7680 |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 204 | |
| 205 | /* --- Control Register bits --------- */ |
| 206 | #define HDSPM_Start (1<<0) /* start engine */ |
| 207 | |
| 208 | #define HDSPM_Latency0 (1<<1) /* buffer size = 2^n */ |
| 209 | #define HDSPM_Latency1 (1<<2) /* where n is defined */ |
| 210 | #define HDSPM_Latency2 (1<<3) /* by Latency{2,1,0} */ |
| 211 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 212 | #define HDSPM_ClockModeMaster (1<<4) /* 1=Master, 0=Autosync */ |
| 213 | #define HDSPM_c0Master 0x1 /* Master clock bit in settings |
| 214 | register [RayDAT, AIO] */ |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 215 | |
| 216 | #define HDSPM_AudioInterruptEnable (1<<5) /* what do you think ? */ |
| 217 | |
| 218 | #define HDSPM_Frequency0 (1<<6) /* 0=44.1kHz/88.2kHz 1=48kHz/96kHz */ |
| 219 | #define HDSPM_Frequency1 (1<<7) /* 0=32kHz/64kHz */ |
| 220 | #define HDSPM_DoubleSpeed (1<<8) /* 0=normal speed, 1=double speed */ |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 221 | #define HDSPM_QuadSpeed (1<<31) /* quad speed bit */ |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 222 | |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 223 | #define HDSPM_Professional (1<<9) /* Professional */ /* AES32 ONLY */ |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 224 | #define HDSPM_TX_64ch (1<<10) /* Output 64channel MODE=1, |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 225 | 56channelMODE=0 */ /* MADI ONLY*/ |
| 226 | #define HDSPM_Emphasis (1<<10) /* Emphasis */ /* AES32 ONLY */ |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 227 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 228 | #define HDSPM_AutoInp (1<<11) /* Auto Input (takeover) == Safe Mode, |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 229 | 0=off, 1=on */ /* MADI ONLY */ |
| 230 | #define HDSPM_Dolby (1<<11) /* Dolby = "NonAudio" ?? */ /* AES32 ONLY */ |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 231 | |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 232 | #define HDSPM_InputSelect0 (1<<14) /* Input select 0= optical, 1=coax |
| 233 | * -- MADI ONLY |
| 234 | */ |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 235 | #define HDSPM_InputSelect1 (1<<15) /* should be 0 */ |
| 236 | |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 237 | #define HDSPM_SyncRef2 (1<<13) |
| 238 | #define HDSPM_SyncRef3 (1<<25) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 239 | |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 240 | #define HDSPM_SMUX (1<<18) /* Frame ??? */ /* MADI ONY */ |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 241 | #define HDSPM_clr_tms (1<<19) /* clear track marker, do not use |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 242 | AES additional bits in |
| 243 | lower 5 Audiodatabits ??? */ |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 244 | #define HDSPM_taxi_reset (1<<20) /* ??? */ /* MADI ONLY ? */ |
| 245 | #define HDSPM_WCK48 (1<<20) /* Frame ??? = HDSPM_SMUX */ /* AES32 ONLY */ |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 246 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 247 | #define HDSPM_Midi0InterruptEnable 0x0400000 |
| 248 | #define HDSPM_Midi1InterruptEnable 0x0800000 |
| 249 | #define HDSPM_Midi2InterruptEnable 0x0200000 |
| 250 | #define HDSPM_Midi3InterruptEnable 0x4000000 |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 251 | |
| 252 | #define HDSPM_LineOut (1<<24) /* Analog Out on channel 63/64 on=1, mute=0 */ |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 253 | #define HDSPe_FLOAT_FORMAT 0x2000000 |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 254 | |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 255 | #define HDSPM_DS_DoubleWire (1<<26) /* AES32 ONLY */ |
| 256 | #define HDSPM_QS_DoubleWire (1<<27) /* AES32 ONLY */ |
| 257 | #define HDSPM_QS_QuadWire (1<<28) /* AES32 ONLY */ |
| 258 | |
| 259 | #define HDSPM_wclk_sel (1<<30) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 260 | |
| 261 | /* --- bit helper defines */ |
| 262 | #define HDSPM_LatencyMask (HDSPM_Latency0|HDSPM_Latency1|HDSPM_Latency2) |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 263 | #define HDSPM_FrequencyMask (HDSPM_Frequency0|HDSPM_Frequency1|\ |
| 264 | HDSPM_DoubleSpeed|HDSPM_QuadSpeed) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 265 | #define HDSPM_InputMask (HDSPM_InputSelect0|HDSPM_InputSelect1) |
| 266 | #define HDSPM_InputOptical 0 |
| 267 | #define HDSPM_InputCoaxial (HDSPM_InputSelect0) |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 268 | #define HDSPM_SyncRefMask (HDSPM_SyncRef0|HDSPM_SyncRef1|\ |
| 269 | HDSPM_SyncRef2|HDSPM_SyncRef3) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 270 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 271 | #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 Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 282 | |
| 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 Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 288 | #define HDSPM_Frequency96KHz (HDSPM_DoubleSpeed|HDSPM_Frequency1|\ |
| 289 | HDSPM_Frequency0) |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 290 | #define HDSPM_Frequency128KHz (HDSPM_QuadSpeed|HDSPM_Frequency0) |
| 291 | #define HDSPM_Frequency176_4KHz (HDSPM_QuadSpeed|HDSPM_Frequency1) |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 292 | #define HDSPM_Frequency192KHz (HDSPM_QuadSpeed|HDSPM_Frequency1|\ |
| 293 | HDSPM_Frequency0) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 294 | |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 295 | |
| 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 Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 304 | #define HDSPM_AUTOSYNC_FROM_TCO 2 |
| 305 | #define HDSPM_AUTOSYNC_FROM_SYNC_IN 3 |
| 306 | #define HDSPM_AUTOSYNC_FROM_NONE 4 |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 307 | |
| 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 Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 313 | #define hdspm_decode_latency(x) ((((x) & HDSPM_LatencyMask)>>1)) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 314 | |
| 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 Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 331 | /* --- Status Register bits --- */ /* MADI ONLY */ /* Bits defined here and |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 332 | that do not conflict with specific bits for AES32 seem to be valid also |
| 333 | for the AES32 |
| 334 | */ |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 335 | #define HDSPM_audioIRQPending (1<<0) /* IRQ is high and pending */ |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 336 | #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 Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 340 | |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 341 | #define HDSPM_madiLock (1<<3) /* MADI Locked =1, no=0 */ |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 342 | #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 Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 349 | |
| 350 | #define HDSPM_BufferPositionMask 0x000FFC0 /* Bit 6..15 : h/w buffer pointer */ |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 351 | /* since 64byte accurate, last 6 bits are not used */ |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 352 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 353 | |
| 354 | |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 355 | #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 Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 362 | #define HDSPM_BufferID (1<<26) /* (Double)Buffer ID toggles with |
| 363 | * Interrupt |
| 364 | */ |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 365 | #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 Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 378 | |
| 379 | /* --- status bit helpers */ |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 380 | #define HDSPM_madiFreqMask (HDSPM_madiFreq0|HDSPM_madiFreq1|\ |
| 381 | HDSPM_madiFreq2|HDSPM_madiFreq3) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 382 | #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 Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 392 | /* Status2 Register bits */ /* MADI ONLY */ |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 393 | |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 394 | #define HDSPM_version0 (1<<0) /* not really defined but I guess */ |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 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 Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 406 | #define HDSPM_SyncRef0 0x10000 /* Sync Reference */ |
| 407 | #define HDSPM_SyncRef1 0x20000 |
| 408 | |
| 409 | #define HDSPM_SelSyncRef0 (1<<8) /* AutoSync Source */ |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 410 | #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 Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 423 | #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 Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 429 | |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 430 | #define HDSPM_SelSyncRefMask (HDSPM_SelSyncRef0|HDSPM_SelSyncRef1|\ |
| 431 | HDSPM_SelSyncRef2) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 432 | #define HDSPM_SelSyncRef_WORD 0 |
| 433 | #define HDSPM_SelSyncRef_MADI (HDSPM_SelSyncRef0) |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 434 | #define HDSPM_SelSyncRef_TCO (HDSPM_SelSyncRef1) |
| 435 | #define HDSPM_SelSyncRef_SyncIn (HDSPM_SelSyncRef0|HDSPM_SelSyncRef1) |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 436 | #define HDSPM_SelSyncRef_NVALID (HDSPM_SelSyncRef0|HDSPM_SelSyncRef1|\ |
| 437 | HDSPM_SelSyncRef2) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 438 | |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 439 | /* |
| 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 Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 445 | /* (status >> HDSPM_AES32_wcFreq_bit) & 0xF gives WC frequency (cf function |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 446 | 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 Bruno | 6534599 | 2007-08-31 12:21:08 +0200 | [diff] [blame] | 459 | #define HDSPM_AES32_AUTOSYNC_FROM_NONE 9 |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 460 | |
| 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 Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 489 | /* Mixer Values */ |
| 490 | #define UNITY_GAIN 32768 /* = 65536/2 */ |
| 491 | #define MINUS_INFINITY_GAIN 0 |
| 492 | |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 493 | /* 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 Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 498 | #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 | |
Adrian Knoth | d2d10a2 | 2011-02-28 15:14:47 +0100 | [diff] [blame] | 509 | #define AES32_CHANNELS 16 |
| 510 | |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 511 | /* the size of a substream (1 mono data stream) */ |
| 512 | #define HDSPM_CHANNEL_BUFFER_SAMPLES (16*1024) |
| 513 | #define HDSPM_CHANNEL_BUFFER_BYTES (4*HDSPM_CHANNEL_BUFFER_SAMPLES) |
| 514 | |
| 515 | /* the size of the area we need to allocate for DMA transfers. the |
| 516 | size is the same regardless of the number of channels, and |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 517 | also the latency to use. |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 518 | for one direction !!! |
| 519 | */ |
Remy Bruno | ffb2c3c | 2007-03-07 19:08:46 +0100 | [diff] [blame] | 520 | #define HDSPM_DMA_AREA_BYTES (HDSPM_MAX_CHANNELS * HDSPM_CHANNEL_BUFFER_BYTES) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 521 | #define HDSPM_DMA_AREA_KILOBYTES (HDSPM_DMA_AREA_BYTES/1024) |
| 522 | |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 523 | /* revisions >= 230 indicate AES32 card */ |
Adrian Knoth | 5f8b4d5 | 2011-07-29 03:11:04 +0200 | [diff] [blame] | 524 | #define HDSPM_MADI_ANCIENT_REV 204 |
Adrian Knoth | efef054 | 2011-06-12 17:26:19 +0200 | [diff] [blame] | 525 | #define HDSPM_MADI_OLD_REV 207 |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 526 | #define HDSPM_MADI_REV 210 |
| 527 | #define HDSPM_RAYDAT_REV 211 |
| 528 | #define HDSPM_AIO_REV 212 |
| 529 | #define HDSPM_MADIFACE_REV 213 |
| 530 | #define HDSPM_AES_REV 240 |
Adrian Knoth | 526ea86 | 2011-02-28 15:14:48 +0100 | [diff] [blame] | 531 | #define HDSPM_AES32_REV 234 |
Adrian Knoth | bdd3255 | 2011-03-07 19:10:11 +0100 | [diff] [blame] | 532 | #define HDSPM_AES32_OLD_REV 233 |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 533 | |
Remy Bruno | 6534599 | 2007-08-31 12:21:08 +0200 | [diff] [blame] | 534 | /* speed factor modes */ |
| 535 | #define HDSPM_SPEED_SINGLE 0 |
| 536 | #define HDSPM_SPEED_DOUBLE 1 |
| 537 | #define HDSPM_SPEED_QUAD 2 |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 538 | |
Remy Bruno | 6534599 | 2007-08-31 12:21:08 +0200 | [diff] [blame] | 539 | /* names for speed modes */ |
| 540 | static char *hdspm_speed_names[] = { "single", "double", "quad" }; |
| 541 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 542 | static char *texts_autosync_aes_tco[] = { "Word Clock", |
| 543 | "AES1", "AES2", "AES3", "AES4", |
| 544 | "AES5", "AES6", "AES7", "AES8", |
| 545 | "TCO" }; |
| 546 | static char *texts_autosync_aes[] = { "Word Clock", |
| 547 | "AES1", "AES2", "AES3", "AES4", |
| 548 | "AES5", "AES6", "AES7", "AES8" }; |
| 549 | static char *texts_autosync_madi_tco[] = { "Word Clock", |
| 550 | "MADI", "TCO", "Sync In" }; |
| 551 | static char *texts_autosync_madi[] = { "Word Clock", |
| 552 | "MADI", "Sync In" }; |
| 553 | |
| 554 | static char *texts_autosync_raydat_tco[] = { |
| 555 | "Word Clock", |
| 556 | "ADAT 1", "ADAT 2", "ADAT 3", "ADAT 4", |
| 557 | "AES", "SPDIF", "TCO", "Sync In" |
| 558 | }; |
| 559 | static char *texts_autosync_raydat[] = { |
| 560 | "Word Clock", |
| 561 | "ADAT 1", "ADAT 2", "ADAT 3", "ADAT 4", |
| 562 | "AES", "SPDIF", "Sync In" |
| 563 | }; |
| 564 | static char *texts_autosync_aio_tco[] = { |
| 565 | "Word Clock", |
| 566 | "ADAT", "AES", "SPDIF", "TCO", "Sync In" |
| 567 | }; |
| 568 | static char *texts_autosync_aio[] = { "Word Clock", |
| 569 | "ADAT", "AES", "SPDIF", "Sync In" }; |
| 570 | |
| 571 | static char *texts_freq[] = { |
| 572 | "No Lock", |
| 573 | "32 kHz", |
| 574 | "44.1 kHz", |
| 575 | "48 kHz", |
| 576 | "64 kHz", |
| 577 | "88.2 kHz", |
| 578 | "96 kHz", |
| 579 | "128 kHz", |
| 580 | "176.4 kHz", |
| 581 | "192 kHz" |
| 582 | }; |
| 583 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 584 | static char *texts_ports_madi[] = { |
| 585 | "MADI.1", "MADI.2", "MADI.3", "MADI.4", "MADI.5", "MADI.6", |
| 586 | "MADI.7", "MADI.8", "MADI.9", "MADI.10", "MADI.11", "MADI.12", |
| 587 | "MADI.13", "MADI.14", "MADI.15", "MADI.16", "MADI.17", "MADI.18", |
| 588 | "MADI.19", "MADI.20", "MADI.21", "MADI.22", "MADI.23", "MADI.24", |
| 589 | "MADI.25", "MADI.26", "MADI.27", "MADI.28", "MADI.29", "MADI.30", |
| 590 | "MADI.31", "MADI.32", "MADI.33", "MADI.34", "MADI.35", "MADI.36", |
| 591 | "MADI.37", "MADI.38", "MADI.39", "MADI.40", "MADI.41", "MADI.42", |
| 592 | "MADI.43", "MADI.44", "MADI.45", "MADI.46", "MADI.47", "MADI.48", |
| 593 | "MADI.49", "MADI.50", "MADI.51", "MADI.52", "MADI.53", "MADI.54", |
| 594 | "MADI.55", "MADI.56", "MADI.57", "MADI.58", "MADI.59", "MADI.60", |
| 595 | "MADI.61", "MADI.62", "MADI.63", "MADI.64", |
| 596 | }; |
| 597 | |
| 598 | |
| 599 | static char *texts_ports_raydat_ss[] = { |
| 600 | "ADAT1.1", "ADAT1.2", "ADAT1.3", "ADAT1.4", "ADAT1.5", "ADAT1.6", |
| 601 | "ADAT1.7", "ADAT1.8", "ADAT2.1", "ADAT2.2", "ADAT2.3", "ADAT2.4", |
| 602 | "ADAT2.5", "ADAT2.6", "ADAT2.7", "ADAT2.8", "ADAT3.1", "ADAT3.2", |
| 603 | "ADAT3.3", "ADAT3.4", "ADAT3.5", "ADAT3.6", "ADAT3.7", "ADAT3.8", |
| 604 | "ADAT4.1", "ADAT4.2", "ADAT4.3", "ADAT4.4", "ADAT4.5", "ADAT4.6", |
| 605 | "ADAT4.7", "ADAT4.8", |
| 606 | "AES.L", "AES.R", |
| 607 | "SPDIF.L", "SPDIF.R" |
| 608 | }; |
| 609 | |
| 610 | static char *texts_ports_raydat_ds[] = { |
| 611 | "ADAT1.1", "ADAT1.2", "ADAT1.3", "ADAT1.4", |
| 612 | "ADAT2.1", "ADAT2.2", "ADAT2.3", "ADAT2.4", |
| 613 | "ADAT3.1", "ADAT3.2", "ADAT3.3", "ADAT3.4", |
| 614 | "ADAT4.1", "ADAT4.2", "ADAT4.3", "ADAT4.4", |
| 615 | "AES.L", "AES.R", |
| 616 | "SPDIF.L", "SPDIF.R" |
| 617 | }; |
| 618 | |
| 619 | static char *texts_ports_raydat_qs[] = { |
| 620 | "ADAT1.1", "ADAT1.2", |
| 621 | "ADAT2.1", "ADAT2.2", |
| 622 | "ADAT3.1", "ADAT3.2", |
| 623 | "ADAT4.1", "ADAT4.2", |
| 624 | "AES.L", "AES.R", |
| 625 | "SPDIF.L", "SPDIF.R" |
| 626 | }; |
| 627 | |
| 628 | |
| 629 | static char *texts_ports_aio_in_ss[] = { |
| 630 | "Analogue.L", "Analogue.R", |
| 631 | "AES.L", "AES.R", |
| 632 | "SPDIF.L", "SPDIF.R", |
| 633 | "ADAT.1", "ADAT.2", "ADAT.3", "ADAT.4", "ADAT.5", "ADAT.6", |
| 634 | "ADAT.7", "ADAT.8" |
| 635 | }; |
| 636 | |
| 637 | static char *texts_ports_aio_out_ss[] = { |
| 638 | "Analogue.L", "Analogue.R", |
| 639 | "AES.L", "AES.R", |
| 640 | "SPDIF.L", "SPDIF.R", |
| 641 | "ADAT.1", "ADAT.2", "ADAT.3", "ADAT.4", "ADAT.5", "ADAT.6", |
| 642 | "ADAT.7", "ADAT.8", |
| 643 | "Phone.L", "Phone.R" |
| 644 | }; |
| 645 | |
| 646 | static char *texts_ports_aio_in_ds[] = { |
| 647 | "Analogue.L", "Analogue.R", |
| 648 | "AES.L", "AES.R", |
| 649 | "SPDIF.L", "SPDIF.R", |
| 650 | "ADAT.1", "ADAT.2", "ADAT.3", "ADAT.4" |
| 651 | }; |
| 652 | |
| 653 | static char *texts_ports_aio_out_ds[] = { |
| 654 | "Analogue.L", "Analogue.R", |
| 655 | "AES.L", "AES.R", |
| 656 | "SPDIF.L", "SPDIF.R", |
| 657 | "ADAT.1", "ADAT.2", "ADAT.3", "ADAT.4", |
| 658 | "Phone.L", "Phone.R" |
| 659 | }; |
| 660 | |
| 661 | static char *texts_ports_aio_in_qs[] = { |
| 662 | "Analogue.L", "Analogue.R", |
| 663 | "AES.L", "AES.R", |
| 664 | "SPDIF.L", "SPDIF.R", |
| 665 | "ADAT.1", "ADAT.2", "ADAT.3", "ADAT.4" |
| 666 | }; |
| 667 | |
| 668 | static char *texts_ports_aio_out_qs[] = { |
| 669 | "Analogue.L", "Analogue.R", |
| 670 | "AES.L", "AES.R", |
| 671 | "SPDIF.L", "SPDIF.R", |
| 672 | "ADAT.1", "ADAT.2", "ADAT.3", "ADAT.4", |
| 673 | "Phone.L", "Phone.R" |
| 674 | }; |
| 675 | |
Adrian Knoth | 432d250 | 2011-02-23 11:43:08 +0100 | [diff] [blame] | 676 | static char *texts_ports_aes32[] = { |
| 677 | "AES.1", "AES.2", "AES.3", "AES.4", "AES.5", "AES.6", "AES.7", |
| 678 | "AES.8", "AES.9.", "AES.10", "AES.11", "AES.12", "AES.13", "AES.14", |
| 679 | "AES.15", "AES.16" |
| 680 | }; |
| 681 | |
Adrian Knoth | 55a5760 | 2011-01-27 11:23:15 +0100 | [diff] [blame] | 682 | /* These tables map the ALSA channels 1..N to the channels that we |
| 683 | need to use in order to find the relevant channel buffer. RME |
| 684 | refers to this kind of mapping as between "the ADAT channel and |
| 685 | the DMA channel." We index it using the logical audio channel, |
| 686 | and the value is the DMA channel (i.e. channel buffer number) |
| 687 | where the data for that channel can be read/written from/to. |
| 688 | */ |
| 689 | |
| 690 | static char channel_map_unity_ss[HDSPM_MAX_CHANNELS] = { |
| 691 | 0, 1, 2, 3, 4, 5, 6, 7, |
| 692 | 8, 9, 10, 11, 12, 13, 14, 15, |
| 693 | 16, 17, 18, 19, 20, 21, 22, 23, |
| 694 | 24, 25, 26, 27, 28, 29, 30, 31, |
| 695 | 32, 33, 34, 35, 36, 37, 38, 39, |
| 696 | 40, 41, 42, 43, 44, 45, 46, 47, |
| 697 | 48, 49, 50, 51, 52, 53, 54, 55, |
| 698 | 56, 57, 58, 59, 60, 61, 62, 63 |
| 699 | }; |
| 700 | |
Adrian Knoth | 55a5760 | 2011-01-27 11:23:15 +0100 | [diff] [blame] | 701 | static char channel_map_raydat_ss[HDSPM_MAX_CHANNELS] = { |
| 702 | 4, 5, 6, 7, 8, 9, 10, 11, /* ADAT 1 */ |
| 703 | 12, 13, 14, 15, 16, 17, 18, 19, /* ADAT 2 */ |
| 704 | 20, 21, 22, 23, 24, 25, 26, 27, /* ADAT 3 */ |
| 705 | 28, 29, 30, 31, 32, 33, 34, 35, /* ADAT 4 */ |
| 706 | 0, 1, /* AES */ |
| 707 | 2, 3, /* SPDIF */ |
| 708 | -1, -1, -1, -1, |
| 709 | -1, -1, -1, -1, -1, -1, -1, -1, |
| 710 | -1, -1, -1, -1, -1, -1, -1, -1, |
| 711 | -1, -1, -1, -1, -1, -1, -1, -1, |
| 712 | }; |
| 713 | |
| 714 | static char channel_map_raydat_ds[HDSPM_MAX_CHANNELS] = { |
| 715 | 4, 5, 6, 7, /* ADAT 1 */ |
| 716 | 8, 9, 10, 11, /* ADAT 2 */ |
| 717 | 12, 13, 14, 15, /* ADAT 3 */ |
| 718 | 16, 17, 18, 19, /* ADAT 4 */ |
| 719 | 0, 1, /* AES */ |
| 720 | 2, 3, /* SPDIF */ |
| 721 | -1, -1, -1, -1, |
| 722 | -1, -1, -1, -1, -1, -1, -1, -1, |
| 723 | -1, -1, -1, -1, -1, -1, -1, -1, |
| 724 | -1, -1, -1, -1, -1, -1, -1, -1, |
| 725 | -1, -1, -1, -1, -1, -1, -1, -1, |
| 726 | -1, -1, -1, -1, -1, -1, -1, -1, |
| 727 | }; |
| 728 | |
| 729 | static char channel_map_raydat_qs[HDSPM_MAX_CHANNELS] = { |
| 730 | 4, 5, /* ADAT 1 */ |
| 731 | 6, 7, /* ADAT 2 */ |
| 732 | 8, 9, /* ADAT 3 */ |
| 733 | 10, 11, /* ADAT 4 */ |
| 734 | 0, 1, /* AES */ |
| 735 | 2, 3, /* SPDIF */ |
| 736 | -1, -1, -1, -1, |
| 737 | -1, -1, -1, -1, -1, -1, -1, -1, |
| 738 | -1, -1, -1, -1, -1, -1, -1, -1, |
| 739 | -1, -1, -1, -1, -1, -1, -1, -1, |
| 740 | -1, -1, -1, -1, -1, -1, -1, -1, |
| 741 | -1, -1, -1, -1, -1, -1, -1, -1, |
| 742 | -1, -1, -1, -1, -1, -1, -1, -1, |
| 743 | }; |
| 744 | |
| 745 | static char channel_map_aio_in_ss[HDSPM_MAX_CHANNELS] = { |
| 746 | 0, 1, /* line in */ |
| 747 | 8, 9, /* aes in, */ |
| 748 | 10, 11, /* spdif in */ |
| 749 | 12, 13, 14, 15, 16, 17, 18, 19, /* ADAT in */ |
| 750 | -1, -1, |
| 751 | -1, -1, -1, -1, -1, -1, -1, -1, |
| 752 | -1, -1, -1, -1, -1, -1, -1, -1, |
| 753 | -1, -1, -1, -1, -1, -1, -1, -1, |
| 754 | -1, -1, -1, -1, -1, -1, -1, -1, |
| 755 | -1, -1, -1, -1, -1, -1, -1, -1, |
| 756 | -1, -1, -1, -1, -1, -1, -1, -1, |
| 757 | }; |
| 758 | |
| 759 | static char channel_map_aio_out_ss[HDSPM_MAX_CHANNELS] = { |
| 760 | 0, 1, /* line out */ |
| 761 | 8, 9, /* aes out */ |
| 762 | 10, 11, /* spdif out */ |
| 763 | 12, 13, 14, 15, 16, 17, 18, 19, /* ADAT out */ |
| 764 | 6, 7, /* phone out */ |
| 765 | -1, -1, -1, -1, -1, -1, -1, -1, |
| 766 | -1, -1, -1, -1, -1, -1, -1, -1, |
| 767 | -1, -1, -1, -1, -1, -1, -1, -1, |
| 768 | -1, -1, -1, -1, -1, -1, -1, -1, |
| 769 | -1, -1, -1, -1, -1, -1, -1, -1, |
| 770 | -1, -1, -1, -1, -1, -1, -1, -1, |
| 771 | }; |
| 772 | |
| 773 | static char channel_map_aio_in_ds[HDSPM_MAX_CHANNELS] = { |
| 774 | 0, 1, /* line in */ |
| 775 | 8, 9, /* aes in */ |
| 776 | 10, 11, /* spdif in */ |
| 777 | 12, 14, 16, 18, /* adat in */ |
| 778 | -1, -1, -1, -1, -1, -1, |
| 779 | -1, -1, -1, -1, -1, -1, -1, -1, |
| 780 | -1, -1, -1, -1, -1, -1, -1, -1, |
| 781 | -1, -1, -1, -1, -1, -1, -1, -1, |
| 782 | -1, -1, -1, -1, -1, -1, -1, -1, |
| 783 | -1, -1, -1, -1, -1, -1, -1, -1, |
| 784 | -1, -1, -1, -1, -1, -1, -1, -1 |
| 785 | }; |
| 786 | |
| 787 | static char channel_map_aio_out_ds[HDSPM_MAX_CHANNELS] = { |
| 788 | 0, 1, /* line out */ |
| 789 | 8, 9, /* aes out */ |
| 790 | 10, 11, /* spdif out */ |
| 791 | 12, 14, 16, 18, /* adat out */ |
| 792 | 6, 7, /* phone out */ |
| 793 | -1, -1, -1, -1, |
| 794 | -1, -1, -1, -1, -1, -1, -1, -1, |
| 795 | -1, -1, -1, -1, -1, -1, -1, -1, |
| 796 | -1, -1, -1, -1, -1, -1, -1, -1, |
| 797 | -1, -1, -1, -1, -1, -1, -1, -1, |
| 798 | -1, -1, -1, -1, -1, -1, -1, -1, |
| 799 | -1, -1, -1, -1, -1, -1, -1, -1 |
| 800 | }; |
| 801 | |
| 802 | static char channel_map_aio_in_qs[HDSPM_MAX_CHANNELS] = { |
| 803 | 0, 1, /* line in */ |
| 804 | 8, 9, /* aes in */ |
| 805 | 10, 11, /* spdif in */ |
| 806 | 12, 16, /* adat in */ |
| 807 | -1, -1, -1, -1, -1, -1, -1, -1, |
| 808 | -1, -1, -1, -1, -1, -1, -1, -1, |
| 809 | -1, -1, -1, -1, -1, -1, -1, -1, |
| 810 | -1, -1, -1, -1, -1, -1, -1, -1, |
| 811 | -1, -1, -1, -1, -1, -1, -1, -1, |
| 812 | -1, -1, -1, -1, -1, -1, -1, -1, |
| 813 | -1, -1, -1, -1, -1, -1, -1, -1 |
| 814 | }; |
| 815 | |
| 816 | static char channel_map_aio_out_qs[HDSPM_MAX_CHANNELS] = { |
| 817 | 0, 1, /* line out */ |
| 818 | 8, 9, /* aes out */ |
| 819 | 10, 11, /* spdif out */ |
| 820 | 12, 16, /* adat out */ |
| 821 | 6, 7, /* phone out */ |
| 822 | -1, -1, -1, -1, -1, -1, |
| 823 | -1, -1, -1, -1, -1, -1, -1, -1, |
| 824 | -1, -1, -1, -1, -1, -1, -1, -1, |
| 825 | -1, -1, -1, -1, -1, -1, -1, -1, |
| 826 | -1, -1, -1, -1, -1, -1, -1, -1, |
| 827 | -1, -1, -1, -1, -1, -1, -1, -1, |
| 828 | -1, -1, -1, -1, -1, -1, -1, -1 |
| 829 | }; |
| 830 | |
Adrian Knoth | 432d250 | 2011-02-23 11:43:08 +0100 | [diff] [blame] | 831 | static char channel_map_aes32[HDSPM_MAX_CHANNELS] = { |
| 832 | 0, 1, 2, 3, 4, 5, 6, 7, |
| 833 | 8, 9, 10, 11, 12, 13, 14, 15, |
| 834 | -1, -1, -1, -1, -1, -1, -1, -1, |
| 835 | -1, -1, -1, -1, -1, -1, -1, -1, |
| 836 | -1, -1, -1, -1, -1, -1, -1, -1, |
| 837 | -1, -1, -1, -1, -1, -1, -1, -1, |
| 838 | -1, -1, -1, -1, -1, -1, -1, -1, |
| 839 | -1, -1, -1, -1, -1, -1, -1, -1 |
| 840 | }; |
| 841 | |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 842 | struct hdspm_midi { |
| 843 | struct hdspm *hdspm; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 844 | int id; |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 845 | struct snd_rawmidi *rmidi; |
| 846 | struct snd_rawmidi_substream *input; |
| 847 | struct snd_rawmidi_substream *output; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 848 | char istimer; /* timer in use */ |
| 849 | struct timer_list timer; |
| 850 | spinlock_t lock; |
| 851 | int pending; |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 852 | int dataIn; |
| 853 | int statusIn; |
| 854 | int dataOut; |
| 855 | int statusOut; |
| 856 | int ie; |
| 857 | int irq; |
| 858 | }; |
| 859 | |
| 860 | struct hdspm_tco { |
| 861 | int input; |
| 862 | int framerate; |
| 863 | int wordclock; |
| 864 | int samplerate; |
| 865 | int pull; |
| 866 | int term; /* 0 = off, 1 = on */ |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 867 | }; |
| 868 | |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 869 | struct hdspm { |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 870 | spinlock_t lock; |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 871 | /* only one playback and/or capture stream */ |
| 872 | struct snd_pcm_substream *capture_substream; |
| 873 | struct snd_pcm_substream *playback_substream; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 874 | |
| 875 | char *card_name; /* for procinfo */ |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 876 | unsigned short firmware_rev; /* dont know if relevant (yes if AES32)*/ |
| 877 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 878 | uint8_t io_type; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 879 | |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 880 | int monitor_outs; /* set up monitoring outs init flag */ |
| 881 | |
| 882 | u32 control_register; /* cached value */ |
| 883 | u32 control2_register; /* cached value */ |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 884 | u32 settings_register; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 885 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 886 | struct hdspm_midi midi[4]; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 887 | struct tasklet_struct midi_tasklet; |
| 888 | |
| 889 | size_t period_bytes; |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 890 | unsigned char ss_in_channels; |
| 891 | unsigned char ds_in_channels; |
| 892 | unsigned char qs_in_channels; |
| 893 | unsigned char ss_out_channels; |
| 894 | unsigned char ds_out_channels; |
| 895 | unsigned char qs_out_channels; |
| 896 | |
| 897 | unsigned char max_channels_in; |
| 898 | unsigned char max_channels_out; |
| 899 | |
Takashi Iwai | 286bed0 | 2011-06-30 12:45:36 +0200 | [diff] [blame] | 900 | signed char *channel_map_in; |
| 901 | signed char *channel_map_out; |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 902 | |
Takashi Iwai | 286bed0 | 2011-06-30 12:45:36 +0200 | [diff] [blame] | 903 | signed char *channel_map_in_ss, *channel_map_in_ds, *channel_map_in_qs; |
| 904 | signed char *channel_map_out_ss, *channel_map_out_ds, *channel_map_out_qs; |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 905 | |
| 906 | char **port_names_in; |
| 907 | char **port_names_out; |
| 908 | |
| 909 | char **port_names_in_ss, **port_names_in_ds, **port_names_in_qs; |
| 910 | char **port_names_out_ss, **port_names_out_ds, **port_names_out_qs; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 911 | |
| 912 | unsigned char *playback_buffer; /* suitably aligned address */ |
| 913 | unsigned char *capture_buffer; /* suitably aligned address */ |
| 914 | |
| 915 | pid_t capture_pid; /* process id which uses capture */ |
| 916 | pid_t playback_pid; /* process id which uses capture */ |
| 917 | int running; /* running status */ |
| 918 | |
| 919 | int last_external_sample_rate; /* samplerate mystic ... */ |
| 920 | int last_internal_sample_rate; |
| 921 | int system_sample_rate; |
| 922 | |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 923 | int dev; /* Hardware vars... */ |
| 924 | int irq; |
| 925 | unsigned long port; |
| 926 | void __iomem *iobase; |
| 927 | |
| 928 | int irq_count; /* for debug */ |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 929 | int midiPorts; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 930 | |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 931 | struct snd_card *card; /* one card */ |
| 932 | struct snd_pcm *pcm; /* has one pcm */ |
| 933 | struct snd_hwdep *hwdep; /* and a hwdep for additional ioctl */ |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 934 | struct pci_dev *pci; /* and an pci info */ |
| 935 | |
| 936 | /* Mixer vars */ |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 937 | /* fast alsa mixer */ |
| 938 | struct snd_kcontrol *playback_mixer_ctls[HDSPM_MAX_CHANNELS]; |
| 939 | /* but input to much, so not used */ |
| 940 | struct snd_kcontrol *input_mixer_ctls[HDSPM_MAX_CHANNELS]; |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 941 | /* full mixer accessible over mixer ioctl or hwdep-device */ |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 942 | struct hdspm_mixer *mixer; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 943 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 944 | struct hdspm_tco *tco; /* NULL if no TCO detected */ |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 945 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 946 | char **texts_autosync; |
| 947 | int texts_autosync_items; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 948 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 949 | cycles_t last_interrupt; |
Jaroslav Kysela | 730a586 | 2011-01-27 13:03:15 +0100 | [diff] [blame] | 950 | |
| 951 | struct hdspm_peak_rms peak_rms; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 952 | }; |
| 953 | |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 954 | |
Alexey Dobriyan | cebe41d | 2010-02-06 00:21:03 +0200 | [diff] [blame] | 955 | static DEFINE_PCI_DEVICE_TABLE(snd_hdspm_ids) = { |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 956 | { |
| 957 | .vendor = PCI_VENDOR_ID_XILINX, |
| 958 | .device = PCI_DEVICE_ID_XILINX_HAMMERFALL_DSP_MADI, |
| 959 | .subvendor = PCI_ANY_ID, |
| 960 | .subdevice = PCI_ANY_ID, |
| 961 | .class = 0, |
| 962 | .class_mask = 0, |
| 963 | .driver_data = 0}, |
| 964 | {0,} |
| 965 | }; |
| 966 | |
| 967 | MODULE_DEVICE_TABLE(pci, snd_hdspm_ids); |
| 968 | |
| 969 | /* prototypes */ |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 970 | static int __devinit snd_hdspm_create_alsa_devices(struct snd_card *card, |
| 971 | struct hdspm * hdspm); |
| 972 | static int __devinit snd_hdspm_create_pcm(struct snd_card *card, |
| 973 | struct hdspm * hdspm); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 974 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 975 | static inline void snd_hdspm_initialize_midi_flush(struct hdspm *hdspm); |
| 976 | static int hdspm_update_simple_mixer_controls(struct hdspm *hdspm); |
| 977 | static int hdspm_autosync_ref(struct hdspm *hdspm); |
| 978 | static int snd_hdspm_set_defaults(struct hdspm *hdspm); |
| 979 | static void hdspm_set_sgbuf(struct hdspm *hdspm, |
Takashi Iwai | 77a23f2 | 2008-08-21 13:00:13 +0200 | [diff] [blame] | 980 | struct snd_pcm_substream *substream, |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 981 | unsigned int reg, int channels); |
| 982 | |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 983 | static inline int HDSPM_bit2freq(int n) |
| 984 | { |
Denys Vlasenko | 62cef82 | 2008-04-14 13:04:18 +0200 | [diff] [blame] | 985 | static const int bit2freq_tab[] = { |
| 986 | 0, 32000, 44100, 48000, 64000, 88200, |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 987 | 96000, 128000, 176400, 192000 }; |
| 988 | if (n < 1 || n > 9) |
| 989 | return 0; |
| 990 | return bit2freq_tab[n]; |
| 991 | } |
| 992 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 993 | /* Write/read to/from HDSPM with Adresses in Bytes |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 994 | not words but only 32Bit writes are allowed */ |
| 995 | |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 996 | static inline void hdspm_write(struct hdspm * hdspm, unsigned int reg, |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 997 | unsigned int val) |
| 998 | { |
| 999 | writel(val, hdspm->iobase + reg); |
| 1000 | } |
| 1001 | |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 1002 | static inline unsigned int hdspm_read(struct hdspm * hdspm, unsigned int reg) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1003 | { |
| 1004 | return readl(hdspm->iobase + reg); |
| 1005 | } |
| 1006 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 1007 | /* for each output channel (chan) I have an Input (in) and Playback (pb) Fader |
| 1008 | mixer is write only on hardware so we have to cache him for read |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1009 | each fader is a u32, but uses only the first 16 bit */ |
| 1010 | |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 1011 | static inline int hdspm_read_in_gain(struct hdspm * hdspm, unsigned int chan, |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1012 | unsigned int in) |
| 1013 | { |
Adrian Bunk | 5bab2482 | 2006-03-13 14:15:04 +0100 | [diff] [blame] | 1014 | if (chan >= HDSPM_MIXER_CHANNELS || in >= HDSPM_MIXER_CHANNELS) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1015 | return 0; |
| 1016 | |
| 1017 | return hdspm->mixer->ch[chan].in[in]; |
| 1018 | } |
| 1019 | |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 1020 | static inline int hdspm_read_pb_gain(struct hdspm * hdspm, unsigned int chan, |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1021 | unsigned int pb) |
| 1022 | { |
Adrian Bunk | 5bab2482 | 2006-03-13 14:15:04 +0100 | [diff] [blame] | 1023 | if (chan >= HDSPM_MIXER_CHANNELS || pb >= HDSPM_MIXER_CHANNELS) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1024 | return 0; |
| 1025 | return hdspm->mixer->ch[chan].pb[pb]; |
| 1026 | } |
| 1027 | |
Denys Vlasenko | 62cef82 | 2008-04-14 13:04:18 +0200 | [diff] [blame] | 1028 | static int hdspm_write_in_gain(struct hdspm *hdspm, unsigned int chan, |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1029 | unsigned int in, unsigned short data) |
| 1030 | { |
| 1031 | if (chan >= HDSPM_MIXER_CHANNELS || in >= HDSPM_MIXER_CHANNELS) |
| 1032 | return -1; |
| 1033 | |
| 1034 | hdspm_write(hdspm, |
| 1035 | HDSPM_MADI_mixerBase + |
| 1036 | ((in + 128 * chan) * sizeof(u32)), |
| 1037 | (hdspm->mixer->ch[chan].in[in] = data & 0xFFFF)); |
| 1038 | return 0; |
| 1039 | } |
| 1040 | |
Denys Vlasenko | 62cef82 | 2008-04-14 13:04:18 +0200 | [diff] [blame] | 1041 | static int hdspm_write_pb_gain(struct hdspm *hdspm, unsigned int chan, |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1042 | unsigned int pb, unsigned short data) |
| 1043 | { |
| 1044 | if (chan >= HDSPM_MIXER_CHANNELS || pb >= HDSPM_MIXER_CHANNELS) |
| 1045 | return -1; |
| 1046 | |
| 1047 | hdspm_write(hdspm, |
| 1048 | HDSPM_MADI_mixerBase + |
| 1049 | ((64 + pb + 128 * chan) * sizeof(u32)), |
| 1050 | (hdspm->mixer->ch[chan].pb[pb] = data & 0xFFFF)); |
| 1051 | return 0; |
| 1052 | } |
| 1053 | |
| 1054 | |
| 1055 | /* enable DMA for specific channels, now available for DSP-MADI */ |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 1056 | static inline void snd_hdspm_enable_in(struct hdspm * hdspm, int i, int v) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1057 | { |
| 1058 | hdspm_write(hdspm, HDSPM_inputEnableBase + (4 * i), v); |
| 1059 | } |
| 1060 | |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 1061 | static inline void snd_hdspm_enable_out(struct hdspm * hdspm, int i, int v) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1062 | { |
| 1063 | hdspm_write(hdspm, HDSPM_outputEnableBase + (4 * i), v); |
| 1064 | } |
| 1065 | |
| 1066 | /* check if same process is writing and reading */ |
Denys Vlasenko | 62cef82 | 2008-04-14 13:04:18 +0200 | [diff] [blame] | 1067 | static int snd_hdspm_use_is_exclusive(struct hdspm *hdspm) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1068 | { |
| 1069 | unsigned long flags; |
| 1070 | int ret = 1; |
| 1071 | |
| 1072 | spin_lock_irqsave(&hdspm->lock, flags); |
| 1073 | if ((hdspm->playback_pid != hdspm->capture_pid) && |
| 1074 | (hdspm->playback_pid >= 0) && (hdspm->capture_pid >= 0)) { |
| 1075 | ret = 0; |
| 1076 | } |
| 1077 | spin_unlock_irqrestore(&hdspm->lock, flags); |
| 1078 | return ret; |
| 1079 | } |
| 1080 | |
| 1081 | /* check for external sample rate */ |
Denys Vlasenko | 62cef82 | 2008-04-14 13:04:18 +0200 | [diff] [blame] | 1082 | static int hdspm_external_sample_rate(struct hdspm *hdspm) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1083 | { |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 1084 | unsigned int status, status2, timecode; |
| 1085 | int syncref, rate = 0, rate_bits; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1086 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 1087 | switch (hdspm->io_type) { |
| 1088 | case AES32: |
| 1089 | status2 = hdspm_read(hdspm, HDSPM_statusRegister2); |
| 1090 | status = hdspm_read(hdspm, HDSPM_statusRegister); |
Adrian Knoth | 7c4a95b | 2011-02-23 11:43:13 +0100 | [diff] [blame] | 1091 | timecode = hdspm_read(hdspm, HDSPM_timecodeRegister); |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 1092 | |
| 1093 | syncref = hdspm_autosync_ref(hdspm); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1094 | |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 1095 | if (syncref == HDSPM_AES32_AUTOSYNC_FROM_WORD && |
| 1096 | status & HDSPM_AES32_wcLock) |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 1097 | return HDSPM_bit2freq((status >> HDSPM_AES32_wcFreq_bit) & 0xF); |
| 1098 | |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 1099 | if (syncref >= HDSPM_AES32_AUTOSYNC_FROM_AES1 && |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 1100 | syncref <= HDSPM_AES32_AUTOSYNC_FROM_AES8 && |
| 1101 | status2 & (HDSPM_LockAES >> |
| 1102 | (syncref - HDSPM_AES32_AUTOSYNC_FROM_AES1))) |
| 1103 | return HDSPM_bit2freq((timecode >> (4*(syncref-HDSPM_AES32_AUTOSYNC_FROM_AES1))) & 0xF); |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 1104 | return 0; |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 1105 | break; |
| 1106 | |
| 1107 | case MADIface: |
| 1108 | status = hdspm_read(hdspm, HDSPM_statusRegister); |
| 1109 | |
| 1110 | if (!(status & HDSPM_madiLock)) { |
| 1111 | rate = 0; /* no lock */ |
| 1112 | } else { |
| 1113 | switch (status & (HDSPM_status1_freqMask)) { |
| 1114 | case HDSPM_status1_F_0*1: |
| 1115 | rate = 32000; break; |
| 1116 | case HDSPM_status1_F_0*2: |
| 1117 | rate = 44100; break; |
| 1118 | case HDSPM_status1_F_0*3: |
| 1119 | rate = 48000; break; |
| 1120 | case HDSPM_status1_F_0*4: |
| 1121 | rate = 64000; break; |
| 1122 | case HDSPM_status1_F_0*5: |
| 1123 | rate = 88200; break; |
| 1124 | case HDSPM_status1_F_0*6: |
| 1125 | rate = 96000; break; |
| 1126 | case HDSPM_status1_F_0*7: |
| 1127 | rate = 128000; break; |
| 1128 | case HDSPM_status1_F_0*8: |
| 1129 | rate = 176400; break; |
| 1130 | case HDSPM_status1_F_0*9: |
| 1131 | rate = 192000; break; |
| 1132 | default: |
| 1133 | rate = 0; break; |
| 1134 | } |
| 1135 | } |
| 1136 | |
| 1137 | break; |
| 1138 | |
| 1139 | case MADI: |
| 1140 | case AIO: |
| 1141 | case RayDAT: |
| 1142 | status2 = hdspm_read(hdspm, HDSPM_statusRegister2); |
| 1143 | status = hdspm_read(hdspm, HDSPM_statusRegister); |
| 1144 | rate = 0; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1145 | |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 1146 | /* if wordclock has synced freq and wordclock is valid */ |
| 1147 | if ((status2 & HDSPM_wcLock) != 0 && |
Adrian Knoth | fedf153 | 2011-06-12 17:26:18 +0200 | [diff] [blame] | 1148 | (status2 & HDSPM_SelSyncRef0) == 0) { |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 1149 | |
| 1150 | rate_bits = status2 & HDSPM_wcFreqMask; |
| 1151 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 1152 | |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 1153 | switch (rate_bits) { |
| 1154 | case HDSPM_wcFreq32: |
| 1155 | rate = 32000; |
| 1156 | break; |
| 1157 | case HDSPM_wcFreq44_1: |
| 1158 | rate = 44100; |
| 1159 | break; |
| 1160 | case HDSPM_wcFreq48: |
| 1161 | rate = 48000; |
| 1162 | break; |
| 1163 | case HDSPM_wcFreq64: |
| 1164 | rate = 64000; |
| 1165 | break; |
| 1166 | case HDSPM_wcFreq88_2: |
| 1167 | rate = 88200; |
| 1168 | break; |
| 1169 | case HDSPM_wcFreq96: |
| 1170 | rate = 96000; |
| 1171 | break; |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 1172 | default: |
| 1173 | rate = 0; |
| 1174 | break; |
| 1175 | } |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1176 | } |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1177 | |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 1178 | /* if rate detected and Syncref is Word than have it, |
| 1179 | * word has priority to MADI |
| 1180 | */ |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 1181 | if (rate != 0 && |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 1182 | (status2 & HDSPM_SelSyncRefMask) == HDSPM_SelSyncRef_WORD) |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 1183 | return rate; |
| 1184 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 1185 | /* maybe a madi input (which is taken if sel sync is madi) */ |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 1186 | if (status & HDSPM_madiLock) { |
| 1187 | rate_bits = status & HDSPM_madiFreqMask; |
| 1188 | |
| 1189 | switch (rate_bits) { |
| 1190 | case HDSPM_madiFreq32: |
| 1191 | rate = 32000; |
| 1192 | break; |
| 1193 | case HDSPM_madiFreq44_1: |
| 1194 | rate = 44100; |
| 1195 | break; |
| 1196 | case HDSPM_madiFreq48: |
| 1197 | rate = 48000; |
| 1198 | break; |
| 1199 | case HDSPM_madiFreq64: |
| 1200 | rate = 64000; |
| 1201 | break; |
| 1202 | case HDSPM_madiFreq88_2: |
| 1203 | rate = 88200; |
| 1204 | break; |
| 1205 | case HDSPM_madiFreq96: |
| 1206 | rate = 96000; |
| 1207 | break; |
| 1208 | case HDSPM_madiFreq128: |
| 1209 | rate = 128000; |
| 1210 | break; |
| 1211 | case HDSPM_madiFreq176_4: |
| 1212 | rate = 176400; |
| 1213 | break; |
| 1214 | case HDSPM_madiFreq192: |
| 1215 | rate = 192000; |
| 1216 | break; |
| 1217 | default: |
| 1218 | rate = 0; |
| 1219 | break; |
| 1220 | } |
Adrian Knoth | d12c51d | 2011-07-29 03:11:03 +0200 | [diff] [blame] | 1221 | |
| 1222 | /* QS and DS rates normally can not be detected |
| 1223 | * automatically by the card. Only exception is MADI |
| 1224 | * in 96k frame mode. |
| 1225 | * |
| 1226 | * So if we read SS values (32 .. 48k), check for |
| 1227 | * user-provided DS/QS bits in the control register |
| 1228 | * and multiply the base frequency accordingly. |
| 1229 | */ |
| 1230 | if (rate <= 48000) { |
| 1231 | if (hdspm->control_register & HDSPM_QuadSpeed) |
| 1232 | rate *= 4; |
| 1233 | else if (hdspm->control_register & |
| 1234 | HDSPM_DoubleSpeed) |
| 1235 | rate *= 2; |
| 1236 | } |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 1237 | } |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 1238 | break; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1239 | } |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 1240 | |
| 1241 | return rate; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1242 | } |
| 1243 | |
Adrian Knoth | 7cb155f | 2011-08-15 00:22:53 +0200 | [diff] [blame] | 1244 | /* return latency in samples per period */ |
| 1245 | static int hdspm_get_latency(struct hdspm *hdspm) |
| 1246 | { |
| 1247 | int n; |
| 1248 | |
| 1249 | n = hdspm_decode_latency(hdspm->control_register); |
| 1250 | |
| 1251 | /* Special case for new RME cards with 32 samples period size. |
| 1252 | * The three latency bits in the control register |
| 1253 | * (HDSP_LatencyMask) encode latency values of 64 samples as |
| 1254 | * 0, 128 samples as 1 ... 4096 samples as 6. For old cards, 7 |
| 1255 | * denotes 8192 samples, but on new cards like RayDAT or AIO, |
| 1256 | * it corresponds to 32 samples. |
| 1257 | */ |
| 1258 | if ((7 == n) && (RayDAT == hdspm->io_type || AIO == hdspm->io_type)) |
| 1259 | n = -1; |
| 1260 | |
| 1261 | return 1 << (n + 6); |
| 1262 | } |
| 1263 | |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1264 | /* Latency function */ |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 1265 | static inline void hdspm_compute_period_size(struct hdspm *hdspm) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1266 | { |
Adrian Knoth | 7cb155f | 2011-08-15 00:22:53 +0200 | [diff] [blame] | 1267 | hdspm->period_bytes = 4 * hdspm_get_latency(hdspm); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1268 | } |
| 1269 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 1270 | |
| 1271 | static snd_pcm_uframes_t hdspm_hw_pointer(struct hdspm *hdspm) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1272 | { |
| 1273 | int position; |
| 1274 | |
| 1275 | position = hdspm_read(hdspm, HDSPM_statusRegister); |
Adrian Knoth | 483cee7 | 2011-02-23 11:43:09 +0100 | [diff] [blame] | 1276 | |
| 1277 | switch (hdspm->io_type) { |
| 1278 | case RayDAT: |
| 1279 | case AIO: |
| 1280 | position &= HDSPM_BufferPositionMask; |
| 1281 | position /= 4; /* Bytes per sample */ |
| 1282 | break; |
| 1283 | default: |
| 1284 | position = (position & HDSPM_BufferID) ? |
| 1285 | (hdspm->period_bytes / 4) : 0; |
| 1286 | } |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1287 | |
| 1288 | return position; |
| 1289 | } |
| 1290 | |
| 1291 | |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 1292 | static inline void hdspm_start_audio(struct hdspm * s) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1293 | { |
| 1294 | s->control_register |= (HDSPM_AudioInterruptEnable | HDSPM_Start); |
| 1295 | hdspm_write(s, HDSPM_controlRegister, s->control_register); |
| 1296 | } |
| 1297 | |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 1298 | static inline void hdspm_stop_audio(struct hdspm * s) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1299 | { |
| 1300 | s->control_register &= ~(HDSPM_Start | HDSPM_AudioInterruptEnable); |
| 1301 | hdspm_write(s, HDSPM_controlRegister, s->control_register); |
| 1302 | } |
| 1303 | |
| 1304 | /* should I silence all or only opened ones ? doit all for first even is 4MB*/ |
Denys Vlasenko | 62cef82 | 2008-04-14 13:04:18 +0200 | [diff] [blame] | 1305 | static void hdspm_silence_playback(struct hdspm *hdspm) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1306 | { |
| 1307 | int i; |
| 1308 | int n = hdspm->period_bytes; |
| 1309 | void *buf = hdspm->playback_buffer; |
| 1310 | |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 1311 | if (buf == NULL) |
| 1312 | return; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1313 | |
| 1314 | for (i = 0; i < HDSPM_MAX_CHANNELS; i++) { |
| 1315 | memset(buf, 0, n); |
| 1316 | buf += HDSPM_CHANNEL_BUFFER_BYTES; |
| 1317 | } |
| 1318 | } |
| 1319 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 1320 | static int hdspm_set_interrupt_interval(struct hdspm *s, unsigned int frames) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1321 | { |
| 1322 | int n; |
| 1323 | |
| 1324 | spin_lock_irq(&s->lock); |
| 1325 | |
Adrian Knoth | 2e61027 | 2011-08-15 00:22:54 +0200 | [diff] [blame] | 1326 | if (32 == frames) { |
| 1327 | /* Special case for new RME cards like RayDAT/AIO which |
| 1328 | * support period sizes of 32 samples. Since latency is |
| 1329 | * encoded in the three bits of HDSP_LatencyMask, we can only |
| 1330 | * have values from 0 .. 7. While 0 still means 64 samples and |
| 1331 | * 6 represents 4096 samples on all cards, 7 represents 8192 |
| 1332 | * on older cards and 32 samples on new cards. |
| 1333 | * |
| 1334 | * In other words, period size in samples is calculated by |
| 1335 | * 2^(n+6) with n ranging from 0 .. 7. |
| 1336 | */ |
| 1337 | n = 7; |
| 1338 | } else { |
| 1339 | frames >>= 7; |
| 1340 | n = 0; |
| 1341 | while (frames) { |
| 1342 | n++; |
| 1343 | frames >>= 1; |
| 1344 | } |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1345 | } |
Adrian Knoth | 2e61027 | 2011-08-15 00:22:54 +0200 | [diff] [blame] | 1346 | |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1347 | s->control_register &= ~HDSPM_LatencyMask; |
| 1348 | s->control_register |= hdspm_encode_latency(n); |
| 1349 | |
| 1350 | hdspm_write(s, HDSPM_controlRegister, s->control_register); |
| 1351 | |
| 1352 | hdspm_compute_period_size(s); |
| 1353 | |
| 1354 | spin_unlock_irq(&s->lock); |
| 1355 | |
| 1356 | return 0; |
| 1357 | } |
| 1358 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 1359 | static u64 hdspm_calc_dds_value(struct hdspm *hdspm, u64 period) |
| 1360 | { |
| 1361 | u64 freq_const; |
| 1362 | |
| 1363 | if (period == 0) |
| 1364 | return 0; |
| 1365 | |
| 1366 | switch (hdspm->io_type) { |
| 1367 | case MADI: |
| 1368 | case AES32: |
| 1369 | freq_const = 110069313433624ULL; |
| 1370 | break; |
| 1371 | case RayDAT: |
| 1372 | case AIO: |
| 1373 | freq_const = 104857600000000ULL; |
| 1374 | break; |
| 1375 | case MADIface: |
| 1376 | freq_const = 131072000000000ULL; |
Takashi Iwai | 3d56c8e | 2011-08-05 12:30:12 +0200 | [diff] [blame] | 1377 | break; |
| 1378 | default: |
| 1379 | snd_BUG(); |
| 1380 | return 0; |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 1381 | } |
| 1382 | |
| 1383 | return div_u64(freq_const, period); |
| 1384 | } |
| 1385 | |
| 1386 | |
Remy Bruno | ffb2c3c | 2007-03-07 19:08:46 +0100 | [diff] [blame] | 1387 | static void hdspm_set_dds_value(struct hdspm *hdspm, int rate) |
| 1388 | { |
| 1389 | u64 n; |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 1390 | |
Remy Bruno | ffb2c3c | 2007-03-07 19:08:46 +0100 | [diff] [blame] | 1391 | if (rate >= 112000) |
| 1392 | rate /= 4; |
| 1393 | else if (rate >= 56000) |
| 1394 | rate /= 2; |
| 1395 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 1396 | switch (hdspm->io_type) { |
| 1397 | case MADIface: |
Takashi Iwai | 3d56c8e | 2011-08-05 12:30:12 +0200 | [diff] [blame] | 1398 | n = 131072000000000ULL; /* 125 MHz */ |
| 1399 | break; |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 1400 | case MADI: |
| 1401 | case AES32: |
Takashi Iwai | 3d56c8e | 2011-08-05 12:30:12 +0200 | [diff] [blame] | 1402 | n = 110069313433624ULL; /* 105 MHz */ |
| 1403 | break; |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 1404 | case RayDAT: |
| 1405 | case AIO: |
Takashi Iwai | 3d56c8e | 2011-08-05 12:30:12 +0200 | [diff] [blame] | 1406 | n = 104857600000000ULL; /* 100 MHz */ |
| 1407 | break; |
| 1408 | default: |
| 1409 | snd_BUG(); |
| 1410 | return; |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 1411 | } |
| 1412 | |
Takashi Iwai | 3f7440a | 2009-06-05 17:40:04 +0200 | [diff] [blame] | 1413 | n = div_u64(n, rate); |
Remy Bruno | ffb2c3c | 2007-03-07 19:08:46 +0100 | [diff] [blame] | 1414 | /* n should be less than 2^32 for being written to FREQ register */ |
Takashi Iwai | da3cec3 | 2008-08-08 17:12:14 +0200 | [diff] [blame] | 1415 | snd_BUG_ON(n >> 32); |
Remy Bruno | ffb2c3c | 2007-03-07 19:08:46 +0100 | [diff] [blame] | 1416 | hdspm_write(hdspm, HDSPM_freqReg, (u32)n); |
| 1417 | } |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1418 | |
| 1419 | /* dummy set rate lets see what happens */ |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 1420 | static int hdspm_set_rate(struct hdspm * hdspm, int rate, int called_internally) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1421 | { |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1422 | int current_rate; |
| 1423 | int rate_bits; |
| 1424 | int not_set = 0; |
Remy Bruno | 6534599 | 2007-08-31 12:21:08 +0200 | [diff] [blame] | 1425 | int current_speed, target_speed; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1426 | |
| 1427 | /* ASSUMPTION: hdspm->lock is either set, or there is no need for |
| 1428 | it (e.g. during module initialization). |
| 1429 | */ |
| 1430 | |
| 1431 | if (!(hdspm->control_register & HDSPM_ClockModeMaster)) { |
| 1432 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 1433 | /* SLAVE --- */ |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1434 | if (called_internally) { |
| 1435 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 1436 | /* request from ctl or card initialization |
| 1437 | just make a warning an remember setting |
| 1438 | for future master mode switching */ |
| 1439 | |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 1440 | snd_printk(KERN_WARNING "HDSPM: " |
| 1441 | "Warning: device is not running " |
| 1442 | "as a clock master.\n"); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1443 | not_set = 1; |
| 1444 | } else { |
| 1445 | |
| 1446 | /* hw_param request while in AutoSync mode */ |
| 1447 | int external_freq = |
| 1448 | hdspm_external_sample_rate(hdspm); |
| 1449 | |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 1450 | if (hdspm_autosync_ref(hdspm) == |
| 1451 | HDSPM_AUTOSYNC_FROM_NONE) { |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1452 | |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 1453 | snd_printk(KERN_WARNING "HDSPM: " |
| 1454 | "Detected no Externel Sync \n"); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1455 | not_set = 1; |
| 1456 | |
| 1457 | } else if (rate != external_freq) { |
| 1458 | |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 1459 | snd_printk(KERN_WARNING "HDSPM: " |
| 1460 | "Warning: No AutoSync source for " |
| 1461 | "requested rate\n"); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1462 | not_set = 1; |
| 1463 | } |
| 1464 | } |
| 1465 | } |
| 1466 | |
| 1467 | current_rate = hdspm->system_sample_rate; |
| 1468 | |
| 1469 | /* Changing between Singe, Double and Quad speed is not |
| 1470 | allowed if any substreams are open. This is because such a change |
| 1471 | causes a shift in the location of the DMA buffers and a reduction |
| 1472 | in the number of available buffers. |
| 1473 | |
| 1474 | Note that a similar but essentially insoluble problem exists for |
| 1475 | externally-driven rate changes. All we can do is to flag rate |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 1476 | changes in the read/write routines. |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1477 | */ |
| 1478 | |
Remy Bruno | 6534599 | 2007-08-31 12:21:08 +0200 | [diff] [blame] | 1479 | if (current_rate <= 48000) |
| 1480 | current_speed = HDSPM_SPEED_SINGLE; |
| 1481 | else if (current_rate <= 96000) |
| 1482 | current_speed = HDSPM_SPEED_DOUBLE; |
| 1483 | else |
| 1484 | current_speed = HDSPM_SPEED_QUAD; |
| 1485 | |
| 1486 | if (rate <= 48000) |
| 1487 | target_speed = HDSPM_SPEED_SINGLE; |
| 1488 | else if (rate <= 96000) |
| 1489 | target_speed = HDSPM_SPEED_DOUBLE; |
| 1490 | else |
| 1491 | target_speed = HDSPM_SPEED_QUAD; |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 1492 | |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1493 | switch (rate) { |
| 1494 | case 32000: |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1495 | rate_bits = HDSPM_Frequency32KHz; |
| 1496 | break; |
| 1497 | case 44100: |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1498 | rate_bits = HDSPM_Frequency44_1KHz; |
| 1499 | break; |
| 1500 | case 48000: |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1501 | rate_bits = HDSPM_Frequency48KHz; |
| 1502 | break; |
| 1503 | case 64000: |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1504 | rate_bits = HDSPM_Frequency64KHz; |
| 1505 | break; |
| 1506 | case 88200: |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1507 | rate_bits = HDSPM_Frequency88_2KHz; |
| 1508 | break; |
| 1509 | case 96000: |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1510 | rate_bits = HDSPM_Frequency96KHz; |
| 1511 | break; |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 1512 | case 128000: |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 1513 | rate_bits = HDSPM_Frequency128KHz; |
| 1514 | break; |
| 1515 | case 176400: |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 1516 | rate_bits = HDSPM_Frequency176_4KHz; |
| 1517 | break; |
| 1518 | case 192000: |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 1519 | rate_bits = HDSPM_Frequency192KHz; |
| 1520 | break; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1521 | default: |
| 1522 | return -EINVAL; |
| 1523 | } |
| 1524 | |
Remy Bruno | 6534599 | 2007-08-31 12:21:08 +0200 | [diff] [blame] | 1525 | if (current_speed != target_speed |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1526 | && (hdspm->capture_pid >= 0 || hdspm->playback_pid >= 0)) { |
| 1527 | snd_printk |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 1528 | (KERN_ERR "HDSPM: " |
Remy Bruno | 6534599 | 2007-08-31 12:21:08 +0200 | [diff] [blame] | 1529 | "cannot change from %s speed to %s speed mode " |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 1530 | "(capture PID = %d, playback PID = %d)\n", |
Remy Bruno | 6534599 | 2007-08-31 12:21:08 +0200 | [diff] [blame] | 1531 | hdspm_speed_names[current_speed], |
| 1532 | hdspm_speed_names[target_speed], |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1533 | hdspm->capture_pid, hdspm->playback_pid); |
| 1534 | return -EBUSY; |
| 1535 | } |
| 1536 | |
| 1537 | hdspm->control_register &= ~HDSPM_FrequencyMask; |
| 1538 | hdspm->control_register |= rate_bits; |
| 1539 | hdspm_write(hdspm, HDSPM_controlRegister, hdspm->control_register); |
| 1540 | |
Remy Bruno | ffb2c3c | 2007-03-07 19:08:46 +0100 | [diff] [blame] | 1541 | /* For AES32, need to set DDS value in FREQ register |
| 1542 | For MADI, also apparently */ |
| 1543 | hdspm_set_dds_value(hdspm, rate); |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 1544 | |
| 1545 | if (AES32 == hdspm->io_type && rate != current_rate) |
Remy Bruno | ffb2c3c | 2007-03-07 19:08:46 +0100 | [diff] [blame] | 1546 | hdspm_write(hdspm, HDSPM_eeprom_wr, 0); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1547 | |
| 1548 | hdspm->system_sample_rate = rate; |
| 1549 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 1550 | if (rate <= 48000) { |
| 1551 | hdspm->channel_map_in = hdspm->channel_map_in_ss; |
| 1552 | hdspm->channel_map_out = hdspm->channel_map_out_ss; |
| 1553 | hdspm->max_channels_in = hdspm->ss_in_channels; |
| 1554 | hdspm->max_channels_out = hdspm->ss_out_channels; |
| 1555 | hdspm->port_names_in = hdspm->port_names_in_ss; |
| 1556 | hdspm->port_names_out = hdspm->port_names_out_ss; |
| 1557 | } else if (rate <= 96000) { |
| 1558 | hdspm->channel_map_in = hdspm->channel_map_in_ds; |
| 1559 | hdspm->channel_map_out = hdspm->channel_map_out_ds; |
| 1560 | hdspm->max_channels_in = hdspm->ds_in_channels; |
| 1561 | hdspm->max_channels_out = hdspm->ds_out_channels; |
| 1562 | hdspm->port_names_in = hdspm->port_names_in_ds; |
| 1563 | hdspm->port_names_out = hdspm->port_names_out_ds; |
| 1564 | } else { |
| 1565 | hdspm->channel_map_in = hdspm->channel_map_in_qs; |
| 1566 | hdspm->channel_map_out = hdspm->channel_map_out_qs; |
| 1567 | hdspm->max_channels_in = hdspm->qs_in_channels; |
| 1568 | hdspm->max_channels_out = hdspm->qs_out_channels; |
| 1569 | hdspm->port_names_in = hdspm->port_names_in_qs; |
| 1570 | hdspm->port_names_out = hdspm->port_names_out_qs; |
| 1571 | } |
| 1572 | |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1573 | if (not_set != 0) |
| 1574 | return -1; |
| 1575 | |
| 1576 | return 0; |
| 1577 | } |
| 1578 | |
| 1579 | /* mainly for init to 0 on load */ |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 1580 | static void all_in_all_mixer(struct hdspm * hdspm, int sgain) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1581 | { |
| 1582 | int i, j; |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 1583 | unsigned int gain; |
| 1584 | |
| 1585 | if (sgain > UNITY_GAIN) |
| 1586 | gain = UNITY_GAIN; |
| 1587 | else if (sgain < 0) |
| 1588 | gain = 0; |
| 1589 | else |
| 1590 | gain = sgain; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1591 | |
| 1592 | for (i = 0; i < HDSPM_MIXER_CHANNELS; i++) |
| 1593 | for (j = 0; j < HDSPM_MIXER_CHANNELS; j++) { |
| 1594 | hdspm_write_in_gain(hdspm, i, j, gain); |
| 1595 | hdspm_write_pb_gain(hdspm, i, j, gain); |
| 1596 | } |
| 1597 | } |
| 1598 | |
| 1599 | /*---------------------------------------------------------------------------- |
| 1600 | MIDI |
| 1601 | ----------------------------------------------------------------------------*/ |
| 1602 | |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 1603 | static inline unsigned char snd_hdspm_midi_read_byte (struct hdspm *hdspm, |
| 1604 | int id) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1605 | { |
| 1606 | /* the hardware already does the relevant bit-mask with 0xff */ |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 1607 | return hdspm_read(hdspm, hdspm->midi[id].dataIn); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1608 | } |
| 1609 | |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 1610 | static inline void snd_hdspm_midi_write_byte (struct hdspm *hdspm, int id, |
| 1611 | int val) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1612 | { |
| 1613 | /* the hardware already does the relevant bit-mask with 0xff */ |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 1614 | return hdspm_write(hdspm, hdspm->midi[id].dataOut, val); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1615 | } |
| 1616 | |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 1617 | static inline int snd_hdspm_midi_input_available (struct hdspm *hdspm, int id) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1618 | { |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 1619 | return hdspm_read(hdspm, hdspm->midi[id].statusIn) & 0xFF; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1620 | } |
| 1621 | |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 1622 | static inline int snd_hdspm_midi_output_possible (struct hdspm *hdspm, int id) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1623 | { |
| 1624 | int fifo_bytes_used; |
| 1625 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 1626 | fifo_bytes_used = hdspm_read(hdspm, hdspm->midi[id].statusOut) & 0xFF; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1627 | |
| 1628 | if (fifo_bytes_used < 128) |
| 1629 | return 128 - fifo_bytes_used; |
| 1630 | else |
| 1631 | return 0; |
| 1632 | } |
| 1633 | |
Denys Vlasenko | 62cef82 | 2008-04-14 13:04:18 +0200 | [diff] [blame] | 1634 | static void snd_hdspm_flush_midi_input(struct hdspm *hdspm, int id) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1635 | { |
| 1636 | while (snd_hdspm_midi_input_available (hdspm, id)) |
| 1637 | snd_hdspm_midi_read_byte (hdspm, id); |
| 1638 | } |
| 1639 | |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 1640 | static int snd_hdspm_midi_output_write (struct hdspm_midi *hmidi) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1641 | { |
| 1642 | unsigned long flags; |
| 1643 | int n_pending; |
| 1644 | int to_write; |
| 1645 | int i; |
| 1646 | unsigned char buf[128]; |
| 1647 | |
| 1648 | /* Output is not interrupt driven */ |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 1649 | |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1650 | spin_lock_irqsave (&hmidi->lock, flags); |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 1651 | if (hmidi->output && |
| 1652 | !snd_rawmidi_transmit_empty (hmidi->output)) { |
| 1653 | n_pending = snd_hdspm_midi_output_possible (hmidi->hdspm, |
| 1654 | hmidi->id); |
| 1655 | if (n_pending > 0) { |
| 1656 | if (n_pending > (int)sizeof (buf)) |
| 1657 | n_pending = sizeof (buf); |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 1658 | |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 1659 | to_write = snd_rawmidi_transmit (hmidi->output, buf, |
| 1660 | n_pending); |
| 1661 | if (to_write > 0) { |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 1662 | for (i = 0; i < to_write; ++i) |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 1663 | snd_hdspm_midi_write_byte (hmidi->hdspm, |
| 1664 | hmidi->id, |
| 1665 | buf[i]); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1666 | } |
| 1667 | } |
| 1668 | } |
| 1669 | spin_unlock_irqrestore (&hmidi->lock, flags); |
| 1670 | return 0; |
| 1671 | } |
| 1672 | |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 1673 | static int snd_hdspm_midi_input_read (struct hdspm_midi *hmidi) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1674 | { |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 1675 | unsigned char buf[128]; /* this buffer is designed to match the MIDI |
| 1676 | * input FIFO size |
| 1677 | */ |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1678 | unsigned long flags; |
| 1679 | int n_pending; |
| 1680 | int i; |
| 1681 | |
| 1682 | spin_lock_irqsave (&hmidi->lock, flags); |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 1683 | n_pending = snd_hdspm_midi_input_available (hmidi->hdspm, hmidi->id); |
| 1684 | if (n_pending > 0) { |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1685 | if (hmidi->input) { |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 1686 | if (n_pending > (int)sizeof (buf)) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1687 | n_pending = sizeof (buf); |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 1688 | for (i = 0; i < n_pending; ++i) |
| 1689 | buf[i] = snd_hdspm_midi_read_byte (hmidi->hdspm, |
| 1690 | hmidi->id); |
| 1691 | if (n_pending) |
| 1692 | snd_rawmidi_receive (hmidi->input, buf, |
| 1693 | n_pending); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1694 | } else { |
| 1695 | /* flush the MIDI input FIFO */ |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 1696 | while (n_pending--) |
| 1697 | snd_hdspm_midi_read_byte (hmidi->hdspm, |
| 1698 | hmidi->id); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1699 | } |
| 1700 | } |
| 1701 | hmidi->pending = 0; |
Adrian Knoth | c0da001 | 2011-06-12 17:26:17 +0200 | [diff] [blame] | 1702 | spin_unlock_irqrestore(&hmidi->lock, flags); |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 1703 | |
Adrian Knoth | c0da001 | 2011-06-12 17:26:17 +0200 | [diff] [blame] | 1704 | spin_lock_irqsave(&hmidi->hdspm->lock, flags); |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 1705 | hmidi->hdspm->control_register |= hmidi->ie; |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 1706 | hdspm_write(hmidi->hdspm, HDSPM_controlRegister, |
| 1707 | hmidi->hdspm->control_register); |
Adrian Knoth | c0da001 | 2011-06-12 17:26:17 +0200 | [diff] [blame] | 1708 | spin_unlock_irqrestore(&hmidi->hdspm->lock, flags); |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 1709 | |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1710 | return snd_hdspm_midi_output_write (hmidi); |
| 1711 | } |
| 1712 | |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 1713 | static void |
| 1714 | snd_hdspm_midi_input_trigger(struct snd_rawmidi_substream *substream, int up) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1715 | { |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 1716 | struct hdspm *hdspm; |
| 1717 | struct hdspm_midi *hmidi; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1718 | unsigned long flags; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1719 | |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 1720 | hmidi = substream->rmidi->private_data; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1721 | hdspm = hmidi->hdspm; |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 1722 | |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1723 | spin_lock_irqsave (&hdspm->lock, flags); |
| 1724 | if (up) { |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 1725 | if (!(hdspm->control_register & hmidi->ie)) { |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1726 | snd_hdspm_flush_midi_input (hdspm, hmidi->id); |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 1727 | hdspm->control_register |= hmidi->ie; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1728 | } |
| 1729 | } else { |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 1730 | hdspm->control_register &= ~hmidi->ie; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1731 | } |
| 1732 | |
| 1733 | hdspm_write(hdspm, HDSPM_controlRegister, hdspm->control_register); |
| 1734 | spin_unlock_irqrestore (&hdspm->lock, flags); |
| 1735 | } |
| 1736 | |
| 1737 | static void snd_hdspm_midi_output_timer(unsigned long data) |
| 1738 | { |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 1739 | struct hdspm_midi *hmidi = (struct hdspm_midi *) data; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1740 | unsigned long flags; |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 1741 | |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1742 | snd_hdspm_midi_output_write(hmidi); |
| 1743 | spin_lock_irqsave (&hmidi->lock, flags); |
| 1744 | |
| 1745 | /* this does not bump hmidi->istimer, because the |
| 1746 | kernel automatically removed the timer when it |
| 1747 | expired, and we are now adding it back, thus |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 1748 | leaving istimer wherever it was set before. |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1749 | */ |
| 1750 | |
| 1751 | if (hmidi->istimer) { |
| 1752 | hmidi->timer.expires = 1 + jiffies; |
| 1753 | add_timer(&hmidi->timer); |
| 1754 | } |
| 1755 | |
| 1756 | spin_unlock_irqrestore (&hmidi->lock, flags); |
| 1757 | } |
| 1758 | |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 1759 | static void |
| 1760 | snd_hdspm_midi_output_trigger(struct snd_rawmidi_substream *substream, int up) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1761 | { |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 1762 | struct hdspm_midi *hmidi; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1763 | unsigned long flags; |
| 1764 | |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 1765 | hmidi = substream->rmidi->private_data; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1766 | spin_lock_irqsave (&hmidi->lock, flags); |
| 1767 | if (up) { |
| 1768 | if (!hmidi->istimer) { |
| 1769 | init_timer(&hmidi->timer); |
| 1770 | hmidi->timer.function = snd_hdspm_midi_output_timer; |
| 1771 | hmidi->timer.data = (unsigned long) hmidi; |
| 1772 | hmidi->timer.expires = 1 + jiffies; |
| 1773 | add_timer(&hmidi->timer); |
| 1774 | hmidi->istimer++; |
| 1775 | } |
| 1776 | } else { |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 1777 | if (hmidi->istimer && --hmidi->istimer <= 0) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1778 | del_timer (&hmidi->timer); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1779 | } |
| 1780 | spin_unlock_irqrestore (&hmidi->lock, flags); |
| 1781 | if (up) |
| 1782 | snd_hdspm_midi_output_write(hmidi); |
| 1783 | } |
| 1784 | |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 1785 | static int snd_hdspm_midi_input_open(struct snd_rawmidi_substream *substream) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1786 | { |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 1787 | struct hdspm_midi *hmidi; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1788 | |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 1789 | hmidi = substream->rmidi->private_data; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1790 | spin_lock_irq (&hmidi->lock); |
| 1791 | snd_hdspm_flush_midi_input (hmidi->hdspm, hmidi->id); |
| 1792 | hmidi->input = substream; |
| 1793 | spin_unlock_irq (&hmidi->lock); |
| 1794 | |
| 1795 | return 0; |
| 1796 | } |
| 1797 | |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 1798 | static int snd_hdspm_midi_output_open(struct snd_rawmidi_substream *substream) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1799 | { |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 1800 | struct hdspm_midi *hmidi; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1801 | |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 1802 | hmidi = substream->rmidi->private_data; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1803 | spin_lock_irq (&hmidi->lock); |
| 1804 | hmidi->output = substream; |
| 1805 | spin_unlock_irq (&hmidi->lock); |
| 1806 | |
| 1807 | return 0; |
| 1808 | } |
| 1809 | |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 1810 | static int snd_hdspm_midi_input_close(struct snd_rawmidi_substream *substream) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1811 | { |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 1812 | struct hdspm_midi *hmidi; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1813 | |
| 1814 | snd_hdspm_midi_input_trigger (substream, 0); |
| 1815 | |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 1816 | hmidi = substream->rmidi->private_data; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1817 | spin_lock_irq (&hmidi->lock); |
| 1818 | hmidi->input = NULL; |
| 1819 | spin_unlock_irq (&hmidi->lock); |
| 1820 | |
| 1821 | return 0; |
| 1822 | } |
| 1823 | |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 1824 | static int snd_hdspm_midi_output_close(struct snd_rawmidi_substream *substream) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1825 | { |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 1826 | struct hdspm_midi *hmidi; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1827 | |
| 1828 | snd_hdspm_midi_output_trigger (substream, 0); |
| 1829 | |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 1830 | hmidi = substream->rmidi->private_data; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1831 | spin_lock_irq (&hmidi->lock); |
| 1832 | hmidi->output = NULL; |
| 1833 | spin_unlock_irq (&hmidi->lock); |
| 1834 | |
| 1835 | return 0; |
| 1836 | } |
| 1837 | |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 1838 | static struct snd_rawmidi_ops snd_hdspm_midi_output = |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1839 | { |
| 1840 | .open = snd_hdspm_midi_output_open, |
| 1841 | .close = snd_hdspm_midi_output_close, |
| 1842 | .trigger = snd_hdspm_midi_output_trigger, |
| 1843 | }; |
| 1844 | |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 1845 | static struct snd_rawmidi_ops snd_hdspm_midi_input = |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1846 | { |
| 1847 | .open = snd_hdspm_midi_input_open, |
| 1848 | .close = snd_hdspm_midi_input_close, |
| 1849 | .trigger = snd_hdspm_midi_input_trigger, |
| 1850 | }; |
| 1851 | |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 1852 | static int __devinit snd_hdspm_create_midi (struct snd_card *card, |
| 1853 | struct hdspm *hdspm, int id) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1854 | { |
| 1855 | int err; |
| 1856 | char buf[32]; |
| 1857 | |
| 1858 | hdspm->midi[id].id = id; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1859 | hdspm->midi[id].hdspm = hdspm; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1860 | spin_lock_init (&hdspm->midi[id].lock); |
| 1861 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 1862 | if (0 == id) { |
| 1863 | if (MADIface == hdspm->io_type) { |
| 1864 | /* MIDI-over-MADI on HDSPe MADIface */ |
| 1865 | hdspm->midi[0].dataIn = HDSPM_midiDataIn2; |
| 1866 | hdspm->midi[0].statusIn = HDSPM_midiStatusIn2; |
| 1867 | hdspm->midi[0].dataOut = HDSPM_midiDataOut2; |
| 1868 | hdspm->midi[0].statusOut = HDSPM_midiStatusOut2; |
| 1869 | hdspm->midi[0].ie = HDSPM_Midi2InterruptEnable; |
| 1870 | hdspm->midi[0].irq = HDSPM_midi2IRQPending; |
| 1871 | } else { |
| 1872 | hdspm->midi[0].dataIn = HDSPM_midiDataIn0; |
| 1873 | hdspm->midi[0].statusIn = HDSPM_midiStatusIn0; |
| 1874 | hdspm->midi[0].dataOut = HDSPM_midiDataOut0; |
| 1875 | hdspm->midi[0].statusOut = HDSPM_midiStatusOut0; |
| 1876 | hdspm->midi[0].ie = HDSPM_Midi0InterruptEnable; |
| 1877 | hdspm->midi[0].irq = HDSPM_midi0IRQPending; |
| 1878 | } |
| 1879 | } else if (1 == id) { |
| 1880 | hdspm->midi[1].dataIn = HDSPM_midiDataIn1; |
| 1881 | hdspm->midi[1].statusIn = HDSPM_midiStatusIn1; |
| 1882 | hdspm->midi[1].dataOut = HDSPM_midiDataOut1; |
| 1883 | hdspm->midi[1].statusOut = HDSPM_midiStatusOut1; |
| 1884 | hdspm->midi[1].ie = HDSPM_Midi1InterruptEnable; |
| 1885 | hdspm->midi[1].irq = HDSPM_midi1IRQPending; |
| 1886 | } else if ((2 == id) && (MADI == hdspm->io_type)) { |
| 1887 | /* MIDI-over-MADI on HDSPe MADI */ |
| 1888 | hdspm->midi[2].dataIn = HDSPM_midiDataIn2; |
| 1889 | hdspm->midi[2].statusIn = HDSPM_midiStatusIn2; |
| 1890 | hdspm->midi[2].dataOut = HDSPM_midiDataOut2; |
| 1891 | hdspm->midi[2].statusOut = HDSPM_midiStatusOut2; |
| 1892 | hdspm->midi[2].ie = HDSPM_Midi2InterruptEnable; |
| 1893 | hdspm->midi[2].irq = HDSPM_midi2IRQPending; |
| 1894 | } else if (2 == id) { |
| 1895 | /* TCO MTC, read only */ |
| 1896 | hdspm->midi[2].dataIn = HDSPM_midiDataIn2; |
| 1897 | hdspm->midi[2].statusIn = HDSPM_midiStatusIn2; |
| 1898 | hdspm->midi[2].dataOut = -1; |
| 1899 | hdspm->midi[2].statusOut = -1; |
| 1900 | hdspm->midi[2].ie = HDSPM_Midi2InterruptEnable; |
| 1901 | hdspm->midi[2].irq = HDSPM_midi2IRQPendingAES; |
| 1902 | } else if (3 == id) { |
| 1903 | /* TCO MTC on HDSPe MADI */ |
| 1904 | hdspm->midi[3].dataIn = HDSPM_midiDataIn3; |
| 1905 | hdspm->midi[3].statusIn = HDSPM_midiStatusIn3; |
| 1906 | hdspm->midi[3].dataOut = -1; |
| 1907 | hdspm->midi[3].statusOut = -1; |
| 1908 | hdspm->midi[3].ie = HDSPM_Midi3InterruptEnable; |
| 1909 | hdspm->midi[3].irq = HDSPM_midi3IRQPending; |
| 1910 | } |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1911 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 1912 | if ((id < 2) || ((2 == id) && ((MADI == hdspm->io_type) || |
| 1913 | (MADIface == hdspm->io_type)))) { |
| 1914 | if ((id == 0) && (MADIface == hdspm->io_type)) { |
| 1915 | sprintf(buf, "%s MIDIoverMADI", card->shortname); |
| 1916 | } else if ((id == 2) && (MADI == hdspm->io_type)) { |
| 1917 | sprintf(buf, "%s MIDIoverMADI", card->shortname); |
| 1918 | } else { |
| 1919 | sprintf(buf, "%s MIDI %d", card->shortname, id+1); |
| 1920 | } |
| 1921 | err = snd_rawmidi_new(card, buf, id, 1, 1, |
| 1922 | &hdspm->midi[id].rmidi); |
| 1923 | if (err < 0) |
| 1924 | return err; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1925 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 1926 | sprintf(hdspm->midi[id].rmidi->name, "%s MIDI %d", |
| 1927 | card->id, id+1); |
| 1928 | hdspm->midi[id].rmidi->private_data = &hdspm->midi[id]; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1929 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 1930 | snd_rawmidi_set_ops(hdspm->midi[id].rmidi, |
| 1931 | SNDRV_RAWMIDI_STREAM_OUTPUT, |
| 1932 | &snd_hdspm_midi_output); |
| 1933 | snd_rawmidi_set_ops(hdspm->midi[id].rmidi, |
| 1934 | SNDRV_RAWMIDI_STREAM_INPUT, |
| 1935 | &snd_hdspm_midi_input); |
| 1936 | |
| 1937 | hdspm->midi[id].rmidi->info_flags |= |
| 1938 | SNDRV_RAWMIDI_INFO_OUTPUT | |
| 1939 | SNDRV_RAWMIDI_INFO_INPUT | |
| 1940 | SNDRV_RAWMIDI_INFO_DUPLEX; |
| 1941 | } else { |
| 1942 | /* TCO MTC, read only */ |
| 1943 | sprintf(buf, "%s MTC %d", card->shortname, id+1); |
| 1944 | err = snd_rawmidi_new(card, buf, id, 1, 1, |
| 1945 | &hdspm->midi[id].rmidi); |
| 1946 | if (err < 0) |
| 1947 | return err; |
| 1948 | |
| 1949 | sprintf(hdspm->midi[id].rmidi->name, |
| 1950 | "%s MTC %d", card->id, id+1); |
| 1951 | hdspm->midi[id].rmidi->private_data = &hdspm->midi[id]; |
| 1952 | |
| 1953 | snd_rawmidi_set_ops(hdspm->midi[id].rmidi, |
| 1954 | SNDRV_RAWMIDI_STREAM_INPUT, |
| 1955 | &snd_hdspm_midi_input); |
| 1956 | |
| 1957 | hdspm->midi[id].rmidi->info_flags |= SNDRV_RAWMIDI_INFO_INPUT; |
| 1958 | } |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1959 | |
| 1960 | return 0; |
| 1961 | } |
| 1962 | |
| 1963 | |
| 1964 | static void hdspm_midi_tasklet(unsigned long arg) |
| 1965 | { |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 1966 | struct hdspm *hdspm = (struct hdspm *)arg; |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 1967 | int i = 0; |
| 1968 | |
| 1969 | while (i < hdspm->midiPorts) { |
| 1970 | if (hdspm->midi[i].pending) |
| 1971 | snd_hdspm_midi_input_read(&hdspm->midi[i]); |
| 1972 | |
| 1973 | i++; |
| 1974 | } |
| 1975 | } |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 1976 | |
| 1977 | |
| 1978 | /*----------------------------------------------------------------------------- |
| 1979 | Status Interface |
| 1980 | ----------------------------------------------------------------------------*/ |
| 1981 | |
| 1982 | /* get the system sample rate which is set */ |
| 1983 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 1984 | |
| 1985 | /** |
| 1986 | * Calculate the real sample rate from the |
| 1987 | * current DDS value. |
| 1988 | **/ |
| 1989 | static int hdspm_get_system_sample_rate(struct hdspm *hdspm) |
| 1990 | { |
| 1991 | unsigned int period, rate; |
| 1992 | |
| 1993 | period = hdspm_read(hdspm, HDSPM_RD_PLL_FREQ); |
| 1994 | rate = hdspm_calc_dds_value(hdspm, period); |
| 1995 | |
| 1996 | return rate; |
| 1997 | } |
| 1998 | |
| 1999 | |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2000 | #define HDSPM_SYSTEM_SAMPLE_RATE(xname, xindex) \ |
Clemens Ladisch | 67ed416 | 2005-07-29 15:32:58 +0200 | [diff] [blame] | 2001 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2002 | .name = xname, \ |
| 2003 | .index = xindex, \ |
| 2004 | .access = SNDRV_CTL_ELEM_ACCESS_READ, \ |
| 2005 | .info = snd_hdspm_info_system_sample_rate, \ |
| 2006 | .get = snd_hdspm_get_system_sample_rate \ |
| 2007 | } |
| 2008 | |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 2009 | static int snd_hdspm_info_system_sample_rate(struct snd_kcontrol *kcontrol, |
| 2010 | struct snd_ctl_elem_info *uinfo) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2011 | { |
| 2012 | uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; |
| 2013 | uinfo->count = 1; |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 2014 | uinfo->value.integer.min = 27000; |
| 2015 | uinfo->value.integer.max = 207000; |
| 2016 | uinfo->value.integer.step = 1; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2017 | return 0; |
| 2018 | } |
| 2019 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 2020 | |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 2021 | static int snd_hdspm_get_system_sample_rate(struct snd_kcontrol *kcontrol, |
| 2022 | struct snd_ctl_elem_value * |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2023 | ucontrol) |
| 2024 | { |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 2025 | struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2026 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 2027 | ucontrol->value.integer.value[0] = hdspm_get_system_sample_rate(hdspm); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2028 | return 0; |
| 2029 | } |
| 2030 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 2031 | |
| 2032 | /** |
| 2033 | * Returns the WordClock sample rate class for the given card. |
| 2034 | **/ |
| 2035 | static int hdspm_get_wc_sample_rate(struct hdspm *hdspm) |
| 2036 | { |
| 2037 | int status; |
| 2038 | |
| 2039 | switch (hdspm->io_type) { |
| 2040 | case RayDAT: |
| 2041 | case AIO: |
| 2042 | status = hdspm_read(hdspm, HDSPM_RD_STATUS_1); |
| 2043 | return (status >> 16) & 0xF; |
| 2044 | break; |
| 2045 | default: |
| 2046 | break; |
| 2047 | } |
| 2048 | |
| 2049 | |
| 2050 | return 0; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2051 | } |
| 2052 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 2053 | |
| 2054 | /** |
| 2055 | * Returns the TCO sample rate class for the given card. |
| 2056 | **/ |
| 2057 | static int hdspm_get_tco_sample_rate(struct hdspm *hdspm) |
| 2058 | { |
| 2059 | int status; |
| 2060 | |
| 2061 | if (hdspm->tco) { |
| 2062 | switch (hdspm->io_type) { |
| 2063 | case RayDAT: |
| 2064 | case AIO: |
| 2065 | status = hdspm_read(hdspm, HDSPM_RD_STATUS_1); |
| 2066 | return (status >> 20) & 0xF; |
| 2067 | break; |
| 2068 | default: |
| 2069 | break; |
| 2070 | } |
| 2071 | } |
| 2072 | |
| 2073 | return 0; |
| 2074 | } |
| 2075 | |
| 2076 | |
| 2077 | /** |
| 2078 | * Returns the SYNC_IN sample rate class for the given card. |
| 2079 | **/ |
| 2080 | static int hdspm_get_sync_in_sample_rate(struct hdspm *hdspm) |
| 2081 | { |
| 2082 | int status; |
| 2083 | |
| 2084 | if (hdspm->tco) { |
| 2085 | switch (hdspm->io_type) { |
| 2086 | case RayDAT: |
| 2087 | case AIO: |
| 2088 | status = hdspm_read(hdspm, HDSPM_RD_STATUS_2); |
| 2089 | return (status >> 12) & 0xF; |
| 2090 | break; |
| 2091 | default: |
| 2092 | break; |
| 2093 | } |
| 2094 | } |
| 2095 | |
| 2096 | return 0; |
| 2097 | } |
| 2098 | |
| 2099 | |
| 2100 | /** |
| 2101 | * Returns the sample rate class for input source <idx> for |
| 2102 | * 'new style' cards like the AIO and RayDAT. |
| 2103 | **/ |
| 2104 | static int hdspm_get_s1_sample_rate(struct hdspm *hdspm, unsigned int idx) |
| 2105 | { |
| 2106 | int status = hdspm_read(hdspm, HDSPM_RD_STATUS_2); |
| 2107 | |
| 2108 | return (status >> (idx*4)) & 0xF; |
| 2109 | } |
| 2110 | |
| 2111 | |
| 2112 | |
| 2113 | #define HDSPM_AUTOSYNC_SAMPLE_RATE(xname, xindex) \ |
| 2114 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ |
| 2115 | .name = xname, \ |
| 2116 | .private_value = xindex, \ |
| 2117 | .access = SNDRV_CTL_ELEM_ACCESS_READ, \ |
| 2118 | .info = snd_hdspm_info_autosync_sample_rate, \ |
| 2119 | .get = snd_hdspm_get_autosync_sample_rate \ |
| 2120 | } |
| 2121 | |
| 2122 | |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 2123 | static int snd_hdspm_info_autosync_sample_rate(struct snd_kcontrol *kcontrol, |
| 2124 | struct snd_ctl_elem_info *uinfo) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2125 | { |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2126 | uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; |
| 2127 | uinfo->count = 1; |
| 2128 | uinfo->value.enumerated.items = 10; |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 2129 | |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2130 | if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items) |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 2131 | uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2132 | strcpy(uinfo->value.enumerated.name, |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 2133 | texts_freq[uinfo->value.enumerated.item]); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2134 | return 0; |
| 2135 | } |
| 2136 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 2137 | |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 2138 | static int snd_hdspm_get_autosync_sample_rate(struct snd_kcontrol *kcontrol, |
| 2139 | struct snd_ctl_elem_value * |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2140 | ucontrol) |
| 2141 | { |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 2142 | struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2143 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 2144 | switch (hdspm->io_type) { |
| 2145 | case RayDAT: |
| 2146 | switch (kcontrol->private_value) { |
| 2147 | case 0: |
| 2148 | ucontrol->value.enumerated.item[0] = |
| 2149 | hdspm_get_wc_sample_rate(hdspm); |
| 2150 | break; |
| 2151 | case 7: |
| 2152 | ucontrol->value.enumerated.item[0] = |
| 2153 | hdspm_get_tco_sample_rate(hdspm); |
| 2154 | break; |
| 2155 | case 8: |
| 2156 | ucontrol->value.enumerated.item[0] = |
| 2157 | hdspm_get_sync_in_sample_rate(hdspm); |
| 2158 | break; |
| 2159 | default: |
| 2160 | ucontrol->value.enumerated.item[0] = |
| 2161 | hdspm_get_s1_sample_rate(hdspm, |
| 2162 | kcontrol->private_value-1); |
| 2163 | } |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2164 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 2165 | case AIO: |
| 2166 | switch (kcontrol->private_value) { |
| 2167 | case 0: /* WC */ |
| 2168 | ucontrol->value.enumerated.item[0] = |
| 2169 | hdspm_get_wc_sample_rate(hdspm); |
| 2170 | break; |
| 2171 | case 4: /* TCO */ |
| 2172 | ucontrol->value.enumerated.item[0] = |
| 2173 | hdspm_get_tco_sample_rate(hdspm); |
| 2174 | break; |
| 2175 | case 5: /* SYNC_IN */ |
| 2176 | ucontrol->value.enumerated.item[0] = |
| 2177 | hdspm_get_sync_in_sample_rate(hdspm); |
| 2178 | break; |
| 2179 | default: |
| 2180 | ucontrol->value.enumerated.item[0] = |
| 2181 | hdspm_get_s1_sample_rate(hdspm, |
| 2182 | ucontrol->id.index-1); |
| 2183 | } |
Adrian Knoth | 7c4a95b | 2011-02-23 11:43:13 +0100 | [diff] [blame] | 2184 | |
| 2185 | case AES32: |
| 2186 | |
| 2187 | switch (kcontrol->private_value) { |
| 2188 | case 0: /* WC */ |
| 2189 | ucontrol->value.enumerated.item[0] = |
| 2190 | hdspm_get_wc_sample_rate(hdspm); |
| 2191 | break; |
| 2192 | case 9: /* TCO */ |
| 2193 | ucontrol->value.enumerated.item[0] = |
| 2194 | hdspm_get_tco_sample_rate(hdspm); |
| 2195 | break; |
| 2196 | case 10: /* SYNC_IN */ |
| 2197 | ucontrol->value.enumerated.item[0] = |
| 2198 | hdspm_get_sync_in_sample_rate(hdspm); |
| 2199 | break; |
| 2200 | default: /* AES1 to AES8 */ |
| 2201 | ucontrol->value.enumerated.item[0] = |
| 2202 | hdspm_get_s1_sample_rate(hdspm, |
| 2203 | kcontrol->private_value-1); |
| 2204 | break; |
| 2205 | |
| 2206 | } |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2207 | default: |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 2208 | break; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2209 | } |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 2210 | |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2211 | return 0; |
| 2212 | } |
| 2213 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 2214 | |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2215 | #define HDSPM_SYSTEM_CLOCK_MODE(xname, xindex) \ |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 2216 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ |
| 2217 | .name = xname, \ |
| 2218 | .index = xindex, \ |
| 2219 | .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |\ |
| 2220 | SNDRV_CTL_ELEM_ACCESS_VOLATILE, \ |
| 2221 | .info = snd_hdspm_info_system_clock_mode, \ |
| 2222 | .get = snd_hdspm_get_system_clock_mode, \ |
| 2223 | .put = snd_hdspm_put_system_clock_mode, \ |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2224 | } |
| 2225 | |
| 2226 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 2227 | /** |
| 2228 | * Returns the system clock mode for the given card. |
| 2229 | * @returns 0 - master, 1 - slave |
| 2230 | **/ |
| 2231 | static int hdspm_system_clock_mode(struct hdspm *hdspm) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2232 | { |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 2233 | switch (hdspm->io_type) { |
| 2234 | case AIO: |
| 2235 | case RayDAT: |
| 2236 | if (hdspm->settings_register & HDSPM_c0Master) |
| 2237 | return 0; |
| 2238 | break; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2239 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 2240 | default: |
| 2241 | if (hdspm->control_register & HDSPM_ClockModeMaster) |
| 2242 | return 0; |
| 2243 | } |
| 2244 | |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2245 | return 1; |
| 2246 | } |
| 2247 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 2248 | |
| 2249 | /** |
| 2250 | * Sets the system clock mode. |
| 2251 | * @param mode 0 - master, 1 - slave |
| 2252 | **/ |
| 2253 | static void hdspm_set_system_clock_mode(struct hdspm *hdspm, int mode) |
| 2254 | { |
| 2255 | switch (hdspm->io_type) { |
| 2256 | case AIO: |
| 2257 | case RayDAT: |
| 2258 | if (0 == mode) |
| 2259 | hdspm->settings_register |= HDSPM_c0Master; |
| 2260 | else |
| 2261 | hdspm->settings_register &= ~HDSPM_c0Master; |
| 2262 | |
| 2263 | hdspm_write(hdspm, HDSPM_WR_SETTINGS, hdspm->settings_register); |
| 2264 | break; |
| 2265 | |
| 2266 | default: |
| 2267 | if (0 == mode) |
| 2268 | hdspm->control_register |= HDSPM_ClockModeMaster; |
| 2269 | else |
| 2270 | hdspm->control_register &= ~HDSPM_ClockModeMaster; |
| 2271 | |
| 2272 | hdspm_write(hdspm, HDSPM_controlRegister, |
| 2273 | hdspm->control_register); |
| 2274 | } |
| 2275 | } |
| 2276 | |
| 2277 | |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 2278 | static int snd_hdspm_info_system_clock_mode(struct snd_kcontrol *kcontrol, |
| 2279 | struct snd_ctl_elem_info *uinfo) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2280 | { |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 2281 | static char *texts[] = { "Master", "AutoSync" }; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2282 | |
| 2283 | uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; |
| 2284 | uinfo->count = 1; |
| 2285 | uinfo->value.enumerated.items = 2; |
| 2286 | if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items) |
| 2287 | uinfo->value.enumerated.item = |
| 2288 | uinfo->value.enumerated.items - 1; |
| 2289 | strcpy(uinfo->value.enumerated.name, |
| 2290 | texts[uinfo->value.enumerated.item]); |
| 2291 | return 0; |
| 2292 | } |
| 2293 | |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 2294 | static int snd_hdspm_get_system_clock_mode(struct snd_kcontrol *kcontrol, |
| 2295 | struct snd_ctl_elem_value *ucontrol) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2296 | { |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 2297 | struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2298 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 2299 | ucontrol->value.enumerated.item[0] = hdspm_system_clock_mode(hdspm); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2300 | return 0; |
| 2301 | } |
| 2302 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 2303 | static int snd_hdspm_put_system_clock_mode(struct snd_kcontrol *kcontrol, |
| 2304 | struct snd_ctl_elem_value *ucontrol) |
| 2305 | { |
| 2306 | struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); |
| 2307 | int val; |
| 2308 | |
| 2309 | if (!snd_hdspm_use_is_exclusive(hdspm)) |
| 2310 | return -EBUSY; |
| 2311 | |
| 2312 | val = ucontrol->value.enumerated.item[0]; |
| 2313 | if (val < 0) |
| 2314 | val = 0; |
| 2315 | else if (val > 1) |
| 2316 | val = 1; |
| 2317 | |
| 2318 | hdspm_set_system_clock_mode(hdspm, val); |
| 2319 | |
| 2320 | return 0; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2321 | } |
| 2322 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 2323 | |
| 2324 | #define HDSPM_INTERNAL_CLOCK(xname, xindex) \ |
| 2325 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ |
| 2326 | .name = xname, \ |
| 2327 | .index = xindex, \ |
| 2328 | .info = snd_hdspm_info_clock_source, \ |
| 2329 | .get = snd_hdspm_get_clock_source, \ |
| 2330 | .put = snd_hdspm_put_clock_source \ |
| 2331 | } |
| 2332 | |
| 2333 | |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 2334 | static int hdspm_clock_source(struct hdspm * hdspm) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2335 | { |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 2336 | switch (hdspm->system_sample_rate) { |
| 2337 | case 32000: return 0; |
| 2338 | case 44100: return 1; |
| 2339 | case 48000: return 2; |
| 2340 | case 64000: return 3; |
| 2341 | case 88200: return 4; |
| 2342 | case 96000: return 5; |
| 2343 | case 128000: return 6; |
| 2344 | case 176400: return 7; |
| 2345 | case 192000: return 8; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2346 | } |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 2347 | |
| 2348 | return -1; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2349 | } |
| 2350 | |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 2351 | static int hdspm_set_clock_source(struct hdspm * hdspm, int mode) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2352 | { |
| 2353 | int rate; |
| 2354 | switch (mode) { |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 2355 | case 0: |
| 2356 | rate = 32000; break; |
| 2357 | case 1: |
| 2358 | rate = 44100; break; |
| 2359 | case 2: |
| 2360 | rate = 48000; break; |
| 2361 | case 3: |
| 2362 | rate = 64000; break; |
| 2363 | case 4: |
| 2364 | rate = 88200; break; |
| 2365 | case 5: |
| 2366 | rate = 96000; break; |
| 2367 | case 6: |
| 2368 | rate = 128000; break; |
| 2369 | case 7: |
| 2370 | rate = 176400; break; |
| 2371 | case 8: |
| 2372 | rate = 192000; break; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2373 | default: |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 2374 | rate = 48000; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2375 | } |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2376 | hdspm_set_rate(hdspm, rate, 1); |
| 2377 | return 0; |
| 2378 | } |
| 2379 | |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 2380 | static int snd_hdspm_info_clock_source(struct snd_kcontrol *kcontrol, |
| 2381 | struct snd_ctl_elem_info *uinfo) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2382 | { |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2383 | uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; |
| 2384 | uinfo->count = 1; |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 2385 | uinfo->value.enumerated.items = 9; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2386 | |
| 2387 | if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items) |
| 2388 | uinfo->value.enumerated.item = |
| 2389 | uinfo->value.enumerated.items - 1; |
| 2390 | |
| 2391 | strcpy(uinfo->value.enumerated.name, |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 2392 | texts_freq[uinfo->value.enumerated.item+1]); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2393 | |
| 2394 | return 0; |
| 2395 | } |
| 2396 | |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 2397 | static int snd_hdspm_get_clock_source(struct snd_kcontrol *kcontrol, |
| 2398 | struct snd_ctl_elem_value *ucontrol) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2399 | { |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 2400 | struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2401 | |
| 2402 | ucontrol->value.enumerated.item[0] = hdspm_clock_source(hdspm); |
| 2403 | return 0; |
| 2404 | } |
| 2405 | |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 2406 | static int snd_hdspm_put_clock_source(struct snd_kcontrol *kcontrol, |
| 2407 | struct snd_ctl_elem_value *ucontrol) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2408 | { |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 2409 | struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2410 | int change; |
| 2411 | int val; |
| 2412 | |
| 2413 | if (!snd_hdspm_use_is_exclusive(hdspm)) |
| 2414 | return -EBUSY; |
| 2415 | val = ucontrol->value.enumerated.item[0]; |
| 2416 | if (val < 0) |
| 2417 | val = 0; |
Remy Bruno | 6534599 | 2007-08-31 12:21:08 +0200 | [diff] [blame] | 2418 | if (val > 9) |
| 2419 | val = 9; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2420 | spin_lock_irq(&hdspm->lock); |
| 2421 | if (val != hdspm_clock_source(hdspm)) |
| 2422 | change = (hdspm_set_clock_source(hdspm, val) == 0) ? 1 : 0; |
| 2423 | else |
| 2424 | change = 0; |
| 2425 | spin_unlock_irq(&hdspm->lock); |
| 2426 | return change; |
| 2427 | } |
| 2428 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 2429 | |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2430 | #define HDSPM_PREF_SYNC_REF(xname, xindex) \ |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 2431 | {.iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ |
| 2432 | .name = xname, \ |
| 2433 | .index = xindex, \ |
| 2434 | .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |\ |
| 2435 | SNDRV_CTL_ELEM_ACCESS_VOLATILE, \ |
| 2436 | .info = snd_hdspm_info_pref_sync_ref, \ |
| 2437 | .get = snd_hdspm_get_pref_sync_ref, \ |
| 2438 | .put = snd_hdspm_put_pref_sync_ref \ |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2439 | } |
| 2440 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 2441 | |
| 2442 | /** |
| 2443 | * Returns the current preferred sync reference setting. |
| 2444 | * The semantics of the return value are depending on the |
| 2445 | * card, please see the comments for clarification. |
| 2446 | **/ |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 2447 | static int hdspm_pref_sync_ref(struct hdspm * hdspm) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2448 | { |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 2449 | switch (hdspm->io_type) { |
| 2450 | case AES32: |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 2451 | switch (hdspm->control_register & HDSPM_SyncRefMask) { |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 2452 | case 0: return 0; /* WC */ |
| 2453 | case HDSPM_SyncRef0: return 1; /* AES 1 */ |
| 2454 | case HDSPM_SyncRef1: return 2; /* AES 2 */ |
| 2455 | case HDSPM_SyncRef1+HDSPM_SyncRef0: return 3; /* AES 3 */ |
| 2456 | case HDSPM_SyncRef2: return 4; /* AES 4 */ |
| 2457 | case HDSPM_SyncRef2+HDSPM_SyncRef0: return 5; /* AES 5 */ |
| 2458 | case HDSPM_SyncRef2+HDSPM_SyncRef1: return 6; /* AES 6 */ |
| 2459 | case HDSPM_SyncRef2+HDSPM_SyncRef1+HDSPM_SyncRef0: |
| 2460 | return 7; /* AES 7 */ |
| 2461 | case HDSPM_SyncRef3: return 8; /* AES 8 */ |
| 2462 | case HDSPM_SyncRef3+HDSPM_SyncRef0: return 9; /* TCO */ |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 2463 | } |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 2464 | break; |
| 2465 | |
| 2466 | case MADI: |
| 2467 | case MADIface: |
| 2468 | if (hdspm->tco) { |
| 2469 | switch (hdspm->control_register & HDSPM_SyncRefMask) { |
| 2470 | case 0: return 0; /* WC */ |
| 2471 | case HDSPM_SyncRef0: return 1; /* MADI */ |
| 2472 | case HDSPM_SyncRef1: return 2; /* TCO */ |
| 2473 | case HDSPM_SyncRef1+HDSPM_SyncRef0: |
| 2474 | return 3; /* SYNC_IN */ |
| 2475 | } |
| 2476 | } else { |
| 2477 | switch (hdspm->control_register & HDSPM_SyncRefMask) { |
| 2478 | case 0: return 0; /* WC */ |
| 2479 | case HDSPM_SyncRef0: return 1; /* MADI */ |
| 2480 | case HDSPM_SyncRef1+HDSPM_SyncRef0: |
| 2481 | return 2; /* SYNC_IN */ |
| 2482 | } |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 2483 | } |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 2484 | break; |
| 2485 | |
| 2486 | case RayDAT: |
| 2487 | if (hdspm->tco) { |
| 2488 | switch ((hdspm->settings_register & |
| 2489 | HDSPM_c0_SyncRefMask) / HDSPM_c0_SyncRef0) { |
| 2490 | case 0: return 0; /* WC */ |
| 2491 | case 3: return 1; /* ADAT 1 */ |
| 2492 | case 4: return 2; /* ADAT 2 */ |
| 2493 | case 5: return 3; /* ADAT 3 */ |
| 2494 | case 6: return 4; /* ADAT 4 */ |
| 2495 | case 1: return 5; /* AES */ |
| 2496 | case 2: return 6; /* SPDIF */ |
| 2497 | case 9: return 7; /* TCO */ |
| 2498 | case 10: return 8; /* SYNC_IN */ |
| 2499 | } |
| 2500 | } else { |
| 2501 | switch ((hdspm->settings_register & |
| 2502 | HDSPM_c0_SyncRefMask) / HDSPM_c0_SyncRef0) { |
| 2503 | case 0: return 0; /* WC */ |
| 2504 | case 3: return 1; /* ADAT 1 */ |
| 2505 | case 4: return 2; /* ADAT 2 */ |
| 2506 | case 5: return 3; /* ADAT 3 */ |
| 2507 | case 6: return 4; /* ADAT 4 */ |
| 2508 | case 1: return 5; /* AES */ |
| 2509 | case 2: return 6; /* SPDIF */ |
| 2510 | case 10: return 7; /* SYNC_IN */ |
| 2511 | } |
| 2512 | } |
| 2513 | |
| 2514 | break; |
| 2515 | |
| 2516 | case AIO: |
| 2517 | if (hdspm->tco) { |
| 2518 | switch ((hdspm->settings_register & |
| 2519 | HDSPM_c0_SyncRefMask) / HDSPM_c0_SyncRef0) { |
| 2520 | case 0: return 0; /* WC */ |
| 2521 | case 3: return 1; /* ADAT */ |
| 2522 | case 1: return 2; /* AES */ |
| 2523 | case 2: return 3; /* SPDIF */ |
| 2524 | case 9: return 4; /* TCO */ |
| 2525 | case 10: return 5; /* SYNC_IN */ |
| 2526 | } |
| 2527 | } else { |
| 2528 | switch ((hdspm->settings_register & |
| 2529 | HDSPM_c0_SyncRefMask) / HDSPM_c0_SyncRef0) { |
| 2530 | case 0: return 0; /* WC */ |
| 2531 | case 3: return 1; /* ADAT */ |
| 2532 | case 1: return 2; /* AES */ |
| 2533 | case 2: return 3; /* SPDIF */ |
| 2534 | case 10: return 4; /* SYNC_IN */ |
| 2535 | } |
| 2536 | } |
| 2537 | |
| 2538 | break; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2539 | } |
| 2540 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 2541 | return -1; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2542 | } |
| 2543 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 2544 | |
| 2545 | /** |
| 2546 | * Set the preferred sync reference to <pref>. The semantics |
| 2547 | * of <pref> are depending on the card type, see the comments |
| 2548 | * for clarification. |
| 2549 | **/ |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 2550 | static int hdspm_set_pref_sync_ref(struct hdspm * hdspm, int pref) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2551 | { |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 2552 | int p = 0; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2553 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 2554 | switch (hdspm->io_type) { |
| 2555 | case AES32: |
| 2556 | hdspm->control_register &= ~HDSPM_SyncRefMask; |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 2557 | switch (pref) { |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 2558 | case 0: /* WC */ |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 2559 | break; |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 2560 | case 1: /* AES 1 */ |
| 2561 | hdspm->control_register |= HDSPM_SyncRef0; |
| 2562 | break; |
| 2563 | case 2: /* AES 2 */ |
| 2564 | hdspm->control_register |= HDSPM_SyncRef1; |
| 2565 | break; |
| 2566 | case 3: /* AES 3 */ |
| 2567 | hdspm->control_register |= |
| 2568 | HDSPM_SyncRef1+HDSPM_SyncRef0; |
| 2569 | break; |
| 2570 | case 4: /* AES 4 */ |
| 2571 | hdspm->control_register |= HDSPM_SyncRef2; |
| 2572 | break; |
| 2573 | case 5: /* AES 5 */ |
| 2574 | hdspm->control_register |= |
| 2575 | HDSPM_SyncRef2+HDSPM_SyncRef0; |
| 2576 | break; |
| 2577 | case 6: /* AES 6 */ |
| 2578 | hdspm->control_register |= |
| 2579 | HDSPM_SyncRef2+HDSPM_SyncRef1; |
| 2580 | break; |
| 2581 | case 7: /* AES 7 */ |
| 2582 | hdspm->control_register |= |
| 2583 | HDSPM_SyncRef2+HDSPM_SyncRef1+HDSPM_SyncRef0; |
| 2584 | break; |
| 2585 | case 8: /* AES 8 */ |
| 2586 | hdspm->control_register |= HDSPM_SyncRef3; |
| 2587 | break; |
| 2588 | case 9: /* TCO */ |
| 2589 | hdspm->control_register |= |
| 2590 | HDSPM_SyncRef3+HDSPM_SyncRef0; |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 2591 | break; |
| 2592 | default: |
| 2593 | return -1; |
| 2594 | } |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 2595 | |
| 2596 | break; |
| 2597 | |
| 2598 | case MADI: |
| 2599 | case MADIface: |
| 2600 | hdspm->control_register &= ~HDSPM_SyncRefMask; |
| 2601 | if (hdspm->tco) { |
| 2602 | switch (pref) { |
| 2603 | case 0: /* WC */ |
| 2604 | break; |
| 2605 | case 1: /* MADI */ |
| 2606 | hdspm->control_register |= HDSPM_SyncRef0; |
| 2607 | break; |
| 2608 | case 2: /* TCO */ |
| 2609 | hdspm->control_register |= HDSPM_SyncRef1; |
| 2610 | break; |
| 2611 | case 3: /* SYNC_IN */ |
| 2612 | hdspm->control_register |= |
| 2613 | HDSPM_SyncRef0+HDSPM_SyncRef1; |
| 2614 | break; |
| 2615 | default: |
| 2616 | return -1; |
| 2617 | } |
| 2618 | } else { |
| 2619 | switch (pref) { |
| 2620 | case 0: /* WC */ |
| 2621 | break; |
| 2622 | case 1: /* MADI */ |
| 2623 | hdspm->control_register |= HDSPM_SyncRef0; |
| 2624 | break; |
| 2625 | case 2: /* SYNC_IN */ |
| 2626 | hdspm->control_register |= |
| 2627 | HDSPM_SyncRef0+HDSPM_SyncRef1; |
| 2628 | break; |
| 2629 | default: |
| 2630 | return -1; |
| 2631 | } |
| 2632 | } |
| 2633 | |
| 2634 | break; |
| 2635 | |
| 2636 | case RayDAT: |
| 2637 | if (hdspm->tco) { |
| 2638 | switch (pref) { |
| 2639 | case 0: p = 0; break; /* WC */ |
| 2640 | case 1: p = 3; break; /* ADAT 1 */ |
| 2641 | case 2: p = 4; break; /* ADAT 2 */ |
| 2642 | case 3: p = 5; break; /* ADAT 3 */ |
| 2643 | case 4: p = 6; break; /* ADAT 4 */ |
| 2644 | case 5: p = 1; break; /* AES */ |
| 2645 | case 6: p = 2; break; /* SPDIF */ |
| 2646 | case 7: p = 9; break; /* TCO */ |
| 2647 | case 8: p = 10; break; /* SYNC_IN */ |
| 2648 | default: return -1; |
| 2649 | } |
| 2650 | } else { |
| 2651 | switch (pref) { |
| 2652 | case 0: p = 0; break; /* WC */ |
| 2653 | case 1: p = 3; break; /* ADAT 1 */ |
| 2654 | case 2: p = 4; break; /* ADAT 2 */ |
| 2655 | case 3: p = 5; break; /* ADAT 3 */ |
| 2656 | case 4: p = 6; break; /* ADAT 4 */ |
| 2657 | case 5: p = 1; break; /* AES */ |
| 2658 | case 6: p = 2; break; /* SPDIF */ |
| 2659 | case 7: p = 10; break; /* SYNC_IN */ |
| 2660 | default: return -1; |
| 2661 | } |
| 2662 | } |
| 2663 | break; |
| 2664 | |
| 2665 | case AIO: |
| 2666 | if (hdspm->tco) { |
| 2667 | switch (pref) { |
| 2668 | case 0: p = 0; break; /* WC */ |
| 2669 | case 1: p = 3; break; /* ADAT */ |
| 2670 | case 2: p = 1; break; /* AES */ |
| 2671 | case 3: p = 2; break; /* SPDIF */ |
| 2672 | case 4: p = 9; break; /* TCO */ |
| 2673 | case 5: p = 10; break; /* SYNC_IN */ |
| 2674 | default: return -1; |
| 2675 | } |
| 2676 | } else { |
| 2677 | switch (pref) { |
| 2678 | case 0: p = 0; break; /* WC */ |
| 2679 | case 1: p = 3; break; /* ADAT */ |
| 2680 | case 2: p = 1; break; /* AES */ |
| 2681 | case 3: p = 2; break; /* SPDIF */ |
| 2682 | case 4: p = 10; break; /* SYNC_IN */ |
| 2683 | default: return -1; |
| 2684 | } |
| 2685 | } |
| 2686 | break; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2687 | } |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 2688 | |
| 2689 | switch (hdspm->io_type) { |
| 2690 | case RayDAT: |
| 2691 | case AIO: |
| 2692 | hdspm->settings_register &= ~HDSPM_c0_SyncRefMask; |
| 2693 | hdspm->settings_register |= HDSPM_c0_SyncRef0 * p; |
| 2694 | hdspm_write(hdspm, HDSPM_WR_SETTINGS, hdspm->settings_register); |
| 2695 | break; |
| 2696 | |
| 2697 | case MADI: |
| 2698 | case MADIface: |
| 2699 | case AES32: |
| 2700 | hdspm_write(hdspm, HDSPM_controlRegister, |
| 2701 | hdspm->control_register); |
| 2702 | } |
| 2703 | |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2704 | return 0; |
| 2705 | } |
| 2706 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 2707 | |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 2708 | static int snd_hdspm_info_pref_sync_ref(struct snd_kcontrol *kcontrol, |
| 2709 | struct snd_ctl_elem_info *uinfo) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2710 | { |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 2711 | struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2712 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 2713 | uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; |
| 2714 | uinfo->count = 1; |
| 2715 | uinfo->value.enumerated.items = hdspm->texts_autosync_items; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2716 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 2717 | if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items) |
| 2718 | uinfo->value.enumerated.item = |
| 2719 | uinfo->value.enumerated.items - 1; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2720 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 2721 | strcpy(uinfo->value.enumerated.name, |
| 2722 | hdspm->texts_autosync[uinfo->value.enumerated.item]); |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 2723 | |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2724 | return 0; |
| 2725 | } |
| 2726 | |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 2727 | static int snd_hdspm_get_pref_sync_ref(struct snd_kcontrol *kcontrol, |
| 2728 | struct snd_ctl_elem_value *ucontrol) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2729 | { |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 2730 | struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 2731 | int psf = hdspm_pref_sync_ref(hdspm); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2732 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 2733 | if (psf >= 0) { |
| 2734 | ucontrol->value.enumerated.item[0] = psf; |
| 2735 | return 0; |
| 2736 | } |
| 2737 | |
| 2738 | return -1; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2739 | } |
| 2740 | |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 2741 | static int snd_hdspm_put_pref_sync_ref(struct snd_kcontrol *kcontrol, |
| 2742 | struct snd_ctl_elem_value *ucontrol) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2743 | { |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 2744 | struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 2745 | int val, change = 0; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2746 | |
| 2747 | if (!snd_hdspm_use_is_exclusive(hdspm)) |
| 2748 | return -EBUSY; |
| 2749 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 2750 | val = ucontrol->value.enumerated.item[0]; |
| 2751 | |
| 2752 | if (val < 0) |
| 2753 | val = 0; |
| 2754 | else if (val >= hdspm->texts_autosync_items) |
| 2755 | val = hdspm->texts_autosync_items-1; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2756 | |
| 2757 | spin_lock_irq(&hdspm->lock); |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 2758 | if (val != hdspm_pref_sync_ref(hdspm)) |
| 2759 | change = (0 == hdspm_set_pref_sync_ref(hdspm, val)) ? 1 : 0; |
| 2760 | |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2761 | spin_unlock_irq(&hdspm->lock); |
| 2762 | return change; |
| 2763 | } |
| 2764 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 2765 | |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2766 | #define HDSPM_AUTOSYNC_REF(xname, xindex) \ |
Clemens Ladisch | 67ed416 | 2005-07-29 15:32:58 +0200 | [diff] [blame] | 2767 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2768 | .name = xname, \ |
| 2769 | .index = xindex, \ |
| 2770 | .access = SNDRV_CTL_ELEM_ACCESS_READ, \ |
| 2771 | .info = snd_hdspm_info_autosync_ref, \ |
| 2772 | .get = snd_hdspm_get_autosync_ref, \ |
| 2773 | } |
| 2774 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 2775 | static int hdspm_autosync_ref(struct hdspm *hdspm) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2776 | { |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 2777 | if (AES32 == hdspm->io_type) { |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 2778 | unsigned int status = hdspm_read(hdspm, HDSPM_statusRegister); |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 2779 | unsigned int syncref = |
| 2780 | (status >> HDSPM_AES32_syncref_bit) & 0xF; |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 2781 | if (syncref == 0) |
| 2782 | return HDSPM_AES32_AUTOSYNC_FROM_WORD; |
| 2783 | if (syncref <= 8) |
| 2784 | return syncref; |
| 2785 | return HDSPM_AES32_AUTOSYNC_FROM_NONE; |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 2786 | } else if (MADI == hdspm->io_type) { |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 2787 | /* This looks at the autosync selected sync reference */ |
| 2788 | unsigned int status2 = hdspm_read(hdspm, HDSPM_statusRegister2); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2789 | |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 2790 | switch (status2 & HDSPM_SelSyncRefMask) { |
| 2791 | case HDSPM_SelSyncRef_WORD: |
| 2792 | return HDSPM_AUTOSYNC_FROM_WORD; |
| 2793 | case HDSPM_SelSyncRef_MADI: |
| 2794 | return HDSPM_AUTOSYNC_FROM_MADI; |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 2795 | case HDSPM_SelSyncRef_TCO: |
| 2796 | return HDSPM_AUTOSYNC_FROM_TCO; |
| 2797 | case HDSPM_SelSyncRef_SyncIn: |
| 2798 | return HDSPM_AUTOSYNC_FROM_SYNC_IN; |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 2799 | case HDSPM_SelSyncRef_NVALID: |
| 2800 | return HDSPM_AUTOSYNC_FROM_NONE; |
| 2801 | default: |
| 2802 | return 0; |
| 2803 | } |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2804 | |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2805 | } |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 2806 | return 0; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2807 | } |
| 2808 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 2809 | |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 2810 | static int snd_hdspm_info_autosync_ref(struct snd_kcontrol *kcontrol, |
| 2811 | struct snd_ctl_elem_info *uinfo) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2812 | { |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 2813 | struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2814 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 2815 | if (AES32 == hdspm->io_type) { |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 2816 | static char *texts[] = { "WordClock", "AES1", "AES2", "AES3", |
| 2817 | "AES4", "AES5", "AES6", "AES7", "AES8", "None"}; |
| 2818 | |
| 2819 | uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; |
| 2820 | uinfo->count = 1; |
| 2821 | uinfo->value.enumerated.items = 10; |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 2822 | if (uinfo->value.enumerated.item >= |
| 2823 | uinfo->value.enumerated.items) |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 2824 | uinfo->value.enumerated.item = |
| 2825 | uinfo->value.enumerated.items - 1; |
| 2826 | strcpy(uinfo->value.enumerated.name, |
| 2827 | texts[uinfo->value.enumerated.item]); |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 2828 | } else if (MADI == hdspm->io_type) { |
| 2829 | static char *texts[] = {"Word Clock", "MADI", "TCO", |
| 2830 | "Sync In", "None" }; |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 2831 | |
| 2832 | uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; |
| 2833 | uinfo->count = 1; |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 2834 | uinfo->value.enumerated.items = 5; |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 2835 | if (uinfo->value.enumerated.item >= |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 2836 | uinfo->value.enumerated.items) |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 2837 | uinfo->value.enumerated.item = |
| 2838 | uinfo->value.enumerated.items - 1; |
| 2839 | strcpy(uinfo->value.enumerated.name, |
| 2840 | texts[uinfo->value.enumerated.item]); |
| 2841 | } |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2842 | return 0; |
| 2843 | } |
| 2844 | |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 2845 | static int snd_hdspm_get_autosync_ref(struct snd_kcontrol *kcontrol, |
| 2846 | struct snd_ctl_elem_value *ucontrol) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2847 | { |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 2848 | struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2849 | |
Remy Bruno | 6534599 | 2007-08-31 12:21:08 +0200 | [diff] [blame] | 2850 | ucontrol->value.enumerated.item[0] = hdspm_autosync_ref(hdspm); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2851 | return 0; |
| 2852 | } |
| 2853 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 2854 | |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2855 | #define HDSPM_LINE_OUT(xname, xindex) \ |
Clemens Ladisch | 67ed416 | 2005-07-29 15:32:58 +0200 | [diff] [blame] | 2856 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2857 | .name = xname, \ |
| 2858 | .index = xindex, \ |
| 2859 | .info = snd_hdspm_info_line_out, \ |
| 2860 | .get = snd_hdspm_get_line_out, \ |
| 2861 | .put = snd_hdspm_put_line_out \ |
| 2862 | } |
| 2863 | |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 2864 | static int hdspm_line_out(struct hdspm * hdspm) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2865 | { |
| 2866 | return (hdspm->control_register & HDSPM_LineOut) ? 1 : 0; |
| 2867 | } |
| 2868 | |
| 2869 | |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 2870 | static int hdspm_set_line_output(struct hdspm * hdspm, int out) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2871 | { |
| 2872 | if (out) |
| 2873 | hdspm->control_register |= HDSPM_LineOut; |
| 2874 | else |
| 2875 | hdspm->control_register &= ~HDSPM_LineOut; |
| 2876 | hdspm_write(hdspm, HDSPM_controlRegister, hdspm->control_register); |
| 2877 | |
| 2878 | return 0; |
| 2879 | } |
| 2880 | |
Takashi Iwai | a5ce889 | 2007-07-23 15:42:26 +0200 | [diff] [blame] | 2881 | #define snd_hdspm_info_line_out snd_ctl_boolean_mono_info |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2882 | |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 2883 | static int snd_hdspm_get_line_out(struct snd_kcontrol *kcontrol, |
| 2884 | struct snd_ctl_elem_value *ucontrol) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2885 | { |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 2886 | struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2887 | |
| 2888 | spin_lock_irq(&hdspm->lock); |
| 2889 | ucontrol->value.integer.value[0] = hdspm_line_out(hdspm); |
| 2890 | spin_unlock_irq(&hdspm->lock); |
| 2891 | return 0; |
| 2892 | } |
| 2893 | |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 2894 | static int snd_hdspm_put_line_out(struct snd_kcontrol *kcontrol, |
| 2895 | struct snd_ctl_elem_value *ucontrol) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2896 | { |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 2897 | struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2898 | int change; |
| 2899 | unsigned int val; |
| 2900 | |
| 2901 | if (!snd_hdspm_use_is_exclusive(hdspm)) |
| 2902 | return -EBUSY; |
| 2903 | val = ucontrol->value.integer.value[0] & 1; |
| 2904 | spin_lock_irq(&hdspm->lock); |
| 2905 | change = (int) val != hdspm_line_out(hdspm); |
| 2906 | hdspm_set_line_output(hdspm, val); |
| 2907 | spin_unlock_irq(&hdspm->lock); |
| 2908 | return change; |
| 2909 | } |
| 2910 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 2911 | |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2912 | #define HDSPM_TX_64(xname, xindex) \ |
Clemens Ladisch | 67ed416 | 2005-07-29 15:32:58 +0200 | [diff] [blame] | 2913 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2914 | .name = xname, \ |
| 2915 | .index = xindex, \ |
| 2916 | .info = snd_hdspm_info_tx_64, \ |
| 2917 | .get = snd_hdspm_get_tx_64, \ |
| 2918 | .put = snd_hdspm_put_tx_64 \ |
| 2919 | } |
| 2920 | |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 2921 | static int hdspm_tx_64(struct hdspm * hdspm) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2922 | { |
| 2923 | return (hdspm->control_register & HDSPM_TX_64ch) ? 1 : 0; |
| 2924 | } |
| 2925 | |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 2926 | static int hdspm_set_tx_64(struct hdspm * hdspm, int out) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2927 | { |
| 2928 | if (out) |
| 2929 | hdspm->control_register |= HDSPM_TX_64ch; |
| 2930 | else |
| 2931 | hdspm->control_register &= ~HDSPM_TX_64ch; |
| 2932 | hdspm_write(hdspm, HDSPM_controlRegister, hdspm->control_register); |
| 2933 | |
| 2934 | return 0; |
| 2935 | } |
| 2936 | |
Takashi Iwai | a5ce889 | 2007-07-23 15:42:26 +0200 | [diff] [blame] | 2937 | #define snd_hdspm_info_tx_64 snd_ctl_boolean_mono_info |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2938 | |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 2939 | static int snd_hdspm_get_tx_64(struct snd_kcontrol *kcontrol, |
| 2940 | struct snd_ctl_elem_value *ucontrol) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2941 | { |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 2942 | struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2943 | |
| 2944 | spin_lock_irq(&hdspm->lock); |
| 2945 | ucontrol->value.integer.value[0] = hdspm_tx_64(hdspm); |
| 2946 | spin_unlock_irq(&hdspm->lock); |
| 2947 | return 0; |
| 2948 | } |
| 2949 | |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 2950 | static int snd_hdspm_put_tx_64(struct snd_kcontrol *kcontrol, |
| 2951 | struct snd_ctl_elem_value *ucontrol) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2952 | { |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 2953 | struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2954 | int change; |
| 2955 | unsigned int val; |
| 2956 | |
| 2957 | if (!snd_hdspm_use_is_exclusive(hdspm)) |
| 2958 | return -EBUSY; |
| 2959 | val = ucontrol->value.integer.value[0] & 1; |
| 2960 | spin_lock_irq(&hdspm->lock); |
| 2961 | change = (int) val != hdspm_tx_64(hdspm); |
| 2962 | hdspm_set_tx_64(hdspm, val); |
| 2963 | spin_unlock_irq(&hdspm->lock); |
| 2964 | return change; |
| 2965 | } |
| 2966 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 2967 | |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2968 | #define HDSPM_C_TMS(xname, xindex) \ |
Clemens Ladisch | 67ed416 | 2005-07-29 15:32:58 +0200 | [diff] [blame] | 2969 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2970 | .name = xname, \ |
| 2971 | .index = xindex, \ |
| 2972 | .info = snd_hdspm_info_c_tms, \ |
| 2973 | .get = snd_hdspm_get_c_tms, \ |
| 2974 | .put = snd_hdspm_put_c_tms \ |
| 2975 | } |
| 2976 | |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 2977 | static int hdspm_c_tms(struct hdspm * hdspm) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2978 | { |
| 2979 | return (hdspm->control_register & HDSPM_clr_tms) ? 1 : 0; |
| 2980 | } |
| 2981 | |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 2982 | static int hdspm_set_c_tms(struct hdspm * hdspm, int out) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2983 | { |
| 2984 | if (out) |
| 2985 | hdspm->control_register |= HDSPM_clr_tms; |
| 2986 | else |
| 2987 | hdspm->control_register &= ~HDSPM_clr_tms; |
| 2988 | hdspm_write(hdspm, HDSPM_controlRegister, hdspm->control_register); |
| 2989 | |
| 2990 | return 0; |
| 2991 | } |
| 2992 | |
Takashi Iwai | a5ce889 | 2007-07-23 15:42:26 +0200 | [diff] [blame] | 2993 | #define snd_hdspm_info_c_tms snd_ctl_boolean_mono_info |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2994 | |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 2995 | static int snd_hdspm_get_c_tms(struct snd_kcontrol *kcontrol, |
| 2996 | struct snd_ctl_elem_value *ucontrol) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2997 | { |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 2998 | struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 2999 | |
| 3000 | spin_lock_irq(&hdspm->lock); |
| 3001 | ucontrol->value.integer.value[0] = hdspm_c_tms(hdspm); |
| 3002 | spin_unlock_irq(&hdspm->lock); |
| 3003 | return 0; |
| 3004 | } |
| 3005 | |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 3006 | static int snd_hdspm_put_c_tms(struct snd_kcontrol *kcontrol, |
| 3007 | struct snd_ctl_elem_value *ucontrol) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 3008 | { |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 3009 | struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 3010 | int change; |
| 3011 | unsigned int val; |
| 3012 | |
| 3013 | if (!snd_hdspm_use_is_exclusive(hdspm)) |
| 3014 | return -EBUSY; |
| 3015 | val = ucontrol->value.integer.value[0] & 1; |
| 3016 | spin_lock_irq(&hdspm->lock); |
| 3017 | change = (int) val != hdspm_c_tms(hdspm); |
| 3018 | hdspm_set_c_tms(hdspm, val); |
| 3019 | spin_unlock_irq(&hdspm->lock); |
| 3020 | return change; |
| 3021 | } |
| 3022 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 3023 | |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 3024 | #define HDSPM_SAFE_MODE(xname, xindex) \ |
Clemens Ladisch | 67ed416 | 2005-07-29 15:32:58 +0200 | [diff] [blame] | 3025 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 3026 | .name = xname, \ |
| 3027 | .index = xindex, \ |
| 3028 | .info = snd_hdspm_info_safe_mode, \ |
| 3029 | .get = snd_hdspm_get_safe_mode, \ |
| 3030 | .put = snd_hdspm_put_safe_mode \ |
| 3031 | } |
| 3032 | |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 3033 | static int hdspm_safe_mode(struct hdspm * hdspm) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 3034 | { |
| 3035 | return (hdspm->control_register & HDSPM_AutoInp) ? 1 : 0; |
| 3036 | } |
| 3037 | |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 3038 | static int hdspm_set_safe_mode(struct hdspm * hdspm, int out) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 3039 | { |
| 3040 | if (out) |
| 3041 | hdspm->control_register |= HDSPM_AutoInp; |
| 3042 | else |
| 3043 | hdspm->control_register &= ~HDSPM_AutoInp; |
| 3044 | hdspm_write(hdspm, HDSPM_controlRegister, hdspm->control_register); |
| 3045 | |
| 3046 | return 0; |
| 3047 | } |
| 3048 | |
Takashi Iwai | a5ce889 | 2007-07-23 15:42:26 +0200 | [diff] [blame] | 3049 | #define snd_hdspm_info_safe_mode snd_ctl_boolean_mono_info |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 3050 | |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 3051 | static int snd_hdspm_get_safe_mode(struct snd_kcontrol *kcontrol, |
| 3052 | struct snd_ctl_elem_value *ucontrol) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 3053 | { |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 3054 | struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 3055 | |
| 3056 | spin_lock_irq(&hdspm->lock); |
| 3057 | ucontrol->value.integer.value[0] = hdspm_safe_mode(hdspm); |
| 3058 | spin_unlock_irq(&hdspm->lock); |
| 3059 | return 0; |
| 3060 | } |
| 3061 | |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 3062 | static int snd_hdspm_put_safe_mode(struct snd_kcontrol *kcontrol, |
| 3063 | struct snd_ctl_elem_value *ucontrol) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 3064 | { |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 3065 | struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 3066 | int change; |
| 3067 | unsigned int val; |
| 3068 | |
| 3069 | if (!snd_hdspm_use_is_exclusive(hdspm)) |
| 3070 | return -EBUSY; |
| 3071 | val = ucontrol->value.integer.value[0] & 1; |
| 3072 | spin_lock_irq(&hdspm->lock); |
| 3073 | change = (int) val != hdspm_safe_mode(hdspm); |
| 3074 | hdspm_set_safe_mode(hdspm, val); |
| 3075 | spin_unlock_irq(&hdspm->lock); |
| 3076 | return change; |
| 3077 | } |
| 3078 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 3079 | |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 3080 | #define HDSPM_EMPHASIS(xname, xindex) \ |
| 3081 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ |
| 3082 | .name = xname, \ |
| 3083 | .index = xindex, \ |
| 3084 | .info = snd_hdspm_info_emphasis, \ |
| 3085 | .get = snd_hdspm_get_emphasis, \ |
| 3086 | .put = snd_hdspm_put_emphasis \ |
| 3087 | } |
| 3088 | |
| 3089 | static int hdspm_emphasis(struct hdspm * hdspm) |
| 3090 | { |
| 3091 | return (hdspm->control_register & HDSPM_Emphasis) ? 1 : 0; |
| 3092 | } |
| 3093 | |
| 3094 | static int hdspm_set_emphasis(struct hdspm * hdspm, int emp) |
| 3095 | { |
| 3096 | if (emp) |
| 3097 | hdspm->control_register |= HDSPM_Emphasis; |
| 3098 | else |
| 3099 | hdspm->control_register &= ~HDSPM_Emphasis; |
| 3100 | hdspm_write(hdspm, HDSPM_controlRegister, hdspm->control_register); |
| 3101 | |
| 3102 | return 0; |
| 3103 | } |
| 3104 | |
Takashi Iwai | a5ce889 | 2007-07-23 15:42:26 +0200 | [diff] [blame] | 3105 | #define snd_hdspm_info_emphasis snd_ctl_boolean_mono_info |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 3106 | |
| 3107 | static int snd_hdspm_get_emphasis(struct snd_kcontrol *kcontrol, |
| 3108 | struct snd_ctl_elem_value *ucontrol) |
| 3109 | { |
| 3110 | struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); |
| 3111 | |
| 3112 | spin_lock_irq(&hdspm->lock); |
| 3113 | ucontrol->value.enumerated.item[0] = hdspm_emphasis(hdspm); |
| 3114 | spin_unlock_irq(&hdspm->lock); |
| 3115 | return 0; |
| 3116 | } |
| 3117 | |
| 3118 | static int snd_hdspm_put_emphasis(struct snd_kcontrol *kcontrol, |
| 3119 | struct snd_ctl_elem_value *ucontrol) |
| 3120 | { |
| 3121 | struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); |
| 3122 | int change; |
| 3123 | unsigned int val; |
| 3124 | |
| 3125 | if (!snd_hdspm_use_is_exclusive(hdspm)) |
| 3126 | return -EBUSY; |
| 3127 | val = ucontrol->value.integer.value[0] & 1; |
| 3128 | spin_lock_irq(&hdspm->lock); |
| 3129 | change = (int) val != hdspm_emphasis(hdspm); |
| 3130 | hdspm_set_emphasis(hdspm, val); |
| 3131 | spin_unlock_irq(&hdspm->lock); |
| 3132 | return change; |
| 3133 | } |
| 3134 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 3135 | |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 3136 | #define HDSPM_DOLBY(xname, xindex) \ |
| 3137 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ |
| 3138 | .name = xname, \ |
| 3139 | .index = xindex, \ |
| 3140 | .info = snd_hdspm_info_dolby, \ |
| 3141 | .get = snd_hdspm_get_dolby, \ |
| 3142 | .put = snd_hdspm_put_dolby \ |
| 3143 | } |
| 3144 | |
| 3145 | static int hdspm_dolby(struct hdspm * hdspm) |
| 3146 | { |
| 3147 | return (hdspm->control_register & HDSPM_Dolby) ? 1 : 0; |
| 3148 | } |
| 3149 | |
| 3150 | static int hdspm_set_dolby(struct hdspm * hdspm, int dol) |
| 3151 | { |
| 3152 | if (dol) |
| 3153 | hdspm->control_register |= HDSPM_Dolby; |
| 3154 | else |
| 3155 | hdspm->control_register &= ~HDSPM_Dolby; |
| 3156 | hdspm_write(hdspm, HDSPM_controlRegister, hdspm->control_register); |
| 3157 | |
| 3158 | return 0; |
| 3159 | } |
| 3160 | |
Takashi Iwai | a5ce889 | 2007-07-23 15:42:26 +0200 | [diff] [blame] | 3161 | #define snd_hdspm_info_dolby snd_ctl_boolean_mono_info |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 3162 | |
| 3163 | static int snd_hdspm_get_dolby(struct snd_kcontrol *kcontrol, |
| 3164 | struct snd_ctl_elem_value *ucontrol) |
| 3165 | { |
| 3166 | struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); |
| 3167 | |
| 3168 | spin_lock_irq(&hdspm->lock); |
| 3169 | ucontrol->value.enumerated.item[0] = hdspm_dolby(hdspm); |
| 3170 | spin_unlock_irq(&hdspm->lock); |
| 3171 | return 0; |
| 3172 | } |
| 3173 | |
| 3174 | static int snd_hdspm_put_dolby(struct snd_kcontrol *kcontrol, |
| 3175 | struct snd_ctl_elem_value *ucontrol) |
| 3176 | { |
| 3177 | struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); |
| 3178 | int change; |
| 3179 | unsigned int val; |
| 3180 | |
| 3181 | if (!snd_hdspm_use_is_exclusive(hdspm)) |
| 3182 | return -EBUSY; |
| 3183 | val = ucontrol->value.integer.value[0] & 1; |
| 3184 | spin_lock_irq(&hdspm->lock); |
| 3185 | change = (int) val != hdspm_dolby(hdspm); |
| 3186 | hdspm_set_dolby(hdspm, val); |
| 3187 | spin_unlock_irq(&hdspm->lock); |
| 3188 | return change; |
| 3189 | } |
| 3190 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 3191 | |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 3192 | #define HDSPM_PROFESSIONAL(xname, xindex) \ |
| 3193 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ |
| 3194 | .name = xname, \ |
| 3195 | .index = xindex, \ |
| 3196 | .info = snd_hdspm_info_professional, \ |
| 3197 | .get = snd_hdspm_get_professional, \ |
| 3198 | .put = snd_hdspm_put_professional \ |
| 3199 | } |
| 3200 | |
| 3201 | static int hdspm_professional(struct hdspm * hdspm) |
| 3202 | { |
| 3203 | return (hdspm->control_register & HDSPM_Professional) ? 1 : 0; |
| 3204 | } |
| 3205 | |
| 3206 | static int hdspm_set_professional(struct hdspm * hdspm, int dol) |
| 3207 | { |
| 3208 | if (dol) |
| 3209 | hdspm->control_register |= HDSPM_Professional; |
| 3210 | else |
| 3211 | hdspm->control_register &= ~HDSPM_Professional; |
| 3212 | hdspm_write(hdspm, HDSPM_controlRegister, hdspm->control_register); |
| 3213 | |
| 3214 | return 0; |
| 3215 | } |
| 3216 | |
Takashi Iwai | a5ce889 | 2007-07-23 15:42:26 +0200 | [diff] [blame] | 3217 | #define snd_hdspm_info_professional snd_ctl_boolean_mono_info |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 3218 | |
| 3219 | static int snd_hdspm_get_professional(struct snd_kcontrol *kcontrol, |
| 3220 | struct snd_ctl_elem_value *ucontrol) |
| 3221 | { |
| 3222 | struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); |
| 3223 | |
| 3224 | spin_lock_irq(&hdspm->lock); |
| 3225 | ucontrol->value.enumerated.item[0] = hdspm_professional(hdspm); |
| 3226 | spin_unlock_irq(&hdspm->lock); |
| 3227 | return 0; |
| 3228 | } |
| 3229 | |
| 3230 | static int snd_hdspm_put_professional(struct snd_kcontrol *kcontrol, |
| 3231 | struct snd_ctl_elem_value *ucontrol) |
| 3232 | { |
| 3233 | struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); |
| 3234 | int change; |
| 3235 | unsigned int val; |
| 3236 | |
| 3237 | if (!snd_hdspm_use_is_exclusive(hdspm)) |
| 3238 | return -EBUSY; |
| 3239 | val = ucontrol->value.integer.value[0] & 1; |
| 3240 | spin_lock_irq(&hdspm->lock); |
| 3241 | change = (int) val != hdspm_professional(hdspm); |
| 3242 | hdspm_set_professional(hdspm, val); |
| 3243 | spin_unlock_irq(&hdspm->lock); |
| 3244 | return change; |
| 3245 | } |
| 3246 | |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 3247 | #define HDSPM_INPUT_SELECT(xname, xindex) \ |
Clemens Ladisch | 67ed416 | 2005-07-29 15:32:58 +0200 | [diff] [blame] | 3248 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 3249 | .name = xname, \ |
| 3250 | .index = xindex, \ |
| 3251 | .info = snd_hdspm_info_input_select, \ |
| 3252 | .get = snd_hdspm_get_input_select, \ |
| 3253 | .put = snd_hdspm_put_input_select \ |
| 3254 | } |
| 3255 | |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 3256 | static int hdspm_input_select(struct hdspm * hdspm) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 3257 | { |
| 3258 | return (hdspm->control_register & HDSPM_InputSelect0) ? 1 : 0; |
| 3259 | } |
| 3260 | |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 3261 | static int hdspm_set_input_select(struct hdspm * hdspm, int out) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 3262 | { |
| 3263 | if (out) |
| 3264 | hdspm->control_register |= HDSPM_InputSelect0; |
| 3265 | else |
| 3266 | hdspm->control_register &= ~HDSPM_InputSelect0; |
| 3267 | hdspm_write(hdspm, HDSPM_controlRegister, hdspm->control_register); |
| 3268 | |
| 3269 | return 0; |
| 3270 | } |
| 3271 | |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 3272 | static int snd_hdspm_info_input_select(struct snd_kcontrol *kcontrol, |
| 3273 | struct snd_ctl_elem_info *uinfo) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 3274 | { |
| 3275 | static char *texts[] = { "optical", "coaxial" }; |
| 3276 | |
| 3277 | uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; |
| 3278 | uinfo->count = 1; |
| 3279 | uinfo->value.enumerated.items = 2; |
| 3280 | |
| 3281 | if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items) |
| 3282 | uinfo->value.enumerated.item = |
| 3283 | uinfo->value.enumerated.items - 1; |
| 3284 | strcpy(uinfo->value.enumerated.name, |
| 3285 | texts[uinfo->value.enumerated.item]); |
| 3286 | |
| 3287 | return 0; |
| 3288 | } |
| 3289 | |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 3290 | static int snd_hdspm_get_input_select(struct snd_kcontrol *kcontrol, |
| 3291 | struct snd_ctl_elem_value *ucontrol) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 3292 | { |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 3293 | struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 3294 | |
| 3295 | spin_lock_irq(&hdspm->lock); |
| 3296 | ucontrol->value.enumerated.item[0] = hdspm_input_select(hdspm); |
| 3297 | spin_unlock_irq(&hdspm->lock); |
| 3298 | return 0; |
| 3299 | } |
| 3300 | |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 3301 | static int snd_hdspm_put_input_select(struct snd_kcontrol *kcontrol, |
| 3302 | struct snd_ctl_elem_value *ucontrol) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 3303 | { |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 3304 | struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 3305 | int change; |
| 3306 | unsigned int val; |
| 3307 | |
| 3308 | if (!snd_hdspm_use_is_exclusive(hdspm)) |
| 3309 | return -EBUSY; |
| 3310 | val = ucontrol->value.integer.value[0] & 1; |
| 3311 | spin_lock_irq(&hdspm->lock); |
| 3312 | change = (int) val != hdspm_input_select(hdspm); |
| 3313 | hdspm_set_input_select(hdspm, val); |
| 3314 | spin_unlock_irq(&hdspm->lock); |
| 3315 | return change; |
| 3316 | } |
| 3317 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 3318 | |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 3319 | #define HDSPM_DS_WIRE(xname, xindex) \ |
| 3320 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ |
| 3321 | .name = xname, \ |
| 3322 | .index = xindex, \ |
| 3323 | .info = snd_hdspm_info_ds_wire, \ |
| 3324 | .get = snd_hdspm_get_ds_wire, \ |
| 3325 | .put = snd_hdspm_put_ds_wire \ |
| 3326 | } |
| 3327 | |
| 3328 | static int hdspm_ds_wire(struct hdspm * hdspm) |
| 3329 | { |
| 3330 | return (hdspm->control_register & HDSPM_DS_DoubleWire) ? 1 : 0; |
| 3331 | } |
| 3332 | |
| 3333 | static int hdspm_set_ds_wire(struct hdspm * hdspm, int ds) |
| 3334 | { |
| 3335 | if (ds) |
| 3336 | hdspm->control_register |= HDSPM_DS_DoubleWire; |
| 3337 | else |
| 3338 | hdspm->control_register &= ~HDSPM_DS_DoubleWire; |
| 3339 | hdspm_write(hdspm, HDSPM_controlRegister, hdspm->control_register); |
| 3340 | |
| 3341 | return 0; |
| 3342 | } |
| 3343 | |
| 3344 | static int snd_hdspm_info_ds_wire(struct snd_kcontrol *kcontrol, |
| 3345 | struct snd_ctl_elem_info *uinfo) |
| 3346 | { |
| 3347 | static char *texts[] = { "Single", "Double" }; |
| 3348 | |
| 3349 | uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; |
| 3350 | uinfo->count = 1; |
| 3351 | uinfo->value.enumerated.items = 2; |
| 3352 | |
| 3353 | if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items) |
| 3354 | uinfo->value.enumerated.item = |
| 3355 | uinfo->value.enumerated.items - 1; |
| 3356 | strcpy(uinfo->value.enumerated.name, |
| 3357 | texts[uinfo->value.enumerated.item]); |
| 3358 | |
| 3359 | return 0; |
| 3360 | } |
| 3361 | |
| 3362 | static int snd_hdspm_get_ds_wire(struct snd_kcontrol *kcontrol, |
| 3363 | struct snd_ctl_elem_value *ucontrol) |
| 3364 | { |
| 3365 | struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); |
| 3366 | |
| 3367 | spin_lock_irq(&hdspm->lock); |
| 3368 | ucontrol->value.enumerated.item[0] = hdspm_ds_wire(hdspm); |
| 3369 | spin_unlock_irq(&hdspm->lock); |
| 3370 | return 0; |
| 3371 | } |
| 3372 | |
| 3373 | static int snd_hdspm_put_ds_wire(struct snd_kcontrol *kcontrol, |
| 3374 | struct snd_ctl_elem_value *ucontrol) |
| 3375 | { |
| 3376 | struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); |
| 3377 | int change; |
| 3378 | unsigned int val; |
| 3379 | |
| 3380 | if (!snd_hdspm_use_is_exclusive(hdspm)) |
| 3381 | return -EBUSY; |
| 3382 | val = ucontrol->value.integer.value[0] & 1; |
| 3383 | spin_lock_irq(&hdspm->lock); |
| 3384 | change = (int) val != hdspm_ds_wire(hdspm); |
| 3385 | hdspm_set_ds_wire(hdspm, val); |
| 3386 | spin_unlock_irq(&hdspm->lock); |
| 3387 | return change; |
| 3388 | } |
| 3389 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 3390 | |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 3391 | #define HDSPM_QS_WIRE(xname, xindex) \ |
| 3392 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ |
| 3393 | .name = xname, \ |
| 3394 | .index = xindex, \ |
| 3395 | .info = snd_hdspm_info_qs_wire, \ |
| 3396 | .get = snd_hdspm_get_qs_wire, \ |
| 3397 | .put = snd_hdspm_put_qs_wire \ |
| 3398 | } |
| 3399 | |
| 3400 | static int hdspm_qs_wire(struct hdspm * hdspm) |
| 3401 | { |
| 3402 | if (hdspm->control_register & HDSPM_QS_DoubleWire) |
| 3403 | return 1; |
| 3404 | if (hdspm->control_register & HDSPM_QS_QuadWire) |
| 3405 | return 2; |
| 3406 | return 0; |
| 3407 | } |
| 3408 | |
| 3409 | static int hdspm_set_qs_wire(struct hdspm * hdspm, int mode) |
| 3410 | { |
| 3411 | hdspm->control_register &= ~(HDSPM_QS_DoubleWire | HDSPM_QS_QuadWire); |
| 3412 | switch (mode) { |
| 3413 | case 0: |
| 3414 | break; |
| 3415 | case 1: |
| 3416 | hdspm->control_register |= HDSPM_QS_DoubleWire; |
| 3417 | break; |
| 3418 | case 2: |
| 3419 | hdspm->control_register |= HDSPM_QS_QuadWire; |
| 3420 | break; |
| 3421 | } |
| 3422 | hdspm_write(hdspm, HDSPM_controlRegister, hdspm->control_register); |
| 3423 | |
| 3424 | return 0; |
| 3425 | } |
| 3426 | |
| 3427 | static int snd_hdspm_info_qs_wire(struct snd_kcontrol *kcontrol, |
| 3428 | struct snd_ctl_elem_info *uinfo) |
| 3429 | { |
| 3430 | static char *texts[] = { "Single", "Double", "Quad" }; |
| 3431 | |
| 3432 | uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; |
| 3433 | uinfo->count = 1; |
| 3434 | uinfo->value.enumerated.items = 3; |
| 3435 | |
| 3436 | if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items) |
| 3437 | uinfo->value.enumerated.item = |
| 3438 | uinfo->value.enumerated.items - 1; |
| 3439 | strcpy(uinfo->value.enumerated.name, |
| 3440 | texts[uinfo->value.enumerated.item]); |
| 3441 | |
| 3442 | return 0; |
| 3443 | } |
| 3444 | |
| 3445 | static int snd_hdspm_get_qs_wire(struct snd_kcontrol *kcontrol, |
| 3446 | struct snd_ctl_elem_value *ucontrol) |
| 3447 | { |
| 3448 | struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); |
| 3449 | |
| 3450 | spin_lock_irq(&hdspm->lock); |
| 3451 | ucontrol->value.enumerated.item[0] = hdspm_qs_wire(hdspm); |
| 3452 | spin_unlock_irq(&hdspm->lock); |
| 3453 | return 0; |
| 3454 | } |
| 3455 | |
| 3456 | static int snd_hdspm_put_qs_wire(struct snd_kcontrol *kcontrol, |
| 3457 | struct snd_ctl_elem_value *ucontrol) |
| 3458 | { |
| 3459 | struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); |
| 3460 | int change; |
| 3461 | int val; |
| 3462 | |
| 3463 | if (!snd_hdspm_use_is_exclusive(hdspm)) |
| 3464 | return -EBUSY; |
| 3465 | val = ucontrol->value.integer.value[0]; |
| 3466 | if (val < 0) |
| 3467 | val = 0; |
| 3468 | if (val > 2) |
| 3469 | val = 2; |
| 3470 | spin_lock_irq(&hdspm->lock); |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 3471 | change = val != hdspm_qs_wire(hdspm); |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 3472 | hdspm_set_qs_wire(hdspm, val); |
| 3473 | spin_unlock_irq(&hdspm->lock); |
| 3474 | return change; |
| 3475 | } |
| 3476 | |
Adrian Knoth | 700d1ef | 2011-07-29 03:11:02 +0200 | [diff] [blame] | 3477 | #define HDSPM_MADI_SPEEDMODE(xname, xindex) \ |
| 3478 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ |
| 3479 | .name = xname, \ |
| 3480 | .index = xindex, \ |
| 3481 | .info = snd_hdspm_info_madi_speedmode, \ |
| 3482 | .get = snd_hdspm_get_madi_speedmode, \ |
| 3483 | .put = snd_hdspm_put_madi_speedmode \ |
| 3484 | } |
| 3485 | |
| 3486 | static int hdspm_madi_speedmode(struct hdspm *hdspm) |
| 3487 | { |
| 3488 | if (hdspm->control_register & HDSPM_QuadSpeed) |
| 3489 | return 2; |
| 3490 | if (hdspm->control_register & HDSPM_DoubleSpeed) |
| 3491 | return 1; |
| 3492 | return 0; |
| 3493 | } |
| 3494 | |
| 3495 | static int hdspm_set_madi_speedmode(struct hdspm *hdspm, int mode) |
| 3496 | { |
| 3497 | hdspm->control_register &= ~(HDSPM_DoubleSpeed | HDSPM_QuadSpeed); |
| 3498 | switch (mode) { |
| 3499 | case 0: |
| 3500 | break; |
| 3501 | case 1: |
| 3502 | hdspm->control_register |= HDSPM_DoubleSpeed; |
| 3503 | break; |
| 3504 | case 2: |
| 3505 | hdspm->control_register |= HDSPM_QuadSpeed; |
| 3506 | break; |
| 3507 | } |
| 3508 | hdspm_write(hdspm, HDSPM_controlRegister, hdspm->control_register); |
| 3509 | |
| 3510 | return 0; |
| 3511 | } |
| 3512 | |
| 3513 | static int snd_hdspm_info_madi_speedmode(struct snd_kcontrol *kcontrol, |
| 3514 | struct snd_ctl_elem_info *uinfo) |
| 3515 | { |
| 3516 | static char *texts[] = { "Single", "Double", "Quad" }; |
| 3517 | |
| 3518 | uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; |
| 3519 | uinfo->count = 1; |
| 3520 | uinfo->value.enumerated.items = 3; |
| 3521 | |
| 3522 | if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items) |
| 3523 | uinfo->value.enumerated.item = |
| 3524 | uinfo->value.enumerated.items - 1; |
| 3525 | strcpy(uinfo->value.enumerated.name, |
| 3526 | texts[uinfo->value.enumerated.item]); |
| 3527 | |
| 3528 | return 0; |
| 3529 | } |
| 3530 | |
| 3531 | static int snd_hdspm_get_madi_speedmode(struct snd_kcontrol *kcontrol, |
| 3532 | struct snd_ctl_elem_value *ucontrol) |
| 3533 | { |
| 3534 | struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); |
| 3535 | |
| 3536 | spin_lock_irq(&hdspm->lock); |
| 3537 | ucontrol->value.enumerated.item[0] = hdspm_madi_speedmode(hdspm); |
| 3538 | spin_unlock_irq(&hdspm->lock); |
| 3539 | return 0; |
| 3540 | } |
| 3541 | |
| 3542 | static int snd_hdspm_put_madi_speedmode(struct snd_kcontrol *kcontrol, |
| 3543 | struct snd_ctl_elem_value *ucontrol) |
| 3544 | { |
| 3545 | struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); |
| 3546 | int change; |
| 3547 | int val; |
| 3548 | |
| 3549 | if (!snd_hdspm_use_is_exclusive(hdspm)) |
| 3550 | return -EBUSY; |
| 3551 | val = ucontrol->value.integer.value[0]; |
| 3552 | if (val < 0) |
| 3553 | val = 0; |
| 3554 | if (val > 2) |
| 3555 | val = 2; |
| 3556 | spin_lock_irq(&hdspm->lock); |
| 3557 | change = val != hdspm_madi_speedmode(hdspm); |
| 3558 | hdspm_set_madi_speedmode(hdspm, val); |
| 3559 | spin_unlock_irq(&hdspm->lock); |
| 3560 | return change; |
| 3561 | } |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 3562 | |
| 3563 | #define HDSPM_MIXER(xname, xindex) \ |
| 3564 | { .iface = SNDRV_CTL_ELEM_IFACE_HWDEP, \ |
| 3565 | .name = xname, \ |
| 3566 | .index = xindex, \ |
Clemens Ladisch | 67ed416 | 2005-07-29 15:32:58 +0200 | [diff] [blame] | 3567 | .device = 0, \ |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 3568 | .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | \ |
| 3569 | SNDRV_CTL_ELEM_ACCESS_VOLATILE, \ |
| 3570 | .info = snd_hdspm_info_mixer, \ |
| 3571 | .get = snd_hdspm_get_mixer, \ |
| 3572 | .put = snd_hdspm_put_mixer \ |
| 3573 | } |
| 3574 | |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 3575 | static int snd_hdspm_info_mixer(struct snd_kcontrol *kcontrol, |
| 3576 | struct snd_ctl_elem_info *uinfo) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 3577 | { |
| 3578 | uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; |
| 3579 | uinfo->count = 3; |
| 3580 | uinfo->value.integer.min = 0; |
| 3581 | uinfo->value.integer.max = 65535; |
| 3582 | uinfo->value.integer.step = 1; |
| 3583 | return 0; |
| 3584 | } |
| 3585 | |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 3586 | static int snd_hdspm_get_mixer(struct snd_kcontrol *kcontrol, |
| 3587 | struct snd_ctl_elem_value *ucontrol) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 3588 | { |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 3589 | struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 3590 | int source; |
| 3591 | int destination; |
| 3592 | |
| 3593 | source = ucontrol->value.integer.value[0]; |
| 3594 | if (source < 0) |
| 3595 | source = 0; |
| 3596 | else if (source >= 2 * HDSPM_MAX_CHANNELS) |
| 3597 | source = 2 * HDSPM_MAX_CHANNELS - 1; |
| 3598 | |
| 3599 | destination = ucontrol->value.integer.value[1]; |
| 3600 | if (destination < 0) |
| 3601 | destination = 0; |
| 3602 | else if (destination >= HDSPM_MAX_CHANNELS) |
| 3603 | destination = HDSPM_MAX_CHANNELS - 1; |
| 3604 | |
| 3605 | spin_lock_irq(&hdspm->lock); |
| 3606 | if (source >= HDSPM_MAX_CHANNELS) |
| 3607 | ucontrol->value.integer.value[2] = |
| 3608 | hdspm_read_pb_gain(hdspm, destination, |
| 3609 | source - HDSPM_MAX_CHANNELS); |
| 3610 | else |
| 3611 | ucontrol->value.integer.value[2] = |
| 3612 | hdspm_read_in_gain(hdspm, destination, source); |
| 3613 | |
| 3614 | spin_unlock_irq(&hdspm->lock); |
| 3615 | |
| 3616 | return 0; |
| 3617 | } |
| 3618 | |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 3619 | static int snd_hdspm_put_mixer(struct snd_kcontrol *kcontrol, |
| 3620 | struct snd_ctl_elem_value *ucontrol) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 3621 | { |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 3622 | struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 3623 | int change; |
| 3624 | int source; |
| 3625 | int destination; |
| 3626 | int gain; |
| 3627 | |
| 3628 | if (!snd_hdspm_use_is_exclusive(hdspm)) |
| 3629 | return -EBUSY; |
| 3630 | |
| 3631 | source = ucontrol->value.integer.value[0]; |
| 3632 | destination = ucontrol->value.integer.value[1]; |
| 3633 | |
| 3634 | if (source < 0 || source >= 2 * HDSPM_MAX_CHANNELS) |
| 3635 | return -1; |
| 3636 | if (destination < 0 || destination >= HDSPM_MAX_CHANNELS) |
| 3637 | return -1; |
| 3638 | |
| 3639 | gain = ucontrol->value.integer.value[2]; |
| 3640 | |
| 3641 | spin_lock_irq(&hdspm->lock); |
| 3642 | |
| 3643 | if (source >= HDSPM_MAX_CHANNELS) |
| 3644 | change = gain != hdspm_read_pb_gain(hdspm, destination, |
| 3645 | source - |
| 3646 | HDSPM_MAX_CHANNELS); |
| 3647 | else |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 3648 | change = gain != hdspm_read_in_gain(hdspm, destination, |
| 3649 | source); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 3650 | |
| 3651 | if (change) { |
| 3652 | if (source >= HDSPM_MAX_CHANNELS) |
| 3653 | hdspm_write_pb_gain(hdspm, destination, |
| 3654 | source - HDSPM_MAX_CHANNELS, |
| 3655 | gain); |
| 3656 | else |
| 3657 | hdspm_write_in_gain(hdspm, destination, source, |
| 3658 | gain); |
| 3659 | } |
| 3660 | spin_unlock_irq(&hdspm->lock); |
| 3661 | |
| 3662 | return change; |
| 3663 | } |
| 3664 | |
| 3665 | /* The simple mixer control(s) provide gain control for the |
| 3666 | basic 1:1 mappings of playback streams to output |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 3667 | streams. |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 3668 | */ |
| 3669 | |
| 3670 | #define HDSPM_PLAYBACK_MIXER \ |
| 3671 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ |
| 3672 | .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_WRITE | \ |
| 3673 | SNDRV_CTL_ELEM_ACCESS_VOLATILE, \ |
| 3674 | .info = snd_hdspm_info_playback_mixer, \ |
| 3675 | .get = snd_hdspm_get_playback_mixer, \ |
| 3676 | .put = snd_hdspm_put_playback_mixer \ |
| 3677 | } |
| 3678 | |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 3679 | static int snd_hdspm_info_playback_mixer(struct snd_kcontrol *kcontrol, |
| 3680 | struct snd_ctl_elem_info *uinfo) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 3681 | { |
| 3682 | uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; |
| 3683 | uinfo->count = 1; |
| 3684 | uinfo->value.integer.min = 0; |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 3685 | uinfo->value.integer.max = 64; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 3686 | uinfo->value.integer.step = 1; |
| 3687 | return 0; |
| 3688 | } |
| 3689 | |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 3690 | static int snd_hdspm_get_playback_mixer(struct snd_kcontrol *kcontrol, |
| 3691 | struct snd_ctl_elem_value *ucontrol) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 3692 | { |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 3693 | struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 3694 | int channel; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 3695 | |
| 3696 | channel = ucontrol->id.index - 1; |
| 3697 | |
Takashi Iwai | da3cec3 | 2008-08-08 17:12:14 +0200 | [diff] [blame] | 3698 | if (snd_BUG_ON(channel < 0 || channel >= HDSPM_MAX_CHANNELS)) |
| 3699 | return -EINVAL; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 3700 | |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 3701 | spin_lock_irq(&hdspm->lock); |
| 3702 | ucontrol->value.integer.value[0] = |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 3703 | (hdspm_read_pb_gain(hdspm, channel, channel)*64)/UNITY_GAIN; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 3704 | spin_unlock_irq(&hdspm->lock); |
| 3705 | |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 3706 | return 0; |
| 3707 | } |
| 3708 | |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 3709 | static int snd_hdspm_put_playback_mixer(struct snd_kcontrol *kcontrol, |
| 3710 | struct snd_ctl_elem_value *ucontrol) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 3711 | { |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 3712 | struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 3713 | int change; |
| 3714 | int channel; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 3715 | int gain; |
| 3716 | |
| 3717 | if (!snd_hdspm_use_is_exclusive(hdspm)) |
| 3718 | return -EBUSY; |
| 3719 | |
| 3720 | channel = ucontrol->id.index - 1; |
| 3721 | |
Takashi Iwai | da3cec3 | 2008-08-08 17:12:14 +0200 | [diff] [blame] | 3722 | if (snd_BUG_ON(channel < 0 || channel >= HDSPM_MAX_CHANNELS)) |
| 3723 | return -EINVAL; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 3724 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 3725 | gain = ucontrol->value.integer.value[0]*UNITY_GAIN/64; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 3726 | |
| 3727 | spin_lock_irq(&hdspm->lock); |
| 3728 | change = |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 3729 | gain != hdspm_read_pb_gain(hdspm, channel, |
| 3730 | channel); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 3731 | if (change) |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 3732 | hdspm_write_pb_gain(hdspm, channel, channel, |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 3733 | gain); |
| 3734 | spin_unlock_irq(&hdspm->lock); |
| 3735 | return change; |
| 3736 | } |
| 3737 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 3738 | #define HDSPM_SYNC_CHECK(xname, xindex) \ |
| 3739 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ |
| 3740 | .name = xname, \ |
| 3741 | .private_value = xindex, \ |
| 3742 | .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE, \ |
| 3743 | .info = snd_hdspm_info_sync_check, \ |
| 3744 | .get = snd_hdspm_get_sync_check \ |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 3745 | } |
| 3746 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 3747 | |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 3748 | static int snd_hdspm_info_sync_check(struct snd_kcontrol *kcontrol, |
| 3749 | struct snd_ctl_elem_info *uinfo) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 3750 | { |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 3751 | static char *texts[] = { "No Lock", "Lock", "Sync", "N/A" }; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 3752 | uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; |
| 3753 | uinfo->count = 1; |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 3754 | uinfo->value.enumerated.items = 4; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 3755 | if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items) |
| 3756 | uinfo->value.enumerated.item = |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 3757 | uinfo->value.enumerated.items - 1; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 3758 | strcpy(uinfo->value.enumerated.name, |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 3759 | texts[uinfo->value.enumerated.item]); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 3760 | return 0; |
| 3761 | } |
| 3762 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 3763 | static int hdspm_wc_sync_check(struct hdspm *hdspm) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 3764 | { |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 3765 | int status, status2; |
| 3766 | |
| 3767 | switch (hdspm->io_type) { |
| 3768 | case AES32: |
| 3769 | status = hdspm_read(hdspm, HDSPM_statusRegister); |
| 3770 | if (status & HDSPM_wcSync) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 3771 | return 2; |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 3772 | else if (status & HDSPM_wcLock) |
| 3773 | return 1; |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 3774 | return 0; |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 3775 | break; |
| 3776 | |
| 3777 | case MADI: |
| 3778 | status2 = hdspm_read(hdspm, HDSPM_statusRegister2); |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 3779 | if (status2 & HDSPM_wcLock) { |
| 3780 | if (status2 & HDSPM_wcSync) |
| 3781 | return 2; |
| 3782 | else |
| 3783 | return 1; |
| 3784 | } |
| 3785 | return 0; |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 3786 | break; |
| 3787 | |
| 3788 | case RayDAT: |
| 3789 | case AIO: |
| 3790 | status = hdspm_read(hdspm, HDSPM_statusRegister); |
| 3791 | |
| 3792 | if (status & 0x2000000) |
| 3793 | return 2; |
| 3794 | else if (status & 0x1000000) |
| 3795 | return 1; |
| 3796 | return 0; |
| 3797 | |
| 3798 | break; |
| 3799 | |
| 3800 | case MADIface: |
| 3801 | break; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 3802 | } |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 3803 | |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 3804 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 3805 | return 3; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 3806 | } |
| 3807 | |
| 3808 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 3809 | static int hdspm_madi_sync_check(struct hdspm *hdspm) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 3810 | { |
| 3811 | int status = hdspm_read(hdspm, HDSPM_statusRegister); |
| 3812 | if (status & HDSPM_madiLock) { |
| 3813 | if (status & HDSPM_madiSync) |
| 3814 | return 2; |
| 3815 | else |
| 3816 | return 1; |
| 3817 | } |
| 3818 | return 0; |
| 3819 | } |
| 3820 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 3821 | |
| 3822 | static int hdspm_s1_sync_check(struct hdspm *hdspm, int idx) |
| 3823 | { |
| 3824 | int status, lock, sync; |
| 3825 | |
| 3826 | status = hdspm_read(hdspm, HDSPM_RD_STATUS_1); |
| 3827 | |
| 3828 | lock = (status & (0x1<<idx)) ? 1 : 0; |
| 3829 | sync = (status & (0x100<<idx)) ? 1 : 0; |
| 3830 | |
| 3831 | if (lock && sync) |
| 3832 | return 2; |
| 3833 | else if (lock) |
| 3834 | return 1; |
| 3835 | return 0; |
| 3836 | } |
| 3837 | |
| 3838 | |
| 3839 | static int hdspm_sync_in_sync_check(struct hdspm *hdspm) |
| 3840 | { |
| 3841 | int status, lock = 0, sync = 0; |
| 3842 | |
| 3843 | switch (hdspm->io_type) { |
| 3844 | case RayDAT: |
| 3845 | case AIO: |
| 3846 | status = hdspm_read(hdspm, HDSPM_RD_STATUS_3); |
| 3847 | lock = (status & 0x400) ? 1 : 0; |
| 3848 | sync = (status & 0x800) ? 1 : 0; |
| 3849 | break; |
| 3850 | |
| 3851 | case MADI: |
| 3852 | case AES32: |
| 3853 | status = hdspm_read(hdspm, HDSPM_statusRegister2); |
Adrian Knoth | a7edbd5 | 2011-02-23 11:43:15 +0100 | [diff] [blame] | 3854 | lock = (status & HDSPM_syncInLock) ? 1 : 0; |
| 3855 | sync = (status & HDSPM_syncInSync) ? 1 : 0; |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 3856 | break; |
| 3857 | |
| 3858 | case MADIface: |
| 3859 | break; |
| 3860 | } |
| 3861 | |
| 3862 | if (lock && sync) |
| 3863 | return 2; |
| 3864 | else if (lock) |
| 3865 | return 1; |
| 3866 | |
| 3867 | return 0; |
| 3868 | } |
| 3869 | |
| 3870 | static int hdspm_aes_sync_check(struct hdspm *hdspm, int idx) |
| 3871 | { |
| 3872 | int status2, lock, sync; |
| 3873 | status2 = hdspm_read(hdspm, HDSPM_statusRegister2); |
| 3874 | |
| 3875 | lock = (status2 & (0x0080 >> idx)) ? 1 : 0; |
| 3876 | sync = (status2 & (0x8000 >> idx)) ? 1 : 0; |
| 3877 | |
| 3878 | if (sync) |
| 3879 | return 2; |
| 3880 | else if (lock) |
| 3881 | return 1; |
| 3882 | return 0; |
| 3883 | } |
| 3884 | |
| 3885 | |
| 3886 | static int hdspm_tco_sync_check(struct hdspm *hdspm) |
| 3887 | { |
| 3888 | int status; |
| 3889 | |
| 3890 | if (hdspm->tco) { |
| 3891 | switch (hdspm->io_type) { |
| 3892 | case MADI: |
| 3893 | case AES32: |
| 3894 | status = hdspm_read(hdspm, HDSPM_statusRegister); |
| 3895 | if (status & HDSPM_tcoLock) { |
| 3896 | if (status & HDSPM_tcoSync) |
| 3897 | return 2; |
| 3898 | else |
| 3899 | return 1; |
| 3900 | } |
| 3901 | return 0; |
| 3902 | |
| 3903 | break; |
| 3904 | |
| 3905 | case RayDAT: |
| 3906 | case AIO: |
| 3907 | status = hdspm_read(hdspm, HDSPM_RD_STATUS_1); |
| 3908 | |
| 3909 | if (status & 0x8000000) |
| 3910 | return 2; /* Sync */ |
| 3911 | if (status & 0x4000000) |
| 3912 | return 1; /* Lock */ |
| 3913 | return 0; /* No signal */ |
| 3914 | break; |
| 3915 | |
| 3916 | default: |
| 3917 | break; |
| 3918 | } |
| 3919 | } |
| 3920 | |
| 3921 | return 3; /* N/A */ |
| 3922 | } |
| 3923 | |
| 3924 | |
| 3925 | static int snd_hdspm_get_sync_check(struct snd_kcontrol *kcontrol, |
| 3926 | struct snd_ctl_elem_value *ucontrol) |
| 3927 | { |
| 3928 | struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); |
| 3929 | int val = -1; |
| 3930 | |
| 3931 | switch (hdspm->io_type) { |
| 3932 | case RayDAT: |
| 3933 | switch (kcontrol->private_value) { |
| 3934 | case 0: /* WC */ |
| 3935 | val = hdspm_wc_sync_check(hdspm); break; |
| 3936 | case 7: /* TCO */ |
| 3937 | val = hdspm_tco_sync_check(hdspm); break; |
| 3938 | case 8: /* SYNC IN */ |
| 3939 | val = hdspm_sync_in_sync_check(hdspm); break; |
| 3940 | default: |
| 3941 | val = hdspm_s1_sync_check(hdspm, ucontrol->id.index-1); |
| 3942 | } |
| 3943 | |
| 3944 | case AIO: |
| 3945 | switch (kcontrol->private_value) { |
| 3946 | case 0: /* WC */ |
| 3947 | val = hdspm_wc_sync_check(hdspm); break; |
| 3948 | case 4: /* TCO */ |
| 3949 | val = hdspm_tco_sync_check(hdspm); break; |
| 3950 | case 5: /* SYNC IN */ |
| 3951 | val = hdspm_sync_in_sync_check(hdspm); break; |
| 3952 | default: |
| 3953 | val = hdspm_s1_sync_check(hdspm, ucontrol->id.index-1); |
| 3954 | } |
| 3955 | |
| 3956 | case MADI: |
| 3957 | switch (kcontrol->private_value) { |
| 3958 | case 0: /* WC */ |
| 3959 | val = hdspm_wc_sync_check(hdspm); break; |
| 3960 | case 1: /* MADI */ |
| 3961 | val = hdspm_madi_sync_check(hdspm); break; |
| 3962 | case 2: /* TCO */ |
| 3963 | val = hdspm_tco_sync_check(hdspm); break; |
| 3964 | case 3: /* SYNC_IN */ |
| 3965 | val = hdspm_sync_in_sync_check(hdspm); break; |
| 3966 | } |
| 3967 | |
| 3968 | case MADIface: |
| 3969 | val = hdspm_madi_sync_check(hdspm); /* MADI */ |
| 3970 | break; |
| 3971 | |
| 3972 | case AES32: |
| 3973 | switch (kcontrol->private_value) { |
| 3974 | case 0: /* WC */ |
| 3975 | val = hdspm_wc_sync_check(hdspm); break; |
| 3976 | case 9: /* TCO */ |
| 3977 | val = hdspm_tco_sync_check(hdspm); break; |
| 3978 | case 10 /* SYNC IN */: |
| 3979 | val = hdspm_sync_in_sync_check(hdspm); break; |
Adrian Knoth | 7c4a95b | 2011-02-23 11:43:13 +0100 | [diff] [blame] | 3980 | default: /* AES1 to AES8 */ |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 3981 | val = hdspm_aes_sync_check(hdspm, |
Adrian Knoth | 7c4a95b | 2011-02-23 11:43:13 +0100 | [diff] [blame] | 3982 | kcontrol->private_value-1); |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 3983 | } |
| 3984 | |
| 3985 | } |
| 3986 | |
| 3987 | if (-1 == val) |
| 3988 | val = 3; |
| 3989 | |
| 3990 | ucontrol->value.enumerated.item[0] = val; |
| 3991 | return 0; |
| 3992 | } |
| 3993 | |
| 3994 | |
| 3995 | |
| 3996 | /** |
| 3997 | * TCO controls |
| 3998 | **/ |
| 3999 | static void hdspm_tco_write(struct hdspm *hdspm) |
| 4000 | { |
| 4001 | unsigned int tc[4] = { 0, 0, 0, 0}; |
| 4002 | |
| 4003 | switch (hdspm->tco->input) { |
| 4004 | case 0: |
| 4005 | tc[2] |= HDSPM_TCO2_set_input_MSB; |
| 4006 | break; |
| 4007 | case 1: |
| 4008 | tc[2] |= HDSPM_TCO2_set_input_LSB; |
| 4009 | break; |
| 4010 | default: |
| 4011 | break; |
| 4012 | } |
| 4013 | |
| 4014 | switch (hdspm->tco->framerate) { |
| 4015 | case 1: |
| 4016 | tc[1] |= HDSPM_TCO1_LTC_Format_LSB; |
| 4017 | break; |
| 4018 | case 2: |
| 4019 | tc[1] |= HDSPM_TCO1_LTC_Format_MSB; |
| 4020 | break; |
| 4021 | case 3: |
| 4022 | tc[1] |= HDSPM_TCO1_LTC_Format_MSB + |
| 4023 | HDSPM_TCO1_set_drop_frame_flag; |
| 4024 | break; |
| 4025 | case 4: |
| 4026 | tc[1] |= HDSPM_TCO1_LTC_Format_LSB + |
| 4027 | HDSPM_TCO1_LTC_Format_MSB; |
| 4028 | break; |
| 4029 | case 5: |
| 4030 | tc[1] |= HDSPM_TCO1_LTC_Format_LSB + |
| 4031 | HDSPM_TCO1_LTC_Format_MSB + |
| 4032 | HDSPM_TCO1_set_drop_frame_flag; |
| 4033 | break; |
| 4034 | default: |
| 4035 | break; |
| 4036 | } |
| 4037 | |
| 4038 | switch (hdspm->tco->wordclock) { |
| 4039 | case 1: |
| 4040 | tc[2] |= HDSPM_TCO2_WCK_IO_ratio_LSB; |
| 4041 | break; |
| 4042 | case 2: |
| 4043 | tc[2] |= HDSPM_TCO2_WCK_IO_ratio_MSB; |
| 4044 | break; |
| 4045 | default: |
| 4046 | break; |
| 4047 | } |
| 4048 | |
| 4049 | switch (hdspm->tco->samplerate) { |
| 4050 | case 1: |
| 4051 | tc[2] |= HDSPM_TCO2_set_freq; |
| 4052 | break; |
| 4053 | case 2: |
| 4054 | tc[2] |= HDSPM_TCO2_set_freq_from_app; |
| 4055 | break; |
| 4056 | default: |
| 4057 | break; |
| 4058 | } |
| 4059 | |
| 4060 | switch (hdspm->tco->pull) { |
| 4061 | case 1: |
| 4062 | tc[2] |= HDSPM_TCO2_set_pull_up; |
| 4063 | break; |
| 4064 | case 2: |
| 4065 | tc[2] |= HDSPM_TCO2_set_pull_down; |
| 4066 | break; |
| 4067 | case 3: |
| 4068 | tc[2] |= HDSPM_TCO2_set_pull_up + HDSPM_TCO2_set_01_4; |
| 4069 | break; |
| 4070 | case 4: |
| 4071 | tc[2] |= HDSPM_TCO2_set_pull_down + HDSPM_TCO2_set_01_4; |
| 4072 | break; |
| 4073 | default: |
| 4074 | break; |
| 4075 | } |
| 4076 | |
| 4077 | if (1 == hdspm->tco->term) { |
| 4078 | tc[2] |= HDSPM_TCO2_set_term_75R; |
| 4079 | } |
| 4080 | |
| 4081 | hdspm_write(hdspm, HDSPM_WR_TCO, tc[0]); |
| 4082 | hdspm_write(hdspm, HDSPM_WR_TCO+4, tc[1]); |
| 4083 | hdspm_write(hdspm, HDSPM_WR_TCO+8, tc[2]); |
| 4084 | hdspm_write(hdspm, HDSPM_WR_TCO+12, tc[3]); |
| 4085 | } |
| 4086 | |
| 4087 | |
| 4088 | #define HDSPM_TCO_SAMPLE_RATE(xname, xindex) \ |
| 4089 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ |
| 4090 | .name = xname, \ |
| 4091 | .index = xindex, \ |
| 4092 | .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |\ |
| 4093 | SNDRV_CTL_ELEM_ACCESS_VOLATILE, \ |
| 4094 | .info = snd_hdspm_info_tco_sample_rate, \ |
| 4095 | .get = snd_hdspm_get_tco_sample_rate, \ |
| 4096 | .put = snd_hdspm_put_tco_sample_rate \ |
| 4097 | } |
| 4098 | |
| 4099 | static int snd_hdspm_info_tco_sample_rate(struct snd_kcontrol *kcontrol, |
| 4100 | struct snd_ctl_elem_info *uinfo) |
| 4101 | { |
| 4102 | static char *texts[] = { "44.1 kHz", "48 kHz" }; |
| 4103 | uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; |
| 4104 | uinfo->count = 1; |
| 4105 | uinfo->value.enumerated.items = 2; |
| 4106 | |
| 4107 | if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items) |
| 4108 | uinfo->value.enumerated.item = |
| 4109 | uinfo->value.enumerated.items - 1; |
| 4110 | |
| 4111 | strcpy(uinfo->value.enumerated.name, |
| 4112 | texts[uinfo->value.enumerated.item]); |
| 4113 | |
| 4114 | return 0; |
| 4115 | } |
| 4116 | |
| 4117 | static int snd_hdspm_get_tco_sample_rate(struct snd_kcontrol *kcontrol, |
| 4118 | struct snd_ctl_elem_value *ucontrol) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 4119 | { |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 4120 | struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 4121 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 4122 | ucontrol->value.enumerated.item[0] = hdspm->tco->samplerate; |
| 4123 | |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 4124 | return 0; |
| 4125 | } |
| 4126 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 4127 | static int snd_hdspm_put_tco_sample_rate(struct snd_kcontrol *kcontrol, |
| 4128 | struct snd_ctl_elem_value *ucontrol) |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 4129 | { |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 4130 | struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); |
| 4131 | |
| 4132 | if (hdspm->tco->samplerate != ucontrol->value.enumerated.item[0]) { |
| 4133 | hdspm->tco->samplerate = ucontrol->value.enumerated.item[0]; |
| 4134 | |
| 4135 | hdspm_tco_write(hdspm); |
| 4136 | |
| 4137 | return 1; |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 4138 | } |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 4139 | |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 4140 | return 0; |
| 4141 | } |
| 4142 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 4143 | |
| 4144 | #define HDSPM_TCO_PULL(xname, xindex) \ |
| 4145 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ |
| 4146 | .name = xname, \ |
| 4147 | .index = xindex, \ |
| 4148 | .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |\ |
| 4149 | SNDRV_CTL_ELEM_ACCESS_VOLATILE, \ |
| 4150 | .info = snd_hdspm_info_tco_pull, \ |
| 4151 | .get = snd_hdspm_get_tco_pull, \ |
| 4152 | .put = snd_hdspm_put_tco_pull \ |
| 4153 | } |
| 4154 | |
| 4155 | static int snd_hdspm_info_tco_pull(struct snd_kcontrol *kcontrol, |
| 4156 | struct snd_ctl_elem_info *uinfo) |
| 4157 | { |
| 4158 | static char *texts[] = { "0", "+ 0.1 %", "- 0.1 %", "+ 4 %", "- 4 %" }; |
| 4159 | uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; |
| 4160 | uinfo->count = 1; |
| 4161 | uinfo->value.enumerated.items = 5; |
| 4162 | |
| 4163 | if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items) |
| 4164 | uinfo->value.enumerated.item = |
| 4165 | uinfo->value.enumerated.items - 1; |
| 4166 | |
| 4167 | strcpy(uinfo->value.enumerated.name, |
| 4168 | texts[uinfo->value.enumerated.item]); |
| 4169 | |
| 4170 | return 0; |
| 4171 | } |
| 4172 | |
| 4173 | static int snd_hdspm_get_tco_pull(struct snd_kcontrol *kcontrol, |
| 4174 | struct snd_ctl_elem_value *ucontrol) |
| 4175 | { |
| 4176 | struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); |
| 4177 | |
| 4178 | ucontrol->value.enumerated.item[0] = hdspm->tco->pull; |
| 4179 | |
| 4180 | return 0; |
| 4181 | } |
| 4182 | |
| 4183 | static int snd_hdspm_put_tco_pull(struct snd_kcontrol *kcontrol, |
| 4184 | struct snd_ctl_elem_value *ucontrol) |
| 4185 | { |
| 4186 | struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); |
| 4187 | |
| 4188 | if (hdspm->tco->pull != ucontrol->value.enumerated.item[0]) { |
| 4189 | hdspm->tco->pull = ucontrol->value.enumerated.item[0]; |
| 4190 | |
| 4191 | hdspm_tco_write(hdspm); |
| 4192 | |
| 4193 | return 1; |
| 4194 | } |
| 4195 | |
| 4196 | return 0; |
| 4197 | } |
| 4198 | |
| 4199 | #define HDSPM_TCO_WCK_CONVERSION(xname, xindex) \ |
| 4200 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ |
| 4201 | .name = xname, \ |
| 4202 | .index = xindex, \ |
| 4203 | .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |\ |
| 4204 | SNDRV_CTL_ELEM_ACCESS_VOLATILE, \ |
| 4205 | .info = snd_hdspm_info_tco_wck_conversion, \ |
| 4206 | .get = snd_hdspm_get_tco_wck_conversion, \ |
| 4207 | .put = snd_hdspm_put_tco_wck_conversion \ |
| 4208 | } |
| 4209 | |
| 4210 | static int snd_hdspm_info_tco_wck_conversion(struct snd_kcontrol *kcontrol, |
| 4211 | struct snd_ctl_elem_info *uinfo) |
| 4212 | { |
| 4213 | static char *texts[] = { "1:1", "44.1 -> 48", "48 -> 44.1" }; |
| 4214 | uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; |
| 4215 | uinfo->count = 1; |
| 4216 | uinfo->value.enumerated.items = 3; |
| 4217 | |
| 4218 | if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items) |
| 4219 | uinfo->value.enumerated.item = |
| 4220 | uinfo->value.enumerated.items - 1; |
| 4221 | |
| 4222 | strcpy(uinfo->value.enumerated.name, |
| 4223 | texts[uinfo->value.enumerated.item]); |
| 4224 | |
| 4225 | return 0; |
| 4226 | } |
| 4227 | |
| 4228 | static int snd_hdspm_get_tco_wck_conversion(struct snd_kcontrol *kcontrol, |
| 4229 | struct snd_ctl_elem_value *ucontrol) |
| 4230 | { |
| 4231 | struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); |
| 4232 | |
| 4233 | ucontrol->value.enumerated.item[0] = hdspm->tco->wordclock; |
| 4234 | |
| 4235 | return 0; |
| 4236 | } |
| 4237 | |
| 4238 | static int snd_hdspm_put_tco_wck_conversion(struct snd_kcontrol *kcontrol, |
| 4239 | struct snd_ctl_elem_value *ucontrol) |
| 4240 | { |
| 4241 | struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); |
| 4242 | |
| 4243 | if (hdspm->tco->wordclock != ucontrol->value.enumerated.item[0]) { |
| 4244 | hdspm->tco->wordclock = ucontrol->value.enumerated.item[0]; |
| 4245 | |
| 4246 | hdspm_tco_write(hdspm); |
| 4247 | |
| 4248 | return 1; |
| 4249 | } |
| 4250 | |
| 4251 | return 0; |
| 4252 | } |
| 4253 | |
| 4254 | |
| 4255 | #define HDSPM_TCO_FRAME_RATE(xname, xindex) \ |
| 4256 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ |
| 4257 | .name = xname, \ |
| 4258 | .index = xindex, \ |
| 4259 | .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |\ |
| 4260 | SNDRV_CTL_ELEM_ACCESS_VOLATILE, \ |
| 4261 | .info = snd_hdspm_info_tco_frame_rate, \ |
| 4262 | .get = snd_hdspm_get_tco_frame_rate, \ |
| 4263 | .put = snd_hdspm_put_tco_frame_rate \ |
| 4264 | } |
| 4265 | |
| 4266 | static int snd_hdspm_info_tco_frame_rate(struct snd_kcontrol *kcontrol, |
| 4267 | struct snd_ctl_elem_info *uinfo) |
| 4268 | { |
| 4269 | static char *texts[] = { "24 fps", "25 fps", "29.97fps", |
| 4270 | "29.97 dfps", "30 fps", "30 dfps" }; |
| 4271 | uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; |
| 4272 | uinfo->count = 1; |
| 4273 | uinfo->value.enumerated.items = 6; |
| 4274 | |
| 4275 | if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items) |
| 4276 | uinfo->value.enumerated.item = |
| 4277 | uinfo->value.enumerated.items - 1; |
| 4278 | |
| 4279 | strcpy(uinfo->value.enumerated.name, |
| 4280 | texts[uinfo->value.enumerated.item]); |
| 4281 | |
| 4282 | return 0; |
| 4283 | } |
| 4284 | |
| 4285 | static int snd_hdspm_get_tco_frame_rate(struct snd_kcontrol *kcontrol, |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 4286 | struct snd_ctl_elem_value *ucontrol) |
| 4287 | { |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 4288 | struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); |
| 4289 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 4290 | ucontrol->value.enumerated.item[0] = hdspm->tco->framerate; |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 4291 | |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 4292 | return 0; |
| 4293 | } |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 4294 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 4295 | static int snd_hdspm_put_tco_frame_rate(struct snd_kcontrol *kcontrol, |
| 4296 | struct snd_ctl_elem_value *ucontrol) |
| 4297 | { |
| 4298 | struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); |
| 4299 | |
| 4300 | if (hdspm->tco->framerate != ucontrol->value.enumerated.item[0]) { |
| 4301 | hdspm->tco->framerate = ucontrol->value.enumerated.item[0]; |
| 4302 | |
| 4303 | hdspm_tco_write(hdspm); |
| 4304 | |
| 4305 | return 1; |
| 4306 | } |
| 4307 | |
| 4308 | return 0; |
| 4309 | } |
| 4310 | |
| 4311 | |
| 4312 | #define HDSPM_TCO_SYNC_SOURCE(xname, xindex) \ |
| 4313 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ |
| 4314 | .name = xname, \ |
| 4315 | .index = xindex, \ |
| 4316 | .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |\ |
| 4317 | SNDRV_CTL_ELEM_ACCESS_VOLATILE, \ |
| 4318 | .info = snd_hdspm_info_tco_sync_source, \ |
| 4319 | .get = snd_hdspm_get_tco_sync_source, \ |
| 4320 | .put = snd_hdspm_put_tco_sync_source \ |
| 4321 | } |
| 4322 | |
| 4323 | static int snd_hdspm_info_tco_sync_source(struct snd_kcontrol *kcontrol, |
| 4324 | struct snd_ctl_elem_info *uinfo) |
| 4325 | { |
| 4326 | static char *texts[] = { "LTC", "Video", "WCK" }; |
| 4327 | uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; |
| 4328 | uinfo->count = 1; |
| 4329 | uinfo->value.enumerated.items = 3; |
| 4330 | |
| 4331 | if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items) |
| 4332 | uinfo->value.enumerated.item = |
| 4333 | uinfo->value.enumerated.items - 1; |
| 4334 | |
| 4335 | strcpy(uinfo->value.enumerated.name, |
| 4336 | texts[uinfo->value.enumerated.item]); |
| 4337 | |
| 4338 | return 0; |
| 4339 | } |
| 4340 | |
| 4341 | static int snd_hdspm_get_tco_sync_source(struct snd_kcontrol *kcontrol, |
| 4342 | struct snd_ctl_elem_value *ucontrol) |
| 4343 | { |
| 4344 | struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); |
| 4345 | |
| 4346 | ucontrol->value.enumerated.item[0] = hdspm->tco->input; |
| 4347 | |
| 4348 | return 0; |
| 4349 | } |
| 4350 | |
| 4351 | static int snd_hdspm_put_tco_sync_source(struct snd_kcontrol *kcontrol, |
| 4352 | struct snd_ctl_elem_value *ucontrol) |
| 4353 | { |
| 4354 | struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); |
| 4355 | |
| 4356 | if (hdspm->tco->input != ucontrol->value.enumerated.item[0]) { |
| 4357 | hdspm->tco->input = ucontrol->value.enumerated.item[0]; |
| 4358 | |
| 4359 | hdspm_tco_write(hdspm); |
| 4360 | |
| 4361 | return 1; |
| 4362 | } |
| 4363 | |
| 4364 | return 0; |
| 4365 | } |
| 4366 | |
| 4367 | |
| 4368 | #define HDSPM_TCO_WORD_TERM(xname, xindex) \ |
| 4369 | { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ |
| 4370 | .name = xname, \ |
| 4371 | .index = xindex, \ |
| 4372 | .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |\ |
| 4373 | SNDRV_CTL_ELEM_ACCESS_VOLATILE, \ |
| 4374 | .info = snd_hdspm_info_tco_word_term, \ |
| 4375 | .get = snd_hdspm_get_tco_word_term, \ |
| 4376 | .put = snd_hdspm_put_tco_word_term \ |
| 4377 | } |
| 4378 | |
| 4379 | static int snd_hdspm_info_tco_word_term(struct snd_kcontrol *kcontrol, |
| 4380 | struct snd_ctl_elem_info *uinfo) |
| 4381 | { |
| 4382 | uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; |
| 4383 | uinfo->count = 1; |
| 4384 | uinfo->value.integer.min = 0; |
| 4385 | uinfo->value.integer.max = 1; |
| 4386 | |
| 4387 | return 0; |
| 4388 | } |
| 4389 | |
| 4390 | |
| 4391 | static int snd_hdspm_get_tco_word_term(struct snd_kcontrol *kcontrol, |
| 4392 | struct snd_ctl_elem_value *ucontrol) |
| 4393 | { |
| 4394 | struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); |
| 4395 | |
| 4396 | ucontrol->value.enumerated.item[0] = hdspm->tco->term; |
| 4397 | |
| 4398 | return 0; |
| 4399 | } |
| 4400 | |
| 4401 | |
| 4402 | static int snd_hdspm_put_tco_word_term(struct snd_kcontrol *kcontrol, |
| 4403 | struct snd_ctl_elem_value *ucontrol) |
| 4404 | { |
| 4405 | struct hdspm *hdspm = snd_kcontrol_chip(kcontrol); |
| 4406 | |
| 4407 | if (hdspm->tco->term != ucontrol->value.enumerated.item[0]) { |
| 4408 | hdspm->tco->term = ucontrol->value.enumerated.item[0]; |
| 4409 | |
| 4410 | hdspm_tco_write(hdspm); |
| 4411 | |
| 4412 | return 1; |
| 4413 | } |
| 4414 | |
| 4415 | return 0; |
| 4416 | } |
| 4417 | |
| 4418 | |
| 4419 | |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 4420 | |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 4421 | static struct snd_kcontrol_new snd_hdspm_controls_madi[] = { |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 4422 | HDSPM_MIXER("Mixer", 0), |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 4423 | HDSPM_INTERNAL_CLOCK("Internal Clock", 0), |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 4424 | HDSPM_SYSTEM_CLOCK_MODE("System Clock Mode", 0), |
| 4425 | HDSPM_PREF_SYNC_REF("Preferred Sync Reference", 0), |
| 4426 | HDSPM_AUTOSYNC_REF("AutoSync Reference", 0), |
| 4427 | HDSPM_SYSTEM_SAMPLE_RATE("System Sample Rate", 0), |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 4428 | HDSPM_SYNC_CHECK("WC SyncCheck", 0), |
| 4429 | HDSPM_SYNC_CHECK("MADI SyncCheck", 1), |
| 4430 | HDSPM_SYNC_CHECK("TCO SyncCHeck", 2), |
| 4431 | HDSPM_SYNC_CHECK("SYNC IN SyncCheck", 3), |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 4432 | HDSPM_LINE_OUT("Line Out", 0), |
| 4433 | HDSPM_TX_64("TX 64 channels mode", 0), |
| 4434 | HDSPM_C_TMS("Clear Track Marker", 0), |
| 4435 | HDSPM_SAFE_MODE("Safe Mode", 0), |
Adrian Knoth | 700d1ef | 2011-07-29 03:11:02 +0200 | [diff] [blame] | 4436 | HDSPM_INPUT_SELECT("Input Select", 0), |
| 4437 | HDSPM_MADI_SPEEDMODE("MADI Speed Mode", 0) |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 4438 | }; |
| 4439 | |
| 4440 | |
| 4441 | static struct snd_kcontrol_new snd_hdspm_controls_madiface[] = { |
| 4442 | HDSPM_MIXER("Mixer", 0), |
| 4443 | HDSPM_INTERNAL_CLOCK("Internal Clock", 0), |
| 4444 | HDSPM_SYSTEM_CLOCK_MODE("System Clock Mode", 0), |
| 4445 | HDSPM_SYSTEM_SAMPLE_RATE("System Sample Rate", 0), |
| 4446 | HDSPM_AUTOSYNC_SAMPLE_RATE("External Rate", 0), |
| 4447 | HDSPM_SYNC_CHECK("MADI SyncCheck", 0), |
| 4448 | HDSPM_TX_64("TX 64 channels mode", 0), |
| 4449 | HDSPM_C_TMS("Clear Track Marker", 0), |
Adrian Knoth | 700d1ef | 2011-07-29 03:11:02 +0200 | [diff] [blame] | 4450 | HDSPM_SAFE_MODE("Safe Mode", 0), |
| 4451 | HDSPM_MADI_SPEEDMODE("MADI Speed Mode", 0) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 4452 | }; |
| 4453 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 4454 | static struct snd_kcontrol_new snd_hdspm_controls_aio[] = { |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 4455 | HDSPM_MIXER("Mixer", 0), |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 4456 | HDSPM_INTERNAL_CLOCK("Internal Clock", 0), |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 4457 | HDSPM_SYSTEM_CLOCK_MODE("System Clock Mode", 0), |
| 4458 | HDSPM_PREF_SYNC_REF("Preferred Sync Reference", 0), |
| 4459 | HDSPM_AUTOSYNC_REF("AutoSync Reference", 0), |
| 4460 | HDSPM_SYSTEM_SAMPLE_RATE("System Sample Rate", 0), |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 4461 | HDSPM_AUTOSYNC_SAMPLE_RATE("External Rate", 0), |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 4462 | HDSPM_SYNC_CHECK("WC SyncCheck", 0), |
| 4463 | HDSPM_SYNC_CHECK("AES SyncCheck", 1), |
| 4464 | HDSPM_SYNC_CHECK("SPDIF SyncCheck", 2), |
| 4465 | HDSPM_SYNC_CHECK("ADAT SyncCheck", 3), |
| 4466 | HDSPM_SYNC_CHECK("TCO SyncCheck", 4), |
| 4467 | HDSPM_SYNC_CHECK("SYNC IN SyncCheck", 5), |
| 4468 | HDSPM_AUTOSYNC_SAMPLE_RATE("WC Frequency", 0), |
| 4469 | HDSPM_AUTOSYNC_SAMPLE_RATE("AES Frequency", 1), |
| 4470 | HDSPM_AUTOSYNC_SAMPLE_RATE("SPDIF Frequency", 2), |
| 4471 | HDSPM_AUTOSYNC_SAMPLE_RATE("ADAT Frequency", 3), |
| 4472 | HDSPM_AUTOSYNC_SAMPLE_RATE("TCO Frequency", 4), |
| 4473 | HDSPM_AUTOSYNC_SAMPLE_RATE("SYNC IN Frequency", 5) |
| 4474 | |
| 4475 | /* |
| 4476 | HDSPM_INPUT_SELECT("Input Select", 0), |
| 4477 | HDSPM_SPDIF_OPTICAL("SPDIF Out Optical", 0), |
| 4478 | HDSPM_PROFESSIONAL("SPDIF Out Professional", 0); |
| 4479 | HDSPM_SPDIF_IN("SPDIF In", 0); |
| 4480 | HDSPM_BREAKOUT_CABLE("Breakout Cable", 0); |
| 4481 | HDSPM_INPUT_LEVEL("Input Level", 0); |
| 4482 | HDSPM_OUTPUT_LEVEL("Output Level", 0); |
| 4483 | HDSPM_PHONES("Phones", 0); |
| 4484 | */ |
| 4485 | }; |
| 4486 | |
| 4487 | static struct snd_kcontrol_new snd_hdspm_controls_raydat[] = { |
| 4488 | HDSPM_MIXER("Mixer", 0), |
| 4489 | HDSPM_INTERNAL_CLOCK("Internal Clock", 0), |
| 4490 | HDSPM_SYSTEM_CLOCK_MODE("Clock Mode", 0), |
| 4491 | HDSPM_PREF_SYNC_REF("Pref Sync Ref", 0), |
| 4492 | HDSPM_SYSTEM_SAMPLE_RATE("System Sample Rate", 0), |
| 4493 | HDSPM_SYNC_CHECK("WC SyncCheck", 0), |
| 4494 | HDSPM_SYNC_CHECK("AES SyncCheck", 1), |
| 4495 | HDSPM_SYNC_CHECK("SPDIF SyncCheck", 2), |
| 4496 | HDSPM_SYNC_CHECK("ADAT1 SyncCheck", 3), |
| 4497 | HDSPM_SYNC_CHECK("ADAT2 SyncCheck", 4), |
| 4498 | HDSPM_SYNC_CHECK("ADAT3 SyncCheck", 5), |
| 4499 | HDSPM_SYNC_CHECK("ADAT4 SyncCheck", 6), |
| 4500 | HDSPM_SYNC_CHECK("TCO SyncCheck", 7), |
| 4501 | HDSPM_SYNC_CHECK("SYNC IN SyncCheck", 8), |
| 4502 | HDSPM_AUTOSYNC_SAMPLE_RATE("WC Frequency", 0), |
| 4503 | HDSPM_AUTOSYNC_SAMPLE_RATE("AES Frequency", 1), |
| 4504 | HDSPM_AUTOSYNC_SAMPLE_RATE("SPDIF Frequency", 2), |
| 4505 | HDSPM_AUTOSYNC_SAMPLE_RATE("ADAT1 Frequency", 3), |
| 4506 | HDSPM_AUTOSYNC_SAMPLE_RATE("ADAT2 Frequency", 4), |
| 4507 | HDSPM_AUTOSYNC_SAMPLE_RATE("ADAT3 Frequency", 5), |
| 4508 | HDSPM_AUTOSYNC_SAMPLE_RATE("ADAT4 Frequency", 6), |
| 4509 | HDSPM_AUTOSYNC_SAMPLE_RATE("TCO Frequency", 7), |
| 4510 | HDSPM_AUTOSYNC_SAMPLE_RATE("SYNC IN Frequency", 8) |
| 4511 | }; |
| 4512 | |
| 4513 | static struct snd_kcontrol_new snd_hdspm_controls_aes32[] = { |
| 4514 | HDSPM_MIXER("Mixer", 0), |
| 4515 | HDSPM_INTERNAL_CLOCK("Internal Clock", 0), |
| 4516 | HDSPM_SYSTEM_CLOCK_MODE("System Clock Mode", 0), |
| 4517 | HDSPM_PREF_SYNC_REF("Preferred Sync Reference", 0), |
| 4518 | HDSPM_AUTOSYNC_REF("AutoSync Reference", 0), |
| 4519 | HDSPM_SYSTEM_SAMPLE_RATE("System Sample Rate", 0), |
| 4520 | HDSPM_AUTOSYNC_SAMPLE_RATE("External Rate", 0), |
| 4521 | HDSPM_SYNC_CHECK("WC Sync Check", 0), |
| 4522 | HDSPM_SYNC_CHECK("AES1 Sync Check", 1), |
| 4523 | HDSPM_SYNC_CHECK("AES2 Sync Check", 2), |
| 4524 | HDSPM_SYNC_CHECK("AES3 Sync Check", 3), |
| 4525 | HDSPM_SYNC_CHECK("AES4 Sync Check", 4), |
| 4526 | HDSPM_SYNC_CHECK("AES5 Sync Check", 5), |
| 4527 | HDSPM_SYNC_CHECK("AES6 Sync Check", 6), |
| 4528 | HDSPM_SYNC_CHECK("AES7 Sync Check", 7), |
| 4529 | HDSPM_SYNC_CHECK("AES8 Sync Check", 8), |
| 4530 | HDSPM_SYNC_CHECK("TCO Sync Check", 9), |
| 4531 | HDSPM_SYNC_CHECK("SYNC IN Sync Check", 10), |
| 4532 | HDSPM_AUTOSYNC_SAMPLE_RATE("WC Frequency", 0), |
| 4533 | HDSPM_AUTOSYNC_SAMPLE_RATE("AES1 Frequency", 1), |
| 4534 | HDSPM_AUTOSYNC_SAMPLE_RATE("AES2 Frequency", 2), |
| 4535 | HDSPM_AUTOSYNC_SAMPLE_RATE("AES3 Frequency", 3), |
| 4536 | HDSPM_AUTOSYNC_SAMPLE_RATE("AES4 Frequency", 4), |
| 4537 | HDSPM_AUTOSYNC_SAMPLE_RATE("AES5 Frequency", 5), |
| 4538 | HDSPM_AUTOSYNC_SAMPLE_RATE("AES6 Frequency", 6), |
| 4539 | HDSPM_AUTOSYNC_SAMPLE_RATE("AES7 Frequency", 7), |
| 4540 | HDSPM_AUTOSYNC_SAMPLE_RATE("AES8 Frequency", 8), |
| 4541 | HDSPM_AUTOSYNC_SAMPLE_RATE("TCO Frequency", 9), |
| 4542 | HDSPM_AUTOSYNC_SAMPLE_RATE("SYNC IN Frequency", 10), |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 4543 | HDSPM_LINE_OUT("Line Out", 0), |
| 4544 | HDSPM_EMPHASIS("Emphasis", 0), |
| 4545 | HDSPM_DOLBY("Non Audio", 0), |
| 4546 | HDSPM_PROFESSIONAL("Professional", 0), |
| 4547 | HDSPM_C_TMS("Clear Track Marker", 0), |
| 4548 | HDSPM_DS_WIRE("Double Speed Wire Mode", 0), |
| 4549 | HDSPM_QS_WIRE("Quad Speed Wire Mode", 0), |
| 4550 | }; |
| 4551 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 4552 | |
| 4553 | |
| 4554 | /* Control elements for the optional TCO module */ |
| 4555 | static struct snd_kcontrol_new snd_hdspm_controls_tco[] = { |
| 4556 | HDSPM_TCO_SAMPLE_RATE("TCO Sample Rate", 0), |
| 4557 | HDSPM_TCO_PULL("TCO Pull", 0), |
| 4558 | HDSPM_TCO_WCK_CONVERSION("TCO WCK Conversion", 0), |
| 4559 | HDSPM_TCO_FRAME_RATE("TCO Frame Rate", 0), |
| 4560 | HDSPM_TCO_SYNC_SOURCE("TCO Sync Source", 0), |
| 4561 | HDSPM_TCO_WORD_TERM("TCO Word Term", 0) |
| 4562 | }; |
| 4563 | |
| 4564 | |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 4565 | static struct snd_kcontrol_new snd_hdspm_playback_mixer = HDSPM_PLAYBACK_MIXER; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 4566 | |
| 4567 | |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 4568 | static int hdspm_update_simple_mixer_controls(struct hdspm * hdspm) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 4569 | { |
| 4570 | int i; |
| 4571 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 4572 | for (i = hdspm->ds_out_channels; i < hdspm->ss_out_channels; ++i) { |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 4573 | if (hdspm->system_sample_rate > 48000) { |
| 4574 | hdspm->playback_mixer_ctls[i]->vd[0].access = |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 4575 | SNDRV_CTL_ELEM_ACCESS_INACTIVE | |
| 4576 | SNDRV_CTL_ELEM_ACCESS_READ | |
| 4577 | SNDRV_CTL_ELEM_ACCESS_VOLATILE; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 4578 | } else { |
| 4579 | hdspm->playback_mixer_ctls[i]->vd[0].access = |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 4580 | SNDRV_CTL_ELEM_ACCESS_READWRITE | |
| 4581 | SNDRV_CTL_ELEM_ACCESS_VOLATILE; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 4582 | } |
| 4583 | snd_ctl_notify(hdspm->card, SNDRV_CTL_EVENT_MASK_VALUE | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 4584 | SNDRV_CTL_EVENT_MASK_INFO, |
| 4585 | &hdspm->playback_mixer_ctls[i]->id); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 4586 | } |
| 4587 | |
| 4588 | return 0; |
| 4589 | } |
| 4590 | |
| 4591 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 4592 | static int snd_hdspm_create_controls(struct snd_card *card, |
| 4593 | struct hdspm *hdspm) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 4594 | { |
| 4595 | unsigned int idx, limit; |
| 4596 | int err; |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 4597 | struct snd_kcontrol *kctl; |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 4598 | struct snd_kcontrol_new *list = NULL; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 4599 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 4600 | switch (hdspm->io_type) { |
| 4601 | case MADI: |
| 4602 | list = snd_hdspm_controls_madi; |
| 4603 | limit = ARRAY_SIZE(snd_hdspm_controls_madi); |
| 4604 | break; |
| 4605 | case MADIface: |
| 4606 | list = snd_hdspm_controls_madiface; |
| 4607 | limit = ARRAY_SIZE(snd_hdspm_controls_madiface); |
| 4608 | break; |
| 4609 | case AIO: |
| 4610 | list = snd_hdspm_controls_aio; |
| 4611 | limit = ARRAY_SIZE(snd_hdspm_controls_aio); |
| 4612 | break; |
| 4613 | case RayDAT: |
| 4614 | list = snd_hdspm_controls_raydat; |
| 4615 | limit = ARRAY_SIZE(snd_hdspm_controls_raydat); |
| 4616 | break; |
| 4617 | case AES32: |
| 4618 | list = snd_hdspm_controls_aes32; |
| 4619 | limit = ARRAY_SIZE(snd_hdspm_controls_aes32); |
| 4620 | break; |
| 4621 | } |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 4622 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 4623 | if (NULL != list) { |
| 4624 | for (idx = 0; idx < limit; idx++) { |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 4625 | err = snd_ctl_add(card, |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 4626 | snd_ctl_new1(&list[idx], hdspm)); |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 4627 | if (err < 0) |
| 4628 | return err; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 4629 | } |
| 4630 | } |
| 4631 | |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 4632 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 4633 | /* create simple 1:1 playback mixer controls */ |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 4634 | snd_hdspm_playback_mixer.name = "Chn"; |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 4635 | if (hdspm->system_sample_rate >= 128000) { |
| 4636 | limit = hdspm->qs_out_channels; |
| 4637 | } else if (hdspm->system_sample_rate >= 64000) { |
| 4638 | limit = hdspm->ds_out_channels; |
| 4639 | } else { |
| 4640 | limit = hdspm->ss_out_channels; |
| 4641 | } |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 4642 | for (idx = 0; idx < limit; ++idx) { |
| 4643 | snd_hdspm_playback_mixer.index = idx + 1; |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 4644 | kctl = snd_ctl_new1(&snd_hdspm_playback_mixer, hdspm); |
| 4645 | err = snd_ctl_add(card, kctl); |
| 4646 | if (err < 0) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 4647 | return err; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 4648 | hdspm->playback_mixer_ctls[idx] = kctl; |
| 4649 | } |
| 4650 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 4651 | |
| 4652 | if (hdspm->tco) { |
| 4653 | /* add tco control elements */ |
| 4654 | list = snd_hdspm_controls_tco; |
| 4655 | limit = ARRAY_SIZE(snd_hdspm_controls_tco); |
| 4656 | for (idx = 0; idx < limit; idx++) { |
| 4657 | err = snd_ctl_add(card, |
| 4658 | snd_ctl_new1(&list[idx], hdspm)); |
| 4659 | if (err < 0) |
| 4660 | return err; |
| 4661 | } |
| 4662 | } |
| 4663 | |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 4664 | return 0; |
| 4665 | } |
| 4666 | |
| 4667 | /*------------------------------------------------------------ |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 4668 | /proc interface |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 4669 | ------------------------------------------------------------*/ |
| 4670 | |
| 4671 | static void |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 4672 | snd_hdspm_proc_read_madi(struct snd_info_entry * entry, |
| 4673 | struct snd_info_buffer *buffer) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 4674 | { |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 4675 | struct hdspm *hdspm = entry->private_data; |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 4676 | unsigned int status, status2, control, freq; |
| 4677 | |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 4678 | char *pref_sync_ref; |
| 4679 | char *autosync_ref; |
| 4680 | char *system_clock_mode; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 4681 | char *insel; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 4682 | int x, x2; |
| 4683 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 4684 | /* TCO stuff */ |
| 4685 | int a, ltc, frames, seconds, minutes, hours; |
| 4686 | unsigned int period; |
| 4687 | u64 freq_const = 0; |
| 4688 | u32 rate; |
| 4689 | |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 4690 | status = hdspm_read(hdspm, HDSPM_statusRegister); |
| 4691 | status2 = hdspm_read(hdspm, HDSPM_statusRegister2); |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 4692 | control = hdspm->control_register; |
| 4693 | freq = hdspm_read(hdspm, HDSPM_timecodeRegister); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 4694 | |
| 4695 | snd_iprintf(buffer, "%s (Card #%d) Rev.%x Status2first3bits: %x\n", |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 4696 | hdspm->card_name, hdspm->card->number + 1, |
| 4697 | hdspm->firmware_rev, |
| 4698 | (status2 & HDSPM_version0) | |
| 4699 | (status2 & HDSPM_version1) | (status2 & |
| 4700 | HDSPM_version2)); |
| 4701 | |
| 4702 | snd_iprintf(buffer, "HW Serial: 0x%06x%06x\n", |
| 4703 | (hdspm_read(hdspm, HDSPM_midiStatusIn1)>>8) & 0xFFFFFF, |
| 4704 | (hdspm_read(hdspm, HDSPM_midiStatusIn0)>>8) & 0xFFFFFF); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 4705 | |
| 4706 | snd_iprintf(buffer, "IRQ: %d Registers bus: 0x%lx VM: 0x%lx\n", |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 4707 | hdspm->irq, hdspm->port, (unsigned long)hdspm->iobase); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 4708 | |
| 4709 | snd_iprintf(buffer, "--- System ---\n"); |
| 4710 | |
| 4711 | snd_iprintf(buffer, |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 4712 | "IRQ Pending: Audio=%d, MIDI0=%d, MIDI1=%d, IRQcount=%d\n", |
| 4713 | status & HDSPM_audioIRQPending, |
| 4714 | (status & HDSPM_midi0IRQPending) ? 1 : 0, |
| 4715 | (status & HDSPM_midi1IRQPending) ? 1 : 0, |
| 4716 | hdspm->irq_count); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 4717 | snd_iprintf(buffer, |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 4718 | "HW pointer: id = %d, rawptr = %d (%d->%d) " |
| 4719 | "estimated= %ld (bytes)\n", |
| 4720 | ((status & HDSPM_BufferID) ? 1 : 0), |
| 4721 | (status & HDSPM_BufferPositionMask), |
| 4722 | (status & HDSPM_BufferPositionMask) % |
| 4723 | (2 * (int)hdspm->period_bytes), |
| 4724 | ((status & HDSPM_BufferPositionMask) - 64) % |
| 4725 | (2 * (int)hdspm->period_bytes), |
| 4726 | (long) hdspm_hw_pointer(hdspm) * 4); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 4727 | |
| 4728 | snd_iprintf(buffer, |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 4729 | "MIDI FIFO: Out1=0x%x, Out2=0x%x, In1=0x%x, In2=0x%x \n", |
| 4730 | hdspm_read(hdspm, HDSPM_midiStatusOut0) & 0xFF, |
| 4731 | hdspm_read(hdspm, HDSPM_midiStatusOut1) & 0xFF, |
| 4732 | hdspm_read(hdspm, HDSPM_midiStatusIn0) & 0xFF, |
| 4733 | hdspm_read(hdspm, HDSPM_midiStatusIn1) & 0xFF); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 4734 | snd_iprintf(buffer, |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 4735 | "MIDIoverMADI FIFO: In=0x%x, Out=0x%x \n", |
| 4736 | hdspm_read(hdspm, HDSPM_midiStatusIn2) & 0xFF, |
| 4737 | hdspm_read(hdspm, HDSPM_midiStatusOut2) & 0xFF); |
| 4738 | snd_iprintf(buffer, |
| 4739 | "Register: ctrl1=0x%x, ctrl2=0x%x, status1=0x%x, " |
| 4740 | "status2=0x%x\n", |
| 4741 | hdspm->control_register, hdspm->control2_register, |
| 4742 | status, status2); |
| 4743 | if (status & HDSPM_tco_detect) { |
| 4744 | snd_iprintf(buffer, "TCO module detected.\n"); |
| 4745 | a = hdspm_read(hdspm, HDSPM_RD_TCO+4); |
| 4746 | if (a & HDSPM_TCO1_LTC_Input_valid) { |
| 4747 | snd_iprintf(buffer, " LTC valid, "); |
| 4748 | switch (a & (HDSPM_TCO1_LTC_Format_LSB | |
| 4749 | HDSPM_TCO1_LTC_Format_MSB)) { |
| 4750 | case 0: |
| 4751 | snd_iprintf(buffer, "24 fps, "); |
| 4752 | break; |
| 4753 | case HDSPM_TCO1_LTC_Format_LSB: |
| 4754 | snd_iprintf(buffer, "25 fps, "); |
| 4755 | break; |
| 4756 | case HDSPM_TCO1_LTC_Format_MSB: |
| 4757 | snd_iprintf(buffer, "29.97 fps, "); |
| 4758 | break; |
| 4759 | default: |
| 4760 | snd_iprintf(buffer, "30 fps, "); |
| 4761 | break; |
| 4762 | } |
| 4763 | if (a & HDSPM_TCO1_set_drop_frame_flag) { |
| 4764 | snd_iprintf(buffer, "drop frame\n"); |
| 4765 | } else { |
| 4766 | snd_iprintf(buffer, "full frame\n"); |
| 4767 | } |
| 4768 | } else { |
| 4769 | snd_iprintf(buffer, " no LTC\n"); |
| 4770 | } |
| 4771 | if (a & HDSPM_TCO1_Video_Input_Format_NTSC) { |
| 4772 | snd_iprintf(buffer, " Video: NTSC\n"); |
| 4773 | } else if (a & HDSPM_TCO1_Video_Input_Format_PAL) { |
| 4774 | snd_iprintf(buffer, " Video: PAL\n"); |
| 4775 | } else { |
| 4776 | snd_iprintf(buffer, " No video\n"); |
| 4777 | } |
| 4778 | if (a & HDSPM_TCO1_TCO_lock) { |
| 4779 | snd_iprintf(buffer, " Sync: lock\n"); |
| 4780 | } else { |
| 4781 | snd_iprintf(buffer, " Sync: no lock\n"); |
| 4782 | } |
| 4783 | |
| 4784 | switch (hdspm->io_type) { |
| 4785 | case MADI: |
| 4786 | case AES32: |
| 4787 | freq_const = 110069313433624ULL; |
| 4788 | break; |
| 4789 | case RayDAT: |
| 4790 | case AIO: |
| 4791 | freq_const = 104857600000000ULL; |
| 4792 | break; |
| 4793 | case MADIface: |
| 4794 | break; /* no TCO possible */ |
| 4795 | } |
| 4796 | |
| 4797 | period = hdspm_read(hdspm, HDSPM_RD_PLL_FREQ); |
| 4798 | snd_iprintf(buffer, " period: %u\n", period); |
| 4799 | |
| 4800 | |
| 4801 | /* rate = freq_const/period; */ |
| 4802 | rate = div_u64(freq_const, period); |
| 4803 | |
| 4804 | if (control & HDSPM_QuadSpeed) { |
| 4805 | rate *= 4; |
| 4806 | } else if (control & HDSPM_DoubleSpeed) { |
| 4807 | rate *= 2; |
| 4808 | } |
| 4809 | |
| 4810 | snd_iprintf(buffer, " Frequency: %u Hz\n", |
| 4811 | (unsigned int) rate); |
| 4812 | |
| 4813 | ltc = hdspm_read(hdspm, HDSPM_RD_TCO); |
| 4814 | frames = ltc & 0xF; |
| 4815 | ltc >>= 4; |
| 4816 | frames += (ltc & 0x3) * 10; |
| 4817 | ltc >>= 4; |
| 4818 | seconds = ltc & 0xF; |
| 4819 | ltc >>= 4; |
| 4820 | seconds += (ltc & 0x7) * 10; |
| 4821 | ltc >>= 4; |
| 4822 | minutes = ltc & 0xF; |
| 4823 | ltc >>= 4; |
| 4824 | minutes += (ltc & 0x7) * 10; |
| 4825 | ltc >>= 4; |
| 4826 | hours = ltc & 0xF; |
| 4827 | ltc >>= 4; |
| 4828 | hours += (ltc & 0x3) * 10; |
| 4829 | snd_iprintf(buffer, |
| 4830 | " LTC In: %02d:%02d:%02d:%02d\n", |
| 4831 | hours, minutes, seconds, frames); |
| 4832 | |
| 4833 | } else { |
| 4834 | snd_iprintf(buffer, "No TCO module detected.\n"); |
| 4835 | } |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 4836 | |
| 4837 | snd_iprintf(buffer, "--- Settings ---\n"); |
| 4838 | |
Adrian Knoth | 7cb155f | 2011-08-15 00:22:53 +0200 | [diff] [blame] | 4839 | x = hdspm_get_latency(hdspm); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 4840 | |
| 4841 | snd_iprintf(buffer, |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 4842 | "Size (Latency): %d samples (2 periods of %lu bytes)\n", |
| 4843 | x, (unsigned long) hdspm->period_bytes); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 4844 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 4845 | snd_iprintf(buffer, "Line out: %s\n", |
| 4846 | (hdspm->control_register & HDSPM_LineOut) ? "on " : "off"); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 4847 | |
| 4848 | switch (hdspm->control_register & HDSPM_InputMask) { |
| 4849 | case HDSPM_InputOptical: |
| 4850 | insel = "Optical"; |
| 4851 | break; |
| 4852 | case HDSPM_InputCoaxial: |
| 4853 | insel = "Coaxial"; |
| 4854 | break; |
| 4855 | default: |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 4856 | insel = "Unkown"; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 4857 | } |
| 4858 | |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 4859 | snd_iprintf(buffer, |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 4860 | "ClearTrackMarker = %s, Transmit in %s Channel Mode, " |
| 4861 | "Auto Input %s\n", |
| 4862 | (hdspm->control_register & HDSPM_clr_tms) ? "on" : "off", |
| 4863 | (hdspm->control_register & HDSPM_TX_64ch) ? "64" : "56", |
| 4864 | (hdspm->control_register & HDSPM_AutoInp) ? "on" : "off"); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 4865 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 4866 | |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 4867 | if (!(hdspm->control_register & HDSPM_ClockModeMaster)) |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 4868 | system_clock_mode = "AutoSync"; |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 4869 | else |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 4870 | system_clock_mode = "Master"; |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 4871 | snd_iprintf(buffer, "AutoSync Reference: %s\n", system_clock_mode); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 4872 | |
| 4873 | switch (hdspm_pref_sync_ref(hdspm)) { |
| 4874 | case HDSPM_SYNC_FROM_WORD: |
| 4875 | pref_sync_ref = "Word Clock"; |
| 4876 | break; |
| 4877 | case HDSPM_SYNC_FROM_MADI: |
| 4878 | pref_sync_ref = "MADI Sync"; |
| 4879 | break; |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 4880 | case HDSPM_SYNC_FROM_TCO: |
| 4881 | pref_sync_ref = "TCO"; |
| 4882 | break; |
| 4883 | case HDSPM_SYNC_FROM_SYNC_IN: |
| 4884 | pref_sync_ref = "Sync In"; |
| 4885 | break; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 4886 | default: |
| 4887 | pref_sync_ref = "XXXX Clock"; |
| 4888 | break; |
| 4889 | } |
| 4890 | snd_iprintf(buffer, "Preferred Sync Reference: %s\n", |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 4891 | pref_sync_ref); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 4892 | |
| 4893 | snd_iprintf(buffer, "System Clock Frequency: %d\n", |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 4894 | hdspm->system_sample_rate); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 4895 | |
| 4896 | |
| 4897 | snd_iprintf(buffer, "--- Status:\n"); |
| 4898 | |
| 4899 | x = status & HDSPM_madiSync; |
| 4900 | x2 = status2 & HDSPM_wcSync; |
| 4901 | |
| 4902 | snd_iprintf(buffer, "Inputs MADI=%s, WordClock=%s\n", |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 4903 | (status & HDSPM_madiLock) ? (x ? "Sync" : "Lock") : |
| 4904 | "NoLock", |
| 4905 | (status2 & HDSPM_wcLock) ? (x2 ? "Sync" : "Lock") : |
| 4906 | "NoLock"); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 4907 | |
| 4908 | switch (hdspm_autosync_ref(hdspm)) { |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 4909 | case HDSPM_AUTOSYNC_FROM_SYNC_IN: |
| 4910 | autosync_ref = "Sync In"; |
| 4911 | break; |
| 4912 | case HDSPM_AUTOSYNC_FROM_TCO: |
| 4913 | autosync_ref = "TCO"; |
| 4914 | break; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 4915 | case HDSPM_AUTOSYNC_FROM_WORD: |
| 4916 | autosync_ref = "Word Clock"; |
| 4917 | break; |
| 4918 | case HDSPM_AUTOSYNC_FROM_MADI: |
| 4919 | autosync_ref = "MADI Sync"; |
| 4920 | break; |
| 4921 | case HDSPM_AUTOSYNC_FROM_NONE: |
| 4922 | autosync_ref = "Input not valid"; |
| 4923 | break; |
| 4924 | default: |
| 4925 | autosync_ref = "---"; |
| 4926 | break; |
| 4927 | } |
| 4928 | snd_iprintf(buffer, |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 4929 | "AutoSync: Reference= %s, Freq=%d (MADI = %d, Word = %d)\n", |
| 4930 | autosync_ref, hdspm_external_sample_rate(hdspm), |
| 4931 | (status & HDSPM_madiFreqMask) >> 22, |
| 4932 | (status2 & HDSPM_wcFreqMask) >> 5); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 4933 | |
| 4934 | snd_iprintf(buffer, "Input: %s, Mode=%s\n", |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 4935 | (status & HDSPM_AB_int) ? "Coax" : "Optical", |
| 4936 | (status & HDSPM_RX_64ch) ? "64 channels" : |
| 4937 | "56 channels"); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 4938 | |
| 4939 | snd_iprintf(buffer, "\n"); |
| 4940 | } |
| 4941 | |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 4942 | static void |
| 4943 | snd_hdspm_proc_read_aes32(struct snd_info_entry * entry, |
| 4944 | struct snd_info_buffer *buffer) |
| 4945 | { |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 4946 | struct hdspm *hdspm = entry->private_data; |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 4947 | unsigned int status; |
| 4948 | unsigned int status2; |
| 4949 | unsigned int timecode; |
| 4950 | int pref_syncref; |
| 4951 | char *autosync_ref; |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 4952 | int x; |
| 4953 | |
| 4954 | status = hdspm_read(hdspm, HDSPM_statusRegister); |
| 4955 | status2 = hdspm_read(hdspm, HDSPM_statusRegister2); |
| 4956 | timecode = hdspm_read(hdspm, HDSPM_timecodeRegister); |
| 4957 | |
| 4958 | snd_iprintf(buffer, "%s (Card #%d) Rev.%x\n", |
| 4959 | hdspm->card_name, hdspm->card->number + 1, |
| 4960 | hdspm->firmware_rev); |
| 4961 | |
| 4962 | snd_iprintf(buffer, "IRQ: %d Registers bus: 0x%lx VM: 0x%lx\n", |
| 4963 | hdspm->irq, hdspm->port, (unsigned long)hdspm->iobase); |
| 4964 | |
| 4965 | snd_iprintf(buffer, "--- System ---\n"); |
| 4966 | |
| 4967 | snd_iprintf(buffer, |
| 4968 | "IRQ Pending: Audio=%d, MIDI0=%d, MIDI1=%d, IRQcount=%d\n", |
| 4969 | status & HDSPM_audioIRQPending, |
| 4970 | (status & HDSPM_midi0IRQPending) ? 1 : 0, |
| 4971 | (status & HDSPM_midi1IRQPending) ? 1 : 0, |
| 4972 | hdspm->irq_count); |
| 4973 | snd_iprintf(buffer, |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 4974 | "HW pointer: id = %d, rawptr = %d (%d->%d) " |
| 4975 | "estimated= %ld (bytes)\n", |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 4976 | ((status & HDSPM_BufferID) ? 1 : 0), |
| 4977 | (status & HDSPM_BufferPositionMask), |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 4978 | (status & HDSPM_BufferPositionMask) % |
| 4979 | (2 * (int)hdspm->period_bytes), |
| 4980 | ((status & HDSPM_BufferPositionMask) - 64) % |
| 4981 | (2 * (int)hdspm->period_bytes), |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 4982 | (long) hdspm_hw_pointer(hdspm) * 4); |
| 4983 | |
| 4984 | snd_iprintf(buffer, |
| 4985 | "MIDI FIFO: Out1=0x%x, Out2=0x%x, In1=0x%x, In2=0x%x \n", |
| 4986 | hdspm_read(hdspm, HDSPM_midiStatusOut0) & 0xFF, |
| 4987 | hdspm_read(hdspm, HDSPM_midiStatusOut1) & 0xFF, |
| 4988 | hdspm_read(hdspm, HDSPM_midiStatusIn0) & 0xFF, |
| 4989 | hdspm_read(hdspm, HDSPM_midiStatusIn1) & 0xFF); |
| 4990 | snd_iprintf(buffer, |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 4991 | "MIDIoverMADI FIFO: In=0x%x, Out=0x%x \n", |
| 4992 | hdspm_read(hdspm, HDSPM_midiStatusIn2) & 0xFF, |
| 4993 | hdspm_read(hdspm, HDSPM_midiStatusOut2) & 0xFF); |
| 4994 | snd_iprintf(buffer, |
| 4995 | "Register: ctrl1=0x%x, ctrl2=0x%x, status1=0x%x, " |
| 4996 | "status2=0x%x\n", |
| 4997 | hdspm->control_register, hdspm->control2_register, |
| 4998 | status, status2); |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 4999 | |
| 5000 | snd_iprintf(buffer, "--- Settings ---\n"); |
| 5001 | |
Adrian Knoth | 7cb155f | 2011-08-15 00:22:53 +0200 | [diff] [blame] | 5002 | x = hdspm_get_latency(hdspm); |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 5003 | |
| 5004 | snd_iprintf(buffer, |
| 5005 | "Size (Latency): %d samples (2 periods of %lu bytes)\n", |
| 5006 | x, (unsigned long) hdspm->period_bytes); |
| 5007 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 5008 | snd_iprintf(buffer, "Line out: %s\n", |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 5009 | (hdspm-> |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 5010 | control_register & HDSPM_LineOut) ? "on " : "off"); |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 5011 | |
| 5012 | snd_iprintf(buffer, |
| 5013 | "ClearTrackMarker %s, Emphasis %s, Dolby %s\n", |
| 5014 | (hdspm-> |
| 5015 | control_register & HDSPM_clr_tms) ? "on" : "off", |
| 5016 | (hdspm-> |
| 5017 | control_register & HDSPM_Emphasis) ? "on" : "off", |
| 5018 | (hdspm-> |
| 5019 | control_register & HDSPM_Dolby) ? "on" : "off"); |
| 5020 | |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 5021 | |
| 5022 | pref_syncref = hdspm_pref_sync_ref(hdspm); |
| 5023 | if (pref_syncref == 0) |
| 5024 | snd_iprintf(buffer, "Preferred Sync Reference: Word Clock\n"); |
| 5025 | else |
| 5026 | snd_iprintf(buffer, "Preferred Sync Reference: AES%d\n", |
| 5027 | pref_syncref); |
| 5028 | |
| 5029 | snd_iprintf(buffer, "System Clock Frequency: %d\n", |
| 5030 | hdspm->system_sample_rate); |
| 5031 | |
| 5032 | snd_iprintf(buffer, "Double speed: %s\n", |
| 5033 | hdspm->control_register & HDSPM_DS_DoubleWire? |
| 5034 | "Double wire" : "Single wire"); |
| 5035 | snd_iprintf(buffer, "Quad speed: %s\n", |
| 5036 | hdspm->control_register & HDSPM_QS_DoubleWire? |
| 5037 | "Double wire" : |
| 5038 | hdspm->control_register & HDSPM_QS_QuadWire? |
| 5039 | "Quad wire" : "Single wire"); |
| 5040 | |
| 5041 | snd_iprintf(buffer, "--- Status:\n"); |
| 5042 | |
| 5043 | snd_iprintf(buffer, "Word: %s Frequency: %d\n", |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 5044 | (status & HDSPM_AES32_wcLock) ? "Sync " : "No Lock", |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 5045 | HDSPM_bit2freq((status >> HDSPM_AES32_wcFreq_bit) & 0xF)); |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 5046 | |
| 5047 | for (x = 0; x < 8; x++) { |
| 5048 | snd_iprintf(buffer, "AES%d: %s Frequency: %d\n", |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 5049 | x+1, |
| 5050 | (status2 & (HDSPM_LockAES >> x)) ? |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 5051 | "Sync " : "No Lock", |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 5052 | HDSPM_bit2freq((timecode >> (4*x)) & 0xF)); |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 5053 | } |
| 5054 | |
| 5055 | switch (hdspm_autosync_ref(hdspm)) { |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 5056 | case HDSPM_AES32_AUTOSYNC_FROM_NONE: |
| 5057 | autosync_ref = "None"; break; |
| 5058 | case HDSPM_AES32_AUTOSYNC_FROM_WORD: |
| 5059 | autosync_ref = "Word Clock"; break; |
| 5060 | case HDSPM_AES32_AUTOSYNC_FROM_AES1: |
| 5061 | autosync_ref = "AES1"; break; |
| 5062 | case HDSPM_AES32_AUTOSYNC_FROM_AES2: |
| 5063 | autosync_ref = "AES2"; break; |
| 5064 | case HDSPM_AES32_AUTOSYNC_FROM_AES3: |
| 5065 | autosync_ref = "AES3"; break; |
| 5066 | case HDSPM_AES32_AUTOSYNC_FROM_AES4: |
| 5067 | autosync_ref = "AES4"; break; |
| 5068 | case HDSPM_AES32_AUTOSYNC_FROM_AES5: |
| 5069 | autosync_ref = "AES5"; break; |
| 5070 | case HDSPM_AES32_AUTOSYNC_FROM_AES6: |
| 5071 | autosync_ref = "AES6"; break; |
| 5072 | case HDSPM_AES32_AUTOSYNC_FROM_AES7: |
| 5073 | autosync_ref = "AES7"; break; |
| 5074 | case HDSPM_AES32_AUTOSYNC_FROM_AES8: |
| 5075 | autosync_ref = "AES8"; break; |
| 5076 | default: |
| 5077 | autosync_ref = "---"; break; |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 5078 | } |
| 5079 | snd_iprintf(buffer, "AutoSync ref = %s\n", autosync_ref); |
| 5080 | |
| 5081 | snd_iprintf(buffer, "\n"); |
| 5082 | } |
| 5083 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 5084 | static void |
| 5085 | snd_hdspm_proc_read_raydat(struct snd_info_entry *entry, |
| 5086 | struct snd_info_buffer *buffer) |
| 5087 | { |
| 5088 | struct hdspm *hdspm = entry->private_data; |
| 5089 | unsigned int status1, status2, status3, control, i; |
| 5090 | unsigned int lock, sync; |
| 5091 | |
| 5092 | status1 = hdspm_read(hdspm, HDSPM_RD_STATUS_1); /* s1 */ |
| 5093 | status2 = hdspm_read(hdspm, HDSPM_RD_STATUS_2); /* freq */ |
| 5094 | status3 = hdspm_read(hdspm, HDSPM_RD_STATUS_3); /* s2 */ |
| 5095 | |
| 5096 | control = hdspm->control_register; |
| 5097 | |
| 5098 | snd_iprintf(buffer, "STATUS1: 0x%08x\n", status1); |
| 5099 | snd_iprintf(buffer, "STATUS2: 0x%08x\n", status2); |
| 5100 | snd_iprintf(buffer, "STATUS3: 0x%08x\n", status3); |
| 5101 | |
| 5102 | |
| 5103 | snd_iprintf(buffer, "\n*** CLOCK MODE\n\n"); |
| 5104 | |
| 5105 | snd_iprintf(buffer, "Clock mode : %s\n", |
| 5106 | (hdspm_system_clock_mode(hdspm) == 0) ? "master" : "slave"); |
| 5107 | snd_iprintf(buffer, "System frequency: %d Hz\n", |
| 5108 | hdspm_get_system_sample_rate(hdspm)); |
| 5109 | |
| 5110 | snd_iprintf(buffer, "\n*** INPUT STATUS\n\n"); |
| 5111 | |
| 5112 | lock = 0x1; |
| 5113 | sync = 0x100; |
| 5114 | |
| 5115 | for (i = 0; i < 8; i++) { |
| 5116 | snd_iprintf(buffer, "s1_input %d: Lock %d, Sync %d, Freq %s\n", |
| 5117 | i, |
| 5118 | (status1 & lock) ? 1 : 0, |
| 5119 | (status1 & sync) ? 1 : 0, |
| 5120 | texts_freq[(status2 >> (i * 4)) & 0xF]); |
| 5121 | |
| 5122 | lock = lock<<1; |
| 5123 | sync = sync<<1; |
| 5124 | } |
| 5125 | |
| 5126 | snd_iprintf(buffer, "WC input: Lock %d, Sync %d, Freq %s\n", |
| 5127 | (status1 & 0x1000000) ? 1 : 0, |
| 5128 | (status1 & 0x2000000) ? 1 : 0, |
| 5129 | texts_freq[(status1 >> 16) & 0xF]); |
| 5130 | |
| 5131 | snd_iprintf(buffer, "TCO input: Lock %d, Sync %d, Freq %s\n", |
| 5132 | (status1 & 0x4000000) ? 1 : 0, |
| 5133 | (status1 & 0x8000000) ? 1 : 0, |
| 5134 | texts_freq[(status1 >> 20) & 0xF]); |
| 5135 | |
| 5136 | snd_iprintf(buffer, "SYNC IN: Lock %d, Sync %d, Freq %s\n", |
| 5137 | (status3 & 0x400) ? 1 : 0, |
| 5138 | (status3 & 0x800) ? 1 : 0, |
| 5139 | texts_freq[(status2 >> 12) & 0xF]); |
| 5140 | |
| 5141 | } |
| 5142 | |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 5143 | #ifdef CONFIG_SND_DEBUG |
| 5144 | static void |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 5145 | snd_hdspm_proc_read_debug(struct snd_info_entry *entry, |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 5146 | struct snd_info_buffer *buffer) |
| 5147 | { |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 5148 | struct hdspm *hdspm = entry->private_data; |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 5149 | |
| 5150 | int j,i; |
| 5151 | |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 5152 | for (i = 0; i < 256 /* 1024*64 */; i += j) { |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 5153 | snd_iprintf(buffer, "0x%08X: ", i); |
| 5154 | for (j = 0; j < 16; j += 4) |
| 5155 | snd_iprintf(buffer, "%08X ", hdspm_read(hdspm, i + j)); |
| 5156 | snd_iprintf(buffer, "\n"); |
| 5157 | } |
| 5158 | } |
| 5159 | #endif |
| 5160 | |
| 5161 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 5162 | static void snd_hdspm_proc_ports_in(struct snd_info_entry *entry, |
| 5163 | struct snd_info_buffer *buffer) |
| 5164 | { |
| 5165 | struct hdspm *hdspm = entry->private_data; |
| 5166 | int i; |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 5167 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 5168 | snd_iprintf(buffer, "# generated by hdspm\n"); |
| 5169 | |
| 5170 | for (i = 0; i < hdspm->max_channels_in; i++) { |
| 5171 | snd_iprintf(buffer, "%d=%s\n", i+1, hdspm->port_names_in[i]); |
| 5172 | } |
| 5173 | } |
| 5174 | |
| 5175 | static void snd_hdspm_proc_ports_out(struct snd_info_entry *entry, |
| 5176 | struct snd_info_buffer *buffer) |
| 5177 | { |
| 5178 | struct hdspm *hdspm = entry->private_data; |
| 5179 | int i; |
| 5180 | |
| 5181 | snd_iprintf(buffer, "# generated by hdspm\n"); |
| 5182 | |
| 5183 | for (i = 0; i < hdspm->max_channels_out; i++) { |
| 5184 | snd_iprintf(buffer, "%d=%s\n", i+1, hdspm->port_names_out[i]); |
| 5185 | } |
| 5186 | } |
| 5187 | |
| 5188 | |
| 5189 | static void __devinit snd_hdspm_proc_init(struct hdspm *hdspm) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5190 | { |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 5191 | struct snd_info_entry *entry; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5192 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 5193 | if (!snd_card_proc_new(hdspm->card, "hdspm", &entry)) { |
| 5194 | switch (hdspm->io_type) { |
| 5195 | case AES32: |
| 5196 | snd_info_set_text_ops(entry, hdspm, |
| 5197 | snd_hdspm_proc_read_aes32); |
| 5198 | break; |
| 5199 | case MADI: |
| 5200 | snd_info_set_text_ops(entry, hdspm, |
| 5201 | snd_hdspm_proc_read_madi); |
| 5202 | break; |
| 5203 | case MADIface: |
| 5204 | /* snd_info_set_text_ops(entry, hdspm, |
| 5205 | snd_hdspm_proc_read_madiface); */ |
| 5206 | break; |
| 5207 | case RayDAT: |
| 5208 | snd_info_set_text_ops(entry, hdspm, |
| 5209 | snd_hdspm_proc_read_raydat); |
| 5210 | break; |
| 5211 | case AIO: |
| 5212 | break; |
| 5213 | } |
| 5214 | } |
| 5215 | |
| 5216 | if (!snd_card_proc_new(hdspm->card, "ports.in", &entry)) { |
| 5217 | snd_info_set_text_ops(entry, hdspm, snd_hdspm_proc_ports_in); |
| 5218 | } |
| 5219 | |
| 5220 | if (!snd_card_proc_new(hdspm->card, "ports.out", &entry)) { |
| 5221 | snd_info_set_text_ops(entry, hdspm, snd_hdspm_proc_ports_out); |
| 5222 | } |
| 5223 | |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 5224 | #ifdef CONFIG_SND_DEBUG |
| 5225 | /* debug file to read all hdspm registers */ |
| 5226 | if (!snd_card_proc_new(hdspm->card, "debug", &entry)) |
| 5227 | snd_info_set_text_ops(entry, hdspm, |
| 5228 | snd_hdspm_proc_read_debug); |
| 5229 | #endif |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5230 | } |
| 5231 | |
| 5232 | /*------------------------------------------------------------ |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 5233 | hdspm intitialize |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5234 | ------------------------------------------------------------*/ |
| 5235 | |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 5236 | static int snd_hdspm_set_defaults(struct hdspm * hdspm) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5237 | { |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5238 | /* ASSUMPTION: hdspm->lock is either held, or there is no need to |
Joe Perches | 561de31 | 2007-12-18 13:13:47 +0100 | [diff] [blame] | 5239 | hold it (e.g. during module initialization). |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 5240 | */ |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5241 | |
| 5242 | /* set defaults: */ |
| 5243 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 5244 | hdspm->settings_register = 0; |
| 5245 | |
| 5246 | switch (hdspm->io_type) { |
| 5247 | case MADI: |
| 5248 | case MADIface: |
| 5249 | hdspm->control_register = |
| 5250 | 0x2 + 0x8 + 0x10 + 0x80 + 0x400 + 0x4000 + 0x1000000; |
| 5251 | break; |
| 5252 | |
| 5253 | case RayDAT: |
| 5254 | case AIO: |
| 5255 | hdspm->settings_register = 0x1 + 0x1000; |
| 5256 | /* Magic values are: LAT_0, LAT_2, Master, freq1, tx64ch, inp_0, |
| 5257 | * line_out */ |
| 5258 | hdspm->control_register = |
| 5259 | 0x2 + 0x8 + 0x10 + 0x80 + 0x400 + 0x4000 + 0x1000000; |
| 5260 | break; |
| 5261 | |
| 5262 | case AES32: |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 5263 | hdspm->control_register = |
| 5264 | HDSPM_ClockModeMaster | /* Master Cloack Mode on */ |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 5265 | hdspm_encode_latency(7) | /* latency max=8192samples */ |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 5266 | HDSPM_SyncRef0 | /* AES1 is syncclock */ |
| 5267 | HDSPM_LineOut | /* Analog output in */ |
| 5268 | HDSPM_Professional; /* Professional mode */ |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 5269 | break; |
| 5270 | } |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5271 | |
| 5272 | hdspm_write(hdspm, HDSPM_controlRegister, hdspm->control_register); |
| 5273 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 5274 | if (AES32 == hdspm->io_type) { |
Remy Bruno | ffb2c3c | 2007-03-07 19:08:46 +0100 | [diff] [blame] | 5275 | /* No control2 register for AES32 */ |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5276 | #ifdef SNDRV_BIG_ENDIAN |
Remy Bruno | ffb2c3c | 2007-03-07 19:08:46 +0100 | [diff] [blame] | 5277 | hdspm->control2_register = HDSPM_BIGENDIAN_MODE; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5278 | #else |
Remy Bruno | ffb2c3c | 2007-03-07 19:08:46 +0100 | [diff] [blame] | 5279 | hdspm->control2_register = 0; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5280 | #endif |
| 5281 | |
Remy Bruno | ffb2c3c | 2007-03-07 19:08:46 +0100 | [diff] [blame] | 5282 | hdspm_write(hdspm, HDSPM_control2Reg, hdspm->control2_register); |
| 5283 | } |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5284 | hdspm_compute_period_size(hdspm); |
| 5285 | |
| 5286 | /* silence everything */ |
| 5287 | |
| 5288 | all_in_all_mixer(hdspm, 0 * UNITY_GAIN); |
| 5289 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 5290 | if (hdspm->io_type == AIO || hdspm->io_type == RayDAT) { |
| 5291 | hdspm_write(hdspm, HDSPM_WR_SETTINGS, hdspm->settings_register); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5292 | } |
| 5293 | |
| 5294 | /* set a default rate so that the channel map is set up. */ |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 5295 | hdspm_set_rate(hdspm, 48000, 1); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5296 | |
| 5297 | return 0; |
| 5298 | } |
| 5299 | |
| 5300 | |
| 5301 | /*------------------------------------------------------------ |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 5302 | interrupt |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5303 | ------------------------------------------------------------*/ |
| 5304 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 5305 | static irqreturn_t snd_hdspm_interrupt(int irq, void *dev_id) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5306 | { |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 5307 | struct hdspm *hdspm = (struct hdspm *) dev_id; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5308 | unsigned int status; |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 5309 | int i, audio, midi, schedule = 0; |
| 5310 | /* cycles_t now; */ |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5311 | |
| 5312 | status = hdspm_read(hdspm, HDSPM_statusRegister); |
| 5313 | |
| 5314 | audio = status & HDSPM_audioIRQPending; |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 5315 | midi = status & (HDSPM_midi0IRQPending | HDSPM_midi1IRQPending | |
| 5316 | HDSPM_midi2IRQPending | HDSPM_midi3IRQPending); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5317 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 5318 | /* now = get_cycles(); */ |
| 5319 | /** |
| 5320 | * LAT_2..LAT_0 period counter (win) counter (mac) |
| 5321 | * 6 4096 ~256053425 ~514672358 |
| 5322 | * 5 2048 ~128024983 ~257373821 |
| 5323 | * 4 1024 ~64023706 ~128718089 |
| 5324 | * 3 512 ~32005945 ~64385999 |
| 5325 | * 2 256 ~16003039 ~32260176 |
| 5326 | * 1 128 ~7998738 ~16194507 |
| 5327 | * 0 64 ~3998231 ~8191558 |
| 5328 | **/ |
| 5329 | /* |
| 5330 | snd_printk(KERN_INFO "snd_hdspm_interrupt %llu @ %llx\n", |
| 5331 | now-hdspm->last_interrupt, status & 0xFFC0); |
| 5332 | hdspm->last_interrupt = now; |
| 5333 | */ |
| 5334 | |
| 5335 | if (!audio && !midi) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5336 | return IRQ_NONE; |
| 5337 | |
| 5338 | hdspm_write(hdspm, HDSPM_interruptConfirmation, 0); |
| 5339 | hdspm->irq_count++; |
| 5340 | |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5341 | |
| 5342 | if (audio) { |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5343 | if (hdspm->capture_substream) |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 5344 | snd_pcm_period_elapsed(hdspm->capture_substream); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5345 | |
| 5346 | if (hdspm->playback_substream) |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 5347 | snd_pcm_period_elapsed(hdspm->playback_substream); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5348 | } |
| 5349 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 5350 | if (midi) { |
| 5351 | i = 0; |
| 5352 | while (i < hdspm->midiPorts) { |
| 5353 | if ((hdspm_read(hdspm, |
| 5354 | hdspm->midi[i].statusIn) & 0xff) && |
| 5355 | (status & hdspm->midi[i].irq)) { |
| 5356 | /* we disable interrupts for this input until |
| 5357 | * processing is done |
| 5358 | */ |
| 5359 | hdspm->control_register &= ~hdspm->midi[i].ie; |
| 5360 | hdspm_write(hdspm, HDSPM_controlRegister, |
| 5361 | hdspm->control_register); |
| 5362 | hdspm->midi[i].pending = 1; |
| 5363 | schedule = 1; |
| 5364 | } |
| 5365 | |
| 5366 | i++; |
| 5367 | } |
| 5368 | |
| 5369 | if (schedule) |
| 5370 | tasklet_hi_schedule(&hdspm->midi_tasklet); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5371 | } |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 5372 | |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5373 | return IRQ_HANDLED; |
| 5374 | } |
| 5375 | |
| 5376 | /*------------------------------------------------------------ |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 5377 | pcm interface |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5378 | ------------------------------------------------------------*/ |
| 5379 | |
| 5380 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 5381 | static snd_pcm_uframes_t snd_hdspm_hw_pointer(struct snd_pcm_substream |
| 5382 | *substream) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5383 | { |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 5384 | struct hdspm *hdspm = snd_pcm_substream_chip(substream); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5385 | return hdspm_hw_pointer(hdspm); |
| 5386 | } |
| 5387 | |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5388 | |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 5389 | static int snd_hdspm_reset(struct snd_pcm_substream *substream) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5390 | { |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 5391 | struct snd_pcm_runtime *runtime = substream->runtime; |
| 5392 | struct hdspm *hdspm = snd_pcm_substream_chip(substream); |
| 5393 | struct snd_pcm_substream *other; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5394 | |
| 5395 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) |
| 5396 | other = hdspm->capture_substream; |
| 5397 | else |
| 5398 | other = hdspm->playback_substream; |
| 5399 | |
| 5400 | if (hdspm->running) |
| 5401 | runtime->status->hw_ptr = hdspm_hw_pointer(hdspm); |
| 5402 | else |
| 5403 | runtime->status->hw_ptr = 0; |
| 5404 | if (other) { |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 5405 | struct snd_pcm_substream *s; |
| 5406 | struct snd_pcm_runtime *oruntime = other->runtime; |
Takashi Iwai | ef991b9 | 2007-02-22 12:52:53 +0100 | [diff] [blame] | 5407 | snd_pcm_group_for_each_entry(s, substream) { |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5408 | if (s == other) { |
| 5409 | oruntime->status->hw_ptr = |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 5410 | runtime->status->hw_ptr; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5411 | break; |
| 5412 | } |
| 5413 | } |
| 5414 | } |
| 5415 | return 0; |
| 5416 | } |
| 5417 | |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 5418 | static int snd_hdspm_hw_params(struct snd_pcm_substream *substream, |
| 5419 | struct snd_pcm_hw_params *params) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5420 | { |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 5421 | struct hdspm *hdspm = snd_pcm_substream_chip(substream); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5422 | int err; |
| 5423 | int i; |
| 5424 | pid_t this_pid; |
| 5425 | pid_t other_pid; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5426 | |
| 5427 | spin_lock_irq(&hdspm->lock); |
| 5428 | |
| 5429 | if (substream->pstr->stream == SNDRV_PCM_STREAM_PLAYBACK) { |
| 5430 | this_pid = hdspm->playback_pid; |
| 5431 | other_pid = hdspm->capture_pid; |
| 5432 | } else { |
| 5433 | this_pid = hdspm->capture_pid; |
| 5434 | other_pid = hdspm->playback_pid; |
| 5435 | } |
| 5436 | |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 5437 | if (other_pid > 0 && this_pid != other_pid) { |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5438 | |
| 5439 | /* The other stream is open, and not by the same |
| 5440 | task as this one. Make sure that the parameters |
| 5441 | that matter are the same. |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 5442 | */ |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5443 | |
| 5444 | if (params_rate(params) != hdspm->system_sample_rate) { |
| 5445 | spin_unlock_irq(&hdspm->lock); |
| 5446 | _snd_pcm_hw_param_setempty(params, |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 5447 | SNDRV_PCM_HW_PARAM_RATE); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5448 | return -EBUSY; |
| 5449 | } |
| 5450 | |
| 5451 | if (params_period_size(params) != hdspm->period_bytes / 4) { |
| 5452 | spin_unlock_irq(&hdspm->lock); |
| 5453 | _snd_pcm_hw_param_setempty(params, |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 5454 | SNDRV_PCM_HW_PARAM_PERIOD_SIZE); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5455 | return -EBUSY; |
| 5456 | } |
| 5457 | |
| 5458 | } |
| 5459 | /* We're fine. */ |
| 5460 | spin_unlock_irq(&hdspm->lock); |
| 5461 | |
| 5462 | /* how to make sure that the rate matches an externally-set one ? */ |
| 5463 | |
| 5464 | spin_lock_irq(&hdspm->lock); |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 5465 | err = hdspm_set_rate(hdspm, params_rate(params), 0); |
| 5466 | if (err < 0) { |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 5467 | snd_printk(KERN_INFO "err on hdspm_set_rate: %d\n", err); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5468 | spin_unlock_irq(&hdspm->lock); |
| 5469 | _snd_pcm_hw_param_setempty(params, |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 5470 | SNDRV_PCM_HW_PARAM_RATE); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5471 | return err; |
| 5472 | } |
| 5473 | spin_unlock_irq(&hdspm->lock); |
| 5474 | |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 5475 | err = hdspm_set_interrupt_interval(hdspm, |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 5476 | params_period_size(params)); |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 5477 | if (err < 0) { |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 5478 | snd_printk(KERN_INFO "err on hdspm_set_interrupt_interval: %d\n", err); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5479 | _snd_pcm_hw_param_setempty(params, |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 5480 | SNDRV_PCM_HW_PARAM_PERIOD_SIZE); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5481 | return err; |
| 5482 | } |
| 5483 | |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 5484 | /* Memory allocation, takashi's method, dont know if we should |
| 5485 | * spinlock |
| 5486 | */ |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5487 | /* malloc all buffer even if not enabled to get sure */ |
Remy Bruno | ffb2c3c | 2007-03-07 19:08:46 +0100 | [diff] [blame] | 5488 | /* Update for MADI rev 204: we need to allocate for all channels, |
| 5489 | * otherwise it doesn't work at 96kHz */ |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 5490 | |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5491 | err = |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 5492 | snd_pcm_lib_malloc_pages(substream, HDSPM_DMA_AREA_BYTES); |
| 5493 | if (err < 0) { |
| 5494 | snd_printk(KERN_INFO "err on snd_pcm_lib_malloc_pages: %d\n", err); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5495 | return err; |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 5496 | } |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5497 | |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5498 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { |
| 5499 | |
Takashi Iwai | 77a23f2 | 2008-08-21 13:00:13 +0200 | [diff] [blame] | 5500 | hdspm_set_sgbuf(hdspm, substream, HDSPM_pageAddressBufferOut, |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5501 | params_channels(params)); |
| 5502 | |
| 5503 | for (i = 0; i < params_channels(params); ++i) |
| 5504 | snd_hdspm_enable_out(hdspm, i, 1); |
| 5505 | |
| 5506 | hdspm->playback_buffer = |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 5507 | (unsigned char *) substream->runtime->dma_area; |
Takashi Iwai | 54bf5dd | 2006-11-06 15:38:55 +0100 | [diff] [blame] | 5508 | snd_printdd("Allocated sample buffer for playback at %p\n", |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 5509 | hdspm->playback_buffer); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5510 | } else { |
Takashi Iwai | 77a23f2 | 2008-08-21 13:00:13 +0200 | [diff] [blame] | 5511 | hdspm_set_sgbuf(hdspm, substream, HDSPM_pageAddressBufferIn, |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5512 | params_channels(params)); |
| 5513 | |
| 5514 | for (i = 0; i < params_channels(params); ++i) |
| 5515 | snd_hdspm_enable_in(hdspm, i, 1); |
| 5516 | |
| 5517 | hdspm->capture_buffer = |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 5518 | (unsigned char *) substream->runtime->dma_area; |
Takashi Iwai | 54bf5dd | 2006-11-06 15:38:55 +0100 | [diff] [blame] | 5519 | snd_printdd("Allocated sample buffer for capture at %p\n", |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 5520 | hdspm->capture_buffer); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5521 | } |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 5522 | |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 5523 | /* |
| 5524 | snd_printdd("Allocated sample buffer for %s at 0x%08X\n", |
| 5525 | substream->stream == SNDRV_PCM_STREAM_PLAYBACK ? |
| 5526 | "playback" : "capture", |
Takashi Iwai | 77a23f2 | 2008-08-21 13:00:13 +0200 | [diff] [blame] | 5527 | snd_pcm_sgbuf_get_addr(substream, 0)); |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 5528 | */ |
Remy Bruno | ffb2c3c | 2007-03-07 19:08:46 +0100 | [diff] [blame] | 5529 | /* |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 5530 | snd_printdd("set_hwparams: %s %d Hz, %d channels, bs = %d\n", |
| 5531 | substream->stream == SNDRV_PCM_STREAM_PLAYBACK ? |
| 5532 | "playback" : "capture", |
| 5533 | params_rate(params), params_channels(params), |
| 5534 | params_buffer_size(params)); |
| 5535 | */ |
| 5536 | |
| 5537 | |
| 5538 | /* Switch to native float format if requested */ |
| 5539 | if (SNDRV_PCM_FORMAT_FLOAT_LE == params_format(params)) { |
| 5540 | if (!(hdspm->control_register & HDSPe_FLOAT_FORMAT)) |
| 5541 | snd_printk(KERN_INFO "hdspm: Switching to native 32bit LE float format.\n"); |
| 5542 | |
| 5543 | hdspm->control_register |= HDSPe_FLOAT_FORMAT; |
| 5544 | } else if (SNDRV_PCM_FORMAT_S32_LE == params_format(params)) { |
| 5545 | if (hdspm->control_register & HDSPe_FLOAT_FORMAT) |
| 5546 | snd_printk(KERN_INFO "hdspm: Switching to native 32bit LE integer format.\n"); |
| 5547 | |
| 5548 | hdspm->control_register &= ~HDSPe_FLOAT_FORMAT; |
| 5549 | } |
| 5550 | hdspm_write(hdspm, HDSPM_controlRegister, hdspm->control_register); |
| 5551 | |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5552 | return 0; |
| 5553 | } |
| 5554 | |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 5555 | static int snd_hdspm_hw_free(struct snd_pcm_substream *substream) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5556 | { |
| 5557 | int i; |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 5558 | struct hdspm *hdspm = snd_pcm_substream_chip(substream); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5559 | |
| 5560 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { |
| 5561 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 5562 | /* params_channels(params) should be enough, |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5563 | but to get sure in case of error */ |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 5564 | for (i = 0; i < hdspm->max_channels_out; ++i) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5565 | snd_hdspm_enable_out(hdspm, i, 0); |
| 5566 | |
| 5567 | hdspm->playback_buffer = NULL; |
| 5568 | } else { |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 5569 | for (i = 0; i < hdspm->max_channels_in; ++i) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5570 | snd_hdspm_enable_in(hdspm, i, 0); |
| 5571 | |
| 5572 | hdspm->capture_buffer = NULL; |
| 5573 | |
| 5574 | } |
| 5575 | |
| 5576 | snd_pcm_lib_free_pages(substream); |
| 5577 | |
| 5578 | return 0; |
| 5579 | } |
| 5580 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 5581 | |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 5582 | static int snd_hdspm_channel_info(struct snd_pcm_substream *substream, |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 5583 | struct snd_pcm_channel_info *info) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5584 | { |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 5585 | struct hdspm *hdspm = snd_pcm_substream_chip(substream); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5586 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 5587 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { |
| 5588 | if (snd_BUG_ON(info->channel >= hdspm->max_channels_out)) { |
| 5589 | snd_printk(KERN_INFO "snd_hdspm_channel_info: output channel out of range (%d)\n", info->channel); |
| 5590 | return -EINVAL; |
| 5591 | } |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5592 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 5593 | if (hdspm->channel_map_out[info->channel] < 0) { |
| 5594 | snd_printk(KERN_INFO "snd_hdspm_channel_info: output channel %d mapped out\n", info->channel); |
| 5595 | return -EINVAL; |
| 5596 | } |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5597 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 5598 | info->offset = hdspm->channel_map_out[info->channel] * |
| 5599 | HDSPM_CHANNEL_BUFFER_BYTES; |
| 5600 | } else { |
| 5601 | if (snd_BUG_ON(info->channel >= hdspm->max_channels_in)) { |
| 5602 | snd_printk(KERN_INFO "snd_hdspm_channel_info: input channel out of range (%d)\n", info->channel); |
| 5603 | return -EINVAL; |
| 5604 | } |
| 5605 | |
| 5606 | if (hdspm->channel_map_in[info->channel] < 0) { |
| 5607 | snd_printk(KERN_INFO "snd_hdspm_channel_info: input channel %d mapped out\n", info->channel); |
| 5608 | return -EINVAL; |
| 5609 | } |
| 5610 | |
| 5611 | info->offset = hdspm->channel_map_in[info->channel] * |
| 5612 | HDSPM_CHANNEL_BUFFER_BYTES; |
| 5613 | } |
| 5614 | |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5615 | info->first = 0; |
| 5616 | info->step = 32; |
| 5617 | return 0; |
| 5618 | } |
| 5619 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 5620 | |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 5621 | static int snd_hdspm_ioctl(struct snd_pcm_substream *substream, |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 5622 | unsigned int cmd, void *arg) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5623 | { |
| 5624 | switch (cmd) { |
| 5625 | case SNDRV_PCM_IOCTL1_RESET: |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 5626 | return snd_hdspm_reset(substream); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5627 | |
| 5628 | case SNDRV_PCM_IOCTL1_CHANNEL_INFO: |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 5629 | { |
| 5630 | struct snd_pcm_channel_info *info = arg; |
| 5631 | return snd_hdspm_channel_info(substream, info); |
| 5632 | } |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5633 | default: |
| 5634 | break; |
| 5635 | } |
| 5636 | |
| 5637 | return snd_pcm_lib_ioctl(substream, cmd, arg); |
| 5638 | } |
| 5639 | |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 5640 | static int snd_hdspm_trigger(struct snd_pcm_substream *substream, int cmd) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5641 | { |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 5642 | struct hdspm *hdspm = snd_pcm_substream_chip(substream); |
| 5643 | struct snd_pcm_substream *other; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5644 | int running; |
| 5645 | |
| 5646 | spin_lock(&hdspm->lock); |
| 5647 | running = hdspm->running; |
| 5648 | switch (cmd) { |
| 5649 | case SNDRV_PCM_TRIGGER_START: |
| 5650 | running |= 1 << substream->stream; |
| 5651 | break; |
| 5652 | case SNDRV_PCM_TRIGGER_STOP: |
| 5653 | running &= ~(1 << substream->stream); |
| 5654 | break; |
| 5655 | default: |
| 5656 | snd_BUG(); |
| 5657 | spin_unlock(&hdspm->lock); |
| 5658 | return -EINVAL; |
| 5659 | } |
| 5660 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) |
| 5661 | other = hdspm->capture_substream; |
| 5662 | else |
| 5663 | other = hdspm->playback_substream; |
| 5664 | |
| 5665 | if (other) { |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 5666 | struct snd_pcm_substream *s; |
Takashi Iwai | ef991b9 | 2007-02-22 12:52:53 +0100 | [diff] [blame] | 5667 | snd_pcm_group_for_each_entry(s, substream) { |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5668 | if (s == other) { |
| 5669 | snd_pcm_trigger_done(s, substream); |
| 5670 | if (cmd == SNDRV_PCM_TRIGGER_START) |
| 5671 | running |= 1 << s->stream; |
| 5672 | else |
| 5673 | running &= ~(1 << s->stream); |
| 5674 | goto _ok; |
| 5675 | } |
| 5676 | } |
| 5677 | if (cmd == SNDRV_PCM_TRIGGER_START) { |
| 5678 | if (!(running & (1 << SNDRV_PCM_STREAM_PLAYBACK)) |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 5679 | && substream->stream == |
| 5680 | SNDRV_PCM_STREAM_CAPTURE) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5681 | hdspm_silence_playback(hdspm); |
| 5682 | } else { |
| 5683 | if (running && |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 5684 | substream->stream == SNDRV_PCM_STREAM_PLAYBACK) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5685 | hdspm_silence_playback(hdspm); |
| 5686 | } |
| 5687 | } else { |
| 5688 | if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) |
| 5689 | hdspm_silence_playback(hdspm); |
| 5690 | } |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 5691 | _ok: |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5692 | snd_pcm_trigger_done(substream, substream); |
| 5693 | if (!hdspm->running && running) |
| 5694 | hdspm_start_audio(hdspm); |
| 5695 | else if (hdspm->running && !running) |
| 5696 | hdspm_stop_audio(hdspm); |
| 5697 | hdspm->running = running; |
| 5698 | spin_unlock(&hdspm->lock); |
| 5699 | |
| 5700 | return 0; |
| 5701 | } |
| 5702 | |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 5703 | static int snd_hdspm_prepare(struct snd_pcm_substream *substream) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5704 | { |
| 5705 | return 0; |
| 5706 | } |
| 5707 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 5708 | static unsigned int period_sizes_old[] = { |
Adrian Knoth | 135d153 | 2011-08-15 00:22:50 +0200 | [diff] [blame] | 5709 | 64, 128, 256, 512, 1024, 2048, 4096, 8192 |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 5710 | }; |
| 5711 | |
| 5712 | static unsigned int period_sizes_new[] = { |
Adrian Knoth | 1ad5972 | 2011-08-15 00:22:52 +0200 | [diff] [blame] | 5713 | 64, 128, 256, 512, 1024, 2048, 4096, 32 |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 5714 | }; |
| 5715 | |
| 5716 | /* RayDAT and AIO always have a buffer of 16384 samples per channel */ |
| 5717 | static unsigned int raydat_aio_buffer_sizes[] = { |
| 5718 | 16384 |
| 5719 | }; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5720 | |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 5721 | static struct snd_pcm_hardware snd_hdspm_playback_subinfo = { |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5722 | .info = (SNDRV_PCM_INFO_MMAP | |
| 5723 | SNDRV_PCM_INFO_MMAP_VALID | |
| 5724 | SNDRV_PCM_INFO_NONINTERLEAVED | |
| 5725 | SNDRV_PCM_INFO_SYNC_START | SNDRV_PCM_INFO_DOUBLE), |
| 5726 | .formats = SNDRV_PCM_FMTBIT_S32_LE, |
| 5727 | .rates = (SNDRV_PCM_RATE_32000 | |
| 5728 | SNDRV_PCM_RATE_44100 | |
| 5729 | SNDRV_PCM_RATE_48000 | |
| 5730 | SNDRV_PCM_RATE_64000 | |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 5731 | SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000 | |
| 5732 | SNDRV_PCM_RATE_176400 | SNDRV_PCM_RATE_192000 ), |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5733 | .rate_min = 32000, |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 5734 | .rate_max = 192000, |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5735 | .channels_min = 1, |
| 5736 | .channels_max = HDSPM_MAX_CHANNELS, |
| 5737 | .buffer_bytes_max = |
| 5738 | HDSPM_CHANNEL_BUFFER_BYTES * HDSPM_MAX_CHANNELS, |
Adrian Knoth | 1b6fa10 | 2011-08-15 00:22:51 +0200 | [diff] [blame] | 5739 | .period_bytes_min = (32 * 4), |
Takashi Iwai | 52e6fb4 | 2011-08-15 10:40:59 +0200 | [diff] [blame^] | 5740 | .period_bytes_max = (8192 * 4) * HDSPM_MAX_CHANNELS, |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5741 | .periods_min = 2, |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 5742 | .periods_max = 512, |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5743 | .fifo_size = 0 |
| 5744 | }; |
| 5745 | |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 5746 | static struct snd_pcm_hardware snd_hdspm_capture_subinfo = { |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5747 | .info = (SNDRV_PCM_INFO_MMAP | |
| 5748 | SNDRV_PCM_INFO_MMAP_VALID | |
| 5749 | SNDRV_PCM_INFO_NONINTERLEAVED | |
| 5750 | SNDRV_PCM_INFO_SYNC_START), |
| 5751 | .formats = SNDRV_PCM_FMTBIT_S32_LE, |
| 5752 | .rates = (SNDRV_PCM_RATE_32000 | |
| 5753 | SNDRV_PCM_RATE_44100 | |
| 5754 | SNDRV_PCM_RATE_48000 | |
| 5755 | SNDRV_PCM_RATE_64000 | |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 5756 | SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000 | |
| 5757 | SNDRV_PCM_RATE_176400 | SNDRV_PCM_RATE_192000), |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5758 | .rate_min = 32000, |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 5759 | .rate_max = 192000, |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5760 | .channels_min = 1, |
| 5761 | .channels_max = HDSPM_MAX_CHANNELS, |
| 5762 | .buffer_bytes_max = |
| 5763 | HDSPM_CHANNEL_BUFFER_BYTES * HDSPM_MAX_CHANNELS, |
Adrian Knoth | 1b6fa10 | 2011-08-15 00:22:51 +0200 | [diff] [blame] | 5764 | .period_bytes_min = (32 * 4), |
Takashi Iwai | 52e6fb4 | 2011-08-15 10:40:59 +0200 | [diff] [blame^] | 5765 | .period_bytes_max = (8192 * 4) * HDSPM_MAX_CHANNELS, |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5766 | .periods_min = 2, |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 5767 | .periods_max = 512, |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5768 | .fifo_size = 0 |
| 5769 | }; |
| 5770 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 5771 | static struct snd_pcm_hw_constraint_list hw_constraints_period_sizes_old = { |
| 5772 | .count = ARRAY_SIZE(period_sizes_old), |
| 5773 | .list = period_sizes_old, |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5774 | .mask = 0 |
| 5775 | }; |
| 5776 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 5777 | static struct snd_pcm_hw_constraint_list hw_constraints_period_sizes_new = { |
| 5778 | .count = ARRAY_SIZE(period_sizes_new), |
| 5779 | .list = period_sizes_new, |
| 5780 | .mask = 0 |
| 5781 | }; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5782 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 5783 | static struct snd_pcm_hw_constraint_list hw_constraints_raydat_io_buffer = { |
| 5784 | .count = ARRAY_SIZE(raydat_aio_buffer_sizes), |
| 5785 | .list = raydat_aio_buffer_sizes, |
| 5786 | .mask = 0 |
| 5787 | }; |
| 5788 | |
| 5789 | static int snd_hdspm_hw_rule_in_channels_rate(struct snd_pcm_hw_params *params, |
| 5790 | struct snd_pcm_hw_rule *rule) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5791 | { |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 5792 | struct hdspm *hdspm = rule->private; |
| 5793 | struct snd_interval *c = |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5794 | hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS); |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 5795 | struct snd_interval *r = |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5796 | hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE); |
| 5797 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 5798 | if (r->min > 96000 && r->max <= 192000) { |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 5799 | struct snd_interval t = { |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 5800 | .min = hdspm->qs_in_channels, |
| 5801 | .max = hdspm->qs_in_channels, |
| 5802 | .integer = 1, |
| 5803 | }; |
| 5804 | return snd_interval_refine(c, &t); |
| 5805 | } else if (r->min > 48000 && r->max <= 96000) { |
| 5806 | struct snd_interval t = { |
| 5807 | .min = hdspm->ds_in_channels, |
| 5808 | .max = hdspm->ds_in_channels, |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5809 | .integer = 1, |
| 5810 | }; |
| 5811 | return snd_interval_refine(c, &t); |
| 5812 | } else if (r->max < 64000) { |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 5813 | struct snd_interval t = { |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 5814 | .min = hdspm->ss_in_channels, |
| 5815 | .max = hdspm->ss_in_channels, |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5816 | .integer = 1, |
| 5817 | }; |
| 5818 | return snd_interval_refine(c, &t); |
| 5819 | } |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 5820 | |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5821 | return 0; |
| 5822 | } |
| 5823 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 5824 | static int snd_hdspm_hw_rule_out_channels_rate(struct snd_pcm_hw_params *params, |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 5825 | struct snd_pcm_hw_rule * rule) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5826 | { |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 5827 | struct hdspm *hdspm = rule->private; |
| 5828 | struct snd_interval *c = |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5829 | hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS); |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 5830 | struct snd_interval *r = |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5831 | hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE); |
| 5832 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 5833 | if (r->min > 96000 && r->max <= 192000) { |
| 5834 | struct snd_interval t = { |
| 5835 | .min = hdspm->qs_out_channels, |
| 5836 | .max = hdspm->qs_out_channels, |
| 5837 | .integer = 1, |
| 5838 | }; |
| 5839 | return snd_interval_refine(c, &t); |
| 5840 | } else if (r->min > 48000 && r->max <= 96000) { |
| 5841 | struct snd_interval t = { |
| 5842 | .min = hdspm->ds_out_channels, |
| 5843 | .max = hdspm->ds_out_channels, |
| 5844 | .integer = 1, |
| 5845 | }; |
| 5846 | return snd_interval_refine(c, &t); |
| 5847 | } else if (r->max < 64000) { |
| 5848 | struct snd_interval t = { |
| 5849 | .min = hdspm->ss_out_channels, |
| 5850 | .max = hdspm->ss_out_channels, |
| 5851 | .integer = 1, |
| 5852 | }; |
| 5853 | return snd_interval_refine(c, &t); |
| 5854 | } else { |
| 5855 | } |
| 5856 | return 0; |
| 5857 | } |
| 5858 | |
| 5859 | static int snd_hdspm_hw_rule_rate_in_channels(struct snd_pcm_hw_params *params, |
| 5860 | struct snd_pcm_hw_rule * rule) |
| 5861 | { |
| 5862 | struct hdspm *hdspm = rule->private; |
| 5863 | struct snd_interval *c = |
| 5864 | hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS); |
| 5865 | struct snd_interval *r = |
| 5866 | hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE); |
| 5867 | |
| 5868 | if (c->min >= hdspm->ss_in_channels) { |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 5869 | struct snd_interval t = { |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5870 | .min = 32000, |
| 5871 | .max = 48000, |
| 5872 | .integer = 1, |
| 5873 | }; |
| 5874 | return snd_interval_refine(r, &t); |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 5875 | } else if (c->max <= hdspm->qs_in_channels) { |
| 5876 | struct snd_interval t = { |
| 5877 | .min = 128000, |
| 5878 | .max = 192000, |
| 5879 | .integer = 1, |
| 5880 | }; |
| 5881 | return snd_interval_refine(r, &t); |
| 5882 | } else if (c->max <= hdspm->ds_in_channels) { |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 5883 | struct snd_interval t = { |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5884 | .min = 64000, |
| 5885 | .max = 96000, |
| 5886 | .integer = 1, |
| 5887 | }; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5888 | return snd_interval_refine(r, &t); |
| 5889 | } |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 5890 | |
| 5891 | return 0; |
| 5892 | } |
| 5893 | static int snd_hdspm_hw_rule_rate_out_channels(struct snd_pcm_hw_params *params, |
| 5894 | struct snd_pcm_hw_rule *rule) |
| 5895 | { |
| 5896 | struct hdspm *hdspm = rule->private; |
| 5897 | struct snd_interval *c = |
| 5898 | hw_param_interval(params, SNDRV_PCM_HW_PARAM_CHANNELS); |
| 5899 | struct snd_interval *r = |
| 5900 | hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE); |
| 5901 | |
| 5902 | if (c->min >= hdspm->ss_out_channels) { |
| 5903 | struct snd_interval t = { |
| 5904 | .min = 32000, |
| 5905 | .max = 48000, |
| 5906 | .integer = 1, |
| 5907 | }; |
| 5908 | return snd_interval_refine(r, &t); |
| 5909 | } else if (c->max <= hdspm->qs_out_channels) { |
| 5910 | struct snd_interval t = { |
| 5911 | .min = 128000, |
| 5912 | .max = 192000, |
| 5913 | .integer = 1, |
| 5914 | }; |
| 5915 | return snd_interval_refine(r, &t); |
| 5916 | } else if (c->max <= hdspm->ds_out_channels) { |
| 5917 | struct snd_interval t = { |
| 5918 | .min = 64000, |
| 5919 | .max = 96000, |
| 5920 | .integer = 1, |
| 5921 | }; |
| 5922 | return snd_interval_refine(r, &t); |
| 5923 | } |
| 5924 | |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5925 | return 0; |
| 5926 | } |
| 5927 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 5928 | static int snd_hdspm_hw_rule_in_channels(struct snd_pcm_hw_params *params, |
Remy Bruno | ffb2c3c | 2007-03-07 19:08:46 +0100 | [diff] [blame] | 5929 | struct snd_pcm_hw_rule *rule) |
| 5930 | { |
| 5931 | unsigned int list[3]; |
| 5932 | struct hdspm *hdspm = rule->private; |
| 5933 | struct snd_interval *c = hw_param_interval(params, |
| 5934 | SNDRV_PCM_HW_PARAM_CHANNELS); |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 5935 | |
| 5936 | list[0] = hdspm->qs_in_channels; |
| 5937 | list[1] = hdspm->ds_in_channels; |
| 5938 | list[2] = hdspm->ss_in_channels; |
| 5939 | return snd_interval_list(c, 3, list, 0); |
| 5940 | } |
| 5941 | |
| 5942 | static int snd_hdspm_hw_rule_out_channels(struct snd_pcm_hw_params *params, |
| 5943 | struct snd_pcm_hw_rule *rule) |
| 5944 | { |
| 5945 | unsigned int list[3]; |
| 5946 | struct hdspm *hdspm = rule->private; |
| 5947 | struct snd_interval *c = hw_param_interval(params, |
| 5948 | SNDRV_PCM_HW_PARAM_CHANNELS); |
| 5949 | |
| 5950 | list[0] = hdspm->qs_out_channels; |
| 5951 | list[1] = hdspm->ds_out_channels; |
| 5952 | list[2] = hdspm->ss_out_channels; |
| 5953 | return snd_interval_list(c, 3, list, 0); |
Remy Bruno | ffb2c3c | 2007-03-07 19:08:46 +0100 | [diff] [blame] | 5954 | } |
| 5955 | |
| 5956 | |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 5957 | static unsigned int hdspm_aes32_sample_rates[] = { |
| 5958 | 32000, 44100, 48000, 64000, 88200, 96000, 128000, 176400, 192000 |
| 5959 | }; |
Remy Bruno | ffb2c3c | 2007-03-07 19:08:46 +0100 | [diff] [blame] | 5960 | |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 5961 | static struct snd_pcm_hw_constraint_list |
| 5962 | hdspm_hw_constraints_aes32_sample_rates = { |
Remy Bruno | ffb2c3c | 2007-03-07 19:08:46 +0100 | [diff] [blame] | 5963 | .count = ARRAY_SIZE(hdspm_aes32_sample_rates), |
| 5964 | .list = hdspm_aes32_sample_rates, |
| 5965 | .mask = 0 |
| 5966 | }; |
| 5967 | |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 5968 | static int snd_hdspm_playback_open(struct snd_pcm_substream *substream) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5969 | { |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 5970 | struct hdspm *hdspm = snd_pcm_substream_chip(substream); |
| 5971 | struct snd_pcm_runtime *runtime = substream->runtime; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5972 | |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5973 | spin_lock_irq(&hdspm->lock); |
| 5974 | |
| 5975 | snd_pcm_set_sync(substream); |
| 5976 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 5977 | |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5978 | runtime->hw = snd_hdspm_playback_subinfo; |
| 5979 | |
| 5980 | if (hdspm->capture_substream == NULL) |
| 5981 | hdspm_stop_audio(hdspm); |
| 5982 | |
| 5983 | hdspm->playback_pid = current->pid; |
| 5984 | hdspm->playback_substream = substream; |
| 5985 | |
| 5986 | spin_unlock_irq(&hdspm->lock); |
| 5987 | |
| 5988 | snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24); |
| 5989 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 5990 | switch (hdspm->io_type) { |
| 5991 | case AIO: |
| 5992 | case RayDAT: |
| 5993 | snd_pcm_hw_constraint_list(runtime, 0, |
| 5994 | SNDRV_PCM_HW_PARAM_PERIOD_SIZE, |
| 5995 | &hw_constraints_period_sizes_new); |
| 5996 | snd_pcm_hw_constraint_list(runtime, 0, |
| 5997 | SNDRV_PCM_HW_PARAM_BUFFER_SIZE, |
| 5998 | &hw_constraints_raydat_io_buffer); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 5999 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 6000 | break; |
| 6001 | |
| 6002 | default: |
| 6003 | snd_pcm_hw_constraint_list(runtime, 0, |
| 6004 | SNDRV_PCM_HW_PARAM_PERIOD_SIZE, |
| 6005 | &hw_constraints_period_sizes_old); |
| 6006 | } |
| 6007 | |
| 6008 | if (AES32 == hdspm->io_type) { |
Remy Bruno | ffb2c3c | 2007-03-07 19:08:46 +0100 | [diff] [blame] | 6009 | snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, |
| 6010 | &hdspm_hw_constraints_aes32_sample_rates); |
| 6011 | } else { |
Remy Bruno | ffb2c3c | 2007-03-07 19:08:46 +0100 | [diff] [blame] | 6012 | snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 6013 | snd_hdspm_hw_rule_rate_out_channels, hdspm, |
| 6014 | SNDRV_PCM_HW_PARAM_CHANNELS, -1); |
Remy Bruno | ffb2c3c | 2007-03-07 19:08:46 +0100 | [diff] [blame] | 6015 | } |
Adrian Knoth | 88fabbf | 2011-02-23 11:43:10 +0100 | [diff] [blame] | 6016 | |
| 6017 | snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS, |
| 6018 | snd_hdspm_hw_rule_out_channels, hdspm, |
| 6019 | SNDRV_PCM_HW_PARAM_CHANNELS, -1); |
| 6020 | |
| 6021 | snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS, |
| 6022 | snd_hdspm_hw_rule_out_channels_rate, hdspm, |
| 6023 | SNDRV_PCM_HW_PARAM_RATE, -1); |
| 6024 | |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6025 | return 0; |
| 6026 | } |
| 6027 | |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 6028 | static int snd_hdspm_playback_release(struct snd_pcm_substream *substream) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6029 | { |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 6030 | struct hdspm *hdspm = snd_pcm_substream_chip(substream); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6031 | |
| 6032 | spin_lock_irq(&hdspm->lock); |
| 6033 | |
| 6034 | hdspm->playback_pid = -1; |
| 6035 | hdspm->playback_substream = NULL; |
| 6036 | |
| 6037 | spin_unlock_irq(&hdspm->lock); |
| 6038 | |
| 6039 | return 0; |
| 6040 | } |
| 6041 | |
| 6042 | |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 6043 | static int snd_hdspm_capture_open(struct snd_pcm_substream *substream) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6044 | { |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 6045 | struct hdspm *hdspm = snd_pcm_substream_chip(substream); |
| 6046 | struct snd_pcm_runtime *runtime = substream->runtime; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6047 | |
| 6048 | spin_lock_irq(&hdspm->lock); |
| 6049 | snd_pcm_set_sync(substream); |
| 6050 | runtime->hw = snd_hdspm_capture_subinfo; |
| 6051 | |
| 6052 | if (hdspm->playback_substream == NULL) |
| 6053 | hdspm_stop_audio(hdspm); |
| 6054 | |
| 6055 | hdspm->capture_pid = current->pid; |
| 6056 | hdspm->capture_substream = substream; |
| 6057 | |
| 6058 | spin_unlock_irq(&hdspm->lock); |
| 6059 | |
| 6060 | snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24); |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 6061 | switch (hdspm->io_type) { |
| 6062 | case AIO: |
| 6063 | case RayDAT: |
| 6064 | snd_pcm_hw_constraint_list(runtime, 0, |
| 6065 | SNDRV_PCM_HW_PARAM_PERIOD_SIZE, |
| 6066 | &hw_constraints_period_sizes_new); |
| 6067 | snd_pcm_hw_constraint_list(runtime, 0, |
| 6068 | SNDRV_PCM_HW_PARAM_BUFFER_SIZE, |
| 6069 | &hw_constraints_raydat_io_buffer); |
| 6070 | break; |
| 6071 | |
| 6072 | default: |
| 6073 | snd_pcm_hw_constraint_list(runtime, 0, |
| 6074 | SNDRV_PCM_HW_PARAM_PERIOD_SIZE, |
| 6075 | &hw_constraints_period_sizes_old); |
| 6076 | } |
| 6077 | |
| 6078 | if (AES32 == hdspm->io_type) { |
Remy Bruno | ffb2c3c | 2007-03-07 19:08:46 +0100 | [diff] [blame] | 6079 | snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, |
| 6080 | &hdspm_hw_constraints_aes32_sample_rates); |
| 6081 | } else { |
Remy Bruno | ffb2c3c | 2007-03-07 19:08:46 +0100 | [diff] [blame] | 6082 | snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, |
Adrian Knoth | 88fabbf | 2011-02-23 11:43:10 +0100 | [diff] [blame] | 6083 | snd_hdspm_hw_rule_rate_in_channels, hdspm, |
| 6084 | SNDRV_PCM_HW_PARAM_CHANNELS, -1); |
Remy Bruno | ffb2c3c | 2007-03-07 19:08:46 +0100 | [diff] [blame] | 6085 | } |
Adrian Knoth | 88fabbf | 2011-02-23 11:43:10 +0100 | [diff] [blame] | 6086 | |
| 6087 | snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS, |
| 6088 | snd_hdspm_hw_rule_in_channels, hdspm, |
| 6089 | SNDRV_PCM_HW_PARAM_CHANNELS, -1); |
| 6090 | |
| 6091 | snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS, |
| 6092 | snd_hdspm_hw_rule_in_channels_rate, hdspm, |
| 6093 | SNDRV_PCM_HW_PARAM_RATE, -1); |
| 6094 | |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6095 | return 0; |
| 6096 | } |
| 6097 | |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 6098 | static int snd_hdspm_capture_release(struct snd_pcm_substream *substream) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6099 | { |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 6100 | struct hdspm *hdspm = snd_pcm_substream_chip(substream); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6101 | |
| 6102 | spin_lock_irq(&hdspm->lock); |
| 6103 | |
| 6104 | hdspm->capture_pid = -1; |
| 6105 | hdspm->capture_substream = NULL; |
| 6106 | |
| 6107 | spin_unlock_irq(&hdspm->lock); |
| 6108 | return 0; |
| 6109 | } |
| 6110 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 6111 | static int snd_hdspm_hwdep_dummy_op(struct snd_hwdep *hw, struct file *file) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6112 | { |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 6113 | /* we have nothing to initialize but the call is required */ |
| 6114 | return 0; |
| 6115 | } |
| 6116 | |
| 6117 | static inline int copy_u32_le(void __user *dest, void __iomem *src) |
| 6118 | { |
| 6119 | u32 val = readl(src); |
| 6120 | return copy_to_user(dest, &val, 4); |
| 6121 | } |
| 6122 | |
| 6123 | static int snd_hdspm_hwdep_ioctl(struct snd_hwdep *hw, struct file *file, |
| 6124 | unsigned int cmd, unsigned long __user arg) |
| 6125 | { |
| 6126 | void __user *argp = (void __user *)arg; |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 6127 | struct hdspm *hdspm = hw->private_data; |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 6128 | struct hdspm_mixer_ioctl mixer; |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 6129 | struct hdspm_config info; |
| 6130 | struct hdspm_status status; |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 6131 | struct hdspm_version hdspm_version; |
Jaroslav Kysela | 730a586 | 2011-01-27 13:03:15 +0100 | [diff] [blame] | 6132 | struct hdspm_peak_rms *levels; |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 6133 | struct hdspm_ltc ltc; |
| 6134 | unsigned int statusregister; |
| 6135 | long unsigned int s; |
| 6136 | int i = 0; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6137 | |
| 6138 | switch (cmd) { |
| 6139 | |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6140 | case SNDRV_HDSPM_IOCTL_GET_PEAK_RMS: |
Jaroslav Kysela | 730a586 | 2011-01-27 13:03:15 +0100 | [diff] [blame] | 6141 | levels = &hdspm->peak_rms; |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 6142 | for (i = 0; i < HDSPM_MAX_CHANNELS; i++) { |
Jaroslav Kysela | 730a586 | 2011-01-27 13:03:15 +0100 | [diff] [blame] | 6143 | levels->input_peaks[i] = |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 6144 | readl(hdspm->iobase + |
| 6145 | HDSPM_MADI_INPUT_PEAK + i*4); |
Jaroslav Kysela | 730a586 | 2011-01-27 13:03:15 +0100 | [diff] [blame] | 6146 | levels->playback_peaks[i] = |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 6147 | readl(hdspm->iobase + |
| 6148 | HDSPM_MADI_PLAYBACK_PEAK + i*4); |
Jaroslav Kysela | 730a586 | 2011-01-27 13:03:15 +0100 | [diff] [blame] | 6149 | levels->output_peaks[i] = |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 6150 | readl(hdspm->iobase + |
| 6151 | HDSPM_MADI_OUTPUT_PEAK + i*4); |
| 6152 | |
Jaroslav Kysela | 730a586 | 2011-01-27 13:03:15 +0100 | [diff] [blame] | 6153 | levels->input_rms[i] = |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 6154 | ((uint64_t) readl(hdspm->iobase + |
| 6155 | HDSPM_MADI_INPUT_RMS_H + i*4) << 32) | |
| 6156 | (uint64_t) readl(hdspm->iobase + |
| 6157 | HDSPM_MADI_INPUT_RMS_L + i*4); |
Jaroslav Kysela | 730a586 | 2011-01-27 13:03:15 +0100 | [diff] [blame] | 6158 | levels->playback_rms[i] = |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 6159 | ((uint64_t)readl(hdspm->iobase + |
| 6160 | HDSPM_MADI_PLAYBACK_RMS_H+i*4) << 32) | |
| 6161 | (uint64_t)readl(hdspm->iobase + |
| 6162 | HDSPM_MADI_PLAYBACK_RMS_L + i*4); |
Jaroslav Kysela | 730a586 | 2011-01-27 13:03:15 +0100 | [diff] [blame] | 6163 | levels->output_rms[i] = |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 6164 | ((uint64_t)readl(hdspm->iobase + |
| 6165 | HDSPM_MADI_OUTPUT_RMS_H + i*4) << 32) | |
| 6166 | (uint64_t)readl(hdspm->iobase + |
| 6167 | HDSPM_MADI_OUTPUT_RMS_L + i*4); |
| 6168 | } |
| 6169 | |
| 6170 | if (hdspm->system_sample_rate > 96000) { |
Jaroslav Kysela | 730a586 | 2011-01-27 13:03:15 +0100 | [diff] [blame] | 6171 | levels->speed = qs; |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 6172 | } else if (hdspm->system_sample_rate > 48000) { |
Jaroslav Kysela | 730a586 | 2011-01-27 13:03:15 +0100 | [diff] [blame] | 6173 | levels->speed = ds; |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 6174 | } else { |
Jaroslav Kysela | 730a586 | 2011-01-27 13:03:15 +0100 | [diff] [blame] | 6175 | levels->speed = ss; |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 6176 | } |
Jaroslav Kysela | 730a586 | 2011-01-27 13:03:15 +0100 | [diff] [blame] | 6177 | levels->status2 = hdspm_read(hdspm, HDSPM_statusRegister2); |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 6178 | |
Jaroslav Kysela | 730a586 | 2011-01-27 13:03:15 +0100 | [diff] [blame] | 6179 | s = copy_to_user(argp, levels, sizeof(struct hdspm_peak_rms)); |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 6180 | if (0 != s) { |
| 6181 | /* snd_printk(KERN_ERR "copy_to_user(.., .., %lu): %lu |
| 6182 | [Levels]\n", sizeof(struct hdspm_peak_rms), s); |
| 6183 | */ |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6184 | return -EFAULT; |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 6185 | } |
| 6186 | break; |
| 6187 | |
| 6188 | case SNDRV_HDSPM_IOCTL_GET_LTC: |
| 6189 | ltc.ltc = hdspm_read(hdspm, HDSPM_RD_TCO); |
| 6190 | i = hdspm_read(hdspm, HDSPM_RD_TCO + 4); |
| 6191 | if (i & HDSPM_TCO1_LTC_Input_valid) { |
| 6192 | switch (i & (HDSPM_TCO1_LTC_Format_LSB | |
| 6193 | HDSPM_TCO1_LTC_Format_MSB)) { |
| 6194 | case 0: |
| 6195 | ltc.format = fps_24; |
| 6196 | break; |
| 6197 | case HDSPM_TCO1_LTC_Format_LSB: |
| 6198 | ltc.format = fps_25; |
| 6199 | break; |
| 6200 | case HDSPM_TCO1_LTC_Format_MSB: |
| 6201 | ltc.format = fps_2997; |
| 6202 | break; |
| 6203 | default: |
| 6204 | ltc.format = 30; |
| 6205 | break; |
| 6206 | } |
| 6207 | if (i & HDSPM_TCO1_set_drop_frame_flag) { |
| 6208 | ltc.frame = drop_frame; |
| 6209 | } else { |
| 6210 | ltc.frame = full_frame; |
| 6211 | } |
| 6212 | } else { |
| 6213 | ltc.format = format_invalid; |
| 6214 | ltc.frame = frame_invalid; |
| 6215 | } |
| 6216 | if (i & HDSPM_TCO1_Video_Input_Format_NTSC) { |
| 6217 | ltc.input_format = ntsc; |
| 6218 | } else if (i & HDSPM_TCO1_Video_Input_Format_PAL) { |
| 6219 | ltc.input_format = pal; |
| 6220 | } else { |
| 6221 | ltc.input_format = no_video; |
| 6222 | } |
| 6223 | |
| 6224 | s = copy_to_user(argp, <c, sizeof(struct hdspm_ltc)); |
| 6225 | if (0 != s) { |
| 6226 | /* |
| 6227 | snd_printk(KERN_ERR "copy_to_user(.., .., %lu): %lu [LTC]\n", sizeof(struct hdspm_ltc), s); */ |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6228 | return -EFAULT; |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 6229 | } |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6230 | |
| 6231 | break; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6232 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 6233 | case SNDRV_HDSPM_IOCTL_GET_CONFIG: |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6234 | |
Adrian Knoth | 4ab69a2 | 2011-02-23 11:43:14 +0100 | [diff] [blame] | 6235 | memset(&info, 0, sizeof(info)); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6236 | spin_lock_irq(&hdspm->lock); |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 6237 | info.pref_sync_ref = hdspm_pref_sync_ref(hdspm); |
| 6238 | info.wordclock_sync_check = hdspm_wc_sync_check(hdspm); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6239 | |
| 6240 | info.system_sample_rate = hdspm->system_sample_rate; |
| 6241 | info.autosync_sample_rate = |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 6242 | hdspm_external_sample_rate(hdspm); |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 6243 | info.system_clock_mode = hdspm_system_clock_mode(hdspm); |
| 6244 | info.clock_source = hdspm_clock_source(hdspm); |
| 6245 | info.autosync_ref = hdspm_autosync_ref(hdspm); |
| 6246 | info.line_out = hdspm_line_out(hdspm); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6247 | info.passthru = 0; |
| 6248 | spin_unlock_irq(&hdspm->lock); |
| 6249 | if (copy_to_user((void __user *) arg, &info, sizeof(info))) |
| 6250 | return -EFAULT; |
| 6251 | break; |
| 6252 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 6253 | case SNDRV_HDSPM_IOCTL_GET_STATUS: |
| 6254 | status.card_type = hdspm->io_type; |
| 6255 | |
| 6256 | status.autosync_source = hdspm_autosync_ref(hdspm); |
| 6257 | |
| 6258 | status.card_clock = 110069313433624ULL; |
| 6259 | status.master_period = hdspm_read(hdspm, HDSPM_RD_PLL_FREQ); |
| 6260 | |
| 6261 | switch (hdspm->io_type) { |
| 6262 | case MADI: |
| 6263 | case MADIface: |
| 6264 | status.card_specific.madi.sync_wc = |
| 6265 | hdspm_wc_sync_check(hdspm); |
| 6266 | status.card_specific.madi.sync_madi = |
| 6267 | hdspm_madi_sync_check(hdspm); |
| 6268 | status.card_specific.madi.sync_tco = |
| 6269 | hdspm_tco_sync_check(hdspm); |
| 6270 | status.card_specific.madi.sync_in = |
| 6271 | hdspm_sync_in_sync_check(hdspm); |
| 6272 | |
| 6273 | statusregister = |
| 6274 | hdspm_read(hdspm, HDSPM_statusRegister); |
| 6275 | status.card_specific.madi.madi_input = |
| 6276 | (statusregister & HDSPM_AB_int) ? 1 : 0; |
| 6277 | status.card_specific.madi.channel_format = |
| 6278 | (statusregister & HDSPM_TX_64ch) ? 1 : 0; |
| 6279 | /* TODO: Mac driver sets it when f_s>48kHz */ |
| 6280 | status.card_specific.madi.frame_format = 0; |
| 6281 | |
| 6282 | default: |
| 6283 | break; |
| 6284 | } |
| 6285 | |
| 6286 | if (copy_to_user((void __user *) arg, &status, sizeof(status))) |
| 6287 | return -EFAULT; |
| 6288 | |
| 6289 | |
| 6290 | break; |
| 6291 | |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6292 | case SNDRV_HDSPM_IOCTL_GET_VERSION: |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 6293 | hdspm_version.card_type = hdspm->io_type; |
| 6294 | strncpy(hdspm_version.cardname, hdspm->card_name, |
| 6295 | sizeof(hdspm_version.cardname)); |
| 6296 | hdspm_version.serial = (hdspm_read(hdspm, |
| 6297 | HDSPM_midiStatusIn0)>>8) & 0xFFFFFF; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6298 | hdspm_version.firmware_rev = hdspm->firmware_rev; |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 6299 | hdspm_version.addons = 0; |
| 6300 | if (hdspm->tco) |
| 6301 | hdspm_version.addons |= HDSPM_ADDON_TCO; |
| 6302 | |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6303 | if (copy_to_user((void __user *) arg, &hdspm_version, |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 6304 | sizeof(hdspm_version))) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6305 | return -EFAULT; |
| 6306 | break; |
| 6307 | |
| 6308 | case SNDRV_HDSPM_IOCTL_GET_MIXER: |
| 6309 | if (copy_from_user(&mixer, (void __user *)arg, sizeof(mixer))) |
| 6310 | return -EFAULT; |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 6311 | if (copy_to_user((void __user *)mixer.mixer, hdspm->mixer, |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 6312 | sizeof(struct hdspm_mixer))) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6313 | return -EFAULT; |
| 6314 | break; |
| 6315 | |
| 6316 | default: |
| 6317 | return -EINVAL; |
| 6318 | } |
| 6319 | return 0; |
| 6320 | } |
| 6321 | |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 6322 | static struct snd_pcm_ops snd_hdspm_playback_ops = { |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6323 | .open = snd_hdspm_playback_open, |
| 6324 | .close = snd_hdspm_playback_release, |
| 6325 | .ioctl = snd_hdspm_ioctl, |
| 6326 | .hw_params = snd_hdspm_hw_params, |
| 6327 | .hw_free = snd_hdspm_hw_free, |
| 6328 | .prepare = snd_hdspm_prepare, |
| 6329 | .trigger = snd_hdspm_trigger, |
| 6330 | .pointer = snd_hdspm_hw_pointer, |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6331 | .page = snd_pcm_sgbuf_ops_page, |
| 6332 | }; |
| 6333 | |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 6334 | static struct snd_pcm_ops snd_hdspm_capture_ops = { |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6335 | .open = snd_hdspm_capture_open, |
| 6336 | .close = snd_hdspm_capture_release, |
| 6337 | .ioctl = snd_hdspm_ioctl, |
| 6338 | .hw_params = snd_hdspm_hw_params, |
| 6339 | .hw_free = snd_hdspm_hw_free, |
| 6340 | .prepare = snd_hdspm_prepare, |
| 6341 | .trigger = snd_hdspm_trigger, |
| 6342 | .pointer = snd_hdspm_hw_pointer, |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6343 | .page = snd_pcm_sgbuf_ops_page, |
| 6344 | }; |
| 6345 | |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 6346 | static int __devinit snd_hdspm_create_hwdep(struct snd_card *card, |
| 6347 | struct hdspm * hdspm) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6348 | { |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 6349 | struct snd_hwdep *hw; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6350 | int err; |
| 6351 | |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 6352 | err = snd_hwdep_new(card, "HDSPM hwdep", 0, &hw); |
| 6353 | if (err < 0) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6354 | return err; |
| 6355 | |
| 6356 | hdspm->hwdep = hw; |
| 6357 | hw->private_data = hdspm; |
| 6358 | strcpy(hw->name, "HDSPM hwdep interface"); |
| 6359 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 6360 | hw->ops.open = snd_hdspm_hwdep_dummy_op; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6361 | hw->ops.ioctl = snd_hdspm_hwdep_ioctl; |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 6362 | hw->ops.release = snd_hdspm_hwdep_dummy_op; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6363 | |
| 6364 | return 0; |
| 6365 | } |
| 6366 | |
| 6367 | |
| 6368 | /*------------------------------------------------------------ |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 6369 | memory interface |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6370 | ------------------------------------------------------------*/ |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 6371 | static int __devinit snd_hdspm_preallocate_memory(struct hdspm *hdspm) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6372 | { |
| 6373 | int err; |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 6374 | struct snd_pcm *pcm; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6375 | size_t wanted; |
| 6376 | |
| 6377 | pcm = hdspm->pcm; |
| 6378 | |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 6379 | wanted = HDSPM_DMA_AREA_BYTES; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6380 | |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 6381 | err = |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6382 | snd_pcm_lib_preallocate_pages_for_all(pcm, |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 6383 | SNDRV_DMA_TYPE_DEV_SG, |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6384 | snd_dma_pci_data(hdspm->pci), |
| 6385 | wanted, |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 6386 | wanted); |
| 6387 | if (err < 0) { |
Andrew Morton | e2eba3e | 2006-01-20 14:07:13 +0100 | [diff] [blame] | 6388 | snd_printdd("Could not preallocate %zd Bytes\n", wanted); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6389 | |
| 6390 | return err; |
| 6391 | } else |
Andrew Morton | e2eba3e | 2006-01-20 14:07:13 +0100 | [diff] [blame] | 6392 | snd_printdd(" Preallocated %zd Bytes\n", wanted); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6393 | |
| 6394 | return 0; |
| 6395 | } |
| 6396 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 6397 | |
| 6398 | static void hdspm_set_sgbuf(struct hdspm *hdspm, |
Takashi Iwai | 77a23f2 | 2008-08-21 13:00:13 +0200 | [diff] [blame] | 6399 | struct snd_pcm_substream *substream, |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6400 | unsigned int reg, int channels) |
| 6401 | { |
| 6402 | int i; |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 6403 | |
| 6404 | /* continuous memory segment */ |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6405 | for (i = 0; i < (channels * 16); i++) |
| 6406 | hdspm_write(hdspm, reg + 4 * i, |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 6407 | snd_pcm_sgbuf_get_addr(substream, 4096 * i)); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6408 | } |
| 6409 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 6410 | |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6411 | /* ------------- ALSA Devices ---------------------------- */ |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 6412 | static int __devinit snd_hdspm_create_pcm(struct snd_card *card, |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 6413 | struct hdspm *hdspm) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6414 | { |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 6415 | struct snd_pcm *pcm; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6416 | int err; |
| 6417 | |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 6418 | err = snd_pcm_new(card, hdspm->card_name, 0, 1, 1, &pcm); |
| 6419 | if (err < 0) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6420 | return err; |
| 6421 | |
| 6422 | hdspm->pcm = pcm; |
| 6423 | pcm->private_data = hdspm; |
| 6424 | strcpy(pcm->name, hdspm->card_name); |
| 6425 | |
| 6426 | snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, |
| 6427 | &snd_hdspm_playback_ops); |
| 6428 | snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, |
| 6429 | &snd_hdspm_capture_ops); |
| 6430 | |
| 6431 | pcm->info_flags = SNDRV_PCM_INFO_JOINT_DUPLEX; |
| 6432 | |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 6433 | err = snd_hdspm_preallocate_memory(hdspm); |
| 6434 | if (err < 0) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6435 | return err; |
| 6436 | |
| 6437 | return 0; |
| 6438 | } |
| 6439 | |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 6440 | static inline void snd_hdspm_initialize_midi_flush(struct hdspm * hdspm) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6441 | { |
Adrian Knoth | 7c7102b | 2011-02-28 15:14:50 +0100 | [diff] [blame] | 6442 | int i; |
| 6443 | |
| 6444 | for (i = 0; i < hdspm->midiPorts; i++) |
| 6445 | snd_hdspm_flush_midi_input(hdspm, i); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6446 | } |
| 6447 | |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 6448 | static int __devinit snd_hdspm_create_alsa_devices(struct snd_card *card, |
| 6449 | struct hdspm * hdspm) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6450 | { |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 6451 | int err, i; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6452 | |
| 6453 | snd_printdd("Create card...\n"); |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 6454 | err = snd_hdspm_create_pcm(card, hdspm); |
| 6455 | if (err < 0) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6456 | return err; |
| 6457 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 6458 | i = 0; |
| 6459 | while (i < hdspm->midiPorts) { |
| 6460 | err = snd_hdspm_create_midi(card, hdspm, i); |
| 6461 | if (err < 0) { |
| 6462 | return err; |
| 6463 | } |
| 6464 | i++; |
| 6465 | } |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6466 | |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 6467 | err = snd_hdspm_create_controls(card, hdspm); |
| 6468 | if (err < 0) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6469 | return err; |
| 6470 | |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 6471 | err = snd_hdspm_create_hwdep(card, hdspm); |
| 6472 | if (err < 0) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6473 | return err; |
| 6474 | |
| 6475 | snd_printdd("proc init...\n"); |
| 6476 | snd_hdspm_proc_init(hdspm); |
| 6477 | |
| 6478 | hdspm->system_sample_rate = -1; |
| 6479 | hdspm->last_external_sample_rate = -1; |
| 6480 | hdspm->last_internal_sample_rate = -1; |
| 6481 | hdspm->playback_pid = -1; |
| 6482 | hdspm->capture_pid = -1; |
| 6483 | hdspm->capture_substream = NULL; |
| 6484 | hdspm->playback_substream = NULL; |
| 6485 | |
| 6486 | snd_printdd("Set defaults...\n"); |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 6487 | err = snd_hdspm_set_defaults(hdspm); |
| 6488 | if (err < 0) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6489 | return err; |
| 6490 | |
| 6491 | snd_printdd("Update mixer controls...\n"); |
| 6492 | hdspm_update_simple_mixer_controls(hdspm); |
| 6493 | |
| 6494 | snd_printdd("Initializeing complete ???\n"); |
| 6495 | |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 6496 | err = snd_card_register(card); |
| 6497 | if (err < 0) { |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6498 | snd_printk(KERN_ERR "HDSPM: error registering card\n"); |
| 6499 | return err; |
| 6500 | } |
| 6501 | |
| 6502 | snd_printdd("... yes now\n"); |
| 6503 | |
| 6504 | return 0; |
| 6505 | } |
| 6506 | |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 6507 | static int __devinit snd_hdspm_create(struct snd_card *card, |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 6508 | struct hdspm *hdspm) { |
| 6509 | |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6510 | struct pci_dev *pci = hdspm->pci; |
| 6511 | int err; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6512 | unsigned long io_extent; |
| 6513 | |
| 6514 | hdspm->irq = -1; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6515 | hdspm->card = card; |
| 6516 | |
| 6517 | spin_lock_init(&hdspm->lock); |
| 6518 | |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6519 | pci_read_config_word(hdspm->pci, |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 6520 | PCI_CLASS_REVISION, &hdspm->firmware_rev); |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 6521 | |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6522 | strcpy(card->mixername, "Xilinx FPGA"); |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 6523 | strcpy(card->driver, "HDSPM"); |
| 6524 | |
| 6525 | switch (hdspm->firmware_rev) { |
| 6526 | case HDSPM_MADI_REV: |
Adrian Knoth | efef054 | 2011-06-12 17:26:19 +0200 | [diff] [blame] | 6527 | case HDSPM_MADI_OLD_REV: |
Adrian Knoth | 5f8b4d5 | 2011-07-29 03:11:04 +0200 | [diff] [blame] | 6528 | case HDSPM_MADI_ANCIENT_REV: |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 6529 | hdspm->io_type = MADI; |
| 6530 | hdspm->card_name = "RME MADI"; |
| 6531 | hdspm->midiPorts = 3; |
| 6532 | break; |
| 6533 | case HDSPM_RAYDAT_REV: |
| 6534 | hdspm->io_type = RayDAT; |
| 6535 | hdspm->card_name = "RME RayDAT"; |
| 6536 | hdspm->midiPorts = 2; |
| 6537 | break; |
| 6538 | case HDSPM_AIO_REV: |
| 6539 | hdspm->io_type = AIO; |
| 6540 | hdspm->card_name = "RME AIO"; |
| 6541 | hdspm->midiPorts = 1; |
| 6542 | break; |
| 6543 | case HDSPM_MADIFACE_REV: |
| 6544 | hdspm->io_type = MADIface; |
| 6545 | hdspm->card_name = "RME MADIface"; |
| 6546 | hdspm->midiPorts = 1; |
| 6547 | break; |
| 6548 | case HDSPM_AES_REV: |
Adrian Knoth | 526ea86 | 2011-02-28 15:14:48 +0100 | [diff] [blame] | 6549 | case HDSPM_AES32_REV: |
Adrian Knoth | bdd3255 | 2011-03-07 19:10:11 +0100 | [diff] [blame] | 6550 | case HDSPM_AES32_OLD_REV: |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 6551 | hdspm->io_type = AES32; |
| 6552 | hdspm->card_name = "RME AES32"; |
| 6553 | hdspm->midiPorts = 2; |
| 6554 | break; |
Adrian Knoth | 5027f34 | 2011-02-28 15:14:49 +0100 | [diff] [blame] | 6555 | default: |
| 6556 | snd_printk(KERN_ERR "HDSPM: unknown firmware revision %x\n", |
| 6557 | hdspm->firmware_rev); |
| 6558 | return -ENODEV; |
Remy Bruno | 3cee5a6 | 2006-10-16 12:46:32 +0200 | [diff] [blame] | 6559 | } |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6560 | |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 6561 | err = pci_enable_device(pci); |
| 6562 | if (err < 0) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6563 | return err; |
| 6564 | |
| 6565 | pci_set_master(hdspm->pci); |
| 6566 | |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 6567 | err = pci_request_regions(pci, "hdspm"); |
| 6568 | if (err < 0) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6569 | return err; |
| 6570 | |
| 6571 | hdspm->port = pci_resource_start(pci, 0); |
| 6572 | io_extent = pci_resource_len(pci, 0); |
| 6573 | |
| 6574 | snd_printdd("grabbed memory region 0x%lx-0x%lx\n", |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 6575 | hdspm->port, hdspm->port + io_extent - 1); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6576 | |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 6577 | hdspm->iobase = ioremap_nocache(hdspm->port, io_extent); |
| 6578 | if (!hdspm->iobase) { |
| 6579 | snd_printk(KERN_ERR "HDSPM: " |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 6580 | "unable to remap region 0x%lx-0x%lx\n", |
| 6581 | hdspm->port, hdspm->port + io_extent - 1); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6582 | return -EBUSY; |
| 6583 | } |
| 6584 | snd_printdd("remapped region (0x%lx) 0x%lx-0x%lx\n", |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 6585 | (unsigned long)hdspm->iobase, hdspm->port, |
| 6586 | hdspm->port + io_extent - 1); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6587 | |
| 6588 | if (request_irq(pci->irq, snd_hdspm_interrupt, |
Takashi Iwai | 934c2b6 | 2011-06-10 16:36:37 +0200 | [diff] [blame] | 6589 | IRQF_SHARED, KBUILD_MODNAME, hdspm)) { |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6590 | snd_printk(KERN_ERR "HDSPM: unable to use IRQ %d\n", pci->irq); |
| 6591 | return -EBUSY; |
| 6592 | } |
| 6593 | |
| 6594 | snd_printdd("use IRQ %d\n", pci->irq); |
| 6595 | |
| 6596 | hdspm->irq = pci->irq; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6597 | |
Andrew Morton | e2eba3e | 2006-01-20 14:07:13 +0100 | [diff] [blame] | 6598 | snd_printdd("kmalloc Mixer memory of %zd Bytes\n", |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 6599 | sizeof(struct hdspm_mixer)); |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 6600 | hdspm->mixer = kzalloc(sizeof(struct hdspm_mixer), GFP_KERNEL); |
| 6601 | if (!hdspm->mixer) { |
| 6602 | snd_printk(KERN_ERR "HDSPM: " |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 6603 | "unable to kmalloc Mixer memory of %d Bytes\n", |
| 6604 | (int)sizeof(struct hdspm_mixer)); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6605 | return err; |
| 6606 | } |
| 6607 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 6608 | hdspm->port_names_in = NULL; |
| 6609 | hdspm->port_names_out = NULL; |
| 6610 | |
| 6611 | switch (hdspm->io_type) { |
| 6612 | case AES32: |
Adrian Knoth | d2d10a2 | 2011-02-28 15:14:47 +0100 | [diff] [blame] | 6613 | hdspm->ss_in_channels = hdspm->ss_out_channels = AES32_CHANNELS; |
| 6614 | hdspm->ds_in_channels = hdspm->ds_out_channels = AES32_CHANNELS; |
| 6615 | hdspm->qs_in_channels = hdspm->qs_out_channels = AES32_CHANNELS; |
Adrian Knoth | 432d250 | 2011-02-23 11:43:08 +0100 | [diff] [blame] | 6616 | |
| 6617 | hdspm->channel_map_in_ss = hdspm->channel_map_out_ss = |
| 6618 | channel_map_aes32; |
| 6619 | hdspm->channel_map_in_ds = hdspm->channel_map_out_ds = |
| 6620 | channel_map_aes32; |
| 6621 | hdspm->channel_map_in_qs = hdspm->channel_map_out_qs = |
| 6622 | channel_map_aes32; |
| 6623 | hdspm->port_names_in_ss = hdspm->port_names_out_ss = |
| 6624 | texts_ports_aes32; |
| 6625 | hdspm->port_names_in_ds = hdspm->port_names_out_ds = |
| 6626 | texts_ports_aes32; |
| 6627 | hdspm->port_names_in_qs = hdspm->port_names_out_qs = |
| 6628 | texts_ports_aes32; |
| 6629 | |
Adrian Knoth | d2d10a2 | 2011-02-28 15:14:47 +0100 | [diff] [blame] | 6630 | hdspm->max_channels_out = hdspm->max_channels_in = |
| 6631 | AES32_CHANNELS; |
Adrian Knoth | 432d250 | 2011-02-23 11:43:08 +0100 | [diff] [blame] | 6632 | hdspm->port_names_in = hdspm->port_names_out = |
| 6633 | texts_ports_aes32; |
| 6634 | hdspm->channel_map_in = hdspm->channel_map_out = |
| 6635 | channel_map_aes32; |
| 6636 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 6637 | break; |
| 6638 | |
| 6639 | case MADI: |
| 6640 | case MADIface: |
| 6641 | hdspm->ss_in_channels = hdspm->ss_out_channels = |
| 6642 | MADI_SS_CHANNELS; |
| 6643 | hdspm->ds_in_channels = hdspm->ds_out_channels = |
| 6644 | MADI_DS_CHANNELS; |
| 6645 | hdspm->qs_in_channels = hdspm->qs_out_channels = |
| 6646 | MADI_QS_CHANNELS; |
| 6647 | |
| 6648 | hdspm->channel_map_in_ss = hdspm->channel_map_out_ss = |
| 6649 | channel_map_unity_ss; |
Adrian Knoth | 01e9607 | 2011-02-23 11:43:11 +0100 | [diff] [blame] | 6650 | hdspm->channel_map_in_ds = hdspm->channel_map_out_ds = |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 6651 | channel_map_unity_ss; |
Adrian Knoth | 01e9607 | 2011-02-23 11:43:11 +0100 | [diff] [blame] | 6652 | hdspm->channel_map_in_qs = hdspm->channel_map_out_qs = |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 6653 | channel_map_unity_ss; |
| 6654 | |
| 6655 | hdspm->port_names_in_ss = hdspm->port_names_out_ss = |
| 6656 | texts_ports_madi; |
| 6657 | hdspm->port_names_in_ds = hdspm->port_names_out_ds = |
| 6658 | texts_ports_madi; |
| 6659 | hdspm->port_names_in_qs = hdspm->port_names_out_qs = |
| 6660 | texts_ports_madi; |
| 6661 | break; |
| 6662 | |
| 6663 | case AIO: |
| 6664 | if (0 == (hdspm_read(hdspm, HDSPM_statusRegister2) & HDSPM_s2_AEBI_D)) { |
| 6665 | snd_printk(KERN_INFO "HDSPM: AEB input board found, but not supported\n"); |
| 6666 | } |
| 6667 | |
| 6668 | hdspm->ss_in_channels = AIO_IN_SS_CHANNELS; |
| 6669 | hdspm->ds_in_channels = AIO_IN_DS_CHANNELS; |
| 6670 | hdspm->qs_in_channels = AIO_IN_QS_CHANNELS; |
| 6671 | hdspm->ss_out_channels = AIO_OUT_SS_CHANNELS; |
| 6672 | hdspm->ds_out_channels = AIO_OUT_DS_CHANNELS; |
| 6673 | hdspm->qs_out_channels = AIO_OUT_QS_CHANNELS; |
| 6674 | |
| 6675 | hdspm->channel_map_out_ss = channel_map_aio_out_ss; |
| 6676 | hdspm->channel_map_out_ds = channel_map_aio_out_ds; |
| 6677 | hdspm->channel_map_out_qs = channel_map_aio_out_qs; |
| 6678 | |
| 6679 | hdspm->channel_map_in_ss = channel_map_aio_in_ss; |
| 6680 | hdspm->channel_map_in_ds = channel_map_aio_in_ds; |
| 6681 | hdspm->channel_map_in_qs = channel_map_aio_in_qs; |
| 6682 | |
| 6683 | hdspm->port_names_in_ss = texts_ports_aio_in_ss; |
| 6684 | hdspm->port_names_out_ss = texts_ports_aio_out_ss; |
| 6685 | hdspm->port_names_in_ds = texts_ports_aio_in_ds; |
| 6686 | hdspm->port_names_out_ds = texts_ports_aio_out_ds; |
| 6687 | hdspm->port_names_in_qs = texts_ports_aio_in_qs; |
| 6688 | hdspm->port_names_out_qs = texts_ports_aio_out_qs; |
| 6689 | |
| 6690 | break; |
| 6691 | |
| 6692 | case RayDAT: |
| 6693 | hdspm->ss_in_channels = hdspm->ss_out_channels = |
| 6694 | RAYDAT_SS_CHANNELS; |
| 6695 | hdspm->ds_in_channels = hdspm->ds_out_channels = |
| 6696 | RAYDAT_DS_CHANNELS; |
| 6697 | hdspm->qs_in_channels = hdspm->qs_out_channels = |
| 6698 | RAYDAT_QS_CHANNELS; |
| 6699 | |
| 6700 | hdspm->max_channels_in = RAYDAT_SS_CHANNELS; |
| 6701 | hdspm->max_channels_out = RAYDAT_SS_CHANNELS; |
| 6702 | |
| 6703 | hdspm->channel_map_in_ss = hdspm->channel_map_out_ss = |
| 6704 | channel_map_raydat_ss; |
| 6705 | hdspm->channel_map_in_ds = hdspm->channel_map_out_ds = |
| 6706 | channel_map_raydat_ds; |
| 6707 | hdspm->channel_map_in_qs = hdspm->channel_map_out_qs = |
| 6708 | channel_map_raydat_qs; |
| 6709 | hdspm->channel_map_in = hdspm->channel_map_out = |
| 6710 | channel_map_raydat_ss; |
| 6711 | |
| 6712 | hdspm->port_names_in_ss = hdspm->port_names_out_ss = |
| 6713 | texts_ports_raydat_ss; |
| 6714 | hdspm->port_names_in_ds = hdspm->port_names_out_ds = |
| 6715 | texts_ports_raydat_ds; |
| 6716 | hdspm->port_names_in_qs = hdspm->port_names_out_qs = |
| 6717 | texts_ports_raydat_qs; |
| 6718 | |
| 6719 | |
| 6720 | break; |
| 6721 | |
| 6722 | } |
| 6723 | |
| 6724 | /* TCO detection */ |
| 6725 | switch (hdspm->io_type) { |
| 6726 | case AIO: |
| 6727 | case RayDAT: |
| 6728 | if (hdspm_read(hdspm, HDSPM_statusRegister2) & |
| 6729 | HDSPM_s2_tco_detect) { |
| 6730 | hdspm->midiPorts++; |
| 6731 | hdspm->tco = kzalloc(sizeof(struct hdspm_tco), |
| 6732 | GFP_KERNEL); |
| 6733 | if (NULL != hdspm->tco) { |
| 6734 | hdspm_tco_write(hdspm); |
| 6735 | } |
| 6736 | snd_printk(KERN_INFO "HDSPM: AIO/RayDAT TCO module found\n"); |
| 6737 | } else { |
| 6738 | hdspm->tco = NULL; |
| 6739 | } |
| 6740 | break; |
| 6741 | |
| 6742 | case MADI: |
| 6743 | if (hdspm_read(hdspm, HDSPM_statusRegister) & HDSPM_tco_detect) { |
| 6744 | hdspm->midiPorts++; |
| 6745 | hdspm->tco = kzalloc(sizeof(struct hdspm_tco), |
| 6746 | GFP_KERNEL); |
| 6747 | if (NULL != hdspm->tco) { |
| 6748 | hdspm_tco_write(hdspm); |
| 6749 | } |
| 6750 | snd_printk(KERN_INFO "HDSPM: MADI TCO module found\n"); |
| 6751 | } else { |
| 6752 | hdspm->tco = NULL; |
| 6753 | } |
| 6754 | break; |
| 6755 | |
| 6756 | default: |
| 6757 | hdspm->tco = NULL; |
| 6758 | } |
| 6759 | |
| 6760 | /* texts */ |
| 6761 | switch (hdspm->io_type) { |
| 6762 | case AES32: |
| 6763 | if (hdspm->tco) { |
| 6764 | hdspm->texts_autosync = texts_autosync_aes_tco; |
| 6765 | hdspm->texts_autosync_items = 10; |
| 6766 | } else { |
| 6767 | hdspm->texts_autosync = texts_autosync_aes; |
| 6768 | hdspm->texts_autosync_items = 9; |
| 6769 | } |
| 6770 | break; |
| 6771 | |
| 6772 | case MADI: |
| 6773 | if (hdspm->tco) { |
| 6774 | hdspm->texts_autosync = texts_autosync_madi_tco; |
| 6775 | hdspm->texts_autosync_items = 4; |
| 6776 | } else { |
| 6777 | hdspm->texts_autosync = texts_autosync_madi; |
| 6778 | hdspm->texts_autosync_items = 3; |
| 6779 | } |
| 6780 | break; |
| 6781 | |
| 6782 | case MADIface: |
| 6783 | |
| 6784 | break; |
| 6785 | |
| 6786 | case RayDAT: |
| 6787 | if (hdspm->tco) { |
| 6788 | hdspm->texts_autosync = texts_autosync_raydat_tco; |
| 6789 | hdspm->texts_autosync_items = 9; |
| 6790 | } else { |
| 6791 | hdspm->texts_autosync = texts_autosync_raydat; |
| 6792 | hdspm->texts_autosync_items = 8; |
| 6793 | } |
| 6794 | break; |
| 6795 | |
| 6796 | case AIO: |
| 6797 | if (hdspm->tco) { |
| 6798 | hdspm->texts_autosync = texts_autosync_aio_tco; |
| 6799 | hdspm->texts_autosync_items = 6; |
| 6800 | } else { |
| 6801 | hdspm->texts_autosync = texts_autosync_aio; |
| 6802 | hdspm->texts_autosync_items = 5; |
| 6803 | } |
| 6804 | break; |
| 6805 | |
| 6806 | } |
| 6807 | |
| 6808 | tasklet_init(&hdspm->midi_tasklet, |
| 6809 | hdspm_midi_tasklet, (unsigned long) hdspm); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6810 | |
| 6811 | snd_printdd("create alsa devices.\n"); |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 6812 | err = snd_hdspm_create_alsa_devices(card, hdspm); |
| 6813 | if (err < 0) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6814 | return err; |
| 6815 | |
| 6816 | snd_hdspm_initialize_midi_flush(hdspm); |
| 6817 | |
| 6818 | return 0; |
| 6819 | } |
| 6820 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 6821 | |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 6822 | static int snd_hdspm_free(struct hdspm * hdspm) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6823 | { |
| 6824 | |
| 6825 | if (hdspm->port) { |
| 6826 | |
| 6827 | /* stop th audio, and cancel all interrupts */ |
| 6828 | hdspm->control_register &= |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 6829 | ~(HDSPM_Start | HDSPM_AudioInterruptEnable | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 6830 | HDSPM_Midi0InterruptEnable | HDSPM_Midi1InterruptEnable | |
| 6831 | HDSPM_Midi2InterruptEnable | HDSPM_Midi3InterruptEnable); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6832 | hdspm_write(hdspm, HDSPM_controlRegister, |
| 6833 | hdspm->control_register); |
| 6834 | } |
| 6835 | |
| 6836 | if (hdspm->irq >= 0) |
| 6837 | free_irq(hdspm->irq, (void *) hdspm); |
| 6838 | |
Jesper Juhl | fc58422 | 2005-10-24 15:11:28 +0200 | [diff] [blame] | 6839 | kfree(hdspm->mixer); |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6840 | |
| 6841 | if (hdspm->iobase) |
| 6842 | iounmap(hdspm->iobase); |
| 6843 | |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6844 | if (hdspm->port) |
| 6845 | pci_release_regions(hdspm->pci); |
| 6846 | |
| 6847 | pci_disable_device(hdspm->pci); |
| 6848 | return 0; |
| 6849 | } |
| 6850 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 6851 | |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 6852 | static void snd_hdspm_card_free(struct snd_card *card) |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6853 | { |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 6854 | struct hdspm *hdspm = card->private_data; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6855 | |
| 6856 | if (hdspm) |
| 6857 | snd_hdspm_free(hdspm); |
| 6858 | } |
| 6859 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 6860 | |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6861 | static int __devinit snd_hdspm_probe(struct pci_dev *pci, |
| 6862 | const struct pci_device_id *pci_id) |
| 6863 | { |
| 6864 | static int dev; |
Takashi Iwai | 98274f0 | 2005-11-17 14:52:34 +0100 | [diff] [blame] | 6865 | struct hdspm *hdspm; |
| 6866 | struct snd_card *card; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6867 | int err; |
| 6868 | |
| 6869 | if (dev >= SNDRV_CARDS) |
| 6870 | return -ENODEV; |
| 6871 | if (!enable[dev]) { |
| 6872 | dev++; |
| 6873 | return -ENOENT; |
| 6874 | } |
| 6875 | |
Takashi Iwai | e58de7b | 2008-12-28 16:44:30 +0100 | [diff] [blame] | 6876 | err = snd_card_create(index[dev], id[dev], |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 6877 | THIS_MODULE, sizeof(struct hdspm), &card); |
Takashi Iwai | e58de7b | 2008-12-28 16:44:30 +0100 | [diff] [blame] | 6878 | if (err < 0) |
| 6879 | return err; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6880 | |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 6881 | hdspm = card->private_data; |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6882 | card->private_free = snd_hdspm_card_free; |
| 6883 | hdspm->dev = dev; |
| 6884 | hdspm->pci = pci; |
| 6885 | |
Takashi Iwai | c187c04 | 2007-02-19 15:27:33 +0100 | [diff] [blame] | 6886 | snd_card_set_dev(card, &pci->dev); |
| 6887 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 6888 | err = snd_hdspm_create(card, hdspm); |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 6889 | if (err < 0) { |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6890 | snd_card_free(card); |
| 6891 | return err; |
| 6892 | } |
| 6893 | |
Adrian Knoth | 0dca179 | 2011-01-26 19:32:14 +0100 | [diff] [blame] | 6894 | if (hdspm->io_type != MADIface) { |
| 6895 | sprintf(card->shortname, "%s_%x", |
| 6896 | hdspm->card_name, |
| 6897 | (hdspm_read(hdspm, HDSPM_midiStatusIn0)>>8) & 0xFFFFFF); |
| 6898 | sprintf(card->longname, "%s S/N 0x%x at 0x%lx, irq %d", |
| 6899 | hdspm->card_name, |
| 6900 | (hdspm_read(hdspm, HDSPM_midiStatusIn0)>>8) & 0xFFFFFF, |
| 6901 | hdspm->port, hdspm->irq); |
| 6902 | } else { |
| 6903 | sprintf(card->shortname, "%s", hdspm->card_name); |
| 6904 | sprintf(card->longname, "%s at 0x%lx, irq %d", |
| 6905 | hdspm->card_name, hdspm->port, hdspm->irq); |
| 6906 | } |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6907 | |
Takashi Iwai | ef5fa1a | 2007-07-27 16:52:46 +0200 | [diff] [blame] | 6908 | err = snd_card_register(card); |
| 6909 | if (err < 0) { |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6910 | snd_card_free(card); |
| 6911 | return err; |
| 6912 | } |
| 6913 | |
| 6914 | pci_set_drvdata(pci, card); |
| 6915 | |
| 6916 | dev++; |
| 6917 | return 0; |
| 6918 | } |
| 6919 | |
| 6920 | static void __devexit snd_hdspm_remove(struct pci_dev *pci) |
| 6921 | { |
| 6922 | snd_card_free(pci_get_drvdata(pci)); |
| 6923 | pci_set_drvdata(pci, NULL); |
| 6924 | } |
| 6925 | |
| 6926 | static struct pci_driver driver = { |
Takashi Iwai | 3733e42 | 2011-06-10 16:20:20 +0200 | [diff] [blame] | 6927 | .name = KBUILD_MODNAME, |
Takashi Iwai | 763f356 | 2005-06-03 11:25:34 +0200 | [diff] [blame] | 6928 | .id_table = snd_hdspm_ids, |
| 6929 | .probe = snd_hdspm_probe, |
| 6930 | .remove = __devexit_p(snd_hdspm_remove), |
| 6931 | }; |
| 6932 | |
| 6933 | |
| 6934 | static int __init alsa_card_hdspm_init(void) |
| 6935 | { |
| 6936 | return pci_register_driver(&driver); |
| 6937 | } |
| 6938 | |
| 6939 | static void __exit alsa_card_hdspm_exit(void) |
| 6940 | { |
| 6941 | pci_unregister_driver(&driver); |
| 6942 | } |
| 6943 | |
| 6944 | module_init(alsa_card_hdspm_init) |
| 6945 | module_exit(alsa_card_hdspm_exit) |