dee93eed9ec8cd09d9499f0f53626e10d6ca5ceb
[firefly-linux-kernel-4.4.55.git] / drivers / net / wireless / rockchip_wlan / esp8089 / esp_driver / esp_init.c
1 /* Copyright (c) 2008 -2014 Espressif System.
2  *
3  * This program is free software; you can redistribute it and/or modify
4  * it under the terms of the GNU General Public License version 2 as
5  * published by the Free Software Foundation.
6  *
7  *
8  * init , call sdio_init or spi_init
9  *
10  */
11
12 #include "esp_pub.h"
13 #include "esp_sif.h"
14 #include "esp_debug.h"
15 #include "esp_version.h"
16 #include "esp_file.h"
17
18 int esp_common_init(void)
19 {
20         int ret;
21 #if (defined(CONFIG_DEBUG_FS) && defined(DEBUGFS_BOOTMODE)) || defined(ESP_CLASS)
22         if (sif_get_esp_run() != 0) {
23                 return 0;
24         }
25 #endif
26 #ifdef ESP_USE_SDIO
27         ret = esp_sdio_init();
28 #endif
29 #ifdef ESP_USE_SPI
30         ret = esp_spi_init();
31 #endif
32 #if (defined(CONFIG_DEBUG_FS) && defined(DEBUGFS_BOOTMODE)) || defined(ESP_CLASS)
33         if (ret == 0)
34                 sif_record_esp_run(1);
35 #endif
36         return ret;
37 }
38
39 void esp_common_exit(void)
40 {
41 #if (defined(CONFIG_DEBUG_FS) && defined(DEBUGFS_BOOTMODE)) || defined(ESP_CLASS)
42         if (sif_get_esp_run() == 0) {
43                 return;
44         }
45 #endif
46 #ifdef ESP_USE_SDIO
47         esp_sdio_exit();
48 #endif
49 #ifdef ESP_USE_SPI
50         esp_spi_exit();
51 #endif
52 #if (defined(CONFIG_DEBUG_FS) && defined(DEBUGFS_BOOTMODE)) || defined(ESP_CLASS)
53         sif_record_esp_run(0);
54 #endif
55 }
56
57 static int /*__init*/ esp_init(void)
58 {
59         u64 ver;
60         int edf_ret = 0;
61
62 #ifdef DRIVER_VER
63         ver = DRIVER_VER;
64         esp_dbg(ESP_SHOW, "\n*****%s %s EAGLE DRIVER VER:%llx*****\n\n", __DATE__, __TIME__, ver);
65 #endif
66         edf_ret = esp_debugfs_init();    /* if failed, continue */
67         if (edf_ret == 0) {
68 #if defined(CONFIG_DEBUG_FS) && defined(DEBUGFS_BOOTMODE)
69                 dbgfs_bootmode_init();
70 #endif
71                 esp_dump_var("esp_msg_level", NULL, &esp_msg_level, ESP_U32);
72
73 #ifdef ESP_ANDROID_LOGGER
74                 esp_dump_var("log_off", NULL, &log_off, ESP_U32);
75 #endif /* ESP_ANDROID_LOGGER */
76         }
77 #ifdef ESP_CLASS
78         esp_class_init();
79 #endif
80         request_init_conf();
81
82         return esp_common_init();
83 }
84
85 static void /*__exit */ esp_exit(void)
86 {
87         esp_debugfs_exit();
88 #ifdef ESP_CLASS
89         esp_class_deinit();
90 #endif
91
92         esp_common_exit();
93 }
94
95 #include <linux/rfkill-wlan.h>
96 extern int get_wifi_chip_type(void);
97
98 int rockchip_wifi_init_module_esp8089(void)
99 {
100 #ifdef CONFIG_WIFI_LOAD_DRIVER_WHEN_KERNEL_BOOTUP
101     int type = get_wifi_chip_type();
102     if (type != WIFI_ESP8089) return 0;
103 #endif
104         return esp_init();
105 }
106
107 void rockchip_wifi_exit_module_esp8089(void)
108 {
109 #ifdef CONFIG_WIFI_LOAD_DRIVER_WHEN_KERNEL_BOOTUP
110     int type = get_wifi_chip_type();
111     if (type != WIFI_ESP8089) return;
112 #endif
113         esp_exit(); 
114 }
115
116 #ifdef CONFIG_WIFI_LOAD_DRIVER_WHEN_KERNEL_BOOTUP
117 late_initcall(rockchip_wifi_init_module_esp8089);
118 module_exit(rockchip_wifi_exit_module_esp8089);
119 #else
120 EXPORT_SYMBOL(rockchip_wifi_init_module_esp8089);
121 EXPORT_SYMBOL(rockchip_wifi_exit_module_esp8089);
122 #endif
123 //module_init(esp_init);
124 //module_exit(esp_exit);