aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArend van Spriel <arend@broadcom.com>2011-12-12 18:15:00 -0500
committerJohn W. Linville <linville@tuxdriver.com>2011-12-13 15:47:58 -0500
commit373c78e19d6c00ff87fc251584d8bab65150e751 (patch)
treedb90a1dea6c0d1d7f7077eb5a16ac893a6eea432
parentd3126c52eb7f3239b45481facc4078b08ed1027c (diff)
brcm80211: smac: use bcma core access functions in otp.c
The code in otp.c now uses the bcma core access functions to read the OTP information from the device. Reviewed-by: Pieter-Paul Giesberts <pieterpg@broadcom.com> Reviewed-by: Alwin Beukers <alwin@broadcom.com> Signed-off-by: Arend van Spriel <arend@broadcom.com> Signed-off-by: Franky Lin <frankyl@broadcom.com> Signed-off-by: John W. Linville <linville@tuxdriver.com>
-rw-r--r--drivers/net/wireless/brcm80211/brcmsmac/otp.c68
-rw-r--r--drivers/net/wireless/brcm80211/include/chipcommon.h2
2 files changed, 28 insertions, 42 deletions
diff --git a/drivers/net/wireless/brcm80211/brcmsmac/otp.c b/drivers/net/wireless/brcm80211/brcmsmac/otp.c
index 612434ea952f..f1ca12625860 100644
--- a/drivers/net/wireless/brcm80211/brcmsmac/otp.c
+++ b/drivers/net/wireless/brcm80211/brcmsmac/otp.c
@@ -77,7 +77,7 @@ struct otp_fn_s {
77}; 77};
78 78
79struct otpinfo { 79struct otpinfo {
80 uint ccrev; /* chipc revision */ 80 struct bcma_device *core; /* chipc core */
81 const struct otp_fn_s *fn; /* OTP functions */ 81 const struct otp_fn_s *fn; /* OTP functions */
82 struct si_pub *sih; /* Saved sb handle */ 82 struct si_pub *sih; /* Saved sb handle */
83 83
@@ -133,9 +133,10 @@ struct otpinfo {
133#define OTP_SZ_FU_144 (144/8) /* 144 bits */ 133#define OTP_SZ_FU_144 (144/8) /* 144 bits */
134 134
135static u16 135static u16
136ipxotp_otpr(struct otpinfo *oi, struct chipcregs __iomem *cc, uint wn) 136ipxotp_otpr(struct otpinfo *oi, uint wn)
137{ 137{
138 return R_REG(&cc->sromotp[wn]); 138 return bcma_read16(oi->core,
139 CHIPCREGOFFS(sromotp[wn]));
139} 140}
140 141
141/* 142/*
@@ -161,19 +162,21 @@ static int ipxotp_max_rgnsz(struct si_pub *sih, int osizew)
161 return ret; 162 return ret;
162} 163}
163 164
164static void _ipxotp_init(struct otpinfo *oi, struct chipcregs __iomem *cc) 165static void _ipxotp_init(struct otpinfo *oi)
165{ 166{
166 uint k; 167 uint k;
167 u32 otpp, st; 168 u32 otpp, st;
169 int ccrev = ai_get_ccrev(oi->sih);
170
168 171
169 /* 172 /*
170 * record word offset of General Use Region 173 * record word offset of General Use Region
171 * for various chipcommon revs 174 * for various chipcommon revs
172 */ 175 */
173 if (oi->ccrev == 21 || oi->ccrev == 24 176 if (ccrev == 21 || ccrev == 24
174 || oi->ccrev == 27) { 177 || ccrev == 27) {
175 oi->otpgu_base = REVA4_OTPGU_BASE; 178 oi->otpgu_base = REVA4_OTPGU_BASE;
176 } else if (oi->ccrev == 36) { 179 } else if (ccrev == 36) {
177 /* 180 /*
178 * OTP size greater than equal to 2KB (128 words), 181 * OTP size greater than equal to 2KB (128 words),
179 * otpgu_base is similar to rev23 182 * otpgu_base is similar to rev23
@@ -182,7 +185,7 @@ static void _ipxotp_init(struct otpinfo *oi, struct chipcregs __iomem *cc)
182 oi->otpgu_base = REVB8_OTPGU_BASE; 185 oi->otpgu_base = REVB8_OTPGU_BASE;
183 else 186 else
184 oi->otpgu_base = REV36_OTPGU_BASE; 187 oi->otpgu_base = REV36_OTPGU_BASE;
185 } else if (oi->ccrev == 23 || oi->ccrev >= 25) { 188 } else if (ccrev == 23 || ccrev >= 25) {
186 oi->otpgu_base = REVB8_OTPGU_BASE; 189 oi->otpgu_base = REVB8_OTPGU_BASE;
187 } 190 }
188 191
@@ -190,24 +193,21 @@ static void _ipxotp_init(struct otpinfo *oi, struct chipcregs __iomem *cc)
190 otpp = 193 otpp =
191 OTPP_START_BUSY | ((OTPPOC_INIT << OTPP_OC_SHIFT) & OTPP_OC_MASK); 194 OTPP_START_BUSY | ((OTPPOC_INIT << OTPP_OC_SHIFT) & OTPP_OC_MASK);
192 195
193 W_REG(&cc->otpprog, otpp); 196 bcma_write32(oi->core, CHIPCREGOFFS(otpprog), otpp);
194 for (k = 0; 197 st = bcma_read32(oi->core, CHIPCREGOFFS(otpprog));
195 ((st = R_REG(&cc->otpprog)) & OTPP_START_BUSY) 198 for (k = 0; (st & OTPP_START_BUSY) && (k < OTPP_TRIES); k++)
196 && (k < OTPP_TRIES); k++) 199 st = bcma_read32(oi->core, CHIPCREGOFFS(otpprog));
197 ;
198 if (k >= OTPP_TRIES) 200 if (k >= OTPP_TRIES)
199 return; 201 return;
200 202
201 /* Read OTP lock bits and subregion programmed indication bits */ 203 /* Read OTP lock bits and subregion programmed indication bits */
202 oi->status = R_REG(&cc->otpstatus); 204 oi->status = bcma_read32(oi->core, CHIPCREGOFFS(otpstatus));
203 205
204 if ((ai_get_chip_id(oi->sih) == BCM43224_CHIP_ID) 206 if ((ai_get_chip_id(oi->sih) == BCM43224_CHIP_ID)
205 || (ai_get_chip_id(oi->sih) == BCM43225_CHIP_ID)) { 207 || (ai_get_chip_id(oi->sih) == BCM43225_CHIP_ID)) {
206 u32 p_bits; 208 u32 p_bits;
207 p_bits = 209 p_bits = (ipxotp_otpr(oi, oi->otpgu_base + OTPGU_P_OFF) &
208 (ipxotp_otpr(oi, cc, oi->otpgu_base + OTPGU_P_OFF) & 210 OTPGU_P_MSK) >> OTPGU_P_SHIFT;
209 OTPGU_P_MSK)
210 >> OTPGU_P_SHIFT;
211 oi->status |= (p_bits << OTPS_GUP_SHIFT); 211 oi->status |= (p_bits << OTPS_GUP_SHIFT);
212 } 212 }
213 213
@@ -220,7 +220,7 @@ static void _ipxotp_init(struct otpinfo *oi, struct chipcregs __iomem *cc)
220 oi->hwlim = oi->wsize; 220 oi->hwlim = oi->wsize;
221 if (oi->status & OTPS_GUP_HW) { 221 if (oi->status & OTPS_GUP_HW) {
222 oi->hwlim = 222 oi->hwlim =
223 ipxotp_otpr(oi, cc, oi->otpgu_base + OTPGU_HSB_OFF) / 16; 223 ipxotp_otpr(oi, oi->otpgu_base + OTPGU_HSB_OFF) / 16;
224 oi->swbase = oi->hwlim; 224 oi->swbase = oi->hwlim;
225 } else 225 } else
226 oi->swbase = oi->hwbase; 226 oi->swbase = oi->hwbase;
@@ -230,7 +230,7 @@ static void _ipxotp_init(struct otpinfo *oi, struct chipcregs __iomem *cc)
230 230
231 if (oi->status & OTPS_GUP_SW) { 231 if (oi->status & OTPS_GUP_SW) {
232 oi->swlim = 232 oi->swlim =
233 ipxotp_otpr(oi, cc, oi->otpgu_base + OTPGU_SFB_OFF) / 16; 233 ipxotp_otpr(oi, oi->otpgu_base + OTPGU_SFB_OFF) / 16;
234 oi->fbase = oi->swlim; 234 oi->fbase = oi->swlim;
235 } else 235 } else
236 oi->fbase = oi->swbase; 236 oi->fbase = oi->swbase;
@@ -240,11 +240,8 @@ static void _ipxotp_init(struct otpinfo *oi, struct chipcregs __iomem *cc)
240 240
241static int ipxotp_init(struct si_pub *sih, struct otpinfo *oi) 241static int ipxotp_init(struct si_pub *sih, struct otpinfo *oi)
242{ 242{
243 uint idx;
244 struct chipcregs __iomem *cc;
245
246 /* Make sure we're running IPX OTP */ 243 /* Make sure we're running IPX OTP */
247 if (!OTPTYPE_IPX(oi->ccrev)) 244 if (!OTPTYPE_IPX(ai_get_ccrev(sih)))
248 return -EBADE; 245 return -EBADE;
249 246
250 /* Make sure OTP is not disabled */ 247 /* Make sure OTP is not disabled */
@@ -282,21 +279,13 @@ static int ipxotp_init(struct si_pub *sih, struct otpinfo *oi)
282 } 279 }
283 280
284 /* Retrieve OTP region info */ 281 /* Retrieve OTP region info */
285 idx = ai_coreidx(sih); 282 _ipxotp_init(oi);
286 cc = ai_setcoreidx(sih, SI_CC_IDX);
287
288 _ipxotp_init(oi, cc);
289
290 ai_setcoreidx(sih, idx);
291
292 return 0; 283 return 0;
293} 284}
294 285
295static int 286static int
296ipxotp_read_region(struct otpinfo *oi, int region, u16 *data, uint *wlen) 287ipxotp_read_region(struct otpinfo *oi, int region, u16 *data, uint *wlen)
297{ 288{
298 uint idx;
299 struct chipcregs __iomem *cc;
300 uint base, i, sz; 289 uint base, i, sz;
301 290
302 /* Validate region selection */ 291 /* Validate region selection */
@@ -365,14 +354,10 @@ ipxotp_read_region(struct otpinfo *oi, int region, u16 *data, uint *wlen)
365 return -EINVAL; 354 return -EINVAL;
366 } 355 }
367 356
368 idx = ai_coreidx(oi->sih);
369 cc = ai_setcoreidx(oi->sih, SI_CC_IDX);
370
371 /* Read the data */ 357 /* Read the data */
372 for (i = 0; i < sz; i++) 358 for (i = 0; i < sz; i++)
373 data[i] = ipxotp_otpr(oi, cc, base + i); 359 data[i] = ipxotp_otpr(oi, base + i);
374 360
375 ai_setcoreidx(oi->sih, idx);
376 *wlen = sz; 361 *wlen = sz;
377 return 0; 362 return 0;
378} 363}
@@ -384,14 +369,13 @@ static const struct otp_fn_s ipxotp_fn = {
384 369
385static int otp_init(struct si_pub *sih, struct otpinfo *oi) 370static int otp_init(struct si_pub *sih, struct otpinfo *oi)
386{ 371{
387
388 int ret; 372 int ret;
389 373
390 memset(oi, 0, sizeof(struct otpinfo)); 374 memset(oi, 0, sizeof(struct otpinfo));
391 375
392 oi->ccrev = ai_get_ccrev(sih); 376 oi->core = ai_findcore(sih, BCMA_CORE_CHIPCOMMON, 0);
393 377
394 if (OTPTYPE_IPX(oi->ccrev)) 378 if (OTPTYPE_IPX(ai_get_ccrev(sih)))
395 oi->fn = &ipxotp_fn; 379 oi->fn = &ipxotp_fn;
396 380
397 if (oi->fn == NULL) 381 if (oi->fn == NULL)
@@ -399,7 +383,7 @@ static int otp_init(struct si_pub *sih, struct otpinfo *oi)
399 383
400 oi->sih = sih; 384 oi->sih = sih;
401 385
402 ret = (oi->fn->init) (sih, oi); 386 ret = (oi->fn->init)(sih, oi);
403 387
404 return ret; 388 return ret;
405} 389}
diff --git a/drivers/net/wireless/brcm80211/include/chipcommon.h b/drivers/net/wireless/brcm80211/include/chipcommon.h
index fefabc39e646..f96834a7c055 100644
--- a/drivers/net/wireless/brcm80211/include/chipcommon.h
+++ b/drivers/net/wireless/brcm80211/include/chipcommon.h
@@ -19,6 +19,8 @@
19 19
20#include "defs.h" /* for PAD macro */ 20#include "defs.h" /* for PAD macro */
21 21
22#define CHIPCREGOFFS(field) offsetof(struct chipcregs, field)
23
22struct chipcregs { 24struct chipcregs {
23 u32 chipid; /* 0x0 */ 25 u32 chipid; /* 0x0 */
24 u32 capabilities; 26 u32 capabilities;