Greg Kroah-Hartman | 0650fd5 | 2006-01-20 14:08:59 -0800 | [diff] [blame] | 1 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | /* |
| 3 | * drm_sysfs.c - Modifications to drm_sysfs_class.c to support |
| 4 | * extra sysfs attribute from DRM. Normal drm_sysfs_class |
| 5 | * does not allow adding attributes. |
| 6 | * |
| 7 | * Copyright (c) 2004 Jon Smirl <jonsmirl@gmail.com> |
| 8 | * Copyright (c) 2003-2004 Greg Kroah-Hartman <greg@kroah.com> |
| 9 | * Copyright (c) 2003-2004 IBM Corp. |
| 10 | * |
| 11 | * This file is released under the GPLv2 |
| 12 | * |
| 13 | */ |
| 14 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | #include <linux/device.h> |
| 16 | #include <linux/kdev_t.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 17 | #include <linux/gfp.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | #include <linux/err.h> |
Paul Gortmaker | 2d1a8a4 | 2011-08-30 18:16:33 -0400 | [diff] [blame] | 19 | #include <linux/export.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | |
David Howells | 760285e | 2012-10-02 18:01:07 +0100 | [diff] [blame] | 21 | #include <drm/drm_sysfs.h> |
David Howells | 760285e | 2012-10-02 18:01:07 +0100 | [diff] [blame] | 22 | #include <drm/drmP.h> |
Daniel Vetter | 67d0ec4 | 2014-09-10 12:43:53 +0200 | [diff] [blame] | 23 | #include "drm_internal.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | |
Dave Airlie | 5bdebb1 | 2013-10-11 14:07:25 +1000 | [diff] [blame] | 25 | #define to_drm_minor(d) dev_get_drvdata(d) |
| 26 | #define to_drm_connector(d) dev_get_drvdata(d) |
Jesse Barnes | e8b962b | 2007-11-22 14:02:38 +1000 | [diff] [blame] | 27 | |
Daniel Vetter | e227170 | 2017-04-04 11:52:55 +0200 | [diff] [blame] | 28 | /** |
| 29 | * DOC: overview |
| 30 | * |
| 31 | * DRM provides very little additional support to drivers for sysfs |
| 32 | * interactions, beyond just all the standard stuff. Drivers who want to expose |
| 33 | * additional sysfs properties and property groups can attach them at either |
| 34 | * &drm_device.dev or &drm_connector.kdev. |
| 35 | * |
| 36 | * Registration is automatically handled when calling drm_dev_register(), or |
| 37 | * drm_connector_register() in case of hot-plugged connectors. Unregistration is |
| 38 | * also automatically handled by drm_dev_unregister() and |
| 39 | * drm_connector_unregister(). |
| 40 | */ |
| 41 | |
Thomas Hellstrom | 08e4d53 | 2009-08-20 19:02:31 +1000 | [diff] [blame] | 42 | static struct device_type drm_sysfs_device_minor = { |
| 43 | .name = "drm_minor" |
| 44 | }; |
| 45 | |
David Herrmann | fcc9021 | 2015-09-09 14:21:30 +0200 | [diff] [blame] | 46 | struct class *drm_class; |
| 47 | |
Al Viro | 2c9ede5 | 2011-07-23 20:24:48 -0400 | [diff] [blame] | 48 | static char *drm_devnode(struct device *dev, umode_t *mode) |
Kay Sievers | 02200d0 | 2009-04-30 15:23:42 +0200 | [diff] [blame] | 49 | { |
| 50 | return kasprintf(GFP_KERNEL, "dri/%s", dev_name(dev)); |
| 51 | } |
| 52 | |
David Herrmann | 82d5e73 | 2016-09-01 14:48:36 +0200 | [diff] [blame] | 53 | static CLASS_ATTR_STRING(version, S_IRUGO, "drm 1.1.0 20060810"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | |
| 55 | /** |
David Herrmann | fcc9021 | 2015-09-09 14:21:30 +0200 | [diff] [blame] | 56 | * drm_sysfs_init - initialize sysfs helpers |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | * |
David Herrmann | fcc9021 | 2015-09-09 14:21:30 +0200 | [diff] [blame] | 58 | * This is used to create the DRM class, which is the implicit parent of any |
| 59 | * other top-level DRM sysfs objects. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | * |
David Herrmann | fcc9021 | 2015-09-09 14:21:30 +0200 | [diff] [blame] | 61 | * You must call drm_sysfs_destroy() to release the allocated resources. |
| 62 | * |
| 63 | * Return: 0 on success, negative error code on failure. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | */ |
David Herrmann | fcc9021 | 2015-09-09 14:21:30 +0200 | [diff] [blame] | 65 | int drm_sysfs_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | { |
Jeff Garzik | 24f73c9 | 2006-10-10 14:23:37 -0700 | [diff] [blame] | 67 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | |
David Herrmann | fcc9021 | 2015-09-09 14:21:30 +0200 | [diff] [blame] | 69 | drm_class = class_create(THIS_MODULE, "drm"); |
| 70 | if (IS_ERR(drm_class)) |
| 71 | return PTR_ERR(drm_class); |
| 72 | |
David Herrmann | fcc9021 | 2015-09-09 14:21:30 +0200 | [diff] [blame] | 73 | err = class_create_file(drm_class, &class_attr_version.attr); |
| 74 | if (err) { |
| 75 | class_destroy(drm_class); |
| 76 | drm_class = NULL; |
| 77 | return err; |
Jeff Garzik | 24f73c9 | 2006-10-10 14:23:37 -0700 | [diff] [blame] | 78 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | |
David Herrmann | fcc9021 | 2015-09-09 14:21:30 +0200 | [diff] [blame] | 80 | drm_class->devnode = drm_devnode; |
| 81 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | /** |
Jesse Barnes | e8b962b | 2007-11-22 14:02:38 +1000 | [diff] [blame] | 85 | * drm_sysfs_destroy - destroys DRM class |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | * |
Jesse Barnes | e8b962b | 2007-11-22 14:02:38 +1000 | [diff] [blame] | 87 | * Destroy the DRM device class. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | */ |
Jesse Barnes | e8b962b | 2007-11-22 14:02:38 +1000 | [diff] [blame] | 89 | void drm_sysfs_destroy(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | { |
David Herrmann | 26b91ae | 2015-09-09 14:21:29 +0200 | [diff] [blame] | 91 | if (IS_ERR_OR_NULL(drm_class)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | return; |
Andi Kleen | 0933e2d | 2010-01-05 12:48:09 +0100 | [diff] [blame] | 93 | class_remove_file(drm_class, &class_attr_version.attr); |
Jesse Barnes | e8b962b | 2007-11-22 14:02:38 +1000 | [diff] [blame] | 94 | class_destroy(drm_class); |
Dave Airlie | 49099c4 | 2012-07-06 18:06:42 +0100 | [diff] [blame] | 95 | drm_class = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | } |
| 97 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 98 | /* |
| 99 | * Connector properties |
| 100 | */ |
Chris Wilson | c484f02 | 2015-03-06 12:36:42 +0000 | [diff] [blame] | 101 | static ssize_t status_store(struct device *device, |
| 102 | struct device_attribute *attr, |
| 103 | const char *buf, size_t count) |
| 104 | { |
| 105 | struct drm_connector *connector = to_drm_connector(device); |
| 106 | struct drm_device *dev = connector->dev; |
Daniel Vetter | ed293f7 | 2015-11-19 17:46:50 +0100 | [diff] [blame] | 107 | enum drm_connector_force old_force; |
Chris Wilson | c484f02 | 2015-03-06 12:36:42 +0000 | [diff] [blame] | 108 | int ret; |
| 109 | |
| 110 | ret = mutex_lock_interruptible(&dev->mode_config.mutex); |
| 111 | if (ret) |
| 112 | return ret; |
| 113 | |
Daniel Vetter | ed293f7 | 2015-11-19 17:46:50 +0100 | [diff] [blame] | 114 | old_force = connector->force; |
Chris Wilson | c484f02 | 2015-03-06 12:36:42 +0000 | [diff] [blame] | 115 | |
Daniel Vetter | ed293f7 | 2015-11-19 17:46:50 +0100 | [diff] [blame] | 116 | if (sysfs_streq(buf, "detect")) |
Chris Wilson | c484f02 | 2015-03-06 12:36:42 +0000 | [diff] [blame] | 117 | connector->force = 0; |
Daniel Vetter | ed293f7 | 2015-11-19 17:46:50 +0100 | [diff] [blame] | 118 | else if (sysfs_streq(buf, "on")) |
Chris Wilson | c484f02 | 2015-03-06 12:36:42 +0000 | [diff] [blame] | 119 | connector->force = DRM_FORCE_ON; |
Daniel Vetter | ed293f7 | 2015-11-19 17:46:50 +0100 | [diff] [blame] | 120 | else if (sysfs_streq(buf, "on-digital")) |
Chris Wilson | c484f02 | 2015-03-06 12:36:42 +0000 | [diff] [blame] | 121 | connector->force = DRM_FORCE_ON_DIGITAL; |
Daniel Vetter | ed293f7 | 2015-11-19 17:46:50 +0100 | [diff] [blame] | 122 | else if (sysfs_streq(buf, "off")) |
Chris Wilson | c484f02 | 2015-03-06 12:36:42 +0000 | [diff] [blame] | 123 | connector->force = DRM_FORCE_OFF; |
Daniel Vetter | ed293f7 | 2015-11-19 17:46:50 +0100 | [diff] [blame] | 124 | else |
Chris Wilson | c484f02 | 2015-03-06 12:36:42 +0000 | [diff] [blame] | 125 | ret = -EINVAL; |
| 126 | |
Daniel Vetter | ed293f7 | 2015-11-19 17:46:50 +0100 | [diff] [blame] | 127 | if (old_force != connector->force || !connector->force) { |
| 128 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s] force updated from %d to %d or reprobing\n", |
Chris Wilson | c484f02 | 2015-03-06 12:36:42 +0000 | [diff] [blame] | 129 | connector->base.id, |
| 130 | connector->name, |
Daniel Vetter | ed293f7 | 2015-11-19 17:46:50 +0100 | [diff] [blame] | 131 | old_force, connector->force); |
Chris Wilson | c484f02 | 2015-03-06 12:36:42 +0000 | [diff] [blame] | 132 | |
Daniel Vetter | ed293f7 | 2015-11-19 17:46:50 +0100 | [diff] [blame] | 133 | connector->funcs->fill_modes(connector, |
| 134 | dev->mode_config.max_width, |
| 135 | dev->mode_config.max_height); |
Chris Wilson | c484f02 | 2015-03-06 12:36:42 +0000 | [diff] [blame] | 136 | } |
| 137 | |
| 138 | mutex_unlock(&dev->mode_config.mutex); |
| 139 | |
Russell King | 38d8571 | 2015-06-06 08:27:30 +1000 | [diff] [blame] | 140 | return ret ? ret : count; |
Chris Wilson | c484f02 | 2015-03-06 12:36:42 +0000 | [diff] [blame] | 141 | } |
| 142 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 143 | static ssize_t status_show(struct device *device, |
| 144 | struct device_attribute *attr, |
| 145 | char *buf) |
| 146 | { |
| 147 | struct drm_connector *connector = to_drm_connector(device); |
Daniel Vetter | 4eb9b94 | 2016-03-30 11:45:13 +0200 | [diff] [blame] | 148 | enum drm_connector_status status; |
| 149 | |
| 150 | status = READ_ONCE(connector->status); |
Chris Wilson | 007c80a | 2011-03-15 11:40:00 +0000 | [diff] [blame] | 151 | |
Keith Packard | 75185c9 | 2009-05-30 20:42:25 -0700 | [diff] [blame] | 152 | return snprintf(buf, PAGE_SIZE, "%s\n", |
Daniel Vetter | 4eb9b94 | 2016-03-30 11:45:13 +0200 | [diff] [blame] | 153 | drm_get_connector_status_name(status)); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 154 | } |
| 155 | |
| 156 | static ssize_t dpms_show(struct device *device, |
| 157 | struct device_attribute *attr, |
| 158 | char *buf) |
| 159 | { |
| 160 | struct drm_connector *connector = to_drm_connector(device); |
Daniel Vetter | 621bd0f | 2015-09-29 09:56:53 +0200 | [diff] [blame] | 161 | int dpms; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 162 | |
Daniel Vetter | 621bd0f | 2015-09-29 09:56:53 +0200 | [diff] [blame] | 163 | dpms = READ_ONCE(connector->dpms); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 164 | |
Keith Packard | 75185c9 | 2009-05-30 20:42:25 -0700 | [diff] [blame] | 165 | return snprintf(buf, PAGE_SIZE, "%s\n", |
Daniel Vetter | 621bd0f | 2015-09-29 09:56:53 +0200 | [diff] [blame] | 166 | drm_get_dpms_name(dpms)); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 167 | } |
| 168 | |
| 169 | static ssize_t enabled_show(struct device *device, |
| 170 | struct device_attribute *attr, |
| 171 | char *buf) |
| 172 | { |
| 173 | struct drm_connector *connector = to_drm_connector(device); |
Daniel Vetter | 4eb9b94 | 2016-03-30 11:45:13 +0200 | [diff] [blame] | 174 | bool enabled; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 175 | |
Daniel Vetter | 4eb9b94 | 2016-03-30 11:45:13 +0200 | [diff] [blame] | 176 | enabled = READ_ONCE(connector->encoder); |
| 177 | |
| 178 | return snprintf(buf, PAGE_SIZE, enabled ? "enabled\n" : "disabled\n"); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 179 | } |
| 180 | |
Chris Wright | 2c3c8be | 2010-05-12 18:28:57 -0700 | [diff] [blame] | 181 | static ssize_t edid_show(struct file *filp, struct kobject *kobj, |
| 182 | struct bin_attribute *attr, char *buf, loff_t off, |
| 183 | size_t count) |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 184 | { |
Geliang Tang | d122cbf | 2016-01-13 22:48:41 +0800 | [diff] [blame] | 185 | struct device *connector_dev = kobj_to_dev(kobj); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 186 | struct drm_connector *connector = to_drm_connector(connector_dev); |
| 187 | unsigned char *edid; |
| 188 | size_t size; |
Daniel Vetter | a48a62b | 2015-10-02 13:01:02 +0200 | [diff] [blame] | 189 | ssize_t ret = 0; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 190 | |
Daniel Vetter | a48a62b | 2015-10-02 13:01:02 +0200 | [diff] [blame] | 191 | mutex_lock(&connector->dev->mode_config.mutex); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 192 | if (!connector->edid_blob_ptr) |
Daniel Vetter | a48a62b | 2015-10-02 13:01:02 +0200 | [diff] [blame] | 193 | goto unlock; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 194 | |
| 195 | edid = connector->edid_blob_ptr->data; |
| 196 | size = connector->edid_blob_ptr->length; |
| 197 | if (!edid) |
Daniel Vetter | a48a62b | 2015-10-02 13:01:02 +0200 | [diff] [blame] | 198 | goto unlock; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 199 | |
| 200 | if (off >= size) |
Daniel Vetter | a48a62b | 2015-10-02 13:01:02 +0200 | [diff] [blame] | 201 | goto unlock; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 202 | |
| 203 | if (off + count > size) |
| 204 | count = size - off; |
| 205 | memcpy(buf, edid + off, count); |
| 206 | |
Daniel Vetter | a48a62b | 2015-10-02 13:01:02 +0200 | [diff] [blame] | 207 | ret = count; |
| 208 | unlock: |
| 209 | mutex_unlock(&connector->dev->mode_config.mutex); |
| 210 | |
| 211 | return ret; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 212 | } |
| 213 | |
| 214 | static ssize_t modes_show(struct device *device, |
| 215 | struct device_attribute *attr, |
| 216 | char *buf) |
| 217 | { |
| 218 | struct drm_connector *connector = to_drm_connector(device); |
| 219 | struct drm_display_mode *mode; |
| 220 | int written = 0; |
| 221 | |
Daniel Vetter | a48a62b | 2015-10-02 13:01:02 +0200 | [diff] [blame] | 222 | mutex_lock(&connector->dev->mode_config.mutex); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 223 | list_for_each_entry(mode, &connector->modes, head) { |
| 224 | written += snprintf(buf + written, PAGE_SIZE - written, "%s\n", |
| 225 | mode->name); |
| 226 | } |
Daniel Vetter | a48a62b | 2015-10-02 13:01:02 +0200 | [diff] [blame] | 227 | mutex_unlock(&connector->dev->mode_config.mutex); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 228 | |
| 229 | return written; |
| 230 | } |
| 231 | |
Chris Wilson | c484f02 | 2015-03-06 12:36:42 +0000 | [diff] [blame] | 232 | static DEVICE_ATTR_RW(status); |
Takashi Iwai | 335f1a6 | 2015-02-04 11:58:53 +0100 | [diff] [blame] | 233 | static DEVICE_ATTR_RO(enabled); |
| 234 | static DEVICE_ATTR_RO(dpms); |
| 235 | static DEVICE_ATTR_RO(modes); |
| 236 | |
| 237 | static struct attribute *connector_dev_attrs[] = { |
| 238 | &dev_attr_status.attr, |
| 239 | &dev_attr_enabled.attr, |
| 240 | &dev_attr_dpms.attr, |
| 241 | &dev_attr_modes.attr, |
| 242 | NULL |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 243 | }; |
| 244 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 245 | static struct bin_attribute edid_attr = { |
| 246 | .attr.name = "edid", |
Keith Packard | e36ebaf | 2009-05-30 20:42:26 -0700 | [diff] [blame] | 247 | .attr.mode = 0444, |
Adam Jackson | 7466f4c | 2010-03-29 21:43:23 +0000 | [diff] [blame] | 248 | .size = 0, |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 249 | .read = edid_show, |
| 250 | }; |
| 251 | |
Takashi Iwai | 335f1a6 | 2015-02-04 11:58:53 +0100 | [diff] [blame] | 252 | static struct bin_attribute *connector_bin_attrs[] = { |
| 253 | &edid_attr, |
| 254 | NULL |
| 255 | }; |
| 256 | |
| 257 | static const struct attribute_group connector_dev_group = { |
| 258 | .attrs = connector_dev_attrs, |
| 259 | .bin_attrs = connector_bin_attrs, |
| 260 | }; |
| 261 | |
Takashi Iwai | 335f1a6 | 2015-02-04 11:58:53 +0100 | [diff] [blame] | 262 | static const struct attribute_group *connector_dev_groups[] = { |
| 263 | &connector_dev_group, |
Takashi Iwai | 335f1a6 | 2015-02-04 11:58:53 +0100 | [diff] [blame] | 264 | NULL |
| 265 | }; |
| 266 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 267 | int drm_sysfs_connector_add(struct drm_connector *connector) |
| 268 | { |
| 269 | struct drm_device *dev = connector->dev; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 270 | |
Dave Airlie | 5bdebb1 | 2013-10-11 14:07:25 +1000 | [diff] [blame] | 271 | if (connector->kdev) |
| 272 | return 0; |
| 273 | |
Takashi Iwai | 335f1a6 | 2015-02-04 11:58:53 +0100 | [diff] [blame] | 274 | connector->kdev = |
| 275 | device_create_with_groups(drm_class, dev->primary->kdev, 0, |
| 276 | connector, connector_dev_groups, |
| 277 | "card%d-%s", dev->primary->index, |
| 278 | connector->name); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 279 | DRM_DEBUG("adding \"%s\" to sysfs\n", |
Jani Nikula | 2593382 | 2014-06-03 14:56:20 +0300 | [diff] [blame] | 280 | connector->name); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 281 | |
Dave Airlie | 5bdebb1 | 2013-10-11 14:07:25 +1000 | [diff] [blame] | 282 | if (IS_ERR(connector->kdev)) { |
| 283 | DRM_ERROR("failed to register connector device: %ld\n", PTR_ERR(connector->kdev)); |
Takashi Iwai | 335f1a6 | 2015-02-04 11:58:53 +0100 | [diff] [blame] | 284 | return PTR_ERR(connector->kdev); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 285 | } |
| 286 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 287 | /* Let userspace know we have a new connector */ |
| 288 | drm_sysfs_hotplug_event(dev); |
| 289 | |
| 290 | return 0; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 291 | } |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 292 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 293 | void drm_sysfs_connector_remove(struct drm_connector *connector) |
| 294 | { |
Dave Airlie | 5bdebb1 | 2013-10-11 14:07:25 +1000 | [diff] [blame] | 295 | if (!connector->kdev) |
Dave Airlie | 1828fe6 | 2012-02-20 14:15:02 +0000 | [diff] [blame] | 296 | return; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 297 | DRM_DEBUG("removing \"%s\" from sysfs\n", |
Jani Nikula | 2593382 | 2014-06-03 14:56:20 +0300 | [diff] [blame] | 298 | connector->name); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 299 | |
Dave Airlie | 5bdebb1 | 2013-10-11 14:07:25 +1000 | [diff] [blame] | 300 | device_unregister(connector->kdev); |
| 301 | connector->kdev = NULL; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 302 | } |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 303 | |
| 304 | /** |
| 305 | * drm_sysfs_hotplug_event - generate a DRM uevent |
| 306 | * @dev: DRM device |
| 307 | * |
| 308 | * Send a uevent for the DRM device specified by @dev. Currently we only |
| 309 | * set HOTPLUG=1 in the uevent environment, but this could be expanded to |
| 310 | * deal with other types of events. |
| 311 | */ |
| 312 | void drm_sysfs_hotplug_event(struct drm_device *dev) |
| 313 | { |
| 314 | char *event_string = "HOTPLUG=1"; |
| 315 | char *envp[] = { event_string, NULL }; |
| 316 | |
| 317 | DRM_DEBUG("generating hotplug event\n"); |
| 318 | |
Dave Airlie | 5bdebb1 | 2013-10-11 14:07:25 +1000 | [diff] [blame] | 319 | kobject_uevent_env(&dev->primary->kdev->kobj, KOBJ_CHANGE, envp); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 320 | } |
Jesse Barnes | 5ca5828 | 2009-03-31 14:11:15 -0700 | [diff] [blame] | 321 | EXPORT_SYMBOL(drm_sysfs_hotplug_event); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 322 | |
David Herrmann | 760c960 | 2013-11-21 20:50:50 +1000 | [diff] [blame] | 323 | static void drm_sysfs_release(struct device *dev) |
| 324 | { |
| 325 | kfree(dev); |
| 326 | } |
| 327 | |
David Herrmann | e172807 | 2014-07-23 11:38:38 +0200 | [diff] [blame] | 328 | struct device *drm_sysfs_minor_alloc(struct drm_minor *minor) |
Jesse Barnes | e8b962b | 2007-11-22 14:02:38 +1000 | [diff] [blame] | 329 | { |
David Herrmann | e172807 | 2014-07-23 11:38:38 +0200 | [diff] [blame] | 330 | const char *minor_str; |
| 331 | struct device *kdev; |
David Herrmann | 760c960 | 2013-11-21 20:50:50 +1000 | [diff] [blame] | 332 | int r; |
Jesse Barnes | e8b962b | 2007-11-22 14:02:38 +1000 | [diff] [blame] | 333 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 334 | if (minor->type == DRM_MINOR_CONTROL) |
| 335 | minor_str = "controlD%d"; |
David Herrmann | e172807 | 2014-07-23 11:38:38 +0200 | [diff] [blame] | 336 | else if (minor->type == DRM_MINOR_RENDER) |
| 337 | minor_str = "renderD%d"; |
| 338 | else |
| 339 | minor_str = "card%d"; |
Jesse Barnes | e8b962b | 2007-11-22 14:02:38 +1000 | [diff] [blame] | 340 | |
David Herrmann | e172807 | 2014-07-23 11:38:38 +0200 | [diff] [blame] | 341 | kdev = kzalloc(sizeof(*kdev), GFP_KERNEL); |
| 342 | if (!kdev) |
| 343 | return ERR_PTR(-ENOMEM); |
David Herrmann | 760c960 | 2013-11-21 20:50:50 +1000 | [diff] [blame] | 344 | |
David Herrmann | e172807 | 2014-07-23 11:38:38 +0200 | [diff] [blame] | 345 | device_initialize(kdev); |
| 346 | kdev->devt = MKDEV(DRM_MAJOR, minor->index); |
| 347 | kdev->class = drm_class; |
| 348 | kdev->type = &drm_sysfs_device_minor; |
| 349 | kdev->parent = minor->dev->dev; |
| 350 | kdev->release = drm_sysfs_release; |
| 351 | dev_set_drvdata(kdev, minor); |
David Herrmann | 760c960 | 2013-11-21 20:50:50 +1000 | [diff] [blame] | 352 | |
David Herrmann | e172807 | 2014-07-23 11:38:38 +0200 | [diff] [blame] | 353 | r = dev_set_name(kdev, minor_str, minor->index); |
David Herrmann | 760c960 | 2013-11-21 20:50:50 +1000 | [diff] [blame] | 354 | if (r < 0) |
David Herrmann | e172807 | 2014-07-23 11:38:38 +0200 | [diff] [blame] | 355 | goto err_free; |
David Herrmann | 760c960 | 2013-11-21 20:50:50 +1000 | [diff] [blame] | 356 | |
David Herrmann | e172807 | 2014-07-23 11:38:38 +0200 | [diff] [blame] | 357 | return kdev; |
David Herrmann | 760c960 | 2013-11-21 20:50:50 +1000 | [diff] [blame] | 358 | |
David Herrmann | e172807 | 2014-07-23 11:38:38 +0200 | [diff] [blame] | 359 | err_free: |
| 360 | put_device(kdev); |
| 361 | return ERR_PTR(r); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 362 | } |
| 363 | |
| 364 | /** |
Daniel Vetter | e227170 | 2017-04-04 11:52:55 +0200 | [diff] [blame] | 365 | * drm_class_device_register - register new device with the DRM sysfs class |
| 366 | * @dev: device to register |
Thomas Hellstrom | 327c225 | 2009-08-17 16:28:37 +0200 | [diff] [blame] | 367 | * |
Daniel Vetter | e227170 | 2017-04-04 11:52:55 +0200 | [diff] [blame] | 368 | * Registers a new &struct device within the DRM sysfs class. Essentially only |
| 369 | * used by ttm to have a place for its global settings. Drivers should never use |
| 370 | * this. |
Thomas Hellstrom | 327c225 | 2009-08-17 16:28:37 +0200 | [diff] [blame] | 371 | */ |
Thomas Hellstrom | 327c225 | 2009-08-17 16:28:37 +0200 | [diff] [blame] | 372 | int drm_class_device_register(struct device *dev) |
| 373 | { |
Dave Airlie | 49099c4 | 2012-07-06 18:06:42 +0100 | [diff] [blame] | 374 | if (!drm_class || IS_ERR(drm_class)) |
| 375 | return -ENOENT; |
| 376 | |
Thomas Hellstrom | 327c225 | 2009-08-17 16:28:37 +0200 | [diff] [blame] | 377 | dev->class = drm_class; |
| 378 | return device_register(dev); |
| 379 | } |
| 380 | EXPORT_SYMBOL_GPL(drm_class_device_register); |
| 381 | |
Daniel Vetter | e227170 | 2017-04-04 11:52:55 +0200 | [diff] [blame] | 382 | /** |
| 383 | * drm_class_device_unregister - unregister device with the DRM sysfs class |
| 384 | * @dev: device to unregister |
| 385 | * |
| 386 | * Unregisters a &struct device from the DRM sysfs class. Essentially only used |
| 387 | * by ttm to have a place for its global settings. Drivers should never use |
| 388 | * this. |
| 389 | */ |
Thomas Hellstrom | 327c225 | 2009-08-17 16:28:37 +0200 | [diff] [blame] | 390 | void drm_class_device_unregister(struct device *dev) |
| 391 | { |
| 392 | return device_unregister(dev); |
| 393 | } |
| 394 | EXPORT_SYMBOL_GPL(drm_class_device_unregister); |