Stefan Reinauer | 4885daa | 2011-04-26 23:47:04 +0000 | [diff] [blame] | 1 | /* |
| 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 Menzel | a46a712 | 2013-02-23 18:37:27 +0100 | [diff] [blame] | 17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
Stefan Reinauer | 4885daa | 2011-04-26 23:47:04 +0000 | [diff] [blame] | 18 | */ |
| 19 | |
| 20 | #include <stdint.h> |
| 21 | #include <arch/io.h> |
Stefan Reinauer | fd4f413 | 2013-06-19 12:25:44 -0700 | [diff] [blame] | 22 | #include <arch/early_variables.h> |
Gabe Black | 4d04a71 | 2011-10-05 01:52:08 -0700 | [diff] [blame] | 23 | #include <delay.h> |
Stefan Reinauer | 4885daa | 2011-04-26 23:47:04 +0000 | [diff] [blame] | 24 | #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 Reinauer | 5ff7c13 | 2011-10-31 12:56:45 -0700 | [diff] [blame] | 33 | PCI_DEV(CONFIG_OXFORD_OXPCIE_BRIDGE_SUBORDINATE, 0, 0) |
Stefan Reinauer | 4885daa | 2011-04-26 23:47:04 +0000 | [diff] [blame] | 34 | |
Stefan Reinauer | a6087d1 | 2011-05-09 15:19:29 -0700 | [diff] [blame] | 35 | #define OXPCIE_DEVICE_3 \ |
| 36 | PCI_DEV(CONFIG_OXFORD_OXPCIE_BRIDGE_SUBORDINATE, 0, 3) |
| 37 | |
Gabe Black | 4d04a71 | 2011-10-05 01:52:08 -0700 | [diff] [blame] | 38 | #if defined(__PRE_RAM__) |
| 39 | int oxford_oxpcie_present CAR_GLOBAL; |
| 40 | |
Stefan Reinauer | 4885daa | 2011-04-26 23:47:04 +0000 | [diff] [blame] | 41 | void oxford_init(void) |
| 42 | { |
| 43 | u16 reg16; |
Gabe Black | 4d04a71 | 2011-10-05 01:52:08 -0700 | [diff] [blame] | 44 | oxford_oxpcie_present = 1; |
Stefan Reinauer | 4885daa | 2011-04-26 23:47:04 +0000 | [diff] [blame] | 45 | |
| 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 Roth | 5688979 | 2013-07-09 21:39:46 -0600 | [diff] [blame] | 67 | // XXX is the calculation of base and limit correct? |
Stefan Reinauer | 5ff7c13 | 2011-10-31 12:56:45 -0700 | [diff] [blame] | 68 | pci_write_config32(PCIE_BRIDGE, PCI_MEMORY_BASE, |
Stefan Reinauer | 4885daa | 2011-04-26 23:47:04 +0000 | [diff] [blame] | 69 | ((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 Black | 4d04a71 | 2011-10-05 01:52:08 -0700 | [diff] [blame] | 77 | u32 timeout = 20000; // Timeout in 10s of microseconds. |
Stefan Reinauer | 4885daa | 2011-04-26 23:47:04 +0000 | [diff] [blame] | 78 | u32 id = 0; |
Gabe Black | 4d04a71 | 2011-10-05 01:52:08 -0700 | [diff] [blame] | 79 | for (;;) { |
Stefan Reinauer | 4885daa | 2011-04-26 23:47:04 +0000 | [diff] [blame] | 80 | id = pci_read_config32(OXPCIE_DEVICE, PCI_VENDOR_ID); |
Gabe Black | 4d04a71 | 2011-10-05 01:52:08 -0700 | [diff] [blame] | 81 | if (!timeout-- || (id != 0 && id != 0xffffffff)) |
| 82 | break; |
| 83 | udelay(10); |
| 84 | } |
Stefan Reinauer | 4885daa | 2011-04-26 23:47:04 +0000 | [diff] [blame] | 85 | |
Stefan Reinauer | a6087d1 | 2011-05-09 15:19:29 -0700 | [diff] [blame] | 86 | 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 Black | 4d04a71 | 2011-10-05 01:52:08 -0700 | [diff] [blame] | 101 | default: |
| 102 | /* No UART here. */ |
| 103 | oxford_oxpcie_present = 0; |
| 104 | return; |
Stefan Reinauer | a6087d1 | 2011-05-09 15:19:29 -0700 | [diff] [blame] | 105 | } |
| 106 | |
Stefan Reinauer | 4885daa | 2011-04-26 23:47:04 +0000 | [diff] [blame] | 107 | /* Setup base address on device */ |
Stefan Reinauer | a6087d1 | 2011-05-09 15:19:29 -0700 | [diff] [blame] | 108 | pci_write_config32(device, PCI_BASE_ADDRESS_0, |
Stefan Reinauer | 4885daa | 2011-04-26 23:47:04 +0000 | [diff] [blame] | 109 | CONFIG_OXFORD_OXPCIE_BASE_ADDRESS); |
| 110 | |
| 111 | /* Enable memory on device */ |
Stefan Reinauer | a6087d1 | 2011-05-09 15:19:29 -0700 | [diff] [blame] | 112 | reg16 = pci_read_config16(device, PCI_COMMAND); |
Stefan Reinauer | 4885daa | 2011-04-26 23:47:04 +0000 | [diff] [blame] | 113 | reg16 |= PCI_COMMAND_MEMORY; |
Stefan Reinauer | a6087d1 | 2011-05-09 15:19:29 -0700 | [diff] [blame] | 114 | pci_write_config16(device, PCI_COMMAND, reg16); |
Stefan Reinauer | 4885daa | 2011-04-26 23:47:04 +0000 | [diff] [blame] | 115 | |
| 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 Black | 4d04a71 | 2011-10-05 01:52:08 -0700 | [diff] [blame] | 122 | #endif |