1 // SPDX-License-Identifier: GPL-2.0-only
3 * Bluetooth built-in chip control
5 * Copyright (c) 2008 Dmitry Baryshkov
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>
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);
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);
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");
39 pr_info("TOSA_BT: going ON\n");
42 pr_info("TOSA_BT: going OFF\n");
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
)
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_alloc("tosa-bt", &dev
->dev
, RFKILL_TYPE_BLUETOOTH
,
74 &tosa_bt_rfkill_ops
, data
);
80 rc
= rfkill_register(rfk
);
84 platform_set_drvdata(dev
, rfk
);
93 gpio_free(data
->gpio_pwr
);
96 gpio_free(data
->gpio_reset
);
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
);
109 rfkill_unregister(rfk
);
116 gpio_free(data
->gpio_pwr
);
117 gpio_free(data
->gpio_reset
);
122 static struct platform_driver tosa_bt_driver
= {
123 .probe
= tosa_bt_probe
,
124 .remove
= tosa_bt_remove
,
130 module_platform_driver(tosa_bt_driver
);
132 MODULE_LICENSE("GPL");
133 MODULE_AUTHOR("Dmitry Baryshkov");
134 MODULE_DESCRIPTION("Bluetooth built-in chip control");