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 = (uint8_t *) 0xffffffe0;
101 old = pci_read_config8(dev, 0x6d);
104 pci_write_config8(dev, 0x6d, new);
107 static void enable_hpet(struct device *dev)
109 unsigned long hpet_address;
111 pci_write_config32(dev, 0x44, 0xfed00001);
112 hpet_address = pci_read_config32(dev, 0x44) & 0xfffffffe;
113 printk(BIOS_DEBUG, "Enabling HPET @0x%lx\n", hpet_address);
118 static void lpc_init(device_t dev)
120 uint8_t byte, byte_old;
123 lpc_common_init(dev);
125 pm_base = pci_read_config32(dev, 0x60) & 0xff00;
126 printk(BIOS_INFO, "%s: pm_base = %x \n", __func__, pm_base);
128 #if CK804_CHIP_REV==1
129 if (dev->bus->secondary != 1)
134 /* Posted memory write enable */
135 byte = pci_read_config8(dev, 0x46);
136 pci_write_config8(dev, 0x46, byte | (1 << 0));
139 /* power after power fail */
140 on = CONFIG_MAINBOARD_POWER_ON_AFTER_POWER_FAIL;
141 get_option(&on, "power_on_after_fail");
142 byte = pci_read_config8(dev, PREVIOUS_POWER_STATE);
146 pci_write_config8(dev, PREVIOUS_POWER_STATE, byte);
147 printk(BIOS_INFO, "set power %s after power fail\n", on ? "on" : "off");
149 /* Throttle the CPU speed down for testing. */
151 get_option(&on, "slow_cpu");
155 pm10_bar = (pci_read_config16(dev, 0x60) & 0xff00);
156 outl(((on << 1) + 0x10), (pm10_bar + 0x10));
157 dword = inl(pm10_bar + 0x10);
159 printk(BIOS_DEBUG, "Throttling CPU %2d.%1.1d percent.\n",
160 (on * 12) + (on >> 1), (on & 1) * 5);
163 // default is enabled
164 /* Enable Port 92 fast reset. */
165 byte = pci_read_config8(dev, 0xe8);
167 pci_write_config8(dev, 0xe8, byte);
170 /* Enable Error reporting. */
171 /* Set up sync flood detected. */
172 byte = pci_read_config8(dev, 0x47);
174 pci_write_config8(dev, 0x47, byte);
176 /* Set up NMI on errors. */
177 byte = inb(0x70); /* RTC70 */
179 nmi_option = NMI_OFF;
180 get_option(&nmi_option, "nmi");
182 byte &= ~(1 << 7); /* Set NMI. */
184 byte |= (1 << 7); /* Can't mask NMI from PCI-E and NMI_NOW. */
186 if (byte != byte_old)
189 /* Initialize the real time clock (RTC). */
192 /* Initialize ISA DMA. */
195 /* Initialize the High Precision Event Timers (HPET). */
198 rom_dummy_write(dev);
201 static void ck804_lpc_read_resources(device_t dev)
203 struct resource *res;
206 /* Get the normal PCI resources of this device. */
207 /* We got one for APIC, or one more for TRAP. */
208 pci_dev_read_resources(dev);
210 /* Get resource for ACPI, SYSTEM_CONTROL, ANALOG_CONTROL. */
211 for (index = 0x60; index <= 0x68; index += 4) /* We got another 3. */
212 pci_get_resource(dev, index);
213 compact_resources(dev);
215 /* Add an extra subtractive resource for both memory and I/O. */
216 res = new_resource(dev, IOINDEX_SUBTRACTIVE(0, 0));
219 res->flags = IORESOURCE_IO | IORESOURCE_SUBTRACTIVE |
220 IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
222 res = new_resource(dev, IOINDEX_SUBTRACTIVE(1, 0));
223 res->base = 0xff800000;
224 res->size = 0x00800000; /* 8 MB for flash */
225 res->flags = IORESOURCE_MEM | IORESOURCE_SUBTRACTIVE |
226 IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
228 res = new_resource(dev, 3); /* IOAPIC */
229 res->base = IO_APIC_ADDR;
230 res->size = 0x00001000;
231 res->flags = IORESOURCE_MEM | IORESOURCE_ASSIGNED | IORESOURCE_FIXED;
235 * Enable resources for children devices.
237 * This function is called by the global enable_resources() indirectly via the
238 * device_operation::enable_resources() method of devices.
241 static void ck804_lpc_enable_childrens_resources(device_t dev)
244 uint32_t reg, reg_var[4];
247 reg = pci_read_config32(dev, 0xa0);
249 for (link = dev->link_list; link; link = link->next) {
251 for (child = link->children; child; child = child->sibling) {
252 if (child->enabled && (child->path.type == DEVICE_PATH_PNP)) {
253 struct resource *res;
254 for (res = child->resource_list; res; res = res->next) {
255 unsigned long base, end; // don't need long long
256 if (!(res->flags & IORESOURCE_IO))
259 end = resource_end(res);
260 printk(BIOS_DEBUG, "ck804 lpc decode:%s, base=0x%08lx, end=0x%08lx\n", dev_path(child), base, end);
268 case 0x378: // Parallel 1
274 case 0x220: // Audio 0
277 case 0x300: // Midi 0
281 if (base == 0x290 || base >= 0x400) {
283 continue; // only 4 var ; compact them ?
284 reg |= (1 << (28 + var_num));
285 reg_var[var_num++] = (base & 0xffff) | ((end & 0xffff) << 16);
291 pci_write_config32(dev, 0xa0, reg);
292 for (i = 0; i < var_num; i++)
293 pci_write_config32(dev, 0xa8 + i * 4, reg_var[i]);
296 static void ck804_lpc_enable_resources(device_t dev)
298 pci_dev_enable_resources(dev);
299 ck804_lpc_enable_childrens_resources(dev);
302 static struct device_operations lpc_ops = {
303 .read_resources = ck804_lpc_read_resources,
304 .set_resources = pci_dev_set_resources,
305 .enable_resources = ck804_lpc_enable_resources,
307 .scan_bus = scan_static_bus,
308 // .enable = ck804_enable,
309 .ops_pci = &ck804_pci_ops,
312 static const struct pci_driver lpc_driver __pci_driver = {
314 .vendor = PCI_VENDOR_ID_NVIDIA,
315 .device = PCI_DEVICE_ID_NVIDIA_CK804_LPC,
318 static const struct pci_driver lpc_driver_pro __pci_driver = {
320 .vendor = PCI_VENDOR_ID_NVIDIA,
321 .device = PCI_DEVICE_ID_NVIDIA_CK804_PRO,
324 #if CK804_CHIP_REV == 1
325 static const struct pci_driver lpc_driver_slave __pci_driver = {
327 .vendor = PCI_VENDOR_ID_NVIDIA,
328 .device = PCI_DEVICE_ID_NVIDIA_CK804_SLAVE,
331 static struct device_operations lpc_slave_ops = {
332 .read_resources = ck804_lpc_read_resources,
333 .set_resources = pci_dev_set_resources,
334 .enable_resources = pci_dev_enable_resources,
335 .init = lpc_slave_init,
336 // .enable = ck804_enable,
337 .ops_pci = &ck804_pci_ops,
340 static const struct pci_driver lpc_driver_slave __pci_driver = {
341 .ops = &lpc_slave_ops,
342 .vendor = PCI_VENDOR_ID_NVIDIA,
343 .device = PCI_DEVICE_ID_NVIDIA_CK804_SLAVE,