drm/sysfs: Link DRM connectors to corresponding Type-C connectors
Subsystems (2)
PATCH 1/1 drm/sysfs: Link DRM connectors to corresponding Type-C connectors
Create a symlink pointing to USB Type-C connector for DRM connectors when they are created. The link will be created only if the firmware is able to describe the connection beween the two connectors.
Signed-off-by Won Chung <[email protected]>
--- drivers/gpu/drm/drm_sysfs.c | 42 +++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+)
drivers/gpu/drm/drm_sysfs.c +42 -0
@@ -11,12 +11,14 @@*/ #include <linux/acpi.h> +#include <linux/component.h> #include <linux/device.h> #include <linux/err.h> #include <linux/export.h> #include <linux/gfp.h> #include <linux/i2c.h> #include <linux/kdev_t.h> +#include <linux/property.h> #include <linux/slab.h> #include <drm/drm_connector.h>
@@ -95,6 +97,36 @@ static char *drm_devnode(struct device *dev, umode_t *mode)return kasprintf (GFP_KERNEL ,"dri/%s" ,dev_name (dev)); } +static int typec_connector_bind (struct device *dev, +struct device *typec_connector,void *data) +{ +int ret; + + ret =sysfs_create_link (&dev->kobj, &typec_connector->kobj, +"typec_connector" ); +if (ret) +return ret; + + ret =sysfs_create_link (&typec_connector->kobj, &dev->kobj, +"drm_connector" ); +if (ret) +sysfs_remove_link (&dev->kobj,"typec_connector" ); + +return ret; +} + +static void typec_connector_unbind (struct device *dev, +struct device *typec_connector,void *data) +{ +sysfs_remove_link (&typec_connector->kobj,"drm_connector" ); +sysfs_remove_link (&dev->kobj,"typec_connector" ); +} + +static const struct component_ops typec_connector_ops = { + .bind = typec_connector_bind, + .unbind = typec_connector_unbind, +}; + static CLASS_ATTR_STRING(version, S_IRUGO, "drm 1.1.0 20060810");/**
@@ -355,6 +387,13 @@ int drm_sysfs_connector_add(struct drm_connector *connector)if (connector->ddc)return sysfs_create_link (&connector->kdev->kobj, &connector->ddc->dev.kobj,"ddc" ); + +if (dev_fwnode (kdev)) { + r =component_add (kdev, &typec_connector_ops); +if (r) +drm_err (dev,"failed to add component\n" ); + } +return 0 ; err_free:
@@ -367,6 +406,9 @@ void drm_sysfs_connector_remove(struct drm_connector *connector)if (!connector->kdev)return ; +if (dev_fwnode (connector->kdev)) +component_del (connector->kdev, &typec_connector_ops); +if (connector->ddc)sysfs_remove_link (&connector->kdev->kobj,"ddc" );
Signature · 1 line
2.37.2.789.g6183377224-goog
Hi Won,
Quoted 29 lines · Won Chung
Create a symlink pointing to USB Type-C connector for DRM connectors when they are created. The link will be created only if the firmware is able to describe the connection beween the two connectors.
Signed-off-by Won Chung <[email protected]>--- drivers/gpu/drm/drm_sysfs.c | 42 +++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+)drivers/gpu/drm/drm_sysfs.c +2
-0@@ -11,12 +11,14 @@*/ #include <linux/acpi.h> +#include <linux/component.h> #include <linux/device.h> #include <linux/err.h> #include <linux/export.h> #include <linux/gfp.h> #include <linux/i2c.h> #include <linux/kdev_t.h> +#include <linux/property.h> #include <linux/slab.h> #include <drm/drm_connector.h>
drivers/gpu/drm/drm_sysfs.c static char *drm_devnode(struct device *dev, umode_t *mode) · line 106
Quoted 10 lines
drivers/gpu/drm/drm_sysfs.c +7
-0@@ -95,6 +97,36 @@ static char *drm_devnode(struct device *dev, umode_t *mode)return kasprintf (GFP_KERNEL ,"dri/%s" ,dev_name (dev)); } +static int typec_connector_bind (struct device *dev, +struct device *typec_connector,void *data) +{ +int ret; + + ret =sysfs_create_link (&dev->kobj, &typec_connector->kobj, +"typec_connector" );
One line is enough.
drivers/gpu/drm/drm_sysfs.c static char *drm_devnode(struct device *dev, umode_t *mode) · line 111
Quoted 5 lines
drivers/gpu/drm/drm_sysfs.c +5
-0+if (ret) +return ret; + + ret =sysfs_create_link (&typec_connector->kobj, &dev->kobj, +"drm_connector" );
Ditto.
Quoted 47 lines
drivers/gpu/drm/drm_sysfs.c +28
-0+if (ret) +sysfs_remove_link (&dev->kobj,"typec_connector" ); + +return ret; +} + +static void typec_connector_unbind (struct device *dev, +struct device *typec_connector,void *data) +{ +sysfs_remove_link (&typec_connector->kobj,"drm_connector" ); +sysfs_remove_link (&dev->kobj,"typec_connector" ); +} + +static const struct component_ops typec_connector_ops = { + .bind = typec_connector_bind, + .unbind = typec_connector_unbind, +}; + static CLASS_ATTR_STRING(version, S_IRUGO, "drm 1.1.0 20060810");/** @@ -355,6 +387,13 @@ int drm_sysfs_connector_add(struct drm_connector *connector)if (connector->ddc)return sysfs_create_link (&connector->kdev->kobj, &connector->ddc->dev.kobj,"ddc" ); + +if (dev_fwnode (kdev)) { + r =component_add (kdev, &typec_connector_ops); +if (r) +drm_err (dev,"failed to add component\n" ); + } +return 0 ; err_free:@@ -367,6 +406,9 @@ void drm_sysfs_connector_remove(struct drm_connector *connector)if (!connector->kdev)return ; +if (dev_fwnode (connector->kdev)) +component_del (connector->kdev, &typec_connector_ops); +if (connector->ddc)sysfs_remove_link (&connector->kdev->kobj,"ddc" );Signature · 1 line
2.37.2.789.g6183377224-goog
Signature · 1 line
heikki