Angel Pons | a21dff6 | 2020-04-03 01:22:24 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Stefan Reinauer | 36a2268 | 2008-10-29 04:52:57 +0000 | [diff] [blame] | 2 | |
Arthur Heymans | cf27838 | 2018-12-16 01:04:24 +0100 | [diff] [blame] | 3 | #include <string.h> |
Stefan Reinauer | aca6ec6 | 2009-10-26 17:12:21 +0000 | [diff] [blame] | 4 | #include <types.h> |
Stefan Reinauer | 36a2268 | 2008-10-29 04:52:57 +0000 | [diff] [blame] | 5 | #include <device/device.h> |
Stefan Reinauer | 3c7f46b | 2009-02-27 23:09:55 +0000 | [diff] [blame] | 6 | #include <console/console.h> |
Vladimir Serbinenko | a2a906e | 2014-09-01 01:41:37 +0200 | [diff] [blame] | 7 | #include <drivers/intel/gma/int15.h> |
Kyösti Mälkki | cbf9571 | 2020-01-05 08:05:45 +0200 | [diff] [blame] | 8 | #include <option.h> |
Elyes HAOUAS | edfe125 | 2019-10-08 21:44:02 +0200 | [diff] [blame] | 9 | #include <superio/hwm5_conf.h> |
Felix Held | 35103fd | 2019-12-15 12:11:44 +0100 | [diff] [blame] | 10 | #include <superio/nuvoton/common/hwm.h> |
Stefan Reinauer | 36a2268 | 2008-10-29 04:52:57 +0000 | [diff] [blame] | 11 | |
Stefan Reinauer | aca6ec6 | 2009-10-26 17:12:21 +0000 | [diff] [blame] | 12 | /* Hardware Monitor */ |
| 13 | |
| 14 | static u16 hwm_base = 0xa00; |
| 15 | |
Stefan Reinauer | aca6ec6 | 2009-10-26 17:12:21 +0000 | [diff] [blame] | 16 | #define FAN_CRUISE_CONTROL_DISABLED 0 |
| 17 | #define FAN_CRUISE_CONTROL_SPEED 1 |
| 18 | #define FAN_CRUISE_CONTROL_THERMAL 2 |
Stefan Reinauer | aca6ec6 | 2009-10-26 17:12:21 +0000 | [diff] [blame] | 19 | #define FAN_SPEED_5625 0 |
Elyes HAOUAS | f10b5ff | 2016-10-06 19:49:55 +0200 | [diff] [blame] | 20 | |
Stefan Reinauer | aca6ec6 | 2009-10-26 17:12:21 +0000 | [diff] [blame] | 21 | struct fan_speed { |
| 22 | u8 fan_in; |
| 23 | u16 fan_speed; |
| 24 | }; |
| 25 | |
Elyes HAOUAS | f10b5ff | 2016-10-06 19:49:55 +0200 | [diff] [blame] | 26 | /* FANIN Target Speed Register */ |
| 27 | /* FANIN = 337500 / RPM */ |
Stefan Reinauer | aca6ec6 | 2009-10-26 17:12:21 +0000 | [diff] [blame] | 28 | struct fan_speed fan_speeds[] = { |
| 29 | { 0x3c, 5625 }, { 0x41, 5192 }, { 0x47, 4753 }, { 0x4e, 4326 }, |
| 30 | { 0x56, 3924 }, { 0x5f, 3552 }, { 0x69, 3214 }, { 0x74, 2909 }, |
| 31 | { 0x80, 2636 }, { 0x8d, 2393 }, { 0x9b, 2177 }, { 0xaa, 1985 }, |
| 32 | { 0xba, 1814 }, { 0xcb, 1662 }, { 0xdd, 1527 }, { 0xf0, 1406 } |
| 33 | }; |
| 34 | |
| 35 | struct temperature { |
| 36 | u8 deg_celsius; |
| 37 | u8 deg_fahrenheit; |
| 38 | }; |
| 39 | |
| 40 | struct temperature temperatures[] = { |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 41 | { 30, 86 }, { 33, 91 }, { 36, 96 }, { 39, 102 }, |
Stefan Reinauer | aca6ec6 | 2009-10-26 17:12:21 +0000 | [diff] [blame] | 42 | { 42, 107 }, { 45, 113 }, { 48, 118 }, { 51, 123 }, |
| 43 | { 54, 129 }, { 57, 134 }, { 60, 140 }, { 63, 145 }, |
| 44 | { 66, 150 }, { 69, 156 }, { 72, 161 }, { 75, 167 } |
| 45 | }; |
| 46 | |
| 47 | static void hwm_setup(void) |
| 48 | { |
Angel Pons | 88dcb31 | 2021-04-26 17:10:28 +0200 | [diff] [blame] | 49 | unsigned int cpufan_control = 0, sysfan_control = 0; |
| 50 | unsigned int cpufan_speed = 0, sysfan_speed = 0; |
| 51 | unsigned int cpufan_temperature = 0, sysfan_temperature = 0; |
Stefan Reinauer | aca6ec6 | 2009-10-26 17:12:21 +0000 | [diff] [blame] | 52 | |
Angel Pons | 88dcb31 | 2021-04-26 17:10:28 +0200 | [diff] [blame] | 53 | cpufan_control = get_uint_option("cpufan_cruise_control", FAN_CRUISE_CONTROL_DISABLED); |
| 54 | cpufan_speed = get_uint_option("cpufan_speed", FAN_SPEED_5625); |
Stefan Reinauer | aca6ec6 | 2009-10-26 17:12:21 +0000 | [diff] [blame] | 55 | |
Angel Pons | 88dcb31 | 2021-04-26 17:10:28 +0200 | [diff] [blame] | 56 | sysfan_control = get_uint_option("sysfan_cruise_control", FAN_CRUISE_CONTROL_DISABLED); |
| 57 | sysfan_speed = get_uint_option("sysfan_speed", FAN_SPEED_5625); |
Stefan Reinauer | aca6ec6 | 2009-10-26 17:12:21 +0000 | [diff] [blame] | 58 | |
Felix Held | 35103fd | 2019-12-15 12:11:44 +0100 | [diff] [blame] | 59 | nuvoton_hwm_select_bank(hwm_base, 0); |
Elyes HAOUAS | edfe125 | 2019-10-08 21:44:02 +0200 | [diff] [blame] | 60 | pnp_write_hwm5_index(hwm_base, 0x59, 0x20); /* Diode Selection */ |
| 61 | pnp_write_hwm5_index(hwm_base, 0x5d, 0x0f); /* All Sensors Diode, not Thermistor */ |
Stefan Reinauer | aca6ec6 | 2009-10-26 17:12:21 +0000 | [diff] [blame] | 62 | |
Felix Held | 35103fd | 2019-12-15 12:11:44 +0100 | [diff] [blame] | 63 | nuvoton_hwm_select_bank(hwm_base, 4); |
Elyes HAOUAS | edfe125 | 2019-10-08 21:44:02 +0200 | [diff] [blame] | 64 | pnp_write_hwm5_index(hwm_base, 0x54, 0xf1); /* SYSTIN temperature offset */ |
| 65 | pnp_write_hwm5_index(hwm_base, 0x55, 0x19); /* CPUTIN temperature offset */ |
| 66 | pnp_write_hwm5_index(hwm_base, 0x56, 0xfc); /* AUXTIN temperature offset */ |
Stefan Reinauer | aca6ec6 | 2009-10-26 17:12:21 +0000 | [diff] [blame] | 67 | |
Felix Held | 35103fd | 2019-12-15 12:11:44 +0100 | [diff] [blame] | 68 | nuvoton_hwm_select_bank(hwm_base, 0x80); /* Default */ |
Stefan Reinauer | aca6ec6 | 2009-10-26 17:12:21 +0000 | [diff] [blame] | 69 | |
| 70 | u8 fan_config = 0; |
Elyes HAOUAS | f10b5ff | 2016-10-06 19:49:55 +0200 | [diff] [blame] | 71 | /* 00 FANOUT is Manual Mode */ |
| 72 | /* 01 FANOUT is Thermal Cruise Mode */ |
| 73 | /* 10 FANOUT is Fan Speed Cruise Mode */ |
Stefan Reinauer | aca6ec6 | 2009-10-26 17:12:21 +0000 | [diff] [blame] | 74 | switch (cpufan_control) { |
| 75 | case FAN_CRUISE_CONTROL_SPEED: fan_config |= (2 << 4); break; |
| 76 | case FAN_CRUISE_CONTROL_THERMAL: fan_config |= (1 << 4); break; |
| 77 | } |
| 78 | switch (sysfan_control) { |
| 79 | case FAN_CRUISE_CONTROL_SPEED: fan_config |= (2 << 2); break; |
| 80 | case FAN_CRUISE_CONTROL_THERMAL: fan_config |= (1 << 2); break; |
| 81 | } |
Elyes HAOUAS | f10b5ff | 2016-10-06 19:49:55 +0200 | [diff] [blame] | 82 | /* This register must be written first */ |
Elyes HAOUAS | edfe125 | 2019-10-08 21:44:02 +0200 | [diff] [blame] | 83 | pnp_write_hwm5_index(hwm_base, 0x04, fan_config); |
Stefan Reinauer | aca6ec6 | 2009-10-26 17:12:21 +0000 | [diff] [blame] | 84 | |
| 85 | switch (cpufan_control) { |
Elyes HAOUAS | edfe125 | 2019-10-08 21:44:02 +0200 | [diff] [blame] | 86 | case FAN_CRUISE_CONTROL_SPEED: /* CPUFANIN target speed */ |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 87 | printk(BIOS_DEBUG, "Fan Cruise Control setting CPU fan to %d RPM\n", |
Stefan Reinauer | aca6ec6 | 2009-10-26 17:12:21 +0000 | [diff] [blame] | 88 | fan_speeds[cpufan_speed].fan_speed); |
Elyes HAOUAS | edfe125 | 2019-10-08 21:44:02 +0200 | [diff] [blame] | 89 | pnp_write_hwm5_index(hwm_base, 0x06, fan_speeds[cpufan_speed].fan_in); |
Stefan Reinauer | aca6ec6 | 2009-10-26 17:12:21 +0000 | [diff] [blame] | 90 | break; |
Elyes HAOUAS | edfe125 | 2019-10-08 21:44:02 +0200 | [diff] [blame] | 91 | case FAN_CRUISE_CONTROL_THERMAL: /* CPUFANIN target temperature */ |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 92 | printk(BIOS_DEBUG, "Fan Cruise Control setting CPU fan to activation at %d deg C/%d deg F\n", |
Stefan Reinauer | aca6ec6 | 2009-10-26 17:12:21 +0000 | [diff] [blame] | 93 | temperatures[cpufan_temperature].deg_celsius, |
| 94 | temperatures[cpufan_temperature].deg_fahrenheit); |
Elyes HAOUAS | edfe125 | 2019-10-08 21:44:02 +0200 | [diff] [blame] | 95 | pnp_write_hwm5_index(hwm_base, 0x06, |
| 96 | temperatures[cpufan_temperature].deg_celsius); |
Stefan Reinauer | aca6ec6 | 2009-10-26 17:12:21 +0000 | [diff] [blame] | 97 | break; |
| 98 | } |
| 99 | |
| 100 | switch (sysfan_control) { |
Elyes HAOUAS | edfe125 | 2019-10-08 21:44:02 +0200 | [diff] [blame] | 101 | case FAN_CRUISE_CONTROL_SPEED: /* SYSFANIN target speed */ |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 102 | printk(BIOS_DEBUG, "Fan Cruise Control setting system fan to %d RPM\n", |
Stefan Reinauer | aca6ec6 | 2009-10-26 17:12:21 +0000 | [diff] [blame] | 103 | fan_speeds[sysfan_speed].fan_speed); |
Elyes HAOUAS | edfe125 | 2019-10-08 21:44:02 +0200 | [diff] [blame] | 104 | pnp_write_hwm5_index(hwm_base, 0x05, fan_speeds[sysfan_speed].fan_in); |
Stefan Reinauer | aca6ec6 | 2009-10-26 17:12:21 +0000 | [diff] [blame] | 105 | break; |
Elyes HAOUAS | edfe125 | 2019-10-08 21:44:02 +0200 | [diff] [blame] | 106 | case FAN_CRUISE_CONTROL_THERMAL: /* SYSFANIN target temperature */ |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 107 | printk(BIOS_DEBUG, "Fan Cruise Control setting system fan to activation at %d deg C/%d deg F\n", |
Stefan Reinauer | aca6ec6 | 2009-10-26 17:12:21 +0000 | [diff] [blame] | 108 | temperatures[sysfan_temperature].deg_celsius, |
| 109 | temperatures[sysfan_temperature].deg_fahrenheit); |
Elyes HAOUAS | edfe125 | 2019-10-08 21:44:02 +0200 | [diff] [blame] | 110 | pnp_write_hwm5_index(hwm_base, 0x05, |
| 111 | temperatures[sysfan_temperature].deg_celsius); |
Stefan Reinauer | aca6ec6 | 2009-10-26 17:12:21 +0000 | [diff] [blame] | 112 | break; |
| 113 | } |
| 114 | |
Elyes HAOUAS | edfe125 | 2019-10-08 21:44:02 +0200 | [diff] [blame] | 115 | pnp_write_hwm5_index(hwm_base, 0x0e, 0x02); /* Fan Output Step Down Time */ |
| 116 | pnp_write_hwm5_index(hwm_base, 0x0f, 0x02); /* Fan Output Step Up Time */ |
Stefan Reinauer | aca6ec6 | 2009-10-26 17:12:21 +0000 | [diff] [blame] | 117 | |
Elyes HAOUAS | edfe125 | 2019-10-08 21:44:02 +0200 | [diff] [blame] | 118 | pnp_write_hwm5_index(hwm_base, 0x47, 0xaf); /* FAN divisor register */ |
| 119 | pnp_write_hwm5_index(hwm_base, 0x4b, 0x84); /* AUXFANIN speed divisor */ |
Stefan Reinauer | aca6ec6 | 2009-10-26 17:12:21 +0000 | [diff] [blame] | 120 | |
Elyes HAOUAS | edfe125 | 2019-10-08 21:44:02 +0200 | [diff] [blame] | 121 | pnp_write_hwm5_index(hwm_base, 0x40, 0x01); /* Init, but no SMI# */ |
Stefan Reinauer | aca6ec6 | 2009-10-26 17:12:21 +0000 | [diff] [blame] | 122 | } |
| 123 | |
Elyes HAOUAS | f65f297e | 2018-05-04 22:09:07 +0200 | [diff] [blame] | 124 | static void mainboard_enable(struct device *dev) |
Stefan Reinauer | aca6ec6 | 2009-10-26 17:12:21 +0000 | [diff] [blame] | 125 | { |
Vladimir Serbinenko | a2a906e | 2014-09-01 01:41:37 +0200 | [diff] [blame] | 126 | install_intel_vga_int15_handler(GMA_INT15_ACTIVE_LFP_INT_LVDS, GMA_INT15_PANEL_FIT_DEFAULT, GMA_INT15_BOOT_DISPLAY_DEFAULT, 3); |
Stefan Reinauer | aca6ec6 | 2009-10-26 17:12:21 +0000 | [diff] [blame] | 127 | hwm_setup(); |
| 128 | } |
| 129 | |
Arthur Heymans | cf27838 | 2018-12-16 01:04:24 +0100 | [diff] [blame] | 130 | static void mainboard_init(void *chip_info) |
| 131 | { |
| 132 | int i; |
| 133 | struct device *dev; |
| 134 | |
| 135 | for (i = 1; i <= 3; i++) { |
Arthur Heymans | cf27838 | 2018-12-16 01:04:24 +0100 | [diff] [blame] | 136 | char cmos_option_name[] = "ethernetx"; |
| 137 | snprintf(cmos_option_name, sizeof(cmos_option_name), |
| 138 | "ethernet%01d", i); |
Angel Pons | 88dcb31 | 2021-04-26 17:10:28 +0200 | [diff] [blame] | 139 | unsigned int ethernet_disable = get_uint_option(cmos_option_name, 0); |
Arthur Heymans | cf27838 | 2018-12-16 01:04:24 +0100 | [diff] [blame] | 140 | if (!ethernet_disable) |
| 141 | continue; |
| 142 | printk(BIOS_DEBUG, "Disabling Ethernet NIC #%d\n", i); |
Elyes HAOUAS | d2abe93 | 2019-01-23 14:18:34 +0100 | [diff] [blame] | 143 | dev = pcidev_on_root(28, i - 1); |
Arthur Heymans | cf27838 | 2018-12-16 01:04:24 +0100 | [diff] [blame] | 144 | if (dev == NULL) { |
| 145 | printk(BIOS_ERR, |
| 146 | "Disabling Ethernet NIC: Cannot find 00:1c.%d!\n", |
| 147 | i - 1); |
| 148 | continue; |
| 149 | } |
| 150 | dev->enabled = 0; |
| 151 | } |
| 152 | } |
| 153 | |
Carl-Daniel Hailfinger | 7ad11e8 | 2009-02-18 20:41:57 +0000 | [diff] [blame] | 154 | struct chip_operations mainboard_ops = { |
Arthur Heymans | cf27838 | 2018-12-16 01:04:24 +0100 | [diff] [blame] | 155 | .init = mainboard_init, |
Stefan Reinauer | aca6ec6 | 2009-10-26 17:12:21 +0000 | [diff] [blame] | 156 | .enable_dev = mainboard_enable, |
Stefan Reinauer | 36a2268 | 2008-10-29 04:52:57 +0000 | [diff] [blame] | 157 | }; |