[PATCH RFC v2 16/16] drm/vkms: Introduce configfs for encoder type
Louis Chauvet
louis.chauvet at bootlin.com
Fri Nov 22 17:38:42 UTC 2024
Signed-off-by: Louis Chauvet <louis.chauvet at bootlin.com>
---
drivers/gpu/drm/vkms/vkms_configfs.c | 57 ++++++++++++++++++++++++++++++++++++
1 file changed, 57 insertions(+)
diff --git a/drivers/gpu/drm/vkms/vkms_configfs.c b/drivers/gpu/drm/vkms/vkms_configfs.c
index 55bd0b9a31d35eca49c67a2fe2d58e3ea84367a4..bfd3c3a0851b2cc76da52b8a190511f22d3f9fbc 100644
--- a/drivers/gpu/drm/vkms/vkms_configfs.c
+++ b/drivers/gpu/drm/vkms/vkms_configfs.c
@@ -1,5 +1,6 @@
// SPDX-License-Identifier: GPL-2.0+
+#include "drm/drm_mode.h"
#include <linux/configfs.h>
#include <linux/mutex.h>
#include <drm/drm_print.h>
@@ -754,6 +755,61 @@ static void encoder_possible_crtcs_drop_link(struct config_item *src,
mutex_unlock(&vkms_configfs->lock);
}
+static ssize_t encoder_type_show(struct config_item *item, char *page)
+{
+ struct vkms_config_encoder *encoder;
+ char encoder_type = DRM_MODE_ENCODER_NONE;
+ struct vkms_configfs_device *vkms_configfs = encoder_item_to_vkms_configfs_device(item);
+
+ scoped_guard(mutex, &vkms_configfs->lock)
+ {
+ encoder = encoder_item_to_vkms_configfs_encoder(item)->vkms_config_encoder;
+ encoder_type = encoder->type;
+ }
+
+ return sprintf(page, "%u", encoder_type);
+}
+
+static ssize_t encoder_type_store(struct config_item *item,
+ const char *page, size_t count)
+{
+ struct vkms_configfs_device *vkms_configfs = encoder_item_to_vkms_configfs_device(item);
+ int val = DRM_MODE_ENCODER_VIRTUAL;
+ struct vkms_config_encoder *encoder;
+ int ret;
+
+ ret = kstrtouint(page, 10, &val);
+ if (ret)
+ return ret;
+
+ if (val != DRM_MODE_ENCODER_DAC &&
+ val != DRM_MODE_ENCODER_DPI &&
+ val != DRM_MODE_ENCODER_DSI &&
+ val != DRM_MODE_ENCODER_LVDS &&
+ val != DRM_MODE_ENCODER_NONE &&
+ val != DRM_MODE_ENCODER_TMDS &&
+ val != DRM_MODE_ENCODER_TVDAC &&
+ val != DRM_MODE_ENCODER_VIRTUAL)
+ return -EINVAL;
+
+ scoped_guard(mutex, &vkms_configfs->lock) {
+ if (vkms_configfs->enabled)
+ return -EINVAL;
+
+ encoder = encoder_item_to_vkms_configfs_encoder(item)->vkms_config_encoder;
+ encoder->type = val;
+ }
+
+ return count;
+}
+
+CONFIGFS_ATTR(encoder_, type);
+
+static struct configfs_attribute *encoder_attrs[] = {
+ &encoder_attr_type,
+ NULL,
+};
+
static struct configfs_item_operations encoder_possible_crtcs_item_operations = {
.allow_link = &encoder_possible_crtcs_allow_link,
.drop_link = &encoder_possible_crtcs_drop_link,
@@ -782,6 +838,7 @@ static struct configfs_item_operations encoder_item_operations = {
static const struct config_item_type encoder_item_type = {
.ct_item_ops = &encoder_item_operations,
+ .ct_attrs = encoder_attrs,
.ct_owner = THIS_MODULE,
};
--
2.47.0
More information about the dri-devel
mailing list