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> |
| 11 | #include <asm/cpu.h> |
| 12 | #include <asm/cpu_x86.h> |
| 13 | #include <asm/cpu_common.h> |
| 14 | #include <asm/intel_regs.h> |
Simon Glass | 412f11b | 2019-04-25 21:58:50 -0600 | [diff] [blame] | 15 | #include <asm/lpc_common.h> |
Simon Glass | 71606de | 2016-03-11 22:07:18 -0700 | [diff] [blame] | 16 | #include <asm/msr.h> |
Simon Glass | 412f11b | 2019-04-25 21:58:50 -0600 | [diff] [blame] | 17 | #include <asm/pci.h> |
Simon Glass | 71606de | 2016-03-11 22:07:18 -0700 | [diff] [blame] | 18 | #include <asm/post.h> |
| 19 | #include <asm/turbo.h> |
| 20 | #include <asm/arch/cpu.h> |
| 21 | #include <asm/arch/pch.h> |
| 22 | #include <asm/arch/rcb.h> |
| 23 | |
Simon Glass | 71606de | 2016-03-11 22:07:18 -0700 | [diff] [blame] | 24 | int arch_cpu_init_dm(void) |
| 25 | { |
| 26 | struct udevice *dev; |
| 27 | int ret; |
| 28 | |
| 29 | /* Start up the LPC so we have serial */ |
| 30 | ret = uclass_first_device(UCLASS_LPC, &dev); |
| 31 | if (ret) |
| 32 | return ret; |
| 33 | if (!dev) |
| 34 | return -ENODEV; |
| 35 | ret = cpu_set_flex_ratio_to_tdp_nominal(); |
| 36 | if (ret) |
| 37 | return ret; |
| 38 | |
| 39 | return 0; |
| 40 | } |
| 41 | |
| 42 | void set_max_freq(void) |
| 43 | { |
| 44 | msr_t msr, perf_ctl, platform_info; |
| 45 | |
| 46 | /* Check for configurable TDP option */ |
| 47 | platform_info = msr_read(MSR_PLATFORM_INFO); |
| 48 | |
| 49 | if ((platform_info.hi >> 1) & 3) { |
| 50 | /* Set to nominal TDP ratio */ |
| 51 | msr = msr_read(MSR_CONFIG_TDP_NOMINAL); |
| 52 | perf_ctl.lo = (msr.lo & 0xff) << 8; |
| 53 | } else { |
| 54 | /* Platform Info bits 15:8 give max ratio */ |
| 55 | msr = msr_read(MSR_PLATFORM_INFO); |
| 56 | perf_ctl.lo = msr.lo & 0xff00; |
| 57 | } |
| 58 | |
| 59 | perf_ctl.hi = 0; |
| 60 | msr_write(IA32_PERF_CTL, perf_ctl); |
| 61 | |
| 62 | debug("CPU: frequency set to %d MHz\n", |
| 63 | ((perf_ctl.lo >> 8) & 0xff) * CPU_BCLK); |
| 64 | } |
| 65 | |
| 66 | int arch_cpu_init(void) |
| 67 | { |
| 68 | post_code(POST_CPU_INIT); |
| 69 | |
| 70 | return x86_cpu_init_f(); |
| 71 | } |
| 72 | |
Simon Glass | ee7c36f | 2017-03-28 10:27:30 -0600 | [diff] [blame] | 73 | int checkcpu(void) |
Simon Glass | 71606de | 2016-03-11 22:07:18 -0700 | [diff] [blame] | 74 | { |
Simon Glass | 71606de | 2016-03-11 22:07:18 -0700 | [diff] [blame] | 75 | int ret; |
| 76 | |
| 77 | set_max_freq(); |
| 78 | |
| 79 | ret = cpu_common_init(); |
| 80 | if (ret) |
| 81 | return ret; |
| 82 | gd->arch.pei_boot_mode = PEI_BOOT_NONE; |
| 83 | |
Simon Glass | ee7c36f | 2017-03-28 10:27:30 -0600 | [diff] [blame] | 84 | return 0; |
| 85 | } |
| 86 | |
| 87 | int print_cpuinfo(void) |
| 88 | { |
| 89 | char processor_name[CPU_MAX_NAME_LEN]; |
| 90 | const char *name; |
| 91 | |
Simon Glass | 71606de | 2016-03-11 22:07:18 -0700 | [diff] [blame] | 92 | /* Print processor name */ |
| 93 | name = cpu_get_name(processor_name); |
| 94 | printf("CPU: %s\n", name); |
| 95 | |
| 96 | return 0; |
| 97 | } |
| 98 | |
Simon Glass | 412f11b | 2019-04-25 21:58:50 -0600 | [diff] [blame] | 99 | void board_debug_uart_init(void) |
| 100 | { |
| 101 | struct udevice *bus = NULL; |
| 102 | |
| 103 | /* com1 / com2 decode range */ |
| 104 | pci_x86_write_config(bus, PCH_DEV_LPC, LPC_IO_DEC, 1 << 4, PCI_SIZE_16); |
| 105 | |
| 106 | pci_x86_write_config(bus, PCH_DEV_LPC, LPC_EN, COMA_LPC_EN, |
| 107 | PCI_SIZE_16); |
| 108 | } |