summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Brockus <dbrockus@chromium.org>2019-11-21 07:30:54 -0700
committerCommit Bot <commit-bot@chromium.org>2019-11-25 22:17:24 +0000
commitf9fd94f64d3294c2005048164361e3697d63a7bb (patch)
treed408036789da808cc6be0d2b4b08ad9e8f6c6970
parenta621ea9f352a7fdd5fa41982bfc4c13f1e351f3c (diff)
downloadchrome-ec-f9fd94f64d3294c2005048164361e3697d63a7bb.tar.gz
usbc: make BB virtual mux retimer compatible with non-virtual
Changed the driver interface for BB virtual mux retimer to stop using global functions and use the usb_retimers array instead. BUG=none BRANCH=none TEST=make buildall -j Change-Id: I56befaca1720eb2f4e0599a983629b4df45dc76b Signed-off-by: Denis Brockus <dbrockus@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1928121 Reviewed-by: Edward Hill <ecgh@chromium.org> Commit-Queue: Edward Hill <ecgh@chromium.org>
-rw-r--r--baseboard/intelrvp/retimer.c12
-rw-r--r--common/usb_pd_protocol.c2
-rw-r--r--driver/retimer/bb_retimer.c35
-rw-r--r--driver/retimer/bb_retimer.h25
-rw-r--r--driver/usb_mux/virtual.c13
-rw-r--r--include/config.h12
-rw-r--r--include/usb_mux.h19
-rw-r--r--include/usb_pd.h2
-rw-r--r--include/usb_retimer.h38
9 files changed, 49 insertions, 109 deletions
diff --git a/baseboard/intelrvp/retimer.c b/baseboard/intelrvp/retimer.c
index 33ada53254..2759e13dde 100644
--- a/baseboard/intelrvp/retimer.c
+++ b/baseboard/intelrvp/retimer.c
@@ -11,25 +11,25 @@
/* USB Retimers configuration */
#ifdef CONFIG_USBC_RETIMER_INTEL_BB
-struct bb_retimer bb_retimers[CONFIG_USB_PD_PORT_MAX_COUNT] = {
+struct usb_retimer usb_retimers[CONFIG_USB_PD_PORT_MAX_COUNT] = {
[TYPE_C_PORT_0] = {
+ .driver = &bb_usb_retimer,
.i2c_port = I2C_PORT0_BB_RETIMER,
- .i2c_addr = I2C_PORT0_BB_RETIMER_ADDR,
- .shared_nvm = USB_PORT0_BB_RETIMER_SHARED_NVM,
+ .i2c_addr_flags = I2C_PORT0_BB_RETIMER_ADDR,
.usb_ls_en_gpio = GPIO_USB_C0_LS_EN,
.retimer_rst_gpio = GPIO_USB_C0_RETIMER_RST,
.force_power_gpio = GPIO_USB_C0_RETIMER_FORCE_PWR,
},
#ifdef HAS_TASK_PD_C1
[TYPE_C_PORT_1] = {
+ .driver = &bb_usb_retimer,
.i2c_port = I2C_PORT1_BB_RETIMER,
- .i2c_addr = I2C_PORT1_BB_RETIMER_ADDR,
- .shared_nvm = USB_PORT1_BB_RETIMER_SHARED_NVM,
+ .i2c_addr_flags = I2C_PORT1_BB_RETIMER_ADDR,
.usb_ls_en_gpio = GPIO_USB_C1_LS_EN,
.retimer_rst_gpio = GPIO_USB_C1_RETIMER_RST,
.force_power_gpio = GPIO_USB_C1_RETIMER_FORCE_PWR,
},
#endif /* HAS_TASK_PD_C1 */
};
-BUILD_ASSERT(ARRAY_SIZE(bb_retimers) == CONFIG_USB_PD_PORT_MAX_COUNT);
+BUILD_ASSERT(ARRAY_SIZE(usb_retimers) == CONFIG_USB_PD_PORT_MAX_COUNT);
#endif /* CONFIG_USBC_RETIMER_INTEL_BB */
diff --git a/common/usb_pd_protocol.c b/common/usb_pd_protocol.c
index f85efa6717..fc8b28f29f 100644
--- a/common/usb_pd_protocol.c
+++ b/common/usb_pd_protocol.c
@@ -393,7 +393,6 @@ int pd_is_vbus_present(int port)
#endif
}
-#ifdef CONFIG_USBC_VIRTUAL_MUX_RETIMER
/**
* This function checks the current CC status of the port partner
* and returns true if the attached partner is UFP.
@@ -410,7 +409,6 @@ int pd_is_debug_acc(int port)
return pd[port].cc_state == PD_CC_UFP_DEBUG_ACC ||
pd[port].cc_state == PD_CC_DFP_DEBUG_ACC;
}
-#endif
static void set_polarity(int port, int polarity)
{
diff --git a/driver/retimer/bb_retimer.c b/driver/retimer/bb_retimer.c
index a6e7f87150..9a0caf5c4e 100644
--- a/driver/retimer/bb_retimer.c
+++ b/driver/retimer/bb_retimer.c
@@ -11,7 +11,6 @@
#include "i2c.h"
#include "timer.h"
#include "usb_pd.h"
-#include "usb_retimer.h"
#include "util.h"
#define BB_RETIMER_REG_SIZE 4
@@ -21,6 +20,9 @@
#define CPRINTS(format, args...) cprints(CC_USBCHARGE, format, ## args)
#define CPRINTF(format, args...) cprintf(CC_USBCHARGE, format, ## args)
+/**
+ * Utility functions
+ */
static int bb_retimer_read(int port, const uint8_t offset, uint32_t *data)
{
int rv;
@@ -33,8 +35,9 @@ static int bb_retimer_read(int port, const uint8_t offset, uint32_t *data)
* byte[1:4] : Data [LSB -> MSB]
* Stop
*/
- rv = i2c_xfer(bb_retimers[port].i2c_port, bb_retimers[port].i2c_addr,
- &offset, 1, buf, BB_RETIMER_READ_SIZE);
+ rv = i2c_xfer(usb_retimers[port].i2c_port,
+ usb_retimers[port].i2c_addr_flags,
+ &offset, 1, buf, BB_RETIMER_READ_SIZE);
if (rv)
return rv;
if (buf[0] != BB_RETIMER_REG_SIZE)
@@ -64,16 +67,16 @@ static int bb_retimer_write(int port, const uint8_t offset, uint32_t data)
buf[4] = (data >> 16) & 0xFF;
buf[5] = (data >> 24) & 0xFF;
- return i2c_xfer(bb_retimers[port].i2c_port, bb_retimers[port].i2c_addr,
+ return i2c_xfer(usb_retimers[port].i2c_port,
+ usb_retimers[port].i2c_addr_flags,
buf, BB_RETIMER_WRITE_SIZE, NULL, 0);
}
static void bb_retimer_power_handle(int port, int on_off)
{
- struct bb_retimer *retimer;
+ const struct usb_retimer * const retimer = &usb_retimers[port];
/* handle retimer's power domain */
- retimer = &bb_retimers[port];
if (on_off) {
gpio_set_level(retimer->usb_ls_en_gpio, 1);
@@ -87,7 +90,10 @@ static void bb_retimer_power_handle(int port, int on_off)
* time for both retimers to be initialized. Else allow 20ms
* to initialize.
*/
- if (retimer->shared_nvm)
+ if ((USB_PORT0_BB_RETIMER_SHARED_NVM &&
+ (port == TYPE_C_PORT_0)) ||
+ (USB_PORT1_BB_RETIMER_SHARED_NVM &&
+ (port == TYPE_C_PORT_1)))
msleep(40);
else
msleep(20);
@@ -100,7 +106,10 @@ static void bb_retimer_power_handle(int port, int on_off)
}
}
-int retimer_set_state(int port, mux_state_t mux_state)
+/**
+ * Driver interface functions
+ */
+static int retimer_set_state(int port, mux_state_t mux_state)
{
uint32_t set_retimer_con = 0;
uint8_t dp_pin_mode;
@@ -195,13 +204,13 @@ int retimer_set_state(int port, mux_state_t mux_state)
set_retimer_con);
}
-int retimer_low_power_mode(int port)
+static int retimer_low_power_mode(int port)
{
bb_retimer_power_handle(port, 0);
return EC_SUCCESS;
}
-int retimer_init(int port)
+static int retimer_init(int port)
{
int rv;
uint32_t data;
@@ -224,6 +233,12 @@ int retimer_init(int port)
return EC_SUCCESS;
}
+const struct usb_retimer_driver bb_usb_retimer = {
+ .init = retimer_init,
+ .set = retimer_set_state,
+ .enter_low_power_mode = retimer_low_power_mode,
+};
+
#ifdef CONFIG_CMD_RETIMER
static int console_command_bb_retimer(int argc, char **argv)
{
diff --git a/driver/retimer/bb_retimer.h b/driver/retimer/bb_retimer.h
index 7134517325..0dfa89e5f0 100644
--- a/driver/retimer/bb_retimer.h
+++ b/driver/retimer/bb_retimer.h
@@ -9,6 +9,7 @@
#define __CROS_EC_BB_RETIMER_H
#include "gpio.h"
+#include "usb_mux.h"
/* Burnside Bridge I2C Configuration Space */
#define BB_RETIMER_REG_VENDOR_ID 0
@@ -30,27 +31,7 @@
#define BB_RETIMER_IRQ_HPD BIT(14)
#define BB_RETIMER_HPD_LVL BIT(15)
-/* Describes a USB Retimer present in the system */
-struct bb_retimer {
- /* USB Retimer I2C port */
- const int i2c_port;
-
- /* USB Retimer I2C address */
- const int i2c_addr;
-
- /* NVM flag if shared with multiple BB-retimers */
- uint8_t shared_nvm;
-
- /* Retimer control GPIOs */
- enum gpio_signal usb_ls_en_gpio; /* Load switch enable */
- enum gpio_signal retimer_rst_gpio; /* Retimer reset */
- enum gpio_signal force_power_gpio; /* Force power (active/low) */
-};
-
-/*
- * USB Retimers in system, ordered by PD port #, defined at board-level
- * CONFIG_USBC_RETIMER_INTEL_BB need to be defind at board-level.
- */
-extern struct bb_retimer bb_retimers[];
+/* Supported USB retimer drivers */
+extern const struct usb_retimer_driver bb_usb_retimer;
#endif /* __CROS_EC_BB_RETIMER_H */
diff --git a/driver/usb_mux/virtual.c b/driver/usb_mux/virtual.c
index 7dc0d9087b..a6e8377ce8 100644
--- a/driver/usb_mux/virtual.c
+++ b/driver/usb_mux/virtual.c
@@ -9,7 +9,6 @@
#include "console.h"
#include "host_command.h"
#include "usb_mux.h"
-#include "usb_retimer.h"
#include "util.h"
/*
@@ -28,19 +27,14 @@ 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;
- if (IS_ENABLED(CONFIG_USBC_VIRTUAL_MUX_RETIMER) &&
- retimer_set_state(port, mux_state))
- return;
+
host_set_single_event(EC_HOST_EVENT_USB_MUX);
}
}
static int virtual_init(int port)
{
- if (IS_ENABLED(CONFIG_USBC_VIRTUAL_MUX_RETIMER))
- return retimer_init(port);
- else
- return EC_SUCCESS;
+ return EC_SUCCESS;
}
/*
@@ -84,7 +78,4 @@ const struct usb_mux_driver virtual_usb_mux_driver = {
.init = virtual_init,
.set = virtual_set_mux,
.get = virtual_get_mux,
-#ifdef CONFIG_USBC_VIRTUAL_MUX_RETIMER
- .enter_low_power_mode = retimer_low_power_mode,
-#endif
};
diff --git a/include/config.h b/include/config.h
index d9b8afcd8b..add8fcfa0e 100644
--- a/include/config.h
+++ b/include/config.h
@@ -3846,11 +3846,6 @@
* automatically be included. This does not stop a board/basebord.h
* configration from defining these as well.
*/
-
-/* Type-C retimer used with virtual mux */
-#undef CONFIG_USBC_VIRTUAL_MUX_RETIMER
-
-/* Type-C retimer used with real mux */
#undef CONFIG_USBC_MUX_RETIMER
/*
@@ -4748,11 +4743,8 @@
* for convenience. Any retimer driver that also needs USBC MUX Retimers
* will not have to include it in their own board/baseboard.h file.
*/
-#ifdef CONFIG_USBC_RETIMER_INTEL_BB
-#define CONFIG_USBC_VIRTUAL_MUX_RETIMER
-#endif
-
-#ifdef CONFIG_USBC_RETIMER_PI3DPX1207
+#if defined(CONFIG_USBC_RETIMER_INTEL_BB) || \
+ defined(CONFIG_USBC_RETIMER_PI3DPX1207)
#define CONFIG_USBC_MUX_RETIMER
#endif
diff --git a/include/usb_mux.h b/include/usb_mux.h
index 0a5a19a338..c0e781f65d 100644
--- a/include/usb_mux.h
+++ b/include/usb_mux.h
@@ -178,20 +178,23 @@ struct usb_retimer_driver {
struct usb_retimer {
/*
* All of the fields are provided on an as needed basis.
- * If your retimer does not perform I2C operations, then
- * values would not be set. This includes the driver
- * field, which would indicate no retimer driver is to
- * be called. Values that are not specifically popuplated
- * shall be 0/NULL.
+ * If your retimer does not use the provided machanism then
+ * values would not be set (defaulted to 0/NULL). This
+ * defaulting includes the driver field, which would indicate
+ * no retimer driver is to be called.
*/
/* I2C port and slave address */
const int i2c_port;
const uint16_t i2c_addr_flags;
- /* GPIOs for enabling the retimer and DP mode */
- const int gpio_enable;
- const int gpio_dp_enable;
+ /* Retimer control GPIOs */
+ const enum gpio_signal gpio_enable; /* Retimer enable */
+ const enum gpio_signal gpio_dp_enable; /* DP Mode enable */
+
+ const enum gpio_signal usb_ls_en_gpio; /* Load switch enable */
+ const enum gpio_signal retimer_rst_gpio;/* Retimer reset */
+ const enum gpio_signal force_power_gpio;/* Force power (active/low) */
/* Driver interfaces for this retimer */
const struct usb_retimer_driver *driver;
diff --git a/include/usb_pd.h b/include/usb_pd.h
index ca6f63254b..6051706670 100644
--- a/include/usb_pd.h
+++ b/include/usb_pd.h
@@ -2275,7 +2275,6 @@ static inline uint8_t board_get_usb_pd_port_count(void)
#endif /* CONFIG_USB_POWER_DELIVERY */
#endif /* CONFIG_USB_PD_PORT_MAX_COUNT */
-#ifdef CONFIG_USBC_VIRTUAL_MUX_RETIMER
/**
* Return true if specified PD port partner is UFP.
*
@@ -2289,7 +2288,6 @@ int pd_partner_is_ufp(int port);
* @param port USB-C port number
*/
int pd_is_debug_acc(int port);
-#endif
/*
* Notify the AP that we have entered into DisplayPort Alternate Mode. This
diff --git a/include/usb_retimer.h b/include/usb_retimer.h
deleted file mode 100644
index 9b750b51bd..0000000000
--- a/include/usb_retimer.h
+++ /dev/null
@@ -1,38 +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.
- */
-
-/* USB retimer driver */
-
-#ifndef __CROS_EC_USB_RETIMER_H
-#define __CROS_EC_USB_RETIMER_H
-
-#include "usb_mux.h"
-
-/**
- * Set USB retimer state
- *
- * @param port Port number.
- * @param mux_state current MUX state
- * @return Non-zero if fail; otherwise, zero.
- */
-int retimer_set_state(int port, mux_state_t mux_state);
-
-/**
- * USB retimer enter to low power mode.
- *
- * @param port Port number.
- * @return Non-zero if fail; otherwise, zero.
- */
-int retimer_low_power_mode(int port);
-
-/**
- * Initialize USB Retimer to its default state.
- *
- * @param port Port number.
- * @return Non-zero if fail; otherwise, zero.
- */
-int retimer_init(int port);
-
-#endif /* __CROS_EC_USB_RETIMER_H */