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 |
| 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 Black | 4d04a71 | 2011-10-05 01:52:08 -0700 | [diff] [blame^] | 23 | #include <cpu/x86/car.h> |
| 24 | #include <delay.h> |
Stefan Reinauer | 4885daa | 2011-04-26 23:47:04 +0000 | [diff] [blame] | 25 | #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 Reinauer | 5ff7c13 | 2011-10-31 12:56:45 -0700 | [diff] [blame] | 34 | PCI_DEV(CONFIG_OXFORD_OXPCIE_BRIDGE_SUBORDINATE, 0, 0) |
Stefan Reinauer | 4885daa | 2011-04-26 23:47:04 +0000 | [diff] [blame] | 35 | |
Stefan Reinauer | a6087d1 | 2011-05-09 15:19:29 -0700 | [diff] [blame] | 36 | #define OXPCIE_DEVICE_3 \ |
| 37 | PCI_DEV(CONFIG_OXFORD_OXPCIE_BRIDGE_SUBORDINATE, 0, 3) |
| 38 | |
Gabe Black | 4d04a71 | 2011-10-05 01:52:08 -0700 | [diff] [blame^] | 39 | #if defined(__PRE_RAM__) |
| 40 | int oxford_oxpcie_present CAR_GLOBAL; |
| 41 | |
Stefan Reinauer | 4885daa | 2011-04-26 23:47:04 +0000 | [diff] [blame] | 42 | void oxford_init(void) |
| 43 | { |
| 44 | u16 reg16; |
Gabe Black | 4d04a71 | 2011-10-05 01:52:08 -0700 | [diff] [blame^] | 45 | oxford_oxpcie_present = 1; |
Stefan Reinauer | 4885daa | 2011-04-26 23:47:04 +0000 | [diff] [blame] | 46 | |
| 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 Reinauer | 5ff7c13 | 2011-10-31 12:56:45 -0700 | [diff] [blame] | 69 | pci_write_config32(PCIE_BRIDGE, PCI_MEMORY_BASE, |
Stefan Reinauer | 4885daa | 2011-04-26 23:47:04 +0000 | [diff] [blame] | 70 | ((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 Black | 4d04a71 | 2011-10-05 01:52:08 -0700 | [diff] [blame^] | 78 | u32 timeout = 20000; // Timeout in 10s of microseconds. |
Stefan Reinauer | 4885daa | 2011-04-26 23:47:04 +0000 | [diff] [blame] | 79 | u32 id = 0; |
Gabe Black | 4d04a71 | 2011-10-05 01:52:08 -0700 | [diff] [blame^] | 80 | for (;;) { |
Stefan Reinauer | 4885daa | 2011-04-26 23:47:04 +0000 | [diff] [blame] | 81 | id = pci_read_config32(OXPCIE_DEVICE, PCI_VENDOR_ID); |
Gabe Black | 4d04a71 | 2011-10-05 01:52:08 -0700 | [diff] [blame^] | 82 | if (!timeout-- || (id != 0 && id != 0xffffffff)) |
| 83 | break; |
| 84 | udelay(10); |
| 85 | } |
Stefan Reinauer | 4885daa | 2011-04-26 23:47:04 +0000 | [diff] [blame] | 86 | |
Stefan Reinauer | a6087d1 | 2011-05-09 15:19:29 -0700 | [diff] [blame] | 87 | 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 Black | 4d04a71 | 2011-10-05 01:52:08 -0700 | [diff] [blame^] | 102 | default: |
| 103 | /* No UART here. */ |
| 104 | oxford_oxpcie_present = 0; |
| 105 | return; |
Stefan Reinauer | a6087d1 | 2011-05-09 15:19:29 -0700 | [diff] [blame] | 106 | } |
| 107 | |
Stefan Reinauer | 4885daa | 2011-04-26 23:47:04 +0000 | [diff] [blame] | 108 | /* Setup base address on device */ |
Stefan Reinauer | a6087d1 | 2011-05-09 15:19:29 -0700 | [diff] [blame] | 109 | pci_write_config32(device, PCI_BASE_ADDRESS_0, |
Stefan Reinauer | 4885daa | 2011-04-26 23:47:04 +0000 | [diff] [blame] | 110 | CONFIG_OXFORD_OXPCIE_BASE_ADDRESS); |
| 111 | |
| 112 | /* Enable memory on device */ |
Stefan Reinauer | a6087d1 | 2011-05-09 15:19:29 -0700 | [diff] [blame] | 113 | reg16 = pci_read_config16(device, PCI_COMMAND); |
Stefan Reinauer | 4885daa | 2011-04-26 23:47:04 +0000 | [diff] [blame] | 114 | reg16 |= PCI_COMMAND_MEMORY; |
Stefan Reinauer | a6087d1 | 2011-05-09 15:19:29 -0700 | [diff] [blame] | 115 | pci_write_config16(device, PCI_COMMAND, reg16); |
Stefan Reinauer | 4885daa | 2011-04-26 23:47:04 +0000 | [diff] [blame] | 116 | |
| 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 Black | 4d04a71 | 2011-10-05 01:52:08 -0700 | [diff] [blame^] | 123 | #endif |