summaryrefslogtreecommitdiff
path: root/board/servo_v4p1
diff options
context:
space:
mode:
authorSam Hurst <shurst@google.com>2020-05-26 10:26:40 -0700
committerCommit Bot <commit-bot@chromium.org>2020-07-30 07:40:10 +0000
commit484f7178604701655ef1a144aaa7465016ad4fc1 (patch)
treecb58cdb71a375195693cc0d0ee9fb2ede97d864b /board/servo_v4p1
parent5fdbcffa491b4965d94dec5f77638cb05e7ae7cc (diff)
downloadchrome-ec-484f7178604701655ef1a144aaa7465016ad4fc1.tar.gz
servo_v4p1: Add BC1.2 functionality
This functionality is available in both RO and RW. BRANCH=none BUG=b:146793000 TEST=make -j buildall Signed-off-by: Sam Hurst <shurst@google.com> Change-Id: Ia442010e7721553a7e155442e32f24ffbf5c4d70 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2216405 Reviewed-by: Brian Nemec <bnemec@chromium.org>
Diffstat (limited to 'board/servo_v4p1')
-rw-r--r--board/servo_v4p1/board.c2
-rw-r--r--board/servo_v4p1/build.mk1
-rw-r--r--board/servo_v4p1/pi3usb9201.c34
-rw-r--r--board/servo_v4p1/pi3usb9201.h59
4 files changed, 96 insertions, 0 deletions
diff --git a/board/servo_v4p1/board.c b/board/servo_v4p1/board.c
index acd797e69a..6148358aff 100644
--- a/board/servo_v4p1/board.c
+++ b/board/servo_v4p1/board.c
@@ -19,6 +19,7 @@
#include "ina231s.h"
#include "ioexpanders.h"
#include "pathsel.h"
+#include "pi3usb9201.h"
#include "queue_policies.h"
#include "registers.h"
#include "spi.h"
@@ -392,6 +393,7 @@ static void board_init(void)
init_ioexpanders();
init_dacs();
init_tusb1064(1);
+ init_pi3usb9201();
/* 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 0c0e45d611..a8d22ccbc3 100644
--- a/board/servo_v4p1/build.mk
+++ b/board/servo_v4p1/build.mk
@@ -18,6 +18,7 @@ board-y=board.o tca6416a.o tca6424a.o
board-y+=ioexpanders.o
board-y+=dacs.o
board-y+=tusb1064.o
+board-y+=pi3usb9201.o
# These files are compiled into RO only
board-ro+=ccd_measure_sbu.o
diff --git a/board/servo_v4p1/pi3usb9201.c b/board/servo_v4p1/pi3usb9201.c
new file mode 100644
index 0000000000..102eaf790d
--- /dev/null
+++ b/board/servo_v4p1/pi3usb9201.c
@@ -0,0 +1,34 @@
+/* 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 "pi3usb9201.h"
+
+#define PI3USB9201_ADDR 0x5f
+
+inline void init_pi3usb9201(void)
+{
+ /*
+ * Write 0x08 (Client mode detection and Enable USB switch auto ON) to
+ * control Reg 2
+ * Write 0x08 (Client Mode) to Control Reg 1
+ */
+ i2c_write16(1, PI3USB9201_ADDR, CTRL_REG1, 0x0808);
+}
+
+inline void write_pi3usb9201(enum pi3usb9201_reg_t reg,
+ enum pi3usb9201_dat_t dat)
+{
+ i2c_write8(1, PI3USB9201_ADDR, reg, dat);
+}
+
+inline uint8_t read_pi3usb9201(enum pi3usb9201_reg_t reg)
+{
+ int tmp;
+
+ i2c_read8(1, PI3USB9201_ADDR, reg, &tmp);
+
+ return tmp;
+}
diff --git a/board/servo_v4p1/pi3usb9201.h b/board/servo_v4p1/pi3usb9201.h
new file mode 100644
index 0000000000..826db8b871
--- /dev/null
+++ b/board/servo_v4p1/pi3usb9201.h
@@ -0,0 +1,59 @@
+/* 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_PI3USB9201_H
+#define __CROS_EC_PI3USB9201_H
+
+enum pi3usb9201_reg_t {
+ CTRL_REG1,
+ CTRL_REG2,
+ CLIENT_STATUS,
+ HOST_STATUS
+};
+
+enum pi3usb9201_dat_t {
+ POWER_DOWN = 0x0,
+ SDP_HOST_MODE = 0x2,
+ DCP_HOST_MODE = 0x4,
+ CDP_HOST_MODE = 0x6,
+ CLIENT_MODE = 0x8,
+ USB_PATH_ON = 0xe
+};
+
+
+/* Client Status bits */
+#define CS_DCP BIT(7)
+#define CS_SDP BIT(6)
+#define CS_CDP BIT(5)
+#define CS_1A_CHARGER BIT(3)
+#define CS_2A_CHARGER BIT(2)
+#define CS_2_4A_CHARGER BIT(1)
+
+/* Host Status bits */
+#define HS_USB_UNPLUGGED BIT(2)
+#define HS_USB_PLUGGED BIT(1)
+#define HS_BC1_2 BIT(0)
+
+/**
+ * Selects Client Mode and client mode detection
+ */
+void init_pi3usb9201(void);
+
+/**
+ * Write a byte to the pi3usb9201
+ *
+ * @param reg register to write
+ * @param dat data to write to the register
+ */
+void write_pi3usb9201(enum pi3usb9201_reg_t reg, enum pi3usb9201_dat_t dat);
+
+/**
+ * Read a byte from the pi3usb9201
+ *
+ * @param return data byte read from pi3usb9201
+ */
+uint8_t read_pi3usb9201(enum pi3usb9201_reg_t reg);
+
+#endif /* __CROS_EC_PI3USB9201_H */