2 * This file is part of the coreboot project.
4 * Copyright (C) 2011 Google Inc
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.
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.
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
22 #include <arch/romcc_io.h>
24 #include <device/pci_def.h>
27 PCI_DEV(CONFIG_OXFORD_OXPCIE_BRIDGE_BUS, \
28 CONFIG_OXFORD_OXPCIE_BRIDGE_DEVICE, \
29 CONFIG_OXFORD_OXPCIE_BRIDGE_FUNCTION)
31 #define OXPCIE_DEVICE \
32 PCI_DEV(CONFIG_OXFORD_OXPCIE_BRIDGE_SUBORDINATE, 0, 0)
34 #define OXPCIE_DEVICE_3 \
35 PCI_DEV(CONFIG_OXFORD_OXPCIE_BRIDGE_SUBORDINATE, 0, 3)
37 void oxford_init(void)
41 /* First we reset the secondary bus */
42 reg16 = pci_read_config16(PCIE_BRIDGE, PCI_BRIDGE_CONTROL);
43 reg16 |= (1 << 6); /* SRESET */
44 pci_write_config16(PCIE_BRIDGE, PCI_BRIDGE_CONTROL, reg16);
46 /* Assume we don't have to wait here forever */
48 /* Read back and clear reset bit. */
49 reg16 = pci_read_config16(PCIE_BRIDGE, PCI_BRIDGE_CONTROL);
50 reg16 &= ~(1 << 6); /* SRESET */
51 pci_write_config16(PCIE_BRIDGE, PCI_BRIDGE_CONTROL, reg16);
53 /* Set up subordinate bus number */
54 pci_write_config8(PCIE_BRIDGE, PCI_SECONDARY_BUS, 0x00);
55 pci_write_config8(PCIE_BRIDGE, PCI_SUBORDINATE_BUS, 0x00);
56 pci_write_config8(PCIE_BRIDGE, PCI_SECONDARY_BUS,
57 CONFIG_OXFORD_OXPCIE_BRIDGE_SUBORDINATE);
58 pci_write_config8(PCIE_BRIDGE, PCI_SUBORDINATE_BUS,
59 CONFIG_OXFORD_OXPCIE_BRIDGE_SUBORDINATE);
61 /* Memory window for the OXPCIe952 card */
62 // XXX is the calculation of base and limit corect?
63 pci_write_config32(PCIE_BRIDGE, PCI_MEMORY_BASE,
64 ((CONFIG_OXFORD_OXPCIE_BASE_ADDRESS & 0xffff0000) |
65 ((CONFIG_OXFORD_OXPCIE_BASE_ADDRESS >> 16) & 0xff00)));
67 /* Enable memory access through bridge */
68 reg16 = pci_read_config16(PCIE_BRIDGE, PCI_COMMAND);
69 reg16 |= PCI_COMMAND_MEMORY;
70 pci_write_config16(PCIE_BRIDGE, PCI_COMMAND, reg16);
72 // FIXME Add a timeout or this will hang forever if
73 // no device is in the slot.
75 while ((id == 0) || (id == 0xffffffff))
76 id = pci_read_config32(OXPCIE_DEVICE, PCI_VENDOR_ID);
78 u32 device = OXPCIE_DEVICE; /* unknown default */
80 case 0xc1181415: /* e.g. Startech PEX1S1PMINI */
81 /* On this device function 0 is the parallel port, and
82 * function 3 is the serial port. So let's go look for
85 id = pci_read_config32(OXPCIE_DEVICE_3, PCI_VENDOR_ID);
88 device = OXPCIE_DEVICE_3;
90 case 0xc1581415: /* e.g. Startech MPEX2S952 */
91 device = OXPCIE_DEVICE;
95 /* Setup base address on device */
96 pci_write_config32(device, PCI_BASE_ADDRESS_0,
97 CONFIG_OXFORD_OXPCIE_BASE_ADDRESS);
99 /* Enable memory on device */
100 reg16 = pci_read_config16(device, PCI_COMMAND);
101 reg16 |= PCI_COMMAND_MEMORY;
102 pci_write_config16(device, PCI_COMMAND, reg16);
104 /* Now the UART initialization */
105 u32 uart0_base = CONFIG_OXFORD_OXPCIE_BASE_ADDRESS + 0x1000;
107 uart8250_mem_init(uart0_base, (4000000 / CONFIG_TTYS0_BAUD));