Debian Codegraph @

src/drivers/usb/acpi/intel_bluetooth.c

raw symbols SCIP
1 /* SPDX-License-Identifier: GPL-2.0-only */
2
3 #include <acpi/acpigen.h>
4 #include <option.h>
5 #include "chip.h"
6
7 /*
8 * Intel Bluetooth DSM
9 *
10 * Check/Set Reset Delay (aa10f4e0-81ac-4233-abf6-3b2ac50e28d9)
11 * Arg2 == 0: Return a package with the following bit set
12 * BIT(0) Indicates whether the device supports other functions
13 * BIT(1) Check Bluetooth reset timing
14 *
15 * Arg2 == 1: Set the reset delay based on Arg3
16 *
17 * Arg2 == 3: Set the reset method based on Arg3 (Not supported by this driver)
18 * WDISABLE2 (BT_RF_KILL_N)
19 * VSEC (PCI Config Space)
20 */
21
22 static void check_reset_delay(void *arg)
23 {
24 acpigen_write_if_lequal_op_int(ARG1_OP, 0);
25 {
26 acpigen_write_return_singleton_buffer(0x03);
27 }
28 acpigen_write_else();
29 {
30 acpigen_write_return_singleton_buffer(0x00);
31 }
32 acpigen_pop_len();
33 }
34
35 static void set_reset_delay(void *arg)
36 {
37 acpigen_write_store_op_to_namestr(ARG3_OP, "RDLY");
38 }
39
40 static void not_supported(void *arg)
41 {
42 acpigen_write_return_singleton_buffer(0x00);
43 }
44
45 void (*reset_supported[])(void *) = { check_reset_delay, set_reset_delay };
46 void (*reset_unsupported[])(void *) = { not_supported };
47
48 void acpi_device_intel_bt(const struct acpi_gpio *enable_gpio,
49 const struct acpi_gpio *reset_gpio,
50 bool audio_offload)
51 {
52 /*
53 * Name (_S0W, 3)
54 */
55 if (get_uint_option("bluetooth_rtd3", 1))
56 acpigen_write_name_integer("_S0W", ACPI_DEVICE_SLEEP_D3_HOT);
57 else
58 acpigen_write_name_integer("_S0W", ACPI_DEVICE_SLEEP_D0);
59
60 /*
61 * Name (_DSD, Package (0x02)
62 * {
63 * ToUUID ("6211e2c0-58a3-4af3-90e1-927a4e0c55a4")
64 * Package (0x01)
65 * {
66 * Package (0x02)
67 * {
68 * "HotPlugSupportInD3",
69 * One
70 * }
71 * }
72 * })
73 *
74 */
75 acpi_device_add_hotplug_support_in_d3(NULL);
76
77 /*
78 * Name (RDLY, 0x69)
79 */
80 acpigen_write_name_integer("RDLY", 0x69);
81
82 /*
83 * Method (_DSM, 4, Serialized)
84 * {
85 * If ((Arg0 == ToUUID ("aa10f4e0-81ac-4233-abf6-3b2ac50e28d9")))
86 * {
87 * If ((Arg2 == Zero))
88 * {
89 * If ((Arg1 == Zero))
90 * {
91 * Return (Buffer (One)
92 * {
93 * 0x03
94 * })
95 * }
96 * Else
97 * {
98 * Return (Buffer (One)
99 * {
100 * 0x00
101 * })
102 * }
103 * }
104 * If ((Arg2 == One))
105 * {
106 * RDLY = Arg3
107 * }
108 * Return (Zero)
109 * }
110 * Else
111 * {
112 * Return (Buffer (One)
113 * {
114 * 0x00
115 * })
116 * }
117 * }
118 */
119
120 struct dsm_uuid uuid_callbacks[] = {
121 DSM_UUID("aa10f4e0-81ac-4233-abf6-3b2ac50e28d9",
122 reset_gpio->pin_count ?
123 reset_supported : reset_unsupported,
124 reset_gpio->pin_count ?
125 ARRAY_SIZE(reset_supported) : ARRAY_SIZE(reset_unsupported),
126 NULL),
127 };
128
129 acpigen_write_dsm_uuid_arr(uuid_callbacks, ARRAY_SIZE(uuid_callbacks));
130 /*
131 * PowerResource (BTRT, 0, 0)
132 * {
133 * Method (_STA, 0, NotSerialized)
134 * {
135 * Return (\_SB.PCI0.GBTE())
136 * }
137 * Method (_ON, 0, NotSerialized)
138 * {
139 * If ((\_SB.PCI0.GBTE() == 1))
140 * Return (1)
141 * }
142 * \_SB.PCI0.SBTE(1)
143 * }
144 * Method (_OFF, 0, NotSerialized)
145 * {
146 * \_SB.PCI0.SBTE(0)
147 * }
148 * Method (_RST, 0, NotSerialized)
149 * {
150 * Local0 = Acquire (\_SB.PCI0.CNMT, 1000)
151 * If ((Local0 == Zero))
152 * {
153 * \_SB.PCI0.BTRK (Zero)
154 * Sleep (RDLY)
155 * \_SB.PCI0.BTRK (One)
156 * Sleep (RDLY)
157 * Release (\_SB.PCI0.CNMT)
158 * }
159 * }
160 * }
161 */
162 acpigen_write_power_res("BTRT", 0, 0, NULL, 0);
163 {
164 acpigen_write_method("_STA", 0);
165 {
166 if (enable_gpio->pin_count) {
167 acpigen_write_store();
168 acpigen_emit_namestring("\\_SB.PCI0.GBTE");
169 acpigen_emit_byte(LOCAL0_OP);
170
171 acpigen_write_return_op(LOCAL0_OP);
172 } else {
173 acpigen_write_return_integer(1);
174 }
175 }
176 acpigen_pop_len();
177
178 acpigen_write_method("_ON", 0);
179 {
180 if (get_uint_option("bluetooth_rtd3", 1) && enable_gpio->pin_count) {
181 acpigen_write_store();
182 acpigen_emit_namestring("\\_SB.PCI0.GBTE");
183 acpigen_emit_byte(LOCAL0_OP);
184
185 acpigen_write_if_lequal_op_int(LOCAL0_OP, 1);
186 {
187 acpigen_write_return_integer(1);
188 }
189 acpigen_pop_len();
190
191 acpigen_emit_namestring("\\_SB.PCI0.SBTE");
192 acpigen_emit_byte(1);
193 }
194 }
195 acpigen_pop_len();
196
197 acpigen_write_method("_OFF", 0);
198 {
199 if (get_uint_option("bluetooth_rtd3", 1) && enable_gpio->pin_count) {
200 acpigen_emit_namestring("\\_SB.PCI0.SBTE");
201 acpigen_emit_byte(0);
202 }
203 }
204 acpigen_pop_len();
205
206 acpigen_write_method("_RST", 0);
207 {
208 if (reset_gpio->pin_count) {
209 acpigen_write_store();
210 acpigen_write_acquire("\\_SB.PCI0.CNMT", 1000);
211 acpigen_emit_byte(LOCAL0_OP);
212
213 acpigen_write_if_lequal_op_int(LOCAL0_OP, 0);
214 {
215 acpigen_emit_namestring("\\_SB.PCI0.BTRK");
216 acpigen_emit_byte(0);
217
218 acpigen_emit_ext_op(SLEEP_OP);
219 acpigen_emit_namestring("RDLY");
220
221 acpigen_emit_namestring("\\_SB.PCI0.BTRK");
222 acpigen_emit_byte(1);
223
224 acpigen_emit_ext_op(SLEEP_OP);
225 acpigen_emit_namestring("RDLY");
226
227 acpigen_write_release("\\_SB.PCI0.CNMT");
228 }
229 acpigen_pop_len();
230 }
231 }
232 acpigen_pop_len();
233 }
234 acpigen_write_power_res_end();
235
236 /*
237 * Name (_PRR, Package (0x01)
238 * {
239 * BTRT
240 * })
241 */
242 acpigen_write_name("_PRR");
243 {
244 acpigen_write_package(1);
245 acpigen_emit_namestring("BTRT");
246 }
247 acpigen_pop_len();
248
249 /*
250 * Name (_PR0, Package (0x01)
251 * {
252 * BTRT
253 * })
254 */
255 acpigen_write_name("_PR0");
256 {
257 acpigen_write_package(1);
258 acpigen_emit_namestring("BTRT");
259 }
260 acpigen_pop_len();
261
262 /*
263 * Method (AOLD, 0, NotSerialized)
264 * {
265 * Name (AODS, Package (0x03)
266 * {
267 * Zero,
268 * 0x12,
269 * Zero // Audio Offload - 0: Disabled
270 * 1: Enabled
271 * })
272 * Return (AODS)
273 * }
274 */
275 acpigen_write_method("AOLD", 0);
276 {
277 acpigen_write_name("AODS");
278 acpigen_write_package(3);
279 {
280 acpigen_write_integer(0);
281 acpigen_write_integer(0x12);
282 acpigen_write_integer(audio_offload);
283 }
284 acpigen_pop_len();
285
286 acpigen_write_return_namestr("AODS");
287 }
288 acpigen_pop_len();
289 }
290
291 void acpi_device_intel_bt_common(const struct acpi_gpio *enable_gpio,
292 const struct acpi_gpio *reset_gpio)
293 {
294 acpigen_write_scope("\\_SB.PCI0");
295 /*
296 * Mutex (CNMT, 0)
297 */
298 acpigen_write_mutex("CNMT", 0);
299
300 /*
301 * Method (SBTE, 1, NotSerialized)
302 * {
303 * If (Arg0 == 1)
304 * {
305 * STXS(enable_gpio)
306 * } Else {
307 * CTXS(enable_gpio)
308 * }
309 * }
310 */
311 acpigen_write_method("SBTE", 1);
312 {
313 if (enable_gpio->pin_count) {
314 acpigen_write_if_lequal_op_int(ARG0_OP, 1);
315 {
316 acpigen_enable_tx_gpio(enable_gpio);
317 }
318 acpigen_write_else();
319 {
320 acpigen_disable_tx_gpio(enable_gpio);
321 }
322 acpigen_pop_len();
323 }
324 }
325 acpigen_pop_len();
326
327 /*
328 * Method (GBTE, 0, NotSerialized)
329 * {
330 * Return (GTXS (enable_gpio))
331 * }
332 */
333 acpigen_write_method("GBTE", 0);
334 {
335 if (enable_gpio->pin_count) {
336 acpigen_get_tx_gpio(enable_gpio);
337 acpigen_write_return_op(LOCAL0_OP);
338 } else {
339 acpigen_write_return_integer(0);
340 }
341 }
342 acpigen_pop_len();
343
344 /*
345 * Method (BTRK, 1, NotSerialized)
346 * {
347 * If (Arg0 == 1)
348 * {
349 * STXS (reset_gpio)
350 * } Else {
351 * CTXS (reset_gpio)
352 * }
353 * }
354 */
355 acpigen_write_method("BTRK", 1);
356 {
357 if (reset_gpio->pin_count) {
358 acpigen_write_if_lequal_op_int(ARG0_OP, 1);
359 {
360 /* De-assert reset */
361 acpigen_disable_tx_gpio(reset_gpio);
362 }
363 acpigen_write_else();
364 {
365 /* Assert Reset */
366 acpigen_enable_tx_gpio(reset_gpio);
367 }
368 acpigen_pop_len();
369 }
370 }
371 acpigen_pop_len();
372
373 /*
374 * Method (GBTR, 0, NotSerialized)
375 * {
376 * Local0 = GTXS (reset_gpio)
377 * Local0 ^= One
378 * Return (Local0)
379 * }
380 */
381 acpigen_write_method("GBTR", 0);
382 {
383 if (reset_gpio->pin_count) {
384 /* Return 1 if not in reset */
385 acpigen_get_tx_gpio(reset_gpio);
386 acpigen_write_xor(LOCAL0_OP, 1, LOCAL0_OP);
387 acpigen_write_return_op(LOCAL0_OP);
388 } else {
389 acpigen_write_return_op(0);
390 }
391 }
392 acpigen_pop_len();
393
394 acpigen_write_scope_end();
395 }