2 * arch/sh/drivers/dma/dma-sh.c
4 * SuperH On-chip DMAC Support
6 * Copyright (C) 2000 Takashi YOSHII
7 * Copyright (C) 2003, 2004 Paul Mundt
9 * This file is subject to the terms and conditions of the GNU General Public
10 * License. See the file "COPYING" in the main directory of this archive
14 #include <linux/config.h>
15 #include <linux/init.h>
16 #include <linux/irq.h>
17 #include <linux/interrupt.h>
18 #include <linux/module.h>
19 #include <asm/signal.h>
26 * The SuperH DMAC supports a number of transmit sizes, we list them here,
27 * with their respective values as they appear in the CHCR registers.
29 * Defaults to a 64-bit transfer size.
40 * The DMA count is defined as the number of bytes to transfer.
42 static unsigned int ts_shift
[] = {
50 static inline unsigned int get_dmte_irq(unsigned int chan
)
55 * Normally we could just do DMTE0_IRQ + chan outright, though in the
56 * case of the 7751R, the DMTE IRQs for channels > 4 start right above
61 irq
= DMTE0_IRQ
+ chan
;
63 irq
= DMTE4_IRQ
+ chan
- 4;
70 * We determine the correct shift size based off of the CHCR transmit size
71 * for the given channel. Since we know that it will take:
73 * info->count >> ts_shift[transmit_size]
75 * iterations to complete the transfer.
77 static inline unsigned int calc_xmit_shift(struct dma_channel
*chan
)
79 u32 chcr
= ctrl_inl(CHCR
[chan
->chan
]);
83 return ts_shift
[chcr
& 0x0007];
87 * The transfer end interrupt must read the chcr register to end the
88 * hardware interrupt active condition.
89 * Besides that it needs to waken any waiting process, which should handle
90 * setting up the next transfer.
92 static irqreturn_t
dma_tei(int irq
, void *dev_id
, struct pt_regs
*regs
)
94 struct dma_channel
*chan
= (struct dma_channel
*)dev_id
;
97 chcr
= ctrl_inl(CHCR
[chan
->chan
]);
99 if (!(chcr
& CHCR_TE
))
102 chcr
&= ~(CHCR_IE
| CHCR_DE
);
103 ctrl_outl(chcr
, CHCR
[chan
->chan
]);
105 wake_up(&chan
->wait_queue
);
110 static int sh_dmac_request_dma(struct dma_channel
*chan
)
112 return request_irq(get_dmte_irq(chan
->chan
), dma_tei
,
113 SA_INTERRUPT
, "DMAC Transfer End", chan
);
116 static void sh_dmac_free_dma(struct dma_channel
*chan
)
118 free_irq(get_dmte_irq(chan
->chan
), chan
);
121 static void sh_dmac_configure_channel(struct dma_channel
*chan
, unsigned long chcr
)
126 ctrl_outl(chcr
, CHCR
[chan
->chan
]);
128 chan
->flags
|= DMA_CONFIGURED
;
131 static void sh_dmac_enable_dma(struct dma_channel
*chan
)
133 int irq
= get_dmte_irq(chan
->chan
);
136 chcr
= ctrl_inl(CHCR
[chan
->chan
]);
137 chcr
|= CHCR_DE
| CHCR_IE
;
138 ctrl_outl(chcr
, CHCR
[chan
->chan
]);
143 static void sh_dmac_disable_dma(struct dma_channel
*chan
)
145 int irq
= get_dmte_irq(chan
->chan
);
150 chcr
= ctrl_inl(CHCR
[chan
->chan
]);
151 chcr
&= ~(CHCR_DE
| CHCR_TE
| CHCR_IE
);
152 ctrl_outl(chcr
, CHCR
[chan
->chan
]);
155 static int sh_dmac_xfer_dma(struct dma_channel
*chan
)
158 * If we haven't pre-configured the channel with special flags, use
161 if (!(chan
->flags
& DMA_CONFIGURED
))
162 sh_dmac_configure_channel(chan
, 0);
164 sh_dmac_disable_dma(chan
);
167 * Single-address mode usage note!
169 * It's important that we don't accidentally write any value to SAR/DAR
170 * (this includes 0) that hasn't been directly specified by the user if
171 * we're in single-address mode.
173 * In this case, only one address can be defined, anything else will
174 * result in a DMA address error interrupt (at least on the SH-4),
175 * which will subsequently halt the transfer.
177 * Channel 2 on the Dreamcast is a special case, as this is used for
178 * cascading to the PVR2 DMAC. In this case, we still need to write
179 * SAR and DAR, regardless of value, in order for cascading to work.
181 if (chan
->sar
|| (mach_is_dreamcast() && chan
->chan
== 2))
182 ctrl_outl(chan
->sar
, SAR
[chan
->chan
]);
183 if (chan
->dar
|| (mach_is_dreamcast() && chan
->chan
== 2))
184 ctrl_outl(chan
->dar
, DAR
[chan
->chan
]);
186 ctrl_outl(chan
->count
>> calc_xmit_shift(chan
), DMATCR
[chan
->chan
]);
188 sh_dmac_enable_dma(chan
);
193 static int sh_dmac_get_dma_residue(struct dma_channel
*chan
)
195 if (!(ctrl_inl(CHCR
[chan
->chan
]) & CHCR_DE
))
198 return ctrl_inl(DMATCR
[chan
->chan
]) << calc_xmit_shift(chan
);
201 #if defined(CONFIG_CPU_SH4)
202 static irqreturn_t
dma_err(int irq
, void *dev_id
, struct pt_regs
*regs
)
204 unsigned long dmaor
= ctrl_inl(DMAOR
);
206 printk("DMAE: DMAOR=%lx\n", dmaor
);
208 ctrl_outl(ctrl_inl(DMAOR
)&~DMAOR_NMIF
, DMAOR
);
209 ctrl_outl(ctrl_inl(DMAOR
)&~DMAOR_AE
, DMAOR
);
210 ctrl_outl(ctrl_inl(DMAOR
)|DMAOR_DME
, DMAOR
);
218 static struct dma_ops sh_dmac_ops
= {
219 .request
= sh_dmac_request_dma
,
220 .free
= sh_dmac_free_dma
,
221 .get_residue
= sh_dmac_get_dma_residue
,
222 .xfer
= sh_dmac_xfer_dma
,
223 .configure
= sh_dmac_configure_channel
,
226 static struct dma_info sh_dmac_info
= {
227 .name
= "SuperH DMAC",
230 .flags
= DMAC_CHANNELS_TEI_CAPABLE
,
233 static int __init
sh_dmac_init(void)
235 struct dma_info
*info
= &sh_dmac_info
;
238 #ifdef CONFIG_CPU_SH4
239 make_ipr_irq(DMAE_IRQ
, DMA_IPR_ADDR
, DMA_IPR_POS
, DMA_PRIORITY
);
240 i
= request_irq(DMAE_IRQ
, dma_err
, SA_INTERRUPT
, "DMAC Address Error", 0);
245 for (i
= 0; i
< info
->nr_channels
; i
++) {
246 int irq
= get_dmte_irq(i
);
248 make_ipr_irq(irq
, DMA_IPR_ADDR
, DMA_IPR_POS
, DMA_PRIORITY
);
251 ctrl_outl(0x8000 | DMAOR_DME
, DMAOR
);
253 return register_dmac(info
);
256 static void __exit
sh_dmac_exit(void)
258 #ifdef CONFIG_CPU_SH4
259 free_irq(DMAE_IRQ
, 0);
263 subsys_initcall(sh_dmac_init
);
264 module_exit(sh_dmac_exit
);
266 MODULE_LICENSE("GPL");