Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 20 | */ |
| 21 | |
| 22 | #include <linux/kernel.h> |
| 23 | #include <linux/module.h> |
| 24 | #include <linux/init.h> |
| 25 | #include <linux/types.h> |
Sudip Mukherjee | 88989fd | 2014-08-28 19:17:19 +0530 | [diff] [blame] | 26 | #include <linux/uaccess.h> |
Zhang Rui | 05a83d9 | 2008-01-17 15:51:24 +0800 | [diff] [blame] | 27 | #include <linux/thermal.h> |
Lv Zheng | 8b48463 | 2013-12-03 08:49:16 +0800 | [diff] [blame] | 28 | #include <linux/acpi.h> |
Aaron Lu | 19593a1 | 2013-11-19 16:59:20 +0800 | [diff] [blame] | 29 | #include <linux/platform_device.h> |
Aaron Lu | 9519a63 | 2014-04-01 15:50:27 +0800 | [diff] [blame] | 30 | #include <linux/sort.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | |
Len Brown | f52fd66 | 2007-02-12 22:42:12 -0500 | [diff] [blame] | 32 | MODULE_AUTHOR("Paul Diefenbaugh"); |
Len Brown | 7cda93e | 2007-02-12 23:50:02 -0500 | [diff] [blame] | 33 | MODULE_DESCRIPTION("ACPI Fan Driver"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | MODULE_LICENSE("GPL"); |
| 35 | |
Aaron Lu | 19593a1 | 2013-11-19 16:59:20 +0800 | [diff] [blame] | 36 | static int acpi_fan_probe(struct platform_device *pdev); |
| 37 | static int acpi_fan_remove(struct platform_device *pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | |
Thomas Renninger | 1ba90e3 | 2007-07-23 14:44:41 +0200 | [diff] [blame] | 39 | static const struct acpi_device_id fan_device_ids[] = { |
| 40 | {"PNP0C0B", 0}, |
Aaron Lu | d806c6e | 2014-04-01 15:54:05 +0800 | [diff] [blame] | 41 | {"INT3404", 0}, |
Thomas Renninger | 1ba90e3 | 2007-07-23 14:44:41 +0200 | [diff] [blame] | 42 | {"", 0}, |
| 43 | }; |
| 44 | MODULE_DEVICE_TABLE(acpi, fan_device_ids); |
| 45 | |
Rafael J. Wysocki | 9069240 | 2012-08-09 23:00:02 +0200 | [diff] [blame] | 46 | #ifdef CONFIG_PM_SLEEP |
Rafael J. Wysocki | 62fcbdd | 2012-06-27 23:26:07 +0200 | [diff] [blame] | 47 | static int acpi_fan_suspend(struct device *dev); |
| 48 | static int acpi_fan_resume(struct device *dev); |
Kaiyen Chang | 1d75158 | 2016-02-10 15:23:27 -0800 | [diff] [blame] | 49 | static const struct dev_pm_ops acpi_fan_pm = { |
Aaron Lu | b9b8515 | 2014-02-19 12:16:48 +0800 | [diff] [blame] | 50 | .resume = acpi_fan_resume, |
| 51 | .freeze = acpi_fan_suspend, |
| 52 | .thaw = acpi_fan_resume, |
| 53 | .restore = acpi_fan_resume, |
| 54 | }; |
| 55 | #define FAN_PM_OPS_PTR (&acpi_fan_pm) |
Shuah Khan | b108e0e | 2014-02-12 20:19:08 -0700 | [diff] [blame] | 56 | #else |
Aaron Lu | b9b8515 | 2014-02-19 12:16:48 +0800 | [diff] [blame] | 57 | #define FAN_PM_OPS_PTR NULL |
Rafael J. Wysocki | 9069240 | 2012-08-09 23:00:02 +0200 | [diff] [blame] | 58 | #endif |
Rafael J. Wysocki | 62fcbdd | 2012-06-27 23:26:07 +0200 | [diff] [blame] | 59 | |
Aaron Lu | 9519a63 | 2014-04-01 15:50:27 +0800 | [diff] [blame] | 60 | struct acpi_fan_fps { |
| 61 | u64 control; |
| 62 | u64 trip_point; |
| 63 | u64 speed; |
| 64 | u64 noise_level; |
| 65 | u64 power; |
| 66 | }; |
| 67 | |
| 68 | struct acpi_fan_fif { |
| 69 | u64 revision; |
| 70 | u64 fine_grain_ctrl; |
| 71 | u64 step_size; |
| 72 | u64 low_speed_notification; |
| 73 | }; |
| 74 | |
| 75 | struct acpi_fan { |
| 76 | bool acpi4; |
| 77 | struct acpi_fan_fif fif; |
| 78 | struct acpi_fan_fps *fps; |
| 79 | int fps_count; |
| 80 | struct thermal_cooling_device *cdev; |
| 81 | }; |
| 82 | |
Aaron Lu | 19593a1 | 2013-11-19 16:59:20 +0800 | [diff] [blame] | 83 | static struct platform_driver acpi_fan_driver = { |
| 84 | .probe = acpi_fan_probe, |
| 85 | .remove = acpi_fan_remove, |
| 86 | .driver = { |
| 87 | .name = "acpi-fan", |
| 88 | .acpi_match_table = fan_device_ids, |
| 89 | .pm = FAN_PM_OPS_PTR, |
| 90 | }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | }; |
| 92 | |
Zhang Rui | 05a83d9 | 2008-01-17 15:51:24 +0800 | [diff] [blame] | 93 | /* thermal cooling device callbacks */ |
Matthew Garrett | 6503e5d | 2008-11-27 17:48:13 +0000 | [diff] [blame] | 94 | static int fan_get_max_state(struct thermal_cooling_device *cdev, unsigned long |
| 95 | *state) |
Zhang Rui | 05a83d9 | 2008-01-17 15:51:24 +0800 | [diff] [blame] | 96 | { |
Aaron Lu | 9519a63 | 2014-04-01 15:50:27 +0800 | [diff] [blame] | 97 | struct acpi_device *device = cdev->devdata; |
| 98 | struct acpi_fan *fan = acpi_driver_data(device); |
| 99 | |
| 100 | if (fan->acpi4) |
| 101 | *state = fan->fps_count - 1; |
| 102 | else |
| 103 | *state = 1; |
Matthew Garrett | 6503e5d | 2008-11-27 17:48:13 +0000 | [diff] [blame] | 104 | return 0; |
Zhang Rui | 05a83d9 | 2008-01-17 15:51:24 +0800 | [diff] [blame] | 105 | } |
| 106 | |
Aaron Lu | 9519a63 | 2014-04-01 15:50:27 +0800 | [diff] [blame] | 107 | static int fan_get_state_acpi4(struct acpi_device *device, unsigned long *state) |
Zhang Rui | 05a83d9 | 2008-01-17 15:51:24 +0800 | [diff] [blame] | 108 | { |
Aaron Lu | 9519a63 | 2014-04-01 15:50:27 +0800 | [diff] [blame] | 109 | struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; |
| 110 | struct acpi_fan *fan = acpi_driver_data(device); |
| 111 | union acpi_object *obj; |
| 112 | acpi_status status; |
| 113 | int control, i; |
| 114 | |
| 115 | status = acpi_evaluate_object(device->handle, "_FST", NULL, &buffer); |
| 116 | if (ACPI_FAILURE(status)) { |
| 117 | dev_err(&device->dev, "Get fan state failed\n"); |
| 118 | return status; |
| 119 | } |
| 120 | |
| 121 | obj = buffer.pointer; |
| 122 | if (!obj || obj->type != ACPI_TYPE_PACKAGE || |
| 123 | obj->package.count != 3 || |
| 124 | obj->package.elements[1].type != ACPI_TYPE_INTEGER) { |
| 125 | dev_err(&device->dev, "Invalid _FST data\n"); |
| 126 | status = -EINVAL; |
| 127 | goto err; |
| 128 | } |
| 129 | |
| 130 | control = obj->package.elements[1].integer.value; |
| 131 | for (i = 0; i < fan->fps_count; i++) { |
| 132 | if (control == fan->fps[i].control) |
| 133 | break; |
| 134 | } |
| 135 | if (i == fan->fps_count) { |
| 136 | dev_dbg(&device->dev, "Invalid control value returned\n"); |
| 137 | status = -EINVAL; |
| 138 | goto err; |
| 139 | } |
| 140 | |
| 141 | *state = i; |
| 142 | |
| 143 | err: |
| 144 | kfree(obj); |
| 145 | return status; |
| 146 | } |
| 147 | |
| 148 | static int fan_get_state(struct acpi_device *device, unsigned long *state) |
| 149 | { |
Zhang Rui | 05a83d9 | 2008-01-17 15:51:24 +0800 | [diff] [blame] | 150 | int result; |
Naresh Bhat | 85eb982 | 2013-07-01 19:51:00 +0530 | [diff] [blame] | 151 | int acpi_state = ACPI_STATE_D0; |
Zhang Rui | 05a83d9 | 2008-01-17 15:51:24 +0800 | [diff] [blame] | 152 | |
Aaron Lu | 2bb3a2b | 2013-11-19 15:43:52 +0800 | [diff] [blame] | 153 | result = acpi_device_update_power(device, &acpi_state); |
Zhang Rui | 05a83d9 | 2008-01-17 15:51:24 +0800 | [diff] [blame] | 154 | if (result) |
| 155 | return result; |
| 156 | |
Rafael J. Wysocki | 20dacb7 | 2015-05-16 01:55:35 +0200 | [diff] [blame] | 157 | *state = acpi_state == ACPI_STATE_D3_COLD |
| 158 | || acpi_state == ACPI_STATE_D3_HOT ? |
| 159 | 0 : (acpi_state == ACPI_STATE_D0 ? 1 : -1); |
Matthew Garrett | 6503e5d | 2008-11-27 17:48:13 +0000 | [diff] [blame] | 160 | return 0; |
Zhang Rui | 05a83d9 | 2008-01-17 15:51:24 +0800 | [diff] [blame] | 161 | } |
| 162 | |
Aaron Lu | 9519a63 | 2014-04-01 15:50:27 +0800 | [diff] [blame] | 163 | static int fan_get_cur_state(struct thermal_cooling_device *cdev, unsigned long |
| 164 | *state) |
| 165 | { |
| 166 | struct acpi_device *device = cdev->devdata; |
| 167 | struct acpi_fan *fan = acpi_driver_data(device); |
| 168 | |
| 169 | if (fan->acpi4) |
| 170 | return fan_get_state_acpi4(device, state); |
| 171 | else |
| 172 | return fan_get_state(device, state); |
| 173 | } |
| 174 | |
| 175 | static int fan_set_state(struct acpi_device *device, unsigned long state) |
| 176 | { |
| 177 | if (state != 0 && state != 1) |
| 178 | return -EINVAL; |
| 179 | |
| 180 | return acpi_device_set_power(device, |
| 181 | state ? ACPI_STATE_D0 : ACPI_STATE_D3_COLD); |
| 182 | } |
| 183 | |
| 184 | static int fan_set_state_acpi4(struct acpi_device *device, unsigned long state) |
| 185 | { |
| 186 | struct acpi_fan *fan = acpi_driver_data(device); |
| 187 | acpi_status status; |
| 188 | |
| 189 | if (state >= fan->fps_count) |
| 190 | return -EINVAL; |
| 191 | |
| 192 | status = acpi_execute_simple_method(device->handle, "_FSL", |
| 193 | fan->fps[state].control); |
| 194 | if (ACPI_FAILURE(status)) { |
| 195 | dev_dbg(&device->dev, "Failed to set state by _FSL\n"); |
| 196 | return status; |
| 197 | } |
| 198 | |
| 199 | return 0; |
| 200 | } |
| 201 | |
Zhang Rui | 05a83d9 | 2008-01-17 15:51:24 +0800 | [diff] [blame] | 202 | static int |
Matthew Garrett | 6503e5d | 2008-11-27 17:48:13 +0000 | [diff] [blame] | 203 | fan_set_cur_state(struct thermal_cooling_device *cdev, unsigned long state) |
Zhang Rui | 05a83d9 | 2008-01-17 15:51:24 +0800 | [diff] [blame] | 204 | { |
| 205 | struct acpi_device *device = cdev->devdata; |
Aaron Lu | 9519a63 | 2014-04-01 15:50:27 +0800 | [diff] [blame] | 206 | struct acpi_fan *fan = acpi_driver_data(device); |
Zhang Rui | 05a83d9 | 2008-01-17 15:51:24 +0800 | [diff] [blame] | 207 | |
Aaron Lu | 9519a63 | 2014-04-01 15:50:27 +0800 | [diff] [blame] | 208 | if (fan->acpi4) |
| 209 | return fan_set_state_acpi4(device, state); |
| 210 | else |
| 211 | return fan_set_state(device, state); |
| 212 | } |
Zhang Rui | 05a83d9 | 2008-01-17 15:51:24 +0800 | [diff] [blame] | 213 | |
Vasiliy Kulikov | 9c8b04b | 2011-06-25 21:07:52 +0400 | [diff] [blame] | 214 | static const struct thermal_cooling_device_ops fan_cooling_ops = { |
Zhang Rui | 05a83d9 | 2008-01-17 15:51:24 +0800 | [diff] [blame] | 215 | .get_max_state = fan_get_max_state, |
| 216 | .get_cur_state = fan_get_cur_state, |
| 217 | .set_cur_state = fan_set_cur_state, |
| 218 | }; |
| 219 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | /* -------------------------------------------------------------------------- |
Sudip Mukherjee | 88989fd | 2014-08-28 19:17:19 +0530 | [diff] [blame] | 221 | * Driver Interface |
| 222 | * -------------------------------------------------------------------------- |
| 223 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 224 | |
Aaron Lu | 9519a63 | 2014-04-01 15:50:27 +0800 | [diff] [blame] | 225 | static bool acpi_fan_is_acpi4(struct acpi_device *device) |
| 226 | { |
| 227 | return acpi_has_method(device->handle, "_FIF") && |
| 228 | acpi_has_method(device->handle, "_FPS") && |
| 229 | acpi_has_method(device->handle, "_FSL") && |
| 230 | acpi_has_method(device->handle, "_FST"); |
| 231 | } |
| 232 | |
| 233 | static int acpi_fan_get_fif(struct acpi_device *device) |
| 234 | { |
| 235 | struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; |
| 236 | struct acpi_fan *fan = acpi_driver_data(device); |
| 237 | struct acpi_buffer format = { sizeof("NNNN"), "NNNN" }; |
| 238 | struct acpi_buffer fif = { sizeof(fan->fif), &fan->fif }; |
| 239 | union acpi_object *obj; |
| 240 | acpi_status status; |
| 241 | |
| 242 | status = acpi_evaluate_object(device->handle, "_FIF", NULL, &buffer); |
| 243 | if (ACPI_FAILURE(status)) |
| 244 | return status; |
| 245 | |
| 246 | obj = buffer.pointer; |
| 247 | if (!obj || obj->type != ACPI_TYPE_PACKAGE) { |
| 248 | dev_err(&device->dev, "Invalid _FIF data\n"); |
| 249 | status = -EINVAL; |
| 250 | goto err; |
| 251 | } |
| 252 | |
| 253 | status = acpi_extract_package(obj, &format, &fif); |
| 254 | if (ACPI_FAILURE(status)) { |
| 255 | dev_err(&device->dev, "Invalid _FIF element\n"); |
| 256 | status = -EINVAL; |
| 257 | } |
| 258 | |
| 259 | err: |
| 260 | kfree(obj); |
| 261 | return status; |
| 262 | } |
| 263 | |
| 264 | static int acpi_fan_speed_cmp(const void *a, const void *b) |
| 265 | { |
| 266 | const struct acpi_fan_fps *fps1 = a; |
| 267 | const struct acpi_fan_fps *fps2 = b; |
| 268 | return fps1->speed - fps2->speed; |
| 269 | } |
| 270 | |
| 271 | static int acpi_fan_get_fps(struct acpi_device *device) |
| 272 | { |
| 273 | struct acpi_fan *fan = acpi_driver_data(device); |
| 274 | struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; |
| 275 | union acpi_object *obj; |
| 276 | acpi_status status; |
| 277 | int i; |
| 278 | |
| 279 | status = acpi_evaluate_object(device->handle, "_FPS", NULL, &buffer); |
| 280 | if (ACPI_FAILURE(status)) |
| 281 | return status; |
| 282 | |
| 283 | obj = buffer.pointer; |
| 284 | if (!obj || obj->type != ACPI_TYPE_PACKAGE || obj->package.count < 2) { |
| 285 | dev_err(&device->dev, "Invalid _FPS data\n"); |
| 286 | status = -EINVAL; |
| 287 | goto err; |
| 288 | } |
| 289 | |
| 290 | fan->fps_count = obj->package.count - 1; /* minus revision field */ |
| 291 | fan->fps = devm_kzalloc(&device->dev, |
| 292 | fan->fps_count * sizeof(struct acpi_fan_fps), |
| 293 | GFP_KERNEL); |
| 294 | if (!fan->fps) { |
| 295 | dev_err(&device->dev, "Not enough memory\n"); |
| 296 | status = -ENOMEM; |
| 297 | goto err; |
| 298 | } |
| 299 | for (i = 0; i < fan->fps_count; i++) { |
| 300 | struct acpi_buffer format = { sizeof("NNNNN"), "NNNNN" }; |
| 301 | struct acpi_buffer fps = { sizeof(fan->fps[i]), &fan->fps[i] }; |
| 302 | status = acpi_extract_package(&obj->package.elements[i + 1], |
| 303 | &format, &fps); |
| 304 | if (ACPI_FAILURE(status)) { |
| 305 | dev_err(&device->dev, "Invalid _FPS element\n"); |
| 306 | break; |
| 307 | } |
| 308 | } |
| 309 | |
| 310 | /* sort the state array according to fan speed in increase order */ |
| 311 | sort(fan->fps, fan->fps_count, sizeof(*fan->fps), |
| 312 | acpi_fan_speed_cmp, NULL); |
| 313 | |
| 314 | err: |
| 315 | kfree(obj); |
| 316 | return status; |
| 317 | } |
| 318 | |
Aaron Lu | 19593a1 | 2013-11-19 16:59:20 +0800 | [diff] [blame] | 319 | static int acpi_fan_probe(struct platform_device *pdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 320 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 321 | int result = 0; |
Zhang Rui | 05a83d9 | 2008-01-17 15:51:24 +0800 | [diff] [blame] | 322 | struct thermal_cooling_device *cdev; |
Aaron Lu | 9519a63 | 2014-04-01 15:50:27 +0800 | [diff] [blame] | 323 | struct acpi_fan *fan; |
Aaron Lu | 19593a1 | 2013-11-19 16:59:20 +0800 | [diff] [blame] | 324 | struct acpi_device *device = ACPI_COMPANION(&pdev->dev); |
Srinivas Pandruvada | bbb16fe | 2014-12-09 16:15:40 -0800 | [diff] [blame] | 325 | char *name; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 326 | |
Aaron Lu | 9519a63 | 2014-04-01 15:50:27 +0800 | [diff] [blame] | 327 | fan = devm_kzalloc(&pdev->dev, sizeof(*fan), GFP_KERNEL); |
| 328 | if (!fan) { |
| 329 | dev_err(&device->dev, "No memory for fan\n"); |
| 330 | return -ENOMEM; |
| 331 | } |
| 332 | device->driver_data = fan; |
| 333 | platform_set_drvdata(pdev, fan); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 334 | |
Aaron Lu | 9519a63 | 2014-04-01 15:50:27 +0800 | [diff] [blame] | 335 | if (acpi_fan_is_acpi4(device)) { |
| 336 | if (acpi_fan_get_fif(device) || acpi_fan_get_fps(device)) |
| 337 | goto end; |
| 338 | fan->acpi4 = true; |
| 339 | } else { |
| 340 | result = acpi_device_update_power(device, NULL); |
| 341 | if (result) { |
Andy Lutomirski | f972799 | 2016-01-13 14:25:19 -0800 | [diff] [blame] | 342 | dev_err(&device->dev, "Failed to set initial power state\n"); |
Aaron Lu | 9519a63 | 2014-04-01 15:50:27 +0800 | [diff] [blame] | 343 | goto end; |
| 344 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 345 | } |
| 346 | |
Srinivas Pandruvada | bbb16fe | 2014-12-09 16:15:40 -0800 | [diff] [blame] | 347 | if (!strncmp(pdev->name, "PNP0C0B", strlen("PNP0C0B"))) |
| 348 | name = "Fan"; |
| 349 | else |
| 350 | name = acpi_device_bid(device); |
| 351 | |
| 352 | cdev = thermal_cooling_device_register(name, device, |
Zhang Rui | 05a83d9 | 2008-01-17 15:51:24 +0800 | [diff] [blame] | 353 | &fan_cooling_ops); |
Thomas Sujith | 19b3678 | 2008-02-15 01:01:52 -0500 | [diff] [blame] | 354 | if (IS_ERR(cdev)) { |
| 355 | result = PTR_ERR(cdev); |
| 356 | goto end; |
| 357 | } |
Zhang Rui | 05a83d9 | 2008-01-17 15:51:24 +0800 | [diff] [blame] | 358 | |
Aaron Lu | 19593a1 | 2013-11-19 16:59:20 +0800 | [diff] [blame] | 359 | dev_dbg(&pdev->dev, "registered as cooling_device%d\n", cdev->id); |
Thomas Sujith | 19b3678 | 2008-02-15 01:01:52 -0500 | [diff] [blame] | 360 | |
Aaron Lu | 9519a63 | 2014-04-01 15:50:27 +0800 | [diff] [blame] | 361 | fan->cdev = cdev; |
Aaron Lu | 19593a1 | 2013-11-19 16:59:20 +0800 | [diff] [blame] | 362 | result = sysfs_create_link(&pdev->dev.kobj, |
Julia Lawall | 9030062 | 2008-04-11 10:09:24 +0800 | [diff] [blame] | 363 | &cdev->device.kobj, |
| 364 | "thermal_cooling"); |
| 365 | if (result) |
Linus Torvalds | 8264fce | 2014-10-24 11:21:43 -0700 | [diff] [blame] | 366 | dev_err(&pdev->dev, "Failed to create sysfs link 'thermal_cooling'\n"); |
Julia Lawall | 9030062 | 2008-04-11 10:09:24 +0800 | [diff] [blame] | 367 | |
| 368 | result = sysfs_create_link(&cdev->device.kobj, |
Aaron Lu | 19593a1 | 2013-11-19 16:59:20 +0800 | [diff] [blame] | 369 | &pdev->dev.kobj, |
Julia Lawall | 9030062 | 2008-04-11 10:09:24 +0800 | [diff] [blame] | 370 | "device"); |
| 371 | if (result) |
Linus Torvalds | 8264fce | 2014-10-24 11:21:43 -0700 | [diff] [blame] | 372 | dev_err(&pdev->dev, "Failed to create sysfs link 'device'\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 373 | |
Felipe Contreras | 568b6ad | 2013-08-30 16:16:05 -0500 | [diff] [blame] | 374 | end: |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 375 | return result; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 376 | } |
| 377 | |
Aaron Lu | 19593a1 | 2013-11-19 16:59:20 +0800 | [diff] [blame] | 378 | static int acpi_fan_remove(struct platform_device *pdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 379 | { |
Aaron Lu | 9519a63 | 2014-04-01 15:50:27 +0800 | [diff] [blame] | 380 | struct acpi_fan *fan = platform_get_drvdata(pdev); |
Zhang Rui | 05a83d9 | 2008-01-17 15:51:24 +0800 | [diff] [blame] | 381 | |
Aaron Lu | 19593a1 | 2013-11-19 16:59:20 +0800 | [diff] [blame] | 382 | sysfs_remove_link(&pdev->dev.kobj, "thermal_cooling"); |
Aaron Lu | 9519a63 | 2014-04-01 15:50:27 +0800 | [diff] [blame] | 383 | sysfs_remove_link(&fan->cdev->device.kobj, "device"); |
| 384 | thermal_cooling_device_unregister(fan->cdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 385 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 386 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 387 | } |
| 388 | |
Rafael J. Wysocki | 9069240 | 2012-08-09 23:00:02 +0200 | [diff] [blame] | 389 | #ifdef CONFIG_PM_SLEEP |
Rafael J. Wysocki | 62fcbdd | 2012-06-27 23:26:07 +0200 | [diff] [blame] | 390 | static int acpi_fan_suspend(struct device *dev) |
Len Brown | ec68373 | 2008-01-23 22:41:20 -0500 | [diff] [blame] | 391 | { |
Aaron Lu | 9519a63 | 2014-04-01 15:50:27 +0800 | [diff] [blame] | 392 | struct acpi_fan *fan = dev_get_drvdata(dev); |
| 393 | if (fan->acpi4) |
| 394 | return 0; |
Len Brown | ec68373 | 2008-01-23 22:41:20 -0500 | [diff] [blame] | 395 | |
Aaron Lu | 19593a1 | 2013-11-19 16:59:20 +0800 | [diff] [blame] | 396 | acpi_device_set_power(ACPI_COMPANION(dev), ACPI_STATE_D0); |
Len Brown | ec68373 | 2008-01-23 22:41:20 -0500 | [diff] [blame] | 397 | |
| 398 | return AE_OK; |
| 399 | } |
| 400 | |
Rafael J. Wysocki | 62fcbdd | 2012-06-27 23:26:07 +0200 | [diff] [blame] | 401 | static int acpi_fan_resume(struct device *dev) |
Len Brown | ec68373 | 2008-01-23 22:41:20 -0500 | [diff] [blame] | 402 | { |
Rafael J. Wysocki | 488a76c | 2010-11-25 00:11:24 +0100 | [diff] [blame] | 403 | int result; |
Aaron Lu | 9519a63 | 2014-04-01 15:50:27 +0800 | [diff] [blame] | 404 | struct acpi_fan *fan = dev_get_drvdata(dev); |
Len Brown | ec68373 | 2008-01-23 22:41:20 -0500 | [diff] [blame] | 405 | |
Aaron Lu | 9519a63 | 2014-04-01 15:50:27 +0800 | [diff] [blame] | 406 | if (fan->acpi4) |
| 407 | return 0; |
Len Brown | ec68373 | 2008-01-23 22:41:20 -0500 | [diff] [blame] | 408 | |
Aaron Lu | 19593a1 | 2013-11-19 16:59:20 +0800 | [diff] [blame] | 409 | result = acpi_device_update_power(ACPI_COMPANION(dev), NULL); |
Rafael J. Wysocki | 488a76c | 2010-11-25 00:11:24 +0100 | [diff] [blame] | 410 | if (result) |
Sudip Mukherjee | 88989fd | 2014-08-28 19:17:19 +0530 | [diff] [blame] | 411 | dev_err(dev, "Error updating fan power state\n"); |
Len Brown | ec68373 | 2008-01-23 22:41:20 -0500 | [diff] [blame] | 412 | |
| 413 | return result; |
| 414 | } |
Rafael J. Wysocki | 9069240 | 2012-08-09 23:00:02 +0200 | [diff] [blame] | 415 | #endif |
Len Brown | ec68373 | 2008-01-23 22:41:20 -0500 | [diff] [blame] | 416 | |
Aaron Lu | 19593a1 | 2013-11-19 16:59:20 +0800 | [diff] [blame] | 417 | module_platform_driver(acpi_fan_driver); |