Lines Matching +full:ati +full:- +full:exclude

1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * ALSA driver for ATI IXP 150/200/250 AC97 modem controllers
24 MODULE_DESCRIPTION("ATI IXP MC97 controller");
27 static int index = -2; /* Exclude the first card */
32 MODULE_PARM_DESC(index, "Index value for ATI IXP controller.");
34 MODULE_PARM_DESC(id, "ID string for ATI IXP controller.");
214 int ac97_pcm_type; /* index # of ac97_pcm to access, -1 = not used */
218 * ATI IXP chip
250 { PCI_VDEVICE(ATI, 0x434d), 0 }, /* SB200 */
251 { PCI_VDEVICE(ATI, 0x4378), 0 }, /* SB400 */
269 void __iomem *addr = chip->remap_addr + reg; in snd_atiixp_update_bits()
284 writel(value, chip->remap_addr + ATI_REG_##reg)
286 readl(chip->remap_addr + ATI_REG_##reg)
294 * in a future version, a scatter-gather buffer should be implemented.
320 return -ENOMEM; in atiixp_build_dma_packets()
322 if (dma->desc_buf.area == NULL) { in atiixp_build_dma_packets()
323 if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, &chip->pci->dev, in atiixp_build_dma_packets()
324 ATI_DESC_LIST_SIZE, &dma->desc_buf) < 0) in atiixp_build_dma_packets()
325 return -ENOMEM; in atiixp_build_dma_packets()
326 dma->period_bytes = dma->periods = 0; /* clear */ in atiixp_build_dma_packets()
329 if (dma->periods == periods && dma->period_bytes == period_bytes) in atiixp_build_dma_packets()
333 spin_lock_irqsave(&chip->reg_lock, flags); in atiixp_build_dma_packets()
334 writel(0, chip->remap_addr + dma->ops->llp_offset); in atiixp_build_dma_packets()
335 dma->ops->enable_dma(chip, 0); in atiixp_build_dma_packets()
336 dma->ops->enable_dma(chip, 1); in atiixp_build_dma_packets()
337 spin_unlock_irqrestore(&chip->reg_lock, flags); in atiixp_build_dma_packets()
340 addr = (u32)substream->runtime->dma_addr; in atiixp_build_dma_packets()
341 desc_addr = (u32)dma->desc_buf.addr; in atiixp_build_dma_packets()
344 desc = &((struct atiixp_dma_desc *)dma->desc_buf.area)[i]; in atiixp_build_dma_packets()
345 desc->addr = cpu_to_le32(addr); in atiixp_build_dma_packets()
346 desc->status = 0; in atiixp_build_dma_packets()
347 desc->size = period_bytes >> 2; /* in dwords */ in atiixp_build_dma_packets()
349 if (i == periods - 1) in atiixp_build_dma_packets()
350 desc->next = cpu_to_le32((u32)dma->desc_buf.addr); in atiixp_build_dma_packets()
352 desc->next = cpu_to_le32(desc_addr); in atiixp_build_dma_packets()
356 writel((u32)dma->desc_buf.addr | ATI_REG_LINKPTR_EN, in atiixp_build_dma_packets()
357 chip->remap_addr + dma->ops->llp_offset); in atiixp_build_dma_packets()
359 dma->period_bytes = period_bytes; in atiixp_build_dma_packets()
360 dma->periods = periods; in atiixp_build_dma_packets()
372 if (dma->desc_buf.area) { in atiixp_clear_dma_packets()
373 writel(0, chip->remap_addr + dma->ops->llp_offset); in atiixp_clear_dma_packets()
374 snd_dma_free_pages(&dma->desc_buf); in atiixp_clear_dma_packets()
375 dma->desc_buf.area = NULL; in atiixp_clear_dma_packets()
387 if (! timeout--) { in snd_atiixp_acquire_codec()
388 dev_warn(chip->card->dev, "codec acquire timeout\n"); in snd_atiixp_acquire_codec()
389 return -EBUSY; in snd_atiixp_acquire_codec()
418 } while (--timeout); in snd_atiixp_codec_read()
421 dev_warn(chip->card->dev, "codec read timeout (reg %x)\n", reg); in snd_atiixp_codec_read()
444 struct atiixp_modem *chip = ac97->private_data; in snd_atiixp_ac97_read()
445 return snd_atiixp_codec_read(chip, ac97->num, reg); in snd_atiixp_ac97_read()
452 struct atiixp_modem *chip = ac97->private_data; in snd_atiixp_ac97_write()
458 snd_atiixp_codec_write(chip, ac97->num, reg, val); in snd_atiixp_ac97_write()
486 if (!--timeout) { in snd_atiixp_aclink_reset()
487 dev_err(chip->card->dev, "codec reset timeout\n"); in snd_atiixp_aclink_reset()
502 // return -EBUSY; in snd_atiixp_aclink_down()
510 * auto-detection of codecs
512 * the IXP chip can generate interrupts for the non-existing codecs.
527 chip->codec_not_ready_bits = 0; in snd_atiixp_codec_detect()
531 while (timeout-- > 0) { in snd_atiixp_codec_detect()
533 if (chip->codec_not_ready_bits) in snd_atiixp_codec_detect()
538 if ((chip->codec_not_ready_bits & ALL_CODEC_NOT_READY) == ALL_CODEC_NOT_READY) { in snd_atiixp_codec_detect()
539 dev_err(chip->card->dev, "no codec detected!\n"); in snd_atiixp_codec_detect()
540 return -ENXIO; in snd_atiixp_codec_detect()
590 * position. when SG-buffer is implemented, the offset must be calculated
596 struct snd_pcm_runtime *runtime = substream->runtime; in snd_atiixp_pcm_pointer()
597 struct atiixp_dma *dma = runtime->private_data; in snd_atiixp_pcm_pointer()
601 while (timeout--) { in snd_atiixp_pcm_pointer()
602 curptr = readl(chip->remap_addr + dma->ops->dt_cur); in snd_atiixp_pcm_pointer()
603 if (curptr < dma->buf_addr) in snd_atiixp_pcm_pointer()
605 curptr -= dma->buf_addr; in snd_atiixp_pcm_pointer()
606 if (curptr >= dma->buf_bytes) in snd_atiixp_pcm_pointer()
610 dev_dbg(chip->card->dev, "invalid DMA pointer read 0x%x (buf=%x)\n", in snd_atiixp_pcm_pointer()
611 readl(chip->remap_addr + dma->ops->dt_cur), dma->buf_addr); in snd_atiixp_pcm_pointer()
621 if (! dma->substream || ! dma->running) in snd_atiixp_xrun_dma()
623 dev_dbg(chip->card->dev, "XRUN detected (DMA %d)\n", dma->ops->type); in snd_atiixp_xrun_dma()
624 snd_pcm_stop_xrun(dma->substream); in snd_atiixp_xrun_dma()
633 if (! dma->substream || ! dma->running) in snd_atiixp_update_dma()
635 snd_pcm_period_elapsed(dma->substream); in snd_atiixp_update_dma()
657 struct atiixp_dma *dma = substream->runtime->private_data; in snd_atiixp_pcm_trigger()
660 if (snd_BUG_ON(!dma->ops->enable_transfer || in snd_atiixp_pcm_trigger()
661 !dma->ops->flush_dma)) in snd_atiixp_pcm_trigger()
662 return -EINVAL; in snd_atiixp_pcm_trigger()
664 spin_lock(&chip->reg_lock); in snd_atiixp_pcm_trigger()
667 dma->ops->enable_transfer(chip, 1); in snd_atiixp_pcm_trigger()
668 dma->running = 1; in snd_atiixp_pcm_trigger()
671 dma->ops->enable_transfer(chip, 0); in snd_atiixp_pcm_trigger()
672 dma->running = 0; in snd_atiixp_pcm_trigger()
675 err = -EINVAL; in snd_atiixp_pcm_trigger()
681 dma->ops->flush_dma(chip); in snd_atiixp_pcm_trigger()
685 spin_unlock(&chip->reg_lock); in snd_atiixp_pcm_trigger()
693 * every callback is supposed to be called in chip->reg_lock spinlock
756 spin_lock_irq(&chip->reg_lock); in snd_atiixp_playback_prepare()
762 spin_unlock_irq(&chip->reg_lock); in snd_atiixp_playback_prepare()
773 * hw_params - allocate the buffer and set up buffer descriptors
779 struct atiixp_dma *dma = substream->runtime->private_data; in snd_atiixp_pcm_hw_params()
783 dma->buf_addr = substream->runtime->dma_addr; in snd_atiixp_pcm_hw_params()
784 dma->buf_bytes = params_buffer_bytes(hw_params); in snd_atiixp_pcm_hw_params()
794 if (! chip->ac97[i]) in snd_atiixp_pcm_hw_params()
796 snd_ac97_write(chip->ac97[i], AC97_LINE1_RATE, params_rate(hw_params)); in snd_atiixp_pcm_hw_params()
797 snd_ac97_write(chip->ac97[i], AC97_LINE1_LEVEL, 0); in snd_atiixp_pcm_hw_params()
806 struct atiixp_dma *dma = substream->runtime->private_data; in snd_atiixp_pcm_hw_free()
840 struct snd_pcm_runtime *runtime = substream->runtime; in snd_atiixp_pcm_open()
849 if (snd_BUG_ON(!dma->ops || !dma->ops->enable_dma)) in snd_atiixp_pcm_open()
850 return -EINVAL; in snd_atiixp_pcm_open()
852 if (dma->opened) in snd_atiixp_pcm_open()
853 return -EBUSY; in snd_atiixp_pcm_open()
854 dma->substream = substream; in snd_atiixp_pcm_open()
855 runtime->hw = snd_atiixp_pcm_hw; in snd_atiixp_pcm_open()
856 dma->ac97_pcm_type = pcm_type; in snd_atiixp_pcm_open()
864 runtime->private_data = dma; in snd_atiixp_pcm_open()
867 spin_lock_irq(&chip->reg_lock); in snd_atiixp_pcm_open()
868 dma->ops->enable_dma(chip, 1); in snd_atiixp_pcm_open()
869 spin_unlock_irq(&chip->reg_lock); in snd_atiixp_pcm_open()
870 dma->opened = 1; in snd_atiixp_pcm_open()
880 if (snd_BUG_ON(!dma->ops || !dma->ops->enable_dma)) in snd_atiixp_pcm_close()
881 return -EINVAL; in snd_atiixp_pcm_close()
882 spin_lock_irq(&chip->reg_lock); in snd_atiixp_pcm_close()
883 dma->ops->enable_dma(chip, 0); in snd_atiixp_pcm_close()
884 spin_unlock_irq(&chip->reg_lock); in snd_atiixp_pcm_close()
885 dma->substream = NULL; in snd_atiixp_pcm_close()
886 dma->opened = 0; in snd_atiixp_pcm_close()
897 mutex_lock(&chip->open_mutex); in snd_atiixp_playback_open()
898 err = snd_atiixp_pcm_open(substream, &chip->dmas[ATI_DMA_PLAYBACK], 0); in snd_atiixp_playback_open()
899 mutex_unlock(&chip->open_mutex); in snd_atiixp_playback_open()
909 mutex_lock(&chip->open_mutex); in snd_atiixp_playback_close()
910 err = snd_atiixp_pcm_close(substream, &chip->dmas[ATI_DMA_PLAYBACK]); in snd_atiixp_playback_close()
911 mutex_unlock(&chip->open_mutex); in snd_atiixp_playback_close()
918 return snd_atiixp_pcm_open(substream, &chip->dmas[ATI_DMA_CAPTURE], 1); in snd_atiixp_capture_open()
924 return snd_atiixp_pcm_close(substream, &chip->dmas[ATI_DMA_CAPTURE]); in snd_atiixp_capture_close()
974 chip->dmas[ATI_DMA_PLAYBACK].ops = &snd_atiixp_playback_dma_ops; in snd_atiixp_pcm_new()
975 chip->dmas[ATI_DMA_CAPTURE].ops = &snd_atiixp_capture_dma_ops; in snd_atiixp_pcm_new()
978 err = snd_pcm_new(chip->card, "ATI IXP MC97", ATI_PCMDEV_ANALOG, 1, 1, &pcm); in snd_atiixp_pcm_new()
983 pcm->dev_class = SNDRV_PCM_CLASS_MODEM; in snd_atiixp_pcm_new()
984 pcm->private_data = chip; in snd_atiixp_pcm_new()
985 strcpy(pcm->name, "ATI IXP MC97"); in snd_atiixp_pcm_new()
986 chip->pcmdevs[ATI_PCMDEV_ANALOG] = pcm; in snd_atiixp_pcm_new()
989 &chip->pci->dev, 64*1024, 128*1024); in snd_atiixp_pcm_new()
1011 snd_atiixp_xrun_dma(chip, &chip->dmas[ATI_DMA_PLAYBACK]); in snd_atiixp_interrupt()
1013 snd_atiixp_update_dma(chip, &chip->dmas[ATI_DMA_PLAYBACK]); in snd_atiixp_interrupt()
1015 snd_atiixp_xrun_dma(chip, &chip->dmas[ATI_DMA_CAPTURE]); in snd_atiixp_interrupt()
1017 snd_atiixp_update_dma(chip, &chip->dmas[ATI_DMA_CAPTURE]); in snd_atiixp_interrupt()
1023 spin_lock(&chip->reg_lock); in snd_atiixp_interrupt()
1024 chip->codec_not_ready_bits |= detected; in snd_atiixp_interrupt()
1026 spin_unlock(&chip->reg_lock); in snd_atiixp_interrupt()
1057 return -ENXIO; in snd_atiixp_mixer_new()
1059 err = snd_ac97_bus(chip->card, 0, &ops, chip, &pbus); in snd_atiixp_mixer_new()
1062 pbus->clock = clock; in snd_atiixp_mixer_new()
1063 chip->ac97_bus = pbus; in snd_atiixp_mixer_new()
1067 if (chip->codec_not_ready_bits & codec_skip[i]) in snd_atiixp_mixer_new()
1071 ac97.pci = chip->pci; in snd_atiixp_mixer_new()
1074 err = snd_ac97_mixer(pbus, &ac97, &chip->ac97[i]); in snd_atiixp_mixer_new()
1076 chip->ac97[i] = NULL; /* to be sure */ in snd_atiixp_mixer_new()
1077 dev_dbg(chip->card->dev, in snd_atiixp_mixer_new()
1085 dev_err(chip->card->dev, "no codec available\n"); in snd_atiixp_mixer_new()
1086 return -ENODEV; in snd_atiixp_mixer_new()
1089 /* snd_ac97_tune_hardware(chip->ac97, ac97_quirks); */ in snd_atiixp_mixer_new()
1101 struct atiixp_modem *chip = card->private_data; in snd_atiixp_suspend()
1106 snd_ac97_suspend(chip->ac97[i]); in snd_atiixp_suspend()
1115 struct atiixp_modem *chip = card->private_data; in snd_atiixp_resume()
1122 snd_ac97_resume(chip->ac97[i]); in snd_atiixp_resume()
1137 struct atiixp_modem *chip = entry->private_data; in snd_atiixp_proc_read()
1141 snd_iprintf(buffer, "%02x: %08x\n", i, readl(chip->remap_addr + i)); in snd_atiixp_proc_read()
1146 snd_card_ro_proc_new(chip->card, "atiixp-modem", chip, in snd_atiixp_proc_init()
1157 snd_atiixp_chip_stop(card->private_data); in snd_atiixp_free()
1165 struct atiixp_modem *chip = card->private_data; in snd_atiixp_init()
1172 spin_lock_init(&chip->reg_lock); in snd_atiixp_init()
1173 mutex_init(&chip->open_mutex); in snd_atiixp_init()
1174 chip->card = card; in snd_atiixp_init()
1175 chip->pci = pci; in snd_atiixp_init()
1176 chip->irq = -1; in snd_atiixp_init()
1177 err = pcim_iomap_regions(pci, 1 << 0, "ATI IXP MC97"); in snd_atiixp_init()
1180 chip->addr = pci_resource_start(pci, 0); in snd_atiixp_init()
1181 chip->remap_addr = pcim_iomap_table(pci)[0]; in snd_atiixp_init()
1183 if (devm_request_irq(&pci->dev, pci->irq, snd_atiixp_interrupt, in snd_atiixp_init()
1185 dev_err(card->dev, "unable to grab IRQ %d\n", pci->irq); in snd_atiixp_init()
1186 return -EBUSY; in snd_atiixp_init()
1188 chip->irq = pci->irq; in snd_atiixp_init()
1189 card->sync_irq = chip->irq; in snd_atiixp_init()
1190 card->private_free = snd_atiixp_free; in snd_atiixp_init()
1204 err = snd_devm_card_new(&pci->dev, index, id, THIS_MODULE, in __snd_atiixp_probe()
1208 chip = card->private_data; in __snd_atiixp_probe()
1210 strcpy(card->driver, "ATIIXP-MODEM"); in __snd_atiixp_probe()
1211 strcpy(card->shortname, "ATI IXP Modem"); in __snd_atiixp_probe()
1232 sprintf(card->longname, "%s rev %x at 0x%lx, irq %i", in __snd_atiixp_probe()
1233 card->shortname, pci->revision, chip->addr, chip->irq); in __snd_atiixp_probe()
1246 return snd_card_free_on_error(&pci->dev, __snd_atiixp_probe(pci, pci_id)); in snd_atiixp_probe()