[PATCH linux dev-4.10] iio: aspeed-adc: wait for initial sequence.
Mykola Kostenok
c_mykolak at mellanox.com
Fri Jul 14 16:35:33 AEST 2017
Hi, Rick.
Thanks for reply.
We definitely have an issue with adc, without this initialization.
This without our changes:
root at msn:~# cat /sys/bus/iio/devices/iio\:device0/i*
653
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
And with:
root at msn:~# cat /sys/bus/iio/devices/iio\:device0/i*
755
776
715
681
657
0
0
0
771
770
759
0
0
0
0
0
We using AST2520, but it should not make any difference.
According to our output, this initialization is necessary. Possibly it could work without it, but in our case it doesn’t.
Will it be OK to do this initialization only for ast2500:
if (strcmp(model_data->model_name , ast2500_model_data.model_name) == 0)
?
Best regards. Mykola Kostenok.
From: Rick Altherr [mailto:raltherr at google.com]
Sent: Thursday, July 13, 2017 9:33 PM
To: Mykola Kostenok <c_mykolak at mellanox.com>
Cc: Joel Stanley <joel at jms.id.au>; OpenBMC Maillist <openbmc at lists.ozlabs.org>; Vadim Pasternak <vadimp at mellanox.com>; Ohad Oz <ohado at mellanox.com>
Subject: Re: [PATCH linux dev-4.10] iio: aspeed-adc: wait for initial sequence.
Huh. We've been getting valid readings without this on our AST2500 systems. Regardless, it is correct for AST2500. On AST2400 though, there is no INIT_RDY bit.
On Thu, Jul 13, 2017 at 7:28 AM, Mykola Kostenok <c_mykolak at mellanox.com<mailto:c_mykolak at mellanox.com>> wrote:
This patch enables adc engine at initialization time and waits
for the initial sequence completion before enabling adc channels.
Without this code adc channels are not functional and shows
zeros for all connected channels.
Tested on mellanox msn platform.
Signed-off-by: Mykola Kostenok <c_mykolak at mellanox.com<mailto:c_mykolak at mellanox.com>>
---
drivers/iio/adc/aspeed_adc.c | 20 ++++++++++++++++++++
1 file changed, 20 insertions(+)
diff --git a/drivers/iio/adc/aspeed_adc.c b/drivers/iio/adc/aspeed_adc.c
index 2283ed2..e4ad6ef 100644
--- a/drivers/iio/adc/aspeed_adc.c
+++ b/drivers/iio/adc/aspeed_adc.c
@@ -22,6 +22,7 @@
#include <linux/iio/iio.h>
#include <linux/iio/driver.h>
+#include <linux/iopoll.h>
#define ASPEED_RESOLUTION_BITS 10
#define ASPEED_CLOCKS_PER_SAMPLE 12
@@ -38,6 +39,11 @@
#define ASPEED_ENGINE_ENABLE BIT(0)
+#define ASPEED_ADC_CTRL_INIT_RDY BIT(8)
+
+#define ASPEED_ADC_INIT_POLLING_TIME 500
+#define ASPEED_ADC_INIT_TIMEOUT 500000
+
struct aspeed_adc_model_data {
const char *model_name;
unsigned int min_sampling_rate; // Hz
@@ -210,6 +216,20 @@ static int aspeed_adc_probe(struct platform_device *pdev)
goto scaler_error;
}
+ /* Enable engine in normal mode. */
+ writel(ASPEED_OPERATION_MODE_NORMAL | ASPEED_ENGINE_ENABLE,
+ data->base + ASPEED_REG_ENGINE_CONTROL);
+
+ /* Wait for initial sequence complete. */
+ ret = readl_poll_timeout(data->base + ASPEED_REG_ENGINE_CONTROL,
+ adc_engine_control_reg_val,
+ adc_engine_control_reg_val &
+ ASPEED_ADC_CTRL_INIT_RDY,
+ ASPEED_ADC_INIT_POLLING_TIME,
+ ASPEED_ADC_INIT_TIMEOUT);
+ if (ret)
+ goto scaler_error;
+
/* Start all channels in normal mode. */
clk_prepare_enable(data->clk_scaler->clk);
adc_engine_control_reg_val = GENMASK(31, 16) |
--
2.8.4
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ozlabs.org/pipermail/openbmc/attachments/20170714/ebd0c010/attachment-0001.html>
More information about the openbmc
mailing list