ITE: drivers/adc: Add config of ADC reference voltage full-scale 3300mV

This option can enable ADC internal reference voltage as
full-scale 3300mV.

Signed-off-by: Tim Lin <tim2.lin@ite.corp-partner.google.com>
This commit is contained in:
Tim Lin 2023-02-16 17:54:42 +08:00 committed by Carles Cufí
parent 4fcc3f0c1e
commit 00e6c19ab5
5 changed files with 43 additions and 2 deletions

View file

@ -13,3 +13,13 @@ config ADC_ITE_IT8XXX2
Voltage range 0 to 3000mV.
Support 10-bit resolution.
Support 8 channels: ch0~ch7.
if ADC_ITE_IT8XXX2
config ADC_IT8XXX2_VOL_FULL_SCALE
bool "ADC internal voltage as full-scale"
help
This option enables ADC internal reference
voltage as full-scale 3300mV.
endif # ADC_ITE_IT8XXX2

View file

@ -22,7 +22,11 @@ LOG_MODULE_REGISTER(adc_ite_it8xxx2);
#include "adc_context.h"
/* ADC internal reference voltage (Unit:mV) */
#ifdef CONFIG_ADC_IT8XXX2_VOL_FULL_SCALE
#define IT8XXX2_ADC_VREF_VOL 3300
#else
#define IT8XXX2_ADC_VREF_VOL 3000
#endif
/* ADC channels disabled */
#define IT8XXX2_ADC_CHANNEL_DISABLED 0x1F
/* ADC sample time delay (Unit:us) */
@ -33,6 +37,12 @@ LOG_MODULE_REGISTER(adc_ite_it8xxx2);
#define ADC_CHANNEL_SHIFT 5
#define ADC_CHANNEL_OFFSET(ch) ((ch)-CHIP_ADC_CH13-ADC_CHANNEL_SHIFT)
#ifdef CONFIG_ADC_IT8XXX2_VOL_FULL_SCALE
#define ADC_0_7_FULL_SCALE_MASK GENMASK(7, 0)
#define ADC_8_10_FULL_SCALE_MASK GENMASK(2, 0)
#define ADC_13_16_FULL_SCALE_MASK GENMASK(3, 0)
#endif
/* List of ADC channels. */
enum chip_adc_channel {
CHIP_ADC_CH0 = 0,
@ -407,6 +417,12 @@ static int adc_it8xxx2_init(const struct device *dev)
struct adc_it8xxx2_regs *const adc_regs = ADC_IT8XXX2_REG_BASE;
int status;
#ifdef CONFIG_ADC_IT8XXX2_VOL_FULL_SCALE
/* ADC input voltage 0V ~ AVCC (3.3V) is mapped into 0h-3FFh */
adc_regs->ADCIVMFSCS1 = ADC_0_7_FULL_SCALE_MASK;
adc_regs->ADCIVMFSCS2 = ADC_8_10_FULL_SCALE_MASK;
adc_regs->ADCIVMFSCS3 = ADC_13_16_FULL_SCALE_MASK;
#endif
/* ADC analog accuracy initialization */
adc_accuracy_initialization();

View file

@ -22,7 +22,11 @@ LOG_MODULE_REGISTER(vcmp_ite_it8xxx2, CONFIG_SENSOR_LOG_LEVEL);
#define VCMP_REG_MASK 0x7
#define VCMP_RESOLUTION BIT(10)
#ifdef CONFIG_ADC_IT8XXX2_VOL_FULL_SCALE
#define VCMP_MAX_MVOLT 3300
#else
#define VCMP_MAX_MVOLT 3000
#endif
/* Device config */
struct vcmp_it8xxx2_config {

View file

@ -140,6 +140,9 @@ IT8XXX2_REG_OFFSET_CHECK(kscan_it8xxx2_regs, KBS_KSOLGOEN, 0x0e);
IT8XXX2_REG_SIZE_CHECK(adc_it8xxx2_regs, 0x6d);
IT8XXX2_REG_OFFSET_CHECK(adc_it8xxx2_regs, ADCGCR, 0x03);
IT8XXX2_REG_OFFSET_CHECK(adc_it8xxx2_regs, VCH0DATM, 0x19);
IT8XXX2_REG_OFFSET_CHECK(adc_it8xxx2_regs, ADCIVMFSCS1, 0x55);
IT8XXX2_REG_OFFSET_CHECK(adc_it8xxx2_regs, ADCIVMFSCS2, 0x56);
IT8XXX2_REG_OFFSET_CHECK(adc_it8xxx2_regs, ADCIVMFSCS3, 0x57);
IT8XXX2_REG_OFFSET_CHECK(adc_it8xxx2_regs, adc_vchs_ctrl[0].VCHCTL, 0x60);
IT8XXX2_REG_OFFSET_CHECK(adc_it8xxx2_regs, adc_vchs_ctrl[2].VCHDATM, 0x67);
IT8XXX2_REG_OFFSET_CHECK(adc_it8xxx2_regs, ADCDVSTS2, 0x6c);

View file

@ -757,8 +757,16 @@ struct adc_it8xxx2_regs {
volatile uint8_t reserved2[42];
/* 0x44: ADC Data Valid Status */
volatile uint8_t ADCDVSTS;
/* 0x45-0x5f: Reserved3 */
volatile uint8_t reserved3[27];
/* 0x45-0x54: Reserved2-1 */
volatile uint8_t reserved2_1[16];
/* 0x55: ADC Input Voltage Mapping Full-Scale Code Selection 1 */
volatile uint8_t ADCIVMFSCS1;
/* 0x56: ADC Input Voltage Mapping Full-Scale Code Selection 2 */
volatile uint8_t ADCIVMFSCS2;
/* 0x57: ADC Input Voltage Mapping Full-Scale Code Selection 3 */
volatile uint8_t ADCIVMFSCS3;
/* 0x58-0x5f: Reserved3 */
volatile uint8_t reserved3[8];
/* 0x60-0x6b: ADC channel 13~16 controller */
struct adc_vchs_ctrl_t adc_vchs_ctrl[4];
/* 0x6c: ADC Data Valid Status 2 */