• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 HiSilicon (Shanghai) Technologies CO., LIMITED.
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
17  */
18 
19 /* ****************************************************************************
20   1 Header File Including
21 **************************************************************************** */
22 #include <linux/interrupt.h>
23 #ifndef HAVE_PCLINT_CHECK
24 #include <linux/platform_device.h>
25 #endif
26 #include "plat_board_adapt.h"
27 #include "plat_firmware.h"
28 #include "plat_pm.h"
29 #include "oal_sdio_host_if.h"
30 #include "hcc_host.h"
31 #include "oal_schedule.h"
32 #if (_PRE_OS_VERSION_LINUX == _PRE_OS_VERSION)
33 #include <linux/kobject.h>
34 #include <linux/mmc/sdio.h>
35 #include <linux/mmc/host.h>
36 #include <linux/mmc/card.h>
37 #include <linux/mmc/sdio_func.h>
38 #include <linux/mmc/sdio_ids.h>
39 #include <linux/mmc/sdio_func.h>
40 #include <linux/mmc/host.h>
41 #include <linux/gpio.h>
42 #include <linux/irq.h>
43 #include <linux/suspend.h>
44 #include <linux/tty.h>
45 #include <linux/notifier.h>
46 #include "exception_rst.h"
47 #elif (_PRE_OS_VERSION_LITEOS == _PRE_OS_VERSION)
48 #include <linux/module.h> /* kernel module definitions */
49 #include <linux/timer.h>
50 #include <linux/wakelock.h>
51 #endif
52 #include "oal_channel_host_if.h"
53 #include "oal_mm.h"
54 #include "oam_ext_if.h"
55 
56 /* ****************************************************************************
57   2 Global Variable Definition
58 **************************************************************************** */
59 #if (_PRE_OS_VERSION_LITEOS == _PRE_OS_VERSION)
60 unsigned int g_ul_wlan_resume_state = 0;
61 unsigned int g_ul_wlan_resume_wifi_init_flag = 0;
62 #endif
63 
64 /* ****************************************************************************
65  * Description  : download wlan patch
66  * Input        :
67  * Output       : none
68  * Return       : 0 means succeed,-1 means failed
69  * *************************************************************************** */
firmware_download_function(hi_u32 which_cfg)70 int firmware_download_function(hi_u32 which_cfg)
71 {
72     hi_s32 ret;
73     unsigned long total_time;
74     oal_time_t_stru start_time, end_time, trans_time;
75     static unsigned long max_time = 0;
76     static unsigned long count = 0;
77 
78     start_time = oal_ktime_get();
79 
80     if (which_cfg >= CFG_FILE_TOTAL) {
81         oam_error_log1(0, 0, "firmware_download_function:: cfg file index [%d] outof range", which_cfg);
82         return -FAILURE;
83     }
84 
85 #ifndef _PRE_FEATURE_NO_GPIO
86     board_power_on();
87 #endif
88 
89     oam_info_log0(0, 0, "firmware_download_function:: firmware_download begin");
90     ret = firmware_download(which_cfg);
91     if (ret < 0) {
92         oam_error_log0(0, 0, "firmware_download_function:: firmware download fail");
93         return ret;
94     }
95     oam_info_log0(0, 0, "firmware_download_function:: firmware_download success");
96     end_time = oal_ktime_get();
97 
98     trans_time = oal_ktime_sub(end_time, start_time);
99     total_time = (unsigned long)oal_ktime_to_us(trans_time);
100     if (total_time > max_time) {
101         max_time = total_time;
102     }
103 
104     count++;
105     oam_info_log3(0, 0, "download firmware, count [%lu], current time [%lu]us, max time [%lu]us", count, total_time,
106         max_time);
107 
108     ret = SUCCESS;
109     return ret;
110 }
111 
wlan_power_on(hi_void)112 hi_s32 wlan_power_on(hi_void)
113 {
114     hi_s32 ret;
115     unsigned long long total_time;
116     oal_time_t_stru start_time, end_time, trans_time;
117     static unsigned long long max_download_time = 0;
118     static unsigned long long num = 0;
119 
120     start_time = oal_ktime_get();
121 
122     ret = firmware_download_function(WIFI_CFG);
123     if (ret != SUCCESS) {
124         oam_error_log0(0, 0, "wlan_power_on:: firmware download fail");
125         return -FAILURE;
126     }
127 
128     oam_warning_log0(0, 0, "wlan_power_on:: firmware download success");
129     /* 注册SDIO中断入口函数 */
130     if (HI_SUCCESS != oal_bus_transfer_prepare(hcc_host_get_handler()->bus)) {
131         oam_error_log0(0, 0, "wlan_power_on:: channel transfer prepare fail");
132         return -FAILURE;
133     }
134 
135     end_time = oal_ktime_get();
136     trans_time = oal_ktime_sub(end_time, start_time);
137     total_time = (unsigned long long)oal_ktime_to_us(trans_time);
138     if (total_time > max_download_time) {
139         max_download_time = total_time;
140     }
141 
142     num++;
143 
144     ret = WIFI_POWER_SUCCESS;
145 
146 #ifndef _PRE_FEATURE_NO_GPIO
147     board_set_host_to_dev_gpio_val_high();
148 #endif
149     return ret;
150 }
151