bd9995x: Use fixed PD-port-to-VBUS/VCC mapping

The bd9995x driver was written to allow any PD port # to be VBUS or VCC,
but the mapping is broken in a few places. Since all boards use VBUS =
port 0, remove the conversion entirely.

BUG=chromium:781849
BRANCH=kevin
TEST=Verify PD and BC1.2 charging still works on kevin.

Change-Id: I3687866835d1684342d9f746d91b3a6079ab5cc4
Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/755000
Commit-Ready: Shawn N <shawnn@chromium.org>
Tested-by: Shawn N <shawnn@chromium.org>
Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
This commit is contained in:
Shawn Nematbakhsh
2017-11-06 10:07:15 -08:00
committed by chrome-bot
parent fca1b7b710
commit f4ee6caa66
15 changed files with 43 additions and 113 deletions

View File

@@ -566,19 +566,10 @@ DECLARE_HOOK(HOOK_INIT, board_init, HOOK_PRIO_FIRST);
int pd_snk_is_vbus_provided(int port)
{
enum bd9995x_charge_port bd9995x_port;
switch (port) {
case USB_PD_PORT_ANX74XX:
case USB_PD_PORT_PS8751:
bd9995x_port = bd9995x_pd_port_to_chg_port(port);
break;
default:
if (port != 0 && port != 1)
panic("Invalid charge port\n");
break;
}
return bd9995x_is_vbus_provided(bd9995x_port);
return bd9995x_is_vbus_provided(port);
}
/**
@@ -601,7 +592,7 @@ int board_set_active_charge_port(int charge_port)
if (board_vbus_source_enabled(charge_port))
return -1;
bd9995x_port = bd9995x_pd_port_to_chg_port(charge_port);
bd9995x_port = charge_port;
break;
case CHARGE_PORT_NONE:
bd9995x_port_select = 0;

View File

@@ -92,7 +92,7 @@ void typec_set_source_current_limit(int port, int rp)
int pd_set_power_supply_ready(int port)
{
/* Ensure we're not charging from this port */
bd9995x_select_input_port(bd9995x_pd_port_to_chg_port(port), 0);
bd9995x_select_input_port(port, 0);
/* Ensure we advertise the proper available current quota */
charge_manager_source_port(port, 1);

View File

@@ -445,19 +445,10 @@ DECLARE_HOOK(HOOK_AC_CHANGE, board_extpower, HOOK_PRIO_DEFAULT);
int pd_snk_is_vbus_provided(int port)
{
enum bd9995x_charge_port bd9995x_port;
switch (port) {
case 0:
case 1:
bd9995x_port = bd9995x_pd_port_to_chg_port(port);
break;
default:
if (port != 0 && port != 1)
panic("Invalid charge port\n");
break;
}
return bd9995x_is_vbus_provided(bd9995x_port);
return bd9995x_is_vbus_provided(port);
}
/**
@@ -480,7 +471,7 @@ int board_set_active_charge_port(int charge_port)
if (board_vbus_source_enabled(charge_port))
return -1;
bd9995x_port = bd9995x_pd_port_to_chg_port(charge_port);
bd9995x_port = charge_port;
break;
case CHARGE_PORT_NONE:
bd9995x_port_select = 0;

View File

@@ -112,7 +112,7 @@ void typec_set_source_current_limit(int port, int rp)
int pd_set_power_supply_ready(int port)
{
/* Ensure we're not charging from this port */
bd9995x_select_input_port(bd9995x_pd_port_to_chg_port(port), 0);
bd9995x_select_input_port(port, 0);
/* Ensure we advertise the proper available current quota */
charge_manager_source_port(port, 1);

View File

@@ -215,7 +215,7 @@ int board_set_active_charge_port(int charge_port)
if (board_vbus_source_enabled(charge_port))
return -1;
bd9995x_port = bd9995x_pd_port_to_chg_port(charge_port);
bd9995x_port = charge_port;
break;
case CHARGE_PORT_NONE:
bd9995x_port_select = 0;
@@ -253,26 +253,17 @@ int extpower_is_present(void)
else if (!p0_src && !p1_src)
port = BD9995X_CHARGE_PORT_BOTH;
else
port = bd9995x_pd_port_to_chg_port(p0_src);
port = p0_src;
return bd9995x_is_vbus_provided(port);
}
int pd_snk_is_vbus_provided(int port)
{
enum bd9995x_charge_port bd9995x_port;
switch (port) {
case 0:
case 1:
bd9995x_port = bd9995x_pd_port_to_chg_port(port);
break;
default:
if (port != 0 && port != 1)
panic("Invalid charge port\n");
break;
}
return bd9995x_is_vbus_provided(bd9995x_port);
return bd9995x_is_vbus_provided(port);
}
static void board_spi_enable(void)

View File

