Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/cjb/mmc
[cris-mirror.git] / include / linux / ti_wilink_st.h
blob7071ec5d011883940f4bd088aed1066a048b44dc
1 /*
2 * Shared Transport Header file
3 * To be included by the protocol stack drivers for
4 * Texas Instruments BT,FM and GPS combo chip drivers
5 * and also serves the sub-modules of the shared transport driver.
7 * Copyright (C) 2009-2010 Texas Instruments
8 * Author: Pavan Savoy <pavan_savoy@ti.com>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 #ifndef TI_WILINK_ST_H
26 #define TI_WILINK_ST_H
28 /**
29 * enum proto-type - The protocol on WiLink chips which share a
30 * common physical interface like UART.
32 enum proto_type {
33 ST_BT,
34 ST_FM,
35 ST_GPS,
36 ST_MAX_CHANNELS = 16,
39 /**
40 * struct st_proto_s - Per Protocol structure from BT/FM/GPS to ST
41 * @type: type of the protocol being registered among the
42 * available proto_type(BT, FM, GPS the protocol which share TTY).
43 * @recv: the receiver callback pointing to a function in the
44 * protocol drivers called by the ST driver upon receiving
45 * relevant data.
46 * @match_packet: reserved for future use, to make ST more generic
47 * @reg_complete_cb: callback handler pointing to a function in protocol
48 * handler called by ST when the pending registrations are complete.
49 * The registrations are marked pending, in situations when fw
50 * download is in progress.
51 * @write: pointer to function in ST provided to protocol drivers from ST,
52 * to be made use when protocol drivers have data to send to TTY.
53 * @priv_data: privdate data holder for the protocol drivers, sent
54 * from the protocol drivers during registration, and sent back on
55 * reg_complete_cb and recv.
56 * @chnl_id: channel id the protocol driver is interested in, the channel
57 * id is nothing but the 1st byte of the packet in UART frame.
58 * @max_frame_size: size of the largest frame the protocol can receive.
59 * @hdr_len: length of the header structure of the protocol.
60 * @offset_len_in_hdr: this provides the offset of the length field in the
61 * header structure of the protocol header, to assist ST to know
62 * how much to receive, if the data is split across UART frames.
63 * @len_size: whether the length field inside the header is 2 bytes
64 * or 1 byte.
65 * @reserve: the number of bytes ST needs to reserve in the skb being
66 * prepared for the protocol driver.
68 struct st_proto_s {
69 enum proto_type type;
70 long (*recv) (void *, struct sk_buff *);
71 unsigned char (*match_packet) (const unsigned char *data);
72 void (*reg_complete_cb) (void *, char data);
73 long (*write) (struct sk_buff *skb);
74 void *priv_data;
76 unsigned char chnl_id;
77 unsigned short max_frame_size;
78 unsigned char hdr_len;
79 unsigned char offset_len_in_hdr;
80 unsigned char len_size;
81 unsigned char reserve;
84 extern long st_register(struct st_proto_s *);
85 extern long st_unregister(struct st_proto_s *);
89 * header information used by st_core.c
92 /* states of protocol list */
93 #define ST_NOTEMPTY 1
94 #define ST_EMPTY 0
97 * possible st_states
99 #define ST_INITIALIZING 1
100 #define ST_REG_IN_PROGRESS 2
101 #define ST_REG_PENDING 3
102 #define ST_WAITING_FOR_RESP 4
105 * struct st_data_s - ST core internal structure
106 * @st_state: different states of ST like initializing, registration
107 * in progress, this is mainly used to return relevant err codes
108 * when protocol drivers are registering. It is also used to track
109 * the recv function, as in during fw download only HCI events
110 * can occur , where as during other times other events CH8, CH9
111 * can occur.
112 * @tty: tty provided by the TTY core for line disciplines.
113 * @tx_skb: If for some reason the tty's write returns lesser bytes written
114 * then to maintain the rest of data to be written on next instance.
115 * This needs to be protected, hence the lock inside wakeup func.
116 * @tx_state: if the data is being written onto the TTY and protocol driver
117 * wants to send more, queue up data and mark that there is
118 * more data to send.
119 * @list: the list of protocols registered, only MAX can exist, one protocol
120 * can register only once.
121 * @rx_state: states to be maintained inside st's tty receive
122 * @rx_count: count to be maintained inside st's tty receieve
123 * @rx_skb: the skb where all data for a protocol gets accumulated,
124 * since tty might not call receive when a complete event packet
125 * is received, the states, count and the skb needs to be maintained.
126 * @rx_chnl: the channel ID for which the data is getting accumalated for.
127 * @txq: the list of skbs which needs to be sent onto the TTY.
128 * @tx_waitq: if the chip is not in AWAKE state, the skbs needs to be queued
129 * up in here, PM(WAKEUP_IND) data needs to be sent and then the skbs
130 * from waitq can be moved onto the txq.
131 * Needs locking too.
132 * @lock: the lock to protect skbs, queues, and ST states.
133 * @protos_registered: count of the protocols registered, also when 0 the
134 * chip enable gpio can be toggled, and when it changes to 1 the fw
135 * needs to be downloaded to initialize chip side ST.
136 * @ll_state: the various PM states the chip can be, the states are notified
137 * to us, when the chip sends relevant PM packets(SLEEP_IND, WAKE_IND).
138 * @kim_data: reference to the parent encapsulating structure.
141 struct st_data_s {
142 unsigned long st_state;
143 struct tty_struct *tty;
144 struct sk_buff *tx_skb;
145 #define ST_TX_SENDING 1
146 #define ST_TX_WAKEUP 2
147 unsigned long tx_state;
148 struct st_proto_s *list[ST_MAX_CHANNELS];
149 unsigned long rx_state;
150 unsigned long rx_count;
151 struct sk_buff *rx_skb;
152 unsigned char rx_chnl;
153 struct sk_buff_head txq, tx_waitq;
154 spinlock_t lock;
155 unsigned char protos_registered;
156 unsigned long ll_state;
157 void *kim_data;
161 * wrapper around tty->ops->write_room to check
162 * availability during firmware download
164 int st_get_uart_wr_room(struct st_data_s *st_gdata);
166 * st_int_write -
167 * point this to tty->driver->write or tty->ops->write
168 * depending upon the kernel version
170 int st_int_write(struct st_data_s*, const unsigned char*, int);
173 * st_write -
174 * internal write function, passed onto protocol drivers
175 * via the write function ptr of protocol struct
177 long st_write(struct sk_buff *);
179 /* function to be called from ST-LL */
180 void st_ll_send_frame(enum proto_type, struct sk_buff *);
182 /* internal wake up function */
183 void st_tx_wakeup(struct st_data_s *st_data);
185 /* init, exit entry funcs called from KIM */
186 int st_core_init(struct st_data_s **);
187 void st_core_exit(struct st_data_s *);
189 /* ask for reference from KIM */
190 void st_kim_ref(struct st_data_s **, int);
192 #define GPS_STUB_TEST
193 #ifdef GPS_STUB_TEST
194 int gps_chrdrv_stub_write(const unsigned char*, int);
195 void gps_chrdrv_stub_init(void);
196 #endif
199 * header information used by st_kim.c
202 /* time in msec to wait for
203 * line discipline to be installed
205 #define LDISC_TIME 1000
206 #define CMD_RESP_TIME 800
207 #define CMD_WR_TIME 5000
208 #define MAKEWORD(a, b) ((unsigned short)(((unsigned char)(a)) \
209 | ((unsigned short)((unsigned char)(b))) << 8))
211 #define GPIO_HIGH 1
212 #define GPIO_LOW 0
214 /* the Power-On-Reset logic, requires to attempt
215 * to download firmware onto chip more than once
216 * since the self-test for chip takes a while
218 #define POR_RETRY_COUNT 5
221 * struct chip_version - save the chip version
223 struct chip_version {
224 unsigned short full;
225 unsigned short chip;
226 unsigned short min_ver;
227 unsigned short maj_ver;
230 #define UART_DEV_NAME_LEN 32
232 * struct kim_data_s - the KIM internal data, embedded as the
233 * platform's drv data. One for each ST device in the system.
234 * @uim_pid: KIM needs to communicate with UIM to request to install
235 * the ldisc by opening UART when protocol drivers register.
236 * @kim_pdev: the platform device added in one of the board-XX.c file
237 * in arch/XX/ directory, 1 for each ST device.
238 * @kim_rcvd: completion handler to notify when data was received,
239 * mainly used during fw download, which involves multiple send/wait
240 * for each of the HCI-VS commands.
241 * @ldisc_installed: completion handler to notify that the UIM accepted
242 * the request to install ldisc, notify from tty_open which suggests
243 * the ldisc was properly installed.
244 * @resp_buffer: data buffer for the .bts fw file name.
245 * @fw_entry: firmware class struct to request/release the fw.
246 * @rx_state: the rx state for kim's receive func during fw download.
247 * @rx_count: the rx count for the kim's receive func during fw download.
248 * @rx_skb: all of fw data might not come at once, and hence data storage for
249 * whole of the fw response, only HCI_EVENTs and hence diff from ST's
250 * response.
251 * @core_data: ST core's data, which mainly is the tty's disc_data
252 * @version: chip version available via a sysfs entry.
255 struct kim_data_s {
256 long uim_pid;
257 struct platform_device *kim_pdev;
258 struct completion kim_rcvd, ldisc_installed;
259 char resp_buffer[30];
260 const struct firmware *fw_entry;
261 long nshutdown;
262 unsigned long rx_state;
263 unsigned long rx_count;
264 struct sk_buff *rx_skb;
265 struct st_data_s *core_data;
266 struct chip_version version;
267 unsigned char ldisc_install;
268 unsigned char dev_name[UART_DEV_NAME_LEN];
269 unsigned char flow_cntrl;
270 unsigned long baud_rate;
274 * functions called when 1 of the protocol drivers gets
275 * registered, these need to communicate with UIM to request
276 * ldisc installed, read chip_version, download relevant fw
278 long st_kim_start(void *);
279 long st_kim_stop(void *);
281 void st_kim_recv(void *, const unsigned char *, long count);
282 void st_kim_complete(void *);
283 void kim_st_list_protocols(struct st_data_s *, void *);
286 * BTS headers
288 #define ACTION_SEND_COMMAND 1
289 #define ACTION_WAIT_EVENT 2
290 #define ACTION_SERIAL 3
291 #define ACTION_DELAY 4
292 #define ACTION_RUN_SCRIPT 5
293 #define ACTION_REMARKS 6
296 * struct bts_header - the fw file is NOT binary which can
297 * be sent onto TTY as is. The .bts is more a script
298 * file which has different types of actions.
299 * Each such action needs to be parsed by the KIM and
300 * relevant procedure to be called.
302 struct bts_header {
303 u32 magic;
304 u32 version;
305 u8 future[24];
306 u8 actions[0];
307 } __attribute__ ((packed));
310 * struct bts_action - Each .bts action has its own type of
311 * data.
313 struct bts_action {
314 u16 type;
315 u16 size;
316 u8 data[0];
317 } __attribute__ ((packed));
319 struct bts_action_send {
320 u8 data[0];
321 } __attribute__ ((packed));
323 struct bts_action_wait {
324 u32 msec;
325 u32 size;
326 u8 data[0];
327 } __attribute__ ((packed));
329 struct bts_action_delay {
330 u32 msec;
331 } __attribute__ ((packed));
333 struct bts_action_serial {
334 u32 baud;
335 u32 flow_control;
336 } __attribute__ ((packed));
339 * struct hci_command - the HCI-VS for intrepreting
340 * the change baud rate of host-side UART, which
341 * needs to be ignored, since UIM would do that
342 * when it receives request from KIM for ldisc installation.
344 struct hci_command {
345 u8 prefix;
346 u16 opcode;
347 u8 plen;
348 u32 speed;
349 } __attribute__ ((packed));
352 * header information used by st_ll.c
355 /* ST LL receiver states */
356 #define ST_W4_PACKET_TYPE 0
357 #define ST_W4_HEADER 1
358 #define ST_W4_DATA 2
360 /* ST LL state machines */
361 #define ST_LL_ASLEEP 0
362 #define ST_LL_ASLEEP_TO_AWAKE 1
363 #define ST_LL_AWAKE 2
364 #define ST_LL_AWAKE_TO_ASLEEP 3
365 #define ST_LL_INVALID 4
367 /* different PM notifications coming from chip */
368 #define LL_SLEEP_IND 0x30
369 #define LL_SLEEP_ACK 0x31
370 #define LL_WAKE_UP_IND 0x32
371 #define LL_WAKE_UP_ACK 0x33
373 /* initialize and de-init ST LL */
374 long st_ll_init(struct st_data_s *);
375 long st_ll_deinit(struct st_data_s *);
378 * enable/disable ST LL along with KIM start/stop
379 * called by ST Core
381 void st_ll_enable(struct st_data_s *);
382 void st_ll_disable(struct st_data_s *);
385 * various funcs used by ST core to set/get the various PM states
386 * of the chip.
388 unsigned long st_ll_getstate(struct st_data_s *);
389 unsigned long st_ll_sleep_state(struct st_data_s *, unsigned char);
390 void st_ll_wakeup(struct st_data_s *);
393 * header information used by st_core.c for FM and GPS
394 * packet parsing, the bluetooth headers are already available
395 * at net/bluetooth/
398 struct fm_event_hdr {
399 u8 plen;
400 } __attribute__ ((packed));
402 #define FM_MAX_FRAME_SIZE 0xFF /* TODO: */
403 #define FM_EVENT_HDR_SIZE 1 /* size of fm_event_hdr */
404 #define ST_FM_CH8_PKT 0x8
406 /* gps stuff */
407 struct gps_event_hdr {
408 u8 opcode;
409 u16 plen;
410 } __attribute__ ((packed));
412 /* platform data */
413 struct ti_st_plat_data {
414 long nshutdown_gpio;
415 unsigned char dev_name[UART_DEV_NAME_LEN]; /* uart name */
416 unsigned char flow_cntrl; /* flow control flag */
417 unsigned long baud_rate;
418 int (*suspend)(struct platform_device *, pm_message_t);
419 int (*resume)(struct platform_device *);
422 #endif /* TI_WILINK_ST_H */