Dmitry Shmidt | da65eba | 2010-05-19 18:53:11 -0700 | [diff] [blame] | 1 | /* |
| 2 | * SD-SPI Protocol Conversion - BCMSDH->SPI Translation Layer |
| 3 | * |
| 4 | * Copyright (C) 1999-2010, Broadcom Corporation |
| 5 | * |
| 6 | * Unless you and Broadcom execute a separate written software license |
| 7 | * agreement governing use of this software, this software is licensed to you |
| 8 | * under the terms of the GNU General Public License version 2 (the "GPL"), |
| 9 | * available at http://www.broadcom.com/licenses/GPLv2.php, with the |
| 10 | * following added to such license: |
| 11 | * |
| 12 | * As a special exception, the copyright holders of this software give you |
| 13 | * permission to link this software with independent modules, and to copy and |
| 14 | * distribute the resulting executable under terms of your choice, provided that |
| 15 | * you also meet, for each linked independent module, the terms and conditions of |
| 16 | * the license of that module. An independent module is a module which is not |
| 17 | * derived from this software. The special exception does not apply to any |
| 18 | * modifications of the software. |
| 19 | * |
| 20 | * Notwithstanding the above, under no circumstances may you combine this |
| 21 | * software in any way with any other Broadcom software provided under a license |
| 22 | * other than the GPL, without Broadcom's express prior written consent. |
| 23 | * |
| 24 | * $Id: bcmsdspi.h,v 13.8.10.2 2008/06/30 21:09:40 Exp $ |
| 25 | */ |
| 26 | |
| 27 | /* global msglevel for debug messages - bitvals come from sdiovar.h */ |
| 28 | |
| 29 | #define sd_err(x) |
| 30 | #define sd_trace(x) |
| 31 | #define sd_info(x) |
| 32 | #define sd_debug(x) |
| 33 | #define sd_data(x) |
| 34 | #define sd_ctrl(x) |
| 35 | |
| 36 | #define sd_log(x) |
| 37 | |
| 38 | #define SDIOH_ASSERT(exp) \ |
| 39 | do { if (!(exp)) \ |
| 40 | printf("!!!ASSERT fail: file %s lines %d", __FILE__, __LINE__); \ |
| 41 | } while (0) |
| 42 | |
| 43 | #define BLOCK_SIZE_4318 64 |
| 44 | #define BLOCK_SIZE_4328 512 |
| 45 | |
| 46 | /* internal return code */ |
| 47 | #define SUCCESS 0 |
| 48 | #undef ERROR |
| 49 | #define ERROR 1 |
| 50 | |
| 51 | /* private bus modes */ |
| 52 | #define SDIOH_MODE_SPI 0 |
| 53 | |
| 54 | #define USE_BLOCKMODE 0x2 /* Block mode can be single block or multi */ |
| 55 | #define USE_MULTIBLOCK 0x4 |
| 56 | |
| 57 | struct sdioh_info { |
| 58 | uint cfg_bar; /* pci cfg address for bar */ |
| 59 | uint32 caps; /* cached value of capabilities reg */ |
| 60 | uint bar0; /* BAR0 for PCI Device */ |
| 61 | osl_t *osh; /* osh handler */ |
| 62 | void *controller; /* Pointer to SPI Controller's private data struct */ |
| 63 | |
| 64 | uint lockcount; /* nest count of sdspi_lock() calls */ |
| 65 | bool client_intr_enabled; /* interrupt connnected flag */ |
| 66 | bool intr_handler_valid; /* client driver interrupt handler valid */ |
| 67 | sdioh_cb_fn_t intr_handler; /* registered interrupt handler */ |
| 68 | void *intr_handler_arg; /* argument to call interrupt handler */ |
| 69 | bool initialized; /* card initialized */ |
| 70 | uint32 target_dev; /* Target device ID */ |
| 71 | uint32 intmask; /* Current active interrupts */ |
| 72 | void *sdos_info; /* Pointer to per-OS private data */ |
| 73 | |
| 74 | uint32 controller_type; /* Host controller type */ |
| 75 | uint8 version; /* Host Controller Spec Compliance Version */ |
| 76 | uint irq; /* Client irq */ |
| 77 | uint32 intrcount; /* Client interrupts */ |
| 78 | uint32 local_intrcount; /* Controller interrupts */ |
| 79 | bool host_init_done; /* Controller initted */ |
| 80 | bool card_init_done; /* Client SDIO interface initted */ |
| 81 | bool polled_mode; /* polling for command completion */ |
| 82 | |
| 83 | bool sd_use_dma; /* DMA on CMD53 */ |
| 84 | bool sd_blockmode; /* sd_blockmode == FALSE => 64 Byte Cmd 53s. */ |
| 85 | /* Must be on for sd_multiblock to be effective */ |
| 86 | bool use_client_ints; /* If this is false, make sure to restore */ |
| 87 | bool got_hcint; /* Host Controller interrupt. */ |
| 88 | /* polling hack in wl_linux.c:wl_timer() */ |
| 89 | int adapter_slot; /* Maybe dealing with multiple slots/controllers */ |
| 90 | int sd_mode; /* SD1/SD4/SPI */ |
| 91 | int client_block_size[SDIOD_MAX_IOFUNCS]; /* Blocksize */ |
| 92 | uint32 data_xfer_count; /* Current register transfer size */ |
| 93 | uint32 cmd53_wr_data; /* Used to pass CMD53 write data */ |
| 94 | uint32 card_response; /* Used to pass back response status byte */ |
| 95 | uint32 card_rsp_data; /* Used to pass back response data word */ |
| 96 | uint16 card_rca; /* Current Address */ |
| 97 | uint8 num_funcs; /* Supported funcs on client */ |
| 98 | uint32 com_cis_ptr; |
| 99 | uint32 func_cis_ptr[SDIOD_MAX_IOFUNCS]; |
| 100 | void *dma_buf; |
| 101 | ulong dma_phys; |
| 102 | int r_cnt; /* rx count */ |
| 103 | int t_cnt; /* tx_count */ |
| 104 | }; |
| 105 | |
| 106 | /************************************************************ |
| 107 | * Internal interfaces: per-port references into bcmsdspi.c |
| 108 | */ |
| 109 | |
| 110 | /* Global message bits */ |
| 111 | extern uint sd_msglevel; |
| 112 | |
| 113 | /************************************************************** |
| 114 | * Internal interfaces: bcmsdspi.c references to per-port code |
| 115 | */ |
| 116 | |
| 117 | /* Register mapping routines */ |
| 118 | extern uint32 *spi_reg_map(osl_t *osh, uintptr addr, int size); |
| 119 | extern void spi_reg_unmap(osl_t *osh, uintptr addr, int size); |
| 120 | |
| 121 | /* Interrupt (de)registration routines */ |
| 122 | extern int spi_register_irq(sdioh_info_t *sd, uint irq); |
| 123 | extern void spi_free_irq(uint irq, sdioh_info_t *sd); |
| 124 | |
| 125 | /* OS-specific interrupt wrappers (atomic interrupt enable/disable) */ |
| 126 | extern void spi_lock(sdioh_info_t *sd); |
| 127 | extern void spi_unlock(sdioh_info_t *sd); |
| 128 | |
| 129 | /* Allocate/init/free per-OS private data */ |
| 130 | extern int spi_osinit(sdioh_info_t *sd); |
| 131 | extern void spi_osfree(sdioh_info_t *sd); |