summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTomasz Michalec <tm@semihalf.com>2022-04-15 13:09:21 +0200
committerChromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com>2022-05-06 15:47:31 +0000
commitc5faba48e6ca3e3cb98db8abc896cd7ff4aeae44 (patch)
tree91c45898ffd8d8b844e9636ad3b41b14da7f894e
parent0e1584749f333086e04b24d3f568bff36bb0de61 (diff)
downloadchrome-ec-c5faba48e6ca3e3cb98db8abc896cd7ff4aeae44.tar.gz
zephyr: Add TCPCI USB-C mux DTS configuration
Add necessary changes to make it possible to configure TCPCI USB-C mux using devicetree. TCPCI USB-C mux has hpd-update property which allows to select hpd_update callback. Right now it allows to select NULL (by not selecting any value) or ps8xxx_tcpc_update_hpd_status. Because it is common to use PS8xxx as a mux, special parade,usbc-mux-ps8xxx compatible is made to automatically select default hpd_update callback. BUG=b:227757117 TEST=zmake testall BRANCH=none Signed-off-by: Tomasz Michalec <tm@semihalf.com> Change-Id: I2b5a98de58aa9fe8c47da69dff9151fd34f2a62b Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3586441 Commit-Queue: Tomasz Michalec <tmichalec@google.com> Tested-by: Tomasz Michalec <tmichalec@google.com> Reviewed-by: Keith Short <keithshort@chromium.org>
-rw-r--r--zephyr/dts/bindings/usbc/mux/cros-ec,usbc-mux-tcpci.yaml69
-rw-r--r--zephyr/dts/bindings/usbc/mux/parade,usbc-mux-ps8xxx.yaml15
-rw-r--r--zephyr/shim/include/usbc/tcpci_usb_mux.h50
-rw-r--r--zephyr/shim/include/usbc/usb_muxes.h22
4 files changed, 153 insertions, 3 deletions
diff --git a/zephyr/dts/bindings/usbc/mux/cros-ec,usbc-mux-tcpci.yaml b/zephyr/dts/bindings/usbc/mux/cros-ec,usbc-mux-tcpci.yaml
new file mode 100644
index 0000000000..9b986a5942
--- /dev/null
+++ b/zephyr/dts/bindings/usbc/mux/cros-ec,usbc-mux-tcpci.yaml
@@ -0,0 +1,69 @@
+# Copyright 2022 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.
+
+description: USBC TCPC USB MUX
+
+include: cros-ec,usbc-mux.yaml
+
+compatible: "cros-ec,usbc-mux-tcpci"
+
+properties:
+ hpd-update:
+ type: string
+ required: false
+ description: |
+ Name of function used as hpd_update callback
+ enum:
+ - ps8xxx_tcpc_update_hpd_status
+
+ port:
+ type: phandle
+ required: false
+ description: |
+ If the TCPC in your design is used to manage both the power-delivery
+ interface and configure the mux for the USB superspeed signals, this
+ property, and the i2c-addr-flags should be omitted. The driver uses
+ the I2C configuration specified in the corresponding TCPC node.
+
+ Example below
+
+ port0@0 {
+ compatible = "named-usbc-port";
+ reg = <0>;
+ tcpc {
+ compatible = "parade,ps8xxx";
+ status = "okay";
+ port = <&i2c_tcpc0>;
+ i2c-addr-flags = "PS8XXX_I2C_ADDR1_FLAGS";
+ };
+ usb-muxes = <&usb_mux_0>;
+ };
+ usb_mux_0 usb-mux-0 {
+ compatible = "parade,usbc-mux-ps8xxx";
+ /* I2C configuration provide by TCPC node */
+ };
+
+ If the TCPC in your design only configures the USB superspeed signals,
+ for instance when the EC chip contains an embedded TCPC controller,
+ then port and i2c-addr-flags are required.
+
+ port0@0 {
+ compatible = "named-usbc-port";
+ reg = <0>;
+ tcpc {
+ compatible = "ite,it8xxx2-tcpc";
+ };
+ };
+ usb_mux_0 usb-mux-0 {
+ compatible = "parade,usbc-mux-ps8xxx";
+ port = <i2c_usbc0>;
+ i2c-addr-flags = "PS8XXX_I2C_ADDR1_FLAGS";
+ };
+
+ i2c-addr-flags:
+ type: int
+ required: false
+ description: |
+ I2C address of chip. If provided, port property has to be present too.
+ Please check description of port property for more information.
diff --git a/zephyr/dts/bindings/usbc/mux/parade,usbc-mux-ps8xxx.yaml b/zephyr/dts/bindings/usbc/mux/parade,usbc-mux-ps8xxx.yaml
new file mode 100644
index 0000000000..685544cbf4
--- /dev/null
+++ b/zephyr/dts/bindings/usbc/mux/parade,usbc-mux-ps8xxx.yaml
@@ -0,0 +1,15 @@
+# Copyright 2022 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.
+
+description: USBC PS8xxx USB MUX
+
+include: cros-ec,usbc-mux-tcpci.yaml
+
+compatible: "parade,usbc-mux-ps8xxx"
+
+properties:
+ hpd-update:
+ description: |
+ PS8xxx USB MUX almost always use this hdp_update callback
+ default: "ps8xxx_tcpc_update_hpd_status"
diff --git a/zephyr/shim/include/usbc/tcpci_usb_mux.h b/zephyr/shim/include/usbc/tcpci_usb_mux.h
new file mode 100644
index 0000000000..9fa29c7c85
--- /dev/null
+++ b/zephyr/shim/include/usbc/tcpci_usb_mux.h
@@ -0,0 +1,50 @@
+/* Copyright 2022 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 __ZEPHYR_SHIM_TCPCI_USB_MUX_H
+#define __ZEPHYR_SHIM_TCPCI_USB_MUX_H
+
+#include "dt-bindings/usbc_mux.h"
+#include "tcpm/ps8xxx_public.h"
+#include "tcpm/tcpci.h"
+
+#define TCPCI_TCPM_USB_MUX_COMPAT cros_ec_usbc_mux_tcpci
+#define PS8XXX_USB_MUX_COMPAT parade_usbc_mux_ps8xxx
+
+/**
+ * Add I2C configuration and USB_MUX_FLAG_NOT_TCPC to enforce it when
+ * mux_read()/mux_write() functions are used.
+ */
+#define USB_MUX_CONFIG_TCPCI_TCPM_WITH_I2C(mux_id, port_id, idx) \
+ { \
+ USB_MUX_COMMON_FIELDS_WITH_FLAGS(mux_id, port_id, idx, \
+ USB_MUX_FLAG_NOT_TCPC, \
+ USB_MUX_FLAG_NOT_TCPC),\
+ .driver = &tcpci_tcpm_usb_mux_driver, \
+ .hpd_update = USB_MUX_CALLBACK_OR_NULL(mux_id, \
+ hpd_update), \
+ .i2c_port = I2C_PORT(DT_PHANDLE(mux_id, port)), \
+ .i2c_addr_flags = DT_PROP(mux_id, i2c_addr_flags), \
+ }
+
+/** Use I2C configuration from TCPC */
+#define USB_MUX_CONFIG_TCPCI_TCPM_WO_I2C(mux_id, port_id, idx) \
+ { \
+ USB_MUX_COMMON_FIELDS(mux_id, port_id, idx), \
+ .driver = &tcpci_tcpm_usb_mux_driver, \
+ .hpd_update = USB_MUX_CALLBACK_OR_NULL(mux_id, \
+ hpd_update), \
+ }
+
+/** This macro will fail if only port or i2c_addr_flags property is present */
+#define USB_MUX_CONFIG_TCPCI_TCPM(mux_id, port_id, idx) \
+ COND_CODE_1(UTIL_OR(DT_NODE_HAS_PROP(mux_id, port), \
+ DT_NODE_HAS_PROP(mux_id, i2c_addr_flags)), \
+ (USB_MUX_CONFIG_TCPCI_TCPM_WITH_I2C(mux_id, port_id,\
+ idx)), \
+ (USB_MUX_CONFIG_TCPCI_TCPM_WO_I2C(mux_id, port_id, \
+ idx)))
+
+#endif /* __ZEPHYR_SHIM_TCPCI_USB_MUX_H */
diff --git a/zephyr/shim/include/usbc/usb_muxes.h b/zephyr/shim/include/usbc/usb_muxes.h
index 09ad3824a0..731f1899a9 100644
--- a/zephyr/shim/include/usbc/usb_muxes.h
+++ b/zephyr/shim/include/usbc/usb_muxes.h
@@ -10,6 +10,7 @@
#include <sys/util_macro.h>
#include "usb_mux.h"
#include "usbc/it5205_usb_mux.h"
+#include "usbc/tcpci_usb_mux.h"
#include "usbc/tusb1064_usb_mux.h"
#include "usbc/virtual_usb_mux.h"
@@ -19,6 +20,8 @@
*/
#define USB_MUX_DRIVERS \
(IT5205_USB_MUX_COMPAT, USB_MUX_CONFIG_IT5205), \
+ (PS8XXX_USB_MUX_COMPAT, USB_MUX_CONFIG_TCPCI_TCPM), \
+ (TCPCI_TCPM_USB_MUX_COMPAT, USB_MUX_CONFIG_TCPCI_TCPM), \
(TUSB1064_USB_MUX_COMPAT, USB_MUX_CONFIG_TUSB1064), \
(VIRTUAL_USB_MUX_COMPAT, USB_MUX_CONFIG_VIRTUAL)
@@ -116,18 +119,31 @@
USB_MUX_POINTER_OR_NULL(DT_STRING_TOKEN_OR(mux_id, cb_name, EMPTY))
/**
- * @brief Set struct usb_mux fields common for all USB muxes
+ * @brief Set struct usb_mux fields common for all USB muxes and alter flags
*
* @param mux_id USB mux node ID
* @param port_id USBC node ID
* @param idx Position of USB mux in chain
+ * @param flags_mask Mask for bits that should be igonred in flags property
+ * @param flags_val Value that should be used instead for masked bits
*/
-#define USB_MUX_COMMON_FIELDS(mux_id, port_id, idx) \
+#define USB_MUX_COMMON_FIELDS_WITH_FLAGS(mux_id, port_id, idx, \
+ flags_mask, flags_val) \
.usb_port = USB_MUX_PORT(port_id), \
.next_mux = USB_MUX_NEXT_POINTER(port_id, idx), \
.board_init = USB_MUX_CALLBACK_OR_NULL(mux_id, board_init), \
.board_set = USB_MUX_CALLBACK_OR_NULL(mux_id, board_set), \
- .flags = DT_PROP(mux_id, flags)
+ .flags = (DT_PROP(mux_id, flags) & ~(flags_mask)) | (flags_val)
+
+/**
+ * @brief Set struct usb_mux fields common for all USB muxes
+ *
+ * @param mux_id USB mux node ID
+ * @param port_id USBC node ID
+ * @param idx Position of USB mux in chain
+ */
+#define USB_MUX_COMMON_FIELDS(mux_id, port_id, idx) \
+ USB_MUX_COMMON_FIELDS_WITH_FLAGS(mux_id, port_id, idx, 0, 0)
/**
* @brief Expands to 1 if @p mux_id has @p compat compatible. It is required