brcm47xx: update flash drivers
[openwrt.git] / target / linux / brcm47xx / patches-3.2 / 029-bcm47xx-read-nvram-from-sflash.patch
1 --- a/arch/mips/bcm47xx/nvram.c
2 +++ b/arch/mips/bcm47xx/nvram.c
3 @@ -20,11 +20,12 @@
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>
8
9 static char nvram_buf[NVRAM_SPACE];
10
11 /* Probe for NVRAM header */
12 -static void early_nvram_init(void)
13 +static void early_nvram_init_pflash(void)
14 {
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)
22 - return;
23 -
24 base = bcma_cc->pflash.window;
25 lim = bcma_cc->pflash.window_size;
26 break;
27 @@ -86,7 +84,106 @@ found:
28 for (i = 0; i < sizeof(struct nvram_header); i += 4)
29 *dst++ = *src++;
30 for (; i < header->len && i < NVRAM_SPACE; i += 4)
31 - *dst++ = le32_to_cpu(*src++);
32 + *dst++ = *src++;
33 +}
34 +
35 +static int early_nvram_init_sflash(void)
36 +{
37 + struct nvram_header header;
38 + u32 off;
39 + int ret;
40 + char *dst;
41 + int len;
42 +
43 + /* check if the struct is already initilized */
44 + if (!bcm47xx_sflash.size)
45 + return -1;
46 +
47 + off = FLASH_MIN;
48 + while (off <= bcm47xx_sflash.size) {
49 + ret = bcm47xx_sflash.read(&bcm47xx_sflash, off - NVRAM_SPACE, sizeof(header), (u8 *)&header);
50 + if (ret != sizeof(header))
51 + return ret;
52 + if (header.magic == NVRAM_HEADER)
53 + goto found;
54 + off <<= 1;
55 + }
56 +
57 + off = FLASH_MIN;
58 + while (off <= bcm47xx_sflash.size) {
59 + ret = bcm47xx_sflash.read(&bcm47xx_sflash, off - (2 * NVRAM_SPACE), sizeof(header), (u8 *)&header);
60 + if (ret != sizeof(header))
61 + return ret;
62 + if (header.magic == NVRAM_HEADER)
63 + goto found;
64 + off <<= 1;
65 + }
66 + return -1;
67 +
68 +found:
69 + len = NVRAM_SPACE;
70 + dst = nvram_buf;
71 + while (len) {
72 + ret = bcm47xx_sflash.read(&bcm47xx_sflash, off - (2 * NVRAM_SPACE), len, dst);
73 + if (ret < 0)
74 + return ret;
75 + off += ret;
76 + len -= ret;
77 + dst += ret;
78 + }
79 + return 0;
80 +}
81 +
82 +#ifdef CONFIG_BCM47XX_SSB
83 +static void early_nvram_init_ssb(void)
84 +{
85 + int err;
86 +
87 + switch (bcm47xx_bus.ssb.chipco.flash_type) {
88 + case SSB_PFLASH:
89 + early_nvram_init_pflash();
90 + case SSB_SFLASH:
91 + err = early_nvram_init_sflash();
92 + if (err < 0)
93 + printk(KERN_WARNING "can not read from flash: %i\n", err);
94 + default:
95 + printk(KERN_WARNING "unknow flash type\n");
96 + }
97 +}
98 +#endif
99 +
100 +#ifdef CONFIG_BCM47XX_BCMA
101 +static void early_nvram_init_bcma(void)
102 +{
103 + int err;
104 +
105 + switch (bcm47xx_bus.bcma.bus.drv_cc.flash_type) {
106 + case BCMA_PFLASH:
107 + early_nvram_init_pflash();
108 + case BCMA_SFLASH:
109 + err = early_nvram_init_sflash();
110 + if (err < 0)
111 + printk(KERN_WARNING "can not read from flash: %i\n", err);
112 + default:
113 + printk(KERN_WARNING "unknow flash type\n");
114 + }
115 +}
116 +#endif
117 +
118 +static void early_nvram_init(void)
119 +{
120 + switch (bcm47xx_bus_type) {
121 +#ifdef CONFIG_BCM47XX_SSB
122 + case BCM47XX_BUS_TYPE_SSB:
123 + early_nvram_init_ssb();
124 + break;
125 +#endif
126 +#ifdef CONFIG_BCM47XX_BCMA
127 + case BCM47XX_BUS_TYPE_BCMA:
128 + early_nvram_init_bcma();
129 + break;
130 +#endif
131 + }
132 }
133
134 int nvram_getenv(char *name, char *val, size_t val_len)
This page took 0.043839 seconds and 5 git commands to generate.