diff options
author | Shawn Nematbakhsh <shawnn@chromium.org> | 2017-11-06 10:07:15 -0800 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2017-11-07 12:17:43 -0800 |
commit | f4ee6caa665009ca3306f61706074b82e1e2c347 (patch) | |
tree | c61dd1cd667f35324443a64c1d540d67e6ee5ed9 | |
parent | fca1b7b710898ff347465d839c14164d610f140d (diff) | |
download | chrome-ec-f4ee6caa665009ca3306f61706074b82e1e2c347.tar.gz |
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>
-rw-r--r-- | board/coral/board.c | 15 | ||||
-rw-r--r-- | board/coral/usb_pd_policy.c | 2 | ||||
-rw-r--r-- | board/eve/board.c | 15 | ||||
-rw-r--r-- | board/eve/usb_pd_policy.c | 2 | ||||
-rw-r--r-- | board/kevin/board.c | 17 | ||||
-rw-r--r-- | board/kevin/usb_pd_policy.c | 2 | ||||
-rw-r--r-- | board/nefario/board.c | 17 | ||||
-rw-r--r-- | board/nefario/usb_pd_policy.c | 2 | ||||
-rw-r--r-- | board/reef/board.c | 15 | ||||
-rw-r--r-- | board/reef/usb_pd_policy.c | 2 | ||||
-rw-r--r-- | board/reef_it8320/board.c | 15 | ||||
-rw-r--r-- | board/reef_it8320/usb_pd_policy.c | 2 | ||||
-rw-r--r-- | driver/charger/bd9995x.c | 25 | ||||
-rw-r--r-- | driver/charger/bd9995x.h | 18 | ||||
-rw-r--r-- | include/config.h | 7 |
15 files changed, 43 insertions, 113 deletions
diff --git a/board/coral/board.c b/board/coral/board.c index a862541c1b..43ea4fca91 100644 --- a/board/coral/board.c +++ b/board/coral/board.c @@ -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; diff --git a/board/coral/usb_pd_policy.c b/board/coral/usb_pd_policy.c index b6c3f07328..20286af0a0 100644 --- a/board/coral/usb_pd_policy.c +++ b/board/coral/usb_pd_policy.c @@ -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); diff --git a/board/eve/board.c b/board/eve/board.c index d6b4d87c38..f580c30651 100644 --- a/board/eve/board.c +++ b/board/eve/board.c @@ -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; diff --git a/board/eve/usb_pd_policy.c b/board/eve/usb_pd_policy.c index 62664d95ae..73cb23aa85 100644 --- a/board/eve/usb_pd_policy.c +++ b/board/eve/usb_pd_policy.c @@ -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); diff --git a/board/kevin/board.c b/board/kevin/board.c index 41d987597d..a15fd63bea 100644 --- a/board/kevin/board.c +++ b/board/kevin/board.c @@ -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) diff --git a/board/kevin/usb_pd_policy.c b/board/kevin/usb_pd_policy.c index 8e1c8da7a8..b8a4766984 100644 --- a/board/kevin/usb_pd_policy.c +++ b/board/kevin/usb_pd_policy.c @@ -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); diff --git a/board/nefario/board.c b/board/nefario/board.c index 9016198162..cd85bd35bf 100644 --- a/board/nefario/board.c +++ b/board/nefario/board.c @@ -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) diff --git a/board/nefario/usb_pd_policy.c b/board/nefario/usb_pd_policy.c index fa59088ac0..6f00e4d57b 100644 --- a/board/nefario/usb_pd_policy.c +++ b/board/nefario/usb_pd_policy.c @@ -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); diff --git a/board/reef/board.c b/board/reef/board.c index 4431adab25..3e0becb255 100644 --- a/board/reef/board.c +++ b/board/reef/board.c @@ -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; diff --git a/board/reef/usb_pd_policy.c b/board/reef/usb_pd_policy.c index b6c3f07328..20286af0a0 100644 --- a/board/reef/usb_pd_policy.c +++ b/board/reef/usb_pd_policy.c @@ -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); diff --git a/board/reef_it8320/board.c b/board/reef_it8320/board.c index 8256cd1a3e..c8eeb2b8ef 100644 --- a/board/reef_it8320/board.c +++ b/board/reef_it8320/board.c @@ -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; diff --git a/board/reef_it8320/usb_pd_policy.c b/board/reef_it8320/usb_pd_policy.c index 48211441be..09afde1f40 100644 --- a/board/reef_it8320/usb_pd_policy.c +++ b/board/reef_it8320/usb_pd_policy.c @@ -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); diff --git a/driver/charger/bd9995x.c b/driver/charger/bd9995x.c index 7f1a023830..9e35f273ee 100644 --- a/driver/charger/bd9995x.c +++ b/driver/charger/bd9995x.c @@ -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; } diff --git a/driver/charger/bd9995x.h b/driver/charger/bd9995x.h index 915ed0987b..7b10dbde99 100644 --- a/driver/charger/bd9995x.h +++ b/driver/charger/bd9995x.h @@ -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) */ diff --git a/include/config.h b/include/config.h index 6d1e7ee9d1..2de39721f6 100644 --- a/include/config.h +++ b/include/config.h @@ -477,13 +477,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 * * Which power save mode should the charger enter when VBUS is removed. Check |