1 From bd489dfe8c0d7495645cbc8b8c283217ba816fab Mon Sep 17 00:00:00 2001
2 From: Hauke Mehrtens <hauke@hauke-m.de>
3 Date: Sun, 4 May 2014 16:35:42 +0200
4 Subject: [PATCH 02/15] bcm47xx: move the nvram header file into common space
6 Moving mach-bcm47xx/bcm47xx_nvram.h makes it possible to reuse this
7 header on the arm bcm47xx (BCM5301X) devices. This way a driver gets
8 the correct functions to access the nvram depending on the SoC it boots
11 arch/mips/bcm47xx/board.c | 2 +-
12 arch/mips/bcm47xx/nvram.c | 2 +-
13 arch/mips/bcm47xx/setup.c | 2 +-
14 arch/mips/bcm47xx/sprom.c | 2 +-
15 arch/mips/bcm47xx/time.c | 2 +-
16 arch/mips/include/asm/mach-bcm47xx/bcm47xx_nvram.h | 53 ------------------
17 drivers/net/ethernet/broadcom/b44.c | 8 +--
18 drivers/net/ethernet/broadcom/bgmac.c | 2 +-
19 drivers/ssb/driver_chipcommon_pmu.c | 6 +-
20 include/linux/bcm47xx_nvram.h | 65 ++++++++++++++++++++++
21 10 files changed, 73 insertions(+), 71 deletions(-)
22 delete mode 100644 arch/mips/include/asm/mach-bcm47xx/bcm47xx_nvram.h
23 create mode 100644 include/linux/bcm47xx_nvram.h
25 --- a/arch/mips/bcm47xx/board.c
26 +++ b/arch/mips/bcm47xx/board.c
28 #include <linux/export.h>
29 #include <linux/string.h>
30 #include <bcm47xx_board.h>
31 -#include <bcm47xx_nvram.h>
32 +#include <linux/bcm47xx_nvram.h>
34 struct bcm47xx_board_type {
35 const enum bcm47xx_board board;
36 --- a/arch/mips/bcm47xx/nvram.c
37 +++ b/arch/mips/bcm47xx/nvram.c
39 #include <linux/kernel.h>
40 #include <linux/string.h>
41 #include <asm/addrspace.h>
42 -#include <bcm47xx_nvram.h>
43 +#include <linux/bcm47xx_nvram.h>
44 #include <asm/mach-bcm47xx/bcm47xx.h>
46 static char nvram_buf[NVRAM_SPACE];
47 --- a/arch/mips/bcm47xx/setup.c
48 +++ b/arch/mips/bcm47xx/setup.c
50 #include <asm/reboot.h>
53 -#include <bcm47xx_nvram.h>
54 +#include <linux/bcm47xx_nvram.h>
55 #include <bcm47xx_board.h>
57 union bcm47xx_bus bcm47xx_bus;
58 --- a/arch/mips/bcm47xx/sprom.c
59 +++ b/arch/mips/bcm47xx/sprom.c
64 -#include <bcm47xx_nvram.h>
65 +#include <linux/bcm47xx_nvram.h>
67 static void create_key(const char *prefix, const char *postfix,
68 const char *name, char *buf, int len)
69 --- a/arch/mips/bcm47xx/time.c
70 +++ b/arch/mips/bcm47xx/time.c
72 #include <linux/ssb/ssb.h>
75 -#include <bcm47xx_nvram.h>
76 +#include <linux/bcm47xx_nvram.h>
77 #include <bcm47xx_board.h>
79 void __init plat_time_init(void)
80 --- a/arch/mips/include/asm/mach-bcm47xx/bcm47xx_nvram.h
84 - * Copyright (C) 2005, Broadcom Corporation
85 - * Copyright (C) 2006, Felix Fietkau <nbd@openwrt.org>
87 - * This program is free software; you can redistribute it and/or modify it
88 - * under the terms of the GNU General Public License as published by the
89 - * Free Software Foundation; either version 2 of the License, or (at your
90 - * option) any later version.
93 -#ifndef __BCM47XX_NVRAM_H
94 -#define __BCM47XX_NVRAM_H
96 -#include <linux/types.h>
97 -#include <linux/kernel.h>
99 -struct nvram_header {
102 - u32 crc_ver_init; /* 0:7 crc, 8:15 ver, 16:31 sdram_init */
103 - u32 config_refresh; /* 0:15 sdram_config, 16:31 sdram_refresh */
104 - u32 config_ncdl; /* ncdl values for memc */
107 -#define NVRAM_HEADER 0x48534C46 /* 'FLSH' */
108 -#define NVRAM_VERSION 1
109 -#define NVRAM_HEADER_SIZE 20
110 -#define NVRAM_SPACE 0x8000
112 -#define FLASH_MIN 0x00020000 /* Minimum flash size */
114 -#define NVRAM_MAX_VALUE_LEN 255
115 -#define NVRAM_MAX_PARAM_LEN 64
117 -extern int bcm47xx_nvram_getenv(char *name, char *val, size_t val_len);
119 -static inline void bcm47xx_nvram_parse_macaddr(char *buf, u8 macaddr[6])
121 - if (strchr(buf, ':'))
122 - sscanf(buf, "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx", &macaddr[0],
123 - &macaddr[1], &macaddr[2], &macaddr[3], &macaddr[4],
125 - else if (strchr(buf, '-'))
126 - sscanf(buf, "%hhx-%hhx-%hhx-%hhx-%hhx-%hhx", &macaddr[0],
127 - &macaddr[1], &macaddr[2], &macaddr[3], &macaddr[4],
130 - printk(KERN_WARNING "Can not parse mac address: %s\n", buf);
133 -int bcm47xx_nvram_gpio_pin(const char *name);
135 -#endif /* __BCM47XX_NVRAM_H */
136 --- a/drivers/net/ethernet/broadcom/b44.c
137 +++ b/drivers/net/ethernet/broadcom/b44.c
139 #include <linux/ssb/ssb.h>
140 #include <linux/slab.h>
141 #include <linux/phy.h>
142 +#include <linux/bcm47xx_nvram.h>
144 #include <asm/uaccess.h>
146 @@ -399,8 +400,6 @@ static void b44_set_flow_ctrl(struct b44
147 __b44_set_flow_ctrl(bp, pause_enab);
150 -#ifdef CONFIG_BCM47XX
151 -#include <bcm47xx_nvram.h>
152 static void b44_wap54g10_workaround(struct b44 *bp)
155 @@ -429,11 +428,6 @@ static void b44_wap54g10_workaround(stru
157 pr_warning("PHY: cannot reset MII transceiver isolate bit\n");
160 -static inline void b44_wap54g10_workaround(struct b44 *bp)
165 static int b44_setup_phy(struct b44 *bp)
167 --- a/drivers/net/ethernet/broadcom/bgmac.c
168 +++ b/drivers/net/ethernet/broadcom/bgmac.c
170 #include <linux/interrupt.h>
171 #include <linux/dma-mapping.h>
172 #include <linux/platform_data/b53.h>
173 -#include <bcm47xx_nvram.h>
174 +#include <linux/bcm47xx_nvram.h>
176 static const struct bcma_device_id bgmac_bcma_tbl[] = {
177 BCMA_CORE(BCMA_MANUF_BCM, BCMA_CORE_4706_MAC_GBIT, BCMA_ANY_REV, BCMA_ANY_CLASS),
178 --- a/drivers/ssb/driver_chipcommon_pmu.c
179 +++ b/drivers/ssb/driver_chipcommon_pmu.c
181 #include <linux/ssb/ssb_driver_chipcommon.h>
182 #include <linux/delay.h>
183 #include <linux/export.h>
184 -#ifdef CONFIG_BCM47XX
185 -#include <bcm47xx_nvram.h>
187 +#include <linux/bcm47xx_nvram.h>
189 #include "ssb_private.h"
191 @@ -320,11 +318,9 @@ static void ssb_pmu_pll_init(struct ssb_
192 u32 crystalfreq = 0; /* in kHz. 0 = keep default freq. */
194 if (bus->bustype == SSB_BUSTYPE_SSB) {
195 -#ifdef CONFIG_BCM47XX
197 if (bcm47xx_nvram_getenv("xtalfreq", buf, sizeof(buf)) >= 0)
198 crystalfreq = simple_strtoul(buf, NULL, 0);
202 switch (bus->chip_id) {
204 +++ b/include/linux/bcm47xx_nvram.h
207 + * Copyright (C) 2005, Broadcom Corporation
208 + * Copyright (C) 2006, Felix Fietkau <nbd@openwrt.org>
209 + * Copyright (C) 2014 Hauke Mehrtens <hauke@hauke-m.de>
211 + * This program is free software; you can redistribute it and/or modify it
212 + * under the terms of the GNU General Public License as published by the
213 + * Free Software Foundation; either version 2 of the License, or (at your
214 + * option) any later version.
217 +#ifndef __BCM47XX_NVRAM_H
218 +#define __BCM47XX_NVRAM_H
220 +#include <linux/types.h>
221 +#include <linux/kernel.h>
223 +struct nvram_header {
226 + u32 crc_ver_init; /* 0:7 crc, 8:15 ver, 16:31 sdram_init */
227 + u32 config_refresh; /* 0:15 sdram_config, 16:31 sdram_refresh */
228 + u32 config_ncdl; /* ncdl values for memc */
231 +#define NVRAM_HEADER 0x48534C46 /* 'FLSH' */
232 +#define NVRAM_VERSION 1
233 +#define NVRAM_HEADER_SIZE 20
234 +#define NVRAM_SPACE 0x8000
236 +#define FLASH_MIN 0x00020000 /* Minimum flash size */
238 +#define NVRAM_MAX_VALUE_LEN 255
239 +#define NVRAM_MAX_PARAM_LEN 64
241 +#ifdef CONFIG_BCM47XX
242 +int bcm47xx_nvram_getenv(const char *name, char *val, size_t val_len);
244 +int bcm47xx_nvram_gpio_pin(const char *name);
246 +static inline int bcm47xx_nvram_getenv(const char *name, char *val, size_t val_len)
251 +static inline int bcm47xx_nvram_gpio_pin(const char *name)
257 +static inline void bcm47xx_nvram_parse_macaddr(char *buf, u8 macaddr[6])
259 + if (strchr(buf, ':'))
260 + sscanf(buf, "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx", &macaddr[0],
261 + &macaddr[1], &macaddr[2], &macaddr[3], &macaddr[4],
263 + else if (strchr(buf, '-'))
264 + sscanf(buf, "%hhx-%hhx-%hhx-%hhx-%hhx-%hhx", &macaddr[0],
265 + &macaddr[1], &macaddr[2], &macaddr[3], &macaddr[4],
268 + pr_warn("Can not parse mac address: %s\n", buf);
270 +#endif /* __BCM47XX_NVRAM_H */