Mario Scheithauer | 58bf3e7 | 2018-10-30 09:57:44 +0100 | [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 <bootstate.h> |
| 17 | #include <console/console.h> |
Mario Scheithauer | d985cdc | 2018-11-07 08:50:45 +0100 | [diff] [blame^] | 18 | #include <device/pci_def.h> |
Mario Scheithauer | 58bf3e7 | 2018-10-30 09:57:44 +0100 | [diff] [blame] | 19 | #include <device/pci_ids.h> |
| 20 | #include <device/pci_ops.h> |
| 21 | #include <gpio.h> |
| 22 | #include <hwilib.h> |
| 23 | #include <intelblocks/lpc_lib.h> |
| 24 | #include <intelblocks/pcr.h> |
| 25 | #include <soc/pcr_ids.h> |
| 26 | #include <timer.h> |
| 27 | #include <timestamp.h> |
| 28 | #include <baseboard/variants.h> |
| 29 | |
| 30 | #define TX_DWORD3 0xa8c |
| 31 | |
| 32 | void variant_mainboard_final(void) |
| 33 | { |
| 34 | struct device *dev = NULL; |
Mario Scheithauer | d985cdc | 2018-11-07 08:50:45 +0100 | [diff] [blame^] | 35 | uint16_t cmd = 0; |
Mario Scheithauer | 58bf3e7 | 2018-10-30 09:57:44 +0100 | [diff] [blame] | 36 | |
Mario Scheithauer | 98689df | 2018-11-06 14:59:11 +0100 | [diff] [blame] | 37 | /* PIR6 register mapping for PCIe root ports |
| 38 | * INTA#->PIRQD#, INTB#->PIRQA#, INTC#->PIRQB#, INTD#-> PIRQC# |
Mario Scheithauer | 58bf3e7 | 2018-10-30 09:57:44 +0100 | [diff] [blame] | 39 | */ |
Mario Scheithauer | 98689df | 2018-11-06 14:59:11 +0100 | [diff] [blame] | 40 | pcr_write16(PID_ITSS, 0x314c, 0x2103); |
Mario Scheithauer | 58bf3e7 | 2018-10-30 09:57:44 +0100 | [diff] [blame] | 41 | |
| 42 | /* Disable clock outputs 1-5 (CLKOUT) for XIO2001 PCIe to PCI Bridge. */ |
| 43 | dev = dev_find_device(PCI_VENDOR_ID_TI, PCI_DEVICE_ID_TI_XIO2001, 0); |
| 44 | if (dev) |
| 45 | pci_write_config8(dev, 0xd8, 0x3e); |
| 46 | |
| 47 | /* Enable CLKRUN_EN for power gating LPC */ |
| 48 | lpc_enable_pci_clk_cntl(); |
| 49 | |
| 50 | /* |
| 51 | * Enable LPC PCE (Power Control Enable) by setting IOSF-SB port 0xD2 |
| 52 | * offset 0x341D bit3 and bit0. |
| 53 | * Enable LPC CCE (Clock Control Enable) by setting IOSF-SB port 0xD2 |
| 54 | * offset 0x341C bit [3:0]. |
| 55 | */ |
| 56 | pcr_or32(PID_LPC, PCR_LPC_PRC, (PCR_LPC_CCE_EN | PCR_LPC_PCE_EN)); |
Mario Scheithauer | d985cdc | 2018-11-07 08:50:45 +0100 | [diff] [blame^] | 57 | |
| 58 | /* Set Master Enable for on-board PCI device. */ |
| 59 | dev = dev_find_device(PCI_VENDOR_ID_SIEMENS, 0x403e, 0); |
| 60 | if (dev) { |
| 61 | cmd = pci_read_config16(dev, PCI_COMMAND); |
| 62 | cmd |= PCI_COMMAND_MASTER; |
| 63 | pci_write_config16(dev, PCI_COMMAND, cmd); |
| 64 | } |
Mario Scheithauer | 58bf3e7 | 2018-10-30 09:57:44 +0100 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | static void wait_for_legacy_dev(void *unused) |
| 68 | { |
| 69 | uint32_t legacy_delay, us_since_boot; |
| 70 | struct stopwatch sw; |
| 71 | |
| 72 | /* Open main hwinfo block. */ |
| 73 | if (hwilib_find_blocks("hwinfo.hex") != CB_SUCCESS) |
| 74 | return; |
| 75 | |
| 76 | /* Get legacy delay parameter from hwinfo. */ |
| 77 | if (hwilib_get_field(LegacyDelay, (uint8_t *) &legacy_delay, |
| 78 | sizeof(legacy_delay)) != sizeof(legacy_delay)) |
| 79 | return; |
| 80 | |
| 81 | us_since_boot = get_us_since_boot(); |
| 82 | /* No need to wait if the time since boot is already long enough.*/ |
| 83 | if (us_since_boot > legacy_delay) |
| 84 | return; |
| 85 | stopwatch_init_msecs_expire(&sw, (legacy_delay - us_since_boot) / 1000); |
| 86 | printk(BIOS_NOTICE, "Wait remaining %d of %d us for legacy devices...", |
| 87 | legacy_delay - us_since_boot, legacy_delay); |
| 88 | stopwatch_wait_until_expired(&sw); |
| 89 | printk(BIOS_NOTICE, "done!\n"); |
| 90 | } |
| 91 | |
| 92 | static void finalize_boot(void *unused) |
| 93 | { |
| 94 | /* Set coreboot ready LED. */ |
| 95 | gpio_output(CNV_RGI_DT, 1); |
| 96 | } |
| 97 | |
| 98 | BOOT_STATE_INIT_ENTRY(BS_DEV_ENUMERATE, BS_ON_ENTRY, wait_for_legacy_dev, NULL); |
| 99 | BOOT_STATE_INIT_ENTRY(BS_PAYLOAD_BOOT, BS_ON_ENTRY, finalize_boot, NULL); |