Rafal Jaworowski | d3a02c3 | 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> |
Heiko Schocher | 50219e6 | 2009-03-26 07:33:59 +0100 | [diff] [blame] | 32 | #include <net.h> |
Ben Warren | b664dea | 2008-08-31 10:36:38 -0700 | [diff] [blame] | 33 | #include <netdev.h> |
Rafal Jaworowski | d3a02c3 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 34 | #include <asm/processor.h> |
| 35 | |
Grzegorz Bernacki | af554d8 | 2008-01-08 17:16:15 +0100 | [diff] [blame] | 36 | #if defined(CONFIG_OF_LIBFDT) |
| 37 | #include <fdt_support.h> |
| 38 | #endif |
| 39 | |
Rafal Jaworowski | d3a02c3 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 40 | DECLARE_GLOBAL_DATA_PTR; |
| 41 | |
| 42 | int checkcpu (void) |
| 43 | { |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 44 | volatile immap_t *immr = (immap_t *) CONFIG_SYS_IMMR; |
Rafal Jaworowski | d3a02c3 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 45 | ulong clock = gd->cpu_clk; |
| 46 | u32 pvr = get_pvr (); |
| 47 | u32 spridr = immr->sysconf.spridr; |
Wolfgang Denk | 2059104 | 2008-10-19 02:35:49 +0200 | [diff] [blame] | 48 | char buf1[32], buf2[32]; |
Rafal Jaworowski | d3a02c3 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 49 | |
Wolfgang Denk | e4a56a5 | 2007-08-12 21:34:34 +0200 | [diff] [blame] | 50 | puts ("CPU: "); |
Rafal Jaworowski | d3a02c3 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 51 | |
| 52 | switch (spridr & 0xffff0000) { |
| 53 | case SPR_5121E: |
| 54 | puts ("MPC5121e "); |
| 55 | break; |
| 56 | default: |
| 57 | printf ("Unknown part ID %08x ", spridr & 0xffff0000); |
| 58 | } |
| 59 | printf ("rev. %d.%d, Core ", SVR_MJREV (spridr), SVR_MNREV (spridr)); |
| 60 | |
| 61 | switch (pvr & 0xffff0000) { |
| 62 | case PVR_E300C4: |
| 63 | puts ("e300c4 "); |
| 64 | break; |
| 65 | default: |
| 66 | puts ("unknown "); |
| 67 | } |
Wolfgang Denk | 2059104 | 2008-10-19 02:35:49 +0200 | [diff] [blame] | 68 | printf ("at %s MHz, CSB at %s MHz\n", |
| 69 | strmhz(buf1, clock), |
| 70 | strmhz(buf2, gd->csb_clk) ); |
Rafal Jaworowski | d3a02c3 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 71 | return 0; |
| 72 | } |
| 73 | |
| 74 | |
| 75 | int |
| 76 | do_reset (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[]) |
| 77 | { |
| 78 | ulong msr; |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 79 | volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR; |
Rafal Jaworowski | d3a02c3 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 80 | |
| 81 | /* Interrupts and MMU off */ |
| 82 | __asm__ __volatile__ ("mfmsr %0":"=r" (msr):); |
| 83 | |
| 84 | msr &= ~( MSR_EE | MSR_IR | MSR_DR); |
| 85 | __asm__ __volatile__ ("mtmsr %0"::"r" (msr)); |
| 86 | |
| 87 | /* |
| 88 | * Enable Reset Control Reg - "RSTE" is the magic word that let us go |
| 89 | */ |
| 90 | immap->reset.rpr = 0x52535445; |
| 91 | |
| 92 | /* Verify Reset Control Reg is enabled */ |
| 93 | while (!((immap->reset.rcer) & RCER_CRE)) |
| 94 | ; |
| 95 | |
| 96 | printf ("Resetting the board.\n"); |
| 97 | udelay(200); |
| 98 | |
| 99 | /* Perform reset */ |
| 100 | immap->reset.rcr = RCR_SWHR; |
| 101 | |
| 102 | /* Unreached... */ |
| 103 | return 1; |
| 104 | } |
| 105 | |
| 106 | |
| 107 | /* |
| 108 | * Get timebase clock frequency (like cpu_clk in Hz) |
| 109 | */ |
| 110 | unsigned long get_tbclk (void) |
| 111 | { |
| 112 | ulong tbclk; |
| 113 | |
| 114 | tbclk = (gd->bus_clk + 3L) / 4L; |
| 115 | |
| 116 | return tbclk; |
| 117 | } |
| 118 | |
| 119 | |
| 120 | #if defined(CONFIG_WATCHDOG) |
| 121 | void watchdog_reset (void) |
| 122 | { |
| 123 | int re_enable = disable_interrupts (); |
| 124 | |
| 125 | /* Reset watchdog */ |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 126 | volatile immap_t *immr = (immap_t *) CONFIG_SYS_IMMR; |
Rafal Jaworowski | d3a02c3 | 2007-07-27 14:43:59 +0200 | [diff] [blame] | 127 | immr->wdt.swsrr = 0x556c; |
| 128 | immr->wdt.swsrr = 0xaa39; |
| 129 | |
| 130 | if (re_enable) |
| 131 | enable_interrupts (); |
| 132 | } |
| 133 | #endif |
Grzegorz Bernacki | af554d8 | 2008-01-08 17:16:15 +0100 | [diff] [blame] | 134 | |
| 135 | #ifdef CONFIG_OF_LIBFDT |
John Rigby | d096f62 | 2008-08-05 17:38:57 -0600 | [diff] [blame] | 136 | |
| 137 | #ifdef CONFIG_OF_SUPPORT_OLD_DEVICE_TREES |
| 138 | /* |
| 139 | * fdt setup for old device trees |
| 140 | * fix up |
| 141 | * cpu clocks |
| 142 | * soc clocks |
| 143 | * ethernet addresses |
| 144 | */ |
| 145 | static void old_ft_cpu_setup(void *blob, bd_t *bd) |
Grzegorz Bernacki | af554d8 | 2008-01-08 17:16:15 +0100 | [diff] [blame] | 146 | { |
John Rigby | d096f62 | 2008-08-05 17:38:57 -0600 | [diff] [blame] | 147 | /* |
| 148 | * avoid fixing up by path because that |
| 149 | * produces scary error messages |
| 150 | */ |
Mike Frysinger | f4aa436 | 2009-02-11 19:18:41 -0500 | [diff] [blame] | 151 | uchar enetaddr[6]; |
John Rigby | d096f62 | 2008-08-05 17:38:57 -0600 | [diff] [blame] | 152 | |
| 153 | /* |
| 154 | * old device trees have ethernet nodes with |
| 155 | * device_type = "network" |
| 156 | */ |
Mike Frysinger | f4aa436 | 2009-02-11 19:18:41 -0500 | [diff] [blame] | 157 | eth_getenv_enetaddr("ethaddr", enetaddr); |
John Rigby | d096f62 | 2008-08-05 17:38:57 -0600 | [diff] [blame] | 158 | do_fixup_by_prop(blob, "device_type", "network", 8, |
Mike Frysinger | f4aa436 | 2009-02-11 19:18:41 -0500 | [diff] [blame] | 159 | "local-mac-address", enetaddr, 6, 0); |
John Rigby | d096f62 | 2008-08-05 17:38:57 -0600 | [diff] [blame] | 160 | do_fixup_by_prop(blob, "device_type", "network", 8, |
Mike Frysinger | f4aa436 | 2009-02-11 19:18:41 -0500 | [diff] [blame] | 161 | "address", enetaddr, 6, 0); |
John Rigby | d096f62 | 2008-08-05 17:38:57 -0600 | [diff] [blame] | 162 | /* |
| 163 | * old device trees have soc nodes with |
| 164 | * device_type = "soc" |
| 165 | */ |
| 166 | do_fixup_by_prop_u32(blob, "device_type", "soc", 4, |
| 167 | "bus-frequency", bd->bi_ipsfreq, 0); |
| 168 | } |
| 169 | #endif |
| 170 | |
| 171 | static void ft_clock_setup(void *blob, bd_t *bd) |
| 172 | { |
Martha Marx | fd449ab | 2008-05-29 14:23:25 -0400 | [diff] [blame] | 173 | char *cpu_path = "/cpus/" OF_CPU; |
Grzegorz Bernacki | af554d8 | 2008-01-08 17:16:15 +0100 | [diff] [blame] | 174 | |
John Rigby | d096f62 | 2008-08-05 17:38:57 -0600 | [diff] [blame] | 175 | /* |
| 176 | * fixup cpu clocks using path |
| 177 | */ |
| 178 | do_fixup_by_path_u32(blob, cpu_path, |
| 179 | "timebase-frequency", OF_TBCLK, 1); |
| 180 | do_fixup_by_path_u32(blob, cpu_path, |
| 181 | "bus-frequency", bd->bi_busfreq, 1); |
| 182 | do_fixup_by_path_u32(blob, cpu_path, |
| 183 | "clock-frequency", bd->bi_intfreq, 1); |
| 184 | /* |
| 185 | * fixup soc clocks using compatible |
| 186 | */ |
| 187 | do_fixup_by_compat_u32(blob, OF_SOC_COMPAT, |
| 188 | "bus-frequency", bd->bi_ipsfreq, 1); |
| 189 | } |
John Rigby | fc807c5 | 2008-01-30 13:36:57 -0700 | [diff] [blame] | 190 | |
John Rigby | d096f62 | 2008-08-05 17:38:57 -0600 | [diff] [blame] | 191 | void ft_cpu_setup(void *blob, bd_t *bd) |
| 192 | { |
| 193 | #ifdef CONFIG_OF_SUPPORT_OLD_DEVICE_TREES |
| 194 | old_ft_cpu_setup(blob, bd); |
| 195 | #endif |
| 196 | ft_clock_setup(blob, bd); |
| 197 | #ifdef CONFIG_HAS_ETH0 |
Kumar Gala | fabda92 | 2008-08-19 15:41:18 -0500 | [diff] [blame] | 198 | fdt_fixup_ethernet(blob); |
John Rigby | d096f62 | 2008-08-05 17:38:57 -0600 | [diff] [blame] | 199 | #endif |
Grzegorz Bernacki | af554d8 | 2008-01-08 17:16:15 +0100 | [diff] [blame] | 200 | } |
| 201 | #endif |
Ben Warren | b664dea | 2008-08-31 10:36:38 -0700 | [diff] [blame] | 202 | |
| 203 | #ifdef CONFIG_MPC512x_FEC |
| 204 | /* Default initializations for FEC controllers. To override, |
| 205 | * create a board-specific function called: |
| 206 | * int board_eth_init(bd_t *bis) |
| 207 | */ |
| 208 | |
| 209 | int cpu_eth_init(bd_t *bis) |
| 210 | { |
| 211 | return mpc512x_fec_initialize(bis); |
| 212 | } |
| 213 | #endif |