[PATCH i-g-t v2 14/26] lib/unigraf: Introduce role configuration
Louis Chauvet
louis.chauvet at bootlin.com
Thu Jul 17 18:46:34 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
---
lib/unigraf/unigraf.c | 55 ++++++++++++++++++++++++++++++++++++++++++++++++---
1 file changed, 52 insertions(+), 3 deletions(-)
diff --git a/lib/unigraf/unigraf.c b/lib/unigraf/unigraf.c
index f4b6183dbacf359c5e91ea70bc3b6acb9488839a..b4401daaac5a69ef02a15ead1b8edf3f2cac3833 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)
{
@@ -90,15 +102,30 @@ static int unigraf_find_device(char *request) {
return chosen_device;
}
+static int unigraf_find_role(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(void)
{
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());
@@ -121,6 +148,7 @@ bool unigraf_open_device(void)
if(cfg_group == NULL) {
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, UNIGRAF_CONFIG_DEVICE_NAME, &cfg_error);
@@ -128,6 +156,13 @@ bool unigraf_open_device(void)
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));
@@ -153,6 +188,20 @@ bool unigraf_open_device(void)
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.0
More information about the igt-dev
mailing list