Skip to content

Commit

Permalink
GTA: Enable ADC de-glitch feature
Browse files Browse the repository at this point in the history
Summary:
# Description
1. Add aspeed patch to enable de-glitch feature for ADC monitor.
2. Initial ADC upper bound value after BMC boot up.
3. Fix some lint error.

# Motivation
To fix glitch signal of ADC.

X-link: facebookexternal/openbmc.wiwynn#2821

Test Plan:
1. Build and test pass on GTA system. pass

2. Get sensor reading and check the upper bound setting root@bmc-oob:~# sensor-util mb 0x5e
mb:
MB_P3V_BAT_VOLT_V            (0x5E) :   3.186 Volts | (ok)
root@bmc-oob:~# sensor-util scm
scm:
SCM_P12V_VOLT_V              (0xF0) :  12.077 Volts | (ok)
SCM_P5V_VOLT_V               (0xF1) :   4.983 Volts | (ok)
SCM_P3V3_VOLT_V              (0xF2) :   3.297 Volts | (ok)
SCM_P2V5_VOLT_V              (0xF3) :   2.491 Volts | (ok)
SCM_P1V8_VOLT_V              (0xF4) :   1.792 Volts | (ok)
SCM_PGPPA_VOLT_V             (0xF5) :   1.799 Volts | (ok)
SCM_P1V2_VOLT_V              (0xF6) :   1.191 Volts | (ok)
SCM_P1V0_VOLT_V              (0xF7) :   1.000 Volts | (ok)
SCM_INLET_TEMP_C             (0xFB) :  29.225 C     | (ok)

root@bmc-oob:/sys/bus/iio/devices/iio:device0/events# cat in_voltage0_thresh_rising_en 1
root@bmc-oob:/sys/bus/iio/devices/iio:device0/events# cat in_voltage0_thresh_rising_value 607
root@bmc-oob:/sys/bus/iio/devices/iio:device0/events# cat in_voltage1_thresh_rising_en 1
root@bmc-oob:/sys/bus/iio/devices/iio:device0/events# cat in_voltage1_thresh_rising_value 612
root@bmc-oob:/sys/bus/iio/devices/iio:device0/events# cat in_voltage2_thresh_rising_en 1
root@bmc-oob:/sys/bus/iio/devices/iio:device0/events# cat in_voltage2_thresh_rising_value 593
root@bmc-oob:/sys/bus/iio/devices/iio:device0/events# cat in_voltage3_thresh_rising_en 1
root@bmc-oob:/sys/bus/iio/devices/iio:device0/events# cat in_voltage3_thresh_rising_value 581
root@bmc-oob:/sys/bus/iio/devices/iio:device0/events# cat in_voltage4_thresh_rising_en 1
root@bmc-oob:/sys/bus/iio/devices/iio:device0/events# cat in_voltage4_thresh_rising_value 580
root@bmc-oob:/sys/bus/iio/devices/iio:device0/events# cat in_voltage5_thresh_rising_en 1
root@bmc-oob:/sys/bus/iio/devices/iio:device0/events# cat in_voltage5_thresh_rising_value 317
root@bmc-oob:/sys/bus/iio/devices/iio:device0/events# cat in_voltage6_thresh_rising_en 1
root@bmc-oob:/sys/bus/iio/devices/iio:device0/events# cat in_voltage6_thresh_rising_value 516
root@bmc-oob:/sys/bus/iio/devices/iio:device0/events# cat in_voltage7_thresh_rising_en 1
root@bmc-oob:/sys/bus/iio/devices/iio:device0/events# cat in_voltage7_thresh_rising_value 464
root@bmc-oob:/sys/bus/iio/devices/iio:device1/events# cat in_voltage0_thresh_rising_en 1
root@bmc-oob:/sys/bus/iio/devices/iio:device1/events# cat in_voltage0_thresh_rising_value 442

Reviewed By: williamspatrick

Differential Revision: D49941021

fbshipit-source-id: 6aa139dac7e116e1a3f848054bcf60512a5a75d3
  • Loading branch information
