blob: cbd4a3b67973c46afa78c4b5e8b237e9a932682f [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 Glassd67d7912023-09-07 09:58:18 -060014#include <spl.h>
Simon Glass71606de2016-03-11 22:07:18 -070015#include <asm/cpu.h>
16#include <asm/cpu_x86.h>
17#include <asm/cpu_common.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060018#include <asm/global_data.h>
Simon Glass71606de2016-03-11 22:07:18 -070019#include <asm/intel_regs.h>
Simon Glass412f11b2019-04-25 21:58:50 -060020#include <asm/lpc_common.h>
Simon Glass71606de2016-03-11 22:07:18 -070021#include <asm/msr.h>
Simon Glass412f11b2019-04-25 21:58:50 -060022#include <asm/pci.h>
Simon Glass71606de2016-03-11 22:07:18 -070023#include <asm/post.h>
24#include <asm/turbo.h>
25#include <asm/arch/cpu.h>
26#include <asm/arch/pch.h>
27#include <asm/arch/rcb.h>
28
Simon Glassb8357c12023-08-21 21:16:56 -060029static int broadwell_init_cpu(void)
Simon Glass71606de2016-03-11 22:07:18 -070030{
31 struct udevice *dev;
32 int ret;
33
34 /* Start up the LPC so we have serial */
Michal Suchanekac12a2f2022-10-12 21:57:59 +020035 ret = uclass_first_device_err(UCLASS_LPC, &dev);
Simon Glass71606de2016-03-11 22:07:18 -070036 if (ret)
37 return ret;
Simon Glass71606de2016-03-11 22:07:18 -070038 ret = cpu_set_flex_ratio_to_tdp_nominal();
39 if (ret)
40 return ret;
41
42 return 0;
43}
Simon Glassb8357c12023-08-21 21:16:56 -060044EVENT_SPY_SIMPLE(EVT_DM_POST_INIT_F, broadwell_init_cpu);
Simon Glass71606de2016-03-11 22:07:18 -070045
46void set_max_freq(void)
47{
Simon Glassb12689d2019-09-25 08:56:38 -060048 msr_t msr, perf_ctl;
Simon Glass71606de2016-03-11 22:07:18 -070049
Simon Glassb12689d2019-09-25 08:56:38 -060050 if (cpu_config_tdp_levels()) {
Simon Glass71606de2016-03-11 22:07:18 -070051 /* Set to nominal TDP ratio */
52 msr = msr_read(MSR_CONFIG_TDP_NOMINAL);
53 perf_ctl.lo = (msr.lo & 0xff) << 8;
54 } else {
55 /* Platform Info bits 15:8 give max ratio */
56 msr = msr_read(MSR_PLATFORM_INFO);
57 perf_ctl.lo = msr.lo & 0xff00;
58 }
59
60 perf_ctl.hi = 0;
Simon Glass76ae0272019-09-25 08:56:35 -060061 msr_write(MSR_IA32_PERF_CTL, perf_ctl);
Simon Glass71606de2016-03-11 22:07:18 -070062
63 debug("CPU: frequency set to %d MHz\n",
Simon Glass4347d832019-09-25 08:56:37 -060064 ((perf_ctl.lo >> 8) & 0xff) * INTEL_BCLK_MHZ);
Simon Glass71606de2016-03-11 22:07:18 -070065}
66
67int arch_cpu_init(void)
68{
69 post_code(POST_CPU_INIT);
70
Simon Glass42bf3b92019-09-25 08:11:40 -060071 /* Do a mini-init if TPL has already done the full init */
Simon Glassd67d7912023-09-07 09:58:18 -060072 if (IS_ENABLED(CONFIG_TPL) && spl_phase() != PHASE_TPL)
73 return x86_cpu_reinit_f();
74 else
75 return x86_cpu_init_f();
Simon Glass71606de2016-03-11 22:07:18 -070076}
77
Simon Glassee7c36f2017-03-28 10:27:30 -060078int checkcpu(void)
Simon Glass71606de2016-03-11 22:07:18 -070079{
Simon Glass71606de2016-03-11 22:07:18 -070080 int ret;
81
82 set_max_freq();
83
84 ret = cpu_common_init();
85 if (ret)
86 return ret;
87 gd->arch.pei_boot_mode = PEI_BOOT_NONE;
88
Simon Glassee7c36f2017-03-28 10:27:30 -060089 return 0;
90}
91
92int print_cpuinfo(void)
93{
94 char processor_name[CPU_MAX_NAME_LEN];
95 const char *name;
96
Simon Glass71606de2016-03-11 22:07:18 -070097 /* Print processor name */
98 name = cpu_get_name(processor_name);
99 printf("CPU: %s\n", name);
100
101 return 0;
102}
103
Simon Glass412f11b2019-04-25 21:58:50 -0600104void board_debug_uart_init(void)
105{
Simon Glass412f11b2019-04-25 21:58:50 -0600106 /* com1 / com2 decode range */
Simon Glassa5464582019-08-31 21:23:18 -0600107 pci_x86_write_config(PCH_DEV_LPC, LPC_IO_DEC, 1 << 4, PCI_SIZE_16);
Simon Glass412f11b2019-04-25 21:58:50 -0600108
Simon Glassa5464582019-08-31 21:23:18 -0600109 pci_x86_write_config(PCH_DEV_LPC, LPC_EN, COMA_LPC_EN, PCI_SIZE_16);
Simon Glass412f11b2019-04-25 21:58:50 -0600110}