9 #include <linux/module.h>
10 #include <linux/errno.h>
11 #include <linux/slab.h>
12 #include <linux/list.h>
13 #include <linux/device.h>
15 #include <linux/ctype.h>
24 #define CCW_BUS_ID_SIZE 10
33 static struct bus_type ccwgroup_bus_type;
40 for (i = 0; i < gdev->
count; i++) {
56 for (i = 0; i < gdev->
count; i++) {
75 if (gdev->
state == CCWGROUP_ONLINE)
82 gdev->
state = CCWGROUP_ONLINE;
95 if (gdev->
state == CCWGROUP_OFFLINE)
102 gdev->
state = CCWGROUP_OFFLINE;
119 if (!try_module_get(gdrv->
driver.owner))
127 ret = ccwgroup_set_online(gdev);
129 ret = ccwgroup_set_offline(gdev);
133 module_put(gdrv->
driver.owner);
134 return (ret == 0) ? count :
ret;
153 static void ccwgroup_ungroup_callback(
struct device *dev)
158 if (device_is_registered(&gdev->
dev)) {
159 __ccwgroup_remove_symlinks(gdev);
161 __ccwgroup_remove_cdev_refs(gdev);
168 const char *buf,
size_t count)
196 static struct attribute *ccwgroup_attrs[] = {
197 &dev_attr_online.attr,
198 &dev_attr_ungroup.attr,
202 .attrs = ccwgroup_attrs,
205 &ccwgroup_attr_group,
209 static void ccwgroup_release(
struct device *dev)
219 for (i = 0; i < gdev->
count; i++) {
221 &gdev->
dev.kobj,
"group_device");
223 for (--i; i >= 0; i--)
229 for (i = 0; i < gdev->
count; i++) {
232 &gdev->
cdev[i]->dev.kobj, str);
234 for (--i; i >= 0; i--) {
238 for (i = 0; i < gdev->
count; i++)
247 static int __get_next_id(
const char **buf,
struct ccw_dev_id *
id)
253 start = (
char *)*buf;
257 end =
strchr(start,
'\n');
262 len = end - start + 1;
266 if (
sscanf(start,
"%2x.%1x.%04x", &cssid, &ssid, &devno) != 3)
300 gdev = kzalloc(
sizeof(*gdev) + num_devices *
sizeof(gdev->
cdev[0]),
309 gdev->
dev.bus = &ccwgroup_bus_type;
310 gdev->
dev.parent = parent;
311 gdev->
dev.release = ccwgroup_release;
314 for (i = 0; i < num_devices &&
buf; i++) {
315 rc = __get_next_id(&buf, &dev_id);
323 if (!gdev->
cdev[i] || !gdev->
cdev[i]->drv ||
324 gdev->
cdev[i]->drv != gdev->
cdev[0]->drv ||
325 gdev->
cdev[i]->id.driver_info !=
326 gdev->
cdev[0]->id.driver_info) {
331 spin_lock_irq(gdev->
cdev[i]->ccwlock);
333 spin_unlock_irq(gdev->
cdev[i]->ccwlock);
338 spin_unlock_irq(gdev->
cdev[i]->ccwlock);
341 if (i < num_devices) {
346 if (i == num_devices &&
strlen(buf) > 0) {
352 gdev->
dev.groups = ccwgroup_attr_groups;
363 rc = __ccwgroup_create_symlinks(gdev);
373 spin_lock_irq(gdev->
cdev[i]->ccwlock);
376 spin_unlock_irq(gdev->
cdev[i]->ccwlock);
398 .notifier_call = ccwgroup_notifier
401 static int __init init_ccwgroup(
void)
416 static void __exit cleanup_ccwgroup(
void)
427 static int ccwgroup_remove(
struct device *dev)
440 static void ccwgroup_shutdown(
struct device *dev)
451 static int ccwgroup_pm_prepare(
struct device *dev)
460 if (!gdev->
dev.driver || gdev->
state != CCWGROUP_ONLINE)
466 static void ccwgroup_pm_complete(
struct device *dev)
471 if (!gdev->
dev.driver || gdev->
state != CCWGROUP_ONLINE)
478 static int ccwgroup_pm_freeze(
struct device *dev)
483 if (!gdev->
dev.driver || gdev->
state != CCWGROUP_ONLINE)
489 static int ccwgroup_pm_thaw(
struct device *dev)
494 if (!gdev->
dev.driver || gdev->
state != CCWGROUP_ONLINE)
497 return gdrv->
thaw ? gdrv->
thaw(gdev) : 0;
500 static int ccwgroup_pm_restore(
struct device *dev)
505 if (!gdev->
dev.driver || gdev->
state != CCWGROUP_ONLINE)
511 static const struct dev_pm_ops ccwgroup_pm_ops = {
512 .prepare = ccwgroup_pm_prepare,
513 .complete = ccwgroup_pm_complete,
514 .freeze = ccwgroup_pm_freeze,
515 .thaw = ccwgroup_pm_thaw,
516 .restore = ccwgroup_pm_restore,
519 static struct bus_type ccwgroup_bus_type = {
521 .remove = ccwgroup_remove,
522 .shutdown = ccwgroup_shutdown,
523 .pm = &ccwgroup_pm_ops,
535 cdriver->
driver.bus = &ccwgroup_bus_type;
541 static int __ccwgroup_match_all(
struct device *dev,
void *data)
558 __ccwgroup_match_all))) {
562 __ccwgroup_remove_symlinks(gdev);
564 __ccwgroup_remove_cdev_refs(gdev);
605 spin_unlock_irq(cdev->
ccwlock);
610 spin_unlock_irq(cdev->
ccwlock);
613 if (device_is_registered(&gdev->
dev)) {
614 __ccwgroup_remove_symlinks(gdev);
616 __ccwgroup_remove_cdev_refs(gdev);