xref: /OK3568_Linux_fs/external/rkwifibt/drivers/bcmdhd/bcmsdspi.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /*
2  * SD-SPI Protocol Conversion - BCMSDH->SPI 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/Open:>>
22  *
23  * $Id: bcmsdspi.h 833013 2019-08-02 16:26:31Z jl904071 $
24  */
25 #ifndef	_BCM_SD_SPI_H
26 #define	_BCM_SD_SPI_H
27 
28 /* global msglevel for debug messages - bitvals come from sdiovar.h */
29 
30 #ifdef BCMDBG
31 #define sd_err(x)	do { if (sd_msglevel & SDH_ERROR_VAL) printf x; } while (0)
32 #define sd_trace(x)	do { if (sd_msglevel & SDH_TRACE_VAL) printf x; } while (0)
33 #define sd_info(x)	do { if (sd_msglevel & SDH_INFO_VAL)  printf x; } while (0)
34 #define sd_debug(x)	do { if (sd_msglevel & SDH_DEBUG_VAL) printf x; } while (0)
35 #define sd_data(x)	do { if (sd_msglevel & SDH_DATA_VAL)  printf x; } while (0)
36 #define sd_ctrl(x)	do { if (sd_msglevel & SDH_CTRL_VAL)  printf x; } while (0)
37 #else
38 #define sd_err(x)
39 #define sd_trace(x)
40 #define sd_info(x)
41 #define sd_debug(x)
42 #define sd_data(x)
43 #define sd_ctrl(x)
44 #endif
45 
46 #ifdef BCMPERFSTATS
47 #define sd_log(x)	do { if (sd_msglevel & SDH_LOG_VAL)	 bcmlog x; } while (0)
48 #else
49 #define sd_log(x)
50 #endif
51 
52 #define SDIOH_ASSERT(exp) \
53 	do { if (!(exp)) \
54 		printf("!!!ASSERT fail: file %s lines %d", __FILE__, __LINE__); \
55 	} while (0)
56 
57 #define BLOCK_SIZE_4318 64
58 #define BLOCK_SIZE_4328 512
59 
60 /* internal return code */
61 #define SUCCESS	0
62 #undef ERROR
63 #define ERROR	1
64 
65 /* private bus modes */
66 #define SDIOH_MODE_SPI		0
67 
68 #define USE_BLOCKMODE		0x2	/* Block mode can be single block or multi */
69 #define USE_MULTIBLOCK		0x4
70 
71 struct sdioh_info {
72 	uint cfg_bar;                   	/* pci cfg address for bar */
73 	uint32 caps;                    	/* cached value of capabilities reg */
74 	uint		bar0;			/* BAR0 for PCI Device */
75 	osl_t 		*osh;			/* osh handler */
76 	void		*controller;	/* Pointer to SPI Controller's private data struct */
77 
78 	uint		lockcount; 		/* nest count of sdspi_lock() calls */
79 	bool		client_intr_enabled;	/* interrupt connnected flag */
80 	bool		intr_handler_valid;	/* client driver interrupt handler valid */
81 	sdioh_cb_fn_t	intr_handler;		/* registered interrupt handler */
82 	void		*intr_handler_arg;	/* argument to call interrupt handler */
83 	bool		initialized;		/* card initialized */
84 	uint32		target_dev;		/* Target device ID */
85 	uint32		intmask;		/* Current active interrupts */
86 	void		*sdos_info;		/* Pointer to per-OS private data */
87 
88 	uint32		controller_type;	/* Host controller type */
89 	uint8		version;		/* Host Controller Spec Compliance Version */
90 	uint 		irq;			/* Client irq */
91 	uint32 		intrcount;		/* Client interrupts */
92 	uint32 		local_intrcount;	/* Controller interrupts */
93 	bool 		host_init_done;		/* Controller initted */
94 	bool 		card_init_done;		/* Client SDIO interface initted */
95 	bool 		polled_mode;		/* polling for command completion */
96 
97 	bool		sd_use_dma;		/* DMA on CMD53 */
98 	bool 		sd_blockmode;		/* sd_blockmode == FALSE => 64 Byte Cmd 53s. */
99 						/*  Must be on for sd_multiblock to be effective */
100 	bool 		use_client_ints;	/* If this is false, make sure to restore */
101 	bool		got_hcint;		/* Host Controller interrupt. */
102 						/*  polling hack in wl_linux.c:wl_timer() */
103 	int 		adapter_slot;		/* Maybe dealing with multiple slots/controllers */
104 	int 		sd_mode;		/* SD1/SD4/SPI */
105 	int 		client_block_size[SDIOD_MAX_IOFUNCS];		/* Blocksize */
106 	uint32 		data_xfer_count;	/* Current register transfer size */
107 	uint32		cmd53_wr_data;		/* Used to pass CMD53 write data */
108 	uint32		card_response;		/* Used to pass back response status byte */
109 	uint32		card_rsp_data;		/* Used to pass back response data word */
110 	uint16 		card_rca;		/* Current Address */
111 	uint8 		num_funcs;		/* Supported funcs on client */
112 	uint32 		com_cis_ptr;
113 	uint32 		func_cis_ptr[SDIOD_MAX_IOFUNCS];
114 	void		*dma_buf;
115 	ulong		dma_phys;
116 	int 		r_cnt;			/* rx count */
117 	int 		t_cnt;			/* tx_count */
118 };
119 
120 /************************************************************
121  * Internal interfaces: per-port references into bcmsdspi.c
122  */
123 
124 /* Global message bits */
125 extern uint sd_msglevel;
126 
127 /**************************************************************
128  * Internal interfaces: bcmsdspi.c references to per-port code
129  */
130 
131 /* Register mapping routines */
132 extern uint32 *spi_reg_map(osl_t *osh, uintptr addr, int size);
133 extern void spi_reg_unmap(osl_t *osh, uintptr addr, int size);
134 
135 /* Interrupt (de)registration routines */
136 extern int spi_register_irq(sdioh_info_t *sd, uint irq);
137 extern void spi_free_irq(uint irq, sdioh_info_t *sd);
138 
139 /* OS-specific interrupt wrappers (atomic interrupt enable/disable) */
140 extern void spi_lock(sdioh_info_t *sd);
141 extern void spi_unlock(sdioh_info_t *sd);
142 
143 /* Allocate/init/free per-OS private data */
144 extern int spi_osinit(sdioh_info_t *sd);
145 extern void spi_osfree(sdioh_info_t *sd);
146 
147 #endif /* _BCM_SD_SPI_H */
148