Merge tag 'u-boot-atmel-fixes-2020.07-a' of https://gitlab.denx.de/u-boot/custodians...
[oweals/u-boot.git] / arch / x86 / cpu / broadwell / cpu.c
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * Copyright (c) 2016 Google, Inc
4  *
5  * 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>
11 #include <init.h>
12 #include <log.h>
13 #include <asm/cpu.h>
14 #include <asm/cpu_x86.h>
15 #include <asm/cpu_common.h>
16 #include <asm/intel_regs.h>
17 #include <asm/lpc_common.h>
18 #include <asm/msr.h>
19 #include <asm/pci.h>
20 #include <asm/post.h>
21 #include <asm/turbo.h>
22 #include <asm/arch/cpu.h>
23 #include <asm/arch/pch.h>
24 #include <asm/arch/rcb.h>
25
26 int arch_cpu_init_dm(void)
27 {
28         struct udevice *dev;
29         int ret;
30
31         /* Start up the LPC so we have serial */
32         ret = uclass_first_device(UCLASS_LPC, &dev);
33         if (ret)
34                 return ret;
35         if (!dev)
36                 return -ENODEV;
37         ret = cpu_set_flex_ratio_to_tdp_nominal();
38         if (ret)
39                 return ret;
40
41         return 0;
42 }
43
44 void set_max_freq(void)
45 {
46         msr_t msr, perf_ctl;
47
48         if (cpu_config_tdp_levels()) {
49                 /* Set to nominal TDP ratio */
50                 msr = msr_read(MSR_CONFIG_TDP_NOMINAL);
51                 perf_ctl.lo = (msr.lo & 0xff) << 8;
52         } else {
53                 /* Platform Info bits 15:8 give max ratio */
54                 msr = msr_read(MSR_PLATFORM_INFO);
55                 perf_ctl.lo = msr.lo & 0xff00;
56         }
57
58         perf_ctl.hi = 0;
59         msr_write(MSR_IA32_PERF_CTL, perf_ctl);
60
61         debug("CPU: frequency set to %d MHz\n",
62               ((perf_ctl.lo >> 8) & 0xff) * INTEL_BCLK_MHZ);
63 }
64
65 int arch_cpu_init(void)
66 {
67         post_code(POST_CPU_INIT);
68
69 #ifdef CONFIG_TPL
70         /* Do a mini-init if TPL has already done the full init */
71         return x86_cpu_reinit_f();
72 #else
73         return x86_cpu_init_f();
74 #endif
75 }
76
77 int checkcpu(void)
78 {
79         int ret;
80
81         set_max_freq();
82
83         ret = cpu_common_init();
84         if (ret)
85                 return ret;
86         gd->arch.pei_boot_mode = PEI_BOOT_NONE;
87
88         return 0;
89 }
90
91 int print_cpuinfo(void)
92 {
93         char processor_name[CPU_MAX_NAME_LEN];
94         const char *name;
95
96         /* Print processor name */
97         name = cpu_get_name(processor_name);
98         printf("CPU:   %s\n", name);
99
100         return 0;
101 }
102
103 void board_debug_uart_init(void)
104 {
105         /* com1 / com2 decode range */
106         pci_x86_write_config(PCH_DEV_LPC, LPC_IO_DEC, 1 << 4, PCI_SIZE_16);
107
108         pci_x86_write_config(PCH_DEV_LPC, LPC_EN, COMA_LPC_EN, PCI_SIZE_16);
109 }