]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - arch/arm/cpu/arm926ejs/orion5x/cpu.c
Merge branch 'master' of git://git.denx.de/u-boot-video
[karo-tx-uboot.git] / arch / arm / cpu / arm926ejs / orion5x / cpu.c
1 /*
2  * Copyright (C) 2010 Albert ARIBAUD <albert.u.boot@aribaud.net>
3  *
4  * Based on original Kirkwood support which is
5  * (C) Copyright 2009
6  * Marvell Semiconductor <www.marvell.com>
7  * Written-by: Prafulla Wadaskar <prafulla@marvell.com>
8  *
9  * See file CREDITS for list of people who contributed to this
10  * project.
11  *
12  * This program is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU General Public License as
14  * published by the Free Software Foundation; either version 2 of
15  * the License, or (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program; if not, write to the Free Software
24  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
25  * MA 02110-1301 USA
26  */
27
28 #include <common.h>
29 #include <netdev.h>
30 #include <asm/cache.h>
31 #include <asm/io.h>
32 #include <u-boot/md5.h>
33 #include <asm/arch/cpu.h>
34 #include <hush.h>
35
36 #define BUFLEN  16
37
38 void reset_cpu(unsigned long ignored)
39 {
40         struct orion5x_cpu_registers *cpureg =
41             (struct orion5x_cpu_registers *)ORION5X_CPU_REG_BASE;
42
43         writel(readl(&cpureg->rstoutn_mask) | (1 << 2),
44                 &cpureg->rstoutn_mask);
45         writel(readl(&cpureg->sys_soft_rst) | 1,
46                 &cpureg->sys_soft_rst);
47         while (1)
48                 ;
49 }
50
51 /*
52  * Compute Window Size field value from size expressed in bytes
53  * Used with the Base register to set the address window size and location.
54  * Must be programmed from LSB to MSB as sequence of ones followed by
55  * sequence of zeros. The number of ones specifies the size of the window in
56  * 64 KiB granularity (e.g., a value of 0x00FF specifies 256 = 16 MiB).
57  * NOTES:
58  * 1) A sizeval equal to 0x0 specifies 4 GiB.
59  * 2) A return value of 0x0 specifies 64 KiB.
60  */
61 unsigned int orion5x_winctrl_calcsize(unsigned int sizeval)
62 {
63         /*
64          * Calculate the number of 64 KiB blocks needed minus one (rounding up).
65          * For sizeval > 0 this is equivalent to:
66          * sizeval = (u32) ceil((double) sizeval / 65536.0) - 1
67          */
68         sizeval = (sizeval - 1) >> 16;
69
70         /*
71          * Propagate 'one' bits to the right by 'oring' them.
72          * We need only treat bits 15-0.
73          */
74         sizeval |= sizeval >> 1;  /* 'Or' bit 15 onto bit 14 */
75         sizeval |= sizeval >> 2;  /* 'Or' bits 15-14 onto bits 13-12 */
76         sizeval |= sizeval >> 4;  /* 'Or' bits 15-12 onto bits 11-8 */
77         sizeval |= sizeval >> 8;  /* 'Or' bits 15-8 onto bits 7-0*/
78
79         return sizeval;
80 }
81
82 /*
83  * orion5x_config_adr_windows - Configure address Windows
84  *
85  * There are 8 address windows supported by Orion5x Soc to addess different
86  * devices. Each window can be configured for size, BAR and remap addr
87  * Below configuration is standard for most of the cases
88  *
89  * If remap function not used, remap_lo must be set as base
90  *
91  * NOTES:
92  *
93  * 1) in order to avoid windows with inconsistent control and base values
94  *    (which could prevent access to BOOTCS and hence execution from FLASH)
95  *    always disable window before writing the base value then reenable it
96  *    by writing the control value.
97  *
98  * 2) in order to avoid losing access to BOOTCS when disabling window 7,
99  *    first configure window 6 for BOOTCS, then configure window 7 for BOOTCS,
100  *    then configure windows 6 for its own target.
101  *
102  * Reference Documentation:
103  * Mbus-L to Mbus Bridge Registers Configuration.
104  * (Sec 25.1 and 25.3 of Datasheet)
105  */
106 int orion5x_config_adr_windows(void)
107 {
108         struct orion5x_win_registers *winregs =
109                 (struct orion5x_win_registers *)ORION5X_CPU_WIN_BASE;
110
111 /* Disable window 0, configure it for its intended target, enable it. */
112         writel(0, &winregs[0].ctrl);
113         writel(ORION5X_ADR_PCIE_MEM, &winregs[0].base);
114         writel(ORION5X_ADR_PCIE_MEM_REMAP_LO, &winregs[0].remap_lo);
115         writel(ORION5X_ADR_PCIE_MEM_REMAP_HI, &winregs[0].remap_hi);
116         writel(ORION5X_CPU_WIN_CTRL_DATA(ORION5X_SZ_PCIE_MEM,
117                 ORION5X_TARGET_PCIE, ORION5X_ATTR_PCIE_MEM,
118                 ORION5X_WIN_ENABLE), &winregs[0].ctrl);
119 /* Disable window 1, configure it for its intended target, enable it. */
120         writel(0, &winregs[1].ctrl);
121         writel(ORION5X_ADR_PCIE_IO, &winregs[1].base);
122         writel(ORION5X_ADR_PCIE_IO_REMAP_LO, &winregs[1].remap_lo);
123         writel(ORION5X_ADR_PCIE_IO_REMAP_HI, &winregs[1].remap_hi);
124         writel(ORION5X_CPU_WIN_CTRL_DATA(ORION5X_SZ_PCIE_IO,
125                 ORION5X_TARGET_PCIE, ORION5X_ATTR_PCIE_IO,
126                 ORION5X_WIN_ENABLE), &winregs[1].ctrl);
127 /* Disable window 2, configure it for its intended target, enable it. */
128         writel(0, &winregs[2].ctrl);
129         writel(ORION5X_ADR_PCI_MEM, &winregs[2].base);
130         writel(ORION5X_CPU_WIN_CTRL_DATA(ORION5X_SZ_PCI_MEM,
131                 ORION5X_TARGET_PCI, ORION5X_ATTR_PCI_MEM,
132                 ORION5X_WIN_ENABLE), &winregs[2].ctrl);
133 /* Disable window 3, configure it for its intended target, enable it. */
134         writel(0, &winregs[3].ctrl);
135         writel(ORION5X_ADR_PCI_IO, &winregs[3].base);
136         writel(ORION5X_CPU_WIN_CTRL_DATA(ORION5X_SZ_PCI_IO,
137                 ORION5X_TARGET_PCI, ORION5X_ATTR_PCI_IO,
138                 ORION5X_WIN_ENABLE), &winregs[3].ctrl);
139 /* Disable window 4, configure it for its intended target, enable it. */
140         writel(0, &winregs[4].ctrl);
141         writel(ORION5X_ADR_DEV_CS0, &winregs[4].base);
142         writel(ORION5X_CPU_WIN_CTRL_DATA(ORION5X_SZ_DEV_CS0,
143                 ORION5X_TARGET_DEVICE, ORION5X_ATTR_DEV_CS0,
144                 ORION5X_WIN_ENABLE), &winregs[4].ctrl);
145 /* Disable window 5, configure it for its intended target, enable it. */
146         writel(0, &winregs[5].ctrl);
147         writel(ORION5X_ADR_DEV_CS1, &winregs[5].base);
148         writel(ORION5X_CPU_WIN_CTRL_DATA(ORION5X_SZ_DEV_CS1,
149                 ORION5X_TARGET_DEVICE, ORION5X_ATTR_DEV_CS1,
150                 ORION5X_WIN_ENABLE), &winregs[5].ctrl);
151 /* Disable window 6, configure it for FLASH, enable it. */
152         writel(0, &winregs[6].ctrl);
153         writel(ORION5X_ADR_BOOTROM, &winregs[6].base);
154         writel(ORION5X_CPU_WIN_CTRL_DATA(ORION5X_SZ_BOOTROM,
155                 ORION5X_TARGET_DEVICE, ORION5X_ATTR_BOOTROM,
156                 ORION5X_WIN_ENABLE), &winregs[6].ctrl);
157 /* Disable window 7, configure it for FLASH, enable it. */
158         writel(0, &winregs[7].ctrl);
159         writel(ORION5X_ADR_BOOTROM, &winregs[7].base);
160         writel(ORION5X_CPU_WIN_CTRL_DATA(ORION5X_SZ_BOOTROM,
161                 ORION5X_TARGET_DEVICE, ORION5X_ATTR_BOOTROM,
162                 ORION5X_WIN_ENABLE), &winregs[7].ctrl);
163 /* Disable window 6, configure it for its intended target, enable it. */
164         writel(0, &winregs[6].ctrl);
165         writel(ORION5X_ADR_DEV_CS2, &winregs[6].base);
166         writel(ORION5X_CPU_WIN_CTRL_DATA(ORION5X_SZ_DEV_CS2,
167                 ORION5X_TARGET_DEVICE, ORION5X_ATTR_DEV_CS2,
168                 ORION5X_WIN_ENABLE), &winregs[6].ctrl);
169
170         return 0;
171 }
172
173 /*
174  * Orion5x identification is done through PCIE space.
175  */
176
177 u32 orion5x_device_id(void)
178 {
179         return readl(PCIE_DEV_ID_OFF) >> 16;
180 }
181
182 u32 orion5x_device_rev(void)
183 {
184         return readl(PCIE_DEV_REV_OFF) & 0xff;
185 }
186
187 #if defined(CONFIG_DISPLAY_CPUINFO)
188
189 /* Display device and revision IDs.
190  * This function must cover all known device/revision
191  * combinations, not only the one for which u-boot is
192  * compiled; this way, one can identify actual HW in
193  * case of a mismatch.
194  */
195 int print_cpuinfo(void)
196 {
197         char dev_str[] = "0x0000";
198         char rev_str[] = "0x00";
199         char *dev_name = NULL;
200         char *rev_name = NULL;
201
202         u32 dev = orion5x_device_id();
203         u32 rev = orion5x_device_rev();
204
205         if (dev == MV88F5181_DEV_ID) {
206                 dev_name = "MV88F5181";
207                 if (rev == MV88F5181_REV_B1)
208                         rev_name = "B1";
209                 else if (rev == MV88F5181L_REV_A1) {
210                         dev_name = "MV88F5181L";
211                         rev_name = "A1";
212                 } else if (rev == MV88F5181L_REV_A0) {
213                         dev_name = "MV88F5181L";
214                         rev_name = "A0";
215                 }
216         } else if (dev == MV88F5182_DEV_ID) {
217                 dev_name = "MV88F5182";
218                 if (rev == MV88F5182_REV_A2)
219                         rev_name = "A2";
220         } else if (dev == MV88F5281_DEV_ID) {
221                 dev_name = "MV88F5281";
222                 if (rev == MV88F5281_REV_D2)
223                         rev_name = "D2";
224                 else if (rev == MV88F5281_REV_D1)
225                         rev_name = "D1";
226                 else if (rev == MV88F5281_REV_D0)
227                         rev_name = "D0";
228         } else if (dev == MV88F6183_DEV_ID) {
229                 dev_name = "MV88F6183";
230                 if (rev == MV88F6183_REV_B0)
231                         rev_name = "B0";
232         }
233         if (dev_name == NULL) {
234                 sprintf(dev_str, "0x%04x", dev);
235                 dev_name = dev_str;
236         }
237         if (rev_name == NULL) {
238                 sprintf(rev_str, "0x%02x", rev);
239                 rev_name = rev_str;
240         }
241
242         printf("SoC:   Orion5x %s-%s\n", dev_name, rev_name);
243
244         return 0;
245 }
246 #endif /* CONFIG_DISPLAY_CPUINFO */
247
248 #ifdef CONFIG_ARCH_CPU_INIT
249 int arch_cpu_init(void)
250 {
251         /* Enable and invalidate L2 cache in write through mode */
252         invalidate_l2_cache();
253
254         orion5x_config_adr_windows();
255
256         return 0;
257 }
258 #endif /* CONFIG_ARCH_CPU_INIT */
259
260 /*
261  * SOC specific misc init
262  */
263 #if defined(CONFIG_ARCH_MISC_INIT)
264 int arch_misc_init(void)
265 {
266         u32 temp;
267
268         /*CPU streaming & write allocate */
269         temp = readfr_extra_feature_reg();
270         temp &= ~(1 << 28);     /* disable wr alloc */
271         writefr_extra_feature_reg(temp);
272
273         temp = readfr_extra_feature_reg();
274         temp &= ~(1 << 29);     /* streaming disabled */
275         writefr_extra_feature_reg(temp);
276
277         /* L2Cache settings */
278         temp = readfr_extra_feature_reg();
279         /* Disable L2C pre fetch - Set bit 24 */
280         temp |= (1 << 24);
281         /* enable L2C - Set bit 22 */
282         temp |= (1 << 22);
283         writefr_extra_feature_reg(temp);
284
285         icache_enable();
286         /* Change reset vector to address 0x0 */
287         temp = get_cr();
288         set_cr(temp & ~CR_V);
289
290         /* Set CPIOs and MPPs - values provided by board
291            include file */
292         writel(ORION5X_MPP0_7, ORION5X_MPP_BASE+0x00);
293         writel(ORION5X_MPP8_15, ORION5X_MPP_BASE+0x04);
294         writel(ORION5X_MPP16_23, ORION5X_MPP_BASE+0x50);
295         writel(ORION5X_GPIO_OUT_VALUE, ORION5X_GPIO_BASE+0x00);
296         writel(ORION5X_GPIO_OUT_ENABLE, ORION5X_GPIO_BASE+0x04);
297         writel(ORION5X_GPIO_IN_POLARITY, ORION5X_GPIO_BASE+0x0c);
298
299         /* initialize timer */
300         timer_init_r();
301         return 0;
302 }
303 #endif /* CONFIG_ARCH_MISC_INIT */
304
305 #ifdef CONFIG_MVGBE
306 int cpu_eth_init(bd_t *bis)
307 {
308         mvgbe_initialize(bis);
309         return 0;
310 }
311 #endif