1e86435ebSPeter Feuerer /* 2e86435ebSPeter Feuerer * acerhdf - A driver which monitors the temperature 3e86435ebSPeter Feuerer * of the aspire one netbook, turns on/off the fan 4e86435ebSPeter Feuerer * as soon as the upper/lower threshold is reached. 5e86435ebSPeter Feuerer * 6e86435ebSPeter Feuerer * (C) 2009 - Peter Feuerer peter (a) piie.net 7e86435ebSPeter Feuerer * http://piie.net 84e791c98SBorislav Petkov * 2009 Borislav Petkov bp (a) alien8.de 9e86435ebSPeter Feuerer * 10e86435ebSPeter Feuerer * Inspired by and many thanks to: 11e86435ebSPeter Feuerer * o acerfand - Rachel Greenham 12e86435ebSPeter Feuerer * o acer_ec.pl - Michael Kurz michi.kurz (at) googlemail.com 13e86435ebSPeter Feuerer * - Petr Tomasek tomasek (#) etf,cuni,cz 14e86435ebSPeter Feuerer * - Carlos Corbacho cathectic (at) gmail.com 15e86435ebSPeter Feuerer * o lkml - Matthew Garrett 16e86435ebSPeter Feuerer * - Borislav Petkov 17e86435ebSPeter Feuerer * - Andreas Mohr 18e86435ebSPeter Feuerer * 19e86435ebSPeter Feuerer * This program is free software; you can redistribute it and/or modify 20e86435ebSPeter Feuerer * it under the terms of the GNU General Public License as published by 21e86435ebSPeter Feuerer * the Free Software Foundation; either version 2 of the License, or 22e86435ebSPeter Feuerer * (at your option) any later version. 23e86435ebSPeter Feuerer * 24e86435ebSPeter Feuerer * This program is distributed in the hope that it will be useful, 25e86435ebSPeter Feuerer * but WITHOUT ANY WARRANTY; without even the implied warranty of 26e86435ebSPeter Feuerer * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 27e86435ebSPeter Feuerer * GNU General Public License for more details. 28e86435ebSPeter Feuerer * 29e86435ebSPeter Feuerer * You should have received a copy of the GNU General Public License 30e86435ebSPeter Feuerer * along with this program; if not, write to the Free Software 31e86435ebSPeter Feuerer * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 32e86435ebSPeter Feuerer */ 33e86435ebSPeter Feuerer 34e86435ebSPeter Feuerer #define pr_fmt(fmt) "acerhdf: " fmt 35e86435ebSPeter Feuerer 36e86435ebSPeter Feuerer #include <linux/kernel.h> 37e86435ebSPeter Feuerer #include <linux/module.h> 38e86435ebSPeter Feuerer #include <linux/dmi.h> 39c4bae98cSJean Delvare #include <linux/acpi.h> 40e86435ebSPeter Feuerer #include <linux/thermal.h> 41e86435ebSPeter Feuerer #include <linux/platform_device.h> 42e86435ebSPeter Feuerer 43e86435ebSPeter Feuerer /* 44e86435ebSPeter Feuerer * The driver is started with "kernel mode off" by default. That means, the BIOS 45e86435ebSPeter Feuerer * is still in control of the fan. In this mode the driver allows to read the 46e86435ebSPeter Feuerer * temperature of the cpu and a userspace tool may take over control of the fan. 47e86435ebSPeter Feuerer * If the driver is switched to "kernel mode" (e.g. via module parameter) the 48e86435ebSPeter Feuerer * driver is in full control of the fan. If you want the module to be started in 49e86435ebSPeter Feuerer * kernel mode by default, define the following: 50e86435ebSPeter Feuerer */ 51e86435ebSPeter Feuerer #undef START_IN_KERNEL_MODE 52e86435ebSPeter Feuerer 5348c8dd64SPeter Feuerer #define DRV_VER "0.7.0" 54e86435ebSPeter Feuerer 55e86435ebSPeter Feuerer /* 56e86435ebSPeter Feuerer * According to the Atom N270 datasheet, 57e86435ebSPeter Feuerer * (http://download.intel.com/design/processor/datashts/320032.pdf) the 58e86435ebSPeter Feuerer * CPU's optimal operating limits denoted in junction temperature as 59e86435ebSPeter Feuerer * measured by the on-die thermal monitor are within 0 <= Tj <= 90. So, 60e86435ebSPeter Feuerer * assume 89°C is critical temperature. 61e86435ebSPeter Feuerer */ 6270052917SPeter Feuerer #define ACERHDF_TEMP_CRIT 89000 63e86435ebSPeter Feuerer #define ACERHDF_FAN_OFF 0 64e86435ebSPeter Feuerer #define ACERHDF_FAN_AUTO 1 65e86435ebSPeter Feuerer 66e86435ebSPeter Feuerer /* 67e86435ebSPeter Feuerer * No matter what value the user puts into the fanon variable, turn on the fan 68e86435ebSPeter Feuerer * at 80 degree Celsius to prevent hardware damage 69e86435ebSPeter Feuerer */ 7070052917SPeter Feuerer #define ACERHDF_MAX_FANON 80000 71e86435ebSPeter Feuerer 72e86435ebSPeter Feuerer /* 73e86435ebSPeter Feuerer * Maximum interval between two temperature checks is 15 seconds, as the die 74e86435ebSPeter Feuerer * can get hot really fast under heavy load (plus we shouldn't forget about 75e86435ebSPeter Feuerer * possible impact of _external_ aggressive sources such as heaters, sun etc.) 76e86435ebSPeter Feuerer */ 77e86435ebSPeter Feuerer #define ACERHDF_MAX_INTERVAL 15 78e86435ebSPeter Feuerer 79e86435ebSPeter Feuerer #ifdef START_IN_KERNEL_MODE 80e86435ebSPeter Feuerer static int kernelmode = 1; 81e86435ebSPeter Feuerer #else 82e86435ebSPeter Feuerer static int kernelmode; 83e86435ebSPeter Feuerer #endif 84e86435ebSPeter Feuerer 85e86435ebSPeter Feuerer static unsigned int interval = 10; 86351963bbSPeter Feuerer static unsigned int fanon = 60000; 87351963bbSPeter Feuerer static unsigned int fanoff = 53000; 88e86435ebSPeter Feuerer static unsigned int verbose; 89e86435ebSPeter Feuerer static unsigned int fanstate = ACERHDF_FAN_AUTO; 90e86435ebSPeter Feuerer static char force_bios[16]; 91ded0cdfcSPeter Feuerer static char force_product[16]; 92e86435ebSPeter Feuerer static unsigned int prev_interval; 93fedae5adSAxel Lin static struct thermal_zone_device *thz_dev; 94fedae5adSAxel Lin static struct thermal_cooling_device *cl_dev; 95fedae5adSAxel Lin static struct platform_device *acerhdf_dev; 96e86435ebSPeter Feuerer 97e86435ebSPeter Feuerer module_param(kernelmode, uint, 0); 98e86435ebSPeter Feuerer MODULE_PARM_DESC(kernelmode, "Kernel mode fan control on / off"); 99e86435ebSPeter Feuerer module_param(interval, uint, 0600); 100e86435ebSPeter Feuerer MODULE_PARM_DESC(interval, "Polling interval of temperature check"); 101e86435ebSPeter Feuerer module_param(fanon, uint, 0600); 102e86435ebSPeter Feuerer MODULE_PARM_DESC(fanon, "Turn the fan on above this temperature"); 103e86435ebSPeter Feuerer module_param(fanoff, uint, 0600); 104e86435ebSPeter Feuerer MODULE_PARM_DESC(fanoff, "Turn the fan off below this temperature"); 105e86435ebSPeter Feuerer module_param(verbose, uint, 0600); 106e86435ebSPeter Feuerer MODULE_PARM_DESC(verbose, "Enable verbose dmesg output"); 107e86435ebSPeter Feuerer module_param_string(force_bios, force_bios, 16, 0); 108e86435ebSPeter Feuerer MODULE_PARM_DESC(force_bios, "Force BIOS version and omit BIOS check"); 109ded0cdfcSPeter Feuerer module_param_string(force_product, force_product, 16, 0); 110ded0cdfcSPeter Feuerer MODULE_PARM_DESC(force_product, "Force BIOS product and omit BIOS check"); 111ded0cdfcSPeter Feuerer 112ded0cdfcSPeter Feuerer /* 113210183d4SPeter Feuerer * cmd_off: to switch the fan completely off and check if the fan is off 114ded0cdfcSPeter Feuerer * cmd_auto: to set the BIOS in control of the fan. The BIOS regulates then 115ded0cdfcSPeter Feuerer * the fan speed depending on the temperature 116ded0cdfcSPeter Feuerer */ 117ded0cdfcSPeter Feuerer struct fancmd { 118ded0cdfcSPeter Feuerer u8 cmd_off; 119ded0cdfcSPeter Feuerer u8 cmd_auto; 120ded0cdfcSPeter Feuerer }; 121e86435ebSPeter Feuerer 1225ef6578cSPeter Feuerer struct manualcmd { 1235ef6578cSPeter Feuerer u8 mreg; 1245ef6578cSPeter Feuerer u8 moff; 1255ef6578cSPeter Feuerer }; 1265ef6578cSPeter Feuerer 1275ef6578cSPeter Feuerer /* default register and command to disable fan in manual mode */ 1285ef6578cSPeter Feuerer static const struct manualcmd mcmd = { 1295ef6578cSPeter Feuerer .mreg = 0x94, 1305ef6578cSPeter Feuerer .moff = 0xff, 1315ef6578cSPeter Feuerer }; 1325ef6578cSPeter Feuerer 133e86435ebSPeter Feuerer /* BIOS settings */ 134e86435ebSPeter Feuerer struct bios_settings_t { 135e86435ebSPeter Feuerer const char *vendor; 136ded0cdfcSPeter Feuerer const char *product; 137e86435ebSPeter Feuerer const char *version; 138e86435ebSPeter Feuerer unsigned char fanreg; 139e86435ebSPeter Feuerer unsigned char tempreg; 140ded0cdfcSPeter Feuerer struct fancmd cmd; 1415ef6578cSPeter Feuerer int mcmd_enable; 142e86435ebSPeter Feuerer }; 143e86435ebSPeter Feuerer 144e86435ebSPeter Feuerer /* Register addresses and values for different BIOS versions */ 145e86435ebSPeter Feuerer static const struct bios_settings_t bios_tbl[] = { 146ded0cdfcSPeter Feuerer /* AOA110 */ 1475ef6578cSPeter Feuerer {"Acer", "AOA110", "v0.3109", 0x55, 0x58, {0x1f, 0x00}, 0}, 1485ef6578cSPeter Feuerer {"Acer", "AOA110", "v0.3114", 0x55, 0x58, {0x1f, 0x00}, 0}, 1495ef6578cSPeter Feuerer {"Acer", "AOA110", "v0.3301", 0x55, 0x58, {0xaf, 0x00}, 0}, 1505ef6578cSPeter Feuerer {"Acer", "AOA110", "v0.3304", 0x55, 0x58, {0xaf, 0x00}, 0}, 1515ef6578cSPeter Feuerer {"Acer", "AOA110", "v0.3305", 0x55, 0x58, {0xaf, 0x00}, 0}, 1525ef6578cSPeter Feuerer {"Acer", "AOA110", "v0.3307", 0x55, 0x58, {0xaf, 0x00}, 0}, 1535ef6578cSPeter Feuerer {"Acer", "AOA110", "v0.3308", 0x55, 0x58, {0x21, 0x00}, 0}, 1545ef6578cSPeter Feuerer {"Acer", "AOA110", "v0.3309", 0x55, 0x58, {0x21, 0x00}, 0}, 1555ef6578cSPeter Feuerer {"Acer", "AOA110", "v0.3310", 0x55, 0x58, {0x21, 0x00}, 0}, 156ded0cdfcSPeter Feuerer /* AOA150 */ 1575ef6578cSPeter Feuerer {"Acer", "AOA150", "v0.3114", 0x55, 0x58, {0x1f, 0x00}, 0}, 1585ef6578cSPeter Feuerer {"Acer", "AOA150", "v0.3301", 0x55, 0x58, {0x20, 0x00}, 0}, 1595ef6578cSPeter Feuerer {"Acer", "AOA150", "v0.3304", 0x55, 0x58, {0x20, 0x00}, 0}, 1605ef6578cSPeter Feuerer {"Acer", "AOA150", "v0.3305", 0x55, 0x58, {0x20, 0x00}, 0}, 1615ef6578cSPeter Feuerer {"Acer", "AOA150", "v0.3307", 0x55, 0x58, {0x20, 0x00}, 0}, 1625ef6578cSPeter Feuerer {"Acer", "AOA150", "v0.3308", 0x55, 0x58, {0x20, 0x00}, 0}, 1635ef6578cSPeter Feuerer {"Acer", "AOA150", "v0.3309", 0x55, 0x58, {0x20, 0x00}, 0}, 1645ef6578cSPeter Feuerer {"Acer", "AOA150", "v0.3310", 0x55, 0x58, {0x20, 0x00}, 0}, 16543ae1e32SPeter Feuerer /* LT1005u */ 1665ef6578cSPeter Feuerer {"Acer", "LT-10Q", "v0.3310", 0x55, 0x58, {0x20, 0x00}, 0}, 16736065746SPeter Feuerer /* Acer 1410 */ 1685ef6578cSPeter Feuerer {"Acer", "Aspire 1410", "v0.3108", 0x55, 0x58, {0x9e, 0x00}, 0}, 1695ef6578cSPeter Feuerer {"Acer", "Aspire 1410", "v0.3113", 0x55, 0x58, {0x9e, 0x00}, 0}, 1705ef6578cSPeter Feuerer {"Acer", "Aspire 1410", "v0.3115", 0x55, 0x58, {0x9e, 0x00}, 0}, 1715ef6578cSPeter Feuerer {"Acer", "Aspire 1410", "v0.3117", 0x55, 0x58, {0x9e, 0x00}, 0}, 1725ef6578cSPeter Feuerer {"Acer", "Aspire 1410", "v0.3119", 0x55, 0x58, {0x9e, 0x00}, 0}, 1735ef6578cSPeter Feuerer {"Acer", "Aspire 1410", "v0.3120", 0x55, 0x58, {0x9e, 0x00}, 0}, 1745ef6578cSPeter Feuerer {"Acer", "Aspire 1410", "v1.3204", 0x55, 0x58, {0x9e, 0x00}, 0}, 1755ef6578cSPeter Feuerer {"Acer", "Aspire 1410", "v1.3303", 0x55, 0x58, {0x9e, 0x00}, 0}, 1765ef6578cSPeter Feuerer {"Acer", "Aspire 1410", "v1.3308", 0x55, 0x58, {0x9e, 0x00}, 0}, 1775ef6578cSPeter Feuerer {"Acer", "Aspire 1410", "v1.3310", 0x55, 0x58, {0x9e, 0x00}, 0}, 1785ef6578cSPeter Feuerer {"Acer", "Aspire 1410", "v1.3314", 0x55, 0x58, {0x9e, 0x00}, 0}, 17994219d79SPeter Feuerer /* Acer 1810xx */ 1805ef6578cSPeter Feuerer {"Acer", "Aspire 1810TZ", "v0.3108", 0x55, 0x58, {0x9e, 0x00}, 0}, 1815ef6578cSPeter Feuerer {"Acer", "Aspire 1810T", "v0.3108", 0x55, 0x58, {0x9e, 0x00}, 0}, 1825ef6578cSPeter Feuerer {"Acer", "Aspire 1810TZ", "v0.3113", 0x55, 0x58, {0x9e, 0x00}, 0}, 1835ef6578cSPeter Feuerer {"Acer", "Aspire 1810T", "v0.3113", 0x55, 0x58, {0x9e, 0x00}, 0}, 1845ef6578cSPeter Feuerer {"Acer", "Aspire 1810TZ", "v0.3115", 0x55, 0x58, {0x9e, 0x00}, 0}, 1855ef6578cSPeter Feuerer {"Acer", "Aspire 1810T", "v0.3115", 0x55, 0x58, {0x9e, 0x00}, 0}, 1865ef6578cSPeter Feuerer {"Acer", "Aspire 1810TZ", "v0.3117", 0x55, 0x58, {0x9e, 0x00}, 0}, 1875ef6578cSPeter Feuerer {"Acer", "Aspire 1810T", "v0.3117", 0x55, 0x58, {0x9e, 0x00}, 0}, 1885ef6578cSPeter Feuerer {"Acer", "Aspire 1810TZ", "v0.3119", 0x55, 0x58, {0x9e, 0x00}, 0}, 1895ef6578cSPeter Feuerer {"Acer", "Aspire 1810T", "v0.3119", 0x55, 0x58, {0x9e, 0x00}, 0}, 1905ef6578cSPeter Feuerer {"Acer", "Aspire 1810TZ", "v0.3120", 0x55, 0x58, {0x9e, 0x00}, 0}, 1915ef6578cSPeter Feuerer {"Acer", "Aspire 1810T", "v0.3120", 0x55, 0x58, {0x9e, 0x00}, 0}, 1925ef6578cSPeter Feuerer {"Acer", "Aspire 1810TZ", "v1.3204", 0x55, 0x58, {0x9e, 0x00}, 0}, 1935ef6578cSPeter Feuerer {"Acer", "Aspire 1810T", "v1.3204", 0x55, 0x58, {0x9e, 0x00}, 0}, 1945ef6578cSPeter Feuerer {"Acer", "Aspire 1810TZ", "v1.3303", 0x55, 0x58, {0x9e, 0x00}, 0}, 1955ef6578cSPeter Feuerer {"Acer", "Aspire 1810T", "v1.3303", 0x55, 0x58, {0x9e, 0x00}, 0}, 1965ef6578cSPeter Feuerer {"Acer", "Aspire 1810TZ", "v1.3308", 0x55, 0x58, {0x9e, 0x00}, 0}, 1975ef6578cSPeter Feuerer {"Acer", "Aspire 1810T", "v1.3308", 0x55, 0x58, {0x9e, 0x00}, 0}, 1985ef6578cSPeter Feuerer {"Acer", "Aspire 1810TZ", "v1.3310", 0x55, 0x58, {0x9e, 0x00}, 0}, 1995ef6578cSPeter Feuerer {"Acer", "Aspire 1810T", "v1.3310", 0x55, 0x58, {0x9e, 0x00}, 0}, 2005ef6578cSPeter Feuerer {"Acer", "Aspire 1810TZ", "v1.3314", 0x55, 0x58, {0x9e, 0x00}, 0}, 2015ef6578cSPeter Feuerer {"Acer", "Aspire 1810T", "v1.3314", 0x55, 0x58, {0x9e, 0x00}, 0}, 2027438d990SPeter Feuerer /* Acer 5755G */ 2037438d990SPeter Feuerer {"Acer", "Aspire 5755G", "V1.20", 0xab, 0xb4, {0x00, 0x08}, 0}, 2047438d990SPeter Feuerer {"Acer", "Aspire 5755G", "V1.21", 0xab, 0xb3, {0x00, 0x08}, 0}, 2057438d990SPeter Feuerer /* Acer 521 */ 2067438d990SPeter Feuerer {"Acer", "AO521", "V1.11", 0x55, 0x58, {0x1f, 0x00}, 0}, 20724964639SPeter Feuerer /* Acer 531 */ 2085ef6578cSPeter Feuerer {"Acer", "AO531h", "v0.3104", 0x55, 0x58, {0x20, 0x00}, 0}, 2095ef6578cSPeter Feuerer {"Acer", "AO531h", "v0.3201", 0x55, 0x58, {0x20, 0x00}, 0}, 2105ef6578cSPeter Feuerer {"Acer", "AO531h", "v0.3304", 0x55, 0x58, {0x20, 0x00}, 0}, 21143ae1e32SPeter Feuerer /* Acer 751 */ 2127438d990SPeter Feuerer {"Acer", "AO751h", "V0.3206", 0x55, 0x58, {0x21, 0x00}, 0}, 2135ef6578cSPeter Feuerer {"Acer", "AO751h", "V0.3212", 0x55, 0x58, {0x21, 0x00}, 0}, 2147438d990SPeter Feuerer /* Acer 753 */ 2157438d990SPeter Feuerer {"Acer", "Aspire One 753", "V1.24", 0x93, 0xac, {0x14, 0x04}, 1}, 21643ae1e32SPeter Feuerer /* Acer 1825 */ 2175ef6578cSPeter Feuerer {"Acer", "Aspire 1825PTZ", "V1.3118", 0x55, 0x58, {0x9e, 0x00}, 0}, 2185ef6578cSPeter Feuerer {"Acer", "Aspire 1825PTZ", "V1.3127", 0x55, 0x58, {0x9e, 0x00}, 0}, 2197438d990SPeter Feuerer /* Acer Extensa 5420 */ 2207438d990SPeter Feuerer {"Acer", "Extensa 5420", "V1.17", 0x93, 0xac, {0x14, 0x04}, 1}, 2217438d990SPeter Feuerer /* Acer Aspire 5315 */ 2227438d990SPeter Feuerer {"Acer", "Aspire 5315", "V1.19", 0x93, 0xac, {0x14, 0x04}, 1}, 2237438d990SPeter Feuerer /* Acer Aspire 5739 */ 2247438d990SPeter Feuerer {"Acer", "Aspire 5739G", "V1.3311", 0x55, 0x58, {0x20, 0x00}, 0}, 22543ae1e32SPeter Feuerer /* Acer TravelMate 7730 */ 2265ef6578cSPeter Feuerer {"Acer", "TravelMate 7730G", "v0.3509", 0x55, 0x58, {0xaf, 0x00}, 0}, 2277438d990SPeter Feuerer /* Acer TravelMate TM8573T */ 2287438d990SPeter Feuerer {"Acer", "TM8573T", "V1.13", 0x93, 0xa8, {0x14, 0x04}, 1}, 22994219d79SPeter Feuerer /* Gateway */ 2305ef6578cSPeter Feuerer {"Gateway", "AOA110", "v0.3103", 0x55, 0x58, {0x21, 0x00}, 0}, 2315ef6578cSPeter Feuerer {"Gateway", "AOA150", "v0.3103", 0x55, 0x58, {0x20, 0x00}, 0}, 2325ef6578cSPeter Feuerer {"Gateway", "LT31", "v1.3103", 0x55, 0x58, {0x9e, 0x00}, 0}, 2335ef6578cSPeter Feuerer {"Gateway", "LT31", "v1.3201", 0x55, 0x58, {0x9e, 0x00}, 0}, 2345ef6578cSPeter Feuerer {"Gateway", "LT31", "v1.3302", 0x55, 0x58, {0x9e, 0x00}, 0}, 2355ef6578cSPeter Feuerer {"Gateway", "LT31", "v1.3303t", 0x55, 0x58, {0x9e, 0x00}, 0}, 23694219d79SPeter Feuerer /* Packard Bell */ 2375ef6578cSPeter Feuerer {"Packard Bell", "DOA150", "v0.3104", 0x55, 0x58, {0x21, 0x00}, 0}, 2385ef6578cSPeter Feuerer {"Packard Bell", "DOA150", "v0.3105", 0x55, 0x58, {0x20, 0x00}, 0}, 2395ef6578cSPeter Feuerer {"Packard Bell", "AOA110", "v0.3105", 0x55, 0x58, {0x21, 0x00}, 0}, 2405ef6578cSPeter Feuerer {"Packard Bell", "AOA150", "v0.3105", 0x55, 0x58, {0x20, 0x00}, 0}, 2415ef6578cSPeter Feuerer {"Packard Bell", "ENBFT", "V1.3118", 0x55, 0x58, {0x9e, 0x00}, 0}, 2425ef6578cSPeter Feuerer {"Packard Bell", "ENBFT", "V1.3127", 0x55, 0x58, {0x9e, 0x00}, 0}, 2435ef6578cSPeter Feuerer {"Packard Bell", "DOTMU", "v1.3303", 0x55, 0x58, {0x9e, 0x00}, 0}, 2445ef6578cSPeter Feuerer {"Packard Bell", "DOTMU", "v0.3120", 0x55, 0x58, {0x9e, 0x00}, 0}, 2455ef6578cSPeter Feuerer {"Packard Bell", "DOTMU", "v0.3108", 0x55, 0x58, {0x9e, 0x00}, 0}, 2465ef6578cSPeter Feuerer {"Packard Bell", "DOTMU", "v0.3113", 0x55, 0x58, {0x9e, 0x00}, 0}, 2475ef6578cSPeter Feuerer {"Packard Bell", "DOTMU", "v0.3115", 0x55, 0x58, {0x9e, 0x00}, 0}, 2485ef6578cSPeter Feuerer {"Packard Bell", "DOTMU", "v0.3117", 0x55, 0x58, {0x9e, 0x00}, 0}, 2495ef6578cSPeter Feuerer {"Packard Bell", "DOTMU", "v0.3119", 0x55, 0x58, {0x9e, 0x00}, 0}, 2505ef6578cSPeter Feuerer {"Packard Bell", "DOTMU", "v1.3204", 0x55, 0x58, {0x9e, 0x00}, 0}, 2515ef6578cSPeter Feuerer {"Packard Bell", "DOTMA", "v1.3201", 0x55, 0x58, {0x9e, 0x00}, 0}, 2525ef6578cSPeter Feuerer {"Packard Bell", "DOTMA", "v1.3302", 0x55, 0x58, {0x9e, 0x00}, 0}, 2535ef6578cSPeter Feuerer {"Packard Bell", "DOTMA", "v1.3303t", 0x55, 0x58, {0x9e, 0x00}, 0}, 2545ef6578cSPeter Feuerer {"Packard Bell", "DOTVR46", "v1.3308", 0x55, 0x58, {0x9e, 0x00}, 0}, 255ded0cdfcSPeter Feuerer /* pewpew-terminator */ 2565ef6578cSPeter Feuerer {"", "", "", 0, 0, {0, 0}, 0} 257e86435ebSPeter Feuerer }; 258e86435ebSPeter Feuerer 259e86435ebSPeter Feuerer static const struct bios_settings_t *bios_cfg __read_mostly; 260e86435ebSPeter Feuerer 26148c8dd64SPeter Feuerer /* 26248c8dd64SPeter Feuerer * this struct is used to instruct thermal layer to use bang_bang instead of 26348c8dd64SPeter Feuerer * default governor for acerhdf 26448c8dd64SPeter Feuerer */ 26548c8dd64SPeter Feuerer static struct thermal_zone_params acerhdf_zone_params = { 26648c8dd64SPeter Feuerer .governor_name = "bang_bang", 26748c8dd64SPeter Feuerer }; 26848c8dd64SPeter Feuerer 269e86435ebSPeter Feuerer static int acerhdf_get_temp(int *temp) 270e86435ebSPeter Feuerer { 271e86435ebSPeter Feuerer u8 read_temp; 272e86435ebSPeter Feuerer 273e86435ebSPeter Feuerer if (ec_read(bios_cfg->tempreg, &read_temp)) 274e86435ebSPeter Feuerer return -EINVAL; 275e86435ebSPeter Feuerer 27670052917SPeter Feuerer *temp = read_temp * 1000; 277e86435ebSPeter Feuerer 278e86435ebSPeter Feuerer return 0; 279e86435ebSPeter Feuerer } 280e86435ebSPeter Feuerer 281e86435ebSPeter Feuerer static int acerhdf_get_fanstate(int *state) 282e86435ebSPeter Feuerer { 283e86435ebSPeter Feuerer u8 fan; 284e86435ebSPeter Feuerer 285e86435ebSPeter Feuerer if (ec_read(bios_cfg->fanreg, &fan)) 286e86435ebSPeter Feuerer return -EINVAL; 287e86435ebSPeter Feuerer 288210183d4SPeter Feuerer if (fan != bios_cfg->cmd.cmd_off) 289ded0cdfcSPeter Feuerer *state = ACERHDF_FAN_AUTO; 290ded0cdfcSPeter Feuerer else 291ded0cdfcSPeter Feuerer *state = ACERHDF_FAN_OFF; 292e86435ebSPeter Feuerer 293e86435ebSPeter Feuerer return 0; 294e86435ebSPeter Feuerer } 295e86435ebSPeter Feuerer 296e86435ebSPeter Feuerer static void acerhdf_change_fanstate(int state) 297e86435ebSPeter Feuerer { 298e86435ebSPeter Feuerer unsigned char cmd; 299e86435ebSPeter Feuerer 300e86435ebSPeter Feuerer if (verbose) 301eecc5bbcSJoe Perches pr_notice("fan %s\n", state == ACERHDF_FAN_OFF ? "OFF" : "ON"); 302e86435ebSPeter Feuerer 303e86435ebSPeter Feuerer if ((state != ACERHDF_FAN_OFF) && (state != ACERHDF_FAN_AUTO)) { 304e86435ebSPeter Feuerer pr_err("invalid fan state %d requested, setting to auto!\n", 305e86435ebSPeter Feuerer state); 306e86435ebSPeter Feuerer state = ACERHDF_FAN_AUTO; 307e86435ebSPeter Feuerer } 308e86435ebSPeter Feuerer 309ded0cdfcSPeter Feuerer cmd = (state == ACERHDF_FAN_OFF) ? bios_cfg->cmd.cmd_off 310ded0cdfcSPeter Feuerer : bios_cfg->cmd.cmd_auto; 311e86435ebSPeter Feuerer fanstate = state; 312e86435ebSPeter Feuerer 313e86435ebSPeter Feuerer ec_write(bios_cfg->fanreg, cmd); 3145ef6578cSPeter Feuerer 3155ef6578cSPeter Feuerer if (bios_cfg->mcmd_enable && state == ACERHDF_FAN_OFF) { 3165ef6578cSPeter Feuerer if (verbose) 3175ef6578cSPeter Feuerer pr_notice("turning off fan manually\n"); 3185ef6578cSPeter Feuerer ec_write(mcmd.mreg, mcmd.moff); 3195ef6578cSPeter Feuerer } 320e86435ebSPeter Feuerer } 321e86435ebSPeter Feuerer 322e86435ebSPeter Feuerer static void acerhdf_check_param(struct thermal_zone_device *thermal) 323e86435ebSPeter Feuerer { 324e86435ebSPeter Feuerer if (fanon > ACERHDF_MAX_FANON) { 325e86435ebSPeter Feuerer pr_err("fanon temperature too high, set to %d\n", 326e86435ebSPeter Feuerer ACERHDF_MAX_FANON); 327e86435ebSPeter Feuerer fanon = ACERHDF_MAX_FANON; 328e86435ebSPeter Feuerer } 329e86435ebSPeter Feuerer 330e86435ebSPeter Feuerer if (kernelmode && prev_interval != interval) { 331e86435ebSPeter Feuerer if (interval > ACERHDF_MAX_INTERVAL) { 332e86435ebSPeter Feuerer pr_err("interval too high, set to %d\n", 333e86435ebSPeter Feuerer ACERHDF_MAX_INTERVAL); 334e86435ebSPeter Feuerer interval = ACERHDF_MAX_INTERVAL; 335e86435ebSPeter Feuerer } 336e86435ebSPeter Feuerer if (verbose) 337eecc5bbcSJoe Perches pr_notice("interval changed to: %d\n", interval); 338e86435ebSPeter Feuerer thermal->polling_delay = interval*1000; 339e86435ebSPeter Feuerer prev_interval = interval; 340e86435ebSPeter Feuerer } 341e86435ebSPeter Feuerer } 342e86435ebSPeter Feuerer 343e86435ebSPeter Feuerer /* 344e86435ebSPeter Feuerer * This is the thermal zone callback which does the delayed polling of the fan 345e86435ebSPeter Feuerer * state. We do check /sysfs-originating settings here in acerhdf_check_param() 346e86435ebSPeter Feuerer * as late as the polling interval is since we can't do that in the respective 347e86435ebSPeter Feuerer * accessors of the module parameters. 348e86435ebSPeter Feuerer */ 349e86435ebSPeter Feuerer static int acerhdf_get_ec_temp(struct thermal_zone_device *thermal, 350e86435ebSPeter Feuerer unsigned long *t) 351e86435ebSPeter Feuerer { 352e86435ebSPeter Feuerer int temp, err = 0; 353e86435ebSPeter Feuerer 354e86435ebSPeter Feuerer acerhdf_check_param(thermal); 355e86435ebSPeter Feuerer 356e86435ebSPeter Feuerer err = acerhdf_get_temp(&temp); 357e86435ebSPeter Feuerer if (err) 358e86435ebSPeter Feuerer return err; 359e86435ebSPeter Feuerer 360e86435ebSPeter Feuerer if (verbose) 361e86435ebSPeter Feuerer pr_notice("temp %d\n", temp); 362e86435ebSPeter Feuerer 363e86435ebSPeter Feuerer *t = temp; 364e86435ebSPeter Feuerer return 0; 365e86435ebSPeter Feuerer } 366e86435ebSPeter Feuerer 367e86435ebSPeter Feuerer static int acerhdf_bind(struct thermal_zone_device *thermal, 368e86435ebSPeter Feuerer struct thermal_cooling_device *cdev) 369e86435ebSPeter Feuerer { 370e86435ebSPeter Feuerer /* if the cooling device is the one from acerhdf bind it */ 371e86435ebSPeter Feuerer if (cdev != cl_dev) 372e86435ebSPeter Feuerer return 0; 373e86435ebSPeter Feuerer 3749d99842fSZhang Rui if (thermal_zone_bind_cooling_device(thermal, 0, cdev, 3759d99842fSZhang Rui THERMAL_NO_LIMIT, THERMAL_NO_LIMIT)) { 376e86435ebSPeter Feuerer pr_err("error binding cooling dev\n"); 377e86435ebSPeter Feuerer return -EINVAL; 378e86435ebSPeter Feuerer } 379e86435ebSPeter Feuerer return 0; 380e86435ebSPeter Feuerer } 381e86435ebSPeter Feuerer 382e86435ebSPeter Feuerer static int acerhdf_unbind(struct thermal_zone_device *thermal, 383e86435ebSPeter Feuerer struct thermal_cooling_device *cdev) 384e86435ebSPeter Feuerer { 385e86435ebSPeter Feuerer if (cdev != cl_dev) 386e86435ebSPeter Feuerer return 0; 387e86435ebSPeter Feuerer 388e86435ebSPeter Feuerer if (thermal_zone_unbind_cooling_device(thermal, 0, cdev)) { 389e86435ebSPeter Feuerer pr_err("error unbinding cooling dev\n"); 390e86435ebSPeter Feuerer return -EINVAL; 391e86435ebSPeter Feuerer } 392e86435ebSPeter Feuerer return 0; 393e86435ebSPeter Feuerer } 394e86435ebSPeter Feuerer 395e86435ebSPeter Feuerer static inline void acerhdf_revert_to_bios_mode(void) 396e86435ebSPeter Feuerer { 397e86435ebSPeter Feuerer acerhdf_change_fanstate(ACERHDF_FAN_AUTO); 398e86435ebSPeter Feuerer kernelmode = 0; 399e86435ebSPeter Feuerer if (thz_dev) 400e86435ebSPeter Feuerer thz_dev->polling_delay = 0; 401e86435ebSPeter Feuerer pr_notice("kernel mode fan control OFF\n"); 402e86435ebSPeter Feuerer } 403e86435ebSPeter Feuerer static inline void acerhdf_enable_kernelmode(void) 404e86435ebSPeter Feuerer { 405e86435ebSPeter Feuerer kernelmode = 1; 406e86435ebSPeter Feuerer 407e86435ebSPeter Feuerer thz_dev->polling_delay = interval*1000; 408e86435ebSPeter Feuerer thermal_zone_device_update(thz_dev); 409e86435ebSPeter Feuerer pr_notice("kernel mode fan control ON\n"); 410e86435ebSPeter Feuerer } 411e86435ebSPeter Feuerer 412e86435ebSPeter Feuerer static int acerhdf_get_mode(struct thermal_zone_device *thermal, 413e86435ebSPeter Feuerer enum thermal_device_mode *mode) 414e86435ebSPeter Feuerer { 415e86435ebSPeter Feuerer if (verbose) 416e86435ebSPeter Feuerer pr_notice("kernel mode fan control %d\n", kernelmode); 417e86435ebSPeter Feuerer 418e86435ebSPeter Feuerer *mode = (kernelmode) ? THERMAL_DEVICE_ENABLED 419e86435ebSPeter Feuerer : THERMAL_DEVICE_DISABLED; 420e86435ebSPeter Feuerer 421e86435ebSPeter Feuerer return 0; 422e86435ebSPeter Feuerer } 423e86435ebSPeter Feuerer 424e86435ebSPeter Feuerer /* 425e86435ebSPeter Feuerer * set operation mode; 426e86435ebSPeter Feuerer * enabled: the thermal layer of the kernel takes care about 427e86435ebSPeter Feuerer * the temperature and the fan. 428e86435ebSPeter Feuerer * disabled: the BIOS takes control of the fan. 429e86435ebSPeter Feuerer */ 430e86435ebSPeter Feuerer static int acerhdf_set_mode(struct thermal_zone_device *thermal, 431e86435ebSPeter Feuerer enum thermal_device_mode mode) 432e86435ebSPeter Feuerer { 433e86435ebSPeter Feuerer if (mode == THERMAL_DEVICE_DISABLED && kernelmode) 434e86435ebSPeter Feuerer acerhdf_revert_to_bios_mode(); 435e86435ebSPeter Feuerer else if (mode == THERMAL_DEVICE_ENABLED && !kernelmode) 436e86435ebSPeter Feuerer acerhdf_enable_kernelmode(); 437e86435ebSPeter Feuerer 438e86435ebSPeter Feuerer return 0; 439e86435ebSPeter Feuerer } 440e86435ebSPeter Feuerer 441e86435ebSPeter Feuerer static int acerhdf_get_trip_type(struct thermal_zone_device *thermal, int trip, 442e86435ebSPeter Feuerer enum thermal_trip_type *type) 443e86435ebSPeter Feuerer { 444e86435ebSPeter Feuerer if (trip == 0) 445e86435ebSPeter Feuerer *type = THERMAL_TRIP_ACTIVE; 4467e8b6d73SPeter Feuerer else if (trip == 1) 4477e8b6d73SPeter Feuerer *type = THERMAL_TRIP_CRITICAL; 4487e8b6d73SPeter Feuerer else 4497e8b6d73SPeter Feuerer return -EINVAL; 450e86435ebSPeter Feuerer 451e86435ebSPeter Feuerer return 0; 452e86435ebSPeter Feuerer } 453e86435ebSPeter Feuerer 45448c8dd64SPeter Feuerer static int acerhdf_get_trip_hyst(struct thermal_zone_device *thermal, int trip, 45548c8dd64SPeter Feuerer unsigned long *temp) 45648c8dd64SPeter Feuerer { 45748c8dd64SPeter Feuerer if (trip != 0) 45848c8dd64SPeter Feuerer return -EINVAL; 45948c8dd64SPeter Feuerer 46048c8dd64SPeter Feuerer *temp = fanon - fanoff; 46148c8dd64SPeter Feuerer 46248c8dd64SPeter Feuerer return 0; 46348c8dd64SPeter Feuerer } 46448c8dd64SPeter Feuerer 465e86435ebSPeter Feuerer static int acerhdf_get_trip_temp(struct thermal_zone_device *thermal, int trip, 466e86435ebSPeter Feuerer unsigned long *temp) 467e86435ebSPeter Feuerer { 468e86435ebSPeter Feuerer if (trip == 0) 469e86435ebSPeter Feuerer *temp = fanon; 4707e8b6d73SPeter Feuerer else if (trip == 1) 4717e8b6d73SPeter Feuerer *temp = ACERHDF_TEMP_CRIT; 4727e8b6d73SPeter Feuerer else 4737e8b6d73SPeter Feuerer return -EINVAL; 474e86435ebSPeter Feuerer 475e86435ebSPeter Feuerer return 0; 476e86435ebSPeter Feuerer } 477e86435ebSPeter Feuerer 478e86435ebSPeter Feuerer static int acerhdf_get_crit_temp(struct thermal_zone_device *thermal, 479e86435ebSPeter Feuerer unsigned long *temperature) 480e86435ebSPeter Feuerer { 481e86435ebSPeter Feuerer *temperature = ACERHDF_TEMP_CRIT; 482e86435ebSPeter Feuerer return 0; 483e86435ebSPeter Feuerer } 484e86435ebSPeter Feuerer 485e86435ebSPeter Feuerer /* bind callback functions to thermalzone */ 486fedae5adSAxel Lin static struct thermal_zone_device_ops acerhdf_dev_ops = { 487e86435ebSPeter Feuerer .bind = acerhdf_bind, 488e86435ebSPeter Feuerer .unbind = acerhdf_unbind, 489e86435ebSPeter Feuerer .get_temp = acerhdf_get_ec_temp, 490e86435ebSPeter Feuerer .get_mode = acerhdf_get_mode, 491e86435ebSPeter Feuerer .set_mode = acerhdf_set_mode, 492e86435ebSPeter Feuerer .get_trip_type = acerhdf_get_trip_type, 49348c8dd64SPeter Feuerer .get_trip_hyst = acerhdf_get_trip_hyst, 494e86435ebSPeter Feuerer .get_trip_temp = acerhdf_get_trip_temp, 495e86435ebSPeter Feuerer .get_crit_temp = acerhdf_get_crit_temp, 496e86435ebSPeter Feuerer }; 497e86435ebSPeter Feuerer 498e86435ebSPeter Feuerer 499e86435ebSPeter Feuerer /* 500e86435ebSPeter Feuerer * cooling device callback functions 501e86435ebSPeter Feuerer * get maximal fan cooling state 502e86435ebSPeter Feuerer */ 503e86435ebSPeter Feuerer static int acerhdf_get_max_state(struct thermal_cooling_device *cdev, 504e86435ebSPeter Feuerer unsigned long *state) 505e86435ebSPeter Feuerer { 506e86435ebSPeter Feuerer *state = 1; 507e86435ebSPeter Feuerer 508e86435ebSPeter Feuerer return 0; 509e86435ebSPeter Feuerer } 510e86435ebSPeter Feuerer 511e86435ebSPeter Feuerer static int acerhdf_get_cur_state(struct thermal_cooling_device *cdev, 512e86435ebSPeter Feuerer unsigned long *state) 513e86435ebSPeter Feuerer { 514e86435ebSPeter Feuerer int err = 0, tmp; 515e86435ebSPeter Feuerer 516e86435ebSPeter Feuerer err = acerhdf_get_fanstate(&tmp); 517e86435ebSPeter Feuerer if (err) 518e86435ebSPeter Feuerer return err; 519e86435ebSPeter Feuerer 520e86435ebSPeter Feuerer *state = (tmp == ACERHDF_FAN_AUTO) ? 1 : 0; 521e86435ebSPeter Feuerer return 0; 522e86435ebSPeter Feuerer } 523e86435ebSPeter Feuerer 524e86435ebSPeter Feuerer /* change current fan state - is overwritten when running in kernel mode */ 525e86435ebSPeter Feuerer static int acerhdf_set_cur_state(struct thermal_cooling_device *cdev, 526e86435ebSPeter Feuerer unsigned long state) 527e86435ebSPeter Feuerer { 528e86435ebSPeter Feuerer int cur_temp, cur_state, err = 0; 529e86435ebSPeter Feuerer 530e86435ebSPeter Feuerer if (!kernelmode) 531e86435ebSPeter Feuerer return 0; 532e86435ebSPeter Feuerer 533e86435ebSPeter Feuerer err = acerhdf_get_temp(&cur_temp); 534e86435ebSPeter Feuerer if (err) { 535e86435ebSPeter Feuerer pr_err("error reading temperature, hand off control to BIOS\n"); 536e86435ebSPeter Feuerer goto err_out; 537e86435ebSPeter Feuerer } 538e86435ebSPeter Feuerer 539e86435ebSPeter Feuerer err = acerhdf_get_fanstate(&cur_state); 540e86435ebSPeter Feuerer if (err) { 541e86435ebSPeter Feuerer pr_err("error reading fan state, hand off control to BIOS\n"); 542e86435ebSPeter Feuerer goto err_out; 543e86435ebSPeter Feuerer } 544e86435ebSPeter Feuerer 545e86435ebSPeter Feuerer if (state == 0) { 54648c8dd64SPeter Feuerer if (cur_state == ACERHDF_FAN_AUTO) 547e86435ebSPeter Feuerer acerhdf_change_fanstate(ACERHDF_FAN_OFF); 548e86435ebSPeter Feuerer } else { 549e86435ebSPeter Feuerer if (cur_state == ACERHDF_FAN_OFF) 550e86435ebSPeter Feuerer acerhdf_change_fanstate(ACERHDF_FAN_AUTO); 551e86435ebSPeter Feuerer } 552e86435ebSPeter Feuerer return 0; 553e86435ebSPeter Feuerer 554e86435ebSPeter Feuerer err_out: 555e86435ebSPeter Feuerer acerhdf_revert_to_bios_mode(); 556e86435ebSPeter Feuerer return -EINVAL; 557e86435ebSPeter Feuerer } 558e86435ebSPeter Feuerer 559e86435ebSPeter Feuerer /* bind fan callbacks to fan device */ 560fedae5adSAxel Lin static struct thermal_cooling_device_ops acerhdf_cooling_ops = { 561e86435ebSPeter Feuerer .get_max_state = acerhdf_get_max_state, 562e86435ebSPeter Feuerer .get_cur_state = acerhdf_get_cur_state, 563e86435ebSPeter Feuerer .set_cur_state = acerhdf_set_cur_state, 564e86435ebSPeter Feuerer }; 565e86435ebSPeter Feuerer 566e86435ebSPeter Feuerer /* suspend / resume functionality */ 567ff27e1f3SBorislav Petkov static int acerhdf_suspend(struct device *dev) 568e86435ebSPeter Feuerer { 569e86435ebSPeter Feuerer if (kernelmode) 570e86435ebSPeter Feuerer acerhdf_change_fanstate(ACERHDF_FAN_AUTO); 571e86435ebSPeter Feuerer 572e86435ebSPeter Feuerer if (verbose) 573e86435ebSPeter Feuerer pr_notice("going suspend\n"); 574e86435ebSPeter Feuerer 575e86435ebSPeter Feuerer return 0; 576e86435ebSPeter Feuerer } 577e86435ebSPeter Feuerer 578b859f159SGreg Kroah-Hartman static int acerhdf_probe(struct platform_device *device) 579e86435ebSPeter Feuerer { 580e86435ebSPeter Feuerer return 0; 581e86435ebSPeter Feuerer } 582e86435ebSPeter Feuerer 583e86435ebSPeter Feuerer static int acerhdf_remove(struct platform_device *device) 584e86435ebSPeter Feuerer { 585e86435ebSPeter Feuerer return 0; 586e86435ebSPeter Feuerer } 587e86435ebSPeter Feuerer 58847145210SAlexey Dobriyan static const struct dev_pm_ops acerhdf_pm_ops = { 589ff27e1f3SBorislav Petkov .suspend = acerhdf_suspend, 590ff27e1f3SBorislav Petkov .freeze = acerhdf_suspend, 591ff27e1f3SBorislav Petkov }; 592ff27e1f3SBorislav Petkov 593ded0cdfcSPeter Feuerer static struct platform_driver acerhdf_driver = { 594e86435ebSPeter Feuerer .driver = { 595e86435ebSPeter Feuerer .name = "acerhdf", 596e86435ebSPeter Feuerer .owner = THIS_MODULE, 597ff27e1f3SBorislav Petkov .pm = &acerhdf_pm_ops, 598e86435ebSPeter Feuerer }, 599e86435ebSPeter Feuerer .probe = acerhdf_probe, 600e86435ebSPeter Feuerer .remove = acerhdf_remove, 601e86435ebSPeter Feuerer }; 602e86435ebSPeter Feuerer 603dcbfb815SPeter Feuerer /* checks if str begins with start */ 604dcbfb815SPeter Feuerer static int str_starts_with(const char *str, const char *start) 605dcbfb815SPeter Feuerer { 606dcbfb815SPeter Feuerer unsigned long str_len = 0, start_len = 0; 607dcbfb815SPeter Feuerer 608dcbfb815SPeter Feuerer str_len = strlen(str); 609dcbfb815SPeter Feuerer start_len = strlen(start); 610dcbfb815SPeter Feuerer 611dcbfb815SPeter Feuerer if (str_len >= start_len && 612dcbfb815SPeter Feuerer !strncmp(str, start, start_len)) 613dcbfb815SPeter Feuerer return 1; 614dcbfb815SPeter Feuerer 615dcbfb815SPeter Feuerer return 0; 616dcbfb815SPeter Feuerer } 617e86435ebSPeter Feuerer 618e86435ebSPeter Feuerer /* check hardware */ 619e86435ebSPeter Feuerer static int acerhdf_check_hardware(void) 620e86435ebSPeter Feuerer { 621e86435ebSPeter Feuerer char const *vendor, *version, *product; 622dcbfb815SPeter Feuerer const struct bios_settings_t *bt = NULL; 623e86435ebSPeter Feuerer 624e86435ebSPeter Feuerer /* get BIOS data */ 625e86435ebSPeter Feuerer vendor = dmi_get_system_info(DMI_SYS_VENDOR); 626e86435ebSPeter Feuerer version = dmi_get_system_info(DMI_BIOS_VERSION); 627e86435ebSPeter Feuerer product = dmi_get_system_info(DMI_PRODUCT_NAME); 628e86435ebSPeter Feuerer 6295cf4c07aSRahul Chaturvedi if (!vendor || !version || !product) { 6305cf4c07aSRahul Chaturvedi pr_err("error getting hardware information\n"); 6315cf4c07aSRahul Chaturvedi return -EINVAL; 6325cf4c07aSRahul Chaturvedi } 633ded0cdfcSPeter Feuerer 634e86435ebSPeter Feuerer pr_info("Acer Aspire One Fan driver, v.%s\n", DRV_VER); 635e86435ebSPeter Feuerer 636ded0cdfcSPeter Feuerer if (force_bios[0]) { 637e86435ebSPeter Feuerer version = force_bios; 638ded0cdfcSPeter Feuerer pr_info("forcing BIOS version: %s\n", version); 639e86435ebSPeter Feuerer kernelmode = 0; 640e86435ebSPeter Feuerer } 641e86435ebSPeter Feuerer 642ded0cdfcSPeter Feuerer if (force_product[0]) { 643ded0cdfcSPeter Feuerer product = force_product; 644ded0cdfcSPeter Feuerer pr_info("forcing BIOS product: %s\n", product); 645ded0cdfcSPeter Feuerer kernelmode = 0; 646ded0cdfcSPeter Feuerer } 647ded0cdfcSPeter Feuerer 648e86435ebSPeter Feuerer if (verbose) 649e86435ebSPeter Feuerer pr_info("BIOS info: %s %s, product: %s\n", 650e86435ebSPeter Feuerer vendor, version, product); 651e86435ebSPeter Feuerer 652e86435ebSPeter Feuerer /* search BIOS version and vendor in BIOS settings table */ 653dcbfb815SPeter Feuerer for (bt = bios_tbl; bt->vendor[0]; bt++) { 654dcbfb815SPeter Feuerer /* 655dcbfb815SPeter Feuerer * check if actual hardware BIOS vendor, product and version 656dcbfb815SPeter Feuerer * IDs start with the strings of BIOS table entry 657dcbfb815SPeter Feuerer */ 658dcbfb815SPeter Feuerer if (str_starts_with(vendor, bt->vendor) && 659dcbfb815SPeter Feuerer str_starts_with(product, bt->product) && 660dcbfb815SPeter Feuerer str_starts_with(version, bt->version)) { 661dcbfb815SPeter Feuerer bios_cfg = bt; 662e86435ebSPeter Feuerer break; 663e86435ebSPeter Feuerer } 664e86435ebSPeter Feuerer } 665e86435ebSPeter Feuerer 666e86435ebSPeter Feuerer if (!bios_cfg) { 667eecc5bbcSJoe Perches pr_err("unknown (unsupported) BIOS version %s/%s/%s, please report, aborting!\n", 668eecc5bbcSJoe Perches vendor, product, version); 669e86435ebSPeter Feuerer return -EINVAL; 670e86435ebSPeter Feuerer } 671e86435ebSPeter Feuerer 672e86435ebSPeter Feuerer /* 673e86435ebSPeter Feuerer * if started with kernel mode off, prevent the kernel from switching 674e86435ebSPeter Feuerer * off the fan 675e86435ebSPeter Feuerer */ 676e86435ebSPeter Feuerer if (!kernelmode) { 677e86435ebSPeter Feuerer pr_notice("Fan control off, to enable do:\n"); 678eecc5bbcSJoe Perches pr_notice("echo -n \"enabled\" > /sys/class/thermal/thermal_zone0/mode\n"); 679e86435ebSPeter Feuerer } 680e86435ebSPeter Feuerer 681e86435ebSPeter Feuerer return 0; 682e86435ebSPeter Feuerer } 683e86435ebSPeter Feuerer 684e86435ebSPeter Feuerer static int acerhdf_register_platform(void) 685e86435ebSPeter Feuerer { 686e86435ebSPeter Feuerer int err = 0; 687e86435ebSPeter Feuerer 688ded0cdfcSPeter Feuerer err = platform_driver_register(&acerhdf_driver); 689e86435ebSPeter Feuerer if (err) 690e86435ebSPeter Feuerer return err; 691e86435ebSPeter Feuerer 692e86435ebSPeter Feuerer acerhdf_dev = platform_device_alloc("acerhdf", -1); 693a0dba697SAxel Lin if (!acerhdf_dev) { 694a0dba697SAxel Lin err = -ENOMEM; 695a0dba697SAxel Lin goto err_device_alloc; 696a0dba697SAxel Lin } 697a0dba697SAxel Lin err = platform_device_add(acerhdf_dev); 698a0dba697SAxel Lin if (err) 699a0dba697SAxel Lin goto err_device_add; 700e86435ebSPeter Feuerer 701e86435ebSPeter Feuerer return 0; 702a0dba697SAxel Lin 703a0dba697SAxel Lin err_device_add: 704a0dba697SAxel Lin platform_device_put(acerhdf_dev); 705a0dba697SAxel Lin err_device_alloc: 706a0dba697SAxel Lin platform_driver_unregister(&acerhdf_driver); 707a0dba697SAxel Lin return err; 708e86435ebSPeter Feuerer } 709e86435ebSPeter Feuerer 710e86435ebSPeter Feuerer static void acerhdf_unregister_platform(void) 711e86435ebSPeter Feuerer { 712a0dba697SAxel Lin platform_device_unregister(acerhdf_dev); 713ded0cdfcSPeter Feuerer platform_driver_unregister(&acerhdf_driver); 714e86435ebSPeter Feuerer } 715e86435ebSPeter Feuerer 716e86435ebSPeter Feuerer static int acerhdf_register_thermal(void) 717e86435ebSPeter Feuerer { 718e86435ebSPeter Feuerer cl_dev = thermal_cooling_device_register("acerhdf-fan", NULL, 719e86435ebSPeter Feuerer &acerhdf_cooling_ops); 720e86435ebSPeter Feuerer 721e86435ebSPeter Feuerer if (IS_ERR(cl_dev)) 722e86435ebSPeter Feuerer return -EINVAL; 723e86435ebSPeter Feuerer 7247e8b6d73SPeter Feuerer thz_dev = thermal_zone_device_register("acerhdf", 2, 0, NULL, 72548c8dd64SPeter Feuerer &acerhdf_dev_ops, 72648c8dd64SPeter Feuerer &acerhdf_zone_params, 0, 727e86435ebSPeter Feuerer (kernelmode) ? interval*1000 : 0); 728e86435ebSPeter Feuerer if (IS_ERR(thz_dev)) 729e86435ebSPeter Feuerer return -EINVAL; 730e86435ebSPeter Feuerer 73148c8dd64SPeter Feuerer if (strcmp(thz_dev->governor->name, 73248c8dd64SPeter Feuerer acerhdf_zone_params.governor_name)) { 73348c8dd64SPeter Feuerer pr_err("Didn't get thermal governor %s, perhaps not compiled into thermal subsystem.\n", 73448c8dd64SPeter Feuerer acerhdf_zone_params.governor_name); 73548c8dd64SPeter Feuerer return -EINVAL; 73648c8dd64SPeter Feuerer } 73748c8dd64SPeter Feuerer 738e86435ebSPeter Feuerer return 0; 739e86435ebSPeter Feuerer } 740e86435ebSPeter Feuerer 741e86435ebSPeter Feuerer static void acerhdf_unregister_thermal(void) 742e86435ebSPeter Feuerer { 743e86435ebSPeter Feuerer if (cl_dev) { 744e86435ebSPeter Feuerer thermal_cooling_device_unregister(cl_dev); 745e86435ebSPeter Feuerer cl_dev = NULL; 746e86435ebSPeter Feuerer } 747e86435ebSPeter Feuerer 748e86435ebSPeter Feuerer if (thz_dev) { 749e86435ebSPeter Feuerer thermal_zone_device_unregister(thz_dev); 750e86435ebSPeter Feuerer thz_dev = NULL; 751e86435ebSPeter Feuerer } 752e86435ebSPeter Feuerer } 753e86435ebSPeter Feuerer 754e86435ebSPeter Feuerer static int __init acerhdf_init(void) 755e86435ebSPeter Feuerer { 756e86435ebSPeter Feuerer int err = 0; 757e86435ebSPeter Feuerer 758e86435ebSPeter Feuerer err = acerhdf_check_hardware(); 759e86435ebSPeter Feuerer if (err) 760e86435ebSPeter Feuerer goto out_err; 761e86435ebSPeter Feuerer 762e86435ebSPeter Feuerer err = acerhdf_register_platform(); 763e86435ebSPeter Feuerer if (err) 764a0dba697SAxel Lin goto out_err; 765e86435ebSPeter Feuerer 766e86435ebSPeter Feuerer err = acerhdf_register_thermal(); 767e86435ebSPeter Feuerer if (err) 768e86435ebSPeter Feuerer goto err_unreg; 769e86435ebSPeter Feuerer 770e86435ebSPeter Feuerer return 0; 771e86435ebSPeter Feuerer 772e86435ebSPeter Feuerer err_unreg: 773e86435ebSPeter Feuerer acerhdf_unregister_thermal(); 774e86435ebSPeter Feuerer acerhdf_unregister_platform(); 775e86435ebSPeter Feuerer 776e86435ebSPeter Feuerer out_err: 777a0dba697SAxel Lin return err; 778e86435ebSPeter Feuerer } 779e86435ebSPeter Feuerer 780e86435ebSPeter Feuerer static void __exit acerhdf_exit(void) 781e86435ebSPeter Feuerer { 782e86435ebSPeter Feuerer acerhdf_change_fanstate(ACERHDF_FAN_AUTO); 783e86435ebSPeter Feuerer acerhdf_unregister_thermal(); 784e86435ebSPeter Feuerer acerhdf_unregister_platform(); 785e86435ebSPeter Feuerer } 786e86435ebSPeter Feuerer 787e86435ebSPeter Feuerer MODULE_LICENSE("GPL"); 788e86435ebSPeter Feuerer MODULE_AUTHOR("Peter Feuerer"); 789e86435ebSPeter Feuerer MODULE_DESCRIPTION("Aspire One temperature and fan driver"); 790bdc731bcSStefan Bader MODULE_ALIAS("dmi:*:*Acer*:pnAOA*:"); 79143ae1e32SPeter Feuerer MODULE_ALIAS("dmi:*:*Acer*:pnAO751h*:"); 7922c3422d9SAnton V. Boyarshinov MODULE_ALIAS("dmi:*:*Acer*:pnAspire*1410*:"); 7932c3422d9SAnton V. Boyarshinov MODULE_ALIAS("dmi:*:*Acer*:pnAspire*1810*:"); 7947438d990SPeter Feuerer MODULE_ALIAS("dmi:*:*Acer*:pnAspire*5755G:"); 79543ae1e32SPeter Feuerer MODULE_ALIAS("dmi:*:*Acer*:pnAspire*1825PTZ:"); 7967438d990SPeter Feuerer MODULE_ALIAS("dmi:*:*Acer*:pnAO521*:"); 79724964639SPeter Feuerer MODULE_ALIAS("dmi:*:*Acer*:pnAO531*:"); 7987438d990SPeter Feuerer MODULE_ALIAS("dmi:*:*Acer*:pnAspire*5739G:"); 7997438d990SPeter Feuerer MODULE_ALIAS("dmi:*:*Acer*:pnAspire*One*753:"); 8007438d990SPeter Feuerer MODULE_ALIAS("dmi:*:*Acer*:pnAspire*5315:"); 80143ae1e32SPeter Feuerer MODULE_ALIAS("dmi:*:*Acer*:TravelMate*7730G:"); 8027438d990SPeter Feuerer MODULE_ALIAS("dmi:*:*Acer*:TM8573T:"); 803bdc731bcSStefan Bader MODULE_ALIAS("dmi:*:*Gateway*:pnAOA*:"); 80494219d79SPeter Feuerer MODULE_ALIAS("dmi:*:*Gateway*:pnLT31*:"); 8052c3422d9SAnton V. Boyarshinov MODULE_ALIAS("dmi:*:*Packard*Bell*:pnAOA*:"); 8062c3422d9SAnton V. Boyarshinov MODULE_ALIAS("dmi:*:*Packard*Bell*:pnDOA*:"); 8072c3422d9SAnton V. Boyarshinov MODULE_ALIAS("dmi:*:*Packard*Bell*:pnDOTMU*:"); 80843ae1e32SPeter Feuerer MODULE_ALIAS("dmi:*:*Packard*Bell*:pnENBFT*:"); 8092c3422d9SAnton V. Boyarshinov MODULE_ALIAS("dmi:*:*Packard*Bell*:pnDOTMA*:"); 81043ae1e32SPeter Feuerer MODULE_ALIAS("dmi:*:*Packard*Bell*:pnDOTVR46*:"); 8117438d990SPeter Feuerer MODULE_ALIAS("dmi:*:*Acer*:pnExtensa 5420*:"); 812e86435ebSPeter Feuerer 813e86435ebSPeter Feuerer module_init(acerhdf_init); 814e86435ebSPeter Feuerer module_exit(acerhdf_exit); 815