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.
20 #include <linux/skbuff.h>
21 extern const uint brcmf_sdio_msglevel;
27 #define SDIOD_FBR_SIZE 0x100
30 #define SDIO_FUNC_ENABLE_1 0x02
31 #define SDIO_FUNC_ENABLE_2 0x04
34 #define SDIO_FUNC_READY_1 0x02
35 #define SDIO_FUNC_READY_2 0x04
38 #define INTR_STATUS_FUNC1 0x2
39 #define INTR_STATUS_FUNC2 0x4
41 /* Maximum number of I/O funcs */
42 #define SDIOD_MAX_IOFUNCS 7
44 #define SBSDIO_NUM_FUNCTION 3 /* as of sdiod rev 0, supports 3 functions */
46 /* function 1 miscellaneous registers */
47 #define SBSDIO_SPROM_CS 0x10000 /* sprom command and status */
48 #define SBSDIO_SPROM_INFO 0x10001 /* sprom info register */
49 #define SBSDIO_SPROM_DATA_LOW 0x10002 /* sprom indirect access data byte 0 */
50 #define SBSDIO_SPROM_DATA_HIGH 0x10003 /* sprom indirect access data byte 1 */
51 #define SBSDIO_SPROM_ADDR_LOW 0x10004 /* sprom indirect access addr byte 0 */
52 #define SBSDIO_SPROM_ADDR_HIGH 0x10005 /* sprom indirect access addr byte 0 */
53 #define SBSDIO_CHIP_CTRL_DATA 0x10006 /* xtal_pu (gpio) output */
54 #define SBSDIO_CHIP_CTRL_EN 0x10007 /* xtal_pu (gpio) enable */
55 #define SBSDIO_WATERMARK 0x10008 /* rev < 7, watermark for sdio device */
56 #define SBSDIO_DEVICE_CTL 0x10009 /* control busy signal generation */
58 /* registers introduced in rev 8, some content (mask/bits) defs in sbsdpcmdev.h */
59 #define SBSDIO_FUNC1_SBADDRLOW 0x1000A /* SB Address Window Low (b15) */
60 #define SBSDIO_FUNC1_SBADDRMID 0x1000B /* SB Address Window Mid (b23:b16) */
61 #define SBSDIO_FUNC1_SBADDRHIGH 0x1000C /* SB Address Window High (b31:b24) */
62 #define SBSDIO_FUNC1_FRAMECTRL 0x1000D /* Frame Control (frame term/abort) */
63 #define SBSDIO_FUNC1_CHIPCLKCSR 0x1000E /* ChipClockCSR (ALP/HT ctl/status) */
64 #define SBSDIO_FUNC1_SDIOPULLUP 0x1000F /* SdioPullUp (on cmd, d0-d2) */
65 #define SBSDIO_FUNC1_WFRAMEBCLO 0x10019 /* Write Frame Byte Count Low */
66 #define SBSDIO_FUNC1_WFRAMEBCHI 0x1001A /* Write Frame Byte Count High */
67 #define SBSDIO_FUNC1_RFRAMEBCLO 0x1001B /* Read Frame Byte Count Low */
68 #define SBSDIO_FUNC1_RFRAMEBCHI 0x1001C /* Read Frame Byte Count High */
70 #define SBSDIO_FUNC1_MISC_REG_START 0x10000 /* f1 misc register start */
71 #define SBSDIO_FUNC1_MISC_REG_LIMIT 0x1001C /* f1 misc register end */
73 /* function 1 OCP space */
74 #define SBSDIO_SB_OFT_ADDR_MASK 0x07FFF /* sb offset addr is <= 15 bits, 32k */
75 #define SBSDIO_SB_OFT_ADDR_LIMIT 0x08000
76 #define SBSDIO_SB_ACCESS_2_4B_FLAG 0x08000 /* with b15, maps to 32-bit SB access */
78 /* some duplication with sbsdpcmdev.h here */
79 /* valid bits in SBSDIO_FUNC1_SBADDRxxx regs */
80 #define SBSDIO_SBADDRLOW_MASK 0x80 /* Valid bits in SBADDRLOW */
81 #define SBSDIO_SBADDRMID_MASK 0xff /* Valid bits in SBADDRMID */
82 #define SBSDIO_SBADDRHIGH_MASK 0xffU /* Valid bits in SBADDRHIGH */
83 #define SBSDIO_SBWINDOW_MASK 0xffff8000 /* Address bits from SBADDR regs */
85 #define SDIOH_READ 0 /* Read request */
86 #define SDIOH_WRITE 1 /* Write request */
88 #define SDIOH_DATA_FIX 0 /* Fixed addressing */
89 #define SDIOH_DATA_INC 1 /* Incremental addressing */
91 /* internal return code */
95 /* forward declarations */
96 struct brcmf_sdio_card;
105 struct osl_info *osh; /* osh handler */
106 bool client_intr_enabled; /* interrupt connnected flag */
107 bool intr_handler_valid; /* client driver interrupt handler valid */
108 void (*intr_handler)(void *); /* registered interrupt handler */
109 void *intr_handler_arg; /* argument to call interrupt handler */
110 u16 intmask; /* Current active interrupts */
111 void *sdos_info; /* Pointer to per-OS private data */
113 uint irq; /* Client irq */
114 int intrcount; /* Client interrupts */
115 bool sd_blockmode; /* sd_blockmode == false => 64 Byte Cmd 53s. */
116 /* Must be on for sd_multiblock to be effective */
117 bool use_client_ints; /* If this is false, make sure to restore */
118 int client_block_size[SDIOD_MAX_IOFUNCS]; /* Blocksize */
119 u8 num_funcs; /* Supported funcs on client */
121 u32 func_cis_ptr[SDIOD_MAX_IOFUNCS];
123 uint max_dma_descriptors; /* DMA Descriptors supported by this controller. */
124 /* SDDMA_DESCRIPTOR SGList[32]; *//* Scatter/Gather DMA List */
127 struct brcmf_sdmmc_instance {
128 struct sdioh_info *sd;
129 struct sdio_func *func[SDIOD_MAX_IOFUNCS];
133 /* Attach and build an interface to the underlying SD host driver.
134 * - Allocates resources (structs, arrays, mem, OS handles, etc) needed by
136 * - Returns the sdio card handle and virtual address base for register access.
137 * The returned handle should be used in all subsequent calls, but the bcmsh
138 * implementation may maintain a single "default" handle (e.g. the first or
139 * most recent one) to enable single-instance implementations to pass NULL.
141 extern struct brcmf_sdio_card*
142 brcmf_sdcard_attach(void *cfghdl, u32 *regsva, uint irq);
144 /* Detach - freeup resources allocated in attach */
145 extern int brcmf_sdcard_detach(struct brcmf_sdio_card *card);
147 /* Enable/disable SD interrupt */
148 extern int brcmf_sdcard_intr_enable(struct brcmf_sdio_card *card);
149 extern int brcmf_sdcard_intr_disable(struct brcmf_sdio_card *card);
151 /* Register/deregister device interrupt handler. */
153 brcmf_sdcard_intr_reg(struct brcmf_sdio_card *card,
154 void (*fn)(void *), void *argh);
156 extern int brcmf_sdcard_intr_dereg(struct brcmf_sdio_card *card);
158 /* Access SDIO address space (e.g. CCCR) using CMD52 (single-byte interface).
159 * fn: function number
160 * addr: unmodified SDIO-space address
161 * data: data byte to write
162 * err: pointer to error code (or NULL)
164 extern u8 brcmf_sdcard_cfg_read(struct brcmf_sdio_card *card, uint func,
166 extern void brcmf_sdcard_cfg_write(struct brcmf_sdio_card *card, uint func,
167 u32 addr, u8 data, int *err);
169 /* Read/Write 4bytes from/to cfg space */
171 brcmf_sdcard_cfg_read_word(struct brcmf_sdio_card *card, uint fnc_num,
174 extern void brcmf_sdcard_cfg_write_word(struct brcmf_sdio_card *card,
175 uint fnc_num, u32 addr,
178 /* Read CIS content for specified function.
179 * fn: function whose CIS is being requested (0 is common CIS)
180 * cis: pointer to memory location to place results
181 * length: number of bytes to read
182 * Internally, this routine uses the values from the cis base regs (0x9-0xB)
183 * to form an SDIO-space address to read the data from.
185 extern int brcmf_sdcard_cis_read(struct brcmf_sdio_card *card, uint func,
186 u8 *cis, uint length);
188 /* Synchronous access to device (client) core registers via CMD53 to F1.
189 * addr: backplane address (i.e. >= regsva from attach)
190 * size: register width in bytes (2 or 4)
191 * data: data for register write
194 brcmf_sdcard_reg_read(struct brcmf_sdio_card *card, u32 addr, uint size);
197 brcmf_sdcard_reg_write(struct brcmf_sdio_card *card, u32 addr, uint size,
200 /* Indicate if last reg read/write failed */
201 extern bool brcmf_sdcard_regfail(struct brcmf_sdio_card *card);
203 /* Buffer transfer to/from device (client) core via cmd53.
204 * fn: function number
205 * addr: backplane address (i.e. >= regsva from attach)
206 * flags: backplane width, address increment, sync/async
207 * buf: pointer to memory data buffer
208 * nbytes: number of bytes to transfer to/from buf
209 * pkt: pointer to packet associated with buf (if any)
210 * complete: callback function for command completion (async only)
211 * handle: handle for completion callback (first arg in callback)
212 * Returns 0 or error code.
213 * NOTE: Async operation is not currently supported.
216 brcmf_sdcard_send_buf(struct brcmf_sdio_card *card, u32 addr, uint fn,
217 uint flags, u8 *buf, uint nbytes, void *pkt,
218 void (*complete)(void *handle, int status,
222 brcmf_sdcard_recv_buf(struct brcmf_sdio_card *card, u32 addr, uint fn,
223 uint flags, u8 *buf, uint nbytes, struct sk_buff *pkt,
224 void (*complete)(void *handle, int status,
229 #define SDIO_REQ_4BYTE 0x1 /* Four-byte target (backplane) width (vs. two-byte) */
230 #define SDIO_REQ_FIXED 0x2 /* Fixed address (FIFO) (vs. incrementing address) */
231 #define SDIO_REQ_ASYNC 0x4 /* Async request (vs. sync request) */
233 /* Pending (non-error) return code */
234 #define BCME_PENDING 1
236 /* Read/write to memory block (F1, no FIFO) via CMD53 (sync only).
237 * rw: read or write (0/1)
238 * addr: direct SDIO address
239 * buf: pointer to memory data buffer
240 * nbytes: number of bytes to transfer to/from buf
241 * Returns 0 or error code.
243 extern int brcmf_sdcard_rwdata(struct brcmf_sdio_card *card, uint rw, u32 addr,
244 u8 *buf, uint nbytes);
246 /* Issue an abort to the specified function */
247 extern int brcmf_sdcard_abort(struct brcmf_sdio_card *card, uint fn);
249 /* Returns the "Device ID" of target device on the SDIO bus. */
250 extern int brcmf_sdcard_query_device(struct brcmf_sdio_card *card);
252 /* Miscellaneous knob tweaker. */
253 extern int brcmf_sdcard_iovar_op(struct brcmf_sdio_card *card, const char *name,
254 void *params, int plen, void *arg, int len,
257 /* helper functions */
259 /* callback functions */
260 struct brcmf_sdioh_driver {
261 /* attach to device */
262 void *(*attach) (u16 vend_id, u16 dev_id, u16 bus, u16 slot,
263 u16 func, uint bustype, u32 regsva, void *param);
264 /* detach from device */
265 void (*detach) (void *ch);
270 /* platform specific/high level functions */
271 extern int brcmf_sdio_function_init(void);
272 extern int brcmf_sdio_register(struct brcmf_sdioh_driver *driver);
273 extern void brcmf_sdio_unregister(void);
274 extern void brcmf_sdio_function_cleanup(void);
275 extern int brcmf_sdio_probe(struct device *dev);
276 extern int brcmf_sdio_remove(struct device *dev);
278 /* Function to return current window addr */
279 extern u32 brcmf_sdcard_cur_sbwad(struct brcmf_sdio_card *card);
281 /* Allocate/init/free per-OS private data */
282 extern int brcmf_sdioh_osinit(struct sdioh_info *sd);
283 extern void brcmf_sdioh_osfree(struct sdioh_info *sd);
285 /* Core interrupt enable/disable of device interrupts */
286 extern void brcmf_sdioh_dev_intr_on(struct sdioh_info *sd);
287 extern void brcmf_sdioh_dev_intr_off(struct sdioh_info *sd);
289 /* attach, return handler on success, NULL if failed.
290 * The handler shall be provided by all subsequent calls. No local cache
291 * cfghdl points to the starting address of pci device mapped memory
293 extern struct sdioh_info *brcmf_sdioh_attach(void *cfghdl, uint irq);
294 extern int brcmf_sdioh_detach(struct sdioh_info *si);
297 brcmf_sdioh_interrupt_register(struct sdioh_info *si,
298 void (*sdioh_cb_fn)(void *), void *argh);
300 extern int brcmf_sdioh_interrupt_deregister(struct sdioh_info *si);
302 /* enable or disable SD interrupt */
304 brcmf_sdioh_interrupt_set(struct sdioh_info *si, bool enable_disable);
306 /* read or write one byte using cmd52 */
308 brcmf_sdioh_request_byte(struct sdioh_info *si, uint rw, uint fnc, uint addr,
311 /* read or write 2/4 bytes using cmd53 */
313 brcmf_sdioh_request_word(struct sdioh_info *si, uint cmd_type,
314 uint rw, uint fnc, uint addr,
315 u32 *word, uint nbyte);
317 /* read or write any buffer using cmd53 */
319 brcmf_sdioh_request_buffer(struct sdioh_info *si, uint pio_dma,
320 uint fix_inc, uint rw, uint fnc_num,
321 u32 addr, uint regwidth,
322 u32 buflen, u8 *buffer, struct sk_buff *pkt);
326 brcmf_sdioh_cis_read(struct sdioh_info *si, uint fuc, u8 *cis, u32 length);
329 brcmf_sdioh_cfg_read(struct sdioh_info *si, uint fuc, u32 addr, u8 *data);
331 brcmf_sdioh_cfg_write(struct sdioh_info *si, uint fuc, u32 addr, u8 *data);
334 extern int brcmf_sdioh_iovar_op(struct sdioh_info *si, const char *name,
335 void *params, int plen, void *arg, int len, bool set);
337 /* Issue abort to the specified function and clear controller as needed */
338 extern int brcmf_sdioh_abort(struct sdioh_info *si, uint fnc);
340 /* Watchdog timer interface for pm ops */
341 extern void brcmf_sdio_wdtmr_enable(bool enable);
343 extern uint sd_msglevel; /* Debug message level */
345 extern struct brcmf_sdmmc_instance *gInstance;
347 #endif /* _BRCM_SDH_H_ */