2 * This file is part of the coreboot project.
4 * Copyright (C) 2003 Linux Networx
5 * Copyright (C) 2003 SuSE Linux AG
6 * Copyright (C) 2004 Tyan Computer
7 * Written by Yinghai Lu <yhlu@tyan.com> for Tyan Computer.
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; version 2 of the License.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23 #include <console/console.h>
24 #include <device/device.h>
25 #include <device/pci.h>
26 #include <device/pnp.h>
27 #include <device/pci_ids.h>
28 #include <device/pci_ops.h>
29 #include <pc80/mc146818rtc.h>
30 #include <pc80/isa-dma.h>
33 #include <arch/ioapic.h>
34 #include <cpu/x86/lapic.h>
38 #define CK804_CHIP_REV 2
43 #define PREVIOUS_POWER_STATE 0x7A
45 #define MAINBOARD_POWER_OFF 0
46 #define MAINBOARD_POWER_ON 1
47 #define SLOW_CPU_OFF 0
48 #define SLOW_CPU__ON 1
50 #ifndef CONFIG_MAINBOARD_POWER_ON_AFTER_POWER_FAIL
51 #define CONFIG_MAINBOARD_POWER_ON_AFTER_POWER_FAIL MAINBOARD_POWER_ON
54 static void lpc_common_init(device_t dev)
59 /* I/O APIC initialization. */
60 byte = pci_read_config8(dev, 0x74);
61 byte |= (1 << 0); /* Enable APIC. */
62 pci_write_config8(dev, 0x74, byte);
63 dword = pci_read_config32(dev, PCI_BASE_ADDRESS_1); /* 0x14 */
65 setup_ioapic(dword, 0); /* Don't rename IOAPIC ID. */
68 dword = pci_read_config32(dev, 0xe4);
70 pci_write_config32(dev, 0xe4, dword);
74 static void lpc_slave_init(device_t dev)
79 static void rom_dummy_write(device_t dev)
84 old = pci_read_config8(dev, 0x88);
87 pci_write_config8(dev, 0x88, new);
89 old = pci_read_config8(dev, 0x6d);
92 pci_write_config8(dev, 0x6d, new);
95 p = (u8 *) 0xffffffe0;
101 old = pci_read_config8(dev, 0x6d);
104 pci_write_config8(dev, 0x6d, new);
107 unsigned pm_base = 0;
109 static void lpc_init(device_t dev)
114 lpc_common_init(dev);
116 pm_base = pci_read_config32(dev, 0x60) & 0xff00;
117 printk(BIOS_INFO, "%s: pm_base = %x \n", __func__, pm_base);
119 #if CK804_CHIP_REV == 1
120 if (dev->bus->secondary != 1)
124 /* Power after power fail */
125 on = CONFIG_MAINBOARD_POWER_ON_AFTER_POWER_FAIL;
126 get_option(&on, "power_on_after_fail");
127 byte = pci_read_config8(dev, PREVIOUS_POWER_STATE);
131 pci_write_config8(dev, PREVIOUS_POWER_STATE, byte);
132 printk(BIOS_INFO, "set power %s after power fail\n", on ? "on" : "off");
134 /* Throttle the CPU speed down for testing. */
136 get_option(&on, "slow_cpu");
140 pm10_bar = (pci_read_config16(dev, 0x60) & 0xff00);
141 outl(((on << 1) + 0x10), (pm10_bar + 0x10));
142 dword = inl(pm10_bar + 0x10);
144 printk(BIOS_DEBUG, "Throttling CPU %2d.%1.1d percent.\n",
145 (on * 12) + (on >> 1), (on & 1) * 5);
148 /* Enable Port 92 fast reset (default is enabled). */
149 byte = pci_read_config8(dev, 0xe8);
151 pci_write_config8(dev, 0xe8, byte);
154 /* Set up NMI on errors. */
155 byte = inb(0x70); /* RTC70 */
157 nmi_option = NMI_OFF;
158 get_option(&nmi_option, "nmi");
160 byte &= ~(1 << 7); /* Set NMI. */
162 byte |= (1 << 7); /* Can't mask NMI from PCI-E and NMI_NOW. */
163 if (byte != byte_old)
166 /* Initialize the real time clock (RTC). */
169 /* Initialize ISA DMA. */
172 rom_dummy_write(dev);
175 static void ck804_lpc_read_resources(device_t dev)
177 struct resource *res;
180 /* Get the normal PCI resources of this device. */
181 /* We got one for APIC, or one more for TRAP. */
182 pci_dev_read_resources(dev);
185 pci_get_resource(dev, 0x44);
187 /* Get resource for ACPI, SYSTEM_CONTROL, ANALOG_CONTROL. */
188 for (index = 0x60; index <= 0x68; index += 4) /* We got another 3. */
189 pci_get_resource(dev, index);
190 compact_resources(dev);
192 /* Add an extra subtractive resource for both memory and I/O. */
193 res = new_resource(dev, IOINDEX_SUBTRACTIVE(0, 0));
196 res->flags = IORESOURCE_IO | IORESOURCE_SUBTRACTIVE |
197 IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
199 res = new_resource(dev, IOINDEX_SUBTRACTIVE(1, 0));
200 res->base = 0xff800000;
201 res->size = 0x00800000; /* 8 MB for flash */
202 res->flags = IORESOURCE_MEM | IORESOURCE_SUBTRACTIVE |
203 IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
205 if (dev->device != PCI_DEVICE_ID_NVIDIA_CK804_SLAVE) {
206 res = find_resource(dev, 0x14); /* IOAPIC */
208 res->base = IO_APIC_ADDR;
209 res->flags |= IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
212 res = find_resource(dev, 0x44); /* HPET */
214 res->base = 0xfed00000;
215 res->flags |= IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
220 static void ck804_lpc_set_resources(device_t dev)
222 struct resource *res;
224 pci_dev_set_resources(dev);
227 res = find_resource(dev, 0x14);
229 pci_write_config32(dev, 0x14, res->base);
230 res->flags |= IORESOURCE_STORED;
231 report_resource_stored(dev, res, "");
235 res = find_resource(dev, 0x44);
237 pci_write_config32(dev, 0x44, res->base|1);
238 res->flags |= IORESOURCE_STORED;
239 report_resource_stored(dev, res, "");
244 * Enable resources for children devices.
246 * This function is called by the global enable_resources() indirectly via the
247 * device_operation::enable_resources() method of devices.
249 static void ck804_lpc_enable_childrens_resources(device_t dev)
255 reg = pci_read_config32(dev, 0xa0);
257 for (link = dev->link_list; link; link = link->next) {
259 for (child = link->children; child; child = child->sibling) {
260 if (child->enabled && (child->path.type == DEVICE_PATH_PNP)) {
261 struct resource *res;
262 for (res = child->resource_list; res; res = res->next) {
263 unsigned long base, end; /* Don't need long long. */
264 if (!(res->flags & IORESOURCE_IO))
267 end = resource_end(res);
268 printk(BIOS_DEBUG, "ck804 lpc decode:%s, base=0x%08lx, end=0x%08lx\n", dev_path(child), base, end);
276 case 0x378: // Parallel 1
282 case 0x220: // Audio 0
285 case 0x300: // Midi 0
289 if (base == 0x290 || base >= 0x400) {
290 /* Only 4 var; compact them? */
293 reg |= (1 << (28 + var_num));
294 reg_var[var_num++] = (base & 0xffff) | ((end & 0xffff) << 16);
300 pci_write_config32(dev, 0xa0, reg);
301 for (i = 0; i < var_num; i++)
302 pci_write_config32(dev, 0xa8 + i * 4, reg_var[i]);
305 static void ck804_lpc_enable_resources(device_t dev)
307 pci_dev_enable_resources(dev);
308 ck804_lpc_enable_childrens_resources(dev);
311 static struct device_operations lpc_ops = {
312 .read_resources = ck804_lpc_read_resources,
313 .set_resources = ck804_lpc_set_resources,
314 .enable_resources = ck804_lpc_enable_resources,
316 .scan_bus = scan_static_bus,
317 // .enable = ck804_enable,
318 .ops_pci = &ck804_pci_ops,
321 static const struct pci_driver lpc_driver __pci_driver = {
323 .vendor = PCI_VENDOR_ID_NVIDIA,
324 .device = PCI_DEVICE_ID_NVIDIA_CK804_LPC,
327 static const struct pci_driver lpc_driver_pro __pci_driver = {
329 .vendor = PCI_VENDOR_ID_NVIDIA,
330 .device = PCI_DEVICE_ID_NVIDIA_CK804_PRO,
333 #if CK804_CHIP_REV == 1
334 static const struct pci_driver lpc_driver_slave __pci_driver = {
336 .vendor = PCI_VENDOR_ID_NVIDIA,
337 .device = PCI_DEVICE_ID_NVIDIA_CK804_SLAVE,
340 static struct device_operations lpc_slave_ops = {
341 .read_resources = ck804_lpc_read_resources,
342 .set_resources = pci_dev_set_resources,
343 .enable_resources = pci_dev_enable_resources,
344 .init = lpc_slave_init,
345 // .enable = ck804_enable,
346 .ops_pci = &ck804_pci_ops,
349 static const struct pci_driver lpc_driver_slave __pci_driver = {
350 .ops = &lpc_slave_ops,
351 .vendor = PCI_VENDOR_ID_NVIDIA,
352 .device = PCI_DEVICE_ID_NVIDIA_CK804_SLAVE,