upload tizen1.0 source
[kernel/linux-2.6.36.git] / drivers / net / wireless / bcm4330 / src / include / bcmnvram.h
1 /*
2  * NVRAM variable manipulation
3  *
4  * Copyright (C) 1999-2011, Broadcom Corporation
5  * 
6  *         Unless you and Broadcom execute a separate written software license
7  * agreement governing use of this software, this software is licensed to you
8  * under the terms of the GNU General Public License version 2 (the "GPL"),
9  * available at http://www.broadcom.com/licenses/GPLv2.php, with the
10  * following added to such license:
11  * 
12  *      As a special exception, the copyright holders of this software give you
13  * permission to link this software with independent modules, and to copy and
14  * distribute the resulting executable under terms of your choice, provided that
15  * you also meet, for each linked independent module, the terms and conditions of
16  * the license of that module.  An independent module is a module which is not
17  * derived from this software.  The special exception does not apply to any
18  * modifications of the software.
19  * 
20  *      Notwithstanding the above, under no circumstances may you combine this
21  * software in any way with any other Broadcom software provided under a license
22  * other than the GPL, without Broadcom's express prior written consent.
23  *
24  * $Id: bcmnvram.h,v 13.62 2008-11-25 21:02:44 $
25  */
26
27 #ifndef _bcmnvram_h_
28 #define _bcmnvram_h_
29
30 #ifndef _LANGUAGE_ASSEMBLY
31
32 #include <typedefs.h>
33 #include <bcmdefs.h>
34
35 struct nvram_header {
36         uint32 magic;
37         uint32 len;
38         uint32 crc_ver_init;    /* 0:7 crc, 8:15 ver, 16:31 sdram_init */
39         uint32 config_refresh;  /* 0:15 sdram_config, 16:31 sdram_refresh */
40         uint32 config_ncdl;     /* ncdl values for memc */
41 };
42
43 struct nvram_tuple {
44         char *name;
45         char *value;
46         struct nvram_tuple *next;
47 };
48
49 /*
50  * Get default value for an NVRAM variable
51  */
52 extern char *nvram_default_get(const char *name);
53
54 /*
55  * Initialize NVRAM access. May be unnecessary or undefined on certain
56  * platforms.
57  */
58 extern int nvram_init(void *sih);
59
60 /*
61  * Append a chunk of nvram variables to the global list
62  */
63 extern int nvram_append(void *si, char *vars, uint varsz);
64
65 /*
66  * Check for reset button press for restoring factory defaults.
67  */
68 extern int nvram_reset(void *sih);
69
70 /*
71  * Disable NVRAM access. May be unnecessary or undefined on certain
72  * platforms.
73  */
74 extern void nvram_exit(void *sih);
75
76 /*
77  * Get the value of an NVRAM variable. The pointer returned may be
78  * invalid after a set.
79  * @param       name    name of variable to get
80  * @return      value of variable or NULL if undefined
81  */
82 extern char * nvram_get(const char *name);
83
84 /* 
85  * Read the reset GPIO value from the nvram and set the GPIO
86  * as input
87  */
88 extern int nvram_resetgpio_init(void *sih);
89
90 /* 
91  * Get the value of an NVRAM variable.
92  * @param       name    name of variable to get
93  * @return      value of variable or NUL if undefined
94  */
95 #define nvram_safe_get(name) (nvram_get(name) ? : "")
96
97 /*
98  * Match an NVRAM variable.
99  * @param       name    name of variable to match
100  * @param       match   value to compare against value of variable
101  * @return      TRUE if variable is defined and its value is string equal
102  *              to match or FALSE otherwise
103  */
104 static INLINE int
105 nvram_match(char *name, char *match)
106 {
107         const char *value = nvram_get(name);
108         return (value && !strcmp(value, match));
109 }
110
111 /*
112  * Inversely match an NVRAM variable.
113  * @param       name    name of variable to match
114  * @param       match   value to compare against value of variable
115  * @return      TRUE if variable is defined and its value is not string
116  *              equal to invmatch or FALSE otherwise
117  */
118 static INLINE int
119 nvram_invmatch(char *name, char *invmatch)
120 {
121         const char *value = nvram_get(name);
122         return (value && strcmp(value, invmatch));
123 }
124
125 /*
126  * Set the value of an NVRAM variable. The name and value strings are
127  * copied into private storage. Pointers to previously set values
128  * may become invalid. The new value may be immediately
129  * retrieved but will not be permanently stored until a commit.
130  * @param       name    name of variable to set
131  * @param       value   value of variable
132  * @return      0 on success and errno on failure
133  */
134 extern int nvram_set(const char *name, const char *value);
135
136 /*
137  * Unset an NVRAM variable. Pointers to previously set values
138  * remain valid until a set.
139  * @param       name    name of variable to unset
140  * @return      0 on success and errno on failure
141  * NOTE: use nvram_commit to commit this change to flash.
142  */
143 extern int nvram_unset(const char *name);
144
145 /*
146  * Commit NVRAM variables to permanent storage. All pointers to values
147  * may be invalid after a commit.
148  * NVRAM values are undefined after a commit.
149  * @return      0 on success and errno on failure
150  */
151 extern int nvram_commit(void);
152
153 /*
154  * Get all NVRAM variables (format name=value\0 ... \0\0).
155  * @param       buf     buffer to store variables
156  * @param       count   size of buffer in bytes
157  * @return      0 on success and errno on failure
158  */
159 extern int nvram_getall(char *nvram_buf, int count);
160
161 /*
162  * returns the crc value of the nvram
163  * @param       nvh     nvram header pointer
164  */
165 uint8 nvram_calc_crc(struct nvram_header * nvh);
166
167 #endif /* _LANGUAGE_ASSEMBLY */
168
169 /* The NVRAM version number stored as an NVRAM variable */
170 #define NVRAM_SOFTWARE_VERSION  "1"
171
172 #define NVRAM_MAGIC             0x48534C46      /* 'FLSH' */
173 #define NVRAM_CLEAR_MAGIC       0x0
174 #define NVRAM_INVALID_MAGIC     0xFFFFFFFF
175 #define NVRAM_VERSION           1
176 #define NVRAM_HEADER_SIZE       20
177 #define NVRAM_SPACE             0x8000
178
179 #define NVRAM_MAX_VALUE_LEN 255
180 #define NVRAM_MAX_PARAM_LEN 64
181
182 #define NVRAM_CRC_START_POSITION        9 /* magic, len, crc8 to be skipped */
183 #define NVRAM_CRC_VER_MASK      0xffffff00 /* for crc_ver_init */
184
185 #endif /* _bcmnvram_h_ */