[PATCH] ppc32: Fix address checking on lmw/stmw align exception
[linux-2.6/verdex.git] / drivers / acpi / fan.c
blob14192ee55f8f1d907ad32fba8ef4f70d17a108bf
1 /*
2 * acpi_fan.c - ACPI Fan Driver ($Revision: 29 $)
4 * Copyright (C) 2001, 2002 Andy Grover <andrew.grover@intel.com>
5 * Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com>
7 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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.
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.
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.
23 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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>
34 #include <acpi/acpi_bus.h>
35 #include <acpi/acpi_drivers.h>
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
46 #define _COMPONENT ACPI_FAN_COMPONENT
47 ACPI_MODULE_NAME ("acpi_fan")
49 MODULE_AUTHOR("Paul Diefenbaugh");
50 MODULE_DESCRIPTION(ACPI_FAN_DRIVER_NAME);
51 MODULE_LICENSE("GPL");
53 static int acpi_fan_add (struct acpi_device *device);
54 static int acpi_fan_remove (struct acpi_device *device, int type);
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,
66 struct acpi_fan {
67 acpi_handle handle;
71 /* --------------------------------------------------------------------------
72 FS Interface (/proc)
73 -------------------------------------------------------------------------- */
75 static struct proc_dir_entry *acpi_fan_dir;
78 static int
79 acpi_fan_read_state (struct seq_file *seq, void *offset)
81 struct acpi_fan *fan = seq->private;
82 int state = 0;
84 ACPI_FUNCTION_TRACE("acpi_fan_read_state");
86 if (fan) {
87 if (acpi_bus_get_power(fan->handle, &state))
88 seq_printf(seq, "status: ERROR\n");
89 else
90 seq_printf(seq, "status: %s\n",
91 !state?"on":"off");
93 return_VALUE(0);
96 static int acpi_fan_state_open_fs(struct inode *inode, struct file *file)
98 return single_open(file, acpi_fan_read_state, PDE(inode)->data);
101 static ssize_t
102 acpi_fan_write_state (
103 struct file *file,
104 const char __user *buffer,
105 size_t count,
106 loff_t *ppos)
108 int result = 0;
109 struct seq_file *m = (struct seq_file *)file->private_data;
110 struct acpi_fan *fan = (struct acpi_fan *) m->private;
111 char state_string[12] = {'\0'};
113 ACPI_FUNCTION_TRACE("acpi_fan_write_state");
115 if (!fan || (count > sizeof(state_string) - 1))
116 return_VALUE(-EINVAL);
118 if (copy_from_user(state_string, buffer, count))
119 return_VALUE(-EFAULT);
121 state_string[count] = '\0';
123 result = acpi_bus_set_power(fan->handle,
124 simple_strtoul(state_string, NULL, 0));
125 if (result)
126 return_VALUE(result);
128 return_VALUE(count);
131 static struct file_operations acpi_fan_state_ops = {
132 .open = acpi_fan_state_open_fs,
133 .read = seq_read,
134 .write = acpi_fan_write_state,
135 .llseek = seq_lseek,
136 .release = single_release,
137 .owner = THIS_MODULE,
140 static int
141 acpi_fan_add_fs (
142 struct acpi_device *device)
144 struct proc_dir_entry *entry = NULL;
146 ACPI_FUNCTION_TRACE("acpi_fan_add_fs");
148 if (!device)
149 return_VALUE(-EINVAL);
151 if (!acpi_device_dir(device)) {
152 acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device),
153 acpi_fan_dir);
154 if (!acpi_device_dir(device))
155 return_VALUE(-ENODEV);
156 acpi_device_dir(device)->owner = THIS_MODULE;
159 /* 'status' [R/W] */
160 entry = create_proc_entry(ACPI_FAN_FILE_STATE,
161 S_IFREG|S_IRUGO|S_IWUSR, acpi_device_dir(device));
162 if (!entry)
163 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
164 "Unable to create '%s' fs entry\n",
165 ACPI_FAN_FILE_STATE));
166 else {
167 entry->proc_fops = &acpi_fan_state_ops;
168 entry->data = acpi_driver_data(device);
169 entry->owner = THIS_MODULE;
172 return_VALUE(0);
176 static int
177 acpi_fan_remove_fs (
178 struct acpi_device *device)
180 ACPI_FUNCTION_TRACE("acpi_fan_remove_fs");
182 if (acpi_device_dir(device)) {
183 remove_proc_entry(ACPI_FAN_FILE_STATE,
184 acpi_device_dir(device));
185 remove_proc_entry(acpi_device_bid(device), acpi_fan_dir);
186 acpi_device_dir(device) = NULL;
189 return_VALUE(0);
193 /* --------------------------------------------------------------------------
194 Driver Interface
195 -------------------------------------------------------------------------- */
197 static int
198 acpi_fan_add (
199 struct acpi_device *device)
201 int result = 0;
202 struct acpi_fan *fan = NULL;
203 int state = 0;
205 ACPI_FUNCTION_TRACE("acpi_fan_add");
207 if (!device)
208 return_VALUE(-EINVAL);
210 fan = kmalloc(sizeof(struct acpi_fan), GFP_KERNEL);
211 if (!fan)
212 return_VALUE(-ENOMEM);
213 memset(fan, 0, sizeof(struct acpi_fan));
215 fan->handle = device->handle;
216 strcpy(acpi_device_name(device), ACPI_FAN_DEVICE_NAME);
217 strcpy(acpi_device_class(device), ACPI_FAN_CLASS);
218 acpi_driver_data(device) = fan;
220 result = acpi_bus_get_power(fan->handle, &state);
221 if (result) {
222 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
223 "Error reading power state\n"));
224 goto end;
227 result = acpi_fan_add_fs(device);
228 if (result)
229 goto end;
231 printk(KERN_INFO PREFIX "%s [%s] (%s)\n",
232 acpi_device_name(device), acpi_device_bid(device),
233 !device->power.state?"on":"off");
235 end:
236 if (result)
237 kfree(fan);
239 return_VALUE(result);
243 static int
244 acpi_fan_remove (
245 struct acpi_device *device,
246 int type)
248 struct acpi_fan *fan = NULL;
250 ACPI_FUNCTION_TRACE("acpi_fan_remove");
252 if (!device || !acpi_driver_data(device))
253 return_VALUE(-EINVAL);
255 fan = (struct acpi_fan *) acpi_driver_data(device);
257 acpi_fan_remove_fs(device);
259 kfree(fan);
261 return_VALUE(0);
265 static int __init
266 acpi_fan_init (void)
268 int result = 0;
270 ACPI_FUNCTION_TRACE("acpi_fan_init");
272 acpi_fan_dir = proc_mkdir(ACPI_FAN_CLASS, acpi_root_dir);
273 if (!acpi_fan_dir)
274 return_VALUE(-ENODEV);
275 acpi_fan_dir->owner = THIS_MODULE;
277 result = acpi_bus_register_driver(&acpi_fan_driver);
278 if (result < 0) {
279 remove_proc_entry(ACPI_FAN_CLASS, acpi_root_dir);
280 return_VALUE(-ENODEV);
283 return_VALUE(0);
287 static void __exit
288 acpi_fan_exit (void)
290 ACPI_FUNCTION_TRACE("acpi_fan_exit");
292 acpi_bus_unregister_driver(&acpi_fan_driver);
294 remove_proc_entry(ACPI_FAN_CLASS, acpi_root_dir);
296 return_VOID;
300 module_init(acpi_fan_init);
301 module_exit(acpi_fan_exit);