Patrick Georgi | 11f0079 | 2020-03-04 15:10:45 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Furquan Shaikh | 4a2cfad | 2016-10-21 16:40:17 -0700 | [diff] [blame] | 2 | |
Furquan Shaikh | 76cedd2 | 2020-05-02 10:24:23 -0700 | [diff] [blame] | 3 | #include <acpi/acpigen.h> |
| 4 | #include <acpi/acpigen_dsm.h> |
Furquan Shaikh | 4a2cfad | 2016-10-21 16:40:17 -0700 | [diff] [blame] | 5 | |
| 6 | /* ------------------- I2C HID DSM ---------------------------- */ |
| 7 | |
| 8 | #define ACPI_DSM_I2C_HID_UUID "3CDFF6F7-4267-4555-AD05-B30A3D8938DE" |
| 9 | |
Josie Nordrum | 3f1de9a | 2020-10-14 13:38:29 -0600 | [diff] [blame] | 10 | /* I2C HID currently supports revision 1 only, for which, only 1 additional |
| 11 | * function is supported. Thus, the query function should return 0x3: |
| 12 | * bit 0 = additional function supported |
| 13 | * bit 1 = function with index 1 supported |
| 14 | * All other revisions do not support additional functions and hence return 0 |
| 15 | */ |
| 16 | |
Furquan Shaikh | 4a2cfad | 2016-10-21 16:40:17 -0700 | [diff] [blame] | 17 | static void i2c_hid_func0_cb(void *arg) |
| 18 | { |
| 19 | /* ToInteger (Arg1, Local2) */ |
| 20 | acpigen_write_to_integer(ARG1_OP, LOCAL2_OP); |
Josie Nordrum | 3f1de9a | 2020-10-14 13:38:29 -0600 | [diff] [blame] | 21 | /* If (LEqual (Local2, 0x1)) */ |
| 22 | acpigen_write_if_lequal_op_int(LOCAL2_OP, 0x1); |
| 23 | /* Return (Buffer (One) { 0x3 }) */ |
| 24 | acpigen_write_return_singleton_buffer(0x3); |
Furquan Shaikh | 4a2cfad | 2016-10-21 16:40:17 -0700 | [diff] [blame] | 25 | acpigen_pop_len(); /* Pop : If */ |
| 26 | /* Else */ |
| 27 | acpigen_write_else(); |
Furquan Shaikh | 4a2cfad | 2016-10-21 16:40:17 -0700 | [diff] [blame] | 28 | /* Return (Buffer (One) { 0x0 }) */ |
| 29 | acpigen_write_return_singleton_buffer(0x0); |
| 30 | acpigen_pop_len(); /* Pop : Else */ |
Furquan Shaikh | 4a2cfad | 2016-10-21 16:40:17 -0700 | [diff] [blame] | 31 | } |
| 32 | |
| 33 | static void i2c_hid_func1_cb(void *arg) |
| 34 | { |
| 35 | struct dsm_i2c_hid_config *config = arg; |
| 36 | acpigen_write_return_byte(config->hid_desc_reg_offset); |
| 37 | } |
| 38 | |
| 39 | static void (*i2c_hid_callbacks[2])(void *) = { |
| 40 | i2c_hid_func0_cb, |
| 41 | i2c_hid_func1_cb, |
| 42 | }; |
| 43 | |
| 44 | void acpigen_write_dsm_i2c_hid(struct dsm_i2c_hid_config *config) |
| 45 | { |
| 46 | acpigen_write_dsm(ACPI_DSM_I2C_HID_UUID, i2c_hid_callbacks, |
| 47 | ARRAY_SIZE(i2c_hid_callbacks), config); |
| 48 | } |
| 49 | |
| 50 | /* ------------------- End: I2C HID DSM ------------------------- */ |