diff mbox series

[06/15] drm/dp: Read AUX read interval from DPCD

Message ID 20191015143509.1104985-7-thierry.reding@gmail.com (mailing list archive)
State New, archived
Headers show
Series drm/dp: Move drm_dp_link helpers to Tegra DRM | expand

Commit Message

Thierry Reding Oct. 15, 2019, 2:35 p.m. UTC
From: Thierry Reding <treding@nvidia.com>

Store the AUX read interval from DPCD, so that it can be used to wait
for the durations given in the specification during link training.

Signed-off-by: Thierry Reding <treding@nvidia.com>
---
 include/drm/drm_dp_helper.h | 33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)

Comments

Lyude Paul Oct. 18, 2019, 9:27 p.m. UTC | #1
On Tue, 2019-10-15 at 16:35 +0200, Thierry Reding wrote:
> From: Thierry Reding <treding@nvidia.com>
> 
> Store the AUX read interval from DPCD, so that it can be used to wait
> for the durations given in the specification during link training.
> 
> Signed-off-by: Thierry Reding <treding@nvidia.com>
> ---
>  include/drm/drm_dp_helper.h | 33 +++++++++++++++++++++++++++++++++
>  1 file changed, 33 insertions(+)
> 
> diff --git a/include/drm/drm_dp_helper.h b/include/drm/drm_dp_helper.h
> index 7a537ffc2fb1..6c12de6f7e46 100644
> --- a/include/drm/drm_dp_helper.h
> +++ b/include/drm/drm_dp_helper.h
> @@ -25,8 +25,11 @@
>  
>  #include <linux/delay.h>
>  #include <linux/i2c.h>
> +#include <linux/time64.h>
>  #include <linux/types.h>
>  
> +#include <drm/drm_print.h>
> +
>  /*
>   * Unless otherwise noted, all values are from the DP 1.1a spec.  Note that
>   * DP and DPCD versions are independent.  Differences from 1.0 are not
> noted,
> @@ -1297,6 +1300,36 @@ drm_dp_alternate_scrambler_reset_cap(const u8
> dpcd[DP_RECEIVER_CAP_SIZE])
>  			DP_ALTERNATE_SCRAMBLER_RESET_CAP;
>  }
>  
> +/**
> + * drm_dp_read_aux_interval() - read the AUX read interval from the DPCD
> + * @dpcd: receiver capacity buffer
> + *
> + * Reads the AUX read interval (in microseconds) from the DPCD. Note that
> the
> + * TRAINING_AUX_RD_INTERVAL stores the value in units of 4 milliseconds. If
> no
> + * read interval is specified and for DPCD v1.4 and later, the read
> interval
> + * is always 100 microseconds.
> + *
> + * Returns:
> + * The read AUX interval in microseconds.
> + */
> +static inline unsigned int
> +drm_dp_aux_rd_interval(const u8 dpcd[DP_RECEIVER_CAP_SIZE])
> +{
> +	unsigned int rd_interval = dpcd[DP_TRAINING_AUX_RD_INTERVAL] &
> +					DP_TRAINING_AUX_RD_MASK;
> +
> +	if (rd_interval > 4)
> +		DRM_DEBUG_KMS("AUX interval %u, out of range (max: 4)\n",
> +			      rd_interval);
Do you think it might be worth clamping the value to 4 here?

> +
> +	if (rd_interval > 0 && dpcd[DP_DPCD_REV] < DP_DPCD_REV_14)

Also small  nit pick: you can just use rd_interval instead of rd_interval > 0
> +		rd_interval *= 4 * USEC_PER_MSEC;
> +	else
> +		rd_interval = 100;
> +
> +	return rd_interval;
> +}
> +
>  /*
>   * DisplayPort AUX channel
>   */
Thierry Reding Oct. 21, 2019, 7:55 a.m. UTC | #2
On Fri, Oct 18, 2019 at 05:27:59PM -0400, Lyude Paul wrote:
> On Tue, 2019-10-15 at 16:35 +0200, Thierry Reding wrote:
> > From: Thierry Reding <treding@nvidia.com>
> > 
> > Store the AUX read interval from DPCD, so that it can be used to wait
> > for the durations given in the specification during link training.
> > 
> > Signed-off-by: Thierry Reding <treding@nvidia.com>
> > ---
> >  include/drm/drm_dp_helper.h | 33 +++++++++++++++++++++++++++++++++
> >  1 file changed, 33 insertions(+)
> > 
> > diff --git a/include/drm/drm_dp_helper.h b/include/drm/drm_dp_helper.h
> > index 7a537ffc2fb1..6c12de6f7e46 100644
> > --- a/include/drm/drm_dp_helper.h
> > +++ b/include/drm/drm_dp_helper.h
> > @@ -25,8 +25,11 @@
> >  
> >  #include <linux/delay.h>
> >  #include <linux/i2c.h>
> > +#include <linux/time64.h>
> >  #include <linux/types.h>
> >  
> > +#include <drm/drm_print.h>
> > +
> >  /*
> >   * Unless otherwise noted, all values are from the DP 1.1a spec.  Note that
> >   * DP and DPCD versions are independent.  Differences from 1.0 are not
> > noted,
> > @@ -1297,6 +1300,36 @@ drm_dp_alternate_scrambler_reset_cap(const u8
> > dpcd[DP_RECEIVER_CAP_SIZE])
> >  			DP_ALTERNATE_SCRAMBLER_RESET_CAP;
> >  }
> >  
> > +/**
> > + * drm_dp_read_aux_interval() - read the AUX read interval from the DPCD
> > + * @dpcd: receiver capacity buffer
> > + *
> > + * Reads the AUX read interval (in microseconds) from the DPCD. Note that
> > the
> > + * TRAINING_AUX_RD_INTERVAL stores the value in units of 4 milliseconds. If
> > no
> > + * read interval is specified and for DPCD v1.4 and later, the read
> > interval
> > + * is always 100 microseconds.
> > + *
> > + * Returns:
> > + * The read AUX interval in microseconds.
> > + */
> > +static inline unsigned int
> > +drm_dp_aux_rd_interval(const u8 dpcd[DP_RECEIVER_CAP_SIZE])
> > +{
> > +	unsigned int rd_interval = dpcd[DP_TRAINING_AUX_RD_INTERVAL] &
> > +					DP_TRAINING_AUX_RD_MASK;
> > +
> > +	if (rd_interval > 4)
> > +		DRM_DEBUG_KMS("AUX interval %u, out of range (max: 4)\n",
> > +			      rd_interval);
> Do you think it might be worth clamping the value to 4 here?

Yeah, I think that makes sense. It might also be worth increasing the
log level for this, perhaps even make it a WARN to make sure we catch
it when this happens.

> > +
> > +	if (rd_interval > 0 && dpcd[DP_DPCD_REV] < DP_DPCD_REV_14)
> 
> Also small  nit pick: you can just use rd_interval instead of rd_interval > 0

Yeah, I suppose so. I thought > 0 was making it really explicit, but I
don't really mind either way.

Thierry

> > +		rd_interval *= 4 * USEC_PER_MSEC;
> > +	else
> > +		rd_interval = 100;
> > +
> > +	return rd_interval;
> > +}
> > +
> >  /*
> >   * DisplayPort AUX channel
> >   */
> -- 
> Cheers,
> 	Lyude Paul
>
diff mbox series

