OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [linux/] [linux-2.4/] [drivers/] [acpi/] [fan.c] - Blame information for rev 1774

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1275 phoenix
/*
2
 *  acpi_fan.c - ACPI Fan Driver ($Revision: 1.1.1.1 $)
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/compatmac.h>
31
#include <linux/proc_fs.h>
32
#include <acpi/acpi_bus.h>
33
#include <acpi/acpi_drivers.h>
34
 
35
 
36
#define _COMPONENT              ACPI_FAN_COMPONENT
37
ACPI_MODULE_NAME                ("acpi_fan")
38
 
39
MODULE_AUTHOR("Paul Diefenbaugh");
40
MODULE_DESCRIPTION(ACPI_FAN_DRIVER_NAME);
41
MODULE_LICENSE("GPL");
42
 
43
#define PREFIX                  "ACPI: "
44
 
45
 
46
int acpi_fan_add (struct acpi_device *device);
47
int acpi_fan_remove (struct acpi_device *device, int type);
48
 
49
static struct acpi_driver acpi_fan_driver = {
50
        .name =         ACPI_FAN_DRIVER_NAME,
51
        .class =        ACPI_FAN_CLASS,
52
        .ids =          ACPI_FAN_HID,
53
        .ops =          {
54
                                .add =          acpi_fan_add,
55
                                .remove =       acpi_fan_remove,
56
                        },
57
};
58
 
59
struct acpi_fan {
60
        acpi_handle             handle;
61
};
62
 
63
 
64
/* --------------------------------------------------------------------------
65
                              FS Interface (/proc)
66
   -------------------------------------------------------------------------- */
67
 
68
struct proc_dir_entry           *acpi_fan_dir;
69
 
70
 
71
static int
72
acpi_fan_read_state (
73
        char                    *page,
74
        char                    **start,
75
        off_t                   off,
76
        int                     count,
77
        int                     *eof,
78
        void                    *data)
79
{
80
        struct acpi_fan         *fan = (struct acpi_fan *) data;
81
        char                    *p = page;
82
        int                     len = 0;
83
        int                     state = 0;
84
 
85
        ACPI_FUNCTION_TRACE("acpi_fan_read_state");
86
 
87
        if (!fan || (off != 0))
88
                goto end;
89
 
90
        if (acpi_bus_get_power(fan->handle, &state))
91
                goto end;
92
 
93
        p += sprintf(p, "status:                  %s\n",
94
                !state?"on":"off");
95
 
96
end:
97
        len = (p - page);
98
        if (len <= off+count) *eof = 1;
99
        *start = page + off;
100
        len -= off;
101
        if (len>count) len = count;
102
        if (len<0) len = 0;
103
 
104
        return_VALUE(len);
105
}
106
 
107
 
108
static int
109
acpi_fan_write_state (
110
        struct file             *file,
111
        const char              *buffer,
112
        unsigned long           count,
113
        void                    *data)
114
{
115
        int                     result = 0;
116
        struct acpi_fan         *fan = (struct acpi_fan *) data;
117
        char                    state_string[12] = {'\0'};
118
 
119
        ACPI_FUNCTION_TRACE("acpi_fan_write_state");
120
 
121
        if (!fan || (count > sizeof(state_string) - 1))
122
                return_VALUE(-EINVAL);
123
 
124
        if (copy_from_user(state_string, buffer, count))
125
                return_VALUE(-EFAULT);
126
 
127
        state_string[count] = '\0';
128
 
129
        result = acpi_bus_set_power(fan->handle,
130
                simple_strtoul(state_string, NULL, 0));
131
        if (result)
132
                return_VALUE(result);
133
 
134
        return_VALUE(count);
135
}
136
 
137
 
138
static int
139
acpi_fan_add_fs (
140
        struct acpi_device      *device)
141
{
142
        struct proc_dir_entry   *entry = NULL;
143
 
144
        ACPI_FUNCTION_TRACE("acpi_fan_add_fs");
145
 
146
        if (!device)
147
                return_VALUE(-EINVAL);
148
 
149
        if (!acpi_device_dir(device)) {
150
                acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device),
151
                        acpi_fan_dir);
152
                if (!acpi_device_dir(device))
153
                        return_VALUE(-ENODEV);
154
        }
155
 
156
        /* 'status' [R/W] */
157
        entry = create_proc_entry(ACPI_FAN_FILE_STATE,
158
                S_IFREG|S_IRUGO|S_IWUSR, acpi_device_dir(device));
