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
;
36 case RFKILL_STATE_UNBLOCKED
:
37 gpio_set_value(nshutdown_gpio
, 1);
39 case RFKILL_STATE_SOFT_BLOCKED
:
40 gpio_set_value(nshutdown_gpio
, 0);
43 printk(KERN_ERR
"invalid bluetooth rfkill state %d\n", state
);
48 static int wl127x_rfkill_probe(struct platform_device
*pdev
)
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");
58 rc
= gpio_direction_output(pdata
->nshutdown_gpio
, 0);
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
))
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
);
80 rfkill_free(pdata
->rfkill
);
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
);
96 static struct platform_driver wl127x_rfkill_platform_driver
= {
97 .probe
= wl127x_rfkill_probe
,
98 .remove
= wl127x_rfkill_remove
,
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");