Merge git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6
[wrt350n-kernel.git] / drivers / char / drm / drm_sysfs.c
blob440df422d969fe95509a0ce0dd970c7b24f6a644
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.
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.
11 * This file is released under the GPLv2
15 #include <linux/device.h>
16 #include <linux/kdev_t.h>
17 #include <linux/err.h>
19 #include "drm_core.h"
20 #include "drmP.h"
22 #define to_drm_device(d) container_of(d, struct drm_device, dev)
24 /**
25 * drm_sysfs_suspend - DRM class suspend hook
26 * @dev: Linux device to suspend
27 * @state: power state to enter
29 * Just figures out what the actual struct drm_device associated with
30 * @dev is and calls its suspend hook, if present.
32 static int drm_sysfs_suspend(struct device *dev, pm_message_t state)
34 struct drm_device *drm_dev = to_drm_device(dev);
36 printk(KERN_ERR "%s\n", __FUNCTION__);
38 if (drm_dev->driver->suspend)
39 <<<<<<< HEAD:drivers/char/drm/drm_sysfs.c
40 return drm_dev->driver->suspend(drm_dev);
41 =======
42 return drm_dev->driver->suspend(drm_dev, state);
43 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:drivers/char/drm/drm_sysfs.c
45 return 0;
48 /**
49 * drm_sysfs_resume - DRM class resume hook
50 * @dev: Linux device to resume
52 * Just figures out what the actual struct drm_device associated with
53 * @dev is and calls its resume hook, if present.
55 static int drm_sysfs_resume(struct device *dev)
57 struct drm_device *drm_dev = to_drm_device(dev);
59 if (drm_dev->driver->resume)
60 return drm_dev->driver->resume(drm_dev);
62 return 0;
65 /* Display the version of drm_core. This doesn't work right in current design */
66 static ssize_t version_show(struct class *dev, char *buf)
68 return sprintf(buf, "%s %d.%d.%d %s\n", CORE_NAME, CORE_MAJOR,
69 CORE_MINOR, CORE_PATCHLEVEL, CORE_DATE);
72 static CLASS_ATTR(version, S_IRUGO, version_show, NULL);
74 /**
75 * drm_sysfs_create - create a struct drm_sysfs_class structure
76 * @owner: pointer to the module that is to "own" this struct drm_sysfs_class
77 * @name: pointer to a string for the name of this class.
79 * This is used to create DRM class pointer that can then be used
80 * in calls to drm_sysfs_device_add().
82 * Note, the pointer created here is to be destroyed when finished by making a
83 * call to drm_sysfs_destroy().
85 struct class *drm_sysfs_create(struct module *owner, char *name)
87 struct class *class;
88 int err;
90 class = class_create(owner, name);
91 if (IS_ERR(class)) {
92 err = PTR_ERR(class);
93 goto err_out;
96 class->suspend = drm_sysfs_suspend;
97 class->resume = drm_sysfs_resume;
99 err = class_create_file(class, &class_attr_version);
100 if (err)
101 goto err_out_class;
103 return class;
105 err_out_class:
106 class_destroy(class);
107 err_out:
108 return ERR_PTR(err);
112 * drm_sysfs_destroy - destroys DRM class
114 * Destroy the DRM device class.
116 void drm_sysfs_destroy(void)
118 if ((drm_class == NULL) || (IS_ERR(drm_class)))
119 return;
120 class_remove_file(drm_class, &class_attr_version);
121 class_destroy(drm_class);
124 static ssize_t show_dri(struct device *device, struct device_attribute *attr,
125 char *buf)
127 struct drm_device *dev = to_drm_device(device);
128 if (dev->driver->dri_library_name)
129 return dev->driver->dri_library_name(dev, buf);
130 return snprintf(buf, PAGE_SIZE, "%s\n", dev->driver->pci_driver.name);
133 static struct device_attribute device_attrs[] = {
134 __ATTR(dri_library_name, S_IRUGO, show_dri, NULL),
138 * drm_sysfs_device_release - do nothing
139 * @dev: Linux device
141 * Normally, this would free the DRM device associated with @dev, along
142 * with cleaning up any other stuff. But we do that in the DRM core, so
143 * this function can just return and hope that the core does its job.
145 static void drm_sysfs_device_release(struct device *dev)
147 return;
151 * drm_sysfs_device_add - adds a class device to sysfs for a character driver
152 * @dev: DRM device to be added
153 * @head: DRM head in question
155 * Add a DRM device to the DRM's device model class. We use @dev's PCI device
156 * as the parent for the Linux device, and make sure it has a file containing
157 * the driver we're using (for userspace compatibility).
159 int drm_sysfs_device_add(struct drm_device *dev, struct drm_head *head)
161 int err;
162 int i, j;
164 dev->dev.parent = &dev->pdev->dev;
165 dev->dev.class = drm_class;
166 dev->dev.release = drm_sysfs_device_release;
167 dev->dev.devt = head->device;
168 snprintf(dev->dev.bus_id, BUS_ID_SIZE, "card%d", head->minor);
170 err = device_register(&dev->dev);
171 if (err) {
172 DRM_ERROR("device add failed: %d\n", err);
173 goto err_out;
176 for (i = 0; i < ARRAY_SIZE(device_attrs); i++) {
177 err = device_create_file(&dev->dev, &device_attrs[i]);
178 if (err)
179 goto err_out_files;
182 return 0;
184 err_out_files:
185 if (i > 0)
186 for (j = 0; j < i; j++)
187 device_remove_file(&dev->dev, &device_attrs[i]);
188 device_unregister(&dev->dev);
189 err_out:
191 return err;
195 * drm_sysfs_device_remove - remove DRM device
196 * @dev: DRM device to remove
198 * This call unregisters and cleans up a class device that was created with a
199 * call to drm_sysfs_device_add()
201 void drm_sysfs_device_remove(struct drm_device *dev)
203 int i;
205 for (i = 0; i < ARRAY_SIZE(device_attrs); i++)
206 device_remove_file(&dev->dev, &device_attrs[i]);
207 device_unregister(&dev->dev);