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