[v3,06/15] drm/bridge: tc358767: Simplify AUX data read
diff mbox series

Message ID 20190605070507.11417-7-andrew.smirnov@gmail.com
State New
Headers show
Series
  • tc358767 driver improvements
Related show

Commit Message

Andrey Smirnov June 5, 2019, 7:04 a.m. UTC
Simplify AUX data read by removing index arithmetic and shifting with
a helper functions that does three things:

    1. Fetch data from up to 4 32-bit registers from the chip
    2. Optionally fix data endianness (not needed on LE hosts)
    3. Copy read data into user provided array.

Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
Cc: Archit Taneja <architt@codeaurora.org>
Cc: Andrzej Hajda <a.hajda@samsung.com>
Cc: Laurent Pinchart <Laurent.pinchart@ideasonboard.com>
Cc: Tomi Valkeinen <tomi.valkeinen@ti.com>
Cc: Andrey Gusakov <andrey.gusakov@cogentembedded.com>
Cc: Philipp Zabel <p.zabel@pengutronix.de>
Cc: Cory Tusar <cory.tusar@zii.aero>
Cc: Chris Healy <cphealy@gmail.com>
Cc: Lucas Stach <l.stach@pengutronix.de>
Cc: dri-devel@lists.freedesktop.org
Cc: linux-kernel@vger.kernel.org
---
 drivers/gpu/drm/bridge/tc358767.c | 40 +++++++++++++++++++++----------
 1 file changed, 27 insertions(+), 13 deletions(-)

Comments

Andrzej Hajda June 6, 2019, 10:59 a.m. UTC | #1
On 05.06.2019 09:04, Andrey Smirnov wrote:
> Simplify AUX data read by removing index arithmetic and shifting with
> a helper functions that does three things:
>
>     1. Fetch data from up to 4 32-bit registers from the chip
>     2. Optionally fix data endianness (not needed on LE hosts)
>     3. Copy read data into user provided array.
>
> Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
> Cc: Archit Taneja <architt@codeaurora.org>
> Cc: Andrzej Hajda <a.hajda@samsung.com>
> Cc: Laurent Pinchart <Laurent.pinchart@ideasonboard.com>
> Cc: Tomi Valkeinen <tomi.valkeinen@ti.com>
> Cc: Andrey Gusakov <andrey.gusakov@cogentembedded.com>
> Cc: Philipp Zabel <p.zabel@pengutronix.de>
> Cc: Cory Tusar <cory.tusar@zii.aero>
> Cc: Chris Healy <cphealy@gmail.com>
> Cc: Lucas Stach <l.stach@pengutronix.de>
> Cc: dri-devel@lists.freedesktop.org
> Cc: linux-kernel@vger.kernel.org
> ---
>  drivers/gpu/drm/bridge/tc358767.c | 40 +++++++++++++++++++++----------
>  1 file changed, 27 insertions(+), 13 deletions(-)
>
> diff --git a/drivers/gpu/drm/bridge/tc358767.c b/drivers/gpu/drm/bridge/tc358767.c
> index e197ce0fb166..da47d81e7109 100644
> --- a/drivers/gpu/drm/bridge/tc358767.c
> +++ b/drivers/gpu/drm/bridge/tc358767.c
> @@ -321,6 +321,29 @@ static int tc_aux_get_status(struct tc_data *tc, u8 *reply)
>  	return 0;
>  }
>  
> +static int tc_aux_read_data(struct tc_data *tc, void *data, size_t size)
> +{
> +	u32 auxrdata[DP_AUX_MAX_PAYLOAD_BYTES / sizeof(u32)];
> +	int ret, i, count = DIV_ROUND_UP(size, sizeof(u32));
> +
> +	ret = regmap_bulk_read(tc->regmap, DP0_AUXRDATA(0), auxrdata, count);
> +	if (ret)
> +		return ret;
> +
> +	for (i = 0; i < count; i++) {
> +		/*
> +		 * Our regmap is configured as LE for register data,
> +		 * so we need undo any byte swapping that might have
> +		 * happened to preserve original byte order.
> +		 */
> +		le32_to_cpus(&auxrdata[i]);
> +	}
> +
> +	memcpy(data, auxrdata, size);
> +
> +	return size;
> +}
> +


Hmm, cannot we just use regmap_raw_read?

Beside this:

Reviewed-by: Andrzej Hajda <a.hajda@samsung.com>

 --
Regards
Andrzej



