arch import user (historical) | 98d0d30 | 2005-07-06 17:13:46 +0000 | [diff] [blame] | 1 | /* |
Uwe Hermann | 8af6d55 | 2010-10-17 19:13:18 +0000 | [diff] [blame] | 2 | * This file is part of the coreboot project. |
| 3 | * |
Timothy Pearson | 40ce5d9 | 2015-01-23 20:18:19 -0600 | [diff] [blame] | 4 | * Copyright (C) 2015 Timothy Pearson <tpearson@raptorengineeringinc.com>, Raptor Engineering |
Uwe Hermann | 8af6d55 | 2010-10-17 19:13:18 +0000 | [diff] [blame] | 5 | * Copyright (C) 2003 Linux Networx |
| 6 | * Copyright (C) 2003 SuSE Linux AG |
| 7 | * Copyright (C) 2004 Tyan Computer |
| 8 | * Written by Yinghai Lu <yhlu@tyan.com> for Tyan Computer. |
| 9 | * |
| 10 | * This program is free software; you can redistribute it and/or modify |
| 11 | * it under the terms of the GNU General Public License as published by |
| 12 | * the Free Software Foundation; version 2 of the License. |
| 13 | * |
| 14 | * This program is distributed in the hope that it will be useful, |
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | * GNU General Public License for more details. |
arch import user (historical) | 98d0d30 | 2005-07-06 17:13:46 +0000 | [diff] [blame] | 18 | */ |
Uwe Hermann | 7f3d48c | 2008-10-02 18:19:17 +0000 | [diff] [blame] | 19 | |
arch import user (historical) | 98d0d30 | 2005-07-06 17:13:46 +0000 | [diff] [blame] | 20 | #include <console/console.h> |
| 21 | #include <device/device.h> |
| 22 | #include <device/pci.h> |
| 23 | #include <device/pnp.h> |
| 24 | #include <device/pci_ids.h> |
| 25 | #include <device/pci_ops.h> |
| 26 | #include <pc80/mc146818rtc.h> |
| 27 | #include <pc80/isa-dma.h> |
arch import user (historical) | 98d0d30 | 2005-07-06 17:13:46 +0000 | [diff] [blame] | 28 | #include <arch/io.h> |
Stefan Reinauer | 0401bd8 | 2010-01-16 18:31:34 +0000 | [diff] [blame] | 29 | #include <arch/ioapic.h> |
Vladimir Serbinenko | 6985d4e | 2014-09-21 14:31:19 +0200 | [diff] [blame] | 30 | #include <arch/acpi.h> |
Yinghai Lu | b8170f7 | 2006-01-06 01:55:42 +0000 | [diff] [blame] | 31 | #include <cpu/x86/lapic.h> |
Carl-Daniel Hailfinger | 2ee6779 | 2008-10-01 12:52:52 +0000 | [diff] [blame] | 32 | #include <stdlib.h> |
Jonathan A. Kollasch | 948dede | 2013-10-11 15:52:30 -0500 | [diff] [blame] | 33 | #include <assert.h> |
Timothy Pearson | 7f3ae39 | 2015-01-27 01:44:37 -0600 | [diff] [blame] | 34 | #include <cpu/amd/powernow.h> |
Kyösti Mälkki | 413e3da | 2015-02-03 08:05:55 +0200 | [diff] [blame] | 35 | #include "chip.h" |
arch import user (historical) | 98d0d30 | 2005-07-06 17:13:46 +0000 | [diff] [blame] | 36 | |
arch import user (historical) | 98d0d30 | 2005-07-06 17:13:46 +0000 | [diff] [blame] | 37 | #define NMI_OFF 0 |
| 38 | |
Timothy Pearson | 40ce5d9 | 2015-01-23 20:18:19 -0600 | [diff] [blame] | 39 | // Power restoration control register is at 0x7a |
arch import user (historical) | 98d0d30 | 2005-07-06 17:13:46 +0000 | [diff] [blame] | 40 | #define PREVIOUS_POWER_STATE 0x7A |
| 41 | |
Timothy Pearson | 40ce5d9 | 2015-01-23 20:18:19 -0600 | [diff] [blame] | 42 | // Auxiliary power control register possibly located at 0xe3 |
| 43 | #define PREVIOUS_POWER_STATE_AUX 0xe3 |
| 44 | |
arch import user (historical) | 98d0d30 | 2005-07-06 17:13:46 +0000 | [diff] [blame] | 45 | #define MAINBOARD_POWER_OFF 0 |
| 46 | #define MAINBOARD_POWER_ON 1 |
| 47 | #define SLOW_CPU_OFF 0 |
| 48 | #define SLOW_CPU__ON 1 |
| 49 | |
Elyes HAOUAS | 1cbe19f | 2018-05-19 10:57:04 +0200 | [diff] [blame] | 50 | static void lpc_common_init(struct device *dev) |
arch import user (historical) | 98d0d30 | 2005-07-06 17:13:46 +0000 | [diff] [blame] | 51 | { |
Uwe Hermann | 7e2fbd5 | 2011-01-04 17:36:55 +0000 | [diff] [blame] | 52 | u32 dword; |
Jonathan A. Kollasch | 948dede | 2013-10-11 15:52:30 -0500 | [diff] [blame] | 53 | struct resource *res; |
Myles Watson | 64caf36 | 2008-09-18 16:27:00 +0000 | [diff] [blame] | 54 | |
Uwe Hermann | 7e2fbd5 | 2011-01-04 17:36:55 +0000 | [diff] [blame] | 55 | /* I/O APIC initialization. */ |
Jonathan A. Kollasch | 948dede | 2013-10-11 15:52:30 -0500 | [diff] [blame] | 56 | res = find_resource(dev, PCI_BASE_ADDRESS_1); /* IOAPIC */ |
| 57 | ASSERT(res != NULL); |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 58 | setup_ioapic(res2mmio(res, 0, 0), 0); /* Don't rename IOAPIC ID. */ |
Myles Watson | 64caf36 | 2008-09-18 16:27:00 +0000 | [diff] [blame] | 59 | |
arch import user (historical) | 98d0d30 | 2005-07-06 17:13:46 +0000 | [diff] [blame] | 60 | #if 1 |
Myles Watson | 64caf36 | 2008-09-18 16:27:00 +0000 | [diff] [blame] | 61 | dword = pci_read_config32(dev, 0xe4); |
Uwe Hermann | 7f3d48c | 2008-10-02 18:19:17 +0000 | [diff] [blame] | 62 | dword |= (1 << 23); |
Myles Watson | 64caf36 | 2008-09-18 16:27:00 +0000 | [diff] [blame] | 63 | pci_write_config32(dev, 0xe4, dword); |
| 64 | #endif |
arch import user (historical) | 98d0d30 | 2005-07-06 17:13:46 +0000 | [diff] [blame] | 65 | } |
| 66 | |
Elyes HAOUAS | 1cbe19f | 2018-05-19 10:57:04 +0200 | [diff] [blame] | 67 | static void lpc_slave_init(struct device *dev) |
arch import user (historical) | 98d0d30 | 2005-07-06 17:13:46 +0000 | [diff] [blame] | 68 | { |
| 69 | lpc_common_init(dev); |
| 70 | } |
| 71 | |
Elyes HAOUAS | 1cbe19f | 2018-05-19 10:57:04 +0200 | [diff] [blame] | 72 | static void rom_dummy_write(struct device *dev) |
Uwe Hermann | 7f3d48c | 2008-10-02 18:19:17 +0000 | [diff] [blame] | 73 | { |
Uwe Hermann | 7e2fbd5 | 2011-01-04 17:36:55 +0000 | [diff] [blame] | 74 | u8 old, new; |
| 75 | u8 *p; |
Myles Watson | 64caf36 | 2008-09-18 16:27:00 +0000 | [diff] [blame] | 76 | |
| 77 | old = pci_read_config8(dev, 0x88); |
| 78 | new = old | 0xc0; |
Uwe Hermann | 7f3d48c | 2008-10-02 18:19:17 +0000 | [diff] [blame] | 79 | if (new != old) |
Myles Watson | 64caf36 | 2008-09-18 16:27:00 +0000 | [diff] [blame] | 80 | pci_write_config8(dev, 0x88, new); |
Uwe Hermann | 7f3d48c | 2008-10-02 18:19:17 +0000 | [diff] [blame] | 81 | /* Enable write. */ |
Myles Watson | 64caf36 | 2008-09-18 16:27:00 +0000 | [diff] [blame] | 82 | old = pci_read_config8(dev, 0x6d); |
| 83 | new = old | 0x01; |
Uwe Hermann | 7f3d48c | 2008-10-02 18:19:17 +0000 | [diff] [blame] | 84 | if (new != old) |
Myles Watson | 64caf36 | 2008-09-18 16:27:00 +0000 | [diff] [blame] | 85 | pci_write_config8(dev, 0x6d, new); |
arch import user (historical) | 98d0d30 | 2005-07-06 17:13:46 +0000 | [diff] [blame] | 86 | |
Uwe Hermann | 7f3d48c | 2008-10-02 18:19:17 +0000 | [diff] [blame] | 87 | /* Dummy write. */ |
Uwe Hermann | 7e2fbd5 | 2011-01-04 17:36:55 +0000 | [diff] [blame] | 88 | p = (u8 *) 0xffffffe0; |
arch import user (historical) | 98d0d30 | 2005-07-06 17:13:46 +0000 | [diff] [blame] | 89 | old = 0; |
| 90 | *p = old; |
| 91 | old = *p; |
| 92 | |
Uwe Hermann | 7f3d48c | 2008-10-02 18:19:17 +0000 | [diff] [blame] | 93 | /* Disable write. */ |
Myles Watson | 64caf36 | 2008-09-18 16:27:00 +0000 | [diff] [blame] | 94 | old = pci_read_config8(dev, 0x6d); |
| 95 | new = old & 0xfe; |
Uwe Hermann | 7f3d48c | 2008-10-02 18:19:17 +0000 | [diff] [blame] | 96 | if (new != old) |
Myles Watson | 64caf36 | 2008-09-18 16:27:00 +0000 | [diff] [blame] | 97 | pci_write_config8(dev, 0x6d, new); |
arch import user (historical) | 98d0d30 | 2005-07-06 17:13:46 +0000 | [diff] [blame] | 98 | } |
Uwe Hermann | 7f3d48c | 2008-10-02 18:19:17 +0000 | [diff] [blame] | 99 | |
Uwe Hermann | 7e2fbd5 | 2011-01-04 17:36:55 +0000 | [diff] [blame] | 100 | unsigned pm_base = 0; |
arch import user (historical) | 98d0d30 | 2005-07-06 17:13:46 +0000 | [diff] [blame] | 101 | |
Elyes HAOUAS | 1cbe19f | 2018-05-19 10:57:04 +0200 | [diff] [blame] | 102 | static void lpc_init(struct device *dev) |
arch import user (historical) | 98d0d30 | 2005-07-06 17:13:46 +0000 | [diff] [blame] | 103 | { |
Uwe Hermann | 7e2fbd5 | 2011-01-04 17:36:55 +0000 | [diff] [blame] | 104 | u8 byte, byte_old; |
Luc Verhaegen | a9c5ea0 | 2009-06-03 14:19:33 +0000 | [diff] [blame] | 105 | int on, nmi_option; |
arch import user (historical) | 98d0d30 | 2005-07-06 17:13:46 +0000 | [diff] [blame] | 106 | |
| 107 | lpc_common_init(dev); |
| 108 | |
Myles Watson | 283a494 | 2009-03-10 20:39:27 +0000 | [diff] [blame] | 109 | pm_base = pci_read_config32(dev, 0x60) & 0xff00; |
Elyes HAOUAS | 7f9df96 | 2016-08-21 12:06:54 +0200 | [diff] [blame] | 110 | printk(BIOS_INFO, "%s: pm_base = %x\n", __func__, pm_base); |
Myles Watson | 283a494 | 2009-03-10 20:39:27 +0000 | [diff] [blame] | 111 | |
Uwe Hermann | 7e2fbd5 | 2011-01-04 17:36:55 +0000 | [diff] [blame] | 112 | /* Power after power fail */ |
Nico Huber | 9faae2b | 2018-11-14 00:00:35 +0100 | [diff] [blame] | 113 | on = CONFIG_MAINBOARD_POWER_FAILURE_STATE; |
Luc Verhaegen | a9c5ea0 | 2009-06-03 14:19:33 +0000 | [diff] [blame] | 114 | get_option(&on, "power_on_after_fail"); |
Myles Watson | 64caf36 | 2008-09-18 16:27:00 +0000 | [diff] [blame] | 115 | byte = pci_read_config8(dev, PREVIOUS_POWER_STATE); |
Timothy Pearson | 40ce5d9 | 2015-01-23 20:18:19 -0600 | [diff] [blame] | 116 | byte &= ~0x45; |
Uwe Hermann | 7f3d48c | 2008-10-02 18:19:17 +0000 | [diff] [blame] | 117 | if (!on) |
Timothy Pearson | 40ce5d9 | 2015-01-23 20:18:19 -0600 | [diff] [blame] | 118 | byte |= 0x45; |
Myles Watson | 64caf36 | 2008-09-18 16:27:00 +0000 | [diff] [blame] | 119 | pci_write_config8(dev, PREVIOUS_POWER_STATE, byte); |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 120 | printk(BIOS_INFO, "set power %s after power fail\n", on ? "on" : "off"); |
arch import user (historical) | 98d0d30 | 2005-07-06 17:13:46 +0000 | [diff] [blame] | 121 | |
Uwe Hermann | 7f3d48c | 2008-10-02 18:19:17 +0000 | [diff] [blame] | 122 | /* Throttle the CPU speed down for testing. */ |
Myles Watson | 64caf36 | 2008-09-18 16:27:00 +0000 | [diff] [blame] | 123 | on = SLOW_CPU_OFF; |
Luc Verhaegen | a9c5ea0 | 2009-06-03 14:19:33 +0000 | [diff] [blame] | 124 | get_option(&on, "slow_cpu"); |
Uwe Hermann | 7f3d48c | 2008-10-02 18:19:17 +0000 | [diff] [blame] | 125 | if (on) { |
Uwe Hermann | 7e2fbd5 | 2011-01-04 17:36:55 +0000 | [diff] [blame] | 126 | u16 pm10_bar; |
| 127 | u32 dword; |
Uwe Hermann | 7f3d48c | 2008-10-02 18:19:17 +0000 | [diff] [blame] | 128 | pm10_bar = (pci_read_config16(dev, 0x60) & 0xff00); |
| 129 | outl(((on << 1) + 0x10), (pm10_bar + 0x10)); |
Myles Watson | 64caf36 | 2008-09-18 16:27:00 +0000 | [diff] [blame] | 130 | dword = inl(pm10_bar + 0x10); |
Uwe Hermann | 7f3d48c | 2008-10-02 18:19:17 +0000 | [diff] [blame] | 131 | on = 8 - on; |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 132 | printk(BIOS_DEBUG, "Throttling CPU %2d.%1.1d percent.\n", |
Uwe Hermann | 7e2fbd5 | 2011-01-04 17:36:55 +0000 | [diff] [blame] | 133 | (on * 12) + (on >> 1), (on & 1) * 5); |
Myles Watson | 64caf36 | 2008-09-18 16:27:00 +0000 | [diff] [blame] | 134 | } |
arch import user (historical) | 98d0d30 | 2005-07-06 17:13:46 +0000 | [diff] [blame] | 135 | |
Uwe Hermann | 7f3d48c | 2008-10-02 18:19:17 +0000 | [diff] [blame] | 136 | /* Set up NMI on errors. */ |
| 137 | byte = inb(0x70); /* RTC70 */ |
arch import user (historical) | 98d0d30 | 2005-07-06 17:13:46 +0000 | [diff] [blame] | 138 | byte_old = byte; |
| 139 | nmi_option = NMI_OFF; |
Luc Verhaegen | a9c5ea0 | 2009-06-03 14:19:33 +0000 | [diff] [blame] | 140 | get_option(&nmi_option, "nmi"); |
Uwe Hermann | 7e2fbd5 | 2011-01-04 17:36:55 +0000 | [diff] [blame] | 141 | if (nmi_option) |
Uwe Hermann | 7f3d48c | 2008-10-02 18:19:17 +0000 | [diff] [blame] | 142 | byte &= ~(1 << 7); /* Set NMI. */ |
Uwe Hermann | 7e2fbd5 | 2011-01-04 17:36:55 +0000 | [diff] [blame] | 143 | else |
Uwe Hermann | 7f3d48c | 2008-10-02 18:19:17 +0000 | [diff] [blame] | 144 | byte |= (1 << 7); /* Can't mask NMI from PCI-E and NMI_NOW. */ |
Uwe Hermann | 7f3d48c | 2008-10-02 18:19:17 +0000 | [diff] [blame] | 145 | if (byte != byte_old) |
Ed Swierk | e42e142 | 2009-07-10 15:05:35 +0000 | [diff] [blame] | 146 | outb(byte, 0x70); |
Myles Watson | 64caf36 | 2008-09-18 16:27:00 +0000 | [diff] [blame] | 147 | |
Uwe Hermann | 7f3d48c | 2008-10-02 18:19:17 +0000 | [diff] [blame] | 148 | /* Initialize the real time clock (RTC). */ |
Gabe Black | b3f08c6 | 2014-04-30 17:12:25 -0700 | [diff] [blame] | 149 | cmos_init(0); |
arch import user (historical) | 98d0d30 | 2005-07-06 17:13:46 +0000 | [diff] [blame] | 150 | |
Uwe Hermann | 7f3d48c | 2008-10-02 18:19:17 +0000 | [diff] [blame] | 151 | /* Initialize ISA DMA. */ |
arch import user (historical) | 98d0d30 | 2005-07-06 17:13:46 +0000 | [diff] [blame] | 152 | isa_dma_init(); |
| 153 | |
arch import user (historical) | 98d0d30 | 2005-07-06 17:13:46 +0000 | [diff] [blame] | 154 | rom_dummy_write(dev); |
arch import user (historical) | 98d0d30 | 2005-07-06 17:13:46 +0000 | [diff] [blame] | 155 | } |
| 156 | |
Elyes HAOUAS | 1cbe19f | 2018-05-19 10:57:04 +0200 | [diff] [blame] | 157 | static void ck804_lpc_read_resources(struct device *dev) |
arch import user (historical) | 98d0d30 | 2005-07-06 17:13:46 +0000 | [diff] [blame] | 158 | { |
| 159 | struct resource *res; |
| 160 | unsigned long index; |
| 161 | |
Uwe Hermann | 7f3d48c | 2008-10-02 18:19:17 +0000 | [diff] [blame] | 162 | /* Get the normal PCI resources of this device. */ |
| 163 | /* We got one for APIC, or one more for TRAP. */ |
| 164 | pci_dev_read_resources(dev); |
arch import user (historical) | 98d0d30 | 2005-07-06 17:13:46 +0000 | [diff] [blame] | 165 | |
Jonathan Kollasch | fadb004 | 2011-03-03 20:52:50 +0000 | [diff] [blame] | 166 | /* HPET */ |
| 167 | pci_get_resource(dev, 0x44); |
| 168 | |
Uwe Hermann | 7f3d48c | 2008-10-02 18:19:17 +0000 | [diff] [blame] | 169 | /* Get resource for ACPI, SYSTEM_CONTROL, ANALOG_CONTROL. */ |
| 170 | for (index = 0x60; index <= 0x68; index += 4) /* We got another 3. */ |
Myles Watson | 64caf36 | 2008-09-18 16:27:00 +0000 | [diff] [blame] | 171 | pci_get_resource(dev, index); |
Myles Watson | 64caf36 | 2008-09-18 16:27:00 +0000 | [diff] [blame] | 172 | compact_resources(dev); |
| 173 | |
Uwe Hermann | 7f3d48c | 2008-10-02 18:19:17 +0000 | [diff] [blame] | 174 | /* Add an extra subtractive resource for both memory and I/O. */ |
Myles Watson | 64caf36 | 2008-09-18 16:27:00 +0000 | [diff] [blame] | 175 | res = new_resource(dev, IOINDEX_SUBTRACTIVE(0, 0)); |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 176 | res->base = 0; |
| 177 | res->size = 0x1000; |
| 178 | res->flags = IORESOURCE_IO | IORESOURCE_SUBTRACTIVE | |
| 179 | IORESOURCE_ASSIGNED | IORESOURCE_FIXED; |
Myles Watson | 64caf36 | 2008-09-18 16:27:00 +0000 | [diff] [blame] | 180 | |
| 181 | res = new_resource(dev, IOINDEX_SUBTRACTIVE(1, 0)); |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 182 | res->base = 0xff800000; |
| 183 | res->size = 0x00800000; /* 8 MB for flash */ |
| 184 | res->flags = IORESOURCE_MEM | IORESOURCE_SUBTRACTIVE | |
| 185 | IORESOURCE_ASSIGNED | IORESOURCE_FIXED; |
| 186 | |
Jonathan Kollasch | fadb004 | 2011-03-03 20:52:50 +0000 | [diff] [blame] | 187 | if (dev->device != PCI_DEVICE_ID_NVIDIA_CK804_SLAVE) { |
Jonathan A. Kollasch | 772d026 | 2013-10-11 16:09:37 -0500 | [diff] [blame] | 188 | res = find_resource(dev, PCI_BASE_ADDRESS_1); /* IOAPIC */ |
Jonathan Kollasch | fadb004 | 2011-03-03 20:52:50 +0000 | [diff] [blame] | 189 | if (res) { |
| 190 | res->base = IO_APIC_ADDR; |
| 191 | res->flags |= IORESOURCE_ASSIGNED | IORESOURCE_FIXED; |
| 192 | } |
| 193 | |
| 194 | res = find_resource(dev, 0x44); /* HPET */ |
| 195 | if (res) { |
Jonathan A. Kollasch | 6f0e8bd | 2015-07-15 13:47:33 -0500 | [diff] [blame] | 196 | res->base = CONFIG_HPET_ADDRESS; |
Jonathan Kollasch | fadb004 | 2011-03-03 20:52:50 +0000 | [diff] [blame] | 197 | res->flags |= IORESOURCE_ASSIGNED | IORESOURCE_FIXED; |
| 198 | } |
| 199 | } |
| 200 | } |
| 201 | |
Elyes HAOUAS | 1cbe19f | 2018-05-19 10:57:04 +0200 | [diff] [blame] | 202 | static void ck804_lpc_set_resources(struct device *dev) |
Jonathan Kollasch | fadb004 | 2011-03-03 20:52:50 +0000 | [diff] [blame] | 203 | { |
Jonathan A. Kollasch | cf18c85 | 2013-10-11 16:14:18 -0500 | [diff] [blame] | 204 | u8 byte; |
Jonathan Kollasch | fadb004 | 2011-03-03 20:52:50 +0000 | [diff] [blame] | 205 | struct resource *res; |
| 206 | |
| 207 | pci_dev_set_resources(dev); |
| 208 | |
| 209 | /* APIC */ |
Jonathan A. Kollasch | 772d026 | 2013-10-11 16:09:37 -0500 | [diff] [blame] | 210 | res = find_resource(dev, PCI_BASE_ADDRESS_1); |
Jonathan Kollasch | fadb004 | 2011-03-03 20:52:50 +0000 | [diff] [blame] | 211 | if (res) { |
Jonathan A. Kollasch | cf18c85 | 2013-10-11 16:14:18 -0500 | [diff] [blame] | 212 | byte = pci_read_config8(dev, 0x74); |
| 213 | byte |= (1 << 1); /* enable access to PCI_BASE_ADDRESS_1 */ |
| 214 | pci_write_config8(dev, 0x74, byte); |
Jonathan A. Kollasch | 772d026 | 2013-10-11 16:09:37 -0500 | [diff] [blame] | 215 | pci_write_config32(dev, PCI_BASE_ADDRESS_1, res->base); |
Jonathan Kollasch | fadb004 | 2011-03-03 20:52:50 +0000 | [diff] [blame] | 216 | res->flags |= IORESOURCE_STORED; |
| 217 | report_resource_stored(dev, res, ""); |
Jonathan A. Kollasch | cf18c85 | 2013-10-11 16:14:18 -0500 | [diff] [blame] | 218 | byte |= (1 << 0); /* enable decode of IOAPIC space */ |
| 219 | byte &= ~(1 << 1); /* hide PCI_BASE_ADDRESS_1 */ |
| 220 | pci_write_config8(dev, 0x74, byte); |
Jonathan Kollasch | fadb004 | 2011-03-03 20:52:50 +0000 | [diff] [blame] | 221 | } |
| 222 | |
| 223 | /* HPET */ |
| 224 | res = find_resource(dev, 0x44); |
| 225 | if (res) { |
| 226 | pci_write_config32(dev, 0x44, res->base|1); |
| 227 | res->flags |= IORESOURCE_STORED; |
| 228 | report_resource_stored(dev, res, ""); |
| 229 | } |
arch import user (historical) | 98d0d30 | 2005-07-06 17:13:46 +0000 | [diff] [blame] | 230 | } |
| 231 | |
Myles Watson | 64caf36 | 2008-09-18 16:27:00 +0000 | [diff] [blame] | 232 | /** |
Uwe Hermann | 7f3d48c | 2008-10-02 18:19:17 +0000 | [diff] [blame] | 233 | * Enable resources for children devices. |
Myles Watson | 64caf36 | 2008-09-18 16:27:00 +0000 | [diff] [blame] | 234 | * |
Uwe Hermann | 7f3d48c | 2008-10-02 18:19:17 +0000 | [diff] [blame] | 235 | * This function is called by the global enable_resources() indirectly via the |
arch import user (historical) | 98d0d30 | 2005-07-06 17:13:46 +0000 | [diff] [blame] | 236 | * device_operation::enable_resources() method of devices. |
Myles Watson | 64caf36 | 2008-09-18 16:27:00 +0000 | [diff] [blame] | 237 | */ |
Elyes HAOUAS | 1cbe19f | 2018-05-19 10:57:04 +0200 | [diff] [blame] | 238 | static void ck804_lpc_enable_childrens_resources(struct device *dev) |
Myles Watson | 64caf36 | 2008-09-18 16:27:00 +0000 | [diff] [blame] | 239 | { |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 240 | struct bus *link; |
Uwe Hermann | 7e2fbd5 | 2011-01-04 17:36:55 +0000 | [diff] [blame] | 241 | u32 reg, reg_var[4]; |
Uwe Hermann | 7f3d48c | 2008-10-02 18:19:17 +0000 | [diff] [blame] | 242 | int i, var_num = 0; |
Myles Watson | 64caf36 | 2008-09-18 16:27:00 +0000 | [diff] [blame] | 243 | |
arch import user (historical) | 98d0d30 | 2005-07-06 17:13:46 +0000 | [diff] [blame] | 244 | reg = pci_read_config32(dev, 0xa0); |
| 245 | |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 246 | for (link = dev->link_list; link; link = link->next) { |
Elyes HAOUAS | 1cbe19f | 2018-05-19 10:57:04 +0200 | [diff] [blame] | 247 | struct device *child; |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 248 | for (child = link->children; child; child = child->sibling) { |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 249 | if (child->enabled && (child->path.type == DEVICE_PATH_PNP)) { |
Myles Watson | c25cc11 | 2010-05-21 14:33:48 +0000 | [diff] [blame] | 250 | struct resource *res; |
| 251 | for (res = child->resource_list; res; res = res->next) { |
Uwe Hermann | 7e2fbd5 | 2011-01-04 17:36:55 +0000 | [diff] [blame] | 252 | unsigned long base, end; /* Don't need long long. */ |
Uwe Hermann | 7f3d48c | 2008-10-02 18:19:17 +0000 | [diff] [blame] | 253 | if (!(res->flags & IORESOURCE_IO)) |
| 254 | continue; |
Myles Watson | 64caf36 | 2008-09-18 16:27:00 +0000 | [diff] [blame] | 255 | base = res->base; |
| 256 | end = resource_end(res); |
Stefan Reinauer | 64ed2b7 | 2010-03-31 14:47:43 +0000 | [diff] [blame] | 257 | printk(BIOS_DEBUG, "ck804 lpc decode:%s, base=0x%08lx, end=0x%08lx\n", dev_path(child), base, end); |
Uwe Hermann | 7f3d48c | 2008-10-02 18:19:17 +0000 | [diff] [blame] | 258 | switch (base) { |
| 259 | case 0x3f8: // COM1 |
| 260 | reg |= (1 << 0); |
| 261 | break; |
| 262 | case 0x2f8: // COM2 |
| 263 | reg |= (1 << 1); |
| 264 | break; |
| 265 | case 0x378: // Parallel 1 |
| 266 | reg |= (1 << 24); |
| 267 | break; |
| 268 | case 0x3f0: // FD0 |
| 269 | reg |= (1 << 20); |
| 270 | break; |
| 271 | case 0x220: // Audio 0 |
| 272 | reg |= (1 << 8); |
| 273 | break; |
| 274 | case 0x300: // Midi 0 |
| 275 | reg |= (1 << 12); |
| 276 | break; |
arch import user (historical) | 98d0d30 | 2005-07-06 17:13:46 +0000 | [diff] [blame] | 277 | } |
Uwe Hermann | 7f3d48c | 2008-10-02 18:19:17 +0000 | [diff] [blame] | 278 | if (base == 0x290 || base >= 0x400) { |
Uwe Hermann | 7e2fbd5 | 2011-01-04 17:36:55 +0000 | [diff] [blame] | 279 | /* Only 4 var; compact them? */ |
Uwe Hermann | 7f3d48c | 2008-10-02 18:19:17 +0000 | [diff] [blame] | 280 | if (var_num >= 4) |
Uwe Hermann | 7e2fbd5 | 2011-01-04 17:36:55 +0000 | [diff] [blame] | 281 | continue; |
Uwe Hermann | 7f3d48c | 2008-10-02 18:19:17 +0000 | [diff] [blame] | 282 | reg |= (1 << (28 + var_num)); |
| 283 | reg_var[var_num++] = (base & 0xffff) | ((end & 0xffff) << 16); |
Myles Watson | 64caf36 | 2008-09-18 16:27:00 +0000 | [diff] [blame] | 284 | } |
arch import user (historical) | 98d0d30 | 2005-07-06 17:13:46 +0000 | [diff] [blame] | 285 | } |
| 286 | } |
Myles Watson | 64caf36 | 2008-09-18 16:27:00 +0000 | [diff] [blame] | 287 | } |
| 288 | } |
arch import user (historical) | 98d0d30 | 2005-07-06 17:13:46 +0000 | [diff] [blame] | 289 | pci_write_config32(dev, 0xa0, reg); |
Uwe Hermann | 7f3d48c | 2008-10-02 18:19:17 +0000 | [diff] [blame] | 290 | for (i = 0; i < var_num; i++) |
| 291 | pci_write_config32(dev, 0xa8 + i * 4, reg_var[i]); |
arch import user (historical) | 98d0d30 | 2005-07-06 17:13:46 +0000 | [diff] [blame] | 292 | } |
| 293 | |
Elyes HAOUAS | 1cbe19f | 2018-05-19 10:57:04 +0200 | [diff] [blame] | 294 | static void ck804_lpc_enable_resources(struct device *dev) |
arch import user (historical) | 98d0d30 | 2005-07-06 17:13:46 +0000 | [diff] [blame] | 295 | { |
Myles Watson | 64caf36 | 2008-09-18 16:27:00 +0000 | [diff] [blame] | 296 | pci_dev_enable_resources(dev); |
| 297 | ck804_lpc_enable_childrens_resources(dev); |
arch import user (historical) | 98d0d30 | 2005-07-06 17:13:46 +0000 | [diff] [blame] | 298 | } |
| 299 | |
Vladimir Serbinenko | 83f81ca | 2014-11-09 13:30:50 +0100 | [diff] [blame] | 300 | #if IS_ENABLED(CONFIG_HAVE_ACPI_TABLES) |
Timothy Pearson | 7f3ae39 | 2015-01-27 01:44:37 -0600 | [diff] [blame] | 301 | |
Elyes HAOUAS | 1cbe19f | 2018-05-19 10:57:04 +0200 | [diff] [blame] | 302 | static void southbridge_acpi_fill_ssdt_generator(struct device *device) |
Timothy Pearson | 7f3ae39 | 2015-01-27 01:44:37 -0600 | [diff] [blame] | 303 | { |
| 304 | amd_generate_powernow(0, 0, 0); |
| 305 | } |
| 306 | |
| 307 | #endif |
| 308 | |
Uwe Hermann | 7f3d48c | 2008-10-02 18:19:17 +0000 | [diff] [blame] | 309 | static struct device_operations lpc_ops = { |
arch import user (historical) | 98d0d30 | 2005-07-06 17:13:46 +0000 | [diff] [blame] | 310 | .read_resources = ck804_lpc_read_resources, |
Jonathan Kollasch | fadb004 | 2011-03-03 20:52:50 +0000 | [diff] [blame] | 311 | .set_resources = ck804_lpc_set_resources, |
arch import user (historical) | 98d0d30 | 2005-07-06 17:13:46 +0000 | [diff] [blame] | 312 | .enable_resources = ck804_lpc_enable_resources, |
Vladimir Serbinenko | f21271e | 2014-10-16 18:00:27 +0200 | [diff] [blame] | 313 | #if IS_ENABLED(CONFIG_HAVE_ACPI_TABLES) |
Timothy Pearson | 7f3ae39 | 2015-01-27 01:44:37 -0600 | [diff] [blame] | 314 | .acpi_fill_ssdt_generator = southbridge_acpi_fill_ssdt_generator, |
Vladimir Serbinenko | 6985d4e | 2014-09-21 14:31:19 +0200 | [diff] [blame] | 315 | .write_acpi_tables = acpi_write_hpet, |
| 316 | #endif |
arch import user (historical) | 98d0d30 | 2005-07-06 17:13:46 +0000 | [diff] [blame] | 317 | .init = lpc_init, |
Kyösti Mälkki | d0e212c | 2015-02-26 20:47:47 +0200 | [diff] [blame] | 318 | .scan_bus = scan_lpc_bus, |
Jonathan Kollasch | c7f3f80 | 2010-10-29 15:56:04 +0000 | [diff] [blame] | 319 | .ops_pci = &ck804_pci_ops, |
arch import user (historical) | 98d0d30 | 2005-07-06 17:13:46 +0000 | [diff] [blame] | 320 | }; |
Uwe Hermann | 7f3d48c | 2008-10-02 18:19:17 +0000 | [diff] [blame] | 321 | |
Stefan Reinauer | f1cf1f7 | 2007-10-24 09:08:58 +0000 | [diff] [blame] | 322 | static const struct pci_driver lpc_driver __pci_driver = { |
arch import user (historical) | 98d0d30 | 2005-07-06 17:13:46 +0000 | [diff] [blame] | 323 | .ops = &lpc_ops, |
| 324 | .vendor = PCI_VENDOR_ID_NVIDIA, |
| 325 | .device = PCI_DEVICE_ID_NVIDIA_CK804_LPC, |
| 326 | }; |
| 327 | |
Stefan Reinauer | f1cf1f7 | 2007-10-24 09:08:58 +0000 | [diff] [blame] | 328 | static const struct pci_driver lpc_driver_pro __pci_driver = { |
Myles Watson | 64caf36 | 2008-09-18 16:27:00 +0000 | [diff] [blame] | 329 | .ops = &lpc_ops, |
| 330 | .vendor = PCI_VENDOR_ID_NVIDIA, |
| 331 | .device = PCI_DEVICE_ID_NVIDIA_CK804_PRO, |
arch import user (historical) | 98d0d30 | 2005-07-06 17:13:46 +0000 | [diff] [blame] | 332 | }; |
| 333 | |
Uwe Hermann | 7f3d48c | 2008-10-02 18:19:17 +0000 | [diff] [blame] | 334 | static struct device_operations lpc_slave_ops = { |
Myles Watson | 64caf36 | 2008-09-18 16:27:00 +0000 | [diff] [blame] | 335 | .read_resources = ck804_lpc_read_resources, |
| 336 | .set_resources = pci_dev_set_resources, |
| 337 | .enable_resources = pci_dev_enable_resources, |
Vladimir Serbinenko | f21271e | 2014-10-16 18:00:27 +0200 | [diff] [blame] | 338 | #if IS_ENABLED(CONFIG_HAVE_ACPI_TABLES) |
Vladimir Serbinenko | 6985d4e | 2014-09-21 14:31:19 +0200 | [diff] [blame] | 339 | .write_acpi_tables = acpi_write_hpet, |
| 340 | #endif |
Myles Watson | 64caf36 | 2008-09-18 16:27:00 +0000 | [diff] [blame] | 341 | .init = lpc_slave_init, |
Jonathan Kollasch | c7f3f80 | 2010-10-29 15:56:04 +0000 | [diff] [blame] | 342 | .ops_pci = &ck804_pci_ops, |
arch import user (historical) | 98d0d30 | 2005-07-06 17:13:46 +0000 | [diff] [blame] | 343 | }; |
| 344 | |
Stefan Reinauer | f1cf1f7 | 2007-10-24 09:08:58 +0000 | [diff] [blame] | 345 | static const struct pci_driver lpc_driver_slave __pci_driver = { |
Myles Watson | 64caf36 | 2008-09-18 16:27:00 +0000 | [diff] [blame] | 346 | .ops = &lpc_slave_ops, |
| 347 | .vendor = PCI_VENDOR_ID_NVIDIA, |
| 348 | .device = PCI_DEVICE_ID_NVIDIA_CK804_SLAVE, |
| 349 | }; |