Merge tag 'usb-5.11-rc3' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb
[linux/fpc-iii.git] / arch / arm / mach-pxa / tosa-bt.c
blobc9541632b8b1dff533bd5ed7470cffaa289bf1aa
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * Bluetooth built-in chip control
5 * Copyright (c) 2008 Dmitry Baryshkov
6 */
8 #include <linux/kernel.h>
9 #include <linux/module.h>
10 #include <linux/platform_device.h>
11 #include <linux/gpio.h>
12 #include <linux/delay.h>
13 #include <linux/rfkill.h>
15 #include "tosa_bt.h"
17 static void tosa_bt_on(struct tosa_bt_data *data)
19 gpio_set_value(data->gpio_reset, 0);
20 gpio_set_value(data->gpio_pwr, 1);
21 gpio_set_value(data->gpio_reset, 1);
22 mdelay(20);
23 gpio_set_value(data->gpio_reset, 0);
26 static void tosa_bt_off(struct tosa_bt_data *data)
28 gpio_set_value(data->gpio_reset, 1);
29 mdelay(10);
30 gpio_set_value(data->gpio_pwr, 0);
31 gpio_set_value(data->gpio_reset, 0);
34 static int tosa_bt_set_block(void *data, bool blocked)
36 pr_info("BT_RADIO going: %s\n", blocked ? "off" : "on");
38 if (!blocked) {
39 pr_info("TOSA_BT: going ON\n");
40 tosa_bt_on(data);
41 } else {
42 pr_info("TOSA_BT: going OFF\n");
43 tosa_bt_off(data);
46 return 0;
49 static const struct rfkill_ops tosa_bt_rfkill_ops = {
50 .set_block = tosa_bt_set_block,
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_alloc("tosa-bt", &dev->dev, RFKILL_TYPE_BLUETOOTH,
74 &tosa_bt_rfkill_ops, data);
75 if (!rfk) {
76 rc = -ENOMEM;
77 goto err_rfk_alloc;
80 rc = rfkill_register(rfk);
81 if (rc)
82 goto err_rfkill;
84 platform_set_drvdata(dev, rfk);
86 return 0;
88 err_rfkill:
89 rfkill_destroy(rfk);
90 err_rfk_alloc:
91 tosa_bt_off(data);
92 err_pwr_dir:
93 gpio_free(data->gpio_pwr);
94 err_pwr:
95 err_reset_dir:
96 gpio_free(data->gpio_reset);
97 err_reset:
98 return rc;
101 static int tosa_bt_remove(struct platform_device *dev)
103 struct tosa_bt_data *data = dev->dev.platform_data;
104 struct rfkill *rfk = platform_get_drvdata(dev);
106 platform_set_drvdata(dev, NULL);
108 if (rfk) {
109 rfkill_unregister(rfk);
110 rfkill_destroy(rfk);
112 rfk = NULL;
114 tosa_bt_off(data);
116 gpio_free(data->gpio_pwr);
117 gpio_free(data->gpio_reset);
119 return 0;
122 static struct platform_driver tosa_bt_driver = {
123 .probe = tosa_bt_probe,
124 .remove = tosa_bt_remove,
126 .driver = {
127 .name = "tosa-bt",
130 module_platform_driver(tosa_bt_driver);
132 MODULE_LICENSE("GPL");
133 MODULE_AUTHOR("Dmitry Baryshkov");
134 MODULE_DESCRIPTION("Bluetooth built-in chip control");