[PATCH i-g-t v7 23/48] lib/unigraf: Introduce input configuration

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

As multiple input can be present on unigraf devices, add a configuration
field to select the proper input. By default it will take the first
available.

The configuration can look like:

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

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

diff --git a/lib/unigraf/unigraf.c b/lib/unigraf/unigraf.c
index 614484044398..ec351ebbd89c 100644
--- a/lib/unigraf/unigraf.c
+++ b/lib/unigraf/unigraf.c
@@ -41,11 +41,21 @@ static char *unigraf_connector_name;
*/
#define UNIGRAF_CONFIG_DEVICE_ROLE "Role"

+/**
+ * UNIGRAF_CONFIG_INPUT_NAME - Key of the input name in the configuration file
+ */
+#define UNIGRAF_CONFIG_INPUT_NAME "Input"
+
/**
* 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"

+/**
+ * UNIGRAF_DEFAULT_INPUT_NAME - Default input name to search on the unigraf device
+ */
+#define UNIGRAF_DEFAULT_INPUT_NAME "DP RX"
+
static void unigraf_close_device(void)
{
if (!unigraf_device)
@@ -125,6 +135,22 @@ static int unigraf_find_role(const char *request)
return -ENODEV;
}

+static int unigraf_find_input(const char *request)
+{
+ int role_count = unigraf_assert(TSIX_VIN_GetInputCount(unigraf_device));
+
+ for (int i = 0; i < role_count; i++) {
+ char input_name[UNIGRAF_NAME_MAX] = "";
+
+ unigraf_assert(TSIX_VIN_GetInputName(unigraf_device, i,
+ input_name, UNIGRAF_NAME_MAX));
+ unigraf_debug("Input %d: %s\n", i, input_name);
+ if (!strncmp(input_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
@@ -139,10 +165,11 @@ bool unigraf_open_device(int drm_fd)
GError *cfg_error = NULL;
char *cfg_device = NULL;
char *cfg_role = NULL;
+ char *cfg_input = NULL;
int device_count;
int chosen_device;
int chosen_role;
- int chosen_input = 0;
+ int chosen_input;

assert(igt_can_fail());

@@ -166,6 +193,14 @@ bool unigraf_open_device(int drm_fd)
unigraf_debug("No device role configured.\n");
cfg_role = NULL;
}
+
+ cfg_error = NULL;
+ cfg_input = g_key_file_get_string(igt_key_file, UNIGRAF_CONFIG_GROUP,
+ UNIGRAF_CONFIG_INPUT_NAME, &cfg_error);
+ if (cfg_error) {
+ unigraf_debug("No input name configured.\n");
+ cfg_input = NULL;
+ }
}

unigraf_assert(TSIX_DEV_RescanDevices(0, TSI_DEVCAP_VIDEO_CAPTURE, 0));
@@ -210,6 +245,25 @@ bool unigraf_open_device(int drm_fd)
}

unigraf_assert(TSIX_DEV_SelectRole(unigraf_device, chosen_role));
+
+ if (!cfg_input) {
+ unigraf_debug("No input configured, trying " UNIGRAF_DEFAULT_INPUT_NAME "\n");
+ chosen_input = unigraf_find_input(UNIGRAF_DEFAULT_INPUT_NAME);
+ if (chosen_input < 0) {
+ char input_name[UNIGRAF_NAME_MAX];
+
+ chosen_input = 0;
+ unigraf_assert(TSIX_VIN_GetInputName(unigraf_device, chosen_input,
+ input_name, UNIGRAF_NAME_MAX));
+ unigraf_debug("Input " UNIGRAF_DEFAULT_INPUT_NAME " not found, using input 0 (%s).\n",
+ input_name);
+ }
+ } else {
+ chosen_input = unigraf_find_input(cfg_input);
+ igt_assert_f(chosen_input >= 0, "TSI:%p: Input %s not found.",
+ unigraf_device, cfg_input);
+ }
+
unigraf_assert(TSIX_VIN_Select(unigraf_device, chosen_input));
unigraf_assert(TSIX_VIN_Enable(unigraf_device, chosen_input));

--
2.52.0