>  static ssize_t tc_aux_transfer(struct drm_dp_aux *aux,
>  			       struct drm_dp_aux_msg *msg)
>  {
> @@ -379,19 +402,10 @@ static ssize_t tc_aux_transfer(struct drm_dp_aux *aux,
>  	if (ret)
>  		return ret;
>  
> -	if (request == DP_AUX_I2C_READ || request == DP_AUX_NATIVE_READ) {
> -		/* Read data */
> -		while (i < size) {
> -			if ((i % 4) == 0) {
> -				ret = regmap_read(tc->regmap,
> -						  DP0_AUXRDATA(i >> 2), &tmp);
> -				if (ret)
> -					return ret;
> -			}
> -			buf[i] = tmp & 0xff;
> -			tmp = tmp >> 8;
> -			i++;
> -		}
> +	switch (request) {
> +	case DP_AUX_NATIVE_READ:
> +	case DP_AUX_I2C_READ:
> +		return tc_aux_read_data(tc, msg->buffer, size);
>  	}
>  
>  	return size;
Andrey Smirnov June 6, 2019, 7:53 p.m. UTC | #2
On Thu, Jun 6, 2019 at 3:59 AM Andrzej Hajda <a.hajda@samsung.com> wrote:
>
> On 05.06.2019 09:04, Andrey Smirnov wrote:
> > Simplify AUX data read by removing index arithmetic and shifting with
> > a helper functions that does three things:
> >
> >     1. Fetch data from up to 4 32-bit registers from the chip
> >     2. Optionally fix data endianness (not needed on LE hosts)
> >     3. Copy read data into user provided array.
> >
> > Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
> > Cc: Archit Taneja <architt@codeaurora.org>
> > Cc: Andrzej Hajda <a.hajda@samsung.com>
> > Cc: Laurent Pinchart <Laurent.pinchart@ideasonboard.com>
> > Cc: Tomi Valkeinen <tomi.valkeinen@ti.com>
> > Cc: Andrey Gusakov <andrey.gusakov@cogentembedded.com>
> > Cc: Philipp Zabel <p.zabel@pengutronix.de>
> > Cc: Cory Tusar <cory.tusar@zii.aero>
> > Cc: Chris Healy <cphealy@gmail.com>
> > Cc: Lucas Stach <l.stach@pengutronix.de>
> > Cc: dri-devel@lists.freedesktop.org
> > Cc: linux-kernel@vger.kernel.org
> > ---
> >  drivers/gpu/drm/bridge/tc358767.c | 40 +++++++++++++++++++++----------
> >  1 file changed, 27 insertions(+), 13 deletions(-)
> >
> > diff --git a/drivers/gpu/drm/bridge/tc358767.c b/drivers/gpu/drm/bridge/tc358767.c
> > index e197ce0fb166..da47d81e7109 100644
> > --- a/drivers/gpu/drm/bridge/tc358767.c
> > +++ b/drivers/gpu/drm/bridge/tc358767.c
> > @@ -321,6 +321,29 @@ static int tc_aux_get_status(struct tc_data *tc, u8 *reply)
> >       return 0;
> >  }
> >
> > +static int tc_aux_read_data(struct tc_data *tc, void *data, size_t size)
> > +{
> > +     u32 auxrdata[DP_AUX_MAX_PAYLOAD_BYTES / sizeof(u32)];
> > +     int ret, i, count = DIV_ROUND_UP(size, sizeof(u32));
> > +
> > +     ret = regmap_bulk_read(tc->regmap, DP0_AUXRDATA(0), auxrdata, count);
> > +     if (ret)
> > +             return ret;
> > +
> > +     for (i = 0; i < count; i++) {
> > +             /*
> > +              * Our regmap is configured as LE for register data,
> > +              * so we need undo any byte swapping that might have
> > +              * happened to preserve original byte order.
> > +              */
> > +             le32_to_cpus(&auxrdata[i]);
> > +     }
> > +
> > +     memcpy(data, auxrdata, size);
> > +
> > +     return size;
> > +}
> > +
>
>
> Hmm, cannot we just use regmap_raw_read?

I'll give it a try in v4.

Thanks,
Andrey Smirnov

Patch
diff mbox series

diff --git a/drivers/gpu/drm/bridge/tc358767.c b/drivers/gpu/drm/bridge/tc358767.c
index e197ce0fb166..da47d81e7109 100644
--- a/drivers/gpu/drm/bridge/tc358767.c
+++ b/drivers/gpu/drm/bridge/tc358767.c
@@ -321,6 +321,29 @@  static int tc_aux_get_status(struct tc_data *tc, u8 *reply)
 	return 0;
 }
 
+static int tc_aux_read_data(struct tc_data *tc, void *data, size_t size)
+{
+	u32 auxrdata[DP_AUX_MAX_PAYLOAD_BYTES / sizeof(u32)];
+	int ret, i, count = DIV_ROUND_UP(size, sizeof(u32));
+
+	ret = regmap_bulk_read(tc->regmap, DP0_AUXRDATA(0), auxrdata, count);
+	if (ret)
+		return ret;
+
+	for (i = 0; i < count; i++) {
+		/*
+		 * Our regmap is configured as LE for register data,
+		 * so we need undo any byte swapping that might have
+		 * happened to preserve original byte order.
+		 */
+		le32_to_cpus(&auxrdata[i]);
+	}
+
+	memcpy(data, auxrdata, size);
+
+	return size;
+}
+
 static ssize_t tc_aux_transfer(struct drm_dp_aux *aux,
 			       struct drm_dp_aux_msg *msg)
 {
@@ -379,19 +402,10 @@  static ssize_t tc_aux_transfer(struct drm_dp_aux *aux,
 	if (ret)
 		return ret;
 
-	if (request == DP_AUX_I2C_READ || request == DP_AUX_NATIVE_READ) {
-		/* Read data */
-		while (i < size) {
-			if ((i % 4) == 0) {
-				ret = regmap_read(tc->regmap,
-						  DP0_AUXRDATA(i >> 2), &tmp);
-				if (ret)
-					return ret;
-			}
-			buf[i] = tmp & 0xff;
-			tmp = tmp >> 8;
-			i++;
-		}
+	switch (request) {
+	case DP_AUX_NATIVE_READ:
+	case DP_AUX_I2C_READ:
+		return tc_aux_read_data(tc, msg->buffer, size);
 	}
 
 	return size;