blob: 78933fadf4ee5e3538a0a7bd045188001c0aafb2 [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.
Timothy Pearsonee3ec8e2015-10-23 22:28:26 -05005 * Copyright (C) 2015 Timothy Pearson <tpearson@raptorengineeringinc.com>, Raptor Engineering
Zheng Baoeff2ffd2010-03-16 01:38:54 +00006 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; version 2 of the License.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
Zheng Baoeff2ffd2010-03-16 01:38:54 +000015 */
16
17#include <console/console.h>
18#include <device/device.h>
19#include <device/pci.h>
20#include <device/pnp.h>
21#include <device/pci_ids.h>
22#include <device/pci_ops.h>
23#include <pc80/mc146818rtc.h>
Vladimir Serbinenko6985d4e2014-09-21 14:31:19 +020024#include <arch/acpi.h>
25#include <arch/acpigen.h>
Zheng Baoeff2ffd2010-03-16 01:38:54 +000026#include <pc80/isa-dma.h>
Zheng Baoeff2ffd2010-03-16 01:38:54 +000027#include <arch/io.h>
Uwe Hermann74d1a6e2010-10-12 17:34:08 +000028#include <arch/ioapic.h>
Rudolf Marekc4369532010-12-13 19:59:13 +000029#include <cbmem.h>
Vladimir Serbinenko47432542014-10-05 14:54:26 +020030#include <cpu/amd/powernow.h>
Zheng Baoeff2ffd2010-03-16 01:38:54 +000031#include "sb700.h"
32
33static void lpc_init(device_t dev)
34{
35 u8 byte;
36 u32 dword;
37 device_t sm_dev;
38
Timothy Pearsonee3ec8e2015-10-23 22:28:26 -050039 printk(BIOS_SPEW, "%s\n", __func__);
40
Zheng Baoeff2ffd2010-03-16 01:38:54 +000041 /* Enable the LPC Controller */
42 sm_dev = dev_find_slot(0, PCI_DEVFN(0x14, 0));
43 dword = pci_read_config32(sm_dev, 0x64);
44 dword |= 1 << 20;
45 pci_write_config32(sm_dev, 0x64, dword);
46
47 /* Initialize isa dma */
Juhana Helovuo50b78b62010-09-13 14:43:02 +000048#if CONFIG_SOUTHBRIDGE_AMD_SB700_SKIP_ISA_DMA_INIT
49 printk(BIOS_DEBUG, "Skipping isa_dma_init() to avoid getting stuck.\n");
50#else
Zheng Baoeff2ffd2010-03-16 01:38:54 +000051 isa_dma_init();
Juhana Helovuo50b78b62010-09-13 14:43:02 +000052#endif
Zheng Baoeff2ffd2010-03-16 01:38:54 +000053
Timothy Pearson85c39a42015-09-05 18:14:25 -050054 if (!IS_ENABLED(CONFIG_SOUTHBRIDGE_AMD_SB700_DISABLE_ISA_DMA)) {
55 /* Enable DMA transaction on the LPC bus */
56 byte = pci_read_config8(dev, 0x40);
57 byte |= (1 << 2);
58 pci_write_config8(dev, 0x40, byte);
59 }
Zheng Baoeff2ffd2010-03-16 01:38:54 +000060
61 /* Disable the timeout mechanism on LPC */
62 byte = pci_read_config8(dev, 0x48);
63 byte &= ~(1 << 7);
64 pci_write_config8(dev, 0x48, byte);
65
66 /* Disable LPC MSI Capability */
67 byte = pci_read_config8(dev, 0x78);
68 byte &= ~(1 << 1);
Kyösti Mälkki399fcdd2012-02-23 18:42:55 +020069#if CONFIG_SOUTHBRIDGE_AMD_SUBTYPE_SP5100
Zheng Baoc3422232011-03-28 03:33:10 +000070 /* Disable FlowContrl, Always service the request from Host
71 * whenever there is a request from Host pending
72 */
73 byte &= ~(1 << 0);
74#endif
Zheng Baoeff2ffd2010-03-16 01:38:54 +000075 pci_write_config8(dev, 0x78, byte);
Rudolf Marekc4369532010-12-13 19:59:13 +000076
Gabe Black03abaee212014-04-30 21:31:44 -070077 cmos_check_update_date();
Rudolf Marekc4369532010-12-13 19:59:13 +000078}
79
Timothy Pearson07464522015-10-30 14:46:18 -050080#if IS_ENABLED(CONFIG_LATE_CBMEM_INIT)
Kyösti Mälkki78c5d582015-01-09 23:48:47 +020081int acpi_get_sleep_type(void)
82{
83 u16 tmp = inw(ACPI_PM1_CNT_BLK);
84 return ((tmp & (7 << 10)) >> 10);
85}
86
Kyösti Mälkkibc90e152013-09-04 13:26:11 +030087void backup_top_of_ram(uint64_t ramtop)
Zheng Baoa5c949e2011-01-27 03:31:50 +000088{
Kyösti Mälkkibc90e152013-09-04 13:26:11 +030089 u32 dword = (u32) ramtop;
Rudolf Marekc4369532010-12-13 19:59:13 +000090 int nvram_pos = 0xfc, i;
91 for (i = 0; i<4; i++) {
92 outb(nvram_pos, BIOSRAM_INDEX);
93 outb((dword >>(8 * i)) & 0xff , BIOSRAM_DATA);
94 nvram_pos++;
95 }
Zheng Baoeff2ffd2010-03-16 01:38:54 +000096}
Kyösti Mälkki4da487e2015-03-19 06:58:15 +020097#endif
Zheng Baoeff2ffd2010-03-16 01:38:54 +000098
99static void sb700_lpc_read_resources(device_t dev)
100{
101 struct resource *res;
102
103 /* Get the normal pci resources of this device */
104 pci_dev_read_resources(dev); /* We got one for APIC, or one more for TRAP */
105
106 pci_get_resource(dev, 0xA0); /* SPI ROM base address */
107
108 /* Add an extra subtractive resource for both memory and I/O. */
109 res = new_resource(dev, IOINDEX_SUBTRACTIVE(0, 0));
110 res->base = 0;
111 res->size = 0x1000;
112 res->flags = IORESOURCE_IO | IORESOURCE_SUBTRACTIVE |
113 IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
114
115 res = new_resource(dev, IOINDEX_SUBTRACTIVE(1, 0));
116 res->base = 0xff800000;
117 res->size = 0x00800000; /* 8 MB for flash */
118 res->flags = IORESOURCE_MEM | IORESOURCE_SUBTRACTIVE |
119 IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
120
121 res = new_resource(dev, 3); /* IOAPIC */
Uwe Hermann74d1a6e2010-10-12 17:34:08 +0000122 res->base = IO_APIC_ADDR;
Zheng Baoeff2ffd2010-03-16 01:38:54 +0000123 res->size = 0x00001000;
124 res->flags = IORESOURCE_MEM | IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
125
126 compact_resources(dev);
127}
128
129static void sb700_lpc_set_resources(struct device *dev)
130{
131 struct resource *res;
Zheng Baoeff2ffd2010-03-16 01:38:54 +0000132
133 pci_dev_set_resources(dev);
134
Martin Rothdcf253c2014-12-16 20:51:31 -0700135 /* Special case. SPI Base Address. The SpiRomEnable should be set. */
Zheng Baoeff2ffd2010-03-16 01:38:54 +0000136 res = find_resource(dev, 0xA0);
137 pci_write_config32(dev, 0xA0, res->base | 1 << 1);
Zheng Baoeff2ffd2010-03-16 01:38:54 +0000138}
139
140/**
141 * @brief Enable resources for children devices
142 *
Zheng Bao2a5101a2010-10-10 15:18:53 +0000143 * @param dev the device whose children's resources are to be enabled
Zheng Baoeff2ffd2010-03-16 01:38:54 +0000144 *
Zheng Baoeff2ffd2010-03-16 01:38:54 +0000145 */
146static void sb700_lpc_enable_childrens_resources(device_t dev)
147{
Myles Watson894a3472010-06-09 22:41:35 +0000148 struct bus *link;
Zheng Baoeff2ffd2010-03-16 01:38:54 +0000149 u32 reg, reg_x;
Zheng Baoeff2ffd2010-03-16 01:38:54 +0000150 int var_num = 0;
Rudolf Marek86bd99a2011-01-28 20:57:48 +0000151 u16 reg_var[3] = {0x0, 0x0, 0x0};
152 u8 wiosize = pci_read_config8(dev, 0x74);
Zheng Baoeff2ffd2010-03-16 01:38:54 +0000153
154 reg = pci_read_config32(dev, 0x44);
155 reg_x = pci_read_config32(dev, 0x48);
156
Myles Watson894a3472010-06-09 22:41:35 +0000157 for (link = dev->link_list; link; link = link->next) {
Zheng Baoeff2ffd2010-03-16 01:38:54 +0000158 device_t child;
Myles Watson894a3472010-06-09 22:41:35 +0000159 for (child = link->children; child;
Zheng Baoeff2ffd2010-03-16 01:38:54 +0000160 child = child->sibling) {
Zheng Baoeff2ffd2010-03-16 01:38:54 +0000161 if (child->enabled
162 && (child->path.type == DEVICE_PATH_PNP)) {
Myles Watsonc25cc112010-05-21 14:33:48 +0000163 struct resource *res;
164 for (res = child->resource_list; res; res = res->next) {
Zheng Baoeff2ffd2010-03-16 01:38:54 +0000165 u32 base, end; /* don't need long long */
Zheng Baoeff2ffd2010-03-16 01:38:54 +0000166 if (!(res->flags & IORESOURCE_IO))
167 continue;
168 base = res->base;
169 end = resource_end(res);
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000170 printk(BIOS_DEBUG, "sb700 lpc decode:%s, base=0x%08x, end=0x%08x\n",
Zheng Baoeff2ffd2010-03-16 01:38:54 +0000171 dev_path(child), base, end);
172 switch (base) {
173 case 0x60: /* KB */
174 case 0x64: /* MS */
175 reg |= (1 << 29);
176 break;
177 case 0x3f8: /* COM1 */
178 reg |= (1 << 6);
179 break;
180 case 0x2f8: /* COM2 */
181 reg |= (1 << 7);
182 break;
Rudolf Marek86bd99a2011-01-28 20:57:48 +0000183 case 0x378: /* Parallel 1 */
Zheng Baoeff2ffd2010-03-16 01:38:54 +0000184 reg |= (1 << 0);
Rudolf Marek86bd99a2011-01-28 20:57:48 +0000185 reg |= (1 << 1); /* + 0x778 for ECP */
Zheng Baoeff2ffd2010-03-16 01:38:54 +0000186 break;
187 case 0x3f0: /* FD0 */
188 reg |= (1 << 26);
189 break;
Rudolf Marek86bd99a2011-01-28 20:57:48 +0000190 case 0x220: /* Audio 0 */
Zheng Baoeff2ffd2010-03-16 01:38:54 +0000191 reg |= (1 << 8);
192 break;
193 case 0x300: /* Midi 0 */
194 reg |= (1 << 18);
195 break;
196 case 0x400:
197 reg_x |= (1 << 16);
198 break;
199 case 0x480:
200 reg_x |= (1 << 17);
201 break;
202 case 0x500:
203 reg_x |= (1 << 18);
204 break;
205 case 0x580:
206 reg_x |= (1 << 19);
207 break;
208 case 0x4700:
209 reg_x |= (1 << 22);
210 break;
211 case 0xfd60:
212 reg_x |= (1 << 23);
213 break;
214 default:
215 if (var_num >= 3)
216 continue; /* only 3 var ; compact them ? */
217 switch (var_num) {
218 case 0:
219 reg_x |= (1 << 2);
Rudolf Marek86bd99a2011-01-28 20:57:48 +0000220 if ((end - base) < 16)
221 wiosize |= (1 << 0);
Zheng Baoeff2ffd2010-03-16 01:38:54 +0000222 break;
223 case 1:
224 reg_x |= (1 << 24);
Rudolf Marek86bd99a2011-01-28 20:57:48 +0000225 if ((end - base) < 16)
226 wiosize |= (1 << 2);
Zheng Baoeff2ffd2010-03-16 01:38:54 +0000227 break;
228 case 2:
229 reg_x |= (1 << 25);
Rudolf Marek86bd99a2011-01-28 20:57:48 +0000230 reg_x |= (1 << 24);
231 if ((end - base) < 16)
232 wiosize |= (1 << 3);
Zheng Baoeff2ffd2010-03-16 01:38:54 +0000233 break;
234 }
235 reg_var[var_num++] =
236 base & 0xffff;
237 }
238 }
239 }
240 }
241 }
242 pci_write_config32(dev, 0x44, reg);
243 pci_write_config32(dev, 0x48, reg_x);
244 /* Set WideIO for as many IOs found (fall through is on purpose) */
245 switch (var_num) {
246 case 2:
247 pci_write_config16(dev, 0x90, reg_var[2]);
248 case 1:
249 pci_write_config16(dev, 0x66, reg_var[1]);
250 case 0:
251 pci_write_config16(dev, 0x64, reg_var[0]);
252 break;
253 }
Rudolf Marek86bd99a2011-01-28 20:57:48 +0000254 pci_write_config8(dev, 0x74, wiosize);
Zheng Baoeff2ffd2010-03-16 01:38:54 +0000255}
256
257static void sb700_lpc_enable_resources(device_t dev)
258{
259 pci_dev_enable_resources(dev);
260 sb700_lpc_enable_childrens_resources(dev);
261}
262
Vladimir Serbinenko83f81ca2014-11-09 13:30:50 +0100263#if IS_ENABLED(CONFIG_HAVE_ACPI_TABLES)
Vladimir Serbinenko6985d4e2014-09-21 14:31:19 +0200264
Alexander Couzens5eea4582015-04-12 22:18:55 +0200265static void southbridge_acpi_fill_ssdt_generator(device_t device) {
Vladimir Serbinenko47432542014-10-05 14:54:26 +0200266 amd_generate_powernow(ACPI_CPU_CONTROL, 6, 1);
Vladimir Serbinenko6985d4e2014-09-21 14:31:19 +0200267}
268
269#endif
270
271
Zheng Baoeff2ffd2010-03-16 01:38:54 +0000272static struct pci_operations lops_pci = {
273 .set_subsystem = pci_dev_set_subsystem,
274};
275
276static struct device_operations lpc_ops = {
277 .read_resources = sb700_lpc_read_resources,
278 .set_resources = sb700_lpc_set_resources,
279 .enable_resources = sb700_lpc_enable_resources,
Vladimir Serbinenko83f81ca2014-11-09 13:30:50 +0100280#if IS_ENABLED(CONFIG_HAVE_ACPI_TABLES)
Vladimir Serbinenko6985d4e2014-09-21 14:31:19 +0200281 .write_acpi_tables = acpi_write_hpet,
282 .acpi_fill_ssdt_generator = southbridge_acpi_fill_ssdt_generator,
283#endif
Zheng Baoeff2ffd2010-03-16 01:38:54 +0000284 .init = lpc_init,
Kyösti Mälkkid0e212c2015-02-26 20:47:47 +0200285 .scan_bus = scan_lpc_bus,
Zheng Baoeff2ffd2010-03-16 01:38:54 +0000286 .ops_pci = &lops_pci,
287};
Stefan Reinauer8e96ba22010-03-16 23:33:29 +0000288static const struct pci_driver lpc_driver __pci_driver = {
Zheng Baoeff2ffd2010-03-16 01:38:54 +0000289 .ops = &lpc_ops,
290 .vendor = PCI_VENDOR_ID_ATI,
291 .device = PCI_DEVICE_ID_ATI_SB700_LPC,
292};