<div dir="auto">Reviewed-by: Rick Altherr <<a href="mailto:raltherr@google.com">raltherr@google.com</a>></div><div class="gmail_extra"><br><div class="gmail_quote">On Jul 14, 2017 1:12 AM, "Mykola Kostenok" <<a href="mailto:c_mykolak@mellanox.com">c_mykolak@mellanox.com</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">This patch enables adc engine at initialization time and waits<br>
for the initial sequence completion before enabling adc channels.<br>
<br>
Without this code adc channels are not functional and shows<br>
zeros for all connected channels.<br>
<br>
Tested on mellanox msn platform.<br>
<br>
v1 -> v2:<br>
Pointed by Rick Altherr:<br>
- Wait init sequence code enabled by bool<br>
from OF match table.<br>
<br>
Signed-off-by: Mykola Kostenok <<a href="mailto:c_mykolak@mellanox.com">c_mykolak@mellanox.com</a>><br>
---<br>
drivers/iio/adc/aspeed_adc.c | 26 ++++++++++++++++++++++++++<br>
1 file changed, 26 insertions(+)<br>
<br>
diff --git a/drivers/iio/adc/aspeed_adc.c b/drivers/iio/adc/aspeed_adc.c<br>
index 2283ed2..cfa7ee1 100644<br>
--- a/drivers/iio/adc/aspeed_adc.c<br>
+++ b/drivers/iio/adc/aspeed_adc.c<br>
@@ -22,6 +22,7 @@<br>
<br>
#include <linux/iio/iio.h><br>
#include <linux/iio/driver.h><br>
+#include <linux/iopoll.h><br>
<br>
#define ASPEED_RESOLUTION_BITS 10<br>
#define ASPEED_CLOCKS_PER_SAMPLE 12<br>
@@ -38,11 +39,17 @@<br>
<br>
#define ASPEED_ENGINE_ENABLE BIT(0)<br>
<br>
+#define ASPEED_ADC_CTRL_INIT_RDY BIT(8)<br>
+<br>
+#define ASPEED_ADC_INIT_POLLING_TIME 500<br>
+#define ASPEED_ADC_INIT_TIMEOUT 500000<br>
+<br>
struct aspeed_adc_model_data {<br>
const char *model_name;<br>
unsigned int min_sampling_rate; // Hz<br>
unsigned int max_sampling_rate; // Hz<br>
unsigned int vref_voltage; // mV<br>
+ bool wait_init_sequence;<br>
};<br>
<br>
struct aspeed_adc_data {<br>
@@ -210,6 +217,24 @@ static int aspeed_adc_probe(struct platform_device *pdev)<br>
goto scaler_error;<br>
}<br>
<br>
+ model_data = of_device_get_match_data(&<wbr>pdev->dev);<br>
+<br>
+ if (model_data->wait_init_<wbr>sequence) {<br>
+ /* Enable engine in normal mode. */<br>
+ writel(ASPEED_OPERATION_MODE_<wbr>NORMAL | ASPEED_ENGINE_ENABLE,<br>
+ data->base + ASPEED_REG_ENGINE_CONTROL);<br>
+<br>
+ /* Wait for initial sequence complete. */<br>
+ ret = readl_poll_timeout(data->base + ASPEED_REG_ENGINE_CONTROL,<br>
+ adc_engine_control_reg_val,<br>
+ adc_engine_control_reg_val &<br>
+ ASPEED_ADC_CTRL_INIT_RDY,<br>
+ ASPEED_ADC_INIT_POLLING_TIME,<br>
+ ASPEED_ADC_INIT_TIMEOUT);<br>
+ if (ret)<br>
+ goto scaler_error;<br>
+ }<br>
+<br>
/* Start all channels in normal mode. */<br>
clk_prepare_enable(data->clk_<wbr>scaler->clk);<br>
adc_engine_control_reg_val = GENMASK(31, 16) |<br>
@@ -269,6 +294,7 @@ static const struct aspeed_adc_model_data ast2500_model_data = {<br>
.vref_voltage = 1800, // mV<br>
.min_sampling_rate = 1,<br>
.max_sampling_rate = 1000000,<br>
+ .wait_init_sequence = true,<br>
};<br>
<br>
static const struct of_device_id aspeed_adc_matches[] = {<br>
--<br>
2.8.4<br>
<br>
</blockquote></div></div>