| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * arch/sh/drivers/dma/dma-sh.c | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * SuperH On-chip DMAC Support | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Copyright (C) 2000 Takashi YOSHII | 
					
						
							|  |  |  |  * Copyright (C) 2003, 2004 Paul Mundt | 
					
						
							| 
									
										
										
										
											2006-01-16 22:14:09 -08:00
										 |  |  |  * Copyright (C) 2005 Andriy Skulysh | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  |  * | 
					
						
							|  |  |  |  * This file is subject to the terms and conditions of the GNU General Public | 
					
						
							|  |  |  |  * License.  See the file "COPYING" in the main directory of this archive | 
					
						
							|  |  |  |  * for more details. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | #include <linux/init.h>
 | 
					
						
							|  |  |  | #include <linux/interrupt.h>
 | 
					
						
							|  |  |  | #include <linux/module.h>
 | 
					
						
							| 
									
										
										
										
											2012-05-19 20:38:50 +09:00
										 |  |  | #include <linux/io.h>
 | 
					
						
							| 
									
										
										
										
											2008-07-29 20:20:36 +09:00
										 |  |  | #include <mach-dreamcast/mach/dma.h>
 | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | #include <asm/dma.h>
 | 
					
						
							| 
									
										
										
										
											2012-05-19 20:38:50 +09:00
										 |  |  | #include <asm/dma-register.h>
 | 
					
						
							|  |  |  | #include <cpu/dma-register.h>
 | 
					
						
							|  |  |  | #include <cpu/dma.h>
 | 
					
						
							| 
									
										
										
										
											2009-03-10 17:26:49 +09:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-19 20:38:50 +09:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * Define the default configuration for dual address memory-memory transfer. | 
					
						
							|  |  |  |  * The 0x400 value represents auto-request, external->external. | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2014-06-20 14:37:40 +02:00
										 |  |  | #define RS_DUAL	(DM_INC | SM_INC | RS_AUTO | TS_INDEX2VAL(XMIT_SZ_32BIT))
 | 
					
						
							| 
									
										
										
										
											2012-05-19 20:38:50 +09:00
										 |  |  | 
 | 
					
						
							|  |  |  | static unsigned long dma_find_base(unsigned int chan) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	unsigned long base = SH_DMAC_BASE0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #ifdef SH_DMAC_BASE1
 | 
					
						
							|  |  |  | 	if (chan >= 6) | 
					
						
							|  |  |  | 		base = SH_DMAC_BASE1; | 
					
						
							| 
									
										
										
										
											2006-10-31 12:35:02 +09:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2009-03-10 17:26:49 +09:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-19 20:38:50 +09:00
										 |  |  | 	return base; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static unsigned long dma_base_addr(unsigned int chan) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	unsigned long base = dma_find_base(chan); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* Normalize offset calculation */ | 
					
						
							|  |  |  | 	if (chan >= 9) | 
					
						
							|  |  |  | 		chan -= 6; | 
					
						
							|  |  |  | 	if (chan >= 4) | 
					
						
							|  |  |  | 		base += 0x10; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return base + (chan * 0x10); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-19 20:38:50 +09:00
										 |  |  | #ifdef CONFIG_SH_DMA_IRQ_MULTI
 | 
					
						
							| 
									
										
										
										
											2006-10-31 12:35:02 +09:00
										 |  |  | static inline unsigned int get_dmte_irq(unsigned int chan) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2012-05-19 20:38:50 +09:00
										 |  |  | 	return chan >= 6 ? DMTE6_IRQ : DMTE0_IRQ; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2009-03-10 17:26:49 +09:00
										 |  |  | #else
 | 
					
						
							| 
									
										
										
										
											2012-05-19 20:38:50 +09:00
										 |  |  | 
 | 
					
						
							|  |  |  | static unsigned int dmte_irq_map[] = { | 
					
						
							|  |  |  | 	DMTE0_IRQ, DMTE0_IRQ + 1, DMTE0_IRQ + 2, DMTE0_IRQ + 3, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #ifdef DMTE4_IRQ
 | 
					
						
							|  |  |  | 	DMTE4_IRQ, DMTE4_IRQ + 1, | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #ifdef DMTE6_IRQ
 | 
					
						
							|  |  |  | 	DMTE6_IRQ, DMTE6_IRQ + 1, | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #ifdef DMTE8_IRQ
 | 
					
						
							|  |  |  | 	DMTE8_IRQ, DMTE9_IRQ, DMTE10_IRQ, DMTE11_IRQ, | 
					
						
							| 
									
										
										
										
											2009-03-10 17:26:49 +09:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2012-05-19 20:38:50 +09:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static inline unsigned int get_dmte_irq(unsigned int chan) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return dmte_irq_map[chan]; | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2012-05-19 20:38:50 +09:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | /*
 | 
					
						
							|  |  |  |  * We determine the correct shift size based off of the CHCR transmit size | 
					
						
							|  |  |  |  * for the given channel. Since we know that it will take: | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  *	info->count >> ts_shift[transmit_size] | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * iterations to complete the transfer. | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2010-02-03 14:44:12 +00:00
										 |  |  | static unsigned int ts_shift[] = TS_SHIFT; | 
					
						
							| 
									
										
										
										
											2012-05-19 20:38:50 +09:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | static inline unsigned int calc_xmit_shift(struct dma_channel *chan) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2012-05-19 20:38:50 +09:00
										 |  |  | 	u32 chcr = __raw_readl(dma_base_addr(chan->chan) + CHCR); | 
					
						
							| 
									
										
										
										
											2010-02-03 14:44:12 +00:00
										 |  |  | 	int cnt = ((chcr & CHCR_TS_LOW_MASK) >> CHCR_TS_LOW_SHIFT) | | 
					
						
							|  |  |  | 		((chcr & CHCR_TS_HIGH_MASK) >> CHCR_TS_HIGH_SHIFT); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-02-03 14:44:12 +00:00
										 |  |  | 	return ts_shift[cnt]; | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*
 | 
					
						
							|  |  |  |  * The transfer end interrupt must read the chcr register to end the | 
					
						
							|  |  |  |  * hardware interrupt active condition. | 
					
						
							|  |  |  |  * Besides that it needs to waken any waiting process, which should handle | 
					
						
							|  |  |  |  * setting up the next transfer. | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2006-10-06 15:31:16 +09:00
										 |  |  | static irqreturn_t dma_tei(int irq, void *dev_id) | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2006-10-06 15:31:16 +09:00
										 |  |  | 	struct dma_channel *chan = dev_id; | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	u32 chcr; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-19 20:38:50 +09:00
										 |  |  | 	chcr = __raw_readl(dma_base_addr(chan->chan) + CHCR); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (!(chcr & CHCR_TE)) | 
					
						
							|  |  |  | 		return IRQ_NONE; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	chcr &= ~(CHCR_IE | CHCR_DE); | 
					
						
							| 
									
										
										
										
											2012-05-19 20:38:50 +09:00
										 |  |  | 	__raw_writel(chcr, (dma_base_addr(chan->chan) + CHCR)); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	wake_up(&chan->wait_queue); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return IRQ_HANDLED; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int sh_dmac_request_dma(struct dma_channel *chan) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2008-02-26 21:42:11 +01:00
										 |  |  | 	if (unlikely(!(chan->flags & DMA_TEI_CAPABLE))) | 
					
						
							| 
									
										
										
										
											2006-09-27 16:55:24 +09:00
										 |  |  | 		return 0; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-19 20:38:50 +09:00
										 |  |  | 	return request_irq(get_dmte_irq(chan->chan), dma_tei, IRQF_SHARED, | 
					
						
							|  |  |  | 			   chan->dev_id, chan); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void sh_dmac_free_dma(struct dma_channel *chan) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	free_irq(get_dmte_irq(chan->chan), chan); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-01-25 15:22:11 +09:00
										 |  |  | static int | 
					
						
							| 
									
										
										
										
											2006-01-16 22:14:09 -08:00
										 |  |  | sh_dmac_configure_channel(struct dma_channel *chan, unsigned long chcr) | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | { | 
					
						
							|  |  |  | 	if (!chcr) | 
					
						
							| 
									
										
										
										
											2006-01-16 22:14:09 -08:00
										 |  |  | 		chcr = RS_DUAL | CHCR_IE; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (chcr & CHCR_IE) { | 
					
						
							|  |  |  | 		chcr &= ~CHCR_IE; | 
					
						
							|  |  |  | 		chan->flags |= DMA_TEI_CAPABLE; | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		chan->flags &= ~DMA_TEI_CAPABLE; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-19 20:38:50 +09:00
										 |  |  | 	__raw_writel(chcr, (dma_base_addr(chan->chan) + CHCR)); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	chan->flags |= DMA_CONFIGURED; | 
					
						
							| 
									
										
										
										
											2007-01-25 15:22:11 +09:00
										 |  |  | 	return 0; | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void sh_dmac_enable_dma(struct dma_channel *chan) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2006-01-16 22:14:09 -08:00
										 |  |  | 	int irq; | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	u32 chcr; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-19 20:38:50 +09:00
										 |  |  | 	chcr = __raw_readl(dma_base_addr(chan->chan) + CHCR); | 
					
						
							| 
									
										
										
										
											2006-01-16 22:14:09 -08:00
										 |  |  | 	chcr |= CHCR_DE; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (chan->flags & DMA_TEI_CAPABLE) | 
					
						
							|  |  |  | 		chcr |= CHCR_IE; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-19 20:38:50 +09:00
										 |  |  | 	__raw_writel(chcr, (dma_base_addr(chan->chan) + CHCR)); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-01-16 22:14:09 -08:00
										 |  |  | 	if (chan->flags & DMA_TEI_CAPABLE) { | 
					
						
							|  |  |  | 		irq = get_dmte_irq(chan->chan); | 
					
						
							|  |  |  | 		enable_irq(irq); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void sh_dmac_disable_dma(struct dma_channel *chan) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2006-01-16 22:14:09 -08:00
										 |  |  | 	int irq; | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	u32 chcr; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-01-16 22:14:09 -08:00
										 |  |  | 	if (chan->flags & DMA_TEI_CAPABLE) { | 
					
						
							|  |  |  | 		irq = get_dmte_irq(chan->chan); | 
					
						
							|  |  |  | 		disable_irq(irq); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-19 20:38:50 +09:00
										 |  |  | 	chcr = __raw_readl(dma_base_addr(chan->chan) + CHCR); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	chcr &= ~(CHCR_DE | CHCR_TE | CHCR_IE); | 
					
						
							| 
									
										
										
										
											2012-05-19 20:38:50 +09:00
										 |  |  | 	__raw_writel(chcr, (dma_base_addr(chan->chan) + CHCR)); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int sh_dmac_xfer_dma(struct dma_channel *chan) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	/*
 | 
					
						
							|  |  |  | 	 * If we haven't pre-configured the channel with special flags, use | 
					
						
							|  |  |  | 	 * the defaults. | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2006-01-16 22:14:09 -08:00
										 |  |  | 	if (unlikely(!(chan->flags & DMA_CONFIGURED))) | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 		sh_dmac_configure_channel(chan, 0); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	sh_dmac_disable_dma(chan); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/*
 | 
					
						
							|  |  |  | 	 * Single-address mode usage note! | 
					
						
							|  |  |  | 	 * | 
					
						
							|  |  |  | 	 * It's important that we don't accidentally write any value to SAR/DAR | 
					
						
							|  |  |  | 	 * (this includes 0) that hasn't been directly specified by the user if | 
					
						
							|  |  |  | 	 * we're in single-address mode. | 
					
						
							|  |  |  | 	 * | 
					
						
							|  |  |  | 	 * In this case, only one address can be defined, anything else will | 
					
						
							|  |  |  | 	 * result in a DMA address error interrupt (at least on the SH-4), | 
					
						
							|  |  |  | 	 * which will subsequently halt the transfer. | 
					
						
							|  |  |  | 	 * | 
					
						
							|  |  |  | 	 * Channel 2 on the Dreamcast is a special case, as this is used for | 
					
						
							|  |  |  | 	 * cascading to the PVR2 DMAC. In this case, we still need to write | 
					
						
							|  |  |  | 	 * SAR and DAR, regardless of value, in order for cascading to work. | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2006-01-16 22:14:09 -08:00
										 |  |  | 	if (chan->sar || (mach_is_dreamcast() && | 
					
						
							|  |  |  | 			  chan->chan == PVR2_CASCADE_CHAN)) | 
					
						
							| 
									
										
										
										
											2012-05-19 20:38:50 +09:00
										 |  |  | 		__raw_writel(chan->sar, (dma_base_addr(chan->chan) + SAR)); | 
					
						
							| 
									
										
										
										
											2006-01-16 22:14:09 -08:00
										 |  |  | 	if (chan->dar || (mach_is_dreamcast() && | 
					
						
							|  |  |  | 			  chan->chan == PVR2_CASCADE_CHAN)) | 
					
						
							| 
									
										
										
										
											2012-05-19 20:38:50 +09:00
										 |  |  | 		__raw_writel(chan->dar, (dma_base_addr(chan->chan) + DAR)); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-01-26 12:58:40 +09:00
										 |  |  | 	__raw_writel(chan->count >> calc_xmit_shift(chan), | 
					
						
							| 
									
										
										
										
											2012-05-19 20:38:50 +09:00
										 |  |  | 		(dma_base_addr(chan->chan) + TCR)); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	sh_dmac_enable_dma(chan); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int sh_dmac_get_dma_residue(struct dma_channel *chan) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2012-05-19 20:38:50 +09:00
										 |  |  | 	if (!(__raw_readl(dma_base_addr(chan->chan) + CHCR) & CHCR_DE)) | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 		return 0; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-19 20:38:50 +09:00
										 |  |  | 	return __raw_readl(dma_base_addr(chan->chan) + TCR) | 
					
						
							| 
									
										
										
										
											2009-03-10 17:26:49 +09:00
										 |  |  | 		 << calc_xmit_shift(chan); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-19 20:38:50 +09:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * DMAOR handling | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | #if defined(CONFIG_CPU_SUBTYPE_SH7723)	|| \
 | 
					
						
							|  |  |  |     defined(CONFIG_CPU_SUBTYPE_SH7724)	|| \ | 
					
						
							|  |  |  |     defined(CONFIG_CPU_SUBTYPE_SH7780)	|| \ | 
					
						
							|  |  |  |     defined(CONFIG_CPU_SUBTYPE_SH7785) | 
					
						
							|  |  |  | #define NR_DMAOR	2
 | 
					
						
							|  |  |  | #else
 | 
					
						
							|  |  |  | #define NR_DMAOR	1
 | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*
 | 
					
						
							|  |  |  |  * DMAOR bases are broken out amongst channel groups. DMAOR0 manages | 
					
						
							|  |  |  |  * channels 0 - 5, DMAOR1 6 - 11 (optional). | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | #define dmaor_read_reg(n)		__raw_readw(dma_find_base((n)*6))
 | 
					
						
							|  |  |  | #define dmaor_write_reg(n, data)	__raw_writew(data, dma_find_base(n)*6)
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-03-10 17:26:49 +09:00
										 |  |  | static inline int dmaor_reset(int no) | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2009-03-10 17:26:49 +09:00
										 |  |  | 	unsigned long dmaor = dmaor_read_reg(no); | 
					
						
							| 
									
										
										
										
											2006-01-16 22:14:09 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* Try to clear the error flags first, incase they are set */ | 
					
						
							|  |  |  | 	dmaor &= ~(DMAOR_NMIF | DMAOR_AE); | 
					
						
							| 
									
										
										
										
											2009-03-10 17:26:49 +09:00
										 |  |  | 	dmaor_write_reg(no, dmaor); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-01-16 22:14:09 -08:00
										 |  |  | 	dmaor |= DMAOR_INIT; | 
					
						
							| 
									
										
										
										
											2009-03-10 17:26:49 +09:00
										 |  |  | 	dmaor_write_reg(no, dmaor); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-01-16 22:14:09 -08:00
										 |  |  | 	/* See if we got an error again */ | 
					
						
							| 
									
										
										
										
											2009-03-10 17:26:49 +09:00
										 |  |  | 	if ((dmaor_read_reg(no) & (DMAOR_AE | DMAOR_NMIF))) { | 
					
						
							| 
									
										
										
										
											2006-01-16 22:14:09 -08:00
										 |  |  | 		printk(KERN_ERR "dma-sh: Can't initialize DMAOR.\n"); | 
					
						
							|  |  |  | 		return -EINVAL; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-01-16 22:14:09 -08:00
										 |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-19 20:38:50 +09:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * DMAE handling | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | #ifdef CONFIG_CPU_SH4
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #if defined(DMAE1_IRQ)
 | 
					
						
							|  |  |  | #define NR_DMAE		2
 | 
					
						
							|  |  |  | #else
 | 
					
						
							|  |  |  | #define NR_DMAE		1
 | 
					
						
							| 
									
										
										
										
											2009-03-10 17:26:49 +09:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2012-05-19 20:38:50 +09:00
										 |  |  | 
 | 
					
						
							|  |  |  | static const char *dmae_name[] = { | 
					
						
							|  |  |  | 	"DMAC Address Error0", | 
					
						
							|  |  |  | 	"DMAC Address Error1" | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #ifdef CONFIG_SH_DMA_IRQ_MULTI
 | 
					
						
							|  |  |  | static inline unsigned int get_dma_error_irq(int n) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return get_dmte_irq(n * 6); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2009-03-10 17:26:49 +09:00
										 |  |  | #else
 | 
					
						
							| 
									
										
										
										
											2012-05-19 20:38:50 +09:00
										 |  |  | 
 | 
					
						
							|  |  |  | static unsigned int dmae_irq_map[] = { | 
					
						
							|  |  |  | 	DMAE0_IRQ, | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #ifdef DMAE1_IRQ
 | 
					
						
							|  |  |  | 	DMAE1_IRQ, | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static inline unsigned int get_dma_error_irq(int n) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return dmae_irq_map[n]; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2009-03-10 17:26:49 +09:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2012-05-19 20:38:50 +09:00
										 |  |  | 
 | 
					
						
							|  |  |  | static irqreturn_t dma_err(int irq, void *dummy) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	int i; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for (i = 0; i < NR_DMAOR; i++) | 
					
						
							|  |  |  | 		dmaor_reset(i); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	disable_irq(irq); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return IRQ_HANDLED; | 
					
						
							| 
									
										
										
										
											2012-05-19 20:38:50 +09:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int dmae_irq_init(void) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	int n; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for (n = 0; n < NR_DMAE; n++) { | 
					
						
							|  |  |  | 		int i = request_irq(get_dma_error_irq(n), dma_err, | 
					
						
							| 
									
										
										
										
											2012-08-04 21:54:05 -04:00
										 |  |  | 				    IRQF_SHARED, dmae_name[n], (void *)dmae_name[n]); | 
					
						
							| 
									
										
										
										
											2012-05-19 20:38:50 +09:00
										 |  |  | 		if (unlikely(i < 0)) { | 
					
						
							|  |  |  | 			printk(KERN_ERR "%s request_irq fail\n", dmae_name[n]); | 
					
						
							|  |  |  | 			return i; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void dmae_irq_free(void) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	int n; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for (n = 0; n < NR_DMAE; n++) | 
					
						
							|  |  |  | 		free_irq(get_dma_error_irq(n), NULL); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | #else
 | 
					
						
							|  |  |  | static inline int dmae_irq_init(void) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void dmae_irq_free(void) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | } | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static struct dma_ops sh_dmac_ops = { | 
					
						
							|  |  |  | 	.request	= sh_dmac_request_dma, | 
					
						
							|  |  |  | 	.free		= sh_dmac_free_dma, | 
					
						
							|  |  |  | 	.get_residue	= sh_dmac_get_dma_residue, | 
					
						
							|  |  |  | 	.xfer		= sh_dmac_xfer_dma, | 
					
						
							|  |  |  | 	.configure	= sh_dmac_configure_channel, | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static struct dma_info sh_dmac_info = { | 
					
						
							| 
									
										
										
										
											2006-01-16 22:14:09 -08:00
										 |  |  | 	.name		= "sh_dmac", | 
					
						
							|  |  |  | 	.nr_channels	= CONFIG_NR_ONCHIP_DMA_CHANNELS, | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 	.ops		= &sh_dmac_ops, | 
					
						
							|  |  |  | 	.flags		= DMAC_CHANNELS_TEI_CAPABLE, | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int __init sh_dmac_init(void) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct dma_info *info = &sh_dmac_info; | 
					
						
							| 
									
										
										
										
											2012-05-19 20:38:50 +09:00
										 |  |  | 	int i, rc; | 
					
						
							| 
									
										
										
										
											2009-03-10 17:26:49 +09:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-19 20:38:50 +09:00
										 |  |  | 	/*
 | 
					
						
							|  |  |  | 	 * Initialize DMAE, for parts that support it. | 
					
						
							|  |  |  | 	 */ | 
					
						
							|  |  |  | 	rc = dmae_irq_init(); | 
					
						
							|  |  |  | 	if (unlikely(rc != 0)) | 
					
						
							|  |  |  | 		return rc; | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-01-16 22:14:09 -08:00
										 |  |  | 	/*
 | 
					
						
							|  |  |  | 	 * Initialize DMAOR, and clean up any error flags that may have | 
					
						
							|  |  |  | 	 * been set. | 
					
						
							|  |  |  | 	 */ | 
					
						
							| 
									
										
										
										
											2012-05-19 20:38:50 +09:00
										 |  |  | 	for (i = 0; i < NR_DMAOR; i++) { | 
					
						
							|  |  |  | 		rc = dmaor_reset(i); | 
					
						
							|  |  |  | 		if (unlikely(rc != 0)) | 
					
						
							|  |  |  | 			return rc; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return register_dmac(info); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void __exit sh_dmac_exit(void) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2012-05-19 20:38:50 +09:00
										 |  |  | 	dmae_irq_free(); | 
					
						
							| 
									
										
										
										
											2006-01-16 22:14:09 -08:00
										 |  |  | 	unregister_dmac(&sh_dmac_info); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | subsys_initcall(sh_dmac_init); | 
					
						
							|  |  |  | module_exit(sh_dmac_exit); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-01-16 22:14:09 -08:00
										 |  |  | MODULE_AUTHOR("Takashi YOSHII, Paul Mundt, Andriy Skulysh"); | 
					
						
							|  |  |  | MODULE_DESCRIPTION("SuperH On-Chip DMAC Support"); | 
					
						
							| 
									
										
										
										
											2005-04-16 15:20:36 -07:00
										 |  |  | MODULE_LICENSE("GPL"); |