drm/edid: add drm_edid_print_product_id()
authorJani Nikula <jani.nikula@intel.com>
Tue, 9 Apr 2024 09:46:10 +0000 (12:46 +0300)
committerJani Nikula <jani.nikula@intel.com>
Mon, 15 Apr 2024 12:42:49 +0000 (15:42 +0300)
Add a function to print a decoded EDID vendor and product id to a drm
printer, optionally with the raw data.

v2:
- refactor date printing
- use seq_buf to avoid kasprintf() (Ville)
- handle week == 0 (Ville)
- use be16_to_cpu() on manufacturer_name

Cc: Ville Syrjälä <ville.syrjala@linux.intel.com>
Acked-by: Melissa Wen <mwen@igalia.com> # v1
Reviewed-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/32bbc83ee6557809ef6d7a5edb1bc8ef4d56d10f.1712655867.git.jani.nikula@intel.com
Signed-off-by: Jani Nikula <jani.nikula@intel.com>
drivers/gpu/drm/drm_edid.c
include/drm/drm_edid.h

index 626a0e24e66a089453cb65fffe75f9f925c172f8..1400722ae3fefc9083fa04f389e4527381fbc991 100644 (file)
  */
 
 #include <linux/bitfield.h>
+#include <linux/byteorder/generic.h>
 #include <linux/cec.h>
 #include <linux/hdmi.h>
 #include <linux/i2c.h>
 #include <linux/kernel.h>
 #include <linux/module.h>
 #include <linux/pci.h>
+#include <linux/seq_buf.h>
 #include <linux/slab.h>
 #include <linux/vga_switcheroo.h>
 
@@ -2771,6 +2773,48 @@ void drm_edid_get_product_id(const struct drm_edid *drm_edid,
 }
 EXPORT_SYMBOL(drm_edid_get_product_id);
 
+static void decode_date(struct seq_buf *s, const struct drm_edid_product_id *id)
+{
+       int week = id->week_of_manufacture;
+       int year = id->year_of_manufacture + 1990;
+
+       if (week == 0xff)
+               seq_buf_printf(s, "model year: %d", year);
+       else if (!week)
+               seq_buf_printf(s, "year of manufacture: %d", year);
+       else
+               seq_buf_printf(s, "week/year of manufacture: %d/%d", week, year);
+}
+
+/**
+ * drm_edid_print_product_id - Print decoded product id to printer
+ * @p: drm printer
+ * @id: EDID product id
+ * @raw: If true, also print the raw hex
+ *
+ * See VESA E-EDID 1.4 section 3.4.
+ */
+void drm_edid_print_product_id(struct drm_printer *p,
+                              const struct drm_edid_product_id *id, bool raw)
+{
+       DECLARE_SEQ_BUF(date, 40);
+       char vend[4];
+
+       drm_edid_decode_mfg_id(be16_to_cpu(id->manufacturer_name), vend);
+
+       decode_date(&date, id);
+
+       drm_printf(p, "manufacturer name: %s, product code: %u, serial number: %u, %s\n",
+                  vend, le16_to_cpu(id->product_code),
+                  le32_to_cpu(id->serial_number), seq_buf_str(&date));
+
+       if (raw)
+               drm_printf(p, "raw product id: %*ph\n", (int)sizeof(*id), id);
+
+       WARN_ON(seq_buf_has_overflowed(&date));
+}
+EXPORT_SYMBOL(drm_edid_print_product_id);
+
 /**
  * drm_edid_get_panel_id - Get a panel's ID from EDID
  * @drm_edid: EDID that contains panel ID.
index 8bdd8d54815d88801efb851522a8951263207333..8e0e323493323c989eb3bd9dfe54c4f21cd4126a 100644 (file)
@@ -30,6 +30,7 @@ struct drm_connector;
 struct drm_device;
 struct drm_display_mode;
 struct drm_edid;
+struct drm_printer;
 struct hdmi_avi_infoframe;
 struct hdmi_vendor_infoframe;
 struct i2c_adapter;
@@ -481,6 +482,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);
+void drm_edid_print_product_id(struct drm_printer *p,
+                              const struct drm_edid_product_id *id, bool raw);
 
 const u8 *drm_find_edid_extension(const struct drm_edid *drm_edid,
                                  int ext_id, int *ext_index);