diff options
author | Takashi Iwai <tiwai@suse.de> | 2008-11-24 08:06:08 -0500 |
---|---|---|
committer | Takashi Iwai <tiwai@suse.de> | 2008-12-04 09:25:03 -0500 |
commit | 5da95273c2e63c9607652b5e8dd39808b6992d7c (patch) | |
tree | f4f7b0c7af29c29524ea93855552d326a0cc58ff /sound/pci/ca0106 | |
parent | 9bf1a2445f3c569098b8de7097ca324e65abecc2 (diff) |
ALSA: ca0106 - Add power-management support
Added the missing PM support for snd-ca0106 driver.
Signed-off-by: Takashi Iwai <tiwai@suse.de>
Diffstat (limited to 'sound/pci/ca0106')
-rw-r--r-- | sound/pci/ca0106/ca0106.h | 15 | ||||
-rw-r--r-- | sound/pci/ca0106/ca0106_main.c | 519 | ||||
-rw-r--r-- | sound/pci/ca0106/ca0106_mixer.c | 182 |
3 files changed, 450 insertions, 266 deletions
diff --git a/sound/pci/ca0106/ca0106.h b/sound/pci/ca0106/ca0106.h index 74175fc80c7f..1c14ff424116 100644 --- a/sound/pci/ca0106/ca0106.h +++ b/sound/pci/ca0106/ca0106.h | |||
@@ -686,7 +686,7 @@ struct snd_ca0106 { | |||
686 | spinlock_t emu_lock; | 686 | spinlock_t emu_lock; |
687 | 687 | ||
688 | struct snd_ac97 *ac97; | 688 | struct snd_ac97 *ac97; |
689 | struct snd_pcm *pcm; | 689 | struct snd_pcm *pcm[4]; |
690 | 690 | ||
691 | struct snd_ca0106_channel playback_channels[4]; | 691 | struct snd_ca0106_channel playback_channels[4]; |
692 | struct snd_ca0106_channel capture_channels[4]; | 692 | struct snd_ca0106_channel capture_channels[4]; |
@@ -703,6 +703,11 @@ struct snd_ca0106 { | |||
703 | struct snd_ca_midi midi2; | 703 | struct snd_ca_midi midi2; |
704 | 704 | ||
705 | u16 spi_dac_reg[16]; | 705 | u16 spi_dac_reg[16]; |
706 | |||
707 | #ifdef CONFIG_PM | ||
708 | #define NUM_SAVED_VOLUMES 9 | ||
709 | unsigned int saved_vol[NUM_SAVED_VOLUMES]; | ||
710 | #endif | ||
706 | }; | 711 | }; |
707 | 712 | ||
708 | int snd_ca0106_mixer(struct snd_ca0106 *emu); | 713 | int snd_ca0106_mixer(struct snd_ca0106 *emu); |
@@ -721,3 +726,11 @@ int snd_ca0106_i2c_write(struct snd_ca0106 *emu, u32 reg, u32 value); | |||
721 | 726 | ||
722 | int snd_ca0106_spi_write(struct snd_ca0106 * emu, | 727 | int snd_ca0106_spi_write(struct snd_ca0106 * emu, |
723 | unsigned int data); | 728 | unsigned int data); |
729 | |||
730 | #ifdef CONFIG_PM | ||
731 | void snd_ca0106_mixer_suspend(struct snd_ca0106 *chip); | ||
732 | void snd_ca0106_mixer_resume(struct snd_ca0106 *chip); | ||
733 | #else | ||
734 | #define snd_ca0106_mixer_suspend(chip) do { } while (0) | ||
735 | #define snd_ca0106_mixer_resume(chip) do { } while (0) | ||
736 | #endif | ||
diff --git a/sound/pci/ca0106/ca0106_main.c b/sound/pci/ca0106/ca0106_main.c index 88fbf285d2b7..cea8a7cdb1d5 100644 --- a/sound/pci/ca0106/ca0106_main.c +++ b/sound/pci/ca0106/ca0106_main.c | |||
@@ -847,15 +847,18 @@ static int snd_ca0106_pcm_trigger_playback(struct snd_pcm_substream *substream, | |||
847 | struct snd_pcm_substream *s; | 847 | struct snd_pcm_substream *s; |
848 | u32 basic = 0; | 848 | u32 basic = 0; |
849 | u32 extended = 0; | 849 | u32 extended = 0; |
850 | int running=0; | 850 | u32 bits; |
851 | int running = 0; | ||
851 | 852 | ||
852 | switch (cmd) { | 853 | switch (cmd) { |
853 | case SNDRV_PCM_TRIGGER_START: | 854 | case SNDRV_PCM_TRIGGER_START: |
854 | running=1; | 855 | case SNDRV_PCM_TRIGGER_RESUME: |
856 | running = 1; | ||
855 | break; | 857 | break; |
856 | case SNDRV_PCM_TRIGGER_STOP: | 858 | case SNDRV_PCM_TRIGGER_STOP: |
859 | case SNDRV_PCM_TRIGGER_SUSPEND: | ||
857 | default: | 860 | default: |
858 | running=0; | 861 | running = 0; |
859 | break; | 862 | break; |
860 | } | 863 | } |
861 | snd_pcm_group_for_each_entry(s, substream) { | 864 | snd_pcm_group_for_each_entry(s, substream) { |
@@ -865,22 +868,32 @@ static int snd_ca0106_pcm_trigger_playback(struct snd_pcm_substream *substream, | |||
865 | runtime = s->runtime; | 868 | runtime = s->runtime; |
866 | epcm = runtime->private_data; | 869 | epcm = runtime->private_data; |
867 | channel = epcm->channel_id; | 870 | channel = epcm->channel_id; |
868 | //snd_printk("channel=%d\n",channel); | 871 | /* snd_printk("channel=%d\n",channel); */ |
869 | epcm->running = running; | 872 | epcm->running = running; |
870 | basic |= (0x1<<channel); | 873 | basic |= (0x1 << channel); |
871 | extended |= (0x10<<channel); | 874 | extended |= (0x10 << channel); |
872 | snd_pcm_trigger_done(s, substream); | 875 | snd_pcm_trigger_done(s, substream); |
873 | } | 876 | } |
874 | //snd_printk("basic=0x%x, extended=0x%x\n",basic, extended); | 877 | /* snd_printk("basic=0x%x, extended=0x%x\n",basic, extended); */ |
875 | 878 | ||
876 | switch (cmd) { | 879 | switch (cmd) { |
877 | case SNDRV_PCM_TRIGGER_START: | 880 | case SNDRV_PCM_TRIGGER_START: |
878 | snd_ca0106_ptr_write(emu, EXTENDED_INT_MASK, 0, snd_ca0106_ptr_read(emu, EXTENDED_INT_MASK, 0) | (extended)); | 881 | case SNDRV_PCM_TRIGGER_RESUME: |
879 | snd_ca0106_ptr_write(emu, BASIC_INTERRUPT, 0, snd_ca0106_ptr_read(emu, BASIC_INTERRUPT, 0)|(basic)); | 882 | bits = snd_ca0106_ptr_read(emu, EXTENDED_INT_MASK, 0); |
883 | bits |= extended; | ||
884 | snd_ca0106_ptr_write(emu, EXTENDED_INT_MASK, 0, bits); | ||
885 | bits = snd_ca0106_ptr_read(emu, BASIC_INTERRUPT, 0); | ||
886 | bits |= basic; | ||
887 | snd_ca0106_ptr_write(emu, BASIC_INTERRUPT, 0, bits); | ||
880 | break; | 888 | break; |
881 | case SNDRV_PCM_TRIGGER_STOP: | 889 | case SNDRV_PCM_TRIGGER_STOP: |
882 | snd_ca0106_ptr_write(emu, BASIC_INTERRUPT, 0, snd_ca0106_ptr_read(emu, BASIC_INTERRUPT, 0) & ~(basic)); | 890 | case SNDRV_PCM_TRIGGER_SUSPEND: |
883 | snd_ca0106_ptr_write(emu, EXTENDED_INT_MASK, 0, snd_ca0106_ptr_read(emu, EXTENDED_INT_MASK, 0) & ~(extended)); | 891 | bits = snd_ca0106_ptr_read(emu, BASIC_INTERRUPT, 0); |
892 | bits &= ~basic; | ||
893 | snd_ca0106_ptr_write(emu, BASIC_INTERRUPT, 0, bits); | ||
894 | bits = snd_ca0106_ptr_read(emu, EXTENDED_INT_MASK, 0); | ||
895 | bits &= ~extended; | ||
896 | snd_ca0106_ptr_write(emu, EXTENDED_INT_MASK, 0, bits); | ||
884 | break; | 897 | break; |
885 | default: | 898 | default: |
886 | result = -EINVAL; | 899 | result = -EINVAL; |
@@ -1103,21 +1116,13 @@ static int snd_ca0106_ac97(struct snd_ca0106 *chip) | |||
1103 | return snd_ac97_mixer(pbus, &ac97, &chip->ac97); | 1116 | return snd_ac97_mixer(pbus, &ac97, &chip->ac97); |
1104 | } | 1117 | } |
1105 | 1118 | ||
1119 | static void ca0106_stop_chip(struct snd_ca0106 *chip); | ||
1120 | |||
1106 | static int snd_ca0106_free(struct snd_ca0106 *chip) | 1121 | static int snd_ca0106_free(struct snd_ca0106 *chip) |
1107 | { | 1122 | { |
1108 | if (chip->res_port != NULL) { /* avoid access to already used hardware */ | 1123 | if (chip->res_port != NULL) { |
1109 | // disable interrupts | 1124 | /* avoid access to already used hardware */ |
1110 | snd_ca0106_ptr_write(chip, BASIC_INTERRUPT, 0, 0); | 1125 | ca0106_stop_chip(chip); |
1111 | outl(0, chip->port + INTE); | ||
1112 | snd_ca0106_ptr_write(chip, EXTENDED_INT_MASK, 0, 0); | ||
1113 | udelay(1000); | ||
1114 | // disable audio | ||
1115 | //outl(HCFG_LOCKSOUNDCACHE, chip->port + HCFG); | ||
1116 | outl(0, chip->port + HCFG); | ||
1117 | /* FIXME: We need to stop and DMA transfers here. | ||
1118 | * But as I am not sure how yet, we cannot from the dma pages. | ||
1119 | * So we can fix: snd-malloc: Memory leak? pages not freed = 8 | ||
1120 | */ | ||
1121 | } | 1126 | } |
1122 | if (chip->irq >= 0) | 1127 | if (chip->irq >= 0) |
1123 | free_irq(chip->irq, chip); | 1128 | free_irq(chip->irq, chip); |
@@ -1203,15 +1208,14 @@ static irqreturn_t snd_ca0106_interrupt(int irq, void *dev_id) | |||
1203 | return IRQ_HANDLED; | 1208 | return IRQ_HANDLED; |
1204 | } | 1209 | } |
1205 | 1210 | ||
1206 | static int __devinit snd_ca0106_pcm(struct snd_ca0106 *emu, int device, struct snd_pcm **rpcm) | 1211 | static int __devinit snd_ca0106_pcm(struct snd_ca0106 *emu, int device) |
1207 | { | 1212 | { |
1208 | struct snd_pcm *pcm; | 1213 | struct snd_pcm *pcm; |
1209 | struct snd_pcm_substream *substream; | 1214 | struct snd_pcm_substream *substream; |
1210 | int err; | 1215 | int err; |
1211 | 1216 | ||
1212 | if (rpcm) | 1217 | err = snd_pcm_new(emu->card, "ca0106", device, 1, 1, &pcm); |
1213 | *rpcm = NULL; | 1218 | if (err < 0) |
1214 | if ((err = snd_pcm_new(emu->card, "ca0106", device, 1, 1, &pcm)) < 0) | ||
1215 | return err; | 1219 | return err; |
1216 | 1220 | ||
1217 | pcm->private_data = emu; | 1221 | pcm->private_data = emu; |
@@ -1238,7 +1242,6 @@ static int __devinit snd_ca0106_pcm(struct snd_ca0106 *emu, int device, struct s | |||
1238 | pcm->info_flags = 0; | 1242 | pcm->info_flags = 0; |
1239 | pcm->dev_subclass = SNDRV_PCM_SUBCLASS_GENERIC_MIX; | 1243 | pcm->dev_subclass = SNDRV_PCM_SUBCLASS_GENERIC_MIX; |
1240 | strcpy(pcm->name, "CA0106"); | 1244 | strcpy(pcm->name, "CA0106"); |
1241 | emu->pcm = pcm; | ||
1242 | 1245 | ||
1243 | for(substream = pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream; | 1246 | for(substream = pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream; |
1244 | substream; | 1247 | substream; |
@@ -1260,8 +1263,7 @@ static int __devinit snd_ca0106_pcm(struct snd_ca0106 *emu, int device, struct s | |||
1260 | return err; | 1263 | return err; |
1261 | } | 1264 | } |
1262 | 1265 | ||
1263 | if (rpcm) | 1266 | emu->pcm[device] = pcm; |
1264 | *rpcm = pcm; | ||
1265 | 1267 | ||
1266 | return 0; | 1268 | return 0; |
1267 | } | 1269 | } |
@@ -1301,89 +1303,9 @@ static unsigned int i2c_adc_init[][2] = { | |||
1301 | { 0x15, ADC_MUX_LINEIN }, /* ADC Mixer control */ | 1303 | { 0x15, ADC_MUX_LINEIN }, /* ADC Mixer control */ |
1302 | }; | 1304 | }; |
1303 | 1305 | ||
1304 | static int __devinit snd_ca0106_create(int dev, struct snd_card *card, | 1306 | static void ca0106_init_chip(struct snd_ca0106 *chip) |
1305 | struct pci_dev *pci, | ||
1306 | struct snd_ca0106 **rchip) | ||
1307 | { | 1307 | { |
1308 | struct snd_ca0106 *chip; | ||
1309 | struct snd_ca0106_details *c; | ||
1310 | int err; | ||
1311 | int ch; | 1308 | int ch; |
1312 | static struct snd_device_ops ops = { | ||
1313 | .dev_free = snd_ca0106_dev_free, | ||
1314 | }; | ||
1315 | |||
1316 | *rchip = NULL; | ||
1317 | |||
1318 | if ((err = pci_enable_device(pci)) < 0) | ||
1319 | return err; | ||
1320 | if (pci_set_dma_mask(pci, DMA_32BIT_MASK) < 0 || | ||
1321 | pci_set_consistent_dma_mask(pci, DMA_32BIT_MASK) < 0) { | ||
1322 | printk(KERN_ERR "error to set 32bit mask DMA\n"); | ||
1323 | pci_disable_device(pci); | ||
1324 | return -ENXIO; | ||
1325 | } | ||
1326 | |||
1327 | chip = kzalloc(sizeof(*chip), GFP_KERNEL); | ||
1328 | if (chip == NULL) { | ||
1329 | pci_disable_device(pci); | ||
1330 | return -ENOMEM; | ||
1331 | } | ||
1332 | |||
1333 | chip->card = card; | ||
1334 | chip->pci = pci; | ||
1335 | chip->irq = -1; | ||
1336 | |||
1337 | spin_lock_init(&chip->emu_lock); | ||
1338 | |||
1339 | chip->port = pci_resource_start(pci, 0); | ||
1340 | if ((chip->res_port = request_region(chip->port, 0x20, | ||
1341 | "snd_ca0106")) == NULL) { | ||
1342 | snd_ca0106_free(chip); | ||
1343 | printk(KERN_ERR "cannot allocate the port\n"); | ||
1344 | return -EBUSY; | ||
1345 | } | ||
1346 | |||
1347 | if (request_irq(pci->irq, snd_ca0106_interrupt, | ||
1348 | IRQF_SHARED, "snd_ca0106", chip)) { | ||
1349 | snd_ca0106_free(chip); | ||
1350 | printk(KERN_ERR "cannot grab irq\n"); | ||
1351 | return -EBUSY; | ||
1352 | } | ||
1353 | chip->irq = pci->irq; | ||
1354 | |||
1355 | /* This stores the periods table. */ | ||
1356 | if(snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(pci), 1024, &chip->buffer) < 0) { | ||
1357 | snd_ca0106_free(chip); | ||
1358 | return -ENOMEM; | ||
1359 | } | ||
1360 | |||
1361 | pci_set_master(pci); | ||
1362 | /* read serial */ | ||
1363 | pci_read_config_dword(pci, PCI_SUBSYSTEM_VENDOR_ID, &chip->serial); | ||
1364 | pci_read_config_word(pci, PCI_SUBSYSTEM_ID, &chip->model); | ||
1365 | #if 1 | ||
1366 | printk(KERN_INFO "snd-ca0106: Model %04x Rev %08x Serial %08x\n", chip->model, | ||
1367 | pci->revision, chip->serial); | ||
1368 | #endif | ||
1369 | strcpy(card->driver, "CA0106"); | ||
1370 | strcpy(card->shortname, "CA0106"); | ||
1371 | |||
1372 | for (c = ca0106_chip_details; c->serial; c++) { | ||
1373 | if (subsystem[dev]) { | ||
1374 | if (c->serial == subsystem[dev]) | ||
1375 | break; | ||
1376 | } else if (c->serial == chip->serial) | ||
1377 | break; | ||
1378 | } | ||
1379 | chip->details = c; | ||
1380 | if (subsystem[dev]) { | ||
1381 | printk(KERN_INFO "snd-ca0106: Sound card name=%s, subsystem=0x%x. Forced to subsystem=0x%x\n", | ||
1382 | c->name, chip->serial, subsystem[dev]); | ||
1383 | } | ||
1384 | |||
1385 | sprintf(card->longname, "%s at 0x%lx irq %i", | ||
1386 | c->name, chip->port, chip->irq); | ||
1387 | 1309 | ||
1388 | outl(0, chip->port + INTE); | 1310 | outl(0, chip->port + INTE); |
1389 | 1311 | ||
@@ -1401,31 +1323,31 @@ static int __devinit snd_ca0106_create(int dev, struct snd_card *card, | |||
1401 | * AN = 0 (Audio data) | 1323 | * AN = 0 (Audio data) |
1402 | * P = 0 (Consumer) | 1324 | * P = 0 (Consumer) |
1403 | */ | 1325 | */ |
1404 | snd_ca0106_ptr_write(chip, SPCS0, 0, | 1326 | chip->spdif_bits[0] = |
1405 | chip->spdif_bits[0] = | 1327 | SPCS_CLKACCY_1000PPM | SPCS_SAMPLERATE_48 | |
1406 | SPCS_CLKACCY_1000PPM | SPCS_SAMPLERATE_48 | | 1328 | SPCS_CHANNELNUM_LEFT | SPCS_SOURCENUM_UNSPEC | |
1407 | SPCS_CHANNELNUM_LEFT | SPCS_SOURCENUM_UNSPEC | | 1329 | SPCS_GENERATIONSTATUS | 0x00001200 | |
1408 | SPCS_GENERATIONSTATUS | 0x00001200 | | 1330 | 0x00000000 | SPCS_EMPHASIS_NONE | SPCS_COPYRIGHT; |
1409 | 0x00000000 | SPCS_EMPHASIS_NONE | SPCS_COPYRIGHT); | 1331 | snd_ca0106_ptr_write(chip, SPCS0, 0, chip->spdif_bits[0]); |
1410 | /* Only SPCS1 has been tested */ | 1332 | /* Only SPCS1 has been tested */ |
1411 | snd_ca0106_ptr_write(chip, SPCS1, 0, | 1333 | chip->spdif_bits[1] = |
1412 | chip->spdif_bits[1] = | 1334 | SPCS_CLKACCY_1000PPM | SPCS_SAMPLERATE_48 | |
1413 | SPCS_CLKACCY_1000PPM | SPCS_SAMPLERATE_48 | | 1335 | SPCS_CHANNELNUM_LEFT | SPCS_SOURCENUM_UNSPEC | |
1414 | SPCS_CHANNELNUM_LEFT | SPCS_SOURCENUM_UNSPEC | | 1336 | SPCS_GENERATIONSTATUS | 0x00001200 | |
1415 | SPCS_GENERATIONSTATUS | 0x00001200 | | 1337 | 0x00000000 | SPCS_EMPHASIS_NONE | SPCS_COPYRIGHT; |
1416 | 0x00000000 | SPCS_EMPHASIS_NONE | SPCS_COPYRIGHT); | 1338 | snd_ca0106_ptr_write(chip, SPCS1, 0, chip->spdif_bits[1]); |
1417 | snd_ca0106_ptr_write(chip, SPCS2, 0, | 1339 | chip->spdif_bits[2] = |
1418 | chip->spdif_bits[2] = | 1340 | SPCS_CLKACCY_1000PPM | SPCS_SAMPLERATE_48 | |
1419 | SPCS_CLKACCY_1000PPM | SPCS_SAMPLERATE_48 | | 1341 | SPCS_CHANNELNUM_LEFT | SPCS_SOURCENUM_UNSPEC | |
1420 | SPCS_CHANNELNUM_LEFT | SPCS_SOURCENUM_UNSPEC | | 1342 | SPCS_GENERATIONSTATUS | 0x00001200 | |
1421 | SPCS_GENERATIONSTATUS | 0x00001200 | | 1343 | 0x00000000 | SPCS_EMPHASIS_NONE | SPCS_COPYRIGHT; |
1422 | 0x00000000 | SPCS_EMPHASIS_NONE | SPCS_COPYRIGHT); | 1344 | snd_ca0106_ptr_write(chip, SPCS2, 0, chip->spdif_bits[2]); |
1423 | snd_ca0106_ptr_write(chip, SPCS3, 0, | 1345 | chip->spdif_bits[3] = |
1424 | chip->spdif_bits[3] = | 1346 | SPCS_CLKACCY_1000PPM | SPCS_SAMPLERATE_48 | |
1425 | SPCS_CLKACCY_1000PPM | SPCS_SAMPLERATE_48 | | 1347 | SPCS_CHANNELNUM_LEFT | SPCS_SOURCENUM_UNSPEC | |
1426 | SPCS_CHANNELNUM_LEFT | SPCS_SOURCENUM_UNSPEC | | 1348 | SPCS_GENERATIONSTATUS | 0x00001200 | |
1427 | SPCS_GENERATIONSTATUS | 0x00001200 | | 1349 | 0x00000000 | SPCS_EMPHASIS_NONE | SPCS_COPYRIGHT; |
1428 | 0x00000000 | SPCS_EMPHASIS_NONE | SPCS_COPYRIGHT); | 1350 | snd_ca0106_ptr_write(chip, SPCS3, 0, chip->spdif_bits[3]); |
1429 | 1351 | ||
1430 | snd_ca0106_ptr_write(chip, PLAYBACK_MUTE, 0, 0x00fc0000); | 1352 | snd_ca0106_ptr_write(chip, PLAYBACK_MUTE, 0, 0x00fc0000); |
1431 | snd_ca0106_ptr_write(chip, CAPTURE_MUTE, 0, 0x00fc0000); | 1353 | snd_ca0106_ptr_write(chip, CAPTURE_MUTE, 0, 0x00fc0000); |
@@ -1433,36 +1355,53 @@ static int __devinit snd_ca0106_create(int dev, struct snd_card *card, | |||
1433 | /* Write 0x8000 to AC97_REC_GAIN to mute it. */ | 1355 | /* Write 0x8000 to AC97_REC_GAIN to mute it. */ |
1434 | outb(AC97_REC_GAIN, chip->port + AC97ADDRESS); | 1356 | outb(AC97_REC_GAIN, chip->port + AC97ADDRESS); |
1435 | outw(0x8000, chip->port + AC97DATA); | 1357 | outw(0x8000, chip->port + AC97DATA); |
1436 | #if 0 | 1358 | #if 0 /* FIXME: what are these? */ |
1437 | snd_ca0106_ptr_write(chip, SPCS0, 0, 0x2108006); | 1359 | snd_ca0106_ptr_write(chip, SPCS0, 0, 0x2108006); |
1438 | snd_ca0106_ptr_write(chip, 0x42, 0, 0x2108006); | 1360 | snd_ca0106_ptr_write(chip, 0x42, 0, 0x2108006); |
1439 | snd_ca0106_ptr_write(chip, 0x43, 0, 0x2108006); | 1361 | snd_ca0106_ptr_write(chip, 0x43, 0, 0x2108006); |
1440 | snd_ca0106_ptr_write(chip, 0x44, 0, 0x2108006); | 1362 | snd_ca0106_ptr_write(chip, 0x44, 0, 0x2108006); |
1441 | #endif | 1363 | #endif |
1442 | 1364 | ||
1443 | //snd_ca0106_ptr_write(chip, SPDIF_SELECT2, 0, 0xf0f003f); /* OSS drivers set this. */ | 1365 | /* OSS drivers set this. */ |
1366 | /* snd_ca0106_ptr_write(chip, SPDIF_SELECT2, 0, 0xf0f003f); */ | ||
1367 | |||
1444 | /* Analog or Digital output */ | 1368 | /* Analog or Digital output */ |
1445 | snd_ca0106_ptr_write(chip, SPDIF_SELECT1, 0, 0xf); | 1369 | snd_ca0106_ptr_write(chip, SPDIF_SELECT1, 0, 0xf); |
1446 | snd_ca0106_ptr_write(chip, SPDIF_SELECT2, 0, 0x000f0000); /* 0x0b000000 for digital, 0x000b0000 for analog, from win2000 drivers. Use 0x000f0000 for surround71 */ | 1370 | /* 0x0b000000 for digital, 0x000b0000 for analog, from win2000 drivers. |
1371 | * Use 0x000f0000 for surround71 | ||
1372 | */ | ||
1373 | snd_ca0106_ptr_write(chip, SPDIF_SELECT2, 0, 0x000f0000); | ||
1374 | |||
1447 | chip->spdif_enable = 0; /* Set digital SPDIF output off */ | 1375 | chip->spdif_enable = 0; /* Set digital SPDIF output off */ |
1448 | //snd_ca0106_ptr_write(chip, 0x45, 0, 0); /* Analogue out */ | 1376 | /*snd_ca0106_ptr_write(chip, 0x45, 0, 0);*/ /* Analogue out */ |
1449 | //snd_ca0106_ptr_write(chip, 0x45, 0, 0xf00); /* Digital out */ | 1377 | /*snd_ca0106_ptr_write(chip, 0x45, 0, 0xf00);*/ /* Digital out */ |
1378 | |||
1379 | /* goes to 0x40c80000 when doing SPDIF IN/OUT */ | ||
1380 | snd_ca0106_ptr_write(chip, CAPTURE_CONTROL, 0, 0x40c81000); | ||
1381 | /* (Mute) CAPTURE feedback into PLAYBACK volume. | ||
1382 | * Only lower 16 bits matter. | ||
1383 | */ | ||
1384 | snd_ca0106_ptr_write(chip, CAPTURE_CONTROL, 1, 0xffffffff); | ||
1385 | /* SPDIF IN Volume */ | ||
1386 | snd_ca0106_ptr_write(chip, CAPTURE_CONTROL, 2, 0x30300000); | ||
1387 | /* SPDIF IN Volume, 0x70 = (vol & 0x3f) | 0x40 */ | ||
1388 | snd_ca0106_ptr_write(chip, CAPTURE_CONTROL, 3, 0x00700000); | ||
1450 | 1389 | ||
1451 | snd_ca0106_ptr_write(chip, CAPTURE_CONTROL, 0, 0x40c81000); /* goes to 0x40c80000 when doing SPDIF IN/OUT */ | ||
1452 | snd_ca0106_ptr_write(chip, CAPTURE_CONTROL, 1, 0xffffffff); /* (Mute) CAPTURE feedback into PLAYBACK volume. Only lower 16 bits matter. */ | ||
1453 | snd_ca0106_ptr_write(chip, CAPTURE_CONTROL, 2, 0x30300000); /* SPDIF IN Volume */ | ||
1454 | snd_ca0106_ptr_write(chip, CAPTURE_CONTROL, 3, 0x00700000); /* SPDIF IN Volume, 0x70 = (vol & 0x3f) | 0x40 */ | ||
1455 | snd_ca0106_ptr_write(chip, PLAYBACK_ROUTING1, 0, 0x32765410); | 1390 | snd_ca0106_ptr_write(chip, PLAYBACK_ROUTING1, 0, 0x32765410); |
1456 | snd_ca0106_ptr_write(chip, PLAYBACK_ROUTING2, 0, 0x76767676); | 1391 | snd_ca0106_ptr_write(chip, PLAYBACK_ROUTING2, 0, 0x76767676); |
1457 | snd_ca0106_ptr_write(chip, CAPTURE_ROUTING1, 0, 0x32765410); | 1392 | snd_ca0106_ptr_write(chip, CAPTURE_ROUTING1, 0, 0x32765410); |
1458 | snd_ca0106_ptr_write(chip, CAPTURE_ROUTING2, 0, 0x76767676); | 1393 | snd_ca0106_ptr_write(chip, CAPTURE_ROUTING2, 0, 0x76767676); |
1459 | for(ch = 0; ch < 4; ch++) { | 1394 | |
1460 | snd_ca0106_ptr_write(chip, CAPTURE_VOLUME1, ch, 0x30303030); /* Only high 16 bits matter */ | 1395 | for (ch = 0; ch < 4; ch++) { |
1396 | /* Only high 16 bits matter */ | ||
1397 | snd_ca0106_ptr_write(chip, CAPTURE_VOLUME1, ch, 0x30303030); | ||
1461 | snd_ca0106_ptr_write(chip, CAPTURE_VOLUME2, ch, 0x30303030); | 1398 | snd_ca0106_ptr_write(chip, CAPTURE_VOLUME2, ch, 0x30303030); |
1462 | //snd_ca0106_ptr_write(chip, PLAYBACK_VOLUME1, ch, 0x40404040); /* Mute */ | 1399 | #if 0 /* Mute */ |
1463 | //snd_ca0106_ptr_write(chip, PLAYBACK_VOLUME2, ch, 0x40404040); /* Mute */ | 1400 | snd_ca0106_ptr_write(chip, PLAYBACK_VOLUME1, ch, 0x40404040); |
1464 | snd_ca0106_ptr_write(chip, PLAYBACK_VOLUME1, ch, 0xffffffff); /* Mute */ | 1401 | snd_ca0106_ptr_write(chip, PLAYBACK_VOLUME2, ch, 0x40404040); |
1465 | snd_ca0106_ptr_write(chip, PLAYBACK_VOLUME2, ch, 0xffffffff); /* Mute */ | 1402 | snd_ca0106_ptr_write(chip, PLAYBACK_VOLUME1, ch, 0xffffffff); |
1403 | snd_ca0106_ptr_write(chip, PLAYBACK_VOLUME2, ch, 0xffffffff); | ||
1404 | #endif | ||
1466 | } | 1405 | } |
1467 | if (chip->details->i2c_adc == 1) { | 1406 | if (chip->details->i2c_adc == 1) { |
1468 | /* Select MIC, Line in, TAD in, AUX in */ | 1407 | /* Select MIC, Line in, TAD in, AUX in */ |
@@ -1481,44 +1420,56 @@ static int __devinit snd_ca0106_create(int dev, struct snd_card *card, | |||
1481 | chip->capture_source = 3; | 1420 | chip->capture_source = 3; |
1482 | } | 1421 | } |
1483 | 1422 | ||
1484 | if (chip->details->gpio_type == 2) { /* The SB0438 use GPIO differently. */ | 1423 | if (chip->details->gpio_type == 2) { |
1485 | /* FIXME: Still need to find out what the other GPIO bits do. E.g. For digital spdif out. */ | 1424 | /* The SB0438 use GPIO differently. */ |
1425 | /* FIXME: Still need to find out what the other GPIO bits do. | ||
1426 | * E.g. For digital spdif out. | ||
1427 | */ | ||
1486 | outl(0x0, chip->port+GPIO); | 1428 | outl(0x0, chip->port+GPIO); |
1487 | //outl(0x00f0e000, chip->port+GPIO); /* Analog */ | 1429 | /* outl(0x00f0e000, chip->port+GPIO); */ /* Analog */ |
1488 | outl(0x005f5301, chip->port+GPIO); /* Analog */ | 1430 | outl(0x005f5301, chip->port+GPIO); /* Analog */ |
1489 | } else if (chip->details->gpio_type == 1) { /* The SB0410 and SB0413 use GPIO differently. */ | 1431 | } else if (chip->details->gpio_type == 1) { |
1490 | /* FIXME: Still need to find out what the other GPIO bits do. E.g. For digital spdif out. */ | 1432 | /* The SB0410 and SB0413 use GPIO differently. */ |
1433 | /* FIXME: Still need to find out what the other GPIO bits do. | ||
1434 | * E.g. For digital spdif out. | ||
1435 | */ | ||
1491 | outl(0x0, chip->port+GPIO); | 1436 | outl(0x0, chip->port+GPIO); |
1492 | //outl(0x00f0e000, chip->port+GPIO); /* Analog */ | 1437 | /* outl(0x00f0e000, chip->port+GPIO); */ /* Analog */ |
1493 | outl(0x005f5301, chip->port+GPIO); /* Analog */ | 1438 | outl(0x005f5301, chip->port+GPIO); /* Analog */ |
1494 | } else { | 1439 | } else { |
1495 | outl(0x0, chip->port+GPIO); | 1440 | outl(0x0, chip->port+GPIO); |
1496 | outl(0x005f03a3, chip->port+GPIO); /* Analog */ | 1441 | outl(0x005f03a3, chip->port+GPIO); /* Analog */ |
1497 | //outl(0x005f02a2, chip->port+GPIO); /* SPDIF */ | 1442 | /* outl(0x005f02a2, chip->port+GPIO); */ /* SPDIF */ |
1498 | } | 1443 | } |
1499 | snd_ca0106_intr_enable(chip, 0x105); /* Win2000 uses 0x1e0 */ | 1444 | snd_ca0106_intr_enable(chip, 0x105); /* Win2000 uses 0x1e0 */ |
1500 | 1445 | ||
1501 | //outl(HCFG_LOCKSOUNDCACHE|HCFG_AUDIOENABLE, chip->port+HCFG); | 1446 | /* outl(HCFG_LOCKSOUNDCACHE|HCFG_AUDIOENABLE, chip->port+HCFG); */ |
1502 | //outl(0x00001409, chip->port+HCFG); /* 0x1000 causes AC3 to fails. Maybe it effects 24 bit output. */ | 1447 | /* 0x1000 causes AC3 to fails. Maybe it effects 24 bit output. */ |
1503 | //outl(0x00000009, chip->port+HCFG); | 1448 | /* outl(0x00001409, chip->port+HCFG); */ |
1504 | outl(HCFG_AC97 | HCFG_AUDIOENABLE, chip->port+HCFG); /* AC97 2.0, Enable outputs. */ | 1449 | /* outl(0x00000009, chip->port+HCFG); */ |
1450 | /* AC97 2.0, Enable outputs. */ | ||
1451 | outl(HCFG_AC97 | HCFG_AUDIOENABLE, chip->port+HCFG); | ||
1505 | 1452 | ||
1506 | if (chip->details->i2c_adc == 1) { /* The SB0410 and SB0413 use I2C to control ADC. */ | 1453 | if (chip->details->i2c_adc == 1) { |
1454 | /* The SB0410 and SB0413 use I2C to control ADC. */ | ||
1507 | int size, n; | 1455 | int size, n; |
1508 | 1456 | ||
1509 | size = ARRAY_SIZE(i2c_adc_init); | 1457 | size = ARRAY_SIZE(i2c_adc_init); |
1510 | //snd_printk("I2C:array size=0x%x\n", size); | 1458 | /* snd_printk("I2C:array size=0x%x\n", size); */ |
1511 | for (n=0; n < size; n++) { | 1459 | for (n = 0; n < size; n++) |
1512 | snd_ca0106_i2c_write(chip, i2c_adc_init[n][0], i2c_adc_init[n][1]); | 1460 | snd_ca0106_i2c_write(chip, i2c_adc_init[n][0], |
1513 | } | 1461 | i2c_adc_init[n][1]); |
1514 | for (n=0; n < 4; n++) { | 1462 | for (n = 0; n < 4; n++) { |
1515 | chip->i2c_capture_volume[n][0]= 0xcf; | 1463 | chip->i2c_capture_volume[n][0] = 0xcf; |
1516 | chip->i2c_capture_volume[n][1]= 0xcf; | 1464 | chip->i2c_capture_volume[n][1] = 0xcf; |
1517 | } | 1465 | } |
1518 | chip->i2c_capture_source=2; /* Line in */ | 1466 | chip->i2c_capture_source = 2; /* Line in */ |
1519 | //snd_ca0106_i2c_write(chip, ADC_MUX, ADC_MUX_LINEIN); /* Enable Line-in capture. MIC in currently untested. */ | 1467 | /* Enable Line-in capture. MIC in currently untested. */ |
1468 | /* snd_ca0106_i2c_write(chip, ADC_MUX, ADC_MUX_LINEIN); */ | ||
1520 | } | 1469 | } |
1521 | if (chip->details->spi_dac == 1) { /* The SB0570 use SPI to control DAC. */ | 1470 | |
1471 | if (chip->details->spi_dac == 1) { | ||
1472 | /* The SB0570 use SPI to control DAC. */ | ||
1522 | int size, n; | 1473 | int size, n; |
1523 | 1474 | ||
1524 | size = ARRAY_SIZE(spi_dac_init); | 1475 | size = ARRAY_SIZE(spi_dac_init); |
@@ -1530,9 +1481,112 @@ static int __devinit snd_ca0106_create(int dev, struct snd_card *card, | |||
1530 | chip->spi_dac_reg[reg] = spi_dac_init[n]; | 1481 | chip->spi_dac_reg[reg] = spi_dac_init[n]; |
1531 | } | 1482 | } |
1532 | } | 1483 | } |
1484 | } | ||
1485 | |||
1486 | static void ca0106_stop_chip(struct snd_ca0106 *chip) | ||
1487 | { | ||
1488 | /* disable interrupts */ | ||
1489 | snd_ca0106_ptr_write(chip, BASIC_INTERRUPT, 0, 0); | ||
1490 | outl(0, chip->port + INTE); | ||
1491 | snd_ca0106_ptr_write(chip, EXTENDED_INT_MASK, 0, 0); | ||
1492 | udelay(1000); | ||
1493 | /* disable audio */ | ||
1494 | /* outl(HCFG_LOCKSOUNDCACHE, chip->port + HCFG); */ | ||
1495 | outl(0, chip->port + HCFG); | ||
1496 | /* FIXME: We need to stop and DMA transfers here. | ||
1497 | * But as I am not sure how yet, we cannot from the dma pages. | ||
1498 | * So we can fix: snd-malloc: Memory leak? pages not freed = 8 | ||
1499 | */ | ||
1500 | } | ||
1533 | 1501 | ||
1534 | if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, | 1502 | static int __devinit snd_ca0106_create(int dev, struct snd_card *card, |
1535 | chip, &ops)) < 0) { | 1503 | struct pci_dev *pci, |
1504 | struct snd_ca0106 **rchip) | ||
1505 | { | ||
1506 | struct snd_ca0106 *chip; | ||
1507 | struct snd_ca0106_details *c; | ||
1508 | int err; | ||
1509 | static struct snd_device_ops ops = { | ||
1510 | .dev_free = snd_ca0106_dev_free, | ||
1511 | }; | ||
1512 | |||
1513 | *rchip = NULL; | ||
1514 | |||
1515 | err = pci_enable_device(pci); | ||
1516 | if (err < 0) | ||
1517 | return err; | ||
1518 | if (pci_set_dma_mask(pci, DMA_32BIT_MASK) < 0 || | ||
1519 | pci_set_consistent_dma_mask(pci, DMA_32BIT_MASK) < 0) { | ||
1520 | printk(KERN_ERR "error to set 32bit mask DMA\n"); | ||
1521 | pci_disable_device(pci); | ||
1522 | return -ENXIO; | ||
1523 | } | ||
1524 | |||
1525 | chip = kzalloc(sizeof(*chip), GFP_KERNEL); | ||
1526 | if (chip == NULL) { | ||
1527 | pci_disable_device(pci); | ||
1528 | return -ENOMEM; | ||
1529 | } | ||
1530 | |||
1531 | chip->card = card; | ||
1532 | chip->pci = pci; | ||
1533 | chip->irq = -1; | ||
1534 | |||
1535 | spin_lock_init(&chip->emu_lock); | ||
1536 | |||
1537 | chip->port = pci_resource_start(pci, 0); | ||
1538 | chip->res_port = request_region(chip->port, 0x20, "snd_ca0106"); | ||
1539 | if (!chip->res_port) { | ||
1540 | snd_ca0106_free(chip); | ||
1541 | printk(KERN_ERR "cannot allocate the port\n"); | ||
1542 | return -EBUSY; | ||
1543 | } | ||
1544 | |||
1545 | if (request_irq(pci->irq, snd_ca0106_interrupt, | ||
1546 | IRQF_SHARED, "snd_ca0106", chip)) { | ||
1547 | snd_ca0106_free(chip); | ||
1548 | printk(KERN_ERR "cannot grab irq\n"); | ||
1549 | return -EBUSY; | ||
1550 | } | ||
1551 | chip->irq = pci->irq; | ||
1552 | |||
1553 | /* This stores the periods table. */ | ||
1554 | if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(pci), | ||
1555 | 1024, &chip->buffer) < 0) { | ||
1556 | snd_ca0106_free(chip); | ||
1557 | return -ENOMEM; | ||
1558 | } | ||
1559 | |||
1560 | pci_set_master(pci); | ||
1561 | /* read serial */ | ||
1562 | pci_read_config_dword(pci, PCI_SUBSYSTEM_VENDOR_ID, &chip->serial); | ||
1563 | pci_read_config_word(pci, PCI_SUBSYSTEM_ID, &chip->model); | ||
1564 | printk(KERN_INFO "snd-ca0106: Model %04x Rev %08x Serial %08x\n", | ||
1565 | chip->model, pci->revision, chip->serial); | ||
1566 | strcpy(card->driver, "CA0106"); | ||
1567 | strcpy(card->shortname, "CA0106"); | ||
1568 | |||
1569 | for (c = ca0106_chip_details; c->serial; c++) { | ||
1570 | if (subsystem[dev]) { | ||
1571 | if (c->serial == subsystem[dev]) | ||
1572 | break; | ||
1573 | } else if (c->serial == chip->serial) | ||
1574 | break; | ||
1575 | } | ||
1576 | chip->details = c; | ||
1577 | if (subsystem[dev]) { | ||
1578 | printk(KERN_INFO "snd-ca0106: Sound card name=%s, " | ||
1579 | "subsystem=0x%x. Forced to subsystem=0x%x\n", | ||
1580 | c->name, chip->serial, subsystem[dev]); | ||
1581 | } | ||
1582 | |||
1583 | sprintf(card->longname, "%s at 0x%lx irq %i", | ||
1584 | c->name, chip->port, chip->irq); | ||
1585 | |||
1586 | ca0106_init_chip(chip); | ||
1587 | |||
1588 | err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops); | ||
1589 | if (err < 0) { | ||
1536 | snd_ca0106_free(chip); | 1590 | snd_ca0106_free(chip); |
1537 | return err; | 1591 | return err; |
1538 | } | 1592 | } |
@@ -1629,7 +1683,7 @@ static int __devinit snd_ca0106_probe(struct pci_dev *pci, | |||
1629 | static int dev; | 1683 | static int dev; |
1630 | struct snd_card *card; | 1684 | struct snd_card *card; |
1631 | struct snd_ca0106 *chip; | 1685 | struct snd_ca0106 *chip; |
1632 | int err; | 1686 | int i, err; |
1633 | 1687 | ||
1634 | if (dev >= SNDRV_CARDS) | 1688 | if (dev >= SNDRV_CARDS) |
1635 | return -ENODEV; | 1689 | return -ENODEV; |
@@ -1642,44 +1696,30 @@ static int __devinit snd_ca0106_probe(struct pci_dev *pci, | |||
1642 | if (card == NULL) | 1696 | if (card == NULL) |
1643 | return -ENOMEM; | 1697 | return -ENOMEM; |
1644 | 1698 | ||
1645 | if ((err = snd_ca0106_create(dev, card, pci, &chip)) < 0) { | 1699 | err = snd_ca0106_create(dev, card, pci, &chip); |
1646 | snd_card_free(card); | 1700 | if (err < 0) |
1647 | return err; | 1701 | goto error; |
1648 | } | ||
1649 | 1702 | ||
1650 | if ((err = snd_ca0106_pcm(chip, 0, NULL)) < 0) { | 1703 | for (i = 0; i < 4; i++) { |
1651 | snd_card_free(card); | 1704 | err = snd_ca0106_pcm(chip, i); |
1652 | return err; | 1705 | if (err < 0) |
1653 | } | 1706 | goto error; |
1654 | if ((err = snd_ca0106_pcm(chip, 1, NULL)) < 0) { | ||
1655 | snd_card_free(card); | ||
1656 | return err; | ||
1657 | } | ||
1658 | if ((err = snd_ca0106_pcm(chip, 2, NULL)) < 0) { | ||
1659 | snd_card_free(card); | ||
1660 | return err; | ||
1661 | } | ||
1662 | if ((err = snd_ca0106_pcm(chip, 3, NULL)) < 0) { | ||
1663 | snd_card_free(card); | ||
1664 | return err; | ||
1665 | } | ||
1666 | if (chip->details->ac97 == 1) { /* The SB0410 and SB0413 do not have an AC97 chip. */ | ||
1667 | if ((err = snd_ca0106_ac97(chip)) < 0) { | ||
1668 | snd_card_free(card); | ||
1669 | return err; | ||
1670 | } | ||
1671 | } | 1707 | } |
1672 | if ((err = snd_ca0106_mixer(chip)) < 0) { | 1708 | |
1673 | snd_card_free(card); | 1709 | if (chip->details->ac97 == 1) { |
1674 | return err; | 1710 | /* The SB0410 and SB0413 do not have an AC97 chip. */ |
1711 | err = snd_ca0106_ac97(chip); | ||
1712 | if (err < 0) | ||
1713 | goto error; | ||
1675 | } | 1714 | } |
1715 | err = snd_ca0106_mixer(chip); | ||
1716 | if (err < 0) | ||
1717 | goto error; | ||
1676 | 1718 | ||
1677 | snd_printdd("ca0106: probe for MIDI channel A ..."); | 1719 | snd_printdd("ca0106: probe for MIDI channel A ..."); |
1678 | if ((err = snd_ca0106_midi(chip,CA0106_MIDI_CHAN_A)) < 0) { | 1720 | err = snd_ca0106_midi(chip, CA0106_MIDI_CHAN_A); |
1679 | snd_card_free(card); | 1721 | if (err < 0) |
1680 | snd_printdd(" failed, err=0x%x\n",err); | 1722 | goto error; |
1681 | return err; | ||
1682 | } | ||
1683 | snd_printdd(" done.\n"); | 1723 | snd_printdd(" done.\n"); |
1684 | 1724 | ||
1685 | #ifdef CONFIG_PROC_FS | 1725 | #ifdef CONFIG_PROC_FS |
@@ -1688,14 +1728,17 @@ static int __devinit snd_ca0106_probe(struct pci_dev *pci, | |||
1688 | 1728 | ||
1689 | snd_card_set_dev(card, &pci->dev); | 1729 | snd_card_set_dev(card, &pci->dev); |
1690 | 1730 | ||
1691 | if ((err = snd_card_register(card)) < 0) { | 1731 | err = snd_card_register(card); |
1692 | snd_card_free(card); | 1732 | if (err < 0) |
1693 | return err; | 1733 | goto error; |
1694 | } | ||
1695 | 1734 | ||
1696 | pci_set_drvdata(pci, card); | 1735 | pci_set_drvdata(pci, card); |
1697 | dev++; | 1736 | dev++; |
1698 | return 0; | 1737 | return 0; |
1738 | |||
1739 | error: | ||
1740 | snd_card_free(card); | ||
1741 | return err; | ||
1699 | } | 1742 | } |
1700 | 1743 | ||
1701 | static void __devexit snd_ca0106_remove(struct pci_dev *pci) | 1744 | static void __devexit snd_ca0106_remove(struct pci_dev *pci) |
@@ -1704,6 +1747,52 @@ static void __devexit snd_ca0106_remove(struct pci_dev *pci) | |||
1704 | pci_set_drvdata(pci, NULL); | 1747 | pci_set_drvdata(pci, NULL); |
1705 | } | 1748 | } |
1706 | 1749 | ||
1750 | #ifdef CONFIG_PM | ||
1751 | static int snd_ca0106_suspend(struct pci_dev *pci, pm_message_t state) | ||
1752 | { | ||
1753 | struct snd_card *card = pci_get_drvdata(pci); | ||
1754 | struct snd_ca0106 *chip = card->private_data; | ||
1755 | int i; | ||
1756 | |||
1757 | snd_power_change_state(card, SNDRV_CTL_POWER_D3hot); | ||
1758 | for (i = 0; i < 4; i++) | ||
1759 | snd_pcm_suspend_all(chip->pcm[i]); | ||
1760 | snd_ac97_suspend(chip->ac97); | ||
1761 | snd_ca0106_mixer_suspend(chip); | ||
1762 | |||
1763 | ca0106_stop_chip(chip); | ||
1764 | |||
1765 | pci_disable_device(pci); | ||
1766 | pci_save_state(pci); | ||
1767 | pci_set_power_state(pci, pci_choose_state(pci, state)); | ||
1768 | return 0; | ||
1769 | } | ||
1770 | |||
1771 | static int snd_ca0106_resume(struct pci_dev *pci) | ||
1772 | { | ||
1773 | struct snd_card *card = pci_get_drvdata(pci); | ||
1774 | struct snd_ca0106 *chip = card->private_data; | ||
1775 | int i; | ||
1776 | |||
1777 | pci_set_power_state(pci, PCI_D0); | ||
1778 | pci_restore_state(pci); | ||
1779 | pci_enable_device(pci); | ||
1780 | pci_set_master(pci); | ||
1781 | |||
1782 | ca0106_init_chip(chip); | ||
1783 | |||
1784 | snd_ac97_resume(chip->ac97); | ||
1785 | snd_ca0106_mixer_resume(chip); | ||
1786 | if (chip->details->spi_dac) { | ||
1787 | for (i = 0; i < ARRAY_SIZE(chip->spi_dac_reg); i++) | ||
1788 | snd_ca0106_spi_write(chip, chip->spi_dac_reg[i]); | ||
1789 | } | ||
1790 | |||
1791 | snd_power_change_state(card, SNDRV_CTL_POWER_D0); | ||
1792 | return 0; | ||
1793 | } | ||
1794 | #endif | ||
1795 | |||
1707 | // PCI IDs | 1796 | // PCI IDs |
1708 | static struct pci_device_id snd_ca0106_ids[] = { | 1797 | static struct pci_device_id snd_ca0106_ids[] = { |
1709 | { 0x1102, 0x0007, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, /* Audigy LS or Live 24bit */ | 1798 | { 0x1102, 0x0007, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, /* Audigy LS or Live 24bit */ |
@@ -1717,6 +1806,10 @@ static struct pci_driver driver = { | |||
1717 | .id_table = snd_ca0106_ids, | 1806 | .id_table = snd_ca0106_ids, |
1718 | .probe = snd_ca0106_probe, | 1807 | .probe = snd_ca0106_probe, |
1719 | .remove = __devexit_p(snd_ca0106_remove), | 1808 | .remove = __devexit_p(snd_ca0106_remove), |
1809 | #ifdef CONFIG_PM | ||
1810 | .suspend = snd_ca0106_suspend, | ||
1811 | .resume = snd_ca0106_resume, | ||
1812 | #endif | ||
1720 | }; | 1813 | }; |
1721 | 1814 | ||
1722 | // initialization of the module | 1815 | // initialization of the module |
diff --git a/sound/pci/ca0106/ca0106_mixer.c b/sound/pci/ca0106/ca0106_mixer.c index 3025ed1b6e1e..cccc32cdb943 100644 --- a/sound/pci/ca0106/ca0106_mixer.c +++ b/sound/pci/ca0106/ca0106_mixer.c | |||
@@ -75,6 +75,84 @@ | |||
75 | 75 | ||
76 | #include "ca0106.h" | 76 | #include "ca0106.h" |
77 | 77 | ||
78 | static void ca0106_spdif_enable(struct snd_ca0106 *emu) | ||
79 | { | ||
80 | unsigned int val; | ||
81 | |||
82 | if (emu->spdif_enable) { | ||
83 | /* Digital */ | ||
84 | snd_ca0106_ptr_write(emu, SPDIF_SELECT1, 0, 0xf); | ||
85 | snd_ca0106_ptr_write(emu, SPDIF_SELECT2, 0, 0x0b000000); | ||
86 | val = snd_ca0106_ptr_read(emu, CAPTURE_CONTROL, 0) & ~0x1000; | ||
87 | snd_ca0106_ptr_write(emu, CAPTURE_CONTROL, 0, val); | ||
88 | val = inl(emu->port + GPIO) & ~0x101; | ||
89 | outl(val, emu->port + GPIO); | ||
90 | |||
91 | } else { | ||
92 | /* Analog */ | ||
93 | snd_ca0106_ptr_write(emu, SPDIF_SELECT1, 0, 0xf); | ||
94 | snd_ca0106_ptr_write(emu, SPDIF_SELECT2, 0, 0x000f0000); | ||
95 | val = snd_ca0106_ptr_read(emu, CAPTURE_CONTROL, 0) | 0x1000; | ||
96 | snd_ca0106_ptr_write(emu, CAPTURE_CONTROL, 0, val); | ||
97 | val = inl(emu->port + GPIO) | 0x101; | ||
98 | outl(val, emu->port + GPIO); | ||
99 | } | ||
100 | } | ||
101 | |||
102 | static void ca0106_set_capture_source(struct snd_ca0106 *emu) | ||
103 | { | ||
104 | unsigned int val = emu->capture_source; | ||
105 | unsigned int source, mask; | ||
106 | source = (val << 28) | (val << 24) | (val << 20) | (val << 16); | ||
107 | mask = snd_ca0106_ptr_read(emu, CAPTURE_SOURCE, 0) & 0xffff; | ||
108 | snd_ca0106_ptr_write(emu, CAPTURE_SOURCE, 0, source | mask); | ||
109 | } | ||
110 | |||
111 | static void ca0106_set_i2c_capture_source(struct snd_ca0106 *emu, | ||
112 | unsigned int val, int force) | ||
113 | { | ||
114 | unsigned int ngain, ogain; | ||
115 | u32 source; | ||
116 | |||
117 | snd_ca0106_i2c_write(emu, ADC_MUX, 0); /* Mute input */ | ||
118 | ngain = emu->i2c_capture_volume[val][0]; /* Left */ | ||
119 | ogain = emu->i2c_capture_volume[emu->i2c_capture_source][0]; /* Left */ | ||
120 | if (force || ngain != ogain) | ||
121 | snd_ca0106_i2c_write(emu, ADC_ATTEN_ADCL, ngain & 0xff); | ||
122 | ngain = emu->i2c_capture_volume[val][1]; /* Right */ | ||
123 | ogain = emu->i2c_capture_volume[emu->i2c_capture_source][1]; /* Right */ | ||
124 | if (force || ngain != ogain) | ||
125 | snd_ca0106_i2c_write(emu, ADC_ATTEN_ADCR, ngain & 0xff); | ||
126 | source = 1 << val; | ||
127 | snd_ca0106_i2c_write(emu, ADC_MUX, source); /* Set source */ | ||
128 | emu->i2c_capture_source = val; | ||
129 | } | ||
130 | |||
131 | static void ca0106_set_capture_mic_line_in(struct snd_ca0106 *emu) | ||
132 | { | ||
133 | u32 tmp; | ||
134 | |||
135 | if (emu->capture_mic_line_in) { | ||
136 | /* snd_ca0106_i2c_write(emu, ADC_MUX, 0); */ /* Mute input */ | ||
137 | tmp = inl(emu->port+GPIO) & ~0x400; | ||
138 | tmp = tmp | 0x400; | ||
139 | outl(tmp, emu->port+GPIO); | ||
140 | /* snd_ca0106_i2c_write(emu, ADC_MUX, ADC_MUX_MIC); */ | ||
141 | } else { | ||
142 | /* snd_ca0106_i2c_write(emu, ADC_MUX, 0); */ /* Mute input */ | ||
143 | tmp = inl(emu->port+GPIO) & ~0x400; | ||
144 | outl(tmp, emu->port+GPIO); | ||
145 | /* snd_ca0106_i2c_write(emu, ADC_MUX, ADC_MUX_LINEIN); */ | ||
146 | } | ||
147 | } | ||
148 | |||
149 | static void ca0106_set_spdif_bits(struct snd_ca0106 *emu, int idx) | ||
150 | { | ||
151 | snd_ca0106_ptr_write(emu, SPCS0 + idx, 0, emu->spdif_bits[idx]); | ||
152 | } | ||
153 | |||
154 | /* | ||
155 | */ | ||
78 | static const DECLARE_TLV_DB_SCALE(snd_ca0106_db_scale1, -5175, 25, 1); | 156 | static const DECLARE_TLV_DB_SCALE(snd_ca0106_db_scale1, -5175, 25, 1); |
79 | static const DECLARE_TLV_DB_SCALE(snd_ca0106_db_scale2, -10350, 50, 1); | 157 | static const DECLARE_TLV_DB_SCALE(snd_ca0106_db_scale2, -10350, 50, 1); |
80 | 158 | ||
@@ -95,30 +173,12 @@ static int snd_ca0106_shared_spdif_put(struct snd_kcontrol *kcontrol, | |||
95 | struct snd_ca0106 *emu = snd_kcontrol_chip(kcontrol); | 173 | struct snd_ca0106 *emu = snd_kcontrol_chip(kcontrol); |
96 | unsigned int val; | 174 | unsigned int val; |
97 | int change = 0; | 175 | int change = 0; |
98 | u32 mask; | ||
99 | 176 | ||
100 | val = !!ucontrol->value.integer.value[0]; | 177 | val = !!ucontrol->value.integer.value[0]; |
101 | change = (emu->spdif_enable != val); | 178 | change = (emu->spdif_enable != val); |
102 | if (change) { | 179 | if (change) { |
103 | emu->spdif_enable = val; | 180 | emu->spdif_enable = val; |
104 | if (val) { | 181 | ca0106_spdif_enable(emu); |
105 | /* Digital */ | ||
106 | snd_ca0106_ptr_write(emu, SPDIF_SELECT1, 0, 0xf); | ||
107 | snd_ca0106_ptr_write(emu, SPDIF_SELECT2, 0, 0x0b000000); | ||
108 | snd_ca0106_ptr_write(emu, CAPTURE_CONTROL, 0, | ||
109 | snd_ca0106_ptr_read(emu, CAPTURE_CONTROL, 0) & ~0x1000); | ||
110 | mask = inl(emu->port + GPIO) & ~0x101; | ||
111 | outl(mask, emu->port + GPIO); | ||
112 | |||
113 | } else { | ||
114 | /* Analog */ | ||
115 | snd_ca0106_ptr_write(emu, SPDIF_SELECT1, 0, 0xf); | ||
116 | snd_ca0106_ptr_write(emu, SPDIF_SELECT2, 0, 0x000f0000); | ||
117 | snd_ca0106_ptr_write(emu, CAPTURE_CONTROL, 0, | ||
118 | snd_ca0106_ptr_read(emu, CAPTURE_CONTROL, 0) | 0x1000); | ||
119 | mask = inl(emu->port + GPIO) | 0x101; | ||
120 | outl(mask, emu->port + GPIO); | ||
121 | } | ||
122 | } | 182 | } |
123 | return change; | 183 | return change; |
124 | } | 184 | } |
@@ -154,8 +214,6 @@ static int snd_ca0106_capture_source_put(struct snd_kcontrol *kcontrol, | |||
154 | struct snd_ca0106 *emu = snd_kcontrol_chip(kcontrol); | 214 | struct snd_ca0106 *emu = snd_kcontrol_chip(kcontrol); |
155 | unsigned int val; | 215 | unsigned int val; |
156 | int change = 0; | 216 | int change = 0; |
157 | u32 mask; | ||
158 | u32 source; | ||
159 | 217 | ||
160 | val = ucontrol->value.enumerated.item[0] ; | 218 | val = ucontrol->value.enumerated.item[0] ; |
161 | if (val >= 6) | 219 | if (val >= 6) |
@@ -163,9 +221,7 @@ static int snd_ca0106_capture_source_put(struct snd_kcontrol *kcontrol, | |||
163 | change = (emu->capture_source != val); | 221 | change = (emu->capture_source != val); |
164 | if (change) { | 222 | if (change) { |
165 | emu->capture_source = val; | 223 | emu->capture_source = val; |
166 | source = (val << 28) | (val << 24) | (val << 20) | (val << 16); | 224 | ca0106_set_capture_source(emu); |
167 | mask = snd_ca0106_ptr_read(emu, CAPTURE_SOURCE, 0) & 0xffff; | ||
168 | snd_ca0106_ptr_write(emu, CAPTURE_SOURCE, 0, source | mask); | ||
169 | } | 225 | } |
170 | return change; | 226 | return change; |
171 | } | 227 | } |
@@ -200,9 +256,7 @@ static int snd_ca0106_i2c_capture_source_put(struct snd_kcontrol *kcontrol, | |||
200 | { | 256 | { |
201 | struct snd_ca0106 *emu = snd_kcontrol_chip(kcontrol); | 257 | struct snd_ca0106 *emu = snd_kcontrol_chip(kcontrol); |
202 | unsigned int source_id; | 258 | unsigned int source_id; |
203 | unsigned int ngain, ogain; | ||
204 | int change = 0; | 259 | int change = 0; |
205 | u32 source; | ||
206 | /* If the capture source has changed, | 260 | /* If the capture source has changed, |
207 | * update the capture volume from the cached value | 261 | * update the capture volume from the cached value |
208 | * for the particular source. | 262 | * for the particular source. |
@@ -212,18 +266,7 @@ static int snd_ca0106_i2c_capture_source_put(struct snd_kcontrol *kcontrol, | |||
212 | return -EINVAL; | 266 | return -EINVAL; |
213 | change = (emu->i2c_capture_source != source_id); | 267 | change = (emu->i2c_capture_source != source_id); |
214 | if (change) { | 268 | if (change) { |
215 | snd_ca0106_i2c_write(emu, ADC_MUX, 0); /* Mute input */ | 269 | ca0106_set_i2c_capture_source(emu, source_id, 0); |
216 | ngain = emu->i2c_capture_volume[source_id][0]; /* Left */ | ||
217 | ogain = emu->i2c_capture_volume[emu->i2c_capture_source][0]; /* Left */ | ||
218 | if (ngain != ogain) | ||
219 | snd_ca0106_i2c_write(emu, ADC_ATTEN_ADCL, ((ngain) & 0xff)); | ||
220 | ngain = emu->i2c_capture_volume[source_id][1]; /* Left */ | ||
221 | ogain = emu->i2c_capture_volume[emu->i2c_capture_source][1]; /* Left */ | ||
222 | if (ngain != ogain) | ||
223 | snd_ca0106_i2c_write(emu, ADC_ATTEN_ADCR, ((ngain) & 0xff)); | ||
224 | source = 1 << source_id; | ||
225 | snd_ca0106_i2c_write(emu, ADC_MUX, source); /* Set source */ | ||
226 | emu->i2c_capture_source = source_id; | ||
227 | } | 270 | } |
228 | return change; | 271 | return change; |
229 | } | 272 | } |
@@ -271,7 +314,6 @@ static int snd_ca0106_capture_mic_line_in_put(struct snd_kcontrol *kcontrol, | |||
271 | struct snd_ca0106 *emu = snd_kcontrol_chip(kcontrol); | 314 | struct snd_ca0106 *emu = snd_kcontrol_chip(kcontrol); |
272 | unsigned int val; | 315 | unsigned int val; |
273 | int change = 0; | 316 | int change = 0; |
274 | u32 tmp; | ||
275 | 317 | ||
276 | val = ucontrol->value.enumerated.item[0] ; | 318 | val = ucontrol->value.enumerated.item[0] ; |
277 | if (val > 1) | 319 | if (val > 1) |
@@ -279,18 +321,7 @@ static int snd_ca0106_capture_mic_line_in_put(struct snd_kcontrol *kcontrol, | |||
279 | change = (emu->capture_mic_line_in != val); | 321 | change = (emu->capture_mic_line_in != val); |
280 | if (change) { | 322 | if (change) { |
281 | emu->capture_mic_line_in = val; | 323 | emu->capture_mic_line_in = val; |
282 | if (val) { | 324 | ca0106_set_capture_mic_line_in(emu); |
283 | //snd_ca0106_i2c_write(emu, ADC_MUX, 0); /* Mute input */ | ||
284 | tmp = inl(emu->port+GPIO) & ~0x400; | ||
285 | tmp = tmp | 0x400; | ||
286 | outl(tmp, emu->port+GPIO); | ||
287 | //snd_ca0106_i2c_write(emu, ADC_MUX, ADC_MUX_MIC); | ||
288 | } else { | ||
289 | //snd_ca0106_i2c_write(emu, ADC_MUX, 0); /* Mute input */ | ||
290 | tmp = inl(emu->port+GPIO) & ~0x400; | ||
291 | outl(tmp, emu->port+GPIO); | ||
292 | //snd_ca0106_i2c_write(emu, ADC_MUX, ADC_MUX_LINEIN); | ||
293 | } | ||
294 | } | 325 | } |
295 | return change; | 326 | return change; |
296 | } | 327 | } |
@@ -359,8 +390,8 @@ static int snd_ca0106_spdif_put(struct snd_kcontrol *kcontrol, | |||
359 | (ucontrol->value.iec958.status[3] << 24); | 390 | (ucontrol->value.iec958.status[3] << 24); |
360 | change = val != emu->spdif_bits[idx]; | 391 | change = val != emu->spdif_bits[idx]; |
361 | if (change) { | 392 | if (change) { |
362 | snd_ca0106_ptr_write(emu, SPCS0 + idx, 0, val); | ||
363 | emu->spdif_bits[idx] = val; | 393 | emu->spdif_bits[idx] = val; |
394 | ca0106_set_spdif_bits(emu, idx); | ||
364 | } | 395 | } |
365 | return change; | 396 | return change; |
366 | } | 397 | } |
@@ -773,3 +804,50 @@ int __devinit snd_ca0106_mixer(struct snd_ca0106 *emu) | |||
773 | return 0; | 804 | return 0; |
774 | } | 805 | } |
775 | 806 | ||
807 | #ifdef CONFIG_PM | ||
808 | struct ca0106_vol_tbl { | ||
809 | unsigned int reg; | ||
810 | unsigned int channel_id; | ||
811 | }; | ||
812 | |||
813 | static struct ca0106_vol_tbl saved_volumes[NUM_SAVED_VOLUMES] = { | ||
814 | { CONTROL_FRONT_CHANNEL, PLAYBACK_VOLUME2 }, | ||
815 | { CONTROL_REAR_CHANNEL, PLAYBACK_VOLUME2 }, | ||
816 | { CONTROL_CENTER_LFE_CHANNEL, PLAYBACK_VOLUME2 }, | ||
817 | { CONTROL_UNKNOWN_CHANNEL, PLAYBACK_VOLUME2 }, | ||
818 | { CONTROL_FRONT_CHANNEL, PLAYBACK_VOLUME1 }, | ||
819 | { CONTROL_REAR_CHANNEL, PLAYBACK_VOLUME1 }, | ||
820 | { CONTROL_CENTER_LFE_CHANNEL, PLAYBACK_VOLUME1 }, | ||
821 | { CONTROL_UNKNOWN_CHANNEL, PLAYBACK_VOLUME1 }, | ||
822 | { 1, CAPTURE_CONTROL }, | ||
823 | }; | ||
824 | |||
825 | void snd_ca0106_mixer_suspend(struct snd_ca0106 *chip) | ||
826 | { | ||
827 | int i; | ||
828 | |||
829 | /* save volumes */ | ||
830 | for (i = 0; i < NUM_SAVED_VOLUMES; i++) | ||
831 | chip->saved_vol[i] = | ||
832 | snd_ca0106_ptr_read(chip, saved_volumes[i].reg, | ||
833 | saved_volumes[i].channel_id); | ||
834 | } | ||
835 | |||
836 | void snd_ca0106_mixer_resume(struct snd_ca0106 *chip) | ||
837 | { | ||
838 | int i; | ||
839 | |||
840 | for (i = 0; i < NUM_SAVED_VOLUMES; i++) | ||
841 | snd_ca0106_ptr_write(chip, saved_volumes[i].reg, | ||
842 | saved_volumes[i].channel_id, | ||
843 | chip->saved_vol[i]); | ||
844 | |||
845 | ca0106_spdif_enable(chip); | ||
846 | ca0106_set_capture_source(chip); | ||
847 | ca0106_set_i2c_capture_source(chip, chip->i2c_capture_source, 1); | ||
848 | for (i = 0; i < 4; i++) | ||
849 | ca0106_set_spdif_bits(chip, i); | ||
850 | if (chip->details->i2c_adc) | ||
851 | ca0106_set_capture_mic_line_in(chip); | ||
852 | } | ||
853 | #endif /* CONFIG_PM */ | ||