diff options
Diffstat (limited to 'drivers/acpi/fan.c')
-rw-r--r-- | drivers/acpi/fan.c | 142 |
1 files changed, 57 insertions, 85 deletions
diff --git a/drivers/acpi/fan.c b/drivers/acpi/fan.c index 14192ee55f8f..e8165c4f162a 100644 --- a/drivers/acpi/fan.c +++ b/drivers/acpi/fan.c | |||
@@ -34,52 +34,45 @@ | |||
34 | #include <acpi/acpi_bus.h> | 34 | #include <acpi/acpi_bus.h> |
35 | #include <acpi/acpi_drivers.h> | 35 | #include <acpi/acpi_drivers.h> |
36 | 36 | ||
37 | |||
38 | #define ACPI_FAN_COMPONENT 0x00200000 | 37 | #define ACPI_FAN_COMPONENT 0x00200000 |
39 | #define ACPI_FAN_CLASS "fan" | 38 | #define ACPI_FAN_CLASS "fan" |
40 | #define ACPI_FAN_HID "PNP0C0B" | ||
41 | #define ACPI_FAN_DRIVER_NAME "ACPI Fan Driver" | 39 | #define ACPI_FAN_DRIVER_NAME "ACPI Fan Driver" |
42 | #define ACPI_FAN_DEVICE_NAME "Fan" | ||
43 | #define ACPI_FAN_FILE_STATE "state" | 40 | #define ACPI_FAN_FILE_STATE "state" |
44 | #define ACPI_FAN_NOTIFY_STATUS 0x80 | ||
45 | 41 | ||
46 | #define _COMPONENT ACPI_FAN_COMPONENT | 42 | #define _COMPONENT ACPI_FAN_COMPONENT |
47 | ACPI_MODULE_NAME ("acpi_fan") | 43 | ACPI_MODULE_NAME("acpi_fan") |
48 | 44 | ||
49 | MODULE_AUTHOR("Paul Diefenbaugh"); | 45 | MODULE_AUTHOR("Paul Diefenbaugh"); |
50 | MODULE_DESCRIPTION(ACPI_FAN_DRIVER_NAME); | 46 | MODULE_DESCRIPTION(ACPI_FAN_DRIVER_NAME); |
51 | MODULE_LICENSE("GPL"); | 47 | MODULE_LICENSE("GPL"); |
52 | 48 | ||
53 | static int acpi_fan_add (struct acpi_device *device); | 49 | static int acpi_fan_add(struct acpi_device *device); |
54 | static int acpi_fan_remove (struct acpi_device *device, int type); | 50 | static int acpi_fan_remove(struct acpi_device *device, int type); |
55 | 51 | ||
56 | static struct acpi_driver acpi_fan_driver = { | 52 | static struct acpi_driver acpi_fan_driver = { |
57 | .name = ACPI_FAN_DRIVER_NAME, | 53 | .name = ACPI_FAN_DRIVER_NAME, |
58 | .class = ACPI_FAN_CLASS, | 54 | .class = ACPI_FAN_CLASS, |
59 | .ids = ACPI_FAN_HID, | 55 | .ids = "PNP0C0B", |
60 | .ops = { | 56 | .ops = { |
61 | .add = acpi_fan_add, | 57 | .add = acpi_fan_add, |
62 | .remove = acpi_fan_remove, | 58 | .remove = acpi_fan_remove, |
63 | }, | 59 | }, |
64 | }; | 60 | }; |
65 | 61 | ||
66 | struct acpi_fan { | 62 | struct acpi_fan { |
67 | acpi_handle handle; | 63 | acpi_handle handle; |
68 | }; | 64 | }; |
69 | 65 | ||
70 | |||
71 | /* -------------------------------------------------------------------------- | 66 | /* -------------------------------------------------------------------------- |
72 | FS Interface (/proc) | 67 | FS Interface (/proc) |
73 | -------------------------------------------------------------------------- */ | 68 | -------------------------------------------------------------------------- */ |
74 | 69 | ||
75 | static struct proc_dir_entry *acpi_fan_dir; | 70 | static struct proc_dir_entry *acpi_fan_dir; |
76 | 71 | ||
77 | 72 | static int acpi_fan_read_state(struct seq_file *seq, void *offset) | |
78 | static int | ||
79 | acpi_fan_read_state (struct seq_file *seq, void *offset) | ||
80 | { | 73 | { |
81 | struct acpi_fan *fan = seq->private; | 74 | struct acpi_fan *fan = seq->private; |
82 | int state = 0; | 75 | int state = 0; |
83 | 76 | ||
84 | ACPI_FUNCTION_TRACE("acpi_fan_read_state"); | 77 | ACPI_FUNCTION_TRACE("acpi_fan_read_state"); |
85 | 78 | ||
@@ -88,7 +81,7 @@ acpi_fan_read_state (struct seq_file *seq, void *offset) | |||
88 | seq_printf(seq, "status: ERROR\n"); | 81 | seq_printf(seq, "status: ERROR\n"); |
89 | else | 82 | else |
90 | seq_printf(seq, "status: %s\n", | 83 | seq_printf(seq, "status: %s\n", |
91 | !state?"on":"off"); | 84 | !state ? "on" : "off"); |
92 | } | 85 | } |
93 | return_VALUE(0); | 86 | return_VALUE(0); |
94 | } | 87 | } |
@@ -99,29 +92,26 @@ static int acpi_fan_state_open_fs(struct inode *inode, struct file *file) | |||
99 | } | 92 | } |
100 | 93 | ||
101 | static ssize_t | 94 | static ssize_t |
102 | acpi_fan_write_state ( | 95 | acpi_fan_write_state(struct file *file, const char __user * buffer, |
103 | struct file *file, | 96 | size_t count, loff_t * ppos) |
104 | const char __user *buffer, | ||
105 | size_t count, | ||
106 | loff_t *ppos) | ||
107 | { | 97 | { |
108 | int result = 0; | 98 | int result = 0; |
109 | struct seq_file *m = (struct seq_file *)file->private_data; | 99 | struct seq_file *m = (struct seq_file *)file->private_data; |
110 | struct acpi_fan *fan = (struct acpi_fan *) m->private; | 100 | struct acpi_fan *fan = (struct acpi_fan *)m->private; |
111 | char state_string[12] = {'\0'}; | 101 | char state_string[12] = { '\0' }; |
112 | 102 | ||
113 | ACPI_FUNCTION_TRACE("acpi_fan_write_state"); | 103 | ACPI_FUNCTION_TRACE("acpi_fan_write_state"); |
114 | 104 | ||
115 | if (!fan || (count > sizeof(state_string) - 1)) | 105 | if (!fan || (count > sizeof(state_string) - 1)) |
116 | return_VALUE(-EINVAL); | 106 | return_VALUE(-EINVAL); |
117 | 107 | ||
118 | if (copy_from_user(state_string, buffer, count)) | 108 | if (copy_from_user(state_string, buffer, count)) |
119 | return_VALUE(-EFAULT); | 109 | return_VALUE(-EFAULT); |
120 | 110 | ||
121 | state_string[count] = '\0'; | 111 | state_string[count] = '\0'; |
122 | 112 | ||
123 | result = acpi_bus_set_power(fan->handle, | 113 | result = acpi_bus_set_power(fan->handle, |
124 | simple_strtoul(state_string, NULL, 0)); | 114 | simple_strtoul(state_string, NULL, 0)); |
125 | if (result) | 115 | if (result) |
126 | return_VALUE(result); | 116 | return_VALUE(result); |
127 | 117 | ||
@@ -129,19 +119,17 @@ acpi_fan_write_state ( | |||
129 | } | 119 | } |
130 | 120 | ||
131 | static struct file_operations acpi_fan_state_ops = { | 121 | static struct file_operations acpi_fan_state_ops = { |
132 | .open = acpi_fan_state_open_fs, | 122 | .open = acpi_fan_state_open_fs, |
133 | .read = seq_read, | 123 | .read = seq_read, |
134 | .write = acpi_fan_write_state, | 124 | .write = acpi_fan_write_state, |
135 | .llseek = seq_lseek, | 125 | .llseek = seq_lseek, |
136 | .release = single_release, | 126 | .release = single_release, |
137 | .owner = THIS_MODULE, | 127 | .owner = THIS_MODULE, |
138 | }; | 128 | }; |
139 | 129 | ||
140 | static int | 130 | static int acpi_fan_add_fs(struct acpi_device *device) |
141 | acpi_fan_add_fs ( | ||
142 | struct acpi_device *device) | ||
143 | { | 131 | { |
144 | struct proc_dir_entry *entry = NULL; | 132 | struct proc_dir_entry *entry = NULL; |
145 | 133 | ||
146 | ACPI_FUNCTION_TRACE("acpi_fan_add_fs"); | 134 | ACPI_FUNCTION_TRACE("acpi_fan_add_fs"); |
147 | 135 | ||
@@ -150,7 +138,7 @@ acpi_fan_add_fs ( | |||
150 | 138 | ||
151 | if (!acpi_device_dir(device)) { | 139 | if (!acpi_device_dir(device)) { |
152 | acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device), | 140 | acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device), |
153 | acpi_fan_dir); | 141 | acpi_fan_dir); |
154 | if (!acpi_device_dir(device)) | 142 | if (!acpi_device_dir(device)) |
155 | return_VALUE(-ENODEV); | 143 | return_VALUE(-ENODEV); |
156 | acpi_device_dir(device)->owner = THIS_MODULE; | 144 | acpi_device_dir(device)->owner = THIS_MODULE; |
@@ -158,11 +146,12 @@ acpi_fan_add_fs ( | |||
158 | 146 | ||
159 | /* 'status' [R/W] */ | 147 | /* 'status' [R/W] */ |
160 | entry = create_proc_entry(ACPI_FAN_FILE_STATE, | 148 | entry = create_proc_entry(ACPI_FAN_FILE_STATE, |
161 | S_IFREG|S_IRUGO|S_IWUSR, acpi_device_dir(device)); | 149 | S_IFREG | S_IRUGO | S_IWUSR, |
150 | acpi_device_dir(device)); | ||
162 | if (!entry) | 151 | if (!entry) |
163 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, | 152 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, |
164 | "Unable to create '%s' fs entry\n", | 153 | "Unable to create '%s' fs entry\n", |
165 | ACPI_FAN_FILE_STATE)); | 154 | ACPI_FAN_FILE_STATE)); |
166 | else { | 155 | else { |
167 | entry->proc_fops = &acpi_fan_state_ops; | 156 | entry->proc_fops = &acpi_fan_state_ops; |
168 | entry->data = acpi_driver_data(device); | 157 | entry->data = acpi_driver_data(device); |
@@ -172,16 +161,12 @@ acpi_fan_add_fs ( | |||
172 | return_VALUE(0); | 161 | return_VALUE(0); |
173 | } | 162 | } |
174 | 163 | ||
175 | 164 | static int acpi_fan_remove_fs(struct acpi_device *device) | |
176 | static int | ||
177 | acpi_fan_remove_fs ( | ||
178 | struct acpi_device *device) | ||
179 | { | 165 | { |
180 | ACPI_FUNCTION_TRACE("acpi_fan_remove_fs"); | 166 | ACPI_FUNCTION_TRACE("acpi_fan_remove_fs"); |
181 | 167 | ||
182 | if (acpi_device_dir(device)) { | 168 | if (acpi_device_dir(device)) { |
183 | remove_proc_entry(ACPI_FAN_FILE_STATE, | 169 | remove_proc_entry(ACPI_FAN_FILE_STATE, acpi_device_dir(device)); |
184 | acpi_device_dir(device)); | ||
185 | remove_proc_entry(acpi_device_bid(device), acpi_fan_dir); | 170 | remove_proc_entry(acpi_device_bid(device), acpi_fan_dir); |
186 | acpi_device_dir(device) = NULL; | 171 | acpi_device_dir(device) = NULL; |
187 | } | 172 | } |
@@ -189,18 +174,15 @@ acpi_fan_remove_fs ( | |||
189 | return_VALUE(0); | 174 | return_VALUE(0); |
190 | } | 175 | } |
191 | 176 | ||
192 | |||
193 | /* -------------------------------------------------------------------------- | 177 | /* -------------------------------------------------------------------------- |
194 | Driver Interface | 178 | Driver Interface |
195 | -------------------------------------------------------------------------- */ | 179 | -------------------------------------------------------------------------- */ |
196 | 180 | ||
197 | static int | 181 | static int acpi_fan_add(struct acpi_device *device) |
198 | acpi_fan_add ( | ||
199 | struct acpi_device *device) | ||
200 | { | 182 | { |
201 | int result = 0; | 183 | int result = 0; |
202 | struct acpi_fan *fan = NULL; | 184 | struct acpi_fan *fan = NULL; |
203 | int state = 0; | 185 | int state = 0; |
204 | 186 | ||
205 | ACPI_FUNCTION_TRACE("acpi_fan_add"); | 187 | ACPI_FUNCTION_TRACE("acpi_fan_add"); |
206 | 188 | ||
@@ -213,14 +195,14 @@ acpi_fan_add ( | |||
213 | memset(fan, 0, sizeof(struct acpi_fan)); | 195 | memset(fan, 0, sizeof(struct acpi_fan)); |
214 | 196 | ||
215 | fan->handle = device->handle; | 197 | fan->handle = device->handle; |
216 | strcpy(acpi_device_name(device), ACPI_FAN_DEVICE_NAME); | 198 | strcpy(acpi_device_name(device), "Fan"); |
217 | strcpy(acpi_device_class(device), ACPI_FAN_CLASS); | 199 | strcpy(acpi_device_class(device), ACPI_FAN_CLASS); |
218 | acpi_driver_data(device) = fan; | 200 | acpi_driver_data(device) = fan; |
219 | 201 | ||
220 | result = acpi_bus_get_power(fan->handle, &state); | 202 | result = acpi_bus_get_power(fan->handle, &state); |
221 | if (result) { | 203 | if (result) { |
222 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, | 204 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, |
223 | "Error reading power state\n")); | 205 | "Error reading power state\n")); |
224 | goto end; | 206 | goto end; |
225 | } | 207 | } |
226 | 208 | ||
@@ -229,30 +211,26 @@ acpi_fan_add ( | |||
229 | goto end; | 211 | goto end; |
230 | 212 | ||
231 | printk(KERN_INFO PREFIX "%s [%s] (%s)\n", | 213 | printk(KERN_INFO PREFIX "%s [%s] (%s)\n", |
232 | acpi_device_name(device), acpi_device_bid(device), | 214 | acpi_device_name(device), acpi_device_bid(device), |
233 | !device->power.state?"on":"off"); | 215 | !device->power.state ? "on" : "off"); |
234 | 216 | ||
235 | end: | 217 | end: |
236 | if (result) | 218 | if (result) |
237 | kfree(fan); | 219 | kfree(fan); |
238 | 220 | ||
239 | return_VALUE(result); | 221 | return_VALUE(result); |
240 | } | 222 | } |
241 | 223 | ||
242 | 224 | static int acpi_fan_remove(struct acpi_device *device, int type) | |
243 | static int | ||
244 | acpi_fan_remove ( | ||
245 | struct acpi_device *device, | ||
246 | int type) | ||
247 | { | 225 | { |
248 | struct acpi_fan *fan = NULL; | 226 | struct acpi_fan *fan = NULL; |
249 | 227 | ||
250 | ACPI_FUNCTION_TRACE("acpi_fan_remove"); | 228 | ACPI_FUNCTION_TRACE("acpi_fan_remove"); |
251 | 229 | ||
252 | if (!device || !acpi_driver_data(device)) | 230 | if (!device || !acpi_driver_data(device)) |
253 | return_VALUE(-EINVAL); | 231 | return_VALUE(-EINVAL); |
254 | 232 | ||
255 | fan = (struct acpi_fan *) acpi_driver_data(device); | 233 | fan = (struct acpi_fan *)acpi_driver_data(device); |
256 | 234 | ||
257 | acpi_fan_remove_fs(device); | 235 | acpi_fan_remove_fs(device); |
258 | 236 | ||
@@ -261,11 +239,9 @@ acpi_fan_remove ( | |||
261 | return_VALUE(0); | 239 | return_VALUE(0); |
262 | } | 240 | } |
263 | 241 | ||
264 | 242 | static int __init acpi_fan_init(void) | |
265 | static int __init | ||
266 | acpi_fan_init (void) | ||
267 | { | 243 | { |
268 | int result = 0; | 244 | int result = 0; |
269 | 245 | ||
270 | ACPI_FUNCTION_TRACE("acpi_fan_init"); | 246 | ACPI_FUNCTION_TRACE("acpi_fan_init"); |
271 | 247 | ||
@@ -283,9 +259,7 @@ acpi_fan_init (void) | |||
283 | return_VALUE(0); | 259 | return_VALUE(0); |
284 | } | 260 | } |
285 | 261 | ||
286 | 262 | static void __exit acpi_fan_exit(void) | |
287 | static void __exit | ||
288 | acpi_fan_exit (void) | ||
289 | { | 263 | { |
290 | ACPI_FUNCTION_TRACE("acpi_fan_exit"); | 264 | ACPI_FUNCTION_TRACE("acpi_fan_exit"); |
291 | 265 | ||
@@ -296,7 +270,5 @@ acpi_fan_exit (void) | |||
296 | return_VOID; | 270 | return_VOID; |
297 | } | 271 | } |
298 | 272 | ||
299 | |||
300 | module_init(acpi_fan_init); | 273 | module_init(acpi_fan_init); |
301 | module_exit(acpi_fan_exit); | 274 | module_exit(acpi_fan_exit); |
302 | |||