From fb43b2f4869182e9337c031a4d516ce820fe78d1 Mon Sep 17 00:00:00 2001 From: Aseda Aboagye Date: Mon, 27 Nov 2017 11:12:19 -0800 Subject: [PATCH] meowth: zoombini: Use PPC calls instead of GPIOs. The next revisions of these boards have the PPCs stuffed instead of load switches. Therefore, replace the GPIO enables with calls to the PPC instead. BUG=None BRANCH=None TEST=make -j buildall Change-Id: I6b9f198b60fa89cf45e45f83c67b117bad3f9179 Signed-off-by: Aseda Aboagye Reviewed-on: https://chromium-review.googlesource.com/791500 Commit-Ready: Aseda Aboagye Tested-by: Aseda Aboagye Reviewed-by: Shawn N --- board/zoombini/board.c | 51 +++++++++++++------------- board/zoombini/board.h | 1 + board/zoombini/gpio.inc | 8 ----- board/zoombini/usb_pd_policy.c | 65 +++++++--------------------------- 4 files changed, 41 insertions(+), 84 deletions(-) diff --git a/board/zoombini/board.c b/board/zoombini/board.c index 6dda4420d3..d728df4ae3 100644 --- a/board/zoombini/board.c +++ b/board/zoombini/board.c @@ -305,49 +305,52 @@ int board_set_active_charge_port(int port) int is_real_port = (port >= 0 && port < CONFIG_USB_PD_PORT_COUNT); int i; + int rv; + int is_enabled; if (!is_real_port && port != CHARGE_PORT_NONE) return EC_ERROR_INVAL; CPRINTS("New chg p%d", port); -#ifdef BOARD_ZOOMBINI if (port == CHARGE_PORT_NONE) { /* Disable all ports. */ - gpio_set_level(GPIO_USB_C0_CHARGE_EN_L, 1); - gpio_set_level(GPIO_USB_C1_CHARGE_EN_L, 1); - gpio_set_level(GPIO_USB_C2_CHARGE_EN_L, 1); + for (i = 0; i < sn5s330_cnt; i++) { + rv = sn5s330_pp_fet_enable(i, SN5S330_PP2, 0); + if (rv) { + CPRINTS("Disabling C%d PP2 FET failed.", i); + return rv; + } + } + return EC_SUCCESS; } /* Check if the port is sourcing VBUS. */ - if (((port == 0) && gpio_get_level(GPIO_USB_C0_5V_EN)) || - ((port == 1) && gpio_get_level(GPIO_USB_C1_5V_EN)) || - ((port == 2) && gpio_get_level(GPIO_USB_C2_5V_EN))) { + if (sn5s330_is_pp_fet_enabled(port, SN5S330_PP1, &is_enabled)) + return EC_ERROR_UNKNOWN; + + if (is_enabled) { CPRINTF("Skip enable p%d", port); return EC_ERROR_INVAL; } - /* Disable other charge ports and enable requested port. */ - gpio_set_level(GPIO_USB_C0_CHARGE_EN_L, port != 0); - gpio_set_level(GPIO_USB_C1_CHARGE_EN_L, port != 1); - gpio_set_level(GPIO_USB_C2_CHARGE_EN_L, port != 2); - -#endif /* defined(BOARD_ZOOMBINI) */ /* - * TODO(aaboagye): Remove manual charge enabling on P1 - - * switched to sn5s330 - */ - - - /* - * Turn on the PP2 FET such that power actually flows and turn off the - * non-charge ports' PP2 FETs. + * Turn off the other ports' PP2 FET, before enabling the requested + * charge port. */ for (i = 0; i < sn5s330_cnt; i++) { - if (sn5s330_pp_fet_enable(i, SN5S330_PP2, port == i)) - CPRINTF("%sabling C%d PP2 FET failed.", - port == i ? "En" : "Dis", port); + if (i == port) + continue; + + if (sn5s330_pp_fet_enable(i, SN5S330_PP2, 0)) + CPRINTS("C%d: PP2 disable failed.", i); + } + + /* Enable requested charge port. */ + if (sn5s330_pp_fet_enable(port, SN5S330_PP2, 1)) { + CPRINTS("C%d: PP2 enable failed."); + return EC_ERROR_UNKNOWN; } return EC_SUCCESS; diff --git a/board/zoombini/board.h b/board/zoombini/board.h index 72b977cec0..37ca260ca0 100644 --- a/board/zoombini/board.h +++ b/board/zoombini/board.h @@ -11,6 +11,7 @@ /* Optional features */ #define CONFIG_HIBERNATE_PSL #define CONFIG_SYSTEM_UNLOCKED /* Allow dangerous commands. */ +#define CONFIG_CMD_PPC_DUMP /* NPCX7 config */ #define NPCX_UART_MODULE2 1 /* GPIO64/65 are used as UART pins. */ diff --git a/board/zoombini/gpio.inc b/board/zoombini/gpio.inc index 7c12544682..97b2cd6db5 100644 --- a/board/zoombini/gpio.inc +++ b/board/zoombini/gpio.inc @@ -71,14 +71,6 @@ GPIO(USB_PD_RST_L, PIN(F, 1), GPIO_ODR_HIGH) GPIO(USB_A_5V_EN, PIN(A, 0), GPIO_ODR_LOW) GPIO(USB_A_HIGH_POWER_EN, PIN(A, 2), GPIO_ODR_LOW) -GPIO(USB_C0_5V_EN, PIN(6, 7), GPIO_OUT_LOW) -GPIO(USB_C1_5V_EN, PIN(7, 0), GPIO_OUT_LOW) -GPIO(USB_C2_5V_EN, PIN(6, 3), GPIO_OUT_LOW) - -GPIO(USB_C0_CHARGE_EN_L, PIN(0, 3), GPIO_OUT_LOW) -GPIO(USB_C1_CHARGE_EN_L, PIN(0, 4), GPIO_OUT_LOW) -GPIO(USB_C2_CHARGE_EN_L, PIN(4, 0), GPIO_OUT_LOW) - GPIO(USB_C0_BC12_VBUS_ON_L, PIN(8, 2), GPIO_ODR_HIGH) GPIO(USB_C1_BC12_VBUS_ON_L, PIN(B, 1), GPIO_ODR_HIGH) GPIO(USB_C2_BC12_VBUS_ON_L, PIN(E, 0), GPIO_ODR_HIGH) diff --git a/board/zoombini/usb_pd_policy.c b/board/zoombini/usb_pd_policy.c index cec3b32453..7623afb5f7 100644 --- a/board/zoombini/usb_pd_policy.c +++ b/board/zoombini/usb_pd_policy.c @@ -7,6 +7,7 @@ #include "common.h" #include "console.h" #include "compile_time_macros.h" +#include "driver/ppc/sn5s330.h" #include "ec_commands.h" #include "gpio.h" #include "system.h" @@ -104,27 +105,8 @@ int pd_is_valid_input_voltage(int mv) void pd_power_supply_reset(int port) { -#ifdef BOARD_ZOOMBINI /* Disable VBUS. */ - switch (port) { - case 0: - gpio_set_level(GPIO_USB_C0_5V_EN, 0); - break; - - case 1: - gpio_set_level(GPIO_USB_C1_5V_EN, 0); - break; - - case 2: - gpio_set_level(GPIO_USB_C2_5V_EN, 0); - break; - - default: - return; - }; -#else - /*TODO(aaboagye): Implement sn5s330 PPC for both Zoombini and Meowth */ -#endif /* defined(BOARD_ZOOMBINI) */ + sn5s330_pp_fet_enable(port, SN5S330_PP1, 0); /* Notify host of power info change. */ pd_send_host_event(PD_EVENT_POWER_CHANGE); @@ -132,41 +114,20 @@ void pd_power_supply_reset(int port) int pd_set_power_supply_ready(int port) { -#ifdef BOARD_ZOOMBINI - switch (port) { - case 0: - /* Disable charging. */ - gpio_set_level(GPIO_USB_C0_CHARGE_EN_L, 1); + int rv; - /* Provide VBUS. */ - gpio_set_level(GPIO_USB_C0_5V_EN, 1); + if (port >= sn5s330_cnt) + return EC_ERROR_INVAL; - break; + /* Disable charging. */ + rv = sn5s330_pp_fet_enable(port, SN5S330_PP2, 0); + if (rv) + return rv; - case 1: - /* Disable charging. */ - gpio_set_level(GPIO_USB_C1_CHARGE_EN_L, 1); - - /* Provide VBUS. */ - gpio_set_level(GPIO_USB_C1_5V_EN, 1); - - break; - - case 2: - /* Disable charging. */ - gpio_set_level(GPIO_USB_C2_CHARGE_EN_L, 1); - - /* Provide VBUS. */ - gpio_set_level(GPIO_USB_C2_5V_EN, 1); - - break; - - default: - break; - }; -#else - /*TODO(aaboagye): Implement sn5s330 PPC for both Zoombini and Meowth */ -#endif /* defined(BOARD_ZOOMBINI) */ + /* Provide Vbus. */ + rv = sn5s330_pp_fet_enable(port, SN5S330_PP1, 1); + if (rv) + return rv; /* Notify host of power info change. */ pd_send_host_event(PD_EVENT_POWER_CHANGE);