pd: log source current

Record what current limit we set when we act as a source
and when we are changing it.

The change should be backward-compatible as older EC will return 0 in
`current_max` when their role is PD_ROLE_SOURCE while newer firmware
will set the actual limit.

BRANCH=none
BUG=chrome-os-partner:56110
TEST=manual: on Kevin, plug and unplug various devices on the 2
ports, and dump the values with 'ectool usbpdpower'.

Change-Id: I8e78663f3196b1b81c2235ed8642da0638bed649
Reviewed-on: https://chromium-review.googlesource.com/375918
Commit-Ready: Vincent Palatin <vpalatin@chromium.org>
Tested-by: Vincent Palatin <vpalatin@chromium.org>
Reviewed-by: Shawn N <shawnn@chromium.org>
This commit is contained in:
Vincent Palatin
2016-08-25 14:25:23 +02:00
committed by chrome-bot
parent 6b4a8e715a
commit ebc973ce39
2 changed files with 28 additions and 1 deletions

View File

@@ -78,6 +78,7 @@ static timestamp_t delayed_override_deadline;
/* Bitmap of ports used as power source */
static volatile uint32_t source_port_bitmap;
BUILD_ASSERT(sizeof(source_port_bitmap)*8 >= CONFIG_USB_PD_PORT_COUNT);
static uint8_t source_port_last_rp[CONFIG_USB_PD_PORT_COUNT];
enum charge_manager_change_type {
CHANGE_CHARGE,
@@ -124,6 +125,7 @@ static void charge_manager_init(void)
charge_ceil[i][j] = CHARGE_CEIL_NONE;
dualrole_capability[i] = spoof_capability ? CAP_DEDICATED :
CAP_UNKNOWN;
source_port_last_rp[i] = CONFIG_USB_PD_PULLUP;
}
}
DECLARE_HOOK(HOOK_INIT, charge_manager_init, HOOK_PRIO_CHARGE_MANAGER_INIT);
@@ -154,6 +156,19 @@ static int charge_manager_is_seeded(void)
}
#ifndef TEST_BUILD
static int charge_manager_get_source_current(int port)
{
switch (source_port_last_rp[port]) {
case TYPEC_RP_3A0:
return 3000;
case TYPEC_RP_1A5:
return 1500;
case TYPEC_RP_USB:
default:
return 500;
}
}
/**
* Fills passed power_info structure with current info about the passed port.
*/
@@ -200,7 +215,7 @@ static void charge_manager_fill_power_info(int port,
r->meas.voltage_max = 0;
r->meas.voltage_now = r->role == USB_PD_PORT_POWER_SOURCE ? 5000
: 0;
r->meas.current_max = 0;
r->meas.current_max = charge_manager_get_source_current(port);
r->max_power = 0;
} else {
#if defined(HAS_TASK_CHG_RAMP) || defined(CONFIG_CHARGE_RAMP_HW)
@@ -916,6 +931,14 @@ void charge_manager_source_port(int port, int enable)
int rp = (source_port_bitmap & ~(1 << p)) ? CONFIG_USB_PD_PULLUP
: CONFIG_USB_PD_MAX_SINGLE_SOURCE_CURRENT;
source_port_last_rp[p] = rp;
#ifdef CONFIG_USB_PD_LOGGING
if (pd_is_connected(p) &&
pd_get_role(p) == PD_ROLE_SOURCE)
charge_manager_save_log(p);
#endif
tcpm_select_rp_value(p, rp);
pd_update_contract(p);
}

View File

@@ -4248,6 +4248,10 @@ static void print_pd_power_info(struct ec_response_usb_pd_power_info *r)
printf("Unknown");
}
if ((r->role == USB_PD_PORT_POWER_SOURCE) &&
(r->meas.current_max))
printf(" %dmA", r->meas.current_max);
if ((r->role == USB_PD_PORT_POWER_DISCONNECTED) ||
(r->role == USB_PD_PORT_POWER_SOURCE)) {
printf("\n");