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