Add qemu 2.4.0
[kvmfornfv.git] / qemu / roms / u-boot / arch / powerpc / cpu / mpc5xxx / cpu.c
1 /*
2  * (C) Copyright 2000-2010
3  * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
4  *
5  * SPDX-License-Identifier:     GPL-2.0+
6  */
7
8 /*
9  * CPU specific code for the MPC5xxx CPUs
10  */
11
12 #include <common.h>
13 #include <watchdog.h>
14 #include <command.h>
15 #include <net.h>
16 #include <mpc5xxx.h>
17 #include <netdev.h>
18 #include <asm/io.h>
19 #include <asm/processor.h>
20
21 #if defined(CONFIG_OF_LIBFDT)
22 #include <libfdt.h>
23 #include <fdt_support.h>
24 #endif
25
26 #if defined(CONFIG_OF_IDE_FIXUP)
27 #include <ide.h>
28 #endif
29
30 DECLARE_GLOBAL_DATA_PTR;
31
32 int checkcpu (void)
33 {
34         ulong clock = gd->cpu_clk;
35         char buf[32];
36         uint svr, pvr;
37
38         puts ("CPU:   ");
39
40         svr = get_svr();
41         pvr = get_pvr();
42
43         switch (pvr) {
44         case PVR_5200:
45                 printf("MPC5200");
46                 break;
47         case PVR_5200B:
48                 printf("MPC5200B");
49                 break;
50         default:
51                 printf("Unknown MPC5xxx");
52                 break;
53         }
54
55         printf (" v%d.%d, Core v%d.%d", SVR_MJREV (svr), SVR_MNREV (svr),
56                 PVR_MAJ(pvr), PVR_MIN(pvr));
57         printf (" at %s MHz\n", strmhz (buf, clock));
58         return 0;
59 }
60
61 /* ------------------------------------------------------------------------- */
62
63 int
64 do_reset (cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
65 {
66         ulong msr;
67         /* Interrupts and MMU off */
68         __asm__ __volatile__ ("mfmsr    %0":"=r" (msr):);
69
70         msr &= ~(MSR_ME | MSR_EE | MSR_IR | MSR_DR);
71         __asm__ __volatile__ ("mtmsr    %0"::"r" (msr));
72
73         /* Charge the watchdog timer */
74         *(vu_long *)(MPC5XXX_GPT0_COUNTER) = 0x0001000f;
75         *(vu_long *)(MPC5XXX_GPT0_ENABLE) = 0x9004; /* wden|ce|timer_ms */
76         while(1);
77
78         return 1;
79
80 }
81
82 /* ------------------------------------------------------------------------- */
83
84 /*
85  * Get timebase clock frequency (like cpu_clk in Hz)
86  *
87  */
88 unsigned long get_tbclk (void)
89 {
90         ulong tbclk;
91
92         tbclk = (gd->bus_clk + 3L) / 4L;
93
94         return (tbclk);
95 }
96
97 /* ------------------------------------------------------------------------- */
98
99 #if defined(CONFIG_OF_LIBFDT) && defined (CONFIG_OF_BOARD_SETUP)
100 void ft_cpu_setup(void *blob, bd_t *bd)
101 {
102         int div = in_8((void*)CONFIG_SYS_MBAR + 0x204) & 0x0020 ? 8 : 4;
103         char * cpu_path = "/cpus/" OF_CPU;
104 #ifdef CONFIG_MPC5xxx_FEC
105         uchar enetaddr[6];
106         char * eth_path = "/" OF_SOC "/ethernet@3000";
107 #endif
108
109         do_fixup_by_path_u32(blob, cpu_path, "timebase-frequency", OF_TBCLK, 1);
110         do_fixup_by_path_u32(blob, cpu_path, "bus-frequency", bd->bi_busfreq, 1);
111         do_fixup_by_path_u32(blob, cpu_path, "clock-frequency", bd->bi_intfreq, 1);
112         do_fixup_by_path_u32(blob, "/" OF_SOC, "bus-frequency", bd->bi_ipbfreq, 1);
113         do_fixup_by_path_u32(blob, "/" OF_SOC, "system-frequency",
114                                 bd->bi_busfreq*div, 1);
115 #ifdef CONFIG_MPC5xxx_FEC
116         eth_getenv_enetaddr("ethaddr", enetaddr);
117         do_fixup_by_path(blob, eth_path, "mac-address", enetaddr, 6, 0);
118         do_fixup_by_path(blob, eth_path, "local-mac-address", enetaddr, 6, 0);
119 #endif
120 #if defined(CONFIG_OF_IDE_FIXUP)
121         if (!ide_device_present(0)) {
122                 /* NO CF card detected -> delete ata node in DTS */
123                 int nodeoffset = 0;
124                 char nodename[] = "/soc5200@f0000000/ata@3a00";
125
126                 nodeoffset = fdt_path_offset(blob, nodename);
127                 if (nodeoffset >= 0) {
128                         fdt_del_node(blob, nodeoffset);
129                 } else {
130                         printf("%s: cannot find %s node err:%s\n",
131                                 __func__, nodename, fdt_strerror(nodeoffset));
132                 }
133         }
134
135 #endif
136         fdt_fixup_memory(blob, (u64)bd->bi_memstart, (u64)bd->bi_memsize);
137 }
138 #endif
139
140 #ifdef CONFIG_MPC5xxx_FEC
141 /* Default initializations for FEC controllers.  To override,
142  * create a board-specific function called:
143  *      int board_eth_init(bd_t *bis)
144  */
145
146 int cpu_eth_init(bd_t *bis)
147 {
148         return mpc5xxx_fec_initialize(bis);
149 }
150 #endif
151
152 #if defined(CONFIG_WATCHDOG)
153 void watchdog_reset(void)
154 {
155         int re_enable = disable_interrupts();
156         reset_5xxx_watchdog();
157         if (re_enable) enable_interrupts();
158 }
159
160 void reset_5xxx_watchdog(void)
161 {
162         volatile struct mpc5xxx_gpt *gpt0 =
163                 (struct mpc5xxx_gpt *) MPC5XXX_GPT;
164
165         /* Trigger TIMER_0 by writing A5 to OCPW */
166         clrsetbits_be32(&gpt0->emsr, 0xff000000, 0xa5000000);
167 }
168 #endif  /* CONFIG_WATCHDOG */