2 * This file is part of the coreboot project.
4 * Copyright (C) 2008 Advanced Micro Devices, Inc.
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.
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.
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
20 #include <console/console.h>
21 #include <device/device.h>
22 #include <device/pci.h>
24 #include <boot/coreboot_tables.h>
25 #include <cpu/x86/msr.h>
26 #include <cpu/amd/mtrr.h>
27 #include <device/pci_def.h>
28 #include <../southbridge/amd/sb600/sb600.h>
31 #define ADT7475_ADDRESS 0x2E
32 #define SMBUS_IO_BASE 0x1000
34 extern int do_smbus_read_byte(u32 smbus_io_base, u32 device, u32 address);
35 extern int do_smbus_write_byte(u32 smbus_io_base, u32 device, u32 address,
37 extern void lb_add_memory_range(struct lb_memory *mem, uint32_t type,
38 uint64_t start, uint64_t size);
40 #define ADT7475_read_byte(address) \
41 do_smbus_read_byte(SMBUS_IO_BASE, ADT7475_ADDRESS, address)
42 #define ADT7475_write_byte(address, val) \
43 do_smbus_write_byte(SMBUS_IO_BASE, ADT7475_ADDRESS, address, val)
45 uint64_t uma_memory_base, uma_memory_size;
47 /********************************************************
48 * pistachio uses a BCM5787 as on-board NIC.
49 * It has a pin named LOW_POWER to enable it into LOW POWER state.
50 * In order to run NIC, we should let it out of Low power state. This pin is
52 * RRG4.2.3 GPM as GPIO
53 * GPM pins can be used as GPIO. The GPM I/O functions is controlled by three registers:
54 * I/O C50, C51, C52, PM I/O94, 95, 96.
55 * RRG4.2.3.1 GPM pins as Input
56 * RRG4.2.3.2 GPM pins as Output
57 * The R77 (on BRASS) / R81 (on Bronze) is not load!
58 * So NIC can work whether this function runs.
59 ********************************************************/
60 static void enable_onboard_nic()
64 printk(BIOS_INFO, "%s.\n", __func__);
66 /* enable GPM8 output */
67 byte = pm_ioread(0x95);
69 pm_iowrite(0x95, byte);
71 /* GPM8 outputs low. */
72 byte = pm_ioread(0x94);
74 pm_iowrite(0x94, byte);
80 static void set_thermal_config()
88 ADT7475_write_byte(0x40, 0x04);
89 /* Config Register 6 */
90 ADT7475_write_byte(0x10, 0x00);
91 /* Config Register 7 */
92 ADT7475_write_byte(0x11, 0x00);
94 /* set Offset 64 format, enable THERM on Remote 1& Remote 2 */
95 ADT7475_write_byte(0x7c, 0xa0);
96 /* No offset for remote 2 */
97 ADT7475_write_byte(0x72, 0x00);
98 /* PWM 1 configuration register CPU fan controlled by CPU Thermal Diode */
99 ADT7475_write_byte(0x5c, 0x02);
100 /* PWM 3 configuration register Case fan controlled by 690 temp */
101 ADT7475_write_byte(0x5e, 0x42);
103 /* remote 1 low temp limit */
104 ADT7475_write_byte(0x4e, 0x00);
105 /* remote 1 High temp limit (90C) */
106 ADT7475_write_byte(0x4f, 0x9a);
108 /* remote2 Low Temp Limit */
109 ADT7475_write_byte(0x52, 0x00);
110 /* remote2 High Limit (90C) */
111 ADT7475_write_byte(0x53, 0x9a);
113 /* remote 1 therm temp limit (95C) */
114 ADT7475_write_byte(0x6a, 0x9f);
115 /* remote 2 therm temp limit (95C) */
116 ADT7475_write_byte(0x6c, 0x9f);
118 /* PWM 1 minimum duty cycle (37%) */
119 ADT7475_write_byte(0x64, 0x60);
120 /* PWM 1 Maximum duty cycle (100%) */
121 ADT7475_write_byte(0x38, 0xff);
122 /* PWM 3 minimum duty cycle (37%) */
123 ADT7475_write_byte(0x66, 0x60);
124 /* PWM 3 Maximum Duty Cycle (100%) */
125 ADT7475_write_byte(0x3a, 0xff);
127 /* Remote 1 temperature Tmin (32C) */
128 ADT7475_write_byte(0x67, 0x60);
129 /* Remote 2 temperature Tmin (32C) */
130 ADT7475_write_byte(0x69, 0x60);
131 /* remote 1 Trange (53C ramp range) */
132 ADT7475_write_byte(0x5f, 0xe8);
133 /* remote 2 Trange (53C ramp range) */
134 ADT7475_write_byte(0x61, 0xe8);
136 /* PWM2 Duty cycle */
137 ADT7475_write_byte(0x65, 0x00);
139 ADT7475_write_byte(0x5d, 0x80);
140 /* PWM2 Max Duty Cycle */
141 ADT7475_write_byte(0x39, 0x00);
143 /* Config Register 3 - enable smbalert & therm */
144 ADT7475_write_byte(0x78, 0x03);
145 /* Config Register 4 - enable therm output */
146 ADT7475_write_byte(0x7d, 0x09);
147 /* Interrupt Mask Register 2 - Mask SMB alert for Therm Conditions, Fan 2 fault, SmbAlert Fan for Therm Timer event */
148 ADT7475_write_byte(0x75, 0x2a);
149 /* Config Register 1 Set Start bit */
150 ADT7475_write_byte(0x40, 0x05);
151 /* Read status register to clear any old errors */
152 byte2 = ADT7475_read_byte(0x42);
153 byte = ADT7475_read_byte(0x41);
155 /* remote 1 temperature offset */
156 ADT7475_write_byte(0x70, 0x00);
158 printk(BIOS_INFO, "Init adt7475 end , status 0x42 %02x, status 0x41 %02x\n",
161 /* sb600 setting for thermal config. Set SB600 GPM5 to trigger ACPI event */
162 /* set GPM5 as GPM5, not DDR3_memory disable */
163 byte = pm_ioread(0x8f);
164 byte |= 1 << 6; /* enable GPE */
165 pm_iowrite(0x8f, byte);
167 /* GPM5 as GPIO not USB OC */
168 sm_dev = dev_find_slot(0, PCI_DEVFN(0x14, 0));
169 dword = pci_read_config32(sm_dev, 0x64);
171 pci_write_config32(sm_dev, 0x64, dword);
173 /* Enable Client Management Index/Data registers */
174 dword = pci_read_config32(sm_dev, 0x78);
175 dword |= 1 << 11; /* Cms_enable */
176 pci_write_config32(sm_dev, 0x78, dword);
179 byte = pci_read_config8(sm_dev, 0x41);
181 pci_write_config8(sm_dev, 0x41, byte);
183 /* set GPM5 as input */
184 /* set index register 0C50h to 13h (miscellaneous control) */
185 outb(0x13, 0xC50); /* CMIndex */
186 /* set CM data register 0C51h bits [7:6] to 01b to set Input/Out control */
187 byte = inb(0xC51); /* CMData */
191 /* set GPM port 0C52h bit 5 to 1 to tri-state the GPM port */
192 byte = inb(0xc52); /* GpmPort */
195 /* set CM data register 0C51h bits [7:6] to 00b to set GPM port for read */
200 /* trigger SCI/SMI */
201 byte = pm_ioread(0x34);
203 pm_iowrite(0x34, byte);
205 /* set GPM5 to not wake from s5 */
206 byte = pm_ioread(0x77);
208 pm_iowrite(0x77, byte);
210 /* trigger on falling edge */
211 byte = pm_ioread(0x38);
213 pm_iowrite(0x38, byte);
215 /* set SB600 GPIO 64 to GPIO with pull-up */
216 byte = pm2_ioread(0x42);
218 pm2_iowrite(0x42, byte);
220 /* set GPIO 64 to input */
221 word = pci_read_config16(sm_dev, 0x56);
223 pci_write_config16(sm_dev, 0x56, word);
225 /* set GPIO 64 internal pull-up */
226 byte = pm2_ioread(0xf0);
228 pm2_iowrite(0xf0, byte);
230 /* set Talert to be active low */
231 byte = pm_ioread(0x67);
233 pm_iowrite(0x67, byte);
235 /* set Talert to generate ACPI event */
236 byte = pm_ioread(0x3c);
238 pm_iowrite(0x3c, byte);
241 /* byte = pm_ioread(0x68);
243 * pm_iowrite(0x68, byte);
245 * byte = pm_ioread(0x55);
247 * pm_iowrite(0x55, byte);
249 * byte = pm_ioread(0x67);
250 * byte &= ~( 1 << 6);
251 * pm_iowrite(0x67, byte);
255 /*************************************************
256 * enable the dedicated function in pistachio board.
257 * This function called early than rs690_enable.
258 *************************************************/
259 void pistachio_enable(device_t dev)
261 struct mainboard_config *mainboard =
262 (struct mainboard_config *)dev->chip_info;
264 printk(BIOS_INFO, "Mainboard Pistachio Enable. dev=0x%p\n", dev);
266 #if (CONFIG_GFXUMA == 1)
269 /* TOP_MEM: the top of DRAM below 4G */
270 msr = rdmsr(TOP_MEM);
271 printk(BIOS_INFO, "%s, TOP MEM: msr.lo = 0x%08x, msr.hi = 0x%08x\n",
272 __func__, msr.lo, msr.hi);
274 /* TOP_MEM2: the top of DRAM above 4G */
275 msr2 = rdmsr(TOP_MEM2);
276 printk(BIOS_INFO, "%s, TOP MEM2: msr2.lo = 0x%08x, msr2.hi = 0x%08x\n",
277 __func__, msr2.lo, msr2.hi);
280 case 0x10000000: /* 256M system memory */
281 uma_memory_size = 0x2000000; /* 32M recommended UMA */
284 case 0x18000000: /* 384M system memory */
285 uma_memory_size = 0x4000000; /* 64M recommended UMA */
288 case 0x20000000: /* 512M system memory */
289 uma_memory_size = 0x4000000; /* 64M recommended UMA */
292 default: /* 1GB and above system memory */
293 uma_memory_size = 0x8000000; /* 128M recommended UMA */
297 uma_memory_base = msr.lo - uma_memory_size; /* TOP_MEM1 */
298 printk(BIOS_INFO, "%s: uma size 0x%08llx, memory start 0x%08llx\n",
299 __func__, uma_memory_size, uma_memory_base);
303 uma_memory_size = 0x8000000; /* 128M recommended UMA */
304 uma_memory_base = 0x38000000; /* 1GB system memory supposed */
307 enable_onboard_nic();
309 set_thermal_config();
312 int add_mainboard_resources(struct lb_memory *mem)
314 /* UMA is removed from system memory in the northbridge code, but
315 * in some circumstances we want the memory mentioned as reserved.
317 #if (CONFIG_GFXUMA == 1)
318 printk(BIOS_INFO, "uma_memory_base=0x%llx, uma_memory_size=0x%llx \n",
319 uma_memory_base, uma_memory_size);
320 lb_add_memory_range(mem, LB_MEM_RESERVED,
321 uma_memory_base, uma_memory_size);
325 struct chip_operations mainboard_ops = {
326 CHIP_NAME("AMD Pistachio Mainboard")
327 .enable_dev = pistachio_enable,