1 /* 2 * BCMSDH Function Driver for the native SDIO/MMC driver in the Linux Kernel 3 * 4 * Copyright (C) 2020, Broadcom. 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 * 21 * <<Broadcom-WL-IPTag/Dual:>> 22 */ 23 24 #ifndef __BCMSDH_SDMMC_H__ 25 #define __BCMSDH_SDMMC_H__ 26 27 #define sd_err(x) do { if (sd_msglevel & SDH_ERROR_VAL) printf x; } while (0) 28 #define sd_trace(x) do { if (sd_msglevel & SDH_TRACE_VAL) printf x; } while (0) 29 #define sd_info(x) do { if (sd_msglevel & SDH_INFO_VAL) printf x; } while (0) 30 #define sd_debug(x) do { if (sd_msglevel & SDH_DEBUG_VAL) printf x; } while (0) 31 #define sd_data(x) do { if (sd_msglevel & SDH_DATA_VAL) printf x; } while (0) 32 #define sd_ctrl(x) do { if (sd_msglevel & SDH_CTRL_VAL) printf x; } while (0) 33 #define sd_cost(x) do { if (sd_msglevel & SDH_COST_VAL) printf x; } while (0) 34 35 #define sd_sync_dma(sd, read, nbytes) 36 #define sd_init_dma(sd) 37 #define sd_ack_intr(sd) 38 #define sd_wakeup(sd); 39 40 #ifdef BCMPERFSTATS 41 #define sd_log(x) do { if (sd_msglevel & SDH_LOG_VAL) bcmlog x; } while (0) 42 #else 43 #define sd_log(x) 44 #endif 45 46 #define SDIOH_ASSERT(exp) \ 47 do { if (!(exp)) \ 48 printf("!!!ASSERT fail: file %s lines %d", __FILE__, __LINE__); \ 49 } while (0) 50 51 #define BLOCK_SIZE_4318 64 52 #define BLOCK_SIZE_4328 512 53 54 /* internal return code */ 55 #define SUCCESS 0 56 #define ERROR 1 57 58 /* private bus modes */ 59 #define SDIOH_MODE_SD4 2 60 #define CLIENT_INTR 0x100 /* Get rid of this! */ 61 #define SDIOH_SDMMC_MAX_SG_ENTRIES 64 62 63 struct sdioh_info { 64 osl_t *osh; /* osh handler */ 65 void *bcmsdh; /* upper layer handle */ 66 bool client_intr_enabled; /* interrupt connnected flag */ 67 bool intr_handler_valid; /* client driver interrupt handler valid */ 68 sdioh_cb_fn_t intr_handler; /* registered interrupt handler */ 69 void *intr_handler_arg; /* argument to call interrupt handler */ 70 uint16 intmask; /* Current active interrupts */ 71 72 int intrcount; /* Client interrupts */ 73 bool sd_use_dma; /* DMA on CMD53 */ 74 bool sd_blockmode; /* sd_blockmode == FALSE => 64 Byte Cmd 53s. */ 75 /* Must be on for sd_multiblock to be effective */ 76 bool use_client_ints; /* If this is false, make sure to restore */ 77 int sd_mode; /* SD1/SD4/SPI */ 78 int client_block_size[SDIOD_MAX_IOFUNCS]; /* Blocksize */ 79 uint8 num_funcs; /* Supported funcs on client */ 80 uint32 com_cis_ptr; 81 uint32 func_cis_ptr[SDIOD_MAX_IOFUNCS]; 82 bool use_rxchain; 83 struct scatterlist sg_list[SDIOH_SDMMC_MAX_SG_ENTRIES]; 84 struct sdio_func fake_func0; 85 struct sdio_func *func[SDIOD_MAX_IOFUNCS]; 86 uint sd_clk_rate; 87 uint txglom_mode; /* Txglom mode: 0 - copy, 1 - multi-descriptor */ 88 #if defined(BCMSDIOH_TXGLOM) && defined(BCMSDIOH_STATIC_COPY_BUF) 89 uint8 *copy_buf; 90 #endif 91 #ifdef PKT_STATICS 92 uint32 sdio_spent_time_us; 93 #endif 94 #if !defined(OOB_INTR_ONLY) 95 struct mutex claim_host_mutex; // terence 20140926: fix for claim host issue 96 #endif 97 }; 98 99 /************************************************************ 100 * Internal interfaces: per-port references into bcmsdh_sdmmc.c 101 */ 102 103 /* Global message bits */ 104 extern uint sd_msglevel; 105 106 /* OS-independent interrupt handler */ 107 extern bool check_client_intr(sdioh_info_t *sd); 108 109 /* Core interrupt enable/disable of device interrupts */ 110 extern void sdioh_sdmmc_devintr_on(sdioh_info_t *sd); 111 extern void sdioh_sdmmc_devintr_off(sdioh_info_t *sd); 112 113 /************************************************************** 114 * Internal interfaces: bcmsdh_sdmmc.c references to per-port code 115 */ 116 117 /* Register mapping routines */ 118 extern uint32 *sdioh_sdmmc_reg_map(osl_t *osh, int32 addr, int size); 119 extern void sdioh_sdmmc_reg_unmap(osl_t *osh, int32 addr, int size); 120 121 /* Interrupt (de)registration routines */ 122 extern int sdioh_sdmmc_register_irq(sdioh_info_t *sd, uint irq); 123 extern void sdioh_sdmmc_free_irq(uint irq, sdioh_info_t *sd); 124 125 extern sdioh_info_t *sdioh_attach(osl_t *osh, struct sdio_func *func); 126 extern SDIOH_API_RC sdioh_detach(osl_t *osh, sdioh_info_t *sd); 127 128 #ifdef GLOBAL_SDMMC_INSTANCE 129 typedef struct _BCMSDH_SDMMC_INSTANCE { 130 sdioh_info_t *sd; 131 struct sdio_func *func[SDIOD_MAX_IOFUNCS]; 132 } BCMSDH_SDMMC_INSTANCE, *PBCMSDH_SDMMC_INSTANCE; 133 #endif 134 135 #endif /* __BCMSDH_SDMMC_H__ */ 136