1 --- a/arch/mips/bcm47xx/nvram.c
2 +++ b/arch/mips/bcm47xx/nvram.c
4 #include <asm/addrspace.h>
5 #include <asm/mach-bcm47xx/nvram.h>
6 #include <asm/mach-bcm47xx/bcm47xx.h>
7 +#include <asm/mach-bcm47xx/bus.h>
9 static char nvram_buf[NVRAM_SPACE];
11 /* Probe for NVRAM header */
12 -static void early_nvram_init(void)
13 +static void early_nvram_init_pflash(void)
15 #ifdef CONFIG_BCM47XX_SSB
16 struct ssb_chipcommon *ssb_cc;
17 @@ -50,9 +51,6 @@ static void early_nvram_init(void)
18 #ifdef CONFIG_BCM47XX_BCMA
19 case BCM47XX_BUS_TYPE_BCMA:
20 bcma_cc = &bcm47xx_bus.bcma.bus.drv_cc;
21 - if (bcma_cc->flash_type != BCMA_PFLASH)
24 base = bcma_cc->pflash.window;
25 lim = bcma_cc->pflash.window_size;
27 @@ -86,7 +84,115 @@ found:
28 for (i = 0; i < sizeof(struct nvram_header); i += 4)
30 for (; i < header->len && i < NVRAM_SPACE; i += 4)
31 - *dst++ = le32_to_cpu(*src++);
35 +static int find_nvram_size(void)
37 + struct nvram_header header;
38 + int nvram_sizes[] = {NVRAM_SPACE, 0xF000, 2 * NVRAM_SPACE};
42 + for (i = 0; i < sizeof(nvram_sizes); i++) {
43 + ret = bcm47xx_sflash.read(&bcm47xx_sflash, bcm47xx_sflash.size - nvram_sizes[i], sizeof(header), (u8 *)&header);
44 + if (ret != sizeof(header))
46 + if (header.magic == NVRAM_HEADER)
47 + return nvram_sizes[i];
52 +static int early_nvram_init_sflash(void)
60 + /* check if the struct is already initilized */
61 + if (!bcm47xx_sflash.size)
64 + size = find_nvram_size();
70 + off = bcm47xx_sflash.size;
72 + printk(KERN_WARNING "nvram on flash is bigger than the reserved"
73 + " space in memory, will just copy the first %i bytes\n",
77 + ret = bcm47xx_sflash.read(&bcm47xx_sflash, off - size, len, dst);
87 +#ifdef CONFIG_BCM47XX_SSB
88 +static void early_nvram_init_ssb(void)
92 + switch (bcm47xx_bus.ssb.chipco.flash_type) {
94 + early_nvram_init_pflash();
97 + err = early_nvram_init_sflash();
99 + printk(KERN_WARNING "can not read from flash: %i\n", err);
102 + printk(KERN_WARNING "unknow flash type\n");
107 +#ifdef CONFIG_BCM47XX_BCMA
108 +static void early_nvram_init_bcma(void)
112 + switch (bcm47xx_bus.bcma.bus.drv_cc.flash_type) {
114 + early_nvram_init_pflash();
117 + err = early_nvram_init_sflash();
119 + printk(KERN_WARNING "can not read from flash: %i\n", err);
122 + printk(KERN_WARNING "unknow flash type\n");
127 +static void early_nvram_init(void)
129 + switch (bcm47xx_bus_type) {
130 +#ifdef CONFIG_BCM47XX_SSB
131 + case BCM47XX_BUS_TYPE_SSB:
132 + early_nvram_init_ssb();
135 +#ifdef CONFIG_BCM47XX_BCMA
136 + case BCM47XX_BUS_TYPE_BCMA:
137 + early_nvram_init_bcma();
143 int nvram_getenv(char *name, char *val, size_t val_len)