summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShawn Nematbakhsh <shawnn@chromium.org>2017-10-11 14:02:09 -0700
committerChromeOS Commit Bot <chromeos-commit-bot@chromium.org>2017-10-30 17:04:54 +0000
commit6d27a437c100f461bbc7ad11ce9b0ab8d30e69ae (patch)
treebe7d9f93485e67b889d54a9dd2db7ba4acd317e5
parent0efc14b3c037397058cb1fd2b2abe1073904470b (diff)
downloadchrome-ec-6d27a437c100f461bbc7ad11ce9b0ab8d30e69ae.tar.gz
servo_v4: Use charge_manager for input port / ILIM selection
BUG=chromium:769895 BRANCH=servo TEST=On servo_v4, attach OEM Apple charger to power port and verify negotiation to 9V and port / ILIM selection from charge_manager. Attach samus to DUT port and verify 9V charging. Change-Id: Icf16f6e8c99af4fbb48a83b7a36f550c20f5fd69 Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/713944 Commit-Ready: Shawn N <shawnn@chromium.org> Tested-by: Shawn N <shawnn@chromium.org> Reviewed-by: Vincent Palatin <vpalatin@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/739996
-rw-r--r--board/servo_v4/board.h5
-rw-r--r--board/servo_v4/usb_pd_policy.c66
-rw-r--r--common/usb_pd_protocol.c10
3 files changed, 33 insertions, 48 deletions
diff --git a/board/servo_v4/board.h b/board/servo_v4/board.h
index dfe8b77e15..07880ec599 100644
--- a/board/servo_v4/board.h
+++ b/board/servo_v4/board.h
@@ -70,6 +70,9 @@
#undef CONFIG_WATCHDOG_HELP
#undef CONFIG_LID_SWITCH
+/* Remove console commands / features for flash / RAM savings */
+#undef CONFIG_CONSOLE_CMDHELP
+
/* Enable control of I2C over USB */
#define CONFIG_USB_I2C
#define CONFIG_I2C
@@ -85,6 +88,7 @@
*/
#undef CONFIG_TASK_PROFILING
+#define CONFIG_CHARGE_MANAGER
#define CONFIG_USB_POWER_DELIVERY
#define CONFIG_CMD_PD
#define CONFIG_USB_PD_DUAL_ROLE
@@ -150,6 +154,7 @@ enum usb_strings {
/* ADC signal */
enum adc_channel {
+ ADC_VBUS = -1,
ADC_CHG_CC1_PD = 0,
ADC_CHG_CC2_PD,
ADC_DUT_CC1_PD,
diff --git a/board/servo_v4/usb_pd_policy.c b/board/servo_v4/usb_pd_policy.c
index 9cf81a9dce..42b93591af 100644
--- a/board/servo_v4/usb_pd_policy.c
+++ b/board/servo_v4/usb_pd_policy.c
@@ -55,7 +55,7 @@ struct vbus_prop {
int ma;
};
static struct vbus_prop vbus[CONFIG_USB_PD_PORT_COUNT];
-static struct vbus_prop vbus_pend;
+static int charge_port_is_active;
static uint8_t vbus_rp = TYPEC_RP_RESERVED;
static int disable_dts_mode;
@@ -124,17 +124,13 @@ static void board_manage_dut_port(void)
pd_update_contract(DUT);
}
-static void board_manage_chg_port(void)
+static void update_ports(void)
{
- /* Update the voltage/current values for CHG port */
- vbus[CHG].mv = vbus_pend.mv;
- vbus[CHG].ma = vbus_pend.ma;
-
/*
* CHG Vbus has changed states, update PDO that reflects CHG port
* state
*/
- if (!vbus[CHG].mv) {
+ if (!vbus[CHG].mv || !charge_port_is_active) {
/* CHG Vbus has dropped, so always source DUT Vbus from host */
gpio_set_level(GPIO_HOST_OR_CHG_CTL, 0);
chg_pdo_cnt = 0;
@@ -161,31 +157,28 @@ static void board_manage_chg_port(void)
/* Call DUT port manager to update Rp and possible PD contract */
board_manage_dut_port();
}
-DECLARE_DEFERRED(board_manage_chg_port);
-static void board_update_chg_vbus(int max_ma, int vbus_mv)
+int board_set_active_charge_port(int charge_port)
{
- /*
- * Determine if vbus from CHG port has changed values and if the current
- * state of CHG vbus is on or off. If the change is on, then schedule a
- * deferred callback. If the change is off, then act immediately.
- */
- if (VBUS_UNCHANGED(vbus[CHG].mv, vbus_pend.mv, vbus_mv) &&
- VBUS_UNCHANGED(vbus[CHG].ma, vbus_pend.ma, max_ma))
- /* No change in CHG VBUS detected, nothing else to do. */
- return;
+ if (charge_port == DUT)
+ return -1;
- /* CHG port voltage and current values are now pending */
- vbus_pend.mv = vbus_mv;
- vbus_pend.ma = max_ma;
+ charge_port_is_active = (charge_port == CHG);
+ update_ports();
- if (vbus_mv)
- /* Wait enough time for PD contract to be established */
- hook_call_deferred(&board_manage_chg_port_data,
- PD_T_SINK_WAIT_CAP * 3);
- else
- /* Update CHG port status now since vbus is off */
- hook_call_deferred(&board_manage_chg_port_data, 0);
+ return 0;
+}
+
+void board_set_charge_limit(int port, int supplier, int charge_ma,
+ int max_ma, int charge_mv)
+{
+ if (port != CHG)
+ return;
+
+ /* Update the voltage/current values for CHG port */
+ vbus[CHG].mv = charge_mv;
+ vbus[CHG].ma = charge_ma;
+ update_ports();
}
int pd_tcpc_cc_nc(int port, int cc_volt, int cc_sel)
@@ -355,11 +348,12 @@ int board_select_rp_value(int port, int rp)
int charge_manager_get_source_pdo(const uint32_t **src_pdo)
{
int pdo_cnt;
+
/*
* If CHG is providing VBUS, then advertise what's available on the CHG
* port, otherwise used the fixed value that matches host capabilities.
*/
- if (vbus[CHG].mv) {
+ if (vbus[CHG].mv && charge_port_is_active) {
*src_pdo = pd_src_chg_pdo;
pdo_cnt = chg_pdo_cnt;
} else {
@@ -440,20 +434,6 @@ void pd_power_supply_reset(int port)
vbus[DUT].ma = 0;
}
-void pd_set_input_current_limit(int port, uint32_t max_ma,
- uint32_t supply_voltage)
-{
- if (port == CHG)
- board_update_chg_vbus(max_ma, supply_voltage);
-}
-
-void typec_set_input_current_limit(int port, uint32_t max_ma,
- uint32_t supply_voltage)
-{
- if (port == CHG)
- board_update_chg_vbus(max_ma, supply_voltage);
-}
-
int pd_snk_is_vbus_provided(int port)
{
diff --git a/common/usb_pd_protocol.c b/common/usb_pd_protocol.c
index 26615fd037..b95badc5cb 100644
--- a/common/usb_pd_protocol.c
+++ b/common/usb_pd_protocol.c
@@ -1390,7 +1390,7 @@ static inline int get_snk_polarity(int cc1, int cc2)
return (cc2 > cc1);
}
-#if defined(CONFIG_CHARGE_MANAGER) || defined(CONFIG_USB_PD_DTS)
+#if defined(CONFIG_CHARGE_MANAGER)
/**
* Returns type C current limit (mA) based upon cc_voltage (mV).
*/
@@ -1478,7 +1478,7 @@ void pd_task(void)
#ifndef CONFIG_USB_PD_VBUS_DETECT_NONE
int snk_hard_reset_vbus_off = 0;
#endif
-#if defined(CONFIG_CHARGE_MANAGER) || defined(CONFIG_USB_PD_DTS)
+#if defined(CONFIG_CHARGE_MANAGER)
int typec_curr = 0, typec_curr_change = 0;
#endif /* CONFIG_CHARGE_MANAGER */
#endif /* CONFIG_USB_PD_DUAL_ROLE */
@@ -2182,7 +2182,7 @@ void pd_task(void)
pd[port].msg_id = 0;
/* initial data role for sink is UFP */
pd_set_data_role(port, PD_ROLE_UFP);
-#if defined(CONFIG_CHARGE_MANAGER) || defined(CONFIG_USB_PD_DTS)
+#if defined(CONFIG_CHARGE_MANAGER)
typec_curr = get_typec_current_limit(pd[port].polarity,
cc1, cc2);
typec_set_input_current_limit(
@@ -2300,7 +2300,7 @@ void pd_task(void)
get_time().val +
PD_T_NO_RESPONSE,
PD_STATE_SNK_DISCONNECTED);
-#if defined(CONFIG_CHARGE_MANAGER) || defined(CONFIG_USB_PD_DTS)
+#if defined(CONFIG_CHARGE_MANAGER)
/*
* If we didn't come from disconnected, must
* have come from some path that did not set
@@ -2313,7 +2313,7 @@ void pd_task(void)
#endif
}
-#if defined(CONFIG_CHARGE_MANAGER) || defined(CONFIG_USB_PD_DTS)
+#if defined(CONFIG_CHARGE_MANAGER)
timeout = PD_T_SINK_ADJ - PD_T_DEBOUNCE;
/* Check if CC pull-up has changed */