diff options
-rw-r--r-- | board/link/board.c | 2 | ||||
-rw-r--r-- | chip/lm4/adc.c | 40 | ||||
-rw-r--r-- | chip/lm4/lm4_adc.h | 3 | ||||
-rw-r--r-- | include/adc.h | 1 |
4 files changed, 40 insertions, 6 deletions
diff --git a/board/link/board.c b/board/link/board.c index 67d975686e..830426743b 100644 --- a/board/link/board.c +++ b/board/link/board.c @@ -109,7 +109,7 @@ const struct adc_t adc_channels[ADC_CH_COUNT] = * = -225 * ADC_VALUE / ADC_READ_MAX + 420.5 */ {"ECTemp", LM4_ADC_SEQ0, -225, ADC_READ_MAX, 420, - LM4_NO_AIN, 0x0e /* TS0 | IE0 | END0 */}, + LM4_AIN_NONE, 0x0e /* TS0 | IE0 | END0 */}, /* Charger current is mapped from 0~4000mA to 0~1.6V. * And ADC maps 0~3.3V to ADC_READ_MAX. diff --git a/chip/lm4/adc.c b/chip/lm4/adc.c index 740c9a623d..29eb73ddb6 100644 --- a/chip/lm4/adc.c +++ b/chip/lm4/adc.c @@ -15,17 +15,51 @@ extern const struct adc_t adc_channels[ADC_CH_COUNT]; +/* GPIO port and mask for AINs. */ +const uint32_t ain_port[24][2] = { + {LM4_GPIO_E, (1<<3)}, + {LM4_GPIO_E, (1<<2)}, + {LM4_GPIO_E, (1<<1)}, + {LM4_GPIO_E, (1<<0)}, + {LM4_GPIO_D, (1<<7)}, + {LM4_GPIO_D, (1<<6)}, + {LM4_GPIO_D, (1<<5)}, + {LM4_GPIO_D, (1<<4)}, + {LM4_GPIO_E, (1<<5)}, + {LM4_GPIO_E, (1<<4)}, + {LM4_GPIO_B, (1<<4)}, + {LM4_GPIO_B, (1<<5)}, + {LM4_GPIO_D, (1<<3)}, + {LM4_GPIO_D, (1<<2)}, + {LM4_GPIO_D, (1<<1)}, + {LM4_GPIO_D, (1<<0)}, + {LM4_GPIO_K, (1<<0)}, + {LM4_GPIO_K, (1<<1)}, + {LM4_GPIO_K, (1<<2)}, + {LM4_GPIO_K, (1<<3)}, + {LM4_GPIO_E, (1<<7)}, + {LM4_GPIO_E, (1<<6)}, + {LM4_GPIO_N, (1<<1)}, + {LM4_GPIO_N, (1<<0)}, +}; + static void configure_gpio(void) { + int i; volatile uint32_t scratch __attribute__((unused)); /* Enable GPIOE module and delay a few clocks */ LM4_SYSTEM_RCGCGPIO |= 0x0010; scratch = LM4_SYSTEM_RCGCGPIO; - /* Use analog function for PE3 (AIN0) */ - LM4_GPIO_DEN(LM4_GPIO_E) &= ~0x08; - LM4_GPIO_AMSEL(LM4_GPIO_E) |= 0x08; + /* Use analog function for AIN */ + for (i = 0; i < ADC_CH_COUNT; ++i) { + int id = adc_channels[i].channel; + if (id != LM4_AIN_NONE) + gpio_set_alternate_function(ain_port[id][0], + ain_port[id][1], + 1); + } } int lm4_adc_flush_and_read(enum lm4_adc_sequencer seq) diff --git a/chip/lm4/lm4_adc.h b/chip/lm4/lm4_adc.h index dad05be703..98f5293646 100644 --- a/chip/lm4/lm4_adc.h +++ b/chip/lm4/lm4_adc.h @@ -27,10 +27,9 @@ enum lm4_adc_sequencer /* Just plain id mapping for code readability */ #define LM4_AIN(x) (x) -#define LM4_AIN_NONE (-1) /* Dummy value for "channel" in adc_t if we don't have an external channel. */ -#define LM4_NO_AIN 0 +#define LM4_AIN_NONE (-1) /* Flush an ADC sequencer and initiate a read. Return raw ADC value. */ int lm4_adc_flush_and_read(enum lm4_adc_sequencer); diff --git a/include/adc.h b/include/adc.h index a59c58c463..6be9542321 100644 --- a/include/adc.h +++ b/include/adc.h @@ -10,6 +10,7 @@ #include "common.h" #include "board.h" +#include "gpio.h" /* Data structure to define ADC channels. */ struct adc_t |