summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVic Yang <victoryang@google.com>2015-02-20 11:24:52 -0800
committerChromeOS Commit Bot <chromeos-commit-bot@chromium.org>2015-02-21 09:19:57 +0000
commit1ef0f27e65e20a6a25b40fe427ab6d538f4b25ee (patch)
tree13a73dcc3da0e84fdb1d840408b1afab4f05022a
parente9c6a03c8ae34dc6eb36b3d1e227521f99c256d3 (diff)
downloadchrome-ec-1ef0f27e65e20a6a25b40fe427ab6d538f4b25ee.tar.gz
stm32f3: Allow per-board ADC sampling time
Depending on the hardware, each ADC channel may need a different sampling time. To keep things simple, let's allow per-board ADC sampling time configuration instead of per-channel configuration. BRANCH=Ryu BUG=None TEST=Configure sampling time to 3 and measure IADP on Ryu P4 and check it's more accurate. Change-Id: I3c1eeea22439c0340f84fdeb3624fc84450358ca Signed-off-by: Vic Yang <victoryang@google.com> Reviewed-on: https://chromium-review.googlesource.com/251701 Tested-by: Vic Yang <victoryang@chromium.org> Reviewed-by: Vincent Palatin <vpalatin@chromium.org> Commit-Queue: Vic Yang <victoryang@chromium.org>
-rw-r--r--chip/stm32/adc-stm32f.c19
-rw-r--r--include/config.h3
2 files changed, 16 insertions, 6 deletions
diff --git a/chip/stm32/adc-stm32f.c b/chip/stm32/adc-stm32f.c
index d6ff369ef9..072c71b9df 100644
--- a/chip/stm32/adc-stm32f.c
+++ b/chip/stm32/adc-stm32f.c
@@ -16,6 +16,16 @@
#define ADC_SINGLE_READ_TIMEOUT 3000 /* 3 ms */
+#define SMPR1_EXPAND(v) ((v) | ((v) << 3) | ((v) << 6) | ((v) << 9) | \
+ ((v) << 12) | ((v) << 15) | ((v) << 18) | \
+ ((v) << 21))
+#define SMPR2_EXPAND(v) (SMPR1_EXPAND(v) | ((v) << 24) | ((v) << 27))
+
+/* Default ADC sample time = 13.5 cycles */
+#ifndef CONFIG_ADC_SAMPLE_TIME
+#define CONFIG_ADC_SAMPLE_TIME 2
+#endif
+
struct mutex adc_lock;
static int watchdog_ain_id;
@@ -290,11 +300,8 @@ static void adc_init(void)
/* Set right alignment */
STM32_ADC_CR2 &= ~(1 << 11);
- /*
- * Set sample time of all channels to 13.5 cycles.
- * Conversion takes 15.75 us.
- */
- STM32_ADC_SMPR1 = 0x00492492;
- STM32_ADC_SMPR2 = 0x12492492;
+ /* Set sample time of all channels */
+ STM32_ADC_SMPR1 = SMPR1_EXPAND(CONFIG_ADC_SAMPLE_TIME);
+ STM32_ADC_SMPR2 = SMPR2_EXPAND(CONFIG_ADC_SAMPLE_TIME);
}
DECLARE_HOOK(HOOK_INIT, adc_init, HOOK_PRIO_DEFAULT);
diff --git a/include/config.h b/include/config.h
index 5c6d17f99e..f458b670b9 100644
--- a/include/config.h
+++ b/include/config.h
@@ -51,6 +51,9 @@
*/
#undef CONFIG_ADC_CLOCK
+/* ADC sample time selection. The value is chip-dependent. */
+#undef CONFIG_ADC_SAMPLE_TIME
+
/*
* Some ALS modules may be connected to the EC. We need the command, and
* specific drivers for each module.