From 50f8d517733d24fce6693ffae552f9833e2e6aa9 Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Tue, 1 Feb 2022 14:33:34 +0100 Subject: [PATCH] xf86drmMode: introduce drmModeGetConnectorTypeName User-space often needs to print the name of a connector type. When a new connector type is added, all user-space programs need to be updated to support the new connector type. Expose a function to get a connector type name in libdrm. The names are taken from the kernel [1]. [1]: https://cgit.freedesktop.org/drm/drm/tree/drivers/gpu/drm/drm_connector.c?h=4fc8cb47fcfdc93e274a1291757e478df4f9c39b#n83 Signed-off-by: Simon Ser --- core-symbols.txt | 1 + xf86drmMode.c | 53 ++++++++++++++++++++++++++++++++++++++++++++++++ xf86drmMode.h | 9 ++++++++ 3 files changed, 63 insertions(+) diff --git a/core-symbols.txt b/core-symbols.txt index 31bbcf8f..dcf90018 100644 --- a/core-symbols.txt +++ b/core-symbols.txt @@ -126,6 +126,7 @@ drmModeFreePropertyBlob drmModeFreeResources drmModeGetConnector drmModeGetConnectorCurrent +drmModeGetConnectorTypeName drmModeGetCrtc drmModeGetEncoder drmModeGetFB diff --git a/xf86drmMode.c b/xf86drmMode.c index 6b79d768..6d636dcc 100644 --- a/xf86drmMode.c +++ b/xf86drmMode.c @@ -1747,3 +1747,56 @@ drm_public void drmModeFreeFB2(drmModeFB2Ptr ptr) { drmFree(ptr); } + +drm_public const char * +drmModeGetConnectorTypeName(uint32_t connector_type) +{ + /* Keep the strings in sync with the kernel's drm_connector_enum_list in + * drm_connector.c. */ + switch (connector_type) { + case DRM_MODE_CONNECTOR_Unknown: + return "Unknown"; + case DRM_MODE_CONNECTOR_VGA: + return "VGA"; + case DRM_MODE_CONNECTOR_DVII: + return "DVI-I"; + case DRM_MODE_CONNECTOR_DVID: + return "DVI-D"; + case DRM_MODE_CONNECTOR_DVIA: + return "DVI-A"; + case DRM_MODE_CONNECTOR_Composite: + return "Composite"; + case DRM_MODE_CONNECTOR_SVIDEO: + return "SVIDEO"; + case DRM_MODE_CONNECTOR_LVDS: + return "LVDS"; + case DRM_MODE_CONNECTOR_Component: + return "Component"; + case DRM_MODE_CONNECTOR_9PinDIN: + return "DIN"; + case DRM_MODE_CONNECTOR_DisplayPort: + return "DP"; + case DRM_MODE_CONNECTOR_HDMIA: + return "HDMI-A"; + case DRM_MODE_CONNECTOR_HDMIB: + return "HDMI-B"; + case DRM_MODE_CONNECTOR_TV: + return "TV"; + case DRM_MODE_CONNECTOR_eDP: + return "eDP"; + case DRM_MODE_CONNECTOR_VIRTUAL: + return "Virtual"; + case DRM_MODE_CONNECTOR_DSI: + return "DSI"; + case DRM_MODE_CONNECTOR_DPI: + return "DPI"; + case DRM_MODE_CONNECTOR_WRITEBACK: + return "Writeback"; + case DRM_MODE_CONNECTOR_SPI: + return "SPI"; + case DRM_MODE_CONNECTOR_USB: + return "USB"; + default: + return NULL; + } +} diff --git a/xf86drmMode.h b/xf86drmMode.h index 08557642..46dc80a2 100644 --- a/xf86drmMode.h +++ b/xf86drmMode.h @@ -475,6 +475,15 @@ extern drmModeObjectListPtr drmModeGetLease(int fd); extern int drmModeRevokeLease(int fd, uint32_t lessee_id); +/** + * Get a string describing a connector type. + * + * NULL is returned if the connector type is unsupported. Callers should handle + * this gracefully, e.g. by falling back to "Unknown" or printing the raw value. + */ +extern const char * +drmModeGetConnectorTypeName(uint32_t connector_type); + #if defined(__cplusplus) } #endif