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
7 Signed-off-by: Jonas Gorski <jonas.gorski@gmail.com>
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
18 --- a/arch/mips/bcm63xx/Makefile
19 +++ b/arch/mips/bcm63xx/Makefile
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-spi.o dev-trng.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-spi.o dev-trng.o dev-uart.o dev-usb-ehci.o \
27 dev-usb-ohci.o dev-wdt.o
28 obj-$(CONFIG_EARLY_PRINTK) += early_printk.o
30 --- a/arch/mips/bcm63xx/boards/board_bcm963xx.c
31 +++ b/arch/mips/bcm63xx/boards/board_bcm963xx.c
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>
41 #define CFE_OFFSET_64K 0x10000
42 #define CFE_OFFSET_128K 0x20000
44 -static struct bcm963xx_nvram nvram;
45 -static unsigned int mac_addr_used;
46 static struct board_info board;
49 @@ -696,50 +695,16 @@ const char *board_get_name(void)
54 - * register & return a new board mac address
56 -static int board_get_mac_address(u8 *mac)
61 - if (mac_addr_used >= nvram.mac_addr_count) {
62 - printk(KERN_ERR PFX "not enough mac address\n");
66 - memcpy(mac, nvram.mac_addr_base, ETH_ALEN);
67 - p = mac + ETH_ALEN - 1;
68 - count = mac_addr_used;
80 - printk(KERN_ERR PFX "unable to fetch mac address\n");
88 static void __init boardid_fixup(u8 *boot_addr)
90 struct bcm_tag *tag = (struct bcm_tag *)(boot_addr + CFE_OFFSET_64K);
91 + char *board_name = (char *)bcm63xx_nvram_get_name();
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) {
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) {
101 printk(KERN_DEBUG "No bcm_tag found!\n");
103 @@ -749,9 +714,9 @@ static void __init boardid_fixup(u8 *boo
104 if (tag->information1[0] != '+')
107 - strncpy(nvram.name, &tag->information1[1], BOARDID_LEN);
108 + strncpy(board_name, &tag->information1[1], BOARDID_LEN);
110 - printk(KERN_INFO "Overriding boardid with '%s'\n", nvram.name);
111 + printk(KERN_INFO "Overriding boardid with '%s'\n", board_name);
115 @@ -759,9 +724,10 @@ static void __init boardid_fixup(u8 *boo
117 void __init board_prom_init(void)
119 - unsigned int check_len, i;
120 - u8 *boot_addr, *cfe, *p;
122 + u8 *boot_addr, *cfe;
123 char cfe_version[32];
127 /* read base address of boot chip select (0)
128 @@ -783,32 +749,19 @@ void __init board_prom_init(void)
129 strcpy(cfe_version, "unknown");
130 printk(KERN_INFO PFX "CFE version: %s\n", cfe_version);
132 - /* extract nvram data */
133 - memcpy(&nvram, boot_addr + BCM963XX_NVRAM_OFFSET, sizeof(nvram));
135 - /* check checksum before using data */
136 - if (nvram.version <= 4)
137 - check_len = offsetof(struct bcm963xx_nvram, checksum_old);
139 - check_len = sizeof(nvram);
142 - while (check_len--)
145 - printk(KERN_ERR PFX "invalid nvram checksum\n");
146 + if (bcm63xx_nvram_init(boot_addr + BCM963XX_NVRAM_OFFSET))
150 if (strcmp(cfe_version, "unknown") != 0) {
152 boardid_fixup(boot_addr);
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))
163 /* copy, board desc array is marked initdata */
164 memcpy(&board, bcm963xx_boards[i], sizeof(board));
165 @@ -818,7 +771,7 @@ void __init board_prom_init(void)
166 /* bail out if board is not found, will complain later */
167 if (!board.name[0]) {
169 - memcpy(name, nvram.name, 16);
170 + memcpy(name, board_name, 16);
172 printk(KERN_ERR PFX "unknown bcm963xx board: %s\n",
174 @@ -910,15 +863,15 @@ int __init board_register_devices(void)
175 bcm63xx_pcmcia_register();
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);
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);
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);
193 @@ -934,7 +887,7 @@ int __init board_register_devices(void)
194 * do this after registering enet devices
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(
203 +++ b/arch/mips/bcm63xx/nvram.c
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.
210 + * Copyright (C) 2012 Jonas Gorski <jonas.gorski@gmail.com>
213 +#define pr_fmt(fmt) "bcm63xx_nvram: " fmt
215 +#include <linux/init.h>
216 +#include <linux/export.h>
217 +#include <linux/kernel.h>
219 +#include <bcm63xx_nvram.h>
221 +static struct bcm963xx_nvram nvram;
222 +static int mac_addr_used;
224 +int __init bcm63xx_nvram_init(void *addr)
226 + unsigned int check_len;
230 + /* extract nvram data */
231 + memcpy(&nvram, addr, sizeof(nvram));
233 + /* check checksum before using data */
234 + if (nvram.version <= 4)
235 + check_len = offsetof(struct bcm963xx_nvram, checksum_old);
237 + check_len = sizeof(nvram);
241 + while (check_len--)
244 + pr_err("invalid nvram checksum\n");
251 +u8 *bcm63xx_nvram_get_name(void)
255 +EXPORT_SYMBOL(bcm63xx_nvram_get_name);
257 +int bcm63xx_nvram_get_mac_address(u8 *mac)
262 + if (mac_addr_used >= nvram.mac_addr_count) {
263 + pr_err("not enough mac address\n");
267 + memcpy(mac, nvram.mac_addr_base, ETH_ALEN);
268 + p = mac + ETH_ALEN - 1;
269 + count = mac_addr_used;
277 + } while (p != mac);
281 + pr_err("unable to fetch mac address\n");
288 +EXPORT_SYMBOL(bcm63xx_nvram_get_mac_address);
290 +++ b/arch/mips/include/asm/mach-bcm63xx/bcm63xx_nvram.h
292 +#ifndef BCM63XX_NVRAM_H
293 +#define BCM63XX_NVRAM_H
295 +#include <linux/if_ether.h>
297 +#define BCM63XX_NVRAM_NAMELEN 16
302 +struct bcm963xx_nvram {
305 + u8 name[BCM63XX_NVRAM_NAMELEN];
306 + u32 main_tp_number;
308 + u32 mac_addr_count;
309 + u8 mac_addr_base[ETH_ALEN];
316 +int __init bcm63xx_nvram_init(void *);
318 +u8 *bcm63xx_nvram_get_name(void);
321 + * register & return a new board mac address
323 +int bcm63xx_nvram_get_mac_address(u8 *mac);
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
329 #define BCM963XX_NVRAM_OFFSET 0x580
334 -struct bcm963xx_nvram {
338 - u32 main_tp_number;
340 - u32 mac_addr_count;
341 - u8 mac_addr_base[6];