^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * acpi_fan.c - ACPI Fan Driver ($Revision: 29 $)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (C) 2001, 2002 Andy Grover <andrew.grover@intel.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/thermal.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/acpi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/sort.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include "fan.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) MODULE_AUTHOR("Paul Diefenbaugh");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) MODULE_DESCRIPTION("ACPI Fan Driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) static int acpi_fan_probe(struct platform_device *pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) static int acpi_fan_remove(struct platform_device *pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) static const struct acpi_device_id fan_device_ids[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) ACPI_FAN_DEVICE_IDS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) {"", 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) MODULE_DEVICE_TABLE(acpi, fan_device_ids);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) #ifdef CONFIG_PM_SLEEP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) static int acpi_fan_suspend(struct device *dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) static int acpi_fan_resume(struct device *dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) static const struct dev_pm_ops acpi_fan_pm = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) .resume = acpi_fan_resume,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) .freeze = acpi_fan_suspend,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) .thaw = acpi_fan_resume,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) .restore = acpi_fan_resume,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) #define FAN_PM_OPS_PTR (&acpi_fan_pm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) #define FAN_PM_OPS_PTR NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) #define ACPI_FPS_NAME_LEN 20
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) struct acpi_fan_fps {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) u64 control;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) u64 trip_point;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) u64 speed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) u64 noise_level;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) u64 power;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) char name[ACPI_FPS_NAME_LEN];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) struct device_attribute dev_attr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) struct acpi_fan_fif {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) u64 revision;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) u64 fine_grain_ctrl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) u64 step_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) u64 low_speed_notification;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) struct acpi_fan {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) bool acpi4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) struct acpi_fan_fif fif;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) struct acpi_fan_fps *fps;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) int fps_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) struct thermal_cooling_device *cdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) static struct platform_driver acpi_fan_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) .probe = acpi_fan_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) .remove = acpi_fan_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) .driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) .name = "acpi-fan",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) .acpi_match_table = fan_device_ids,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) .pm = FAN_PM_OPS_PTR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) /* thermal cooling device callbacks */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) static int fan_get_max_state(struct thermal_cooling_device *cdev, unsigned long
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) *state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) struct acpi_device *device = cdev->devdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) struct acpi_fan *fan = acpi_driver_data(device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) if (fan->acpi4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) *state = fan->fps_count - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) *state = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) static int fan_get_state_acpi4(struct acpi_device *device, unsigned long *state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) struct acpi_fan *fan = acpi_driver_data(device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) union acpi_object *obj;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) acpi_status status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) int control, i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) status = acpi_evaluate_object(device->handle, "_FST", NULL, &buffer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) if (ACPI_FAILURE(status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) dev_err(&device->dev, "Get fan state failed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) obj = buffer.pointer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) if (!obj || obj->type != ACPI_TYPE_PACKAGE ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) obj->package.count != 3 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) obj->package.elements[1].type != ACPI_TYPE_INTEGER) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) dev_err(&device->dev, "Invalid _FST data\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) status = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) control = obj->package.elements[1].integer.value;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) for (i = 0; i < fan->fps_count; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) * When Fine Grain Control is set, return the state
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) * corresponding to maximum fan->fps[i].control
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) * value compared to the current speed. Here the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) * fan->fps[] is sorted array with increasing speed.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) if (fan->fif.fine_grain_ctrl && control < fan->fps[i].control) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) i = (i > 0) ? i - 1 : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) } else if (control == fan->fps[i].control) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) if (i == fan->fps_count) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) dev_dbg(&device->dev, "Invalid control value returned\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) status = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) *state = i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) kfree(obj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) static int fan_get_state(struct acpi_device *device, unsigned long *state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) int result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) int acpi_state = ACPI_STATE_D0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) result = acpi_device_update_power(device, &acpi_state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) if (result)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) *state = acpi_state == ACPI_STATE_D3_COLD
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) || acpi_state == ACPI_STATE_D3_HOT ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 0 : (acpi_state == ACPI_STATE_D0 ? 1 : -1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) static int fan_get_cur_state(struct thermal_cooling_device *cdev, unsigned long
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) *state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) struct acpi_device *device = cdev->devdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) struct acpi_fan *fan = acpi_driver_data(device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) if (fan->acpi4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) return fan_get_state_acpi4(device, state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) return fan_get_state(device, state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) static int fan_set_state(struct acpi_device *device, unsigned long state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) if (state != 0 && state != 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) return acpi_device_set_power(device,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) state ? ACPI_STATE_D0 : ACPI_STATE_D3_COLD);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) static int fan_set_state_acpi4(struct acpi_device *device, unsigned long state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) struct acpi_fan *fan = acpi_driver_data(device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) acpi_status status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) if (state >= fan->fps_count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) status = acpi_execute_simple_method(device->handle, "_FSL",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) fan->fps[state].control);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) if (ACPI_FAILURE(status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) dev_dbg(&device->dev, "Failed to set state by _FSL\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) fan_set_cur_state(struct thermal_cooling_device *cdev, unsigned long state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) struct acpi_device *device = cdev->devdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) struct acpi_fan *fan = acpi_driver_data(device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) if (fan->acpi4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) return fan_set_state_acpi4(device, state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) return fan_set_state(device, state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) static const struct thermal_cooling_device_ops fan_cooling_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) .get_max_state = fan_get_max_state,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) .get_cur_state = fan_get_cur_state,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) .set_cur_state = fan_set_cur_state,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) /* --------------------------------------------------------------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) * Driver Interface
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) * --------------------------------------------------------------------------
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) static bool acpi_fan_is_acpi4(struct acpi_device *device)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) return acpi_has_method(device->handle, "_FIF") &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) acpi_has_method(device->handle, "_FPS") &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) acpi_has_method(device->handle, "_FSL") &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) acpi_has_method(device->handle, "_FST");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) static int acpi_fan_get_fif(struct acpi_device *device)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) struct acpi_fan *fan = acpi_driver_data(device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) struct acpi_buffer format = { sizeof("NNNN"), "NNNN" };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) struct acpi_buffer fif = { sizeof(fan->fif), &fan->fif };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) union acpi_object *obj;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) acpi_status status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) status = acpi_evaluate_object(device->handle, "_FIF", NULL, &buffer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) if (ACPI_FAILURE(status))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) obj = buffer.pointer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) if (!obj || obj->type != ACPI_TYPE_PACKAGE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) dev_err(&device->dev, "Invalid _FIF data\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) status = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) status = acpi_extract_package(obj, &format, &fif);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) if (ACPI_FAILURE(status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) dev_err(&device->dev, "Invalid _FIF element\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) status = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) kfree(obj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) static int acpi_fan_speed_cmp(const void *a, const void *b)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) const struct acpi_fan_fps *fps1 = a;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) const struct acpi_fan_fps *fps2 = b;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) return fps1->speed - fps2->speed;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) static ssize_t show_state(struct device *dev, struct device_attribute *attr, char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) struct acpi_fan_fps *fps = container_of(attr, struct acpi_fan_fps, dev_attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) int count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) if (fps->control == 0xFFFFFFFF || fps->control > 100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) count = scnprintf(buf, PAGE_SIZE, "not-defined:");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) count = scnprintf(buf, PAGE_SIZE, "%lld:", fps->control);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) if (fps->trip_point == 0xFFFFFFFF || fps->trip_point > 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) count += scnprintf(&buf[count], PAGE_SIZE - count, "not-defined:");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) count += scnprintf(&buf[count], PAGE_SIZE - count, "%lld:", fps->trip_point);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) if (fps->speed == 0xFFFFFFFF)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) count += scnprintf(&buf[count], PAGE_SIZE - count, "not-defined:");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) count += scnprintf(&buf[count], PAGE_SIZE - count, "%lld:", fps->speed);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) if (fps->noise_level == 0xFFFFFFFF)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) count += scnprintf(&buf[count], PAGE_SIZE - count, "not-defined:");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) count += scnprintf(&buf[count], PAGE_SIZE - count, "%lld:", fps->noise_level * 100);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) if (fps->power == 0xFFFFFFFF)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) count += scnprintf(&buf[count], PAGE_SIZE - count, "not-defined\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) count += scnprintf(&buf[count], PAGE_SIZE - count, "%lld\n", fps->power);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) static int acpi_fan_get_fps(struct acpi_device *device)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) struct acpi_fan *fan = acpi_driver_data(device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) union acpi_object *obj;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) acpi_status status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) status = acpi_evaluate_object(device->handle, "_FPS", NULL, &buffer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) if (ACPI_FAILURE(status))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) obj = buffer.pointer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) if (!obj || obj->type != ACPI_TYPE_PACKAGE || obj->package.count < 2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) dev_err(&device->dev, "Invalid _FPS data\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) status = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) fan->fps_count = obj->package.count - 1; /* minus revision field */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) fan->fps = devm_kcalloc(&device->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) fan->fps_count, sizeof(struct acpi_fan_fps),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) if (!fan->fps) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) dev_err(&device->dev, "Not enough memory\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) status = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) for (i = 0; i < fan->fps_count; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) struct acpi_buffer format = { sizeof("NNNNN"), "NNNNN" };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) struct acpi_buffer fps = { offsetof(struct acpi_fan_fps, name),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) &fan->fps[i] };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) status = acpi_extract_package(&obj->package.elements[i + 1],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) &format, &fps);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) if (ACPI_FAILURE(status)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) dev_err(&device->dev, "Invalid _FPS element\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) /* sort the state array according to fan speed in increase order */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) sort(fan->fps, fan->fps_count, sizeof(*fan->fps),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) acpi_fan_speed_cmp, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) for (i = 0; i < fan->fps_count; ++i) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) struct acpi_fan_fps *fps = &fan->fps[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) snprintf(fps->name, ACPI_FPS_NAME_LEN, "state%d", i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) sysfs_attr_init(&fps->dev_attr.attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) fps->dev_attr.show = show_state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) fps->dev_attr.store = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) fps->dev_attr.attr.name = fps->name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) fps->dev_attr.attr.mode = 0444;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) status = sysfs_create_file(&device->dev.kobj, &fps->dev_attr.attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) if (status) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) int j;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) for (j = 0; j < i; ++j)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) sysfs_remove_file(&device->dev.kobj, &fan->fps[j].dev_attr.attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) kfree(obj);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) return status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) static int acpi_fan_probe(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) int result = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) struct thermal_cooling_device *cdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) struct acpi_fan *fan;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) struct acpi_device *device = ACPI_COMPANION(&pdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) char *name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) fan = devm_kzalloc(&pdev->dev, sizeof(*fan), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) if (!fan) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) dev_err(&device->dev, "No memory for fan\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) device->driver_data = fan;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) platform_set_drvdata(pdev, fan);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) if (acpi_fan_is_acpi4(device)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) result = acpi_fan_get_fif(device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) if (result)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) result = acpi_fan_get_fps(device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) if (result)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) fan->acpi4 = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) result = acpi_device_update_power(device, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) if (result) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) dev_err(&device->dev, "Failed to set initial power state\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) goto err_end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) if (!strncmp(pdev->name, "PNP0C0B", strlen("PNP0C0B")))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) name = "Fan";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) name = acpi_device_bid(device);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) cdev = thermal_cooling_device_register(name, device,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) &fan_cooling_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) if (IS_ERR(cdev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) result = PTR_ERR(cdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) goto err_end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) dev_dbg(&pdev->dev, "registered as cooling_device%d\n", cdev->id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) fan->cdev = cdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) result = sysfs_create_link(&pdev->dev.kobj,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) &cdev->device.kobj,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) "thermal_cooling");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) if (result)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) dev_err(&pdev->dev, "Failed to create sysfs link 'thermal_cooling'\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) result = sysfs_create_link(&cdev->device.kobj,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) &pdev->dev.kobj,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) "device");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) if (result) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) dev_err(&pdev->dev, "Failed to create sysfs link 'device'\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) goto err_end;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) err_end:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) if (fan->acpi4) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) for (i = 0; i < fan->fps_count; ++i)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) sysfs_remove_file(&device->dev.kobj, &fan->fps[i].dev_attr.attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) static int acpi_fan_remove(struct platform_device *pdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) struct acpi_fan *fan = platform_get_drvdata(pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) if (fan->acpi4) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) struct acpi_device *device = ACPI_COMPANION(&pdev->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) for (i = 0; i < fan->fps_count; ++i)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) sysfs_remove_file(&device->dev.kobj, &fan->fps[i].dev_attr.attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) sysfs_remove_link(&pdev->dev.kobj, "thermal_cooling");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) sysfs_remove_link(&fan->cdev->device.kobj, "device");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) thermal_cooling_device_unregister(fan->cdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) #ifdef CONFIG_PM_SLEEP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) static int acpi_fan_suspend(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) struct acpi_fan *fan = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) if (fan->acpi4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) acpi_device_set_power(ACPI_COMPANION(dev), ACPI_STATE_D0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) return AE_OK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) static int acpi_fan_resume(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) int result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) struct acpi_fan *fan = dev_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) if (fan->acpi4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) result = acpi_device_update_power(ACPI_COMPANION(dev), NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) if (result)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) dev_err(dev, "Error updating fan power state\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) module_platform_driver(acpi_fan_driver);