Merge "dev: vadc: Add fast averaging samples configuration"
diff --git a/dev/pmic/pm8x41/include/pm_vadc_hc.h b/dev/pmic/pm8x41/include/pm_vadc_hc.h
index 53312cb..8e0dba4 100644
--- a/dev/pmic/pm8x41/include/pm_vadc_hc.h
+++ b/dev/pmic/pm8x41/include/pm_vadc_hc.h
@@ -48,12 +48,12 @@
#define HC_DEC_RATIO_SHIFT 2
#define HC_FAST_AVG_CTL 0x43
-#define HC_FAST_AVG_SAMPLES_MASK 0xfff
+#define HC_FAST_AVG_SAMPLES_MASK 0x7
#define HC_ADC_CH_SEL_CTL 0x44
#define HC_DELAY_CTL 0x45
-#define HC_DELAY_CTL_MASK 0xfff
+#define HC_DELAY_CTL_MASK 0xf
#define HC_EN_CTL1 0x46
#define HC_ADC_EN BIT(7)
@@ -79,6 +79,15 @@
enum adc_type adc_type;
};
+enum adc_fast_avg_sample {
+ AVG_1_SAMPLE = 0,
+ AVG_2_SAMPLES,
+ AVG_4_SAMPLES,
+ AVG_8_SAMPLES,
+ AVG_16_SAMPLES,
+ AVG_SAMPLES_INVALID
+};
+
enum adc_channel_prediv_type {
SCALE_DIV1 = 0,
SCALE_DIV3,
diff --git a/dev/pmic/pm8x41/pm_vadc_hc.c b/dev/pmic/pm8x41/pm_vadc_hc.c
index fdf26ab..7517a31 100644
--- a/dev/pmic/pm8x41/pm_vadc_hc.c
+++ b/dev/pmic/pm8x41/pm_vadc_hc.c
@@ -61,9 +61,11 @@
enum adc_hc_channel channel;
/* Hardware settling delay for the channel */
enum adc_usr_delay_ctl hw_settle;
+ /* Fast average sample value for the channel */
+ enum adc_fast_avg_sample avg_sample;
/*
* Pre scale ratio for the channel before ADC is measured.
- * This is used during scaling the code to physical units by
+ * This is used while scaling the code to physical units by
* applying the respective pre-scale value.
*/
struct adc_pre_scale_ratio pre_scale;
@@ -107,6 +109,7 @@
HC_ABS_CAL,
HC_CALIB_VREF_1P25,
HC_HW_SETTLE_DELAY_0US,
+ AVG_1_SAMPLE,
{1, 1},
scale_default_voltage
},
@@ -115,6 +118,7 @@
HC_ABS_CAL,
HC_VPH_PWR,
HC_HW_SETTLE_DELAY_0US,
+ AVG_1_SAMPLE,
{1, 3},
scale_default_voltage
},
@@ -201,7 +205,7 @@
static void vadc_hc_configure(struct vadc_hc_periph_cfg *adc_cfg,
struct vadc_hc_channel_cfg *ch_cfg)
{
- uint8_t cal = 0;
+ uint8_t cal = 0, avg_samples = 0;
/* Configure calibration select */
vadc_hc_reg_read(adc_cfg, HC_ADC_DIG_PARAM, &cal);
@@ -215,6 +219,12 @@
/* HW settle delay */
vadc_hc_reg_write(adc_cfg, HC_DELAY_CTL, ch_cfg->hw_settle);
+ /* Fast avg sample value */
+ vadc_hc_reg_read(adc_cfg, HC_FAST_AVG_CTL, &avg_samples);
+ avg_samples &= ~HC_FAST_AVG_SAMPLES_MASK;
+ avg_samples |= ch_cfg->avg_sample;
+ vadc_hc_reg_write(adc_cfg, HC_FAST_AVG_CTL, avg_samples);
+
/* Enable ADC */
vadc_hc_reg_write(adc_cfg, HC_EN_CTL1, HC_ADC_EN);