blob: 6b80983d43c9499cfc4d82280106b0052115571e [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
20#define BCMSDH_ERROR_VAL 0x0001 /* Error */
21#define BCMSDH_INFO_VAL 0x0002 /* Info */
22extern const uint bcmsdh_msglevel;
23
24#ifdef BCMDBG
25#define BCMSDH_ERROR(x) do { if ((bcmsdh_msglevel & BCMSDH_ERROR_VAL) && net_ratelimit()) printf x; } while (0)
26#define BCMSDH_INFO(x) do { if ((bcmsdh_msglevel & BCMSDH_INFO_VAL) && net_ratelimit()) printf x; } while (0)
27#else /* BCMDBG */
28#define BCMSDH_ERROR(x)
29#define BCMSDH_INFO(x)
30#endif /* BCMDBG */
31
32/* forward declarations */
33typedef struct bcmsdh_info bcmsdh_info_t;
34typedef void (*bcmsdh_cb_fn_t) (void *);
35
36/* Attach and build an interface to the underlying SD host driver.
37 * - Allocates resources (structs, arrays, mem, OS handles, etc) needed by bcmsdh.
38 * - Returns the bcmsdh handle and virtual address base for register access.
39 * The returned handle should be used in all subsequent calls, but the bcmsh
40 * implementation may maintain a single "default" handle (e.g. the first or
41 * most recent one) to enable single-instance implementations to pass NULL.
42 */
Jason Cooper7cc4a4c2010-09-14 09:45:30 -040043extern bcmsdh_info_t *bcmsdh_attach(osl_t *osh, void *cfghdl, void **regsva,
Henry Ptasinskia9533e72010-09-08 21:04:42 -070044 uint irq);
45
46/* Detach - freeup resources allocated in attach */
Jason Cooper7cc4a4c2010-09-14 09:45:30 -040047extern int bcmsdh_detach(osl_t *osh, void *sdh);
Henry Ptasinskia9533e72010-09-08 21:04:42 -070048
49/* Query if SD device interrupts are enabled */
50extern bool bcmsdh_intr_query(void *sdh);
51
52/* Enable/disable SD interrupt */
53extern int bcmsdh_intr_enable(void *sdh);
54extern int bcmsdh_intr_disable(void *sdh);
55
56/* Register/deregister device interrupt handler. */
57extern int bcmsdh_intr_reg(void *sdh, bcmsdh_cb_fn_t fn, void *argh);
58extern int bcmsdh_intr_dereg(void *sdh);
59
60#if defined(BCMDBG)
61/* Query pending interrupt status from the host controller */
62extern bool bcmsdh_intr_pending(void *sdh);
63#endif
64extern int bcmsdh_claim_host_and_lock(void *sdh);
65extern int bcmsdh_release_host_and_unlock(void *sdh);
66
67/* Register a callback to be called if and when bcmsdh detects
68 * device removal. No-op in the case of non-removable/hardwired devices.
69 */
70extern int bcmsdh_devremove_reg(void *sdh, bcmsdh_cb_fn_t fn, void *argh);
71
72/* Access SDIO address space (e.g. CCCR) using CMD52 (single-byte interface).
73 * fn: function number
74 * addr: unmodified SDIO-space address
75 * data: data byte to write
76 * err: pointer to error code (or NULL)
77 */
Greg Kroah-Hartman66cbd3a2010-10-08 11:05:47 -070078extern u8 bcmsdh_cfg_read(void *sdh, uint func, u32 addr, int *err);
79extern void bcmsdh_cfg_write(void *sdh, uint func, u32 addr, u8 data,
Henry Ptasinskia9533e72010-09-08 21:04:42 -070080 int *err);
81
82/* Read/Write 4bytes from/to cfg space */
Greg Kroah-Hartman66cbd3a2010-10-08 11:05:47 -070083extern u32 bcmsdh_cfg_read_word(void *sdh, uint fnc_num, u32 addr,
Henry Ptasinskia9533e72010-09-08 21:04:42 -070084 int *err);
Greg Kroah-Hartman66cbd3a2010-10-08 11:05:47 -070085extern void bcmsdh_cfg_write_word(void *sdh, uint fnc_num, u32 addr,
86 u32 data, int *err);
Henry Ptasinskia9533e72010-09-08 21:04:42 -070087
88/* Read CIS content for specified function.
89 * fn: function whose CIS is being requested (0 is common CIS)
90 * cis: pointer to memory location to place results
91 * length: number of bytes to read
92 * Internally, this routine uses the values from the cis base regs (0x9-0xB)
93 * to form an SDIO-space address to read the data from.
94 */
Greg Kroah-Hartmande9bca62010-10-05 10:23:40 -070095extern int bcmsdh_cis_read(void *sdh, uint func, u8 *cis, uint length);
Henry Ptasinskia9533e72010-09-08 21:04:42 -070096
97/* Synchronous access to device (client) core registers via CMD53 to F1.
98 * addr: backplane address (i.e. >= regsva from attach)
99 * size: register width in bytes (2 or 4)
100 * data: data for register write
101 */
Greg Kroah-Hartman66cbd3a2010-10-08 11:05:47 -0700102extern u32 bcmsdh_reg_read(void *sdh, u32 addr, uint size);
103extern u32 bcmsdh_reg_write(void *sdh, u32 addr, uint size, u32 data);
Henry Ptasinskia9533e72010-09-08 21:04:42 -0700104
105/* Indicate if last reg read/write failed */
106extern bool bcmsdh_regfail(void *sdh);
107
108/* Buffer transfer to/from device (client) core via cmd53.
109 * fn: function number
110 * addr: backplane address (i.e. >= regsva from attach)
111 * flags: backplane width, address increment, sync/async
112 * buf: pointer to memory data buffer
113 * nbytes: number of bytes to transfer to/from buf
114 * pkt: pointer to packet associated with buf (if any)
115 * complete: callback function for command completion (async only)
116 * handle: handle for completion callback (first arg in callback)
117 * Returns 0 or error code.
118 * NOTE: Async operation is not currently supported.
119 */
120typedef void (*bcmsdh_cmplt_fn_t) (void *handle, int status, bool sync_waiting);
Greg Kroah-Hartman66cbd3a2010-10-08 11:05:47 -0700121extern int bcmsdh_send_buf(void *sdh, u32 addr, uint fn, uint flags,
Greg Kroah-Hartmande9bca62010-10-05 10:23:40 -0700122 u8 *buf, uint nbytes, void *pkt,
Henry Ptasinskia9533e72010-09-08 21:04:42 -0700123 bcmsdh_cmplt_fn_t complete, void *handle);
Greg Kroah-Hartman66cbd3a2010-10-08 11:05:47 -0700124extern int bcmsdh_recv_buf(void *sdh, u32 addr, uint fn, uint flags,
Greg Kroah-Hartmande9bca62010-10-05 10:23:40 -0700125 u8 *buf, uint nbytes, void *pkt,
Henry Ptasinskia9533e72010-09-08 21:04:42 -0700126 bcmsdh_cmplt_fn_t complete, void *handle);
127
128/* Flags bits */
129#define SDIO_REQ_4BYTE 0x1 /* Four-byte target (backplane) width (vs. two-byte) */
130#define SDIO_REQ_FIXED 0x2 /* Fixed address (FIFO) (vs. incrementing address) */
131#define SDIO_REQ_ASYNC 0x4 /* Async request (vs. sync request) */
132
133/* Pending (non-error) return code */
134#define BCME_PENDING 1
135
136/* Read/write to memory block (F1, no FIFO) via CMD53 (sync only).
137 * rw: read or write (0/1)
138 * addr: direct SDIO address
139 * buf: pointer to memory data buffer
140 * nbytes: number of bytes to transfer to/from buf
141 * Returns 0 or error code.
142 */
Greg Kroah-Hartman66cbd3a2010-10-08 11:05:47 -0700143extern int bcmsdh_rwdata(void *sdh, uint rw, u32 addr, u8 *buf,
Henry Ptasinskia9533e72010-09-08 21:04:42 -0700144 uint nbytes);
145
146/* Issue an abort to the specified function */
147extern int bcmsdh_abort(void *sdh, uint fn);
148
149/* Start SDIO Host Controller communication */
150extern int bcmsdh_start(void *sdh, int stage);
151
152/* Stop SDIO Host Controller communication */
153extern int bcmsdh_stop(void *sdh);
154
155/* Returns the "Device ID" of target device on the SDIO bus. */
156extern int bcmsdh_query_device(void *sdh);
157
158/* Returns the number of IO functions reported by the device */
159extern uint bcmsdh_query_iofnum(void *sdh);
160
161/* Miscellaneous knob tweaker. */
162extern int bcmsdh_iovar_op(void *sdh, const char *name,
163 void *params, int plen, void *arg, int len,
164 bool set);
165
166/* Reset and reinitialize the device */
Jason Cooper7cc4a4c2010-09-14 09:45:30 -0400167extern int bcmsdh_reset(bcmsdh_info_t *sdh);
Henry Ptasinskia9533e72010-09-08 21:04:42 -0700168
169/* helper functions */
170
Jason Cooper7cc4a4c2010-09-14 09:45:30 -0400171extern void *bcmsdh_get_sdioh(bcmsdh_info_t *sdh);
Henry Ptasinskia9533e72010-09-08 21:04:42 -0700172
173/* callback functions */
174typedef struct {
175 /* attach to device */
Greg Kroah-Hartman7d4df482010-10-07 17:04:47 -0700176 void *(*attach) (u16 vend_id, u16 dev_id, u16 bus, u16 slot,
177 u16 func, uint bustype, void *regsva, osl_t *osh,
Henry Ptasinskia9533e72010-09-08 21:04:42 -0700178 void *param);
179 /* detach from device */
180 void (*detach) (void *ch);
181} bcmsdh_driver_t;
182
183/* platform specific/high level functions */
Jason Cooper7cc4a4c2010-09-14 09:45:30 -0400184extern int bcmsdh_register(bcmsdh_driver_t *driver);
Henry Ptasinskia9533e72010-09-08 21:04:42 -0700185extern void bcmsdh_unregister(void);
Greg Kroah-Hartman7d4df482010-10-07 17:04:47 -0700186extern bool bcmsdh_chipmatch(u16 vendor, u16 device);
Henry Ptasinskia9533e72010-09-08 21:04:42 -0700187extern void bcmsdh_device_remove(void *sdh);
188
189/* Function to pass device-status bits to DHD. */
Greg Kroah-Hartman66cbd3a2010-10-08 11:05:47 -0700190extern u32 bcmsdh_get_dstatus(void *sdh);
Henry Ptasinskia9533e72010-09-08 21:04:42 -0700191
192/* Function to return current window addr */
Greg Kroah-Hartman66cbd3a2010-10-08 11:05:47 -0700193extern u32 bcmsdh_cur_sbwad(void *sdh);
Henry Ptasinskia9533e72010-09-08 21:04:42 -0700194
195/* Function to pass chipid and rev to lower layers for controlling pr's */
Greg Kroah-Hartman66cbd3a2010-10-08 11:05:47 -0700196extern void bcmsdh_chipinfo(void *sdh, u32 chip, u32 chiprev);
Henry Ptasinskia9533e72010-09-08 21:04:42 -0700197
198#endif /* _bcmsdh_h_ */