Edward O'Callaghan | 3628f93 | 2014-05-21 07:00:48 +1000 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2007-2009 coresystems GmbH |
| 5 | * Copyright (C) 2014 Edward O'Callaghan <eocallaghan@alterapraxis.com> |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; version 2 of the License. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
Edward O'Callaghan | 3628f93 | 2014-05-21 07:00:48 +1000 | [diff] [blame] | 15 | */ |
| 16 | |
| 17 | #include <types.h> |
| 18 | #include <arch/io.h> |
| 19 | #include <console/console.h> |
| 20 | #include <device/device.h> |
| 21 | #include <pc80/mc146818rtc.h> |
| 22 | |
| 23 | #include "superio_hwm.h" |
| 24 | |
| 25 | /* Hardware Monitor */ |
| 26 | |
| 27 | #define FAN_CRUISE_CONTROL_DISABLED 0 |
| 28 | #define FAN_CRUISE_CONTROL_SPEED 1 |
| 29 | #define FAN_CRUISE_CONTROL_THERMAL 2 |
| 30 | |
| 31 | #define FAN_SPEED_5625 0 |
| 32 | //#define FAN_TEMPERATURE_30DEGC 0 |
| 33 | |
| 34 | #define HWM_BASE 0x290 |
| 35 | |
| 36 | static void hwm_write(u8 reg, u8 value) |
| 37 | { |
| 38 | outb(reg, HWM_BASE + 0x05); |
| 39 | outb(value, HWM_BASE + 0x06); |
| 40 | } |
| 41 | |
| 42 | static void hwm_bank(u8 bank) |
| 43 | { |
| 44 | hwm_write(0x4e, bank); |
| 45 | } |
| 46 | |
| 47 | struct fan_speed { |
| 48 | u8 fan_in; |
| 49 | u16 fan_speed; |
| 50 | }; |
| 51 | |
| 52 | // FANIN Target Speed Register |
| 53 | // FANIN = 337500 / RPM |
| 54 | struct fan_speed fan_speeds[] = { |
| 55 | { 0x3c, 5625 }, { 0x41, 5192 }, { 0x47, 4753 }, { 0x4e, 4326 }, |
| 56 | { 0x56, 3924 }, { 0x5f, 3552 }, { 0x69, 3214 }, { 0x74, 2909 }, |
| 57 | { 0x80, 2636 }, { 0x8d, 2393 }, { 0x9b, 2177 }, { 0xaa, 1985 }, |
| 58 | { 0xba, 1814 }, { 0xcb, 1662 }, { 0xdd, 1527 }, { 0xf0, 1406 } |
| 59 | }; |
| 60 | |
| 61 | struct temperature { |
| 62 | u8 deg_celsius; |
| 63 | u8 deg_fahrenheit; |
| 64 | }; |
| 65 | |
| 66 | struct temperature temperatures[] = { |
| 67 | { 30, 86 }, { 33, 91 }, { 36, 96 }, { 39, 102 }, |
| 68 | { 42, 107 }, { 45, 113 }, { 48, 118 }, { 51, 123 }, |
| 69 | { 54, 129 }, { 57, 134 }, { 60, 140 }, { 63, 145 }, |
| 70 | { 66, 150 }, { 69, 156 }, { 72, 161 }, { 75, 167 } |
| 71 | }; |
| 72 | |
| 73 | void hwm_setup(void) |
| 74 | { |
| 75 | int cpufan_control = 0, sysfan_control = 0; |
| 76 | int cpufan_speed = 0, sysfan_speed = 0; |
| 77 | int cpufan_temperature = 0, sysfan_temperature = 0; |
| 78 | |
Varad Gautam | 06ef046 | 2015-03-11 09:54:41 +0530 | [diff] [blame] | 79 | cpufan_control = FAN_CRUISE_CONTROL_DISABLED; |
| 80 | get_option(&cpufan_control, "cpufan_cruise_control"); |
| 81 | cpufan_speed = FAN_SPEED_5625; |
| 82 | get_option(&cpufan_speed, "cpufan_speed"); |
| 83 | //cpufan_temperature = FAN_TEMPERATURE_30DEGC; |
| 84 | //get_option(&cpufan_temperature, "cpufan_temperature"); |
Edward O'Callaghan | 3628f93 | 2014-05-21 07:00:48 +1000 | [diff] [blame] | 85 | |
Varad Gautam | 06ef046 | 2015-03-11 09:54:41 +0530 | [diff] [blame] | 86 | sysfan_control = FAN_CRUISE_CONTROL_DISABLED; |
| 87 | get_option(&sysfan_control, "sysfan_cruise_control"); |
| 88 | sysfan_speed = FAN_SPEED_5625; |
| 89 | get_option(&sysfan_speed, "sysfan_speed"); |
| 90 | //sysfan_temperature = FAN_TEMPERATURE_30DEGC; |
| 91 | //get_option(&sysfan_temperature, "sysfan_temperature"); |
Edward O'Callaghan | 3628f93 | 2014-05-21 07:00:48 +1000 | [diff] [blame] | 92 | |
| 93 | // hwm_write(0x31, 0x20); // AVCC high limit |
| 94 | // hwm_write(0x34, 0x06); // VIN2 low limit |
| 95 | |
| 96 | hwm_bank(0); |
| 97 | hwm_write(0x59, 0x20); // Diode Selection |
| 98 | hwm_write(0x5d, 0x0f); // All Sensors Diode, not Thermistor |
| 99 | |
| 100 | hwm_bank(4); |
| 101 | hwm_write(0x54, 0xf1); // SYSTIN temperature offset |
| 102 | hwm_write(0x55, 0x19); // CPUTIN temperature offset |
| 103 | hwm_write(0x56, 0xfc); // AUXTIN temperature offset |
| 104 | |
| 105 | hwm_bank(0x80); // Default |
| 106 | |
| 107 | u8 fan_config = 0; |
| 108 | // 00 FANOUT is Manual Mode |
| 109 | // 01 FANOUT is Thermal Cruise Mode |
| 110 | // 10 FANOUT is Fan Speed Cruise Mode |
| 111 | switch (cpufan_control) { |
| 112 | case FAN_CRUISE_CONTROL_SPEED: fan_config |= (2 << 4); break; |
| 113 | case FAN_CRUISE_CONTROL_THERMAL: fan_config |= (1 << 4); break; |
| 114 | } |
| 115 | switch (sysfan_control) { |
| 116 | case FAN_CRUISE_CONTROL_SPEED: fan_config |= (2 << 2); break; |
| 117 | case FAN_CRUISE_CONTROL_THERMAL: fan_config |= (1 << 2); break; |
| 118 | } |
| 119 | // This register must be written first |
| 120 | hwm_write(0x04, fan_config); |
| 121 | |
| 122 | switch (cpufan_control) { |
| 123 | case FAN_CRUISE_CONTROL_SPEED: |
| 124 | printk(BIOS_DEBUG, "Fan Cruise Control setting CPU fan to %d RPM\n", |
| 125 | fan_speeds[cpufan_speed].fan_speed); |
| 126 | hwm_write(0x06, fan_speeds[cpufan_speed].fan_in); // CPUFANIN target speed |
| 127 | break; |
| 128 | case FAN_CRUISE_CONTROL_THERMAL: |
| 129 | printk(BIOS_DEBUG, "Fan Cruise Control setting CPU fan to activation at %d deg C/%d deg F\n", |
| 130 | temperatures[cpufan_temperature].deg_celsius, |
| 131 | temperatures[cpufan_temperature].deg_fahrenheit); |
| 132 | hwm_write(0x06, temperatures[cpufan_temperature].deg_celsius); // CPUFANIN target temperature |
| 133 | break; |
| 134 | } |
| 135 | |
| 136 | switch (sysfan_control) { |
| 137 | case FAN_CRUISE_CONTROL_SPEED: |
| 138 | printk(BIOS_DEBUG, "Fan Cruise Control setting system fan to %d RPM\n", |
| 139 | fan_speeds[sysfan_speed].fan_speed); |
| 140 | hwm_write(0x05, fan_speeds[sysfan_speed].fan_in); // SYSFANIN target speed |
| 141 | break; |
| 142 | case FAN_CRUISE_CONTROL_THERMAL: |
| 143 | printk(BIOS_DEBUG, "Fan Cruise Control setting system fan to activation at %d deg C/%d deg F\n", |
| 144 | temperatures[sysfan_temperature].deg_celsius, |
| 145 | temperatures[sysfan_temperature].deg_fahrenheit); |
| 146 | hwm_write(0x05, temperatures[sysfan_temperature].deg_celsius); // SYSFANIN target temperature |
| 147 | break; |
| 148 | } |
| 149 | |
| 150 | hwm_write(0x0e, 0x02); // Fan Output Step Down Time |
| 151 | hwm_write(0x0f, 0x02); // Fan Output Step Up Time |
| 152 | |
| 153 | hwm_write(0x47, 0xaf); // FAN divisor register |
| 154 | hwm_write(0x4b, 0x84); // AUXFANIN speed divisor |
| 155 | |
| 156 | hwm_write(0x40, 0x01); // Init, but no SMI# |
| 157 | } |