Merge branch 'upstream-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/jikos/hid
[pandora-kernel.git] / drivers / staging / ti-st / st_core.h
1 /*
2  *  Shared Transport Core header file
3  *
4  *  Copyright (C) 2009 Texas Instruments
5  *
6  *  This program is free software; you can redistribute it and/or modify
7  *  it under the terms of the GNU General Public License version 2 as
8  *  published by the Free Software Foundation.
9  *
10  *  This program is distributed in the hope that it will be useful,
11  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  *  GNU General Public License for more details.
14  *
15  *  You should have received a copy of the GNU General Public License
16  *  along with this program; if not, write to the Free Software
17  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18  *
19  */
20
21 #ifndef ST_CORE_H
22 #define ST_CORE_H
23
24 #include <linux/skbuff.h>
25 #include "st.h"
26
27 /* states of protocol list */
28 #define ST_NOTEMPTY     1
29 #define ST_EMPTY        0
30
31 /*
32  * possible st_states
33  */
34 #define ST_INITIALIZING         1
35 #define ST_REG_IN_PROGRESS      2
36 #define ST_REG_PENDING          3
37 #define ST_WAITING_FOR_RESP     4
38
39 /**
40  * struct st_data_s - ST core internal structure
41  * @st_state: different states of ST like initializing, registration
42  *      in progress, this is mainly used to return relevant err codes
43  *      when protocol drivers are registering. It is also used to track
44  *      the recv function, as in during fw download only HCI events
45  *      can occur , where as during other times other events CH8, CH9
46  *      can occur.
47  * @tty: tty provided by the TTY core for line disciplines.
48  * @ldisc_ops: the procedures that this line discipline registers with TTY.
49  * @tx_skb: If for some reason the tty's write returns lesser bytes written
50  *      then to maintain the rest of data to be written on next instance.
51  *      This needs to be protected, hence the lock inside wakeup func.
52  * @tx_state: if the data is being written onto the TTY and protocol driver
53  *      wants to send more, queue up data and mark that there is
54  *      more data to send.
55  * @list: the list of protocols registered, only MAX can exist, one protocol
56  *      can register only once.
57  * @rx_state: states to be maintained inside st's tty receive
58  * @rx_count: count to be maintained inside st's tty receieve
59  * @rx_skb: the skb where all data for a protocol gets accumulated,
60  *      since tty might not call receive when a complete event packet
61  *      is received, the states, count and the skb needs to be maintained.
62  * @txq: the list of skbs which needs to be sent onto the TTY.
63  * @tx_waitq: if the chip is not in AWAKE state, the skbs needs to be queued
64  *      up in here, PM(WAKEUP_IND) data needs to be sent and then the skbs
65  *      from waitq can be moved onto the txq.
66  *      Needs locking too.
67  * @lock: the lock to protect skbs, queues, and ST states.
68  * @protos_registered: count of the protocols registered, also when 0 the
69  *      chip enable gpio can be toggled, and when it changes to 1 the fw
70  *      needs to be downloaded to initialize chip side ST.
71  * @ll_state: the various PM states the chip can be, the states are notified
72  *      to us, when the chip sends relevant PM packets(SLEEP_IND, WAKE_IND).
73  * @kim_data: reference to the parent encapsulating structure.
74  *
75  */
76 struct st_data_s {
77         unsigned long st_state;
78         struct tty_struct *tty;
79         struct tty_ldisc_ops *ldisc_ops;
80         struct sk_buff *tx_skb;
81 #define ST_TX_SENDING   1
82 #define ST_TX_WAKEUP    2
83         unsigned long tx_state;
84         struct st_proto_s *list[ST_MAX];
85         unsigned long rx_state;
86         unsigned long rx_count;
87         struct sk_buff *rx_skb;
88         struct sk_buff_head txq, tx_waitq;
89         spinlock_t lock;
90         unsigned char   protos_registered;
91         unsigned long ll_state;
92         void *kim_data;
93 };
94
95 /**
96  * st_int_write -
97  * point this to tty->driver->write or tty->ops->write
98  * depending upon the kernel version
99  */
100 int st_int_write(struct st_data_s*, const unsigned char*, int);
101
102 /**
103  * st_write -
104  * internal write function, passed onto protocol drivers
105  * via the write function ptr of protocol struct
106  */
107 long st_write(struct sk_buff *);
108
109 /* function to be called from ST-LL */
110 void st_ll_send_frame(enum proto_type, struct sk_buff *);
111
112 /* internal wake up function */
113 void st_tx_wakeup(struct st_data_s *st_data);
114
115 /* init, exit entry funcs called from KIM */
116 int st_core_init(struct st_data_s **);
117 void st_core_exit(struct st_data_s *);
118
119 /* ask for reference from KIM */
120 void st_kim_ref(struct st_data_s **, int);
121
122 #define GPS_STUB_TEST
123 #ifdef GPS_STUB_TEST
124 int gps_chrdrv_stub_write(const unsigned char*, int);
125 void gps_chrdrv_stub_init(void);
126 #endif
127
128 #endif /*ST_CORE_H */