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> |
| 33 | #include <asm/processor.h> |
Gerald Van Baren | d6abef4 | 2007-03-31 12:23:51 -0400 | [diff] [blame] | 34 | #if defined(CONFIG_OF_FLAT_TREE) |
| 35 | #include <ft_build.h> |
Jerry Van Baren | 1a96f62 | 2007-07-04 21:27:30 -0400 | [diff] [blame] | 36 | #elif defined(CONFIG_OF_LIBFDT) |
Gerald Van Baren | d6abef4 | 2007-03-31 12:23:51 -0400 | [diff] [blame] | 37 | #include <libfdt.h> |
| 38 | #include <libfdt_env.h> |
| 39 | #endif |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 40 | |
Wolfgang Denk | 6405a15 | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 41 | DECLARE_GLOBAL_DATA_PTR; |
| 42 | |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 43 | |
| 44 | int checkcpu(void) |
| 45 | { |
Dave Liu | a46daea | 2006-11-03 19:33:44 -0600 | [diff] [blame] | 46 | volatile immap_t *immr; |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 47 | ulong clock = gd->cpu_clk; |
| 48 | u32 pvr = get_pvr(); |
Dave Liu | a46daea | 2006-11-03 19:33:44 -0600 | [diff] [blame] | 49 | u32 spridr; |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 50 | char buf[32]; |
| 51 | |
Timur Tabi | 386a280 | 2006-11-03 12:00:28 -0600 | [diff] [blame] | 52 | immr = (immap_t *)CFG_IMMR; |
Dave Liu | a46daea | 2006-11-03 19:33:44 -0600 | [diff] [blame] | 53 | |
Kim Phillips | d82b077 | 2007-04-30 15:26:21 -0500 | [diff] [blame] | 54 | puts("CPU: "); |
Scott Wood | 7206a99 | 2007-04-16 14:34:16 -0500 | [diff] [blame] | 55 | |
| 56 | switch (pvr & 0xffff0000) { |
| 57 | case PVR_E300C1: |
| 58 | printf("e300c1, "); |
| 59 | break; |
| 60 | |
| 61 | case PVR_E300C2: |
| 62 | printf("e300c2, "); |
| 63 | break; |
| 64 | |
| 65 | case PVR_E300C3: |
| 66 | printf("e300c3, "); |
| 67 | break; |
| 68 | |
| 69 | default: |
| 70 | printf("Unknown core, "); |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 71 | } |
| 72 | |
Dave Liu | a46daea | 2006-11-03 19:33:44 -0600 | [diff] [blame] | 73 | spridr = immr->sysconf.spridr; |
Dave Liu | a46daea | 2006-11-03 19:33:44 -0600 | [diff] [blame] | 74 | switch(spridr) { |
| 75 | case SPR_8349E_REV10: |
| 76 | case SPR_8349E_REV11: |
Xie Xiaobo | 800b753 | 2007-02-14 18:26:44 +0800 | [diff] [blame] | 77 | case SPR_8349E_REV31: |
Dave Liu | a46daea | 2006-11-03 19:33:44 -0600 | [diff] [blame] | 78 | puts("MPC8349E, "); |
| 79 | break; |
| 80 | case SPR_8349_REV10: |
| 81 | case SPR_8349_REV11: |
Xie Xiaobo | 800b753 | 2007-02-14 18:26:44 +0800 | [diff] [blame] | 82 | case SPR_8349_REV31: |
Dave Liu | a46daea | 2006-11-03 19:33:44 -0600 | [diff] [blame] | 83 | puts("MPC8349, "); |
| 84 | break; |
| 85 | case SPR_8347E_REV10_TBGA: |
| 86 | case SPR_8347E_REV11_TBGA: |
Xie Xiaobo | 800b753 | 2007-02-14 18:26:44 +0800 | [diff] [blame] | 87 | case SPR_8347E_REV31_TBGA: |
Dave Liu | a46daea | 2006-11-03 19:33:44 -0600 | [diff] [blame] | 88 | case SPR_8347E_REV10_PBGA: |
| 89 | case SPR_8347E_REV11_PBGA: |
Xie Xiaobo | 800b753 | 2007-02-14 18:26:44 +0800 | [diff] [blame] | 90 | case SPR_8347E_REV31_PBGA: |
Dave Liu | a46daea | 2006-11-03 19:33:44 -0600 | [diff] [blame] | 91 | puts("MPC8347E, "); |
| 92 | break; |
| 93 | case SPR_8347_REV10_TBGA: |
| 94 | case SPR_8347_REV11_TBGA: |
Xie Xiaobo | 800b753 | 2007-02-14 18:26:44 +0800 | [diff] [blame] | 95 | case SPR_8347_REV31_TBGA: |
Dave Liu | a46daea | 2006-11-03 19:33:44 -0600 | [diff] [blame] | 96 | case SPR_8347_REV10_PBGA: |
| 97 | case SPR_8347_REV11_PBGA: |
Xie Xiaobo | 800b753 | 2007-02-14 18:26:44 +0800 | [diff] [blame] | 98 | case SPR_8347_REV31_PBGA: |
Dave Liu | a46daea | 2006-11-03 19:33:44 -0600 | [diff] [blame] | 99 | puts("MPC8347, "); |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 100 | break; |
Dave Liu | a46daea | 2006-11-03 19:33:44 -0600 | [diff] [blame] | 101 | case SPR_8343E_REV10: |
| 102 | case SPR_8343E_REV11: |
Xie Xiaobo | 800b753 | 2007-02-14 18:26:44 +0800 | [diff] [blame] | 103 | case SPR_8343E_REV31: |
Dave Liu | a46daea | 2006-11-03 19:33:44 -0600 | [diff] [blame] | 104 | puts("MPC8343E, "); |
| 105 | break; |
| 106 | case SPR_8343_REV10: |
| 107 | case SPR_8343_REV11: |
Xie Xiaobo | 800b753 | 2007-02-14 18:26:44 +0800 | [diff] [blame] | 108 | case SPR_8343_REV31: |
Dave Liu | a46daea | 2006-11-03 19:33:44 -0600 | [diff] [blame] | 109 | puts("MPC8343, "); |
| 110 | break; |
| 111 | case SPR_8360E_REV10: |
| 112 | case SPR_8360E_REV11: |
| 113 | case SPR_8360E_REV12: |
Xie Xiaobo | a9be42a | 2007-02-14 18:27:06 +0800 | [diff] [blame] | 114 | case SPR_8360E_REV20: |
Lee Nipper | f600cf3 | 2007-06-14 20:07:33 -0500 | [diff] [blame] | 115 | case SPR_8360E_REV21: |
Dave Liu | a46daea | 2006-11-03 19:33:44 -0600 | [diff] [blame] | 116 | puts("MPC8360E, "); |
| 117 | break; |
| 118 | case SPR_8360_REV10: |
| 119 | case SPR_8360_REV11: |
| 120 | case SPR_8360_REV12: |
Xie Xiaobo | a9be42a | 2007-02-14 18:27:06 +0800 | [diff] [blame] | 121 | case SPR_8360_REV20: |
Lee Nipper | f600cf3 | 2007-06-14 20:07:33 -0500 | [diff] [blame] | 122 | case SPR_8360_REV21: |
Dave Liu | a46daea | 2006-11-03 19:33:44 -0600 | [diff] [blame] | 123 | puts("MPC8360, "); |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 124 | break; |
Dave Liu | e740c46 | 2006-12-07 21:13:15 +0800 | [diff] [blame] | 125 | case SPR_8323E_REV10: |
| 126 | case SPR_8323E_REV11: |
| 127 | puts("MPC8323E, "); |
| 128 | break; |
| 129 | case SPR_8323_REV10: |
| 130 | case SPR_8323_REV11: |
| 131 | puts("MPC8323, "); |
| 132 | break; |
| 133 | case SPR_8321E_REV10: |
| 134 | case SPR_8321E_REV11: |
| 135 | puts("MPC8321E, "); |
| 136 | break; |
| 137 | case SPR_8321_REV10: |
| 138 | case SPR_8321_REV11: |
| 139 | puts("MPC8321, "); |
| 140 | break; |
Scott Wood | f13983e | 2007-04-16 14:34:15 -0500 | [diff] [blame] | 141 | case SPR_8311_REV10: |
| 142 | puts("MPC8311, "); |
| 143 | break; |
| 144 | case SPR_8311E_REV10: |
| 145 | puts("MPC8311E, "); |
| 146 | break; |
| 147 | case SPR_8313_REV10: |
| 148 | puts("MPC8313, "); |
| 149 | break; |
| 150 | case SPR_8313E_REV10: |
| 151 | puts("MPC8313E, "); |
| 152 | break; |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 153 | default: |
Lee Nipper | f600cf3 | 2007-06-14 20:07:33 -0500 | [diff] [blame] | 154 | printf("Rev: Unknown revision number:%08x\n" |
| 155 | "Warning: Unsupported cpu revision!\n",spridr); |
Xie Xiaobo | 800b753 | 2007-02-14 18:26:44 +0800 | [diff] [blame] | 156 | return 0; |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 157 | } |
Rafal Jaworowski | 384da5e | 2005-10-17 02:39:53 +0200 | [diff] [blame] | 158 | |
Kumar Gala | b7870e7 | 2007-01-30 14:08:30 -0600 | [diff] [blame] | 159 | #if defined(CONFIG_MPC834X) |
Xie Xiaobo | 800b753 | 2007-02-14 18:26:44 +0800 | [diff] [blame] | 160 | /* Multiple revisons of 834x processors may have the same SPRIDR value. |
| 161 | * So use PVR to identify the revision number. |
| 162 | */ |
Kim Phillips | d82b077 | 2007-04-30 15:26:21 -0500 | [diff] [blame] | 163 | printf("Rev: %02x at %s MHz", PVR_MAJ(pvr)<<4 | PVR_MIN(pvr), strmhz(buf, clock)); |
Dave Liu | a46daea | 2006-11-03 19:33:44 -0600 | [diff] [blame] | 164 | #else |
Kim Phillips | d82b077 | 2007-04-30 15:26:21 -0500 | [diff] [blame] | 165 | printf("Rev: %02x at %s MHz", spridr & 0x0000FFFF, strmhz(buf, clock)); |
Dave Liu | a46daea | 2006-11-03 19:33:44 -0600 | [diff] [blame] | 166 | #endif |
Kim Phillips | d82b077 | 2007-04-30 15:26:21 -0500 | [diff] [blame] | 167 | printf(", CSB: %4d MHz\n", gd->csb_clk / 1000000); |
| 168 | |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 169 | return 0; |
| 170 | } |
| 171 | |
| 172 | |
Timur Tabi | ab34754 | 2006-11-03 19:15:00 -0600 | [diff] [blame] | 173 | /* |
Timur Tabi | 054838e | 2006-10-31 18:44:42 -0600 | [diff] [blame] | 174 | * Program a UPM with the code supplied in the table. |
| 175 | * |
| 176 | * The 'dummy' variable is used to increment the MAD. 'dummy' is |
| 177 | * supposed to be a pointer to the memory of the device being |
| 178 | * programmed by the UPM. The data in the MDR is written into |
| 179 | * memory and the MAD is incremented every time there's a read |
| 180 | * from 'dummy'. Unfortunately, the current prototype for this |
| 181 | * function doesn't allow for passing the address of this |
| 182 | * device, and changing the prototype will break a number lots |
| 183 | * of other code, so we need to use a round-about way of finding |
| 184 | * the value for 'dummy'. |
| 185 | * |
| 186 | * The value can be extracted from the base address bits of the |
| 187 | * Base Register (BR) associated with the specific UPM. To find |
| 188 | * that BR, we need to scan all 8 BRs until we find the one that |
| 189 | * has its MSEL bits matching the UPM we want. Once we know the |
| 190 | * right BR, we can extract the base address bits from it. |
| 191 | * |
| 192 | * The MxMR and the BR and OR of the chosen bank should all be |
| 193 | * configured before calling this function. |
| 194 | * |
| 195 | * Parameters: |
| 196 | * upm: 0=UPMA, 1=UPMB, 2=UPMC |
| 197 | * table: Pointer to an array of values to program |
| 198 | * size: Number of elements in the array. Must be 64 or less. |
Timur Tabi | ab34754 | 2006-11-03 19:15:00 -0600 | [diff] [blame] | 199 | */ |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 200 | void upmconfig (uint upm, uint *table, uint size) |
| 201 | { |
Timur Tabi | 054838e | 2006-10-31 18:44:42 -0600 | [diff] [blame] | 202 | #if defined(CONFIG_MPC834X) |
Timur Tabi | 386a280 | 2006-11-03 12:00:28 -0600 | [diff] [blame] | 203 | volatile immap_t *immap = (immap_t *) CFG_IMMR; |
Timur Tabi | 054838e | 2006-10-31 18:44:42 -0600 | [diff] [blame] | 204 | volatile lbus83xx_t *lbus = &immap->lbus; |
| 205 | volatile uchar *dummy = NULL; |
| 206 | const u32 msel = (upm + 4) << BR_MSEL_SHIFT; /* What the MSEL field in BRn should be */ |
| 207 | volatile u32 *mxmr = &lbus->mamr + upm; /* Pointer to mamr, mbmr, or mcmr */ |
| 208 | uint i; |
| 209 | |
| 210 | /* Scan all the banks to determine the base address of the device */ |
| 211 | for (i = 0; i < 8; i++) { |
| 212 | if ((lbus->bank[i].br & BR_MSEL) == msel) { |
| 213 | dummy = (uchar *) (lbus->bank[i].br & BR_BA); |
| 214 | break; |
| 215 | } |
| 216 | } |
| 217 | |
| 218 | if (!dummy) { |
| 219 | printf("Error: %s() could not find matching BR\n", __FUNCTION__); |
| 220 | hang(); |
| 221 | } |
| 222 | |
| 223 | /* Set the OP field in the MxMR to "write" and the MAD field to 000000 */ |
| 224 | *mxmr = (*mxmr & 0xCFFFFFC0) | 0x10000000; |
| 225 | |
| 226 | for (i = 0; i < size; i++) { |
| 227 | lbus->mdr = table[i]; |
| 228 | __asm__ __volatile__ ("sync"); |
| 229 | *dummy; /* Write the value to memory and increment MAD */ |
| 230 | __asm__ __volatile__ ("sync"); |
| 231 | } |
| 232 | |
| 233 | /* Set the OP field in the MxMR to "normal" and the MAD field to 000000 */ |
| 234 | *mxmr &= 0xCFFFFFC0; |
| 235 | #else |
| 236 | printf("Error: %s() not defined for this configuration.\n", __FUNCTION__); |
| 237 | hang(); |
| 238 | #endif |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 239 | } |
| 240 | |
| 241 | |
| 242 | int |
| 243 | do_reset (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[]) |
| 244 | { |
Wolfgang Denk | 301d096 | 2005-08-05 19:49:35 +0200 | [diff] [blame] | 245 | ulong msr; |
| 246 | #ifndef MPC83xx_RESET |
| 247 | ulong addr; |
| 248 | #endif |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 249 | |
Timur Tabi | 386a280 | 2006-11-03 12:00:28 -0600 | [diff] [blame] | 250 | volatile immap_t *immap = (immap_t *) CFG_IMMR; |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 251 | |
| 252 | #ifdef MPC83xx_RESET |
| 253 | /* Interrupts and MMU off */ |
| 254 | __asm__ __volatile__ ("mfmsr %0":"=r" (msr):); |
| 255 | |
| 256 | msr &= ~( MSR_EE | MSR_IR | MSR_DR); |
| 257 | __asm__ __volatile__ ("mtmsr %0"::"r" (msr)); |
| 258 | |
| 259 | /* enable Reset Control Reg */ |
| 260 | immap->reset.rpr = 0x52535445; |
Marian Balakowicz | 919b187 | 2006-03-14 16:12:48 +0100 | [diff] [blame] | 261 | __asm__ __volatile__ ("sync"); |
| 262 | __asm__ __volatile__ ("isync"); |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 263 | |
| 264 | /* confirm Reset Control Reg is enabled */ |
| 265 | while(!((immap->reset.rcer) & RCER_CRE)); |
| 266 | |
| 267 | printf("Resetting the board."); |
| 268 | printf("\n"); |
| 269 | |
| 270 | udelay(200); |
| 271 | |
| 272 | /* perform reset, only one bit */ |
Wolfgang Denk | 301d096 | 2005-08-05 19:49:35 +0200 | [diff] [blame] | 273 | immap->reset.rcr = RCR_SWHR; |
| 274 | |
| 275 | #else /* ! MPC83xx_RESET */ |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 276 | |
Wolfgang Denk | 301d096 | 2005-08-05 19:49:35 +0200 | [diff] [blame] | 277 | immap->reset.rmr = RMR_CSRE; /* Checkstop Reset enable */ |
| 278 | |
| 279 | /* Interrupts and MMU off */ |
| 280 | __asm__ __volatile__ ("mfmsr %0":"=r" (msr):); |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 281 | |
| 282 | msr &= ~(MSR_ME | MSR_EE | MSR_IR | MSR_DR); |
| 283 | __asm__ __volatile__ ("mtmsr %0"::"r" (msr)); |
| 284 | |
| 285 | /* |
| 286 | * Trying to execute the next instruction at a non-existing address |
| 287 | * should cause a machine check, resulting in reset |
| 288 | */ |
| 289 | addr = CFG_RESET_ADDRESS; |
| 290 | |
| 291 | printf("resetting the board."); |
| 292 | printf("\n"); |
| 293 | ((void (*)(void)) addr) (); |
Wolfgang Denk | 301d096 | 2005-08-05 19:49:35 +0200 | [diff] [blame] | 294 | #endif /* MPC83xx_RESET */ |
| 295 | |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 296 | return 1; |
| 297 | } |
| 298 | |
| 299 | |
| 300 | /* |
| 301 | * Get timebase clock frequency (like cpu_clk in Hz) |
| 302 | */ |
| 303 | |
| 304 | unsigned long get_tbclk(void) |
| 305 | { |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 306 | ulong tbclk; |
| 307 | |
| 308 | tbclk = (gd->bus_clk + 3L) / 4L; |
| 309 | |
| 310 | return tbclk; |
| 311 | } |
| 312 | |
| 313 | |
| 314 | #if defined(CONFIG_WATCHDOG) |
| 315 | void watchdog_reset (void) |
| 316 | { |
Timur Tabi | 054838e | 2006-10-31 18:44:42 -0600 | [diff] [blame] | 317 | int re_enable = disable_interrupts(); |
| 318 | |
| 319 | /* Reset the 83xx watchdog */ |
Timur Tabi | 386a280 | 2006-11-03 12:00:28 -0600 | [diff] [blame] | 320 | volatile immap_t *immr = (immap_t *) CFG_IMMR; |
Timur Tabi | 054838e | 2006-10-31 18:44:42 -0600 | [diff] [blame] | 321 | immr->wdt.swsrr = 0x556c; |
| 322 | immr->wdt.swsrr = 0xaa39; |
| 323 | |
| 324 | if (re_enable) |
| 325 | enable_interrupts (); |
Eran Liberty | 9095d4a | 2005-07-28 10:08:46 -0500 | [diff] [blame] | 326 | } |
Timur Tabi | 054838e | 2006-10-31 18:44:42 -0600 | [diff] [blame] | 327 | #endif |
Kumar Gala | 5bbb045 | 2006-01-11 16:48:10 -0600 | [diff] [blame] | 328 | |
Gerald Van Baren | d6abef4 | 2007-03-31 12:23:51 -0400 | [diff] [blame] | 329 | #if defined(CONFIG_OF_LIBFDT) |
| 330 | |
| 331 | /* |
Gerald Van Baren | 2f73416 | 2007-04-15 13:54:26 -0400 | [diff] [blame] | 332 | * "Setter" functions used to add/modify FDT entries. |
| 333 | */ |
Kim Phillips | 60dc3fc | 2007-07-25 19:25:22 -0500 | [diff] [blame] | 334 | static int fdt_set_eth0(void *blob, int nodeoffset, const char *name, bd_t *bd) |
Gerald Van Baren | 2f73416 | 2007-04-15 13:54:26 -0400 | [diff] [blame] | 335 | { |
| 336 | /* |
| 337 | * Fix it up if it exists, don't create it if it doesn't exist. |
| 338 | */ |
Kim Phillips | 60dc3fc | 2007-07-25 19:25:22 -0500 | [diff] [blame] | 339 | if (fdt_get_property(blob, nodeoffset, name, 0)) { |
| 340 | return fdt_setprop(blob, nodeoffset, name, bd->bi_enetaddr, 6); |
Gerald Van Baren | 2f73416 | 2007-04-15 13:54:26 -0400 | [diff] [blame] | 341 | } |
Jerry Van Baren | a4deb4d | 2007-07-04 21:34:24 -0400 | [diff] [blame] | 342 | return 0; |
Gerald Van Baren | 2f73416 | 2007-04-15 13:54:26 -0400 | [diff] [blame] | 343 | } |
| 344 | #ifdef CONFIG_HAS_ETH1 |
| 345 | /* second onboard ethernet port */ |
Kim Phillips | 60dc3fc | 2007-07-25 19:25:22 -0500 | [diff] [blame] | 346 | static int fdt_set_eth1(void *blob, int nodeoffset, const char *name, bd_t *bd) |
Gerald Van Baren | 2f73416 | 2007-04-15 13:54:26 -0400 | [diff] [blame] | 347 | { |
| 348 | /* |
| 349 | * Fix it up if it exists, don't create it if it doesn't exist. |
| 350 | */ |
Kim Phillips | 60dc3fc | 2007-07-25 19:25:22 -0500 | [diff] [blame] | 351 | if (fdt_get_property(blob, nodeoffset, name, 0)) { |
| 352 | return fdt_setprop(blob, nodeoffset, name, bd->bi_enet1addr, 6); |
Gerald Van Baren | 2f73416 | 2007-04-15 13:54:26 -0400 | [diff] [blame] | 353 | } |
Jerry Van Baren | a4deb4d | 2007-07-04 21:34:24 -0400 | [diff] [blame] | 354 | return 0; |
Gerald Van Baren | 2f73416 | 2007-04-15 13:54:26 -0400 | [diff] [blame] | 355 | } |
| 356 | #endif |
| 357 | #ifdef CONFIG_HAS_ETH2 |
| 358 | /* third onboard ethernet port */ |
Kim Phillips | 60dc3fc | 2007-07-25 19:25:22 -0500 | [diff] [blame] | 359 | static int fdt_set_eth2(void *blob, int nodeoffset, const char *name, bd_t *bd) |
Gerald Van Baren | 2f73416 | 2007-04-15 13:54:26 -0400 | [diff] [blame] | 360 | { |
| 361 | /* |
| 362 | * Fix it up if it exists, don't create it if it doesn't exist. |
| 363 | */ |
Kim Phillips | 60dc3fc | 2007-07-25 19:25:22 -0500 | [diff] [blame] | 364 | if (fdt_get_property(blob, nodeoffset, name, 0)) { |
| 365 | return fdt_setprop(blob, nodeoffset, name, bd->bi_enet2addr, 6); |
Gerald Van Baren | 2f73416 | 2007-04-15 13:54:26 -0400 | [diff] [blame] | 366 | } |
Jerry Van Baren | a4deb4d | 2007-07-04 21:34:24 -0400 | [diff] [blame] | 367 | return 0; |
Gerald Van Baren | 2f73416 | 2007-04-15 13:54:26 -0400 | [diff] [blame] | 368 | } |
| 369 | #endif |
| 370 | #ifdef CONFIG_HAS_ETH3 |
| 371 | /* fourth onboard ethernet port */ |
Kim Phillips | 60dc3fc | 2007-07-25 19:25:22 -0500 | [diff] [blame] | 372 | static int fdt_set_eth3(void *blob, int nodeoffset, const char *name, bd_t *bd) |
Gerald Van Baren | 2f73416 | 2007-04-15 13:54:26 -0400 | [diff] [blame] | 373 | { |
| 374 | /* |
| 375 | * Fix it up if it exists, don't create it if it doesn't exist. |
| 376 | */ |
Kim Phillips | 60dc3fc | 2007-07-25 19:25:22 -0500 | [diff] [blame] | 377 | if (fdt_get_property(blob, nodeoffset, name, 0)) { |
| 378 | return fdt_setprop(blob, nodeoffset, name, bd->bi_enet3addr, 6); |
Gerald Van Baren | 2f73416 | 2007-04-15 13:54:26 -0400 | [diff] [blame] | 379 | } |
Jerry Van Baren | a4deb4d | 2007-07-04 21:34:24 -0400 | [diff] [blame] | 380 | return 0; |
Gerald Van Baren | 2f73416 | 2007-04-15 13:54:26 -0400 | [diff] [blame] | 381 | } |
| 382 | #endif |
| 383 | |
Kim Phillips | 60dc3fc | 2007-07-25 19:25:22 -0500 | [diff] [blame] | 384 | static int fdt_set_busfreq(void *blob, int nodeoffset, const char *name, bd_t *bd) |
Gerald Van Baren | 2f73416 | 2007-04-15 13:54:26 -0400 | [diff] [blame] | 385 | { |
| 386 | u32 tmp; |
| 387 | /* |
| 388 | * Create or update the property. |
| 389 | */ |
| 390 | tmp = cpu_to_be32(bd->bi_busfreq); |
Kim Phillips | 60dc3fc | 2007-07-25 19:25:22 -0500 | [diff] [blame] | 391 | return fdt_setprop(blob, nodeoffset, name, &tmp, sizeof(tmp)); |
Gerald Van Baren | 2f73416 | 2007-04-15 13:54:26 -0400 | [diff] [blame] | 392 | } |
| 393 | |
Kim Phillips | 60dc3fc | 2007-07-25 19:25:22 -0500 | [diff] [blame] | 394 | static int fdt_set_tbfreq(void *blob, int nodeoffset, const char *name, bd_t *bd) |
Jerry Van Baren | a4deb4d | 2007-07-04 21:34:24 -0400 | [diff] [blame] | 395 | { |
| 396 | u32 tmp; |
| 397 | /* |
| 398 | * Create or update the property. |
| 399 | */ |
| 400 | tmp = cpu_to_be32(OF_TBCLK); |
Kim Phillips | 60dc3fc | 2007-07-25 19:25:22 -0500 | [diff] [blame] | 401 | return fdt_setprop(blob, nodeoffset, name, &tmp, sizeof(tmp)); |
Jerry Van Baren | a4deb4d | 2007-07-04 21:34:24 -0400 | [diff] [blame] | 402 | } |
| 403 | |
| 404 | |
Gerald Van Baren | 2f73416 | 2007-04-15 13:54:26 -0400 | [diff] [blame] | 405 | /* |
Jerry Van Baren | a4deb4d | 2007-07-04 21:34:24 -0400 | [diff] [blame] | 406 | * Fixups to the fdt. |
Gerald Van Baren | d6abef4 | 2007-03-31 12:23:51 -0400 | [diff] [blame] | 407 | */ |
Gerald Van Baren | d6abef4 | 2007-03-31 12:23:51 -0400 | [diff] [blame] | 408 | static const struct { |
Gerald Van Baren | d6abef4 | 2007-03-31 12:23:51 -0400 | [diff] [blame] | 409 | char *node; |
| 410 | char *prop; |
Kim Phillips | 60dc3fc | 2007-07-25 19:25:22 -0500 | [diff] [blame] | 411 | int (*set_fn)(void *blob, int nodeoffset, const char *name, bd_t *bd); |
Gerald Van Baren | d6abef4 | 2007-03-31 12:23:51 -0400 | [diff] [blame] | 412 | } fixup_props[] = { |
Gerald Van Baren | 2f73416 | 2007-04-15 13:54:26 -0400 | [diff] [blame] | 413 | { "/cpus/" OF_CPU, |
Jerry Van Baren | a4deb4d | 2007-07-04 21:34:24 -0400 | [diff] [blame] | 414 | "timebase-frequency", |
| 415 | fdt_set_tbfreq |
Gerald Van Baren | d6abef4 | 2007-03-31 12:23:51 -0400 | [diff] [blame] | 416 | }, |
Jerry Van Baren | a4deb4d | 2007-07-04 21:34:24 -0400 | [diff] [blame] | 417 | { "/cpus/" OF_CPU, |
Gerald Van Baren | 2f73416 | 2007-04-15 13:54:26 -0400 | [diff] [blame] | 418 | "bus-frequency", |
| 419 | fdt_set_busfreq |
Gerald Van Baren | d6abef4 | 2007-03-31 12:23:51 -0400 | [diff] [blame] | 420 | }, |
Jerry Van Baren | a4deb4d | 2007-07-04 21:34:24 -0400 | [diff] [blame] | 421 | { "/cpus/" OF_CPU, |
| 422 | "clock-frequency", |
| 423 | fdt_set_busfreq |
| 424 | }, |
| 425 | { "/" OF_SOC "/serial@4500", |
Gerald Van Baren | 2f73416 | 2007-04-15 13:54:26 -0400 | [diff] [blame] | 426 | "clock-frequency", |
| 427 | fdt_set_busfreq |
Gerald Van Baren | d6abef4 | 2007-03-31 12:23:51 -0400 | [diff] [blame] | 428 | }, |
Jerry Van Baren | a4deb4d | 2007-07-04 21:34:24 -0400 | [diff] [blame] | 429 | { "/" OF_SOC "/serial@4600", |
Gerald Van Baren | 2f73416 | 2007-04-15 13:54:26 -0400 | [diff] [blame] | 430 | "clock-frequency", |
| 431 | fdt_set_busfreq |
Gerald Van Baren | d6abef4 | 2007-03-31 12:23:51 -0400 | [diff] [blame] | 432 | }, |
Kim Phillips | 177e58f | 2007-05-16 16:52:19 -0500 | [diff] [blame] | 433 | #ifdef CONFIG_TSEC1 |
Jerry Van Baren | a4deb4d | 2007-07-04 21:34:24 -0400 | [diff] [blame] | 434 | { "/" OF_SOC "/ethernet@24000", |
Gerald Van Baren | d6abef4 | 2007-03-31 12:23:51 -0400 | [diff] [blame] | 435 | "mac-address", |
Gerald Van Baren | 2f73416 | 2007-04-15 13:54:26 -0400 | [diff] [blame] | 436 | fdt_set_eth0 |
Gerald Van Baren | d6abef4 | 2007-03-31 12:23:51 -0400 | [diff] [blame] | 437 | }, |
Jerry Van Baren | a4deb4d | 2007-07-04 21:34:24 -0400 | [diff] [blame] | 438 | { "/" OF_SOC "/ethernet@24000", |
Gerald Van Baren | d6abef4 | 2007-03-31 12:23:51 -0400 | [diff] [blame] | 439 | "local-mac-address", |
Gerald Van Baren | 2f73416 | 2007-04-15 13:54:26 -0400 | [diff] [blame] | 440 | fdt_set_eth0 |
Gerald Van Baren | d6abef4 | 2007-03-31 12:23:51 -0400 | [diff] [blame] | 441 | }, |
| 442 | #endif |
Kim Phillips | 177e58f | 2007-05-16 16:52:19 -0500 | [diff] [blame] | 443 | #ifdef CONFIG_TSEC2 |
Jerry Van Baren | a4deb4d | 2007-07-04 21:34:24 -0400 | [diff] [blame] | 444 | { "/" OF_SOC "/ethernet@25000", |
Gerald Van Baren | 2f73416 | 2007-04-15 13:54:26 -0400 | [diff] [blame] | 445 | "mac-address", |
| 446 | fdt_set_eth1 |
| 447 | }, |
Jerry Van Baren | a4deb4d | 2007-07-04 21:34:24 -0400 | [diff] [blame] | 448 | { "/" OF_SOC "/ethernet@25000", |
Gerald Van Baren | 2f73416 | 2007-04-15 13:54:26 -0400 | [diff] [blame] | 449 | "local-mac-address", |
| 450 | fdt_set_eth1 |
| 451 | }, |
| 452 | #endif |
| 453 | #ifdef CONFIG_UEC_ETH1 |
| 454 | #if CFG_UEC1_UCC_NUM == 0 /* UCC1 */ |
Jerry Van Baren | a4deb4d | 2007-07-04 21:34:24 -0400 | [diff] [blame] | 455 | { "/" OF_QE "/ucc@2000", |
Gerald Van Baren | d6abef4 | 2007-03-31 12:23:51 -0400 | [diff] [blame] | 456 | "mac-address", |
Gerald Van Baren | 2f73416 | 2007-04-15 13:54:26 -0400 | [diff] [blame] | 457 | fdt_set_eth0 |
Gerald Van Baren | d6abef4 | 2007-03-31 12:23:51 -0400 | [diff] [blame] | 458 | }, |
Jerry Van Baren | a4deb4d | 2007-07-04 21:34:24 -0400 | [diff] [blame] | 459 | { "/" OF_QE "/ucc@2000", |
Gerald Van Baren | d6abef4 | 2007-03-31 12:23:51 -0400 | [diff] [blame] | 460 | "local-mac-address", |
Gerald Van Baren | 2f73416 | 2007-04-15 13:54:26 -0400 | [diff] [blame] | 461 | fdt_set_eth0 |
| 462 | }, |
| 463 | #elif CFG_UEC1_UCC_NUM == 2 /* UCC3 */ |
Jerry Van Baren | a4deb4d | 2007-07-04 21:34:24 -0400 | [diff] [blame] | 464 | { "/" OF_QE "/ucc@2200", |
Gerald Van Baren | 2f73416 | 2007-04-15 13:54:26 -0400 | [diff] [blame] | 465 | "mac-address", |
| 466 | fdt_set_eth0 |
| 467 | }, |
Jerry Van Baren | a4deb4d | 2007-07-04 21:34:24 -0400 | [diff] [blame] | 468 | { "/" OF_QE "/ucc@2200", |
Gerald Van Baren | 2f73416 | 2007-04-15 13:54:26 -0400 | [diff] [blame] | 469 | "local-mac-address", |
| 470 | fdt_set_eth0 |
| 471 | }, |
| 472 | #endif |
Jerry Van Baren | a4deb4d | 2007-07-04 21:34:24 -0400 | [diff] [blame] | 473 | #endif /* CONFIG_UEC_ETH1 */ |
Gerald Van Baren | 2f73416 | 2007-04-15 13:54:26 -0400 | [diff] [blame] | 474 | #ifdef CONFIG_UEC_ETH2 |
| 475 | #if CFG_UEC2_UCC_NUM == 1 /* UCC2 */ |
Jerry Van Baren | a4deb4d | 2007-07-04 21:34:24 -0400 | [diff] [blame] | 476 | { "/" OF_QE "/ucc@3000", |
Gerald Van Baren | 2f73416 | 2007-04-15 13:54:26 -0400 | [diff] [blame] | 477 | "mac-address", |
| 478 | fdt_set_eth1 |
| 479 | }, |
Jerry Van Baren | a4deb4d | 2007-07-04 21:34:24 -0400 | [diff] [blame] | 480 | { "/" OF_QE "/ucc@3000", |
Gerald Van Baren | 2f73416 | 2007-04-15 13:54:26 -0400 | [diff] [blame] | 481 | "local-mac-address", |
| 482 | fdt_set_eth1 |
| 483 | }, |
Kim Phillips | 69edf93 | 2007-08-15 22:30:12 -0500 | [diff] [blame^] | 484 | #elif CFG_UEC2_UCC_NUM == 3 /* UCC4 */ |
Jerry Van Baren | a4deb4d | 2007-07-04 21:34:24 -0400 | [diff] [blame] | 485 | { "/" OF_QE "/ucc@3200", |
Gerald Van Baren | 2f73416 | 2007-04-15 13:54:26 -0400 | [diff] [blame] | 486 | "mac-address", |
| 487 | fdt_set_eth1 |
| 488 | }, |
Jerry Van Baren | a4deb4d | 2007-07-04 21:34:24 -0400 | [diff] [blame] | 489 | { "/" OF_QE "/ucc@3200", |
Gerald Van Baren | 2f73416 | 2007-04-15 13:54:26 -0400 | [diff] [blame] | 490 | "local-mac-address", |
| 491 | fdt_set_eth1 |
Gerald Van Baren | d6abef4 | 2007-03-31 12:23:51 -0400 | [diff] [blame] | 492 | }, |
| 493 | #endif |
Jerry Van Baren | a4deb4d | 2007-07-04 21:34:24 -0400 | [diff] [blame] | 494 | #endif /* CONFIG_UEC_ETH2 */ |
Gerald Van Baren | d6abef4 | 2007-03-31 12:23:51 -0400 | [diff] [blame] | 495 | }; |
| 496 | |
| 497 | void |
| 498 | ft_cpu_setup(void *blob, bd_t *bd) |
| 499 | { |
Gerald Van Baren | 2f73416 | 2007-04-15 13:54:26 -0400 | [diff] [blame] | 500 | int nodeoffset; |
| 501 | int err; |
| 502 | int j; |
Gerald Van Baren | d6abef4 | 2007-03-31 12:23:51 -0400 | [diff] [blame] | 503 | |
| 504 | for (j = 0; j < (sizeof(fixup_props) / sizeof(fixup_props[0])); j++) { |
Kim Phillips | 60dc3fc | 2007-07-25 19:25:22 -0500 | [diff] [blame] | 505 | nodeoffset = fdt_find_node_by_path(blob, fixup_props[j].node); |
Gerald Van Baren | d6abef4 | 2007-03-31 12:23:51 -0400 | [diff] [blame] | 506 | if (nodeoffset >= 0) { |
Jerry Van Baren | a4deb4d | 2007-07-04 21:34:24 -0400 | [diff] [blame] | 507 | err = fixup_props[j].set_fn(blob, nodeoffset, |
| 508 | fixup_props[j].prop, bd); |
Gerald Van Baren | 2f73416 | 2007-04-15 13:54:26 -0400 | [diff] [blame] | 509 | if (err < 0) |
Jerry Van Baren | a4deb4d | 2007-07-04 21:34:24 -0400 | [diff] [blame] | 510 | debug("Problem setting %s = %s: %s\n", |
Gerald Van Baren | 2f73416 | 2007-04-15 13:54:26 -0400 | [diff] [blame] | 511 | fixup_props[j].node, |
| 512 | fixup_props[j].prop, |
| 513 | fdt_strerror(err)); |
Jerry Van Baren | a4deb4d | 2007-07-04 21:34:24 -0400 | [diff] [blame] | 514 | } else { |
| 515 | debug("Couldn't find %s: %s\n", |
| 516 | fixup_props[j].node, |
| 517 | fdt_strerror(nodeoffset)); |
Gerald Van Baren | d6abef4 | 2007-03-31 12:23:51 -0400 | [diff] [blame] | 518 | } |
| 519 | } |
| 520 | } |
Jerry Van Baren | 1a96f62 | 2007-07-04 21:27:30 -0400 | [diff] [blame] | 521 | #elif defined(CONFIG_OF_FLAT_TREE) |
Kumar Gala | 5bbb045 | 2006-01-11 16:48:10 -0600 | [diff] [blame] | 522 | void |
| 523 | ft_cpu_setup(void *blob, bd_t *bd) |
| 524 | { |
| 525 | u32 *p; |
| 526 | int len; |
| 527 | ulong clock; |
| 528 | |
| 529 | clock = bd->bi_busfreq; |
| 530 | p = ft_get_prop(blob, "/cpus/" OF_CPU "/bus-frequency", &len); |
| 531 | if (p != NULL) |
| 532 | *p = cpu_to_be32(clock); |
| 533 | |
| 534 | p = ft_get_prop(blob, "/" OF_SOC "/bus-frequency", &len); |
| 535 | if (p != NULL) |
| 536 | *p = cpu_to_be32(clock); |
| 537 | |
| 538 | p = ft_get_prop(blob, "/" OF_SOC "/serial@4500/clock-frequency", &len); |
| 539 | if (p != NULL) |
| 540 | *p = cpu_to_be32(clock); |
| 541 | |
| 542 | p = ft_get_prop(blob, "/" OF_SOC "/serial@4600/clock-frequency", &len); |
| 543 | if (p != NULL) |
| 544 | *p = cpu_to_be32(clock); |
| 545 | |
Kim Phillips | 177e58f | 2007-05-16 16:52:19 -0500 | [diff] [blame] | 546 | #ifdef CONFIG_TSEC1 |
Timur Tabi | ef64838 | 2007-02-13 10:41:42 -0600 | [diff] [blame] | 547 | p = ft_get_prop(blob, "/" OF_SOC "/ethernet@24000/mac-address", &len); |
| 548 | if (p != NULL) |
| 549 | memcpy(p, bd->bi_enetaddr, 6); |
| 550 | |
Kim Phillips | d99bd8b | 2006-11-01 00:07:25 -0600 | [diff] [blame] | 551 | 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] | 552 | if (p != NULL) |
Kumar Gala | 5bbb045 | 2006-01-11 16:48:10 -0600 | [diff] [blame] | 553 | memcpy(p, bd->bi_enetaddr, 6); |
| 554 | #endif |
| 555 | |
Kim Phillips | 177e58f | 2007-05-16 16:52:19 -0500 | [diff] [blame] | 556 | #ifdef CONFIG_TSEC2 |
Timur Tabi | ef64838 | 2007-02-13 10:41:42 -0600 | [diff] [blame] | 557 | p = ft_get_prop(blob, "/" OF_SOC "/ethernet@25000/mac-address", &len); |
| 558 | if (p != NULL) |
| 559 | memcpy(p, bd->bi_enet1addr, 6); |
| 560 | |
Kim Phillips | d99bd8b | 2006-11-01 00:07:25 -0600 | [diff] [blame] | 561 | 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] | 562 | if (p != NULL) |
Kumar Gala | 5bbb045 | 2006-01-11 16:48:10 -0600 | [diff] [blame] | 563 | memcpy(p, bd->bi_enet1addr, 6); |
| 564 | #endif |
Kim Phillips | 526addb | 2007-02-22 20:06:57 -0600 | [diff] [blame] | 565 | |
| 566 | #ifdef CONFIG_UEC_ETH1 |
| 567 | #if CFG_UEC1_UCC_NUM == 0 /* UCC1 */ |
| 568 | p = ft_get_prop(blob, "/" OF_QE "/ucc@2000/mac-address", &len); |
| 569 | if (p != NULL) |
| 570 | memcpy(p, bd->bi_enetaddr, 6); |
| 571 | |
| 572 | p = ft_get_prop(blob, "/" OF_QE "/ucc@2000/local-mac-address", &len); |
| 573 | if (p != NULL) |
| 574 | memcpy(p, bd->bi_enetaddr, 6); |
| 575 | #elif CFG_UEC1_UCC_NUM == 2 /* UCC3 */ |
| 576 | p = ft_get_prop(blob, "/" OF_QE "/ucc@2200/mac-address", &len); |
| 577 | if (p != NULL) |
| 578 | memcpy(p, bd->bi_enetaddr, 6); |
| 579 | |
| 580 | p = ft_get_prop(blob, "/" OF_QE "/ucc@2200/local-mac-address", &len); |
| 581 | if (p != NULL) |
| 582 | memcpy(p, bd->bi_enetaddr, 6); |
| 583 | #endif |
| 584 | #endif |
| 585 | |
| 586 | #ifdef CONFIG_UEC_ETH2 |
| 587 | #if CFG_UEC2_UCC_NUM == 1 /* UCC2 */ |
| 588 | p = ft_get_prop(blob, "/" OF_QE "/ucc@3000/mac-address", &len); |
| 589 | if (p != NULL) |
| 590 | memcpy(p, bd->bi_enet1addr, 6); |
| 591 | |
| 592 | p = ft_get_prop(blob, "/" OF_QE "/ucc@3000/local-mac-address", &len); |
| 593 | if (p != NULL) |
| 594 | memcpy(p, bd->bi_enet1addr, 6); |
| 595 | #elif CFG_UEC2_UCC_NUM == 3 /* UCC4 */ |
| 596 | p = ft_get_prop(blob, "/" OF_QE "/ucc@3200/mac-address", &len); |
| 597 | if (p != NULL) |
| 598 | memcpy(p, bd->bi_enet1addr, 6); |
| 599 | |
| 600 | p = ft_get_prop(blob, "/" OF_QE "/ucc@3200/local-mac-address", &len); |
| 601 | if (p != NULL) |
| 602 | memcpy(p, bd->bi_enet1addr, 6); |
| 603 | #endif |
| 604 | #endif |
Kumar Gala | 5bbb045 | 2006-01-11 16:48:10 -0600 | [diff] [blame] | 605 | } |
| 606 | #endif |
Marian Balakowicz | 7ec9ebc | 2006-03-14 16:14:48 +0100 | [diff] [blame] | 607 | |
| 608 | #if defined(CONFIG_DDR_ECC) |
| 609 | void dma_init(void) |
| 610 | { |
Timur Tabi | 386a280 | 2006-11-03 12:00:28 -0600 | [diff] [blame] | 611 | volatile immap_t *immap = (immap_t *)CFG_IMMR; |
Dave Liu | f503592 | 2006-10-25 14:41:21 -0500 | [diff] [blame] | 612 | volatile dma83xx_t *dma = &immap->dma; |
Marian Balakowicz | 7ec9ebc | 2006-03-14 16:14:48 +0100 | [diff] [blame] | 613 | volatile u32 status = swab32(dma->dmasr0); |
| 614 | volatile u32 dmamr0 = swab32(dma->dmamr0); |
| 615 | |
| 616 | debug("DMA-init\n"); |
| 617 | |
| 618 | /* initialize DMASARn, DMADAR and DMAABCRn */ |
| 619 | dma->dmadar0 = (u32)0; |
| 620 | dma->dmasar0 = (u32)0; |
| 621 | dma->dmabcr0 = 0; |
| 622 | |
| 623 | __asm__ __volatile__ ("sync"); |
| 624 | __asm__ __volatile__ ("isync"); |
| 625 | |
| 626 | /* clear CS bit */ |
| 627 | dmamr0 &= ~DMA_CHANNEL_START; |
| 628 | dma->dmamr0 = swab32(dmamr0); |
| 629 | __asm__ __volatile__ ("sync"); |
| 630 | __asm__ __volatile__ ("isync"); |
| 631 | |
| 632 | /* while the channel is busy, spin */ |
| 633 | while(status & DMA_CHANNEL_BUSY) { |
| 634 | status = swab32(dma->dmasr0); |
| 635 | } |
| 636 | |
| 637 | debug("DMA-init end\n"); |
| 638 | } |
| 639 | |
| 640 | uint dma_check(void) |
| 641 | { |
Timur Tabi | 386a280 | 2006-11-03 12:00:28 -0600 | [diff] [blame] | 642 | volatile immap_t *immap = (immap_t *)CFG_IMMR; |
Dave Liu | f503592 | 2006-10-25 14:41:21 -0500 | [diff] [blame] | 643 | volatile dma83xx_t *dma = &immap->dma; |
Marian Balakowicz | 7ec9ebc | 2006-03-14 16:14:48 +0100 | [diff] [blame] | 644 | volatile u32 status = swab32(dma->dmasr0); |
| 645 | volatile u32 byte_count = swab32(dma->dmabcr0); |
| 646 | |
| 647 | /* while the channel is busy, spin */ |
| 648 | while (status & DMA_CHANNEL_BUSY) { |
| 649 | status = swab32(dma->dmasr0); |
| 650 | } |
| 651 | |
| 652 | if (status & DMA_CHANNEL_TRANSFER_ERROR) { |
| 653 | printf ("DMA Error: status = %x @ %d\n", status, byte_count); |
| 654 | } |
| 655 | |
| 656 | return status; |
| 657 | } |
| 658 | |
| 659 | int dma_xfer(void *dest, u32 count, void *src) |
| 660 | { |
Timur Tabi | 386a280 | 2006-11-03 12:00:28 -0600 | [diff] [blame] | 661 | volatile immap_t *immap = (immap_t *)CFG_IMMR; |
Dave Liu | f503592 | 2006-10-25 14:41:21 -0500 | [diff] [blame] | 662 | volatile dma83xx_t *dma = &immap->dma; |
Marian Balakowicz | 7ec9ebc | 2006-03-14 16:14:48 +0100 | [diff] [blame] | 663 | volatile u32 dmamr0; |
| 664 | |
| 665 | /* initialize DMASARn, DMADAR and DMAABCRn */ |
| 666 | dma->dmadar0 = swab32((u32)dest); |
| 667 | dma->dmasar0 = swab32((u32)src); |
| 668 | dma->dmabcr0 = swab32(count); |
| 669 | |
| 670 | __asm__ __volatile__ ("sync"); |
| 671 | __asm__ __volatile__ ("isync"); |
| 672 | |
| 673 | /* init direct transfer, clear CS bit */ |
| 674 | dmamr0 = (DMA_CHANNEL_TRANSFER_MODE_DIRECT | |
| 675 | DMA_CHANNEL_SOURCE_ADDRESS_HOLD_8B | |
| 676 | DMA_CHANNEL_SOURCE_ADRESSS_HOLD_EN); |
Wolfgang Denk | ebd3deb | 2006-04-16 10:51:58 +0200 | [diff] [blame] | 677 | |
Marian Balakowicz | 7ec9ebc | 2006-03-14 16:14:48 +0100 | [diff] [blame] | 678 | dma->dmamr0 = swab32(dmamr0); |
| 679 | |
| 680 | __asm__ __volatile__ ("sync"); |
| 681 | __asm__ __volatile__ ("isync"); |
| 682 | |
| 683 | /* set CS to start DMA transfer */ |
| 684 | dmamr0 |= DMA_CHANNEL_START; |
| 685 | dma->dmamr0 = swab32(dmamr0); |
| 686 | __asm__ __volatile__ ("sync"); |
| 687 | __asm__ __volatile__ ("isync"); |
| 688 | |
| 689 | return ((int)dma_check()); |
| 690 | } |
| 691 | #endif /*CONFIG_DDR_ECC*/ |