| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* | 
 | 2 |  * arch/sh/drivers/dma/dma-sh.c | 
 | 3 |  * | 
 | 4 |  * SuperH On-chip DMAC Support | 
 | 5 |  * | 
 | 6 |  * Copyright (C) 2000 Takashi YOSHII | 
 | 7 |  * Copyright (C) 2003, 2004 Paul Mundt | 
| Paul Mundt | 0d83177 | 2006-01-16 22:14:09 -0800 | [diff] [blame] | 8 |  * Copyright (C) 2005 Andriy Skulysh | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 |  * | 
 | 10 |  * This file is subject to the terms and conditions of the GNU General Public | 
 | 11 |  * License.  See the file "COPYING" in the main directory of this archive | 
 | 12 |  * for more details. | 
 | 13 |  */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | #include <linux/init.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | #include <linux/interrupt.h> | 
 | 16 | #include <linux/module.h> | 
| Paul Mundt | 71b8064 | 2008-07-29 20:20:36 +0900 | [diff] [blame] | 17 | #include <mach-dreamcast/mach/dma.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | #include <asm/dma.h> | 
 | 19 | #include <asm/io.h> | 
| Nobuhiro Iwamatsu | 71b973a | 2009-03-10 17:26:49 +0900 | [diff] [blame] | 20 | #include <asm/dma-sh.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 |  | 
| Nobuhiro Iwamatsu | 71b973a | 2009-03-10 17:26:49 +0900 | [diff] [blame] | 22 | #if defined(DMAE1_IRQ) | 
 | 23 | #define NR_DMAE		2 | 
 | 24 | #else | 
 | 25 | #define NR_DMAE		1 | 
