22 #define pr_fmt(fmt) "(stc): " fmt
23 #include <linux/module.h>
24 #include <linux/kernel.h>
26 #include <linux/tty.h>
33 extern void st_kim_recv(
void *,
const unsigned char *,
long);
34 void st_int_recv(
void *,
const unsigned char *,
long);
39 static void (*st_recv) (
void *,
const unsigned char *,
long);
42 static void add_channel_to_table(
struct st_data_s *st_gdata,
51 static void remove_channel_from_table(
struct st_data_s *st_gdata,
70 pr_err(
"tty unavailable to perform write");
74 return tty->
ops->write_room(tty);
89 pr_err(
"tty unavailable to perform write");
95 16, 1, data, count, 0);
97 return tty->
ops->write(tty, data, count);
105 static void st_send_frame(
unsigned char chnl_id,
struct st_data_s *st_gdata)
107 pr_debug(
" %s(prot:%d) ", __func__, chnl_id);
112 pr_err(
"chnl_id %d not registered, no data to send?",
124 (st_gdata->
list[chnl_id]->recv
125 (st_gdata->
list[chnl_id]->priv_data, st_gdata->
rx_skb)
127 pr_err(
" proto stack %d's ->recv failed", chnl_id);
132 pr_err(
" proto stack %d's ->recv null", chnl_id);
145 static void st_reg_complete(
struct st_data_s *st_gdata,
char err)
152 st_gdata->
list[i]->reg_complete_cb !=
NULL)) {
153 st_gdata->
list[
i]->reg_complete_cb
154 (st_gdata->
list[i]->priv_data, err);
155 pr_info(
"protocol %d's cb sent %d\n", i, err);
164 static inline int st_check_data_len(
struct st_data_s *st_gdata,
165 unsigned char chnl_id,
int len)
167 int room = skb_tailroom(st_gdata->
rx_skb);
169 pr_debug(
"len %d room %d", len, room);
176 st_send_frame(chnl_id, st_gdata);
178 }
else if (len > room) {
182 pr_err(
"Data length is too large len %d room %d", len,
208 static inline void st_wakeup_ack(
struct st_data_s *st_gdata,
212 unsigned long flags = 0;
223 spin_unlock_irqrestore(&st_gdata->
lock, flags);
243 int len = 0,
type = 0;
251 pr_err(
" received null from TTY ");
256 "rx_count %ld", count, st_gdata->
rx_state,
279 st_send_frame(st_gdata->
rx_chnl, st_gdata);
290 pr_debug(
"plen pointing to %x\n", *plen);
292 payload_len = *(
unsigned char *)plen;
300 st_check_data_len(st_gdata, proto->
chnl_id,
323 spin_unlock_irqrestore(&st_gdata->
lock, flags);
334 spin_unlock_irqrestore(&st_gdata->
lock, flags);
336 st_wakeup_ack(st_gdata, *ptr);
346 pr_err(
"chip/interface misbehavior dropping"
347 " frame starting with 0x%02x",
type);
351 st_gdata->
rx_skb = alloc_skb(
352 st_gdata->
list[
type]->max_frame_size,
355 pr_err(
"out of memory: dropping\n");
359 skb_reserve(st_gdata->
rx_skb,
363 st_gdata->
rx_skb->cb[1] = 0;
373 spin_unlock_irqrestore(&st_gdata->
lock, flags);
390 returning_skb = st_gdata->
tx_skb;
392 return returning_skb;
408 unsigned long flags = 0;
415 pr_debug(
"ST LL is AWAKE, sending normally");
422 pr_err(
"ST LL is illegal state(%ld),"
431 pr_err(
"ST LL is illegal state(%ld),"
437 spin_unlock_irqrestore(&st_gdata->
lock, flags);
466 while ((skb = st_int_dequeue(st_data))) {
477 spin_unlock_irqrestore(&st_data->
lock, flags);
481 spin_unlock_irqrestore(&st_data->
lock, flags);
495 seq_printf(buf,
"[%d]\nBT=%c\nFM=%c\nGPS=%c\n",
511 unsigned long flags = 0;
517 pr_err(
"gdata/new_proto/recv or reg_complete_cb not ready");
521 if (new_proto->
chnl_id >= ST_MAX_CHANNELS) {
538 add_channel_to_table(st_gdata, new_proto);
543 spin_unlock_irqrestore(&st_gdata->
lock, flags);
554 spin_unlock_irqrestore(&st_gdata->
lock, flags);
564 pr_err(
" KIM failure complete callback ");
565 st_reg_complete(st_gdata, err);
581 pr_debug(
" call reg complete callback ");
582 st_reg_complete(st_gdata, 0);
590 pr_err(
" proto %d already registered ",
592 spin_unlock_irqrestore(&st_gdata->
lock, flags);
596 add_channel_to_table(st_gdata, new_proto);
599 spin_unlock_irqrestore(&st_gdata->
lock, flags);
604 add_channel_to_table(st_gdata, new_proto);
609 spin_unlock_irqrestore(&st_gdata->
lock, flags);
622 unsigned long flags = 0;
628 if (!st_gdata || proto->
chnl_id >= ST_MAX_CHANNELS) {
637 spin_unlock_irqrestore(&st_gdata->
lock, flags);
642 remove_channel_from_table(st_gdata, proto);
643 spin_unlock_irqrestore(&st_gdata->
lock, flags);
651 pr_info(
" all chnl_ids unregistered ");
679 pr_err(
"data/tty unavailable to perform write");
687 st_int_enqueue(st_gdata, skb);
733 unsigned long flags = 0;
745 pr_err(
"%d not un-registered", i);
750 spin_unlock_irqrestore(&st_gdata->
lock, flags);
770 spin_unlock_irqrestore(&st_gdata->
lock, flags);
775 static void st_tty_receive(
struct tty_struct *tty,
const unsigned char *
data,
776 char *tty_flags,
int count)
780 16, 1, data, count, 0);
794 static void st_tty_wakeup(
struct tty_struct *tty)
805 static void st_tty_flush_buffer(
struct tty_struct *tty)
813 tty->
ops->flush_buffer(tty);
821 .close = st_tty_close,
822 .receive_buf = st_tty_receive,
823 .write_wakeup = st_tty_wakeup,
824 .flush_buffer = st_tty_flush_buffer,
836 pr_err(
"error registering %d line discipline %ld",
840 pr_debug(
"registered n_shared line discipline");
844 pr_err(
"memory allocation failed");
847 pr_err(
"unable to un-register ldisc %ld", err);
855 skb_queue_head_init(&st_gdata->txq);
856 skb_queue_head_init(&st_gdata->
tx_waitq);
863 pr_err(
"error during st_ll initialization(%ld)", err);
867 pr_err(
"unable to un-register ldisc");
870 *core_data = st_gdata;
880 pr_err(
"error during deinit of ST LL %ld", err);
882 if (st_gdata !=
NULL) {
891 pr_err(
"unable to un-register ldisc %ld", err);