8de6c372c0702c8d22bd54ca4761c986ecc7d6fc
[openwrt/staging/neocturne.git] /
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
5 device name
6
7 Allow DT aliases of eg DSI2 to force make DRM allocate the
8 display with the requested name.
9
10 Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
11 ---
12 drivers/gpu/drm/drm_connector.c | 60 ++++++++++++++++++++++++++++++---
13 1 file changed, 56 insertions(+), 4 deletions(-)
14
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 {
18 int type;
19 const char *name;
20 struct ida ida;
21 + int first_dyn_num;
22 };
23
24 /*
25 @@ -110,12 +111,41 @@ static struct drm_conn_prop_enum_list dr
26 { DRM_MODE_CONNECTOR_USB, "USB" },
27 };
28
29 +#define MAX_DT_NODE_NAME_LEN 20
30 +#define DT_DRM_NODE_PREFIX "drm_"
31 +
32 +static void drm_connector_get_of_name(int type, char *node_name, int length)
33 +{
34 + int i = 0;
35 +
36 + strcpy(node_name, DT_DRM_NODE_PREFIX);
37 +
38 + do {
39 + node_name[i + strlen(DT_DRM_NODE_PREFIX)] =
40 + tolower(drm_connector_enum_list[type].name[i]);
41 +
42 + } while (drm_connector_enum_list[type].name[i++] &&
43 + i < length);
44 +
45 + node_name[length - 1] = '\0';
46 +}
47 +
48 void drm_connector_ida_init(void)
49 {
50 - int i;
51 + int i, id;
52 + char node_name[MAX_DT_NODE_NAME_LEN];
53
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);
57 +
58 + drm_connector_get_of_name(i, node_name, MAX_DT_NODE_NAME_LEN);
59 +
60 + id = of_alias_get_highest_id(node_name);
61 + if (id > 0)
62 + drm_connector_enum_list[i].first_dyn_num = id + 1;
63 + else
64 + drm_connector_enum_list[i].first_dyn_num = 1;
65 + }
66 }
67
68 void drm_connector_ida_destroy(void)
69 @@ -222,7 +252,9 @@ static int __drm_connector_init(struct d
70 struct i2c_adapter *ddc)
71 {
72 struct drm_mode_config *config = &dev->mode_config;
73 + char node_name[MAX_DT_NODE_NAME_LEN];
74 int ret;
75 + int id;
76 struct ida *connector_ida =
77 &drm_connector_enum_list[connector_type].ida;
78
79 @@ -252,8 +284,28 @@ static int __drm_connector_init(struct d
80 ret = 0;
81
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;
86 +
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);
89 + if (id > 0) {
90 + /* Try and allocate the requested ID
91 + * Valid range is 1 to 31, hence ignoring 0 as an error
92 + */
93 + int type_id = ida_alloc_range(connector_ida, id, id, GFP_KERNEL);
94 +
95 + if (type_id > 0)
96 + connector->connector_type_id = type_id;
97 + else
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,
100 + type_id);
101 + }
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,
106 + GFP_KERNEL);
107 if (connector->connector_type_id < 0) {
108 ret = connector->connector_type_id;
109 goto out_put_id;