1 // SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
2 /* Copyright(c) 2019-2020 Realtek Corporation
3 */
4
5 #include "acpi.h"
6 #include "debug.h"
7 #include "ps.h"
8 #include "util.h"
9
10 #define COUNTRY_REGD(_alpha2, _txpwr_regd...) \
11 {.alpha2 = (_alpha2), \
12 .txpwr_regd = {_txpwr_regd}, \
13 }
14
15 static const struct rtw89_regd rtw89_ww_regd =
16 COUNTRY_REGD("00", RTW89_WW, RTW89_WW, RTW89_WW);
17
18 static const struct rtw89_regd rtw89_regd_map[] = {
19 COUNTRY_REGD("AR", RTW89_MEXICO, RTW89_MEXICO, RTW89_FCC),
20 COUNTRY_REGD("BO", RTW89_FCC, RTW89_FCC, RTW89_FCC),
21 COUNTRY_REGD("BR", RTW89_FCC, RTW89_FCC, RTW89_FCC),
22 COUNTRY_REGD("CL", RTW89_CHILE, RTW89_CHILE, RTW89_CHILE),
23 COUNTRY_REGD("CO", RTW89_FCC, RTW89_FCC, RTW89_FCC),
24 COUNTRY_REGD("CR", RTW89_FCC, RTW89_FCC, RTW89_FCC),
25 COUNTRY_REGD("EC", RTW89_FCC, RTW89_FCC, RTW89_NA),
26 COUNTRY_REGD("SV", RTW89_FCC, RTW89_FCC, RTW89_FCC),
27 COUNTRY_REGD("GT", RTW89_FCC, RTW89_FCC, RTW89_FCC),
28 COUNTRY_REGD("HN", RTW89_FCC, RTW89_FCC, RTW89_FCC),
29 COUNTRY_REGD("MX", RTW89_MEXICO, RTW89_MEXICO, RTW89_FCC),
30 COUNTRY_REGD("NI", RTW89_FCC, RTW89_FCC, RTW89_NA),
31 COUNTRY_REGD("PA", RTW89_FCC, RTW89_FCC, RTW89_NA),
32 COUNTRY_REGD("PY", RTW89_FCC, RTW89_FCC, RTW89_NA),
33 COUNTRY_REGD("PE", RTW89_FCC, RTW89_FCC, RTW89_FCC),
34 COUNTRY_REGD("US", RTW89_FCC, RTW89_FCC, RTW89_FCC),
35 COUNTRY_REGD("UY", RTW89_FCC, RTW89_FCC, RTW89_NA),
36 COUNTRY_REGD("VE", RTW89_FCC, RTW89_FCC, RTW89_NA),
37 COUNTRY_REGD("PR", RTW89_FCC, RTW89_FCC, RTW89_NA),
38 COUNTRY_REGD("DO", RTW89_FCC, RTW89_FCC, RTW89_NA),
39 COUNTRY_REGD("AT", RTW89_ETSI, RTW89_ETSI, RTW89_ETSI),
40 COUNTRY_REGD("BE", RTW89_ETSI, RTW89_ETSI, RTW89_ETSI),
41 COUNTRY_REGD("CY", RTW89_ETSI, RTW89_ETSI, RTW89_ETSI),
42 COUNTRY_REGD("CZ", RTW89_ETSI, RTW89_ETSI, RTW89_ETSI),
43 COUNTRY_REGD("DK", RTW89_ETSI, RTW89_ETSI, RTW89_ETSI),
44 COUNTRY_REGD("EE", RTW89_ETSI, RTW89_ETSI, RTW89_ETSI),
45 COUNTRY_REGD("FI", RTW89_ETSI, RTW89_ETSI, RTW89_ETSI),
46 COUNTRY_REGD("FR", RTW89_ETSI, RTW89_ETSI, RTW89_ETSI),
47 COUNTRY_REGD("DE", RTW89_ETSI, RTW89_ETSI, RTW89_ETSI),
48 COUNTRY_REGD("GR", RTW89_ETSI, RTW89_ETSI, RTW89_ETSI),
49 COUNTRY_REGD("HU", RTW89_ETSI, RTW89_ETSI, RTW89_ETSI),
50 COUNTRY_REGD("IS", RTW89_ETSI, RTW89_ETSI, RTW89_ETSI),
51 COUNTRY_REGD("IE", RTW89_ETSI, RTW89_ETSI, RTW89_ETSI),
52 COUNTRY_REGD("IT", RTW89_ETSI, RTW89_ETSI, RTW89_ETSI),
53 COUNTRY_REGD("LV", RTW89_ETSI, RTW89_ETSI, RTW89_ETSI),
54 COUNTRY_REGD("LI", RTW89_ETSI, RTW89_ETSI, RTW89_ETSI),
55 COUNTRY_REGD("LT", RTW89_ETSI, RTW89_ETSI, RTW89_ETSI),
56 COUNTRY_REGD("LU", RTW89_ETSI, RTW89_ETSI, RTW89_ETSI),
57 COUNTRY_REGD("MT", RTW89_ETSI, RTW89_ETSI, RTW89_ETSI),
58 COUNTRY_REGD("MC", RTW89_ETSI, RTW89_ETSI, RTW89_ETSI),
59 COUNTRY_REGD("NL", RTW89_ETSI, RTW89_ETSI, RTW89_ETSI),
60 COUNTRY_REGD("NO", RTW89_ETSI, RTW89_ETSI, RTW89_ETSI),
61 COUNTRY_REGD("PL", RTW89_ETSI, RTW89_ETSI, RTW89_ETSI),
62 COUNTRY_REGD("PT", RTW89_ETSI, RTW89_ETSI, RTW89_ETSI),
63 COUNTRY_REGD("SK", RTW89_ETSI, RTW89_ETSI, RTW89_ETSI),
64 COUNTRY_REGD("SI", RTW89_ETSI, RTW89_ETSI, RTW89_ETSI),
65 COUNTRY_REGD("ES", RTW89_ETSI, RTW89_ETSI, RTW89_ETSI),
66 COUNTRY_REGD("SE", RTW89_ETSI, RTW89_ETSI, RTW89_ETSI),
67 COUNTRY_REGD("CH", RTW89_ETSI, RTW89_ETSI, RTW89_ETSI),
68 COUNTRY_REGD("GB", RTW89_UK, RTW89_UK, RTW89_UK),
69 COUNTRY_REGD("AL", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
70 COUNTRY_REGD("AZ", RTW89_ETSI, RTW89_ETSI, RTW89_ETSI),
71 COUNTRY_REGD("BH", RTW89_ETSI, RTW89_ETSI, RTW89_ETSI),
72 COUNTRY_REGD("BA", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
73 COUNTRY_REGD("BG", RTW89_ETSI, RTW89_ETSI, RTW89_ETSI),
74 COUNTRY_REGD("HR", RTW89_ETSI, RTW89_ETSI, RTW89_ETSI),
75 COUNTRY_REGD("EG", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
76 COUNTRY_REGD("GH", RTW89_ETSI, RTW89_ETSI, RTW89_ETSI),
77 COUNTRY_REGD("IQ", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
78 COUNTRY_REGD("IL", RTW89_ETSI, RTW89_ETSI, RTW89_ETSI),
79 COUNTRY_REGD("JO", RTW89_ETSI, RTW89_ETSI, RTW89_ETSI),
80 COUNTRY_REGD("KZ", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
81 COUNTRY_REGD("KE", RTW89_ETSI, RTW89_ETSI, RTW89_ETSI),
82 COUNTRY_REGD("KW", RTW89_ETSI, RTW89_ETSI, RTW89_ETSI),
83 COUNTRY_REGD("KG", RTW89_ETSI, RTW89_ETSI, RTW89_ETSI),
84 COUNTRY_REGD("LB", RTW89_ETSI, RTW89_ETSI, RTW89_ETSI),
85 COUNTRY_REGD("LS", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
86 COUNTRY_REGD("MK", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
87 COUNTRY_REGD("MA", RTW89_ETSI, RTW89_ETSI, RTW89_ETSI),
88 COUNTRY_REGD("MZ", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
89 COUNTRY_REGD("NA", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
90 COUNTRY_REGD("NG", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
91 COUNTRY_REGD("OM", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
92 COUNTRY_REGD("QA", RTW89_QATAR, RTW89_QATAR, RTW89_QATAR),
93 COUNTRY_REGD("RO", RTW89_ETSI, RTW89_ETSI, RTW89_ETSI),
94 COUNTRY_REGD("RU", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
95 COUNTRY_REGD("SA", RTW89_ETSI, RTW89_ETSI, RTW89_ETSI),
96 COUNTRY_REGD("SN", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
97 COUNTRY_REGD("RS", RTW89_ETSI, RTW89_ETSI, RTW89_ETSI),
98 COUNTRY_REGD("ME", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
99 COUNTRY_REGD("ZA", RTW89_ETSI, RTW89_ETSI, RTW89_ETSI),
100 COUNTRY_REGD("TR", RTW89_ETSI, RTW89_ETSI, RTW89_ETSI),
101 COUNTRY_REGD("UA", RTW89_UKRAINE, RTW89_UKRAINE, RTW89_UKRAINE),
102 COUNTRY_REGD("AE", RTW89_ETSI, RTW89_ETSI, RTW89_ETSI),
103 COUNTRY_REGD("YE", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
104 COUNTRY_REGD("ZW", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
105 COUNTRY_REGD("BD", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
106 COUNTRY_REGD("KH", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
107 COUNTRY_REGD("CN", RTW89_CN, RTW89_CN, RTW89_CN),
108 COUNTRY_REGD("HK", RTW89_ETSI, RTW89_ETSI, RTW89_ETSI),
109 COUNTRY_REGD("IN", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
110 COUNTRY_REGD("ID", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
111 COUNTRY_REGD("KR", RTW89_KCC, RTW89_KCC, RTW89_KCC),
112 COUNTRY_REGD("MY", RTW89_ETSI, RTW89_ETSI, RTW89_ETSI),
113 COUNTRY_REGD("PK", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
114 COUNTRY_REGD("PH", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
115 COUNTRY_REGD("SG", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
116 COUNTRY_REGD("LK", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
117 COUNTRY_REGD("TW", RTW89_FCC, RTW89_FCC, RTW89_NA),
118 COUNTRY_REGD("TH", RTW89_WW, RTW89_WW, RTW89_WW),
119 COUNTRY_REGD("VN", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
120 COUNTRY_REGD("AU", RTW89_ACMA, RTW89_ACMA, RTW89_ACMA),
121 COUNTRY_REGD("NZ", RTW89_ACMA, RTW89_ACMA, RTW89_ACMA),
122 COUNTRY_REGD("PG", RTW89_ETSI, RTW89_ETSI, RTW89_ETSI),
123 COUNTRY_REGD("CA", RTW89_IC, RTW89_IC, RTW89_IC),
124 COUNTRY_REGD("JP", RTW89_MKK, RTW89_MKK, RTW89_MKK),
125 COUNTRY_REGD("JM", RTW89_FCC, RTW89_FCC, RTW89_FCC),
126 COUNTRY_REGD("AN", RTW89_FCC, RTW89_FCC, RTW89_FCC),
127 COUNTRY_REGD("TT", RTW89_FCC, RTW89_FCC, RTW89_NA),
128 COUNTRY_REGD("TN", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
129 COUNTRY_REGD("AF", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
130 COUNTRY_REGD("DZ", RTW89_ETSI, RTW89_ETSI, RTW89_ETSI),
131 COUNTRY_REGD("AS", RTW89_FCC, RTW89_FCC, RTW89_NA),
132 COUNTRY_REGD("AD", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
133 COUNTRY_REGD("AO", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
134 COUNTRY_REGD("AI", RTW89_ETSI, RTW89_ETSI, RTW89_ETSI),
135 COUNTRY_REGD("AQ", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
136 COUNTRY_REGD("AG", RTW89_FCC, RTW89_FCC, RTW89_FCC),
137 COUNTRY_REGD("AM", RTW89_ETSI, RTW89_ETSI, RTW89_ETSI),
138 COUNTRY_REGD("AW", RTW89_FCC, RTW89_FCC, RTW89_FCC),
139 COUNTRY_REGD("BS", RTW89_FCC, RTW89_FCC, RTW89_FCC),
140 COUNTRY_REGD("BB", RTW89_FCC, RTW89_FCC, RTW89_FCC),
141 COUNTRY_REGD("BY", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
142 COUNTRY_REGD("BZ", RTW89_FCC, RTW89_FCC, RTW89_NA),
143 COUNTRY_REGD("BJ", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
144 COUNTRY_REGD("BM", RTW89_FCC, RTW89_FCC, RTW89_FCC),
145 COUNTRY_REGD("BT", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
146 COUNTRY_REGD("BW", RTW89_ETSI, RTW89_ETSI, RTW89_ETSI),
147 COUNTRY_REGD("BV", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
148 COUNTRY_REGD("IO", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
149 COUNTRY_REGD("VG", RTW89_FCC, RTW89_FCC, RTW89_FCC),
150 COUNTRY_REGD("BN", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
151 COUNTRY_REGD("BF", RTW89_ETSI, RTW89_ETSI, RTW89_ETSI),
152 COUNTRY_REGD("MM", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
153 COUNTRY_REGD("BI", RTW89_ETSI, RTW89_ETSI, RTW89_ETSI),
154 COUNTRY_REGD("CM", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
155 COUNTRY_REGD("CV", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
156 COUNTRY_REGD("KY", RTW89_FCC, RTW89_FCC, RTW89_FCC),
157 COUNTRY_REGD("CF", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
158 COUNTRY_REGD("TD", RTW89_ETSI, RTW89_ETSI, RTW89_ETSI),
159 COUNTRY_REGD("CX", RTW89_ACMA, RTW89_ACMA, RTW89_NA),
160 COUNTRY_REGD("CC", RTW89_ACMA, RTW89_ACMA, RTW89_NA),
161 COUNTRY_REGD("KM", RTW89_ETSI, RTW89_ETSI, RTW89_ETSI),
162 COUNTRY_REGD("CG", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
163 COUNTRY_REGD("CD", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
164 COUNTRY_REGD("CK", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
165 COUNTRY_REGD("CI", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
166 COUNTRY_REGD("DJ", RTW89_ETSI, RTW89_ETSI, RTW89_ETSI),
167 COUNTRY_REGD("DM", RTW89_FCC, RTW89_FCC, RTW89_NA),
168 COUNTRY_REGD("GQ", RTW89_ETSI, RTW89_ETSI, RTW89_ETSI),
169 COUNTRY_REGD("ER", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
170 COUNTRY_REGD("ET", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
171 COUNTRY_REGD("FK", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
172 COUNTRY_REGD("FO", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
173 COUNTRY_REGD("FJ", RTW89_FCC, RTW89_FCC, RTW89_NA),
174 COUNTRY_REGD("GF", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
175 COUNTRY_REGD("PF", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
176 COUNTRY_REGD("TF", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
177 COUNTRY_REGD("GA", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
178 COUNTRY_REGD("GM", RTW89_ETSI, RTW89_ETSI, RTW89_ETSI),
179 COUNTRY_REGD("GE", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
180 COUNTRY_REGD("GI", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
181 COUNTRY_REGD("GL", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
182 COUNTRY_REGD("GD", RTW89_FCC, RTW89_FCC, RTW89_NA),
183 COUNTRY_REGD("GP", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
184 COUNTRY_REGD("GU", RTW89_FCC, RTW89_FCC, RTW89_NA),
185 COUNTRY_REGD("GG", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
186 COUNTRY_REGD("GN", RTW89_ETSI, RTW89_ETSI, RTW89_ETSI),
187 COUNTRY_REGD("GW", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
188 COUNTRY_REGD("GY", RTW89_FCC, RTW89_FCC, RTW89_NA),
189 COUNTRY_REGD("HT", RTW89_FCC, RTW89_FCC, RTW89_FCC),
190 COUNTRY_REGD("HM", RTW89_ACMA, RTW89_ACMA, RTW89_NA),
191 COUNTRY_REGD("VA", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
192 COUNTRY_REGD("IM", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
193 COUNTRY_REGD("JE", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
194 COUNTRY_REGD("KI", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
195 COUNTRY_REGD("XK", RTW89_ETSI, RTW89_ETSI, RTW89_ETSI),
196 COUNTRY_REGD("LA", RTW89_ETSI, RTW89_ETSI, RTW89_ETSI),
197 COUNTRY_REGD("LR", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
198 COUNTRY_REGD("LY", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
199 COUNTRY_REGD("MO", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
200 COUNTRY_REGD("MG", RTW89_ETSI, RTW89_ETSI, RTW89_ETSI),
201 COUNTRY_REGD("MW", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
202 COUNTRY_REGD("MV", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
203 COUNTRY_REGD("ML", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
204 COUNTRY_REGD("MH", RTW89_FCC, RTW89_FCC, RTW89_NA),
205 COUNTRY_REGD("MQ", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
206 COUNTRY_REGD("MR", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
207 COUNTRY_REGD("MU", RTW89_ETSI, RTW89_ETSI, RTW89_ETSI),
208 COUNTRY_REGD("YT", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
209 COUNTRY_REGD("FM", RTW89_FCC, RTW89_FCC, RTW89_NA),
210 COUNTRY_REGD("MD", RTW89_ETSI, RTW89_ETSI, RTW89_ETSI),
211 COUNTRY_REGD("MN", RTW89_ETSI, RTW89_ETSI, RTW89_ETSI),
212 COUNTRY_REGD("MS", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
213 COUNTRY_REGD("NR", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
214 COUNTRY_REGD("NP", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
215 COUNTRY_REGD("NC", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
216 COUNTRY_REGD("NE", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
217 COUNTRY_REGD("NU", RTW89_ACMA, RTW89_ACMA, RTW89_NA),
218 COUNTRY_REGD("NF", RTW89_ACMA, RTW89_ACMA, RTW89_NA),
219 COUNTRY_REGD("MP", RTW89_FCC, RTW89_FCC, RTW89_NA),
220 COUNTRY_REGD("PW", RTW89_FCC, RTW89_FCC, RTW89_NA),
221 COUNTRY_REGD("RE", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
222 COUNTRY_REGD("RW", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
223 COUNTRY_REGD("SH", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
224 COUNTRY_REGD("KN", RTW89_FCC, RTW89_FCC, RTW89_FCC),
225 COUNTRY_REGD("LC", RTW89_FCC, RTW89_FCC, RTW89_FCC),
226 COUNTRY_REGD("MF", RTW89_FCC, RTW89_FCC, RTW89_NA),
227 COUNTRY_REGD("SX", RTW89_FCC, RTW89_FCC, RTW89_NA),
228 COUNTRY_REGD("PM", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
229 COUNTRY_REGD("VC", RTW89_FCC, RTW89_FCC, RTW89_NA),
230 COUNTRY_REGD("WS", RTW89_FCC, RTW89_FCC, RTW89_NA),
231 COUNTRY_REGD("SM", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
232 COUNTRY_REGD("ST", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
233 COUNTRY_REGD("SC", RTW89_FCC, RTW89_FCC, RTW89_NA),
234 COUNTRY_REGD("SL", RTW89_ETSI, RTW89_ETSI, RTW89_ETSI),
235 COUNTRY_REGD("SB", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
236 COUNTRY_REGD("SO", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
237 COUNTRY_REGD("GS", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
238 COUNTRY_REGD("SR", RTW89_FCC, RTW89_FCC, RTW89_FCC),
239 COUNTRY_REGD("SJ", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
240 COUNTRY_REGD("SZ", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
241 COUNTRY_REGD("TJ", RTW89_ETSI, RTW89_ETSI, RTW89_ETSI),
242 COUNTRY_REGD("TZ", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
243 COUNTRY_REGD("TG", RTW89_ETSI, RTW89_ETSI, RTW89_ETSI),
244 COUNTRY_REGD("TK", RTW89_ACMA, RTW89_ACMA, RTW89_NA),
245 COUNTRY_REGD("TO", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
246 COUNTRY_REGD("TM", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
247 COUNTRY_REGD("TC", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
248 COUNTRY_REGD("TV", RTW89_ETSI, RTW89_NA, RTW89_NA),
249 COUNTRY_REGD("UG", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
250 COUNTRY_REGD("VI", RTW89_FCC, RTW89_FCC, RTW89_NA),
251 COUNTRY_REGD("UZ", RTW89_ETSI, RTW89_ETSI, RTW89_ETSI),
252 COUNTRY_REGD("VU", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
253 COUNTRY_REGD("WF", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
254 COUNTRY_REGD("EH", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
255 COUNTRY_REGD("ZM", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
256 COUNTRY_REGD("IR", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
257 COUNTRY_REGD("PS", RTW89_ETSI, RTW89_ETSI, RTW89_NA),
258 };
259
rtw89_regd_find_reg_by_name(char * alpha2)260 static const struct rtw89_regd *rtw89_regd_find_reg_by_name(char *alpha2)
261 {
262 u32 i;
263
264 for (i = 0; i < ARRAY_SIZE(rtw89_regd_map); i++) {
265 if (!memcmp(rtw89_regd_map[i].alpha2, alpha2, 2))
266 return &rtw89_regd_map[i];
267 }
268
269 return &rtw89_ww_regd;
270 }
271
rtw89_regd_is_ww(const struct rtw89_regd * regd)272 static bool rtw89_regd_is_ww(const struct rtw89_regd *regd)
273 {
274 return regd == &rtw89_ww_regd;
275 }
276
277 #define rtw89_debug_regd(_dev, _regd, _desc, _argv...) \
278 do { \
279 typeof(_regd) __r = _regd; \
280 rtw89_debug(_dev, RTW89_DBG_REGD, _desc \
281 ": %c%c: mapping txregd to {2g: %d, 5g: %d, 6g: %d}\n", \
282 ##_argv, __r->alpha2[0], __r->alpha2[1], \
283 __r->txpwr_regd[RTW89_BAND_2G], \
284 __r->txpwr_regd[RTW89_BAND_5G], \
285 __r->txpwr_regd[RTW89_BAND_6G]); \
286 } while (0)
287
rtw89_regd_setup_unii4(struct rtw89_dev * rtwdev,struct wiphy * wiphy)288 static void rtw89_regd_setup_unii4(struct rtw89_dev *rtwdev,
289 struct wiphy *wiphy)
290 {
291 const struct rtw89_chip_info *chip = rtwdev->chip;
292 bool regd_allow_unii_4 = chip->support_unii4;
293 struct ieee80211_supported_band *sband;
294 int ret;
295 u8 val;
296
297 if (!chip->support_unii4)
298 goto bottom;
299
300 ret = rtw89_acpi_evaluate_dsm(rtwdev, RTW89_ACPI_DSM_FUNC_59G_EN, &val);
301 if (ret) {
302 rtw89_debug(rtwdev, RTW89_DBG_REGD,
303 "acpi: cannot eval unii 4: %d\n", ret);
304 goto bottom;
305 }
306
307 rtw89_debug(rtwdev, RTW89_DBG_REGD,
308 "acpi: eval if allow unii 4: %d\n", val);
309
310 switch (val) {
311 case 0:
312 regd_allow_unii_4 = false;
313 break;
314 case 1:
315 regd_allow_unii_4 = true;
316 break;
317 default:
318 break;
319 }
320
321 bottom:
322 rtw89_debug(rtwdev, RTW89_DBG_REGD, "regd: allow unii 4: %d\n",
323 regd_allow_unii_4);
324
325 if (regd_allow_unii_4)
326 return;
327
328 sband = wiphy->bands[NL80211_BAND_5GHZ];
329 if (!sband)
330 return;
331
332 sband->n_channels -= 3;
333 }
334
rtw89_regd_setup_6ghz(struct rtw89_dev * rtwdev,struct wiphy * wiphy)335 static void rtw89_regd_setup_6ghz(struct rtw89_dev *rtwdev, struct wiphy *wiphy)
336 {
337 const struct rtw89_chip_info *chip = rtwdev->chip;
338 bool chip_support_6ghz = chip->support_bands & BIT(NL80211_BAND_6GHZ);
339 bool regd_allow_6ghz = chip_support_6ghz;
340 struct ieee80211_supported_band *sband;
341 int ret;
342 u8 val;
343
344 if (!chip_support_6ghz)
345 goto bottom;
346
347 ret = rtw89_acpi_evaluate_dsm(rtwdev, RTW89_ACPI_DSM_FUNC_6G_DIS, &val);
348 if (ret) {
349 rtw89_debug(rtwdev, RTW89_DBG_REGD,
350 "acpi: cannot eval 6ghz: %d\n", ret);
351 goto bottom;
352 }
353
354 rtw89_debug(rtwdev, RTW89_DBG_REGD,
355 "acpi: eval if disallow 6ghz: %d\n", val);
356
357 switch (val) {
358 case 0:
359 regd_allow_6ghz = true;
360 break;
361 case 1:
362 regd_allow_6ghz = false;
363 break;
364 default:
365 break;
366 }
367
368 bottom:
369 rtw89_debug(rtwdev, RTW89_DBG_REGD, "regd: allow 6ghz: %d\n",
370 regd_allow_6ghz);
371
372 if (regd_allow_6ghz)
373 return;
374
375 sband = wiphy->bands[NL80211_BAND_6GHZ];
376 if (!sband)
377 return;
378
379 wiphy->bands[NL80211_BAND_6GHZ] = NULL;
380 kfree(sband->iftype_data);
381 kfree(sband);
382 }
383
rtw89_regd_setup(struct rtw89_dev * rtwdev)384 int rtw89_regd_setup(struct rtw89_dev *rtwdev)
385 {
386 struct wiphy *wiphy = rtwdev->hw->wiphy;
387
388 if (!wiphy)
389 return -EINVAL;
390
391 rtw89_regd_setup_unii4(rtwdev, wiphy);
392 rtw89_regd_setup_6ghz(rtwdev, wiphy);
393
394 wiphy->reg_notifier = rtw89_regd_notifier;
395 return 0;
396 }
397
rtw89_regd_init(struct rtw89_dev * rtwdev,void (* reg_notifier)(struct wiphy * wiphy,struct regulatory_request * request))398 int rtw89_regd_init(struct rtw89_dev *rtwdev,
399 void (*reg_notifier)(struct wiphy *wiphy,
400 struct regulatory_request *request))
401 {
402 struct rtw89_regulatory_info *regulatory = &rtwdev->regulatory;
403 const struct rtw89_regd *chip_regd;
404 struct wiphy *wiphy = rtwdev->hw->wiphy;
405 int ret;
406
407 regulatory->reg_6ghz_power = RTW89_REG_6GHZ_POWER_DFLT;
408
409 if (!wiphy)
410 return -EINVAL;
411
412 chip_regd = rtw89_regd_find_reg_by_name(rtwdev->efuse.country_code);
413 if (!rtw89_regd_is_ww(chip_regd)) {
414 rtwdev->regulatory.regd = chip_regd;
415 /* Ignore country ie if there is a country domain programmed in chip */
416 wiphy->regulatory_flags |= REGULATORY_COUNTRY_IE_IGNORE;
417 wiphy->regulatory_flags |= REGULATORY_STRICT_REG;
418
419 ret = regulatory_hint(rtwdev->hw->wiphy,
420 rtwdev->regulatory.regd->alpha2);
421 if (ret)
422 rtw89_warn(rtwdev, "failed to hint regulatory:%d\n", ret);
423
424 rtw89_debug_regd(rtwdev, chip_regd, "efuse country code");
425 return 0;
426 }
427
428 rtw89_debug_regd(rtwdev, rtwdev->regulatory.regd,
429 "worldwide roaming chip, follow the setting of stack");
430 return 0;
431 }
432
rtw89_regd_notifier_apply(struct rtw89_dev * rtwdev,struct wiphy * wiphy,struct regulatory_request * request)433 static void rtw89_regd_notifier_apply(struct rtw89_dev *rtwdev,
434 struct wiphy *wiphy,
435 struct regulatory_request *request)
436 {
437 rtwdev->regulatory.regd = rtw89_regd_find_reg_by_name(request->alpha2);
438 /* This notification might be set from the system of distros,
439 * and it does not expect the regulatory will be modified by
440 * connecting to an AP (i.e. country ie).
441 */
442 if (request->initiator == NL80211_REGDOM_SET_BY_USER &&
443 !rtw89_regd_is_ww(rtwdev->regulatory.regd))
444 wiphy->regulatory_flags |= REGULATORY_COUNTRY_IE_IGNORE;
445 else
446 wiphy->regulatory_flags &= ~REGULATORY_COUNTRY_IE_IGNORE;
447 }
448
rtw89_regd_notifier(struct wiphy * wiphy,struct regulatory_request * request)449 void rtw89_regd_notifier(struct wiphy *wiphy, struct regulatory_request *request)
450 {
451 struct ieee80211_hw *hw = wiphy_to_ieee80211_hw(wiphy);
452 struct rtw89_dev *rtwdev = hw->priv;
453
454 mutex_lock(&rtwdev->mutex);
455 rtw89_leave_ps_mode(rtwdev);
456
457 if (wiphy->regd) {
458 rtw89_debug(rtwdev, RTW89_DBG_REGD,
459 "There is a country domain programmed in chip, ignore notifications\n");
460 goto exit;
461 }
462 rtw89_regd_notifier_apply(rtwdev, wiphy, request);
463 rtw89_debug_regd(rtwdev, rtwdev->regulatory.regd,
464 "get from initiator %d, alpha2",
465 request->initiator);
466
467 rtw89_core_set_chip_txpwr(rtwdev);
468
469 exit:
470 mutex_unlock(&rtwdev->mutex);
471 }
472
__rtw89_reg_6ghz_power_recalc(struct rtw89_dev * rtwdev)473 static void __rtw89_reg_6ghz_power_recalc(struct rtw89_dev *rtwdev)
474 {
475 struct rtw89_regulatory_info *regulatory = &rtwdev->regulatory;
476 enum rtw89_reg_6ghz_power sel;
477 const struct rtw89_chan *chan;
478 struct rtw89_vif *rtwvif;
479 int count = 0;
480
481 rtw89_for_each_rtwvif(rtwdev, rtwvif) {
482 chan = rtw89_chan_get(rtwdev, rtwvif->sub_entity_idx);
483 if (chan->band_type != RTW89_BAND_6G)
484 continue;
485
486 if (count != 0 && rtwvif->reg_6ghz_power == sel)
487 continue;
488
489 sel = rtwvif->reg_6ghz_power;
490 count++;
491 }
492
493 if (count != 1)
494 sel = RTW89_REG_6GHZ_POWER_DFLT;
495
496 if (regulatory->reg_6ghz_power == sel)
497 return;
498
499 rtw89_debug(rtwdev, RTW89_DBG_REGD,
500 "recalc 6 GHz reg power type to %d\n", sel);
501
502 regulatory->reg_6ghz_power = sel;
503
504 rtw89_core_set_chip_txpwr(rtwdev);
505 }
506
rtw89_reg_6ghz_power_recalc(struct rtw89_dev * rtwdev,struct rtw89_vif * rtwvif,bool active)507 void rtw89_reg_6ghz_power_recalc(struct rtw89_dev *rtwdev,
508 struct rtw89_vif *rtwvif, bool active)
509 {
510 struct ieee80211_vif *vif = rtwvif_to_vif(rtwvif);
511
512 lockdep_assert_held(&rtwdev->mutex);
513
514 if (active) {
515 switch (vif->bss_conf.power_type) {
516 case IEEE80211_REG_VLP_AP:
517 rtwvif->reg_6ghz_power = RTW89_REG_6GHZ_POWER_VLP;
518 break;
519 case IEEE80211_REG_LPI_AP:
520 rtwvif->reg_6ghz_power = RTW89_REG_6GHZ_POWER_LPI;
521 break;
522 case IEEE80211_REG_SP_AP:
523 rtwvif->reg_6ghz_power = RTW89_REG_6GHZ_POWER_STD;
524 break;
525 default:
526 rtwvif->reg_6ghz_power = RTW89_REG_6GHZ_POWER_DFLT;
527 break;
528 }
529 } else {
530 rtwvif->reg_6ghz_power = RTW89_REG_6GHZ_POWER_DFLT;
531 }
532
533 __rtw89_reg_6ghz_power_recalc(rtwdev);
534 }
535