summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcin Bukat <marcin.bukat@gmail.com>2011-07-18 22:00:17 +0000
committerMarcin Bukat <marcin.bukat@gmail.com>2011-07-18 22:00:17 +0000
commit8fba4fb937332f4125d5fe6aee90e37dc9f68b0e (patch)
treee786ea0a69971b83e1c26d2bbebf684613a602da
parenta5e7354b20b1b406e850ac26d589ea0ddb4936e2 (diff)
downloadrockbox-8fba4fb937332f4125d5fe6aee90e37dc9f68b0e.tar.gz
rockbox-8fba4fb937332f4125d5fe6aee90e37dc9f68b0e.zip
rk27xx - fix (hopefully) adc readings
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@30164 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--firmware/target/arm/rk27xx/adc-rk27xx.c18
1 files changed, 12 insertions, 6 deletions
diff --git a/firmware/target/arm/rk27xx/adc-rk27xx.c b/firmware/target/arm/rk27xx/adc-rk27xx.c
index c8bbae7514..524cf4d166 100644
--- a/firmware/target/arm/rk27xx/adc-rk27xx.c
+++ b/firmware/target/arm/rk27xx/adc-rk27xx.c
@@ -11,7 +11,7 @@
11 * 11 *
12 * This program is free software; you can redistribute it and/or 12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License 13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2 14 * as published by the Free Software Foundation; either version 1
15 * of the License, or (at your option) any later version. 15 * of the License, or (at your option) any later version.
16 * 16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY 17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
@@ -28,11 +28,17 @@
28 28
29unsigned int adc_scan(int channel) 29unsigned int adc_scan(int channel)
30{ 30{
31 ADC_CTRL = (1<<4) | (1<<3) | (channel & (NUM_ADC_CHANNELS - 1)); 31 ADC_CTRL = (1<<4)|(1<<3) | (channel & (NUM_ADC_CHANNELS - 1));
32
33 /* wait for conversion ready ~10us */
34 while (ADC_STAT & 0x01);
35 32
33 /* Wait for conversion ready.
34 * The doc says one should pool ADC_STAT for end of conversion
35 * or setup interrupt. Neither of these two methods work as
36 * advertised.
37 *
38 * ~10us should be enough so we wait 20us to be on the safe side
39 */
40 udelay(20);
41
36 /* 10bits result */ 42 /* 10bits result */
37 return (ADC_DATA & 0x3ff); 43 return (ADC_DATA & 0x3ff);
38} 44}
@@ -43,5 +49,5 @@ void adc_init(void)
43 SCU_DIVCON1 = (SCU_DIVCON1 & ~(0xff<<10)) | (49<<10); 49 SCU_DIVCON1 = (SCU_DIVCON1 & ~(0xff<<10)) | (49<<10);
44 50
45 /* enable clocks for ADC */ 51 /* enable clocks for ADC */
46 SCU_CLKCFG |= 3<<23; 52 SCU_CLKCFG &= ~(3<<23);
47} 53}