2 * BCM947xx nvram variable access
4 * Copyright 2005, Broadcom Corporation
5 * Copyright 2006, Felix Fietkau <nbd@openwrt.org>
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2 of the License, or (at your
10 * option) any later version.
13 #include <linux/init.h>
14 #include <linux/module.h>
15 #include <linux/ssb/ssb.h>
16 #include <linux/kernel.h>
17 #include <linux/string.h>
18 #include <linux/interrupt.h>
19 #include <linux/spinlock.h>
20 #include <linux/slab.h>
21 #include <asm/byteorder.h>
22 #include <asm/bootinfo.h>
23 #include <asm/addrspace.h>
25 #include <asm/uaccess.h>
30 extern struct ssb_bus ssb
;
32 static char nvram_buf
[NVRAM_SPACE
];
34 extern char *cfe_env_get(char *nv_buf
, const char *name
);
36 /* Probe for NVRAM header */
37 static void __init
early_nvram_init(void)
39 struct ssb_mipscore
*mcore
= &ssb
.mipscore
;
40 struct nvram_header
*header
;
45 base
= mcore
->flash_window
;
46 lim
= mcore
->flash_window_size
;
50 /* XXX: hack for supporting the CFE environment stuff on WGT634U */
52 src
= (u32
*) KSEG1ADDR(base
+ 8 MB
- 0x2000);
53 dst
= (u32
*) nvram_buf
;
55 if ((*src
& 0xff00ff) == 0x000001) {
56 printk("early_nvram_init: WGT634U NVRAM found.\n");
58 for (i
= 0; i
< 0x1ff0; i
++) {
59 if (*src
== 0xFFFFFFFF)
70 /* Windowed flash access */
71 header
= (struct nvram_header
*) KSEG1ADDR(base
+ off
- NVRAM_SPACE
);
72 if (header
->magic
== NVRAM_HEADER
)
77 /* Try embedded NVRAM at 4 KB and 1 KB as last resorts */
78 header
= (struct nvram_header
*) KSEG1ADDR(base
+ 4096);
79 if (header
->magic
== NVRAM_HEADER
)
82 header
= (struct nvram_header
*) KSEG1ADDR(base
+ 1024);
83 if (header
->magic
== NVRAM_HEADER
)
90 dst
= (u32
*) nvram_buf
;
91 for (i
= 0; i
< sizeof(struct nvram_header
); i
+= 4)
93 for (; i
< header
->len
&& i
< NVRAM_SPACE
; i
+= 4)
94 *dst
++ = le32_to_cpu(*src
++);
97 char *nvram_get(const char *name
)
99 char *var
, *value
, *end
, *eq
;
108 return cfe_env_get(nvram_buf
, name
);
110 /* Look for name=value and return value */
111 var
= &nvram_buf
[sizeof(struct nvram_header
)];
112 end
= nvram_buf
+ sizeof(nvram_buf
) - 2;
113 end
[0] = end
[1] = '\0';
114 for (; *var
; var
= value
+ strlen(value
) + 1) {
115 if (!(eq
= strchr(var
, '=')))
118 if ((eq
- var
) == strlen(name
) && strncmp(var
, name
, (eq
- var
)) == 0)
125 EXPORT_SYMBOL(nvram_get
);
This page took 0.05374 seconds and 5 git commands to generate.