34 #include <linux/pci.h>
36 #include <linux/slab.h>
37 #include <linux/module.h>
77 #define IPR_MIDITRANSBUFEMPTY 0x00000001
78 #define IPR_MIDIRECVBUFEMPTY 0x00000002
79 #define IPR_CH_0_LOOP 0x00000800
80 #define IPR_CH_0_HALF_LOOP 0x00000100
81 #define IPR_CAP_0_LOOP 0x00080000
82 #define IPR_CAP_0_HALF_LOOP 0x00010000
85 #define INTE_MIDITXENABLE 0x00000001
86 #define INTE_MIDIRXENABLE 0x00000002
87 #define INTE_CH_0_LOOP 0x00000800
88 #define INTE_CH_0_HALF_LOOP 0x00000100
89 #define INTE_CAP_0_LOOP 0x00080000
90 #define INTE_CAP_0_HALF_LOOP 0x00010000
94 #define HCFG_LOCKSOUNDCACHE 0x00000008
96 #define HCFG_AUDIOENABLE 0x00000001
102 #define AC97DATA 0x1c
104 #define AC97ADDRESS 0x1e
109 #define PLAYBACK_LIST_ADDR 0x00
115 #define PLAYBACK_LIST_SIZE 0x01
116 #define PLAYBACK_LIST_PTR 0x02
117 #define PLAYBACK_DMA_ADDR 0x04
118 #define PLAYBACK_PERIOD_SIZE 0x05
119 #define PLAYBACK_POINTER 0x06
120 #define PLAYBACK_UNKNOWN1 0x07
121 #define PLAYBACK_UNKNOWN2 0x08
124 #define CAPTURE_DMA_ADDR 0x10
125 #define CAPTURE_BUFFER_SIZE 0x11
126 #define CAPTURE_POINTER 0x12
127 #define CAPTURE_UNKNOWN 0x13
131 #define TRIGGER_CHANNEL 0x40
132 #define TRIGGER_CHANNEL_0 0x00000001
133 #define TRIGGER_CHANNEL_1 0x00000002
134 #define TRIGGER_CHANNEL_2 0x00000004
135 #define TRIGGER_CAPTURE 0x00000100
138 #define ROUTING_FRONT_LEFT 0x00000001
139 #define ROUTING_FRONT_RIGHT 0x00000002
140 #define ROUTING_REAR_LEFT 0x00000004
141 #define ROUTING_REAR_RIGHT 0x00000008
142 #define ROUTING_CENTER_LFE 0x00010000
150 #define SPCS_CLKACCYMASK 0x30000000
151 #define SPCS_CLKACCY_1000PPM 0x00000000
152 #define SPCS_CLKACCY_50PPM 0x10000000
153 #define SPCS_CLKACCY_VARIABLE 0x20000000
154 #define SPCS_SAMPLERATEMASK 0x0f000000
155 #define SPCS_SAMPLERATE_44 0x00000000
156 #define SPCS_SAMPLERATE_48 0x02000000
157 #define SPCS_SAMPLERATE_32 0x03000000
158 #define SPCS_CHANNELNUMMASK 0x00f00000
159 #define SPCS_CHANNELNUM_UNSPEC 0x00000000
160 #define SPCS_CHANNELNUM_LEFT 0x00100000
161 #define SPCS_CHANNELNUM_RIGHT 0x00200000
162 #define SPCS_SOURCENUMMASK 0x000f0000
163 #define SPCS_SOURCENUM_UNSPEC 0x00000000
164 #define SPCS_GENERATIONSTATUS 0x00008000
165 #define SPCS_CATEGORYCODEMASK 0x00007f00
166 #define SPCS_MODEMASK 0x000000c0
167 #define SPCS_EMPHASISMASK 0x00000038
168 #define SPCS_EMPHASIS_NONE 0x00000000
169 #define SPCS_EMPHASIS_50_15 0x00000008
170 #define SPCS_COPYRIGHT 0x00000004
171 #define SPCS_NOTAUDIODATA 0x00000002
172 #define SPCS_PROFESSIONAL 0x00000001
174 #define SPDIF_SELECT 0x45
269 .period_bytes_min = 64,
270 .period_bytes_max = (16*1024),
288 .period_bytes_min = 64,
289 .period_bytes_max = (16*1024),
295 static unsigned int snd_emu10k1x_ptr_read(
struct emu10k1x *
emu,
302 regptr = (reg << 16) | chn;
307 spin_unlock_irqrestore(&emu->
emu_lock, flags);
311 static void snd_emu10k1x_ptr_write(
struct emu10k1x *
emu,
319 regptr = (reg << 16) | chn;
324 spin_unlock_irqrestore(&emu->
emu_lock, flags);
327 static void snd_emu10k1x_intr_enable(
struct emu10k1x *
emu,
unsigned int intrenb)
335 spin_unlock_irqrestore(&emu->
emu_lock, flags);
338 static void snd_emu10k1x_intr_disable(
struct emu10k1x *
emu,
unsigned int intrenb)
346 spin_unlock_irqrestore(&emu->
emu_lock, flags);
349 static void snd_emu10k1x_gpio_write(
struct emu10k1x *
emu,
unsigned int value)
355 spin_unlock_irqrestore(&emu->
emu_lock, flags);
358 static void snd_emu10k1x_pcm_free_substream(
struct snd_pcm_runtime *runtime)
374 snd_pcm_lib_period_bytes(epcm->
substream),
375 snd_pcm_lib_buffer_bytes(epcm->
substream));
401 runtime->
private_free = snd_emu10k1x_pcm_free_substream;
403 runtime->
hw = snd_emu10k1x_playback_hw;
422 epcm->
voice = &epcm->
emu->voices[substream->
pcm->device];
423 epcm->
voice->use = 1;
424 epcm->
voice->epcm = epcm;
443 epcm->
voice->use = 0;
457 int voice = epcm->
voice->number;
459 u32 period_size_bytes = frames_to_bytes(runtime, runtime->
period_size);
462 for(i = 0; i < runtime->
periods; i++) {
463 *table_base++=runtime->
dma_addr+(i*period_size_bytes);
464 *table_base++=period_size_bytes<<16;
520 int channel = epcm->
voice->number;
530 if(ptr4 == 0 && ptr1 == frames_to_bytes(runtime, runtime->
buffer_size))
535 ptr2 = bytes_to_frames(runtime, ptr1);
546 static struct snd_pcm_ops snd_emu10k1x_playback_ops = {
547 .open = snd_emu10k1x_playback_open,
548 .close = snd_emu10k1x_playback_close,
550 .hw_params = snd_emu10k1x_pcm_hw_params,
551 .hw_free = snd_emu10k1x_pcm_hw_free,
552 .prepare = snd_emu10k1x_pcm_prepare,
553 .trigger = snd_emu10k1x_pcm_trigger,
554 .pointer = snd_emu10k1x_pcm_pointer,
578 runtime->
private_free = snd_emu10k1x_pcm_free_substream;
580 runtime->
hw = snd_emu10k1x_capture_hw;
592 static int snd_emu10k1x_pcm_hw_params_capture(
struct snd_pcm_substream *substream,
599 if (epcm->
emu->capture_voice.use)
601 epcm->
voice = &epcm->
emu->capture_voice;
602 epcm->
voice->epcm = epcm;
603 epcm->
voice->use = 1;
622 epcm->
voice->use = 0;
685 ptr = bytes_to_frames(runtime, snd_emu10k1x_ptr_read(emu,
CAPTURE_POINTER, 0));
692 static struct snd_pcm_ops snd_emu10k1x_capture_ops = {
693 .open = snd_emu10k1x_pcm_open_capture,
694 .close = snd_emu10k1x_pcm_close_capture,
696 .hw_params = snd_emu10k1x_pcm_hw_params_capture,
697 .hw_free = snd_emu10k1x_pcm_hw_free_capture,
698 .prepare = snd_emu10k1x_pcm_prepare_capture,
699 .trigger = snd_emu10k1x_pcm_trigger_capture,
700 .pointer = snd_emu10k1x_pcm_pointer_capture,
703 static unsigned short snd_emu10k1x_ac97_read(
struct snd_ac97 *ac97,
713 spin_unlock_irqrestore(&emu->
emu_lock, flags);
717 static void snd_emu10k1x_ac97_write(
struct snd_ac97 *
ac97,
718 unsigned short reg,
unsigned short val)
726 spin_unlock_irqrestore(&emu->
emu_lock, flags);
729 static int snd_emu10k1x_ac97(
struct emu10k1x *chip)
735 .write = snd_emu10k1x_ac97_write,
736 .read = snd_emu10k1x_ac97_read,
743 memset(&ac97, 0,
sizeof(ac97));
749 static int snd_emu10k1x_free(
struct emu10k1x *chip)
779 return snd_emu10k1x_free(chip);
800 snd_emu10k1x_pcm_interrupt(chip, cap_voice);
802 snd_emu10k1x_intr_disable(chip,
808 for (i = 0; i < 3; i++) {
811 snd_emu10k1x_pcm_interrupt(chip, pvoice);
813 snd_emu10k1x_intr_disable(chip, mask);
820 if (chip->
midi.interrupt)
821 chip->
midi.interrupt(chip, status);
857 if ((err =
snd_pcm_new(emu->
card,
"emu10k1x", device, 1, capture, &pcm)) < 0)
913 .dev_free = snd_emu10k1x_dev_free,
921 pci_set_consistent_dma_mask(pci,
DMA_BIT_MASK(28)) < 0) {
942 "EMU10K1X")) ==
NULL) {
944 snd_emu10k1x_free(chip);
951 snd_emu10k1x_free(chip);
958 snd_emu10k1x_free(chip);
972 for(ch = 0; ch < 3; ch++) {
974 chip->
voices[ch].number = ch;
991 snd_emu10k1x_ptr_write(chip,
SPCS0, 0,
997 snd_emu10k1x_ptr_write(chip,
SPCS1, 0,
1003 snd_emu10k1x_ptr_write(chip,
SPCS2, 0,
1011 snd_emu10k1x_ptr_write(chip,
ROUTING, 0, 0x1003F);
1012 snd_emu10k1x_gpio_write(chip, 0x1080);
1018 snd_emu10k1x_free(chip);
1029 unsigned long value,value1,value2;
1030 unsigned long flags;
1033 snd_iprintf(buffer,
"Registers:\n\n");
1034 for(i = 0; i < 0x20; i+=4) {
1037 spin_unlock_irqrestore(&emu->
emu_lock, flags);
1038 snd_iprintf(buffer,
"Register %02X: %08lX\n", i, value);
1040 snd_iprintf(buffer,
"\nRegisters\n\n");
1041 for(i = 0; i <= 0x48; i++) {
1042 value = snd_emu10k1x_ptr_read(emu, i, 0);
1043 if(i < 0x10 || (i >= 0x20 && i < 0x40)) {
1044 value1 = snd_emu10k1x_ptr_read(emu, i, 1);
1045 value2 = snd_emu10k1x_ptr_read(emu, i, 2);
1046 snd_iprintf(buffer,
"%02X: %08lX %08lX %08lX\n", i, value, value1, value2);
1048 snd_iprintf(buffer,
"%02X: %08lX\n", i, value);
1053 static void snd_emu10k1x_proc_reg_write(
struct snd_info_entry *entry,
1058 unsigned int reg, channel_id ,
val;
1060 while (!snd_info_get_line(buffer, line,
sizeof(line))) {
1061 if (
sscanf(line,
"%x %x %x", ®, &channel_id, &val) != 3)
1064 if (reg < 0x49 && val <= 0xffffffff && channel_id <= 2)
1065 snd_emu10k1x_ptr_write(emu, reg, channel_id, val);
1073 if(! snd_card_proc_new(emu->
card,
"emu10k1x_regs", &entry)) {
1074 snd_info_set_text_ops(entry, emu, snd_emu10k1x_proc_reg_read);
1075 entry->
c.
text.write = snd_emu10k1x_proc_reg_write;
1083 #define snd_emu10k1x_shared_spdif_info snd_ctl_boolean_mono_info
1085 static int snd_emu10k1x_shared_spdif_get(
struct snd_kcontrol *kcontrol,
1090 ucontrol->
value.integer.value[0] = (snd_emu10k1x_ptr_read(emu,
SPDIF_SELECT, 0) == 0x700) ? 0 : 1;
1095 static int snd_emu10k1x_shared_spdif_put(
struct snd_kcontrol *kcontrol,
1102 val = ucontrol->
value.integer.value[0] ;
1107 snd_emu10k1x_ptr_write(emu,
ROUTING, 0, 0x700);
1108 snd_emu10k1x_gpio_write(emu, 0x1000);
1112 snd_emu10k1x_ptr_write(emu,
ROUTING, 0, 0x1003F);
1113 snd_emu10k1x_gpio_write(emu, 0x1080);
1121 .name =
"Analog/Digital Output Jack",
1123 .get = snd_emu10k1x_shared_spdif_get,
1124 .put = snd_emu10k1x_shared_spdif_put
1134 static int snd_emu10k1x_spdif_get(
struct snd_kcontrol *kcontrol,
1138 unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->
id);
1147 static int snd_emu10k1x_spdif_get_mask(
struct snd_kcontrol *kcontrol,
1150 ucontrol->
value.iec958.status[0] = 0xff;
1151 ucontrol->
value.iec958.status[1] = 0xff;
1152 ucontrol->
value.iec958.status[2] = 0xff;
1153 ucontrol->
value.iec958.status[3] = 0xff;
1157 static int snd_emu10k1x_spdif_put(
struct snd_kcontrol *kcontrol,
1161 unsigned int idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->
id);
1165 val = (ucontrol->
value.iec958.status[0] << 0) |
1166 (ucontrol->
value.iec958.status[1] << 8) |
1167 (ucontrol->
value.iec958.status[2] << 16) |
1168 (ucontrol->
value.iec958.status[3] << 24);
1171 snd_emu10k1x_ptr_write(emu,
SPCS0 + idx, 0, val);
1183 .info = snd_emu10k1x_spdif_info,
1184 .get = snd_emu10k1x_spdif_get_mask
1192 .info = snd_emu10k1x_spdif_info,
1193 .get = snd_emu10k1x_spdif_get,
1194 .put = snd_emu10k1x_spdif_put
1219 #define EMU10K1X_MIDI_MODE_INPUT (1<<0)
1220 #define EMU10K1X_MIDI_MODE_OUTPUT (1<<1)
1224 return (
unsigned char)snd_emu10k1x_ptr_read(emu, mpu->
port + idx, 0);
1229 snd_emu10k1x_ptr_write(emu, mpu->
port + idx, 0, data);
1232 #define mpu401_write_data(emu, mpu, data) mpu401_write(emu, mpu, data, 0)
1233 #define mpu401_write_cmd(emu, mpu, data) mpu401_write(emu, mpu, data, 1)
1234 #define mpu401_read_data(emu, mpu) mpu401_read(emu, mpu, 0)
1235 #define mpu401_read_stat(emu, mpu) mpu401_read(emu, mpu, 1)
1237 #define mpu401_input_avail(emu,mpu) (!(mpu401_read_stat(emu,mpu) & 0x80))
1238 #define mpu401_output_ready(emu,mpu) (!(mpu401_read_stat(emu,mpu) & 0x40))
1240 #define MPU401_RESET 0xff
1241 #define MPU401_ENTER_UART 0x3f
1242 #define MPU401_ACK 0xfe
1249 #ifdef CONFIG_SND_DEBUG
1259 static void do_emu10k1x_midi_interrupt(
struct emu10k1x *emu,
1272 mpu401_clear_rx(emu, midi);
1287 snd_emu10k1x_intr_disable(emu, midi->
tx_enable);
1293 static void snd_emu10k1x_midi_interrupt(
struct emu10k1x *emu,
unsigned int status)
1295 do_emu10k1x_midi_interrupt(emu, &emu->
midi, status);
1298 static int snd_emu10k1x_midi_cmd(
struct emu10k1x * emu,
1301 unsigned long flags;
1312 while (!ok && timeout-- > 0) {
1323 spin_unlock_irqrestore(&midi->
input_lock, flags);
1325 snd_printk(
KERN_ERR "midi_cmd: 0x%x failed at 0x%lx (status = 0x%x, data = 0x%x)!!!\n",
1338 unsigned long flags;
1347 spin_unlock_irqrestore(&midi->
open_lock, flags);
1353 spin_unlock_irqrestore(&midi->
open_lock, flags);
1365 unsigned long flags;
1374 spin_unlock_irqrestore(&midi->
open_lock, flags);
1380 spin_unlock_irqrestore(&midi->
open_lock, flags);
1392 unsigned long flags;
1399 snd_emu10k1x_intr_disable(emu, midi->
rx_enable);
1403 spin_unlock_irqrestore(&midi->
open_lock, flags);
1404 err = snd_emu10k1x_midi_cmd(emu, midi,
MPU401_RESET, 0);
1406 spin_unlock_irqrestore(&midi->
open_lock, flags);
1415 unsigned long flags;
1422 snd_emu10k1x_intr_disable(emu, midi->
tx_enable);
1426 spin_unlock_irqrestore(&midi->
open_lock, flags);
1427 err = snd_emu10k1x_midi_cmd(emu, midi,
MPU401_RESET, 0);
1429 spin_unlock_irqrestore(&midi->
open_lock, flags);
1443 snd_emu10k1x_intr_enable(emu, midi->
rx_enable);
1445 snd_emu10k1x_intr_disable(emu, midi->
rx_enable);
1452 unsigned long flags;
1469 spin_unlock_irqrestore(&midi->
output_lock, flags);
1478 spin_unlock_irqrestore(&midi->
output_lock, flags);
1479 snd_emu10k1x_intr_enable(emu, midi->
tx_enable);
1481 snd_emu10k1x_intr_disable(emu, midi->
tx_enable);
1491 .open = snd_emu10k1x_midi_output_open,
1492 .close = snd_emu10k1x_midi_output_close,
1493 .trigger = snd_emu10k1x_midi_output_trigger,
1498 .open = snd_emu10k1x_midi_input_open,
1499 .close = snd_emu10k1x_midi_input_close,
1500 .trigger = snd_emu10k1x_midi_input_trigger,
1503 static void snd_emu10k1x_midi_free(
struct snd_rawmidi *rmidi)
1530 midi->
rmidi = rmidi;
1539 if ((err = emu10k1x_midi_init(emu, midi, 0,
"EMU10K1X MPU-401 (UART)")) < 0)
1547 midi->
interrupt = snd_emu10k1x_midi_interrupt;
1570 if ((err = snd_emu10k1x_create(card, pci, &chip)) < 0) {
1575 if ((err = snd_emu10k1x_pcm(chip, 0,
NULL)) < 0) {
1579 if ((err = snd_emu10k1x_pcm(chip, 1,
NULL)) < 0) {
1583 if ((err = snd_emu10k1x_pcm(chip, 2,
NULL)) < 0) {
1588 if ((err = snd_emu10k1x_ac97(chip)) < 0) {
1593 if ((err = snd_emu10k1x_mixer(chip)) < 0) {
1598 if ((err = snd_emu10k1x_midi(chip)) < 0) {
1603 snd_emu10k1x_proc_init(chip);
1617 pci_set_drvdata(pci, card);
1625 pci_set_drvdata(pci,
NULL);
1637 .name = KBUILD_MODNAME,
1638 .id_table = snd_emu10k1x_ids,
1639 .probe = snd_emu10k1x_probe,