2 * Copyright (c) 2010 - 2014 Espressif System.
7 #include <linux/netdevice.h>
8 #include <linux/etherdevice.h>
9 #include <linux/rtnetlink.h>
10 #include <linux/firmware.h>
11 #include <linux/sched.h>
12 #include <net/cfg80211.h>
13 #include <net/mac80211.h>
14 #include <linux/time.h>
15 #include <linux/moduleparam.h>
20 #include "esp_debug.h"
24 struct completion *gl_bootup_cplx = NULL;
27 static int esp_download_fw(struct esp_pub * epub);
28 #endif /* !FGPA_DEBUG */
30 static int modparam_no_txampdu = 0;
31 static int modparam_no_rxampdu = 0;
32 module_param_named(no_txampdu, modparam_no_txampdu, int, 0444);
33 MODULE_PARM_DESC(no_txampdu, "Disable tx ampdu.");
34 module_param_named(no_rxampdu, modparam_no_rxampdu, int, 0444);
35 MODULE_PARM_DESC(no_rxampdu, "Disable rx ampdu.");
37 static char *modparam_eagle_path = "";
38 module_param_named(eagle_path, modparam_eagle_path, charp, 0444);
39 MODULE_PARM_DESC(eagle_path, "eagle path");
41 bool mod_support_no_txampdu()
43 return modparam_no_txampdu;
46 bool mod_support_no_rxampdu()
48 return modparam_no_rxampdu;
51 void mod_support_no_txampdu_set(bool value)
53 modparam_no_txampdu = value;
56 char *mod_eagle_path_get(void)
58 if (modparam_eagle_path[0] == '\0')
61 return modparam_eagle_path;
64 int esp_pub_init_all(struct esp_pub *epub)
68 /* completion for bootup event poll*/
69 DECLARE_COMPLETION_ONSTACK(complete);
70 atomic_set(&epub->ps.state, ESP_PM_OFF);
71 if(epub->sdio_state == ESP_SDIO_STATE_FIRST_INIT){
72 epub->sip = sip_attach(epub);
73 if (epub->sip == NULL) {
74 printk(KERN_ERR "%s sip alloc failed\n", __func__);
78 esp_dump_var("esp_msg_level", NULL, &esp_msg_level, ESP_U32);
80 #ifdef ESP_ANDROID_LOGGER
81 esp_dump_var("log_off", NULL, &log_off, ESP_U32);
82 #endif /* ESP_ANDROID_LOGGER */
84 atomic_set(&epub->sip->state, SIP_PREPARE_BOOT);
85 atomic_set(&epub->sip->tx_credits, 0);
88 epub->sip->to_host_seq = 0;
91 if(sif_get_ate_config() != 0 && sif_get_ate_config() != 1 && sif_get_ate_config() !=6 )
99 ret = esp_download_fw(epub);
101 if(sif_get_ate_config() != 1)
102 epub->enable_int = 1;
105 if(sif_get_ate_config() == 6)
107 sif_enable_irq(epub);
109 sif_disable_irq(epub);
116 esp_dbg(ESP_DBG_ERROR, "download firmware failed\n");
120 esp_dbg(ESP_DBG_TRACE, "download firmware OK \n");
122 sip_send_bootup(epub->sip);
123 #endif /* FPGA_DEBUG */
125 gl_bootup_cplx = &complete;
126 epub->wait_reset = 0;
127 sif_enable_irq(epub);
129 if(epub->sdio_state == ESP_SDIO_STATE_SECOND_INIT || sif_get_ate_config() == 1){
130 ret = sip_poll_bootup_event(epub->sip);
132 ret = sip_poll_resetting_event(epub->sip);
135 sif_interrupt_target(epub, 7);
136 sif_unlock_bus(epub);
141 gl_bootup_cplx = NULL;
143 if (sif_get_ate_config() == 1)
150 esp_dsr(struct esp_pub *epub)
163 struct esp_fw_blk_hdr {
168 #define ESP_FW_NAME1 "eagle_fw1.bin"
169 #define ESP_FW_NAME2 "eagle_fw2.bin"
170 #define ESP_FW_NAME3 "eagle_fw3.bin"
173 static int esp_download_fw(struct esp_pub * epub)
176 const struct firmware *fw_entry;
182 struct esp_fw_hdr *fhdr;
183 struct esp_fw_blk_hdr *bhdr=NULL;
184 struct sip_cmd_bootup bootcmd;
188 if(sif_get_ate_config() == 1) {
189 char * esp_fw_name = ESP_FW_NAME3;
191 char * esp_fw_name = epub->sdio_state == ESP_SDIO_STATE_FIRST_INIT ? ESP_FW_NAME1 : ESP_FW_NAME2;
193 ret = esp_request_firmware(&fw_entry, esp_fw_name, epub->dev);
198 fw_buf = kmemdup(fw_entry->data, fw_entry->size, GFP_KERNEL);
200 esp_release_firmware(fw_entry);
202 if (fw_buf == NULL) {
207 #include "eagle_fw1.h"
208 #include "eagle_fw2.h"
209 #include "eagle_fw3.h"
210 if(sif_get_ate_config() == 1){
211 fw_buf = &eagle_fw3[0];
213 fw_buf = epub->sdio_state == ESP_SDIO_STATE_FIRST_INIT ? &eagle_fw1[0] : &eagle_fw2[0];
217 fhdr = (struct esp_fw_hdr *)fw_buf;
219 if (fhdr->magic != 0xE9) {
220 esp_dbg(ESP_DBG_ERROR, "%s wrong magic! \n", __func__);
224 blocks = fhdr->blocks;
225 offset += sizeof(struct esp_fw_hdr);
229 bhdr = (struct esp_fw_blk_hdr *)(&fw_buf[offset]);
230 offset += sizeof(struct esp_fw_blk_hdr);
232 ret = sip_write_memory(epub->sip, bhdr->load_addr, &fw_buf[offset], bhdr->data_len);
235 esp_dbg(ESP_DBG_ERROR, "%s Failed to write fw, err: %d\n", __func__, ret);
240 offset += bhdr->data_len;
243 /* TODO: last byte should be the checksum and skip checksum for now */
245 bootcmd.boot_addr = fhdr->entry_addr;
246 ret = sip_send_cmd(epub->sip, SIP_CMD_BOOTUP, sizeof(struct sip_cmd_bootup), &bootcmd);
259 #endif /* !FPGA_DEBUG */