blob: 3a87a4f5c562054d5d6553a1030577f67ff7ffe1 [file] [log] [blame]
Mario Scheithauer58bf3e72018-10-30 09:57:44 +01001/*
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>
Mario Scheithauer04ea73e2018-11-07 12:58:28 +010017#include <cf9_reset.h>
Mario Scheithauer58bf3e72018-10-30 09:57:44 +010018#include <console/console.h>
Mario Scheithauerd985cdc2018-11-07 08:50:45 +010019#include <device/pci_def.h>
Mario Scheithauer58bf3e72018-10-30 09:57:44 +010020#include <device/pci_ids.h>
21#include <device/pci_ops.h>
22#include <gpio.h>
23#include <hwilib.h>
24#include <intelblocks/lpc_lib.h>
25#include <intelblocks/pcr.h>
26#include <soc/pcr_ids.h>
27#include <timer.h>
28#include <timestamp.h>
29#include <baseboard/variants.h>
30
31#define TX_DWORD3 0xa8c
32
33void variant_mainboard_final(void)
34{
35 struct device *dev = NULL;
Mario Scheithauerd985cdc2018-11-07 08:50:45 +010036 uint16_t cmd = 0;
Mario Scheithauer58bf3e72018-10-30 09:57:44 +010037
Mario Scheithauer98689df2018-11-06 14:59:11 +010038 /* PIR6 register mapping for PCIe root ports
39 * INTA#->PIRQD#, INTB#->PIRQA#, INTC#->PIRQB#, INTD#-> PIRQC#
Mario Scheithauer58bf3e72018-10-30 09:57:44 +010040 */
Mario Scheithauer98689df2018-11-06 14:59:11 +010041 pcr_write16(PID_ITSS, 0x314c, 0x2103);
Mario Scheithauer58bf3e72018-10-30 09:57:44 +010042
43 /* Disable clock outputs 1-5 (CLKOUT) for XIO2001 PCIe to PCI Bridge. */
44 dev = dev_find_device(PCI_VENDOR_ID_TI, PCI_DEVICE_ID_TI_XIO2001, 0);
45 if (dev)
46 pci_write_config8(dev, 0xd8, 0x3e);
47
48 /* Enable CLKRUN_EN for power gating LPC */
49 lpc_enable_pci_clk_cntl();
50
51 /*
52 * Enable LPC PCE (Power Control Enable) by setting IOSF-SB port 0xD2
53 * offset 0x341D bit3 and bit0.
54 * Enable LPC CCE (Clock Control Enable) by setting IOSF-SB port 0xD2
55 * offset 0x341C bit [3:0].
56 */
57 pcr_or32(PID_LPC, PCR_LPC_PRC, (PCR_LPC_CCE_EN | PCR_LPC_PCE_EN));
Mario Scheithauerd985cdc2018-11-07 08:50:45 +010058
59 /* Set Master Enable for on-board PCI device. */
60 dev = dev_find_device(PCI_VENDOR_ID_SIEMENS, 0x403e, 0);
61 if (dev) {
62 cmd = pci_read_config16(dev, PCI_COMMAND);
63 cmd |= PCI_COMMAND_MASTER;
64 pci_write_config16(dev, PCI_COMMAND, cmd);
65 }
Mario Scheithauer04ea73e2018-11-07 12:58:28 +010066
67 /* Set Full Reset Bit in Reset Control Register (I/O port CF9h).
68 * When Bit 3 is set to 1 and then the reset button is pressed the PCH
69 * will drive SLP_S3 active (low). SLP_S3 is then used on the mainboard
70 * to generate the right reset timing.
71 */
72 outb(FULL_RST, RST_CNT);
Mario Scheithauer58bf3e72018-10-30 09:57:44 +010073}
74
75static void wait_for_legacy_dev(void *unused)
76{
77 uint32_t legacy_delay, us_since_boot;
78 struct stopwatch sw;
79
80 /* Open main hwinfo block. */
81 if (hwilib_find_blocks("hwinfo.hex") != CB_SUCCESS)
82 return;
83
84 /* Get legacy delay parameter from hwinfo. */
85 if (hwilib_get_field(LegacyDelay, (uint8_t *) &legacy_delay,
86 sizeof(legacy_delay)) != sizeof(legacy_delay))
87 return;
88
89 us_since_boot = get_us_since_boot();
90 /* No need to wait if the time since boot is already long enough.*/
91 if (us_since_boot > legacy_delay)
92 return;
93 stopwatch_init_msecs_expire(&sw, (legacy_delay - us_since_boot) / 1000);
94 printk(BIOS_NOTICE, "Wait remaining %d of %d us for legacy devices...",
95 legacy_delay - us_since_boot, legacy_delay);
96 stopwatch_wait_until_expired(&sw);
97 printk(BIOS_NOTICE, "done!\n");
98}
99
100static void finalize_boot(void *unused)
101{
102 /* Set coreboot ready LED. */
103 gpio_output(CNV_RGI_DT, 1);
104}
105
106BOOT_STATE_INIT_ENTRY(BS_DEV_ENUMERATE, BS_ON_ENTRY, wait_for_legacy_dev, NULL);
107BOOT_STATE_INIT_ENTRY(BS_PAYLOAD_BOOT, BS_ON_ENTRY, finalize_boot, NULL);