1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
|
/*
* Bluetooth TI wl127x rfkill power control via GPIO
*
* Copyright (C) 2009 Motorola, Inc.
* Copyright (C) 2008 Texas Instruments
* Initial code: Pavan Savoy <pavan.savoy@gmail.com> (wl127x_power.c)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include <linux/module.h>
#include <linux/init.h>
#include <linux/gpio.h>
#include <linux/rfkill.h>
#include <linux/platform_device.h>
#include <linux/wl127x-rfkill.h>
#include <linux/delay.h>
static int wl127x_bt_rfkill_set_power(void *data, bool blocked)
{
struct wl127x_rfkill_platform_data *pdata =
(struct wl127x_rfkill_platform_data *) data;
int nshutdown_gpio = pdata->bt_nshutdown_gpio;
if (blocked) {
gpio_set_value(nshutdown_gpio, 0);
if (pdata->bt_hw_disable)
pdata->bt_hw_disable();
} else {
if (pdata->bt_hw_enable)
pdata->bt_hw_enable();
gpio_set_value(nshutdown_gpio, 1);
}
return 0;
}
static int wl127x_fm_rfkill_set_power(void *data, bool blocked)
{
int nshutdown_gpio = (int) data;
if (blocked)
gpio_set_value(nshutdown_gpio, 0);
else
gpio_set_value(nshutdown_gpio, 1);
return 0;
}
static const struct rfkill_ops wl127x_bt_rfkill_ops = {
.set_block = wl127x_bt_rfkill_set_power,
};
static const struct rfkill_ops wl127x_fm_rfkill_ops = {
.set_block = wl127x_fm_rfkill_set_power,
};
/**
Added to reset the BT chip after Ram download
*/
static ssize_t reset_wl18xx_chip(struct device *dev,
struct device_attribute
*attr, const char *buf, size_t size)
{
int bt_enable_gpio;
printk(KERN_DEBUG "Calling reset_wl18xx_chip \n");
/* TODO, rework once device tree is pulled in */
/* bt_enable_gpio = get_gpio_by_name("bt_reset_b"); */
bt_enable_gpio = 83;
printk(KERN_DEBUG "bt_enable_gpio = %d\n", bt_enable_gpio);
if (bt_enable_gpio < 0) {
printk(KERN_DEBUG "reset_wl18xx_chip: cannot retrieve bt_reset_b gpio from device tree\n");
bt_enable_gpio = -1;
return -EINVAL;
}
gpio_set_value(bt_enable_gpio, 0);
msleep(5);
gpio_set_value(bt_enable_gpio, 1);
printk(KERN_DEBUG " successfully set the value\n");
return 0;
}
static DEVICE_ATTR(reset_vio, 0644, NULL, reset_wl18xx_chip);
static int wl127x_rfkill_probe(struct platform_device *pdev)
{
int rc = 0;
bool fm_deinit_required_flag = false;
struct wl127x_rfkill_platform_data *pdata = pdev->dev.platform_data;
if (pdata->bt_nshutdown_gpio >= 0) {
bool default_blocked = true; /* power off */
printk(KERN_DEBUG "Entered the bt enable part \n");
rc = gpio_request(pdata->bt_nshutdown_gpio,
"wl127x_bt_nshutdown_gpio");
if (unlikely(rc))
return rc;
rc = gpio_direction_output(pdata->bt_nshutdown_gpio, 0);
if (unlikely(rc)) {
printk(KERN_ERR "wl127x_rfkill_probe failure could not set output direction for gpio bt_nshutdown_gpio \n");
goto bt_err_gpio_direction;
}
if (pdata->bt_hw_init)
rc = pdata->bt_hw_init();
if (unlikely(rc)) {
printk(KERN_ERR "wl127x_rfkill_probe failure could not init hardware \n");
goto bt_err_gpio_direction;
}
wl127x_bt_rfkill_set_power((void *)pdata, default_blocked);
pdata->rfkill[WL127X_BLUETOOTH] = rfkill_alloc(
"wl127x Bluetooth", &pdev->dev,
RFKILL_TYPE_BLUETOOTH, &wl127x_bt_rfkill_ops,
(void *)pdata);
if (unlikely(!pdata->rfkill[WL127X_BLUETOOTH])) {
printk(KERN_ERR "wl127x_rfkill_probe failure could not allocate memory \n");
rc = -ENOMEM;
goto bt_err_rfkill_alloc;
}
rfkill_set_states(pdata->rfkill[WL127X_BLUETOOTH],
default_blocked, false);
rc = rfkill_register(pdata->rfkill[WL127X_BLUETOOTH]);
if (unlikely(rc)) {
printk(KERN_ERR "wl127x_rfkill_probe failure could to register BT \n");
goto bt_err_rfkill_register;
}
}
if (pdata->fm_enable_gpio >= 0) {
bool default_blocked = true; /* power off */
printk(KERN_DEBUG "Entered the fm enable part \n");
rc = gpio_request(pdata->fm_enable_gpio,
"wl127x_fm_enable_gpio");
if (unlikely(rc))
return rc;
rc = gpio_direction_output(pdata->fm_enable_gpio, 0);
if (unlikely(rc)) {
printk(KERN_ERR "wl127x_rfkill_probe failure could not set output direction for gpio fm_enable_gpio \n");
goto fm_err_gpio_direction;
}
wl127x_fm_rfkill_set_power((void *)pdata->fm_enable_gpio,
default_blocked);
pdata->rfkill[WL127X_FM] = rfkill_alloc("wl127x FM Radio",
&pdev->dev, RFKILL_TYPE_FM,
&wl127x_fm_rfkill_ops,
(void *)pdata->fm_enable_gpio);
if (unlikely(!pdata->rfkill[WL127X_FM])) {
printk(KERN_ERR "wl127x_rfkill_probe failure could not allocate memory for fm\n");
rc = -ENOMEM;
goto fm_err_gpio_direction;
}
rfkill_set_states(pdata->rfkill[WL127X_FM], default_blocked,
false);
rc = rfkill_register(pdata->rfkill[WL127X_FM]);
if (unlikely(rc)) {
printk(KERN_ERR "wl127x_rfkill_probe failure could to register FM \n");
goto fm_err_rfkill_register;
}
fm_deinit_required_flag = true;
}
/* Create device file to expose interface to user space to
reset the vio of BT, this should be done independent of whether
BT/FM is initialised as both run on the same w18xx chip
*/
if (device_create_file(&pdev->dev, &dev_attr_reset_vio)) {
printk(KERN_DEBUG "Error creating sys entry for reset vio\n");
rc = -1;
goto bt_err_rfkill_register;
}
goto done;
/* Clean up for BT generic registration */
bt_err_rfkill_register:
rfkill_destroy(pdata->rfkill[WL127X_BLUETOOTH]);
bt_err_rfkill_alloc:
if (pdata->bt_hw_release)
pdata->bt_hw_release();
bt_err_gpio_direction:
if (pdata->bt_nshutdown_gpio >= 0)
gpio_free(pdata->bt_nshutdown_gpio);
if (fm_deinit_required_flag == false)
goto done;
fm_deinit_required_flag = false;
/* Clean up for FM generic registration
do not clean up BT process as we still want to use BT
*/
fm_err_rfkill_register:
rfkill_destroy(pdata->rfkill[WL127X_FM]);
fm_err_gpio_direction:
gpio_free(pdata->fm_enable_gpio);
done:
return rc;
}
static int wl127x_rfkill_remove(struct platform_device *pdev)
{
struct wl127x_rfkill_platform_data *pdata = pdev->dev.platform_data;
if (pdata->bt_nshutdown_gpio >= 0) {
rfkill_unregister(pdata->rfkill[WL127X_BLUETOOTH]);
rfkill_destroy(pdata->rfkill[WL127X_BLUETOOTH]);
if (pdata->bt_hw_release)
pdata->bt_hw_release();
gpio_free(pdata->bt_nshutdown_gpio);
}
if (pdata->fm_enable_gpio >= 0) {
rfkill_unregister(pdata->rfkill[WL127X_FM]);
rfkill_destroy(pdata->rfkill[WL127X_FM]);
gpio_free(pdata->fm_enable_gpio);
}
/* remove the sys fs file created as part of probe*/
device_remove_file(&pdev->dev, &dev_attr_reset_vio);
return 0;
}
static struct platform_driver wl127x_rfkill_platform_driver = {
.probe = wl127x_rfkill_probe,
.remove = wl127x_rfkill_remove,
.driver = {
.name = "wl127x-rfkill",
.owner = THIS_MODULE,
},
};
static int __init wl127x_rfkill_init(void)
{
return platform_driver_register(&wl127x_rfkill_platform_driver);
}
static void __exit wl127x_rfkill_exit(void)
{
platform_driver_unregister(&wl127x_rfkill_platform_driver);
}
module_init(wl127x_rfkill_init);
module_exit(wl127x_rfkill_exit);
MODULE_ALIAS("platform:wl127x");
MODULE_DESCRIPTION("wl127x-rfkill");
MODULE_AUTHOR("Motorola");
MODULE_LICENSE("GPL");
|