2 * SDIO host client driver interface of Broadcom HNBU
3 * export functions to client drivers
4 * abstract OS and BUS specific details of SDIO
6 * Copyright (C) 1999-2011, Broadcom Corporation
8 * Unless you and Broadcom execute a separate written software license
9 * agreement governing use of this software, this software is licensed to you
10 * under the terms of the GNU General Public License version 2 (the "GPL"),
11 * available at http://www.broadcom.com/licenses/GPLv2.php, with the
12 * following added to such license:
14 * As a special exception, the copyright holders of this software give you
15 * permission to link this software with independent modules, and to copy and
16 * distribute the resulting executable under terms of your choice, provided that
17 * you also meet, for each linked independent module, the terms and conditions of
18 * the license of that module. An independent module is a module which is not
19 * derived from this software. The special exception does not apply to any
20 * modifications of the software.
22 * Notwithstanding the above, under no circumstances may you combine this
23 * software in any way with any other Broadcom software provided under a license
24 * other than the GPL, without Broadcom's express prior written consent.
26 * $Id: bcmsdh.h,v 13.46.52.3 2010-10-19 00:41:44 $
32 #define BCMSDH_ERROR_VAL 0x0001 /* Error */
33 #define BCMSDH_INFO_VAL 0x0002 /* Info */
34 extern const uint bcmsdh_msglevel;
36 #define BCMSDH_ERROR(x)
37 #define BCMSDH_INFO(x)
39 /* forward declarations */
40 typedef struct bcmsdh_info bcmsdh_info_t;
41 typedef void (*bcmsdh_cb_fn_t)(void *);
43 /* Attach and build an interface to the underlying SD host driver.
44 * - Allocates resources (structs, arrays, mem, OS handles, etc) needed by bcmsdh.
45 * - Returns the bcmsdh handle and virtual address base for register access.
46 * The returned handle should be used in all subsequent calls, but the bcmsh
47 * implementation may maintain a single "default" handle (e.g. the first or
48 * most recent one) to enable single-instance implementations to pass NULL.
50 extern bcmsdh_info_t *bcmsdh_attach(osl_t *osh, void *cfghdl, void **regsva, uint irq);
52 /* Detach - freeup resources allocated in attach */
53 extern int bcmsdh_detach(osl_t *osh, void *sdh);
55 /* Query if SD device interrupts are enabled */
56 extern bool bcmsdh_intr_query(void *sdh);
58 /* Enable/disable SD interrupt */
59 extern int bcmsdh_intr_enable(void *sdh);
60 extern int bcmsdh_intr_disable(void *sdh);
62 /* Register/deregister device interrupt handler. */
63 extern int bcmsdh_intr_reg(void *sdh, bcmsdh_cb_fn_t fn, void *argh);
64 extern int bcmsdh_intr_dereg(void *sdh);
66 #if defined(DHD_DEBUG)
67 /* Query pending interrupt status from the host controller */
68 extern bool bcmsdh_intr_pending(void *sdh);
72 extern int bcmsdh_claim_host_and_lock(void *sdh);
73 extern int bcmsdh_release_host_and_unlock(void *sdh);
74 #endif /* BCMLXSDMMC */
76 /* Register a callback to be called if and when bcmsdh detects
77 * device removal. No-op in the case of non-removable/hardwired devices.
79 extern int bcmsdh_devremove_reg(void *sdh, bcmsdh_cb_fn_t fn, void *argh);
81 /* Access SDIO address space (e.g. CCCR) using CMD52 (single-byte interface).
83 * addr: unmodified SDIO-space address
84 * data: data byte to write
85 * err: pointer to error code (or NULL)
87 extern uint8 bcmsdh_cfg_read(void *sdh, uint func, uint32 addr, int *err);
88 extern void bcmsdh_cfg_write(void *sdh, uint func, uint32 addr, uint8 data, int *err);
90 /* Read/Write 4bytes from/to cfg space */
91 extern uint32 bcmsdh_cfg_read_word(void *sdh, uint fnc_num, uint32 addr, int *err);
92 extern void bcmsdh_cfg_write_word(void *sdh, uint fnc_num, uint32 addr, uint32 data, int *err);
94 /* Read CIS content for specified function.
95 * fn: function whose CIS is being requested (0 is common CIS)
96 * cis: pointer to memory location to place results
97 * length: number of bytes to read
98 * Internally, this routine uses the values from the cis base regs (0x9-0xB)
99 * to form an SDIO-space address to read the data from.
101 extern int bcmsdh_cis_read(void *sdh, uint func, uint8 *cis, uint length);
103 /* Synchronous access to device (client) core registers via CMD53 to F1.
104 * addr: backplane address (i.e. >= regsva from attach)
105 * size: register width in bytes (2 or 4)
106 * data: data for register write
108 extern uint32 bcmsdh_reg_read(void *sdh, uint32 addr, uint size);
109 extern uint32 bcmsdh_reg_write(void *sdh, uint32 addr, uint size, uint32 data);
111 /* Indicate if last reg read/write failed */
112 extern bool bcmsdh_regfail(void *sdh);
114 /* Buffer transfer to/from device (client) core via cmd53.
115 * fn: function number
116 * addr: backplane address (i.e. >= regsva from attach)
117 * flags: backplane width, address increment, sync/async
118 * buf: pointer to memory data buffer
119 * nbytes: number of bytes to transfer to/from buf
120 * pkt: pointer to packet associated with buf (if any)
121 * complete: callback function for command completion (async only)
122 * handle: handle for completion callback (first arg in callback)
123 * Returns 0 or error code.
124 * NOTE: Async operation is not currently supported.
126 typedef void (*bcmsdh_cmplt_fn_t)(void *handle, int status, bool sync_waiting);
127 extern int bcmsdh_send_buf(void *sdh, uint32 addr, uint fn, uint flags,
128 uint8 *buf, uint nbytes, void *pkt,
129 bcmsdh_cmplt_fn_t complete, void *handle);
130 extern int bcmsdh_recv_buf(void *sdh, uint32 addr, uint fn, uint flags,
131 uint8 *buf, uint nbytes, void *pkt,
132 bcmsdh_cmplt_fn_t complete, void *handle);
135 #define SDIO_REQ_4BYTE 0x1 /* Four-byte target (backplane) width (vs. two-byte) */
136 #define SDIO_REQ_FIXED 0x2 /* Fixed address (FIFO) (vs. incrementing address) */
137 #define SDIO_REQ_ASYNC 0x4 /* Async request (vs. sync request) */
139 /* Pending (non-error) return code */
140 #define BCME_PENDING 1
142 /* Read/write to memory block (F1, no FIFO) via CMD53 (sync only).
143 * rw: read or write (0/1)
144 * addr: direct SDIO address
145 * buf: pointer to memory data buffer
146 * nbytes: number of bytes to transfer to/from buf
147 * Returns 0 or error code.
149 extern int bcmsdh_rwdata(void *sdh, uint rw, uint32 addr, uint8 *buf, uint nbytes);
151 /* Issue an abort to the specified function */
152 extern int bcmsdh_abort(void *sdh, uint fn);
154 /* Start SDIO Host Controller communication */
155 extern int bcmsdh_start(void *sdh, int stage);
157 /* Stop SDIO Host Controller communication */
158 extern int bcmsdh_stop(void *sdh);
160 /* Wait system lock free */
161 extern int bcmsdh_waitlockfree(void *sdh);
163 /* Returns the "Device ID" of target device on the SDIO bus. */
164 extern int bcmsdh_query_device(void *sdh);
166 /* Returns the number of IO functions reported by the device */
167 extern uint bcmsdh_query_iofnum(void *sdh);
169 /* Miscellaneous knob tweaker. */
170 extern int bcmsdh_iovar_op(void *sdh, const char *name,
171 void *params, int plen, void *arg, int len, bool set);
173 /* Reset and reinitialize the device */
174 extern int bcmsdh_reset(bcmsdh_info_t *sdh);
176 /* helper functions */
178 extern void *bcmsdh_get_sdioh(bcmsdh_info_t *sdh);
180 /* callback functions */
182 /* attach to device */
183 void *(*attach)(uint16 vend_id, uint16 dev_id, uint16 bus, uint16 slot,
184 uint16 func, uint bustype, void * regsva, osl_t * osh,
186 /* detach from device */
187 void (*detach)(void *ch);
190 /* platform specific/high level functions */
191 extern int bcmsdh_register(bcmsdh_driver_t *driver);
192 extern void bcmsdh_unregister(void);
193 extern bool bcmsdh_chipmatch(uint16 vendor, uint16 device);
194 extern void bcmsdh_device_remove(void * sdh);
196 #if defined(OOB_INTR_ONLY)
197 extern int bcmsdh_register_oob_intr(void * dhdp);
198 extern void bcmsdh_unregister_oob_intr(void);
199 extern void bcmsdh_oob_intr_set(bool enable);
200 #endif /* defined(OOB_INTR_ONLY) */
201 /* Function to pass device-status bits to DHD. */
202 extern uint32 bcmsdh_get_dstatus(void *sdh);
204 /* Function to return current window addr */
205 extern uint32 bcmsdh_cur_sbwad(void *sdh);
207 /* Function to pass chipid and rev to lower layers for controlling pr's */
208 extern void bcmsdh_chipinfo(void *sdh, uint32 chip, uint32 chiprev);
211 extern void bcmsdh_dwordmode(void *sdh, bool set);
214 #endif /* _bcmsdh_h_ */