^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) * acerhdf - A driver which monitors the temperature
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * of the aspire one netbook, turns on/off the fan
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * as soon as the upper/lower threshold is reached.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * (C) 2009 - Peter Kaestle peter (a) piie.net
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * https://piie.net
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * 2009 Borislav Petkov bp (a) alien8.de
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) * Inspired by and many thanks to:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) * o acerfand - Rachel Greenham
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) * o acer_ec.pl - Michael Kurz michi.kurz (at) googlemail.com
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) * - Petr Tomasek tomasek (#) etf,cuni,cz
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) * - Carlos Corbacho cathectic (at) gmail.com
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) * o lkml - Matthew Garrett
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) * - Borislav Petkov
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) * - Andreas Mohr
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #define pr_fmt(fmt) "acerhdf: " fmt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #include <linux/dmi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #include <linux/acpi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #include <linux/thermal.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #include <linux/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) * The driver is started with "kernel mode off" by default. That means, the BIOS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) * is still in control of the fan. In this mode the driver allows to read the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) * temperature of the cpu and a userspace tool may take over control of the fan.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) * If the driver is switched to "kernel mode" (e.g. via module parameter) the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) * driver is in full control of the fan. If you want the module to be started in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) * kernel mode by default, define the following:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) #undef START_IN_KERNEL_MODE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) #define DRV_VER "0.7.0"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) * According to the Atom N270 datasheet,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) * (http://download.intel.com/design/processor/datashts/320032.pdf) the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) * CPU's optimal operating limits denoted in junction temperature as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) * measured by the on-die thermal monitor are within 0 <= Tj <= 90. So,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) * assume 89°C is critical temperature.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) #define ACERHDF_TEMP_CRIT 89000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) #define ACERHDF_FAN_OFF 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) #define ACERHDF_FAN_AUTO 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) * No matter what value the user puts into the fanon variable, turn on the fan
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) * at 80 degree Celsius to prevent hardware damage
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) #define ACERHDF_MAX_FANON 80000
^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) * Maximum interval between two temperature checks is 15 seconds, as the die
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) * can get hot really fast under heavy load (plus we shouldn't forget about
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) * possible impact of _external_ aggressive sources such as heaters, sun etc.)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) #define ACERHDF_MAX_INTERVAL 15
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) #ifdef START_IN_KERNEL_MODE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) static int kernelmode = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) static int kernelmode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) static unsigned int interval = 10;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) static unsigned int fanon = 60000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) static unsigned int fanoff = 53000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) static unsigned int verbose;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) static unsigned int list_supported;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) static unsigned int fanstate = ACERHDF_FAN_AUTO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) static char force_bios[16];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) static char force_product[16];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) static unsigned int prev_interval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) static struct thermal_zone_device *thz_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) static struct thermal_cooling_device *cl_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) static struct platform_device *acerhdf_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) module_param(kernelmode, uint, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) MODULE_PARM_DESC(kernelmode, "Kernel mode fan control on / off");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) module_param(interval, uint, 0600);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) MODULE_PARM_DESC(interval, "Polling interval of temperature check");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) module_param(fanon, uint, 0600);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) MODULE_PARM_DESC(fanon, "Turn the fan on above this temperature");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) module_param(fanoff, uint, 0600);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) MODULE_PARM_DESC(fanoff, "Turn the fan off below this temperature");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) module_param(verbose, uint, 0600);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) MODULE_PARM_DESC(verbose, "Enable verbose dmesg output");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) module_param(list_supported, uint, 0600);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) MODULE_PARM_DESC(list_supported, "List supported models and BIOS versions");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) module_param_string(force_bios, force_bios, 16, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) MODULE_PARM_DESC(force_bios, "Pretend system has this known supported BIOS version");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) module_param_string(force_product, force_product, 16, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) MODULE_PARM_DESC(force_product, "Pretend system is this known supported model");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) * cmd_off: to switch the fan completely off and check if the fan is off
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) * cmd_auto: to set the BIOS in control of the fan. The BIOS regulates then
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) * the fan speed depending on the temperature
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) struct fancmd {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) u8 cmd_off;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) u8 cmd_auto;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) struct manualcmd {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) u8 mreg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) u8 moff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) /* default register and command to disable fan in manual mode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) static const struct manualcmd mcmd = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) .mreg = 0x94,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) .moff = 0xff,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) /* BIOS settings - only used during probe */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) struct bios_settings {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) const char *vendor;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) const char *product;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) const char *version;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) u8 fanreg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) u8 tempreg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) struct fancmd cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) int mcmd_enable;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) /* This could be a daughter struct in the above, but not worth the redirect */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) struct ctrl_settings {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) u8 fanreg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) u8 tempreg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) struct fancmd cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) int mcmd_enable;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) static struct ctrl_settings ctrl_cfg __read_mostly;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) /* Register addresses and values for different BIOS versions */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) static const struct bios_settings bios_tbl[] __initconst = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) /* AOA110 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) {"Acer", "AOA110", "v0.3109", 0x55, 0x58, {0x1f, 0x00}, 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) {"Acer", "AOA110", "v0.3114", 0x55, 0x58, {0x1f, 0x00}, 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) {"Acer", "AOA110", "v0.3301", 0x55, 0x58, {0xaf, 0x00}, 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) {"Acer", "AOA110", "v0.3304", 0x55, 0x58, {0xaf, 0x00}, 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) {"Acer", "AOA110", "v0.3305", 0x55, 0x58, {0xaf, 0x00}, 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) {"Acer", "AOA110", "v0.3307", 0x55, 0x58, {0xaf, 0x00}, 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) {"Acer", "AOA110", "v0.3308", 0x55, 0x58, {0x21, 0x00}, 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) {"Acer", "AOA110", "v0.3309", 0x55, 0x58, {0x21, 0x00}, 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) {"Acer", "AOA110", "v0.3310", 0x55, 0x58, {0x21, 0x00}, 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) /* AOA150 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) {"Acer", "AOA150", "v0.3114", 0x55, 0x58, {0x1f, 0x00}, 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) {"Acer", "AOA150", "v0.3301", 0x55, 0x58, {0x20, 0x00}, 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) {"Acer", "AOA150", "v0.3304", 0x55, 0x58, {0x20, 0x00}, 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) {"Acer", "AOA150", "v0.3305", 0x55, 0x58, {0x20, 0x00}, 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) {"Acer", "AOA150", "v0.3307", 0x55, 0x58, {0x20, 0x00}, 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) {"Acer", "AOA150", "v0.3308", 0x55, 0x58, {0x20, 0x00}, 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) {"Acer", "AOA150", "v0.3309", 0x55, 0x58, {0x20, 0x00}, 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) {"Acer", "AOA150", "v0.3310", 0x55, 0x58, {0x20, 0x00}, 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) /* LT1005u */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) {"Acer", "LT-10Q", "v0.3310", 0x55, 0x58, {0x20, 0x00}, 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) /* Acer 1410 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) {"Acer", "Aspire 1410", "v0.3108", 0x55, 0x58, {0x9e, 0x00}, 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) {"Acer", "Aspire 1410", "v0.3113", 0x55, 0x58, {0x9e, 0x00}, 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) {"Acer", "Aspire 1410", "v0.3115", 0x55, 0x58, {0x9e, 0x00}, 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) {"Acer", "Aspire 1410", "v0.3117", 0x55, 0x58, {0x9e, 0x00}, 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) {"Acer", "Aspire 1410", "v0.3119", 0x55, 0x58, {0x9e, 0x00}, 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) {"Acer", "Aspire 1410", "v0.3120", 0x55, 0x58, {0x9e, 0x00}, 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) {"Acer", "Aspire 1410", "v1.3204", 0x55, 0x58, {0x9e, 0x00}, 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) {"Acer", "Aspire 1410", "v1.3303", 0x55, 0x58, {0x9e, 0x00}, 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) {"Acer", "Aspire 1410", "v1.3308", 0x55, 0x58, {0x9e, 0x00}, 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) {"Acer", "Aspire 1410", "v1.3310", 0x55, 0x58, {0x9e, 0x00}, 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) {"Acer", "Aspire 1410", "v1.3314", 0x55, 0x58, {0x9e, 0x00}, 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) /* Acer 1810xx */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) {"Acer", "Aspire 1810TZ", "v0.3108", 0x55, 0x58, {0x9e, 0x00}, 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) {"Acer", "Aspire 1810T", "v0.3108", 0x55, 0x58, {0x9e, 0x00}, 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) {"Acer", "Aspire 1810TZ", "v0.3113", 0x55, 0x58, {0x9e, 0x00}, 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) {"Acer", "Aspire 1810T", "v0.3113", 0x55, 0x58, {0x9e, 0x00}, 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) {"Acer", "Aspire 1810TZ", "v0.3115", 0x55, 0x58, {0x9e, 0x00}, 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) {"Acer", "Aspire 1810T", "v0.3115", 0x55, 0x58, {0x9e, 0x00}, 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) {"Acer", "Aspire 1810TZ", "v0.3117", 0x55, 0x58, {0x9e, 0x00}, 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) {"Acer", "Aspire 1810T", "v0.3117", 0x55, 0x58, {0x9e, 0x00}, 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) {"Acer", "Aspire 1810TZ", "v0.3119", 0x55, 0x58, {0x9e, 0x00}, 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) {"Acer", "Aspire 1810T", "v0.3119", 0x55, 0x58, {0x9e, 0x00}, 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) {"Acer", "Aspire 1810TZ", "v0.3120", 0x55, 0x58, {0x9e, 0x00}, 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) {"Acer", "Aspire 1810T", "v0.3120", 0x55, 0x58, {0x9e, 0x00}, 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) {"Acer", "Aspire 1810TZ", "v1.3204", 0x55, 0x58, {0x9e, 0x00}, 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) {"Acer", "Aspire 1810T", "v1.3204", 0x55, 0x58, {0x9e, 0x00}, 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) {"Acer", "Aspire 1810TZ", "v1.3303", 0x55, 0x58, {0x9e, 0x00}, 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) {"Acer", "Aspire 1810T", "v1.3303", 0x55, 0x58, {0x9e, 0x00}, 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) {"Acer", "Aspire 1810TZ", "v1.3308", 0x55, 0x58, {0x9e, 0x00}, 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) {"Acer", "Aspire 1810T", "v1.3308", 0x55, 0x58, {0x9e, 0x00}, 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) {"Acer", "Aspire 1810TZ", "v1.3310", 0x55, 0x58, {0x9e, 0x00}, 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) {"Acer", "Aspire 1810T", "v1.3310", 0x55, 0x58, {0x9e, 0x00}, 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) {"Acer", "Aspire 1810TZ", "v1.3314", 0x55, 0x58, {0x9e, 0x00}, 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) {"Acer", "Aspire 1810T", "v1.3314", 0x55, 0x58, {0x9e, 0x00}, 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) /* Acer 5755G */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) {"Acer", "Aspire 5755G", "V1.20", 0xab, 0xb4, {0x00, 0x08}, 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) {"Acer", "Aspire 5755G", "V1.21", 0xab, 0xb3, {0x00, 0x08}, 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) /* Acer 521 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) {"Acer", "AO521", "V1.11", 0x55, 0x58, {0x1f, 0x00}, 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) /* Acer 531 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) {"Acer", "AO531h", "v0.3104", 0x55, 0x58, {0x20, 0x00}, 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) {"Acer", "AO531h", "v0.3201", 0x55, 0x58, {0x20, 0x00}, 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) {"Acer", "AO531h", "v0.3304", 0x55, 0x58, {0x20, 0x00}, 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) /* Acer 751 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) {"Acer", "AO751h", "V0.3206", 0x55, 0x58, {0x21, 0x00}, 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) {"Acer", "AO751h", "V0.3212", 0x55, 0x58, {0x21, 0x00}, 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) /* Acer 753 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) {"Acer", "Aspire One 753", "V1.24", 0x93, 0xac, {0x14, 0x04}, 1},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) /* Acer 1825 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) {"Acer", "Aspire 1825PTZ", "V1.3118", 0x55, 0x58, {0x9e, 0x00}, 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) {"Acer", "Aspire 1825PTZ", "V1.3127", 0x55, 0x58, {0x9e, 0x00}, 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) /* Acer Extensa 5420 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) {"Acer", "Extensa 5420", "V1.17", 0x93, 0xac, {0x14, 0x04}, 1},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) /* Acer Aspire 5315 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) {"Acer", "Aspire 5315", "V1.19", 0x93, 0xac, {0x14, 0x04}, 1},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) /* Acer Aspire 5739 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) {"Acer", "Aspire 5739G", "V1.3311", 0x55, 0x58, {0x20, 0x00}, 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) /* Acer TravelMate 7730 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) {"Acer", "TravelMate 7730G", "v0.3509", 0x55, 0x58, {0xaf, 0x00}, 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) /* Acer Aspire 7551 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) {"Acer", "Aspire 7551", "V1.18", 0x93, 0xa8, {0x14, 0x04}, 1},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) /* Acer TravelMate TM8573T */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) {"Acer", "TM8573T", "V1.13", 0x93, 0xa8, {0x14, 0x04}, 1},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) /* Gateway */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) {"Gateway", "AOA110", "v0.3103", 0x55, 0x58, {0x21, 0x00}, 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) {"Gateway", "AOA150", "v0.3103", 0x55, 0x58, {0x20, 0x00}, 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) {"Gateway", "LT31", "v1.3103", 0x55, 0x58, {0x9e, 0x00}, 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) {"Gateway", "LT31", "v1.3201", 0x55, 0x58, {0x9e, 0x00}, 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) {"Gateway", "LT31", "v1.3302", 0x55, 0x58, {0x9e, 0x00}, 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) {"Gateway", "LT31", "v1.3303t", 0x55, 0x58, {0x9e, 0x00}, 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) {"Gateway", "LT31", "v1.3307", 0x55, 0x58, {0x9e, 0x00}, 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) /* Packard Bell */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) {"Packard Bell", "DOA150", "v0.3104", 0x55, 0x58, {0x21, 0x00}, 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) {"Packard Bell", "DOA150", "v0.3105", 0x55, 0x58, {0x20, 0x00}, 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) {"Packard Bell", "AOA110", "v0.3105", 0x55, 0x58, {0x21, 0x00}, 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) {"Packard Bell", "AOA150", "v0.3105", 0x55, 0x58, {0x20, 0x00}, 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) {"Packard Bell", "ENBFT", "V1.3118", 0x55, 0x58, {0x9e, 0x00}, 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) {"Packard Bell", "ENBFT", "V1.3127", 0x55, 0x58, {0x9e, 0x00}, 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) {"Packard Bell", "DOTMU", "v1.3303", 0x55, 0x58, {0x9e, 0x00}, 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) {"Packard Bell", "DOTMU", "v0.3120", 0x55, 0x58, {0x9e, 0x00}, 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) {"Packard Bell", "DOTMU", "v0.3108", 0x55, 0x58, {0x9e, 0x00}, 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) {"Packard Bell", "DOTMU", "v0.3113", 0x55, 0x58, {0x9e, 0x00}, 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) {"Packard Bell", "DOTMU", "v0.3115", 0x55, 0x58, {0x9e, 0x00}, 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) {"Packard Bell", "DOTMU", "v0.3117", 0x55, 0x58, {0x9e, 0x00}, 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) {"Packard Bell", "DOTMU", "v0.3119", 0x55, 0x58, {0x9e, 0x00}, 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) {"Packard Bell", "DOTMU", "v1.3204", 0x55, 0x58, {0x9e, 0x00}, 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) {"Packard Bell", "DOTMA", "v1.3201", 0x55, 0x58, {0x9e, 0x00}, 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) {"Packard Bell", "DOTMA", "v1.3302", 0x55, 0x58, {0x9e, 0x00}, 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) {"Packard Bell", "DOTMA", "v1.3303t", 0x55, 0x58, {0x9e, 0x00}, 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) {"Packard Bell", "DOTVR46", "v1.3308", 0x55, 0x58, {0x9e, 0x00}, 0},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) /* pewpew-terminator */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) {"", "", "", 0, 0, {0, 0}, 0}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) * this struct is used to instruct thermal layer to use bang_bang instead of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) * default governor for acerhdf
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) static struct thermal_zone_params acerhdf_zone_params = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) .governor_name = "bang_bang",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) static int acerhdf_get_temp(int *temp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) u8 read_temp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) if (ec_read(ctrl_cfg.tempreg, &read_temp))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) *temp = read_temp * 1000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) static int acerhdf_get_fanstate(int *state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) u8 fan;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) if (ec_read(ctrl_cfg.fanreg, &fan))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) if (fan != ctrl_cfg.cmd.cmd_off)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) *state = ACERHDF_FAN_AUTO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) *state = ACERHDF_FAN_OFF;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) static void acerhdf_change_fanstate(int state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) unsigned char cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) if (verbose)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) pr_notice("fan %s\n", state == ACERHDF_FAN_OFF ? "OFF" : "ON");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) if ((state != ACERHDF_FAN_OFF) && (state != ACERHDF_FAN_AUTO)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) pr_err("invalid fan state %d requested, setting to auto!\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) state = ACERHDF_FAN_AUTO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) cmd = (state == ACERHDF_FAN_OFF) ? ctrl_cfg.cmd.cmd_off
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) : ctrl_cfg.cmd.cmd_auto;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) fanstate = state;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) ec_write(ctrl_cfg.fanreg, cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) if (ctrl_cfg.mcmd_enable && state == ACERHDF_FAN_OFF) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) if (verbose)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) pr_notice("turning off fan manually\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) ec_write(mcmd.mreg, mcmd.moff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) static void acerhdf_check_param(struct thermal_zone_device *thermal)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) if (fanon > ACERHDF_MAX_FANON) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) pr_err("fanon temperature too high, set to %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) ACERHDF_MAX_FANON);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) fanon = ACERHDF_MAX_FANON;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) if (kernelmode && prev_interval != interval) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) if (interval > ACERHDF_MAX_INTERVAL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) pr_err("interval too high, set to %d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) ACERHDF_MAX_INTERVAL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) interval = ACERHDF_MAX_INTERVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) if (verbose)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) pr_notice("interval changed to: %d\n", interval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) thermal->polling_delay = interval*1000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) prev_interval = interval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) }
^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) * This is the thermal zone callback which does the delayed polling of the fan
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) * state. We do check /sysfs-originating settings here in acerhdf_check_param()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) * as late as the polling interval is since we can't do that in the respective
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) * accessors of the module parameters.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) static int acerhdf_get_ec_temp(struct thermal_zone_device *thermal, int *t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) int temp, err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) acerhdf_check_param(thermal);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) err = acerhdf_get_temp(&temp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) if (verbose)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) pr_notice("temp %d\n", temp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) *t = temp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) static int acerhdf_bind(struct thermal_zone_device *thermal,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) struct thermal_cooling_device *cdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) /* if the cooling device is the one from acerhdf bind it */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) if (cdev != cl_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) if (thermal_zone_bind_cooling_device(thermal, 0, cdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) THERMAL_NO_LIMIT, THERMAL_NO_LIMIT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) THERMAL_WEIGHT_DEFAULT)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) pr_err("error binding cooling dev\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) static int acerhdf_unbind(struct thermal_zone_device *thermal,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) struct thermal_cooling_device *cdev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) if (cdev != cl_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) if (thermal_zone_unbind_cooling_device(thermal, 0, cdev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) pr_err("error unbinding cooling dev\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) static inline void acerhdf_revert_to_bios_mode(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) acerhdf_change_fanstate(ACERHDF_FAN_AUTO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) kernelmode = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) pr_notice("kernel mode fan control OFF\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) static inline void acerhdf_enable_kernelmode(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) kernelmode = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) pr_notice("kernel mode fan control ON\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) * set operation mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) * enabled: the thermal layer of the kernel takes care about
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) * the temperature and the fan.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) * disabled: the BIOS takes control of the fan.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) static int acerhdf_change_mode(struct thermal_zone_device *thermal,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) enum thermal_device_mode mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) if (mode == THERMAL_DEVICE_DISABLED && kernelmode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) acerhdf_revert_to_bios_mode();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) else if (mode == THERMAL_DEVICE_ENABLED && !kernelmode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) acerhdf_enable_kernelmode();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) static int acerhdf_get_trip_type(struct thermal_zone_device *thermal, int trip,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) enum thermal_trip_type *type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) if (trip == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) *type = THERMAL_TRIP_ACTIVE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) else if (trip == 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) *type = THERMAL_TRIP_CRITICAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) return -EINVAL;
^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)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) static int acerhdf_get_trip_hyst(struct thermal_zone_device *thermal, int trip,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) int *temp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) if (trip != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) *temp = fanon - fanoff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) static int acerhdf_get_trip_temp(struct thermal_zone_device *thermal, int trip,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) int *temp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) if (trip == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) *temp = fanon;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) else if (trip == 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) *temp = ACERHDF_TEMP_CRIT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) static int acerhdf_get_crit_temp(struct thermal_zone_device *thermal,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) int *temperature)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) *temperature = ACERHDF_TEMP_CRIT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) /* bind callback functions to thermalzone */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) static struct thermal_zone_device_ops acerhdf_dev_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) .bind = acerhdf_bind,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) .unbind = acerhdf_unbind,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) .get_temp = acerhdf_get_ec_temp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) .change_mode = acerhdf_change_mode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) .get_trip_type = acerhdf_get_trip_type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) .get_trip_hyst = acerhdf_get_trip_hyst,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) .get_trip_temp = acerhdf_get_trip_temp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) .get_crit_temp = acerhdf_get_crit_temp,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) * cooling device callback functions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) * get maximal fan cooling state
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) static int acerhdf_get_max_state(struct thermal_cooling_device *cdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) unsigned long *state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) *state = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) static int acerhdf_get_cur_state(struct thermal_cooling_device *cdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) unsigned long *state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) int err = 0, tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) err = acerhdf_get_fanstate(&tmp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) *state = (tmp == ACERHDF_FAN_AUTO) ? 1 : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) /* change current fan state - is overwritten when running in kernel mode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) static int acerhdf_set_cur_state(struct thermal_cooling_device *cdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) unsigned long state)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) int cur_temp, cur_state, err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) if (!kernelmode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) err = acerhdf_get_temp(&cur_temp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) pr_err("error reading temperature, hand off control to BIOS\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) goto err_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) err = acerhdf_get_fanstate(&cur_state);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) if (err) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) pr_err("error reading fan state, hand off control to BIOS\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) goto err_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) if (state == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) if (cur_state == ACERHDF_FAN_AUTO)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) acerhdf_change_fanstate(ACERHDF_FAN_OFF);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) if (cur_state == ACERHDF_FAN_OFF)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) acerhdf_change_fanstate(ACERHDF_FAN_AUTO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) err_out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) acerhdf_revert_to_bios_mode();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) /* bind fan callbacks to fan device */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) static const struct thermal_cooling_device_ops acerhdf_cooling_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) .get_max_state = acerhdf_get_max_state,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) .get_cur_state = acerhdf_get_cur_state,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) .set_cur_state = acerhdf_set_cur_state,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) /* suspend / resume functionality */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) static int acerhdf_suspend(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554) if (kernelmode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) acerhdf_change_fanstate(ACERHDF_FAN_AUTO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) if (verbose)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) pr_notice("going suspend\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) static int acerhdf_probe(struct platform_device *device)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) static int acerhdf_remove(struct platform_device *device)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) static const struct dev_pm_ops acerhdf_pm_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) .suspend = acerhdf_suspend,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) .freeze = acerhdf_suspend,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) static struct platform_driver acerhdf_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) .driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) .name = "acerhdf",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) .pm = &acerhdf_pm_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) .probe = acerhdf_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) .remove = acerhdf_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) /* checks if str begins with start */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) static int str_starts_with(const char *str, const char *start)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) unsigned long str_len = 0, start_len = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592) str_len = strlen(str);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) start_len = strlen(start);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595) if (str_len >= start_len &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) !strncmp(str, start, start_len))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) /* check hardware */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) static int __init acerhdf_check_hardware(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) char const *vendor, *version, *product;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606) const struct bios_settings *bt = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) int found = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) /* get BIOS data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) vendor = dmi_get_system_info(DMI_SYS_VENDOR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) version = dmi_get_system_info(DMI_BIOS_VERSION);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) product = dmi_get_system_info(DMI_PRODUCT_NAME);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) if (!vendor || !version || !product) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) pr_err("error getting hardware information\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) pr_info("Acer Aspire One Fan driver, v.%s\n", DRV_VER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) if (list_supported) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) pr_info("List of supported Manufacturer/Model/BIOS:\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) pr_info("---------------------------------------------------\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) for (bt = bios_tbl; bt->vendor[0]; bt++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) pr_info("%-13s | %-17s | %-10s\n", bt->vendor,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) bt->product, bt->version);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) pr_info("---------------------------------------------------\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) return -ECANCELED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632) if (force_bios[0]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) version = force_bios;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) pr_info("forcing BIOS version: %s\n", version);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) kernelmode = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) if (force_product[0]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) product = force_product;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) pr_info("forcing BIOS product: %s\n", product);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) kernelmode = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) if (verbose)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) pr_info("BIOS info: %s %s, product: %s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) vendor, version, product);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) /* search BIOS version and vendor in BIOS settings table */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649) for (bt = bios_tbl; bt->vendor[0]; bt++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) * check if actual hardware BIOS vendor, product and version
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) * IDs start with the strings of BIOS table entry
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) if (str_starts_with(vendor, bt->vendor) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655) str_starts_with(product, bt->product) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) str_starts_with(version, bt->version)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) found = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) if (!found) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) pr_err("unknown (unsupported) BIOS version %s/%s/%s, please report, aborting!\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) vendor, product, version);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) /* Copy control settings from BIOS table before we free it. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) ctrl_cfg.fanreg = bt->fanreg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) ctrl_cfg.tempreg = bt->tempreg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) memcpy(&ctrl_cfg.cmd, &bt->cmd, sizeof(struct fancmd));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) ctrl_cfg.mcmd_enable = bt->mcmd_enable;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) * if started with kernel mode off, prevent the kernel from switching
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) * off the fan
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) if (!kernelmode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) pr_notice("Fan control off, to enable do:\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) pr_notice("echo -n \"enabled\" > /sys/class/thermal/thermal_zoneN/mode # N=0,1,2...\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686) static int __init acerhdf_register_platform(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) int err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) err = platform_driver_register(&acerhdf_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) acerhdf_dev = platform_device_alloc("acerhdf", -1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) if (!acerhdf_dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) err = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) goto err_device_alloc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) err = platform_device_add(acerhdf_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) goto err_device_add;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) err_device_add:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) platform_device_put(acerhdf_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) err_device_alloc:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) platform_driver_unregister(&acerhdf_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) static void acerhdf_unregister_platform(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) platform_device_unregister(acerhdf_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715) platform_driver_unregister(&acerhdf_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) static int __init acerhdf_register_thermal(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) cl_dev = thermal_cooling_device_register("acerhdf-fan", NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) &acerhdf_cooling_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) if (IS_ERR(cl_dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) thz_dev = thermal_zone_device_register("acerhdf", 2, 0, NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) &acerhdf_dev_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) &acerhdf_zone_params, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) (kernelmode) ? interval*1000 : 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) if (IS_ERR(thz_dev))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) if (kernelmode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) ret = thermal_zone_device_enable(thz_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) ret = thermal_zone_device_disable(thz_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742) if (strcmp(thz_dev->governor->name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) acerhdf_zone_params.governor_name)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) pr_err("Didn't get thermal governor %s, perhaps not compiled into thermal subsystem.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) acerhdf_zone_params.governor_name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752) static void acerhdf_unregister_thermal(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) if (cl_dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) thermal_cooling_device_unregister(cl_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) cl_dev = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) if (thz_dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) thermal_zone_device_unregister(thz_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) thz_dev = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) static int __init acerhdf_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) int err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) err = acerhdf_check_hardware();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) goto out_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) err = acerhdf_register_platform();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) goto out_err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777) err = acerhdf_register_thermal();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) goto err_unreg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783) err_unreg:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) acerhdf_unregister_thermal();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) acerhdf_unregister_platform();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787) out_err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 790)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 791) static void __exit acerhdf_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 792) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 793) acerhdf_change_fanstate(ACERHDF_FAN_AUTO);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 794) acerhdf_unregister_thermal();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 795) acerhdf_unregister_platform();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 796) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 797)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 798) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 799) MODULE_AUTHOR("Peter Kaestle");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 800) MODULE_DESCRIPTION("Aspire One temperature and fan driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 801) MODULE_ALIAS("dmi:*:*Acer*:pnAOA*:");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 802) MODULE_ALIAS("dmi:*:*Acer*:pnAO751h*:");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 803) MODULE_ALIAS("dmi:*:*Acer*:pnAspire*1410*:");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 804) MODULE_ALIAS("dmi:*:*Acer*:pnAspire*1810*:");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 805) MODULE_ALIAS("dmi:*:*Acer*:pnAspire*5755G:");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 806) MODULE_ALIAS("dmi:*:*Acer*:pnAspire*1825PTZ:");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 807) MODULE_ALIAS("dmi:*:*Acer*:pnAO521*:");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 808) MODULE_ALIAS("dmi:*:*Acer*:pnAO531*:");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 809) MODULE_ALIAS("dmi:*:*Acer*:pnAspire*5739G:");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 810) MODULE_ALIAS("dmi:*:*Acer*:pnAspire*One*753:");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 811) MODULE_ALIAS("dmi:*:*Acer*:pnAspire*5315:");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 812) MODULE_ALIAS("dmi:*:*Acer*:TravelMate*7730G:");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 813) MODULE_ALIAS("dmi:*:*Acer*:pnAspire*7551:");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 814) MODULE_ALIAS("dmi:*:*Acer*:TM8573T:");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 815) MODULE_ALIAS("dmi:*:*Gateway*:pnAOA*:");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 816) MODULE_ALIAS("dmi:*:*Gateway*:pnLT31*:");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 817) MODULE_ALIAS("dmi:*:*Packard*Bell*:pnAOA*:");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 818) MODULE_ALIAS("dmi:*:*Packard*Bell*:pnDOA*:");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 819) MODULE_ALIAS("dmi:*:*Packard*Bell*:pnDOTMU*:");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 820) MODULE_ALIAS("dmi:*:*Packard*Bell*:pnENBFT*:");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 821) MODULE_ALIAS("dmi:*:*Packard*Bell*:pnDOTMA*:");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 822) MODULE_ALIAS("dmi:*:*Packard*Bell*:pnDOTVR46*:");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 823) MODULE_ALIAS("dmi:*:*Acer*:pnExtensa*5420*:");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 824)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 825) module_init(acerhdf_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 826) module_exit(acerhdf_exit);