1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * Shared Transport Header file
4 * To be included by the protocol stack drivers for
5 * Texas Instruments BT,FM and GPS combo chip drivers
6 * and also serves the sub-modules of the shared transport driver.
8 * Copyright (C) 2009-2010 Texas Instruments
9 * Author: Pavan Savoy <pavan_savoy@ti.com>
12 #ifndef TI_WILINK_ST_H
13 #define TI_WILINK_ST_H
15 #include <linux/skbuff.h>
18 * enum proto-type - The protocol on WiLink chips which share a
19 * common physical interface like UART.
29 * struct st_proto_s - Per Protocol structure from BT/FM/GPS to ST
30 * @type: type of the protocol being registered among the
31 * available proto_type(BT, FM, GPS the protocol which share TTY).
32 * @recv: the receiver callback pointing to a function in the
33 * protocol drivers called by the ST driver upon receiving
35 * @match_packet: reserved for future use, to make ST more generic
36 * @reg_complete_cb: callback handler pointing to a function in protocol
37 * handler called by ST when the pending registrations are complete.
38 * The registrations are marked pending, in situations when fw
39 * download is in progress.
40 * @write: pointer to function in ST provided to protocol drivers from ST,
41 * to be made use when protocol drivers have data to send to TTY.
42 * @priv_data: privdate data holder for the protocol drivers, sent
43 * from the protocol drivers during registration, and sent back on
44 * reg_complete_cb and recv.
45 * @chnl_id: channel id the protocol driver is interested in, the channel
46 * id is nothing but the 1st byte of the packet in UART frame.
47 * @max_frame_size: size of the largest frame the protocol can receive.
48 * @hdr_len: length of the header structure of the protocol.
49 * @offset_len_in_hdr: this provides the offset of the length field in the
50 * header structure of the protocol header, to assist ST to know
51 * how much to receive, if the data is split across UART frames.
52 * @len_size: whether the length field inside the header is 2 bytes
54 * @reserve: the number of bytes ST needs to reserve in the skb being
55 * prepared for the protocol driver.
59 long (*recv) (void *, struct sk_buff *);
60 unsigned char (*match_packet) (const unsigned char *data);
61 void (*reg_complete_cb) (void *, int data);
62 long (*write) (struct sk_buff *skb);
65 unsigned char chnl_id;
66 unsigned short max_frame_size;
67 unsigned char hdr_len;
68 unsigned char offset_len_in_hdr;
69 unsigned char len_size;
70 unsigned char reserve;
73 extern long st_register(struct st_proto_s *);
74 extern long st_unregister(struct st_proto_s *);
78 * header information used by st_core.c
81 /* states of protocol list */
88 #define ST_INITIALIZING 1
89 #define ST_REG_IN_PROGRESS 2
90 #define ST_REG_PENDING 3
91 #define ST_WAITING_FOR_RESP 4
94 * struct st_data_s - ST core internal structure
95 * @st_state: different states of ST like initializing, registration
96 * in progress, this is mainly used to return relevant err codes
97 * when protocol drivers are registering. It is also used to track
98 * the recv function, as in during fw download only HCI events
99 * can occur , where as during other times other events CH8, CH9
101 * @tty: tty provided by the TTY core for line disciplines.
102 * @tx_skb: If for some reason the tty's write returns lesser bytes written
103 * then to maintain the rest of data to be written on next instance.
104 * This needs to be protected, hence the lock inside wakeup func.
105 * @tx_state: if the data is being written onto the TTY and protocol driver
106 * wants to send more, queue up data and mark that there is
108 * @list: the list of protocols registered, only MAX can exist, one protocol
109 * can register only once.
110 * @rx_state: states to be maintained inside st's tty receive
111 * @rx_count: count to be maintained inside st's tty receieve
112 * @rx_skb: the skb where all data for a protocol gets accumulated,
113 * since tty might not call receive when a complete event packet
114 * is received, the states, count and the skb needs to be maintained.
115 * @rx_chnl: the channel ID for which the data is getting accumalated for.
116 * @txq: the list of skbs which needs to be sent onto the TTY.
117 * @tx_waitq: if the chip is not in AWAKE state, the skbs needs to be queued
118 * up in here, PM(WAKEUP_IND) data needs to be sent and then the skbs
119 * from waitq can be moved onto the txq.
121 * @lock: the lock to protect skbs, queues, and ST states.
122 * @protos_registered: count of the protocols registered, also when 0 the
123 * chip enable gpio can be toggled, and when it changes to 1 the fw
124 * needs to be downloaded to initialize chip side ST.
125 * @ll_state: the various PM states the chip can be, the states are notified
126 * to us, when the chip sends relevant PM packets(SLEEP_IND, WAKE_IND).
127 * @kim_data: reference to the parent encapsulating structure.
131 unsigned long st_state;
132 struct sk_buff *tx_skb;
133 #define ST_TX_SENDING 1
134 #define ST_TX_WAKEUP 2
135 unsigned long tx_state;
136 struct st_proto_s *list[ST_MAX_CHANNELS];
137 bool is_registered[ST_MAX_CHANNELS];
138 unsigned long rx_state;
139 unsigned long rx_count;
140 struct sk_buff *rx_skb;
141 unsigned char rx_chnl;
142 struct sk_buff_head txq, tx_waitq;
144 unsigned char protos_registered;
145 unsigned long ll_state;
147 struct tty_struct *tty;
148 struct work_struct work_write_wakeup;
152 * wrapper around tty->ops->write_room to check
153 * availability during firmware download
155 int st_get_uart_wr_room(struct st_data_s *st_gdata);
158 * point this to tty->driver->write or tty->ops->write
159 * depending upon the kernel version
161 int st_int_write(struct st_data_s*, const unsigned char*, int);
165 * internal write function, passed onto protocol drivers
166 * via the write function ptr of protocol struct
168 long st_write(struct sk_buff *);
170 /* function to be called from ST-LL */
171 void st_ll_send_frame(enum proto_type, struct sk_buff *);
173 /* internal wake up function */
174 void st_tx_wakeup(struct st_data_s *st_data);
176 /* init, exit entry funcs called from KIM */
177 int st_core_init(struct st_data_s **);
178 void st_core_exit(struct st_data_s *);
180 /* ask for reference from KIM */
181 void st_kim_ref(struct st_data_s **, int);
183 #define GPS_STUB_TEST
185 int gps_chrdrv_stub_write(const unsigned char*, int);
186 void gps_chrdrv_stub_init(void);
190 * header information used by st_kim.c
193 /* time in msec to wait for
194 * line discipline to be installed
196 #define LDISC_TIME 1000
197 #define CMD_RESP_TIME 800
198 #define CMD_WR_TIME 5000
199 #define MAKEWORD(a, b) ((unsigned short)(((unsigned char)(a)) \
200 | ((unsigned short)((unsigned char)(b))) << 8))
205 /* the Power-On-Reset logic, requires to attempt
206 * to download firmware onto chip more than once
207 * since the self-test for chip takes a while
209 #define POR_RETRY_COUNT 5
212 * struct chip_version - save the chip version
214 struct chip_version {
217 unsigned short min_ver;
218 unsigned short maj_ver;
221 #define UART_DEV_NAME_LEN 32
223 * struct kim_data_s - the KIM internal data, embedded as the
224 * platform's drv data. One for each ST device in the system.
225 * @uim_pid: KIM needs to communicate with UIM to request to install
226 * the ldisc by opening UART when protocol drivers register.
227 * @kim_pdev: the platform device added in one of the board-XX.c file
228 * in arch/XX/ directory, 1 for each ST device.
229 * @kim_rcvd: completion handler to notify when data was received,
230 * mainly used during fw download, which involves multiple send/wait
231 * for each of the HCI-VS commands.
232 * @ldisc_installed: completion handler to notify that the UIM accepted
233 * the request to install ldisc, notify from tty_open which suggests
234 * the ldisc was properly installed.
235 * @resp_buffer: data buffer for the .bts fw file name.
236 * @fw_entry: firmware class struct to request/release the fw.
237 * @rx_state: the rx state for kim's receive func during fw download.
238 * @rx_count: the rx count for the kim's receive func during fw download.
239 * @rx_skb: all of fw data might not come at once, and hence data storage for
240 * whole of the fw response, only HCI_EVENTs and hence diff from ST's
242 * @core_data: ST core's data, which mainly is the tty's disc_data
243 * @version: chip version available via a sysfs entry.
248 struct platform_device *kim_pdev;
249 struct completion kim_rcvd, ldisc_installed;
250 char resp_buffer[30];
251 const struct firmware *fw_entry;
253 unsigned long rx_state;
254 unsigned long rx_count;
255 struct sk_buff *rx_skb;
256 struct st_data_s *core_data;
257 struct chip_version version;
258 unsigned char ldisc_install;
259 unsigned char dev_name[UART_DEV_NAME_LEN + 1];
265 * functions called when 1 of the protocol drivers gets
266 * registered, these need to communicate with UIM to request
267 * ldisc installed, read chip_version, download relevant fw
269 long st_kim_start(void *);
270 long st_kim_stop(void *);
272 void st_kim_complete(void *);
273 void kim_st_list_protocols(struct st_data_s *, void *);
274 void st_kim_recv(void *disc_data, const u8 *data, size_t count);
280 #define ACTION_SEND_COMMAND 1
281 #define ACTION_WAIT_EVENT 2
282 #define ACTION_SERIAL 3
283 #define ACTION_DELAY 4
284 #define ACTION_RUN_SCRIPT 5
285 #define ACTION_REMARKS 6
288 * struct bts_header - the fw file is NOT binary which can
289 * be sent onto TTY as is. The .bts is more a script
290 * file which has different types of actions.
291 * Each such action needs to be parsed by the KIM and
292 * relevant procedure to be called.
299 } __attribute__ ((packed));
302 * struct bts_action - Each .bts action has its own type of
309 } __attribute__ ((packed));
311 struct bts_action_send {
313 } __attribute__ ((packed));
315 struct bts_action_wait {
319 } __attribute__ ((packed));
321 struct bts_action_delay {
323 } __attribute__ ((packed));
325 struct bts_action_serial {
328 } __attribute__ ((packed));
331 * struct hci_command - the HCI-VS for intrepreting
332 * the change baud rate of host-side UART, which
333 * needs to be ignored, since UIM would do that
334 * when it receives request from KIM for ldisc installation.
341 } __attribute__ ((packed));
344 * header information used by st_ll.c
347 /* ST LL receiver states */
348 #define ST_W4_PACKET_TYPE 0
349 #define ST_W4_HEADER 1
352 /* ST LL state machines */
353 #define ST_LL_ASLEEP 0
354 #define ST_LL_ASLEEP_TO_AWAKE 1
355 #define ST_LL_AWAKE 2
356 #define ST_LL_AWAKE_TO_ASLEEP 3
357 #define ST_LL_INVALID 4
359 /* different PM notifications coming from chip */
360 #define LL_SLEEP_IND 0x30
361 #define LL_SLEEP_ACK 0x31
362 #define LL_WAKE_UP_IND 0x32
363 #define LL_WAKE_UP_ACK 0x33
365 /* initialize and de-init ST LL */
366 long st_ll_init(struct st_data_s *);
367 long st_ll_deinit(struct st_data_s *);
370 * enable/disable ST LL along with KIM start/stop
373 void st_ll_enable(struct st_data_s *);
374 void st_ll_disable(struct st_data_s *);
377 * various funcs used by ST core to set/get the various PM states
380 unsigned long st_ll_getstate(struct st_data_s *);
381 unsigned long st_ll_sleep_state(struct st_data_s *, unsigned char);
382 void st_ll_wakeup(struct st_data_s *);
385 * header information used by st_core.c for FM and GPS
386 * packet parsing, the bluetooth headers are already available
390 struct fm_event_hdr {
392 } __attribute__ ((packed));
394 #define FM_MAX_FRAME_SIZE 0xFF /* TODO: */
395 #define FM_EVENT_HDR_SIZE 1 /* size of fm_event_hdr */
396 #define ST_FM_CH8_PKT 0x8
399 struct gps_event_hdr {
402 } __attribute__ ((packed));
405 * struct ti_st_plat_data - platform data shared between ST driver and
406 * platform specific board file which adds the ST device.
407 * @nshutdown_gpio: Host's GPIO line to which chip's BT_EN is connected.
408 * @dev_name: The UART/TTY name to which chip is interfaced. (eg: /dev/ttyS1)
409 * @flow_cntrl: Should always be 1, since UART's CTS/RTS is used for PM
411 * @baud_rate: The baud rate supported by the Host UART controller, this will
412 * be shared across with the chip via a HCI VS command from User-Space Init
415 * @resume: legacy PM routines hooked to platform specific board file, so as
416 * to take chip-host interface specific action.
418 * @chip_disable: Platform/Interface specific mux mode setting, GPIO
419 * configuring, Host side PM disabling etc.. can be done here.
421 * @chip_awake: Chip specific deep sleep states is communicated to Host
422 * specific board-xx.c to take actions such as cut UART clocks when chip
423 * asleep or run host faster when chip awake etc..
426 struct ti_st_plat_data {
428 unsigned char dev_name[UART_DEV_NAME_LEN]; /* uart name */
429 u32 flow_cntrl; /* flow control flag */
431 int (*suspend)(struct platform_device *, pm_message_t);
432 int (*resume)(struct platform_device *);
433 int (*chip_enable) (struct kim_data_s *);
434 int (*chip_disable) (struct kim_data_s *);
435 int (*chip_asleep) (struct kim_data_s *);
436 int (*chip_awake) (struct kim_data_s *);
439 #endif /* TI_WILINK_ST_H */