bcm53xx: update to kernel 3.14
[openwrt.git] / target / linux / bcm53xx / patches-3.14 / 123-bcma-get-sprom-from-devicetree.patch
1 From 5d94449a92e4121b408e7cb8931a47984135eeea Mon Sep 17 00:00:00 2001
2 From: Hauke Mehrtens <hauke@hauke-m.de>
3 Date: Sun, 4 May 2014 14:34:31 +0200
4 Subject: [PATCH 07/15] bcma: get sprom from devicetree
5
6 This patch make it possible to device an sprom provider in device tree
7 and get the sprom from this driver. Every time there is such a provider
8 it gets asked for a sprom.
9
10 Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
11 ---
12  drivers/bcma/sprom.c | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++-
13  1 file changed, 50 insertions(+), 1 deletion(-)
14
15 --- a/drivers/bcma/sprom.c
16 +++ b/drivers/bcma/sprom.c
17 @@ -15,6 +15,8 @@
18  #include <linux/io.h>
19  #include <linux/dma-mapping.h>
20  #include <linux/slab.h>
21 +#include <linux/of.h>
22 +#include <linux/of_platform.h>
23  
24  static int(*get_fallback_sprom)(struct bcma_bus *dev, struct ssb_sprom *out);
25  
26 @@ -46,6 +48,46 @@ int bcma_arch_register_fallback_sprom(in
27         return 0;
28  }
29  
30 +#ifdef CONFIG_OF
31 +static int bcma_fill_sprom_with_dt(struct bcma_bus *bus,
32 +                                  struct ssb_sprom *out)
33 +{
34 +       const phandle *handle;
35 +       struct device_node *sprom_node;
36 +       struct platform_device *sprom_dev;
37 +       struct ssb_sprom *sprom;
38 +
39 +       if (!bus->host_pdev || !bus->host_pdev->dev.of_node)
40 +               return -ENOENT;
41 +
42 +       handle = of_get_property(bus->host_pdev->dev.of_node, "sprom", NULL);
43 +       if (!handle)
44 +               return -ENOENT;
45 +
46 +       sprom_node = of_find_node_by_phandle(be32_to_cpup(handle));
47 +       if (!sprom_node)
48 +               return -ENOENT;
49 +
50 +       sprom_dev = of_find_device_by_node(sprom_node);
51 +       if (!sprom_dev)
52 +               return -ENOENT;
53 +
54 +       sprom = platform_get_drvdata(sprom_dev);
55 +       if (!sprom)
56 +               return -ENOENT;
57 +
58 +       memcpy(out, sprom, sizeof(*out));
59 +
60 +       return 0;
61 +}
62 +#else
63 +static int bcma_fill_sprom_with_dt(struct bcma_bus *bus,
64 +                                  struct ssb_sprom *out)
65 +{
66 +       return -ENOENT;
67 +}
68 +#endif
69 +
70  static int bcma_fill_sprom_with_fallback(struct bcma_bus *bus,
71                                          struct ssb_sprom *out)
72  {
73 @@ -580,7 +622,14 @@ int bcma_sprom_get(struct bcma_bus *bus)
74         u16 *sprom;
75         size_t sprom_sizes[] = { SSB_SPROMSIZE_WORDS_R4,
76                                  SSB_SPROMSIZE_WORDS_R10, };
77 -       int i, err = 0;
78 +       int i, err;
79 +
80 +       err = bcma_fill_sprom_with_dt(bus, &bus->sprom);
81 +       if (err == 0) {
82 +               bcma_info(bus, "Found sprom from device tree provider\n");
83 +               return 0;
84 +       }
85 +       err = 0;
86  
87         if (!bus->drv_cc.core)
88                 return -EOPNOTSUPP;