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> |
| 17 | #include <linux/err.h> |
| 18 | |
| 19 | #include "drm_core.h" |
Dave Airlie | f210973 | 2005-09-05 21:33:44 +1000 | [diff] [blame] | 20 | #include "drmP.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | |
Dave Airlie | 2c14f28 | 2008-04-21 16:47:32 +1000 | [diff] [blame] | 22 | #define to_drm_minor(d) container_of(d, struct drm_minor, kdev) |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 23 | #define to_drm_connector(d) container_of(d, struct drm_connector, kdev) |
Jesse Barnes | e8b962b | 2007-11-22 14:02:38 +1000 | [diff] [blame] | 24 | |
| 25 | /** |
| 26 | * drm_sysfs_suspend - DRM class suspend hook |
| 27 | * @dev: Linux device to suspend |
| 28 | * @state: power state to enter |
| 29 | * |
| 30 | * Just figures out what the actual struct drm_device associated with |
| 31 | * @dev is and calls its suspend hook, if present. |
| 32 | */ |
| 33 | static int drm_sysfs_suspend(struct device *dev, pm_message_t state) |
| 34 | { |
Dave Airlie | 2c14f28 | 2008-04-21 16:47:32 +1000 | [diff] [blame] | 35 | struct drm_minor *drm_minor = to_drm_minor(dev); |
| 36 | struct drm_device *drm_dev = drm_minor->dev; |
Jesse Barnes | e8b962b | 2007-11-22 14:02:38 +1000 | [diff] [blame] | 37 | |
Kristian Høgsberg | 112b715 | 2009-01-04 16:55:33 -0500 | [diff] [blame] | 38 | if (drm_minor->type == DRM_MINOR_LEGACY && |
| 39 | !drm_core_check_feature(drm_dev, DRIVER_MODESET) && |
| 40 | drm_dev->driver->suspend) |
Dave Airlie | b932ccb | 2008-02-20 10:02:20 +1000 | [diff] [blame] | 41 | return drm_dev->driver->suspend(drm_dev, state); |
Jesse Barnes | e8b962b | 2007-11-22 14:02:38 +1000 | [diff] [blame] | 42 | |
| 43 | return 0; |
| 44 | } |
| 45 | |
| 46 | /** |
| 47 | * drm_sysfs_resume - DRM class resume hook |
| 48 | * @dev: Linux device to resume |
| 49 | * |
| 50 | * Just figures out what the actual struct drm_device associated with |
| 51 | * @dev is and calls its resume hook, if present. |
| 52 | */ |
| 53 | static int drm_sysfs_resume(struct device *dev) |
| 54 | { |
Dave Airlie | 2c14f28 | 2008-04-21 16:47:32 +1000 | [diff] [blame] | 55 | struct drm_minor *drm_minor = to_drm_minor(dev); |
| 56 | struct drm_device *drm_dev = drm_minor->dev; |
Jesse Barnes | e8b962b | 2007-11-22 14:02:38 +1000 | [diff] [blame] | 57 | |
Kristian Høgsberg | 112b715 | 2009-01-04 16:55:33 -0500 | [diff] [blame] | 58 | if (drm_minor->type == DRM_MINOR_LEGACY && |
| 59 | !drm_core_check_feature(drm_dev, DRIVER_MODESET) && |
| 60 | drm_dev->driver->resume) |
Jesse Barnes | e8b962b | 2007-11-22 14:02:38 +1000 | [diff] [blame] | 61 | return drm_dev->driver->resume(drm_dev); |
| 62 | |
| 63 | return 0; |
| 64 | } |
| 65 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | /* Display the version of drm_core. This doesn't work right in current design */ |
| 67 | static ssize_t version_show(struct class *dev, char *buf) |
| 68 | { |
| 69 | return sprintf(buf, "%s %d.%d.%d %s\n", CORE_NAME, CORE_MAJOR, |
| 70 | CORE_MINOR, CORE_PATCHLEVEL, CORE_DATE); |
| 71 | } |
| 72 | |
Kay Sievers | 02200d0 | 2009-04-30 15:23:42 +0200 | [diff] [blame] | 73 | static char *drm_nodename(struct device *dev) |
| 74 | { |
| 75 | return kasprintf(GFP_KERNEL, "dri/%s", dev_name(dev)); |
| 76 | } |
| 77 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | static CLASS_ATTR(version, S_IRUGO, version_show, NULL); |
| 79 | |
| 80 | /** |
| 81 | * drm_sysfs_create - create a struct drm_sysfs_class structure |
| 82 | * @owner: pointer to the module that is to "own" this struct drm_sysfs_class |
| 83 | * @name: pointer to a string for the name of this class. |
| 84 | * |
Jesse Barnes | e8b962b | 2007-11-22 14:02:38 +1000 | [diff] [blame] | 85 | * This is used to create DRM class pointer that can then be used |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | * in calls to drm_sysfs_device_add(). |
| 87 | * |
| 88 | * Note, the pointer created here is to be destroyed when finished by making a |
| 89 | * call to drm_sysfs_destroy(). |
| 90 | */ |
Greg Kroah-Hartman | 0650fd5 | 2006-01-20 14:08:59 -0800 | [diff] [blame] | 91 | struct class *drm_sysfs_create(struct module *owner, char *name) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | { |
Greg Kroah-Hartman | 0650fd5 | 2006-01-20 14:08:59 -0800 | [diff] [blame] | 93 | struct class *class; |
Jeff Garzik | 24f73c9 | 2006-10-10 14:23:37 -0700 | [diff] [blame] | 94 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | |
Greg Kroah-Hartman | 0650fd5 | 2006-01-20 14:08:59 -0800 | [diff] [blame] | 96 | class = class_create(owner, name); |
Akinobu Mita | 94f060b | 2006-12-09 10:49:47 +1100 | [diff] [blame] | 97 | if (IS_ERR(class)) { |
| 98 | err = PTR_ERR(class); |
Jeff Garzik | 24f73c9 | 2006-10-10 14:23:37 -0700 | [diff] [blame] | 99 | goto err_out; |
| 100 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | |
Jesse Barnes | e8b962b | 2007-11-22 14:02:38 +1000 | [diff] [blame] | 102 | class->suspend = drm_sysfs_suspend; |
| 103 | class->resume = drm_sysfs_resume; |
| 104 | |
Jeff Garzik | 24f73c9 | 2006-10-10 14:23:37 -0700 | [diff] [blame] | 105 | err = class_create_file(class, &class_attr_version); |
| 106 | if (err) |
| 107 | goto err_out_class; |
| 108 | |
Kay Sievers | 02200d0 | 2009-04-30 15:23:42 +0200 | [diff] [blame] | 109 | class->nodename = drm_nodename; |
| 110 | |
Greg Kroah-Hartman | 0650fd5 | 2006-01-20 14:08:59 -0800 | [diff] [blame] | 111 | return class; |
Jeff Garzik | 24f73c9 | 2006-10-10 14:23:37 -0700 | [diff] [blame] | 112 | |
| 113 | err_out_class: |
| 114 | class_destroy(class); |
| 115 | err_out: |
| 116 | return ERR_PTR(err); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | } |
| 118 | |
| 119 | /** |
Jesse Barnes | e8b962b | 2007-11-22 14:02:38 +1000 | [diff] [blame] | 120 | * drm_sysfs_destroy - destroys DRM class |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | * |
Jesse Barnes | e8b962b | 2007-11-22 14:02:38 +1000 | [diff] [blame] | 122 | * Destroy the DRM device class. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | */ |
Jesse Barnes | e8b962b | 2007-11-22 14:02:38 +1000 | [diff] [blame] | 124 | void drm_sysfs_destroy(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | { |
Jesse Barnes | e8b962b | 2007-11-22 14:02:38 +1000 | [diff] [blame] | 126 | if ((drm_class == NULL) || (IS_ERR(drm_class))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | return; |
Jesse Barnes | e8b962b | 2007-11-22 14:02:38 +1000 | [diff] [blame] | 128 | class_remove_file(drm_class, &class_attr_version); |
| 129 | class_destroy(drm_class); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | } |
| 131 | |
| 132 | /** |
Jesse Barnes | e8b962b | 2007-11-22 14:02:38 +1000 | [diff] [blame] | 133 | * drm_sysfs_device_release - do nothing |
| 134 | * @dev: Linux device |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | * |
Jesse Barnes | e8b962b | 2007-11-22 14:02:38 +1000 | [diff] [blame] | 136 | * Normally, this would free the DRM device associated with @dev, along |
| 137 | * with cleaning up any other stuff. But we do that in the DRM core, so |
| 138 | * this function can just return and hope that the core does its job. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | */ |
Jesse Barnes | e8b962b | 2007-11-22 14:02:38 +1000 | [diff] [blame] | 140 | static void drm_sysfs_device_release(struct device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | { |
Ma Ling | 77d26dc | 2009-04-16 17:51:25 +0800 | [diff] [blame] | 142 | memset(dev, 0, sizeof(struct device)); |
Jesse Barnes | e8b962b | 2007-11-22 14:02:38 +1000 | [diff] [blame] | 143 | return; |
| 144 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 146 | /* |
| 147 | * Connector properties |
| 148 | */ |
| 149 | static ssize_t status_show(struct device *device, |
| 150 | struct device_attribute *attr, |
| 151 | char *buf) |
| 152 | { |
| 153 | struct drm_connector *connector = to_drm_connector(device); |
| 154 | enum drm_connector_status status; |
| 155 | |
| 156 | status = connector->funcs->detect(connector); |
Keith Packard | 75185c9 | 2009-05-30 20:42:25 -0700 | [diff] [blame] | 157 | return snprintf(buf, PAGE_SIZE, "%s\n", |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 158 | drm_get_connector_status_name(status)); |
| 159 | } |
| 160 | |
| 161 | static ssize_t dpms_show(struct device *device, |
| 162 | struct device_attribute *attr, |
| 163 | char *buf) |
| 164 | { |
| 165 | struct drm_connector *connector = to_drm_connector(device); |
| 166 | struct drm_device *dev = connector->dev; |
| 167 | uint64_t dpms_status; |
| 168 | int ret; |
| 169 | |
| 170 | ret = drm_connector_property_get_value(connector, |
| 171 | dev->mode_config.dpms_property, |
| 172 | &dpms_status); |
| 173 | if (ret) |
| 174 | return 0; |
| 175 | |
Keith Packard | 75185c9 | 2009-05-30 20:42:25 -0700 | [diff] [blame] | 176 | return snprintf(buf, PAGE_SIZE, "%s\n", |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 177 | drm_get_dpms_name((int)dpms_status)); |
| 178 | } |
| 179 | |
| 180 | static ssize_t enabled_show(struct device *device, |
| 181 | struct device_attribute *attr, |
| 182 | char *buf) |
| 183 | { |
| 184 | struct drm_connector *connector = to_drm_connector(device); |
| 185 | |
Keith Packard | 75185c9 | 2009-05-30 20:42:25 -0700 | [diff] [blame] | 186 | return snprintf(buf, PAGE_SIZE, "%s\n", connector->encoder ? "enabled" : |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 187 | "disabled"); |
| 188 | } |
| 189 | |
| 190 | static ssize_t edid_show(struct kobject *kobj, struct bin_attribute *attr, |
| 191 | char *buf, loff_t off, size_t count) |
| 192 | { |
| 193 | struct device *connector_dev = container_of(kobj, struct device, kobj); |
| 194 | struct drm_connector *connector = to_drm_connector(connector_dev); |
| 195 | unsigned char *edid; |
| 196 | size_t size; |
| 197 | |
| 198 | if (!connector->edid_blob_ptr) |
| 199 | return 0; |
| 200 | |
| 201 | edid = connector->edid_blob_ptr->data; |
| 202 | size = connector->edid_blob_ptr->length; |
| 203 | if (!edid) |
| 204 | return 0; |
| 205 | |
| 206 | if (off >= size) |
| 207 | return 0; |
| 208 | |
| 209 | if (off + count > size) |
| 210 | count = size - off; |
| 211 | memcpy(buf, edid + off, count); |
| 212 | |
| 213 | return count; |
| 214 | } |
| 215 | |
| 216 | static ssize_t modes_show(struct device *device, |
| 217 | struct device_attribute *attr, |
| 218 | char *buf) |
| 219 | { |
| 220 | struct drm_connector *connector = to_drm_connector(device); |
| 221 | struct drm_display_mode *mode; |
| 222 | int written = 0; |
| 223 | |
| 224 | list_for_each_entry(mode, &connector->modes, head) { |
| 225 | written += snprintf(buf + written, PAGE_SIZE - written, "%s\n", |
| 226 | mode->name); |
| 227 | } |
| 228 | |
| 229 | return written; |
| 230 | } |
| 231 | |
| 232 | static ssize_t subconnector_show(struct device *device, |
| 233 | struct device_attribute *attr, |
| 234 | char *buf) |
| 235 | { |
| 236 | struct drm_connector *connector = to_drm_connector(device); |
| 237 | struct drm_device *dev = connector->dev; |
| 238 | struct drm_property *prop = NULL; |
| 239 | uint64_t subconnector; |
| 240 | int is_tv = 0; |
| 241 | int ret; |
| 242 | |
| 243 | switch (connector->connector_type) { |
| 244 | case DRM_MODE_CONNECTOR_DVII: |
| 245 | prop = dev->mode_config.dvi_i_subconnector_property; |
| 246 | break; |
| 247 | case DRM_MODE_CONNECTOR_Composite: |
| 248 | case DRM_MODE_CONNECTOR_SVIDEO: |
| 249 | case DRM_MODE_CONNECTOR_Component: |
Francisco Jerez | 74bd3c2 | 2009-08-02 04:19:18 +0200 | [diff] [blame^] | 250 | case DRM_MODE_CONNECTOR_TV: |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 251 | prop = dev->mode_config.tv_subconnector_property; |
| 252 | is_tv = 1; |
| 253 | break; |
| 254 | default: |
| 255 | DRM_ERROR("Wrong connector type for this property\n"); |
| 256 | return 0; |
| 257 | } |
| 258 | |
| 259 | if (!prop) { |
| 260 | DRM_ERROR("Unable to find subconnector property\n"); |
| 261 | return 0; |
| 262 | } |
| 263 | |
| 264 | ret = drm_connector_property_get_value(connector, prop, &subconnector); |
| 265 | if (ret) |
| 266 | return 0; |
| 267 | |
| 268 | return snprintf(buf, PAGE_SIZE, "%s", is_tv ? |
| 269 | drm_get_tv_subconnector_name((int)subconnector) : |
| 270 | drm_get_dvi_i_subconnector_name((int)subconnector)); |
| 271 | } |
| 272 | |
| 273 | static ssize_t select_subconnector_show(struct device *device, |
| 274 | struct device_attribute *attr, |
| 275 | char *buf) |
| 276 | { |
| 277 | struct drm_connector *connector = to_drm_connector(device); |
| 278 | struct drm_device *dev = connector->dev; |
| 279 | struct drm_property *prop = NULL; |
| 280 | uint64_t subconnector; |
| 281 | int is_tv = 0; |
| 282 | int ret; |
| 283 | |
| 284 | switch (connector->connector_type) { |
| 285 | case DRM_MODE_CONNECTOR_DVII: |
| 286 | prop = dev->mode_config.dvi_i_select_subconnector_property; |
| 287 | break; |
| 288 | case DRM_MODE_CONNECTOR_Composite: |
| 289 | case DRM_MODE_CONNECTOR_SVIDEO: |
| 290 | case DRM_MODE_CONNECTOR_Component: |
Francisco Jerez | 74bd3c2 | 2009-08-02 04:19:18 +0200 | [diff] [blame^] | 291 | case DRM_MODE_CONNECTOR_TV: |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 292 | prop = dev->mode_config.tv_select_subconnector_property; |
| 293 | is_tv = 1; |
| 294 | break; |
| 295 | default: |
| 296 | DRM_ERROR("Wrong connector type for this property\n"); |
| 297 | return 0; |
| 298 | } |
| 299 | |
| 300 | if (!prop) { |
| 301 | DRM_ERROR("Unable to find select subconnector property\n"); |
| 302 | return 0; |
| 303 | } |
| 304 | |
| 305 | ret = drm_connector_property_get_value(connector, prop, &subconnector); |
| 306 | if (ret) |
| 307 | return 0; |
| 308 | |
| 309 | return snprintf(buf, PAGE_SIZE, "%s", is_tv ? |
| 310 | drm_get_tv_select_name((int)subconnector) : |
| 311 | drm_get_dvi_i_select_name((int)subconnector)); |
| 312 | } |
| 313 | |
| 314 | static struct device_attribute connector_attrs[] = { |
| 315 | __ATTR_RO(status), |
| 316 | __ATTR_RO(enabled), |
| 317 | __ATTR_RO(dpms), |
| 318 | __ATTR_RO(modes), |
| 319 | }; |
| 320 | |
| 321 | /* These attributes are for both DVI-I connectors and all types of tv-out. */ |
| 322 | static struct device_attribute connector_attrs_opt1[] = { |
| 323 | __ATTR_RO(subconnector), |
| 324 | __ATTR_RO(select_subconnector), |
| 325 | }; |
| 326 | |
| 327 | static struct bin_attribute edid_attr = { |
| 328 | .attr.name = "edid", |
Keith Packard | e36ebaf | 2009-05-30 20:42:26 -0700 | [diff] [blame] | 329 | .attr.mode = 0444, |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 330 | .size = 128, |
| 331 | .read = edid_show, |
| 332 | }; |
| 333 | |
| 334 | /** |
| 335 | * drm_sysfs_connector_add - add an connector to sysfs |
| 336 | * @connector: connector to add |
| 337 | * |
| 338 | * Create an connector device in sysfs, along with its associated connector |
| 339 | * properties (so far, connection status, dpms, mode list & edid) and |
| 340 | * generate a hotplug event so userspace knows there's a new connector |
| 341 | * available. |
| 342 | * |
| 343 | * Note: |
| 344 | * This routine should only be called *once* for each DRM minor registered. |
| 345 | * A second call for an already registered device will trigger the BUG_ON |
| 346 | * below. |
| 347 | */ |
| 348 | int drm_sysfs_connector_add(struct drm_connector *connector) |
| 349 | { |
| 350 | struct drm_device *dev = connector->dev; |
| 351 | int ret = 0, i, j; |
| 352 | |
| 353 | /* We shouldn't get called more than once for the same connector */ |
| 354 | BUG_ON(device_is_registered(&connector->kdev)); |
| 355 | |
| 356 | connector->kdev.parent = &dev->primary->kdev; |
| 357 | connector->kdev.class = drm_class; |
| 358 | connector->kdev.release = drm_sysfs_device_release; |
| 359 | |
| 360 | DRM_DEBUG("adding \"%s\" to sysfs\n", |
| 361 | drm_get_connector_name(connector)); |
| 362 | |
Kay Sievers | 2ead054 | 2009-03-24 16:38:22 -0700 | [diff] [blame] | 363 | dev_set_name(&connector->kdev, "card%d-%s", |
| 364 | dev->primary->index, drm_get_connector_name(connector)); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 365 | ret = device_register(&connector->kdev); |
| 366 | |
| 367 | if (ret) { |
| 368 | DRM_ERROR("failed to register connector device: %d\n", ret); |
| 369 | goto out; |
| 370 | } |
| 371 | |
| 372 | /* Standard attributes */ |
| 373 | |
| 374 | for (i = 0; i < ARRAY_SIZE(connector_attrs); i++) { |
| 375 | ret = device_create_file(&connector->kdev, &connector_attrs[i]); |
| 376 | if (ret) |
| 377 | goto err_out_files; |
| 378 | } |
| 379 | |
| 380 | /* Optional attributes */ |
| 381 | /* |
| 382 | * In the long run it maybe a good idea to make one set of |
| 383 | * optionals per connector type. |
| 384 | */ |
| 385 | switch (connector->connector_type) { |
| 386 | case DRM_MODE_CONNECTOR_DVII: |
| 387 | case DRM_MODE_CONNECTOR_Composite: |
| 388 | case DRM_MODE_CONNECTOR_SVIDEO: |
| 389 | case DRM_MODE_CONNECTOR_Component: |
Francisco Jerez | 74bd3c2 | 2009-08-02 04:19:18 +0200 | [diff] [blame^] | 390 | case DRM_MODE_CONNECTOR_TV: |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 391 | for (i = 0; i < ARRAY_SIZE(connector_attrs_opt1); i++) { |
| 392 | ret = device_create_file(&connector->kdev, &connector_attrs_opt1[i]); |
| 393 | if (ret) |
| 394 | goto err_out_files; |
| 395 | } |
| 396 | break; |
| 397 | default: |
| 398 | break; |
| 399 | } |
| 400 | |
| 401 | ret = sysfs_create_bin_file(&connector->kdev.kobj, &edid_attr); |
| 402 | if (ret) |
| 403 | goto err_out_files; |
| 404 | |
| 405 | /* Let userspace know we have a new connector */ |
| 406 | drm_sysfs_hotplug_event(dev); |
| 407 | |
| 408 | return 0; |
| 409 | |
| 410 | err_out_files: |
| 411 | if (i > 0) |
| 412 | for (j = 0; j < i; j++) |
| 413 | device_remove_file(&connector->kdev, |
| 414 | &connector_attrs[i]); |
| 415 | device_unregister(&connector->kdev); |
| 416 | |
| 417 | out: |
| 418 | return ret; |
| 419 | } |
| 420 | EXPORT_SYMBOL(drm_sysfs_connector_add); |
| 421 | |
| 422 | /** |
| 423 | * drm_sysfs_connector_remove - remove an connector device from sysfs |
| 424 | * @connector: connector to remove |
| 425 | * |
| 426 | * Remove @connector and its associated attributes from sysfs. Note that |
| 427 | * the device model core will take care of sending the "remove" uevent |
| 428 | * at this time, so we don't need to do it. |
| 429 | * |
| 430 | * Note: |
| 431 | * This routine should only be called if the connector was previously |
| 432 | * successfully registered. If @connector hasn't been registered yet, |
| 433 | * you'll likely see a panic somewhere deep in sysfs code when called. |
| 434 | */ |
| 435 | void drm_sysfs_connector_remove(struct drm_connector *connector) |
| 436 | { |
| 437 | int i; |
| 438 | |
| 439 | DRM_DEBUG("removing \"%s\" from sysfs\n", |
| 440 | drm_get_connector_name(connector)); |
| 441 | |
| 442 | for (i = 0; i < ARRAY_SIZE(connector_attrs); i++) |
| 443 | device_remove_file(&connector->kdev, &connector_attrs[i]); |
| 444 | sysfs_remove_bin_file(&connector->kdev.kobj, &edid_attr); |
| 445 | device_unregister(&connector->kdev); |
| 446 | } |
| 447 | EXPORT_SYMBOL(drm_sysfs_connector_remove); |
| 448 | |
| 449 | /** |
| 450 | * drm_sysfs_hotplug_event - generate a DRM uevent |
| 451 | * @dev: DRM device |
| 452 | * |
| 453 | * Send a uevent for the DRM device specified by @dev. Currently we only |
| 454 | * set HOTPLUG=1 in the uevent environment, but this could be expanded to |
| 455 | * deal with other types of events. |
| 456 | */ |
| 457 | void drm_sysfs_hotplug_event(struct drm_device *dev) |
| 458 | { |
| 459 | char *event_string = "HOTPLUG=1"; |
| 460 | char *envp[] = { event_string, NULL }; |
| 461 | |
| 462 | DRM_DEBUG("generating hotplug event\n"); |
| 463 | |
| 464 | kobject_uevent_env(&dev->primary->kdev.kobj, KOBJ_CHANGE, envp); |
| 465 | } |
Jesse Barnes | 5ca5828 | 2009-03-31 14:11:15 -0700 | [diff] [blame] | 466 | EXPORT_SYMBOL(drm_sysfs_hotplug_event); |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 467 | |
Jesse Barnes | e8b962b | 2007-11-22 14:02:38 +1000 | [diff] [blame] | 468 | /** |
| 469 | * drm_sysfs_device_add - adds a class device to sysfs for a character driver |
| 470 | * @dev: DRM device to be added |
| 471 | * @head: DRM head in question |
| 472 | * |
| 473 | * Add a DRM device to the DRM's device model class. We use @dev's PCI device |
| 474 | * as the parent for the Linux device, and make sure it has a file containing |
| 475 | * the driver we're using (for userspace compatibility). |
| 476 | */ |
Dave Airlie | 2c14f28 | 2008-04-21 16:47:32 +1000 | [diff] [blame] | 477 | int drm_sysfs_device_add(struct drm_minor *minor) |
Jesse Barnes | e8b962b | 2007-11-22 14:02:38 +1000 | [diff] [blame] | 478 | { |
| 479 | int err; |
Dave Airlie | 2c14f28 | 2008-04-21 16:47:32 +1000 | [diff] [blame] | 480 | char *minor_str; |
Jesse Barnes | e8b962b | 2007-11-22 14:02:38 +1000 | [diff] [blame] | 481 | |
Dave Airlie | 2c14f28 | 2008-04-21 16:47:32 +1000 | [diff] [blame] | 482 | minor->kdev.parent = &minor->dev->pdev->dev; |
| 483 | minor->kdev.class = drm_class; |
| 484 | minor->kdev.release = drm_sysfs_device_release; |
| 485 | minor->kdev.devt = minor->device; |
Dave Airlie | f453ba0 | 2008-11-07 14:05:41 -0800 | [diff] [blame] | 486 | if (minor->type == DRM_MINOR_CONTROL) |
| 487 | minor_str = "controlD%d"; |
| 488 | else if (minor->type == DRM_MINOR_RENDER) |
| 489 | minor_str = "renderD%d"; |
| 490 | else |
| 491 | minor_str = "card%d"; |
Jesse Barnes | e8b962b | 2007-11-22 14:02:38 +1000 | [diff] [blame] | 492 | |
Kay Sievers | 8f4bbd9 | 2009-01-06 10:44:41 -0800 | [diff] [blame] | 493 | dev_set_name(&minor->kdev, minor_str, minor->index); |
Dave Airlie | 2c14f28 | 2008-04-21 16:47:32 +1000 | [diff] [blame] | 494 | |
| 495 | err = device_register(&minor->kdev); |
Jesse Barnes | e8b962b | 2007-11-22 14:02:38 +1000 | [diff] [blame] | 496 | if (err) { |
| 497 | DRM_ERROR("device add failed: %d\n", err); |
Jeff Garzik | 24f73c9 | 2006-10-10 14:23:37 -0700 | [diff] [blame] | 498 | goto err_out; |
| 499 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 500 | |
Jesse Barnes | e8b962b | 2007-11-22 14:02:38 +1000 | [diff] [blame] | 501 | return 0; |
Jeff Garzik | 24f73c9 | 2006-10-10 14:23:37 -0700 | [diff] [blame] | 502 | |
Jeff Garzik | 24f73c9 | 2006-10-10 14:23:37 -0700 | [diff] [blame] | 503 | err_out: |
Jesse Barnes | e8b962b | 2007-11-22 14:02:38 +1000 | [diff] [blame] | 504 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 505 | } |
| 506 | |
| 507 | /** |
Jesse Barnes | e8b962b | 2007-11-22 14:02:38 +1000 | [diff] [blame] | 508 | * drm_sysfs_device_remove - remove DRM device |
| 509 | * @dev: DRM device to remove |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 510 | * |
| 511 | * This call unregisters and cleans up a class device that was created with a |
| 512 | * call to drm_sysfs_device_add() |
| 513 | */ |
Dave Airlie | 2c14f28 | 2008-04-21 16:47:32 +1000 | [diff] [blame] | 514 | void drm_sysfs_device_remove(struct drm_minor *minor) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 515 | { |
Dave Airlie | 2c14f28 | 2008-04-21 16:47:32 +1000 | [diff] [blame] | 516 | device_unregister(&minor->kdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 517 | } |