diff options
Diffstat (limited to 'firmware/target/arm/rk27xx')
-rw-r--r-- | firmware/target/arm/rk27xx/adc-rk27xx.c | 18 |
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 | ||
29 | unsigned int adc_scan(int channel) | 29 | unsigned 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 | } |