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