blob: 8ce089043a27dcd05be911bd1cd953e4abe92af0 [file] [log] [blame]
Hauke Mehrtens4785ffb2015-05-12 23:23:01 +02001/*
2 * Copyright (C) 2015 Broadcom Corporation
3 * Copyright (C) 2015 Hauke Mehrtens <hauke@hauke-m.de>
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation version 2.
8 *
9 * This program is distributed "as is" WITHOUT ANY WARRANTY of any
10 * kind, whether express or implied; without even the implied warranty
11 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 */
14
15#include <linux/kernel.h>
16#include <linux/pci.h>
17#include <linux/module.h>
18#include <linux/slab.h>
19#include <linux/phy/phy.h>
20#include <linux/bcma/bcma.h>
21#include <linux/ioport.h>
22
23#include "pcie-iproc.h"
24
25
26/* NS: CLASS field is R/O, and set to wrong 0x200 value */
27static void bcma_pcie2_fixup_class(struct pci_dev *dev)
28{
29 dev->class = PCI_CLASS_BRIDGE_PCI << 8;
30}
31DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_BROADCOM, 0x8011, bcma_pcie2_fixup_class);
32DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_BROADCOM, 0x8012, bcma_pcie2_fixup_class);
33
34static int iproc_pcie_bcma_map_irq(const struct pci_dev *dev, u8 slot, u8 pin)
35{
36 struct pci_sys_data *sys = dev->sysdata;
37 struct iproc_pcie *pcie = sys->private_data;
38 struct bcma_device *bdev = container_of(pcie->dev, struct bcma_device, dev);
39
40 return bcma_core_irq(bdev, 5);
41}
42
43static int iproc_pcie_bcma_probe(struct bcma_device *bdev)
44{
Bjorn Helgaas786aecc2016-10-06 13:36:08 -050045 struct device *dev = &bdev->dev;
Hauke Mehrtens4785ffb2015-05-12 23:23:01 +020046 struct iproc_pcie *pcie;
47 LIST_HEAD(res);
48 struct resource res_mem;
49 int ret;
50
Bjorn Helgaas786aecc2016-10-06 13:36:08 -050051 pcie = devm_kzalloc(dev, sizeof(*pcie), GFP_KERNEL);
Hauke Mehrtens4785ffb2015-05-12 23:23:01 +020052 if (!pcie)
53 return -ENOMEM;
54
Bjorn Helgaas786aecc2016-10-06 13:36:08 -050055 pcie->dev = dev;
Hauke Mehrtens4785ffb2015-05-12 23:23:01 +020056
57 pcie->base = bdev->io_addr;
Bjorn Helgaasf66e5b22016-10-06 13:36:07 -050058 if (!pcie->base) {
59 dev_err(dev, "no controller registers\n");
60 return -ENOMEM;
61 }
62
Ray Jui3bc2b232016-01-06 18:04:35 -060063 pcie->base_addr = bdev->addr;
Hauke Mehrtens4785ffb2015-05-12 23:23:01 +020064
65 res_mem.start = bdev->addr_s[0];
66 res_mem.end = bdev->addr_s[0] + SZ_128M - 1;
67 res_mem.name = "PCIe MEM space";
68 res_mem.flags = IORESOURCE_MEM;
69 pci_add_resource(&res, &res_mem);
70
Hauke Mehrtens4785ffb2015-05-12 23:23:01 +020071 pcie->map_irq = iproc_pcie_bcma_map_irq;
72
Hauke Mehrtens18c43422015-05-24 22:37:02 +020073 ret = iproc_pcie_setup(pcie, &res);
Hauke Mehrtensef079912015-05-24 22:37:03 +020074 if (ret)
Bjorn Helgaas786aecc2016-10-06 13:36:08 -050075 dev_err(dev, "PCIe controller setup failed\n");
Hauke Mehrtens4785ffb2015-05-12 23:23:01 +020076
Hauke Mehrtensef079912015-05-24 22:37:03 +020077 pci_free_resource_list(&res);
78
Bjorn Helgaas556c7bb2016-10-06 13:36:08 -050079 bcma_set_drvdata(bdev, pcie);
Hauke Mehrtensef079912015-05-24 22:37:03 +020080 return ret;
Hauke Mehrtens4785ffb2015-05-12 23:23:01 +020081}
82
83static void iproc_pcie_bcma_remove(struct bcma_device *bdev)
84{
85 struct iproc_pcie *pcie = bcma_get_drvdata(bdev);
86
87 iproc_pcie_remove(pcie);
88}
89
90static const struct bcma_device_id iproc_pcie_bcma_table[] = {
91 BCMA_CORE(BCMA_MANUF_BCM, BCMA_CORE_NS_PCIEG2, BCMA_ANY_REV, BCMA_ANY_CLASS),
92 {},
93};
94MODULE_DEVICE_TABLE(bcma, iproc_pcie_bcma_table);
95
96static struct bcma_driver iproc_pcie_bcma_driver = {
97 .name = KBUILD_MODNAME,
98 .id_table = iproc_pcie_bcma_table,
99 .probe = iproc_pcie_bcma_probe,
100 .remove = iproc_pcie_bcma_remove,
101};
102
103static int __init iproc_pcie_bcma_init(void)
104{
105 return bcma_driver_register(&iproc_pcie_bcma_driver);
106}
107module_init(iproc_pcie_bcma_init);
108
109static void __exit iproc_pcie_bcma_exit(void)
110{
111 bcma_driver_unregister(&iproc_pcie_bcma_driver);
112}
113module_exit(iproc_pcie_bcma_exit);
114
115MODULE_AUTHOR("Hauke Mehrtens");
116MODULE_DESCRIPTION("Broadcom iProc PCIe BCMA driver");
117MODULE_LICENSE("GPL v2");