aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/char/drm/drm_sysfs.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/char/drm/drm_sysfs.c')
-rw-r--r--drivers/char/drm/drm_sysfs.c146
1 files changed, 97 insertions, 49 deletions
diff --git a/drivers/char/drm/drm_sysfs.c b/drivers/char/drm/drm_sysfs.c
index cf4349b00b07..fa36153619e8 100644
--- a/drivers/char/drm/drm_sysfs.c
+++ b/drivers/char/drm/drm_sysfs.c
@@ -19,6 +19,45 @@
19#include "drm_core.h" 19#include "drm_core.h"
20#include "drmP.h" 20#include "drmP.h"
21 21
22#define to_drm_device(d) container_of(d, struct drm_device, dev)
23
24/**
25 * drm_sysfs_suspend - DRM class suspend hook
26 * @dev: Linux device to suspend
27 * @state: power state to enter
28 *
29 * Just figures out what the actual struct drm_device associated with
30 * @dev is and calls its suspend hook, if present.
31 */
32static int drm_sysfs_suspend(struct device *dev, pm_message_t state)
33{
34 struct drm_device *drm_dev = to_drm_device(dev);
35
36 printk(KERN_ERR "%s\n", __FUNCTION__);
37
38 if (drm_dev->driver->suspend)
39 return drm_dev->driver->suspend(drm_dev);
40
41 return 0;
42}
43
44/**
45 * drm_sysfs_resume - DRM class resume hook
46 * @dev: Linux device to resume
47 *
48 * Just figures out what the actual struct drm_device associated with
49 * @dev is and calls its resume hook, if present.
50 */
51static int drm_sysfs_resume(struct device *dev)
52{
53 struct drm_device *drm_dev = to_drm_device(dev);
54
55 if (drm_dev->driver->resume)
56 return drm_dev->driver->resume(drm_dev);
57
58 return 0;
59}
60
22/* Display the version of drm_core. This doesn't work right in current design */ 61/* Display the version of drm_core. This doesn't work right in current design */
23static ssize_t version_show(struct class *dev, char *buf) 62static ssize_t version_show(struct class *dev, char *buf)
24{ 63{
@@ -33,7 +72,7 @@ static CLASS_ATTR(version, S_IRUGO, version_show, NULL);
33 * @owner: pointer to the module that is to "own" this struct drm_sysfs_class 72 * @owner: pointer to the module that is to "own" this struct drm_sysfs_class
34 * @name: pointer to a string for the name of this class. 73 * @name: pointer to a string for the name of this class.
35 * 74 *
36 * This is used to create a struct drm_sysfs_class pointer that can then be used 75 * This is used to create DRM class pointer that can then be used
37 * in calls to drm_sysfs_device_add(). 76 * in calls to drm_sysfs_device_add().
38 * 77 *
39 * Note, the pointer created here is to be destroyed when finished by making a 78 * Note, the pointer created here is to be destroyed when finished by making a
@@ -50,6 +89,9 @@ struct class *drm_sysfs_create(struct module *owner, char *name)
50 goto err_out; 89 goto err_out;
51 } 90 }
52 91
92 class->suspend = drm_sysfs_suspend;
93 class->resume = drm_sysfs_resume;
94
53 err = class_create_file(class, &class_attr_version); 95 err = class_create_file(class, &class_attr_version);
54 if (err) 96 if (err)
55 goto err_out_class; 97 goto err_out_class;
@@ -63,94 +105,100 @@ err_out:
63} 105}
64 106
65/** 107/**
66 * drm_sysfs_destroy - destroys a struct drm_sysfs_class structure 108 * drm_sysfs_destroy - destroys DRM class
67 * @cs: pointer to the struct drm_sysfs_class that is to be destroyed
68 * 109 *
69 * Note, the pointer to be destroyed must have been created with a call to 110 * Destroy the DRM device class.
70 * drm_sysfs_create().
71 */ 111 */
72void drm_sysfs_destroy(struct class *class) 112void drm_sysfs_destroy(void)
73{ 113{
74 if ((class == NULL) || (IS_ERR(class))) 114 if ((drm_class == NULL) || (IS_ERR(drm_class)))
75 return; 115 return;
76 116 class_remove_file(drm_class, &class_attr_version);
77 class_remove_file(class, &class_attr_version); 117 class_destroy(drm_class);
78 class_destroy(class);
79} 118}
80 119
81static ssize_t show_dri(struct class_device *class_device, char *buf) 120static ssize_t show_dri(struct device *device, struct device_attribute *attr,
121 char *buf)
82{ 122{
83 struct drm_device * dev = ((struct drm_head *)class_get_devdata(class_device))->dev; 123 struct drm_device *dev = to_drm_device(device);
84 if (dev->driver->dri_library_name) 124 if (dev->driver->dri_library_name)
85 return dev->driver->dri_library_name(dev, buf); 125 return dev->driver->dri_library_name(dev, buf);
86 return snprintf(buf, PAGE_SIZE, "%s\n", dev->driver->pci_driver.name); 126 return snprintf(buf, PAGE_SIZE, "%s\n", dev->driver->pci_driver.name);
87} 127}
88 128
89static struct class_device_attribute class_device_attrs[] = { 129static struct device_attribute device_attrs[] = {
90 __ATTR(dri_library_name, S_IRUGO, show_dri, NULL), 130 __ATTR(dri_library_name, S_IRUGO, show_dri, NULL),
91}; 131};
92 132
93/** 133/**
134 * drm_sysfs_device_release - do nothing
135 * @dev: Linux device
136 *
137 * Normally, this would free the DRM device associated with @dev, along
138 * with cleaning up any other stuff. But we do that in the DRM core, so
139 * this function can just return and hope that the core does its job.
140 */
141static void drm_sysfs_device_release(struct device *dev)
142{
143 return;
144}
145
146/**
94 * drm_sysfs_device_add - adds a class device to sysfs for a character driver 147 * drm_sysfs_device_add - adds a class device to sysfs for a character driver
95 * @cs: pointer to the struct class that this device should be registered to. 148 * @dev: DRM device to be added
96 * @dev: the dev_t for the device to be added. 149 * @head: DRM head in question
97 * @device: a pointer to a struct device that is assiociated with this class device.
98 * @fmt: string for the class device's name
99 * 150 *
100 * A struct class_device will be created in sysfs, registered to the specified 151 * Add a DRM device to the DRM's device model class. We use @dev's PCI device
101 * class. A "dev" file will be created, showing the dev_t for the device. The 152 * as the parent for the Linux device, and make sure it has a file containing
102 * pointer to the struct class_device will be returned from the call. Any further 153 * the driver we're using (for userspace compatibility).
103 * sysfs files that might be required can be created using this pointer.
104 * Note: the struct class passed to this function must have previously been
105 * created with a call to drm_sysfs_create().
106 */ 154 */
107struct class_device *drm_sysfs_device_add(struct class *cs, struct drm_head *head) 155int drm_sysfs_device_add(struct drm_device *dev, struct drm_head *head)
108{ 156{
109 struct class_device *class_dev; 157 int err;
110 int i, j, err; 158 int i, j;
111 159
112 class_dev = class_device_create(cs, NULL, 160 dev->dev.parent = &dev->pdev->dev;
113 MKDEV(DRM_MAJOR, head->minor), 161 dev->dev.class = drm_class;
114 &(head->dev->pdev)->dev, 162 dev->dev.release = drm_sysfs_device_release;
115 "card%d", head->minor); 163 dev->dev.devt = head->device;
116 if (IS_ERR(class_dev)) { 164 snprintf(dev->dev.bus_id, BUS_ID_SIZE, "card%d", head->minor);
117 err = PTR_ERR(class_dev); 165
166 err = device_register(&dev->dev);
167 if (err) {
168 DRM_ERROR("device add failed: %d\n", err);
118 goto err_out; 169 goto err_out;
119 } 170 }
120 171
121 class_set_devdata(class_dev, head); 172 for (i = 0; i < ARRAY_SIZE(device_attrs); i++) {
122 173 err = device_create_file(&dev->dev, &device_attrs[i]);
123 for (i = 0; i < ARRAY_SIZE(class_device_attrs); i++) {
124 err = class_device_create_file(class_dev,
125 &class_device_attrs[i]);
126 if (err) 174 if (err)
127 goto err_out_files; 175 goto err_out_files;
128 } 176 }
129 177
130 return class_dev; 178 return 0;
131 179
132err_out_files: 180err_out_files:
133 if (i > 0) 181 if (i > 0)
134 for (j = 0; j < i; j++) 182 for (j = 0; j < i; j++)
135 class_device_remove_file(class_dev, 183 device_remove_file(&dev->dev, &device_attrs[i]);
136 &class_device_attrs[i]); 184 device_unregister(&dev->dev);
137 class_device_unregister(class_dev);
138err_out: 185err_out:
139 return ERR_PTR(err); 186
187 return err;
140} 188}
141 189
142/** 190/**
143 * drm_sysfs_device_remove - removes a class device that was created with drm_sysfs_device_add() 191 * drm_sysfs_device_remove - remove DRM device
144 * @dev: the dev_t of the device that was previously registered. 192 * @dev: DRM device to remove
145 * 193 *
146 * This call unregisters and cleans up a class device that was created with a 194 * This call unregisters and cleans up a class device that was created with a
147 * call to drm_sysfs_device_add() 195 * call to drm_sysfs_device_add()
148 */ 196 */
149void drm_sysfs_device_remove(struct class_device *class_dev) 197void drm_sysfs_device_remove(struct drm_device *dev)
150{ 198{
151 int i; 199 int i;
152 200
153 for (i = 0; i < ARRAY_SIZE(class_device_attrs); i++) 201 for (i = 0; i < ARRAY_SIZE(device_attrs); i++)
154 class_device_remove_file(class_dev, &class_device_attrs[i]); 202 device_remove_file(&dev->dev, &device_attrs[i]);
155 class_device_unregister(class_dev); 203 device_unregister(&dev->dev);
156} 204}