blob: 6d37fed2ef7e6caf6728a537c010abddbe1d7c31 [file] [log] [blame]
Arthur Heymans6390e522016-11-21 17:11:48 +01001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2007-2008 coresystems GmbH
5 * Copyright (C) 2016 Arthur Heymans arthur@aheymans.xyz
6 * Copyright (C) 2016 Kyösti Mälkki <kyosti.malkki@gmail.com>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; version 2 of the License.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 */
17
Arthur Heymansc5839202019-11-12 23:48:42 +010018#include <bootblock_common.h>
Arthur Heymans6390e522016-11-21 17:11:48 +010019#include <stdint.h>
Elyes HAOUASd07048a2019-04-21 20:17:11 +020020#include <cf9_reset.h>
Kyösti Mälkki3855c012019-03-03 08:45:19 +020021#include <device/pnp_ops.h>
Kyösti Mälkkif1b58b72019-03-01 13:43:02 +020022#include <device/pci_ops.h>
Arthur Heymans6390e522016-11-21 17:11:48 +010023#include <superio/winbond/common/winbond.h>
24#include <superio/winbond/w83627dhg/w83627dhg.h>
Arthur Heymans6390e522016-11-21 17:11:48 +010025#include <console/console.h>
Arthur Heymans6390e522016-11-21 17:11:48 +010026#include <northbridge/intel/i945/i945.h>
Arthur Heymans6390e522016-11-21 17:11:48 +010027#include <southbridge/intel/i82801gx/i82801gx.h>
28#include <cpu/x86/msr.h>
29#include <cpu/intel/speedstep.h>
30#include <arch/cpu.h>
31
32#define SERIAL_DEV PNP_DEV(0x2e, W83627DHG_SP1)
33#define GPIO_DEV PNP_DEV(0x2e, W83627DHG_GPIO2345_V)
34
Arthur Heymans6390e522016-11-21 17:11:48 +010035/*
36 * BSEL0 is connected with GPIO32
37 * BSEL1 is connected with GPIO33 with inversed logic
38 * BSEL2 is connected with GPIO55
39 */
Arthur Heymans42315682017-05-06 00:28:12 +020040static int setup_sio_gpio(u8 bsel)
Arthur Heymans6390e522016-11-21 17:11:48 +010041{
42 int need_reset = 0;
43 u8 reg, old_reg;
44
45 pnp_enter_ext_func_mode(GPIO_DEV);
46 pnp_set_logical_device(GPIO_DEV);
47
48 reg = 0x9a;
49 old_reg = pnp_read_config(GPIO_DEV, 0x2c);
50 pnp_write_config(GPIO_DEV, 0x2c, reg);
51 need_reset = (reg != old_reg);
52
53 pnp_write_config(GPIO_DEV, 0x30, 0x0e);
54 pnp_write_config(GPIO_DEV, 0xe0, 0xde);
55 pnp_write_config(GPIO_DEV, 0xf0, 0xf3);
56 pnp_write_config(GPIO_DEV, 0xf4, 0x80);
57 pnp_write_config(GPIO_DEV, 0xf5, 0x80);
58
59 /* Invert GPIO33 */
60 pnp_write_config(GPIO_DEV, 0xf2, 0x08);
61
62 reg = (bsel & 3) << 2;
63 old_reg = pnp_read_config(GPIO_DEV, 0xf1);
64 pnp_write_config(GPIO_DEV, 0xf1, reg);
65 need_reset += ((reg & 0xc) != (old_reg & 0xc));
66
67 reg = (bsel >> 2) << 5;
68 old_reg = pnp_read_config(GPIO_DEV, 0xe1);
69 pnp_write_config(GPIO_DEV, 0xe1, reg);
70 need_reset += ((reg & 0x20) != (old_reg & 0x20));
71
72 pnp_exit_ext_func_mode(GPIO_DEV);
73
Arthur Heymans42315682017-05-06 00:28:12 +020074 return need_reset;
Arthur Heymans6390e522016-11-21 17:11:48 +010075}
76
77static u8 msr_get_fsb(void)
78{
79 u8 fsbcfg;
80 msr_t msr;
81 const u32 eax = cpuid_eax(1);
82
83 /* Netburst */
84 if (((eax >> 8) & 0xf) == 0xf) {
Elyes HAOUASf6bbc602017-11-26 15:34:20 +010085 msr = rdmsr(MSR_EBC_FREQUENCY_ID);
Arthur Heymans6390e522016-11-21 17:11:48 +010086 fsbcfg = (msr.lo >> 16) & 0x7;
87 } else { /* Intel Core 2 */
88 msr = rdmsr(MSR_FSB_FREQ);
89 fsbcfg = msr.lo & 0x7;
90 }
91
92 return fsbcfg;
93}
94
Arthur Heymansdc584c32019-11-12 20:37:21 +010095void mainboard_late_rcba_config(void)
Arthur Heymans6390e522016-11-21 17:11:48 +010096{
Arthur Heymans6390e522016-11-21 17:11:48 +010097 /* Enable PCIe Root Port Clock Gate */
Arthur Heymansb451df22017-08-15 20:59:09 +020098 RCBA32(CG) = 0x00000001;
Arthur Heymans6390e522016-11-21 17:11:48 +010099}
Arthur Heymansdc584c32019-11-12 20:37:21 +0100100
101void mainboard_pre_raminit_config(int s3_resume)
Arthur Heymans6390e522016-11-21 17:11:48 +0100102{
Arthur Heymans6390e522016-11-21 17:11:48 +0100103 u8 c_bsel = msr_get_fsb();
Arthur Heymans42315682017-05-06 00:28:12 +0200104 /*
105 * Result is that FSB is incorrect on s3 resume (fixed at 800MHz).
106 * Some CPU accept this others don't.
107 */
Arthur Heymansdc584c32019-11-12 20:37:21 +0100108 if (!s3_resume && setup_sio_gpio(c_bsel)) {
Arthur Heymans42315682017-05-06 00:28:12 +0200109 printk(BIOS_DEBUG,
110 "Needs reset to configure CPU BSEL straps\n");
Elyes HAOUASd07048a2019-04-21 20:17:11 +0200111 full_reset();
Arthur Heymans42315682017-05-06 00:28:12 +0200112 }
Arthur Heymansdc584c32019-11-12 20:37:21 +0100113}
Arthur Heymans42315682017-05-06 00:28:12 +0200114
Arthur Heymansc5839202019-11-12 23:48:42 +0100115void bootblock_mainboard_early_init(void)
Arthur Heymansdc584c32019-11-12 20:37:21 +0100116{
117 winbond_enable_serial(SERIAL_DEV, CONFIG_TTYS0_BASE);
Arthur Heymans6390e522016-11-21 17:11:48 +0100118}