1*4882a593Smuzhiyun /* 2*4882a593Smuzhiyun * SD-SPI Protocol Conversion - BCMSDH->gSPI Translation Layer 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/Open:>> 28*4882a593Smuzhiyun * 29*4882a593Smuzhiyun * $Id: bcmspibrcm.h 514727 2014-11-12 03:02:48Z $ 30*4882a593Smuzhiyun */ 31*4882a593Smuzhiyun #ifndef _BCM_SPI_BRCM_H 32*4882a593Smuzhiyun #define _BCM_SPI_BRCM_H 33*4882a593Smuzhiyun 34*4882a593Smuzhiyun #ifndef SPI_MAX_IOFUNCS 35*4882a593Smuzhiyun /* Maximum number of I/O funcs */ 36*4882a593Smuzhiyun #define SPI_MAX_IOFUNCS 4 37*4882a593Smuzhiyun #endif // endif 38*4882a593Smuzhiyun /* global msglevel for debug messages - bitvals come from sdiovar.h */ 39*4882a593Smuzhiyun 40*4882a593Smuzhiyun #if defined(DHD_DEBUG) 41*4882a593Smuzhiyun #define sd_err(x) do { if (sd_msglevel & SDH_ERROR_VAL) printf x; } while (0) 42*4882a593Smuzhiyun #define sd_trace(x) do { if (sd_msglevel & SDH_TRACE_VAL) printf x; } while (0) 43*4882a593Smuzhiyun #define sd_info(x) do { if (sd_msglevel & SDH_INFO_VAL) printf x; } while (0) 44*4882a593Smuzhiyun #define sd_debug(x) do { if (sd_msglevel & SDH_DEBUG_VAL) printf x; } while (0) 45*4882a593Smuzhiyun #define sd_data(x) do { if (sd_msglevel & SDH_DATA_VAL) printf x; } while (0) 46*4882a593Smuzhiyun #define sd_ctrl(x) do { if (sd_msglevel & SDH_CTRL_VAL) printf x; } while (0) 47*4882a593Smuzhiyun #else 48*4882a593Smuzhiyun #define sd_err(x) 49*4882a593Smuzhiyun #define sd_trace(x) 50*4882a593Smuzhiyun #define sd_info(x) 51*4882a593Smuzhiyun #define sd_debug(x) 52*4882a593Smuzhiyun #define sd_data(x) 53*4882a593Smuzhiyun #define sd_ctrl(x) 54*4882a593Smuzhiyun #endif // endif 55*4882a593Smuzhiyun 56*4882a593Smuzhiyun #define sd_log(x) 57*4882a593Smuzhiyun 58*4882a593Smuzhiyun #define SDIOH_ASSERT(exp) \ 59*4882a593Smuzhiyun do { if (!(exp)) \ 60*4882a593Smuzhiyun printf("!!!ASSERT fail: file %s lines %d", __FILE__, __LINE__); \ 61*4882a593Smuzhiyun } while (0) 62*4882a593Smuzhiyun 63*4882a593Smuzhiyun #define BLOCK_SIZE_F1 64 64*4882a593Smuzhiyun #define BLOCK_SIZE_F2 2048 65*4882a593Smuzhiyun #define BLOCK_SIZE_F3 2048 66*4882a593Smuzhiyun 67*4882a593Smuzhiyun /* internal return code */ 68*4882a593Smuzhiyun #define SUCCESS 0 69*4882a593Smuzhiyun #undef ERROR 70*4882a593Smuzhiyun #define ERROR 1 71*4882a593Smuzhiyun #define ERROR_UF 2 72*4882a593Smuzhiyun #define ERROR_OF 3 73*4882a593Smuzhiyun 74*4882a593Smuzhiyun /* private bus modes */ 75*4882a593Smuzhiyun #define SDIOH_MODE_SPI 0 76*4882a593Smuzhiyun 77*4882a593Smuzhiyun #define USE_BLOCKMODE 0x2 /* Block mode can be single block or multi */ 78*4882a593Smuzhiyun #define USE_MULTIBLOCK 0x4 79*4882a593Smuzhiyun 80*4882a593Smuzhiyun struct sdioh_info { 81*4882a593Smuzhiyun uint cfg_bar; /* pci cfg address for bar */ 82*4882a593Smuzhiyun uint32 caps; /* cached value of capabilities reg */ 83*4882a593Smuzhiyun #ifndef BCMSPI_ANDROID 84*4882a593Smuzhiyun void *bar0; /* BAR0 for PCI Device */ 85*4882a593Smuzhiyun #endif /* !BCMSPI_ANDROID */ 86*4882a593Smuzhiyun osl_t *osh; /* osh handler */ 87*4882a593Smuzhiyun void *bcmsdh; /* handler to upper layer stack (bcmsdh) */ 88*4882a593Smuzhiyun void *controller; /* Pointer to SPI Controller's private data struct */ 89*4882a593Smuzhiyun uint lockcount; /* nest count of spi_lock() calls */ 90*4882a593Smuzhiyun bool client_intr_enabled; /* interrupt connnected flag */ 91*4882a593Smuzhiyun bool intr_handler_valid; /* client driver interrupt handler valid */ 92*4882a593Smuzhiyun sdioh_cb_fn_t intr_handler; /* registered interrupt handler */ 93*4882a593Smuzhiyun void *intr_handler_arg; /* argument to call interrupt handler */ 94*4882a593Smuzhiyun bool initialized; /* card initialized */ 95*4882a593Smuzhiyun uint32 target_dev; /* Target device ID */ 96*4882a593Smuzhiyun uint32 intmask; /* Current active interrupts */ 97*4882a593Smuzhiyun void *sdos_info; /* Pointer to per-OS private data */ 98*4882a593Smuzhiyun uint32 controller_type; /* Host controller type */ 99*4882a593Smuzhiyun uint8 version; /* Host Controller Spec Compliance Version */ 100*4882a593Smuzhiyun uint irq; /* Client irq */ 101*4882a593Smuzhiyun uint32 intrcount; /* Client interrupts */ 102*4882a593Smuzhiyun uint32 local_intrcount; /* Controller interrupts */ 103*4882a593Smuzhiyun bool host_init_done; /* Controller initted */ 104*4882a593Smuzhiyun bool card_init_done; /* Client SDIO interface initted */ 105*4882a593Smuzhiyun bool polled_mode; /* polling for command completion */ 106*4882a593Smuzhiyun 107*4882a593Smuzhiyun bool sd_use_dma; /* DMA on CMD53 */ 108*4882a593Smuzhiyun bool sd_blockmode; /* sd_blockmode == FALSE => 64 Byte Cmd 53s. */ 109*4882a593Smuzhiyun /* Must be on for sd_multiblock to be effective */ 110*4882a593Smuzhiyun bool use_client_ints; /* If this is false, make sure to restore */ 111*4882a593Smuzhiyun bool got_hcint; /* Host Controller interrupt. */ 112*4882a593Smuzhiyun /* polling hack in wl_linux.c:wl_timer() */ 113*4882a593Smuzhiyun int adapter_slot; /* Maybe dealing with multiple slots/controllers */ 114*4882a593Smuzhiyun int sd_mode; /* SD1/SD4/SPI */ 115*4882a593Smuzhiyun int client_block_size[SPI_MAX_IOFUNCS]; /* Blocksize */ 116*4882a593Smuzhiyun uint32 data_xfer_count; /* Current transfer */ 117*4882a593Smuzhiyun uint16 card_rca; /* Current Address */ 118*4882a593Smuzhiyun uint8 num_funcs; /* Supported funcs on client */ 119*4882a593Smuzhiyun uint32 card_dstatus; /* 32bit device status */ 120*4882a593Smuzhiyun uint32 com_cis_ptr; 121*4882a593Smuzhiyun uint32 func_cis_ptr[SPI_MAX_IOFUNCS]; 122*4882a593Smuzhiyun void *dma_buf; 123*4882a593Smuzhiyun ulong dma_phys; 124*4882a593Smuzhiyun int r_cnt; /* rx count */ 125*4882a593Smuzhiyun int t_cnt; /* tx_count */ 126*4882a593Smuzhiyun uint32 wordlen; /* host processor 16/32bits */ 127*4882a593Smuzhiyun uint32 prev_fun; 128*4882a593Smuzhiyun uint32 chip; 129*4882a593Smuzhiyun uint32 chiprev; 130*4882a593Smuzhiyun bool resp_delay_all; 131*4882a593Smuzhiyun bool dwordmode; 132*4882a593Smuzhiyun bool resp_delay_new; 133*4882a593Smuzhiyun 134*4882a593Smuzhiyun struct spierrstats_t spierrstats; 135*4882a593Smuzhiyun }; 136*4882a593Smuzhiyun 137*4882a593Smuzhiyun /************************************************************ 138*4882a593Smuzhiyun * Internal interfaces: per-port references into bcmspibrcm.c 139*4882a593Smuzhiyun */ 140*4882a593Smuzhiyun 141*4882a593Smuzhiyun /* Global message bits */ 142*4882a593Smuzhiyun extern uint sd_msglevel; 143*4882a593Smuzhiyun 144*4882a593Smuzhiyun /************************************************************** 145*4882a593Smuzhiyun * Internal interfaces: bcmspibrcm.c references to per-port code 146*4882a593Smuzhiyun */ 147*4882a593Smuzhiyun 148*4882a593Smuzhiyun /* Interrupt (de)registration routines */ 149*4882a593Smuzhiyun extern int spi_register_irq(sdioh_info_t *sd, uint irq); 150*4882a593Smuzhiyun extern void spi_free_irq(uint irq, sdioh_info_t *sd); 151*4882a593Smuzhiyun 152*4882a593Smuzhiyun /* OS-specific interrupt wrappers (atomic interrupt enable/disable) */ 153*4882a593Smuzhiyun extern void spi_lock(sdioh_info_t *sd); 154*4882a593Smuzhiyun extern void spi_unlock(sdioh_info_t *sd); 155*4882a593Smuzhiyun 156*4882a593Smuzhiyun /* Allocate/init/free per-OS private data */ 157*4882a593Smuzhiyun extern int spi_osinit(sdioh_info_t *sd); 158*4882a593Smuzhiyun extern void spi_osfree(sdioh_info_t *sd); 159*4882a593Smuzhiyun 160*4882a593Smuzhiyun #define SPI_RW_FLAG_M BITFIELD_MASK(1) /* Bit [31] - R/W Command Bit */ 161*4882a593Smuzhiyun #define SPI_RW_FLAG_S 31 162*4882a593Smuzhiyun #define SPI_ACCESS_M BITFIELD_MASK(1) /* Bit [30] - Fixed/Incr Access */ 163*4882a593Smuzhiyun #define SPI_ACCESS_S 30 164*4882a593Smuzhiyun #define SPI_FUNCTION_M BITFIELD_MASK(2) /* Bit [29:28] - Function Number */ 165*4882a593Smuzhiyun #define SPI_FUNCTION_S 28 166*4882a593Smuzhiyun #define SPI_REG_ADDR_M BITFIELD_MASK(17) /* Bit [27:11] - Address */ 167*4882a593Smuzhiyun #define SPI_REG_ADDR_S 11 168*4882a593Smuzhiyun #define SPI_LEN_M BITFIELD_MASK(11) /* Bit [10:0] - Packet length */ 169*4882a593Smuzhiyun #define SPI_LEN_S 0 170*4882a593Smuzhiyun 171*4882a593Smuzhiyun #endif /* _BCM_SPI_BRCM_H */ 172