Jonathon Hall | a41c825 | 2023-04-12 16:01:16 -0400 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 | |
Elyes Haouas | 877fafa | 2024-05-27 12:43:10 +0200 | [diff] [blame^] | 3 | #include <commonlib/bsd/helpers.h> |
Jonathon Hall | a41c825 | 2023-04-12 16:01:16 -0400 | [diff] [blame] | 4 | #include "librem_ec.h" |
| 5 | #include "../../system76/ec/system76_ec.h" |
Jonathon Hall | a41c825 | 2023-04-12 16:01:16 -0400 | [diff] [blame] | 6 | |
| 7 | #define CMD_PROBE 1 |
| 8 | |
| 9 | bool librem_ec_has_jack_detect(void) |
| 10 | { |
| 11 | /* The 'flags' field in the probe command reply was added in an update. |
| 12 | Send 4 bytes of zeroes in the "request" to zero out the field if the |
| 13 | EC does not set it for its reply. */ |
| 14 | const uint8_t request_data[4] = {0}; |
| 15 | uint8_t reply_data[4] = {0}; |
| 16 | bool ec_cmd_success = system76_ec_cmd(CMD_PROBE, request_data, |
| 17 | ARRAY_SIZE(request_data), reply_data, ARRAY_SIZE(reply_data)); |
| 18 | if (!ec_cmd_success) |
| 19 | return false; |
| 20 | /* Byte 3 is flags, bit 0 is the jack detect flag */ |
| 21 | return reply_data[3] & 0x01; |
| 22 | } |