drm_edid: Add a function to get EDID base block
authorHsin-Yi Wang <hsinyi@chromium.org>
Thu, 7 Mar 2024 22:57:41 +0000 (14:57 -0800)
committerDouglas Anderson <dianders@chromium.org>
Thu, 14 Mar 2024 15:20:26 +0000 (08:20 -0700)
It's found that some panels have variants that they share the same panel id
although their EDID and names are different. Besides panel id, now we need
more information from the EDID base block to distinguish these panel
variants.

Add drm_edid_read_base_block() to return the EDID base block, which is
wrapped in struct drm_edid.

Caller can further use it to get panel id or check if the block contains
certain strings, such as panel name.

Merge drm_edid_get_panel_id() and edid_extract_panel_id() into one
function.

Signed-off-by: Hsin-Yi Wang <hsinyi@chromium.org>
Reviewed-by: Douglas Anderson <dianders@chromium.org>
Reviewed-by: Jani Nikula <jani.nikula@intel.com>
Signed-off-by: Douglas Anderson <dianders@chromium.org>
Link: https://patchwork.freedesktop.org/patch/msgid/20240307230653.1807557-2-hsinyi@chromium.org
drivers/gpu/drm/drm_edid.c
drivers/gpu/drm/panel/panel-edp.c
include/drm/drm_edid.h

index 923c4423151c1eb2c8ce635940898fc01db63825..ecd6e9255b6710997bd5a39dff757ad783185681 100644 (file)
@@ -2749,8 +2749,27 @@ const struct drm_edid *drm_edid_read(struct drm_connector *connector)
 }
 EXPORT_SYMBOL(drm_edid_read);
 
