// SPDX-License-Identifier: GPL-2.0-or-later /* * acerhdf - A driver which monitors the temperature * of the aspire one netbook, turns on/off the fan * as soon as the upper/lower threshold is reached. * * (C) 2009 - Peter Kaestle peter (a) piie.net * https://piie.net * 2009 Borislav Petkov bp (a) alien8.de * * Inspired by and many thanks to: * o acerfand - Rachel Greenham * o acer_ec.pl - Michael Kurz michi.kurz (at) googlemail.com * - Petr Tomasek tomasek (#) etf,cuni,cz * - Carlos Corbacho cathectic (at) gmail.com * o lkml - Matthew Garrett * - Borislav Petkov * - Andreas Mohr
*/
/* * The driver is started with "kernel mode off" by default. That means, the BIOS * is still in control of the fan. In this mode the driver allows to read the * temperature of the cpu and a userspace tool may take over control of the fan. * If the driver is switched to "kernel mode" (e.g. via module parameter) the * driver is in full control of the fan. If you want the module to be started in * kernel mode by default, define the following:
*/ #undef START_IN_KERNEL_MODE
#define DRV_VER "0.7.0"
/* * According to the Atom N270 datasheet, * (http://download.intel.com/design/processor/datashts/320032.pdf) the * CPU's optimal operating limits denoted in junction temperature as * measured by the on-die thermal monitor are within 0 <= Tj <= 90. So, * assume 89°C is critical temperature.
*/ #define ACERHDF_DEFAULT_TEMP_FANON 60000 #define ACERHDF_DEFAULT_TEMP_FANOFF 53000 #define ACERHDF_TEMP_CRIT 89000 #define ACERHDF_FAN_OFF 0 #define ACERHDF_FAN_AUTO 1
/* * No matter what value the user puts into the fanon variable, turn on the fan * at 80 degree Celsius to prevent hardware damage
*/ #define ACERHDF_MAX_FANON 80000
/* * Maximum interval between two temperature checks is 15 seconds, as the die * can get hot really fast under heavy load (plus we shouldn't forget about * possible impact of _external_ aggressive sources such as heaters, sun etc.)
*/ #define ACERHDF_MAX_INTERVAL 15
module_param(kernelmode, uint, 0);
MODULE_PARM_DESC(kernelmode, "Kernel mode fan control on / off");
module_param(fanon, uint, 0600);
MODULE_PARM_DESC(fanon, "Turn the fan on above this temperature");
module_param(fanoff, uint, 0600);
MODULE_PARM_DESC(fanoff, "Turn the fan off below this temperature");
module_param(verbose, uint, 0600);
MODULE_PARM_DESC(verbose, "Enable verbose dmesg output");
module_param(list_supported, uint, 0600);
MODULE_PARM_DESC(list_supported, "List supported models and BIOS versions");
module_param_string(force_bios, force_bios, 16, 0);
MODULE_PARM_DESC(force_bios, "Pretend system has this known supported BIOS version");
module_param_string(force_product, force_product, 16, 0);
MODULE_PARM_DESC(force_product, "Pretend system is this known supported model");
/* * cmd_off: to switch the fan completely off and check if the fan is off * cmd_auto: to set the BIOS in control of the fan. The BIOS regulates then * the fan speed depending on the temperature
*/ struct fancmd {
u8 cmd_off;
u8 cmd_auto;
};
struct manualcmd {
u8 mreg;
u8 moff;
};
/* default register and command to disable fan in manual mode */ staticconststruct manualcmd mcmd = {
.mreg = 0x94,
.moff = 0xff,
};
/* BIOS settings - only used during probe */ struct bios_settings { constchar *vendor; constchar *product; constchar *version;
u8 fanreg;
u8 tempreg; struct fancmd cmd; int mcmd_enable;
};
/* This could be a daughter struct in the above, but not worth the redirect */ struct ctrl_settings {
u8 fanreg;
u8 tempreg; struct fancmd cmd; int mcmd_enable;
};
/* * this struct is used to instruct thermal layer to use bang_bang instead of * default governor for acerhdf
*/ staticconststruct thermal_zone_params acerhdf_zone_params = {
.governor_name = "bang_bang",
};
if (verbose)
pr_notice("fan %s\n", state == ACERHDF_FAN_OFF ? "OFF" : "ON");
if ((state != ACERHDF_FAN_OFF) && (state != ACERHDF_FAN_AUTO)) {
pr_err("invalid fan state %d requested, setting to auto!\n",
state);
state = ACERHDF_FAN_AUTO;
}
if (ctrl_cfg.mcmd_enable && state == ACERHDF_FAN_OFF) { if (verbose)
pr_notice("turning off fan manually\n");
ec_write(mcmd.mreg, mcmd.moff);
}
}
staticvoid acerhdf_check_param(struct thermal_zone_device *thermal)
{ if (fanon > ACERHDF_MAX_FANON) {
pr_err("fanon temperature too high, set to %d\n",
ACERHDF_MAX_FANON);
fanon = ACERHDF_MAX_FANON;
}
if (fanon < fanoff) {
pr_err("fanoff temperature (%d) is above fanon temperature (%d), clamping to %d\n",
fanoff, fanon, fanon);
fanoff = fanon;
}
if (kernelmode) { if (interval > ACERHDF_MAX_INTERVAL) {
pr_err("interval too high, set to %d\n",
ACERHDF_MAX_INTERVAL);
interval = ACERHDF_MAX_INTERVAL;
}
if (verbose)
pr_notice("interval changed to: %d\n", interval);
}
}
/* * This is the thermal zone callback which does the delayed polling of the fan * state. We do check /sysfs-originating settings here in acerhdf_check_param() * as late as the polling interval is since we can't do that in the respective * accessors of the module parameters.
*/ staticint acerhdf_get_ec_temp(struct thermal_zone_device *thermal, int *t)
{ int temp, err = 0;
err = acerhdf_get_temp(&temp); if (err) return err;
if (verbose)
pr_notice("temp %d\n", temp);
*t = temp; return0;
}
staticbool acerhdf_should_bind(struct thermal_zone_device *thermal, conststruct thermal_trip *trip, struct thermal_cooling_device *cdev, struct cooling_spec *c)
{ /* if the cooling device is the one from acerhdf bind it */ return cdev == cl_dev && trip->type == THERMAL_TRIP_ACTIVE;
}
pr_notice("kernel mode fan control OFF\n");
} staticinlinevoid acerhdf_enable_kernelmode(void)
{
kernelmode = 1;
pr_notice("kernel mode fan control ON\n");
}
/* * set operation mode; * enabled: the thermal layer of the kernel takes care about * the temperature and the fan. * disabled: the BIOS takes control of the fan.
*/ staticint acerhdf_change_mode(struct thermal_zone_device *thermal, enum thermal_device_mode mode)
{ if (mode == THERMAL_DEVICE_DISABLED && kernelmode)
acerhdf_revert_to_bios_mode(); elseif (mode == THERMAL_DEVICE_ENABLED && !kernelmode)
acerhdf_enable_kernelmode();
/* change current fan state - is overwritten when running in kernel mode */ staticint acerhdf_set_cur_state(struct thermal_cooling_device *cdev, unsignedlong state)
{ int cur_temp, cur_state, err = 0;
if (!kernelmode) return0;
err = acerhdf_get_temp(&cur_temp); if (err) {
pr_err("error reading temperature, hand off control to BIOS\n"); goto err_out;
}
err = acerhdf_get_fanstate(&cur_state); if (err) {
pr_err("error reading fan state, hand off control to BIOS\n"); goto err_out;
}
if (state == 0) { if (cur_state == ACERHDF_FAN_AUTO)
acerhdf_change_fanstate(ACERHDF_FAN_OFF);
} else { if (cur_state == ACERHDF_FAN_OFF)
acerhdf_change_fanstate(ACERHDF_FAN_AUTO);
} return0;
/* get BIOS data */
vendor = dmi_get_system_info(DMI_SYS_VENDOR);
version = dmi_get_system_info(DMI_BIOS_VERSION);
product = dmi_get_system_info(DMI_PRODUCT_NAME);
/* search BIOS version and vendor in BIOS settings table */ for (bt = bios_tbl; bt->vendor[0]; bt++) { /* * check if actual hardware BIOS vendor, product and version * IDs start with the strings of BIOS table entry
*/ if (strstarts(vendor, bt->vendor) &&
strstarts(product, bt->product) &&
strstarts(version, bt->version)) {
found = 1; break;
}
}
if (!found) {
pr_err("unknown (unsupported) BIOS version %s/%s/%s, please report, aborting!\n",
vendor, product, version); return -EINVAL;
}
/* Copy control settings from BIOS table before we free it. */
ctrl_cfg.fanreg = bt->fanreg;
ctrl_cfg.tempreg = bt->tempreg;
memcpy(&ctrl_cfg.cmd, &bt->cmd, sizeof(struct fancmd));
ctrl_cfg.mcmd_enable = bt->mcmd_enable;
/* * if started with kernel mode off, prevent the kernel from switching * off the fan
*/ if (!kernelmode) {
pr_notice("Fan control off, to enable do:\n");
pr_notice("echo -n \"enabled\" > /sys/class/thermal/thermal_zoneN/mode # N=0,1,2...\n");
}
return0;
}
staticint __init acerhdf_register_platform(void)
{ int err = 0;
err = platform_driver_register(&acerhdf_driver); if (err) return err;
acerhdf_dev = platform_device_alloc("acerhdf", PLATFORM_DEVID_NONE); if (!acerhdf_dev) {
err = -ENOMEM; goto err_device_alloc;
}
err = platform_device_add(acerhdf_dev); if (err) goto err_device_add;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.