blob: 40c0739bb10d8d6fdb80488bcb0bed9dcd49503e [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"
zbao9bcdbf82012-04-05 13:18:49 +080022#include <arch/io.h>
23#include <cbmem.h>
Frank Vibrans63e62b02011-02-14 18:38:14 +000024
Elyes HAOUAS1a4abb72018-05-19 16:49:20 +020025void lpc_read_resources(struct device *dev)
Frank Vibrans63e62b02011-02-14 18:38:14 +000026{
27 struct resource *res;
28
Kerry Shefeed3292011-08-18 18:03:44 +080029 printk(BIOS_DEBUG, "SB800 - Lpc.c - lpc_read_resources - Start.\n");
Frank Vibrans63e62b02011-02-14 18:38:14 +000030 /* Get the normal pci resources of this device */
31 pci_dev_read_resources(dev); /* We got one for APIC, or one more for TRAP */
32
Frank Vibrans63e62b02011-02-14 18:38:14 +000033 /* Add an extra subtractive resource for both memory and I/O. */
34 res = new_resource(dev, IOINDEX_SUBTRACTIVE(0, 0));
35 res->base = 0;
36 res->size = 0x1000;
37 res->flags = IORESOURCE_IO | IORESOURCE_SUBTRACTIVE |
38 IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
39
40 res = new_resource(dev, IOINDEX_SUBTRACTIVE(1, 0));
41 res->base = 0xff800000;
42 res->size = 0x00800000; /* 8 MB for flash */
43 res->flags = IORESOURCE_MEM | IORESOURCE_SUBTRACTIVE |
44 IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
45
Dave Frodinac1b8752014-06-05 14:30:22 -060046 /* Add a memory resource for the SPI BAR. */
47 fixed_mem_resource(dev, 2, SPI_BASE_ADDRESS / 1024, 1, IORESOURCE_SUBTRACTIVE);
48
Patrick Georgi2c2e78d2012-02-16 18:54:37 +010049 res = new_resource(dev, 3);
50 res->base = IO_APIC_ADDR;
Frank Vibrans63e62b02011-02-14 18:38:14 +000051 res->size = 0x00001000;
52 res->flags = IORESOURCE_MEM | IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
53
54 compact_resources(dev);
Kerry Shefeed3292011-08-18 18:03:44 +080055 printk(BIOS_DEBUG, "SB800 - Lpc.c - lpc_read_resources - End.\n");
Frank Vibrans63e62b02011-02-14 18:38:14 +000056}
57
58void lpc_set_resources(struct device *dev)
59{
60 struct resource *res;
61
Kerry Shefeed3292011-08-18 18:03:44 +080062 printk(BIOS_DEBUG, "SB800 - Lpc.c - lpc_set_resources - Start.\n");
Martin Roth3aef7b42012-12-05 15:50:32 -070063
64 /* Special case. SPI Base Address. The SpiRomEnable should STAY set. */
Dave Frodinac1b8752014-06-05 14:30:22 -060065 res = find_resource(dev, 2);
66 pci_write_config32(dev, SPIROM_BASE_ADDRESS_REGISTER, res->base | SPI_ROM_ENABLE);
Martin Roth3aef7b42012-12-05 15:50:32 -070067
Frank Vibrans63e62b02011-02-14 18:38:14 +000068 pci_dev_set_resources(dev);
69
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 *
Martin Roth3c3a50c2014-12-16 20:50:26 -070076 * @param dev the device whose children's resources are to be enabled
Frank Vibrans63e62b02011-02-14 18:38:14 +000077 *
78 */
Elyes HAOUAS1a4abb72018-05-19 16:49:20 +020079void lpc_enable_childrens_resources(struct device *dev)
Frank Vibrans63e62b02011-02-14 18:38:14 +000080{
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) {
Elyes HAOUAS1a4abb72018-05-19 16:49:20 +020091 struct device *child;
Frank Vibrans63e62b02011-02-14 18:38:14 +000092 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) {
Paul Menzel621abec2017-09-09 11:26:24 +020098 u32 base; /* don't need long long */
Frank Vibrans63e62b02011-02-14 18:38:14 +000099 if (!(res->flags & IORESOURCE_IO))
100 continue;
101 base = res->base;
Frank Vibrans63e62b02011-02-14 18:38:14 +0000102/*
Paul Menzel482f8222017-09-09 11:05:21 +0200103 printk(BIOS_DEBUG, "sb800 lpc decode:%s,
104 base=0x%08x, end=0x%08x\n",
Paul Menzel621abec2017-09-09 11:26:24 +0200105 dev_path(child), base,
106 resource_end(res));
Frank Vibrans63e62b02011-02-14 18:38:14 +0000107*/
108 switch (base) {
109 case 0x60: /* KB */
110 case 0x64: /* MS */
111 reg |= (1 << 29);
112 break;
113 case 0x3f8: /* COM1 */
114 reg |= (1 << 6);
115 break;
116 case 0x2f8: /* COM2 */
117 reg |= (1 << 7);
118 break;
Martin Roth3c3a50c2014-12-16 20:50:26 -0700119 case 0x378: /* Parallel 1 */
Frank Vibrans63e62b02011-02-14 18:38:14 +0000120 reg |= (1 << 0);
121 break;
122 case 0x3f0: /* FD0 */
123 reg |= (1 << 26);
124 break;
Martin Roth3c3a50c2014-12-16 20:50:26 -0700125 case 0x220: /* Audio 0 */
Frank Vibrans63e62b02011-02-14 18:38:14 +0000126 reg |= (1 << 8);
127 break;
128 case 0x300: /* Midi 0 */
129 reg |= (1 << 18);
130 break;
131 case 0x400:
132 reg_x |= (1 << 16);
133 break;
134 case 0x480:
135 reg_x |= (1 << 17);
136 break;
137 case 0x500:
138 reg_x |= (1 << 18);
139 break;
140 case 0x580:
141 reg_x |= (1 << 19);
142 break;
143 case 0x4700:
144 reg_x |= (1 << 22);
145 break;
146 case 0xfd60:
147 reg_x |= (1 << 23);
148 break;
149 default:
150 if (var_num >= 3)
151 continue; /* only 3 var ; compact them ? */
152 switch (var_num) {
153 case 0:
154 reg_x |= (1 << 2);
155 break;
156 case 1:
157 reg_x |= (1 << 24);
158 break;
159 case 2:
160 reg_x |= (1 << 25);
161 break;
162 }
163 reg_var[var_num++] =
164 base & 0xffff;
165 }
166 }
167 }
168 }
169 }
170 pci_write_config32(dev, 0x44, reg);
171 pci_write_config32(dev, 0x48, reg_x);
172 /* Set WideIO for as many IOs found (fall through is on purpose) */
173 switch (var_num) {
174 case 2:
175 pci_write_config16(dev, 0x90, reg_var[2]);
176 case 1:
177 pci_write_config16(dev, 0x66, reg_var[1]);
178 case 0:
179 //pci_write_config16(dev, 0x64, reg_var[0]); //cause filo can not find sata
180 break;
181 }
Kerry Shefeed3292011-08-18 18:03:44 +0800182 printk(BIOS_DEBUG, "SB800 - Lpc.c - lpc_enable_childrens_resources - End.\n");
Frank Vibrans63e62b02011-02-14 18:38:14 +0000183}