16 #ifdef CONFIG_S3C2410_DMA_DEBUG
20 #include <linux/module.h>
22 #include <linux/sched.h>
26 #include <linux/slab.h>
27 #include <linux/errno.h>
31 #include <mach/hardware.h>
42 static int dma_channels;
49 #define BUF_MAGIC (0xcafebabe)
51 #define dmawarn(fmt...) printk(KERN_DEBUG fmt)
53 #define dma_regaddr(chan, reg) ((chan)->regs + (reg))
56 #define dma_wrreg(chan, reg, val) writel((val), (chan)->regs + (reg))
61 pr_debug(
"writing %08x to register %08x\n",(
unsigned int)val,reg);
66 #define dma_rdreg(chan, reg) readl((chan)->regs + (reg))
78 #ifdef CONFIG_S3C2410_DMA_DEBUG
99 printk(
KERN_DEBUG "dma%d: %s:%d: DCSRC=%08lx, DISRC=%08lx, DSTAT=%08lx DMT=%02lx, DCON=%08lx\n",
100 chan->
number, fname, line,
110 dmadbg_capture(chan, &
state);
116 dmadbg_dumpregs(fname, line, chan, &
state);
124 dmadbg_capture(chan, &
state);
125 dmadbg_dumpregs(fname, line, chan, &
state);
128 #define dbg_showregs(chan) dmadbg_showregs(__func__, __LINE__, (chan))
129 #define dbg_showchan(chan) dmadbg_showchan(__func__, __LINE__, (chan))
131 #define dbg_showregs(chan) do { } while(0)
132 #define dbg_showchan(chan) do { } while(0)
148 if (val < stats->timeout_shortest)
171 chan->
stats->loads++;
173 while (--timeout > 0) {
177 s3c2410_dma_stats_timeout(chan->
stats, took);
193 chan->
stats->timeout_failed++;
208 unsigned long reload;
215 pr_debug(
"s3c2410_chan_loadbuffer: loading buff %p (0x%08lx,0x%06x)\n",
216 buf, (
unsigned long)buf->
data, buf->
size);
221 dmawarn(
"load_state is S3C2410_DMALOAD_1LOADED\n");
225 dmawarn(
"state is S3C2410_DMALOAD_1LOADED_1RUNNING\n");
233 pr_debug(
"load_state is none, checking for noreload (next=%p)\n",
241 if ((buf->
data & 0xf0000000) != 0x30000000) {
242 dmawarn(
"dmaload: buffer is %p\n", (
void *)buf->
data);
264 dmawarn(
"dmaload: unknown state %d in loadbuffer\n",
282 (chan->
op_fn)(chan, op);
297 pr_debug(
"callback_fn=%p, buf=%p, id=%p, size=%d, result=%d\n",
321 pr_debug(
"s3c2410_start_dma: already running (%d)\n", chan->
state);
341 s3c2410_dma_loadbuffer(chan, chan->
next);
382 if (s3c2410_dma_waitforload(chan, __LINE__) == 0) {
383 pr_debug(
"%s: buff not yet loaded, no more todo\n",
387 s3c2410_dma_loadbuffer(chan, chan->
next);
391 s3c2410_dma_loadbuffer(chan, chan->
next);
443 pr_debug(
"%s: id=%p, data=%08x, size=%d\n",
444 __func__,
id, (
unsigned int)data, size);
448 pr_debug(
"%s: out of memory (%ld alloc)\n",
449 __func__, (
long)
sizeof(*buf));
466 pr_debug(
"%s: buffer %p queued onto empty channel\n",
473 pr_debug(
"dma%d: %s: buffer %p queued onto non-empty channel\n",
474 chan->
number, __func__, buf);
477 pr_debug(
"dma%d: %s: %p not empty, and chan->end==NULL?\n",
478 chan->
number, __func__, chan);
492 if (s3c2410_dma_waitforload(chan, __LINE__) == 0) {
494 "timeout loading buffer\n",
502 while (s3c2410_dma_canload(chan) && chan->
next !=
NULL) {
503 s3c2410_dma_loadbuffer(chan, chan->
next);
528 printk(
"s3c2410_dma_freebuf: buff %p with bad magic\n", buf);
542 pr_debug(
"dma%d: s3c2410_dma_lastxfer: load_state %d\n",
551 if (s3c2410_dma_waitforload(chan, __LINE__) == 0) {
566 pr_debug(
"dma%d: lastxfer: unhandled load_state %d with no next\n",
577 #define dmadbg2(x...)
580 s3c2410_dma_irq(
int irq,
void *devpw)
640 chan->
number, __func__, buf);
647 s3c2410_dma_freebuf(buf);
671 if (s3c2410_dma_waitforload(chan, __LINE__) == 0) {
690 s3c2410_dma_loadbuffer(chan, chan->
next);
693 s3c2410_dma_lastxfer(chan);
697 pr_debug(
"dma%d: end of transfer, stopping channel (%ld)\n",
723 pr_debug(
"dma%d: s3c2410_request_dma: client=%s, dev=%p\n",
724 channel, client->
name, dev);
728 chan = s3c2410_dma_map_channel(channel);
740 pr_debug(
"dma%d: %s : requesting irq %d\n",
741 channel, __func__, chan->
irq);
747 client->
name, (
void *)chan);
768 pr_debug(
"%s: channel initialised, %p\n", __func__, chan);
796 if (chan->
client != client) {
797 printk(
KERN_WARNING "dma%d: possible free from different client (channel %p, passed %p)\n",
798 channel, chan->
client, client);
804 pr_debug(
"%s: need to stop dma channel %p\n",
866 unsigned int timeout = 0x10000;
868 while (timeout-- > 0) {
896 pr_debug(
"%s: stopping channel...\n", __func__ );
910 pr_debug(
"%s: free buffer %p, next %p\n",
911 __func__, buf, buf->
next);
914 s3c2410_dma_freebuf(buf);
920 s3c2410_dma_waitforstop(chan);
956 if (s3c2410_dma_waitforload(chan, __LINE__) == 0) {
957 pr_debug(
"%s: buff not yet loaded, no more todo\n",
961 s3c2410_dma_loadbuffer(chan, chan->
next);
965 s3c2410_dma_loadbuffer(chan, chan->
next);
986 return s3c2410_dma_start(chan);
989 return s3c2410_dma_dostop(chan);
996 return s3c2410_dma_flush(chan);
999 return s3c2410_dma_started(chan);
1030 pr_debug(
"%s: chan=%d, xfer_unit=%d\n", __func__, channel, xferunit);
1035 dcon = chan->
dcon & dma_sel.dcon_mask;
1036 pr_debug(
"%s: dcon is %08x\n", __func__, dcon);
1075 pr_debug(
"%s: bad transfer size %d\n", __func__, xferunit);
1082 pr_debug(
"%s: dcon now %08x\n", __func__, dcon);
1105 unsigned long devaddr)
1113 pr_debug(
"%s: source=%d, devaddr=%08lx\n",
1114 __func__, (
int)source, devaddr);
1136 pr_debug(
"%s: hw source, devaddr=%08lx, hwcfg=%d\n",
1137 __func__, devaddr, hwcfg);
1147 pr_debug(
"%s: mem source, devaddr=%08lx, hwcfg=%d\n",
1148 __func__, devaddr, hwcfg);
1163 if (dma_sel.direction !=
NULL)
1164 (dma_sel.direction)(chan, chan->
map, source);
1212 s3c2410_dma_dostop(cp);
1221 for (channel = 0; channel < dma_channels; cp++, channel++)
1222 s3c2410_dma_suspend_chan(cp);
1244 dma_sel.select(cp, cp->
map);
1252 for (channel = dma_channels - 1; channel >= 0; cp--, channel--)
1253 s3c2410_dma_resume_chan(cp);
1257 #define s3c2410_dma_suspend NULL
1258 #define s3c2410_dma_resume NULL
1268 static void s3c2410_dma_cache_ctor(
void *
p)
1275 static int __init s3c24xx_dma_syscore_init(
void)
1285 unsigned int stride)
1291 printk(
"S3C24XX DMA Driver, Copyright 2003-2006 Simtec Electronics\n");
1296 if (dma_base ==
NULL) {
1304 s3c2410_dma_cache_ctor);
1306 if (dma_kmem ==
NULL) {
1312 for (channel = 0; channel <
channels; channel++) {
1320 cp->
regs = dma_base + (channel * stride);
1330 printk(
"DMA channel %d at %p, irq %d\n",
1348 static inline int is_channel_valid(
unsigned int channel)
1373 if (dma_sel.map ==
NULL || channel > dma_sel.map_size)
1376 ch_map = dma_sel.map +
channel;
1383 for (ch = 0; ch < dma_channels; ch++) {
1385 if (!is_channel_valid(ord->
list[ch]))
1401 for (ch = 0; ch < dma_channels; ch++) {
1402 if (!is_channel_valid(ch_map->
channels[ch]))
1406 printk(
"mapped channel %d to %d\n", channel, ch);
1411 if (ch >= dma_channels)
1418 dmach->
map = ch_map;
1424 (dma_sel.select)(dmach, ch_map);
1437 size_t map_sz =
sizeof(*nmap) * sel->
map_size;
1444 memcpy(&dma_sel, sel,
sizeof(*sel));
1448 for (ptr = 0; ptr < sel->
map_size; ptr++)
1449 s3c24xx_dma_check_entry(nmap+ptr, ptr);