blob: 4f7a3cb105b525135a2690c98c142aadf9334cec [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
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
20#include <stdint.h>
21#include <arch/io.h>
22#include <arch/romcc_io.h>
Gabe Black4d04a712011-10-05 01:52:08 -070023#include <cpu/x86/car.h>
24#include <delay.h>
Stefan Reinauer4885daa2011-04-26 23:47:04 +000025#include <uart8250.h>
26#include <device/pci_def.h>
27
28#define PCIE_BRIDGE \
29 PCI_DEV(CONFIG_OXFORD_OXPCIE_BRIDGE_BUS, \
30 CONFIG_OXFORD_OXPCIE_BRIDGE_DEVICE, \
31 CONFIG_OXFORD_OXPCIE_BRIDGE_FUNCTION)
32
33#define OXPCIE_DEVICE \
Stefan Reinauer5ff7c132011-10-31 12:56:45 -070034 PCI_DEV(CONFIG_OXFORD_OXPCIE_BRIDGE_SUBORDINATE, 0, 0)
Stefan Reinauer4885daa2011-04-26 23:47:04 +000035
Stefan Reinauera6087d12011-05-09 15:19:29 -070036#define OXPCIE_DEVICE_3 \
37 PCI_DEV(CONFIG_OXFORD_OXPCIE_BRIDGE_SUBORDINATE, 0, 3)
38
Gabe Black4d04a712011-10-05 01:52:08 -070039#if defined(__PRE_RAM__)
40int oxford_oxpcie_present CAR_GLOBAL;
41
Stefan Reinauer4885daa2011-04-26 23:47:04 +000042void oxford_init(void)
43{
44 u16 reg16;
Gabe Black4d04a712011-10-05 01:52:08 -070045 oxford_oxpcie_present = 1;
Stefan Reinauer4885daa2011-04-26 23:47:04 +000046
47 /* First we reset the secondary bus */
48 reg16 = pci_read_config16(PCIE_BRIDGE, PCI_BRIDGE_CONTROL);
49 reg16 |= (1 << 6); /* SRESET */
50 pci_write_config16(PCIE_BRIDGE, PCI_BRIDGE_CONTROL, reg16);
51
52 /* Assume we don't have to wait here forever */
53
54 /* Read back and clear reset bit. */
55 reg16 = pci_read_config16(PCIE_BRIDGE, PCI_BRIDGE_CONTROL);
56 reg16 &= ~(1 << 6); /* SRESET */
57 pci_write_config16(PCIE_BRIDGE, PCI_BRIDGE_CONTROL, reg16);
58
59 /* Set up subordinate bus number */
60 pci_write_config8(PCIE_BRIDGE, PCI_SECONDARY_BUS, 0x00);
61 pci_write_config8(PCIE_BRIDGE, PCI_SUBORDINATE_BUS, 0x00);
62 pci_write_config8(PCIE_BRIDGE, PCI_SECONDARY_BUS,
63 CONFIG_OXFORD_OXPCIE_BRIDGE_SUBORDINATE);
64 pci_write_config8(PCIE_BRIDGE, PCI_SUBORDINATE_BUS,
65 CONFIG_OXFORD_OXPCIE_BRIDGE_SUBORDINATE);
66
67 /* Memory window for the OXPCIe952 card */
68 // XXX is the calculation of base and limit corect?
Stefan Reinauer5ff7c132011-10-31 12:56:45 -070069 pci_write_config32(PCIE_BRIDGE, PCI_MEMORY_BASE,
Stefan Reinauer4885daa2011-04-26 23:47:04 +000070 ((CONFIG_OXFORD_OXPCIE_BASE_ADDRESS & 0xffff0000) |
71 ((CONFIG_OXFORD_OXPCIE_BASE_ADDRESS >> 16) & 0xff00)));
72
73 /* Enable memory access through bridge */
74 reg16 = pci_read_config16(PCIE_BRIDGE, PCI_COMMAND);
75 reg16 |= PCI_COMMAND_MEMORY;
76 pci_write_config16(PCIE_BRIDGE, PCI_COMMAND, reg16);
77
Gabe Black4d04a712011-10-05 01:52:08 -070078 u32 timeout = 20000; // Timeout in 10s of microseconds.
Stefan Reinauer4885daa2011-04-26 23:47:04 +000079 u32 id = 0;
Gabe Black4d04a712011-10-05 01:52:08 -070080 for (;;) {
Stefan Reinauer4885daa2011-04-26 23:47:04 +000081 id = pci_read_config32(OXPCIE_DEVICE, PCI_VENDOR_ID);
Gabe Black4d04a712011-10-05 01:52:08 -070082 if (!timeout-- || (id != 0 && id != 0xffffffff))
83 break;
84 udelay(10);
85 }
Stefan Reinauer4885daa2011-04-26 23:47:04 +000086
Stefan Reinauera6087d12011-05-09 15:19:29 -070087 u32 device = OXPCIE_DEVICE; /* unknown default */
88 switch (id) {
89 case 0xc1181415: /* e.g. Startech PEX1S1PMINI */
90 /* On this device function 0 is the parallel port, and
91 * function 3 is the serial port. So let's go look for
92 * the UART.
93 */
94 id = pci_read_config32(OXPCIE_DEVICE_3, PCI_VENDOR_ID);
95 if (id != 0xc11b1415)
96 return;
97 device = OXPCIE_DEVICE_3;
98 break;
99 case 0xc1581415: /* e.g. Startech MPEX2S952 */
100 device = OXPCIE_DEVICE;
101 break;
Gabe Black4d04a712011-10-05 01:52:08 -0700102 default:
103 /* No UART here. */
104 oxford_oxpcie_present = 0;
105 return;
Stefan Reinauera6087d12011-05-09 15:19:29 -0700106 }
107
Stefan Reinauer4885daa2011-04-26 23:47:04 +0000108 /* Setup base address on device */
Stefan Reinauera6087d12011-05-09 15:19:29 -0700109 pci_write_config32(device, PCI_BASE_ADDRESS_0,
Stefan Reinauer4885daa2011-04-26 23:47:04 +0000110 CONFIG_OXFORD_OXPCIE_BASE_ADDRESS);
111
112 /* Enable memory on device */
Stefan Reinauera6087d12011-05-09 15:19:29 -0700113 reg16 = pci_read_config16(device, PCI_COMMAND);
Stefan Reinauer4885daa2011-04-26 23:47:04 +0000114 reg16 |= PCI_COMMAND_MEMORY;
Stefan Reinauera6087d12011-05-09 15:19:29 -0700115 pci_write_config16(device, PCI_COMMAND, reg16);
Stefan Reinauer4885daa2011-04-26 23:47:04 +0000116
117 /* Now the UART initialization */
118 u32 uart0_base = CONFIG_OXFORD_OXPCIE_BASE_ADDRESS + 0x1000;
119
120 uart8250_mem_init(uart0_base, (4000000 / CONFIG_TTYS0_BAUD));
121}
122
Gabe Black4d04a712011-10-05 01:52:08 -0700123#endif