1 From 3aa1f2477545ea6298bc6f2d7ffae68f090af9b8 Mon Sep 17 00:00:00 2001
2 From: Dave Stevenson <dave.stevenson@raspberrypi.com>
3 Date: Thu, 28 Sep 2023 18:27:09 +0100
4 Subject: [PATCH] drm: Look for an alias for the displays to use as the DRM
7 Allow DT aliases of eg DSI2 to force make DRM allocate the
8 display with the requested name.
10 Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
12 drivers/gpu/drm/drm_connector.c | 60 ++++++++++++++++++++++++++++++---
13 1 file changed, 56 insertions(+), 4 deletions(-)
15 --- a/drivers/gpu/drm/drm_connector.c
16 +++ b/drivers/gpu/drm/drm_connector.c
17 @@ -81,6 +81,7 @@ struct drm_conn_prop_enum_list {
25 @@ -110,12 +111,41 @@ static struct drm_conn_prop_enum_list dr
26 { DRM_MODE_CONNECTOR_USB, "USB" },
29 +#define MAX_DT_NODE_NAME_LEN 20
30 +#define DT_DRM_NODE_PREFIX "drm_"
32 +static void drm_connector_get_of_name(int type, char *node_name, int length)
36 + strcpy(node_name, DT_DRM_NODE_PREFIX);
39 + node_name[i + strlen(DT_DRM_NODE_PREFIX)] =
40 + tolower(drm_connector_enum_list[type].name[i]);
42 + } while (drm_connector_enum_list[type].name[i++] &&
45 + node_name[length - 1] = '\0';
48 void drm_connector_ida_init(void)
52 + char node_name[MAX_DT_NODE_NAME_LEN];
54 - for (i = 0; i < ARRAY_SIZE(drm_connector_enum_list); i++)
55 + for (i = 0; i < ARRAY_SIZE(drm_connector_enum_list); i++) {
56 ida_init(&drm_connector_enum_list[i].ida);
58 + drm_connector_get_of_name(i, node_name, MAX_DT_NODE_NAME_LEN);
60 + id = of_alias_get_highest_id(node_name);
62 + drm_connector_enum_list[i].first_dyn_num = id + 1;
64 + drm_connector_enum_list[i].first_dyn_num = 1;
68 void drm_connector_ida_destroy(void)
69 @@ -222,7 +252,9 @@ static int __drm_connector_init(struct d
70 struct i2c_adapter *ddc)
72 struct drm_mode_config *config = &dev->mode_config;
73 + char node_name[MAX_DT_NODE_NAME_LEN];
76 struct ida *connector_ida =
77 &drm_connector_enum_list[connector_type].ida;
79 @@ -252,8 +284,28 @@ static int __drm_connector_init(struct d
82 connector->connector_type = connector_type;
83 - connector->connector_type_id =
84 - ida_alloc_min(connector_ida, 1, GFP_KERNEL);
85 + connector->connector_type_id = 0;
87 + drm_connector_get_of_name(connector_type, node_name, MAX_DT_NODE_NAME_LEN);
88 + id = of_alias_get_id(dev->dev->of_node, node_name);
90 + /* Try and allocate the requested ID
91 + * Valid range is 1 to 31, hence ignoring 0 as an error
93 + int type_id = ida_alloc_range(connector_ida, id, id, GFP_KERNEL);
96 + connector->connector_type_id = type_id;
98 + drm_err(dev, "Failed to acquire type ID %d for interface type %s, ret %d\n",
99 + id, drm_connector_enum_list[connector_type].name,
102 + if (!connector->connector_type_id)
103 + connector->connector_type_id =
104 + ida_alloc_min(connector_ida,
105 + drm_connector_enum_list[connector_type].first_dyn_num,
107 if (connector->connector_type_id < 0) {
108 ret = connector->connector_type_id;