blob: 0e82e74fa34d18150748dc31d2d2d57943a67668 [file] [log] [blame]
Jon Loeligerdebb7352006-04-26 17:58:56 -05001/*
Jon Loeligercb5965f2006-05-31 12:44:44 -05002 * Copyright 2006 Freescale Semiconductor
3 * Jeff Brown
Jon Loeligerdebb7352006-04-26 17:58:56 -05004 * Srikanth Srinivasan (srikanth.srinivasan@freescale.com)
5 *
6 * See file CREDITS for list of people who contributed to this
7 * project.
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License as
11 * published by the Free Software Foundation; either version 2 of
12 * the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
22 * MA 02111-1307 USA
23 */
24
25#include <common.h>
26#include <watchdog.h>
27#include <command.h>
28#include <asm/cache.h>
29#include <mpc86xx.h>
30
31#if defined(CONFIG_OF_FLAT_TREE)
32#include <ft_build.h>
33#endif
34
Jon Loeliger4d3d7292006-05-31 11:24:28 -050035#ifdef CONFIG_MPC8641HPCN
36extern void mpc8641_reset_board(cmd_tbl_t *cmdtp, int flag,
37 int argc, char *argv[]);
38#endif
Jon Loeligerdebb7352006-04-26 17:58:56 -050039
Jon Loeligerdebb7352006-04-26 17:58:56 -050040
Jon Loeligerdebb7352006-04-26 17:58:56 -050041int checkcpu (void)
42{
43 sys_info_t sysinfo;
44 uint pvr, svr;
45 uint ver;
46 uint major, minor;
47 uint lcrr; /* local bus clock ratio register */
48 uint clkdiv; /* clock divider portion of lcrr */
Jon Loeliger5c9efb32006-04-27 10:15:16 -050049
Jon Loeligerdebb7352006-04-26 17:58:56 -050050 puts("Freescale PowerPC\n");
51
52 pvr = get_pvr();
53 ver = PVR_VER(pvr);
54 major = PVR_MAJ(pvr);
55 minor = PVR_MIN(pvr);
56
Jon Loeliger5c9efb32006-04-27 10:15:16 -050057 puts("CPU:\n");
Jon Loeligercb5965f2006-05-31 12:44:44 -050058 puts(" Core: ");
Jon Loeliger5c9efb32006-04-27 10:15:16 -050059
Jon Loeligerdebb7352006-04-26 17:58:56 -050060 switch (ver) {
61 case PVR_VER(PVR_86xx):
62 puts("E600");
63 break;
64 default:
65 puts("Unknown");
66 break;
67 }
68 printf(", Version: %d.%d, (0x%08x)\n", major, minor, pvr);
69
70 svr = get_svr();
71 ver = SVR_VER(svr);
72 major = SVR_MAJ(svr);
73 minor = SVR_MIN(svr);
74
75 puts(" System: ");
Jon Loeliger5c9efb32006-04-27 10:15:16 -050076 switch (ver) {
Jon Loeligerdebb7352006-04-26 17:58:56 -050077 case SVR_8641:
78 puts("8641");
79 break;
80 case SVR_8641D:
81 puts("8641D");
82 break;
83 default:
84 puts("Unknown");
85 break;
86 }
87 printf(", Version: %d.%d, (0x%08x)\n", major, minor, svr);
88
89 get_sys_info(&sysinfo);
90
91 puts(" Clocks: ");
92 printf("CPU:%4lu MHz, ", sysinfo.freqProcessor / 1000000);
93 printf("MPX:%4lu MHz, ", sysinfo.freqSystemBus / 1000000);
94 printf("DDR:%4lu MHz, ", sysinfo.freqSystemBus / 2000000);
Jon Loeliger5c9efb32006-04-27 10:15:16 -050095
Jon Loeligerdebb7352006-04-26 17:58:56 -050096#if defined(CFG_LBC_LCRR)
97 lcrr = CFG_LBC_LCRR;
98#else
99 {
100 volatile immap_t *immap = (immap_t *)CFG_IMMR;
101 volatile ccsr_lbc_t *lbc= &immap->im_lbc;
102
103 lcrr = lbc->lcrr;
104 }
105#endif
106 clkdiv = lcrr & 0x0f;
107 if (clkdiv == 2 || clkdiv == 4 || clkdiv == 8) {
108 printf("LBC:%4lu MHz\n",
109 sysinfo.freqSystemBus / 1000000 / clkdiv);
110 } else {
111 printf(" LBC: unknown (lcrr: 0x%08x)\n", lcrr);
112 }
113
Jon Loeligercb5965f2006-05-31 12:44:44 -0500114 puts(" L2: ");
Jon Loeliger126aa702006-05-30 17:47:00 -0500115 if (get_l2cr() & 0x80000000)
Jon Loeligercb5965f2006-05-31 12:44:44 -0500116 puts("Enabled\n");
Jon Loeliger126aa702006-05-30 17:47:00 -0500117 else
Jon Loeligercb5965f2006-05-31 12:44:44 -0500118 puts("Disabled\n");
Jon Loeliger5c9efb32006-04-27 10:15:16 -0500119
120 return 0;
Jon Loeligerdebb7352006-04-26 17:58:56 -0500121}
122
123
Jon Loeligerdebb7352006-04-26 17:58:56 -0500124static inline void
125soft_restart(unsigned long addr)
126{
Jon Loeligerdebb7352006-04-26 17:58:56 -0500127#ifndef CONFIG_MPC8641HPCN
Jon Loeliger5c9efb32006-04-27 10:15:16 -0500128
Jon Loeligerdebb7352006-04-26 17:58:56 -0500129 /* SRR0 has system reset vector, SRR1 has default MSR value */
130 /* rfi restores MSR from SRR1 and sets the PC to the SRR0 value */
131
132 __asm__ __volatile__ ("mtspr 26, %0" :: "r" (addr));
133 __asm__ __volatile__ ("li 4, (1 << 6)" ::: "r4");
134 __asm__ __volatile__ ("mtspr 27, 4");
135 __asm__ __volatile__ ("rfi");
136
137#else /* CONFIG_MPC8641HPCN */
Jon Loeligercb5965f2006-05-31 12:44:44 -0500138
139 out8(PIXIS_BASE + PIXIS_RST, 0);
140
Jon Loeligerdebb7352006-04-26 17:58:56 -0500141#endif /* !CONFIG_MPC8641HPCN */
Jon Loeligercb5965f2006-05-31 12:44:44 -0500142
Jon Loeligerdebb7352006-04-26 17:58:56 -0500143 while(1); /* not reached */
144}
145
146
Jon Loeliger126aa702006-05-30 17:47:00 -0500147/*
148 * No generic way to do board reset. Simply call soft_reset.
149 */
Jon Loeligerdebb7352006-04-26 17:58:56 -0500150void
Jon Loeliger126aa702006-05-30 17:47:00 -0500151do_reset(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
Jon Loeligerdebb7352006-04-26 17:58:56 -0500152{
Jon Loeligercb5965f2006-05-31 12:44:44 -0500153#ifndef CONFIG_MPC8641HPCN
Jon Loeligerdebb7352006-04-26 17:58:56 -0500154
155#ifdef CFG_RESET_ADDRESS
Jon Loeligercb5965f2006-05-31 12:44:44 -0500156 ulong addr = CFG_RESET_ADDRESS;
Jon Loeligerdebb7352006-04-26 17:58:56 -0500157#else
158 /*
159 * note: when CFG_MONITOR_BASE points to a RAM address,
160 * CFG_MONITOR_BASE - sizeof (ulong) is usually a valid
161 * address. Better pick an address known to be invalid on your
162 * system and assign it to CFG_RESET_ADDRESS.
163 */
Jon Loeligercb5965f2006-05-31 12:44:44 -0500164 ulong addr = CFG_MONITOR_BASE - sizeof(ulong);
Jon Loeligerdebb7352006-04-26 17:58:56 -0500165#endif
166
Jon Loeliger5c9efb32006-04-27 10:15:16 -0500167 /* flush and disable I/D cache */
Jon Loeligerdebb7352006-04-26 17:58:56 -0500168 __asm__ __volatile__ ("mfspr 3, 1008" ::: "r3");
169 __asm__ __volatile__ ("ori 5, 5, 0xcc00" ::: "r5");
170 __asm__ __volatile__ ("ori 4, 3, 0xc00" ::: "r4");
171 __asm__ __volatile__ ("andc 5, 3, 5" ::: "r5");
172 __asm__ __volatile__ ("sync");
173 __asm__ __volatile__ ("mtspr 1008, 4");
174 __asm__ __volatile__ ("isync");
175 __asm__ __volatile__ ("sync");
176 __asm__ __volatile__ ("mtspr 1008, 5");
177 __asm__ __volatile__ ("isync");
178 __asm__ __volatile__ ("sync");
179
Jon Loeliger126aa702006-05-30 17:47:00 -0500180 soft_restart(addr);
Jon Loeligerdebb7352006-04-26 17:58:56 -0500181
182#else /* CONFIG_MPC8641HPCN */
Jon Loeligerdebb7352006-04-26 17:58:56 -0500183
Jon Loeliger4d3d7292006-05-31 11:24:28 -0500184 mpc8641_reset_board(cmdtp, flag, argc, argv);
Jon Loeliger5c9efb32006-04-27 10:15:16 -0500185
Jon Loeligerdebb7352006-04-26 17:58:56 -0500186#endif /* !CONFIG_MPC8641HPCN */
Jon Loeliger5c9efb32006-04-27 10:15:16 -0500187
Jon Loeligerdebb7352006-04-26 17:58:56 -0500188 while(1); /* not reached */
189}
190
191
Jon Loeligerdebb7352006-04-26 17:58:56 -0500192/*
193 * Get timebase clock frequency
194 */
195unsigned long get_tbclk(void)
196{
197 sys_info_t sys_info;
198
199 get_sys_info(&sys_info);
Jon Loeliger5c9efb32006-04-27 10:15:16 -0500200 return (sys_info.freqSystemBus + 3L) / 4L;
Jon Loeligerdebb7352006-04-26 17:58:56 -0500201}
202
Jon Loeligerdebb7352006-04-26 17:58:56 -0500203
204#if defined(CONFIG_WATCHDOG)
205void
206watchdog_reset(void)
207{
Jon Loeligerdebb7352006-04-26 17:58:56 -0500208}
209#endif /* CONFIG_WATCHDOG */
210
Jon Loeligerdebb7352006-04-26 17:58:56 -0500211
212#if defined(CONFIG_DDR_ECC)
Jon Loeliger5c9efb32006-04-27 10:15:16 -0500213void dma_init(void)
214{
Jon Loeligerdebb7352006-04-26 17:58:56 -0500215 volatile immap_t *immap = (immap_t *)CFG_IMMR;
216 volatile ccsr_dma_t *dma = &immap->im_dma;
217
218 dma->satr0 = 0x00040000;
219 dma->datr0 = 0x00040000;
220 asm("sync; isync");
Jon Loeligerdebb7352006-04-26 17:58:56 -0500221}
222
Jon Loeliger5c9efb32006-04-27 10:15:16 -0500223uint dma_check(void)
224{
Jon Loeligerdebb7352006-04-26 17:58:56 -0500225 volatile immap_t *immap = (immap_t *)CFG_IMMR;
226 volatile ccsr_dma_t *dma = &immap->im_dma;
227 volatile uint status = dma->sr0;
228
229 /* While the channel is busy, spin */
230 while((status & 4) == 4) {
231 status = dma->sr0;
232 }
233
234 if (status != 0) {
235 printf ("DMA Error: status = %x\n", status);
236 }
237 return status;
238}
239
Jon Loeliger5c9efb32006-04-27 10:15:16 -0500240int dma_xfer(void *dest, uint count, void *src)
241{
Jon Loeligerdebb7352006-04-26 17:58:56 -0500242 volatile immap_t *immap = (immap_t *)CFG_IMMR;
243 volatile ccsr_dma_t *dma = &immap->im_dma;
244
245 dma->dar0 = (uint) dest;
246 dma->sar0 = (uint) src;
247 dma->bcr0 = count;
248 dma->mr0 = 0xf000004;
249 asm("sync;isync");
250 dma->mr0 = 0xf000005;
251 asm("sync;isync");
252 return dma_check();
253}
Jon Loeliger5c9efb32006-04-27 10:15:16 -0500254
Jon Loeligerdebb7352006-04-26 17:58:56 -0500255#endif /* CONFIG_DDR_ECC */
256
257
258#ifdef CONFIG_OF_FLAT_TREE
259void ft_cpu_setup(void *blob, bd_t *bd)
260{
261 u32 *p;
262 ulong clock;
263 int len;
Jon Loeliger5c9efb32006-04-27 10:15:16 -0500264
Jon Loeligerdebb7352006-04-26 17:58:56 -0500265 clock = bd->bi_busfreq;
266 p = ft_get_prop(blob, "/cpus/" OF_CPU "/bus-frequency", &len);
267 if (p != NULL)
268 *p = cpu_to_be32(clock);
269
270 p = ft_get_prop(blob, "/" OF_SOC "/serial@4500/clock-frequency", &len);
271 if (p != NULL)
272 *p = cpu_to_be32(clock);
273
274 p = ft_get_prop(blob, "/" OF_SOC "/serial@4600/clock-frequency", &len);
275 if (p != NULL)
276 *p = cpu_to_be32(clock);
277
278#if defined(CONFIG_MPC86XX_TSEC1)
Jon Loeliger709d3072006-08-03 16:17:56 -0500279 p = ft_get_prop(blob, "/" OF_SOC "/ethernet@24000/mac-address", &len);
Jon Loeligerdebb7352006-04-26 17:58:56 -0500280 memcpy(p, bd->bi_enetaddr, 6);
281#endif
Jon Loeliger5c9efb32006-04-27 10:15:16 -0500282
Jon Loeligerdebb7352006-04-26 17:58:56 -0500283#if defined(CONFIG_MPC86XX_TSEC2)
Jon Loeliger709d3072006-08-03 16:17:56 -0500284 p = ft_get_prop(blob, "/" OF_SOC "/ethernet@25000/mac-address", &len);
Jon Loeligerdebb7352006-04-26 17:58:56 -0500285 memcpy(p, bd->bi_enet1addr, 6);
286#endif
287
288#if defined(CONFIG_MPC86XX_TSEC3)
Jon Loeliger709d3072006-08-03 16:17:56 -0500289 p = ft_get_prop(blob, "/" OF_SOC "/ethernet@26000/mac-address", &len);
Jon Loeligerdebb7352006-04-26 17:58:56 -0500290 memcpy(p, bd->bi_enet2addr, 6);
291#endif
292
293#if defined(CONFIG_MPC86XX_TSEC4)
Jon Loeliger709d3072006-08-03 16:17:56 -0500294 p = ft_get_prop(blob, "/" OF_SOC "/ethernet@27000/mac-address", &len);
Jon Loeligerdebb7352006-04-26 17:58:56 -0500295 memcpy(p, bd->bi_enet3addr, 6);
296#endif
297
298}
299#endif