summaryrefslogtreecommitdiff
path: root/zephyr/include/emul
diff options
context:
space:
mode:
authorTomasz Michalec <tm@semihalf.com>2021-11-03 15:29:07 +0100
committerCommit Bot <commit-bot@chromium.org>2021-11-18 10:52:45 +0000
commit2c71cfba6e25e7c07ea10c12309aaaf6a7261e4e (patch)
treec445d31390fca77cd3c8ef5132c871d458577a80 /zephyr/include/emul
parentf40f426c2ebcd6c8656bc65b2133fa90783c022b (diff)
downloadchrome-ec-2c71cfba6e25e7c07ea10c12309aaaf6a7261e4e.tar.gz
zephyr: add USB-C charger emulator
Add basic charger emulator that can be attached to TCPCI emulator. Charger is always presenting one source capability mode and is able to respond to some TCPM messages. BUG=none BRANCH=none TEST=make configure --test zephyr/test/drivers Signed-off-by: Tomasz Michalec <tm@semihalf.com> Change-Id: Ic8d2c4f1352324d47ff8659ea971beb3de5c2e9c Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3259926 Reviewed-by: Aaron Massey <aaronmassey@google.com> Reviewed-by: Simon Glass <sjg@chromium.org> Tested-by: Tomasz Michalec <tmichalec@google.com> Commit-Queue: Tomasz Michalec <tmichalec@google.com>
Diffstat (limited to 'zephyr/include/emul')
-rw-r--r--zephyr/include/emul/emul_charger.h66
1 files changed, 66 insertions, 0 deletions
diff --git a/zephyr/include/emul/emul_charger.h b/zephyr/include/emul/emul_charger.h
new file mode 100644
index 0000000000..87303181e8
--- /dev/null
+++ b/zephyr/include/emul/emul_charger.h
@@ -0,0 +1,66 @@
+/* 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.
+ */
+
+/**
+ * @file
+ *
+ * @brief Backend API for USB-C charger emulator
+ */
+
+#ifndef __EMUL_CHARGER_H
+#define __EMUL_CHARGER_H
+
+#include <emul.h>
+#include "emul/emul_tcpci.h"
+
+/**
+ * @brief USB-C charger emulator backend API
+ * @defgroup charger_emul USB-C charger emulator
+ * @{
+ *
+ * USB-C charger emulator can be attached to TCPCI emulator. It is able to
+ * respond to some TCPM messages. It always attach as source and present
+ * hardcoded set of source capabilities.
+ */
+
+/** Structure describing charger emulator */
+struct charger_emul_data {
+ /** Operations used by TCPCI emulator */
+ struct tcpci_emul_partner_ops ops;
+ /** Work used to send message with delay */
+ struct k_work_delayable delayed_send;
+ /** Pointer to connected TCPCI emulator */
+ const struct emul *tcpci_emul;
+ /** Queue for delayed messages */
+ struct k_fifo to_send;
+ /** Next SOP message id */
+ int msg_id;
+};
+
+/**
+ * @brief Initialise USB-C charger emulator. Need to be called before any other
+ * function.
+ *
+ * @param data Pointer to USB-C charger emulator
+ */
+void charger_emul_init(struct charger_emul_data *data);
+
+/**
+ * @brief Connect emulated device to TCPCI
+ *
+ * @param data Pointer to USB-C charger emulator
+ * @param tcpci_emul Poinetr to TCPCI emulator to connect
+ *
+ * @return 0 on success
+ * @return negative on TCPCI connect error or send source capabilities error
+ */
+int charger_emul_connect_to_tcpci(struct charger_emul_data *data,
+ const struct emul *tcpci_emul);
+
+/**
+ * @}
+ */
+
+#endif /* __EMUL_CHARGER */