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