bcm53xx: bcma: get IRQs also from device tree
[openwrt/staging/wigyori.git] / target / linux / bcm53xx / patches-3.18 / 061-bcma-get-IRQ-numbers-from-dt.patch
1 From 4eb6a1fd46965ed6c3fb9327276eb53a3021eaaa Mon Sep 17 00:00:00 2001
2 From: Hauke Mehrtens <hauke@hauke-m.de>
3 Date: Thu, 9 Jan 2014 19:40:14 +0100
4 Subject: [PATCH 3/3] bcma: get IRQ numbers from dt
5
6 It is not possible to auto detect the irq numbers used by the cores on
7 an arm SoC. If bcma was registered with device tree it will search for
8 some device tree nodes with the irq number and add it to the core
9 configuration.
10
11 Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
12 ---
13 Documentation/devicetree/bindings/bus/bcma.txt | 21 +++++++++++
14 drivers/bcma/main.c | 52 +++++++++++++++++++++++++-
15 2 files changed, 72 insertions(+), 1 deletion(-)
16
17 --- a/Documentation/devicetree/bindings/bus/bcma.txt
18 +++ b/Documentation/devicetree/bindings/bus/bcma.txt
19 @@ -8,6 +8,11 @@ Required properties:
20
21 The cores on the AXI bus are automatically detected by bcma with the
22 memory ranges they are using and they get registered afterwards.
23 +Automatic detection of the IRQ number is not working on
24 +BCM47xx/BCM53xx ARM SoCs. To assign IRQ numbers to the cores, provide
25 +them manually through device tree. Use an interrupt-map to specify the
26 +IRQ used by the devices on the bus. The first address is just an index,
27 +because we do not have any special register.
28
29 The top-level axi bus may contain children representing attached cores
30 (devices). This is needed since some hardware details can't be auto
31 @@ -22,6 +27,22 @@ Example:
32 ranges = <0x00000000 0x18000000 0x00100000>;
33 #address-cells = <1>;
34 #size-cells = <1>;
35 + #interrupt-cells = <1>;
36 + interrupt-map-mask = <0x000fffff 0xffff>;
37 + interrupt-map =
38 + /* Ethernet Controller 0 */
39 + <0x00024000 0 &gic GIC_SPI 147 IRQ_TYPE_LEVEL_HIGH>,
40 +
41 + /* Ethernet Controller 1 */
42 + <0x00025000 0 &gic GIC_SPI 148 IRQ_TYPE_LEVEL_HIGH>;
43 +
44 + /* PCIe Controller 0 */
45 + <0x00012000 0 &gic GIC_SPI 126 IRQ_TYPE_LEVEL_HIGH>,
46 + <0x00012000 1 &gic GIC_SPI 127 IRQ_TYPE_LEVEL_HIGH>,
47 + <0x00012000 2 &gic GIC_SPI 128 IRQ_TYPE_LEVEL_HIGH>,
48 + <0x00012000 3 &gic GIC_SPI 129 IRQ_TYPE_LEVEL_HIGH>,
49 + <0x00012000 4 &gic GIC_SPI 130 IRQ_TYPE_LEVEL_HIGH>,
50 + <0x00012000 5 &gic GIC_SPI 131 IRQ_TYPE_LEVEL_HIGH>;
51
52 chipcommon {
53 reg = <0x00000000 0x1000>;
54 --- a/drivers/bcma/main.c
55 +++ b/drivers/bcma/main.c
56 @@ -11,6 +11,7 @@
57 #include <linux/bcma/bcma.h>
58 #include <linux/slab.h>
59 #include <linux/of_address.h>
60 +#include <linux/of_irq.h>
61
62 MODULE_DESCRIPTION("Broadcom's specific AMBA driver");
63 MODULE_LICENSE("GPL");
64 @@ -153,6 +154,46 @@ static struct device_node *bcma_of_find_
65 return NULL;
66 }
67
68 +static int bcma_of_irq_parse(struct platform_device *parent,
69 + struct bcma_device *core,
70 + struct of_phandle_args *out_irq, int num)
71 +{
72 + __be32 laddr[1];
73 + int rc;
74 +
75 + if (core->dev.of_node) {
76 + rc = of_irq_parse_one(core->dev.of_node, num, out_irq);
77 + if (!rc)
78 + return rc;
79 + }
80 +
81 + out_irq->np = parent->dev.of_node;
82 + out_irq->args_count = 1;
83 + out_irq->args[0] = num;
84 +
85 + laddr[0] = cpu_to_be32(core->addr);
86 + return of_irq_parse_raw(laddr, out_irq);
87 +}
88 +
89 +static unsigned int bcma_of_get_irq(struct platform_device *parent,
90 + struct bcma_device *core, int num)
91 +{
92 + struct of_phandle_args out_irq;
93 + int ret;
94 +
95 + if (!parent || !parent->dev.of_node)
96 + return 0;
97 +
98 + ret = bcma_of_irq_parse(parent, core, &out_irq, num);
99 + if (ret) {
100 + bcma_debug(core->bus, "bcma_of_get_irq() failed with rc=%d\n",
101 + ret);
102 + return 0;
103 + }
104 +
105 + return irq_create_of_mapping(&out_irq);
106 +}
107 +
108 static void bcma_of_fill_device(struct platform_device *parent,
109 struct bcma_device *core)
110 {
111 @@ -161,12 +202,19 @@ static void bcma_of_fill_device(struct p
112 node = bcma_of_find_child_device(parent, core);
113 if (node)
114 core->dev.of_node = node;
115 +
116 + core->irq = bcma_of_get_irq(parent, core, 0);
117 }
118 #else
119 static void bcma_of_fill_device(struct platform_device *parent,
120 struct bcma_device *core)
121 {
122 }
123 +static inline unsigned int bcma_of_get_irq(struct platform_device *parent,
124 + struct bcma_device *core, int num)
125 +{
126 + return 0;
127 +}
128 #endif /* CONFIG_OF */
129
130 unsigned int bcma_core_irq(struct bcma_device *core, int num)
131 @@ -182,7 +230,9 @@ unsigned int bcma_core_irq(struct bcma_d
132 mips_irq = bcma_core_mips_irq(core);
133 return mips_irq <= 4 ? mips_irq + 2 : 0;
134 }
135 - break;
136 + if (bus->host_pdev)
137 + return bcma_of_get_irq(bus->host_pdev, core, num);
138 + return 0;
139 case BCMA_HOSTTYPE_SDIO:
140 return 0;
141 }