Lines Matching refs:chip
220 void (*enable_dma)(struct atiixp *chip, int on);
222 void (*enable_transfer)(struct atiixp *chip, int on);
224 void (*flush_dma)(struct atiixp *chip);
245 * ATI IXP chip
299 static int snd_atiixp_update_bits(struct atiixp *chip, unsigned int reg,
302 void __iomem *addr = chip->remap_addr + reg;
316 #define atiixp_write(chip,reg,value) \
317 writel(value, chip->remap_addr + ATI_REG_##reg)
318 #define atiixp_read(chip,reg) \
319 readl(chip->remap_addr + ATI_REG_##reg)
320 #define atiixp_update(chip,reg,mask,val) \
321 snd_atiixp_update_bits(chip, ATI_REG_##reg, mask, val)
342 static int atiixp_build_dma_packets(struct atiixp *chip, struct atiixp_dma *dma,
356 &chip->pci->dev,
367 spin_lock_irqsave(&chip->reg_lock, flags);
368 writel(0, chip->remap_addr + dma->ops->llp_offset);
369 dma->ops->enable_dma(chip, 0);
370 dma->ops->enable_dma(chip, 1);
371 spin_unlock_irqrestore(&chip->reg_lock, flags);
391 chip->remap_addr + dma->ops->llp_offset);
402 static void atiixp_clear_dma_packets(struct atiixp *chip, struct atiixp_dma *dma,
406 writel(0, chip->remap_addr + dma->ops->llp_offset);
415 static int snd_atiixp_acquire_codec(struct atiixp *chip)
419 while (atiixp_read(chip, PHYS_OUT_ADDR) & ATI_REG_PHYS_OUT_ADDR_EN) {
421 dev_warn(chip->card->dev, "codec acquire timeout\n");
429 static unsigned short snd_atiixp_codec_read(struct atiixp *chip, unsigned short codec, unsigned short reg)
434 if (snd_atiixp_acquire_codec(chip) < 0)
440 atiixp_write(chip, PHYS_OUT_ADDR, data);
441 if (snd_atiixp_acquire_codec(chip) < 0)
445 data = atiixp_read(chip, PHYS_IN_ADDR);
452 dev_warn(chip->card->dev, "codec read timeout (reg %x)\n", reg);
457 static void snd_atiixp_codec_write(struct atiixp *chip, unsigned short codec,
462 if (snd_atiixp_acquire_codec(chip) < 0)
467 atiixp_write(chip, PHYS_OUT_ADDR, data);
474 struct atiixp *chip = ac97->private_data;
475 return snd_atiixp_codec_read(chip, ac97->num, reg);
482 struct atiixp *chip = ac97->private_data;
483 snd_atiixp_codec_write(chip, ac97->num, reg, val);
489 static int snd_atiixp_aclink_reset(struct atiixp *chip)
494 if (atiixp_update(chip, CMD, ATI_REG_CMD_POWERDOWN, 0))
498 atiixp_update(chip, CMD, ATI_REG_CMD_AC_SOFT_RESET, ATI_REG_CMD_AC_SOFT_RESET);
499 atiixp_read(chip, CMD);
501 atiixp_update(chip, CMD, ATI_REG_CMD_AC_SOFT_RESET, 0);
504 while (! (atiixp_read(chip, CMD) & ATI_REG_CMD_ACLINK_ACTIVE)) {
506 atiixp_update(chip, CMD, ATI_REG_CMD_AC_SYNC|ATI_REG_CMD_AC_RESET,
508 atiixp_read(chip, CMD);
510 atiixp_update(chip, CMD, ATI_REG_CMD_AC_RESET, ATI_REG_CMD_AC_RESET);
512 dev_err(chip->card->dev, "codec reset timeout\n");
518 atiixp_update(chip, CMD, ATI_REG_CMD_AC_SYNC|ATI_REG_CMD_AC_RESET,
525 static int snd_atiixp_aclink_down(struct atiixp *chip)
527 // if (atiixp_read(chip, MODEM_MIRROR) & 0x1) /* modem running, too? */
529 atiixp_update(chip, CMD,
539 * the IXP chip can generate interrupts for the non-existing codecs.
564 static int snd_atiixp_codec_detect(struct atiixp *chip)
568 chip->codec_not_ready_bits = 0;
570 ac97_codec = ac97_probing_bugs(chip->pci);
572 chip->codec_not_ready_bits |=
577 atiixp_write(chip, IER, CODEC_CHECK_BITS);
582 if (chip->codec_not_ready_bits)
585 atiixp_write(chip, IER, 0); /* disable irqs */
587 if ((chip->codec_not_ready_bits & ALL_CODEC_NOT_READY) == ALL_CODEC_NOT_READY) {
588 dev_err(chip->card->dev, "no codec detected!\n");
598 static int snd_atiixp_chip_start(struct atiixp *chip)
603 reg = atiixp_read(chip, CMD);
606 atiixp_write(chip, CMD, reg);
608 reg = atiixp_read(chip, SPDF_CMD);
610 atiixp_write(chip, SPDF_CMD, reg);
613 atiixp_write(chip, ISR, 0xffffffff);
615 atiixp_write(chip, IER,
628 static int snd_atiixp_chip_stop(struct atiixp *chip)
631 atiixp_write(chip, ISR, atiixp_read(chip, ISR));
633 atiixp_write(chip, IER, 0);
649 struct atiixp *chip = snd_pcm_substream_chip(substream);
656 curptr = readl(chip->remap_addr + dma->ops->dt_cur);
664 dev_dbg(chip->card->dev, "invalid DMA pointer read 0x%x (buf=%x)\n",
665 readl(chip->remap_addr + dma->ops->dt_cur), dma->buf_addr);
672 static void snd_atiixp_xrun_dma(struct atiixp *chip, struct atiixp_dma *dma)
676 dev_dbg(chip->card->dev, "XRUN detected (DMA %d)\n", dma->ops->type);
683 static void snd_atiixp_update_dma(struct atiixp *chip, struct atiixp_dma *dma)
692 static void snd_atiixp_check_bus_busy(struct atiixp *chip)
695 if (atiixp_read(chip, CMD) & (ATI_REG_CMD_SEND_EN |
701 atiixp_update(chip, IER, ATI_REG_IER_SET_BUS_BUSY, bus_busy);
709 struct atiixp *chip = snd_pcm_substream_chip(substream);
717 spin_lock(&chip->reg_lock);
724 writel(dma->saved_curptr, chip->remap_addr +
726 dma->ops->enable_transfer(chip, 1);
735 dma->saved_curptr = readl(chip->remap_addr +
737 dma->ops->enable_transfer(chip, 0);
745 snd_atiixp_check_bus_busy(chip);
747 dma->ops->flush_dma(chip);
748 snd_atiixp_check_bus_busy(chip);
751 spin_unlock(&chip->reg_lock);
759 * every callback is supposed to be called in chip->reg_lock spinlock
763 static void atiixp_out_flush_dma(struct atiixp *chip)
765 atiixp_write(chip, FIFO_FLUSH, ATI_REG_FIFO_OUT_FLUSH);
769 static void atiixp_out_enable_dma(struct atiixp *chip, int on)
772 data = atiixp_read(chip, CMD);
776 atiixp_out_flush_dma(chip);
780 atiixp_write(chip, CMD, data);
784 static void atiixp_out_enable_transfer(struct atiixp *chip, int on)
786 atiixp_update(chip, CMD, ATI_REG_CMD_SEND_EN,
791 static void atiixp_in_enable_dma(struct atiixp *chip, int on)
793 atiixp_update(chip, CMD, ATI_REG_CMD_IN_DMA_EN,
798 static void atiixp_in_enable_transfer(struct atiixp *chip, int on)
801 unsigned int data = atiixp_read(chip, CMD);
806 while ((atiixp_read(chip, COUNTER) &
810 atiixp_write(chip, CMD, data);
813 atiixp_update(chip, CMD, ATI_REG_CMD_RECEIVE_EN, 0);
817 static void atiixp_in_flush_dma(struct atiixp *chip)
819 atiixp_write(chip, FIFO_FLUSH, ATI_REG_FIFO_IN_FLUSH);
823 static void atiixp_spdif_enable_dma(struct atiixp *chip, int on)
825 atiixp_update(chip, CMD, ATI_REG_CMD_SPDF_DMA_EN,
830 static void atiixp_spdif_enable_transfer(struct atiixp *chip, int on)
833 data = atiixp_read(chip, CMD);
838 atiixp_write(chip, CMD, data);
842 static void atiixp_spdif_flush_dma(struct atiixp *chip)
847 atiixp_spdif_enable_dma(chip, 0);
848 atiixp_spdif_enable_transfer(chip, 1);
852 if (! (atiixp_read(chip, SPDF_DMA_DT_SIZE) & ATI_REG_DMA_FIFO_USED))
857 atiixp_spdif_enable_transfer(chip, 0);
863 struct atiixp *chip = snd_pcm_substream_chip(substream);
865 spin_lock_irq(&chip->reg_lock);
866 if (chip->spdif_over_aclink) {
869 atiixp_update(chip, CMD, ATI_REG_CMD_SPDF_CONFIG_MASK,
871 data = atiixp_read(chip, OUT_DMA_SLOT) & ~ATI_REG_OUT_DMA_SLOT_MASK;
875 atiixp_write(chip, OUT_DMA_SLOT, data);
876 atiixp_update(chip, CMD, ATI_REG_CMD_INTERLEAVE_OUT,
880 atiixp_update(chip, CMD, ATI_REG_CMD_SPDF_CONFIG_MASK, 0);
881 atiixp_update(chip, CMD, ATI_REG_CMD_INTERLEAVE_SPDF, 0);
883 spin_unlock_irq(&chip->reg_lock);
890 struct atiixp *chip = snd_pcm_substream_chip(substream);
893 spin_lock_irq(&chip->reg_lock);
894 data = atiixp_read(chip, OUT_DMA_SLOT) & ~ATI_REG_OUT_DMA_SLOT_MASK;
916 atiixp_write(chip, OUT_DMA_SLOT, data);
918 atiixp_update(chip, CMD, ATI_REG_CMD_INTERLEAVE_OUT,
925 atiixp_update(chip, 6CH_REORDER, ATI_REG_6CH_REORDER_EN,
928 spin_unlock_irq(&chip->reg_lock);
935 struct atiixp *chip = snd_pcm_substream_chip(substream);
937 spin_lock_irq(&chip->reg_lock);
938 atiixp_update(chip, CMD, ATI_REG_CMD_INTERLEAVE_IN,
941 spin_unlock_irq(&chip->reg_lock);
951 struct atiixp *chip = snd_pcm_substream_chip(substream);
958 err = atiixp_build_dma_packets(chip, dma, substream,
965 struct ac97_pcm *pcm = chip->pcms[dma->ac97_pcm_type];
985 struct atiixp *chip = snd_pcm_substream_chip(substream);
989 struct ac97_pcm *pcm = chip->pcms[dma->ac97_pcm_type];
993 atiixp_clear_dma_packets(chip, dma, substream);
1024 struct atiixp *chip = snd_pcm_substream_chip(substream);
1037 runtime->hw.rates = chip->pcms[pcm_type]->rates;
1048 spin_lock_irq(&chip->reg_lock);
1049 dma->ops->enable_dma(chip, 1);
1050 spin_unlock_irq(&chip->reg_lock);
1059 struct atiixp *chip = snd_pcm_substream_chip(substream);
1063 spin_lock_irq(&chip->reg_lock);
1064 dma->ops->enable_dma(chip, 0);
1065 spin_unlock_irq(&chip->reg_lock);
1075 struct atiixp *chip = snd_pcm_substream_chip(substream);
1078 mutex_lock(&chip->open_mutex);
1079 err = snd_atiixp_pcm_open(substream, &chip->dmas[ATI_DMA_PLAYBACK], 0);
1080 mutex_unlock(&chip->open_mutex);
1083 substream->runtime->hw.channels_max = chip->max_channels;
1084 if (chip->max_channels > 2)
1093 struct atiixp *chip = snd_pcm_substream_chip(substream);
1095 mutex_lock(&chip->open_mutex);
1096 err = snd_atiixp_pcm_close(substream, &chip->dmas[ATI_DMA_PLAYBACK]);
1097 mutex_unlock(&chip->open_mutex);
1103 struct atiixp *chip = snd_pcm_substream_chip(substream);
1104 return snd_atiixp_pcm_open(substream, &chip->dmas[ATI_DMA_CAPTURE], 1);
1109 struct atiixp *chip = snd_pcm_substream_chip(substream);
1110 return snd_atiixp_pcm_close(substream, &chip->dmas[ATI_DMA_CAPTURE]);
1115 struct atiixp *chip = snd_pcm_substream_chip(substream);
1117 mutex_lock(&chip->open_mutex);
1118 if (chip->spdif_over_aclink) /* share DMA_PLAYBACK */
1119 err = snd_atiixp_pcm_open(substream, &chip->dmas[ATI_DMA_PLAYBACK], 2);
1121 err = snd_atiixp_pcm_open(substream, &chip->dmas[ATI_DMA_SPDIF], -1);
1122 mutex_unlock(&chip->open_mutex);
1128 struct atiixp *chip = snd_pcm_substream_chip(substream);
1130 mutex_lock(&chip->open_mutex);
1131 if (chip->spdif_over_aclink)
1132 err = snd_atiixp_pcm_close(substream, &chip->dmas[ATI_DMA_PLAYBACK]);
1134 err = snd_atiixp_pcm_close(substream, &chip->dmas[ATI_DMA_SPDIF]);
1135 mutex_unlock(&chip->open_mutex);
1236 static int snd_atiixp_pcm_new(struct atiixp *chip)
1240 struct snd_ac97_bus *pbus = chip->ac97_bus;
1244 chip->dmas[ATI_DMA_PLAYBACK].ops = &snd_atiixp_playback_dma_ops;
1245 chip->dmas[ATI_DMA_CAPTURE].ops = &snd_atiixp_capture_dma_ops;
1246 if (! chip->spdif_over_aclink)
1247 chip->dmas[ATI_DMA_SPDIF].ops = &snd_atiixp_spdif_dma_ops;
1250 if (chip->spdif_over_aclink)
1258 chip->pcms[i] = &pbus->pcms[i];
1260 chip->max_channels = 2;
1263 chip->max_channels = 6;
1265 chip->max_channels = 4;
1269 err = snd_pcm_new(chip->card, "ATI IXP AC97",
1275 pcm->private_data = chip;
1277 chip->pcmdevs[ATI_PCMDEV_ANALOG] = pcm;
1280 &chip->pci->dev, 64*1024, 128*1024);
1283 snd_pcm_alt_chmaps, chip->max_channels, 0,
1288 chip->ac97[0]->chmaps[SNDRV_PCM_STREAM_PLAYBACK] = chmap;
1291 if (chip->pcms[ATI_PCM_SPDIF] && ! chip->pcms[ATI_PCM_SPDIF]->rates)
1295 if (chip->pcms[ATI_PCM_SPDIF])
1296 chip->pcms[ATI_PCM_SPDIF]->rates = SNDRV_PCM_RATE_48000;
1299 err = snd_pcm_new(chip->card, "ATI IXP IEC958",
1304 pcm->private_data = chip;
1305 if (chip->spdif_over_aclink)
1309 chip->pcmdevs[ATI_PCMDEV_DIGITAL] = pcm;
1312 &chip->pci->dev, 64*1024, 128*1024);
1316 if (chip->ac97[i])
1317 snd_ac97_update_bits(chip->ac97[i],
1332 struct atiixp *chip = dev_id;
1335 status = atiixp_read(chip, ISR);
1342 snd_atiixp_xrun_dma(chip, &chip->dmas[ATI_DMA_PLAYBACK]);
1344 snd_atiixp_update_dma(chip, &chip->dmas[ATI_DMA_PLAYBACK]);
1346 snd_atiixp_xrun_dma(chip, &chip->dmas[ATI_DMA_CAPTURE]);
1348 snd_atiixp_update_dma(chip, &chip->dmas[ATI_DMA_CAPTURE]);
1349 if (! chip->spdif_over_aclink) {
1351 snd_atiixp_xrun_dma(chip, &chip->dmas[ATI_DMA_SPDIF]);
1353 snd_atiixp_update_dma(chip, &chip->dmas[ATI_DMA_SPDIF]);
1360 spin_lock(&chip->reg_lock);
1361 chip->codec_not_ready_bits |= detected;
1362 atiixp_update(chip, IER, detected, 0); /* disable the detected irqs */
1363 spin_unlock(&chip->reg_lock);
1367 atiixp_write(chip, ISR, status);
1399 static int snd_atiixp_mixer_new(struct atiixp *chip, int clock,
1416 if (snd_atiixp_codec_detect(chip) < 0)
1419 if ((err = snd_ac97_bus(chip->card, 0, &ops, chip, &pbus)) < 0)
1422 chip->ac97_bus = pbus;
1426 if (chip->codec_not_ready_bits & codec_skip[i])
1429 ac97.private_data = chip;
1430 ac97.pci = chip->pci;
1433 if (! chip->spdif_over_aclink)
1435 if ((err = snd_ac97_mixer(pbus, &ac97, &chip->ac97[i])) < 0) {
1436 chip->ac97[i] = NULL; /* to be sure */
1437 dev_dbg(chip->card->dev,
1445 dev_err(chip->card->dev, "no codec available\n");
1449 snd_ac97_tune_hardware(chip->ac97[0], ac97_quirks, quirk_override);
1462 struct atiixp *chip = card->private_data;
1467 snd_ac97_suspend(chip->ac97[i]);
1468 snd_atiixp_aclink_down(chip);
1469 snd_atiixp_chip_stop(chip);
1476 struct atiixp *chip = card->private_data;
1479 snd_atiixp_aclink_reset(chip);
1480 snd_atiixp_chip_start(chip);
1483 snd_ac97_resume(chip->ac97[i]);
1486 if (chip->pcmdevs[i]) {
1487 struct atiixp_dma *dma = &chip->dmas[i];
1489 dma->ops->enable_dma(chip, 1);
1492 chip->remap_addr + dma->ops->llp_offset);
1514 struct atiixp *chip = entry->private_data;
1518 snd_iprintf(buffer, "%02x: %08x\n", i, readl(chip->remap_addr + i));
1521 static void snd_atiixp_proc_init(struct atiixp *chip)
1523 snd_card_ro_proc_new(chip->card, "atiixp", chip, snd_atiixp_proc_read);
1531 static int snd_atiixp_free(struct atiixp *chip)
1533 if (chip->irq < 0)
1535 snd_atiixp_chip_stop(chip);
1538 if (chip->irq >= 0)
1539 free_irq(chip->irq, chip);
1540 iounmap(chip->remap_addr);
1541 pci_release_regions(chip->pci);
1542 pci_disable_device(chip->pci);
1543 kfree(chip);
1549 struct atiixp *chip = device->device_data;
1550 return snd_atiixp_free(chip);
1554 * constructor for chip instance
1563 struct atiixp *chip;
1569 chip = kzalloc(sizeof(*chip), GFP_KERNEL);
1570 if (chip == NULL) {
1575 spin_lock_init(&chip->reg_lock);
1576 mutex_init(&chip->open_mutex);
1577 chip->card = card;
1578 chip->pci = pci;
1579 chip->irq = -1;
1582 kfree(chip);
1585 chip->addr = pci_resource_start(pci, 0);
1586 chip->remap_addr = pci_ioremap_bar(pci, 0);
1587 if (chip->remap_addr == NULL) {
1589 snd_atiixp_free(chip);
1594 KBUILD_MODNAME, chip)) {
1596 snd_atiixp_free(chip);
1599 chip->irq = pci->irq;
1600 card->sync_irq = chip->irq;
1603 if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops)) < 0) {
1604 snd_atiixp_free(chip);
1608 *r_chip = chip;
1617 struct atiixp *chip;
1626 if ((err = snd_atiixp_create(card, pci, &chip)) < 0)
1628 card->private_data = chip;
1630 if ((err = snd_atiixp_aclink_reset(chip)) < 0)
1633 chip->spdif_over_aclink = spdif_aclink;
1635 if ((err = snd_atiixp_mixer_new(chip, ac97_clock, ac97_quirk)) < 0)
1638 if ((err = snd_atiixp_pcm_new(chip)) < 0)
1641 snd_atiixp_proc_init(chip);
1643 snd_atiixp_chip_start(chip);
1648 chip->ac97[0] ? snd_ac97_get_short_name(chip->ac97[0]) : "?",
1649 chip->addr, chip->irq);