2024-03-06 00:43:59

by Hsin-Yi Wang

[permalink] [raw]
Subject: [PATCH v4 0/5] Match panel with identity

This series is a follow up for 1a5e81de180e ("Revert "drm/panel-edp: Add
auo_b116xa3_mode""). It's found that 2 different AUO panels use the same
product id. One of them requires an overridden mode, while the other should
use the mode directly from edid.

Match the panel for identity (id and name). If not found, fallback to match
id.

v1: https://lore.kernel.org/lkml/[email protected]
v2: https://lore.kernel.org/lkml/[email protected]
v3: https://lore.kernel.org/lkml/[email protected]

Hsin-Yi Wang (5):
drm_edid: Add a function to get EDID base block
drm/edid: Add a function to match EDID with identity
drm/edid: match edid quirks with identity
drm/panel-edp: Match edp_panels with panel identity
drm/panel-edp: Fix AUO 0x405c panel naming and add a variant

drivers/gpu/drm/drm_edid.c | 152 ++++++++++++++++++++++++------
drivers/gpu/drm/panel/panel-edp.c | 68 ++++++++-----
include/drm/drm_edid.h | 11 ++-
3 files changed, 177 insertions(+), 54 deletions(-)

--
2.44.0.278.ge034bb2e1d-goog



2024-03-06 00:44:07

by Hsin-Yi Wang

[permalink] [raw]
Subject: [PATCH v4 1/5] drm_edid: Add a function to get EDID base block

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.

Signed-off-by: Hsin-Yi Wang <[email protected]>
---
v3->v4: change drm_edid_read_base_block return type to drm_edid.
---
drivers/gpu/drm/drm_edid.c | 63 +++++++++++++++++++------------
drivers/gpu/drm/panel/panel-edp.c | 8 +++-
include/drm/drm_edid.h | 3 +-
3 files changed, 46 insertions(+), 28 deletions(-)

diff --git a/drivers/gpu/drm/drm_edid.c b/drivers/gpu/drm/drm_edid.c
index 923c4423151c..f9e09f327f81 100644
--- a/drivers/gpu/drm/drm_edid.c
+++ b/drivers/gpu/drm/drm_edid.c
@@ -2770,58 +2770,71 @@ static u32 edid_extract_panel_id(const struct edid *edid)
}

