ARM: cpu topology: Add debugfs interface for cpu_power
[cmplus.git] / drivers / misc / wl127x-rfkill.c
blobf5b95152948b2aae3a2bc04800b15a237535b083
1 /*
2 * Bluetooth TI wl127x rfkill power control via GPIO
4 * Copyright (C) 2009 Motorola, Inc.
5 * Copyright (C) 2008 Texas Instruments
6 * Initial code: Pavan Savoy <pavan.savoy@gmail.com> (wl127x_power.c)
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 #include <linux/module.h>
25 #include <linux/init.h>
26 #include <linux/gpio.h>
27 #include <linux/rfkill.h>
28 #include <linux/platform_device.h>
29 #include <linux/wl127x-rfkill.h>
31 static int wl127x_rfkill_set_power(void *data, enum rfkill_state state)
33 int nshutdown_gpio = (int) data;
35 switch (state) {
36 case RFKILL_STATE_UNBLOCKED:
37 gpio_set_value(nshutdown_gpio, 1);
38 break;
39 case RFKILL_STATE_SOFT_BLOCKED:
40 gpio_set_value(nshutdown_gpio, 0);
41 break;
42 default:
43 printk(KERN_ERR "invalid bluetooth rfkill state %d\n", state);
45 return 0;
48 static int wl127x_rfkill_probe(struct platform_device *pdev)
50 int rc = 0;
51 struct wl127x_rfkill_platform_data *pdata = pdev->dev.platform_data;
52 enum rfkill_state default_state = RFKILL_STATE_SOFT_BLOCKED; /* off */
54 rc = gpio_request(pdata->nshutdown_gpio, "wl127x_nshutdown_gpio");
55 if (unlikely(rc))
56 return rc;
58 rc = gpio_direction_output(pdata->nshutdown_gpio, 0);
59 if (unlikely(rc))
60 return rc;
62 rfkill_set_default(RFKILL_TYPE_BLUETOOTH, default_state);
63 wl127x_rfkill_set_power(NULL, default_state);
65 pdata->rfkill = rfkill_allocate(&pdev->dev, RFKILL_TYPE_BLUETOOTH);
66 if (unlikely(!pdata->rfkill))
67 return -ENOMEM;
69 pdata->rfkill->name = "wl127x";
70 pdata->rfkill->state = default_state;
71 /* userspace cannot take exclusive control */
72 pdata->rfkill->user_claim_unsupported = 1;
73 pdata->rfkill->user_claim = 0;
74 pdata->rfkill->data = (void *) pdata->nshutdown_gpio;
75 pdata->rfkill->toggle_radio = wl127x_rfkill_set_power;
77 rc = rfkill_register(pdata->rfkill);
79 if (unlikely(rc))
80 rfkill_free(pdata->rfkill);
82 return 0;
85 static int wl127x_rfkill_remove(struct platform_device *pdev)
87 struct wl127x_rfkill_platform_data *pdata = pdev->dev.platform_data;
89 rfkill_unregister(pdata->rfkill);
90 rfkill_free(pdata->rfkill);
91 gpio_free(pdata->nshutdown_gpio);
93 return 0;
96 static struct platform_driver wl127x_rfkill_platform_driver = {
97 .probe = wl127x_rfkill_probe,
98 .remove = wl127x_rfkill_remove,
99 .driver = {
100 .name = "wl127x-rfkill",
101 .owner = THIS_MODULE,
105 static int __init wl127x_rfkill_init(void)
107 return platform_driver_register(&wl127x_rfkill_platform_driver);
110 static void __exit wl127x_rfkill_exit(void)
112 platform_driver_unregister(&wl127x_rfkill_platform_driver);
115 module_init(wl127x_rfkill_init);
116 module_exit(wl127x_rfkill_exit);
118 MODULE_ALIAS("platform:wl127x");
119 MODULE_DESCRIPTION("wl127x-rfkill");
120 MODULE_AUTHOR("Motorola");
121 MODULE_LICENSE("GPL");