blob: 7864264d41fe7b791480661b6d872bb943ca709e [file] [log] [blame]
Edward O'Callaghan3628f932014-05-21 07:00:48 +10001/*
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.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21#include <types.h>
22#include <arch/io.h>
23#include <console/console.h>
24#include <device/device.h>
25#include <pc80/mc146818rtc.h>
26
27#include "superio_hwm.h"
28
29/* Hardware Monitor */
30
31#define FAN_CRUISE_CONTROL_DISABLED 0
32#define FAN_CRUISE_CONTROL_SPEED 1
33#define FAN_CRUISE_CONTROL_THERMAL 2
34
35#define FAN_SPEED_5625 0
36//#define FAN_TEMPERATURE_30DEGC 0
37
38#define HWM_BASE 0x290
39
40static void hwm_write(u8 reg, u8 value)
41{
42 outb(reg, HWM_BASE + 0x05);
43 outb(value, HWM_BASE + 0x06);
44}
45
46static void hwm_bank(u8 bank)
47{
48 hwm_write(0x4e, bank);
49}
50
51struct fan_speed {
52 u8 fan_in;
53 u16 fan_speed;
54};
55
56// FANIN Target Speed Register
57// FANIN = 337500 / RPM
58struct fan_speed fan_speeds[] = {
59 { 0x3c, 5625 }, { 0x41, 5192 }, { 0x47, 4753 }, { 0x4e, 4326 },
60 { 0x56, 3924 }, { 0x5f, 3552 }, { 0x69, 3214 }, { 0x74, 2909 },
61 { 0x80, 2636 }, { 0x8d, 2393 }, { 0x9b, 2177 }, { 0xaa, 1985 },
62 { 0xba, 1814 }, { 0xcb, 1662 }, { 0xdd, 1527 }, { 0xf0, 1406 }
63};
64
65struct temperature {
66 u8 deg_celsius;
67 u8 deg_fahrenheit;
68};
69
70struct temperature temperatures[] = {
71 { 30, 86 }, { 33, 91 }, { 36, 96 }, { 39, 102 },
72 { 42, 107 }, { 45, 113 }, { 48, 118 }, { 51, 123 },
73 { 54, 129 }, { 57, 134 }, { 60, 140 }, { 63, 145 },
74 { 66, 150 }, { 69, 156 }, { 72, 161 }, { 75, 167 }
75};
76
77void hwm_setup(void)
78{
79 int cpufan_control = 0, sysfan_control = 0;
80 int cpufan_speed = 0, sysfan_speed = 0;
81 int cpufan_temperature = 0, sysfan_temperature = 0;
82
83 if (get_option(&cpufan_control, "cpufan_cruise_control") != CB_SUCCESS)
84 cpufan_control = FAN_CRUISE_CONTROL_DISABLED;
85 if (get_option(&cpufan_speed, "cpufan_speed") != CB_SUCCESS)
86 cpufan_speed = FAN_SPEED_5625;
87 //if (get_option(&cpufan_temperature, "cpufan_temperature") != CB_SUCCESS)
88 // cpufan_temperature = FAN_TEMPERATURE_30DEGC;
89
90 if (get_option(&sysfan_control, "sysfan_cruise_control") != CB_SUCCESS)
91 sysfan_control = FAN_CRUISE_CONTROL_DISABLED;
92 if (get_option(&sysfan_speed, "sysfan_speed") != CB_SUCCESS)
93 sysfan_speed = FAN_SPEED_5625;
94 //if (get_option(&sysfan_temperature, "sysfan_temperature") != CB_SUCCESS)
95 // sysfan_temperature = FAN_TEMPERATURE_30DEGC;
96
97 // hwm_write(0x31, 0x20); // AVCC high limit
98 // hwm_write(0x34, 0x06); // VIN2 low limit
99
100 hwm_bank(0);
101 hwm_write(0x59, 0x20); // Diode Selection
102 hwm_write(0x5d, 0x0f); // All Sensors Diode, not Thermistor
103
104 hwm_bank(4);
105 hwm_write(0x54, 0xf1); // SYSTIN temperature offset
106 hwm_write(0x55, 0x19); // CPUTIN temperature offset
107 hwm_write(0x56, 0xfc); // AUXTIN temperature offset
108
109 hwm_bank(0x80); // Default
110
111 u8 fan_config = 0;
112 // 00 FANOUT is Manual Mode
113 // 01 FANOUT is Thermal Cruise Mode
114 // 10 FANOUT is Fan Speed Cruise Mode
115 switch (cpufan_control) {
116 case FAN_CRUISE_CONTROL_SPEED: fan_config |= (2 << 4); break;
117 case FAN_CRUISE_CONTROL_THERMAL: fan_config |= (1 << 4); break;
118 }
119 switch (sysfan_control) {
120 case FAN_CRUISE_CONTROL_SPEED: fan_config |= (2 << 2); break;
121 case FAN_CRUISE_CONTROL_THERMAL: fan_config |= (1 << 2); break;
122 }
123 // This register must be written first
124 hwm_write(0x04, fan_config);
125
126 switch (cpufan_control) {
127 case FAN_CRUISE_CONTROL_SPEED:
128 printk(BIOS_DEBUG, "Fan Cruise Control setting CPU fan to %d RPM\n",
129 fan_speeds[cpufan_speed].fan_speed);
130 hwm_write(0x06, fan_speeds[cpufan_speed].fan_in); // CPUFANIN target speed
131 break;
132 case FAN_CRUISE_CONTROL_THERMAL:
133 printk(BIOS_DEBUG, "Fan Cruise Control setting CPU fan to activation at %d deg C/%d deg F\n",
134 temperatures[cpufan_temperature].deg_celsius,
135 temperatures[cpufan_temperature].deg_fahrenheit);
136 hwm_write(0x06, temperatures[cpufan_temperature].deg_celsius); // CPUFANIN target temperature
137 break;
138 }
139
140 switch (sysfan_control) {
141 case FAN_CRUISE_CONTROL_SPEED:
142 printk(BIOS_DEBUG, "Fan Cruise Control setting system fan to %d RPM\n",
143 fan_speeds[sysfan_speed].fan_speed);
144 hwm_write(0x05, fan_speeds[sysfan_speed].fan_in); // SYSFANIN target speed
145 break;
146 case FAN_CRUISE_CONTROL_THERMAL:
147 printk(BIOS_DEBUG, "Fan Cruise Control setting system fan to activation at %d deg C/%d deg F\n",
148 temperatures[sysfan_temperature].deg_celsius,
149 temperatures[sysfan_temperature].deg_fahrenheit);
150 hwm_write(0x05, temperatures[sysfan_temperature].deg_celsius); // SYSFANIN target temperature
151 break;
152 }
153
154 hwm_write(0x0e, 0x02); // Fan Output Step Down Time
155 hwm_write(0x0f, 0x02); // Fan Output Step Up Time
156
157 hwm_write(0x47, 0xaf); // FAN divisor register
158 hwm_write(0x4b, 0x84); // AUXFANIN speed divisor
159
160 hwm_write(0x40, 0x01); // Init, but no SMI#
161}