blob: 03735f4eb071eb2f5040ae86bb447010d10a83a1 [file] [log] [blame]
Zheng Bao1ad9f292010-04-23 17:37:41 +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 <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>
efdesign9800c8c4a2011-07-20 12:37:58 -060029#include "southbridge/amd/sb700/smbus.h"
Zheng Bao1ad9f292010-04-23 17:37:41 +000030#include "chip.h"
31
32#define ADT7461_ADDRESS 0x4C
33#define ARA_ADDRESS 0x0C /* Alert Response Address */
34
Zheng Bao1ad9f292010-04-23 17:37:41 +000035#define ADT7461_read_byte(address) \
36 do_smbus_read_byte(SMBUS_IO_BASE, ADT7461_ADDRESS, address)
37#define ARA_read_byte(address) \
38 do_smbus_read_byte(SMBUS_IO_BASE, ARA_ADDRESS, address)
39#define ADT7461_write_byte(address, val) \
40 do_smbus_write_byte(SMBUS_IO_BASE, ADT7461_ADDRESS, address, val)
41
Zheng Bao1ad9f292010-04-23 17:37:41 +000042void set_pcie_dereset(void);
43void set_pcie_reset(void);
Wang Qing Pei543f7672010-08-17 11:11:09 +000044u8 is_dev3_present(void);
Zheng Bao1ad9f292010-04-23 17:37:41 +000045
46void set_pcie_dereset()
47{
48 u8 byte;
49 u16 word;
50 device_t sm_dev;
51 /* set 0 to bit1 :disable GPM9 as SLP_S2 output */
52 /* set 0 to bit2 :disable GPM8 as AZ_RST output */
53 byte = pm_ioread(0x8d);
54 byte &= ~((1 << 1) | (1 << 2));
55 pm_iowrite(0x8d, byte);
56
57 /* set the GPM8 and GPM9 output enable and the value to 1 */
58 byte = pm_ioread(0x94);
59 byte &= ~((1 << 2) | (1 << 3));
60 byte |= ((1 << 0) | (1 << 1));
61 pm_iowrite(0x94, byte);
62
63 /* set the GPIO65 output enable and the value is 1 */
64 sm_dev = dev_find_slot(0, PCI_DEVFN(0x14, 0));
65 word = pci_read_config16(sm_dev, 0x7e);
66 word |= (1 << 0);
67 word &= ~(1 << 4);
68 pci_write_config16(sm_dev, 0x7e, word);
69}
70
71void set_pcie_reset()
72{
73 u8 byte;
74 u16 word;
75 device_t sm_dev;
76
77 /* set 0 to bit1 :disable GPM9 as SLP_S2 output */
78 /* set 0 to bit2 :disable GPM8 as AZ_RST output */
79 byte = pm_ioread(0x8d);
80 byte &= ~((1 << 1) | (1 << 2));
81 pm_iowrite(0x8d, byte);
82
83 /* set the GPM8 and GPM9 output enable and the value to 0 */
84 byte = pm_ioread(0x94);
85 byte &= ~((1 << 2) | (1 << 3));
86 byte &= ~((1 << 0) | (1 << 1));
87 pm_iowrite(0x94, byte);
88
89 /* set the GPIO65 output enable and the value is 0 */
90 sm_dev = dev_find_slot(0, PCI_DEVFN(0x14, 0));
91 word = pci_read_config16(sm_dev, 0x7e);
92 word &= ~(1 << 0);
93 word &= ~(1 << 4);
94 pci_write_config16(sm_dev, 0x7e, word);
95}
96
97#if 0 /* TODO: */
98/********************************************************
99* tilapia uses SB700 GPIO8 to detect IDE_DMA66.
100* IDE_DMA66 is routed to GPIO 8. So we read Gpio 8 to
101* get the cable type, 40 pin or 80 pin?
102********************************************************/
103static void get_ide_dma66(void)
104{
105 u8 byte;
106 /*u32 sm_dev, ide_dev; */
107 device_t sm_dev, ide_dev;
108
109 sm_dev = dev_find_slot(0, PCI_DEVFN(0x14, 0));
110
111 byte = pci_read_config8(sm_dev, 0xA9);
112 byte |= (1 << 4); /* Set Gpio8 as input */
113 pci_write_config8(sm_dev, 0xA9, byte);
114
115 ide_dev = dev_find_slot(0, PCI_DEVFN(0x14, 1));
116 byte = pci_read_config8(ide_dev, 0x56);
117 byte &= ~(7 << 0);
118 if ((1 << 4) & pci_read_config8(sm_dev, 0xAA))
119 byte |= 2 << 0; /* mode 2 */
120 else
121 byte |= 5 << 0; /* mode 5 */
122 pci_write_config8(ide_dev, 0x56, byte);
123}
124#endif
125
126/*
Wang Qing Pei543f7672010-08-17 11:11:09 +0000127 * justify the dev3 is exist or not
128 */
129u8 is_dev3_present(void)
130{
131 u16 word;
132 device_t sm_dev;
133
134 /* access the smbus extended register */
135 sm_dev = dev_find_slot(0, PCI_DEVFN(0x14, 0));
136
137 /* put the GPIO68 output to tristate */
138 word = pci_read_config16(sm_dev, 0x7e);
139 word |= 1 << 6;
140 pci_write_config16(sm_dev, 0x7e,word);
141
142 /* read the GPIO68 input status */
143 word = pci_read_config16(sm_dev, 0x7e);
144
145 if(word & (1 << 10)){
146 /*not exist*/
147 return 0;
148 }else{
149 /*exist*/
150 return 1;
151 }
152}
153
154
155/*
156 * set gpio40 gfx
157 */
158static void set_gpio40_gfx(void)
159{
160 u8 byte;
161 u32 dword;
162 device_t sm_dev;
163 /* disable the GPIO40 as CLKREQ2# function */
164 byte = pm_ioread(0xd3);
165 byte &= ~(1 << 7);
166 pm_iowrite(0xd3, byte);
167
168 /* disable the GPIO40 as CLKREQ3# function */
169 byte = pm_ioread(0xd4);
170 byte &= ~(1 << 0);
171 pm_iowrite(0xd4, byte);
172
173 /* enable pull up for GPIO68 */
174 byte = pm2_ioread(0xf1);
175 byte &= ~(1 << 4);
176 pm2_iowrite(0xf1, byte);
177
178 /* access the smbus extended register */
179 sm_dev = dev_find_slot(0, PCI_DEVFN(0x14, 0));
180
181 /*if the dev3 is present, set the gfx to 2x8 lanes*/
182 /*otherwise set the gfx to 1x16 lanes*/
183 if(is_dev3_present()){
184
185 printk(BIOS_INFO, "Dev3 is present. GFX Configuration is Two x8 slots\n");
186 /* when the gpio40 is configured as GPIO, this will enable the output */
187 pci_write_config32(sm_dev, 0xf8, 0x4);
188 dword = pci_read_config32(sm_dev, 0xfc);
189 dword &= ~(1 << 10);
190
191 /* When the gpio40 is configured as GPIO, this will represent the output value*/
192 /* 1 :enable two x8 , 0 : master slot enable only */
193 dword |= (1 << 26);
194 pci_write_config32(sm_dev, 0xfc, dword);
195
196 }else{
197 printk(BIOS_INFO, "Dev3 is not present. GFX Configuration is One x16 slot\n");
198 /* when the gpio40 is configured as GPIO, this will enable the output */
199 pci_write_config32(sm_dev, 0xf8, 0x4);
200 dword = pci_read_config32(sm_dev, 0xfc);
201 dword &= ~(1 << 10);
202
203 /* When the gpio40 is configured as GPIO, this will represent the output value*/
204 /* 1 :enable two x8 , 0 : master slot enable only */
205 dword &= ~(1 << 26);
206 pci_write_config32(sm_dev, 0xfc, dword);
207 }
208}
209
210/*
Zheng Bao1ad9f292010-04-23 17:37:41 +0000211 * set thermal config
212 */
213static void set_thermal_config(void)
214{
215 u8 byte;
216 u16 word;
217 device_t sm_dev;
218
219 /* set ADT 7461 */
220 ADT7461_write_byte(0x0B, 0x50); /* Local Temperature Hight limit */
221 ADT7461_write_byte(0x0C, 0x00); /* Local Temperature Low limit */
222 ADT7461_write_byte(0x0D, 0x50); /* External Temperature Hight limit High Byte */
223 ADT7461_write_byte(0x0E, 0x00); /* External Temperature Low limit High Byte */
224
225 ADT7461_write_byte(0x19, 0x55); /* External THERM limit */
226 ADT7461_write_byte(0x20, 0x55); /* Local THERM limit */
227
228 byte = ADT7461_read_byte(0x02); /* read status register to clear it */
229 ARA_read_byte(0x05); /* A hardware alert can only be cleared by the master sending an ARA as a read command */
230 printk(BIOS_INFO, "Init adt7461 end , status 0x02 %02x\n", byte);
231
232 /* sb700 settings for thermal config */
233 /* set SB700 GPIO 64 to GPIO with pull-up */
234 byte = pm2_ioread(0x42);
235 byte &= 0x3f;
236 pm2_iowrite(0x42, byte);
237
238 /* set GPIO 64 to input */
239 sm_dev = dev_find_slot(0, PCI_DEVFN(0x14, 0));
240 word = pci_read_config16(sm_dev, 0x56);
241 word |= 1 << 7;
242 pci_write_config16(sm_dev, 0x56, word);
243
244 /* set GPIO 64 internal pull-up */
245 byte = pm2_ioread(0xf0);
246 byte &= 0xee;
247 pm2_iowrite(0xf0, byte);
248
249 /* set Talert to be active low */
250 byte = pm_ioread(0x67);
251 byte &= ~(1 << 5);
252 pm_iowrite(0x67, byte);
253
254 /* set Talert to generate ACPI event */
255 byte = pm_ioread(0x3c);
256 byte &= 0xf3;
257 pm_iowrite(0x3c, byte);
258
259 /* THERMTRIP pin */
260 /* byte = pm_ioread(0x68);
261 * byte |= 1 << 3;
262 * pm_iowrite(0x68, byte);
263 *
264 * byte = pm_ioread(0x55);
265 * byte |= 1 << 0;
266 * pm_iowrite(0x55, byte);
267 *
268 * byte = pm_ioread(0x67);
269 * byte &= ~( 1 << 6);
270 * pm_iowrite(0x67, byte);
271 */
272}
273
274/*************************************************
275* enable the dedicated function in tilapia board.
276* This function called early than rs780_enable.
277*************************************************/
278static void tilapia_enable(device_t dev)
279{
Zheng Bao1ad9f292010-04-23 17:37:41 +0000280 printk(BIOS_INFO, "Mainboard TILAPIA Enable. dev=0x%p\n", dev);
281
Kyösti Mälkki231f2612012-07-11 08:02:57 +0300282 setup_uma_memory();
Zheng Bao1ad9f292010-04-23 17:37:41 +0000283
284 set_pcie_dereset();
285 /* get_ide_dma66(); */
286 set_thermal_config();
Wang Qing Pei543f7672010-08-17 11:11:09 +0000287 set_gpio40_gfx();
Zheng Bao1ad9f292010-04-23 17:37:41 +0000288}
289
290int add_mainboard_resources(struct lb_memory *mem)
291{
Zheng Bao1ad9f292010-04-23 17:37:41 +0000292 return 0;
293}
294
295struct chip_operations mainboard_ops = {
296 CHIP_NAME("AMD TILAPIA Mainboard")
297 .enable_dev = tilapia_enable,
298};