blob: 59d74c07371e8d9b33fd5cb44a8c5f372cb1c88f [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.
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
Kerry Shefeed3292011-08-18 18:03:44 +080020#include <console/console.h>
Frank Vibrans63e62b02011-02-14 18:38:14 +000021#include <device/pci.h>
Patrick Georgi2c2e78d2012-02-16 18:54:37 +010022#include <arch/ioapic.h>
Frank Vibrans63e62b02011-02-14 18:38:14 +000023#include "lpc.h"
zbao9bcdbf82012-04-05 13:18:49 +080024#include <bitops.h>
25#include <arch/io.h>
26#include <cbmem.h>
Frank Vibrans63e62b02011-02-14 18:38:14 +000027
28void lpc_read_resources(device_t dev)
29{
30 struct resource *res;
31
Kerry Shefeed3292011-08-18 18:03:44 +080032 printk(BIOS_DEBUG, "SB800 - Lpc.c - lpc_read_resources - Start.\n");
Frank Vibrans63e62b02011-02-14 18:38:14 +000033 /* Get the normal pci resources of this device */
34 pci_dev_read_resources(dev); /* We got one for APIC, or one more for TRAP */
35
36 pci_get_resource(dev, SPIROM_BASE_ADDRESS); /* SPI ROM base address */
37
38 /* Add an extra subtractive resource for both memory and I/O. */
39 res = new_resource(dev, IOINDEX_SUBTRACTIVE(0, 0));
40 res->base = 0;
41 res->size = 0x1000;
42 res->flags = IORESOURCE_IO | IORESOURCE_SUBTRACTIVE |
43 IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
44
45 res = new_resource(dev, IOINDEX_SUBTRACTIVE(1, 0));
46 res->base = 0xff800000;
47 res->size = 0x00800000; /* 8 MB for flash */
48 res->flags = IORESOURCE_MEM | IORESOURCE_SUBTRACTIVE |
49 IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
50
Patrick Georgi2c2e78d2012-02-16 18:54:37 +010051 res = new_resource(dev, 3);
52 res->base = IO_APIC_ADDR;
Frank Vibrans63e62b02011-02-14 18:38:14 +000053 res->size = 0x00001000;
54 res->flags = IORESOURCE_MEM | IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
55
56 compact_resources(dev);
Kerry Shefeed3292011-08-18 18:03:44 +080057 printk(BIOS_DEBUG, "SB800 - Lpc.c - lpc_read_resources - End.\n");
Frank Vibrans63e62b02011-02-14 18:38:14 +000058}
59
60void lpc_set_resources(struct device *dev)
61{
62 struct resource *res;
63
Kerry Shefeed3292011-08-18 18:03:44 +080064 printk(BIOS_DEBUG, "SB800 - Lpc.c - lpc_set_resources - Start.\n");
Frank Vibrans63e62b02011-02-14 18:38:14 +000065 pci_dev_set_resources(dev);
66
67 /* Specical case. SPI Base Address. The SpiRomEnable should be set. */
68 res = find_resource(dev, SPIROM_BASE_ADDRESS);
69 pci_write_config32(dev, SPIROM_BASE_ADDRESS, res->base | 1 << 1);
Kerry Shefeed3292011-08-18 18:03:44 +080070 printk(BIOS_DEBUG, "SB800 - Lpc.c - lpc_set_resources - End.\n");
Frank Vibrans63e62b02011-02-14 18:38:14 +000071}
72
73/**
74 * @brief Enable resources for children devices
75 *
76 * @param dev the device whos children's resources are to be enabled
77 *
78 */
79void lpc_enable_childrens_resources(device_t dev)
80{
81 struct bus *link;
82 u32 reg, reg_x;
83 int var_num = 0;
84 u16 reg_var[3];
85
Kerry Shefeed3292011-08-18 18:03:44 +080086 printk(BIOS_DEBUG, "SB800 - Lpc.c - lpc_enable_childrens_resources - Start.\n");
Frank Vibrans63e62b02011-02-14 18:38:14 +000087 reg = pci_read_config32(dev, 0x44);
88 reg_x = pci_read_config32(dev, 0x48);
89
90 for (link = dev->link_list; link; link = link->next) {
91 device_t child;
92 for (child = link->children; child;
93 child = child->sibling) {
94 if (child->enabled
95 && (child->path.type == DEVICE_PATH_PNP)) {
96 struct resource *res;
97 for (res = child->resource_list; res; res = res->next) {
98 u32 base, end; /* don't need long long */
99 if (!(res->flags & IORESOURCE_IO))
100 continue;
101 base = res->base;
102 end = resource_end(res);
103/*
104 printk(BIOS_DEBUG, "sb800 lpc decode:%s, base=0x%08x, end=0x%08x\n",
105 dev_path(child), base, end);
106*/
107 switch (base) {
108 case 0x60: /* KB */
109 case 0x64: /* MS */
110 reg |= (1 << 29);
111 break;
112 case 0x3f8: /* COM1 */
113 reg |= (1 << 6);
114 break;
115 case 0x2f8: /* COM2 */
116 reg |= (1 << 7);
117 break;
118 case 0x378: /* Parallal 1 */
119 reg |= (1 << 0);
120 break;
121 case 0x3f0: /* FD0 */
122 reg |= (1 << 26);
123 break;
124 case 0x220: /* Aduio 0 */
125 reg |= (1 << 8);
126 break;
127 case 0x300: /* Midi 0 */
128 reg |= (1 << 18);
129 break;
130 case 0x400:
131 reg_x |= (1 << 16);
132 break;
133 case 0x480:
134 reg_x |= (1 << 17);
135 break;
136 case 0x500:
137 reg_x |= (1 << 18);
138 break;
139 case 0x580:
140 reg_x |= (1 << 19);
141 break;
142 case 0x4700:
143 reg_x |= (1 << 22);
144 break;
145 case 0xfd60:
146 reg_x |= (1 << 23);
147 break;
148 default:
149 if (var_num >= 3)
150 continue; /* only 3 var ; compact them ? */
151 switch (var_num) {
152 case 0:
153 reg_x |= (1 << 2);
154 break;
155 case 1:
156 reg_x |= (1 << 24);
157 break;
158 case 2:
159 reg_x |= (1 << 25);
160 break;
161 }
162 reg_var[var_num++] =
163 base & 0xffff;
164 }
165 }
166 }
167 }
168 }
169 pci_write_config32(dev, 0x44, reg);
170 pci_write_config32(dev, 0x48, reg_x);
171 /* Set WideIO for as many IOs found (fall through is on purpose) */
172 switch (var_num) {
173 case 2:
174 pci_write_config16(dev, 0x90, reg_var[2]);
175 case 1:
176 pci_write_config16(dev, 0x66, reg_var[1]);
177 case 0:
178 //pci_write_config16(dev, 0x64, reg_var[0]); //cause filo can not find sata
179 break;
180 }
Kerry Shefeed3292011-08-18 18:03:44 +0800181 printk(BIOS_DEBUG, "SB800 - Lpc.c - lpc_enable_childrens_resources - End.\n");
Frank Vibrans63e62b02011-02-14 18:38:14 +0000182}