@@ -90,7 +90,7 @@ static void board_vbus_update_source_current(int port)
int pd_set_power_supply_ready(int port)
{
/* Ensure we're not charging from this port */
bd9995x_select_input_port(bd9995x_pd_port_to_chg_port(port), 0);
bd9995x_select_input_port(port, 0);
/* Ensure we advertise the proper available current quota */
charge_manager_source_port(port, 1);

View File

@@ -199,7 +199,7 @@ int board_set_active_charge_port(int charge_port)
if (board_vbus_source_enabled(charge_port))
return -1;
bd9995x_port = bd9995x_pd_port_to_chg_port(charge_port);
bd9995x_port = charge_port;
break;
case CHARGE_PORT_NONE:
bd9995x_port_select = 0;
@@ -235,26 +235,17 @@ int extpower_is_present(void)
else if (!p0_src && !p1_src)
port = BD9995X_CHARGE_PORT_BOTH;
else
port = bd9995x_pd_port_to_chg_port(p0_src);
port = p0_src;
return bd9995x_is_vbus_provided(port);
}
int pd_snk_is_vbus_provided(int port)
{
enum bd9995x_charge_port bd9995x_port;
switch (port) {
case 0:
case 1:
bd9995x_port = bd9995x_pd_port_to_chg_port(port);
break;
default:
if (port != 0 && port != 1)
panic("Invalid charge port\n");
break;
}
return bd9995x_is_vbus_provided(bd9995x_port);
return bd9995x_is_vbus_provided(port);
}
static void board_spi_enable(void)

View File

