Werner Zeh | 0dc87ef | 2019-10-22 15:08:19 +0200 | [diff] [blame^] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2018 Siemens AG |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; version 2 of the License. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | */ |
| 15 | |
| 16 | #include <arch/io.h> |
| 17 | #include <bootstate.h> |
| 18 | #include <cf9_reset.h> |
| 19 | #include <console/console.h> |
| 20 | #include <device/pci_def.h> |
| 21 | #include <device/pci_ids.h> |
| 22 | #include <device/pci_ops.h> |
| 23 | #include <gpio.h> |
| 24 | #include <hwilib.h> |
| 25 | #include <intelblocks/lpc_lib.h> |
| 26 | #include <intelblocks/pcr.h> |
| 27 | #include <soc/pcr_ids.h> |
| 28 | #include <timer.h> |
| 29 | #include <timestamp.h> |
| 30 | #include <baseboard/variants.h> |
| 31 | #include <types.h> |
| 32 | |
| 33 | #define TX_DWORD3 0xa8c |
| 34 | |
| 35 | void variant_mainboard_final(void) |
| 36 | { |
| 37 | struct device *dev = NULL; |
| 38 | uint16_t cmd = 0; |
| 39 | |
| 40 | /* PIR6 register mapping for PCIe root ports |
| 41 | * INTA#->PIRQD#, INTB#->PIRQA#, INTC#->PIRQB#, INTD#-> PIRQC# |
| 42 | */ |
| 43 | pcr_write16(PID_ITSS, 0x314c, 0x2103); |
| 44 | |
| 45 | /* Enable CLKRUN_EN for power gating LPC */ |
| 46 | lpc_enable_pci_clk_cntl(); |
| 47 | |
| 48 | /* |
| 49 | * Enable LPC PCE (Power Control Enable) by setting IOSF-SB port 0xD2 |
| 50 | * offset 0x341D bit3 and bit0. |
| 51 | * Enable LPC CCE (Clock Control Enable) by setting IOSF-SB port 0xD2 |
| 52 | * offset 0x341C bit [3:0]. |
| 53 | */ |
| 54 | pcr_or32(PID_LPC, PCR_LPC_PRC, (PCR_LPC_CCE_EN | PCR_LPC_PCE_EN)); |
| 55 | |
| 56 | /* Set Master Enable for on-board PCI device. */ |
| 57 | dev = dev_find_device(PCI_VENDOR_ID_SIEMENS, 0x403e, 0); |
| 58 | if (dev) { |
| 59 | cmd = pci_read_config16(dev, PCI_COMMAND); |
| 60 | cmd |= PCI_COMMAND_MASTER; |
| 61 | pci_write_config16(dev, PCI_COMMAND, cmd); |
| 62 | |
| 63 | /* Disable clock outputs 0 and 2-4 (CLKOUT) for upstream |
| 64 | * XIO2001 PCIe to PCI Bridge. |
| 65 | */ |
| 66 | struct device *parent = dev->bus->dev; |
| 67 | if (parent && parent->device == PCI_DEVICE_ID_TI_XIO2001) |
| 68 | pci_write_config8(parent, 0xd8, 0x1d); |
| 69 | } |
| 70 | |
| 71 | /* Disable clock outputs 2-5 (CLKOUT) for another XIO2001 PCIe to PCI |
| 72 | * Bridge on this mainboard. |
| 73 | */ |
| 74 | dev = dev_find_device(PCI_VENDOR_ID_SIEMENS, 0x403f, 0); |
| 75 | if (dev) { |
| 76 | struct device *parent = dev->bus->dev; |
| 77 | if (parent && parent->device == PCI_DEVICE_ID_TI_XIO2001) |
| 78 | pci_write_config8(parent, 0xd8, 0x3c); |
| 79 | } |
| 80 | |
| 81 | /* Set Full Reset Bit in Reset Control Register (I/O port CF9h). |
| 82 | * When Bit 3 is set to 1 and then the reset button is pressed the PCH |
| 83 | * will drive SLP_S3 active (low). SLP_S3 is then used on the mainboard |
| 84 | * to generate the right reset timing. |
| 85 | */ |
| 86 | outb(FULL_RST, RST_CNT); |
| 87 | } |
| 88 | |
| 89 | static void wait_for_legacy_dev(void *unused) |
| 90 | { |
| 91 | uint32_t legacy_delay, us_since_boot; |
| 92 | struct stopwatch sw; |
| 93 | |
| 94 | /* Open main hwinfo block. */ |
| 95 | if (hwilib_find_blocks("hwinfo.hex") != CB_SUCCESS) |
| 96 | return; |
| 97 | |
| 98 | /* Get legacy delay parameter from hwinfo. */ |
| 99 | if (hwilib_get_field(LegacyDelay, (uint8_t *) &legacy_delay, |
| 100 | sizeof(legacy_delay)) != sizeof(legacy_delay)) |
| 101 | return; |
| 102 | |
| 103 | us_since_boot = get_us_since_boot(); |
| 104 | /* No need to wait if the time since boot is already long enough.*/ |
| 105 | if (us_since_boot > legacy_delay) |
| 106 | return; |
| 107 | stopwatch_init_msecs_expire(&sw, (legacy_delay - us_since_boot) / 1000); |
| 108 | printk(BIOS_NOTICE, "Wait remaining %d of %d us for legacy devices...", |
| 109 | legacy_delay - us_since_boot, legacy_delay); |
| 110 | stopwatch_wait_until_expired(&sw); |
| 111 | printk(BIOS_NOTICE, "done!\n"); |
| 112 | } |
| 113 | |
| 114 | static void finalize_boot(void *unused) |
| 115 | { |
| 116 | /* Set coreboot ready LED. */ |
| 117 | gpio_output(CNV_RGI_DT, 1); |
| 118 | } |
| 119 | |
| 120 | BOOT_STATE_INIT_ENTRY(BS_DEV_ENUMERATE, BS_ON_ENTRY, wait_for_legacy_dev, NULL); |
| 121 | BOOT_STATE_INIT_ENTRY(BS_PAYLOAD_BOOT, BS_ON_ENTRY, finalize_boot, NULL); |