platform/chrome: cros_ec_proto: Introduce cros_ec_read_features helper

Extract the EC feature-reading logic from cros_ec_check_features() into
cros_ec_read_features() helper function.

Currently, cros_ec_check_features() swallows command transfer errors. By
isolating the transaction logic into an explicit helper that returns the
actual transfer error code, subsequent callers (such as the cros_ec_dev
driver during device probing) can catch a read error.

Signed-off-by: Andrei Kuchynski <akuchynski@chromium.org>
Acked-by: Tzung-Bi Shih <tzungbi@kernel.org>
Link: https://patch.msgid.link/20260608211518.2214740-2-akuchynski@chromium.org
Signed-off-by: Lee Jones <lee@kernel.org>
This commit is contained in:
Andrei Kuchynski 2026-06-08 21:15:17 +00:00 committed by Lee Jones
parent dc59e4fea9
commit d6ae9f9b9b
2 changed files with 24 additions and 8 deletions

View File

@ -946,6 +946,27 @@ u32 cros_ec_get_host_event(struct cros_ec_device *ec_dev)
}
EXPORT_SYMBOL(cros_ec_get_host_event);
/**
* cros_ec_read_features() - Read EC features
*
* @ec: EC device.
*
* Return: >= 0 on success, negative error number on failure.
*/
int cros_ec_read_features(struct cros_ec_dev *ec)
{
int ret = cros_ec_cmd(ec->ec_dev, 0, EC_CMD_GET_FEATURES + ec->cmd_offset,
NULL, 0, &ec->features, sizeof(ec->features));
if (ret < 0) {
dev_warn(ec->dev, "cannot get EC features: %d\n", ret);
memset(&ec->features, 0, sizeof(ec->features));
}
return ret;
}
EXPORT_SYMBOL_GPL(cros_ec_read_features);
/**
* cros_ec_check_features() - Test for the presence of EC features
*
@ -960,17 +981,10 @@ EXPORT_SYMBOL(cros_ec_get_host_event);
bool cros_ec_check_features(struct cros_ec_dev *ec, int feature)
{
struct ec_response_get_features *features = &ec->features;
int ret;
if (features->flags[0] == -1U && features->flags[1] == -1U) {
/* features bitmap not read yet */
ret = cros_ec_cmd(ec->ec_dev, 0, EC_CMD_GET_FEATURES + ec->cmd_offset,
NULL, 0, features, sizeof(*features));
if (ret < 0) {
dev_warn(ec->dev, "cannot get EC features: %d\n", ret);
memset(features, 0, sizeof(*features));
}
cros_ec_read_features(ec);
dev_dbg(ec->dev, "EC features %08x %08x\n",
features->flags[0], features->flags[1]);
}

View File

@ -271,6 +271,8 @@ int cros_ec_get_next_event(struct cros_ec_device *ec_dev,
u32 cros_ec_get_host_event(struct cros_ec_device *ec_dev);
int cros_ec_read_features(struct cros_ec_dev *ec);
bool cros_ec_check_features(struct cros_ec_dev *ec, int feature);
int cros_ec_get_sensor_count(struct cros_ec_dev *ec);