1*4882a593Smuzhiyun /* 2*4882a593Smuzhiyun * BCMSDH Function Driver for the native SDIO/MMC driver in the Linux Kernel 3*4882a593Smuzhiyun * 4*4882a593Smuzhiyun * Portions of this code are copyright (c) 2021 Cypress Semiconductor Corporation 5*4882a593Smuzhiyun * 6*4882a593Smuzhiyun * Copyright (C) 1999-2017, Broadcom Corporation 7*4882a593Smuzhiyun * 8*4882a593Smuzhiyun * Unless you and Broadcom execute a separate written software license 9*4882a593Smuzhiyun * agreement governing use of this software, this software is licensed to you 10*4882a593Smuzhiyun * under the terms of the GNU General Public License version 2 (the "GPL"), 11*4882a593Smuzhiyun * available at http://www.broadcom.com/licenses/GPLv2.php, with the 12*4882a593Smuzhiyun * following added to such license: 13*4882a593Smuzhiyun * 14*4882a593Smuzhiyun * As a special exception, the copyright holders of this software give you 15*4882a593Smuzhiyun * permission to link this software with independent modules, and to copy and 16*4882a593Smuzhiyun * distribute the resulting executable under terms of your choice, provided that 17*4882a593Smuzhiyun * you also meet, for each linked independent module, the terms and conditions of 18*4882a593Smuzhiyun * the license of that module. An independent module is a module which is not 19*4882a593Smuzhiyun * derived from this software. The special exception does not apply to any 20*4882a593Smuzhiyun * modifications of the software. 21*4882a593Smuzhiyun * 22*4882a593Smuzhiyun * Notwithstanding the above, under no circumstances may you combine this 23*4882a593Smuzhiyun * software in any way with any other Broadcom software provided under a license 24*4882a593Smuzhiyun * other than the GPL, without Broadcom's express prior written consent. 25*4882a593Smuzhiyun * 26*4882a593Smuzhiyun * 27*4882a593Smuzhiyun * <<Broadcom-WL-IPTag/Proprietary,Open:>> 28*4882a593Smuzhiyun * 29*4882a593Smuzhiyun * $Id: bcmsdh_sdmmc.h 690294 2017-03-15 12:33:14Z $ 30*4882a593Smuzhiyun */ 31*4882a593Smuzhiyun 32*4882a593Smuzhiyun #ifndef __BCMSDH_SDMMC_H__ 33*4882a593Smuzhiyun #define __BCMSDH_SDMMC_H__ 34*4882a593Smuzhiyun 35*4882a593Smuzhiyun #define sd_err(x) do { if (sd_msglevel & SDH_ERROR_VAL) printf x; } while (0) 36*4882a593Smuzhiyun #define sd_trace(x) do { if (sd_msglevel & SDH_TRACE_VAL) printf x; } while (0) 37*4882a593Smuzhiyun #define sd_info(x) do { if (sd_msglevel & SDH_INFO_VAL) printf x; } while (0) 38*4882a593Smuzhiyun #define sd_debug(x) do { if (sd_msglevel & SDH_DEBUG_VAL) printf x; } while (0) 39*4882a593Smuzhiyun #define sd_data(x) do { if (sd_msglevel & SDH_DATA_VAL) printf x; } while (0) 40*4882a593Smuzhiyun #define sd_ctrl(x) do { if (sd_msglevel & SDH_CTRL_VAL) printf x; } while (0) 41*4882a593Smuzhiyun 42*4882a593Smuzhiyun #define sd_sync_dma(sd, read, nbytes) 43*4882a593Smuzhiyun #define sd_init_dma(sd) 44*4882a593Smuzhiyun #define sd_ack_intr(sd) 45*4882a593Smuzhiyun #define sd_wakeup(sd); 46*4882a593Smuzhiyun 47*4882a593Smuzhiyun #define sd_log(x) 48*4882a593Smuzhiyun 49*4882a593Smuzhiyun #define SDIOH_ASSERT(exp) \ 50*4882a593Smuzhiyun do { if (!(exp)) \ 51*4882a593Smuzhiyun printf("!!!ASSERT fail: file %s lines %d", __FILE__, __LINE__); \ 52*4882a593Smuzhiyun } while (0) 53*4882a593Smuzhiyun 54*4882a593Smuzhiyun #define BLOCK_SIZE_4318 64 55*4882a593Smuzhiyun #define BLOCK_SIZE_4328 512 56*4882a593Smuzhiyun 57*4882a593Smuzhiyun /* internal return code */ 58*4882a593Smuzhiyun #define SUCCESS 0 59*4882a593Smuzhiyun #define ERROR 1 60*4882a593Smuzhiyun 61*4882a593Smuzhiyun /* private bus modes */ 62*4882a593Smuzhiyun #define SDIOH_MODE_SD4 2 63*4882a593Smuzhiyun #define CLIENT_INTR 0x100 /* Get rid of this! */ 64*4882a593Smuzhiyun #define SDIOH_SDMMC_MAX_SG_ENTRIES 64 65*4882a593Smuzhiyun 66*4882a593Smuzhiyun struct sdioh_info { 67*4882a593Smuzhiyun osl_t *osh; /* osh handler */ 68*4882a593Smuzhiyun void *bcmsdh; /* upper layer handle */ 69*4882a593Smuzhiyun bool client_intr_enabled; /* interrupt connnected flag */ 70*4882a593Smuzhiyun bool intr_handler_valid; /* client driver interrupt handler valid */ 71*4882a593Smuzhiyun sdioh_cb_fn_t intr_handler; /* registered interrupt handler */ 72*4882a593Smuzhiyun void *intr_handler_arg; /* argument to call interrupt handler */ 73*4882a593Smuzhiyun uint16 intmask; /* Current active interrupts */ 74*4882a593Smuzhiyun 75*4882a593Smuzhiyun int intrcount; /* Client interrupts */ 76*4882a593Smuzhiyun bool sd_use_dma; /* DMA on CMD53 */ 77*4882a593Smuzhiyun bool sd_blockmode; /* sd_blockmode == FALSE => 64 Byte Cmd 53s. */ 78*4882a593Smuzhiyun /* Must be on for sd_multiblock to be effective */ 79*4882a593Smuzhiyun bool use_client_ints; /* If this is false, make sure to restore */ 80*4882a593Smuzhiyun int sd_mode; /* SD1/SD4/SPI */ 81*4882a593Smuzhiyun int client_block_size[SDIOD_MAX_IOFUNCS]; /* Blocksize */ 82*4882a593Smuzhiyun uint8 num_funcs; /* Supported funcs on client */ 83*4882a593Smuzhiyun uint32 com_cis_ptr; 84*4882a593Smuzhiyun uint32 func_cis_ptr[SDIOD_MAX_IOFUNCS]; 85*4882a593Smuzhiyun bool use_rxchain; 86*4882a593Smuzhiyun struct scatterlist sg_list[SDIOH_SDMMC_MAX_SG_ENTRIES]; 87*4882a593Smuzhiyun struct sdio_func fake_func0; 88*4882a593Smuzhiyun struct sdio_func *func[SDIOD_MAX_IOFUNCS]; 89*4882a593Smuzhiyun uint sd_clk_rate; 90*4882a593Smuzhiyun }; 91*4882a593Smuzhiyun 92*4882a593Smuzhiyun /************************************************************ 93*4882a593Smuzhiyun * Internal interfaces: per-port references into bcmsdh_sdmmc.c 94*4882a593Smuzhiyun */ 95*4882a593Smuzhiyun 96*4882a593Smuzhiyun /* Global message bits */ 97*4882a593Smuzhiyun extern uint sd_msglevel; 98*4882a593Smuzhiyun 99*4882a593Smuzhiyun /* OS-independent interrupt handler */ 100*4882a593Smuzhiyun extern bool check_client_intr(sdioh_info_t *sd); 101*4882a593Smuzhiyun 102*4882a593Smuzhiyun /* Core interrupt enable/disable of device interrupts */ 103*4882a593Smuzhiyun extern void sdioh_sdmmc_devintr_on(sdioh_info_t *sd); 104*4882a593Smuzhiyun extern void sdioh_sdmmc_devintr_off(sdioh_info_t *sd); 105*4882a593Smuzhiyun 106*4882a593Smuzhiyun /************************************************************** 107*4882a593Smuzhiyun * Internal interfaces: bcmsdh_sdmmc.c references to per-port code 108*4882a593Smuzhiyun */ 109*4882a593Smuzhiyun 110*4882a593Smuzhiyun /* Register mapping routines */ 111*4882a593Smuzhiyun extern uint32 *sdioh_sdmmc_reg_map(osl_t *osh, int32 addr, int size); 112*4882a593Smuzhiyun extern void sdioh_sdmmc_reg_unmap(osl_t *osh, int32 addr, int size); 113*4882a593Smuzhiyun 114*4882a593Smuzhiyun /* Interrupt (de)registration routines */ 115*4882a593Smuzhiyun extern int sdioh_sdmmc_register_irq(sdioh_info_t *sd, uint irq); 116*4882a593Smuzhiyun extern void sdioh_sdmmc_free_irq(uint irq, sdioh_info_t *sd); 117*4882a593Smuzhiyun 118*4882a593Smuzhiyun extern sdioh_info_t *sdioh_attach(osl_t *osh, struct sdio_func *func); 119*4882a593Smuzhiyun extern SDIOH_API_RC sdioh_detach(osl_t *osh, sdioh_info_t *sd); 120*4882a593Smuzhiyun #endif /* __BCMSDH_SDMMC_H__ */ 121