16 #include <linux/module.h>
21 #include <cpu/dma-register.h>
28 #define RS_DUAL (DM_INC | SM_INC | 0x400 | TS_INDEX2VAL(XMIT_SZ_32BIT))
30 static unsigned long dma_find_base(
unsigned int chan)
44 unsigned long base = dma_find_base(chan);
52 return base + (chan * 0x10);
55 #ifdef CONFIG_SH_DMA_IRQ_MULTI
56 static inline unsigned int get_dmte_irq(
unsigned int chan)
62 static unsigned int dmte_irq_map[] = {
78 static inline unsigned int get_dmte_irq(
unsigned int chan)
80 return dmte_irq_map[chan];
92 static unsigned int ts_shift[] =
TS_SHIFT;
94 static inline unsigned int calc_xmit_shift(
struct dma_channel *chan)
100 return ts_shift[
cnt];
127 static int sh_dmac_request_dma(
struct dma_channel *chan)
129 if (
unlikely(!(chan->flags & DMA_TEI_CAPABLE)))
136 static void sh_dmac_free_dma(
struct dma_channel *chan)
138 free_irq(get_dmte_irq(chan->chan), chan);
142 sh_dmac_configure_channel(
struct dma_channel *chan,
unsigned long chcr)
149 chan->flags |= DMA_TEI_CAPABLE;
151 chan->flags &= ~DMA_TEI_CAPABLE;
156 chan->flags |= DMA_CONFIGURED;
160 static void sh_dmac_enable_dma(
struct dma_channel *chan)
168 if (chan->flags & DMA_TEI_CAPABLE)
173 if (chan->flags & DMA_TEI_CAPABLE) {
174 irq = get_dmte_irq(chan->chan);
179 static void sh_dmac_disable_dma(
struct dma_channel *chan)
184 if (chan->flags & DMA_TEI_CAPABLE) {
185 irq = get_dmte_irq(chan->chan);
194 static int sh_dmac_xfer_dma(
struct dma_channel *chan)
200 if (
unlikely(!(chan->flags & DMA_CONFIGURED)))
201 sh_dmac_configure_channel(chan, 0);
203 sh_dmac_disable_dma(chan);
220 if (chan->sar || (mach_is_dreamcast() &&
223 if (chan->dar || (mach_is_dreamcast() &&
230 sh_dmac_enable_dma(chan);
235 static int sh_dmac_get_dma_residue(
struct dma_channel *chan)
241 << calc_xmit_shift(chan);
247 #if defined(CONFIG_CPU_SUBTYPE_SH7723) || \
248 defined(CONFIG_CPU_SUBTYPE_SH7724) || \
249 defined(CONFIG_CPU_SUBTYPE_SH7780) || \
250 defined(CONFIG_CPU_SUBTYPE_SH7785)
260 #define dmaor_read_reg(n) __raw_readw(dma_find_base((n)*6))
261 #define dmaor_write_reg(n, data) __raw_writew(data, dma_find_base(n)*6)
263 static inline int dmaor_reset(
int no)
286 #ifdef CONFIG_CPU_SH4
288 #if defined(DMAE1_IRQ)
294 static const char *dmae_name[] = {
295 "DMAC Address Error0",
296 "DMAC Address Error1"
299 #ifdef CONFIG_SH_DMA_IRQ_MULTI
300 static inline unsigned int get_dma_error_irq(
int n)
302 return get_dmte_irq(n * 6);
306 static unsigned int dmae_irq_map[] = {
314 static inline unsigned int get_dma_error_irq(
int n)
316 return dmae_irq_map[
n];
332 static int dmae_irq_init(
void)
336 for (n = 0; n < NR_DMAE; n++) {
348 static void dmae_irq_free(
void)
352 for (n = 0; n < NR_DMAE; n++)
356 static inline int dmae_irq_init(
void)
361 static void dmae_irq_free(
void)
366 static struct dma_ops sh_dmac_ops = {
367 .request = sh_dmac_request_dma,
368 .free = sh_dmac_free_dma,
369 .get_residue = sh_dmac_get_dma_residue,
370 .xfer = sh_dmac_xfer_dma,
371 .configure = sh_dmac_configure_channel,
374 static struct dma_info sh_dmac_info = {
376 .nr_channels = CONFIG_NR_ONCHIP_DMA_CHANNELS,
378 .flags = DMAC_CHANNELS_TEI_CAPABLE,
381 static int __init sh_dmac_init(
void)
389 rc = dmae_irq_init();
406 static void __exit sh_dmac_exit(
void)