]> Pileus Git - ~andy/linux/blob - drivers/mmc/core/sysfs.c
mmc: refactor host class handling
[~andy/linux] / drivers / mmc / core / sysfs.c
1 /*
2  *  linux/drivers/mmc/core/sysfs.c
3  *
4  *  Copyright (C) 2003 Russell King, All Rights Reserved.
5  *  Copyright 2007 Pierre Ossman
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License version 2 as
9  * published by the Free Software Foundation.
10  *
11  *  MMC sysfs/driver model support.
12  */
13 #include <linux/module.h>
14 #include <linux/init.h>
15 #include <linux/device.h>
16 #include <linux/idr.h>
17 #include <linux/workqueue.h>
18
19 #include <linux/mmc/card.h>
20 #include <linux/mmc/host.h>
21
22 #include "bus.h"
23 #include "host.h"
24 #include "sysfs.h"
25
26 int mmc_add_attrs(struct mmc_card *card, struct device_attribute *attrs)
27 {
28         int error = 0;
29         int i;
30
31         for (i = 0; attr_name(attrs[i]); i++) {
32                 error = device_create_file(&card->dev, &attrs[i]);
33                 if (error) {
34                         while (--i >= 0)
35                                 device_remove_file(&card->dev, &attrs[i]);
36                         break;
37                 }
38         }
39
40         return error;
41 }
42
43 void mmc_remove_attrs(struct mmc_card *card, struct device_attribute *attrs)
44 {
45         int i;
46
47         for (i = 0; attr_name(attrs[i]); i++)
48                 device_remove_file(&card->dev, &attrs[i]);
49 }
50
51 static struct workqueue_struct *workqueue;
52
53 /*
54  * Internal function. Schedule delayed work in the MMC work queue.
55  */
56 int mmc_schedule_delayed_work(struct delayed_work *work, unsigned long delay)
57 {
58         return queue_delayed_work(workqueue, work, delay);
59 }
60
61 /*
62  * Internal function. Flush all scheduled work from the MMC work queue.
63  */
64 void mmc_flush_scheduled_work(void)
65 {
66         flush_workqueue(workqueue);
67 }
68
69 static int __init mmc_init(void)
70 {
71         int ret;
72
73         workqueue = create_singlethread_workqueue("kmmcd");
74         if (!workqueue)
75                 return -ENOMEM;
76
77         ret = mmc_register_bus();
78         if (ret == 0) {
79                 ret = mmc_register_host_class();
80                 if (ret)
81                         mmc_unregister_bus();
82         }
83         return ret;
84 }
85
86 static void __exit mmc_exit(void)
87 {
88         mmc_unregister_host_class();
89         mmc_unregister_bus();
90         destroy_workqueue(workqueue);
91 }
92
93 module_init(mmc_init);
94 module_exit(mmc_exit);