2 * Copyright (c) 2011 - 2014 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
24 /* S/W struct mapping to slc registers */
25 typedef struct slc_host_regs {
26 /* do NOT read token_rdata
52 typedef struct esp_sdio_ctrl {
53 struct sdio_func *func;
55 typedef struct esp_spi_ctrl {
56 struct spi_device *spi;
61 struct list_head free_req;
66 struct list_head scat_req;
69 atomic_t irq_handling;
71 const struct sdio_device_id *id;
73 const struct spi_device_id *id;
77 u32 slc_window_end_addr;
79 struct slc_host_regs slc_regs;
80 atomic_t irq_installed;
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;
97 u32 block_w_data_resp_size_final;
98 u32 block_r_data_resp_size_final;
102 #define SIF_TO_DEVICE 0x1
103 #define SIF_FROM_DEVICE 0x2
105 #define SIF_SYNC 0x00000010
106 #define SIF_ASYNC 0x00000020
108 #define SIF_BYTE_BASIS 0x00000040
109 #define SIF_BLOCK_BASIS 0x00000080
111 #define SIF_FIXED_ADDR 0x00000100
112 #define SIF_INC_ADDR 0x00000200
115 #define EPUB_CTRL_CHECK(_epub, _go_err) do{\
116 if (_epub == NULL) {\
120 if ((_epub)->sif == NULL) {\
126 #define EPUB_FUNC_CHECK(_epub, _go_err) do{\
127 if (_epub == NULL) {\
131 if ((_epub)->sif == NULL) {\
135 if (((struct esp_sdio_ctrl *)(_epub)->sif)->func == NULL) {\
141 #define EPUB_TO_CTRL(_epub) (((struct esp_sdio_ctrl *)(_epub)->sif))
143 #define EPUB_TO_FUNC(_epub) (((struct esp_sdio_ctrl *)(_epub)->sif)->func)
148 #define EPUB_CTRL_CHECK(_epub, _go_err) do{\
149 if (_epub == NULL) {\
153 if ((_epub)->sif == NULL) {\
159 #define EPUB_FUNC_CHECK(_epub, _go_err) do{\
160 if (_epub == NULL) {\
164 if ((_epub)->sif == NULL) {\
168 if (((struct esp_spi_ctrl *)(_epub)->sif)->spi == NULL) {\
174 #define EPUB_TO_CTRL(_epub) (((struct esp_spi_ctrl *)(_epub)->sif))
176 #define EPUB_TO_FUNC(_epub) (((struct esp_spi_ctrl *)(_epub)->sif)->spi)
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);
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);
187 u32 sif_get_blksz(struct esp_pub *epub);
188 u32 sif_get_target_id(struct esp_pub *epub);
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);
208 #ifdef REGISTER_SPI_BOARD_INFO
209 void sif_platform_register_board_info(void);
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);
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);
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);
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);
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);
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);
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);
250 struct slc_host_regs * sif_get_regs(struct esp_pub *epub);
252 void sif_lock_bus(struct esp_pub *epub);
253 void sif_unlock_bus(struct esp_pub *epub);
255 void sif_platform_target_poweroff(void);
256 void sif_platform_target_poweron(void);
257 void sif_platform_target_speed(int high_speed);
259 void sif_platform_reset_target(void);
260 void sif_platform_rescan_card(unsigned insert);
262 int sif_interrupt_target(struct esp_pub *epub, u8 index);
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);
270 void check_target_id(struct esp_pub *epub);
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);
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
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)
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)
292 #endif /* _ESP_SIF_H_ */