blob: b81a7ffa916a37939a6dcad6aacc1006f5d44b0a [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.
Stefan Reinauer4885daa2011-04-26 23:47:04 +000014 */
15
Kyösti Mälkki2b95da02014-02-15 10:19:23 +020016#define __SIMPLE_DEVICE__
17
Stefan Reinauer4885daa2011-04-26 23:47:04 +000018#include <stdint.h>
Kyösti Mälkki2b95da02014-02-15 10:19:23 +020019#include <stddef.h>
Stefan Reinauer4885daa2011-04-26 23:47:04 +000020#include <arch/io.h>
Kyösti Mälkkif1b58b72019-03-01 13:43:02 +020021#include <device/pci_ops.h>
Stefan Reinauerfd4f4132013-06-19 12:25:44 -070022#include <arch/early_variables.h>
Kyösti Mälkkibbf6f3d2014-03-15 01:32:55 +020023#include <boot/coreboot_tables.h>
Kyösti Mälkki1d7541f2014-02-17 21:34:42 +020024#include <console/uart.h>
Kyösti Mälkkibbf6f3d2014-03-15 01:32:55 +020025#include <device/pci.h>
Stefan Reinauer4885daa2011-04-26 23:47:04 +000026#include <device/pci_def.h>
27
Kyösti Mälkki2b95da02014-02-15 10:19:23 +020028static unsigned int oxpcie_present CAR_GLOBAL;
Aaron Durbine4d7abc2017-04-16 22:05:36 -050029static DEVTREE_CONST u32 uart0_base = CONFIG_EARLY_PCI_MMIO_BASE + 0x1000;
Kyösti Mälkki2b95da02014-02-15 10:19:23 +020030
Kyösti Mälkki4c686f22014-02-14 12:45:09 +020031int pci_early_device_probe(u8 bus, u8 dev, u32 mmio_base)
Stefan Reinauer4885daa2011-04-26 23:47:04 +000032{
Kyösti Mälkki4c686f22014-02-14 12:45:09 +020033 pci_devfn_t device = PCI_DEV(bus, dev, 0);
Stefan Reinauer4885daa2011-04-26 23:47:04 +000034
Kyösti Mälkki4c686f22014-02-14 12:45:09 +020035 u32 id = pci_read_config32(device, PCI_VENDOR_ID);
Stefan Reinauera6087d12011-05-09 15:19:29 -070036 switch (id) {
Kyösti Mälkki4c686f22014-02-14 12:45:09 +020037 case 0xc1181415: /* e.g. Startech PEX1S1PMINI function 0 */
Stefan Reinauera6087d12011-05-09 15:19:29 -070038 /* On this device function 0 is the parallel port, and
39 * function 3 is the serial port. So let's go look for
40 * the UART.
41 */
Kyösti Mälkki4c686f22014-02-14 12:45:09 +020042 device = PCI_DEV(bus, dev, 3);
43 id = pci_read_config32(device, PCI_VENDOR_ID);
Stefan Reinauera6087d12011-05-09 15:19:29 -070044 if (id != 0xc11b1415)
Kyösti Mälkki4c686f22014-02-14 12:45:09 +020045 return -1;
Stefan Reinauera6087d12011-05-09 15:19:29 -070046 break;
Kyösti Mälkki4c686f22014-02-14 12:45:09 +020047 case 0xc11b1415: /* e.g. Startech PEX1S1PMINI function 3 */
Stefan Reinauera6087d12011-05-09 15:19:29 -070048 case 0xc1581415: /* e.g. Startech MPEX2S952 */
Stefan Reinauera6087d12011-05-09 15:19:29 -070049 break;
Gabe Black4d04a712011-10-05 01:52:08 -070050 default:
51 /* No UART here. */
Kyösti Mälkki4c686f22014-02-14 12:45:09 +020052 return -1;
Stefan Reinauera6087d12011-05-09 15:19:29 -070053 }
54
Kyösti Mälkki4c686f22014-02-14 12:45:09 +020055 /* Sanity-check, we assume fixed location. */
56 if (mmio_base != CONFIG_EARLY_PCI_MMIO_BASE)
57 return -1;
58
Stefan Reinauer4885daa2011-04-26 23:47:04 +000059 /* Setup base address on device */
Kyösti Mälkki4c686f22014-02-14 12:45:09 +020060 pci_write_config32(device, PCI_BASE_ADDRESS_0, mmio_base);
Stefan Reinauer4885daa2011-04-26 23:47:04 +000061
62 /* Enable memory on device */
Kyösti Mälkki4c686f22014-02-14 12:45:09 +020063 u16 reg16 = pci_read_config16(device, PCI_COMMAND);
Stefan Reinauer4885daa2011-04-26 23:47:04 +000064 reg16 |= PCI_COMMAND_MEMORY;
Stefan Reinauera6087d12011-05-09 15:19:29 -070065 pci_write_config16(device, PCI_COMMAND, reg16);
Stefan Reinauer4885daa2011-04-26 23:47:04 +000066
Kyösti Mälkki2b95da02014-02-15 10:19:23 +020067 car_set_var(oxpcie_present, 1);
Kyösti Mälkki4c686f22014-02-14 12:45:09 +020068 return 0;
Stefan Reinauer4885daa2011-04-26 23:47:04 +000069}
70
Kyösti Mälkki2b95da02014-02-15 10:19:23 +020071static int oxpcie_uart_active(void)
72{
73 return (car_get_var(oxpcie_present));
74}
75
Ronald G. Minnich2adb2972014-10-16 10:53:48 +000076uintptr_t uart_platform_base(int idx)
Kyösti Mälkki2b95da02014-02-15 10:19:23 +020077{
Kyösti Mälkkie993ec72015-03-20 08:51:57 +020078 if ((idx >= 0) && (idx < 8) && oxpcie_uart_active())
79 return uart0_base + idx * 0x200;
Kyösti Mälkki2b95da02014-02-15 10:19:23 +020080 return 0;
81}
82
Kyösti Mälkki2b95da02014-02-15 10:19:23 +020083void oxford_remap(u32 new_base)
84{
Kyösti Mälkkifb25f9f2018-12-26 20:15:58 +020085#if ENV_RAMSTAGE
Kyösti Mälkki2b95da02014-02-15 10:19:23 +020086 uart0_base = new_base + 0x1000;
Gabe Black4d04a712011-10-05 01:52:08 -070087#endif
Kyösti Mälkkifb25f9f2018-12-26 20:15:58 +020088}
Kyösti Mälkki3ee16682014-02-17 19:37:52 +020089
90unsigned int uart_platform_refclk(void)
91{
92 return 62500000;
93}