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