diff options
author | Aseda Aboagye <aaboagye@google.com> | 2017-11-29 23:26:36 -0800 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2017-12-06 01:08:24 -0800 |
commit | fb32b6d30cf55408f4bdb36b729c99452f6e8e11 (patch) | |
tree | 8506ce54893a0cf9953ea7bcaaf29d96eb1b0df9 /common | |
parent | fb43b2f4869182e9337c031a4d516ce820fe78d1 (diff) | |
download | chrome-ec-fb32b6d30cf55408f4bdb36b729c99452f6e8e11.tar.gz |
ppc: Create generic PPC driver framework.
This commit introduces a driver framework for power path controllers.
It provides some common PPC APIs as well as allowing a board to use
multiple different PPCs drivers/parts. This should make it easier to
add PPC drivers in the future.
BUG=None
BRANCH=None
TEST=`make -j buildall`
TEST=Flash zoombini; verify PPC works as expected.
TEST=Flash meowth; verify PPC works as expected.
Change-Id: Icfb99f384610590b431456cfd28d4aff18442cb2
Signed-off-by: Aseda Aboagye <aaboagye@google.com>
Reviewed-on: https://chromium-review.googlesource.com/807630
Commit-Ready: Aseda Aboagye <aaboagye@chromium.org>
Tested-by: Aseda Aboagye <aaboagye@chromium.org>
Reviewed-by: Edward Hill <ecgh@chromium.org>
Reviewed-by: Shawn N <shawnn@chromium.org>
Diffstat (limited to 'common')
-rw-r--r-- | common/build.mk | 1 | ||||
-rw-r--r-- | common/usbc_ppc.c | 76 |
2 files changed, 77 insertions, 0 deletions
diff --git a/common/build.mk b/common/build.mk index c0ea4bbd5f..70922f95fe 100644 --- a/common/build.mk +++ b/common/build.mk @@ -112,6 +112,7 @@ common-$(CONFIG_USB_POWER_DELIVERY)+=usb_pd_protocol.o usb_pd_policy.o common-$(CONFIG_USB_PD_LOGGING)+=event_log.o pd_log.o common-$(CONFIG_USB_PD_TCPC)+=usb_pd_tcpc.o common-$(CONFIG_USB_UPDATE)+=usb_update.o update_fw.o +common-$(CONFIG_USBC_PPC)+=usbc_ppc.o common-$(CONFIG_VBOOT_EFS)+=vboot/vboot.o common-$(CONFIG_VBOOT_HASH)+=sha256.o vboot_hash.o common-$(CONFIG_VOLUME_BUTTONS)+=button.o diff --git a/common/usbc_ppc.c b/common/usbc_ppc.c new file mode 100644 index 0000000000..5d41619a79 --- /dev/null +++ b/common/usbc_ppc.c @@ -0,0 +1,76 @@ +/* Copyright 2017 The Chromium OS Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +/* USB-C Power Path Controller Common Code */ + +#include "common.h" +#include "console.h" +#include "hooks.h" +#include "usbc_ppc.h" +#include "util.h" + +#define CPRINTF(format, args...) cprintf(CC_USBPD, format, ## args) +#define CPRINTS(format, args...) cprints(CC_USBPD, format, ## args) + +/* Simple wrappers to dispatch to the drivers. */ + +int ppc_is_sourcing_vbus(int port) +{ + if ((port < 0) || (port >= ppc_cnt)) { + CPRINTS("%s(%d) Invalid port!", __func__, port); + return 0; + } + + return ppc_chips[port].drv->is_sourcing_vbus(port); +} + +int ppc_vbus_sink_enable(int port, int enable) +{ + if ((port < 0) || (port >= ppc_cnt)) + return EC_ERROR_INVAL; + + return ppc_chips[port].drv->vbus_sink_enable(port, enable); +} + +int ppc_vbus_source_enable(int port, int enable) +{ + if ((port < 0) || (port >= ppc_cnt)) + return EC_ERROR_INVAL; + + return ppc_chips[port].drv->vbus_source_enable(port, enable); +} + +static void ppc_init(void) +{ + int i; + int rv; + + for (i = 0; i < ppc_cnt; i++) { + rv = ppc_chips[i].drv->init(i); + if (rv) + CPRINTS("p%d: PPC init failed! (%d)", i, rv); + else + CPRINTS("p%d: PPC init'd.", i); + } +} +DECLARE_HOOK(HOOK_INIT, ppc_init, HOOK_PRIO_INIT_I2C + 1); + +#ifdef CONFIG_CMD_PPC_DUMP +static int command_ppc_dump(int argc, char **argv) +{ + int port; + + if (argc < 2) + return EC_ERROR_PARAM_COUNT; + + port = atoi(argv[1]); + if (port >= ppc_cnt) + return EC_ERROR_PARAM1; + + return ppc_chips[port].drv->reg_dump(port); +} +DECLARE_CONSOLE_COMMAND(ppc_dump, command_ppc_dump, "<Type-C port>", + "dump the PPC regs"); +#endif /* defined(CONFIG_CMD_PPC_DUMP) */ |