staging: brcm80211: moved code around for cleanup
[deliverable/linux.git] / drivers / staging / brcm80211 / include / bcmsdh.h
CommitLineData
a9533e7e
HP
1/*
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
f8559b69 20#include <linux/skbuff.h>
a9533e7e
HP
21#define BCMSDH_ERROR_VAL 0x0001 /* Error */
22#define BCMSDH_INFO_VAL 0x0002 /* Info */
23extern const uint bcmsdh_msglevel;
24
25#ifdef BCMDBG
26#define BCMSDH_ERROR(x) do { if ((bcmsdh_msglevel & BCMSDH_ERROR_VAL) && net_ratelimit()) printf x; } while (0)
27#define BCMSDH_INFO(x) do { if ((bcmsdh_msglevel & BCMSDH_INFO_VAL) && net_ratelimit()) printf x; } while (0)
28#else /* BCMDBG */
29#define BCMSDH_ERROR(x)
30#define BCMSDH_INFO(x)
31#endif /* BCMDBG */
32
33/* forward declarations */
34typedef struct bcmsdh_info bcmsdh_info_t;
35typedef void (*bcmsdh_cb_fn_t) (void *);
36
37/* Attach and build an interface to the underlying SD host driver.
38 * - Allocates resources (structs, arrays, mem, OS handles, etc) needed by bcmsdh.
39 * - Returns the bcmsdh handle and virtual address base for register access.
40 * The returned handle should be used in all subsequent calls, but the bcmsh
41 * implementation may maintain a single "default" handle (e.g. the first or
42 * most recent one) to enable single-instance implementations to pass NULL.
43 */
e69284f2
BR
44extern bcmsdh_info_t *bcmsdh_attach(struct osl_info *osh, void *cfghdl,
45 void **regsva, uint irq);
a9533e7e
HP
46
47/* Detach - freeup resources allocated in attach */
e69284f2 48extern int bcmsdh_detach(struct osl_info *osh, void *sdh);
a9533e7e
HP
49
50/* Query if SD device interrupts are enabled */
51extern bool bcmsdh_intr_query(void *sdh);
52
53/* Enable/disable SD interrupt */
54extern int bcmsdh_intr_enable(void *sdh);
55extern int bcmsdh_intr_disable(void *sdh);
56
57/* Register/deregister device interrupt handler. */
58extern int bcmsdh_intr_reg(void *sdh, bcmsdh_cb_fn_t fn, void *argh);
59extern int bcmsdh_intr_dereg(void *sdh);
60
61#if defined(BCMDBG)
62/* Query pending interrupt status from the host controller */
63extern bool bcmsdh_intr_pending(void *sdh);
64#endif
65extern int bcmsdh_claim_host_and_lock(void *sdh);
66extern int bcmsdh_release_host_and_unlock(void *sdh);
67
68/* Register a callback to be called if and when bcmsdh detects
69 * device removal. No-op in the case of non-removable/hardwired devices.
70 */
71extern int bcmsdh_devremove_reg(void *sdh, bcmsdh_cb_fn_t fn, void *argh);
72
73/* Access SDIO address space (e.g. CCCR) using CMD52 (single-byte interface).
74 * fn: function number
75 * addr: unmodified SDIO-space address
76 * data: data byte to write
77 * err: pointer to error code (or NULL)
78 */
66cbd3ab
GKH
79extern u8 bcmsdh_cfg_read(void *sdh, uint func, u32 addr, int *err);
80extern void bcmsdh_cfg_write(void *sdh, uint func, u32 addr, u8 data,
a9533e7e
HP
81 int *err);
82
83/* Read/Write 4bytes from/to cfg space */
66cbd3ab 84extern u32 bcmsdh_cfg_read_word(void *sdh, uint fnc_num, u32 addr,
a9533e7e 85 int *err);
66cbd3ab
GKH
86extern void bcmsdh_cfg_write_word(void *sdh, uint fnc_num, u32 addr,
87 u32 data, int *err);
a9533e7e
HP
88
89/* Read CIS content for specified function.
90 * fn: function whose CIS is being requested (0 is common CIS)
91 * cis: pointer to memory location to place results
92 * length: number of bytes to read
93 * Internally, this routine uses the values from the cis base regs (0x9-0xB)
94 * to form an SDIO-space address to read the data from.
95 */
de9bca63 96extern int bcmsdh_cis_read(void *sdh, uint func, u8 *cis, uint length);
a9533e7e
HP
97
98/* Synchronous access to device (client) core registers via CMD53 to F1.
99 * addr: backplane address (i.e. >= regsva from attach)
100 * size: register width in bytes (2 or 4)
101 * data: data for register write
102 */
66cbd3ab
GKH
103extern u32 bcmsdh_reg_read(void *sdh, u32 addr, uint size);
104extern u32 bcmsdh_reg_write(void *sdh, u32 addr, uint size, u32 data);
a9533e7e
HP
105
106/* Indicate if last reg read/write failed */
107extern bool bcmsdh_regfail(void *sdh);
108
109/* Buffer transfer to/from device (client) core via cmd53.
110 * fn: function number
111 * addr: backplane address (i.e. >= regsva from attach)
112 * flags: backplane width, address increment, sync/async
113 * buf: pointer to memory data buffer
114 * nbytes: number of bytes to transfer to/from buf
115 * pkt: pointer to packet associated with buf (if any)
116 * complete: callback function for command completion (async only)
117 * handle: handle for completion callback (first arg in callback)
118 * Returns 0 or error code.
119 * NOTE: Async operation is not currently supported.
120 */
121typedef void (*bcmsdh_cmplt_fn_t) (void *handle, int status, bool sync_waiting);
66cbd3ab 122extern int bcmsdh_send_buf(void *sdh, u32 addr, uint fn, uint flags,
de9bca63 123 u8 *buf, uint nbytes, void *pkt,
a9533e7e 124 bcmsdh_cmplt_fn_t complete, void *handle);
66cbd3ab 125extern int bcmsdh_recv_buf(void *sdh, u32 addr, uint fn, uint flags,
c26b1378 126 u8 *buf, uint nbytes, struct sk_buff *pkt,
a9533e7e
HP
127 bcmsdh_cmplt_fn_t complete, void *handle);
128
129/* Flags bits */
130#define SDIO_REQ_4BYTE 0x1 /* Four-byte target (backplane) width (vs. two-byte) */
131#define SDIO_REQ_FIXED 0x2 /* Fixed address (FIFO) (vs. incrementing address) */
132#define SDIO_REQ_ASYNC 0x4 /* Async request (vs. sync request) */
133
134/* Pending (non-error) return code */
135#define BCME_PENDING 1
136
137/* Read/write to memory block (F1, no FIFO) via CMD53 (sync only).
138 * rw: read or write (0/1)
139 * addr: direct SDIO address
140 * buf: pointer to memory data buffer
141 * nbytes: number of bytes to transfer to/from buf
142 * Returns 0 or error code.
143 */
66cbd3ab 144extern int bcmsdh_rwdata(void *sdh, uint rw, u32 addr, u8 *buf,
a9533e7e
HP
145 uint nbytes);
146
147/* Issue an abort to the specified function */
148extern int bcmsdh_abort(void *sdh, uint fn);
149
150/* Start SDIO Host Controller communication */
151extern int bcmsdh_start(void *sdh, int stage);
152
153/* Stop SDIO Host Controller communication */
154extern int bcmsdh_stop(void *sdh);
155
156/* Returns the "Device ID" of target device on the SDIO bus. */
157extern int bcmsdh_query_device(void *sdh);
158
159/* Returns the number of IO functions reported by the device */
160extern uint bcmsdh_query_iofnum(void *sdh);
161
162/* Miscellaneous knob tweaker. */
163extern int bcmsdh_iovar_op(void *sdh, const char *name,
164 void *params, int plen, void *arg, int len,
165 bool set);
166
167/* Reset and reinitialize the device */
7cc4a4c0 168extern int bcmsdh_reset(bcmsdh_info_t *sdh);
a9533e7e
HP
169
170/* helper functions */
171
7cc4a4c0 172extern void *bcmsdh_get_sdioh(bcmsdh_info_t *sdh);
a9533e7e
HP
173
174/* callback functions */
175typedef struct {
176 /* attach to device */
7d4df48e 177 void *(*attach) (u16 vend_id, u16 dev_id, u16 bus, u16 slot,
e69284f2
BR
178 u16 func, uint bustype, void *regsva,
179 struct osl_info *osh, void *param);
a9533e7e
HP
180 /* detach from device */
181 void (*detach) (void *ch);
182} bcmsdh_driver_t;
183
184/* platform specific/high level functions */
7cc4a4c0 185extern int bcmsdh_register(bcmsdh_driver_t *driver);
a9533e7e 186extern void bcmsdh_unregister(void);
7d4df48e 187extern bool bcmsdh_chipmatch(u16 vendor, u16 device);
a9533e7e
HP
188extern void bcmsdh_device_remove(void *sdh);
189
190/* Function to pass device-status bits to DHD. */
66cbd3ab 191extern u32 bcmsdh_get_dstatus(void *sdh);
a9533e7e
HP
192
193/* Function to return current window addr */
66cbd3ab 194extern u32 bcmsdh_cur_sbwad(void *sdh);
a9533e7e
HP
195
196/* Function to pass chipid and rev to lower layers for controlling pr's */
66cbd3ab 197extern void bcmsdh_chipinfo(void *sdh, u32 chip, u32 chiprev);
a9533e7e
HP
198
199#endif /* _bcmsdh_h_ */
This page took 0.069338 seconds and 5 git commands to generate.