saradc: s6: Fix sampling errors [1/1]

PD#SWPL-177668

Problem:
There is an error in SARADC sampling.

Solution:
Use software to calculate average.

Verify:
S6/BL201 S7D/BM201

Change-Id: I390c39bf2160d6609a2556eb259c6d4d810dc3f2
Signed-off-by: Huqiang Qin <huqiang.qin@amlogic.com>
This commit is contained in:
Huqiang Qin
2025-04-25 15:17:10 +08:00
committed by Jun Zhang
parent 89cd3089b7
commit 2d1d04cabd
4 changed files with 42 additions and 16 deletions
+4 -4
View File
@@ -343,10 +343,10 @@
/* Delay configure */
amlogic,reg3-init = <0x10a02403>;
amlogic,reg4-init = <0x00000080>;
/* Set aux and extern vref */
amlogic,reg9-init = <0x0000e4e4>;
amlogic,reg10-init = <0x74543414>;
amlogic,reg11-init = <0xf4d4b494>;
/* Set aux and external vref */
amlogic,reg9-init = <0x0000f0f0>;
amlogic,reg10-init = <0x70503010>;
amlogic,reg11-init = <0xf0d0b090>;
reset-names = "analog";
resets = <&reset RESET_SAR_ANA>;
status = "disabled";
+4 -4
View File
@@ -429,10 +429,10 @@
/* Delay configure */
amlogic,reg3-init = <0x10a02403>;
amlogic,reg4-init = <0x001dd080>;
/* Set aux and extern vref */
amlogic,reg9-init = <0x0000e4e4>;
amlogic,reg10-init = <0x74543414>;
amlogic,reg11-init = <0xf4d4b494>;
/* Set aux and external vref */
amlogic,reg9-init = <0x0000f0f0>;
amlogic,reg10-init = <0x70503010>;
amlogic,reg11-init = <0xf0d0b090>;
reset-names = "analog";
resets = <&reset RESET_SAR_ANA>;
status = "disabled";
+4 -4
View File
@@ -343,10 +343,10 @@
/* Delay configure */
amlogic,reg3-init = <0x10a02403>;
amlogic,reg4-init = <0x00000080>;
/* Set aux and extern vref */
amlogic,reg9-init = <0x0000e4e4>;
amlogic,reg10-init = <0x74543414>;
amlogic,reg11-init = <0xf4d4b494>;
/* Set aux and external vref */
amlogic,reg9-init = <0x0000f0f0>;
amlogic,reg10-init = <0x70503010>;
amlogic,reg11-init = <0xf0d0b090>;
reset-names = "analog";
resets = <&reset RESET_SAR_ANA>;
status = "disabled";
+30 -4
View File
@@ -80,6 +80,7 @@
#define SARADC_CHANNEL_MAX 8
#define SARADC_MAX_FIFO_SIZE 16
#define SARADC_TIMEOUT 100 /* Millisecond */
#define SARADC_SOFT_AVG_NUM 8
#define SARADC_DEFAULT_CLOCK_FREQUENCY 1200000
#define SARADC_DEFAULT_TEST_CHANNEL 7
@@ -236,9 +237,9 @@ static void amlogic_saradc_stop_sample(struct amlogic_saradc_priv *priv)
SARADC_REG0_ADC_EN, 0);
}
static int amlogic_saradc_get_sample(struct iio_dev *indio_dev,
const struct iio_chan_spec *chan,
int *val, bool en_avg)
static int amlogic_saradc_get_sample_once(struct iio_dev *indio_dev,
const struct iio_chan_spec *chan,
int *val, bool en_avg)
{
struct amlogic_saradc_priv *priv = iio_priv(indio_dev);
int ret;
@@ -247,7 +248,7 @@ static int amlogic_saradc_get_sample(struct iio_dev *indio_dev,
mutex_lock(&priv->lock);
/* Configure the averaging mode of the channels we use */
amlogic_saradc_set_averaging(priv, 0,
amlogic_saradc_set_averaging(priv, chan->address,
en_avg ? MEDIAN_AVERAGING : NO_AVERAGING,
en_avg ? EIGHT_SAMPLES : ONE_SAMPLE);
@@ -274,6 +275,31 @@ fail:
return ret;
}
static int amlogic_saradc_get_sample(struct iio_dev *indio_dev,
const struct iio_chan_spec *chan,
int *val, bool en_avg)
{
struct amlogic_saradc_priv *priv = iio_priv(indio_dev);
int sum = 0;
int tmp;
int ret;
int count;
if (!priv->apply_workaround || !en_avg)
return amlogic_saradc_get_sample_once(indio_dev, chan, val, en_avg);
for (count = 0; count < SARADC_SOFT_AVG_NUM; count++) {
ret = amlogic_saradc_get_sample_once(indio_dev, chan, &tmp, false);
if (ret < 0)
return ret;
sum += tmp;
}
*val = sum / SARADC_SOFT_AVG_NUM;
return ret;
}
static int amlogic_saradc_get_sample_voltage(struct iio_dev *indio_dev,
const struct iio_chan_spec *chan,
int *val, bool en_avg)