2005-04-16 16:20:36 -06: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 23:14:09 -07:00
|
|
|
* Copyright (C) 2005 Andriy Skulysh
|
2005-04-16 16:20:36 -06: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>
|
2008-07-29 05:20:36 -06:00
|
|
|
#include <mach-dreamcast/mach/dma.h>
|
2005-04-16 16:20:36 -06:00
|
|
|
#include <asm/dma.h>
|
|
|
|
#include <asm/io.h>
|
|
|
|
#include "dma-sh.h"
|
|
|
|
|
2007-01-24 23:22:11 -07:00
|
|
|
static int dmte_irq_map[] = {
|
|
|
|
DMTE0_IRQ,
|
|
|
|
DMTE1_IRQ,
|
|
|
|
DMTE2_IRQ,
|
|
|
|
DMTE3_IRQ,
|
2007-08-19 17:59:33 -06:00
|
|
|
#if defined(CONFIG_CPU_SUBTYPE_SH7720) || \
|
2007-12-25 19:45:06 -07:00
|
|
|
defined(CONFIG_CPU_SUBTYPE_SH7721) || \
|
2007-08-19 17:59:33 -06:00
|
|
|
defined(CONFIG_CPU_SUBTYPE_SH7751R) || \
|
2007-01-24 23:22:11 -07:00
|
|
|
defined(CONFIG_CPU_SUBTYPE_SH7760) || \
|
2007-09-10 21:49:59 -06:00
|
|
|
defined(CONFIG_CPU_SUBTYPE_SH7709) || \
|
2007-01-24 23:22:11 -07:00
|
|
|
defined(CONFIG_CPU_SUBTYPE_SH7780)
|
|
|
|
DMTE4_IRQ,
|
|
|
|
DMTE5_IRQ,
|
2007-08-19 17:59:33 -06:00
|
|
|
#endif
|
|
|
|
#if defined(CONFIG_CPU_SUBTYPE_SH7751R) || \
|
|
|
|
defined(CONFIG_CPU_SUBTYPE_SH7760) || \
|
|
|
|
defined(CONFIG_CPU_SUBTYPE_SH7780)
|
2007-01-24 23:22:11 -07:00
|
|
|
DMTE6_IRQ,
|
2007-08-19 17:59:33 -06:00
|
|
|
DMTE7_IRQ,
|
2006-10-30 20:35:02 -07:00
|
|
|
#endif
|
|
|
|
};
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2006-10-30 20:35:02 -07:00
|
|
|
static inline unsigned int get_dmte_irq(unsigned int chan)
|
|
|
|
{
|
|
|
|
unsigned int irq = 0;
|
2007-01-24 23:22:11 -07:00
|
|
|
if (chan < ARRAY_SIZE(dmte_irq_map))
|
|
|
|
irq = dmte_irq_map[chan];
|
2005-04-16 16:20:36 -06:00
|
|
|
return irq;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
static inline unsigned int calc_xmit_shift(struct dma_channel *chan)
|
|
|
|
{
|
|
|
|
u32 chcr = ctrl_inl(CHCR[chan->chan]);
|
|
|
|
|
2006-01-16 23:14:09 -07:00
|
|
|
return ts_shift[(chcr & CHCR_TS_MASK)>>CHCR_TS_SHIFT];
|
2005-04-16 16:20:36 -06: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 00:31:16 -06:00
|
|
|
static irqreturn_t dma_tei(int irq, void *dev_id)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
2006-10-06 00:31:16 -06:00
|
|
|
struct dma_channel *chan = dev_id;
|
2005-04-16 16:20:36 -06:00
|
|
|
u32 chcr;
|
|
|
|
|
|
|
|
chcr = ctrl_inl(CHCR[chan->chan]);
|
|
|
|
|
|
|
|
if (!(chcr & CHCR_TE))
|
|
|
|
return IRQ_NONE;
|
|
|
|
|
|
|
|
chcr &= ~(CHCR_IE | CHCR_DE);
|
|
|
|
ctrl_outl(chcr, CHCR[chan->chan]);
|
|
|
|
|
|
|
|
wake_up(&chan->wait_queue);
|
|
|
|
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int sh_dmac_request_dma(struct dma_channel *chan)
|
|
|
|
{
|
2008-02-26 13:42:11 -07:00
|
|
|
if (unlikely(!(chan->flags & DMA_TEI_CAPABLE)))
|
2006-09-27 01:55:24 -06:00
|
|
|
return 0;
|
|
|
|
|
2005-04-16 16:20:36 -06:00
|
|
|
return request_irq(get_dmte_irq(chan->chan), dma_tei,
|
2006-11-23 22:50:05 -07:00
|
|
|
IRQF_DISABLED, chan->dev_id, chan);
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
static void sh_dmac_free_dma(struct dma_channel *chan)
|
|
|
|
{
|
|
|
|
free_irq(get_dmte_irq(chan->chan), chan);
|
|
|
|
}
|
|
|
|
|
2007-01-24 23:22:11 -07:00
|
|
|
static int
|
2006-01-16 23:14:09 -07:00
|
|
|
sh_dmac_configure_channel(struct dma_channel *chan, unsigned long chcr)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
|
|
|
if (!chcr)
|
2006-01-16 23:14:09 -07: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 16:20:36 -06:00
|
|
|
|
|
|
|
ctrl_outl(chcr, CHCR[chan->chan]);
|
|
|
|
|
|
|
|
chan->flags |= DMA_CONFIGURED;
|
2007-01-24 23:22:11 -07:00
|
|
|
return 0;
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
static void sh_dmac_enable_dma(struct dma_channel *chan)
|
|
|
|
{
|
2006-01-16 23:14:09 -07:00
|
|
|
int irq;
|
2005-04-16 16:20:36 -06:00
|
|
|
u32 chcr;
|
|
|
|
|
|
|
|
chcr = ctrl_inl(CHCR[chan->chan]);
|
2006-01-16 23:14:09 -07:00
|
|
|
chcr |= CHCR_DE;
|
|
|
|
|
|
|
|
if (chan->flags & DMA_TEI_CAPABLE)
|
|
|
|
chcr |= CHCR_IE;
|
|
|
|
|
2005-04-16 16:20:36 -06:00
|
|
|
ctrl_outl(chcr, CHCR[chan->chan]);
|
|
|
|
|
2006-01-16 23:14:09 -07:00
|
|
|
if (chan->flags & DMA_TEI_CAPABLE) {
|
|
|
|
irq = get_dmte_irq(chan->chan);
|
|
|
|
enable_irq(irq);
|
|
|
|
}
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
static void sh_dmac_disable_dma(struct dma_channel *chan)
|
|
|
|
{
|
2006-01-16 23:14:09 -07:00
|
|
|
int irq;
|
2005-04-16 16:20:36 -06:00
|
|
|
u32 chcr;
|
|
|
|
|
2006-01-16 23:14:09 -07:00
|
|
|
if (chan->flags & DMA_TEI_CAPABLE) {
|
|
|
|
irq = get_dmte_irq(chan->chan);
|
|
|
|
disable_irq(irq);
|
|
|
|
}
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
chcr = ctrl_inl(CHCR[chan->chan]);
|
|
|
|
chcr &= ~(CHCR_DE | CHCR_TE | CHCR_IE);
|
|
|
|
ctrl_outl(chcr, CHCR[chan->chan]);
|
|
|
|
}
|
|
|
|
|
|
|
|
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 23:14:09 -07:00
|
|
|
if (unlikely(!(chan->flags & DMA_CONFIGURED)))
|
2005-04-16 16:20:36 -06: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 23:14:09 -07:00
|
|
|
if (chan->sar || (mach_is_dreamcast() &&
|
|
|
|
chan->chan == PVR2_CASCADE_CHAN))
|
2005-04-16 16:20:36 -06:00
|
|
|
ctrl_outl(chan->sar, SAR[chan->chan]);
|
2006-01-16 23:14:09 -07:00
|
|
|
if (chan->dar || (mach_is_dreamcast() &&
|
|
|
|
chan->chan == PVR2_CASCADE_CHAN))
|
2005-04-16 16:20:36 -06:00
|
|
|
ctrl_outl(chan->dar, DAR[chan->chan]);
|
|
|
|
|
|
|
|
ctrl_outl(chan->count >> calc_xmit_shift(chan), DMATCR[chan->chan]);
|
|
|
|
|
|
|
|
sh_dmac_enable_dma(chan);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int sh_dmac_get_dma_residue(struct dma_channel *chan)
|
|
|
|
{
|
|
|
|
if (!(ctrl_inl(CHCR[chan->chan]) & CHCR_DE))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return ctrl_inl(DMATCR[chan->chan]) << calc_xmit_shift(chan);
|
|
|
|
}
|
|
|
|
|
2007-08-19 17:59:33 -06:00
|
|
|
#if defined(CONFIG_CPU_SUBTYPE_SH7720) || \
|
2007-12-25 19:45:06 -07:00
|
|
|
defined(CONFIG_CPU_SUBTYPE_SH7721) || \
|
2008-11-23 07:27:22 -07:00
|
|
|
defined(CONFIG_CPU_SUBTYPE_SH7780) || \
|
|
|
|
defined(CONFIG_CPU_SUBTYPE_SH7709)
|
2006-01-16 23:14:09 -07:00
|
|
|
#define dmaor_read_reg() ctrl_inw(DMAOR)
|
|
|
|
#define dmaor_write_reg(data) ctrl_outw(data, DMAOR)
|
|
|
|
#else
|
|
|
|
#define dmaor_read_reg() ctrl_inl(DMAOR)
|
|
|
|
#define dmaor_write_reg(data) ctrl_outl(data, DMAOR)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static inline int dmaor_reset(void)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
2006-01-16 23:14:09 -07:00
|
|
|
unsigned long dmaor = dmaor_read_reg();
|
|
|
|
|
|
|
|
/* Try to clear the error flags first, incase they are set */
|
|
|
|
dmaor &= ~(DMAOR_NMIF | DMAOR_AE);
|
|
|
|
dmaor_write_reg(dmaor);
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2006-01-16 23:14:09 -07:00
|
|
|
dmaor |= DMAOR_INIT;
|
|
|
|
dmaor_write_reg(dmaor);
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2006-01-16 23:14:09 -07:00
|
|
|
/* See if we got an error again */
|
|
|
|
if ((dmaor_read_reg() & (DMAOR_AE | DMAOR_NMIF))) {
|
|
|
|
printk(KERN_ERR "dma-sh: Can't initialize DMAOR.\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2006-01-16 23:14:09 -07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if defined(CONFIG_CPU_SH4)
|
2006-10-06 00:31:16 -06:00
|
|
|
static irqreturn_t dma_err(int irq, void *dummy)
|
2006-01-16 23:14:09 -07:00
|
|
|
{
|
|
|
|
dmaor_reset();
|
2005-04-16 16:20:36 -06:00
|
|
|
disable_irq(irq);
|
|
|
|
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
#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 23:14:09 -07:00
|
|
|
.name = "sh_dmac",
|
|
|
|
.nr_channels = CONFIG_NR_ONCHIP_DMA_CHANNELS,
|
2005-04-16 16:20:36 -06:00
|
|
|
.ops = &sh_dmac_ops,
|
|
|
|
.flags = DMAC_CHANNELS_TEI_CAPABLE,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int __init sh_dmac_init(void)
|
|
|
|
{
|
|
|
|
struct dma_info *info = &sh_dmac_info;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
#ifdef CONFIG_CPU_SH4
|
2006-07-01 20:29:25 -06:00
|
|
|
i = request_irq(DMAE_IRQ, dma_err, IRQF_DISABLED, "DMAC Address Error", 0);
|
2006-09-27 01:55:24 -06:00
|
|
|
if (unlikely(i < 0))
|
2005-04-16 16:20:36 -06:00
|
|
|
return i;
|
|
|
|
#endif
|
|
|
|
|
2006-01-16 23:14:09 -07:00
|
|
|
/*
|
|
|
|
* Initialize DMAOR, and clean up any error flags that may have
|
|
|
|
* been set.
|
|
|
|
*/
|
|
|
|
i = dmaor_reset();
|
2006-09-27 01:55:24 -06:00
|
|
|
if (unlikely(i != 0))
|
2006-01-16 23:14:09 -07:00
|
|
|
return i;
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
return register_dmac(info);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __exit sh_dmac_exit(void)
|
|
|
|
{
|
|
|
|
#ifdef CONFIG_CPU_SH4
|
|
|
|
free_irq(DMAE_IRQ, 0);
|
|
|
|
#endif
|
2006-01-16 23:14:09 -07:00
|
|
|
unregister_dmac(&sh_dmac_info);
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
subsys_initcall(sh_dmac_init);
|
|
|
|
module_exit(sh_dmac_exit);
|
|
|
|
|
2006-01-16 23:14:09 -07:00
|
|
|
MODULE_AUTHOR("Takashi YOSHII, Paul Mundt, Andriy Skulysh");
|
|
|
|
MODULE_DESCRIPTION("SuperH On-Chip DMAC Support");
|
2005-04-16 16:20:36 -06:00
|
|
|
MODULE_LICENSE("GPL");
|