Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * sys.c - pseudo-bus for system 'devices' (cpus, PICs, timers, etc) |
| 3 | * |
| 4 | * Copyright (c) 2002-3 Patrick Mochel |
| 5 | * 2002-3 Open Source Development Lab |
| 6 | * |
| 7 | * This file is released under the GPLv2 |
| 8 | * |
| 9 | * This exports a 'system' bus type. |
| 10 | * By default, a 'sys' bus gets added to the root of the system. There will |
| 11 | * always be core system devices. Devices can use sysdev_register() to |
| 12 | * add themselves as children of the system bus. |
| 13 | */ |
| 14 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | #include <linux/sysdev.h> |
| 16 | #include <linux/err.h> |
| 17 | #include <linux/module.h> |
| 18 | #include <linux/kernel.h> |
| 19 | #include <linux/init.h> |
| 20 | #include <linux/slab.h> |
| 21 | #include <linux/string.h> |
Pavel Machek | 438510f | 2005-04-16 15:25:24 -0700 | [diff] [blame] | 22 | #include <linux/pm.h> |
Adrian Bunk | f67d115 | 2006-01-19 17:30:17 +0100 | [diff] [blame] | 23 | #include <linux/device.h> |
Matthias Kaehlcke | 9f3f776 | 2007-05-23 14:19:42 -0700 | [diff] [blame] | 24 | #include <linux/mutex.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | |
Adrian Bunk | f67d115 | 2006-01-19 17:30:17 +0100 | [diff] [blame] | 26 | #include "base.h" |
| 27 | |
Greg Kroah-Hartman | 823bccf | 2007-04-13 13:15:19 -0700 | [diff] [blame] | 28 | extern struct kset devices_subsys; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | |
| 30 | #define to_sysdev(k) container_of(k, struct sys_device, kobj) |
| 31 | #define to_sysdev_attr(a) container_of(a, struct sysdev_attribute, attr) |
| 32 | |
| 33 | |
| 34 | static ssize_t |
| 35 | sysdev_show(struct kobject * kobj, struct attribute * attr, char * buffer) |
| 36 | { |
| 37 | struct sys_device * sysdev = to_sysdev(kobj); |
| 38 | struct sysdev_attribute * sysdev_attr = to_sysdev_attr(attr); |
| 39 | |
| 40 | if (sysdev_attr->show) |
| 41 | return sysdev_attr->show(sysdev, buffer); |
Dmitry Torokhov | 4a0c20b | 2005-04-29 01:23:47 -0500 | [diff] [blame] | 42 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | } |
| 44 | |
| 45 | |
| 46 | static ssize_t |
| 47 | sysdev_store(struct kobject * kobj, struct attribute * attr, |
| 48 | const char * buffer, size_t count) |
| 49 | { |
| 50 | struct sys_device * sysdev = to_sysdev(kobj); |
| 51 | struct sysdev_attribute * sysdev_attr = to_sysdev_attr(attr); |
| 52 | |
| 53 | if (sysdev_attr->store) |
| 54 | return sysdev_attr->store(sysdev, buffer, count); |
Dmitry Torokhov | 4a0c20b | 2005-04-29 01:23:47 -0500 | [diff] [blame] | 55 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | static struct sysfs_ops sysfs_ops = { |
| 59 | .show = sysdev_show, |
| 60 | .store = sysdev_store, |
| 61 | }; |
| 62 | |
| 63 | static struct kobj_type ktype_sysdev = { |
| 64 | .sysfs_ops = &sysfs_ops, |
| 65 | }; |
| 66 | |
| 67 | |
| 68 | int sysdev_create_file(struct sys_device * s, struct sysdev_attribute * a) |
| 69 | { |
| 70 | return sysfs_create_file(&s->kobj, &a->attr); |
| 71 | } |
| 72 | |
| 73 | |
| 74 | void sysdev_remove_file(struct sys_device * s, struct sysdev_attribute * a) |
| 75 | { |
| 76 | sysfs_remove_file(&s->kobj, &a->attr); |
| 77 | } |
| 78 | |
| 79 | EXPORT_SYMBOL_GPL(sysdev_create_file); |
| 80 | EXPORT_SYMBOL_GPL(sysdev_remove_file); |
| 81 | |
Shaohua Li | 670dd90 | 2006-05-08 13:45:57 +0800 | [diff] [blame] | 82 | #define to_sysdev_class(k) container_of(k, struct sysdev_class, kset.kobj) |
| 83 | #define to_sysdev_class_attr(a) container_of(a, \ |
| 84 | struct sysdev_class_attribute, attr) |
| 85 | |
| 86 | static ssize_t sysdev_class_show(struct kobject *kobj, struct attribute *attr, |
| 87 | char *buffer) |
| 88 | { |
| 89 | struct sysdev_class * class = to_sysdev_class(kobj); |
| 90 | struct sysdev_class_attribute *class_attr = to_sysdev_class_attr(attr); |
| 91 | |
| 92 | if (class_attr->show) |
| 93 | return class_attr->show(class, buffer); |
| 94 | return -EIO; |
| 95 | } |
| 96 | |
| 97 | static ssize_t sysdev_class_store(struct kobject *kobj, struct attribute *attr, |
| 98 | const char *buffer, size_t count) |
| 99 | { |
| 100 | struct sysdev_class * class = to_sysdev_class(kobj); |
| 101 | struct sysdev_class_attribute * class_attr = to_sysdev_class_attr(attr); |
| 102 | |
| 103 | if (class_attr->store) |
| 104 | return class_attr->store(class, buffer, count); |
| 105 | return -EIO; |
| 106 | } |
| 107 | |
| 108 | static struct sysfs_ops sysfs_class_ops = { |
| 109 | .show = sysdev_class_show, |
| 110 | .store = sysdev_class_store, |
| 111 | }; |
| 112 | |
| 113 | static struct kobj_type ktype_sysdev_class = { |
| 114 | .sysfs_ops = &sysfs_class_ops, |
| 115 | }; |
| 116 | |
| 117 | int sysdev_class_create_file(struct sysdev_class *c, |
| 118 | struct sysdev_class_attribute *a) |
| 119 | { |
| 120 | return sysfs_create_file(&c->kset.kobj, &a->attr); |
| 121 | } |
| 122 | EXPORT_SYMBOL_GPL(sysdev_class_create_file); |
| 123 | |
| 124 | void sysdev_class_remove_file(struct sysdev_class *c, |
| 125 | struct sysdev_class_attribute *a) |
| 126 | { |
| 127 | sysfs_remove_file(&c->kset.kobj, &a->attr); |
| 128 | } |
| 129 | EXPORT_SYMBOL_GPL(sysdev_class_remove_file); |
| 130 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | /* |
| 132 | * declare system_subsys |
| 133 | */ |
Greg Kroah-Hartman | 3514fac | 2007-10-16 10:11:44 -0600 | [diff] [blame^] | 134 | static decl_subsys(system, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | |
| 136 | int sysdev_class_register(struct sysdev_class * cls) |
| 137 | { |
| 138 | pr_debug("Registering sysdev class '%s'\n", |
| 139 | kobject_name(&cls->kset.kobj)); |
| 140 | INIT_LIST_HEAD(&cls->drivers); |
Greg Kroah-Hartman | 823bccf | 2007-04-13 13:15:19 -0700 | [diff] [blame] | 141 | cls->kset.kobj.parent = &system_subsys.kobj; |
Greg Kroah-Hartman | 3514fac | 2007-10-16 10:11:44 -0600 | [diff] [blame^] | 142 | cls->kset.kobj.ktype = &ktype_sysdev_class; |
Greg Kroah-Hartman | 27f20e5 | 2007-09-12 15:06:57 -0700 | [diff] [blame] | 143 | cls->kset.kobj.kset = &system_subsys; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | return kset_register(&cls->kset); |
| 145 | } |
| 146 | |
| 147 | void sysdev_class_unregister(struct sysdev_class * cls) |
| 148 | { |
| 149 | pr_debug("Unregistering sysdev class '%s'\n", |
| 150 | kobject_name(&cls->kset.kobj)); |
| 151 | kset_unregister(&cls->kset); |
| 152 | } |
| 153 | |
| 154 | EXPORT_SYMBOL_GPL(sysdev_class_register); |
| 155 | EXPORT_SYMBOL_GPL(sysdev_class_unregister); |
| 156 | |
Matthias Kaehlcke | 9f3f776 | 2007-05-23 14:19:42 -0700 | [diff] [blame] | 157 | static DEFINE_MUTEX(sysdev_drivers_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 158 | |
| 159 | /** |
| 160 | * sysdev_driver_register - Register auxillary driver |
Akinobu Mita | 44b760a | 2007-08-19 16:51:14 +0900 | [diff] [blame] | 161 | * @cls: Device class driver belongs to. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | * @drv: Driver. |
| 163 | * |
Akinobu Mita | 44b760a | 2007-08-19 16:51:14 +0900 | [diff] [blame] | 164 | * @drv is inserted into @cls->drivers to be |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | * called on each operation on devices of that class. The refcount |
| 166 | * of @cls is incremented. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | */ |
| 168 | |
Akinobu Mita | 44b760a | 2007-08-19 16:51:14 +0900 | [diff] [blame] | 169 | int sysdev_driver_register(struct sysdev_class *cls, struct sysdev_driver *drv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | { |
Akinobu Mita | 44b760a | 2007-08-19 16:51:14 +0900 | [diff] [blame] | 171 | int err = 0; |
| 172 | |
Matthias Kaehlcke | 9f3f776 | 2007-05-23 14:19:42 -0700 | [diff] [blame] | 173 | mutex_lock(&sysdev_drivers_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | if (cls && kset_get(&cls->kset)) { |
| 175 | list_add_tail(&drv->entry, &cls->drivers); |
| 176 | |
| 177 | /* If devices of this class already exist, tell the driver */ |
| 178 | if (drv->add) { |
| 179 | struct sys_device *dev; |
| 180 | list_for_each_entry(dev, &cls->kset.list, kobj.entry) |
| 181 | drv->add(dev); |
| 182 | } |
Akinobu Mita | 44b760a | 2007-08-19 16:51:14 +0900 | [diff] [blame] | 183 | } else { |
| 184 | err = -EINVAL; |
| 185 | printk(KERN_ERR "%s: invalid device class\n", __FUNCTION__); |
| 186 | WARN_ON(1); |
| 187 | } |
Matthias Kaehlcke | 9f3f776 | 2007-05-23 14:19:42 -0700 | [diff] [blame] | 188 | mutex_unlock(&sysdev_drivers_lock); |
Akinobu Mita | 44b760a | 2007-08-19 16:51:14 +0900 | [diff] [blame] | 189 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | } |
| 191 | |
| 192 | |
| 193 | /** |
| 194 | * sysdev_driver_unregister - Remove an auxillary driver. |
| 195 | * @cls: Class driver belongs to. |
| 196 | * @drv: Driver. |
| 197 | */ |
| 198 | void sysdev_driver_unregister(struct sysdev_class * cls, |
| 199 | struct sysdev_driver * drv) |
| 200 | { |
Matthias Kaehlcke | 9f3f776 | 2007-05-23 14:19:42 -0700 | [diff] [blame] | 201 | mutex_lock(&sysdev_drivers_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | list_del_init(&drv->entry); |
| 203 | if (cls) { |
| 204 | if (drv->remove) { |
| 205 | struct sys_device *dev; |
| 206 | list_for_each_entry(dev, &cls->kset.list, kobj.entry) |
| 207 | drv->remove(dev); |
| 208 | } |
| 209 | kset_put(&cls->kset); |
| 210 | } |
Matthias Kaehlcke | 9f3f776 | 2007-05-23 14:19:42 -0700 | [diff] [blame] | 211 | mutex_unlock(&sysdev_drivers_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 212 | } |
| 213 | |
| 214 | EXPORT_SYMBOL_GPL(sysdev_driver_register); |
| 215 | EXPORT_SYMBOL_GPL(sysdev_driver_unregister); |
| 216 | |
| 217 | |
| 218 | |
| 219 | /** |
| 220 | * sysdev_register - add a system device to the tree |
| 221 | * @sysdev: device in question |
| 222 | * |
| 223 | */ |
| 224 | int sysdev_register(struct sys_device * sysdev) |
| 225 | { |
| 226 | int error; |
| 227 | struct sysdev_class * cls = sysdev->cls; |
| 228 | |
| 229 | if (!cls) |
| 230 | return -EINVAL; |
| 231 | |
| 232 | /* Make sure the kset is set */ |
| 233 | sysdev->kobj.kset = &cls->kset; |
| 234 | |
| 235 | /* But make sure we point to the right type for sysfs translation */ |
| 236 | sysdev->kobj.ktype = &ktype_sysdev; |
| 237 | error = kobject_set_name(&sysdev->kobj, "%s%d", |
| 238 | kobject_name(&cls->kset.kobj), sysdev->id); |
| 239 | if (error) |
| 240 | return error; |
| 241 | |
| 242 | pr_debug("Registering sys device '%s'\n", kobject_name(&sysdev->kobj)); |
| 243 | |
| 244 | /* Register the object */ |
| 245 | error = kobject_register(&sysdev->kobj); |
| 246 | |
| 247 | if (!error) { |
| 248 | struct sysdev_driver * drv; |
| 249 | |
Matthias Kaehlcke | 9f3f776 | 2007-05-23 14:19:42 -0700 | [diff] [blame] | 250 | mutex_lock(&sysdev_drivers_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 251 | /* Generic notification is implicit, because it's that |
| 252 | * code that should have called us. |
| 253 | */ |
| 254 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 | /* Notify class auxillary drivers */ |
| 256 | list_for_each_entry(drv, &cls->drivers, entry) { |
| 257 | if (drv->add) |
| 258 | drv->add(sysdev); |
| 259 | } |
Matthias Kaehlcke | 9f3f776 | 2007-05-23 14:19:42 -0700 | [diff] [blame] | 260 | mutex_unlock(&sysdev_drivers_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 261 | } |
| 262 | return error; |
| 263 | } |
| 264 | |
| 265 | void sysdev_unregister(struct sys_device * sysdev) |
| 266 | { |
| 267 | struct sysdev_driver * drv; |
| 268 | |
Matthias Kaehlcke | 9f3f776 | 2007-05-23 14:19:42 -0700 | [diff] [blame] | 269 | mutex_lock(&sysdev_drivers_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 270 | list_for_each_entry(drv, &sysdev->cls->drivers, entry) { |
| 271 | if (drv->remove) |
| 272 | drv->remove(sysdev); |
| 273 | } |
Matthias Kaehlcke | 9f3f776 | 2007-05-23 14:19:42 -0700 | [diff] [blame] | 274 | mutex_unlock(&sysdev_drivers_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 275 | |
| 276 | kobject_unregister(&sysdev->kobj); |
| 277 | } |
| 278 | |
| 279 | |
| 280 | |
| 281 | /** |
| 282 | * sysdev_shutdown - Shut down all system devices. |
| 283 | * |
| 284 | * Loop over each class of system devices, and the devices in each |
| 285 | * of those classes. For each device, we call the shutdown method for |
Akinobu Mita | 44b760a | 2007-08-19 16:51:14 +0900 | [diff] [blame] | 286 | * each driver registered for the device - the auxillaries, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 287 | * and the class driver. |
| 288 | * |
| 289 | * Note: The list is iterated in reverse order, so that we shut down |
| 290 | * child devices before we shut down thier parents. The list ordering |
| 291 | * is guaranteed by virtue of the fact that child devices are registered |
| 292 | * after their parents. |
| 293 | */ |
| 294 | |
| 295 | void sysdev_shutdown(void) |
| 296 | { |
| 297 | struct sysdev_class * cls; |
| 298 | |
| 299 | pr_debug("Shutting Down System Devices\n"); |
| 300 | |
Matthias Kaehlcke | 9f3f776 | 2007-05-23 14:19:42 -0700 | [diff] [blame] | 301 | mutex_lock(&sysdev_drivers_lock); |
Greg Kroah-Hartman | 823bccf | 2007-04-13 13:15:19 -0700 | [diff] [blame] | 302 | list_for_each_entry_reverse(cls, &system_subsys.list, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 303 | kset.kobj.entry) { |
| 304 | struct sys_device * sysdev; |
| 305 | |
| 306 | pr_debug("Shutting down type '%s':\n", |
| 307 | kobject_name(&cls->kset.kobj)); |
| 308 | |
| 309 | list_for_each_entry(sysdev, &cls->kset.list, kobj.entry) { |
| 310 | struct sysdev_driver * drv; |
| 311 | pr_debug(" %s\n", kobject_name(&sysdev->kobj)); |
| 312 | |
Akinobu Mita | 44b760a | 2007-08-19 16:51:14 +0900 | [diff] [blame] | 313 | /* Call auxillary drivers first */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 314 | list_for_each_entry(drv, &cls->drivers, entry) { |
| 315 | if (drv->shutdown) |
| 316 | drv->shutdown(sysdev); |
| 317 | } |
| 318 | |
| 319 | /* Now call the generic one */ |
| 320 | if (cls->shutdown) |
| 321 | cls->shutdown(sysdev); |
| 322 | } |
| 323 | } |
Matthias Kaehlcke | 9f3f776 | 2007-05-23 14:19:42 -0700 | [diff] [blame] | 324 | mutex_unlock(&sysdev_drivers_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 325 | } |
| 326 | |
Shaohua Li | ceaeade | 2005-08-11 10:37:39 +0800 | [diff] [blame] | 327 | static void __sysdev_resume(struct sys_device *dev) |
| 328 | { |
| 329 | struct sysdev_class *cls = dev->cls; |
| 330 | struct sysdev_driver *drv; |
| 331 | |
| 332 | /* First, call the class-specific one */ |
| 333 | if (cls->resume) |
| 334 | cls->resume(dev); |
| 335 | |
| 336 | /* Call auxillary drivers next. */ |
| 337 | list_for_each_entry(drv, &cls->drivers, entry) { |
| 338 | if (drv->resume) |
| 339 | drv->resume(dev); |
| 340 | } |
Shaohua Li | ceaeade | 2005-08-11 10:37:39 +0800 | [diff] [blame] | 341 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 342 | |
| 343 | /** |
| 344 | * sysdev_suspend - Suspend all system devices. |
| 345 | * @state: Power state to enter. |
| 346 | * |
| 347 | * We perform an almost identical operation as sys_device_shutdown() |
| 348 | * above, though calling ->suspend() instead. Interrupts are disabled |
| 349 | * when this called. Devices are responsible for both saving state and |
| 350 | * quiescing or powering down the device. |
| 351 | * |
| 352 | * This is only called by the device PM core, so we let them handle |
| 353 | * all synchronization. |
| 354 | */ |
| 355 | |
Pavel Machek | 438510f | 2005-04-16 15:25:24 -0700 | [diff] [blame] | 356 | int sysdev_suspend(pm_message_t state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 357 | { |
| 358 | struct sysdev_class * cls; |
Shaohua Li | ceaeade | 2005-08-11 10:37:39 +0800 | [diff] [blame] | 359 | struct sys_device *sysdev, *err_dev; |
| 360 | struct sysdev_driver *drv, *err_drv; |
| 361 | int ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 362 | |
| 363 | pr_debug("Suspending System Devices\n"); |
| 364 | |
Greg Kroah-Hartman | 823bccf | 2007-04-13 13:15:19 -0700 | [diff] [blame] | 365 | list_for_each_entry_reverse(cls, &system_subsys.list, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 366 | kset.kobj.entry) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 367 | |
| 368 | pr_debug("Suspending type '%s':\n", |
| 369 | kobject_name(&cls->kset.kobj)); |
| 370 | |
| 371 | list_for_each_entry(sysdev, &cls->kset.list, kobj.entry) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 372 | pr_debug(" %s\n", kobject_name(&sysdev->kobj)); |
| 373 | |
Akinobu Mita | 44b760a | 2007-08-19 16:51:14 +0900 | [diff] [blame] | 374 | /* Call auxillary drivers first */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 375 | list_for_each_entry(drv, &cls->drivers, entry) { |
Shaohua Li | ceaeade | 2005-08-11 10:37:39 +0800 | [diff] [blame] | 376 | if (drv->suspend) { |
| 377 | ret = drv->suspend(sysdev, state); |
| 378 | if (ret) |
| 379 | goto aux_driver; |
| 380 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 381 | } |
| 382 | |
| 383 | /* Now call the generic one */ |
Shaohua Li | ceaeade | 2005-08-11 10:37:39 +0800 | [diff] [blame] | 384 | if (cls->suspend) { |
| 385 | ret = cls->suspend(sysdev, state); |
| 386 | if (ret) |
| 387 | goto cls_driver; |
| 388 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 389 | } |
| 390 | } |
| 391 | return 0; |
Shaohua Li | ceaeade | 2005-08-11 10:37:39 +0800 | [diff] [blame] | 392 | /* resume current sysdev */ |
| 393 | cls_driver: |
| 394 | drv = NULL; |
| 395 | printk(KERN_ERR "Class suspend failed for %s\n", |
| 396 | kobject_name(&sysdev->kobj)); |
| 397 | |
| 398 | aux_driver: |
| 399 | if (drv) |
| 400 | printk(KERN_ERR "Class driver suspend failed for %s\n", |
| 401 | kobject_name(&sysdev->kobj)); |
| 402 | list_for_each_entry(err_drv, &cls->drivers, entry) { |
| 403 | if (err_drv == drv) |
| 404 | break; |
| 405 | if (err_drv->resume) |
| 406 | err_drv->resume(sysdev); |
| 407 | } |
Shaohua Li | ceaeade | 2005-08-11 10:37:39 +0800 | [diff] [blame] | 408 | |
Shaohua Li | ceaeade | 2005-08-11 10:37:39 +0800 | [diff] [blame] | 409 | /* resume other sysdevs in current class */ |
| 410 | list_for_each_entry(err_dev, &cls->kset.list, kobj.entry) { |
| 411 | if (err_dev == sysdev) |
| 412 | break; |
| 413 | pr_debug(" %s\n", kobject_name(&err_dev->kobj)); |
| 414 | __sysdev_resume(err_dev); |
| 415 | } |
| 416 | |
| 417 | /* resume other classes */ |
Greg Kroah-Hartman | 823bccf | 2007-04-13 13:15:19 -0700 | [diff] [blame] | 418 | list_for_each_entry_continue(cls, &system_subsys.list, |
Shaohua Li | ceaeade | 2005-08-11 10:37:39 +0800 | [diff] [blame] | 419 | kset.kobj.entry) { |
| 420 | list_for_each_entry(err_dev, &cls->kset.list, kobj.entry) { |
| 421 | pr_debug(" %s\n", kobject_name(&err_dev->kobj)); |
| 422 | __sysdev_resume(err_dev); |
| 423 | } |
| 424 | } |
| 425 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 426 | } |
| 427 | |
| 428 | |
| 429 | /** |
| 430 | * sysdev_resume - Bring system devices back to life. |
| 431 | * |
| 432 | * Similar to sys_device_suspend(), but we iterate the list forwards |
| 433 | * to guarantee that parent devices are resumed before their children. |
| 434 | * |
| 435 | * Note: Interrupts are disabled when called. |
| 436 | */ |
| 437 | |
| 438 | int sysdev_resume(void) |
| 439 | { |
| 440 | struct sysdev_class * cls; |
| 441 | |
| 442 | pr_debug("Resuming System Devices\n"); |
| 443 | |
Greg Kroah-Hartman | 823bccf | 2007-04-13 13:15:19 -0700 | [diff] [blame] | 444 | list_for_each_entry(cls, &system_subsys.list, kset.kobj.entry) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 445 | struct sys_device * sysdev; |
| 446 | |
| 447 | pr_debug("Resuming type '%s':\n", |
| 448 | kobject_name(&cls->kset.kobj)); |
| 449 | |
| 450 | list_for_each_entry(sysdev, &cls->kset.list, kobj.entry) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 451 | pr_debug(" %s\n", kobject_name(&sysdev->kobj)); |
| 452 | |
Shaohua Li | ceaeade | 2005-08-11 10:37:39 +0800 | [diff] [blame] | 453 | __sysdev_resume(sysdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 454 | } |
| 455 | } |
| 456 | return 0; |
| 457 | } |
| 458 | |
| 459 | |
| 460 | int __init system_bus_init(void) |
| 461 | { |
Greg Kroah-Hartman | 823bccf | 2007-04-13 13:15:19 -0700 | [diff] [blame] | 462 | system_subsys.kobj.parent = &devices_subsys.kobj; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 463 | return subsystem_register(&system_subsys); |
| 464 | } |
| 465 | |
| 466 | EXPORT_SYMBOL_GPL(sysdev_register); |
| 467 | EXPORT_SYMBOL_GPL(sysdev_unregister); |