usb: gadget: m66592-udc: add pullup function
[zen-stable.git] / drivers / staging / brcm80211 / brcmsmac / nvram.c
blob085ec0b9224f798588d7b4e33b4bb1011bb202f9
1 /*
2 * Copyright (c) 2010 Broadcom Corporation
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
11 * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
13 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
14 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 #include <linux/slab.h>
18 #include <linux/string.h>
19 #include <bcmdefs.h>
20 #include <bcmutils.h>
21 #include <bcmnvram.h>
22 #include <sbchipc.h>
23 #include <bcmdevs.h>
24 #include <hndsoc.h>
26 #define NVR_MSG(x)
28 typedef struct _vars {
29 struct _vars *next;
30 int bufsz; /* allocated size */
31 int size; /* actual vars size */
32 char *vars;
33 } vars_t;
35 #define VARS_T_OH sizeof(vars_t)
37 static vars_t *vars;
39 #define NVRAM_FILE 1
41 static char *findvar(char *vars, char *lim, const char *name);
43 int nvram_init(void)
46 /* Make sure we read nvram in flash just once before freeing the memory */
47 if (vars != NULL) {
48 NVR_MSG(("nvram_init: called again without calling nvram_exit()\n"));
49 return 0;
51 return 0;
54 int nvram_append(char *varlst, uint varsz)
56 uint bufsz = VARS_T_OH;
57 vars_t *new;
59 new = kmalloc(bufsz, GFP_ATOMIC);
60 if (new == NULL)
61 return -ENOMEM;
63 new->vars = varlst;
64 new->bufsz = bufsz;
65 new->size = varsz;
66 new->next = vars;
67 vars = new;
69 return 0;
72 void nvram_exit(void)
74 vars_t *this, *next;
76 this = vars;
77 if (this)
78 kfree(this->vars);
80 while (this) {
81 next = this->next;
82 kfree(this);
83 this = next;
85 vars = NULL;
88 static char *findvar(char *vars, char *lim, const char *name)
90 char *s;
91 int len;
93 len = strlen(name);
95 for (s = vars; (s < lim) && *s;) {
96 if ((memcmp(s, name, len) == 0) && (s[len] == '='))
97 return &s[len + 1];
99 while (*s++)
103 return NULL;
107 * Search the name=value vars for a specific one and return its value.
108 * Returns NULL if not found.
110 char *getvar(char *vars, const char *name)
112 char *s;
113 int len;
115 if (!name)
116 return NULL;
118 len = strlen(name);
119 if (len == 0)
120 return NULL;
122 /* first look in vars[] */
123 for (s = vars; s && *s;) {
124 if ((memcmp(s, name, len) == 0) && (s[len] == '='))
125 return &s[len + 1];
127 while (*s++)
130 /* then query nvram */
131 return nvram_get(name);
135 * Search the vars for a specific one and return its value as
136 * an integer. Returns 0 if not found.
138 int getintvar(char *vars, const char *name)
140 char *val;
142 val = getvar(vars, name);
143 if (val == NULL)
144 return 0;
146 return simple_strtoul(val, NULL, 0);
149 char *nvram_get(const char *name)
151 char *v = NULL;
152 vars_t *cur;
154 for (cur = vars; cur; cur = cur->next) {
155 v = findvar(cur->vars, cur->vars + cur->size, name);
156 if (v)
157 break;
160 return v;
163 int nvram_set(const char *name, const char *value)
165 return 0;
168 int nvram_unset(const char *name)
170 return 0;
173 int nvram_reset(void)
175 return 0;
178 int nvram_commit(void)
180 return 0;
183 int nvram_getall(char *buf, int count)
185 int len, resid = count;
186 vars_t *this;
188 this = vars;
189 while (this) {
190 char *from, *lim, *to;
191 int acc;
193 from = this->vars;
194 lim = (char *)(this->vars + this->size);
195 to = buf;
196 acc = 0;
197 while ((from < lim) && (*from)) {
198 len = strlen(from) + 1;
199 if (resid < (acc + len))
200 return -EOVERFLOW;
201 memcpy(to, from, len);
202 acc += len;
203 from += len;
204 to += len;
207 resid -= acc;
208 buf += acc;
209 this = this->next;
211 if (resid < 1)
212 return -EOVERFLOW;
213 *buf = '\0';
214 return 0;