summaryrefslogtreecommitdiff
path: root/driver
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 /driver
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>
Diffstat (limited to 'driver')
-rw-r--r--driver/retimer/bb_retimer.c35
-rw-r--r--driver/retimer/bb_retimer.h25
-rw-r--r--driver/usb_mux/virtual.c13
3 files changed, 30 insertions, 43 deletions
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
};