Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Simon Glass | 71606de | 2016-03-11 22:07:18 -0700 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2016 Google, Inc |
| 4 | * |
Simon Glass | 71606de | 2016-03-11 22:07:18 -0700 | [diff] [blame] | 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> |
Simon Glass | fc55736 | 2022-03-04 08:43:05 -0700 | [diff] [blame] | 11 | #include <event.h> |
Simon Glass | 9758973 | 2020-05-10 11:40:02 -0600 | [diff] [blame] | 12 | #include <init.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 13 | #include <log.h> |
Simon Glass | d67d791 | 2023-09-07 09:58:18 -0600 | [diff] [blame] | 14 | #include <spl.h> |
Simon Glass | 71606de | 2016-03-11 22:07:18 -0700 | [diff] [blame] | 15 | #include <asm/cpu.h> |
| 16 | #include <asm/cpu_x86.h> |
| 17 | #include <asm/cpu_common.h> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 18 | #include <asm/global_data.h> |
Simon Glass | 71606de | 2016-03-11 22:07:18 -0700 | [diff] [blame] | 19 | #include <asm/intel_regs.h> |
Simon Glass | 412f11b | 2019-04-25 21:58:50 -0600 | [diff] [blame] | 20 | #include <asm/lpc_common.h> |
Simon Glass | 71606de | 2016-03-11 22:07:18 -0700 | [diff] [blame] | 21 | #include <asm/msr.h> |
Simon Glass | 412f11b | 2019-04-25 21:58:50 -0600 | [diff] [blame] | 22 | #include <asm/pci.h> |
Simon Glass | 71606de | 2016-03-11 22:07:18 -0700 | [diff] [blame] | 23 | #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 Glass | b8357c1 | 2023-08-21 21:16:56 -0600 | [diff] [blame] | 29 | static int broadwell_init_cpu(void) |
Simon Glass | 71606de | 2016-03-11 22:07:18 -0700 | [diff] [blame] | 30 | { |
| 31 | struct udevice *dev; |
| 32 | int ret; |
| 33 | |
| 34 | /* Start up the LPC so we have serial */ |
Michal Suchanek | ac12a2f | 2022-10-12 21:57:59 +0200 | [diff] [blame] | 35 | ret = uclass_first_device_err(UCLASS_LPC, &dev); |
Simon Glass | 71606de | 2016-03-11 22:07:18 -0700 | [diff] [blame] | 36 | if (ret) |
| 37 | return ret; |
Simon Glass | 71606de | 2016-03-11 22:07:18 -0700 | [diff] [blame] | 38 | ret = cpu_set_flex_ratio_to_tdp_nominal(); |
| 39 | if (ret) |
| 40 | return ret; |
| 41 | |
| 42 | return 0; |
| 43 | } |
Simon Glass | b8357c1 | 2023-08-21 21:16:56 -0600 | [diff] [blame] | 44 | EVENT_SPY_SIMPLE(EVT_DM_POST_INIT_F, broadwell_init_cpu); |
Simon Glass | 71606de | 2016-03-11 22:07:18 -0700 | [diff] [blame] | 45 | |
| 46 | void set_max_freq(void) |
| 47 | { |
Simon Glass | b12689d | 2019-09-25 08:56:38 -0600 | [diff] [blame] | 48 | msr_t msr, perf_ctl; |
Simon Glass | 71606de | 2016-03-11 22:07:18 -0700 | [diff] [blame] | 49 | |
Simon Glass | b12689d | 2019-09-25 08:56:38 -0600 | [diff] [blame] | 50 | if (cpu_config_tdp_levels()) { |
Simon Glass | 71606de | 2016-03-11 22:07:18 -0700 | [diff] [blame] | 51 | /* 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 Glass | 76ae027 | 2019-09-25 08:56:35 -0600 | [diff] [blame] | 61 | msr_write(MSR_IA32_PERF_CTL, perf_ctl); |
Simon Glass | 71606de | 2016-03-11 22:07:18 -0700 | [diff] [blame] | 62 | |
| 63 | debug("CPU: frequency set to %d MHz\n", |
Simon Glass | 4347d83 | 2019-09-25 08:56:37 -0600 | [diff] [blame] | 64 | ((perf_ctl.lo >> 8) & 0xff) * INTEL_BCLK_MHZ); |
Simon Glass | 71606de | 2016-03-11 22:07:18 -0700 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | int arch_cpu_init(void) |
| 68 | { |
| 69 | post_code(POST_CPU_INIT); |
| 70 | |
Simon Glass | 42bf3b9 | 2019-09-25 08:11:40 -0600 | [diff] [blame] | 71 | /* Do a mini-init if TPL has already done the full init */ |
Simon Glass | d67d791 | 2023-09-07 09:58:18 -0600 | [diff] [blame] | 72 | if (IS_ENABLED(CONFIG_TPL) && spl_phase() != PHASE_TPL) |
| 73 | return x86_cpu_reinit_f(); |
| 74 | else |
| 75 | return x86_cpu_init_f(); |
Simon Glass | 71606de | 2016-03-11 22:07:18 -0700 | [diff] [blame] | 76 | } |
| 77 | |
Simon Glass | ee7c36f | 2017-03-28 10:27:30 -0600 | [diff] [blame] | 78 | int checkcpu(void) |
Simon Glass | 71606de | 2016-03-11 22:07:18 -0700 | [diff] [blame] | 79 | { |
Simon Glass | 71606de | 2016-03-11 22:07:18 -0700 | [diff] [blame] | 80 | 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 Glass | ee7c36f | 2017-03-28 10:27:30 -0600 | [diff] [blame] | 89 | return 0; |
| 90 | } |
| 91 | |
| 92 | int print_cpuinfo(void) |
| 93 | { |
| 94 | char processor_name[CPU_MAX_NAME_LEN]; |
| 95 | const char *name; |
| 96 | |
Simon Glass | 71606de | 2016-03-11 22:07:18 -0700 | [diff] [blame] | 97 | /* Print processor name */ |
| 98 | name = cpu_get_name(processor_name); |
| 99 | printf("CPU: %s\n", name); |
| 100 | |
| 101 | return 0; |
| 102 | } |
| 103 | |
Simon Glass | 412f11b | 2019-04-25 21:58:50 -0600 | [diff] [blame] | 104 | void board_debug_uart_init(void) |
| 105 | { |
Simon Glass | 412f11b | 2019-04-25 21:58:50 -0600 | [diff] [blame] | 106 | /* com1 / com2 decode range */ |
Simon Glass | a546458 | 2019-08-31 21:23:18 -0600 | [diff] [blame] | 107 | pci_x86_write_config(PCH_DEV_LPC, LPC_IO_DEC, 1 << 4, PCI_SIZE_16); |
Simon Glass | 412f11b | 2019-04-25 21:58:50 -0600 | [diff] [blame] | 108 | |
Simon Glass | a546458 | 2019-08-31 21:23:18 -0600 | [diff] [blame] | 109 | pci_x86_write_config(PCH_DEV_LPC, LPC_EN, COMA_LPC_EN, PCI_SIZE_16); |
Simon Glass | 412f11b | 2019-04-25 21:58:50 -0600 | [diff] [blame] | 110 | } |