blob: 8508e8db40eeacb4afc636f9398739c6522cf441 [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 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02005 * SPDX-License-Identifier: GPL-2.0+
Rafal Jaworowskid3a02c32007-07-27 14:43:59 +02006 */
7
8/*
9 * CPU specific code for the MPC512x family.
10 *
11 * Derived from the MPC83xx code.
12 */
13
14#include <common.h>
15#include <command.h>
Heiko Schocher50219e62009-03-26 07:33:59 +010016#include <net.h>
Ben Warrenb664dea2008-08-31 10:36:38 -070017#include <netdev.h>
Rafal Jaworowskid3a02c32007-07-27 14:43:59 +020018#include <asm/processor.h>
Detlev Zundel00c27162010-01-21 17:55:58 +010019#include <asm/io.h>
Rafal Jaworowskid3a02c32007-07-27 14:43:59 +020020
Grzegorz Bernackiaf554d82008-01-08 17:16:15 +010021#if defined(CONFIG_OF_LIBFDT)
22#include <fdt_support.h>
23#endif
24
Rafal Jaworowskid3a02c32007-07-27 14:43:59 +020025DECLARE_GLOBAL_DATA_PTR;
26
27int checkcpu (void)
28{
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020029 volatile immap_t *immr = (immap_t *) CONFIG_SYS_IMMR;
Rafal Jaworowskid3a02c32007-07-27 14:43:59 +020030 ulong clock = gd->cpu_clk;
31 u32 pvr = get_pvr ();
Detlev Zundel00c27162010-01-21 17:55:58 +010032 u32 spridr = in_be32(&immr->sysconf.spridr);
Wolfgang Denk20591042008-10-19 02:35:49 +020033 char buf1[32], buf2[32];
Rafal Jaworowskid3a02c32007-07-27 14:43:59 +020034
Wolfgang Denke4a56a52007-08-12 21:34:34 +020035 puts ("CPU: ");
Rafal Jaworowskid3a02c32007-07-27 14:43:59 +020036
37 switch (spridr & 0xffff0000) {
38 case SPR_5121E:
39 puts ("MPC5121e ");
40 break;
41 default:
42 printf ("Unknown part ID %08x ", spridr & 0xffff0000);
43 }
44 printf ("rev. %d.%d, Core ", SVR_MJREV (spridr), SVR_MNREV (spridr));
45
46 switch (pvr & 0xffff0000) {
47 case PVR_E300C4:
48 puts ("e300c4 ");
49 break;
50 default:
51 puts ("unknown ");
52 }
Detlev Zundela2ea2762010-01-22 14:47:59 +010053 printf ("at %s MHz, CSB at %s MHz (RSR=0x%04lx)\n",
Wolfgang Denk20591042008-10-19 02:35:49 +020054 strmhz(buf1, clock),
Simon Glass6c6cbd12012-12-13 20:48:54 +000055 strmhz(buf2, gd->arch.csb_clk),
Simon Glass4d6eaa32012-12-13 20:48:56 +000056 gd->arch.reset_status & 0xffff);
Rafal Jaworowskid3a02c32007-07-27 14:43:59 +020057 return 0;
58}
59
60
61int
Wolfgang Denk6262d0212010-06-28 22:00:46 +020062do_reset (cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
Rafal Jaworowskid3a02c32007-07-27 14:43:59 +020063{
64 ulong msr;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020065 volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
Rafal Jaworowskid3a02c32007-07-27 14:43:59 +020066
67 /* Interrupts and MMU off */
68 __asm__ __volatile__ ("mfmsr %0":"=r" (msr):);
69
70 msr &= ~( MSR_EE | MSR_IR | MSR_DR);
71 __asm__ __volatile__ ("mtmsr %0"::"r" (msr));
72
73 /*
74 * Enable Reset Control Reg - "RSTE" is the magic word that let us go
75 */
Detlev Zundel00c27162010-01-21 17:55:58 +010076 out_be32(&immap->reset.rpr, 0x52535445);
Rafal Jaworowskid3a02c32007-07-27 14:43:59 +020077
78 /* Verify Reset Control Reg is enabled */
Detlev Zundel00c27162010-01-21 17:55:58 +010079 while (!(in_be32(&immap->reset.rcer) & RCER_CRE))
Rafal Jaworowskid3a02c32007-07-27 14:43:59 +020080 ;
81
82 printf ("Resetting the board.\n");
83 udelay(200);
84
85 /* Perform reset */
Detlev Zundel00c27162010-01-21 17:55:58 +010086 out_be32(&immap->reset.rcr, RCR_SWHR);
Rafal Jaworowskid3a02c32007-07-27 14:43:59 +020087
88 /* Unreached... */
89 return 1;
90}
91
92
93/*
94 * Get timebase clock frequency (like cpu_clk in Hz)
95 */
96unsigned long get_tbclk (void)
97{
98 ulong tbclk;
99
100 tbclk = (gd->bus_clk + 3L) / 4L;
101
102 return tbclk;
103}
104
105
106#if defined(CONFIG_WATCHDOG)
107void watchdog_reset (void)
108{
109 int re_enable = disable_interrupts ();
110
111 /* Reset watchdog */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200112 volatile immap_t *immr = (immap_t *) CONFIG_SYS_IMMR;
Detlev Zundel00c27162010-01-21 17:55:58 +0100113 out_be32(&immr->wdt.swsrr, 0x556c);
114 out_be32(&immr->wdt.swsrr, 0xaa39);
Rafal Jaworowskid3a02c32007-07-27 14:43:59 +0200115
116 if (re_enable)
117 enable_interrupts ();
118}
119#endif
Grzegorz Bernackiaf554d82008-01-08 17:16:15 +0100120
121#ifdef CONFIG_OF_LIBFDT
John Rigbyd096f622008-08-05 17:38:57 -0600122
123#ifdef CONFIG_OF_SUPPORT_OLD_DEVICE_TREES
124/*
125 * fdt setup for old device trees
126 * fix up
127 * cpu clocks
128 * soc clocks
129 * ethernet addresses
130 */
131static void old_ft_cpu_setup(void *blob, bd_t *bd)
Grzegorz Bernackiaf554d82008-01-08 17:16:15 +0100132{
John Rigbyd096f622008-08-05 17:38:57 -0600133 /*
134 * avoid fixing up by path because that
135 * produces scary error messages
136 */
Mike Frysingerf4aa4362009-02-11 19:18:41 -0500137 uchar enetaddr[6];
John Rigbyd096f622008-08-05 17:38:57 -0600138
139 /*
140 * old device trees have ethernet nodes with
141 * device_type = "network"
142 */
Mike Frysingerf4aa4362009-02-11 19:18:41 -0500143 eth_getenv_enetaddr("ethaddr", enetaddr);
John Rigbyd096f622008-08-05 17:38:57 -0600144 do_fixup_by_prop(blob, "device_type", "network", 8,
Mike Frysingerf4aa4362009-02-11 19:18:41 -0500145 "local-mac-address", enetaddr, 6, 0);
John Rigbyd096f622008-08-05 17:38:57 -0600146 do_fixup_by_prop(blob, "device_type", "network", 8,
Mike Frysingerf4aa4362009-02-11 19:18:41 -0500147 "address", enetaddr, 6, 0);
John Rigbyd096f622008-08-05 17:38:57 -0600148 /*
149 * old device trees have soc nodes with
150 * device_type = "soc"
151 */
152 do_fixup_by_prop_u32(blob, "device_type", "soc", 4,
153 "bus-frequency", bd->bi_ipsfreq, 0);
154}
155#endif
156
157static void ft_clock_setup(void *blob, bd_t *bd)
158{
Martha Marxfd449ab2008-05-29 14:23:25 -0400159 char *cpu_path = "/cpus/" OF_CPU;
Grzegorz Bernackiaf554d82008-01-08 17:16:15 +0100160
John Rigbyd096f622008-08-05 17:38:57 -0600161 /*
162 * fixup cpu clocks using path
163 */
164 do_fixup_by_path_u32(blob, cpu_path,
165 "timebase-frequency", OF_TBCLK, 1);
166 do_fixup_by_path_u32(blob, cpu_path,
167 "bus-frequency", bd->bi_busfreq, 1);
168 do_fixup_by_path_u32(blob, cpu_path,
169 "clock-frequency", bd->bi_intfreq, 1);
170 /*
171 * fixup soc clocks using compatible
172 */
173 do_fixup_by_compat_u32(blob, OF_SOC_COMPAT,
174 "bus-frequency", bd->bi_ipsfreq, 1);
175}
John Rigbyfc807c52008-01-30 13:36:57 -0700176
John Rigbyd096f622008-08-05 17:38:57 -0600177void ft_cpu_setup(void *blob, bd_t *bd)
178{
179#ifdef CONFIG_OF_SUPPORT_OLD_DEVICE_TREES
180 old_ft_cpu_setup(blob, bd);
181#endif
182 ft_clock_setup(blob, bd);
183#ifdef CONFIG_HAS_ETH0
Kumar Galafabda922008-08-19 15:41:18 -0500184 fdt_fixup_ethernet(blob);
John Rigbyd096f622008-08-05 17:38:57 -0600185#endif
Heiko Schocher733b48d2009-12-03 11:20:06 +0100186 fdt_fixup_memory(blob, (u64)bd->bi_memstart, (u64)bd->bi_memsize);
Grzegorz Bernackiaf554d82008-01-08 17:16:15 +0100187}
188#endif
Ben Warrenb664dea2008-08-31 10:36:38 -0700189
190#ifdef CONFIG_MPC512x_FEC
191/* Default initializations for FEC controllers. To override,
192 * create a board-specific function called:
193 * int board_eth_init(bd_t *bis)
194 */
195
196int cpu_eth_init(bd_t *bis)
197{
198 return mpc512x_fec_initialize(bis);
199}
200#endif