11 #include <linux/bitmap.h>
17 #include <linux/module.h>
19 #include <linux/types.h>
29 #define DAC_DATA 0x0000
30 #define DAC_CTRL 0x0008
31 #define DAC_INT_MASK 0x000c
32 #define DAC_INT_EN 0x0010
33 #define DAC_INT_DIS 0x0014
34 #define DAC_INT_CLR 0x0018
35 #define DAC_INT_STATUS 0x001c
38 #define DAC_SWAP_OFFSET 30
39 #define DAC_SWAP_SIZE 1
40 #define DAC_EN_OFFSET 31
44 #define DAC_UNDERRUN_OFFSET 28
45 #define DAC_UNDERRUN_SIZE 1
46 #define DAC_TX_READY_OFFSET 29
47 #define DAC_TX_READY_SIZE 1
50 #define DAC_BIT(name) \
51 (1 << DAC_##name##_OFFSET)
52 #define DAC_BF(name, value) \
53 (((value) & ((1 << DAC_##name##_SIZE) - 1)) \
54 << DAC_##name##_OFFSET)
55 #define DAC_BFEXT(name, value) \
56 (((value) >> DAC_##name##_OFFSET) \
57 & ((1 << DAC_##name##_SIZE) - 1))
58 #define DAC_BFINS(name, value, old) \
59 (((old) & ~(((1 << DAC_##name##_SIZE) - 1) \
60 << DAC_##name##_OFFSET)) \
61 | DAC_BF(name, value))
64 #define dac_readl(port, reg) \
65 __raw_readl((port)->regs + DAC_##reg)
66 #define dac_writel(port, reg, value) \
67 __raw_writel((value), (port)->regs + DAC_##reg)
74 #define MAX_NUM_RATES 6
76 #define RATE_MAX 192000
106 #define get_dac(card) ((struct atmel_abdac *)(card)->private_data)
109 static void atmel_abdac_dma_period_done(
void *
arg)
115 static int atmel_abdac_prepare_dma(
struct atmel_abdac *dac,
122 unsigned long buffer_len, period_len;
129 dev_dbg(&dac->
pdev->dev,
"too complex transfer\n");
133 buffer_len = frames_to_bytes(runtime, runtime->
buffer_size);
134 period_len = frames_to_bytes(runtime, runtime->
period_size);
139 dev_dbg(&dac->
pdev->dev,
"could not prepare cyclic DMA\n");
140 return PTR_ERR(cdesc);
146 dac->
dma.cdesc = cdesc;
180 substream->
runtime->hw = atmel_abdac_hw;
229 retval = atmel_abdac_prepare_dma(dac, substream,
DMA_TO_DEVICE);
276 frames = bytes_to_frames(runtime, bytes);
293 dev_err(&dac->
pdev->dev,
"spurious interrupt (status=0x%x)\n",
302 .open = atmel_abdac_open,
303 .close = atmel_abdac_close,
305 .hw_params = atmel_abdac_hw_params,
306 .hw_free = atmel_abdac_hw_free,
307 .prepare = atmel_abdac_prepare,
308 .trigger = atmel_abdac_trigger,
309 .pointer = atmel_abdac_pointer,
319 dac->
pdev->id, 1, 0, &pcm);
348 static int set_sample_rates(
struct atmel_abdac *dac)
372 for (i = 0; i < (index / 2); i++) {
373 unsigned int tmp = dac->
rates[index - 1 -
i];
396 struct clk *sample_clk;
408 dev_dbg(&pdev->
dev,
"could not get IRQ number\n");
412 pdata = pdev->
dev.platform_data;
421 return PTR_ERR(pclk);
423 sample_clk =
clk_get(&pdev->
dev,
"sample_clk");
424 if (IS_ERR(sample_clk)) {
426 retval = PTR_ERR(sample_clk);
434 dev_dbg(&pdev->
dev,
"could not create sound card device\n");
435 goto out_put_sample_clk;
446 retval = set_sample_rates(dac);
448 dev_dbg(&pdev->
dev,
"could not set supported rates\n");
454 dev_dbg(&pdev->
dev,
"could not remap register memory\n");
463 retval =
request_irq(irq, abdac_interrupt, 0,
"abdac", dac);
465 dev_dbg(&pdev->
dev,
"could not request irq\n");
471 if (pdata->
dws.dma_dev) {
488 dmaengine_slave_config(dac->
dma.chan, &dma_conf);
491 if (!pdata->
dws.dma_dev || !dac->
dma.chan) {
494 goto out_unset_card_dev;
501 retval = atmel_abdac_pcm_new(dac);
503 dev_dbg(&pdev->
dev,
"could not register ABDAC pcm device\n");
504 goto out_release_dma;
509 dev_dbg(&pdev->
dev,
"could not register sound card\n");
510 goto out_release_dma;
513 platform_set_drvdata(pdev, card);
515 dev_info(&pdev->
dev,
"Atmel ABDAC at 0x%p using %s\n",
516 dac->
regs, dev_name(&dac->
dma.chan->dev->device));
538 #ifdef CONFIG_PM_SLEEP
539 static int atmel_abdac_suspend(
struct device *pdev)
551 static int atmel_abdac_resume(
struct device *pdev)
564 static SIMPLE_DEV_PM_OPS(atmel_abdac_pm, atmel_abdac_suspend, atmel_abdac_resume);
565 #define ATMEL_ABDAC_PM_OPS &atmel_abdac_pm
567 #define ATMEL_ABDAC_PM_OPS NULL
572 struct snd_card *card = platform_get_drvdata(pdev);
586 platform_set_drvdata(pdev,
NULL);
594 .name =
"atmel_abdac",
600 static int __init atmel_abdac_init(
void)
607 static void __exit atmel_abdac_exit(
void)