blob: 498b306cd6183cf96c37344ad17ca718b2ee52a6 [file] [log] [blame]
Simon Glassfcfd26e2019-12-08 17:40:14 -07001// SPDX-License-Identifier: GPL-2.0
2/*
3 * Copyright 2019 Google LLC
4 */
5
Simon Glassf07f4b92020-11-04 09:57:15 -07006#include <dm.h>
7#include <log.h>
Simon Glassfcfd26e2019-12-08 17:40:14 -07008#include <asm/cpu_common.h>
Simon Glass9cfd95b2021-03-15 18:00:31 +13009#include <asm/io.h>
Simon Glassfcfd26e2019-12-08 17:40:14 -070010#include <asm/msr.h>
Simon Glass9cfd95b2021-03-15 18:00:31 +130011#include <asm/pci.h>
Simon Glassf07f4b92020-11-04 09:57:15 -070012#include <asm/arch/cpu.h>
13#include <asm/arch/iomap.h>
Simon Glass9cfd95b2021-03-15 18:00:31 +130014#include <asm/arch/uart.h>
Simon Glassf07f4b92020-11-04 09:57:15 -070015#include <power/acpi_pmc.h>
Simon Glassfcfd26e2019-12-08 17:40:14 -070016
Simon Glass9cfd95b2021-03-15 18:00:31 +130017/* Define this here to avoid referencing any drivers for the debug UART 1 */
18#define PCH_DEV_P2SB PCI_BDF(0, 0x0d, 0)
19
Simon Glassfcfd26e2019-12-08 17:40:14 -070020void cpu_flush_l1d_to_l2(void)
21{
22 struct msr_t msr;
23
24 msr = msr_read(MSR_POWER_MISC);
25 msr.lo |= FLUSH_DL1_L2;
26 msr_write(MSR_POWER_MISC, msr);
27}
Simon Glassf07f4b92020-11-04 09:57:15 -070028
29void enable_pm_timer_emulation(const struct udevice *pmc)
30{
31 struct acpi_pmc_upriv *upriv = dev_get_uclass_priv(pmc);
32 msr_t msr;
33
34 /*
35 * The derived frequency is calculated as follows:
36 * (CTC_FREQ * msr[63:32]) >> 32 = target frequency.
37 *
38 * Back-solve the multiplier so the 3.579545MHz ACPI timer frequency is
39 * used.
40 */
41 msr.hi = (3579545ULL << 32) / CTC_FREQ;
42
43 /* Set PM1 timer IO port and enable */
44 msr.lo = EMULATE_PM_TMR_EN | (upriv->acpi_base + R_ACPI_PM1_TMR);
45 debug("PM timer %x %x\n", msr.hi, msr.lo);
46 msr_write(MSR_EMULATE_PM_TIMER, msr);
47}
Simon Glass9cfd95b2021-03-15 18:00:31 +130048
49static void pch_uart_init(void)
50{
51 /*
52 * Set up the pinmux so that the UART rx/tx signals are connected
53 * outside the SoC.
54 *
55 * There are about 500 lines of code required to program the GPIO
56 * configuration for the UARTs. But it boils down to four writes, and
57 * for the debug UART we want the minimum possible amount of code before
58 * the UART is running. So just add the magic writes here. See
59 * apl_hostbridge_early_init_pinctrl() for the full horror.
60 */
61 if (PCI_FUNC(PCH_DEV_UART) == 1) {
62 writel(0x40000402, 0xd0c50650);
63 writel(0x3c47, 0xd0c50654);
64 writel(0x40000400, 0xd0c50658);
65 writel(0x3c48, 0xd0c5065c);
66 } else { /* UART2 */
67 writel(0x40000402, 0xd0c50670);
68 writel(0x3c4b, 0xd0c50674);
69 writel(0x40000400, 0xd0c50678);
70 writel(0x3c4c, 0xd0c5067c);
71 }
72
73#ifdef CONFIG_DEBUG_UART
Pali Rohár8864b352022-05-27 22:15:24 +020074 apl_uart_init(PCH_DEV_UART, CONFIG_VAL(DEBUG_UART_BASE));
Simon Glass9cfd95b2021-03-15 18:00:31 +130075#endif
76}
77
78static void p2sb_enable_bar(ulong bar)
79{
80 /* Enable PCR Base address in PCH */
81 pci_x86_write_config(PCH_DEV_P2SB, PCI_BASE_ADDRESS_0, bar,
82 PCI_SIZE_32);
83 pci_x86_write_config(PCH_DEV_P2SB, PCI_BASE_ADDRESS_1, 0, PCI_SIZE_32);
84
85 /* Enable P2SB MSE */
86 pci_x86_write_config(PCH_DEV_P2SB, PCI_COMMAND,
87 PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY,
88 PCI_SIZE_8);
89}
90
91/*
92 * board_debug_uart_init() - Init the debug UART ready for use
93 *
94 * This is the minimum init needed to get the UART running. It avoids any
95 * drivers or complex code, so that the UART is running as soon as possible.
96 */
97void board_debug_uart_init(void)
98{
99 p2sb_enable_bar(IOMAP_P2SB_BAR);
100 pch_uart_init();
101}