Files
OpenCellular/common/usbc_ppc.c
Aseda Aboagye 755517e2cf ppc: Add API to set Vbus source ILIM.
The PPC needs to update its Vbus source current limits whenever our
policy changes on the PD ports.  This commit simply adds and API to do
so.

BUG=None
BRANCH=None
TEST=With some extra code to enable 3A out, flash zoombini; Plug in a PD
device to a port, verify that it gets 5V @ 3A.  Plug in a second device,
verify that we re-send new source caps of 5V @ 1.5A.
TEST=Repeat above for meowth.

Change-Id: Ifa4bc8b7df87f7730f2bcded842906d43171394b
Signed-off-by: Aseda Aboagye <aaboagye@google.com>
Reviewed-on: https://chromium-review.googlesource.com/818335
Commit-Ready: Aseda Aboagye <aaboagye@chromium.org>
Tested-by: Aseda Aboagye <aaboagye@chromium.org>
Reviewed-by: Shawn N <shawnn@chromium.org>
2017-12-13 22:33:22 -08:00

95 lines
2.2 KiB
C

/* 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_set_vbus_source_current_limit(int port, enum tcpc_rp_value rp)
{
if ((port < 0) || (port >= ppc_cnt))
return EC_ERROR_INVAL;
return ppc_chips[port].drv->set_vbus_source_current_limit(port, rp);
}
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);
}
#ifdef CONFIG_USB_PD_VBUS_DETECT_PPC
int ppc_is_vbus_present(int port, int *vbus_present)
{
if (port >= ppc_cnt)
return EC_ERROR_INVAL;
return ppc_chips[port].drv->is_vbus_present(port, vbus_present);
}
#endif /* defined(CONFIG_USB_PD_VBUS_DETECT_PPC) */
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) */