blob: 09cbd2024db3b040a06012981d4a915a29c96181 [file] [log] [blame]
Rafal Jaworowskid3a02c32007-07-27 14:43:59 +02001/*
Detlev Zundel00c27162010-01-21 17:55:58 +01002 * (C) Copyright 2007-2010 DENX Software Engineering
Rafal Jaworowskid3a02c32007-07-27 14:43:59 +02003 * Copyright (C) 2004-2006 Freescale Semiconductor, Inc.
Rafal Jaworowskid3a02c32007-07-27 14:43:59 +02004 *
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 Schocher50219e62009-03-26 07:33:59 +010032#include <net.h>
Ben Warrenb664dea2008-08-31 10:36:38 -070033#include <netdev.h>
Rafal Jaworowskid3a02c32007-07-27 14:43:59 +020034#include <asm/processor.h>
Detlev Zundel00c27162010-01-21 17:55:58 +010035#include <asm/io.h>
Rafal Jaworowskid3a02c32007-07-27 14:43:59 +020036
Grzegorz Bernackiaf554d82008-01-08 17:16:15 +010037#if defined(CONFIG_OF_LIBFDT)
38#include <fdt_support.h>
39#endif
40
Rafal Jaworowskid3a02c32007-07-27 14:43:59 +020041DECLARE_GLOBAL_DATA_PTR;
42
43int checkcpu (void)
44{
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020045 volatile immap_t *immr = (immap_t *) CONFIG_SYS_IMMR;
Rafal Jaworowskid3a02c32007-07-27 14:43:59 +020046 ulong clock = gd->cpu_clk;
47 u32 pvr = get_pvr ();
Detlev Zundel00c27162010-01-21 17:55:58 +010048 u32 spridr = in_be32(&immr->sysconf.spridr);
Wolfgang Denk20591042008-10-19 02:35:49 +020049 char buf1[32], buf2[32];
Rafal Jaworowskid3a02c32007-07-27 14:43:59 +020050
Wolfgang Denke4a56a52007-08-12 21:34:34 +020051 puts ("CPU: ");
Rafal Jaworowskid3a02c32007-07-27 14:43:59 +020052
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 }
Detlev Zundela2ea2762010-01-22 14:47:59 +010069 printf ("at %s MHz, CSB at %s MHz (RSR=0x%04lx)\n",
Wolfgang Denk20591042008-10-19 02:35:49 +020070 strmhz(buf1, clock),
Detlev Zundela2ea2762010-01-22 14:47:59 +010071 strmhz(buf2, gd->csb_clk),
72 gd->reset_status & 0xffff);
Rafal Jaworowskid3a02c32007-07-27 14:43:59 +020073 return 0;
74}
75
76
77int
78do_reset (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
79{
80 ulong msr;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020081 volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
Rafal Jaworowskid3a02c32007-07-27 14:43:59 +020082
83 /* Interrupts and MMU off */
84 __asm__ __volatile__ ("mfmsr %0":"=r" (msr):);
85
86 msr &= ~( MSR_EE | MSR_IR | MSR_DR);
87 __asm__ __volatile__ ("mtmsr %0"::"r" (msr));
88
89 /*
90 * Enable Reset Control Reg - "RSTE" is the magic word that let us go
91 */
Detlev Zundel00c27162010-01-21 17:55:58 +010092 out_be32(&immap->reset.rpr, 0x52535445);
Rafal Jaworowskid3a02c32007-07-27 14:43:59 +020093
94 /* Verify Reset Control Reg is enabled */
Detlev Zundel00c27162010-01-21 17:55:58 +010095 while (!(in_be32(&immap->reset.rcer) & RCER_CRE))
Rafal Jaworowskid3a02c32007-07-27 14:43:59 +020096 ;
97
98 printf ("Resetting the board.\n");
99 udelay(200);
100
101 /* Perform reset */
Detlev Zundel00c27162010-01-21 17:55:58 +0100102 out_be32(&immap->reset.rcr, RCR_SWHR);
Rafal Jaworowskid3a02c32007-07-27 14:43:59 +0200103
104 /* Unreached... */
105 return 1;
106}
107
108
109/*
110 * Get timebase clock frequency (like cpu_clk in Hz)
111 */
112unsigned long get_tbclk (void)
113{
114 ulong tbclk;
115
116 tbclk = (gd->bus_clk + 3L) / 4L;
117
118 return tbclk;
119}
120
121
122#if defined(CONFIG_WATCHDOG)
123void watchdog_reset (void)
124{
125 int re_enable = disable_interrupts ();
126
127 /* Reset watchdog */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200128 volatile immap_t *immr = (immap_t *) CONFIG_SYS_IMMR;
Detlev Zundel00c27162010-01-21 17:55:58 +0100129 out_be32(&immr->wdt.swsrr, 0x556c);
130 out_be32(&immr->wdt.swsrr, 0xaa39);
Rafal Jaworowskid3a02c32007-07-27 14:43:59 +0200131
132 if (re_enable)
133 enable_interrupts ();
134}
135#endif
Grzegorz Bernackiaf554d82008-01-08 17:16:15 +0100136
137#ifdef CONFIG_OF_LIBFDT
John Rigbyd096f622008-08-05 17:38:57 -0600138
139#ifdef CONFIG_OF_SUPPORT_OLD_DEVICE_TREES
140/*
141 * fdt setup for old device trees
142 * fix up
143 * cpu clocks
144 * soc clocks
145 * ethernet addresses
146 */
147static void old_ft_cpu_setup(void *blob, bd_t *bd)
Grzegorz Bernackiaf554d82008-01-08 17:16:15 +0100148{
John Rigbyd096f622008-08-05 17:38:57 -0600149 /*
150 * avoid fixing up by path because that
151 * produces scary error messages
152 */
Mike Frysingerf4aa4362009-02-11 19:18:41 -0500153 uchar enetaddr[6];
John Rigbyd096f622008-08-05 17:38:57 -0600154
155 /*
156 * old device trees have ethernet nodes with
157 * device_type = "network"
158 */
Mike Frysingerf4aa4362009-02-11 19:18:41 -0500159 eth_getenv_enetaddr("ethaddr", enetaddr);
John Rigbyd096f622008-08-05 17:38:57 -0600160 do_fixup_by_prop(blob, "device_type", "network", 8,
Mike Frysingerf4aa4362009-02-11 19:18:41 -0500161 "local-mac-address", enetaddr, 6, 0);
John Rigbyd096f622008-08-05 17:38:57 -0600162 do_fixup_by_prop(blob, "device_type", "network", 8,
Mike Frysingerf4aa4362009-02-11 19:18:41 -0500163 "address", enetaddr, 6, 0);
John Rigbyd096f622008-08-05 17:38:57 -0600164 /*
165 * old device trees have soc nodes with
166 * device_type = "soc"
167 */
168 do_fixup_by_prop_u32(blob, "device_type", "soc", 4,
169 "bus-frequency", bd->bi_ipsfreq, 0);
170}
171#endif
172
173static void ft_clock_setup(void *blob, bd_t *bd)
174{
Martha Marxfd449ab2008-05-29 14:23:25 -0400175 char *cpu_path = "/cpus/" OF_CPU;
Grzegorz Bernackiaf554d82008-01-08 17:16:15 +0100176
John Rigbyd096f622008-08-05 17:38:57 -0600177 /*
178 * fixup cpu clocks using path
179 */
180 do_fixup_by_path_u32(blob, cpu_path,
181 "timebase-frequency", OF_TBCLK, 1);
182 do_fixup_by_path_u32(blob, cpu_path,
183 "bus-frequency", bd->bi_busfreq, 1);
184 do_fixup_by_path_u32(blob, cpu_path,
185 "clock-frequency", bd->bi_intfreq, 1);
186 /*
187 * fixup soc clocks using compatible
188 */
189 do_fixup_by_compat_u32(blob, OF_SOC_COMPAT,
190 "bus-frequency", bd->bi_ipsfreq, 1);
191}
John Rigbyfc807c52008-01-30 13:36:57 -0700192
John Rigbyd096f622008-08-05 17:38:57 -0600193void ft_cpu_setup(void *blob, bd_t *bd)
194{
195#ifdef CONFIG_OF_SUPPORT_OLD_DEVICE_TREES
196 old_ft_cpu_setup(blob, bd);
197#endif
198 ft_clock_setup(blob, bd);
199#ifdef CONFIG_HAS_ETH0
Kumar Galafabda922008-08-19 15:41:18 -0500200 fdt_fixup_ethernet(blob);
John Rigbyd096f622008-08-05 17:38:57 -0600201#endif
Heiko Schocher733b48d2009-12-03 11:20:06 +0100202 fdt_fixup_memory(blob, (u64)bd->bi_memstart, (u64)bd->bi_memsize);
Grzegorz Bernackiaf554d82008-01-08 17:16:15 +0100203}
204#endif
Ben Warrenb664dea2008-08-31 10:36:38 -0700205
206#ifdef CONFIG_MPC512x_FEC
207/* Default initializations for FEC controllers. To override,
208 * create a board-specific function called:
209 * int board_eth_init(bd_t *bis)
210 */
211
212int cpu_eth_init(bd_t *bis)
213{
214 return mpc512x_fec_initialize(bis);
215}
216#endif