Home | History | Annotate | Download | only in include
      1 /*
      2  * SDIO host client driver interface of Broadcom HNBU
      3  *     export functions to client drivers
      4  *     abstract OS and BUS specific details of SDIO
      5  *
      6  * Copyright (C) 1999-2010, Broadcom Corporation
      7  *
      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:
     13  *
     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.
     21  *
     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.
     25  *
     26  * $Id: bcmsdh.h,v 13.35.14.7.6.8 2009/10/14 04:22:25 Exp $
     27  */
     28 
     29 #ifndef	_bcmsdh_h_
     30 #define	_bcmsdh_h_
     31 
     32 #define BCMSDH_ERROR_VAL	0x0001 /* Error */
     33 #define BCMSDH_INFO_VAL		0x0002 /* Info */
     34 extern const uint bcmsdh_msglevel;
     35 
     36 #define BCMSDH_ERROR(x)
     37 #define BCMSDH_INFO(x)
     38 
     39 /* forward declarations */
     40 typedef struct bcmsdh_info bcmsdh_info_t;
     41 typedef void (*bcmsdh_cb_fn_t)(void *);
     42 
     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.
     49  */
     50 extern bcmsdh_info_t *bcmsdh_attach(osl_t *osh, void *cfghdl, void **regsva, uint irq);
     51 
     52 /* Detach - freeup resources allocated in attach */
     53 extern int bcmsdh_detach(osl_t *osh, void *sdh);
     54 
     55 /* Query if SD device interrupts are enabled */
     56 extern bool bcmsdh_intr_query(void *sdh);
     57 
     58 /* Enable/disable SD interrupt */
     59 extern int bcmsdh_intr_enable(void *sdh);
     60 extern int bcmsdh_intr_disable(void *sdh);
     61 
     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);
     65 
     66 #if defined(DHD_DEBUG)
     67 /* Query pending interrupt status from the host controller */
     68 extern bool bcmsdh_intr_pending(void *sdh);
     69 #endif
     70 
     71 #ifdef BCMLXSDMMC
     72 extern int bcmsdh_claim_host_and_lock(void *sdh);
     73 extern int bcmsdh_release_host_and_unlock(void *sdh);
     74 #endif /* BCMLXSDMMC */
     75 
     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.
     78  */
     79 extern int bcmsdh_devremove_reg(void *sdh, bcmsdh_cb_fn_t fn, void *argh);
     80 
     81 /* Access SDIO address space (e.g. CCCR) using CMD52 (single-byte interface).
     82  *   fn:   function number
     83  *   addr: unmodified SDIO-space address
     84  *   data: data byte to write
     85  *   err:  pointer to error code (or NULL)
     86  */
     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);
     89 
     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);
     93 
     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.
    100  */
    101 extern int bcmsdh_cis_read(void *sdh, uint func, uint8 *cis, uint length);
    102 
    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
    107  */
    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);
    110 
    111 /* Indicate if last reg read/write failed */
    112 extern bool bcmsdh_regfail(void *sdh);
    113 
    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.
    125  */
    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);
    133 
    134 /* Flags bits */
    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) */
    138 
    139 /* Pending (non-error) return code */
    140 #define BCME_PENDING	1
    141 
    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.
    148  */
    149 extern int bcmsdh_rwdata(void *sdh, uint rw, uint32 addr, uint8 *buf, uint nbytes);
    150 
    151 /* Issue an abort to the specified function */
    152 extern int bcmsdh_abort(void *sdh, uint fn);
    153 
    154 /* Start SDIO Host Controller communication */
    155 extern int bcmsdh_start(void *sdh, int stage);
    156 
    157 /* Stop SDIO Host Controller communication */
    158 extern int bcmsdh_stop(void *sdh);
    159 
    160 /* Returns the "Device ID" of target device on the SDIO bus. */
    161 extern int bcmsdh_query_device(void *sdh);
    162 
    163 /* Returns the number of IO functions reported by the device */
    164 extern uint bcmsdh_query_iofnum(void *sdh);
    165 
    166 /* Miscellaneous knob tweaker. */
    167 extern int bcmsdh_iovar_op(void *sdh, const char *name,
    168                            void *params, int plen, void *arg, int len, bool set);
    169 
    170 /* Reset and reinitialize the device */
    171 extern int bcmsdh_reset(bcmsdh_info_t *sdh);
    172 
    173 /* helper functions */
    174 
    175 extern void *bcmsdh_get_sdioh(bcmsdh_info_t *sdh);
    176 
    177 /* callback functions */
    178 typedef struct {
    179 	/* attach to device */
    180 	void *(*attach)(uint16 vend_id, uint16 dev_id, uint16 bus, uint16 slot,
    181 	                uint16 func, uint bustype, void * regsva, osl_t * osh,
    182 	                void * param);
    183 	/* detach from device */
    184 	void (*detach)(void *ch);
    185 } bcmsdh_driver_t;
    186 
    187 /* platform specific/high level functions */
    188 extern int bcmsdh_register(bcmsdh_driver_t *driver);
    189 extern void bcmsdh_unregister(void);
    190 extern bool bcmsdh_chipmatch(uint16 vendor, uint16 device);
    191 extern void bcmsdh_device_remove(void * sdh);
    192 
    193 #if defined(OOB_INTR_ONLY)
    194 extern int bcmsdh_register_oob_intr(void * dhdp);
    195 extern void bcmsdh_unregister_oob_intr(void);
    196 extern void bcmsdh_oob_intr_set(bool enable);
    197 #endif /* defined(OOB_INTR_ONLY) */
    198 /* Function to pass device-status bits to DHD. */
    199 extern uint32 bcmsdh_get_dstatus(void *sdh);
    200 
    201 /* Function to return current window addr */
    202 extern uint32 bcmsdh_cur_sbwad(void *sdh);
    203 
    204 /* Function to pass chipid and rev to lower layers for controlling pr's */
    205 extern void bcmsdh_chipinfo(void *sdh, uint32 chip, uint32 chiprev);
    206 
    207 
    208 #endif	/* _bcmsdh_h_ */
    209