Josef Kellermann | bfa7ee5 | 2011-05-11 07:47:43 +0000 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2008 Advanced Micro Devices, Inc. |
| 5 | * Copyright (C) 2010 Siemens AG, Inc. |
| 6 | * (Written by Josef Kellermann <joseph.kellermann@heitec.de> for Siemens AG, Inc.) |
Stefan Reinauer | 5ff7c13 | 2011-10-31 12:56:45 -0700 | [diff] [blame] | 7 | * |
Josef Kellermann | bfa7ee5 | 2011-05-11 07:47:43 +0000 | [diff] [blame] | 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License as published by |
| 10 | * the Free Software Foundation; version 2 of the License. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License |
| 18 | * along with this program; if not, write to the Free Software |
| 19 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 20 | */ |
Stefan Reinauer | 5ff7c13 | 2011-10-31 12:56:45 -0700 | [diff] [blame] | 21 | |
Josef Kellermann | bfa7ee5 | 2011-05-11 07:47:43 +0000 | [diff] [blame] | 22 | #include <console/console.h> |
| 23 | #include <device/device.h> |
| 24 | #include <device/pci.h> |
| 25 | #include <arch/io.h> |
| 26 | #include <delay.h> |
| 27 | #include <boot/tables.h> |
| 28 | #include <cpu/x86/msr.h> |
| 29 | #include <cpu/amd/mtrr.h> |
| 30 | #include <device/pci_def.h> |
| 31 | #include <pc80/mc146818rtc.h> |
| 32 | #include <cpu/x86/lapic.h> |
| 33 | #include <southbridge/amd/sb600/sb600.h> |
| 34 | #include <southbridge/amd/rs690/chip.h> |
| 35 | #include <southbridge/amd/rs690/rs690.h> |
| 36 | #include <superio/ite/it8712f/it8712f.h> |
| 37 | #include "chip.h" |
| 38 | #if CONFIG_PCI_OPTION_ROM_RUN_YABEL |
| 39 | #include <x86emu/x86emu.h> |
| 40 | #endif |
| 41 | #include "int15_func.h" |
| 42 | |
| 43 | // ****LCD panel ID support: ***** |
| 44 | // Callback Sub-Function 00h - Get LCD Panel ID |
| 45 | #define PANEL_TABLE_ID_NO 0 // no LCD |
| 46 | #define PANEL_TABLE_ID1 1 // 1024x768_65MHz_Dual |
| 47 | #define PANEL_TABLE_ID2 2 // 920x1200_162MHz |
| 48 | #define PANEL_TABLE_ID3 3 // 600x1200_162MHz |
| 49 | #define PANEL_TABLE_ID4 4 // 1024x768_65MHz |
| 50 | #define PANEL_TABLE_ID5 5 // 1400x1050_108MHz |
| 51 | #define PANEL_TABLE_ID6 6 // 1680x1050_119MHz |
| 52 | #define PANEL_TABLE_ID7 7 // 2048x1536_164MHz |
| 53 | #define PANEL_TABLE_ID8 8 // 1280x1024_108MHz |
| 54 | #define PANEL_TABLE_ID9 9 // 1366x768_86MHz_chimei_V32B1L01 |
| 55 | |
| 56 | // Callback Sub-Function 05h Select Boot-up TV Standard |
| 57 | #define TV_MODE_00 0x00 /* NTSC */ |
| 58 | #define TV_MODE_01 0x01 /* PAL */ |
| 59 | #define TV_MODE_02 0x02 /* PALM */ |
| 60 | #define TV_MODE_03 0x03 /* PAL60 */ |
| 61 | #define TV_MODE_04 0x04 /* NTSCJ */ |
| 62 | #define TV_MODE_05 0x05 /* PALCN */ |
| 63 | #define TV_MODE_06 0x06 /* PALN */ |
| 64 | #define TV_MODE_09 0x09 /* SCART-RGB */ |
| 65 | #define TV_MODE_NO 0xff /* No TV Support */ |
| 66 | |
| 67 | #define PLX_VIDDID 0x861610b5 |
| 68 | |
| 69 | /* 7475 Common Registers */ |
| 70 | #define REG_DEVREV2 0x12 /* ADT7490 only */ |
| 71 | #define REG_VTT 0x1E /* ADT7490 only */ |
| 72 | #define REG_EXTEND3 0x1F /* ADT7490 only */ |
| 73 | #define REG_VOLTAGE_BASE 0x20 |
| 74 | #define REG_TEMP_BASE 0x25 |
| 75 | #define REG_TACH_BASE 0x28 |
| 76 | #define REG_PWM_BASE 0x30 |
| 77 | #define REG_PWM_MAX_BASE 0x38 |
| 78 | #define REG_DEVID 0x3D |
| 79 | #define REG_VENDID 0x3E |
| 80 | #define REG_DEVID2 0x3F |
| 81 | #define REG_STATUS1 0x41 |
| 82 | #define REG_STATUS2 0x42 |
| 83 | #define REG_VID 0x43 /* ADT7476 only */ |
| 84 | #define REG_VOLTAGE_MIN_BASE 0x44 |
| 85 | #define REG_VOLTAGE_MAX_BASE 0x45 |
| 86 | #define REG_TEMP_MIN_BASE 0x4E |
| 87 | #define REG_TEMP_MAX_BASE 0x4F |
| 88 | #define REG_TACH_MIN_BASE 0x54 |
| 89 | #define REG_PWM_CONFIG_BASE 0x5C |
| 90 | #define REG_TEMP_TRANGE_BASE 0x5F |
| 91 | #define REG_PWM_MIN_BASE 0x64 |
| 92 | #define REG_TEMP_TMIN_BASE 0x67 |
| 93 | #define REG_TEMP_THERM_BASE 0x6A |
| 94 | #define REG_REMOTE1_HYSTERSIS 0x6D |
| 95 | #define REG_REMOTE2_HYSTERSIS 0x6E |
| 96 | #define REG_TEMP_OFFSET_BASE 0x70 |
| 97 | #define REG_CONFIG2 0x73 |
| 98 | #define REG_EXTEND1 0x76 |
| 99 | #define REG_EXTEND2 0x77 |
| 100 | #define REG_CONFIG1 0x40 // ADT7475 |
| 101 | #define REG_CONFIG3 0x78 |
| 102 | #define REG_CONFIG5 0x7C |
| 103 | #define REG_CONFIG6 0x10 // ADT7475 |
| 104 | #define REG_CONFIG7 0x11 // ADT7475 |
| 105 | #define REG_CONFIG4 0x7D |
| 106 | #define REG_STATUS4 0x81 /* ADT7490 only */ |
| 107 | #define REG_VTT_MIN 0x84 /* ADT7490 only */ |
| 108 | #define REG_VTT_MAX 0x86 /* ADT7490 only */ |
| 109 | |
| 110 | #define VID_VIDSEL 0x80 /* ADT7476 only */ |
| 111 | |
| 112 | #define CONFIG2_ATTN 0x20 |
| 113 | #define CONFIG3_SMBALERT 0x01 |
| 114 | #define CONFIG3_THERM 0x02 |
| 115 | #define CONFIG4_PINFUNC 0x03 |
| 116 | #define CONFIG4_MAXDUTY 0x08 |
| 117 | #define CONFIG4_ATTN_IN10 0x30 |
| 118 | #define CONFIG4_ATTN_IN43 0xC0 |
| 119 | #define CONFIG5_TWOSCOMP 0x01 |
| 120 | #define CONFIG5_TEMPOFFSET 0x02 |
| 121 | #define CONFIG5_VIDGPIO 0x10 /* ADT7476 only */ |
| 122 | #define REMOTE1 0 |
| 123 | #define LOCAL 1 |
| 124 | #define REMOTE2 2 |
| 125 | |
| 126 | /* ADT7475 Settings */ |
| 127 | #define ADT7475_VOLTAGE_COUNT 5 /* Not counting Vtt */ |
| 128 | #define ADT7475_TEMP_COUNT 3 |
| 129 | #define ADT7475_TACH_COUNT 4 |
| 130 | #define ADT7475_PWM_COUNT 3 |
| 131 | |
| 132 | /* Macros to easily index the registers */ |
| 133 | #define TACH_REG(idx) (REG_TACH_BASE + ((idx) * 2)) |
| 134 | #define TACH_MIN_REG(idx) (REG_TACH_MIN_BASE + ((idx) * 2)) |
| 135 | |
| 136 | #define PWM_REG(idx) (REG_PWM_BASE + (idx)) |
| 137 | #define PWM_MAX_REG(idx) (REG_PWM_MAX_BASE + (idx)) |
| 138 | #define PWM_MIN_REG(idx) (REG_PWM_MIN_BASE + (idx)) |
| 139 | #define PWM_CONFIG_REG(idx) (REG_PWM_CONFIG_BASE + (idx)) |
| 140 | |
| 141 | #define VOLTAGE_REG(idx) (REG_VOLTAGE_BASE + (idx)) |
| 142 | #define VOLTAGE_MIN_REG(idx) (REG_VOLTAGE_MIN_BASE + ((idx) * 2)) |
| 143 | #define VOLTAGE_MAX_REG(idx) (REG_VOLTAGE_MAX_BASE + ((idx) * 2)) |
| 144 | |
| 145 | #define TEMP_REG(idx) (REG_TEMP_BASE + (idx)) |
| 146 | #define TEMP_MIN_REG(idx) (REG_TEMP_MIN_BASE + ((idx) * 2)) |
| 147 | #define TEMP_MAX_REG(idx) (REG_TEMP_MAX_BASE + ((idx) * 2)) |
| 148 | #define TEMP_TMIN_REG(idx) (REG_TEMP_TMIN_BASE + (idx)) |
| 149 | #define TEMP_THERM_REG(idx) (REG_TEMP_THERM_BASE + (idx)) |
| 150 | #define TEMP_OFFSET_REG(idx) (REG_TEMP_OFFSET_BASE + (idx)) |
| 151 | #define TEMP_TRANGE_REG(idx) (REG_TEMP_TRANGE_BASE + (idx)) |
| 152 | |
| 153 | #define SMBUS_IO_BASE 0x1000 |
| 154 | #define ADT7475_ADDRESS 0x2E |
| 155 | |
| 156 | #define D_OPEN (1 << 6) |
| 157 | #define D_CLS (1 << 5) |
| 158 | #define D_LCK (1 << 4) |
| 159 | #define G_SMRAME (1 << 3) |
| 160 | #define A_BASE_SEG ((0 << 2) | (1 << 1) | (0 << 0)) // 0x2: SMM space at 640KB-768KB |
| 161 | |
| 162 | extern int do_smbus_read_byte(u32 smbus_io_base, u32 device, u32 address); |
| 163 | extern int do_smbus_write_byte(u32 smbus_io_base, u32 device, u32 address, u8 val); |
| 164 | |
Josef Kellermann | bfa7ee5 | 2011-05-11 07:47:43 +0000 | [diff] [blame] | 165 | static u32 smbus_io_base = SMBUS_IO_BASE; |
| 166 | static u32 adt7475_address = ADT7475_ADDRESS; |
| 167 | |
| 168 | /* Macro to read the registers */ |
| 169 | #define adt7475_read_byte(reg) \ |
| 170 | do_smbus_read_byte(smbus_io_base, adt7475_address, reg) |
| 171 | |
| 172 | #define adt7475_write_byte(reg, val) \ |
| 173 | do_smbus_write_byte(smbus_io_base, adt7475_address, reg, val) |
Stefan Reinauer | 5ff7c13 | 2011-10-31 12:56:45 -0700 | [diff] [blame] | 174 | |
Josef Kellermann | bfa7ee5 | 2011-05-11 07:47:43 +0000 | [diff] [blame] | 175 | #define TWOS_COMPL 1 |
| 176 | |
| 177 | struct __table__{ |
| 178 | const char *info; |
| 179 | u8 val; |
| 180 | }; |
| 181 | |
| 182 | struct __table__ dutycycles[] = { |
| 183 | {"25%", 0x3f},{"30%", 0x4c},{"35%", 0x59},{"40%", 0x66},{"45%", 0x73}, |
| 184 | {"50%", 0x80},{"55%", 0x8d},{"60%", 0x9a},{"65%", 0xa7},{"70%", 0xb4}, |
| 185 | {"75%", 0xc1},{"80%", 0xce},{"85%", 0xdb},{"90%", 0xe8},{"95%", 0xf5}, |
| 186 | {"100%", 0xff} |
| 187 | }; |
| 188 | #define SIZEOF_DUTYCYCLES sizeof(dutycycles)/sizeof(struct __table__) |
| 189 | #define DUTYCYCLE(i,d) (i < SIZEOF_DUTYCYCLES) ? dutycycles[i].val : dutycycles[d].val // hopefully d is a correct value !!! fix |
| 190 | #define DUTYCYCLE_INFO(i) (i < SIZEOF_DUTYCYCLES) ? dutycycles[i].info : "out_of_range" |
| 191 | #if TWOS_COMPL == 0 |
| 192 | struct __table__ temperatures[] = { |
| 193 | {"30°C", 0x5e},{"35°C", 0x63},{"40°C", 0x68},{"45°C", 0x6d},{"50°C", 0x72}, |
| 194 | {"55°C", 0x77},{"60°C", 0x7c},{"65°C", 0x81},{"70°C", 0x86},{"75°C", 0x8b}, |
| 195 | {"80°C", 0x90} |
| 196 | }; |
| 197 | #else |
| 198 | struct __table__ temperatures[] = { |
| 199 | {"30°C", 30},{"35°C", 35},{"40°C", 40},{"45°C", 45},{"50°C", 50}, |
| 200 | {"55°C", 55},{"60°C", 60},{"65°C", 65},{"70°C", 70},{"75°C", 75}, |
| 201 | {"80°C", 80} |
| 202 | }; |
| 203 | #endif |
| 204 | int trange[] = {2.0,2.5,3.33,4.0,5.0,6.67,8.0,10.0,13.33,16.0,20.0,26.67,32.0,40.0,53.33,80.0}; |
| 205 | |
| 206 | #define SIZEOF_TEMPERATURES sizeof(temperatures)/sizeof(struct __table__) |
| 207 | #define TEMPERATURE(i,d) (i < SIZEOF_TEMPERATURES) ? temperatures[i].val : temperatures[d].val // hopefully d is a correct value !!! fix |
| 208 | #define TEMPERATURE_INFO(i) (i < SIZEOF_TEMPERATURES) ? temperatures[i].info : "out of range" |
| 209 | |
| 210 | struct fan_control { |
| 211 | unsigned int enable : 1; |
| 212 | u8 polarity; |
| 213 | u8 t_min; |
| 214 | u8 t_max; |
| 215 | u8 pwm_min; |
| 216 | u8 pwm_max; |
| 217 | u8 t_range; |
| 218 | }; |
| 219 | /* ############################################################################################# */ |
| 220 | #if CONFIG_PCI_OPTION_ROM_RUN_YABEL |
| 221 | static int int15_handler(void) |
| 222 | { |
| 223 | #define BOOT_DISPLAY_DEFAULT 0 |
| 224 | #define BOOT_DISPLAY_CRT (1 << 0) |
| 225 | #define BOOT_DISPLAY_TV (1 << 1) |
| 226 | #define BOOT_DISPLAY_EFP (1 << 2) |
| 227 | #define BOOT_DISPLAY_LCD (1 << 3) |
| 228 | #define BOOT_DISPLAY_CRT2 (1 << 4) |
| 229 | #define BOOT_DISPLAY_TV2 (1 << 5) |
| 230 | #define BOOT_DISPLAY_EFP2 (1 << 6) |
| 231 | #define BOOT_DISPLAY_LCD2 (1 << 7) |
| 232 | |
| 233 | printk(BIOS_DEBUG, "%s: AX=%04x BX=%04x CX=%04x DX=%04x\n", |
| 234 | __func__, M.x86.R_AX, M.x86.R_BX, M.x86.R_CX, M.x86.R_DX); |
| 235 | |
| 236 | switch (M.x86.R_AX) { |
| 237 | case 0x4e08: /* Boot Display */ |
| 238 | switch (M.x86.R_BX) { |
| 239 | case 0x80: |
| 240 | M.x86.R_AX &= ~(0xff); // Success |
| 241 | M.x86.R_BX &= ~(0xff); |
| 242 | printk(BIOS_DEBUG, "Integrated System Information\n"); |
| 243 | break; |
| 244 | case 0x00: |
| 245 | M.x86.R_AX &= ~(0xff); |
| 246 | M.x86.R_BX = 0x00; |
| 247 | printk(BIOS_DEBUG, "Panel ID = 0\n"); |
| 248 | break; |
| 249 | case 0x05: |
| 250 | M.x86.R_AX &= ~(0xff); |
| 251 | M.x86.R_BX = 0xff; |
| 252 | printk(BIOS_DEBUG, "TV = off\n"); |
| 253 | break; |
| 254 | default: |
| 255 | return 0; |
| 256 | } |
| 257 | break; |
| 258 | case 0x5f35: /* Boot Display */ |
| 259 | M.x86.R_AX = 0x005f; // Success |
| 260 | M.x86.R_CL = BOOT_DISPLAY_DEFAULT; |
| 261 | break; |
| 262 | case 0x5f40: /* Boot Panel Type */ |
| 263 | // M.x86.R_AX = 0x015f; // Supported but failed |
| 264 | M.x86.R_AX = 0x005f; // Success |
| 265 | M.x86.R_CL = 3; // Display ID |
| 266 | break; |
| 267 | default: |
| 268 | /* Interrupt was not handled */ |
| 269 | return 0; |
| 270 | } |
| 271 | |
| 272 | /* Interrupt handled */ |
| 273 | return 1; |
| 274 | } |
| 275 | |
| 276 | static void int15_install(void) |
| 277 | { |
| 278 | typedef int (* yabel_handleIntFunc)(void); |
| 279 | extern yabel_handleIntFunc yabel_intFuncArray[256]; |
| 280 | yabel_intFuncArray[0x15] = int15_handler; |
| 281 | } |
| 282 | #endif |
| 283 | /* ############################################################################################# */ |
| 284 | |
| 285 | /** |
Stefan Reinauer | 5ff7c13 | 2011-10-31 12:56:45 -0700 | [diff] [blame] | 286 | * @brief |
Josef Kellermann | bfa7ee5 | 2011-05-11 07:47:43 +0000 | [diff] [blame] | 287 | * |
Stefan Reinauer | 5ff7c13 | 2011-10-31 12:56:45 -0700 | [diff] [blame] | 288 | * @param |
Josef Kellermann | bfa7ee5 | 2011-05-11 07:47:43 +0000 | [diff] [blame] | 289 | */ |
| 290 | |
| 291 | static u8 calc_trange(u8 t_min, u8 t_max) { |
| 292 | |
| 293 | u8 prev; |
| 294 | int i; |
| 295 | int diff = t_max - t_min; |
Stefan Reinauer | 5ff7c13 | 2011-10-31 12:56:45 -0700 | [diff] [blame] | 296 | |
Josef Kellermann | bfa7ee5 | 2011-05-11 07:47:43 +0000 | [diff] [blame] | 297 | // walk through the trange table |
| 298 | for(i = 0, prev = 0; i < sizeof(trange)/sizeof(int); i++) { |
| 299 | if( trange[i] < diff ) { |
| 300 | prev = i; // save last val |
| 301 | continue; |
| 302 | } |
| 303 | if( diff == trange[i] ) return i; |
| 304 | if( (diff - trange[prev]) < (trange[i] - diff) ) break; // return with last val index |
| 305 | return i; |
Stefan Reinauer | 5ff7c13 | 2011-10-31 12:56:45 -0700 | [diff] [blame] | 306 | } |
Josef Kellermann | bfa7ee5 | 2011-05-11 07:47:43 +0000 | [diff] [blame] | 307 | return prev; |
| 308 | } |
| 309 | |
| 310 | /******************************************************** |
| 311 | * sina uses SB600 GPIO9 to detect IDE_DMA66. |
| 312 | * IDE_DMA66 is routed to GPIO 9. So we read Gpio 9 to |
| 313 | * get the cable type, 40 pin or 80 pin? |
| 314 | ********************************************************/ |
| 315 | static void cable_detect(void) |
| 316 | { |
| 317 | |
| 318 | u8 byte; |
| 319 | struct device *sm_dev; |
| 320 | struct device *ide_dev; |
Stefan Reinauer | 5ff7c13 | 2011-10-31 12:56:45 -0700 | [diff] [blame] | 321 | |
Josef Kellermann | bfa7ee5 | 2011-05-11 07:47:43 +0000 | [diff] [blame] | 322 | /* SMBus Module and ACPI Block (Device 20, Function 0) on SB600 */ |
| 323 | printk(BIOS_DEBUG, "%s.\n", __func__); |
| 324 | sm_dev = dev_find_slot(0, PCI_DEVFN(0x14, 0)); |
| 325 | |
| 326 | byte = pci_read_config8(sm_dev, 0xA9); |
| 327 | byte |= (1 << 5); /* Set Gpio9 as input */ |
| 328 | pci_write_config8(sm_dev, 0xA9, byte); |
Stefan Reinauer | 5ff7c13 | 2011-10-31 12:56:45 -0700 | [diff] [blame] | 329 | |
Josef Kellermann | bfa7ee5 | 2011-05-11 07:47:43 +0000 | [diff] [blame] | 330 | /* IDE Controller (Device 20, Function 1) on SB600 */ |
| 331 | ide_dev = dev_find_slot(0, PCI_DEVFN(0x14, 1)); |
| 332 | |
| 333 | byte = pci_read_config8(ide_dev, 9); |
| 334 | printk(BIOS_INFO, "IDE controller in %s Mode\n", byte & (1 << 0) ? "Native" : "Compatibility"); |
| 335 | |
| 336 | byte = pci_read_config8(ide_dev, 0x56); |
| 337 | byte &= ~(7 << 0); |
| 338 | if( pci_read_config8(sm_dev, 0xAA) & (1 << 5) ) |
| 339 | byte |= 2 << 0; /* mode 2 */ |
| 340 | else |
| 341 | byte |= 5 << 0; /* mode 5 */ |
| 342 | printk(BIOS_INFO, "DMA mode %d selected\n", byte & (7 << 0)); |
| 343 | pci_write_config8(ide_dev, 0x56, byte); |
| 344 | } |
| 345 | |
| 346 | /** |
| 347 | * @brief Detect the ADT7475 device |
| 348 | * |
Stefan Reinauer | 5ff7c13 | 2011-10-31 12:56:45 -0700 | [diff] [blame] | 349 | * @param |
Josef Kellermann | bfa7ee5 | 2011-05-11 07:47:43 +0000 | [diff] [blame] | 350 | */ |
Stefan Reinauer | 5ff7c13 | 2011-10-31 12:56:45 -0700 | [diff] [blame] | 351 | |
Josef Kellermann | bfa7ee5 | 2011-05-11 07:47:43 +0000 | [diff] [blame] | 352 | static const char * adt7475_detect( void ) { |
| 353 | |
| 354 | int vendid, devid, devid2; |
| 355 | const char *name = NULL; |
Stefan Reinauer | 5ff7c13 | 2011-10-31 12:56:45 -0700 | [diff] [blame] | 356 | |
Josef Kellermann | bfa7ee5 | 2011-05-11 07:47:43 +0000 | [diff] [blame] | 357 | vendid = adt7475_read_byte(REG_VENDID); |
| 358 | devid2 = adt7475_read_byte(REG_DEVID2); |
| 359 | if (vendid != 0x41 || /* Analog Devices */ |
| 360 | (devid2 & 0xf8) != 0x68) { |
| 361 | return name; |
| 362 | } |
| 363 | |
| 364 | devid = adt7475_read_byte(REG_DEVID); |
| 365 | if (devid == 0x73) |
| 366 | name = "adt7473"; |
| 367 | else if (devid == 0x75 && adt7475_address == 0x2e) |
| 368 | name = "adt7475"; |
| 369 | else if (devid == 0x76) |
| 370 | name = "adt7476"; |
| 371 | else if ((devid2 & 0xfc) == 0x6c) |
| 372 | name = "adt7490"; |
Stefan Reinauer | 5ff7c13 | 2011-10-31 12:56:45 -0700 | [diff] [blame] | 373 | |
Josef Kellermann | bfa7ee5 | 2011-05-11 07:47:43 +0000 | [diff] [blame] | 374 | return name; |
| 375 | } |
| 376 | |
| 377 | // thermal control defaults |
| 378 | const struct fan_control cpu_fan_control_defaults = { |
| 379 | .enable = 0, // disable by default |
| 380 | .polarity = 0, // high by default |
| 381 | .t_min = 3, // default = 45°C |
| 382 | .t_max = 7, // 65°C |
| 383 | .pwm_min = 1, // default dutycycle = 30% |
| 384 | .pwm_max = 13, // 90% |
| 385 | }; |
| 386 | const struct fan_control case_fan_control_defaults = { |
| 387 | .enable = 0, // disable by default |
| 388 | .polarity = 0, // high by default |
| 389 | .t_min = 2, // default = 40°C |
| 390 | .t_max = 8, // 70°C |
| 391 | .pwm_min = 0, // default dutycycle = 25% |
| 392 | .pwm_max = 13, // 90% |
| 393 | }; |
| 394 | |
| 395 | static void pm_init( void ) |
| 396 | { |
| 397 | u16 word; |
Stefan Reinauer | 5ff7c13 | 2011-10-31 12:56:45 -0700 | [diff] [blame] | 398 | u8 byte; |
Josef Kellermann | bfa7ee5 | 2011-05-11 07:47:43 +0000 | [diff] [blame] | 399 | device_t sm_dev = dev_find_slot(0, PCI_DEVFN(0x14, 0)); |
| 400 | |
| 401 | /* set SB600 GPIO 64 to GPIO with pull-up */ |
| 402 | byte = pm2_ioread(0x42); |
| 403 | byte &= 0x3f; |
| 404 | pm2_iowrite(0x42, byte); |
| 405 | |
| 406 | /* set GPIO 64 to tristate */ |
| 407 | word = pci_read_config16(sm_dev, 0x56); |
| 408 | word |= 1 << 7; |
| 409 | pci_write_config16(sm_dev, 0x56, word); |
| 410 | |
| 411 | /* set GPIO 64 internal pull-up */ |
| 412 | byte = pm2_ioread(0xf0); |
| 413 | byte &= 0xee; |
| 414 | pm2_iowrite(0xf0, byte); |
| 415 | |
| 416 | /* set Talert to be active low */ |
| 417 | byte = pm_ioread(0x67); |
| 418 | byte &= ~(1 << 5); |
| 419 | pm_iowrite(0x67, byte); |
| 420 | |
| 421 | /* set Talert to generate ACPI event */ |
| 422 | byte = pm_ioread(0x3c); |
| 423 | byte &= 0xf3; |
| 424 | pm_iowrite(0x3c, byte); |
Stefan Reinauer | 5ff7c13 | 2011-10-31 12:56:45 -0700 | [diff] [blame] | 425 | |
Josef Kellermann | bfa7ee5 | 2011-05-11 07:47:43 +0000 | [diff] [blame] | 426 | /* set GPM5 to not wake from s5 */ |
| 427 | byte = pm_ioread(0x77); |
| 428 | byte &= ~(1 << 5); |
| 429 | pm_iowrite(0x77, byte); |
| 430 | } |
| 431 | |
| 432 | /** |
| 433 | * @brief Setup thermal config on SINA Mainboard |
| 434 | * |
Stefan Reinauer | 5ff7c13 | 2011-10-31 12:56:45 -0700 | [diff] [blame] | 435 | * @param |
Josef Kellermann | bfa7ee5 | 2011-05-11 07:47:43 +0000 | [diff] [blame] | 436 | */ |
| 437 | |
| 438 | static void set_thermal_config(void) |
| 439 | { |
| 440 | u8 byte, byte2; |
| 441 | u8 cpu_pwm_conf, case_pwm_conf; |
| 442 | device_t sm_dev; |
| 443 | struct fan_control cpu_fan_control, case_fan_control; |
| 444 | const char *name = NULL; |
Stefan Reinauer | 5ff7c13 | 2011-10-31 12:56:45 -0700 | [diff] [blame] | 445 | |
| 446 | |
Josef Kellermann | bfa7ee5 | 2011-05-11 07:47:43 +0000 | [diff] [blame] | 447 | sm_dev = dev_find_slot(0, PCI_DEVFN(0x14, 0)); |
| 448 | smbus_io_base = pci_read_config32(sm_dev, 0x10) & ~(0xf); // get BAR0-Address which holds the SMBUS_IO_BASE |
Stefan Reinauer | 5ff7c13 | 2011-10-31 12:56:45 -0700 | [diff] [blame] | 449 | |
Josef Kellermann | bfa7ee5 | 2011-05-11 07:47:43 +0000 | [diff] [blame] | 450 | if( (name = adt7475_detect()) == NULL ) { |
| 451 | printk(BIOS_NOTICE, "Couldn't detect an ADT7473/75/76/90 part at %x:%x\n", smbus_io_base, adt7475_address); |
| 452 | return; |
| 453 | } |
| 454 | printk(BIOS_DEBUG, "Found %s part at %x:%x\n", name, smbus_io_base, adt7475_address); |
Stefan Reinauer | 5ff7c13 | 2011-10-31 12:56:45 -0700 | [diff] [blame] | 455 | |
Josef Kellermann | bfa7ee5 | 2011-05-11 07:47:43 +0000 | [diff] [blame] | 456 | cpu_fan_control = cpu_fan_control_defaults; |
| 457 | case_fan_control = case_fan_control_defaults; |
| 458 | |
| 459 | if( get_option(&byte, "cpu_fan_control") == -4 ) { |
| 460 | printk(BIOS_WARNING, "%s: CMOS checksum invalid, keeping default values\n",__func__); |
| 461 | } else { |
| 462 | // get all the options needed |
| 463 | if( get_option(&byte, "cpu_fan_control") == 0 ) |
| 464 | cpu_fan_control.enable = byte ? 1 : 0; |
Stefan Reinauer | 5ff7c13 | 2011-10-31 12:56:45 -0700 | [diff] [blame] | 465 | |
Josef Kellermann | bfa7ee5 | 2011-05-11 07:47:43 +0000 | [diff] [blame] | 466 | get_option(&cpu_fan_control.polarity, "cpu_fan_polarity"); |
| 467 | get_option(&cpu_fan_control.t_min, "cpu_t_min"); |
| 468 | get_option(&cpu_fan_control.t_max, "cpu_t_max"); |
| 469 | get_option(&cpu_fan_control.pwm_min, "cpu_dutycycle_min"); |
| 470 | get_option(&cpu_fan_control.pwm_max, "cpu_dutycycle_max"); |
| 471 | |
| 472 | if( get_option(&byte, "chassis_fan_control") == 0) |
Stefan Reinauer | 5ff7c13 | 2011-10-31 12:56:45 -0700 | [diff] [blame] | 473 | case_fan_control.enable = byte ? 1 : 0; |
| 474 | get_option(&case_fan_control.polarity, "chassis_fan_polarity"); |
Josef Kellermann | bfa7ee5 | 2011-05-11 07:47:43 +0000 | [diff] [blame] | 475 | get_option(&case_fan_control.t_min, "chassis_t_min"); |
| 476 | get_option(&case_fan_control.t_max, "chassis_t_max"); |
| 477 | get_option(&case_fan_control.pwm_min, "chassis_dutycycle_min"); |
| 478 | get_option(&case_fan_control.pwm_max, "chassis_dutycycle_max"); |
Stefan Reinauer | 5ff7c13 | 2011-10-31 12:56:45 -0700 | [diff] [blame] | 479 | |
Josef Kellermann | bfa7ee5 | 2011-05-11 07:47:43 +0000 | [diff] [blame] | 480 | } |
| 481 | |
| 482 | printk(BIOS_DEBUG, "cpu_fan_control:%s", cpu_fan_control.enable ? "enable" : "disable"); |
| 483 | printk(BIOS_DEBUG, " cpu_fan_polarity:%s", cpu_fan_control.polarity ? "low" : "high"); |
| 484 | |
| 485 | printk(BIOS_DEBUG, " cpu_t_min:%s", TEMPERATURE_INFO(cpu_fan_control.t_min)); |
| 486 | cpu_fan_control.t_min = TEMPERATURE(cpu_fan_control.t_min, cpu_fan_control_defaults.t_min); |
Stefan Reinauer | 5ff7c13 | 2011-10-31 12:56:45 -0700 | [diff] [blame] | 487 | |
Josef Kellermann | bfa7ee5 | 2011-05-11 07:47:43 +0000 | [diff] [blame] | 488 | printk(BIOS_DEBUG, " cpu_t_max:%s", TEMPERATURE_INFO(cpu_fan_control.t_max)); |
| 489 | cpu_fan_control.t_max = TEMPERATURE(cpu_fan_control.t_max, cpu_fan_control_defaults.t_max); |
Stefan Reinauer | 5ff7c13 | 2011-10-31 12:56:45 -0700 | [diff] [blame] | 490 | |
Josef Kellermann | bfa7ee5 | 2011-05-11 07:47:43 +0000 | [diff] [blame] | 491 | printk(BIOS_DEBUG, " cpu_pwm_min:%s", DUTYCYCLE_INFO(cpu_fan_control.pwm_min)); |
| 492 | cpu_fan_control.pwm_min = DUTYCYCLE(cpu_fan_control.pwm_min, cpu_fan_control_defaults.pwm_min); |
Stefan Reinauer | 5ff7c13 | 2011-10-31 12:56:45 -0700 | [diff] [blame] | 493 | |
Josef Kellermann | bfa7ee5 | 2011-05-11 07:47:43 +0000 | [diff] [blame] | 494 | printk(BIOS_DEBUG, " cpu_pwm_max:%s", DUTYCYCLE_INFO(cpu_fan_control.pwm_max)); |
| 495 | cpu_fan_control.pwm_max = DUTYCYCLE(cpu_fan_control.pwm_max, cpu_fan_control_defaults.pwm_max); |
Stefan Reinauer | 5ff7c13 | 2011-10-31 12:56:45 -0700 | [diff] [blame] | 496 | |
Josef Kellermann | bfa7ee5 | 2011-05-11 07:47:43 +0000 | [diff] [blame] | 497 | cpu_fan_control.t_range = calc_trange(cpu_fan_control.t_min, cpu_fan_control.t_max); |
| 498 | printk(BIOS_DEBUG, " cpu_t_range:0x%02x\n", cpu_fan_control.t_range); |
| 499 | cpu_fan_control.t_range <<= 4; |
| 500 | cpu_fan_control.t_range |= (4 << 0); // 35.3Hz |
Stefan Reinauer | 5ff7c13 | 2011-10-31 12:56:45 -0700 | [diff] [blame] | 501 | |
Josef Kellermann | bfa7ee5 | 2011-05-11 07:47:43 +0000 | [diff] [blame] | 502 | printk(BIOS_DEBUG, "chassis_fan_control:%s", case_fan_control.enable ? "enable" : "disable"); |
| 503 | printk(BIOS_DEBUG, " chassis_fan_polarity:%s", case_fan_control.polarity ? "low" : "high"); |
| 504 | |
| 505 | printk(BIOS_DEBUG, " chassis_t_min:%s", TEMPERATURE_INFO(case_fan_control.t_min)); |
| 506 | case_fan_control.t_min = TEMPERATURE(case_fan_control.t_min, case_fan_control_defaults.t_min); |
Stefan Reinauer | 5ff7c13 | 2011-10-31 12:56:45 -0700 | [diff] [blame] | 507 | |
Josef Kellermann | bfa7ee5 | 2011-05-11 07:47:43 +0000 | [diff] [blame] | 508 | printk(BIOS_DEBUG, " chassis_t_max:%s", TEMPERATURE_INFO(case_fan_control.t_max)); |
| 509 | case_fan_control.t_max = TEMPERATURE(case_fan_control.t_max, case_fan_control_defaults.t_max); |
Stefan Reinauer | 5ff7c13 | 2011-10-31 12:56:45 -0700 | [diff] [blame] | 510 | |
Josef Kellermann | bfa7ee5 | 2011-05-11 07:47:43 +0000 | [diff] [blame] | 511 | printk(BIOS_DEBUG, " chassis_pwm_min:%s", DUTYCYCLE_INFO(case_fan_control.pwm_min)); |
| 512 | case_fan_control.pwm_min = DUTYCYCLE(case_fan_control.pwm_min, case_fan_control_defaults.pwm_min); |
Stefan Reinauer | 5ff7c13 | 2011-10-31 12:56:45 -0700 | [diff] [blame] | 513 | |
Josef Kellermann | bfa7ee5 | 2011-05-11 07:47:43 +0000 | [diff] [blame] | 514 | printk(BIOS_DEBUG, " chassis_pwm_max:%s", DUTYCYCLE_INFO(case_fan_control.pwm_max)); |
| 515 | case_fan_control.pwm_max = DUTYCYCLE(case_fan_control.pwm_max, case_fan_control_defaults.pwm_max); |
Stefan Reinauer | 5ff7c13 | 2011-10-31 12:56:45 -0700 | [diff] [blame] | 516 | |
Josef Kellermann | bfa7ee5 | 2011-05-11 07:47:43 +0000 | [diff] [blame] | 517 | case_fan_control.t_range = calc_trange(case_fan_control.t_min, case_fan_control.t_max); |
| 518 | printk(BIOS_DEBUG, " case_t_range:0x%02x\n", case_fan_control.t_range); |
| 519 | case_fan_control.t_range <<= 4; |
| 520 | case_fan_control.t_range |= (4 << 0); // 35.3Hz |
Stefan Reinauer | 5ff7c13 | 2011-10-31 12:56:45 -0700 | [diff] [blame] | 521 | |
Josef Kellermann | bfa7ee5 | 2011-05-11 07:47:43 +0000 | [diff] [blame] | 522 | cpu_pwm_conf = (((cpu_fan_control.polarity & 0x1) << 4) | 0x2); // bit 4 control polarity of PWMx output |
| 523 | case_pwm_conf = (((case_fan_control.polarity & 0x1) << 4) | 0x2); // bit 4 control polarity of PWMx output |
Stefan Reinauer | 5ff7c13 | 2011-10-31 12:56:45 -0700 | [diff] [blame] | 524 | cpu_pwm_conf |= cpu_fan_control.enable ? (0 << 5) : (7 << 5); // manual control |
Josef Kellermann | bfa7ee5 | 2011-05-11 07:47:43 +0000 | [diff] [blame] | 525 | case_pwm_conf |= case_fan_control.enable ? (1 << 5) : (7 << 5); // local temp |
Stefan Reinauer | 5ff7c13 | 2011-10-31 12:56:45 -0700 | [diff] [blame] | 526 | |
Josef Kellermann | bfa7ee5 | 2011-05-11 07:47:43 +0000 | [diff] [blame] | 527 | /* set adt7475 */ |
| 528 | |
| 529 | adt7475_write_byte(REG_CONFIG1, 0x04); // clear register, bit 2 is read only |
Stefan Reinauer | 5ff7c13 | 2011-10-31 12:56:45 -0700 | [diff] [blame] | 530 | |
Josef Kellermann | bfa7ee5 | 2011-05-11 07:47:43 +0000 | [diff] [blame] | 531 | /* Config Register 6: */ |
| 532 | adt7475_write_byte(REG_CONFIG6, 0x00); |
| 533 | /* Config Register 7 */ |
| 534 | adt7475_write_byte(REG_CONFIG7, 0x00); |
| 535 | |
| 536 | /* Config Register 5: */ |
| 537 | /* set Offset 64 format, enable THERM on Remote 1& Local */ |
Stefan Reinauer | 5ff7c13 | 2011-10-31 12:56:45 -0700 | [diff] [blame] | 538 | adt7475_write_byte(REG_CONFIG5, TWOS_COMPL ? 0x61 : 0x60); |
Josef Kellermann | bfa7ee5 | 2011-05-11 07:47:43 +0000 | [diff] [blame] | 539 | /* No offset for remote 1 */ |
| 540 | adt7475_write_byte(TEMP_OFFSET_REG(0), 0x00); |
| 541 | /* No offset for local */ |
| 542 | adt7475_write_byte(TEMP_OFFSET_REG(1), 0x00); |
| 543 | /* No offset for remote 2 */ |
| 544 | adt7475_write_byte(TEMP_OFFSET_REG(2), 0x00); |
Stefan Reinauer | 5ff7c13 | 2011-10-31 12:56:45 -0700 | [diff] [blame] | 545 | |
Josef Kellermann | bfa7ee5 | 2011-05-11 07:47:43 +0000 | [diff] [blame] | 546 | /* remote 1 low temp limit */ |
| 547 | adt7475_write_byte(TEMP_MIN_REG(0), 0x00); |
| 548 | /* remote 1 High temp limit (90C) */ |
| 549 | adt7475_write_byte(TEMP_MAX_REG(0), 0x9a); |
| 550 | |
| 551 | /* local Low Temp Limit */ |
| 552 | adt7475_write_byte(TEMP_MIN_REG(1), 0x00); |
| 553 | /* local High Limit (90C) */ |
| 554 | adt7475_write_byte(TEMP_MAX_REG(1), 0x9a); |
| 555 | |
| 556 | /* remote 1 therm temp limit (95C) */ |
| 557 | adt7475_write_byte(TEMP_THERM_REG(0), 0x9f); |
| 558 | /* local therm temp limit (95C) */ |
| 559 | adt7475_write_byte(TEMP_THERM_REG(1), 0x9f); |
Stefan Reinauer | 5ff7c13 | 2011-10-31 12:56:45 -0700 | [diff] [blame] | 560 | |
Josef Kellermann | bfa7ee5 | 2011-05-11 07:47:43 +0000 | [diff] [blame] | 561 | /* PWM 1 configuration register CPU fan controlled by CPU Thermal Diode */ |
| 562 | adt7475_write_byte(PWM_CONFIG_REG(0), cpu_pwm_conf); |
| 563 | /* PWM 3 configuration register Case fan controlled by ADTxxxx temp */ |
| 564 | adt7475_write_byte(PWM_CONFIG_REG(2), case_pwm_conf); |
| 565 | |
| 566 | if( cpu_fan_control.enable ) { |
| 567 | /* PWM 1 minimum duty cycle (37%) */ |
| 568 | adt7475_write_byte(PWM_MIN_REG(0), cpu_fan_control.pwm_min); |
| 569 | /* PWM 1 Maximum duty cycle (100%) */ |
| 570 | adt7475_write_byte(PWM_MAX_REG(0), cpu_fan_control.pwm_max); |
| 571 | /* Remote 1 temperature Tmin (32C) */ |
| 572 | adt7475_write_byte(TEMP_TMIN_REG(0), cpu_fan_control.t_min); |
| 573 | /* remote 1 Trange (53C ramp range) */ |
| 574 | adt7475_write_byte(TEMP_TRANGE_REG(0), cpu_fan_control.t_range); |
| 575 | } else { |
| 576 | adt7475_write_byte(PWM_REG(0), cpu_fan_control.pwm_max); |
| 577 | } |
Stefan Reinauer | 5ff7c13 | 2011-10-31 12:56:45 -0700 | [diff] [blame] | 578 | |
Josef Kellermann | bfa7ee5 | 2011-05-11 07:47:43 +0000 | [diff] [blame] | 579 | if( case_fan_control.enable ) { |
| 580 | /* PWM 2 minimum duty cycle (37%) */ |
| 581 | adt7475_write_byte(PWM_MIN_REG(2), case_fan_control.pwm_min); |
| 582 | /* PWM 2 Maximum Duty Cycle (100%) */ |
| 583 | adt7475_write_byte(PWM_MAX_REG(2), case_fan_control.pwm_max); |
| 584 | /* local temperature Tmin (32C) */ |
| 585 | adt7475_write_byte(TEMP_TMIN_REG(1), case_fan_control.t_min); |
| 586 | /* local Trange (53C ramp range) */ |
| 587 | adt7475_write_byte(TEMP_TRANGE_REG(1), case_fan_control.t_range); // Local TRange |
| 588 | adt7475_write_byte(TEMP_TRANGE_REG(2), case_fan_control.t_range); // PWM2 Freq |
| 589 | } else { |
| 590 | adt7475_write_byte(PWM_REG(2), case_fan_control.pwm_max); |
| 591 | } |
| 592 | |
| 593 | /* Config Register 3 - enable smbalert & therm */ |
| 594 | adt7475_write_byte(0x78, 0x03); |
| 595 | /* Config Register 4 - enable therm output */ |
| 596 | adt7475_write_byte(0x7d, 0x09); |
| 597 | /* Interrupt Mask Register 2 - Mask SMB alert for Therm Conditions, Fan 3 fault, SmbAlert Fan for Therm Timer event */ |
| 598 | adt7475_write_byte(0x75, 0x2e); |
Stefan Reinauer | 5ff7c13 | 2011-10-31 12:56:45 -0700 | [diff] [blame] | 599 | |
Josef Kellermann | bfa7ee5 | 2011-05-11 07:47:43 +0000 | [diff] [blame] | 600 | /* Config Register 1 Set Start bit */ |
| 601 | adt7475_write_byte(0x40, 0x05); |
Stefan Reinauer | 5ff7c13 | 2011-10-31 12:56:45 -0700 | [diff] [blame] | 602 | |
Josef Kellermann | bfa7ee5 | 2011-05-11 07:47:43 +0000 | [diff] [blame] | 603 | /* Read status register to clear any old errors */ |
| 604 | byte2 = adt7475_read_byte(0x42); |
| 605 | byte = adt7475_read_byte(0x41); |
| 606 | |
| 607 | printk(BIOS_DEBUG, "Init 'Thermal Monitor' end , status 0x42 = 0x%02x, status 0x41 = 0x%02x\n", |
| 608 | byte2, byte); |
| 609 | |
| 610 | } |
| 611 | |
| 612 | /** |
Stefan Reinauer | 5ff7c13 | 2011-10-31 12:56:45 -0700 | [diff] [blame] | 613 | * @brief |
Josef Kellermann | bfa7ee5 | 2011-05-11 07:47:43 +0000 | [diff] [blame] | 614 | * |
Stefan Reinauer | 5ff7c13 | 2011-10-31 12:56:45 -0700 | [diff] [blame] | 615 | * @param |
Josef Kellermann | bfa7ee5 | 2011-05-11 07:47:43 +0000 | [diff] [blame] | 616 | */ |
| 617 | |
| 618 | static void patch_mmio_nonposted( void ) |
| 619 | { |
Stefan Reinauer | 5ff7c13 | 2011-10-31 12:56:45 -0700 | [diff] [blame] | 620 | unsigned reg, index; |
Josef Kellermann | bfa7ee5 | 2011-05-11 07:47:43 +0000 | [diff] [blame] | 621 | resource_t rbase, rend; |
| 622 | u32 base, limit; |
| 623 | struct resource *resource; |
| 624 | device_t dev; |
| 625 | device_t k8_f1 = dev_find_slot(0, PCI_DEVFN(0x18,1)); |
Stefan Reinauer | 5ff7c13 | 2011-10-31 12:56:45 -0700 | [diff] [blame] | 626 | |
Josef Kellermann | bfa7ee5 | 2011-05-11 07:47:43 +0000 | [diff] [blame] | 627 | printk(BIOS_DEBUG,"%s ...\n", __func__); |
| 628 | |
| 629 | dev = dev_find_slot(1, PCI_DEVFN(5,0)); |
| 630 | // the uma frame buffer |
| 631 | index = 0x10; |
| 632 | resource = probe_resource(dev, index); |
| 633 | if( resource ) { |
| 634 | // fixup resource nonposted in k8 mmio |
| 635 | /* Get the base address */ |
| 636 | rbase = (resource->base >> 8) & ~(0xff); |
| 637 | /* Get the limit (rounded up) */ |
| 638 | rend = (resource_end(resource) >> 8) & ~(0xff); |
Stefan Reinauer | 5ff7c13 | 2011-10-31 12:56:45 -0700 | [diff] [blame] | 639 | |
Josef Kellermann | bfa7ee5 | 2011-05-11 07:47:43 +0000 | [diff] [blame] | 640 | printk(BIOS_DEBUG,"%s %x base = %0llx limit = %0llx\n", dev_path(dev), index, rbase, rend); |
| 641 | |
| 642 | for( reg = 0xb8; reg >= 0x80; reg -= 8 ) { |
| 643 | base = pci_read_config32(k8_f1,reg); |
| 644 | limit = pci_read_config32(k8_f1,reg+4); |
| 645 | printk(BIOS_DEBUG," %02x[%08x] %02x[%08x]", reg, base, reg+4, limit); |
| 646 | if( ((base & ~(0xff)) == rbase) && ((limit & ~(0xff)) == rend) ) { |
Stefan Reinauer | 5ff7c13 | 2011-10-31 12:56:45 -0700 | [diff] [blame] | 647 | limit |= (1 << 7); |
Josef Kellermann | bfa7ee5 | 2011-05-11 07:47:43 +0000 | [diff] [blame] | 648 | printk(BIOS_DEBUG, "\nPatching %s %x <- %08x", dev_path(k8_f1), reg, limit); |
Stefan Reinauer | 5ff7c13 | 2011-10-31 12:56:45 -0700 | [diff] [blame] | 649 | pci_write_config32(k8_f1, reg+4, limit); |
Josef Kellermann | bfa7ee5 | 2011-05-11 07:47:43 +0000 | [diff] [blame] | 650 | break; |
| 651 | } |
| 652 | } |
| 653 | printk(BIOS_DEBUG, "\n"); |
| 654 | } |
| 655 | } |
| 656 | |
| 657 | /** |
Stefan Reinauer | 5ff7c13 | 2011-10-31 12:56:45 -0700 | [diff] [blame] | 658 | * @brief |
Josef Kellermann | bfa7ee5 | 2011-05-11 07:47:43 +0000 | [diff] [blame] | 659 | * |
Stefan Reinauer | 5ff7c13 | 2011-10-31 12:56:45 -0700 | [diff] [blame] | 660 | * @param |
Josef Kellermann | bfa7ee5 | 2011-05-11 07:47:43 +0000 | [diff] [blame] | 661 | */ |
Stefan Reinauer | 5ff7c13 | 2011-10-31 12:56:45 -0700 | [diff] [blame] | 662 | |
Josef Kellermann | bfa7ee5 | 2011-05-11 07:47:43 +0000 | [diff] [blame] | 663 | struct { |
| 664 | unsigned int bus; |
| 665 | unsigned int devfn; |
| 666 | } slot[] = { |
| 667 | {0, PCI_DEVFN(0,0)}, |
| 668 | {0, PCI_DEVFN(18,0)}, |
| 669 | {0, PCI_DEVFN(19,0)},{0, PCI_DEVFN(19,1)},{0, PCI_DEVFN(19,2)},{0, PCI_DEVFN(19,3)},{0, PCI_DEVFN(19,4)},{0, PCI_DEVFN(19,5)}, |
| 670 | {0, PCI_DEVFN(20,0)},{0, PCI_DEVFN(20,1)},{0, PCI_DEVFN(20,2)},{0, PCI_DEVFN(20,3)},{0, PCI_DEVFN(20,5)},{0, PCI_DEVFN(20,6)}, |
| 671 | {0, PCI_DEVFN(5,0)},{0, PCI_DEVFN(5,2)}, |
| 672 | {255,0}, |
| 673 | }; |
Stefan Reinauer | 5ff7c13 | 2011-10-31 12:56:45 -0700 | [diff] [blame] | 674 | |
Josef Kellermann | bfa7ee5 | 2011-05-11 07:47:43 +0000 | [diff] [blame] | 675 | |
| 676 | static void update_subsystemid( device_t dev ) { |
| 677 | |
| 678 | int i; |
| 679 | struct mainboard_config *mb = dev->chip_info; |
Stefan Reinauer | 5ff7c13 | 2011-10-31 12:56:45 -0700 | [diff] [blame] | 680 | |
Josef Kellermann | bfa7ee5 | 2011-05-11 07:47:43 +0000 | [diff] [blame] | 681 | dev->subsystem_vendor = 0x110a; |
| 682 | if( mb->plx_present ){ |
| 683 | dev->subsystem_device = 0x4076; // U1P1 = 0x4076, U1P0 = 0x4077 |
| 684 | } else { |
| 685 | dev->subsystem_device = 0x4077; // U1P0 = 0x4077 |
| 686 | } |
| 687 | printk(BIOS_INFO, "%s [%x/%x]\n", dev->chip_ops->name, dev->subsystem_vendor, dev->subsystem_device ); |
| 688 | for( i=0; slot[i].bus < 255; i++) { |
| 689 | device_t d; |
| 690 | d = dev_find_slot(slot[i].bus,slot[i].devfn); |
| 691 | if( d ) { |
| 692 | printk(BIOS_DEBUG,"%s subsystem <- %x/%x\n", dev_path(d), dev->subsystem_vendor, dev->subsystem_device); |
| 693 | d->subsystem_device = dev->subsystem_device; |
| 694 | } |
| 695 | } |
| 696 | } |
| 697 | |
| 698 | /** |
Stefan Reinauer | 5ff7c13 | 2011-10-31 12:56:45 -0700 | [diff] [blame] | 699 | * @brief |
Josef Kellermann | bfa7ee5 | 2011-05-11 07:47:43 +0000 | [diff] [blame] | 700 | * |
Stefan Reinauer | 5ff7c13 | 2011-10-31 12:56:45 -0700 | [diff] [blame] | 701 | * @param |
Josef Kellermann | bfa7ee5 | 2011-05-11 07:47:43 +0000 | [diff] [blame] | 702 | */ |
| 703 | |
| 704 | static void detect_hw_variant( device_t dev ) { |
| 705 | |
| 706 | device_t nb_dev =0, dev2 = 0; |
| 707 | struct southbridge_amd_rs690_config *cfg; |
| 708 | u32 lc_state, id = 0; |
| 709 | struct mainboard_config *mb = dev->chip_info; |
Stefan Reinauer | 5ff7c13 | 2011-10-31 12:56:45 -0700 | [diff] [blame] | 710 | |
Josef Kellermann | bfa7ee5 | 2011-05-11 07:47:43 +0000 | [diff] [blame] | 711 | printk(BIOS_INFO, "Scan for PLX device ...\n"); |
| 712 | nb_dev = dev_find_slot(0, PCI_DEVFN(0, 0)); |
| 713 | if (!nb_dev) { |
| 714 | die("CAN NOT FIND RS690 DEVICE, HALT!\n"); |
| 715 | /* NOT REACHED */ |
| 716 | } |
| 717 | |
| 718 | dev2 = dev_find_slot(0, PCI_DEVFN(2, 0)); |
| 719 | if (!dev2) { |
| 720 | die("CAN NOT FIND GFX DEVICE 2, HALT!\n"); |
| 721 | /* NOT REACHED */ |
| 722 | } |
| 723 | PcieReleasePortTraining(nb_dev, dev2, 2); // we assume PLX is connected to port 2 |
| 724 | |
| 725 | mdelay(40); |
| 726 | lc_state = nbpcie_p_read_index(dev2, 0xa5); /* lc_state */ |
| 727 | printk(BIOS_DEBUG, "lc current state=%x\n", lc_state); |
| 728 | /* LC_CURRENT_STATE = bit0-5 */ |
| 729 | switch( lc_state & 0x3f ){ |
| 730 | case 0x00: |
| 731 | case 0x01: |
| 732 | case 0x02: |
| 733 | case 0x03: |
| 734 | case 0x04: |
| 735 | printk(BIOS_NOTICE, "No device present, skipping PLX scan ..\n"); |
| 736 | break; |
| 737 | case 0x07: |
| 738 | case 0x10: |
| 739 | { |
| 740 | struct device dummy; |
| 741 | u32 pci_primary_bus, buses; |
| 742 | u16 secondary, subordinate; |
Stefan Reinauer | 5ff7c13 | 2011-10-31 12:56:45 -0700 | [diff] [blame] | 743 | |
| 744 | printk(BIOS_DEBUG, "Scan for PLX bridge behind %s[%x]\n", dev_path(dev2), pci_read_config32(dev2, PCI_VENDOR_ID)); |
Josef Kellermann | bfa7ee5 | 2011-05-11 07:47:43 +0000 | [diff] [blame] | 745 | // save the existing primary/secondary/subordinate bus number configuration. |
| 746 | secondary = dev2->bus->secondary; |
| 747 | subordinate = dev2->bus->subordinate; |
| 748 | buses = pci_primary_bus = pci_read_config32(dev2, PCI_PRIMARY_BUS); |
| 749 | |
| 750 | // Configure the bus numbers for this bridge |
Stefan Reinauer | 5ff7c13 | 2011-10-31 12:56:45 -0700 | [diff] [blame] | 751 | // bus number 1 is for internal gfx device, so we start with busnumber 2 |
Josef Kellermann | bfa7ee5 | 2011-05-11 07:47:43 +0000 | [diff] [blame] | 752 | |
| 753 | buses &= 0xff000000; |
| 754 | buses |= ((2 << 8) | (0xff << 16)); |
Stefan Reinauer | 5ff7c13 | 2011-10-31 12:56:45 -0700 | [diff] [blame] | 755 | // setup the buses in device 2 |
Josef Kellermann | bfa7ee5 | 2011-05-11 07:47:43 +0000 | [diff] [blame] | 756 | pci_write_config32(dev2,PCI_PRIMARY_BUS, buses); |
| 757 | |
| 758 | // fake a device descriptor for a device behind device 2 |
| 759 | dummy.bus = dev2->bus; |
| 760 | dummy.bus->secondary = (buses >> 8) & 0xff; |
| 761 | dummy.bus->subordinate = (buses >> 16) & 0xff; |
| 762 | dummy.path.type = DEVICE_PATH_PCI; |
| 763 | dummy.path.pci.devfn = PCI_DEVFN(0,0); // PLX: device number 0, function 0 |
| 764 | |
| 765 | id = pci_read_config32(&dummy, PCI_VENDOR_ID); |
| 766 | /* Have we found something? |
| 767 | * Some broken boards return 0 if a slot is empty, but |
| 768 | * the expected answer is 0xffffffff |
Stefan Reinauer | 5ff7c13 | 2011-10-31 12:56:45 -0700 | [diff] [blame] | 769 | */ |
Josef Kellermann | bfa7ee5 | 2011-05-11 07:47:43 +0000 | [diff] [blame] | 770 | if ((id == 0xffffffff) || (id == 0x00000000) || (id == 0x0000ffff) || (id == 0xffff0000)) { |
| 771 | printk(BIOS_DEBUG, "%s, bad id 0x%x\n", dev_path(&dummy), id); |
| 772 | } else { |
| 773 | printk(BIOS_DEBUG, "found device [%x]\n", id); |
| 774 | } |
| 775 | // restore changes made for device 2 |
| 776 | dev2->bus->secondary = secondary; |
| 777 | dev2->bus->secondary = subordinate; |
| 778 | pci_write_config32(dev2, PCI_PRIMARY_BUS, pci_primary_bus); |
| 779 | } |
| 780 | break; |
| 781 | default: |
| 782 | break; |
| 783 | } |
Stefan Reinauer | 5ff7c13 | 2011-10-31 12:56:45 -0700 | [diff] [blame] | 784 | |
| 785 | mb->plx_present = 0; |
Josef Kellermann | bfa7ee5 | 2011-05-11 07:47:43 +0000 | [diff] [blame] | 786 | if( id == PLX_VIDDID ){ |
| 787 | printk(BIOS_INFO, "found PLX device\n"); |
| 788 | mb->plx_present = 1; |
| 789 | cfg = (struct southbridge_amd_rs690_config *)dev2->chip_info; |
| 790 | if( cfg->gfx_tmds ) { |
| 791 | printk(BIOS_INFO, "Disable 'gfx_tmds' support\n"); |
| 792 | cfg->gfx_tmds = 0; |
| 793 | cfg->gfx_link_width = 4; |
| 794 | } |
| 795 | return; |
Stefan Reinauer | 5ff7c13 | 2011-10-31 12:56:45 -0700 | [diff] [blame] | 796 | } |
Josef Kellermann | bfa7ee5 | 2011-05-11 07:47:43 +0000 | [diff] [blame] | 797 | } |
| 798 | |
| 799 | static void smm_lock( void ) |
| 800 | { |
| 801 | /* LOCK the SMM memory window and enable normal SMM. |
| 802 | * After running this function, only a full reset can |
| 803 | * make the SMM registers writable again. |
| 804 | */ |
| 805 | printk(BIOS_DEBUG, "Locking SMM.\n"); |
| 806 | pci_write_config8(dev_find_slot(0, PCI_DEVFN(0, 0)), 0x69, |
| 807 | D_LCK | G_SMRAME | A_BASE_SEG); |
| 808 | } |
| 809 | |
| 810 | /** |
| 811 | * @brief Init |
| 812 | * |
| 813 | * @param the root device |
| 814 | */ |
Stefan Reinauer | 5ff7c13 | 2011-10-31 12:56:45 -0700 | [diff] [blame] | 815 | |
Josef Kellermann | bfa7ee5 | 2011-05-11 07:47:43 +0000 | [diff] [blame] | 816 | static void init(device_t dev) |
| 817 | { |
Patrick Georgi | e166782 | 2012-05-05 15:29:32 +0200 | [diff] [blame] | 818 | #if !CONFIG_PCI_OPTION_ROM_RUN_YABEL |
Josef Kellermann | bfa7ee5 | 2011-05-11 07:47:43 +0000 | [diff] [blame] | 819 | INT15_function_extensions int15_func; |
| 820 | #endif |
Stefan Reinauer | 5ff7c13 | 2011-10-31 12:56:45 -0700 | [diff] [blame] | 821 | |
Josef Kellermann | bfa7ee5 | 2011-05-11 07:47:43 +0000 | [diff] [blame] | 822 | printk(BIOS_DEBUG, "%s %s[%x/%x] %s\n", |
| 823 | dev->chip_ops->name, dev_path(dev), dev->subsystem_vendor, dev->subsystem_device, __func__); |
Stefan Reinauer | 5ff7c13 | 2011-10-31 12:56:45 -0700 | [diff] [blame] | 824 | |
Patrick Georgi | e166782 | 2012-05-05 15:29:32 +0200 | [diff] [blame] | 825 | #if !CONFIG_PCI_OPTION_ROM_RUN_YABEL |
Josef Kellermann | bfa7ee5 | 2011-05-11 07:47:43 +0000 | [diff] [blame] | 826 | if( get_option(&int15_func.regs.func00_LCD_panel_id, "lcd_panel_id") < 0 ) |
| 827 | int15_func.regs.func00_LCD_panel_id = PANEL_TABLE_ID_NO; |
| 828 | int15_func.regs.func05_TV_standard = TV_MODE_NO; |
| 829 | install_INT15_function_extensions(&int15_func); |
| 830 | #endif |
| 831 | set_thermal_config(); |
| 832 | pm_init(); |
| 833 | cable_detect(); |
| 834 | patch_mmio_nonposted(); |
| 835 | smm_lock(); |
| 836 | } |
| 837 | |
| 838 | /************************************************* |
| 839 | * enable the dedicated function in sina board. |
| 840 | * This function called early than rs690_enable. |
| 841 | *************************************************/ |
| 842 | static void enable_dev(device_t dev) |
| 843 | { |
Stefan Reinauer | 5ff7c13 | 2011-10-31 12:56:45 -0700 | [diff] [blame] | 844 | |
Josef Kellermann | bfa7ee5 | 2011-05-11 07:47:43 +0000 | [diff] [blame] | 845 | printk(BIOS_INFO, "%s %s[%x/%x] %s\n", |
| 846 | dev->chip_ops->name, dev_path(dev), dev->subsystem_vendor, dev->subsystem_device, __func__); |
| 847 | #if CONFIG_PCI_OPTION_ROM_RUN_YABEL |
| 848 | /* Install custom int15 handler for VGA OPROM */ |
| 849 | int15_install(); |
| 850 | #endif |
| 851 | |
| 852 | detect_hw_variant(dev); |
| 853 | update_subsystemid(dev); |
Kyösti Mälkki | ba589e3 | 2012-07-11 08:03:13 +0300 | [diff] [blame] | 854 | setup_uma_memory(); |
Josef Kellermann | bfa7ee5 | 2011-05-11 07:47:43 +0000 | [diff] [blame] | 855 | |
Stefan Reinauer | 5ff7c13 | 2011-10-31 12:56:45 -0700 | [diff] [blame] | 856 | dev->ops->init = init; // rest of mainboard init later |
Josef Kellermann | bfa7ee5 | 2011-05-11 07:47:43 +0000 | [diff] [blame] | 857 | } |
| 858 | |
| 859 | /** |
Stefan Reinauer | 5ff7c13 | 2011-10-31 12:56:45 -0700 | [diff] [blame] | 860 | * @brief |
Josef Kellermann | bfa7ee5 | 2011-05-11 07:47:43 +0000 | [diff] [blame] | 861 | * |
Stefan Reinauer | 5ff7c13 | 2011-10-31 12:56:45 -0700 | [diff] [blame] | 862 | * @param |
Josef Kellermann | bfa7ee5 | 2011-05-11 07:47:43 +0000 | [diff] [blame] | 863 | */ |
| 864 | |
| 865 | int add_mainboard_resources(struct lb_memory *mem) |
| 866 | { |
| 867 | device_t dev; |
| 868 | struct resource *res; |
Stefan Reinauer | 5ff7c13 | 2011-10-31 12:56:45 -0700 | [diff] [blame] | 869 | |
Josef Kellermann | bfa7ee5 | 2011-05-11 07:47:43 +0000 | [diff] [blame] | 870 | dev = dev_find_slot(0, PCI_DEVFN(0,0)); |
| 871 | res = probe_resource(dev, 0x1C); |
| 872 | if( res ) { |
| 873 | printk(BIOS_INFO, "mmconf: base=%0llx size=%0llx\n", res->base, res->size); |
| 874 | lb_add_memory_range(mem, LB_MEM_RESERVED, res->base, res->size); |
| 875 | } |
Josef Kellermann | bfa7ee5 | 2011-05-11 07:47:43 +0000 | [diff] [blame] | 876 | return 0; |
| 877 | } |
| 878 | |
| 879 | struct chip_operations mainboard_ops = { |
| 880 | CHIP_NAME(CONFIG_MAINBOARD_PART_NUMBER) |
| 881 | .enable_dev = enable_dev, |
| 882 | }; |