summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlec Berg <alecaberg@chromium.org>2014-08-20 09:11:20 -0700
committerchrome-internal-fetch <chrome-internal-fetch@google.com>2014-08-22 01:03:19 +0000
commit08081ee2dc05fe08cadd19252f94db06664f1cc9 (patch)
treec1d07b7eb1bfc4a10bacfc82a8ab5bfb4ab3ef6c
parent3e844ec271fa69e2153408cf17aabfacf9723db1 (diff)
downloadchrome-ec-08081ee2dc05fe08cadd19252f94db06664f1cc9.tar.gz
zinger: always disable adc watchdog before reading ADC channel
This fixes a bug where we were reading the CC line ADC without disabling the adc watchdog, which caused misreads. Instead, I changed adc_read_channel so that every ADC read disables and restores the ADC watchdog. BUG=chrome-os-partner:31454 BRANCH=none TEST=tested on EVT zinger. Added debug code to print out CC line voltage after reading it in usb_pd_protocol.c. Before the change the CC voltage is mostly wrong, unless you read the ADC twice back to back and look at the second read value. After this change, the CC voltage ADC reading always matches the real voltage. Change-Id: I9d3aa02b3d22defb9cf6f5a866de2b846a6b8a35 Signed-off-by: Alec Berg <alecaberg@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/213253 Reviewed-by: Todd Broch <tbroch@chromium.org>
-rw-r--r--board/zinger/hardware.c25
-rw-r--r--board/zinger/usb_pd_config.h6
-rw-r--r--board/zinger/usb_pd_policy.c9
3 files changed, 27 insertions, 13 deletions
diff --git a/board/zinger/hardware.c b/board/zinger/hardware.c
index 25b9b59569..fd9b86ff15 100644
--- a/board/zinger/hardware.c
+++ b/board/zinger/hardware.c
@@ -170,9 +170,26 @@ void hardware_init(void)
irq_init();
}
+static int watchdog_ain_id, watchdog_ain_high, watchdog_ain_low;
+
+static int adc_enable_last_watchdog(void)
+{
+ return adc_enable_watchdog(watchdog_ain_id, watchdog_ain_high,
+ watchdog_ain_low);
+}
+
+static inline int adc_watchdog_enabled(void)
+{
+ return STM32_ADC_CFGR1 & (1 << 23);
+}
+
int adc_read_channel(enum adc_channel ch)
{
int value;
+ int watchdog_enabled = adc_watchdog_enabled();
+
+ if (watchdog_enabled)
+ adc_disable_watchdog();
/* Select channel to convert */
STM32_ADC_CHSELR = 1 << ch;
@@ -186,11 +203,19 @@ int adc_read_channel(enum adc_channel ch)
/* read converted value */
value = STM32_ADC_DR;
+ if (watchdog_enabled)
+ adc_enable_last_watchdog();
+
return value;
}
int adc_enable_watchdog(int ch, int high, int low)
{
+ /* store last watchdog setup */
+ watchdog_ain_id = ch;
+ watchdog_ain_high = high;
+ watchdog_ain_low = low;
+
/* Set thresholds */
STM32_ADC_TR = ((high & 0xfff) << 16) | (low & 0xfff);
/* Select channel to convert */
diff --git a/board/zinger/usb_pd_config.h b/board/zinger/usb_pd_config.h
index cbaa8b286b..882936a9a5 100644
--- a/board/zinger/usb_pd_config.h
+++ b/board/zinger/usb_pd_config.h
@@ -105,10 +105,8 @@ static inline void pd_tx_init(void)
static inline int pd_adc_read(int port, int cc)
{
- if (cc == 0)
- return adc_read_channel(ADC_CH_CC1_PD);
- else
- return adc_read_channel(ADC_CH_CC2_PD);
+ /* only one CC line */
+ return adc_read_channel(ADC_CH_CC1_PD);
}
/* 3.0A DFP : no-connect voltage is 2.45V */
diff --git a/board/zinger/usb_pd_policy.c b/board/zinger/usb_pd_policy.c
index 420e22776d..f3d817f728 100644
--- a/board/zinger/usb_pd_policy.c
+++ b/board/zinger/usb_pd_policy.c
@@ -201,23 +201,14 @@ void pd_power_supply_reset(int port)
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;
- if (watchdog_enabled)
- /* if the watchdog is enabled, stop it to do other readings */
- adc_disable_watchdog();
-
vbus_volt = adc_read_channel(ADC_CH_V_SENSE);
vbus_amp = adc_read_channel(ADC_CH_A_SENSE);
- if (watchdog_enabled)
- /* re-enable fast OCP */
- adc_enable_watchdog(ADC_CH_A_SENSE, MAX_CURRENT_FAST, 0);
-
if (fault == FAULT_FAST_OCP) {
debug_printf("Fast OverCurrent\n");
fault = FAULT_OCP;