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