aboutsummaryrefslogtreecommitdiffstats
path: root/sound/pci/ca0106/ca0106_main.c
diff options
context:
space:
mode:
authorTakashi Iwai <tiwai@suse.de>2008-12-20 17:43:00 -0500
committerTakashi Iwai <tiwai@suse.de>2008-12-20 17:43:00 -0500
commit6bcdbd55b4c603d9741398d081133fcc50a10b6c (patch)
tree335e8d03b134030a748439993bb24d53004032a1 /sound/pci/ca0106/ca0106_main.c
parent6a8436419d1b77b24d82bd90354adc4baa393566 (diff)
parent72077aa336d0f4c5e3c7014d7471c79bc69873bb (diff)
Merge branch 'topic/ca0106-resume' into topic/ca0106
Diffstat (limited to 'sound/pci/ca0106/ca0106_main.c')
-rw-r--r--sound/pci/ca0106/ca0106_main.c528
1 files changed, 312 insertions, 216 deletions
diff --git a/sound/pci/ca0106/ca0106_main.c b/sound/pci/ca0106/ca0106_main.c
index 507abf3d09a..3e6dda37ef2 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