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