From 8a07d5e2f8af6b5d0edab1c5b63f1a278302feaf Mon Sep 17 00:00:00 2001 From: Sam Hurst Date: Tue, 14 Jul 2020 12:01:09 -0700 Subject: servo_v4p1: Add TUSB1064 functionality This functionality is available in both RO and RW. BRANCH=none BUG=b:146793000 TEST=make -j buildall Signed-off-by: Sam Hurst Change-Id: I2161e5326a1869e092d0c6dd15ad45523f13ca05 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2298268 Reviewed-by: Wai-Hong Tam (cherry picked from commit c556adf8d3689299d4da24bdfa36d09e23f73843) Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2332246 --- board/servo_v4p1/board.c | 2 ++ board/servo_v4p1/build.mk | 1 + board/servo_v4p1/tusb1064.c | 42 +++++++++++++++++++++++++++++++++++++ board/servo_v4p1/tusb1064.h | 51 +++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 96 insertions(+) create mode 100644 board/servo_v4p1/tusb1064.c create mode 100644 board/servo_v4p1/tusb1064.h diff --git a/board/servo_v4p1/board.c b/board/servo_v4p1/board.c index d573308712..4a389e30ca 100644 --- a/board/servo_v4p1/board.c +++ b/board/servo_v4p1/board.c @@ -24,6 +24,7 @@ #include "system.h" #include "task.h" #include "timer.h" +#include "tusb1064.h" #include "update_fw.h" #include "usart-stm32f0.h" #include "usart_tx_dma.h" @@ -324,6 +325,7 @@ static void board_init(void) init_ioexpanders(); init_dacs(); + init_tusb1064(1); /* Clear BBRAM, we don't want any PD state carried over on reset. */ system_set_bbram(SYSTEM_BBRAM_IDX_PD0, 0); diff --git a/board/servo_v4p1/build.mk b/board/servo_v4p1/build.mk index 7c4e8b030f..38e9fb9469 100644 --- a/board/servo_v4p1/build.mk +++ b/board/servo_v4p1/build.mk @@ -17,6 +17,7 @@ test-list-y= board-y=board.o tca6416a.o tca6424a.o board-y+=ioexpanders.o board-y+=dacs.o +board-y+=tusb1064.o # These files are compiled into RO only board-ro+=ccd_measure_sbu.o diff --git a/board/servo_v4p1/tusb1064.c b/board/servo_v4p1/tusb1064.c new file mode 100644 index 0000000000..30816da11b --- /dev/null +++ b/board/servo_v4p1/tusb1064.c @@ -0,0 +1,42 @@ +/* Copyright 2020 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. + */ + +#include "i2c.h" +#include "tusb1064.h" +#include "ioexpanders.h" + +int init_tusb1064(int port) +{ + uint8_t val; + + /* Enable the TUSB1064 redriver */ + cmux_en(1); + + /* Disconnect USB3.1 and DP */ + val = tusb1064_read_byte(port, TUSB1064_REG_GENERAL); + if (val < 0) + return EC_ERROR_INVAL; + + val &= ~REG_GENERAL_CTLSEL_2DP_AND_USB3; + if (tusb1064_write_byte(port, TUSB1064_REG_GENERAL, val)) + return EC_ERROR_INVAL; + + return EC_SUCCESS; +} + +int tusb1064_write_byte(int port, uint8_t reg, uint8_t val) +{ + return i2c_write8(port, TUSB1064_ADDR_FLAGS, reg, val); +} + +int tusb1064_read_byte(int port, uint8_t reg) +{ + int tmp; + + if (i2c_read8(port, TUSB1064_ADDR_FLAGS, reg, &tmp)) + return -1; + + return tmp; +} diff --git a/board/servo_v4p1/tusb1064.h b/board/servo_v4p1/tusb1064.h new file mode 100644 index 0000000000..a6ca77b7b7 --- /dev/null +++ b/board/servo_v4p1/tusb1064.h @@ -0,0 +1,51 @@ +/* Copyright 2020 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 __CROS_EC_TUSB1064_H +#define __CROS_EC_TUSB1064_H + +#include + +#define TUSB1064_ADDR_FLAGS 0x12 + +#define TUSB1064_REG_GENERAL 0x0a +#define REG_GENERAL_CTLSEL_DISABLE 0x00 +#define REG_GENERAL_CTLSEL_USB3 0x01 +#define REG_GENERAL_CTLSEL_4DP_LANES 0x02 +#define REG_GENERAL_CTLSEL_2DP_AND_USB3 0x03 +#define REG_GENERAL_FLIPSEL BIT(2) +#define REG_GENERAL_DP_ENABLE_CTRL BIT(3) +#define REG_GENERAL_EQ_OVERRIDE BIT(4) + +/* + * Initialize the TUSB1064 + * + * @param port The I2C port of TUSB1064 + * @return EC_SUCCESS or EC_ERROR_* + */ +int init_tusb1064(int port); + +/* + * Write a byte to the TUSB1064 + * + * @param port The I2C port of TUSB1064. + * @param reg Register to write byte to. + * @param val Value to write to TUSB1064. + * + * @return EC_SUCCESS, or EC_ERROR_* on error. + */ +int tusb1064_write_byte(int port, uint8_t reg, uint8_t val); + +/* + * Read a byte from TUSB1064 + * + * @param port The I2C port of TUSB1064. + * @param reg Register to read byte from. + * + * @return byte value, or -1 on error. + */ +int tusb1064_read_byte(int port, uint8_t reg); + +#endif /* __CROS_EC_TUSB1064_H */ -- cgit v1.2.1