Blame view
drivers/acpi/fan.c
5.66 KB
1da177e4c Linux-2.6.12-rc2 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
/* * acpi_fan.c - ACPI Fan Driver ($Revision: 29 $) * * Copyright (C) 2001, 2002 Andy Grover <andrew.grover@intel.com> * Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com> * * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or (at * your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */ #include <linux/kernel.h> #include <linux/module.h> #include <linux/init.h> #include <linux/types.h> |
1da177e4c Linux-2.6.12-rc2 |
30 |
#include <asm/uaccess.h> |
05a83d972 ACPI: register AC... |
31 |
#include <linux/thermal.h> |
1da177e4c Linux-2.6.12-rc2 |
32 33 |
#include <acpi/acpi_bus.h> #include <acpi/acpi_drivers.h> |
a192a9580 ACPI: Move defini... |
34 |
#define PREFIX "ACPI: " |
1da177e4c Linux-2.6.12-rc2 |
35 |
#define ACPI_FAN_CLASS "fan" |
1da177e4c Linux-2.6.12-rc2 |
36 |
#define ACPI_FAN_FILE_STATE "state" |
1da177e4c Linux-2.6.12-rc2 |
37 38 |
#define _COMPONENT ACPI_FAN_COMPONENT |
f52fd66d2 ACPI: clean up AC... |
39 |
ACPI_MODULE_NAME("fan"); |
1da177e4c Linux-2.6.12-rc2 |
40 |
|
f52fd66d2 ACPI: clean up AC... |
41 |
MODULE_AUTHOR("Paul Diefenbaugh"); |
7cda93e00 ACPI: delete extr... |
42 |
MODULE_DESCRIPTION("ACPI Fan Driver"); |
1da177e4c Linux-2.6.12-rc2 |
43 |
MODULE_LICENSE("GPL"); |
4be44fcd3 [ACPI] Lindent al... |
44 45 |
static int acpi_fan_add(struct acpi_device *device); static int acpi_fan_remove(struct acpi_device *device, int type); |
ec68373c0 Revert "ACPI: Fan... |
46 47 |
static int acpi_fan_suspend(struct acpi_device *device, pm_message_t state); static int acpi_fan_resume(struct acpi_device *device); |
1da177e4c Linux-2.6.12-rc2 |
48 |
|
1ba90e3a8 ACPI: autoload mo... |
49 50 51 52 53 |
static const struct acpi_device_id fan_device_ids[] = { {"PNP0C0B", 0}, {"", 0}, }; MODULE_DEVICE_TABLE(acpi, fan_device_ids); |
1da177e4c Linux-2.6.12-rc2 |
54 |
static struct acpi_driver acpi_fan_driver = { |
c2b6705b7 ACPI: fix acpi_dr... |
55 |
.name = "fan", |
4be44fcd3 [ACPI] Lindent al... |
56 |
.class = ACPI_FAN_CLASS, |
1ba90e3a8 ACPI: autoload mo... |
57 |
.ids = fan_device_ids, |
4be44fcd3 [ACPI] Lindent al... |
58 59 60 |
.ops = { .add = acpi_fan_add, .remove = acpi_fan_remove, |
ec68373c0 Revert "ACPI: Fan... |
61 62 |
.suspend = acpi_fan_suspend, .resume = acpi_fan_resume, |
4be44fcd3 [ACPI] Lindent al... |
63 |
}, |
1da177e4c Linux-2.6.12-rc2 |
64 |
}; |
05a83d972 ACPI: register AC... |
65 |
/* thermal cooling device callbacks */ |
6503e5df0 thermal: use inte... |
66 67 |
static int fan_get_max_state(struct thermal_cooling_device *cdev, unsigned long *state) |
05a83d972 ACPI: register AC... |
68 69 |
{ /* ACPI fan device only support two states: ON/OFF */ |
6503e5df0 thermal: use inte... |
70 71 |
*state = 1; return 0; |
05a83d972 ACPI: register AC... |
72 |
} |
6503e5df0 thermal: use inte... |
73 74 |
static int fan_get_cur_state(struct thermal_cooling_device *cdev, unsigned long *state) |
05a83d972 ACPI: register AC... |
75 76 |
{ struct acpi_device *device = cdev->devdata; |
05a83d972 ACPI: register AC... |
77 |
int result; |
6503e5df0 thermal: use inte... |
78 |
int acpi_state; |
05a83d972 ACPI: register AC... |
79 80 81 |
if (!device) return -EINVAL; |
488a76c52 ACPI / Fan: Rewor... |
82 |
result = acpi_bus_update_power(device->handle, &acpi_state); |
05a83d972 ACPI: register AC... |
83 84 |
if (result) return result; |
6503e5df0 thermal: use inte... |
85 86 87 |
*state = (acpi_state == ACPI_STATE_D3 ? 0 : (acpi_state == ACPI_STATE_D0 ? 1 : -1)); return 0; |
05a83d972 ACPI: register AC... |
88 89 90 |
} static int |
6503e5df0 thermal: use inte... |
91 |
fan_set_cur_state(struct thermal_cooling_device *cdev, unsigned long state) |
05a83d972 ACPI: register AC... |
92 93 94 95 96 97 98 99 100 101 102 103 |
{ struct acpi_device *device = cdev->devdata; int result; if (!device || (state != 0 && state != 1)) return -EINVAL; result = acpi_bus_set_power(device->handle, state ? ACPI_STATE_D0 : ACPI_STATE_D3); return result; } |
9c8b04be4 ACPI: constify op... |
104 |
static const struct thermal_cooling_device_ops fan_cooling_ops = { |
05a83d972 ACPI: register AC... |
105 106 107 108 |
.get_max_state = fan_get_max_state, .get_cur_state = fan_get_cur_state, .set_cur_state = fan_set_cur_state, }; |
1da177e4c Linux-2.6.12-rc2 |
109 |
/* -------------------------------------------------------------------------- |
1da177e4c Linux-2.6.12-rc2 |
110 111 |
Driver Interface -------------------------------------------------------------------------- */ |
4be44fcd3 [ACPI] Lindent al... |
112 |
static int acpi_fan_add(struct acpi_device *device) |
1da177e4c Linux-2.6.12-rc2 |
113 |
{ |
4be44fcd3 [ACPI] Lindent al... |
114 |
int result = 0; |
05a83d972 ACPI: register AC... |
115 |
struct thermal_cooling_device *cdev; |
1da177e4c Linux-2.6.12-rc2 |
116 117 |
if (!device) |
d550d98d3 ACPI: delete trac... |
118 |
return -EINVAL; |
1da177e4c Linux-2.6.12-rc2 |
119 |
|
c65ade4dc [ACPI] whitespace |
120 |
strcpy(acpi_device_name(device), "Fan"); |
1da177e4c Linux-2.6.12-rc2 |
121 |
strcpy(acpi_device_class(device), ACPI_FAN_CLASS); |
1da177e4c Linux-2.6.12-rc2 |
122 |
|
488a76c52 ACPI / Fan: Rewor... |
123 |
result = acpi_bus_update_power(device->handle, NULL); |
1da177e4c Linux-2.6.12-rc2 |
124 |
if (result) { |
488a76c52 ACPI / Fan: Rewor... |
125 126 |
printk(KERN_ERR PREFIX "Setting initial power state "); |
1da177e4c Linux-2.6.12-rc2 |
127 128 |
goto end; } |
05a83d972 ACPI: register AC... |
129 130 |
cdev = thermal_cooling_device_register("Fan", device, &fan_cooling_ops); |
19b36780e ACPI fan: extract... |
131 132 133 134 |
if (IS_ERR(cdev)) { result = PTR_ERR(cdev); goto end; } |
9030062f3 ACPI: elide a non... |
135 |
|
13c411570 ACPI: Remove repe... |
136 137 |
dev_dbg(&device->dev, "registered as cooling_device%d ", cdev->id); |
9030062f3 ACPI: elide a non... |
138 |
|
db89b4f0d ACPI: catch calls... |
139 |
device->driver_data = cdev; |
9030062f3 ACPI: elide a non... |
140 141 142 143 |
result = sysfs_create_link(&device->dev.kobj, &cdev->device.kobj, "thermal_cooling"); if (result) |
fc3a8828b driver core: fix ... |
144 145 146 |
dev_err(&device->dev, "Failed to create sysfs link " "'thermal_cooling' "); |
9030062f3 ACPI: elide a non... |
147 148 149 150 151 |
result = sysfs_create_link(&cdev->device.kobj, &device->dev.kobj, "device"); if (result) |
fc3a8828b driver core: fix ... |
152 153 154 |
dev_err(&device->dev, "Failed to create sysfs link " "'device' "); |
05a83d972 ACPI: register AC... |
155 |
|
1da177e4c Linux-2.6.12-rc2 |
156 157 |
printk(KERN_INFO PREFIX "%s [%s] (%s) ", |
4be44fcd3 [ACPI] Lindent al... |
158 159 |
acpi_device_name(device), acpi_device_bid(device), !device->power.state ? "on" : "off"); |
1da177e4c Linux-2.6.12-rc2 |
160 |
|
4be44fcd3 [ACPI] Lindent al... |
161 |
end: |
d550d98d3 ACPI: delete trac... |
162 |
return result; |
1da177e4c Linux-2.6.12-rc2 |
163 |
} |
4be44fcd3 [ACPI] Lindent al... |
164 |
static int acpi_fan_remove(struct acpi_device *device, int type) |
1da177e4c Linux-2.6.12-rc2 |
165 |
{ |
05a83d972 ACPI: register AC... |
166 167 168 |
struct thermal_cooling_device *cdev = acpi_driver_data(device); if (!device || !cdev) |
d550d98d3 ACPI: delete trac... |
169 |
return -EINVAL; |
1da177e4c Linux-2.6.12-rc2 |
170 |
|
05a83d972 ACPI: register AC... |
171 172 173 |
sysfs_remove_link(&device->dev.kobj, "thermal_cooling"); sysfs_remove_link(&cdev->device.kobj, "device"); thermal_cooling_device_unregister(cdev); |
1da177e4c Linux-2.6.12-rc2 |
174 |
|
d550d98d3 ACPI: delete trac... |
175 |
return 0; |
1da177e4c Linux-2.6.12-rc2 |
176 |
} |
ec68373c0 Revert "ACPI: Fan... |
177 178 179 180 181 182 183 184 185 186 187 188 |
static int acpi_fan_suspend(struct acpi_device *device, pm_message_t state) { if (!device) return -EINVAL; acpi_bus_set_power(device->handle, ACPI_STATE_D0); return AE_OK; } static int acpi_fan_resume(struct acpi_device *device) { |
488a76c52 ACPI / Fan: Rewor... |
189 |
int result; |
ec68373c0 Revert "ACPI: Fan... |
190 191 192 |
if (!device) return -EINVAL; |
488a76c52 ACPI / Fan: Rewor... |
193 194 195 196 |
result = acpi_bus_update_power(device->handle, NULL); if (result) printk(KERN_ERR PREFIX "Error updating fan power state "); |
ec68373c0 Revert "ACPI: Fan... |
197 198 199 |
return result; } |
4be44fcd3 [ACPI] Lindent al... |
200 |
static int __init acpi_fan_init(void) |
1da177e4c Linux-2.6.12-rc2 |
201 |
{ |
c65ade4dc [ACPI] whitespace |
202 |
int result = 0; |
1da177e4c Linux-2.6.12-rc2 |
203 |
|
1da177e4c Linux-2.6.12-rc2 |
204 |
result = acpi_bus_register_driver(&acpi_fan_driver); |
b2a44989c ACPI fan: remove ... |
205 |
if (result < 0) |
d550d98d3 ACPI: delete trac... |
206 |
return -ENODEV; |
1da177e4c Linux-2.6.12-rc2 |
207 |
|
d550d98d3 ACPI: delete trac... |
208 |
return 0; |
1da177e4c Linux-2.6.12-rc2 |
209 |
} |
4be44fcd3 [ACPI] Lindent al... |
210 |
static void __exit acpi_fan_exit(void) |
1da177e4c Linux-2.6.12-rc2 |
211 |
{ |
1da177e4c Linux-2.6.12-rc2 |
212 213 |
acpi_bus_unregister_driver(&acpi_fan_driver); |
d550d98d3 ACPI: delete trac... |
214 |
return; |
1da177e4c Linux-2.6.12-rc2 |
215 |
} |
1da177e4c Linux-2.6.12-rc2 |
216 217 |
module_init(acpi_fan_init); module_exit(acpi_fan_exit); |