Skip to content

Commit f74c755

Browse files
duda-patrykTzung-Bi Shih
authored andcommitted
platform/chrome: cros_ec_proto: Update version on GET_NEXT_EVENT failure
Some EC based devices (e.g. Fingerpint MCU) can jump to RO part of the firmware (intentionally or due to device reboot). The RO part doesn't change during the device lifecycle, so it won't support newer version of EC_CMD_GET_NEXT_EVENT command. Function cros_ec_query_all() is responsible for finding maximum supported MKBP event version. It's usually called when the device is running RW part of the firmware, so the command version can be potentially higher than version supported by the RO. The problem was fixed by updating maximum supported version when the device returns EC_RES_INVALID_VERSION (mapped to -ENOPROTOOPT). That way the kernel will use highest common version supported by RO and RW. Fixes: 3300fdd ("platform/chrome: cros_ec: handle MKBP more events flag") Cc: <stable@vger.kernel.org> # 5.10+ Reviewed-by: Guenter Roeck <groeck@chromium.org> Signed-off-by: Patryk Duda <pdk@semihalf.com> Signed-off-by: Tzung-Bi Shih <tzungbi@kernel.org> Link: https://lore.kernel.org/r/20220802154128.21175-1-pdk@semihalf.com
1 parent 568035b commit f74c755

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

drivers/platform/chrome/cros_ec_proto.c

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -773,6 +773,7 @@ int cros_ec_get_next_event(struct cros_ec_device *ec_dev,
773773
u8 event_type;
774774
u32 host_event;
775775
int ret;
776+
u32 ver_mask;
776777

777778
/*
778779
* Default value for wake_event.
@@ -794,6 +795,37 @@ int cros_ec_get_next_event(struct cros_ec_device *ec_dev,
794795
return get_keyboard_state_event(ec_dev);
795796

796797
ret = get_next_event(ec_dev);
798+
/*
799+
* -ENOPROTOOPT is returned when EC returns EC_RES_INVALID_VERSION.
800+
* This can occur when EC based device (e.g. Fingerprint MCU) jumps to
801+
* the RO image which doesn't support newer version of the command. In
802+
* this case we will attempt to update maximum supported version of the
803+
* EC_CMD_GET_NEXT_EVENT.
804+
*/
805+
if (ret == -ENOPROTOOPT) {
806+
dev_dbg(ec_dev->dev,
807+
"GET_NEXT_EVENT returned invalid version error.\n");
808+
ret = cros_ec_get_host_command_version_mask(ec_dev,
809+
EC_CMD_GET_NEXT_EVENT,
810+
&ver_mask);
811+
if (ret < 0 || ver_mask == 0)
812+
/*
813+
* Do not change the MKBP supported version if we can't
814+
* obtain supported version correctly. Please note that
815+
* calling EC_CMD_GET_NEXT_EVENT returned
816+
* EC_RES_INVALID_VERSION which means that the command
817+
* is present.
818+
*/
819+
return -ENOPROTOOPT;
820+
821+
ec_dev->mkbp_event_supported = fls(ver_mask);
822+
dev_dbg(ec_dev->dev, "MKBP support version changed to %u\n",
823+
ec_dev->mkbp_event_supported - 1);
824+
825+
/* Try to get next event with new MKBP support version set. */
826+
ret = get_next_event(ec_dev);
827+
}
828+
797829
if (ret <= 0)
798830
return ret;
799831

0 commit comments

Comments
 (0)