SeanChuangWiwynn authored and facebook-github-bot committed Oct 6, 2023
1 parent 204d433 commit 7f9c8ee
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ fi
#VPDB BRICK
# only for PVT DISCRETE Config
if [ "$vrev" -eq "$VPDB_DISCRETE_PVT" ] &&
( [ "$vsku" -eq "2" ] || [ "$vsku" -eq "5" ] ); then
{ [ "$vsku" -eq "2" ] || [ "$vsku" -eq "5" ]; }; then
# DISCRETE_PVT has unique sku ( 010 and 101 )
# that specially point out its brick source
brick_driver="raa228006"
Expand Down Expand Up @@ -367,7 +367,6 @@ fi
if [ "$vrev" -ge "$VPDB_PVT4" ]; then
# ADC Type
adc_type_dif="0"
adc_type_sgl="1"
adc_type="$(gpio_get VPDB_SKU_ID_4)"
adc_dif_sku="$(($(gpio_get VPDB_SKU_ID_6) << 1 | $(gpio_get VPDB_SKU_ID_5)))"
adc_sgl_sku="$(gpio_get VPDB_SKU_ID_7)"
Expand Down Expand Up @@ -399,9 +398,9 @@ if [ "$vrev" -ge "$VPDB_PVT4" ]; then
fi
else
# probe adc sig
if [ $adc_sgl_sku -eq 0 ]; then
if [ "$adc_sgl_sku" -eq 0 ]; then
i2c_device_add 36 0x35 max11617
echo 1 > /sys/bus/i2c/devices/36-0035/iio\:device*/polar_resistor
echo 1 > /sys/bus/i2c/devices/36-0035/iio:device*/polar_resistor
else
rebind_i2c_dev 36 48 ads1015
fi
Expand Down Expand Up @@ -492,7 +491,7 @@ hpdb_hsc=$(gpio_get HPDB_SKU_ID_0)

# HPDB_BOARD_ID_3 was present in between stage DVT and stage PVT3
# but the value was 1, so if revs in range 11 ~ 15 (DVT ~ PVT3) need to be reconfig.
if [ $hrev -ge 11 ] && [ $hrev -le 15 ]; then
if [ "$hrev" -ge 11 ] && [ "$hrev" -le 15 ]; then
kv set hpdb_rev "$((
$(gpio_get HPDB_BOARD_ID_2) << 2 |
$(gpio_get HPDB_BOARD_ID_1) << 1 |
Expand All @@ -502,7 +501,7 @@ if [ $hrev -ge 11 ] && [ $hrev -le 15 ]; then
fi

# Stage before PVT4
[ $hrev -lt $HPDB_PVT4 ] && hpdb_hsc=$(gpio_get HPDB_SKU_ID_2)
[ "$hrev" -lt "$HPDB_PVT4" ] && hpdb_hsc=$(gpio_get HPDB_SKU_ID_2)

if [ "$hpdb_hsc" -eq "$HPDB_HSC_MAIN" ] && [ "$hrev" -gt 1 ]; then
i2cset -f -y 39 0x40 0xD9 0x8b
Expand All @@ -522,7 +521,6 @@ if [ "$hrev" -ge "$HPDB_PVT4" ]; then

# ADC Type
adc_type_dif="0"
adc_type_sgl="1"
adc_type=$(gpio_get HPDB_SKU_ID_2)
adc_dif_sku="$(($(gpio_get HPDB_SKU_ID_4) << 1 | $(gpio_get HPDB_SKU_ID_3)))"
adc_sgl_sku=$(gpio_get HPDB_SKU_ID_5)
Expand Down Expand Up @@ -560,9 +558,9 @@ if [ "$hrev" -ge "$HPDB_PVT4" ]; then
fi
else
# probe adc sig
if [ $adc_sgl_sku -eq 0 ]; then
if [ "$adc_sgl_sku" -eq 0 ]; then
rebind_i2c_dev 37 35 max11617
echo 1 > /sys/bus/i2c/devices/37-0035/iio\:device*/polar_resistor
echo 1 > /sys/bus/i2c/devices/37-0035/iio:device*/polar_resistor
else
rebind_i2c_dev 37 48 ads1015
fi
Expand Down Expand Up @@ -935,3 +933,22 @@ if [ "$(is_bmc_por)" -eq 1 ]; then
sleep 3
fi

#Enable ADC upper bound value
#ADC0 ~ ADC7 upper bound value
adc0_upper_bound=("25F" "264" "251" "245" "244" "13D" "204" "1D0")
#ADC8 ~ ADC15 upper bound value
adc1_upper_bound=("1BA" " " " " " " " " " " " " " ")

