summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVijay Hiremath <vijay.p.hiremath@intel.com>2020-02-10 16:00:42 -0800
committerCommit Bot <commit-bot@chromium.org>2020-02-12 20:05:31 +0000
commit7460621eae83145ea57d42c0eb6daf486286f234 (patch)
treedb327d2b2bcf77442f6d7f5284ab55247cbb7515
parente34464e92cc0d13e1fc4a7647897bf534be52444 (diff)
downloadchrome-ec-7460621eae83145ea57d42c0eb6daf486286f234.tar.gz
TCPMv1/v2: Move pd_check_requested_voltage() to common file
BUG=b:148528713 BRANCH=none TEST=make buildall -j Change-Id: I5ba854552b5c6124e3c6758273651edc0e3c23ae Signed-off-by: Vijay Hiremath <vijay.p.hiremath@intel.com> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2051214 Reviewed-by: Keith Short <keithshort@chromium.org>
-rw-r--r--board/plankton/usb_pd_policy.c9
-rw-r--r--board/zinger/usb_pd_policy.c8
-rw-r--r--common/usb_common.c48
-rw-r--r--common/usb_pd_policy.c45
-rw-r--r--common/usbc/usb_pe_drp_sm.c48
-rw-r--r--include/usb_pd.h2
6 files changed, 50 insertions, 110 deletions
diff --git a/board/plankton/usb_pd_policy.c b/board/plankton/usb_pd_policy.c
index d575e29f83..87718648f1 100644
--- a/board/plankton/usb_pd_policy.c
+++ b/board/plankton/usb_pd_policy.c
@@ -68,15 +68,6 @@ void pd_set_input_current_limit(int port, uint32_t max_ma,
return;
}
-int pd_board_check_request(uint32_t rdo, int pdo_cnt)
-{
- int idx = RDO_POS(rdo);
-
- /* Check for invalid index */
- return (!idx || idx > pdo_cnt) ?
- EC_ERROR_INVAL : EC_SUCCESS;
-}
-
__override void pd_transition_voltage(int idx)
{
gpio_set_level(GPIO_USBC_VSEL_0, idx >= 2);
diff --git a/board/zinger/usb_pd_policy.c b/board/zinger/usb_pd_policy.c
index fba299c89b..f47789e063 100644
--- a/board/zinger/usb_pd_policy.c
+++ b/board/zinger/usb_pd_policy.c
@@ -198,18 +198,12 @@ static int discharge_volt_idx;
/* output current measurement */
int vbus_amp;
-int pd_board_check_request(uint32_t rdo, int pdo_cnt)
+__override int pd_board_check_request(uint32_t rdo, int pdo_cnt)
{
- int idx = RDO_POS(rdo);
-
/* fault condition or output disabled: reject transitions */
if (fault != FAULT_OK || !output_is_enabled())
return EC_ERROR_INVAL;
- /* Invalid index */
- if (!idx || idx > pd_src_pdo_cnt)
- return EC_ERROR_INVAL;
-
return EC_SUCCESS;
}
diff --git a/common/usb_common.c b/common/usb_common.c
index e5255fc339..814a209da3 100644
--- a/common/usb_common.c
+++ b/common/usb_common.c
@@ -9,6 +9,7 @@
*/
#include "atomic.h"
+#include "charge_manager.h"
#include "charge_state.h"
#include "chipset.h"
#include "common.h"
@@ -155,6 +156,53 @@ enum pd_cc_states pd_get_cc_state(
return PD_CC_NONE;
}
+__overridable int pd_board_check_request(uint32_t rdo, int pdo_cnt)
+{
+ return EC_SUCCESS;
+}
+
+int pd_check_requested_voltage(uint32_t rdo, const int port)
+{
+ int max_ma = rdo & 0x3FF;
+ int op_ma = (rdo >> 10) & 0x3FF;
+ int idx = RDO_POS(rdo);
+ uint32_t pdo;
+ uint32_t pdo_ma;
+#if defined(CONFIG_USB_PD_DYNAMIC_SRC_CAP) || \
+ defined(CONFIG_USB_PD_MAX_SINGLE_SOURCE_CURRENT)
+ const uint32_t *src_pdo;
+ const int pdo_cnt = charge_manager_get_source_pdo(&src_pdo, port);
+#else
+ const uint32_t *src_pdo = pd_src_pdo;
+ const int pdo_cnt = pd_src_pdo_cnt;
+#endif
+
+ /* Check for invalid index */
+ if (!idx || idx > pdo_cnt)
+ return EC_ERROR_INVAL;
+
+ /* Board specific check for this request */
+ if (pd_board_check_request(rdo, pdo_cnt))
+ return EC_ERROR_INVAL;
+
+ /* check current ... */
+ pdo = src_pdo[idx - 1];
+ pdo_ma = (pdo & 0x3ff);
+
+ if (op_ma > pdo_ma)
+ return EC_ERROR_INVAL; /* too much op current */
+
+ if (max_ma > pdo_ma && !(rdo & RDO_CAP_MISMATCH))
+ return EC_ERROR_INVAL; /* too much max current */
+
+ CPRINTF("Requested %d mV %d mA (for %d/%d mA)\n",
+ ((pdo >> 10) & 0x3ff) * 50, (pdo & 0x3ff) * 10,
+ op_ma * 10, max_ma * 10);
+
+ /* Accept the requested voltage */
+ return EC_SUCCESS;
+}
+
/*
* Zinger implements a board specific usb policy that does not define
* PD_MAX_VOLTAGE_MV and PD_OPERATING_POWER_MW. And in turn, does not
diff --git a/common/usb_pd_policy.c b/common/usb_pd_policy.c
index e2e6ed3b42..29e13017c7 100644
--- a/common/usb_pd_policy.c
+++ b/common/usb_pd_policy.c
@@ -53,51 +53,6 @@ void pd_notify_dp_alt_mode_entry(void)
}
#endif /* CONFIG_MKBP_EVENT */
-int pd_check_requested_voltage(uint32_t rdo, const int port)
-{
- int max_ma = rdo & 0x3FF;
- int op_ma = (rdo >> 10) & 0x3FF;
- int idx = RDO_POS(rdo);
- uint32_t pdo;
- uint32_t pdo_ma;
-#if defined(CONFIG_USB_PD_DYNAMIC_SRC_CAP) || \
- defined(CONFIG_USB_PD_MAX_SINGLE_SOURCE_CURRENT)
- const uint32_t *src_pdo;
- const int pdo_cnt = charge_manager_get_source_pdo(&src_pdo, port);
-#else
- const uint32_t *src_pdo = pd_src_pdo;
- const int pdo_cnt = pd_src_pdo_cnt;
-#endif
-
- /* Board specific check for this request */
- if (pd_board_check_request(rdo, pdo_cnt))
- return EC_ERROR_INVAL;
-
- /* check current ... */
- pdo = src_pdo[idx - 1];
- pdo_ma = (pdo & 0x3ff);
- if (op_ma > pdo_ma)
- return EC_ERROR_INVAL; /* too much op current */
- if (max_ma > pdo_ma && !(rdo & RDO_CAP_MISMATCH))
- return EC_ERROR_INVAL; /* too much max current */
-
- CPRINTF("Requested %d mV %d mA (for %d/%d mA)\n",
- ((pdo >> 10) & 0x3ff) * 50, (pdo & 0x3ff) * 10,
- op_ma * 10, max_ma * 10);
-
- /* Accept the requested voltage */
- return EC_SUCCESS;
-}
-
-__attribute__((weak)) int pd_board_check_request(uint32_t rdo, int pdo_cnt)
-{
- int idx = RDO_POS(rdo);
-
- /* Check for invalid index */
- return (!idx || idx > pdo_cnt) ?
- EC_ERROR_INVAL : EC_SUCCESS;
-}
-
#ifdef CONFIG_USB_PD_DUAL_ROLE
/* Last received source cap */
static uint32_t pd_src_caps[CONFIG_USB_PD_PORT_MAX_COUNT][PDO_MAX_OBJECTS];
diff --git a/common/usbc/usb_pe_drp_sm.c b/common/usbc/usb_pe_drp_sm.c
index 01b27e21b6..46caa7082b 100644
--- a/common/usbc/usb_pe_drp_sm.c
+++ b/common/usbc/usb_pe_drp_sm.c
@@ -944,15 +944,6 @@ int pd_is_port_partner_dualrole(int port)
return PE_CHK_FLAG(port, PE_FLAGS_PORT_PARTNER_IS_DUALROLE);
}
-int pd_board_check_request(uint32_t rdo, int pdo_cnt)
-{
- int idx = RDO_POS(rdo);
-
- /* Check for invalid index */
- return (!idx || idx > pdo_cnt) ?
- EC_ERROR_INVAL : EC_SUCCESS;
-}
-
static void pe_prl_execute_hard_reset(int port)
{
prl_execute_hard_reset(port);
@@ -4444,45 +4435,6 @@ static void pe_dr_snk_get_sink_cap_run(int port)
set_state_pe(port, PE_SNK_READY);
}
-/* Policy Engine utility functions */
-int pd_check_requested_voltage(uint32_t rdo, const int port)
-{
- int max_ma = rdo & 0x3FF;
- int op_ma = (rdo >> 10) & 0x3FF;
- int idx = RDO_POS(rdo);
- uint32_t pdo;
- uint32_t pdo_ma;
-#if defined(CONFIG_USB_PD_DYNAMIC_SRC_CAP) || \
- defined(CONFIG_USB_PD_MAX_SINGLE_SOURCE_CURRENT)
- const uint32_t *src_pdo;
- const int pdo_cnt = charge_manager_get_source_pdo(&src_pdo, port);
-#else
- const uint32_t *src_pdo = pd_src_pdo;
- const int pdo_cnt = pd_src_pdo_cnt;
-#endif
-
- /* Board specific check for this request */
- if (pd_board_check_request(rdo, pdo_cnt))
- return EC_ERROR_INVAL;
-
- /* check current ... */
- pdo = src_pdo[idx - 1];
- pdo_ma = (pdo & 0x3ff);
-
- if (op_ma > pdo_ma)
- return EC_ERROR_INVAL; /* too much op current */
-
- if (max_ma > pdo_ma && !(rdo & RDO_CAP_MISMATCH))
- return EC_ERROR_INVAL; /* too much max current */
-
- CPRINTF("Requested %d mV %d mA (for %d/%d mA)\n",
- ((pdo >> 10) & 0x3ff) * 50, (pdo & 0x3ff) * 10,
- op_ma * 10, max_ma * 10);
-
- /* Accept the requested voltage */
- return EC_SUCCESS;
-}
-
void pd_process_source_cap(int port, int cnt, uint32_t *src_caps)
{
#ifdef CONFIG_CHARGE_MANAGER
diff --git a/include/usb_pd.h b/include/usb_pd.h
index 813f13389a..7e3ad705df 100644
--- a/include/usb_pd.h
+++ b/include/usb_pd.h
@@ -1365,7 +1365,7 @@ int pd_check_requested_voltage(uint32_t rdo, const int port);
* @param pdo_cnt the total number of source PDOs.
* @return EC_SUCCESS if request is ok , <0 else.
*/
-int pd_board_check_request(uint32_t rdo, int pdo_cnt);
+__override_proto int pd_board_check_request(uint32_t rdo, int pdo_cnt);
/**
* Select a new output voltage.