Rafal Jaworowski | 8993e54 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2004-2006 Freescale Semiconductor, Inc. |
| 3 | * (C) Copyright 2007 DENX Software Engineering |
| 4 | * |
| 5 | * See file CREDITS for list of people who contributed to this |
| 6 | * project. |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or |
| 9 | * modify it under the terms of the GNU General Public License as |
| 10 | * published by the Free Software Foundation; either version 2 of |
| 11 | * the License, or (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to the Free Software |
| 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 21 | * MA 02111-1307 USA |
| 22 | */ |
| 23 | |
| 24 | /* |
| 25 | * CPU specific code for the MPC512x family. |
| 26 | * |
| 27 | * Derived from the MPC83xx code. |
| 28 | */ |
| 29 | |
| 30 | #include <common.h> |
| 31 | #include <command.h> |
| 32 | #include <mpc512x.h> |
Heiko Schocher | 76756e4 | 2009-03-26 07:33:59 +0100 | [diff] [blame] | 33 | #include <net.h> |
Ben Warren | a0aad08 | 2008-08-31 10:36:38 -0700 | [diff] [blame] | 34 | #include <netdev.h> |
Rafal Jaworowski | 8993e54 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 35 | #include <asm/processor.h> |
| 36 | |
Grzegorz Bernacki | 281ff9a | 2008-01-08 17:16:15 +0100 | [diff] [blame] | 37 | #if defined(CONFIG_OF_LIBFDT) |
| 38 | #include <fdt_support.h> |
| 39 | #endif |
| 40 | |
Rafal Jaworowski | 8993e54 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 41 | DECLARE_GLOBAL_DATA_PTR; |
| 42 | |
| 43 | int checkcpu (void) |
| 44 | { |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 45 | volatile immap_t *immr = (immap_t *) CONFIG_SYS_IMMR; |
Rafal Jaworowski | 8993e54 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 46 | ulong clock = gd->cpu_clk; |
| 47 | u32 pvr = get_pvr (); |
| 48 | u32 spridr = immr->sysconf.spridr; |
Wolfgang Denk | 08ef89e | 2008-10-19 02:35:49 +0200 | [diff] [blame] | 49 | char buf1[32], buf2[32]; |
Rafal Jaworowski | 8993e54 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 50 | |
Wolfgang Denk | 77d19a8 | 2007-08-12 21:34:34 +0200 | [diff] [blame] | 51 | puts ("CPU: "); |
Rafal Jaworowski | 8993e54 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 52 | |
| 53 | switch (spridr & 0xffff0000) { |
| 54 | case SPR_5121E: |
| 55 | puts ("MPC5121e "); |
| 56 | break; |
| 57 | default: |
| 58 | printf ("Unknown part ID %08x ", spridr & 0xffff0000); |
| 59 | } |
| 60 | printf ("rev. %d.%d, Core ", SVR_MJREV (spridr), SVR_MNREV (spridr)); |
| 61 | |
| 62 | switch (pvr & 0xffff0000) { |
| 63 | case PVR_E300C4: |
| 64 | puts ("e300c4 "); |
| 65 | break; |
| 66 | default: |
| 67 | puts ("unknown "); |
| 68 | } |
Wolfgang Denk | 08ef89e | 2008-10-19 02:35:49 +0200 | [diff] [blame] | 69 | printf ("at %s MHz, CSB at %s MHz\n", |
| 70 | strmhz(buf1, clock), |
| 71 | strmhz(buf2, gd->csb_clk) ); |
Rafal Jaworowski | 8993e54 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 72 | return 0; |
| 73 | } |
| 74 | |
| 75 | |
| 76 | int |
| 77 | do_reset (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[]) |
| 78 | { |
| 79 | ulong msr; |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 80 | volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR; |
Rafal Jaworowski | 8993e54 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 81 | |
| 82 | /* Interrupts and MMU off */ |
| 83 | __asm__ __volatile__ ("mfmsr %0":"=r" (msr):); |
| 84 | |
| 85 | msr &= ~( MSR_EE | MSR_IR | MSR_DR); |
| 86 | __asm__ __volatile__ ("mtmsr %0"::"r" (msr)); |
| 87 | |
| 88 | /* |
| 89 | * Enable Reset Control Reg - "RSTE" is the magic word that let us go |
| 90 | */ |
| 91 | immap->reset.rpr = 0x52535445; |
| 92 | |
| 93 | /* Verify Reset Control Reg is enabled */ |
| 94 | while (!((immap->reset.rcer) & RCER_CRE)) |
| 95 | ; |
| 96 | |
| 97 | printf ("Resetting the board.\n"); |
| 98 | udelay(200); |
| 99 | |
| 100 | /* Perform reset */ |
| 101 | immap->reset.rcr = RCR_SWHR; |
| 102 | |
| 103 | /* Unreached... */ |
| 104 | return 1; |
| 105 | } |
| 106 | |
| 107 | |
| 108 | /* |
| 109 | * Get timebase clock frequency (like cpu_clk in Hz) |
| 110 | */ |
| 111 | unsigned long get_tbclk (void) |
| 112 | { |
| 113 | ulong tbclk; |
| 114 | |
| 115 | tbclk = (gd->bus_clk + 3L) / 4L; |
| 116 | |
| 117 | return tbclk; |
| 118 | } |
| 119 | |
| 120 | |
| 121 | #if defined(CONFIG_WATCHDOG) |
| 122 | void watchdog_reset (void) |
| 123 | { |
| 124 | int re_enable = disable_interrupts (); |
| 125 | |
| 126 | /* Reset watchdog */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 127 | volatile immap_t *immr = (immap_t *) CONFIG_SYS_IMMR; |
Rafal Jaworowski | 8993e54 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 128 | immr->wdt.swsrr = 0x556c; |
| 129 | immr->wdt.swsrr = 0xaa39; |
| 130 | |
| 131 | if (re_enable) |
| 132 | enable_interrupts (); |
| 133 | } |
| 134 | #endif |
Grzegorz Bernacki | 281ff9a | 2008-01-08 17:16:15 +0100 | [diff] [blame] | 135 | |
| 136 | #ifdef CONFIG_OF_LIBFDT |
John Rigby | ef11df6 | 2008-08-05 17:38:57 -0600 | [diff] [blame] | 137 | |
| 138 | #ifdef CONFIG_OF_SUPPORT_OLD_DEVICE_TREES |
| 139 | /* |
| 140 | * fdt setup for old device trees |
| 141 | * fix up |
| 142 | * cpu clocks |
| 143 | * soc clocks |
| 144 | * ethernet addresses |
| 145 | */ |
| 146 | static void old_ft_cpu_setup(void *blob, bd_t *bd) |
| 147 | { |
| 148 | /* |
| 149 | * avoid fixing up by path because that |
| 150 | * produces scary error messages |
| 151 | */ |
Mike Frysinger | 6bacfa6 | 2009-02-11 19:18:41 -0500 | [diff] [blame] | 152 | uchar enetaddr[6]; |
John Rigby | ef11df6 | 2008-08-05 17:38:57 -0600 | [diff] [blame] | 153 | |
| 154 | /* |
| 155 | * old device trees have ethernet nodes with |
| 156 | * device_type = "network" |
| 157 | */ |
Mike Frysinger | 6bacfa6 | 2009-02-11 19:18:41 -0500 | [diff] [blame] | 158 | eth_getenv_enetaddr("ethaddr", enetaddr); |
John Rigby | ef11df6 | 2008-08-05 17:38:57 -0600 | [diff] [blame] | 159 | do_fixup_by_prop(blob, "device_type", "network", 8, |
Mike Frysinger | 6bacfa6 | 2009-02-11 19:18:41 -0500 | [diff] [blame] | 160 | "local-mac-address", enetaddr, 6, 0); |
John Rigby | ef11df6 | 2008-08-05 17:38:57 -0600 | [diff] [blame] | 161 | do_fixup_by_prop(blob, "device_type", "network", 8, |
Mike Frysinger | 6bacfa6 | 2009-02-11 19:18:41 -0500 | [diff] [blame] | 162 | "address", enetaddr, 6, 0); |
John Rigby | ef11df6 | 2008-08-05 17:38:57 -0600 | [diff] [blame] | 163 | /* |
| 164 | * old device trees have soc nodes with |
| 165 | * device_type = "soc" |
| 166 | */ |
| 167 | do_fixup_by_prop_u32(blob, "device_type", "soc", 4, |
| 168 | "bus-frequency", bd->bi_ipsfreq, 0); |
| 169 | } |
| 170 | #endif |
| 171 | |
| 172 | static void ft_clock_setup(void *blob, bd_t *bd) |
| 173 | { |
John Rigby | ef11df6 | 2008-08-05 17:38:57 -0600 | [diff] [blame] | 174 | char *cpu_path = "/cpus/" OF_CPU; |
John Rigby | ef11df6 | 2008-08-05 17:38:57 -0600 | [diff] [blame] | 175 | |
| 176 | /* |
| 177 | * fixup cpu clocks using path |
| 178 | */ |
| 179 | do_fixup_by_path_u32(blob, cpu_path, |
| 180 | "timebase-frequency", OF_TBCLK, 1); |
| 181 | do_fixup_by_path_u32(blob, cpu_path, |
| 182 | "bus-frequency", bd->bi_busfreq, 1); |
| 183 | do_fixup_by_path_u32(blob, cpu_path, |
| 184 | "clock-frequency", bd->bi_intfreq, 1); |
| 185 | /* |
| 186 | * fixup soc clocks using compatible |
| 187 | */ |
| 188 | do_fixup_by_compat_u32(blob, OF_SOC_COMPAT, |
| 189 | "bus-frequency", bd->bi_ipsfreq, 1); |
| 190 | } |
| 191 | |
Grzegorz Bernacki | 281ff9a | 2008-01-08 17:16:15 +0100 | [diff] [blame] | 192 | void ft_cpu_setup(void *blob, bd_t *bd) |
| 193 | { |
John Rigby | ef11df6 | 2008-08-05 17:38:57 -0600 | [diff] [blame] | 194 | #ifdef CONFIG_OF_SUPPORT_OLD_DEVICE_TREES |
| 195 | old_ft_cpu_setup(blob, bd); |
| 196 | #endif |
| 197 | ft_clock_setup(blob, bd); |
| 198 | #ifdef CONFIG_HAS_ETH0 |
Kumar Gala | ba37aa0 | 2008-08-19 15:41:18 -0500 | [diff] [blame] | 199 | fdt_fixup_ethernet(blob); |
John Rigby | ef11df6 | 2008-08-05 17:38:57 -0600 | [diff] [blame] | 200 | #endif |
Grzegorz Bernacki | 281ff9a | 2008-01-08 17:16:15 +0100 | [diff] [blame] | 201 | } |
| 202 | #endif |
Ben Warren | a0aad08 | 2008-08-31 10:36:38 -0700 | [diff] [blame] | 203 | |
| 204 | #ifdef CONFIG_MPC512x_FEC |
| 205 | /* Default initializations for FEC controllers. To override, |
| 206 | * create a board-specific function called: |
| 207 | * int board_eth_init(bd_t *bis) |
| 208 | */ |
| 209 | |
| 210 | int cpu_eth_init(bd_t *bis) |
| 211 | { |
| 212 | return mpc512x_fec_initialize(bis); |
| 213 | } |
| 214 | #endif |