xref: /OK3568_Linux_fs/external/rkwifibt/drivers/infineon/include/bcmsdstd.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun  *  'Standard' SDIO HOST CONTROLLER driver
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: bcmsdstd.h 663318 2016-10-04 19:02:16Z $
30*4882a593Smuzhiyun  */
31*4882a593Smuzhiyun #ifndef	_BCM_SD_STD_H
32*4882a593Smuzhiyun #define	_BCM_SD_STD_H
33*4882a593Smuzhiyun 
34*4882a593Smuzhiyun /* global msglevel for debug messages - bitvals come from sdiovar.h */
35*4882a593Smuzhiyun #define sd_err(x)	do { if (sd_msglevel & SDH_ERROR_VAL) printf x; } while (0)
36*4882a593Smuzhiyun #define sd_trace(x)
37*4882a593Smuzhiyun #define sd_info(x)
38*4882a593Smuzhiyun #define sd_debug(x)
39*4882a593Smuzhiyun #define sd_data(x)
40*4882a593Smuzhiyun #define sd_ctrl(x)
41*4882a593Smuzhiyun #define sd_dma(x)
42*4882a593Smuzhiyun 
43*4882a593Smuzhiyun #define sd_sync_dma(sd, read, nbytes)
44*4882a593Smuzhiyun #define sd_init_dma(sd)
45*4882a593Smuzhiyun #define sd_ack_intr(sd)
46*4882a593Smuzhiyun #define sd_wakeup(sd);
47*4882a593Smuzhiyun /* Allocate/init/free per-OS private data */
48*4882a593Smuzhiyun extern int sdstd_osinit(sdioh_info_t *sd);
49*4882a593Smuzhiyun extern void sdstd_osfree(sdioh_info_t *sd);
50*4882a593Smuzhiyun 
51*4882a593Smuzhiyun #define sd_log(x)
52*4882a593Smuzhiyun 
53*4882a593Smuzhiyun #define SDIOH_ASSERT(exp) \
54*4882a593Smuzhiyun 	do { if (!(exp)) \
55*4882a593Smuzhiyun 		printf("!!!ASSERT fail: file %s lines %d", __FILE__, __LINE__); \
56*4882a593Smuzhiyun 	} while (0)
57*4882a593Smuzhiyun 
58*4882a593Smuzhiyun #define BLOCK_SIZE_4318 64
59*4882a593Smuzhiyun #define BLOCK_SIZE_4328 512
60*4882a593Smuzhiyun 
61*4882a593Smuzhiyun /* internal return code */
62*4882a593Smuzhiyun #define SUCCESS	0
63*4882a593Smuzhiyun #define ERROR	1
64*4882a593Smuzhiyun 
65*4882a593Smuzhiyun /* private bus modes */
66*4882a593Smuzhiyun #define SDIOH_MODE_SPI		0
67*4882a593Smuzhiyun #define SDIOH_MODE_SD1		1
68*4882a593Smuzhiyun #define SDIOH_MODE_SD4		2
69*4882a593Smuzhiyun 
70*4882a593Smuzhiyun #define MAX_SLOTS 6 	/* For PCI: Only 6 BAR entries => 6 slots */
71*4882a593Smuzhiyun #define SDIOH_REG_WINSZ	0x100 /* Number of registers in Standard Host Controller */
72*4882a593Smuzhiyun 
73*4882a593Smuzhiyun #define SDIOH_TYPE_ARASAN_HDK	1
74*4882a593Smuzhiyun #define SDIOH_TYPE_BCM27XX	2
75*4882a593Smuzhiyun #define SDIOH_TYPE_TI_PCIXX21	4	/* TI PCIxx21 Standard Host Controller */
76*4882a593Smuzhiyun #define SDIOH_TYPE_RICOH_R5C822	5	/* Ricoh Co Ltd R5C822 SD/SDIO/MMC/MS/MSPro Host Adapter */
77*4882a593Smuzhiyun #define SDIOH_TYPE_JMICRON	6	/* JMicron Standard SDIO Host Controller */
78*4882a593Smuzhiyun 
79*4882a593Smuzhiyun /* For linux, allow yielding for dongle */
80*4882a593Smuzhiyun #define BCMSDYIELD
81*4882a593Smuzhiyun 
82*4882a593Smuzhiyun /* Expected card status value for CMD7 */
83*4882a593Smuzhiyun #define SDIOH_CMD7_EXP_STATUS   0x00001E00
84*4882a593Smuzhiyun 
85*4882a593Smuzhiyun #define RETRIES_LARGE 100000
86*4882a593Smuzhiyun #ifdef BCMQT
87*4882a593Smuzhiyun extern void sdstd_os_yield(sdioh_info_t *sd);
88*4882a593Smuzhiyun #define RETRIES_SMALL 10000
89*4882a593Smuzhiyun #else
90*4882a593Smuzhiyun #define sdstd_os_yield(sd)	do {} while (0)
91*4882a593Smuzhiyun #define RETRIES_SMALL 100
92*4882a593Smuzhiyun #endif // endif
93*4882a593Smuzhiyun 
94*4882a593Smuzhiyun #define USE_BLOCKMODE		0x2	/* Block mode can be single block or multi */
95*4882a593Smuzhiyun #define USE_MULTIBLOCK		0x4
96*4882a593Smuzhiyun 
97*4882a593Smuzhiyun #define USE_FIFO		0x8	/* Fifo vs non-fifo */
98*4882a593Smuzhiyun 
99*4882a593Smuzhiyun #define CLIENT_INTR 		0x100	/* Get rid of this! */
100*4882a593Smuzhiyun 
101*4882a593Smuzhiyun #define HC_INTR_RETUNING	0x1000
102*4882a593Smuzhiyun 
103*4882a593Smuzhiyun #ifdef BCMSDIOH_TXGLOM
104*4882a593Smuzhiyun /* Total glom pkt can not exceed 64K
105*4882a593Smuzhiyun  * need one more slot for glom padding packet
106*4882a593Smuzhiyun  */
107*4882a593Smuzhiyun #define SDIOH_MAXGLOM_SIZE	(40+1)
108*4882a593Smuzhiyun 
109*4882a593Smuzhiyun typedef struct glom_buf {
110*4882a593Smuzhiyun 	uint32 count;				/* Total number of pkts queued */
111*4882a593Smuzhiyun 	void *dma_buf_arr[SDIOH_MAXGLOM_SIZE];	/* Frame address */
112*4882a593Smuzhiyun 	ulong dma_phys_arr[SDIOH_MAXGLOM_SIZE]; /* DMA_MAPed address of frames */
113*4882a593Smuzhiyun 	uint16 nbytes[SDIOH_MAXGLOM_SIZE];	/* Size of each frame */
114*4882a593Smuzhiyun } glom_buf_t;
115*4882a593Smuzhiyun #endif // endif
116*4882a593Smuzhiyun 
117*4882a593Smuzhiyun struct sdioh_info {
118*4882a593Smuzhiyun 	uint cfg_bar;				/* pci cfg address for bar */
119*4882a593Smuzhiyun 	uint32 caps;				/* cached value of capabilities reg */
120*4882a593Smuzhiyun 	uint32 curr_caps;			/* max current capabilities reg */
121*4882a593Smuzhiyun 
122*4882a593Smuzhiyun 	osl_t		*osh;			/* osh handler */
123*4882a593Smuzhiyun 	volatile char	*mem_space;		/* pci device memory va */
124*4882a593Smuzhiyun 	uint		lockcount;		/* nest count of sdstd_lock() calls */
125*4882a593Smuzhiyun 	bool		client_intr_enabled;	/* interrupt connnected flag */
126*4882a593Smuzhiyun 	bool		intr_handler_valid;	/* client driver interrupt handler valid */
127*4882a593Smuzhiyun 	sdioh_cb_fn_t	intr_handler;		/* registered interrupt handler */
128*4882a593Smuzhiyun 	void		*intr_handler_arg;	/* argument to call interrupt handler */
129*4882a593Smuzhiyun 	bool		initialized;		/* card initialized */
130*4882a593Smuzhiyun 	uint		target_dev;		/* Target device ID */
131*4882a593Smuzhiyun 	uint16		intmask;		/* Current active interrupts */
132*4882a593Smuzhiyun 	void		*sdos_info;		/* Pointer to per-OS private data */
133*4882a593Smuzhiyun 	void		*bcmsdh;		/* handler to upper layer stack (bcmsdh) */
134*4882a593Smuzhiyun 
135*4882a593Smuzhiyun 	uint32		controller_type;	/* Host controller type */
136*4882a593Smuzhiyun 	uint8		version;		/* Host Controller Spec Compliance Version */
137*4882a593Smuzhiyun 	uint		irq;			/* Client irq */
138*4882a593Smuzhiyun 	int		intrcount;		/* Client interrupts */
139*4882a593Smuzhiyun 	int		local_intrcount;	/* Controller interrupts */
140*4882a593Smuzhiyun 	bool		host_init_done;		/* Controller initted */
141*4882a593Smuzhiyun 	bool		card_init_done;		/* Client SDIO interface initted */
142*4882a593Smuzhiyun 	bool		polled_mode;		/* polling for command completion */
143*4882a593Smuzhiyun 
144*4882a593Smuzhiyun 	bool		sd_blockmode;		/* sd_blockmode == FALSE => 64 Byte Cmd 53s. */
145*4882a593Smuzhiyun 						/*  Must be on for sd_multiblock to be effective */
146*4882a593Smuzhiyun 	bool		use_client_ints;	/* If this is false, make sure to restore */
147*4882a593Smuzhiyun 						/*  polling hack in wl_linux.c:wl_timer() */
148*4882a593Smuzhiyun 	int		adapter_slot;		/* Maybe dealing with multiple slots/controllers */
149*4882a593Smuzhiyun 	int		sd_mode;		/* SD1/SD4/SPI */
150*4882a593Smuzhiyun 	int		client_block_size[SDIOD_MAX_IOFUNCS];		/* Blocksize */
151*4882a593Smuzhiyun 	uint32		data_xfer_count;	/* Current transfer */
152*4882a593Smuzhiyun 	uint16		card_rca;		/* Current Address */
153*4882a593Smuzhiyun 	int8		sd_dma_mode;		/* DMA Mode (PIO, SDMA, ... ADMA2) on CMD53 */
154*4882a593Smuzhiyun 	uint8		num_funcs;		/* Supported funcs on client */
155*4882a593Smuzhiyun 	uint32		com_cis_ptr;
156*4882a593Smuzhiyun 	uint32		func_cis_ptr[SDIOD_MAX_IOFUNCS];
157*4882a593Smuzhiyun 	void		*dma_buf;		/* DMA Buffer virtual address */
158*4882a593Smuzhiyun 	ulong		dma_phys;		/* DMA Buffer physical address */
159*4882a593Smuzhiyun 	void		*adma2_dscr_buf;	/* ADMA2 Descriptor Buffer virtual address */
160*4882a593Smuzhiyun 	ulong		adma2_dscr_phys;	/* ADMA2 Descriptor Buffer physical address */
161*4882a593Smuzhiyun 
162*4882a593Smuzhiyun 	/* adjustments needed to make the dma align properly */
163*4882a593Smuzhiyun 	void		*dma_start_buf;
164*4882a593Smuzhiyun 	ulong		dma_start_phys;
165*4882a593Smuzhiyun 	uint		alloced_dma_size;
166*4882a593Smuzhiyun 	void		*adma2_dscr_start_buf;
167*4882a593Smuzhiyun 	ulong		adma2_dscr_start_phys;
168*4882a593Smuzhiyun 	uint		alloced_adma2_dscr_size;
169*4882a593Smuzhiyun 
170*4882a593Smuzhiyun 	int		r_cnt;			/* rx count */
171*4882a593Smuzhiyun 	int		t_cnt;			/* tx_count */
172*4882a593Smuzhiyun 	bool		got_hcint;		/* local interrupt flag */
173*4882a593Smuzhiyun 	uint16		last_intrstatus;	/* to cache intrstatus */
174*4882a593Smuzhiyun 	int	host_UHSISupported;		/* whether UHSI is supported for HC. */
175*4882a593Smuzhiyun 	int	card_UHSI_voltage_Supported;	/* whether UHSI is supported for
176*4882a593Smuzhiyun 						 * Card in terms of Voltage [1.8 or 3.3].
177*4882a593Smuzhiyun 						 */
178*4882a593Smuzhiyun 	int	global_UHSI_Supp;	/* type of UHSI support in both host and card.
179*4882a593Smuzhiyun 					 * HOST_SDR_UNSUPP: capabilities not supported/matched
180*4882a593Smuzhiyun 					 * HOST_SDR_12_25: SDR12 and SDR25 supported
181*4882a593Smuzhiyun 					 * HOST_SDR_50_104_DDR: one of SDR50/SDR104 or DDR50 supptd
182*4882a593Smuzhiyun 					 */
183*4882a593Smuzhiyun 	volatile int	sd3_dat_state;		/* data transfer state used for retuning check */
184*4882a593Smuzhiyun 	volatile int	sd3_tun_state;		/* tuning state used for retuning check */
185*4882a593Smuzhiyun 	bool	sd3_tuning_reqd;	/* tuning requirement parameter */
186*4882a593Smuzhiyun 	bool	sd3_tuning_disable;	/* tuning disable due to bus sleeping */
187*4882a593Smuzhiyun 	uint32	caps3;			/* cached value of 32 MSbits capabilities reg (SDIO 3.0) */
188*4882a593Smuzhiyun #ifdef BCMSDIOH_TXGLOM
189*4882a593Smuzhiyun 	glom_buf_t glom_info;		/* pkt information used for glomming */
190*4882a593Smuzhiyun 	uint	txglom_mode;		/* Txglom mode: 0 - copy, 1 - multi-descriptor */
191*4882a593Smuzhiyun #endif // endif
192*4882a593Smuzhiyun };
193*4882a593Smuzhiyun 
194*4882a593Smuzhiyun #define DMA_MODE_NONE	0
195*4882a593Smuzhiyun #define DMA_MODE_SDMA	1
196*4882a593Smuzhiyun #define DMA_MODE_ADMA1	2
197*4882a593Smuzhiyun #define DMA_MODE_ADMA2	3
198*4882a593Smuzhiyun #define DMA_MODE_ADMA2_64 4
199*4882a593Smuzhiyun #define DMA_MODE_AUTO	-1
200*4882a593Smuzhiyun 
201*4882a593Smuzhiyun #define USE_DMA(sd)		((bool)((sd->sd_dma_mode > 0) ? TRUE : FALSE))
202*4882a593Smuzhiyun 
203*4882a593Smuzhiyun /* States for Tuning and corr data */
204*4882a593Smuzhiyun #define TUNING_IDLE 			0
205*4882a593Smuzhiyun #define TUNING_START 			1
206*4882a593Smuzhiyun #define TUNING_START_AFTER_DAT 	2
207*4882a593Smuzhiyun #define TUNING_ONGOING 			3
208*4882a593Smuzhiyun 
209*4882a593Smuzhiyun #define DATA_TRANSFER_IDLE 		0
210*4882a593Smuzhiyun #define DATA_TRANSFER_ONGOING	1
211*4882a593Smuzhiyun 
212*4882a593Smuzhiyun #define CHECK_TUNING_PRE_DATA	1
213*4882a593Smuzhiyun #define CHECK_TUNING_POST_DATA	2
214*4882a593Smuzhiyun 
215*4882a593Smuzhiyun #ifdef DHD_DEBUG
216*4882a593Smuzhiyun #define SD_DHD_DISABLE_PERIODIC_TUNING 0x01
217*4882a593Smuzhiyun #define SD_DHD_ENABLE_PERIODIC_TUNING  0x00
218*4882a593Smuzhiyun #endif // endif
219*4882a593Smuzhiyun 
220*4882a593Smuzhiyun /************************************************************
221*4882a593Smuzhiyun  * Internal interfaces: per-port references into bcmsdstd.c
222*4882a593Smuzhiyun  */
223*4882a593Smuzhiyun 
224*4882a593Smuzhiyun /* Global message bits */
225*4882a593Smuzhiyun extern uint sd_msglevel;
226*4882a593Smuzhiyun 
227*4882a593Smuzhiyun /* OS-independent interrupt handler */
228*4882a593Smuzhiyun extern bool check_client_intr(sdioh_info_t *sd);
229*4882a593Smuzhiyun 
230*4882a593Smuzhiyun /* Core interrupt enable/disable of device interrupts */
231*4882a593Smuzhiyun extern void sdstd_devintr_on(sdioh_info_t *sd);
232*4882a593Smuzhiyun extern void sdstd_devintr_off(sdioh_info_t *sd);
233*4882a593Smuzhiyun 
234*4882a593Smuzhiyun /* Enable/disable interrupts for local controller events */
235*4882a593Smuzhiyun extern void sdstd_intrs_on(sdioh_info_t *sd, uint16 norm, uint16 err);
236*4882a593Smuzhiyun extern void sdstd_intrs_off(sdioh_info_t *sd, uint16 norm, uint16 err);
237*4882a593Smuzhiyun 
238*4882a593Smuzhiyun /* Wait for specified interrupt and error bits to be set */
239*4882a593Smuzhiyun extern void sdstd_spinbits(sdioh_info_t *sd, uint16 norm, uint16 err);
240*4882a593Smuzhiyun 
241*4882a593Smuzhiyun /**************************************************************
242*4882a593Smuzhiyun  * Internal interfaces: bcmsdstd.c references to per-port code
243*4882a593Smuzhiyun  */
244*4882a593Smuzhiyun 
245*4882a593Smuzhiyun /* Register mapping routines */
246*4882a593Smuzhiyun extern uint32 *sdstd_reg_map(osl_t *osh, ulong addr, int size);
247*4882a593Smuzhiyun extern void sdstd_reg_unmap(osl_t *osh, ulong addr, int size);
248*4882a593Smuzhiyun 
249*4882a593Smuzhiyun /* Interrupt (de)registration routines */
250*4882a593Smuzhiyun extern int sdstd_register_irq(sdioh_info_t *sd, uint irq);
251*4882a593Smuzhiyun extern void sdstd_free_irq(uint irq, sdioh_info_t *sd);
252*4882a593Smuzhiyun 
253*4882a593Smuzhiyun /* OS-specific interrupt wrappers (atomic interrupt enable/disable) */
254*4882a593Smuzhiyun extern void sdstd_lock(sdioh_info_t *sd);
255*4882a593Smuzhiyun extern void sdstd_unlock(sdioh_info_t *sd);
256*4882a593Smuzhiyun extern void sdstd_waitlockfree(sdioh_info_t *sd);
257*4882a593Smuzhiyun 
258*4882a593Smuzhiyun /* OS-specific wrappers for safe concurrent register access */
259*4882a593Smuzhiyun extern void sdstd_os_lock_irqsave(sdioh_info_t *sd, ulong* flags);
260*4882a593Smuzhiyun extern void sdstd_os_unlock_irqrestore(sdioh_info_t *sd, ulong* flags);
261*4882a593Smuzhiyun 
262*4882a593Smuzhiyun /* OS-specific wait-for-interrupt-or-status */
263*4882a593Smuzhiyun extern int sdstd_waitbits(sdioh_info_t *sd, uint16 norm, uint16 err, bool yield, uint16 *bits);
264*4882a593Smuzhiyun 
265*4882a593Smuzhiyun /* used by bcmsdstd_linux [implemented in sdstd] */
266*4882a593Smuzhiyun extern void sdstd_3_enable_retuning_int(sdioh_info_t *sd);
267*4882a593Smuzhiyun extern void sdstd_3_disable_retuning_int(sdioh_info_t *sd);
268*4882a593Smuzhiyun extern bool sdstd_3_is_retuning_int_set(sdioh_info_t *sd);
269*4882a593Smuzhiyun extern void sdstd_3_check_and_do_tuning(sdioh_info_t *sd, int tuning_param);
270*4882a593Smuzhiyun extern bool sdstd_3_check_and_set_retuning(sdioh_info_t *sd);
271*4882a593Smuzhiyun extern int sdstd_3_get_tune_state(sdioh_info_t *sd);
272*4882a593Smuzhiyun extern int sdstd_3_get_data_state(sdioh_info_t *sd);
273*4882a593Smuzhiyun extern void sdstd_3_set_tune_state(sdioh_info_t *sd, int state);
274*4882a593Smuzhiyun extern void sdstd_3_set_data_state(sdioh_info_t *sd, int state);
275*4882a593Smuzhiyun extern uint8 sdstd_3_get_tuning_exp(sdioh_info_t *sd);
276*4882a593Smuzhiyun extern uint32 sdstd_3_get_uhsi_clkmode(sdioh_info_t *sd);
277*4882a593Smuzhiyun extern int sdstd_3_clk_tuning(sdioh_info_t *sd, uint32 sd3ClkMode);
278*4882a593Smuzhiyun 
279*4882a593Smuzhiyun /* used by sdstd [implemented in bcmsdstd_linux/ndis] */
280*4882a593Smuzhiyun extern void sdstd_3_start_tuning(sdioh_info_t *sd);
281*4882a593Smuzhiyun extern void sdstd_3_osinit_tuning(sdioh_info_t *sd);
282*4882a593Smuzhiyun extern void sdstd_3_osclean_tuning(sdioh_info_t *sd);
283*4882a593Smuzhiyun 
284*4882a593Smuzhiyun extern void sdstd_enable_disable_periodic_timer(sdioh_info_t * sd, uint val);
285*4882a593Smuzhiyun 
286*4882a593Smuzhiyun extern sdioh_info_t *sdioh_attach(osl_t *osh, void *bar0, uint irq);
287*4882a593Smuzhiyun extern SDIOH_API_RC sdioh_detach(osl_t *osh, sdioh_info_t *sd);
288*4882a593Smuzhiyun #endif /* _BCM_SD_STD_H */
289