aboutsummaryrefslogtreecommitdiffstats
path: root/arch/mips/bcm47xx
diff options
context:
space:
mode:
authorRalf Baechle <ralf@linux-mips.org>2013-02-21 06:51:33 -0500
committerRalf Baechle <ralf@linux-mips.org>2013-02-21 06:51:33 -0500
commit8bfc245f9ad7bd4e461179e4e7852ef99b8b6144 (patch)
tree0ad091f645fbc8318634599d278966a53d3922ee /arch/mips/bcm47xx
parent612663a974065c3445e641d046769fe4c55a6438 (diff)
parent535237cecab2b078114be712c67e89a0db61965f (diff)
Merge branch 'mips-next-3.9' of git://git.linux-mips.org/pub/scm/john/linux-john into mips-for-linux-next
Diffstat (limited to 'arch/mips/bcm47xx')
-rw-r--r--arch/mips/bcm47xx/nvram.c159
-rw-r--r--arch/mips/bcm47xx/setup.c6
-rw-r--r--arch/mips/bcm47xx/sprom.c22
3 files changed, 131 insertions, 56 deletions
diff --git a/arch/mips/bcm47xx/nvram.c b/arch/mips/bcm47xx/nvram.c
index c37419c11c92..cc40b74940f5 100644
--- a/arch/mips/bcm47xx/nvram.c
+++ b/arch/mips/bcm47xx/nvram.c
@@ -3,7 +3,7 @@
3 * 3 *
4 * Copyright (C) 2005 Broadcom Corporation 4 * Copyright (C) 2005 Broadcom Corporation
5 * Copyright (C) 2006 Felix Fietkau <nbd@openwrt.org> 5 * Copyright (C) 2006 Felix Fietkau <nbd@openwrt.org>
6 * Copyright (C) 2010-2011 Hauke Mehrtens <hauke@hauke-m.de> 6 * Copyright (C) 2010-2012 Hauke Mehrtens <hauke@hauke-m.de>
7 * 7 *
8 * This program is free software; you can redistribute it and/or modify it 8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the 9 * under the terms of the GNU General Public License as published by the
@@ -18,83 +18,160 @@
18#include <linux/kernel.h> 18#include <linux/kernel.h>
19#include <linux/string.h> 19#include <linux/string.h>
20#include <asm/addrspace.h> 20#include <asm/addrspace.h>
21#include <asm/mach-bcm47xx/nvram.h> 21#include <bcm47xx_nvram.h>
22#include <asm/mach-bcm47xx/bcm47xx.h> 22#include <asm/mach-bcm47xx/bcm47xx.h>
23 23
24static char nvram_buf[NVRAM_SPACE]; 24static char nvram_buf[NVRAM_SPACE];
25 25
26static u32 find_nvram_size(u32 end)
27{
28 struct nvram_header *header;
29 u32 nvram_sizes[] = {0x8000, 0xF000, 0x10000};
30 int i;
31
32 for (i = 0; i < ARRAY_SIZE(nvram_sizes); i++) {
33 header = (struct nvram_header *)KSEG1ADDR(end - nvram_sizes[i]);
34 if (header->magic == NVRAM_HEADER)
35 return nvram_sizes[i];
36 }
37
38 return 0;
39}
40
26/* Probe for NVRAM header */ 41/* Probe for NVRAM header */
27static void early_nvram_init(void) 42static int nvram_find_and_copy(u32 base, u32 lim)
28{ 43{
29#ifdef CONFIG_BCM47XX_SSB
30 struct ssb_mipscore *mcore_ssb;
31#endif
32#ifdef CONFIG_BCM47XX_BCMA
33 struct bcma_drv_cc *bcma_cc;
34#endif
35 struct nvram_header *header; 44 struct nvram_header *header;
36 int i; 45 int i;
37 u32 base = 0;
38 u32 lim = 0;
39 u32 off; 46 u32 off;
40 u32 *src, *dst; 47 u32 *src, *dst;
48 u32 size;
41 49
42 switch (bcm47xx_bus_type) { 50 /* TODO: when nvram is on nand flash check for bad blocks first. */
43#ifdef CONFIG_BCM47XX_SSB
44 case BCM47XX_BUS_TYPE_SSB:
45 mcore_ssb = &bcm47xx_bus.ssb.mipscore;
46 base = mcore_ssb->pflash.window;
47 lim = mcore_ssb->pflash.window_size;
48 break;
49#endif
50#ifdef CONFIG_BCM47XX_BCMA
51 case BCM47XX_BUS_TYPE_BCMA:
52 bcma_cc = &bcm47xx_bus.bcma.bus.drv_cc;
53 base = bcma_cc->pflash.window;
54 lim = bcma_cc->pflash.window_size;
55 break;
56#endif
57 }
58
59 off = FLASH_MIN; 51 off = FLASH_MIN;
60 while (off <= lim) { 52 while (off <= lim) {
61 /* Windowed flash access */ 53 /* Windowed flash access */
62 header = (struct nvram_header *) 54 size = find_nvram_size(base + off);
63 KSEG1ADDR(base + off - NVRAM_SPACE); 55 if (size) {
64 if (header->magic == NVRAM_HEADER) 56 header = (struct nvram_header *)KSEG1ADDR(base + off -
57 size);
65 goto found; 58 goto found;
59 }
66 off <<= 1; 60 off <<= 1;
67 } 61 }
68 62
69 /* Try embedded NVRAM at 4 KB and 1 KB as last resorts */ 63 /* Try embedded NVRAM at 4 KB and 1 KB as last resorts */
70 header = (struct nvram_header *) KSEG1ADDR(base + 4096); 64 header = (struct nvram_header *) KSEG1ADDR(base + 4096);
71 if (header->magic == NVRAM_HEADER) 65 if (header->magic == NVRAM_HEADER) {
66 size = NVRAM_SPACE;
72 goto found; 67 goto found;
68 }
73 69
74 header = (struct nvram_header *) KSEG1ADDR(base + 1024); 70 header = (struct nvram_header *) KSEG1ADDR(base + 1024);
75 if (header->magic == NVRAM_HEADER) 71 if (header->magic == NVRAM_HEADER) {
72 size = NVRAM_SPACE;
76 goto found; 73 goto found;
74 }
77 75
78 return; 76 pr_err("no nvram found\n");
77 return -ENXIO;
79 78
80found: 79found:
80
81 if (header->len > size)
82 pr_err("The nvram size accoridng to the header seems to be bigger than the partition on flash\n");
83 if (header->len > NVRAM_SPACE)
84 pr_err("nvram on flash (%i bytes) is bigger than the reserved space in memory, will just copy the first %i bytes\n",
85 header->len, NVRAM_SPACE);
86
81 src = (u32 *) header; 87 src = (u32 *) header;
82 dst = (u32 *) nvram_buf; 88 dst = (u32 *) nvram_buf;
83 for (i = 0; i < sizeof(struct nvram_header); i += 4) 89 for (i = 0; i < sizeof(struct nvram_header); i += 4)
84 *dst++ = *src++; 90 *dst++ = *src++;
85 for (; i < header->len && i < NVRAM_SPACE; i += 4) 91 for (; i < header->len && i < NVRAM_SPACE && i < size; i += 4)
86 *dst++ = le32_to_cpu(*src++); 92 *dst++ = le32_to_cpu(*src++);
93 memset(dst, 0x0, NVRAM_SPACE - i);
94
95 return 0;
87} 96}
88 97
89int nvram_getenv(char *name, char *val, size_t val_len) 98#ifdef CONFIG_BCM47XX_SSB
99static int nvram_init_ssb(void)
100{
101 struct ssb_mipscore *mcore = &bcm47xx_bus.ssb.mipscore;
102 u32 base;
103 u32 lim;
104
105 if (mcore->pflash.present) {
106 base = mcore->pflash.window;
107 lim = mcore->pflash.window_size;
108 } else {
109 pr_err("Couldn't find supported flash memory\n");
110 return -ENXIO;
111 }
112
113 return nvram_find_and_copy(base, lim);
114}
115#endif
116
117#ifdef CONFIG_BCM47XX_BCMA
118static int nvram_init_bcma(void)
119{
120 struct bcma_drv_cc *cc = &bcm47xx_bus.bcma.bus.drv_cc;
121 u32 base;
122 u32 lim;
123
124#ifdef CONFIG_BCMA_NFLASH
125 if (cc->nflash.boot) {
126 base = BCMA_SOC_FLASH1;
127 lim = BCMA_SOC_FLASH1_SZ;
128 } else
129#endif
130 if (cc->pflash.present) {
131 base = cc->pflash.window;
132 lim = cc->pflash.window_size;
133#ifdef CONFIG_BCMA_SFLASH
134 } else if (cc->sflash.present) {
135 base = cc->sflash.window;
136 lim = cc->sflash.size;
137#endif
138 } else {
139 pr_err("Couldn't find supported flash memory\n");
140 return -ENXIO;
141 }
142
143 return nvram_find_and_copy(base, lim);
144}
145#endif
146
147static int nvram_init(void)
148{
149 switch (bcm47xx_bus_type) {
150#ifdef CONFIG_BCM47XX_SSB
151 case BCM47XX_BUS_TYPE_SSB:
152 return nvram_init_ssb();
153#endif
154#ifdef CONFIG_BCM47XX_BCMA
155 case BCM47XX_BUS_TYPE_BCMA:
156 return nvram_init_bcma();
157#endif
158 }
159 return -ENXIO;
160}
161
162int bcm47xx_nvram_getenv(char *name, char *val, size_t val_len)
90{ 163{
91 char *var, *value, *end, *eq; 164 char *var, *value, *end, *eq;
165 int err;
92 166
93 if (!name) 167 if (!name)
94 return NVRAM_ERR_INV_PARAM; 168 return -EINVAL;
95 169
96 if (!nvram_buf[0]) 170 if (!nvram_buf[0]) {
97 early_nvram_init(); 171 err = nvram_init();
172 if (err)
173 return err;
174 }
98 175
99 /* Look for name=value and return value */ 176 /* Look for name=value and return value */
100 var = &nvram_buf[sizeof(struct nvram_header)]; 177 var = &nvram_buf[sizeof(struct nvram_header)];
@@ -110,6 +187,6 @@ int nvram_getenv(char *name, char *val, size_t val_len)
110 return snprintf(val, val_len, "%s", value); 187 return snprintf(val, val_len, "%s", value);
111 } 188 }
112 } 189 }
113 return NVRAM_ERR_ENVNOTFOUND; 190 return -ENOENT;
114} 191}
115EXPORT_SYMBOL(nvram_getenv); 192EXPORT_SYMBOL(bcm47xx_nvram_getenv);
diff --git a/arch/mips/bcm47xx/setup.c b/arch/mips/bcm47xx/setup.c
index 4d54b58dbd32..b2246cd9ca12 100644
--- a/arch/mips/bcm47xx/setup.c
+++ b/arch/mips/bcm47xx/setup.c
@@ -35,7 +35,7 @@
35#include <asm/reboot.h> 35#include <asm/reboot.h>
36#include <asm/time.h> 36#include <asm/time.h>
37#include <bcm47xx.h> 37#include <bcm47xx.h>
38#include <asm/mach-bcm47xx/nvram.h> 38#include <bcm47xx_nvram.h>
39 39
40union bcm47xx_bus bcm47xx_bus; 40union bcm47xx_bus bcm47xx_bus;
41EXPORT_SYMBOL(bcm47xx_bus); 41EXPORT_SYMBOL(bcm47xx_bus);
@@ -115,7 +115,7 @@ static int bcm47xx_get_invariants(struct ssb_bus *bus,
115 memset(&iv->sprom, 0, sizeof(struct ssb_sprom)); 115 memset(&iv->sprom, 0, sizeof(struct ssb_sprom));
116 bcm47xx_fill_sprom(&iv->sprom, NULL, false); 116 bcm47xx_fill_sprom(&iv->sprom, NULL, false);
117 117
118 if (nvram_getenv("cardbus", buf, sizeof(buf)) >= 0) 118 if (bcm47xx_nvram_getenv("cardbus", buf, sizeof(buf)) >= 0)
119 iv->has_cardbus_slot = !!simple_strtoul(buf, NULL, 10); 119 iv->has_cardbus_slot = !!simple_strtoul(buf, NULL, 10);
120 120
121 return 0; 121 return 0;
@@ -138,7 +138,7 @@ static void __init bcm47xx_register_ssb(void)
138 panic("Failed to initialize SSB bus (err %d)", err); 138 panic("Failed to initialize SSB bus (err %d)", err);
139 139
140 mcore = &bcm47xx_bus.ssb.mipscore; 140 mcore = &bcm47xx_bus.ssb.mipscore;
141 if (nvram_getenv("kernel_args", buf, sizeof(buf)) >= 0) { 141 if (bcm47xx_nvram_getenv("kernel_args", buf, sizeof(buf)) >= 0) {
142 if (strstr(buf, "console=ttyS1")) { 142 if (strstr(buf, "console=ttyS1")) {
143 struct ssb_serial_port port; 143 struct ssb_serial_port port;
144 144
diff --git a/arch/mips/bcm47xx/sprom.c b/arch/mips/bcm47xx/sprom.c
index b2a7c251e471..ad03c931b905 100644
--- a/arch/mips/bcm47xx/sprom.c
+++ b/arch/mips/bcm47xx/sprom.c
@@ -27,7 +27,7 @@
27 */ 27 */
28 28
29#include <bcm47xx.h> 29#include <bcm47xx.h>
30#include <nvram.h> 30#include <bcm47xx_nvram.h>
31 31
32static void create_key(const char *prefix, const char *postfix, 32static void create_key(const char *prefix, const char *postfix,
33 const char *name, char *buf, int len) 33 const char *name, char *buf, int len)
@@ -50,10 +50,10 @@ static int get_nvram_var(const char *prefix, const char *postfix,
50 50
51 create_key(prefix, postfix, name, key, sizeof(key)); 51 create_key(prefix, postfix, name, key, sizeof(key));
52 52
53 err = nvram_getenv(key, buf, len); 53 err = bcm47xx_nvram_getenv(key, buf, len);
54 if (fallback && err == NVRAM_ERR_ENVNOTFOUND && prefix) { 54 if (fallback && err == -ENOENT && prefix) {
55 create_key(NULL, postfix, name, key, sizeof(key)); 55 create_key(NULL, postfix, name, key, sizeof(key));
56 err = nvram_getenv(key, buf, len); 56 err = bcm47xx_nvram_getenv(key, buf, len);
57 } 57 }
58 return err; 58 return err;
59} 59}
@@ -71,7 +71,7 @@ static void nvram_read_ ## type (const char *prefix, \
71 fallback); \ 71 fallback); \
72 if (err < 0) \ 72 if (err < 0) \
73 return; \ 73 return; \
74 err = kstrto ## type (buf, 0, &var); \ 74 err = kstrto ## type(strim(buf), 0, &var); \
75 if (err) { \ 75 if (err) { \
76 pr_warn("can not parse nvram name %s%s%s with value %s got %i\n", \ 76 pr_warn("can not parse nvram name %s%s%s with value %s got %i\n", \
77 prefix, name, postfix, buf, err); \ 77 prefix, name, postfix, buf, err); \
@@ -99,7 +99,7 @@ static void nvram_read_u32_2(const char *prefix, const char *name,
99 err = get_nvram_var(prefix, NULL, name, buf, sizeof(buf), fallback); 99 err = get_nvram_var(prefix, NULL, name, buf, sizeof(buf), fallback);
100 if (err < 0) 100 if (err < 0)
101 return; 101 return;
102 err = kstrtou32(buf, 0, &val); 102 err = kstrtou32(strim(buf), 0, &val);
103 if (err) { 103 if (err) {
104 pr_warn("can not parse nvram name %s%s with value %s got %i\n", 104 pr_warn("can not parse nvram name %s%s with value %s got %i\n",
105 prefix, name, buf, err); 105 prefix, name, buf, err);
@@ -120,7 +120,7 @@ static void nvram_read_leddc(const char *prefix, const char *name,
120 err = get_nvram_var(prefix, NULL, name, buf, sizeof(buf), fallback); 120 err = get_nvram_var(prefix, NULL, name, buf, sizeof(buf), fallback);
121 if (err < 0) 121 if (err < 0)
122 return; 122 return;
123 err = kstrtou32(buf, 0, &val); 123 err = kstrtou32(strim(buf), 0, &val);
124 if (err) { 124 if (err) {
125 pr_warn("can not parse nvram name %s%s with value %s got %i\n", 125 pr_warn("can not parse nvram name %s%s with value %s got %i\n",
126 prefix, name, buf, err); 126 prefix, name, buf, err);
@@ -144,7 +144,7 @@ static void nvram_read_macaddr(const char *prefix, const char *name,
144 if (err < 0) 144 if (err < 0)
145 return; 145 return;
146 146
147 nvram_parse_macaddr(buf, *val); 147 bcm47xx_nvram_parse_macaddr(buf, *val);
148} 148}
149 149
150static void nvram_read_alpha2(const char *prefix, const char *name, 150static void nvram_read_alpha2(const char *prefix, const char *name,
@@ -652,12 +652,10 @@ static void bcm47xx_fill_sprom_ethernet(struct ssb_sprom *sprom,
652static void bcm47xx_fill_board_data(struct ssb_sprom *sprom, const char *prefix, 652static void bcm47xx_fill_board_data(struct ssb_sprom *sprom, const char *prefix,
653 bool fallback) 653 bool fallback)
654{ 654{
655 nvram_read_u16(prefix, NULL, "boardrev", &sprom->board_rev, 0, 655 nvram_read_u16(prefix, NULL, "boardrev", &sprom->board_rev, 0, true);
656 fallback);
657 nvram_read_u16(prefix, NULL, "boardnum", &sprom->board_num, 0, 656 nvram_read_u16(prefix, NULL, "boardnum", &sprom->board_num, 0,
658 fallback); 657 fallback);
659 nvram_read_u16(prefix, NULL, "boardtype", &sprom->board_type, 0, 658 nvram_read_u16(prefix, NULL, "boardtype", &sprom->board_type, 0, true);
660 fallback);
661 nvram_read_u32_2(prefix, "boardflags", &sprom->boardflags_lo, 659 nvram_read_u32_2(prefix, "boardflags", &sprom->boardflags_lo,
662 &sprom->boardflags_hi, fallback); 660 &sprom->boardflags_hi, fallback);
663 nvram_read_u32_2(prefix, "boardflags2", &sprom->boardflags2_lo, 661 nvram_read_u32_2(prefix, "boardflags2", &sprom->boardflags2_lo,