25 #include <linux/module.h>
27 #include <linux/slab.h>
34 #define M2P_CONTROL 0x0000
35 #define M2P_CONTROL_STALLINT BIT(0)
36 #define M2P_CONTROL_NFBINT BIT(1)
37 #define M2P_CONTROL_CH_ERROR_INT BIT(3)
38 #define M2P_CONTROL_ENABLE BIT(4)
39 #define M2P_CONTROL_ICE BIT(6)
41 #define M2P_INTERRUPT 0x0004
42 #define M2P_INTERRUPT_STALL BIT(0)
43 #define M2P_INTERRUPT_NFB BIT(1)
44 #define M2P_INTERRUPT_ERROR BIT(3)
46 #define M2P_PPALLOC 0x0008
47 #define M2P_STATUS 0x000c
49 #define M2P_MAXCNT0 0x0020
50 #define M2P_BASE0 0x0024
51 #define M2P_MAXCNT1 0x0030
52 #define M2P_BASE1 0x0034
54 #define M2P_STATE_IDLE 0
55 #define M2P_STATE_STALL 1
56 #define M2P_STATE_ON 2
57 #define M2P_STATE_NEXT 3
60 #define M2M_CONTROL 0x0000
61 #define M2M_CONTROL_DONEINT BIT(2)
62 #define M2M_CONTROL_ENABLE BIT(3)
63 #define M2M_CONTROL_START BIT(4)
64 #define M2M_CONTROL_DAH BIT(11)
65 #define M2M_CONTROL_SAH BIT(12)
66 #define M2M_CONTROL_PW_SHIFT 9
67 #define M2M_CONTROL_PW_8 (0 << M2M_CONTROL_PW_SHIFT)
68 #define M2M_CONTROL_PW_16 (1 << M2M_CONTROL_PW_SHIFT)
69 #define M2M_CONTROL_PW_32 (2 << M2M_CONTROL_PW_SHIFT)
70 #define M2M_CONTROL_PW_MASK (3 << M2M_CONTROL_PW_SHIFT)
71 #define M2M_CONTROL_TM_SHIFT 13
72 #define M2M_CONTROL_TM_TX (1 << M2M_CONTROL_TM_SHIFT)
73 #define M2M_CONTROL_TM_RX (2 << M2M_CONTROL_TM_SHIFT)
74 #define M2M_CONTROL_NFBINT BIT(21)
75 #define M2M_CONTROL_RSS_SHIFT 22
76 #define M2M_CONTROL_RSS_SSPRX (1 << M2M_CONTROL_RSS_SHIFT)
77 #define M2M_CONTROL_RSS_SSPTX (2 << M2M_CONTROL_RSS_SHIFT)
78 #define M2M_CONTROL_RSS_IDE (3 << M2M_CONTROL_RSS_SHIFT)
79 #define M2M_CONTROL_NO_HDSK BIT(24)
80 #define M2M_CONTROL_PWSC_SHIFT 25
82 #define M2M_INTERRUPT 0x0004
83 #define M2M_INTERRUPT_MASK 6
85 #define M2M_STATUS 0x000c
86 #define M2M_STATUS_CTL_SHIFT 1
87 #define M2M_STATUS_CTL_IDLE (0 << M2M_STATUS_CTL_SHIFT)
88 #define M2M_STATUS_CTL_STALL (1 << M2M_STATUS_CTL_SHIFT)
89 #define M2M_STATUS_CTL_MEMRD (2 << M2M_STATUS_CTL_SHIFT)
90 #define M2M_STATUS_CTL_MEMWR (3 << M2M_STATUS_CTL_SHIFT)
91 #define M2M_STATUS_CTL_BWCWAIT (4 << M2M_STATUS_CTL_SHIFT)
92 #define M2M_STATUS_CTL_MASK (7 << M2M_STATUS_CTL_SHIFT)
93 #define M2M_STATUS_BUF_SHIFT 4
94 #define M2M_STATUS_BUF_NO (0 << M2M_STATUS_BUF_SHIFT)
95 #define M2M_STATUS_BUF_ON (1 << M2M_STATUS_BUF_SHIFT)
96 #define M2M_STATUS_BUF_NEXT (2 << M2M_STATUS_BUF_SHIFT)
97 #define M2M_STATUS_BUF_MASK (3 << M2M_STATUS_BUF_SHIFT)
98 #define M2M_STATUS_DONE BIT(6)
100 #define M2M_BCR0 0x0010
101 #define M2M_BCR1 0x0014
102 #define M2M_SAR_BASE0 0x0018
103 #define M2M_SAR_BASE1 0x001c
104 #define M2M_DAR_BASE0 0x002c
105 #define M2M_DAR_BASE1 0x0030
107 #define DMA_MAX_CHAN_BYTES 0xffff
108 #define DMA_MAX_CHAN_DESCRIPTORS 32
174 #define EP93XX_DMA_IS_CYCLIC 0
207 #define INTERRUPT_UNKNOWN 0
208 #define INTERRUPT_DONE 1
209 #define INTERRUPT_NEXT_BUFFER 2
217 return &edmac->
chan.dev->device;
244 while (!list_empty(&desc->
tx_list)) {
254 d->
txd.callback = desc->
txd.callback;
255 d->
txd.callback_param = desc->
txd.callback_param;
265 if (list_empty(&edmac->
active))
287 list_rotate_left(&edmac->
active);
292 desc = ep93xx_dma_get_active(edmac);
300 return !desc->
txd.cookie;
326 m2p_set_control(edmac, control);
342 m2p_set_control(edmac, control);
347 m2p_set_control(edmac, 0);
358 desc = ep93xx_dma_get_active(edmac);
360 dev_warn(chan2dev(edmac),
"M2P: empty descriptor list\n");
384 m2p_fill_desc(edmac);
387 if (ep93xx_dma_advance_active(edmac)) {
388 m2p_fill_desc(edmac);
392 m2p_set_control(edmac, control);
415 "DMA transfer failed! Details:\n"
417 "\tsrc_addr : 0x%08x\n"
418 "\tdst_addr : 0x%08x\n"
429 m2p_set_control(edmac, control);
434 if (ep93xx_dma_advance_active(edmac))
435 m2p_fill_desc(edmac);
458 switch (data->
port) {
518 desc = ep93xx_dma_get_active(edmac);
520 dev_warn(chan2dev(edmac),
"M2M: empty descriptor list\n");
550 m2m_fill_desc(edmac);
553 if (ep93xx_dma_advance_active(edmac)) {
554 m2m_fill_desc(edmac);
608 desc = ep93xx_dma_get_active(edmac);
609 last_done = !desc || desc->
txd.cookie;
625 if (ep93xx_dma_advance_active(edmac)) {
626 m2m_fill_desc(edmac);
627 if (done && !edmac->
chan.private) {
673 if (async_tx_test_ack(&desc->
txd)) {
674 list_del_init(&desc->
node);
681 desc->
txd.cookie = 0;
683 desc->
txd.callback_param =
NULL;
689 spin_unlock_irqrestore(&edmac->
lock, flags);
702 spin_unlock_irqrestore(&edmac->
lock, flags);
720 if (!list_empty(&edmac->
active) || list_empty(&edmac->
queue)) {
721 spin_unlock_irqrestore(&edmac->
lock, flags);
727 list_del_init(&new->node);
729 ep93xx_dma_set_active(edmac,
new);
732 edmac->
edma->hw_submit(edmac);
733 spin_unlock_irqrestore(&edmac->
lock, flags);
758 static void ep93xx_dma_tasklet(
unsigned long data)
763 void *callback_param =
NULL;
766 spin_lock_irq(&edmac->
lock);
772 desc = ep93xx_dma_get_active(edmac);
777 dma_cookie_complete(&desc->
txd);
780 callback = desc->
txd.callback;
781 callback_param = desc->
txd.callback_param;
783 spin_unlock_irq(&edmac->
lock);
786 ep93xx_dma_advance_work(edmac);
794 if (!edmac->
chan.private)
795 ep93xx_dma_unmap_buffers(desc);
797 ep93xx_dma_desc_put(edmac, desc);
810 spin_lock(&edmac->
lock);
812 desc = ep93xx_dma_get_active(edmac);
815 "got interrupt while active list is empty\n");
816 spin_unlock(&edmac->
lock);
820 switch (edmac->
edma->hw_interrupt(edmac)) {
823 tasklet_schedule(&edmac->
tasklet);
828 tasklet_schedule(&edmac->
tasklet);
832 dev_warn(chan2dev(edmac),
"unknown interrupt!\n");
837 spin_unlock(&edmac->
lock);
857 cookie = dma_cookie_assign(tx);
866 if (list_empty(&edmac->
active)) {
867 ep93xx_dma_set_active(edmac, desc);
868 edmac->
edma->hw_submit(edmac);
873 spin_unlock_irqrestore(&edmac->
lock, flags);
885 static int ep93xx_dma_alloc_chan_resources(
struct dma_chan *
chan)
889 const char *
name = dma_chan_name(chan);
893 if (!edmac->
edma->m2m) {
899 if (data->
direction != ep93xx_dma_chan_direction(chan))
903 switch (data->
port) {
916 if (data && data->
name)
923 ret =
request_irq(edmac->
irq, ep93xx_dma_interrupt, 0, name, edmac);
925 goto fail_clk_disable;
927 spin_lock_irq(&edmac->
lock);
928 dma_cookie_init(&edmac->
chan);
929 ret = edmac->
edma->hw_setup(edmac);
930 spin_unlock_irq(&edmac->
lock);
940 dev_warn(chan2dev(edmac),
"not enough descriptors\n");
944 INIT_LIST_HEAD(&desc->
tx_list);
948 desc->
txd.tx_submit = ep93xx_dma_tx_submit;
950 ep93xx_dma_desc_put(edmac, desc);
970 static void ep93xx_dma_free_chan_resources(
struct dma_chan *chan)
981 edmac->
edma->hw_shutdown(edmac);
986 spin_unlock_irqrestore(&edmac->
lock, flags);
1014 for (offset = 0; offset < len; offset +=
bytes) {
1015 desc = ep93xx_dma_desc_get(edmac);
1017 dev_warn(chan2dev(edmac),
"couln't get descriptor\n");
1038 ep93xx_dma_desc_put(edmac, first);
1056 unsigned long flags,
void *
context)
1063 if (!edmac->
edma->m2m && dir != ep93xx_dma_chan_direction(chan)) {
1065 "channel was configured with different direction\n");
1071 "channel is already used for cyclic transfers\n");
1080 dev_warn(chan2dev(edmac),
"too big transfer size %d\n",
1085 desc = ep93xx_dma_desc_get(edmac);
1087 dev_warn(chan2dev(edmac),
"couln't get descriptor\n");
1098 desc->
size = sg_len;
1112 ep93xx_dma_desc_put(edmac, first);
1136 size_t buf_len,
size_t period_len,
1144 if (!edmac->
edma->m2m && dir != ep93xx_dma_chan_direction(chan)) {
1146 "channel was configured with different direction\n");
1152 "channel is already used for cyclic transfers\n");
1157 dev_warn(chan2dev(edmac),
"too big period length %d\n",
1164 for (offset = 0; offset < buf_len; offset += period_len) {
1165 desc = ep93xx_dma_desc_get(edmac);
1167 dev_warn(chan2dev(edmac),
"couln't get descriptor\n");
1179 desc->
size = period_len;
1192 ep93xx_dma_desc_put(edmac, first);
1206 unsigned long flags;
1211 edmac->
edma->hw_shutdown(edmac);
1219 edmac->
edma->hw_setup(edmac);
1220 spin_unlock_irqrestore(&edmac->
lock, flags);
1223 ep93xx_dma_desc_put(edmac, desc);
1232 unsigned long flags;
1235 if (!edmac->edma->m2m)
1238 switch (config->direction) {
1240 width = config->src_addr_width;
1241 addr = config->src_addr;
1245 width = config->dst_addr_width;
1246 addr = config->dst_addr;
1268 edmac->runtime_addr =
addr;
1269 edmac->runtime_ctrl =
ctrl;
1270 spin_unlock_irqrestore(&edmac->lock, flags);
1292 return ep93xx_dma_terminate_all(edmac);
1296 return ep93xx_dma_slave_config(edmac, config);
1319 unsigned long flags;
1322 ret = dma_cookie_status(chan, cookie, state);
1323 spin_unlock_irqrestore(&edmac->
lock, flags);
1335 static void ep93xx_dma_issue_pending(
struct dma_chan *chan)
1337 ep93xx_dma_advance_work(to_ep93xx_dma_chan(chan));
1349 edma = kzalloc(
sizeof(*edma) + edma_size,
GFP_KERNEL);
1357 INIT_LIST_HEAD(&dma_dev->
channels);
1362 edmac->
chan.device = dma_dev;
1368 if (IS_ERR(edmac->
clk)) {
1369 dev_warn(&pdev->
dev,
"failed to get clock for %s\n",
1375 INIT_LIST_HEAD(&edmac->
active);
1376 INIT_LIST_HEAD(&edmac->
queue);
1379 (
unsigned long)edmac);
1389 dma_dev->
dev = &pdev->
dev;
1421 if (!IS_ERR_OR_NULL(edmac->
clk))
1427 edma->
m2m ?
"M" :
"P");
1434 {
"ep93xx-dma-m2p", 0 },
1435 {
"ep93xx-dma-m2m", 1 },
1441 .name =
"ep93xx-dma",
1443 .id_table = ep93xx_dma_driver_ids,
1446 static int __init ep93xx_dma_module_init(
void)