[4/7] drm/sysfs: Add mstpath attribute to connector devices
diff mbox series

Message ID 1558019883-12397-5-git-send-email-sunpeng.li@amd.com
State New
Headers show
Series
  • Add DP MST AUX devices
Related show

Commit Message

Leo May 16, 2019, 3:18 p.m. UTC
From: Leo Li <sunpeng.li@amd.com>

This can be used to create more descriptive symlinks for MST aux
devices. Consider the following udev rule:

SUBSYSTEM=="drm_dp_aux_dev", SUBSYSTEMS=="drm", ATTRS{mstpath}=="?*",
	SYMLINK+="drm_dp_aux/by-path/$attr{mstpath}"

The following symlinks will be created (depending on your MST topology):

$ ls /dev/drm_dp_aux/by-path/
card0-mst:0-1  card0-mst:0-1-1  card0-mst:0-1-8  card0-mst:0-8

Cc: Ville Syrjälä <ville.syrjala@linux.intel.com>
Cc: Lyude Paul <lyude@redhat.com>
Signed-off-by: Leo Li <sunpeng.li@amd.com>
---
 drivers/gpu/drm/drm_sysfs.c | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

Patch
diff mbox series

diff --git a/drivers/gpu/drm/drm_sysfs.c b/drivers/gpu/drm/drm_sysfs.c
index ecb7b33..e000e0c 100644
--- a/drivers/gpu/drm/drm_sysfs.c
+++ b/drivers/gpu/drm/drm_sysfs.c
@@ -229,16 +229,39 @@  static ssize_t modes_show(struct device *device,
 	return written;
 }
 
+static ssize_t mstpath_show(struct device *device,
+			    struct device_attribute *attr,
+			    char *buf)
+{
+	struct drm_connector *connector = to_drm_connector(device);
+	ssize_t ret = 0;
+	char *path;
+
+	mutex_lock(&connector->dev->mode_config.mutex);
+	if (!connector->path_blob_ptr)
+		goto unlock;
+
+	path = connector->path_blob_ptr->data;
+	ret = snprintf(buf, PAGE_SIZE, "card%d-%s\n",
+	               connector->dev->primary->index, path);
+
+unlock:
+	mutex_unlock(&connector->dev->mode_config.mutex);
+	return ret;
+}
+
 static DEVICE_ATTR_RW(status);
 static DEVICE_ATTR_RO(enabled);
 static DEVICE_ATTR_RO(dpms);
 static DEVICE_ATTR_RO(modes);
+static DEVICE_ATTR_RO(mstpath);
 
 static struct attribute *connector_dev_attrs[] = {
 	&dev_attr_status.attr,
 	&dev_attr_enabled.attr,
 	&dev_attr_dpms.attr,
 	&dev_attr_modes.attr,
+	&dev_attr_mstpath.attr,
 	NULL
 };