coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
mainboard.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 
3 #include <amdblocks/acpimmio.h>
5 #include <console/console.h>
6 #include <device/device.h>
8 #include <arch/io.h>
9 #include <device/mmio.h>
10 #include <device/pci_ops.h>
11 #include <device/pci_def.h>
13 #include <vendorcode/amd/cimx/sb800/OEM.h> /* SMBUS0_BASE_ADDRESS */
15 #include "sema.h"
16 
17 static const u8 mainboard_intr_data[] = {
18  [0x00] = 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, /* INTA# - INTH# */
19  [0x08] = 0x00, 0x00, 0x00, 0x00, 0x1F, 0x1F, 0x1F, 0x1F, /* Misc-nil, 0, 1, 2, INT from Serial irq */
20  [0x10] = 0x09, 0x1F, 0x1F, 0x10, 0x1F, 0x12, 0x1F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
21  0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
22  0x12, 0x11, 0x12, 0x11, 0x12, 0x11, 0x12, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
23  0x11, 0x13, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
24  0x10, 0x11, 0x12, 0x13
25 };
26 
27 /* Init SIO GPIOs. */
28 #define SIO_RUNTIME_BASE 0x0E00
29 static const u16 sio_init_table[] = { // hi = offset, lo = value
30  0x4BA0, // GP1x: COM1/2 control = RS232, no term, max 115200
31  0x2300, // GP10: COM1 termination = push/pull output
32  0x2400, // GP11: COM2 termination = push/pull output
33  0x2500, // GP12: COM1 RS485 mode = push/pull output
34  0x2600, // GP13: COM2 RS485 mode = push/pull output
35  0x2700, // GP14: COM1 speed A = push/pull output
36  0x2900, // GP15: COM1 speed B = push/pull output
37  0x2A00, // GP16: COM2 speed A = push/pull output
38  0x2B00, // GP17: COM2 speed B = push/pull output
39 
40  0x3904, // GP36 = KBDRST# function
41 
42  0x4E74, // GP4x: Ethernet enable = on
43  0x6E84, // GP44: Ethernet enable = open drain output
44 
45  // GP5x = COM2 function instead of GPIO
46  0x3F05, 0x4005, 0x4105, 0x4204, 0x4305, 0x4404, 0x4505, 0x4604,
47 
48  0x470C, // GP60 = WDT function
49  0x5E00, // LED2: Live LED = off
50  0x4884, // GP61: Live LED = LED2 function
51 
52  0x5038, // GP6x: USB power = 3x on
53  0x5580, // GP63: USB power 0/1 = open drain output
54  0x5680, // GP64: USB power 2/3 = open drain output
55  0x5780, // GP65: USB power 4/5 = open drain output
56 };
57 
58 /* PIRQ Setup */
59 static void pirq_setup(void)
60 {
62 }
63 
64 static void init(struct device *dev)
65 {
66  volatile u8 *spi_base; /* base addr of Hudson's SPI host controller */
67  int i;
68 
69  /* Init Hudson GPIOs. */
70  printk(BIOS_DEBUG, "Init FCH GPIOs @ 0x%08x\n", ACPI_MMIO_BASE+GPIO_BASE);
71  /* GPIO50: FCH_ARST#_GATE resets stuck PCIe devices */
72  iomux_write8(50, 2);
73  /* output set to 1 as it's never needed */
74  iomux_write8(50, 0xc0);
75  /* GPIO197: BIOS_DEFAULTS# = input (int. PU) */
76  iomux_write8(197, 2);
77  /* GPIO58-56: REV_ID2-0 */
78  iomux_write8(56, 1);
79  /* inputs, disable int. pull-ups */
80  gpio_100_write8(56, 0x28);
81  iomux_write8(57, 1);
82  gpio_100_write8(57, 0x28);
83  iomux_write8(58, 1);
84  gpio_100_write8(58, 0x28);
85  /* "Gpio96": GEVENT0# signal on X2 connector (int. PU) */
86  iomux_write8(96, 1);
87  /* GPIO52,61,62,187-192 free to use on X2 connector */
88  iomux_write8(52, 1);
89  /* default to inputs with int. PU */
90  iomux_write8(61, 2);
91  iomux_write8(62, 2);
92  iomux_write8(187, 2);
93  iomux_write8(188, 2);
94  iomux_write8(189, 1);
95  iomux_write8(190, 1);
96  iomux_write8(191, 1);
97  iomux_write8(192, 1);
98  /* just in case anyone cares */
99  if (!fch_gpio_state(197))
100  printk(BIOS_INFO, "BIOS_DEFAULTS jumper is present.\n");
101  printk(BIOS_INFO, "Board revision ID: %u\n",
102  fch_gpio_state(58)<<2 | fch_gpio_state(57)<<1 | fch_gpio_state(56));
103 
104  /* Init SIO GPIOs. */
105  printk(BIOS_DEBUG, "Init SIO GPIOs @ 0x%04x\n", SIO_RUNTIME_BASE);
106  for (i = 0; i < ARRAY_SIZE(sio_init_table); i++) {
107  u16 val = sio_init_table[i];
108  outb((u8)val, SIO_RUNTIME_BASE + (val >> 8));
109  }
110 
111  /* Lower SPI speed from default 66 to 22 MHz for SST 25VF032B */
113  0xA0) & 0xFFFFFFE0);
114  /* NormSpeed in SPI_Cntrl1 register */
115  spi_base[0x0D] = (spi_base[0x0D] & ~0x30) | 0x20;
116 
117  /*
118  * Notify the SMC we're alive and kicking, or after a while it will
119  * effect a power cycle and switch to the alternate BIOS chip.
120  * Should be done as late as possible.
121  * Failure here does not matter if watchdog was already disabled,
122  * by configuration or previous boot, so ignore return value.
123  */
124  sema_send_alive();
125 
126 }
127 
128 /**********************************************
129  * Enable the dedicated functions of the board.
130  **********************************************/
131 static void mainboard_enable(struct device *dev)
132 {
133  /* Initialize the PIRQ data structures for consumption */
134  pirq_setup();
135 
136  dev->ops->init = init;
137 
138  /* enable GPP CLK0 */
139  /* disable GPP CLK1 thru SLT_GFX_CLK */
140  misc_write8(0, 0x0f);
141  misc_write8(1, 0);
142  misc_write8(2, 0);
143  misc_write8(3, 0);
144  misc_write8(4, 0);
145 
146  /*
147  * Initialize ASF registers to an arbitrary address because someone
148  * long ago set things up this way inside the SPD read code. The
149  * SPD read code has been made generic and moved out of the board
150  * directory, so the ASF init is being done here.
151  */
152  pm_write8(0x29, 0x80);
153  pm_write8(0x28, 0x61);
154 }
155 
158 };
struct chip_operations mainboard_ops
Definition: mainboard.c:19
static void pm_write8(uint8_t reg, uint8_t value)
Definition: acpimmio.h:181
static void misc_write8(uint8_t reg, uint8_t value)
Definition: acpimmio.h:271
static void gpio_100_write8(uint8_t reg, uint8_t value)
static void iomux_write8(uint8_t reg, uint8_t value)
#define ARRAY_SIZE(a)
Definition: helpers.h:12
#define printk(level,...)
Definition: stdlib.h:16
void outb(u8 val, u16 port)
DEVTREE_CONST struct device * pcidev_on_root(uint8_t dev, uint8_t fn)
Definition: device_const.c:260
static uintptr_t spi_base
Definition: fch_spi_util.c:12
static u8 fch_gpio_state(unsigned int gpio_nr)
Definition: gpio_oem.h:20
static __always_inline u32 pci_read_config32(const struct device *dev, u16 reg)
Definition: pci_ops.h:58
static const u16 sio_init_table[]
Definition: mainboard.c:29
#define SIO_RUNTIME_BASE
Definition: mainboard.c:28
static const u8 mainboard_intr_data[]
Definition: mainboard.c:17
static void mainboard_enable(struct device *dev)
Definition: mainboard.c:131
static void pirq_setup(void)
Definition: mainboard.c:59
static void init(struct device *dev)
Definition: mainboard.c:64
#define BIOS_INFO
BIOS_INFO - Expected events.
Definition: loglevel.h:113
#define BIOS_DEBUG
BIOS_DEBUG - Verbose output.
Definition: loglevel.h:128
int sema_send_alive(void)
Definition: sema.c:49
const u8 * intr_data_ptr
Definition: amd_pci_util.c:13
#define GPIO_BASE
Definition: lpc.h:21
unsigned long uintptr_t
Definition: stdint.h:21
uint16_t u16
Definition: stdint.h:48
uint8_t u8
Definition: stdint.h:45
void(* enable_dev)(struct device *dev)
Definition: device.h:24
void(* init)(struct device *dev)
Definition: device.h:42
Definition: device.h:107
struct device_operations * ops
Definition: device.h:143
u8 val
Definition: sys.c:300