aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/staging
diff options
context:
space:
mode:
authorPavan Savoy <pavan_savoy@ti.com>2010-10-06 12:18:14 -0400
committerGreg Kroah-Hartman <gregkh@suse.de>2010-10-06 11:25:06 -0400
commita0cc2f3b51a8649da5262aba7501dc21738e1b8d (patch)
tree01f5a8a5fa8ef079de806fc192a1a400348d17ea /drivers/staging
parentaecac19179180b7d6cda13f598e314c0870aee80 (diff)
staging: ti-st: move TI_ST from staging to misc/
move the 3 source files st_core.c, st_kim.c and st_ll.c from staging to drivers/misc/. Texas Instrument's WiLink 7 chipset packs wireless technologies like Bluetooth, FM, GPS and WLAN into a single die. Among these the Bluetooth, FM Rx/Tx and GPS are interfaced to a apps processor over a single UART. This line discipline driver allows various protocol drivers such as Bluetooth BlueZ driver, FM V4L2 driver and GPS simple character device driver to communicate with its relevant core in the chip. Each protocol or technologies use a logical channel to communicate with chip. Bluetooth uses the HCI-H4 [channels 1-4], FM uses a CH-8 and GPS a CH-9 protocol. The driver also constitutes the TI HCI-LL Power Management protocol which use channels 30-33. Signed-off-by: Pavan Savoy <pavan_savoy@ti.com> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/staging')
-rw-r--r--drivers/staging/ti-st/Kconfig11
-rw-r--r--drivers/staging/ti-st/Makefile2
-rw-r--r--drivers/staging/ti-st/st_core.c1030
-rw-r--r--drivers/staging/ti-st/st_kim.c797
-rw-r--r--drivers/staging/ti-st/st_ll.c149
5 files changed, 0 insertions, 1989 deletions
diff --git a/drivers/staging/ti-st/Kconfig b/drivers/staging/ti-st/Kconfig
index 858062dbed7..074b8e89e91 100644
--- a/drivers/staging/ti-st/Kconfig
+++ b/drivers/staging/ti-st/Kconfig
@@ -3,17 +3,6 @@
3# drivers (BT, FM and GPS) 3# drivers (BT, FM and GPS)
4# 4#
5menu "Texas Instruments shared transport line discipline" 5menu "Texas Instruments shared transport line discipline"
6config TI_ST
7 tristate "Shared transport core driver"
8 depends on RFKILL
9 select FW_LOADER
10 help
11 This enables the shared transport core driver for TI
12 BT / FM and GPS combo chips. This enables protocol drivers
13 to register themselves with core and send data, the responses
14 are returned to relevant protocol drivers based on their
15 packet types.
16
17config ST_BT 6config ST_BT
18 tristate "BlueZ bluetooth driver for ST" 7 tristate "BlueZ bluetooth driver for ST"
19 depends on BT && RFKILL 8 depends on BT && RFKILL
diff --git a/drivers/staging/ti-st/Makefile b/drivers/staging/ti-st/Makefile
index 0167d1d2c25..5f11b82c016 100644
--- a/drivers/staging/ti-st/Makefile
+++ b/drivers/staging/ti-st/Makefile
@@ -2,6 +2,4 @@
2# Makefile for TI's shared transport line discipline 2# Makefile for TI's shared transport line discipline
3# and its protocol drivers (BT, FM, GPS) 3# and its protocol drivers (BT, FM, GPS)
4# 4#
5obj-$(CONFIG_TI_ST) += st_drv.o
6st_drv-objs := st_core.o st_kim.o st_ll.o
7obj-$(CONFIG_ST_BT) += bt_drv.o 5obj-$(CONFIG_ST_BT) += bt_drv.o
diff --git a/drivers/staging/ti-st/st_core.c b/drivers/staging/ti-st/st_core.c
deleted file mode 100644
index 5bef61e579c..00000000000
--- a/drivers/staging/ti-st/st_core.c
+++ /dev/null
@@ -1,1030 +0,0 @@
1/*
2 * Shared Transport Line discipline driver Core
3 * This hooks up ST KIM driver and ST LL driver
4 * Copyright (C) 2009 Texas Instruments
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 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 *
19 */
20
21#define pr_fmt(fmt) "(stc): " fmt
22#include <linux/module.h>
23#include <linux/kernel.h>
24#include <linux/init.h>
25#include <linux/tty.h>
26
27/* understand BT, FM and GPS for now */
28#include <net/bluetooth/bluetooth.h>
29#include <net/bluetooth/hci_core.h>
30#include <net/bluetooth/hci.h>
31#include <linux/ti_wilink_st.h>
32
33/* strings to be used for rfkill entries and by
34 * ST Core to be used for sysfs debug entry
35 */
36#define PROTO_ENTRY(type, name) name
37const unsigned char *protocol_strngs[] = {
38 PROTO_ENTRY(ST_BT, "Bluetooth"),
39 PROTO_ENTRY(ST_FM, "FM"),
40 PROTO_ENTRY(ST_GPS, "GPS"),
41};
42/* function pointer pointing to either,
43 * st_kim_recv during registration to receive fw download responses
44 * st_int_recv after registration to receive proto stack responses
45 */
46void (*st_recv) (void*, const unsigned char*, long);
47
48/********************************************************************/
49#if 0
50/* internal misc functions */
51bool is_protocol_list_empty(void)
52{
53 unsigned char i = 0;
54 pr_debug(" %s ", __func__);
55 for (i = 0; i < ST_MAX; i++) {
56 if (st_gdata->list[i] != NULL)
57 return ST_NOTEMPTY;
58 /* not empty */
59 }
60 /* list empty */
61 return ST_EMPTY;
62}
63#endif
64
65/* can be called in from
66 * -- KIM (during fw download)
67 * -- ST Core (during st_write)
68 *
69 * This is the internal write function - a wrapper
70 * to tty->ops->write
71 */
72int st_int_write(struct st_data_s *st_gdata,
73 const unsigned char *data, int count)
74{
75 struct tty_struct *tty;
76 if (unlikely(st_gdata == NULL || st_gdata->tty == NULL)) {
77 pr_err("tty unavailable to perform write");
78 return -1;
79 }
80 tty = st_gdata->tty;
81#ifdef VERBOSE
82 print_hex_dump(KERN_DEBUG, "<out<", DUMP_PREFIX_NONE,
83 16, 1, data, count, 0);
84#endif
85 return tty->ops->write(tty, data, count);
86
87}
88
89/*
90 * push the skb received to relevant
91 * protocol stacks
92 */
93void st_send_frame(enum proto_type protoid, struct st_data_s *st_gdata)
94{
95 pr_info(" %s(prot:%d) ", __func__, protoid);
96
97 if (unlikely
98 (st_gdata == NULL || st_gdata->rx_skb == NULL
99 || st_gdata->list[protoid] == NULL)) {
100 pr_err("protocol %d not registered, no data to send?",
101 protoid);
102 kfree_skb(st_gdata->rx_skb);
103 return;
104 }
105 /* this cannot fail
106 * this shouldn't take long
107 * - should be just skb_queue_tail for the
108 * protocol stack driver
109 */
110 if (likely(st_gdata->list[protoid]->recv != NULL)) {
111 if (unlikely
112 (st_gdata->list[protoid]->recv
113 (st_gdata->list[protoid]->priv_data, st_gdata->rx_skb)
114 != 0)) {
115 pr_err(" proto stack %d's ->recv failed", protoid);
116 kfree_skb(st_gdata->rx_skb);
117 return;
118 }
119 } else {
120 pr_err(" proto stack %d's ->recv null", protoid);
121 kfree_skb(st_gdata->rx_skb);
122 }
123 return;
124}
125
126/**
127 * st_reg_complete -
128 * to call registration complete callbacks
129 * of all protocol stack drivers
130 */
131void st_reg_complete(struct st_data_s *st_gdata, char err)
132{
133 unsigned char i = 0;
134 pr_info(" %s ", __func__);
135 for (i = 0; i < ST_MAX; i++) {
136 if (likely(st_gdata != NULL && st_gdata->list[i] != NULL &&
137 st_gdata->list[i]->reg_complete_cb != NULL))
138 st_gdata->list[i]->reg_complete_cb
139 (st_gdata->list[i]->priv_data, err);
140 }
141}
142
143static inline int st_check_data_len(struct st_data_s *st_gdata,
144 int protoid, int len)
145{
146 register int room = skb_tailroom(st_gdata->rx_skb);
147
148 pr_debug("len %d room %d", len, room);
149
150 if (!len) {
151 /* Received packet has only packet header and
152 * has zero length payload. So, ask ST CORE to
153 * forward the packet to protocol driver (BT/FM/GPS)
154 */
155 st_send_frame(protoid, st_gdata);
156
157 } else if (len > room) {
158 /* Received packet's payload length is larger.
159 * We can't accommodate it in created skb.
160 */
161 pr_err("Data length is too large len %d room %d", len,
162 room);
163 kfree_skb(st_gdata->rx_skb);
164 } else {
165 /* Packet header has non-zero payload length and
166 * we have enough space in created skb. Lets read
167 * payload data */
168 st_gdata->rx_state = ST_BT_W4_DATA;
169 st_gdata->rx_count = len;
170 return len;
171 }
172
173 /* Change ST state to continue to process next
174 * packet */
175 st_gdata->rx_state = ST_W4_PACKET_TYPE;
176 st_gdata->rx_skb = NULL;
177 st_gdata->rx_count = 0;
178
179 return 0;
180}
181
182/**
183 * st_wakeup_ack - internal function for action when wake-up ack
184 * received
185 */
186static inline void st_wakeup_ack(struct st_data_s *st_gdata,
187 unsigned char cmd)
188{
189 register struct sk_buff *waiting_skb;
190 unsigned long flags = 0;
191
192 spin_lock_irqsave(&st_gdata->lock, flags);
193 /* de-Q from waitQ and Q in txQ now that the
194 * chip is awake
195 */
196 while ((waiting_skb = skb_dequeue(&st_gdata->tx_waitq)))
197 skb_queue_tail(&st_gdata->txq, waiting_skb);
198
199 /* state forwarded to ST LL */
200 st_ll_sleep_state(st_gdata, (unsigned long)cmd);
201 spin_unlock_irqrestore(&st_gdata->lock, flags);
202
203 /* wake up to send the recently copied skbs from waitQ */
204 st_tx_wakeup(st_gdata);
205}
206
207/**
208 * st_int_recv - ST's internal receive function.
209 * Decodes received RAW data and forwards to corresponding
210 * client drivers (Bluetooth,FM,GPS..etc).
211 * This can receive various types of packets,
212 * HCI-Events, ACL, SCO, 4 types of HCI-LL PM packets
213 * CH-8 packets from FM, CH-9 packets from GPS cores.
214 */
215void st_int_recv(void *disc_data,
216 const unsigned char *data, long count)
217{
218 register char *ptr;
219 struct hci_event_hdr *eh;
220 struct hci_acl_hdr *ah;
221 struct hci_sco_hdr *sh;
222 struct fm_event_hdr *fm;
223 struct gps_event_hdr *gps;
224 register int len = 0, type = 0, dlen = 0;
225 static enum proto_type protoid = ST_MAX;
226 struct st_data_s *st_gdata = (struct st_data_s *)disc_data;
227
228 ptr = (char *)data;
229 /* tty_receive sent null ? */
230 if (unlikely(ptr == NULL) || (st_gdata == NULL)) {
231 pr_err(" received null from TTY ");
232 return;
233 }
234
235 pr_info("count %ld rx_state %ld"
236 "rx_count %ld", count, st_gdata->rx_state,
237 st_gdata->rx_count);
238
239 /* Decode received bytes here */
240 while (count) {
241 if (st_gdata->rx_count) {
242 len = min_t(unsigned int, st_gdata->rx_count, count);
243 memcpy(skb_put(st_gdata->rx_skb, len), ptr, len);
244 st_gdata->rx_count -= len;
245 count -= len;
246 ptr += len;
247
248 if (st_gdata->rx_count)
249 continue;
250
251 /* Check ST RX state machine , where are we? */
252 switch (st_gdata->rx_state) {
253
254 /* Waiting for complete packet ? */
255 case ST_BT_W4_DATA:
256 pr_debug("Complete pkt received");
257
258 /* Ask ST CORE to forward
259 * the packet to protocol driver */
260 st_send_frame(protoid, st_gdata);
261
262 st_gdata->rx_state = ST_W4_PACKET_TYPE;
263 st_gdata->rx_skb = NULL;
264 protoid = ST_MAX; /* is this required ? */
265 continue;
266
267 /* Waiting for Bluetooth event header ? */
268 case ST_BT_W4_EVENT_HDR:
269 eh = (struct hci_event_hdr *)st_gdata->rx_skb->
270 data;
271
272 pr_debug("Event header: evt 0x%2.2x"
273 "plen %d", eh->evt, eh->plen);
274
275 st_check_data_len(st_gdata, protoid, eh->plen);
276 continue;
277
278 /* Waiting for Bluetooth acl header ? */
279 case ST_BT_W4_ACL_HDR:
280 ah = (struct hci_acl_hdr *)st_gdata->rx_skb->
281 data;
282 dlen = __le16_to_cpu(ah->dlen);
283
284 pr_info("ACL header: dlen %d", dlen);
285
286 st_check_data_len(st_gdata, protoid, dlen);
287 continue;
288
289 /* Waiting for Bluetooth sco header ? */
290 case ST_BT_W4_SCO_HDR:
291 sh = (struct hci_sco_hdr *)st_gdata->rx_skb->
292 data;
293
294 pr_info("SCO header: dlen %d", sh->dlen);
295
296 st_check_data_len(st_gdata, protoid, sh->dlen);
297 continue;
298 case ST_FM_W4_EVENT_HDR:
299 fm = (struct fm_event_hdr *)st_gdata->rx_skb->
300 data;
301 pr_info("FM Header: ");
302 st_check_data_len(st_gdata, ST_FM, fm->plen);
303 continue;
304 /* TODO : Add GPS packet machine logic here */
305 case ST_GPS_W4_EVENT_HDR:
306 /* [0x09 pkt hdr][R/W byte][2 byte len] */
307 gps = (struct gps_event_hdr *)st_gdata->rx_skb->
308 data;
309 pr_info("GPS Header: ");
310 st_check_data_len(st_gdata, ST_GPS, gps->plen);
311 continue;
312 } /* end of switch rx_state */
313 }
314
315 /* end of if rx_count */
316 /* Check first byte of packet and identify module
317 * owner (BT/FM/GPS) */
318 switch (*ptr) {
319
320 /* Bluetooth event packet? */
321 case HCI_EVENT_PKT:
322 pr_info("Event packet");
323 st_gdata->rx_state = ST_BT_W4_EVENT_HDR;
324 st_gdata->rx_count = HCI_EVENT_HDR_SIZE;
325 type = HCI_EVENT_PKT;
326 protoid = ST_BT;
327 break;
328
329 /* Bluetooth acl packet? */
330 case HCI_ACLDATA_PKT:
331 pr_info("ACL packet");
332 st_gdata->rx_state = ST_BT_W4_ACL_HDR;
333 st_gdata->rx_count = HCI_ACL_HDR_SIZE;
334 type = HCI_ACLDATA_PKT;
335 protoid = ST_BT;
336 break;
337
338 /* Bluetooth sco packet? */
339 case HCI_SCODATA_PKT:
340 pr_info("SCO packet");
341 st_gdata->rx_state = ST_BT_W4_SCO_HDR;
342 st_gdata->rx_count = HCI_SCO_HDR_SIZE;
343 type = HCI_SCODATA_PKT;
344 protoid = ST_BT;
345 break;
346
347 /* Channel 8(FM) packet? */
348 case ST_FM_CH8_PKT:
349 pr_info("FM CH8 packet");
350 type = ST_FM_CH8_PKT;
351 st_gdata->rx_state = ST_FM_W4_EVENT_HDR;
352 st_gdata->rx_count = FM_EVENT_HDR_SIZE;
353 protoid = ST_FM;
354 break;
355
356 /* Channel 9(GPS) packet? */
357 case 0x9: /*ST_LL_GPS_CH9_PKT */
358 pr_info("GPS CH9 packet");
359 type = 0x9; /* ST_LL_GPS_CH9_PKT; */
360 protoid = ST_GPS;
361 st_gdata->rx_state = ST_GPS_W4_EVENT_HDR;
362 st_gdata->rx_count = 3; /* GPS_EVENT_HDR_SIZE -1*/
363 break;
364 case LL_SLEEP_IND:
365 case LL_SLEEP_ACK:
366 case LL_WAKE_UP_IND:
367 pr_info("PM packet");
368 /* this takes appropriate action based on
369 * sleep state received --
370 */
371 st_ll_sleep_state(st_gdata, *ptr);
372 ptr++;
373 count--;
374 continue;
375 case LL_WAKE_UP_ACK:
376 pr_info("PM packet");
377 /* wake up ack received */
378 st_wakeup_ack(st_gdata, *ptr);
379 ptr++;
380 count--;
381 continue;
382 /* Unknow packet? */
383 default:
384 pr_err("Unknown packet type %2.2x", (__u8) *ptr);
385 ptr++;
386 count--;
387 continue;
388 };
389 ptr++;
390 count--;
391
392 switch (protoid) {
393 case ST_BT:
394 /* Allocate new packet to hold received data */
395 st_gdata->rx_skb =
396 bt_skb_alloc(HCI_MAX_FRAME_SIZE, GFP_ATOMIC);
397 if (!st_gdata->rx_skb) {
398 pr_err("Can't allocate mem for new packet");
399 st_gdata->rx_state = ST_W4_PACKET_TYPE;
400 st_gdata->rx_count = 0;
401 return;
402 }
403 bt_cb(st_gdata->rx_skb)->pkt_type = type;
404 break;
405 case ST_FM: /* for FM */
406 st_gdata->rx_skb =
407 alloc_skb(FM_MAX_FRAME_SIZE, GFP_ATOMIC);
408 if (!st_gdata->rx_skb) {
409 pr_err("Can't allocate mem for new packet");
410 st_gdata->rx_state = ST_W4_PACKET_TYPE;
411 st_gdata->rx_count = 0;
412 return;
413 }
414 /* place holder 0x08 */
415 skb_reserve(st_gdata->rx_skb, 1);
416 st_gdata->rx_skb->cb[0] = ST_FM_CH8_PKT;
417 break;
418 case ST_GPS:
419 /* for GPS */
420 st_gdata->rx_skb =
421 alloc_skb(100 /*GPS_MAX_FRAME_SIZE */ , GFP_ATOMIC);
422 if (!st_gdata->rx_skb) {
423 pr_err("Can't allocate mem for new packet");
424 st_gdata->rx_state = ST_W4_PACKET_TYPE;
425 st_gdata->rx_count = 0;
426 return;
427 }
428 /* place holder 0x09 */
429 skb_reserve(st_gdata->rx_skb, 1);
430 st_gdata->rx_skb->cb[0] = 0x09; /*ST_GPS_CH9_PKT; */
431 break;
432 case ST_MAX:
433 break;
434 }
435 }
436 pr_debug("done %s", __func__);
437 return;
438}
439
440/**
441 * st_int_dequeue - internal de-Q function.
442 * If the previous data set was not written
443 * completely, return that skb which has the pending data.
444 * In normal cases, return top of txq.
445 */
446struct sk_buff *st_int_dequeue(struct st_data_s *st_gdata)
447{
448 struct sk_buff *returning_skb;
449
450 pr_debug("%s", __func__);
451 if (st_gdata->tx_skb != NULL) {
452 returning_skb = st_gdata->tx_skb;
453 st_gdata->tx_skb = NULL;
454 return returning_skb;
455 }
456 return skb_dequeue(&st_gdata->txq);
457}
458
459/**
460 * st_int_enqueue - internal Q-ing function.
461 * Will either Q the skb to txq or the tx_waitq
462 * depending on the ST LL state.
463 * If the chip is asleep, then Q it onto waitq and
464 * wakeup the chip.
465 * txq and waitq needs protection since the other contexts
466 * may be sending data, waking up chip.
467 */
468void st_int_enqueue(struct st_data_s *st_gdata, struct sk_buff *skb)
469{
470 unsigned long flags = 0;
471
472 pr_debug("%s", __func__);
473 spin_lock_irqsave(&st_gdata->lock, flags);
474
475 switch (st_ll_getstate(st_gdata)) {
476 case ST_LL_AWAKE:
477 pr_info("ST LL is AWAKE, sending normally");
478 skb_queue_tail(&st_gdata->txq, skb);
479 break;
480 case ST_LL_ASLEEP_TO_AWAKE:
481 skb_queue_tail(&st_gdata->tx_waitq, skb);
482 break;
483 case ST_LL_AWAKE_TO_ASLEEP:
484 pr_err("ST LL is illegal state(%ld),"
485 "purging received skb.", st_ll_getstate(st_gdata));
486 kfree_skb(skb);
487 break;
488 case ST_LL_ASLEEP:
489 skb_queue_tail(&st_gdata->tx_waitq, skb);
490 st_ll_wakeup(st_gdata);
491 break;
492 default:
493 pr_err("ST LL is illegal state(%ld),"
494 "purging received skb.", st_ll_getstate(st_gdata));
495 kfree_skb(skb);
496 break;
497 }
498
499 spin_unlock_irqrestore(&st_gdata->lock, flags);
500 pr_debug("done %s", __func__);
501 return;
502}
503
504/*
505 * internal wakeup function
506 * called from either
507 * - TTY layer when write's finished
508 * - st_write (in context of the protocol stack)
509 */
510void st_tx_wakeup(struct st_data_s *st_data)
511{
512 struct sk_buff *skb;
513 unsigned long flags; /* for irq save flags */
514 pr_debug("%s", __func__);
515 /* check for sending & set flag sending here */
516 if (test_and_set_bit(ST_TX_SENDING, &st_data->tx_state)) {
517 pr_info("ST already sending");
518 /* keep sending */
519 set_bit(ST_TX_WAKEUP, &st_data->tx_state);
520 return;
521 /* TX_WAKEUP will be checked in another
522 * context
523 */
524 }
525 do { /* come back if st_tx_wakeup is set */
526 /* woke-up to write */
527 clear_bit(ST_TX_WAKEUP, &st_data->tx_state);
528 while ((skb = st_int_dequeue(st_data))) {
529 int len;
530 spin_lock_irqsave(&st_data->lock, flags);
531 /* enable wake-up from TTY */
532 set_bit(TTY_DO_WRITE_WAKEUP, &st_data->tty->flags);
533 len = st_int_write(st_data, skb->data, skb->len);
534 skb_pull(skb, len);
535 /* if skb->len = len as expected, skb->len=0 */
536 if (skb->len) {
537 /* would be the next skb to be sent */
538 st_data->tx_skb = skb;
539 spin_unlock_irqrestore(&st_data->lock, flags);
540 break;
541 }
542 kfree_skb(skb);
543 spin_unlock_irqrestore(&st_data->lock, flags);
544 }
545 /* if wake-up is set in another context- restart sending */
546 } while (test_bit(ST_TX_WAKEUP, &st_data->tx_state));
547
548 /* clear flag sending */
549 clear_bit(ST_TX_SENDING, &st_data->tx_state);
550}
551
552/********************************************************************/
553/* functions called from ST KIM
554*/
555void kim_st_list_protocols(struct st_data_s *st_gdata, void *buf)
556{
557 seq_printf(buf, "[%d]\nBT=%c\nFM=%c\nGPS=%c\n",
558 st_gdata->protos_registered,
559 st_gdata->list[ST_BT] != NULL ? 'R' : 'U',
560 st_gdata->list[ST_FM] != NULL ? 'R' : 'U',
561 st_gdata->list[ST_GPS] != NULL ? 'R' : 'U');
562}
563
564/********************************************************************/
565/*
566 * functions called from protocol stack drivers
567 * to be EXPORT-ed
568 */
569long st_register(struct st_proto_s *new_proto)
570{
571 struct st_data_s *st_gdata;
572 long err = 0;
573 unsigned long flags = 0;
574
575 st_kim_ref(&st_gdata, 0);
576 pr_info("%s(%d) ", __func__, new_proto->type);
577 if (st_gdata == NULL || new_proto == NULL || new_proto->recv == NULL
578 || new_proto->reg_complete_cb == NULL) {
579 pr_err("gdata/new_proto/recv or reg_complete_cb not ready");
580 return -1;
581 }
582
583 if (new_proto->type < ST_BT || new_proto->type >= ST_MAX) {
584 pr_err("protocol %d not supported", new_proto->type);
585 return -EPROTONOSUPPORT;
586 }
587
588 if (st_gdata->list[new_proto->type] != NULL) {
589 pr_err("protocol %d already registered", new_proto->type);
590 return -EALREADY;
591 }
592
593 /* can be from process context only */
594 spin_lock_irqsave(&st_gdata->lock, flags);
595
596 if (test_bit(ST_REG_IN_PROGRESS, &st_gdata->st_state)) {
597 pr_info(" ST_REG_IN_PROGRESS:%d ", new_proto->type);
598 /* fw download in progress */
599 st_kim_chip_toggle(new_proto->type, KIM_GPIO_ACTIVE);
600
601 st_gdata->list[new_proto->type] = new_proto;
602 st_gdata->protos_registered++;
603 new_proto->write = st_write;
604
605 set_bit(ST_REG_PENDING, &st_gdata->st_state);
606 spin_unlock_irqrestore(&st_gdata->lock, flags);
607 return -EINPROGRESS;
608 } else if (st_gdata->protos_registered == ST_EMPTY) {
609 pr_info(" protocol list empty :%d ", new_proto->type);
610 set_bit(ST_REG_IN_PROGRESS, &st_gdata->st_state);
611 st_recv = st_kim_recv;
612
613 /* release lock previously held - re-locked below */
614 spin_unlock_irqrestore(&st_gdata->lock, flags);
615
616 /* enable the ST LL - to set default chip state */
617 st_ll_enable(st_gdata);
618 /* this may take a while to complete
619 * since it involves BT fw download
620 */
621 err = st_kim_start(st_gdata->kim_data);
622 if (err != 0) {
623 clear_bit(ST_REG_IN_PROGRESS, &st_gdata->st_state);
624 if ((st_gdata->protos_registered != ST_EMPTY) &&
625 (test_bit(ST_REG_PENDING, &st_gdata->st_state))) {
626 pr_err(" KIM failure complete callback ");
627 st_reg_complete(st_gdata, -1);
628 }
629
630 return -1;
631 }
632
633 /* the protocol might require other gpios to be toggled
634 */
635 st_kim_chip_toggle(new_proto->type, KIM_GPIO_ACTIVE);
636
637 clear_bit(ST_REG_IN_PROGRESS, &st_gdata->st_state);
638 st_recv = st_int_recv;
639
640 /* this is where all pending registration
641 * are signalled to be complete by calling callback functions
642 */
643 if ((st_gdata->protos_registered != ST_EMPTY) &&
644 (test_bit(ST_REG_PENDING, &st_gdata->st_state))) {
645 pr_debug(" call reg complete callback ");
646 st_reg_complete(st_gdata, 0);
647 }
648 clear_bit(ST_REG_PENDING, &st_gdata->st_state);
649
650 /* check for already registered once more,
651 * since the above check is old
652 */
653 if (st_gdata->list[new_proto->type] != NULL) {
654 pr_err(" proto %d already registered ",
655 new_proto->type);
656 return -EALREADY;
657 }
658
659 spin_lock_irqsave(&st_gdata->lock, flags);
660 st_gdata->list[new_proto->type] = new_proto;
661 st_gdata->protos_registered++;
662 new_proto->write = st_write;
663 spin_unlock_irqrestore(&st_gdata->lock, flags);
664 return err;
665 }
666 /* if fw is already downloaded & new stack registers protocol */
667 else {
668 switch (new_proto->type) {
669 case ST_BT:
670 /* do nothing */
671 break;
672 case ST_FM:
673 case ST_GPS:
674 st_kim_chip_toggle(new_proto->type, KIM_GPIO_ACTIVE);
675 break;
676 case ST_MAX:
677 default:
678 pr_err("%d protocol not supported",
679 new_proto->type);
680 spin_unlock_irqrestore(&st_gdata->lock, flags);
681 return -EPROTONOSUPPORT;
682 }
683 st_gdata->list[new_proto->type] = new_proto;
684 st_gdata->protos_registered++;
685 new_proto->write = st_write;
686
687 /* lock already held before entering else */
688 spin_unlock_irqrestore(&st_gdata->lock, flags);
689 return err;
690 }
691 pr_debug("done %s(%d) ", __func__, new_proto->type);
692}
693EXPORT_SYMBOL_GPL(st_register);
694
695/* to unregister a protocol -
696 * to be called from protocol stack driver
697 */
698long st_unregister(enum proto_type type)
699{
700 long err = 0;
701 unsigned long flags = 0;
702 struct st_data_s *st_gdata;
703
704 pr_debug("%s: %d ", __func__, type);
705
706 st_kim_ref(&st_gdata, 0);
707 if (type < ST_BT || type >= ST_MAX) {
708 pr_err(" protocol %d not supported", type);
709 return -EPROTONOSUPPORT;
710 }
711
712 spin_lock_irqsave(&st_gdata->lock, flags);
713
714 if (st_gdata->list[type] == NULL) {
715 pr_err(" protocol %d not registered", type);
716 spin_unlock_irqrestore(&st_gdata->lock, flags);
717 return -EPROTONOSUPPORT;
718 }
719
720 st_gdata->protos_registered--;
721 st_gdata->list[type] = NULL;
722
723 /* kim ignores BT in the below function
724 * and handles the rest, BT is toggled
725 * only in kim_start and kim_stop
726 */
727 st_kim_chip_toggle(type, KIM_GPIO_INACTIVE);
728 spin_unlock_irqrestore(&st_gdata->lock, flags);
729
730 if ((st_gdata->protos_registered == ST_EMPTY) &&
731 (!test_bit(ST_REG_PENDING, &st_gdata->st_state))) {
732 pr_info(" all protocols unregistered ");
733
734 /* stop traffic on tty */
735 if (st_gdata->tty) {
736 tty_ldisc_flush(st_gdata->tty);
737 stop_tty(st_gdata->tty);
738 }
739
740 /* all protocols now unregistered */
741 st_kim_stop(st_gdata->kim_data);
742 /* disable ST LL */
743 st_ll_disable(st_gdata);
744 }
745 return err;
746}
747
748/*
749 * called in protocol stack drivers
750 * via the write function pointer
751 */
752long st_write(struct sk_buff *skb)
753{
754 struct st_data_s *st_gdata;
755#ifdef DEBUG
756 enum proto_type protoid = ST_MAX;
757#endif
758 long len;
759
760 st_kim_ref(&st_gdata, 0);
761 if (unlikely(skb == NULL || st_gdata == NULL
762 || st_gdata->tty == NULL)) {
763 pr_err("data/tty unavailable to perform write");
764 return -1;
765 }
766#ifdef DEBUG /* open-up skb to read the 1st byte */
767 switch (skb->data[0]) {
768 case HCI_COMMAND_PKT:
769 case HCI_ACLDATA_PKT:
770 case HCI_SCODATA_PKT:
771 protoid = ST_BT;
772 break;
773 case ST_FM_CH8_PKT:
774 protoid = ST_FM;
775 break;
776 case 0x09:
777 protoid = ST_GPS;
778 break;
779 }
780 if (unlikely(st_gdata->list[protoid] == NULL)) {
781 pr_err(" protocol %d not registered, and writing? ",
782 protoid);
783 return -1;
784 }
785#endif
786 pr_debug("%d to be written", skb->len);
787 len = skb->len;
788
789 /* st_ll to decide where to enqueue the skb */
790 st_int_enqueue(st_gdata, skb);
791 /* wake up */
792 st_tx_wakeup(st_gdata);
793
794 /* return number of bytes written */
795 return len;
796}
797
798/* for protocols making use of shared transport */
799EXPORT_SYMBOL_GPL(st_unregister);
800
801/********************************************************************/
802/*
803 * functions called from TTY layer
804 */
805static int st_tty_open(struct tty_struct *tty)
806{
807 int err = 0;
808 struct st_data_s *st_gdata;
809 pr_info("%s ", __func__);
810
811 st_kim_ref(&st_gdata, 0);
812 st_gdata->tty = tty;
813 tty->disc_data = st_gdata;
814
815 /* don't do an wakeup for now */
816 clear_bit(TTY_DO_WRITE_WAKEUP, &tty->flags);
817
818 /* mem already allocated
819 */
820 tty->receive_room = 65536;
821 /* Flush any pending characters in the driver and discipline. */
822 tty_ldisc_flush(tty);
823 tty_driver_flush_buffer(tty);
824 /*
825 * signal to UIM via KIM that -
826 * installation of N_TI_WL ldisc is complete
827 */
828 st_kim_complete(st_gdata->kim_data);
829 pr_debug("done %s", __func__);
830 return err;
831}
832
833static void st_tty_close(struct tty_struct *tty)
834{
835 unsigned char i = ST_MAX;
836 unsigned long flags = 0;
837 struct st_data_s *st_gdata = tty->disc_data;
838
839 pr_info("%s ", __func__);
840
841 /* TODO:
842 * if a protocol has been registered & line discipline
843 * un-installed for some reason - what should be done ?
844 */
845 spin_lock_irqsave(&st_gdata->lock, flags);
846 for (i = ST_BT; i < ST_MAX; i++) {
847 if (st_gdata->list[i] != NULL)
848 pr_err("%d not un-registered", i);
849 st_gdata->list[i] = NULL;
850 }
851 st_gdata->protos_registered = 0;
852 spin_unlock_irqrestore(&st_gdata->lock, flags);
853 /*
854 * signal to UIM via KIM that -
855 * N_TI_WL ldisc is un-installed
856 */
857 st_kim_complete(st_gdata->kim_data);
858 st_gdata->tty = NULL;
859 /* Flush any pending characters in the driver and discipline. */
860 tty_ldisc_flush(tty);
861 tty_driver_flush_buffer(tty);
862
863 spin_lock_irqsave(&st_gdata->lock, flags);
864 /* empty out txq and tx_waitq */
865 skb_queue_purge(&st_gdata->txq);
866 skb_queue_purge(&st_gdata->tx_waitq);
867 /* reset the TTY Rx states of ST */
868 st_gdata->rx_count = 0;
869 st_gdata->rx_state = ST_W4_PACKET_TYPE;
870 kfree_skb(st_gdata->rx_skb);
871 st_gdata->rx_skb = NULL;
872 spin_unlock_irqrestore(&st_gdata->lock, flags);
873
874 pr_debug("%s: done ", __func__);
875}
876
877static void st_tty_receive(struct tty_struct *tty, const unsigned char *data,
878 char *tty_flags, int count)
879{
880
881#ifdef VERBOSE
882 print_hex_dump(KERN_DEBUG, ">in>", DUMP_PREFIX_NONE,
883 16, 1, data, count, 0);
884#endif
885
886 /*
887 * if fw download is in progress then route incoming data
888 * to KIM for validation
889 */
890 st_recv(tty->disc_data, data, count);
891 pr_debug("done %s", __func__);
892}
893
894/* wake-up function called in from the TTY layer
895 * inside the internal wakeup function will be called
896 */
897static void st_tty_wakeup(struct tty_struct *tty)
898{
899 struct st_data_s *st_gdata = tty->disc_data;
900 pr_debug("%s ", __func__);
901 /* don't do an wakeup for now */
902 clear_bit(TTY_DO_WRITE_WAKEUP, &tty->flags);
903
904 /* call our internal wakeup */
905 st_tx_wakeup((void *)st_gdata);
906}
907
908static void st_tty_flush_buffer(struct tty_struct *tty)
909{
910 struct st_data_s *st_gdata = tty->disc_data;
911 pr_debug("%s ", __func__);
912
913 kfree_skb(st_gdata->tx_skb);
914 st_gdata->tx_skb = NULL;
915
916 tty->ops->flush_buffer(tty);
917 return;
918}
919
920/********************************************************************/
921int st_core_init(struct st_data_s **core_data)
922{
923 struct st_data_s *st_gdata;
924 long err;
925 static struct tty_ldisc_ops *st_ldisc_ops;
926
927 /* populate and register to TTY line discipline */
928 st_ldisc_ops = kzalloc(sizeof(*st_ldisc_ops), GFP_KERNEL);
929 if (!st_ldisc_ops) {
930 pr_err("no mem to allocate");
931 return -ENOMEM;
932 }
933
934 st_ldisc_ops->magic = TTY_LDISC_MAGIC;
935 st_ldisc_ops->name = "n_st"; /*"n_hci"; */
936 st_ldisc_ops->open = st_tty_open;
937 st_ldisc_ops->close = st_tty_close;
938 st_ldisc_ops->receive_buf = st_tty_receive;
939 st_ldisc_ops->write_wakeup = st_tty_wakeup;
940 st_ldisc_ops->flush_buffer = st_tty_flush_buffer;
941 st_ldisc_ops->owner = THIS_MODULE;
942
943 err = tty_register_ldisc(N_TI_WL, st_ldisc_ops);
944 if (err) {
945 pr_err("error registering %d line discipline %ld",
946 N_TI_WL, err);
947 kfree(st_ldisc_ops);
948 return err;
949 }
950 pr_debug("registered n_shared line discipline");
951
952 st_gdata = kzalloc(sizeof(struct st_data_s), GFP_KERNEL);
953 if (!st_gdata) {
954 pr_err("memory allocation failed");
955 err = tty_unregister_ldisc(N_TI_WL);
956 if (err)
957 pr_err("unable to un-register ldisc %ld", err);
958 kfree(st_ldisc_ops);
959 err = -ENOMEM;
960 return err;
961 }
962
963 /* Initialize ST TxQ and Tx waitQ queue head. All BT/FM/GPS module skb's
964 * will be pushed in this queue for actual transmission.
965 */
966 skb_queue_head_init(&st_gdata->txq);
967 skb_queue_head_init(&st_gdata->tx_waitq);
968
969 /* Locking used in st_int_enqueue() to avoid multiple execution */
970 spin_lock_init(&st_gdata->lock);
971
972 /* ldisc_ops ref to be only used in __exit of module */
973 st_gdata->ldisc_ops = st_ldisc_ops;
974
975#if 0
976 err = st_kim_init();
977 if (err) {
978 pr_err("error during kim initialization(%ld)", err);
979 kfree(st_gdata);
980 err = tty_unregister_ldisc(N_TI_WL);
981 if (err)
982 pr_err("unable to un-register ldisc");
983 kfree(st_ldisc_ops);
984 return -1;
985 }
986#endif
987
988 err = st_ll_init(st_gdata);
989 if (err) {
990 pr_err("error during st_ll initialization(%ld)", err);
991 kfree(st_gdata);
992 err = tty_unregister_ldisc(N_TI_WL);
993 if (err)
994 pr_err("unable to un-register ldisc");
995 kfree(st_ldisc_ops);
996 return -1;
997 }
998 *core_data = st_gdata;
999 return 0;
1000}
1001
1002void st_core_exit(struct st_data_s *st_gdata)
1003{
1004 long err;
1005 /* internal module cleanup */
1006 err = st_ll_deinit(st_gdata);
1007 if (err)
1008 pr_err("error during deinit of ST LL %ld", err);
1009#if 0
1010 err = st_kim_deinit();
1011 if (err)
1012 pr_err("error during deinit of ST KIM %ld", err);
1013#endif
1014 if (st_gdata != NULL) {
1015 /* Free ST Tx Qs and skbs */
1016 skb_queue_purge(&st_gdata->txq);
1017 skb_queue_purge(&st_gdata->tx_waitq);
1018 kfree_skb(st_gdata->rx_skb);
1019 kfree_skb(st_gdata->tx_skb);
1020 /* TTY ldisc cleanup */
1021 err = tty_unregister_ldisc(N_TI_WL);
1022 if (err)
1023 pr_err("unable to un-register ldisc %ld", err);
1024 kfree(st_gdata->ldisc_ops);
1025 /* free the global data pointer */
1026 kfree(st_gdata);
1027 }
1028}
1029
1030
diff --git a/drivers/staging/ti-st/st_kim.c b/drivers/staging/ti-st/st_kim.c
deleted file mode 100644
index 372a9960c30..00000000000
--- a/drivers/staging/ti-st/st_kim.c
+++ /dev/null
@@ -1,797 +0,0 @@
1/*
2 * Shared Transport Line discipline driver Core
3 * Init Manager module responsible for GPIO control
4 * and firmware download
5 * Copyright (C) 2009 Texas Instruments
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 *
20 */
21
22#define pr_fmt(fmt) "(stk) :" fmt
23#include <linux/platform_device.h>
24#include <linux/jiffies.h>
25#include <linux/firmware.h>
26#include <linux/delay.h>
27#include <linux/wait.h>
28#include <linux/gpio.h>
29#include <linux/debugfs.h>
30#include <linux/seq_file.h>
31#include <linux/sched.h>
32#include <linux/rfkill.h>
33
34/* understand BT events for fw response */
35#include <net/bluetooth/bluetooth.h>
36#include <net/bluetooth/hci_core.h>
37#include <net/bluetooth/hci.h>
38
39#include <linux/ti_wilink_st.h>
40
41
42static int kim_probe(struct platform_device *pdev);
43static int kim_remove(struct platform_device *pdev);
44
45/* KIM platform device driver structure */
46static struct platform_driver kim_platform_driver = {
47 .probe = kim_probe,
48 .remove = kim_remove,
49 /* TODO: ST driver power management during suspend/resume ?
50 */
51#if 0
52 .suspend = kim_suspend,
53 .resume = kim_resume,
54#endif
55 .driver = {
56 .name = "kim",
57 .owner = THIS_MODULE,
58 },
59};
60
61static int kim_toggle_radio(void*, bool);
62static const struct rfkill_ops kim_rfkill_ops = {
63 .set_block = kim_toggle_radio,
64};
65
66/* strings to be used for rfkill entries and by
67 * ST Core to be used for sysfs debug entry
68 */
69#define PROTO_ENTRY(type, name) name
70const unsigned char *protocol_names[] = {
71 PROTO_ENTRY(ST_BT, "Bluetooth"),
72 PROTO_ENTRY(ST_FM, "FM"),
73 PROTO_ENTRY(ST_GPS, "GPS"),
74};
75
76#define MAX_ST_DEVICES 3 /* Imagine 1 on each UART for now */
77struct platform_device *st_kim_devices[MAX_ST_DEVICES];
78
79/**********************************************************************/
80/* internal functions */
81
82/**
83 * st_get_plat_device -
84 * function which returns the reference to the platform device
85 * requested by id. As of now only 1 such device exists (id=0)
86 * the context requesting for reference can get the id to be
87 * requested by a. The protocol driver which is registering or
88 * b. the tty device which is opened.
89 */
90static struct platform_device *st_get_plat_device(int id)
91{
92 return st_kim_devices[id];
93}
94
95/**
96 * validate_firmware_response -
97 * function to return whether the firmware response was proper
98 * in case of error don't complete so that waiting for proper
99 * response times out
100 */
101void validate_firmware_response(struct kim_data_s *kim_gdata)
102{
103 struct sk_buff *skb = kim_gdata->rx_skb;
104 if (unlikely(skb->data[5] != 0)) {
105 pr_err("no proper response during fw download");
106 pr_err("data6 %x", skb->data[5]);
107 return; /* keep waiting for the proper response */
108 }
109 /* becos of all the script being downloaded */
110 complete_all(&kim_gdata->kim_rcvd);
111 kfree_skb(skb);
112}
113
114/* check for data len received inside kim_int_recv
115 * most often hit the last case to update state to waiting for data
116 */
117static inline int kim_check_data_len(struct kim_data_s *kim_gdata, int len)
118{
119 register int room = skb_tailroom(kim_gdata->rx_skb);
120
121 pr_debug("len %d room %d", len, room);
122
123 if (!len) {
124 validate_firmware_response(kim_gdata);
125 } else if (len > room) {
126 /* Received packet's payload length is larger.
127 * We can't accommodate it in created skb.
128 */
129 pr_err("Data length is too large len %d room %d", len,
130 room);
131 kfree_skb(kim_gdata->rx_skb);
132 } else {
133 /* Packet header has non-zero payload length and
134 * we have enough space in created skb. Lets read
135 * payload data */
136 kim_gdata->rx_state = ST_BT_W4_DATA;
137 kim_gdata->rx_count = len;
138 return len;
139 }
140
141 /* Change ST LL state to continue to process next
142 * packet */
143 kim_gdata->rx_state = ST_W4_PACKET_TYPE;
144 kim_gdata->rx_skb = NULL;
145 kim_gdata->rx_count = 0;
146
147 return 0;
148}
149
150/**
151 * kim_int_recv - receive function called during firmware download
152 * firmware download responses on different UART drivers
153 * have been observed to come in bursts of different
154 * tty_receive and hence the logic
155 */
156void kim_int_recv(struct kim_data_s *kim_gdata,
157 const unsigned char *data, long count)
158{
159 register char *ptr;
160 struct hci_event_hdr *eh;
161 register int len = 0, type = 0;
162
163 pr_debug("%s", __func__);
164 /* Decode received bytes here */
165 ptr = (char *)data;
166 if (unlikely(ptr == NULL)) {
167 pr_err(" received null from TTY ");
168 return;
169 }
170 while (count) {
171 if (kim_gdata->rx_count) {
172 len = min_t(unsigned int, kim_gdata->rx_count, count);
173 memcpy(skb_put(kim_gdata->rx_skb, len), ptr, len);
174 kim_gdata->rx_count -= len;
175 count -= len;
176 ptr += len;
177
178 if (kim_gdata->rx_count)
179 continue;
180
181 /* Check ST RX state machine , where are we? */
182 switch (kim_gdata->rx_state) {
183 /* Waiting for complete packet ? */
184 case ST_BT_W4_DATA:
185 pr_debug("Complete pkt received");
186 validate_firmware_response(kim_gdata);
187 kim_gdata->rx_state = ST_W4_PACKET_TYPE;
188 kim_gdata->rx_skb = NULL;
189 continue;
190 /* Waiting for Bluetooth event header ? */
191 case ST_BT_W4_EVENT_HDR:
192 eh = (struct hci_event_hdr *)kim_gdata->
193 rx_skb->data;
194 pr_debug("Event header: evt 0x%2.2x"
195 "plen %d", eh->evt, eh->plen);
196 kim_check_data_len(kim_gdata, eh->plen);
197 continue;
198 } /* end of switch */
199 } /* end of if rx_state */
200 switch (*ptr) {
201 /* Bluetooth event packet? */
202 case HCI_EVENT_PKT:
203 pr_info("Event packet");
204 kim_gdata->rx_state = ST_BT_W4_EVENT_HDR;
205 kim_gdata->rx_count = HCI_EVENT_HDR_SIZE;
206 type = HCI_EVENT_PKT;
207 break;
208 default:
209 pr_info("unknown packet");
210 ptr++;
211 count--;
212 continue;
213 }
214 ptr++;
215 count--;
216 kim_gdata->rx_skb =
217 bt_skb_alloc(HCI_MAX_FRAME_SIZE, GFP_ATOMIC);
218 if (!kim_gdata->rx_skb) {
219 pr_err("can't allocate mem for new packet");
220 kim_gdata->rx_state = ST_W4_PACKET_TYPE;
221 kim_gdata->rx_count = 0;
222 return;
223 }
224 bt_cb(kim_gdata->rx_skb)->pkt_type = type;
225 }
226 pr_info("done %s", __func__);
227 return;
228}
229
230static long read_local_version(struct kim_data_s *kim_gdata, char *bts_scr_name)
231{
232 unsigned short version = 0, chip = 0, min_ver = 0, maj_ver = 0;
233 char read_ver_cmd[] = { 0x01, 0x01, 0x10, 0x00 };
234
235 pr_debug("%s", __func__);
236
237 INIT_COMPLETION(kim_gdata->kim_rcvd);
238 if (4 != st_int_write(kim_gdata->core_data, read_ver_cmd, 4)) {
239 pr_err("kim: couldn't write 4 bytes");
240 return -1;
241 }
242
243 if (!wait_for_completion_timeout
244 (&kim_gdata->kim_rcvd, msecs_to_jiffies(CMD_RESP_TIME))) {
245 pr_err(" waiting for ver info- timed out ");
246 return -1;
247 }
248
249 version =
250 MAKEWORD(kim_gdata->resp_buffer[13],
251 kim_gdata->resp_buffer[14]);
252 chip = (version & 0x7C00) >> 10;
253 min_ver = (version & 0x007F);
254 maj_ver = (version & 0x0380) >> 7;
255
256 if (version & 0x8000)
257 maj_ver |= 0x0008;
258
259 sprintf(bts_scr_name, "TIInit_%d.%d.%d.bts", chip, maj_ver, min_ver);
260
261 /* to be accessed later via sysfs entry */
262 kim_gdata->version.full = version;
263 kim_gdata->version.chip = chip;
264 kim_gdata->version.maj_ver = maj_ver;
265 kim_gdata->version.min_ver = min_ver;
266
267 pr_info("%s", bts_scr_name);
268 return 0;
269}
270
271/**
272 * download_firmware -
273 * internal function which parses through the .bts firmware
274 * script file intreprets SEND, DELAY actions only as of now
275 */
276static long download_firmware(struct kim_data_s *kim_gdata)
277{
278 long err = 0;
279 long len = 0;
280 register unsigned char *ptr = NULL;
281 register unsigned char *action_ptr = NULL;
282 unsigned char bts_scr_name[30] = { 0 }; /* 30 char long bts scr name? */
283
284 err = read_local_version(kim_gdata, bts_scr_name);
285 if (err != 0) {
286 pr_err("kim: failed to read local ver");
287 return err;
288 }
289 err =
290 request_firmware(&kim_gdata->fw_entry, bts_scr_name,
291 &kim_gdata->kim_pdev->dev);
292 if (unlikely((err != 0) || (kim_gdata->fw_entry->data == NULL) ||
293 (kim_gdata->fw_entry->size == 0))) {
294 pr_err(" request_firmware failed(errno %ld) for %s", err,
295 bts_scr_name);
296 return -1;
297 }
298 ptr = (void *)kim_gdata->fw_entry->data;
299 len = kim_gdata->fw_entry->size;
300 /* bts_header to remove out magic number and
301 * version
302 */
303 ptr += sizeof(struct bts_header);
304 len -= sizeof(struct bts_header);
305
306 while (len > 0 && ptr) {
307 pr_debug(" action size %d, type %d ",
308 ((struct bts_action *)ptr)->size,
309 ((struct bts_action *)ptr)->type);
310
311 switch (((struct bts_action *)ptr)->type) {
312 case ACTION_SEND_COMMAND: /* action send */
313 action_ptr = &(((struct bts_action *)ptr)->data[0]);
314 if (unlikely
315 (((struct hci_command *)action_ptr)->opcode ==
316 0xFF36)) {
317 /* ignore remote change
318 * baud rate HCI VS command */
319 pr_err
320 (" change remote baud"
321 " rate command in firmware");
322 break;
323 }
324
325 INIT_COMPLETION(kim_gdata->kim_rcvd);
326 err = st_int_write(kim_gdata->core_data,
327 ((struct bts_action_send *)action_ptr)->data,
328 ((struct bts_action *)ptr)->size);
329 if (unlikely(err < 0)) {
330 release_firmware(kim_gdata->fw_entry);
331 return -1;
332 }
333 if (!wait_for_completion_timeout
334 (&kim_gdata->kim_rcvd,
335 msecs_to_jiffies(CMD_RESP_TIME))) {
336 pr_err
337 (" response timeout during fw download ");
338 /* timed out */
339 release_firmware(kim_gdata->fw_entry);
340 return -1;
341 }
342 break;
343 case ACTION_DELAY: /* sleep */
344 pr_info("sleep command in scr");
345 action_ptr = &(((struct bts_action *)ptr)->data[0]);
346 mdelay(((struct bts_action_delay *)action_ptr)->msec);
347 break;
348 }
349 len =
350 len - (sizeof(struct bts_action) +
351 ((struct bts_action *)ptr)->size);
352 ptr =
353 ptr + sizeof(struct bts_action) +
354 ((struct bts_action *)ptr)->size;
355 }
356 /* fw download complete */
357 release_firmware(kim_gdata->fw_entry);
358 return 0;
359}
360
361/**********************************************************************/
362/* functions called from ST core */
363/* function to toggle the GPIO
364 * needs to know whether the GPIO is active high or active low
365 */
366void st_kim_chip_toggle(enum proto_type type, enum kim_gpio_state state)
367{
368 struct platform_device *kim_pdev;
369 struct kim_data_s *kim_gdata;
370 pr_info(" %s ", __func__);
371
372 kim_pdev = st_get_plat_device(0);
373 kim_gdata = dev_get_drvdata(&kim_pdev->dev);
374
375 if (kim_gdata->gpios[type] == -1) {
376 pr_info(" gpio not requested for protocol %s",
377 protocol_names[type]);
378 return;
379 }
380 switch (type) {
381 case ST_BT:
382 /*Do Nothing */
383 break;
384
385 case ST_FM:
386 if (state == KIM_GPIO_ACTIVE)
387 gpio_set_value(kim_gdata->gpios[ST_FM], GPIO_LOW);
388 else
389 gpio_set_value(kim_gdata->gpios[ST_FM], GPIO_HIGH);
390 break;
391
392 case ST_GPS:
393 if (state == KIM_GPIO_ACTIVE)
394 gpio_set_value(kim_gdata->gpios[ST_GPS], GPIO_HIGH);
395 else
396 gpio_set_value(kim_gdata->gpios[ST_GPS], GPIO_LOW);
397 break;
398
399 case ST_MAX:
400 default:
401 break;
402 }
403
404 return;
405}
406
407/* called from ST Core, when REG_IN_PROGRESS (registration in progress)
408 * can be because of
409 * 1. response to read local version
410 * 2. during send/recv's of firmware download
411 */
412void st_kim_recv(void *disc_data, const unsigned char *data, long count)
413{
414 struct st_data_s *st_gdata = (struct st_data_s *)disc_data;
415 struct kim_data_s *kim_gdata = st_gdata->kim_data;
416
417 pr_info(" %s ", __func__);
418 /* copy to local buffer */
419 if (unlikely(data[4] == 0x01 && data[5] == 0x10 && data[0] == 0x04)) {
420 /* must be the read_ver_cmd */
421 memcpy(kim_gdata->resp_buffer, data, count);
422 complete_all(&kim_gdata->kim_rcvd);
423 return;
424 } else {
425 kim_int_recv(kim_gdata, data, count);
426 /* either completes or times out */
427 }
428 return;
429}
430
431/* to signal completion of line discipline installation
432 * called from ST Core, upon tty_open
433 */
434void st_kim_complete(void *kim_data)
435{
436 struct kim_data_s *kim_gdata = (struct kim_data_s *)kim_data;
437 complete(&kim_gdata->ldisc_installed);
438}
439
440/**
441 * st_kim_start - called from ST Core upon 1st registration
442 * This involves toggling the chip enable gpio, reading
443 * the firmware version from chip, forming the fw file name
444 * based on the chip version, requesting the fw, parsing it
445 * and perform download(send/recv).
446 */
447long st_kim_start(void *kim_data)
448{
449 long err = 0;
450 long retry = POR_RETRY_COUNT;
451 struct kim_data_s *kim_gdata = (struct kim_data_s *)kim_data;
452
453 pr_info(" %s", __func__);
454
455 do {
456 /* TODO: this is only because rfkill sub-system
457 * doesn't send events to user-space if the state
458 * isn't changed
459 */
460 rfkill_set_hw_state(kim_gdata->rfkill[ST_BT], 1);
461 /* Configure BT nShutdown to HIGH state */
462 gpio_set_value(kim_gdata->gpios[ST_BT], GPIO_LOW);
463 mdelay(5); /* FIXME: a proper toggle */
464 gpio_set_value(kim_gdata->gpios[ST_BT], GPIO_HIGH);
465 mdelay(100);
466 /* re-initialize the completion */
467 INIT_COMPLETION(kim_gdata->ldisc_installed);
468#if 0 /* older way of signalling user-space UIM */
469 /* send signal to UIM */
470 err = kill_pid(find_get_pid(kim_gdata->uim_pid), SIGUSR2, 0);
471 if (err != 0) {
472 pr_info(" sending SIGUSR2 to uim failed %ld", err);
473 err = -1;
474 continue;
475 }
476#endif
477 /* unblock and send event to UIM via /dev/rfkill */
478 rfkill_set_hw_state(kim_gdata->rfkill[ST_BT], 0);
479 /* wait for ldisc to be installed */
480 err = wait_for_completion_timeout(&kim_gdata->ldisc_installed,
481 msecs_to_jiffies(LDISC_TIME));
482 if (!err) { /* timeout */
483 pr_err("line disc installation timed out ");
484 err = -1;
485 continue;
486 } else {
487 /* ldisc installed now */
488 pr_info(" line discipline installed ");
489 err = download_firmware(kim_gdata);
490 if (err != 0) {
491 pr_err("download firmware failed");
492 continue;
493 } else { /* on success don't retry */
494 break;
495 }
496 }
497 } while (retry--);
498 return err;
499}
500
501/**
502 * st_kim_stop - called from ST Core, on the last un-registration
503 * toggle low the chip enable gpio
504 */
505long st_kim_stop(void *kim_data)
506{
507 long err = 0;
508 struct kim_data_s *kim_gdata = (struct kim_data_s *)kim_data;
509
510 INIT_COMPLETION(kim_gdata->ldisc_installed);
511#if 0 /* older way of signalling user-space UIM */
512 /* send signal to UIM */
513 err = kill_pid(find_get_pid(kim_gdata->uim_pid), SIGUSR2, 1);
514 if (err != 0) {
515 pr_err("sending SIGUSR2 to uim failed %ld", err);
516 return -1;
517 }
518#endif
519 /* set BT rfkill to be blocked */
520 err = rfkill_set_hw_state(kim_gdata->rfkill[ST_BT], 1);
521
522 /* wait for ldisc to be un-installed */
523 err = wait_for_completion_timeout(&kim_gdata->ldisc_installed,
524 msecs_to_jiffies(LDISC_TIME));
525 if (!err) { /* timeout */
526 pr_err(" timed out waiting for ldisc to be un-installed");
527 return -1;
528 }
529
530 /* By default configure BT nShutdown to LOW state */
531 gpio_set_value(kim_gdata->gpios[ST_BT], GPIO_LOW);
532 mdelay(1);
533 gpio_set_value(kim_gdata->gpios[ST_BT], GPIO_HIGH);
534 mdelay(1);
535 gpio_set_value(kim_gdata->gpios[ST_BT], GPIO_LOW);
536 return err;
537}
538
539/**********************************************************************/
540/* functions called from subsystems */
541/* called when debugfs entry is read from */
542
543static int show_version(struct seq_file *s, void *unused)
544{
545 struct kim_data_s *kim_gdata = (struct kim_data_s *)s->private;
546 seq_printf(s, "%04X %d.%d.%d\n", kim_gdata->version.full,
547 kim_gdata->version.chip, kim_gdata->version.maj_ver,
548 kim_gdata->version.min_ver);
549 return 0;
550}
551
552static int show_list(struct seq_file *s, void *unused)
553{
554 struct kim_data_s *kim_gdata = (struct kim_data_s *)s->private;
555 kim_st_list_protocols(kim_gdata->core_data, s);
556 return 0;
557}
558
559/* function called from rfkill subsystem, when someone from
560 * user space would write 0/1 on the sysfs entry
561 * /sys/class/rfkill/rfkill0,1,3/state
562 */
563static int kim_toggle_radio(void *data, bool blocked)
564{
565 enum proto_type type = *((enum proto_type *)data);
566 pr_debug(" %s: %d ", __func__, type);
567
568 switch (type) {
569 case ST_BT:
570 /* do nothing */
571 break;
572 case ST_FM:
573 case ST_GPS:
574 if (blocked)
575 st_kim_chip_toggle(type, KIM_GPIO_INACTIVE);
576 else
577 st_kim_chip_toggle(type, KIM_GPIO_ACTIVE);
578 break;
579 case ST_MAX:
580 pr_err(" wrong proto type ");
581 break;
582 }
583 return 0;
584}
585
586/**
587 * st_kim_ref - reference the core's data
588 * This references the per-ST platform device in the arch/xx/
589 * board-xx.c file.
590 * This would enable multiple such platform devices to exist
591 * on a given platform
592 */
593void st_kim_ref(struct st_data_s **core_data, int id)
594{
595 struct platform_device *pdev;
596 struct kim_data_s *kim_gdata;
597 /* get kim_gdata reference from platform device */
598 pdev = st_get_plat_device(id);
599 kim_gdata = dev_get_drvdata(&pdev->dev);
600 *core_data = kim_gdata->core_data;
601}
602
603static int kim_version_open(struct inode *i, struct file *f)
604{
605 return single_open(f, show_version, i->i_private);
606}
607
608static int kim_list_open(struct inode *i, struct file *f)
609{
610 return single_open(f, show_list, i->i_private);
611}
612
613static const struct file_operations version_debugfs_fops = {
614 /* version info */
615 .open = kim_version_open,
616 .read = seq_read,
617 .llseek = seq_lseek,
618 .release = single_release,
619};
620static const struct file_operations list_debugfs_fops = {
621 /* protocols info */
622 .open = kim_list_open,
623 .read = seq_read,
624 .llseek = seq_lseek,
625 .release = single_release,
626};
627
628/**********************************************************************/
629/* functions called from platform device driver subsystem
630 * need to have a relevant platform device entry in the platform's
631 * board-*.c file
632 */
633
634struct dentry *kim_debugfs_dir;
635static int kim_probe(struct platform_device *pdev)
636{
637 long status;
638 long proto;
639 long *gpios = pdev->dev.platform_data;
640 struct kim_data_s *kim_gdata;
641
642 if ((pdev->id != -1) && (pdev->id < MAX_ST_DEVICES)) {
643 /* multiple devices could exist */
644 st_kim_devices[pdev->id] = pdev;
645 } else {
646 /* platform's sure about existance of 1 device */
647 st_kim_devices[0] = pdev;
648 }
649
650 kim_gdata = kzalloc(sizeof(struct kim_data_s), GFP_ATOMIC);
651 if (!kim_gdata) {
652 pr_err("no mem to allocate");
653 return -ENOMEM;
654 }
655 dev_set_drvdata(&pdev->dev, kim_gdata);
656
657 status = st_core_init(&kim_gdata->core_data);
658 if (status != 0) {
659 pr_err(" ST core init failed");
660 return -1;
661 }
662 /* refer to itself */
663 kim_gdata->core_data->kim_data = kim_gdata;
664
665 for (proto = 0; proto < ST_MAX; proto++) {
666 kim_gdata->gpios[proto] = gpios[proto];
667 pr_info(" %ld gpio to be requested", gpios[proto]);
668 }
669
670 for (proto = 0; (proto < ST_MAX) && (gpios[proto] != -1); proto++) {
671 /* Claim the Bluetooth/FM/GPIO
672 * nShutdown gpio from the system
673 */
674 status = gpio_request(gpios[proto], "kim");
675 if (unlikely(status)) {
676 pr_err(" gpio %ld request failed ", gpios[proto]);
677 proto -= 1;
678 while (proto >= 0) {
679 if (gpios[proto] != -1)
680 gpio_free(gpios[proto]);
681 }
682 return status;
683 }
684
685 /* Configure nShutdown GPIO as output=0 */
686 status =
687 gpio_direction_output(gpios[proto], 0);
688 if (unlikely(status)) {
689 pr_err(" unable to configure gpio %ld",
690 gpios[proto]);
691 proto -= 1;
692 while (proto >= 0) {
693 if (gpios[proto] != -1)
694 gpio_free(gpios[proto]);
695 }
696 return status;
697 }
698 }
699 /* get reference of pdev for request_firmware
700 */
701 kim_gdata->kim_pdev = pdev;
702 init_completion(&kim_gdata->kim_rcvd);
703 init_completion(&kim_gdata->ldisc_installed);
704
705 for (proto = 0; (proto < ST_MAX) && (gpios[proto] != -1); proto++) {
706 /* TODO: should all types be rfkill_type_bt ? */
707 kim_gdata->rf_protos[proto] = proto;
708 kim_gdata->rfkill[proto] = rfkill_alloc(protocol_names[proto],
709 &pdev->dev, RFKILL_TYPE_BLUETOOTH,
710 &kim_rfkill_ops, &kim_gdata->rf_protos[proto]);
711 if (kim_gdata->rfkill[proto] == NULL) {
712 pr_err("cannot create rfkill entry for gpio %ld",
713 gpios[proto]);
714 continue;
715 }
716 /* block upon creation */
717 rfkill_init_sw_state(kim_gdata->rfkill[proto], 1);
718 status = rfkill_register(kim_gdata->rfkill[proto]);
719 if (unlikely(status)) {
720 pr_err("rfkill registration failed for gpio %ld",
721 gpios[proto]);
722 rfkill_unregister(kim_gdata->rfkill[proto]);
723 continue;
724 }
725 pr_info("rfkill entry created for %ld", gpios[proto]);
726 }
727
728 kim_debugfs_dir = debugfs_create_dir("ti-st", NULL);
729 if (IS_ERR(kim_debugfs_dir)) {
730 pr_err(" debugfs entries creation failed ");
731 kim_debugfs_dir = NULL;
732 return -1;
733 }
734
735 debugfs_create_file("version", S_IRUGO, kim_debugfs_dir,
736 kim_gdata, &version_debugfs_fops);
737 debugfs_create_file("protocols", S_IRUGO, kim_debugfs_dir,
738 kim_gdata, &list_debugfs_fops);
739 pr_info(" debugfs entries created ");
740 return 0;
741}
742
743static int kim_remove(struct platform_device *pdev)
744{
745 /* free the GPIOs requested
746 */
747 long *gpios = pdev->dev.platform_data;
748 long proto;
749 struct kim_data_s *kim_gdata;
750
751 kim_gdata = dev_get_drvdata(&pdev->dev);
752
753 for (proto = 0; (proto < ST_MAX) && (gpios[proto] != -1); proto++) {
754 /* Claim the Bluetooth/FM/GPIO
755 * nShutdown gpio from the system
756 */
757 gpio_free(gpios[proto]);
758 rfkill_unregister(kim_gdata->rfkill[proto]);
759 rfkill_destroy(kim_gdata->rfkill[proto]);
760 kim_gdata->rfkill[proto] = NULL;
761 }
762 pr_info("kim: GPIO Freed");
763 debugfs_remove_recursive(kim_debugfs_dir);
764 kim_gdata->kim_pdev = NULL;
765 st_core_exit(kim_gdata->core_data);
766
767 kfree(kim_gdata);
768 kim_gdata = NULL;
769 return 0;
770}
771
772/**********************************************************************/
773/* entry point for ST KIM module, called in from ST Core */
774
775static int __init st_kim_init(void)
776{
777 long ret = 0;
778 ret = platform_driver_register(&kim_platform_driver);
779 if (ret != 0) {
780 pr_err("platform drv registration failed");
781 return -1;
782 }
783 return 0;
784}
785
786static void __exit st_kim_deinit(void)
787{
788 /* the following returns void */
789 platform_driver_unregister(&kim_platform_driver);
790}
791
792
793module_init(st_kim_init);
794module_exit(st_kim_deinit);
795MODULE_AUTHOR("Pavan Savoy <pavan_savoy@ti.com>");
796MODULE_DESCRIPTION("Shared Transport Driver for TI BT/FM/GPS combo chips ");
797MODULE_LICENSE("GPL");
diff --git a/drivers/staging/ti-st/st_ll.c b/drivers/staging/ti-st/st_ll.c
deleted file mode 100644
index ed1e4bc180d..00000000000
--- a/drivers/staging/ti-st/st_ll.c
+++ /dev/null
@@ -1,149 +0,0 @@
1/*
2 * Shared Transport driver
3 * HCI-LL module responsible for TI proprietary HCI_LL protocol
4 * Copyright (C) 2009 Texas Instruments
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 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 *
19 */
20
21#define pr_fmt(fmt) "(stll) :" fmt
22#include <linux/skbuff.h>
23#include <linux/module.h>
24#include <linux/ti_wilink_st.h>
25
26/**********************************************************************/
27/* internal functions */
28static void send_ll_cmd(struct st_data_s *st_data,
29 unsigned char cmd)
30{
31
32 pr_info("%s: writing %x", __func__, cmd);
33 st_int_write(st_data, &cmd, 1);
34 return;
35}
36
37static void ll_device_want_to_sleep(struct st_data_s *st_data)
38{
39 pr_debug("%s", __func__);
40 /* sanity check */
41 if (st_data->ll_state != ST_LL_AWAKE)
42 pr_err("ERR hcill: ST_LL_GO_TO_SLEEP_IND"
43 "in state %ld", st_data->ll_state);
44
45 send_ll_cmd(st_data, LL_SLEEP_ACK);
46 /* update state */
47 st_data->ll_state = ST_LL_ASLEEP;
48}
49
50static void ll_device_want_to_wakeup(struct st_data_s *st_data)
51{
52 /* diff actions in diff states */
53 switch (st_data->ll_state) {
54 case ST_LL_ASLEEP:
55 send_ll_cmd(st_data, LL_WAKE_UP_ACK); /* send wake_ack */
56 break;
57 case ST_LL_ASLEEP_TO_AWAKE:
58 /* duplicate wake_ind */
59 pr_err("duplicate wake_ind while waiting for Wake ack");
60 break;
61 case ST_LL_AWAKE:
62 /* duplicate wake_ind */
63 pr_err("duplicate wake_ind already AWAKE");
64 break;
65 case ST_LL_AWAKE_TO_ASLEEP:
66 /* duplicate wake_ind */
67 pr_err("duplicate wake_ind");
68 break;
69 }
70 /* update state */
71 st_data->ll_state = ST_LL_AWAKE;
72}
73
74/**********************************************************************/
75/* functions invoked by ST Core */
76
77/* called when ST Core wants to
78 * enable ST LL */
79void st_ll_enable(struct st_data_s *ll)
80{
81 ll->ll_state = ST_LL_AWAKE;
82}
83
84/* called when ST Core /local module wants to
85 * disable ST LL */
86void st_ll_disable(struct st_data_s *ll)
87{
88 ll->ll_state = ST_LL_INVALID;
89}
90
91/* called when ST Core wants to update the state */
92void st_ll_wakeup(struct st_data_s *ll)
93{
94 if (likely(ll->ll_state != ST_LL_AWAKE)) {
95 send_ll_cmd(ll, LL_WAKE_UP_IND); /* WAKE_IND */
96 ll->ll_state = ST_LL_ASLEEP_TO_AWAKE;
97 } else {
98 /* don't send the duplicate wake_indication */
99 pr_err(" Chip already AWAKE ");
100 }
101}
102
103/* called when ST Core wants the state */
104unsigned long st_ll_getstate(struct st_data_s *ll)
105{
106 pr_debug(" returning state %ld", ll->ll_state);
107 return ll->ll_state;
108}
109
110/* called from ST Core, when a PM related packet arrives */
111unsigned long st_ll_sleep_state(struct st_data_s *st_data,
112 unsigned char cmd)
113{
114 switch (cmd) {
115 case LL_SLEEP_IND: /* sleep ind */
116 pr_info("sleep indication recvd");
117 ll_device_want_to_sleep(st_data);
118 break;
119 case LL_SLEEP_ACK: /* sleep ack */
120 pr_err("sleep ack rcvd: host shouldn't");
121 break;
122 case LL_WAKE_UP_IND: /* wake ind */
123 pr_info("wake indication recvd");
124 ll_device_want_to_wakeup(st_data);
125 break;
126 case LL_WAKE_UP_ACK: /* wake ack */
127 pr_info("wake ack rcvd");
128 st_data->ll_state = ST_LL_AWAKE;
129 break;
130 default:
131 pr_err(" unknown input/state ");
132 return -1;
133 }
134 return 0;
135}
136
137/* Called from ST CORE to initialize ST LL */
138long st_ll_init(struct st_data_s *ll)
139{
140 /* set state to invalid */
141 ll->ll_state = ST_LL_INVALID;
142 return 0;
143}
144
145/* Called from ST CORE to de-initialize ST LL */
146long st_ll_deinit(struct st_data_s *ll)
147{
148 return 0;
149}