159
        if (!entry)
160
                ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
161
                        "Unable to create '%s' fs entry\n",
162
                        ACPI_FAN_FILE_STATE));
163
        else {
164
                entry->read_proc = acpi_fan_read_state;
165
                entry->write_proc = acpi_fan_write_state;
166
                entry->data = acpi_driver_data(device);
167
        }
168
 
169
        return_VALUE(0);
170
}
171
 
172
 
173
static int
174
acpi_fan_remove_fs (
175
        struct acpi_device      *device)
176
{
177
        ACPI_FUNCTION_TRACE("acpi_fan_remove_fs");
178
 
179
        if (acpi_device_dir(device)) {
180
                remove_proc_entry(acpi_device_bid(device), acpi_fan_dir);
181
                acpi_device_dir(device) = NULL;
182
        }
183
 
184
        return_VALUE(0);
185
}
186
 
187
 
188
/* --------------------------------------------------------------------------
189
                                 Driver Interface
190
   -------------------------------------------------------------------------- */
191
 
192
int
193
acpi_fan_add (
194
        struct acpi_device      *device)
195
{
196
        int                     result = 0;
197
        struct acpi_fan         *fan = NULL;
198
        int                     state = 0;
199
 
200
        ACPI_FUNCTION_TRACE("acpi_fan_add");
201
 
202
        if (!device)
203
                return_VALUE(-EINVAL);
204
 
205
        fan = kmalloc(sizeof(struct acpi_fan), GFP_KERNEL);
206
        if (!fan)
207
                return_VALUE(-ENOMEM);
208
        memset(fan, 0, sizeof(struct acpi_fan));
209
 
210
        fan->handle = device->handle;
211
        sprintf(acpi_device_name(device), "%s", ACPI_FAN_DEVICE_NAME);
212
        sprintf(acpi_device_class(device), "%s", ACPI_FAN_CLASS);
213
        acpi_driver_data(device) = fan;
214
 
215
        result = acpi_bus_get_power(fan->handle, &state);
216
        if (result) {
217
                ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
218
                        "Error reading power state\n"));
219
                goto end;
220
        }
221
 
222
        result = acpi_fan_add_fs(device);
223
        if (result)
224
                goto end;
225
 
226
        printk(KERN_INFO PREFIX "%s [%s] (%s)\n",
227
                acpi_device_name(device), acpi_device_bid(device),
228
                !device->power.state?"on":"off");
229
 
230
end:
231
        if (result)
232
                kfree(fan);
233
 
234
        return_VALUE(result);
235
}
236
 
237
 
238
int
239
acpi_fan_remove (
240
        struct acpi_device      *device,
241
        int                     type)
242
{
243
        struct acpi_fan         *fan = NULL;
244
 
245
        ACPI_FUNCTION_TRACE("acpi_fan_remove");
246
 
247
        if (!device || !acpi_driver_data(device))
248
                return_VALUE(-EINVAL);
249
 
250
        fan = (struct acpi_fan *) acpi_driver_data(device);
251
 
252
        acpi_fan_remove_fs(device);
253
 
254
        kfree(fan);
255
 
256
        return_VALUE(0);
257
}
258
 
259
 
260
int __init
261
acpi_fan_init (void)
262
{
263
        int                     result = 0;
264
 
265
        ACPI_FUNCTION_TRACE("acpi_fan_init");
266
 
267
        acpi_fan_dir = proc_mkdir(ACPI_FAN_CLASS, acpi_root_dir);
268
        if (!acpi_fan_dir)
269
                return_VALUE(-ENODEV);
270
 
271
        result = acpi_bus_register_driver(&acpi_fan_driver);
272
        if (result < 0) {
273
                remove_proc_entry(ACPI_FAN_CLASS, acpi_root_dir);
274
                return_VALUE(-ENODEV);
275
        }
276
 
277
        return_VALUE(0);
278
}
279
 
280
 
281
void __exit
282
acpi_fan_exit (void)
283
{
284
        ACPI_FUNCTION_TRACE("acpi_fan_exit");
285
 
286
        acpi_bus_unregister_driver(&acpi_fan_driver);
287
 
288
        remove_proc_entry(ACPI_FAN_CLASS, acpi_root_dir);
289
 
290
        return_VOID;
291
}
292
 
293
 
294
module_init(acpi_fan_init);
295
module_exit(acpi_fan_exit);
296
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.