blob: f8e1f1c84d08eb6837e013b4c85216a34d24d268 [file] [log] [blame]
Franky Lina83369b2011-11-04 22:23:28 +01001/*
2 * Copyright (c) 2011 Broadcom Corporation
3 *
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.
7 *
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.
15 */
16/* ***** SDIO interface chip backplane handle functions ***** */
17
Joe Perches02f77192012-01-15 00:38:44 -080018#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
19
Franky Lina83369b2011-11-04 22:23:28 +010020#include <linux/types.h>
21#include <linux/netdevice.h>
22#include <linux/mmc/card.h>
Franky Lin61213be2011-11-04 22:23:41 +010023#include <linux/ssb/ssb_regs.h>
Franky Lin99ba15c2011-11-04 22:23:42 +010024#include <linux/bcma/bcma.h>
Franky Lin61213be2011-11-04 22:23:41 +010025
Franky Lina83369b2011-11-04 22:23:28 +010026#include <chipcommon.h>
27#include <brcm_hw_ids.h>
28#include <brcmu_wifi.h>
29#include <brcmu_utils.h>
Franky Lin2d4a9af2011-11-04 22:23:31 +010030#include <soc.h>
Franky Lina83369b2011-11-04 22:23:28 +010031#include "dhd_dbg.h"
32#include "sdio_host.h"
33#include "sdio_chip.h"
34
35/* chip core base & ramsize */
36/* bcm4329 */
37/* SDIO device core, ID 0x829 */
38#define BCM4329_CORE_BUS_BASE 0x18011000
39/* internal memory core, ID 0x80e */
40#define BCM4329_CORE_SOCRAM_BASE 0x18003000
41/* ARM Cortex M3 core, ID 0x82a */
42#define BCM4329_CORE_ARM_BASE 0x18002000
43#define BCM4329_RAMSIZE 0x48000
44
Franky Lina83369b2011-11-04 22:23:28 +010045#define SBCOREREV(sbidh) \
Franky Lin61213be2011-11-04 22:23:41 +010046 ((((sbidh) & SSB_IDHIGH_RCHI) >> SSB_IDHIGH_RCHI_SHIFT) | \
47 ((sbidh) & SSB_IDHIGH_RCLO))
Franky Lina83369b2011-11-04 22:23:28 +010048
Franky Lin6ca687d2011-11-10 20:30:21 +010049/* SOC Interconnect types (aka chip types) */
50#define SOCI_SB 0
51#define SOCI_AI 1
52
Franky Lin523894f2011-11-10 20:30:22 +010053/* EROM CompIdentB */
54#define CIB_REV_MASK 0xff000000
55#define CIB_REV_SHIFT 24
56
Franky Line12afb62011-11-04 22:23:40 +010057#define SDIOD_DRVSTR_KEY(chip, pmu) (((chip) << 16) | (pmu))
58/* SDIO Pad drive strength to select value mappings */
59struct sdiod_drive_str {
60 u8 strength; /* Pad Drive Strength in mA */
61 u8 sel; /* Chip-specific select value */
62};
Franky Lince2d7d72011-12-08 15:06:39 -080063/* SDIO Drive Strength to sel value table for PMU Rev 11 (1.8V) */
Franky Linffb27562011-12-08 15:06:40 -080064static const struct sdiod_drive_str sdiod_drvstr_tab1_1v8[] = {
Franky Lince2d7d72011-12-08 15:06:39 -080065 {32, 0x6},
66 {26, 0x7},
67 {22, 0x4},
68 {16, 0x5},
69 {12, 0x2},
70 {8, 0x3},
71 {4, 0x0},
72 {0, 0x1}
73};
74
Franky Lin99ba15c2011-11-04 22:23:42 +010075u8
76brcmf_sdio_chip_getinfidx(struct chip_info *ci, u16 coreid)
77{
78 u8 idx;
79
80 for (idx = 0; idx < BRCMF_MAX_CORENUM; idx++)
81 if (coreid == ci->c_inf[idx].id)
82 return idx;
83
84 return BRCMF_MAX_CORENUM;
85}
86
Franky Lin454d2a82011-11-04 22:23:37 +010087static u32
Franky Lin523894f2011-11-10 20:30:22 +010088brcmf_sdio_sb_corerev(struct brcmf_sdio_dev *sdiodev,
89 struct chip_info *ci, u16 coreid)
Franky Lin454d2a82011-11-04 22:23:37 +010090{
91 u32 regdata;
Franky Lin523894f2011-11-10 20:30:22 +010092 u8 idx;
93
94 idx = brcmf_sdio_chip_getinfidx(ci, coreid);
Franky Lin454d2a82011-11-04 22:23:37 +010095
Franky Lin79ae3952012-05-04 18:27:34 -070096 regdata = brcmf_sdio_regrl(sdiodev,
97 CORE_SB(ci->c_inf[idx].base, sbidhigh),
98 NULL);
Franky Lin454d2a82011-11-04 22:23:37 +010099 return SBCOREREV(regdata);
100}
101
Franky Lin523894f2011-11-10 20:30:22 +0100102static u32
103brcmf_sdio_ai_corerev(struct brcmf_sdio_dev *sdiodev,
104 struct chip_info *ci, u16 coreid)
105{
106 u8 idx;
107
108 idx = brcmf_sdio_chip_getinfidx(ci, coreid);
109
110 return (ci->c_inf[idx].cib & CIB_REV_MASK) >> CIB_REV_SHIFT;
111}
112
Franky Lin6ca687d2011-11-10 20:30:21 +0100113static bool
114brcmf_sdio_sb_iscoreup(struct brcmf_sdio_dev *sdiodev,
115 struct chip_info *ci, u16 coreid)
Franky Lind8f64a42011-11-04 22:23:36 +0100116{
117 u32 regdata;
Franky Lin6ca687d2011-11-10 20:30:21 +0100118 u8 idx;
119
120 idx = brcmf_sdio_chip_getinfidx(ci, coreid);
Franky Lind8f64a42011-11-04 22:23:36 +0100121
Franky Lin79ae3952012-05-04 18:27:34 -0700122 regdata = brcmf_sdio_regrl(sdiodev,
123 CORE_SB(ci->c_inf[idx].base, sbtmstatelow),
124 NULL);
Franky Lin61213be2011-11-04 22:23:41 +0100125 regdata &= (SSB_TMSLOW_RESET | SSB_TMSLOW_REJECT |
126 SSB_IMSTATE_REJECT | SSB_TMSLOW_CLOCK);
127 return (SSB_TMSLOW_CLOCK == regdata);
Franky Lind8f64a42011-11-04 22:23:36 +0100128}
129
Franky Lin6ca687d2011-11-10 20:30:21 +0100130static bool
131brcmf_sdio_ai_iscoreup(struct brcmf_sdio_dev *sdiodev,
132 struct chip_info *ci, u16 coreid)
133{
134 u32 regdata;
135 u8 idx;
136 bool ret;
137
138 idx = brcmf_sdio_chip_getinfidx(ci, coreid);
139
Franky Lin79ae3952012-05-04 18:27:34 -0700140 regdata = brcmf_sdio_regrl(sdiodev, ci->c_inf[idx].wrapbase+BCMA_IOCTL,
141 NULL);
Franky Lin6ca687d2011-11-10 20:30:21 +0100142 ret = (regdata & (BCMA_IOCTL_FGC | BCMA_IOCTL_CLK)) == BCMA_IOCTL_CLK;
143
Franky Lin79ae3952012-05-04 18:27:34 -0700144 regdata = brcmf_sdio_regrl(sdiodev,
145 ci->c_inf[idx].wrapbase+BCMA_RESET_CTL,
146 NULL);
Franky Lin6ca687d2011-11-10 20:30:21 +0100147 ret = ret && ((regdata & BCMA_RESET_CTL_RESET) == 0);
148
149 return ret;
150}
151
Franky Lin086a2e02011-11-10 20:30:23 +0100152static void
153brcmf_sdio_sb_coredisable(struct brcmf_sdio_dev *sdiodev,
154 struct chip_info *ci, u16 coreid)
Franky Lin2d4a9af2011-11-04 22:23:31 +0100155{
Franky Lin79ae3952012-05-04 18:27:34 -0700156 u32 regdata, base;
Franky Lin086a2e02011-11-10 20:30:23 +0100157 u8 idx;
158
159 idx = brcmf_sdio_chip_getinfidx(ci, coreid);
Franky Lin79ae3952012-05-04 18:27:34 -0700160 base = ci->c_inf[idx].base;
Franky Lin2d4a9af2011-11-04 22:23:31 +0100161
Franky Lin79ae3952012-05-04 18:27:34 -0700162 regdata = brcmf_sdio_regrl(sdiodev, CORE_SB(base, sbtmstatelow), NULL);
Franky Lin61213be2011-11-04 22:23:41 +0100163 if (regdata & SSB_TMSLOW_RESET)
Franky Lin2d4a9af2011-11-04 22:23:31 +0100164 return;
165
Franky Lin79ae3952012-05-04 18:27:34 -0700166 regdata = brcmf_sdio_regrl(sdiodev, CORE_SB(base, sbtmstatelow), NULL);
Franky Lin61213be2011-11-04 22:23:41 +0100167 if ((regdata & SSB_TMSLOW_CLOCK) != 0) {
Franky Lin2d4a9af2011-11-04 22:23:31 +0100168 /*
169 * set target reject and spin until busy is clear
170 * (preserve core-specific bits)
171 */
Franky Lin79ae3952012-05-04 18:27:34 -0700172 regdata = brcmf_sdio_regrl(sdiodev, CORE_SB(base, sbtmstatelow),
173 NULL);
Franky Line13ce262012-05-04 18:27:35 -0700174 brcmf_sdio_regwl(sdiodev, CORE_SB(base, sbtmstatelow),
175 regdata | SSB_TMSLOW_REJECT, NULL);
Franky Lin2d4a9af2011-11-04 22:23:31 +0100176
Franky Lin79ae3952012-05-04 18:27:34 -0700177 regdata = brcmf_sdio_regrl(sdiodev, CORE_SB(base, sbtmstatelow),
178 NULL);
Franky Lin2d4a9af2011-11-04 22:23:31 +0100179 udelay(1);
Franky Lin79ae3952012-05-04 18:27:34 -0700180 SPINWAIT((brcmf_sdio_regrl(sdiodev,
181 CORE_SB(base, sbtmstatehigh),
182 NULL) &
Franky Lin61213be2011-11-04 22:23:41 +0100183 SSB_TMSHIGH_BUSY), 100000);
Franky Lin2d4a9af2011-11-04 22:23:31 +0100184
Franky Lin79ae3952012-05-04 18:27:34 -0700185 regdata = brcmf_sdio_regrl(sdiodev,
186 CORE_SB(base, sbtmstatehigh),
187 NULL);
Franky Lin61213be2011-11-04 22:23:41 +0100188 if (regdata & SSB_TMSHIGH_BUSY)
Franky Lin2d4a9af2011-11-04 22:23:31 +0100189 brcmf_dbg(ERROR, "core state still busy\n");
190
Franky Lin79ae3952012-05-04 18:27:34 -0700191 regdata = brcmf_sdio_regrl(sdiodev, CORE_SB(base, sbidlow),
192 NULL);
Franky Lin61213be2011-11-04 22:23:41 +0100193 if (regdata & SSB_IDLOW_INITIATOR) {
Franky Lin79ae3952012-05-04 18:27:34 -0700194 regdata = brcmf_sdio_regrl(sdiodev,
195 CORE_SB(base, sbimstate),
196 NULL);
197 regdata |= SSB_IMSTATE_REJECT;
Franky Line13ce262012-05-04 18:27:35 -0700198 brcmf_sdio_regwl(sdiodev, CORE_SB(base, sbimstate),
199 regdata, NULL);
Franky Lin79ae3952012-05-04 18:27:34 -0700200 regdata = brcmf_sdio_regrl(sdiodev,
201 CORE_SB(base, sbimstate),
202 NULL);
Franky Lin2d4a9af2011-11-04 22:23:31 +0100203 udelay(1);
Franky Lin79ae3952012-05-04 18:27:34 -0700204 SPINWAIT((brcmf_sdio_regrl(sdiodev,
205 CORE_SB(base, sbimstate),
206 NULL) &
Franky Lin61213be2011-11-04 22:23:41 +0100207 SSB_IMSTATE_BUSY), 100000);
Franky Lin2d4a9af2011-11-04 22:23:31 +0100208 }
209
210 /* set reset and reject while enabling the clocks */
Franky Line13ce262012-05-04 18:27:35 -0700211 regdata = SSB_TMSLOW_FGC | SSB_TMSLOW_CLOCK |
212 SSB_TMSLOW_REJECT | SSB_TMSLOW_RESET;
213 brcmf_sdio_regwl(sdiodev, CORE_SB(base, sbtmstatelow),
214 regdata, NULL);
Franky Lin79ae3952012-05-04 18:27:34 -0700215 regdata = brcmf_sdio_regrl(sdiodev, CORE_SB(base, sbtmstatelow),
216 NULL);
Franky Lin2d4a9af2011-11-04 22:23:31 +0100217 udelay(10);
218
219 /* clear the initiator reject bit */
Franky Lin79ae3952012-05-04 18:27:34 -0700220 regdata = brcmf_sdio_regrl(sdiodev, CORE_SB(base, sbidlow),
221 NULL);
Franky Lin61213be2011-11-04 22:23:41 +0100222 if (regdata & SSB_IDLOW_INITIATOR) {
Franky Lin79ae3952012-05-04 18:27:34 -0700223 regdata = brcmf_sdio_regrl(sdiodev,
224 CORE_SB(base, sbimstate),
225 NULL);
226 regdata &= ~SSB_IMSTATE_REJECT;
Franky Line13ce262012-05-04 18:27:35 -0700227 brcmf_sdio_regwl(sdiodev, CORE_SB(base, sbimstate),
228 regdata, NULL);
Franky Lin2d4a9af2011-11-04 22:23:31 +0100229 }
230 }
231
232 /* leave reset and reject asserted */
Franky Line13ce262012-05-04 18:27:35 -0700233 brcmf_sdio_regwl(sdiodev, CORE_SB(base, sbtmstatelow),
234 (SSB_TMSLOW_REJECT | SSB_TMSLOW_RESET), NULL);
Franky Lin2d4a9af2011-11-04 22:23:31 +0100235 udelay(1);
236}
237
Franky Lin086a2e02011-11-10 20:30:23 +0100238static void
239brcmf_sdio_ai_coredisable(struct brcmf_sdio_dev *sdiodev,
240 struct chip_info *ci, u16 coreid)
241{
242 u8 idx;
243 u32 regdata;
244
245 idx = brcmf_sdio_chip_getinfidx(ci, coreid);
246
247 /* if core is already in reset, just return */
Franky Lin79ae3952012-05-04 18:27:34 -0700248 regdata = brcmf_sdio_regrl(sdiodev,
249 ci->c_inf[idx].wrapbase+BCMA_RESET_CTL,
250 NULL);
Franky Lin086a2e02011-11-10 20:30:23 +0100251 if ((regdata & BCMA_RESET_CTL_RESET) != 0)
252 return;
253
Franky Line13ce262012-05-04 18:27:35 -0700254 brcmf_sdio_regwl(sdiodev, ci->c_inf[idx].wrapbase+BCMA_IOCTL, 0, NULL);
Franky Lin79ae3952012-05-04 18:27:34 -0700255 regdata = brcmf_sdio_regrl(sdiodev, ci->c_inf[idx].wrapbase+BCMA_IOCTL,
256 NULL);
Franky Lin086a2e02011-11-10 20:30:23 +0100257 udelay(10);
258
Franky Line13ce262012-05-04 18:27:35 -0700259 brcmf_sdio_regwl(sdiodev, ci->c_inf[idx].wrapbase+BCMA_RESET_CTL,
260 BCMA_RESET_CTL_RESET, NULL);
Franky Lin086a2e02011-11-10 20:30:23 +0100261 udelay(1);
262}
263
Franky Lind77e70f2011-11-10 20:30:24 +0100264static void
265brcmf_sdio_sb_resetcore(struct brcmf_sdio_dev *sdiodev,
266 struct chip_info *ci, u16 coreid)
Franky Lin2bc78e12011-11-04 22:23:38 +0100267{
268 u32 regdata;
Franky Lin086a2e02011-11-10 20:30:23 +0100269 u8 idx;
270
271 idx = brcmf_sdio_chip_getinfidx(ci, coreid);
Franky Lin2bc78e12011-11-04 22:23:38 +0100272
273 /*
274 * Must do the disable sequence first to work for
275 * arbitrary current core state.
276 */
Franky Lind77e70f2011-11-10 20:30:24 +0100277 brcmf_sdio_sb_coredisable(sdiodev, ci, coreid);
Franky Lin2bc78e12011-11-04 22:23:38 +0100278
279 /*
280 * Now do the initialization sequence.
281 * set reset while enabling the clock and
282 * forcing them on throughout the core
283 */
Franky Line13ce262012-05-04 18:27:35 -0700284 brcmf_sdio_regwl(sdiodev,
285 CORE_SB(ci->c_inf[idx].base, sbtmstatelow),
286 SSB_TMSLOW_FGC | SSB_TMSLOW_CLOCK | SSB_TMSLOW_RESET,
287 NULL);
Franky Lin79ae3952012-05-04 18:27:34 -0700288 regdata = brcmf_sdio_regrl(sdiodev,
289 CORE_SB(ci->c_inf[idx].base, sbtmstatelow),
290 NULL);
Franky Lin2bc78e12011-11-04 22:23:38 +0100291 udelay(1);
292
Franky Lind77e70f2011-11-10 20:30:24 +0100293 /* clear any serror */
Franky Lin79ae3952012-05-04 18:27:34 -0700294 regdata = brcmf_sdio_regrl(sdiodev,
295 CORE_SB(ci->c_inf[idx].base, sbtmstatehigh),
296 NULL);
Franky Lin61213be2011-11-04 22:23:41 +0100297 if (regdata & SSB_TMSHIGH_SERR)
Franky Line13ce262012-05-04 18:27:35 -0700298 brcmf_sdio_regwl(sdiodev,
299 CORE_SB(ci->c_inf[idx].base, sbtmstatehigh),
300 0, NULL);
Franky Lin2bc78e12011-11-04 22:23:38 +0100301
Franky Lin79ae3952012-05-04 18:27:34 -0700302 regdata = brcmf_sdio_regrl(sdiodev,
303 CORE_SB(ci->c_inf[idx].base, sbimstate),
304 NULL);
Franky Lin61213be2011-11-04 22:23:41 +0100305 if (regdata & (SSB_IMSTATE_IBE | SSB_IMSTATE_TO))
Franky Line13ce262012-05-04 18:27:35 -0700306 brcmf_sdio_regwl(sdiodev,
307 CORE_SB(ci->c_inf[idx].base, sbimstate),
308 regdata & ~(SSB_IMSTATE_IBE | SSB_IMSTATE_TO),
309 NULL);
Franky Lin2bc78e12011-11-04 22:23:38 +0100310
311 /* clear reset and allow it to propagate throughout the core */
Franky Line13ce262012-05-04 18:27:35 -0700312 brcmf_sdio_regwl(sdiodev, CORE_SB(ci->c_inf[idx].base, sbtmstatelow),
313 SSB_TMSLOW_FGC | SSB_TMSLOW_CLOCK, NULL);
Franky Lin79ae3952012-05-04 18:27:34 -0700314 regdata = brcmf_sdio_regrl(sdiodev,
315 CORE_SB(ci->c_inf[idx].base, sbtmstatelow),
316 NULL);
Franky Lin2bc78e12011-11-04 22:23:38 +0100317 udelay(1);
318
319 /* leave clock enabled */
Franky Line13ce262012-05-04 18:27:35 -0700320 brcmf_sdio_regwl(sdiodev, CORE_SB(ci->c_inf[idx].base, sbtmstatelow),
321 SSB_TMSLOW_CLOCK, NULL);
Franky Lin79ae3952012-05-04 18:27:34 -0700322 regdata = brcmf_sdio_regrl(sdiodev,
323 CORE_SB(ci->c_inf[idx].base, sbtmstatelow),
324 NULL);
Franky Lind77e70f2011-11-10 20:30:24 +0100325 udelay(1);
326}
327
328static void
329brcmf_sdio_ai_resetcore(struct brcmf_sdio_dev *sdiodev,
330 struct chip_info *ci, u16 coreid)
331{
332 u8 idx;
333 u32 regdata;
334
335 idx = brcmf_sdio_chip_getinfidx(ci, coreid);
336
337 /* must disable first to work for arbitrary current core state */
338 brcmf_sdio_ai_coredisable(sdiodev, ci, coreid);
339
340 /* now do initialization sequence */
Franky Line13ce262012-05-04 18:27:35 -0700341 brcmf_sdio_regwl(sdiodev, ci->c_inf[idx].wrapbase+BCMA_IOCTL,
342 BCMA_IOCTL_FGC | BCMA_IOCTL_CLK, NULL);
Franky Lin79ae3952012-05-04 18:27:34 -0700343 regdata = brcmf_sdio_regrl(sdiodev, ci->c_inf[idx].wrapbase+BCMA_IOCTL,
344 NULL);
Franky Line13ce262012-05-04 18:27:35 -0700345 brcmf_sdio_regwl(sdiodev, ci->c_inf[idx].wrapbase+BCMA_RESET_CTL,
346 0, NULL);
Franky Lind77e70f2011-11-10 20:30:24 +0100347 udelay(1);
348
Franky Line13ce262012-05-04 18:27:35 -0700349 brcmf_sdio_regwl(sdiodev, ci->c_inf[idx].wrapbase+BCMA_IOCTL,
350 BCMA_IOCTL_CLK, NULL);
Franky Lin79ae3952012-05-04 18:27:34 -0700351 regdata = brcmf_sdio_regrl(sdiodev, ci->c_inf[idx].wrapbase+BCMA_IOCTL,
352 NULL);
Franky Lin2bc78e12011-11-04 22:23:38 +0100353 udelay(1);
354}
355
Franky Lina83369b2011-11-04 22:23:28 +0100356static int brcmf_sdio_chip_recognition(struct brcmf_sdio_dev *sdiodev,
357 struct chip_info *ci, u32 regs)
358{
359 u32 regdata;
360
361 /*
362 * Get CC core rev
363 * Chipid is assume to be at offset 0 from regs arg
364 * For different chiptypes or old sdio hosts w/o chipcommon,
365 * other ways of recognition should be added here.
366 */
Franky Lin99ba15c2011-11-04 22:23:42 +0100367 ci->c_inf[0].id = BCMA_CORE_CHIPCOMMON;
368 ci->c_inf[0].base = regs;
Franky Lin79ae3952012-05-04 18:27:34 -0700369 regdata = brcmf_sdio_regrl(sdiodev,
370 CORE_CC_REG(ci->c_inf[0].base, chipid),
371 NULL);
Franky Lina83369b2011-11-04 22:23:28 +0100372 ci->chip = regdata & CID_ID_MASK;
373 ci->chiprev = (regdata & CID_REV_MASK) >> CID_REV_SHIFT;
Franky Lin6ca687d2011-11-10 20:30:21 +0100374 ci->socitype = (regdata & CID_TYPE_MASK) >> CID_TYPE_SHIFT;
Franky Lina83369b2011-11-04 22:23:28 +0100375
376 brcmf_dbg(INFO, "chipid=0x%x chiprev=%d\n", ci->chip, ci->chiprev);
377
378 /* Address of cores for new chips should be added here */
379 switch (ci->chip) {
380 case BCM4329_CHIP_ID:
Franky Lin99ba15c2011-11-04 22:23:42 +0100381 ci->c_inf[1].id = BCMA_CORE_SDIO_DEV;
382 ci->c_inf[1].base = BCM4329_CORE_BUS_BASE;
383 ci->c_inf[2].id = BCMA_CORE_INTERNAL_MEM;
384 ci->c_inf[2].base = BCM4329_CORE_SOCRAM_BASE;
385 ci->c_inf[3].id = BCMA_CORE_ARM_CM3;
386 ci->c_inf[3].base = BCM4329_CORE_ARM_BASE;
Franky Lina83369b2011-11-04 22:23:28 +0100387 ci->ramsize = BCM4329_RAMSIZE;
388 break;
Franky Lince2d7d72011-12-08 15:06:39 -0800389 case BCM4330_CHIP_ID:
390 ci->c_inf[0].wrapbase = 0x18100000;
391 ci->c_inf[0].cib = 0x27004211;
392 ci->c_inf[1].id = BCMA_CORE_SDIO_DEV;
393 ci->c_inf[1].base = 0x18002000;
394 ci->c_inf[1].wrapbase = 0x18102000;
395 ci->c_inf[1].cib = 0x07004211;
396 ci->c_inf[2].id = BCMA_CORE_INTERNAL_MEM;
397 ci->c_inf[2].base = 0x18004000;
398 ci->c_inf[2].wrapbase = 0x18104000;
399 ci->c_inf[2].cib = 0x0d080401;
400 ci->c_inf[3].id = BCMA_CORE_ARM_CM3;
401 ci->c_inf[3].base = 0x18003000;
402 ci->c_inf[3].wrapbase = 0x18103000;
403 ci->c_inf[3].cib = 0x03004211;
404 ci->ramsize = 0x48000;
405 break;
Franky Lina83369b2011-11-04 22:23:28 +0100406 default:
407 brcmf_dbg(ERROR, "chipid 0x%x is not supported\n", ci->chip);
408 return -ENODEV;
409 }
410
Franky Lin6ca687d2011-11-10 20:30:21 +0100411 switch (ci->socitype) {
412 case SOCI_SB:
413 ci->iscoreup = brcmf_sdio_sb_iscoreup;
Franky Lin523894f2011-11-10 20:30:22 +0100414 ci->corerev = brcmf_sdio_sb_corerev;
Franky Lin086a2e02011-11-10 20:30:23 +0100415 ci->coredisable = brcmf_sdio_sb_coredisable;
Franky Lind77e70f2011-11-10 20:30:24 +0100416 ci->resetcore = brcmf_sdio_sb_resetcore;
Franky Lin6ca687d2011-11-10 20:30:21 +0100417 break;
418 case SOCI_AI:
419 ci->iscoreup = brcmf_sdio_ai_iscoreup;
Franky Lin523894f2011-11-10 20:30:22 +0100420 ci->corerev = brcmf_sdio_ai_corerev;
Franky Lin086a2e02011-11-10 20:30:23 +0100421 ci->coredisable = brcmf_sdio_ai_coredisable;
Franky Lind77e70f2011-11-10 20:30:24 +0100422 ci->resetcore = brcmf_sdio_ai_resetcore;
Franky Lin6ca687d2011-11-10 20:30:21 +0100423 break;
424 default:
425 brcmf_dbg(ERROR, "socitype %u not supported\n", ci->socitype);
426 return -ENODEV;
427 }
428
Franky Lina83369b2011-11-04 22:23:28 +0100429 return 0;
430}
431
Franky Line63ac6b2011-11-04 22:23:29 +0100432static int
433brcmf_sdio_chip_buscoreprep(struct brcmf_sdio_dev *sdiodev)
434{
435 int err = 0;
436 u8 clkval, clkset;
437
438 /* Try forcing SDIO core to do ALPAvail request only */
439 clkset = SBSDIO_FORCE_HW_CLKREQ_OFF | SBSDIO_ALP_AVAIL_REQ;
Franky Lin3bba8292012-05-04 18:27:33 -0700440 brcmf_sdio_regwb(sdiodev, SBSDIO_FUNC1_CHIPCLKCSR, clkset, &err);
Franky Line63ac6b2011-11-04 22:23:29 +0100441 if (err) {
442 brcmf_dbg(ERROR, "error writing for HT off\n");
443 return err;
444 }
445
446 /* If register supported, wait for ALPAvail and then force ALP */
447 /* This may take up to 15 milliseconds */
Franky Lin45db3392012-05-04 18:27:32 -0700448 clkval = brcmf_sdio_regrb(sdiodev,
449 SBSDIO_FUNC1_CHIPCLKCSR, NULL);
Franky Line63ac6b2011-11-04 22:23:29 +0100450
451 if ((clkval & ~SBSDIO_AVBITS) != clkset) {
452 brcmf_dbg(ERROR, "ChipClkCSR access: wrote 0x%02x read 0x%02x\n",
453 clkset, clkval);
454 return -EACCES;
455 }
456
Franky Lin45db3392012-05-04 18:27:32 -0700457 SPINWAIT(((clkval = brcmf_sdio_regrb(sdiodev,
458 SBSDIO_FUNC1_CHIPCLKCSR, NULL)),
Franky Line63ac6b2011-11-04 22:23:29 +0100459 !SBSDIO_ALPAV(clkval)),
460 PMU_MAX_TRANSITION_DLY);
461 if (!SBSDIO_ALPAV(clkval)) {
462 brcmf_dbg(ERROR, "timeout on ALPAV wait, clkval 0x%02x\n",
463 clkval);
464 return -EBUSY;
465 }
466
467 clkset = SBSDIO_FORCE_HW_CLKREQ_OFF | SBSDIO_FORCE_ALP;
Franky Lin3bba8292012-05-04 18:27:33 -0700468 brcmf_sdio_regwb(sdiodev, SBSDIO_FUNC1_CHIPCLKCSR, clkset, &err);
Franky Line63ac6b2011-11-04 22:23:29 +0100469 udelay(65);
470
471 /* Also, disable the extra SDIO pull-ups */
Franky Lin3bba8292012-05-04 18:27:33 -0700472 brcmf_sdio_regwb(sdiodev, SBSDIO_FUNC1_SDIOPULLUP, 0, NULL);
Franky Line63ac6b2011-11-04 22:23:29 +0100473
474 return 0;
475}
476
Franky Lin5b45e542011-11-04 22:23:30 +0100477static void
478brcmf_sdio_chip_buscoresetup(struct brcmf_sdio_dev *sdiodev,
479 struct chip_info *ci)
480{
Franky Lin79ae3952012-05-04 18:27:34 -0700481 u32 base = ci->c_inf[0].base;
482
Franky Lin5b45e542011-11-04 22:23:30 +0100483 /* get chipcommon rev */
Franky Lin523894f2011-11-10 20:30:22 +0100484 ci->c_inf[0].rev = ci->corerev(sdiodev, ci, ci->c_inf[0].id);
Franky Lin5b45e542011-11-04 22:23:30 +0100485
486 /* get chipcommon capabilites */
Franky Lin79ae3952012-05-04 18:27:34 -0700487 ci->c_inf[0].caps = brcmf_sdio_regrl(sdiodev,
488 CORE_CC_REG(base, capabilities),
489 NULL);
Franky Lin5b45e542011-11-04 22:23:30 +0100490
491 /* get pmu caps & rev */
Franky Lin99ba15c2011-11-04 22:23:42 +0100492 if (ci->c_inf[0].caps & CC_CAP_PMU) {
Franky Lin79ae3952012-05-04 18:27:34 -0700493 ci->pmucaps =
494 brcmf_sdio_regrl(sdiodev,
495 CORE_CC_REG(base, pmucapabilities),
496 NULL);
Franky Lin5b45e542011-11-04 22:23:30 +0100497 ci->pmurev = ci->pmucaps & PCAP_REV_MASK;
498 }
499
Franky Lin523894f2011-11-10 20:30:22 +0100500 ci->c_inf[1].rev = ci->corerev(sdiodev, ci, ci->c_inf[1].id);
Franky Lin5b45e542011-11-04 22:23:30 +0100501
502 brcmf_dbg(INFO, "ccrev=%d, pmurev=%d, buscore rev/type=%d/0x%x\n",
Franky Lin99ba15c2011-11-04 22:23:42 +0100503 ci->c_inf[0].rev, ci->pmurev,
504 ci->c_inf[1].rev, ci->c_inf[1].id);
Franky Lin966414d2011-11-04 22:23:32 +0100505
506 /*
507 * Make sure any on-chip ARM is off (in case strapping is wrong),
508 * or downloaded code was already running.
509 */
Franky Lin086a2e02011-11-10 20:30:23 +0100510 ci->coredisable(sdiodev, ci, BCMA_CORE_ARM_CM3);
Franky Lin5b45e542011-11-04 22:23:30 +0100511}
512
Franky Lina83369b2011-11-04 22:23:28 +0100513int brcmf_sdio_chip_attach(struct brcmf_sdio_dev *sdiodev,
Franky Lina97e4fc2011-11-04 22:23:35 +0100514 struct chip_info **ci_ptr, u32 regs)
Franky Lina83369b2011-11-04 22:23:28 +0100515{
Franky Lina97e4fc2011-11-04 22:23:35 +0100516 int ret;
517 struct chip_info *ci;
518
519 brcmf_dbg(TRACE, "Enter\n");
520
521 /* alloc chip_info_t */
522 ci = kzalloc(sizeof(struct chip_info), GFP_ATOMIC);
523 if (!ci)
524 return -ENOMEM;
Franky Lina83369b2011-11-04 22:23:28 +0100525
Franky Line63ac6b2011-11-04 22:23:29 +0100526 ret = brcmf_sdio_chip_buscoreprep(sdiodev);
527 if (ret != 0)
Franky Lina97e4fc2011-11-04 22:23:35 +0100528 goto err;
Franky Line63ac6b2011-11-04 22:23:29 +0100529
Franky Lina83369b2011-11-04 22:23:28 +0100530 ret = brcmf_sdio_chip_recognition(sdiodev, ci, regs);
531 if (ret != 0)
Franky Lina97e4fc2011-11-04 22:23:35 +0100532 goto err;
Franky Lina83369b2011-11-04 22:23:28 +0100533
Franky Lin5b45e542011-11-04 22:23:30 +0100534 brcmf_sdio_chip_buscoresetup(sdiodev, ci);
535
Franky Line13ce262012-05-04 18:27:35 -0700536 brcmf_sdio_regwl(sdiodev, CORE_CC_REG(ci->c_inf[0].base, gpiopullup),
537 0, NULL);
538 brcmf_sdio_regwl(sdiodev, CORE_CC_REG(ci->c_inf[0].base, gpiopulldown),
539 0, NULL);
Franky Lin960908d2011-11-04 22:23:33 +0100540
Franky Lina97e4fc2011-11-04 22:23:35 +0100541 *ci_ptr = ci;
542 return 0;
543
544err:
545 kfree(ci);
Franky Lina83369b2011-11-04 22:23:28 +0100546 return ret;
547}
Franky Lina8a6c042011-11-04 22:23:39 +0100548
549void
550brcmf_sdio_chip_detach(struct chip_info **ci_ptr)
551{
552 brcmf_dbg(TRACE, "Enter\n");
553
554 kfree(*ci_ptr);
555 *ci_ptr = NULL;
556}
Franky Line12afb62011-11-04 22:23:40 +0100557
558static char *brcmf_sdio_chip_name(uint chipid, char *buf, uint len)
559{
560 const char *fmt;
561
562 fmt = ((chipid > 0xa000) || (chipid < 0x4000)) ? "%d" : "%x";
563 snprintf(buf, len, fmt, chipid);
564 return buf;
565}
566
567void
568brcmf_sdio_chip_drivestrengthinit(struct brcmf_sdio_dev *sdiodev,
569 struct chip_info *ci, u32 drivestrength)
570{
571 struct sdiod_drive_str *str_tab = NULL;
572 u32 str_mask = 0;
573 u32 str_shift = 0;
574 char chn[8];
Franky Lin79ae3952012-05-04 18:27:34 -0700575 u32 base = ci->c_inf[0].base;
Franky Line12afb62011-11-04 22:23:40 +0100576
Franky Lin99ba15c2011-11-04 22:23:42 +0100577 if (!(ci->c_inf[0].caps & CC_CAP_PMU))
Franky Line12afb62011-11-04 22:23:40 +0100578 return;
579
580 switch (SDIOD_DRVSTR_KEY(ci->chip, ci->pmurev)) {
Franky Lince2d7d72011-12-08 15:06:39 -0800581 case SDIOD_DRVSTR_KEY(BCM4330_CHIP_ID, 12):
Franky Linffb27562011-12-08 15:06:40 -0800582 str_tab = (struct sdiod_drive_str *)&sdiod_drvstr_tab1_1v8;
Franky Lince2d7d72011-12-08 15:06:39 -0800583 str_mask = 0x00003800;
584 str_shift = 11;
585 break;
Franky Line12afb62011-11-04 22:23:40 +0100586 default:
587 brcmf_dbg(ERROR, "No SDIO Drive strength init done for chip %s rev %d pmurev %d\n",
588 brcmf_sdio_chip_name(ci->chip, chn, 8),
589 ci->chiprev, ci->pmurev);
590 break;
591 }
592
593 if (str_tab != NULL) {
594 u32 drivestrength_sel = 0;
595 u32 cc_data_temp;
596 int i;
597
598 for (i = 0; str_tab[i].strength != 0; i++) {
599 if (drivestrength >= str_tab[i].strength) {
600 drivestrength_sel = str_tab[i].sel;
601 break;
602 }
603 }
604
Franky Line13ce262012-05-04 18:27:35 -0700605 brcmf_sdio_regwl(sdiodev, CORE_CC_REG(base, chipcontrol_addr),
606 1, NULL);
Franky Lin79ae3952012-05-04 18:27:34 -0700607 cc_data_temp =
608 brcmf_sdio_regrl(sdiodev,
609 CORE_CC_REG(base, chipcontrol_addr),
610 NULL);
Franky Line12afb62011-11-04 22:23:40 +0100611 cc_data_temp &= ~str_mask;
612 drivestrength_sel <<= str_shift;
613 cc_data_temp |= drivestrength_sel;
Franky Line13ce262012-05-04 18:27:35 -0700614 brcmf_sdio_regwl(sdiodev, CORE_CC_REG(base, chipcontrol_addr),
615 cc_data_temp, NULL);
Franky Line12afb62011-11-04 22:23:40 +0100616
617 brcmf_dbg(INFO, "SDIO: %dmA drive strength selected, set to 0x%08x\n",
618 drivestrength, cc_data_temp);
619 }
620}