27 #include <linux/pci.h>
28 #include <linux/slab.h>
29 #include <linux/gameport.h>
30 #include <linux/module.h>
49 "{C-Media,CMI8338B}}");
51 #if defined(CONFIG_GAMEPORT) || (defined(MODULE) && defined(CONFIG_GAMEPORT_MODULE))
52 #define SUPPORT_JOYSTICK 1
61 #ifdef SUPPORT_JOYSTICK
76 MODULE_PARM_DESC(soft_ac3,
"Software-conversion of raw SPDIF packets (model 033 only).");
77 #ifdef SUPPORT_JOYSTICK
86 #define CM_REG_FUNCTRL0 0x00
87 #define CM_RST_CH1 0x00080000
88 #define CM_RST_CH0 0x00040000
89 #define CM_CHEN1 0x00020000
90 #define CM_CHEN0 0x00010000
91 #define CM_PAUSE1 0x00000008
92 #define CM_PAUSE0 0x00000004
93 #define CM_CHADC1 0x00000002
94 #define CM_CHADC0 0x00000001
96 #define CM_REG_FUNCTRL1 0x04
97 #define CM_DSFC_MASK 0x0000E000
98 #define CM_DSFC_SHIFT 13
99 #define CM_ASFC_MASK 0x00001C00
100 #define CM_ASFC_SHIFT 10
101 #define CM_SPDF_1 0x00000200
102 #define CM_SPDF_0 0x00000100
103 #define CM_SPDFLOOP 0x00000080
104 #define CM_SPDO2DAC 0x00000040
105 #define CM_INTRM 0x00000020
106 #define CM_BREQ 0x00000010
107 #define CM_VOICE_EN 0x00000008
108 #define CM_UART_EN 0x00000004
109 #define CM_JYSTK_EN 0x00000002
110 #define CM_ZVPORT 0x00000001
112 #define CM_REG_CHFORMAT 0x08
114 #define CM_CHB3D5C 0x80000000
115 #define CM_FMOFFSET2 0x40000000
116 #define CM_CHB3D 0x20000000
118 #define CM_CHIP_MASK1 0x1f000000
119 #define CM_CHIP_037 0x01000000
120 #define CM_SETLAT48 0x00800000
121 #define CM_EDGEIRQ 0x00400000
122 #define CM_SPD24SEL39 0x00200000
123 #define CM_AC3EN1 0x00100000
124 #define CM_SPDIF_SELECT1 0x00080000
125 #define CM_SPD24SEL 0x00020000
128 #define CM_ADCBITLEN_MASK 0x0000C000
129 #define CM_ADCBITLEN_16 0x00000000
130 #define CM_ADCBITLEN_15 0x00004000
131 #define CM_ADCBITLEN_14 0x00008000
132 #define CM_ADCBITLEN_13 0x0000C000
134 #define CM_ADCDACLEN_MASK 0x00003000
135 #define CM_ADCDACLEN_060 0x00000000
136 #define CM_ADCDACLEN_066 0x00001000
137 #define CM_ADCDACLEN_130 0x00002000
138 #define CM_ADCDACLEN_280 0x00003000
140 #define CM_ADCDLEN_MASK 0x00003000
141 #define CM_ADCDLEN_ORIGINAL 0x00000000
142 #define CM_ADCDLEN_EXTRA 0x00001000
143 #define CM_ADCDLEN_24K 0x00002000
144 #define CM_ADCDLEN_WEIGHT 0x00003000
146 #define CM_CH1_SRATE_176K 0x00000800
147 #define CM_CH1_SRATE_96K 0x00000800
148 #define CM_CH1_SRATE_88K 0x00000400
149 #define CM_CH0_SRATE_176K 0x00000200
150 #define CM_CH0_SRATE_96K 0x00000200
151 #define CM_CH0_SRATE_88K 0x00000100
152 #define CM_CH0_SRATE_128K 0x00000300
153 #define CM_CH0_SRATE_MASK 0x00000300
155 #define CM_SPDIF_INVERSE2 0x00000080
156 #define CM_DBLSPDS 0x00000040
157 #define CM_POLVALID 0x00000020
158 #define CM_SPDLOCKED 0x00000010
160 #define CM_CH1FMT_MASK 0x0000000C
161 #define CM_CH1FMT_SHIFT 2
162 #define CM_CH0FMT_MASK 0x00000003
163 #define CM_CH0FMT_SHIFT 0
165 #define CM_REG_INT_HLDCLR 0x0C
166 #define CM_CHIP_MASK2 0xff000000
167 #define CM_CHIP_8768 0x20000000
168 #define CM_CHIP_055 0x08000000
169 #define CM_CHIP_039 0x04000000
170 #define CM_CHIP_039_6CH 0x01000000
171 #define CM_UNKNOWN_INT_EN 0x00080000
172 #define CM_TDMA_INT_EN 0x00040000
173 #define CM_CH1_INT_EN 0x00020000
174 #define CM_CH0_INT_EN 0x00010000
176 #define CM_REG_INT_STATUS 0x10
177 #define CM_INTR 0x80000000
178 #define CM_VCO 0x08000000
179 #define CM_MCBINT 0x04000000
180 #define CM_UARTINT 0x00010000
181 #define CM_LTDMAINT 0x00008000
182 #define CM_HTDMAINT 0x00004000
183 #define CM_XDO46 0x00000080
184 #define CM_LHBTOG 0x00000040
185 #define CM_LEG_HDMA 0x00000020
186 #define CM_LEG_STEREO 0x00000010
187 #define CM_CH1BUSY 0x00000008
188 #define CM_CH0BUSY 0x00000004
189 #define CM_CHINT1 0x00000002
190 #define CM_CHINT0 0x00000001
192 #define CM_REG_LEGACY_CTRL 0x14
193 #define CM_NXCHG 0x80000000
194 #define CM_VMPU_MASK 0x60000000
195 #define CM_VMPU_330 0x00000000
196 #define CM_VMPU_320 0x20000000
197 #define CM_VMPU_310 0x40000000
198 #define CM_VMPU_300 0x60000000
199 #define CM_ENWR8237 0x10000000
200 #define CM_VSBSEL_MASK 0x0C000000
201 #define CM_VSBSEL_220 0x00000000
202 #define CM_VSBSEL_240 0x04000000
203 #define CM_VSBSEL_260 0x08000000
204 #define CM_VSBSEL_280 0x0C000000
205 #define CM_FMSEL_MASK 0x03000000
206 #define CM_FMSEL_388 0x00000000
207 #define CM_FMSEL_3C8 0x01000000
208 #define CM_FMSEL_3E0 0x02000000
209 #define CM_FMSEL_3E8 0x03000000
210 #define CM_ENSPDOUT 0x00800000
211 #define CM_SPDCOPYRHT 0x00400000
212 #define CM_DAC2SPDO 0x00200000
213 #define CM_INVIDWEN 0x00100000
214 #define CM_SETRETRY 0x00100000
215 #define CM_C_EEACCESS 0x00080000
216 #define CM_C_EECS 0x00040000
217 #define CM_C_EEDI46 0x00020000
218 #define CM_C_EECK46 0x00010000
219 #define CM_CHB3D6C 0x00008000
220 #define CM_CENTR2LIN 0x00004000
221 #define CM_BASE2LIN 0x00002000
222 #define CM_EXBASEN 0x00001000
224 #define CM_REG_MISC_CTRL 0x18
225 #define CM_PWD 0x80000000
226 #define CM_RESET 0x40000000
227 #define CM_SFIL_MASK 0x30000000
228 #define CM_VMGAIN 0x10000000
229 #define CM_TXVX 0x08000000
230 #define CM_N4SPK3D 0x04000000
231 #define CM_SPDO5V 0x02000000
232 #define CM_SPDIF48K 0x01000000
233 #define CM_SPATUS48K 0x01000000
234 #define CM_ENDBDAC 0x00800000
235 #define CM_XCHGDAC 0x00400000
236 #define CM_SPD32SEL 0x00200000
237 #define CM_SPDFLOOPI 0x00100000
238 #define CM_FM_EN 0x00080000
239 #define CM_AC3EN2 0x00040000
240 #define CM_ENWRASID 0x00010000
241 #define CM_VIDWPDSB 0x00010000
242 #define CM_SPDF_AC97 0x00008000
243 #define CM_MASK_EN 0x00004000
244 #define CM_ENWRMSID 0x00002000
245 #define CM_VIDWPPRT 0x00002000
246 #define CM_SFILENB 0x00001000
247 #define CM_MMODE_MASK 0x00000E00
248 #define CM_SPDIF_SELECT2 0x00000100
249 #define CM_ENCENTER 0x00000080
250 #define CM_FLINKON 0x00000040
251 #define CM_MUTECH1 0x00000040
252 #define CM_FLINKOFF 0x00000020
253 #define CM_MIDSMP 0x00000010
254 #define CM_UPDDMA_MASK 0x0000000C
255 #define CM_UPDDMA_2048 0x00000000
256 #define CM_UPDDMA_1024 0x00000004
257 #define CM_UPDDMA_512 0x00000008
258 #define CM_UPDDMA_256 0x0000000C
259 #define CM_TWAIT_MASK 0x00000003
260 #define CM_TWAIT1 0x00000002
261 #define CM_TWAIT0 0x00000001
263 #define CM_REG_TDMA_POSITION 0x1C
264 #define CM_TDMA_CNT_MASK 0xFFFF0000
265 #define CM_TDMA_ADR_MASK 0x0000FFFF
268 #define CM_REG_MIXER0 0x20
269 #define CM_REG_SBVR 0x20
270 #define CM_REG_DEV 0x20
272 #define CM_REG_MIXER21 0x21
273 #define CM_UNKNOWN_21_MASK 0x78
274 #define CM_X_ADPCM 0x04
275 #define CM_PROINV 0x02
276 #define CM_X_SB16 0x01
278 #define CM_REG_SB16_DATA 0x22
279 #define CM_REG_SB16_ADDR 0x23
281 #define CM_REFFREQ_XIN (315*1000*1000)/22
282 #define CM_ADCMULT_XIN 512
283 #define CM_TOLERANCE_RATE 0.001
284 #define CM_MAXIMUM_RATE 80000000
286 #define CM_REG_MIXER1 0x24
287 #define CM_FMMUTE 0x80
288 #define CM_FMMUTE_SHIFT 7
289 #define CM_WSMUTE 0x40
290 #define CM_WSMUTE_SHIFT 6
291 #define CM_REAR2LIN 0x20
292 #define CM_REAR2LIN_SHIFT 5
293 #define CM_REAR2FRONT 0x10
294 #define CM_REAR2FRONT_SHIFT 4
295 #define CM_WAVEINL 0x08
296 #define CM_WAVEINL_SHIFT 3
297 #define CM_WAVEINR 0x04
298 #define CM_WAVEINR_SHIFT 2
299 #define CM_X3DEN 0x02
300 #define CM_X3DEN_SHIFT 1
301 #define CM_CDPLAY 0x01
302 #define CM_CDPLAY_SHIFT 0
304 #define CM_REG_MIXER2 0x25
305 #define CM_RAUXREN 0x80
306 #define CM_RAUXREN_SHIFT 7
307 #define CM_RAUXLEN 0x40
308 #define CM_RAUXLEN_SHIFT 6
309 #define CM_VAUXRM 0x20
310 #define CM_VAUXRM_SHIFT 5
311 #define CM_VAUXLM 0x10
312 #define CM_VAUXLM_SHIFT 4
313 #define CM_VADMIC_MASK 0x0e
314 #define CM_VADMIC_SHIFT 1
315 #define CM_MICGAINZ 0x01
316 #define CM_MICGAINZ_SHIFT 0
318 #define CM_REG_MIXER3 0x24
319 #define CM_REG_AUX_VOL 0x26
320 #define CM_VAUXL_MASK 0xf0
321 #define CM_VAUXR_MASK 0x0f
323 #define CM_REG_MISC 0x27
324 #define CM_UNKNOWN_27_MASK 0xd8
325 #define CM_XGPO1 0x20
327 #define CM_MIC_CENTER_LFE 0x04
328 #define CM_SPDIF_INVERSE 0x04
329 #define CM_SPDVALID 0x02
330 #define CM_DMAUTO 0x01
332 #define CM_REG_AC97 0x28
337 #define CM_REG_EXTERN_CODEC CM_REG_AC97
342 #define CM_REG_MPU_PCI 0x40
347 #define CM_REG_FM_PCI 0x50
352 #define CM_REG_EXTENT_IND 0xf0
353 #define CM_VPHONE_MASK 0xe0
354 #define CM_VPHONE_SHIFT 5
355 #define CM_VPHOM 0x10
356 #define CM_VSPKM 0x08
357 #define CM_RLOOPREN 0x04
358 #define CM_RLOOPLEN 0x02
359 #define CM_VADMIC3 0x01
366 #define CM_REG_PLL 0xf8
371 #define CM_REG_CH0_FRAME1 0x80
372 #define CM_REG_CH0_FRAME2 0x84
373 #define CM_REG_CH1_FRAME1 0x88
374 #define CM_REG_CH1_FRAME2 0x8C
376 #define CM_REG_EXT_MISC 0x90
377 #define CM_ADC48K44K 0x10000000
378 #define CM_CHB3D8C 0x00200000
379 #define CM_SPD32FMT 0x00100000
380 #define CM_ADC2SPDIF 0x00080000
381 #define CM_SHAREADC 0x00040000
382 #define CM_REALTCMP 0x00020000
383 #define CM_INVLRCK 0x00010000
384 #define CM_UNKNOWN_90_MASK 0x0000FFFF
389 #define CM_EXTENT_CODEC 0x100
390 #define CM_EXTENT_MIDI 0x2
391 #define CM_EXTENT_SYNTH 0x4
403 #define CM_OPEN_NONE 0
404 #define CM_OPEN_CH_MASK 0x01
405 #define CM_OPEN_DAC 0x10
406 #define CM_OPEN_ADC 0x20
407 #define CM_OPEN_SPDIF 0x40
408 #define CM_OPEN_MCHAN 0x80
409 #define CM_OPEN_PLAYBACK (CM_CH_PLAY | CM_OPEN_DAC)
410 #define CM_OPEN_PLAYBACK2 (CM_CH_CAPT | CM_OPEN_DAC)
411 #define CM_OPEN_PLAYBACK_MULTI (CM_CH_PLAY | CM_OPEN_DAC | CM_OPEN_MCHAN)
412 #define CM_OPEN_CAPTURE (CM_CH_CAPT | CM_OPEN_ADC)
413 #define CM_OPEN_SPDIF_PLAYBACK (CM_CH_PLAY | CM_OPEN_DAC | CM_OPEN_SPDIF)
414 #define CM_OPEN_SPDIF_CAPTURE (CM_CH_CAPT | CM_OPEN_ADC | CM_OPEN_SPDIF)
418 #define CM_PLAYBACK_SRATE_176K CM_CH1_SRATE_176K
419 #define CM_PLAYBACK_SPDF CM_SPDF_1
420 #define CM_CAPTURE_SPDF CM_SPDF_0
422 #define CM_PLAYBACK_SRATE_176K CM_CH0_SRATE_176K
423 #define CM_PLAYBACK_SPDF CM_SPDF_0
424 #define CM_CAPTURE_SPDF CM_SPDF_1
450 {
"PCM Playback Switch", 0},
451 {
"IEC958 Output Switch", 1},
452 {
"IEC958 Mix Analog", 0},
456 #define CM_SAVED_MIXERS ARRAY_SIZE(cm_saved_mixer)
501 #ifdef SUPPORT_JOYSTICK
507 #ifdef CONFIG_PM_SLEEP
509 unsigned char saved_mixers[0x20];
515 static inline void snd_cmipci_write(
struct cmipci *cm,
unsigned int cmd,
unsigned int data)
520 static inline unsigned int snd_cmipci_read(
struct cmipci *cm,
unsigned int cmd)
526 static inline void snd_cmipci_write_w(
struct cmipci *cm,
unsigned int cmd,
unsigned short data)
531 static inline unsigned short snd_cmipci_read_w(
struct cmipci *cm,
unsigned int cmd)
537 static inline void snd_cmipci_write_b(
struct cmipci *cm,
unsigned int cmd,
unsigned char data)
542 static inline unsigned char snd_cmipci_read_b(
struct cmipci *cm,
unsigned int cmd)
548 static int snd_cmipci_set_bit(
struct cmipci *cm,
unsigned int cmd,
unsigned int flag)
550 unsigned int val, oval;
559 static int snd_cmipci_clear_bit(
struct cmipci *cm,
unsigned int cmd,
unsigned int flag)
561 unsigned int val, oval;
571 static int snd_cmipci_set_bit_b(
struct cmipci *cm,
unsigned int cmd,
unsigned char flag)
573 unsigned char val, oval;
582 static int snd_cmipci_clear_bit_b(
struct cmipci *cm,
unsigned int cmd,
unsigned char flag)
584 unsigned char val, oval;
602 static unsigned int rates[] = { 5512, 11025, 22050, 44100, 8000, 16000, 32000, 48000 };
604 static unsigned int snd_cmipci_rate_freq(
unsigned int rate)
609 if (rates[i] == rate)
616 #ifdef USE_VAR48KRATE
622 static int snd_cmipci_pll_rmn(
unsigned int rate,
unsigned int adcmult,
int *
r,
int *
m,
int *
n)
624 unsigned int delta, tolerance;
634 for (xn = (1+2); xn < (0x1f+2); xn++) {
635 for (xm = (1+2); xm < (0xff+2); xm++) {
647 if (delta < tolerance) {
664 static void snd_cmipci_set_pll(
struct cmipci *cm,
unsigned int rate,
unsigned int slot)
675 snd_cmipci_write_b(cm, reg, rate>>8);
676 snd_cmipci_write_b(cm, reg, rate&0xff);
705 static void snd_cmipci_ch_reset(
struct cmipci *cm,
int ch)
722 static unsigned int hw_channels[] = {1, 2, 4, 6, 8};
744 if (rec->
fmt != 0x03)
782 static int snd_cmipci_pcm_prepare(
struct cmipci *cm,
struct cmipci_pcm *rec,
786 unsigned int period_size;
798 if (rec->
is_dac && set_dac_channels(cm, rec, runtime->
channels) < 0) {
810 period_size = (period_size * runtime->
channels) / 2;
817 snd_cmipci_write(cm, reg, rec->
offset);
820 snd_cmipci_write_w(cm, reg, rec->
dma_size - 1);
821 snd_cmipci_write_w(cm, reg + 2, period_size - 1);
835 if (runtime->
rate > 48000)
836 switch (runtime->
rate) {
843 freq = snd_cmipci_rate_freq(runtime->
rate);
866 val |= freq_ext << (rec->
ch * 2);
872 if (runtime->
rate > 44100)
887 static int snd_cmipci_pcm_trigger(
struct cmipci *cm,
struct cmipci_pcm *rec,
944 unsigned int reg, rem, tries;
948 #if 1 // this seems better..
950 for (tries = 0; tries < 3; tries++) {
951 rem = snd_cmipci_read_w(cm, reg);
952 if (rem < rec->dma_size)
961 ptr = snd_cmipci_read(cm, reg) - rec->
offset;
962 ptr = bytes_to_frames(substream->
runtime, ptr);
964 if (substream->
runtime->channels > 2)
965 ptr = (ptr * 2) / substream->
runtime->channels;
1010 static int snd_cmipci_spdif_default_info(
struct snd_kcontrol *kcontrol,
1018 static int snd_cmipci_spdif_default_get(
struct snd_kcontrol *kcontrol,
1025 for (i = 0; i < 4; i++)
1026 ucontrol->
value.iec958.status[i] = (chip->
dig_status >> (i * 8)) & 0xff;
1031 static int snd_cmipci_spdif_default_put(
struct snd_kcontrol *kcontrol,
1040 for (i = 0; i < 4; i++)
1041 val |= (
unsigned int)ucontrol->
value.iec958.status[
i] << (i * 8);
1052 .info = snd_cmipci_spdif_default_info,
1053 .get = snd_cmipci_spdif_default_get,
1054 .put = snd_cmipci_spdif_default_put
1057 static int snd_cmipci_spdif_mask_info(
struct snd_kcontrol *kcontrol,
1065 static int snd_cmipci_spdif_mask_get(
struct snd_kcontrol *kcontrol,
1068 ucontrol->
value.iec958.status[0] = 0xff;
1069 ucontrol->
value.iec958.status[1] = 0xff;
1070 ucontrol->
value.iec958.status[2] = 0xff;
1071 ucontrol->
value.iec958.status[3] = 0xff;
1080 .info = snd_cmipci_spdif_mask_info,
1081 .get = snd_cmipci_spdif_mask_get,
1084 static int snd_cmipci_spdif_stream_info(
struct snd_kcontrol *kcontrol,
1092 static int snd_cmipci_spdif_stream_get(
struct snd_kcontrol *kcontrol,
1099 for (i = 0; i < 4; i++)
1105 static int snd_cmipci_spdif_stream_put(
struct snd_kcontrol *kcontrol,
1114 for (i = 0; i < 4; i++)
1115 val |= (
unsigned int)ucontrol->
value.iec958.status[
i] << (i * 8);
1127 .info = snd_cmipci_spdif_stream_info,
1128 .get = snd_cmipci_spdif_stream_get,
1129 .put = snd_cmipci_spdif_stream_put
1136 static int save_mixer_state(
struct cmipci *cm)
1149 memset(val, 0,
sizeof(*val));
1170 static void restore_mixer_state(
struct cmipci *cm)
1186 memset(val, 0,
sizeof(*val));
1221 if (rate >= 48000) {
1257 if ((err = save_mixer_state(cm)) < 0)
1268 setup_ac3(cm, subs, do_ac3, rate);
1270 if (rate == 48000 || rate == 96000)
1284 setup_ac3(cm, subs, 0, 0);
1299 int rate = substream->
runtime->rate;
1300 int err, do_spdif, do_ac3 = 0;
1302 do_spdif = (rate >= 44100 && rate <= 96000 &&
1304 substream->
runtime->channels == 2);
1307 if ((err = setup_spdif_playback(cm, substream, do_spdif, do_ac3)) < 0)
1313 static int snd_cmipci_playback_spdif_prepare(
struct snd_pcm_substream *substream)
1322 if ((err = setup_spdif_playback(cm, substream, 1, do_ac3)) < 0)
1335 static void snd_cmipci_silence_hack(
struct cmipci *cm,
struct cmipci_pcm *rec)
1345 snd_cmipci_write(cm, reg, val);
1349 set_dac_channels(cm, rec, 2);
1384 setup_spdif_playback(cm, substream, 0, 0);
1385 restore_mixer_state(cm);
1386 snd_cmipci_silence_hack(cm, &cm->
channel[0]);
1387 return snd_cmipci_hw_free(substream);
1393 snd_cmipci_silence_hack(cm, &cm->
channel[1]);
1394 return snd_cmipci_hw_free(substream);
1405 static int snd_cmipci_capture_spdif_prepare(
struct snd_pcm_substream *substream)
1412 if (substream->
runtime->rate > 48000)
1436 return snd_cmipci_hw_free(subs);
1467 if ((status & CM_CHINT0) && cm->
channel[0].running)
1469 if ((status & CM_CHINT1) && cm->
channel[1].running)
1492 .period_bytes_min = 64,
1493 .period_bytes_max = (128*1024),
1512 .period_bytes_min = 64,
1513 .period_bytes_max = (128*1024),
1532 .period_bytes_min = 64,
1533 .period_bytes_max = (128*1024),
1552 .period_bytes_min = 64,
1553 .period_bytes_max = (128*1024),
1572 .period_bytes_min = 64,
1573 .period_bytes_max = (128*1024),
1593 .period_bytes_min = 64,
1594 .period_bytes_max = (128*1024),
1600 static unsigned int rate_constraints[] = { 5512, 8000, 11025, 16000, 22050,
1601 32000, 44100, 48000, 88200, 96000, 128000 };
1604 .list = rate_constraints,
1626 cm->
channel[ch].substream = subs;
1638 static void close_device_check(
struct cmipci *cm,
int mode)
1643 if (cm->
opened[ch] == mode) {
1644 if (cm->
channel[ch].substream) {
1645 snd_cmipci_ch_reset(cm, ch);
1650 if (! cm->
channel[ch].is_dac) {
1672 runtime->
hw = snd_cmipci_playback;
1676 runtime->
hw.rate_max = 96000;
1683 runtime->
hw.rate_max = 128000;
1698 runtime->
hw = snd_cmipci_capture;
1700 runtime->
hw.rate_min = 41000;
1708 runtime->
hw.rate_max = 128000;
1722 runtime->
hw = snd_cmipci_playback2;
1739 runtime->
hw.rate_max = 96000;
1746 runtime->
hw.rate_max = 128000;
1761 runtime->
hw = snd_cmipci_playback_spdif;
1769 runtime->
hw.rate_max = 96000;
1772 runtime->
hw = snd_cmipci_playback_iec958_subframe;
1787 runtime->
hw = snd_cmipci_capture_spdif;
1791 runtime->
hw.rate_max = 96000;
1841 static struct snd_pcm_ops snd_cmipci_playback_ops = {
1842 .open = snd_cmipci_playback_open,
1843 .close = snd_cmipci_playback_close,
1845 .hw_params = snd_cmipci_hw_params,
1846 .hw_free = snd_cmipci_playback_hw_free,
1847 .prepare = snd_cmipci_playback_prepare,
1848 .trigger = snd_cmipci_playback_trigger,
1849 .pointer = snd_cmipci_playback_pointer,
1852 static struct snd_pcm_ops snd_cmipci_capture_ops = {
1853 .open = snd_cmipci_capture_open,
1854 .close = snd_cmipci_capture_close,
1856 .hw_params = snd_cmipci_hw_params,
1857 .hw_free = snd_cmipci_hw_free,
1858 .prepare = snd_cmipci_capture_prepare,
1859 .trigger = snd_cmipci_capture_trigger,
1860 .pointer = snd_cmipci_capture_pointer,
1863 static struct snd_pcm_ops snd_cmipci_playback2_ops = {
1864 .open = snd_cmipci_playback2_open,
1865 .close = snd_cmipci_playback2_close,
1867 .hw_params = snd_cmipci_playback2_hw_params,
1868 .hw_free = snd_cmipci_playback2_hw_free,
1869 .prepare = snd_cmipci_capture_prepare,
1870 .trigger = snd_cmipci_capture_trigger,
1871 .pointer = snd_cmipci_capture_pointer,
1874 static struct snd_pcm_ops snd_cmipci_playback_spdif_ops = {
1875 .open = snd_cmipci_playback_spdif_open,
1876 .close = snd_cmipci_playback_spdif_close,
1878 .hw_params = snd_cmipci_hw_params,
1879 .hw_free = snd_cmipci_playback_hw_free,
1880 .prepare = snd_cmipci_playback_spdif_prepare,
1881 .trigger = snd_cmipci_playback_trigger,
1882 .pointer = snd_cmipci_playback_pointer,
1885 static struct snd_pcm_ops snd_cmipci_capture_spdif_ops = {
1886 .open = snd_cmipci_capture_spdif_open,
1887 .close = snd_cmipci_capture_spdif_close,
1889 .hw_params = snd_cmipci_hw_params,
1890 .hw_free = snd_cmipci_capture_spdif_hw_free,
1891 .prepare = snd_cmipci_capture_spdif_prepare,
1892 .trigger = snd_cmipci_capture_trigger,
1893 .pointer = snd_cmipci_capture_pointer,
1923 static int __devinit snd_cmipci_pcm2_new(
struct cmipci *cm,
int device)
1945 static int __devinit snd_cmipci_pcm_spdif_new(
struct cmipci *cm,
int device)
1983 static void snd_cmipci_mixer_write(
struct cmipci *
s,
unsigned char idx,
unsigned char data)
1989 static unsigned char snd_cmipci_mixer_read(
struct cmipci *
s,
unsigned char idx)
2009 #define COMPOSE_SB_REG(lreg,rreg,lshift,rshift,mask,invert,stereo) \
2010 ((lreg) | ((rreg) << 8) | (lshift << 16) | (rshift << 19) | (mask << 24) | (invert << 22) | (stereo << 23))
2012 #define CMIPCI_DOUBLE(xname, left_reg, right_reg, left_shift, right_shift, mask, invert, stereo) \
2013 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
2014 .info = snd_cmipci_info_volume, \
2015 .get = snd_cmipci_get_volume, .put = snd_cmipci_put_volume, \
2016 .private_value = COMPOSE_SB_REG(left_reg, right_reg, left_shift, right_shift, mask, invert, stereo), \
2019 #define CMIPCI_SB_VOL_STEREO(xname,reg,shift,mask) CMIPCI_DOUBLE(xname, reg, reg+1, shift, shift, mask, 0, 1)
2020 #define CMIPCI_SB_VOL_MONO(xname,reg,shift,mask) CMIPCI_DOUBLE(xname, reg, reg, shift, shift, mask, 0, 0)
2021 #define CMIPCI_SB_SW_STEREO(xname,lshift,rshift) CMIPCI_DOUBLE(xname, SB_DSP4_OUTPUT_SW, SB_DSP4_OUTPUT_SW, lshift, rshift, 1, 0, 1)
2022 #define CMIPCI_SB_SW_MONO(xname,shift) CMIPCI_DOUBLE(xname, SB_DSP4_OUTPUT_SW, SB_DSP4_OUTPUT_SW, shift, shift, 1, 0, 0)
2024 static void cmipci_sb_reg_decode(
struct cmipci_sb_reg *r,
unsigned long val)
2030 r->
invert = (val >> 22) & 1;
2031 r->
stereo = (val >> 23) & 1;
2032 r->
mask = (val >> 24) & 0xff;
2035 static int snd_cmipci_info_volume(
struct snd_kcontrol *kcontrol,
2042 uinfo->
count = reg.stereo + 1;
2048 static int snd_cmipci_get_volume(
struct snd_kcontrol *kcontrol,
2057 val = (snd_cmipci_mixer_read(cm, reg.left_reg) >> reg.left_shift) & reg.mask;
2059 val = reg.mask -
val;
2060 ucontrol->
value.integer.value[0] =
val;
2062 val = (snd_cmipci_mixer_read(cm, reg.right_reg) >> reg.right_shift) & reg.mask;
2064 val = reg.mask -
val;
2065 ucontrol->
value.integer.value[1] =
val;
2071 static int snd_cmipci_put_volume(
struct snd_kcontrol *kcontrol,
2080 left = ucontrol->
value.integer.value[0] & reg.mask;
2082 left = reg.mask -
left;
2083 left <<= reg.left_shift;
2085 right = ucontrol->
value.integer.value[1] & reg.mask;
2087 right = reg.mask -
right;
2088 right <<= reg.right_shift;
2092 oleft = snd_cmipci_mixer_read(cm, reg.left_reg);
2093 left |= oleft & ~(reg.mask << reg.left_shift);
2094 change = left != oleft;
2096 if (reg.left_reg != reg.right_reg) {
2097 snd_cmipci_mixer_write(cm, reg.left_reg, left);
2098 oright = snd_cmipci_mixer_read(cm, reg.right_reg);
2101 right |= oright & ~(reg.mask << reg.right_shift);
2102 change |= right != oright;
2103 snd_cmipci_mixer_write(cm, reg.right_reg, right);
2105 snd_cmipci_mixer_write(cm, reg.left_reg, left);
2113 #define CMIPCI_SB_INPUT_SW(xname, left_shift, right_shift) \
2114 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
2115 .info = snd_cmipci_info_input_sw, \
2116 .get = snd_cmipci_get_input_sw, .put = snd_cmipci_put_input_sw, \
2117 .private_value = COMPOSE_SB_REG(SB_DSP4_INPUT_LEFT, SB_DSP4_INPUT_RIGHT, left_shift, right_shift, 1, 0, 1), \
2120 static int snd_cmipci_info_input_sw(
struct snd_kcontrol *kcontrol,
2130 static int snd_cmipci_get_input_sw(
struct snd_kcontrol *kcontrol,
2139 val1 = snd_cmipci_mixer_read(cm, reg.left_reg);
2140 val2 = snd_cmipci_mixer_read(cm, reg.right_reg);
2142 ucontrol->
value.integer.value[0] = (val1 >> reg.left_shift) & 1;
2143 ucontrol->
value.integer.value[1] = (val2 >> reg.left_shift) & 1;
2144 ucontrol->
value.integer.value[2] = (val1 >> reg.right_shift) & 1;
2145 ucontrol->
value.integer.value[3] = (val2 >> reg.right_shift) & 1;
2149 static int snd_cmipci_put_input_sw(
struct snd_kcontrol *kcontrol,
2155 int val1, val2, oval1, oval2;
2159 oval1 = snd_cmipci_mixer_read(cm, reg.left_reg);
2160 oval2 = snd_cmipci_mixer_read(cm, reg.right_reg);
2161 val1 = oval1 & ~((1 << reg.left_shift) | (1 << reg.right_shift));
2162 val2 = oval2 & ~((1 << reg.left_shift) | (1 << reg.right_shift));
2163 val1 |= (ucontrol->
value.integer.value[0] & 1) << reg.left_shift;
2164 val2 |= (ucontrol->
value.integer.value[1] & 1) << reg.left_shift;
2165 val1 |= (ucontrol->
value.integer.value[2] & 1) << reg.right_shift;
2166 val2 |= (ucontrol->
value.integer.value[3] & 1) << reg.right_shift;
2167 change = val1 != oval1 || val2 != oval2;
2168 snd_cmipci_mixer_write(cm, reg.left_reg, val1);
2169 snd_cmipci_mixer_write(cm, reg.right_reg, val2);
2178 #define CMIPCI_MIXER_SW_STEREO(xname, reg, lshift, rshift, invert) \
2179 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
2180 .info = snd_cmipci_info_native_mixer, \
2181 .get = snd_cmipci_get_native_mixer, .put = snd_cmipci_put_native_mixer, \
2182 .private_value = COMPOSE_SB_REG(reg, reg, lshift, rshift, 1, invert, 1), \
2185 #define CMIPCI_MIXER_SW_MONO(xname, reg, shift, invert) \
2186 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
2187 .info = snd_cmipci_info_native_mixer, \
2188 .get = snd_cmipci_get_native_mixer, .put = snd_cmipci_put_native_mixer, \
2189 .private_value = COMPOSE_SB_REG(reg, reg, shift, shift, 1, invert, 0), \
2192 #define CMIPCI_MIXER_VOL_STEREO(xname, reg, lshift, rshift, mask) \
2193 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
2194 .info = snd_cmipci_info_native_mixer, \
2195 .get = snd_cmipci_get_native_mixer, .put = snd_cmipci_put_native_mixer, \
2196 .private_value = COMPOSE_SB_REG(reg, reg, lshift, rshift, mask, 0, 1), \
2199 #define CMIPCI_MIXER_VOL_MONO(xname, reg, shift, mask) \
2200 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
2201 .info = snd_cmipci_info_native_mixer, \
2202 .get = snd_cmipci_get_native_mixer, .put = snd_cmipci_put_native_mixer, \
2203 .private_value = COMPOSE_SB_REG(reg, reg, shift, shift, mask, 0, 0), \
2206 static int snd_cmipci_info_native_mixer(
struct snd_kcontrol *kcontrol,
2220 static int snd_cmipci_get_native_mixer(
struct snd_kcontrol *kcontrol,
2225 unsigned char oreg,
val;
2230 val = (oreg >> reg.left_shift) & reg.mask;
2232 val = reg.mask -
val;
2233 ucontrol->
value.integer.value[0] =
val;
2235 val = (oreg >> reg.right_shift) & reg.mask;
2237 val = reg.mask -
val;
2238 ucontrol->
value.integer.value[1] =
val;
2244 static int snd_cmipci_put_native_mixer(
struct snd_kcontrol *kcontrol,
2249 unsigned char oreg, nreg,
val;
2254 val = ucontrol->
value.integer.value[0] & reg.mask;
2256 val = reg.mask -
val;
2257 nreg = oreg & ~(reg.mask << reg.left_shift);
2258 nreg |= (val << reg.left_shift);
2260 val = ucontrol->
value.integer.value[1] & reg.mask;
2262 val = reg.mask -
val;
2263 nreg &= ~(reg.mask << reg.right_shift);
2264 nreg |= (val << reg.right_shift);
2268 return (nreg != oreg);
2274 static int snd_cmipci_get_native_mixer_sensitive(
struct snd_kcontrol *kcontrol,
2278 return snd_cmipci_get_native_mixer(kcontrol, ucontrol);
2281 static int snd_cmipci_put_native_mixer_sensitive(
struct snd_kcontrol *kcontrol,
2289 return snd_cmipci_put_native_mixer(kcontrol, ucontrol);
2300 .name =
"PCM Playback Switch",
2301 .info = snd_cmipci_info_native_mixer,
2302 .get = snd_cmipci_get_native_mixer_sensitive,
2303 .put = snd_cmipci_put_native_mixer_sensitive,
2345 #define snd_cmipci_uswitch_info snd_ctl_boolean_mono_info
2347 static int _snd_cmipci_uswitch_get(
struct snd_kcontrol *kcontrol,
2356 ucontrol->
value.integer.value[0] = 0;
2363 val = snd_cmipci_read(cm, args->
reg);
2364 ucontrol->
value.integer.value[0] = ((val & args->
mask) == args->
mask_on) ? 1 : 0;
2369 static int snd_cmipci_uswitch_get(
struct snd_kcontrol *kcontrol,
2376 return _snd_cmipci_uswitch_get(kcontrol, ucontrol, args);
2379 static int _snd_cmipci_uswitch_put(
struct snd_kcontrol *kcontrol,
2396 val = snd_cmipci_read(cm, args->
reg);
2397 change = (val & args->
mask) != (ucontrol->
value.integer.value[0] ?
2401 if (ucontrol->
value.integer.value[0])
2408 snd_cmipci_write(cm, args->
reg, val);
2414 static int snd_cmipci_uswitch_put(
struct snd_kcontrol *kcontrol,
2421 return _snd_cmipci_uswitch_put(kcontrol, ucontrol, args);
2424 #define DEFINE_SWITCH_ARG(sname, xreg, xmask, xmask_on, xis_byte, xac3) \
2425 static struct cmipci_switch_args cmipci_switch_arg_##sname = { \
2428 .mask_on = xmask_on, \
2429 .is_byte = xis_byte, \
2430 .ac3_sensitive = xac3, \
2433 #define DEFINE_BIT_SWITCH_ARG(sname, xreg, xmask, xis_byte, xac3) \
2434 DEFINE_SWITCH_ARG(sname, xreg, xmask, xmask, xis_byte, xac3)
2465 #define DEFINE_SWITCH(sname, stype, sarg) \
2468 .info = snd_cmipci_uswitch_info, \
2469 .get = snd_cmipci_uswitch_get, \
2470 .put = snd_cmipci_uswitch_put, \
2471 .private_value = (unsigned long)&cmipci_switch_arg_##sarg,\
2474 #define DEFINE_CARD_SWITCH(sname, sarg) DEFINE_SWITCH(sname, SNDRV_CTL_ELEM_IFACE_CARD, sarg)
2475 #define DEFINE_MIXER_SWITCH(sname, sarg) DEFINE_SWITCH(sname, SNDRV_CTL_ELEM_IFACE_MIXER, sarg)
2482 static int snd_cmipci_spdout_enable_get(
struct snd_kcontrol *kcontrol,
2486 changed = _snd_cmipci_uswitch_get(kcontrol, ucontrol, &cmipci_switch_arg_spdif_enable);
2487 changed |= _snd_cmipci_uswitch_get(kcontrol, ucontrol, &cmipci_switch_arg_spdo2dac);
2491 static int snd_cmipci_spdout_enable_put(
struct snd_kcontrol *kcontrol,
2496 changed = _snd_cmipci_uswitch_put(kcontrol, ucontrol, &cmipci_switch_arg_spdif_enable);
2497 changed |= _snd_cmipci_uswitch_put(kcontrol, ucontrol, &cmipci_switch_arg_spdo2dac);
2499 if (ucontrol->
value.integer.value[0]) {
2512 static int snd_cmipci_line_in_mode_info(
struct snd_kcontrol *kcontrol,
2516 static const char *
const texts[3] = {
2517 "Line-In",
"Rear Output",
"Bass Output"
2524 static inline unsigned int get_line_in_mode(
struct cmipci *cm)
2538 static int snd_cmipci_line_in_mode_get(
struct snd_kcontrol *kcontrol,
2544 ucontrol->
value.enumerated.item[0] = get_line_in_mode(cm);
2549 static int snd_cmipci_line_in_mode_put(
struct snd_kcontrol *kcontrol,
2556 if (ucontrol->
value.enumerated.item[0] == 2)
2560 if (ucontrol->
value.enumerated.item[0] == 1)
2568 static int snd_cmipci_mic_in_mode_info(
struct snd_kcontrol *kcontrol,
2571 static const char *
const texts[2] = {
"Mic-In",
"Center/LFE Output" };
2576 static int snd_cmipci_mic_in_mode_get(
struct snd_kcontrol *kcontrol,
2582 ucontrol->
value.enumerated.item[0] =
2588 static int snd_cmipci_mic_in_mode_put(
struct snd_kcontrol *kcontrol,
2595 if (ucontrol->
value.enumerated.item[0])
2604 static struct snd_kcontrol_new snd_cmipci_mixer_switches[] __devinitdata = {
2607 .name =
"Line-In Mode",
2609 .info = snd_cmipci_line_in_mode_info,
2610 .get = snd_cmipci_line_in_mode_get,
2611 .put = snd_cmipci_line_in_mode_put,
2620 static struct snd_kcontrol_new snd_cmipci_8738_mixer_switches[] __devinitdata = {
2627 { .name =
"IEC958 Output Switch",
2630 .get = snd_cmipci_spdout_enable_get,
2631 .put = snd_cmipci_spdout_enable_put,
2642 static struct snd_kcontrol_new snd_cmipci_old_mixer_switches[] __devinitdata = {
2649 static struct snd_kcontrol_new snd_cmipci_extra_mixer_switches[] __devinitdata = {
2653 .name =
"Mic-In Mode",
2655 .info = snd_cmipci_mic_in_mode_info,
2656 .get = snd_cmipci_mic_in_mode_get,
2657 .put = snd_cmipci_mic_in_mode_put,
2666 static int __devinit snd_cmipci_mixer_new(
struct cmipci *cm,
int pcm_spdif_device)
2682 snd_cmipci_mixer_write(cm, 0x00, 0x00);
2685 for (idx = 0; idx <
ARRAY_SIZE(snd_cmipci_mixers); idx++) {
2688 "PCM Playback Volume"))
2696 sw = snd_cmipci_mixer_switches;
2697 for (idx = 0; idx <
ARRAY_SIZE(snd_cmipci_mixer_switches); idx++, sw++) {
2709 sw = snd_cmipci_8738_mixer_switches;
2710 for (idx = 0; idx <
ARRAY_SIZE(snd_cmipci_8738_mixer_switches); idx++, sw++) {
2718 kctl->
id.device = pcm_spdif_device;
2721 kctl->
id.device = pcm_spdif_device;
2724 kctl->
id.device = pcm_spdif_device;
2727 sw = snd_cmipci_old_mixer_switches;
2728 for (idx = 0; idx <
ARRAY_SIZE(snd_cmipci_old_mixer_switches); idx++, sw++) {
2736 sw = snd_cmipci_extra_mixer_switches;
2737 for (idx = 0; idx <
ARRAY_SIZE(snd_cmipci_extra_mixer_switches); idx++, sw++) {
2759 memset(&elem_id, 0,
sizeof(elem_id));
2761 strcpy(elem_id.name, cm_saved_mixer[idx].
name);
2775 #ifdef CONFIG_PROC_FS
2782 snd_iprintf(buffer,
"%s\n", cm->
card->longname);
2783 for (i = 0; i < 0x94; i++) {
2788 snd_iprintf(buffer,
"\n%02x:", i);
2789 snd_iprintf(buffer,
" %02x", v);
2791 snd_iprintf(buffer,
"\n");
2798 if (! snd_card_proc_new(cm->
card,
"cmipci", &entry))
2799 snd_info_set_text_ops(entry, cm, snd_cmipci_proc_read);
2802 static inline void snd_cmipci_proc_init(
struct cmipci *cm) {}
2822 unsigned int detect;
2868 #ifdef SUPPORT_JOYSTICK
2871 static int ports[] = { 0x201, 0x200, 0 };
2876 if (joystick_port[dev] == 0)
2879 if (joystick_port[dev] == 1) {
2880 for (i = 0; ports[
i]; i++) {
2887 io_port = joystick_port[
dev];
2896 cm->gameport = gp = gameport_allocate_port();
2898 printk(
KERN_ERR "cmipci: cannot allocate memory for gameport\n");
2902 gameport_set_name(gp,
"C-Media Gameport");
2904 gameport_set_dev_parent(gp, &cm->
pci->dev);
2906 gameport_set_port_data(gp, r);
2910 gameport_register_port(cm->gameport);
2915 static void snd_cmipci_free_gameport(
struct cmipci *cm)
2918 struct resource *r = gameport_get_port_data(cm->gameport);
2921 cm->gameport =
NULL;
2928 static inline int snd_cmipci_create_gameport(
struct cmipci *cm,
int dev) {
return -
ENOSYS; }
2929 static inline void snd_cmipci_free_gameport(
struct cmipci *cm) { }
2932 static int snd_cmipci_free(
struct cmipci *cm)
2944 snd_cmipci_mixer_write(cm, 0, 0);
2949 snd_cmipci_free_gameport(cm);
2956 static int snd_cmipci_dev_free(
struct snd_device *device)
2959 return snd_cmipci_free(cm);
2962 static int __devinit snd_cmipci_create_fm(
struct cmipci *cm,
long fm_port)
2999 "skipping...\n", iosynth);
3016 int dev,
struct cmipci **rcmipci)
3021 .dev_free = snd_cmipci_dev_free,
3025 int integrated_midi = 0;
3027 int pcm_index, pcm_spdif_index;
3064 snd_cmipci_free(cm);
3133 val = pci->
device < 0x110 ? 8338 : 8738;
3168 snd_cmipci_free(cm);
3174 if (val != 0x00 && val != 0xff) {
3176 integrated_midi = 1;
3179 if (!integrated_midi) {
3181 iomidi = mpu_port[
dev];
3194 if (
inb(iomidi + 1) == 0xff) {
3196 " at %#lx\n", iomidi);
3205 err = snd_cmipci_create_fm(cm, fm_port[dev]);
3211 snd_cmipci_mixer_write(cm, 0, 0);
3213 snd_cmipci_proc_init(cm);
3216 pcm_index = pcm_spdif_index = 0;
3217 if ((err = snd_cmipci_pcm_new(cm, pcm_index)) < 0)
3220 if ((err = snd_cmipci_pcm2_new(cm, pcm_index)) < 0)
3224 pcm_spdif_index = pcm_index;
3225 if ((err = snd_cmipci_pcm_spdif_new(cm, pcm_index)) < 0)
3230 if ((err = snd_cmipci_mixer_new(cm, pcm_spdif_index)) < 0)
3239 -1, &cm->
rmidi)) < 0) {
3244 #ifdef USE_VAR48KRATE
3245 for (val = 0; val <
ARRAY_SIZE(rates); val++)
3246 snd_cmipci_set_pll(cm, rates[val], val);
3254 if (snd_cmipci_create_gameport(cm, dev) < 0)
3301 if ((err = snd_cmipci_create(card, pci, dev, &cm)) < 0) {
3311 pci_set_drvdata(pci, card);
3320 pci_set_drvdata(pci,
NULL);
3324 #ifdef CONFIG_PM_SLEEP
3336 static unsigned char saved_mixers[] = {
3347 static int snd_cmipci_suspend(
struct device *dev)
3356 snd_pcm_suspend_all(cm->
pcm);
3357 snd_pcm_suspend_all(cm->
pcm2);
3362 cm->saved_regs[i] = snd_cmipci_read(cm, saved_regs[i]);
3363 for (i = 0; i <
ARRAY_SIZE(saved_mixers); i++)
3364 cm->saved_mixers[i] = snd_cmipci_mixer_read(cm, saved_mixers[i]);
3375 static int snd_cmipci_resume(
struct device *dev)
3386 "disabling device\n");
3396 snd_cmipci_mixer_write(cm, 0, 0);
3400 snd_cmipci_write(cm, saved_regs[i], cm->saved_regs[i]);
3401 for (i = 0; i <
ARRAY_SIZE(saved_mixers); i++)
3402 snd_cmipci_mixer_write(cm, saved_mixers[i], cm->saved_mixers[i]);
3409 #define SND_CMIPCI_PM_OPS &snd_cmipci_pm
3411 #define SND_CMIPCI_PM_OPS NULL
3415 .name = KBUILD_MODNAME,
3416 .id_table = snd_cmipci_ids,
3417 .probe = snd_cmipci_probe,