Commit 331de7db authored by Hans de Goede's avatar Hans de Goede

drm/connector: Give connector sysfs devices there own device_type

Give connector sysfs devices there own device_type, this allows us to
check if a device passed to functions dealing with generic devices is
a drm_connector or not.

A check like this is necessary in the drm_connector_acpi_bus_match()
function added in the next patch in this series.
Tested-by: default avatarHeikki Krogerus <heikki.krogerus@linux.intel.com>
Signed-off-by: default avatarHans de Goede <hdegoede@redhat.com>
Reviewed-by: default avatarLyude Paul <lyude@redhat.com>
Link: https://lore.kernel.org/r/20210817215201.795062-2-hdegoede@redhat.com
parent c7782443
...@@ -50,6 +50,10 @@ static struct device_type drm_sysfs_device_minor = { ...@@ -50,6 +50,10 @@ static struct device_type drm_sysfs_device_minor = {
.name = "drm_minor" .name = "drm_minor"
}; };
static struct device_type drm_sysfs_device_connector = {
.name = "drm_connector",
};
struct class *drm_class; struct class *drm_class;
static char *drm_devnode(struct device *dev, umode_t *mode) static char *drm_devnode(struct device *dev, umode_t *mode)
...@@ -102,6 +106,11 @@ void drm_sysfs_destroy(void) ...@@ -102,6 +106,11 @@ void drm_sysfs_destroy(void)
drm_class = NULL; drm_class = NULL;
} }
static void drm_sysfs_release(struct device *dev)
{
kfree(dev);
}
/* /*
* Connector properties * Connector properties
*/ */
...@@ -273,27 +282,47 @@ static const struct attribute_group *connector_dev_groups[] = { ...@@ -273,27 +282,47 @@ static const struct attribute_group *connector_dev_groups[] = {
int drm_sysfs_connector_add(struct drm_connector *connector) int drm_sysfs_connector_add(struct drm_connector *connector)
{ {
struct drm_device *dev = connector->dev; struct drm_device *dev = connector->dev;
struct device *kdev;
int r;
if (connector->kdev) if (connector->kdev)
return 0; return 0;
connector->kdev = kdev = kzalloc(sizeof(*kdev), GFP_KERNEL);
device_create_with_groups(drm_class, dev->primary->kdev, 0, if (!kdev)
connector, connector_dev_groups, return -ENOMEM;
"card%d-%s", dev->primary->index,
connector->name); device_initialize(kdev);
kdev->class = drm_class;
kdev->type = &drm_sysfs_device_connector;
kdev->parent = dev->primary->kdev;
kdev->groups = connector_dev_groups;
kdev->release = drm_sysfs_release;
dev_set_drvdata(kdev, connector);
r = dev_set_name(kdev, "card%d-%s", dev->primary->index, connector->name);
if (r)
goto err_free;
DRM_DEBUG("adding \"%s\" to sysfs\n", DRM_DEBUG("adding \"%s\" to sysfs\n",
connector->name); connector->name);
if (IS_ERR(connector->kdev)) { r = device_add(kdev);
DRM_ERROR("failed to register connector device: %ld\n", PTR_ERR(connector->kdev)); if (r) {
return PTR_ERR(connector->kdev); drm_err(dev, "failed to register connector device: %d\n", r);
goto err_free;
} }
connector->kdev = kdev;
if (connector->ddc) if (connector->ddc)
return sysfs_create_link(&connector->kdev->kobj, return sysfs_create_link(&connector->kdev->kobj,
&connector->ddc->dev.kobj, "ddc"); &connector->ddc->dev.kobj, "ddc");
return 0; return 0;
err_free:
put_device(kdev);
return r;
} }
void drm_sysfs_connector_remove(struct drm_connector *connector) void drm_sysfs_connector_remove(struct drm_connector *connector)
...@@ -374,11 +403,6 @@ void drm_sysfs_connector_status_event(struct drm_connector *connector, ...@@ -374,11 +403,6 @@ void drm_sysfs_connector_status_event(struct drm_connector *connector,
} }
EXPORT_SYMBOL(drm_sysfs_connector_status_event); EXPORT_SYMBOL(drm_sysfs_connector_status_event);
static void drm_sysfs_release(struct device *dev)
{
kfree(dev);
}
struct device *drm_sysfs_minor_alloc(struct drm_minor *minor) struct device *drm_sysfs_minor_alloc(struct drm_minor *minor)
{ {
const char *minor_str; const char *minor_str;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment