Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Simon Glass | dcfac35 | 2014-11-12 22:42:15 -0700 | [diff] [blame] | 2 | /* |
| 3 | * From coreboot southbridge/intel/bd82x6x/lpc.c |
| 4 | * |
| 5 | * Copyright (C) 2008-2009 coresystems GmbH |
Simon Glass | dcfac35 | 2014-11-12 22:42:15 -0700 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include <common.h> |
Simon Glass | e0e7b36 | 2015-03-05 12:25:33 -0700 | [diff] [blame] | 9 | #include <dm.h> |
Simon Glass | dcfac35 | 2014-11-12 22:42:15 -0700 | [diff] [blame] | 10 | #include <errno.h> |
| 11 | #include <fdtdec.h> |
Simon Glass | 06409c9 | 2014-11-14 18:18:35 -0700 | [diff] [blame] | 12 | #include <rtc.h> |
Simon Glass | dcfac35 | 2014-11-12 22:42:15 -0700 | [diff] [blame] | 13 | #include <pci.h> |
Simon Glass | ab39d33 | 2016-03-11 22:06:56 -0700 | [diff] [blame] | 14 | #include <asm/intel_regs.h> |
Simon Glass | 06409c9 | 2014-11-14 18:18:35 -0700 | [diff] [blame] | 15 | #include <asm/interrupt.h> |
| 16 | #include <asm/io.h> |
| 17 | #include <asm/ioapic.h> |
Simon Glass | 63e08a2 | 2016-03-11 22:06:57 -0700 | [diff] [blame] | 18 | #include <asm/lpc_common.h> |
Simon Glass | dcfac35 | 2014-11-12 22:42:15 -0700 | [diff] [blame] | 19 | #include <asm/pci.h> |
| 20 | #include <asm/arch/pch.h> |
| 21 | |
Simon Glass | d87b092 | 2017-01-16 07:03:37 -0700 | [diff] [blame] | 22 | DECLARE_GLOBAL_DATA_PTR; |
| 23 | |
Simon Glass | 06409c9 | 2014-11-14 18:18:35 -0700 | [diff] [blame] | 24 | #define NMI_OFF 0 |
| 25 | |
| 26 | #define ENABLE_ACPI_MODE_IN_COREBOOT 0 |
| 27 | #define TEST_SMM_FLASH_LOCKDOWN 0 |
| 28 | |
Simon Glass | d6fe74e | 2016-01-17 16:11:42 -0700 | [diff] [blame] | 29 | static int pch_enable_apic(struct udevice *pch) |
Simon Glass | 06409c9 | 2014-11-14 18:18:35 -0700 | [diff] [blame] | 30 | { |
| 31 | u32 reg32; |
| 32 | int i; |
| 33 | |
| 34 | /* Enable ACPI I/O and power management. Set SCI IRQ to IRQ9 */ |
Simon Glass | d6fe74e | 2016-01-17 16:11:42 -0700 | [diff] [blame] | 35 | dm_pci_write_config8(pch, ACPI_CNTL, 0x80); |
Simon Glass | 06409c9 | 2014-11-14 18:18:35 -0700 | [diff] [blame] | 36 | |
| 37 | writel(0, IO_APIC_INDEX); |
| 38 | writel(1 << 25, IO_APIC_DATA); |
| 39 | |
| 40 | /* affirm full set of redirection table entries ("write once") */ |
| 41 | writel(1, IO_APIC_INDEX); |
| 42 | reg32 = readl(IO_APIC_DATA); |
| 43 | writel(1, IO_APIC_INDEX); |
| 44 | writel(reg32, IO_APIC_DATA); |
| 45 | |
| 46 | writel(0, IO_APIC_INDEX); |
| 47 | reg32 = readl(IO_APIC_DATA); |
| 48 | debug("PCH APIC ID = %x\n", (reg32 >> 24) & 0x0f); |
| 49 | if (reg32 != (1 << 25)) { |
| 50 | printf("APIC Error - cannot write to registers\n"); |
| 51 | return -EPERM; |
| 52 | } |
| 53 | |
| 54 | debug("Dumping IOAPIC registers\n"); |
| 55 | for (i = 0; i < 3; i++) { |
| 56 | writel(i, IO_APIC_INDEX); |
| 57 | debug(" reg 0x%04x:", i); |
| 58 | reg32 = readl(IO_APIC_DATA); |
| 59 | debug(" 0x%08x\n", reg32); |
| 60 | } |
| 61 | |
| 62 | /* Select Boot Configuration register. */ |
| 63 | writel(3, IO_APIC_INDEX); |
| 64 | |
| 65 | /* Use Processor System Bus to deliver interrupts. */ |
| 66 | writel(1, IO_APIC_DATA); |
| 67 | |
| 68 | return 0; |
| 69 | } |
| 70 | |
Simon Glass | d6fe74e | 2016-01-17 16:11:42 -0700 | [diff] [blame] | 71 | static void pch_enable_serial_irqs(struct udevice *pch) |
Simon Glass | 06409c9 | 2014-11-14 18:18:35 -0700 | [diff] [blame] | 72 | { |
| 73 | u32 value; |
| 74 | |
| 75 | /* Set packet length and toggle silent mode bit for one frame. */ |
| 76 | value = (1 << 7) | (1 << 6) | ((21 - 17) << 2) | (0 << 0); |
| 77 | #ifdef CONFIG_SERIRQ_CONTINUOUS_MODE |
Simon Glass | d6fe74e | 2016-01-17 16:11:42 -0700 | [diff] [blame] | 78 | dm_pci_write_config8(pch, SERIRQ_CNTL, value); |
Simon Glass | 06409c9 | 2014-11-14 18:18:35 -0700 | [diff] [blame] | 79 | #else |
Simon Glass | d6fe74e | 2016-01-17 16:11:42 -0700 | [diff] [blame] | 80 | dm_pci_write_config8(pch, SERIRQ_CNTL, value | (1 << 6)); |
Simon Glass | 06409c9 | 2014-11-14 18:18:35 -0700 | [diff] [blame] | 81 | #endif |
| 82 | } |
| 83 | |
Simon Glass | d6fe74e | 2016-01-17 16:11:42 -0700 | [diff] [blame] | 84 | static int pch_pirq_init(struct udevice *pch) |
Simon Glass | 06409c9 | 2014-11-14 18:18:35 -0700 | [diff] [blame] | 85 | { |
| 86 | uint8_t route[8], *ptr; |
| 87 | |
Simon Glass | dd79d6e | 2017-01-17 16:52:55 -0700 | [diff] [blame] | 88 | if (fdtdec_get_byte_array(gd->fdt_blob, dev_of_offset(pch), |
Simon Glass | d6fe74e | 2016-01-17 16:11:42 -0700 | [diff] [blame] | 89 | "intel,pirq-routing", route, sizeof(route))) |
Simon Glass | 06409c9 | 2014-11-14 18:18:35 -0700 | [diff] [blame] | 90 | return -EINVAL; |
| 91 | ptr = route; |
Simon Glass | d6fe74e | 2016-01-17 16:11:42 -0700 | [diff] [blame] | 92 | dm_pci_write_config8(pch, PIRQA_ROUT, *ptr++); |
| 93 | dm_pci_write_config8(pch, PIRQB_ROUT, *ptr++); |
| 94 | dm_pci_write_config8(pch, PIRQC_ROUT, *ptr++); |
| 95 | dm_pci_write_config8(pch, PIRQD_ROUT, *ptr++); |
Simon Glass | 06409c9 | 2014-11-14 18:18:35 -0700 | [diff] [blame] | 96 | |
Simon Glass | d6fe74e | 2016-01-17 16:11:42 -0700 | [diff] [blame] | 97 | dm_pci_write_config8(pch, PIRQE_ROUT, *ptr++); |
| 98 | dm_pci_write_config8(pch, PIRQF_ROUT, *ptr++); |
| 99 | dm_pci_write_config8(pch, PIRQG_ROUT, *ptr++); |
| 100 | dm_pci_write_config8(pch, PIRQH_ROUT, *ptr++); |
Simon Glass | 06409c9 | 2014-11-14 18:18:35 -0700 | [diff] [blame] | 101 | |
| 102 | /* |
| 103 | * TODO(sjg@chromium.org): U-Boot does not set up the interrupts |
| 104 | * here. It's unclear if it is needed |
| 105 | */ |
| 106 | return 0; |
| 107 | } |
| 108 | |
Simon Glass | d6fe74e | 2016-01-17 16:11:42 -0700 | [diff] [blame] | 109 | static int pch_gpi_routing(struct udevice *pch) |
Simon Glass | 06409c9 | 2014-11-14 18:18:35 -0700 | [diff] [blame] | 110 | { |
| 111 | u8 route[16]; |
| 112 | u32 reg; |
| 113 | int gpi; |
| 114 | |
Simon Glass | dd79d6e | 2017-01-17 16:52:55 -0700 | [diff] [blame] | 115 | if (fdtdec_get_byte_array(gd->fdt_blob, dev_of_offset(pch), |
Simon Glass | d6fe74e | 2016-01-17 16:11:42 -0700 | [diff] [blame] | 116 | "intel,gpi-routing", route, sizeof(route))) |
Simon Glass | 06409c9 | 2014-11-14 18:18:35 -0700 | [diff] [blame] | 117 | return -EINVAL; |
| 118 | |
| 119 | for (reg = 0, gpi = 0; gpi < ARRAY_SIZE(route); gpi++) |
| 120 | reg |= route[gpi] << (gpi * 2); |
| 121 | |
Simon Glass | d6fe74e | 2016-01-17 16:11:42 -0700 | [diff] [blame] | 122 | dm_pci_write_config32(pch, 0xb8, reg); |
Simon Glass | 06409c9 | 2014-11-14 18:18:35 -0700 | [diff] [blame] | 123 | |
| 124 | return 0; |
| 125 | } |
| 126 | |
Simon Glass | d6fe74e | 2016-01-17 16:11:42 -0700 | [diff] [blame] | 127 | static int pch_power_options(struct udevice *pch) |
Simon Glass | 06409c9 | 2014-11-14 18:18:35 -0700 | [diff] [blame] | 128 | { |
Simon Glass | d6fe74e | 2016-01-17 16:11:42 -0700 | [diff] [blame] | 129 | const void *blob = gd->fdt_blob; |
Simon Glass | dd79d6e | 2017-01-17 16:52:55 -0700 | [diff] [blame] | 130 | int node = dev_of_offset(pch); |
Simon Glass | 06409c9 | 2014-11-14 18:18:35 -0700 | [diff] [blame] | 131 | u8 reg8; |
| 132 | u16 reg16, pmbase; |
| 133 | u32 reg32; |
| 134 | const char *state; |
| 135 | int pwr_on; |
| 136 | int nmi_option; |
| 137 | int ret; |
| 138 | |
| 139 | /* |
| 140 | * Which state do we want to goto after g3 (power restored)? |
| 141 | * 0 == S0 Full On |
| 142 | * 1 == S5 Soft Off |
| 143 | * |
| 144 | * If the option is not existent (Laptops), use Kconfig setting. |
| 145 | * TODO(sjg@chromium.org): Make this configurable |
| 146 | */ |
| 147 | pwr_on = MAINBOARD_POWER_ON; |
| 148 | |
Simon Glass | d6fe74e | 2016-01-17 16:11:42 -0700 | [diff] [blame] | 149 | dm_pci_read_config16(pch, GEN_PMCON_3, ®16); |
Simon Glass | 06409c9 | 2014-11-14 18:18:35 -0700 | [diff] [blame] | 150 | reg16 &= 0xfffe; |
| 151 | switch (pwr_on) { |
| 152 | case MAINBOARD_POWER_OFF: |
| 153 | reg16 |= 1; |
| 154 | state = "off"; |
| 155 | break; |
| 156 | case MAINBOARD_POWER_ON: |
| 157 | reg16 &= ~1; |
| 158 | state = "on"; |
| 159 | break; |
| 160 | case MAINBOARD_POWER_KEEP: |
| 161 | reg16 &= ~1; |
| 162 | state = "state keep"; |
| 163 | break; |
| 164 | default: |
| 165 | state = "undefined"; |
| 166 | } |
| 167 | |
| 168 | reg16 &= ~(3 << 4); /* SLP_S4# Assertion Stretch 4s */ |
| 169 | reg16 |= (1 << 3); /* SLP_S4# Assertion Stretch Enable */ |
| 170 | |
| 171 | reg16 &= ~(1 << 10); |
| 172 | reg16 |= (1 << 11); /* SLP_S3# Min Assertion Width 50ms */ |
| 173 | |
| 174 | reg16 |= (1 << 12); /* Disable SLP stretch after SUS well */ |
| 175 | |
Simon Glass | d6fe74e | 2016-01-17 16:11:42 -0700 | [diff] [blame] | 176 | dm_pci_write_config16(pch, GEN_PMCON_3, reg16); |
Simon Glass | 06409c9 | 2014-11-14 18:18:35 -0700 | [diff] [blame] | 177 | debug("Set power %s after power failure.\n", state); |
| 178 | |
| 179 | /* Set up NMI on errors. */ |
| 180 | reg8 = inb(0x61); |
| 181 | reg8 &= 0x0f; /* Higher Nibble must be 0 */ |
| 182 | reg8 &= ~(1 << 3); /* IOCHK# NMI Enable */ |
| 183 | reg8 |= (1 << 2); /* PCI SERR# Disable for now */ |
| 184 | outb(reg8, 0x61); |
| 185 | |
| 186 | reg8 = inb(0x70); |
| 187 | /* TODO(sjg@chromium.org): Make this configurable */ |
| 188 | nmi_option = NMI_OFF; |
| 189 | if (nmi_option) { |
| 190 | debug("NMI sources enabled.\n"); |
| 191 | reg8 &= ~(1 << 7); /* Set NMI. */ |
| 192 | } else { |
| 193 | debug("NMI sources disabled.\n"); |
| 194 | /* Can't mask NMI from PCI-E and NMI_NOW */ |
| 195 | reg8 |= (1 << 7); |
| 196 | } |
| 197 | outb(reg8, 0x70); |
| 198 | |
| 199 | /* Enable CPU_SLP# and Intel Speedstep, set SMI# rate down */ |
Simon Glass | d6fe74e | 2016-01-17 16:11:42 -0700 | [diff] [blame] | 200 | dm_pci_read_config16(pch, GEN_PMCON_1, ®16); |
Simon Glass | 06409c9 | 2014-11-14 18:18:35 -0700 | [diff] [blame] | 201 | reg16 &= ~(3 << 0); /* SMI# rate 1 minute */ |
| 202 | reg16 &= ~(1 << 10); /* Disable BIOS_PCI_EXP_EN for native PME */ |
| 203 | #if DEBUG_PERIODIC_SMIS |
| 204 | /* Set DEBUG_PERIODIC_SMIS in pch.h to debug using periodic SMIs */ |
| 205 | reg16 |= (3 << 0); /* Periodic SMI every 8s */ |
| 206 | #endif |
Simon Glass | d6fe74e | 2016-01-17 16:11:42 -0700 | [diff] [blame] | 207 | dm_pci_write_config16(pch, GEN_PMCON_1, reg16); |
Simon Glass | 06409c9 | 2014-11-14 18:18:35 -0700 | [diff] [blame] | 208 | |
| 209 | /* Set the board's GPI routing. */ |
Simon Glass | d6fe74e | 2016-01-17 16:11:42 -0700 | [diff] [blame] | 210 | ret = pch_gpi_routing(pch); |
Simon Glass | 06409c9 | 2014-11-14 18:18:35 -0700 | [diff] [blame] | 211 | if (ret) |
| 212 | return ret; |
| 213 | |
Simon Glass | d6fe74e | 2016-01-17 16:11:42 -0700 | [diff] [blame] | 214 | dm_pci_read_config16(pch, 0x40, &pmbase); |
| 215 | pmbase &= 0xfffe; |
Simon Glass | 06409c9 | 2014-11-14 18:18:35 -0700 | [diff] [blame] | 216 | |
Simon Glass | 0a42c02 | 2016-09-25 21:33:34 -0600 | [diff] [blame] | 217 | writel(fdtdec_get_int(blob, node, "intel,gpe0-enable", 0), |
| 218 | (ulong)pmbase + GPE0_EN); |
| 219 | writew(fdtdec_get_int(blob, node, "intel,alt-gp-smi-enable", 0), |
| 220 | (ulong)pmbase + ALT_GP_SMI_EN); |
Simon Glass | 06409c9 | 2014-11-14 18:18:35 -0700 | [diff] [blame] | 221 | |
| 222 | /* Set up power management block and determine sleep mode */ |
| 223 | reg32 = inl(pmbase + 0x04); /* PM1_CNT */ |
| 224 | reg32 &= ~(7 << 10); /* SLP_TYP */ |
| 225 | reg32 |= (1 << 0); /* SCI_EN */ |
| 226 | outl(reg32, pmbase + 0x04); |
| 227 | |
| 228 | /* Clear magic status bits to prevent unexpected wake */ |
| 229 | setbits_le32(RCB_REG(0x3310), (1 << 4) | (1 << 5) | (1 << 0)); |
| 230 | clrbits_le32(RCB_REG(0x3f02), 0xf); |
| 231 | |
| 232 | return 0; |
| 233 | } |
| 234 | |
Simon Glass | d6fe74e | 2016-01-17 16:11:42 -0700 | [diff] [blame] | 235 | static void pch_rtc_init(struct udevice *pch) |
Simon Glass | 06409c9 | 2014-11-14 18:18:35 -0700 | [diff] [blame] | 236 | { |
| 237 | int rtc_failed; |
| 238 | u8 reg8; |
| 239 | |
Simon Glass | d6fe74e | 2016-01-17 16:11:42 -0700 | [diff] [blame] | 240 | dm_pci_read_config8(pch, GEN_PMCON_3, ®8); |
Simon Glass | 06409c9 | 2014-11-14 18:18:35 -0700 | [diff] [blame] | 241 | rtc_failed = reg8 & RTC_BATTERY_DEAD; |
| 242 | if (rtc_failed) { |
| 243 | reg8 &= ~RTC_BATTERY_DEAD; |
Simon Glass | d6fe74e | 2016-01-17 16:11:42 -0700 | [diff] [blame] | 244 | dm_pci_write_config8(pch, GEN_PMCON_3, reg8); |
Simon Glass | 06409c9 | 2014-11-14 18:18:35 -0700 | [diff] [blame] | 245 | } |
| 246 | debug("rtc_failed = 0x%x\n", rtc_failed); |
| 247 | |
Simon Glass | 06409c9 | 2014-11-14 18:18:35 -0700 | [diff] [blame] | 248 | /* TODO: Handle power failure */ |
| 249 | if (rtc_failed) |
| 250 | printf("RTC power failed\n"); |
Simon Glass | 06409c9 | 2014-11-14 18:18:35 -0700 | [diff] [blame] | 251 | } |
| 252 | |
| 253 | /* CougarPoint PCH Power Management init */ |
Simon Glass | d6fe74e | 2016-01-17 16:11:42 -0700 | [diff] [blame] | 254 | static void cpt_pm_init(struct udevice *pch) |
Simon Glass | 06409c9 | 2014-11-14 18:18:35 -0700 | [diff] [blame] | 255 | { |
| 256 | debug("CougarPoint PM init\n"); |
Simon Glass | d6fe74e | 2016-01-17 16:11:42 -0700 | [diff] [blame] | 257 | dm_pci_write_config8(pch, 0xa9, 0x47); |
Simon Glass | 06409c9 | 2014-11-14 18:18:35 -0700 | [diff] [blame] | 258 | setbits_le32(RCB_REG(0x2238), (1 << 6) | (1 << 0)); |
| 259 | |
| 260 | setbits_le32(RCB_REG(0x228c), 1 << 0); |
| 261 | setbits_le32(RCB_REG(0x1100), (1 << 13) | (1 << 14)); |
| 262 | setbits_le32(RCB_REG(0x0900), 1 << 14); |
| 263 | writel(0xc0388400, RCB_REG(0x2304)); |
| 264 | setbits_le32(RCB_REG(0x2314), (1 << 5) | (1 << 18)); |
| 265 | setbits_le32(RCB_REG(0x2320), (1 << 15) | (1 << 1)); |
| 266 | clrsetbits_le32(RCB_REG(0x3314), ~0x1f, 0xf); |
| 267 | writel(0x050f0000, RCB_REG(0x3318)); |
| 268 | writel(0x04000000, RCB_REG(0x3324)); |
| 269 | setbits_le32(RCB_REG(0x3340), 0xfffff); |
| 270 | setbits_le32(RCB_REG(0x3344), 1 << 1); |
| 271 | |
| 272 | writel(0x0001c000, RCB_REG(0x3360)); |
| 273 | writel(0x00061100, RCB_REG(0x3368)); |
| 274 | writel(0x7f8fdfff, RCB_REG(0x3378)); |
| 275 | writel(0x000003fc, RCB_REG(0x337c)); |
| 276 | writel(0x00001000, RCB_REG(0x3388)); |
| 277 | writel(0x0001c000, RCB_REG(0x3390)); |
| 278 | writel(0x00000800, RCB_REG(0x33a0)); |
| 279 | writel(0x00001000, RCB_REG(0x33b0)); |
| 280 | writel(0x00093900, RCB_REG(0x33c0)); |
| 281 | writel(0x24653002, RCB_REG(0x33cc)); |
| 282 | writel(0x062108fe, RCB_REG(0x33d0)); |
| 283 | clrsetbits_le32(RCB_REG(0x33d4), 0x0fff0fff, 0x00670060); |
| 284 | writel(0x01010000, RCB_REG(0x3a28)); |
| 285 | writel(0x01010404, RCB_REG(0x3a2c)); |
| 286 | writel(0x01041041, RCB_REG(0x3a80)); |
| 287 | clrsetbits_le32(RCB_REG(0x3a84), 0x0000ffff, 0x00001001); |
| 288 | setbits_le32(RCB_REG(0x3a84), 1 << 24); /* SATA 2/3 disabled */ |
| 289 | setbits_le32(RCB_REG(0x3a88), 1 << 0); /* SATA 4/5 disabled */ |
| 290 | writel(0x00000001, RCB_REG(0x3a6c)); |
| 291 | clrsetbits_le32(RCB_REG(0x2344), ~0x00ffff00, 0xff00000c); |
| 292 | clrsetbits_le32(RCB_REG(0x80c), 0xff << 20, 0x11 << 20); |
| 293 | writel(0, RCB_REG(0x33c8)); |
| 294 | setbits_le32(RCB_REG(0x21b0), 0xf); |
| 295 | } |
| 296 | |
| 297 | /* PantherPoint PCH Power Management init */ |
Simon Glass | d6fe74e | 2016-01-17 16:11:42 -0700 | [diff] [blame] | 298 | static void ppt_pm_init(struct udevice *pch) |
Simon Glass | 06409c9 | 2014-11-14 18:18:35 -0700 | [diff] [blame] | 299 | { |
| 300 | debug("PantherPoint PM init\n"); |
Simon Glass | d6fe74e | 2016-01-17 16:11:42 -0700 | [diff] [blame] | 301 | dm_pci_write_config8(pch, 0xa9, 0x47); |
Simon Glass | 06409c9 | 2014-11-14 18:18:35 -0700 | [diff] [blame] | 302 | setbits_le32(RCB_REG(0x2238), 1 << 0); |
| 303 | setbits_le32(RCB_REG(0x228c), 1 << 0); |
| 304 | setbits_le16(RCB_REG(0x1100), (1 << 13) | (1 << 14)); |
| 305 | setbits_le16(RCB_REG(0x0900), 1 << 14); |
| 306 | writel(0xc03b8400, RCB_REG(0x2304)); |
| 307 | setbits_le32(RCB_REG(0x2314), (1 << 5) | (1 << 18)); |
| 308 | setbits_le32(RCB_REG(0x2320), (1 << 15) | (1 << 1)); |
| 309 | clrsetbits_le32(RCB_REG(0x3314), 0x1f, 0xf); |
| 310 | writel(0x054f0000, RCB_REG(0x3318)); |
| 311 | writel(0x04000000, RCB_REG(0x3324)); |
| 312 | setbits_le32(RCB_REG(0x3340), 0xfffff); |
| 313 | setbits_le32(RCB_REG(0x3344), (1 << 1) | (1 << 0)); |
| 314 | writel(0x0001c000, RCB_REG(0x3360)); |
| 315 | writel(0x00061100, RCB_REG(0x3368)); |
| 316 | writel(0x7f8fdfff, RCB_REG(0x3378)); |
| 317 | writel(0x000003fd, RCB_REG(0x337c)); |
| 318 | writel(0x00001000, RCB_REG(0x3388)); |
| 319 | writel(0x0001c000, RCB_REG(0x3390)); |
| 320 | writel(0x00000800, RCB_REG(0x33a0)); |
| 321 | writel(0x00001000, RCB_REG(0x33b0)); |
| 322 | writel(0x00093900, RCB_REG(0x33c0)); |
| 323 | writel(0x24653002, RCB_REG(0x33cc)); |
| 324 | writel(0x067388fe, RCB_REG(0x33d0)); |
| 325 | clrsetbits_le32(RCB_REG(0x33d4), 0x0fff0fff, 0x00670060); |
| 326 | writel(0x01010000, RCB_REG(0x3a28)); |
| 327 | writel(0x01010404, RCB_REG(0x3a2c)); |
| 328 | writel(0x01040000, RCB_REG(0x3a80)); |
| 329 | clrsetbits_le32(RCB_REG(0x3a84), 0x0000ffff, 0x00001001); |
| 330 | /* SATA 2/3 disabled */ |
| 331 | setbits_le32(RCB_REG(0x3a84), 1 << 24); |
| 332 | /* SATA 4/5 disabled */ |
| 333 | setbits_le32(RCB_REG(0x3a88), 1 << 0); |
| 334 | writel(0x00000001, RCB_REG(0x3a6c)); |
| 335 | clrsetbits_le32(RCB_REG(0x2344), 0xff0000ff, 0xff00000c); |
| 336 | clrsetbits_le32(RCB_REG(0x80c), 0xff << 20, 0x11 << 20); |
| 337 | setbits_le32(RCB_REG(0x33a4), (1 << 0)); |
| 338 | writel(0, RCB_REG(0x33c8)); |
| 339 | setbits_le32(RCB_REG(0x21b0), 0xf); |
| 340 | } |
| 341 | |
| 342 | static void enable_hpet(void) |
| 343 | { |
| 344 | /* Move HPET to default address 0xfed00000 and enable it */ |
| 345 | clrsetbits_le32(RCB_REG(HPTC), 3 << 0, 1 << 7); |
| 346 | } |
| 347 | |
Simon Glass | d6fe74e | 2016-01-17 16:11:42 -0700 | [diff] [blame] | 348 | static void enable_clock_gating(struct udevice *pch) |
Simon Glass | 06409c9 | 2014-11-14 18:18:35 -0700 | [diff] [blame] | 349 | { |
| 350 | u32 reg32; |
| 351 | u16 reg16; |
| 352 | |
| 353 | setbits_le32(RCB_REG(0x2234), 0xf); |
| 354 | |
Simon Glass | d6fe74e | 2016-01-17 16:11:42 -0700 | [diff] [blame] | 355 | dm_pci_read_config16(pch, GEN_PMCON_1, ®16); |
Simon Glass | 06409c9 | 2014-11-14 18:18:35 -0700 | [diff] [blame] | 356 | reg16 |= (1 << 2) | (1 << 11); |
Simon Glass | d6fe74e | 2016-01-17 16:11:42 -0700 | [diff] [blame] | 357 | dm_pci_write_config16(pch, GEN_PMCON_1, reg16); |
Simon Glass | 06409c9 | 2014-11-14 18:18:35 -0700 | [diff] [blame] | 358 | |
Simon Glass | c8f4453 | 2016-09-25 21:33:35 -0600 | [diff] [blame] | 359 | pch_iobp_update(pch, 0xeb007f07, ~0U, 1 << 31); |
| 360 | pch_iobp_update(pch, 0xeb004000, ~0U, 1 << 7); |
| 361 | pch_iobp_update(pch, 0xec007f07, ~0U, 1 << 31); |
| 362 | pch_iobp_update(pch, 0xec004000, ~0U, 1 << 7); |
Simon Glass | 06409c9 | 2014-11-14 18:18:35 -0700 | [diff] [blame] | 363 | |
| 364 | reg32 = readl(RCB_REG(CG)); |
| 365 | reg32 |= (1 << 31); |
| 366 | reg32 |= (1 << 29) | (1 << 28); |
| 367 | reg32 |= (1 << 27) | (1 << 26) | (1 << 25) | (1 << 24); |
| 368 | reg32 |= (1 << 16); |
| 369 | reg32 |= (1 << 17); |
| 370 | reg32 |= (1 << 18); |
| 371 | reg32 |= (1 << 22); |
| 372 | reg32 |= (1 << 23); |
| 373 | reg32 &= ~(1 << 20); |
| 374 | reg32 |= (1 << 19); |
| 375 | reg32 |= (1 << 0); |
| 376 | reg32 |= (0xf << 1); |
| 377 | writel(reg32, RCB_REG(CG)); |
| 378 | |
| 379 | setbits_le32(RCB_REG(0x38c0), 0x7); |
| 380 | setbits_le32(RCB_REG(0x36d4), 0x6680c004); |
| 381 | setbits_le32(RCB_REG(0x3564), 0x3); |
| 382 | } |
| 383 | |
Simon Glass | d6fe74e | 2016-01-17 16:11:42 -0700 | [diff] [blame] | 384 | static void pch_disable_smm_only_flashing(struct udevice *pch) |
Simon Glass | 06409c9 | 2014-11-14 18:18:35 -0700 | [diff] [blame] | 385 | { |
| 386 | u8 reg8; |
| 387 | |
| 388 | debug("Enabling BIOS updates outside of SMM... "); |
Simon Glass | d6fe74e | 2016-01-17 16:11:42 -0700 | [diff] [blame] | 389 | dm_pci_read_config8(pch, 0xdc, ®8); /* BIOS_CNTL */ |
Simon Glass | 06409c9 | 2014-11-14 18:18:35 -0700 | [diff] [blame] | 390 | reg8 &= ~(1 << 5); |
Simon Glass | d6fe74e | 2016-01-17 16:11:42 -0700 | [diff] [blame] | 391 | dm_pci_write_config8(pch, 0xdc, reg8); |
Simon Glass | 06409c9 | 2014-11-14 18:18:35 -0700 | [diff] [blame] | 392 | } |
| 393 | |
Simon Glass | d6fe74e | 2016-01-17 16:11:42 -0700 | [diff] [blame] | 394 | static void pch_fixups(struct udevice *pch) |
Simon Glass | 06409c9 | 2014-11-14 18:18:35 -0700 | [diff] [blame] | 395 | { |
| 396 | u8 gen_pmcon_2; |
| 397 | |
| 398 | /* Indicate DRAM init done for MRC S3 to know it can resume */ |
Simon Glass | d6fe74e | 2016-01-17 16:11:42 -0700 | [diff] [blame] | 399 | dm_pci_read_config8(pch, GEN_PMCON_2, &gen_pmcon_2); |
Simon Glass | 06409c9 | 2014-11-14 18:18:35 -0700 | [diff] [blame] | 400 | gen_pmcon_2 |= (1 << 7); |
Simon Glass | d6fe74e | 2016-01-17 16:11:42 -0700 | [diff] [blame] | 401 | dm_pci_write_config8(pch, GEN_PMCON_2, gen_pmcon_2); |
Simon Glass | 06409c9 | 2014-11-14 18:18:35 -0700 | [diff] [blame] | 402 | |
| 403 | /* Enable DMI ASPM in the PCH */ |
| 404 | clrbits_le32(RCB_REG(0x2304), 1 << 10); |
| 405 | setbits_le32(RCB_REG(0x21a4), (1 << 11) | (1 << 10)); |
| 406 | setbits_le32(RCB_REG(0x21a8), 0x3); |
| 407 | } |
| 408 | |
Simon Glass | 8acbabb | 2016-01-17 16:11:12 -0700 | [diff] [blame] | 409 | static void set_spi_speed(void) |
| 410 | { |
| 411 | u32 fdod; |
| 412 | |
| 413 | /* Observe SPI Descriptor Component Section 0 */ |
| 414 | writel(0x1000, RCB_REG(SPI_DESC_COMP0)); |
| 415 | |
| 416 | /* Extract the1 Write/Erase SPI Frequency from descriptor */ |
| 417 | fdod = readl(RCB_REG(SPI_FREQ_WR_ERA)); |
| 418 | fdod >>= 24; |
| 419 | fdod &= 7; |
| 420 | |
| 421 | /* Set Software Sequence frequency to match */ |
| 422 | clrsetbits_8(RCB_REG(SPI_FREQ_SWSEQ), 7, fdod); |
| 423 | } |
| 424 | |
Simon Glass | d6fe74e | 2016-01-17 16:11:42 -0700 | [diff] [blame] | 425 | static int lpc_init_extra(struct udevice *dev) |
Simon Glass | 06409c9 | 2014-11-14 18:18:35 -0700 | [diff] [blame] | 426 | { |
Simon Glass | d6fe74e | 2016-01-17 16:11:42 -0700 | [diff] [blame] | 427 | struct udevice *pch = dev->parent; |
Simon Glass | 06409c9 | 2014-11-14 18:18:35 -0700 | [diff] [blame] | 428 | |
| 429 | debug("pch: lpc_init\n"); |
Simon Glass | d6fe74e | 2016-01-17 16:11:42 -0700 | [diff] [blame] | 430 | dm_pci_write_bar32(pch, 0, 0); |
| 431 | dm_pci_write_bar32(pch, 1, 0xff800000); |
| 432 | dm_pci_write_bar32(pch, 2, 0xfec00000); |
| 433 | dm_pci_write_bar32(pch, 3, 0x800); |
| 434 | dm_pci_write_bar32(pch, 4, 0x900); |
Simon Glass | 06409c9 | 2014-11-14 18:18:35 -0700 | [diff] [blame] | 435 | |
Simon Glass | 06409c9 | 2014-11-14 18:18:35 -0700 | [diff] [blame] | 436 | /* Set the value for PCI command register. */ |
Simon Glass | d6fe74e | 2016-01-17 16:11:42 -0700 | [diff] [blame] | 437 | dm_pci_write_config16(pch, PCI_COMMAND, 0x000f); |
Simon Glass | 06409c9 | 2014-11-14 18:18:35 -0700 | [diff] [blame] | 438 | |
| 439 | /* IO APIC initialization. */ |
Simon Glass | d6fe74e | 2016-01-17 16:11:42 -0700 | [diff] [blame] | 440 | pch_enable_apic(pch); |
Simon Glass | 06409c9 | 2014-11-14 18:18:35 -0700 | [diff] [blame] | 441 | |
Simon Glass | d6fe74e | 2016-01-17 16:11:42 -0700 | [diff] [blame] | 442 | pch_enable_serial_irqs(pch); |
Simon Glass | 06409c9 | 2014-11-14 18:18:35 -0700 | [diff] [blame] | 443 | |
| 444 | /* Setup the PIRQ. */ |
Simon Glass | d6fe74e | 2016-01-17 16:11:42 -0700 | [diff] [blame] | 445 | pch_pirq_init(pch); |
Simon Glass | 06409c9 | 2014-11-14 18:18:35 -0700 | [diff] [blame] | 446 | |
| 447 | /* Setup power options. */ |
Simon Glass | d6fe74e | 2016-01-17 16:11:42 -0700 | [diff] [blame] | 448 | pch_power_options(pch); |
Simon Glass | 06409c9 | 2014-11-14 18:18:35 -0700 | [diff] [blame] | 449 | |
| 450 | /* Initialize power management */ |
Simon Glass | b3a9e51 | 2016-01-17 16:11:52 -0700 | [diff] [blame] | 451 | switch (pch_silicon_type(pch)) { |
Simon Glass | 06409c9 | 2014-11-14 18:18:35 -0700 | [diff] [blame] | 452 | case PCH_TYPE_CPT: /* CougarPoint */ |
Simon Glass | d6fe74e | 2016-01-17 16:11:42 -0700 | [diff] [blame] | 453 | cpt_pm_init(pch); |
Simon Glass | 06409c9 | 2014-11-14 18:18:35 -0700 | [diff] [blame] | 454 | break; |
| 455 | case PCH_TYPE_PPT: /* PantherPoint */ |
Simon Glass | d6fe74e | 2016-01-17 16:11:42 -0700 | [diff] [blame] | 456 | ppt_pm_init(pch); |
Simon Glass | 06409c9 | 2014-11-14 18:18:35 -0700 | [diff] [blame] | 457 | break; |
| 458 | default: |
Simon Glass | d6fe74e | 2016-01-17 16:11:42 -0700 | [diff] [blame] | 459 | printf("Unknown Chipset: %s\n", pch->name); |
Simon Glass | 06409c9 | 2014-11-14 18:18:35 -0700 | [diff] [blame] | 460 | return -ENOSYS; |
| 461 | } |
| 462 | |
| 463 | /* Initialize the real time clock. */ |
Simon Glass | d6fe74e | 2016-01-17 16:11:42 -0700 | [diff] [blame] | 464 | pch_rtc_init(pch); |
Simon Glass | 06409c9 | 2014-11-14 18:18:35 -0700 | [diff] [blame] | 465 | |
| 466 | /* Initialize the High Precision Event Timers, if present. */ |
| 467 | enable_hpet(); |
| 468 | |
| 469 | /* Initialize Clock Gating */ |
Simon Glass | d6fe74e | 2016-01-17 16:11:42 -0700 | [diff] [blame] | 470 | enable_clock_gating(pch); |
Simon Glass | 06409c9 | 2014-11-14 18:18:35 -0700 | [diff] [blame] | 471 | |
Simon Glass | d6fe74e | 2016-01-17 16:11:42 -0700 | [diff] [blame] | 472 | pch_disable_smm_only_flashing(pch); |
Simon Glass | 06409c9 | 2014-11-14 18:18:35 -0700 | [diff] [blame] | 473 | |
Simon Glass | d6fe74e | 2016-01-17 16:11:42 -0700 | [diff] [blame] | 474 | pch_fixups(pch); |
Simon Glass | 06409c9 | 2014-11-14 18:18:35 -0700 | [diff] [blame] | 475 | |
| 476 | return 0; |
| 477 | } |
| 478 | |
Simon Glass | a716f9e | 2016-01-17 16:11:21 -0700 | [diff] [blame] | 479 | static int bd82x6x_lpc_early_init(struct udevice *dev) |
| 480 | { |
Simon Glass | 63e08a2 | 2016-03-11 22:06:57 -0700 | [diff] [blame] | 481 | set_spi_speed(); |
| 482 | |
Simon Glass | a716f9e | 2016-01-17 16:11:21 -0700 | [diff] [blame] | 483 | /* Setting up Southbridge. In the northbridge code. */ |
| 484 | debug("Setting up static southbridge registers\n"); |
Simon Glass | ab39d33 | 2016-03-11 22:06:56 -0700 | [diff] [blame] | 485 | dm_pci_write_config32(dev->parent, PCH_RCBA_BASE, |
| 486 | RCB_BASE_ADDRESS | 1); |
Simon Glass | a716f9e | 2016-01-17 16:11:21 -0700 | [diff] [blame] | 487 | dm_pci_write_config32(dev->parent, PMBASE, DEFAULT_PMBASE | 1); |
| 488 | |
| 489 | /* Enable ACPI BAR */ |
| 490 | dm_pci_write_config8(dev->parent, ACPI_CNTL, 0x80); |
| 491 | |
| 492 | debug("Disabling watchdog reboot\n"); |
| 493 | setbits_le32(RCB_REG(GCS), 1 >> 5); /* No reset */ |
| 494 | outw(1 << 11, DEFAULT_PMBASE | 0x60 | 0x08); /* halt timer */ |
| 495 | |
Simon Glass | 25d1f94 | 2016-01-17 16:11:22 -0700 | [diff] [blame] | 496 | dm_pci_write_config32(dev->parent, GPIO_BASE, DEFAULT_GPIOBASE | 1); |
| 497 | dm_pci_write_config32(dev->parent, GPIO_CNTL, 0x10); |
| 498 | |
Simon Glass | a716f9e | 2016-01-17 16:11:21 -0700 | [diff] [blame] | 499 | return 0; |
| 500 | } |
| 501 | |
Simon Glass | 044f1a0 | 2016-01-17 16:11:10 -0700 | [diff] [blame] | 502 | static int bd82x6x_lpc_probe(struct udevice *dev) |
| 503 | { |
Simon Glass | 62b3717 | 2016-01-17 16:11:11 -0700 | [diff] [blame] | 504 | int ret; |
| 505 | |
Simon Glass | 40e7a20 | 2016-01-17 16:11:40 -0700 | [diff] [blame] | 506 | if (!(gd->flags & GD_FLG_RELOC)) { |
Simon Glass | 63e08a2 | 2016-03-11 22:06:57 -0700 | [diff] [blame] | 507 | ret = lpc_common_early_init(dev); |
Simon Glass | 40e7a20 | 2016-01-17 16:11:40 -0700 | [diff] [blame] | 508 | if (ret) { |
| 509 | debug("%s: lpc_early_init() failed\n", __func__); |
| 510 | return ret; |
| 511 | } |
Simon Glass | 62b3717 | 2016-01-17 16:11:11 -0700 | [diff] [blame] | 512 | |
Simon Glass | 40e7a20 | 2016-01-17 16:11:40 -0700 | [diff] [blame] | 513 | return bd82x6x_lpc_early_init(dev); |
Simon Glass | 62b3717 | 2016-01-17 16:11:11 -0700 | [diff] [blame] | 514 | } |
| 515 | |
Simon Glass | d6fe74e | 2016-01-17 16:11:42 -0700 | [diff] [blame] | 516 | return lpc_init_extra(dev); |
Simon Glass | 044f1a0 | 2016-01-17 16:11:10 -0700 | [diff] [blame] | 517 | } |
| 518 | |
Simon Glass | 06e694f | 2015-03-26 09:29:29 -0600 | [diff] [blame] | 519 | static const struct udevice_id bd82x6x_lpc_ids[] = { |
| 520 | { .compatible = "intel,bd82x6x-lpc" }, |
| 521 | { } |
| 522 | }; |
| 523 | |
| 524 | U_BOOT_DRIVER(bd82x6x_lpc_drv) = { |
| 525 | .name = "lpc", |
| 526 | .id = UCLASS_LPC, |
| 527 | .of_match = bd82x6x_lpc_ids, |
Simon Glass | 044f1a0 | 2016-01-17 16:11:10 -0700 | [diff] [blame] | 528 | .probe = bd82x6x_lpc_probe, |
Simon Glass | 06e694f | 2015-03-26 09:29:29 -0600 | [diff] [blame] | 529 | }; |