ITE drivers/sensor: add voltage comparator driver

Add voltage comparator driver for ITE it8xxx2 chip.

Signed-off-by: Ruibin Chang <Ruibin.Chang@ite.com.tw>
This commit is contained in:
Ruibin Chang 2022-02-22 17:11:18 +08:00 committed by Marti Bolivar
commit a21d043f5b
11 changed files with 637 additions and 1 deletions

View file

@ -103,6 +103,7 @@ add_subdirectory_ifdef(CONFIG_ITDS wsen_itds)
add_subdirectory_ifdef(CONFIG_MCUX_ACMP mcux_acmp)
add_subdirectory_ifdef(CONFIG_TACH_NPCX nuvoton_tach_npcx)
add_subdirectory_ifdef(CONFIG_TACH_IT8XXX2 ite_tach_it8xxx2)
add_subdirectory_ifdef(CONFIG_VCMP_IT8XXX2 ite_vcmp_it8xxx2)
if(CONFIG_USERSPACE OR CONFIG_SENSOR_SHELL OR CONFIG_SENSOR_SHELL_BATTERY)
# The above if() is needed or else CMake would complain about

View file

@ -242,4 +242,6 @@ source "drivers/sensor/nuvoton_tach_npcx/Kconfig"
source "drivers/sensor/ite_tach_it8xxx2/Kconfig"
source "drivers/sensor/ite_vcmp_it8xxx2/Kconfig"
endif # SENSOR

View file

@ -0,0 +1,5 @@
# SPDX-License-Identifier: Apache-2.0
zephyr_library()
zephyr_library_sources(vcmp_ite_it8xxx2.c)

View file

@ -0,0 +1,15 @@
# ITE Voltage Comparator driver configuration options
# Copyright (c) 2022 ITE Technology Corporation.
# SPDX-License-Identifier: Apache-2.0
DT_COMPAT_ITE_IT8XXX2_VCMP := ite,it8xxx2-vcmp
config VCMP_IT8XXX2
bool "ITE it8xxx2 Voltage Comparator"
depends on SOC_IT8XXX2 && ADC_ITE_IT8XXX2
default $(dt_compat_enabled,$(DT_COMPAT_ITE_IT8XXX2_VCMP))
help
This option enables the ITE it8xxx2 voltage comparator,
it8xxx2 supports six 10-bit resolution voltage comparator
channels, and the input of each comparator comes from ADC pin.

View file

