diff mbox series

[[PATCH,v2] ] drm/ast: fixed reading monitor EDID not stable issue

Message ID 1540949474-1269-1-git-send-email-yc_chen@aspeedtech.com (mailing list archive)
State New, archived
Headers show
Series [[PATCH,v2] ] drm/ast: fixed reading monitor EDID not stable issue | expand

Commit Message

陳雅正 Oct. 31, 2018, 1:31 a.m. UTC
From: "Y.C. Chen" <yc_chen@aspeedtech.com>

v1: over-sample data to increase the stability with some specific monitors
v2: refine to avoid infinite loop

Signed-off-by: Y.C. Chen <yc_chen@aspeedtech.com>
---
 drivers/gpu/drm/ast/ast_mode.c | 34 ++++++++++++++++++++++++++++------
 1 file changed, 28 insertions(+), 6 deletions(-)

Comments

Dave Airlie Nov. 22, 2018, 1:15 a.m. UTC | #1
On Wed, 31 Oct 2018 at 18:12, Y.C. Chen <yacheng600221@gmail.com> wrote:
>
> From: "Y.C. Chen" <yc_chen@aspeedtech.com>
>
> v1: over-sample data to increase the stability with some specific monitors
> v2: refine to avoid infinite loop

This contains at least 4 whitespace breakages (val  =) in a few
places, also why the volatiles, I don't think they make much sense
here, have you verified they are required?

Dave.

>
> Signed-off-by: Y.C. Chen <yc_chen@aspeedtech.com>
> ---
>  drivers/gpu/drm/ast/ast_mode.c | 34 ++++++++++++++++++++++++++++------
>  1 file changed, 28 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/gpu/drm/ast/ast_mode.c b/drivers/gpu/drm/ast/ast_mode.c
> index 5e77d45..092e9a7 100644
> --- a/drivers/gpu/drm/ast/ast_mode.c
> +++ b/drivers/gpu/drm/ast/ast_mode.c
> @@ -972,9 +972,20 @@ static int get_clock(void *i2c_priv)
>  {
>         struct ast_i2c_chan *i2c = i2c_priv;
>         struct ast_private *ast = i2c->dev->dev_private;
> -       uint32_t val;
> +       volatile uint32_t val, val2, count, pass;
> +
> +       count = 0;
> +       pass  = 0;
> +       val   = (ast_get_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xb7, 0x10) >> 4) & 0x01;
> +       do {
> +               val2 = (ast_get_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xb7, 0x10) >> 4) & 0x01;
> +               if (val == val2) pass++;
> +               else {
> +                       pass = 0;
> +                       val   = (ast_get_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xb7, 0x10) >> 4) & 0x01;




> +               }
> +       } while ((pass < 5) && (count++ < 0x10000));
>
> -       val = ast_get_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xb7, 0x10) >> 4;
>         return val & 1 ? 1 : 0;
>  }
>
> @@ -982,9 +993,20 @@ static int get_data(void *i2c_priv)
>  {
>         struct ast_i2c_chan *i2c = i2c_priv;
>         struct ast_private *ast = i2c->dev->dev_private;
> -       uint32_t val;
> +       volatile uint32_t val, val2, count, pass;
> +
> +       count = 0;
> +       pass  = 0;
> +       val   = (ast_get_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xb7, 0x20) >> 5) & 0x01;
> +       do {
> +               val2 = (ast_get_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xb7, 0x20) >> 5) & 0x01;
> +               if (val == val2) pass++;
> +               else {
> +                       pass = 0;
> +                       val   = (ast_get_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xb7, 0x20) >> 5) & 0x01;
> +               }
> +       } while ((pass < 5) && (count++ < 0x10000));
>
> -       val = ast_get_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xb7, 0x20) >> 5;
>         return val & 1 ? 1 : 0;
>  }
>
> @@ -997,7 +1019,7 @@ static void set_clock(void *i2c_priv, int clock)
>
>         for (i = 0; i < 0x10000; i++) {
>                 ujcrb7 = ((clock & 0x01) ? 0 : 1);
> -               ast_set_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xb7, 0xfe, ujcrb7);
> +               ast_set_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xb7, 0xf4, ujcrb7);
>                 jtemp = ast_get_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xb7, 0x01);
>                 if (ujcrb7 == jtemp)
>                         break;
> @@ -1013,7 +1035,7 @@ static void set_data(void *i2c_priv, int data)
>
>         for (i = 0; i < 0x10000; i++) {
>                 ujcrb7 = ((data & 0x01) ? 0 : 1) << 2;
> -               ast_set_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xb7, 0xfb, ujcrb7);
> +               ast_set_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xb7, 0xf1, ujcrb7);
>                 jtemp = ast_get_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xb7, 0x04);
>                 if (ujcrb7 == jtemp)
>                         break;
> --
> 1.8.3.1
>
> _______________________________________________
> dri-devel mailing list
> dri-devel@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/dri-devel
陳雅正 Nov. 22, 2018, 1:42 a.m. UTC | #2
Hi Dave,
Thanks for your feedback. No issue found actually if I remove "volatile" on
my platform. In my experience, if the value is volatile, adding "volatile"
will be safer and no harm, that is why I add it by default. If you think it
is not necessary, it's ok for me to remove it.

