• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * SD-SPI Protocol Conversion - BCMSDH->gSPI Translation Layer
4  *
5  * Copyright (C) 1999-2019, Broadcom.
6  *
7  *      Unless you and Broadcom execute a separate written software license
8  * agreement governing use of this software, this software is licensed to you
9  * under the terms of the GNU General Public License version 2 (the "GPL"),
10  * available at http://www.broadcom.com/licenses/GPLv2.php, with the
11  * following added to such license:
12  *
13  *      As a special exception, the copyright holders of this software give you
14  * permission to link this software with independent modules, and to copy and
15  * distribute the resulting executable under terms of your choice, provided that
16  * you also meet, for each linked independent module, the terms and conditions of
17  * the license of that module.  An independent module is a module which is not
18  * derived from this software.  The special exception does not apply to any
19  * modifications of the software.
20  *
21  *      Notwithstanding the above, under no circumstances may you combine this
22  * software in any way with any other Broadcom software provided under a license
23  * other than the GPL, without Broadcom's express prior written consent.
24  *
25  *
26  * <<Broadcom-WL-IPTag/Open:>>
27  *
28  * $Id: bcmspibrcm.h 514727 2014-11-12 03:02:48Z $
29  */
30 #ifndef	_BCM_SPI_BRCM_H
31 #define	_BCM_SPI_BRCM_H
32 
33 #ifndef SPI_MAX_IOFUNCS
34 /* Maximum number of I/O funcs */
35 #define SPI_MAX_IOFUNCS		4
36 #endif // endif
37 /* global msglevel for debug messages - bitvals come from sdiovar.h */
38 
39 #if defined(DHD_DEBUG)
40 #define sd_err(x)	do { if (sd_msglevel & SDH_ERROR_VAL) printf x; } while (0)
41 #define sd_trace(x)	do { if (sd_msglevel & SDH_TRACE_VAL) printf x; } while (0)
42 #define sd_info(x)	do { if (sd_msglevel & SDH_INFO_VAL)  printf x; } while (0)
43 #define sd_debug(x)	do { if (sd_msglevel & SDH_DEBUG_VAL) printf x; } while (0)
44 #define sd_data(x)	do { if (sd_msglevel & SDH_DATA_VAL)  printf x; } while (0)
45 #define sd_ctrl(x)	do { if (sd_msglevel & SDH_CTRL_VAL)  printf x; } while (0)
46 #else
47 #define sd_err(x)
48 #define sd_trace(x)
49 #define sd_info(x)
50 #define sd_debug(x)
51 #define sd_data(x)
52 #define sd_ctrl(x)
53 #endif // endif
54 
55 #define sd_log(x)
56 
57 #define SDIOH_ASSERT(exp) \
58 	do { if (!(exp)) \
59 		printf("!!!ASSERT fail: file %s lines %d", __FILE__, __LINE__); \
60 	} while (0)
61 
62 #define BLOCK_SIZE_F1		64
63 #define BLOCK_SIZE_F2 		2048
64 #define BLOCK_SIZE_F3 		2048
65 
66 /* internal return code */
67 #define SUCCESS	0
68 #undef ERROR
69 #define ERROR	1
70 #define ERROR_UF	2
71 #define ERROR_OF	3
72 
73 /* private bus modes */
74 #define SDIOH_MODE_SPI		0
75 
76 #define USE_BLOCKMODE		0x2	/* Block mode can be single block or multi */
77 #define USE_MULTIBLOCK		0x4
78 
79 struct sdioh_info {
80 	uint		cfg_bar;		/* pci cfg address for bar */
81 	uint32		caps;			/* cached value of capabilities reg */
82 #ifndef BCMSPI_ANDROID
83 	void		*bar0;			/* BAR0 for PCI Device */
84 #endif /* !BCMSPI_ANDROID */
85 	osl_t		*osh;			/* osh handler */
86 	void		*controller;	/* Pointer to SPI Controller's private data struct */
87 	uint		lockcount;		/* nest count of spi_lock() calls */
88 	bool		client_intr_enabled;	/* interrupt connnected flag */
89 	bool		intr_handler_valid;	/* client driver interrupt handler valid */
90 	sdioh_cb_fn_t	intr_handler;		/* registered interrupt handler */
91 	void		*intr_handler_arg;	/* argument to call interrupt handler */
92 	bool		initialized;		/* card initialized */
93 	uint32		target_dev;		/* Target device ID */
94 	uint32		intmask;		/* Current active interrupts */
95 	void		*sdos_info;		/* Pointer to per-OS private data */
96 	uint32		controller_type;	/* Host controller type */
97 	uint8		version;		/* Host Controller Spec Compliance Version */
98 	uint		irq;			/* Client irq */
99 	uint32		intrcount;		/* Client interrupts */
100 	uint32		local_intrcount;	/* Controller interrupts */
101 	bool 		host_init_done;		/* Controller initted */
102 	bool 		card_init_done;		/* Client SDIO interface initted */
103 	bool 		polled_mode;		/* polling for command completion */
104 
105 	bool		sd_use_dma;		/* DMA on CMD53 */
106 	bool 		sd_blockmode;		/* sd_blockmode == FALSE => 64 Byte Cmd 53s. */
107 						/*  Must be on for sd_multiblock to be effective */
108 	bool 		use_client_ints;	/* If this is false, make sure to restore */
109 						/*  polling hack in wl_linux.c:wl_timer() */
110 	int 		adapter_slot;		/* Maybe dealing with multiple slots/controllers */
111 	int 		sd_mode;		/* SD1/SD4/SPI */
112 	int 		client_block_size[SPI_MAX_IOFUNCS];		/* Blocksize */
113 	uint32 		data_xfer_count;	/* Current transfer */
114 	uint16 		card_rca;		/* Current Address */
115 	uint8 		num_funcs;		/* Supported funcs on client */
116 	uint32 		card_dstatus;		/* 32bit device status */
117 	uint32 		com_cis_ptr;
118 	uint32 		func_cis_ptr[SPI_MAX_IOFUNCS];
119 	void		*dma_buf;
120 	ulong		dma_phys;
121 	int 		r_cnt;			/* rx count */
122 	int 		t_cnt;			/* tx_count */
123 	uint32		wordlen;			/* host processor 16/32bits */
124 	uint32		prev_fun;
125 	uint32		chip;
126 	uint32		chiprev;
127 	bool		resp_delay_all;
128 	bool		dwordmode;
129 	bool		resp_delay_new;
130 
131 	struct spierrstats_t spierrstats;
132 };
133 
134 /************************************************************
135  * Internal interfaces: per-port references into bcmspibrcm.c
136  */
137 
138 /* Global message bits */
139 extern uint sd_msglevel;
140 
141 /**************************************************************
142  * Internal interfaces: bcmspibrcm.c references to per-port code
143  */
144 
145 /* Interrupt (de)registration routines */
146 extern int spi_register_irq(sdioh_info_t *sd, uint irq);
147 extern void spi_free_irq(uint irq, sdioh_info_t *sd);
148 
149 /* OS-specific interrupt wrappers (atomic interrupt enable/disable) */
150 extern void spi_lock(sdioh_info_t *sd);
151 extern void spi_unlock(sdioh_info_t *sd);
152 
153 /* Allocate/init/free per-OS private data */
154 extern int spi_osinit(sdioh_info_t *sd);
155 extern void spi_osfree(sdioh_info_t *sd);
156 
157 #define SPI_RW_FLAG_M			BITFIELD_MASK(1)	/* Bit [31] - R/W Command Bit */
158 #define SPI_RW_FLAG_S			31
159 #define SPI_ACCESS_M			BITFIELD_MASK(1)	/* Bit [30] - Fixed/Incr Access */
160 #define SPI_ACCESS_S			30
161 #define SPI_FUNCTION_M			BITFIELD_MASK(2)	/* Bit [29:28] - Function Number */
162 #define SPI_FUNCTION_S			28
163 #define SPI_REG_ADDR_M			BITFIELD_MASK(17)	/* Bit [27:11] - Address */
164 #define SPI_REG_ADDR_S			11
165 #define SPI_LEN_M			BITFIELD_MASK(11)	/* Bit [10:0] - Packet length */
166 #define SPI_LEN_S			0
167 
168 #endif /* _BCM_SPI_BRCM_H */
169