-static u32 edid_extract_panel_id(const struct edid *edid)
+/**
+ * drm_edid_get_panel_id - Get a panel's ID from EDID
+ * @drm_edid: EDID that contains panel ID.
+ *
+ * This function uses the first block of the EDID of a panel and (assuming
+ * that the EDID is valid) extracts the ID out of it. The ID is a 32-bit value
+ * (16 bits of manufacturer ID and 16 bits of per-manufacturer ID) that's
+ * supposed to be different for each different modem of panel.
+ *
+ * Return: A 32-bit ID that should be different for each make/model of panel.
+ *         See the functions drm_edid_encode_panel_id() and
+ *         drm_edid_decode_panel_id() for some details on the structure of this
+ *         ID. Return 0 if the EDID size is less than a base block.
+ */
+u32 drm_edid_get_panel_id(const struct drm_edid *drm_edid)
 {
+       const struct edid *edid = drm_edid->edid;
+
+       if (drm_edid->size < EDID_LENGTH)
+               return 0;
+
        /*
         * We represent the ID as a 32-bit number so it can easily be compared
         * with "==".
@@ -2768,60 +2787,54 @@ static u32 edid_extract_panel_id(const struct edid *edid)
               (u32)edid->mfg_id[1] << 16   |
               (u32)EDID_PRODUCT_ID(edid);
 }
+EXPORT_SYMBOL(drm_edid_get_panel_id);
 
 /**
- * drm_edid_get_panel_id - Get a panel's ID through DDC
+ * drm_edid_read_base_block - Get a panel's EDID base block
  * @adapter: I2C adapter to use for DDC
  *
- * This function reads the first block of the EDID of a panel and (assuming
- * that the EDID is valid) extracts the ID out of it. The ID is a 32-bit value
- * (16 bits of manufacturer ID and 16 bits of per-manufacturer ID) that's
- * supposed to be different for each different modem of panel.
+ * This function returns the drm_edid containing the first block of the EDID of
+ * a panel.
  *
  * This function is intended to be used during early probing on devices where
  * more than one panel might be present. Because of its intended use it must
- * assume that the EDID of the panel is correct, at least as far as the ID
- * is concerned (in other words, we don't process any overrides here).
+ * assume that the EDID of the panel is correct, at least as far as the base
+ * block is concerned (in other words, we don't process any overrides here).
+ *
+ * Caller should call drm_edid_free() after use.
  *
  * NOTE: it's expected that this function and drm_do_get_edid() will both
  * be read the EDID, but there is no caching between them. Since we're only
  * reading the first block, hopefully this extra overhead won't be too big.
  *
- * Return: A 32-bit ID that should be different for each make/model of panel.
- *         See the functions drm_edid_encode_panel_id() and
- *         drm_edid_decode_panel_id() for some details on the structure of this
- *         ID.
+ * WARNING: Only use this function when the connector is unknown. For example,
+ * during the early probe of panel. The EDID read from the function is temporary
+ * and should be replaced by the full EDID returned from other drm_edid_read.
+ *
+ * Return: Pointer to allocated EDID base block, or NULL on any failure.
  */
-
-u32 drm_edid_get_panel_id(struct i2c_adapter *adapter)
+const struct drm_edid *drm_edid_read_base_block(struct i2c_adapter *adapter)
 {
        enum edid_block_status status;
        void *base_block;
-       u32 panel_id = 0;
-
-       /*
-        * There are no manufacturer IDs of 0, so if there is a problem reading
-        * the EDID then we'll just return 0.
-        */
 
        base_block = kzalloc(EDID_LENGTH, GFP_KERNEL);
        if (!base_block)
-               return 0;
+               return NULL;
 
        status = edid_block_read(base_block, 0, drm_do_probe_ddc_edid, adapter);
 
        edid_block_status_print(status, base_block, 0);
 
-       if (edid_block_status_valid(status, edid_block_tag(base_block)))
-               panel_id = edid_extract_panel_id(base_block);
-       else
+       if (!edid_block_status_valid(status, edid_block_tag(base_block))) {
                edid_block_dump(KERN_NOTICE, base_block, 0);
+               kfree(base_block);
+               return NULL;
+       }
 
-       kfree(base_block);
-
-       return panel_id;
+       return _drm_edid_alloc(base_block, EDID_LENGTH);
 }
-EXPORT_SYMBOL(drm_edid_get_panel_id);
+EXPORT_SYMBOL(drm_edid_read_base_block);
 
 /**
  * drm_get_edid_switcheroo - get EDID data for a vga_switcheroo output
@@ -2906,7 +2919,7 @@ EXPORT_SYMBOL(drm_edid_duplicate);
  */
 static u32 edid_get_quirks(const struct drm_edid *drm_edid)
 {
-       u32 panel_id = edid_extract_panel_id(drm_edid->edid);
+       u32 panel_id = drm_edid_get_panel_id(drm_edid);
        const struct edid_quirk *quirk;
        int i;
 
index 2906a382aae040f24af64c0413a706d424653b2c..f7db5b10e2336a1dad8bd8a505f0148713729a63 100644 (file)
@@ -766,6 +766,7 @@ static const struct edp_panel_entry *find_edp_panel(u32 panel_id);
 static int generic_edp_panel_probe(struct device *dev, struct panel_edp *panel)
 {
        struct panel_desc *desc;
+       const struct drm_edid *base_block;
        u32 panel_id;
        char vend[4];
        u16 product_id;
@@ -795,8 +796,11 @@ static int generic_edp_panel_probe(struct device *dev, struct panel_edp *panel)
                goto exit;
        }
 
-       panel_id = drm_edid_get_panel_id(panel->ddc);
-       if (!panel_id) {
+       base_block = drm_edid_read_base_block(panel->ddc);
+       if (base_block) {
+               panel_id = drm_edid_get_panel_id(base_block);
+               drm_edid_free(base_block);
+       } else {
                dev_err(dev, "Couldn't identify panel via EDID\n");
                ret = -EIO;
                goto exit;
index 7923bc00dc7a4386ef641c04d4e4d141b186b211..9686a7cee6a63972f788dc86e3e55772c2f1c30e 100644 (file)
@@ -410,7 +410,8 @@ struct edid *drm_do_get_edid(struct drm_connector *connector,
        void *data);
 struct edid *drm_get_edid(struct drm_connector *connector,
                          struct i2c_adapter *adapter);
-u32 drm_edid_get_panel_id(struct i2c_adapter *adapter);
+const struct drm_edid *drm_edid_read_base_block(struct i2c_adapter *adapter);
+u32 drm_edid_get_panel_id(const struct drm_edid *drm_edid);
 struct edid *drm_get_edid_switcheroo(struct drm_connector *connector,
                                     struct i2c_adapter *adapter);
 struct edid *drm_edid_duplicate(const struct edid *edid);