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 #include <linux/skbuff.h>
31 * enum proto-type - The protocol on WiLink chips which share a
32 * common physical interface like UART.
42 * struct st_proto_s - Per Protocol structure from BT/FM/GPS to ST
43 * @type: type of the protocol being registered among the
44 * available proto_type(BT, FM, GPS the protocol which share TTY).
45 * @recv: the receiver callback pointing to a function in the
46 * protocol drivers called by the ST driver upon receiving
48 * @match_packet: reserved for future use, to make ST more generic
49 * @reg_complete_cb: callback handler pointing to a function in protocol
50 * handler called by ST when the pending registrations are complete.
51 * The registrations are marked pending, in situations when fw
52 * download is in progress.
53 * @write: pointer to function in ST provided to protocol drivers from ST,
54 * to be made use when protocol drivers have data to send to TTY.
55 * @priv_data: privdate data holder for the protocol drivers, sent
56 * from the protocol drivers during registration, and sent back on
57 * reg_complete_cb and recv.
58 * @chnl_id: channel id the protocol driver is interested in, the channel
59 * id is nothing but the 1st byte of the packet in UART frame.
60 * @max_frame_size: size of the largest frame the protocol can receive.
61 * @hdr_len: length of the header structure of the protocol.
62 * @offset_len_in_hdr: this provides the offset of the length field in the
63 * header structure of the protocol header, to assist ST to know
64 * how much to receive, if the data is split across UART frames.
65 * @len_size: whether the length field inside the header is 2 bytes
67 * @reserve: the number of bytes ST needs to reserve in the skb being
68 * prepared for the protocol driver.
72 long (*recv
) (void *, struct sk_buff
*);
73 unsigned char (*match_packet
) (const unsigned char *data
);
74 void (*reg_complete_cb
) (void *, char data
);
75 long (*write
) (struct sk_buff
*skb
);
78 unsigned char chnl_id
;
79 unsigned short max_frame_size
;
80 unsigned char hdr_len
;
81 unsigned char offset_len_in_hdr
;
82 unsigned char len_size
;
83 unsigned char reserve
;
86 extern long st_register(struct st_proto_s
*);
87 extern long st_unregister(struct st_proto_s
*);
89 extern struct ti_st_plat_data
*dt_pdata
;
92 * header information used by st_core.c
95 /* states of protocol list */
102 #define ST_INITIALIZING 1
103 #define ST_REG_IN_PROGRESS 2
104 #define ST_REG_PENDING 3
105 #define ST_WAITING_FOR_RESP 4
108 * struct st_data_s - ST core internal structure
109 * @st_state: different states of ST like initializing, registration
110 * in progress, this is mainly used to return relevant err codes
111 * when protocol drivers are registering. It is also used to track
112 * the recv function, as in during fw download only HCI events
113 * can occur , where as during other times other events CH8, CH9
115 * @tty: tty provided by the TTY core for line disciplines.
116 * @tx_skb: If for some reason the tty's write returns lesser bytes written
117 * then to maintain the rest of data to be written on next instance.
118 * This needs to be protected, hence the lock inside wakeup func.
119 * @tx_state: if the data is being written onto the TTY and protocol driver
120 * wants to send more, queue up data and mark that there is
122 * @list: the list of protocols registered, only MAX can exist, one protocol
123 * can register only once.
124 * @rx_state: states to be maintained inside st's tty receive
125 * @rx_count: count to be maintained inside st's tty receieve
126 * @rx_skb: the skb where all data for a protocol gets accumulated,
127 * since tty might not call receive when a complete event packet
128 * is received, the states, count and the skb needs to be maintained.
129 * @rx_chnl: the channel ID for which the data is getting accumalated for.
130 * @txq: the list of skbs which needs to be sent onto the TTY.
131 * @tx_waitq: if the chip is not in AWAKE state, the skbs needs to be queued
132 * up in here, PM(WAKEUP_IND) data needs to be sent and then the skbs
133 * from waitq can be moved onto the txq.
135 * @lock: the lock to protect skbs, queues, and ST states.
136 * @protos_registered: count of the protocols registered, also when 0 the
137 * chip enable gpio can be toggled, and when it changes to 1 the fw
138 * needs to be downloaded to initialize chip side ST.
139 * @ll_state: the various PM states the chip can be, the states are notified
140 * to us, when the chip sends relevant PM packets(SLEEP_IND, WAKE_IND).
141 * @kim_data: reference to the parent encapsulating structure.
145 unsigned long st_state
;
146 struct sk_buff
*tx_skb
;
147 #define ST_TX_SENDING 1
148 #define ST_TX_WAKEUP 2
149 unsigned long tx_state
;
150 struct st_proto_s
*list
[ST_MAX_CHANNELS
];
151 bool is_registered
[ST_MAX_CHANNELS
];
152 unsigned long rx_state
;
153 unsigned long rx_count
;
154 struct sk_buff
*rx_skb
;
155 unsigned char rx_chnl
;
156 struct sk_buff_head txq
, tx_waitq
;
158 unsigned char protos_registered
;
159 unsigned long ll_state
;
161 struct tty_struct
*tty
;
165 * wrapper around tty->ops->write_room to check
166 * availability during firmware download
168 int st_get_uart_wr_room(struct st_data_s
*st_gdata
);
171 * point this to tty->driver->write or tty->ops->write
172 * depending upon the kernel version
174 int st_int_write(struct st_data_s
*, const unsigned char*, int);
178 * internal write function, passed onto protocol drivers
179 * via the write function ptr of protocol struct
181 long st_write(struct sk_buff
*);
183 /* function to be called from ST-LL */
184 void st_ll_send_frame(enum proto_type
, struct sk_buff
*);
186 /* internal wake up function */
187 void st_tx_wakeup(struct st_data_s
*st_data
);
189 /* init, exit entry funcs called from KIM */
190 int st_core_init(struct st_data_s
**);
191 void st_core_exit(struct st_data_s
*);
193 /* ask for reference from KIM */
194 void st_kim_ref(struct st_data_s
**, int);
196 #define GPS_STUB_TEST
198 int gps_chrdrv_stub_write(const unsigned char*, int);
199 void gps_chrdrv_stub_init(void);
203 * header information used by st_kim.c
206 /* time in msec to wait for
207 * line discipline to be installed
209 #define LDISC_TIME 1000
210 #define CMD_RESP_TIME 800
211 #define CMD_WR_TIME 5000
212 #define MAKEWORD(a, b) ((unsigned short)(((unsigned char)(a)) \
213 | ((unsigned short)((unsigned char)(b))) << 8))
218 /* the Power-On-Reset logic, requires to attempt
219 * to download firmware onto chip more than once
220 * since the self-test for chip takes a while
222 #define POR_RETRY_COUNT 5
225 * struct chip_version - save the chip version
227 struct chip_version
{
230 unsigned short min_ver
;
231 unsigned short maj_ver
;
234 #define UART_DEV_NAME_LEN 32
236 * struct kim_data_s - the KIM internal data, embedded as the
237 * platform's drv data. One for each ST device in the system.
238 * @uim_pid: KIM needs to communicate with UIM to request to install
239 * the ldisc by opening UART when protocol drivers register.
240 * @kim_pdev: the platform device added in one of the board-XX.c file
241 * in arch/XX/ directory, 1 for each ST device.
242 * @kim_rcvd: completion handler to notify when data was received,
243 * mainly used during fw download, which involves multiple send/wait
244 * for each of the HCI-VS commands.
245 * @ldisc_installed: completion handler to notify that the UIM accepted
246 * the request to install ldisc, notify from tty_open which suggests
247 * the ldisc was properly installed.
248 * @resp_buffer: data buffer for the .bts fw file name.
249 * @fw_entry: firmware class struct to request/release the fw.
250 * @rx_state: the rx state for kim's receive func during fw download.
251 * @rx_count: the rx count for the kim's receive func during fw download.
252 * @rx_skb: all of fw data might not come at once, and hence data storage for
253 * whole of the fw response, only HCI_EVENTs and hence diff from ST's
255 * @core_data: ST core's data, which mainly is the tty's disc_data
256 * @version: chip version available via a sysfs entry.
261 struct platform_device
*kim_pdev
;
262 struct completion kim_rcvd
, ldisc_installed
;
263 char resp_buffer
[30];
264 const struct firmware
*fw_entry
;
266 unsigned long rx_state
;
267 unsigned long rx_count
;
268 struct sk_buff
*rx_skb
;
269 struct st_data_s
*core_data
;
270 struct chip_version version
;
271 unsigned char ldisc_install
;
272 unsigned char dev_name
[UART_DEV_NAME_LEN
+ 1];
278 * functions called when 1 of the protocol drivers gets
279 * registered, these need to communicate with UIM to request
280 * ldisc installed, read chip_version, download relevant fw
282 long st_kim_start(void *);
283 long st_kim_stop(void *);
285 void st_kim_complete(void *);
286 void kim_st_list_protocols(struct st_data_s
*, void *);
287 void st_kim_recv(void *, const unsigned char *, long);
293 #define ACTION_SEND_COMMAND 1
294 #define ACTION_WAIT_EVENT 2
295 #define ACTION_SERIAL 3
296 #define ACTION_DELAY 4
297 #define ACTION_RUN_SCRIPT 5
298 #define ACTION_REMARKS 6
301 * struct bts_header - the fw file is NOT binary which can
302 * be sent onto TTY as is. The .bts is more a script
303 * file which has different types of actions.
304 * Each such action needs to be parsed by the KIM and
305 * relevant procedure to be called.
312 } __attribute__ ((packed
));
315 * struct bts_action - Each .bts action has its own type of
322 } __attribute__ ((packed
));
324 struct bts_action_send
{
326 } __attribute__ ((packed
));
328 struct bts_action_wait
{
332 } __attribute__ ((packed
));
334 struct bts_action_delay
{
336 } __attribute__ ((packed
));
338 struct bts_action_serial
{
341 } __attribute__ ((packed
));
344 * struct hci_command - the HCI-VS for intrepreting
345 * the change baud rate of host-side UART, which
346 * needs to be ignored, since UIM would do that
347 * when it receives request from KIM for ldisc installation.
354 } __attribute__ ((packed
));
357 * header information used by st_ll.c
360 /* ST LL receiver states */
361 #define ST_W4_PACKET_TYPE 0
362 #define ST_W4_HEADER 1
365 /* ST LL state machines */
366 #define ST_LL_ASLEEP 0
367 #define ST_LL_ASLEEP_TO_AWAKE 1
368 #define ST_LL_AWAKE 2
369 #define ST_LL_AWAKE_TO_ASLEEP 3
370 #define ST_LL_INVALID 4
372 /* different PM notifications coming from chip */
373 #define LL_SLEEP_IND 0x30
374 #define LL_SLEEP_ACK 0x31
375 #define LL_WAKE_UP_IND 0x32
376 #define LL_WAKE_UP_ACK 0x33
378 /* initialize and de-init ST LL */
379 long st_ll_init(struct st_data_s
*);
380 long st_ll_deinit(struct st_data_s
*);
383 * enable/disable ST LL along with KIM start/stop
386 void st_ll_enable(struct st_data_s
*);
387 void st_ll_disable(struct st_data_s
*);
390 * various funcs used by ST core to set/get the various PM states
393 unsigned long st_ll_getstate(struct st_data_s
*);
394 unsigned long st_ll_sleep_state(struct st_data_s
*, unsigned char);
395 void st_ll_wakeup(struct st_data_s
*);
398 * header information used by st_core.c for FM and GPS
399 * packet parsing, the bluetooth headers are already available
403 struct fm_event_hdr
{
405 } __attribute__ ((packed
));
407 #define FM_MAX_FRAME_SIZE 0xFF /* TODO: */
408 #define FM_EVENT_HDR_SIZE 1 /* size of fm_event_hdr */
409 #define ST_FM_CH8_PKT 0x8
412 struct gps_event_hdr
{
415 } __attribute__ ((packed
));
418 * struct ti_st_plat_data - platform data shared between ST driver and
419 * platform specific board file which adds the ST device.
420 * @nshutdown_gpio: Host's GPIO line to which chip's BT_EN is connected.
421 * @dev_name: The UART/TTY name to which chip is interfaced. (eg: /dev/ttyS1)
422 * @flow_cntrl: Should always be 1, since UART's CTS/RTS is used for PM
424 * @baud_rate: The baud rate supported by the Host UART controller, this will
425 * be shared across with the chip via a HCI VS command from User-Space Init
428 * @resume: legacy PM routines hooked to platform specific board file, so as
429 * to take chip-host interface specific action.
431 * @chip_disable: Platform/Interface specific mux mode setting, GPIO
432 * configuring, Host side PM disabling etc.. can be done here.
434 * @chip_awake: Chip specific deep sleep states is communicated to Host
435 * specific board-xx.c to take actions such as cut UART clocks when chip
436 * asleep or run host faster when chip awake etc..
439 struct ti_st_plat_data
{
441 unsigned char dev_name
[UART_DEV_NAME_LEN
]; /* uart name */
442 u32 flow_cntrl
; /* flow control flag */
444 int (*suspend
)(struct platform_device
*, pm_message_t
);
445 int (*resume
)(struct platform_device
*);
446 int (*chip_enable
) (struct kim_data_s
*);
447 int (*chip_disable
) (struct kim_data_s
*);
448 int (*chip_asleep
) (struct kim_data_s
*);
449 int (*chip_awake
) (struct kim_data_s
*);
452 #endif /* TI_WILINK_ST_H */
This page took 0.069763 seconds and 6 git commands to generate.