![]() |
|
|||
0001 /* SPDX-License-Identifier: GPL-2.0-only */ 0002 /* 0003 * Shared Transport Header file 0004 * To be included by the protocol stack drivers for 0005 * Texas Instruments BT,FM and GPS combo chip drivers 0006 * and also serves the sub-modules of the shared transport driver. 0007 * 0008 * Copyright (C) 2009-2010 Texas Instruments 0009 * Author: Pavan Savoy <pavan_savoy@ti.com> 0010 */ 0011 0012 #ifndef TI_WILINK_ST_H 0013 #define TI_WILINK_ST_H 0014 0015 #include <linux/skbuff.h> 0016 0017 /** 0018 * enum proto-type - The protocol on WiLink chips which share a 0019 * common physical interface like UART. 0020 */ 0021 enum proto_type { 0022 ST_BT, 0023 ST_FM, 0024 ST_GPS, 0025 ST_MAX_CHANNELS = 16, 0026 }; 0027 0028 /** 0029 * struct st_proto_s - Per Protocol structure from BT/FM/GPS to ST 0030 * @type: type of the protocol being registered among the 0031 * available proto_type(BT, FM, GPS the protocol which share TTY). 0032 * @recv: the receiver callback pointing to a function in the 0033 * protocol drivers called by the ST driver upon receiving 0034 * relevant data. 0035 * @match_packet: reserved for future use, to make ST more generic 0036 * @reg_complete_cb: callback handler pointing to a function in protocol 0037 * handler called by ST when the pending registrations are complete. 0038 * The registrations are marked pending, in situations when fw 0039 * download is in progress. 0040 * @write: pointer to function in ST provided to protocol drivers from ST, 0041 * to be made use when protocol drivers have data to send to TTY. 0042 * @priv_data: privdate data holder for the protocol drivers, sent 0043 * from the protocol drivers during registration, and sent back on 0044 * reg_complete_cb and recv. 0045 * @chnl_id: channel id the protocol driver is interested in, the channel 0046 * id is nothing but the 1st byte of the packet in UART frame. 0047 * @max_frame_size: size of the largest frame the protocol can receive. 0048 * @hdr_len: length of the header structure of the protocol. 0049 * @offset_len_in_hdr: this provides the offset of the length field in the 0050 * header structure of the protocol header, to assist ST to know 0051 * how much to receive, if the data is split across UART frames. 0052 * @len_size: whether the length field inside the header is 2 bytes 0053 * or 1 byte. 0054 * @reserve: the number of bytes ST needs to reserve in the skb being 0055 * prepared for the protocol driver. 0056 */ 0057 struct st_proto_s { 0058 enum proto_type type; 0059 long (*recv) (void *, struct sk_buff *); 0060 unsigned char (*match_packet) (const unsigned char *data); 0061 void (*reg_complete_cb) (void *, int data); 0062 long (*write) (struct sk_buff *skb); 0063 void *priv_data; 0064 0065 unsigned char chnl_id; 0066 unsigned short max_frame_size; 0067 unsigned char hdr_len; 0068 unsigned char offset_len_in_hdr; 0069 unsigned char len_size; 0070 unsigned char reserve; 0071 }; 0072 0073 extern long st_register(struct st_proto_s *); 0074 extern long st_unregister(struct st_proto_s *); 0075 0076 0077 /* 0078 * header information used by st_core.c 0079 */ 0080 0081 /* states of protocol list */ 0082 #define ST_NOTEMPTY 1 0083 #define ST_EMPTY 0 0084 0085 /* 0086 * possible st_states 0087 */ 0088 #define ST_INITIALIZING 1 0089 #define ST_REG_IN_PROGRESS 2 0090 #define ST_REG_PENDING 3 0091 #define ST_WAITING_FOR_RESP 4 0092 0093 /** 0094 * struct st_data_s - ST core internal structure 0095 * @st_state: different states of ST like initializing, registration 0096 * in progress, this is mainly used to return relevant err codes 0097 * when protocol drivers are registering. It is also used to track 0098 * the recv function, as in during fw download only HCI events 0099 * can occur , where as during other times other events CH8, CH9 0100 * can occur. 0101 * @tty: tty provided by the TTY core for line disciplines. 0102 * @tx_skb: If for some reason the tty's write returns lesser bytes written 0103 * then to maintain the rest of data to be written on next instance. 0104 * This needs to be protected, hence the lock inside wakeup func. 0105 * @tx_state: if the data is being written onto the TTY and protocol driver 0106 * wants to send more, queue up data and mark that there is 0107 * more data to send. 0108 * @list: the list of protocols registered, only MAX can exist, one protocol 0109 * can register only once. 0110 * @rx_state: states to be maintained inside st's tty receive 0111 * @rx_count: count to be maintained inside st's tty receieve 0112 * @rx_skb: the skb where all data for a protocol gets accumulated, 0113 * since tty might not call receive when a complete event packet 0114 * is received, the states, count and the skb needs to be maintained. 0115 * @rx_chnl: the channel ID for which the data is getting accumalated for. 0116 * @txq: the list of skbs which needs to be sent onto the TTY. 0117 * @tx_waitq: if the chip is not in AWAKE state, the skbs needs to be queued 0118 * up in here, PM(WAKEUP_IND) data needs to be sent and then the skbs 0119 * from waitq can be moved onto the txq. 0120 * Needs locking too. 0121 * @lock: the lock to protect skbs, queues, and ST states. 0122 * @protos_registered: count of the protocols registered, also when 0 the 0123 * chip enable gpio can be toggled, and when it changes to 1 the fw 0124 * needs to be downloaded to initialize chip side ST. 0125 * @ll_state: the various PM states the chip can be, the states are notified 0126 * to us, when the chip sends relevant PM packets(SLEEP_IND, WAKE_IND). 0127 * @kim_data: reference to the parent encapsulating structure. 0128 * 0129 */ 0130 struct st_data_s { 0131 unsigned long st_state; 0132 struct sk_buff *tx_skb; 0133 #define ST_TX_SENDING 1 0134 #define ST_TX_WAKEUP 2 0135 unsigned long tx_state; 0136 struct st_proto_s *list[ST_MAX_CHANNELS]; 0137 bool is_registered[ST_MAX_CHANNELS]; 0138 unsigned long rx_state; 0139 unsigned long rx_count; 0140 struct sk_buff *rx_skb; 0141 unsigned char rx_chnl; 0142 struct sk_buff_head txq, tx_waitq; 0143 spinlock_t lock; 0144 unsigned char protos_registered; 0145 unsigned long ll_state; 0146 void *kim_data; 0147 struct tty_struct *tty; 0148 struct work_struct work_write_wakeup; 0149 }; 0150 0151 /* 0152 * wrapper around tty->ops->write_room to check 0153 * availability during firmware download 0154 */ 0155 int st_get_uart_wr_room(struct st_data_s *st_gdata); 0156 /** 0157 * st_int_write - 0158 * point this to tty->driver->write or tty->ops->write 0159 * depending upon the kernel version 0160 */ 0161 int st_int_write(struct st_data_s*, const unsigned char*, int); 0162 0163 /** 0164 * st_write - 0165 * internal write function, passed onto protocol drivers 0166 * via the write function ptr of protocol struct 0167 */ 0168 long st_write(struct sk_buff *); 0169 0170 /* function to be called from ST-LL */ 0171 void st_ll_send_frame(enum proto_type, struct sk_buff *); 0172 0173 /* internal wake up function */ 0174 void st_tx_wakeup(struct st_data_s *st_data); 0175 0176 /* init, exit entry funcs called from KIM */ 0177 int st_core_init(struct st_data_s **); 0178 void st_core_exit(struct st_data_s *); 0179 0180 /* ask for reference from KIM */ 0181 void st_kim_ref(struct st_data_s **, int); 0182 0183 #define GPS_STUB_TEST 0184 #ifdef GPS_STUB_TEST 0185 int gps_chrdrv_stub_write(const unsigned char*, int); 0186 void gps_chrdrv_stub_init(void); 0187 #endif 0188 0189 /* 0190 * header information used by st_kim.c 0191 */ 0192 0193 /* time in msec to wait for 0194 * line discipline to be installed 0195 */ 0196 #define LDISC_TIME 1000 0197 #define CMD_RESP_TIME 800 0198 #define CMD_WR_TIME 5000 0199 #define MAKEWORD(a, b) ((unsigned short)(((unsigned char)(a)) \ 0200 | ((unsigned short)((unsigned char)(b))) << 8)) 0201 0202 #define GPIO_HIGH 1 0203 #define GPIO_LOW 0 0204 0205 /* the Power-On-Reset logic, requires to attempt 0206 * to download firmware onto chip more than once 0207 * since the self-test for chip takes a while 0208 */ 0209 #define POR_RETRY_COUNT 5 0210 0211 /** 0212 * struct chip_version - save the chip version 0213 */ 0214 struct chip_version { 0215 unsigned short full; 0216 unsigned short chip; 0217 unsigned short min_ver; 0218 unsigned short maj_ver; 0219 }; 0220 0221 #define UART_DEV_NAME_LEN 32 0222 /** 0223 * struct kim_data_s - the KIM internal data, embedded as the 0224 * platform's drv data. One for each ST device in the system. 0225 * @uim_pid: KIM needs to communicate with UIM to request to install 0226 * the ldisc by opening UART when protocol drivers register. 0227 * @kim_pdev: the platform device added in one of the board-XX.c file 0228 * in arch/XX/ directory, 1 for each ST device. 0229 * @kim_rcvd: completion handler to notify when data was received, 0230 * mainly used during fw download, which involves multiple send/wait 0231 * for each of the HCI-VS commands. 0232 * @ldisc_installed: completion handler to notify that the UIM accepted 0233 * the request to install ldisc, notify from tty_open which suggests 0234 * the ldisc was properly installed. 0235 * @resp_buffer: data buffer for the .bts fw file name. 0236 * @fw_entry: firmware class struct to request/release the fw. 0237 * @rx_state: the rx state for kim's receive func during fw download. 0238 * @rx_count: the rx count for the kim's receive func during fw download. 0239 * @rx_skb: all of fw data might not come at once, and hence data storage for 0240 * whole of the fw response, only HCI_EVENTs and hence diff from ST's 0241 * response. 0242 * @core_data: ST core's data, which mainly is the tty's disc_data 0243 * @version: chip version available via a sysfs entry. 0244 * 0245 */ 0246 struct kim_data_s { 0247 long uim_pid; 0248 struct platform_device *kim_pdev; 0249 struct completion kim_rcvd, ldisc_installed; 0250 char resp_buffer[30]; 0251 const struct firmware *fw_entry; 0252 unsigned nshutdown; 0253 unsigned long rx_state; 0254 unsigned long rx_count; 0255 struct sk_buff *rx_skb; 0256 struct st_data_s *core_data; 0257 struct chip_version version; 0258 unsigned char ldisc_install; 0259 unsigned char dev_name[UART_DEV_NAME_LEN + 1]; 0260 unsigned flow_cntrl; 0261 unsigned baud_rate; 0262 }; 0263 0264 /** 0265 * functions called when 1 of the protocol drivers gets 0266 * registered, these need to communicate with UIM to request 0267 * ldisc installed, read chip_version, download relevant fw 0268 */ 0269 long st_kim_start(void *); 0270 long st_kim_stop(void *); 0271 0272 void st_kim_complete(void *); 0273 void kim_st_list_protocols(struct st_data_s *, void *); 0274 void st_kim_recv(void *, const unsigned char *, long); 0275 0276 0277 /* 0278 * BTS headers 0279 */ 0280 #define ACTION_SEND_COMMAND 1 0281 #define ACTION_WAIT_EVENT 2 0282 #define ACTION_SERIAL 3 0283 #define ACTION_DELAY 4 0284 #define ACTION_RUN_SCRIPT 5 0285 #define ACTION_REMARKS 6 0286 0287 /** 0288 * struct bts_header - the fw file is NOT binary which can 0289 * be sent onto TTY as is. The .bts is more a script 0290 * file which has different types of actions. 0291 * Each such action needs to be parsed by the KIM and 0292 * relevant procedure to be called. 0293 */ 0294 struct bts_header { 0295 u32 magic; 0296 u32 version; 0297 u8 future[24]; 0298 u8 actions[]; 0299 } __attribute__ ((packed)); 0300 0301 /** 0302 * struct bts_action - Each .bts action has its own type of 0303 * data. 0304 */ 0305 struct bts_action { 0306 u16 type; 0307 u16 size; 0308 u8 data[]; 0309 } __attribute__ ((packed)); 0310 0311 struct bts_action_send { 0312 u8 data[0]; 0313 } __attribute__ ((packed)); 0314 0315 struct bts_action_wait { 0316 u32 msec; 0317 u32 size; 0318 u8 data[]; 0319 } __attribute__ ((packed)); 0320 0321 struct bts_action_delay { 0322 u32 msec; 0323 } __attribute__ ((packed)); 0324 0325 struct bts_action_serial { 0326 u32 baud; 0327 u32 flow_control; 0328 } __attribute__ ((packed)); 0329 0330 /** 0331 * struct hci_command - the HCI-VS for intrepreting 0332 * the change baud rate of host-side UART, which 0333 * needs to be ignored, since UIM would do that 0334 * when it receives request from KIM for ldisc installation. 0335 */ 0336 struct hci_command { 0337 u8 prefix; 0338 u16 opcode; 0339 u8 plen; 0340 u32 speed; 0341 } __attribute__ ((packed)); 0342 0343 /* 0344 * header information used by st_ll.c 0345 */ 0346 0347 /* ST LL receiver states */ 0348 #define ST_W4_PACKET_TYPE 0 0349 #define ST_W4_HEADER 1 0350 #define ST_W4_DATA 2 0351 0352 /* ST LL state machines */ 0353 #define ST_LL_ASLEEP 0 0354 #define ST_LL_ASLEEP_TO_AWAKE 1 0355 #define ST_LL_AWAKE 2 0356 #define ST_LL_AWAKE_TO_ASLEEP 3 0357 #define ST_LL_INVALID 4 0358 0359 /* different PM notifications coming from chip */ 0360 #define LL_SLEEP_IND 0x30 0361 #define LL_SLEEP_ACK 0x31 0362 #define LL_WAKE_UP_IND 0x32 0363 #define LL_WAKE_UP_ACK 0x33 0364 0365 /* initialize and de-init ST LL */ 0366 long st_ll_init(struct st_data_s *); 0367 long st_ll_deinit(struct st_data_s *); 0368 0369 /** 0370 * enable/disable ST LL along with KIM start/stop 0371 * called by ST Core 0372 */ 0373 void st_ll_enable(struct st_data_s *); 0374 void st_ll_disable(struct st_data_s *); 0375 0376 /** 0377 * various funcs used by ST core to set/get the various PM states 0378 * of the chip. 0379 */ 0380 unsigned long st_ll_getstate(struct st_data_s *); 0381 unsigned long st_ll_sleep_state(struct st_data_s *, unsigned char); 0382 void st_ll_wakeup(struct st_data_s *); 0383 0384 /* 0385 * header information used by st_core.c for FM and GPS 0386 * packet parsing, the bluetooth headers are already available 0387 * at net/bluetooth/ 0388 */ 0389 0390 struct fm_event_hdr { 0391 u8 plen; 0392 } __attribute__ ((packed)); 0393 0394 #define FM_MAX_FRAME_SIZE 0xFF /* TODO: */ 0395 #define FM_EVENT_HDR_SIZE 1 /* size of fm_event_hdr */ 0396 #define ST_FM_CH8_PKT 0x8 0397 0398 /* gps stuff */ 0399 struct gps_event_hdr { 0400 u8 opcode; 0401 u16 plen; 0402 } __attribute__ ((packed)); 0403 0404 /** 0405 * struct ti_st_plat_data - platform data shared between ST driver and 0406 * platform specific board file which adds the ST device. 0407 * @nshutdown_gpio: Host's GPIO line to which chip's BT_EN is connected. 0408 * @dev_name: The UART/TTY name to which chip is interfaced. (eg: /dev/ttyS1) 0409 * @flow_cntrl: Should always be 1, since UART's CTS/RTS is used for PM 0410 * purposes. 0411 * @baud_rate: The baud rate supported by the Host UART controller, this will 0412 * be shared across with the chip via a HCI VS command from User-Space Init 0413 * Mgr application. 0414 * @suspend: 0415 * @resume: legacy PM routines hooked to platform specific board file, so as 0416 * to take chip-host interface specific action. 0417 * @chip_enable: 0418 * @chip_disable: Platform/Interface specific mux mode setting, GPIO 0419 * configuring, Host side PM disabling etc.. can be done here. 0420 * @chip_asleep: 0421 * @chip_awake: Chip specific deep sleep states is communicated to Host 0422 * specific board-xx.c to take actions such as cut UART clocks when chip 0423 * asleep or run host faster when chip awake etc.. 0424 * 0425 */ 0426 struct ti_st_plat_data { 0427 u32 nshutdown_gpio; 0428 unsigned char dev_name[UART_DEV_NAME_LEN]; /* uart name */ 0429 u32 flow_cntrl; /* flow control flag */ 0430 u32 baud_rate; 0431 int (*suspend)(struct platform_device *, pm_message_t); 0432 int (*resume)(struct platform_device *); 0433 int (*chip_enable) (struct kim_data_s *); 0434 int (*chip_disable) (struct kim_data_s *); 0435 int (*chip_asleep) (struct kim_data_s *); 0436 int (*chip_awake) (struct kim_data_s *); 0437 }; 0438 0439 #endif /* TI_WILINK_ST_H */
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.1.0 LXR engine. The LXR team |
![]() ![]() |