diff options
Diffstat (limited to 'driver/usb_mux')
-rw-r--r-- | driver/usb_mux/amd_fp5.c | 119 | ||||
-rw-r--r-- | driver/usb_mux/amd_fp5.h | 21 | ||||
-rw-r--r-- | driver/usb_mux/it5205.c | 135 | ||||
-rw-r--r-- | driver/usb_mux/it5205.h | 34 | ||||
-rw-r--r-- | driver/usb_mux/pi3usb30532.c | 112 | ||||
-rw-r--r-- | driver/usb_mux/pi3usb30532.h | 65 | ||||
-rw-r--r-- | driver/usb_mux/pi3usb9281.h | 82 | ||||
-rw-r--r-- | driver/usb_mux/ps874x.c | 127 | ||||
-rw-r--r-- | driver/usb_mux/ps874x.h | 114 | ||||
-rw-r--r-- | driver/usb_mux/usb_mux.c | 292 | ||||
-rw-r--r-- | driver/usb_mux/virtual.c | 81 |
11 files changed, 0 insertions, 1182 deletions
diff --git a/driver/usb_mux/amd_fp5.c b/driver/usb_mux/amd_fp5.c deleted file mode 100644 index a912d03365..0000000000 --- a/driver/usb_mux/amd_fp5.c +++ /dev/null @@ -1,119 +0,0 @@ -/* Copyright 2019 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. - * - * AMD FP5 USB/DP Mux. - */ - -#include "amd_fp5.h" -#include "chipset.h" -#include "common.h" -#include "i2c.h" -#include "usb_mux.h" - -static inline int amd_fp5_mux_read(int port, uint8_t *val) -{ - uint8_t buf[3] = { 0 }; - int rv; - - rv = i2c_xfer(I2C_PORT_USB_MUX, AMD_FP5_MUX_I2C_ADDR_FLAGS, - NULL, 0, buf, 3); - if (rv) - return rv; - - *val = buf[port + 1]; - - return EC_SUCCESS; -} - -static inline int amd_fp5_mux_write(int port, uint8_t val) -{ - return i2c_write8(I2C_PORT_USB_MUX, AMD_FP5_MUX_I2C_ADDR_FLAGS, - port, val); -} - -static int amd_fp5_init(int port) -{ - return EC_SUCCESS; -} - -static int amd_fp5_set_mux(int port, mux_state_t mux_state) -{ - uint8_t val = 0; - - /* - * This MUX is on the FP5 SoC. If that device is not powered then - * we either have to complain that it is not powered or if we were - * setting the state to OFF, then go ahead and report that we did - * it because a powered down MUX is off. - */ - if (chipset_in_state(CHIPSET_STATE_HARD_OFF)) - return (mux_state == TYPEC_MUX_NONE) - ? EC_SUCCESS - : EC_ERROR_NOT_POWERED; - - if ((mux_state & MUX_USB_ENABLED) && (mux_state & MUX_DP_ENABLED)) - val = (mux_state & MUX_POLARITY_INVERTED) - ? AMD_FP5_MUX_DOCK_INVERTED : AMD_FP5_MUX_DOCK; - else if (mux_state & MUX_USB_ENABLED) - val = (mux_state & MUX_POLARITY_INVERTED) - ? AMD_FP5_MUX_USB_INVERTED : AMD_FP5_MUX_USB; - else if (mux_state & MUX_DP_ENABLED) - val = (mux_state & MUX_POLARITY_INVERTED) - ? AMD_FP5_MUX_DP_INVERTED : AMD_FP5_MUX_DP; - - return amd_fp5_mux_write(port, val); -} - -static int amd_fp5_get_mux(int port, mux_state_t *mux_state) -{ - uint8_t val = AMD_FP5_MUX_SAFE; - - /* - * This MUX is on the FP5 SoC. Only access the device if we - * have power. If that device is not powered then claim the - * state to be NONE, which is SAFE. - */ - if (!chipset_in_state(CHIPSET_STATE_HARD_OFF)) { - int rv; - - rv = amd_fp5_mux_read(port, &val); - if (rv) - return rv; - } - - - switch (val) { - case AMD_FP5_MUX_USB: - *mux_state = MUX_USB_ENABLED; - break; - case AMD_FP5_MUX_USB_INVERTED: - *mux_state = MUX_USB_ENABLED | MUX_POLARITY_INVERTED; - break; - case AMD_FP5_MUX_DOCK: - *mux_state = MUX_USB_ENABLED | MUX_DP_ENABLED; - break; - case AMD_FP5_MUX_DOCK_INVERTED: - *mux_state = MUX_USB_ENABLED | MUX_DP_ENABLED - | MUX_POLARITY_INVERTED; - break; - case AMD_FP5_MUX_DP: - *mux_state = MUX_DP_ENABLED; - break; - case AMD_FP5_MUX_DP_INVERTED: - *mux_state = MUX_DP_ENABLED | MUX_POLARITY_INVERTED; - break; - case AMD_FP5_MUX_SAFE: - default: - *mux_state = TYPEC_MUX_NONE; - break; - } - - return EC_SUCCESS; -} - -const struct usb_mux_driver amd_fp5_usb_mux_driver = { - .init = amd_fp5_init, - .set = amd_fp5_set_mux, - .get = amd_fp5_get_mux, -}; diff --git a/driver/usb_mux/amd_fp5.h b/driver/usb_mux/amd_fp5.h deleted file mode 100644 index 7534ea0d8a..0000000000 --- a/driver/usb_mux/amd_fp5.h +++ /dev/null @@ -1,21 +0,0 @@ -/* Copyright 2019 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. - * - * AMD FP5 USB/DP Mux. - */ - -#ifndef __CROS_EC_USB_MUX_AMD_FP5_H -#define __CROS_EC_USB_MUX_AMD_FP5_H - -#define AMD_FP5_MUX_I2C_ADDR_FLAGS 0x5C - -#define AMD_FP5_MUX_SAFE 0x00 -#define AMD_FP5_MUX_USB 0x02 -#define AMD_FP5_MUX_USB_INVERTED 0x11 -#define AMD_FP5_MUX_DOCK 0x06 -#define AMD_FP5_MUX_DOCK_INVERTED 0x19 -#define AMD_FP5_MUX_DP 0x0C -#define AMD_FP5_MUX_DP_INVERTED 0x1C - -#endif /* __CROS_EC_USB_MUX_AMD_FP5_H */ diff --git a/driver/usb_mux/it5205.c b/driver/usb_mux/it5205.c deleted file mode 100644 index 9a6f71dade..0000000000 --- a/driver/usb_mux/it5205.c +++ /dev/null @@ -1,135 +0,0 @@ -/* Copyright 2017 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. - * - * ITE IT5205 Type-C USB alternate mode mux. - */ - -#include "common.h" -#include "console.h" -#include "i2c.h" -#include "it5205.h" -#include "usb_mux.h" -#include "util.h" - -#define MUX_STATE_DP_USB_MASK (MUX_USB_ENABLED | MUX_DP_ENABLED) - -static int it5205_read(int port, uint8_t reg, int *val) -{ - return i2c_read8(I2C_PORT_USB_MUX, MUX_ADDR(port), reg, val); -} - -static int it5205_write(int port, uint8_t reg, uint8_t val) -{ - return i2c_write8(I2C_PORT_USB_MUX, MUX_ADDR(port), reg, val); -} - -struct mux_chip_id_t { - uint8_t chip_id; - uint8_t reg; -}; - -static const struct mux_chip_id_t mux_chip_id_verify[] = { - { '5', IT5205_REG_CHIP_ID3}, - { '2', IT5205_REG_CHIP_ID2}, - { '0', IT5205_REG_CHIP_ID1}, - { '5', IT5205_REG_CHIP_ID0}, -}; - -static int it5205_init(int port) -{ - int i, val, ret; - - /* bit[0]: mux power on, bit[7-1]: reserved. */ - ret = it5205_write(port, IT5205_REG_MUXPDR, 0); - if (ret) - return ret; - /* Verify chip ID registers. */ - for (i = 0; i < ARRAY_SIZE(mux_chip_id_verify); i++) { - ret = it5205_read(port, mux_chip_id_verify[i].reg, &val); - if (ret) - return ret; - - if (val != mux_chip_id_verify[i].chip_id) - return EC_ERROR_UNKNOWN; - } - - return EC_SUCCESS; -} - -/* Writes control register to set switch mode */ -static int it5205_set_mux(int port, mux_state_t mux_state) -{ - uint8_t reg; - - switch (mux_state & MUX_STATE_DP_USB_MASK) { - case MUX_USB_ENABLED: - reg = IT5205_USB; - break; - case MUX_DP_ENABLED: - reg = IT5205_DP; - break; - case MUX_STATE_DP_USB_MASK: - reg = IT5205_DP_USB; - break; - default: - reg = 0; - break; - } - - if (mux_state & MUX_POLARITY_INVERTED) - reg |= IT5205_POLARITY_INVERTED; - - return it5205_write(port, IT5205_REG_MUXCR, reg); -} - -/* Reads control register and updates mux_state accordingly */ -static int it5205_get_mux(int port, mux_state_t *mux_state) -{ - int reg, ret; - - ret = it5205_read(port, IT5205_REG_MUXCR, ®); - if (ret) - return ret; - - switch (reg & IT5205_DP_USB_CTRL_MASK) { - case IT5205_USB: - *mux_state = MUX_USB_ENABLED; - break; - case IT5205_DP: - *mux_state = MUX_DP_ENABLED; - break; - case IT5205_DP_USB: - *mux_state = MUX_STATE_DP_USB_MASK; - break; - default: - *mux_state = 0; - break; - } - - if (reg & IT5205_POLARITY_INVERTED) - *mux_state |= MUX_POLARITY_INVERTED; - - return EC_SUCCESS; -} - -static int it5205_enter_low_power_mode(int port) -{ - int rv; - - /* Turn off all switches */ - rv = it5205_write(port, IT5205_REG_MUXCR, 0); - - if (rv) - return rv; - - /* Power down mux */ - return it5205_write(port, IT5205_REG_MUXPDR, IT5205_MUX_POWER_DOWN); -} - -const struct usb_mux_driver it5205_usb_mux_driver = { - .init = &it5205_init, - .set = &it5205_set_mux, - .get = &it5205_get_mux, - .enter_low_power_mode = &it5205_enter_low_power_mode, -}; diff --git a/driver/usb_mux/it5205.h b/driver/usb_mux/it5205.h deleted file mode 100644 index 9e9c4ccfcc..0000000000 --- a/driver/usb_mux/it5205.h +++ /dev/null @@ -1,34 +0,0 @@ -/* Copyright 2017 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. - * - * ITE IT5205 Type-C USB alternate mode mux. - */ - -#ifndef __CROS_EC_IT5205_H -#define __CROS_EC_IT5205_H - -/* I2C interface */ -#define IT5205_I2C_ADDR1_FLAGS 0x48 -#define IT5205_I2C_ADDR2_FLAGS 0x58 - -/* Chip ID registers */ -#define IT5205_REG_CHIP_ID3 0x4 -#define IT5205_REG_CHIP_ID2 0x5 -#define IT5205_REG_CHIP_ID1 0x6 -#define IT5205_REG_CHIP_ID0 0x7 - -/* MUX power down register */ -#define IT5205_REG_MUXPDR 0x10 -#define IT5205_MUX_POWER_DOWN BIT(0) - -/* MUX control register */ -#define IT5205_REG_MUXCR 0x11 -#define IT5205_POLARITY_INVERTED BIT(4) - -#define IT5205_DP_USB_CTRL_MASK 0x0f -#define IT5205_DP 0x0f -#define IT5205_DP_USB 0x03 -#define IT5205_USB 0x07 - -#endif /* __CROS_EC_IT5205_H */ diff --git a/driver/usb_mux/pi3usb30532.c b/driver/usb_mux/pi3usb30532.c deleted file mode 100644 index e5af1b90a6..0000000000 --- a/driver/usb_mux/pi3usb30532.c +++ /dev/null @@ -1,112 +0,0 @@ -/* Copyright 2015 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. - * - * Pericom PI3USB30532 USB port switch driver. - */ - -#include "common.h" -#include "i2c.h" -#include "pi3usb30532.h" -#include "usb_mux.h" -#include "util.h" - -static int pi3usb30532_read(int port, uint8_t reg, uint8_t *val) -{ - int read, res; - - /* - * First byte read will be slave address (ignored). - * Second byte read will be vendor ID. - * Third byte read will be selection control. - */ - res = i2c_read16(I2C_PORT_USB_MUX, MUX_ADDR(port), - 0, &read); - if (res) - return res; - - if (reg == PI3USB30532_REG_VENDOR) - *val = read & 0xff; - else /* reg == PI3USB30532_REG_CONTROL */ - *val = (read >> 8) & 0xff; - - return EC_SUCCESS; -} - -static int pi3usb30532_write(int port, uint8_t reg, uint8_t val) -{ - if (reg != PI3USB30532_REG_CONTROL) - return EC_ERROR_UNKNOWN; - - return i2c_write8(I2C_PORT_USB_MUX, MUX_ADDR(port), - 0, val); -} - -static int pi3usb30532_reset(int port) -{ - return pi3usb30532_write( - port, - PI3USB30532_REG_CONTROL, - (PI3USB30532_MODE_POWERDOWN & PI3USB30532_CTRL_MASK) | - PI3USB30532_CTRL_RSVD); -} - -static int pi3usb30532_init(int port) -{ - uint8_t val; - int res; - - res = pi3usb30532_reset(port); - if (res) - return res; - res = pi3usb30532_read(port, PI3USB30532_REG_VENDOR, &val); - if (res) - return res; - if (val != PI3USB30532_VENDOR_ID) - return EC_ERROR_UNKNOWN; - - return EC_SUCCESS; -} - -/* Writes control register to set switch mode */ -static int pi3usb30532_set_mux(int port, mux_state_t mux_state) -{ - uint8_t reg = 0; - - if (mux_state & MUX_USB_ENABLED) - reg |= PI3USB30532_MODE_USB; - if (mux_state & MUX_DP_ENABLED) - reg |= PI3USB30532_MODE_DP; - if (mux_state & MUX_POLARITY_INVERTED) - reg |= PI3USB30532_BIT_SWAP; - - return pi3usb30532_write(port, PI3USB30532_REG_CONTROL, - reg | PI3USB30532_CTRL_RSVD); -} - -/* Reads control register and updates mux_state accordingly */ -static int pi3usb30532_get_mux(int port, mux_state_t *mux_state) -{ - uint8_t reg = 0; - uint8_t res; - - *mux_state = 0; - res = pi3usb30532_read(port, PI3USB30532_REG_CONTROL, ®); - if (res) - return res; - - if (reg & PI3USB30532_MODE_USB) - *mux_state |= MUX_USB_ENABLED; - if (reg & PI3USB30532_MODE_DP) - *mux_state |= MUX_DP_ENABLED; - if (reg & PI3USB30532_BIT_SWAP) - *mux_state |= MUX_POLARITY_INVERTED; - - return EC_SUCCESS; -} - -const struct usb_mux_driver pi3usb30532_usb_mux_driver = { - .init = pi3usb30532_init, - .set = pi3usb30532_set_mux, - .get = pi3usb30532_get_mux, -}; diff --git a/driver/usb_mux/pi3usb30532.h b/driver/usb_mux/pi3usb30532.h deleted file mode 100644 index 7f120a9f85..0000000000 --- a/driver/usb_mux/pi3usb30532.h +++ /dev/null @@ -1,65 +0,0 @@ -/* Copyright 2015 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. - * - * Pericom PI3USB30532 USB port switch driver. - */ - -#ifndef __CROS_EC_PI3USB30532_H -#define __CROS_EC_PI3USB30532_H - -#include "usb_pd.h" - -/* USB switch registers */ -#define PI3USB30532_REG_ADDR 0x00 -#define PI3USB30532_REG_VENDOR 0x01 -#define PI3USB30532_REG_CONTROL 0x02 -/* Control register field */ -#define PI3USB30532_CTRL_MASK 0x7 -#define PI3USB30532_CTRL_RSVD 0 -/* Switch vendor ID */ -#define PI3USB30532_VENDOR_ID 0 - -/* PI3USB30532 control flags */ -#define PI3USB30532_BIT_SWAP BIT(0) -#define PI3USB30532_BIT_DP BIT(1) -#define PI3USB30532_BIT_USB BIT(2) - -/* PI3USB30532 modes */ -/* Power down, switch open */ -#define PI3USB30532_MODE_POWERDOWN 0 -/* Keep power on, switch open */ -#define PI3USB30532_MODE_POWERON 1 -/* 4-lane DP 1.2 - * dp0~3 : rx2, tx2, tx1, rx1 - * hpd+/-: rfu1, rfu2 - */ -#define PI3USB30532_MODE_DP PI3USB30532_BIT_DP -/* 4-lane DP 1.2 swap - * dp0~3 : rx1, tx1, tx2, rx2 - * hpd+/-: rfu2, rfu1 - */ -#define PI3USB30532_MODE_DP_SWAP (PI3USB30532_MODE_DP | PI3USB30532_BIT_SWAP) -/* USB3 - * tx/rx : tx1, rx1 - */ -#define PI3USB30532_MODE_USB PI3USB30532_BIT_USB -/* USB3 swap - * tx/rx : tx2, rx2 - */ -#define PI3USB30532_MODE_USB_SWAP (PI3USB30532_MODE_USB | PI3USB30532_BIT_SWAP) -/* 2-lane DP 1.2 + USB3 - * tx/rx : tx1, rx1 - * dp0~1 : rx2, tx2 - * hpd+/-: rfu1, rfu2 - */ -#define PI3USB30532_MODE_DP_USB (PI3USB30532_BIT_DP | PI3USB30532_BIT_USB) -/* 2-lane DP 1.2 + USB3, swap - * tx/rx : tx2, rx2 - * dp0-1 : rx1, tx1 - * hpd+/-: rfu2, rfu1 - */ -#define PI3USB30532_MODE_DP_USB_SWAP (PI3USB30532_MODE_DP_USB | \ - PI3USB30532_BIT_SWAP) - -#endif /* __CROS_EC_PI3USB30532_H */ diff --git a/driver/usb_mux/pi3usb9281.h b/driver/usb_mux/pi3usb9281.h deleted file mode 100644 index 69b671500e..0000000000 --- a/driver/usb_mux/pi3usb9281.h +++ /dev/null @@ -1,82 +0,0 @@ -/* Copyright 2014 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. - * - * Pericom PI3USB9281 USB port switch. - */ - -#ifndef __CROS_EC_PI3USB9281_H -#define __CROS_EC_PI3USB9281_H - -#define PI3USB9281_REG_DEV_ID 0x01 -#define PI3USB9281_REG_CONTROL 0x02 -#define PI3USB9281_REG_INT 0x03 -#define PI3USB9281_REG_INT_MASK 0x05 -#define PI3USB9281_REG_DEV_TYPE 0x0a -#define PI3USB9281_REG_CHG_STATUS 0x0e -#define PI3USB9281_REG_MANUAL 0x13 -#define PI3USB9281_REG_RESET 0x1b -#define PI3USB9281_REG_VBUS 0x1d - -#define PI3USB9281_DEV_ID 0x10 -#define PI3USB9281_DEV_ID_A 0x18 - -#define PI3USB9281_CTRL_INT_DIS BIT(0) -#define PI3USB9281_CTRL_AUTO BIT(2) -#define PI3USB9281_CTRL_SWITCH_AUTO BIT(4) -/* Bits 5 thru 7 are read X, write 0 */ -#define PI3USB9281_CTRL_MASK 0x1f -/* Bits 1 and 3 are read 1, write 1 */ -#define PI3USB9281_CTRL_RSVD_1 0x0a - -#define PI3USB9281_PIN_MANUAL_VBUS (3 << 0) -#define PI3USB9281_PIN_MANUAL_DP BIT(2) -#define PI3USB9281_PIN_MANUAL_DM BIT(5) - -#define PI3USB9281_INT_ATTACH BIT(0) -#define PI3USB9281_INT_DETACH BIT(1) -#define PI3USB9281_INT_OVP BIT(5) -#define PI3USB9281_INT_OCP BIT(6) -#define PI3USB9281_INT_OVP_OC BIT(7) -#define PI3USB9281_INT_ATTACH_DETACH (PI3USB9281_INT_ATTACH | \ - PI3USB9281_INT_DETACH) - -#define PI3USB9281_TYPE_NONE 0 -#define PI3USB9281_TYPE_MHL BIT(0) -#define PI3USB9281_TYPE_OTG BIT(1) -#define PI3USB9281_TYPE_SDP BIT(2) -#define PI3USB9281_TYPE_CAR BIT(4) -#define PI3USB9281_TYPE_CDP BIT(5) -#define PI3USB9281_TYPE_DCP BIT(6) - -#define PI3USB9281_CHG_NONE 0 -#define PI3USB9281_CHG_CAR_TYPE1 BIT(1) -#define PI3USB9281_CHG_CAR_TYPE2 (3 << 0) -#define PI3USB9281_CHG_APPLE_1A BIT(2) -#define PI3USB9281_CHG_APPLE_2A BIT(3) -#define PI3USB9281_CHG_APPLE_2_4A BIT(4) -/* Check if charge status has any connection */ -#define PI3USB9281_CHG_STATUS_ANY(x) (((x) & 0x1f) > 1) - -/* Define configuration of one pi3usb9281 part */ -struct pi3usb9281_config { - /* i2c port that chip resides on */ - int i2c_port; - /* GPIO for chip selection in muxed configuration */ - enum gpio_signal mux_gpio; - /* Logic level of mux_gpio to select chip */ - int mux_gpio_level; - /* Mutex to lock access to mux gpio or NULL if no mux exists */ - struct mutex *mux_lock; -}; - -/* Configuration struct defined at board level */ -extern struct pi3usb9281_config pi3usb9281_chips[]; - -/* Enable interrupts. */ -int pi3usb9281_enable_interrupts(int port); - -/* Get the device type */ -int pi3usb9281_get_device_type(int port); - -#endif /* __CROS_EC_PI3USB9281_H */ diff --git a/driver/usb_mux/ps874x.c b/driver/usb_mux/ps874x.c deleted file mode 100644 index db13180c1c..0000000000 --- a/driver/usb_mux/ps874x.c +++ /dev/null @@ -1,127 +0,0 @@ -/* Copyright 2017 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. - * - * Parade PS874X USB Type-C Redriving Switch for USB Host / DisplayPort. - */ - -#include "common.h" -#include "i2c.h" -#include "ps874x.h" -#include "usb_mux.h" -#include "util.h" - -static inline int ps874x_read(int port, uint8_t reg, int *val) -{ - return i2c_read8(I2C_PORT_USB_MUX, MUX_ADDR(port), - reg, val); -} - -static inline int ps874x_write(int port, uint8_t reg, uint8_t val) -{ - return i2c_write8(I2C_PORT_USB_MUX, MUX_ADDR(port), - reg, val); -} - -static int ps874x_init(int port) -{ - int val; - int res; - - /* Reset chip back to power-on state */ - res = ps874x_write(port, PS874X_REG_MODE, PS874X_MODE_POWER_DOWN); - if (res) - return res; - - /* - * Verify revision / chip ID registers. - */ - res = ps874x_read(port, PS874X_REG_REVISION_ID1, &val); - if (res) - return res; - -#ifdef CONFIG_USB_MUX_PS8743 - /* - * From Parade: PS8743 may have REVISION_ID1 as 0 or 1 - * Rev 1 is derived from Rev 0 and have same functionality. - */ - if (val != PS874X_REVISION_ID1_0 && val != PS874X_REVISION_ID1_1) - return EC_ERROR_UNKNOWN; -#else - if (val != PS874X_REVISION_ID1) - return EC_ERROR_UNKNOWN; -#endif - - res = ps874x_read(port, PS874X_REG_REVISION_ID2, &val); - if (res) - return res; - if (val != PS874X_REVISION_ID2) - return EC_ERROR_UNKNOWN; - - res = ps874x_read(port, PS874X_REG_CHIP_ID1, &val); - if (res) - return res; - if (val != PS874X_CHIP_ID1) - return EC_ERROR_UNKNOWN; - - res = ps874x_read(port, PS874X_REG_CHIP_ID2, &val); - if (res) - return res; - if (val != PS874X_CHIP_ID2) - return EC_ERROR_UNKNOWN; - - return EC_SUCCESS; -} - -/* Writes control register to set switch mode */ -static int ps874x_set_mux(int port, mux_state_t mux_state) -{ - uint8_t reg = 0; - - if (mux_state & MUX_USB_ENABLED) - reg |= PS874X_MODE_USB_ENABLED; - if (mux_state & MUX_DP_ENABLED) - reg |= PS874X_MODE_DP_ENABLED; - if (mux_state & MUX_POLARITY_INVERTED) - reg |= PS874X_MODE_POLARITY_INVERTED; - - return ps874x_write(port, PS874X_REG_MODE, reg); -} - -/* Reads control register and updates mux_state accordingly */ -static int ps874x_get_mux(int port, mux_state_t *mux_state) -{ - int reg; - int res; - - res = ps874x_read(port, PS874X_REG_STATUS, ®); - if (res) - return res; - - *mux_state = 0; - if (reg & PS874X_STATUS_USB_ENABLED) - *mux_state |= MUX_USB_ENABLED; - if (reg & PS874X_STATUS_DP_ENABLED) - *mux_state |= MUX_DP_ENABLED; - if (reg & PS874X_STATUS_POLARITY_INVERTED) - *mux_state |= MUX_POLARITY_INVERTED; - - return EC_SUCCESS; -} - -/* Tune USB Tx/Rx Equalization */ -int ps874x_tune_usb_eq(int port, uint8_t tx, uint8_t rx) -{ - int ret; - - ret = ps874x_write(port, PS874X_REG_USB_EQ_TX, tx); - ret |= ps874x_write(port, PS874X_REG_USB_EQ_RX, rx); - - return ret; -} - -const struct usb_mux_driver ps874x_usb_mux_driver = { - .init = ps874x_init, - .set = ps874x_set_mux, - .get = ps874x_get_mux, -}; diff --git a/driver/usb_mux/ps874x.h b/driver/usb_mux/ps874x.h deleted file mode 100644 index e7bd185bcf..0000000000 --- a/driver/usb_mux/ps874x.h +++ /dev/null @@ -1,114 +0,0 @@ -/* Copyright 2017 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. - * - * Parade PS874X USB Type-C Redriving Switch for USB Host / DisplayPort. - */ - -#ifndef __CROS_EC_PS874X_H -#define __CROS_EC_PS874X_H - -/* Mode register for setting mux */ -#define PS874X_REG_MODE 0x00 -#ifdef CONFIG_USB_MUX_PS8740 - #define PS874X_MODE_POLARITY_INVERTED BIT(4) - #define PS874X_MODE_USB_ENABLED BIT(5) - #define PS874X_MODE_DP_ENABLED BIT(6) - #define PS874X_MODE_POWER_DOWN BIT(7) -#elif defined(CONFIG_USB_MUX_PS8743) - #define PS874X_MODE_POLARITY_INVERTED BIT(2) - #define PS874X_MODE_FLIP_PIN_ENABLED BIT(3) - #define PS874X_MODE_USB_ENABLED BIT(4) - #define PS874X_MODE_CE_USB_ENABLED BIT(5) - #define PS874X_MODE_DP_ENABLED BIT(6) - #define PS874X_MODE_CE_DP_ENABLED BIT(7) - /* To reset the state machine to default */ - #define PS874X_MODE_POWER_DOWN (PS874X_MODE_CE_USB_ENABLED | \ - PS874X_MODE_CE_DP_ENABLED) -#endif - -/* Status register for checking mux state */ -#define PS874X_REG_STATUS 0x09 -#define PS874X_STATUS_POLARITY_INVERTED BIT(2) -#define PS874X_STATUS_USB_ENABLED BIT(3) -#define PS874X_STATUS_DP_ENABLED BIT(4) -#define PS874X_STATUS_HPD_ASSERTED BIT(7) - -/* Chip ID / revision registers and expected fused values */ -#define PS874X_REG_REVISION_ID1 0xf0 -#define PS874X_REG_REVISION_ID2 0xf1 -#define PS874X_REG_CHIP_ID1 0xf2 -#define PS874X_REG_CHIP_ID2 0xf3 -#ifdef CONFIG_USB_MUX_PS8740 - #define PS874X_REVISION_ID1 0x00 - #define PS874X_REVISION_ID2 0x0a - #define PS874X_CHIP_ID1 0x40 -#elif defined(CONFIG_USB_MUX_PS8743) - #define PS874X_REVISION_ID1_0 0x00 - #define PS874X_REVISION_ID1_1 0x01 - #define PS874X_REVISION_ID2 0x0b - #define PS874X_CHIP_ID1 0x41 -#endif -#define PS874X_CHIP_ID2 0x87 - -/* USB equalization settings for Host to Mux */ -#define PS874X_REG_USB_EQ_TX 0x32 -#ifdef CONFIG_USB_MUX_PS8740 - #define PS874X_USB_EQ_TX_10_1_DB 0x00 - #define PS874X_USB_EQ_TX_14_3_DB 0x20 - #define PS874X_USB_EQ_TX_8_5_DB 0x40 - #define PS874X_USB_EQ_TX_6_5_DB 0x60 - #define PS874X_USB_EQ_TX_11_5_DB 0x80 - #define PS874X_USB_EQ_TX_9_5_DB 0xc0 - #define PS874X_USB_EQ_TX_7_5_DB 0xe0 - #define PS874X_USB_EQ_TERM_100_OHM (0 << 2) - #define PS874X_USB_EQ_TERM_85_OHM BIT(2) -#elif defined(CONFIG_USB_MUX_PS8743) - #define PS874X_USB_EQ_TX_12_8_DB 0x00 - #define PS874X_USB_EQ_TX_17_DB 0x20 - #define PS874X_USB_EQ_TX_7_7_DB 0x40 - #define PS874X_USB_EQ_TX_3_6_DB 0x60 - #define PS874X_USB_EQ_TX_15_DB 0x80 - #define PS874X_USB_EQ_TX_10_9_DB 0xc0 - #define PS874X_USB_EQ_TX_4_5_DB 0xe0 -#endif - -/* USB equalization settings for Connector to Mux */ -#define PS874X_REG_USB_EQ_RX 0x3b -#ifdef CONFIG_USB_MUX_PS8740 - #define PS874X_USB_EQ_RX_4_4_DB 0x00 - #define PS874X_USB_EQ_RX_7_0_DB 0x10 - #define PS874X_USB_EQ_RX_8_2_DB 0x20 - #define PS874X_USB_EQ_RX_9_4_DB 0x30 - #define PS874X_USB_EQ_RX_10_2_DB 0x40 - #define PS874X_USB_EQ_RX_11_4_DB 0x50 - #define PS874X_USB_EQ_RX_14_3_DB 0x60 - #define PS874X_USB_EQ_RX_14_8_DB 0x70 - #define PS874X_USB_EQ_RX_15_2_DB 0x80 - #define PS874X_USB_EQ_RX_15_5_DB 0x90 - #define PS874X_USB_EQ_RX_16_2_DB 0xa0 - #define PS874X_USB_EQ_RX_17_3_DB 0xb0 - #define PS874X_USB_EQ_RX_18_4_DB 0xc0 - #define PS874X_USB_EQ_RX_20_1_DB 0xd0 - #define PS874X_USB_EQ_RX_21_3_DB 0xe0 -#elif defined(CONFIG_USB_MUX_PS8743) - #define PS874X_USB_EQ_RX_2_4_DB 0x00 - #define PS874X_USB_EQ_RX_5_DB 0x10 - #define PS874X_USB_EQ_RX_6_5_DB 0x20 - #define PS874X_USB_EQ_RX_7_4_DB 0x30 - #define PS874X_USB_EQ_RX_8_7_DB 0x40 - #define PS874X_USB_EQ_RX_10_9_DB 0x50 - #define PS874X_USB_EQ_RX_12_8_DB 0x60 - #define PS874X_USB_EQ_RX_13_8_DB 0x70 - #define PS874X_USB_EQ_RX_14_8_DB 0x80 - #define PS874X_USB_EQ_RX_15_4_DB 0x90 - #define PS874X_USB_EQ_RX_16_0_DB 0xa0 - #define PS874X_USB_EQ_RX_16_7_DB 0xb0 - #define PS874X_USB_EQ_RX_18_8_DB 0xc0 - #define PS874X_USB_EQ_RX_21_3_DB 0xd0 - #define PS874X_USB_EQ_RX_22_2_DB 0xe0 -#endif - -int ps874x_tune_usb_eq(int i2c_addr, uint8_t tx, uint8_t rx); - -#endif /* __CROS_EC_PS874X_H */ diff --git a/driver/usb_mux/usb_mux.c b/driver/usb_mux/usb_mux.c deleted file mode 100644 index 93c741c1e9..0000000000 --- a/driver/usb_mux/usb_mux.c +++ /dev/null @@ -1,292 +0,0 @@ -/* Copyright 2015 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. - */ - -/* USB mux high-level driver. */ - -#include "common.h" -#include "console.h" -#include "host_command.h" -#include "usb_mux.h" -#include "usbc_ppc.h" -#include "util.h" - -#define CPRINTS(format, args...) cprints(CC_USBCHARGE, format, ## args) -#define CPRINTF(format, args...) cprintf(CC_USBCHARGE, format, ## args) - -static int enable_debug_prints; - -/* - * Flags will reset to 0 after sysjump; This works for current flags as LPM will - * get reset in the init method which is called during PD task startup. - */ -static uint8_t flags[CONFIG_USB_PD_PORT_MAX_COUNT]; - -#define USB_MUX_FLAG_IN_LPM BIT(0) /* Device is in low power mode. */ - - -static void enter_low_power_mode(int port) -{ - const struct usb_mux *mux = &usb_muxes[port]; - int res; - - /* - * Set LPM flag regardless of method presence or method failure. We want - * know know that we tried to put the device in low power mode so we can - * re-initialize the device on the next access. - */ - flags[port] |= USB_MUX_FLAG_IN_LPM; - - /* Apply any low power customization if present */ - if (mux->driver->enter_low_power_mode) { - res = mux->driver->enter_low_power_mode(port); - if (res) { - CPRINTS("Err: %s mux port(%d): %d", - __func__, port, res); - return; - } - } - - if (IS_ENABLED(CONFIG_USBC_MUX_RETIMER)) { - const struct usb_retimer *retimer = &usb_retimers[port]; - - if (retimer->driver && retimer->driver->enter_low_power_mode) { - res = retimer->driver->enter_low_power_mode(port); - if (res) { - CPRINTS("Err: %s retimer port(%d): %d", - __func__, port, res); - return; - } - } - } -} - -static inline void exit_low_power_mode(int port) -{ - /* If we are in low power, initialize device (which clears LPM flag) */ - if (flags[port] & USB_MUX_FLAG_IN_LPM) - usb_mux_init(port); -} - -void usb_mux_init(int port) -{ - const struct usb_mux *mux = &usb_muxes[port]; - int res; - - ASSERT(port >= 0 && port < CONFIG_USB_PD_PORT_MAX_COUNT); - - res = mux->driver->init(port); - if (res) { - CPRINTS("Err: init mux port(%d): %d", port, res); - return; - } - - if (IS_ENABLED(CONFIG_USBC_MUX_RETIMER)) { - const struct usb_retimer *retimer = &usb_retimers[port]; - - if (retimer->driver && retimer->driver->init) { - res = retimer->driver->init(port); - if (res) { - CPRINTS("Err: init retimer port(%d): %d", - port, res); - return; - } - } - } - - /* Device is always out of LPM after initialization. */ - flags[port] &= ~USB_MUX_FLAG_IN_LPM; - - /* Apply board specific initialization */ - if (mux->board_init) { - res = mux->board_init(port); - - if (res) - CPRINTS("Err: board_init mux port(%d): %d", port, res); - } -} - -/* - * TODO(crbug.com/505480): Setting muxes often involves I2C transcations, - * which can block. Consider implementing an asynchronous task. - */ -void usb_mux_set(int port, enum typec_mux mux_mode, - enum usb_switch usb_mode, int polarity) -{ - const struct usb_mux *mux = &usb_muxes[port]; - int res; - mux_state_t mux_state; - const int should_enter_low_power_mode = - mux_mode == TYPEC_MUX_NONE && usb_mode == USB_SWITCH_DISCONNECT; - - /* Configure USB2.0 */ - if (IS_ENABLED(CONFIG_USB_CHARGER)) - usb_charger_set_switches(port, usb_mode); - - /* - * Don't wake device up just to put it back to sleep. Low power mode - * flag is only set if the mux set() operation succeeded previously for - * the same disconnected state. - */ - if (should_enter_low_power_mode && (flags[port] & USB_MUX_FLAG_IN_LPM)) - return; - - exit_low_power_mode(port); - - /* Configure superspeed lanes */ - mux_state = ((mux_mode != TYPEC_MUX_NONE) && polarity) - ? mux_mode | MUX_POLARITY_INVERTED - : mux_mode; - - res = mux->driver->set(port, mux_state); - if (res) { - CPRINTS("Err: set mux port(%d): %d", port, res); - return; - } - - if (IS_ENABLED(CONFIG_USBC_MUX_RETIMER)) { - const struct usb_retimer *retimer = &usb_retimers[port]; - - if (retimer->driver && retimer->driver->set) { - res = retimer->driver->set(port, mux_state); - if (res) { - CPRINTS("Err: set retimer port(%d): %d", - port, res); - return; - } - } - } - - if (enable_debug_prints) - CPRINTS( - "usb/dp mux: port(%d) typec_mux(%d) usb2(%d) polarity(%d)", - port, mux_mode, usb_mode, polarity); - - /* - * If we are completely disconnecting the mux, then we should put it in - * its lowest power state. - */ - if (should_enter_low_power_mode) - enter_low_power_mode(port); -} - -mux_state_t usb_mux_get(int port) -{ - const struct usb_mux *mux = &usb_muxes[port]; - int res; - mux_state_t mux_state; - - exit_low_power_mode(port); - - res = mux->driver->get(port, &mux_state); - if (res) { - CPRINTS("Err: get mux port(%d): %d", port, res); - return 0; - } - - return mux_state; -} - -void usb_mux_flip(int port) -{ - const struct usb_mux *mux = &usb_muxes[port]; - int res; - mux_state_t mux_state; - - exit_low_power_mode(port); - - res = mux->driver->get(port, &mux_state); - if (res) { - CPRINTS("Err: get mux port(%d): %d", port, res); - return; - } - - if (mux_state & MUX_POLARITY_INVERTED) - mux_state &= ~MUX_POLARITY_INVERTED; - else - mux_state |= MUX_POLARITY_INVERTED; - - res = mux->driver->set(port, mux_state); - if (res) - CPRINTS("Err: set mux port(%d): %d", port, res); -} - -#ifdef CONFIG_CMD_TYPEC -static int command_typec(int argc, char **argv) -{ - const char * const mux_name[] = {"none", "usb", "dp", "dock"}; - char *e; - int port; - enum typec_mux mux = TYPEC_MUX_NONE; - int i; - - if (argc == 2 && !strcasecmp(argv[1], "debug")) { - enable_debug_prints = 1; - return EC_SUCCESS; - } - - if (argc < 2) - return EC_ERROR_PARAM_COUNT; - - port = strtoi(argv[1], &e, 10); - if (*e || port >= board_get_usb_pd_port_count()) - return EC_ERROR_PARAM1; - - if (argc < 3) { - mux_state_t mux_state; - - mux_state = usb_mux_get(port); - ccprintf("Port %d: USB=%d DP=%d POLARITY=%s HPD_IRQ=%d " - "HPD_LVL=%d SAFE=%d\n", port, - !!(mux_state & USB_PD_MUX_USB_ENABLED), - !!(mux_state & USB_PD_MUX_DP_ENABLED), - mux_state & USB_PD_MUX_POLARITY_INVERTED ? - "INVERTED" : "NORMAL", - !!(mux_state & USB_PD_MUX_HPD_IRQ), - !!(mux_state & USB_PD_MUX_HPD_LVL), - !!(mux_state & USB_PD_MUX_SAFE_MODE)); - - return EC_SUCCESS; - } - - for (i = 0; i < ARRAY_SIZE(mux_name); i++) - if (!strcasecmp(argv[2], mux_name[i])) - mux = i; - usb_mux_set(port, mux, mux == TYPEC_MUX_NONE ? - USB_SWITCH_DISCONNECT : - USB_SWITCH_CONNECT, - pd_get_polarity(port)); - return EC_SUCCESS; -} -DECLARE_CONSOLE_COMMAND(typec, command_typec, - "[port|debug] [none|usb|dp|dock]", - "Control type-C connector muxing"); -#endif - -static enum ec_status hc_usb_pd_mux_info(struct host_cmd_handler_args *args) -{ - const struct ec_params_usb_pd_mux_info *p = args->params; - struct ec_response_usb_pd_mux_info *r = args->response; - int port = p->port; - const struct usb_mux *mux; - - if (port >= board_get_usb_pd_port_count()) - return EC_RES_INVALID_PARAM; - - mux = &usb_muxes[port]; - if (mux->driver->get(port, &r->flags) != EC_SUCCESS) - return EC_RES_ERROR; - - /* Clear HPD IRQ event since we're about to inform host of it. */ - if (IS_ENABLED(CONFIG_USB_MUX_VIRTUAL) && - (r->flags & USB_PD_MUX_HPD_IRQ) && - (mux->hpd_update == &virtual_hpd_update)) - mux->hpd_update(port, r->flags & USB_PD_MUX_HPD_LVL, 0); - - args->response_size = sizeof(*r); - return EC_RES_SUCCESS; -} -DECLARE_HOST_COMMAND(EC_CMD_USB_PD_MUX_INFO, - hc_usb_pd_mux_info, - EC_VER_MASK(0)); diff --git a/driver/usb_mux/virtual.c b/driver/usb_mux/virtual.c deleted file mode 100644 index a6e8377ce8..0000000000 --- a/driver/usb_mux/virtual.c +++ /dev/null @@ -1,81 +0,0 @@ -/* Copyright 2016 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. - * - * Virtual USB mux driver for host-controlled USB muxes. - */ - -#include "common.h" -#include "console.h" -#include "host_command.h" -#include "usb_mux.h" -#include "util.h" - -/* - * USB PD protocol configures the USB & DP mux state and USB PD policy - * configures the HPD mux state. Both states are independent of each other - * may differ when the PD role changes when in dock mode. - */ -#define USB_PD_MUX_HPD_STATE (USB_PD_MUX_HPD_LVL | USB_PD_MUX_HPD_IRQ) -#define USB_PD_MUX_USB_DP_STATE (USB_PD_MUX_USB_ENABLED | \ - USB_PD_MUX_DP_ENABLED | USB_PD_MUX_POLARITY_INVERTED | \ - USB_PD_MUX_SAFE_MODE) - -static mux_state_t virtual_mux_state[CONFIG_USB_PD_PORT_MAX_COUNT]; - -static inline void virtual_mux_update_state(int port, mux_state_t mux_state) -{ - if (virtual_mux_state[port] != mux_state) { - virtual_mux_state[port] = mux_state; - - host_set_single_event(EC_HOST_EVENT_USB_MUX); - } -} - -static int virtual_init(int port) -{ - return EC_SUCCESS; -} - -/* - * Set the state of our 'virtual' mux. The EC does not actually control this - * mux, so update the desired state, then notify the host of the update. - */ -static int virtual_set_mux(int port, mux_state_t mux_state) -{ - /* Current USB & DP mux status + existing HPD related mux status */ - mux_state_t new_mux_state = (mux_state & ~USB_PD_MUX_HPD_STATE) | - (virtual_mux_state[port] & USB_PD_MUX_HPD_STATE); - - virtual_mux_update_state(port, new_mux_state); - - return EC_SUCCESS; -} - -/* - * Get the state of our 'virtual' mux. Since we the EC does not actually - * control this mux, and the EC has no way of knowing its actual status, - * we return the desired state here. - */ -static int virtual_get_mux(int port, mux_state_t *mux_state) -{ - *mux_state = virtual_mux_state[port]; - - return EC_SUCCESS; -} - -void virtual_hpd_update(int port, int hpd_lvl, int hpd_irq) -{ - /* Current HPD related mux status + existing USB & DP mux status */ - mux_state_t new_mux_state = (hpd_lvl ? USB_PD_MUX_HPD_LVL : 0) | - (hpd_irq ? USB_PD_MUX_HPD_IRQ : 0) | - (virtual_mux_state[port] & USB_PD_MUX_USB_DP_STATE); - - virtual_mux_update_state(port, new_mux_state); -} - -const struct usb_mux_driver virtual_usb_mux_driver = { - .init = virtual_init, - .set = virtual_set_mux, - .get = virtual_get_mux, -}; |