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