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