<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0in;
margin-bottom:.0001pt;
font-size:12.0pt;
font-family:"Times New Roman",serif;}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:blue;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:purple;
text-decoration:underline;}
p.msonormal0, li.msonormal0, div.msonormal0
{mso-style-name:msonormal;
mso-margin-top-alt:auto;
margin-right:0in;
mso-margin-bottom-alt:auto;
margin-left:0in;
font-size:12.0pt;
font-family:"Times New Roman",serif;}
span.hoenzb
{mso-style-name:hoenzb;}
span.EmailStyle19
{mso-style-type:personal-reply;
font-family:"Calibri",sans-serif;
color:windowtext;}
.MsoChpDefault
{mso-style-type:export-only;}
@page WordSection1
{size:8.5in 11.0in;
margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-US" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">Hi, Rick.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">Thanks for reply.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">We definitely have an issue with adc, without this initialization.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">This without our changes:<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:.5in"><span style="font-family:"Calibri",sans-serif;color:black">root@msn:~# cat /sys/bus/iio/devices/iio\:device0/i*<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:.5in"><span style="font-family:"Calibri",sans-serif;color:black">653<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:.5in"><span style="font-family:"Calibri",sans-serif;color:black">0<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:.5in"><span style="font-family:"Calibri",sans-serif;color:black">0<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:.5in"><span style="font-family:"Calibri",sans-serif;color:black">0<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:.5in"><span style="font-family:"Calibri",sans-serif;color:black">0<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:.5in"><span style="font-family:"Calibri",sans-serif;color:black">0<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:.5in"><span style="font-family:"Calibri",sans-serif;color:black">0<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:.5in"><span style="font-family:"Calibri",sans-serif;color:black">0<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:.5in"><span style="font-family:"Calibri",sans-serif;color:black">0<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:.5in"><span style="font-family:"Calibri",sans-serif;color:black">0<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:.5in"><span style="font-family:"Calibri",sans-serif;color:black">0<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:.5in"><span style="font-family:"Calibri",sans-serif;color:black">0<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:.5in"><span style="font-family:"Calibri",sans-serif;color:black">0<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:.5in"><span style="font-family:"Calibri",sans-serif;color:black">0<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:.5in"><span style="font-family:"Calibri",sans-serif;color:black">0<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:.5in"><span style="font-family:"Calibri",sans-serif;color:black">0<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">And with:<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:.5in"><span style="font-family:"Calibri",sans-serif;color:black">root@msn:~# cat /sys/bus/iio/devices/iio\:device0/i*<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:.5in"><span style="font-family:"Calibri",sans-serif;color:black">755<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:.5in"><span style="font-family:"Calibri",sans-serif;color:black">776<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:.5in"><span style="font-family:"Calibri",sans-serif;color:black">715<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:.5in"><span style="font-family:"Calibri",sans-serif;color:black">681<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:.5in"><span style="font-family:"Calibri",sans-serif;color:black">657<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:.5in"><span style="font-family:"Calibri",sans-serif;color:black">0<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:.5in"><span style="font-family:"Calibri",sans-serif;color:black">0<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:.5in"><span style="font-family:"Calibri",sans-serif;color:black">0<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:.5in"><span style="font-family:"Calibri",sans-serif;color:black">771<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:.5in"><span style="font-family:"Calibri",sans-serif;color:black">770<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:.5in"><span style="font-family:"Calibri",sans-serif;color:black">759<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:.5in"><span style="font-family:"Calibri",sans-serif;color:black">0<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:.5in"><span style="font-family:"Calibri",sans-serif;color:black">0<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:.5in"><span style="font-family:"Calibri",sans-serif;color:black">0<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:.5in"><span style="font-family:"Calibri",sans-serif;color:black">0<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-left:.5in"><span style="font-family:"Calibri",sans-serif;color:black">0<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">We using AST2520, but it should not make any difference.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">According to our output, this initialization is necessary. Possibly it could work without it, but in our case it doesn’t.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">Will it be OK to do this initialization only for ast2500:<o:p></o:p></span></p>
<p class="MsoNormal" style="text-indent:.5in"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">if (strcmp(model_data->model_name , ast2500_model_data.model_name) == 0)<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">?<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">Best regards. Mykola Kostenok.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif"><o:p> </o:p></span></p>
<div style="border:none;border-left:solid blue 1.5pt;padding:0in 0in 0in 4.0pt">
<div>
<div style="border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal"><b><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">From:</span></b><span style="font-size:11.0pt;font-family:"Calibri",sans-serif"> Rick Altherr [mailto:raltherr@google.com]
<br>
<b>Sent:</b> Thursday, July 13, 2017 9:33 PM<br>
<b>To:</b> Mykola Kostenok <c_mykolak@mellanox.com><br>
<b>Cc:</b> Joel Stanley <joel@jms.id.au>; OpenBMC Maillist <openbmc@lists.ozlabs.org>; Vadim Pasternak <vadimp@mellanox.com>; Ohad Oz <ohado@mellanox.com><br>
<b>Subject:</b> Re: [PATCH linux dev-4.10] iio: aspeed-adc: wait for initial sequence.<o:p></o:p></span></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<p class="MsoNormal">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.<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<p class="MsoNormal">On Thu, Jul 13, 2017 at 7:28 AM, Mykola Kostenok <<a href="mailto:c_mykolak@mellanox.com" target="_blank">c_mykolak@mellanox.com</a>> wrote:<o:p></o:p></p>
<blockquote style="border:none;border-left:solid #CCCCCC 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-right:0in">
<p class="MsoNormal" style="margin-bottom:12.0pt">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>
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 | 20 ++++++++++++++++++++<br>
1 file changed, 20 insertions(+)<br>
<br>
diff --git a/drivers/iio/adc/aspeed_adc.c b/drivers/iio/adc/aspeed_adc.c<br>
index 2283ed2..e4ad6ef 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,6 +39,11 @@<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>
@@ -210,6 +216,20 @@ static int aspeed_adc_probe(struct platform_device *pdev)<br>
goto scaler_error;<br>
}<br>
<br>
+ /* Enable engine in normal mode. */<br>
+ writel(ASPEED_OPERATION_MODE_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>
/* Start all channels in normal mode. */<br>
clk_prepare_enable(data->clk_scaler->clk);<br>
adc_engine_control_reg_val = GENMASK(31, 16) |<br>
<span class="hoenzb"><span style="color:#888888">--</span></span><span style="color:#888888"><br>
<span class="hoenzb">2.8.4</span></span><o:p></o:p></p>
</blockquote>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
</div>
</div>
</body>
</html>