@@ -80,7 +80,7 @@ static void board_vbus_update_source_current(int port)
int pd_set_power_supply_ready(int port)
{
/* Ensure we're not charging from this port */
bd9995x_select_input_port(bd9995x_pd_port_to_chg_port(port), 0);
bd9995x_select_input_port(port, 0);
/* Ensure we advertise the proper available current quota */
charge_manager_source_port(port, 1);

View File

@@ -558,19 +558,10 @@ DECLARE_HOOK(HOOK_INIT, board_init, HOOK_PRIO_FIRST);
int pd_snk_is_vbus_provided(int port)
{
enum bd9995x_charge_port bd9995x_port;
switch (port) {
case USB_PD_PORT_ANX74XX:
case USB_PD_PORT_PS8751:
bd9995x_port = bd9995x_pd_port_to_chg_port(port);
break;
default:
if (port != 0 && port != 1)
panic("Invalid charge port\n");
break;
}
return bd9995x_is_vbus_provided(bd9995x_port);
return bd9995x_is_vbus_provided(port);
}
/**
@@ -593,7 +584,7 @@ int board_set_active_charge_port(int charge_port)
if (board_vbus_source_enabled(charge_port))
return -1;
bd9995x_port = bd9995x_pd_port_to_chg_port(charge_port);
bd9995x_port = charge_port;
break;
case CHARGE_PORT_NONE:
bd9995x_port_select = 0;

View File

@@ -92,7 +92,7 @@ void typec_set_source_current_limit(int port, int rp)
int pd_set_power_supply_ready(int port)
{
/* Ensure we're not charging from this port */
bd9995x_select_input_port(bd9995x_pd_port_to_chg_port(port), 0);
bd9995x_select_input_port(port, 0);
/* Ensure we advertise the proper available current quota */
charge_manager_source_port(port, 1);

View File

@@ -343,19 +343,10 @@ DECLARE_HOOK(HOOK_INIT, board_init, HOOK_PRIO_INIT_I2C + 1);
int pd_snk_is_vbus_provided(int port)
{
enum bd9995x_charge_port bd9995x_port = 0;
switch (port) {
case 0:
case 1:
bd9995x_port = bd9995x_pd_port_to_chg_port(port);
break;
default:
if (port != 0 && port != 1)
panic("Invalid charge port\n");
break;
}
return bd9995x_is_vbus_provided(bd9995x_port);
return bd9995x_is_vbus_provided(port);
}
/**
@@ -378,7 +369,7 @@ int board_set_active_charge_port(int charge_port)
if (board_vbus_source_enabled(charge_port))
return -1;
bd9995x_port = bd9995x_pd_port_to_chg_port(charge_port);
bd9995x_port = charge_port;
break;
case CHARGE_PORT_NONE:
bd9995x_port_select = 0;

View File

@@ -85,7 +85,7 @@ void typec_set_source_current_limit(int port, int rp)
int pd_set_power_supply_ready(int port)
{
/* Ensure we're not charging from this port */
bd9995x_select_input_port(bd9995x_pd_port_to_chg_port(port), 0);
bd9995x_select_input_port(port, 0);
/* Ensure we advertise the proper available current quota */
charge_manager_source_port(port, 1);

View File

@@ -308,7 +308,7 @@ static int bd9995x_get_charger_op_status(int *status)
#ifdef HAS_TASK_USB_CHG
static int bc12_detected_type[CONFIG_USB_PD_PORT_COUNT];
static int bd9995x_get_bc12_device_type(enum bd9995x_charge_port port)
static int bd9995x_get_bc12_device_type(int port)
{
int rv;
int reg;
@@ -337,8 +337,7 @@ static int bd9995x_get_bc12_device_type(enum bd9995x_charge_port port)
}
}
static int bd9995x_enable_usb_switch(enum bd9995x_charge_port port,
enum usb_switch setting)
static int bd9995x_enable_usb_switch(int port, enum usb_switch setting)
{
int rv;
int reg;
@@ -363,9 +362,8 @@ static int bd9995x_bc12_check_type(int port)
{
int bc12_type;
struct charge_port_info charge;
int chg_port = bd9995x_pd_port_to_chg_port(port);
int vbus_provided = bd9995x_is_vbus_provided(port) &&
!usb_charger_port_is_sourcing_vbus(chg_port);
!usb_charger_port_is_sourcing_vbus(port);
/*
* If vbus is no longer provided, then no need to continue. Return 0 so
@@ -475,14 +473,13 @@ static int bd9995x_get_interrupts(int port)
return reg;
}
static int usb_charger_process(enum bd9995x_charge_port port)
static int usb_charger_process(int port)
{
int chg_port = bd9995x_pd_port_to_chg_port(port);
int vbus_provided = bd9995x_is_vbus_provided(port) &&
!usb_charger_port_is_sourcing_vbus(chg_port);
!usb_charger_port_is_sourcing_vbus(port);
/* Inform other modules about VBUS level */
usb_charger_vbus_change(chg_port, vbus_provided);
usb_charger_vbus_change(port, vbus_provided);
/* Do BC1.2 detection */
if (vbus_provided) {
@@ -970,9 +967,8 @@ int charger_get_vbus_voltage(int port)
uint8_t read_reg;
int voltage;
read_reg = (bd9995x_pd_port_to_chg_port(port) ==
BD9995X_CHARGE_PORT_VBUS) ? BD9995X_CMD_VBUS_VAL :
BD9995X_CMD_VCC_VAL;
read_reg = (port == BD9995X_CHARGE_PORT_VBUS) ? BD9995X_CMD_VBUS_VAL :
BD9995X_CMD_VCC_VAL;
return ch_raw_read16(read_reg, &voltage, BD9995X_EXTENDED_COMMAND) ?
0 : voltage;
@@ -1075,7 +1071,7 @@ int bd9995x_get_battery_voltage(void)
}
#ifdef HAS_TASK_USB_CHG
int bd9995x_bc12_enable_charging(enum bd9995x_charge_port port, int enable)
int bd9995x_bc12_enable_charging(int port, int enable)
{
int rv;
int reg;
@@ -1178,8 +1174,7 @@ void usb_charger_task(void *u)
voltage = 0;
/* Set discharge accordingly */
pd_set_vbus_discharge(
bd9995x_pd_port_to_chg_port(port),
pd_set_vbus_discharge(port,
voltage < BD9995X_VBUS_DISCHARGE_TH);
changed = 1;
}

View File

@@ -23,6 +23,12 @@ enum bd9995x_command {
BD9995X_INVALID_COMMAND
};
/*
* BD9995X has two external VBUS inputs (named VBUS and VCC) and two sets
* of registers / bits for control. This entire driver is written under the
* assumption that the physical VBUS port corresponds to PD port 0, and the
* physical VCC port corresponds to PD port 1.
*/
enum bd9995x_charge_port {
BD9995X_CHARGE_PORT_VBUS,
BD9995X_CHARGE_PORT_VCC,
@@ -326,16 +332,6 @@ enum bd9995x_charge_port {
#define BD9995X_PWR_SAVE_MAX 0x6
#define BD9995X_CMD_DEBUG_MODE_SET 0x7F
/* Map PD port number to charge port number */
static inline enum bd9995x_charge_port bd9995x_pd_port_to_chg_port(int port)
{
#ifdef CONFIG_BD9995X_PRIMARY_CHARGE_PORT_VCC
return port ? BD9995X_CHARGE_PORT_VBUS : BD9995X_CHARGE_PORT_VCC;
#else
return port ? BD9995X_CHARGE_PORT_VCC : BD9995X_CHARGE_PORT_VBUS;
#endif
}
/*
* Non-standard interface functions - bd9995x integrates additional
* functionality not part of the standard charger interface.
@@ -346,7 +342,7 @@ int bd9995x_is_vbus_provided(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);
/* Enable/Disable charging triggered by BC1.2 */
int bd9995x_bc12_enable_charging(enum bd9995x_charge_port port, int enable);
int bd9995x_bc12_enable_charging(int port, int enable);
/* Interrupt handler for USB charger VBUS */
void bd9995x_vbus_interrupt(enum gpio_signal signal);
/* Read temperature measurement value (in Celsius) */

View File

@@ -476,13 +476,6 @@
*/
#undef CONFIG_CHARGER_BD9995X_CHGEN
/*
* BD9995X PD port to charger port mapping.
* By default VBUS is selected as primary port.
* Define only if the VCC is the primary port.
*/
#undef CONFIG_BD9995X_PRIMARY_CHARGE_PORT_VCC
/*
* BD9995X Power Save Mode
*