Regards,

Y.C. Chen

Dave Airlie <airlied@gmail.com> 於 2018年11月22日 週四 上午9:15寫道:

> On Wed, 31 Oct 2018 at 18:12, Y.C. Chen <yacheng600221@gmail.com> wrote:
> >
> > From: "Y.C. Chen" <yc_chen@aspeedtech.com>
> >
> > v1: over-sample data to increase the stability with some specific
> monitors
> > v2: refine to avoid infinite loop
>
> This contains at least 4 whitespace breakages (val  =) in a few
> places, also why the volatiles, I don't think they make much sense
> here, have you verified they are required?
>
> Dave.
>
> >
> > Signed-off-by: Y.C. Chen <yc_chen@aspeedtech.com>
> > ---
> >  drivers/gpu/drm/ast/ast_mode.c | 34 ++++++++++++++++++++++++++++------
> >  1 file changed, 28 insertions(+), 6 deletions(-)
> >
> > diff --git a/drivers/gpu/drm/ast/ast_mode.c
> b/drivers/gpu/drm/ast/ast_mode.c
> > index 5e77d45..092e9a7 100644
> > --- a/drivers/gpu/drm/ast/ast_mode.c
> > +++ b/drivers/gpu/drm/ast/ast_mode.c
> > @@ -972,9 +972,20 @@ static int get_clock(void *i2c_priv)
> >  {
> >         struct ast_i2c_chan *i2c = i2c_priv;
> >         struct ast_private *ast = i2c->dev->dev_private;
> > -       uint32_t val;
> > +       volatile uint32_t val, val2, count, pass;
> > +
> > +       count = 0;
> > +       pass  = 0;
> > +       val   = (ast_get_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xb7,
> 0x10) >> 4) & 0x01;
> > +       do {
> > +               val2 = (ast_get_index_reg_mask(ast, AST_IO_CRTC_PORT,
> 0xb7, 0x10) >> 4) & 0x01;
> > +               if (val == val2) pass++;
> > +               else {
> > +                       pass = 0;
> > +                       val   = (ast_get_index_reg_mask(ast,
> AST_IO_CRTC_PORT, 0xb7, 0x10) >> 4) & 0x01;
>
>
>
>
> > +               }
> > +       } while ((pass < 5) && (count++ < 0x10000));
> >
> > -       val = ast_get_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xb7, 0x10)
> >> 4;
> >         return val & 1 ? 1 : 0;
> >  }
> >
> > @@ -982,9 +993,20 @@ static int get_data(void *i2c_priv)
> >  {
> >         struct ast_i2c_chan *i2c = i2c_priv;
> >         struct ast_private *ast = i2c->dev->dev_private;
> > -       uint32_t val;
> > +       volatile uint32_t val, val2, count, pass;
> > +
> > +       count = 0;
> > +       pass  = 0;
> > +       val   = (ast_get_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xb7,
> 0x20) >> 5) & 0x01;
> > +       do {
> > +               val2 = (ast_get_index_reg_mask(ast, AST_IO_CRTC_PORT,
> 0xb7, 0x20) >> 5) & 0x01;
> > +               if (val == val2) pass++;
> > +               else {
> > +                       pass = 0;
> > +                       val   = (ast_get_index_reg_mask(ast,
> AST_IO_CRTC_PORT, 0xb7, 0x20) >> 5) & 0x01;
> > +               }
> > +       } while ((pass < 5) && (count++ < 0x10000));
> >
> > -       val = ast_get_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xb7, 0x20)
> >> 5;
> >         return val & 1 ? 1 : 0;
> >  }
> >
> > @@ -997,7 +1019,7 @@ static void set_clock(void *i2c_priv, int clock)
> >
> >         for (i = 0; i < 0x10000; i++) {
> >                 ujcrb7 = ((clock & 0x01) ? 0 : 1);
> > -               ast_set_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xb7,
> 0xfe, ujcrb7);
> > +               ast_set_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xb7,
> 0xf4, ujcrb7);
> >                 jtemp = ast_get_index_reg_mask(ast, AST_IO_CRTC_PORT,
> 0xb7, 0x01);
> >                 if (ujcrb7 == jtemp)
> >                         break;
> > @@ -1013,7 +1035,7 @@ static void set_data(void *i2c_priv, int data)
> >
> >         for (i = 0; i < 0x10000; i++) {
> >                 ujcrb7 = ((data & 0x01) ? 0 : 1) << 2;
> > -               ast_set_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xb7,
> 0xfb, ujcrb7);
> > +               ast_set_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xb7,
> 0xf1, ujcrb7);
> >                 jtemp = ast_get_index_reg_mask(ast, AST_IO_CRTC_PORT,
> 0xb7, 0x04);
> >                 if (ujcrb7 == jtemp)
> >                         break;
> > --
> > 1.8.3.1
> >
> > _______________________________________________
> > dri-devel mailing list
> > dri-devel@lists.freedesktop.org
> > https://lists.freedesktop.org/mailman/listinfo/dri-devel
>
<div dir="ltr">Hi Dave,<div>Thanks for your feedback. No issue found actually if I remove &quot;volatile&quot; on my platform. In my experience, if the value is volatile, adding &quot;volatile&quot; will be safer and no harm, that is why I add it by default. If you think it is not necessary, it&#39;s ok for me to remove it.</div><div><br></div><div>Regards,</div><div><br></div><div>Y.C. Chen</div></div><br><div class="gmail_quote"><div dir="ltr">Dave Airlie &lt;<a href="mailto:airlied@gmail.com">airlied@gmail.com</a>&gt; 於 2018年11月22日 週四 上午9:15寫道:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On Wed, 31 Oct 2018 at 18:12, Y.C. Chen &lt;<a href="mailto:yacheng600221@gmail.com" target="_blank">yacheng600221@gmail.com</a>&gt; wrote:<br>
&gt;<br>
&gt; From: &quot;Y.C. Chen&quot; &lt;<a href="mailto:yc_chen@aspeedtech.com" target="_blank">yc_chen@aspeedtech.com</a>&gt;<br>
&gt;<br>
&gt; v1: over-sample data to increase the stability with some specific monitors<br>
&gt; v2: refine to avoid infinite loop<br>
<br>
This contains at least 4 whitespace breakages (val  =) in a few<br>
places, also why the volatiles, I don&#39;t think they make much sense<br>
here, have you verified they are required?<br>
<br>
Dave.<br>
<br>
&gt;<br>
&gt; Signed-off-by: Y.C. Chen &lt;<a href="mailto:yc_chen@aspeedtech.com" target="_blank">yc_chen@aspeedtech.com</a>&gt;<br>
&gt; ---<br>
&gt;  drivers/gpu/drm/ast/ast_mode.c | 34 ++++++++++++++++++++++++++++------<br>
&gt;  1 file changed, 28 insertions(+), 6 deletions(-)<br>
&gt;<br>
&gt; diff --git a/drivers/gpu/drm/ast/ast_mode.c b/drivers/gpu/drm/ast/ast_mode.c<br>
&gt; index 5e77d45..092e9a7 100644<br>
&gt; --- a/drivers/gpu/drm/ast/ast_mode.c<br>
&gt; +++ b/drivers/gpu/drm/ast/ast_mode.c<br>
&gt; @@ -972,9 +972,20 @@ static int get_clock(void *i2c_priv)<br>
&gt;  {<br>
&gt;         struct ast_i2c_chan *i2c = i2c_priv;<br>
&gt;         struct ast_private *ast = i2c-&gt;dev-&gt;dev_private;<br>
&gt; -       uint32_t val;<br>
&gt; +       volatile uint32_t val, val2, count, pass;<br>
&gt; +<br>
&gt; +       count = 0;<br>
&gt; +       pass  = 0;<br>
&gt; +       val   = (ast_get_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xb7, 0x10) &gt;&gt; 4) &amp; 0x01;<br>
&gt; +       do {<br>
&gt; +               val2 = (ast_get_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xb7, 0x10) &gt;&gt; 4) &amp; 0x01;<br>
&gt; +               if (val == val2) pass++;<br>
&gt; +               else {<br>
&gt; +                       pass = 0;<br>
&gt; +                       val   = (ast_get_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xb7, 0x10) &gt;&gt; 4) &amp; 0x01;<br>
<br>
<br>
<br>
<br>
&gt; +               }<br>
&gt; +       } while ((pass &lt; 5) &amp;&amp; (count++ &lt; 0x10000));<br>
&gt;<br>
&gt; -       val = ast_get_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xb7, 0x10) &gt;&gt; 4;<br>
&gt;         return val &amp; 1 ? 1 : 0;<br>
&gt;  }<br>
&gt;<br>
&gt; @@ -982,9 +993,20 @@ static int get_data(void *i2c_priv)<br>
&gt;  {<br>
&gt;         struct ast_i2c_chan *i2c = i2c_priv;<br>
&gt;         struct ast_private *ast = i2c-&gt;dev-&gt;dev_private;<br>
&gt; -       uint32_t val;<br>
&gt; +       volatile uint32_t val, val2, count, pass;<br>
&gt; +<br>
&gt; +       count = 0;<br>
&gt; +       pass  = 0;<br>
&gt; +       val   = (ast_get_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xb7, 0x20) &gt;&gt; 5) &amp; 0x01;<br>
&gt; +       do {<br>
&gt; +               val2 = (ast_get_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xb7, 0x20) &gt;&gt; 5) &amp; 0x01;<br>
&gt; +               if (val == val2) pass++;<br>
&gt; +               else {<br>
&gt; +                       pass = 0;<br>
&gt; +                       val   = (ast_get_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xb7, 0x20) &gt;&gt; 5) &amp; 0x01;<br>
&gt; +               }<br>
&gt; +       } while ((pass &lt; 5) &amp;&amp; (count++ &lt; 0x10000));<br>
&gt;<br>
&gt; -       val = ast_get_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xb7, 0x20) &gt;&gt; 5;<br>
&gt;         return val &amp; 1 ? 1 : 0;<br>
&gt;  }<br>
&gt;<br>
&gt; @@ -997,7 +1019,7 @@ static void set_clock(void *i2c_priv, int clock)<br>
&gt;<br>
&gt;         for (i = 0; i &lt; 0x10000; i++) {<br>
&gt;                 ujcrb7 = ((clock &amp; 0x01) ? 0 : 1);<br>
&gt; -               ast_set_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xb7, 0xfe, ujcrb7);<br>
&gt; +               ast_set_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xb7, 0xf4, ujcrb7);<br>
&gt;                 jtemp = ast_get_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xb7, 0x01);<br>
&gt;                 if (ujcrb7 == jtemp)<br>
&gt;                         break;<br>
&gt; @@ -1013,7 +1035,7 @@ static void set_data(void *i2c_priv, int data)<br>
&gt;<br>
&gt;         for (i = 0; i &lt; 0x10000; i++) {<br>
&gt;                 ujcrb7 = ((data &amp; 0x01) ? 0 : 1) &lt;&lt; 2;<br>
&gt; -               ast_set_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xb7, 0xfb, ujcrb7);<br>
&gt; +               ast_set_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xb7, 0xf1, ujcrb7);<br>
&gt;                 jtemp = ast_get_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xb7, 0x04);<br>
&gt;                 if (ujcrb7 == jtemp)<br>
&gt;                         break;<br>
&gt; --<br>
&gt; 1.8.3.1<br>
&gt;<br>
&gt; _______________________________________________<br>
&gt; dri-devel mailing list<br>
&gt; <a href="mailto:dri-devel@lists.freedesktop.org" target="_blank">dri-devel@lists.freedesktop.org</a><br>
&gt; <a href="https://lists.freedesktop.org/mailman/listinfo/dri-devel" rel="noreferrer" target="_blank">https://lists.freedesktop.org/mailman/listinfo/dri-devel</a><br>
</blockquote></div>
Dave Airlie Nov. 22, 2018, 2:48 a.m. UTC | #3
On Thu, 22 Nov 2018 at 11:42, 陳雅正 <yacheng600221@gmail.com> wrote:
>
> Hi Dave,
> Thanks for your feedback. No issue found actually if I remove "volatile" on my platform. In my experience, if the value is volatile, adding "volatile" will be safer and no harm, that is why I add it by default. If you think it is not necessary, it's ok for me to remove it.
>

