blob: d04e9d4df0fef77b1bd1035a9a70c5761cc06d0e [file] [log] [blame]
Stefan Reinauer4885daa2011-04-26 23:47:04 +00001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2011 Google Inc
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
Paul Menzela46a7122013-02-23 18:37:27 +010017 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Stefan Reinauer4885daa2011-04-26 23:47:04 +000018 */
19
20#include <stdint.h>
21#include <arch/io.h>
Stefan Reinauerfd4f4132013-06-19 12:25:44 -070022#include <arch/early_variables.h>
Gabe Black4d04a712011-10-05 01:52:08 -070023#include <delay.h>
Stefan Reinauer4885daa2011-04-26 23:47:04 +000024#include <uart8250.h>
25#include <device/pci_def.h>
26
27#define PCIE_BRIDGE \
28 PCI_DEV(CONFIG_OXFORD_OXPCIE_BRIDGE_BUS, \
29 CONFIG_OXFORD_OXPCIE_BRIDGE_DEVICE, \
30 CONFIG_OXFORD_OXPCIE_BRIDGE_FUNCTION)
31
32#define OXPCIE_DEVICE \
Stefan Reinauer5ff7c132011-10-31 12:56:45 -070033 PCI_DEV(CONFIG_OXFORD_OXPCIE_BRIDGE_SUBORDINATE, 0, 0)
Stefan Reinauer4885daa2011-04-26 23:47:04 +000034
Stefan Reinauera6087d12011-05-09 15:19:29 -070035#define OXPCIE_DEVICE_3 \
36 PCI_DEV(CONFIG_OXFORD_OXPCIE_BRIDGE_SUBORDINATE, 0, 3)
37
Gabe Black4d04a712011-10-05 01:52:08 -070038#if defined(__PRE_RAM__)
39int oxford_oxpcie_present CAR_GLOBAL;
40
Stefan Reinauer4885daa2011-04-26 23:47:04 +000041void oxford_init(void)
42{
43 u16 reg16;
Gabe Black4d04a712011-10-05 01:52:08 -070044 oxford_oxpcie_present = 1;
Stefan Reinauer4885daa2011-04-26 23:47:04 +000045
46 /* First we reset the secondary bus */
47 reg16 = pci_read_config16(PCIE_BRIDGE, PCI_BRIDGE_CONTROL);
48 reg16 |= (1 << 6); /* SRESET */
49 pci_write_config16(PCIE_BRIDGE, PCI_BRIDGE_CONTROL, reg16);
50
51 /* Assume we don't have to wait here forever */
52
53 /* Read back and clear reset bit. */
54 reg16 = pci_read_config16(PCIE_BRIDGE, PCI_BRIDGE_CONTROL);
55 reg16 &= ~(1 << 6); /* SRESET */
56 pci_write_config16(PCIE_BRIDGE, PCI_BRIDGE_CONTROL, reg16);
57
58 /* Set up subordinate bus number */
59 pci_write_config8(PCIE_BRIDGE, PCI_SECONDARY_BUS, 0x00);
60 pci_write_config8(PCIE_BRIDGE, PCI_SUBORDINATE_BUS, 0x00);
61 pci_write_config8(PCIE_BRIDGE, PCI_SECONDARY_BUS,
62 CONFIG_OXFORD_OXPCIE_BRIDGE_SUBORDINATE);
63 pci_write_config8(PCIE_BRIDGE, PCI_SUBORDINATE_BUS,
64 CONFIG_OXFORD_OXPCIE_BRIDGE_SUBORDINATE);
65
66 /* Memory window for the OXPCIe952 card */
Martin Roth56889792013-07-09 21:39:46 -060067 // XXX is the calculation of base and limit correct?
Stefan Reinauer5ff7c132011-10-31 12:56:45 -070068 pci_write_config32(PCIE_BRIDGE, PCI_MEMORY_BASE,
Stefan Reinauer4885daa2011-04-26 23:47:04 +000069 ((CONFIG_OXFORD_OXPCIE_BASE_ADDRESS & 0xffff0000) |
70 ((CONFIG_OXFORD_OXPCIE_BASE_ADDRESS >> 16) & 0xff00)));
71
72 /* Enable memory access through bridge */
73 reg16 = pci_read_config16(PCIE_BRIDGE, PCI_COMMAND);
74 reg16 |= PCI_COMMAND_MEMORY;
75 pci_write_config16(PCIE_BRIDGE, PCI_COMMAND, reg16);
76
Gabe Black4d04a712011-10-05 01:52:08 -070077 u32 timeout = 20000; // Timeout in 10s of microseconds.
Stefan Reinauer4885daa2011-04-26 23:47:04 +000078 u32 id = 0;
Gabe Black4d04a712011-10-05 01:52:08 -070079 for (;;) {
Stefan Reinauer4885daa2011-04-26 23:47:04 +000080 id = pci_read_config32(OXPCIE_DEVICE, PCI_VENDOR_ID);
Gabe Black4d04a712011-10-05 01:52:08 -070081 if (!timeout-- || (id != 0 && id != 0xffffffff))
82 break;
83 udelay(10);
84 }
Stefan Reinauer4885daa2011-04-26 23:47:04 +000085
Stefan Reinauera6087d12011-05-09 15:19:29 -070086 u32 device = OXPCIE_DEVICE; /* unknown default */
87 switch (id) {
88 case 0xc1181415: /* e.g. Startech PEX1S1PMINI */
89 /* On this device function 0 is the parallel port, and
90 * function 3 is the serial port. So let's go look for
91 * the UART.
92 */
93 id = pci_read_config32(OXPCIE_DEVICE_3, PCI_VENDOR_ID);
94 if (id != 0xc11b1415)
95 return;
96 device = OXPCIE_DEVICE_3;
97 break;
98 case 0xc1581415: /* e.g. Startech MPEX2S952 */
99 device = OXPCIE_DEVICE;
100 break;
Gabe Black4d04a712011-10-05 01:52:08 -0700101 default:
102 /* No UART here. */
103 oxford_oxpcie_present = 0;
104 return;
Stefan Reinauera6087d12011-05-09 15:19:29 -0700105 }
106
Stefan Reinauer4885daa2011-04-26 23:47:04 +0000107 /* Setup base address on device */
Stefan Reinauera6087d12011-05-09 15:19:29 -0700108 pci_write_config32(device, PCI_BASE_ADDRESS_0,
Stefan Reinauer4885daa2011-04-26 23:47:04 +0000109 CONFIG_OXFORD_OXPCIE_BASE_ADDRESS);
110
111 /* Enable memory on device */
Stefan Reinauera6087d12011-05-09 15:19:29 -0700112 reg16 = pci_read_config16(device, PCI_COMMAND);
Stefan Reinauer4885daa2011-04-26 23:47:04 +0000113 reg16 |= PCI_COMMAND_MEMORY;
Stefan Reinauera6087d12011-05-09 15:19:29 -0700114 pci_write_config16(device, PCI_COMMAND, reg16);
Stefan Reinauer4885daa2011-04-26 23:47:04 +0000115
116 /* Now the UART initialization */
117 u32 uart0_base = CONFIG_OXFORD_OXPCIE_BASE_ADDRESS + 0x1000;
118
119 uart8250_mem_init(uart0_base, (4000000 / CONFIG_TTYS0_BAUD));
120}
121
Gabe Black4d04a712011-10-05 01:52:08 -0700122#endif