1 From a4304adb62af528957ed8858c9eb4f2630abe6d7 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] MIPS: BCM63XX: move nvram functions into their own file
6 Refactor nvram related functions into its own unit for easier expansion
7 and exposure of the values to other drivers.
9 Signed-off-by: Jonas Gorski <jonas.gorski@gmail.com>
12 This patch depends on the previous reset helper patch series or the
13 Makefile change needs to be merged manually. It has no real functional
16 arch/mips/bcm63xx/Makefile | 7 +-
17 arch/mips/bcm63xx/boards/board_bcm963xx.c | 71 ++-----------
18 arch/mips/bcm63xx/nvram.c | 104 ++++++++++++++++++++
19 arch/mips/include/asm/mach-bcm63xx/bcm63xx_nvram.h | 35 +++++++
20 .../mips/include/asm/mach-bcm63xx/board_bcm963xx.h | 17 ---
21 5 files changed, 154 insertions(+), 80 deletions(-)
22 create mode 100644 arch/mips/bcm63xx/nvram.c
23 create mode 100644 arch/mips/include/asm/mach-bcm63xx/bcm63xx_nvram.h
25 --- a/arch/mips/bcm63xx/Makefile
26 +++ b/arch/mips/bcm63xx/Makefile
28 -obj-y += clk.o cpu.o cs.o gpio.o irq.o prom.o reset.o setup.o \
29 - timer.o dev-dsp.o dev-enet.o dev-flash.o dev-pcmcia.o \
30 - dev-rng.o dev-spi.o dev-uart.o dev-wdt.o dev-usb-usbd.o
31 +obj-y += clk.o cpu.o cs.o gpio.o irq.o nvram.o prom.o reset.o \
32 + setup.o timer.o dev-dsp.o dev-enet.o dev-flash.o \
33 + dev-pcmcia.o dev-rng.o dev-spi.o dev-uart.o dev-wdt.o \
35 obj-$(CONFIG_EARLY_PRINTK) += early_printk.o
38 --- a/arch/mips/bcm63xx/boards/board_bcm963xx.c
39 +++ b/arch/mips/bcm63xx/boards/board_bcm963xx.c
41 #include <bcm63xx_dev_uart.h>
42 #include <bcm63xx_regs.h>
43 #include <bcm63xx_io.h>
44 +#include <bcm63xx_nvram.h>
45 #include <bcm63xx_dev_pci.h>
46 #include <bcm63xx_dev_enet.h>
47 #include <bcm63xx_dev_dsp.h>
50 #define PFX "board_bcm963xx: "
52 -static struct bcm963xx_nvram nvram;
53 -static unsigned int mac_addr_used;
54 static struct board_info board;
57 @@ -716,50 +715,14 @@ const char *board_get_name(void)
61 - * register & return a new board mac address
63 -static int board_get_mac_address(u8 *mac)
68 - if (mac_addr_used >= nvram.mac_addr_count) {
69 - printk(KERN_ERR PFX "not enough mac address\n");
73 - memcpy(mac, nvram.mac_addr_base, ETH_ALEN);
74 - oui = mac + ETH_ALEN/2 - 1;
75 - count = mac_addr_used;
78 - u8 *p = mac + ETH_ALEN - 1;
88 - printk(KERN_ERR PFX "unable to fetch mac address\n");
98 * early init callback, read nvram data from flash and checksum it
100 void __init board_prom_init(void)
102 - unsigned int check_len, i;
103 - u8 *boot_addr, *cfe, *p;
105 + u8 *boot_addr, *cfe;
106 char cfe_version[32];
110 /* read base address of boot chip select (0)
111 @@ -782,27 +745,15 @@ void __init board_prom_init(void)
112 strcpy(cfe_version, "unknown");
113 printk(KERN_INFO PFX "CFE version: %s\n", cfe_version);
115 - /* extract nvram data */
116 - memcpy(&nvram, boot_addr + BCM963XX_NVRAM_OFFSET, sizeof(nvram));
118 - /* check checksum before using data */
119 - if (nvram.version <= 4)
120 - check_len = offsetof(struct bcm963xx_nvram, checksum_old);
122 - check_len = sizeof(nvram);
125 - while (check_len--)
128 + if (bcm63xx_nvram_init(boot_addr + BCM963XX_NVRAM_OFFSET)) {
129 printk(KERN_ERR PFX "invalid nvram checksum\n");
133 + board_name = bcm63xx_nvram_get_name();
134 /* find board by name */
135 for (i = 0; i < ARRAY_SIZE(bcm963xx_boards); i++) {
136 - if (strncmp(nvram.name, bcm963xx_boards[i]->name,
137 - sizeof(nvram.name)))
138 + if (strncmp(board_name, bcm963xx_boards[i]->name, 16))
140 /* copy, board desc array is marked initdata */
141 memcpy(&board, bcm963xx_boards[i], sizeof(board));
142 @@ -812,7 +763,7 @@ void __init board_prom_init(void)
143 /* bail out if board is not found, will complain later */
144 if (!board.name[0]) {
146 - memcpy(name, nvram.name, 16);
147 + memcpy(name, board_name, 16);
149 printk(KERN_ERR PFX "unknown bcm963xx board: %s\n",
151 @@ -890,11 +841,11 @@ int __init board_register_devices(void)
152 bcm63xx_pcmcia_register();
154 if (board.has_enet0 &&
155 - !board_get_mac_address(board.enet0.mac_addr))
156 + !bcm63xx_nvram_get_mac_address(board.enet0.mac_addr))
157 bcm63xx_enet_register(0, &board.enet0);
159 if (board.has_enet1 &&
160 - !board_get_mac_address(board.enet1.mac_addr))
161 + !bcm63xx_nvram_get_mac_address(board.enet1.mac_addr))
162 bcm63xx_enet_register(1, &board.enet1);
165 @@ -907,7 +858,7 @@ int __init board_register_devices(void)
166 * do this after registering enet devices
168 #ifdef CONFIG_SSB_PCIHOST
169 - if (!board_get_mac_address(bcm63xx_sprom.il0mac)) {
170 + if (!bcm63xx_nvram_get_mac_address(bcm63xx_sprom.il0mac)) {
171 memcpy(bcm63xx_sprom.et0mac, bcm63xx_sprom.il0mac, ETH_ALEN);
172 memcpy(bcm63xx_sprom.et1mac, bcm63xx_sprom.il0mac, ETH_ALEN);
173 if (ssb_arch_register_fallback_sprom(
175 +++ b/arch/mips/bcm63xx/nvram.c
178 + * This file is subject to the terms and conditions of the GNU General Public
179 + * License. See the file "COPYING" in the main directory of this archive
180 + * for more details.
182 + * Copyright (C) 2008 Maxime Bizon <mbizon@freebox.fr>
183 + * Copyright (C) 2008 Florian Fainelli <florian@openwrt.org>
184 + * Copyright (C) 2012 Jonas Gorski <jonas.gorski@gmail.com>
187 +#define pr_fmt(fmt) "bcm63xx_nvram: " fmt
189 +#include <linux/init.h>
190 +#include <linux/export.h>
191 +#include <linux/kernel.h>
192 +#include <linux/if_ether.h>
194 +#include <bcm63xx_nvram.h>
199 +struct bcm963xx_nvram {
203 + u32 main_tp_number;
205 + u32 mac_addr_count;
206 + u8 mac_addr_base[ETH_ALEN];
213 +static struct bcm963xx_nvram nvram;
214 +static int mac_addr_used;
216 +int __init bcm63xx_nvram_init(void *addr)
218 + unsigned int check_len;
222 + /* extract nvram data */
223 + memcpy(&nvram, addr, sizeof(nvram));
225 + /* check checksum before using data */
226 + if (nvram.version <= 4)
227 + check_len = offsetof(struct bcm963xx_nvram, checksum_old);
229 + check_len = sizeof(nvram);
233 + while (check_len--)
241 +u8 *bcm63xx_nvram_get_name(void)
245 +EXPORT_SYMBOL(bcm63xx_nvram_get_name);
247 +int bcm63xx_nvram_get_mac_address(u8 *mac)
252 + if (mac_addr_used >= nvram.mac_addr_count) {
253 + pr_err("not enough mac addresses\n");
257 + memcpy(mac, nvram.mac_addr_base, ETH_ALEN);
258 + oui = mac + ETH_ALEN/2 - 1;
259 + count = mac_addr_used;
262 + u8 *p = mac + ETH_ALEN - 1;
269 + } while (p != oui);
272 + pr_err("unable to fetch mac address\n");
280 +EXPORT_SYMBOL(bcm63xx_nvram_get_mac_address);
282 +++ b/arch/mips/include/asm/mach-bcm63xx/bcm63xx_nvram.h
284 +#ifndef BCM63XX_NVRAM_H
285 +#define BCM63XX_NVRAM_H
287 +#include <linux/types.h>
290 + * bcm63xx_nvram_init() - initializes nvram
291 + * @nvram: address of the nvram data
293 + * Initialized the local nvram copy from the target address and checks
296 + * Returns 0 on success.
298 +int __init bcm63xx_nvram_init(void *nvram);
301 + * bcm63xx_nvram_get_name() - returns the board name according to nvram
303 + * Returns the board name field from nvram. Note that it might not be
304 + * null terminated if it is exactly 16 bytes long.
306 +u8 *bcm63xx_nvram_get_name(void);
309 + * bcm63xx_nvram_get_mac_address() - register & return a new mac address
310 + * @mac: pointer to array for allocated mac
312 + * Registers and returns a mac address from the allocated macs from nvram.
314 + * Returns 0 on success.
316 +int bcm63xx_nvram_get_mac_address(u8 *mac);
318 +#endif /* BCM63XX_NVRAM_H */
319 --- a/arch/mips/include/asm/mach-bcm63xx/board_bcm963xx.h
320 +++ b/arch/mips/include/asm/mach-bcm63xx/board_bcm963xx.h
322 #define BCM963XX_NVRAM_OFFSET 0x580
327 -struct bcm963xx_nvram {
331 - u32 main_tp_number;
333 - u32 mac_addr_count;
334 - u8 mac_addr_base[6];