wifi->esp8089:
[firefly-linux-kernel-4.4.55.git] / drivers / net / wireless / rockchip_wlan / esp8089 / esp_driver / esp_sif.h
1 /*
2  * Copyright (c) 2011 - 2014 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
24 /* S/W struct mapping to slc registers */
25 typedef struct slc_host_regs {
26         /* do NOT read token_rdata
27          *
28                 u32 pf_data;
29                 u32 token_rdata;
30         */
31         u32 intr_raw;
32         u32 state_w0;
33         u32 state_w1;
34         u32 config_w0;
35         u32 config_w1;
36         u32 intr_status;
37         u32 config_w2;
38         u32 config_w3;
39         u32 config_w4;
40         u32 token_wdata;
41         u32 intr_clear;
42         u32 intr_enable;
43 } sif_slc_reg_t;
44
45
46 enum io_sync_type {     
47         ESP_SIF_NOSYNC = 0,
48         ESP_SIF_SYNC, 
49 };
50
51 #ifdef ESP_USE_SDIO
52 typedef struct esp_sdio_ctrl {
53         struct sdio_func *func;
54 #else
55 typedef struct esp_spi_ctrl {
56         struct spi_device *spi;
57 #endif
58         struct esp_pub *epub;
59
60
61         struct list_head free_req;
62
63         u8 *dma_buffer;
64
65         spinlock_t scat_lock;
66         struct list_head scat_req;
67
68         bool off;
69         atomic_t irq_handling;
70 #ifdef ESP_USE_SDIO
71         const struct sdio_device_id *id;
72 #else
73         const struct spi_device_id *id;
74 #endif
75         u32 slc_blk_sz;
76         u32 target_id;
77         u32 slc_window_end_addr;
78
79         struct slc_host_regs slc_regs;
80         atomic_t        irq_installed;
81
82 #ifdef ESP_USE_SDIO
83 } esp_sdio_ctrl_t;
84 #else
85 } esp_spi_ctrl_t;
86 #endif
87
88 #ifdef ESP_USE_SPI
89 struct esp_spi_resp {
90         u32 max_dataW_resp_size;
91         u32 max_dataR_resp_size;
92         u32 max_block_dataW_resp_size;
93         u32 max_block_dataR_resp_size;
94         u32 max_cmd_resp_size;
95         u32 data_resp_size_w;
96         u32 data_resp_size_r;
97         u32 block_w_data_resp_size_final;
98         u32 block_r_data_resp_size_final;
99 };
100 #endif
101
102 #define SIF_TO_DEVICE                    0x1
103 #define SIF_FROM_DEVICE                    0x2
104
105 #define SIF_SYNC             0x00000010
106 #define SIF_ASYNC           0x00000020
107
108 #define SIF_BYTE_BASIS              0x00000040
109 #define SIF_BLOCK_BASIS             0x00000080
110
111 #define SIF_FIXED_ADDR           0x00000100
112 #define SIF_INC_ADDR     0x00000200
113
114 #ifdef ESP_USE_SDIO
115 #define EPUB_CTRL_CHECK(_epub, _go_err) do{\
116         if (_epub == NULL) {\
117                 ESSERT(0);\
118                 goto _go_err;\
119         }\
120         if ((_epub)->sif == NULL) {\
121                 ESSERT(0);\
122                 goto _go_err;\
123         }\
124 }while(0)
125
126 #define EPUB_FUNC_CHECK(_epub, _go_err) do{\
127         if (_epub == NULL) {\
128                 ESSERT(0);\
129                 goto _go_err;\
130         }\
131         if ((_epub)->sif == NULL) {\
132                 ESSERT(0);\
133                 goto _go_err;\
134         }\
135         if (((struct esp_sdio_ctrl *)(_epub)->sif)->func == NULL) {\
136                 ESSERT(0);\
137                 goto _go_err;\
138         }\
139 }while(0)
140
141 #define EPUB_TO_CTRL(_epub) (((struct esp_sdio_ctrl *)(_epub)->sif))
142
143 #define EPUB_TO_FUNC(_epub) (((struct esp_sdio_ctrl *)(_epub)->sif)->func)
144 #endif
145
146
147 #ifdef ESP_USE_SPI
148 #define EPUB_CTRL_CHECK(_epub, _go_err) do{\
149         if (_epub == NULL) {\
150                 ESSERT(0);\
151                 goto _go_err;\
152         }\
153         if ((_epub)->sif == NULL) {\
154                 ESSERT(0);\
155                 goto _go_err;\
156         }\
157 }while(0)
158
159 #define EPUB_FUNC_CHECK(_epub, _go_err) do{\
160         if (_epub == NULL) {\
161                 ESSERT(0);\
162                 goto _go_err;\
163         }\
164         if ((_epub)->sif == NULL) {\
165                 ESSERT(0);\
166                 goto _go_err;\
167         }\
168         if (((struct esp_spi_ctrl *)(_epub)->sif)->spi == NULL) {\
169                 ESSERT(0);\
170                 goto _go_err;\
171         }\
172 }while(0)
173
174 #define EPUB_TO_CTRL(_epub) (((struct esp_spi_ctrl *)(_epub)->sif))
175
176 #define EPUB_TO_FUNC(_epub) (((struct esp_spi_ctrl *)(_epub)->sif)->spi)
177 #endif
178
179 void sdio_io_writeb(struct esp_pub *epub, u8 value, int addr, int *res);
180 u8 sdio_io_readb(struct esp_pub *epub, int addr, int *res);
181
182
183 void sif_enable_irq(struct esp_pub *epub);
184 void sif_disable_irq(struct esp_pub *epub);
185 void sif_disable_target_interrupt(struct esp_pub *epub);
186
187 u32 sif_get_blksz(struct esp_pub *epub);
188 u32 sif_get_target_id(struct esp_pub *epub);
189
190 #ifdef ESP_USE_SDIO
191 void sif_dsr(struct sdio_func *func);
192 int sif_io_raw(struct esp_pub *epub, u32 addr, u8 *buf, u32 len, u32 flag);
193 int sif_io_sync(struct esp_pub *epub, u32 addr, u8 *buf, u32 len, u32 flag);
194 int sif_io_async(struct esp_pub *epub, u32 addr, u8 *buf, u32 len, u32 flag, void * context);
195 int sif_lldesc_read_sync(struct esp_pub *epub, u8 *buf, u32 len);
196 int sif_lldesc_write_sync(struct esp_pub *epub, u8 *buf, u32 len);
197 int sif_lldesc_read_raw(struct esp_pub *epub, u8 *buf, u32 len, bool noround);
198 int sif_lldesc_write_raw(struct esp_pub *epub, u8 *buf, u32 len);
199 void sif_platform_check_r1_ready(struct esp_pub *epub);
200 #endif 
201
202 #ifdef ESP_USE_SPI
203 enum if_dummymode {
204         NOT_DUMMYMODE = 0,
205         DUMMYMODE,
206 };
207
208 #ifdef REGISTER_SPI_BOARD_INFO
209 void sif_platform_register_board_info(void);
210 #endif
211
212 void sif_dsr(struct spi_device *spi);
213 int sif_spi_read_mix_nosync(struct spi_device *spi, unsigned int addr, unsigned char *buf, int len, int dummymode);
214 int sif_spi_epub_read_mix_sync(struct esp_pub *epub, unsigned int addr,unsigned char *buf, int len, int dummymode);
215 int sif_spi_epub_read_mix_nosync(struct esp_pub *epub, unsigned int addr,unsigned char *buf, int len, int dummymode);
216 int sif_spi_read_sync(struct esp_pub *epub, unsigned char *buf, int len, int dummymode);
217 int sif_spi_read_nosync(struct esp_pub *epub, unsigned char *buf, int len, int dummymode, bool noround);
218
219 int sif_spi_write_mix_nosync(struct spi_device *spi, unsigned int addr, unsigned char *buf, int len, int dummymode);
220 int sif_spi_epub_write_mix_sync(struct esp_pub *epub, unsigned int addr,unsigned char *buf, int len, int dummymode);
221 int sif_spi_epub_write_mix_nosync(struct esp_pub *epub, unsigned int addr,unsigned char *buf, int len, int dummymode);
222 int sif_spi_write_sync(struct esp_pub *epub, unsigned char *buf, int len, int dummymode);
223 int sif_spi_write_nosync(struct esp_pub *epub, unsigned char *buf, int len, int dummymode);
224
225 int sif_platform_get_irq_no(void);
226 int sif_platform_is_irq_occur(void);
227 void sif_platform_irq_clear(void);
228 void sif_platform_irq_mask(int enable_mask);
229 int sif_platform_irq_init(void);
230 void sif_platform_irq_deinit(void);
231
232 int sif_spi_write_bytes(struct spi_device *spi, unsigned int addr,unsigned char *dst, int count, int check_idle);
233 int sif_spi_read_bytes(struct spi_device *spi, unsigned int addr,unsigned char *dst, int count, int check_idle);
234 struct esp_spi_resp *sif_get_spi_resp(void);
235 #endif
236
237 int esp_common_read(struct esp_pub *epub, u8 *buf, u32 len, int sync, bool noround);
238 int esp_common_write(struct esp_pub *epub, u8 *buf, u32 len, int sync);
239 int esp_common_read_with_addr(struct esp_pub *epub, u32 addr, u8 *buf, u32 len, int sync);
240 int esp_common_write_with_addr(struct esp_pub *epub, u32 addr, u8 *buf, u32 len, int sync);
241
242 int esp_common_readbyte_with_addr(struct esp_pub *epub, u32 addr, u8 *buf, int sync);
243 int esp_common_writebyte_with_addr(struct esp_pub *epub, u32 addr, u8 buf, int sync);
244
245 int sif_read_reg_window(struct esp_pub *epub, unsigned int reg_addr, unsigned char *value);
246 int sif_write_reg_window(struct esp_pub *epub, unsigned int reg_addr, unsigned char *value);
247 int sif_ack_target_read_err(struct esp_pub *epub);
248 int sif_had_io_enable(struct esp_pub *epub);
249
250 struct slc_host_regs * sif_get_regs(struct esp_pub *epub);
251
252 void sif_lock_bus(struct esp_pub *epub);
253 void sif_unlock_bus(struct esp_pub *epub);
254
255 void sif_platform_target_poweroff(void);
256 void sif_platform_target_poweron(void);
257 void sif_platform_target_speed(int high_speed);
258
259 void sif_platform_reset_target(void);
260 void sif_platform_rescan_card(unsigned insert);
261
262 int sif_interrupt_target(struct esp_pub *epub, u8 index);
263 #ifdef USE_EXT_GPIO
264 int sif_config_gpio_mode(struct esp_pub *epub, u8 gpio_num, u8 gpio_mode);
265 int sif_set_gpio_output(struct esp_pub *epub, u16 mask, u16 value);
266 int sif_get_gpio_intr(struct esp_pub *epub, u16 intr_mask, u16 *value);
267 int sif_get_gpio_input(struct esp_pub *epub, u16 *mask, u16 *value);
268 #endif
269
270 void check_target_id(struct esp_pub *epub);
271
272 void sif_record_bt_config(int value);
273 int sif_get_bt_config(void);
274 void sif_record_rst_config(int value);
275 int sif_get_rst_config(void);
276 void sif_record_ate_config(int value);
277 int sif_get_ate_config(void);
278 void sif_record_retry_config(void);
279 int sif_get_retry_config(void);
280 void sif_record_wakeup_gpio_config(int value);
281 int sif_get_wakeup_gpio_config(void);
282
283 #ifdef ESP_ACK_INTERRUPT
284 //extern void sif_platform_ack_interrupt(struct mmc_host *mmc);
285 extern void sif_platform_ack_interrupt(struct esp_pub *epub);
286 #endif //ESP_ACK_INTERRUPT
287
288 #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)
289
290 #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)
291
292 #endif /* _ESP_SIF_H_ */