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_set_block(void *data, bool blocked)
40 pr_info("BT_RADIO going: %s\n", blocked ? "off" : "on");
43 pr_info("TOSA_BT: going ON\n");
46 pr_info("TOSA_BT: going OFF\n");
53 static const struct rfkill_ops tosa_bt_rfkill_ops = {
54 .set_block = tosa_bt_set_block,
57 static int tosa_bt_probe(struct platform_device *dev)
62 struct tosa_bt_data *data = dev->dev.platform_data;
64 rc = gpio_request(data->gpio_reset, "Bluetooth reset");
67 rc = gpio_direction_output(data->gpio_reset, 0);
70 rc = gpio_request(data->gpio_pwr, "Bluetooth power");
73 rc = gpio_direction_output(data->gpio_pwr, 0);
77 rfk = rfkill_alloc("tosa-bt", &dev->dev, RFKILL_TYPE_BLUETOOTH,
78 &tosa_bt_rfkill_ops, data);
84 rc = rfkill_register(rfk);
88 platform_set_drvdata(dev, rfk);
97 gpio_free(data->gpio_pwr);
100 gpio_free(data->gpio_reset);
105 static int __devexit tosa_bt_remove(struct platform_device *dev)
107 struct tosa_bt_data *data = dev->dev.platform_data;
108 struct rfkill *rfk = platform_get_drvdata(dev);
110 platform_set_drvdata(dev, NULL);
113 rfkill_unregister(rfk);
120 gpio_free(data->gpio_pwr);
121 gpio_free(data->gpio_reset);
126 static struct platform_driver tosa_bt_driver = {
127 .probe = tosa_bt_probe,
128 .remove = __devexit_p(tosa_bt_remove),
132 .owner = THIS_MODULE,
137 static int __init tosa_bt_init(void)
139 return platform_driver_register(&tosa_bt_driver);
142 static void __exit tosa_bt_exit(void)
144 platform_driver_unregister(&tosa_bt_driver);
147 module_init(tosa_bt_init);
148 module_exit(tosa_bt_exit);