// SPDX-License-Identifier: GPL-2.01/*2* SDK7786 FPGA PCIe mux handling3*4* Copyright (C) 2010 Paul Mundt5*/6#define pr_fmt(fmt) "PCI: " fmt78#include <linux/init.h>9#include <linux/kernel.h>10#include <linux/pci.h>11#include <mach/fpga.h>1213/*14* The SDK7786 FPGA supports mangling of most of the slots in some way or15* another. Slots 3/4 are special in that only one can be supported at a16* time, and both appear on port 3 to the PCI bus scan. Enabling slot 417* (the horizontal edge connector) will disable slot 3 entirely.18*19* Misconfigurations can be detected through the FPGA via the slot20* resistors to determine card presence. Hotplug remains unsupported.21*/22static unsigned int slot4en __initdata;2324char *__init pcibios_setup(char *str)25{26if (strcmp(str, "slot4en") == 0) {27slot4en = 1;28return NULL;29}3031return str;32}3334static int __init sdk7786_pci_init(void)35{36u16 data = fpga_read_reg(PCIECR);3738/*39* Enable slot #4 if it's been specified on the command line.40*41* Optionally reroute if slot #4 has a card present while slot #342* does not, regardless of command line value.43*44* Card presence is logically inverted.45*/46slot4en ?: (!(data & PCIECR_PRST4) && (data & PCIECR_PRST3));47if (slot4en) {48pr_info("Activating PCIe slot#4 (disabling slot#3)\n");4950data &= ~PCIECR_PCIEMUX1;51fpga_write_reg(data, PCIECR);5253/* Warn about forced rerouting if slot#3 is occupied */54if ((data & PCIECR_PRST3) == 0) {55pr_warn("Unreachable card detected in slot#3\n");56return -EBUSY;57}58} else59pr_info("PCIe slot#4 disabled\n");6061return 0;62}63postcore_initcall(sdk7786_pci_init);646566