Angel Pons | 182dbde | 2020-04-02 23:49:05 +0200 | [diff] [blame^] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 | /* This file is part of the coreboot project. */ |
Frank Vibrans | 63e62b0 | 2011-02-14 18:38:14 +0000 | [diff] [blame] | 3 | |
Kerry She | feed329 | 2011-08-18 18:03:44 +0800 | [diff] [blame] | 4 | #include <console/console.h> |
Frank Vibrans | 63e62b0 | 2011-02-14 18:38:14 +0000 | [diff] [blame] | 5 | #include <device/pci.h> |
Martin Roth | 3aef7b4 | 2012-12-05 15:50:32 -0700 | [diff] [blame] | 6 | #include <device/pci_def.h> |
Patrick Georgi | 2c2e78d | 2012-02-16 18:54:37 +0100 | [diff] [blame] | 7 | #include <arch/ioapic.h> |
Frank Vibrans | 63e62b0 | 2011-02-14 18:38:14 +0000 | [diff] [blame] | 8 | #include "lpc.h" |
Kyösti Mälkki | f1b58b7 | 2019-03-01 13:43:02 +0200 | [diff] [blame] | 9 | #include <device/pci_ops.h> |
Frank Vibrans | 63e62b0 | 2011-02-14 18:38:14 +0000 | [diff] [blame] | 10 | |
Elyes HAOUAS | 1a4abb7 | 2018-05-19 16:49:20 +0200 | [diff] [blame] | 11 | void lpc_read_resources(struct device *dev) |
Frank Vibrans | 63e62b0 | 2011-02-14 18:38:14 +0000 | [diff] [blame] | 12 | { |
| 13 | struct resource *res; |
| 14 | |
Kerry She | feed329 | 2011-08-18 18:03:44 +0800 | [diff] [blame] | 15 | printk(BIOS_DEBUG, "SB800 - Lpc.c - lpc_read_resources - Start.\n"); |
Frank Vibrans | 63e62b0 | 2011-02-14 18:38:14 +0000 | [diff] [blame] | 16 | /* Get the normal pci resources of this device */ |
| 17 | pci_dev_read_resources(dev); /* We got one for APIC, or one more for TRAP */ |
| 18 | |
Frank Vibrans | 63e62b0 | 2011-02-14 18:38:14 +0000 | [diff] [blame] | 19 | /* Add an extra subtractive resource for both memory and I/O. */ |
| 20 | res = new_resource(dev, IOINDEX_SUBTRACTIVE(0, 0)); |
| 21 | res->base = 0; |
| 22 | res->size = 0x1000; |
| 23 | res->flags = IORESOURCE_IO | IORESOURCE_SUBTRACTIVE | |
| 24 | IORESOURCE_ASSIGNED | IORESOURCE_FIXED; |
| 25 | |
| 26 | res = new_resource(dev, IOINDEX_SUBTRACTIVE(1, 0)); |
| 27 | res->base = 0xff800000; |
| 28 | res->size = 0x00800000; /* 8 MB for flash */ |
| 29 | res->flags = IORESOURCE_MEM | IORESOURCE_SUBTRACTIVE | |
| 30 | IORESOURCE_ASSIGNED | IORESOURCE_FIXED; |
| 31 | |
Dave Frodin | ac1b875 | 2014-06-05 14:30:22 -0600 | [diff] [blame] | 32 | /* Add a memory resource for the SPI BAR. */ |
| 33 | fixed_mem_resource(dev, 2, SPI_BASE_ADDRESS / 1024, 1, IORESOURCE_SUBTRACTIVE); |
| 34 | |
Patrick Georgi | 2c2e78d | 2012-02-16 18:54:37 +0100 | [diff] [blame] | 35 | res = new_resource(dev, 3); |
| 36 | res->base = IO_APIC_ADDR; |
Frank Vibrans | 63e62b0 | 2011-02-14 18:38:14 +0000 | [diff] [blame] | 37 | res->size = 0x00001000; |
| 38 | res->flags = IORESOURCE_MEM | IORESOURCE_ASSIGNED | IORESOURCE_FIXED; |
| 39 | |
| 40 | compact_resources(dev); |
Kerry She | feed329 | 2011-08-18 18:03:44 +0800 | [diff] [blame] | 41 | printk(BIOS_DEBUG, "SB800 - Lpc.c - lpc_read_resources - End.\n"); |
Frank Vibrans | 63e62b0 | 2011-02-14 18:38:14 +0000 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | void lpc_set_resources(struct device *dev) |
| 45 | { |
| 46 | struct resource *res; |
| 47 | |
Kerry She | feed329 | 2011-08-18 18:03:44 +0800 | [diff] [blame] | 48 | printk(BIOS_DEBUG, "SB800 - Lpc.c - lpc_set_resources - Start.\n"); |
Martin Roth | 3aef7b4 | 2012-12-05 15:50:32 -0700 | [diff] [blame] | 49 | |
| 50 | /* Special case. SPI Base Address. The SpiRomEnable should STAY set. */ |
Dave Frodin | ac1b875 | 2014-06-05 14:30:22 -0600 | [diff] [blame] | 51 | res = find_resource(dev, 2); |
| 52 | pci_write_config32(dev, SPIROM_BASE_ADDRESS_REGISTER, res->base | SPI_ROM_ENABLE); |
Martin Roth | 3aef7b4 | 2012-12-05 15:50:32 -0700 | [diff] [blame] | 53 | |
Frank Vibrans | 63e62b0 | 2011-02-14 18:38:14 +0000 | [diff] [blame] | 54 | pci_dev_set_resources(dev); |
| 55 | |
Kerry She | feed329 | 2011-08-18 18:03:44 +0800 | [diff] [blame] | 56 | printk(BIOS_DEBUG, "SB800 - Lpc.c - lpc_set_resources - End.\n"); |
Frank Vibrans | 63e62b0 | 2011-02-14 18:38:14 +0000 | [diff] [blame] | 57 | } |
| 58 | |
| 59 | /** |
| 60 | * @brief Enable resources for children devices |
| 61 | * |
Martin Roth | 3c3a50c | 2014-12-16 20:50:26 -0700 | [diff] [blame] | 62 | * @param dev the device whose children's resources are to be enabled |
Frank Vibrans | 63e62b0 | 2011-02-14 18:38:14 +0000 | [diff] [blame] | 63 | * |
| 64 | */ |
Elyes HAOUAS | 1a4abb7 | 2018-05-19 16:49:20 +0200 | [diff] [blame] | 65 | void lpc_enable_childrens_resources(struct device *dev) |
Frank Vibrans | 63e62b0 | 2011-02-14 18:38:14 +0000 | [diff] [blame] | 66 | { |
| 67 | struct bus *link; |
| 68 | u32 reg, reg_x; |
| 69 | int var_num = 0; |
| 70 | u16 reg_var[3]; |
| 71 | |
Kerry She | feed329 | 2011-08-18 18:03:44 +0800 | [diff] [blame] | 72 | printk(BIOS_DEBUG, "SB800 - Lpc.c - lpc_enable_childrens_resources - Start.\n"); |
Frank Vibrans | 63e62b0 | 2011-02-14 18:38:14 +0000 | [diff] [blame] | 73 | reg = pci_read_config32(dev, 0x44); |
| 74 | reg_x = pci_read_config32(dev, 0x48); |
| 75 | |
| 76 | for (link = dev->link_list; link; link = link->next) { |
Elyes HAOUAS | 1a4abb7 | 2018-05-19 16:49:20 +0200 | [diff] [blame] | 77 | struct device *child; |
Frank Vibrans | 63e62b0 | 2011-02-14 18:38:14 +0000 | [diff] [blame] | 78 | for (child = link->children; child; |
| 79 | child = child->sibling) { |
| 80 | if (child->enabled |
| 81 | && (child->path.type == DEVICE_PATH_PNP)) { |
| 82 | struct resource *res; |
| 83 | for (res = child->resource_list; res; res = res->next) { |
Paul Menzel | 621abec | 2017-09-09 11:26:24 +0200 | [diff] [blame] | 84 | u32 base; /* don't need long long */ |
Frank Vibrans | 63e62b0 | 2011-02-14 18:38:14 +0000 | [diff] [blame] | 85 | if (!(res->flags & IORESOURCE_IO)) |
| 86 | continue; |
| 87 | base = res->base; |
Frank Vibrans | 63e62b0 | 2011-02-14 18:38:14 +0000 | [diff] [blame] | 88 | /* |
Paul Menzel | 482f822 | 2017-09-09 11:05:21 +0200 | [diff] [blame] | 89 | printk(BIOS_DEBUG, "sb800 lpc decode:%s, |
| 90 | base=0x%08x, end=0x%08x\n", |
Paul Menzel | 621abec | 2017-09-09 11:26:24 +0200 | [diff] [blame] | 91 | dev_path(child), base, |
| 92 | resource_end(res)); |
Frank Vibrans | 63e62b0 | 2011-02-14 18:38:14 +0000 | [diff] [blame] | 93 | */ |
| 94 | switch (base) { |
| 95 | case 0x60: /* KB */ |
| 96 | case 0x64: /* MS */ |
| 97 | reg |= (1 << 29); |
| 98 | break; |
| 99 | case 0x3f8: /* COM1 */ |
| 100 | reg |= (1 << 6); |
| 101 | break; |
| 102 | case 0x2f8: /* COM2 */ |
| 103 | reg |= (1 << 7); |
| 104 | break; |
Martin Roth | 3c3a50c | 2014-12-16 20:50:26 -0700 | [diff] [blame] | 105 | case 0x378: /* Parallel 1 */ |
Frank Vibrans | 63e62b0 | 2011-02-14 18:38:14 +0000 | [diff] [blame] | 106 | reg |= (1 << 0); |
| 107 | break; |
| 108 | case 0x3f0: /* FD0 */ |
| 109 | reg |= (1 << 26); |
| 110 | break; |
Martin Roth | 3c3a50c | 2014-12-16 20:50:26 -0700 | [diff] [blame] | 111 | case 0x220: /* Audio 0 */ |
Frank Vibrans | 63e62b0 | 2011-02-14 18:38:14 +0000 | [diff] [blame] | 112 | reg |= (1 << 8); |
| 113 | break; |
| 114 | case 0x300: /* Midi 0 */ |
| 115 | reg |= (1 << 18); |
| 116 | break; |
| 117 | case 0x400: |
| 118 | reg_x |= (1 << 16); |
| 119 | break; |
| 120 | case 0x480: |
| 121 | reg_x |= (1 << 17); |
| 122 | break; |
| 123 | case 0x500: |
| 124 | reg_x |= (1 << 18); |
| 125 | break; |
| 126 | case 0x580: |
| 127 | reg_x |= (1 << 19); |
| 128 | break; |
| 129 | case 0x4700: |
| 130 | reg_x |= (1 << 22); |
| 131 | break; |
| 132 | case 0xfd60: |
| 133 | reg_x |= (1 << 23); |
| 134 | break; |
| 135 | default: |
| 136 | if (var_num >= 3) |
| 137 | continue; /* only 3 var ; compact them ? */ |
| 138 | switch (var_num) { |
| 139 | case 0: |
| 140 | reg_x |= (1 << 2); |
| 141 | break; |
| 142 | case 1: |
| 143 | reg_x |= (1 << 24); |
| 144 | break; |
| 145 | case 2: |
| 146 | reg_x |= (1 << 25); |
| 147 | break; |
| 148 | } |
| 149 | reg_var[var_num++] = |
| 150 | base & 0xffff; |
| 151 | } |
| 152 | } |
| 153 | } |
| 154 | } |
| 155 | } |
| 156 | pci_write_config32(dev, 0x44, reg); |
| 157 | pci_write_config32(dev, 0x48, reg_x); |
| 158 | /* Set WideIO for as many IOs found (fall through is on purpose) */ |
| 159 | switch (var_num) { |
Jacob Garber | a9bf88b | 2019-06-25 12:46:35 -0600 | [diff] [blame] | 160 | case 3: |
Frank Vibrans | 63e62b0 | 2011-02-14 18:38:14 +0000 | [diff] [blame] | 161 | pci_write_config16(dev, 0x90, reg_var[2]); |
Jacob Garber | 4c33a3a | 2019-07-12 10:34:06 -0600 | [diff] [blame] | 162 | /* fall through */ |
Jacob Garber | a9bf88b | 2019-06-25 12:46:35 -0600 | [diff] [blame] | 163 | case 2: |
Frank Vibrans | 63e62b0 | 2011-02-14 18:38:14 +0000 | [diff] [blame] | 164 | pci_write_config16(dev, 0x66, reg_var[1]); |
Jacob Garber | 4c33a3a | 2019-07-12 10:34:06 -0600 | [diff] [blame] | 165 | /* fall through */ |
Jacob Garber | a9bf88b | 2019-06-25 12:46:35 -0600 | [diff] [blame] | 166 | case 1: |
Frank Vibrans | 63e62b0 | 2011-02-14 18:38:14 +0000 | [diff] [blame] | 167 | //pci_write_config16(dev, 0x64, reg_var[0]); //cause filo can not find sata |
| 168 | break; |
| 169 | } |
Kerry She | feed329 | 2011-08-18 18:03:44 +0800 | [diff] [blame] | 170 | printk(BIOS_DEBUG, "SB800 - Lpc.c - lpc_enable_childrens_resources - End.\n"); |
Frank Vibrans | 63e62b0 | 2011-02-14 18:38:14 +0000 | [diff] [blame] | 171 | } |