12 #include <linux/module.h>
14 #include <linux/types.h>
17 #include <linux/slab.h>
20 #include <linux/device.h>
41 #define TDCR_SSZ_8_BITS (0x0 << 22)
42 #define TDCR_SSZ_12_BITS (0x1 << 22)
43 #define TDCR_SSZ_16_BITS (0x2 << 22)
44 #define TDCR_SSZ_20_BITS (0x3 << 22)
45 #define TDCR_SSZ_24_BITS (0x4 << 22)
46 #define TDCR_SSZ_32_BITS (0x5 << 22)
47 #define TDCR_SSZ_SHIFT (0x1 << 22)
48 #define TDCR_SSZ_MASK (0x7 << 22)
49 #define TDCR_SSPMOD (0x1 << 21)
50 #define TDCR_ABR (0x1 << 20)
51 #define TDCR_CDE (0x1 << 17)
52 #define TDCR_PACKMOD (0x1 << 16)
53 #define TDCR_CHANACT (0x1 << 14)
54 #define TDCR_FETCHND (0x1 << 13)
55 #define TDCR_CHANEN (0x1 << 12)
56 #define TDCR_INTMODE (0x1 << 10)
57 #define TDCR_CHAINMOD (0x1 << 9)
58 #define TDCR_BURSTSZ_MSK (0x7 << 6)
59 #define TDCR_BURSTSZ_4B (0x0 << 6)
60 #define TDCR_BURSTSZ_8B (0x1 << 6)
61 #define TDCR_BURSTSZ_16B (0x3 << 6)
62 #define TDCR_BURSTSZ_32B (0x6 << 6)
63 #define TDCR_BURSTSZ_64B (0x7 << 6)
64 #define TDCR_BURSTSZ_SQU_32B (0x7 << 6)
65 #define TDCR_BURSTSZ_128B (0x5 << 6)
66 #define TDCR_DSTDIR_MSK (0x3 << 4)
67 #define TDCR_DSTDIR_ADDR_HOLD (0x2 << 4)
68 #define TDCR_DSTDIR_ADDR_INC (0x0 << 4)
69 #define TDCR_SRCDIR_MSK (0x3 << 2)
70 #define TDCR_SRCDIR_ADDR_HOLD (0x2 << 2)
71 #define TDCR_SRCDIR_ADDR_INC (0x0 << 2)
72 #define TDCR_DSTDESCCONT (0x1 << 1)
73 #define TDCR_SRCDESTCONT (0x1 << 0)
76 #define TDIMR_COMP (0x1 << 0)
79 #define TDISR_COMP (0x1 << 0)
97 #define TDMA_ALIGNMENT 3
98 #define TDMA_MAX_XFER_BYTES SZ_64K
125 #define TDMA_CHANNEL_NUM 2
133 #define to_mmp_tdma_chan(dchan) container_of(dchan, struct mmp_tdma_chan, chan)
142 static void mmp_tdma_enable_chan(
struct mmp_tdma_chan *tdmac)
152 static void mmp_tdma_disable_chan(
struct mmp_tdma_chan *tdmac)
159 static void mmp_tdma_resume_chan(
struct mmp_tdma_chan *tdmac)
177 mmp_tdma_disable_chan(tdmac);
207 dev_err(tdmac->
dev,
"mmp_tdma: unknown burst size.\n");
222 dev_err(tdmac->
dev,
"mmp_tdma: unknown bus size.\n");
234 static int mmp_tdma_clear_chan_irq(
struct mmp_tdma_chan *tdmac)
252 if (mmp_tdma_clear_chan_irq(tdmac) == 0) {
254 tasklet_schedule(&tdmac->
tasklet);
260 static irqreturn_t mmp_tdma_int_handler(
int irq,
void *dev_id)
269 ret = mmp_tdma_chan_handler(irq, tdmac);
280 static void dma_do_tasklet(
unsigned long data)
284 if (tdmac->
desc.callback)
285 tdmac->
desc.callback(tdmac->
desc.callback_param);
289 static void mmp_tdma_free_descriptor(
struct mmp_tdma_chan *tdmac)
312 static int mmp_tdma_alloc_chan_resources(
struct dma_chan *
chan)
318 tdmac->
desc.tx_submit = mmp_tdma_tx_submit;
321 ret = devm_request_irq(tdmac->
dev, tdmac->
irq,
329 static void mmp_tdma_free_chan_resources(
struct dma_chan *chan)
335 mmp_tdma_free_descriptor(tdmac);
365 int num_periods = buf_len / period_len;
373 "maximum period size exceeded: %d > %d\n",
384 while (
buf < buf_len) {
387 if (i + 1 == num_periods)
391 sizeof(*desc) * (i + 1);
401 dma_addr += period_len;
426 mmp_tdma_disable_chan(tdmac);
429 mmp_tdma_pause_chan(tdmac);
432 mmp_tdma_resume_chan(tdmac);
445 return mmp_tdma_config_chan(tdmac);
458 dma_set_residue(txstate, tdmac->
buf_len - tdmac->
pos);
463 static void mmp_tdma_issue_pending(
struct dma_chan *chan)
467 mmp_tdma_enable_chan(tdmac);
483 if (idx >= TDMA_CHANNEL_NUM) {
484 dev_err(tdev->
dev,
"too many channels for device!\n");
491 dev_err(tdev->
dev,
"no free memory for DMA channels!\n");
512 { .compatible =
"marvell,adma-1.0", .data = (
void *)
MMP_AUD_TDMA},
513 { .compatible =
"marvell,pxa910-squ", .data = (
void *)
PXA910_SQU},
525 int irq = 0, irq_num = 0;
554 INIT_LIST_HEAD(&tdev->
device.channels);
556 if (irq_num != chan_num) {
558 ret = devm_request_irq(&pdev->
dev, irq,
567 ret = mmp_tdma_chan_init(tdev, i, irq, type);
575 tdev->
device.device_alloc_chan_resources =
576 mmp_tdma_alloc_chan_resources;
577 tdev->
device.device_free_chan_resources =
578 mmp_tdma_free_chan_resources;
579 tdev->
device.device_prep_dma_cyclic = mmp_tdma_prep_dma_cyclic;
580 tdev->
device.device_tx_status = mmp_tdma_tx_status;
581 tdev->
device.device_issue_pending = mmp_tdma_issue_pending;
582 tdev->
device.device_control = mmp_tdma_control;
586 platform_set_drvdata(pdev, tdev);
608 .of_match_table = mmp_tdma_dt_ids,
610 .id_table = mmp_tdma_id_table,
611 .probe = mmp_tdma_probe,