kernel: add bcma patches sent upstream but not pushed yet
[librecmc/librecmc.git] / target / linux / bcm53xx / patches-3.14 / 120-bcma-register-bcma-as-device-tree-driver.patch
1 From 04b91da96d7c163fd39c0849d2034e2928103f4d Mon Sep 17 00:00:00 2001
2 From: Hauke Mehrtens <hauke@hauke-m.de>
3 Date: Mon, 6 Jan 2014 23:29:15 +0100
4 Subject: [PATCH 04/17] bcma: register bcma as device tree driver
5
6 This driver is used by the bcm53xx ARM SoC code. Now it is possible to
7 give the address of the chipcommon core in device tree and bcma will
8 search for all the other cores.
9
10 Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
11 ---
12  Documentation/devicetree/bindings/bus/bcma.txt | 46 +++++++++++++++++
13  drivers/bcma/host_soc.c                        | 70 ++++++++++++++++++++++++++
14  include/linux/bcma/bcma.h                      |  2 +
15  3 files changed, 118 insertions(+)
16  create mode 100644 Documentation/devicetree/bindings/bus/bcma.txt
17
18 --- /dev/null
19 +++ b/Documentation/devicetree/bindings/bus/bcma.txt
20 @@ -0,0 +1,46 @@
21 +Broadcom AIX bcma bus driver
22 +
23 +
24 +Required properties:
25 +
26 +- compatible : brcm,bus-aix
27 +
28 +- reg : iomem address range of chipcommon core
29 +
30 +Optional properties:
31 +
32 +- sprom: reference to a sprom driver. This is needed for sprom less devices.
33 +        Use bcm47xx_sprom for example.
34 +
35 +
36 +The cores on the AIX bus are auto detected by bcma. Detection of the
37 +IRQ number is not supported on BCM47xx/BCM53xx ARM SoCs, so it is
38 +possible to provide the IRQ number over device tree. The IRQ number and
39 +the device tree child entry will be added to the core with the matching
40 +reg address.
41 +
42 +Example:
43 +
44 +       aix@18000000 {
45 +               compatible = "brcm,bus-aix";
46 +               reg = <0x18000000 0x1000>;
47 +               ranges = <0x00000000 0x18000000 0x00100000>;
48 +               #address-cells = <1>;
49 +               #size-cells = <1>;
50 +               sprom = <&sprom0>;
51 +
52 +               gmac@0 {
53 +                       reg = <0x18024000 0x1000>;
54 +                       interrupts = <GIC_SPI 147 IRQ_TYPE_LEVEL_HIGH>;
55 +               };
56 +
57 +               gmac@1 {
58 +                       reg = <0x18025000 0x1000>;
59 +                       interrupts = <GIC_SPI 148 IRQ_TYPE_LEVEL_HIGH>;
60 +               };
61 +
62 +               pcie@0 {
63 +                       reg = <0x18012000 0x1000>;
64 +                       interrupts = <GIC_SPI 131 IRQ_TYPE_LEVEL_HIGH>;
65 +               };
66 +       };
67 --- a/drivers/bcma/host_soc.c
68 +++ b/drivers/bcma/host_soc.c
69 @@ -7,6 +7,9 @@
70  
71  #include "bcma_private.h"
72  #include "scan.h"
73 +#include <linux/slab.h>
74 +#include <linux/module.h>
75 +#include <linux/of_address.h>
76  #include <linux/bcma/bcma.h>
77  #include <linux/bcma/bcma_soc.h>
78  
79 @@ -176,6 +179,7 @@ int __init bcma_host_soc_register(struct
80         /* Host specific */
81         bus->hosttype = BCMA_HOSTTYPE_SOC;
82         bus->ops = &bcma_host_soc_ops;
83 +       bus->host_pdev = NULL;
84  
85         /* Initialize struct, detect chip */
86         bcma_init_bus(bus);
87 @@ -195,3 +199,72 @@ int __init bcma_host_soc_init(struct bcm
88  
89         return err;
90  }
91 +
92 +#ifdef CONFIG_OF
93 +static int bcma_host_soc_probe(struct platform_device *pdev)
94 +{
95 +       struct device *dev = &pdev->dev;
96 +       struct device_node *np = dev->of_node;
97 +       struct bcma_bus *bus;
98 +       int err;
99 +
100 +       /* Alloc */
101 +       bus = devm_kzalloc(dev, sizeof(*bus), GFP_KERNEL);
102 +       if (!bus)
103 +               return -ENOMEM;
104 +
105 +       /* Map MMIO */
106 +       bus->mmio = of_iomap(np, 0);
107 +       if (!bus->mmio)
108 +               return -ENOMEM;
109 +
110 +       /* Host specific */
111 +       bus->hosttype = BCMA_HOSTTYPE_SOC;
112 +       bus->ops = &bcma_host_soc_ops;
113 +       bus->host_pdev = pdev;
114 +
115 +       /* Initialize struct, detect chip */
116 +       bcma_init_bus(bus);
117 +
118 +       /* Register */
119 +       err = bcma_bus_register(bus);
120 +       if (err)
121 +               goto err_unmap_mmio;
122 +
123 +       platform_set_drvdata(pdev, bus);
124 +
125 +       return err;
126 +
127 +err_unmap_mmio:
128 +       iounmap(bus->mmio);
129 +       return err;
130 +}
131 +
132 +static int bcma_host_soc_remove(struct platform_device *pdev)
133 +{
134 +       struct bcma_bus *bus = platform_get_drvdata(pdev);
135 +
136 +       bcma_bus_unregister(bus);
137 +       iounmap(bus->mmio);
138 +       platform_set_drvdata(pdev, NULL);
139 +
140 +       return 0;
141 +}
142 +
143 +static const struct of_device_id bcma_host_soc_of_match[] = {
144 +       { .compatible = "brcm,bus-aix", },
145 +       {},
146 +};
147 +MODULE_DEVICE_TABLE(of, bcma_host_soc_of_match);
148 +
149 +static struct platform_driver bcma_host_soc_driver = {
150 +       .driver = {
151 +               .name = "bcma-host-soc",
152 +               .owner = THIS_MODULE,
153 +               .of_match_table = bcma_host_soc_of_match,
154 +       },
155 +       .probe          = bcma_host_soc_probe,
156 +       .remove         = bcma_host_soc_remove,
157 +};
158 +module_platform_driver(bcma_host_soc_driver);
159 +#endif /* CONFIG_OF */
160 --- a/include/linux/bcma/bcma.h
161 +++ b/include/linux/bcma/bcma.h
162 @@ -323,6 +323,8 @@ struct bcma_bus {
163                 struct pci_dev *host_pci;
164                 /* Pointer to the SDIO device (only for BCMA_HOSTTYPE_SDIO) */
165                 struct sdio_func *host_sdio;
166 +               /* Pointer to platform device (only for BCMA_HOSTTYPE_SOC) */
167 +               struct platform_device *host_pdev;
168         };
169  
170         struct bcma_chipinfo chipinfo;