summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVijay Hiremath <vijay.p.hiremath@intel.com>2016-10-26 17:40:57 -0700
committerchrome-bot <chrome-bot@chromium.org>2016-10-27 19:28:53 -0700
commit799c272e282a4727da949940828d815f11c526db (patch)
treece54acaa1222a08ed6e761636122087e8eef5e53
parentb6937caeeb3f4642cfdc0bca52a890b30b81e9a4 (diff)
downloadchrome-ec-799c272e282a4727da949940828d815f11c526db.tar.gz
BD9995X: Disable input to port when sourcing
POR has both VCC & VBUS enabled. If the port is sourcing VBUS it will also act as sync and AC_OK pin gets enabled. Hence disable the input to the port when sourcing. BUG=chrome-os-partner:59020 BRANCH=none TEST=Manually verified on Reef. Connected HoHo and AC_OK is not enabled. Change-Id: Ic51b81f45759d7dddb2c9744d1c24dbafd1e1293 Signed-off-by: Vijay Hiremath <vijay.p.hiremath@intel.com> Reviewed-on: https://chromium-review.googlesource.com/404168 Commit-Ready: Vijay P Hiremath <vijay.p.hiremath@intel.com> Tested-by: Vijay P Hiremath <vijay.p.hiremath@intel.com> Reviewed-by: Shawn N <shawnn@chromium.org>
-rw-r--r--board/eve/board.c28
-rw-r--r--board/eve/usb_pd_policy.c3
-rw-r--r--board/kevin/board.c10
-rw-r--r--board/kevin/usb_pd_policy.c3
-rw-r--r--board/pyro/board.c28
-rw-r--r--board/pyro/usb_pd_policy.c3
-rw-r--r--board/reef/board.c28
-rw-r--r--board/reef/usb_pd_policy.c3
-rw-r--r--board/snappy/board.c28
-rw-r--r--board/snappy/usb_pd_policy.c3
-rw-r--r--driver/charger/bd9995x.c41
-rw-r--r--driver/charger/bd9995x.h5
12 files changed, 82 insertions, 101 deletions
diff --git a/board/eve/board.c b/board/eve/board.c
index 51cd515cbc..91ea7af370 100644
--- a/board/eve/board.c
+++ b/board/eve/board.c
@@ -391,20 +391,9 @@ int pd_snk_is_vbus_provided(int port)
int board_set_active_charge_port(int charge_port)
{
enum bd9995x_charge_port bd9995x_port;
+ int bd9995x_port_select = 1;
static int initialized;
- /* charge port is a physical port */
- int is_real_port = (charge_port >= 0 &&
- charge_port < CONFIG_USB_PD_PORT_COUNT);
- /* check if we are source VBUS on the port */
- int source = gpio_get_level(charge_port == 0 ? GPIO_USB_C0_5V_EN :
- GPIO_USB_C1_5V_EN);
-
- if (is_real_port && source) {
- CPRINTF("Skip enable p%d", charge_port);
- return EC_ERROR_INVAL;
- }
-
/*
* Reject charge port disable if our battery is critical and we
* have yet to initialize a charge port - continue to charge using
@@ -415,24 +404,29 @@ int board_set_active_charge_port(int charge_port)
charge_get_percent() < 2)
return -1;
- CPRINTS("New chg p%d", charge_port);
-
switch (charge_port) {
case 0:
case 1:
+ /* Don't charge from a source port */
+ if (gpio_get_level(charge_port == 0 ?
+ GPIO_USB_C0_5V_EN : GPIO_USB_C1_5V_EN))
+ return -1;
+
bd9995x_port = bd9995x_pd_port_to_chg_port(charge_port);
break;
case CHARGE_PORT_NONE:
- bd9995x_port = BD9995X_CHARGE_PORT_NONE;
+ bd9995x_port_select = 0;
+ bd9995x_port = BD9995X_CHARGE_PORT_BOTH;
break;
default:
panic("Invalid charge port\n");
break;
}
+ CPRINTS("New chg p%d", charge_port);
initialized = 1;
- return bd9995x_select_input_port(bd9995x_port);
+ return bd9995x_select_input_port(bd9995x_port, bd9995x_port_select);
}
/**
@@ -570,5 +564,5 @@ void board_hibernate_late(void)
void board_hibernate(void)
{
/* Enable both the VBUS & VCC ports before entering PG3 */
- bd9995x_select_input_port(BD9995X_CHARGE_PORT_BOTH);
+ bd9995x_select_input_port(BD9995X_CHARGE_PORT_BOTH, 1);
}
diff --git a/board/eve/usb_pd_policy.c b/board/eve/usb_pd_policy.c
index f0eccf50aa..74c1c54c80 100644
--- a/board/eve/usb_pd_policy.c
+++ b/board/eve/usb_pd_policy.c
@@ -54,8 +54,7 @@ void pd_transition_voltage(int idx)
int pd_set_power_supply_ready(int port)
{
/* Ensure we're not charging from this port */
- if (charge_manager_get_active_charge_port() == port)
- bd9995x_select_input_port(BD9995X_CHARGE_PORT_NONE);
+ bd9995x_select_input_port(bd9995x_pd_port_to_chg_port(port), 0);
/* Provide VBUS */
gpio_set_level(port ? GPIO_USB_C1_5V_EN :
diff --git a/board/kevin/board.c b/board/kevin/board.c
index 6f2644c0f4..fa91ca462c 100644
--- a/board/kevin/board.c
+++ b/board/kevin/board.c
@@ -199,6 +199,7 @@ uint16_t tcpc_get_alert_status(void)
int board_set_active_charge_port(int charge_port)
{
enum bd9995x_charge_port bd9995x_port;
+ int bd9995x_port_select = 1;
static int initialized;
/*
@@ -213,8 +214,6 @@ int board_set_active_charge_port(int charge_port)
return -1;
}
- CPRINTS("New chg p%d", charge_port);
-
switch (charge_port) {
case 0: case 1:
/* Don't charge from a source port */
@@ -225,15 +224,18 @@ int board_set_active_charge_port(int charge_port)
bd9995x_port = bd9995x_pd_port_to_chg_port(charge_port);
break;
case CHARGE_PORT_NONE:
- bd9995x_port = BD9995X_CHARGE_PORT_NONE;
+ bd9995x_port_select = 0;
+ bd9995x_port = BD9995X_CHARGE_PORT_BOTH;
break;
default:
panic("Invalid charge port\n");
break;
}
+ CPRINTS("New chg p%d", charge_port);
initialized = 1;
- return bd9995x_select_input_port(bd9995x_port);
+
+ return bd9995x_select_input_port(bd9995x_port, bd9995x_port_select);
}
void board_set_charge_limit(int port, int supplier, int charge_ma, int max_ma)
diff --git a/board/kevin/usb_pd_policy.c b/board/kevin/usb_pd_policy.c
index 44cd120448..e81659306c 100644
--- a/board/kevin/usb_pd_policy.c
+++ b/board/kevin/usb_pd_policy.c
@@ -55,8 +55,7 @@ void pd_transition_voltage(int idx)
int pd_set_power_supply_ready(int port)
{
/* Ensure we're not charging from this port */
- if (charge_manager_get_active_charge_port() == port)
- bd9995x_select_input_port(BD9995X_CHARGE_PORT_NONE);
+ bd9995x_select_input_port(bd9995x_pd_port_to_chg_port(port), 0);
/* Ensure we advertise the proper available current quota */
charge_manager_source_port(port, 1);
diff --git a/board/pyro/board.c b/board/pyro/board.c
index 280479712b..6ca7183dc8 100644
--- a/board/pyro/board.c
+++ b/board/pyro/board.c
@@ -488,20 +488,9 @@ int pd_snk_is_vbus_provided(int port)
int board_set_active_charge_port(int charge_port)
{
enum bd9995x_charge_port bd9995x_port;
+ int bd9995x_port_select = 1;
static int initialized;
- /* charge port is a physical port */
- int is_real_port = (charge_port >= 0 &&
- charge_port < CONFIG_USB_PD_PORT_COUNT);
- /* check if we are source VBUS on the port */
- int source = gpio_get_level(charge_port == 0 ? GPIO_USB_C0_5V_EN :
- GPIO_USB_C1_5V_EN);
-
- if (is_real_port && source) {
- CPRINTF("Skip enable p%d", charge_port);
- return EC_ERROR_INVAL;
- }
-
/*
* Reject charge port disable if our battery is critical and we
* have yet to initialize a charge port - continue to charge using
@@ -512,24 +501,29 @@ int board_set_active_charge_port(int charge_port)
charge_get_percent() < 2)
return -1;
- CPRINTS("New chg p%d", charge_port);
-
switch (charge_port) {
case 0:
case 1:
+ /* Don't charge from a source port */
+ if (gpio_get_level(charge_port == 0 ?
+ GPIO_USB_C0_5V_EN : GPIO_USB_C1_5V_EN))
+ return -1;
+
bd9995x_port = bd9995x_pd_port_to_chg_port(charge_port);
break;
case CHARGE_PORT_NONE:
- bd9995x_port = BD9995X_CHARGE_PORT_NONE;
+ bd9995x_port_select = 0;
+ bd9995x_port = BD9995X_CHARGE_PORT_BOTH;
break;
default:
panic("Invalid charge port\n");
break;
}
+ CPRINTS("New chg p%d", charge_port);
initialized = 1;
- return bd9995x_select_input_port(bd9995x_port);
+ return bd9995x_select_input_port(bd9995x_port, bd9995x_port_select);
}
/**
@@ -915,7 +909,7 @@ void board_hibernate(void)
msleep(100);
/* Enable both the VBUS & VCC ports before entering PG3 */
- bd9995x_select_input_port(BD9995X_CHARGE_PORT_BOTH);
+ bd9995x_select_input_port(BD9995X_CHARGE_PORT_BOTH, 1);
}
struct {
diff --git a/board/pyro/usb_pd_policy.c b/board/pyro/usb_pd_policy.c
index cb7d9ff62b..e2f8157dc3 100644
--- a/board/pyro/usb_pd_policy.c
+++ b/board/pyro/usb_pd_policy.c
@@ -54,8 +54,7 @@ void pd_transition_voltage(int idx)
int pd_set_power_supply_ready(int port)
{
/* Ensure we're not charging from this port */
- if (charge_manager_get_active_charge_port() == port)
- bd9995x_select_input_port(BD9995X_CHARGE_PORT_NONE);
+ bd9995x_select_input_port(bd9995x_pd_port_to_chg_port(port), 0);
/* Provide VBUS */
gpio_set_level(port ? GPIO_USB_C1_5V_EN :
diff --git a/board/reef/board.c b/board/reef/board.c
index cec70666d9..22ca518c39 100644
--- a/board/reef/board.c
+++ b/board/reef/board.c
@@ -488,20 +488,9 @@ int pd_snk_is_vbus_provided(int port)
int board_set_active_charge_port(int charge_port)
{
enum bd9995x_charge_port bd9995x_port;
+ int bd9995x_port_select = 1;
static int initialized;
- /* charge port is a physical port */
- int is_real_port = (charge_port >= 0 &&
- charge_port < CONFIG_USB_PD_PORT_COUNT);
- /* check if we are source VBUS on the port */
- int source = gpio_get_level(charge_port == 0 ? GPIO_USB_C0_5V_EN :
- GPIO_USB_C1_5V_EN);
-
- if (is_real_port && source) {
- CPRINTF("Skip enable p%d", charge_port);
- return EC_ERROR_INVAL;
- }
-
/*
* Reject charge port disable if our battery is critical and we
* have yet to initialize a charge port - continue to charge using
@@ -512,24 +501,29 @@ int board_set_active_charge_port(int charge_port)
charge_get_percent() < 2)
return -1;
- CPRINTS("New chg p%d", charge_port);
-
switch (charge_port) {
case 0:
case 1:
+ /* Don't charge from a source port */
+ if (gpio_get_level(charge_port == 0 ?
+ GPIO_USB_C0_5V_EN : GPIO_USB_C1_5V_EN))
+ return -1;
+
bd9995x_port = bd9995x_pd_port_to_chg_port(charge_port);
break;
case CHARGE_PORT_NONE:
- bd9995x_port = BD9995X_CHARGE_PORT_NONE;
+ bd9995x_port_select = 0;
+ bd9995x_port = BD9995X_CHARGE_PORT_BOTH;
break;
default:
panic("Invalid charge port\n");
break;
}
+ CPRINTS("New chg p%d", charge_port);
initialized = 1;
- return bd9995x_select_input_port(bd9995x_port);
+ return bd9995x_select_input_port(bd9995x_port, bd9995x_port_select);
}
/**
@@ -911,7 +905,7 @@ void board_hibernate(void)
msleep(100);
/* Enable both the VBUS & VCC ports before entering PG3 */
- bd9995x_select_input_port(BD9995X_CHARGE_PORT_BOTH);
+ bd9995x_select_input_port(BD9995X_CHARGE_PORT_BOTH, 1);
}
struct {
diff --git a/board/reef/usb_pd_policy.c b/board/reef/usb_pd_policy.c
index 5a2bae6f96..6e515abf81 100644
--- a/board/reef/usb_pd_policy.c
+++ b/board/reef/usb_pd_policy.c
@@ -54,8 +54,7 @@ void pd_transition_voltage(int idx)
int pd_set_power_supply_ready(int port)
{
/* Ensure we're not charging from this port */
- if (charge_manager_get_active_charge_port() == port)
- bd9995x_select_input_port(BD9995X_CHARGE_PORT_NONE);
+ bd9995x_select_input_port(bd9995x_pd_port_to_chg_port(port), 0);
/* Provide VBUS */
gpio_set_level(port ? GPIO_USB_C1_5V_EN :
diff --git a/board/snappy/board.c b/board/snappy/board.c
index 0b2d042c63..beb48868de 100644
--- a/board/snappy/board.c
+++ b/board/snappy/board.c
@@ -488,20 +488,9 @@ int pd_snk_is_vbus_provided(int port)
int board_set_active_charge_port(int charge_port)
{
enum bd9995x_charge_port bd9995x_port;
+ int bd9995x_port_select = 1;
static int initialized;
- /* charge port is a physical port */
- int is_real_port = (charge_port >= 0 &&
- charge_port < CONFIG_USB_PD_PORT_COUNT);
- /* check if we are source VBUS on the port */
- int source = gpio_get_level(charge_port == 0 ? GPIO_USB_C0_5V_EN :
- GPIO_USB_C1_5V_EN);
-
- if (is_real_port && source) {
- CPRINTF("Skip enable p%d", charge_port);
- return EC_ERROR_INVAL;
- }
-
/*
* Reject charge port disable if our battery is critical and we
* have yet to initialize a charge port - continue to charge using
@@ -512,24 +501,29 @@ int board_set_active_charge_port(int charge_port)
charge_get_percent() < 2)
return -1;
- CPRINTS("New chg p%d", charge_port);
-
switch (charge_port) {
case 0:
case 1:
+ /* Don't charge from a source port */
+ if (gpio_get_level(charge_port == 0 ?
+ GPIO_USB_C0_5V_EN : GPIO_USB_C1_5V_EN))
+ return -1;
+
bd9995x_port = bd9995x_pd_port_to_chg_port(charge_port);
break;
case CHARGE_PORT_NONE:
- bd9995x_port = BD9995X_CHARGE_PORT_NONE;
+ bd9995x_port_select = 0;
+ bd9995x_port = BD9995X_CHARGE_PORT_BOTH;
break;
default:
panic("Invalid charge port\n");
break;
}
+ CPRINTS("New chg p%d", charge_port);
initialized = 1;
- return bd9995x_select_input_port(bd9995x_port);
+ return bd9995x_select_input_port(bd9995x_port, bd9995x_port_select);
}
/**
@@ -915,7 +909,7 @@ void board_hibernate(void)
msleep(100);
/* Enable both the VBUS & VCC ports before entering PG3 */
- bd9995x_select_input_port(BD9995X_CHARGE_PORT_BOTH);
+ bd9995x_select_input_port(BD9995X_CHARGE_PORT_BOTH, 1);
}
struct {
diff --git a/board/snappy/usb_pd_policy.c b/board/snappy/usb_pd_policy.c
index cb7d9ff62b..e2f8157dc3 100644
--- a/board/snappy/usb_pd_policy.c
+++ b/board/snappy/usb_pd_policy.c
@@ -54,8 +54,7 @@ void pd_transition_voltage(int idx)
int pd_set_power_supply_ready(int port)
{
/* Ensure we're not charging from this port */
- if (charge_manager_get_active_charge_port() == port)
- bd9995x_select_input_port(BD9995X_CHARGE_PORT_NONE);
+ bd9995x_select_input_port(bd9995x_pd_port_to_chg_port(port), 0);
/* Provide VBUS */
gpio_set_level(port ? GPIO_USB_C1_5V_EN :
diff --git a/driver/charger/bd9995x.c b/driver/charger/bd9995x.c
index 65e7483772..675afafe90 100644
--- a/driver/charger/bd9995x.c
+++ b/driver/charger/bd9995x.c
@@ -798,7 +798,7 @@ int bd9995x_is_vbus_provided(int port)
return !!reg;
}
-int bd9995x_select_input_port(enum bd9995x_charge_port port)
+int bd9995x_select_input_port(enum bd9995x_charge_port port, int select)
{
int rv;
int reg;
@@ -808,22 +808,31 @@ int bd9995x_select_input_port(enum bd9995x_charge_port port)
if (rv)
return rv;
- if (port == BD9995X_CHARGE_PORT_NONE) {
- reg &= ~(BD9995X_CMD_VIN_CTRL_SET_VBUS_EN |
- BD9995X_CMD_VIN_CTRL_SET_VCC_EN);
- } else if (port == BD9995X_CHARGE_PORT_VBUS) {
- reg |= BD9995X_CMD_VIN_CTRL_SET_VBUS_EN;
- reg &= ~BD9995X_CMD_VIN_CTRL_SET_VCC_EN;
- } else if (port == BD9995X_CHARGE_PORT_VCC) {
- reg |= BD9995X_CMD_VIN_CTRL_SET_VCC_EN;
- reg &= ~BD9995X_CMD_VIN_CTRL_SET_VBUS_EN;
- } else if (port == BD9995X_CHARGE_PORT_BOTH) {
- /* Enable both the ports for PG3 */
- reg |= BD9995X_CMD_VIN_CTRL_SET_VBUS_EN |
- BD9995X_CMD_VIN_CTRL_SET_VCC_EN;
+ if (select) {
+ if (port == BD9995X_CHARGE_PORT_VBUS) {
+ reg |= BD9995X_CMD_VIN_CTRL_SET_VBUS_EN;
+ reg &= ~BD9995X_CMD_VIN_CTRL_SET_VCC_EN;
+ } else if (port == BD9995X_CHARGE_PORT_VCC) {
+ reg |= BD9995X_CMD_VIN_CTRL_SET_VCC_EN;
+ reg &= ~BD9995X_CMD_VIN_CTRL_SET_VBUS_EN;
+ } else if (port == BD9995X_CHARGE_PORT_BOTH) {
+ /* Enable both the ports for PG3 */
+ reg |= BD9995X_CMD_VIN_CTRL_SET_VBUS_EN |
+ BD9995X_CMD_VIN_CTRL_SET_VCC_EN;
+ } else {
+ /* Invalid charge port */
+ panic("Invalid charge port");
+ }
} else {
- /* Invalid charge port */
- panic("Invalid charge port");
+ if (port == BD9995X_CHARGE_PORT_VBUS)
+ reg &= ~BD9995X_CMD_VIN_CTRL_SET_VBUS_EN;
+ else if (port == BD9995X_CHARGE_PORT_VCC)
+ reg &= ~BD9995X_CMD_VIN_CTRL_SET_VCC_EN;
+ if (port == BD9995X_CHARGE_PORT_BOTH)
+ reg &= ~(BD9995X_CMD_VIN_CTRL_SET_VBUS_EN |
+ BD9995X_CMD_VIN_CTRL_SET_VCC_EN);
+ else
+ panic("Invalid charge port");
}
return ch_raw_write16(BD9995X_CMD_VIN_CTRL_SET, reg,
diff --git a/driver/charger/bd9995x.h b/driver/charger/bd9995x.h
index baef184d09..ea27b88715 100644
--- a/driver/charger/bd9995x.h
+++ b/driver/charger/bd9995x.h
@@ -31,7 +31,6 @@ enum bd9995x_charge_port {
BD9995X_CHARGE_PORT_VBUS,
BD9995X_CHARGE_PORT_VCC,
BD9995X_CHARGE_PORT_BOTH,
- BD9995X_CHARGE_PORT_NONE,
};
/* Charger parameters */
@@ -348,8 +347,8 @@ static inline enum bd9995x_charge_port bd9995x_pd_port_to_chg_port(int port)
/* Is VBUS provided or external power present */
int bd9995x_is_vbus_provided(int port);
-/* Select input port from {VCC, VBUS, VCC&VBUS, NONE}. */
-int bd9995x_select_input_port(enum bd9995x_charge_port port);
+/* Select or deselect input port from {VCC, VBUS, VCC&VBUS}. */
+int bd9995x_select_input_port(enum bd9995x_charge_port port, int select);
/* Get input current limit for BC1.2 suppliers */
int bd9995x_get_bc12_ilim(int charge_supplier);
/* Enable/Disable charging triggered by BC1.2 */