2 * Bluetooth built-in chip control
4 * Copyright (c) 2008 Dmitry Baryshkov
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
12 #include <linux/kernel.h>
13 #include <linux/module.h>
14 #include <linux/platform_device.h>
15 #include <linux/gpio.h>
16 #include <linux/delay.h>
17 #include <linux/rfkill.h>
19 #include <mach/tosa_bt.h>
21 static void tosa_bt_on(struct tosa_bt_data *data)
23 gpio_set_value(data->gpio_reset, 0);
24 gpio_set_value(data->gpio_pwr, 1);
25 gpio_set_value(data->gpio_reset, 1);
27 gpio_set_value(data->gpio_reset, 0);
30 static void tosa_bt_off(struct tosa_bt_data *data)
32 gpio_set_value(data->gpio_reset, 1);
34 gpio_set_value(data->gpio_pwr, 0);
35 gpio_set_value(data->gpio_reset, 0);
38 static int tosa_bt_toggle_radio(void *data, enum rfkill_state state)
40 pr_info("BT_RADIO going: %s\n",
41 state == RFKILL_STATE_ON ? "on" : "off");
43 if (state == RFKILL_STATE_ON) {
44 pr_info("TOSA_BT: going ON\n");
47 pr_info("TOSA_BT: going OFF\n");
53 static int tosa_bt_probe(struct platform_device *dev)
58 struct tosa_bt_data *data = dev->dev.platform_data;
60 rc = gpio_request(data->gpio_reset, "Bluetooth reset");
63 rc = gpio_direction_output(data->gpio_reset, 0);
66 rc = gpio_request(data->gpio_pwr, "Bluetooth power");
69 rc = gpio_direction_output(data->gpio_pwr, 0);
73 rfk = rfkill_allocate(&dev->dev, RFKILL_TYPE_BLUETOOTH);
79 rfk->name = "tosa-bt";
80 rfk->toggle_radio = tosa_bt_toggle_radio;
82 #ifdef CONFIG_RFKILL_LEDS
83 rfk->led_trigger.name = "tosa-bt";
86 rc = rfkill_register(rfk);
90 platform_set_drvdata(dev, rfk);
101 gpio_free(data->gpio_pwr);
104 gpio_free(data->gpio_reset);
109 static int __devexit tosa_bt_remove(struct platform_device *dev)
111 struct tosa_bt_data *data = dev->dev.platform_data;
112 struct rfkill *rfk = platform_get_drvdata(dev);
114 platform_set_drvdata(dev, NULL);
117 rfkill_unregister(rfk);
122 gpio_free(data->gpio_pwr);
123 gpio_free(data->gpio_reset);
128 static struct platform_driver tosa_bt_driver = {
129 .probe = tosa_bt_probe,
130 .remove = __devexit_p(tosa_bt_remove),
134 .owner = THIS_MODULE,
139 static int __init tosa_bt_init(void)
141 return platform_driver_register(&tosa_bt_driver);
144 static void __exit tosa_bt_exit(void)
146 platform_driver_unregister(&tosa_bt_driver);
149 module_init(tosa_bt_init);
150 module_exit(tosa_bt_exit);