183d290c5STom Rini // SPDX-License-Identifier: GPL-2.0
21e6f4e58SSimon Glass /*
31e6f4e58SSimon Glass * Copyright (c) 2016 Google, Inc
41e6f4e58SSimon Glass */
51e6f4e58SSimon Glass
61e6f4e58SSimon Glass #include <common.h>
71e6f4e58SSimon Glass #include <dm.h>
81e6f4e58SSimon Glass #include <pch.h>
91e6f4e58SSimon Glass #include <asm/cpu.h>
101e6f4e58SSimon Glass #include <asm/gpio.h>
111e6f4e58SSimon Glass #include <asm/i8259.h>
121e6f4e58SSimon Glass #include <asm/intel_regs.h>
131e6f4e58SSimon Glass #include <asm/io.h>
141e6f4e58SSimon Glass #include <asm/ioapic.h>
151e6f4e58SSimon Glass #include <asm/lpc_common.h>
161e6f4e58SSimon Glass #include <asm/pch_common.h>
171e6f4e58SSimon Glass #include <asm/arch/cpu.h>
181e6f4e58SSimon Glass #include <asm/arch/gpio.h>
191e6f4e58SSimon Glass #include <asm/arch/iomap.h>
201e6f4e58SSimon Glass #include <asm/arch/pch.h>
211e6f4e58SSimon Glass #include <asm/arch/pm.h>
221e6f4e58SSimon Glass #include <asm/arch/rcb.h>
23*3f3411ebSSimon Glass #include <asm/arch/serialio.h>
241e6f4e58SSimon Glass #include <asm/arch/spi.h>
25*3f3411ebSSimon Glass #include <dm/uclass-internal.h>
261e6f4e58SSimon Glass
271e6f4e58SSimon Glass #define BIOS_CTRL 0xdc
281e6f4e58SSimon Glass
cpu_is_ult(void)291e6f4e58SSimon Glass bool cpu_is_ult(void)
301e6f4e58SSimon Glass {
311e6f4e58SSimon Glass u32 fm = cpu_get_family_model();
321e6f4e58SSimon Glass
331e6f4e58SSimon Glass return fm == BROADWELL_FAMILY_ULT || fm == HASWELL_FAMILY_ULT;
341e6f4e58SSimon Glass }
351e6f4e58SSimon Glass
broadwell_pch_early_init(struct udevice * dev)361e6f4e58SSimon Glass static int broadwell_pch_early_init(struct udevice *dev)
371e6f4e58SSimon Glass {
381e6f4e58SSimon Glass struct gpio_desc desc;
391e6f4e58SSimon Glass struct udevice *bus;
401e6f4e58SSimon Glass pci_dev_t bdf;
411e6f4e58SSimon Glass int ret;
421e6f4e58SSimon Glass
431e6f4e58SSimon Glass dm_pci_write_config32(dev, PCH_RCBA, RCB_BASE_ADDRESS | 1);
441e6f4e58SSimon Glass
451e6f4e58SSimon Glass dm_pci_write_config32(dev, PMBASE, ACPI_BASE_ADDRESS | 1);
461e6f4e58SSimon Glass dm_pci_write_config8(dev, ACPI_CNTL, ACPI_EN);
471e6f4e58SSimon Glass dm_pci_write_config32(dev, GPIO_BASE, GPIO_BASE_ADDRESS | 1);
481e6f4e58SSimon Glass dm_pci_write_config8(dev, GPIO_CNTL, GPIO_EN);
491e6f4e58SSimon Glass
501e6f4e58SSimon Glass /* Enable IOAPIC */
511e6f4e58SSimon Glass writew(0x1000, RCB_REG(OIC));
521e6f4e58SSimon Glass /* Read back for posted write */
531e6f4e58SSimon Glass readw(RCB_REG(OIC));
541e6f4e58SSimon Glass
551e6f4e58SSimon Glass /* Set HPET address and enable it */
561e6f4e58SSimon Glass clrsetbits_le32(RCB_REG(HPTC), 3, 1 << 7);
571e6f4e58SSimon Glass /* Read back for posted write */
581e6f4e58SSimon Glass readl(RCB_REG(HPTC));
591e6f4e58SSimon Glass /* Enable HPET to start counter */
601e6f4e58SSimon Glass setbits_le32(HPET_BASE_ADDRESS + 0x10, 1 << 0);
611e6f4e58SSimon Glass
621e6f4e58SSimon Glass setbits_le32(RCB_REG(GCS), 1 << 5);
631e6f4e58SSimon Glass
641e6f4e58SSimon Glass /*
651e6f4e58SSimon Glass * Enable PP3300_AUTOBAHN_EN after initial GPIO setup
661e6f4e58SSimon Glass * to prevent possible brownout. This will cause the GPIOs to be set
671e6f4e58SSimon Glass * up if it has not been done already.
681e6f4e58SSimon Glass */
691e6f4e58SSimon Glass ret = gpio_request_by_name(dev, "power-enable-gpio", 0, &desc,
701e6f4e58SSimon Glass GPIOD_IS_OUT | GPIOD_IS_OUT_ACTIVE);
711e6f4e58SSimon Glass if (ret)
721e6f4e58SSimon Glass return ret;
731e6f4e58SSimon Glass
741e6f4e58SSimon Glass /* 8.14 Additional PCI Express Programming Steps, step #1 */
751e6f4e58SSimon Glass bdf = PCI_BDF(0, 0x1c, 0);
761e6f4e58SSimon Glass bus = pci_get_controller(dev);
771e6f4e58SSimon Glass pci_bus_clrset_config32(bus, bdf, 0xf4, 0x60, 0);
781e6f4e58SSimon Glass pci_bus_clrset_config32(bus, bdf, 0xf4, 0x80, 0x80);
791e6f4e58SSimon Glass pci_bus_clrset_config32(bus, bdf, 0xe2, 0x30, 0x30);
801e6f4e58SSimon Glass
811e6f4e58SSimon Glass return 0;
821e6f4e58SSimon Glass }
831e6f4e58SSimon Glass
pch_misc_init(struct udevice * dev)841e6f4e58SSimon Glass static void pch_misc_init(struct udevice *dev)
851e6f4e58SSimon Glass {
861e6f4e58SSimon Glass /* Setup SLP signal assertion, SLP_S4=4s, SLP_S3=50ms */
871e6f4e58SSimon Glass dm_pci_clrset_config8(dev, GEN_PMCON_3, 3 << 4 | 1 << 10,
881e6f4e58SSimon Glass 1 << 3 | 1 << 11 | 1 << 12);
891e6f4e58SSimon Glass /* Prepare sleep mode */
901e6f4e58SSimon Glass clrsetio_32(ACPI_BASE_ADDRESS + PM1_CNT, SLP_TYP, SCI_EN);
911e6f4e58SSimon Glass
921e6f4e58SSimon Glass /* Setup NMI on errors, disable SERR */
931e6f4e58SSimon Glass clrsetio_8(0x61, 0xf0, 1 << 2);
941e6f4e58SSimon Glass /* Disable NMI sources */
951e6f4e58SSimon Glass setio_8(0x70, 1 << 7);
961e6f4e58SSimon Glass /* Indicate DRAM init done for MRC */
971e6f4e58SSimon Glass dm_pci_clrset_config8(dev, GEN_PMCON_2, 0, 1 << 7);
981e6f4e58SSimon Glass
991e6f4e58SSimon Glass /* Clear status bits to prevent unexpected wake */
1001e6f4e58SSimon Glass setbits_le32(RCB_REG(0x3310), 0x0000002f);
1011e6f4e58SSimon Glass clrsetbits_le32(RCB_REG(0x3f02), 0x0000000f, 0);
1021e6f4e58SSimon Glass /* Enable PCIe Relaxed Order */
1031e6f4e58SSimon Glass setbits_le32(RCB_REG(0x2314), 1 << 31 | 1 << 7);
1041e6f4e58SSimon Glass setbits_le32(RCB_REG(0x1114), 1 << 15 | 1 << 14);
1051e6f4e58SSimon Glass /* Setup SERIRQ, enable continuous mode */
1061e6f4e58SSimon Glass dm_pci_clrset_config8(dev, SERIRQ_CNTL, 0, 1 << 7 | 1 << 6);
1071e6f4e58SSimon Glass };
1081e6f4e58SSimon Glass
pch_enable_ioapic(void)1091e6f4e58SSimon Glass static void pch_enable_ioapic(void)
1101e6f4e58SSimon Glass {
1111e6f4e58SSimon Glass u32 reg32;
1121e6f4e58SSimon Glass
113b813ea9aSBin Meng /* Make sure this is a unique ID within system */
114b813ea9aSBin Meng io_apic_set_id(0x04);
1151e6f4e58SSimon Glass
1161e6f4e58SSimon Glass /* affirm full set of redirection table entries ("write once") */
1171e6f4e58SSimon Glass reg32 = io_apic_read(0x01);
1181e6f4e58SSimon Glass
1191e6f4e58SSimon Glass /* PCH-LP has 39 redirection entries */
1201e6f4e58SSimon Glass reg32 &= ~0x00ff0000;
1211e6f4e58SSimon Glass reg32 |= 0x00270000;
1221e6f4e58SSimon Glass
1231e6f4e58SSimon Glass io_apic_write(0x01, reg32);
1241e6f4e58SSimon Glass
1251e6f4e58SSimon Glass /*
1261e6f4e58SSimon Glass * Select Boot Configuration register (0x03) and
1271e6f4e58SSimon Glass * use Processor System Bus (0x01) to deliver interrupts.
1281e6f4e58SSimon Glass */
1291e6f4e58SSimon Glass io_apic_write(0x03, 0x01);
1301e6f4e58SSimon Glass }
1311e6f4e58SSimon Glass
1321e6f4e58SSimon Glass /* Enable all requested GPE */
enable_all_gpe(u32 set1,u32 set2,u32 set3,u32 set4)1331e6f4e58SSimon Glass void enable_all_gpe(u32 set1, u32 set2, u32 set3, u32 set4)
1341e6f4e58SSimon Glass {
1351e6f4e58SSimon Glass outl(set1, ACPI_BASE_ADDRESS + GPE0_EN(GPE_31_0));
1361e6f4e58SSimon Glass outl(set2, ACPI_BASE_ADDRESS + GPE0_EN(GPE_63_32));
1371e6f4e58SSimon Glass outl(set3, ACPI_BASE_ADDRESS + GPE0_EN(GPE_94_64));
1381e6f4e58SSimon Glass outl(set4, ACPI_BASE_ADDRESS + GPE0_EN(GPE_STD));
1391e6f4e58SSimon Glass }
1401e6f4e58SSimon Glass
1411e6f4e58SSimon Glass /*
1421e6f4e58SSimon Glass * Enable GPIO SMI events - it would be good to put this in the GPIO driver
1431e6f4e58SSimon Glass * but it would need a new driver operation.
1441e6f4e58SSimon Glass */
enable_alt_smi(struct udevice * pch,u32 mask)1451e6f4e58SSimon Glass int enable_alt_smi(struct udevice *pch, u32 mask)
1461e6f4e58SSimon Glass {
1471e6f4e58SSimon Glass struct pch_lp_gpio_regs *regs;
1481e6f4e58SSimon Glass u32 gpiobase;
1491e6f4e58SSimon Glass int ret;
1501e6f4e58SSimon Glass
1511e6f4e58SSimon Glass ret = pch_get_gpio_base(pch, &gpiobase);
1521e6f4e58SSimon Glass if (ret) {
1531e6f4e58SSimon Glass debug("%s: invalid GPIOBASE address (%08x)\n", __func__,
1541e6f4e58SSimon Glass gpiobase);
1551e6f4e58SSimon Glass return -EINVAL;
1561e6f4e58SSimon Glass }
1571e6f4e58SSimon Glass
1581e6f4e58SSimon Glass regs = (struct pch_lp_gpio_regs *)gpiobase;
1591e6f4e58SSimon Glass setio_32(regs->alt_gpi_smi_en, mask);
1601e6f4e58SSimon Glass
1611e6f4e58SSimon Glass return 0;
1621e6f4e58SSimon Glass }
1631e6f4e58SSimon Glass
pch_power_options(struct udevice * dev)1641e6f4e58SSimon Glass static int pch_power_options(struct udevice *dev)
1651e6f4e58SSimon Glass {
1661e6f4e58SSimon Glass int pwr_on_after_power_fail = MAINBOARD_POWER_OFF;
1671e6f4e58SSimon Glass const char *state;
1681e6f4e58SSimon Glass u32 enable[4];
1691e6f4e58SSimon Glass u16 reg16;
1701e6f4e58SSimon Glass int ret;
1711e6f4e58SSimon Glass
1721e6f4e58SSimon Glass dm_pci_read_config16(dev, GEN_PMCON_3, ®16);
1731e6f4e58SSimon Glass reg16 &= 0xfffe;
1741e6f4e58SSimon Glass switch (pwr_on_after_power_fail) {
1751e6f4e58SSimon Glass case MAINBOARD_POWER_OFF:
1761e6f4e58SSimon Glass reg16 |= 1;
1771e6f4e58SSimon Glass state = "off";
1781e6f4e58SSimon Glass break;
1791e6f4e58SSimon Glass case MAINBOARD_POWER_ON:
1801e6f4e58SSimon Glass reg16 &= ~1;
1811e6f4e58SSimon Glass state = "on";
1821e6f4e58SSimon Glass break;
1831e6f4e58SSimon Glass case MAINBOARD_POWER_KEEP:
1841e6f4e58SSimon Glass reg16 &= ~1;
1851e6f4e58SSimon Glass state = "state keep";
1861e6f4e58SSimon Glass break;
1871e6f4e58SSimon Glass default:
1881e6f4e58SSimon Glass state = "undefined";
1891e6f4e58SSimon Glass }
1901e6f4e58SSimon Glass dm_pci_write_config16(dev, GEN_PMCON_3, reg16);
1911e6f4e58SSimon Glass debug("Set power %s after power failure.\n", state);
1921e6f4e58SSimon Glass
1931e6f4e58SSimon Glass /* GPE setup based on device tree configuration */
194e160f7d4SSimon Glass ret = fdtdec_get_int_array(gd->fdt_blob, dev_of_offset(dev),
1951e6f4e58SSimon Glass "intel,gpe0-en", enable, ARRAY_SIZE(enable));
1961e6f4e58SSimon Glass if (ret)
1971e6f4e58SSimon Glass return -EINVAL;
1981e6f4e58SSimon Glass enable_all_gpe(enable[0], enable[1], enable[2], enable[3]);
1991e6f4e58SSimon Glass
2001e6f4e58SSimon Glass /* SMI setup based on device tree configuration */
201e160f7d4SSimon Glass enable_alt_smi(dev, fdtdec_get_int(gd->fdt_blob, dev_of_offset(dev),
2021e6f4e58SSimon Glass "intel,alt-gp-smi-enable", 0));
2031e6f4e58SSimon Glass
2041e6f4e58SSimon Glass return 0;
2051e6f4e58SSimon Glass }
2061e6f4e58SSimon Glass
2071e6f4e58SSimon Glass /* Magic register settings for power management */
pch_pm_init_magic(struct udevice * dev)2081e6f4e58SSimon Glass static void pch_pm_init_magic(struct udevice *dev)
2091e6f4e58SSimon Glass {
2101e6f4e58SSimon Glass dm_pci_write_config8(dev, 0xa9, 0x46);
2111e6f4e58SSimon Glass clrbits_le32(RCB_REG(0x232c), 1),
2121e6f4e58SSimon Glass setbits_le32(RCB_REG(0x1100), 0x0000c13f);
2131e6f4e58SSimon Glass clrsetbits_le32(RCB_REG(0x2320), 0x60, 0x10);
2141e6f4e58SSimon Glass writel(0x00012fff, RCB_REG(0x3314));
2151e6f4e58SSimon Glass clrsetbits_le32(RCB_REG(0x3318), 0x000f0330, 0x0dcf0400);
2161e6f4e58SSimon Glass writel(0x04000000, RCB_REG(0x3324));
2171e6f4e58SSimon Glass writel(0x00041400, RCB_REG(0x3368));
2181e6f4e58SSimon Glass writel(0x3f8ddbff, RCB_REG(0x3388));
2191e6f4e58SSimon Glass writel(0x00007001, RCB_REG(0x33ac));
2201e6f4e58SSimon Glass writel(0x00181900, RCB_REG(0x33b0));
2211e6f4e58SSimon Glass writel(0x00060A00, RCB_REG(0x33c0));
2221e6f4e58SSimon Glass writel(0x06200840, RCB_REG(0x33d0));
2231e6f4e58SSimon Glass writel(0x01010101, RCB_REG(0x3a28));
2241e6f4e58SSimon Glass writel(0x040c0404, RCB_REG(0x3a2c));
2251e6f4e58SSimon Glass writel(0x9000000a, RCB_REG(0x3a9c));
2261e6f4e58SSimon Glass writel(0x03808033, RCB_REG(0x2b1c));
2271e6f4e58SSimon Glass writel(0x80000009, RCB_REG(0x2b34));
2281e6f4e58SSimon Glass writel(0x022ddfff, RCB_REG(0x3348));
2291e6f4e58SSimon Glass writel(0x00000001, RCB_REG(0x334c));
2301e6f4e58SSimon Glass writel(0x0001c000, RCB_REG(0x3358));
2311e6f4e58SSimon Glass writel(0x3f8ddbff, RCB_REG(0x3380));
2321e6f4e58SSimon Glass writel(0x0001c7e1, RCB_REG(0x3384));
2331e6f4e58SSimon Glass writel(0x0001c7e1, RCB_REG(0x338c));
2341e6f4e58SSimon Glass writel(0x0001c000, RCB_REG(0x3398));
2351e6f4e58SSimon Glass writel(0x00181900, RCB_REG(0x33a8));
2361e6f4e58SSimon Glass writel(0x00080000, RCB_REG(0x33dc));
2371e6f4e58SSimon Glass writel(0x00000001, RCB_REG(0x33e0));
2381e6f4e58SSimon Glass writel(0x0000040c, RCB_REG(0x3a20));
2391e6f4e58SSimon Glass writel(0x01010101, RCB_REG(0x3a24));
2401e6f4e58SSimon Glass writel(0x01010101, RCB_REG(0x3a30));
2411e6f4e58SSimon Glass dm_pci_clrset_config32(dev, 0xac, 0x00200000, 0);
2421e6f4e58SSimon Glass setbits_le32(RCB_REG(0x0410), 0x00000003);
2431e6f4e58SSimon Glass setbits_le32(RCB_REG(0x2618), 0x08000000);
2441e6f4e58SSimon Glass setbits_le32(RCB_REG(0x2300), 0x00000002);
2451e6f4e58SSimon Glass setbits_le32(RCB_REG(0x2600), 0x00000008);
2461e6f4e58SSimon Glass writel(0x00007001, RCB_REG(0x33b4));
2471e6f4e58SSimon Glass writel(0x022ddfff, RCB_REG(0x3350));
2481e6f4e58SSimon Glass writel(0x00000001, RCB_REG(0x3354));
2491e6f4e58SSimon Glass /* Power Optimizer */
2501e6f4e58SSimon Glass setbits_le32(RCB_REG(0x33d4), 0x08000000);
2511e6f4e58SSimon Glass /*
2521e6f4e58SSimon Glass * This stops the LCD from turning on:
2531e6f4e58SSimon Glass * setbits_le32(RCB_REG(0x33c8), 0x08000080);
2541e6f4e58SSimon Glass */
2551e6f4e58SSimon Glass writel(0x0000883c, RCB_REG(0x2b10));
2561e6f4e58SSimon Glass writel(0x1e0a4616, RCB_REG(0x2b14));
2571e6f4e58SSimon Glass writel(0x40000005, RCB_REG(0x2b24));
2581e6f4e58SSimon Glass writel(0x0005db01, RCB_REG(0x2b20));
2591e6f4e58SSimon Glass writel(0x05145005, RCB_REG(0x3a80));
2601e6f4e58SSimon Glass writel(0x00001005, RCB_REG(0x3a84));
2611e6f4e58SSimon Glass setbits_le32(RCB_REG(0x33d4), 0x2fff2fb1);
2621e6f4e58SSimon Glass setbits_le32(RCB_REG(0x33c8), 0x00008000);
2631e6f4e58SSimon Glass };
2641e6f4e58SSimon Glass
pch_type(struct udevice * dev)2651e6f4e58SSimon Glass static int pch_type(struct udevice *dev)
2661e6f4e58SSimon Glass {
2671e6f4e58SSimon Glass u16 type;
2681e6f4e58SSimon Glass
2691e6f4e58SSimon Glass dm_pci_read_config16(dev, PCI_DEVICE_ID, &type);
2701e6f4e58SSimon Glass
2711e6f4e58SSimon Glass return type;
2721e6f4e58SSimon Glass }
2731e6f4e58SSimon Glass
2741e6f4e58SSimon Glass /* Return 1 if PCH type is WildcatPoint */
pch_is_wpt(struct udevice * dev)2751e6f4e58SSimon Glass static int pch_is_wpt(struct udevice *dev)
2761e6f4e58SSimon Glass {
2771e6f4e58SSimon Glass return ((pch_type(dev) & 0xfff0) == 0x9cc0) ? 1 : 0;
2781e6f4e58SSimon Glass }
2791e6f4e58SSimon Glass
2801e6f4e58SSimon Glass /* Return 1 if PCH type is WildcatPoint ULX */
pch_is_wpt_ulx(struct udevice * dev)2811e6f4e58SSimon Glass static int pch_is_wpt_ulx(struct udevice *dev)
2821e6f4e58SSimon Glass {
2831e6f4e58SSimon Glass u16 lpcid = pch_type(dev);
2841e6f4e58SSimon Glass
2851e6f4e58SSimon Glass switch (lpcid) {
2861e6f4e58SSimon Glass case PCH_WPT_BDW_Y_SAMPLE:
2871e6f4e58SSimon Glass case PCH_WPT_BDW_Y_PREMIUM:
2881e6f4e58SSimon Glass case PCH_WPT_BDW_Y_BASE:
2891e6f4e58SSimon Glass return 1;
2901e6f4e58SSimon Glass }
2911e6f4e58SSimon Glass
2921e6f4e58SSimon Glass return 0;
2931e6f4e58SSimon Glass }
2941e6f4e58SSimon Glass
pch_read_soft_strap(int id)2951e6f4e58SSimon Glass static u32 pch_read_soft_strap(int id)
2961e6f4e58SSimon Glass {
2971e6f4e58SSimon Glass clrbits_le32(SPI_REG(SPIBAR_FDOC), 0x00007ffc);
2981e6f4e58SSimon Glass setbits_le32(SPI_REG(SPIBAR_FDOC), 0x00004000 | id * 4);
2991e6f4e58SSimon Glass
3001e6f4e58SSimon Glass return readl(SPI_REG(SPIBAR_FDOD));
3011e6f4e58SSimon Glass }
3021e6f4e58SSimon Glass
pch_enable_mphy(struct udevice * dev)3031e6f4e58SSimon Glass static void pch_enable_mphy(struct udevice *dev)
3041e6f4e58SSimon Glass {
3051e6f4e58SSimon Glass u32 data_and = 0xffffffff;
3061e6f4e58SSimon Glass u32 data_or = (1 << 14) | (1 << 13) | (1 << 12);
3071e6f4e58SSimon Glass
3081e6f4e58SSimon Glass data_or |= (1 << 0);
3091e6f4e58SSimon Glass if (pch_is_wpt(dev)) {
3101e6f4e58SSimon Glass data_and &= ~((1 << 7) | (1 << 6) | (1 << 3));
3111e6f4e58SSimon Glass data_or |= (1 << 5) | (1 << 4);
3121e6f4e58SSimon Glass
3131e6f4e58SSimon Glass if (pch_is_wpt_ulx(dev)) {
3141e6f4e58SSimon Glass /* Check if SATA and USB3 MPHY are enabled */
3151e6f4e58SSimon Glass u32 strap19 = pch_read_soft_strap(19);
3161e6f4e58SSimon Glass strap19 &= ((1 << 31) | (1 << 30));
3171e6f4e58SSimon Glass strap19 >>= 30;
3181e6f4e58SSimon Glass if (strap19 == 3) {
3191e6f4e58SSimon Glass data_or |= (1 << 3);
3201e6f4e58SSimon Glass debug("Enable ULX MPHY PG control in single domain\n");
3211e6f4e58SSimon Glass } else if (strap19 == 0) {
3221e6f4e58SSimon Glass debug("Enable ULX MPHY PG control in split domains\n");
3231e6f4e58SSimon Glass } else {
3241e6f4e58SSimon Glass debug("Invalid PCH Soft Strap 19 configuration\n");
3251e6f4e58SSimon Glass }
3261e6f4e58SSimon Glass } else {
3271e6f4e58SSimon Glass data_or |= (1 << 3);
3281e6f4e58SSimon Glass }
3291e6f4e58SSimon Glass }
3301e6f4e58SSimon Glass
3311e6f4e58SSimon Glass pch_iobp_update(0xCF000000, data_and, data_or);
3321e6f4e58SSimon Glass }
3331e6f4e58SSimon Glass
pch_init_deep_sx(bool deep_sx_enable_ac,bool deep_sx_enable_dc)3341e6f4e58SSimon Glass static void pch_init_deep_sx(bool deep_sx_enable_ac, bool deep_sx_enable_dc)
3351e6f4e58SSimon Glass {
3361e6f4e58SSimon Glass if (deep_sx_enable_ac) {
3371e6f4e58SSimon Glass setbits_le32(RCB_REG(DEEP_S3_POL), DEEP_S3_EN_AC);
3381e6f4e58SSimon Glass setbits_le32(RCB_REG(DEEP_S5_POL), DEEP_S5_EN_AC);
3391e6f4e58SSimon Glass }
3401e6f4e58SSimon Glass
3411e6f4e58SSimon Glass if (deep_sx_enable_dc) {
3421e6f4e58SSimon Glass setbits_le32(RCB_REG(DEEP_S3_POL), DEEP_S3_EN_DC);
3431e6f4e58SSimon Glass setbits_le32(RCB_REG(DEEP_S5_POL), DEEP_S5_EN_DC);
3441e6f4e58SSimon Glass }
3451e6f4e58SSimon Glass
3461e6f4e58SSimon Glass if (deep_sx_enable_ac || deep_sx_enable_dc) {
3471e6f4e58SSimon Glass setbits_le32(RCB_REG(DEEP_SX_CONFIG),
3481e6f4e58SSimon Glass DEEP_SX_WAKE_PIN_EN | DEEP_SX_GP27_PIN_EN);
3491e6f4e58SSimon Glass }
3501e6f4e58SSimon Glass }
3511e6f4e58SSimon Glass
3521e6f4e58SSimon Glass /* Power Management init */
pch_pm_init(struct udevice * dev)3531e6f4e58SSimon Glass static void pch_pm_init(struct udevice *dev)
3541e6f4e58SSimon Glass {
3551e6f4e58SSimon Glass debug("PCH PM init\n");
3561e6f4e58SSimon Glass
3571e6f4e58SSimon Glass pch_init_deep_sx(false, false);
3581e6f4e58SSimon Glass pch_enable_mphy(dev);
3591e6f4e58SSimon Glass pch_pm_init_magic(dev);
3601e6f4e58SSimon Glass
3611e6f4e58SSimon Glass if (pch_is_wpt(dev)) {
3621e6f4e58SSimon Glass setbits_le32(RCB_REG(0x33e0), 1 << 4 | 1 << 1);
3631e6f4e58SSimon Glass setbits_le32(RCB_REG(0x2b1c), 1 << 22 | 1 << 14 | 1 << 13);
3641e6f4e58SSimon Glass writel(0x16bf0002, RCB_REG(0x33e4));
3651e6f4e58SSimon Glass setbits_le32(RCB_REG(0x33e4), 0x1);
3661e6f4e58SSimon Glass }
3671e6f4e58SSimon Glass
3681e6f4e58SSimon Glass pch_iobp_update(0xCA000000, ~0UL, 0x00000009);
3691e6f4e58SSimon Glass
3701e6f4e58SSimon Glass /* Set RCBA 0x2b1c[29]=1 if DSP disabled */
3711e6f4e58SSimon Glass if (readl(RCB_REG(FD)) & PCH_DISABLE_ADSPD)
3721e6f4e58SSimon Glass setbits_le32(RCB_REG(0x2b1c), 1 << 29);
3731e6f4e58SSimon Glass }
3741e6f4e58SSimon Glass
pch_cg_init(struct udevice * dev)3751e6f4e58SSimon Glass static void pch_cg_init(struct udevice *dev)
3761e6f4e58SSimon Glass {
3771e6f4e58SSimon Glass struct udevice *bus = pci_get_controller(dev);
3781e6f4e58SSimon Glass u32 reg32;
3791e6f4e58SSimon Glass u16 reg16;
3801e6f4e58SSimon Glass ulong val;
3811e6f4e58SSimon Glass
3821e6f4e58SSimon Glass /* DMI */
3831e6f4e58SSimon Glass setbits_le32(RCB_REG(0x2234), 0xf);
3841e6f4e58SSimon Glass
3851e6f4e58SSimon Glass dm_pci_read_config16(dev, GEN_PMCON_1, ®16);
3861e6f4e58SSimon Glass reg16 &= ~(1 << 10); /* Disable BIOS_PCI_EXP_EN for native PME */
3871e6f4e58SSimon Glass if (pch_is_wpt(dev))
3881e6f4e58SSimon Glass reg16 &= ~(1 << 11);
3891e6f4e58SSimon Glass else
3901e6f4e58SSimon Glass reg16 |= 1 << 11;
3911e6f4e58SSimon Glass reg16 |= 1 << 5 | 1 << 6 | 1 << 7 | 1 << 12;
3921e6f4e58SSimon Glass reg16 |= 1 << 2; /* PCI CLKRUN# Enable */
3931e6f4e58SSimon Glass dm_pci_write_config16(dev, GEN_PMCON_1, reg16);
3941e6f4e58SSimon Glass
3951e6f4e58SSimon Glass /*
3961e6f4e58SSimon Glass * RCBA + 0x2614[27:25,14:13,10,8] = 101,11,1,1
3971e6f4e58SSimon Glass * RCBA + 0x2614[23:16] = 0x20
3981e6f4e58SSimon Glass * RCBA + 0x2614[30:28] = 0x0
3991e6f4e58SSimon Glass * RCBA + 0x2614[26] = 1 (IF 0:2.0@0x08 >= 0x0b)
4001e6f4e58SSimon Glass */
4011e6f4e58SSimon Glass clrsetbits_le32(RCB_REG(0x2614), 0x64ff0000, 0x0a206500);
4021e6f4e58SSimon Glass
4031e6f4e58SSimon Glass /* Check for 0:2.0@0x08 >= 0x0b */
4041e6f4e58SSimon Glass pci_bus_read_config(bus, PCI_BDF(0, 0x2, 0), 0x8, &val, PCI_SIZE_8);
4051e6f4e58SSimon Glass if (pch_is_wpt(dev) || val >= 0x0b)
4061e6f4e58SSimon Glass setbits_le32(RCB_REG(0x2614), 1 << 26);
4071e6f4e58SSimon Glass
4081e6f4e58SSimon Glass setbits_le32(RCB_REG(0x900), 0x0000031f);
4091e6f4e58SSimon Glass
4101e6f4e58SSimon Glass reg32 = readl(RCB_REG(CG));
4111e6f4e58SSimon Glass if (readl(RCB_REG(0x3454)) & (1 << 4))
4121e6f4e58SSimon Glass reg32 &= ~(1 << 29); /* LPC Dynamic */
4131e6f4e58SSimon Glass else
4141e6f4e58SSimon Glass reg32 |= (1 << 29); /* LPC Dynamic */
4151e6f4e58SSimon Glass reg32 |= 1 << 31; /* LP LPC */
4161e6f4e58SSimon Glass reg32 |= 1 << 30; /* LP BLA */
4171e6f4e58SSimon Glass if (readl(RCB_REG(0x3454)) & (1 << 4))
4181e6f4e58SSimon Glass reg32 &= ~(1 << 29);
4191e6f4e58SSimon Glass else
4201e6f4e58SSimon Glass reg32 |= 1 << 29;
4211e6f4e58SSimon Glass reg32 |= 1 << 28; /* GPIO Dynamic */
4221e6f4e58SSimon Glass reg32 |= 1 << 27; /* HPET Dynamic */
4231e6f4e58SSimon Glass reg32 |= 1 << 26; /* Generic Platform Event Clock */
4241e6f4e58SSimon Glass if (readl(RCB_REG(BUC)) & PCH_DISABLE_GBE)
4251e6f4e58SSimon Glass reg32 |= 1 << 23; /* GbE Static */
4261e6f4e58SSimon Glass if (readl(RCB_REG(FD)) & PCH_DISABLE_HD_AUDIO)
4271e6f4e58SSimon Glass reg32 |= 1 << 21; /* HDA Static */
4281e6f4e58SSimon Glass reg32 |= 1 << 22; /* HDA Dynamic */
4291e6f4e58SSimon Glass writel(reg32, RCB_REG(CG));
4301e6f4e58SSimon Glass
4311e6f4e58SSimon Glass /* PCH-LP LPC */
4321e6f4e58SSimon Glass if (pch_is_wpt(dev))
4331e6f4e58SSimon Glass clrsetbits_le32(RCB_REG(0x3434), 0x1f, 0x17);
4341e6f4e58SSimon Glass else
4351e6f4e58SSimon Glass setbits_le32(RCB_REG(0x3434), 0x7);
4361e6f4e58SSimon Glass
4371e6f4e58SSimon Glass /* SPI */
4381e6f4e58SSimon Glass setbits_le32(RCB_REG(0x38c0), 0x3c07);
4391e6f4e58SSimon Glass
4401e6f4e58SSimon Glass pch_iobp_update(0xCE00C000, ~1UL, 0x00000000);
4411e6f4e58SSimon Glass }
4421e6f4e58SSimon Glass
systemagent_init(void)4431e6f4e58SSimon Glass static void systemagent_init(void)
4441e6f4e58SSimon Glass {
4451e6f4e58SSimon Glass /* Enable Power Aware Interrupt Routing */
4461e6f4e58SSimon Glass clrsetbits_8(MCHBAR_REG(MCH_PAIR), 0x7, 0x4); /* Fixed Priority */
4471e6f4e58SSimon Glass
4481e6f4e58SSimon Glass /*
4491e6f4e58SSimon Glass * Set bits 0+1 of BIOS_RESET_CPL to indicate to the CPU
4501e6f4e58SSimon Glass * that BIOS has initialized memory and power management
4511e6f4e58SSimon Glass */
4521e6f4e58SSimon Glass setbits_8(MCHBAR_REG(BIOS_RESET_CPL), 3);
4531e6f4e58SSimon Glass debug("Set BIOS_RESET_CPL\n");
4541e6f4e58SSimon Glass
4551e6f4e58SSimon Glass /* Configure turbo power limits 1ms after reset complete bit */
4561e6f4e58SSimon Glass mdelay(1);
4571e6f4e58SSimon Glass
4581e6f4e58SSimon Glass cpu_set_power_limits(28);
4591e6f4e58SSimon Glass }
4601e6f4e58SSimon Glass
461*3f3411ebSSimon Glass /* Enable LTR Auto Mode for D21:F1-F6 */
serialio_d21_ltr(u32 bar0)462*3f3411ebSSimon Glass static void serialio_d21_ltr(u32 bar0)
463*3f3411ebSSimon Glass {
464*3f3411ebSSimon Glass /* 1. Program BAR0 + 808h[2] = 0b */
465*3f3411ebSSimon Glass clrbits_le32(bar0 + SIO_REG_PPR_GEN, SIO_REG_PPR_GEN_LTR_MODE_MASK);
466*3f3411ebSSimon Glass
467*3f3411ebSSimon Glass /* 2. Program BAR0 + 804h[1:0] = 00b */
468*3f3411ebSSimon Glass clrbits_le32(bar0 + SIO_REG_PPR_RST, SIO_REG_PPR_RST_ASSERT);
469*3f3411ebSSimon Glass
470*3f3411ebSSimon Glass /* 3. Program BAR0 + 804h[1:0] = 11b */
471*3f3411ebSSimon Glass setbits_le32(bar0 + SIO_REG_PPR_RST, SIO_REG_PPR_RST_ASSERT);
472*3f3411ebSSimon Glass
473*3f3411ebSSimon Glass /* 4. Program BAR0 + 814h[31:0] = 00000000h */
474*3f3411ebSSimon Glass writel(0, bar0 + SIO_REG_AUTO_LTR);
475*3f3411ebSSimon Glass }
476*3f3411ebSSimon Glass
477*3f3411ebSSimon Glass /* Select I2C voltage of 1.8V or 3.3V */
serialio_i2c_voltage_sel(u32 bar0,uint voltage)478*3f3411ebSSimon Glass static void serialio_i2c_voltage_sel(u32 bar0, uint voltage)
479*3f3411ebSSimon Glass {
480*3f3411ebSSimon Glass clrsetbits_le32(bar0 + SIO_REG_PPR_GEN, SIO_REG_PPR_GEN_VOLTAGE_MASK,
481*3f3411ebSSimon Glass SIO_REG_PPR_GEN_VOLTAGE(voltage));
482*3f3411ebSSimon Glass }
483*3f3411ebSSimon Glass
484*3f3411ebSSimon Glass /* Put Serial IO D21:F0-F6 device into desired mode */
serialio_d21_mode(int sio_index,int int_pin,bool acpi_mode)485*3f3411ebSSimon Glass static void serialio_d21_mode(int sio_index, int int_pin, bool acpi_mode)
486*3f3411ebSSimon Glass {
487*3f3411ebSSimon Glass u32 portctrl = SIO_IOBP_PORTCTRL_PM_CAP_PRSNT;
488*3f3411ebSSimon Glass
489*3f3411ebSSimon Glass /* Snoop select 1 */
490*3f3411ebSSimon Glass portctrl |= SIO_IOBP_PORTCTRL_SNOOP_SELECT(1);
491*3f3411ebSSimon Glass
492*3f3411ebSSimon Glass /* Set interrupt pin */
493*3f3411ebSSimon Glass portctrl |= SIO_IOBP_PORTCTRL_INT_PIN(int_pin);
494*3f3411ebSSimon Glass
495*3f3411ebSSimon Glass if (acpi_mode) {
496*3f3411ebSSimon Glass /* Enable ACPI interrupt mode */
497*3f3411ebSSimon Glass portctrl |= SIO_IOBP_PORTCTRL_ACPI_IRQ_EN;
498*3f3411ebSSimon Glass }
499*3f3411ebSSimon Glass
500*3f3411ebSSimon Glass pch_iobp_update(SIO_IOBP_PORTCTRLX(sio_index), 0, portctrl);
501*3f3411ebSSimon Glass }
502*3f3411ebSSimon Glass
503*3f3411ebSSimon Glass /* Init sequence to be run once, done as part of D21:F0 (SDMA) init */
serialio_init_once(bool acpi_mode)504*3f3411ebSSimon Glass static void serialio_init_once(bool acpi_mode)
505*3f3411ebSSimon Glass {
506*3f3411ebSSimon Glass if (acpi_mode) {
507*3f3411ebSSimon Glass /* Enable ACPI IRQ for IRQ13, IRQ7, IRQ6, IRQ5 in RCBA */
508*3f3411ebSSimon Glass setbits_le32(RCB_REG(ACPIIRQEN),
509*3f3411ebSSimon Glass 1 << 13 | 1 << 7 | 1 << 6 | 1 << 5);
510*3f3411ebSSimon Glass }
511*3f3411ebSSimon Glass
512*3f3411ebSSimon Glass /* Program IOBP CB000154h[12,9:8,4:0] = 1001100011111b */
513*3f3411ebSSimon Glass pch_iobp_update(SIO_IOBP_GPIODF, ~0x0000131f, 0x0000131f);
514*3f3411ebSSimon Glass
515*3f3411ebSSimon Glass /* Program IOBP CB000180h[5:0] = 111111b (undefined register) */
516*3f3411ebSSimon Glass pch_iobp_update(0xcb000180, ~0x0000003f, 0x0000003f);
517*3f3411ebSSimon Glass }
518*3f3411ebSSimon Glass
519*3f3411ebSSimon Glass /**
520*3f3411ebSSimon Glass * pch_serialio_init() - set up serial I/O devices
521*3f3411ebSSimon Glass *
522*3f3411ebSSimon Glass * @return 0 if OK, -ve on error
523*3f3411ebSSimon Glass */
pch_serialio_init(void)524*3f3411ebSSimon Glass static int pch_serialio_init(void)
525*3f3411ebSSimon Glass {
526*3f3411ebSSimon Glass struct udevice *dev, *hda;
527*3f3411ebSSimon Glass bool acpi_mode = true;
528*3f3411ebSSimon Glass u32 bar0, bar1;
529*3f3411ebSSimon Glass int ret;
530*3f3411ebSSimon Glass
531*3f3411ebSSimon Glass ret = uclass_find_first_device(UCLASS_I2C, &dev);
532*3f3411ebSSimon Glass if (ret)
533*3f3411ebSSimon Glass return ret;
534*3f3411ebSSimon Glass bar0 = dm_pci_read_bar32(dev, 0);
535*3f3411ebSSimon Glass if (!bar0)
536*3f3411ebSSimon Glass return -EINVAL;
537*3f3411ebSSimon Glass bar1 = dm_pci_read_bar32(dev, 1);
538*3f3411ebSSimon Glass if (!bar1)
539*3f3411ebSSimon Glass return -EINVAL;
540*3f3411ebSSimon Glass
541*3f3411ebSSimon Glass serialio_init_once(acpi_mode);
542*3f3411ebSSimon Glass serialio_d21_mode(SIO_ID_SDMA, SIO_PIN_INTB, acpi_mode);
543*3f3411ebSSimon Glass
544*3f3411ebSSimon Glass serialio_d21_ltr(bar0);
545*3f3411ebSSimon Glass serialio_i2c_voltage_sel(bar0, 1); /* Select 1.8V always */
546*3f3411ebSSimon Glass serialio_d21_mode(SIO_ID_I2C0, SIO_PIN_INTC, acpi_mode);
547*3f3411ebSSimon Glass setbits_le32(bar1 + PCH_PCS, PCH_PCS_PS_D3HOT);
548*3f3411ebSSimon Glass
549*3f3411ebSSimon Glass clrbits_le32(bar1 + PCH_PCS, PCH_PCS_PS_D3HOT);
550*3f3411ebSSimon Glass
551*3f3411ebSSimon Glass setbits_le32(bar0 + SIO_REG_PPR_CLOCK, SIO_REG_PPR_CLOCK_EN);
552*3f3411ebSSimon Glass
553*3f3411ebSSimon Glass /* Manually find the High-definition audio, to turn it off */
554*3f3411ebSSimon Glass ret = dm_pci_bus_find_bdf(PCI_BDF(0, 0x1b, 0), &hda);
555*3f3411ebSSimon Glass if (ret)
556*3f3411ebSSimon Glass return -ENOENT;
557*3f3411ebSSimon Glass dm_pci_clrset_config8(hda, 0x43, 0, 0x6f);
558*3f3411ebSSimon Glass
559*3f3411ebSSimon Glass /* Route I/O buffers to ADSP function */
560*3f3411ebSSimon Glass dm_pci_clrset_config8(hda, 0x42, 0, 1 << 7 | 1 << 6);
561*3f3411ebSSimon Glass log_debug("HDA disabled, I/O buffers routed to ADSP\n");
562*3f3411ebSSimon Glass
563*3f3411ebSSimon Glass return 0;
564*3f3411ebSSimon Glass }
565*3f3411ebSSimon Glass
broadwell_pch_init(struct udevice * dev)5661e6f4e58SSimon Glass static int broadwell_pch_init(struct udevice *dev)
5671e6f4e58SSimon Glass {
5681e6f4e58SSimon Glass int ret;
5691e6f4e58SSimon Glass
5701e6f4e58SSimon Glass /* Enable upper 128 bytes of CMOS */
5711e6f4e58SSimon Glass setbits_le32(RCB_REG(RC), 1 << 2);
5721e6f4e58SSimon Glass
5731e6f4e58SSimon Glass /*
5741e6f4e58SSimon Glass * TODO: TCO timer halt - this hangs
5751e6f4e58SSimon Glass * setio_16(ACPI_BASE_ADDRESS + TCO1_CNT, TCO_TMR_HLT);
5761e6f4e58SSimon Glass */
5771e6f4e58SSimon Glass
5781e6f4e58SSimon Glass /* Disable unused device (always) */
5791e6f4e58SSimon Glass setbits_le32(RCB_REG(FD), PCH_DISABLE_ALWAYS);
5801e6f4e58SSimon Glass
5811e6f4e58SSimon Glass pch_misc_init(dev);
5821e6f4e58SSimon Glass
5831e6f4e58SSimon Glass /* Interrupt configuration */
5841e6f4e58SSimon Glass pch_enable_ioapic();
5851e6f4e58SSimon Glass
5861e6f4e58SSimon Glass /* Initialize power management */
5871e6f4e58SSimon Glass ret = pch_power_options(dev);
5881e6f4e58SSimon Glass if (ret)
5891e6f4e58SSimon Glass return ret;
5901e6f4e58SSimon Glass pch_pm_init(dev);
5911e6f4e58SSimon Glass pch_cg_init(dev);
592*3f3411ebSSimon Glass ret = pch_serialio_init();
593*3f3411ebSSimon Glass if (ret)
594*3f3411ebSSimon Glass return ret;
5951e6f4e58SSimon Glass systemagent_init();
5961e6f4e58SSimon Glass
5971e6f4e58SSimon Glass return 0;
5981e6f4e58SSimon Glass }
5991e6f4e58SSimon Glass
broadwell_pch_probe(struct udevice * dev)6001e6f4e58SSimon Glass static int broadwell_pch_probe(struct udevice *dev)
6011e6f4e58SSimon Glass {
6021e6f4e58SSimon Glass if (!(gd->flags & GD_FLG_RELOC))
6031e6f4e58SSimon Glass return broadwell_pch_early_init(dev);
6041e6f4e58SSimon Glass else
6051e6f4e58SSimon Glass return broadwell_pch_init(dev);
6061e6f4e58SSimon Glass }
6071e6f4e58SSimon Glass
broadwell_pch_get_spi_base(struct udevice * dev,ulong * sbasep)6081e6f4e58SSimon Glass static int broadwell_pch_get_spi_base(struct udevice *dev, ulong *sbasep)
6091e6f4e58SSimon Glass {
6101e6f4e58SSimon Glass u32 rcba;
6111e6f4e58SSimon Glass
6121e6f4e58SSimon Glass dm_pci_read_config32(dev, PCH_RCBA, &rcba);
6131e6f4e58SSimon Glass /* Bits 31-14 are the base address, 13-1 are reserved, 0 is enable */
6141e6f4e58SSimon Glass rcba = rcba & 0xffffc000;
6151e6f4e58SSimon Glass *sbasep = rcba + 0x3800;
6161e6f4e58SSimon Glass
6171e6f4e58SSimon Glass return 0;
6181e6f4e58SSimon Glass }
6191e6f4e58SSimon Glass
broadwell_set_spi_protect(struct udevice * dev,bool protect)6201e6f4e58SSimon Glass static int broadwell_set_spi_protect(struct udevice *dev, bool protect)
6211e6f4e58SSimon Glass {
6221e6f4e58SSimon Glass return lpc_set_spi_protect(dev, BIOS_CTRL, protect);
6231e6f4e58SSimon Glass }
6241e6f4e58SSimon Glass
broadwell_get_gpio_base(struct udevice * dev,u32 * gbasep)6251e6f4e58SSimon Glass static int broadwell_get_gpio_base(struct udevice *dev, u32 *gbasep)
6261e6f4e58SSimon Glass {
6271e6f4e58SSimon Glass dm_pci_read_config32(dev, GPIO_BASE, gbasep);
6281e6f4e58SSimon Glass *gbasep &= PCI_BASE_ADDRESS_IO_MASK;
6291e6f4e58SSimon Glass
6301e6f4e58SSimon Glass return 0;
6311e6f4e58SSimon Glass }
6321e6f4e58SSimon Glass
6331e6f4e58SSimon Glass static const struct pch_ops broadwell_pch_ops = {
6341e6f4e58SSimon Glass .get_spi_base = broadwell_pch_get_spi_base,
6351e6f4e58SSimon Glass .set_spi_protect = broadwell_set_spi_protect,
6361e6f4e58SSimon Glass .get_gpio_base = broadwell_get_gpio_base,
6371e6f4e58SSimon Glass };
6381e6f4e58SSimon Glass
6391e6f4e58SSimon Glass static const struct udevice_id broadwell_pch_ids[] = {
6401e6f4e58SSimon Glass { .compatible = "intel,broadwell-pch" },
6411e6f4e58SSimon Glass { }
6421e6f4e58SSimon Glass };
6431e6f4e58SSimon Glass
6441e6f4e58SSimon Glass U_BOOT_DRIVER(broadwell_pch) = {
6451e6f4e58SSimon Glass .name = "broadwell_pch",
6461e6f4e58SSimon Glass .id = UCLASS_PCH,
6471e6f4e58SSimon Glass .of_match = broadwell_pch_ids,
6481e6f4e58SSimon Glass .probe = broadwell_pch_probe,
6491e6f4e58SSimon Glass .ops = &broadwell_pch_ops,
6501e6f4e58SSimon Glass };
651