blob: 79f402993fc4d6813016903e76cc1fba856ca27a [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.
Frank Vibrans63e62b02011-02-14 18:38:14 +000015 */
16
Kerry Shefeed3292011-08-18 18:03:44 +080017#include <console/console.h>
Frank Vibrans63e62b02011-02-14 18:38:14 +000018#include <device/pci.h>
Martin Roth3aef7b42012-12-05 15:50:32 -070019#include <device/pci_def.h>
Patrick Georgi2c2e78d2012-02-16 18:54:37 +010020#include <arch/ioapic.h>
Frank Vibrans63e62b02011-02-14 18:38:14 +000021#include "lpc.h"
Kyösti Mälkkif1b58b72019-03-01 13:43:02 +020022#include <device/pci_ops.h>
Frank Vibrans63e62b02011-02-14 18:38:14 +000023
Elyes HAOUAS1a4abb72018-05-19 16:49:20 +020024void lpc_read_resources(struct device *dev)
Frank Vibrans63e62b02011-02-14 18:38:14 +000025{
26 struct resource *res;
27
Kerry Shefeed3292011-08-18 18:03:44 +080028 printk(BIOS_DEBUG, "SB800 - Lpc.c - lpc_read_resources - Start.\n");
Frank Vibrans63e62b02011-02-14 18:38:14 +000029 /* Get the normal pci resources of this device */
30 pci_dev_read_resources(dev); /* We got one for APIC, or one more for TRAP */
31
Frank Vibrans63e62b02011-02-14 18:38:14 +000032 /* Add an extra subtractive resource for both memory and I/O. */
33 res = new_resource(dev, IOINDEX_SUBTRACTIVE(0, 0));
34 res->base = 0;
35 res->size = 0x1000;
36 res->flags = IORESOURCE_IO | IORESOURCE_SUBTRACTIVE |
37 IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
38
39 res = new_resource(dev, IOINDEX_SUBTRACTIVE(1, 0));
40 res->base = 0xff800000;
41 res->size = 0x00800000; /* 8 MB for flash */
42 res->flags = IORESOURCE_MEM | IORESOURCE_SUBTRACTIVE |
43 IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
44
Dave Frodinac1b8752014-06-05 14:30:22 -060045 /* Add a memory resource for the SPI BAR. */
46 fixed_mem_resource(dev, 2, SPI_BASE_ADDRESS / 1024, 1, IORESOURCE_SUBTRACTIVE);
47
Patrick Georgi2c2e78d2012-02-16 18:54:37 +010048 res = new_resource(dev, 3);
49 res->base = IO_APIC_ADDR;
Frank Vibrans63e62b02011-02-14 18:38:14 +000050 res->size = 0x00001000;
51 res->flags = IORESOURCE_MEM | IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
52
53 compact_resources(dev);
Kerry Shefeed3292011-08-18 18:03:44 +080054 printk(BIOS_DEBUG, "SB800 - Lpc.c - lpc_read_resources - End.\n");
Frank Vibrans63e62b02011-02-14 18:38:14 +000055}
56
57void lpc_set_resources(struct device *dev)
58{
59 struct resource *res;
60
Kerry Shefeed3292011-08-18 18:03:44 +080061 printk(BIOS_DEBUG, "SB800 - Lpc.c - lpc_set_resources - Start.\n");
Martin Roth3aef7b42012-12-05 15:50:32 -070062
63 /* Special case. SPI Base Address. The SpiRomEnable should STAY set. */
Dave Frodinac1b8752014-06-05 14:30:22 -060064 res = find_resource(dev, 2);
65 pci_write_config32(dev, SPIROM_BASE_ADDRESS_REGISTER, res->base | SPI_ROM_ENABLE);
Martin Roth3aef7b42012-12-05 15:50:32 -070066
Frank Vibrans63e62b02011-02-14 18:38:14 +000067 pci_dev_set_resources(dev);
68
Kerry Shefeed3292011-08-18 18:03:44 +080069 printk(BIOS_DEBUG, "SB800 - Lpc.c - lpc_set_resources - End.\n");
Frank Vibrans63e62b02011-02-14 18:38:14 +000070}
71
72/**
73 * @brief Enable resources for children devices
74 *
Martin Roth3c3a50c2014-12-16 20:50:26 -070075 * @param dev the device whose children's resources are to be enabled
Frank Vibrans63e62b02011-02-14 18:38:14 +000076 *
77 */
Elyes HAOUAS1a4abb72018-05-19 16:49:20 +020078void lpc_enable_childrens_resources(struct device *dev)
Frank Vibrans63e62b02011-02-14 18:38:14 +000079{
80 struct bus *link;
81 u32 reg, reg_x;
82 int var_num = 0;
83 u16 reg_var[3];
84
Kerry Shefeed3292011-08-18 18:03:44 +080085 printk(BIOS_DEBUG, "SB800 - Lpc.c - lpc_enable_childrens_resources - Start.\n");
Frank Vibrans63e62b02011-02-14 18:38:14 +000086 reg = pci_read_config32(dev, 0x44);
87 reg_x = pci_read_config32(dev, 0x48);
88
89 for (link = dev->link_list; link; link = link->next) {
Elyes HAOUAS1a4abb72018-05-19 16:49:20 +020090 struct device *child;
Frank Vibrans63e62b02011-02-14 18:38:14 +000091 for (child = link->children; child;
92 child = child->sibling) {
93 if (child->enabled
94 && (child->path.type == DEVICE_PATH_PNP)) {
95 struct resource *res;
96 for (res = child->resource_list; res; res = res->next) {
Paul Menzel621abec2017-09-09 11:26:24 +020097 u32 base; /* don't need long long */
Frank Vibrans63e62b02011-02-14 18:38:14 +000098 if (!(res->flags & IORESOURCE_IO))
99 continue;
100 base = res->base;
Frank Vibrans63e62b02011-02-14 18:38:14 +0000101/*
Paul Menzel482f8222017-09-09 11:05:21 +0200102 printk(BIOS_DEBUG, "sb800 lpc decode:%s,
103 base=0x%08x, end=0x%08x\n",
Paul Menzel621abec2017-09-09 11:26:24 +0200104 dev_path(child), base,
105 resource_end(res));
Frank Vibrans63e62b02011-02-14 18:38:14 +0000106*/
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;
Martin Roth3c3a50c2014-12-16 20:50:26 -0700118 case 0x378: /* Parallel 1 */
Frank Vibrans63e62b02011-02-14 18:38:14 +0000119 reg |= (1 << 0);
120 break;
121 case 0x3f0: /* FD0 */
122 reg |= (1 << 26);
123 break;
Martin Roth3c3a50c2014-12-16 20:50:26 -0700124 case 0x220: /* Audio 0 */
Frank Vibrans63e62b02011-02-14 18:38:14 +0000125 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) {
Jacob Garbera9bf88b2019-06-25 12:46:35 -0600173 case 3:
Frank Vibrans63e62b02011-02-14 18:38:14 +0000174 pci_write_config16(dev, 0x90, reg_var[2]);
Jacob Garber4c33a3a2019-07-12 10:34:06 -0600175 /* fall through */
Jacob Garbera9bf88b2019-06-25 12:46:35 -0600176 case 2:
Frank Vibrans63e62b02011-02-14 18:38:14 +0000177 pci_write_config16(dev, 0x66, reg_var[1]);
Jacob Garber4c33a3a2019-07-12 10:34:06 -0600178 /* fall through */
Jacob Garbera9bf88b2019-06-25 12:46:35 -0600179 case 1:
Frank Vibrans63e62b02011-02-14 18:38:14 +0000180 //pci_write_config16(dev, 0x64, reg_var[0]); //cause filo can not find sata
181 break;
182 }
Kerry Shefeed3292011-08-18 18:03:44 +0800183 printk(BIOS_DEBUG, "SB800 - Lpc.c - lpc_enable_childrens_resources - End.\n");
Frank Vibrans63e62b02011-02-14 18:38:14 +0000184}