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
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
9 1) Move private defines to the .c file
10 2) Move SPROM helper to the sprom.c
12 4) Rename magic to the NVRAM_MAGIC
13 5) Add const to the char pointer we never modify
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>
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(-)
26 --- a/arch/mips/bcm47xx/nvram.c
27 +++ b/arch/mips/bcm47xx/nvram.c
29 #include <linux/mtd/mtd.h>
30 #include <bcm47xx_nvram.h>
32 +#define NVRAM_MAGIC 0x48534C46 /* 'FLSH' */
33 +#define NVRAM_SPACE 0x8000
35 +#define FLASH_MIN 0x00020000 /* Minimum flash size */
37 +struct nvram_header {
40 + u32 crc_ver_init; /* 0:7 crc, 8:15 ver, 16:31 sdram_init */
41 + u32 config_refresh; /* 0:15 sdram_config, 16:31 sdram_refresh */
42 + u32 config_ncdl; /* ncdl values for memc */
45 static char nvram_buf[NVRAM_SPACE];
46 static const u32 nvram_sizes[] = {0x8000, 0xF000, 0x10000};
48 @@ -28,7 +41,7 @@ static u32 find_nvram_size(void __iomem
50 for (i = 0; i < ARRAY_SIZE(nvram_sizes); i++) {
51 header = (struct nvram_header *)(end - nvram_sizes[i]);
52 - if (header->magic == NVRAM_HEADER)
53 + if (header->magic == NVRAM_MAGIC)
54 return nvram_sizes[i];
57 @@ -63,13 +76,13 @@ static int nvram_find_and_copy(void __io
59 /* Try embedded NVRAM at 4 KB and 1 KB as last resorts */
60 header = (struct nvram_header *)(iobase + 4096);
61 - if (header->magic == NVRAM_HEADER) {
62 + if (header->magic == NVRAM_MAGIC) {
67 header = (struct nvram_header *)(iobase + 1024);
68 - if (header->magic == NVRAM_HEADER) {
69 + if (header->magic == NVRAM_MAGIC) {
73 @@ -139,7 +152,7 @@ static int nvram_init(void)
75 err = mtd_read(mtd, from, sizeof(header), &bytes_read,
77 - if (!err && header.magic == NVRAM_HEADER) {
78 + if (!err && header.magic == NVRAM_MAGIC) {
79 u8 *dst = (uint8_t *)nvram_buf;
80 size_t len = header.len;
82 @@ -162,7 +175,7 @@ static int nvram_init(void)
86 -int bcm47xx_nvram_getenv(char *name, char *val, size_t val_len)
87 +int bcm47xx_nvram_getenv(const char *name, char *val, size_t val_len)
89 char *var, *value, *end, *eq;
91 --- a/arch/mips/bcm47xx/sprom.c
92 +++ b/arch/mips/bcm47xx/sprom.c
93 @@ -136,6 +136,20 @@ static void nvram_read_leddc(const char
94 *leddc_off_time = (val >> 16) & 0xff;
97 +static void bcm47xx_nvram_parse_macaddr(char *buf, u8 macaddr[6])
99 + if (strchr(buf, ':'))
100 + sscanf(buf, "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx", &macaddr[0],
101 + &macaddr[1], &macaddr[2], &macaddr[3], &macaddr[4],
103 + else if (strchr(buf, '-'))
104 + sscanf(buf, "%hhx-%hhx-%hhx-%hhx-%hhx-%hhx", &macaddr[0],
105 + &macaddr[1], &macaddr[2], &macaddr[3], &macaddr[4],
108 + pr_warn("Can not parse mac address: %s\n", buf);
111 static void nvram_read_macaddr(const char *prefix, const char *name,
112 u8 val[6], bool fallback)
114 --- a/arch/mips/include/asm/mach-bcm47xx/bcm47xx_nvram.h
115 +++ b/arch/mips/include/asm/mach-bcm47xx/bcm47xx_nvram.h
117 #include <linux/types.h>
118 #include <linux/kernel.h>
120 -struct nvram_header {
123 - u32 crc_ver_init; /* 0:7 crc, 8:15 ver, 16:31 sdram_init */
124 - u32 config_refresh; /* 0:15 sdram_config, 16:31 sdram_refresh */
125 - u32 config_ncdl; /* ncdl values for memc */
128 -#define NVRAM_HEADER 0x48534C46 /* 'FLSH' */
129 -#define NVRAM_VERSION 1
130 -#define NVRAM_HEADER_SIZE 20
131 -#define NVRAM_SPACE 0x8000
133 -#define FLASH_MIN 0x00020000 /* Minimum flash size */
135 -#define NVRAM_MAX_VALUE_LEN 255
136 -#define NVRAM_MAX_PARAM_LEN 64
138 int bcm47xx_nvram_init_from_mem(u32 base, u32 lim);
139 -extern int bcm47xx_nvram_getenv(char *name, char *val, size_t val_len);
141 -static inline void bcm47xx_nvram_parse_macaddr(char *buf, u8 macaddr[6])
143 - if (strchr(buf, ':'))
144 - sscanf(buf, "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx", &macaddr[0],
145 - &macaddr[1], &macaddr[2], &macaddr[3], &macaddr[4],
147 - else if (strchr(buf, '-'))
148 - sscanf(buf, "%hhx-%hhx-%hhx-%hhx-%hhx-%hhx", &macaddr[0],
149 - &macaddr[1], &macaddr[2], &macaddr[3], &macaddr[4],
152 - printk(KERN_WARNING "Can not parse mac address: %s\n", buf);
155 +int bcm47xx_nvram_getenv(const char *name, char *val, size_t val_len);
156 int bcm47xx_nvram_gpio_pin(const char *name);
158 #endif /* __BCM47XX_NVRAM_H */