summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYuval Peress <peress@google.com>2021-10-12 10:08:55 -0600
committerCommit Bot <commit-bot@chromium.org>2021-10-13 03:44:27 +0000
commit3069cac31e30169615800324987c465965f20698 (patch)
treefa5eeac0dbc7baa7fa7049bd80b4a94564846926
parente46d6b63a075fab257a89e2c45fcbdf2f687e19f (diff)
downloadchrome-ec-3069cac31e30169615800324987c465965f20698.tar.gz
zephyr: cros_cbi demangle return value from status
The call to cros_cbi_ssfc_get_parent_field_value() was returning 0 for error which is also a valid value. This was also fixed so it is possible to distinguish between an error and a value. BRANCH=none BUG=b:202789410 TEST=zmake configure --test zephyr/test/drivers Signed-off-by: Yuval Peress <peress@google.com> Change-Id: Id58de2cd5f3d87a66cd48fc8b2bd3853d0dce649 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3218252 Reviewed-by: Jack Rosenthal <jrosenth@chromium.org>
-rw-r--r--zephyr/drivers/cros_cbi/cros_cbi.c45
-rw-r--r--zephyr/include/drivers/cros_cbi.h4
2 files changed, 29 insertions, 20 deletions
diff --git a/zephyr/drivers/cros_cbi/cros_cbi.c b/zephyr/drivers/cros_cbi/cros_cbi.c
index f3acda15ce..d962231c22 100644
--- a/zephyr/drivers/cros_cbi/cros_cbi.c
+++ b/zephyr/drivers/cros_cbi/cros_cbi.c
@@ -45,17 +45,18 @@ BUILD_ASSERT(DT_NUM_INST_STATUS_OKAY(named_cbi_ssfc) < 2,
BUILD_ASSERT(DT_INST_PROP(inst, value) <= UINT8_MAX, \
"CBI SSFS value too big");
-#define CBI_SSFC_PARENT_VALUE_CASE_GENERATE(value_id, value_parent) \
- case value_id: \
- return value_parent;
+#define CBI_SSFC_PARENT_VALUE_CASE_GENERATE(value_id, value_parent, value) \
+ case value_id: \
+ *value = value_parent; \
+ break;
-#define CBI_SSFC_PARENT_VALUE_CASE_ID(id) \
- CBI_SSFC_PARENT_VALUE_CASE_GENERATE( \
- CBI_SSFC_VALUE_ID(id), \
- cached_ssfc.CBI_SSFC_UNION_ENTRY_NAME(DT_PARENT(id)))
+#define CBI_SSFC_PARENT_VALUE_CASE_ID(id, cached_ssfc, value) \
+ CBI_SSFC_PARENT_VALUE_CASE_GENERATE( \
+ CBI_SSFC_VALUE_ID(id), \
+ cached_ssfc.CBI_SSFC_UNION_ENTRY_NAME(DT_PARENT(id)), value)
-#define CBI_SSFC_PARENT_VALUE_CASE(inst) \
- CBI_SSFC_PARENT_VALUE_CASE_ID(DT_DRV_INST(inst))
+#define CBI_SSFC_PARENT_VALUE_CASE(inst, cached_ssfc, value) \
+ CBI_SSFC_PARENT_VALUE_CASE_ID(DT_DRV_INST(inst), cached_ssfc, value)
#define CBI_SSFC_UNION_ENTRY_NAME(id) DT_CAT(cbi_ssfc_, id)
#define CBI_SSFC_UNION_ENTRY(id) \
@@ -161,27 +162,35 @@ static void cros_cbi_ssfc_init(const struct device *dev)
LOG_INF("Read CBI SSFC : 0x%08X\n", data->cached_ssfc.raw_value);
}
-static uint32_t cros_cbi_ssfc_get_parent_field_value(union cbi_ssfc cached_ssfc,
- enum cbi_ssfc_value_id value_id)
+static int cros_cbi_ssfc_get_parent_field_value(union cbi_ssfc cached_ssfc,
+ enum cbi_ssfc_value_id value_id,
+ uint32_t *value)
{
switch (value_id) {
- DT_INST_FOREACH_STATUS_OKAY(CBI_SSFC_PARENT_VALUE_CASE)
+ DT_INST_FOREACH_STATUS_OKAY_VARGS(CBI_SSFC_PARENT_VALUE_CASE,
+ cached_ssfc, value)
default:
LOG_ERR("CBI SSFC parent field value not found: %d\n",
value_id);
- return 0;
+ return -EINVAL;
}
+ return 0;
}
-static int cros_cbi_ec_ssfc_check_match(const struct device *dev,
- enum cbi_ssfc_value_id value_id)
+static bool cros_cbi_ec_ssfc_check_match(const struct device *dev,
+ enum cbi_ssfc_value_id value_id)
{
struct cros_cbi_data *data = (struct cros_cbi_data *)(dev->data);
struct cros_cbi_config *cfg = (struct cros_cbi_config *)(dev->config);
+ int rc;
+ uint32_t value;
- return cros_cbi_ssfc_get_parent_field_value(data->cached_ssfc,
- value_id) ==
- cfg->ssfc_values[value_id];
+ rc = cros_cbi_ssfc_get_parent_field_value(data->cached_ssfc,
+ value_id, &value);
+ if (rc) {
+ return false;
+ }
+ return value == cfg->ssfc_values[value_id];
}
/* CBI SSFC part end */
diff --git a/zephyr/include/drivers/cros_cbi.h b/zephyr/include/drivers/cros_cbi.h
index aa55e03b77..0aecbb4d19 100644
--- a/zephyr/include/drivers/cros_cbi.h
+++ b/zephyr/include/drivers/cros_cbi.h
@@ -36,8 +36,8 @@ enum cbi_ssfc_value_id {
* (Internal use only.)
*/
typedef int (*cros_cbi_api_init)(const struct device *dev);
-typedef int (*cros_cbi_api_ssfc_check_match)(const struct device *dev,
- enum cbi_ssfc_value_id value_id);
+typedef bool (*cros_cbi_api_ssfc_check_match)(const struct device *dev,
+ enum cbi_ssfc_value_id value_id);
__subsystem struct cros_cbi_driver_api {
cros_cbi_api_init init;