summaryrefslogtreecommitdiff
path: root/board/grunt/board.c
diff options
context:
space:
mode:
authorEdward Hill <ecgh@chromium.org>2017-12-08 17:36:00 -0700
committerchrome-bot <chrome-bot@chromium.org>2017-12-13 12:33:40 -0800
commit69173f990a7c02967261595f27ef98eb312db44a (patch)
tree26191b6578c3bb73a4dcd4752c81e9a9edd56dba /board/grunt/board.c
parent7d2ce0c47e06622e2f423d33eec5ffceeeeb6a01 (diff)
downloadchrome-ec-69173f990a7c02967261595f27ef98eb312db44a.tar.gz
grunt: Use PPC for USB PD
Use the new PPC functions to fill in more of the USB PD board code: board_set_active_charge_port board_vbus_source_enabled pd_snk_is_vbus_provided pd_set_power_supply_ready pd_power_supply_reset BUG=b:69378796 BRANCH=none TEST=make BOARD=grunt Change-Id: Ie6c7da8575edbb11d5a4d28da3b228abd811a5a7 Signed-off-by: Edward Hill <ecgh@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/818504 Reviewed-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'board/grunt/board.c')
-rw-r--r--board/grunt/board.c70
1 files changed, 60 insertions, 10 deletions
diff --git a/board/grunt/board.c b/board/grunt/board.c
index f1ca30358f..65beb7ad68 100644
--- a/board/grunt/board.c
+++ b/board/grunt/board.c
@@ -37,8 +37,12 @@
#include "thermistor.h"
#include "usb_mux.h"
#include "usb_pd_tcpm.h"
+#include "usbc_ppc.h"
#include "util.h"
+#define CPRINTS(format, args...) cprints(CC_USBCHARGE, format, ## args)
+#define CPRINTF(format, args...) cprintf(CC_USBCHARGE, format, ## args)
+
static void tcpc_alert_event(enum gpio_signal signal)
{
if ((signal == GPIO_USB_C0_PD_INT_ODL) &&
@@ -168,11 +172,19 @@ struct usb_mux usb_muxes[CONFIG_USB_PD_PORT_COUNT] = {
}
};
-const struct sn5s330_config sn5s330_chips[] = {
- {I2C_PORT_TCPC0, SN5S330_ADDR0},
- {I2C_PORT_TCPC1, SN5S330_ADDR0},
+const struct ppc_config_t ppc_chips[] = {
+ {
+ .i2c_port = I2C_PORT_TCPC0,
+ .i2c_addr = SN5S330_ADDR0,
+ .drv = &sn5s330_drv
+ },
+ {
+ .i2c_port = I2C_PORT_TCPC1,
+ .i2c_addr = SN5S330_ADDR0,
+ .drv = &sn5s330_drv
+ },
};
-const unsigned int sn5s330_cnt = ARRAY_SIZE(sn5s330_chips);
+const unsigned int ppc_cnt = ARRAY_SIZE(ppc_chips);
const int usb_port_enable[CONFIG_USB_PORT_POWER_SMART_PORT_COUNT] = {
GPIO_EN_USB_A0_5V,
@@ -262,17 +274,55 @@ void board_tcpc_init(void)
}
}
-int pd_snk_is_vbus_provided(int port)
+void board_overcurrent_event(int port)
{
- /* TODO(ecgh): Detect VBUS via SWCTL_INT and I2C to SN5S330 */
- return 0;
+ /* TODO(ecgh): assert GPIO to notify SOC */
}
int board_set_active_charge_port(int port)
{
- /* TODO(ecgh): how to disable/enable charge ports? */
- /* TODO(ecgh): how to check if port sourcing VBUS? */
- /* TODO(ecgh): disable/enable SN5S330 FETs? */
+ int i;
+ int rv;
+
+ CPRINTS("New chg p%d", port);
+
+ if (port == CHARGE_PORT_NONE) {
+ /* Disable all ports. */
+ for (i = 0; i < ppc_cnt; i++) {
+ rv = ppc_vbus_sink_enable(i, 0);
+ if (rv) {
+ CPRINTS("Disabling p%d sink path failed.", i);
+ return rv;
+ }
+ }
+
+ return EC_SUCCESS;
+ }
+
+ /* Check if the port is sourcing VBUS. */
+ if (ppc_is_sourcing_vbus(port)) {
+ CPRINTF("Skip enable p%d", port);
+ return EC_ERROR_INVAL;
+ }
+
+ /*
+ * Turn off the other ports' sink path FETs, before enabling the
+ * requested charge port.
+ */
+ for (i = 0; i < ppc_cnt; i++) {
+ if (i == port)
+ continue;
+
+ if (ppc_vbus_sink_enable(i, 0))
+ CPRINTS("p%d: sink path disable failed.", i);
+ }
+
+ /* Enable requested charge port. */
+ if (ppc_vbus_sink_enable(port, 1)) {
+ CPRINTS("p%d: sink path enable failed.");
+ return EC_ERROR_UNKNOWN;
+ }
+
return EC_SUCCESS;
}