Commit | Line | Data |
---|---|---|
83ef41f0 PS |
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. | |
6 | * | |
7 | * Copyright (C) 2009-2010 Texas Instruments | |
8 | * Author: Pavan Savoy <pavan_savoy@ti.com> | |
9 | * | |
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. | |
13 | * | |
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. | |
18 | * | |
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 | |
22 | * | |
23 | */ | |
24 | ||
25 | #ifndef TI_WILINK_ST_H | |
26 | #define TI_WILINK_ST_H | |
27 | ||
9624f615 MG |
28 | #include <linux/skbuff.h> |
29 | ||
83ef41f0 PS |
30 | /** |
31 | * enum proto-type - The protocol on WiLink chips which share a | |
32 | * common physical interface like UART. | |
33 | */ | |
34 | enum proto_type { | |
35 | ST_BT, | |
36 | ST_FM, | |
37 | ST_GPS, | |
5c88b021 | 38 | ST_MAX_CHANNELS = 16, |
83ef41f0 PS |
39 | }; |
40 | ||
41 | /** | |
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 | |
47 | * relevant data. | |
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. | |
5c88b021 PS |
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 | |
66 | * or 1 byte. | |
67 | * @reserve: the number of bytes ST needs to reserve in the skb being | |
68 | * prepared for the protocol driver. | |
83ef41f0 PS |
69 | */ |
70 | struct st_proto_s { | |
71 | enum proto_type type; | |
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); | |
76 | void *priv_data; | |
5c88b021 PS |
77 | |
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; | |
83ef41f0 PS |
84 | }; |
85 | ||
86 | extern long st_register(struct st_proto_s *); | |
5c88b021 | 87 | extern long st_unregister(struct st_proto_s *); |
83ef41f0 PS |
88 | |
89 | ||
90 | /* | |
91 | * header information used by st_core.c | |
92 | */ | |
93 | ||
94 | /* states of protocol list */ | |
95 | #define ST_NOTEMPTY 1 | |
96 | #define ST_EMPTY 0 | |
97 | ||
98 | /* | |
99 | * possible st_states | |
100 | */ | |
101 | #define ST_INITIALIZING 1 | |
102 | #define ST_REG_IN_PROGRESS 2 | |
103 | #define ST_REG_PENDING 3 | |
104 | #define ST_WAITING_FOR_RESP 4 | |
105 | ||
106 | /** | |
107 | * struct st_data_s - ST core internal structure | |
108 | * @st_state: different states of ST like initializing, registration | |
109 | * in progress, this is mainly used to return relevant err codes | |
110 | * when protocol drivers are registering. It is also used to track | |
111 | * the recv function, as in during fw download only HCI events | |
112 | * can occur , where as during other times other events CH8, CH9 | |
113 | * can occur. | |
114 | * @tty: tty provided by the TTY core for line disciplines. | |
83ef41f0 PS |
115 | * @tx_skb: If for some reason the tty's write returns lesser bytes written |
116 | * then to maintain the rest of data to be written on next instance. | |
117 | * This needs to be protected, hence the lock inside wakeup func. | |
118 | * @tx_state: if the data is being written onto the TTY and protocol driver | |
119 | * wants to send more, queue up data and mark that there is | |
120 | * more data to send. | |
121 | * @list: the list of protocols registered, only MAX can exist, one protocol | |
122 | * can register only once. | |
123 | * @rx_state: states to be maintained inside st's tty receive | |
124 | * @rx_count: count to be maintained inside st's tty receieve | |
125 | * @rx_skb: the skb where all data for a protocol gets accumulated, | |
126 | * since tty might not call receive when a complete event packet | |
127 | * is received, the states, count and the skb needs to be maintained. | |
5c88b021 | 128 | * @rx_chnl: the channel ID for which the data is getting accumalated for. |
83ef41f0 PS |
129 | * @txq: the list of skbs which needs to be sent onto the TTY. |
130 | * @tx_waitq: if the chip is not in AWAKE state, the skbs needs to be queued | |
131 | * up in here, PM(WAKEUP_IND) data needs to be sent and then the skbs | |
132 | * from waitq can be moved onto the txq. | |
133 | * Needs locking too. | |
134 | * @lock: the lock to protect skbs, queues, and ST states. | |
135 | * @protos_registered: count of the protocols registered, also when 0 the | |
136 | * chip enable gpio can be toggled, and when it changes to 1 the fw | |
137 | * needs to be downloaded to initialize chip side ST. | |
138 | * @ll_state: the various PM states the chip can be, the states are notified | |
139 | * to us, when the chip sends relevant PM packets(SLEEP_IND, WAKE_IND). | |
140 | * @kim_data: reference to the parent encapsulating structure. | |
141 | * | |
142 | */ | |
143 | struct st_data_s { | |
144 | unsigned long st_state; | |
83ef41f0 PS |
145 | struct sk_buff *tx_skb; |
146 | #define ST_TX_SENDING 1 | |
147 | #define ST_TX_WAKEUP 2 | |
148 | unsigned long tx_state; | |
5c88b021 | 149 | struct st_proto_s *list[ST_MAX_CHANNELS]; |
764b0c4b | 150 | bool is_registered[ST_MAX_CHANNELS]; |
83ef41f0 PS |
151 | unsigned long rx_state; |
152 | unsigned long rx_count; | |
153 | struct sk_buff *rx_skb; | |
5c88b021 | 154 | unsigned char rx_chnl; |
83ef41f0 PS |
155 | struct sk_buff_head txq, tx_waitq; |
156 | spinlock_t lock; | |
157 | unsigned char protos_registered; | |
158 | unsigned long ll_state; | |
159 | void *kim_data; | |
764b0c4b | 160 | struct tty_struct *tty; |
83ef41f0 PS |
161 | }; |
162 | ||
ef04d121 PS |
163 | /* |
164 | * wrapper around tty->ops->write_room to check | |
165 | * availability during firmware download | |
166 | */ | |
167 | int st_get_uart_wr_room(struct st_data_s *st_gdata); | |
83ef41f0 PS |
168 | /** |
169 | * st_int_write - | |
170 | * point this to tty->driver->write or tty->ops->write | |
171 | * depending upon the kernel version | |
172 | */ | |
173 | int st_int_write(struct st_data_s*, const unsigned char*, int); | |
174 | ||
175 | /** | |
176 | * st_write - | |
177 | * internal write function, passed onto protocol drivers | |
178 | * via the write function ptr of protocol struct | |
179 | */ | |
180 | long st_write(struct sk_buff *); | |
181 | ||
182 | /* function to be called from ST-LL */ | |
183 | void st_ll_send_frame(enum proto_type, struct sk_buff *); | |
184 | ||
185 | /* internal wake up function */ | |
186 | void st_tx_wakeup(struct st_data_s *st_data); | |
187 | ||
188 | /* init, exit entry funcs called from KIM */ | |
189 | int st_core_init(struct st_data_s **); | |
190 | void st_core_exit(struct st_data_s *); | |
191 | ||
192 | /* ask for reference from KIM */ | |
193 | void st_kim_ref(struct st_data_s **, int); | |
194 | ||
195 | #define GPS_STUB_TEST | |
196 | #ifdef GPS_STUB_TEST | |
197 | int gps_chrdrv_stub_write(const unsigned char*, int); | |
198 | void gps_chrdrv_stub_init(void); | |
199 | #endif | |
200 | ||
201 | /* | |
202 | * header information used by st_kim.c | |
203 | */ | |
204 | ||
205 | /* time in msec to wait for | |
206 | * line discipline to be installed | |
207 | */ | |
ec60d0ad PS |
208 | #define LDISC_TIME 1000 |
209 | #define CMD_RESP_TIME 800 | |
ef04d121 | 210 | #define CMD_WR_TIME 5000 |
83ef41f0 PS |
211 | #define MAKEWORD(a, b) ((unsigned short)(((unsigned char)(a)) \ |
212 | | ((unsigned short)((unsigned char)(b))) << 8)) | |
213 | ||
214 | #define GPIO_HIGH 1 | |
215 | #define GPIO_LOW 0 | |
216 | ||
217 | /* the Power-On-Reset logic, requires to attempt | |
218 | * to download firmware onto chip more than once | |
219 | * since the self-test for chip takes a while | |
220 | */ | |
221 | #define POR_RETRY_COUNT 5 | |
222 | ||
223 | /** | |
224 | * struct chip_version - save the chip version | |
225 | */ | |
226 | struct chip_version { | |
227 | unsigned short full; | |
228 | unsigned short chip; | |
229 | unsigned short min_ver; | |
230 | unsigned short maj_ver; | |
231 | }; | |
232 | ||
ec60d0ad | 233 | #define UART_DEV_NAME_LEN 32 |
83ef41f0 PS |
234 | /** |
235 | * struct kim_data_s - the KIM internal data, embedded as the | |
236 | * platform's drv data. One for each ST device in the system. | |
237 | * @uim_pid: KIM needs to communicate with UIM to request to install | |
238 | * the ldisc by opening UART when protocol drivers register. | |
239 | * @kim_pdev: the platform device added in one of the board-XX.c file | |
240 | * in arch/XX/ directory, 1 for each ST device. | |
241 | * @kim_rcvd: completion handler to notify when data was received, | |
242 | * mainly used during fw download, which involves multiple send/wait | |
243 | * for each of the HCI-VS commands. | |
244 | * @ldisc_installed: completion handler to notify that the UIM accepted | |
245 | * the request to install ldisc, notify from tty_open which suggests | |
246 | * the ldisc was properly installed. | |
247 | * @resp_buffer: data buffer for the .bts fw file name. | |
248 | * @fw_entry: firmware class struct to request/release the fw. | |
83ef41f0 PS |
249 | * @rx_state: the rx state for kim's receive func during fw download. |
250 | * @rx_count: the rx count for the kim's receive func during fw download. | |
251 | * @rx_skb: all of fw data might not come at once, and hence data storage for | |
252 | * whole of the fw response, only HCI_EVENTs and hence diff from ST's | |
253 | * response. | |
83ef41f0 PS |
254 | * @core_data: ST core's data, which mainly is the tty's disc_data |
255 | * @version: chip version available via a sysfs entry. | |
256 | * | |
257 | */ | |
258 | struct kim_data_s { | |
259 | long uim_pid; | |
260 | struct platform_device *kim_pdev; | |
261 | struct completion kim_rcvd, ldisc_installed; | |
262 | char resp_buffer[30]; | |
263 | const struct firmware *fw_entry; | |
781a7395 | 264 | long nshutdown; |
83ef41f0 PS |
265 | unsigned long rx_state; |
266 | unsigned long rx_count; | |
267 | struct sk_buff *rx_skb; | |
83ef41f0 PS |
268 | struct st_data_s *core_data; |
269 | struct chip_version version; | |
ec60d0ad PS |
270 | unsigned char ldisc_install; |
271 | unsigned char dev_name[UART_DEV_NAME_LEN]; | |
272 | unsigned char flow_cntrl; | |
273 | unsigned long baud_rate; | |
83ef41f0 PS |
274 | }; |
275 | ||
276 | /** | |
277 | * functions called when 1 of the protocol drivers gets | |
278 | * registered, these need to communicate with UIM to request | |
279 | * ldisc installed, read chip_version, download relevant fw | |
280 | */ | |
281 | long st_kim_start(void *); | |
282 | long st_kim_stop(void *); | |
283 | ||
83ef41f0 PS |
284 | void st_kim_complete(void *); |
285 | void kim_st_list_protocols(struct st_data_s *, void *); | |
27712b39 PS |
286 | void st_kim_recv(void *, const unsigned char *, long); |
287 | ||
83ef41f0 PS |
288 | |
289 | /* | |
290 | * BTS headers | |
291 | */ | |
292 | #define ACTION_SEND_COMMAND 1 | |
293 | #define ACTION_WAIT_EVENT 2 | |
294 | #define ACTION_SERIAL 3 | |
295 | #define ACTION_DELAY 4 | |
296 | #define ACTION_RUN_SCRIPT 5 | |
297 | #define ACTION_REMARKS 6 | |
298 | ||
299 | /** | |
300 | * struct bts_header - the fw file is NOT binary which can | |
301 | * be sent onto TTY as is. The .bts is more a script | |
302 | * file which has different types of actions. | |
303 | * Each such action needs to be parsed by the KIM and | |
304 | * relevant procedure to be called. | |
305 | */ | |
306 | struct bts_header { | |
307 | u32 magic; | |
308 | u32 version; | |
309 | u8 future[24]; | |
310 | u8 actions[0]; | |
311 | } __attribute__ ((packed)); | |
312 | ||
313 | /** | |
314 | * struct bts_action - Each .bts action has its own type of | |
315 | * data. | |
316 | */ | |
317 | struct bts_action { | |
318 | u16 type; | |
319 | u16 size; | |
320 | u8 data[0]; | |
321 | } __attribute__ ((packed)); | |
322 | ||
323 | struct bts_action_send { | |
324 | u8 data[0]; | |
325 | } __attribute__ ((packed)); | |
326 | ||
327 | struct bts_action_wait { | |
328 | u32 msec; | |
329 | u32 size; | |
330 | u8 data[0]; | |
331 | } __attribute__ ((packed)); | |
332 | ||
333 | struct bts_action_delay { | |
334 | u32 msec; | |
335 | } __attribute__ ((packed)); | |
336 | ||
337 | struct bts_action_serial { | |
338 | u32 baud; | |
339 | u32 flow_control; | |
340 | } __attribute__ ((packed)); | |
341 | ||
342 | /** | |
343 | * struct hci_command - the HCI-VS for intrepreting | |
344 | * the change baud rate of host-side UART, which | |
345 | * needs to be ignored, since UIM would do that | |
346 | * when it receives request from KIM for ldisc installation. | |
347 | */ | |
348 | struct hci_command { | |
349 | u8 prefix; | |
350 | u16 opcode; | |
351 | u8 plen; | |
352 | u32 speed; | |
353 | } __attribute__ ((packed)); | |
354 | ||
355 | /* | |
356 | * header information used by st_ll.c | |
357 | */ | |
358 | ||
359 | /* ST LL receiver states */ | |
360 | #define ST_W4_PACKET_TYPE 0 | |
5c88b021 PS |
361 | #define ST_W4_HEADER 1 |
362 | #define ST_W4_DATA 2 | |
83ef41f0 PS |
363 | |
364 | /* ST LL state machines */ | |
365 | #define ST_LL_ASLEEP 0 | |
366 | #define ST_LL_ASLEEP_TO_AWAKE 1 | |
367 | #define ST_LL_AWAKE 2 | |
368 | #define ST_LL_AWAKE_TO_ASLEEP 3 | |
369 | #define ST_LL_INVALID 4 | |
370 | ||
371 | /* different PM notifications coming from chip */ | |
372 | #define LL_SLEEP_IND 0x30 | |
373 | #define LL_SLEEP_ACK 0x31 | |
374 | #define LL_WAKE_UP_IND 0x32 | |
375 | #define LL_WAKE_UP_ACK 0x33 | |
376 | ||
377 | /* initialize and de-init ST LL */ | |
378 | long st_ll_init(struct st_data_s *); | |
379 | long st_ll_deinit(struct st_data_s *); | |
380 | ||
381 | /** | |
382 | * enable/disable ST LL along with KIM start/stop | |
383 | * called by ST Core | |
384 | */ | |
385 | void st_ll_enable(struct st_data_s *); | |
386 | void st_ll_disable(struct st_data_s *); | |
387 | ||
388 | /** | |
389 | * various funcs used by ST core to set/get the various PM states | |
390 | * of the chip. | |
391 | */ | |
392 | unsigned long st_ll_getstate(struct st_data_s *); | |
393 | unsigned long st_ll_sleep_state(struct st_data_s *, unsigned char); | |
394 | void st_ll_wakeup(struct st_data_s *); | |
395 | ||
396 | /* | |
397 | * header information used by st_core.c for FM and GPS | |
398 | * packet parsing, the bluetooth headers are already available | |
399 | * at net/bluetooth/ | |
400 | */ | |
401 | ||
402 | struct fm_event_hdr { | |
403 | u8 plen; | |
404 | } __attribute__ ((packed)); | |
405 | ||
406 | #define FM_MAX_FRAME_SIZE 0xFF /* TODO: */ | |
407 | #define FM_EVENT_HDR_SIZE 1 /* size of fm_event_hdr */ | |
408 | #define ST_FM_CH8_PKT 0x8 | |
409 | ||
410 | /* gps stuff */ | |
411 | struct gps_event_hdr { | |
412 | u8 opcode; | |
413 | u16 plen; | |
414 | } __attribute__ ((packed)); | |
415 | ||
0d7c5f25 PS |
416 | /** |
417 | * struct ti_st_plat_data - platform data shared between ST driver and | |
418 | * platform specific board file which adds the ST device. | |
419 | * @nshutdown_gpio: Host's GPIO line to which chip's BT_EN is connected. | |
420 | * @dev_name: The UART/TTY name to which chip is interfaced. (eg: /dev/ttyS1) | |
421 | * @flow_cntrl: Should always be 1, since UART's CTS/RTS is used for PM | |
422 | * purposes. | |
423 | * @baud_rate: The baud rate supported by the Host UART controller, this will | |
424 | * be shared across with the chip via a HCI VS command from User-Space Init | |
425 | * Mgr application. | |
426 | * @suspend: | |
427 | * @resume: legacy PM routines hooked to platform specific board file, so as | |
428 | * to take chip-host interface specific action. | |
429 | * @chip_enable: | |
430 | * @chip_disable: Platform/Interface specific mux mode setting, GPIO | |
431 | * configuring, Host side PM disabling etc.. can be done here. | |
432 | * @chip_asleep: | |
433 | * @chip_awake: Chip specific deep sleep states is communicated to Host | |
434 | * specific board-xx.c to take actions such as cut UART clocks when chip | |
435 | * asleep or run host faster when chip awake etc.. | |
436 | * | |
437 | */ | |
ec60d0ad | 438 | struct ti_st_plat_data { |
781a7395 | 439 | long nshutdown_gpio; |
ec60d0ad PS |
440 | unsigned char dev_name[UART_DEV_NAME_LEN]; /* uart name */ |
441 | unsigned char flow_cntrl; /* flow control flag */ | |
442 | unsigned long baud_rate; | |
443 | int (*suspend)(struct platform_device *, pm_message_t); | |
444 | int (*resume)(struct platform_device *); | |
0d7c5f25 PS |
445 | int (*chip_enable) (struct kim_data_s *); |
446 | int (*chip_disable) (struct kim_data_s *); | |
447 | int (*chip_asleep) (struct kim_data_s *); | |
448 | int (*chip_awake) (struct kim_data_s *); | |
ec60d0ad PS |
449 | }; |
450 | ||
83ef41f0 | 451 | #endif /* TI_WILINK_ST_H */ |