aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--sound/pci/ca0106/ca0106.h15
-rw-r--r--sound/pci/ca0106/ca0106_main.c528
-rw-r--r--sound/pci/ca0106/ca0106_mixer.c182
3 files changed, 456 insertions, 269 deletions
diff --git a/sound/pci/ca0106/ca0106.h b/sound/pci/ca0106/ca0106.h
index 3faccb6ecad9..a6943cb0d209 100644
--- a/sound/pci/ca0106/ca0106.h
+++ b/sound/pci/ca0106/ca0106.h
@@ -690,7 +690,7 @@ struct snd_ca0106 {
690 spinlock_t emu_lock; 690 spinlock_t emu_lock;
691 691
692 struct snd_ac97 *ac97; 692 struct snd_ac97 *ac97;
693 struct snd_pcm *pcm; 693 struct snd_pcm *pcm[4];
694 694
695 struct snd_ca0106_channel playback_channels[4]; 695 struct snd_ca0106_channel playback_channels[4];
696 struct snd_ca0106_channel capture_channels[4]; 696 struct snd_ca0106_channel capture_channels[4];
@@ -707,6 +707,11 @@ struct snd_ca0106 {
707 struct snd_ca_midi midi2; 707 struct snd_ca_midi midi2;
708 708
709 u16 spi_dac_reg[16]; 709 u16 spi_dac_reg[16];
710
711#ifdef CONFIG_PM
712#define NUM_SAVED_VOLUMES 9
713 unsigned int saved_vol[NUM_SAVED_VOLUMES];
714#endif
710}; 715};
711 716
712int snd_ca0106_mixer(struct snd_ca0106 *emu); 717int snd_ca0106_mixer(struct snd_ca0106 *emu);
@@ -725,3 +730,11 @@ int snd_ca0106_i2c_write(struct snd_ca0106 *emu, u32 reg, u32 value);
725 730
726int snd_ca0106_spi_write(struct snd_ca0106 * emu, 731int snd_ca0106_spi_write(struct snd_ca0106 * emu,
727 unsigned int data); 732 unsigned int data);
733
734#ifdef CONFIG_PM
735void snd_ca0106_mixer_suspend(struct snd_ca0106 *chip);
736void snd_ca0106_mixer_resume(struct snd_ca0106 *chip);
737#else
738#define snd_ca0106_mixer_suspend(chip) do { } while (0)
739#define snd_ca0106_mixer_resume(chip) do { } while (0)
740#endif
diff --git a/sound/pci/ca0106/ca0106_main.c b/sound/pci/ca0106/ca0106_main.c
index 507abf3d09a6..3e6dda37ef21 100644
--- a/sound/pci/ca0106/ca0106_main.c
+++ b/sound/pci/ca0106/ca0106_main.c
@@ -853,15 +853,18 @@ static int snd_ca0106_pcm_trigger_playback(struct snd_pcm_substream *substream,
853 struct snd_pcm_substream *s; 853 struct snd_pcm_substream *s;
854 u32 basic = 0; 854 u32 basic = 0;
855 u32 extended = 0; 855 u32 extended = 0;
856 int running=0; 856 u32 bits;
857 int running = 0;
857 858
858 switch (cmd) { 859 switch (cmd) {
859 case SNDRV_PCM_TRIGGER_START: 860 case SNDRV_PCM_TRIGGER_START:
860 running=1; 861 case SNDRV_PCM_TRIGGER_RESUME:
862 running = 1;
861 break; 863 break;
862 case SNDRV_PCM_TRIGGER_STOP: 864 case SNDRV_PCM_TRIGGER_STOP:
865 case SNDRV_PCM_TRIGGER_SUSPEND:
863 default: 866 default:
864 running=0; 867 running = 0;
865 break; 868 break;
866 } 869 }
867 snd_pcm_group_for_each_entry(s, substream) { 870 snd_pcm_group_for_each_entry(s, substream) {
@@ -871,22 +874,32 @@ static int snd_ca0106_pcm_trigger_playback(struct snd_pcm_substream *substream,
871 runtime = s->runtime; 874 runtime = s->runtime;
872 epcm = runtime->private_data; 875 epcm = runtime->private_data;
873 channel = epcm->channel_id; 876 channel = epcm->channel_id;
874 //snd_printk("channel=%d\n",channel); 877 /* snd_printk("channel=%d\n",channel); */
875 epcm->running = running; 878 epcm->running = running;
876 basic |= (0x1<<channel); 879 basic |= (0x1 << channel);
877 extended |= (0x10<<channel); 880 extended |= (0x10 << channel);
878 snd_pcm_trigger_done(s, substream); 881 snd_pcm_trigger_done(s, substream);
879 } 882 }
880 //snd_printk("basic=0x%x, extended=0x%x\n",basic, extended); 883 /* snd_printk("basic=0x%x, extended=0x%x\n",basic, extended); */
881 884
882 switch (cmd) { 885 switch (cmd) {
883 case SNDRV_PCM_TRIGGER_START: 886 case SNDRV_PCM_TRIGGER_START:
884 snd_ca0106_ptr_write(emu, EXTENDED_INT_MASK, 0, snd_ca0106_ptr_read(emu, EXTENDED_INT_MASK, 0) | (extended)); 887 case SNDRV_PCM_TRIGGER_RESUME:
885 snd_ca0106_ptr_write(emu, BASIC_INTERRUPT, 0, snd_ca0106_ptr_read(emu, BASIC_INTERRUPT, 0)|(basic)); 888 bits = snd_ca0106_ptr_read(emu, EXTENDED_INT_MASK, 0);
889 bits |= extended;
890 snd_ca0106_ptr_write(emu, EXTENDED_INT_MASK, 0, bits);
891 bits = snd_ca0106_ptr_read(emu, BASIC_INTERRUPT, 0);
892 bits |= basic;
893 snd_ca0106_ptr_write(emu, BASIC_INTERRUPT, 0, bits);
886 break; 894 break;
887 case SNDRV_PCM_TRIGGER_STOP: 895 case SNDRV_PCM_TRIGGER_STOP:
888 snd_ca0106_ptr_write(emu, BASIC_INTERRUPT, 0, snd_ca0106_ptr_read(emu, BASIC_INTERRUPT, 0) & ~(basic)); 896 case SNDRV_PCM_TRIGGER_SUSPEND:
889 snd_ca0106_ptr_write(emu, EXTENDED_INT_MASK, 0, snd_ca0106_ptr_read(emu, EXTENDED_INT_MASK, 0) & ~(extended)); 897 bits = snd_ca0106_ptr_read(emu, BASIC_INTERRUPT, 0);
898 bits &= ~basic;
899 snd_ca0106_ptr_write(emu, BASIC_INTERRUPT, 0, bits);
900 bits = snd_ca0106_ptr_read(emu, EXTENDED_INT_MASK, 0);
901 bits &= ~extended;
902 snd_ca0106_ptr_write(emu, EXTENDED_INT_MASK, 0, bits);
890 break; 903 break;
891 default: 904 default:
892 result = -EINVAL; 905 result = -EINVAL;
@@ -1109,21 +1122,13 @@ static int snd_ca0106_ac97(struct snd_ca0106 *chip)
1109 return snd_ac97_mixer(pbus, &ac97, &chip->ac97); 1122 return snd_ac97_mixer(pbus, &ac97, &chip->ac97);
1110} 1123}
1111 1124
1125static void ca0106_stop_chip(struct snd_ca0106 *chip);
1126
1112static int snd_ca0106_free(struct snd_ca0106 *chip) 1127static int snd_ca0106_free(struct snd_ca0106 *chip)
1113{ 1128{
1114 if (chip->res_port != NULL) { /* avoid access to already used hardware */ 1129 if (chip->res_port != NULL) {
1115 // disable interrupts 1130 /* avoid access to already used hardware */
1116 snd_ca0106_ptr_write(chip, BASIC_INTERRUPT, 0, 0); 1131 ca0106_stop_chip(chip);
1117 outl(0, chip->port + INTE);
1118 snd_ca0106_ptr_write(chip, EXTENDED_INT_MASK, 0, 0);
1119 udelay(1000);
1120 // disable audio
1121 //outl(HCFG_LOCKSOUNDCACHE, chip->port + HCFG);
1122 outl(0, chip->port + HCFG);
1123 /* FIXME: We need to stop and DMA transfers here.
1124 * But as I am not sure how yet, we cannot from the dma pages.
1125 * So we can fix: snd-malloc: Memory leak? pages not freed = 8
1126 */
1127 } 1132 }
1128 if (chip->irq >= 0) 1133 if (chip->irq >= 0)
1129 free_irq(chip->irq, chip); 1134 free_irq(chip->irq, chip);
@@ -1209,15 +1214,14 @@ static irqreturn_t snd_ca0106_interrupt(int irq, void *dev_id)
1209 return IRQ_HANDLED; 1214 return IRQ_HANDLED;
1210} 1215}
1211 1216
1212static int __devinit snd_ca0106_pcm(struct snd_ca0106 *emu, int device, struct snd_pcm **rpcm) 1217static int __devinit snd_ca0106_pcm(struct snd_ca0106 *emu, int device)
1213{ 1218{
1214 struct snd_pcm *pcm; 1219 struct snd_pcm *pcm;
1215 struct snd_pcm_substream *substream; 1220 struct snd_pcm_substream *substream;
1216 int err; 1221 int err;
1217 1222
1218 if (rpcm) 1223 err = snd_pcm_new(emu->card, "ca0106", device, 1, 1, &pcm);
1219 *rpcm = NULL; 1224 if (err < 0)
1220 if ((err = snd_pcm_new(emu->card, "ca0106", device, 1, 1, &pcm)) < 0)
1221 return err; 1225 return err;
1222 1226
1223 pcm->private_data = emu; 1227 pcm->private_data = emu;
@@ -1244,7 +1248,6 @@ static int __devinit snd_ca0106_pcm(struct snd_ca0106 *emu, int device, struct s
1244 pcm->info_flags = 0; 1248 pcm->info_flags = 0;
1245 pcm->dev_subclass = SNDRV_PCM_SUBCLASS_GENERIC_MIX; 1249 pcm->dev_subclass = SNDRV_PCM_SUBCLASS_GENERIC_MIX;
1246 strcpy(pcm->name, "CA0106"); 1250 strcpy(pcm->name, "CA0106");
1247 emu->pcm = pcm;
1248 1251
1249 for(substream = pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream; 1252 for(substream = pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream;
1250 substream; 1253 substream;
@@ -1266,8 +1269,7 @@ static int __devinit snd_ca0106_pcm(struct snd_ca0106 *emu, int device, struct s
1266 return err; 1269 return err;
1267 } 1270 }
1268 1271
1269 if (rpcm) 1272 emu->pcm[device] = pcm;
1270 *rpcm = pcm;
1271 1273
1272 return 0; 1274 return 0;
1273} 1275}
@@ -1307,89 +1309,10 @@ static unsigned int i2c_adc_init[][2] = {
1307 { 0x15, ADC_MUX_LINEIN }, /* ADC Mixer control */ 1309 { 0x15, ADC_MUX_LINEIN }, /* ADC Mixer control */
1308}; 1310};
1309 1311
1310static int __devinit snd_ca0106_create(int dev, struct snd_card *card, 1312static void ca0106_init_chip(struct snd_ca0106 *chip, int resume)
1311 struct pci_dev *pci,
1312 struct snd_ca0106 **rchip)
1313{ 1313{
1314 struct snd_ca0106 *chip;
1315 struct snd_ca0106_details *c;
1316 int err;
1317 int ch; 1314 int ch;
1318 static struct snd_device_ops ops = { 1315 unsigned int def_bits;
1319 .dev_free = snd_ca0106_dev_free,
1320 };
1321
1322 *rchip = NULL;
1323
1324 if ((err = pci_enable_device(pci)) < 0)
1325 return err;
1326 if (pci_set_dma_mask(pci, DMA_32BIT_MASK) < 0 ||
1327 pci_set_consistent_dma_mask(pci, DMA_32BIT_MASK) < 0) {
1328 printk(KERN_ERR "error to set 32bit mask DMA\n");
1329 pci_disable_device(pci);
1330 return -ENXIO;
1331 }
1332
1333 chip = kzalloc(sizeof(*chip), GFP_KERNEL);
1334 if (chip == NULL) {
1335 pci_disable_device(pci);
1336 return -ENOMEM;
1337 }
1338
1339 chip->card = card;
1340 chip->pci = pci;
1341 chip->irq = -1;
1342
1343 spin_lock_init(&chip->emu_lock);
1344
1345 chip->port = pci_resource_start(pci, 0);
1346 if ((chip->res_port = request_region(chip->port, 0x20,
1347 "snd_ca0106")) == NULL) {
1348 snd_ca0106_free(chip);
1349 printk(KERN_ERR "cannot allocate the port\n");
1350 return -EBUSY;
1351 }
1352
1353 if (request_irq(pci->irq, snd_ca0106_interrupt,
1354 IRQF_SHARED, "snd_ca0106", chip)) {
1355 snd_ca0106_free(chip);
1356 printk(KERN_ERR "cannot grab irq\n");
1357 return -EBUSY;
1358 }
1359 chip->irq = pci->irq;
1360
1361 /* This stores the periods table. */
1362 if(snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(pci), 1024, &chip->buffer) < 0) {
1363 snd_ca0106_free(chip);
1364 return -ENOMEM;
1365 }
1366
1367 pci_set_master(pci);
1368 /* read serial */
1369 pci_read_config_dword(pci, PCI_SUBSYSTEM_VENDOR_ID, &chip->serial);
1370 pci_read_config_word(pci, PCI_SUBSYSTEM_ID, &chip->model);
1371#if 1
1372 printk(KERN_INFO "snd-ca0106: Model %04x Rev %08x Serial %08x\n", chip->model,
1373 pci->revision, chip->serial);
1374#endif
1375 strcpy(card->driver, "CA0106");
1376 strcpy(card->shortname, "CA0106");
1377
1378 for (c = ca0106_chip_details; c->serial; c++) {
1379 if (subsystem[dev]) {
1380 if (c->serial == subsystem[dev])
1381 break;
1382 } else if (c->serial == chip->serial)
1383 break;
1384 }
1385 chip->details = c;
1386 if (subsystem[dev]) {
1387 printk(KERN_INFO "snd-ca0106: Sound card name=%s, subsystem=0x%x. Forced to subsystem=0x%x\n",
1388 c->name, chip->serial, subsystem[dev]);
1389 }
1390
1391 sprintf(card->longname, "%s at 0x%lx irq %i",
1392 c->name, chip->port, chip->irq);
1393 1316
1394 outl(0, chip->port + INTE); 1317 outl(0, chip->port + INTE);
1395 1318
@@ -1407,31 +1330,22 @@ static int __devinit snd_ca0106_create(int dev, struct snd_card *card,
1407 * AN = 0 (Audio data) 1330 * AN = 0 (Audio data)
1408 * P = 0 (Consumer) 1331 * P = 0 (Consumer)
1409 */ 1332 */
1410 snd_ca0106_ptr_write(chip, SPCS0, 0, 1333 def_bits =
1411 chip->spdif_bits[0] = 1334 SPCS_CLKACCY_1000PPM | SPCS_SAMPLERATE_48 |
1412 SPCS_CLKACCY_1000PPM | SPCS_SAMPLERATE_48 | 1335 SPCS_CHANNELNUM_LEFT | SPCS_SOURCENUM_UNSPEC |
1413 SPCS_CHANNELNUM_LEFT | SPCS_SOURCENUM_UNSPEC | 1336 SPCS_GENERATIONSTATUS | 0x00001200 |
1414 SPCS_GENERATIONSTATUS | 0x00001200 | 1337 0x00000000 | SPCS_EMPHASIS_NONE | SPCS_COPYRIGHT;
1415 0x00000000 | SPCS_EMPHASIS_NONE | SPCS_COPYRIGHT); 1338 if (!resume) {
1339 chip->spdif_bits[0] = def_bits;
1340 chip->spdif_bits[1] = def_bits;
1341 chip->spdif_bits[2] = def_bits;
1342 chip->spdif_bits[3] = def_bits;
1343 }
1416 /* Only SPCS1 has been tested */ 1344 /* Only SPCS1 has been tested */
1417 snd_ca0106_ptr_write(chip, SPCS1, 0, 1345 snd_ca0106_ptr_write(chip, SPCS1, 0, chip->spdif_bits[1]);
1418 chip->spdif_bits[1] = 1346 snd_ca0106_ptr_write(chip, SPCS0, 0, chip->spdif_bits[0]);
1419 SPCS_CLKACCY_1000PPM | SPCS_SAMPLERATE_48 | 1347 snd_ca0106_ptr_write(chip, SPCS2, 0, chip->spdif_bits[2]);
1420 SPCS_CHANNELNUM_LEFT | SPCS_SOURCENUM_UNSPEC | 1348 snd_ca0106_ptr_write(chip, SPCS3, 0, chip->spdif_bits[3]);
1421 SPCS_GENERATIONSTATUS | 0x00001200 |
1422 0x00000000 | SPCS_EMPHASIS_NONE | SPCS_COPYRIGHT);
1423 snd_ca0106_ptr_write(chip, SPCS2, 0,
1424 chip->spdif_bits[2] =
1425 SPCS_CLKACCY_1000PPM | SPCS_SAMPLERATE_48 |
1426 SPCS_CHANNELNUM_LEFT | SPCS_SOURCENUM_UNSPEC |
1427 SPCS_GENERATIONSTATUS | 0x00001200 |
1428 0x00000000 | SPCS_EMPHASIS_NONE | SPCS_COPYRIGHT);
1429 snd_ca0106_ptr_write(chip, SPCS3, 0,
1430 chip->spdif_bits[3] =
1431 SPCS_CLKACCY_1000PPM | SPCS_SAMPLERATE_48 |
1432 SPCS_CHANNELNUM_LEFT | SPCS_SOURCENUM_UNSPEC |
1433 SPCS_GENERATIONSTATUS | 0x00001200 |
1434 0x00000000 | SPCS_EMPHASIS_NONE | SPCS_COPYRIGHT);
1435 1349
1436 snd_ca0106_ptr_write(chip, PLAYBACK_MUTE, 0, 0x00fc0000); 1350 snd_ca0106_ptr_write(chip, PLAYBACK_MUTE, 0, 0x00fc0000);
1437 snd_ca0106_ptr_write(chip, CAPTURE_MUTE, 0, 0x00fc0000); 1351 snd_ca0106_ptr_write(chip, CAPTURE_MUTE, 0, 0x00fc0000);
@@ -1439,92 +1353,124 @@ static int __devinit snd_ca0106_create(int dev, struct snd_card *card,
1439 /* Write 0x8000 to AC97_REC_GAIN to mute it. */ 1353 /* Write 0x8000 to AC97_REC_GAIN to mute it. */
1440 outb(AC97_REC_GAIN, chip->port + AC97ADDRESS); 1354 outb(AC97_REC_GAIN, chip->port + AC97ADDRESS);
1441 outw(0x8000, chip->port + AC97DATA); 1355 outw(0x8000, chip->port + AC97DATA);
1442#if 0 1356#if 0 /* FIXME: what are these? */
1443 snd_ca0106_ptr_write(chip, SPCS0, 0, 0x2108006); 1357 snd_ca0106_ptr_write(chip, SPCS0, 0, 0x2108006);
1444 snd_ca0106_ptr_write(chip, 0x42, 0, 0x2108006); 1358 snd_ca0106_ptr_write(chip, 0x42, 0, 0x2108006);
1445 snd_ca0106_ptr_write(chip, 0x43, 0, 0x2108006); 1359 snd_ca0106_ptr_write(chip, 0x43, 0, 0x2108006);
1446 snd_ca0106_ptr_write(chip, 0x44, 0, 0x2108006); 1360 snd_ca0106_ptr_write(chip, 0x44, 0, 0x2108006);
1447#endif 1361#endif
1448 1362
1449 //snd_ca0106_ptr_write(chip, SPDIF_SELECT2, 0, 0xf0f003f); /* OSS drivers set this. */ 1363 /* OSS drivers set this. */
1364 /* snd_ca0106_ptr_write(chip, SPDIF_SELECT2, 0, 0xf0f003f); */
1365
1450 /* Analog or Digital output */ 1366 /* Analog or Digital output */
1451 snd_ca0106_ptr_write(chip, SPDIF_SELECT1, 0, 0xf); 1367 snd_ca0106_ptr_write(chip, SPDIF_SELECT1, 0, 0xf);
1452 snd_ca0106_ptr_write(chip, SPDIF_SELECT2, 0, 0x000f0000); /* 0x0b000000 for digital, 0x000b0000 for analog, from win2000 drivers. Use 0x000f0000 for surround71 */ 1368 /* 0x0b000000 for digital, 0x000b0000 for analog, from win2000 drivers.
1369 * Use 0x000f0000 for surround71
1370 */
1371 snd_ca0106_ptr_write(chip, SPDIF_SELECT2, 0, 0x000f0000);
1372
1453 chip->spdif_enable = 0; /* Set digital SPDIF output off */ 1373 chip->spdif_enable = 0; /* Set digital SPDIF output off */
1454 //snd_ca0106_ptr_write(chip, 0x45, 0, 0); /* Analogue out */ 1374 /*snd_ca0106_ptr_write(chip, 0x45, 0, 0);*/ /* Analogue out */
1455 //snd_ca0106_ptr_write(chip, 0x45, 0, 0xf00); /* Digital out */ 1375 /*snd_ca0106_ptr_write(chip, 0x45, 0, 0xf00);*/ /* Digital out */
1376
1377 /* goes to 0x40c80000 when doing SPDIF IN/OUT */
1378 snd_ca0106_ptr_write(chip, CAPTURE_CONTROL, 0, 0x40c81000);
1379 /* (Mute) CAPTURE feedback into PLAYBACK volume.
1380 * Only lower 16 bits matter.
1381 */
1382 snd_ca0106_ptr_write(chip, CAPTURE_CONTROL, 1, 0xffffffff);
1383 /* SPDIF IN Volume */
1384 snd_ca0106_ptr_write(chip, CAPTURE_CONTROL, 2, 0x30300000);
1385 /* SPDIF IN Volume, 0x70 = (vol & 0x3f) | 0x40 */
1386 snd_ca0106_ptr_write(chip, CAPTURE_CONTROL, 3, 0x00700000);
1456 1387
1457 snd_ca0106_ptr_write(chip, CAPTURE_CONTROL, 0, 0x40c81000); /* goes to 0x40c80000 when doing SPDIF IN/OUT */
1458 snd_ca0106_ptr_write(chip, CAPTURE_CONTROL, 1, 0xffffffff); /* (Mute) CAPTURE feedback into PLAYBACK volume. Only lower 16 bits matter. */
1459 snd_ca0106_ptr_write(chip, CAPTURE_CONTROL, 2, 0x30300000); /* SPDIF IN Volume */
1460 snd_ca0106_ptr_write(chip, CAPTURE_CONTROL, 3, 0x00700000); /* SPDIF IN Volume, 0x70 = (vol & 0x3f) | 0x40 */
1461 snd_ca0106_ptr_write(chip, PLAYBACK_ROUTING1, 0, 0x32765410); 1388 snd_ca0106_ptr_write(chip, PLAYBACK_ROUTING1, 0, 0x32765410);
1462 snd_ca0106_ptr_write(chip, PLAYBACK_ROUTING2, 0, 0x76767676); 1389 snd_ca0106_ptr_write(chip, PLAYBACK_ROUTING2, 0, 0x76767676);
1463 snd_ca0106_ptr_write(chip, CAPTURE_ROUTING1, 0, 0x32765410); 1390 snd_ca0106_ptr_write(chip, CAPTURE_ROUTING1, 0, 0x32765410);
1464 snd_ca0106_ptr_write(chip, CAPTURE_ROUTING2, 0, 0x76767676); 1391 snd_ca0106_ptr_write(chip, CAPTURE_ROUTING2, 0, 0x76767676);
1465 for(ch = 0; ch < 4; ch++) { 1392
1466 snd_ca0106_ptr_write(chip, CAPTURE_VOLUME1, ch, 0x30303030); /* Only high 16 bits matter */ 1393 for (ch = 0; ch < 4; ch++) {
1394 /* Only high 16 bits matter */
1395 snd_ca0106_ptr_write(chip, CAPTURE_VOLUME1, ch, 0x30303030);
1467 snd_ca0106_ptr_write(chip, CAPTURE_VOLUME2, ch, 0x30303030); 1396 snd_ca0106_ptr_write(chip, CAPTURE_VOLUME2, ch, 0x30303030);
1468 //snd_ca0106_ptr_write(chip, PLAYBACK_VOLUME1, ch, 0x40404040); /* Mute */ 1397#if 0 /* Mute */
1469 //snd_ca0106_ptr_write(chip, PLAYBACK_VOLUME2, ch, 0x40404040); /* Mute */ 1398 snd_ca0106_ptr_write(chip, PLAYBACK_VOLUME1, ch, 0x40404040);
1470 snd_ca0106_ptr_write(chip, PLAYBACK_VOLUME1, ch, 0xffffffff); /* Mute */ 1399 snd_ca0106_ptr_write(chip, PLAYBACK_VOLUME2, ch, 0x40404040);
1471 snd_ca0106_ptr_write(chip, PLAYBACK_VOLUME2, ch, 0xffffffff); /* Mute */ 1400 snd_ca0106_ptr_write(chip, PLAYBACK_VOLUME1, ch, 0xffffffff);
1401 snd_ca0106_ptr_write(chip, PLAYBACK_VOLUME2, ch, 0xffffffff);
1402#endif
1472 } 1403 }
1473 if (chip->details->i2c_adc == 1) { 1404 if (chip->details->i2c_adc == 1) {
1474 /* Select MIC, Line in, TAD in, AUX in */ 1405 /* Select MIC, Line in, TAD in, AUX in */
1475 snd_ca0106_ptr_write(chip, CAPTURE_SOURCE, 0x0, 0x333300e4); 1406 snd_ca0106_ptr_write(chip, CAPTURE_SOURCE, 0x0, 0x333300e4);
1476 /* Default to CAPTURE_SOURCE to i2s in */ 1407 /* Default to CAPTURE_SOURCE to i2s in */
1477 chip->capture_source = 3; 1408 if (!resume)
1409 chip->capture_source = 3;
1478 } else if (chip->details->ac97 == 1) { 1410 } else if (chip->details->ac97 == 1) {
1479 /* Default to AC97 in */ 1411 /* Default to AC97 in */
1480 snd_ca0106_ptr_write(chip, CAPTURE_SOURCE, 0x0, 0x444400e4); 1412 snd_ca0106_ptr_write(chip, CAPTURE_SOURCE, 0x0, 0x444400e4);
1481 /* Default to CAPTURE_SOURCE to AC97 in */ 1413 /* Default to CAPTURE_SOURCE to AC97 in */
1482 chip->capture_source = 4; 1414 if (!resume)
1415 chip->capture_source = 4;
1483 } else { 1416 } else {
1484 /* Select MIC, Line in, TAD in, AUX in */ 1417 /* Select MIC, Line in, TAD in, AUX in */
1485 snd_ca0106_ptr_write(chip, CAPTURE_SOURCE, 0x0, 0x333300e4); 1418 snd_ca0106_ptr_write(chip, CAPTURE_SOURCE, 0x0, 0x333300e4);
1486 /* Default to Set CAPTURE_SOURCE to i2s in */ 1419 /* Default to Set CAPTURE_SOURCE to i2s in */
1487 chip->capture_source = 3; 1420 if (!resume)
1421 chip->capture_source = 3;
1488 } 1422 }
1489 1423
1490 if (chip->details->gpio_type == 2) { /* The SB0438 use GPIO differently. */ 1424 if (chip->details->gpio_type == 2) {
1491 /* FIXME: Still need to find out what the other GPIO bits do. E.g. For digital spdif out. */ 1425 /* The SB0438 use GPIO differently. */
1426 /* FIXME: Still need to find out what the other GPIO bits do.
1427 * E.g. For digital spdif out.
1428 */
1492 outl(0x0, chip->port+GPIO); 1429 outl(0x0, chip->port+GPIO);
1493 //outl(0x00f0e000, chip->port+GPIO); /* Analog */ 1430 /* outl(0x00f0e000, chip->port+GPIO); */ /* Analog */
1494 outl(0x005f5301, chip->port+GPIO); /* Analog */ 1431 outl(0x005f5301, chip->port+GPIO); /* Analog */
1495 } else if (chip->details->gpio_type == 1) { /* The SB0410 and SB0413 use GPIO differently. */ 1432 } else if (chip->details->gpio_type == 1) {
1496 /* FIXME: Still need to find out what the other GPIO bits do. E.g. For digital spdif out. */ 1433 /* The SB0410 and SB0413 use GPIO differently. */
1434 /* FIXME: Still need to find out what the other GPIO bits do.
1435 * E.g. For digital spdif out.
1436 */
1497 outl(0x0, chip->port+GPIO); 1437 outl(0x0, chip->port+GPIO);
1498 //outl(0x00f0e000, chip->port+GPIO); /* Analog */ 1438 /* outl(0x00f0e000, chip->port+GPIO); */ /* Analog */
1499 outl(0x005f5301, chip->port+GPIO); /* Analog */ 1439 outl(0x005f5301, chip->port+GPIO); /* Analog */
1500 } else { 1440 } else {
1501 outl(0x0, chip->port+GPIO); 1441 outl(0x0, chip->port+GPIO);
1502 outl(0x005f03a3, chip->port+GPIO); /* Analog */ 1442 outl(0x005f03a3, chip->port+GPIO); /* Analog */
1503 //outl(0x005f02a2, chip->port+GPIO); /* SPDIF */ 1443 /* outl(0x005f02a2, chip->port+GPIO); */ /* SPDIF */
1504 } 1444 }
1505 snd_ca0106_intr_enable(chip, 0x105); /* Win2000 uses 0x1e0 */ 1445 snd_ca0106_intr_enable(chip, 0x105); /* Win2000 uses 0x1e0 */
1506 1446
1507 //outl(HCFG_LOCKSOUNDCACHE|HCFG_AUDIOENABLE, chip->port+HCFG); 1447 /* outl(HCFG_LOCKSOUNDCACHE|HCFG_AUDIOENABLE, chip->port+HCFG); */
1508 //outl(0x00001409, chip->port+HCFG); /* 0x1000 causes AC3 to fails. Maybe it effects 24 bit output. */ 1448 /* 0x1000 causes AC3 to fails. Maybe it effects 24 bit output. */
1509 //outl(0x00000009, chip->port+HCFG); 1449 /* outl(0x00001409, chip->port+HCFG); */
1510 outl(HCFG_AC97 | HCFG_AUDIOENABLE, chip->port+HCFG); /* AC97 2.0, Enable outputs. */ 1450 /* outl(0x00000009, chip->port+HCFG); */
1451 /* AC97 2.0, Enable outputs. */
1452 outl(HCFG_AC97 | HCFG_AUDIOENABLE, chip->port+HCFG);
1511 1453
1512 if (chip->details->i2c_adc == 1) { /* The SB0410 and SB0413 use I2C to control ADC. */ 1454 if (chip->details->i2c_adc == 1) {
1455 /* The SB0410 and SB0413 use I2C to control ADC. */
1513 int size, n; 1456 int size, n;
1514 1457
1515 size = ARRAY_SIZE(i2c_adc_init); 1458 size = ARRAY_SIZE(i2c_adc_init);
1516 //snd_printk("I2C:array size=0x%x\n", size); 1459 /* snd_printk("I2C:array size=0x%x\n", size); */
1517 for (n=0; n < size; n++) { 1460 for (n = 0; n < size; n++)
1518 snd_ca0106_i2c_write(chip, i2c_adc_init[n][0], i2c_adc_init[n][1]); 1461 snd_ca0106_i2c_write(chip, i2c_adc_init[n][0],
1519 } 1462 i2c_adc_init[n][1]);
1520 for (n=0; n < 4; n++) { 1463 for (n = 0; n < 4; n++) {
1521 chip->i2c_capture_volume[n][0]= 0xcf; 1464 chip->i2c_capture_volume[n][0] = 0xcf;
1522 chip->i2c_capture_volume[n][1]= 0xcf; 1465 chip->i2c_capture_volume[n][1] = 0xcf;
1523 } 1466 }
1524 chip->i2c_capture_source=2; /* Line in */ 1467 chip->i2c_capture_source = 2; /* Line in */
1525 //snd_ca0106_i2c_write(chip, ADC_MUX, ADC_MUX_LINEIN); /* Enable Line-in capture. MIC in currently untested. */ 1468 /* Enable Line-in capture. MIC in currently untested. */
1469 /* snd_ca0106_i2c_write(chip, ADC_MUX, ADC_MUX_LINEIN); */
1526 } 1470 }
1527 if (chip->details->spi_dac == 1) { /* The SB0570 use SPI to control DAC. */ 1471
1472 if (chip->details->spi_dac == 1) {
1473 /* The SB0570 use SPI to control DAC. */
1528 int size, n; 1474 int size, n;
1529 1475
1530 size = ARRAY_SIZE(spi_dac_init); 1476 size = ARRAY_SIZE(spi_dac_init);
@@ -1536,9 +1482,112 @@ static int __devinit snd_ca0106_create(int dev, struct snd_card *card,
1536 chip->spi_dac_reg[reg] = spi_dac_init[n]; 1482 chip->spi_dac_reg[reg] = spi_dac_init[n];
1537 } 1483 }
1538 } 1484 }
1485}
1486
1487static void ca0106_stop_chip(struct snd_ca0106 *chip)
1488{
1489 /* disable interrupts */
1490 snd_ca0106_ptr_write(chip, BASIC_INTERRUPT, 0, 0);
1491 outl(0, chip->port + INTE);
1492 snd_ca0106_ptr_write(chip, EXTENDED_INT_MASK, 0, 0);
1493 udelay(1000);
1494 /* disable audio */
1495 /* outl(HCFG_LOCKSOUNDCACHE, chip->port + HCFG); */
1496 outl(0, chip->port + HCFG);
1497 /* FIXME: We need to stop and DMA transfers here.
1498 * But as I am not sure how yet, we cannot from the dma pages.
1499 * So we can fix: snd-malloc: Memory leak? pages not freed = 8
1500 */
1501}
1502
1503static int __devinit snd_ca0106_create(int dev, struct snd_card *card,
1504 struct pci_dev *pci,
1505 struct snd_ca0106 **rchip)
1506{
1507 struct snd_ca0106 *chip;
1508 struct snd_ca0106_details *c;
1509 int err;
1510 static struct snd_device_ops ops = {
1511 .dev_free = snd_ca0106_dev_free,
1512 };
1513
1514 *rchip = NULL;
1539 1515
1540 if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, 1516 err = pci_enable_device(pci);
1541 chip, &ops)) < 0) { 1517 if (err < 0)
1518 return err;
1519 if (pci_set_dma_mask(pci, DMA_32BIT_MASK) < 0 ||
1520 pci_set_consistent_dma_mask(pci, DMA_32BIT_MASK) < 0) {
1521 printk(KERN_ERR "error to set 32bit mask DMA\n");
1522 pci_disable_device(pci);
1523 return -ENXIO;
1524 }
1525
1526 chip = kzalloc(sizeof(*chip), GFP_KERNEL);
1527 if (chip == NULL) {
1528 pci_disable_device(pci);
1529 return -ENOMEM;
1530 }
1531
1532 chip->card = card;
1533 chip->pci = pci;
1534 chip->irq = -1;
1535
1536 spin_lock_init(&chip->emu_lock);
1537
1538 chip->port = pci_resource_start(pci, 0);
1539 chip->res_port = request_region(chip->port, 0x20, "snd_ca0106");
1540 if (!chip->res_port) {
1541 snd_ca0106_free(chip);
1542 printk(KERN_ERR "cannot allocate the port\n");
1543 return -EBUSY;
1544 }
1545
1546 if (request_irq(pci->irq, snd_ca0106_interrupt,
1547 IRQF_SHARED, "snd_ca0106", chip)) {
1548 snd_ca0106_free(chip);
1549 printk(KERN_ERR "cannot grab irq\n");
1550 return -EBUSY;
1551 }
1552 chip->irq = pci->irq;
1553
1554 /* This stores the periods table. */
1555 if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(pci),
1556 1024, &chip->buffer) < 0) {
1557 snd_ca0106_free(chip);
1558 return -ENOMEM;
1559 }
1560
1561 pci_set_master(pci);
1562 /* read serial */
1563 pci_read_config_dword(pci, PCI_SUBSYSTEM_VENDOR_ID, &chip->serial);
1564 pci_read_config_word(pci, PCI_SUBSYSTEM_ID, &chip->model);
1565 printk(KERN_INFO "snd-ca0106: Model %04x Rev %08x Serial %08x\n",
1566 chip->model, pci->revision, chip->serial);
1567 strcpy(card->driver, "CA0106");
1568 strcpy(card->shortname, "CA0106");
1569
1570 for (c = ca0106_chip_details; c->serial; c++) {
1571 if (subsystem[dev]) {
1572 if (c->serial == subsystem[dev])
1573 break;
1574 } else if (c->serial == chip->serial)
1575 break;
1576 }
1577 chip->details = c;
1578 if (subsystem[dev]) {
1579 printk(KERN_INFO "snd-ca0106: Sound card name=%s, "
1580 "subsystem=0x%x. Forced to subsystem=0x%x\n",
1581 c->name, chip->serial, subsystem[dev]);
1582 }
1583
1584 sprintf(card->longname, "%s at 0x%lx irq %i",
1585 c->name, chip->port, chip->irq);
1586
1587 ca0106_init_chip(chip, 0);
1588
1589 err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops);
1590 if (err < 0) {
1542 snd_ca0106_free(chip); 1591 snd_ca0106_free(chip);
1543 return err; 1592 return err;
1544 } 1593 }
@@ -1635,7 +1684,7 @@ static int __devinit snd_ca0106_probe(struct pci_dev *pci,
1635 static int dev; 1684 static int dev;
1636 struct snd_card *card; 1685 struct snd_card *card;
1637 struct snd_ca0106 *chip; 1686 struct snd_ca0106 *chip;
1638 int err; 1687 int i, err;
1639 1688
1640 if (dev >= SNDRV_CARDS) 1689 if (dev >= SNDRV_CARDS)
1641 return -ENODEV; 1690 return -ENODEV;
@@ -1648,44 +1697,31 @@ static int __devinit snd_ca0106_probe(struct pci_dev *pci,
1648 if (card == NULL) 1697 if (card == NULL)
1649 return -ENOMEM; 1698 return -ENOMEM;
1650 1699
1651 if ((err = snd_ca0106_create(dev, card, pci, &chip)) < 0) { 1700 err = snd_ca0106_create(dev, card, pci, &chip);
1652 snd_card_free(card); 1701 if (err < 0)
1653 return err; 1702 goto error;
1654 } 1703 card->private_data = chip;
1655 1704
1656 if ((err = snd_ca0106_pcm(chip, 0, NULL)) < 0) { 1705 for (i = 0; i < 4; i++) {
1657 snd_card_free(card); 1706 err = snd_ca0106_pcm(chip, i);
1658 return err; 1707 if (err < 0)
1659 } 1708 goto error;
1660 if ((err = snd_ca0106_pcm(chip, 1, NULL)) < 0) {
1661 snd_card_free(card);
1662 return err;
1663 }
1664 if ((err = snd_ca0106_pcm(chip, 2, NULL)) < 0) {
1665 snd_card_free(card);
1666 return err;
1667 }
1668 if ((err = snd_ca0106_pcm(chip, 3, NULL)) < 0) {
1669 snd_card_free(card);
1670 return err;
1671 }
1672 if (chip->details->ac97 == 1) { /* The SB0410 and SB0413 do not have an AC97 chip. */
1673 if ((err = snd_ca0106_ac97(chip)) < 0) {
1674 snd_card_free(card);
1675 return err;
1676 }
1677 } 1709 }
1678 if ((err = snd_ca0106_mixer(chip)) < 0) { 1710
1679 snd_card_free(card); 1711 if (chip->details->ac97 == 1) {
1680 return err; 1712 /* The SB0410 and SB0413 do not have an AC97 chip. */
1713 err = snd_ca0106_ac97(chip);
1714 if (err < 0)
1715 goto error;
1681 } 1716 }
1717 err = snd_ca0106_mixer(chip);
1718 if (err < 0)
1719 goto error;
1682 1720
1683 snd_printdd("ca0106: probe for MIDI channel A ..."); 1721 snd_printdd("ca0106: probe for MIDI channel A ...");
1684 if ((err = snd_ca0106_midi(chip,CA0106_MIDI_CHAN_A)) < 0) { 1722 err = snd_ca0106_midi(chip, CA0106_MIDI_CHAN_A);
1685 snd_card_free(card); 1723 if (err < 0)
1686 snd_printdd(" failed, err=0x%x\n",err); 1724 goto error;
1687 return err;
1688 }
1689 snd_printdd(" done.\n"); 1725 snd_printdd(" done.\n");
1690 1726
1691#ifdef CONFIG_PROC_FS 1727#ifdef CONFIG_PROC_FS
@@ -1694,14 +1730,17 @@ static int __devinit snd_ca0106_probe(struct pci_dev *pci,
1694 1730
1695 snd_card_set_dev(card, &pci->dev); 1731 snd_card_set_dev(card, &pci->dev);
1696 1732
1697 if ((err = snd_card_register(card)) < 0) { 1733 err = snd_card_register(card);
1698 snd_card_free(card); 1734 if (err < 0)
1699 return err; 1735 goto error;
1700 }
1701 1736
1702 pci_set_drvdata(pci, card); 1737 pci_set_drvdata(pci, card);
1703 dev++; 1738 dev++;
1704 return 0; 1739 return 0;
1740
1741 error:
1742 snd_card_free(card);
1743 return err;
1705} 1744}
1706 1745
1707static void __devexit snd_ca0106_remove(struct pci_dev *pci) 1746static void __devexit snd_ca0106_remove(struct pci_dev *pci)
@@ -1710,6 +1749,59 @@ static void __devexit snd_ca0106_remove(struct pci_dev *pci)
1710 pci_set_drvdata(pci, NULL); 1749 pci_set_drvdata(pci, NULL);
1711} 1750}
1712 1751
1752#ifdef CONFIG_PM
1753static int snd_ca0106_suspend(struct pci_dev *pci, pm_message_t state)
1754{
1755 struct snd_card *card = pci_get_drvdata(pci);
1756 struct snd_ca0106 *chip = card->private_data;
1757 int i;
1758
1759 snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
1760 for (i = 0; i < 4; i++)
1761 snd_pcm_suspend_all(chip->pcm[i]);
1762 if (chip->details->ac97)
1763 snd_ac97_suspend(chip->ac97);
1764 snd_ca0106_mixer_suspend(chip);
1765
1766 ca0106_stop_chip(chip);
1767
1768 pci_disable_device(pci);
1769 pci_save_state(pci);
1770 pci_set_power_state(pci, pci_choose_state(pci, state));
1771 return 0;
1772}
1773
1774static int snd_ca0106_resume(struct pci_dev *pci)
1775{
1776 struct snd_card *card = pci_get_drvdata(pci);
1777 struct snd_ca0106 *chip = card->private_data;
1778 int i;
1779
1780 pci_set_power_state(pci, PCI_D0);
1781 pci_restore_state(pci);
1782
1783 if (pci_enable_device(pci) < 0) {
1784 snd_card_disconnect(card);
1785 return -EIO;
1786 }
1787
1788 pci_set_master(pci);
1789
1790 ca0106_init_chip(chip, 1);
1791
1792 if (chip->details->ac97)
1793 snd_ac97_resume(chip->ac97);
1794 snd_ca0106_mixer_resume(chip);
1795 if (chip->details->spi_dac) {
1796 for (i = 0; i < ARRAY_SIZE(chip->spi_dac_reg); i++)
1797 snd_ca0106_spi_write(chip, chip->spi_dac_reg[i]);
1798 }
1799
1800 snd_power_change_state(card, SNDRV_CTL_POWER_D0);
1801 return 0;
1802}
1803#endif
1804
1713// PCI IDs 1805// PCI IDs
1714static struct pci_device_id snd_ca0106_ids[] = { 1806static struct pci_device_id snd_ca0106_ids[] = {
1715 { 0x1102, 0x0007, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, /* Audigy LS or Live 24bit */ 1807 { 0x1102, 0x0007, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, /* Audigy LS or Live 24bit */
@@ -1723,6 +1815,10 @@ static struct pci_driver driver = {
1723 .id_table = snd_ca0106_ids, 1815 .id_table = snd_ca0106_ids,
1724 .probe = snd_ca0106_probe, 1816 .probe = snd_ca0106_probe,
1725 .remove = __devexit_p(snd_ca0106_remove), 1817 .remove = __devexit_p(snd_ca0106_remove),
1818#ifdef CONFIG_PM
1819 .suspend = snd_ca0106_suspend,
1820 .resume = snd_ca0106_resume,
1821#endif
1726}; 1822};
1727 1823
1728// initialization of the module 1824// initialization of the module
diff --git a/sound/pci/ca0106/ca0106_mixer.c b/sound/pci/ca0106/ca0106_mixer.c
index 3025ed1b6e1e..9845a20f5427 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
78static 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
102static 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
111static 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
131static 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
149static 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 */
78static const DECLARE_TLV_DB_SCALE(snd_ca0106_db_scale1, -5175, 25, 1); 156static const DECLARE_TLV_DB_SCALE(snd_ca0106_db_scale1, -5175, 25, 1);
79static const DECLARE_TLV_DB_SCALE(snd_ca0106_db_scale2, -10350, 50, 1); 157static 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
808struct ca0106_vol_tbl {
809 unsigned int channel_id;
810 unsigned int reg;
811};
812
813static 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
825void 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
836void 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 */