ti_wilink_st.h 13 KB

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