Mario Scheithauer | 5716b4c | 2018-11-14 13:27:05 +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> |
| 18 | #include <device/pci_ids.h> |
| 19 | #include <device/pci_ops.h> |
| 20 | #include <gpio.h> |
| 21 | #include <hwilib.h> |
| 22 | #include <intelblocks/lpc_lib.h> |
| 23 | #include <intelblocks/pcr.h> |
| 24 | #include <soc/pcr_ids.h> |
| 25 | #include <timer.h> |
| 26 | #include <timestamp.h> |
| 27 | #include <baseboard/variants.h> |
| 28 | #include <variant/ptn3460.h> |
| 29 | |
| 30 | #define TX_DWORD3 0xa8c |
| 31 | |
| 32 | void variant_mainboard_final(void) |
| 33 | { |
| 34 | int status; |
| 35 | struct device *dev = NULL; |
| 36 | |
| 37 | /* |
| 38 | * Set up the DP2LVDS converter. |
| 39 | * ptn3460_init() may only be executed after i2c bus init. |
| 40 | */ |
| 41 | status = ptn3460_init("hwinfo.hex"); |
| 42 | if (status) |
| 43 | printk(BIOS_ERR, "LCD: Set up PTN with status 0x%x\n", status); |
| 44 | else |
| 45 | printk(BIOS_INFO, "LCD: Set up PTN was successful.\n"); |
| 46 | |
| 47 | /* |
| 48 | * PIR6 register mapping for PCIe root ports |
| 49 | * INTA#->PIRQB#, INTB#->PIRQC#, INTC#->PIRQD#, INTD#-> PIRQA# |
| 50 | */ |
| 51 | pcr_write16(PID_ITSS, 0x314c, 0x0321); |
| 52 | |
| 53 | /* Disable clock outputs 1-5 (CLKOUT) for XIO2001 PCIe to PCI Bridge. */ |
| 54 | dev = dev_find_device(PCI_VENDOR_ID_TI, PCI_DEVICE_ID_TI_XIO2001, 0); |
| 55 | if (dev) |
| 56 | pci_write_config8(dev, 0xd8, 0x3e); |
| 57 | |
| 58 | /* Enable CLKRUN_EN for power gating LPC */ |
| 59 | lpc_enable_pci_clk_cntl(); |
| 60 | |
| 61 | /* |
| 62 | * Enable LPC PCE (Power Control Enable) by setting IOSF-SB port 0xD2 |
| 63 | * offset 0x341D bit3 and bit0. |
| 64 | * Enable LPC CCE (Clock Control Enable) by setting IOSF-SB port 0xD2 |
| 65 | * offset 0x341C bit [3:0]. |
| 66 | */ |
| 67 | pcr_or32(PID_LPC, PCR_LPC_PRC, (PCR_LPC_CCE_EN | PCR_LPC_PCE_EN)); |
| 68 | |
| 69 | /* |
| 70 | * Correct the SATA transmit signal via the High Speed I/O Transmit |
| 71 | * Control Register 3. |
| 72 | * Bit [23:16] set the output voltage swing for TX line. |
| 73 | * The value 0x4a sets the swing level to 0.58 V. |
| 74 | */ |
| 75 | pcr_rmw32(PID_MODPHY, TX_DWORD3, (0x00 << 16), (0x4a << 16)); |
| 76 | } |
| 77 | |
| 78 | static void wait_for_legacy_dev(void *unused) |
| 79 | { |
| 80 | uint32_t legacy_delay, us_since_boot; |
| 81 | struct stopwatch sw; |
| 82 | |
| 83 | /* Open main hwinfo block. */ |
| 84 | if (hwilib_find_blocks("hwinfo.hex") != CB_SUCCESS) |
| 85 | return; |
| 86 | |
| 87 | /* Get legacy delay parameter from hwinfo. */ |
| 88 | if (hwilib_get_field(LegacyDelay, (uint8_t *) &legacy_delay, |
| 89 | sizeof(legacy_delay)) != sizeof(legacy_delay)) |
| 90 | return; |
| 91 | |
| 92 | us_since_boot = get_us_since_boot(); |
| 93 | /* No need to wait if the time since boot is already long enough.*/ |
| 94 | if (us_since_boot > legacy_delay) |
| 95 | return; |
| 96 | stopwatch_init_msecs_expire(&sw, (legacy_delay - us_since_boot) / 1000); |
| 97 | printk(BIOS_NOTICE, "Wait remaining %d of %d us for legacy devices...", |
| 98 | legacy_delay - us_since_boot, legacy_delay); |
| 99 | stopwatch_wait_until_expired(&sw); |
| 100 | printk(BIOS_NOTICE, "done!\n"); |
| 101 | } |
| 102 | |
| 103 | static void finalize_boot(void *unused) |
| 104 | { |
| 105 | /* Set coreboot ready LED. */ |
| 106 | gpio_output(CNV_RGI_DT, 1); |
| 107 | } |
| 108 | |
| 109 | BOOT_STATE_INIT_ENTRY(BS_DEV_ENUMERATE, BS_ON_ENTRY, wait_for_legacy_dev, NULL); |
| 110 | BOOT_STATE_INIT_ENTRY(BS_PAYLOAD_BOOT, BS_ON_ENTRY, finalize_boot, NULL); |