blob: 3b57dc13b1ded3f726d154ad81620040dd53cffa [file] [log] [blame]
Henry Ptasinskia9533e72010-09-08 21:04:42 -07001/*
2 * Copyright (c) 2010 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
17#ifndef _bcmsdh_h_
18#define _bcmsdh_h_
19
Arend van Sprielf8559b6922011-01-21 10:54:48 +010020#include <linux/skbuff.h>
Henry Ptasinskia9533e72010-09-08 21:04:42 -070021#define BCMSDH_ERROR_VAL 0x0001 /* Error */
22#define BCMSDH_INFO_VAL 0x0002 /* Info */
23extern const uint bcmsdh_msglevel;
24
25#ifdef BCMDBG
Arend van Spriel0bef7742011-02-10 12:03:44 +010026#define BCMSDH_ERROR(x) \
27 do { \
28 if ((bcmsdh_msglevel & BCMSDH_ERROR_VAL) && net_ratelimit()) \
29 printk x; \
30 } while (0)
31#define BCMSDH_INFO(x) \
32 do { \
33 if ((bcmsdh_msglevel & BCMSDH_INFO_VAL) && net_ratelimit()) \
34 printk x; \
35 } while (0)
Henry Ptasinskia9533e72010-09-08 21:04:42 -070036#else /* BCMDBG */
37#define BCMSDH_ERROR(x)
38#define BCMSDH_INFO(x)
39#endif /* BCMDBG */
40
41/* forward declarations */
42typedef struct bcmsdh_info bcmsdh_info_t;
43typedef void (*bcmsdh_cb_fn_t) (void *);
44
45/* Attach and build an interface to the underlying SD host driver.
46 * - Allocates resources (structs, arrays, mem, OS handles, etc) needed by bcmsdh.
47 * - Returns the bcmsdh handle and virtual address base for register access.
48 * The returned handle should be used in all subsequent calls, but the bcmsh
49 * implementation may maintain a single "default" handle (e.g. the first or
50 * most recent one) to enable single-instance implementations to pass NULL.
51 */
Arend van Spriel3c9d4c32011-03-02 21:18:48 +010052extern bcmsdh_info_t *bcmsdh_attach(void *cfghdl, void **regsva, uint irq);
Henry Ptasinskia9533e72010-09-08 21:04:42 -070053
54/* Detach - freeup resources allocated in attach */
Arend van Spriel8da4a3a2011-03-02 21:18:42 +010055extern int bcmsdh_detach(void *sdh);
Henry Ptasinskia9533e72010-09-08 21:04:42 -070056
57/* Query if SD device interrupts are enabled */
58extern bool bcmsdh_intr_query(void *sdh);
59
60/* Enable/disable SD interrupt */
61extern int bcmsdh_intr_enable(void *sdh);
62extern int bcmsdh_intr_disable(void *sdh);
63
64/* Register/deregister device interrupt handler. */
65extern int bcmsdh_intr_reg(void *sdh, bcmsdh_cb_fn_t fn, void *argh);
66extern int bcmsdh_intr_dereg(void *sdh);
67
Hauke Mehrtens26e80552011-02-09 21:21:39 +010068#if defined(DHD_DEBUG)
Henry Ptasinskia9533e72010-09-08 21:04:42 -070069/* Query pending interrupt status from the host controller */
70extern bool bcmsdh_intr_pending(void *sdh);
71#endif
72extern int bcmsdh_claim_host_and_lock(void *sdh);
73extern int bcmsdh_release_host_and_unlock(void *sdh);
74
75/* Register a callback to be called if and when bcmsdh detects
76 * device removal. No-op in the case of non-removable/hardwired devices.
77 */
78extern int bcmsdh_devremove_reg(void *sdh, bcmsdh_cb_fn_t fn, void *argh);
79
80/* Access SDIO address space (e.g. CCCR) using CMD52 (single-byte interface).
81 * fn: function number
82 * addr: unmodified SDIO-space address
83 * data: data byte to write
84 * err: pointer to error code (or NULL)
85 */
Greg Kroah-Hartman66cbd3a2010-10-08 11:05:47 -070086extern u8 bcmsdh_cfg_read(void *sdh, uint func, u32 addr, int *err);
87extern void bcmsdh_cfg_write(void *sdh, uint func, u32 addr, u8 data,
Henry Ptasinskia9533e72010-09-08 21:04:42 -070088 int *err);
89
90/* Read/Write 4bytes from/to cfg space */
Greg Kroah-Hartman66cbd3a2010-10-08 11:05:47 -070091extern u32 bcmsdh_cfg_read_word(void *sdh, uint fnc_num, u32 addr,
Henry Ptasinskia9533e72010-09-08 21:04:42 -070092 int *err);
Greg Kroah-Hartman66cbd3a2010-10-08 11:05:47 -070093extern void bcmsdh_cfg_write_word(void *sdh, uint fnc_num, u32 addr,
94 u32 data, int *err);
Henry Ptasinskia9533e72010-09-08 21:04:42 -070095
96/* Read CIS content for specified function.
97 * fn: function whose CIS is being requested (0 is common CIS)
98 * cis: pointer to memory location to place results
99 * length: number of bytes to read
100 * Internally, this routine uses the values from the cis base regs (0x9-0xB)
101 * to form an SDIO-space address to read the data from.
102 */
Greg Kroah-Hartmande9bca62010-10-05 10:23:40 -0700103extern int bcmsdh_cis_read(void *sdh, uint func, u8 *cis, uint length);
Henry Ptasinskia9533e72010-09-08 21:04:42 -0700104
105/* Synchronous access to device (client) core registers via CMD53 to F1.
106 * addr: backplane address (i.e. >= regsva from attach)
107 * size: register width in bytes (2 or 4)
108 * data: data for register write
109 */
Greg Kroah-Hartman66cbd3a2010-10-08 11:05:47 -0700110extern u32 bcmsdh_reg_read(void *sdh, u32 addr, uint size);
111extern u32 bcmsdh_reg_write(void *sdh, u32 addr, uint size, u32 data);
Henry Ptasinskia9533e72010-09-08 21:04:42 -0700112
113/* Indicate if last reg read/write failed */
114extern bool bcmsdh_regfail(void *sdh);
115
116/* Buffer transfer to/from device (client) core via cmd53.
117 * fn: function number
118 * addr: backplane address (i.e. >= regsva from attach)
119 * flags: backplane width, address increment, sync/async
120 * buf: pointer to memory data buffer
121 * nbytes: number of bytes to transfer to/from buf
122 * pkt: pointer to packet associated with buf (if any)
123 * complete: callback function for command completion (async only)
124 * handle: handle for completion callback (first arg in callback)
125 * Returns 0 or error code.
126 * NOTE: Async operation is not currently supported.
127 */
128typedef void (*bcmsdh_cmplt_fn_t) (void *handle, int status, bool sync_waiting);
Greg Kroah-Hartman66cbd3a2010-10-08 11:05:47 -0700129extern int bcmsdh_send_buf(void *sdh, u32 addr, uint fn, uint flags,
Greg Kroah-Hartmande9bca62010-10-05 10:23:40 -0700130 u8 *buf, uint nbytes, void *pkt,
Henry Ptasinskia9533e72010-09-08 21:04:42 -0700131 bcmsdh_cmplt_fn_t complete, void *handle);
Greg Kroah-Hartman66cbd3a2010-10-08 11:05:47 -0700132extern int bcmsdh_recv_buf(void *sdh, u32 addr, uint fn, uint flags,
Arend van Sprielc26b1372010-11-23 14:06:23 +0100133 u8 *buf, uint nbytes, struct sk_buff *pkt,
Henry Ptasinskia9533e72010-09-08 21:04:42 -0700134 bcmsdh_cmplt_fn_t complete, void *handle);
135
136/* Flags bits */
137#define SDIO_REQ_4BYTE 0x1 /* Four-byte target (backplane) width (vs. two-byte) */
138#define SDIO_REQ_FIXED 0x2 /* Fixed address (FIFO) (vs. incrementing address) */
139#define SDIO_REQ_ASYNC 0x4 /* Async request (vs. sync request) */
140
141/* Pending (non-error) return code */
142#define BCME_PENDING 1
143
144/* Read/write to memory block (F1, no FIFO) via CMD53 (sync only).
145 * rw: read or write (0/1)
146 * addr: direct SDIO address
147 * buf: pointer to memory data buffer
148 * nbytes: number of bytes to transfer to/from buf
149 * Returns 0 or error code.
150 */
Greg Kroah-Hartman66cbd3a2010-10-08 11:05:47 -0700151extern int bcmsdh_rwdata(void *sdh, uint rw, u32 addr, u8 *buf,
Henry Ptasinskia9533e72010-09-08 21:04:42 -0700152 uint nbytes);
153
154/* Issue an abort to the specified function */
155extern int bcmsdh_abort(void *sdh, uint fn);
156
157/* Start SDIO Host Controller communication */
158extern int bcmsdh_start(void *sdh, int stage);
159
160/* Stop SDIO Host Controller communication */
161extern int bcmsdh_stop(void *sdh);
162
163/* Returns the "Device ID" of target device on the SDIO bus. */
164extern int bcmsdh_query_device(void *sdh);
165
166/* Returns the number of IO functions reported by the device */
167extern uint bcmsdh_query_iofnum(void *sdh);
168
169/* Miscellaneous knob tweaker. */
170extern int bcmsdh_iovar_op(void *sdh, const char *name,
171 void *params, int plen, void *arg, int len,
172 bool set);
173
174/* Reset and reinitialize the device */
Jason Cooper7cc4a4c2010-09-14 09:45:30 -0400175extern int bcmsdh_reset(bcmsdh_info_t *sdh);
Henry Ptasinskia9533e72010-09-08 21:04:42 -0700176
177/* helper functions */
178
Jason Cooper7cc4a4c2010-09-14 09:45:30 -0400179extern void *bcmsdh_get_sdioh(bcmsdh_info_t *sdh);
Henry Ptasinskia9533e72010-09-08 21:04:42 -0700180
181/* callback functions */
182typedef struct {
183 /* attach to device */
Greg Kroah-Hartman7d4df482010-10-07 17:04:47 -0700184 void *(*attach) (u16 vend_id, u16 dev_id, u16 bus, u16 slot,
Arend van Spriel3c9d4c32011-03-02 21:18:48 +0100185 u16 func, uint bustype, void *regsva, void *param);
Henry Ptasinskia9533e72010-09-08 21:04:42 -0700186 /* detach from device */
187 void (*detach) (void *ch);
188} bcmsdh_driver_t;
189
190/* platform specific/high level functions */
Jason Cooper7cc4a4c2010-09-14 09:45:30 -0400191extern int bcmsdh_register(bcmsdh_driver_t *driver);
Henry Ptasinskia9533e72010-09-08 21:04:42 -0700192extern void bcmsdh_unregister(void);
Greg Kroah-Hartman7d4df482010-10-07 17:04:47 -0700193extern bool bcmsdh_chipmatch(u16 vendor, u16 device);
Henry Ptasinskia9533e72010-09-08 21:04:42 -0700194extern void bcmsdh_device_remove(void *sdh);
195
196/* Function to pass device-status bits to DHD. */
Greg Kroah-Hartman66cbd3a2010-10-08 11:05:47 -0700197extern u32 bcmsdh_get_dstatus(void *sdh);
Henry Ptasinskia9533e72010-09-08 21:04:42 -0700198
199/* Function to return current window addr */
Greg Kroah-Hartman66cbd3a2010-10-08 11:05:47 -0700200extern u32 bcmsdh_cur_sbwad(void *sdh);
Henry Ptasinskia9533e72010-09-08 21:04:42 -0700201
202/* Function to pass chipid and rev to lower layers for controlling pr's */
Greg Kroah-Hartman66cbd3a2010-10-08 11:05:47 -0700203extern void bcmsdh_chipinfo(void *sdh, u32 chip, u32 chiprev);
Henry Ptasinskia9533e72010-09-08 21:04:42 -0700204
205#endif /* _bcmsdh_h_ */