mirror of
https://github.com/Telecominfraproject/OpenCellular.git
synced 2026-01-15 08:57:42 +00:00
The NX20P3483 is a USB PD and Type C high voltage sink/source combo switch. This CL adds support for this PPC variant. Unlike the TI SN5S330, the NX20P3483 does not support VCONN and does not need to be informed of CC polarity by the TCPM. To account for these differences, 2 new PPC config options are added and the driver for the TI SN5S330 was modified to include these new options. The SNK/SRC switch mode for the NX20P3483 is controlled by 2 GPIO signals which may be connected the EC or directly to the TCPC. To handle both cases, the ppc_chips structure was modified with a flags, snk_gpio, and src_gpio elements. BUG=b:74206647 BRANCH=none TEST=make -j buildall and verified there are no build errors. Change-Id: Ic4415ab7571b80e7661ea673434eaf4cf1f1fd2d Signed-off-by: Scott Collyer <scollyer@google.com> Reviewed-on: https://chromium-review.googlesource.com/966926 Commit-Ready: Scott Collyer <scollyer@chromium.org> Tested-by: Scott Collyer <scollyer@chromium.org> Reviewed-by: Aseda Aboagye <aaboagye@chromium.org> Reviewed-by: Furquan Shaikh <furquan@chromium.org>
127 lines
2.7 KiB
C
127 lines
2.7 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_init(int port)
|
|
{
|
|
int rv;
|
|
|
|
if (port >= ppc_cnt)
|
|
return EC_ERROR_INVAL;
|
|
|
|
rv = ppc_chips[port].drv->init(port);
|
|
if (rv)
|
|
CPRINTS("p%d: PPC init failed! (%d)", port, rv);
|
|
else
|
|
CPRINTS("p%d: PPC init'd.", port);
|
|
|
|
return rv;
|
|
}
|
|
|
|
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);
|
|
}
|
|
|
|
#ifdef CONFIG_USBC_PPC_POLARITY
|
|
int ppc_set_polarity(int port, int polarity)
|
|
{
|
|
if ((port < 0) || (port >= ppc_cnt))
|
|
return EC_ERROR_INVAL;
|
|
|
|
return ppc_chips[port].drv->set_polarity(port, polarity);
|
|
}
|
|
#endif
|
|
|
|
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_discharge_vbus(int port, int enable)
|
|
{
|
|
if ((port < 0) || (port >= ppc_cnt))
|
|
return EC_ERROR_INVAL;
|
|
|
|
return ppc_chips[port].drv->discharge_vbus(port, enable);
|
|
}
|
|
|
|
#ifdef CONFIG_USBC_PPC_VCONN
|
|
int ppc_set_vconn(int port, int enable)
|
|
{
|
|
if ((port < 0) || (port >= ppc_cnt))
|
|
return EC_ERROR_INVAL;
|
|
|
|
return ppc_chips[port].drv->set_vconn(port, enable);
|
|
}
|
|
#endif
|
|
|
|
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)
|
|
{
|
|
if ((port < 0) || (port >= ppc_cnt)) {
|
|
CPRINTS("%s(%d) Invalid port!", __func__, port);
|
|
return 0;
|
|
}
|
|
|
|
return ppc_chips[port].drv->is_vbus_present(port);
|
|
}
|
|
#endif /* defined(CONFIG_USB_PD_VBUS_DETECT_PPC) */
|
|
|
|
|
|
#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) */
|