summaryrefslogtreecommitdiff
path: root/zephyr
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2021-03-22 12:46:58 +1300
committerCommit Bot <commit-bot@chromium.org>2021-03-24 03:30:41 +0000
commit50b2c4deb60575a60f6f58b28d48a1ada595ee65 (patch)
tree96750e22d99ec03739d6ca540ab0f974dfda2178 /zephyr
parentf15b0fcff7ab0df04279a3480e80bc67b54ebee5 (diff)
downloadchrome-ec-50b2c4deb60575a60f6f58b28d48a1ada595ee65.tar.gz
zephyr: Add a binding for named batteries
Each board has its own list of supported batteries, taken from a set of possible ones. Create a binding for this so we can generate the enum from the device tree. We can add new battery types as needed. For now, just include the battery for volteer. Add a new header file to generate enum battery_type. BUG=b:176121284 BRANCH=none TEST=build zephry for volteer Signed-off-by: Simon Glass <sjg@chromium.org> Change-Id: I6452705250075423ed6b5c87fdf32eda3f31c32b Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2777634
Diffstat (limited to 'zephyr')
-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