Merge remote-tracking branch 'asoc/topic/wm8960' into asoc-next
[linux-2.6-block.git] / drivers / edac / edac_module.c
CommitLineData
81d87cb1
DJ
1/*
2 * edac_module.c
3 *
fb3fb206
DT
4 * (C) 2007 www.softwarebitmaker.com
5 *
81d87cb1
DJ
6 * This file is licensed under the terms of the GNU General Public
7 * License version 2. This program is licensed "as is" without any
8 * warranty of any kind, whether express or implied.
9 *
fb3fb206 10 * Author: Doug Thompson <dougthompson@xmission.com>
81d87cb1
DJ
11 *
12 */
c0d12172 13#include <linux/edac.h>
7c9281d7 14
20bcb7a8 15#include "edac_core.h"
7c9281d7
DT
16#include "edac_module.h"
17
5156a5f4 18#define EDAC_VERSION "Ver: 3.0.0"
7c9281d7
DT
19
20#ifdef CONFIG_EDAC_DEBUG
37929874
BP
21
22static int edac_set_debug_level(const char *buf, struct kernel_param *kp)
23{
24 unsigned long val;
25 int ret;
26
27 ret = kstrtoul(buf, 0, &val);
28 if (ret)
29 return ret;
30
6866b390 31 if (val > 4)
37929874
BP
32 return -EINVAL;
33
34 return param_set_int(buf, kp);
35}
36
7c9281d7 37/* Values of 0 to 4 will generate output */
8096cfaf 38int edac_debug_level = 2;
7c9281d7 39EXPORT_SYMBOL_GPL(edac_debug_level);
37929874
BP
40
41module_param_call(edac_debug_level, edac_set_debug_level, param_get_int,
42 &edac_debug_level, 0644);
43MODULE_PARM_DESC(edac_debug_level, "EDAC debug level: [0-4], default: 2");
7c9281d7
DT
44#endif
45
91b99041 46/*
494d0d55 47 * edac_op_state_to_string()
91b99041 48 */
494d0d55 49char *edac_op_state_to_string(int opstate)
91b99041
DJ
50{
51 if (opstate == OP_RUNNING_POLL)
52 return "POLLED";
53 else if (opstate == OP_RUNNING_INTERRUPT)
54 return "INTERRUPT";
55 else if (opstate == OP_RUNNING_POLL_INTR)
56 return "POLL-INTR";
57 else if (opstate == OP_ALLOC)
58 return "ALLOC";
59 else if (opstate == OP_OFFLINE)
60 return "OFFLINE";
61
62 return "UNKNOWN";
63}
64
733476cf
BP
65/*
66 * sysfs object: /sys/devices/system/edac
67 * need to export to other files
68 */
a97d2627 69static struct bus_type edac_subsys = {
733476cf
BP
70 .name = "edac",
71 .dev_name = "edac",
72};
733476cf
BP
73
74static int edac_subsys_init(void)
75{
76 int err;
77
78 /* create the /sys/devices/system/edac directory */
79 err = subsys_system_register(&edac_subsys, NULL);
80 if (err)
81 printk(KERN_ERR "Error registering toplevel EDAC sysfs dir\n");
82
83 return err;
84}
85
86static void edac_subsys_exit(void)
87{
88 bus_unregister(&edac_subsys);
89}
90
91/* return pointer to the 'edac' node in sysfs */
92struct bus_type *edac_get_sysfs_subsys(void)
93{
94 return &edac_subsys;
95}
96EXPORT_SYMBOL_GPL(edac_get_sysfs_subsys);
7c9281d7
DT
97/*
98 * edac_init
99 * module initialization entry point
100 */
101static int __init edac_init(void)
102{
e27e3dac
DT
103 int err = 0;
104
fb3fb206 105 edac_printk(KERN_INFO, EDAC_MC, EDAC_VERSION "\n");
7c9281d7 106
733476cf
BP
107 err = edac_subsys_init();
108 if (err)
109 return err;
110
7c9281d7
DT
111 /*
112 * Harvest and clear any boot/initialization PCI parity errors
113 *
114 * FIXME: This only clears errors logged by devices present at time of
079708b9
DT
115 * module initialization. We should also do an initial clear
116 * of each newly hotplugged device.
7c9281d7
DT
117 */
118 edac_pci_clear_parity_errors();
119
7a623c03 120 err = edac_mc_sysfs_init();
8096cfaf 121 if (err)
c6b97bcf 122 goto err_sysfs;
7c9281d7 123
e7930ba4
RH
124 edac_debugfs_init();
125
e27e3dac
DT
126 err = edac_workqueue_setup();
127 if (err) {
c6b97bcf
AK
128 edac_printk(KERN_ERR, EDAC_MC, "Failure initializing workqueue\n");
129 goto err_wq;
7c9281d7
DT
130 }
131
7c9281d7 132 return 0;
e27e3dac 133
c6b97bcf
AK
134err_wq:
135 edac_debugfs_exit();
136 edac_mc_sysfs_exit();
137
138err_sysfs:
733476cf
BP
139 edac_subsys_exit();
140
e27e3dac 141 return err;
7c9281d7
DT
142}
143
144/*
145 * edac_exit()
146 * module exit/termination function
147 */
148static void __exit edac_exit(void)
149{
956b9ba1 150 edac_dbg(0, "\n");
7c9281d7 151
079708b9 152 /* tear down the various subsystems */
e27e3dac 153 edac_workqueue_teardown();
7a623c03 154 edac_mc_sysfs_exit();
e7930ba4 155 edac_debugfs_exit();
733476cf 156 edac_subsys_exit();
7c9281d7
DT
157}
158
159/*
160 * Inform the kernel of our entry and exit points
161 */
4ab19b06 162subsys_initcall(edac_init);
7c9281d7
DT
163module_exit(edac_exit);
164
165MODULE_LICENSE("GPL");
166MODULE_AUTHOR("Doug Thompson www.softwarebitmaker.com, et al");
167MODULE_DESCRIPTION("Core library routines for EDAC reporting");