Skip to content

Commit

Permalink
drm/bridge: tc358767: Simplify AUX data read
Browse files Browse the repository at this point in the history
Simplify AUX data read by removing index arithmetic and shifting with
a helper function that does two things:

    1. Fetch data from up to 4 32-bit registers from the chip
    2. Copy read data into user provided array.

Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
Reviewed-by: Andrzej Hajda <a.hajda@samsung.com>
Reviewed-by: Tomi Valkeinen <tomi.valkeinen@ti.com>
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
Signed-off-by: Andrzej Hajda <a.hajda@samsung.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20190619052716.16831-7-andrew.smirnov@gmail.com
  • Loading branch information
Andrey Smirnov authored and Andrzej Hajda committed Jun 27, 2019
1 parent 6d0c383 commit 53b166d
Showing 1 changed file with 18 additions and 13 deletions.
31 changes: 18 additions & 13 deletions drivers/gpu/drm/bridge/tc358767.c
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,20 @@ 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, count = ALIGN(size, sizeof(u32));

ret = regmap_raw_read(tc->regmap, DP0_AUXRDATA(0), auxrdata, count);
if (ret)
return ret;

memcpy(data, auxrdata, size);

return size;
}

static ssize_t tc_aux_transfer(struct drm_dp_aux *aux,
struct drm_dp_aux_msg *msg)
{
Expand Down Expand Up @@ -370,19 +384,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;
Expand Down

0 comments on commit 53b166d

Please sign in to comment.