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>
This commit is contained in:
Vijay Hiremath
2016-10-26 17:40:57 -07:00
committed by chrome-bot
parent b6937caeeb
commit 799c272e28
12 changed files with 82 additions and 101 deletions

View File

@@ -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);
}

View File

@@ -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 :

View File

@@ -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)

View File

@@ -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);

View File

@@ -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 {

View File

@@ -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 :

View File

@@ -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 {

View File

@@ -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 :

View File

@@ -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 {

View File

@@ -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 :

View File

@@ -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,

View File

@@ -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 */