diff options
author | Rob Barnes <robbarnes@google.com> | 2021-06-07 14:39:12 -0600 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2021-06-11 21:21:42 +0000 |
commit | 8c0af6114508375f0c75112b9cef593719d8812a (patch) | |
tree | 797edbfe6fd17a9e021fe5252530845ba90bb47d /baseboard/guybrush | |
parent | 4860dccf9a0ea7c5ecba92d984491bd7151a31f0 (diff) | |
download | chrome-ec-8c0af6114508375f0c75112b9cef593719d8812a.tar.gz |
guybrush: Reuse USB mux structure for USBA retimers
Reuse the USB mux structure for USB A retimers. These retimers do not
have an internal mux, so many fields do not apply. This change makes it
simpler to create generic methods.
BUG=None
TEST=Build and run
BRANCH=None
Signed-off-by: Rob Barnes <robbarnes@google.com>
Change-Id: Idb2eef25bdd820febb18ef3b7af48c21f4c545d8
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2946306
Reviewed-by: Diana Z <dzigterman@chromium.org>
Diffstat (limited to 'baseboard/guybrush')
-rw-r--r-- | baseboard/guybrush/baseboard.c | 60 |
1 files changed, 43 insertions, 17 deletions
diff --git a/baseboard/guybrush/baseboard.c b/baseboard/guybrush/baseboard.c index 69e454eef9..b034b6f633 100644 --- a/baseboard/guybrush/baseboard.c +++ b/baseboard/guybrush/baseboard.c @@ -849,12 +849,13 @@ void board_hibernate(void) } } -__overridable void board_a1_ps8811_retimer_setup(void) +__overridable enum ec_error_list +board_a1_ps8811_retimer_init(const struct usb_mux *me) { - CPRINTSUSB("A1: PS8811 retimer using default tuning"); + return EC_SUCCESS; } -static void baseboard_a1_ps8811_retimer_setup(void) +static int baseboard_a1_ps8811_retimer_init(const struct usb_mux *me) { int rv; int tries = 2; @@ -862,25 +863,37 @@ static void baseboard_a1_ps8811_retimer_setup(void) do { int val; - rv = i2c_read8(I2C_PORT_TCPC1, - PS8811_I2C_ADDR_FLAGS3 + PS8811_REG_PAGE1, - PS8811_REG1_USB_BEQ_LEVEL, &val); + rv = i2c_read8(me->i2c_port, + me->i2c_addr_flags + PS8811_REG_PAGE1, + PS8811_REG1_USB_BEQ_LEVEL, &val); } while (rv && --tries); if (rv) { CPRINTSUSB("A1: PS8811 retimer not detected!"); - return; + return rv; } CPRINTSUSB("A1: PS8811 retimer detected"); - board_a1_ps8811_retimer_setup(); + rv = board_a1_ps8811_retimer_init(me); + if (rv) + CPRINTSUSB("A1: Error during PS8811 setup rv:%d", rv); + return rv; } -__overridable void board_a1_anx7491_retimer_setup(void) +/* PS8811 is just a type-A USB retimer, reusing mux structure for convience. */ +const struct usb_mux usba1_ps8811 = { + .usb_port = USBA_PORT_A1, + .i2c_port = I2C_PORT_TCPC1, + .i2c_addr_flags = PS8811_I2C_ADDR_FLAGS3, + .board_init = &baseboard_a1_ps8811_retimer_init, +}; + +__overridable enum ec_error_list +board_a1_anx7491_retimer_init(const struct usb_mux *me) { - CPRINTSUSB("A1: ANX7491 retimer using default tuning"); + return EC_SUCCESS; } -static void baseboard_a1_anx7491_retimer_setup(void) +static int baseboard_a1_anx7491_retimer_init(const struct usb_mux *me) { int rv; int tries = 2; @@ -888,29 +901,42 @@ static void baseboard_a1_anx7491_retimer_setup(void) do { int val; - rv = i2c_read8(I2C_PORT_TCPC1, ANX7491_I2C_ADDR0_FLAGS, 0, - &val); + rv = i2c_read8(me->i2c_port, me->i2c_addr_flags, 0, &val); } while (rv && --tries); if (rv) { CPRINTSUSB("A1: ANX7491 retimer not detected!"); - return; + return rv; } CPRINTSUSB("A1: ANX7491 retimer detected"); - board_a1_anx7491_retimer_setup(); + rv = board_a1_anx7491_retimer_init(me); + if (rv) + CPRINTSUSB("A1: Error during ANX7491 setup rv:%d", rv); + return rv; } +/* ANX7491 is just a type-A USB retimer, reusing mux structure for convience. */ +const struct usb_mux usba1_anx7491 = { + .usb_port = USBA_PORT_A1, + .i2c_port = I2C_PORT_TCPC1, + .i2c_addr_flags = ANX7491_I2C_ADDR0_FLAGS, + .board_init = &baseboard_a1_anx7491_retimer_init, +}; + void baseboard_a1_retimer_setup(void) { + struct usb_mux a1_retimer; switch (board_get_usb_a1_retimer()) { case USB_A1_RETIMER_ANX7491: - baseboard_a1_anx7491_retimer_setup(); + a1_retimer = usba1_anx7491; break; case USB_A1_RETIMER_PS8811: - baseboard_a1_ps8811_retimer_setup(); + a1_retimer = usba1_ps8811; break; default: CPRINTSUSB("A1: Unknown retimer!"); + return; } + a1_retimer.board_init(&a1_retimer); } DECLARE_DEFERRED(baseboard_a1_retimer_setup); |