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 #define BCMSDH_ERROR_VAL 0x0001 /* Error */
21 #define BCMSDH_INFO_VAL 0x0002 /* Info */
22 extern const uint bcmsdh_msglevel
;
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)
28 #define BCMSDH_ERROR(x)
29 #define BCMSDH_INFO(x)
32 /* forward declarations */
33 typedef struct bcmsdh_info bcmsdh_info_t
;
34 typedef void (*bcmsdh_cb_fn_t
) (void *);
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.
43 extern bcmsdh_info_t
*bcmsdh_attach(osl_t
*osh
, void *cfghdl
, void **regsva
,
46 /* Detach - freeup resources allocated in attach */
47 extern int bcmsdh_detach(osl_t
*osh
, void *sdh
);
49 /* Query if SD device interrupts are enabled */
50 extern bool bcmsdh_intr_query(void *sdh
);
52 /* Enable/disable SD interrupt */
53 extern int bcmsdh_intr_enable(void *sdh
);
54 extern int bcmsdh_intr_disable(void *sdh
);
56 /* Register/deregister device interrupt handler. */
57 extern int bcmsdh_intr_reg(void *sdh
, bcmsdh_cb_fn_t fn
, void *argh
);
58 extern int bcmsdh_intr_dereg(void *sdh
);
61 /* Query pending interrupt status from the host controller */
62 extern bool bcmsdh_intr_pending(void *sdh
);
64 extern int bcmsdh_claim_host_and_lock(void *sdh
);
65 extern int bcmsdh_release_host_and_unlock(void *sdh
);
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.
70 extern int bcmsdh_devremove_reg(void *sdh
, bcmsdh_cb_fn_t fn
, void *argh
);
72 /* Access SDIO address space (e.g. CCCR) using CMD52 (single-byte interface).
74 * addr: unmodified SDIO-space address
75 * data: data byte to write
76 * err: pointer to error code (or NULL)
78 extern u8
bcmsdh_cfg_read(void *sdh
, uint func
, u32 addr
, int *err
);
79 extern void bcmsdh_cfg_write(void *sdh
, uint func
, u32 addr
, u8 data
,
82 /* Read/Write 4bytes from/to cfg space */
83 extern u32
bcmsdh_cfg_read_word(void *sdh
, uint fnc_num
, u32 addr
,
85 extern void bcmsdh_cfg_write_word(void *sdh
, uint fnc_num
, u32 addr
,
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.
95 extern int bcmsdh_cis_read(void *sdh
, uint func
, u8
*cis
, uint length
);
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
102 extern u32
bcmsdh_reg_read(void *sdh
, u32 addr
, uint size
);
103 extern u32
bcmsdh_reg_write(void *sdh
, u32 addr
, uint size
, u32 data
);
105 /* Indicate if last reg read/write failed */
106 extern bool bcmsdh_regfail(void *sdh
);
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.
120 typedef void (*bcmsdh_cmplt_fn_t
) (void *handle
, int status
, bool sync_waiting
);
121 extern int bcmsdh_send_buf(void *sdh
, u32 addr
, uint fn
, uint flags
,
122 u8
*buf
, uint nbytes
, void *pkt
,
123 bcmsdh_cmplt_fn_t complete
, void *handle
);
124 extern int bcmsdh_recv_buf(void *sdh
, u32 addr
, uint fn
, uint flags
,
125 u8
*buf
, uint nbytes
, void *pkt
,
126 bcmsdh_cmplt_fn_t complete
, void *handle
);
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) */
133 /* Pending (non-error) return code */
134 #define BCME_PENDING 1
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.
143 extern int bcmsdh_rwdata(void *sdh
, uint rw
, u32 addr
, u8
*buf
,
146 /* Issue an abort to the specified function */
147 extern int bcmsdh_abort(void *sdh
, uint fn
);
149 /* Start SDIO Host Controller communication */
150 extern int bcmsdh_start(void *sdh
, int stage
);
152 /* Stop SDIO Host Controller communication */
153 extern int bcmsdh_stop(void *sdh
);
155 /* Returns the "Device ID" of target device on the SDIO bus. */
156 extern int bcmsdh_query_device(void *sdh
);
158 /* Returns the number of IO functions reported by the device */
159 extern uint
bcmsdh_query_iofnum(void *sdh
);
161 /* Miscellaneous knob tweaker. */
162 extern int bcmsdh_iovar_op(void *sdh
, const char *name
,
163 void *params
, int plen
, void *arg
, int len
,
166 /* Reset and reinitialize the device */
167 extern int bcmsdh_reset(bcmsdh_info_t
*sdh
);
169 /* helper functions */
171 extern void *bcmsdh_get_sdioh(bcmsdh_info_t
*sdh
);
173 /* callback functions */
175 /* attach to device */
176 void *(*attach
) (u16 vend_id
, u16 dev_id
, u16 bus
, u16 slot
,
177 u16 func
, uint bustype
, void *regsva
, osl_t
*osh
,
179 /* detach from device */
180 void (*detach
) (void *ch
);
183 /* platform specific/high level functions */
184 extern int bcmsdh_register(bcmsdh_driver_t
*driver
);
185 extern void bcmsdh_unregister(void);
186 extern bool bcmsdh_chipmatch(u16 vendor
, u16 device
);
187 extern void bcmsdh_device_remove(void *sdh
);
189 /* Function to pass device-status bits to DHD. */
190 extern u32
bcmsdh_get_dstatus(void *sdh
);
192 /* Function to return current window addr */
193 extern u32
bcmsdh_cur_sbwad(void *sdh
);
195 /* Function to pass chipid and rev to lower layers for controlling pr's */
196 extern void bcmsdh_chipinfo(void *sdh
, u32 chip
, u32 chiprev
);
198 #endif /* _bcmsdh_h_ */