blob: eb6f8804a03de5185266e22d93c1e5961a1eb3a4 [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
16#include <stdint.h>
Kyösti Mälkki2b95da02014-02-15 10:19:23 +020017#include <stddef.h>
Kyösti Mälkkif1b58b72019-03-01 13:43:02 +020018#include <device/pci_ops.h>
Stefan Reinauerfd4f4132013-06-19 12:25:44 -070019#include <arch/early_variables.h>
Kyösti Mälkkibbf6f3d2014-03-15 01:32:55 +020020#include <boot/coreboot_tables.h>
Kyösti Mälkki1d7541f2014-02-17 21:34:42 +020021#include <console/uart.h>
Kyösti Mälkkibbf6f3d2014-03-15 01:32:55 +020022#include <device/pci.h>
Stefan Reinauer4885daa2011-04-26 23:47:04 +000023#include <device/pci_def.h>
24
Kyösti Mälkki2b95da02014-02-15 10:19:23 +020025static unsigned int oxpcie_present CAR_GLOBAL;
Aaron Durbine4d7abc2017-04-16 22:05:36 -050026static DEVTREE_CONST u32 uart0_base = CONFIG_EARLY_PCI_MMIO_BASE + 0x1000;
Kyösti Mälkki2b95da02014-02-15 10:19:23 +020027
Kyösti Mälkki4c686f22014-02-14 12:45:09 +020028int pci_early_device_probe(u8 bus, u8 dev, u32 mmio_base)
Stefan Reinauer4885daa2011-04-26 23:47:04 +000029{
Kyösti Mälkki4c686f22014-02-14 12:45:09 +020030 pci_devfn_t device = PCI_DEV(bus, dev, 0);
Stefan Reinauer4885daa2011-04-26 23:47:04 +000031
Kyösti Mälkkie0887212019-09-26 22:33:51 +030032 u32 id = pci_s_read_config32(device, PCI_VENDOR_ID);
Stefan Reinauera6087d12011-05-09 15:19:29 -070033 switch (id) {
Kyösti Mälkki4c686f22014-02-14 12:45:09 +020034 case 0xc1181415: /* e.g. Startech PEX1S1PMINI function 0 */
Stefan Reinauera6087d12011-05-09 15:19:29 -070035 /* On this device function 0 is the parallel port, and
36 * function 3 is the serial port. So let's go look for
37 * the UART.
38 */
Kyösti Mälkki4c686f22014-02-14 12:45:09 +020039 device = PCI_DEV(bus, dev, 3);
Kyösti Mälkkie0887212019-09-26 22:33:51 +030040 id = pci_s_read_config32(device, PCI_VENDOR_ID);
Stefan Reinauera6087d12011-05-09 15:19:29 -070041 if (id != 0xc11b1415)
Kyösti Mälkki4c686f22014-02-14 12:45:09 +020042 return -1;
Stefan Reinauera6087d12011-05-09 15:19:29 -070043 break;
Kyösti Mälkki4c686f22014-02-14 12:45:09 +020044 case 0xc11b1415: /* e.g. Startech PEX1S1PMINI function 3 */
Stefan Reinauera6087d12011-05-09 15:19:29 -070045 case 0xc1581415: /* e.g. Startech MPEX2S952 */
Stefan Reinauera6087d12011-05-09 15:19:29 -070046 break;
Gabe Black4d04a712011-10-05 01:52:08 -070047 default:
48 /* No UART here. */
Kyösti Mälkki4c686f22014-02-14 12:45:09 +020049 return -1;
Stefan Reinauera6087d12011-05-09 15:19:29 -070050 }
51
Kyösti Mälkki4c686f22014-02-14 12:45:09 +020052 /* Sanity-check, we assume fixed location. */
53 if (mmio_base != CONFIG_EARLY_PCI_MMIO_BASE)
54 return -1;
55
Stefan Reinauer4885daa2011-04-26 23:47:04 +000056 /* Setup base address on device */
Kyösti Mälkkie0887212019-09-26 22:33:51 +030057 pci_s_write_config32(device, PCI_BASE_ADDRESS_0, mmio_base);
Stefan Reinauer4885daa2011-04-26 23:47:04 +000058
59 /* Enable memory on device */
Kyösti Mälkkie0887212019-09-26 22:33:51 +030060 u16 reg16 = pci_s_read_config16(device, PCI_COMMAND);
Stefan Reinauer4885daa2011-04-26 23:47:04 +000061 reg16 |= PCI_COMMAND_MEMORY;
Kyösti Mälkkie0887212019-09-26 22:33:51 +030062 pci_s_write_config16(device, PCI_COMMAND, reg16);
Stefan Reinauer4885daa2011-04-26 23:47:04 +000063
Kyösti Mälkki2b95da02014-02-15 10:19:23 +020064 car_set_var(oxpcie_present, 1);
Kyösti Mälkki4c686f22014-02-14 12:45:09 +020065 return 0;
Stefan Reinauer4885daa2011-04-26 23:47:04 +000066}
67
Kyösti Mälkki2b95da02014-02-15 10:19:23 +020068static int oxpcie_uart_active(void)
69{
70 return (car_get_var(oxpcie_present));
71}
72
Ronald G. Minnich2adb2972014-10-16 10:53:48 +000073uintptr_t uart_platform_base(int idx)
Kyösti Mälkki2b95da02014-02-15 10:19:23 +020074{
Kyösti Mälkkie993ec72015-03-20 08:51:57 +020075 if ((idx >= 0) && (idx < 8) && oxpcie_uart_active())
76 return uart0_base + idx * 0x200;
Kyösti Mälkki2b95da02014-02-15 10:19:23 +020077 return 0;
78}
79
Kyösti Mälkki2b95da02014-02-15 10:19:23 +020080void oxford_remap(u32 new_base)
81{
Kyösti Mälkkifb25f9f2018-12-26 20:15:58 +020082#if ENV_RAMSTAGE
Kyösti Mälkki2b95da02014-02-15 10:19:23 +020083 uart0_base = new_base + 0x1000;
Gabe Black4d04a712011-10-05 01:52:08 -070084#endif
Kyösti Mälkkifb25f9f2018-12-26 20:15:58 +020085}
Kyösti Mälkki3ee16682014-02-17 19:37:52 +020086
87unsigned int uart_platform_refclk(void)
88{
89 return 62500000;
90}