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>
This commit is contained in:
Shawn Nematbakhsh
2017-10-11 14:02:09 -07:00
committed by chrome-bot
parent 87dbec5dfa
commit e7dfbf35a4
3 changed files with 33 additions and 48 deletions

View File

@@ -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_USB_PD_DTS
#define CONFIG_CMD_PD
@@ -151,6 +155,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,

View File

@@ -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. */
if (charge_port == DUT)
return -1;
charge_port_is_active = (charge_port == CHG);
update_ports();
return 0;
}
void board_set_charge_limit(int port, int supplier, int charge_ma,
int max_ma, int charge_mv)
{
if (port != CHG)
return;
/* CHG port voltage and current values are now pending */
vbus_pend.mv = vbus_mv;
vbus_pend.ma = max_ma;
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);
/* 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, const int port)
{
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 {
@@ -434,20 +428,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)
{

View File

@@ -1532,7 +1532,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).
*/
@@ -1637,7 +1637,7 @@ void pd_task(void *u)
#ifdef CONFIG_USB_PD_DUAL_ROLE_AUTO_TOGGLE
const int auto_toggle_supported = tcpm_auto_toggle_supported(port);
#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 */
@@ -2442,7 +2442,7 @@ void pd_task(void *u)
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(
@@ -2572,7 +2572,7 @@ void pd_task(void *u)
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
@@ -2585,7 +2585,7 @@ void pd_task(void *u)
#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 */