Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 1 | /* |
Dave Liu | f503592 | 2006-10-25 14:41:21 -0500 | [diff] [blame] | 2 | * Copyright (C) 2004-2006 Freescale Semiconductor, Inc. |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 3 | * |
| 4 | * See file CREDITS for list of people who contributed to this |
| 5 | * project. |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or |
| 8 | * modify it under the terms of the GNU General Public License as |
| 9 | * published by the Free Software Foundation; either version 2 of |
| 10 | * the License, or (at your option) any later version. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License |
| 18 | * along with this program; if not, write to the Free Software |
| 19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 20 | * MA 02111-1307 USA |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 21 | */ |
| 22 | |
| 23 | /* |
| 24 | * CPU specific code for the MPC83xx family. |
| 25 | * |
| 26 | * Derived from the MPC8260 and MPC85xx. |
| 27 | */ |
| 28 | |
| 29 | #include <common.h> |
| 30 | #include <watchdog.h> |
| 31 | #include <command.h> |
| 32 | #include <mpc83xx.h> |
Kumar Gala | 5bbb045 | 2006-01-11 16:48:10 -0600 | [diff] [blame] | 33 | #include <ft_build.h> |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 34 | #include <asm/processor.h> |
| 35 | |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 36 | DECLARE_GLOBAL_DATA_PTR; |
| 37 | |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 38 | |
| 39 | int checkcpu(void) |
| 40 | { |
Dave Liu | a46daea | 2006-11-03 19:33:44 -0600 | [diff] [blame] | 41 | volatile immap_t *immr; |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 42 | ulong clock = gd->cpu_clk; |
| 43 | u32 pvr = get_pvr(); |
Dave Liu | a46daea | 2006-11-03 19:33:44 -0600 | [diff] [blame] | 44 | u32 spridr; |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 45 | char buf[32]; |
| 46 | |
Timur Tabi | 386a280 | 2006-11-03 12:00:28 -0600 | [diff] [blame] | 47 | immr = (immap_t *)CFG_IMMR; |
Dave Liu | a46daea | 2006-11-03 19:33:44 -0600 | [diff] [blame] | 48 | |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 49 | if ((pvr & 0xFFFF0000) != PVR_83xx) { |
| 50 | puts("Not MPC83xx Family!!!\n"); |
| 51 | return -1; |
| 52 | } |
| 53 | |
Dave Liu | a46daea | 2006-11-03 19:33:44 -0600 | [diff] [blame] | 54 | spridr = immr->sysconf.spridr; |
| 55 | puts("CPU: "); |
| 56 | switch(spridr) { |
| 57 | case SPR_8349E_REV10: |
| 58 | case SPR_8349E_REV11: |
Xie Xiaobo | 800b753 | 2007-02-14 18:26:44 +0800 | [diff] [blame^] | 59 | case SPR_8349E_REV31: |
Dave Liu | a46daea | 2006-11-03 19:33:44 -0600 | [diff] [blame] | 60 | puts("MPC8349E, "); |
| 61 | break; |
| 62 | case SPR_8349_REV10: |
| 63 | case SPR_8349_REV11: |
Xie Xiaobo | 800b753 | 2007-02-14 18:26:44 +0800 | [diff] [blame^] | 64 | case SPR_8349_REV31: |
Dave Liu | a46daea | 2006-11-03 19:33:44 -0600 | [diff] [blame] | 65 | puts("MPC8349, "); |
| 66 | break; |
| 67 | case SPR_8347E_REV10_TBGA: |
| 68 | case SPR_8347E_REV11_TBGA: |
Xie Xiaobo | 800b753 | 2007-02-14 18:26:44 +0800 | [diff] [blame^] | 69 | case SPR_8347E_REV31_TBGA: |
Dave Liu | a46daea | 2006-11-03 19:33:44 -0600 | [diff] [blame] | 70 | case SPR_8347E_REV10_PBGA: |
| 71 | case SPR_8347E_REV11_PBGA: |
Xie Xiaobo | 800b753 | 2007-02-14 18:26:44 +0800 | [diff] [blame^] | 72 | case SPR_8347E_REV31_PBGA: |
Dave Liu | a46daea | 2006-11-03 19:33:44 -0600 | [diff] [blame] | 73 | puts("MPC8347E, "); |
| 74 | break; |
| 75 | case SPR_8347_REV10_TBGA: |
| 76 | case SPR_8347_REV11_TBGA: |
Xie Xiaobo | 800b753 | 2007-02-14 18:26:44 +0800 | [diff] [blame^] | 77 | case SPR_8347_REV31_TBGA: |
Dave Liu | a46daea | 2006-11-03 19:33:44 -0600 | [diff] [blame] | 78 | case SPR_8347_REV10_PBGA: |
| 79 | case SPR_8347_REV11_PBGA: |
Xie Xiaobo | 800b753 | 2007-02-14 18:26:44 +0800 | [diff] [blame^] | 80 | case SPR_8347_REV31_PBGA: |
Dave Liu | a46daea | 2006-11-03 19:33:44 -0600 | [diff] [blame] | 81 | puts("MPC8347, "); |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 82 | break; |
Dave Liu | a46daea | 2006-11-03 19:33:44 -0600 | [diff] [blame] | 83 | case SPR_8343E_REV10: |
| 84 | case SPR_8343E_REV11: |
Xie Xiaobo | 800b753 | 2007-02-14 18:26:44 +0800 | [diff] [blame^] | 85 | case SPR_8343E_REV31: |
Dave Liu | a46daea | 2006-11-03 19:33:44 -0600 | [diff] [blame] | 86 | puts("MPC8343E, "); |
| 87 | break; |
| 88 | case SPR_8343_REV10: |
| 89 | case SPR_8343_REV11: |
Xie Xiaobo | 800b753 | 2007-02-14 18:26:44 +0800 | [diff] [blame^] | 90 | case SPR_8343_REV31: |
Dave Liu | a46daea | 2006-11-03 19:33:44 -0600 | [diff] [blame] | 91 | puts("MPC8343, "); |
| 92 | break; |
| 93 | case SPR_8360E_REV10: |
| 94 | case SPR_8360E_REV11: |
| 95 | case SPR_8360E_REV12: |
| 96 | puts("MPC8360E, "); |
| 97 | break; |
| 98 | case SPR_8360_REV10: |
| 99 | case SPR_8360_REV11: |
| 100 | case SPR_8360_REV12: |
| 101 | puts("MPC8360, "); |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 102 | break; |
Dave Liu | e740c46 | 2006-12-07 21:13:15 +0800 | [diff] [blame] | 103 | case SPR_8323E_REV10: |
| 104 | case SPR_8323E_REV11: |
| 105 | puts("MPC8323E, "); |
| 106 | break; |
| 107 | case SPR_8323_REV10: |
| 108 | case SPR_8323_REV11: |
| 109 | puts("MPC8323, "); |
| 110 | break; |
| 111 | case SPR_8321E_REV10: |
| 112 | case SPR_8321E_REV11: |
| 113 | puts("MPC8321E, "); |
| 114 | break; |
| 115 | case SPR_8321_REV10: |
| 116 | case SPR_8321_REV11: |
| 117 | puts("MPC8321, "); |
| 118 | break; |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 119 | default: |
Xie Xiaobo | 800b753 | 2007-02-14 18:26:44 +0800 | [diff] [blame^] | 120 | puts("Rev: Unknown revision number.\nWarning: Unsupported cpu revision!\n"); |
| 121 | return 0; |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 122 | } |
Rafal Jaworowski | 384da5e | 2005-10-17 02:39:53 +0200 | [diff] [blame] | 123 | |
Kumar Gala | b7870e7 | 2007-01-30 14:08:30 -0600 | [diff] [blame] | 124 | #if defined(CONFIG_MPC834X) |
Xie Xiaobo | 800b753 | 2007-02-14 18:26:44 +0800 | [diff] [blame^] | 125 | /* Multiple revisons of 834x processors may have the same SPRIDR value. |
| 126 | * So use PVR to identify the revision number. |
| 127 | */ |
| 128 | printf("Rev: %02x at %s MHz\n", PVR_MAJ(pvr)<<4 | PVR_MIN(pvr), strmhz(buf, clock)); |
Dave Liu | a46daea | 2006-11-03 19:33:44 -0600 | [diff] [blame] | 129 | #else |
| 130 | printf("Rev: %02x at %s MHz\n", spridr & 0x0000FFFF, strmhz(buf, clock)); |
| 131 | #endif |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 132 | return 0; |
| 133 | } |
| 134 | |
| 135 | |
Timur Tabi | ab34754 | 2006-11-03 19:15:00 -0600 | [diff] [blame] | 136 | /* |
Timur Tabi | 054838e | 2006-10-31 18:44:42 -0600 | [diff] [blame] | 137 | * Program a UPM with the code supplied in the table. |
| 138 | * |
| 139 | * The 'dummy' variable is used to increment the MAD. 'dummy' is |
| 140 | * supposed to be a pointer to the memory of the device being |
| 141 | * programmed by the UPM. The data in the MDR is written into |
| 142 | * memory and the MAD is incremented every time there's a read |
| 143 | * from 'dummy'. Unfortunately, the current prototype for this |
| 144 | * function doesn't allow for passing the address of this |
| 145 | * device, and changing the prototype will break a number lots |
| 146 | * of other code, so we need to use a round-about way of finding |
| 147 | * the value for 'dummy'. |
| 148 | * |
| 149 | * The value can be extracted from the base address bits of the |
| 150 | * Base Register (BR) associated with the specific UPM. To find |
| 151 | * that BR, we need to scan all 8 BRs until we find the one that |
| 152 | * has its MSEL bits matching the UPM we want. Once we know the |
| 153 | * right BR, we can extract the base address bits from it. |
| 154 | * |
| 155 | * The MxMR and the BR and OR of the chosen bank should all be |
| 156 | * configured before calling this function. |
| 157 | * |
| 158 | * Parameters: |
| 159 | * upm: 0=UPMA, 1=UPMB, 2=UPMC |
| 160 | * table: Pointer to an array of values to program |
| 161 | * size: Number of elements in the array. Must be 64 or less. |
Timur Tabi | ab34754 | 2006-11-03 19:15:00 -0600 | [diff] [blame] | 162 | */ |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 163 | void upmconfig (uint upm, uint *table, uint size) |
| 164 | { |
Timur Tabi | 054838e | 2006-10-31 18:44:42 -0600 | [diff] [blame] | 165 | #if defined(CONFIG_MPC834X) |
Timur Tabi | 386a280 | 2006-11-03 12:00:28 -0600 | [diff] [blame] | 166 | volatile immap_t *immap = (immap_t *) CFG_IMMR; |
Timur Tabi | 054838e | 2006-10-31 18:44:42 -0600 | [diff] [blame] | 167 | volatile lbus83xx_t *lbus = &immap->lbus; |
| 168 | volatile uchar *dummy = NULL; |
| 169 | const u32 msel = (upm + 4) << BR_MSEL_SHIFT; /* What the MSEL field in BRn should be */ |
| 170 | volatile u32 *mxmr = &lbus->mamr + upm; /* Pointer to mamr, mbmr, or mcmr */ |
| 171 | uint i; |
| 172 | |
| 173 | /* Scan all the banks to determine the base address of the device */ |
| 174 | for (i = 0; i < 8; i++) { |
| 175 | if ((lbus->bank[i].br & BR_MSEL) == msel) { |
| 176 | dummy = (uchar *) (lbus->bank[i].br & BR_BA); |
| 177 | break; |
| 178 | } |
| 179 | } |
| 180 | |
| 181 | if (!dummy) { |
| 182 | printf("Error: %s() could not find matching BR\n", __FUNCTION__); |
| 183 | hang(); |
| 184 | } |
| 185 | |
| 186 | /* Set the OP field in the MxMR to "write" and the MAD field to 000000 */ |
| 187 | *mxmr = (*mxmr & 0xCFFFFFC0) | 0x10000000; |
| 188 | |
| 189 | for (i = 0; i < size; i++) { |
| 190 | lbus->mdr = table[i]; |
| 191 | __asm__ __volatile__ ("sync"); |
| 192 | *dummy; /* Write the value to memory and increment MAD */ |
| 193 | __asm__ __volatile__ ("sync"); |
| 194 | } |
| 195 | |
| 196 | /* Set the OP field in the MxMR to "normal" and the MAD field to 000000 */ |
| 197 | *mxmr &= 0xCFFFFFC0; |
| 198 | #else |
| 199 | printf("Error: %s() not defined for this configuration.\n", __FUNCTION__); |
| 200 | hang(); |
| 201 | #endif |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 202 | } |
| 203 | |
| 204 | |
| 205 | int |
| 206 | do_reset (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[]) |
| 207 | { |
Wolfgang Denk | 301d096 | 2005-08-05 19:49:35 +0200 | [diff] [blame] | 208 | ulong msr; |
| 209 | #ifndef MPC83xx_RESET |
| 210 | ulong addr; |
| 211 | #endif |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 212 | |
Timur Tabi | 386a280 | 2006-11-03 12:00:28 -0600 | [diff] [blame] | 213 | volatile immap_t *immap = (immap_t *) CFG_IMMR; |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 214 | |
| 215 | #ifdef MPC83xx_RESET |
| 216 | /* Interrupts and MMU off */ |
| 217 | __asm__ __volatile__ ("mfmsr %0":"=r" (msr):); |
| 218 | |
| 219 | msr &= ~( MSR_EE | MSR_IR | MSR_DR); |
| 220 | __asm__ __volatile__ ("mtmsr %0"::"r" (msr)); |
| 221 | |
| 222 | /* enable Reset Control Reg */ |
| 223 | immap->reset.rpr = 0x52535445; |
Marian Balakowicz | 919b187 | 2006-03-14 16:12:48 +0100 | [diff] [blame] | 224 | __asm__ __volatile__ ("sync"); |
| 225 | __asm__ __volatile__ ("isync"); |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 226 | |
| 227 | /* confirm Reset Control Reg is enabled */ |
| 228 | while(!((immap->reset.rcer) & RCER_CRE)); |
| 229 | |
| 230 | printf("Resetting the board."); |
| 231 | printf("\n"); |
| 232 | |
| 233 | udelay(200); |
| 234 | |
| 235 | /* perform reset, only one bit */ |
Wolfgang Denk | 301d096 | 2005-08-05 19:49:35 +0200 | [diff] [blame] | 236 | immap->reset.rcr = RCR_SWHR; |
| 237 | |
| 238 | #else /* ! MPC83xx_RESET */ |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 239 | |
Wolfgang Denk | 301d096 | 2005-08-05 19:49:35 +0200 | [diff] [blame] | 240 | immap->reset.rmr = RMR_CSRE; /* Checkstop Reset enable */ |
| 241 | |
| 242 | /* Interrupts and MMU off */ |
| 243 | __asm__ __volatile__ ("mfmsr %0":"=r" (msr):); |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 244 | |
| 245 | msr &= ~(MSR_ME | MSR_EE | MSR_IR | MSR_DR); |
| 246 | __asm__ __volatile__ ("mtmsr %0"::"r" (msr)); |
| 247 | |
| 248 | /* |
| 249 | * Trying to execute the next instruction at a non-existing address |
| 250 | * should cause a machine check, resulting in reset |
| 251 | */ |
| 252 | addr = CFG_RESET_ADDRESS; |
| 253 | |
| 254 | printf("resetting the board."); |
| 255 | printf("\n"); |
| 256 | ((void (*)(void)) addr) (); |
Wolfgang Denk | 301d096 | 2005-08-05 19:49:35 +0200 | [diff] [blame] | 257 | #endif /* MPC83xx_RESET */ |
| 258 | |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 259 | return 1; |
| 260 | } |
| 261 | |
| 262 | |
| 263 | /* |
| 264 | * Get timebase clock frequency (like cpu_clk in Hz) |
| 265 | */ |
| 266 | |
| 267 | unsigned long get_tbclk(void) |
| 268 | { |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 269 | ulong tbclk; |
| 270 | |
| 271 | tbclk = (gd->bus_clk + 3L) / 4L; |
| 272 | |
| 273 | return tbclk; |
| 274 | } |
| 275 | |
| 276 | |
| 277 | #if defined(CONFIG_WATCHDOG) |
| 278 | void watchdog_reset (void) |
| 279 | { |
Timur Tabi | 054838e | 2006-10-31 18:44:42 -0600 | [diff] [blame] | 280 | int re_enable = disable_interrupts(); |
| 281 | |
| 282 | /* Reset the 83xx watchdog */ |
Timur Tabi | 386a280 | 2006-11-03 12:00:28 -0600 | [diff] [blame] | 283 | volatile immap_t *immr = (immap_t *) CFG_IMMR; |
Timur Tabi | 054838e | 2006-10-31 18:44:42 -0600 | [diff] [blame] | 284 | immr->wdt.swsrr = 0x556c; |
| 285 | immr->wdt.swsrr = 0xaa39; |
| 286 | |
| 287 | if (re_enable) |
| 288 | enable_interrupts (); |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 289 | } |
Timur Tabi | 054838e | 2006-10-31 18:44:42 -0600 | [diff] [blame] | 290 | #endif |
Kumar Gala | 5bbb045 | 2006-01-11 16:48:10 -0600 | [diff] [blame] | 291 | |
| 292 | #if defined(CONFIG_OF_FLAT_TREE) |
| 293 | void |
| 294 | ft_cpu_setup(void *blob, bd_t *bd) |
| 295 | { |
| 296 | u32 *p; |
| 297 | int len; |
| 298 | ulong clock; |
| 299 | |
| 300 | clock = bd->bi_busfreq; |
| 301 | p = ft_get_prop(blob, "/cpus/" OF_CPU "/bus-frequency", &len); |
| 302 | if (p != NULL) |
| 303 | *p = cpu_to_be32(clock); |
| 304 | |
| 305 | p = ft_get_prop(blob, "/" OF_SOC "/bus-frequency", &len); |
| 306 | if (p != NULL) |
| 307 | *p = cpu_to_be32(clock); |
| 308 | |
| 309 | p = ft_get_prop(blob, "/" OF_SOC "/serial@4500/clock-frequency", &len); |
| 310 | if (p != NULL) |
| 311 | *p = cpu_to_be32(clock); |
| 312 | |
| 313 | p = ft_get_prop(blob, "/" OF_SOC "/serial@4600/clock-frequency", &len); |
| 314 | if (p != NULL) |
| 315 | *p = cpu_to_be32(clock); |
| 316 | |
| 317 | #ifdef CONFIG_MPC83XX_TSEC1 |
Kim Phillips | d99bd8b | 2006-11-01 00:07:25 -0600 | [diff] [blame] | 318 | p = ft_get_prop(blob, "/" OF_SOC "/ethernet@24000/local-mac-address", &len); |
Kim Phillips | 24f63e9 | 2007-01-30 16:15:21 -0600 | [diff] [blame] | 319 | if (p != NULL) |
Kumar Gala | 5bbb045 | 2006-01-11 16:48:10 -0600 | [diff] [blame] | 320 | memcpy(p, bd->bi_enetaddr, 6); |
| 321 | #endif |
| 322 | |
| 323 | #ifdef CONFIG_MPC83XX_TSEC2 |
Kim Phillips | d99bd8b | 2006-11-01 00:07:25 -0600 | [diff] [blame] | 324 | p = ft_get_prop(blob, "/" OF_SOC "/ethernet@25000/local-mac-address", &len); |
Kim Phillips | 24f63e9 | 2007-01-30 16:15:21 -0600 | [diff] [blame] | 325 | if (p != NULL) |
Kumar Gala | 5bbb045 | 2006-01-11 16:48:10 -0600 | [diff] [blame] | 326 | memcpy(p, bd->bi_enet1addr, 6); |
| 327 | #endif |
| 328 | } |
| 329 | #endif |
Marian Balakowicz | 7ec9ebc | 2006-03-14 16:14:48 +0100 | [diff] [blame] | 330 | |
| 331 | #if defined(CONFIG_DDR_ECC) |
| 332 | void dma_init(void) |
| 333 | { |
Timur Tabi | 386a280 | 2006-11-03 12:00:28 -0600 | [diff] [blame] | 334 | volatile immap_t *immap = (immap_t *)CFG_IMMR; |
Dave Liu | f503592 | 2006-10-25 14:41:21 -0500 | [diff] [blame] | 335 | volatile dma83xx_t *dma = &immap->dma; |
Marian Balakowicz | 7ec9ebc | 2006-03-14 16:14:48 +0100 | [diff] [blame] | 336 | volatile u32 status = swab32(dma->dmasr0); |
| 337 | volatile u32 dmamr0 = swab32(dma->dmamr0); |
| 338 | |
| 339 | debug("DMA-init\n"); |
| 340 | |
| 341 | /* initialize DMASARn, DMADAR and DMAABCRn */ |
| 342 | dma->dmadar0 = (u32)0; |
| 343 | dma->dmasar0 = (u32)0; |
| 344 | dma->dmabcr0 = 0; |
| 345 | |
| 346 | __asm__ __volatile__ ("sync"); |
| 347 | __asm__ __volatile__ ("isync"); |
| 348 | |
| 349 | /* clear CS bit */ |
| 350 | dmamr0 &= ~DMA_CHANNEL_START; |
| 351 | dma->dmamr0 = swab32(dmamr0); |
| 352 | __asm__ __volatile__ ("sync"); |
| 353 | __asm__ __volatile__ ("isync"); |
| 354 | |
| 355 | /* while the channel is busy, spin */ |
| 356 | while(status & DMA_CHANNEL_BUSY) { |
| 357 | status = swab32(dma->dmasr0); |
| 358 | } |
| 359 | |
| 360 | debug("DMA-init end\n"); |
| 361 | } |
| 362 | |
| 363 | uint dma_check(void) |
| 364 | { |
Timur Tabi | 386a280 | 2006-11-03 12:00:28 -0600 | [diff] [blame] | 365 | volatile immap_t *immap = (immap_t *)CFG_IMMR; |
Dave Liu | f503592 | 2006-10-25 14:41:21 -0500 | [diff] [blame] | 366 | volatile dma83xx_t *dma = &immap->dma; |
Marian Balakowicz | 7ec9ebc | 2006-03-14 16:14:48 +0100 | [diff] [blame] | 367 | volatile u32 status = swab32(dma->dmasr0); |
| 368 | volatile u32 byte_count = swab32(dma->dmabcr0); |
| 369 | |
| 370 | /* while the channel is busy, spin */ |
| 371 | while (status & DMA_CHANNEL_BUSY) { |
| 372 | status = swab32(dma->dmasr0); |
| 373 | } |
| 374 | |
| 375 | if (status & DMA_CHANNEL_TRANSFER_ERROR) { |
| 376 | printf ("DMA Error: status = %x @ %d\n", status, byte_count); |
| 377 | } |
| 378 | |
| 379 | return status; |
| 380 | } |
| 381 | |
| 382 | int dma_xfer(void *dest, u32 count, void *src) |
| 383 | { |
Timur Tabi | 386a280 | 2006-11-03 12:00:28 -0600 | [diff] [blame] | 384 | volatile immap_t *immap = (immap_t *)CFG_IMMR; |
Dave Liu | f503592 | 2006-10-25 14:41:21 -0500 | [diff] [blame] | 385 | volatile dma83xx_t *dma = &immap->dma; |
Marian Balakowicz | 7ec9ebc | 2006-03-14 16:14:48 +0100 | [diff] [blame] | 386 | volatile u32 dmamr0; |
| 387 | |
| 388 | /* initialize DMASARn, DMADAR and DMAABCRn */ |
| 389 | dma->dmadar0 = swab32((u32)dest); |
| 390 | dma->dmasar0 = swab32((u32)src); |
| 391 | dma->dmabcr0 = swab32(count); |
| 392 | |
| 393 | __asm__ __volatile__ ("sync"); |
| 394 | __asm__ __volatile__ ("isync"); |
| 395 | |
| 396 | /* init direct transfer, clear CS bit */ |
| 397 | dmamr0 = (DMA_CHANNEL_TRANSFER_MODE_DIRECT | |
| 398 | DMA_CHANNEL_SOURCE_ADDRESS_HOLD_8B | |
| 399 | DMA_CHANNEL_SOURCE_ADRESSS_HOLD_EN); |
Wolfgang Denk | ebd3deb | 2006-04-16 10:51:58 +0200 | [diff] [blame] | 400 | |
Marian Balakowicz | 7ec9ebc | 2006-03-14 16:14:48 +0100 | [diff] [blame] | 401 | dma->dmamr0 = swab32(dmamr0); |
| 402 | |
| 403 | __asm__ __volatile__ ("sync"); |
| 404 | __asm__ __volatile__ ("isync"); |
| 405 | |
| 406 | /* set CS to start DMA transfer */ |
| 407 | dmamr0 |= DMA_CHANNEL_START; |
| 408 | dma->dmamr0 = swab32(dmamr0); |
| 409 | __asm__ __volatile__ ("sync"); |
| 410 | __asm__ __volatile__ ("isync"); |
| 411 | |
| 412 | return ((int)dma_check()); |
| 413 | } |
| 414 | #endif /*CONFIG_DDR_ECC*/ |