ff2a831d84bedfde3c2b57a8c14955c6f83366e1
[openwrt/svn-archive/archive.git] / target / linux / brcm63xx / patches-3.3 / 421-MIPS-BCM63XX-move-nvram-related-functions-into-their.patch
1 From 5b753c1d01c6af23d7d37d37d9de30da8a971084 Mon Sep 17 00:00:00 2001
2 From: Jonas Gorski <jonas.gorski@gmail.com>
3 Date: Sat, 12 May 2012 22:51:08 +0200
4 Subject: [PATCH 60/79] MIPS: BCM63XX: move nvram related functions into their
5 own file
6
7 Signed-off-by: Jonas Gorski <jonas.gorski@gmail.com>
8 ---
9 arch/mips/bcm63xx/Makefile | 6 +-
10 arch/mips/bcm63xx/boards/board_bcm963xx.c | 74 +++--------------
11 arch/mips/bcm63xx/nvram.c | 84 ++++++++++++++++++++
12 arch/mips/include/asm/mach-bcm63xx/bcm63xx_nvram.h | 34 ++++++++
13 .../mips/include/asm/mach-bcm63xx/board_bcm963xx.h | 17 ----
14 5 files changed, 134 insertions(+), 81 deletions(-)
15 create mode 100644 arch/mips/bcm63xx/nvram.c
16 create mode 100644 arch/mips/include/asm/mach-bcm63xx/bcm63xx_nvram.h
17
18 --- a/arch/mips/bcm63xx/Makefile
19 +++ b/arch/mips/bcm63xx/Makefile
20 @@ -1,6 +1,6 @@
21 -obj-y += clk.o cpu.o cs.o gpio.o irq.o prom.o setup.o timer.o \
22 - dev-dsp.o dev-enet.o dev-flash.o dev-hsspi.o dev-pcmcia.o \
23 - dev-rng.o dev-spi.o dev-uart.o dev-usb-ehci.o \
24 +obj-y += clk.o cpu.o cs.o gpio.o irq.o nvram.o prom.o setup.o \
25 + timer.o dev-dsp.o dev-enet.o dev-flash.o dev-hsspi.o \
26 + dev-pcmcia.o dev-rng.o dev-spi.o dev-uart.o dev-usb-ehci.o \
27 dev-usb-ohci.o dev-wdt.o
28 obj-$(CONFIG_EARLY_PRINTK) += early_printk.o
29
30 --- a/arch/mips/bcm63xx/boards/board_bcm963xx.c
31 +++ b/arch/mips/bcm63xx/boards/board_bcm963xx.c
32 @@ -21,6 +21,7 @@
33 #include <bcm63xx_dev_uart.h>
34 #include <bcm63xx_regs.h>
35 #include <bcm63xx_io.h>
36 +#include <bcm63xx_nvram.h>
37 #include <bcm63xx_dev_pci.h>
38 #include <bcm63xx_dev_enet.h>
39 #include <bcm63xx_dev_dsp.h>
40 @@ -41,8 +42,6 @@
41 #define CFE_OFFSET_64K 0x10000
42 #define CFE_OFFSET_128K 0x20000
43
44 -static struct bcm963xx_nvram nvram;
45 -static unsigned int mac_addr_used;
46 static struct board_info board;
47
48 /*
49 @@ -696,50 +695,16 @@ const char *board_get_name(void)
50 return board.name;
51 }
52
53 -/*
54 - * register & return a new board mac address
55 - */
56 -static int board_get_mac_address(u8 *mac)
57 -{
58 - u8 *p;
59 - int count;
60 -
61 - if (mac_addr_used >= nvram.mac_addr_count) {
62 - printk(KERN_ERR PFX "not enough mac address\n");
63 - return -ENODEV;
64 - }
65 -
66 - memcpy(mac, nvram.mac_addr_base, ETH_ALEN);
67 - p = mac + ETH_ALEN - 1;
68 - count = mac_addr_used;
69 -
70 - while (count--) {
71 - do {
72 - (*p)++;
73 - if (*p != 0)
74 - break;
75 - p--;
76 - } while (p != mac);
77 - }
78 -
79 - if (p == mac) {
80 - printk(KERN_ERR PFX "unable to fetch mac address\n");
81 - return -ENODEV;
82 - }
83 -
84 - mac_addr_used++;
85 - return 0;
86 -}
87 -
88 static void __init boardid_fixup(u8 *boot_addr)
89 {
90 struct bcm_tag *tag = (struct bcm_tag *)(boot_addr + CFE_OFFSET_64K);
91 + char *board_name = (char *)bcm63xx_nvram_get_name();
92
93 /* check if bcm_tag is at 64k offset */
94 - if (strncmp(nvram.name, tag->boardid, BOARDID_LEN) != 0) {
95 + if (strncmp(board_name, tag->boardid, BOARDID_LEN) != 0) {
96 /* else try 128k */
97 tag = (struct bcm_tag *)(boot_addr + CFE_OFFSET_128K);
98 - if (strncmp(nvram.name, tag->boardid, BOARDID_LEN) != 0) {
99 + if (strncmp(board_name, tag->boardid, BOARDID_LEN) != 0) {
100 /* No tag found */
101 printk(KERN_DEBUG "No bcm_tag found!\n");
102 return;
103 @@ -749,9 +714,9 @@ static void __init boardid_fixup(u8 *boo
104 if (tag->information1[0] != '+')
105 return;
106
107 - strncpy(nvram.name, &tag->information1[1], BOARDID_LEN);
108 + strncpy(board_name, &tag->information1[1], BOARDID_LEN);
109
110 - printk(KERN_INFO "Overriding boardid with '%s'\n", nvram.name);
111 + printk(KERN_INFO "Overriding boardid with '%s'\n", board_name);
112 }
113
114 /*
115 @@ -759,9 +724,10 @@ static void __init boardid_fixup(u8 *boo
116 */
117 void __init board_prom_init(void)
118 {
119 - unsigned int check_len, i;
120 - u8 *boot_addr, *cfe, *p;
121 + unsigned int i;
122 + u8 *boot_addr, *cfe;
123 char cfe_version[32];
124 + char *board_name;
125 u32 val;
126
127 /* read base address of boot chip select (0)
128 @@ -786,32 +752,19 @@ void __init board_prom_init(void)
129 strcpy(cfe_version, "unknown");
130 printk(KERN_INFO PFX "CFE version: %s\n", cfe_version);
131
132 - /* extract nvram data */
133 - memcpy(&nvram, boot_addr + BCM963XX_NVRAM_OFFSET, sizeof(nvram));
134 -
135 - /* check checksum before using data */
136 - if (nvram.version <= 4)
137 - check_len = offsetof(struct bcm963xx_nvram, checksum_old);
138 - else
139 - check_len = sizeof(nvram);
140 - val = 0;
141 - p = (u8 *)&nvram;
142 - while (check_len--)
143 - val += *p;
144 - if (val) {
145 - printk(KERN_ERR PFX "invalid nvram checksum\n");
146 + if (bcm63xx_nvram_init(boot_addr + BCM963XX_NVRAM_OFFSET))
147 return;
148 - }
149
150 if (strcmp(cfe_version, "unknown") != 0) {
151 /* cfe present */
152 boardid_fixup(boot_addr);
153 }
154
155 + board_name = bcm63xx_nvram_get_name();
156 /* find board by name */
157 for (i = 0; i < ARRAY_SIZE(bcm963xx_boards); i++) {
158 - if (strncmp(nvram.name, bcm963xx_boards[i]->name,
159 - sizeof(nvram.name)))
160 + if (strncmp(board_name, bcm963xx_boards[i]->name,
161 + BCM63XX_NVRAM_NAMELEN))
162 continue;
163 /* copy, board desc array is marked initdata */
164 memcpy(&board, bcm963xx_boards[i], sizeof(board));
165 @@ -821,7 +774,7 @@ void __init board_prom_init(void)
166 /* bail out if board is not found, will complain later */
167 if (!board.name[0]) {
168 char name[17];
169 - memcpy(name, nvram.name, 16);
170 + memcpy(name, board_name, 16);
171 name[16] = 0;
172 printk(KERN_ERR PFX "unknown bcm963xx board: %s\n",
173 name);
174 @@ -914,15 +867,15 @@ int __init board_register_devices(void)
175 bcm63xx_pcmcia_register();
176
177 if (board.has_enet0 &&
178 - !board_get_mac_address(board.enet0.mac_addr))
179 + !bcm63xx_nvram_get_mac_address(board.enet0.mac_addr))
180 bcm63xx_enet_register(0, &board.enet0);
181
182 if (board.has_enet1 &&
183 - !board_get_mac_address(board.enet1.mac_addr))
184 + !bcm63xx_nvram_get_mac_address(board.enet1.mac_addr))
185 bcm63xx_enet_register(1, &board.enet1);
186
187 if (board.has_enetsw &&
188 - !board_get_mac_address(board.enetsw.mac_addr))
189 + !bcm63xx_nvram_get_mac_address(board.enetsw.mac_addr))
190 bcm63xx_enetsw_register(&board.enetsw);
191
192 if (board.has_ehci0)
193 @@ -938,7 +891,7 @@ int __init board_register_devices(void)
194 * do this after registering enet devices
195 */
196 #ifdef CONFIG_SSB_PCIHOST
197 - if (!board_get_mac_address(bcm63xx_sprom.il0mac)) {
198 + if (!bcm63xx_nvram_get_mac_address(bcm63xx_sprom.il0mac)) {
199 memcpy(bcm63xx_sprom.et0mac, bcm63xx_sprom.il0mac, ETH_ALEN);
200 memcpy(bcm63xx_sprom.et1mac, bcm63xx_sprom.il0mac, ETH_ALEN);
201 if (ssb_arch_register_fallback_sprom(
202 --- /dev/null
203 +++ b/arch/mips/bcm63xx/nvram.c
204 @@ -0,0 +1,84 @@
205 +/*
206 + * This file is subject to the terms and conditions of the GNU General Public
207 + * License. See the file "COPYING" in the main directory of this archive
208 + * for more details.
209 + *
210 + * Copyright (C) 2012 Jonas Gorski <jonas.gorski@gmail.com>
211 + */
212 +
213 +#define pr_fmt(fmt) "bcm63xx_nvram: " fmt
214 +
215 +#include <linux/init.h>
216 +#include <linux/export.h>
217 +#include <linux/kernel.h>
218 +
219 +#include <bcm63xx_nvram.h>
220 +
221 +static struct bcm963xx_nvram nvram;
222 +static int mac_addr_used;
223 +
224 +int __init bcm63xx_nvram_init(void *addr)
225 +{
226 + unsigned int check_len;
227 + u8 *p;
228 + u32 val;
229 +
230 + /* extract nvram data */
231 + memcpy(&nvram, addr, sizeof(nvram));
232 +
233 + /* check checksum before using data */
234 + if (nvram.version <= 4)
235 + check_len = offsetof(struct bcm963xx_nvram, checksum_old);
236 + else
237 + check_len = sizeof(nvram);
238 + val = 0;
239 + p = (u8 *)&nvram;
240 +
241 + while (check_len--)
242 + val += *p;
243 + if (val) {
244 + pr_err("invalid nvram checksum\n");
245 + return -EINVAL;
246 + }
247 +
248 + return 0;
249 +}
250 +
251 +u8 *bcm63xx_nvram_get_name(void)
252 +{
253 + return nvram.name;
254 +}
255 +EXPORT_SYMBOL(bcm63xx_nvram_get_name);
256 +
257 +int bcm63xx_nvram_get_mac_address(u8 *mac)
258 +{
259 + u8 *p;
260 + int count;
261 +
262 + if (mac_addr_used >= nvram.mac_addr_count) {
263 + pr_err("not enough mac address\n");
264 + return -ENODEV;
265 + }
266 +
267 + memcpy(mac, nvram.mac_addr_base, ETH_ALEN);
268 + p = mac + ETH_ALEN - 1;
269 + count = mac_addr_used;
270 +
271 + while (count--) {
272 + do {
273 + (*p)++;
274 + if (*p != 0)
275 + break;
276 + p--;
277 + } while (p != mac);
278 + }
279 +
280 + if (p == mac) {
281 + pr_err("unable to fetch mac address\n");
282 + return -ENODEV;
283 + }
284 +
285 + mac_addr_used++;
286 + return 0;
287 +}
288 +EXPORT_SYMBOL(bcm63xx_nvram_get_mac_address);
289 --- /dev/null
290 +++ b/arch/mips/include/asm/mach-bcm63xx/bcm63xx_nvram.h
291 @@ -0,0 +1,34 @@
292 +#ifndef BCM63XX_NVRAM_H
293 +#define BCM63XX_NVRAM_H
294 +
295 +#include <linux/if_ether.h>
296 +
297 +#define BCM63XX_NVRAM_NAMELEN 16
298 +
299 +/*
300 + * nvram structure
301 + */
302 +struct bcm963xx_nvram {
303 + u32 version;
304 + u8 reserved1[256];
305 + u8 name[BCM63XX_NVRAM_NAMELEN];
306 + u32 main_tp_number;
307 + u32 psi_size;
308 + u32 mac_addr_count;
309 + u8 mac_addr_base[ETH_ALEN];
310 + u8 reserved2[2];
311 + u32 checksum_old;
312 + u8 reserved3[720];
313 + u32 checksum_high;
314 +};
315 +
316 +int __init bcm63xx_nvram_init(void *);
317 +
318 +u8 *bcm63xx_nvram_get_name(void);
319 +
320 +/*
321 + * register & return a new board mac address
322 + */
323 +int bcm63xx_nvram_get_mac_address(u8 *mac);
324 +
325 +#endif /* BCM63XX_NVRAM_H */
326 --- a/arch/mips/include/asm/mach-bcm63xx/board_bcm963xx.h
327 +++ b/arch/mips/include/asm/mach-bcm63xx/board_bcm963xx.h
328 @@ -15,23 +15,6 @@
329 #define BCM963XX_NVRAM_OFFSET 0x580
330
331 /*
332 - * nvram structure
333 - */
334 -struct bcm963xx_nvram {
335 - u32 version;
336 - u8 reserved1[256];
337 - u8 name[16];
338 - u32 main_tp_number;
339 - u32 psi_size;
340 - u32 mac_addr_count;
341 - u8 mac_addr_base[6];
342 - u8 reserved2[2];
343 - u32 checksum_old;
344 - u8 reserved3[720];
345 - u32 checksum_high;
346 -};
347 -
348 -/*
349 * board definition
350 */
351 struct board_info {