2 * Copyright (c) 2011 - 2013 Espressif System.
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
14 #include <linux/mmc/host.h>
15 #include <linux/spi/spi.h>
18 * H/W SLC module definitions
21 #define SIF_SLC_BLOCK_SIZE 512
23 #define SIF_DMA_BUFFER_SIZE (64 * 1024)
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)
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)
35 #define SIF_REQ_MAX_NUM 64
37 /* S/W struct mapping to slc registers */
38 typedef struct slc_host_regs {
39 /* do NOT read token_rdata
60 struct list_head list;
77 typedef struct esp_sdio_ctrl {
78 struct sdio_func *func;
80 typedef struct esp_spi_ctrl {
81 struct spi_device *spi;
86 struct list_head free_req;
87 struct sif_req reqs[SIF_REQ_MAX_NUM];
92 struct list_head scat_req;
95 atomic_t irq_handling;
97 const struct sdio_device_id *id;
99 const struct spi_device_id *id;
103 u32 slc_window_end_addr;
105 struct slc_host_regs slc_regs;
106 atomic_t irq_installed;
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;
128 #define SIF_TO_DEVICE 0x1
129 #define SIF_FROM_DEVICE 0x2
131 #define SIF_SYNC 0x00000010
132 #define SIF_ASYNC 0x00000020
134 #define SIF_BYTE_BASIS 0x00000040
135 #define SIF_BLOCK_BASIS 0x00000080
137 #define SIF_FIXED_ADDR 0x00000100
138 #define SIF_INC_ADDR 0x00000200
141 #define EPUB_CTRL_CHECK(_epub, _go_err) do{\
142 if (_epub == NULL) {\
146 if ((_epub)->sif == NULL) {\
152 #define EPUB_FUNC_CHECK(_epub, _go_err) do{\
153 if (_epub == NULL) {\
157 if ((_epub)->sif == NULL) {\
161 if (((struct esp_sdio_ctrl *)(_epub)->sif)->func == NULL) {\
167 #define EPUB_TO_CTRL(_epub) (((struct esp_sdio_ctrl *)(_epub)->sif))
169 #define EPUB_TO_FUNC(_epub) (((struct esp_sdio_ctrl *)(_epub)->sif)->func)
174 #define EPUB_CTRL_CHECK(_epub, _go_err) do{\
175 if (_epub == NULL) {\
179 if ((_epub)->sif == NULL) {\
185 #define EPUB_FUNC_CHECK(_epub, _go_err) do{\
186 if (_epub == NULL) {\
190 if ((_epub)->sif == NULL) {\
194 if (((struct esp_spi_ctrl *)(_epub)->sif)->spi == NULL) {\
200 #define EPUB_TO_CTRL(_epub) (((struct esp_spi_ctrl *)(_epub)->sif))
202 #define EPUB_TO_FUNC(_epub) (((struct esp_spi_ctrl *)(_epub)->sif)->spi)
205 static void inline sif_setup_req(struct sif_req *req, u32 addr, u32 flag, u32 len,
206 u8 * buf, void *context)
212 req->context = context;
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);
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);
223 u32 sif_get_blksz(struct esp_pub *epub);
224 u32 sif_get_target_id(struct esp_pub *epub);
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);
244 #ifdef REGISTER_SPI_BOARD_INFO
245 void sif_platform_register_board_info(void);
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);
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);
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);
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);
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);
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);
283 struct slc_host_regs * sif_get_regs(struct esp_pub *epub);
285 void sif_lock_bus(struct esp_pub *epub);
286 void sif_unlock_bus(struct esp_pub *epub);
288 void sif_platform_target_poweroff(void);
289 void sif_platform_target_poweron(void);
290 void sif_platform_target_speed(int high_speed);
292 void sif_platform_reset_target(void);
293 void sif_platform_rescan_card(unsigned insert);
295 int sif_interrupt_target(struct esp_pub *epub, u8 index);
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);
303 void sif_raw_dummy_read(struct esp_pub *epub,int ext_gpio);
304 void check_target_id(struct esp_pub *epub);
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);
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
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)
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)
326 #endif /* _ESP_SIF_H_ */