General indent and whitespace cleanups.
[oweals/u-boot.git] / cpu / mpc86xx / cpu.c
1 /*
2  * Copyright 2006 Freescale Semiconductor
3  * Jeff Brown
4  * 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
35 #ifdef CONFIG_MPC8641HPCN
36 extern void mpc8641_reset_board(cmd_tbl_t *cmdtp, int flag,
37                                 int argc, char *argv[]);
38 #endif
39
40
41 int
42 checkcpu(void)
43 {
44         sys_info_t sysinfo;
45         uint pvr, svr;
46         uint ver;
47         uint major, minor;
48         uint lcrr;              /* local bus clock ratio register */
49         uint clkdiv;            /* clock divider portion of lcrr */
50
51         puts("Freescale PowerPC\n");
52
53         pvr = get_pvr();
54         ver = PVR_VER(pvr);
55         major = PVR_MAJ(pvr);
56         minor = PVR_MIN(pvr);
57
58         puts("CPU:\n");
59         puts("    Core: ");
60
61         switch (ver) {
62         case PVR_VER(PVR_86xx):
63                 puts("E600");
64                 break;
65         default:
66                 puts("Unknown");
67                 break;
68         }
69         printf(", Version: %d.%d, (0x%08x)\n", major, minor, pvr);
70
71         svr = get_svr();
72         ver = SVR_VER(svr);
73         major = SVR_MAJ(svr);
74         minor = SVR_MIN(svr);
75
76         puts("    System: ");
77         switch (ver) {
78         case SVR_8641:
79                 puts("8641");
80                 break;
81         case SVR_8641D:
82                 puts("8641D");
83                 break;
84         default:
85                 puts("Unknown");
86                 break;
87         }
88         printf(", Version: %d.%d, (0x%08x)\n", major, minor, svr);
89
90         get_sys_info(&sysinfo);
91
92         puts("    Clocks: ");
93         printf("CPU:%4lu MHz, ", sysinfo.freqProcessor / 1000000);
94         printf("MPX:%4lu MHz, ", sysinfo.freqSystemBus / 1000000);
95         printf("DDR:%4lu MHz, ", sysinfo.freqSystemBus / 2000000);
96
97 #if defined(CFG_LBC_LCRR)
98         lcrr = CFG_LBC_LCRR;
99 #else
100         {
101                 volatile immap_t *immap = (immap_t *) CFG_IMMR;
102                 volatile ccsr_lbc_t *lbc = &immap->im_lbc;
103
104                 lcrr = lbc->lcrr;
105         }
106 #endif
107         clkdiv = lcrr & 0x0f;
108         if (clkdiv == 2 || clkdiv == 4 || clkdiv == 8) {
109                 printf("LBC:%4lu MHz\n",
110                        sysinfo.freqSystemBus / 1000000 / clkdiv);
111         } else {
112                 printf("    LBC: unknown (lcrr: 0x%08x)\n", lcrr);
113         }
114
115         puts("    L2: ");
116         if (get_l2cr() & 0x80000000)
117                 puts("Enabled\n");
118         else
119                 puts("Disabled\n");
120
121         return 0;
122 }
123
124
125 static inline void
126 soft_restart(unsigned long addr)
127 {
128 #ifndef CONFIG_MPC8641HPCN
129
130         /*
131          * SRR0 has system reset vector, SRR1 has default MSR value
132          * rfi restores MSR from SRR1 and sets the PC to the SRR0 value
133          */
134
135         __asm__ __volatile__ ("mtspr    26, %0"         :: "r" (addr));
136         __asm__ __volatile__ ("li       4, (1 << 6)"    ::: "r4");
137         __asm__ __volatile__ ("mtspr    27, 4");
138         __asm__ __volatile__ ("rfi");
139
140 #else /* CONFIG_MPC8641HPCN */
141
142         out8(PIXIS_BASE + PIXIS_RST, 0);
143
144 #endif /* !CONFIG_MPC8641HPCN */
145
146         while (1) ;             /* not reached */
147 }
148
149
150 /*
151  * No generic way to do board reset. Simply call soft_reset.
152  */
153 void
154 do_reset(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
155 {
156 #ifndef CONFIG_MPC8641HPCN
157
158 #ifdef CFG_RESET_ADDRESS
159         ulong addr = CFG_RESET_ADDRESS;
160 #else
161         /*
162          * note: when CFG_MONITOR_BASE points to a RAM address,
163          * CFG_MONITOR_BASE - sizeof (ulong) is usually a valid
164          * address. Better pick an address known to be invalid on your
165          * system and assign it to CFG_RESET_ADDRESS.
166          */
167         ulong addr = CFG_MONITOR_BASE - sizeof(ulong);
168 #endif
169
170         /* flush and disable I/D cache */
171         __asm__ __volatile__ ("mfspr    3, 1008"        ::: "r3");
172         __asm__ __volatile__ ("ori      5, 5, 0xcc00"   ::: "r5");
173         __asm__ __volatile__ ("ori      4, 3, 0xc00"    ::: "r4");
174         __asm__ __volatile__ ("andc     5, 3, 5"        ::: "r5");
175         __asm__ __volatile__ ("sync");
176         __asm__ __volatile__ ("mtspr    1008, 4");
177         __asm__ __volatile__ ("isync");
178         __asm__ __volatile__ ("sync");
179         __asm__ __volatile__ ("mtspr    1008, 5");
180         __asm__ __volatile__ ("isync");
181         __asm__ __volatile__ ("sync");
182
183         soft_restart(addr);
184
185 #else /* CONFIG_MPC8641HPCN */
186
187         mpc8641_reset_board(cmdtp, flag, argc, argv);
188
189 #endif /* !CONFIG_MPC8641HPCN */
190
191         while (1) ;             /* not reached */
192 }
193
194
195 /*
196  * Get timebase clock frequency
197  */
198 unsigned long
199 get_tbclk(void)
200 {
201         sys_info_t sys_info;
202
203         get_sys_info(&sys_info);
204         return (sys_info.freqSystemBus + 3L) / 4L;
205 }
206
207
208 #if defined(CONFIG_WATCHDOG)
209 void
210 watchdog_reset(void)
211 {
212 }
213 #endif  /* CONFIG_WATCHDOG */
214
215
216 #if defined(CONFIG_DDR_ECC)
217 void
218 dma_init(void)
219 {
220         volatile immap_t *immap = (immap_t *) CFG_IMMR;
221         volatile ccsr_dma_t *dma = &immap->im_dma;
222
223         dma->satr0 = 0x00040000;
224         dma->datr0 = 0x00040000;
225         asm("sync; isync");
226 }
227
228 uint
229 dma_check(void)
230 {
231         volatile immap_t *immap = (immap_t *) CFG_IMMR;
232         volatile ccsr_dma_t *dma = &immap->im_dma;
233         volatile uint status = dma->sr0;
234
235         /* While the channel is busy, spin */
236         while ((status & 4) == 4) {
237                 status = dma->sr0;
238         }
239
240         if (status != 0) {
241                 printf("DMA Error: status = %x\n", status);
242         }
243         return status;
244 }
245
246 int
247 dma_xfer(void *dest, uint count, void *src)
248 {
249         volatile immap_t *immap = (immap_t *) CFG_IMMR;
250         volatile ccsr_dma_t *dma = &immap->im_dma;
251
252         dma->dar0 = (uint) dest;
253         dma->sar0 = (uint) src;
254         dma->bcr0 = count;
255         dma->mr0 = 0xf000004;
256         asm("sync;isync");
257         dma->mr0 = 0xf000005;
258         asm("sync;isync");
259         return dma_check();
260 }
261
262 #endif  /* CONFIG_DDR_ECC */
263
264
265 #ifdef CONFIG_OF_FLAT_TREE
266 void
267 ft_cpu_setup(void *blob, bd_t *bd)
268 {
269         u32 *p;
270         ulong clock;
271         int len;
272
273         clock = bd->bi_busfreq;
274         p = ft_get_prop(blob, "/cpus/" OF_CPU "/bus-frequency", &len);
275         if (p != NULL)
276                 *p = cpu_to_be32(clock);
277
278         p = ft_get_prop(blob, "/" OF_SOC "/serial@4500/clock-frequency", &len);
279         if (p != NULL)
280                 *p = cpu_to_be32(clock);
281
282         p = ft_get_prop(blob, "/" OF_SOC "/serial@4600/clock-frequency", &len);
283         if (p != NULL)
284                 *p = cpu_to_be32(clock);
285
286 #if defined(CONFIG_MPC86XX_TSEC1)
287         p = ft_get_prop(blob, "/" OF_SOC "/ethernet@24000/mac-address", &len);
288         memcpy(p, bd->bi_enetaddr, 6);
289 #endif
290
291 #if defined(CONFIG_MPC86XX_TSEC2)
292         p = ft_get_prop(blob, "/" OF_SOC "/ethernet@25000/mac-address", &len);
293         memcpy(p, bd->bi_enet1addr, 6);
294 #endif
295
296 #if defined(CONFIG_MPC86XX_TSEC3)
297         p = ft_get_prop(blob, "/" OF_SOC "/ethernet@26000/mac-address", &len);
298         memcpy(p, bd->bi_enet2addr, 6);
299 #endif
300
301 #if defined(CONFIG_MPC86XX_TSEC4)
302         p = ft_get_prop(blob, "/" OF_SOC "/ethernet@27000/mac-address", &len);
303         memcpy(p, bd->bi_enet3addr, 6);
304 #endif
305
306 }
307 #endif