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

Configure Feed

Select the types of activity you want to include in your feed.

misc: ti-st: st_kim: remove the driver

This driver has only ever been used by the omap4-panda board file. This
file has been gone for over 10 years. Let it go.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Link: https://lore.kernel.org/r/20241016094117.16654-1-brgl@bgdev.pl
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Bartosz Golaszewski and committed by
Greg Kroah-Hartman
78fe6636 c3c3a3e2

-1941
-1
drivers/misc/Kconfig
··· 613 613 source "drivers/misc/c2port/Kconfig" 614 614 source "drivers/misc/eeprom/Kconfig" 615 615 source "drivers/misc/cb710/Kconfig" 616 - source "drivers/misc/ti-st/Kconfig" 617 616 source "drivers/misc/lis3lv02d/Kconfig" 618 617 source "drivers/misc/altera-stapl/Kconfig" 619 618 source "drivers/misc/mei/Kconfig"
-1
drivers/misc/Makefile
··· 40 40 obj-y += cb710/ 41 41 obj-$(CONFIG_VMWARE_BALLOON) += vmw_balloon.o 42 42 obj-$(CONFIG_PCH_PHUB) += pch_phub.o 43 - obj-y += ti-st/ 44 43 obj-y += lis3lv02d/ 45 44 obj-$(CONFIG_ALTERA_STAPL) +=altera-stapl/ 46 45 obj-$(CONFIG_INTEL_MEI) += mei/
-19
drivers/misc/ti-st/Kconfig
··· 1 - # SPDX-License-Identifier: GPL-2.0-only 2 - # 3 - # TI's shared transport line discipline and the protocol 4 - # drivers (BT, FM and GPS) 5 - # 6 - menu "Texas Instruments shared transport line discipline" 7 - config TI_ST 8 - tristate "Shared transport core driver" 9 - depends on NET && TTY 10 - depends on GPIOLIB || COMPILE_TEST 11 - select FW_LOADER 12 - help 13 - This enables the shared transport core driver for TI 14 - BT / FM and GPS combo chips. This enables protocol drivers 15 - to register themselves with core and send data, the responses 16 - are returned to relevant protocol drivers based on their 17 - packet types. 18 - 19 - endmenu
-7
drivers/misc/ti-st/Makefile
··· 1 - # SPDX-License-Identifier: GPL-2.0-only 2 - # 3 - # Makefile for TI's shared transport line discipline 4 - # and its protocol drivers (BT, FM, GPS) 5 - # 6 - obj-$(CONFIG_TI_ST) += st_drv.o 7 - st_drv-objs := st_core.o st_kim.o st_ll.o
-918
drivers/misc/ti-st/st_core.c
··· 1 - // SPDX-License-Identifier: GPL-2.0-only 2 - /* 3 - * Shared Transport Line discipline driver Core 4 - * This hooks up ST KIM driver and ST LL driver 5 - * Copyright (C) 2009-2010 Texas Instruments 6 - * Author: Pavan Savoy <pavan_savoy@ti.com> 7 - */ 8 - 9 - #define pr_fmt(fmt) "(stc): " fmt 10 - #include <linux/module.h> 11 - #include <linux/kernel.h> 12 - #include <linux/tty.h> 13 - 14 - #include <linux/seq_file.h> 15 - #include <linux/skbuff.h> 16 - 17 - #include <linux/ti_wilink_st.h> 18 - #include <linux/netdevice.h> 19 - 20 - /* 21 - * function pointer pointing to either, 22 - * st_kim_recv during registration to receive fw download responses 23 - * st_int_recv after registration to receive proto stack responses 24 - */ 25 - static void (*st_recv)(void *disc_data, const u8 *ptr, size_t count); 26 - 27 - /********************************************************************/ 28 - static void add_channel_to_table(struct st_data_s *st_gdata, 29 - struct st_proto_s *new_proto) 30 - { 31 - pr_info("%s: id %d\n", __func__, new_proto->chnl_id); 32 - /* list now has the channel id as index itself */ 33 - st_gdata->list[new_proto->chnl_id] = new_proto; 34 - st_gdata->is_registered[new_proto->chnl_id] = true; 35 - } 36 - 37 - static void remove_channel_from_table(struct st_data_s *st_gdata, 38 - struct st_proto_s *proto) 39 - { 40 - pr_info("%s: id %d\n", __func__, proto->chnl_id); 41 - /* st_gdata->list[proto->chnl_id] = NULL; */ 42 - st_gdata->is_registered[proto->chnl_id] = false; 43 - } 44 - 45 - /* 46 - * called from KIM during firmware download. 47 - * 48 - * This is a wrapper function to tty->ops->write_room. 49 - * It returns number of free space available in 50 - * uart tx buffer. 51 - */ 52 - int st_get_uart_wr_room(struct st_data_s *st_gdata) 53 - { 54 - if (unlikely(st_gdata == NULL || st_gdata->tty == NULL)) { 55 - pr_err("tty unavailable to perform write"); 56 - return -1; 57 - } 58 - 59 - return tty_write_room(st_gdata->tty); 60 - } 61 - 62 - /* 63 - * can be called in from 64 - * -- KIM (during fw download) 65 - * -- ST Core (during st_write) 66 - * 67 - * This is the internal write function - a wrapper 68 - * to tty->ops->write 69 - */ 70 - int st_int_write(struct st_data_s *st_gdata, 71 - const unsigned char *data, int count) 72 - { 73 - struct tty_struct *tty; 74 - if (unlikely(st_gdata == NULL || st_gdata->tty == NULL)) { 75 - pr_err("tty unavailable to perform write"); 76 - return -EINVAL; 77 - } 78 - tty = st_gdata->tty; 79 - #ifdef VERBOSE 80 - print_hex_dump(KERN_DEBUG, "<out<", DUMP_PREFIX_NONE, 81 - 16, 1, data, count, 0); 82 - #endif 83 - return tty->ops->write(tty, data, count); 84 - 85 - } 86 - 87 - /* 88 - * push the skb received to relevant 89 - * protocol stacks 90 - */ 91 - static void st_send_frame(unsigned char chnl_id, struct st_data_s *st_gdata) 92 - { 93 - pr_debug(" %s(prot:%d) ", __func__, chnl_id); 94 - 95 - if (unlikely 96 - (st_gdata == NULL || st_gdata->rx_skb == NULL 97 - || st_gdata->is_registered[chnl_id] == false)) { 98 - pr_err("chnl_id %d not registered, no data to send?", 99 - chnl_id); 100 - kfree_skb(st_gdata->rx_skb); 101 - return; 102 - } 103 - /* 104 - * this cannot fail 105 - * this shouldn't take long 106 - * - should be just skb_queue_tail for the 107 - * protocol stack driver 108 - */ 109 - if (likely(st_gdata->list[chnl_id]->recv != NULL)) { 110 - if (unlikely 111 - (st_gdata->list[chnl_id]->recv 112 - (st_gdata->list[chnl_id]->priv_data, st_gdata->rx_skb) 113 - != 0)) { 114 - pr_err(" proto stack %d's ->recv failed", chnl_id); 115 - kfree_skb(st_gdata->rx_skb); 116 - return; 117 - } 118 - } else { 119 - pr_err(" proto stack %d's ->recv null", chnl_id); 120 - kfree_skb(st_gdata->rx_skb); 121 - } 122 - return; 123 - } 124 - 125 - /* 126 - * st_reg_complete - to call registration complete callbacks 127 - * of all protocol stack drivers 128 - * This function is being called with spin lock held, protocol drivers are 129 - * only expected to complete their waits and do nothing more than that. 130 - */ 131 - static void st_reg_complete(struct st_data_s *st_gdata, int err) 132 - { 133 - unsigned char i = 0; 134 - pr_info(" %s ", __func__); 135 - for (i = 0; i < ST_MAX_CHANNELS; i++) { 136 - if (likely(st_gdata != NULL && 137 - st_gdata->is_registered[i] == true && 138 - st_gdata->list[i]->reg_complete_cb != NULL)) { 139 - st_gdata->list[i]->reg_complete_cb 140 - (st_gdata->list[i]->priv_data, err); 141 - pr_info("protocol %d's cb sent %d\n", i, err); 142 - if (err) { /* cleanup registered protocol */ 143 - st_gdata->is_registered[i] = false; 144 - if (st_gdata->protos_registered) 145 - st_gdata->protos_registered--; 146 - } 147 - } 148 - } 149 - } 150 - 151 - static inline int st_check_data_len(struct st_data_s *st_gdata, 152 - unsigned char chnl_id, int len) 153 - { 154 - int room = skb_tailroom(st_gdata->rx_skb); 155 - 156 - pr_debug("len %d room %d", len, room); 157 - 158 - if (!len) { 159 - /* 160 - * Received packet has only packet header and 161 - * has zero length payload. So, ask ST CORE to 162 - * forward the packet to protocol driver (BT/FM/GPS) 163 - */ 164 - st_send_frame(chnl_id, st_gdata); 165 - 166 - } else if (len > room) { 167 - /* 168 - * Received packet's payload length is larger. 169 - * We can't accommodate it in created skb. 170 - */ 171 - pr_err("Data length is too large len %d room %d", len, 172 - room); 173 - kfree_skb(st_gdata->rx_skb); 174 - } else { 175 - /* 176 - * Packet header has non-zero payload length and 177 - * we have enough space in created skb. Lets read 178 - * payload data */ 179 - st_gdata->rx_state = ST_W4_DATA; 180 - st_gdata->rx_count = len; 181 - return len; 182 - } 183 - 184 - /* Change ST state to continue to process next packet */ 185 - st_gdata->rx_state = ST_W4_PACKET_TYPE; 186 - st_gdata->rx_skb = NULL; 187 - st_gdata->rx_count = 0; 188 - st_gdata->rx_chnl = 0; 189 - 190 - return 0; 191 - } 192 - 193 - /* 194 - * st_wakeup_ack - internal function for action when wake-up ack 195 - * received 196 - */ 197 - static inline void st_wakeup_ack(struct st_data_s *st_gdata, 198 - unsigned char cmd) 199 - { 200 - struct sk_buff *waiting_skb; 201 - unsigned long flags = 0; 202 - 203 - spin_lock_irqsave(&st_gdata->lock, flags); 204 - /* 205 - * de-Q from waitQ and Q in txQ now that the 206 - * chip is awake 207 - */ 208 - while ((waiting_skb = skb_dequeue(&st_gdata->tx_waitq))) 209 - skb_queue_tail(&st_gdata->txq, waiting_skb); 210 - 211 - /* state forwarded to ST LL */ 212 - st_ll_sleep_state(st_gdata, (unsigned long)cmd); 213 - spin_unlock_irqrestore(&st_gdata->lock, flags); 214 - 215 - /* wake up to send the recently copied skbs from waitQ */ 216 - st_tx_wakeup(st_gdata); 217 - } 218 - 219 - /* 220 - * st_int_recv - ST's internal receive function. 221 - * Decodes received RAW data and forwards to corresponding 222 - * client drivers (Bluetooth,FM,GPS..etc). 223 - * This can receive various types of packets, 224 - * HCI-Events, ACL, SCO, 4 types of HCI-LL PM packets 225 - * CH-8 packets from FM, CH-9 packets from GPS cores. 226 - */ 227 - static void st_int_recv(void *disc_data, const u8 *ptr, size_t count) 228 - { 229 - struct st_proto_s *proto; 230 - unsigned short payload_len = 0; 231 - int len = 0; 232 - unsigned char type = 0; 233 - unsigned char *plen; 234 - struct st_data_s *st_gdata = (struct st_data_s *)disc_data; 235 - unsigned long flags; 236 - 237 - if (st_gdata == NULL) { 238 - pr_err(" received null from TTY "); 239 - return; 240 - } 241 - 242 - pr_debug("count %zu rx_state %ld" 243 - "rx_count %ld", count, st_gdata->rx_state, 244 - st_gdata->rx_count); 245 - 246 - spin_lock_irqsave(&st_gdata->lock, flags); 247 - /* Decode received bytes here */ 248 - while (count) { 249 - if (st_gdata->rx_count) { 250 - len = min_t(unsigned int, st_gdata->rx_count, count); 251 - skb_put_data(st_gdata->rx_skb, ptr, len); 252 - st_gdata->rx_count -= len; 253 - count -= len; 254 - ptr += len; 255 - 256 - if (st_gdata->rx_count) 257 - continue; 258 - 259 - /* Check ST RX state machine , where are we? */ 260 - switch (st_gdata->rx_state) { 261 - /* Waiting for complete packet ? */ 262 - case ST_W4_DATA: 263 - pr_debug("Complete pkt received"); 264 - /* 265 - * Ask ST CORE to forward 266 - * the packet to protocol driver 267 - */ 268 - st_send_frame(st_gdata->rx_chnl, st_gdata); 269 - 270 - st_gdata->rx_state = ST_W4_PACKET_TYPE; 271 - st_gdata->rx_skb = NULL; 272 - continue; 273 - /* parse the header to know details */ 274 - case ST_W4_HEADER: 275 - proto = st_gdata->list[st_gdata->rx_chnl]; 276 - plen = 277 - &st_gdata->rx_skb->data 278 - [proto->offset_len_in_hdr]; 279 - pr_debug("plen pointing to %x\n", *plen); 280 - if (proto->len_size == 1) /* 1 byte len field */ 281 - payload_len = *(unsigned char *)plen; 282 - else if (proto->len_size == 2) 283 - payload_len = 284 - __le16_to_cpu(*(unsigned short *)plen); 285 - else 286 - pr_info("%s: invalid length " 287 - "for id %d\n", 288 - __func__, proto->chnl_id); 289 - st_check_data_len(st_gdata, proto->chnl_id, 290 - payload_len); 291 - pr_debug("off %d, pay len %d\n", 292 - proto->offset_len_in_hdr, payload_len); 293 - continue; 294 - } /* end of switch rx_state */ 295 - } 296 - 297 - /* end of if rx_count */ 298 - 299 - /* 300 - * Check first byte of packet and identify module 301 - * owner (BT/FM/GPS) 302 - */ 303 - switch (*ptr) { 304 - case LL_SLEEP_IND: 305 - case LL_SLEEP_ACK: 306 - case LL_WAKE_UP_IND: 307 - pr_debug("PM packet"); 308 - /* 309 - * this takes appropriate action based on 310 - * sleep state received -- 311 - */ 312 - st_ll_sleep_state(st_gdata, *ptr); 313 - /* 314 - * if WAKEUP_IND collides copy from waitq to txq 315 - * and assume chip awake 316 - */ 317 - spin_unlock_irqrestore(&st_gdata->lock, flags); 318 - if (st_ll_getstate(st_gdata) == ST_LL_AWAKE) 319 - st_wakeup_ack(st_gdata, LL_WAKE_UP_ACK); 320 - spin_lock_irqsave(&st_gdata->lock, flags); 321 - 322 - ptr++; 323 - count--; 324 - continue; 325 - case LL_WAKE_UP_ACK: 326 - pr_debug("PM packet"); 327 - 328 - spin_unlock_irqrestore(&st_gdata->lock, flags); 329 - /* wake up ack received */ 330 - st_wakeup_ack(st_gdata, *ptr); 331 - spin_lock_irqsave(&st_gdata->lock, flags); 332 - 333 - ptr++; 334 - count--; 335 - continue; 336 - /* Unknown packet? */ 337 - default: 338 - type = *ptr; 339 - 340 - /* 341 - * Default case means non-HCILL packets, 342 - * possibilities are packets for: 343 - * (a) valid protocol - Supported Protocols within 344 - * the ST_MAX_CHANNELS. 345 - * (b) registered protocol - Checked by 346 - * "st_gdata->list[type] == NULL)" are supported 347 - * protocols only. 348 - * Rules out any invalid protocol and 349 - * unregistered protocols with channel ID < 16. 350 - */ 351 - 352 - if ((type >= ST_MAX_CHANNELS) || 353 - (st_gdata->list[type] == NULL)) { 354 - pr_err("chip/interface misbehavior: " 355 - "dropping frame starting " 356 - "with 0x%02x\n", type); 357 - goto done; 358 - } 359 - 360 - st_gdata->rx_skb = alloc_skb( 361 - st_gdata->list[type]->max_frame_size, 362 - GFP_ATOMIC); 363 - if (st_gdata->rx_skb == NULL) { 364 - pr_err("out of memory: dropping\n"); 365 - goto done; 366 - } 367 - 368 - skb_reserve(st_gdata->rx_skb, 369 - st_gdata->list[type]->reserve); 370 - /* next 2 required for BT only */ 371 - st_gdata->rx_skb->cb[0] = type; /*pkt_type*/ 372 - st_gdata->rx_skb->cb[1] = 0; /*incoming*/ 373 - st_gdata->rx_chnl = *ptr; 374 - st_gdata->rx_state = ST_W4_HEADER; 375 - st_gdata->rx_count = st_gdata->list[type]->hdr_len; 376 - pr_debug("rx_count %ld\n", st_gdata->rx_count); 377 - } 378 - ptr++; 379 - count--; 380 - } 381 - done: 382 - spin_unlock_irqrestore(&st_gdata->lock, flags); 383 - pr_debug("done %s", __func__); 384 - return; 385 - } 386 - 387 - /* 388 - * st_int_dequeue - internal de-Q function. 389 - * If the previous data set was not written 390 - * completely, return that skb which has the pending data. 391 - * In normal cases, return top of txq. 392 - */ 393 - static struct sk_buff *st_int_dequeue(struct st_data_s *st_gdata) 394 - { 395 - struct sk_buff *returning_skb; 396 - 397 - pr_debug("%s", __func__); 398 - if (st_gdata->tx_skb != NULL) { 399 - returning_skb = st_gdata->tx_skb; 400 - st_gdata->tx_skb = NULL; 401 - return returning_skb; 402 - } 403 - return skb_dequeue(&st_gdata->txq); 404 - } 405 - 406 - /* 407 - * st_int_enqueue - internal Q-ing function. 408 - * Will either Q the skb to txq or the tx_waitq 409 - * depending on the ST LL state. 410 - * If the chip is asleep, then Q it onto waitq and 411 - * wakeup the chip. 412 - * txq and waitq needs protection since the other contexts 413 - * may be sending data, waking up chip. 414 - */ 415 - static void st_int_enqueue(struct st_data_s *st_gdata, struct sk_buff *skb) 416 - { 417 - unsigned long flags = 0; 418 - 419 - pr_debug("%s", __func__); 420 - spin_lock_irqsave(&st_gdata->lock, flags); 421 - 422 - switch (st_ll_getstate(st_gdata)) { 423 - case ST_LL_AWAKE: 424 - pr_debug("ST LL is AWAKE, sending normally"); 425 - skb_queue_tail(&st_gdata->txq, skb); 426 - break; 427 - case ST_LL_ASLEEP_TO_AWAKE: 428 - skb_queue_tail(&st_gdata->tx_waitq, skb); 429 - break; 430 - case ST_LL_AWAKE_TO_ASLEEP: 431 - pr_err("ST LL is illegal state(%ld)," 432 - "purging received skb.", st_ll_getstate(st_gdata)); 433 - dev_kfree_skb_irq(skb); 434 - break; 435 - case ST_LL_ASLEEP: 436 - skb_queue_tail(&st_gdata->tx_waitq, skb); 437 - st_ll_wakeup(st_gdata); 438 - break; 439 - default: 440 - pr_err("ST LL is illegal state(%ld)," 441 - "purging received skb.", st_ll_getstate(st_gdata)); 442 - dev_kfree_skb_irq(skb); 443 - break; 444 - } 445 - 446 - spin_unlock_irqrestore(&st_gdata->lock, flags); 447 - pr_debug("done %s", __func__); 448 - return; 449 - } 450 - 451 - /* 452 - * internal wakeup function 453 - * called from either 454 - * - TTY layer when write's finished 455 - * - st_write (in context of the protocol stack) 456 - */ 457 - static void work_fn_write_wakeup(struct work_struct *work) 458 - { 459 - struct st_data_s *st_gdata = container_of(work, struct st_data_s, 460 - work_write_wakeup); 461 - 462 - st_tx_wakeup((void *)st_gdata); 463 - } 464 - void st_tx_wakeup(struct st_data_s *st_data) 465 - { 466 - struct sk_buff *skb; 467 - unsigned long flags; /* for irq save flags */ 468 - pr_debug("%s", __func__); 469 - /* check for sending & set flag sending here */ 470 - if (test_and_set_bit(ST_TX_SENDING, &st_data->tx_state)) { 471 - pr_debug("ST already sending"); 472 - /* keep sending */ 473 - set_bit(ST_TX_WAKEUP, &st_data->tx_state); 474 - return; 475 - /* TX_WAKEUP will be checked in another 476 - * context 477 - */ 478 - } 479 - do { /* come back if st_tx_wakeup is set */ 480 - /* woke-up to write */ 481 - clear_bit(ST_TX_WAKEUP, &st_data->tx_state); 482 - while ((skb = st_int_dequeue(st_data))) { 483 - int len; 484 - spin_lock_irqsave(&st_data->lock, flags); 485 - /* enable wake-up from TTY */ 486 - set_bit(TTY_DO_WRITE_WAKEUP, &st_data->tty->flags); 487 - len = st_int_write(st_data, skb->data, skb->len); 488 - skb_pull(skb, len); 489 - /* if skb->len = len as expected, skb->len=0 */ 490 - if (skb->len) { 491 - /* would be the next skb to be sent */ 492 - st_data->tx_skb = skb; 493 - spin_unlock_irqrestore(&st_data->lock, flags); 494 - break; 495 - } 496 - dev_kfree_skb_irq(skb); 497 - spin_unlock_irqrestore(&st_data->lock, flags); 498 - } 499 - /* if wake-up is set in another context- restart sending */ 500 - } while (test_bit(ST_TX_WAKEUP, &st_data->tx_state)); 501 - 502 - /* clear flag sending */ 503 - clear_bit(ST_TX_SENDING, &st_data->tx_state); 504 - } 505 - 506 - /********************************************************************/ 507 - /* functions called from ST KIM 508 - */ 509 - void kim_st_list_protocols(struct st_data_s *st_gdata, void *buf) 510 - { 511 - seq_printf(buf, "[%d]\nBT=%c\nFM=%c\nGPS=%c\n", 512 - st_gdata->protos_registered, 513 - st_gdata->is_registered[0x04] == true ? 'R' : 'U', 514 - st_gdata->is_registered[0x08] == true ? 'R' : 'U', 515 - st_gdata->is_registered[0x09] == true ? 'R' : 'U'); 516 - } 517 - 518 - /********************************************************************/ 519 - /* 520 - * functions called from protocol stack drivers 521 - * to be EXPORT-ed 522 - */ 523 - long st_register(struct st_proto_s *new_proto) 524 - { 525 - struct st_data_s *st_gdata; 526 - long err = 0; 527 - unsigned long flags = 0; 528 - 529 - st_kim_ref(&st_gdata, 0); 530 - if (st_gdata == NULL || new_proto == NULL || new_proto->recv == NULL 531 - || new_proto->reg_complete_cb == NULL) { 532 - pr_err("gdata/new_proto/recv or reg_complete_cb not ready"); 533 - return -EINVAL; 534 - } 535 - 536 - if (new_proto->chnl_id >= ST_MAX_CHANNELS) { 537 - pr_err("chnl_id %d not supported", new_proto->chnl_id); 538 - return -EPROTONOSUPPORT; 539 - } 540 - 541 - if (st_gdata->is_registered[new_proto->chnl_id] == true) { 542 - pr_err("chnl_id %d already registered", new_proto->chnl_id); 543 - return -EALREADY; 544 - } 545 - 546 - /* can be from process context only */ 547 - spin_lock_irqsave(&st_gdata->lock, flags); 548 - 549 - if (test_bit(ST_REG_IN_PROGRESS, &st_gdata->st_state)) { 550 - pr_info(" ST_REG_IN_PROGRESS:%d ", new_proto->chnl_id); 551 - /* fw download in progress */ 552 - 553 - add_channel_to_table(st_gdata, new_proto); 554 - st_gdata->protos_registered++; 555 - new_proto->write = st_write; 556 - 557 - set_bit(ST_REG_PENDING, &st_gdata->st_state); 558 - spin_unlock_irqrestore(&st_gdata->lock, flags); 559 - return -EINPROGRESS; 560 - } else if (st_gdata->protos_registered == ST_EMPTY) { 561 - pr_info(" chnl_id list empty :%d ", new_proto->chnl_id); 562 - set_bit(ST_REG_IN_PROGRESS, &st_gdata->st_state); 563 - st_recv = st_kim_recv; 564 - 565 - /* enable the ST LL - to set default chip state */ 566 - st_ll_enable(st_gdata); 567 - 568 - /* release lock previously held - re-locked below */ 569 - spin_unlock_irqrestore(&st_gdata->lock, flags); 570 - 571 - /* 572 - * this may take a while to complete 573 - * since it involves BT fw download 574 - */ 575 - err = st_kim_start(st_gdata->kim_data); 576 - if (err != 0) { 577 - clear_bit(ST_REG_IN_PROGRESS, &st_gdata->st_state); 578 - if ((st_gdata->protos_registered != ST_EMPTY) && 579 - (test_bit(ST_REG_PENDING, &st_gdata->st_state))) { 580 - pr_err(" KIM failure complete callback "); 581 - spin_lock_irqsave(&st_gdata->lock, flags); 582 - st_reg_complete(st_gdata, err); 583 - spin_unlock_irqrestore(&st_gdata->lock, flags); 584 - clear_bit(ST_REG_PENDING, &st_gdata->st_state); 585 - } 586 - return -EINVAL; 587 - } 588 - 589 - spin_lock_irqsave(&st_gdata->lock, flags); 590 - 591 - clear_bit(ST_REG_IN_PROGRESS, &st_gdata->st_state); 592 - st_recv = st_int_recv; 593 - 594 - /* 595 - * this is where all pending registration 596 - * are signalled to be complete by calling callback functions 597 - */ 598 - if ((st_gdata->protos_registered != ST_EMPTY) && 599 - (test_bit(ST_REG_PENDING, &st_gdata->st_state))) { 600 - pr_debug(" call reg complete callback "); 601 - st_reg_complete(st_gdata, 0); 602 - } 603 - clear_bit(ST_REG_PENDING, &st_gdata->st_state); 604 - 605 - /* 606 - * check for already registered once more, 607 - * since the above check is old 608 - */ 609 - if (st_gdata->is_registered[new_proto->chnl_id] == true) { 610 - pr_err(" proto %d already registered ", 611 - new_proto->chnl_id); 612 - spin_unlock_irqrestore(&st_gdata->lock, flags); 613 - return -EALREADY; 614 - } 615 - 616 - add_channel_to_table(st_gdata, new_proto); 617 - st_gdata->protos_registered++; 618 - new_proto->write = st_write; 619 - spin_unlock_irqrestore(&st_gdata->lock, flags); 620 - return err; 621 - } 622 - /* if fw is already downloaded & new stack registers protocol */ 623 - else { 624 - add_channel_to_table(st_gdata, new_proto); 625 - st_gdata->protos_registered++; 626 - new_proto->write = st_write; 627 - 628 - /* lock already held before entering else */ 629 - spin_unlock_irqrestore(&st_gdata->lock, flags); 630 - return err; 631 - } 632 - } 633 - EXPORT_SYMBOL_GPL(st_register); 634 - 635 - /* 636 - * to unregister a protocol - 637 - * to be called from protocol stack driver 638 - */ 639 - long st_unregister(struct st_proto_s *proto) 640 - { 641 - long err = 0; 642 - unsigned long flags = 0; 643 - struct st_data_s *st_gdata; 644 - 645 - pr_debug("%s: %d ", __func__, proto->chnl_id); 646 - 647 - st_kim_ref(&st_gdata, 0); 648 - if (!st_gdata || proto->chnl_id >= ST_MAX_CHANNELS) { 649 - pr_err(" chnl_id %d not supported", proto->chnl_id); 650 - return -EPROTONOSUPPORT; 651 - } 652 - 653 - spin_lock_irqsave(&st_gdata->lock, flags); 654 - 655 - if (st_gdata->is_registered[proto->chnl_id] == false) { 656 - pr_err(" chnl_id %d not registered", proto->chnl_id); 657 - spin_unlock_irqrestore(&st_gdata->lock, flags); 658 - return -EPROTONOSUPPORT; 659 - } 660 - 661 - if (st_gdata->protos_registered) 662 - st_gdata->protos_registered--; 663 - 664 - remove_channel_from_table(st_gdata, proto); 665 - spin_unlock_irqrestore(&st_gdata->lock, flags); 666 - 667 - if ((st_gdata->protos_registered == ST_EMPTY) && 668 - (!test_bit(ST_REG_PENDING, &st_gdata->st_state))) { 669 - pr_info(" all chnl_ids unregistered "); 670 - 671 - /* stop traffic on tty */ 672 - if (st_gdata->tty) { 673 - tty_ldisc_flush(st_gdata->tty); 674 - stop_tty(st_gdata->tty); 675 - } 676 - 677 - /* all chnl_ids now unregistered */ 678 - st_kim_stop(st_gdata->kim_data); 679 - /* disable ST LL */ 680 - st_ll_disable(st_gdata); 681 - } 682 - return err; 683 - } 684 - 685 - /* 686 - * called in protocol stack drivers 687 - * via the write function pointer 688 - */ 689 - long st_write(struct sk_buff *skb) 690 - { 691 - struct st_data_s *st_gdata; 692 - long len; 693 - 694 - st_kim_ref(&st_gdata, 0); 695 - if (unlikely(skb == NULL || st_gdata == NULL 696 - || st_gdata->tty == NULL)) { 697 - pr_err("data/tty unavailable to perform write"); 698 - return -EINVAL; 699 - } 700 - 701 - pr_debug("%d to be written", skb->len); 702 - len = skb->len; 703 - 704 - /* st_ll to decide where to enqueue the skb */ 705 - st_int_enqueue(st_gdata, skb); 706 - /* wake up */ 707 - st_tx_wakeup(st_gdata); 708 - 709 - /* return number of bytes written */ 710 - return len; 711 - } 712 - 713 - /* for protocols making use of shared transport */ 714 - EXPORT_SYMBOL_GPL(st_unregister); 715 - 716 - /********************************************************************/ 717 - /* 718 - * functions called from TTY layer 719 - */ 720 - static int st_tty_open(struct tty_struct *tty) 721 - { 722 - struct st_data_s *st_gdata; 723 - pr_info("%s ", __func__); 724 - 725 - st_kim_ref(&st_gdata, 0); 726 - st_gdata->tty = tty; 727 - tty->disc_data = st_gdata; 728 - 729 - /* don't do an wakeup for now */ 730 - clear_bit(TTY_DO_WRITE_WAKEUP, &tty->flags); 731 - 732 - /* mem already allocated 733 - */ 734 - tty->receive_room = 65536; 735 - /* Flush any pending characters in the driver and discipline. */ 736 - tty_ldisc_flush(tty); 737 - tty_driver_flush_buffer(tty); 738 - /* 739 - * signal to UIM via KIM that - 740 - * installation of N_TI_WL ldisc is complete 741 - */ 742 - st_kim_complete(st_gdata->kim_data); 743 - pr_debug("done %s", __func__); 744 - 745 - return 0; 746 - } 747 - 748 - static void st_tty_close(struct tty_struct *tty) 749 - { 750 - unsigned char i; 751 - unsigned long flags; 752 - struct st_data_s *st_gdata = tty->disc_data; 753 - 754 - pr_info("%s ", __func__); 755 - 756 - /* 757 - * TODO: 758 - * if a protocol has been registered & line discipline 759 - * un-installed for some reason - what should be done ? 760 - */ 761 - spin_lock_irqsave(&st_gdata->lock, flags); 762 - for (i = ST_BT; i < ST_MAX_CHANNELS; i++) { 763 - if (st_gdata->is_registered[i] == true) 764 - pr_err("%d not un-registered", i); 765 - st_gdata->list[i] = NULL; 766 - st_gdata->is_registered[i] = false; 767 - } 768 - st_gdata->protos_registered = 0; 769 - spin_unlock_irqrestore(&st_gdata->lock, flags); 770 - /* 771 - * signal to UIM via KIM that - 772 - * N_TI_WL ldisc is un-installed 773 - */ 774 - st_kim_complete(st_gdata->kim_data); 775 - st_gdata->tty = NULL; 776 - /* Flush any pending characters in the driver and discipline. */ 777 - tty_ldisc_flush(tty); 778 - tty_driver_flush_buffer(tty); 779 - 780 - spin_lock_irqsave(&st_gdata->lock, flags); 781 - /* empty out txq and tx_waitq */ 782 - skb_queue_purge(&st_gdata->txq); 783 - skb_queue_purge(&st_gdata->tx_waitq); 784 - /* reset the TTY Rx states of ST */ 785 - st_gdata->rx_count = 0; 786 - st_gdata->rx_state = ST_W4_PACKET_TYPE; 787 - kfree_skb(st_gdata->rx_skb); 788 - st_gdata->rx_skb = NULL; 789 - spin_unlock_irqrestore(&st_gdata->lock, flags); 790 - 791 - pr_debug("%s: done ", __func__); 792 - } 793 - 794 - static void st_tty_receive(struct tty_struct *tty, const u8 *data, 795 - const u8 *tty_flags, size_t count) 796 - { 797 - #ifdef VERBOSE 798 - print_hex_dump(KERN_DEBUG, ">in>", DUMP_PREFIX_NONE, 799 - 16, 1, data, count, 0); 800 - #endif 801 - 802 - /* 803 - * if fw download is in progress then route incoming data 804 - * to KIM for validation 805 - */ 806 - st_recv(tty->disc_data, data, count); 807 - pr_debug("done %s", __func__); 808 - } 809 - 810 - /* 811 - * wake-up function called in from the TTY layer 812 - * inside the internal wakeup function will be called 813 - */ 814 - static void st_tty_wakeup(struct tty_struct *tty) 815 - { 816 - struct st_data_s *st_gdata = tty->disc_data; 817 - pr_debug("%s ", __func__); 818 - /* don't do an wakeup for now */ 819 - clear_bit(TTY_DO_WRITE_WAKEUP, &tty->flags); 820 - 821 - /* 822 - * schedule the internal wakeup instead of calling directly to 823 - * avoid lockup (port->lock needed in tty->ops->write is 824 - * already taken here 825 - */ 826 - schedule_work(&st_gdata->work_write_wakeup); 827 - } 828 - 829 - static void st_tty_flush_buffer(struct tty_struct *tty) 830 - { 831 - struct st_data_s *st_gdata = tty->disc_data; 832 - pr_debug("%s ", __func__); 833 - 834 - kfree_skb(st_gdata->tx_skb); 835 - st_gdata->tx_skb = NULL; 836 - 837 - tty_driver_flush_buffer(tty); 838 - return; 839 - } 840 - 841 - static struct tty_ldisc_ops st_ldisc_ops = { 842 - .num = N_TI_WL, 843 - .name = "n_st", 844 - .open = st_tty_open, 845 - .close = st_tty_close, 846 - .receive_buf = st_tty_receive, 847 - .write_wakeup = st_tty_wakeup, 848 - .flush_buffer = st_tty_flush_buffer, 849 - .owner = THIS_MODULE 850 - }; 851 - 852 - /********************************************************************/ 853 - int st_core_init(struct st_data_s **core_data) 854 - { 855 - struct st_data_s *st_gdata; 856 - long err; 857 - 858 - err = tty_register_ldisc(&st_ldisc_ops); 859 - if (err) { 860 - pr_err("error registering %d line discipline %ld", 861 - N_TI_WL, err); 862 - return err; 863 - } 864 - pr_debug("registered n_shared line discipline"); 865 - 866 - st_gdata = kzalloc(sizeof(struct st_data_s), GFP_KERNEL); 867 - if (!st_gdata) { 868 - pr_err("memory allocation failed"); 869 - err = -ENOMEM; 870 - goto err_unreg_ldisc; 871 - } 872 - 873 - /* Initialize ST TxQ and Tx waitQ queue head. All BT/FM/GPS module skb's 874 - * will be pushed in this queue for actual transmission. 875 - */ 876 - skb_queue_head_init(&st_gdata->txq); 877 - skb_queue_head_init(&st_gdata->tx_waitq); 878 - 879 - /* Locking used in st_int_enqueue() to avoid multiple execution */ 880 - spin_lock_init(&st_gdata->lock); 881 - 882 - err = st_ll_init(st_gdata); 883 - if (err) { 884 - pr_err("error during st_ll initialization(%ld)", err); 885 - goto err_free_gdata; 886 - } 887 - 888 - INIT_WORK(&st_gdata->work_write_wakeup, work_fn_write_wakeup); 889 - 890 - *core_data = st_gdata; 891 - return 0; 892 - err_free_gdata: 893 - kfree(st_gdata); 894 - err_unreg_ldisc: 895 - tty_unregister_ldisc(&st_ldisc_ops); 896 - return err; 897 - } 898 - 899 - void st_core_exit(struct st_data_s *st_gdata) 900 - { 901 - long err; 902 - /* internal module cleanup */ 903 - err = st_ll_deinit(st_gdata); 904 - if (err) 905 - pr_err("error during deinit of ST LL %ld", err); 906 - 907 - if (st_gdata != NULL) { 908 - /* Free ST Tx Qs and skbs */ 909 - skb_queue_purge(&st_gdata->txq); 910 - skb_queue_purge(&st_gdata->tx_waitq); 911 - kfree_skb(st_gdata->rx_skb); 912 - kfree_skb(st_gdata->tx_skb); 913 - /* TTY ldisc cleanup */ 914 - tty_unregister_ldisc(&st_ldisc_ops); 915 - /* free the global data pointer */ 916 - kfree(st_gdata); 917 - } 918 - }
-839
drivers/misc/ti-st/st_kim.c
··· 1 - // SPDX-License-Identifier: GPL-2.0-only 2 - /* 3 - * Shared Transport Line discipline driver Core 4 - * Init Manager module responsible for GPIO control 5 - * and firmware download 6 - * Copyright (C) 2009-2010 Texas Instruments 7 - * Author: Pavan Savoy <pavan_savoy@ti.com> 8 - */ 9 - 10 - #define pr_fmt(fmt) "(stk) :" fmt 11 - #include <linux/platform_device.h> 12 - #include <linux/jiffies.h> 13 - #include <linux/firmware.h> 14 - #include <linux/delay.h> 15 - #include <linux/wait.h> 16 - #include <linux/gpio.h> 17 - #include <linux/debugfs.h> 18 - #include <linux/seq_file.h> 19 - #include <linux/sched.h> 20 - #include <linux/sysfs.h> 21 - #include <linux/tty.h> 22 - 23 - #include <linux/skbuff.h> 24 - #include <linux/ti_wilink_st.h> 25 - #include <linux/module.h> 26 - 27 - #define MAX_ST_DEVICES 3 /* Imagine 1 on each UART for now */ 28 - static struct platform_device *st_kim_devices[MAX_ST_DEVICES]; 29 - 30 - /**********************************************************************/ 31 - /* internal functions */ 32 - 33 - /* 34 - * st_get_plat_device - 35 - * function which returns the reference to the platform device 36 - * requested by id. As of now only 1 such device exists (id=0) 37 - * the context requesting for reference can get the id to be 38 - * requested by a. The protocol driver which is registering or 39 - * b. the tty device which is opened. 40 - */ 41 - static struct platform_device *st_get_plat_device(int id) 42 - { 43 - return st_kim_devices[id]; 44 - } 45 - 46 - /* 47 - * validate_firmware_response - 48 - * function to return whether the firmware response was proper 49 - * in case of error don't complete so that waiting for proper 50 - * response times out 51 - */ 52 - static void validate_firmware_response(struct kim_data_s *kim_gdata) 53 - { 54 - struct sk_buff *skb = kim_gdata->rx_skb; 55 - if (!skb) 56 - return; 57 - 58 - /* 59 - * these magic numbers are the position in the response buffer which 60 - * allows us to distinguish whether the response is for the read 61 - * version info. command 62 - */ 63 - if (skb->data[2] == 0x01 && skb->data[3] == 0x01 && 64 - skb->data[4] == 0x10 && skb->data[5] == 0x00) { 65 - /* fw version response */ 66 - memcpy(kim_gdata->resp_buffer, 67 - kim_gdata->rx_skb->data, 68 - kim_gdata->rx_skb->len); 69 - kim_gdata->rx_state = ST_W4_PACKET_TYPE; 70 - kim_gdata->rx_skb = NULL; 71 - kim_gdata->rx_count = 0; 72 - } else if (unlikely(skb->data[5] != 0)) { 73 - pr_err("no proper response during fw download"); 74 - pr_err("data6 %x", skb->data[5]); 75 - kfree_skb(skb); 76 - return; /* keep waiting for the proper response */ 77 - } 78 - /* becos of all the script being downloaded */ 79 - complete_all(&kim_gdata->kim_rcvd); 80 - kfree_skb(skb); 81 - } 82 - 83 - /* 84 - * check for data len received inside kim_int_recv 85 - * most often hit the last case to update state to waiting for data 86 - */ 87 - static inline int kim_check_data_len(struct kim_data_s *kim_gdata, int len) 88 - { 89 - register int room = skb_tailroom(kim_gdata->rx_skb); 90 - 91 - pr_debug("len %d room %d", len, room); 92 - 93 - if (!len) { 94 - validate_firmware_response(kim_gdata); 95 - } else if (len > room) { 96 - /* 97 - * Received packet's payload length is larger. 98 - * We can't accommodate it in created skb. 99 - */ 100 - pr_err("Data length is too large len %d room %d", len, 101 - room); 102 - kfree_skb(kim_gdata->rx_skb); 103 - } else { 104 - /* 105 - * Packet header has non-zero payload length and 106 - * we have enough space in created skb. Lets read 107 - * payload data */ 108 - kim_gdata->rx_state = ST_W4_DATA; 109 - kim_gdata->rx_count = len; 110 - return len; 111 - } 112 - 113 - /* 114 - * Change ST LL state to continue to process next 115 - * packet 116 - */ 117 - kim_gdata->rx_state = ST_W4_PACKET_TYPE; 118 - kim_gdata->rx_skb = NULL; 119 - kim_gdata->rx_count = 0; 120 - 121 - return 0; 122 - } 123 - 124 - /* 125 - * kim_int_recv - receive function called during firmware download 126 - * firmware download responses on different UART drivers 127 - * have been observed to come in bursts of different 128 - * tty_receive and hence the logic 129 - */ 130 - static void kim_int_recv(struct kim_data_s *kim_gdata, const u8 *ptr, 131 - size_t count) 132 - { 133 - int len = 0; 134 - unsigned char *plen; 135 - 136 - pr_debug("%s", __func__); 137 - /* Decode received bytes here */ 138 - while (count) { 139 - if (kim_gdata->rx_count) { 140 - len = min_t(unsigned int, kim_gdata->rx_count, count); 141 - skb_put_data(kim_gdata->rx_skb, ptr, len); 142 - kim_gdata->rx_count -= len; 143 - count -= len; 144 - ptr += len; 145 - 146 - if (kim_gdata->rx_count) 147 - continue; 148 - 149 - /* Check ST RX state machine , where are we? */ 150 - switch (kim_gdata->rx_state) { 151 - /* Waiting for complete packet ? */ 152 - case ST_W4_DATA: 153 - pr_debug("Complete pkt received"); 154 - validate_firmware_response(kim_gdata); 155 - kim_gdata->rx_state = ST_W4_PACKET_TYPE; 156 - kim_gdata->rx_skb = NULL; 157 - continue; 158 - /* Waiting for Bluetooth event header ? */ 159 - case ST_W4_HEADER: 160 - plen = 161 - (unsigned char *)&kim_gdata->rx_skb->data[1]; 162 - pr_debug("event hdr: plen 0x%02x\n", *plen); 163 - kim_check_data_len(kim_gdata, *plen); 164 - continue; 165 - } /* end of switch */ 166 - } /* end of if rx_state */ 167 - switch (*ptr) { 168 - /* Bluetooth event packet? */ 169 - case 0x04: 170 - kim_gdata->rx_state = ST_W4_HEADER; 171 - kim_gdata->rx_count = 2; 172 - break; 173 - default: 174 - pr_info("unknown packet"); 175 - ptr++; 176 - count--; 177 - continue; 178 - } 179 - ptr++; 180 - count--; 181 - kim_gdata->rx_skb = 182 - alloc_skb(1024+8, GFP_ATOMIC); 183 - if (!kim_gdata->rx_skb) { 184 - pr_err("can't allocate mem for new packet"); 185 - kim_gdata->rx_state = ST_W4_PACKET_TYPE; 186 - kim_gdata->rx_count = 0; 187 - return; 188 - } 189 - skb_reserve(kim_gdata->rx_skb, 8); 190 - kim_gdata->rx_skb->cb[0] = 4; 191 - kim_gdata->rx_skb->cb[1] = 0; 192 - 193 - } 194 - return; 195 - } 196 - 197 - static long read_local_version(struct kim_data_s *kim_gdata, char *bts_scr_name) 198 - { 199 - unsigned short version = 0, chip = 0, min_ver = 0, maj_ver = 0; 200 - static const char read_ver_cmd[] = { 0x01, 0x01, 0x10, 0x00 }; 201 - long time_left; 202 - 203 - pr_debug("%s", __func__); 204 - 205 - reinit_completion(&kim_gdata->kim_rcvd); 206 - if (4 != st_int_write(kim_gdata->core_data, read_ver_cmd, 4)) { 207 - pr_err("kim: couldn't write 4 bytes"); 208 - return -EIO; 209 - } 210 - 211 - time_left = wait_for_completion_interruptible_timeout( 212 - &kim_gdata->kim_rcvd, msecs_to_jiffies(CMD_RESP_TIME)); 213 - if (time_left <= 0) { 214 - pr_err(" waiting for ver info- timed out or received signal"); 215 - return time_left ? -ERESTARTSYS : -ETIMEDOUT; 216 - } 217 - reinit_completion(&kim_gdata->kim_rcvd); 218 - /* 219 - * the positions 12 & 13 in the response buffer provide with the 220 - * chip, major & minor numbers 221 - */ 222 - 223 - version = 224 - MAKEWORD(kim_gdata->resp_buffer[12], 225 - kim_gdata->resp_buffer[13]); 226 - chip = (version & 0x7C00) >> 10; 227 - min_ver = (version & 0x007F); 228 - maj_ver = (version & 0x0380) >> 7; 229 - 230 - if (version & 0x8000) 231 - maj_ver |= 0x0008; 232 - 233 - sprintf(bts_scr_name, "ti-connectivity/TIInit_%d.%d.%d.bts", 234 - chip, maj_ver, min_ver); 235 - 236 - /* to be accessed later via sysfs entry */ 237 - kim_gdata->version.full = version; 238 - kim_gdata->version.chip = chip; 239 - kim_gdata->version.maj_ver = maj_ver; 240 - kim_gdata->version.min_ver = min_ver; 241 - 242 - pr_info("%s", bts_scr_name); 243 - return 0; 244 - } 245 - 246 - static void skip_change_remote_baud(unsigned char **ptr, long *len) 247 - { 248 - unsigned char *nxt_action, *cur_action; 249 - cur_action = *ptr; 250 - 251 - nxt_action = cur_action + sizeof(struct bts_action) + 252 - ((struct bts_action *) cur_action)->size; 253 - 254 - if (((struct bts_action *) nxt_action)->type != ACTION_WAIT_EVENT) { 255 - pr_err("invalid action after change remote baud command"); 256 - } else { 257 - *ptr = *ptr + sizeof(struct bts_action) + 258 - ((struct bts_action *)cur_action)->size; 259 - *len = *len - (sizeof(struct bts_action) + 260 - ((struct bts_action *)cur_action)->size); 261 - /* warn user on not commenting these in firmware */ 262 - pr_warn("skipping the wait event of change remote baud"); 263 - } 264 - } 265 - 266 - /* 267 - * download_firmware - 268 - * internal function which parses through the .bts firmware 269 - * script file intreprets SEND, DELAY actions only as of now 270 - */ 271 - static long download_firmware(struct kim_data_s *kim_gdata) 272 - { 273 - long err = 0; 274 - long len = 0; 275 - unsigned char *ptr = NULL; 276 - unsigned char *action_ptr = NULL; 277 - unsigned char bts_scr_name[40] = { 0 }; /* 40 char long bts scr name? */ 278 - int wr_room_space; 279 - int cmd_size; 280 - unsigned long timeout; 281 - 282 - err = read_local_version(kim_gdata, bts_scr_name); 283 - if (err != 0) { 284 - pr_err("kim: failed to read local ver"); 285 - return err; 286 - } 287 - err = 288 - request_firmware(&kim_gdata->fw_entry, bts_scr_name, 289 - &kim_gdata->kim_pdev->dev); 290 - if (unlikely((err != 0) || (kim_gdata->fw_entry->data == NULL) || 291 - (kim_gdata->fw_entry->size == 0))) { 292 - pr_err(" request_firmware failed(errno %ld) for %s", err, 293 - bts_scr_name); 294 - return -EINVAL; 295 - } 296 - ptr = (void *)kim_gdata->fw_entry->data; 297 - len = kim_gdata->fw_entry->size; 298 - /* 299 - * bts_header to remove out magic number and 300 - * version 301 - */ 302 - ptr += sizeof(struct bts_header); 303 - len -= sizeof(struct bts_header); 304 - 305 - while (len > 0 && ptr) { 306 - pr_debug(" action size %d, type %d ", 307 - ((struct bts_action *)ptr)->size, 308 - ((struct bts_action *)ptr)->type); 309 - 310 - switch (((struct bts_action *)ptr)->type) { 311 - case ACTION_SEND_COMMAND: /* action send */ 312 - pr_debug("S"); 313 - action_ptr = &(((struct bts_action *)ptr)->data[0]); 314 - if (unlikely 315 - (((struct hci_command *)action_ptr)->opcode == 316 - 0xFF36)) { 317 - /* 318 - * ignore remote change 319 - * baud rate HCI VS command 320 - */ 321 - pr_warn("change remote baud" 322 - " rate command in firmware"); 323 - skip_change_remote_baud(&ptr, &len); 324 - break; 325 - } 326 - /* 327 - * Make sure we have enough free space in uart 328 - * tx buffer to write current firmware command 329 - */ 330 - cmd_size = ((struct bts_action *)ptr)->size; 331 - timeout = jiffies + msecs_to_jiffies(CMD_WR_TIME); 332 - do { 333 - wr_room_space = 334 - st_get_uart_wr_room(kim_gdata->core_data); 335 - if (wr_room_space < 0) { 336 - pr_err("Unable to get free " 337 - "space info from uart tx buffer"); 338 - release_firmware(kim_gdata->fw_entry); 339 - return wr_room_space; 340 - } 341 - mdelay(1); /* wait 1ms before checking room */ 342 - } while ((wr_room_space < cmd_size) && 343 - time_before(jiffies, timeout)); 344 - 345 - /* Timeout happened ? */ 346 - if (time_after_eq(jiffies, timeout)) { 347 - pr_err("Timeout while waiting for free " 348 - "free space in uart tx buffer"); 349 - release_firmware(kim_gdata->fw_entry); 350 - return -ETIMEDOUT; 351 - } 352 - /* 353 - * reinit completion before sending for the 354 - * relevant wait 355 - */ 356 - reinit_completion(&kim_gdata->kim_rcvd); 357 - 358 - /* 359 - * Free space found in uart buffer, call st_int_write 360 - * to send current firmware command to the uart tx 361 - * buffer. 362 - */ 363 - err = st_int_write(kim_gdata->core_data, 364 - ((struct bts_action_send *)action_ptr)->data, 365 - ((struct bts_action *)ptr)->size); 366 - if (unlikely(err < 0)) { 367 - release_firmware(kim_gdata->fw_entry); 368 - return err; 369 - } 370 - /* 371 - * Check number of bytes written to the uart tx buffer 372 - * and requested command write size 373 - */ 374 - if (err != cmd_size) { 375 - pr_err("Number of bytes written to uart " 376 - "tx buffer are not matching with " 377 - "requested cmd write size"); 378 - release_firmware(kim_gdata->fw_entry); 379 - return -EIO; 380 - } 381 - break; 382 - case ACTION_WAIT_EVENT: /* wait */ 383 - pr_debug("W"); 384 - err = wait_for_completion_interruptible_timeout( 385 - &kim_gdata->kim_rcvd, 386 - msecs_to_jiffies(CMD_RESP_TIME)); 387 - if (err <= 0) { 388 - pr_err("response timeout/signaled during fw download "); 389 - /* timed out */ 390 - release_firmware(kim_gdata->fw_entry); 391 - return err ? -ERESTARTSYS : -ETIMEDOUT; 392 - } 393 - reinit_completion(&kim_gdata->kim_rcvd); 394 - break; 395 - case ACTION_DELAY: /* sleep */ 396 - pr_info("sleep command in scr"); 397 - action_ptr = &(((struct bts_action *)ptr)->data[0]); 398 - mdelay(((struct bts_action_delay *)action_ptr)->msec); 399 - break; 400 - } 401 - len = 402 - len - (sizeof(struct bts_action) + 403 - ((struct bts_action *)ptr)->size); 404 - ptr = 405 - ptr + sizeof(struct bts_action) + 406 - ((struct bts_action *)ptr)->size; 407 - } 408 - /* fw download complete */ 409 - release_firmware(kim_gdata->fw_entry); 410 - return 0; 411 - } 412 - 413 - /**********************************************************************/ 414 - /* functions called from ST core */ 415 - /* called from ST Core, when REG_IN_PROGRESS (registration in progress) 416 - * can be because of 417 - * 1. response to read local version 418 - * 2. during send/recv's of firmware download 419 - */ 420 - void st_kim_recv(void *disc_data, const u8 *data, size_t count) 421 - { 422 - struct st_data_s *st_gdata = (struct st_data_s *)disc_data; 423 - struct kim_data_s *kim_gdata = st_gdata->kim_data; 424 - 425 - /* 426 - * proceed to gather all data and distinguish read fw version response 427 - * from other fw responses when data gathering is complete 428 - */ 429 - kim_int_recv(kim_gdata, data, count); 430 - return; 431 - } 432 - 433 - /* 434 - * to signal completion of line discipline installation 435 - * called from ST Core, upon tty_open 436 - */ 437 - void st_kim_complete(void *kim_data) 438 - { 439 - struct kim_data_s *kim_gdata = (struct kim_data_s *)kim_data; 440 - complete(&kim_gdata->ldisc_installed); 441 - } 442 - 443 - /* 444 - * st_kim_start - called from ST Core upon 1st registration 445 - * This involves toggling the chip enable gpio, reading 446 - * the firmware version from chip, forming the fw file name 447 - * based on the chip version, requesting the fw, parsing it 448 - * and perform download(send/recv). 449 - */ 450 - long st_kim_start(void *kim_data) 451 - { 452 - long err = 0; 453 - long retry = POR_RETRY_COUNT; 454 - struct ti_st_plat_data *pdata; 455 - struct kim_data_s *kim_gdata = (struct kim_data_s *)kim_data; 456 - 457 - pr_info(" %s", __func__); 458 - pdata = kim_gdata->kim_pdev->dev.platform_data; 459 - 460 - do { 461 - /* platform specific enabling code here */ 462 - if (pdata->chip_enable) 463 - pdata->chip_enable(kim_gdata); 464 - 465 - /* Configure BT nShutdown to HIGH state */ 466 - gpio_set_value_cansleep(kim_gdata->nshutdown, GPIO_LOW); 467 - mdelay(5); /* FIXME: a proper toggle */ 468 - gpio_set_value_cansleep(kim_gdata->nshutdown, GPIO_HIGH); 469 - mdelay(100); 470 - /* re-initialize the completion */ 471 - reinit_completion(&kim_gdata->ldisc_installed); 472 - /* send notification to UIM */ 473 - kim_gdata->ldisc_install = 1; 474 - pr_info("ldisc_install = 1"); 475 - sysfs_notify(&kim_gdata->kim_pdev->dev.kobj, 476 - NULL, "install"); 477 - /* wait for ldisc to be installed */ 478 - err = wait_for_completion_interruptible_timeout( 479 - &kim_gdata->ldisc_installed, msecs_to_jiffies(LDISC_TIME)); 480 - if (!err) { 481 - /* 482 - * ldisc installation timeout, 483 - * flush uart, power cycle BT_EN 484 - */ 485 - pr_err("ldisc installation timeout"); 486 - err = st_kim_stop(kim_gdata); 487 - continue; 488 - } else { 489 - /* ldisc installed now */ 490 - pr_info("line discipline installed"); 491 - err = download_firmware(kim_gdata); 492 - if (err != 0) { 493 - /* 494 - * ldisc installed but fw download failed, 495 - * flush uart & power cycle BT_EN 496 - */ 497 - pr_err("download firmware failed"); 498 - err = st_kim_stop(kim_gdata); 499 - continue; 500 - } else { /* on success don't retry */ 501 - break; 502 - } 503 - } 504 - } while (retry--); 505 - return err; 506 - } 507 - 508 - /* 509 - * st_kim_stop - stop communication with chip. 510 - * This can be called from ST Core/KIM, on the- 511 - * (a) last un-register when chip need not be powered there-after, 512 - * (b) upon failure to either install ldisc or download firmware. 513 - * The function is responsible to (a) notify UIM about un-installation, 514 - * (b) flush UART if the ldisc was installed. 515 - * (c) reset BT_EN - pull down nshutdown at the end. 516 - * (d) invoke platform's chip disabling routine. 517 - */ 518 - long st_kim_stop(void *kim_data) 519 - { 520 - long err = 0; 521 - struct kim_data_s *kim_gdata = (struct kim_data_s *)kim_data; 522 - struct ti_st_plat_data *pdata = 523 - kim_gdata->kim_pdev->dev.platform_data; 524 - struct tty_struct *tty = kim_gdata->core_data->tty; 525 - 526 - reinit_completion(&kim_gdata->ldisc_installed); 527 - 528 - if (tty) { /* can be called before ldisc is installed */ 529 - /* Flush any pending characters in the driver and discipline. */ 530 - tty_ldisc_flush(tty); 531 - tty_driver_flush_buffer(tty); 532 - } 533 - 534 - /* send uninstall notification to UIM */ 535 - pr_info("ldisc_install = 0"); 536 - kim_gdata->ldisc_install = 0; 537 - sysfs_notify(&kim_gdata->kim_pdev->dev.kobj, NULL, "install"); 538 - 539 - /* wait for ldisc to be un-installed */ 540 - err = wait_for_completion_interruptible_timeout( 541 - &kim_gdata->ldisc_installed, msecs_to_jiffies(LDISC_TIME)); 542 - if (!err) { /* timeout */ 543 - pr_err(" timed out waiting for ldisc to be un-installed"); 544 - err = -ETIMEDOUT; 545 - } 546 - 547 - /* By default configure BT nShutdown to LOW state */ 548 - gpio_set_value_cansleep(kim_gdata->nshutdown, GPIO_LOW); 549 - mdelay(1); 550 - gpio_set_value_cansleep(kim_gdata->nshutdown, GPIO_HIGH); 551 - mdelay(1); 552 - gpio_set_value_cansleep(kim_gdata->nshutdown, GPIO_LOW); 553 - 554 - /* platform specific disable */ 555 - if (pdata->chip_disable) 556 - pdata->chip_disable(kim_gdata); 557 - return err; 558 - } 559 - 560 - /**********************************************************************/ 561 - /* functions called from subsystems */ 562 - /* called when debugfs entry is read from */ 563 - 564 - static int version_show(struct seq_file *s, void *unused) 565 - { 566 - struct kim_data_s *kim_gdata = s->private; 567 - seq_printf(s, "%04X %d.%d.%d\n", kim_gdata->version.full, 568 - kim_gdata->version.chip, kim_gdata->version.maj_ver, 569 - kim_gdata->version.min_ver); 570 - return 0; 571 - } 572 - 573 - static int list_show(struct seq_file *s, void *unused) 574 - { 575 - struct kim_data_s *kim_gdata = s->private; 576 - kim_st_list_protocols(kim_gdata->core_data, s); 577 - return 0; 578 - } 579 - 580 - static ssize_t show_install(struct device *dev, 581 - struct device_attribute *attr, char *buf) 582 - { 583 - struct kim_data_s *kim_data = dev_get_drvdata(dev); 584 - return sprintf(buf, "%d\n", kim_data->ldisc_install); 585 - } 586 - 587 - #ifdef DEBUG 588 - static ssize_t store_dev_name(struct device *dev, 589 - struct device_attribute *attr, const char *buf, size_t count) 590 - { 591 - struct kim_data_s *kim_data = dev_get_drvdata(dev); 592 - pr_debug("storing dev name >%s<", buf); 593 - strscpy(kim_data->dev_name, buf, sizeof(kim_data->dev_name)); 594 - pr_debug("stored dev name >%s<", kim_data->dev_name); 595 - return count; 596 - } 597 - 598 - static ssize_t store_baud_rate(struct device *dev, 599 - struct device_attribute *attr, const char *buf, size_t count) 600 - { 601 - struct kim_data_s *kim_data = dev_get_drvdata(dev); 602 - pr_debug("storing baud rate >%s<", buf); 603 - sscanf(buf, "%ld", &kim_data->baud_rate); 604 - pr_debug("stored baud rate >%ld<", kim_data->baud_rate); 605 - return count; 606 - } 607 - #endif /* if DEBUG */ 608 - 609 - static ssize_t show_dev_name(struct device *dev, 610 - struct device_attribute *attr, char *buf) 611 - { 612 - struct kim_data_s *kim_data = dev_get_drvdata(dev); 613 - return sprintf(buf, "%s\n", kim_data->dev_name); 614 - } 615 - 616 - static ssize_t show_baud_rate(struct device *dev, 617 - struct device_attribute *attr, char *buf) 618 - { 619 - struct kim_data_s *kim_data = dev_get_drvdata(dev); 620 - return sprintf(buf, "%d\n", kim_data->baud_rate); 621 - } 622 - 623 - static ssize_t show_flow_cntrl(struct device *dev, 624 - struct device_attribute *attr, char *buf) 625 - { 626 - struct kim_data_s *kim_data = dev_get_drvdata(dev); 627 - return sprintf(buf, "%d\n", kim_data->flow_cntrl); 628 - } 629 - 630 - /* structures specific for sysfs entries */ 631 - static struct kobj_attribute ldisc_install = 632 - __ATTR(install, 0444, (void *)show_install, NULL); 633 - 634 - static struct kobj_attribute uart_dev_name = 635 - #ifdef DEBUG /* TODO: move this to debug-fs if possible */ 636 - __ATTR(dev_name, 0644, (void *)show_dev_name, (void *)store_dev_name); 637 - #else 638 - __ATTR(dev_name, 0444, (void *)show_dev_name, NULL); 639 - #endif 640 - 641 - static struct kobj_attribute uart_baud_rate = 642 - #ifdef DEBUG /* TODO: move to debugfs */ 643 - __ATTR(baud_rate, 0644, (void *)show_baud_rate, (void *)store_baud_rate); 644 - #else 645 - __ATTR(baud_rate, 0444, (void *)show_baud_rate, NULL); 646 - #endif 647 - 648 - static struct kobj_attribute uart_flow_cntrl = 649 - __ATTR(flow_cntrl, 0444, (void *)show_flow_cntrl, NULL); 650 - 651 - static struct attribute *uim_attrs[] = { 652 - &ldisc_install.attr, 653 - &uart_dev_name.attr, 654 - &uart_baud_rate.attr, 655 - &uart_flow_cntrl.attr, 656 - NULL, 657 - }; 658 - 659 - static const struct attribute_group uim_attr_grp = { 660 - .attrs = uim_attrs, 661 - }; 662 - 663 - /* 664 - * st_kim_ref - reference the core's data 665 - * This references the per-ST platform device in the arch/xx/ 666 - * board-xx.c file. 667 - * This would enable multiple such platform devices to exist 668 - * on a given platform 669 - */ 670 - void st_kim_ref(struct st_data_s **core_data, int id) 671 - { 672 - struct platform_device *pdev; 673 - struct kim_data_s *kim_gdata; 674 - /* get kim_gdata reference from platform device */ 675 - pdev = st_get_plat_device(id); 676 - if (!pdev) 677 - goto err; 678 - kim_gdata = platform_get_drvdata(pdev); 679 - if (!kim_gdata) 680 - goto err; 681 - 682 - *core_data = kim_gdata->core_data; 683 - return; 684 - err: 685 - *core_data = NULL; 686 - } 687 - 688 - DEFINE_SHOW_ATTRIBUTE(version); 689 - DEFINE_SHOW_ATTRIBUTE(list); 690 - 691 - /**********************************************************************/ 692 - /* functions called from platform device driver subsystem 693 - * need to have a relevant platform device entry in the platform's 694 - * board-*.c file 695 - */ 696 - 697 - static struct dentry *kim_debugfs_dir; 698 - static int kim_probe(struct platform_device *pdev) 699 - { 700 - struct kim_data_s *kim_gdata; 701 - struct ti_st_plat_data *pdata = pdev->dev.platform_data; 702 - int err; 703 - 704 - if ((pdev->id != -1) && (pdev->id < MAX_ST_DEVICES)) { 705 - /* multiple devices could exist */ 706 - st_kim_devices[pdev->id] = pdev; 707 - } else { 708 - /* platform's sure about existence of 1 device */ 709 - st_kim_devices[0] = pdev; 710 - } 711 - 712 - kim_gdata = kzalloc(sizeof(struct kim_data_s), GFP_KERNEL); 713 - if (!kim_gdata) { 714 - pr_err("no mem to allocate"); 715 - return -ENOMEM; 716 - } 717 - platform_set_drvdata(pdev, kim_gdata); 718 - 719 - err = st_core_init(&kim_gdata->core_data); 720 - if (err != 0) { 721 - pr_err(" ST core init failed"); 722 - err = -EIO; 723 - goto err_core_init; 724 - } 725 - /* refer to itself */ 726 - kim_gdata->core_data->kim_data = kim_gdata; 727 - 728 - /* Claim the chip enable nShutdown gpio from the system */ 729 - kim_gdata->nshutdown = pdata->nshutdown_gpio; 730 - err = gpio_request(kim_gdata->nshutdown, "kim"); 731 - if (unlikely(err)) { 732 - pr_err(" gpio %d request failed ", kim_gdata->nshutdown); 733 - goto err_sysfs_group; 734 - } 735 - 736 - /* Configure nShutdown GPIO as output=0 */ 737 - err = gpio_direction_output(kim_gdata->nshutdown, 0); 738 - if (unlikely(err)) { 739 - pr_err(" unable to configure gpio %d", kim_gdata->nshutdown); 740 - goto err_sysfs_group; 741 - } 742 - /* get reference of pdev for request_firmware */ 743 - kim_gdata->kim_pdev = pdev; 744 - init_completion(&kim_gdata->kim_rcvd); 745 - init_completion(&kim_gdata->ldisc_installed); 746 - 747 - err = sysfs_create_group(&pdev->dev.kobj, &uim_attr_grp); 748 - if (err) { 749 - pr_err("failed to create sysfs entries"); 750 - goto err_sysfs_group; 751 - } 752 - 753 - /* copying platform data */ 754 - strscpy(kim_gdata->dev_name, pdata->dev_name, 755 - sizeof(kim_gdata->dev_name)); 756 - kim_gdata->flow_cntrl = pdata->flow_cntrl; 757 - kim_gdata->baud_rate = pdata->baud_rate; 758 - pr_info("sysfs entries created\n"); 759 - 760 - kim_debugfs_dir = debugfs_create_dir("ti-st", NULL); 761 - 762 - debugfs_create_file("version", S_IRUGO, kim_debugfs_dir, 763 - kim_gdata, &version_fops); 764 - debugfs_create_file("protocols", S_IRUGO, kim_debugfs_dir, 765 - kim_gdata, &list_fops); 766 - return 0; 767 - 768 - err_sysfs_group: 769 - st_core_exit(kim_gdata->core_data); 770 - 771 - err_core_init: 772 - kfree(kim_gdata); 773 - 774 - return err; 775 - } 776 - 777 - static void kim_remove(struct platform_device *pdev) 778 - { 779 - /* free the GPIOs requested */ 780 - struct ti_st_plat_data *pdata = pdev->dev.platform_data; 781 - struct kim_data_s *kim_gdata; 782 - 783 - kim_gdata = platform_get_drvdata(pdev); 784 - 785 - /* 786 - * Free the Bluetooth/FM/GPIO 787 - * nShutdown gpio from the system 788 - */ 789 - gpio_free(pdata->nshutdown_gpio); 790 - pr_info("nshutdown GPIO Freed"); 791 - 792 - debugfs_remove_recursive(kim_debugfs_dir); 793 - sysfs_remove_group(&pdev->dev.kobj, &uim_attr_grp); 794 - pr_info("sysfs entries removed"); 795 - 796 - kim_gdata->kim_pdev = NULL; 797 - st_core_exit(kim_gdata->core_data); 798 - 799 - kfree(kim_gdata); 800 - kim_gdata = NULL; 801 - } 802 - 803 - static int kim_suspend(struct platform_device *pdev, pm_message_t state) 804 - { 805 - struct ti_st_plat_data *pdata = pdev->dev.platform_data; 806 - 807 - if (pdata->suspend) 808 - return pdata->suspend(pdev, state); 809 - 810 - return 0; 811 - } 812 - 813 - static int kim_resume(struct platform_device *pdev) 814 - { 815 - struct ti_st_plat_data *pdata = pdev->dev.platform_data; 816 - 817 - if (pdata->resume) 818 - return pdata->resume(pdev); 819 - 820 - return 0; 821 - } 822 - 823 - /**********************************************************************/ 824 - /* entry point for ST KIM module, called in from ST Core */ 825 - static struct platform_driver kim_platform_driver = { 826 - .probe = kim_probe, 827 - .remove_new = kim_remove, 828 - .suspend = kim_suspend, 829 - .resume = kim_resume, 830 - .driver = { 831 - .name = "kim", 832 - }, 833 - }; 834 - 835 - module_platform_driver(kim_platform_driver); 836 - 837 - MODULE_AUTHOR("Pavan Savoy <pavan_savoy@ti.com>"); 838 - MODULE_DESCRIPTION("Shared Transport Driver for TI BT/FM/GPS combo chips "); 839 - MODULE_LICENSE("GPL");
-156
drivers/misc/ti-st/st_ll.c
··· 1 - // SPDX-License-Identifier: GPL-2.0-only 2 - /* 3 - * Shared Transport driver 4 - * HCI-LL module responsible for TI proprietary HCI_LL protocol 5 - * Copyright (C) 2009-2010 Texas Instruments 6 - * Author: Pavan Savoy <pavan_savoy@ti.com> 7 - */ 8 - 9 - #define pr_fmt(fmt) "(stll) :" fmt 10 - #include <linux/skbuff.h> 11 - #include <linux/module.h> 12 - #include <linux/platform_device.h> 13 - #include <linux/ti_wilink_st.h> 14 - 15 - /**********************************************************************/ 16 - /* internal functions */ 17 - static void send_ll_cmd(struct st_data_s *st_data, 18 - unsigned char cmd) 19 - { 20 - 21 - pr_debug("%s: writing %x", __func__, cmd); 22 - st_int_write(st_data, &cmd, 1); 23 - return; 24 - } 25 - 26 - static void ll_device_want_to_sleep(struct st_data_s *st_data) 27 - { 28 - struct kim_data_s *kim_data; 29 - struct ti_st_plat_data *pdata; 30 - 31 - pr_debug("%s", __func__); 32 - /* sanity check */ 33 - if (st_data->ll_state != ST_LL_AWAKE) 34 - pr_err("ERR hcill: ST_LL_GO_TO_SLEEP_IND" 35 - "in state %ld", st_data->ll_state); 36 - 37 - send_ll_cmd(st_data, LL_SLEEP_ACK); 38 - /* update state */ 39 - st_data->ll_state = ST_LL_ASLEEP; 40 - 41 - /* communicate to platform about chip asleep */ 42 - kim_data = st_data->kim_data; 43 - pdata = kim_data->kim_pdev->dev.platform_data; 44 - if (pdata->chip_asleep) 45 - pdata->chip_asleep(NULL); 46 - } 47 - 48 - static void ll_device_want_to_wakeup(struct st_data_s *st_data) 49 - { 50 - struct kim_data_s *kim_data; 51 - struct ti_st_plat_data *pdata; 52 - 53 - /* diff actions in diff states */ 54 - switch (st_data->ll_state) { 55 - case ST_LL_ASLEEP: 56 - send_ll_cmd(st_data, LL_WAKE_UP_ACK); /* send wake_ack */ 57 - break; 58 - case ST_LL_ASLEEP_TO_AWAKE: 59 - /* duplicate wake_ind */ 60 - pr_err("duplicate wake_ind while waiting for Wake ack"); 61 - break; 62 - case ST_LL_AWAKE: 63 - /* duplicate wake_ind */ 64 - pr_err("duplicate wake_ind already AWAKE"); 65 - break; 66 - case ST_LL_AWAKE_TO_ASLEEP: 67 - /* duplicate wake_ind */ 68 - pr_err("duplicate wake_ind"); 69 - break; 70 - } 71 - /* update state */ 72 - st_data->ll_state = ST_LL_AWAKE; 73 - 74 - /* communicate to platform about chip wakeup */ 75 - kim_data = st_data->kim_data; 76 - pdata = kim_data->kim_pdev->dev.platform_data; 77 - if (pdata->chip_awake) 78 - pdata->chip_awake(NULL); 79 - } 80 - 81 - /**********************************************************************/ 82 - /* functions invoked by ST Core */ 83 - 84 - /* called when ST Core wants to 85 - * enable ST LL */ 86 - void st_ll_enable(struct st_data_s *ll) 87 - { 88 - ll->ll_state = ST_LL_AWAKE; 89 - } 90 - 91 - /* called when ST Core /local module wants to 92 - * disable ST LL */ 93 - void st_ll_disable(struct st_data_s *ll) 94 - { 95 - ll->ll_state = ST_LL_INVALID; 96 - } 97 - 98 - /* called when ST Core wants to update the state */ 99 - void st_ll_wakeup(struct st_data_s *ll) 100 - { 101 - if (likely(ll->ll_state != ST_LL_AWAKE)) { 102 - send_ll_cmd(ll, LL_WAKE_UP_IND); /* WAKE_IND */ 103 - ll->ll_state = ST_LL_ASLEEP_TO_AWAKE; 104 - } else { 105 - /* don't send the duplicate wake_indication */ 106 - pr_err(" Chip already AWAKE "); 107 - } 108 - } 109 - 110 - /* called when ST Core wants the state */ 111 - unsigned long st_ll_getstate(struct st_data_s *ll) 112 - { 113 - pr_debug(" returning state %ld", ll->ll_state); 114 - return ll->ll_state; 115 - } 116 - 117 - /* called from ST Core, when a PM related packet arrives */ 118 - unsigned long st_ll_sleep_state(struct st_data_s *st_data, 119 - unsigned char cmd) 120 - { 121 - switch (cmd) { 122 - case LL_SLEEP_IND: /* sleep ind */ 123 - pr_debug("sleep indication recvd"); 124 - ll_device_want_to_sleep(st_data); 125 - break; 126 - case LL_SLEEP_ACK: /* sleep ack */ 127 - pr_err("sleep ack rcvd: host shouldn't"); 128 - break; 129 - case LL_WAKE_UP_IND: /* wake ind */ 130 - pr_debug("wake indication recvd"); 131 - ll_device_want_to_wakeup(st_data); 132 - break; 133 - case LL_WAKE_UP_ACK: /* wake ack */ 134 - pr_debug("wake ack rcvd"); 135 - st_data->ll_state = ST_LL_AWAKE; 136 - break; 137 - default: 138 - pr_err(" unknown input/state "); 139 - return -EINVAL; 140 - } 141 - return 0; 142 - } 143 - 144 - /* Called from ST CORE to initialize ST LL */ 145 - long st_ll_init(struct st_data_s *ll) 146 - { 147 - /* set state to invalid */ 148 - ll->ll_state = ST_LL_INVALID; 149 - return 0; 150 - } 151 - 152 - /* Called from ST CORE to de-initialize ST LL */ 153 - long st_ll_deinit(struct st_data_s *ll) 154 - { 155 - return 0; 156 - }