blob: 2adcf4b242c5a37e94b298566cc3512dd8cac95a [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0
Simon Glass71606de2016-03-11 22:07:18 -07002/*
3 * Copyright (c) 2016 Google, Inc
4 *
Simon Glass71606de2016-03-11 22:07:18 -07005 * Based on code from coreboot src/soc/intel/broadwell/cpu.c
6 */
7
8#include <common.h>
9#include <dm.h>
10#include <cpu.h>
Simon Glassfc557362022-03-04 08:43:05 -070011#include <event.h>
Simon Glass97589732020-05-10 11:40:02 -060012#include <init.h>
Simon Glass0f2af882020-05-10 11:40:05 -060013#include <log.h>
Simon Glass71606de2016-03-11 22:07:18 -070014#include <asm/cpu.h>
15#include <asm/cpu_x86.h>
16#include <asm/cpu_common.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060017#include <asm/global_data.h>
Simon Glass71606de2016-03-11 22:07:18 -070018#include <asm/intel_regs.h>
Simon Glass412f11b2019-04-25 21:58:50 -060019#include <asm/lpc_common.h>
Simon Glass71606de2016-03-11 22:07:18 -070020#include <asm/msr.h>
Simon Glass412f11b2019-04-25 21:58:50 -060021#include <asm/pci.h>
Simon Glass71606de2016-03-11 22:07:18 -070022#include <asm/post.h>
23#include <asm/turbo.h>
24#include <asm/arch/cpu.h>
25#include <asm/arch/pch.h>
26#include <asm/arch/rcb.h>
27
Simon Glassfc557362022-03-04 08:43:05 -070028static int broadwell_init_cpu(void *ctx, struct event *event)
Simon Glass71606de2016-03-11 22:07:18 -070029{
30 struct udevice *dev;
31 int ret;
32
33 /* Start up the LPC so we have serial */
34 ret = uclass_first_device(UCLASS_LPC, &dev);
35 if (ret)
36 return ret;
37 if (!dev)
38 return -ENODEV;
39 ret = cpu_set_flex_ratio_to_tdp_nominal();
40 if (ret)
41 return ret;
42
43 return 0;
44}
Simon Glassfc557362022-03-04 08:43:05 -070045EVENT_SPY(EVT_DM_POST_INIT, broadwell_init_cpu);
Simon Glass71606de2016-03-11 22:07:18 -070046
47void set_max_freq(void)
48{
Simon Glassb12689d2019-09-25 08:56:38 -060049 msr_t msr, perf_ctl;
Simon Glass71606de2016-03-11 22:07:18 -070050
Simon Glassb12689d2019-09-25 08:56:38 -060051 if (cpu_config_tdp_levels()) {
Simon Glass71606de2016-03-11 22:07:18 -070052 /* Set to nominal TDP ratio */
53 msr = msr_read(MSR_CONFIG_TDP_NOMINAL);
54 perf_ctl.lo = (msr.lo & 0xff) << 8;
55 } else {
56 /* Platform Info bits 15:8 give max ratio */
57 msr = msr_read(MSR_PLATFORM_INFO);
58 perf_ctl.lo = msr.lo & 0xff00;
59 }
60
61 perf_ctl.hi = 0;
Simon Glass76ae0272019-09-25 08:56:35 -060062 msr_write(MSR_IA32_PERF_CTL, perf_ctl);
Simon Glass71606de2016-03-11 22:07:18 -070063
64 debug("CPU: frequency set to %d MHz\n",
Simon Glass4347d832019-09-25 08:56:37 -060065 ((perf_ctl.lo >> 8) & 0xff) * INTEL_BCLK_MHZ);
Simon Glass71606de2016-03-11 22:07:18 -070066}
67
68int arch_cpu_init(void)
69{
70 post_code(POST_CPU_INIT);
71
Simon Glass42bf3b92019-09-25 08:11:40 -060072#ifdef CONFIG_TPL
73 /* Do a mini-init if TPL has already done the full init */
74 return x86_cpu_reinit_f();
75#else
Simon Glass71606de2016-03-11 22:07:18 -070076 return x86_cpu_init_f();
Simon Glass42bf3b92019-09-25 08:11:40 -060077#endif
Simon Glass71606de2016-03-11 22:07:18 -070078}
79
Simon Glassee7c36f2017-03-28 10:27:30 -060080int checkcpu(void)
Simon Glass71606de2016-03-11 22:07:18 -070081{
Simon Glass71606de2016-03-11 22:07:18 -070082 int ret;
83
84 set_max_freq();
85
86 ret = cpu_common_init();
87 if (ret)
88 return ret;
89 gd->arch.pei_boot_mode = PEI_BOOT_NONE;
90
Simon Glassee7c36f2017-03-28 10:27:30 -060091 return 0;
92}
93
94int print_cpuinfo(void)
95{
96 char processor_name[CPU_MAX_NAME_LEN];
97 const char *name;
98
Simon Glass71606de2016-03-11 22:07:18 -070099 /* Print processor name */
100 name = cpu_get_name(processor_name);
101 printf("CPU: %s\n", name);
102
103 return 0;
104}
105
Simon Glass412f11b2019-04-25 21:58:50 -0600106void board_debug_uart_init(void)
107{
Simon Glass412f11b2019-04-25 21:58:50 -0600108 /* com1 / com2 decode range */
Simon Glassa5464582019-08-31 21:23:18 -0600109 pci_x86_write_config(PCH_DEV_LPC, LPC_IO_DEC, 1 << 4, PCI_SIZE_16);
Simon Glass412f11b2019-04-25 21:58:50 -0600110
Simon Glassa5464582019-08-31 21:23:18 -0600111 pci_x86_write_config(PCH_DEV_LPC, LPC_EN, COMA_LPC_EN, PCI_SIZE_16);
Simon Glass412f11b2019-04-25 21:58:50 -0600112}