diff options
Diffstat (limited to 'firmware/target/arm')
-rw-r--r-- | firmware/target/arm/imx31/gigabeat-s/adc-imx31.c | 17 |
1 files changed, 6 insertions, 11 deletions
diff --git a/firmware/target/arm/imx31/gigabeat-s/adc-imx31.c b/firmware/target/arm/imx31/gigabeat-s/adc-imx31.c index b1b79a7989..dfaaab9177 100644 --- a/firmware/target/arm/imx31/gigabeat-s/adc-imx31.c +++ b/firmware/target/arm/imx31/gigabeat-s/adc-imx31.c | |||
@@ -23,19 +23,15 @@ | |||
23 | #include "kernel.h" | 23 | #include "kernel.h" |
24 | 24 | ||
25 | /* Do this so we may read all channels in a single SPI message */ | 25 | /* Do this so we may read all channels in a single SPI message */ |
26 | static const unsigned char reg_array[NUM_ADC_CHANNELS/2] = | 26 | static const unsigned char reg_array[4] = |
27 | { | 27 | { |
28 | MC13783_ADC2, | 28 | MC13783_ADC2, |
29 | MC13783_ADC2, | 29 | MC13783_ADC2, |
30 | MC13783_ADC2, | 30 | MC13783_ADC2, |
31 | MC13783_ADC2, | 31 | MC13783_ADC2, |
32 | MC13783_ADC2, | ||
33 | MC13783_ADC2, | ||
34 | MC13783_ADC2, | ||
35 | MC13783_ADC2, | ||
36 | }; | 32 | }; |
37 | 33 | ||
38 | static uint32_t channels[2][NUM_ADC_CHANNELS/2]; | 34 | static uint32_t channels[2][4]; |
39 | static struct wakeup adc_wake; | 35 | static struct wakeup adc_wake; |
40 | static struct mutex adc_mtx; | 36 | static struct mutex adc_mtx; |
41 | static long last_adc_read[2]; /* One for each input group */ | 37 | static long last_adc_read[2]; /* One for each input group */ |
@@ -49,10 +45,10 @@ unsigned short adc_read(int channel) | |||
49 | if ((unsigned)channel >= NUM_ADC_CHANNELS) | 45 | if ((unsigned)channel >= NUM_ADC_CHANNELS) |
50 | return ADC_READ_ERROR; | 46 | return ADC_READ_ERROR; |
51 | 47 | ||
52 | mutex_lock(&adc_mtx); | ||
53 | |||
54 | input_select = channel >> 3; | 48 | input_select = channel >> 3; |
55 | 49 | ||
50 | mutex_lock(&adc_mtx); | ||
51 | |||
56 | /* Limit the traffic through here */ | 52 | /* Limit the traffic through here */ |
57 | if (TIME_AFTER(current_tick, last_adc_read[input_select])) | 53 | if (TIME_AFTER(current_tick, last_adc_read[input_select])) |
58 | { | 54 | { |
@@ -72,13 +68,12 @@ unsigned short adc_read(int channel) | |||
72 | 68 | ||
73 | /* Read all 8 channels that are converted - two channels in each | 69 | /* Read all 8 channels that are converted - two channels in each |
74 | * word. */ | 70 | * word. */ |
75 | mc13783_read_regset(reg_array, channels[input_select], | 71 | mc13783_read_regset(reg_array, channels[input_select], 4); |
76 | NUM_ADC_CHANNELS/2); | ||
77 | 72 | ||
78 | last_adc_read[input_select] = current_tick; | 73 | last_adc_read[input_select] = current_tick; |
79 | } | 74 | } |
80 | 75 | ||
81 | data = channels[input_select][channel & 7]; | 76 | data = channels[input_select][(channel >> 1) & 3]; |
82 | 77 | ||
83 | mutex_unlock(&adc_mtx); | 78 | mutex_unlock(&adc_mtx); |
84 | 79 | ||