Don't add it unless you've got proof you need it, we don't want it
confusing people later.

Dave.
diff mbox series

Patch

diff --git a/drivers/gpu/drm/ast/ast_mode.c b/drivers/gpu/drm/ast/ast_mode.c
index 5e77d45..092e9a7 100644
--- a/drivers/gpu/drm/ast/ast_mode.c
+++ b/drivers/gpu/drm/ast/ast_mode.c
@@ -972,9 +972,20 @@  static int get_clock(void *i2c_priv)
 {
 	struct ast_i2c_chan *i2c = i2c_priv;
 	struct ast_private *ast = i2c->dev->dev_private;
-	uint32_t val;
+	volatile uint32_t val, val2, count, pass;
+
+	count = 0;
+	pass  = 0;
+	val   = (ast_get_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xb7, 0x10) >> 4) & 0x01;
+	do {
+		val2 = (ast_get_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xb7, 0x10) >> 4) & 0x01;
+		if (val == val2) pass++;
+		else {
+			pass = 0;
+			val   = (ast_get_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xb7, 0x10) >> 4) & 0x01;
+		}
+	} while ((pass < 5) && (count++ < 0x10000));
 
-	val = ast_get_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xb7, 0x10) >> 4;
 	return val & 1 ? 1 : 0;
 }
 