| Jamie Lenehan | bd71ab8 | 2006-10-31 12:35:02 +0900 | [diff] [blame] | 26 | #endif | 
| Nobuhiro Iwamatsu | 71b973a | 2009-03-10 17:26:49 +0900 | [diff] [blame] | 27 |  | 
 | 28 | static const char *dmae_name[] = { | 
 | 29 | 	"DMAC Address Error0", "DMAC Address Error1" | 
| Jamie Lenehan | bd71ab8 | 2006-10-31 12:35:02 +0900 | [diff] [blame] | 30 | }; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 |  | 
| Jamie Lenehan | bd71ab8 | 2006-10-31 12:35:02 +0900 | [diff] [blame] | 32 | static inline unsigned int get_dmte_irq(unsigned int chan) | 
 | 33 | { | 
 | 34 | 	unsigned int irq = 0; | 
| Manuel Lauss | 9f8a5e3 | 2007-01-25 15:22:11 +0900 | [diff] [blame] | 35 | 	if (chan < ARRAY_SIZE(dmte_irq_map)) | 
 | 36 | 		irq = dmte_irq_map[chan]; | 
| Nobuhiro Iwamatsu | 71b973a | 2009-03-10 17:26:49 +0900 | [diff] [blame] | 37 |  | 
| Nobuhiro Iwamatsu | 988f831 | 2009-03-16 03:22:07 +0000 | [diff] [blame] | 38 | #if defined(CONFIG_SH_DMA_IRQ_MULTI) | 
| Nobuhiro Iwamatsu | 71b973a | 2009-03-10 17:26:49 +0900 | [diff] [blame] | 39 | 	if (irq > DMTE6_IRQ) | 
 | 40 | 		return DMTE6_IRQ; | 
 | 41 | 	return DMTE0_IRQ; | 
 | 42 | #else | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | 	return irq; | 
| Nobuhiro Iwamatsu | 71b973a | 2009-03-10 17:26:49 +0900 | [diff] [blame] | 44 | #endif | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | } | 
 | 46 |  | 
 | 47 | /* | 
 | 48 |  * We determine the correct shift size based off of the CHCR transmit size | 
 | 49 |  * for the given channel. Since we know that it will take: | 
 | 50 |  * | 
 | 51 |  *	info->count >> ts_shift[transmit_size] | 
 | 52 |  * | 
 | 53 |  * iterations to complete the transfer. | 
 | 54 |  */ | 
| Guennadi Liakhovetski | 623b4ac | 2010-02-03 14:44:12 +0000 | [diff] [blame] | 55 | static unsigned int ts_shift[] = TS_SHIFT; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | static inline unsigned int calc_xmit_shift(struct dma_channel *chan) | 
 | 57 | { | 
| Paul Mundt | 9d56dd3 | 2010-01-26 12:58:40 +0900 | [diff] [blame] | 58 | 	u32 chcr = __raw_readl(dma_base_addr[chan->chan] + CHCR); | 
| Guennadi Liakhovetski | 623b4ac | 2010-02-03 14:44:12 +0000 | [diff] [blame] | 59 | 	int cnt = ((chcr & CHCR_TS_LOW_MASK) >> CHCR_TS_LOW_SHIFT) | | 
 | 60 | 		((chcr & CHCR_TS_HIGH_MASK) >> CHCR_TS_HIGH_SHIFT); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 |  | 
| Guennadi Liakhovetski | 623b4ac | 2010-02-03 14:44:12 +0000 | [diff] [blame] | 62 | 	return ts_shift[cnt]; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | } | 
 | 64 |  | 
 | 65 | /* | 
 | 66 |  * The transfer end interrupt must read the chcr register to end the | 
 | 67 |  * hardware interrupt active condition. | 
 | 68 |  * Besides that it needs to waken any waiting process, which should handle | 
 | 69 |  * setting up the next transfer. | 
 | 70 |  */ | 
| Paul Mundt | 35f3c51 | 2006-10-06 15:31:16 +0900 | [diff] [blame] | 71 | static irqreturn_t dma_tei(int irq, void *dev_id) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | { | 
| Paul Mundt | 35f3c51 | 2006-10-06 15:31:16 +0900 | [diff] [blame] | 73 | 	struct dma_channel *chan = dev_id; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | 	u32 chcr; | 
 | 75 |  | 
| Paul Mundt | 9d56dd3 | 2010-01-26 12:58:40 +0900 | [diff] [blame] | 76 | 	chcr = __raw_readl(dma_base_addr[chan->chan] + CHCR); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 |  | 
 | 78 | 	if (!(chcr & CHCR_TE)) | 
 | 79 | 		return IRQ_NONE; | 
 | 80 |  | 
 | 81 | 	chcr &= ~(CHCR_IE | CHCR_DE); | 
| Paul Mundt | 9d56dd3 | 2010-01-26 12:58:40 +0900 | [diff] [blame] | 82 | 	__raw_writel(chcr, (dma_base_addr[chan->chan] + CHCR)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 |  | 
 | 84 | 	wake_up(&chan->wait_queue); | 
 | 85 |  | 
 | 86 | 	return IRQ_HANDLED; | 
 | 87 | } | 
 | 88 |  | 
 | 89 | static int sh_dmac_request_dma(struct dma_channel *chan) | 
 | 90 | { | 
| Julia Lawall | b2d7c7f | 2008-02-26 21:42:11 +0100 | [diff] [blame] | 91 | 	if (unlikely(!(chan->flags & DMA_TEI_CAPABLE))) | 
| Paul Mundt | 9e3043c | 2006-09-27 16:55:24 +0900 | [diff] [blame] | 92 | 		return 0; | 
 | 93 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | 	return request_irq(get_dmte_irq(chan->chan), dma_tei, | 
| Nobuhiro Iwamatsu | 988f831 | 2009-03-16 03:22:07 +0000 | [diff] [blame] | 95 | #if defined(CONFIG_SH_DMA_IRQ_MULTI) | 
| Nobuhiro Iwamatsu | 71b973a | 2009-03-10 17:26:49 +0900 | [diff] [blame] | 96 | 				IRQF_SHARED, | 
 | 97 | #else | 
 | 98 | 				IRQF_DISABLED, | 
 | 99 | #endif | 
 | 100 | 				chan->dev_id, chan); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | } | 
 | 102 |  | 
 | 103 | static void sh_dmac_free_dma(struct dma_channel *chan) | 
 | 104 | { | 
 | 105 | 	free_irq(get_dmte_irq(chan->chan), chan); | 
 | 106 | } | 
 | 107 |  | 
| Manuel Lauss | 9f8a5e3 | 2007-01-25 15:22:11 +0900 | [diff] [blame] | 108 | static int | 
| Paul Mundt | 0d83177 | 2006-01-16 22:14:09 -0800 | [diff] [blame] | 109 | sh_dmac_configure_channel(struct dma_channel *chan, unsigned long chcr) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | { | 
 | 111 | 	if (!chcr) | 
| Paul Mundt | 0d83177 | 2006-01-16 22:14:09 -0800 | [diff] [blame] | 112 | 		chcr = RS_DUAL | CHCR_IE; | 
 | 113 |  | 
 | 114 | 	if (chcr & CHCR_IE) { | 
 | 115 | 		chcr &= ~CHCR_IE; | 
 | 116 | 		chan->flags |= DMA_TEI_CAPABLE; | 
 | 117 | 	} else { | 
 | 118 | 		chan->flags &= ~DMA_TEI_CAPABLE; | 
 | 119 | 	} | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 |  | 
| Paul Mundt | 9d56dd3 | 2010-01-26 12:58:40 +0900 | [diff] [blame] | 121 | 	__raw_writel(chcr, (dma_base_addr[chan->chan] + CHCR)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 |  | 
 | 123 | 	chan->flags |= DMA_CONFIGURED; | 
| Manuel Lauss | 9f8a5e3 | 2007-01-25 15:22:11 +0900 | [diff] [blame] | 124 | 	return 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | } | 
 | 126 |  | 
 | 127 | static void sh_dmac_enable_dma(struct dma_channel *chan) | 
 | 128 | { | 
| Paul Mundt | 0d83177 | 2006-01-16 22:14:09 -0800 | [diff] [blame] | 129 | 	int irq; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | 	u32 chcr; | 
 | 131 |  | 
| Paul Mundt | 9d56dd3 | 2010-01-26 12:58:40 +0900 | [diff] [blame] | 132 | 	chcr = __raw_readl(dma_base_addr[chan->chan] + CHCR); | 
| Paul Mundt | 0d83177 | 2006-01-16 22:14:09 -0800 | [diff] [blame] | 133 | 	chcr |= CHCR_DE; | 
 | 134 |  | 
 | 135 | 	if (chan->flags & DMA_TEI_CAPABLE) | 
 | 136 | 		chcr |= CHCR_IE; | 
 | 137 |  | 
| Paul Mundt | 9d56dd3 | 2010-01-26 12:58:40 +0900 | [diff] [blame] | 138 | 	__raw_writel(chcr, (dma_base_addr[chan->chan] + CHCR)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 |  | 
| Paul Mundt | 0d83177 | 2006-01-16 22:14:09 -0800 | [diff] [blame] | 140 | 	if (chan->flags & DMA_TEI_CAPABLE) { | 
 | 141 | 		irq = get_dmte_irq(chan->chan); | 
 | 142 | 		enable_irq(irq); | 
 | 143 | 	} | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | } | 
 | 145 |  | 
 | 146 | static void sh_dmac_disable_dma(struct dma_channel *chan) | 
 | 147 | { | 
| Paul Mundt | 0d83177 | 2006-01-16 22:14:09 -0800 | [diff] [blame] | 148 | 	int irq; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | 	u32 chcr; | 
 | 150 |  | 
| Paul Mundt | 0d83177 | 2006-01-16 22:14:09 -0800 | [diff] [blame] | 151 | 	if (chan->flags & DMA_TEI_CAPABLE) { | 
 | 152 | 		irq = get_dmte_irq(chan->chan); | 
 | 153 | 		disable_irq(irq); | 
 | 154 | 	} | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 |  | 
| Paul Mundt | 9d56dd3 | 2010-01-26 12:58:40 +0900 | [diff] [blame] | 156 | 	chcr = __raw_readl(dma_base_addr[chan->chan] + CHCR); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | 	chcr &= ~(CHCR_DE | CHCR_TE | CHCR_IE); | 
| Paul Mundt | 9d56dd3 | 2010-01-26 12:58:40 +0900 | [diff] [blame] | 158 | 	__raw_writel(chcr, (dma_base_addr[chan->chan] + CHCR)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | } | 
 | 160 |  | 
 | 161 | static int sh_dmac_xfer_dma(struct dma_channel *chan) | 
 | 162 | { | 
 | 163 | 	/* | 
 | 164 | 	 * If we haven't pre-configured the channel with special flags, use | 
 | 165 | 	 * the defaults. | 
 | 166 | 	 */ | 
| Paul Mundt | 0d83177 | 2006-01-16 22:14:09 -0800 | [diff] [blame] | 167 | 	if (unlikely(!(chan->flags & DMA_CONFIGURED))) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 168 | 		sh_dmac_configure_channel(chan, 0); | 
 | 169 |  | 
 | 170 | 	sh_dmac_disable_dma(chan); | 
 | 171 |  | 
 | 172 | 	/* | 
 | 173 | 	 * Single-address mode usage note! | 
 | 174 | 	 * | 
 | 175 | 	 * It's important that we don't accidentally write any value to SAR/DAR | 
 | 176 | 	 * (this includes 0) that hasn't been directly specified by the user if | 
 | 177 | 	 * we're in single-address mode. | 
 | 178 | 	 * | 
 | 179 | 	 * In this case, only one address can be defined, anything else will | 
 | 180 | 	 * result in a DMA address error interrupt (at least on the SH-4), | 
 | 181 | 	 * which will subsequently halt the transfer. | 
 | 182 | 	 * | 
 | 183 | 	 * Channel 2 on the Dreamcast is a special case, as this is used for | 
 | 184 | 	 * cascading to the PVR2 DMAC. In this case, we still need to write | 
 | 185 | 	 * SAR and DAR, regardless of value, in order for cascading to work. | 
 | 186 | 	 */ | 
| Paul Mundt | 0d83177 | 2006-01-16 22:14:09 -0800 | [diff] [blame] | 187 | 	if (chan->sar || (mach_is_dreamcast() && | 
 | 188 | 			  chan->chan == PVR2_CASCADE_CHAN)) | 
| Paul Mundt | 9d56dd3 | 2010-01-26 12:58:40 +0900 | [diff] [blame] | 189 | 		__raw_writel(chan->sar, (dma_base_addr[chan->chan]+SAR)); | 
| Paul Mundt | 0d83177 | 2006-01-16 22:14:09 -0800 | [diff] [blame] | 190 | 	if (chan->dar || (mach_is_dreamcast() && | 
 | 191 | 			  chan->chan == PVR2_CASCADE_CHAN)) | 
| Paul Mundt | 9d56dd3 | 2010-01-26 12:58:40 +0900 | [diff] [blame] | 192 | 		__raw_writel(chan->dar, (dma_base_addr[chan->chan] + DAR)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 |  | 
| Paul Mundt | 9d56dd3 | 2010-01-26 12:58:40 +0900 | [diff] [blame] | 194 | 	__raw_writel(chan->count >> calc_xmit_shift(chan), | 
| Nobuhiro Iwamatsu | 71b973a | 2009-03-10 17:26:49 +0900 | [diff] [blame] | 195 | 		(dma_base_addr[chan->chan] + TCR)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 |  | 
 | 197 | 	sh_dmac_enable_dma(chan); | 
 | 198 |  | 
 | 199 | 	return 0; | 
 | 200 | } | 
 | 201 |  | 
 | 202 | static int sh_dmac_get_dma_residue(struct dma_channel *chan) | 
 | 203 | { | 
| Paul Mundt | 9d56dd3 | 2010-01-26 12:58:40 +0900 | [diff] [blame] | 204 | 	if (!(__raw_readl(dma_base_addr[chan->chan] + CHCR) & CHCR_DE)) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | 		return 0; | 
 | 206 |  | 
| Paul Mundt | 9d56dd3 | 2010-01-26 12:58:40 +0900 | [diff] [blame] | 207 | 	return __raw_readl(dma_base_addr[chan->chan] + TCR) | 
| Nobuhiro Iwamatsu | 71b973a | 2009-03-10 17:26:49 +0900 | [diff] [blame] | 208 | 		 << calc_xmit_shift(chan); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | } | 
 | 210 |  | 
| Nobuhiro Iwamatsu | 71b973a | 2009-03-10 17:26:49 +0900 | [diff] [blame] | 211 | static inline int dmaor_reset(int no) | 
| Paul Mundt | 0d83177 | 2006-01-16 22:14:09 -0800 | [diff] [blame] | 212 | { | 
| Nobuhiro Iwamatsu | 71b973a | 2009-03-10 17:26:49 +0900 | [diff] [blame] | 213 | 	unsigned long dmaor = dmaor_read_reg(no); | 
| Paul Mundt | 0d83177 | 2006-01-16 22:14:09 -0800 | [diff] [blame] | 214 |  | 
 | 215 | 	/* Try to clear the error flags first, incase they are set */ | 
 | 216 | 	dmaor &= ~(DMAOR_NMIF | DMAOR_AE); | 
| Nobuhiro Iwamatsu | 71b973a | 2009-03-10 17:26:49 +0900 | [diff] [blame] | 217 | 	dmaor_write_reg(no, dmaor); | 
| Paul Mundt | 0d83177 | 2006-01-16 22:14:09 -0800 | [diff] [blame] | 218 |  | 
 | 219 | 	dmaor |= DMAOR_INIT; | 
| Nobuhiro Iwamatsu | 71b973a | 2009-03-10 17:26:49 +0900 | [diff] [blame] | 220 | 	dmaor_write_reg(no, dmaor); | 
| Paul Mundt | 0d83177 | 2006-01-16 22:14:09 -0800 | [diff] [blame] | 221 |  | 
 | 222 | 	/* See if we got an error again */ | 
| Nobuhiro Iwamatsu | 71b973a | 2009-03-10 17:26:49 +0900 | [diff] [blame] | 223 | 	if ((dmaor_read_reg(no) & (DMAOR_AE | DMAOR_NMIF))) { | 
| Paul Mundt | 0d83177 | 2006-01-16 22:14:09 -0800 | [diff] [blame] | 224 | 		printk(KERN_ERR "dma-sh: Can't initialize DMAOR.\n"); | 
 | 225 | 		return -EINVAL; | 
 | 226 | 	} | 
 | 227 |  | 
 | 228 | 	return 0; | 
 | 229 | } | 
 | 230 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 231 | #if defined(CONFIG_CPU_SH4) | 
| Paul Mundt | 35f3c51 | 2006-10-06 15:31:16 +0900 | [diff] [blame] | 232 | static irqreturn_t dma_err(int irq, void *dummy) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | { | 
| Nobuhiro Iwamatsu | 988f831 | 2009-03-16 03:22:07 +0000 | [diff] [blame] | 234 | #if defined(CONFIG_SH_DMA_IRQ_MULTI) | 
| Nobuhiro Iwamatsu | 71b973a | 2009-03-10 17:26:49 +0900 | [diff] [blame] | 235 | 	int cnt = 0; | 
 | 236 | 	switch (irq) { | 
 | 237 | #if defined(DMTE6_IRQ) && defined(DMAE1_IRQ) | 
 | 238 | 	case DMTE6_IRQ: | 
 | 239 | 		cnt++; | 
 | 240 | #endif | 
 | 241 | 	case DMTE0_IRQ: | 
 | 242 | 		if (dmaor_read_reg(cnt) & (DMAOR_NMIF | DMAOR_AE)) { | 
 | 243 | 			disable_irq(irq); | 
 | 244 | 			/* DMA multi and error IRQ */ | 
 | 245 | 			return IRQ_HANDLED; | 
 | 246 | 		} | 
 | 247 | 	default: | 
 | 248 | 		return IRQ_NONE; | 
 | 249 | 	} | 
 | 250 | #else | 
 | 251 | 	dmaor_reset(0); | 
 | 252 | #if defined(CONFIG_CPU_SUBTYPE_SH7723)	|| \ | 
 | 253 | 		defined(CONFIG_CPU_SUBTYPE_SH7780)	|| \ | 
 | 254 | 		defined(CONFIG_CPU_SUBTYPE_SH7785) | 
 | 255 | 	dmaor_reset(1); | 
 | 256 | #endif | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 257 | 	disable_irq(irq); | 
 | 258 |  | 
 | 259 | 	return IRQ_HANDLED; | 
| Nobuhiro Iwamatsu | 71b973a | 2009-03-10 17:26:49 +0900 | [diff] [blame] | 260 | #endif | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 261 | } | 
 | 262 | #endif | 
 | 263 |  | 
 | 264 | static struct dma_ops sh_dmac_ops = { | 
 | 265 | 	.request	= sh_dmac_request_dma, | 
 | 266 | 	.free		= sh_dmac_free_dma, | 
 | 267 | 	.get_residue	= sh_dmac_get_dma_residue, | 
 | 268 | 	.xfer		= sh_dmac_xfer_dma, | 
 | 269 | 	.configure	= sh_dmac_configure_channel, | 
 | 270 | }; | 
 | 271 |  | 
 | 272 | static struct dma_info sh_dmac_info = { | 
| Paul Mundt | 0d83177 | 2006-01-16 22:14:09 -0800 | [diff] [blame] | 273 | 	.name		= "sh_dmac", | 
 | 274 | 	.nr_channels	= CONFIG_NR_ONCHIP_DMA_CHANNELS, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 275 | 	.ops		= &sh_dmac_ops, | 
 | 276 | 	.flags		= DMAC_CHANNELS_TEI_CAPABLE, | 
 | 277 | }; | 
 | 278 |  | 
| Nobuhiro Iwamatsu | 02ebd32 | 2009-03-13 04:31:34 +0000 | [diff] [blame] | 279 | #ifdef CONFIG_CPU_SH4 | 
| Nobuhiro Iwamatsu | 71b973a | 2009-03-10 17:26:49 +0900 | [diff] [blame] | 280 | static unsigned int get_dma_error_irq(int n) | 
 | 281 | { | 
| Nobuhiro Iwamatsu | 988f831 | 2009-03-16 03:22:07 +0000 | [diff] [blame] | 282 | #if defined(CONFIG_SH_DMA_IRQ_MULTI) | 
| Nobuhiro Iwamatsu | 71b973a | 2009-03-10 17:26:49 +0900 | [diff] [blame] | 283 | 	return (n == 0) ? get_dmte_irq(0) : get_dmte_irq(6); | 
 | 284 | #else | 
 | 285 | 	return (n == 0) ? DMAE0_IRQ : | 
 | 286 | #if defined(DMAE1_IRQ) | 
 | 287 | 				DMAE1_IRQ; | 
 | 288 | #else | 
 | 289 | 				-1; | 
 | 290 | #endif | 
 | 291 | #endif | 
 | 292 | } | 
| Nobuhiro Iwamatsu | 02ebd32 | 2009-03-13 04:31:34 +0000 | [diff] [blame] | 293 | #endif | 
| Nobuhiro Iwamatsu | 71b973a | 2009-03-10 17:26:49 +0900 | [diff] [blame] | 294 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 295 | static int __init sh_dmac_init(void) | 
 | 296 | { | 
 | 297 | 	struct dma_info *info = &sh_dmac_info; | 
 | 298 | 	int i; | 
 | 299 |  | 
 | 300 | #ifdef CONFIG_CPU_SH4 | 
| Nobuhiro Iwamatsu | 71b973a | 2009-03-10 17:26:49 +0900 | [diff] [blame] | 301 | 	int n; | 
 | 302 |  | 
 | 303 | 	for (n = 0; n < NR_DMAE; n++) { | 
 | 304 | 		i = request_irq(get_dma_error_irq(n), dma_err, | 
| Nobuhiro Iwamatsu | 988f831 | 2009-03-16 03:22:07 +0000 | [diff] [blame] | 305 | #if defined(CONFIG_SH_DMA_IRQ_MULTI) | 
| Nobuhiro Iwamatsu | 71b973a | 2009-03-10 17:26:49 +0900 | [diff] [blame] | 306 | 				IRQF_SHARED, | 
 | 307 | #else | 
 | 308 | 				IRQF_DISABLED, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 309 | #endif | 
| Nobuhiro Iwamatsu | 71b973a | 2009-03-10 17:26:49 +0900 | [diff] [blame] | 310 | 				dmae_name[n], (void *)dmae_name[n]); | 
 | 311 | 		if (unlikely(i < 0)) { | 
 | 312 | 			printk(KERN_ERR "%s request_irq fail\n", dmae_name[n]); | 
 | 313 | 			return i; | 
 | 314 | 		} | 
 | 315 | 	} | 
 | 316 | #endif /* CONFIG_CPU_SH4 */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 |  | 
| Paul Mundt | 0d83177 | 2006-01-16 22:14:09 -0800 | [diff] [blame] | 318 | 	/* | 
 | 319 | 	 * Initialize DMAOR, and clean up any error flags that may have | 
 | 320 | 	 * been set. | 
 | 321 | 	 */ | 
| Nobuhiro Iwamatsu | 71b973a | 2009-03-10 17:26:49 +0900 | [diff] [blame] | 322 | 	i = dmaor_reset(0); | 
| Paul Mundt | 9e3043c | 2006-09-27 16:55:24 +0900 | [diff] [blame] | 323 | 	if (unlikely(i != 0)) | 
| Paul Mundt | 0d83177 | 2006-01-16 22:14:09 -0800 | [diff] [blame] | 324 | 		return i; | 
| Nobuhiro Iwamatsu | 71b973a | 2009-03-10 17:26:49 +0900 | [diff] [blame] | 325 | #if defined(CONFIG_CPU_SUBTYPE_SH7723)	|| \ | 
 | 326 | 		defined(CONFIG_CPU_SUBTYPE_SH7780)	|| \ | 
 | 327 | 		defined(CONFIG_CPU_SUBTYPE_SH7785) | 
 | 328 | 	i = dmaor_reset(1); | 
 | 329 | 	if (unlikely(i != 0)) | 
 | 330 | 		return i; | 
 | 331 | #endif | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 332 |  | 
 | 333 | 	return register_dmac(info); | 
 | 334 | } | 
 | 335 |  | 
 | 336 | static void __exit sh_dmac_exit(void) | 
 | 337 | { | 
 | 338 | #ifdef CONFIG_CPU_SH4 | 
| Nobuhiro Iwamatsu | 71b973a | 2009-03-10 17:26:49 +0900 | [diff] [blame] | 339 | 	int n; | 
 | 340 |  | 
 | 341 | 	for (n = 0; n < NR_DMAE; n++) { | 
 | 342 | 		free_irq(get_dma_error_irq(n), (void *)dmae_name[n]); | 
 | 343 | 	} | 
 | 344 | #endif /* CONFIG_CPU_SH4 */ | 
| Paul Mundt | 0d83177 | 2006-01-16 22:14:09 -0800 | [diff] [blame] | 345 | 	unregister_dmac(&sh_dmac_info); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 346 | } | 
 | 347 |  | 
 | 348 | subsys_initcall(sh_dmac_init); | 
 | 349 | module_exit(sh_dmac_exit); | 
 | 350 |  | 
| Paul Mundt | 0d83177 | 2006-01-16 22:14:09 -0800 | [diff] [blame] | 351 | MODULE_AUTHOR("Takashi YOSHII, Paul Mundt, Andriy Skulysh"); | 
 | 352 | MODULE_DESCRIPTION("SuperH On-Chip DMAC Support"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 353 | MODULE_LICENSE("GPL"); |