mb/ocp/tiogapass: Fix GPIOs
[coreboot2.git] / src / mainboard / asus / p5ql-em / early_init.c
blobaf5713b22461f426b21a920f01a56890e655f77e
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
3 #include <bootblock_common.h>
4 #include <device/pnp_ops.h>
5 #include <console/console.h>
6 #include <northbridge/intel/x4x/x4x.h>
7 #include <cpu/x86/msr.h>
8 #include <cpu/intel/speedstep.h>
9 #include <cf9_reset.h>
10 #include <superio/winbond/w83627dhg/w83627dhg.h>
11 #include <superio/winbond/common/winbond.h>
13 #define SERIAL_DEV PNP_DEV(0x2e, W83627DHG_SP1)
14 #define GPIO_DEV PNP_DEV(0x2e, W83627DHG_GPIO2345_V)
16 void bootblock_mainboard_early_init(void)
18 winbond_enable_serial(SERIAL_DEV, CONFIG_TTYS0_BASE);
21 static u8 msr_get_fsb(void)
23 u8 fsbcfg;
24 msr_t msr;
25 const u32 eax = cpuid_eax(1);
27 /* Netburst */
28 if (((eax >> 8) & 0xf) == 0xf) {
29 msr = rdmsr(MSR_EBC_FREQUENCY_ID);
30 fsbcfg = (msr.lo >> 16) & 0x7;
31 } else { /* Intel Core 2 */
32 msr = rdmsr(MSR_FSB_FREQ);
33 fsbcfg = msr.lo & 0x7;
36 return fsbcfg;
39 /* BSEL MCH straps are not hooked up to the CPU as usual but to the SIO */
40 static int setup_sio_gpio(void)
42 int need_reset = 0;
43 u8 reg, old_reg;
45 u8 bsel = msr_get_fsb();
46 switch (bsel) {
47 case 0:
48 case 2:
49 case 4:
50 break;
51 default:
52 printk(BIOS_WARNING,
53 "BSEL: Unsupported FSB frequency, using 800MHz\n");
54 bsel = 2; /* 800MHz */
55 break;
58 pnp_enter_ext_func_mode(GPIO_DEV);
59 pnp_set_logical_device(GPIO_DEV);
62 * P5QL-EM:
63 * BSEL0 -> not hooked up (not supported anyways)
64 * BSEL1 -> GPIO33 (inverted)
65 * BSEL2 -> GPIO40
67 reg = 0x92;
68 /* Multi-function Pin Selection */
69 old_reg = pnp_read_config(GPIO_DEV, 0x2c);
70 pnp_write_config(GPIO_DEV, 0x2c, reg);
71 need_reset = (reg != old_reg);
73 pnp_write_config(GPIO_DEV, 0x30, 0x0e); /* Enable GPIO3x,4x,5x */
74 pnp_write_config(GPIO_DEV, 0xf0, 0xf3); /* GPIO3x direction */
75 pnp_write_config(GPIO_DEV, 0xf2, 0x08); /* GPIO3x inversion */
76 pnp_write_config(GPIO_DEV, 0xf4, 0x06); /* GPIO4x direction */
78 const int gpio33 = (bsel & 2) >> 1;
79 const int gpio40 = (bsel & 4) >> 2;
80 reg = (gpio33 << 3);
81 old_reg = pnp_read_config(GPIO_DEV, 0xf1); /* GPIO3x data */
82 /* Set GPIO32 high like vendor firmware */
83 pnp_write_config(GPIO_DEV, 0xf1, old_reg | reg | 4);
84 need_reset += ((reg & 0x8) != (old_reg & 0x8));
86 reg = gpio40;
87 old_reg = pnp_read_config(GPIO_DEV, 0xf5); /* GPIO4x data */
88 pnp_write_config(GPIO_DEV, 0xf5, old_reg | reg);
89 need_reset += ((reg & 0x1) != (old_reg & 0x1));
90 pnp_exit_ext_func_mode(GPIO_DEV);
92 return need_reset;
95 void mb_pre_raminit_setup(int s3_resume)
97 if (!s3_resume && setup_sio_gpio()) {
98 printk(BIOS_DEBUG, "Needs reset to configure CPU BSEL straps\n");
99 full_reset();
103 void mb_get_spd_map(u8 spd_map[4])
105 /* This board has first dimm slot of each channel hooked up to
106 rank0 and rank1, while the second dimm slot is only connected
107 to rank1. The raminit does not support such setups. So only the
108 first dimms of each channel are used. */
109 spd_map[0] = 0x50;
110 spd_map[2] = 0x52;