/**
- * drm_edid_get_panel_id - Get a panel's ID through DDC
- * @adapter: I2C adapter to use for DDC
+ * drm_edid_get_panel_id - Get a panel's ID from EDID
+ * @drm_edid: EDID that contains panel ID.
*
- * This function reads the first block of the EDID of a panel and (assuming
+ * 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.
+ */
+u32 drm_edid_get_panel_id(const struct drm_edid *drm_edid)
+{
+ return edid_extract_panel_id(drm_edid->edid);
+}
+EXPORT_SYMBOL(drm_edid_get_panel_id);
+
+/**
+ * drm_edid_read_base_block - Get a panel's EDID base block
+ * @adapter: I2C adapter to use for DDC
+ *
+ * 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
diff --git a/drivers/gpu/drm/panel/panel-edp.c b/drivers/gpu/drm/panel/panel-edp.c
index 745f3e48f02a..d094cfc43da8 100644
--- a/drivers/gpu/drm/panel/panel-edp.c
+++ b/drivers/gpu/drm/panel/panel-edp.c
@@ -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;
diff --git a/include/drm/drm_edid.h b/include/drm/drm_edid.h
index 7923bc00dc7a..9686a7cee6a6 100644
--- a/include/drm/drm_edid.h
+++ b/include/drm/drm_edid.h
@@ -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);
--
2.44.0.278.ge034bb2e1d-goog


2024-03-06 00:44:13

by Hsin-Yi Wang

[permalink] [raw]
Subject: [PATCH v4 2/5] drm/edid: Add a function to match EDID with identity

Create a type drm_edid_ident as the identity of an EDID. Currently it
contains panel id and monitor name.

Create a function that can match a given EDID and an identity:
1. Reject if the panel id doesn't match.
2. If name is not null in identity, try to match it in the detailed timing
blocks. Note that some panel vendors put the monitor name after
EDID_DETAIL_MONITOR_STRING.

Signed-off-by: Hsin-Yi Wang <[email protected]>
---
v3->v4:
1. add a type drm_edid_ident
2. match name -> match identity. Modify function to use edid iterators.
---
drivers/gpu/drm/drm_edid.c | 76 ++++++++++++++++++++++++++++++++++++++
include/drm/drm_edid.h | 8 ++++
2 files changed, 84 insertions(+)

diff --git a/drivers/gpu/drm/drm_edid.c b/drivers/gpu/drm/drm_edid.c
index f9e09f327f81..5e7e69e0e345 100644
--- a/drivers/gpu/drm/drm_edid.c
+++ b/drivers/gpu/drm/drm_edid.c
@@ -102,6 +102,11 @@ struct detailed_mode_closure {
int modes;
};

+struct drm_edid_ident_closure {
+ const struct drm_edid_ident *ident;
+ bool matched;
+};
+
#define LEVEL_DMT 0
#define LEVEL_GTF 1
#define LEVEL_GTF2 2
@@ -5455,6 +5460,77 @@ drm_parse_hdmi_vsdb_audio(struct drm_connector *connector, const u8 *db)
connector->audio_latency[0], connector->audio_latency[1]);
}

+static void
+match_identity(const struct detailed_timing *timing, void *data)
+{
+ struct drm_edid_ident_closure *closure = data;
+ unsigned int i, j;
+ const char *str = closure->ident->name;
+ unsigned int buflen = strlen(str);
+ unsigned int size = ARRAY_SIZE(timing->data.other_data.data.str.str);
+
+ if (buflen > size ||
+ !(is_display_descriptor(timing, EDID_DETAIL_MONITOR_NAME) ||
+ is_display_descriptor(timing, EDID_DETAIL_MONITOR_STRING)))
+ return;
+
+ for (i = 0; i < buflen; i++) {
+ char c = timing->data.other_data.data.str.str[i];
+
+ if (c != str[i] || c == '\n')
+ break;
+ }
+
+ if (i == buflen) {
+ /* Allow trailing white spaces. */
+ for (j = i; j < size; j++) {
+ char c = timing->data.other_data.data.str.str[j];
+
+ if (c == '\n') {
+ closure->matched = true;
+ return;
+ } else if (c != ' ') {
+ break;
+ }
+ }
+ if (j == size) {
+ closure->matched = true;
+ return;
+ }
+ }
+}
+
+/**
+ * drm_edid_match_identity - match drm_edid with given identity
+ * @drm_edid: EDID
+ * @ident: the EDID identity to match with
+ *
+ * Check if the EDID matches with the given identity.
+ *
+ * Return: True if the given identity matched with EDID, false otherwise.
+ */
+bool drm_edid_match_identity(const struct drm_edid *drm_edid,
+ const struct drm_edid_ident *ident)
+{
+ if (!drm_edid || edid_extract_panel_id(drm_edid->edid) != ident->panel_id)
+ return false;
+
+ /* Match with name only if it's not NULL. */
+ if (ident->name) {
+ struct drm_edid_ident_closure closure = {
+ .ident = ident,
+ .matched = false,
+ };
+
+ drm_for_each_detailed_block(drm_edid, match_identity, &closure);
+
+ return closure.matched;
+ }
+
+ return true;
+}
+EXPORT_SYMBOL(drm_edid_match_identity);
+
static void
monitor_name(const struct detailed_timing *timing, void *data)
{
diff --git a/include/drm/drm_edid.h b/include/drm/drm_edid.h
index 9686a7cee6a6..01825a8954b6 100644
--- a/include/drm/drm_edid.h
+++ b/include/drm/drm_edid.h
@@ -312,6 +312,12 @@ struct edid {
u8 checksum;
} __packed;

+/* EDID matching */
+struct drm_edid_ident {
+ u32 panel_id;
+ const char *name;
+};
+
#define EDID_PRODUCT_ID(e) ((e)->prod_code[0] | ((e)->prod_code[1] << 8))

/* Short Audio Descriptor */
@@ -412,6 +418,8 @@ struct edid *drm_get_edid(struct drm_connector *connector,
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);
+bool drm_edid_match_identity(const struct drm_edid *drm_edid,
+ const struct drm_edid_ident *ident);
struct edid *drm_get_edid_switcheroo(struct drm_connector *connector,
struct i2c_adapter *adapter);
struct edid *drm_edid_duplicate(const struct edid *edid);
--
2.44.0.278.ge034bb2e1d-goog


2024-03-06 00:44:20

by Hsin-Yi Wang

[permalink] [raw]
Subject: [PATCH v4 3/5] drm/edid: Match edid quirks with identity

Currently edid quirks are matched by panel id only.

Modify it to match with identity so it's easier to be extended
for more complex matching if required.

Suggested-by: Jani Nikula <[email protected]>
Signed-off-by: Hsin-Yi Wang <[email protected]>
---
v4: new
Per discussion https://lore.kernel.org/lkml/[email protected]/
---
drivers/gpu/drm/drm_edid.c | 13 ++++++++-----
1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/drivers/gpu/drm/drm_edid.c b/drivers/gpu/drm/drm_edid.c
index 5e7e69e0e345..93a49b262dbe 100644
--- a/drivers/gpu/drm/drm_edid.c
+++ b/drivers/gpu/drm/drm_edid.c
@@ -114,13 +114,15 @@ struct drm_edid_ident_closure {

#define EDID_QUIRK(vend_chr_0, vend_chr_1, vend_chr_2, product_id, _quirks) \
{ \
- .panel_id = drm_edid_encode_panel_id(vend_chr_0, vend_chr_1, vend_chr_2, \
- product_id), \
+ .ident = { \
+ .panel_id = drm_edid_encode_panel_id(vend_chr_0, vend_chr_1, \
+ vend_chr_2, product_id), \
+ }, \
.quirks = _quirks \
}

static const struct edid_quirk {
- u32 panel_id;
+ const struct drm_edid_ident ident;
u32 quirks;
} edid_quirk_list[] = {
/* Acer AL1706 */
@@ -2921,16 +2923,17 @@ EXPORT_SYMBOL(drm_edid_duplicate);
* @drm_edid: EDID to process
*
* This tells subsequent routines what fixes they need to apply.
+ *
+ * Return: A u32 represents the quirks to apply.
*/
static u32 edid_get_quirks(const struct drm_edid *drm_edid)
{
- u32 panel_id = edid_extract_panel_id(drm_edid->edid);
const struct edid_quirk *quirk;
int i;

for (i = 0; i < ARRAY_SIZE(edid_quirk_list); i++) {
quirk = &edid_quirk_list[i];
- if (quirk->panel_id == panel_id)
+ if (drm_edid_match_identity(drm_edid, &quirk->ident))
return quirk->quirks;
}

--
2.44.0.278.ge034bb2e1d-goog


2024-03-06 00:44:33

by Hsin-Yi Wang

[permalink] [raw]
Subject: [PATCH v4 4/5] drm/panel-edp: Match edp_panels with panel identity

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 identity, which contains both
panel id and panel name. If not found, match with panel id only.

Signed-off-by: Hsin-Yi Wang <[email protected]>
---
v3->v4: combine name and id to identity.
---
drivers/gpu/drm/panel/panel-edp.c | 45 ++++++++++++++++---------------
1 file changed, 24 insertions(+), 21 deletions(-)

diff --git a/drivers/gpu/drm/panel/panel-edp.c b/drivers/gpu/drm/panel/panel-edp.c
index d094cfc43da8..fb70e97a2e71 100644
--- a/drivers/gpu/drm/panel/panel-edp.c
+++ b/drivers/gpu/drm/panel/panel-edp.c
@@ -210,15 +210,12 @@ struct panel_desc {
* struct edp_panel_entry - Maps panel ID to delay / panel name.
*/
struct edp_panel_entry {
- /** @panel_id: 32-bit ID for panel, encoded with drm_edid_encode_panel_id(). */
- u32 panel_id;
+ /** @ident: edid identity used for panel matching. */
+ const struct drm_edid_ident ident;

/** @delay: The power sequencing delays needed for this panel. */
const struct panel_delay *delay;

- /** @name: Name of this panel (for printing to logs). */
- const char *name;
-
/** @override_edid_mode: Override the mode obtained by edid. */
const struct drm_display_mode *override_edid_mode;
};
@@ -691,7 +688,7 @@ static int detected_panel_show(struct seq_file *s, void *data)
else if (!p->detected_panel)
seq_puts(s, "HARDCODED\n");
else
- seq_printf(s, "%s\n", p->detected_panel->name);
+ seq_printf(s, "%s\n", p->detected_panel->ident.name);

return 0;
}
@@ -761,7 +758,7 @@ 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 const struct edp_panel_entry *find_edp_panel(u32 panel_id, const struct drm_edid *edid);

static int generic_edp_panel_probe(struct device *dev, struct panel_edp *panel)
{
@@ -799,7 +796,6 @@ static int generic_edp_panel_probe(struct device *dev, struct panel_edp *panel)
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;
@@ -807,7 +803,9 @@ static int generic_edp_panel_probe(struct device *dev, struct panel_edp *panel)
}
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, base_block);
+
+ drm_edid_free(base_block);

/*
* We're using non-optimized timings and want it really obvious that
@@ -840,7 +838,7 @@ static int generic_edp_panel_probe(struct device *dev, struct panel_edp *panel)
panel->detected_panel = ERR_PTR(-EINVAL);
} else {
dev_info(dev, "Detected %s %s (%#06x)\n",
- vend, panel->detected_panel->name, product_id);
+ vend, panel->detected_panel->ident.name, product_id);

/* Update the delay; everything else comes from EDID */
desc->delay = *panel->detected_panel->delay;
@@ -1930,17 +1928,21 @@ static const struct panel_delay delay_200_500_e50_po2e200 = {

#define EDP_PANEL_ENTRY(vend_chr_0, vend_chr_1, vend_chr_2, product_id, _delay, _name) \
{ \
- .name = _name, \
- .panel_id = drm_edid_encode_panel_id(vend_chr_0, vend_chr_1, vend_chr_2, \
- product_id), \
+ .ident = { \
+ .name = _name, \
+ .panel_id = drm_edid_encode_panel_id(vend_chr_0, vend_chr_1, vend_chr_2, \
+ product_id), \
+ }, \
.delay = _delay \
}

#define EDP_PANEL_ENTRY2(vend_chr_0, vend_chr_1, vend_chr_2, product_id, _delay, _name, _mode) \
{ \
- .name = _name, \
- .panel_id = drm_edid_encode_panel_id(vend_chr_0, vend_chr_1, vend_chr_2, \
- product_id), \
+ .ident = { \
+ .name = _name, \
+ .panel_id = drm_edid_encode_panel_id(vend_chr_0, vend_chr_1, vend_chr_2, \
+ product_id), \
+ }, \
.delay = _delay, \
.override_edid_mode = _mode \
}
@@ -2087,15 +2089,16 @@ static const struct edp_panel_entry edp_panels[] = {
{ /* sentinal */ }
};

-static const struct edp_panel_entry *find_edp_panel(u32 panel_id)
+static const struct edp_panel_entry *find_edp_panel(u32 panel_id, const struct drm_edid *edid)
{
const struct edp_panel_entry *panel;

- if (!panel_id)
- return NULL;
+ for (panel = edp_panels; panel->ident.panel_id; panel++)
+ if (drm_edid_match_identity(edid, &panel->ident))
+ return panel;

- for (panel = edp_panels; panel->panel_id; panel++)
- if (panel->panel_id == panel_id)
+ for (panel = edp_panels; panel->ident.panel_id; panel++)
+ if (panel->ident.panel_id == panel_id)
return panel;

return NULL;
--
2.44.0.278.ge034bb2e1d-goog


2024-03-06 00:44:45

by Hsin-Yi Wang

[permalink] [raw]
Subject: [PATCH v4 5/5] drm/panel-edp: Fix AUO 0x405c panel naming and add a variant

There are 2 different AUO panels using the same panel id. One of the
variants requires using overridden modes to resolve glitching issue as
described in commit 70e0d5550f5c ("drm/panel-edp: Add auo_b116xa3_mode").
Other variants should use the modes parsed from EDID.

Signed-off-by: Hsin-Yi Wang <[email protected]>
---
v4->v5: no change
---
drivers/gpu/drm/panel/panel-edp.c | 17 ++++++++++++++++-
1 file changed, 16 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/panel/panel-edp.c b/drivers/gpu/drm/panel/panel-edp.c
index fb70e97a2e71..9db04457fb4d 100644
--- a/drivers/gpu/drm/panel/panel-edp.c
+++ b/drivers/gpu/drm/panel/panel-edp.c
@@ -1007,6 +1007,19 @@ static const struct panel_desc auo_b101ean01 = {
},
};

+static const struct drm_display_mode auo_b116xa3_mode = {
+ .clock = 70589,
+ .hdisplay = 1366,
+ .hsync_start = 1366 + 40,
+ .hsync_end = 1366 + 40 + 40,
+ .htotal = 1366 + 40 + 40 + 32,
+ .vdisplay = 768,
+ .vsync_start = 768 + 10,
+ .vsync_end = 768 + 10 + 12,
+ .vtotal = 768 + 10 + 12 + 6,
+ .flags = DRM_MODE_FLAG_NVSYNC | DRM_MODE_FLAG_NHSYNC,
+};
+
static const struct drm_display_mode auo_b116xak01_mode = {
.clock = 69300,
.hdisplay = 1366,
@@ -1966,7 +1979,9 @@ static const struct edp_panel_entry edp_panels[] = {
EDP_PANEL_ENTRY('A', 'U', 'O', 0x239b, &delay_200_500_e50, "B116XAN06.1"),
EDP_PANEL_ENTRY('A', 'U', 'O', 0x255c, &delay_200_500_e50, "B116XTN02.5"),
EDP_PANEL_ENTRY('A', 'U', 'O', 0x403d, &delay_200_500_e50, "B140HAN04.0"),
- EDP_PANEL_ENTRY('A', 'U', 'O', 0x405c, &auo_b116xak01.delay, "B116XAK01.0"),
+ EDP_PANEL_ENTRY('A', 'U', 'O', 0x405c, &auo_b116xak01.delay, "B116XAN04.0"),
+ EDP_PANEL_ENTRY2('A', 'U', 'O', 0x405c, &auo_b116xak01.delay, "B116XAK01.0 ",
+ &auo_b116xa3_mode),
EDP_PANEL_ENTRY('A', 'U', 'O', 0x435c, &delay_200_500_e50, "Unknown"),
EDP_PANEL_ENTRY('A', 'U', 'O', 0x582d, &delay_200_500_e50, "B133UAN01.0"),
EDP_PANEL_ENTRY('A', 'U', 'O', 0x615c, &delay_200_500_e50, "B116XAN06.1"),
--
2.44.0.278.ge034bb2e1d-goog


2024-03-06 08:52:35

by Jani Nikula

[permalink] [raw]
Subject: Re: [PATCH v4 1/5] drm_edid: Add a function to get EDID base block

On Tue, 05 Mar 2024, Hsin-Yi Wang <[email protected]> wrote:
> 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.
>
> Signed-off-by: Hsin-Yi Wang <[email protected]>
> ---
> v3->v4: change drm_edid_read_base_block return type to drm_edid.
> ---
> drivers/gpu/drm/drm_edid.c | 63 +++++++++++++++++++------------
> drivers/gpu/drm/panel/panel-edp.c | 8 +++-
> include/drm/drm_edid.h | 3 +-
> 3 files changed, 46 insertions(+), 28 deletions(-)
>
> diff --git a/drivers/gpu/drm/drm_edid.c b/drivers/gpu/drm/drm_edid.c
> index 923c4423151c..f9e09f327f81 100644
> --- a/drivers/gpu/drm/drm_edid.c
> +++ b/drivers/gpu/drm/drm_edid.c
> @@ -2770,58 +2770,71 @@ static u32 edid_extract_panel_id(const struct edid *edid)
> }
>
> /**
> - * drm_edid_get_panel_id - Get a panel's ID through DDC
> - * @adapter: I2C adapter to use for DDC
> + * drm_edid_get_panel_id - Get a panel's ID from EDID
> + * @drm_edid: EDID that contains panel ID.
> *
> - * This function reads the first block of the EDID of a panel and (assuming
> + * 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.
> + */
> +u32 drm_edid_get_panel_id(const struct drm_edid *drm_edid)
> +{
> + return edid_extract_panel_id(drm_edid->edid);
> +}
> +EXPORT_SYMBOL(drm_edid_get_panel_id);
> +
> +/**
> + * drm_edid_read_base_block - Get a panel's EDID base block
> + * @adapter: I2C adapter to use for DDC
> + *
> + * 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);

This leaks base_block. Please use _drm_edid_alloc() (with underscore) to
only allocate the container without kmemduping the data.

Otherwise LGTM.

BR,
Jani.



> }
> -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
> diff --git a/drivers/gpu/drm/panel/panel-edp.c b/drivers/gpu/drm/panel/panel-edp.c
> index 745f3e48f02a..d094cfc43da8 100644
> --- a/drivers/gpu/drm/panel/panel-edp.c
> +++ b/drivers/gpu/drm/panel/panel-edp.c
> @@ -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;
> diff --git a/include/drm/drm_edid.h b/include/drm/drm_edid.h
> index 7923bc00dc7a..9686a7cee6a6 100644
> --- a/include/drm/drm_edid.h
> +++ b/include/drm/drm_edid.h
> @@ -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);

--
Jani Nikula, Intel

2024-03-06 09:19:00

by Jani Nikula

[permalink] [raw]
Subject: Re: [PATCH v4 3/5] drm/edid: Match edid quirks with identity

On Tue, 05 Mar 2024, Hsin-Yi Wang <[email protected]> wrote:
> Currently edid quirks are matched by panel id only.
>
> Modify it to match with identity so it's easier to be extended
> for more complex matching if required.
>
> Suggested-by: Jani Nikula <[email protected]>
> Signed-off-by: Hsin-Yi Wang <[email protected]>

Reviewed-by: Jani Nikula <[email protected]>

> ---
> v4: new
> Per discussion https://lore.kernel.org/lkml/[email protected]/
> ---
> drivers/gpu/drm/drm_edid.c | 13 ++++++++-----
> 1 file changed, 8 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/gpu/drm/drm_edid.c b/drivers/gpu/drm/drm_edid.c
> index 5e7e69e0e345..93a49b262dbe 100644
> --- a/drivers/gpu/drm/drm_edid.c
> +++ b/drivers/gpu/drm/drm_edid.c
> @@ -114,13 +114,15 @@ struct drm_edid_ident_closure {
>
> #define EDID_QUIRK(vend_chr_0, vend_chr_1, vend_chr_2, product_id, _quirks) \
> { \
> - .panel_id = drm_edid_encode_panel_id(vend_chr_0, vend_chr_1, vend_chr_2, \
> - product_id), \
> + .ident = { \
> + .panel_id = drm_edid_encode_panel_id(vend_chr_0, vend_chr_1, \
> + vend_chr_2, product_id), \
> + }, \
> .quirks = _quirks \
> }
>
> static const struct edid_quirk {
> - u32 panel_id;
> + const struct drm_edid_ident ident;
> u32 quirks;
> } edid_quirk_list[] = {
> /* Acer AL1706 */
> @@ -2921,16 +2923,17 @@ EXPORT_SYMBOL(drm_edid_duplicate);
> * @drm_edid: EDID to process
> *
> * This tells subsequent routines what fixes they need to apply.
> + *
> + * Return: A u32 represents the quirks to apply.
> */
> static u32 edid_get_quirks(const struct drm_edid *drm_edid)
> {
> - u32 panel_id = edid_extract_panel_id(drm_edid->edid);
> const struct edid_quirk *quirk;
> int i;
>
> for (i = 0; i < ARRAY_SIZE(edid_quirk_list); i++) {
> quirk = &edid_quirk_list[i];
> - if (quirk->panel_id == panel_id)
> + if (drm_edid_match_identity(drm_edid, &quirk->ident))
> return quirk->quirks;
> }

--
Jani Nikula, Intel

2024-03-06 09:24:00

by Jani Nikula

[permalink] [raw]
Subject: Re: [PATCH v4 4/5] drm/panel-edp: Match edp_panels with panel identity

On Tue, 05 Mar 2024, Hsin-Yi Wang <[email protected]> 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 identity, which contains both
> panel id and panel name. If not found, match with panel id only.

Do you want to start matching also with name, for all panels? That's
totally up to you, but that's the big functional change here.

BR,
Jani.

>
> Signed-off-by: Hsin-Yi Wang <[email protected]>
> ---
> v3->v4: combine name and id to identity.
> ---
> drivers/gpu/drm/panel/panel-edp.c | 45 ++++++++++++++++---------------
> 1 file changed, 24 insertions(+), 21 deletions(-)
>
> diff --git a/drivers/gpu/drm/panel/panel-edp.c b/drivers/gpu/drm/panel/panel-edp.c
> index d094cfc43da8..fb70e97a2e71 100644
> --- a/drivers/gpu/drm/panel/panel-edp.c
> +++ b/drivers/gpu/drm/panel/panel-edp.c
> @@ -210,15 +210,12 @@ struct panel_desc {
> * struct edp_panel_entry - Maps panel ID to delay / panel name.
> */
> struct edp_panel_entry {
> - /** @panel_id: 32-bit ID for panel, encoded with drm_edid_encode_panel_id(). */
> - u32 panel_id;
> + /** @ident: edid identity used for panel matching. */
> + const struct drm_edid_ident ident;
>
> /** @delay: The power sequencing delays needed for this panel. */
> const struct panel_delay *delay;
>
> - /** @name: Name of this panel (for printing to logs). */
> - const char *name;
> -
> /** @override_edid_mode: Override the mode obtained by edid. */
> const struct drm_display_mode *override_edid_mode;
> };
> @@ -691,7 +688,7 @@ static int detected_panel_show(struct seq_file *s, void *data)
> else if (!p->detected_panel)
> seq_puts(s, "HARDCODED\n");
> else
> - seq_printf(s, "%s\n", p->detected_panel->name);
> + seq_printf(s, "%s\n", p->detected_panel->ident.name);
>
> return 0;
> }
> @@ -761,7 +758,7 @@ 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 const struct edp_panel_entry *find_edp_panel(u32 panel_id, const struct drm_edid *edid);
>
> static int generic_edp_panel_probe(struct device *dev, struct panel_edp *panel)
> {
> @@ -799,7 +796,6 @@ static int generic_edp_panel_probe(struct device *dev, struct panel_edp *panel)
> 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;
> @@ -807,7 +803,9 @@ static int generic_edp_panel_probe(struct device *dev, struct panel_edp *panel)
> }
> 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, base_block);
> +
> + drm_edid_free(base_block);
>
> /*
> * We're using non-optimized timings and want it really obvious that
> @@ -840,7 +838,7 @@ static int generic_edp_panel_probe(struct device *dev, struct panel_edp *panel)
> panel->detected_panel = ERR_PTR(-EINVAL);
> } else {
> dev_info(dev, "Detected %s %s (%#06x)\n",
> - vend, panel->detected_panel->name, product_id);
> + vend, panel->detected_panel->ident.name, product_id);
>
> /* Update the delay; everything else comes from EDID */
> desc->delay = *panel->detected_panel->delay;
> @@ -1930,17 +1928,21 @@ static const struct panel_delay delay_200_500_e50_po2e200 = {
>
> #define EDP_PANEL_ENTRY(vend_chr_0, vend_chr_1, vend_chr_2, product_id, _delay, _name) \
> { \
> - .name = _name, \
> - .panel_id = drm_edid_encode_panel_id(vend_chr_0, vend_chr_1, vend_chr_2, \
> - product_id), \
> + .ident = { \
> + .name = _name, \
> + .panel_id = drm_edid_encode_panel_id(vend_chr_0, vend_chr_1, vend_chr_2, \
> + product_id), \
> + }, \
> .delay = _delay \
> }
>
> #define EDP_PANEL_ENTRY2(vend_chr_0, vend_chr_1, vend_chr_2, product_id, _delay, _name, _mode) \
> { \
> - .name = _name, \
> - .panel_id = drm_edid_encode_panel_id(vend_chr_0, vend_chr_1, vend_chr_2, \
> - product_id), \
> + .ident = { \
> + .name = _name, \
> + .panel_id = drm_edid_encode_panel_id(vend_chr_0, vend_chr_1, vend_chr_2, \
> + product_id), \
> + }, \
> .delay = _delay, \
> .override_edid_mode = _mode \
> }
> @@ -2087,15 +2089,16 @@ static const struct edp_panel_entry edp_panels[] = {
> { /* sentinal */ }
> };
>
> -static const struct edp_panel_entry *find_edp_panel(u32 panel_id)
> +static const struct edp_panel_entry *find_edp_panel(u32 panel_id, const struct drm_edid *edid)
> {
> const struct edp_panel_entry *panel;
>
> - if (!panel_id)
> - return NULL;
> + for (panel = edp_panels; panel->ident.panel_id; panel++)
> + if (drm_edid_match_identity(edid, &panel->ident))
> + return panel;
>
> - for (panel = edp_panels; panel->panel_id; panel++)
> - if (panel->panel_id == panel_id)
> + for (panel = edp_panels; panel->ident.panel_id; panel++)
> + if (panel->ident.panel_id == panel_id)
> return panel;
>
> return NULL;

--
Jani Nikula, Intel

2024-03-06 09:28:48

by Jani Nikula

[permalink] [raw]
Subject: Re: [PATCH v4 2/5] drm/edid: Add a function to match EDID with identity

On Tue, 05 Mar 2024, Hsin-Yi Wang <[email protected]> wrote:
> Create a type drm_edid_ident as the identity of an EDID. Currently it
> contains panel id and monitor name.
>
> Create a function that can match a given EDID and an identity:
> 1. Reject if the panel id doesn't match.
> 2. If name is not null in identity, try to match it in the detailed timing
> blocks. Note that some panel vendors put the monitor name after
> EDID_DETAIL_MONITOR_STRING.
>
> Signed-off-by: Hsin-Yi Wang <[email protected]>
> ---
> v3->v4:
> 1. add a type drm_edid_ident
> 2. match name -> match identity. Modify function to use edid iterators.
> ---
> drivers/gpu/drm/drm_edid.c | 76 ++++++++++++++++++++++++++++++++++++++
> include/drm/drm_edid.h | 8 ++++
> 2 files changed, 84 insertions(+)
>
> diff --git a/drivers/gpu/drm/drm_edid.c b/drivers/gpu/drm/drm_edid.c
> index f9e09f327f81..5e7e69e0e345 100644
> --- a/drivers/gpu/drm/drm_edid.c
> +++ b/drivers/gpu/drm/drm_edid.c
> @@ -102,6 +102,11 @@ struct detailed_mode_closure {
> int modes;
> };
>
> +struct drm_edid_ident_closure {
> + const struct drm_edid_ident *ident;
> + bool matched;
> +};

More like drm_edid_match_closure.

> +
> #define LEVEL_DMT 0
> #define LEVEL_GTF 1
> #define LEVEL_GTF2 2
> @@ -5455,6 +5460,77 @@ drm_parse_hdmi_vsdb_audio(struct drm_connector *connector, const u8 *db)
> connector->audio_latency[0], connector->audio_latency[1]);
> }
>
> +static void
> +match_identity(const struct detailed_timing *timing, void *data)
> +{
> + struct drm_edid_ident_closure *closure = data;
> + unsigned int i, j;
> + const char *str = closure->ident->name;
> + unsigned int buflen = strlen(str);
> + unsigned int size = ARRAY_SIZE(timing->data.other_data.data.str.str);
> +
> + if (buflen > size ||
> + !(is_display_descriptor(timing, EDID_DETAIL_MONITOR_NAME) ||
> + is_display_descriptor(timing, EDID_DETAIL_MONITOR_STRING)))
> + return;
> +
> + for (i = 0; i < buflen; i++) {
> + char c = timing->data.other_data.data.str.str[i];
> +
> + if (c != str[i] || c == '\n')
> + break;
> + }
> +
> + if (i == buflen) {

This will never be true.

> + /* Allow trailing white spaces. */
> + for (j = i; j < size; j++) {
> + char c = timing->data.other_data.data.str.str[j];
> +
> + if (c == '\n') {
> + closure->matched = true;
> + return;
> + } else if (c != ' ') {
> + break;
> + }
> + }
> + if (j == size) {
> + closure->matched = true;
> + return;
> + }
> + }

Please let's use strcmp and friends instead of reinventing our own:

const char *name = closure->ident->name;
int name_len = strlen(name);
const char *desc = timing->data.other_data.data.str.str;
int desc_len = ARRAY_SIZE(timing->data.other_data.data.str.str);

if (name_len > desc_len)
return;

if (strncmp(name, desc, name_en))
return;

for (i = name_len; i < desc_len; i++) {
if (!isspace(desc[i]) && !desc[i])
return;
}

closure->matched = true;


> +}
> +
> +/**
> + * drm_edid_match_identity - match drm_edid with given identity
> + * @drm_edid: EDID
> + * @ident: the EDID identity to match with
> + *
> + * Check if the EDID matches with the given identity.
> + *
> + * Return: True if the given identity matched with EDID, false otherwise.
> + */
> +bool drm_edid_match_identity(const struct drm_edid *drm_edid,
> + const struct drm_edid_ident *ident)

Can we please just call this drm_edid_match()? Is the _identity in the
name somehow helpful?

> +{
> + if (!drm_edid || edid_extract_panel_id(drm_edid->edid) != ident->panel_id)
> + return false;

Side note, edid_extract_panel_id() could now be made to take struct
drm_edid.

> +
> + /* Match with name only if it's not NULL. */
> + if (ident->name) {
> + struct drm_edid_ident_closure closure = {
> + .ident = ident,
> + .matched = false,
> + };
> +
> + drm_for_each_detailed_block(drm_edid, match_identity, &closure);
> +
> + return closure.matched;
> + }
> +
> + return true;
> +}
> +EXPORT_SYMBOL(drm_edid_match_identity);
> +
> static void
> monitor_name(const struct detailed_timing *timing, void *data)
> {
> diff --git a/include/drm/drm_edid.h b/include/drm/drm_edid.h
> index 9686a7cee6a6..01825a8954b6 100644
> --- a/include/drm/drm_edid.h
> +++ b/include/drm/drm_edid.h
> @@ -312,6 +312,12 @@ struct edid {
> u8 checksum;
> } __packed;
>
> +/* EDID matching */
> +struct drm_edid_ident {
> + u32 panel_id;
> + const char *name;
> +};
> +
> #define EDID_PRODUCT_ID(e) ((e)->prod_code[0] | ((e)->prod_code[1] << 8))
>
> /* Short Audio Descriptor */
> @@ -412,6 +418,8 @@ struct edid *drm_get_edid(struct drm_connector *connector,
> 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);
> +bool drm_edid_match_identity(const struct drm_edid *drm_edid,
> + const struct drm_edid_ident *ident);
> struct edid *drm_get_edid_switcheroo(struct drm_connector *connector,
> struct i2c_adapter *adapter);
> struct edid *drm_edid_duplicate(const struct edid *edid);

--
Jani Nikula, Intel

2024-03-06 18:49:29

by Hsin-Yi Wang

[permalink] [raw]
Subject: Re: [PATCH v4 4/5] drm/panel-edp: Match edp_panels with panel identity

On Wed, Mar 6, 2024 at 1:23 AM Jani Nikula <[email protected]> wrote:
>
> On Tue, 05 Mar 2024, Hsin-Yi Wang <[email protected]> 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 identity, which contains both
> > panel id and panel name. If not found, match with panel id only.
>
> Do you want to start matching also with name, for all panels? That's
> totally up to you, but that's the big functional change here.
>

It might be difficult to find all the datasheets for all the panels to
verify the names. Also, some of the names in the panels are also
marked as "Unknown", so I think we still want to keep the matching
with id only.

Without really testing on the exact panel, I'm afraid that this might
break them.


> BR,
> Jani.
>
> >
> > Signed-off-by: Hsin-Yi Wang <[email protected]>
> > ---
> > v3->v4: combine name and id to identity.
> > ---
> > drivers/gpu/drm/panel/panel-edp.c | 45 ++++++++++++++++---------------
> > 1 file changed, 24 insertions(+), 21 deletions(-)
> >
> > diff --git a/drivers/gpu/drm/panel/panel-edp.c b/drivers/gpu/drm/panel/panel-edp.c
> > index d094cfc43da8..fb70e97a2e71 100644
> > --- a/drivers/gpu/drm/panel/panel-edp.c
> > +++ b/drivers/gpu/drm/panel/panel-edp.c
> > @@ -210,15 +210,12 @@ struct panel_desc {
> > * struct edp_panel_entry - Maps panel ID to delay / panel name.
> > */
> > struct edp_panel_entry {
> > - /** @panel_id: 32-bit ID for panel, encoded with drm_edid_encode_panel_id(). */
> > - u32 panel_id;
> > + /** @ident: edid identity used for panel matching. */
> > + const struct drm_edid_ident ident;
> >
> > /** @delay: The power sequencing delays needed for this panel. */
> > const struct panel_delay *delay;
> >
> > - /** @name: Name of this panel (for printing to logs). */
> > - const char *name;
> > -
> > /** @override_edid_mode: Override the mode obtained by edid. */
> > const struct drm_display_mode *override_edid_mode;
> > };
> > @@ -691,7 +688,7 @@ static int detected_panel_show(struct seq_file *s, void *data)
> > else if (!p->detected_panel)
> > seq_puts(s, "HARDCODED\n");
> > else
> > - seq_printf(s, "%s\n", p->detected_panel->name);
> > + seq_printf(s, "%s\n", p->detected_panel->ident.name);
> >
> > return 0;
> > }
> > @@ -761,7 +758,7 @@ 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 const struct edp_panel_entry *find_edp_panel(u32 panel_id, const struct drm_edid *edid);
> >
> > static int generic_edp_panel_probe(struct device *dev, struct panel_edp *panel)
> > {
> > @@ -799,7 +796,6 @@ static int generic_edp_panel_probe(struct device *dev, struct panel_edp *panel)
> > 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;
> > @@ -807,7 +803,9 @@ static int generic_edp_panel_probe(struct device *dev, struct panel_edp *panel)
> > }
> > 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, base_block);
> > +
> > + drm_edid_free(base_block);
> >
> > /*
> > * We're using non-optimized timings and want it really obvious that
> > @@ -840,7 +838,7 @@ static int generic_edp_panel_probe(struct device *dev, struct panel_edp *panel)
> > panel->detected_panel = ERR_PTR(-EINVAL);
> > } else {
> > dev_info(dev, "Detected %s %s (%#06x)\n",
> > - vend, panel->detected_panel->name, product_id);
> > + vend, panel->detected_panel->ident.name, product_id);
> >
> > /* Update the delay; everything else comes from EDID */
> > desc->delay = *panel->detected_panel->delay;
> > @@ -1930,17 +1928,21 @@ static const struct panel_delay delay_200_500_e50_po2e200 = {
> >
> > #define EDP_PANEL_ENTRY(vend_chr_0, vend_chr_1, vend_chr_2, product_id, _delay, _name) \
> > { \
> > - .name = _name, \
> > - .panel_id = drm_edid_encode_panel_id(vend_chr_0, vend_chr_1, vend_chr_2, \
> > - product_id), \
> > + .ident = { \
> > + .name = _name, \
> > + .panel_id = drm_edid_encode_panel_id(vend_chr_0, vend_chr_1, vend_chr_2, \
> > + product_id), \
> > + }, \
> > .delay = _delay \
> > }
> >
> > #define EDP_PANEL_ENTRY2(vend_chr_0, vend_chr_1, vend_chr_2, product_id, _delay, _name, _mode) \
> > { \
> > - .name = _name, \
> > - .panel_id = drm_edid_encode_panel_id(vend_chr_0, vend_chr_1, vend_chr_2, \
> > - product_id), \
> > + .ident = { \
> > + .name = _name, \
> > + .panel_id = drm_edid_encode_panel_id(vend_chr_0, vend_chr_1, vend_chr_2, \
> > + product_id), \
> > + }, \
> > .delay = _delay, \
> > .override_edid_mode = _mode \
> > }
> > @@ -2087,15 +2089,16 @@ static const struct edp_panel_entry edp_panels[] = {
> > { /* sentinal */ }
> > };
> >
> > -static const struct edp_panel_entry *find_edp_panel(u32 panel_id)
> > +static const struct edp_panel_entry *find_edp_panel(u32 panel_id, const struct drm_edid *edid)
> > {
> > const struct edp_panel_entry *panel;
> >
> > - if (!panel_id)
> > - return NULL;
> > + for (panel = edp_panels; panel->ident.panel_id; panel++)
> > + if (drm_edid_match_identity(edid, &panel->ident))
> > + return panel;
> >
> > - for (panel = edp_panels; panel->panel_id; panel++)
> > - if (panel->panel_id == panel_id)
> > + for (panel = edp_panels; panel->ident.panel_id; panel++)
> > + if (panel->ident.panel_id == panel_id)
> > return panel;
> >
> > return NULL;
>
> --
> Jani Nikula, Intel

2024-03-06 19:09:10

by Hsin-Yi Wang

[permalink] [raw]
Subject: Re: [PATCH v4 2/5] drm/edid: Add a function to match EDID with identity

On Wed, Mar 6, 2024 at 1:17 AM Jani Nikula <[email protected]> wrote:
>
> On Tue, 05 Mar 2024, Hsin-Yi Wang <[email protected]> wrote:
> > Create a type drm_edid_ident as the identity of an EDID. Currently it
> > contains panel id and monitor name.
> >
> > Create a function that can match a given EDID and an identity:
> > 1. Reject if the panel id doesn't match.
> > 2. If name is not null in identity, try to match it in the detailed timing
> > blocks. Note that some panel vendors put the monitor name after
> > EDID_DETAIL_MONITOR_STRING.
> >
> > Signed-off-by: Hsin-Yi Wang <[email protected]>
> > ---
> > v3->v4:
> > 1. add a type drm_edid_ident
> > 2. match name -> match identity. Modify function to use edid iterators.
> > ---
> > drivers/gpu/drm/drm_edid.c | 76 ++++++++++++++++++++++++++++++++++++++
> > include/drm/drm_edid.h | 8 ++++
> > 2 files changed, 84 insertions(+)
> >
> > diff --git a/drivers/gpu/drm/drm_edid.c b/drivers/gpu/drm/drm_edid.c
> > index f9e09f327f81..5e7e69e0e345 100644
> > --- a/drivers/gpu/drm/drm_edid.c
> > +++ b/drivers/gpu/drm/drm_edid.c
> > @@ -102,6 +102,11 @@ struct detailed_mode_closure {
> > int modes;
> > };
> >
> > +struct drm_edid_ident_closure {
> > + const struct drm_edid_ident *ident;
> > + bool matched;
> > +};
>
> More like drm_edid_match_closure.
>
> > +
> > #define LEVEL_DMT 0
> > #define LEVEL_GTF 1
> > #define LEVEL_GTF2 2
> > @@ -5455,6 +5460,77 @@ drm_parse_hdmi_vsdb_audio(struct drm_connector *connector, const u8 *db)
> > connector->audio_latency[0], connector->audio_latency[1]);
> > }
> >
> > +static void
> > +match_identity(const struct detailed_timing *timing, void *data)
> > +{
> > + struct drm_edid_ident_closure *closure = data;
> > + unsigned int i, j;
> > + const char *str = closure->ident->name;
> > + unsigned int buflen = strlen(str);
> > + unsigned int size = ARRAY_SIZE(timing->data.other_data.data.strstr);
> > +
> > + if (buflen > size ||
> > + !(is_display_descriptor(timing, EDID_DETAIL_MONITOR_NAME) ||
> > + is_display_descriptor(timing, EDID_DETAIL_MONITOR_STRING)))
> > + return;
> > +
> > + for (i = 0; i < buflen; i++) {
> > + char c = timing->data.other_data.data.str.str[i];
> > +
> > + if (c != str[i] || c == '\n')
> > + break;
> > + }
> > +
> > + if (i == buflen) {
>
> This will never be true.

It should be

for (i = 0; i < buflen; i++) {
..
}

if (i==buflen) {
..
}

But okay we can use strcmp.

>
> > + /* Allow trailing white spaces. */
> > + for (j = i; j < size; j++) {
> > + char c = timing->data.other_data.data.str.str[j];
> > +
> > + if (c == '\n') {
> > + closure->matched = true;
> > + return;
> > + } else if (c != ' ') {
> > + break;
> > + }
> > + }
> > + if (j == size) {
> > + closure->matched = true;
> > + return;
> > + }
> > + }
>
> Please let's use strcmp and friends instead of reinventing our own:
>
> const char *name = closure->ident->name;
> int name_len = strlen(name);
> const char *desc = timing->data.other_data.data.str.str;
> int desc_len = ARRAY_SIZE(timing->data.other_data.data.str.str);
>
> if (name_len > desc_len)
> return;
>
> if (strncmp(name, desc, name_en))
> return;
>
> for (i = name_len; i < desc_len; i++) {
> if (!isspace(desc[i]) && !desc[i])
> return;
> }
>
> closure->matched = true;
>
>
> > +}
> > +
> > +/**
> > + * drm_edid_match_identity - match drm_edid with given identity
> > + * @drm_edid: EDID
> > + * @ident: the EDID identity to match with
> > + *
> > + * Check if the EDID matches with the given identity.
> > + *
> > + * Return: True if the given identity matched with EDID, false otherwise.
> > + */
> > +bool drm_edid_match_identity(const struct drm_edid *drm_edid,
> > + const struct drm_edid_ident *ident)
>
> Can we please just call this drm_edid_match()? Is the _identity in the
> name somehow helpful?
>
> > +{
> > + if (!drm_edid || edid_extract_panel_id(drm_edid->edid) != ident->panel_id)
> > + return false;
>
> Side note, edid_extract_panel_id() could now be made to take struct
> drm_edid.
>
> > +
> > + /* Match with name only if it's not NULL. */
> > + if (ident->name) {
> > + struct drm_edid_ident_closure closure = {
> > + .ident = ident,
> > + .matched = false,
> > + };
> > +
> > + drm_for_each_detailed_block(drm_edid, match_identity, &closure);
> > +
> > + return closure.matched;
> > + }
> > +
> > + return true;
> > +}
> > +EXPORT_SYMBOL(drm_edid_match_identity);
> > +
> > static void
> > monitor_name(const struct detailed_timing *timing, void *data)
> > {
> > diff --git a/include/drm/drm_edid.h b/include/drm/drm_edid.h
> > index 9686a7cee6a6..01825a8954b6 100644
> > --- a/include/drm/drm_edid.h
> > +++ b/include/drm/drm_edid.h
> > @@ -312,6 +312,12 @@ struct edid {
> > u8 checksum;
> > } __packed;
> >
> > +/* EDID matching */
> > +struct drm_edid_ident {
> > + u32 panel_id;
> > + const char *name;
> > +};
> > +
> > #define EDID_PRODUCT_ID(e) ((e)->prod_code[0] | ((e)->prod_code[1] << 8))
> >
> > /* Short Audio Descriptor */
> > @@ -412,6 +418,8 @@ struct edid *drm_get_edid(struct drm_connector *connector,
> > 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);
> > +bool drm_edid_match_identity(const struct drm_edid *drm_edid,
> > + const struct drm_edid_ident *ident);
> > struct edid *drm_get_edid_switcheroo(struct drm_connector *connector,
> > struct i2c_adapter *adapter);
> > struct edid *drm_edid_duplicate(const struct edid *edid);
>
> --
> Jani Nikula, Intel