diff options
author | Shawn Nematbakhsh <shawnn@chromium.org> | 2017-11-06 10:07:15 -0800 |
---|---|---|
committer | ChromeOS Commit Bot <chromeos-commit-bot@chromium.org> | 2018-02-12 19:49:20 +0000 |
commit | a10d039c5498a1b2a3a655a511b443ce5b1707d5 (patch) | |
tree | ec7a021ce5d67811087e72b7a3b54e3d679c6354 | |
parent | c9571c5257940a3d3e1b665a968b097d526e499e (diff) | |
download | chrome-ec-a10d039c5498a1b2a3a655a511b443ce5b1707d5.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: I53162fb6e93e89dd161369302a18fc59e48e5dc8
Signed-off-by: Duncan Laurie <dlaurie@google.com>
Original-Commit-Id: f4ee6caa665009ca3306f61706074b82e1e2c347
Original-Change-Id: I3687866835d1684342d9f746d91b3a6079ab5cc4
Original-Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org>
Original-Reviewed-on: https://chromium-review.googlesource.com/755000
Original-Commit-Ready: Shawn N <shawnn@chromium.org>
Original-Tested-by: Shawn N <shawnn@chromium.org>
Original-Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/914643
-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/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 |
13 files changed, 38 insertions, 99 deletions
diff --git a/board/coral/board.c b/board/coral/board.c index 0e2923bf83..fff13b3965 100644 --- a/board/coral/board.c +++ b/board/coral/board.c @@ -540,19 +540,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); } /** @@ -586,7 +577,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 7b2ec9d1bd..e0c334f063 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 d3503b525d..e454a85cd8 100644 --- a/board/eve/board.c +++ b/board/eve/board.c @@ -452,19 +452,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); } /** @@ -498,7 +489,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 e1425c15d8..16d7f5547f 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 c733d565a6..9c81e744c1 100644 --- a/board/kevin/board.c +++ b/board/kevin/board.c @@ -228,7 +228,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; @@ -278,26 +278,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 c72433dbb3..14a5b2f0a7 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/reef/board.c b/board/reef/board.c index 037fd9de5d..85ab59e6a1 100644 --- a/board/reef/board.c +++ b/board/reef/board.c @@ -540,19 +540,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); } /** @@ -586,7 +577,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 7b2ec9d1bd..e0c334f063 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 06259c0c6a..8e3a40d9f2 100644 --- a/board/reef_it8320/board.c +++ b/board/reef_it8320/board.c @@ -327,19 +327,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); } /** @@ -373,7 +364,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 7985ed4176..45a4169394 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 6503ea840d..115e9751ef 100644 --- a/driver/charger/bd9995x.c +++ b/driver/charger/bd9995x.c @@ -313,7 +313,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; @@ -342,8 +342,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; @@ -368,9 +367,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 @@ -480,14 +478,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) { @@ -1007,9 +1004,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; @@ -1116,7 +1112,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; @@ -1219,8 +1215,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 158494149b..b17fa6a1b5 100644 --- a/driver/charger/bd9995x.h +++ b/driver/charger/bd9995x.h @@ -27,6 +27,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, @@ -330,16 +336,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. @@ -350,7 +346,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 dd37ab1c9d..78cb88c913 100644 --- a/include/config.h +++ b/include/config.h @@ -434,13 +434,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 |