3d5e0b5c66095ddb6b9ca2504d4a04096c34c73e
[firefly-linux-kernel-4.4.55.git] / drivers / net / wireless / rockchip_wlan / esp8089 / esp_driver / esp_sif.h
1 /*
2  * Copyright (c) 2011 - 2013 Espressif System.
3  *
4  *   Serial I/F wrapper layer for eagle WLAN device,
5  *    abstraction of buses like SDIO/SIP, and provides
6  *    flow control for tx/rx layer
7  *
8  */
9
10 #ifndef _ESP_SIF_H_
11 #define _ESP_SIF_H_
12
13 #include "esp_pub.h"
14 #include <linux/mmc/host.h>
15 #include <linux/spi/spi.h>
16
17 /*
18  *  H/W SLC module definitions
19  */
20
21 #define SIF_SLC_BLOCK_SIZE                512
22
23 #define SIF_DMA_BUFFER_SIZE (64 * 1024)
24
25 /* to make the last byte located at :xffff, increase 1 byte here */
26 //#define SIF_SLC_WINDOW_END_ADDR  (0xffff + 1)
27 //#define SIF_SLC_WINDOW_END_ADDR  (0x1ffff + 1 - 0x800)
28
29 #define SIF_MAX_SCATTER_REQUESTS             4
30 #define SIF_MAX_SCATTER_ENTRIES_PER_REQ      16
31 #define SIF_MAX_SCATTER_REQ_TRANSFER_SIZE    (32 * 1024)
32
33
34 /* SIF bus request */
35 #define SIF_REQ_MAX_NUM                64
36
37 /* S/W struct mapping to slc registers */
38 typedef struct slc_host_regs {
39         /* do NOT read token_rdata
40          *
41                 u32 pf_data;
42                 u32 token_rdata;
43         */
44         u32 intr_raw;
45         u32 state_w0;
46         u32 state_w1;
47         u32 config_w0;
48         u32 config_w1;
49         u32 intr_status;
50         u32 config_w2;
51         u32 config_w3;
52         u32 config_w4;
53         u32 token_wdata;
54         u32 intr_clear;
55         u32 intr_enable;
56 } sif_slc_reg_t;
57
58
59 struct sif_req {
60         struct list_head list;
61
62         u32 address;
63
64         u8 *buffer;
65         u32 length;
66         u32 flag;
67         int status;
68         void * context;
69 };
70
71 enum io_sync_type {     
72         ESP_SIF_NOSYNC = 0,
73         ESP_SIF_SYNC, 
74 };
75
76 #ifdef ESP_USE_SDIO
77 typedef struct esp_sdio_ctrl {
78         struct sdio_func *func;
79 #else
80 typedef struct esp_spi_ctrl {
81         struct spi_device *spi;
82 #endif
83         struct esp_pub *epub;
84
85
86         struct list_head free_req;
87         struct sif_req reqs[SIF_REQ_MAX_NUM];
88
89         u8 *dma_buffer;
90
91         spinlock_t scat_lock;
92         struct list_head scat_req;
93
94         bool off;
95         atomic_t irq_handling;
96 #ifdef ESP_USE_SDIO
97         const struct sdio_device_id *id;
98 #else
99         const struct spi_device_id *id;
100 #endif
101         u32 slc_blk_sz;
102         u32 target_id;
103         u32 slc_window_end_addr;
104
105         struct slc_host_regs slc_regs;
106         atomic_t        irq_installed;
107
108 #ifdef ESP_USE_SDIO
109 } esp_sdio_ctrl_t;
110 #else
111 } esp_spi_ctrl_t;
112 #endif
113
114 #ifdef ESP_USE_SPI
115 struct esp_spi_resp {
116     u32 max_dataW_resp_size;
117     u32 max_dataR_resp_size;
118     u32 max_block_dataW_resp_size;
119     u32 max_block_dataR_resp_size;
120     u32 max_cmd_resp_size;
121     u32 data_resp_size_w;
122     u32 data_resp_size_r;
123     u32 block_w_data_resp_size_final;
124     u32 block_r_data_resp_size_final;
125 };
126 #endif
127
128 #define SIF_TO_DEVICE                    0x1
129 #define SIF_FROM_DEVICE                    0x2
130
131 #define SIF_SYNC             0x00000010
132 #define SIF_ASYNC           0x00000020
133
134 #define SIF_BYTE_BASIS              0x00000040
135 #define SIF_BLOCK_BASIS             0x00000080
136
137 #define SIF_FIXED_ADDR           0x00000100
138 #define SIF_INC_ADDR     0x00000200
139
140 #ifdef ESP_USE_SDIO
141 #define EPUB_CTRL_CHECK(_epub, _go_err) do{\
142         if (_epub == NULL) {\
143                 ESSERT(0);\
144                 goto _go_err;\
145         }\
146         if ((_epub)->sif == NULL) {\
147                 ESSERT(0);\
148                 goto _go_err;\
149         }\
150 }while(0)
151
152 #define EPUB_FUNC_CHECK(_epub, _go_err) do{\
153         if (_epub == NULL) {\
154                 ESSERT(0);\
155                 goto _go_err;\
156         }\
157         if ((_epub)->sif == NULL) {\
158                 ESSERT(0);\
159                 goto _go_err;\
160         }\
161         if (((struct esp_sdio_ctrl *)(_epub)->sif)->func == NULL) {\
162                 ESSERT(0);\
163                 goto _go_err;\
164         }\
165 }while(0)
166
167 #define EPUB_TO_CTRL(_epub) (((struct esp_sdio_ctrl *)(_epub)->sif))
168
169 #define EPUB_TO_FUNC(_epub) (((struct esp_sdio_ctrl *)(_epub)->sif)->func)
170 #endif
171
172
173 #ifdef ESP_USE_SPI
174 #define EPUB_CTRL_CHECK(_epub, _go_err) do{\
175         if (_epub == NULL) {\
176                 ESSERT(0);\
177                 goto _go_err;\
178         }\
179         if ((_epub)->sif == NULL) {\
180                 ESSERT(0);\
181                 goto _go_err;\
182         }\
183 }while(0)
184
185 #define EPUB_FUNC_CHECK(_epub, _go_err) do{\
186         if (_epub == NULL) {\
187                 ESSERT(0);\
188                 goto _go_err;\
189         }\
190         if ((_epub)->sif == NULL) {\
191                 ESSERT(0);\
192                 goto _go_err;\
193         }\
194         if (((struct esp_spi_ctrl *)(_epub)->sif)->spi == NULL) {\
195                 ESSERT(0);\
196                 goto _go_err;\
197         }\
198 }while(0)
199
200 #define EPUB_TO_CTRL(_epub) (((struct esp_spi_ctrl *)(_epub)->sif))
201
202 #define EPUB_TO_FUNC(_epub) (((struct esp_spi_ctrl *)(_epub)->sif)->spi)
203 #endif
204
205 static void inline sif_setup_req(struct sif_req *req, u32 addr, u32 flag, u32 len,
206                                  u8 * buf, void *context)
207 {
208         req->address = addr;
209         req->flag = flag;
210         req->length = len;
211         req->buffer = buf;
212         req->context = context;
213 }
214
215 void sdio_io_writeb(struct esp_pub *epub, u8 value, int addr, int *res);
216 u8 sdio_io_readb(struct esp_pub *epub, int addr, int *res);
217
218
219 void sif_enable_irq(struct esp_pub *epub);
220 void sif_disable_irq(struct esp_pub *epub);
221 void sif_disable_target_interrupt(struct esp_pub *epub);
222
223 u32 sif_get_blksz(struct esp_pub *epub);
224 u32 sif_get_target_id(struct esp_pub *epub);
225
226 #ifdef ESP_USE_SDIO
227 void sif_dsr(struct sdio_func *func);
228 int sif_io_raw(struct esp_pub *epub, u32 addr, u8 *buf, u32 len, u32 flag);
229 int sif_io_sync(struct esp_pub *epub, u32 addr, u8 *buf, u32 len, u32 flag);
230 int sif_io_async(struct esp_pub *epub, u32 addr, u8 *buf, u32 len, u32 flag, void * context);
231 int sif_lldesc_read_sync(struct esp_pub *epub, u8 *buf, u32 len);
232 int sif_lldesc_write_sync(struct esp_pub *epub, u8 *buf, u32 len);
233 int sif_lldesc_read_raw(struct esp_pub *epub, u8 *buf, u32 len, bool noround);
234 int sif_lldesc_write_raw(struct esp_pub *epub, u8 *buf, u32 len);
235 void sif_platform_check_r1_ready(struct esp_pub *epub);
236 #endif 
237
238 #ifdef ESP_USE_SPI
239 enum if_dummymode {
240         NOT_DUMMYMODE = 0,
241         DUMMYMODE,
242 };
243
244 #ifdef REGISTER_SPI_BOARD_INFO
245 void sif_platform_register_board_info(void);
246 #endif
247
248 void sif_dsr(struct spi_device *spi);
249 int sif_spi_read_mix_nosync(struct spi_device *spi, unsigned int addr, unsigned char *buf, int len, int dummymode,int reg_window);
250 int sif_spi_epub_read_mix_sync(struct esp_pub *epub, unsigned int addr,unsigned char *buf, int len, int dummymode,int reg_window);
251 int sif_spi_epub_read_mix_nosync(struct esp_pub *epub, unsigned int addr,unsigned char *buf, int len, int dummymode,int reg_window);
252 int sif_spi_read_sync(struct esp_pub *epub, unsigned char *buf, int len, int dummymode,int reg_window);
253 int sif_spi_read_nosync(struct esp_pub *epub, unsigned char *buf, int len, int dummymode, bool noround,int reg_window);
254
255 int sif_spi_write_mix_nosync(struct spi_device *spi, unsigned int addr, unsigned char *buf, int len, int dummymode,int reg_window);
256 int sif_spi_epub_write_mix_sync(struct esp_pub *epub, unsigned int addr,unsigned char *buf, int len, int dummymode,int reg_window);
257 int sif_spi_epub_write_mix_nosync(struct esp_pub *epub, unsigned int addr,unsigned char *buf, int len, int dummymode,int reg_window);
258 int sif_spi_write_sync(struct esp_pub *epub, unsigned char *buf, int len, int dummymode,int reg_window);
259 int sif_spi_write_nosync(struct esp_pub *epub, unsigned char *buf, int len, int dummymode,int reg_window);
260
261 int sif_platform_get_irq_no(void);
262 int sif_platform_is_irq_occur(void);
263 void sif_platform_irq_clear(void);
264 void sif_platform_irq_mask(int enable_mask);
265 int sif_platform_irq_init(void);
266 void sif_platform_irq_deinit(void);
267 #endif
268
269 #ifdef ESP_USE_SPI
270 int sif_spi_write_bytes(struct spi_device *spi, unsigned int addr,unsigned char *dst, int count, int check_idle);
271 int sif_spi_read_bytes(struct spi_device *spi, unsigned int addr,unsigned char *dst, int count, int check_idle);
272 struct esp_spi_resp *sif_get_spi_resp(void);
273 #endif
274
275 int esp_common_read(struct esp_pub *epub, u8 *buf, u32 len, int sync, bool noround);
276 int esp_common_write(struct esp_pub *epub, u8 *buf, u32 len, int sync);
277 int esp_common_read_with_addr(struct esp_pub *epub, u32 addr, u8 *buf, u32 len, int sync);
278 int esp_common_write_with_addr(struct esp_pub *epub, u32 addr, u8 *buf, u32 len, int sync);
279
280 int esp_common_readbyte_with_addr(struct esp_pub *epub, u32 addr, u8 *buf, int sync);
281 int esp_common_writebyte_with_addr(struct esp_pub *epub, u32 addr, u8 buf, int sync);
282
283 struct slc_host_regs * sif_get_regs(struct esp_pub *epub);
284
285 void sif_lock_bus(struct esp_pub *epub);
286 void sif_unlock_bus(struct esp_pub *epub);
287
288 void sif_platform_target_poweroff(void);
289 void sif_platform_target_poweron(void);
290 void sif_platform_target_speed(int high_speed);
291
292 void sif_platform_reset_target(void);
293 void sif_platform_rescan_card(unsigned insert);
294
295 int sif_interrupt_target(struct esp_pub *epub, u8 index);
296 #ifdef USE_EXT_GPIO
297 int sif_config_gpio_mode(struct esp_pub *epub, u8 gpio_num, u8 gpio_mode);
298 int sif_set_gpio_output(struct esp_pub *epub, u16 mask, u16 value);
299 int sif_get_gpio_intr(struct esp_pub *epub, u16 intr_mask, u16 *value);
300 int sif_get_gpio_input(struct esp_pub *epub, u16 *mask, u16 *value);
301 #endif
302
303 void sif_raw_dummy_read(struct esp_pub *epub,int ext_gpio);
304 void check_target_id(struct esp_pub *epub);
305
306 void sif_record_bt_config(int value);
307 int sif_get_bt_config(void);
308 void sif_record_rst_config(int value);
309 int sif_get_rst_config(void);
310 void sif_record_ate_config(int value);
311 int sif_get_ate_config(void);
312 void sif_record_retry_config(void);
313 int sif_get_retry_config(void);
314 void sif_record_wakeup_gpio_config(int value);
315 int sif_get_wakeup_gpio_config(void);
316
317 #ifdef ESP_ACK_INTERRUPT
318 //extern void sif_platform_ack_interrupt(struct mmc_host *mmc);
319 extern void sif_platform_ack_interrupt(struct esp_pub *epub);
320 #endif //ESP_ACK_INTERRUPT
321
322 #define sif_reg_read_sync(epub, addr, buf, len) sif_io_sync((epub), (addr), (buf), (len), SIF_FROM_DEVICE | SIF_BYTE_BASIS | SIF_INC_ADDR)
323
324 #define sif_reg_write_sync(epub, addr, buf, len) sif_io_sync((epub), (addr), (buf), (len), SIF_TO_DEVICE | SIF_BYTE_BASIS | SIF_INC_ADDR)
325
326 #endif /* _ESP_SIF_H_ */