[v2,2/3] drm/panel: panel-edp: Match edp_panels with panel name
Commit Message
It's found that some panels have variants that they share the same panel id
although their EDID and names are different. When matching generic edp
panels, we should first match with both panel id and panel name by checking
if edid contains the name string. If not found, match with panel id only.
Signed-off-by: Hsin-Yi Wang <hsinyi@chromium.org>
---
v1->v2:
match with panel name instead of crc hash.
Note that we can't directly use drm_edid_get_monitor_name(), because some
panel store the name after EDID_DETAIL_MONITOR_STRING instead of
EDID_DETAIL_MONITOR_NAME.
---
drivers/gpu/drm/drm_edid.c | 69 +++++++------------------------
drivers/gpu/drm/panel/panel-edp.c | 44 +++++++++++++++++---
include/drm/drm_edid.h | 2 +-
3 files changed, 54 insertions(+), 61 deletions(-)
Comments
On Wed, 28 Feb 2024 at 03:11, Hsin-Yi Wang <hsinyi@chromium.org> wrote:
>
> It's found that some panels have variants that they share the same panel id
> although their EDID and names are different. When matching generic edp
> panels, we should first match with both panel id and panel name by checking
> if edid contains the name string. If not found, match with panel id only.
>
> Signed-off-by: Hsin-Yi Wang <hsinyi@chromium.org>
> ---
> v1->v2:
> match with panel name instead of crc hash.
> Note that we can't directly use drm_edid_get_monitor_name(), because some
> panel store the name after EDID_DETAIL_MONITOR_STRING instead of
> EDID_DETAIL_MONITOR_NAME.
> ---
> drivers/gpu/drm/drm_edid.c | 69 +++++++------------------------
> drivers/gpu/drm/panel/panel-edp.c | 44 +++++++++++++++++---
> include/drm/drm_edid.h | 2 +-
> 3 files changed, 54 insertions(+), 61 deletions(-)
>
> diff --git a/drivers/gpu/drm/drm_edid.c b/drivers/gpu/drm/drm_edid.c
> index 15b97c8ed993..c4126475ff0a 100644
> --- a/drivers/gpu/drm/drm_edid.c
> +++ b/drivers/gpu/drm/drm_edid.c
> @@ -2764,7 +2764,19 @@ 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)
> +/**
> + * edid_extract_panel_id - Extract a panel's ID from EDID
> + * @edid: EDID used to extract the panel's ID.
> + *
> + * Extract panel ID from EDID.
> + *
> + * 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.
> + */
> +
> +u32 edid_extract_panel_id(const struct edid *edid)
drm_edid_extract_panel_id(), please
> {
> /*
> * We represent the ID as a 32-bit number so it can easily be compared
[skipeed the rest, LGTM]
Hi,
On Tue, Feb 27, 2024 at 5:11 PM Hsin-Yi Wang <hsinyi@chromium.org> wrote:
>
> @@ -2107,13 +2113,41 @@ static const struct edp_panel_entry edp_panels[] = {
> { /* sentinal */ }
> };
>
> -static const struct edp_panel_entry *find_edp_panel(u32 panel_id)
> +static bool edid_has_name(struct edid *edid, const char *panel_name)
> +{
> + int i, j;
> + char buf[13];
> +
Should have some comment about why this can't use
drm_edid_get_monitor_name(). AKA because panels seem to be storing the
monitor name tagged as raw strings instead of as the name. Should
probably also have some of the other checks from
is_display_descriptor() like checking for clock of 0 and pad1 of 0.
> + for (i = 0; i < 4; i++) {
Instead of 4, I think this can be ARRAY_SIZE(edid->detailed_timings), right?
> + strncpy(buf, edid->detailed_timings[i].data.other_data.data.str.str,
> + sizeof(buf));
I can never quite remember which of the strXcpy() routines are frowned
upon and which are the golden children at the moment. ...but I don't
think we really need the copy nor the local buffer anyway, right?
You're already going through this thing 1 byte at a time so just
compare it straight away.
> + for (j = 0; j < 13; j++) {
> + if (buf[j] == 0x0a) {
Instead of hardcoding 0x0a, I think you want '\n', no?
> + buf[j] = '\0';
> + break;
> + }
> + }
> + buf[12] = '\0';
> + if (strncmp(panel_name, buf, strlen(panel_name)) == 0)
> + return true;
Untested, but I think with my suggestions above the function becomes this:
static bool edid_has_name(struct edid *edid, const char *panel_name)
{
int i, j;
/*
* We can't use drm_edid_get_monitor_name() since many eDP panels store
* their name as a raw string. We'll accept either a string or name
* match as long as the panel ID also matches.
*/
for (i = 0; i < ARRAY_SIZE(edid->detailed_timings); i++) {
struct detailed_timing *timing = &edid->detailed_timings[i];
if (timing->pixel_clock != 0 ||
timing->data.other_data.pad1 != 0 ||
(timing->data.other_data.type != EDID_DETAIL_MONITOR_NAME &&
timing->data.other_data.type != EDID_DETAIL_MONITOR_STRING))
continue;
for (j = 0; j < ARRAY_SIZE(timing->data.other_data.data.str.str); j++) {
const char *str = timing->data.other_data.data.str.str;
if (panel_name[j] == '\0') {
if (str[j] == '\0' || str[j] == '\n')
return true;
break;
}
}
if (j == ARRAY_SIZE(timing->data.other_data.data.str.str) &&
panel_name[j] == '\0')
return true;
}
return false;
}
@@ -2764,7 +2764,19 @@ 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)
+/**
+ * edid_extract_panel_id - Extract a panel's ID from EDID
+ * @edid: EDID used to extract the panel's ID.
+ *
+ * Extract panel ID from EDID.
+ *
+ * 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.
+ */
+
+u32 edid_extract_panel_id(const struct edid *edid)
{
/*
* We represent the ID as a 32-bit number so it can easily be compared
@@ -2783,60 +2795,7 @@ static u32 edid_extract_panel_id(const struct edid *edid)
(u32)edid->mfg_id[1] << 16 |
(u32)EDID_PRODUCT_ID(edid);
}
-
-/**
- * drm_edid_get_panel_id - Get a panel's ID through DDC
- * @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 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).
- *
- * 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.
- */
-
-u32 drm_edid_get_panel_id(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;
-
- 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
- edid_block_dump(KERN_NOTICE, base_block, 0);
-
- kfree(base_block);
-
- return panel_id;
-}
-EXPORT_SYMBOL(drm_edid_get_panel_id);
+EXPORT_SYMBOL(edid_extract_panel_id);
/**
* drm_get_edid_switcheroo - get EDID data for a vga_switcheroo output
@@ -761,11 +761,13 @@ static void panel_edp_parse_panel_timing_node(struct device *dev,
dev_err(dev, "Reject override mode: No display_timing found\n");
}
-static const struct edp_panel_entry *find_edp_panel(u32 panel_id);
+static bool edid_has_name(struct edid *edid, const char *panel_name);
+static const struct edp_panel_entry *find_edp_panel(u32 panel_id, struct edid *edid);
static int generic_edp_panel_probe(struct device *dev, struct panel_edp *panel)
{
struct panel_desc *desc;
+ struct edid *edid;
u32 panel_id;
char vend[4];
u16 product_id;
@@ -795,15 +797,19 @@ 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) {
+ edid = drm_get_edid_no_connector(panel->ddc);
+ if (!edid) {
dev_err(dev, "Couldn't identify panel via EDID\n");
ret = -EIO;
goto exit;
}
+ panel_id = edid_extract_panel_id(edid);
drm_edid_decode_panel_id(panel_id, vend, &product_id);
- panel->detected_panel = find_edp_panel(panel_id);
+ panel->detected_panel = find_edp_panel(panel_id, edid);
+
+ /* Read EDID again in panel_edp_get_modes() when connector is known. */
+ kfree(edid);
/*
* We're using non-optimized timings and want it really obvious that
@@ -2107,13 +2113,41 @@ static const struct edp_panel_entry edp_panels[] = {
{ /* sentinal */ }
};
-static const struct edp_panel_entry *find_edp_panel(u32 panel_id)
+static bool edid_has_name(struct edid *edid, const char *panel_name)
+{
+ int i, j;
+ char buf[13];
+
+ for (i = 0; i < 4; i++) {
+ strncpy(buf, edid->detailed_timings[i].data.other_data.data.str.str,
+ sizeof(buf));
+ for (j = 0; j < 13; j++) {
+ if (buf[j] == 0x0a) {
+ buf[j] = '\0';
+ break;
+ }
+ }
+ buf[12] = '\0';
+ if (strncmp(panel_name, buf, strlen(panel_name)) == 0)
+ return true;
+ }
+
+ return false;
+}
+
+static const struct edp_panel_entry *find_edp_panel(u32 panel_id, struct edid *edid)
{
const struct edp_panel_entry *panel;
if (!panel_id)
return NULL;
+ /* Match with both panel_id and name. Find if EDID contains name. */
+ for (panel = edp_panels; panel->panel_id; panel++)
+ if (panel->panel_id == panel_id && edid_has_name(edid, panel->name))
+ return panel;
+
+ /* Match with only panel_id */
for (panel = edp_panels; panel->panel_id; panel++)
if (panel->panel_id == panel_id)
return panel;
@@ -566,7 +566,7 @@ struct edid *drm_do_get_edid(struct drm_connector *connector,
struct edid *drm_get_edid(struct drm_connector *connector,
struct i2c_adapter *adapter);
struct edid *drm_get_edid_no_connector(struct i2c_adapter *adapter);
-u32 drm_edid_get_panel_id(struct i2c_adapter *adapter);
+u32 edid_extract_panel_id(const struct edid *edid);
struct edid *drm_get_edid_switcheroo(struct drm_connector *connector,
struct i2c_adapter *adapter);
struct edid *drm_edid_duplicate(const struct edid *edid);