ti_wilink_st.h 13 KB

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