summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--zephyr/dts/bindings/battery/named-batteries.yaml14
-rw-r--r--zephyr/shim/include/battery_enum.h25
2 files changed, 39 insertions, 0 deletions
diff --git a/zephyr/dts/bindings/battery/named-batteries.yaml b/zephyr/dts/bindings/battery/named-batteries.yaml
new file mode 100644
index 0000000000..88dc0af960
--- /dev/null
+++ b/zephyr/dts/bindings/battery/named-batteries.yaml
@@ -0,0 +1,14 @@
+description: Named Batteries parent node
+
+compatible: "named-batteries"
+
+# TODO(b/183544739): Move this to use compatible strings
+
+child-binding:
+ description: Named batteries child node
+ properties:
+ enum-name:
+ type: string
+ required: true
+ enum:
+ - "lgc011"
diff --git a/zephyr/shim/include/battery_enum.h b/zephyr/shim/include/battery_enum.h
new file mode 100644
index 0000000000..36692e68e5
--- /dev/null
+++ b/zephyr/shim/include/battery_enum.h
@@ -0,0 +1,25 @@
+/* Copyright 2021 The Chromium OS Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef __CROS_EC_CONFIG_CHIP_H
+#error "This file must only be included from config_chip.h and it should be" \
+ "included in all zephyr builds automatically"
+#endif
+
+/* TODO(b/183544739): Move this to use compatible strings */
+
+#define BATTERY_ENUM(val) DT_CAT(BATTERY_, val)
+#define BATTERY_TYPE(id) BATTERY_ENUM(DT_ENUM_UPPER_TOKEN(id, enum_name))
+#define BATTERY_TYPE_WITH_COMMA(id) BATTERY_TYPE(id),
+
+/* This produces a list of BATTERY_<ENUM_NAME> identifiers */
+enum battery_type {
+#if DT_NODE_EXISTS(DT_PATH(named_batteries))
+ DT_FOREACH_CHILD(DT_PATH(named_batteries), BATTERY_TYPE_WITH_COMMA)
+#endif
+
+ BATTERY_TYPE_COUNT,
+};
+#undef BATTERY_TYPE_WITH_COMMA