brcm63xx: add kernel 3.18 support
[openwrt/openwrt.git] / target / linux / bcm53xx / patches-3.18 / 110-bcm47xx-move-the-nvram-header-file-into-common-space.patch
1 From 7063a1583166abe1a9cefed38c2f53a0e14a0005 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 01/17] MIPS: BCM47XX: move the nvram header file into common
5 space
6
7 Moving mach-bcm47xx/bcm47xx_nvram.h to include/linux/bcm47xx_nvram.h
8 makes it possible to reuse this header on the ARM based bcm47xx/bcm53xx
9 SoCs (e.g. BCM5301X devices). Broadcom uses ARM CPUs in their new SoC
10 form the bcm47xx and bcm53xx line, but many other things like nvram
11 stayed the same.
12
13 This is a preparation for adding a new nvram driver, which can be used
14 by the ARM SoC and the MIPS SoC code. The device drivers accessing
15 nvram do not have to care about ARM or MIPS SoC version.
16
17 Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
18 ---
19 arch/mips/bcm47xx/board.c | 2 +-
20 arch/mips/bcm47xx/nvram.c | 2 +-
21 arch/mips/bcm47xx/setup.c | 2 +-
22 arch/mips/bcm47xx/sprom.c | 2 +-
23 arch/mips/bcm47xx/time.c | 2 +-
24 arch/mips/include/asm/mach-bcm47xx/bcm47xx_nvram.h | 53 -----------------
25 drivers/net/ethernet/broadcom/b44.c | 8 +--
26 drivers/net/ethernet/broadcom/bgmac.c | 2 +-
27 drivers/ssb/driver_chipcommon_pmu.c | 6 +-
28 include/linux/bcm47xx_nvram.h | 66 ++++++++++++++++++++++
29 10 files changed, 74 insertions(+), 71 deletions(-)
30 delete mode 100644 arch/mips/include/asm/mach-bcm47xx/bcm47xx_nvram.h
31 create mode 100644 include/linux/bcm47xx_nvram.h
32
33 --- a/arch/mips/bcm47xx/board.c
34 +++ b/arch/mips/bcm47xx/board.c
35 @@ -2,7 +2,7 @@
36 #include <linux/export.h>
37 #include <linux/string.h>
38 #include <bcm47xx_board.h>
39 -#include <bcm47xx_nvram.h>
40 +#include <linux/bcm47xx_nvram.h>
41
42 struct bcm47xx_board_type {
43 const enum bcm47xx_board board;
44 --- a/arch/mips/bcm47xx/nvram.c
45 +++ b/arch/mips/bcm47xx/nvram.c
46 @@ -17,7 +17,7 @@
47 #include <linux/kernel.h>
48 #include <linux/string.h>
49 #include <asm/addrspace.h>
50 -#include <bcm47xx_nvram.h>
51 +#include <linux/bcm47xx_nvram.h>
52 #include <asm/mach-bcm47xx/bcm47xx.h>
53
54 static char nvram_buf[NVRAM_SPACE];
55 --- a/arch/mips/bcm47xx/setup.c
56 +++ b/arch/mips/bcm47xx/setup.c
57 @@ -42,7 +42,7 @@
58 #include <asm/reboot.h>
59 #include <asm/time.h>
60 #include <bcm47xx.h>
61 -#include <bcm47xx_nvram.h>
62 +#include <linux/bcm47xx_nvram.h>
63 #include <bcm47xx_board.h>
64
65 union bcm47xx_bus bcm47xx_bus;
66 --- a/arch/mips/bcm47xx/sprom.c
67 +++ b/arch/mips/bcm47xx/sprom.c
68 @@ -27,7 +27,7 @@
69 */
70
71 #include <bcm47xx.h>
72 -#include <bcm47xx_nvram.h>
73 +#include <linux/bcm47xx_nvram.h>
74 #include <linux/if_ether.h>
75 #include <linux/etherdevice.h>
76
77 --- a/arch/mips/bcm47xx/time.c
78 +++ b/arch/mips/bcm47xx/time.c
79 @@ -27,7 +27,7 @@
80 #include <linux/ssb/ssb.h>
81 #include <asm/time.h>
82 #include <bcm47xx.h>
83 -#include <bcm47xx_nvram.h>
84 +#include <linux/bcm47xx_nvram.h>
85 #include <bcm47xx_board.h>
86
87 void __init plat_time_init(void)
88 --- a/arch/mips/include/asm/mach-bcm47xx/bcm47xx_nvram.h
89 +++ /dev/null
90 @@ -1,53 +0,0 @@
91 -/*
92 - * Copyright (C) 2005, Broadcom Corporation
93 - * Copyright (C) 2006, Felix Fietkau <nbd@openwrt.org>
94 - *
95 - * This program is free software; you can redistribute it and/or modify it
96 - * under the terms of the GNU General Public License as published by the
97 - * Free Software Foundation; either version 2 of the License, or (at your
98 - * option) any later version.
99 - */
100 -
101 -#ifndef __BCM47XX_NVRAM_H
102 -#define __BCM47XX_NVRAM_H
103 -
104 -#include <linux/types.h>
105 -#include <linux/kernel.h>
106 -
107 -struct nvram_header {
108 - u32 magic;
109 - u32 len;
110 - u32 crc_ver_init; /* 0:7 crc, 8:15 ver, 16:31 sdram_init */
111 - u32 config_refresh; /* 0:15 sdram_config, 16:31 sdram_refresh */
112 - u32 config_ncdl; /* ncdl values for memc */
113 -};
114 -
115 -#define NVRAM_HEADER 0x48534C46 /* 'FLSH' */
116 -#define NVRAM_VERSION 1
117 -#define NVRAM_HEADER_SIZE 20
118 -#define NVRAM_SPACE 0x8000
119 -
120 -#define FLASH_MIN 0x00020000 /* Minimum flash size */
121 -
122 -#define NVRAM_MAX_VALUE_LEN 255
123 -#define NVRAM_MAX_PARAM_LEN 64
124 -
125 -extern int bcm47xx_nvram_getenv(char *name, char *val, size_t val_len);
126 -
127 -static inline void bcm47xx_nvram_parse_macaddr(char *buf, u8 macaddr[6])
128 -{
129 - if (strchr(buf, ':'))
130 - sscanf(buf, "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx", &macaddr[0],
131 - &macaddr[1], &macaddr[2], &macaddr[3], &macaddr[4],
132 - &macaddr[5]);
133 - else if (strchr(buf, '-'))
134 - sscanf(buf, "%hhx-%hhx-%hhx-%hhx-%hhx-%hhx", &macaddr[0],
135 - &macaddr[1], &macaddr[2], &macaddr[3], &macaddr[4],
136 - &macaddr[5]);
137 - else
138 - printk(KERN_WARNING "Can not parse mac address: %s\n", buf);
139 -}
140 -
141 -int bcm47xx_nvram_gpio_pin(const char *name);
142 -
143 -#endif /* __BCM47XX_NVRAM_H */
144 --- a/drivers/net/ethernet/broadcom/b44.c
145 +++ b/drivers/net/ethernet/broadcom/b44.c
146 @@ -31,6 +31,7 @@
147 #include <linux/ssb/ssb.h>
148 #include <linux/slab.h>
149 #include <linux/phy.h>
150 +#include <linux/bcm47xx_nvram.h>
151
152 #include <asm/uaccess.h>
153 #include <asm/io.h>
154 @@ -399,8 +400,6 @@ static void b44_set_flow_ctrl(struct b44
155 __b44_set_flow_ctrl(bp, pause_enab);
156 }
157
158 -#ifdef CONFIG_BCM47XX
159 -#include <bcm47xx_nvram.h>
160 static void b44_wap54g10_workaround(struct b44 *bp)
161 {
162 char buf[20];
163 @@ -429,11 +428,6 @@ static void b44_wap54g10_workaround(stru
164 error:
165 pr_warn("PHY: cannot reset MII transceiver isolate bit\n");
166 }
167 -#else
168 -static inline void b44_wap54g10_workaround(struct b44 *bp)
169 -{
170 -}
171 -#endif
172
173 static int b44_setup_phy(struct b44 *bp)
174 {
175 --- a/drivers/net/ethernet/broadcom/bgmac.c
176 +++ b/drivers/net/ethernet/broadcom/bgmac.c
177 @@ -17,7 +17,7 @@
178 #include <linux/interrupt.h>
179 #include <linux/dma-mapping.h>
180 #include <linux/platform_data/b53.h>
181 -#include <bcm47xx_nvram.h>
182 +#include <linux/bcm47xx_nvram.h>
183
184 static const struct bcma_device_id bgmac_bcma_tbl[] = {
185 BCMA_CORE(BCMA_MANUF_BCM, BCMA_CORE_4706_MAC_GBIT, BCMA_ANY_REV, BCMA_ANY_CLASS),
186 --- a/drivers/ssb/driver_chipcommon_pmu.c
187 +++ b/drivers/ssb/driver_chipcommon_pmu.c
188 @@ -13,9 +13,7 @@
189 #include <linux/ssb/ssb_driver_chipcommon.h>
190 #include <linux/delay.h>
191 #include <linux/export.h>
192 -#ifdef CONFIG_BCM47XX
193 -#include <bcm47xx_nvram.h>
194 -#endif
195 +#include <linux/bcm47xx_nvram.h>
196
197 #include "ssb_private.h"
198
199 @@ -320,11 +318,9 @@ static void ssb_pmu_pll_init(struct ssb_
200 u32 crystalfreq = 0; /* in kHz. 0 = keep default freq. */
201
202 if (bus->bustype == SSB_BUSTYPE_SSB) {
203 -#ifdef CONFIG_BCM47XX
204 char buf[20];
205 if (bcm47xx_nvram_getenv("xtalfreq", buf, sizeof(buf)) >= 0)
206 crystalfreq = simple_strtoul(buf, NULL, 0);
207 -#endif
208 }
209
210 switch (bus->chip_id) {
211 --- /dev/null
212 +++ b/include/linux/bcm47xx_nvram.h
213 @@ -0,0 +1,66 @@
214 +/*
215 + * Copyright (C) 2005, Broadcom Corporation
216 + * Copyright (C) 2006, Felix Fietkau <nbd@openwrt.org>
217 + * Copyright (C) 2014 Hauke Mehrtens <hauke@hauke-m.de>
218 + *
219 + * This program is free software; you can redistribute it and/or modify it
220 + * under the terms of the GNU General Public License as published by the
221 + * Free Software Foundation; either version 2 of the License, or (at your
222 + * option) any later version.
223 + */
224 +
225 +#ifndef __BCM47XX_NVRAM_H
226 +#define __BCM47XX_NVRAM_H
227 +
228 +#include <linux/types.h>
229 +#include <linux/kernel.h>
230 +
231 +struct nvram_header {
232 + u32 magic;
233 + u32 len;
234 + u32 crc_ver_init; /* 0:7 crc, 8:15 ver, 16:31 sdram_init */
235 + u32 config_refresh; /* 0:15 sdram_config, 16:31 sdram_refresh */
236 + u32 config_ncdl; /* ncdl values for memc */
237 +};
238 +
239 +#define NVRAM_HEADER 0x48534C46 /* 'FLSH' */
240 +#define NVRAM_VERSION 1
241 +#define NVRAM_HEADER_SIZE 20
242 +#define NVRAM_SPACE 0x8000
243 +
244 +#define FLASH_MIN 0x00020000 /* Minimum flash size */
245 +
246 +#define NVRAM_MAX_VALUE_LEN 255
247 +#define NVRAM_MAX_PARAM_LEN 64
248 +
249 +#ifdef CONFIG_BCM47XX
250 +int bcm47xx_nvram_getenv(const char *name, char *val, size_t val_len);
251 +
252 +int bcm47xx_nvram_gpio_pin(const char *name);
253 +#else
254 +static inline int bcm47xx_nvram_getenv(const char *name, char *val,
255 + size_t val_len)
256 +{
257 + return -ENXIO;
258 +}
259 +
260 +static inline int bcm47xx_nvram_gpio_pin(const char *name)
261 +{
262 + return -ENXIO;
263 +}
264 +#endif
265 +
266 +static inline void bcm47xx_nvram_parse_macaddr(char *buf, u8 macaddr[6])
267 +{
268 + if (strchr(buf, ':'))
269 + sscanf(buf, "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx", &macaddr[0],
270 + &macaddr[1], &macaddr[2], &macaddr[3], &macaddr[4],
271 + &macaddr[5]);
272 + else if (strchr(buf, '-'))
273 + sscanf(buf, "%hhx-%hhx-%hhx-%hhx-%hhx-%hhx", &macaddr[0],
274 + &macaddr[1], &macaddr[2], &macaddr[3], &macaddr[4],
275 + &macaddr[5]);
276 + else
277 + pr_warn("Can not parse mac address: %s\n", buf);
278 +}
279 +#endif /* __BCM47XX_NVRAM_H */