summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShawn Nematbakhsh <shawnn@chromium.org>2015-06-09 14:29:09 -0700
committerChromeOS Commit Bot <chromeos-commit-bot@chromium.org>2015-06-12 16:37:39 +0000
commit5b7cfac64e971a7e925d17a8b33e651a01e71707 (patch)
tree72ee34fae7f6bee5d2c8d781e5256fbceee3f8e1
parent9941f088d7a56ba4ba7396d9221612b00143a3cc (diff)
downloadchrome-ec-5b7cfac64e971a7e925d17a8b33e651a01e71707.tar.gz
usb: pi3usb9281: Allow flexible chip configurations
Previously we supported using a single pi3usb9281 chip, or using two chips on the same i2c bus behind a mux. Now that we need to support a third configuration of multiple chips on different busses, it makes sense to be able to configure the configuration freely at the board level. BUG=chrome-os-partner:40920 TEST=Manual on samus_pd. Plug USB charger, verify detection is correct on both charge ports. BRANCH=None Change-Id: I120dcb1c3ceb6f013b92407effcd8cb66e7ffcce Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/276511 Reviewed-by: Alec Berg <alecaberg@chromium.org>
-rw-r--r--board/oak/board.c19
-rw-r--r--board/oak/board.h4
-rw-r--r--board/oak/ec.tasklist2
-rw-r--r--board/ryu/board.c11
-rw-r--r--board/ryu/board.h2
-rw-r--r--board/ryu_p4p5/board.c11
-rw-r--r--board/ryu_p4p5/board.h2
-rw-r--r--board/samus_pd/board.c28
-rw-r--r--board/samus_pd/board.h4
-rw-r--r--common/usb_charger.c25
-rw-r--r--driver/pi3usb9281.h45
-rw-r--r--driver/usb_switch_pi3usb9281.c151
-rw-r--r--include/config.h4
-rw-r--r--include/usb_charge.h8
14 files changed, 190 insertions, 126 deletions
diff --git a/board/oak/board.c b/board/oak/board.c
index 1877c7c0c7..2f0373e672 100644
--- a/board/oak/board.c
+++ b/board/oak/board.c
@@ -108,6 +108,24 @@ const struct i2c_port_t i2c_ports[] = {
const unsigned int i2c_ports_used = ARRAY_SIZE(i2c_ports);
+struct mutex pericom_mux_lock;
+struct pi3usb9281_config pi3usb9281_chips[] = {
+ {
+ .i2c_port = I2C_PORT_PERICOM,
+ .mux_gpio = GPIO_USB_C_BC12_SEL,
+ .mux_gpio_level = 0,
+ .mux_lock = &pericom_mux_lock,
+ },
+ {
+ .i2c_port = I2C_PORT_PERICOM,
+ .mux_gpio = GPIO_USB_C_BC12_SEL,
+ .mux_gpio_level = 1,
+ .mux_lock = &pericom_mux_lock,
+ },
+};
+BUILD_ASSERT(ARRAY_SIZE(pi3usb9281_chips) ==
+ CONFIG_USB_SWITCH_PI3USB9281_CHIP_COUNT);
+
static int discharging_on_ac;
/**
@@ -185,6 +203,7 @@ static void board_init(void)
&charge_none);
/* Initialize VBUS supplier based on VBUS */
+ /* TODO(crbug.com/498974): Don't do i2c from hook_init. */
bc12_status = pi3usb9281_get_charger_status(i);
charge_sel = PI3USB9281_CHG_STATUS_ANY(bc12_status) ?
&charge_vbus : &charge_none;
diff --git a/board/oak/board.h b/board/oak/board.h
index e00ce7be50..f10c6dabe7 100644
--- a/board/oak/board.h
+++ b/board/oak/board.h
@@ -93,8 +93,7 @@
/* BC 1.2 charger */
#define CONFIG_USB_SWITCH_PI3USB30532
#define CONFIG_USB_SWITCH_PI3USB9281
-#undef CONFIG_USB_SWITCH_PI3USB9281_MUX_GPIO
-#define CONFIG_USB_SWITCH_PI3USB9281_MUX_GPIO GPIO_USB_C_BC12_SEL
+#define CONFIG_USB_SWITCH_PI3USB9281_CHIP_COUNT 2
#ifndef __ASSEMBLER__
@@ -108,6 +107,7 @@
#define I2C_PORT_MASTER 0
#define I2C_PORT_BATTERY 0
#define I2C_PORT_CHARGER 0
+#define I2C_PORT_PERICOM 0
#define I2C_PORT_PD_MCU 1
#define I2C_PORT_USB_SWITCH 1
#define I2C_PORT_TCPC 1
diff --git a/board/oak/ec.tasklist b/board/oak/ec.tasklist
index 35c72c3acf..35b64ed622 100644
--- a/board/oak/ec.tasklist
+++ b/board/oak/ec.tasklist
@@ -26,3 +26,5 @@
TASK_NOTEST(KEYSCAN, keyboard_scan_task, NULL, TASK_STACK_SIZE) \
TASK_ALWAYS(PD_C0, pd_task, NULL, LARGER_TASK_STACK_SIZE) \
TASK_ALWAYS(PD_C1, pd_task, NULL, LARGER_TASK_STACK_SIZE)
+
+/* TODO: Add pericom USB charger tasks */
diff --git a/board/ryu/board.c b/board/ryu/board.c
index 0c15c674b7..348dd55c9f 100644
--- a/board/ryu/board.c
+++ b/board/ryu/board.c
@@ -160,6 +160,15 @@ USB_STREAM_CONFIG(sh_usb,
sh_usb_to_usart,
sh_usart_to_usb)
+struct pi3usb9281_config pi3usb9281_chips[] = {
+ {
+ .i2c_port = I2C_PORT_PERICOM,
+ .mux_lock = NULL,
+ }
+};
+BUILD_ASSERT(ARRAY_SIZE(pi3usb9281_chips) ==
+ CONFIG_USB_SWITCH_PI3USB9281_CHIP_COUNT);
+
/* Initialize board. */
static void board_init(void)
{
@@ -188,8 +197,6 @@ static void board_init(void)
/* Enable pericom BC1.2 interrupts. */
gpio_enable_interrupt(GPIO_USBC_BC12_INT_L);
- pi3usb9281_set_interrupt_mask(0, 0xff);
- pi3usb9281_enable_interrupts(0);
/*
* Determine recovery mode is requested by the power, volup, and
diff --git a/board/ryu/board.h b/board/ryu/board.h
index 2cc8fa4e61..72cc5f32a8 100644
--- a/board/ryu/board.h
+++ b/board/ryu/board.h
@@ -37,6 +37,7 @@
#define CONFIG_USB_PD_TCPC
#define CONFIG_USB_PD_TCPM_STUB
#define CONFIG_USB_SWITCH_PI3USB9281
+#define CONFIG_USB_SWITCH_PI3USB9281_CHIP_COUNT 1
#define CONFIG_USBC_SS_MUX
#define CONFIG_USBC_VCONN
#define CONFIG_USBC_VCONN_SWAP
@@ -85,6 +86,7 @@
#define I2C_PORT_BATTERY I2C_PORT_MASTER
#define I2C_PORT_LIGHTBAR I2C_PORT_MASTER
#define I2C_PORT_ACCEL I2C_PORT_MASTER
+#define I2C_PORT_PERICOM I2C_PORT_MASTER
#define BMM150_I2C_ADDRESS BMM150_ADDR0
/* slave address for host commands */
diff --git a/board/ryu_p4p5/board.c b/board/ryu_p4p5/board.c
index 4ce21be02a..7a333610a1 100644
--- a/board/ryu_p4p5/board.c
+++ b/board/ryu_p4p5/board.c
@@ -158,6 +158,15 @@ USB_STREAM_CONFIG(sh_usb,
sh_usb_to_usart,
sh_usart_to_usb)
+struct pi3usb9281_config pi3usb9281_chips[] = {
+ {
+ .i2c_port = I2C_PORT_PERICOM,
+ .mux_lock = NULL,
+ }
+};
+BUILD_ASSERT(ARRAY_SIZE(pi3usb9281_chips) ==
+ CONFIG_USB_SWITCH_PI3USB9281_CHIP_COUNT);
+
/* Initialize board. */
static void board_init(void)
{
@@ -186,8 +195,6 @@ static void board_init(void)
/* Enable pericom BC1.2 interrupts. */
gpio_enable_interrupt(GPIO_USBC_BC12_INT_L);
- pi3usb9281_set_interrupt_mask(0, 0xff);
- pi3usb9281_enable_interrupts(0);
/*
* Determine recovery mode is requested by the power, volup, and
diff --git a/board/ryu_p4p5/board.h b/board/ryu_p4p5/board.h
index 4d039b2ea0..93eda6f119 100644
--- a/board/ryu_p4p5/board.h
+++ b/board/ryu_p4p5/board.h
@@ -34,6 +34,7 @@
#define CONFIG_USB_PD_TCPC
#define CONFIG_USB_PD_TCPM_STUB
#define CONFIG_USB_SWITCH_PI3USB9281
+#define CONFIG_USB_SWITCH_PI3USB9281_CHIP_COUNT 1
#define CONFIG_USBC_SS_MUX
#define CONFIG_USBC_VCONN
#define CONFIG_USBC_VCONN_SWAP
@@ -82,6 +83,7 @@
#define I2C_PORT_CHARGER I2C_PORT_MASTER
#define I2C_PORT_BATTERY I2C_PORT_MASTER
#define I2C_PORT_LIGHTBAR I2C_PORT_MASTER
+#define I2C_PORT_PERICOM I2C_PORT_MASTER
/* slave address for host commands */
#ifdef HAS_TASK_HOSTCMD
diff --git a/board/samus_pd/board.c b/board/samus_pd/board.c
index eee86c4a8b..161fc135fc 100644
--- a/board/samus_pd/board.c
+++ b/board/samus_pd/board.c
@@ -24,6 +24,7 @@
#include "system.h"
#include "task.h"
#include "usb.h"
+#include "usb_charge.h"
#include "usb_pd.h"
#include "util.h"
@@ -77,6 +78,24 @@ const struct pwm_t pwm_channels[] = {
};
BUILD_ASSERT(ARRAY_SIZE(pwm_channels) == PWM_CH_COUNT);
+struct mutex pericom_mux_lock;
+struct pi3usb9281_config pi3usb9281_chips[] = {
+ {
+ .i2c_port = I2C_PORT_PERICOM,
+ .mux_gpio = GPIO_USB_C_BC12_SEL,
+ .mux_gpio_level = 0,
+ .mux_lock = &pericom_mux_lock,
+ },
+ {
+ .i2c_port = I2C_PORT_PERICOM,
+ .mux_gpio = GPIO_USB_C_BC12_SEL,
+ .mux_gpio_level = 1,
+ .mux_lock = &pericom_mux_lock,
+ },
+};
+BUILD_ASSERT(ARRAY_SIZE(pi3usb9281_chips) ==
+ CONFIG_USB_SWITCH_PI3USB9281_CHIP_COUNT);
+
static void pericom_port0_reenable_interrupts(void)
{
CPRINTS("VBUS p0 %d", gpio_get_level(GPIO_USB_C0_VBUS_WAKE));
@@ -309,10 +328,6 @@ static void board_init(void)
/* Enable pericom BC1.2 interrupts. */
gpio_enable_interrupt(GPIO_USB_C0_BC12_INT_L);
gpio_enable_interrupt(GPIO_USB_C1_BC12_INT_L);
- pi3usb9281_set_interrupt_mask(0, 0xff);
- pi3usb9281_set_interrupt_mask(1, 0xff);
- pi3usb9281_enable_interrupts(0);
- pi3usb9281_enable_interrupts(1);
/* Determine initial chipset state */
if (slp_s5 && slp_s3) {
@@ -555,10 +570,7 @@ int board_set_active_charge_port(int charge_port)
int is_real_port = (charge_port >= 0 &&
charge_port < CONFIG_USB_PD_PORT_COUNT);
/* check if we are source vbus on that port */
- int source = gpio_get_level(charge_port == 0 ? GPIO_USB_C0_5V_EN :
- GPIO_USB_C1_5V_EN);
-
- if (is_real_port && source) {
+ if (is_real_port && usb_charger_port_is_sourcing_vbus(charge_port)) {
CPRINTS("Skip enable p%d", charge_port);
return EC_ERROR_INVAL;
}
diff --git a/board/samus_pd/board.h b/board/samus_pd/board.h
index c3dcd49ca0..8e72a259ac 100644
--- a/board/samus_pd/board.h
+++ b/board/samus_pd/board.h
@@ -61,8 +61,7 @@
#define CONFIG_USB_PD_TCPC
#define CONFIG_USB_PD_TCPM_STUB
#define CONFIG_USB_SWITCH_PI3USB9281
-#undef CONFIG_USB_SWITCH_PI3USB9281_MUX_GPIO
-#define CONFIG_USB_SWITCH_PI3USB9281_MUX_GPIO GPIO_USB_C_BC12_SEL
+#define CONFIG_USB_SWITCH_PI3USB9281_CHIP_COUNT 2
#define CONFIG_USBC_SS_MUX_DFP_ONLY
#define CONFIG_USBC_SS_MUX
#define CONFIG_USBC_VCONN
@@ -79,6 +78,7 @@
#define I2C_PORT_MASTER 1
#define I2C_PORT_SLAVE 0
#define I2C_PORT_EC I2C_PORT_SLAVE
+#define I2C_PORT_PERICOM I2C_PORT_MASTER
/* slave address for host commands */
#ifdef HAS_TASK_HOSTCMD
diff --git a/common/usb_charger.c b/common/usb_charger.c
index bb85fc3c7f..b003f415e4 100644
--- a/common/usb_charger.c
+++ b/common/usb_charger.c
@@ -16,6 +16,7 @@
#include "pi3usb9281.h"
#include "task.h"
#include "timer.h"
+#include "usb_charge.h"
#include "usb_pd.h"
/* Wait after a charger is detected to debounce pin contact order */
@@ -26,24 +27,36 @@
*/
#define USB_CHG_RESET_DELAY_MS 100
+int usb_charger_port_is_sourcing_vbus(int port)
+{
+ if (port == 0)
+ return gpio_get_level(GPIO_USB_C0_5V_EN);
+#if CONFIG_USB_PD_PORT_COUNT >= 2
+ else if (port == 1)
+ return gpio_get_level(GPIO_USB_C1_5V_EN);
+#endif
+ /* Not a valid port */
+ return 0;
+}
+
void usb_charger_task(void)
{
int port = (task_get_current() == TASK_ID_USB_CHG_P0 ? 0 : 1);
-#if (CONFIG_USB_PD_PORT_COUNT == 1)
- int vbus_source = GPIO_USB_C0_5V_EN;
-#else
- int vbus_source = (port == 0 ? GPIO_USB_C0_5V_EN : GPIO_USB_C1_5V_EN);
-#endif
+
int device_type, charger_status;
struct charge_port_info charge;
int type;
+
charge.voltage = USB_BC12_CHARGE_VOLTAGE;
+ /* Initialize chip and enable interrupts */
+ pi3usb9281_init(port);
+
while (1) {
/* Read interrupt register to clear on chip */
pi3usb9281_get_interrupts(port);
- if (gpio_get_level(vbus_source)) {
+ if (usb_charger_port_is_sourcing_vbus(port)) {
/* If we're sourcing VBUS then we're not charging */
device_type = charger_status = 0;
} else {
diff --git a/driver/pi3usb9281.h b/driver/pi3usb9281.h
index 56b126c1e3..7a23a869b3 100644
--- a/driver/pi3usb9281.h
+++ b/driver/pi3usb9281.h
@@ -56,46 +56,55 @@
/* Check if charge status has any connection */
#define PI3USB9281_CHG_STATUS_ANY(x) (((x) & 0x1f) > 1)
-/* Read PI3USB9281 register. */
-uint8_t pi3usb9281_read(uint8_t chip_idx, uint8_t reg);
-
-/* Write PI3USB9281 register. */
-int pi3usb9281_write(uint8_t chip_idx, uint8_t reg, uint8_t val);
+/* Define configuration of one pi3usb9281 part */
+struct pi3usb9281_config {
+ /* i2c port that chip resides on */
+ int i2c_port;
+ /* GPIO for chip selection in muxed configuration */
+ enum gpio_signal mux_gpio;
+ /* Logic level of mux_gpio to select chip */
+ int mux_gpio_level;
+ /* Mutex to lock access to mux gpio or NULL if no mux exists */
+ struct mutex *mux_lock;
+};
+
+/* Configuration struct defined at board level */
+extern struct pi3usb9281_config pi3usb9281_chips[];
+
+/* Initialize chip and enable interrupts */
+void pi3usb9281_init(int port);
/* Enable interrupts. */
-int pi3usb9281_enable_interrupts(uint8_t chip_idx);
+int pi3usb9281_enable_interrupts(int port);
/* Disable all interrupts. */
-int pi3usb9281_disable_interrupts(uint8_t chip_idx);
+int pi3usb9281_disable_interrupts(int port);
/* Set interrupt mask. */
-int pi3usb9281_set_interrupt_mask(uint8_t chip_idx, uint8_t mask);
+int pi3usb9281_set_interrupt_mask(int port, uint8_t mask);
/* Get and clear current interrupt status. */
-int pi3usb9281_get_interrupts(uint8_t chip_idx);
-
-/* Get but keep interrupt status. */
-int pi3usb9281_peek_interrupts(uint8_t chip_idx);
+int pi3usb9281_get_interrupts(int port);
/* Get attached device type. */
-int pi3usb9281_get_device_type(uint8_t chip_idx);
+int pi3usb9281_get_device_type(int port);
/* Get attached charger status. */
-int pi3usb9281_get_charger_status(uint8_t chip_idx);
+int pi3usb9281_get_charger_status(int port);
/* Get charger current limit based on device type and charger status. */
int pi3usb9281_get_ilim(int device_type, int charger_status);
/* Set switch configuration to manual. */
-int pi3usb9281_set_switch_manual(uint8_t chip_idx, int val);
+int pi3usb9281_set_switch_manual(int port, int val);
/* Set bits to enable pins in manual switch register. */
-int pi3usb9281_set_pins(uint8_t chip_idx, uint8_t mask);
+int pi3usb9281_set_pins(int port, uint8_t mask);
/* Set D+/D-/Vbus switches to open or closed/auto-control. */
-int pi3usb9281_set_switches(uint8_t chip_idx, int open);
+int pi3usb9281_set_switches(int port, int open);
/* Reset PI3USB9281. */
-int pi3usb9281_reset(uint8_t chip_idx);
+int pi3usb9281_reset(int port);
#endif /* PI3USB9281_H */
diff --git a/driver/usb_switch_pi3usb9281.c b/driver/usb_switch_pi3usb9281.c
index 1841a9909a..063d7d3983 100644
--- a/driver/usb_switch_pi3usb9281.c
+++ b/driver/usb_switch_pi3usb9281.c
@@ -24,35 +24,34 @@
/* Delay values */
#define PI3USB9281_SW_RESET_DELAY 20
-#ifdef CONFIG_USB_SWITCH_PI3USB9281_MUX_GPIO
-#define PI3USB9281_COUNT 2
-struct mutex mux_lock;
-static inline void select_chip(uint8_t chip_idx)
+static void select_chip(int port)
{
- mutex_lock(&mux_lock);
- gpio_set_level(CONFIG_USB_SWITCH_PI3USB9281_MUX_GPIO, chip_idx);
+ struct pi3usb9281_config *chip = &pi3usb9281_chips[port];
+ ASSERT(port < CONFIG_USB_SWITCH_PI3USB9281_CHIP_COUNT);
+
+ if (chip->mux_lock) {
+ mutex_lock(chip->mux_lock);
+ gpio_set_level(chip->mux_gpio, chip->mux_gpio_level);
+ }
}
-static inline void unselect_chip(void)
+static void unselect_chip(int port)
{
- /* Just release the mutex, no need to change the mux gpio */
- mutex_unlock(&mux_lock);
-}
-#else
-#define PI3USB9281_COUNT 1
-#define select_chip(x)
-#define unselect_chip()
-#endif
+ struct pi3usb9281_config *chip = &pi3usb9281_chips[port];
-static int saved_interrupts[PI3USB9281_COUNT];
+ if (chip->mux_lock)
+ /* Just release the mutex, no need to change the mux gpio */
+ mutex_unlock(chip->mux_lock);
+}
-uint8_t pi3usb9281_read(uint8_t chip_idx, uint8_t reg)
+static uint8_t pi3usb9281_read(int port, uint8_t reg)
{
+ struct pi3usb9281_config *chip = &pi3usb9281_chips[port];
int res, val;
- select_chip(chip_idx);
- res = i2c_read8(I2C_PORT_MASTER, PI3USB9281_I2C_ADDR, reg, &val);
- unselect_chip();
+ select_chip(port);
+ res = i2c_read8(chip->i2c_port, PI3USB9281_I2C_ADDR, reg, &val);
+ unselect_chip(port);
if (res)
return 0xee;
@@ -60,13 +59,14 @@ uint8_t pi3usb9281_read(uint8_t chip_idx, uint8_t reg)
return val;
}
-int pi3usb9281_write(uint8_t chip_idx, uint8_t reg, uint8_t val)
+static int pi3usb9281_write(int port, uint8_t reg, uint8_t val)
{
+ struct pi3usb9281_config *chip = &pi3usb9281_chips[port];
int res;
- select_chip(chip_idx);
- res = i2c_write8(I2C_PORT_MASTER, PI3USB9281_I2C_ADDR, reg, val);
- unselect_chip();
+ select_chip(port);
+ res = i2c_write8(chip->i2c_port, PI3USB9281_I2C_ADDR, reg, val);
+ unselect_chip(port);
if (res)
CPRINTS("PI3USB9281 I2C write failed");
@@ -74,70 +74,68 @@ int pi3usb9281_write(uint8_t chip_idx, uint8_t reg, uint8_t val)
}
/* Write control register, taking care to correctly set reserved bits. */
-static int pi3usb9281_write_ctrl(uint8_t chip_idx, uint8_t ctrl)
+static int pi3usb9281_write_ctrl(int port, uint8_t ctrl)
{
- return pi3usb9281_write(chip_idx, PI3USB9281_REG_CONTROL,
+ return pi3usb9281_write(port, PI3USB9281_REG_CONTROL,
(ctrl & PI3USB9281_CTRL_MASK) |
PI3USB9281_CTRL_RSVD_1);
}
-int pi3usb9281_enable_interrupts(uint8_t chip_idx)
+void pi3usb9281_init(int port)
{
- uint8_t ctrl = pi3usb9281_read(chip_idx, PI3USB9281_REG_CONTROL);
+ uint8_t dev_id;
+
+ dev_id = pi3usb9281_read(port, PI3USB9281_REG_DEV_ID);
+
+ if (dev_id != PI3USB9281_DEV_ID && dev_id != PI3USB9281_DEV_ID_A)
+ CPRINTS("PI3USB9281 invalid ID 0x%02x", dev_id);
+
+ pi3usb9281_set_interrupt_mask(port, 0xff);
+ pi3usb9281_enable_interrupts(port);
+}
+
+
+int pi3usb9281_enable_interrupts(int port)
+{
+ uint8_t ctrl = pi3usb9281_read(port, PI3USB9281_REG_CONTROL);
if (ctrl == 0xee)
return EC_ERROR_UNKNOWN;
- return pi3usb9281_write_ctrl(chip_idx, ctrl & ~PI3USB9281_CTRL_INT_DIS);
+ return pi3usb9281_write_ctrl(port, ctrl & ~PI3USB9281_CTRL_INT_DIS);
}
-int pi3usb9281_disable_interrupts(uint8_t chip_idx)
+int pi3usb9281_disable_interrupts(int port)
{
- uint8_t ctrl = pi3usb9281_read(chip_idx, PI3USB9281_REG_CONTROL);
+ uint8_t ctrl = pi3usb9281_read(port, PI3USB9281_REG_CONTROL);
int rv;
if (ctrl == 0xee)
return EC_ERROR_UNKNOWN;
- rv = pi3usb9281_write_ctrl(chip_idx, ctrl | PI3USB9281_CTRL_INT_DIS);
- pi3usb9281_get_interrupts(chip_idx);
+ rv = pi3usb9281_write_ctrl(port, ctrl | PI3USB9281_CTRL_INT_DIS);
+ pi3usb9281_get_interrupts(port);
return rv;
}
-int pi3usb9281_set_interrupt_mask(uint8_t chip_idx, uint8_t mask)
+int pi3usb9281_set_interrupt_mask(int port, uint8_t mask)
{
- return pi3usb9281_write(chip_idx, PI3USB9281_REG_INT_MASK, ~mask);
+ return pi3usb9281_write(port, PI3USB9281_REG_INT_MASK, ~mask);
}
-int pi3usb9281_get_interrupts(uint8_t chip_idx)
+int pi3usb9281_get_interrupts(int port)
{
- int ret = pi3usb9281_peek_interrupts(chip_idx);
-
- if (chip_idx >= PI3USB9281_COUNT)
- return EC_ERROR_PARAM1;
-
- saved_interrupts[chip_idx] = 0;
- return ret;
-}
-
-int pi3usb9281_peek_interrupts(uint8_t chip_idx)
-{
- if (chip_idx >= PI3USB9281_COUNT)
- return EC_ERROR_PARAM1;
-
- saved_interrupts[chip_idx] |= pi3usb9281_read(chip_idx,
- PI3USB9281_REG_INT);
- return saved_interrupts[chip_idx];
+ return pi3usb9281_read(port, PI3USB9281_REG_INT);
}
-int pi3usb9281_get_device_type(uint8_t chip_idx)
+int pi3usb9281_get_device_type(int port)
{
- return pi3usb9281_read(chip_idx, PI3USB9281_REG_DEV_TYPE) & 0x77;
+ return pi3usb9281_read(port, PI3USB9281_REG_DEV_TYPE) & 0x77;
}
-int pi3usb9281_get_charger_status(uint8_t chip_idx)
+int pi3usb9281_get_charger_status(int port)
{
- return pi3usb9281_read(chip_idx, PI3USB9281_REG_CHG_STATUS) & 0x1f;
+ return pi3usb9281_read(port, PI3USB9281_REG_CHG_STATUS) & 0x1f;
}
int pi3usb9281_get_ilim(int device_type, int charger_status)
@@ -162,18 +160,18 @@ int pi3usb9281_get_ilim(int device_type, int charger_status)
return current_limit_ma;
}
-int pi3usb9281_get_vbus(uint8_t chip_idx)
+int pi3usb9281_get_vbus(int port)
{
- int vbus = pi3usb9281_read(chip_idx, PI3USB9281_REG_VBUS);
+ int vbus = pi3usb9281_read(port, PI3USB9281_REG_VBUS);
if (vbus == 0xee)
return EC_ERROR_UNKNOWN;
return !!(vbus & 0x2);
}
-int pi3usb9281_reset(uint8_t chip_idx)
+int pi3usb9281_reset(int port)
{
- int rv = pi3usb9281_write(chip_idx, PI3USB9281_REG_RESET, 0x1);
+ int rv = pi3usb9281_write(port, PI3USB9281_REG_RESET, 0x1);
if (!rv)
/* Reset takes ~15ms. Wait for 20ms to be safe. */
@@ -182,9 +180,9 @@ int pi3usb9281_reset(uint8_t chip_idx)
return rv;
}
-int pi3usb9281_set_switch_manual(uint8_t chip_idx, int val)
+int pi3usb9281_set_switch_manual(int port, int val)
{
- uint8_t ctrl = pi3usb9281_read(chip_idx, PI3USB9281_REG_CONTROL);
+ uint8_t ctrl = pi3usb9281_read(port, PI3USB9281_REG_CONTROL);
if (ctrl == 0xee)
return EC_ERROR_UNKNOWN;
@@ -194,17 +192,17 @@ int pi3usb9281_set_switch_manual(uint8_t chip_idx, int val)
else
ctrl |= PI3USB9281_CTRL_AUTO;
- return pi3usb9281_write_ctrl(chip_idx, ctrl);
+ return pi3usb9281_write_ctrl(port, ctrl);
}
-int pi3usb9281_set_pins(uint8_t chip_idx, uint8_t val)
+int pi3usb9281_set_pins(int port, uint8_t val)
{
- return pi3usb9281_write(chip_idx, PI3USB9281_REG_MANUAL, val);
+ return pi3usb9281_write(port, PI3USB9281_REG_MANUAL, val);
}
-int pi3usb9281_set_switches(uint8_t chip_idx, int open)
+int pi3usb9281_set_switches(int port, int open)
{
- uint8_t ctrl = pi3usb9281_read(chip_idx, PI3USB9281_REG_CONTROL);
+ uint8_t ctrl = pi3usb9281_read(port, PI3USB9281_REG_CONTROL);
if (ctrl == 0xee)
return EC_ERROR_UNKNOWN;
@@ -214,20 +212,5 @@ int pi3usb9281_set_switches(uint8_t chip_idx, int open)
else
ctrl |= PI3USB9281_CTRL_SWITCH_AUTO;
- return pi3usb9281_write_ctrl(chip_idx, ctrl);
-}
-
-static void pi3usb9281_init(void)
-{
- uint8_t dev_id;
- int i;
-
- for (i = 0; i < PI3USB9281_COUNT; i++) {
- dev_id = pi3usb9281_read(i, PI3USB9281_REG_DEV_ID);
-
- if (dev_id != PI3USB9281_DEV_ID &&
- dev_id != PI3USB9281_DEV_ID_A)
- CPRINTS("PI3USB9281[%d] invalid ID 0x%02x", i, dev_id);
- }
+ return pi3usb9281_write_ctrl(port, ctrl);
}
-DECLARE_HOOK(HOOK_INIT, pi3usb9281_init, HOOK_PRIO_LAST);
diff --git a/include/config.h b/include/config.h
index 8ceba6036b..c0c553fd38 100644
--- a/include/config.h
+++ b/include/config.h
@@ -1414,8 +1414,8 @@
/* Support the Pericom PI3USB9281 I2C USB switch */
#undef CONFIG_USB_SWITCH_PI3USB9281
-/* Select GPIO MUX for Pericom PI3USB9281 I2C USB switch */
-#undef CONFIG_USB_SWITCH_PI3USB9281_MUX_GPIO
+/* Number of Pericom PI3USB9281 chips present in system */
+#undef CONFIG_USB_SWITCH_PI3USB9281_CHIP_COUNT
/*****************************************************************************/
/* USB GPIO config */
diff --git a/include/usb_charge.h b/include/usb_charge.h
index e67aba482e..f95e69e91d 100644
--- a/include/usb_charge.h
+++ b/include/usb_charge.h
@@ -42,4 +42,12 @@ int usb_charge_set_mode(int usb_port_id, enum usb_charge_mode mode);
*/
int usb_charge_ports_enabled(void);
+/**
+ * Returns true if the passed port is a power source.
+ *
+ * @param port Port number.
+ * @return True if port is sourcing vbus.
+ */
+int usb_charger_port_is_sourcing_vbus(int port);
+
#endif /* __CROS_EC_USB_CHARGE_H */