blob: 793167937cf25316b4dfd021f5dc92f6680829a8 [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 Glass97589732020-05-10 11:40:02 -060011#include <init.h>
Simon Glass71606de2016-03-11 22:07:18 -070012#include <asm/cpu.h>
13#include <asm/cpu_x86.h>
14#include <asm/cpu_common.h>
15#include <asm/intel_regs.h>
Simon Glass412f11b2019-04-25 21:58:50 -060016#include <asm/lpc_common.h>
Simon Glass71606de2016-03-11 22:07:18 -070017#include <asm/msr.h>
Simon Glass412f11b2019-04-25 21:58:50 -060018#include <asm/pci.h>
Simon Glass71606de2016-03-11 22:07:18 -070019#include <asm/post.h>
20#include <asm/turbo.h>
21#include <asm/arch/cpu.h>
22#include <asm/arch/pch.h>
23#include <asm/arch/rcb.h>
24
Simon Glass71606de2016-03-11 22:07:18 -070025int arch_cpu_init_dm(void)
26{
27 struct udevice *dev;
28 int ret;
29
30 /* Start up the LPC so we have serial */
31 ret = uclass_first_device(UCLASS_LPC, &dev);
32 if (ret)
33 return ret;
34 if (!dev)
35 return -ENODEV;
36 ret = cpu_set_flex_ratio_to_tdp_nominal();
37 if (ret)
38 return ret;
39
40 return 0;
41}
42
43void set_max_freq(void)
44{
Simon Glassb12689d2019-09-25 08:56:38 -060045 msr_t msr, perf_ctl;
Simon Glass71606de2016-03-11 22:07:18 -070046
Simon Glassb12689d2019-09-25 08:56:38 -060047 if (cpu_config_tdp_levels()) {
Simon Glass71606de2016-03-11 22:07:18 -070048 /* Set to nominal TDP ratio */
49 msr = msr_read(MSR_CONFIG_TDP_NOMINAL);
50 perf_ctl.lo = (msr.lo & 0xff) << 8;
51 } else {
52 /* Platform Info bits 15:8 give max ratio */
53 msr = msr_read(MSR_PLATFORM_INFO);
54 perf_ctl.lo = msr.lo & 0xff00;
55 }
56
57 perf_ctl.hi = 0;
Simon Glass76ae0272019-09-25 08:56:35 -060058 msr_write(MSR_IA32_PERF_CTL, perf_ctl);
Simon Glass71606de2016-03-11 22:07:18 -070059
60 debug("CPU: frequency set to %d MHz\n",
Simon Glass4347d832019-09-25 08:56:37 -060061 ((perf_ctl.lo >> 8) & 0xff) * INTEL_BCLK_MHZ);
Simon Glass71606de2016-03-11 22:07:18 -070062}
63
64int arch_cpu_init(void)
65{
66 post_code(POST_CPU_INIT);
67
Simon Glass42bf3b92019-09-25 08:11:40 -060068#ifdef CONFIG_TPL
69 /* Do a mini-init if TPL has already done the full init */
70 return x86_cpu_reinit_f();
71#else
Simon Glass71606de2016-03-11 22:07:18 -070072 return x86_cpu_init_f();
Simon Glass42bf3b92019-09-25 08:11:40 -060073#endif
Simon Glass71606de2016-03-11 22:07:18 -070074}
75
Simon Glassee7c36f2017-03-28 10:27:30 -060076int checkcpu(void)
Simon Glass71606de2016-03-11 22:07:18 -070077{
Simon Glass71606de2016-03-11 22:07:18 -070078 int ret;
79
80 set_max_freq();
81
82 ret = cpu_common_init();
83 if (ret)
84 return ret;
85 gd->arch.pei_boot_mode = PEI_BOOT_NONE;
86
Simon Glassee7c36f2017-03-28 10:27:30 -060087 return 0;
88}
89
90int print_cpuinfo(void)
91{
92 char processor_name[CPU_MAX_NAME_LEN];
93 const char *name;
94
Simon Glass71606de2016-03-11 22:07:18 -070095 /* Print processor name */
96 name = cpu_get_name(processor_name);
97 printf("CPU: %s\n", name);
98
99 return 0;
100}
101
Simon Glass412f11b2019-04-25 21:58:50 -0600102void board_debug_uart_init(void)
103{
Simon Glass412f11b2019-04-25 21:58:50 -0600104 /* com1 / com2 decode range */
Simon Glassa5464582019-08-31 21:23:18 -0600105 pci_x86_write_config(PCH_DEV_LPC, LPC_IO_DEC, 1 << 4, PCI_SIZE_16);
Simon Glass412f11b2019-04-25 21:58:50 -0600106
Simon Glassa5464582019-08-31 21:23:18 -0600107 pci_x86_write_config(PCH_DEV_LPC, LPC_EN, COMA_LPC_EN, PCI_SIZE_16);
Simon Glass412f11b2019-04-25 21:58:50 -0600108}