From: Ville Syrjälä <[email protected]>
Add drm_edid_get_displayid_product_id() as the DisplayID based
counterpart to the already existing EDID base block based
drm_edid_get_product_id().
In DisplayID the information is stored in the "Product ID"
block (0x00 or 0x20). The layout is slightly different to the
EDID one as the vendor ID is a three byte OUI isntead of
the compressed ASCII EISA/PNPID of EDID. The "year of
manufacture" is now relative to the year 2000, as opposed
to 1990 for EDID.
There is also a product ID string, but I decided to leave that
out from the user visible struct because the variable length
would just complicate things.
v2: Call it drm_edid_get_displayid_product_id() (Jani)
Return an error to indicate what happened (Jani)
Reviewed-by: Jani Nikula <[email protected]>
Signed-off-by: Ville Syrjälä <[email protected]>
---
drivers/gpu/drm/drm_displayid_internal.h | 11 +++++
drivers/gpu/drm/drm_edid.c | 56 ++++++++++++++++++++++++
include/drm/drm_edid.h | 10 +++++
3 files changed, 77 insertions(+)
diff --git a/drivers/gpu/drm/drm_displayid_internal.h
b/drivers/gpu/drm/drm_displayid_internal.h
index ef7e6c9bd4db..2177c19cae4c 100644
--- a/drivers/gpu/drm/drm_displayid_internal.h
+++ b/drivers/gpu/drm/drm_displayid_internal.h
@@ -103,6 +103,17 @@ struct displayid_block {
u8 num_bytes;
} __packed;
+struct displayid_product_id_block {
+ struct displayid_block base;
+ u8 vendor_id[3];
+ __le16 product_code;
+ __le32 serial_number;
+ u8 week_of_manufacture;
+ u8 year_of_manufacture;
+ u8 size_of_product_id_string;
+ u8 product_id_string[];
+} __packed;
+
struct displayid_tiled_block {
struct displayid_block base;
u8 tile_cap;
diff --git a/drivers/gpu/drm/drm_edid.c b/drivers/gpu/drm/drm_edid.c
index b8f882a17c8f..8faec57f70d1 100644
--- a/drivers/gpu/drm/drm_edid.c
+++ b/drivers/gpu/drm/drm_edid.c
@@ -2791,6 +2791,62 @@ void drm_edid_get_product_id(const struct drm_edid
*drm_edid,
}
EXPORT_SYMBOL(drm_edid_get_product_id);
+static bool displayid_is_product_id_block(const struct displayid_iter *iter,
+ const struct displayid_block *block)
+{
+ return (displayid_version(iter) < DISPLAY_ID_STRUCTURE_VER_20 &&
+ block->tag == DATA_BLOCK_PRODUCT_ID) ||
+ (displayid_version(iter) == DISPLAY_ID_STRUCTURE_VER_20 &&
+ block->tag == DATA_BLOCK_2_PRODUCT_ID);
+}
+
+/**
+ * drm_edid_get_displayid_product_id - Get the vendor and product
identification from DisplayID
+ * @drm_edid: EDID
+ * @id: Where to place the product id
+ *
+ * Return: Zero on success, or a negative errno code otherwise.
+ */
+int drm_edid_get_displayid_product_id(const struct drm_edid *drm_edid,
+ struct drm_displayid_product_id *id)
+{
+ const struct displayid_block *block;
+ struct displayid_iter iter;
+ int ret = -ENOENT;
+
+ memset(id, 0, sizeof(*id));
+
+ if (!drm_edid)
+ return -EINVAL;
+
+ displayid_iter_edid_begin(drm_edid, &iter);
+ displayid_iter_for_each(block, &iter) {
+ const struct displayid_product_id_block *prod_id =
+ (struct displayid_product_id_block *)block;
+
+ if (!displayid_is_product_id_block(&iter, block))
+ continue;
+
+ if (block->num_bytes < sizeof(*prod_id) - sizeof(prod_id->base))
+ continue;
+
+ id->vendor_id[0] = prod_id->vendor_id[0];
+ id->vendor_id[1] = prod_id->vendor_id[1];
+ id->vendor_id[2] = prod_id->vendor_id[2];
+ id->product_code = prod_id->product_code;
+ id->serial_number = prod_id->serial_number;
+ id->week_of_manufacture = prod_id->week_of_manufacture;
+ id->year_of_manufacture = prod_id->year_of_manufacture;
+
+ ret = 0;
+ break;
+ }
+ displayid_iter_end(&iter);
+
+ return ret;
+}
+EXPORT_SYMBOL(drm_edid_get_displayid_product_id);
+
static void decode_date(struct seq_buf *s, const struct drm_edid_product_id
*id)
{
int week = id->week_of_manufacture;
diff --git a/include/drm/drm_edid.h b/include/drm/drm_edid.h
index a2617aa34edf..a4e5366b53ad 100644
--- a/include/drm/drm_edid.h
+++ b/include/drm/drm_edid.h
@@ -288,6 +288,14 @@ struct drm_edid_product_id {
u8 year_of_manufacture;
} __packed;
+struct drm_displayid_product_id {
+ u8 vendor_id[3];
+ __le16 product_code;
+ __le32 serial_number;
+ u8 week_of_manufacture;
+ u8 year_of_manufacture;
+} __packed;
+
struct edid {
u8 header[8];
/* Vendor & product info */
@@ -484,6 +492,8 @@ int drm_edid_connector_add_modes(struct drm_connector
*connector);
bool drm_edid_is_digital(const struct drm_edid *drm_edid);
void drm_edid_get_product_id(const struct drm_edid *drm_edid,
struct drm_edid_product_id *id);
+int drm_edid_get_displayid_product_id(const struct drm_edid *drm_edid,
+ struct drm_displayid_product_id *id);
void drm_edid_print_product_id(struct drm_printer *p,
const struct drm_edid_product_id *id, bool raw);
u32 drm_edid_get_panel_id(const struct drm_edid *drm_edid);
--
2.56.1