blob: a36dce07c691e33efaad03eff0f0af32fe80b4a2 [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
30#define ADT7461_ADDRESS 0x4C
31#define ARA_ADDRESS 0x0C /* Alert Response Address */
32
Juhana Helovuod09d1f72010-09-13 14:51:26 +000033#define ADT7461_read_byte(address) \
34 do_smbus_read_byte(SMBUS_IO_BASE, ADT7461_ADDRESS, address)
35#define ARA_read_byte(address) \
36 do_smbus_read_byte(SMBUS_IO_BASE, ARA_ADDRESS, address)
37#define ADT7461_write_byte(address, val) \
38 do_smbus_write_byte(SMBUS_IO_BASE, ADT7461_ADDRESS, address, val)
39
Juhana Helovuod09d1f72010-09-13 14:51:26 +000040void set_pcie_dereset(void);
41void set_pcie_reset(void);
42u8 is_dev3_present(void);
43
44void set_pcie_dereset()
45{
46 u8 byte;
47 u16 word;
48 device_t sm_dev;
49 /* set 0 to bit1 :disable GPM9 as SLP_S2 output */
50 /* set 0 to bit2 :disable GPM8 as AZ_RST output */
51 byte = pm_ioread(0x8d);
52 byte &= ~((1 << 1) | (1 << 2));
53 pm_iowrite(0x8d, byte);
54
55 /* set the GPM8 and GPM9 output enable and the value to 1 */
56 byte = pm_ioread(0x94);
57 byte &= ~((1 << 2) | (1 << 3));
58 byte |= ((1 << 0) | (1 << 1));
59 pm_iowrite(0x94, byte);
60
61 /* set the GPIO65 output enable and the value is 1 */
62 sm_dev = dev_find_slot(0, PCI_DEVFN(0x14, 0));
63 word = pci_read_config16(sm_dev, 0x7e);
64 word |= (1 << 0);
65 word &= ~(1 << 4);
66 pci_write_config16(sm_dev, 0x7e, word);
67}
68
69void set_pcie_reset()
70{
71 u8 byte;
72 u16 word;
73 device_t sm_dev;
74
75 /* set 0 to bit1 :disable GPM9 as SLP_S2 output */
76 /* set 0 to bit2 :disable GPM8 as AZ_RST output */
77 byte = pm_ioread(0x8d);
78 byte &= ~((1 << 1) | (1 << 2));
79 pm_iowrite(0x8d, byte);
80
81 /* set the GPM8 and GPM9 output enable and the value to 0 */
82 byte = pm_ioread(0x94);
83 byte &= ~((1 << 2) | (1 << 3));
84 byte &= ~((1 << 0) | (1 << 1));
85 pm_iowrite(0x94, byte);
86
87 /* set the GPIO65 output enable and the value is 0 */
88 sm_dev = dev_find_slot(0, PCI_DEVFN(0x14, 0));
89 word = pci_read_config16(sm_dev, 0x7e);
90 word &= ~(1 << 0);
91 word &= ~(1 << 4);
92 pci_write_config16(sm_dev, 0x7e, word);
93}
94
Juhana Helovuod09d1f72010-09-13 14:51:26 +000095/*
96 * justify the dev3 is exist or not
97 * NOTE: This just copied from AMD Tilapia code.
Juhana Helovuoa8c84902010-12-06 01:11:12 +000098 * It is completly unknown it it will work at all for ASUS M4A785-M.
Juhana Helovuod09d1f72010-09-13 14:51:26 +000099 */
100u8 is_dev3_present(void)
101{
102 u16 word;
103 device_t sm_dev;
104
105 /* access the smbus extended register */
106 sm_dev = dev_find_slot(0, PCI_DEVFN(0x14, 0));
107
108 /* put the GPIO68 output to tristate */
109 word = pci_read_config16(sm_dev, 0x7e);
110 word |= 1 << 6;
111 pci_write_config16(sm_dev, 0x7e,word);
112
113 /* read the GPIO68 input status */
114 word = pci_read_config16(sm_dev, 0x7e);
115
116 if(word & (1 << 10)){
117 /*not exist*/
118 return 0;
119 }else{
120 /*exist*/
121 return 1;
122 }
123}
124
125/*
126 * set thermal config
127 */
128static void set_thermal_config(void)
129{
130 u8 byte;
131 u16 word;
132 device_t sm_dev;
133
134 /* set ADT 7461 */
135 ADT7461_write_byte(0x0B, 0x50); /* Local Temperature Hight limit */
136 ADT7461_write_byte(0x0C, 0x00); /* Local Temperature Low limit */
137 ADT7461_write_byte(0x0D, 0x50); /* External Temperature Hight limit High Byte */
138 ADT7461_write_byte(0x0E, 0x00); /* External Temperature Low limit High Byte */
139
140 ADT7461_write_byte(0x19, 0x55); /* External THERM limit */
141 ADT7461_write_byte(0x20, 0x55); /* Local THERM limit */
142
143 byte = ADT7461_read_byte(0x02); /* read status register to clear it */
144 ARA_read_byte(0x05); /* A hardware alert can only be cleared by the master sending an ARA as a read command */
145 printk(BIOS_INFO, "Init adt7461 end , status 0x02 %02x\n", byte);
146
147 /* sb700 settings for thermal config */
148 /* set SB700 GPIO 64 to GPIO with pull-up */
149 byte = pm2_ioread(0x42);
150 byte &= 0x3f;
151 pm2_iowrite(0x42, byte);
152
153 /* set GPIO 64 to input */
154 sm_dev = dev_find_slot(0, PCI_DEVFN(0x14, 0));
155 word = pci_read_config16(sm_dev, 0x56);
156 word |= 1 << 7;
157 pci_write_config16(sm_dev, 0x56, word);
158
159 /* set GPIO 64 internal pull-up */
160 byte = pm2_ioread(0xf0);
161 byte &= 0xee;
162 pm2_iowrite(0xf0, byte);
163
164 /* set Talert to be active low */
165 byte = pm_ioread(0x67);
166 byte &= ~(1 << 5);
167 pm_iowrite(0x67, byte);
168
169 /* set Talert to generate ACPI event */
170 byte = pm_ioread(0x3c);
171 byte &= 0xf3;
172 pm_iowrite(0x3c, byte);
173
174 /* THERMTRIP pin */
175 /* byte = pm_ioread(0x68);
176 * byte |= 1 << 3;
177 * pm_iowrite(0x68, byte);
178 *
179 * byte = pm_ioread(0x55);
180 * byte |= 1 << 0;
181 * pm_iowrite(0x55, byte);
182 *
183 * byte = pm_ioread(0x67);
184 * byte &= ~( 1 << 6);
185 * pm_iowrite(0x67, byte);
186 */
187}
188
189/*************************************************
Juhana Helovuoa8c84902010-12-06 01:11:12 +0000190* enable the dedicated function in this board.
Juhana Helovuod09d1f72010-09-13 14:51:26 +0000191* This function called early than rs780_enable.
192*************************************************/
Paul Menzel528640d2013-02-23 21:31:23 +0100193static void mainboard_enable(device_t dev)
Juhana Helovuod09d1f72010-09-13 14:51:26 +0000194{
Juhana Helovuoa8c84902010-12-06 01:11:12 +0000195 printk(BIOS_INFO, "Mainboard enable. dev=0x%p\n", dev);
Juhana Helovuod09d1f72010-09-13 14:51:26 +0000196
Juhana Helovuod09d1f72010-09-13 14:51:26 +0000197 set_pcie_dereset();
198 /* get_ide_dma66(); */
199 set_thermal_config();
200}
201
202struct chip_operations mainboard_ops = {
Paul Menzel528640d2013-02-23 21:31:23 +0100203 .enable_dev = mainboard_enable,
Juhana Helovuod09d1f72010-09-13 14:51:26 +0000204};