blob: f41fe732f34445ee012e02582c5f66187c125cbe [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>
17#include <console/console.h>
Mario Scheithauerd985cdc2018-11-07 08:50:45 +010018#include <device/pci_def.h>
Mario Scheithauer58bf3e72018-10-30 09:57:44 +010019#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
32void variant_mainboard_final(void)
33{
34 struct device *dev = NULL;
Mario Scheithauerd985cdc2018-11-07 08:50:45 +010035 uint16_t cmd = 0;
Mario Scheithauer58bf3e72018-10-30 09:57:44 +010036
Mario Scheithauer98689df2018-11-06 14:59:11 +010037 /* PIR6 register mapping for PCIe root ports
38 * INTA#->PIRQD#, INTB#->PIRQA#, INTC#->PIRQB#, INTD#-> PIRQC#
Mario Scheithauer58bf3e72018-10-30 09:57:44 +010039 */
Mario Scheithauer98689df2018-11-06 14:59:11 +010040 pcr_write16(PID_ITSS, 0x314c, 0x2103);
Mario Scheithauer58bf3e72018-10-30 09:57:44 +010041
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 Scheithauerd985cdc2018-11-07 08:50:45 +010057
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 Scheithauer58bf3e72018-10-30 09:57:44 +010065}
66
67static 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
92static void finalize_boot(void *unused)
93{
94 /* Set coreboot ready LED. */
95 gpio_output(CNV_RGI_DT, 1);
96}
97
98BOOT_STATE_INIT_ENTRY(BS_DEV_ENUMERATE, BS_ON_ENTRY, wait_for_legacy_dev, NULL);
99BOOT_STATE_INIT_ENTRY(BS_PAYLOAD_BOOT, BS_ON_ENTRY, finalize_boot, NULL);