[PATCH i-g-t v7 22/48] lib/unigraf: Introduce role configuration

Louis Chauvet
2026-02-23T12:09:13Z

Some unigraf devices, like the UCD-500 can have multiple hardware
configurations: displayport input/output, usbc input/output.

The device configuration can look like:

[Unigraf]
Device=UCD-500 [2434C620]
Role=DisplayPort Source and Sink

Reviewed-by: Luca Ceresoli <luca.ceresoli@bootlin.com>
Signed-off-by: Louis Chauvet <louis.chauvet@bootlin.com>
---
lib/unigraf/unigraf.c | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 56 insertions(+), 1 deletion(-)

diff --git a/lib/unigraf/unigraf.c b/lib/unigraf/unigraf.c
index ec709a55c106..614484044398 100644
--- a/lib/unigraf/unigraf.c
+++ b/lib/unigraf/unigraf.c
@@ -7,6 +7,7 @@
*/

#include "igt_core.h"
+#include <asm-generic/errno-base.h>
#include <stdint.h>

#include "unigraf.h"
@@ -35,6 +36,16 @@ static char *unigraf_connector_name;
*/
#define UNIGRAF_CONFIG_DEVICE_NAME "Device"

+/**
+ * UNIGRAF_CONFIG_DEVICE_ROLE - Key of the device role in the configuration file
+ */
+#define UNIGRAF_CONFIG_DEVICE_ROLE "Role"
+
+/**
+ * UNIGRAF_DEFAULT_ROLE_NAME - Default role name to search on the unigraf device
+ */
+#define UNIGRAF_DEFAULT_ROLE_NAME "USB-C, DP Alt Mode Source and Sink"
+
static void unigraf_close_device(void)
{
if (!unigraf_device)
@@ -97,6 +108,23 @@ static int unigraf_find_device(char *request)
return -ENODEV;
}

+static int unigraf_find_role(const char *request)
+{
+ int role_count = unigraf_assert(TSIX_DEV_GetDeviceRoleCount(unigraf_device));
+
+ for (int i = 0; i < role_count; i++) {
+ char role_name[UNIGRAF_NAME_MAX] = "";
+
+ unigraf_assert(TSIX_DEV_GetDeviceRoleName(unigraf_device, i,
+ role_name,
+ UNIGRAF_NAME_MAX));
+ unigraf_debug("Role %d: %s\n", i, role_name);
+ if (!strncmp(role_name, request, UNIGRAF_NAME_MAX))
+ return i;
+ }
+ return -ENODEV;
+}
+
/**
* unigraf_open_device() - Search and open a device.
* @drm_fd: File descriptor of the currently used drm device
@@ -110,9 +138,10 @@ bool unigraf_open_device(int drm_fd)
TSI_RESULT r;
GError *cfg_error = NULL;
char *cfg_device = NULL;
+ char *cfg_role = NULL;
int device_count;
int chosen_device;
- int chosen_role = 0;
+ int chosen_role;
int chosen_input = 0;

assert(igt_can_fail());
@@ -129,6 +158,14 @@ bool unigraf_open_device(int drm_fd)
unigraf_debug("No device name configured, uses first device available.\n");
cfg_device = NULL;
}
+
+ cfg_error = NULL;
+ cfg_role = g_key_file_get_string(igt_key_file, UNIGRAF_CONFIG_GROUP,
+ UNIGRAF_CONFIG_DEVICE_ROLE, &cfg_error);
+ if (cfg_error) {
+ unigraf_debug("No device role configured.\n");
+ cfg_role = NULL;
+ }
}

unigraf_assert(TSIX_DEV_RescanDevices(0, TSI_DEVCAP_VIDEO_CAPTURE, 0));
@@ -154,6 +191,24 @@ bool unigraf_open_device(int drm_fd)
igt_assert(unigraf_device);
unigraf_debug("Successfully opened the unigraf device %d.\n", chosen_device);

+ if (!cfg_role) {
+ unigraf_debug("No role configured, trying " UNIGRAF_DEFAULT_ROLE_NAME "\n");
+ chosen_role = unigraf_find_role(UNIGRAF_DEFAULT_ROLE_NAME);
+ if (chosen_role < 0) {
+ char role_name[UNIGRAF_NAME_MAX];
+
+ chosen_role = 0;
+ unigraf_assert(TSIX_DEV_GetDeviceRoleName(unigraf_device, chosen_role,
+ role_name, UNIGRAF_NAME_MAX));
+ unigraf_debug("Role " UNIGRAF_DEFAULT_ROLE_NAME " not found, using role 0 (%s)\n",
+ role_name);
+ }
+ } else {
+ chosen_role = unigraf_find_role(cfg_role);
+ igt_assert_f(chosen_role >= 0, "TSI:%p: Role %s not found.",
+ unigraf_device, cfg_role);
+ }
+
unigraf_assert(TSIX_DEV_SelectRole(unigraf_device, chosen_role));
unigraf_assert(TSIX_VIN_Select(unigraf_device, chosen_input));
unigraf_assert(TSIX_VIN_Enable(unigraf_device, chosen_input));

--
2.52.0