ath9k: improve ANI debugfs file
[openwrt.git] / package / kernel / mac80211 / patches / 904-wlcore-add-initial-device-tree-support-to-the-sdio-module.patch
1 If platform data is not available, try to get the required information
2 from the device tree.  Register an OF match table and parse the
3 appropriate device tree nodes.
4
5 Parse interrupt property only, for now.
6
7 Signed-off-by: Luciano Coelho <coelho@ti.com>
8 Reviewed-by: Felipe Balbi <balbi@ti.com>
9
10 --- a/drivers/net/wireless/ti/wlcore/sdio.c
11 +++ b/drivers/net/wireless/ti/wlcore/sdio.c
12 @@ -30,7 +30,7 @@
13  #include <linux/mmc/sdio_ids.h>
14  #include <linux/mmc/card.h>
15  #include <linux/mmc/host.h>
16 -#include <linux/gpio.h>
17 +#include <linux/of_irq.h>
18  #include <linux/wl12xx.h>
19  #include <linux/pm_runtime.h>
20  #include <linux/printk.h>
21 @@ -214,6 +214,43 @@ static struct wl1271_if_operations sdio_
22         .set_block_size = wl1271_sdio_set_block_size,
23  };
24  
25 +static struct wl12xx_platform_data *wlcore_get_pdata_from_of(struct device *dev)
26 +{
27 +       struct wl12xx_platform_data *pdata;
28 +       struct device_node *np = dev->of_node;
29 +
30 +       if (!np) {
31 +               np = of_find_matching_node(NULL, dev->driver->of_match_table);
32 +               if (!np) {
33 +                       dev_notice(dev, "device tree node not available\n");
34 +                       pdata = ERR_PTR(-ENODEV);
35 +                       goto out;
36 +               }
37 +       }
38 +
39 +       pdata = kzalloc(sizeof(*pdata), GFP_KERNEL);
40 +       if (!pdata) {
41 +               dev_err(dev, "can't allocate platform data\n");
42 +               pdata = ERR_PTR(-ENODEV);
43 +               goto out;
44 +       }
45 +
46 +       pdata->irq = irq_of_parse_and_map(np, 0);
47 +       if (pdata->irq < 0) {
48 +               dev_err(dev, "can't get interrupt gpio from the device tree\n");
49 +               goto out_free;
50 +       }
51 +
52 +       goto out;
53 +
54 +out_free:
55 +       kfree(pdata);
56 +       pdata = ERR_PTR(-ENODEV);
57 +
58 +out:
59 +       return pdata;
60 +}
61 +
62  static int wl1271_probe(struct sdio_func *func,
63                                   const struct sdio_device_id *id)
64  {
65 @@ -248,11 +285,22 @@ static int wl1271_probe(struct sdio_func
66         /* Use block mode for transferring over one block size of data */
67         func->card->quirks |= MMC_QUIRK_BLKSZ_FOR_BYTE_MODE;
68  
69 +       /* The pdata allocated here is freed when the device is freed,
70 +        * so we don't need an additional out label to free it in case
71 +        * of error further on.
72 +        */
73 +
74 +       /* Try to get legacy platform data from the board file */
75         pdev_data->pdata = wl12xx_get_platform_data();
76         if (IS_ERR(pdev_data->pdata)) {
77 -               ret = PTR_ERR(pdev_data->pdata);
78 -               dev_err(glue->dev, "missing wlan platform data: %d\n", ret);
79 -               goto out_free_glue;
80 +               dev_info(&func->dev,
81 +                        "legacy platform data not found, trying device tree\n");
82 +
83 +               pdev_data->pdata = wlcore_get_pdata_from_of(&func->dev);
84 +               if (IS_ERR(pdev_data->pdata)) {
85 +                       dev_err(&func->dev, "can't get platform data\n");
86 +                       goto out_free_glue;
87 +               }
88         }
89  
90         /* if sdio can keep power while host is suspended, enable wow */
91 @@ -386,16 +434,25 @@ static const struct dev_pm_ops wl1271_sd
92  };
93  #endif
94  
95 +static const struct of_device_id wlcore_sdio_of_match_table[] = {
96 +       { .compatible = "ti,wilink6" },
97 +       { .compatible = "ti,wilink7" },
98 +       { .compatible = "ti,wilink8" },
99 +       { }
100 +};
101 +MODULE_DEVICE_TABLE(of, wlcore_sdio_of_match_table);
102 +
103  static struct sdio_driver wl1271_sdio_driver = {
104         .name           = "wl1271_sdio",
105         .id_table       = wl1271_devices,
106         .probe          = wl1271_probe,
107         .remove         = wl1271_remove,
108 -#ifdef CONFIG_PM
109         .drv = {
110 +#ifdef CONFIG_PM
111                 .pm = &wl1271_sdio_pm_ops,
112 -       },
113  #endif
114 +               .of_match_table = of_match_ptr(wlcore_sdio_of_match_table),
115 +       },
116  };
117  
118  static int __init wl1271_init(void)