02cf1ea9b561742c0ead4aaa469c1224153091e9
[openwrt/staging/yousong.git] / target / linux / bcm53xx / patches-3.14 / 121-bcma-get-irqs-from-dt.patch
1 From eaf1943a2c49cbc6eb0ffafa7b6ced45f2d328da 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 05/17] 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 drivers/bcma/main.c | 42 +++++++++++++++++++++++++++++++++++++++++-
14 1 file changed, 41 insertions(+), 1 deletion(-)
15
16 --- a/drivers/bcma/main.c
17 +++ b/drivers/bcma/main.c
18 @@ -10,6 +10,8 @@
19 #include <linux/platform_device.h>
20 #include <linux/bcma/bcma.h>
21 #include <linux/slab.h>
22 +#include <linux/of_irq.h>
23 +#include <linux/of_address.h>
24
25 MODULE_DESCRIPTION("Broadcom's specific AMBA driver");
26 MODULE_LICENSE("GPL");
27 @@ -131,6 +133,38 @@ static bool bcma_is_core_needed_early(u1
28 return false;
29 }
30
31 +static struct device_node *bcma_of_find_child_device(struct platform_device *parent,
32 + struct bcma_device *core)
33 +{
34 + struct device_node *node;
35 + u64 size;
36 + const __be32 *reg;
37 +
38 + if (!parent || !parent->dev.of_node)
39 + return NULL;
40 +
41 + for_each_child_of_node(parent->dev.of_node, node) {
42 + reg = of_get_address(node, 0, &size, NULL);
43 + if (!reg)
44 + continue;
45 + if (be32_to_cpup(reg) == core->addr)
46 + return node;
47 + }
48 + return NULL;
49 +}
50 +
51 +static void bcma_of_fill_device(struct platform_device *parent,
52 + struct bcma_device *core)
53 +{
54 + struct device_node *node;
55 +
56 + node = bcma_of_find_child_device(parent, core);
57 + if (!node)
58 + return;
59 + core->dev.of_node = node;
60 + core->irq = irq_of_parse_and_map(node, 0);
61 +}
62 +
63 static void bcma_register_core(struct bcma_bus *bus, struct bcma_device *core)
64 {
65 int err;
66 @@ -147,7 +181,13 @@ static void bcma_register_core(struct bc
67 break;
68 case BCMA_HOSTTYPE_SOC:
69 core->dev.dma_mask = &core->dev.coherent_dma_mask;
70 - core->dma_dev = &core->dev;
71 + if (bus->host_pdev) {
72 + core->dma_dev = &bus->host_pdev->dev;
73 + core->dev.parent = &bus->host_pdev->dev;
74 + bcma_of_fill_device(bus->host_pdev, core);
75 + } else {
76 + core->dma_dev = &core->dev;
77 + }
78 break;
79 case BCMA_HOSTTYPE_SDIO:
80 break;