mirror of
https://github.com/Telecominfraproject/OpenCellular.git
synced 2026-01-08 16:41:55 +00:00
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>
This commit is contained in:
committed by
chrome-internal-fetch
parent
3e844ec271
commit
08081ee2dc
@@ -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 */
|
||||
|
||||
@@ -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 */
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user