[PATCH i-g-t v3 15/29] lib/unigraf: Introduce role configuration
Louis Chauvet
louis.chauvet at bootlin.com
Sat Aug 23 02:11:35 UTC 2025
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
Signed-off-by: Louis Chauvet <louis.chauvet at bootlin.com>
---
lib/unigraf/unigraf.c | 65 ++++++++++++++++++++++++++++++++++++++++++++++++---
1 file changed, 62 insertions(+), 3 deletions(-)
diff --git a/lib/unigraf/unigraf.c b/lib/unigraf/unigraf.c
index 304567467b27a5e68cc2db6ce66b3a8b53fb87a3..0b8fe11a957b0ebaf7e9c4c4fc23b5f52c4632df 100644
--- a/lib/unigraf/unigraf.c
+++ b/lib/unigraf/unigraf.c
@@ -19,18 +19,30 @@ static TSI_HANDLE unigraf_device;
static char *unigraf_default_edid;
static char *unigraf_connector_name;
+/**
+ * UNIGRAF_NAME_MAX - Maximum name length to be used for TSI functions
+ */
+#define UNIGRAF_NAME_MAX 1024
+
/**
* UNIGRAF_CONFIG_GROUP - Name of the unigraf group in the configuration file
*/
#define UNIGRAF_CONFIG_GROUP "Unigraf"
+
/**
* UNIGRAF_CONFIG_DEVICE_NAME - Key of the device name in the configuration file
*/
#define UNIGRAF_CONFIG_DEVICE_NAME "Device"
+
/**
- * UNIGRAF_NAME_MAX - Maximum name length to be used for TSI functions
+ * UNIGRAF_CONFIG_DEVICE_ROLE - Key of the device role in the configuration file
*/
-#define UNIGRAF_NAME_MAX 1024
+#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)
{
@@ -93,15 +105,35 @@ static int unigraf_find_device(char *request)
return chosen_device;
}
+static int unigraf_find_role(const char *request)
+{
+ int chosen_role = -1;
+ int role_count = unigraf_assert(TSIX_DEV_GetDeviceRoleCount(unigraf_device));
+
+ for (int i = 0; i < role_count; i++) {
+ char role_name[UNIGRAF_NAME_MAX];
+
+ memset(role_name, 0, 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))
+ chosen_role = i;
+ }
+ return chosen_role;
+}
+
bool unigraf_open_device(int drm_fd)
{
TSI_RESULT r;
char *cfg_group = NULL;
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());
@@ -125,6 +157,7 @@ bool unigraf_open_device(int drm_fd)
if (!cfg_group) {
unigraf_debug("No device configured, will try to find the first available.\n");
cfg_device = NULL;
+ cfg_role = NULL;
unigraf_connector_name = NULL;
} else {
cfg_device = g_key_file_get_string(igt_key_file, cfg_group,
@@ -133,6 +166,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, cfg_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));
@@ -158,6 +199,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.50.1
More information about the igt-dev
mailing list