blob: 107f37210fb9de3de9bf37e6618f979195e5bce9 [file] [log] [blame]
Dmitry Baryshkov16b32fd2008-07-05 09:02:48 +01001/*
2 * Bluetooth built-in chip control
3 *
4 * Copyright (c) 2008 Dmitry Baryshkov
5 *
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.
9 *
10 */
11
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>
18
Arnd Bergmann4c25c5d2015-01-30 10:45:33 +010019#include "tosa_bt.h"
Dmitry Baryshkov16b32fd2008-07-05 09:02:48 +010020
21static void tosa_bt_on(struct tosa_bt_data *data)
22{
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);
28}
29
30static void tosa_bt_off(struct tosa_bt_data *data)
31{
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);
36}
37
Johannes Berg19d337d2009-06-02 13:01:37 +020038static int tosa_bt_set_block(void *data, bool blocked)
Dmitry Baryshkov16b32fd2008-07-05 09:02:48 +010039{
Johannes Berg19d337d2009-06-02 13:01:37 +020040 pr_info("BT_RADIO going: %s\n", blocked ? "off" : "on");
Dmitry Baryshkov16b32fd2008-07-05 09:02:48 +010041
Johannes Berg19d337d2009-06-02 13:01:37 +020042 if (!blocked) {
Dmitry Baryshkov16b32fd2008-07-05 09:02:48 +010043 pr_info("TOSA_BT: going ON\n");
44 tosa_bt_on(data);
45 } else {
46 pr_info("TOSA_BT: going OFF\n");
47 tosa_bt_off(data);
48 }
Johannes Berg19d337d2009-06-02 13:01:37 +020049
Dmitry Baryshkov16b32fd2008-07-05 09:02:48 +010050 return 0;
51}
52
Johannes Berg19d337d2009-06-02 13:01:37 +020053static const struct rfkill_ops tosa_bt_rfkill_ops = {
54 .set_block = tosa_bt_set_block,
55};
56
Dmitry Baryshkov16b32fd2008-07-05 09:02:48 +010057static int tosa_bt_probe(struct platform_device *dev)
58{
59 int rc;
60 struct rfkill *rfk;
61
62 struct tosa_bt_data *data = dev->dev.platform_data;
63
64 rc = gpio_request(data->gpio_reset, "Bluetooth reset");
65 if (rc)
66 goto err_reset;
67 rc = gpio_direction_output(data->gpio_reset, 0);
68 if (rc)
69 goto err_reset_dir;
70 rc = gpio_request(data->gpio_pwr, "Bluetooth power");
71 if (rc)
72 goto err_pwr;
73 rc = gpio_direction_output(data->gpio_pwr, 0);
74 if (rc)
75 goto err_pwr_dir;
76
Johannes Berg19d337d2009-06-02 13:01:37 +020077 rfk = rfkill_alloc("tosa-bt", &dev->dev, RFKILL_TYPE_BLUETOOTH,
78 &tosa_bt_rfkill_ops, data);
Dmitry Baryshkov16b32fd2008-07-05 09:02:48 +010079 if (!rfk) {
80 rc = -ENOMEM;
81 goto err_rfk_alloc;
82 }
83
Dmitry Baryshkov16b32fd2008-07-05 09:02:48 +010084 rc = rfkill_register(rfk);
85 if (rc)
86 goto err_rfkill;
87
88 platform_set_drvdata(dev, rfk);
89
90 return 0;
91
92err_rfkill:
Johannes Berg19d337d2009-06-02 13:01:37 +020093 rfkill_destroy(rfk);
Dmitry Baryshkov16b32fd2008-07-05 09:02:48 +010094err_rfk_alloc:
95 tosa_bt_off(data);
96err_pwr_dir:
97 gpio_free(data->gpio_pwr);
98err_pwr:
99err_reset_dir:
100 gpio_free(data->gpio_reset);
101err_reset:
102 return rc;
103}
104
Greg Kroah-Hartman351a1022012-12-21 14:02:24 -0800105static int tosa_bt_remove(struct platform_device *dev)
Dmitry Baryshkov16b32fd2008-07-05 09:02:48 +0100106{
107 struct tosa_bt_data *data = dev->dev.platform_data;
108 struct rfkill *rfk = platform_get_drvdata(dev);
109
110 platform_set_drvdata(dev, NULL);
111
Johannes Berg19d337d2009-06-02 13:01:37 +0200112 if (rfk) {
Dmitry Baryshkov16b32fd2008-07-05 09:02:48 +0100113 rfkill_unregister(rfk);
Johannes Berg19d337d2009-06-02 13:01:37 +0200114 rfkill_destroy(rfk);
115 }
Dmitry Baryshkov16b32fd2008-07-05 09:02:48 +0100116 rfk = NULL;
117
118 tosa_bt_off(data);
119
120 gpio_free(data->gpio_pwr);
121 gpio_free(data->gpio_reset);
122
123 return 0;
124}
125
126static struct platform_driver tosa_bt_driver = {
127 .probe = tosa_bt_probe,
Greg Kroah-Hartman351a1022012-12-21 14:02:24 -0800128 .remove = tosa_bt_remove,
Dmitry Baryshkov16b32fd2008-07-05 09:02:48 +0100129
130 .driver = {
131 .name = "tosa-bt",
Dmitry Baryshkov16b32fd2008-07-05 09:02:48 +0100132 },
133};
Vaishali Thakkar9754c8e2015-07-03 17:40:45 +0530134module_platform_driver(tosa_bt_driver);