12 #include <linux/bitmap.h>
13 #include <linux/device.h>
19 #include <linux/module.h>
23 #include <linux/types.h>
37 #include <mach/gpio.h>
39 #ifdef CONFIG_ARCH_AT91
40 #include <mach/hardware.h>
84 #define get_chip(card) ((struct atmel_ac97c *)(card)->private_data)
86 #define ac97c_writel(chip, reg, val) \
87 __raw_writel((val), (chip)->regs + AC97C_##reg)
88 #define ac97c_readl(chip, reg) \
89 __raw_readl((chip)->regs + AC97C_##reg)
92 static void atmel_ac97c_dma_playback_period_done(
void *
arg)
98 static void atmel_ac97c_dma_capture_period_done(
void *
arg)
111 unsigned long buffer_len, period_len;
118 dev_dbg(&chip->
pdev->dev,
"too complex transfer\n");
123 chan = chip->
dma.tx_chan;
125 chan = chip->
dma.rx_chan;
127 buffer_len = frames_to_bytes(runtime, runtime->
buffer_size);
128 period_len = frames_to_bytes(runtime, runtime->
period_size);
131 period_len, direction);
133 dev_dbg(&chip->
pdev->dev,
"could not prepare cyclic DMA\n");
134 return PTR_ERR(cdesc);
179 runtime->
hw = atmel_ac97c_hw;
198 runtime->
hw = atmel_ac97c_hw;
347 switch (runtime->
format) {
373 if (runtime->
rate != 48000) {
386 dev_dbg(&chip->
pdev->dev,
"could not set rate %d Hz\n",
391 retval = atmel_ac97c_prepare_dma(chip, substream,
409 int block_size = frames_to_bytes(runtime, runtime->
period_size);
438 switch (runtime->
format) {
464 if (runtime->
rate != 48000) {
477 dev_dbg(&chip->
pdev->dev,
"could not set rate %d Hz\n",
482 retval = atmel_ac97c_prepare_dma(chip, substream,
500 unsigned long camr, ptcr = 0;
544 unsigned long camr, ptcr = 0;
599 frames = bytes_to_frames(runtime, bytes);
619 frames = bytes_to_frames(runtime, bytes);
625 static struct snd_pcm_ops atmel_ac97_playback_ops = {
626 .open = atmel_ac97c_playback_open,
627 .close = atmel_ac97c_playback_close,
629 .hw_params = atmel_ac97c_playback_hw_params,
630 .hw_free = atmel_ac97c_playback_hw_free,
631 .prepare = atmel_ac97c_playback_prepare,
632 .trigger = atmel_ac97c_playback_trigger,
633 .pointer = atmel_ac97c_playback_pointer,
636 static struct snd_pcm_ops atmel_ac97_capture_ops = {
637 .open = atmel_ac97c_capture_open,
638 .close = atmel_ac97c_capture_close,
640 .hw_params = atmel_ac97c_capture_hw_params,
641 .hw_free = atmel_ac97c_capture_hw_free,
642 .prepare = atmel_ac97c_capture_prepare,
643 .trigger = atmel_ac97c_capture_trigger,
644 .pointer = atmel_ac97c_capture_pointer,
659 dev_dbg(&chip->
pdev->dev,
"channel A event%s%s%s%s%s%s\n",
665 !casr ?
" NONE" :
"");
669 block_size = frames_to_bytes(runtime,
676 if (next_period == runtime->
periods)
679 offset = block_size * next_period;
691 block_size = frames_to_bytes(runtime,
698 if (next_period == runtime->
periods)
701 offset = block_size * next_period;
714 dev_info(&chip->
pdev->dev,
"codec channel event%s%s%s%s%s\n",
719 !cosr ?
" NONE" :
"");
724 dev_err(&chip->
pdev->dev,
"spurious interrupt sr 0x%08x "
725 "casr 0x%08x cosr 0x%08x\n", sr, casr, cosr);
776 chip->
pdev->id, playback, capture, &pcm);
782 &atmel_ac97_capture_ops);
785 &atmel_ac97_playback_ops);
801 static int atmel_ac97c_mixer_new(
struct atmel_ac97c *chip)
804 memset(&
template, 0,
sizeof(
template));
805 template.private_data =
chip;
809 static void atmel_ac97c_write(
struct snd_ac97 *ac97,
unsigned short reg,
816 word = (reg & 0x7f) << 16 | val;
826 dev_dbg(&chip->
pdev->dev,
"codec write timeout\n");
829 static unsigned short atmel_ac97c_read(
struct snd_ac97 *ac97,
837 word = (0x80 | (reg & 0x7f)) << 16;
886 static void atmel_ac97c_reset(
struct atmel_ac97c *chip)
913 .write = atmel_ac97c_write,
914 .read = atmel_ac97c_read,
925 pdata = pdev->
dev.platform_data;
945 return PTR_ERR(pclk);
952 dev_dbg(&pdev->
dev,
"could not create sound card device\n");
953 goto err_snd_card_new;
958 retval =
request_irq(irq, atmel_ac97c_interrupt, 0,
"AC97C", chip);
960 dev_dbg(&pdev->
dev,
"unable to request irq %d\n", irq);
961 goto err_request_irq;
977 dev_dbg(&pdev->
dev,
"could not remap register memory\n");
984 dev_dbg(&pdev->
dev,
"reset pin not available\n");
996 atmel_ac97c_reset(chip);
1004 dev_dbg(&pdev->
dev,
"could not register on ac97 bus\n");
1008 retval = atmel_ac97c_mixer_new(chip);
1010 dev_dbg(&pdev->
dev,
"could not register ac97 mixer\n");
1015 if (pdata->
rx_dws.dma_dev) {
1023 if (chip->
dma.rx_chan) {
1035 dmaengine_slave_config(chip->
dma.rx_chan,
1040 dev_name(&chip->
dma.rx_chan->dev->device));
1044 if (pdata->
tx_dws.dma_dev) {
1052 if (chip->
dma.tx_chan) {
1064 dmaengine_slave_config(chip->
dma.tx_chan,
1069 dev_name(&chip->
dma.tx_chan->dev->device));
1086 retval = atmel_ac97c_pcm_new(chip);
1088 dev_dbg(&pdev->
dev,
"could not register ac97 pcm device\n");
1094 dev_dbg(&pdev->
dev,
"could not register sound card\n");
1098 platform_set_drvdata(pdev, card);
1100 dev_info(&pdev->
dev,
"Atmel AC97 controller at 0x%p, irq = %d\n",
1133 #ifdef CONFIG_PM_SLEEP
1134 static int atmel_ac97c_suspend(
struct device *pdev)
1150 static int atmel_ac97c_resume(
struct device *pdev)
1165 static SIMPLE_DEV_PM_OPS(atmel_ac97c_pm, atmel_ac97c_suspend, atmel_ac97c_resume);
1166 #define ATMEL_AC97C_PM_OPS &atmel_ac97c_pm
1168 #define ATMEL_AC97C_PM_OPS NULL
1173 struct snd_card *card = platform_get_drvdata(pdev);
1202 platform_set_drvdata(pdev,
NULL);
1210 .name =
"atmel_ac97c",
1216 static int __init atmel_ac97c_init(
void)
1223 static void __exit atmel_ac97c_exit(
void)