blob: a68beb2687afc2a43f6f49c3bfcf243d374a4ef6 [file] [log] [blame]
Werner Zeh42b88352021-11-16 07:31:44 +01001/* SPDX-License-Identifier: GPL-2.0-only */
2
3#include <arch/mmio.h>
4#include <device/pci.h>
5#include <device/pci_def.h>
6#include <device/pci_ids.h>
7#include <device/pci_ops.h>
8#include <types.h>
9
10#include "nc_fpga.h"
11
12static DEVTREE_CONST uint32_t fpga_bar = CONFIG_EARLY_PCI_MMIO_BASE;
13static bool nc_fpga_present = false;
14
15int pci_early_device_probe(u8 bus, u8 dev, u32 mmio_base)
16{
17 pci_devfn_t pci_dev = PCI_DEV(bus, dev, 0);
18 uint32_t id = pci_s_read_config32(pci_dev, PCI_VENDOR_ID);
19
Felix Singer43b7f412022-03-07 04:34:52 +010020 if (id != (0x4091 << 16 | PCI_VID_SIEMENS))
Werner Zeh42b88352021-11-16 07:31:44 +010021 return -1;
22
23 /* Setup base address for BAR0. */
24 pci_s_write_config32(pci_dev, PCI_BASE_ADDRESS_0, mmio_base);
25 /* Enable memory access for pci_dev. */
26 u16 reg16 = pci_s_read_config16(pci_dev, PCI_COMMAND);
27 reg16 |= PCI_COMMAND_MEMORY;
28 pci_s_write_config16(pci_dev, PCI_COMMAND, reg16);
29 nc_fpga_present = true;
30
31 return 0;
32}
33
34void nc_fpga_remap(uint32_t new_mmio)
35{
36#if ENV_RAMSTAGE
37 fpga_bar = new_mmio;
38#endif
39}
40
41void nc_fpga_post(uint8_t value)
42{
43 /* The function pci_earyl_device_probe is called in bootblock and romstage. Make sure
44 that in these stages the initialization code was successful before the POST code
45 value is written to the register. */
46 if ((ENV_BOOTBLOCK || ENV_ROMSTAGE) && nc_fpga_present == false)
47 return;
48 write32((void *)(fpga_bar + NC_FPGA_POST_OFFSET), value);
49}