Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

MIPS: BCM47XX: Clean up nvram header

1) Move private defines to the .c file
2) Move SPROM helper to the sprom.c
3) Drop unused code
4) Rename magic to the NVRAM_MAGIC
5) Add const to the char pointer we never modify

Signed-off-by: Rafał Miłecki <zajec5@gmail.com>
Acked-by: Hauke Mehrtens <hauke@hauke-m.de>
Cc: linux-mips@linux-mips.org
Patchwork: https://patchwork.linux-mips.org/patch/8289/
Signed-off-by: Ralf Baechle <ralf@linux-mips.org>

authored by

Rafał Miłecki and committed by
Ralf Baechle
341097f1 9d1d0864

+33 -39
+18 -5
arch/mips/bcm47xx/nvram.c
··· 18 18 #include <linux/mtd/mtd.h> 19 19 #include <bcm47xx_nvram.h> 20 20 21 + #define NVRAM_MAGIC 0x48534C46 /* 'FLSH' */ 22 + #define NVRAM_SPACE 0x8000 23 + 24 + #define FLASH_MIN 0x00020000 /* Minimum flash size */ 25 + 26 + struct nvram_header { 27 + u32 magic; 28 + u32 len; 29 + u32 crc_ver_init; /* 0:7 crc, 8:15 ver, 16:31 sdram_init */ 30 + u32 config_refresh; /* 0:15 sdram_config, 16:31 sdram_refresh */ 31 + u32 config_ncdl; /* ncdl values for memc */ 32 + }; 33 + 21 34 static char nvram_buf[NVRAM_SPACE]; 22 35 static const u32 nvram_sizes[] = {0x8000, 0xF000, 0x10000}; 23 36 ··· 41 28 42 29 for (i = 0; i < ARRAY_SIZE(nvram_sizes); i++) { 43 30 header = (struct nvram_header *)(end - nvram_sizes[i]); 44 - if (header->magic == NVRAM_HEADER) 31 + if (header->magic == NVRAM_MAGIC) 45 32 return nvram_sizes[i]; 46 33 } 47 34 ··· 76 63 77 64 /* Try embedded NVRAM at 4 KB and 1 KB as last resorts */ 78 65 header = (struct nvram_header *)(iobase + 4096); 79 - if (header->magic == NVRAM_HEADER) { 66 + if (header->magic == NVRAM_MAGIC) { 80 67 size = NVRAM_SPACE; 81 68 goto found; 82 69 } 83 70 84 71 header = (struct nvram_header *)(iobase + 1024); 85 - if (header->magic == NVRAM_HEADER) { 72 + if (header->magic == NVRAM_MAGIC) { 86 73 size = NVRAM_SPACE; 87 74 goto found; 88 75 } ··· 152 139 153 140 err = mtd_read(mtd, from, sizeof(header), &bytes_read, 154 141 (uint8_t *)&header); 155 - if (!err && header.magic == NVRAM_HEADER) { 142 + if (!err && header.magic == NVRAM_MAGIC) { 156 143 u8 *dst = (uint8_t *)nvram_buf; 157 144 size_t len = header.len; 158 145 ··· 175 162 return -ENXIO; 176 163 } 177 164 178 - int bcm47xx_nvram_getenv(char *name, char *val, size_t val_len) 165 + int bcm47xx_nvram_getenv(const char *name, char *val, size_t val_len) 179 166 { 180 167 char *var, *value, *end, *eq; 181 168 int err;
+14
arch/mips/bcm47xx/sprom.c
··· 136 136 *leddc_off_time = (val >> 16) & 0xff; 137 137 } 138 138 139 + static void bcm47xx_nvram_parse_macaddr(char *buf, u8 macaddr[6]) 140 + { 141 + if (strchr(buf, ':')) 142 + sscanf(buf, "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx", &macaddr[0], 143 + &macaddr[1], &macaddr[2], &macaddr[3], &macaddr[4], 144 + &macaddr[5]); 145 + else if (strchr(buf, '-')) 146 + sscanf(buf, "%hhx-%hhx-%hhx-%hhx-%hhx-%hhx", &macaddr[0], 147 + &macaddr[1], &macaddr[2], &macaddr[3], &macaddr[4], 148 + &macaddr[5]); 149 + else 150 + pr_warn("Can not parse mac address: %s\n", buf); 151 + } 152 + 139 153 static void nvram_read_macaddr(const char *prefix, const char *name, 140 154 u8 val[6], bool fallback) 141 155 {
+1 -34
arch/mips/include/asm/mach-bcm47xx/bcm47xx_nvram.h
··· 14 14 #include <linux/types.h> 15 15 #include <linux/kernel.h> 16 16 17 - struct nvram_header { 18 - u32 magic; 19 - u32 len; 20 - u32 crc_ver_init; /* 0:7 crc, 8:15 ver, 16:31 sdram_init */ 21 - u32 config_refresh; /* 0:15 sdram_config, 16:31 sdram_refresh */ 22 - u32 config_ncdl; /* ncdl values for memc */ 23 - }; 24 - 25 - #define NVRAM_HEADER 0x48534C46 /* 'FLSH' */ 26 - #define NVRAM_VERSION 1 27 - #define NVRAM_HEADER_SIZE 20 28 - #define NVRAM_SPACE 0x8000 29 - 30 - #define FLASH_MIN 0x00020000 /* Minimum flash size */ 31 - 32 - #define NVRAM_MAX_VALUE_LEN 255 33 - #define NVRAM_MAX_PARAM_LEN 64 34 - 35 17 int bcm47xx_nvram_init_from_mem(u32 base, u32 lim); 36 - extern int bcm47xx_nvram_getenv(char *name, char *val, size_t val_len); 37 - 38 - static inline void bcm47xx_nvram_parse_macaddr(char *buf, u8 macaddr[6]) 39 - { 40 - if (strchr(buf, ':')) 41 - sscanf(buf, "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx", &macaddr[0], 42 - &macaddr[1], &macaddr[2], &macaddr[3], &macaddr[4], 43 - &macaddr[5]); 44 - else if (strchr(buf, '-')) 45 - sscanf(buf, "%hhx-%hhx-%hhx-%hhx-%hhx-%hhx", &macaddr[0], 46 - &macaddr[1], &macaddr[2], &macaddr[3], &macaddr[4], 47 - &macaddr[5]); 48 - else 49 - printk(KERN_WARNING "Can not parse mac address: %s\n", buf); 50 - } 51 - 18 + int bcm47xx_nvram_getenv(const char *name, char *val, size_t val_len); 52 19 int bcm47xx_nvram_gpio_pin(const char *name); 53 20 54 21 #endif /* __BCM47XX_NVRAM_H */