blob: 8ebc765c0bf17f1db6d2e16309bf93d9e2955569 [file] [log] [blame]
Zheng Baoeff2ffd2010-03-16 01:38:54 +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
Paul Menzela46a7122013-02-23 18:37:27 +010017 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Zheng Baoeff2ffd2010-03-16 01:38:54 +000018 */
19
20#include <console/console.h>
21#include <device/device.h>
22#include <device/pci.h>
23#include <device/pnp.h>
24#include <device/pci_ids.h>
25#include <device/pci_ops.h>
26#include <pc80/mc146818rtc.h>
Vladimir Serbinenko6985d4e2014-09-21 14:31:19 +020027#include <arch/acpi.h>
28#include <arch/acpigen.h>
Zheng Baoeff2ffd2010-03-16 01:38:54 +000029#include <pc80/isa-dma.h>
Zheng Baoeff2ffd2010-03-16 01:38:54 +000030#include <arch/io.h>
Uwe Hermann74d1a6e2010-10-12 17:34:08 +000031#include <arch/ioapic.h>
Vladimir Serbinenko6985d4e2014-09-21 14:31:19 +020032#include <arch/acpi.h>
Rudolf Marekc4369532010-12-13 19:59:13 +000033#include <cbmem.h>
Vladimir Serbinenko47432542014-10-05 14:54:26 +020034#include <cpu/amd/powernow.h>
Zheng Baoeff2ffd2010-03-16 01:38:54 +000035#include "sb700.h"
36
Vladimir Serbinenko6985d4e2014-09-21 14:31:19 +020037unsigned long acpi_fill_mcfg(unsigned long current)
38{
39 /* Just a dummy */
40 return current;
41}
42
Zheng Baoeff2ffd2010-03-16 01:38:54 +000043static void lpc_init(device_t dev)
44{
45 u8 byte;
46 u32 dword;
47 device_t sm_dev;
48
49 /* Enable the LPC Controller */
50 sm_dev = dev_find_slot(0, PCI_DEVFN(0x14, 0));
51 dword = pci_read_config32(sm_dev, 0x64);
52 dword |= 1 << 20;
53 pci_write_config32(sm_dev, 0x64, dword);
54
55 /* Initialize isa dma */
Juhana Helovuo50b78b62010-09-13 14:43:02 +000056#if CONFIG_SOUTHBRIDGE_AMD_SB700_SKIP_ISA_DMA_INIT
57 printk(BIOS_DEBUG, "Skipping isa_dma_init() to avoid getting stuck.\n");
58#else
Zheng Baoeff2ffd2010-03-16 01:38:54 +000059 isa_dma_init();
Juhana Helovuo50b78b62010-09-13 14:43:02 +000060#endif
Zheng Baoeff2ffd2010-03-16 01:38:54 +000061
62 /* Enable DMA transaction on the LPC bus */
63 byte = pci_read_config8(dev, 0x40);
64 byte |= (1 << 2);
65 pci_write_config8(dev, 0x40, byte);
66
67 /* Disable the timeout mechanism on LPC */
68 byte = pci_read_config8(dev, 0x48);
69 byte &= ~(1 << 7);
70 pci_write_config8(dev, 0x48, byte);
71
72 /* Disable LPC MSI Capability */
73 byte = pci_read_config8(dev, 0x78);
74 byte &= ~(1 << 1);
Kyösti Mälkki399fcdd2012-02-23 18:42:55 +020075#if CONFIG_SOUTHBRIDGE_AMD_SUBTYPE_SP5100
Zheng Baoc3422232011-03-28 03:33:10 +000076 /* Disable FlowContrl, Always service the request from Host
77 * whenever there is a request from Host pending
78 */
79 byte &= ~(1 << 0);
80#endif
Zheng Baoeff2ffd2010-03-16 01:38:54 +000081 pci_write_config8(dev, 0x78, byte);
Rudolf Marekc4369532010-12-13 19:59:13 +000082
83 /* hack, but the whole sb700 startup lacks any device which
84 is doing the acpi init */
Patrick Georgie1667822012-05-05 15:29:32 +020085#if CONFIG_HAVE_ACPI_RESUME
Rudolf Marekc4369532010-12-13 19:59:13 +000086 {
Rudolf Marekc4369532010-12-13 19:59:13 +000087 u16 tmp = inw(ACPI_PM1_CNT_BLK);
88 acpi_slp_type = ((tmp & (7 << 10)) >> 10);
89 printk(BIOS_DEBUG, "SLP_TYP type was %x\n", acpi_slp_type);
90 }
91#endif
zbao366f0fc2012-08-03 16:58:53 +080092
Gabe Black03abaee212014-04-30 21:31:44 -070093 cmos_check_update_date();
Rudolf Marekc4369532010-12-13 19:59:13 +000094}
95
Kyösti Mälkkibc90e152013-09-04 13:26:11 +030096void backup_top_of_ram(uint64_t ramtop)
Zheng Baoa5c949e2011-01-27 03:31:50 +000097{
Kyösti Mälkkibc90e152013-09-04 13:26:11 +030098 u32 dword = (u32) ramtop;
Rudolf Marekc4369532010-12-13 19:59:13 +000099 int nvram_pos = 0xfc, i;
100 for (i = 0; i<4; i++) {
101 outb(nvram_pos, BIOSRAM_INDEX);
102 outb((dword >>(8 * i)) & 0xff , BIOSRAM_DATA);
103 nvram_pos++;
104 }
Zheng Baoeff2ffd2010-03-16 01:38:54 +0000105}
106
107static void sb700_lpc_read_resources(device_t dev)
108{
109 struct resource *res;
110
111 /* Get the normal pci resources of this device */
112 pci_dev_read_resources(dev); /* We got one for APIC, or one more for TRAP */
113
114 pci_get_resource(dev, 0xA0); /* SPI ROM base address */
115
116 /* Add an extra subtractive resource for both memory and I/O. */
117 res = new_resource(dev, IOINDEX_SUBTRACTIVE(0, 0));
118 res->base = 0;
119 res->size = 0x1000;
120 res->flags = IORESOURCE_IO | IORESOURCE_SUBTRACTIVE |
121 IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
122
123 res = new_resource(dev, IOINDEX_SUBTRACTIVE(1, 0));
124 res->base = 0xff800000;
125 res->size = 0x00800000; /* 8 MB for flash */
126 res->flags = IORESOURCE_MEM | IORESOURCE_SUBTRACTIVE |
127 IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
128
129 res = new_resource(dev, 3); /* IOAPIC */
Uwe Hermann74d1a6e2010-10-12 17:34:08 +0000130 res->base = IO_APIC_ADDR;
Zheng Baoeff2ffd2010-03-16 01:38:54 +0000131 res->size = 0x00001000;
132 res->flags = IORESOURCE_MEM | IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
133
134 compact_resources(dev);
135}
136
137static void sb700_lpc_set_resources(struct device *dev)
138{
139 struct resource *res;
Zheng Baoeff2ffd2010-03-16 01:38:54 +0000140
141 pci_dev_set_resources(dev);
142
Martin Rothdcf253c2014-12-16 20:51:31 -0700143 /* Special case. SPI Base Address. The SpiRomEnable should be set. */
Zheng Baoeff2ffd2010-03-16 01:38:54 +0000144 res = find_resource(dev, 0xA0);
145 pci_write_config32(dev, 0xA0, res->base | 1 << 1);
Zheng Baoeff2ffd2010-03-16 01:38:54 +0000146}
147
148/**
149 * @brief Enable resources for children devices
150 *
Zheng Bao2a5101a2010-10-10 15:18:53 +0000151 * @param dev the device whose children's resources are to be enabled
Zheng Baoeff2ffd2010-03-16 01:38:54 +0000152 *
Zheng Baoeff2ffd2010-03-16 01:38:54 +0000153 */
154static void sb700_lpc_enable_childrens_resources(device_t dev)
155{
Myles Watson894a3472010-06-09 22:41:35 +0000156 struct bus *link;
Zheng Baoeff2ffd2010-03-16 01:38:54 +0000157 u32 reg, reg_x;
Zheng Baoeff2ffd2010-03-16 01:38:54 +0000158 int var_num = 0;
Rudolf Marek86bd99a2011-01-28 20:57:48 +0000159 u16 reg_var[3] = {0x0, 0x0, 0x0};
160 u8 wiosize = pci_read_config8(dev, 0x74);
Zheng Baoeff2ffd2010-03-16 01:38:54 +0000161
162 reg = pci_read_config32(dev, 0x44);
163 reg_x = pci_read_config32(dev, 0x48);
164
Myles Watson894a3472010-06-09 22:41:35 +0000165 for (link = dev->link_list; link; link = link->next) {
Zheng Baoeff2ffd2010-03-16 01:38:54 +0000166 device_t child;
Myles Watson894a3472010-06-09 22:41:35 +0000167 for (child = link->children; child;
Zheng Baoeff2ffd2010-03-16 01:38:54 +0000168 child = child->sibling) {
Zheng Baoeff2ffd2010-03-16 01:38:54 +0000169 if (child->enabled
170 && (child->path.type == DEVICE_PATH_PNP)) {
Myles Watsonc25cc112010-05-21 14:33:48 +0000171 struct resource *res;
172 for (res = child->resource_list; res; res = res->next) {
Zheng Baoeff2ffd2010-03-16 01:38:54 +0000173 u32 base, end; /* don't need long long */
Zheng Baoeff2ffd2010-03-16 01:38:54 +0000174 if (!(res->flags & IORESOURCE_IO))
175 continue;
176 base = res->base;
177 end = resource_end(res);
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000178 printk(BIOS_DEBUG, "sb700 lpc decode:%s, base=0x%08x, end=0x%08x\n",
Zheng Baoeff2ffd2010-03-16 01:38:54 +0000179 dev_path(child), base, end);
180 switch (base) {
181 case 0x60: /* KB */
182 case 0x64: /* MS */
183 reg |= (1 << 29);
184 break;
185 case 0x3f8: /* COM1 */
186 reg |= (1 << 6);
187 break;
188 case 0x2f8: /* COM2 */
189 reg |= (1 << 7);
190 break;
Rudolf Marek86bd99a2011-01-28 20:57:48 +0000191 case 0x378: /* Parallel 1 */
Zheng Baoeff2ffd2010-03-16 01:38:54 +0000192 reg |= (1 << 0);
Rudolf Marek86bd99a2011-01-28 20:57:48 +0000193 reg |= (1 << 1); /* + 0x778 for ECP */
Zheng Baoeff2ffd2010-03-16 01:38:54 +0000194 break;
195 case 0x3f0: /* FD0 */
196 reg |= (1 << 26);
197 break;
Rudolf Marek86bd99a2011-01-28 20:57:48 +0000198 case 0x220: /* Audio 0 */
Zheng Baoeff2ffd2010-03-16 01:38:54 +0000199 reg |= (1 << 8);
200 break;
201 case 0x300: /* Midi 0 */
202 reg |= (1 << 18);
203 break;
204 case 0x400:
205 reg_x |= (1 << 16);
206 break;
207 case 0x480:
208 reg_x |= (1 << 17);
209 break;
210 case 0x500:
211 reg_x |= (1 << 18);
212 break;
213 case 0x580:
214 reg_x |= (1 << 19);
215 break;
216 case 0x4700:
217 reg_x |= (1 << 22);
218 break;
219 case 0xfd60:
220 reg_x |= (1 << 23);
221 break;
222 default:
223 if (var_num >= 3)
224 continue; /* only 3 var ; compact them ? */
225 switch (var_num) {
226 case 0:
227 reg_x |= (1 << 2);
Rudolf Marek86bd99a2011-01-28 20:57:48 +0000228 if ((end - base) < 16)
229 wiosize |= (1 << 0);
Zheng Baoeff2ffd2010-03-16 01:38:54 +0000230 break;
231 case 1:
232 reg_x |= (1 << 24);
Rudolf Marek86bd99a2011-01-28 20:57:48 +0000233 if ((end - base) < 16)
234 wiosize |= (1 << 2);
Zheng Baoeff2ffd2010-03-16 01:38:54 +0000235 break;
236 case 2:
237 reg_x |= (1 << 25);
Rudolf Marek86bd99a2011-01-28 20:57:48 +0000238 reg_x |= (1 << 24);
239 if ((end - base) < 16)
240 wiosize |= (1 << 3);
Zheng Baoeff2ffd2010-03-16 01:38:54 +0000241 break;
242 }
243 reg_var[var_num++] =
244 base & 0xffff;
245 }
246 }
247 }
248 }
249 }
250 pci_write_config32(dev, 0x44, reg);
251 pci_write_config32(dev, 0x48, reg_x);
252 /* Set WideIO for as many IOs found (fall through is on purpose) */
253 switch (var_num) {
254 case 2:
255 pci_write_config16(dev, 0x90, reg_var[2]);
256 case 1:
257 pci_write_config16(dev, 0x66, reg_var[1]);
258 case 0:
259 pci_write_config16(dev, 0x64, reg_var[0]);
260 break;
261 }
Rudolf Marek86bd99a2011-01-28 20:57:48 +0000262 pci_write_config8(dev, 0x74, wiosize);
Zheng Baoeff2ffd2010-03-16 01:38:54 +0000263}
264
265static void sb700_lpc_enable_resources(device_t dev)
266{
267 pci_dev_enable_resources(dev);
268 sb700_lpc_enable_childrens_resources(dev);
269}
270
Vladimir Serbinenkof21271e2014-10-16 18:00:27 +0200271#if IS_ENABLED(CONFIG_HAVE_ACPI_TABLES) && IS_ENABLED(CONFIG_PER_DEVICE_ACPI_TABLES)
Vladimir Serbinenko6985d4e2014-09-21 14:31:19 +0200272
273static void southbridge_acpi_fill_ssdt_generator(void) {
Vladimir Serbinenko47432542014-10-05 14:54:26 +0200274 amd_generate_powernow(ACPI_CPU_CONTROL, 6, 1);
Vladimir Serbinenko6985d4e2014-09-21 14:31:19 +0200275}
276
277#endif
278
279
Zheng Baoeff2ffd2010-03-16 01:38:54 +0000280static struct pci_operations lops_pci = {
281 .set_subsystem = pci_dev_set_subsystem,
282};
283
284static struct device_operations lpc_ops = {
285 .read_resources = sb700_lpc_read_resources,
286 .set_resources = sb700_lpc_set_resources,
287 .enable_resources = sb700_lpc_enable_resources,
Vladimir Serbinenkof21271e2014-10-16 18:00:27 +0200288#if IS_ENABLED(CONFIG_HAVE_ACPI_TABLES) && IS_ENABLED(CONFIG_PER_DEVICE_ACPI_TABLES)
Vladimir Serbinenko6985d4e2014-09-21 14:31:19 +0200289 .write_acpi_tables = acpi_write_hpet,
290 .acpi_fill_ssdt_generator = southbridge_acpi_fill_ssdt_generator,
291#endif
Zheng Baoeff2ffd2010-03-16 01:38:54 +0000292 .init = lpc_init,
293 .scan_bus = scan_static_bus,
294 .ops_pci = &lops_pci,
295};
Stefan Reinauer8e96ba22010-03-16 23:33:29 +0000296static const struct pci_driver lpc_driver __pci_driver = {
Zheng Baoeff2ffd2010-03-16 01:38:54 +0000297 .ops = &lpc_ops,
298 .vendor = PCI_VENDOR_ID_ATI,
299 .device = PCI_DEVICE_ID_ATI_SB700_LPC,
300};