diff options
Diffstat (limited to 'drivers/acpi/fan.c')
-rw-r--r-- | drivers/acpi/fan.c | 72 |
1 files changed, 7 insertions, 65 deletions
diff --git a/drivers/acpi/fan.c b/drivers/acpi/fan.c index c81f6bdb68b8..a5a5532db268 100644 --- a/drivers/acpi/fan.c +++ b/drivers/acpi/fan.c | |||
@@ -47,8 +47,6 @@ MODULE_LICENSE("GPL"); | |||
47 | 47 | ||
48 | static int acpi_fan_add(struct acpi_device *device); | 48 | static int acpi_fan_add(struct acpi_device *device); |
49 | static int acpi_fan_remove(struct acpi_device *device, int type); | 49 | static int acpi_fan_remove(struct acpi_device *device, int type); |
50 | static int acpi_fan_suspend(struct acpi_device *device, pm_message_t state); | ||
51 | static int acpi_fan_resume(struct acpi_device *device); | ||
52 | 50 | ||
53 | static const struct acpi_device_id fan_device_ids[] = { | 51 | static const struct acpi_device_id fan_device_ids[] = { |
54 | {"PNP0C0B", 0}, | 52 | {"PNP0C0B", 0}, |
@@ -63,15 +61,9 @@ static struct acpi_driver acpi_fan_driver = { | |||
63 | .ops = { | 61 | .ops = { |
64 | .add = acpi_fan_add, | 62 | .add = acpi_fan_add, |
65 | .remove = acpi_fan_remove, | 63 | .remove = acpi_fan_remove, |
66 | .suspend = acpi_fan_suspend, | ||
67 | .resume = acpi_fan_resume, | ||
68 | }, | 64 | }, |
69 | }; | 65 | }; |
70 | 66 | ||
71 | struct acpi_fan { | ||
72 | struct acpi_device * device; | ||
73 | }; | ||
74 | |||
75 | /* -------------------------------------------------------------------------- | 67 | /* -------------------------------------------------------------------------- |
76 | FS Interface (/proc) | 68 | FS Interface (/proc) |
77 | -------------------------------------------------------------------------- */ | 69 | -------------------------------------------------------------------------- */ |
@@ -80,12 +72,12 @@ static struct proc_dir_entry *acpi_fan_dir; | |||
80 | 72 | ||
81 | static int acpi_fan_read_state(struct seq_file *seq, void *offset) | 73 | static int acpi_fan_read_state(struct seq_file *seq, void *offset) |
82 | { | 74 | { |
83 | struct acpi_fan *fan = seq->private; | 75 | struct acpi_device *device = seq->private; |
84 | int state = 0; | 76 | int state = 0; |
85 | 77 | ||
86 | 78 | ||
87 | if (fan) { | 79 | if (device) { |
88 | if (acpi_bus_get_power(fan->device->handle, &state)) | 80 | if (acpi_bus_get_power(device->handle, &state)) |
89 | seq_printf(seq, "status: ERROR\n"); | 81 | seq_printf(seq, "status: ERROR\n"); |
90 | else | 82 | else |
91 | seq_printf(seq, "status: %s\n", | 83 | seq_printf(seq, "status: %s\n", |
@@ -105,11 +97,10 @@ acpi_fan_write_state(struct file *file, const char __user * buffer, | |||
105 | { | 97 | { |
106 | int result = 0; | 98 | int result = 0; |
107 | struct seq_file *m = file->private_data; | 99 | struct seq_file *m = file->private_data; |
108 | struct acpi_fan *fan = m->private; | 100 | struct acpi_device *device = m->private; |
109 | char state_string[12] = { '\0' }; | 101 | char state_string[12] = { '\0' }; |
110 | 102 | ||
111 | 103 | if (count > sizeof(state_string) - 1) | |
112 | if (!fan || (count > sizeof(state_string) - 1)) | ||
113 | return -EINVAL; | 104 | return -EINVAL; |
114 | 105 | ||
115 | if (copy_from_user(state_string, buffer, count)) | 106 | if (copy_from_user(state_string, buffer, count)) |
@@ -117,7 +108,7 @@ acpi_fan_write_state(struct file *file, const char __user * buffer, | |||
117 | 108 | ||
118 | state_string[count] = '\0'; | 109 | state_string[count] = '\0'; |
119 | 110 | ||
120 | result = acpi_bus_set_power(fan->device->handle, | 111 | result = acpi_bus_set_power(device->handle, |
121 | simple_strtoul(state_string, NULL, 0)); | 112 | simple_strtoul(state_string, NULL, 0)); |
122 | if (result) | 113 | if (result) |
123 | return result; | 114 | return result; |
@@ -158,7 +149,7 @@ static int acpi_fan_add_fs(struct acpi_device *device) | |||
158 | return -ENODEV; | 149 | return -ENODEV; |
159 | else { | 150 | else { |
160 | entry->proc_fops = &acpi_fan_state_ops; | 151 | entry->proc_fops = &acpi_fan_state_ops; |
161 | entry->data = acpi_driver_data(device); | 152 | entry->data = device; |
162 | entry->owner = THIS_MODULE; | 153 | entry->owner = THIS_MODULE; |
163 | } | 154 | } |
164 | 155 | ||
@@ -191,14 +182,8 @@ static int acpi_fan_add(struct acpi_device *device) | |||
191 | if (!device) | 182 | if (!device) |
192 | return -EINVAL; | 183 | return -EINVAL; |
193 | 184 | ||
194 | fan = kzalloc(sizeof(struct acpi_fan), GFP_KERNEL); | ||
195 | if (!fan) | ||
196 | return -ENOMEM; | ||
197 | |||
198 | fan->device = device; | ||
199 | strcpy(acpi_device_name(device), "Fan"); | 185 | strcpy(acpi_device_name(device), "Fan"); |
200 | strcpy(acpi_device_class(device), ACPI_FAN_CLASS); | 186 | strcpy(acpi_device_class(device), ACPI_FAN_CLASS); |
201 | acpi_driver_data(device) = fan; | ||
202 | 187 | ||
203 | result = acpi_bus_get_power(device->handle, &state); | 188 | result = acpi_bus_get_power(device->handle, &state); |
204 | if (result) { | 189 | if (result) { |
@@ -206,10 +191,6 @@ static int acpi_fan_add(struct acpi_device *device) | |||
206 | goto end; | 191 | goto end; |
207 | } | 192 | } |
208 | 193 | ||
209 | device->flags.force_power_state = 1; | ||
210 | acpi_bus_set_power(device->handle, state); | ||
211 | device->flags.force_power_state = 0; | ||
212 | |||
213 | result = acpi_fan_add_fs(device); | 194 | result = acpi_fan_add_fs(device); |
214 | if (result) | 195 | if (result) |
215 | goto end; | 196 | goto end; |
@@ -227,53 +208,14 @@ static int acpi_fan_add(struct acpi_device *device) | |||
227 | 208 | ||
228 | static int acpi_fan_remove(struct acpi_device *device, int type) | 209 | static int acpi_fan_remove(struct acpi_device *device, int type) |
229 | { | 210 | { |
230 | struct acpi_fan *fan = NULL; | ||
231 | |||
232 | |||
233 | if (!device || !acpi_driver_data(device)) | 211 | if (!device || !acpi_driver_data(device)) |
234 | return -EINVAL; | 212 | return -EINVAL; |
235 | 213 | ||
236 | fan = acpi_driver_data(device); | ||
237 | |||
238 | acpi_fan_remove_fs(device); | 214 | acpi_fan_remove_fs(device); |
239 | 215 | ||
240 | kfree(fan); | ||
241 | |||
242 | return 0; | 216 | return 0; |
243 | } | 217 | } |
244 | 218 | ||
245 | static int acpi_fan_suspend(struct acpi_device *device, pm_message_t state) | ||
246 | { | ||
247 | if (!device) | ||
248 | return -EINVAL; | ||
249 | |||
250 | acpi_bus_set_power(device->handle, ACPI_STATE_D0); | ||
251 | |||
252 | return AE_OK; | ||
253 | } | ||
254 | |||
255 | static int acpi_fan_resume(struct acpi_device *device) | ||
256 | { | ||
257 | int result = 0; | ||
258 | int power_state = 0; | ||
259 | |||
260 | if (!device) | ||
261 | return -EINVAL; | ||
262 | |||
263 | result = acpi_bus_get_power(device->handle, &power_state); | ||
264 | if (result) { | ||
265 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, | ||
266 | "Error reading fan power state\n")); | ||
267 | return result; | ||
268 | } | ||
269 | |||
270 | device->flags.force_power_state = 1; | ||
271 | acpi_bus_set_power(device->handle, power_state); | ||
272 | device->flags.force_power_state = 0; | ||
273 | |||
274 | return result; | ||
275 | } | ||
276 | |||
277 | static int __init acpi_fan_init(void) | 219 | static int __init acpi_fan_init(void) |
278 | { | 220 | { |
279 | int result = 0; | 221 | int result = 0; |