141 #include <linux/pci.h>
142 #include <linux/slab.h>
143 #include <linux/module.h>
179 { .serial = 0x10131102,
180 .name =
"X-Fi Extreme Audio [SBxxxx]",
197 { .serial = 0x10121102,
198 .name =
"X-Fi Extreme Audio [SB0790]",
203 { .serial = 0x10021102,
204 .name =
"AudigyLS [SB0310]",
207 { .serial = 0x10051102,
208 .name =
"AudigyLS [SB0310b]",
211 { .serial = 0x10061102,
212 .name =
"Live! 7.1 24bit [SB0410]",
216 { .serial = 0x10071102,
217 .name =
"Live! 7.1 24bit [SB0413]",
226 { .serial = 0x100a1102,
227 .name =
"Audigy SE [SB0570]",
230 .spi_dac = 0x4021 } ,
237 { .serial = 0x10111102,
238 .name =
"Audigy SE OEM [SB0570a]",
241 .spi_dac = 0x4021 } ,
246 { .serial = 0x10041102,
247 .name =
"Sound Blaster 5.1vx [SB1070]",
258 { .serial = 0x10091462,
259 .name =
"MSI K8N Diamond MB [SB0438]",
263 { .serial = 0x10091102,
264 .name =
"MSI K8N Diamond MB",
267 .spi_dac = 0x4021 } ,
272 { .serial = 0x1458a006,
273 .name =
"Giga-byte GA-G1975X",
281 { .serial = 0x30381297,
282 .name =
"Shuttle XPC SD31P [SD31P]",
290 { .serial = 0x30411297,
291 .name =
"Shuttle XPC SD11G5 [SD11G5]",
295 .name =
"AudigyLS [Unknown]" }
353 regptr = (reg << 16) | chn;
358 spin_unlock_irqrestore(&emu->
emu_lock, flags);
370 regptr = (reg << 16) | chn;
375 spin_unlock_irqrestore(&emu->
emu_lock, flags);
381 unsigned int reset,
set;
388 reset = (tmp & ~0x3ffff) | 0x20000;
389 set = reset | 0x10000;
395 for (n = 0; n < 100; n++) {
398 if (!(tmp & 0x10000)) {
419 if ((reg > 0x7f) || (value > 0x1ff)) {
424 tmp = reg << 25 | value << 16;
434 for (retry = 0; retry < 10; retry++) {
467 static void snd_ca0106_intr_enable(
struct snd_ca0106 *
emu,
unsigned int intrenb)
475 spin_unlock_irqrestore(&emu->
emu_lock, flags);
478 static void snd_ca0106_intr_disable(
struct snd_ca0106 *
emu,
unsigned int intrenb)
486 spin_unlock_irqrestore(&emu->
emu_lock, flags);
490 static void snd_ca0106_pcm_free_substream(
struct snd_pcm_runtime *runtime)
495 static const int spi_dacd_reg[] = {
502 static const int spi_dacd_bit[] = {
522 switch (channel_id) {
524 return (details->
spi_dac & 0xf000) >> (4 * 3);
526 return (details->
spi_dac & 0x0f00) >> (4 * 2);
528 return (details->
spi_dac & 0x00f0) >> (4 * 1);
530 return (details->
spi_dac & 0x000f) >> (4 * 0);
538 static int snd_ca0106_pcm_power_dac(
struct snd_ca0106 *chip,
int channel_id,
542 const int dac = snd_ca0106_channel_dac(chip->
details,
544 const int reg = spi_dacd_reg[dac];
545 const int bit = spi_dacd_bit[dac];
559 static int snd_ca0106_pcm_open_playback_channel(
struct snd_pcm_substream *substream,
579 runtime->
hw = snd_ca0106_playback_hw;
582 channel->
number = channel_id;
590 channel->
epcm = epcm;
599 err = snd_ca0106_pcm_power_dac(chip, channel_id, 1);
604 restore_spdif_bits(chip, channel_id);
622 err = snd_ca0106_pcm_power_dac(chip, epcm->
channel_id, 0);
631 static int snd_ca0106_pcm_open_playback_front(
struct snd_pcm_substream *substream)
636 static int snd_ca0106_pcm_open_playback_center_lfe(
struct snd_pcm_substream *substream)
641 static int snd_ca0106_pcm_open_playback_unknown(
struct snd_pcm_substream *substream)
646 static int snd_ca0106_pcm_open_playback_rear(
struct snd_pcm_substream *substream)
652 static int snd_ca0106_pcm_open_capture_channel(
struct snd_pcm_substream *substream,
673 runtime->
hw = snd_ca0106_capture_hw;
676 channel->
number = channel_id;
684 channel->
epcm = epcm;
706 return snd_ca0106_pcm_open_capture_channel(substream, 0);
711 return snd_ca0106_pcm_open_capture_channel(substream, 1);
716 return snd_ca0106_pcm_open_capture_channel(substream, 2);
721 return snd_ca0106_pcm_open_capture_channel(substream, 3);
725 static int snd_ca0106_pcm_hw_params_playback(
struct snd_pcm_substream *substream,
759 u32 *table_base = (
u32 *)(emu->
buffer.area+(8*16*channel));
760 u32 period_size_bytes = frames_to_bytes(runtime, runtime->
period_size);
762 u32 hcfg_set = 0x00000000;
764 u32 reg40_mask = 0x30000 << (channel<<1);
768 u32 reg71_mask = 0x03030000 ;
775 "prepare:channel_number=%d, rate=%d, format=0x%x, "
776 "channels=%d, buffer_size=%ld, period_size=%ld, "
777 "periods=%u, frames_to_bytes=%d\n",
781 frames_to_bytes(runtime, 1));
790 switch (runtime->
rate) {
792 reg40_set = 0x10000 << (channel<<1);
793 reg71_set = 0x01010000;
800 reg40_set = 0x20000 << (channel<<1);
801 reg71_set = 0x02020000;
804 reg40_set = 0x30000 << (channel<<1);
805 reg71_set = 0x03030000;
814 switch (runtime->
format) {
826 hcfg = (hcfg & ~hcfg_mask) | hcfg_set;
829 reg40 = (reg40 & ~reg40_mask) | reg40_set;
832 reg71 = (reg71 & ~reg71_mask) | reg71_set;
836 for(i=0; i < runtime->
periods; i++) {
837 table_base[i*2] = runtime->
dma_addr + (i * period_size_bytes);
838 table_base[i*2+1] = period_size_bytes << 16;
871 u32 hcfg_set = 0x00000000;
873 u32 over_sampling=0x2;
874 u32 reg71_mask = 0x0000c000 ;
880 "prepare:channel_number=%d, rate=%d, format=0x%x, "
881 "channels=%d, buffer_size=%ld, period_size=%ld, "
882 "periods=%u, frames_to_bytes=%d\n",
886 frames_to_bytes(runtime, 1));
893 switch (runtime->
rate) {
895 reg71_set = 0x00004000;
901 reg71_set = 0x00008000;
905 reg71_set = 0x0000c000;
914 switch (runtime->
format) {
926 hcfg = (hcfg & ~hcfg_mask) | hcfg_set;
929 reg71 = (reg71 & ~reg71_mask) | reg71_set;
931 if (emu->
details->i2c_adc == 1) {
989 snd_pcm_trigger_done(s, substream);
1054 unsigned int ptr, prev_ptr;
1065 ptr += bytes_to_frames(runtime,
1069 if (prev_ptr == ptr)
1072 }
while (--timeout);
1091 ptr2 = bytes_to_frames(runtime, ptr1);
1106 static struct snd_pcm_ops snd_ca0106_playback_front_ops = {
1107 .open = snd_ca0106_pcm_open_playback_front,
1108 .close = snd_ca0106_pcm_close_playback,
1110 .hw_params = snd_ca0106_pcm_hw_params_playback,
1111 .hw_free = snd_ca0106_pcm_hw_free_playback,
1112 .prepare = snd_ca0106_pcm_prepare_playback,
1113 .trigger = snd_ca0106_pcm_trigger_playback,
1114 .pointer = snd_ca0106_pcm_pointer_playback,
1117 static struct snd_pcm_ops snd_ca0106_capture_0_ops = {
1118 .open = snd_ca0106_pcm_open_0_capture,
1119 .close = snd_ca0106_pcm_close_capture,
1121 .hw_params = snd_ca0106_pcm_hw_params_capture,
1122 .hw_free = snd_ca0106_pcm_hw_free_capture,
1123 .prepare = snd_ca0106_pcm_prepare_capture,
1124 .trigger = snd_ca0106_pcm_trigger_capture,
1125 .pointer = snd_ca0106_pcm_pointer_capture,
1128 static struct snd_pcm_ops snd_ca0106_capture_1_ops = {
1129 .open = snd_ca0106_pcm_open_1_capture,
1130 .close = snd_ca0106_pcm_close_capture,
1132 .hw_params = snd_ca0106_pcm_hw_params_capture,
1133 .hw_free = snd_ca0106_pcm_hw_free_capture,
1134 .prepare = snd_ca0106_pcm_prepare_capture,
1135 .trigger = snd_ca0106_pcm_trigger_capture,
1136 .pointer = snd_ca0106_pcm_pointer_capture,
1139 static struct snd_pcm_ops snd_ca0106_capture_2_ops = {
1140 .open = snd_ca0106_pcm_open_2_capture,
1141 .close = snd_ca0106_pcm_close_capture,
1143 .hw_params = snd_ca0106_pcm_hw_params_capture,
1144 .hw_free = snd_ca0106_pcm_hw_free_capture,
1145 .prepare = snd_ca0106_pcm_prepare_capture,
1146 .trigger = snd_ca0106_pcm_trigger_capture,
1147 .pointer = snd_ca0106_pcm_pointer_capture,
1150 static struct snd_pcm_ops snd_ca0106_capture_3_ops = {
1151 .open = snd_ca0106_pcm_open_3_capture,
1152 .close = snd_ca0106_pcm_close_capture,
1154 .hw_params = snd_ca0106_pcm_hw_params_capture,
1155 .hw_free = snd_ca0106_pcm_hw_free_capture,
1156 .prepare = snd_ca0106_pcm_prepare_capture,
1157 .trigger = snd_ca0106_pcm_trigger_capture,
1158 .pointer = snd_ca0106_pcm_pointer_capture,
1161 static struct snd_pcm_ops snd_ca0106_playback_center_lfe_ops = {
1162 .open = snd_ca0106_pcm_open_playback_center_lfe,
1163 .close = snd_ca0106_pcm_close_playback,
1165 .hw_params = snd_ca0106_pcm_hw_params_playback,
1166 .hw_free = snd_ca0106_pcm_hw_free_playback,
1167 .prepare = snd_ca0106_pcm_prepare_playback,
1168 .trigger = snd_ca0106_pcm_trigger_playback,
1169 .pointer = snd_ca0106_pcm_pointer_playback,
1172 static struct snd_pcm_ops snd_ca0106_playback_unknown_ops = {
1173 .open = snd_ca0106_pcm_open_playback_unknown,
1174 .close = snd_ca0106_pcm_close_playback,
1176 .hw_params = snd_ca0106_pcm_hw_params_playback,
1177 .hw_free = snd_ca0106_pcm_hw_free_playback,
1178 .prepare = snd_ca0106_pcm_prepare_playback,
1179 .trigger = snd_ca0106_pcm_trigger_playback,
1180 .pointer = snd_ca0106_pcm_pointer_playback,
1183 static struct snd_pcm_ops snd_ca0106_playback_rear_ops = {
1184 .open = snd_ca0106_pcm_open_playback_rear,
1185 .close = snd_ca0106_pcm_close_playback,
1187 .hw_params = snd_ca0106_pcm_hw_params_playback,
1188 .hw_free = snd_ca0106_pcm_hw_free_playback,
1189 .prepare = snd_ca0106_pcm_prepare_playback,
1190 .trigger = snd_ca0106_pcm_trigger_playback,
1191 .pointer = snd_ca0106_pcm_pointer_playback,
1195 static unsigned short snd_ca0106_ac97_read(
struct snd_ac97 *ac97,
1199 unsigned long flags;
1205 spin_unlock_irqrestore(&emu->
emu_lock, flags);
1209 static void snd_ca0106_ac97_write(
struct snd_ac97 *
ac97,
1210 unsigned short reg,
unsigned short val)
1213 unsigned long flags;
1218 spin_unlock_irqrestore(&emu->
emu_lock, flags);
1221 static int snd_ca0106_ac97(
struct snd_ca0106 *chip)
1227 .write = snd_ca0106_ac97_write,
1228 .read = snd_ca0106_ac97_read,
1235 memset(&ac97, 0,
sizeof(ac97));
1241 static void ca0106_stop_chip(
struct snd_ca0106 *chip);
1243 static int snd_ca0106_free(
struct snd_ca0106 *chip)
1247 ca0106_stop_chip(chip);
1268 return snd_ca0106_free(chip);
1278 unsigned int stat76;
1293 for(i = 0; i < 4; i++) {
1295 if (stat76 & mask) {
1307 for(i = 0; i < 4; i++) {
1309 if (stat76 & mask) {
1323 if (chip->
midi.dev_id &&
1324 (status & (chip->
midi.ipr_tx|chip->
midi.ipr_rx))) {
1325 if (chip->
midi.interrupt)
1326 chip->
midi.interrupt(&chip->
midi, status);
1328 chip->
midi.interrupt_disable(&chip->
midi, chip->
midi.tx_enable | chip->
midi.rx_enable);
1396 substream = substream->
next) {
1400 64*1024, 64*1024)) < 0)
1406 substream = substream->
next) {
1410 64*1024, 64*1024)) < 0)
1419 emu->
pcm[device] = pcm;
1424 #define SPI_REG(reg, value) (((reg) << SPI_REG_SHIFT) | (value))
1425 static unsigned int spi_dac_init[] = {
1443 static unsigned int i2c_adc_init[][2] = {
1462 unsigned int def_bits;
1540 for (ch = 0; ch < 4; ch++) {
1551 if (chip->
details->i2c_adc == 1) {
1557 }
else if (chip->
details->ac97 == 1) {
1571 if (chip->
details->gpio_type == 2) {
1579 }
else if (chip->
details->gpio_type == 1) {
1592 snd_ca0106_intr_enable(chip, 0x105);
1601 if (chip->
details->i2c_adc == 1) {
1607 for (n = 0; n <
size; n++)
1609 i2c_adc_init[n][1]);
1610 for (n = 0; n < 4; n++) {
1624 for (n = 0; n <
size; n++) {
1637 static void ca0106_stop_chip(
struct snd_ca0106 *chip)
1661 .dev_free = snd_ca0106_dev_free,
1670 pci_set_consistent_dma_mask(pci,
DMA_BIT_MASK(32)) < 0) {
1691 snd_ca0106_free(chip);
1698 snd_ca0106_free(chip);
1706 1024, &chip->
buffer) < 0) {
1707 snd_ca0106_free(chip);
1720 for (c = ca0106_chip_details; c->
serial; c++) {
1721 if (subsystem[dev]) {
1722 if (c->
serial == subsystem[dev])
1728 if (subsystem[dev]) {
1730 "subsystem=0x%x. Forced to subsystem=0x%x\n",
1737 ca0106_init_chip(chip, 0);
1741 snd_ca0106_free(chip);
1749 static void ca0106_midi_interrupt_enable(
struct snd_ca_midi *midi,
int intr)
1754 static void ca0106_midi_interrupt_disable(
struct snd_ca_midi *midi,
int intr)
1759 static unsigned char ca0106_midi_read(
struct snd_ca_midi *midi,
int idx)
1762 midi->
port + idx, 0);
1765 static void ca0106_midi_write(
struct snd_ca_midi *midi,
int data,
int idx)
1770 static struct snd_card *ca0106_dev_id_card(
void *dev_id)
1775 static int ca0106_dev_id_port(
void *dev_id)
1787 name =
"CA0106 MPU-401 (UART) B";
1788 midi = &chip->
midi2;
1795 name =
"CA0106 MPU-401 (UART)";
1816 midi->
read = ca0106_midi_read;
1817 midi->
write = ca0106_midi_write;
1850 err = snd_ca0106_create(dev, card, pci, &chip);
1855 for (i = 0; i < 4; i++) {
1861 if (chip->
details->ac97 == 1) {
1863 err = snd_ca0106_ac97(chip);
1871 snd_printdd(
"ca0106: probe for MIDI channel A ...");
1877 #ifdef CONFIG_PROC_FS
1887 pci_set_drvdata(pci, card);
1899 pci_set_drvdata(pci,
NULL);
1902 #ifdef CONFIG_PM_SLEEP
1903 static int snd_ca0106_suspend(
struct device *dev)
1911 for (i = 0; i < 4; i++)
1912 snd_pcm_suspend_all(chip->
pcm[i]);
1914 snd_ac97_suspend(chip->
ac97);
1917 ca0106_stop_chip(chip);
1925 static int snd_ca0106_resume(
struct device *dev)
1942 ca0106_init_chip(chip, 1);
1945 snd_ac97_resume(chip->
ac97);
1957 #define SND_CA0106_PM_OPS &snd_ca0106_pm
1959 #define SND_CA0106_PM_OPS NULL
1971 .name = KBUILD_MODNAME,
1972 .id_table = snd_ca0106_ids,
1973 .probe = snd_ca0106_probe,