aboutsummaryrefslogtreecommitdiffstats
path: root/arch/mips/bcm47xx
diff options
context:
space:
mode:
authorHauke Mehrtens <hauke@hauke-m.de>2012-12-26 14:51:10 -0500
committerJohn Crispin <blogic@openwrt.org>2013-02-15 13:01:56 -0500
commitcc4403e02541af226ae6b7da0917c8959dd73a75 (patch)
tree0bdd262f0cfc89a7553556fb6097b5356fc6c9fd /arch/mips/bcm47xx
parentee7e2f3c235f43d815c0be285101b5b91a3bcaa5 (diff)
MIPS: BCM47XX: return error when init of nvram failed
This makes it possible to handle the case of not being able to read the nvram ram. This could happen when the code searching for the specific flash chip have not run jet. Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de> Patchwork: http://patchwork.linux-mips.org/patch/4740/ Signed-off-by: John Crispin <blogic@openwrt.org>
Diffstat (limited to 'arch/mips/bcm47xx')
-rw-r--r--arch/mips/bcm47xx/nvram.c35
1 files changed, 20 insertions, 15 deletions
diff --git a/arch/mips/bcm47xx/nvram.c b/arch/mips/bcm47xx/nvram.c
index e19fc2600b76..80e352e0c995 100644
--- a/arch/mips/bcm47xx/nvram.c
+++ b/arch/mips/bcm47xx/nvram.c
@@ -23,7 +23,7 @@
23 23
24static char nvram_buf[NVRAM_SPACE]; 24static char nvram_buf[NVRAM_SPACE];
25 25
26static void nvram_find_and_copy(u32 base, u32 lim) 26static int nvram_find_and_copy(u32 base, u32 lim)
27{ 27{
28 struct nvram_header *header; 28 struct nvram_header *header;
29 int i; 29 int i;
@@ -49,7 +49,7 @@ static void nvram_find_and_copy(u32 base, u32 lim)
49 if (header->magic == NVRAM_HEADER) 49 if (header->magic == NVRAM_HEADER)
50 goto found; 50 goto found;
51 51
52 return; 52 return -ENXIO;
53 53
54found: 54found:
55 src = (u32 *) header; 55 src = (u32 *) header;
@@ -58,10 +58,12 @@ found:
58 *dst++ = *src++; 58 *dst++ = *src++;
59 for (; i < header->len && i < NVRAM_SPACE; i += 4) 59 for (; i < header->len && i < NVRAM_SPACE; i += 4)
60 *dst++ = le32_to_cpu(*src++); 60 *dst++ = le32_to_cpu(*src++);
61
62 return 0;
61} 63}
62 64
63#ifdef CONFIG_BCM47XX_SSB 65#ifdef CONFIG_BCM47XX_SSB
64static void nvram_init_ssb(void) 66static int nvram_init_ssb(void)
65{ 67{
66 struct ssb_mipscore *mcore = &bcm47xx_bus.ssb.mipscore; 68 struct ssb_mipscore *mcore = &bcm47xx_bus.ssb.mipscore;
67 u32 base; 69 u32 base;
@@ -72,15 +74,15 @@ static void nvram_init_ssb(void)
72 lim = mcore->pflash.window_size; 74 lim = mcore->pflash.window_size;
73 } else { 75 } else {
74 pr_err("Couldn't find supported flash memory\n"); 76 pr_err("Couldn't find supported flash memory\n");
75 return; 77 return -ENXIO;
76 } 78 }
77 79
78 nvram_find_and_copy(base, lim); 80 return nvram_find_and_copy(base, lim);
79} 81}
80#endif 82#endif
81 83
82#ifdef CONFIG_BCM47XX_BCMA 84#ifdef CONFIG_BCM47XX_BCMA
83static void nvram_init_bcma(void) 85static int nvram_init_bcma(void)
84{ 86{
85 struct bcma_drv_cc *cc = &bcm47xx_bus.bcma.bus.drv_cc; 87 struct bcma_drv_cc *cc = &bcm47xx_bus.bcma.bus.drv_cc;
86 u32 base; 88 u32 base;
@@ -96,38 +98,41 @@ static void nvram_init_bcma(void)
96#endif 98#endif
97 } else { 99 } else {
98 pr_err("Couldn't find supported flash memory\n"); 100 pr_err("Couldn't find supported flash memory\n");
99 return; 101 return -ENXIO;
100 } 102 }
101 103
102 nvram_find_and_copy(base, lim); 104 return nvram_find_and_copy(base, lim);
103} 105}
104#endif 106#endif
105 107
106static void early_nvram_init(void) 108static int early_nvram_init(void)
107{ 109{
108 switch (bcm47xx_bus_type) { 110 switch (bcm47xx_bus_type) {
109#ifdef CONFIG_BCM47XX_SSB 111#ifdef CONFIG_BCM47XX_SSB
110 case BCM47XX_BUS_TYPE_SSB: 112 case BCM47XX_BUS_TYPE_SSB:
111 nvram_init_ssb(); 113 return nvram_init_ssb();
112 break;
113#endif 114#endif
114#ifdef CONFIG_BCM47XX_BCMA 115#ifdef CONFIG_BCM47XX_BCMA
115 case BCM47XX_BUS_TYPE_BCMA: 116 case BCM47XX_BUS_TYPE_BCMA:
116 nvram_init_bcma(); 117 return nvram_init_bcma();
117 break;
118#endif 118#endif
119 } 119 }
120 return -ENXIO;
120} 121}
121 122
122int nvram_getenv(char *name, char *val, size_t val_len) 123int nvram_getenv(char *name, char *val, size_t val_len)
123{ 124{
124 char *var, *value, *end, *eq; 125 char *var, *value, *end, *eq;
126 int err;
125 127
126 if (!name) 128 if (!name)
127 return -EINVAL; 129 return -EINVAL;
128 130
129 if (!nvram_buf[0]) 131 if (!nvram_buf[0]) {
130 early_nvram_init(); 132 err = early_nvram_init();
133 if (err)
134 return err;
135 }
131 136
132 /* Look for name=value and return value */ 137 /* Look for name=value and return value */
133 var = &nvram_buf[sizeof(struct nvram_header)]; 138 var = &nvram_buf[sizeof(struct nvram_header)];