1 From 1d693b2c9d5943cbe938f879041b837cd004737f Mon Sep 17 00:00:00 2001
2 From: Hauke Mehrtens <hauke@hauke-m.de>
3 Date: Sat, 23 Jul 2011 18:29:38 +0200
4 Subject: [PATCH 25/26] bcm47xx: read nvram from sflash
6 bcm47xx: add sflash support to nvram
8 Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
10 arch/mips/bcm47xx/nvram.c | 86 +++++++++++++++++++++++++++++++++++++++++++-
11 1 files changed, 84 insertions(+), 2 deletions(-)
13 --- a/arch/mips/bcm47xx/nvram.c
14 +++ b/arch/mips/bcm47xx/nvram.c
16 #include <asm/addrspace.h>
17 #include <asm/mach-bcm47xx/nvram.h>
18 #include <asm/mach-bcm47xx/bcm47xx.h>
19 +#include <asm/mach-bcm47xx/bus.h>
21 static char nvram_buf[NVRAM_SPACE];
23 /* Probe for NVRAM header */
24 -static void early_nvram_init(void)
25 +static void early_nvram_init_pflash(void)
27 #ifdef CONFIG_BCM47XX_SSB
28 struct ssb_chipcommon *ssb_cc;
29 @@ -86,7 +87,88 @@ found:
30 for (i = 0; i < sizeof(struct nvram_header); i += 4)
32 for (; i < header->len && i < NVRAM_SPACE; i += 4)
33 - *dst++ = le32_to_cpu(*src++);
37 +static int early_nvram_init_sflash(void)
39 + struct nvram_header header;
45 + /* check if the struct is already initilized */
46 + if (!bcm47xx_sflash.size)
50 + while (off <= bcm47xx_sflash.size) {
51 + ret = bcm47xx_sflash.read(&bcm47xx_sflash, off - NVRAM_SPACE, sizeof(header), (u8 *)&header);
52 + if (ret != sizeof(header))
54 + if (header.magic == NVRAM_HEADER)
60 + while (off <= bcm47xx_sflash.size) {
61 + ret = bcm47xx_sflash.read(&bcm47xx_sflash, off - (2 * NVRAM_SPACE), sizeof(header), (u8 *)&header);
62 + if (ret != sizeof(header))
64 + if (header.magic == NVRAM_HEADER)
74 + ret = bcm47xx_sflash.read(&bcm47xx_sflash, off - (2 * NVRAM_SPACE), len, dst);
84 +static void early_nvram_init(void)
88 + switch (bcm47xx_bus_type) {
89 +#ifdef CONFIG_BCM47XX_SSB
90 + case BCM47XX_BUS_TYPE_SSB:
91 + if (bcm47xx_bus.ssb.chipco.flash_type == SSB_PFLASH) {
92 + early_nvram_init_pflash();
93 + } else if (bcm47xx_bus.ssb.chipco.flash_type == SSB_SFLASH) {
94 + err = early_nvram_init_sflash();
96 + printk(KERN_WARNING "can not read from flash: %i\n", err);
98 + printk(KERN_WARNING "unknow flash type\n");
102 +#ifdef CONFIG_BCM47XX_BCMA
103 + case BCM47XX_BUS_TYPE_BCMA:
104 + if (bcm47xx_bus.bcma.bus.drv_cc.flash_type == BCMA_PFLASH) {
105 + early_nvram_init_pflash();
106 + } else if (bcm47xx_bus.bcma.bus.drv_cc.flash_type == BCMA_SFLASH) {
107 + err = early_nvram_init_sflash();
109 + printk(KERN_WARNING "can not read from flash: %i\n", err);
111 + printk(KERN_WARNING "unknow flash type\n");
118 int nvram_getenv(char *name, char *val, size_t val_len)