1 /* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */
2 /*
3  * Copyright (C) 2017 Intel Deutschland GmbH
4  * Copyright (C) 2018-2021 Intel Corporation
5  */
6 #ifndef __iwl_fw_acpi__
7 #define __iwl_fw_acpi__
8 
9 #include <linux/acpi.h>
10 #include "fw/api/commands.h"
11 #include "fw/api/power.h"
12 #include "fw/api/phy.h"
13 #include "fw/api/nvm-reg.h"
14 #include "fw/img.h"
15 #include "iwl-trans.h"
16 
17 
18 #define ACPI_WRDS_METHOD	"WRDS"
19 #define ACPI_EWRD_METHOD	"EWRD"
20 #define ACPI_WGDS_METHOD	"WGDS"
21 #define ACPI_WRDD_METHOD	"WRDD"
22 #define ACPI_SPLC_METHOD	"SPLC"
23 #define ACPI_ECKV_METHOD	"ECKV"
24 #define ACPI_PPAG_METHOD	"PPAG"
25 #define ACPI_WTAS_METHOD	"WTAS"
26 
27 #define ACPI_WIFI_DOMAIN	(0x07)
28 
29 #define ACPI_SAR_TABLE_SIZE		10
30 #define ACPI_SAR_PROFILE_NUM		4
31 
32 #define ACPI_GEO_TABLE_SIZE		6
33 #define ACPI_NUM_GEO_PROFILES		3
34 #define ACPI_GEO_PER_CHAIN_SIZE		3
35 
36 #define ACPI_SAR_NUM_CHAIN_LIMITS	2
37 #define ACPI_SAR_NUM_SUB_BANDS		5
38 #define ACPI_SAR_NUM_TABLES		1
39 
40 #define ACPI_WRDS_WIFI_DATA_SIZE	(ACPI_SAR_TABLE_SIZE + 2)
41 #define ACPI_EWRD_WIFI_DATA_SIZE	((ACPI_SAR_PROFILE_NUM - 1) * \
42 					 ACPI_SAR_TABLE_SIZE + 3)
43 #define ACPI_WGDS_WIFI_DATA_SIZE	19
44 #define ACPI_WRDD_WIFI_DATA_SIZE	2
45 #define ACPI_SPLC_WIFI_DATA_SIZE	2
46 #define ACPI_ECKV_WIFI_DATA_SIZE	2
47 
48 /*
49  * 1 type, 1 enabled, 1 block list size, 16 block list array
50  */
51 #define APCI_WTAS_BLACK_LIST_MAX	16
52 #define ACPI_WTAS_WIFI_DATA_SIZE	(3 + APCI_WTAS_BLACK_LIST_MAX)
53 
54 #define ACPI_WGDS_TABLE_SIZE		3
55 
56 #define ACPI_PPAG_WIFI_DATA_SIZE	((IWL_NUM_CHAIN_LIMITS * \
57 					  IWL_NUM_SUB_BANDS) + 2)
58 #define ACPI_PPAG_WIFI_DATA_SIZE_V2	((IWL_NUM_CHAIN_LIMITS * \
59 					  IWL_NUM_SUB_BANDS_V2) + 2)
60 
61 /* PPAG gain value bounds in 1/8 dBm */
62 #define ACPI_PPAG_MIN_LB -16
63 #define ACPI_PPAG_MAX_LB 24
64 #define ACPI_PPAG_MIN_HB -16
65 #define ACPI_PPAG_MAX_HB 40
66 
67 struct iwl_sar_profile {
68 	bool enabled;
69 	u8 table[ACPI_SAR_TABLE_SIZE];
70 };
71 
72 struct iwl_geo_profile {
73 	u8 values[ACPI_GEO_TABLE_SIZE];
74 };
75 
76 enum iwl_dsm_funcs_rev_0 {
77 	DSM_FUNC_QUERY = 0,
78 	DSM_FUNC_DISABLE_SRD = 1,
79 	DSM_FUNC_ENABLE_INDONESIA_5G2 = 2,
80 };
81 
82 enum iwl_dsm_values_srd {
83 	DSM_VALUE_SRD_ACTIVE,
84 	DSM_VALUE_SRD_PASSIVE,
85 	DSM_VALUE_SRD_DISABLE,
86 	DSM_VALUE_SRD_MAX
87 };
88 
89 enum iwl_dsm_values_indonesia {
90 	DSM_VALUE_INDONESIA_DISABLE,
91 	DSM_VALUE_INDONESIA_ENABLE,
92 	DSM_VALUE_INDONESIA_RESERVED,
93 	DSM_VALUE_INDONESIA_MAX
94 };
95 
96 /* DSM RFI uses a different GUID, so need separate definitions */
97 
98 #define DSM_RFI_FUNC_ENABLE 3
99 
100 enum iwl_dsm_values_rfi {
101 	DSM_VALUE_RFI_ENABLE,
102 	DSM_VALUE_RFI_DISABLE,
103 	DSM_VALUE_RFI_MAX
104 };
105 
106 #ifdef CONFIG_ACPI
107 
108 struct iwl_fw_runtime;
109 
110 extern const guid_t iwl_guid;
111 extern const guid_t iwl_rfi_guid;
112 
113 void *iwl_acpi_get_object(struct device *dev, acpi_string method);
114 
115 int iwl_acpi_get_dsm_u8(struct device *dev, int rev, int func,
116 			const guid_t *guid, u8 *value);
117 
118 union acpi_object *iwl_acpi_get_wifi_pkg(struct device *dev,
119 					 union acpi_object *data,
120 					 int data_size, int *tbl_rev);
121 
122 /**
123  * iwl_acpi_get_mcc - read MCC from ACPI, if available
124  *
125  * @dev: the struct device
126  * @mcc: output buffer (3 bytes) that will get the MCC
127  *
128  * This function tries to read the current MCC from ACPI if available.
129  */
130 int iwl_acpi_get_mcc(struct device *dev, char *mcc);
131 
132 u64 iwl_acpi_get_pwr_limit(struct device *dev);
133 
134 /*
135  * iwl_acpi_get_eckv - read external clock validation from ACPI, if available
136  *
137  * @dev: the struct device
138  * @extl_clk: output var (2 bytes) that will get the clk indication.
139  *
140  * This function tries to read the external clock indication
141  * from ACPI if available.
142  */
143 int iwl_acpi_get_eckv(struct device *dev, u32 *extl_clk);
144 
145 int iwl_sar_select_profile(struct iwl_fw_runtime *fwrt,
146 			   __le16 *per_chain, u32 n_tables, u32 n_subbands,
147 			   int prof_a, int prof_b);
148 
149 int iwl_sar_get_wrds_table(struct iwl_fw_runtime *fwrt);
150 
151 int iwl_sar_get_ewrd_table(struct iwl_fw_runtime *fwrt);
152 
153 int iwl_sar_get_wgds_table(struct iwl_fw_runtime *fwrt);
154 
155 bool iwl_sar_geo_support(struct iwl_fw_runtime *fwrt);
156 
157 int iwl_sar_geo_init(struct iwl_fw_runtime *fwrt,
158 		     struct iwl_per_chain_offset *table, u32 n_bands);
159 
160 int iwl_acpi_get_tas(struct iwl_fw_runtime *fwrt, __le32 *block_list_array,
161 		     int *block_list_size);
162 
163 #else /* CONFIG_ACPI */
164 
165 static inline void *iwl_acpi_get_object(struct device *dev, acpi_string method)
166 {
167 	return ERR_PTR(-ENOENT);
168 }
169 
170 static inline void *iwl_acpi_get_dsm_object(struct device *dev, int rev,
171 					    int func, union acpi_object *args)
172 {
173 	return ERR_PTR(-ENOENT);
174 }
175 
176 static inline int iwl_acpi_get_dsm_u8(struct device *dev, int rev, int func,
177 				      const guid_t *guid, u8 *value)
178 {
179 	return -ENOENT;
180 }
181 
182 static inline union acpi_object *iwl_acpi_get_wifi_pkg(struct device *dev,
183 						       union acpi_object *data,
184 						       int data_size,
185 						       int *tbl_rev)
186 {
187 	return ERR_PTR(-ENOENT);
188 }
189 
190 static inline int iwl_acpi_get_mcc(struct device *dev, char *mcc)
191 {
192 	return -ENOENT;
193 }
194 
195 static inline u64 iwl_acpi_get_pwr_limit(struct device *dev)
196 {
197 	return 0;
198 }
199 
200 static inline int iwl_acpi_get_eckv(struct device *dev, u32 *extl_clk)
201 {
202 	return -ENOENT;
203 }
204 
205 static inline int iwl_sar_select_profile(struct iwl_fw_runtime *fwrt,
206 			   __le16 *per_chain, u32 n_tables, u32 n_subbands,
207 			   int prof_a, int prof_b)
208 {
209 	return -ENOENT;
210 }
211 
212 static inline int iwl_sar_get_wrds_table(struct iwl_fw_runtime *fwrt)
213 {
214 	return -ENOENT;
215 }
216 
217 static inline int iwl_sar_get_ewrd_table(struct iwl_fw_runtime *fwrt)
218 {
219 	return -ENOENT;
220 }
221 
222 static inline int iwl_sar_get_wgds_table(struct iwl_fw_runtime *fwrt)
223 {
224 	return -ENOENT;
225 }
226 
227 static inline bool iwl_sar_geo_support(struct iwl_fw_runtime *fwrt)
228 {
229 	return false;
230 }
231 
232 static inline int iwl_acpi_get_tas(struct iwl_fw_runtime *fwrt,
233 				   __le32 *block_list_array,
234 				   int *block_list_size)
235 {
236 	return -ENOENT;
237 }
238 #endif /* CONFIG_ACPI */
239 #endif /* __iwl_fw_acpi__ */
240