Here is a proposed way how to handle the SATA PHY settings on SB700. It
[coreboot.git] / src / mainboard / asrock / 939a785gmh / mainboard.c
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 <boot/tables.h>
25 #include <cpu/x86/msr.h>
26 #include <cpu/amd/mtrr.h>
27 #include <device/pci_def.h>
28 #include <southbridge/amd/sb700/sb700.h>
29 #include "chip.h"
30
31 #define SMBUS_IO_BASE 0x6000
32
33 uint64_t uma_memory_base, uma_memory_size;
34
35 void set_pcie_dereset(void);
36 void set_pcie_reset(void);
37 u8 is_dev3_present(void);
38 void set_pcie_dereset()
39 {
40 }
41
42 void set_pcie_reset()
43 {
44 }
45
46 #if 0        /* not tested yet */
47 /********************************************************
48 * mahogany uses SB700 GPIO9 to detect IDE_DMA66.
49 * IDE_DMA66 is routed to GPIO 9. So we read Gpio 9 to
50 * get the cable type, 40 pin or 80 pin?
51 ********************************************************/
52 static void get_ide_dma66(void)
53 {
54         u8 byte;
55         /*u32 sm_dev, ide_dev; */
56         device_t sm_dev, ide_dev;
57
58         sm_dev = dev_find_slot(0, PCI_DEVFN(0x14, 0));
59
60         byte = pci_read_config8(sm_dev, 0xA9);
61         byte |= (1 << 5);       /* Set Gpio9 as input */
62         pci_write_config8(sm_dev, 0xA9, byte);
63
64         ide_dev = dev_find_slot(0, PCI_DEVFN(0x14, 1));
65         byte = pci_read_config8(ide_dev, 0x56);
66         byte &= ~(7 << 0);
67         if ((1 << 5) & pci_read_config8(sm_dev, 0xAA))
68                 byte |= 2 << 0; /* mode 2 */
69         else
70                 byte |= 5 << 0; /* mode 5 */
71         pci_write_config8(ide_dev, 0x56, byte);
72 }
73 #endif  /* get_ide_dma66 */
74
75 u8 is_dev3_present(void)
76 {
77         return 0;
78 }
79
80 /*************************************************
81 * enable the dedicated function in mahogany board.
82 * This function called early than rs780_enable.
83 *************************************************/
84 static void mb_enable(device_t dev)
85 {
86         printk(BIOS_INFO, "Mainboard 939A785GMH/128M Enable. dev=0x%p\n", dev);
87
88 #if (CONFIG_GFXUMA == 1)
89         msr_t msr, msr2;
90
91         /* TOP_MEM: the top of DRAM below 4G */
92         msr = rdmsr(TOP_MEM);
93         printk
94             (BIOS_INFO, "%s, TOP MEM: msr.lo = 0x%08x, msr.hi = 0x%08x\n",
95              __func__, msr.lo, msr.hi);
96
97         /* TOP_MEM2: the top of DRAM above 4G */
98         msr2 = rdmsr(TOP_MEM2);
99         printk
100             (BIOS_INFO, "%s, TOP MEM2: msr2.lo = 0x%08x, msr2.hi = 0x%08x\n",
101              __func__, msr2.lo, msr2.hi);
102
103         /* refer to UMA Size Consideration in 780 BDG. */
104         switch (msr.lo) {
105         case 0x10000000:        /* 256M system memory */
106                 uma_memory_size = 0x4000000;    /* 64M recommended UMA */
107                 break;
108
109         case 0x20000000:        /* 512M system memory */
110                 uma_memory_size = 0x8000000;    /* 128M recommended UMA */
111                 break;
112
113         default:                /* 1GB and above system memory */
114                 uma_memory_size = 0x10000000;   /* 256M recommended UMA */
115                 break;
116         }
117
118         uma_memory_base = msr.lo - uma_memory_size;     /* TOP_MEM1 */
119         printk(BIOS_INFO, "%s: uma size 0x%08llx, memory start 0x%08llx\n",
120                     __func__, uma_memory_size, uma_memory_base);
121
122         /* TODO: TOP_MEM2 */
123 #else
124         uma_memory_size = 0x8000000;    /* 128M recommended UMA */
125         uma_memory_base = 0x38000000;   /* 1GB  system memory supposed */
126 #endif
127
128         set_pcie_dereset();
129         /* get_ide_dma66(); */
130 }
131
132 int add_mainboard_resources(struct lb_memory *mem)
133 {
134         /* UMA is removed from system memory in the northbridge code, but
135          * in some circumstances we want the memory mentioned as reserved.
136          */
137 #if (CONFIG_GFXUMA == 1)
138         printk(BIOS_INFO, "uma_memory_start=0x%llx, uma_memory_size=0x%llx \n",
139                     uma_memory_base, uma_memory_size);
140         lb_add_memory_range(mem, LB_MEM_RESERVED, uma_memory_base,
141                             uma_memory_size);
142 #endif
143         return 0;
144 }
145
146 struct chip_operations mainboard_ops = {
147         CHIP_NAME("Asrock 939A785GMH/128M Mainboard")
148         .enable_dev = mb_enable,
149 };
150
151 /* override the default SATA PHY setup */
152 void sb700_setup_sata_phys(struct device *dev) {
153         /* RPR7.6.1 Program the PHY Global Control to 0x2C00 */
154         pci_write_config16(dev, 0x86, 0x2c00);
155
156         /* RPR7.6.2 SATA GENI PHY ports setting */
157         pci_write_config32(dev, 0x88, 0x01B48016);
158         pci_write_config32(dev, 0x8c, 0x01B48016);
159         pci_write_config32(dev, 0x90, 0x01B48016);
160         pci_write_config32(dev, 0x94, 0x01B48016);
161         pci_write_config32(dev, 0x98, 0x01B48016);
162         pci_write_config32(dev, 0x9C, 0x01B48016);
163
164         /* RPR7.6.3 SATA GEN II PHY port setting for port [0~5]. */
165         pci_write_config16(dev, 0xA0, 0xA07A);
166         pci_write_config16(dev, 0xA2, 0xA07A);
167         pci_write_config16(dev, 0xA4, 0xA07A);
168         pci_write_config16(dev, 0xA6, 0xA07A);
169         pci_write_config16(dev, 0xA8, 0xA07A);
170         pci_write_config16(dev, 0xAA, 0xA0FF);
171 }