@ -0,0 +1,383 @@
/*
* Copyright (c) 2022 ITE Technology Corporation.
*
* SPDX-License-Identifier: Apache-2.0
*/
#define DT_DRV_COMPAT ite_it8xxx2_vcmp
#include <device.h>
#include <devicetree/io-channels.h>
#include <drivers/adc.h>
#include <drivers/sensor.h>
#include <drivers/sensor/it8xxx2_vcmp.h>
#include <dt-bindings/dt-util.h>
#include <dt-bindings/sensor/it8xxx2_vcmp.h>
#include <errno.h>
#include <soc.h>
#include <soc_dt.h>
#include <logging/log.h>
LOG_MODULE_REGISTER(vcmp_ite_it8xxx2, CONFIG_SENSOR_LOG_LEVEL);
#define VCMP_REG_MASK 0x7
#define VCMP_RESOLUTION BIT(10)
#define VCMP_MAX_MVOLT 3000
/* Device config */
struct vcmp_it8xxx2_config {
/* Voltage comparator x control register */
volatile uint8_t *reg_vcmpxctl;
/* Voltage comparator x channel select MSB register */
volatile uint8_t *reg_vcmpxcselm;
/* Voltage comparator scan period register */
volatile uint8_t *reg_vcmpscp;
/* Voltage comparator x threshold data buffer MSB register */
volatile uint8_t *reg_vcmpxthrdatm;
/* Voltage comparator x threshold data buffer LSB register */
volatile uint8_t *reg_vcmpxthrdatl;
/* Voltage comparator status register */
volatile uint8_t *reg_vcmpsts;
/* Voltage comparator status 2 register */
volatile uint8_t *reg_vcmpsts2;
/* Voltage comparator module irq */
int irq;
/* Voltage comparator module irq config function */
void (*irq_cfg_func)(void);
/* Voltage comparator channel */
int vcmp_ch;
/* Scan period for "all voltage comparator channel" */
int scan_period;
/*
* Determines the condition between ADC data and threshold_mv
* that will trigger voltage comparator interrupt.
*/
int comparison;
/* Threshold assert value in mv */
int threshold_mv;
/* Pointer of ADC device that will be performing measurement */
const struct device *adc;
};
/* Driver data */
struct vcmp_it8xxx2_data {
/* ADC channel config */
struct adc_channel_cfg adc_ch_cfg;
/* Work queue to be notified when threshold assertion happens */
struct k_work work;
/* Sensor trigger hanlder to notify user of assetion */
sensor_trigger_handler_t handler;
/* Pointer of voltage comparator device */
const struct device *vcmp;
};
/* Voltage comparator work queue address */
static uint32_t vcmp_work_addr[VCMP_CHANNEL_CNT];
static void clear_vcmp_status(const struct device *dev, int vcmp_ch)
{
const struct vcmp_it8xxx2_config *const config = dev->config;
volatile uint8_t *reg_vcmpsts = config->reg_vcmpsts;
volatile uint8_t *reg_vcmpsts2 = config->reg_vcmpsts2;
/* W/C voltage comparator specific channel interrupt status */
if (vcmp_ch <= VCMP_CHANNEL_2) {
*reg_vcmpsts = BIT(vcmp_ch);
} else {
*reg_vcmpsts2 = BIT(vcmp_ch - VCMP_CHANNEL_3);
}
}
static void vcmp_enable(const struct device *dev, int enable)
{
const struct vcmp_it8xxx2_config *const config = dev->config;
volatile uint8_t *reg_vcmpxctl = config->reg_vcmpxctl;
if (enable) {
/* Enable voltage comparator specific channel interrupt */
*reg_vcmpxctl |= IT8XXX2_VCMP_CMPINTEN;
/* Start voltage comparator specific channel */
*reg_vcmpxctl |= IT8XXX2_VCMP_CMPEN;
} else {
/* Stop voltage comparator specific channel */
*reg_vcmpxctl &= ~IT8XXX2_VCMP_CMPEN;
/* Disable voltage comparator specific channel interrupt */
*reg_vcmpxctl &= ~IT8XXX2_VCMP_CMPINTEN;
}
}
static int vcmp_set_threshold(const struct device *dev,
enum sensor_attribute attr,
int32_t reg_val)
{
const struct vcmp_it8xxx2_config *const config = dev->config;
volatile uint8_t *reg_vcmpxthrdatm = config->reg_vcmpxthrdatm;
volatile uint8_t *reg_vcmpxthrdatl = config->reg_vcmpxthrdatl;
volatile uint8_t *reg_vcmpxctl = config->reg_vcmpxctl;
if (reg_val >= VCMP_RESOLUTION) {
LOG_ERR("Vcmp%d threshold only support 10-bits", config->vcmp_ch);
return -ENOTSUP;
}
/* Set threshold raw value */
*reg_vcmpxthrdatl = (uint8_t)(reg_val & 0xff);
*reg_vcmpxthrdatm = (uint8_t)((reg_val >> 8) & 0xff);
/* Set lower or higher threshold */
if ((attr == SENSOR_ATTR_UPPER_THRESH) ||
(attr == (uint16_t) SENSOR_ATTR_UPPER_VOLTAGE_THRESH)) {
*reg_vcmpxctl |= IT8XXX2_VCMP_GREATER_THRESHOLD;
} else {
*reg_vcmpxctl &= ~IT8XXX2_VCMP_GREATER_THRESHOLD;
}
return 0;
}
static void it8xxx2_vcmp_trigger_work_handler(struct k_work *item)
{
struct vcmp_it8xxx2_data *data =
CONTAINER_OF(item, struct vcmp_it8xxx2_data, work);
struct sensor_trigger trigger = {
.type = SENSOR_TRIG_THRESHOLD,
.chan = SENSOR_CHAN_VOLTAGE
};
if (data->handler) {
data->handler(data->vcmp, &trigger);
}
}
static int vcmp_ite_it8xxx2_attr_set(const struct device *dev,
enum sensor_channel chan,
enum sensor_attribute attr,
const struct sensor_value *val)
{
const struct vcmp_it8xxx2_config *const config = dev->config;
int32_t reg_val, ret = 0;
if (chan != SENSOR_CHAN_VOLTAGE) {
return -ENOTSUP;
}
switch ((uint16_t)attr) {
case SENSOR_ATTR_LOWER_THRESH:
case SENSOR_ATTR_UPPER_THRESH:
ret = vcmp_set_threshold(dev, attr, val->val1);
break;
case SENSOR_ATTR_LOWER_VOLTAGE_THRESH:
case SENSOR_ATTR_UPPER_VOLTAGE_THRESH:
/*
* Tranfrom threshold from mv to raw
* NOTE: CMPXTHRDAT[9:0] = threshold(mv) * 1024 / 3000(mv)
*/
reg_val = (val->val1 * VCMP_RESOLUTION / VCMP_MAX_MVOLT);
ret = vcmp_set_threshold(dev, attr, reg_val);
break;
case SENSOR_ATTR_ALERT:
if (!!val->val1) {
clear_vcmp_status(dev, config->vcmp_ch);
vcmp_enable(dev, 1);
} else {
vcmp_enable(dev, 0);
clear_vcmp_status(dev, config->vcmp_ch);
}
break;
default:
ret = -ENOTSUP;
}
return ret;
}
static int vcmp_ite_it8xxx2_trigger_set(const struct device *dev,
const struct sensor_trigger *trig,
sensor_trigger_handler_t handler)
{
const struct vcmp_it8xxx2_config *const config = dev->config;
struct vcmp_it8xxx2_data *const data = dev->data;
if (trig->type != SENSOR_TRIG_THRESHOLD ||
trig->chan != SENSOR_CHAN_VOLTAGE) {
return -ENOTSUP;
}
data->handler = handler;
vcmp_work_addr[config->vcmp_ch] = (uint32_t) &data->work;
return 0;
}
static int vcmp_it8xxx2_channel_get(const struct device *dev,
enum sensor_channel chan,
struct sensor_value *val)
{
const struct vcmp_it8xxx2_config *const config = dev->config;
if (chan != SENSOR_CHAN_VOLTAGE) {
return -ENOTSUP;
}
/*
* It8xxx2 adc and comparator module read automatically, according to
* {ADCCTS1, ADCCTS2} and VCMPSCP register setting.
*/
val->val1 = config->vcmp_ch;
return 0;
}
/*
* All voltage comparator channels share one irq interrupt, so we
* need to handle all channels, when the interrupt fired.
*/
static void vcmp_it8xxx2_isr(const struct device *dev)
{
const struct vcmp_it8xxx2_config *const config = dev->config;
volatile uint8_t *reg_vcmpsts = config->reg_vcmpsts;
volatile uint8_t *reg_vcmpsts2 = config->reg_vcmpsts2;
int idx, status;
/* Find out which voltage comparator triggered */
status = *reg_vcmpsts & VCMP_REG_MASK;
status |= (*reg_vcmpsts2 & VCMP_REG_MASK) << 3;
for (idx = VCMP_CHANNEL_0; idx < VCMP_CHANNEL_CNT; idx++) {
if (status & BIT(idx)) {
/* Call triggered channel callback function in work queue */
if (vcmp_work_addr[idx]) {
k_work_submit((struct k_work *) vcmp_work_addr[idx]);
}
/* W/C voltage comparator specific channel interrupt status */
clear_vcmp_status(dev, idx);
}
}
/* W/C voltage comparator irq interrupt status */
ite_intc_isr_clear(config->irq);
}
static int vcmp_it8xxx2_init(const struct device *dev)
{
const struct vcmp_it8xxx2_config *const config = dev->config;
struct vcmp_it8xxx2_data *const data = dev->data;
volatile uint8_t *reg_vcmpxctl = config->reg_vcmpxctl;
volatile uint8_t *reg_vcmpxcselm = config->reg_vcmpxcselm;
volatile uint8_t *reg_vcmpscp = config->reg_vcmpscp;
/* Disable voltage comparator specific channel before init */
vcmp_enable(dev, 0);
/*
* ADC channel signal output to voltage comparator,
* so we need to set ADC channel to alternate mode first.
*/
if (!device_is_ready(config->adc)) {
LOG_ERR("ADC device not ready");
return -ENODEV;
}
adc_channel_setup(config->adc, &data->adc_ch_cfg);
/* Select which ADC channel output voltage into comparator */
if (data->adc_ch_cfg.channel_id <= 7) {
/* ADC channel 0~7 map to value 0x0~0x7 */
*reg_vcmpxctl |= data->adc_ch_cfg.channel_id & VCMP_REG_MASK;
*reg_vcmpxcselm &= ~IT8XXX2_VCMP_VCMPXCSELM;
} else {
/* ADC channel 13~16 map to value 0x8~0xb */
*reg_vcmpxctl |= (data->adc_ch_cfg.channel_id - 5) & VCMP_REG_MASK;
*reg_vcmpxcselm |= IT8XXX2_VCMP_VCMPXCSELM;
}
/* Set minimum scan period for "all voltage comparator channel" */
if (*reg_vcmpscp > config->scan_period) {
*reg_vcmpscp = config->scan_period;
}
/* Data must keep device reference for worker handler */
data->vcmp = dev;
/* Init and set worker queue to enable notifications */
k_work_init(&data->work, it8xxx2_vcmp_trigger_work_handler);
vcmp_work_addr[config->vcmp_ch] = (uint32_t) &data->work;
/* Set threshold and comparison if set on device tree */
if ((config->threshold_mv != IT8XXX2_VCMP_UNDEFINED) &&
(config->comparison != IT8XXX2_VCMP_UNDEFINED)) {
enum sensor_attribute attr;
struct sensor_value val;
if (config->comparison == IT8XXX2_VCMP_LESS_OR_EQUAL) {
attr = SENSOR_ATTR_LOWER_VOLTAGE_THRESH;
} else {
attr = SENSOR_ATTR_UPPER_VOLTAGE_THRESH;
}
val.val1 = config->threshold_mv;
val.val2 = 0;
vcmp_ite_it8xxx2_attr_set(dev, SENSOR_CHAN_VOLTAGE, attr, &val);
}
ite_intc_isr_clear(config->irq);
config->irq_cfg_func();
irq_enable(config->irq);
return 0;
}
static const struct sensor_driver_api vcmp_ite_it8xxx2_api = {
.attr_set = vcmp_ite_it8xxx2_attr_set,
.trigger_set = vcmp_ite_it8xxx2_trigger_set,
.channel_get = vcmp_it8xxx2_channel_get,
};
#define VCMP_IT8XXX2_INIT(inst) \
static void vcmp_it8xxx2_irq_cfg_func_##inst(void) \
{ \
IRQ_CONNECT(DT_INST_IRQN(inst), \
0, \
vcmp_it8xxx2_isr, \
DEVICE_DT_INST_GET(inst), \
0); \
} \
\
static const struct vcmp_it8xxx2_config vcmp_it8xxx2_cfg_##inst = { \
.reg_vcmpxctl = (uint8_t *)DT_INST_REG_ADDR_BY_IDX(inst, 0), \
.reg_vcmpxcselm = (uint8_t *)DT_INST_REG_ADDR_BY_IDX(inst, 1), \
.reg_vcmpscp = (uint8_t *)DT_INST_REG_ADDR_BY_IDX(inst, 2), \
.reg_vcmpxthrdatm = (uint8_t *)DT_INST_REG_ADDR_BY_IDX(inst, 3), \
.reg_vcmpxthrdatl = (uint8_t *)DT_INST_REG_ADDR_BY_IDX(inst, 4), \
.reg_vcmpsts = (uint8_t *)DT_INST_REG_ADDR_BY_IDX(inst, 5), \
.reg_vcmpsts2 = (uint8_t *)DT_INST_REG_ADDR_BY_IDX(inst, 6), \
.irq = DT_INST_IRQN(inst), \
.irq_cfg_func = vcmp_it8xxx2_irq_cfg_func_##inst, \
.vcmp_ch = DT_INST_PROP(inst, vcmp_ch), \
.scan_period = DT_INST_PROP(inst, scan_period), \
.comparison = DT_INST_PROP(inst, comparison), \
.threshold_mv = DT_INST_PROP(inst, threshold_mv), \
.adc = DEVICE_DT_GET(DT_INST_IO_CHANNELS_CTLR(inst)), \
}; \
\
static struct vcmp_it8xxx2_data vcmp_it8xxx2_data_##inst = { \
.adc_ch_cfg.gain = ADC_GAIN_1, \
.adc_ch_cfg.reference = ADC_REF_INTERNAL, \
.adc_ch_cfg.acquisition_time = ADC_ACQ_TIME_DEFAULT, \
.adc_ch_cfg.channel_id = (uint8_t)DT_INST_IO_CHANNELS_INPUT(inst), \
}; \
\
DEVICE_DT_INST_DEFINE(inst, \
vcmp_it8xxx2_init, \
NULL, \
&vcmp_it8xxx2_data_##inst, \
&vcmp_it8xxx2_cfg_##inst, \
PRE_KERNEL_2, \
CONFIG_SENSOR_INIT_PRIORITY, \
&vcmp_ite_it8xxx2_api);
DT_INST_FOREACH_STATUS_OKAY(VCMP_IT8XXX2_INIT)

