add chaos_calmer branch
[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 --- a/arch/mips/bcm47xx/nvram.c
27 +++ b/arch/mips/bcm47xx/nvram.c
28 @@ -18,6 +18,19 @@
29  #include <linux/mtd/mtd.h>
30  #include <bcm47xx_nvram.h>
31  
32 +#define NVRAM_MAGIC            0x48534C46      /* 'FLSH' */
33 +#define NVRAM_SPACE            0x8000
34 +
35 +#define FLASH_MIN              0x00020000      /* Minimum flash size */
36 +
37 +struct nvram_header {
38 +       u32 magic;
39 +       u32 len;
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 */
43 +};
44 +
45  static char nvram_buf[NVRAM_SPACE];
46  static const u32 nvram_sizes[] = {0x8000, 0xF000, 0x10000};
47  
48 @@ -28,7 +41,7 @@ static u32 find_nvram_size(void __iomem
49  
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];
55         }
56  
57 @@ -63,13 +76,13 @@ static int nvram_find_and_copy(void __io
58  
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) {
63                 size = NVRAM_SPACE;
64                 goto found;
65         }
66  
67         header = (struct nvram_header *)(iobase + 1024);
68 -       if (header->magic == NVRAM_HEADER) {
69 +       if (header->magic == NVRAM_MAGIC) {
70                 size = NVRAM_SPACE;
71                 goto found;
72         }
73 @@ -139,7 +152,7 @@ static int nvram_init(void)
74  
75                 err = mtd_read(mtd, from, sizeof(header), &bytes_read,
76                                (uint8_t *)&header);
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;
81  
82 @@ -162,7 +175,7 @@ static int nvram_init(void)
83         return -ENXIO;
84  }
85  
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)
88  {
89         char *var, *value, *end, *eq;
90         int err;
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;
95  }
96  
97 +static void bcm47xx_nvram_parse_macaddr(char *buf, u8 macaddr[6])
98 +{
99 +       if (strchr(buf, ':'))
100 +               sscanf(buf, "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx", &macaddr[0],
101 +                       &macaddr[1], &macaddr[2], &macaddr[3], &macaddr[4],
102 +                       &macaddr[5]);
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],
106 +                       &macaddr[5]);
107 +       else
108 +               pr_warn("Can not parse mac address: %s\n", buf);
109 +}
110 +
111  static void nvram_read_macaddr(const char *prefix, const char *name,
112                                u8 val[6], bool fallback)
113  {
114 --- a/arch/mips/include/asm/mach-bcm47xx/bcm47xx_nvram.h
115 +++ b/arch/mips/include/asm/mach-bcm47xx/bcm47xx_nvram.h
116 @@ -14,41 +14,8 @@
117  #include <linux/types.h>
118  #include <linux/kernel.h>
119  
120 -struct nvram_header {
121 -       u32 magic;
122 -       u32 len;
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 */
126 -};
127 -
128 -#define NVRAM_HEADER           0x48534C46      /* 'FLSH' */
129 -#define NVRAM_VERSION          1
130 -#define NVRAM_HEADER_SIZE      20
131 -#define NVRAM_SPACE            0x8000
132 -
133 -#define FLASH_MIN              0x00020000      /* Minimum flash size */
134 -
135 -#define NVRAM_MAX_VALUE_LEN 255
136 -#define NVRAM_MAX_PARAM_LEN 64
137 -
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);
140 -
141 -static inline void bcm47xx_nvram_parse_macaddr(char *buf, u8 macaddr[6])
142 -{
143 -       if (strchr(buf, ':'))
144 -               sscanf(buf, "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx", &macaddr[0],
145 -                       &macaddr[1], &macaddr[2], &macaddr[3], &macaddr[4],
146 -                       &macaddr[5]);
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],
150 -                       &macaddr[5]);
151 -       else
152 -               printk(KERN_WARNING "Can not parse mac address: %s\n", buf);
153 -}
154 -
155 +int bcm47xx_nvram_getenv(const char *name, char *val, size_t val_len);
156  int bcm47xx_nvram_gpio_pin(const char *name);
157  
158  #endif /* __BCM47XX_NVRAM_H */