030-0002-PCI-iproc-Add-BCMA-PCIe-driver.patch 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. From 4785ffbdc9b52e308e43b9e2dcc1dca44f056d76 Mon Sep 17 00:00:00 2001
  2. From: Hauke Mehrtens <hauke@hauke-m.de>
  3. Date: Tue, 12 May 2015 23:23:01 +0200
  4. Subject: [PATCH 2/2] PCI: iproc: Add BCMA PCIe driver
  5. MIME-Version: 1.0
  6. Content-Type: text/plain; charset=UTF-8
  7. Content-Transfer-Encoding: 8bit
  8. This driver adds support for the PCIe 2.0 controller found on the BCMA bus.
  9. This controller can be found on (mostly) all Broadcom BCM470X / BCM5301X
  10. ARM SoCs.
  11. The driver found in the Broadcom SDK does some more stuff, like setting up
  12. some DMA memory areas, chaining MPS and MRRS to 512 and also some PHY
  13. changes like "improving" the PCIe jitter and doing some special
  14. initialization for the 3rd PCIe port.
  15. This was tested on a bcm4708 board with 2 PCIe ports and wireless cards
  16. connected to them.
  17. PCI_DOMAINS is needed by this driver, because normally there is more than
  18. one PCIe controller and without PCI_DOMAINS only the first controller gets
  19. registered. This controller gets 6 IRQs; the last one is trigged by all
  20. IRQ events.
  21. [bhelgaas: fix "GPLv2" MODULE_LICENSE typo]
  22. Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
  23. Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
  24. Acked-by: Rafał Miłecki <zajec5@gmail.com>
  25. Acked-by: Ray Jui <rjui@broadcom.com.com>
  26. ---
  27. drivers/pci/host/Kconfig | 11 ++++
  28. drivers/pci/host/Makefile | 1 +
  29. drivers/pci/host/pcie-iproc-bcma.c | 112 +++++++++++++++++++++++++++++++++++++
  30. 3 files changed, 124 insertions(+)
  31. create mode 100644 drivers/pci/host/pcie-iproc-bcma.c
  32. --- a/drivers/pci/host/Kconfig
  33. +++ b/drivers/pci/host/Kconfig
  34. @@ -125,4 +125,15 @@ config PCIE_IPROC_PLATFORM
  35. Say Y here if you want to use the Broadcom iProc PCIe controller
  36. through the generic platform bus interface
  37. +config PCIE_IPROC_BCMA
  38. + bool "Broadcom iProc PCIe BCMA bus driver"
  39. + depends on ARCH_BCM_IPROC || (ARM && COMPILE_TEST)
  40. + select PCIE_IPROC
  41. + select BCMA
  42. + select PCI_DOMAINS
  43. + default ARCH_BCM_5301X
  44. + help
  45. + Say Y here if you want to use the Broadcom iProc PCIe controller
  46. + through the BCMA bus interface
  47. +
  48. endmenu
  49. --- a/drivers/pci/host/Makefile
  50. +++ b/drivers/pci/host/Makefile
  51. @@ -15,3 +15,4 @@ obj-$(CONFIG_PCI_LAYERSCAPE) += pci-laye
  52. obj-$(CONFIG_PCI_VERSATILE) += pci-versatile.o
  53. obj-$(CONFIG_PCIE_IPROC) += pcie-iproc.o
  54. obj-$(CONFIG_PCIE_IPROC_PLATFORM) += pcie-iproc-platform.o
  55. +obj-$(CONFIG_PCIE_IPROC_BCMA) += pcie-iproc-bcma.o
  56. --- /dev/null
  57. +++ b/drivers/pci/host/pcie-iproc-bcma.c
  58. @@ -0,0 +1,112 @@
  59. +/*
  60. + * Copyright (C) 2015 Broadcom Corporation
  61. + * Copyright (C) 2015 Hauke Mehrtens <hauke@hauke-m.de>
  62. + *
  63. + * This program is free software; you can redistribute it and/or
  64. + * modify it under the terms of the GNU General Public License as
  65. + * published by the Free Software Foundation version 2.
  66. + *
  67. + * This program is distributed "as is" WITHOUT ANY WARRANTY of any
  68. + * kind, whether express or implied; without even the implied warranty
  69. + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  70. + * GNU General Public License for more details.
  71. + */
  72. +
  73. +#include <linux/kernel.h>
  74. +#include <linux/pci.h>
  75. +#include <linux/module.h>
  76. +#include <linux/slab.h>
  77. +#include <linux/phy/phy.h>
  78. +#include <linux/bcma/bcma.h>
  79. +#include <linux/ioport.h>
  80. +
  81. +#include "pcie-iproc.h"
  82. +
  83. +
  84. +/* NS: CLASS field is R/O, and set to wrong 0x200 value */
  85. +static void bcma_pcie2_fixup_class(struct pci_dev *dev)
  86. +{
  87. + dev->class = PCI_CLASS_BRIDGE_PCI << 8;
  88. +}
  89. +DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_BROADCOM, 0x8011, bcma_pcie2_fixup_class);
  90. +DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_BROADCOM, 0x8012, bcma_pcie2_fixup_class);
  91. +
  92. +static int iproc_pcie_bcma_map_irq(const struct pci_dev *dev, u8 slot, u8 pin)
  93. +{
  94. + struct pci_sys_data *sys = dev->sysdata;
  95. + struct iproc_pcie *pcie = sys->private_data;
  96. + struct bcma_device *bdev = container_of(pcie->dev, struct bcma_device, dev);
  97. +
  98. + return bcma_core_irq(bdev, 5);
  99. +}
  100. +
  101. +static int iproc_pcie_bcma_probe(struct bcma_device *bdev)
  102. +{
  103. + struct iproc_pcie *pcie;
  104. + LIST_HEAD(res);
  105. + struct resource res_mem;
  106. + int ret;
  107. +
  108. + pcie = devm_kzalloc(&bdev->dev, sizeof(*pcie), GFP_KERNEL);
  109. + if (!pcie)
  110. + return -ENOMEM;
  111. +
  112. + pcie->dev = &bdev->dev;
  113. + bcma_set_drvdata(bdev, pcie);
  114. +
  115. + pcie->base = bdev->io_addr;
  116. +
  117. + res_mem.start = bdev->addr_s[0];
  118. + res_mem.end = bdev->addr_s[0] + SZ_128M - 1;
  119. + res_mem.name = "PCIe MEM space";
  120. + res_mem.flags = IORESOURCE_MEM;
  121. + pci_add_resource(&res, &res_mem);
  122. +
  123. + pcie->resources = &res;
  124. +
  125. + pcie->map_irq = iproc_pcie_bcma_map_irq;
  126. +
  127. + ret = iproc_pcie_setup(pcie);
  128. + if (ret) {
  129. + dev_err(pcie->dev, "PCIe controller setup failed\n");
  130. + return ret;
  131. + }
  132. +
  133. + return 0;
  134. +}
  135. +
  136. +static void iproc_pcie_bcma_remove(struct bcma_device *bdev)
  137. +{
  138. + struct iproc_pcie *pcie = bcma_get_drvdata(bdev);
  139. +
  140. + iproc_pcie_remove(pcie);
  141. +}
  142. +
  143. +static const struct bcma_device_id iproc_pcie_bcma_table[] = {
  144. + BCMA_CORE(BCMA_MANUF_BCM, BCMA_CORE_NS_PCIEG2, BCMA_ANY_REV, BCMA_ANY_CLASS),
  145. + {},
  146. +};
  147. +MODULE_DEVICE_TABLE(bcma, iproc_pcie_bcma_table);
  148. +
  149. +static struct bcma_driver iproc_pcie_bcma_driver = {
  150. + .name = KBUILD_MODNAME,
  151. + .id_table = iproc_pcie_bcma_table,
  152. + .probe = iproc_pcie_bcma_probe,
  153. + .remove = iproc_pcie_bcma_remove,
  154. +};
  155. +
  156. +static int __init iproc_pcie_bcma_init(void)
  157. +{
  158. + return bcma_driver_register(&iproc_pcie_bcma_driver);
  159. +}
  160. +module_init(iproc_pcie_bcma_init);
  161. +
  162. +static void __exit iproc_pcie_bcma_exit(void)
  163. +{
  164. + bcma_driver_unregister(&iproc_pcie_bcma_driver);
  165. +}
  166. +module_exit(iproc_pcie_bcma_exit);
  167. +
  168. +MODULE_AUTHOR("Hauke Mehrtens");
  169. +MODULE_DESCRIPTION("Broadcom iProc PCIe BCMA driver");
  170. +MODULE_LICENSE("GPL v2");