From a41c825068f4f5afc3fd6839a796d868241d91cd Mon Sep 17 00:00:00 2001 From: Jonathon Hall Date: Wed, 12 Apr 2023 16:01:16 -0400 Subject: ec/purism,system76: Provide probe for fixed Librem-EC jack detect Provide system76_ec_cmd() to send arbitrary commands to the EC. Provide librem_ec_has_jack_detect() to probe for the jack detect fix. Change-Id: Ic7bda0ce230a3ad68dfeb7b01a0e04f70dab9e5d Signed-off-by: Jonathon Hall Reviewed-on: https://review.coreboot.org/c/coreboot/+/74390 Reviewed-by: Angel Pons Tested-by: build bot (Jenkins) Reviewed-by: Tim Crawford --- src/ec/purism/librem-ec/Makefile.inc | 1 + src/ec/purism/librem-ec/librem_ec.c | 22 ++++++++++++++++++++++ src/ec/purism/librem-ec/librem_ec.h | 14 ++++++++++++++ 3 files changed, 37 insertions(+) create mode 100644 src/ec/purism/librem-ec/librem_ec.c create mode 100644 src/ec/purism/librem-ec/librem_ec.h (limited to 'src/ec/purism') diff --git a/src/ec/purism/librem-ec/Makefile.inc b/src/ec/purism/librem-ec/Makefile.inc index 5e2b2dfac8..464371f272 100644 --- a/src/ec/purism/librem-ec/Makefile.inc +++ b/src/ec/purism/librem-ec/Makefile.inc @@ -2,6 +2,7 @@ ifeq ($(CONFIG_EC_LIBREM_EC),y) all-y += ../../system76/ec/system76_ec.c +all-y += librem_ec.c smm-$(CONFIG_DEBUG_SMI) += ../../system76/ec/system76_ec.c endif diff --git a/src/ec/purism/librem-ec/librem_ec.c b/src/ec/purism/librem-ec/librem_ec.c new file mode 100644 index 0000000000..8298b73644 --- /dev/null +++ b/src/ec/purism/librem-ec/librem_ec.c @@ -0,0 +1,22 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#include "librem_ec.h" +#include "../../system76/ec/system76_ec.h" +#include + +#define CMD_PROBE 1 + +bool librem_ec_has_jack_detect(void) +{ + /* The 'flags' field in the probe command reply was added in an update. + Send 4 bytes of zeroes in the "request" to zero out the field if the + EC does not set it for its reply. */ + const uint8_t request_data[4] = {0}; + uint8_t reply_data[4] = {0}; + bool ec_cmd_success = system76_ec_cmd(CMD_PROBE, request_data, + ARRAY_SIZE(request_data), reply_data, ARRAY_SIZE(reply_data)); + if (!ec_cmd_success) + return false; + /* Byte 3 is flags, bit 0 is the jack detect flag */ + return reply_data[3] & 0x01; +} diff --git a/src/ec/purism/librem-ec/librem_ec.h b/src/ec/purism/librem-ec/librem_ec.h new file mode 100644 index 0000000000..f3a6a78fd9 --- /dev/null +++ b/src/ec/purism/librem-ec/librem_ec.h @@ -0,0 +1,14 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#ifndef LIBREM_EC_H +#define LIBREM_EC_H + +#include + +/* + * Check whether librem-ec has working jack detect. This was fixed in librem-ec + * 1.13, so we only use the verbs with jack detect if the EC has been updated. + */ +bool librem_ec_has_jack_detect(void); + +#endif -- cgit v1.2.3