bcm53xx: add support for the PCIe controller
[openwrt/openwrt.git] / target / linux / bcm53xx / patches-3.14 / 110-bcm47xx-move-the-nvram-header-file-into-common-space.patch
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
5
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
9 for.
10 ---
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
24
25 --- a/arch/mips/bcm47xx/board.c
26 +++ b/arch/mips/bcm47xx/board.c
27 @@ -2,7 +2,7 @@
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>
33
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
38 @@ -17,7 +17,7 @@
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>
45
46 static char nvram_buf[NVRAM_SPACE];
47 --- a/arch/mips/bcm47xx/setup.c
48 +++ b/arch/mips/bcm47xx/setup.c
49 @@ -42,7 +42,7 @@
50 #include <asm/reboot.h>
51 #include <asm/time.h>
52 #include <bcm47xx.h>
53 -#include <bcm47xx_nvram.h>
54 +#include <linux/bcm47xx_nvram.h>
55 #include <bcm47xx_board.h>
56
57 union bcm47xx_bus bcm47xx_bus;
58 --- a/arch/mips/bcm47xx/sprom.c
59 +++ b/arch/mips/bcm47xx/sprom.c
60 @@ -27,7 +27,7 @@
61 */
62
63 #include <bcm47xx.h>
64 -#include <bcm47xx_nvram.h>
65 +#include <linux/bcm47xx_nvram.h>
66
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
71 @@ -27,7 +27,7 @@
72 #include <linux/ssb/ssb.h>
73 #include <asm/time.h>
74 #include <bcm47xx.h>
75 -#include <bcm47xx_nvram.h>
76 +#include <linux/bcm47xx_nvram.h>
77 #include <bcm47xx_board.h>
78
79 void __init plat_time_init(void)
80 --- a/arch/mips/include/asm/mach-bcm47xx/bcm47xx_nvram.h
81 +++ /dev/null
82 @@ -1,53 +0,0 @@
83 -/*
84 - * Copyright (C) 2005, Broadcom Corporation
85 - * Copyright (C) 2006, Felix Fietkau <nbd@openwrt.org>
86 - *
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.
91 - */
92 -
93 -#ifndef __BCM47XX_NVRAM_H
94 -#define __BCM47XX_NVRAM_H
95 -
96 -#include <linux/types.h>
97 -#include <linux/kernel.h>
98 -
99 -struct nvram_header {
100 - u32 magic;
101 - u32 len;
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 */
105 -};
106 -
107 -#define NVRAM_HEADER 0x48534C46 /* 'FLSH' */
108 -#define NVRAM_VERSION 1
109 -#define NVRAM_HEADER_SIZE 20
110 -#define NVRAM_SPACE 0x8000
111 -
112 -#define FLASH_MIN 0x00020000 /* Minimum flash size */
113 -
114 -#define NVRAM_MAX_VALUE_LEN 255
115 -#define NVRAM_MAX_PARAM_LEN 64
116 -
117 -extern int bcm47xx_nvram_getenv(char *name, char *val, size_t val_len);
118 -
119 -static inline void bcm47xx_nvram_parse_macaddr(char *buf, u8 macaddr[6])
120 -{
121 - if (strchr(buf, ':'))
122 - sscanf(buf, "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx", &macaddr[0],
123 - &macaddr[1], &macaddr[2], &macaddr[3], &macaddr[4],
124 - &macaddr[5]);
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],
128 - &macaddr[5]);
129 - else
130 - printk(KERN_WARNING "Can not parse mac address: %s\n", buf);
131 -}
132 -
133 -int bcm47xx_nvram_gpio_pin(const char *name);
134 -
135 -#endif /* __BCM47XX_NVRAM_H */
136 --- a/drivers/net/ethernet/broadcom/b44.c
137 +++ b/drivers/net/ethernet/broadcom/b44.c
138 @@ -31,6 +31,7 @@
139 #include <linux/ssb/ssb.h>
140 #include <linux/slab.h>
141 #include <linux/phy.h>
142 +#include <linux/bcm47xx_nvram.h>
143
144 #include <asm/uaccess.h>
145 #include <asm/io.h>
146 @@ -399,8 +400,6 @@ static void b44_set_flow_ctrl(struct b44
147 __b44_set_flow_ctrl(bp, pause_enab);
148 }
149
150 -#ifdef CONFIG_BCM47XX
151 -#include <bcm47xx_nvram.h>
152 static void b44_wap54g10_workaround(struct b44 *bp)
153 {
154 char buf[20];
155 @@ -429,11 +428,6 @@ static void b44_wap54g10_workaround(stru
156 error:
157 pr_warning("PHY: cannot reset MII transceiver isolate bit\n");
158 }
159 -#else
160 -static inline void b44_wap54g10_workaround(struct b44 *bp)
161 -{
162 -}
163 -#endif
164
165 static int b44_setup_phy(struct b44 *bp)
166 {
167 --- a/drivers/net/ethernet/broadcom/bgmac.c
168 +++ b/drivers/net/ethernet/broadcom/bgmac.c
169 @@ -17,7 +17,7 @@
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>
175
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
180 @@ -13,9 +13,7 @@
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>
186 -#endif
187 +#include <linux/bcm47xx_nvram.h>
188
189 #include "ssb_private.h"
190
191 @@ -320,11 +318,9 @@ static void ssb_pmu_pll_init(struct ssb_
192 u32 crystalfreq = 0; /* in kHz. 0 = keep default freq. */
193
194 if (bus->bustype == SSB_BUSTYPE_SSB) {
195 -#ifdef CONFIG_BCM47XX
196 char buf[20];
197 if (bcm47xx_nvram_getenv("xtalfreq", buf, sizeof(buf)) >= 0)
198 crystalfreq = simple_strtoul(buf, NULL, 0);
199 -#endif
200 }
201
202 switch (bus->chip_id) {
203 --- /dev/null
204 +++ b/include/linux/bcm47xx_nvram.h
205 @@ -0,0 +1,65 @@
206 +/*
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>
210 + *
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.
215 + */
216 +
217 +#ifndef __BCM47XX_NVRAM_H
218 +#define __BCM47XX_NVRAM_H
219 +
220 +#include <linux/types.h>
221 +#include <linux/kernel.h>
222 +
223 +struct nvram_header {
224 + u32 magic;
225 + u32 len;
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 */
229 +};
230 +
231 +#define NVRAM_HEADER 0x48534C46 /* 'FLSH' */
232 +#define NVRAM_VERSION 1
233 +#define NVRAM_HEADER_SIZE 20
234 +#define NVRAM_SPACE 0x8000
235 +
236 +#define FLASH_MIN 0x00020000 /* Minimum flash size */
237 +
238 +#define NVRAM_MAX_VALUE_LEN 255
239 +#define NVRAM_MAX_PARAM_LEN 64
240 +
241 +#ifdef CONFIG_BCM47XX
242 +int bcm47xx_nvram_getenv(const char *name, char *val, size_t val_len);
243 +
244 +int bcm47xx_nvram_gpio_pin(const char *name);
245 +#else
246 +static inline int bcm47xx_nvram_getenv(const char *name, char *val, size_t val_len)
247 +{
248 + return -ENXIO;
249 +}
250 +
251 +static inline int bcm47xx_nvram_gpio_pin(const char *name)
252 +{
253 + return -ENXIO;
254 +}
255 +#endif
256 +
257 +static inline void bcm47xx_nvram_parse_macaddr(char *buf, u8 macaddr[6])
258 +{
259 + if (strchr(buf, ':'))
260 + sscanf(buf, "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx", &macaddr[0],
261 + &macaddr[1], &macaddr[2], &macaddr[3], &macaddr[4],
262 + &macaddr[5]);
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],
266 + &macaddr[5]);
267 + else
268 + pr_warn("Can not parse mac address: %s\n", buf);
269 +}
270 +#endif /* __BCM47XX_NVRAM_H */