11 #include <linux/module.h>
12 #include <linux/kernel.h>
15 #include <linux/slab.h>
18 #include <linux/device.h>
29 #define COHC_2_DEV(cohc) (&cohc->chan.dev->device)
32 #define COH_DBG(x) ({ if (1) x; 0; })
34 #define COH_DBG(x) ({ if (0) x; 0; })
92 ", dst 0x%x, link 0x%x virt_link_addr 0x%p\n",
100 #ifdef CONFIG_DEBUG_FS
102 #define COH901318_DEBUGFS_ASSIGN(x, y) (x = y)
105 static struct dentry *dma_dentry;
107 static int coh901318_debugfs_read(
struct file *
file,
char __user *
buf,
108 size_t count, loff_t *f_pos)
110 u64 started_channels = debugfs_dma_base->
pm.started_channels;
111 int pool_count = debugfs_dma_base->
pool.debugfs_pool_counter;
123 tmp +=
sprintf(tmp,
"DMA -- enabled dma channels\n");
125 for (i = 0; i < debugfs_dma_base->
platform->max_channels; i++)
126 if (started_channels & (1 << i))
127 tmp +=
sprintf(tmp,
"channel %d\n", i);
129 tmp +=
sprintf(tmp,
"Pool alloc nbr %d\n", pool_count);
130 dev_size = tmp - dev_buf;
133 if (*f_pos > dev_size)
136 if (count > dev_size - *f_pos)
137 count = dev_size - *f_pos;
152 static const struct file_operations coh901318_debugfs_status_operations = {
155 .read = coh901318_debugfs_read,
160 static int __init init_coh901318_debugfs(
void)
168 &coh901318_debugfs_status_operations);
172 static void __exit exit_coh901318_debugfs(
void)
181 #define COH901318_DEBUGFS_ASSIGN(x, y)
196 return cohc->
base->platform->chan_conf[cohc->
id].dev_addr;
202 return &cohc->
base->platform->chan_conf[cohc->
id].param;
208 return &cohc->
base->platform->chan_conf[cohc->
id];
222 cohc->
base->platform->access_memory_state(cohc->
base->dev,
226 spin_unlock_irqrestore(&pm->
lock, flags);
237 cohc->
base->platform->access_memory_state(cohc->
base->dev,
243 spin_unlock_irqrestore(&pm->
lock, flags);
275 disable_powersave(cohc);
288 static int coh901318_prep_linked_list(
struct coh901318_chan *cohc,
320 if (list_empty(&cohc->
free)) {
328 INIT_LIST_HEAD(&desc->
node);
365 if (list_empty(&cohc->
active))
391 if (list_empty(&cohc->
queue))
478 left += coh901318_get_bytes_in_lli(lli);
480 left += coh901318_get_bytes_in_lli(cohd->
lli);
488 left += coh901318_get_bytes_in_lli(cohd->
lli);
491 spin_unlock_irqrestore(&cohc->
lock, flags);
500 static void coh901318_pause(
struct dma_chan *chan)
505 int channel = cohc->
id;
520 val &= ~COH901318_CX_CFG_CH_ENABLE;
537 enable_powersave(cohc);
539 spin_unlock_irqrestore(&cohc->
lock, flags);
545 static void coh901318_resume(
struct dma_chan *chan)
550 int channel = cohc->
id;
554 disable_powersave(cohc);
569 spin_unlock_irqrestore(&cohc->
lock, flags);
574 unsigned int ch_nr = (
unsigned int) chan_id;
576 if (ch_nr == to_coh901318_chan(chan)->id)
591 int channel = cohc->
id;
599 p = &cohc->
base->platform->chan_conf[
channel].param;
606 writel(1 << (channel - 32), virtbase +
608 writel(1 << (channel - 32), virtbase +
612 coh901318_set_conf(cohc, p->
config);
615 spin_unlock_irqrestore(&cohc->
lock, flags);
635 cohd = coh901318_first_queued(cohc);
639 coh901318_desc_remove(cohd);
643 coh901318_desc_submit(cohc, cohd);
647 coh901318_set_ctrl(cohc, cohd->
head_ctrl);
648 coh901318_prep_linked_list(cohc, cohd->
lli);
651 coh901318_start(cohc);
662 static void dma_tasklet(
unsigned long data)
668 void *callback_param;
671 " nbr_active_done %ld\n", __func__,
677 cohd_fin = coh901318_first_active_get(cohc);
679 if (cohd_fin ==
NULL)
683 callback = cohd_fin->
desc.callback;
684 callback_param = cohd_fin->
desc.callback_param;
687 dma_cookie_complete(&cohd_fin->
desc);
693 coh901318_desc_remove(cohd_fin);
694 coh901318_desc_free(cohc, cohd_fin);
696 spin_unlock_irqrestore(&cohc->
lock, flags);
714 "came in while we were scheduling this tasklet\n");
715 if (cohc_chan_conf(cohc)->priority_high)
716 tasklet_hi_schedule(&cohc->
tasklet);
718 tasklet_schedule(&cohc->
tasklet);
721 spin_unlock_irqrestore(&cohc->
lock, flags);
726 spin_unlock_irqrestore(&cohc->
lock, flags);
740 "unallocated channel\n");
744 spin_lock(&cohc->
lock);
763 if (coh901318_queue_start(cohc) ==
NULL)
766 spin_unlock(&cohc->
lock);
772 if (cohc_chan_conf(cohc)->priority_high)
773 tasklet_hi_schedule(&cohc->
tasklet);
775 tasklet_schedule(&cohc->
tasklet);
792 if (
unlikely(status1 == 0 && status2 == 0)) {
793 dev_warn(base->
dev,
"spurious DMA IRQ from no channel!\n");
803 i =
ffs(status1) - 1;
806 cohc = &base->
chans[ch];
807 spin_lock(&cohc->
lock);
810 status1 &= ~(1 <<
i);
814 "DMA bus error on channel %d!\n", ch);
823 "ignoring interrupt not caused by terminal count on channel %d\n", ch);
832 enable_powersave(cohc);
844 spin_unlock(&cohc->
lock);
850 i =
ffs(status2) - 1;
852 cohc = &base->
chans[ch];
853 spin_lock(&cohc->
lock);
856 status2 &= ~(1 <<
i);
860 "DMA bus error on channel %d!\n", ch);
869 "ignoring interrupt not caused by terminal count on channel %d\n", ch);
878 enable_powersave(cohc);
889 spin_unlock(&cohc->
lock);
895 static int coh901318_alloc_chan_resources(
struct dma_chan *chan)
908 coh901318_config(cohc,
NULL);
911 dma_cookie_init(chan);
913 spin_unlock_irqrestore(&cohc->
lock, flags);
919 coh901318_free_chan_resources(
struct dma_chan *chan)
922 int channel = cohc->
id;
935 spin_unlock_irqrestore(&cohc->
lock, flags);
951 cookie = dma_cookie_assign(tx);
953 coh901318_desc_queue(cohc, cohd);
955 spin_unlock_irqrestore(&cohc->
lock, flags);
962 size_t size,
unsigned long flags)
969 u32 ctrl_last = cohc_chan_param(cohc)->ctrl_lli_last;
975 "[%s] channel %d src 0x%x dest 0x%x size %d\n",
976 __func__, cohc->
id, src, dest, size);
983 if ((lli_len << MAX_DMA_PACKET_SIZE_SHIFT) < size)
992 &cohc->
base->pool, lli, src, size, dest,
993 cohc_chan_param(cohc)->ctrl_lli_chained,
998 COH_DBG(coh901318_list_print(cohc, lli));
1001 cohd = coh901318_desc_get(cohc);
1004 cohd->
desc.tx_submit = coh901318_tx_submit;
1006 spin_unlock_irqrestore(&cohc->
lock, flg);
1010 spin_unlock_irqrestore(&cohc->
lock, flg);
1017 unsigned long flags,
void *
context)
1027 u32 ctrl_chained = cohc_chan_param(cohc)->ctrl_lli_chained;
1028 u32 ctrl = cohc_chan_param(cohc)->ctrl_lli;
1029 u32 ctrl_last = cohc_chan_param(cohc)->ctrl_lli_last;
1042 __func__, sg_len, direction);
1044 if (flags & DMA_PREP_INTERRUPT)
1048 params = cohc_chan_param(cohc);
1064 ctrl_chained |= tx_flags;
1065 ctrl_last |= tx_flags;
1072 ctrl_chained |= rx_flags;
1073 ctrl_last |= rx_flags;
1083 unsigned int factor;
1092 if ((factor << MAX_DMA_PACKET_SIZE_SHIFT) < size)
1098 pr_debug(
"Allocate %d lli:s for this transfer\n", len);
1106 cohc_dev_addr(cohc),
1115 COH_DBG(coh901318_list_print(cohc, lli));
1118 cohd = coh901318_desc_get(cohc);
1128 cohd->
desc.tx_submit = coh901318_tx_submit;
1131 spin_unlock_irqrestore(&cohc->
lock, flg);
1137 spin_unlock_irqrestore(&cohc->
lock, flg);
1149 ret = dma_cookie_status(chan, cookie, txstate);
1151 dma_set_residue(txstate, coh901318_get_bytes_left(chan));
1160 coh901318_issue_pending(
struct dma_chan *chan)
1163 unsigned long flags;
1174 coh901318_queue_start(cohc);
1176 spin_unlock_irqrestore(&cohc->
lock, flags);
1240 static void coh901318_dma_set_runtimeconfig(
struct dma_chan *chan,
1266 switch (addr_width) {
1273 if (burst_sizes[i].burst_8bit <= maxburst)
1285 if (burst_sizes[i].burst_16bit <= maxburst)
1298 if (burst_sizes[i].burst_32bit <= maxburst)
1306 "bad runtimeconfig: alien address width\n");
1310 runtime_ctrl |= burst_sizes[
i].
reg;
1312 "selected burst size %d bytes for address width %d bytes, maxburst %d\n",
1313 burst_sizes[i].burst_8bit, addr_width, maxburst);
1323 unsigned long flags;
1332 coh901318_dma_set_runtimeconfig(chan, config);
1337 coh901318_pause(chan);
1342 coh901318_resume(chan);
1350 coh901318_pause(chan);
1354 if (cohc->
id < 32) {
1358 writel(1 << (cohc->
id - 32), virtbase +
1360 writel(1 << (cohc->
id - 32), virtbase +
1364 enable_powersave(cohc);
1366 while ((cohd = coh901318_first_active_get(cohc))) {
1371 coh901318_desc_remove(cohd);
1372 coh901318_desc_free(cohc, cohd);
1375 while ((cohd = coh901318_first_queued(cohc))) {
1380 coh901318_desc_remove(cohd);
1381 coh901318_desc_free(cohc, cohd);
1388 spin_unlock_irqrestore(&cohc->
lock, flags);
1402 for (chans_i = 0; pick_chans[chans_i] != -1; chans_i += 2) {
1403 for (i = pick_chans[chans_i]; i <= pick_chans[chans_i+1]; i++) {
1418 INIT_LIST_HEAD(&cohc->
free);
1419 INIT_LIST_HEAD(&cohc->
active);
1420 INIT_LIST_HEAD(&cohc->
queue);
1423 (
unsigned long) cohc);
1447 pdev->
dev.driver->name) ==
NULL)
1450 pdata = pdev->
dev.platform_data;
1471 base->
pm.started_channels = 0;
1497 base->
dma_slave.device_alloc_chan_resources = coh901318_alloc_chan_resources;
1498 base->
dma_slave.device_free_chan_resources = coh901318_free_chan_resources;
1499 base->
dma_slave.device_prep_slave_sg = coh901318_prep_slave_sg;
1500 base->
dma_slave.device_tx_status = coh901318_tx_status;
1501 base->
dma_slave.device_issue_pending = coh901318_issue_pending;
1502 base->
dma_slave.device_control = coh901318_control;
1508 goto err_register_slave;
1517 base->
dma_memcpy.device_alloc_chan_resources = coh901318_alloc_chan_resources;
1518 base->
dma_memcpy.device_free_chan_resources = coh901318_free_chan_resources;
1519 base->
dma_memcpy.device_prep_dma_memcpy = coh901318_prep_memcpy;
1520 base->
dma_memcpy.device_tx_status = coh901318_tx_status;
1521 base->
dma_memcpy.device_issue_pending = coh901318_issue_pending;
1522 base->
dma_memcpy.device_control = coh901318_control;
1532 goto err_register_memcpy;
1534 platform_set_drvdata(pdev, base);
1535 dev_info(&pdev->
dev,
"Initialized COH901318 DMA on virtual base 0x%08x\n",
1540 err_register_memcpy:
1559 .remove =
__exit_p(coh901318_remove),
1561 .name =
"coh901318",