From 55abd0b93cdadc717175ce9dbe732576ff36986f Mon Sep 17 00:00:00 2001 From: Alec Berg Date: Thu, 24 Oct 2013 14:19:50 -0700 Subject: lm4: Disable ADC module when not in use. Changed ADC clock gating to disable the ADC module to conserve power, and only enable it when needed. This saves about 15% of the power consumed by the EC when the AP is running. BUG=none BRANCH=none TEST=Run the ADC stress test. This runs 2000 consecutive ADC reads of all the channels and verifies that the ADC module successfully records the samples. Note that when running this test make sure all other calls to read an ADC channel are disabled because the ADC read function does not protect against different tasks accesses. Change-Id: I9ca3671d8cf68e09d21c9c2594856f9c08476398 Signed-off-by: Alec Berg Reviewed-on: https://chromium-review.googlesource.com/174580 Reviewed-by: Randall Spangler Reviewed-by: Vincent Palatin --- chip/lm4/adc.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/chip/lm4/adc.c b/chip/lm4/adc.c index 365a2776c9..b3e24809a8 100644 --- a/chip/lm4/adc.c +++ b/chip/lm4/adc.c @@ -120,7 +120,17 @@ static void lm4_adc_configure(const struct adc_t *adc) int adc_read_channel(enum adc_channel ch) { const struct adc_t *adc = adc_channels + ch; - int rv = lm4_adc_flush_and_read(adc->sequencer); + int rv; + + /* Enable ADC0 module in run and sleep modes. */ + clock_enable_peripheral(CGC_OFFSET_ADC, 0x1, + CGC_MODE_RUN | CGC_MODE_SLEEP); + + rv = lm4_adc_flush_and_read(adc->sequencer); + + /* Disable ADC0 module to conserve power. */ + clock_disable_peripheral(CGC_OFFSET_ADC, 0x1, + CGC_MODE_RUN | CGC_MODE_SLEEP); if (rv == ADC_READ_ERROR) return ADC_READ_ERROR; @@ -236,5 +246,9 @@ static void adc_init(void) /* Initialize ADC sequencer */ for (i = 0; i < ADC_CH_COUNT; ++i) lm4_adc_configure(adc_channels + i); + + /* Disable ADC0 module until it is needed to conserve power. */ + clock_disable_peripheral(CGC_OFFSET_ADC, 0x1, + CGC_MODE_RUN | CGC_MODE_SLEEP); } DECLARE_HOOK(HOOK_INIT, adc_init, HOOK_PRIO_DEFAULT); -- cgit v1.2.1