fixups-sdk7786.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * SDK7786 FPGA PCIe mux handling
  4. *
  5. * Copyright (C) 2010 Paul Mundt
  6. */
  7. #define pr_fmt(fmt) "PCI: " fmt
  8. #include <linux/init.h>
  9. #include <linux/kernel.h>
  10. #include <linux/pci.h>
  11. #include <mach/fpga.h>
  12. /*
  13. * The SDK7786 FPGA supports mangling of most of the slots in some way or
  14. * another. Slots 3/4 are special in that only one can be supported at a
  15. * time, and both appear on port 3 to the PCI bus scan. Enabling slot 4
  16. * (the horizontal edge connector) will disable slot 3 entirely.
  17. *
  18. * Misconfigurations can be detected through the FPGA via the slot
  19. * resistors to determine card presence. Hotplug remains unsupported.
  20. */
  21. static unsigned int slot4en __initdata;
  22. char *__init pcibios_setup(char *str)
  23. {
  24. if (strcmp(str, "slot4en") == 0) {
  25. slot4en = 1;
  26. return NULL;
  27. }
  28. return str;
  29. }
  30. static int __init sdk7786_pci_init(void)
  31. {
  32. u16 data = fpga_read_reg(PCIECR);
  33. /*
  34. * Enable slot #4 if it's been specified on the command line.
  35. *
  36. * Optionally reroute if slot #4 has a card present while slot #3
  37. * does not, regardless of command line value.
  38. *
  39. * Card presence is logically inverted.
  40. */
  41. slot4en ?: (!(data & PCIECR_PRST4) && (data & PCIECR_PRST3));
  42. if (slot4en) {
  43. pr_info("Activating PCIe slot#4 (disabling slot#3)\n");
  44. data &= ~PCIECR_PCIEMUX1;
  45. fpga_write_reg(data, PCIECR);
  46. /* Warn about forced rerouting if slot#3 is occupied */
  47. if ((data & PCIECR_PRST3) == 0) {
  48. pr_warn("Unreachable card detected in slot#3\n");
  49. return -EBUSY;
  50. }
  51. } else
  52. pr_info("PCIe slot#4 disabled\n");
  53. return 0;
  54. }
  55. postcore_initcall(sdk7786_pci_init);