for i in {0..7}; do
if [[ "${adc0_upper_bound["$i"]}" != " " ]]; then
echo $((0x"${adc0_upper_bound["$i"]}")) > /sys/bus/iio/devices/iio:device0/events/in_voltage"$i"_thresh_rising_value
echo 1 > /sys/bus/iio/devices/iio:device0/events/in_voltage"$i"_thresh_rising_en
fi
done
for i in {0..7}; do
if [[ "${adc1_upper_bound["$i"]}" != " " ]]; then
echo $((0x"${adc1_upper_bound["$i"]}")) > /sys/bus/iio/devices/iio:device1/events/in_voltage"$i"_thresh_rising_value
echo 1 > /sys/bus/iio/devices/iio:device1/events/in_voltage"$i"_thresh_rising_en
fi
done

Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ FILESEXTRAPATHS:prepend := "${THISDIR}/plat_conf:"

SRC_URI += "\
file://grandteton.cfg \
file://0001-iio-adc-aspeed-Extend-the-delay-time-to-meet-ADC-hw-.patch \
"

KERNEL_MODULE_AUTOLOAD += " \
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
From 8bf1e8fd0cad6f78413c6d7b7913092d758fde00 Mon Sep 17 00:00:00 2001
From: Billy Tsai <[email protected]>
Date: Tue, 13 Jun 2023 18:04:47 +0800
Subject: [PATCH] iio: adc: aspeed: Extend the delay time to meet ADC hw
behavior.

The patch is intended to extend the delay time when the last channel of
the ADC is enabled. In our ADC, it takes 12 dummy sampling periods to
switch the sampling channel from CH7 to CH0. Therefore, the patch checks
the enable status of channel 7 in order to determine the appropriate delay
period for obtaining the updated ADC values of each channel.

Signed-off-by: Billy Tsai <[email protected]>
Change-Id: I759510c9bddb704a384df83b8109b8e36d696f11
---
drivers/iio/adc/aspeed_adc.c | 13 ++++++++-----
1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/drivers/iio/adc/aspeed_adc.c b/drivers/iio/adc/aspeed_adc.c
index 6bdbc6b3158e..436cf8ad29c2 100644
--- a/drivers/iio/adc/aspeed_adc.c
+++ b/drivers/iio/adc/aspeed_adc.c
@@ -120,7 +120,7 @@ struct aspeed_adc_data {
int cv;
bool battery_sensing;
struct adc_gain battery_mode_gain;
- unsigned int enabled_channels_num;
+ unsigned int required_eoc_num;
u16 *upper_bound;
u16 *lower_bound;
bool *upper_en;
@@ -308,18 +308,18 @@ static int aspeed_adc_get_voltage_raw(struct aspeed_adc_data *data, struct iio_c
chan->channel, data->upper_en[chan->channel],
data->upper_bound[chan->channel], data->lower_en[chan->channel],
data->lower_bound[chan->channel], data->sample_period_ns,
- data->enabled_channels_num);
+ data->required_eoc_num);
if (data->upper_en[chan->channel]) {
if (val >= data->upper_bound[chan->channel]) {
ndelay(data->sample_period_ns *
- data->enabled_channels_num);
+ data->required_eoc_num);
val = readw(data->base + chan->address);
}
}
if (data->lower_en[chan->channel]) {
if (val <= data->lower_bound[chan->channel]) {
ndelay(data->sample_period_ns *
- data->enabled_channels_num);
+ data->required_eoc_num);
val = readw(data->base + chan->address);
}
}
@@ -806,7 +806,10 @@ static int aspeed_adc_probe(struct platform_device *pdev)
adc_engine_control_reg_val =
FIELD_GET(ASPEED_ADC_CTRL_CHANNEL,
readl(data->base + ASPEED_REG_ENGINE_CONTROL));
- data->enabled_channels_num = hweight_long(adc_engine_control_reg_val);
+ data->required_eoc_num = hweight_long(adc_engine_control_reg_val);
+ if (adc_engine_control_reg_val &
+ BIT(data->model_data->num_channels - 1))
+ data->required_eoc_num += 12;
indio_dev->name = data->model_data->model_name;
indio_dev->info = &aspeed_adc_iio_info;
indio_dev->modes = INDIO_DIRECT_MODE;
--
2.25.1

0 comments on commit 7f9c8ee

Please sign in to comment.