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