diff options
author | Ruibin Chang <ruibin.chang@ite.com.tw> | 2020-03-06 15:55:07 +0800 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2020-03-11 04:22:51 +0000 |
commit | 18500f672d0dcc76c79c8975a014293d7c7e94db (patch) | |
tree | 6a455552a6052c016102a872f7a1168bac623659 /chip/it83xx/adc_chip.h | |
parent | 788b6f46ddb78c139bc960e936050882530d591d (diff) | |
download | chrome-ec-18500f672d0dcc76c79c8975a014293d7c7e94db.tar.gz |
it83xx/adc: add voltage comparator feature
Add voltage comparator feature.
BUG=b:149094481
BRANCH=none
TEST=on board it83xx_evb,
1.set VCMP1 threshold 2.8v: external input 3v,
the INT would be triggered and ADC5 read the correctly voltage.
2.set VCMP0 threshold 0.2v: external input 0v,
the INT would be triggered and ADC5 read the correctly voltage.
Change-Id: I59510b1c6bd38004ff06e0fcbd2a671e895d59e3
Signed-off-by: Ruibin Chang <ruibin.chang@ite.com.tw>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2062110
Tested-by: Ruibin Chang <Ruibin.Chang@ite.com.tw>
Reviewed-by: Diana Z <dzigterman@chromium.org>
Commit-Queue: Ruibin Chang <Ruibin.Chang@ite.com.tw>
Diffstat (limited to 'chip/it83xx/adc_chip.h')
-rw-r--r-- | chip/it83xx/adc_chip.h | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/chip/it83xx/adc_chip.h b/chip/it83xx/adc_chip.h index c43a64c132..e894e97b64 100644 --- a/chip/it83xx/adc_chip.h +++ b/chip/it83xx/adc_chip.h @@ -41,6 +41,33 @@ enum chip_adc_channel { CHIP_ADC_COUNT, }; +/* List of voltage comparator. */ +enum chip_vcmp { + CHIP_VCMP0 = 0, + CHIP_VCMP1, + CHIP_VCMP2, + CHIP_VCMP3, + CHIP_VCMP4, + CHIP_VCMP5, + CHIP_VCMP_COUNT, +}; + +/* List of voltage comparator scan period times. */ +enum vcmp_scan_period { + VCMP_SCAN_PERIOD_100US = 0x10, + VCMP_SCAN_PERIOD_200US = 0x20, + VCMP_SCAN_PERIOD_400US = 0x30, + VCMP_SCAN_PERIOD_600US = 0x40, + VCMP_SCAN_PERIOD_800US = 0x50, + VCMP_SCAN_PERIOD_1MS = 0x60, + VCMP_SCAN_PERIOD_1_5MS = 0x70, + VCMP_SCAN_PERIOD_2MS = 0x80, + VCMP_SCAN_PERIOD_2_5MS = 0x90, + VCMP_SCAN_PERIOD_3MS = 0xA0, + VCMP_SCAN_PERIOD_4MS = 0xB0, + VCMP_SCAN_PERIOD_5MS = 0xC0, +}; + /* Data structure to define ADC channel control registers. */ struct adc_ctrl_t { volatile uint8_t *adc_ctrl; @@ -58,10 +85,56 @@ struct adc_t { enum chip_adc_channel channel; }; +/* Data structure to define voltage comparator control registers. */ +struct vcmp_ctrl_t { + volatile uint8_t *vcmp_ctrl; + volatile uint8_t *vcmp_adc_chm; + volatile uint8_t *vcmp_datm; + volatile uint8_t *vcmp_datl; +}; + +/* supported flags (member "flag" in struct vcmp_t) for voltage comparator */ +#define GREATER_THRESHOLD BIT(0) +#define LESS_EQUAL_THRESHOLD BIT(1) + +/* Data structure for board to define voltage comparator list. */ +struct vcmp_t { + const char *name; + int threshold; + /* + * Select greater/less equal threshold. + * NOTE: once edge trigger interrupt fires, we need disable the voltage + * comparator, or the matching threshold level will infinitely + * triggers interrupt. + */ + char flag; + /* Called when the interrupt fires */ + void (*vcmp_thresh_cb)(void); + /* + * Select "all voltage comparator" scan period time. + * The power consumption is positively relative with scan frequency. + */ + enum vcmp_scan_period scan_period; + /* + * Select which ADC channel output voltage into comparator and we + * should set the ADC channel pin in alternate mode via adc_channels[]. + */ + enum chip_adc_channel adc_ch; +}; + /* * Boards must provide this list of ADC channel definitions. This must match * the enum adc_channel list provided by the board. */ extern const struct adc_t adc_channels[]; +#ifdef CONFIG_ADC_VOLTAGE_COMPARATOR +/* + * Boards must provide this list of voltage comparator definitions. + * This must match the enum board_vcmp list provided by the board. + */ +extern const struct vcmp_t vcmp_list[]; +void vcmp_enable(int index, int enable); +#endif + #endif /* __CROS_EC_ADC_CHIP_H */ |