blob: 968a9560b4aa312798540d6bab32e27c883cb612 [file] [log] [blame]
Thomas Gleixner55716d22019-06-01 10:08:42 +02001// SPDX-License-Identifier: GPL-2.0-only
Greg Kroah-Hartman0650fd52006-01-20 14:08:59 -08002
Linus Torvalds1da177e2005-04-16 15:20:36 -07003/*
4 * drm_sysfs.c - Modifications to drm_sysfs_class.c to support
5 * extra sysfs attribute from DRM. Normal drm_sysfs_class
6 * does not allow adding attributes.
7 *
8 * Copyright (c) 2004 Jon Smirl <jonsmirl@gmail.com>
9 * Copyright (c) 2003-2004 Greg Kroah-Hartman <greg@kroah.com>
10 * Copyright (c) 2003-2004 IBM Corp.
Linus Torvalds1da177e2005-04-16 15:20:36 -070011 */
12
Linus Torvalds1da177e2005-04-16 15:20:36 -070013#include <linux/device.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070014#include <linux/err.h>
Paul Gortmaker2d1a8a42011-08-30 18:16:33 -040015#include <linux/export.h>
Sam Ravnborg0500c042019-05-26 19:35:35 +020016#include <linux/gfp.h>
Andrzej Pietrasiewicze1a29c62019-07-26 19:22:55 +020017#include <linux/i2c.h>
Sam Ravnborg0500c042019-05-26 19:35:35 +020018#include <linux/kdev_t.h>
19#include <linux/slab.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070020
Sam Ravnborg0500c042019-05-26 19:35:35 +020021#include <drm/drm_connector.h>
22#include <drm/drm_device.h>
23#include <drm/drm_file.h>
24#include <drm/drm_modes.h>
25#include <drm/drm_print.h>
26#include <drm/drm_property.h>
David Howells760285e2012-10-02 18:01:07 +010027#include <drm/drm_sysfs.h>
Sam Ravnborg0500c042019-05-26 19:35:35 +020028
Daniel Vetter67d0ec42014-09-10 12:43:53 +020029#include "drm_internal.h"
Ramalingam C6fe2ce02019-08-01 17:11:16 +053030#include "drm_crtc_internal.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070031
Dave Airlie5bdebb12013-10-11 14:07:25 +100032#define to_drm_minor(d) dev_get_drvdata(d)
33#define to_drm_connector(d) dev_get_drvdata(d)
Jesse Barnese8b962b2007-11-22 14:02:38 +100034
Daniel Vettere2271702017-04-04 11:52:55 +020035/**
36 * DOC: overview
37 *
38 * DRM provides very little additional support to drivers for sysfs
39 * interactions, beyond just all the standard stuff. Drivers who want to expose
40 * additional sysfs properties and property groups can attach them at either
41 * &drm_device.dev or &drm_connector.kdev.
42 *
43 * Registration is automatically handled when calling drm_dev_register(), or
44 * drm_connector_register() in case of hot-plugged connectors. Unregistration is
45 * also automatically handled by drm_dev_unregister() and
46 * drm_connector_unregister().
47 */
48
Thomas Hellstrom08e4d532009-08-20 19:02:31 +100049static struct device_type drm_sysfs_device_minor = {
50 .name = "drm_minor"
51};
52
David Herrmannfcc90212015-09-09 14:21:30 +020053struct class *drm_class;
54
Al Viro2c9ede52011-07-23 20:24:48 -040055static char *drm_devnode(struct device *dev, umode_t *mode)
Kay Sievers02200d02009-04-30 15:23:42 +020056{
57 return kasprintf(GFP_KERNEL, "dri/%s", dev_name(dev));
58}
59
David Herrmann82d5e732016-09-01 14:48:36 +020060static CLASS_ATTR_STRING(version, S_IRUGO, "drm 1.1.0 20060810");
Linus Torvalds1da177e2005-04-16 15:20:36 -070061
62/**
David Herrmannfcc90212015-09-09 14:21:30 +020063 * drm_sysfs_init - initialize sysfs helpers
Linus Torvalds1da177e2005-04-16 15:20:36 -070064 *
David Herrmannfcc90212015-09-09 14:21:30 +020065 * This is used to create the DRM class, which is the implicit parent of any
66 * other top-level DRM sysfs objects.
Linus Torvalds1da177e2005-04-16 15:20:36 -070067 *
David Herrmannfcc90212015-09-09 14:21:30 +020068 * You must call drm_sysfs_destroy() to release the allocated resources.
69 *
70 * Return: 0 on success, negative error code on failure.
Linus Torvalds1da177e2005-04-16 15:20:36 -070071 */
David Herrmannfcc90212015-09-09 14:21:30 +020072int drm_sysfs_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070073{
Jeff Garzik24f73c92006-10-10 14:23:37 -070074 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -070075
David Herrmannfcc90212015-09-09 14:21:30 +020076 drm_class = class_create(THIS_MODULE, "drm");
77 if (IS_ERR(drm_class))
78 return PTR_ERR(drm_class);
79
David Herrmannfcc90212015-09-09 14:21:30 +020080 err = class_create_file(drm_class, &class_attr_version.attr);
81 if (err) {
82 class_destroy(drm_class);
83 drm_class = NULL;
84 return err;
Jeff Garzik24f73c92006-10-10 14:23:37 -070085 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070086
David Herrmannfcc90212015-09-09 14:21:30 +020087 drm_class->devnode = drm_devnode;
88 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070089}
90
91/**
Jesse Barnese8b962b2007-11-22 14:02:38 +100092 * drm_sysfs_destroy - destroys DRM class
Linus Torvalds1da177e2005-04-16 15:20:36 -070093 *
Jesse Barnese8b962b2007-11-22 14:02:38 +100094 * Destroy the DRM device class.
Linus Torvalds1da177e2005-04-16 15:20:36 -070095 */
Jesse Barnese8b962b2007-11-22 14:02:38 +100096void drm_sysfs_destroy(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070097{
David Herrmann26b91ae2015-09-09 14:21:29 +020098 if (IS_ERR_OR_NULL(drm_class))
Linus Torvalds1da177e2005-04-16 15:20:36 -070099 return;
Andi Kleen0933e2d2010-01-05 12:48:09 +0100100 class_remove_file(drm_class, &class_attr_version.attr);
Jesse Barnese8b962b2007-11-22 14:02:38 +1000101 class_destroy(drm_class);
Dave Airlie49099c42012-07-06 18:06:42 +0100102 drm_class = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103}
104
Dave Airlief453ba02008-11-07 14:05:41 -0800105/*
106 * Connector properties
107 */
Chris Wilsonc484f022015-03-06 12:36:42 +0000108static ssize_t status_store(struct device *device,
109 struct device_attribute *attr,
110 const char *buf, size_t count)
111{
112 struct drm_connector *connector = to_drm_connector(device);
113 struct drm_device *dev = connector->dev;
Daniel Vettered293f72015-11-19 17:46:50 +0100114 enum drm_connector_force old_force;
Chris Wilsonc484f022015-03-06 12:36:42 +0000115 int ret;
116
117 ret = mutex_lock_interruptible(&dev->mode_config.mutex);
118 if (ret)
119 return ret;
120
Daniel Vettered293f72015-11-19 17:46:50 +0100121 old_force = connector->force;
Chris Wilsonc484f022015-03-06 12:36:42 +0000122
Daniel Vettered293f72015-11-19 17:46:50 +0100123 if (sysfs_streq(buf, "detect"))
Chris Wilsonc484f022015-03-06 12:36:42 +0000124 connector->force = 0;
Daniel Vettered293f72015-11-19 17:46:50 +0100125 else if (sysfs_streq(buf, "on"))
Chris Wilsonc484f022015-03-06 12:36:42 +0000126 connector->force = DRM_FORCE_ON;
Daniel Vettered293f72015-11-19 17:46:50 +0100127 else if (sysfs_streq(buf, "on-digital"))
Chris Wilsonc484f022015-03-06 12:36:42 +0000128 connector->force = DRM_FORCE_ON_DIGITAL;
Daniel Vettered293f72015-11-19 17:46:50 +0100129 else if (sysfs_streq(buf, "off"))
Chris Wilsonc484f022015-03-06 12:36:42 +0000130 connector->force = DRM_FORCE_OFF;
Daniel Vettered293f72015-11-19 17:46:50 +0100131 else
Chris Wilsonc484f022015-03-06 12:36:42 +0000132 ret = -EINVAL;
133
Daniel Vettered293f72015-11-19 17:46:50 +0100134 if (old_force != connector->force || !connector->force) {
135 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] force updated from %d to %d or reprobing\n",
Chris Wilsonc484f022015-03-06 12:36:42 +0000136 connector->base.id,
137 connector->name,
Daniel Vettered293f72015-11-19 17:46:50 +0100138 old_force, connector->force);
Chris Wilsonc484f022015-03-06 12:36:42 +0000139
Daniel Vettered293f72015-11-19 17:46:50 +0100140 connector->funcs->fill_modes(connector,
141 dev->mode_config.max_width,
142 dev->mode_config.max_height);
Chris Wilsonc484f022015-03-06 12:36:42 +0000143 }
144
145 mutex_unlock(&dev->mode_config.mutex);
146
Russell King38d85712015-06-06 08:27:30 +1000147 return ret ? ret : count;
Chris Wilsonc484f022015-03-06 12:36:42 +0000148}
149
Dave Airlief453ba02008-11-07 14:05:41 -0800150static ssize_t status_show(struct device *device,
151 struct device_attribute *attr,
152 char *buf)
153{
154 struct drm_connector *connector = to_drm_connector(device);
Daniel Vetter4eb9b942016-03-30 11:45:13 +0200155 enum drm_connector_status status;
156
157 status = READ_ONCE(connector->status);
Chris Wilson007c80a2011-03-15 11:40:00 +0000158
Tian Tao835bc482021-03-22 09:19:38 +0800159 return sysfs_emit(buf, "%s\n",
160 drm_get_connector_status_name(status));
Dave Airlief453ba02008-11-07 14:05:41 -0800161}
162
163static ssize_t dpms_show(struct device *device,
164 struct device_attribute *attr,
165 char *buf)
166{
167 struct drm_connector *connector = to_drm_connector(device);
Daniel Vetter621bd0f2015-09-29 09:56:53 +0200168 int dpms;
Dave Airlief453ba02008-11-07 14:05:41 -0800169
Daniel Vetter621bd0f2015-09-29 09:56:53 +0200170 dpms = READ_ONCE(connector->dpms);
Dave Airlief453ba02008-11-07 14:05:41 -0800171
Tian Tao835bc482021-03-22 09:19:38 +0800172 return sysfs_emit(buf, "%s\n", drm_get_dpms_name(dpms));
Dave Airlief453ba02008-11-07 14:05:41 -0800173}
174
175static ssize_t enabled_show(struct device *device,
176 struct device_attribute *attr,
177 char *buf)
178{
179 struct drm_connector *connector = to_drm_connector(device);
Daniel Vetter4eb9b942016-03-30 11:45:13 +0200180 bool enabled;
Dave Airlief453ba02008-11-07 14:05:41 -0800181
Daniel Vetter4eb9b942016-03-30 11:45:13 +0200182 enabled = READ_ONCE(connector->encoder);
183
Tian Tao835bc482021-03-22 09:19:38 +0800184 return sysfs_emit(buf, enabled ? "enabled\n" : "disabled\n");
Dave Airlief453ba02008-11-07 14:05:41 -0800185}
186
Chris Wright2c3c8be2010-05-12 18:28:57 -0700187static ssize_t edid_show(struct file *filp, struct kobject *kobj,
188 struct bin_attribute *attr, char *buf, loff_t off,
189 size_t count)
Dave Airlief453ba02008-11-07 14:05:41 -0800190{
Geliang Tangd122cbf2016-01-13 22:48:41 +0800191 struct device *connector_dev = kobj_to_dev(kobj);
Dave Airlief453ba02008-11-07 14:05:41 -0800192 struct drm_connector *connector = to_drm_connector(connector_dev);
193 unsigned char *edid;
194 size_t size;
Daniel Vettera48a62b2015-10-02 13:01:02 +0200195 ssize_t ret = 0;
Dave Airlief453ba02008-11-07 14:05:41 -0800196
Daniel Vettera48a62b2015-10-02 13:01:02 +0200197 mutex_lock(&connector->dev->mode_config.mutex);
Dave Airlief453ba02008-11-07 14:05:41 -0800198 if (!connector->edid_blob_ptr)
Daniel Vettera48a62b2015-10-02 13:01:02 +0200199 goto unlock;
Dave Airlief453ba02008-11-07 14:05:41 -0800200
201 edid = connector->edid_blob_ptr->data;
202 size = connector->edid_blob_ptr->length;
203 if (!edid)
Daniel Vettera48a62b2015-10-02 13:01:02 +0200204 goto unlock;
Dave Airlief453ba02008-11-07 14:05:41 -0800205
206 if (off >= size)
Daniel Vettera48a62b2015-10-02 13:01:02 +0200207 goto unlock;
Dave Airlief453ba02008-11-07 14:05:41 -0800208
209 if (off + count > size)
210 count = size - off;
211 memcpy(buf, edid + off, count);
212
Daniel Vettera48a62b2015-10-02 13:01:02 +0200213 ret = count;
214unlock:
215 mutex_unlock(&connector->dev->mode_config.mutex);
216
217 return ret;
Dave Airlief453ba02008-11-07 14:05:41 -0800218}
219
220static ssize_t modes_show(struct device *device,
221 struct device_attribute *attr,
222 char *buf)
223{
224 struct drm_connector *connector = to_drm_connector(device);
225 struct drm_display_mode *mode;
226 int written = 0;
227
Daniel Vettera48a62b2015-10-02 13:01:02 +0200228 mutex_lock(&connector->dev->mode_config.mutex);
Dave Airlief453ba02008-11-07 14:05:41 -0800229 list_for_each_entry(mode, &connector->modes, head) {
Takashi Iwai9b9f2212020-03-11 08:35:40 +0100230 written += scnprintf(buf + written, PAGE_SIZE - written, "%s\n",
Dave Airlief453ba02008-11-07 14:05:41 -0800231 mode->name);
232 }
Daniel Vettera48a62b2015-10-02 13:01:02 +0200233 mutex_unlock(&connector->dev->mode_config.mutex);
Dave Airlief453ba02008-11-07 14:05:41 -0800234
235 return written;
236}
237
Chris Wilsonc484f022015-03-06 12:36:42 +0000238static DEVICE_ATTR_RW(status);
Takashi Iwai335f1a62015-02-04 11:58:53 +0100239static DEVICE_ATTR_RO(enabled);
240static DEVICE_ATTR_RO(dpms);
241static DEVICE_ATTR_RO(modes);
242
243static struct attribute *connector_dev_attrs[] = {
244 &dev_attr_status.attr,
245 &dev_attr_enabled.attr,
246 &dev_attr_dpms.attr,
247 &dev_attr_modes.attr,
248 NULL
Dave Airlief453ba02008-11-07 14:05:41 -0800249};
250
Dave Airlief453ba02008-11-07 14:05:41 -0800251static struct bin_attribute edid_attr = {
252 .attr.name = "edid",
Keith Packarde36ebaf2009-05-30 20:42:26 -0700253 .attr.mode = 0444,
Adam Jackson7466f4c2010-03-29 21:43:23 +0000254 .size = 0,
Dave Airlief453ba02008-11-07 14:05:41 -0800255 .read = edid_show,
256};
257
Takashi Iwai335f1a62015-02-04 11:58:53 +0100258static struct bin_attribute *connector_bin_attrs[] = {
259 &edid_attr,
260 NULL
261};
262
263static const struct attribute_group connector_dev_group = {
264 .attrs = connector_dev_attrs,
265 .bin_attrs = connector_bin_attrs,
266};
267
Takashi Iwai335f1a62015-02-04 11:58:53 +0100268static const struct attribute_group *connector_dev_groups[] = {
269 &connector_dev_group,
Takashi Iwai335f1a62015-02-04 11:58:53 +0100270 NULL
271};
272
Dave Airlief453ba02008-11-07 14:05:41 -0800273int drm_sysfs_connector_add(struct drm_connector *connector)
274{
275 struct drm_device *dev = connector->dev;
Dave Airlief453ba02008-11-07 14:05:41 -0800276
Dave Airlie5bdebb12013-10-11 14:07:25 +1000277 if (connector->kdev)
278 return 0;
279
Takashi Iwai335f1a62015-02-04 11:58:53 +0100280 connector->kdev =
281 device_create_with_groups(drm_class, dev->primary->kdev, 0,
282 connector, connector_dev_groups,
283 "card%d-%s", dev->primary->index,
284 connector->name);
Dave Airlief453ba02008-11-07 14:05:41 -0800285 DRM_DEBUG("adding \"%s\" to sysfs\n",
Jani Nikula25933822014-06-03 14:56:20 +0300286 connector->name);
Dave Airlief453ba02008-11-07 14:05:41 -0800287
Dave Airlie5bdebb12013-10-11 14:07:25 +1000288 if (IS_ERR(connector->kdev)) {
289 DRM_ERROR("failed to register connector device: %ld\n", PTR_ERR(connector->kdev));
Takashi Iwai335f1a62015-02-04 11:58:53 +0100290 return PTR_ERR(connector->kdev);
Dave Airlief453ba02008-11-07 14:05:41 -0800291 }
292
Andrzej Pietrasiewicze1a29c62019-07-26 19:22:55 +0200293 if (connector->ddc)
294 return sysfs_create_link(&connector->kdev->kobj,
295 &connector->ddc->dev.kobj, "ddc");
Dave Airlief453ba02008-11-07 14:05:41 -0800296 return 0;
Dave Airlief453ba02008-11-07 14:05:41 -0800297}
Dave Airlief453ba02008-11-07 14:05:41 -0800298
Dave Airlief453ba02008-11-07 14:05:41 -0800299void drm_sysfs_connector_remove(struct drm_connector *connector)
300{
Dave Airlie5bdebb12013-10-11 14:07:25 +1000301 if (!connector->kdev)
Dave Airlie1828fe62012-02-20 14:15:02 +0000302 return;
Andrzej Pietrasiewicze1a29c62019-07-26 19:22:55 +0200303
304 if (connector->ddc)
305 sysfs_remove_link(&connector->kdev->kobj, "ddc");
306
Dave Airlief453ba02008-11-07 14:05:41 -0800307 DRM_DEBUG("removing \"%s\" from sysfs\n",
Jani Nikula25933822014-06-03 14:56:20 +0300308 connector->name);
Dave Airlief453ba02008-11-07 14:05:41 -0800309
Dave Airlie5bdebb12013-10-11 14:07:25 +1000310 device_unregister(connector->kdev);
311 connector->kdev = NULL;
Dave Airlief453ba02008-11-07 14:05:41 -0800312}
Dave Airlief453ba02008-11-07 14:05:41 -0800313
Daniel Vetterce858822018-11-29 10:42:26 +0100314void drm_sysfs_lease_event(struct drm_device *dev)
315{
316 char *event_string = "LEASE=1";
317 char *envp[] = { event_string, NULL };
318
319 DRM_DEBUG("generating lease event\n");
320
321 kobject_uevent_env(&dev->primary->kdev->kobj, KOBJ_CHANGE, envp);
322}
323
Dave Airlief453ba02008-11-07 14:05:41 -0800324/**
325 * drm_sysfs_hotplug_event - generate a DRM uevent
326 * @dev: DRM device
327 *
328 * Send a uevent for the DRM device specified by @dev. Currently we only
329 * set HOTPLUG=1 in the uevent environment, but this could be expanded to
330 * deal with other types of events.
Ramalingam C6fe2ce02019-08-01 17:11:16 +0530331 *
332 * Any new uapi should be using the drm_sysfs_connector_status_event()
333 * for uevents on connector status change.
Dave Airlief453ba02008-11-07 14:05:41 -0800334 */
335void drm_sysfs_hotplug_event(struct drm_device *dev)
336{
337 char *event_string = "HOTPLUG=1";
338 char *envp[] = { event_string, NULL };
339
340 DRM_DEBUG("generating hotplug event\n");
341
Dave Airlie5bdebb12013-10-11 14:07:25 +1000342 kobject_uevent_env(&dev->primary->kdev->kobj, KOBJ_CHANGE, envp);
Dave Airlief453ba02008-11-07 14:05:41 -0800343}
Jesse Barnes5ca58282009-03-31 14:11:15 -0700344EXPORT_SYMBOL(drm_sysfs_hotplug_event);
Dave Airlief453ba02008-11-07 14:05:41 -0800345
Ramalingam C6fe2ce02019-08-01 17:11:16 +0530346/**
347 * drm_sysfs_connector_status_event - generate a DRM uevent for connector
348 * property status change
349 * @connector: connector on which property status changed
350 * @property: connector property whose status changed.
351 *
352 * Send a uevent for the DRM device specified by @dev. Currently we
353 * set HOTPLUG=1 and connector id along with the attached property id
354 * related to the status change.
355 */
356void drm_sysfs_connector_status_event(struct drm_connector *connector,
357 struct drm_property *property)
358{
359 struct drm_device *dev = connector->dev;
360 char hotplug_str[] = "HOTPLUG=1", conn_id[21], prop_id[21];
361 char *envp[4] = { hotplug_str, conn_id, prop_id, NULL };
362
363 WARN_ON(!drm_mode_obj_find_prop_id(&connector->base,
364 property->base.id));
365
366 snprintf(conn_id, ARRAY_SIZE(conn_id),
367 "CONNECTOR=%u", connector->base.id);
368 snprintf(prop_id, ARRAY_SIZE(prop_id),
369 "PROPERTY=%u", property->base.id);
370
371 DRM_DEBUG("generating connector status event\n");
372
373 kobject_uevent_env(&dev->primary->kdev->kobj, KOBJ_CHANGE, envp);
374}
375EXPORT_SYMBOL(drm_sysfs_connector_status_event);
376
David Herrmann760c9602013-11-21 20:50:50 +1000377static void drm_sysfs_release(struct device *dev)
378{
379 kfree(dev);
380}
381
David Herrmanne1728072014-07-23 11:38:38 +0200382struct device *drm_sysfs_minor_alloc(struct drm_minor *minor)
Jesse Barnese8b962b2007-11-22 14:02:38 +1000383{
David Herrmanne1728072014-07-23 11:38:38 +0200384 const char *minor_str;
385 struct device *kdev;
David Herrmann760c9602013-11-21 20:50:50 +1000386 int r;
Jesse Barnese8b962b2007-11-22 14:02:38 +1000387
Daniel Vetter0d49f302018-04-20 08:51:59 +0200388 if (minor->type == DRM_MINOR_RENDER)
David Herrmanne1728072014-07-23 11:38:38 +0200389 minor_str = "renderD%d";
390 else
391 minor_str = "card%d";
Jesse Barnese8b962b2007-11-22 14:02:38 +1000392
David Herrmanne1728072014-07-23 11:38:38 +0200393 kdev = kzalloc(sizeof(*kdev), GFP_KERNEL);
394 if (!kdev)
395 return ERR_PTR(-ENOMEM);
David Herrmann760c9602013-11-21 20:50:50 +1000396
David Herrmanne1728072014-07-23 11:38:38 +0200397 device_initialize(kdev);
398 kdev->devt = MKDEV(DRM_MAJOR, minor->index);
399 kdev->class = drm_class;
400 kdev->type = &drm_sysfs_device_minor;
401 kdev->parent = minor->dev->dev;
402 kdev->release = drm_sysfs_release;
403 dev_set_drvdata(kdev, minor);
David Herrmann760c9602013-11-21 20:50:50 +1000404
David Herrmanne1728072014-07-23 11:38:38 +0200405 r = dev_set_name(kdev, minor_str, minor->index);
David Herrmann760c9602013-11-21 20:50:50 +1000406 if (r < 0)
David Herrmanne1728072014-07-23 11:38:38 +0200407 goto err_free;
David Herrmann760c9602013-11-21 20:50:50 +1000408
David Herrmanne1728072014-07-23 11:38:38 +0200409 return kdev;
David Herrmann760c9602013-11-21 20:50:50 +1000410
David Herrmanne1728072014-07-23 11:38:38 +0200411err_free:
412 put_device(kdev);
413 return ERR_PTR(r);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414}
415
416/**
Daniel Vettere2271702017-04-04 11:52:55 +0200417 * drm_class_device_register - register new device with the DRM sysfs class
418 * @dev: device to register
Thomas Hellstrom327c2252009-08-17 16:28:37 +0200419 *
Daniel Vettere2271702017-04-04 11:52:55 +0200420 * Registers a new &struct device within the DRM sysfs class. Essentially only
421 * used by ttm to have a place for its global settings. Drivers should never use
422 * this.
Thomas Hellstrom327c2252009-08-17 16:28:37 +0200423 */
Thomas Hellstrom327c2252009-08-17 16:28:37 +0200424int drm_class_device_register(struct device *dev)
425{
Dave Airlie49099c42012-07-06 18:06:42 +0100426 if (!drm_class || IS_ERR(drm_class))
427 return -ENOENT;
428
Thomas Hellstrom327c2252009-08-17 16:28:37 +0200429 dev->class = drm_class;
430 return device_register(dev);
431}
432EXPORT_SYMBOL_GPL(drm_class_device_register);
433
Daniel Vettere2271702017-04-04 11:52:55 +0200434/**
435 * drm_class_device_unregister - unregister device with the DRM sysfs class
436 * @dev: device to unregister
437 *
438 * Unregisters a &struct device from the DRM sysfs class. Essentially only used
439 * by ttm to have a place for its global settings. Drivers should never use
440 * this.
441 */
Thomas Hellstrom327c2252009-08-17 16:28:37 +0200442void drm_class_device_unregister(struct device *dev)
443{
444 return device_unregister(dev);
445}
446EXPORT_SYMBOL_GPL(drm_class_device_unregister);