1 /*
2 * acpi_fan.c - ACPI Fan Driver ($Revision: 29 $)
3 *
4 * Copyright (C) 2001, 2002 Andy Grover <andrew.grover@intel.com>
5 * Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com>
6 *
7 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or (at
12 * your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write to the Free Software Foundation, Inc.,
21 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
22 *
23 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
24 */
25
26 #include <linux/kernel.h>
27 #include <linux/module.h>
28 #include <linux/init.h>
29 #include <linux/types.h>
30 #include <linux/proc_fs.h>
31 #include <linux/seq_file.h>
32 #include <asm/uaccess.h>
33
34 #include <acpi/acpi_bus.h>
35 #include <acpi/acpi_drivers.h>
36
37
38 #define ACPI_FAN_COMPONENT 0x00200000
39 #define ACPI_FAN_CLASS "fan"
40 #define ACPI_FAN_HID "PNP0C0B"
41 #define ACPI_FAN_DRIVER_NAME "ACPI Fan Driver"
42 #define ACPI_FAN_DEVICE_NAME "Fan"
43 #define ACPI_FAN_FILE_STATE "state"
44 #define ACPI_FAN_NOTIFY_STATUS 0x80
45
46 #define _COMPONENT ACPI_FAN_COMPONENT
47 ACPI_MODULE_NAME ("acpi_fan")
48
49 MODULE_AUTHOR("Paul Diefenbaugh");
50 MODULE_DESCRIPTION(ACPI_FAN_DRIVER_NAME);
51 MODULE_LICENSE("GPL");
52
53 int acpi_fan_add (struct acpi_device *device);
54 int acpi_fan_remove (struct acpi_device *device, int type);
55
56 static struct acpi_driver acpi_fan_driver = {
57 .name = ACPI_FAN_DRIVER_NAME,
58 .class = ACPI_FAN_CLASS,
59 .ids = ACPI_FAN_HID,
60 .ops = {
61 .add = acpi_fan_add,
62 .remove = acpi_fan_remove,
63 },
64 };
65
66 struct acpi_fan {
67 acpi_handle handle;
68 };
69
70
71 /* --------------------------------------------------------------------------
72 FS Interface (/proc)
73 -------------------------------------------------------------------------- */
74
75 struct proc_dir_entry *acpi_fan_dir;
76
77
78 static int
79 acpi_fan_read_state (struct seq_file *seq, void *offset)
80 {
81 struct acpi_fan *fan = (struct acpi_fan *) seq->private;
82 int state = 0;
83
84 ACPI_FUNCTION_TRACE("acpi_fan_read_state");
85
86 if (!fan)
87 goto end;
88
89 if (acpi_bus_get_power(fan->handle, &state))
90 goto end;
91
92 seq_printf(seq, "status: %s\n",
93 !state?"on":"off");
94
95 end:
96 return_VALUE(0);
97 }
98
99 static int acpi_fan_state_open_fs(struct inode *inode, struct file *file)
100 {
101 return single_open(file, acpi_fan_read_state, PDE(inode)->data);
102 }
103
104 static ssize_t
105 acpi_fan_write_state (
106 struct file *file,
107 const char __user *buffer,
108 size_t count,
109 loff_t *ppos)
110 {
111 int result = 0;
112 struct seq_file *m = (struct seq_file *)file->private_data;
113 struct acpi_fan *fan = (struct acpi_fan *) m->private;
114 char state_string[12] = {'\0'};
115
116 ACPI_FUNCTION_TRACE("acpi_fan_write_state");
117
118 if (!fan || (count > sizeof(state_string) - 1))
119 return_VALUE(-EINVAL);
120
121 if (copy_from_user(state_string, buffer, count))
122 return_VALUE(-EFAULT);
123
124 state_string[count] = '\0';
125
126 result = acpi_bus_set_power(fan->handle,
127 simple_strtoul(state_string, NULL, 0));
128 if (result)
129 return_VALUE(result);
130
131 return_VALUE(count);
132 }
133
134 static struct file_operations acpi_fan_state_ops = {
135 .open = acpi_fan_state_open_fs,
136 .read = seq_read,
137 .write = acpi_fan_write_state,
138 .llseek = seq_lseek,
139 .release = single_release,
140 .owner = THIS_MODULE,
141 };
142
143 static int
144 acpi_fan_add_fs (
145 struct acpi_device *device)
146 {
147 struct proc_dir_entry *entry = NULL;
148
149 ACPI_FUNCTION_TRACE("acpi_fan_add_fs");
150
151 if (!device)
152 return_VALUE(-EINVAL);
153
154 if (!acpi_device_dir(device)) {
155 acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device),
156 acpi_fan_dir);
157 if (!acpi_device_dir(device))
158 return_VALUE(-ENODEV);
159 acpi_device_dir(device)->owner = THIS_MODULE;
160 }
161
162 /* 'status' [R/W] */
163 entry = create_proc_entry(ACPI_FAN_FILE_STATE,
164 S_IFREG|S_IRUGO|S_IWUSR, acpi_device_dir(device));
165 if (!entry)
166 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
167 "Unable to create '%s' fs entry\n",
168 ACPI_FAN_FILE_STATE));
169 else {
170 entry->proc_fops = &acpi_fan_state_ops;
171 entry->data = acpi_driver_data(device);
172 entry->owner = THIS_MODULE;
173 }
174
175 return_VALUE(0);
176 }
177
178
179 static int
180 acpi_fan_remove_fs (
181 struct acpi_device *device)
182 {
183 ACPI_FUNCTION_TRACE("acpi_fan_remove_fs");
184
185 if (acpi_device_dir(device)) {
186 remove_proc_entry(ACPI_FAN_FILE_STATE,
187 acpi_device_dir(device));
188 remove_proc_entry(acpi_device_bid(device), acpi_fan_dir);
189 acpi_device_dir(device) = NULL;
190 }
191
192 return_VALUE(0);
193 }
194
195
196 /* --------------------------------------------------------------------------
197 Driver Interface
198 -------------------------------------------------------------------------- */
199
200 int
201 acpi_fan_add (
202 struct acpi_device *device)
203 {
204 int result = 0;
205 struct acpi_fan *fan = NULL;
206 int state = 0;
207
208 ACPI_FUNCTION_TRACE("acpi_fan_add");
209
210 if (!device)
211 return_VALUE(-EINVAL);
212
213 fan = kmalloc(sizeof(struct acpi_fan), GFP_KERNEL);
214 if (!fan)
215 return_VALUE(-ENOMEM);
216 memset(fan, 0, sizeof(struct acpi_fan));
217
218 fan->handle = device->handle;
219 strcpy(acpi_device_name(device), ACPI_FAN_DEVICE_NAME);
220 strcpy(acpi_device_class(device), ACPI_FAN_CLASS);
221 acpi_driver_data(device) = fan;
222
223 result = acpi_bus_get_power(fan->handle, &state);
224 if (result) {
225 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
226 "Error reading power state\n"));
227 goto end;
228 }
229
230 result = acpi_fan_add_fs(device);
231 if (result)
232 goto end;
233
234 printk(KERN_INFO PREFIX "%s [%s] (%s)\n",
235 acpi_device_name(device), acpi_device_bid(device),
236 !device->power.state?"on":"off");
237
238 end:
239 if (result)
240 kfree(fan);
241
242 return_VALUE(result);
243 }
244
245
246 int
247 acpi_fan_remove (
248 struct acpi_device *device,
249 int type)
250 {
251 struct acpi_fan *fan = NULL;
252
253 ACPI_FUNCTION_TRACE("acpi_fan_remove");
254
255 if (!device || !acpi_driver_data(device))
256 return_VALUE(-EINVAL);
257
258 fan = (struct acpi_fan *) acpi_driver_data(device);
259
260 acpi_fan_remove_fs(device);
261
262 kfree(fan);
263
264 return_VALUE(0);
265 }
266
267
268 int __init
269 acpi_fan_init (void)
270 {
271 int result = 0;
272
273 ACPI_FUNCTION_TRACE("acpi_fan_init");
274
275 acpi_fan_dir = proc_mkdir(ACPI_FAN_CLASS, acpi_root_dir);
276 if (!acpi_fan_dir)
277 return_VALUE(-ENODEV);
278 acpi_fan_dir->owner = THIS_MODULE;
279
280 result = acpi_bus_register_driver(&acpi_fan_driver);
281 if (result < 0) {
282 remove_proc_entry(ACPI_FAN_CLASS, acpi_root_dir);
283 return_VALUE(-ENODEV);
284 }
285
286 return_VALUE(0);
287 }
288
289
290 void __exit
291 acpi_fan_exit (void)
292 {
293 ACPI_FUNCTION_TRACE("acpi_fan_exit");
294
295 acpi_bus_unregister_driver(&acpi_fan_driver);
296
297 remove_proc_entry(ACPI_FAN_CLASS, acpi_root_dir);
298
299 return_VOID;
300 }
301
302
303 module_init(acpi_fan_init);
304 module_exit(acpi_fan_exit);
305
306
|
This page was automatically generated by the
LXR engine.
|