blob: f2c313ecc646a77d12fbc314595d41110640583e [file] [log] [blame]
Angel Pons30a511c2020-04-03 01:22:09 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Edward O'Callaghan3628f932014-05-21 07:00:48 +10002
3#include <types.h>
Edward O'Callaghan3628f932014-05-21 07:00:48 +10004#include <console/console.h>
5#include <device/device.h>
Kyösti Mälkkicbf95712020-01-05 08:05:45 +02006#include <option.h>
Elyes HAOUASedfe1252019-10-08 21:44:02 +02007#include <superio/hwm5_conf.h>
Felix Held734c9992019-12-27 18:00:53 +01008#include <superio/nuvoton/common/hwm.h>
Edward O'Callaghan3628f932014-05-21 07:00:48 +10009
10#include "superio_hwm.h"
11
12/* Hardware Monitor */
13
14#define FAN_CRUISE_CONTROL_DISABLED 0
15#define FAN_CRUISE_CONTROL_SPEED 1
16#define FAN_CRUISE_CONTROL_THERMAL 2
17
18#define FAN_SPEED_5625 0
19//#define FAN_TEMPERATURE_30DEGC 0
20
21#define HWM_BASE 0x290
22
Edward O'Callaghan3628f932014-05-21 07:00:48 +100023struct fan_speed {
24 u8 fan_in;
25 u16 fan_speed;
26};
27
28// FANIN Target Speed Register
29// FANIN = 337500 / RPM
30struct fan_speed fan_speeds[] = {
31 { 0x3c, 5625 }, { 0x41, 5192 }, { 0x47, 4753 }, { 0x4e, 4326 },
32 { 0x56, 3924 }, { 0x5f, 3552 }, { 0x69, 3214 }, { 0x74, 2909 },
33 { 0x80, 2636 }, { 0x8d, 2393 }, { 0x9b, 2177 }, { 0xaa, 1985 },
34 { 0xba, 1814 }, { 0xcb, 1662 }, { 0xdd, 1527 }, { 0xf0, 1406 }
35};
36
37struct temperature {
38 u8 deg_celsius;
39 u8 deg_fahrenheit;
40};
41
42struct temperature temperatures[] = {
43 { 30, 86 }, { 33, 91 }, { 36, 96 }, { 39, 102 },
44 { 42, 107 }, { 45, 113 }, { 48, 118 }, { 51, 123 },
45 { 54, 129 }, { 57, 134 }, { 60, 140 }, { 63, 145 },
46 { 66, 150 }, { 69, 156 }, { 72, 161 }, { 75, 167 }
47};
48
49void hwm_setup(void)
50{
Angel Pons88dcb312021-04-26 17:10:28 +020051 unsigned int cpufan_control = 0, sysfan_control = 0;
52 unsigned int cpufan_speed = 0, sysfan_speed = 0;
53 unsigned int cpufan_temperature = 0, sysfan_temperature = 0;
Edward O'Callaghan3628f932014-05-21 07:00:48 +100054
Angel Pons88dcb312021-04-26 17:10:28 +020055 cpufan_control = get_uint_option("cpufan_cruise_control", FAN_CRUISE_CONTROL_DISABLED);
56 cpufan_speed = get_uint_option("cpufan_speed", FAN_SPEED_5625);
57 //cpufan_temperature = get_uint_option("cpufan_temperature", FAN_TEMPERATURE_30DEGC);
Edward O'Callaghan3628f932014-05-21 07:00:48 +100058
Angel Pons88dcb312021-04-26 17:10:28 +020059 sysfan_control = get_uint_option("sysfan_cruise_control", FAN_CRUISE_CONTROL_DISABLED);
60 sysfan_speed = get_uint_option("sysfan_speed", FAN_SPEED_5625);
61 //sysfan_temperature = get_uint_option("sysfan_temperature", FAN_TEMPERATURE_30DEGC);
Edward O'Callaghan3628f932014-05-21 07:00:48 +100062
Elyes HAOUASedfe1252019-10-08 21:44:02 +020063 // pnp_write_hwm5_index(HWM_BASE, 0x31, 0x20); // AVCC high limit
64 // pnp_write_hwm5_index(HWM_BASE, 0x34, 0x06); // VIN2 low limit
Edward O'Callaghan3628f932014-05-21 07:00:48 +100065
Felix Held734c9992019-12-27 18:00:53 +010066 nuvoton_hwm_select_bank(HWM_BASE, 0);
Elyes HAOUASedfe1252019-10-08 21:44:02 +020067 pnp_write_hwm5_index(HWM_BASE, 0x59, 0x20); // Diode Selection
68 pnp_write_hwm5_index(HWM_BASE, 0x5d, 0x0f); // All Sensors Diode, not Thermistor
Edward O'Callaghan3628f932014-05-21 07:00:48 +100069
Felix Held734c9992019-12-27 18:00:53 +010070 nuvoton_hwm_select_bank(HWM_BASE, 4);
Elyes HAOUASedfe1252019-10-08 21:44:02 +020071 pnp_write_hwm5_index(HWM_BASE, 0x54, 0xf1); // SYSTIN temperature offset
72 pnp_write_hwm5_index(HWM_BASE, 0x55, 0x19); // CPUTIN temperature offset
73 pnp_write_hwm5_index(HWM_BASE, 0x56, 0xfc); // AUXTIN temperature offset
Edward O'Callaghan3628f932014-05-21 07:00:48 +100074
Felix Held734c9992019-12-27 18:00:53 +010075 nuvoton_hwm_select_bank(HWM_BASE, 0x80); // Default
Edward O'Callaghan3628f932014-05-21 07:00:48 +100076
77 u8 fan_config = 0;
78 // 00 FANOUT is Manual Mode
79 // 01 FANOUT is Thermal Cruise Mode
80 // 10 FANOUT is Fan Speed Cruise Mode
81 switch (cpufan_control) {
82 case FAN_CRUISE_CONTROL_SPEED: fan_config |= (2 << 4); break;
83 case FAN_CRUISE_CONTROL_THERMAL: fan_config |= (1 << 4); break;
84 }
85 switch (sysfan_control) {
86 case FAN_CRUISE_CONTROL_SPEED: fan_config |= (2 << 2); break;
87 case FAN_CRUISE_CONTROL_THERMAL: fan_config |= (1 << 2); break;
88 }
89 // This register must be written first
Elyes HAOUASedfe1252019-10-08 21:44:02 +020090 pnp_write_hwm5_index(HWM_BASE, 0x04, fan_config);
Edward O'Callaghan3628f932014-05-21 07:00:48 +100091
92 switch (cpufan_control) {
Elyes HAOUASedfe1252019-10-08 21:44:02 +020093 case FAN_CRUISE_CONTROL_SPEED: /* CPUFANIN target speed */
Edward O'Callaghan3628f932014-05-21 07:00:48 +100094 printk(BIOS_DEBUG, "Fan Cruise Control setting CPU fan to %d RPM\n",
95 fan_speeds[cpufan_speed].fan_speed);
Elyes HAOUASedfe1252019-10-08 21:44:02 +020096 pnp_write_hwm5_index(HWM_BASE, 0x06, fan_speeds[cpufan_speed].fan_in);
Edward O'Callaghan3628f932014-05-21 07:00:48 +100097 break;
Elyes HAOUASedfe1252019-10-08 21:44:02 +020098 case FAN_CRUISE_CONTROL_THERMAL: /* CPUFANIN target temperature */
Edward O'Callaghan3628f932014-05-21 07:00:48 +100099 printk(BIOS_DEBUG, "Fan Cruise Control setting CPU fan to activation at %d deg C/%d deg F\n",
100 temperatures[cpufan_temperature].deg_celsius,
101 temperatures[cpufan_temperature].deg_fahrenheit);
Elyes HAOUASedfe1252019-10-08 21:44:02 +0200102 pnp_write_hwm5_index(HWM_BASE, 0x06,
103 temperatures[cpufan_temperature].deg_celsius);
Edward O'Callaghan3628f932014-05-21 07:00:48 +1000104 break;
105 }
106
107 switch (sysfan_control) {
Elyes HAOUASedfe1252019-10-08 21:44:02 +0200108 case FAN_CRUISE_CONTROL_SPEED: /* SYSFANIN target speed */
Edward O'Callaghan3628f932014-05-21 07:00:48 +1000109 printk(BIOS_DEBUG, "Fan Cruise Control setting system fan to %d RPM\n",
110 fan_speeds[sysfan_speed].fan_speed);
Elyes HAOUASedfe1252019-10-08 21:44:02 +0200111 pnp_write_hwm5_index(HWM_BASE, 0x05, fan_speeds[sysfan_speed].fan_in);
Edward O'Callaghan3628f932014-05-21 07:00:48 +1000112 break;
Elyes HAOUASedfe1252019-10-08 21:44:02 +0200113 case FAN_CRUISE_CONTROL_THERMAL: /* SYSFANIN target temperature */
Edward O'Callaghan3628f932014-05-21 07:00:48 +1000114 printk(BIOS_DEBUG, "Fan Cruise Control setting system fan to activation at %d deg C/%d deg F\n",
115 temperatures[sysfan_temperature].deg_celsius,
116 temperatures[sysfan_temperature].deg_fahrenheit);
Elyes HAOUASedfe1252019-10-08 21:44:02 +0200117 pnp_write_hwm5_index(HWM_BASE,
118 0x05, temperatures[sysfan_temperature].deg_celsius);
Edward O'Callaghan3628f932014-05-21 07:00:48 +1000119 break;
120 }
121
Elyes HAOUASedfe1252019-10-08 21:44:02 +0200122 pnp_write_hwm5_index(HWM_BASE, 0x0e, 0x02); // Fan Output Step Down Time
123 pnp_write_hwm5_index(HWM_BASE, 0x0f, 0x02); // Fan Output Step Up Time
Edward O'Callaghan3628f932014-05-21 07:00:48 +1000124
Elyes HAOUASedfe1252019-10-08 21:44:02 +0200125 pnp_write_hwm5_index(HWM_BASE, 0x47, 0xaf); // FAN divisor register
126 pnp_write_hwm5_index(HWM_BASE, 0x4b, 0x84); // AUXFANIN speed divisor
Edward O'Callaghan3628f932014-05-21 07:00:48 +1000127
Elyes HAOUASedfe1252019-10-08 21:44:02 +0200128 pnp_write_hwm5_index(HWM_BASE, 0x40, 0x01); // Init, but no SMI#
Edward O'Callaghan3628f932014-05-21 07:00:48 +1000129}