1 /* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */
2 /*
3  * Copyright (C) 2017 Intel Deutschland GmbH
4  * Copyright (C) 2018-2020 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) + 3)
58 #define ACPI_PPAG_WIFI_DATA_SIZE_V2	((IWL_NUM_CHAIN_LIMITS * \
59 					IWL_NUM_SUB_BANDS_V2) + 3)
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 #ifdef CONFIG_ACPI
97 
98 struct iwl_fw_runtime;
99 
100 void *iwl_acpi_get_object(struct device *dev, acpi_string method);
101 
102 int iwl_acpi_get_dsm_u8(struct device *dev, int rev, int func);
103 
104 union acpi_object *iwl_acpi_get_wifi_pkg(struct device *dev,
105 					 union acpi_object *data,
106 					 int data_size, int *tbl_rev);
107 
108 /**
109  * iwl_acpi_get_mcc - read MCC from ACPI, if available
110  *
111  * @dev: the struct device
112  * @mcc: output buffer (3 bytes) that will get the MCC
113  *
114  * This function tries to read the current MCC from ACPI if available.
115  */
116 int iwl_acpi_get_mcc(struct device *dev, char *mcc);
117 
118 u64 iwl_acpi_get_pwr_limit(struct device *dev);
119 
120 /*
121  * iwl_acpi_get_eckv - read external clock validation from ACPI, if available
122  *
123  * @dev: the struct device
124  * @extl_clk: output var (2 bytes) that will get the clk indication.
125  *
126  * This function tries to read the external clock indication
127  * from ACPI if available.
128  */
129 int iwl_acpi_get_eckv(struct device *dev, u32 *extl_clk);
130 
131 int iwl_sar_select_profile(struct iwl_fw_runtime *fwrt,
132 			   __le16 *per_chain, u32 n_tables, u32 n_subbands,
133 			   int prof_a, int prof_b);
134 
135 int iwl_sar_get_wrds_table(struct iwl_fw_runtime *fwrt);
136 
137 int iwl_sar_get_ewrd_table(struct iwl_fw_runtime *fwrt);
138 
139 int iwl_sar_get_wgds_table(struct iwl_fw_runtime *fwrt);
140 
141 bool iwl_sar_geo_support(struct iwl_fw_runtime *fwrt);
142 
143 int iwl_sar_geo_init(struct iwl_fw_runtime *fwrt,
144 		     struct iwl_per_chain_offset *table, u32 n_bands);
145 
146 int iwl_acpi_get_tas(struct iwl_fw_runtime *fwrt, __le32 *block_list_array,
147 		     int *block_list_size);
148 
149 #else /* CONFIG_ACPI */
150 
151 static inline void *iwl_acpi_get_object(struct device *dev, acpi_string method)
152 {
153 	return ERR_PTR(-ENOENT);
154 }
155 
156 static inline void *iwl_acpi_get_dsm_object(struct device *dev, int rev,
157 					    int func, union acpi_object *args)
158 {
159 	return ERR_PTR(-ENOENT);
160 }
161 
162 static inline int iwl_acpi_get_dsm_u8(struct device *dev, int rev, int func)
163 {
164 	return -ENOENT;
165 }
166 
167 static inline union acpi_object *iwl_acpi_get_wifi_pkg(struct device *dev,
168 						       union acpi_object *data,
169 						       int data_size,
170 						       int *tbl_rev)
171 {
172 	return ERR_PTR(-ENOENT);
173 }
174 
175 static inline int iwl_acpi_get_mcc(struct device *dev, char *mcc)
176 {
177 	return -ENOENT;
178 }
179 
180 static inline u64 iwl_acpi_get_pwr_limit(struct device *dev)
181 {
182 	return 0;
183 }
184 
185 static inline int iwl_acpi_get_eckv(struct device *dev, u32 *extl_clk)
186 {
187 	return -ENOENT;
188 }
189 
190 static inline int iwl_sar_select_profile(struct iwl_fw_runtime *fwrt,
191 			   __le16 *per_chain, u32 n_tables, u32 n_subbands,
192 			   int prof_a, int prof_b)
193 {
194 	return -ENOENT;
195 }
196 
197 static inline int iwl_sar_get_wrds_table(struct iwl_fw_runtime *fwrt)
198 {
199 	return -ENOENT;
200 }
201 
202 static inline int iwl_sar_get_ewrd_table(struct iwl_fw_runtime *fwrt)
203 {
204 	return -ENOENT;
205 }
206 
207 static inline int iwl_sar_get_wgds_table(struct iwl_fw_runtime *fwrt)
208 {
209 	return -ENOENT;
210 }
211 
212 static inline bool iwl_sar_geo_support(struct iwl_fw_runtime *fwrt)
213 {
214 	return false;
215 }
216 
217 static inline int iwl_acpi_get_tas(struct iwl_fw_runtime *fwrt,
218 				   __le32 *block_list_array,
219 				   int *block_list_size)
220 {
221 	return -ENOENT;
222 }
223 #endif /* CONFIG_ACPI */
224 #endif /* __iwl_fw_acpi__ */
225