| 1 |
|
| 2 |
|
| 3 |
#include <types.h> |
| 4 |
#include <device/device.h> |
| 5 |
#include <console/console.h> |
| 6 |
#include <drivers/intel/gma/int15.h> |
| 7 |
#include <option.h> |
| 8 |
#include <stdio.h> |
| 9 |
#include <superio/hwm5_conf.h> |
| 10 |
#include <superio/nuvoton/common/hwm.h> |
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
static u16 hwm_base = 0xa00; |
| 15 |
|
| 16 |
#define FAN_CRUISE_CONTROL_DISABLED 0 |
| 17 |
#define FAN_CRUISE_CONTROL_SPEED 1 |
| 18 |
#define FAN_CRUISE_CONTROL_THERMAL 2 |
| 19 |
#define FAN_SPEED_5625 0 |
| 20 |
|
| 21 |
struct fan_speed { |
| 22 |
u8 fan_in; |
| 23 |
u16 fan_speed; |
| 24 |
}; |
| 25 |
|
| 26 |
|
| 27 |
|
| 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[] = { |
| 41 |
{ 30, 86 }, { 33, 91 }, { 36, 96 }, { 39, 102 }, |
| 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 |
{ |
| 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; |
| 52 |
|
| 53 |
cpufan_control = get_uint_option("cpufan_cruise_control", FAN_CRUISE_CONTROL_DISABLED); |
| 54 |
cpufan_speed = get_uint_option("cpufan_speed", FAN_SPEED_5625); |
| 55 |
|
| 56 |
sysfan_control = get_uint_option("sysfan_cruise_control", FAN_CRUISE_CONTROL_DISABLED); |
| 57 |
sysfan_speed = get_uint_option("sysfan_speed", FAN_SPEED_5625); |
| 58 |
|
| 59 |
nuvoton_hwm_select_bank(hwm_base, 0); |
| 60 |
pnp_write_hwm5_index(hwm_base, 0x59, 0x20); |
| 61 |
pnp_write_hwm5_index(hwm_base, 0x5d, 0x0f); |
| 62 |
|
| 63 |
nuvoton_hwm_select_bank(hwm_base, 4); |
| 64 |
pnp_write_hwm5_index(hwm_base, 0x54, 0xf1); |
| 65 |
pnp_write_hwm5_index(hwm_base, 0x55, 0x19); |
| 66 |
pnp_write_hwm5_index(hwm_base, 0x56, 0xfc); |
| 67 |
|
| 68 |
nuvoton_hwm_select_bank(hwm_base, 0x80); |
| 69 |
|
| 70 |
u8 fan_config = 0; |
| 71 |
|
| 72 |
|
| 73 |
|
| 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 |
} |
| 82 |
|
| 83 |
pnp_write_hwm5_index(hwm_base, 0x04, fan_config); |
| 84 |
|
| 85 |
switch (cpufan_control) { |
| 86 |
case FAN_CRUISE_CONTROL_SPEED: |
| 87 |
printk(BIOS_DEBUG, "Fan Cruise Control setting CPU fan to %d RPM\n", |
| 88 |
fan_speeds[cpufan_speed].fan_speed); |
| 89 |
pnp_write_hwm5_index(hwm_base, 0x06, fan_speeds[cpufan_speed].fan_in); |
| 90 |
break; |
| 91 |
case FAN_CRUISE_CONTROL_THERMAL: |
| 92 |
printk(BIOS_DEBUG, "Fan Cruise Control setting CPU fan to activation at %d deg C/%d deg F\n", |
| 93 |
temperatures[cpufan_temperature].deg_celsius, |
| 94 |
temperatures[cpufan_temperature].deg_fahrenheit); |
| 95 |
pnp_write_hwm5_index(hwm_base, 0x06, |
| 96 |
temperatures[cpufan_temperature].deg_celsius); |
| 97 |
break; |
| 98 |
} |
| 99 |
|
| 100 |
switch (sysfan_control) { |
| 101 |
case FAN_CRUISE_CONTROL_SPEED: |
| 102 |
printk(BIOS_DEBUG, "Fan Cruise Control setting system fan to %d RPM\n", |
| 103 |
fan_speeds[sysfan_speed].fan_speed); |
| 104 |
pnp_write_hwm5_index(hwm_base, 0x05, fan_speeds[sysfan_speed].fan_in); |
| 105 |
break; |
| 106 |
case FAN_CRUISE_CONTROL_THERMAL: |
| 107 |
printk(BIOS_DEBUG, "Fan Cruise Control setting system fan to activation at %d deg C/%d deg F\n", |
| 108 |
temperatures[sysfan_temperature].deg_celsius, |
| 109 |
temperatures[sysfan_temperature].deg_fahrenheit); |
| 110 |
pnp_write_hwm5_index(hwm_base, 0x05, |
| 111 |
temperatures[sysfan_temperature].deg_celsius); |
| 112 |
break; |
| 113 |
} |
| 114 |
|
| 115 |
pnp_write_hwm5_index(hwm_base, 0x0e, 0x02); |
| 116 |
pnp_write_hwm5_index(hwm_base, 0x0f, 0x02); |
| 117 |
|
| 118 |
pnp_write_hwm5_index(hwm_base, 0x47, 0xaf); |
| 119 |
pnp_write_hwm5_index(hwm_base, 0x4b, 0x84); |
| 120 |
|
| 121 |
pnp_write_hwm5_index(hwm_base, 0x40, 0x01); |
| 122 |
} |
| 123 |
|
| 124 |
static void mainboard_enable(struct device *dev) |
| 125 |
{ |
| 126 |
install_intel_vga_int15_handler(GMA_INT15_ACTIVE_LFP_INT_LVDS, GMA_INT15_PANEL_FIT_DEFAULT, GMA_INT15_BOOT_DISPLAY_DEFAULT, 3); |
| 127 |
hwm_setup(); |
| 128 |
} |
| 129 |
|
| 130 |
static void mainboard_init(void *chip_info) |
| 131 |
{ |
| 132 |
int i; |
| 133 |
struct device *dev; |
| 134 |
|
| 135 |
for (i = 1; i <= 3; i++) { |
| 136 |
char cmos_option_name[] = "ethernetx"; |
| 137 |
snprintf(cmos_option_name, sizeof(cmos_option_name), |
| 138 |
"ethernet%01d", i); |
| 139 |
unsigned int ethernet_disable = get_uint_option(cmos_option_name, 0); |
| 140 |
if (!ethernet_disable) |
| 141 |
continue; |
| 142 |
printk(BIOS_DEBUG, "Disabling Ethernet NIC #%d\n", i); |
| 143 |
dev = pcidev_on_root(28, i - 1); |
| 144 |
if (dev == nullptr) { |
| 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 |
|
| 154 |
struct chip_operations mainboard_ops = { |
| 155 |
.init = mainboard_init, |
| 156 |
.enable_dev = mainboard_enable, |
| 157 |
}; |