blob: 33ea8285eb7ddd0ef547692b1af6d1733a42c173 [file] [log] [blame]
Peter Tyser017f11f2009-06-30 17:15:40 -05001/*
2 * Copyright 2004,2007,2008 Freescale Semiconductor, Inc.
3 * (C) Copyright 2002, 2003 Motorola Inc.
4 * Xianghua Xiao (X.Xiao@motorola.com)
5 *
6 * (C) Copyright 2000
7 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
8 *
9 * See file CREDITS for list of people who contributed to this
10 * project.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License as
14 * published by the Free Software Foundation; either version 2 of
15 * the License, or (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
25 * MA 02111-1307 USA
26 */
27
28#include <config.h>
29#include <common.h>
Peter Tysera7303932009-06-30 17:15:42 -050030#include <asm/io.h>
Peter Tyser017f11f2009-06-30 17:15:40 -050031#include <asm/fsl_dma.h>
32
33#if defined(CONFIG_MPC85xx)
Peter Tysera7303932009-06-30 17:15:42 -050034ccsr_dma_t *dma_base = (void *)(CONFIG_SYS_MPC85xx_DMA_ADDR);
Peter Tyser017f11f2009-06-30 17:15:40 -050035#elif defined(CONFIG_MPC86xx)
Peter Tysera7303932009-06-30 17:15:42 -050036ccsr_dma_t *dma_base = (void *)(CONFIG_SYS_MPC86xx_DMA_ADDR);
Peter Tyser017f11f2009-06-30 17:15:40 -050037#else
38#error "Freescale DMA engine not supported on your processor"
39#endif
40
41static void dma_sync(void)
42{
43#if defined(CONFIG_MPC85xx)
44 asm("sync; isync; msync");
45#elif defined(CONFIG_MPC86xx)
46 asm("sync; isync");
47#endif
48}
49
50static uint dma_check(void) {
51 volatile fsl_dma_t *dma = &dma_base->dma[0];
Peter Tysera7303932009-06-30 17:15:42 -050052 uint status;
Peter Tyser017f11f2009-06-30 17:15:40 -050053
54 /* While the channel is busy, spin */
Peter Tysera7303932009-06-30 17:15:42 -050055 do {
56 status = in_be32(&dma->sr);
57 } while (status & FSL_DMA_SR_CB);
Peter Tyser017f11f2009-06-30 17:15:40 -050058
59 /* clear MR[CS] channel start bit */
Peter Tysera7303932009-06-30 17:15:42 -050060 out_be32(&dma->mr, in_be32(&dma->mr) & FSL_DMA_MR_CS);
Peter Tyser017f11f2009-06-30 17:15:40 -050061 dma_sync();
62
63 if (status != 0)
64 printf ("DMA Error: status = %x\n", status);
65
66 return status;
67}
68
69void dma_init(void) {
70 volatile fsl_dma_t *dma = &dma_base->dma[0];
71
Peter Tysera7303932009-06-30 17:15:42 -050072 out_be32(&dma->satr, FSL_DMA_SATR_SREAD_NO_SNOOP);
73 out_be32(&dma->datr, FSL_DMA_DATR_DWRITE_NO_SNOOP);
74 out_be32(&dma->sr, 0xffffffff); /* clear any errors */
Peter Tyser017f11f2009-06-30 17:15:40 -050075 dma_sync();
76}
77
78int dma_xfer(void *dest, uint count, void *src) {
79 volatile fsl_dma_t *dma = &dma_base->dma[0];
80
Peter Tysera7303932009-06-30 17:15:42 -050081 out_be32(&dma->dar, (uint) dest);
82 out_be32(&dma->sar, (uint) src);
83 out_be32(&dma->bcr, count);
Peter Tyser017f11f2009-06-30 17:15:40 -050084
85 /* Disable bandwidth control, use direct transfer mode */
Peter Tysera7303932009-06-30 17:15:42 -050086 out_be32(&dma->mr, FSL_DMA_MR_BWC_DIS | FSL_DMA_MR_CTM_DIRECT);
Peter Tyser017f11f2009-06-30 17:15:40 -050087 dma_sync();
88
89 /* Start the transfer */
Peter Tysera7303932009-06-30 17:15:42 -050090 out_be32(&dma->mr, FSL_DMA_MR_BWC_DIS |
91 FSL_DMA_MR_CTM_DIRECT |
92 FSL_DMA_MR_CS);
Peter Tyser017f11f2009-06-30 17:15:40 -050093 dma_sync();
94
95 return dma_check();
96}