Since some people disapprove of white space cleanups mixed in regular commits
[coreboot.git] / src / mainboard / kontron / 986lcd-m / mainboard.c
1 /*
2  * This file is part of the coreboot project.
3  *
4  * Copyright (C) 2007-2009 coresystems GmbH
5  *
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.
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.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18  */
19
20 #include <types.h>
21 #include <device/device.h>
22 #include <console/console.h>
23 #include <boot/tables.h>
24 #if CONFIG_PCI_OPTION_ROM_RUN_YABEL
25 #include <x86emu/x86emu.h>
26 #endif
27 #include <pc80/mc146818rtc.h>
28 #include <arch/io.h>
29 #include <arch/coreboot_tables.h>
30 #include "chip.h"
31
32 int add_mainboard_resources(struct lb_memory *mem)
33 {
34         return add_northbridge_resources(mem);
35 }
36
37 #if CONFIG_PCI_OPTION_ROM_RUN_YABEL
38 static int int15_handler(void)
39 {
40 #define BOOT_DISPLAY_DEFAULT    0
41 #define BOOT_DISPLAY_CRT        (1 << 0)
42 #define BOOT_DISPLAY_TV         (1 << 1)
43 #define BOOT_DISPLAY_EFP        (1 << 2)
44 #define BOOT_DISPLAY_LCD        (1 << 3)
45 #define BOOT_DISPLAY_CRT2       (1 << 4)
46 #define BOOT_DISPLAY_TV2        (1 << 5)
47 #define BOOT_DISPLAY_EFP2       (1 << 6)
48 #define BOOT_DISPLAY_LCD2       (1 << 7)
49
50         printk(BIOS_DEBUG, "%s: AX=%04x BX=%04x CX=%04x DX=%04x\n",
51                           __func__, M.x86.R_AX, M.x86.R_BX, M.x86.R_CX, M.x86.R_DX);
52
53         switch (M.x86.R_AX) {
54         case 0x5f35: /* Boot Display */
55                 M.x86.R_AX = 0x005f; // Success
56                 M.x86.R_CL = BOOT_DISPLAY_DEFAULT;
57                 break;
58         case 0x5f40: /* Boot Panel Type */
59                 // M.x86.R_AX = 0x015f; // Supported but failed
60                 M.x86.R_AX = 0x005f; // Success
61                 M.x86.R_CL = 3; // Display ID
62                 break;
63         default:
64                 /* Interrupt was not handled */
65                 return 0;
66         }
67
68         /* Interrupt handled */
69         return 1;
70 }
71
72 static void int15_install(void)
73 {
74         typedef int (* yabel_handleIntFunc)(void);
75         extern yabel_handleIntFunc yabel_intFuncArray[256];
76         yabel_intFuncArray[0x15] = int15_handler;
77 }
78 #endif
79
80 /* Hardware Monitor */
81
82 static u16 hwm_base = 0xa00;
83
84 static void hwm_write(u8 reg, u8 value)
85 {
86         outb(reg, hwm_base + 0x05);
87         outb(value, hwm_base + 0x06);
88 }
89
90 static void hwm_bank(u8 bank)
91 {
92         hwm_write(0x4e, bank);
93 }
94
95 #define FAN_CRUISE_CONTROL_DISABLED     0
96 #define FAN_CRUISE_CONTROL_SPEED        1
97 #define FAN_CRUISE_CONTROL_THERMAL      2
98
99 #define FAN_SPEED_5625  0
100 //#define FAN_TEMPERATURE_30DEGC        0
101
102 struct fan_speed {
103         u8 fan_in;
104         u16 fan_speed;
105 };
106
107 // FANIN Target Speed Register
108 // FANIN = 337500 / RPM
109 struct fan_speed fan_speeds[] = {
110         { 0x3c, 5625 }, { 0x41, 5192 }, { 0x47, 4753 }, { 0x4e, 4326 },
111         { 0x56, 3924 }, { 0x5f, 3552 }, { 0x69, 3214 }, { 0x74, 2909 },
112         { 0x80, 2636 }, { 0x8d, 2393 }, { 0x9b, 2177 }, { 0xaa, 1985 },
113         { 0xba, 1814 }, { 0xcb, 1662 }, { 0xdd, 1527 }, { 0xf0, 1406 }
114 };
115
116 struct temperature {
117         u8 deg_celsius;
118         u8 deg_fahrenheit;
119 };
120
121 struct temperature temperatures[] = {
122         { 30,  86 }, { 33,  91 }, { 36,  96 }, { 39, 102 },
123         { 42, 107 }, { 45, 113 }, { 48, 118 }, { 51, 123 },
124         { 54, 129 }, { 57, 134 }, { 60, 140 }, { 63, 145 },
125         { 66, 150 }, { 69, 156 }, { 72, 161 }, { 75, 167 }
126 };
127
128 static void hwm_setup(void)
129 {
130         int cpufan_control = 0, sysfan_control = 0;
131         int cpufan_speed = 0, sysfan_speed = 0;
132         int cpufan_temperature = 0, sysfan_temperature = 0;
133
134         if (get_option(&cpufan_control, "cpufan_cruise_control") < 0)
135                 cpufan_control = FAN_CRUISE_CONTROL_DISABLED;
136         if (get_option(&cpufan_speed, "cpufan_speed") < 0)
137                 cpufan_speed = FAN_SPEED_5625;
138         //if (get_option(&cpufan_temperature, "cpufan_temperature") < 0)
139         //      cpufan_temperature = FAN_TEMPERATURE_30DEGC;
140
141         if (get_option(&sysfan_control, "sysfan_cruise_control") < 0)
142                 sysfan_control = FAN_CRUISE_CONTROL_DISABLED;
143         if (get_option(&sysfan_speed, "sysfan_speed") < 0)
144                 sysfan_speed = FAN_SPEED_5625;
145         //if (get_option(&sysfan_temperature, "sysfan_temperature") < 0)
146         //      sysfan_temperature = FAN_TEMPERATURE_30DEGC;
147
148         // hwm_write(0x31, 0x20); // AVCC high limit
149         // hwm_write(0x34, 0x06); // VIN2 low limit
150
151         hwm_bank(0);
152         hwm_write(0x59, 0x20); // Diode Selection
153         hwm_write(0x5d, 0x0f); // All Sensors Diode, not Thermistor
154
155         hwm_bank(4);
156         hwm_write(0x54, 0xf1); // SYSTIN temperature offset
157         hwm_write(0x55, 0x19); // CPUTIN temperature offset
158         hwm_write(0x56, 0xfc); // AUXTIN temperature offset
159
160         hwm_bank(0x80); // Default
161
162         u8 fan_config = 0;
163         // 00 FANOUT is Manual Mode
164         // 01 FANOUT is Thermal Cruise Mode
165         // 10 FANOUT is Fan Speed Cruise Mode
166         switch (cpufan_control) {
167         case FAN_CRUISE_CONTROL_SPEED:   fan_config |= (2 << 4); break;
168         case FAN_CRUISE_CONTROL_THERMAL: fan_config |= (1 << 4); break;
169         }
170         switch (sysfan_control) {
171         case FAN_CRUISE_CONTROL_SPEED:   fan_config |= (2 << 2); break;
172         case FAN_CRUISE_CONTROL_THERMAL: fan_config |= (1 << 2); break;
173         }
174         // This register must be written first
175         hwm_write(0x04, fan_config);
176
177         switch (cpufan_control) {
178         case FAN_CRUISE_CONTROL_SPEED:
179                 printk(BIOS_DEBUG, "Fan Cruise Control setting CPU fan to %d RPM\n",
180                                 fan_speeds[cpufan_speed].fan_speed);
181                 hwm_write(0x06, fan_speeds[cpufan_speed].fan_in);  // CPUFANIN target speed
182                 break;
183         case FAN_CRUISE_CONTROL_THERMAL:
184                 printk(BIOS_DEBUG, "Fan Cruise Control setting CPU fan to activation at %d deg C/%d deg F\n",
185                                 temperatures[cpufan_temperature].deg_celsius,
186                                 temperatures[cpufan_temperature].deg_fahrenheit);
187                 hwm_write(0x06, temperatures[cpufan_temperature].deg_celsius);  // CPUFANIN target temperature
188                 break;
189         }
190
191         switch (sysfan_control) {
192         case FAN_CRUISE_CONTROL_SPEED:
193                 printk(BIOS_DEBUG, "Fan Cruise Control setting system fan to %d RPM\n",
194                                 fan_speeds[sysfan_speed].fan_speed);
195                 hwm_write(0x05, fan_speeds[sysfan_speed].fan_in);  // SYSFANIN target speed
196                 break;
197         case FAN_CRUISE_CONTROL_THERMAL:
198                 printk(BIOS_DEBUG, "Fan Cruise Control setting system fan to activation at %d deg C/%d deg F\n",
199                                 temperatures[sysfan_temperature].deg_celsius,
200                                 temperatures[sysfan_temperature].deg_fahrenheit);
201                 hwm_write(0x05, temperatures[sysfan_temperature].deg_celsius); // SYSFANIN target temperature
202                 break;
203         }
204
205         hwm_write(0x0e, 0x02); // Fan Output Step Down Time
206         hwm_write(0x0f, 0x02); // Fan Output Step Up Time
207
208         hwm_write(0x47, 0xaf); // FAN divisor register
209         hwm_write(0x4b, 0x84); // AUXFANIN speed divisor
210
211         hwm_write(0x40, 0x01); // Init, but no SMI#
212 }
213
214 /* Audio Setup */
215
216 extern u32 * cim_verb_data;
217 extern u32 cim_verb_data_size;
218
219 static void verb_setup(void)
220 {
221         // Default VERB is fine on this mainboard.
222         cim_verb_data = NULL;
223         cim_verb_data_size = 0;
224 }
225
226 // mainboard_enable is executed as first thing after
227 // enumerate_buses().
228
229 static void mainboard_enable(device_t dev)
230 {
231 #if CONFIG_PCI_OPTION_ROM_RUN_YABEL
232         /* Install custom int15 handler for VGA OPROM */
233         int15_install();
234 #endif
235         verb_setup();
236         hwm_setup();
237 }
238
239 struct chip_operations mainboard_ops = {
240         CHIP_NAME("Kontron 986LCD-M Mainboard")
241         .enable_dev = mainboard_enable,
242 };
243