brcm47xx: group MIPS BCM47XX backported patches by source kernel
[15.05/openwrt.git] / target / linux / brcm47xx / patches-3.18 / 030-07-MIPS-BCM47XX-Clean-up-nvram-header.patch
1 From 341097f17c76b3dd39539526a2af9e7fff43705e Mon Sep 17 00:00:00 2001
2 From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= <zajec5@gmail.com>
3 Date: Thu, 30 Oct 2014 12:50:03 +0100
4 Subject: [PATCH] MIPS: BCM47XX: Clean up nvram header
5 MIME-Version: 1.0
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
8
9 1) Move private defines to the .c file
10 2) Move SPROM helper to the sprom.c
11 3) Drop unused code
12 4) Rename magic to the NVRAM_MAGIC
13 5) Add const to the char pointer we never modify
14
15 Signed-off-by: Rafał Miłecki <zajec5@gmail.com>
16 Acked-by: Hauke Mehrtens <hauke@hauke-m.de>
17 Cc: linux-mips@linux-mips.org
18 Patchwork: https://patchwork.linux-mips.org/patch/8289/
19 Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
20 ---
21  arch/mips/bcm47xx/nvram.c                          | 23 ++++++++++----
22  arch/mips/bcm47xx/sprom.c                          | 14 +++++++++
23  arch/mips/include/asm/mach-bcm47xx/bcm47xx_nvram.h | 35 +---------------------
24  3 files changed, 33 insertions(+), 39 deletions(-)
25
26 diff --git a/arch/mips/bcm47xx/nvram.c b/arch/mips/bcm47xx/nvram.c
27 index 8b64991..c5c381c 100644
28 --- a/arch/mips/bcm47xx/nvram.c
29 +++ b/arch/mips/bcm47xx/nvram.c
30 @@ -18,6 +18,19 @@
31  #include <linux/mtd/mtd.h>
32  #include <bcm47xx_nvram.h>
33  
34 +#define NVRAM_MAGIC            0x48534C46      /* 'FLSH' */
35 +#define NVRAM_SPACE            0x8000
36 +
37 +#define FLASH_MIN              0x00020000      /* Minimum flash size */
38 +
39 +struct nvram_header {
40 +       u32 magic;
41 +       u32 len;
42 +       u32 crc_ver_init;       /* 0:7 crc, 8:15 ver, 16:31 sdram_init */
43 +       u32 config_refresh;     /* 0:15 sdram_config, 16:31 sdram_refresh */
44 +       u32 config_ncdl;        /* ncdl values for memc */
45 +};
46 +
47  static char nvram_buf[NVRAM_SPACE];
48  static const u32 nvram_sizes[] = {0x8000, 0xF000, 0x10000};
49  
50 @@ -28,7 +41,7 @@ static u32 find_nvram_size(void __iomem *end)
51  
52         for (i = 0; i < ARRAY_SIZE(nvram_sizes); i++) {
53                 header = (struct nvram_header *)(end - nvram_sizes[i]);
54 -               if (header->magic == NVRAM_HEADER)
55 +               if (header->magic == NVRAM_MAGIC)
56                         return nvram_sizes[i];
57         }
58  
59 @@ -63,13 +76,13 @@ static int nvram_find_and_copy(void __iomem *iobase, u32 lim)
60  
61         /* Try embedded NVRAM at 4 KB and 1 KB as last resorts */
62         header = (struct nvram_header *)(iobase + 4096);
63 -       if (header->magic == NVRAM_HEADER) {
64 +       if (header->magic == NVRAM_MAGIC) {
65                 size = NVRAM_SPACE;
66                 goto found;
67         }
68  
69         header = (struct nvram_header *)(iobase + 1024);
70 -       if (header->magic == NVRAM_HEADER) {
71 +       if (header->magic == NVRAM_MAGIC) {
72                 size = NVRAM_SPACE;
73                 goto found;
74         }
75 @@ -139,7 +152,7 @@ static int nvram_init(void)
76  
77                 err = mtd_read(mtd, from, sizeof(header), &bytes_read,
78                                (uint8_t *)&header);
79 -               if (!err && header.magic == NVRAM_HEADER) {
80 +               if (!err && header.magic == NVRAM_MAGIC) {
81                         u8 *dst = (uint8_t *)nvram_buf;
82                         size_t len = header.len;
83  
84 @@ -162,7 +175,7 @@ static int nvram_init(void)
85         return -ENXIO;
86  }
87  
88 -int bcm47xx_nvram_getenv(char *name, char *val, size_t val_len)
89 +int bcm47xx_nvram_getenv(const char *name, char *val, size_t val_len)
90  {
91         char *var, *value, *end, *eq;
92         int err;
93 diff --git a/arch/mips/bcm47xx/sprom.c b/arch/mips/bcm47xx/sprom.c
94 index e772e77..2eff7fe 100644
95 --- a/arch/mips/bcm47xx/sprom.c
96 +++ b/arch/mips/bcm47xx/sprom.c
97 @@ -136,6 +136,20 @@ static void nvram_read_leddc(const char *prefix, const char *name,
98         *leddc_off_time = (val >> 16) & 0xff;
99  }
100  
101 +static void bcm47xx_nvram_parse_macaddr(char *buf, u8 macaddr[6])
102 +{
103 +       if (strchr(buf, ':'))
104 +               sscanf(buf, "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx", &macaddr[0],
105 +                       &macaddr[1], &macaddr[2], &macaddr[3], &macaddr[4],
106 +                       &macaddr[5]);
107 +       else if (strchr(buf, '-'))
108 +               sscanf(buf, "%hhx-%hhx-%hhx-%hhx-%hhx-%hhx", &macaddr[0],
109 +                       &macaddr[1], &macaddr[2], &macaddr[3], &macaddr[4],
110 +                       &macaddr[5]);
111 +       else
112 +               pr_warn("Can not parse mac address: %s\n", buf);
113 +}
114 +
115  static void nvram_read_macaddr(const char *prefix, const char *name,
116                                u8 val[6], bool fallback)
117  {
118 diff --git a/arch/mips/include/asm/mach-bcm47xx/bcm47xx_nvram.h b/arch/mips/include/asm/mach-bcm47xx/bcm47xx_nvram.h
119 index 676be22..ee59ffe 100644
120 --- a/arch/mips/include/asm/mach-bcm47xx/bcm47xx_nvram.h
121 +++ b/arch/mips/include/asm/mach-bcm47xx/bcm47xx_nvram.h
122 @@ -14,41 +14,8 @@
123  #include <linux/types.h>
124  #include <linux/kernel.h>
125  
126 -struct nvram_header {
127 -       u32 magic;
128 -       u32 len;
129 -       u32 crc_ver_init;       /* 0:7 crc, 8:15 ver, 16:31 sdram_init */
130 -       u32 config_refresh;     /* 0:15 sdram_config, 16:31 sdram_refresh */
131 -       u32 config_ncdl;        /* ncdl values for memc */
132 -};
133 -
134 -#define NVRAM_HEADER           0x48534C46      /* 'FLSH' */
135 -#define NVRAM_VERSION          1
136 -#define NVRAM_HEADER_SIZE      20
137 -#define NVRAM_SPACE            0x8000
138 -
139 -#define FLASH_MIN              0x00020000      /* Minimum flash size */
140 -
141 -#define NVRAM_MAX_VALUE_LEN 255
142 -#define NVRAM_MAX_PARAM_LEN 64
143 -
144  int bcm47xx_nvram_init_from_mem(u32 base, u32 lim);
145 -extern int bcm47xx_nvram_getenv(char *name, char *val, size_t val_len);
146 -
147 -static inline void bcm47xx_nvram_parse_macaddr(char *buf, u8 macaddr[6])
148 -{
149 -       if (strchr(buf, ':'))
150 -               sscanf(buf, "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx", &macaddr[0],
151 -                       &macaddr[1], &macaddr[2], &macaddr[3], &macaddr[4],
152 -                       &macaddr[5]);
153 -       else if (strchr(buf, '-'))
154 -               sscanf(buf, "%hhx-%hhx-%hhx-%hhx-%hhx-%hhx", &macaddr[0],
155 -                       &macaddr[1], &macaddr[2], &macaddr[3], &macaddr[4],
156 -                       &macaddr[5]);
157 -       else
158 -               printk(KERN_WARNING "Can not parse mac address: %s\n", buf);
159 -}
160 -
161 +int bcm47xx_nvram_getenv(const char *name, char *val, size_t val_len);
162  int bcm47xx_nvram_gpio_pin(const char *name);
163  
164  #endif /* __BCM47XX_NVRAM_H */
165 -- 
166 1.8.4.5
167