Juhana Helovuo | d09d1f7 | 2010-09-13 14:51:26 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2010 Advanced Micro Devices, Inc. |
| 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 <console/console.h> |
| 21 | #include <device/device.h> |
| 22 | #include <device/pci.h> |
| 23 | #include <arch/io.h> |
| 24 | #include <cpu/x86/msr.h> |
| 25 | #include <cpu/amd/mtrr.h> |
| 26 | #include <device/pci_def.h> |
| 27 | #include <southbridge/amd/sb700/sb700.h> |
| 28 | #include "chip.h" |
| 29 | |
| 30 | #define ADT7461_ADDRESS 0x4C |
| 31 | #define ARA_ADDRESS 0x0C /* Alert Response Address */ |
| 32 | |
| 33 | extern int do_smbus_read_byte(u32 smbus_io_base, u32 device, u32 address); |
| 34 | extern int do_smbus_write_byte(u32 smbus_io_base, u32 device, u32 address, |
| 35 | u8 val); |
| 36 | |
| 37 | #define ADT7461_read_byte(address) \ |
| 38 | do_smbus_read_byte(SMBUS_IO_BASE, ADT7461_ADDRESS, address) |
| 39 | #define ARA_read_byte(address) \ |
| 40 | do_smbus_read_byte(SMBUS_IO_BASE, ARA_ADDRESS, address) |
| 41 | #define ADT7461_write_byte(address, val) \ |
| 42 | do_smbus_write_byte(SMBUS_IO_BASE, ADT7461_ADDRESS, address, val) |
| 43 | |
| 44 | #define SMBUS_IO_BASE 0x6000 |
| 45 | |
| 46 | uint64_t uma_memory_base, uma_memory_size; |
| 47 | |
| 48 | void set_pcie_dereset(void); |
| 49 | void set_pcie_reset(void); |
| 50 | u8 is_dev3_present(void); |
| 51 | |
| 52 | void set_pcie_dereset() |
| 53 | { |
| 54 | u8 byte; |
| 55 | u16 word; |
| 56 | device_t sm_dev; |
| 57 | /* set 0 to bit1 :disable GPM9 as SLP_S2 output */ |
| 58 | /* set 0 to bit2 :disable GPM8 as AZ_RST output */ |
| 59 | byte = pm_ioread(0x8d); |
| 60 | byte &= ~((1 << 1) | (1 << 2)); |
| 61 | pm_iowrite(0x8d, byte); |
| 62 | |
| 63 | /* set the GPM8 and GPM9 output enable and the value to 1 */ |
| 64 | byte = pm_ioread(0x94); |
| 65 | byte &= ~((1 << 2) | (1 << 3)); |
| 66 | byte |= ((1 << 0) | (1 << 1)); |
| 67 | pm_iowrite(0x94, byte); |
| 68 | |
| 69 | /* set the GPIO65 output enable and the value is 1 */ |
| 70 | sm_dev = dev_find_slot(0, PCI_DEVFN(0x14, 0)); |
| 71 | word = pci_read_config16(sm_dev, 0x7e); |
| 72 | word |= (1 << 0); |
| 73 | word &= ~(1 << 4); |
| 74 | pci_write_config16(sm_dev, 0x7e, word); |
| 75 | } |
| 76 | |
| 77 | void set_pcie_reset() |
| 78 | { |
| 79 | u8 byte; |
| 80 | u16 word; |
| 81 | device_t sm_dev; |
| 82 | |
| 83 | /* set 0 to bit1 :disable GPM9 as SLP_S2 output */ |
| 84 | /* set 0 to bit2 :disable GPM8 as AZ_RST output */ |
| 85 | byte = pm_ioread(0x8d); |
| 86 | byte &= ~((1 << 1) | (1 << 2)); |
| 87 | pm_iowrite(0x8d, byte); |
| 88 | |
| 89 | /* set the GPM8 and GPM9 output enable and the value to 0 */ |
| 90 | byte = pm_ioread(0x94); |
| 91 | byte &= ~((1 << 2) | (1 << 3)); |
| 92 | byte &= ~((1 << 0) | (1 << 1)); |
| 93 | pm_iowrite(0x94, byte); |
| 94 | |
| 95 | /* set the GPIO65 output enable and the value is 0 */ |
| 96 | sm_dev = dev_find_slot(0, PCI_DEVFN(0x14, 0)); |
| 97 | word = pci_read_config16(sm_dev, 0x7e); |
| 98 | word &= ~(1 << 0); |
| 99 | word &= ~(1 << 4); |
| 100 | pci_write_config16(sm_dev, 0x7e, word); |
| 101 | } |
| 102 | |
| 103 | #if 0 /* TODO: */ |
| 104 | /******************************************************** |
| 105 | * tilapia uses SB700 GPIO8 to detect IDE_DMA66. |
| 106 | * IDE_DMA66 is routed to GPIO 8. So we read Gpio 8 to |
| 107 | * get the cable type, 40 pin or 80 pin? |
| 108 | ********************************************************/ |
| 109 | static void get_ide_dma66(void) |
| 110 | { |
| 111 | u8 byte; |
| 112 | /*u32 sm_dev, ide_dev; */ |
| 113 | device_t sm_dev, ide_dev; |
| 114 | |
| 115 | sm_dev = dev_find_slot(0, PCI_DEVFN(0x14, 0)); |
| 116 | |
| 117 | byte = pci_read_config8(sm_dev, 0xA9); |
| 118 | byte |= (1 << 4); /* Set Gpio8 as input */ |
| 119 | pci_write_config8(sm_dev, 0xA9, byte); |
| 120 | |
| 121 | ide_dev = dev_find_slot(0, PCI_DEVFN(0x14, 1)); |
| 122 | byte = pci_read_config8(ide_dev, 0x56); |
| 123 | byte &= ~(7 << 0); |
| 124 | if ((1 << 4) & pci_read_config8(sm_dev, 0xAA)) |
| 125 | byte |= 2 << 0; /* mode 2 */ |
| 126 | else |
| 127 | byte |= 5 << 0; /* mode 5 */ |
| 128 | pci_write_config8(ide_dev, 0x56, byte); |
| 129 | } |
| 130 | #endif |
| 131 | |
| 132 | /* |
| 133 | * justify the dev3 is exist or not |
| 134 | * NOTE: This just copied from AMD Tilapia code. |
| 135 | * It is completly unknown it it will work at all for Asus M4A785-A |
| 136 | */ |
| 137 | u8 is_dev3_present(void) |
| 138 | { |
| 139 | u16 word; |
| 140 | device_t sm_dev; |
| 141 | |
| 142 | /* access the smbus extended register */ |
| 143 | sm_dev = dev_find_slot(0, PCI_DEVFN(0x14, 0)); |
| 144 | |
| 145 | /* put the GPIO68 output to tristate */ |
| 146 | word = pci_read_config16(sm_dev, 0x7e); |
| 147 | word |= 1 << 6; |
| 148 | pci_write_config16(sm_dev, 0x7e,word); |
| 149 | |
| 150 | /* read the GPIO68 input status */ |
| 151 | word = pci_read_config16(sm_dev, 0x7e); |
| 152 | |
| 153 | if(word & (1 << 10)){ |
| 154 | /*not exist*/ |
| 155 | return 0; |
| 156 | }else{ |
| 157 | /*exist*/ |
| 158 | return 1; |
| 159 | } |
| 160 | } |
| 161 | |
| 162 | /* |
| 163 | * set thermal config |
| 164 | */ |
| 165 | static void set_thermal_config(void) |
| 166 | { |
| 167 | u8 byte; |
| 168 | u16 word; |
| 169 | device_t sm_dev; |
| 170 | |
| 171 | /* set ADT 7461 */ |
| 172 | ADT7461_write_byte(0x0B, 0x50); /* Local Temperature Hight limit */ |
| 173 | ADT7461_write_byte(0x0C, 0x00); /* Local Temperature Low limit */ |
| 174 | ADT7461_write_byte(0x0D, 0x50); /* External Temperature Hight limit High Byte */ |
| 175 | ADT7461_write_byte(0x0E, 0x00); /* External Temperature Low limit High Byte */ |
| 176 | |
| 177 | ADT7461_write_byte(0x19, 0x55); /* External THERM limit */ |
| 178 | ADT7461_write_byte(0x20, 0x55); /* Local THERM limit */ |
| 179 | |
| 180 | byte = ADT7461_read_byte(0x02); /* read status register to clear it */ |
| 181 | ARA_read_byte(0x05); /* A hardware alert can only be cleared by the master sending an ARA as a read command */ |
| 182 | printk(BIOS_INFO, "Init adt7461 end , status 0x02 %02x\n", byte); |
| 183 | |
| 184 | /* sb700 settings for thermal config */ |
| 185 | /* set SB700 GPIO 64 to GPIO with pull-up */ |
| 186 | byte = pm2_ioread(0x42); |
| 187 | byte &= 0x3f; |
| 188 | pm2_iowrite(0x42, byte); |
| 189 | |
| 190 | /* set GPIO 64 to input */ |
| 191 | sm_dev = dev_find_slot(0, PCI_DEVFN(0x14, 0)); |
| 192 | word = pci_read_config16(sm_dev, 0x56); |
| 193 | word |= 1 << 7; |
| 194 | pci_write_config16(sm_dev, 0x56, word); |
| 195 | |
| 196 | /* set GPIO 64 internal pull-up */ |
| 197 | byte = pm2_ioread(0xf0); |
| 198 | byte &= 0xee; |
| 199 | pm2_iowrite(0xf0, byte); |
| 200 | |
| 201 | /* set Talert to be active low */ |
| 202 | byte = pm_ioread(0x67); |
| 203 | byte &= ~(1 << 5); |
| 204 | pm_iowrite(0x67, byte); |
| 205 | |
| 206 | /* set Talert to generate ACPI event */ |
| 207 | byte = pm_ioread(0x3c); |
| 208 | byte &= 0xf3; |
| 209 | pm_iowrite(0x3c, byte); |
| 210 | |
| 211 | /* THERMTRIP pin */ |
| 212 | /* byte = pm_ioread(0x68); |
| 213 | * byte |= 1 << 3; |
| 214 | * pm_iowrite(0x68, byte); |
| 215 | * |
| 216 | * byte = pm_ioread(0x55); |
| 217 | * byte |= 1 << 0; |
| 218 | * pm_iowrite(0x55, byte); |
| 219 | * |
| 220 | * byte = pm_ioread(0x67); |
| 221 | * byte &= ~( 1 << 6); |
| 222 | * pm_iowrite(0x67, byte); |
| 223 | */ |
| 224 | } |
| 225 | |
| 226 | /************************************************* |
| 227 | * enable the dedicated function in m4a785m board. |
| 228 | * This function called early than rs780_enable. |
| 229 | *************************************************/ |
| 230 | static void m4a785m_enable(device_t dev) |
| 231 | { |
| 232 | printk(BIOS_INFO, "Mainboard M4A785M Enable. dev=0x%p\n", dev); |
| 233 | |
| 234 | #if (CONFIG_GFXUMA == 1) |
| 235 | msr_t msr, msr2; |
| 236 | |
| 237 | /* TOP_MEM: the top of DRAM below 4G */ |
| 238 | msr = rdmsr(TOP_MEM); |
| 239 | printk(BIOS_INFO, |
| 240 | "%s, TOP MEM: msr.lo = 0x%08x, msr.hi = 0x%08x\n", |
| 241 | __func__, msr.lo, msr.hi); |
| 242 | |
| 243 | /* TOP_MEM2: the top of DRAM above 4G */ |
| 244 | msr2 = rdmsr(TOP_MEM2); |
| 245 | printk(BIOS_INFO, |
| 246 | "%s, TOP MEM2: msr2.lo = 0x%08x, msr2.hi = 0x%08x\n", |
| 247 | __func__, msr2.lo, msr2.hi); |
| 248 | |
| 249 | switch (msr.lo) { |
| 250 | case 0x10000000: /* 256M system memory */ |
| 251 | uma_memory_size = 0x4000000; /* 64M recommended UMA */ |
| 252 | break; |
| 253 | |
| 254 | case 0x20000000: /* 512M system memory */ |
| 255 | uma_memory_size = 0x8000000; /* 128M recommended UMA */ |
| 256 | break; |
| 257 | |
| 258 | default: /* 1GB and above system memory */ |
| 259 | uma_memory_size = 0x10000000; /* 256M recommended UMA */ |
| 260 | break; |
| 261 | } |
| 262 | |
| 263 | uma_memory_base = msr.lo - uma_memory_size; /* TOP_MEM1 */ |
| 264 | printk(BIOS_INFO, "%s: uma size 0x%08llx, memory start 0x%08llx\n", |
| 265 | __func__, uma_memory_size, uma_memory_base); |
| 266 | |
| 267 | /* TODO: TOP_MEM2 */ |
| 268 | #else |
| 269 | uma_memory_size = 0x8000000; /* 128M recommended UMA */ |
| 270 | uma_memory_base = 0x38000000; /* 1GB system memory supposed */ |
| 271 | #endif |
| 272 | |
| 273 | set_pcie_dereset(); |
| 274 | /* get_ide_dma66(); */ |
| 275 | set_thermal_config(); |
| 276 | } |
| 277 | |
| 278 | struct chip_operations mainboard_ops = { |
| 279 | CHIP_NAME("AMD M4A785M Mainboard") |
| 280 | .enable_dev = m4a785m_enable, |
| 281 | }; |