fsl_dma.c 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /*
  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. #include <config.h>
  28. #include <common.h>
  29. #include <asm/fsl_dma.h>
  30. #if defined(CONFIG_MPC85xx)
  31. volatile ccsr_dma_t *dma_base = (void *)(CONFIG_SYS_MPC85xx_DMA_ADDR);
  32. #elif defined(CONFIG_MPC86xx)
  33. volatile ccsr_dma_t *dma_base = (void *)(CONFIG_SYS_MPC86xx_DMA_ADDR);
  34. #else
  35. #error "Freescale DMA engine not supported on your processor"
  36. #endif
  37. static void dma_sync(void)
  38. {
  39. #if defined(CONFIG_MPC85xx)
  40. asm("sync; isync; msync");
  41. #elif defined(CONFIG_MPC86xx)
  42. asm("sync; isync");
  43. #endif
  44. }
  45. static uint dma_check(void) {
  46. volatile fsl_dma_t *dma = &dma_base->dma[0];
  47. volatile uint status = dma->sr;
  48. /* While the channel is busy, spin */
  49. while (status & 4)
  50. status = dma->sr;
  51. /* clear MR[CS] channel start bit */
  52. dma->mr &= 1;
  53. dma_sync();
  54. if (status != 0)
  55. printf ("DMA Error: status = %x\n", status);
  56. return status;
  57. }
  58. void dma_init(void) {
  59. volatile fsl_dma_t *dma = &dma_base->dma[0];
  60. dma->satr = 0x00040000;
  61. dma->datr = 0x00040000;
  62. dma->sr = 0xffffffff; /* clear any errors */
  63. dma_sync();
  64. }
  65. int dma_xfer(void *dest, uint count, void *src) {
  66. volatile fsl_dma_t *dma = &dma_base->dma[0];
  67. dma->dar = (uint) dest;
  68. dma->sar = (uint) src;
  69. dma->bcr = count;
  70. /* Disable bandwidth control, use direct transfer mode */
  71. dma->mr = 0xf000004;
  72. dma_sync();
  73. /* Start the transfer */
  74. dma->mr = 0xf000005;
  75. dma_sync();
  76. return dma_check();
  77. }