diff mbox series

[v3,1/2] drm/bridge: megachips-stdpxxxx-ge-b850v3-fw: switch to drm_do_get_edid()

Message ID 20230921104751.56544-1-ian.ray@ge.com (mailing list archive)
State New, archived
Headers show
Series [v3,1/2] drm/bridge: megachips-stdpxxxx-ge-b850v3-fw: switch to drm_do_get_edid() | expand

Commit Message

Ian Ray Sept. 21, 2023, 10:47 a.m. UTC
Migrate away from custom EDID parsing and validity checks.

Note:  This is a follow-up to the original RFC by Jani [1].  The first
submission in this series should have been marked v2.

[1] https://patchwork.freedesktop.org/patch/msgid/20230901102400.552254-1-jani.nikula@intel.com

Co-developed-by: Jani Nikula <jani.nikula@intel.com>
Signed-off-by: Jani Nikula <jani.nikula@intel.com>
Signed-off-by: Ian Ray <ian.ray@ge.com>
---
 .../drm/bridge/megachips-stdpxxxx-ge-b850v3-fw.c   | 57 ++++------------------
 1 file changed, 9 insertions(+), 48 deletions(-)

Comments

Robert Foss Oct. 13, 2023, 2:27 p.m. UTC | #1
On Thu, Sep 21, 2023 at 12:48 PM Ian Ray <ian.ray@ge.com> wrote:
>
> Migrate away from custom EDID parsing and validity checks.
>
> Note:  This is a follow-up to the original RFC by Jani [1].  The first
> submission in this series should have been marked v2.
>
> [1] https://patchwork.freedesktop.org/patch/msgid/20230901102400.552254-1-jani.nikula@intel.com
>
> Co-developed-by: Jani Nikula <jani.nikula@intel.com>
> Signed-off-by: Jani Nikula <jani.nikula@intel.com>
> Signed-off-by: Ian Ray <ian.ray@ge.com>
> ---
>  .../drm/bridge/megachips-stdpxxxx-ge-b850v3-fw.c   | 57 ++++------------------
>  1 file changed, 9 insertions(+), 48 deletions(-)
>
> diff --git a/drivers/gpu/drm/bridge/megachips-stdpxxxx-ge-b850v3-fw.c b/drivers/gpu/drm/bridge/megachips-stdpxxxx-ge-b850v3-fw.c
> index 460db3c..e93083b 100644
> --- a/drivers/gpu/drm/bridge/megachips-stdpxxxx-ge-b850v3-fw.c
> +++ b/drivers/gpu/drm/bridge/megachips-stdpxxxx-ge-b850v3-fw.c
> @@ -65,12 +65,11 @@ struct ge_b850v3_lvds {
>
>  static struct ge_b850v3_lvds *ge_b850v3_lvds_ptr;
>
> -static u8 *stdp2690_get_edid(struct i2c_client *client)
> +static int stdp2690_read_block(void *context, u8 *buf, unsigned int block, size_t len)
>  {
> +       struct i2c_client *client = context;
>         struct i2c_adapter *adapter = client->adapter;
> -       unsigned char start = 0x00;
> -       unsigned int total_size;
> -       u8 *block = kmalloc(EDID_LENGTH, GFP_KERNEL);
> +       unsigned char start = block * EDID_LENGTH;
>
>         struct i2c_msg msgs[] = {
>                 {
> @@ -81,53 +80,15 @@ static u8 *stdp2690_get_edid(struct i2c_client *client)
>                 }, {
>                         .addr   = client->addr,
>                         .flags  = I2C_M_RD,
> -                       .len    = EDID_LENGTH,
> -                       .buf    = block,
> +                       .len    = len,
> +                       .buf    = buf,
>                 }
>         };
>
> -       if (!block)
> -               return NULL;
> +       if (i2c_transfer(adapter, msgs, 2) != 2)
> +               return -1;
>
> -       if (i2c_transfer(adapter, msgs, 2) != 2) {
> -               DRM_ERROR("Unable to read EDID.\n");
> -               goto err;
> -       }
> -
> -       if (!drm_edid_block_valid(block, 0, false, NULL)) {
> -               DRM_ERROR("Invalid EDID data\n");
> -               goto err;
> -       }
> -
> -       total_size = (block[EDID_EXT_BLOCK_CNT] + 1) * EDID_LENGTH;
> -       if (total_size > EDID_LENGTH) {
> -               kfree(block);
> -               block = kmalloc(total_size, GFP_KERNEL);
> -               if (!block)
> -                       return NULL;
> -
> -               /* Yes, read the entire buffer, and do not skip the first
> -                * EDID_LENGTH bytes.
> -                */
> -               start = 0x00;
> -               msgs[1].len = total_size;
> -               msgs[1].buf = block;
> -
> -               if (i2c_transfer(adapter, msgs, 2) != 2) {
> -                       DRM_ERROR("Unable to read EDID extension blocks.\n");
> -                       goto err;
> -               }
> -               if (!drm_edid_block_valid(block, 1, false, NULL)) {
> -                       DRM_ERROR("Invalid EDID data\n");
> -                       goto err;
> -               }
> -       }
> -
> -       return block;
> -
> -err:
> -       kfree(block);
> -       return NULL;
> +       return 0;
>  }
>
>  static struct edid *ge_b850v3_lvds_get_edid(struct drm_bridge *bridge,
> @@ -137,7 +98,7 @@ static struct edid *ge_b850v3_lvds_get_edid(struct drm_bridge *bridge,
>
>         client = ge_b850v3_lvds_ptr->stdp2690_i2c;
>
> -       return (struct edid *)stdp2690_get_edid(client);
> +       return drm_do_get_edid(connector, stdp2690_read_block, client);
>  }
>
>  static int ge_b850v3_lvds_get_modes(struct drm_connector *connector)

Reviewed-by: Robert Foss <rfoss@kernel.org>
Robert Foss Oct. 13, 2023, 2:33 p.m. UTC | #2
On Thu, 21 Sep 2023 13:47:50 +0300, Ian Ray wrote:
> Migrate away from custom EDID parsing and validity checks.
> 
> Note:  This is a follow-up to the original RFC by Jani [1].  The first
> submission in this series should have been marked v2.
> 
> [1] https://patchwork.freedesktop.org/patch/msgid/20230901102400.552254-1-jani.nikula@intel.com
> 
> [...]

Applied, thanks!

[1/2] drm/bridge: megachips-stdpxxxx-ge-b850v3-fw: switch to drm_do_get_edid()
      https://cgit.freedesktop.org/drm/drm-misc/commit/?id=e0eb7db49764
[2/2] MAINTAINERS: Update entry for megachips-stdpxxxx-ge-b850v3-fw
      https://cgit.freedesktop.org/drm/drm-misc/commit/?id=e755d439c1b7



Rob
diff mbox series

Patch

diff --git a/drivers/gpu/drm/bridge/megachips-stdpxxxx-ge-b850v3-fw.c b/drivers/gpu/drm/bridge/megachips-stdpxxxx-ge-b850v3-fw.c
index 460db3c..e93083b 100644
--- a/drivers/gpu/drm/bridge/megachips-stdpxxxx-ge-b850v3-fw.c
+++ b/drivers/gpu/drm/bridge/megachips-stdpxxxx-ge-b850v3-fw.c
@@ -65,12 +65,11 @@  struct ge_b850v3_lvds {
 
 static struct ge_b850v3_lvds *ge_b850v3_lvds_ptr;
 
-static u8 *stdp2690_get_edid(struct i2c_client *client)
+static int stdp2690_read_block(void *context, u8 *buf, unsigned int block, size_t len)
 {
+	struct i2c_client *client = context;
 	struct i2c_adapter *adapter = client->adapter;
-	unsigned char start = 0x00;
-	unsigned int total_size;
-	u8 *block = kmalloc(EDID_LENGTH, GFP_KERNEL);
+	unsigned char start = block * EDID_LENGTH;
 
 	struct i2c_msg msgs[] = {
 		{
@@ -81,53 +80,15 @@  static u8 *stdp2690_get_edid(struct i2c_client *client)
 		}, {
 			.addr	= client->addr,
 			.flags	= I2C_M_RD,
-			.len	= EDID_LENGTH,
-			.buf	= block,
+			.len	= len,
+			.buf	= buf,
 		}
 	};
 
-	if (!block)
-		return NULL;
+	if (i2c_transfer(adapter, msgs, 2) != 2)
+		return -1;
 
-	if (i2c_transfer(adapter, msgs, 2) != 2) {
-		DRM_ERROR("Unable to read EDID.\n");
-		goto err;
-	}
-
-	if (!drm_edid_block_valid(block, 0, false, NULL)) {
-		DRM_ERROR("Invalid EDID data\n");
-		goto err;
-	}
-
-	total_size = (block[EDID_EXT_BLOCK_CNT] + 1) * EDID_LENGTH;
-	if (total_size > EDID_LENGTH) {
-		kfree(block);
-		block = kmalloc(total_size, GFP_KERNEL);
-		if (!block)
-			return NULL;
-
-		/* Yes, read the entire buffer, and do not skip the first
-		 * EDID_LENGTH bytes.
-		 */
-		start = 0x00;
-		msgs[1].len = total_size;
-		msgs[1].buf = block;
-
-		if (i2c_transfer(adapter, msgs, 2) != 2) {
-			DRM_ERROR("Unable to read EDID extension blocks.\n");
-			goto err;
-		}
-		if (!drm_edid_block_valid(block, 1, false, NULL)) {
-			DRM_ERROR("Invalid EDID data\n");
-			goto err;
-		}
-	}
-
-	return block;
-
-err:
-	kfree(block);
-	return NULL;
+	return 0;
 }
 
 static struct edid *ge_b850v3_lvds_get_edid(struct drm_bridge *bridge,
@@ -137,7 +98,7 @@  static struct edid *ge_b850v3_lvds_get_edid(struct drm_bridge *bridge,
 
 	client = ge_b850v3_lvds_ptr->stdp2690_i2c;
 
-	return (struct edid *)stdp2690_get_edid(client);
+	return drm_do_get_edid(connector, stdp2690_read_block, client);
 }
 
 static int ge_b850v3_lvds_get_modes(struct drm_connector *connector)