This source file includes following definitions.
- ti_st_tx_complete
- st_reg_completion_cb
- st_receive
- ti_st_open
- ti_st_close
- ti_st_send_frame
- bt_ti_probe
- bt_ti_remove
1
2
3
4
5
6
7
8
9
10
11
12
13 #include <linux/platform_device.h>
14 #include <net/bluetooth/bluetooth.h>
15 #include <net/bluetooth/hci_core.h>
16 #include <net/bluetooth/hci.h>
17
18 #include <linux/ti_wilink_st.h>
19 #include <linux/module.h>
20
21
22 #define VERSION "1.0"
23 #define MAX_BT_CHNL_IDS 3
24
25
26
27
28 #define BT_REGISTER_TIMEOUT 6000
29
30
31
32
33
34
35
36
37
38
39 struct ti_st {
40 struct hci_dev *hdev;
41 int reg_status;
42 long (*st_write) (struct sk_buff *);
43 struct completion wait_reg_completion;
44 };
45
46
47 static inline void ti_st_tx_complete(struct ti_st *hst, int pkt_type)
48 {
49 struct hci_dev *hdev = hst->hdev;
50
51
52 switch (pkt_type) {
53 case HCI_COMMAND_PKT:
54 hdev->stat.cmd_tx++;
55 break;
56
57 case HCI_ACLDATA_PKT:
58 hdev->stat.acl_tx++;
59 break;
60
61 case HCI_SCODATA_PKT:
62 hdev->stat.sco_tx++;
63 break;
64 }
65 }
66
67
68
69
70
71
72
73 static void st_reg_completion_cb(void *priv_data, int data)
74 {
75 struct ti_st *lhst = priv_data;
76
77
78 lhst->reg_status = data;
79
80 complete(&lhst->wait_reg_completion);
81 }
82
83
84 static long st_receive(void *priv_data, struct sk_buff *skb)
85 {
86 struct ti_st *lhst = priv_data;
87 int err;
88
89 if (!skb)
90 return -EFAULT;
91
92 if (!lhst) {
93 kfree_skb(skb);
94 return -EFAULT;
95 }
96
97
98 err = hci_recv_frame(lhst->hdev, skb);
99 if (err < 0) {
100 BT_ERR("Unable to push skb to HCI core(%d)", err);
101 return err;
102 }
103
104 lhst->hdev->stat.byte_rx += skb->len;
105
106 return 0;
107 }
108
109
110
111 static struct st_proto_s ti_st_proto[MAX_BT_CHNL_IDS] = {
112 {
113 .chnl_id = HCI_EVENT_PKT,
114 .hdr_len = sizeof(struct hci_event_hdr),
115 .offset_len_in_hdr = offsetof(struct hci_event_hdr, plen),
116 .len_size = 1,
117 .reserve = 8,
118 },
119 {
120 .chnl_id = HCI_ACLDATA_PKT,
121 .hdr_len = sizeof(struct hci_acl_hdr),
122 .offset_len_in_hdr = offsetof(struct hci_acl_hdr, dlen),
123 .len_size = 2,
124 .reserve = 8,
125 },
126 {
127 .chnl_id = HCI_SCODATA_PKT,
128 .hdr_len = sizeof(struct hci_sco_hdr),
129 .offset_len_in_hdr = offsetof(struct hci_sco_hdr, dlen),
130 .len_size = 1,
131 .reserve = 8,
132 },
133 };
134
135
136 static int ti_st_open(struct hci_dev *hdev)
137 {
138 unsigned long timeleft;
139 struct ti_st *hst;
140 int err, i;
141
142 BT_DBG("%s %p", hdev->name, hdev);
143
144
145 hst = hci_get_drvdata(hdev);
146
147 for (i = 0; i < MAX_BT_CHNL_IDS; i++) {
148 ti_st_proto[i].priv_data = hst;
149 ti_st_proto[i].max_frame_size = HCI_MAX_FRAME_SIZE;
150 ti_st_proto[i].recv = st_receive;
151 ti_st_proto[i].reg_complete_cb = st_reg_completion_cb;
152
153
154 init_completion(&hst->wait_reg_completion);
155
156
157
158
159
160 hst->reg_status = -EINPROGRESS;
161
162 err = st_register(&ti_st_proto[i]);
163 if (!err)
164 goto done;
165
166 if (err != -EINPROGRESS) {
167 BT_ERR("st_register failed %d", err);
168 return err;
169 }
170
171
172
173
174 BT_DBG("waiting for registration "
175 "completion signal from ST");
176 timeleft = wait_for_completion_timeout
177 (&hst->wait_reg_completion,
178 msecs_to_jiffies(BT_REGISTER_TIMEOUT));
179 if (!timeleft) {
180 BT_ERR("Timeout(%d sec),didn't get reg "
181 "completion signal from ST",
182 BT_REGISTER_TIMEOUT / 1000);
183 return -ETIMEDOUT;
184 }
185
186
187
188
189 if (hst->reg_status != 0) {
190 BT_ERR("ST registration completed with invalid "
191 "status %d", hst->reg_status);
192 return -EAGAIN;
193 }
194
195 done:
196 hst->st_write = ti_st_proto[i].write;
197 if (!hst->st_write) {
198 BT_ERR("undefined ST write function");
199 for (i = 0; i < MAX_BT_CHNL_IDS; i++) {
200
201 err = st_unregister(&ti_st_proto[i]);
202 if (err)
203 BT_ERR("st_unregister() failed with "
204 "error %d", err);
205 hst->st_write = NULL;
206 }
207 return -EIO;
208 }
209 }
210 return 0;
211 }
212
213
214 static int ti_st_close(struct hci_dev *hdev)
215 {
216 int err, i;
217 struct ti_st *hst = hci_get_drvdata(hdev);
218
219 for (i = MAX_BT_CHNL_IDS-1; i >= 0; i--) {
220 err = st_unregister(&ti_st_proto[i]);
221 if (err)
222 BT_ERR("st_unregister(%d) failed with error %d",
223 ti_st_proto[i].chnl_id, err);
224 }
225
226 hst->st_write = NULL;
227
228 return err;
229 }
230
231 static int ti_st_send_frame(struct hci_dev *hdev, struct sk_buff *skb)
232 {
233 struct ti_st *hst;
234 long len;
235 int pkt_type;
236
237 hst = hci_get_drvdata(hdev);
238
239
240 memcpy(skb_push(skb, 1), &hci_skb_pkt_type(skb), 1);
241
242 BT_DBG("%s: type %d len %d", hdev->name, hci_skb_pkt_type(skb),
243 skb->len);
244
245
246
247
248
249 pkt_type = hci_skb_pkt_type(skb);
250 len = hst->st_write(skb);
251 if (len < 0) {
252 BT_ERR("ST write failed (%ld)", len);
253
254 return -EAGAIN;
255 }
256
257
258 hdev->stat.byte_tx += len;
259 ti_st_tx_complete(hst, pkt_type);
260
261 return 0;
262 }
263
264 static int bt_ti_probe(struct platform_device *pdev)
265 {
266 struct ti_st *hst;
267 struct hci_dev *hdev;
268 int err;
269
270 hst = devm_kzalloc(&pdev->dev, sizeof(struct ti_st), GFP_KERNEL);
271 if (!hst)
272 return -ENOMEM;
273
274
275 hdev = hci_alloc_dev();
276 if (!hdev)
277 return -ENOMEM;
278
279 BT_DBG("hdev %p", hdev);
280
281 hst->hdev = hdev;
282 hdev->bus = HCI_UART;
283 hci_set_drvdata(hdev, hst);
284 hdev->open = ti_st_open;
285 hdev->close = ti_st_close;
286 hdev->flush = NULL;
287 hdev->send = ti_st_send_frame;
288
289 err = hci_register_dev(hdev);
290 if (err < 0) {
291 BT_ERR("Can't register HCI device error %d", err);
292 hci_free_dev(hdev);
293 return err;
294 }
295
296 BT_DBG("HCI device registered (hdev %p)", hdev);
297
298 dev_set_drvdata(&pdev->dev, hst);
299 return 0;
300 }
301
302 static int bt_ti_remove(struct platform_device *pdev)
303 {
304 struct hci_dev *hdev;
305 struct ti_st *hst = dev_get_drvdata(&pdev->dev);
306
307 if (!hst)
308 return -EFAULT;
309
310 BT_DBG("%s", hst->hdev->name);
311
312 hdev = hst->hdev;
313 ti_st_close(hdev);
314 hci_unregister_dev(hdev);
315
316 hci_free_dev(hdev);
317
318 dev_set_drvdata(&pdev->dev, NULL);
319 return 0;
320 }
321
322 static struct platform_driver btwilink_driver = {
323 .probe = bt_ti_probe,
324 .remove = bt_ti_remove,
325 .driver = {
326 .name = "btwilink",
327 },
328 };
329
330 module_platform_driver(btwilink_driver);
331
332
333
334 MODULE_AUTHOR("Raja Mani <raja_mani@ti.com>");
335 MODULE_DESCRIPTION("Bluetooth Driver for TI Shared Transport" VERSION);
336 MODULE_VERSION(VERSION);
337 MODULE_LICENSE("GPL");