blob: 519e3c1175284a6fa1c48624777de46ab5aec595 [file] [log] [blame]
Frank Vibrans63e62b02011-02-14 18:38:14 +00001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2011 Advanced Micro Devices, Inc.
Dave Frodinac1b8752014-06-05 14:30:22 -06005 * Copyright (C) 2014 Sage Electronic Engineering, LLC
Frank Vibrans63e62b02011-02-14 18:38:14 +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.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
Paul Menzela46a7122013-02-23 18:37:27 +010018 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Frank Vibrans63e62b02011-02-14 18:38:14 +000019 */
20
Kerry Shefeed3292011-08-18 18:03:44 +080021#include <console/console.h>
Frank Vibrans63e62b02011-02-14 18:38:14 +000022#include <device/pci.h>
Martin Roth3aef7b42012-12-05 15:50:32 -070023#include <device/pci_def.h>
Patrick Georgi2c2e78d2012-02-16 18:54:37 +010024#include <arch/ioapic.h>
Frank Vibrans63e62b02011-02-14 18:38:14 +000025#include "lpc.h"
zbao9bcdbf82012-04-05 13:18:49 +080026#include <arch/io.h>
27#include <cbmem.h>
Frank Vibrans63e62b02011-02-14 18:38:14 +000028
29void lpc_read_resources(device_t dev)
30{
31 struct resource *res;
32
Kerry Shefeed3292011-08-18 18:03:44 +080033 printk(BIOS_DEBUG, "SB800 - Lpc.c - lpc_read_resources - Start.\n");
Frank Vibrans63e62b02011-02-14 18:38:14 +000034 /* Get the normal pci resources of this device */
35 pci_dev_read_resources(dev); /* We got one for APIC, or one more for TRAP */
36
Frank Vibrans63e62b02011-02-14 18:38:14 +000037 /* Add an extra subtractive resource for both memory and I/O. */
38 res = new_resource(dev, IOINDEX_SUBTRACTIVE(0, 0));
39 res->base = 0;
40 res->size = 0x1000;
41 res->flags = IORESOURCE_IO | IORESOURCE_SUBTRACTIVE |
42 IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
43
44 res = new_resource(dev, IOINDEX_SUBTRACTIVE(1, 0));
45 res->base = 0xff800000;
46 res->size = 0x00800000; /* 8 MB for flash */
47 res->flags = IORESOURCE_MEM | IORESOURCE_SUBTRACTIVE |
48 IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
49
Dave Frodinac1b8752014-06-05 14:30:22 -060050 /* Add a memory resource for the SPI BAR. */
51 fixed_mem_resource(dev, 2, SPI_BASE_ADDRESS / 1024, 1, IORESOURCE_SUBTRACTIVE);
52
Patrick Georgi2c2e78d2012-02-16 18:54:37 +010053 res = new_resource(dev, 3);
54 res->base = IO_APIC_ADDR;
Frank Vibrans63e62b02011-02-14 18:38:14 +000055 res->size = 0x00001000;
56 res->flags = IORESOURCE_MEM | IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
57
58 compact_resources(dev);
Kerry Shefeed3292011-08-18 18:03:44 +080059 printk(BIOS_DEBUG, "SB800 - Lpc.c - lpc_read_resources - End.\n");
Frank Vibrans63e62b02011-02-14 18:38:14 +000060}
61
62void lpc_set_resources(struct device *dev)
63{
64 struct resource *res;
65
Kerry Shefeed3292011-08-18 18:03:44 +080066 printk(BIOS_DEBUG, "SB800 - Lpc.c - lpc_set_resources - Start.\n");
Martin Roth3aef7b42012-12-05 15:50:32 -070067
68 /* Special case. SPI Base Address. The SpiRomEnable should STAY set. */
Dave Frodinac1b8752014-06-05 14:30:22 -060069 res = find_resource(dev, 2);
70 pci_write_config32(dev, SPIROM_BASE_ADDRESS_REGISTER, res->base | SPI_ROM_ENABLE);
Martin Roth3aef7b42012-12-05 15:50:32 -070071
Frank Vibrans63e62b02011-02-14 18:38:14 +000072 pci_dev_set_resources(dev);
73
Kerry Shefeed3292011-08-18 18:03:44 +080074 printk(BIOS_DEBUG, "SB800 - Lpc.c - lpc_set_resources - End.\n");
Frank Vibrans63e62b02011-02-14 18:38:14 +000075}
76
77/**
78 * @brief Enable resources for children devices
79 *
80 * @param dev the device whos children's resources are to be enabled
81 *
82 */
83void lpc_enable_childrens_resources(device_t dev)
84{
85 struct bus *link;
86 u32 reg, reg_x;
87 int var_num = 0;
88 u16 reg_var[3];
89
Kerry Shefeed3292011-08-18 18:03:44 +080090 printk(BIOS_DEBUG, "SB800 - Lpc.c - lpc_enable_childrens_resources - Start.\n");
Frank Vibrans63e62b02011-02-14 18:38:14 +000091 reg = pci_read_config32(dev, 0x44);
92 reg_x = pci_read_config32(dev, 0x48);
93
94 for (link = dev->link_list; link; link = link->next) {
95 device_t child;
96 for (child = link->children; child;
97 child = child->sibling) {
98 if (child->enabled
99 && (child->path.type == DEVICE_PATH_PNP)) {
100 struct resource *res;
101 for (res = child->resource_list; res; res = res->next) {
102 u32 base, end; /* don't need long long */
103 if (!(res->flags & IORESOURCE_IO))
104 continue;
105 base = res->base;
106 end = resource_end(res);
107/*
108 printk(BIOS_DEBUG, "sb800 lpc decode:%s, base=0x%08x, end=0x%08x\n",
109 dev_path(child), base, end);
110*/
111 switch (base) {
112 case 0x60: /* KB */
113 case 0x64: /* MS */
114 reg |= (1 << 29);
115 break;
116 case 0x3f8: /* COM1 */
117 reg |= (1 << 6);
118 break;
119 case 0x2f8: /* COM2 */
120 reg |= (1 << 7);
121 break;
122 case 0x378: /* Parallal 1 */
123 reg |= (1 << 0);
124 break;
125 case 0x3f0: /* FD0 */
126 reg |= (1 << 26);
127 break;
128 case 0x220: /* Aduio 0 */
129 reg |= (1 << 8);
130 break;
131 case 0x300: /* Midi 0 */
132 reg |= (1 << 18);
133 break;
134 case 0x400:
135 reg_x |= (1 << 16);
136 break;
137 case 0x480:
138 reg_x |= (1 << 17);
139 break;
140 case 0x500:
141 reg_x |= (1 << 18);
142 break;
143 case 0x580:
144 reg_x |= (1 << 19);
145 break;
146 case 0x4700:
147 reg_x |= (1 << 22);
148 break;
149 case 0xfd60:
150 reg_x |= (1 << 23);
151 break;
152 default:
153 if (var_num >= 3)
154 continue; /* only 3 var ; compact them ? */
155 switch (var_num) {
156 case 0:
157 reg_x |= (1 << 2);
158 break;
159 case 1:
160 reg_x |= (1 << 24);
161 break;
162 case 2:
163 reg_x |= (1 << 25);
164 break;
165 }
166 reg_var[var_num++] =
167 base & 0xffff;
168 }
169 }
170 }
171 }
172 }
173 pci_write_config32(dev, 0x44, reg);
174 pci_write_config32(dev, 0x48, reg_x);
175 /* Set WideIO for as many IOs found (fall through is on purpose) */
176 switch (var_num) {
177 case 2:
178 pci_write_config16(dev, 0x90, reg_var[2]);
179 case 1:
180 pci_write_config16(dev, 0x66, reg_var[1]);
181 case 0:
182 //pci_write_config16(dev, 0x64, reg_var[0]); //cause filo can not find sata
183 break;
184 }
Kerry Shefeed3292011-08-18 18:03:44 +0800185 printk(BIOS_DEBUG, "SB800 - Lpc.c - lpc_enable_childrens_resources - End.\n");
Frank Vibrans63e62b02011-02-14 18:38:14 +0000186}