summaryrefslogtreecommitdiff
path: root/board/zinger
diff options
context:
space:
mode:
authorAlec Berg <alecaberg@chromium.org>2014-07-24 10:16:51 -0700
committerchrome-internal-fetch <chrome-internal-fetch@google.com>2014-07-29 04:36:15 +0000
commit909c3236de7452d78fff49c34df1c30c1497fee0 (patch)
tree4cce3a654cf2a505393869d3f4dc41e059bfb758 /board/zinger
parentf93f1cfe77ed3603ab16047d79a283a781416db4 (diff)
downloadchrome-ec-909c3236de7452d78fff49c34df1c30c1497fee0.tar.gz
zinger: fix down voltage transitions to keep output enabled
Fix bug in which output was disabled on down voltage transitions. This also changes the behavior of the OVP protection. On down-step transitions, the OVP threshold is not lowered for a specified amount of time after the transition to allow the output to dissipate down to the new voltage. This will still catch a problem if the voltage goes up instead of down, but avoid OVPing immediately on a normal down transition. BUG=chrome-os-partner:30389 BRANCH=none TEST=Attach to firefly and probe output voltage. Make sure we transition smoothly going down in voltage. Change-Id: I7f3a0c17cc8b392a25d24d56d2b7155b806acb64 Signed-off-by: Alec Berg <alecaberg@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/209863
Diffstat (limited to 'board/zinger')
-rw-r--r--board/zinger/usb_pd_policy.c35
1 files changed, 29 insertions, 6 deletions
diff --git a/board/zinger/usb_pd_policy.c b/board/zinger/usb_pd_policy.c
index fded37ab11..f12ca9d7af 100644
--- a/board/zinger/usb_pd_policy.c
+++ b/board/zinger/usb_pd_policy.c
@@ -97,6 +97,10 @@ static timestamp_t fault_deadline;
/* Over-voltage recovery threshold is 1.1x Vnom */
#define OVP_REC_MV(mv) VBUS_MV((mv) * 11 / 10)
+/* Time to allow for voltage down stepping */
+/* TODO reduce this time if possible when voltage discharging is implemented */
+#define VOLTAGE_DOWN_STEP_TIME (500*MSEC)
+
/* ----------------------- USB Power delivery policy ---------------------- */
/* Power Delivery Objects */
@@ -121,8 +125,13 @@ static const struct {
{VO_20V, UVP_MV(20000), OVP_MV(20000), OVP_REC_MV(20000)},
};
-/* currently selected PDO entry */
+/* current and previous selected PDO entry */
static int volt_idx;
+static int last_volt_idx;
+
+/* flag and timestamp for down-stepping the voltage */
+static int down_step;
+static uint64_t down_step_done_time;
int pd_request_voltage(uint32_t rdo)
{
@@ -152,9 +161,12 @@ int pd_request_voltage(uint32_t rdo)
((pdo >> 10) & 0x3ff) * 50, (pdo & 0x3ff) * 10,
((rdo >> 10) & 0x3ff) * 10, (rdo & 0x3ff) * 10);
- if (idx - 1 < volt_idx) /* down voltage transition */
- output_disable();
- /* TODO discharge ? */
+ if (idx - 1 < volt_idx) { /* down voltage transition */
+ down_step = 1;
+ down_step_done_time = get_time().val + VOLTAGE_DOWN_STEP_TIME;
+ /* TODO discharge on down voltage transitions ? */
+ }
+ last_volt_idx = volt_idx;
volt_idx = idx - 1;
set_output_voltage(voltages[volt_idx].select);
@@ -190,6 +202,7 @@ int pd_board_checks(void)
{
int vbus_volt, vbus_amp;
int watchdog_enabled = STM32_ADC_CFGR1 & (1 << 23);
+ int ovp_idx;
/* Reload the watchdog */
STM32_IWDG_KR = STM32_IWDG_KR_RELOAD;
@@ -212,6 +225,7 @@ int pd_board_checks(void)
fault_deadline.val = get_time().val + OCP_TIMEOUT;
return EC_ERROR_INVAL;
}
+
if (vbus_amp > MAX_CURRENT) {
/* 3 more samples to check whether this is just a transient */
int count;
@@ -229,8 +243,17 @@ int pd_board_checks(void)
return EC_ERROR_INVAL;
}
}
- if ((output_is_enabled() && (vbus_volt > voltages[volt_idx].ovp)) ||
- (fault && (vbus_volt > voltages[volt_idx].ovp_rec))) {
+
+ /*
+ * Set the voltage index to use for checking OVP. During a down step
+ * transition, use the previous voltage index to check for OVP.
+ */
+ if (down_step && get_time().val >= down_step_done_time)
+ down_step = 0;
+ ovp_idx = down_step ? last_volt_idx : volt_idx;
+
+ if ((output_is_enabled() && (vbus_volt > voltages[ovp_idx].ovp)) ||
+ (fault && (vbus_volt > voltages[ovp_idx].ovp_rec))) {
if (!fault)
debug_printf("OverVoltage : %d mV\n",
vbus_volt * VDDA_MV * VOLT_DIV / ADC_SCALE);