]>
Commit | Line | Data |
---|---|---|
1da177e4 LT |
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> | |
1da177e4 | 30 | #include <asm/uaccess.h> |
05a83d97 | 31 | #include <linux/thermal.h> |
8b48463f | 32 | #include <linux/acpi.h> |
1da177e4 | 33 | |
a192a958 LB |
34 | #define PREFIX "ACPI: " |
35 | ||
1da177e4 | 36 | #define ACPI_FAN_CLASS "fan" |
1da177e4 | 37 | #define ACPI_FAN_FILE_STATE "state" |
1da177e4 LT |
38 | |
39 | #define _COMPONENT ACPI_FAN_COMPONENT | |
f52fd66d | 40 | ACPI_MODULE_NAME("fan"); |
1da177e4 | 41 | |
f52fd66d | 42 | MODULE_AUTHOR("Paul Diefenbaugh"); |
7cda93e0 | 43 | MODULE_DESCRIPTION("ACPI Fan Driver"); |
1da177e4 LT |
44 | MODULE_LICENSE("GPL"); |
45 | ||
4be44fcd | 46 | static int acpi_fan_add(struct acpi_device *device); |
51fac838 | 47 | static int acpi_fan_remove(struct acpi_device *device); |
1da177e4 | 48 | |
1ba90e3a TR |
49 | static const struct acpi_device_id fan_device_ids[] = { |
50 | {"PNP0C0B", 0}, | |
51 | {"", 0}, | |
52 | }; | |
53 | MODULE_DEVICE_TABLE(acpi, fan_device_ids); | |
54 | ||
90692404 | 55 | #ifdef CONFIG_PM_SLEEP |
62fcbdd9 RW |
56 | static int acpi_fan_suspend(struct device *dev); |
57 | static int acpi_fan_resume(struct device *dev); | |
b9b8515f AL |
58 | static struct dev_pm_ops acpi_fan_pm = { |
59 | .resume = acpi_fan_resume, | |
60 | .freeze = acpi_fan_suspend, | |
61 | .thaw = acpi_fan_resume, | |
62 | .restore = acpi_fan_resume, | |
63 | }; | |
64 | #define FAN_PM_OPS_PTR (&acpi_fan_pm) | |
b108e0ea | 65 | #else |
b9b8515f | 66 | #define FAN_PM_OPS_PTR NULL |
90692404 | 67 | #endif |
62fcbdd9 | 68 | |
1da177e4 | 69 | static struct acpi_driver acpi_fan_driver = { |
c2b6705b | 70 | .name = "fan", |
4be44fcd | 71 | .class = ACPI_FAN_CLASS, |
1ba90e3a | 72 | .ids = fan_device_ids, |
4be44fcd LB |
73 | .ops = { |
74 | .add = acpi_fan_add, | |
75 | .remove = acpi_fan_remove, | |
76 | }, | |
b9b8515f | 77 | .drv.pm = FAN_PM_OPS_PTR, |
1da177e4 LT |
78 | }; |
79 | ||
05a83d97 | 80 | /* thermal cooling device callbacks */ |
6503e5df MG |
81 | static int fan_get_max_state(struct thermal_cooling_device *cdev, unsigned long |
82 | *state) | |
05a83d97 ZR |
83 | { |
84 | /* ACPI fan device only support two states: ON/OFF */ | |
6503e5df MG |
85 | *state = 1; |
86 | return 0; | |
05a83d97 ZR |
87 | } |
88 | ||
6503e5df MG |
89 | static int fan_get_cur_state(struct thermal_cooling_device *cdev, unsigned long |
90 | *state) | |
05a83d97 ZR |
91 | { |
92 | struct acpi_device *device = cdev->devdata; | |
05a83d97 | 93 | int result; |
85eb9827 | 94 | int acpi_state = ACPI_STATE_D0; |
05a83d97 ZR |
95 | |
96 | if (!device) | |
97 | return -EINVAL; | |
98 | ||
488a76c5 | 99 | result = acpi_bus_update_power(device->handle, &acpi_state); |
05a83d97 ZR |
100 | if (result) |
101 | return result; | |
102 | ||
8ad928d5 | 103 | *state = (acpi_state == ACPI_STATE_D3_COLD ? 0 : |
6503e5df MG |
104 | (acpi_state == ACPI_STATE_D0 ? 1 : -1)); |
105 | return 0; | |
05a83d97 ZR |
106 | } |
107 | ||
108 | static int | |
6503e5df | 109 | fan_set_cur_state(struct thermal_cooling_device *cdev, unsigned long state) |
05a83d97 ZR |
110 | { |
111 | struct acpi_device *device = cdev->devdata; | |
112 | int result; | |
113 | ||
114 | if (!device || (state != 0 && state != 1)) | |
115 | return -EINVAL; | |
116 | ||
117 | result = acpi_bus_set_power(device->handle, | |
8ad928d5 | 118 | state ? ACPI_STATE_D0 : ACPI_STATE_D3_COLD); |
05a83d97 ZR |
119 | |
120 | return result; | |
121 | } | |
122 | ||
9c8b04be | 123 | static const struct thermal_cooling_device_ops fan_cooling_ops = { |
05a83d97 ZR |
124 | .get_max_state = fan_get_max_state, |
125 | .get_cur_state = fan_get_cur_state, | |
126 | .set_cur_state = fan_set_cur_state, | |
127 | }; | |
128 | ||
1da177e4 LT |
129 | /* -------------------------------------------------------------------------- |
130 | Driver Interface | |
131 | -------------------------------------------------------------------------- */ | |
132 | ||
4be44fcd | 133 | static int acpi_fan_add(struct acpi_device *device) |
1da177e4 | 134 | { |
4be44fcd | 135 | int result = 0; |
05a83d97 | 136 | struct thermal_cooling_device *cdev; |
1da177e4 LT |
137 | |
138 | if (!device) | |
d550d98d | 139 | return -EINVAL; |
1da177e4 | 140 | |
c65ade4d | 141 | strcpy(acpi_device_name(device), "Fan"); |
1da177e4 | 142 | strcpy(acpi_device_class(device), ACPI_FAN_CLASS); |
1da177e4 | 143 | |
488a76c5 | 144 | result = acpi_bus_update_power(device->handle, NULL); |
1da177e4 | 145 | if (result) { |
488a76c5 | 146 | printk(KERN_ERR PREFIX "Setting initial power state\n"); |
1da177e4 LT |
147 | goto end; |
148 | } | |
149 | ||
05a83d97 ZR |
150 | cdev = thermal_cooling_device_register("Fan", device, |
151 | &fan_cooling_ops); | |
19b36780 TS |
152 | if (IS_ERR(cdev)) { |
153 | result = PTR_ERR(cdev); | |
154 | goto end; | |
155 | } | |
9030062f | 156 | |
13c41157 | 157 | dev_dbg(&device->dev, "registered as cooling_device%d\n", cdev->id); |
9030062f | 158 | |
db89b4f0 | 159 | device->driver_data = cdev; |
9030062f JL |
160 | result = sysfs_create_link(&device->dev.kobj, |
161 | &cdev->device.kobj, | |
162 | "thermal_cooling"); | |
163 | if (result) | |
fc3a8828 GKH |
164 | dev_err(&device->dev, "Failed to create sysfs link " |
165 | "'thermal_cooling'\n"); | |
9030062f JL |
166 | |
167 | result = sysfs_create_link(&cdev->device.kobj, | |
168 | &device->dev.kobj, | |
169 | "device"); | |
170 | if (result) | |
fc3a8828 GKH |
171 | dev_err(&device->dev, "Failed to create sysfs link " |
172 | "'device'\n"); | |
05a83d97 | 173 | |
1da177e4 | 174 | printk(KERN_INFO PREFIX "%s [%s] (%s)\n", |
4be44fcd LB |
175 | acpi_device_name(device), acpi_device_bid(device), |
176 | !device->power.state ? "on" : "off"); | |
1da177e4 | 177 | |
568b6ad8 | 178 | end: |
d550d98d | 179 | return result; |
1da177e4 LT |
180 | } |
181 | ||
51fac838 | 182 | static int acpi_fan_remove(struct acpi_device *device) |
1da177e4 | 183 | { |
f0c29583 CIK |
184 | struct thermal_cooling_device *cdev; |
185 | ||
186 | if (!device) | |
187 | return -EINVAL; | |
05a83d97 | 188 | |
f0c29583 CIK |
189 | cdev = acpi_driver_data(device); |
190 | if (!cdev) | |
d550d98d | 191 | return -EINVAL; |
1da177e4 | 192 | |
05a83d97 ZR |
193 | sysfs_remove_link(&device->dev.kobj, "thermal_cooling"); |
194 | sysfs_remove_link(&cdev->device.kobj, "device"); | |
195 | thermal_cooling_device_unregister(cdev); | |
1da177e4 | 196 | |
d550d98d | 197 | return 0; |
1da177e4 LT |
198 | } |
199 | ||
90692404 | 200 | #ifdef CONFIG_PM_SLEEP |
62fcbdd9 | 201 | static int acpi_fan_suspend(struct device *dev) |
ec68373c | 202 | { |
62fcbdd9 | 203 | if (!dev) |
ec68373c LB |
204 | return -EINVAL; |
205 | ||
62fcbdd9 | 206 | acpi_bus_set_power(to_acpi_device(dev)->handle, ACPI_STATE_D0); |
ec68373c LB |
207 | |
208 | return AE_OK; | |
209 | } | |
210 | ||
62fcbdd9 | 211 | static int acpi_fan_resume(struct device *dev) |
ec68373c | 212 | { |
488a76c5 | 213 | int result; |
ec68373c | 214 | |
62fcbdd9 | 215 | if (!dev) |
ec68373c LB |
216 | return -EINVAL; |
217 | ||
62fcbdd9 | 218 | result = acpi_bus_update_power(to_acpi_device(dev)->handle, NULL); |
488a76c5 RW |
219 | if (result) |
220 | printk(KERN_ERR PREFIX "Error updating fan power state\n"); | |
ec68373c LB |
221 | |
222 | return result; | |
223 | } | |
90692404 | 224 | #endif |
ec68373c | 225 | |
d8014c4b | 226 | module_acpi_driver(acpi_fan_driver); |