xref: /OK3568_Linux_fs/external/rkwifibt/drivers/rtl8852bs/phl/hal_g6/hal_chan.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /******************************************************************************
2  *
3  * Copyright(c) 2019 Realtek Corporation.
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms of version 2 of the GNU General Public License as
7  * published by the Free Software Foundation.
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12  * more details.
13  *
14  *****************************************************************************/
15 #define _HAL_CHAN_C_
16 #include "hal_headers.h"
17 
18 #ifdef CONFIG_PHL_DFS
19 enum rtw_hal_status
rtw_hal_radar_detect_cfg(void * hal,bool dfs_enable)20 rtw_hal_radar_detect_cfg(void *hal, bool dfs_enable)
21 {
22 	struct hal_info_t *hal_info = (struct hal_info_t *)hal;
23 	u8 rpt_num = 0;/*52A - 29/61/93/125 pkt*/
24 	u8 rpt_to = 1;/*52A CAV - 0 , 80us ,2ms, CBV - 0 / 20ms / 40ms / 80ms*/
25 
26 	PHL_INFO("====>%s dfs_en:%d ============\n", __func__, dfs_enable);
27 	if (dfs_enable) {
28 		rtw_hal_mac_dfs_rpt_cfg(hal_info, true, rpt_num, rpt_to);
29 		rtw_hal_bb_dfs_rpt_cfg(hal_info, true);
30 	}
31 	else {
32 		rtw_hal_mac_dfs_rpt_cfg(hal_info, false, 0, 0);
33 		rtw_hal_bb_dfs_rpt_cfg(hal_info, true);
34 	}
35 	return RTW_HAL_STATUS_SUCCESS;
36 }
37 #endif /*CONFIG_PHL_DFS*/
38 
rtw_hal_set_ch_bw(void * hal,u8 band_idx,struct rtw_chan_def * chdef,bool do_rfk)39 enum rtw_hal_status rtw_hal_set_ch_bw(void *hal, u8 band_idx,
40 		struct rtw_chan_def *chdef, bool do_rfk)
41 {
42 	struct hal_info_t *hal_info = (struct hal_info_t *)hal;
43 	struct rtw_hal_com_t *hal_com = hal_info->hal_com;
44 	struct rtw_chan_def *cur_chdef = &(hal_com->band[band_idx].cur_chandef);
45 	enum rtw_hal_status status = RTW_HAL_STATUS_SUCCESS;
46 	u8 center_ch = 0;
47 	u8 central_ch_seg1 = 0;
48 	enum band_type change_band;
49 	enum phl_phy_idx phy_idx = HW_PHY_0;
50 
51 	if ((chdef->chan != cur_chdef->chan) ||
52 	    (chdef->bw != cur_chdef->bw) ||
53 	    (chdef->offset != cur_chdef->offset)) {
54 		if (band_idx == 1)
55 			phy_idx = HW_PHY_1;
56 
57 		status = rtw_hal_reset(hal_com, phy_idx, band_idx, true);
58 		if(status != RTW_HAL_STATUS_SUCCESS) {
59 			PHL_ERR("%s rtw_hal_reset en - failed\n", __func__);
60 			_os_warn_on(1);
61 		}
62 		/* if central channel changed, reset BB & MAC */
63 		center_ch = rtw_phl_get_center_ch(chdef->chan, chdef->bw, chdef->offset);
64 		PHL_INFO("Using central channel %u for primary channel %u BW %u\n",
65 		         center_ch, chdef->chan, chdef->bw);
66 
67 		change_band = chdef->band;
68 
69 		status = rtw_hal_mac_set_bw(hal_info, band_idx, chdef->chan,
70 					      center_ch, central_ch_seg1, change_band,
71 					      chdef->bw);
72 		if(status != RTW_HAL_STATUS_SUCCESS) {
73 			PHL_ERR("%s rtw_hal_mac_set_bw - failed\n", __func__);
74 			return status;
75 		}
76 
77 
78 		if(chdef->bw == CHANNEL_WIDTH_80_80 && central_ch_seg1 == 0) {
79 			PHL_ERR("%s mising info for 80+80M configuration\n", __func__);
80 			return RTW_HAL_STATUS_FAILURE;
81 		}
82 		status = rtw_hal_bb_set_ch_bw(hal_info, phy_idx, chdef->chan,
83 					      center_ch, central_ch_seg1, change_band,
84 					      chdef->bw);
85 		if(status != RTW_HAL_STATUS_SUCCESS) {
86 			PHL_ERR("%s rtw_hal_bb_set_ch_bw - failed\n", __func__);
87 			return status;
88 		}
89 
90 		status = rtw_hal_rf_set_ch_bw(hal_info, phy_idx, center_ch, change_band, chdef->bw);
91 
92 		if(status != RTW_HAL_STATUS_SUCCESS) {
93 			PHL_ERR("%s rtw_hal_rf_set_ch_bw - failed\n", __func__);
94 			return status;
95 		}
96 
97 		cur_chdef->chan = chdef->chan;
98 		cur_chdef->bw = chdef->bw;
99 		cur_chdef->center_ch = center_ch;
100 
101 		if (cur_chdef->band != change_band) {
102 			cur_chdef->band = change_band;
103 			rtw_hal_notify_switch_band(hal, change_band, phy_idx);
104 		}
105 
106 		status = rtw_hal_rf_set_power(hal_info, phy_idx, PWR_LIMIT);
107 
108 		if(status != RTW_HAL_STATUS_SUCCESS) {
109 			PHL_ERR("%s rtw_hal_rf_set_power - failed\n", __func__);
110 			return status;
111 		}
112 
113 		status = rtw_hal_rf_set_power(hal_info, phy_idx, PWR_LIMIT_RU);
114 
115 		if(status != RTW_HAL_STATUS_SUCCESS) {
116 			PHL_ERR("%s rtw_hal_rf_set_power - failed\n", __func__);
117 			return status;
118 		}
119 
120 		PHL_INFO("%s band_idx:%d, ch:%d, bw:%d, offset:%d\n",
121 			__func__, band_idx, chdef->chan, chdef->bw, chdef->offset);
122 
123 		status = rtw_hal_reset(hal_com, phy_idx, band_idx, false);
124 		if(status != RTW_HAL_STATUS_SUCCESS) {
125 			PHL_ERR("%s rtw_hal_reset dis- failed\n", __func__);
126 			_os_warn_on(1);
127 		}
128 
129 		/*PHL_DUMP_CHAN_DEF_EX(chandef);*/
130 	}
131 	if (do_rfk) {
132 		status = rtw_hal_rf_chl_rfk_trigger(hal_info, phy_idx, true);
133 		if (status != RTW_HAL_STATUS_SUCCESS)
134 			PHL_ERR("rtw_hal_rf_chl_rfk_trigger fail!\n");
135 	}
136 	PHL_INFO("%s: Switch chdef done, do_rfk:%s\n", __func__,
137 		(do_rfk) ? "Y" : "N");
138 	return status;
139 }
140 
rtw_hal_get_cur_ch(void * hal,u8 band_idx)141 u8 rtw_hal_get_cur_ch(void *hal, u8 band_idx)
142 {
143 	struct hal_info_t *hal_info = (struct hal_info_t *)hal;
144 	struct rtw_hal_com_t *hal_com = hal_info->hal_com;
145 	struct rtw_chan_def *chandef = &(hal_com->band[band_idx].cur_chandef);
146 
147 	return chandef->chan;
148 }
149 
rtw_hal_get_cur_chdef(void * hal,u8 band_idx,struct rtw_chan_def * cur_chandef)150 void rtw_hal_get_cur_chdef(void *hal, u8 band_idx,
151 				struct rtw_chan_def *cur_chandef)
152 {
153 	struct hal_info_t *hal_info = (struct hal_info_t *)hal;
154 	struct rtw_hal_com_t *hal_com = hal_info->hal_com;
155 	struct rtw_chan_def *chandef = &(hal_com->band[band_idx].cur_chandef);
156 	void *drv = hal_com->drv_priv;
157 
158 	_os_mem_cpy(drv, cur_chandef, chandef, sizeof(struct rtw_chan_def));
159 }
160 
rtw_hal_sync_cur_ch(void * hal,u8 band_idx,struct rtw_chan_def chandef)161 void rtw_hal_sync_cur_ch(void *hal, u8 band_idx, struct rtw_chan_def chandef)
162 {
163 	struct hal_info_t *hal_info = (struct hal_info_t *)hal;
164 	struct rtw_hal_com_t *hal_com = hal_info->hal_com;
165 	struct rtw_chan_def *cur_chandef = &(hal_com->band[band_idx].cur_chandef);
166 
167 	PHL_INFO("%s: Sync cur chan to ch:%d bw:%d offset:%d\n",
168 		 __FUNCTION__, chandef.chan, chandef.bw, chandef.offset);
169 	cur_chandef->chan = chandef.chan;
170 	cur_chandef->bw = chandef.bw;
171 	cur_chandef->offset = chandef.offset;
172 }
173