blob: 6a883c6a2642f1d019821dd4dce3e93d6e7c2ba7 [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
Kyösti Mälkkibdaec072019-03-02 23:18:29 +020016#include <arch/io.h>
Mario Scheithauer58bf3e72018-10-30 09:57:44 +010017#include <bootstate.h>
Mario Scheithauer04ea73e2018-11-07 12:58:28 +010018#include <cf9_reset.h>
Mario Scheithauer58bf3e72018-10-30 09:57:44 +010019#include <console/console.h>
Mario Scheithauerd985cdc2018-11-07 08:50:45 +010020#include <device/pci_def.h>
Mario Scheithauer58bf3e72018-10-30 09:57:44 +010021#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>
Elyes HAOUASe39db682019-05-15 21:12:31 +020031#include <types.h>
Mario Scheithauer58bf3e72018-10-30 09:57:44 +010032
33#define TX_DWORD3 0xa8c
34
35void variant_mainboard_final(void)
36{
37 struct device *dev = NULL;
Mario Scheithauerd985cdc2018-11-07 08:50:45 +010038 uint16_t cmd = 0;
Mario Scheithauer58bf3e72018-10-30 09:57:44 +010039
Mario Scheithauer98689df2018-11-06 14:59:11 +010040 /* PIR6 register mapping for PCIe root ports
41 * INTA#->PIRQD#, INTB#->PIRQA#, INTC#->PIRQB#, INTD#-> PIRQC#
Mario Scheithauer58bf3e72018-10-30 09:57:44 +010042 */
Mario Scheithauer98689df2018-11-06 14:59:11 +010043 pcr_write16(PID_ITSS, 0x314c, 0x2103);
Mario Scheithauer58bf3e72018-10-30 09:57:44 +010044
Mario Scheithauer58bf3e72018-10-30 09:57:44 +010045 /* 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));
Mario Scheithauerd985cdc2018-11-07 08:50:45 +010055
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);
Mario Scheithauer49468042018-11-08 13:49:24 +010062
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);
Mario Scheithauerd985cdc2018-11-07 08:50:45 +010079 }
Mario Scheithauer04ea73e2018-11-07 12:58:28 +010080
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);
Mario Scheithauer58bf3e72018-10-30 09:57:44 +010087}
88
89static 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
114static void finalize_boot(void *unused)
115{
116 /* Set coreboot ready LED. */
117 gpio_output(CNV_RGI_DT, 1);
118}
119
120BOOT_STATE_INIT_ENTRY(BS_DEV_ENUMERATE, BS_ON_ENTRY, wait_for_legacy_dev, NULL);
121BOOT_STATE_INIT_ENTRY(BS_PAYLOAD_BOOT, BS_ON_ENTRY, finalize_boot, NULL);