OMAP3: PM: Ensure MUSB block can idle when driver not loaded
[linux-ginger.git] / arch / arm / mach-pxa / tosa-bt.c
blobfb0294bd43107442d4a0f3f569f67caf4ba59c29
1 /*
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);
26 mdelay(20);
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);
33 mdelay(10);
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");
45 tosa_bt_on(data);
46 } else {
47 pr_info("TOSA_BT: going OFF\n");
48 tosa_bt_off(data);
50 return 0;
53 static int tosa_bt_probe(struct platform_device *dev)
55 int rc;
56 struct rfkill *rfk;
58 struct tosa_bt_data *data = dev->dev.platform_data;
60 rc = gpio_request(data->gpio_reset, "Bluetooth reset");
61 if (rc)
62 goto err_reset;
63 rc = gpio_direction_output(data->gpio_reset, 0);
64 if (rc)
65 goto err_reset_dir;
66 rc = gpio_request(data->gpio_pwr, "Bluetooth power");
67 if (rc)
68 goto err_pwr;
69 rc = gpio_direction_output(data->gpio_pwr, 0);
70 if (rc)
71 goto err_pwr_dir;
73 rfk = rfkill_allocate(&dev->dev, RFKILL_TYPE_BLUETOOTH);
74 if (!rfk) {
75 rc = -ENOMEM;
76 goto err_rfk_alloc;
79 rfk->name = "tosa-bt";
80 rfk->toggle_radio = tosa_bt_toggle_radio;
81 rfk->data = data;
82 #ifdef CONFIG_RFKILL_LEDS
83 rfk->led_trigger.name = "tosa-bt";
84 #endif
86 rc = rfkill_register(rfk);
87 if (rc)
88 goto err_rfkill;
90 platform_set_drvdata(dev, rfk);
92 return 0;
94 err_rfkill:
95 if (rfk)
96 rfkill_free(rfk);
97 rfk = NULL;
98 err_rfk_alloc:
99 tosa_bt_off(data);
100 err_pwr_dir:
101 gpio_free(data->gpio_pwr);
102 err_pwr:
103 err_reset_dir:
104 gpio_free(data->gpio_reset);
105 err_reset:
106 return rc;
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);
116 if (rfk)
117 rfkill_unregister(rfk);
118 rfk = NULL;
120 tosa_bt_off(data);
122 gpio_free(data->gpio_pwr);
123 gpio_free(data->gpio_reset);
125 return 0;
128 static struct platform_driver tosa_bt_driver = {
129 .probe = tosa_bt_probe,
130 .remove = __devexit_p(tosa_bt_remove),
132 .driver = {
133 .name = "tosa-bt",
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);