View file

@ -0,0 +1,51 @@
# Copyright (c) 2022 ITE Technology Corporation.
# SPDX-License-Identifier: Apache-2.0
description: ITE, it8xxx2 Voltage Comparator node
compatible: "ite,it8xxx2-vcmp"
include: base.yaml
properties:
reg:
required: true
label:
required: true
interrupts:
required: true
vcmp-ch:
type: int
required: true
description: Voltage comparator channel.
scan-period:
type: int
required: true
description: |
Select the scan interval for all comparator channel.
Check include/dt-bindings/sensor/it8xxx2_vcmp.h file for pre-defined values.
comparison:
type: int
required: true
description: |
Determines the condition to be met between ADC data and
threshold assert value that will trigger comparator interrupt.
Check include/dt-bindings/sensor/it8xxx2_vcmp.h file for pre-defined values.
threshold-mv:
type: int
required: true
description: |
16-bit value in milli-volts present on ADC data as threshold assert.
Check include/dt-bindings/sensor/it8xxx2_vcmp.h file for pre-defined values.
io-channels:
type: phandle-array
required: true
description: |
ADC channel that will perform measurement.

View file

@ -14,6 +14,7 @@
#include <dt-bindings/pinctrl/it8xxx2-pinctrl.h>
#include <dt-bindings/pwm/pwm.h>
#include <dt-bindings/pwm/it8xxx2_pwm.h>
#include <dt-bindings/sensor/it8xxx2_vcmp.h>
#include <dt-bindings/sensor/it8xxx2_tach.h>
#include "it8xxx2-alts-map.dtsi"
#include "ite/it8xxx2-wuc-map.dtsi"
@ -824,6 +825,96 @@
&pinctrl_adc15 /* ADC15*/
&pinctrl_adc16>;/* ADC16*/
};
vcmp0: vcmp@f01946 {
compatible = "ite,it8xxx2-vcmp";
reg = <0xf01946 0x01 /* VCMP0CTL */
0xf01977 0x01 /* VCMP0CSELM */
0xf01937 0x01 /* VCMPSCP */
0xf01947 0x01 /* VCMP0THRDATM */
0xf01948 0x01 /* VCMP0THRDATL */
0xf01945 0x01 /* VCMPSTS */
0xf0196d 0x01>; /* VCMPSTS2 */
label = "VCMP_0";
interrupts = <IT8XXX2_IRQ_V_CMP IRQ_TYPE_LEVEL_HIGH>;
interrupt-parent = <&intc>;
vcmp-ch = <VCMP_CHANNEL_0>;
status = "disabled";
};
vcmp1: vcmp@f01949 {
compatible = "ite,it8xxx2-vcmp";
reg = <0xf01949 0x01 /* VCMP1CTL */
0xf01978 0x01 /* VCMP1CSELM */
0xf01937 0x01 /* VCMPSCP */
0xf0194a 0x01 /* VCMP1THRDATM */
0xf0194b 0x01 /* VCMP1THRDATL */
0xf01945 0x01 /* VCMPSTS */
0xf0196d 0x01>; /* VCMPSTS2 */
label = "VCMP_1";
interrupts = <IT8XXX2_IRQ_V_CMP IRQ_TYPE_LEVEL_HIGH>;
interrupt-parent = <&intc>;
vcmp-ch = <VCMP_CHANNEL_1>;
status = "disabled";
};
vcmp2: vcmp@f0194c {
compatible = "ite,it8xxx2-vcmp";
reg = <0xf0194c 0x01 /* VCMP2CTL */
0xf01979 0x01 /* VCMP2CSELM */
0xf01937 0x01 /* VCMPSCP */
0xf0194d 0x01 /* VCMP2THRDATM */
0xf0194e 0x01 /* VCMP2THRDATL */
0xf01945 0x01 /* VCMPSTS */
0xf0196d 0x01>; /* VCMPSTS2 */
label = "VCMP_2";
interrupts = <IT8XXX2_IRQ_V_CMP IRQ_TYPE_LEVEL_HIGH>;
interrupt-parent = <&intc>;
vcmp-ch = <VCMP_CHANNEL_2>;
status = "disabled";
};
vcmp3: vcmp@f0196e {
compatible = "ite,it8xxx2-vcmp";
reg = <0xf0196e 0x01 /* VCMP3CTL */
0xf0197a 0x01 /* VCMP3CSELM */
0xf01937 0x01 /* VCMPSCP */
0xf0196f 0x01 /* VCMP3THRDATM */
0xf01970 0x01 /* VCMP3THRDATL */
0xf01945 0x01 /* VCMPSTS */
0xf0196d 0x01>; /* VCMPSTS2 */
label = "VCMP_3";
interrupts = <IT8XXX2_IRQ_V_CMP IRQ_TYPE_LEVEL_HIGH>;
interrupt-parent = <&intc>;
vcmp-ch = <VCMP_CHANNEL_3>;
status = "disabled";
};
vcmp4: vcmp@f01971 {
compatible = "ite,it8xxx2-vcmp";
reg = <0xf01971 0x01 /* VCMP4CTL */
0xf0197b 0x01 /* VCMP4CSELM */
0xf01937 0x01 /* VCMPSCP */
0xf01972 0x01 /* VCMP4THRDATM */
0xf01973 0x01 /* VCMP4THRDATL */
0xf01945 0x01 /* VCMPSTS */
0xf0196d 0x01>; /* VCMPSTS2 */
label = "VCMP_4";
interrupts = <IT8XXX2_IRQ_V_CMP IRQ_TYPE_LEVEL_HIGH>;
interrupt-parent = <&intc>;
vcmp-ch = <VCMP_CHANNEL_4>;
status = "disabled";
};
vcmp5: vcmp@f01974 {
compatible = "ite,it8xxx2-vcmp";
reg = <0xf01974 0x01 /* VCMP5CTL */
0xf0197c 0x01 /* VCMP5CSELM */
0xf01937 0x01 /* VCMPSCP */
0xf01975 0x01 /* VCMP5THRDATM */
0xf01976 0x01 /* VCMP5THRDATL */
0xf01945 0x01 /* VCMPSTS */
0xf0196d 0x01>; /* VCMPSTS2 */
label = "VCMP_5";
interrupts = <IT8XXX2_IRQ_V_CMP IRQ_TYPE_LEVEL_HIGH>;
interrupt-parent = <&intc>;
vcmp-ch = <VCMP_CHANNEL_5>;
status = "disabled";
};
i2c0: i2c@f01c40 {
compatible = "ite,it8xxx2-i2c";

View file

@ -0,0 +1,25 @@
/*
* Copyright (c) 2022 ITE Technology Corporation.
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef ZEPHYR_INCLUDE_DRIVERS_SENSOR_IT8XXX2_VCMP_H_
#define ZEPHYR_INCLUDE_DRIVERS_SENSOR_IT8XXX2_VCMP_H_
#ifdef __cplusplus
extern "C" {
#endif
#include <drivers/sensor.h>
enum it8xxx2_vcmp_sensor_attribute {
SENSOR_ATTR_LOWER_VOLTAGE_THRESH = SENSOR_ATTR_PRIV_START,
SENSOR_ATTR_UPPER_VOLTAGE_THRESH,
};
#ifdef __cplusplus
}
#endif
#endif /* ZEPHYR_INCLUDE_DRIVERS_SENSOR_IT8XXX2_VCMP_H_ */

View file

@ -137,6 +137,7 @@
#define IT8XXX2_IRQ_WU124 145
#define IT8XXX2_IRQ_WU125 146
#define IT8XXX2_IRQ_WU126 147
#define IT8XXX2_IRQ_V_CMP 151
/* Group 19 */
#define IT8XXX2_IRQ_SMB_E 152
#define IT8XXX2_IRQ_SMB_F 153

View file

@ -0,0 +1,54 @@
/*
* Copyright (c) 2022 ITE Technology Corporation.
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef ZEPHYR_INCLUDE_DT_BINDINGS_SENSOR_IT8XXX2_VCMP_H_
#define ZEPHYR_INCLUDE_DT_BINDINGS_SENSOR_IT8XXX2_VCMP_H_
/**
* @name it8xxx2 voltage comparator channel references
* @{
*/
#define VCMP_CHANNEL_0 0
#define VCMP_CHANNEL_1 1
#define VCMP_CHANNEL_2 2
#define VCMP_CHANNEL_3 3
#define VCMP_CHANNEL_4 4
#define VCMP_CHANNEL_5 5
#define VCMP_CHANNEL_CNT 6
/** @} */
/**
* @name it8xxx2 voltage comparator scan period for "all comparator channel"
* @{
*/
#define IT8XXX2_VCMP_SCAN_PERIOD_100US 0x10
#define IT8XXX2_VCMP_SCAN_PERIOD_200US 0x20
#define IT8XXX2_VCMP_SCAN_PERIOD_400US 0x30
#define IT8XXX2_VCMP_SCAN_PERIOD_600US 0x40
#define IT8XXX2_VCMP_SCAN_PERIOD_800US 0x50
#define IT8XXX2_VCMP_SCAN_PERIOD_1MS 0x60
#define IT8XXX2_VCMP_SCAN_PERIOD_1_5MS 0x70
#define IT8XXX2_VCMP_SCAN_PERIOD_2MS 0x80
#define IT8XXX2_VCMP_SCAN_PERIOD_2_5MS 0x90
#define IT8XXX2_VCMP_SCAN_PERIOD_3MS 0xa0
#define IT8XXX2_VCMP_SCAN_PERIOD_4MS 0xb0
#define IT8XXX2_VCMP_SCAN_PERIOD_5MS 0xc0
/** @} */
/**
* @name it8xxx2 voltage comparator interrupt trigger mode
* @{
*/
#define IT8XXX2_VCMP_LESS_OR_EQUAL 0
#define IT8XXX2_VCMP_GREATER 1
#define IT8XXX2_VCMP_UNDEFINED 0xffff
/** @} */
#endif /* ZEPHYR_INCLUDE_DT_BINDINGS_SENSOR_IT8XXX2_VCMP_H_ */

View file

@ -1,4 +1,4 @@
/*
/*
* Copyright (c) 2020 ITE Corporation. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/
@ -1510,6 +1510,14 @@ struct adc_it8xxx2_regs {
#define IT8XXX2_ADC_VCHEN BIT(4)
/* Automatic hardware calibration enable */
#define IT8XXX2_ADC_AHCE BIT(7)
/* 0x046, 0x049, 0x04c, 0x06e, 0x071, 0x074: Voltage comparator x control */
#define IT8XXX2_VCMP_CMPEN BIT(7)
#define IT8XXX2_VCMP_CMPINTEN BIT(6)
#define IT8XXX2_VCMP_GREATER_THRESHOLD BIT(5)
#define IT8XXX2_VCMP_EDGE_TRIGGER BIT(4)
#define IT8XXX2_VCMP_GPIO_ACTIVE_LOW BIT(3)
/* 0x077~0x07c: Voltage comparator x channel select MSB */
#define IT8XXX2_VCMP_VCMPXCSELM BIT(0)
/**
*