summaryrefslogtreecommitdiff
path: root/zephyr/test/drivers/common/include/test/drivers/charger_utils.h
diff options
context:
space:
mode:
Diffstat (limited to 'zephyr/test/drivers/common/include/test/drivers/charger_utils.h')
-rw-r--r--zephyr/test/drivers/common/include/test/drivers/charger_utils.h30
1 files changed, 30 insertions, 0 deletions
diff --git a/zephyr/test/drivers/common/include/test/drivers/charger_utils.h b/zephyr/test/drivers/common/include/test/drivers/charger_utils.h
new file mode 100644
index 0000000000..22331c8575
--- /dev/null
+++ b/zephyr/test/drivers/common/include/test/drivers/charger_utils.h
@@ -0,0 +1,30 @@
+/* Copyright 2021 The ChromiumOS Authors
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef ZEPHYR_TEST_DRIVERS_INCLUDE_CHARGER_UTILS_H_
+#define ZEPHYR_TEST_DRIVERS_INCLUDE_CHARGER_UTILS_H_
+
+#include "charger.h"
+
+/**
+ * @brief Get the index of the charger in chg_chips
+ *
+ * @param charger Pointer to the charger driver.
+ * @return The index of the charger if found
+ * @return board_get_charger_chip_count() if not found
+ */
+static inline uint8_t get_charger_num(const struct charger_drv *charger)
+{
+ const uint8_t chip_count = board_get_charger_chip_count();
+ uint8_t chip;
+
+ for (chip = 0; chip < chip_count; ++chip) {
+ if (chg_chips[chip].drv == charger)
+ return chip;
+ }
+ return chip;
+}
+
+#endif /* ZEPHYR_TEST_DRIVERS_INCLUDE_CHARGER_UTILS_H_ */