Stefan Reinauer | 36a2268 | 2008-10-29 04:52:57 +0000 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
Stefan Reinauer | aca6ec6 | 2009-10-26 17:12:21 +0000 | [diff] [blame] | 4 | * Copyright (C) 2007-2009 coresystems GmbH |
Stefan Reinauer | 36a2268 | 2008-10-29 04:52:57 +0000 | [diff] [blame] | 5 | * |
Uwe Hermann | 2bb4acf | 2010-03-01 17:19:55 +0000 | [diff] [blame] | 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; version 2 of the License. |
Stefan Reinauer | 36a2268 | 2008-10-29 04:52:57 +0000 | [diff] [blame] | 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
Stefan Reinauer | 36a2268 | 2008-10-29 04:52:57 +0000 | [diff] [blame] | 14 | */ |
| 15 | |
Arthur Heymans | cf27838 | 2018-12-16 01:04:24 +0100 | [diff] [blame] | 16 | #include <string.h> |
Stefan Reinauer | aca6ec6 | 2009-10-26 17:12:21 +0000 | [diff] [blame] | 17 | #include <types.h> |
Stefan Reinauer | 36a2268 | 2008-10-29 04:52:57 +0000 | [diff] [blame] | 18 | #include <device/device.h> |
Stefan Reinauer | 3c7f46b | 2009-02-27 23:09:55 +0000 | [diff] [blame] | 19 | #include <console/console.h> |
Vladimir Serbinenko | a2a906e | 2014-09-01 01:41:37 +0200 | [diff] [blame] | 20 | #include <drivers/intel/gma/int15.h> |
Kyösti Mälkki | cbf9571 | 2020-01-05 08:05:45 +0200 | [diff] [blame^] | 21 | #include <option.h> |
Elyes HAOUAS | edfe125 | 2019-10-08 21:44:02 +0200 | [diff] [blame] | 22 | #include <superio/hwm5_conf.h> |
Felix Held | 35103fd | 2019-12-15 12:11:44 +0100 | [diff] [blame] | 23 | #include <superio/nuvoton/common/hwm.h> |
Stefan Reinauer | 36a2268 | 2008-10-29 04:52:57 +0000 | [diff] [blame] | 24 | |
Stefan Reinauer | aca6ec6 | 2009-10-26 17:12:21 +0000 | [diff] [blame] | 25 | /* Hardware Monitor */ |
| 26 | |
| 27 | static u16 hwm_base = 0xa00; |
| 28 | |
Stefan Reinauer | aca6ec6 | 2009-10-26 17:12:21 +0000 | [diff] [blame] | 29 | #define FAN_CRUISE_CONTROL_DISABLED 0 |
| 30 | #define FAN_CRUISE_CONTROL_SPEED 1 |
| 31 | #define FAN_CRUISE_CONTROL_THERMAL 2 |
| 32 | |
| 33 | #define FAN_SPEED_5625 0 |
Elyes HAOUAS | f10b5ff | 2016-10-06 19:49:55 +0200 | [diff] [blame] | 34 | |
Stefan Reinauer | aca6ec6 | 2009-10-26 17:12:21 +0000 | [diff] [blame] | 35 | |
| 36 | struct fan_speed { |
| 37 | u8 fan_in; |
| 38 | u16 fan_speed; |
| 39 | }; |
| 40 | |
Elyes HAOUAS | f10b5ff | 2016-10-06 19:49:55 +0200 | [diff] [blame] | 41 | /* FANIN Target Speed Register */ |
| 42 | /* FANIN = 337500 / RPM */ |
Stefan Reinauer | aca6ec6 | 2009-10-26 17:12:21 +0000 | [diff] [blame] | 43 | struct fan_speed fan_speeds[] = { |
| 44 | { 0x3c, 5625 }, { 0x41, 5192 }, { 0x47, 4753 }, { 0x4e, 4326 }, |
| 45 | { 0x56, 3924 }, { 0x5f, 3552 }, { 0x69, 3214 }, { 0x74, 2909 }, |
| 46 | { 0x80, 2636 }, { 0x8d, 2393 }, { 0x9b, 2177 }, { 0xaa, 1985 }, |
| 47 | { 0xba, 1814 }, { 0xcb, 1662 }, { 0xdd, 1527 }, { 0xf0, 1406 } |
| 48 | }; |
| 49 | |
| 50 | struct temperature { |
| 51 | u8 deg_celsius; |
| 52 | u8 deg_fahrenheit; |
| 53 | }; |
| 54 | |
| 55 | struct temperature temperatures[] = { |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 56 | { 30, 86 }, { 33, 91 }, { 36, 96 }, { 39, 102 }, |
Stefan Reinauer | aca6ec6 | 2009-10-26 17:12:21 +0000 | [diff] [blame] | 57 | { 42, 107 }, { 45, 113 }, { 48, 118 }, { 51, 123 }, |
| 58 | { 54, 129 }, { 57, 134 }, { 60, 140 }, { 63, 145 }, |
| 59 | { 66, 150 }, { 69, 156 }, { 72, 161 }, { 75, 167 } |
| 60 | }; |
| 61 | |
| 62 | static void hwm_setup(void) |
| 63 | { |
| 64 | int cpufan_control = 0, sysfan_control = 0; |
| 65 | int cpufan_speed = 0, sysfan_speed = 0; |
| 66 | int cpufan_temperature = 0, sysfan_temperature = 0; |
| 67 | |
Varad Gautam | 06ef046 | 2015-03-11 09:54:41 +0530 | [diff] [blame] | 68 | cpufan_control = FAN_CRUISE_CONTROL_DISABLED; |
| 69 | get_option(&cpufan_control, "cpufan_cruise_control"); |
| 70 | cpufan_speed = FAN_SPEED_5625; |
| 71 | get_option(&cpufan_speed, "cpufan_speed"); |
Stefan Reinauer | aca6ec6 | 2009-10-26 17:12:21 +0000 | [diff] [blame] | 72 | |
Varad Gautam | 06ef046 | 2015-03-11 09:54:41 +0530 | [diff] [blame] | 73 | sysfan_control = FAN_CRUISE_CONTROL_DISABLED; |
| 74 | get_option(&sysfan_control, "sysfan_cruise_control"); |
| 75 | sysfan_speed = FAN_SPEED_5625; |
| 76 | get_option(&sysfan_speed, "sysfan_speed"); |
Stefan Reinauer | aca6ec6 | 2009-10-26 17:12:21 +0000 | [diff] [blame] | 77 | |
Felix Held | 35103fd | 2019-12-15 12:11:44 +0100 | [diff] [blame] | 78 | nuvoton_hwm_select_bank(hwm_base, 0); |
Elyes HAOUAS | edfe125 | 2019-10-08 21:44:02 +0200 | [diff] [blame] | 79 | pnp_write_hwm5_index(hwm_base, 0x59, 0x20); /* Diode Selection */ |
| 80 | 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] | 81 | |
Felix Held | 35103fd | 2019-12-15 12:11:44 +0100 | [diff] [blame] | 82 | nuvoton_hwm_select_bank(hwm_base, 4); |
Elyes HAOUAS | edfe125 | 2019-10-08 21:44:02 +0200 | [diff] [blame] | 83 | pnp_write_hwm5_index(hwm_base, 0x54, 0xf1); /* SYSTIN temperature offset */ |
| 84 | pnp_write_hwm5_index(hwm_base, 0x55, 0x19); /* CPUTIN temperature offset */ |
| 85 | pnp_write_hwm5_index(hwm_base, 0x56, 0xfc); /* AUXTIN temperature offset */ |
Stefan Reinauer | aca6ec6 | 2009-10-26 17:12:21 +0000 | [diff] [blame] | 86 | |
Felix Held | 35103fd | 2019-12-15 12:11:44 +0100 | [diff] [blame] | 87 | nuvoton_hwm_select_bank(hwm_base, 0x80); /* Default */ |
Stefan Reinauer | aca6ec6 | 2009-10-26 17:12:21 +0000 | [diff] [blame] | 88 | |
| 89 | u8 fan_config = 0; |
Elyes HAOUAS | f10b5ff | 2016-10-06 19:49:55 +0200 | [diff] [blame] | 90 | /* 00 FANOUT is Manual Mode */ |
| 91 | /* 01 FANOUT is Thermal Cruise Mode */ |
| 92 | /* 10 FANOUT is Fan Speed Cruise Mode */ |
Stefan Reinauer | aca6ec6 | 2009-10-26 17:12:21 +0000 | [diff] [blame] | 93 | switch (cpufan_control) { |
| 94 | case FAN_CRUISE_CONTROL_SPEED: fan_config |= (2 << 4); break; |
| 95 | case FAN_CRUISE_CONTROL_THERMAL: fan_config |= (1 << 4); break; |
| 96 | } |
| 97 | switch (sysfan_control) { |
| 98 | case FAN_CRUISE_CONTROL_SPEED: fan_config |= (2 << 2); break; |
| 99 | case FAN_CRUISE_CONTROL_THERMAL: fan_config |= (1 << 2); break; |
| 100 | } |
Elyes HAOUAS | f10b5ff | 2016-10-06 19:49:55 +0200 | [diff] [blame] | 101 | /* This register must be written first */ |
Elyes HAOUAS | edfe125 | 2019-10-08 21:44:02 +0200 | [diff] [blame] | 102 | pnp_write_hwm5_index(hwm_base, 0x04, fan_config); |
Stefan Reinauer | aca6ec6 | 2009-10-26 17:12:21 +0000 | [diff] [blame] | 103 | |
| 104 | switch (cpufan_control) { |
Elyes HAOUAS | edfe125 | 2019-10-08 21:44:02 +0200 | [diff] [blame] | 105 | case FAN_CRUISE_CONTROL_SPEED: /* CPUFANIN target speed */ |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 106 | 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] | 107 | fan_speeds[cpufan_speed].fan_speed); |
Elyes HAOUAS | edfe125 | 2019-10-08 21:44:02 +0200 | [diff] [blame] | 108 | 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] | 109 | break; |
Elyes HAOUAS | edfe125 | 2019-10-08 21:44:02 +0200 | [diff] [blame] | 110 | case FAN_CRUISE_CONTROL_THERMAL: /* CPUFANIN target temperature */ |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 111 | 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] | 112 | temperatures[cpufan_temperature].deg_celsius, |
| 113 | temperatures[cpufan_temperature].deg_fahrenheit); |
Elyes HAOUAS | edfe125 | 2019-10-08 21:44:02 +0200 | [diff] [blame] | 114 | pnp_write_hwm5_index(hwm_base, 0x06, |
| 115 | temperatures[cpufan_temperature].deg_celsius); |
Stefan Reinauer | aca6ec6 | 2009-10-26 17:12:21 +0000 | [diff] [blame] | 116 | break; |
| 117 | } |
| 118 | |
| 119 | switch (sysfan_control) { |
Elyes HAOUAS | edfe125 | 2019-10-08 21:44:02 +0200 | [diff] [blame] | 120 | case FAN_CRUISE_CONTROL_SPEED: /* SYSFANIN target speed */ |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 121 | 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] | 122 | fan_speeds[sysfan_speed].fan_speed); |
Elyes HAOUAS | edfe125 | 2019-10-08 21:44:02 +0200 | [diff] [blame] | 123 | 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] | 124 | break; |
Elyes HAOUAS | edfe125 | 2019-10-08 21:44:02 +0200 | [diff] [blame] | 125 | case FAN_CRUISE_CONTROL_THERMAL: /* SYSFANIN target temperature */ |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 126 | 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] | 127 | temperatures[sysfan_temperature].deg_celsius, |
| 128 | temperatures[sysfan_temperature].deg_fahrenheit); |
Elyes HAOUAS | edfe125 | 2019-10-08 21:44:02 +0200 | [diff] [blame] | 129 | pnp_write_hwm5_index(hwm_base, 0x05, |
| 130 | temperatures[sysfan_temperature].deg_celsius); |
Stefan Reinauer | aca6ec6 | 2009-10-26 17:12:21 +0000 | [diff] [blame] | 131 | break; |
| 132 | } |
| 133 | |
Elyes HAOUAS | edfe125 | 2019-10-08 21:44:02 +0200 | [diff] [blame] | 134 | pnp_write_hwm5_index(hwm_base, 0x0e, 0x02); /* Fan Output Step Down Time */ |
| 135 | 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] | 136 | |
Elyes HAOUAS | edfe125 | 2019-10-08 21:44:02 +0200 | [diff] [blame] | 137 | pnp_write_hwm5_index(hwm_base, 0x47, 0xaf); /* FAN divisor register */ |
| 138 | pnp_write_hwm5_index(hwm_base, 0x4b, 0x84); /* AUXFANIN speed divisor */ |
Stefan Reinauer | aca6ec6 | 2009-10-26 17:12:21 +0000 | [diff] [blame] | 139 | |
Elyes HAOUAS | edfe125 | 2019-10-08 21:44:02 +0200 | [diff] [blame] | 140 | pnp_write_hwm5_index(hwm_base, 0x40, 0x01); /* Init, but no SMI# */ |
Stefan Reinauer | aca6ec6 | 2009-10-26 17:12:21 +0000 | [diff] [blame] | 141 | } |
| 142 | |
Elyes HAOUAS | f10b5ff | 2016-10-06 19:49:55 +0200 | [diff] [blame] | 143 | /* mainboard_enable is executed as first thing after */ |
| 144 | /* enumerate_buses(). */ |
Stefan Reinauer | c6f2bd0 | 2010-01-19 21:15:01 +0000 | [diff] [blame] | 145 | |
Elyes HAOUAS | f65f297e | 2018-05-04 22:09:07 +0200 | [diff] [blame] | 146 | static void mainboard_enable(struct device *dev) |
Stefan Reinauer | aca6ec6 | 2009-10-26 17:12:21 +0000 | [diff] [blame] | 147 | { |
Vladimir Serbinenko | a2a906e | 2014-09-01 01:41:37 +0200 | [diff] [blame] | 148 | 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] | 149 | hwm_setup(); |
| 150 | } |
| 151 | |
Arthur Heymans | cf27838 | 2018-12-16 01:04:24 +0100 | [diff] [blame] | 152 | static void mainboard_init(void *chip_info) |
| 153 | { |
| 154 | int i; |
| 155 | struct device *dev; |
| 156 | |
| 157 | for (i = 1; i <= 3; i++) { |
| 158 | int ethernet_disable = 0; |
| 159 | char cmos_option_name[] = "ethernetx"; |
| 160 | snprintf(cmos_option_name, sizeof(cmos_option_name), |
| 161 | "ethernet%01d", i); |
| 162 | get_option(ðernet_disable, cmos_option_name); |
| 163 | if (!ethernet_disable) |
| 164 | continue; |
| 165 | printk(BIOS_DEBUG, "Disabling Ethernet NIC #%d\n", i); |
Elyes HAOUAS | d2abe93 | 2019-01-23 14:18:34 +0100 | [diff] [blame] | 166 | dev = pcidev_on_root(28, i - 1); |
Arthur Heymans | cf27838 | 2018-12-16 01:04:24 +0100 | [diff] [blame] | 167 | if (dev == NULL) { |
| 168 | printk(BIOS_ERR, |
| 169 | "Disabling Ethernet NIC: Cannot find 00:1c.%d!\n", |
| 170 | i - 1); |
| 171 | continue; |
| 172 | } |
| 173 | dev->enabled = 0; |
| 174 | } |
| 175 | } |
| 176 | |
Carl-Daniel Hailfinger | 7ad11e8 | 2009-02-18 20:41:57 +0000 | [diff] [blame] | 177 | struct chip_operations mainboard_ops = { |
Arthur Heymans | cf27838 | 2018-12-16 01:04:24 +0100 | [diff] [blame] | 178 | .init = mainboard_init, |
Stefan Reinauer | aca6ec6 | 2009-10-26 17:12:21 +0000 | [diff] [blame] | 179 | .enable_dev = mainboard_enable, |
Stefan Reinauer | 36a2268 | 2008-10-29 04:52:57 +0000 | [diff] [blame] | 180 | }; |