Merge branch 'mpc86xx'
[platform/kernel/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 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 */
49
50         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
57         puts("CPU:\n");
58         puts("    Core: ");
59
60         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: ");
76         switch (ver) {
77         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);
95
96 #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
114         puts("    L2: ");
115         if (get_l2cr() & 0x80000000)
116                 puts("Enabled\n");
117         else
118                 puts("Disabled\n");
119
120         return 0;
121 }
122
123
124 static inline void
125 soft_restart(unsigned long addr)
126 {
127 #ifndef CONFIG_MPC8641HPCN
128
129         /* 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 */
138
139         out8(PIXIS_BASE + PIXIS_RST, 0);
140
141 #endif /* !CONFIG_MPC8641HPCN */
142
143         while(1);       /* not reached */
144 }
145
146
147 /*
148  * No generic way to do board reset. Simply call soft_reset.
149  */
150 void
151 do_reset(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
152 {
153 #ifndef CONFIG_MPC8641HPCN
154
155 #ifdef CFG_RESET_ADDRESS
156         ulong addr = CFG_RESET_ADDRESS;
157 #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          */
164         ulong addr = CFG_MONITOR_BASE - sizeof(ulong);
165 #endif
166
167         /* flush and disable I/D cache */
168         __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
180         soft_restart(addr);
181
182 #else /* CONFIG_MPC8641HPCN */
183
184         mpc8641_reset_board(cmdtp, flag, argc, argv);
185
186 #endif /* !CONFIG_MPC8641HPCN */
187
188         while(1);       /* not reached */
189 }
190
191
192 /*
193  * Get timebase clock frequency
194  */
195 unsigned long get_tbclk(void)
196 {
197         sys_info_t  sys_info;
198
199         get_sys_info(&sys_info);
200         return (sys_info.freqSystemBus + 3L) / 4L;
201 }
202
203
204 #if defined(CONFIG_WATCHDOG)
205 void
206 watchdog_reset(void)
207 {
208 }
209 #endif  /* CONFIG_WATCHDOG */
210
211
212 #if defined(CONFIG_DDR_ECC)
213 void dma_init(void)
214 {
215         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");
221 }
222
223 uint dma_check(void)
224 {
225         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
240 int dma_xfer(void *dest, uint count, void *src)
241 {
242         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 }
254
255 #endif  /* CONFIG_DDR_ECC */
256
257
258 #ifdef CONFIG_OF_FLAT_TREE
259 void ft_cpu_setup(void *blob, bd_t *bd)
260 {
261         u32 *p;
262         ulong clock;
263         int len;
264
265         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)
279         p = ft_get_prop(blob, "/" OF_SOC "/ethernet@24000/address", &len);
280         memcpy(p, bd->bi_enetaddr, 6);
281 #endif
282
283 #if defined(CONFIG_MPC86XX_TSEC2)
284         p = ft_get_prop(blob, "/" OF_SOC "/ethernet@25000/address", &len);
285         memcpy(p, bd->bi_enet1addr, 6);
286 #endif
287
288 #if defined(CONFIG_MPC86XX_TSEC3)
289         p = ft_get_prop(blob, "/" OF_SOC "/ethernet@26000/address", &len);
290         memcpy(p, bd->bi_enet2addr, 6);
291 #endif
292
293 #if defined(CONFIG_MPC86XX_TSEC4)
294         p = ft_get_prop(blob, "/" OF_SOC "/ethernet@27000/address", &len);
295          memcpy(p, bd->bi_enet3addr, 6);
296 #endif
297
298 }
299 #endif