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 | 9758973 | 2020-05-10 11:40:02 -0600 | [diff] [blame] | 11 | #include <init.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 12 | #include <log.h> |
Simon Glass | 71606de | 2016-03-11 22:07:18 -0700 | [diff] [blame] | 13 | #include <asm/cpu.h> |
| 14 | #include <asm/cpu_x86.h> |
| 15 | #include <asm/cpu_common.h> |
| 16 | #include <asm/intel_regs.h> |
Simon Glass | 412f11b | 2019-04-25 21:58:50 -0600 | [diff] [blame] | 17 | #include <asm/lpc_common.h> |
Simon Glass | 71606de | 2016-03-11 22:07:18 -0700 | [diff] [blame] | 18 | #include <asm/msr.h> |
Simon Glass | 412f11b | 2019-04-25 21:58:50 -0600 | [diff] [blame] | 19 | #include <asm/pci.h> |
Simon Glass | 71606de | 2016-03-11 22:07:18 -0700 | [diff] [blame] | 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 | |
Simon Glass | 71606de | 2016-03-11 22:07:18 -0700 | [diff] [blame] | 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 | { |
Simon Glass | b12689d | 2019-09-25 08:56:38 -0600 | [diff] [blame] | 46 | msr_t msr, perf_ctl; |
Simon Glass | 71606de | 2016-03-11 22:07:18 -0700 | [diff] [blame] | 47 | |
Simon Glass | b12689d | 2019-09-25 08:56:38 -0600 | [diff] [blame] | 48 | if (cpu_config_tdp_levels()) { |
Simon Glass | 71606de | 2016-03-11 22:07:18 -0700 | [diff] [blame] | 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; |
Simon Glass | 76ae027 | 2019-09-25 08:56:35 -0600 | [diff] [blame] | 59 | msr_write(MSR_IA32_PERF_CTL, perf_ctl); |
Simon Glass | 71606de | 2016-03-11 22:07:18 -0700 | [diff] [blame] | 60 | |
| 61 | debug("CPU: frequency set to %d MHz\n", |
Simon Glass | 4347d83 | 2019-09-25 08:56:37 -0600 | [diff] [blame] | 62 | ((perf_ctl.lo >> 8) & 0xff) * INTEL_BCLK_MHZ); |
Simon Glass | 71606de | 2016-03-11 22:07:18 -0700 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | int arch_cpu_init(void) |
| 66 | { |
| 67 | post_code(POST_CPU_INIT); |
| 68 | |
Simon Glass | 42bf3b9 | 2019-09-25 08:11:40 -0600 | [diff] [blame] | 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 |
Simon Glass | 71606de | 2016-03-11 22:07:18 -0700 | [diff] [blame] | 73 | return x86_cpu_init_f(); |
Simon Glass | 42bf3b9 | 2019-09-25 08:11:40 -0600 | [diff] [blame] | 74 | #endif |
Simon Glass | 71606de | 2016-03-11 22:07:18 -0700 | [diff] [blame] | 75 | } |
| 76 | |
Simon Glass | ee7c36f | 2017-03-28 10:27:30 -0600 | [diff] [blame] | 77 | int checkcpu(void) |
Simon Glass | 71606de | 2016-03-11 22:07:18 -0700 | [diff] [blame] | 78 | { |
Simon Glass | 71606de | 2016-03-11 22:07:18 -0700 | [diff] [blame] | 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 | |
Simon Glass | ee7c36f | 2017-03-28 10:27:30 -0600 | [diff] [blame] | 88 | return 0; |
| 89 | } |
| 90 | |
| 91 | int print_cpuinfo(void) |
| 92 | { |
| 93 | char processor_name[CPU_MAX_NAME_LEN]; |
| 94 | const char *name; |
| 95 | |
Simon Glass | 71606de | 2016-03-11 22:07:18 -0700 | [diff] [blame] | 96 | /* Print processor name */ |
| 97 | name = cpu_get_name(processor_name); |
| 98 | printf("CPU: %s\n", name); |
| 99 | |
| 100 | return 0; |
| 101 | } |
| 102 | |
Simon Glass | 412f11b | 2019-04-25 21:58:50 -0600 | [diff] [blame] | 103 | void board_debug_uart_init(void) |
| 104 | { |
Simon Glass | 412f11b | 2019-04-25 21:58:50 -0600 | [diff] [blame] | 105 | /* com1 / com2 decode range */ |
Simon Glass | a546458 | 2019-08-31 21:23:18 -0600 | [diff] [blame] | 106 | 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] | 107 | |
Simon Glass | a546458 | 2019-08-31 21:23:18 -0600 | [diff] [blame] | 108 | 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] | 109 | } |