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