diff options
author | Shawn Nematbakhsh <shawnn@chromium.org> | 2015-06-11 13:29:16 -0700 |
---|---|---|
committer | ChromeOS Commit Bot <chromeos-commit-bot@chromium.org> | 2015-06-12 16:37:54 +0000 |
commit | 3062442361cb1765224a237043db37e6d8ebb762 (patch) | |
tree | d22c6088bf9d5c42e07abf6e693e1583594f440f | |
parent | a0bec46ef3f7804ad4ae59d5a89b89da636a54a3 (diff) | |
download | chrome-ec-3062442361cb1765224a237043db37e6d8ebb762.tar.gz |
glados: Enable BC1.2 USB charging
Enable charger detection through the pericom chips.
BUG=chrome-os-partner:40920
TEST=Manual on Glados. Plug 1A Apple charger, verify that port is
selected and charge limit is set correctly on both ports. Also verify
that Zinger still charges correctly.
BRANCH=None
Change-Id: I7e462194560965b6140446f3444be225e5503616
Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/276886
Reviewed-by: Alec Berg <alecaberg@chromium.org>
-rw-r--r-- | board/glados/board.c | 73 | ||||
-rw-r--r-- | board/glados/board.h | 5 | ||||
-rw-r--r-- | board/glados/ec.tasklist | 2 |
3 files changed, 63 insertions, 17 deletions
diff --git a/board/glados/board.c b/board/glados/board.c index 1f88043cc4..3bfc0139bb 100644 --- a/board/glados/board.c +++ b/board/glados/board.c @@ -18,11 +18,14 @@ #include "i2c.h" #include "lid_switch.h" #include "motion_sense.h" +#include "pi3usb9281.h" #include "power.h" #include "power_button.h" #include "switch.h" #include "task.h" #include "timer.h" +#include "usb_charge.h" +#include "usb_pd.h" #include "usb_pd_tcpm.h" #include "util.h" @@ -44,24 +47,51 @@ static void pd_mcu_interrupt(enum gpio_signal signal) host_command_pd_send_status(0); } +static void update_vbus_supplier(int port, int vbus_level) +{ + struct charge_port_info charge; + + /* + * If VBUS is low, or VBUS is high and we are not outputting VBUS + * ourselves, then update the VBUS supplier. + */ + if (!vbus_level || !usb_charger_port_is_sourcing_vbus(port)) { + charge.voltage = USB_BC12_CHARGE_VOLTAGE; + charge.current = vbus_level ? DEFAULT_CURR_LIMIT : 0; + charge_manager_update_charge(CHARGE_SUPPLIER_VBUS, + port, + &charge); + } +} + void vbus0_evt(enum gpio_signal signal) { - CPRINTF("VBUS C0, %d\n", !gpio_get_level(signal)); + /* VBUS present GPIO is inverted */ + int vbus_level = !gpio_get_level(signal); + + CPRINTF("VBUS C0, %d\n", vbus_level); + update_vbus_supplier(0, vbus_level); task_wake(TASK_ID_PD_C0); } void vbus1_evt(enum gpio_signal signal) { - CPRINTF("VBUS C1, %d\n", !gpio_get_level(signal)); + /* VBUS present GPIO is inverted */ + int vbus_level = !gpio_get_level(signal); + + CPRINTF("VBUS C1, %d\n", vbus_level); + update_vbus_supplier(0, vbus_level); task_wake(TASK_ID_PD_C1); } void usb0_evt(enum gpio_signal signal) { + task_wake(TASK_ID_USB_CHG_P0); } void usb1_evt(enum gpio_signal signal) { + task_wake(TASK_ID_USB_CHG_P1); } #include "gpio_list.h" @@ -98,6 +128,24 @@ const struct i2c_port_t i2c_ports[] = { }; const unsigned int i2c_ports_used = ARRAY_SIZE(i2c_ports); +struct pi3usb9281_config pi3usb9281_chips[] = { + { + .i2c_port = I2C_PORT_USB_CHARGER_1, + .mux_lock = NULL, + }, + { + .i2c_port = I2C_PORT_USB_CHARGER_2, + .mux_lock = NULL, + }, +}; +BUILD_ASSERT(ARRAY_SIZE(pi3usb9281_chips) == + CONFIG_USB_SWITCH_PI3USB9281_CHIP_COUNT); + +void board_set_usb_switches(int port, enum usb_switch setting) +{ + /* TODO: Set open / close USB switches based on param */ +} + /** * Discharge battery when on AC power for factory test. */ @@ -141,7 +189,7 @@ DECLARE_HOOK(HOOK_CHIPSET_PRE_INIT, pmic_init, HOOK_PRIO_DEFAULT); static void board_init(void) { int i; - struct charge_port_info charge_none, charge_vbus; + struct charge_port_info charge_none; /* Enable PD MCU interrupt */ gpio_enable_interrupt(GPIO_PD_MCU_INT); @@ -171,21 +219,12 @@ static void board_init(void) } /* Initialize VBUS supplier based on whether or not VBUS is present */ - charge_vbus.voltage = USB_BC12_CHARGE_VOLTAGE; - charge_vbus.current = DEFAULT_CURR_LIMIT; - if (!gpio_get_level(GPIO_USB_C0_VBUS_WAKE_L)) - charge_manager_update_charge(CHARGE_SUPPLIER_VBUS, 0, - &charge_vbus); - else - charge_manager_update_charge(CHARGE_SUPPLIER_VBUS, 0, - &charge_none); + update_vbus_supplier(0, !gpio_get_level(GPIO_USB_C0_VBUS_WAKE_L)); + update_vbus_supplier(1, !gpio_get_level(GPIO_USB_C1_VBUS_WAKE_L)); - if (!gpio_get_level(GPIO_USB_C1_VBUS_WAKE_L)) - charge_manager_update_charge(CHARGE_SUPPLIER_VBUS, 1, - &charge_vbus); - else - charge_manager_update_charge(CHARGE_SUPPLIER_VBUS, 1, - &charge_none); + /* Enable pericom BC1.2 interrupts */ + gpio_enable_interrupt(GPIO_USB_C0_BC12_INT_L); + gpio_enable_interrupt(GPIO_USB_C1_BC12_INT_L); } DECLARE_HOOK(HOOK_INIT, board_init, HOOK_PRIO_DEFAULT); diff --git a/board/glados/board.h b/board/glados/board.h index 923289388b..c16e9f8295 100644 --- a/board/glados/board.h +++ b/board/glados/board.h @@ -36,6 +36,7 @@ #define CONFIG_POWER_BUTTON #define CONFIG_POWER_BUTTON_X86 #define CONFIG_POWER_COMMON +#define CONFIG_USB_CHARGER #define CONFIG_USB_POWER_DELIVERY #define CONFIG_USB_PD_ALT_MODE #define CONFIG_USB_PD_ALT_MODE_DFP @@ -43,6 +44,8 @@ #define CONFIG_USB_PD_DUAL_ROLE #define CONFIG_USB_PD_PORT_COUNT 2 #define CONFIG_USB_PD_TCPM_TCPCI +#define CONFIG_USB_SWITCH_PI3USB9281 +#define CONFIG_USB_SWITCH_PI3USB9281_CHIP_COUNT 2 #define CONFIG_SCI_GPIO GPIO_PCH_SCI_L #define CONFIG_SPI_PORT 1 @@ -61,11 +64,13 @@ /* I2C ports */ #define I2C_PORT_BATTERY MEC1322_I2C0_0 #define I2C_PORT_CHARGER MEC1322_I2C0_0 +#define I2C_PORT_USB_CHARGER_1 MEC1322_I2C0_1 #define I2C_PORT_PD_MCU MEC1322_I2C1 #define I2C_PORT_TCPC MEC1322_I2C1 #define I2C_PORT_ALS MEC1322_I2C2 #define I2C_PORT_ACCEL MEC1322_I2C2 #define I2C_PORT_PMIC MEC1322_I2C3 +#define I2C_PORT_USB_CHARGER_2 MEC1322_I2C3 #undef DEFERRABLE_MAX_COUNT #define DEFERRABLE_MAX_COUNT 10 diff --git a/board/glados/ec.tasklist b/board/glados/ec.tasklist index 90f974cd29..b975e51679 100644 --- a/board/glados/ec.tasklist +++ b/board/glados/ec.tasklist @@ -18,6 +18,8 @@ */ #define CONFIG_TASK_LIST \ TASK_ALWAYS(HOOKS, hook_task, NULL, LARGER_TASK_STACK_SIZE) \ + TASK_ALWAYS(USB_CHG_P0, usb_charger_task, NULL, TASK_STACK_SIZE) \ + TASK_ALWAYS(USB_CHG_P1, usb_charger_task, NULL, TASK_STACK_SIZE) \ TASK_ALWAYS(CHARGER, charger_task, NULL, LARGER_TASK_STACK_SIZE) \ TASK_NOTEST(CHIPSET, chipset_task, NULL, LARGER_TASK_STACK_SIZE) \ TASK_NOTEST(KEYPROTO, keyboard_protocol_task, NULL, TASK_STACK_SIZE) \ |