Patch

diff --git a/include/drm/drm_dp_helper.h b/include/drm/drm_dp_helper.h
index 7a537ffc2fb1..6c12de6f7e46 100644
--- a/include/drm/drm_dp_helper.h
+++ b/include/drm/drm_dp_helper.h
@@ -25,8 +25,11 @@ 
 
 #include <linux/delay.h>
 #include <linux/i2c.h>
+#include <linux/time64.h>
 #include <linux/types.h>
 
+#include <drm/drm_print.h>
+
 /*
  * Unless otherwise noted, all values are from the DP 1.1a spec.  Note that
  * DP and DPCD versions are independent.  Differences from 1.0 are not noted,
@@ -1297,6 +1300,36 @@  drm_dp_alternate_scrambler_reset_cap(const u8 dpcd[DP_RECEIVER_CAP_SIZE])
 			DP_ALTERNATE_SCRAMBLER_RESET_CAP;
 }
 
+/**
+ * drm_dp_read_aux_interval() - read the AUX read interval from the DPCD
+ * @dpcd: receiver capacity buffer
+ *
+ * Reads the AUX read interval (in microseconds) from the DPCD. Note that the
+ * TRAINING_AUX_RD_INTERVAL stores the value in units of 4 milliseconds. If no
+ * read interval is specified and for DPCD v1.4 and later, the read interval
+ * is always 100 microseconds.
+ *
+ * Returns:
+ * The read AUX interval in microseconds.
+ */
+static inline unsigned int
+drm_dp_aux_rd_interval(const u8 dpcd[DP_RECEIVER_CAP_SIZE])
+{
+	unsigned int rd_interval = dpcd[DP_TRAINING_AUX_RD_INTERVAL] &
+					DP_TRAINING_AUX_RD_MASK;
+
+	if (rd_interval > 4)
+		DRM_DEBUG_KMS("AUX interval %u, out of range (max: 4)\n",
+			      rd_interval);
+
+	if (rd_interval > 0 && dpcd[DP_DPCD_REV] < DP_DPCD_REV_14)
+		rd_interval *= 4 * USEC_PER_MSEC;
+	else
+		rd_interval = 100;
+
+	return rd_interval;
+}
+
 /*
  * DisplayPort AUX channel
  */