Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

drivers:misc: ti-st: register with channel IDs

The architecture of shared transport had begun with individual
protocols like bluetooth, fm and gps telling the shared transport
what sort of protocol they are and then expecting the ST driver
to parse the incoming data from chip and forward data only
relevant to the protocol drivers.

This change would mean each protocol drivers would also send
information to ST driver as to how to intrepret their protocol
data coming out of the chip.

Signed-off-by: Pavan Savoy <pavan_savoy@ti.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>

authored by

Pavan Savoy and committed by
Greg Kroah-Hartman
5c88b021 6d6a49e9

+167 -284
+112 -243
drivers/misc/ti-st/st_core.c
··· 25 25 #include <linux/init.h> 26 26 #include <linux/tty.h> 27 27 28 - /* understand BT, FM and GPS for now */ 29 - #include <net/bluetooth/bluetooth.h> 30 - #include <net/bluetooth/hci_core.h> 31 - #include <net/bluetooth/hci.h> 28 + #include <linux/seq_file.h> 29 + #include <linux/skbuff.h> 30 + 32 31 #include <linux/ti_wilink_st.h> 33 32 34 33 /* function pointer pointing to either, ··· 37 38 void (*st_recv) (void*, const unsigned char*, long); 38 39 39 40 /********************************************************************/ 40 - #if 0 41 - /* internal misc functions */ 42 - bool is_protocol_list_empty(void) 41 + static void add_channel_to_table(struct st_data_s *st_gdata, 42 + struct st_proto_s *new_proto) 43 43 { 44 - unsigned char i = 0; 45 - pr_debug(" %s ", __func__); 46 - for (i = 0; i < ST_MAX; i++) { 47 - if (st_gdata->list[i] != NULL) 48 - return ST_NOTEMPTY; 49 - /* not empty */ 50 - } 51 - /* list empty */ 52 - return ST_EMPTY; 44 + pr_info("%s: id %d\n", __func__, new_proto->chnl_id); 45 + /* list now has the channel id as index itself */ 46 + st_gdata->list[new_proto->chnl_id] = new_proto; 53 47 } 54 - #endif 48 + 49 + static void remove_channel_from_table(struct st_data_s *st_gdata, 50 + struct st_proto_s *proto) 51 + { 52 + pr_info("%s: id %d\n", __func__, proto->chnl_id); 53 + st_gdata->list[proto->chnl_id] = NULL; 54 + } 55 55 56 56 /* can be called in from 57 57 * -- KIM (during fw download) ··· 80 82 * push the skb received to relevant 81 83 * protocol stacks 82 84 */ 83 - void st_send_frame(enum proto_type protoid, struct st_data_s *st_gdata) 85 + void st_send_frame(unsigned char chnl_id, struct st_data_s *st_gdata) 84 86 { 85 - pr_info(" %s(prot:%d) ", __func__, protoid); 87 + pr_info(" %s(prot:%d) ", __func__, chnl_id); 86 88 87 89 if (unlikely 88 90 (st_gdata == NULL || st_gdata->rx_skb == NULL 89 - || st_gdata->list[protoid] == NULL)) { 90 - pr_err("protocol %d not registered, no data to send?", 91 - protoid); 91 + || st_gdata->list[chnl_id] == NULL)) { 92 + pr_err("chnl_id %d not registered, no data to send?", 93 + chnl_id); 92 94 kfree_skb(st_gdata->rx_skb); 93 95 return; 94 96 } ··· 97 99 * - should be just skb_queue_tail for the 98 100 * protocol stack driver 99 101 */ 100 - if (likely(st_gdata->list[protoid]->recv != NULL)) { 102 + if (likely(st_gdata->list[chnl_id]->recv != NULL)) { 101 103 if (unlikely 102 - (st_gdata->list[protoid]->recv 103 - (st_gdata->list[protoid]->priv_data, st_gdata->rx_skb) 104 + (st_gdata->list[chnl_id]->recv 105 + (st_gdata->list[chnl_id]->priv_data, st_gdata->rx_skb) 104 106 != 0)) { 105 - pr_err(" proto stack %d's ->recv failed", protoid); 107 + pr_err(" proto stack %d's ->recv failed", chnl_id); 106 108 kfree_skb(st_gdata->rx_skb); 107 109 return; 108 110 } 109 111 } else { 110 - pr_err(" proto stack %d's ->recv null", protoid); 112 + pr_err(" proto stack %d's ->recv null", chnl_id); 111 113 kfree_skb(st_gdata->rx_skb); 112 114 } 113 115 return; ··· 122 124 { 123 125 unsigned char i = 0; 124 126 pr_info(" %s ", __func__); 125 - for (i = 0; i < ST_MAX; i++) { 127 + for (i = 0; i < ST_MAX_CHANNELS; i++) { 126 128 if (likely(st_gdata != NULL && st_gdata->list[i] != NULL && 127 129 st_gdata->list[i]->reg_complete_cb != NULL)) 128 130 st_gdata->list[i]->reg_complete_cb ··· 131 133 } 132 134 133 135 static inline int st_check_data_len(struct st_data_s *st_gdata, 134 - int protoid, int len) 136 + unsigned char chnl_id, int len) 135 137 { 136 138 int room = skb_tailroom(st_gdata->rx_skb); 137 139 ··· 142 144 * has zero length payload. So, ask ST CORE to 143 145 * forward the packet to protocol driver (BT/FM/GPS) 144 146 */ 145 - st_send_frame(protoid, st_gdata); 147 + st_send_frame(chnl_id, st_gdata); 146 148 147 149 } else if (len > room) { 148 150 /* Received packet's payload length is larger. ··· 155 157 /* Packet header has non-zero payload length and 156 158 * we have enough space in created skb. Lets read 157 159 * payload data */ 158 - st_gdata->rx_state = ST_BT_W4_DATA; 160 + st_gdata->rx_state = ST_W4_DATA; 159 161 st_gdata->rx_count = len; 160 162 return len; 161 163 } ··· 165 167 st_gdata->rx_state = ST_W4_PACKET_TYPE; 166 168 st_gdata->rx_skb = NULL; 167 169 st_gdata->rx_count = 0; 170 + st_gdata->rx_chnl = 0; 168 171 169 172 return 0; 170 173 } ··· 207 208 const unsigned char *data, long count) 208 209 { 209 210 char *ptr; 210 - struct hci_event_hdr *eh; 211 - struct hci_acl_hdr *ah; 212 - struct hci_sco_hdr *sh; 213 - struct fm_event_hdr *fm; 214 - struct gps_event_hdr *gps; 215 - int len = 0, type = 0, dlen = 0; 216 - static enum proto_type protoid = ST_MAX; 211 + struct st_proto_s *proto; 212 + unsigned short payload_len = 0; 213 + int len = 0, type = 0; 214 + unsigned char *plen; 217 215 struct st_data_s *st_gdata = (struct st_data_s *)disc_data; 218 216 219 217 ptr = (char *)data; ··· 238 242 239 243 /* Check ST RX state machine , where are we? */ 240 244 switch (st_gdata->rx_state) { 241 - 242 - /* Waiting for complete packet ? */ 243 - case ST_BT_W4_DATA: 245 + /* Waiting for complete packet ? */ 246 + case ST_W4_DATA: 244 247 pr_debug("Complete pkt received"); 245 - 246 248 /* Ask ST CORE to forward 247 249 * the packet to protocol driver */ 248 - st_send_frame(protoid, st_gdata); 250 + st_send_frame(st_gdata->rx_chnl, st_gdata); 249 251 250 252 st_gdata->rx_state = ST_W4_PACKET_TYPE; 251 253 st_gdata->rx_skb = NULL; 252 - protoid = ST_MAX; /* is this required ? */ 253 254 continue; 254 - 255 - /* Waiting for Bluetooth event header ? */ 256 - case ST_BT_W4_EVENT_HDR: 257 - eh = (struct hci_event_hdr *)st_gdata->rx_skb-> 258 - data; 259 - 260 - pr_debug("Event header: evt 0x%2.2x" 261 - "plen %d", eh->evt, eh->plen); 262 - 263 - st_check_data_len(st_gdata, protoid, eh->plen); 264 - continue; 265 - 266 - /* Waiting for Bluetooth acl header ? */ 267 - case ST_BT_W4_ACL_HDR: 268 - ah = (struct hci_acl_hdr *)st_gdata->rx_skb-> 269 - data; 270 - dlen = __le16_to_cpu(ah->dlen); 271 - 272 - pr_info("ACL header: dlen %d", dlen); 273 - 274 - st_check_data_len(st_gdata, protoid, dlen); 275 - continue; 276 - 277 - /* Waiting for Bluetooth sco header ? */ 278 - case ST_BT_W4_SCO_HDR: 279 - sh = (struct hci_sco_hdr *)st_gdata->rx_skb-> 280 - data; 281 - 282 - pr_info("SCO header: dlen %d", sh->dlen); 283 - 284 - st_check_data_len(st_gdata, protoid, sh->dlen); 285 - continue; 286 - case ST_FM_W4_EVENT_HDR: 287 - fm = (struct fm_event_hdr *)st_gdata->rx_skb-> 288 - data; 289 - pr_info("FM Header: "); 290 - st_check_data_len(st_gdata, ST_FM, fm->plen); 291 - continue; 292 - /* TODO : Add GPS packet machine logic here */ 293 - case ST_GPS_W4_EVENT_HDR: 294 - /* [0x09 pkt hdr][R/W byte][2 byte len] */ 295 - gps = (struct gps_event_hdr *)st_gdata->rx_skb-> 296 - data; 297 - pr_info("GPS Header: "); 298 - st_check_data_len(st_gdata, ST_GPS, gps->plen); 255 + /* parse the header to know details */ 256 + case ST_W4_HEADER: 257 + proto = st_gdata->list[st_gdata->rx_chnl]; 258 + plen = 259 + &st_gdata->rx_skb->data 260 + [proto->offset_len_in_hdr]; 261 + pr_info("plen pointing to %x\n", *plen); 262 + if (proto->len_size == 1)/* 1 byte len field */ 263 + payload_len = *(unsigned char *)plen; 264 + else if (proto->len_size == 2) 265 + payload_len = 266 + __le16_to_cpu(*(unsigned short *)plen); 267 + else 268 + pr_info("%s: invalid length " 269 + "for id %d\n", 270 + __func__, proto->chnl_id); 271 + st_check_data_len(st_gdata, proto->chnl_id, 272 + payload_len); 273 + pr_info("off %d, pay len %d\n", 274 + proto->offset_len_in_hdr, payload_len); 299 275 continue; 300 276 } /* end of switch rx_state */ 301 277 } ··· 276 308 /* Check first byte of packet and identify module 277 309 * owner (BT/FM/GPS) */ 278 310 switch (*ptr) { 279 - 280 - /* Bluetooth event packet? */ 281 - case HCI_EVENT_PKT: 282 - pr_info("Event packet"); 283 - st_gdata->rx_state = ST_BT_W4_EVENT_HDR; 284 - st_gdata->rx_count = HCI_EVENT_HDR_SIZE; 285 - type = HCI_EVENT_PKT; 286 - protoid = ST_BT; 287 - break; 288 - 289 - /* Bluetooth acl packet? */ 290 - case HCI_ACLDATA_PKT: 291 - pr_info("ACL packet"); 292 - st_gdata->rx_state = ST_BT_W4_ACL_HDR; 293 - st_gdata->rx_count = HCI_ACL_HDR_SIZE; 294 - type = HCI_ACLDATA_PKT; 295 - protoid = ST_BT; 296 - break; 297 - 298 - /* Bluetooth sco packet? */ 299 - case HCI_SCODATA_PKT: 300 - pr_info("SCO packet"); 301 - st_gdata->rx_state = ST_BT_W4_SCO_HDR; 302 - st_gdata->rx_count = HCI_SCO_HDR_SIZE; 303 - type = HCI_SCODATA_PKT; 304 - protoid = ST_BT; 305 - break; 306 - 307 - /* Channel 8(FM) packet? */ 308 - case ST_FM_CH8_PKT: 309 - pr_info("FM CH8 packet"); 310 - type = ST_FM_CH8_PKT; 311 - st_gdata->rx_state = ST_FM_W4_EVENT_HDR; 312 - st_gdata->rx_count = FM_EVENT_HDR_SIZE; 313 - protoid = ST_FM; 314 - break; 315 - 316 - /* Channel 9(GPS) packet? */ 317 - case 0x9: /*ST_LL_GPS_CH9_PKT */ 318 - pr_info("GPS CH9 packet"); 319 - type = 0x9; /* ST_LL_GPS_CH9_PKT; */ 320 - protoid = ST_GPS; 321 - st_gdata->rx_state = ST_GPS_W4_EVENT_HDR; 322 - st_gdata->rx_count = 3; /* GPS_EVENT_HDR_SIZE -1*/ 323 - break; 324 311 case LL_SLEEP_IND: 325 312 case LL_SLEEP_ACK: 326 313 case LL_WAKE_UP_IND: ··· 296 373 continue; 297 374 /* Unknow packet? */ 298 375 default: 299 - pr_err("Unknown packet type %2.2x", (__u8) *ptr); 300 - ptr++; 301 - count--; 302 - continue; 376 + type = *ptr; 377 + st_gdata->rx_skb = alloc_skb( 378 + st_gdata->list[type]->max_frame_size, 379 + GFP_ATOMIC); 380 + skb_reserve(st_gdata->rx_skb, 381 + st_gdata->list[type]->reserve); 382 + /* next 2 required for BT only */ 383 + st_gdata->rx_skb->cb[0] = type; /*pkt_type*/ 384 + st_gdata->rx_skb->cb[1] = 0; /*incoming*/ 385 + st_gdata->rx_chnl = *ptr; 386 + st_gdata->rx_state = ST_W4_HEADER; 387 + st_gdata->rx_count = st_gdata->list[type]->hdr_len; 388 + pr_info("rx_count %ld\n", st_gdata->rx_count); 303 389 }; 304 390 ptr++; 305 391 count--; 306 - 307 - switch (protoid) { 308 - case ST_BT: 309 - /* Allocate new packet to hold received data */ 310 - st_gdata->rx_skb = 311 - bt_skb_alloc(HCI_MAX_FRAME_SIZE, GFP_ATOMIC); 312 - if (!st_gdata->rx_skb) { 313 - pr_err("Can't allocate mem for new packet"); 314 - st_gdata->rx_state = ST_W4_PACKET_TYPE; 315 - st_gdata->rx_count = 0; 316 - return; 317 - } 318 - bt_cb(st_gdata->rx_skb)->pkt_type = type; 319 - break; 320 - case ST_FM: /* for FM */ 321 - st_gdata->rx_skb = 322 - alloc_skb(FM_MAX_FRAME_SIZE, GFP_ATOMIC); 323 - if (!st_gdata->rx_skb) { 324 - pr_err("Can't allocate mem for new packet"); 325 - st_gdata->rx_state = ST_W4_PACKET_TYPE; 326 - st_gdata->rx_count = 0; 327 - return; 328 - } 329 - /* place holder 0x08 */ 330 - skb_reserve(st_gdata->rx_skb, 1); 331 - st_gdata->rx_skb->cb[0] = ST_FM_CH8_PKT; 332 - break; 333 - case ST_GPS: 334 - /* for GPS */ 335 - st_gdata->rx_skb = 336 - alloc_skb(100 /*GPS_MAX_FRAME_SIZE */ , GFP_ATOMIC); 337 - if (!st_gdata->rx_skb) { 338 - pr_err("Can't allocate mem for new packet"); 339 - st_gdata->rx_state = ST_W4_PACKET_TYPE; 340 - st_gdata->rx_count = 0; 341 - return; 342 - } 343 - /* place holder 0x09 */ 344 - skb_reserve(st_gdata->rx_skb, 1); 345 - st_gdata->rx_skb->cb[0] = 0x09; /*ST_GPS_CH9_PKT; */ 346 - break; 347 - case ST_MAX: 348 - break; 349 - } 350 392 } 351 393 pr_debug("done %s", __func__); 352 394 return; ··· 453 565 unsigned long flags = 0; 454 566 455 567 st_kim_ref(&st_gdata, 0); 456 - pr_info("%s(%d) ", __func__, new_proto->type); 568 + pr_info("%s(%d) ", __func__, new_proto->chnl_id); 457 569 if (st_gdata == NULL || new_proto == NULL || new_proto->recv == NULL 458 570 || new_proto->reg_complete_cb == NULL) { 459 571 pr_err("gdata/new_proto/recv or reg_complete_cb not ready"); 572 + if (st_gdata == NULL) 573 + pr_err("error 1\n"); 574 + if (new_proto == NULL) 575 + pr_err("error 2\n"); 576 + if (new_proto->recv == NULL) 577 + pr_err("error 3\n"); 578 + if (new_proto->reg_complete_cb == NULL) 579 + pr_err("erro 4\n"); 460 580 return -1; 461 581 } 462 582 463 - if (new_proto->type < ST_BT || new_proto->type >= ST_MAX) { 464 - pr_err("protocol %d not supported", new_proto->type); 583 + if (new_proto->chnl_id >= ST_MAX_CHANNELS) { 584 + pr_err("chnl_id %d not supported", new_proto->chnl_id); 465 585 return -EPROTONOSUPPORT; 466 586 } 467 587 468 - if (st_gdata->list[new_proto->type] != NULL) { 469 - pr_err("protocol %d already registered", new_proto->type); 588 + if (st_gdata->list[new_proto->chnl_id] != NULL) { 589 + pr_err("chnl_id %d already registered", new_proto->chnl_id); 470 590 return -EALREADY; 471 591 } 472 592 ··· 482 586 spin_lock_irqsave(&st_gdata->lock, flags); 483 587 484 588 if (test_bit(ST_REG_IN_PROGRESS, &st_gdata->st_state)) { 485 - pr_info(" ST_REG_IN_PROGRESS:%d ", new_proto->type); 589 + pr_info(" ST_REG_IN_PROGRESS:%d ", new_proto->chnl_id); 486 590 /* fw download in progress */ 487 - st_kim_chip_toggle(new_proto->type, KIM_GPIO_ACTIVE); 591 + st_kim_chip_toggle(new_proto->chnl_id, KIM_GPIO_ACTIVE); 488 592 489 - st_gdata->list[new_proto->type] = new_proto; 593 + add_channel_to_table(st_gdata, new_proto); 490 594 st_gdata->protos_registered++; 491 595 new_proto->write = st_write; 492 596 ··· 494 598 spin_unlock_irqrestore(&st_gdata->lock, flags); 495 599 return -EINPROGRESS; 496 600 } else if (st_gdata->protos_registered == ST_EMPTY) { 497 - pr_info(" protocol list empty :%d ", new_proto->type); 601 + pr_info(" chnl_id list empty :%d ", new_proto->chnl_id); 498 602 set_bit(ST_REG_IN_PROGRESS, &st_gdata->st_state); 499 603 st_recv = st_kim_recv; 500 604 ··· 518 622 return -1; 519 623 } 520 624 521 - /* the protocol might require other gpios to be toggled 625 + /* the chnl_id might require other gpios to be toggled 522 626 */ 523 - st_kim_chip_toggle(new_proto->type, KIM_GPIO_ACTIVE); 627 + st_kim_chip_toggle(new_proto->chnl_id, KIM_GPIO_ACTIVE); 524 628 525 629 clear_bit(ST_REG_IN_PROGRESS, &st_gdata->st_state); 526 630 st_recv = st_int_recv; ··· 538 642 /* check for already registered once more, 539 643 * since the above check is old 540 644 */ 541 - if (st_gdata->list[new_proto->type] != NULL) { 645 + if (st_gdata->list[new_proto->chnl_id] != NULL) { 542 646 pr_err(" proto %d already registered ", 543 - new_proto->type); 647 + new_proto->chnl_id); 544 648 return -EALREADY; 545 649 } 546 650 547 651 spin_lock_irqsave(&st_gdata->lock, flags); 548 - st_gdata->list[new_proto->type] = new_proto; 652 + add_channel_to_table(st_gdata, new_proto); 549 653 st_gdata->protos_registered++; 550 654 new_proto->write = st_write; 551 655 spin_unlock_irqrestore(&st_gdata->lock, flags); ··· 553 657 } 554 658 /* if fw is already downloaded & new stack registers protocol */ 555 659 else { 556 - switch (new_proto->type) { 557 - case ST_BT: 558 - /* do nothing */ 559 - break; 560 - case ST_FM: 561 - case ST_GPS: 562 - st_kim_chip_toggle(new_proto->type, KIM_GPIO_ACTIVE); 563 - break; 564 - case ST_MAX: 565 - default: 566 - pr_err("%d protocol not supported", 567 - new_proto->type); 568 - spin_unlock_irqrestore(&st_gdata->lock, flags); 569 - return -EPROTONOSUPPORT; 570 - } 571 - st_gdata->list[new_proto->type] = new_proto; 660 + add_channel_to_table(st_gdata, new_proto); 572 661 st_gdata->protos_registered++; 573 662 new_proto->write = st_write; 574 663 ··· 561 680 spin_unlock_irqrestore(&st_gdata->lock, flags); 562 681 return err; 563 682 } 564 - pr_debug("done %s(%d) ", __func__, new_proto->type); 683 + pr_debug("done %s(%d) ", __func__, new_proto->chnl_id); 565 684 } 566 685 EXPORT_SYMBOL_GPL(st_register); 567 686 568 687 /* to unregister a protocol - 569 688 * to be called from protocol stack driver 570 689 */ 571 - long st_unregister(enum proto_type type) 690 + long st_unregister(struct st_proto_s *proto) 572 691 { 573 692 long err = 0; 574 693 unsigned long flags = 0; 575 694 struct st_data_s *st_gdata; 576 695 577 - pr_debug("%s: %d ", __func__, type); 696 + pr_debug("%s: %d ", __func__, proto->chnl_id); 578 697 579 698 st_kim_ref(&st_gdata, 0); 580 - if (type < ST_BT || type >= ST_MAX) { 581 - pr_err(" protocol %d not supported", type); 699 + if (proto->chnl_id >= ST_MAX_CHANNELS) { 700 + pr_err(" chnl_id %d not supported", proto->chnl_id); 582 701 return -EPROTONOSUPPORT; 583 702 } 584 703 585 704 spin_lock_irqsave(&st_gdata->lock, flags); 586 705 587 - if (st_gdata->list[type] == NULL) { 588 - pr_err(" protocol %d not registered", type); 706 + if (st_gdata->list[proto->chnl_id] == NULL) { 707 + pr_err(" chnl_id %d not registered", proto->chnl_id); 589 708 spin_unlock_irqrestore(&st_gdata->lock, flags); 590 709 return -EPROTONOSUPPORT; 591 710 } 592 711 593 712 st_gdata->protos_registered--; 594 - st_gdata->list[type] = NULL; 713 + remove_channel_from_table(st_gdata, proto); 595 714 596 715 /* kim ignores BT in the below function 597 716 * and handles the rest, BT is toggled 598 717 * only in kim_start and kim_stop 599 718 */ 600 - st_kim_chip_toggle(type, KIM_GPIO_INACTIVE); 719 + st_kim_chip_toggle(proto->chnl_id, KIM_GPIO_INACTIVE); 601 720 spin_unlock_irqrestore(&st_gdata->lock, flags); 602 721 603 722 if ((st_gdata->protos_registered == ST_EMPTY) && 604 723 (!test_bit(ST_REG_PENDING, &st_gdata->st_state))) { 605 - pr_info(" all protocols unregistered "); 724 + pr_info(" all chnl_ids unregistered "); 606 725 607 726 /* stop traffic on tty */ 608 727 if (st_gdata->tty) { ··· 610 729 stop_tty(st_gdata->tty); 611 730 } 612 731 613 - /* all protocols now unregistered */ 732 + /* all chnl_ids now unregistered */ 614 733 st_kim_stop(st_gdata->kim_data); 615 734 /* disable ST LL */ 616 735 st_ll_disable(st_gdata); ··· 626 745 { 627 746 struct st_data_s *st_gdata; 628 747 #ifdef DEBUG 629 - enum proto_type protoid = ST_MAX; 748 + unsigned char chnl_id = ST_MAX_CHANNELS; 630 749 #endif 631 750 long len; 632 751 ··· 637 756 return -1; 638 757 } 639 758 #ifdef DEBUG /* open-up skb to read the 1st byte */ 640 - switch (skb->data[0]) { 641 - case HCI_COMMAND_PKT: 642 - case HCI_ACLDATA_PKT: 643 - case HCI_SCODATA_PKT: 644 - protoid = ST_BT; 645 - break; 646 - case ST_FM_CH8_PKT: 647 - protoid = ST_FM; 648 - break; 649 - case 0x09: 650 - protoid = ST_GPS; 651 - break; 652 - } 653 - if (unlikely(st_gdata->list[protoid] == NULL)) { 654 - pr_err(" protocol %d not registered, and writing? ", 655 - protoid); 759 + chnl_id = skb->data[0]; 760 + if (unlikely(st_gdata->list[chnl_id] == NULL)) { 761 + pr_err(" chnl_id %d not registered, and writing? ", 762 + chnl_id); 656 763 return -1; 657 764 } 658 765 #endif ··· 693 824 694 825 static void st_tty_close(struct tty_struct *tty) 695 826 { 696 - unsigned char i = ST_MAX; 827 + unsigned char i = ST_MAX_CHANNELS; 697 828 unsigned long flags = 0; 698 829 struct st_data_s *st_gdata = tty->disc_data; 699 830 ··· 704 835 * un-installed for some reason - what should be done ? 705 836 */ 706 837 spin_lock_irqsave(&st_gdata->lock, flags); 707 - for (i = ST_BT; i < ST_MAX; i++) { 838 + for (i = ST_BT; i < ST_MAX_CHANNELS; i++) { 708 839 if (st_gdata->list[i] != NULL) 709 840 pr_err("%d not un-registered", i); 710 841 st_gdata->list[i] = NULL; ··· 738 869 static void st_tty_receive(struct tty_struct *tty, const unsigned char *data, 739 870 char *tty_flags, int count) 740 871 { 741 - 872 + #define VERBOSE 742 873 #ifdef VERBOSE 743 874 print_hex_dump(KERN_DEBUG, ">in>", DUMP_PREFIX_NONE, 744 875 16, 1, data, count, 0);
+27 -29
drivers/misc/ti-st/st_kim.c
··· 32 32 #include <linux/sched.h> 33 33 #include <linux/rfkill.h> 34 34 35 - /* understand BT events for fw response */ 36 - #include <net/bluetooth/bluetooth.h> 37 - #include <net/bluetooth/hci_core.h> 38 - #include <net/bluetooth/hci.h> 39 - 35 + #include <linux/skbuff.h> 40 36 #include <linux/ti_wilink_st.h> 41 37 42 38 ··· 130 134 /* Packet header has non-zero payload length and 131 135 * we have enough space in created skb. Lets read 132 136 * payload data */ 133 - kim_gdata->rx_state = ST_BT_W4_DATA; 137 + kim_gdata->rx_state = ST_W4_DATA; 134 138 kim_gdata->rx_count = len; 135 139 return len; 136 140 } ··· 154 158 const unsigned char *data, long count) 155 159 { 156 160 const unsigned char *ptr; 157 - struct hci_event_hdr *eh; 158 161 int len = 0, type = 0; 162 + unsigned char *plen; 159 163 160 164 pr_debug("%s", __func__); 161 165 /* Decode received bytes here */ ··· 179 183 /* Check ST RX state machine , where are we? */ 180 184 switch (kim_gdata->rx_state) { 181 185 /* Waiting for complete packet ? */ 182 - case ST_BT_W4_DATA: 186 + case ST_W4_DATA: 183 187 pr_debug("Complete pkt received"); 184 188 validate_firmware_response(kim_gdata); 185 189 kim_gdata->rx_state = ST_W4_PACKET_TYPE; 186 190 kim_gdata->rx_skb = NULL; 187 191 continue; 188 192 /* Waiting for Bluetooth event header ? */ 189 - case ST_BT_W4_EVENT_HDR: 190 - eh = (struct hci_event_hdr *)kim_gdata-> 191 - rx_skb->data; 192 - pr_debug("Event header: evt 0x%2.2x" 193 - "plen %d", eh->evt, eh->plen); 194 - kim_check_data_len(kim_gdata, eh->plen); 193 + case ST_W4_HEADER: 194 + plen = 195 + (unsigned char *)&kim_gdata->rx_skb->data[1]; 196 + pr_debug("event hdr: plen 0x%02x\n", *plen); 197 + kim_check_data_len(kim_gdata, *plen); 195 198 continue; 196 199 } /* end of switch */ 197 200 } /* end of if rx_state */ 198 201 switch (*ptr) { 199 202 /* Bluetooth event packet? */ 200 - case HCI_EVENT_PKT: 201 - pr_info("Event packet"); 202 - kim_gdata->rx_state = ST_BT_W4_EVENT_HDR; 203 - kim_gdata->rx_count = HCI_EVENT_HDR_SIZE; 204 - type = HCI_EVENT_PKT; 203 + case 0x04: 204 + kim_gdata->rx_state = ST_W4_HEADER; 205 + kim_gdata->rx_count = 2; 206 + type = *ptr; 205 207 break; 206 208 default: 207 209 pr_info("unknown packet"); ··· 210 216 ptr++; 211 217 count--; 212 218 kim_gdata->rx_skb = 213 - bt_skb_alloc(HCI_MAX_FRAME_SIZE, GFP_ATOMIC); 219 + alloc_skb(1024+8, GFP_ATOMIC); 214 220 if (!kim_gdata->rx_skb) { 215 221 pr_err("can't allocate mem for new packet"); 216 222 kim_gdata->rx_state = ST_W4_PACKET_TYPE; 217 223 kim_gdata->rx_count = 0; 218 224 return; 219 225 } 220 - bt_cb(kim_gdata->rx_skb)->pkt_type = type; 226 + skb_reserve(kim_gdata->rx_skb, 8); 227 + kim_gdata->rx_skb->cb[0] = 4; 228 + kim_gdata->rx_skb->cb[1] = 0; 229 + 221 230 } 222 - pr_info("done %s", __func__); 223 231 return; 224 232 } 225 233 ··· 394 398 gpio_set_value(kim_gdata->gpios[ST_GPS], GPIO_LOW); 395 399 break; 396 400 397 - case ST_MAX: 401 + case ST_MAX_CHANNELS: 398 402 default: 399 403 break; 400 404 } ··· 412 416 struct st_data_s *st_gdata = (struct st_data_s *)disc_data; 413 417 struct kim_data_s *kim_gdata = st_gdata->kim_data; 414 418 415 - pr_info(" %s ", __func__); 416 419 /* copy to local buffer */ 417 420 if (unlikely(data[4] == 0x01 && data[5] == 0x10 && data[0] == 0x04)) { 418 421 /* must be the read_ver_cmd */ ··· 573 578 else 574 579 st_kim_chip_toggle(type, KIM_GPIO_ACTIVE); 575 580 break; 576 - case ST_MAX: 581 + case ST_MAX_CHANNELS: 577 582 pr_err(" wrong proto type "); 578 583 break; 579 584 } ··· 659 664 /* refer to itself */ 660 665 kim_gdata->core_data->kim_data = kim_gdata; 661 666 662 - for (proto = 0; proto < ST_MAX; proto++) { 667 + for (proto = 0; proto < ST_MAX_CHANNELS; proto++) { 663 668 kim_gdata->gpios[proto] = gpios[proto]; 664 669 pr_info(" %ld gpio to be requested", gpios[proto]); 665 670 } 666 671 667 - for (proto = 0; (proto < ST_MAX) && (gpios[proto] != -1); proto++) { 672 + for (proto = 0; (proto < ST_MAX_CHANNELS) 673 + && (gpios[proto] != -1); proto++) { 668 674 /* Claim the Bluetooth/FM/GPIO 669 675 * nShutdown gpio from the system 670 676 */ ··· 700 704 init_completion(&kim_gdata->kim_rcvd); 701 705 init_completion(&kim_gdata->ldisc_installed); 702 706 703 - for (proto = 0; (proto < ST_MAX) && (gpios[proto] != -1); proto++) { 707 + for (proto = 0; (proto < ST_MAX_CHANNELS) 708 + && (gpios[proto] != -1); proto++) { 704 709 /* TODO: should all types be rfkill_type_bt ? */ 705 710 kim_gdata->rf_protos[proto] = proto; 706 711 kim_gdata->rfkill[proto] = rfkill_alloc(protocol_names[proto], ··· 749 752 750 753 kim_gdata = dev_get_drvdata(&pdev->dev); 751 754 752 - for (proto = 0; (proto < ST_MAX) && (gpios[proto] != -1); proto++) { 755 + for (proto = 0; (proto < ST_MAX_CHANNELS) 756 + && (gpios[proto] != -1); proto++) { 753 757 /* Claim the Bluetooth/FM/GPIO 754 758 * nShutdown gpio from the system 755 759 */