coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
early_fch.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 
3 #include <amdblocks/acpimmio.h>
4 #include <amdblocks/lpc.h>
5 #include <amdblocks/pmlib.h>
6 #include <amdblocks/reset.h>
7 #include <amdblocks/smbus.h>
8 #include <amdblocks/spi.h>
9 #include <soc/southbridge.h>
10 #include <types.h>
11 
12 static void sb_enable_lpc(void)
13 {
14  u8 byte;
15 
16  /* Enable LPC controller */
17  byte = pm_io_read8(PM_LPC_GATING);
18  byte |= PM_LPC_ENABLE;
20 }
21 
22 static void sb_lpc_decode(void)
23 {
24  u32 tmp = 0;
25 
26  /* Enable I/O decode to LPC bus */
39 
40  /* Decode SIOs at 2E/2F and 4E/4F */
41  if (CONFIG(STONEYRIDGE_LEGACY_FREE))
43 
44  lpc_enable_decode(tmp);
45 }
46 
47 static void setup_spread_spectrum(int *reboot)
48 {
50 
51  rstcfg &= ~TOGGLE_ALL_PWR_GOOD;
52  pm_write16(PWR_RESET_CFG, rstcfg);
53 
55 
56  if (cntl1 & CG1PLL_FBDIV_TEST) {
57  printk(BIOS_DEBUG, "Spread spectrum is ready\n");
61 
62  return;
63  }
64 
65  printk(BIOS_DEBUG, "Setting up spread spectrum\n");
66 
68  cfg6 &= ~CG1PLL_LF_MODE_MASK;
69  cfg6 |= (0x0f8 << CG1PLL_LF_MODE_SHIFT) & CG1PLL_LF_MODE_MASK;
71 
73  cfg3 &= ~CG1PLL_REFDIV_MASK;
74  cfg3 |= (0x003 << CG1PLL_REFDIV_SHIFT) & CG1PLL_REFDIV_MASK;
75  cfg3 &= ~CG1PLL_FBDIV_MASK;
76  cfg3 |= (0x04b << CG1PLL_FBDIV_SHIFT) & CG1PLL_FBDIV_MASK;
78 
83 
85  cfg4 &= ~SS_AMOUNT_DSFRAC_MASK;
86  cfg4 |= (0xd000 << SS_AMOUNT_DSFRAC_SHIFT) & SS_AMOUNT_DSFRAC_MASK;
87  cfg4 &= ~SS_STEP_SIZE_DSFRAC_MASK;
88  cfg4 |= (0x02d5 << SS_STEP_SIZE_DSFRAC_SHIFT)
91 
92  rstcfg |= TOGGLE_ALL_PWR_GOOD;
93  pm_write16(PWR_RESET_CFG, rstcfg);
94 
95  cntl1 |= CG1PLL_FBDIV_TEST;
97 
98  *reboot = 1;
99 }
100 
101 static void setup_misc(int *reboot)
102 {
103  /* Undocumented register */
104  uint32_t reg = misc_read32(0x50);
105  if (!(reg & BIT(16))) {
106  reg |= BIT(16);
107 
108  misc_write32(0x50, reg);
109  *reboot = 1;
110  }
111 }
112 
113 /* Before console init */
115 {
116  int reboot = 0;
117 
118  /* Enable_acpimmio_decode_pm04 to enable the ACPIMMIO decode which is needed to access
119  the GPIO registers. */
121  lpc_enable_rom();
122  sb_enable_lpc();
124  sb_lpc_decode();
125  /* Make sure the base address is predictable */
128  fch_smbus_init();
130  setup_spread_spectrum(&reboot);
131  setup_misc(&reboot);
132 
133  if (reboot)
134  warm_reset();
135 
138 
139  /* disable the keyboard reset function before mainboard GPIO setup */
140  if (CONFIG(DISABLE_KEYBOARD_RESET_PIN))
142 }
143 
144 /* After console init */
146 {
150 }
151 
153 {
154  u32 ctrl;
155 
156  /*
157  * Clear the disable for OSCOUT1 (signal typically named XnnM_25M_48M)
158  * or OSCOUT2 (USBCLK/25M_48M_OSC). The frequency defaults to 48MHz.
159  */
160  ctrl = misc_read32(MISC_CLK_CNTL1);
161 
162  switch (osc) {
163  case 1:
164  ctrl &= ~OSCOUT1_CLK_OUTPUT_ENB;
165  break;
166  case 2:
167  ctrl &= ~OSCOUT2_CLK_OUTPUT_ENB;
168  break;
169  default:
170  return; /* do nothing if invalid */
171  }
173 }
static void pm_write16(uint8_t reg, uint16_t value)
Definition: acpimmio.h:186
static uint32_t misc_read32(uint8_t reg)
Definition: acpimmio.h:266
static void misc_write32(uint8_t reg, uint32_t value)
Definition: acpimmio.h:281
static uint16_t pm_read16(uint8_t reg)
Definition: acpimmio.h:171
#define SPI_BASE_ADDRESS
Definition: iomap.h:8
void enable_aoac_devices(void)
Definition: aoac.c:41
#define PWR_RESET_CFG
Definition: southbridge.h:13
#define PM_LPC_ENABLE
Definition: southbridge.h:80
#define PM_LPC_GATING
Definition: southbridge.h:77
#define TOGGLE_ALL_PWR_GOOD
Definition: southbridge.h:14
#define printk(level,...)
Definition: stdlib.h:16
@ CONFIG
Definition: dsi_common.h:201
#define BIT(nr)
Definition: ec_commands.h:45
#define BIOS_DEBUG
BIOS_DEBUG - Verbose output.
Definition: loglevel.h:128
uint8_t pm_io_read8(uint8_t reg)
Definition: mmio_util.c:103
void fch_enable_cf9_io(void)
Definition: mmio_util.c:63
void pm_io_write8(uint8_t reg, uint8_t value)
Definition: mmio_util.c:119
void fch_enable_legacy_io(void)
Definition: mmio_util.c:68
void enable_acpimmio_decode_pm04(void)
Definition: mmio_util.c:54
void fch_disable_kb_rst(void)
Definition: mmio_util.c:97
#define CG1PLL_SPREAD_SPECTRUM_ENABLE
Definition: southbridge.h:92
#define MISC_CGPLL_CONFIG1
Definition: southbridge.h:91
#define MISC_CLK_CNTL1
Definition: southbridge.h:93
void pm_set_power_failure_state(void)
Definition: pmlib.c:16
void fch_print_pmxc0_status(void)
void lpc_set_spibase(uint32_t base)
Definition: lpc_util.c:318
#define DECODE_ENABLE_FDC_PORT0
Definition: lpc.h:43
#define DECODE_ENABLE_AUDIO_PORT1
Definition: lpc.h:32
#define DECODE_ENABLE_GAME_PORT
Definition: lpc.h:45
#define DECODE_ENABLE_SERIAL_PORT7
Definition: lpc.h:30
#define DECODE_ENABLE_SERIAL_PORT2
Definition: lpc.h:25
void lpc_enable_decode(uint32_t decodes)
Definition: lpc_util.c:160
#define DECODE_ENABLE_MSS_PORT3
Definition: lpc.h:42
#define DECODE_ENABLE_FDC_PORT1
Definition: lpc.h:44
#define DECODE_ENABLE_PARALLEL_PORT2
Definition: lpc.h:19
#define DECODE_SIO_ENABLE
Definition: lpc.h:67
void lpc_enable_port80(void)
Definition: lpc_util.c:139
#define DECODE_ENABLE_ADLIB_PORT
Definition: lpc.h:48
#define DECODE_ENABLE_SERIAL_PORT3
Definition: lpc.h:26
#define DECODE_ENABLE_AUDIO_PORT3
Definition: lpc.h:34
#define DECODE_ENABLE_SERIAL_PORT1
Definition: lpc.h:24
#define DECODE_ALTERNATE_SIO_ENABLE
Definition: lpc.h:66
#define DECODE_ENABLE_ACPIUC_PORT
Definition: lpc.h:47
#define DECODE_ENABLE_KBC_PORT
Definition: lpc.h:46
#define DECODE_ENABLE_SERIAL_PORT6
Definition: lpc.h:29
#define DECODE_ENABLE_MSS_PORT2
Definition: lpc.h:41
#define DECODE_ENABLE_SERIAL_PORT5
Definition: lpc.h:28
#define DECODE_ENABLE_SERIAL_PORT4
Definition: lpc.h:27
#define DECODE_ENABLE_AUDIO_PORT2
Definition: lpc.h:33
#define DECODE_ENABLE_PARALLEL_PORT4
Definition: lpc.h:21
#define DECODE_ENABLE_PARALLEL_PORT0
Definition: lpc.h:17
#define DECODE_ENABLE_SERIAL_PORT0
Definition: lpc.h:23
#define DECODE_ENABLE_AUDIO_PORT0
Definition: lpc.h:31
void lpc_enable_rom(void)
Definition: lpc_util.c:250
static __noreturn void warm_reset(void)
Definition: reset.h:15
void fch_smbus_init(void)
void fch_spi_early_init(void)
Definition: fch_spi.c:122
void show_spi_speeds_and_modes(void)
Definition: fch_spi.c:35
unsigned short uint16_t
Definition: stdint.h:11
unsigned int uint32_t
Definition: stdint.h:14
uint32_t u32
Definition: stdint.h:51
uint8_t u8
Definition: stdint.h:45
void fch_clk_output_48Mhz(u32 osc)
Definition: early_fch.c:152
void bootblock_fch_init(void)
Definition: early_fch.c:145
static void sb_enable_lpc(void)
Definition: early_fch.c:12
static void setup_misc(int *reboot)
Definition: early_fch.c:101
void bootblock_fch_early_init(void)
Definition: early_fch.c:114
static void sb_lpc_decode(void)
Definition: early_fch.c:22
static void setup_spread_spectrum(int *reboot)
Definition: early_fch.c:47
#define SS_AMOUNT_DSFRAC_MASK
Definition: southbridge.h:96
#define MISC_CGPLL_CONFIG5
Definition: southbridge.h:97
#define SS_STEP_SIZE_DSFRAC_SHIFT
Definition: southbridge.h:93
#define CG1PLL_FBDIV_SHIFT
Definition: southbridge.h:90
#define SS_AMOUNT_DSFRAC_SHIFT
Definition: southbridge.h:95
#define CG1PLL_FBDIV_MASK
Definition: southbridge.h:91
#define SS_AMOUNT_NFRAC_SLIP_SHIFT
Definition: southbridge.h:98
#define CG1PLL_LF_MODE_MASK
Definition: southbridge.h:102
#define OSCOUT2_CLK_OUTPUT_ENB
Definition: southbridge.h:106
#define SS_STEP_SIZE_DSFRAC_MASK
Definition: southbridge.h:94
#define CG1PLL_REFDIV_MASK
Definition: southbridge.h:89
#define MISC_CGPLL_CONFIG6
Definition: southbridge.h:100
#define OSCOUT1_CLK_OUTPUT_ENB
Definition: southbridge.h:105
#define CG1PLL_LF_MODE_SHIFT
Definition: southbridge.h:101
#define CG1PLL_REFDIV_SHIFT
Definition: southbridge.h:88
#define CG1PLL_FBDIV_TEST
Definition: southbridge.h:104
#define MISC_CGPLL_CONFIG3
Definition: southbridge.h:87
#define MISC_CGPLL_CONFIG4
Definition: southbridge.h:92
#define SS_AMOUNT_NFRAC_SLIP_MASK
Definition: southbridge.h:99