summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew McRae <amcrae@google.com>2022-01-06 14:52:56 +1100
committerCommit Bot <commit-bot@chromium.org>2022-01-07 01:40:59 +0000
commit528204882dc93ae8164135f52c4edde480759084 (patch)
treef28c3c9bf406a0de575ed3d587eb450692a081b7
parent9ce2297ff42e96a08df75012d66072371062ede6 (diff)
downloadchrome-ec-528204882dc93ae8164135f52c4edde480759084.tar.gz
zephyr: Add tests for fw_config support and normalize some names.
Add tests for fw_config support, and normalise some common names for matching "compatible" bindings to support tests. BUG=b:212490923 TEST=zmake configure --test zephyr/test/drivers; zmake testall BRANCH=none Signed-off-by: Andrew McRae <amcrae@google.com> Cq-Depend: chromium:3367729 Change-Id: I245207ce0674f40a81e9c9fdbe7c9c2d4105a4fb Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3367734 Reviewed-by: Jeremy Bettis <jbettis@chromium.org>
-rw-r--r--zephyr/drivers/cros_cbi/cros_cbi_fw_config.c33
-rw-r--r--zephyr/include/drivers/cros_cbi.h9
-rw-r--r--zephyr/test/drivers/overlay.dts29
-rw-r--r--zephyr/test/drivers/src/cros_cbi.c24
4 files changed, 71 insertions, 24 deletions
diff --git a/zephyr/drivers/cros_cbi/cros_cbi_fw_config.c b/zephyr/drivers/cros_cbi/cros_cbi_fw_config.c
index 4790fad2bb..2eacbcf6d4 100644
--- a/zephyr/drivers/cros_cbi/cros_cbi_fw_config.c
+++ b/zephyr/drivers/cros_cbi/cros_cbi_fw_config.c
@@ -14,14 +14,9 @@ LOG_MODULE_REGISTER(cros_cbi_fw_config, LOG_LEVEL_ERR);
/*
* Validation macros.
- * These are moved out of header files to reduce the overhead
- * during compilation.
+ * These are moved out of header files to avoid exposing them outside
+ * this file scope.
*/
-/*
- * Do not perform validation if no FW_CONFIG nodes exist so that
- * the validation macros are simplified.
- */
-#if DT_HAS_COMPAT_STATUS_OKAY(CBI_FW_CONFIG_FIELD_COMPAT)
/*
* Statically count the number of bits set in a 32 bit constant expression.
@@ -38,7 +33,7 @@ LOG_MODULE_REGISTER(cros_cbi_fw_config, LOG_LEVEL_ERR);
BIT_SET(v, 3) + BIT_SET(v, 2) + BIT_SET(v, 1) + BIT_SET(v, 0))
/*
- * Shorthand macros to access properties on the node.
+ * Shorthand macros to access properties on the field node.
*/
#define FW_START(id) DT_PROP(id, start)
#define FW_SIZE(id) DT_PROP(id, size)
@@ -55,7 +50,7 @@ LOG_MODULE_REGISTER(cros_cbi_fw_config, LOG_LEVEL_ERR);
/*
* For a child "named-cbi-fw-config-value" node, retrieve the
- * size of the field this value is associated with.
+ * size of the parent field this value is associated with.
*/
#define FW_PARENT_SIZE(id) DT_PROP(DT_PARENT(id), size)
@@ -73,7 +68,7 @@ LOG_MODULE_REGISTER(cros_cbi_fw_config, LOG_LEVEL_ERR);
* Result is the sum of all the field sizes.
*/
#define TOTAL_FW_CONFIG_NODES_SIZE \
- (0 DT_FOREACH_STATUS_OKAY(CBI_FW_CONFIG_FIELD_COMPAT, FIELDS_ALL_SIZE))
+ (0 DT_FOREACH_STATUS_OKAY(CBI_FW_CONFIG_COMPAT, FIELDS_ALL_SIZE))
BUILD_ASSERT(TOTAL_FW_CONFIG_NODES_SIZE <= 32,
"CBI FW Config is bigger than 32 bits");
@@ -88,7 +83,7 @@ BUILD_ASSERT(TOTAL_FW_CONFIG_NODES_SIZE <= 32,
DT_FOREACH_CHILD_STATUS_OKAY(inst, OR_FIELD_SHIFT_MASK)
#define TOTAL_BITS_SET \
- (0 DT_FOREACH_STATUS_OKAY(CBI_FW_CONFIG_FIELD_COMPAT, \
+ (0 DT_FOREACH_STATUS_OKAY(CBI_FW_CONFIG_COMPAT, \
FIELDS_ALL_BITS_SET))
BUILD_ASSERT(BIT_COUNT(TOTAL_BITS_SET) == TOTAL_FW_CONFIG_NODES_SIZE,
@@ -101,11 +96,9 @@ BUILD_ASSERT(BIT_COUNT(TOTAL_BITS_SET) == TOTAL_FW_CONFIG_NODES_SIZE,
#define FW_VALUE_BUILD_ASSERT(inst) \
BUILD_ASSERT(DT_PROP(inst, value) < \
(1 << FW_PARENT_SIZE(inst)), \
- "CBI FW Config value too big")
-
-DT_FOREACH_STATUS_OKAY(DT_DRV_COMPAT, FW_VALUE_BUILD_ASSERT)
+ "CBI FW Config value too big");
-#endif /* DT_HAS_COMPAT_STATUS_OKAY(CBI_FW_CONFIG_FIELD_COMPAT) */
+DT_FOREACH_STATUS_OKAY(CBI_FW_CONFIG_VALUE_COMPAT, FW_VALUE_BUILD_ASSERT)
/*
* Define union bit fields based on the device tree entries. Example:
@@ -113,11 +106,11 @@ DT_FOREACH_STATUS_OKAY(DT_DRV_COMPAT, FW_VALUE_BUILD_ASSERT)
* compatible = "named-cbi-fw-config";
*
* fan {
- * enum-name = "FAN";
+ * enum-name = "FW_CONFIG_FAN";
* start = <0>;
* size = <1>;
* fan_present {
- * enum-name = "PRESENT"
+ * enum-name = "FW_FAN_PRESENT"
* compatible = "named-cbi-fw-config-value";
* value = <1>;
* };
@@ -126,7 +119,7 @@ DT_FOREACH_STATUS_OKAY(DT_DRV_COMPAT, FW_VALUE_BUILD_ASSERT)
*
* Creates
* switch (field_id) {
- * case CBI_FW_CONFIG_FAN:
+ * case FW_CONFIG_FAN:
* return (value >> 0) & 1;
* ...
* }
@@ -138,7 +131,7 @@ DT_FOREACH_STATUS_OKAY(DT_DRV_COMPAT, FW_VALUE_BUILD_ASSERT)
* Extract the field value using the start and size.
*/
#define FW_FIELD_CASE(id, cached, value) \
- case CBI_FW_CONFIG_FIELD_ID(id): \
+ case CBI_FW_CONFIG_ENUM(id): \
*value = (cached >> FW_START(id)) & FW_MASK(id); \
break;
@@ -171,7 +164,7 @@ static int cros_cbi_fw_config_get_field(
* Iterate through all the the "named-cbi-fw-config" nodes,
* and create cases for all of their child nodes.
*/
- DT_FOREACH_STATUS_OKAY_VARGS(CBI_FW_CONFIG_FIELD_COMPAT,
+ DT_FOREACH_STATUS_OKAY_VARGS(CBI_FW_CONFIG_COMPAT,
FW_FIELD_NODES,
cached_fw_config,
value)
diff --git a/zephyr/include/drivers/cros_cbi.h b/zephyr/include/drivers/cros_cbi.h
index 26261764f6..15c94bcb19 100644
--- a/zephyr/include/drivers/cros_cbi.h
+++ b/zephyr/include/drivers/cros_cbi.h
@@ -36,8 +36,11 @@ enum cbi_ssfc_value_id {
#undef DT_DRV_COMPAT
/*
- * Macros to help generate the enum list of field and value names.
+ * Macros to help generate the enum list of field and value names
+ * for the FW_CONFIG CBI data.
*/
+#define CBI_FW_CONFIG_COMPAT named_cbi_fw_config
+#define CBI_FW_CONFIG_VALUE_COMPAT named_cbi_fw_config_value
/*
* Retrieve the enum-name property for this node.
@@ -67,7 +70,7 @@ enum cbi_ssfc_value_id {
* Enum list of all fields.
*/
enum cbi_fw_config_field_id {
- DT_FOREACH_STATUS_OKAY(named_cbi_fw_config,
+ DT_FOREACH_STATUS_OKAY(CBI_FW_CONFIG_COMPAT,
CBI_FW_CONFIG_CHILD_ENUM_LIST)
CBI_FW_CONFIG_FIELDS_COUNT
};
@@ -76,7 +79,7 @@ enum cbi_fw_config_field_id {
* enum list of all child values.
*/
enum cbi_fw_config_value_id {
- DT_FOREACH_STATUS_OKAY(named_cbi_fw_config_value,
+ DT_FOREACH_STATUS_OKAY(CBI_FW_CONFIG_VALUE_COMPAT,
CBI_FW_CONFIG_ENUM_WITH_VALUE)
CBI_FW_CONFIG_VALUES_LAST /* added to ensure at least one entry */
};
diff --git a/zephyr/test/drivers/overlay.dts b/zephyr/test/drivers/overlay.dts
index e32a849c5d..f45210d621 100644
--- a/zephyr/test/drivers/overlay.dts
+++ b/zephyr/test/drivers/overlay.dts
@@ -154,6 +154,35 @@
};
};
+ cbi-fw-config {
+ compatible = "named-cbi-fw-config";
+ field-1 {
+ enum-name = "FW_CONFIG_FIELD_1";
+ start = <0>;
+ size = <2>;
+ val-0 {
+ compatible = "named-cbi-fw-config-value";
+ enum-name = "FW_FIELD_1_A";
+ value = <0>;
+ };
+ val-1 {
+ compatible = "named-cbi-fw-config-value";
+ enum-name = "FW_FIELD_1_B";
+ value = <1>;
+ };
+ };
+ field-2 {
+ enum-name = "FW_CONFIG_FIELD_2";
+ start = <5>;
+ size = <1>;
+ val-1 {
+ compatible = "named-cbi-fw-config-value";
+ enum-name = "FW_FIELD_2_X";
+ value = <1>;
+ };
+ };
+ };
+
adc0: adc {
compatible = "zephyr,adc-emul";
nchannels = <4>;
diff --git a/zephyr/test/drivers/src/cros_cbi.c b/zephyr/test/drivers/src/cros_cbi.c
index ee3666f3f0..5209bb2b7f 100644
--- a/zephyr/test/drivers/src/cros_cbi.c
+++ b/zephyr/test/drivers/src/cros_cbi.c
@@ -39,10 +39,32 @@ static void test_fail_check_match(void)
"Expected cbi ssfc to never match CBI_SSFC_VALUE_COUNT");
}
+static void test_fw_config(void)
+{
+ const struct device *dev = device_get_binding(CROS_CBI_LABEL);
+ uint32_t value;
+ int ret;
+
+ zassert_not_null(dev, NULL);
+
+ ret = cros_cbi_get_fw_config(dev, FW_CONFIG_FIELD_1, &value);
+ zassert_true(ret == 0,
+ "Expected no error return from cros_cbi_get_fw_config");
+ zassert_true(value == FW_FIELD_1_A,
+ "Expected field value to match FW_FIELD_1_A");
+
+ ret = cros_cbi_get_fw_config(dev, FW_CONFIG_FIELD_2, &value);
+ zassert_true(ret == 0,
+ "Expected no error return from cros_cbi_get_fw_config");
+ zassert_false(value == FW_FIELD_2_X,
+ "Expected field value to not match FW_FIELD_2_X");
+}
+
void test_suite_cros_cbi(void)
{
ztest_test_suite(cros_cbi,
ztest_unit_test(test_check_match),
- ztest_unit_test(test_fail_check_match));
+ ztest_unit_test(test_fail_check_match),
+ ztest_unit_test(test_fw_config));
ztest_run_test_suite(cros_cbi);
}