blob: d7f473ed78cecc8749827b9037c5533aef5bcf60 [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
Paul Menzela46a7122013-02-23 18:37:27 +010017 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Stefan Reinauer4885daa2011-04-26 23:47:04 +000018 */
19
Kyösti Mälkki2b95da02014-02-15 10:19:23 +020020#define __SIMPLE_DEVICE__
21
Stefan Reinauer4885daa2011-04-26 23:47:04 +000022#include <stdint.h>
Kyösti Mälkki2b95da02014-02-15 10:19:23 +020023#include <stddef.h>
Stefan Reinauer4885daa2011-04-26 23:47:04 +000024#include <arch/io.h>
Stefan Reinauerfd4f4132013-06-19 12:25:44 -070025#include <arch/early_variables.h>
Gabe Black4d04a712011-10-05 01:52:08 -070026#include <delay.h>
Kyösti Mälkki1d7541f2014-02-17 21:34:42 +020027#include <console/uart.h>
Stefan Reinauer4885daa2011-04-26 23:47:04 +000028#include <device/pci_def.h>
29
Kyösti Mälkki2b95da02014-02-15 10:19:23 +020030static unsigned int oxpcie_present CAR_GLOBAL;
31static ROMSTAGE_CONST u32 uart0_base = CONFIG_OXFORD_OXPCIE_BASE_ADDRESS + 0x1000;
32static ROMSTAGE_CONST u32 uart1_base = CONFIG_OXFORD_OXPCIE_BASE_ADDRESS + 0x2000;
33
Stefan Reinauer4885daa2011-04-26 23:47:04 +000034#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 Reinauer5ff7c132011-10-31 12:56:45 -070040 PCI_DEV(CONFIG_OXFORD_OXPCIE_BRIDGE_SUBORDINATE, 0, 0)
Stefan Reinauer4885daa2011-04-26 23:47:04 +000041
Stefan Reinauera6087d12011-05-09 15:19:29 -070042#define OXPCIE_DEVICE_3 \
43 PCI_DEV(CONFIG_OXFORD_OXPCIE_BRIDGE_SUBORDINATE, 0, 3)
44
Kyösti Mälkki2b95da02014-02-15 10:19:23 +020045static void oxpcie_init_bridge(void)
Stefan Reinauer4885daa2011-04-26 23:47:04 +000046{
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 Roth56889792013-07-09 21:39:46 -060070 // XXX is the calculation of base and limit correct?
Stefan Reinauer5ff7c132011-10-31 12:56:45 -070071 pci_write_config32(PCIE_BRIDGE, PCI_MEMORY_BASE,
Stefan Reinauer4885daa2011-04-26 23:47:04 +000072 ((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 Black4d04a712011-10-05 01:52:08 -070080 u32 timeout = 20000; // Timeout in 10s of microseconds.
Stefan Reinauer4885daa2011-04-26 23:47:04 +000081 u32 id = 0;
Gabe Black4d04a712011-10-05 01:52:08 -070082 for (;;) {
Stefan Reinauer4885daa2011-04-26 23:47:04 +000083 id = pci_read_config32(OXPCIE_DEVICE, PCI_VENDOR_ID);
Gabe Black4d04a712011-10-05 01:52:08 -070084 if (!timeout-- || (id != 0 && id != 0xffffffff))
85 break;
86 udelay(10);
87 }
Stefan Reinauer4885daa2011-04-26 23:47:04 +000088
Stefan Reinauera6087d12011-05-09 15:19:29 -070089 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 Black4d04a712011-10-05 01:52:08 -0700104 default:
105 /* No UART here. */
Gabe Black4d04a712011-10-05 01:52:08 -0700106 return;
Stefan Reinauera6087d12011-05-09 15:19:29 -0700107 }
108
Stefan Reinauer4885daa2011-04-26 23:47:04 +0000109 /* Setup base address on device */
Stefan Reinauera6087d12011-05-09 15:19:29 -0700110 pci_write_config32(device, PCI_BASE_ADDRESS_0,
Stefan Reinauer4885daa2011-04-26 23:47:04 +0000111 CONFIG_OXFORD_OXPCIE_BASE_ADDRESS);
112
113 /* Enable memory on device */
Stefan Reinauera6087d12011-05-09 15:19:29 -0700114 reg16 = pci_read_config16(device, PCI_COMMAND);
Stefan Reinauer4885daa2011-04-26 23:47:04 +0000115 reg16 |= PCI_COMMAND_MEMORY;
Stefan Reinauera6087d12011-05-09 15:19:29 -0700116 pci_write_config16(device, PCI_COMMAND, reg16);
Stefan Reinauer4885daa2011-04-26 23:47:04 +0000117
Kyösti Mälkki2b95da02014-02-15 10:19:23 +0200118 car_set_var(oxpcie_present, 1);
Stefan Reinauer4885daa2011-04-26 23:47:04 +0000119}
120
Kyösti Mälkki2b95da02014-02-15 10:19:23 +0200121static int oxpcie_uart_active(void)
122{
123 return (car_get_var(oxpcie_present));
124}
125
126unsigned 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__
136void oxford_remap(u32 new_base)
137{
138 uart0_base = new_base + 0x1000;
139 uart1_base = new_base + 0x2000;
140}
141
142uint32_t uartmem_getbaseaddr(void)
143{
144 return uart_platform_base(0);
145}
Gabe Black4d04a712011-10-05 01:52:08 -0700146#endif
Kyösti Mälkki3ee16682014-02-17 19:37:52 +0200147
148unsigned int uart_platform_refclk(void)
149{
150 return 62500000;
151}
Kyösti Mälkki2b95da02014-02-15 10:19:23 +0200152
153void oxford_init(void)
154{
155 oxpcie_init_bridge();
156}