blob: a678559c7e86f7e273e6329287cf64a3e717357a [file] [log] [blame]
Kyösti Mälkkif09e6d42015-01-10 12:13:23 +02001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2011 Advanced Micro Devices, Inc.
Kyösti Mälkki8c190f32014-11-14 16:20:22 +02005 * Copyright (C) 2013-2014 Sage Electronic Engineering, LLC
Kyösti Mälkkif09e6d42015-01-10 12:13:23 +02006 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; version 2 of the License.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
Kyösti Mälkkif09e6d42015-01-10 12:13:23 +020015 */
16
17#include <console/console.h>
18#include <device/device.h>
19#include <device/pci.h>
20#include <arch/io.h>
21#include <cpu/x86/msr.h>
22#include <device/pci_def.h>
Stefan Reinauer13e41822015-04-27 14:02:36 -070023#include <southbridge/amd/common/amd_pci_util.h>
Kyösti Mälkkif09e6d42015-01-10 12:13:23 +020024#include <southbridge/amd/cimx/cimx_util.h>
25#include <arch/acpi.h>
26#include <northbridge/amd/agesa/BiosCallOuts.h>
Kyösti Mälkkif09e6d42015-01-10 12:13:23 +020027#include <cpu/amd/mtrr.h>
Kyösti Mälkkicd32da42015-10-14 22:17:22 +030028#include <smbios.h>
29#include <string.h>
Kyösti Mälkkif09e6d42015-01-10 12:13:23 +020030#include "SBPLATFORM.h"
31#include <southbridge/amd/cimx/sb800/pci_devs.h>
32#include <northbridge/amd/agesa/family14/pci_devs.h>
Kyösti Mälkki017c2152015-05-11 22:53:19 +030033#include <superio/nuvoton/nct5104d/nct5104d.h>
Kyösti Mälkki78093562014-11-11 17:22:23 +020034#include "gpio_ftns.h"
Kyösti Mälkkif09e6d42015-01-10 12:13:23 +020035
36void set_pcie_reset(void);
37void set_pcie_dereset(void);
38
39/***********************************************************
40 * These arrays set up the FCH PCI_INTR registers 0xC00/0xC01.
41 * This table is responsible for physically routing the PIC and
42 * IOAPIC IRQs to the different PCI devices on the system. It
43 * is read and written via registers 0xC00/0xC01 as an
44 * Index/Data pair. These values are chipset and mainboard
45 * dependent and should be updated accordingly.
46 *
47 * These values are used by the PCI configuration space,
48 * MP Tables. TODO: Make ACPI use these values too.
49 *
Kyösti Mälkki8c190f32014-11-14 16:20:22 +020050 * The PCI INTA/B/C/D pins are connected to
Kyösti Mälkkif09e6d42015-01-10 12:13:23 +020051 * FCH pins INTE/F/G/H on the schematic so these need
52 * to be routed as well.
53 */
54static const u8 mainboard_picr_data[FCH_INT_TABLE_SIZE] = {
55 /* INTA# - INTH# */
56 [0x00] = 0x0A,0x0B,0x0A,0x0B,0x0A,0x0B,0x0A,0x0B,
57 /* Misc-nil,0,1,2, INT from Serial irq */
Kyösti Mälkki8c190f32014-11-14 16:20:22 +020058 [0x08] = 0x00,0xF1,0x00,0x00,0x1F,0x1F,0x1F,0x1F,
Kyösti Mälkkif09e6d42015-01-10 12:13:23 +020059 /* SCI, SMBUS0, ASF, HDA, FC, GEC, PerfMon */
60 [0x10] = 0x1F,0x1F,0x1F,0x0A,0x1F,0x1F,0x1F,
61 /* IMC INT0 - 5 */
62 [0x20] = 0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,
63 /* USB Devs 18/19/20/22 INTA-C */
Kyösti Mälkki5d899c42015-01-14 12:58:53 +020064 [0x30] = 0x0A,0x0B,0x0A,0x0B,0x0A,0x0B,0x0A,
Kyösti Mälkkif09e6d42015-01-10 12:13:23 +020065 /* IDE, SATA */
66 [0x40] = 0x0B,0x0B,
67 /* GPPInt0 - 3 */
68 [0x50] = 0x0A,0x0B,0x0A,0x0B
69};
70
71static const u8 mainboard_intr_data[FCH_INT_TABLE_SIZE] = {
72 /* INTA# - INTH# */
73 [0x00] = 0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,
74 /* Misc-nil,0,1,2, INT from Serial irq */
75 [0x08] = 0x00,0x00,0x00,0x00,0x1F,0x1F,0x1F,0x1F,
76 /* SCI, SMBUS0, ASF, HDA, FC, GEC, PerMon */
77 [0x10] = 0x09,0x1F,0x1F,0x10,0x1F,0x12,0x1F,
78 /* IMC INT0 - 5 */
79 [0x20] = 0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,
80 /* USB Devs 18/19/22/20 INTA-C */
81 [0x30] = 0x12,0x11,0x12,0x11,0x12,0x11,0x12,
82 /* IDE, SATA */
83 [0x40] = 0x11,0x13,
84 /* GPPInt0 - 3 */
85 [0x50] = 0x10,0x11,0x12,0x13
86};
87
88/*
89 * This table defines the index into the picr/intr_data
90 * tables for each device. Any enabled device and slot
91 * that uses hardware interrupts should have an entry
92 * in this table to define its index into the FCH
93 * PCI_INTR register 0xC00/0xC01. This index will define
94 * the interrupt that it should use. Putting PIRQ_A into
95 * the PIN A index for a device will tell that device to
96 * use PIC IRQ 10 if it uses PIN A for its hardware INT.
97 */
98/*
Kyösti Mälkki8c190f32014-11-14 16:20:22 +020099 * The PCI slot INTA/B/C/D connected to PIRQE/F/G/H
100 * but because of PCI INT_PIN swizzle isnt implemented to match
Kyösti Mälkkif09e6d42015-01-10 12:13:23 +0200101 * the IDSEL (dev 3) of the slot, the table is adjusted for the
102 * swizzle and INTA is connected to PIRQH so PINA/B/C/D on
103 * off-chip devices should get mapped to PIRQH/E/F/G.
104 */
105static const struct pirq_struct mainboard_pirq_data[] = {
106 /* {PCI_devfn, {PIN A, PIN B, PIN C, PIN D}}, */
107 {GFX_DEVFN, {PIRQ_A, PIRQ_B, PIRQ_NC, PIRQ_NC}}, /* VGA: 01.0 */
108 {NB_PCIE_PORT1_DEVFN, {PIRQ_A, PIRQ_B, PIRQ_C, PIRQ_D}}, /* NIC: 04.0 */
Kyösti Mälkki8c190f32014-11-14 16:20:22 +0200109 {NB_PCIE_PORT2_DEVFN, {PIRQ_A, PIRQ_B, PIRQ_C, PIRQ_D}}, /* NIC: 05.0 */
110 {NB_PCIE_PORT3_DEVFN, {PIRQ_A, PIRQ_B, PIRQ_C, PIRQ_D}}, /* NIC: 06.0 */
111 {NB_PCIE_PORT4_DEVFN, {PIRQ_A, PIRQ_B, PIRQ_C, PIRQ_D}}, /* miniPCIe: 07.0 */
Kyösti Mälkkif09e6d42015-01-10 12:13:23 +0200112 {SATA_DEVFN, {PIRQ_SATA, PIRQ_NC, PIRQ_NC, PIRQ_NC}}, /* SATA: 11.0 */
113 {OHCI1_DEVFN, {PIRQ_OHCI1, PIRQ_NC, PIRQ_NC, PIRQ_NC}}, /* OHCI1: 12.0 */
114 {EHCI1_DEVFN, {PIRQ_NC, PIRQ_EHCI1, PIRQ_NC, PIRQ_NC}}, /* EHCI1: 12.2 */
115 {OHCI2_DEVFN, {PIRQ_OHCI2, PIRQ_NC, PIRQ_NC, PIRQ_NC}}, /* OHCI2: 13.0 */
116 {EHCI2_DEVFN, {PIRQ_NC, PIRQ_EHCI2, PIRQ_NC, PIRQ_NC}}, /* EHCI2: 13.2 */
117 {SMBUS_DEVFN, {PIRQ_SMBUS, PIRQ_NC, PIRQ_NC, PIRQ_NC}}, /* SMBUS: 14.0 */
118 {IDE_DEVFN, {PIRQ_NC, PIRQ_IDE, PIRQ_NC, PIRQ_NC}}, /* IDE: 14.1 */
119 {HDA_DEVFN, {PIRQ_HDA, PIRQ_NC, PIRQ_NC, PIRQ_NC}}, /* HDA: 14.2 */
120 {SB_PCI_PORT_DEVFN, {PIRQ_H, PIRQ_E, PIRQ_F, PIRQ_G}}, /* PCI bdg: 14.4 */
121 {OHCI4_DEVFN, {PIRQ_NC, PIRQ_NC, PIRQ_OHCI4, PIRQ_NC}}, /* OHCI4: 14.5 */
Kyösti Mälkki8c190f32014-11-14 16:20:22 +0200122 {SB_PCIE_PORT1_DEVFN, {PIRQ_A, PIRQ_B, PIRQ_C, PIRQ_D}}, /* miniPCIe: 15.0 */
Kyösti Mälkkif09e6d42015-01-10 12:13:23 +0200123 {OHCI3_DEVFN, {PIRQ_OHCI3, PIRQ_NC, PIRQ_NC, PIRQ_NC}}, /* OHCI3: 16.0 */
124 {EHCI3_DEVFN, {PIRQ_NC, PIRQ_EHCI3, PIRQ_NC, PIRQ_NC}}, /* EHCI3: 16.2 */
125};
126
127/* PIRQ Setup */
128static void pirq_setup(void)
129{
130 pirq_data_ptr = mainboard_pirq_data;
131 pirq_data_size = sizeof(mainboard_pirq_data) / sizeof(struct pirq_struct);
132 intr_data_ptr = mainboard_intr_data;
133 picr_data_ptr = mainboard_picr_data;
134}
135
Kyösti Mälkki017c2152015-05-11 22:53:19 +0300136/* Wrapper to enable GPIO/UART devices under menuconfig. Revisit
137 * once configuration file format for SPI flash storage is complete.
138 */
139#define SIO_PORT 0x2e
140
141static void config_gpio_mux(void)
142{
143 struct device *uart, *gpio;
144
145 uart = dev_find_slot_pnp(SIO_PORT, NCT5104D_SP3);
146 gpio = dev_find_slot_pnp(SIO_PORT, NCT5104D_GPIO0);
147 if (uart)
Kyösti Mälkki17163752016-05-27 13:07:50 +0300148 uart->enabled = CONFIG_APU1_PINMUX_UART_C;
Kyösti Mälkki017c2152015-05-11 22:53:19 +0300149 if (gpio)
Kyösti Mälkki17163752016-05-27 13:07:50 +0300150 gpio->enabled = CONFIG_APU1_PINMUX_GPIO0;
Kyösti Mälkki017c2152015-05-11 22:53:19 +0300151
152 uart = dev_find_slot_pnp(SIO_PORT, NCT5104D_SP4);
153 gpio = dev_find_slot_pnp(SIO_PORT, NCT5104D_GPIO1);
154 if (uart)
Kyösti Mälkki17163752016-05-27 13:07:50 +0300155 uart->enabled = CONFIG_APU1_PINMUX_UART_D;
Kyösti Mälkki017c2152015-05-11 22:53:19 +0300156 if (gpio)
Kyösti Mälkki17163752016-05-27 13:07:50 +0300157 gpio->enabled = CONFIG_APU1_PINMUX_GPIO1;
Kyösti Mälkki017c2152015-05-11 22:53:19 +0300158}
159
Kyösti Mälkkie1c36ae2015-10-13 15:01:15 +0300160static void pnp_raw_resource(struct device *dev, u8 reg, u8 val)
161{
162 struct resource *res;
163 res = new_resource(dev, reg);
164 res->base = val;
165 res->size = 0;
166 res->flags |= IORESOURCE_IRQ | IORESOURCE_ASSIGNED;
167}
168
169static void config_addon_uart(void)
170{
171 struct device *uart;
172
173 uart = dev_find_slot_pnp(SIO_PORT, NCT5104D_SP3);
174 if (uart && uart->enabled && CONFIG_UART_C_RS485)
175 pnp_raw_resource(uart, 0xf2, 0x12);
176
177 uart = dev_find_slot_pnp(SIO_PORT, NCT5104D_SP4);
178 if (uart && uart->enabled && CONFIG_UART_D_RS485)
179 pnp_raw_resource(uart, 0xf2, 0x12);
180}
181
Kyösti Mälkkif09e6d42015-01-10 12:13:23 +0200182/**
183 * TODO
184 * SB CIMx callback
185 */
186void set_pcie_reset(void)
187{
188}
189
190/**
191 * TODO
192 * mainboard specific SB CIMx callback
193 */
194void set_pcie_dereset(void)
195{
196}
197
Kyösti Mälkkif09e6d42015-01-10 12:13:23 +0200198/**********************************************
199 * Enable the dedicated functions of the board.
200 **********************************************/
201static void mainboard_enable(device_t dev)
202{
203 printk(BIOS_INFO, "Mainboard " CONFIG_MAINBOARD_PART_NUMBER " Enable.\n");
204
Kyösti Mälkki017c2152015-05-11 22:53:19 +0300205 config_gpio_mux();
Kyösti Mälkkie1c36ae2015-10-13 15:01:15 +0300206 config_addon_uart();
Kyösti Mälkki017c2152015-05-11 22:53:19 +0300207
Felix Heldb06015b2015-11-06 18:31:01 +0100208 /* Power off unused clock pins of GPP PCIe devices */
209 u8 *misc_mem_clk_cntrl = (u8 *)(ACPI_MMIO_BASE + MISC_BASE);
210 /* GPP CLK0-2 are connected to the 3 ethernet chips
211 * GPP CLK3-4 are connected to the miniPCIe slots */
Felix Helddf95b512015-11-06 18:32:43 +0100212 write8(misc_mem_clk_cntrl + 0, 0x21);
213 write8(misc_mem_clk_cntrl + 1, 0x43);
Felix Heldb06015b2015-11-06 18:31:01 +0100214 /* GPP CLK5 is only connected to test pads -> disable */
Felix Helddf95b512015-11-06 18:32:43 +0100215 write8(misc_mem_clk_cntrl + 2, 0x05);
Felix Heldb06015b2015-11-06 18:31:01 +0100216 /* disable unconnected GPP CLK6-8 and SLT_GFX_CLK */
217 write8(misc_mem_clk_cntrl + 3, 0x00);
218 write8(misc_mem_clk_cntrl + 4, 0x00);
219
Kyösti Mälkkif09e6d42015-01-10 12:13:23 +0200220 /* Initialize the PIRQ data structures for consumption */
221 pirq_setup();
222}
223
Kyösti Mälkkicd32da42015-10-14 22:17:22 +0300224/*
225 * We will stuff a modified version of the first NICs (BDF 1:0.0) MAC address
226 * into the smbios serial number location.
227 */
228const char *smbios_mainboard_serial_number(void)
229{
230 static char serial[10];
231 device_t nic_dev;
232 uintptr_t bar18;
233 u32 mac_addr = 0;
234 int i;
235
236 nic_dev = dev_find_slot(1, PCI_DEVFN(0, 0));
237 if ((serial[0] != 0) || !nic_dev)
238 return serial;
239
240 /* Read in the last 3 bytes of NIC's MAC address. */
241 bar18 = pci_read_config32(nic_dev, 0x18);
242 bar18 &= 0xFFFFFC00;
243 for (i = 3; i < 6; i++) {
244 mac_addr <<= 8;
245 mac_addr |= read8((u8 *)bar18 + i);
246 }
247 mac_addr &= 0x00FFFFFF;
248 mac_addr /= 4;
249 mac_addr -= 64;
250
251 snprintf(serial, sizeof(serial), "%d", mac_addr);
252 return serial;
253}
254
Tobias Diedrich3385ebe2016-03-13 21:19:45 +0100255/*
256 * Set up "Over Current Control 1" (reg 0x58) on the first OHCI device.
257 * The remaining ports on the second device are for mcpie2/sdcard and
258 * can stay at the power-on default value.
259 *
260 * The schematic shows this transposed mapping for the first device:
261 * chipset port 0 -> port 1 (j12 external 2, usboc0#)
262 * chipset port 1 -> port 4 (j17 mpcie1)
263 * chipset port 2 -> port 2 (j14 header row1, usboc1#)
264 * chipset port 3 -> port 3 (j14 header row2, usboc1#)
265 * chipset port 4 -> port 0 (j12 external 1. usboc0#)
266 *
267 * Register mapping:
268 * bit0-3: Mapping for HS Port 0
269 * bit4-7: Mapping for HS Port 1
270 * bit8-11: Mapping for HS Port 2
271 * bit12-15: Mapping for HS Port 3
272 * bit16-19: Mapping for HS Port 4
273 * bit20-31: Reserved (0)
274 *
275 * power-on default: 0xfffff
276 * A value >7 will disable the overcurrent detection.
277 */
278static void usb_oc_setup(void)
279{
280 device_t dev = dev_find_slot(0, PCI_DEVFN(0x12, 0));
281
282 pci_write_config32(dev, 0x58, 0x011f0);
283}
284
Kyösti Mälkki9aba60e2016-05-30 16:56:11 +0300285/*
286 * We will stuff the memory size into the smbios sku location.
287 */
288const char *smbios_mainboard_sku(void)
289{
290 static char sku[5];
291 if (sku[0] != 0)
292 return sku;
293
294 if (!get_spd_offset())
295 snprintf(sku, sizeof(sku), "2 GB");
296 else
297 snprintf(sku, sizeof(sku), "4 GB");
298 return sku;
299}
300
Kyösti Mälkki78093562014-11-11 17:22:23 +0200301static void mainboard_final(void *chip_info)
302{
303 u32 mmio_base;
304
305 printk(BIOS_INFO, "Mainboard " CONFIG_MAINBOARD_PART_NUMBER " Final.\n");
306
307 /*
308 * LED1/D7/GPIO_189 should be 0
309 * LED2/D6/GPIO_190 should be 1
310 * LED3/D5/GPIO_191 should be 1
311 */
312 mmio_base = find_gpio_base();
313 configure_gpio(mmio_base, GPIO_189, GPIO_FTN_1, GPIO_OUTPUT | GPIO_DATA_LOW);
314 configure_gpio(mmio_base, GPIO_190, GPIO_FTN_1, GPIO_OUTPUT | GPIO_DATA_HIGH);
315 configure_gpio(mmio_base, GPIO_191, GPIO_FTN_1, GPIO_OUTPUT | GPIO_DATA_HIGH);
Tobias Diedrich3385ebe2016-03-13 21:19:45 +0100316 usb_oc_setup();
Kyösti Mälkki78093562014-11-11 17:22:23 +0200317}
318
Kyösti Mälkkif09e6d42015-01-10 12:13:23 +0200319struct chip_operations mainboard_ops = {
320 .enable_dev = mainboard_enable,
Kyösti Mälkki78093562014-11-11 17:22:23 +0200321 .final = mainboard_final,
Kyösti Mälkkif09e6d42015-01-10 12:13:23 +0200322};