blob: 2cbc8c7948de5a968307d424bfcf5a0193fae758 [file] [log] [blame]
Angel Pons8a3453f2020-04-02 23:48:19 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Stefan Reinauer4885daa2011-04-26 23:47:04 +00002
3#include <stdint.h>
Kyösti Mälkki2b95da02014-02-15 10:19:23 +02004#include <stddef.h>
Kyösti Mälkkif1b58b72019-03-01 13:43:02 +02005#include <device/pci_ops.h>
Kyösti Mälkki1d7541f2014-02-17 21:34:42 +02006#include <console/uart.h>
Kyösti Mälkkibbf6f3d2014-03-15 01:32:55 +02007#include <device/pci.h>
Stefan Reinauer4885daa2011-04-26 23:47:04 +00008
Arthur Heymans5fadb462019-11-20 21:28:15 +01009static unsigned int oxpcie_present;
Aaron Durbine4d7abc2017-04-16 22:05:36 -050010static DEVTREE_CONST u32 uart0_base = CONFIG_EARLY_PCI_MMIO_BASE + 0x1000;
Kyösti Mälkki2b95da02014-02-15 10:19:23 +020011
Kyösti Mälkki4c686f22014-02-14 12:45:09 +020012int pci_early_device_probe(u8 bus, u8 dev, u32 mmio_base)
Stefan Reinauer4885daa2011-04-26 23:47:04 +000013{
Kyösti Mälkki4c686f22014-02-14 12:45:09 +020014 pci_devfn_t device = PCI_DEV(bus, dev, 0);
Stefan Reinauer4885daa2011-04-26 23:47:04 +000015
Kyösti Mälkkie0887212019-09-26 22:33:51 +030016 u32 id = pci_s_read_config32(device, PCI_VENDOR_ID);
Stefan Reinauera6087d12011-05-09 15:19:29 -070017 switch (id) {
Kyösti Mälkki4c686f22014-02-14 12:45:09 +020018 case 0xc1181415: /* e.g. Startech PEX1S1PMINI function 0 */
Stefan Reinauera6087d12011-05-09 15:19:29 -070019 /* On this device function 0 is the parallel port, and
20 * function 3 is the serial port. So let's go look for
21 * the UART.
22 */
Kyösti Mälkki4c686f22014-02-14 12:45:09 +020023 device = PCI_DEV(bus, dev, 3);
Kyösti Mälkkie0887212019-09-26 22:33:51 +030024 id = pci_s_read_config32(device, PCI_VENDOR_ID);
Stefan Reinauera6087d12011-05-09 15:19:29 -070025 if (id != 0xc11b1415)
Kyösti Mälkki4c686f22014-02-14 12:45:09 +020026 return -1;
Stefan Reinauera6087d12011-05-09 15:19:29 -070027 break;
Kyösti Mälkki4c686f22014-02-14 12:45:09 +020028 case 0xc11b1415: /* e.g. Startech PEX1S1PMINI function 3 */
Stefan Reinauera6087d12011-05-09 15:19:29 -070029 case 0xc1581415: /* e.g. Startech MPEX2S952 */
Stefan Reinauera6087d12011-05-09 15:19:29 -070030 break;
Gabe Black4d04a712011-10-05 01:52:08 -070031 default:
32 /* No UART here. */
Kyösti Mälkki4c686f22014-02-14 12:45:09 +020033 return -1;
Stefan Reinauera6087d12011-05-09 15:19:29 -070034 }
35
Kyösti Mälkki4c686f22014-02-14 12:45:09 +020036 /* Sanity-check, we assume fixed location. */
37 if (mmio_base != CONFIG_EARLY_PCI_MMIO_BASE)
38 return -1;
39
Stefan Reinauer4885daa2011-04-26 23:47:04 +000040 /* Setup base address on device */
Kyösti Mälkkie0887212019-09-26 22:33:51 +030041 pci_s_write_config32(device, PCI_BASE_ADDRESS_0, mmio_base);
Stefan Reinauer4885daa2011-04-26 23:47:04 +000042
43 /* Enable memory on device */
Kyösti Mälkkie0887212019-09-26 22:33:51 +030044 u16 reg16 = pci_s_read_config16(device, PCI_COMMAND);
Stefan Reinauer4885daa2011-04-26 23:47:04 +000045 reg16 |= PCI_COMMAND_MEMORY;
Kyösti Mälkkie0887212019-09-26 22:33:51 +030046 pci_s_write_config16(device, PCI_COMMAND, reg16);
Stefan Reinauer4885daa2011-04-26 23:47:04 +000047
Arthur Heymans5fadb462019-11-20 21:28:15 +010048 oxpcie_present = 1;
Kyösti Mälkki4c686f22014-02-14 12:45:09 +020049 return 0;
Stefan Reinauer4885daa2011-04-26 23:47:04 +000050}
51
Kyösti Mälkki2b95da02014-02-15 10:19:23 +020052static int oxpcie_uart_active(void)
53{
Arthur Heymans5fadb462019-11-20 21:28:15 +010054 return oxpcie_present;
Kyösti Mälkki2b95da02014-02-15 10:19:23 +020055}
56
Felix Helde3a12472020-09-11 15:47:09 +020057uintptr_t uart_platform_base(unsigned int idx)
Kyösti Mälkki2b95da02014-02-15 10:19:23 +020058{
Felix Helde3a12472020-09-11 15:47:09 +020059 if ((idx < 8) && oxpcie_uart_active())
Kyösti Mälkkie993ec72015-03-20 08:51:57 +020060 return uart0_base + idx * 0x200;
Kyösti Mälkki2b95da02014-02-15 10:19:23 +020061 return 0;
62}
63
Kyösti Mälkki2b95da02014-02-15 10:19:23 +020064void oxford_remap(u32 new_base)
65{
Kyösti Mälkkifb25f9f2018-12-26 20:15:58 +020066#if ENV_RAMSTAGE
Kyösti Mälkki2b95da02014-02-15 10:19:23 +020067 uart0_base = new_base + 0x1000;
Gabe Black4d04a712011-10-05 01:52:08 -070068#endif
Kyösti Mälkkifb25f9f2018-12-26 20:15:58 +020069}
Kyösti Mälkki3ee16682014-02-17 19:37:52 +020070
71unsigned int uart_platform_refclk(void)
72{
73 return 62500000;
74}