xref: /OK3568_Linux_fs/external/rkwifibt/drivers/rtl8852be/phl/hal_g6/hal_thermal.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /******************************************************************************
2  *
3  * Copyright(c) 2020 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_THERMAL_C_
16 #include "hal_headers.h"
17 
18 #ifdef CONFIG_PHL_THERMAL_PROTECT
19 
20 enum rtw_hal_status
rtw_hal_thermal_protect_cfg_tx_ampdu(void * hal,struct rtw_phl_stainfo_t * sta,u8 ratio)21 rtw_hal_thermal_protect_cfg_tx_ampdu(
22 	void *hal,
23 	struct rtw_phl_stainfo_t *sta,
24 	u8 ratio)
25 {
26 	struct hal_info_t *hal_info = (struct hal_info_t *)hal;
27 	enum rtw_hal_status hsts = RTW_HAL_STATUS_FAILURE;
28 	u8 num_ampdu = 0, tx_time = 0;
29 
30 	if (64 == sta->asoc_cap.num_ampdu)
31 		tx_time = 0xA5;
32 	else if (128 == sta->asoc_cap.num_ampdu)
33 		tx_time = 0xAB;
34 
35 	if(sta->asoc_cap.num_ampdu_bk == 0)
36 		sta->asoc_cap.num_ampdu_bk = sta->asoc_cap.num_ampdu;
37 
38 	sta->asoc_cap.num_ampdu = sta->asoc_cap.num_ampdu_bk * ratio / 100;
39 	num_ampdu = sta->asoc_cap.num_ampdu;
40 
41 	if(num_ampdu == 0)
42 		num_ampdu = 1;
43 
44 	hsts = rtw_hal_mac_set_hw_ampdu_cfg(hal_info, 0, num_ampdu, tx_time);
45 
46 	PHL_INFO("%s: bk_num_ampdu = %d num_ampdu = %d, tx_time = %x\n",
47 		 __FUNCTION__, sta->asoc_cap.num_ampdu_bk, num_ampdu, tx_time);
48 
49 	if (RTW_HAL_STATUS_SUCCESS != hsts)
50 		goto out;
51 
52 out:
53 	return hsts;
54 }
55 
rtw_hal_check_thermal_protect(struct rtw_phl_com_t * phl_com,void * hal)56 bool rtw_hal_check_thermal_protect(
57 	struct rtw_phl_com_t *phl_com,
58 	void *hal
59 )
60 {
61 	struct hal_info_t *hal_info = (struct hal_info_t *)hal;
62 	enum halrf_thermal_status status = HALRF_THERMAL_STATUS_BELOW_THRESHOLD;
63 	bool action_changed = false;
64 
65 	status = rtw_hal_rf_get_ther_protected_threshold(hal_info);
66 
67 	PHL_INFO("%s: Cur action = %x\n", __FUNCTION__, phl_com->thermal_protect_action);
68 	PHL_INFO("%s: status = %x\n", __FUNCTION__, status);
69 
70 	switch (phl_com->thermal_protect_action){
71 		case PHL_THERMAL_PROTECT_ACTION_NONE:
72 			if(status == HALRF_THERMAL_STATUS_ABOVE_THRESHOLD){
73 				phl_com->thermal_protect_action =
74 					PHL_THERMAL_PROTECT_ACTION_LEVEL1;
75 				phl_com->drv_mode = RTW_DRV_MODE_HIGH_THERMAL;
76 				action_changed = true;
77 			}
78 			else if(status == HALRF_THERMAL_STATUS_BELOW_THRESHOLD ||
79 				status == HALRF_THERMAL_STATUS_STAY_THRESHOLD){
80 				/* Do nothing */
81 			}
82 			else{
83 				PHL_ERR("Unknown thermal status(%x)!\n", status);
84 			}
85 			break;
86 		case PHL_THERMAL_PROTECT_ACTION_LEVEL1:
87 			if(status == HALRF_THERMAL_STATUS_BELOW_THRESHOLD){
88 				phl_com->thermal_protect_action =
89 					PHL_THERMAL_PROTECT_ACTION_NONE;
90 				phl_com->drv_mode = RTW_DRV_MODE_NORMAL;
91 				action_changed = true;
92 			}
93 			else if(status == HALRF_THERMAL_STATUS_ABOVE_THRESHOLD){
94 				phl_com->thermal_protect_action =
95 					PHL_THERMAL_PROTECT_ACTION_LEVEL2;
96 				action_changed = true;
97 			}
98 			else if(status == HALRF_THERMAL_STATUS_STAY_THRESHOLD){
99 				/* Do nothing */
100 			}
101 			else{
102 				PHL_ERR("Unknown thermal status(%x)!\n", status);
103 			}
104 			break;
105 		case PHL_THERMAL_PROTECT_ACTION_LEVEL2:
106 			if(status == HALRF_THERMAL_STATUS_BELOW_THRESHOLD){
107 				phl_com->thermal_protect_action =
108 					PHL_THERMAL_PROTECT_ACTION_LEVEL1;
109 				action_changed = true;
110 			}
111 			else if(status == HALRF_THERMAL_STATUS_ABOVE_THRESHOLD){
112 				/* No next action */
113 			}
114 			else if(status == HALRF_THERMAL_STATUS_STAY_THRESHOLD){
115 				/* Do nothing */
116 			}
117 			else{
118 				PHL_ERR("Unknown thermal status(%x)!\n", status);
119 			}
120 			break;
121 		default:
122 			PHL_ERR("Unknown thermal protect action(%x)!\n",
123 				phl_com->thermal_protect_action);
124 			break;
125 	}
126 	if(action_changed)
127 		PHL_INFO("%s: Next action = %x\n", __FUNCTION__, phl_com->thermal_protect_action);
128 	return action_changed;
129 }
130 
131 #endif /* CONFIG_PHL_THERMAL_PROTECT */
132 
133 
134 enum rtw_hal_status
rtw_hal_thermal_protect_cfg_tx_duty(void * hal,u16 tx_duty_interval,u8 ratio)135 rtw_hal_thermal_protect_cfg_tx_duty(
136 	void *hal,
137 	u16 tx_duty_interval,
138 	u8 ratio)
139 {
140 	struct hal_info_t *hal_info = (struct hal_info_t *)hal;
141 	enum rtw_hal_status hsts = RTW_HAL_STATUS_FAILURE;
142 	u16 pause_duration = 0, tx_duration = 0;
143 
144 	tx_duration = tx_duty_interval * ratio / 100;
145 	pause_duration = tx_duty_interval - tx_duration;
146 	PHL_INFO("%s: tx duty interval = %d tx duration = %d, pause duration = %d\n",
147 		 __FUNCTION__, tx_duty_interval, tx_duration, pause_duration);
148 
149 	hsts = rtw_hal_mac_set_tx_duty(hal_info, pause_duration, tx_duration);
150 
151 	return hsts;
152 }
153 
154 enum rtw_hal_status
rtw_hal_thermal_protect_stop_tx_duty(void * hal)155 rtw_hal_thermal_protect_stop_tx_duty(
156 	void *hal)
157 {
158 	struct hal_info_t *hal_info = (struct hal_info_t *)hal;
159 	enum rtw_hal_status hsts = RTW_HAL_STATUS_FAILURE;
160 
161 	PHL_INFO("%s: Stop tx duty!\n", __FUNCTION__);
162 
163 	hsts = rtw_hal_mac_stop_tx_duty(hal_info);
164 
165 	return hsts;
166 }