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