Commit 373c78e1 authored by Arend van Spriel's avatar Arend van Spriel Committed by John W. Linville

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: default avatarPieter-Paul Giesberts <pieterpg@broadcom.com>
Reviewed-by: default avatarAlwin Beukers <alwin@broadcom.com>
Signed-off-by: default avatarArend van Spriel <arend@broadcom.com>
Signed-off-by: default avatarFranky Lin <frankyl@broadcom.com>
Signed-off-by: default avatarJohn W. Linville <linville@tuxdriver.com>
parent d3126c52
...@@ -77,7 +77,7 @@ struct otp_fn_s { ...@@ -77,7 +77,7 @@ struct otp_fn_s {
}; };
struct otpinfo { struct otpinfo {
uint ccrev; /* chipc revision */ struct bcma_device *core; /* chipc core */
const struct otp_fn_s *fn; /* OTP functions */ const struct otp_fn_s *fn; /* OTP functions */
struct si_pub *sih; /* Saved sb handle */ struct si_pub *sih; /* Saved sb handle */
...@@ -133,9 +133,10 @@ struct otpinfo { ...@@ -133,9 +133,10 @@ struct otpinfo {
#define OTP_SZ_FU_144 (144/8) /* 144 bits */ #define OTP_SZ_FU_144 (144/8) /* 144 bits */
static u16 static u16
ipxotp_otpr(struct otpinfo *oi, struct chipcregs __iomem *cc, uint wn) ipxotp_otpr(struct otpinfo *oi, uint wn)
{ {
return R_REG(&cc->sromotp[wn]); return bcma_read16(oi->core,
CHIPCREGOFFS(sromotp[wn]));
} }
/* /*
...@@ -161,19 +162,21 @@ static int ipxotp_max_rgnsz(struct si_pub *sih, int osizew) ...@@ -161,19 +162,21 @@ static int ipxotp_max_rgnsz(struct si_pub *sih, int osizew)
return ret; return ret;
} }
static void _ipxotp_init(struct otpinfo *oi, struct chipcregs __iomem *cc) static void _ipxotp_init(struct otpinfo *oi)
{ {
uint k; uint k;
u32 otpp, st; u32 otpp, st;
int ccrev = ai_get_ccrev(oi->sih);
/* /*
* record word offset of General Use Region * record word offset of General Use Region
* for various chipcommon revs * for various chipcommon revs
*/ */
if (oi->ccrev == 21 || oi->ccrev == 24 if (ccrev == 21 || ccrev == 24
|| oi->ccrev == 27) { || ccrev == 27) {
oi->otpgu_base = REVA4_OTPGU_BASE; oi->otpgu_base = REVA4_OTPGU_BASE;
} else if (oi->ccrev == 36) { } else if (ccrev == 36) {
/* /*
* OTP size greater than equal to 2KB (128 words), * OTP size greater than equal to 2KB (128 words),
* otpgu_base is similar to rev23 * otpgu_base is similar to rev23
...@@ -182,7 +185,7 @@ static void _ipxotp_init(struct otpinfo *oi, struct chipcregs __iomem *cc) ...@@ -182,7 +185,7 @@ static void _ipxotp_init(struct otpinfo *oi, struct chipcregs __iomem *cc)
oi->otpgu_base = REVB8_OTPGU_BASE; oi->otpgu_base = REVB8_OTPGU_BASE;
else else
oi->otpgu_base = REV36_OTPGU_BASE; oi->otpgu_base = REV36_OTPGU_BASE;
} else if (oi->ccrev == 23 || oi->ccrev >= 25) { } else if (ccrev == 23 || ccrev >= 25) {
oi->otpgu_base = REVB8_OTPGU_BASE; oi->otpgu_base = REVB8_OTPGU_BASE;
} }
...@@ -190,24 +193,21 @@ static void _ipxotp_init(struct otpinfo *oi, struct chipcregs __iomem *cc) ...@@ -190,24 +193,21 @@ static void _ipxotp_init(struct otpinfo *oi, struct chipcregs __iomem *cc)
otpp = otpp =
OTPP_START_BUSY | ((OTPPOC_INIT << OTPP_OC_SHIFT) & OTPP_OC_MASK); OTPP_START_BUSY | ((OTPPOC_INIT << OTPP_OC_SHIFT) & OTPP_OC_MASK);
W_REG(&cc->otpprog, otpp); bcma_write32(oi->core, CHIPCREGOFFS(otpprog), otpp);
for (k = 0; st = bcma_read32(oi->core, CHIPCREGOFFS(otpprog));
((st = R_REG(&cc->otpprog)) & OTPP_START_BUSY) for (k = 0; (st & OTPP_START_BUSY) && (k < OTPP_TRIES); k++)
&& (k < OTPP_TRIES); k++) st = bcma_read32(oi->core, CHIPCREGOFFS(otpprog));
;
if (k >= OTPP_TRIES) if (k >= OTPP_TRIES)
return; return;
/* Read OTP lock bits and subregion programmed indication bits */ /* Read OTP lock bits and subregion programmed indication bits */
oi->status = R_REG(&cc->otpstatus); oi->status = bcma_read32(oi->core, CHIPCREGOFFS(otpstatus));
if ((ai_get_chip_id(oi->sih) == BCM43224_CHIP_ID) if ((ai_get_chip_id(oi->sih) == BCM43224_CHIP_ID)
|| (ai_get_chip_id(oi->sih) == BCM43225_CHIP_ID)) { || (ai_get_chip_id(oi->sih) == BCM43225_CHIP_ID)) {
u32 p_bits; u32 p_bits;
p_bits = p_bits = (ipxotp_otpr(oi, oi->otpgu_base + OTPGU_P_OFF) &
(ipxotp_otpr(oi, cc, oi->otpgu_base + OTPGU_P_OFF) & OTPGU_P_MSK) >> OTPGU_P_SHIFT;
OTPGU_P_MSK)
>> OTPGU_P_SHIFT;
oi->status |= (p_bits << OTPS_GUP_SHIFT); oi->status |= (p_bits << OTPS_GUP_SHIFT);
} }
...@@ -220,7 +220,7 @@ static void _ipxotp_init(struct otpinfo *oi, struct chipcregs __iomem *cc) ...@@ -220,7 +220,7 @@ static void _ipxotp_init(struct otpinfo *oi, struct chipcregs __iomem *cc)
oi->hwlim = oi->wsize; oi->hwlim = oi->wsize;
if (oi->status & OTPS_GUP_HW) { if (oi->status & OTPS_GUP_HW) {
oi->hwlim = oi->hwlim =
ipxotp_otpr(oi, cc, oi->otpgu_base + OTPGU_HSB_OFF) / 16; ipxotp_otpr(oi, oi->otpgu_base + OTPGU_HSB_OFF) / 16;
oi->swbase = oi->hwlim; oi->swbase = oi->hwlim;
} else } else
oi->swbase = oi->hwbase; oi->swbase = oi->hwbase;
...@@ -230,7 +230,7 @@ static void _ipxotp_init(struct otpinfo *oi, struct chipcregs __iomem *cc) ...@@ -230,7 +230,7 @@ static void _ipxotp_init(struct otpinfo *oi, struct chipcregs __iomem *cc)
if (oi->status & OTPS_GUP_SW) { if (oi->status & OTPS_GUP_SW) {
oi->swlim = oi->swlim =
ipxotp_otpr(oi, cc, oi->otpgu_base + OTPGU_SFB_OFF) / 16; ipxotp_otpr(oi, oi->otpgu_base + OTPGU_SFB_OFF) / 16;
oi->fbase = oi->swlim; oi->fbase = oi->swlim;
} else } else
oi->fbase = oi->swbase; oi->fbase = oi->swbase;
...@@ -240,11 +240,8 @@ static void _ipxotp_init(struct otpinfo *oi, struct chipcregs __iomem *cc) ...@@ -240,11 +240,8 @@ static void _ipxotp_init(struct otpinfo *oi, struct chipcregs __iomem *cc)
static int ipxotp_init(struct si_pub *sih, struct otpinfo *oi) static int ipxotp_init(struct si_pub *sih, struct otpinfo *oi)
{ {
uint idx;
struct chipcregs __iomem *cc;
/* Make sure we're running IPX OTP */ /* Make sure we're running IPX OTP */
if (!OTPTYPE_IPX(oi->ccrev)) if (!OTPTYPE_IPX(ai_get_ccrev(sih)))
return -EBADE; return -EBADE;
/* Make sure OTP is not disabled */ /* Make sure OTP is not disabled */
...@@ -282,21 +279,13 @@ static int ipxotp_init(struct si_pub *sih, struct otpinfo *oi) ...@@ -282,21 +279,13 @@ static int ipxotp_init(struct si_pub *sih, struct otpinfo *oi)
} }
/* Retrieve OTP region info */ /* Retrieve OTP region info */
idx = ai_coreidx(sih); _ipxotp_init(oi);
cc = ai_setcoreidx(sih, SI_CC_IDX);
_ipxotp_init(oi, cc);
ai_setcoreidx(sih, idx);
return 0; return 0;
} }
static int static int
ipxotp_read_region(struct otpinfo *oi, int region, u16 *data, uint *wlen) ipxotp_read_region(struct otpinfo *oi, int region, u16 *data, uint *wlen)
{ {
uint idx;
struct chipcregs __iomem *cc;
uint base, i, sz; uint base, i, sz;
/* Validate region selection */ /* Validate region selection */
...@@ -365,14 +354,10 @@ ipxotp_read_region(struct otpinfo *oi, int region, u16 *data, uint *wlen) ...@@ -365,14 +354,10 @@ ipxotp_read_region(struct otpinfo *oi, int region, u16 *data, uint *wlen)
return -EINVAL; return -EINVAL;
} }
idx = ai_coreidx(oi->sih);
cc = ai_setcoreidx(oi->sih, SI_CC_IDX);
/* Read the data */ /* Read the data */
for (i = 0; i < sz; i++) for (i = 0; i < sz; i++)
data[i] = ipxotp_otpr(oi, cc, base + i); data[i] = ipxotp_otpr(oi, base + i);
ai_setcoreidx(oi->sih, idx);
*wlen = sz; *wlen = sz;
return 0; return 0;
} }
...@@ -384,14 +369,13 @@ static const struct otp_fn_s ipxotp_fn = { ...@@ -384,14 +369,13 @@ static const struct otp_fn_s ipxotp_fn = {
static int otp_init(struct si_pub *sih, struct otpinfo *oi) static int otp_init(struct si_pub *sih, struct otpinfo *oi)
{ {
int ret; int ret;
memset(oi, 0, sizeof(struct otpinfo)); memset(oi, 0, sizeof(struct otpinfo));
oi->ccrev = ai_get_ccrev(sih); oi->core = ai_findcore(sih, BCMA_CORE_CHIPCOMMON, 0);
if (OTPTYPE_IPX(oi->ccrev)) if (OTPTYPE_IPX(ai_get_ccrev(sih)))
oi->fn = &ipxotp_fn; oi->fn = &ipxotp_fn;
if (oi->fn == NULL) if (oi->fn == NULL)
...@@ -399,7 +383,7 @@ static int otp_init(struct si_pub *sih, struct otpinfo *oi) ...@@ -399,7 +383,7 @@ static int otp_init(struct si_pub *sih, struct otpinfo *oi)
oi->sih = sih; oi->sih = sih;
ret = (oi->fn->init) (sih, oi); ret = (oi->fn->init)(sih, oi);
return ret; return ret;
} }
......
...@@ -19,6 +19,8 @@ ...@@ -19,6 +19,8 @@
#include "defs.h" /* for PAD macro */ #include "defs.h" /* for PAD macro */
#define CHIPCREGOFFS(field) offsetof(struct chipcregs, field)
struct chipcregs { struct chipcregs {
u32 chipid; /* 0x0 */ u32 chipid; /* 0x0 */
u32 capabilities; u32 capabilities;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment