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 | |
Kyösti Mälkki | 2b95da0 | 2014-02-15 10:19:23 +0200 | [diff] [blame^] | 20 | #define __SIMPLE_DEVICE__ |
| 21 | |
Stefan Reinauer | 4885daa | 2011-04-26 23:47:04 +0000 | [diff] [blame] | 22 | #include <stdint.h> |
Kyösti Mälkki | 2b95da0 | 2014-02-15 10:19:23 +0200 | [diff] [blame^] | 23 | #include <stddef.h> |
Stefan Reinauer | 4885daa | 2011-04-26 23:47:04 +0000 | [diff] [blame] | 24 | #include <arch/io.h> |
Stefan Reinauer | fd4f413 | 2013-06-19 12:25:44 -0700 | [diff] [blame] | 25 | #include <arch/early_variables.h> |
Gabe Black | 4d04a71 | 2011-10-05 01:52:08 -0700 | [diff] [blame] | 26 | #include <delay.h> |
Kyösti Mälkki | 1d7541f | 2014-02-17 21:34:42 +0200 | [diff] [blame] | 27 | #include <console/uart.h> |
Stefan Reinauer | 4885daa | 2011-04-26 23:47:04 +0000 | [diff] [blame] | 28 | #include <device/pci_def.h> |
| 29 | |
Kyösti Mälkki | 2b95da0 | 2014-02-15 10:19:23 +0200 | [diff] [blame^] | 30 | static unsigned int oxpcie_present CAR_GLOBAL; |
| 31 | static ROMSTAGE_CONST u32 uart0_base = CONFIG_OXFORD_OXPCIE_BASE_ADDRESS + 0x1000; |
| 32 | static ROMSTAGE_CONST u32 uart1_base = CONFIG_OXFORD_OXPCIE_BASE_ADDRESS + 0x2000; |
| 33 | |
Stefan Reinauer | 4885daa | 2011-04-26 23:47:04 +0000 | [diff] [blame] | 34 | #define PCIE_BRIDGE \ |
| 35 | PCI_DEV(CONFIG_OXFORD_OXPCIE_BRIDGE_BUS, \ |
| 36 | CONFIG_OXFORD_OXPCIE_BRIDGE_DEVICE, \ |
| 37 | CONFIG_OXFORD_OXPCIE_BRIDGE_FUNCTION) |
| 38 | |
| 39 | #define OXPCIE_DEVICE \ |
Stefan Reinauer | 5ff7c13 | 2011-10-31 12:56:45 -0700 | [diff] [blame] | 40 | PCI_DEV(CONFIG_OXFORD_OXPCIE_BRIDGE_SUBORDINATE, 0, 0) |
Stefan Reinauer | 4885daa | 2011-04-26 23:47:04 +0000 | [diff] [blame] | 41 | |
Stefan Reinauer | a6087d1 | 2011-05-09 15:19:29 -0700 | [diff] [blame] | 42 | #define OXPCIE_DEVICE_3 \ |
| 43 | PCI_DEV(CONFIG_OXFORD_OXPCIE_BRIDGE_SUBORDINATE, 0, 3) |
| 44 | |
Kyösti Mälkki | 2b95da0 | 2014-02-15 10:19:23 +0200 | [diff] [blame^] | 45 | static void oxpcie_init_bridge(void) |
Stefan Reinauer | 4885daa | 2011-04-26 23:47:04 +0000 | [diff] [blame] | 46 | { |
| 47 | u16 reg16; |
| 48 | |
| 49 | /* First we reset the secondary bus */ |
| 50 | reg16 = pci_read_config16(PCIE_BRIDGE, PCI_BRIDGE_CONTROL); |
| 51 | reg16 |= (1 << 6); /* SRESET */ |
| 52 | pci_write_config16(PCIE_BRIDGE, PCI_BRIDGE_CONTROL, reg16); |
| 53 | |
| 54 | /* Assume we don't have to wait here forever */ |
| 55 | |
| 56 | /* Read back and clear reset bit. */ |
| 57 | reg16 = pci_read_config16(PCIE_BRIDGE, PCI_BRIDGE_CONTROL); |
| 58 | reg16 &= ~(1 << 6); /* SRESET */ |
| 59 | pci_write_config16(PCIE_BRIDGE, PCI_BRIDGE_CONTROL, reg16); |
| 60 | |
| 61 | /* Set up subordinate bus number */ |
| 62 | pci_write_config8(PCIE_BRIDGE, PCI_SECONDARY_BUS, 0x00); |
| 63 | pci_write_config8(PCIE_BRIDGE, PCI_SUBORDINATE_BUS, 0x00); |
| 64 | pci_write_config8(PCIE_BRIDGE, PCI_SECONDARY_BUS, |
| 65 | CONFIG_OXFORD_OXPCIE_BRIDGE_SUBORDINATE); |
| 66 | pci_write_config8(PCIE_BRIDGE, PCI_SUBORDINATE_BUS, |
| 67 | CONFIG_OXFORD_OXPCIE_BRIDGE_SUBORDINATE); |
| 68 | |
| 69 | /* Memory window for the OXPCIe952 card */ |
Martin Roth | 5688979 | 2013-07-09 21:39:46 -0600 | [diff] [blame] | 70 | // XXX is the calculation of base and limit correct? |
Stefan Reinauer | 5ff7c13 | 2011-10-31 12:56:45 -0700 | [diff] [blame] | 71 | pci_write_config32(PCIE_BRIDGE, PCI_MEMORY_BASE, |
Stefan Reinauer | 4885daa | 2011-04-26 23:47:04 +0000 | [diff] [blame] | 72 | ((CONFIG_OXFORD_OXPCIE_BASE_ADDRESS & 0xffff0000) | |
| 73 | ((CONFIG_OXFORD_OXPCIE_BASE_ADDRESS >> 16) & 0xff00))); |
| 74 | |
| 75 | /* Enable memory access through bridge */ |
| 76 | reg16 = pci_read_config16(PCIE_BRIDGE, PCI_COMMAND); |
| 77 | reg16 |= PCI_COMMAND_MEMORY; |
| 78 | pci_write_config16(PCIE_BRIDGE, PCI_COMMAND, reg16); |
| 79 | |
Gabe Black | 4d04a71 | 2011-10-05 01:52:08 -0700 | [diff] [blame] | 80 | u32 timeout = 20000; // Timeout in 10s of microseconds. |
Stefan Reinauer | 4885daa | 2011-04-26 23:47:04 +0000 | [diff] [blame] | 81 | u32 id = 0; |
Gabe Black | 4d04a71 | 2011-10-05 01:52:08 -0700 | [diff] [blame] | 82 | for (;;) { |
Stefan Reinauer | 4885daa | 2011-04-26 23:47:04 +0000 | [diff] [blame] | 83 | id = pci_read_config32(OXPCIE_DEVICE, PCI_VENDOR_ID); |
Gabe Black | 4d04a71 | 2011-10-05 01:52:08 -0700 | [diff] [blame] | 84 | if (!timeout-- || (id != 0 && id != 0xffffffff)) |
| 85 | break; |
| 86 | udelay(10); |
| 87 | } |
Stefan Reinauer | 4885daa | 2011-04-26 23:47:04 +0000 | [diff] [blame] | 88 | |
Stefan Reinauer | a6087d1 | 2011-05-09 15:19:29 -0700 | [diff] [blame] | 89 | u32 device = OXPCIE_DEVICE; /* unknown default */ |
| 90 | switch (id) { |
| 91 | case 0xc1181415: /* e.g. Startech PEX1S1PMINI */ |
| 92 | /* On this device function 0 is the parallel port, and |
| 93 | * function 3 is the serial port. So let's go look for |
| 94 | * the UART. |
| 95 | */ |
| 96 | id = pci_read_config32(OXPCIE_DEVICE_3, PCI_VENDOR_ID); |
| 97 | if (id != 0xc11b1415) |
| 98 | return; |
| 99 | device = OXPCIE_DEVICE_3; |
| 100 | break; |
| 101 | case 0xc1581415: /* e.g. Startech MPEX2S952 */ |
| 102 | device = OXPCIE_DEVICE; |
| 103 | break; |
Gabe Black | 4d04a71 | 2011-10-05 01:52:08 -0700 | [diff] [blame] | 104 | default: |
| 105 | /* No UART here. */ |
Gabe Black | 4d04a71 | 2011-10-05 01:52:08 -0700 | [diff] [blame] | 106 | return; |
Stefan Reinauer | a6087d1 | 2011-05-09 15:19:29 -0700 | [diff] [blame] | 107 | } |
| 108 | |
Stefan Reinauer | 4885daa | 2011-04-26 23:47:04 +0000 | [diff] [blame] | 109 | /* Setup base address on device */ |
Stefan Reinauer | a6087d1 | 2011-05-09 15:19:29 -0700 | [diff] [blame] | 110 | pci_write_config32(device, PCI_BASE_ADDRESS_0, |
Stefan Reinauer | 4885daa | 2011-04-26 23:47:04 +0000 | [diff] [blame] | 111 | CONFIG_OXFORD_OXPCIE_BASE_ADDRESS); |
| 112 | |
| 113 | /* Enable memory on device */ |
Stefan Reinauer | a6087d1 | 2011-05-09 15:19:29 -0700 | [diff] [blame] | 114 | reg16 = pci_read_config16(device, PCI_COMMAND); |
Stefan Reinauer | 4885daa | 2011-04-26 23:47:04 +0000 | [diff] [blame] | 115 | reg16 |= PCI_COMMAND_MEMORY; |
Stefan Reinauer | a6087d1 | 2011-05-09 15:19:29 -0700 | [diff] [blame] | 116 | pci_write_config16(device, PCI_COMMAND, reg16); |
Stefan Reinauer | 4885daa | 2011-04-26 23:47:04 +0000 | [diff] [blame] | 117 | |
Kyösti Mälkki | 2b95da0 | 2014-02-15 10:19:23 +0200 | [diff] [blame^] | 118 | car_set_var(oxpcie_present, 1); |
Stefan Reinauer | 4885daa | 2011-04-26 23:47:04 +0000 | [diff] [blame] | 119 | } |
| 120 | |
Kyösti Mälkki | 2b95da0 | 2014-02-15 10:19:23 +0200 | [diff] [blame^] | 121 | static int oxpcie_uart_active(void) |
| 122 | { |
| 123 | return (car_get_var(oxpcie_present)); |
| 124 | } |
| 125 | |
| 126 | unsigned int uart_platform_base(int idx) |
| 127 | { |
| 128 | if (idx == 0 && oxpcie_uart_active()) |
| 129 | return uart0_base; |
| 130 | if (idx == 1 && oxpcie_uart_active()) |
| 131 | return uart1_base; |
| 132 | return 0; |
| 133 | } |
| 134 | |
| 135 | #ifndef __PRE_RAM__ |
| 136 | void oxford_remap(u32 new_base) |
| 137 | { |
| 138 | uart0_base = new_base + 0x1000; |
| 139 | uart1_base = new_base + 0x2000; |
| 140 | } |
| 141 | |
| 142 | uint32_t uartmem_getbaseaddr(void) |
| 143 | { |
| 144 | return uart_platform_base(0); |
| 145 | } |
Gabe Black | 4d04a71 | 2011-10-05 01:52:08 -0700 | [diff] [blame] | 146 | #endif |
Kyösti Mälkki | 3ee1668 | 2014-02-17 19:37:52 +0200 | [diff] [blame] | 147 | |
| 148 | unsigned int uart_platform_refclk(void) |
| 149 | { |
| 150 | return 62500000; |
| 151 | } |
Kyösti Mälkki | 2b95da0 | 2014-02-15 10:19:23 +0200 | [diff] [blame^] | 152 | |
| 153 | void oxford_init(void) |
| 154 | { |
| 155 | oxpcie_init_bridge(); |
| 156 | } |