Rudolf Marek | 133647a | 2010-04-05 19:47:34 +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> |
Stefan Reinauer | 23836e2 | 2010-04-15 12:39:29 +0000 | [diff] [blame] | 24 | #include <boot/tables.h> |
Rudolf Marek | 133647a | 2010-04-05 19:47:34 +0000 | [diff] [blame] | 25 | #include <cpu/x86/msr.h> |
| 26 | #include <cpu/amd/mtrr.h> |
| 27 | #include <device/pci_def.h> |
efdesign98 | 00c8c4a | 2011-07-20 12:37:58 -0600 | [diff] [blame^] | 28 | #include "southbridge/amd/sb700/sb700.h" |
| 29 | #include "southbridge/amd/sb700/smbus.h" |
Rudolf Marek | 133647a | 2010-04-05 19:47:34 +0000 | [diff] [blame] | 30 | #include "chip.h" |
| 31 | |
Rudolf Marek | 133647a | 2010-04-05 19:47:34 +0000 | [diff] [blame] | 32 | uint64_t uma_memory_base, uma_memory_size; |
| 33 | |
| 34 | void set_pcie_dereset(void); |
| 35 | void set_pcie_reset(void); |
Wang Qing Pei | 543f767 | 2010-08-17 11:11:09 +0000 | [diff] [blame] | 36 | u8 is_dev3_present(void); |
Rudolf Marek | 837403d | 2011-02-26 19:46:08 +0000 | [diff] [blame] | 37 | |
| 38 | static void pcie_rst_toggle(u8 val) { |
| 39 | u8 byte; |
| 40 | |
| 41 | byte = pm_ioread(0x8d); |
| 42 | byte &= ~(3 << 1); |
| 43 | pm_iowrite(0x8d, byte); |
| 44 | |
| 45 | byte = pm_ioread(0x94); |
| 46 | /* Output enable */ |
| 47 | byte &= ~(3 << 2); |
| 48 | /* Toggle GPM8, GPM9 */ |
| 49 | byte &= ~(3 << 0); |
| 50 | byte |= val; |
| 51 | pm_iowrite(0x94, byte); |
| 52 | } |
| 53 | |
Rudolf Marek | 133647a | 2010-04-05 19:47:34 +0000 | [diff] [blame] | 54 | void set_pcie_dereset() |
| 55 | { |
Rudolf Marek | 837403d | 2011-02-26 19:46:08 +0000 | [diff] [blame] | 56 | pcie_rst_toggle(0x3); |
Rudolf Marek | 133647a | 2010-04-05 19:47:34 +0000 | [diff] [blame] | 57 | } |
| 58 | |
| 59 | void set_pcie_reset() |
| 60 | { |
Rudolf Marek | 837403d | 2011-02-26 19:46:08 +0000 | [diff] [blame] | 61 | pcie_rst_toggle(0x0); |
Rudolf Marek | 133647a | 2010-04-05 19:47:34 +0000 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | #if 0 /* not tested yet */ |
| 65 | /******************************************************** |
| 66 | * mahogany uses SB700 GPIO9 to detect IDE_DMA66. |
| 67 | * IDE_DMA66 is routed to GPIO 9. So we read Gpio 9 to |
| 68 | * get the cable type, 40 pin or 80 pin? |
| 69 | ********************************************************/ |
| 70 | static void get_ide_dma66(void) |
| 71 | { |
| 72 | u8 byte; |
| 73 | /*u32 sm_dev, ide_dev; */ |
| 74 | device_t sm_dev, ide_dev; |
| 75 | |
| 76 | sm_dev = dev_find_slot(0, PCI_DEVFN(0x14, 0)); |
| 77 | |
| 78 | byte = pci_read_config8(sm_dev, 0xA9); |
| 79 | byte |= (1 << 5); /* Set Gpio9 as input */ |
| 80 | pci_write_config8(sm_dev, 0xA9, byte); |
| 81 | |
| 82 | ide_dev = dev_find_slot(0, PCI_DEVFN(0x14, 1)); |
| 83 | byte = pci_read_config8(ide_dev, 0x56); |
| 84 | byte &= ~(7 << 0); |
| 85 | if ((1 << 5) & pci_read_config8(sm_dev, 0xAA)) |
| 86 | byte |= 2 << 0; /* mode 2 */ |
| 87 | else |
| 88 | byte |= 5 << 0; /* mode 5 */ |
| 89 | pci_write_config8(ide_dev, 0x56, byte); |
| 90 | } |
| 91 | #endif /* get_ide_dma66 */ |
| 92 | |
Wang Qing Pei | 543f767 | 2010-08-17 11:11:09 +0000 | [diff] [blame] | 93 | u8 is_dev3_present(void) |
| 94 | { |
| 95 | return 0; |
| 96 | } |
| 97 | |
Rudolf Marek | 133647a | 2010-04-05 19:47:34 +0000 | [diff] [blame] | 98 | /************************************************* |
| 99 | * enable the dedicated function in mahogany board. |
| 100 | * This function called early than rs780_enable. |
| 101 | *************************************************/ |
Rudolf Marek | c7d2773 | 2010-08-17 21:03:17 +0000 | [diff] [blame] | 102 | static void mb_enable(device_t dev) |
Rudolf Marek | 133647a | 2010-04-05 19:47:34 +0000 | [diff] [blame] | 103 | { |
Rudolf Marek | c7d2773 | 2010-08-17 21:03:17 +0000 | [diff] [blame] | 104 | printk(BIOS_INFO, "Mainboard 939A785GMH/128M Enable. dev=0x%p\n", dev); |
Rudolf Marek | 133647a | 2010-04-05 19:47:34 +0000 | [diff] [blame] | 105 | |
| 106 | #if (CONFIG_GFXUMA == 1) |
| 107 | msr_t msr, msr2; |
| 108 | |
| 109 | /* TOP_MEM: the top of DRAM below 4G */ |
| 110 | msr = rdmsr(TOP_MEM); |
| 111 | printk |
| 112 | (BIOS_INFO, "%s, TOP MEM: msr.lo = 0x%08x, msr.hi = 0x%08x\n", |
| 113 | __func__, msr.lo, msr.hi); |
| 114 | |
| 115 | /* TOP_MEM2: the top of DRAM above 4G */ |
| 116 | msr2 = rdmsr(TOP_MEM2); |
| 117 | printk |
| 118 | (BIOS_INFO, "%s, TOP MEM2: msr2.lo = 0x%08x, msr2.hi = 0x%08x\n", |
| 119 | __func__, msr2.lo, msr2.hi); |
| 120 | |
| 121 | /* refer to UMA Size Consideration in 780 BDG. */ |
| 122 | switch (msr.lo) { |
| 123 | case 0x10000000: /* 256M system memory */ |
| 124 | uma_memory_size = 0x4000000; /* 64M recommended UMA */ |
| 125 | break; |
| 126 | |
| 127 | case 0x20000000: /* 512M system memory */ |
| 128 | uma_memory_size = 0x8000000; /* 128M recommended UMA */ |
| 129 | break; |
| 130 | |
| 131 | default: /* 1GB and above system memory */ |
| 132 | uma_memory_size = 0x10000000; /* 256M recommended UMA */ |
| 133 | break; |
| 134 | } |
| 135 | |
| 136 | uma_memory_base = msr.lo - uma_memory_size; /* TOP_MEM1 */ |
| 137 | printk(BIOS_INFO, "%s: uma size 0x%08llx, memory start 0x%08llx\n", |
| 138 | __func__, uma_memory_size, uma_memory_base); |
| 139 | |
| 140 | /* TODO: TOP_MEM2 */ |
| 141 | #else |
| 142 | uma_memory_size = 0x8000000; /* 128M recommended UMA */ |
| 143 | uma_memory_base = 0x38000000; /* 1GB system memory supposed */ |
| 144 | #endif |
| 145 | |
| 146 | set_pcie_dereset(); |
| 147 | /* get_ide_dma66(); */ |
| 148 | } |
| 149 | |
| 150 | int add_mainboard_resources(struct lb_memory *mem) |
| 151 | { |
| 152 | /* UMA is removed from system memory in the northbridge code, but |
| 153 | * in some circumstances we want the memory mentioned as reserved. |
| 154 | */ |
| 155 | #if (CONFIG_GFXUMA == 1) |
| 156 | printk(BIOS_INFO, "uma_memory_start=0x%llx, uma_memory_size=0x%llx \n", |
| 157 | uma_memory_base, uma_memory_size); |
| 158 | lb_add_memory_range(mem, LB_MEM_RESERVED, uma_memory_base, |
| 159 | uma_memory_size); |
| 160 | #endif |
| 161 | return 0; |
| 162 | } |
| 163 | |
| 164 | struct chip_operations mainboard_ops = { |
Rudolf Marek | c7d2773 | 2010-08-17 21:03:17 +0000 | [diff] [blame] | 165 | CHIP_NAME("Asrock 939A785GMH/128M Mainboard") |
| 166 | .enable_dev = mb_enable, |
Rudolf Marek | 133647a | 2010-04-05 19:47:34 +0000 | [diff] [blame] | 167 | }; |
Rudolf Marek | 7df50a8 | 2010-09-22 22:46:47 +0000 | [diff] [blame] | 168 | |
| 169 | /* override the default SATA PHY setup */ |
Zheng Bao | c342223 | 2011-03-28 03:33:10 +0000 | [diff] [blame] | 170 | void sb7xx_51xx_setup_sata_phys(struct device *dev) { |
Rudolf Marek | 7df50a8 | 2010-09-22 22:46:47 +0000 | [diff] [blame] | 171 | /* RPR7.6.1 Program the PHY Global Control to 0x2C00 */ |
| 172 | pci_write_config16(dev, 0x86, 0x2c00); |
| 173 | |
| 174 | /* RPR7.6.2 SATA GENI PHY ports setting */ |
| 175 | pci_write_config32(dev, 0x88, 0x01B48016); |
| 176 | pci_write_config32(dev, 0x8c, 0x01B48016); |
| 177 | pci_write_config32(dev, 0x90, 0x01B48016); |
| 178 | pci_write_config32(dev, 0x94, 0x01B48016); |
| 179 | pci_write_config32(dev, 0x98, 0x01B48016); |
| 180 | pci_write_config32(dev, 0x9C, 0x01B48016); |
| 181 | |
| 182 | /* RPR7.6.3 SATA GEN II PHY port setting for port [0~5]. */ |
| 183 | pci_write_config16(dev, 0xA0, 0xA07A); |
| 184 | pci_write_config16(dev, 0xA2, 0xA07A); |
| 185 | pci_write_config16(dev, 0xA4, 0xA07A); |
| 186 | pci_write_config16(dev, 0xA6, 0xA07A); |
| 187 | pci_write_config16(dev, 0xA8, 0xA07A); |
| 188 | pci_write_config16(dev, 0xAA, 0xA0FF); |
| 189 | } |