1 From adf0f7b7d7c0083dd936fe46423b89e974f8df12 Mon Sep 17 00:00:00 2001
2 From: Vladimir Ermakov <vooon341@gmail.com>
3 Date: Wed, 10 Jul 2013 03:06:54 +0400
4 Subject: [PATCH] ARM i.MX6 Wandboard add wifi+bt rfkill driver
6 BRCM WiFi module requires initialization for control gpio;
7 Additional provides rfkill funcs.
9 v2: fix wrong probe func in driver struct
10 v3: add imx6qdl compatible
12 Signed-off-by: Vladimir Ermakov <vooon341@gmail.com>
14 arch/arm/mach-imx/devices/Kconfig | 6 +
15 arch/arm/mach-imx/devices/Makefile | 1 +
16 arch/arm/mach-imx/devices/wand-rfkill.c | 290 ++++++++++++++++++++++++++++++++
17 3 files changed, 297 insertions(+)
18 create mode 100644 arch/arm/mach-imx/devices/wand-rfkill.c
20 diff --git a/arch/arm/mach-imx/devices/Kconfig b/arch/arm/mach-imx/devices/Kconfig
21 index 68c74fb..a0adf75 100644
22 --- a/arch/arm/mach-imx/devices/Kconfig
23 +++ b/arch/arm/mach-imx/devices/Kconfig
24 @@ -85,3 +85,9 @@ config IMX_HAVE_PLATFORM_SDHCI_ESDHC_IMX
26 config IMX_HAVE_PLATFORM_SPI_IMX
30 + tristate "Wandboard RF Kill support"
31 + depends on SOC_IMX6Q
34 diff --git a/arch/arm/mach-imx/devices/Makefile b/arch/arm/mach-imx/devices/Makefile
35 index 67416fb..b2aded5 100644
36 --- a/arch/arm/mach-imx/devices/Makefile
37 +++ b/arch/arm/mach-imx/devices/Makefile
38 @@ -30,3 +30,4 @@ obj-$(CONFIG_IMX_HAVE_PLATFORM_MXC_W1) += platform-mxc_w1.o
39 obj-$(CONFIG_IMX_HAVE_PLATFORM_SDHCI_ESDHC_IMX) += platform-sdhci-esdhc-imx.o
40 obj-$(CONFIG_IMX_HAVE_PLATFORM_SPI_IMX) += platform-spi_imx.o
41 obj-$(CONFIG_IMX_HAVE_PLATFORM_MX2_EMMA) += platform-mx2-emma.o
42 +obj-$(CONFIG_WAND_RFKILL) += wand-rfkill.o
43 diff --git a/arch/arm/mach-imx/devices/wand-rfkill.c b/arch/arm/mach-imx/devices/wand-rfkill.c
45 index 0000000..da7ef9f
47 +++ b/arch/arm/mach-imx/devices/wand-rfkill.c
50 + * arch/arm/mach-imx/devices/wand-rfkill.c
52 + * Copyright (C) 2013 Vladimir Ermakov <vooon341@gmail.com>
54 + * based on net/rfkill/rfkill-gpio.c
56 + * This software is licensed under the terms of the GNU General Public
57 + * License version 2, as published by the Free Software Foundation, and
58 + * may be copied, distributed, and modified under those terms.
60 + * This program is distributed in the hope that it will be useful,
61 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
62 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
63 + * GNU General Public License for more details.
67 +#include <linux/of.h>
68 +#include <linux/of_gpio.h>
69 +#include <linux/of_device.h>
70 +#include <linux/pinctrl/consumer.h>
71 +#include <linux/platform_device.h>
72 +#include <linux/rfkill.h>
73 +#include <linux/delay.h>
74 +#include <linux/kernel.h>
75 +#include <linux/module.h>
76 +#include <linux/slab.h>
79 +struct wand_rfkill_data {
80 + struct rfkill *rfkill_dev;
82 + const char *shutdown_name;
85 +static int wand_rfkill_set_block(void *data, bool blocked)
87 + struct wand_rfkill_data *rfkill = data;
89 + pr_debug("wandboard-rfkill: set block %d\n", blocked);
92 + if (gpio_is_valid(rfkill->shutdown_gpio))
93 + gpio_direction_output(rfkill->shutdown_gpio, 0);
95 + if (gpio_is_valid(rfkill->shutdown_gpio))
96 + gpio_direction_output(rfkill->shutdown_gpio, 1);
102 +static const struct rfkill_ops wand_rfkill_ops = {
103 + .set_block = wand_rfkill_set_block,
106 +static int wand_rfkill_wifi_probe(struct device *dev,
107 + struct device_node *np,
108 + struct wand_rfkill_data *rfkill)
111 + int wl_ref_on, wl_rst_n, wl_reg_on, wl_wake, wl_host_wake;
113 + wl_ref_on = of_get_named_gpio(np, "wifi-ref-on", 0);
114 + wl_rst_n = of_get_named_gpio(np, "wifi-rst-n", 0);
115 + wl_reg_on = of_get_named_gpio(np, "wifi-reg-on", 0);
116 + wl_wake = of_get_named_gpio(np, "wifi-wake", 0);
117 + wl_host_wake = of_get_named_gpio(np, "wifi-host-wake", 0);
119 + if (!gpio_is_valid(wl_rst_n) || !gpio_is_valid(wl_ref_on) ||
120 + !gpio_is_valid(wl_reg_on) || !gpio_is_valid(wl_wake) ||
121 + !gpio_is_valid(wl_host_wake)) {
123 + dev_err(dev, "incorrect wifi gpios (%d %d %d %d %d)\n",
124 + wl_rst_n, wl_ref_on, wl_reg_on, wl_wake, wl_host_wake);
128 + dev_info(dev, "initialize wifi chip\n");
130 + gpio_request(wl_rst_n, "wl_rst_n");
131 + gpio_direction_output(wl_rst_n, 0);
133 + gpio_set_value(wl_rst_n, 1);
135 + gpio_request(wl_ref_on, "wl_ref_on");
136 + gpio_direction_output(wl_ref_on, 1);
138 + gpio_request(wl_reg_on, "wl_reg_on");
139 + gpio_direction_output(wl_reg_on, 1);
141 + gpio_request(wl_wake, "wl_wake");
142 + gpio_direction_output(wl_wake, 1);
144 + gpio_request(wl_host_wake, "wl_host_wake");
145 + gpio_direction_input(wl_host_wake);
147 + rfkill->shutdown_name = "wifi_shutdown";
148 + rfkill->shutdown_gpio = wl_wake;
150 + rfkill->rfkill_dev = rfkill_alloc("wifi-rfkill", dev, RFKILL_TYPE_WLAN,
151 + &wand_rfkill_ops, rfkill);
152 + if (!rfkill->rfkill_dev) {
154 + goto wifi_fail_free_gpio;
157 + ret = rfkill_register(rfkill->rfkill_dev);
159 + goto wifi_fail_unregister;
161 + dev_info(dev, "wifi-rfkill registered.\n");
165 +wifi_fail_unregister:
166 + rfkill_destroy(rfkill->rfkill_dev);
167 +wifi_fail_free_gpio:
168 + if (gpio_is_valid(wl_rst_n)) gpio_free(wl_rst_n);
169 + if (gpio_is_valid(wl_ref_on)) gpio_free(wl_ref_on);
170 + if (gpio_is_valid(wl_reg_on)) gpio_free(wl_reg_on);
171 + if (gpio_is_valid(wl_wake)) gpio_free(wl_wake);
172 + if (gpio_is_valid(wl_host_wake)) gpio_free(wl_host_wake);
177 +static int wand_rfkill_bt_probe(struct device *dev,
178 + struct device_node *np,
179 + struct wand_rfkill_data *rfkill)
182 + int bt_on, bt_wake, bt_host_wake;
184 + bt_on = of_get_named_gpio(np, "bluetooth-on", 0);
185 + bt_wake = of_get_named_gpio(np, "bluetooth-wake", 0);
186 + bt_host_wake = of_get_named_gpio(np, "bluetooth-host-wake", 0);
188 + if (!gpio_is_valid(bt_on) || !gpio_is_valid(bt_wake) ||
189 + !gpio_is_valid(bt_host_wake)) {
191 + dev_err(dev, "incorrect bt gpios (%d %d %d)\n",
192 + bt_on, bt_wake, bt_host_wake);
196 + dev_info(dev, "initialize bluetooth chip\n");
198 + gpio_request(bt_on, "bt_on");
199 + gpio_direction_output(bt_on, 0);
201 + gpio_set_value(bt_on, 1);
203 + gpio_request(bt_wake, "bt_wake");
204 + gpio_direction_output(bt_wake, 1);
206 + gpio_request(bt_host_wake, "bt_host_wake");
207 + gpio_direction_input(bt_host_wake);
209 + rfkill->shutdown_name = "bluetooth_shutdown";
210 + rfkill->shutdown_gpio = bt_wake;
212 + rfkill->rfkill_dev = rfkill_alloc("bluetooth-rfkill", dev, RFKILL_TYPE_BLUETOOTH,
213 + &wand_rfkill_ops, rfkill);
214 + if (!rfkill->rfkill_dev) {
216 + goto bt_fail_free_gpio;
219 + ret = rfkill_register(rfkill->rfkill_dev);
221 + goto bt_fail_unregister;
223 + dev_info(dev, "bluetooth-rfkill registered.\n");
228 + rfkill_destroy(rfkill->rfkill_dev);
230 + if (gpio_is_valid(bt_on)) gpio_free(bt_on);
231 + if (gpio_is_valid(bt_wake)) gpio_free(bt_wake);
232 + if (gpio_is_valid(bt_host_wake)) gpio_free(bt_host_wake);
237 +static int wand_rfkill_probe(struct platform_device *pdev)
239 + struct wand_rfkill_data *rfkill;
240 + struct pinctrl *pinctrl;
243 + dev_info(&pdev->dev, "Wandboard rfkill initialization\n");
245 + if (!pdev->dev.of_node) {
246 + dev_err(&pdev->dev, "no device tree node\n");
250 + rfkill = kzalloc(sizeof(*rfkill) * 2, GFP_KERNEL);
254 + pinctrl = devm_pinctrl_get_select_default(&pdev->dev);
255 + if (IS_ERR(pinctrl)) {
256 + int ret = PTR_ERR(pinctrl);
257 + dev_err(&pdev->dev, "failed to get default pinctrl: %d\n", ret);
262 + ret = wand_rfkill_wifi_probe(&pdev->dev, pdev->dev.of_node, &rfkill[0]);
264 + goto fail_free_rfkill;
266 + /* setup bluetooth */
267 + ret = wand_rfkill_bt_probe(&pdev->dev, pdev->dev.of_node, &rfkill[1]);
269 + goto fail_unregister_wifi;
271 + platform_set_drvdata(pdev, rfkill);
275 +fail_unregister_wifi:
276 + if (rfkill[1].rfkill_dev) {
277 + rfkill_unregister(rfkill[1].rfkill_dev);
278 + rfkill_destroy(rfkill[1].rfkill_dev);
281 + /* TODO free gpio */
289 +static int wand_rfkill_remove(struct platform_device *pdev)
291 + struct wand_rfkill_data *rfkill = platform_get_drvdata(pdev);
293 + dev_info(&pdev->dev, "Module unloading\n");
299 + if (gpio_is_valid(rfkill[0].shutdown_gpio))
300 + gpio_free(rfkill[0].shutdown_gpio);
302 + rfkill_unregister(rfkill[0].rfkill_dev);
303 + rfkill_destroy(rfkill[0].rfkill_dev);
306 + if (gpio_is_valid(rfkill[1].shutdown_gpio))
307 + gpio_free(rfkill[1].shutdown_gpio);
309 + rfkill_unregister(rfkill[1].rfkill_dev);
310 + rfkill_destroy(rfkill[1].rfkill_dev);
317 +static struct of_device_id wand_rfkill_match[] = {
318 + { .compatible = "wand,imx6q-wandboard-rfkill", },
319 + { .compatible = "wand,imx6dl-wandboard-rfkill", },
320 + { .compatible = "wand,imx6qdl-wandboard-rfkill", },
324 +static struct platform_driver wand_rfkill_driver = {
326 + .name = "wandboard-rfkill",
327 + .owner = THIS_MODULE,
328 + .of_match_table = of_match_ptr(wand_rfkill_match),
330 + .probe = wand_rfkill_probe,
331 + .remove = wand_rfkill_remove
334 +module_platform_driver(wand_rfkill_driver);
336 +MODULE_AUTHOR("Vladimir Ermakov <vooon341@gmail.com>");
337 +MODULE_DESCRIPTION("Wandboard rfkill driver");
338 +MODULE_LICENSE("GPL v2");