@@ -982,9 +993,20 @@  static int get_data(void *i2c_priv)
 {
 	struct ast_i2c_chan *i2c = i2c_priv;
 	struct ast_private *ast = i2c->dev->dev_private;
-	uint32_t val;
+	volatile uint32_t val, val2, count, pass;
+
+	count = 0;
+	pass  = 0;
+	val   = (ast_get_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xb7, 0x20) >> 5) & 0x01;
+	do {
+		val2 = (ast_get_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xb7, 0x20) >> 5) & 0x01;
+		if (val == val2) pass++;
+		else {
+			pass = 0;
+			val   = (ast_get_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xb7, 0x20) >> 5) & 0x01;
+		}
+	} while ((pass < 5) && (count++ < 0x10000));
 
-	val = ast_get_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xb7, 0x20) >> 5;
 	return val & 1 ? 1 : 0;
 }
 
@@ -997,7 +1019,7 @@  static void set_clock(void *i2c_priv, int clock)
 
 	for (i = 0; i < 0x10000; i++) {
 		ujcrb7 = ((clock & 0x01) ? 0 : 1);
-		ast_set_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xb7, 0xfe, ujcrb7);
+		ast_set_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xb7, 0xf4, ujcrb7);
 		jtemp = ast_get_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xb7, 0x01);
 		if (ujcrb7 == jtemp)
 			break;
@@ -1013,7 +1035,7 @@  static void set_data(void *i2c_priv, int data)
 
 	for (i = 0; i < 0x10000; i++) {
 		ujcrb7 = ((data & 0x01) ? 0 : 1) << 2;
-		ast_set_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xb7, 0xfb, ujcrb7);
+		ast_set_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xb7, 0xf1, ujcrb7);
 		jtemp = ast_get_index_reg_mask(ast, AST_IO_CRTC_PORT, 0xb7, 0x04);
 		if (ujcrb7 == jtemp)
 			break;