fsl_dma.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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/io.h>
  30. #include <asm/fsl_dma.h>
  31. /* Controller can only transfer 2^26 - 1 bytes at a time */
  32. #define FSL_DMA_MAX_SIZE (0x3ffffff)
  33. #if defined(CONFIG_MPC85xx)
  34. ccsr_dma_t *dma_base = (void *)(CONFIG_SYS_MPC85xx_DMA_ADDR);
  35. #elif defined(CONFIG_MPC86xx)
  36. ccsr_dma_t *dma_base = (void *)(CONFIG_SYS_MPC86xx_DMA_ADDR);
  37. #else
  38. #error "Freescale DMA engine not supported on your processor"
  39. #endif
  40. static void dma_sync(void)
  41. {
  42. #if defined(CONFIG_MPC85xx)
  43. asm("sync; isync; msync");
  44. #elif defined(CONFIG_MPC86xx)
  45. asm("sync; isync");
  46. #endif
  47. }
  48. static uint dma_check(void) {
  49. volatile fsl_dma_t *dma = &dma_base->dma[0];
  50. uint status;
  51. /* While the channel is busy, spin */
  52. do {
  53. status = in_be32(&dma->sr);
  54. } while (status & FSL_DMA_SR_CB);
  55. /* clear MR[CS] channel start bit */
  56. out_be32(&dma->mr, in_be32(&dma->mr) & ~FSL_DMA_MR_CS);
  57. dma_sync();
  58. if (status != 0)
  59. printf ("DMA Error: status = %x\n", status);
  60. return status;
  61. }
  62. void dma_init(void) {
  63. volatile fsl_dma_t *dma = &dma_base->dma[0];
  64. out_be32(&dma->satr, FSL_DMA_SATR_SREAD_SNOOP);
  65. out_be32(&dma->datr, FSL_DMA_DATR_DWRITE_SNOOP);
  66. out_be32(&dma->sr, 0xffffffff); /* clear any errors */
  67. dma_sync();
  68. }
  69. int dmacpy(phys_addr_t dest, phys_addr_t src, phys_size_t count) {
  70. volatile fsl_dma_t *dma = &dma_base->dma[0];
  71. uint xfer_size;
  72. while (count) {
  73. xfer_size = MIN(FSL_DMA_MAX_SIZE, count);
  74. out_be32(&dma->dar, (uint) dest);
  75. out_be32(&dma->sar, (uint) src);
  76. out_be32(&dma->bcr, xfer_size);
  77. /* Disable bandwidth control, use direct transfer mode */
  78. out_be32(&dma->mr, FSL_DMA_MR_BWC_DIS | FSL_DMA_MR_CTM_DIRECT);
  79. dma_sync();
  80. /* Start the transfer */
  81. out_be32(&dma->mr, FSL_DMA_MR_BWC_DIS |
  82. FSL_DMA_MR_CTM_DIRECT |
  83. FSL_DMA_MR_CS);
  84. count -= xfer_size;
  85. src += xfer_size;
  86. dest += xfer_size;
  87. dma_sync();
  88. if (dma_check())
  89. return -1;
  90. }
  91. return 0;
  92. }
  93. #if (defined(CONFIG_DDR_ECC) && !defined(CONFIG_ECC_INIT_VIA_DDRCONTROLLER))
  94. void dma_meminit(uint val, uint size)
  95. {
  96. uint *p = 0;
  97. uint i = 0;
  98. for (*p = 0; p < (uint *)(8 * 1024); p++) {
  99. if (((uint)p & 0x1f) == 0)
  100. ppcDcbz((ulong)p);
  101. *p = (uint)CONFIG_MEM_INIT_VALUE;
  102. if (((uint)p & 0x1c) == 0x1c)
  103. ppcDcbf((ulong)p);
  104. }
  105. dmacpy(0x002000, 0, 0x002000); /* 8K */
  106. dmacpy(0x004000, 0, 0x004000); /* 16K */
  107. dmacpy(0x008000, 0, 0x008000); /* 32K */
  108. dmacpy(0x010000, 0, 0x010000); /* 64K */
  109. dmacpy(0x020000, 0, 0x020000); /* 128K */
  110. dmacpy(0x040000, 0, 0x040000); /* 256K */
  111. dmacpy(0x080000, 0, 0x080000); /* 512K */
  112. dmacpy(0x100000, 0, 0x100000); /* 1M */
  113. dmacpy(0x200000, 0, 0x200000); /* 2M */
  114. dmacpy(0x400000, 0, 0x400000); /* 4M */
  115. for (i = 1; i < size / 0x800000; i++)
  116. dmacpy((0x800000 * i), 0, 0x800000);
  117. }
  118. #endif