summaryrefslogtreecommitdiff
path: root/common/usbc_ppc.c
diff options
context:
space:
mode:
authorDenis Brockus <dbrockus@chromium.org>2019-09-27 13:25:14 -0600
committerCommit Bot <commit-bot@chromium.org>2019-10-06 22:55:08 +0000
commitcfb6d3ded36e6b7935f8693532f6f9031643865d (patch)
tree8a59dccf74d4f3a8ad1f54cc6000f3b1a98f203f /common/usbc_ppc.c
parent437e7346ab38a1eca1bb8526ae03b120635f03e9 (diff)
downloadchrome-ec-cfb6d3ded36e6b7935f8693532f6f9031643865d.tar.gz
ppc: cleanup ppc
Allow limited PPC chips to default to EC_ERROR_UNIMPLEMENTED for functions in the driver that are not needed. BUG=b:138599218 BRANCH=none TEST=make buildall -j Change-Id: I5242ef285eb277c06d516ab09f7a74f76d7d34b2 Signed-off-by: Denis Brockus <dbrockus@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1829405 Reviewed-by: Edward Hill <ecgh@chromium.org>
Diffstat (limited to 'common/usbc_ppc.c')
-rw-r--r--common/usbc_ppc.c184
1 files changed, 147 insertions, 37 deletions
diff --git a/common/usbc_ppc.c b/common/usbc_ppc.c
index 60a514d0f3..4274443a3d 100644
--- a/common/usbc_ppc.c
+++ b/common/usbc_ppc.c
@@ -13,8 +13,13 @@
#include "usbc_ppc.h"
#include "util.h"
+#ifndef TEST_BUILD
#define CPRINTF(format, args...) cprintf(CC_USBPD, format, ## args)
#define CPRINTS(format, args...) cprints(CC_USBPD, format, ## args)
+#else
+#define CPRINTF(args...)
+#define CPRINTS(args...)
+#endif
/*
* A per-port table that indicates how many VBUS overcurrent events have
@@ -29,24 +34,32 @@ static uint32_t connected_ports;
int ppc_init(int port)
{
- int rv;
+ int rv = EC_ERROR_UNIMPLEMENTED;
+ const struct ppc_config_t *ppc;
- if (port >= ppc_cnt)
+ if ((port < 0) || (port >= ppc_cnt)) {
+ CPRINTS("%s(%d) Invalid port!", __func__, port);
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);
+ ppc = &ppc_chips[port];
+ if (ppc->drv->init) {
+ rv = ppc->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_add_oc_event(int port)
{
- if ((port < 0) || (port >= ppc_cnt))
+ if ((port < 0) || (port >= ppc_cnt)) {
+ CPRINTS("%s(%d) Invalid port!", __func__, port);
return EC_ERROR_INVAL;
+ }
oc_event_cnt_tbl[port]++;
@@ -79,8 +92,10 @@ DECLARE_DEFERRED(clear_oc_tbl);
int ppc_clear_oc_event_counter(int port)
{
- if ((port < 0) || (port >= ppc_cnt))
+ if ((port < 0) || (port >= ppc_cnt)) {
+ CPRINTS("%s(%d) Invalid port!", __func__, port);
return EC_ERROR_INVAL;
+ }
/*
* If we are clearing our event table in quick succession, we may be in
@@ -98,44 +113,80 @@ int ppc_clear_oc_event_counter(int port)
int ppc_is_sourcing_vbus(int port)
{
+ int rv = EC_ERROR_UNIMPLEMENTED;
+ const struct ppc_config_t *ppc;
+
if ((port < 0) || (port >= ppc_cnt)) {
CPRINTS("%s(%d) Invalid port!", __func__, port);
- return 0;
+ return EC_ERROR_INVAL;
}
- return ppc_chips[port].drv->is_sourcing_vbus(port);
+ ppc = &ppc_chips[port];
+ if (ppc->drv->is_sourcing_vbus)
+ rv = ppc->drv->is_sourcing_vbus(port);
+
+ return rv;
}
#ifdef CONFIG_USBC_PPC_POLARITY
int ppc_set_polarity(int port, int polarity)
{
- if ((port < 0) || (port >= ppc_cnt))
+ int rv = EC_ERROR_UNIMPLEMENTED;
+ const struct ppc_config_t *ppc;
+
+ if ((port < 0) || (port >= ppc_cnt)) {
+ CPRINTS("%s(%d) Invalid port!", __func__, port);
return EC_ERROR_INVAL;
+ }
+
+ ppc = &ppc_chips[port];
+ if (ppc->drv->set_polarity)
+ rv = ppc->drv->set_polarity(port, polarity);
- return ppc_chips[port].drv->set_polarity(port, polarity);
+ return rv;
}
#endif
int ppc_set_vbus_source_current_limit(int port, enum tcpc_rp_value rp)
{
- if ((port < 0) || (port >= ppc_cnt))
+ int rv = EC_ERROR_UNIMPLEMENTED;
+ const struct ppc_config_t *ppc;
+
+ if ((port < 0) || (port >= ppc_cnt)) {
+ CPRINTS("%s(%d) Invalid port!", __func__, port);
return EC_ERROR_INVAL;
+ }
- return ppc_chips[port].drv->set_vbus_source_current_limit(port, rp);
+ ppc = &ppc_chips[port];
+ if (ppc->drv->set_vbus_source_current_limit)
+ rv = ppc->drv->set_vbus_source_current_limit(port, rp);
+
+ return rv;
}
int ppc_discharge_vbus(int port, int enable)
{
- if ((port < 0) || (port >= ppc_cnt))
+ int rv = EC_ERROR_UNIMPLEMENTED;
+ const struct ppc_config_t *ppc;
+
+ if ((port < 0) || (port >= ppc_cnt)) {
+ CPRINTS("%s(%d) Invalid port!", __func__, port);
return EC_ERROR_INVAL;
+ }
+
+ ppc = &ppc_chips[port];
+ if (ppc->drv->discharge_vbus)
+ rv = ppc->drv->discharge_vbus(port, enable);
- return ppc_chips[port].drv->discharge_vbus(port, enable);
+ return rv;
}
int ppc_is_port_latched_off(int port)
{
- if ((port < 0) || (port >= ppc_cnt))
- return 0;
+ if ((port < 0) || (port >= ppc_cnt)) {
+ CPRINTS("%s(%d) Invalid port!", __func__, port);
+ return EC_ERROR_INVAL;
+ }
return oc_event_cnt_tbl[port] >= PPC_OC_CNT_THRESH;
}
@@ -143,18 +194,32 @@ int ppc_is_port_latched_off(int port)
#ifdef CONFIG_USBC_PPC_SBU
int ppc_set_sbu(int port, int enable)
{
- if ((port < 0) || (port >= ppc_cnt))
+ int rv = EC_ERROR_UNIMPLEMENTED;
+ const struct ppc_config_t *ppc;
+
+ if ((port < 0) || (port >= ppc_cnt)) {
+ CPRINTS("%s(%d) Invalid port!", __func__, port);
return EC_ERROR_INVAL;
+ }
- return ppc_chips[port].drv->set_sbu(port, enable);
+ ppc = &ppc_chips[port];
+ if (ppc->drv->set_sbu)
+ rv = ppc->drv->set_sbu(port, enable);
+
+ return rv;
}
#endif /* defined(CONFIG_USBC_PPC_SBU) */
#ifdef CONFIG_USBC_PPC_VCONN
int ppc_set_vconn(int port, int enable)
{
- if ((port < 0) || (port >= ppc_cnt))
+ int rv = EC_ERROR_UNIMPLEMENTED;
+ const struct ppc_config_t *ppc;
+
+ if ((port < 0) || (port >= ppc_cnt)) {
+ CPRINTS("%s(%d) Invalid port!", __func__, port);
return EC_ERROR_INVAL;
+ }
/*
* Check our OC event counter. If we've exceeded our threshold, then
@@ -165,12 +230,21 @@ int ppc_set_vconn(int port, int enable)
if (enable && ppc_is_port_latched_off(port))
return EC_ERROR_ACCESS_DENIED;
- return ppc_chips[port].drv->set_vconn(port, enable);
+ ppc = &ppc_chips[port];
+ if (ppc->drv->set_vconn)
+ rv = ppc->drv->set_vconn(port, enable);
+
+ return rv;
}
#endif
void ppc_sink_is_connected(int port, int is_connected)
{
+ if ((port < 0) || (port >= ppc_cnt)) {
+ CPRINTS("%s(%d) Invalid port!", __func__, port);
+ return;
+ }
+
if (is_connected)
atomic_or(&connected_ports, 1 << port);
else
@@ -179,31 +253,47 @@ void ppc_sink_is_connected(int port, int is_connected)
int ppc_vbus_sink_enable(int port, int enable)
{
- if ((port < 0) || (port >= ppc_cnt))
+ int rv = EC_ERROR_UNIMPLEMENTED;
+ const struct ppc_config_t *ppc;
+
+ if ((port < 0) || (port >= ppc_cnt)) {
+ CPRINTS("%s(%d) Invalid port!", __func__, port);
return EC_ERROR_INVAL;
+ }
- return ppc_chips[port].drv->vbus_sink_enable(port, enable);
+ ppc = &ppc_chips[port];
+ if (ppc->drv->vbus_sink_enable)
+ rv = ppc->drv->vbus_sink_enable(port, enable);
+
+ return rv;
}
int ppc_enter_low_power_mode(int port)
{
+ int rv = EC_ERROR_UNIMPLEMENTED;
const struct ppc_config_t *ppc;
- if ((port < 0) || (port >= ppc_cnt))
+ if ((port < 0) || (port >= ppc_cnt)) {
+ CPRINTS("%s(%d) Invalid port!", __func__, port);
return EC_ERROR_INVAL;
+ }
ppc = &ppc_chips[port];
-
if (ppc->drv->enter_low_power_mode)
- return ppc->drv->enter_low_power_mode(port);
- else
- return EC_ERROR_UNIMPLEMENTED;
+ rv = ppc->drv->enter_low_power_mode(port);
+
+ return rv;
}
int ppc_vbus_source_enable(int port, int enable)
{
- if ((port < 0) || (port >= ppc_cnt))
+ int rv = EC_ERROR_UNIMPLEMENTED;
+ const struct ppc_config_t *ppc;
+
+ if ((port < 0) || (port >= ppc_cnt)) {
+ CPRINTS("%s(%d) Invalid port!", __func__, port);
return EC_ERROR_INVAL;
+ }
/*
* Check our OC event counter. If we've exceeded our threshold, then
@@ -214,18 +304,30 @@ int ppc_vbus_source_enable(int port, int enable)
if (enable && ppc_is_port_latched_off(port))
return EC_ERROR_ACCESS_DENIED;
- return ppc_chips[port].drv->vbus_source_enable(port, enable);
+ ppc = &ppc_chips[port];
+ if (ppc->drv->vbus_source_enable)
+ rv = ppc->drv->vbus_source_enable(port, enable);
+
+ return rv;
}
#ifdef CONFIG_USB_PD_VBUS_DETECT_PPC
int ppc_is_vbus_present(int port)
{
+ int rv = EC_ERROR_UNIMPLEMENTED;
+ const struct ppc_config_t *ppc;
+
if ((port < 0) || (port >= ppc_cnt)) {
CPRINTS("%s(%d) Invalid port!", __func__, port);
- return 0;
+ return EC_ERROR_INVAL;
}
- return ppc_chips[port].drv->is_vbus_present(port);
+ ppc = &ppc_chips[port];
+
+ if (ppc->drv->is_vbus_present)
+ rv = ppc->drv->is_vbus_present(port);
+
+ return rv;
}
#endif /* defined(CONFIG_USB_PD_VBUS_DETECT_PPC) */
@@ -233,15 +335,23 @@ int ppc_is_vbus_present(int port)
static int command_ppc_dump(int argc, char **argv)
{
int port;
+ int rv = EC_ERROR_UNIMPLEMENTED;
+ const struct ppc_config_t *ppc;
if (argc < 2)
return EC_ERROR_PARAM_COUNT;
port = atoi(argv[1]);
- if (port >= ppc_cnt)
- return EC_ERROR_PARAM1;
+ if ((port < 0) || (port >= ppc_cnt)) {
+ CPRINTS("%s(%d) Invalid port!", __func__, port);
+ return EC_ERROR_INVAL;
+ }
- return ppc_chips[port].drv->reg_dump(port);
+ ppc = &ppc_chips[port];
+ if (ppc->drv->reg_dump)
+ rv = ppc->drv->reg_dump(port);
+
+ return rv;
}
DECLARE_CONSOLE_COMMAND(ppc_dump, command_ppc_dump, "<Type-C port>",
"dump the PPC regs");