radio-iris.h 26 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100
  1. /*
  2. *
  3. * Copyright (c) 2011-2013 The Linux Foundation. All rights reserved.
  4. *
  5. * This file is based on include/net/bluetooth/hci_core.h
  6. *
  7. * Written 2000,2001 by Maxim Krasnyansky <maxk@qualcomm.com>
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License version 2 as
  11. * published by the Free Software Foundation;
  12. *
  13. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  14. * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  15. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS.
  16. * IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR ANY
  17. * CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES
  18. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  19. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  20. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  21. *
  22. * ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS,
  23. * COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS
  24. * SOFTWARE IS DISCLAIMED.
  25. */
  26. #ifndef __RADIO_HCI_CORE_H
  27. #define __RADIO_HCI_CORE_H
  28. #include <linux/skbuff.h>
  29. #include <linux/interrupt.h>
  30. #include <linux/mutex.h>
  31. #include <linux/atomic.h>
  32. #include "radio-iris-commands.h"
  33. #define MIN_TX_TONE_VAL 0x00
  34. #define MAX_TX_TONE_VAL 0x07
  35. #define MIN_HARD_MUTE_VAL 0x00
  36. #define MAX_HARD_MUTE_VAL 0x03
  37. #define MIN_SRCH_MODE 0x00
  38. #define MAX_SRCH_MODE 0x09
  39. #define MIN_SCAN_DWELL 0x00
  40. #define MAX_SCAN_DWELL 0x0F
  41. #define MIN_SIG_TH 0x00
  42. #define MAX_SIG_TH 0x03
  43. #define MIN_PTY 0X00
  44. #define MAX_PTY 0x1F
  45. #define MIN_PI 0x0000
  46. #define MAX_PI 0xFFFF
  47. #define MIN_SRCH_STATIONS_CNT 0x00
  48. #define MAX_SRCH_STATIONS_CNT 0x14
  49. #define MIN_CHAN_SPACING 0x00
  50. #define MAX_CHAN_SPACING 0x02
  51. #define MIN_EMPHASIS 0x00
  52. #define MAX_EMPHASIS 0x01
  53. #define MIN_RDS_STD 0x00
  54. #define MAX_RDS_STD 0x02
  55. #define MIN_ANTENNA_VAL 0x00
  56. #define MAX_ANTENNA_VAL 0x01
  57. #define MIN_TX_PS_REPEAT_CNT 0x01
  58. #define MAX_TX_PS_REPEAT_CNT 0x0F
  59. #define MIN_SOFT_MUTE 0x00
  60. #define MAX_SOFT_MUTE 0x01
  61. #define MIN_PEEK_ACCESS_LEN 0x01
  62. #define MAX_PEEK_ACCESS_LEN 0xF9
  63. #define MIN_RESET_CNTR 0x00
  64. #define MAX_RESET_CNTR 0x01
  65. #define MIN_HLSI 0x00
  66. #define MAX_HLSI 0x02
  67. #define MIN_NOTCH_FILTER 0x00
  68. #define MAX_NOTCH_FILTER 0x02
  69. #define MIN_INTF_DET_OUT_LW_TH 0x00
  70. #define MAX_INTF_DET_OUT_LW_TH 0xFF
  71. #define MIN_INTF_DET_OUT_HG_TH 0x00
  72. #define MAX_INTF_DET_OUT_HG_TH 0xFF
  73. #define MIN_SINR_TH -128
  74. #define MAX_SINR_TH 127
  75. #define MIN_SINR_SAMPLES 0x01
  76. #define MAX_SINR_SAMPLES 0xFF
  77. /* ---- HCI Packet structures ---- */
  78. #define RADIO_HCI_COMMAND_HDR_SIZE sizeof(struct radio_hci_command_hdr)
  79. #define RADIO_HCI_EVENT_HDR_SIZE sizeof(struct radio_hci_event_hdr)
  80. /* HCI data types */
  81. #define RADIO_HCI_COMMAND_PKT 0x11
  82. #define RADIO_HCI_EVENT_PKT 0x14
  83. /*HCI reponce packets*/
  84. #define MAX_RIVA_PEEK_RSP_SIZE 251
  85. /* default data access */
  86. #define DEFAULT_DATA_OFFSET 2
  87. #define DEFAULT_DATA_SIZE 249
  88. /* Power levels are 0-7, but SOC will expect values from 0-255
  89. * So the each level step size will be 255/7 = 36 */
  90. #define FM_TX_PWR_LVL_STEP_SIZE 36
  91. #define FM_TX_PWR_LVL_0 0 /* Lowest power lvl that can be set for Tx */
  92. #define FM_TX_PWR_LVL_MAX 7 /* Max power lvl for Tx */
  93. #define FM_TX_PHY_CFG_MODE 0x3c
  94. #define FM_TX_PHY_CFG_LEN 0x10
  95. #define FM_TX_PWR_GAIN_OFFSET 14
  96. /**RDS CONFIG MODE**/
  97. #define FM_RDS_CNFG_MODE 0x0f
  98. #define FM_RDS_CNFG_LEN 0x10
  99. #define AF_RMSSI_TH_LSB_OFFSET 10
  100. #define AF_RMSSI_TH_MSB_OFFSET 11
  101. #define AF_RMSSI_SAMPLES_OFFSET 15
  102. /**RX CONFIG MODE**/
  103. #define FM_RX_CONFG_MODE 0x15
  104. #define FM_RX_CNFG_LEN 0x20
  105. #define GD_CH_RMSSI_TH_OFFSET 12
  106. #define MAX_GD_CH_RMSSI_TH 127
  107. #define SRCH_ALGO_TYPE_OFFSET 25
  108. #define SINRFIRSTSTAGE_OFFSET 26
  109. #define RMSSIFIRSTSTAGE_OFFSET 27
  110. #define CF0TH12_BYTE1_OFFSET 8
  111. #define CF0TH12_BYTE2_OFFSET 9
  112. #define CF0TH12_BYTE3_OFFSET 10
  113. #define CF0TH12_BYTE4_OFFSET 11
  114. #define MAX_SINR_FIRSTSTAGE 127
  115. #define MAX_RMSSI_FIRSTSTAGE 127
  116. #define RDS_PS0_XFR_MODE 0x01
  117. #define RDS_PS0_LEN 6
  118. #define RX_REPEATE_BYTE_OFFSET 5
  119. #define FM_AF_LIST_MAX_SIZE 200
  120. #define AF_LIST_MAX (FM_AF_LIST_MAX_SIZE / 4) /* Each AF frequency consist
  121. of sizeof(int) bytes */
  122. /* HCI timeouts */
  123. #define RADIO_HCI_TIMEOUT (10000) /* 10 seconds */
  124. #define TUNE_PARAM 16
  125. #define AF_JMP_TUNE 0x03
  126. /**DIGITAL AUDIO 0 MODE**/
  127. #define DIG_AUDIO_0_MODE 0x2B
  128. #define DIG_AUDIO_0_LEN 0x10
  129. #define SMUTE_TH_OFFSET 2
  130. #define MAX_SOFTMUTE_TH 127
  131. struct radio_hci_command_hdr {
  132. __le16 opcode; /* OCF & OGF */
  133. __u8 plen;
  134. } __packed;
  135. struct radio_hci_event_hdr {
  136. __u8 evt;
  137. __u8 plen;
  138. } __packed;
  139. struct radio_hci_dev {
  140. char name[8];
  141. unsigned long flags;
  142. __u16 id;
  143. __u8 bus;
  144. __u8 dev_type;
  145. __u8 dev_name[248];
  146. __u8 dev_class[3];
  147. __u8 features[8];
  148. __u8 commands[64];
  149. unsigned int data_block_len;
  150. unsigned long cmd_last_tx;
  151. struct sk_buff *sent_cmd;
  152. __u32 req_status;
  153. __u32 req_result;
  154. atomic_t cmd_cnt;
  155. struct tasklet_struct cmd_task;
  156. struct tasklet_struct rx_task;
  157. struct tasklet_struct tx_task;
  158. struct sk_buff_head rx_q;
  159. struct sk_buff_head raw_q;
  160. struct sk_buff_head cmd_q;
  161. struct mutex req_lock;
  162. wait_queue_head_t req_wait_q;
  163. int (*open)(struct radio_hci_dev *hdev);
  164. int (*close)(struct radio_hci_dev *hdev);
  165. int (*flush)(struct radio_hci_dev *hdev);
  166. int (*send)(struct sk_buff *skb);
  167. void (*destruct)(struct radio_hci_dev *hdev);
  168. void (*notify)(struct radio_hci_dev *hdev, unsigned int evt);
  169. void (*close_smd)(void);
  170. };
  171. int radio_hci_register_dev(struct radio_hci_dev *hdev);
  172. int radio_hci_unregister_dev(struct radio_hci_dev *hdev);
  173. int radio_hci_recv_frame(struct sk_buff *skb);
  174. int radio_hci_send_cmd(struct radio_hci_dev *hdev, __u16 opcode, __u32 plen,
  175. void *param);
  176. void radio_hci_event_packet(struct radio_hci_dev *hdev, struct sk_buff *skb);
  177. /* Opcode OCF */
  178. /* HCI recv control commands opcode */
  179. #define HCI_OCF_FM_ENABLE_RECV_REQ 0x0001
  180. #define HCI_OCF_FM_DISABLE_RECV_REQ 0x0002
  181. #define HCI_OCF_FM_GET_RECV_CONF_REQ 0x0003
  182. #define HCI_OCF_FM_SET_RECV_CONF_REQ 0x0004
  183. #define HCI_OCF_FM_SET_MUTE_MODE_REQ 0x0005
  184. #define HCI_OCF_FM_SET_STEREO_MODE_REQ 0x0006
  185. #define HCI_OCF_FM_SET_ANTENNA 0x0007
  186. #define HCI_OCF_FM_SET_SIGNAL_THRESHOLD 0x0008
  187. #define HCI_OCF_FM_GET_SIGNAL_THRESHOLD 0x0009
  188. #define HCI_OCF_FM_GET_STATION_PARAM_REQ 0x000A
  189. #define HCI_OCF_FM_GET_PROGRAM_SERVICE_REQ 0x000B
  190. #define HCI_OCF_FM_GET_RADIO_TEXT_REQ 0x000C
  191. #define HCI_OCF_FM_GET_AF_LIST_REQ 0x000D
  192. #define HCI_OCF_FM_SEARCH_STATIONS 0x000E
  193. #define HCI_OCF_FM_SEARCH_RDS_STATIONS 0x000F
  194. #define HCI_OCF_FM_SEARCH_STATIONS_LIST 0x0010
  195. #define HCI_OCF_FM_CANCEL_SEARCH 0x0011
  196. #define HCI_OCF_FM_RDS_GRP 0x0012
  197. #define HCI_OCF_FM_RDS_GRP_PROCESS 0x0013
  198. #define HCI_OCF_FM_EN_WAN_AVD_CTRL 0x0014
  199. #define HCI_OCF_FM_EN_NOTCH_CTRL 0x0015
  200. #define HCI_OCF_FM_SET_EVENT_MASK 0x0016
  201. #define HCI_OCF_FM_SET_CH_DET_THRESHOLD 0x0017
  202. #define HCI_OCF_FM_GET_CH_DET_THRESHOLD 0x0018
  203. /* HCI trans control commans opcode*/
  204. #define HCI_OCF_FM_ENABLE_TRANS_REQ 0x0001
  205. #define HCI_OCF_FM_DISABLE_TRANS_REQ 0x0002
  206. #define HCI_OCF_FM_GET_TRANS_CONF_REQ 0x0003
  207. #define HCI_OCF_FM_SET_TRANS_CONF_REQ 0x0004
  208. #define HCI_OCF_FM_RDS_RT_REQ 0x0008
  209. #define HCI_OCF_FM_RDS_PS_REQ 0x0009
  210. /* HCI common control commands opcode */
  211. #define HCI_OCF_FM_TUNE_STATION_REQ 0x0001
  212. #define HCI_OCF_FM_DEFAULT_DATA_READ 0x0002
  213. #define HCI_OCF_FM_DEFAULT_DATA_WRITE 0x0003
  214. #define HCI_OCF_FM_RESET 0x0004
  215. #define HCI_OCF_FM_GET_FEATURE_LIST 0x0005
  216. #define HCI_OCF_FM_DO_CALIBRATION 0x0006
  217. #define HCI_OCF_FM_SET_CALIBRATION 0x0007
  218. /*HCI Status parameters commands*/
  219. #define HCI_OCF_FM_READ_GRP_COUNTERS 0x0001
  220. /*HCI Diagnostic commands*/
  221. #define HCI_OCF_FM_PEEK_DATA 0x0002
  222. #define HCI_OCF_FM_POKE_DATA 0x0003
  223. #define HCI_OCF_FM_SSBI_PEEK_REG 0x0004
  224. #define HCI_OCF_FM_SSBI_POKE_REG 0x0005
  225. #define HCI_OCF_FM_STATION_DBG_PARAM 0x0007
  226. #define HCI_FM_SET_INTERNAL_TONE_GENRATOR 0x0008
  227. /* Opcode OGF */
  228. #define HCI_OGF_FM_RECV_CTRL_CMD_REQ 0x0013
  229. #define HCI_OGF_FM_TRANS_CTRL_CMD_REQ 0x0014
  230. #define HCI_OGF_FM_COMMON_CTRL_CMD_REQ 0x0015
  231. #define HCI_OGF_FM_STATUS_PARAMETERS_CMD_REQ 0x0016
  232. #define HCI_OGF_FM_TEST_CMD_REQ 0x0017
  233. #define HCI_OGF_FM_DIAGNOSTIC_CMD_REQ 0x003F
  234. /* Command opcode pack/unpack */
  235. #define hci_opcode_pack(ogf, ocf) (__u16) ((ocf & 0x03ff)|(ogf << 10))
  236. #define hci_opcode_ogf(op) (op >> 10)
  237. #define hci_opcode_ocf(op) (op & 0x03ff)
  238. #define hci_recv_ctrl_cmd_op_pack(ocf) \
  239. (__u16) hci_opcode_pack(HCI_OGF_FM_RECV_CTRL_CMD_REQ, ocf)
  240. #define hci_trans_ctrl_cmd_op_pack(ocf) \
  241. (__u16) hci_opcode_pack(HCI_OGF_FM_TRANS_CTRL_CMD_REQ, ocf)
  242. #define hci_common_cmd_op_pack(ocf) \
  243. (__u16) hci_opcode_pack(HCI_OGF_FM_COMMON_CTRL_CMD_REQ, ocf)
  244. #define hci_status_param_op_pack(ocf) \
  245. (__u16) hci_opcode_pack(HCI_OGF_FM_STATUS_PARAMETERS_CMD_REQ, ocf)
  246. #define hci_diagnostic_cmd_op_pack(ocf) \
  247. (__u16) hci_opcode_pack(HCI_OGF_FM_DIAGNOSTIC_CMD_REQ, ocf)
  248. /* HCI commands with no arguments*/
  249. #define HCI_FM_ENABLE_RECV_CMD 1
  250. #define HCI_FM_DISABLE_RECV_CMD 2
  251. #define HCI_FM_GET_RECV_CONF_CMD 3
  252. #define HCI_FM_GET_STATION_PARAM_CMD 4
  253. #define HCI_FM_GET_SIGNAL_TH_CMD 5
  254. #define HCI_FM_GET_PROGRAM_SERVICE_CMD 6
  255. #define HCI_FM_GET_RADIO_TEXT_CMD 7
  256. #define HCI_FM_GET_AF_LIST_CMD 8
  257. #define HCI_FM_CANCEL_SEARCH_CMD 9
  258. #define HCI_FM_RESET_CMD 10
  259. #define HCI_FM_GET_FEATURES_CMD 11
  260. #define HCI_FM_STATION_DBG_PARAM_CMD 12
  261. #define HCI_FM_ENABLE_TRANS_CMD 13
  262. #define HCI_FM_DISABLE_TRANS_CMD 14
  263. #define HCI_FM_GET_TX_CONFIG 15
  264. #define HCI_FM_GET_DET_CH_TH_CMD 16
  265. /* Defines for FM TX*/
  266. #define TX_PS_DATA_LENGTH 108
  267. #define TX_RT_DATA_LENGTH 64
  268. #define PS_STRING_LEN 9
  269. /* ----- HCI Command request ----- */
  270. struct hci_fm_recv_conf_req {
  271. __u8 emphasis;
  272. __u8 ch_spacing;
  273. __u8 rds_std;
  274. __u8 hlsi;
  275. __u32 band_low_limit;
  276. __u32 band_high_limit;
  277. } __packed;
  278. /* ----- HCI Command request ----- */
  279. struct hci_fm_trans_conf_req_struct {
  280. __u8 emphasis;
  281. __u8 rds_std;
  282. __u32 band_low_limit;
  283. __u32 band_high_limit;
  284. } __packed;
  285. /* ----- HCI Command request ----- */
  286. struct hci_fm_tx_ps {
  287. __u8 ps_control;
  288. __u16 pi;
  289. __u8 pty;
  290. __u8 ps_repeatcount;
  291. __u8 ps_num;
  292. __u8 ps_data[TX_PS_DATA_LENGTH];
  293. } __packed;
  294. struct hci_fm_tx_rt {
  295. __u8 rt_control;
  296. __u16 pi;
  297. __u8 pty;
  298. __u8 rt_len;
  299. __u8 rt_data[TX_RT_DATA_LENGTH];
  300. } __packed;
  301. struct hci_fm_mute_mode_req {
  302. __u8 hard_mute;
  303. __u8 soft_mute;
  304. } __packed;
  305. struct hci_fm_stereo_mode_req {
  306. __u8 stereo_mode;
  307. __u8 sig_blend;
  308. __u8 intf_blend;
  309. __u8 most_switch;
  310. } __packed;
  311. struct hci_fm_search_station_req {
  312. __u8 srch_mode;
  313. __u8 scan_time;
  314. __u8 srch_dir;
  315. } __packed;
  316. struct hci_fm_search_rds_station_req {
  317. struct hci_fm_search_station_req srch_station;
  318. __u8 srch_pty;
  319. __u16 srch_pi;
  320. } __packed;
  321. struct hci_fm_search_station_list_req {
  322. __u8 srch_list_mode;
  323. __u8 srch_list_dir;
  324. __u32 srch_list_max;
  325. __u8 srch_pty;
  326. } __packed;
  327. struct hci_fm_rds_grp_req {
  328. __u32 rds_grp_enable_mask;
  329. __u32 rds_buf_size;
  330. __u8 en_rds_change_filter;
  331. } __packed;
  332. struct hci_fm_en_avd_ctrl_req {
  333. __u8 no_freqs;
  334. __u8 freq_index;
  335. __u8 lo_shft;
  336. __u16 freq_min;
  337. __u16 freq_max;
  338. } __packed;
  339. struct hci_fm_def_data_rd_req {
  340. __u8 mode;
  341. __u8 length;
  342. __u8 param_len;
  343. __u8 param;
  344. } __packed;
  345. struct hci_fm_def_data_wr_req {
  346. __u8 mode;
  347. __u8 length;
  348. __u8 data[DEFAULT_DATA_SIZE];
  349. } __packed;
  350. struct hci_fm_riva_data {
  351. __u8 subopcode;
  352. __u32 start_addr;
  353. __u8 length;
  354. } __packed;
  355. struct hci_fm_riva_poke {
  356. struct hci_fm_riva_data cmd_params;
  357. __u8 data[MAX_RIVA_PEEK_RSP_SIZE];
  358. } __packed;
  359. struct hci_fm_ssbi_req {
  360. __u16 start_addr;
  361. __u8 data;
  362. } __packed;
  363. struct hci_fm_ssbi_peek {
  364. __u16 start_address;
  365. } __packed;
  366. struct hci_fm_ch_det_threshold {
  367. signed char sinr;
  368. __u8 sinr_samples;
  369. __u8 low_th;
  370. __u8 high_th;
  371. } __packed;
  372. /*HCI events*/
  373. #define HCI_EV_TUNE_STATUS 0x01
  374. #define HCI_EV_RDS_LOCK_STATUS 0x02
  375. #define HCI_EV_STEREO_STATUS 0x03
  376. #define HCI_EV_SERVICE_AVAILABLE 0x04
  377. #define HCI_EV_SEARCH_PROGRESS 0x05
  378. #define HCI_EV_SEARCH_RDS_PROGRESS 0x06
  379. #define HCI_EV_SEARCH_LIST_PROGRESS 0x07
  380. #define HCI_EV_RDS_RX_DATA 0x08
  381. #define HCI_EV_PROGRAM_SERVICE 0x09
  382. #define HCI_EV_RADIO_TEXT 0x0A
  383. #define HCI_EV_FM_AF_LIST 0x0B
  384. #define HCI_EV_TX_RDS_GRP_AVBLE 0x0C
  385. #define HCI_EV_TX_RDS_GRP_COMPL 0x0D
  386. #define HCI_EV_TX_RDS_CONT_GRP_COMPL 0x0E
  387. #define HCI_EV_CMD_COMPLETE 0x0F
  388. #define HCI_EV_CMD_STATUS 0x10
  389. #define HCI_EV_TUNE_COMPLETE 0x11
  390. #define HCI_EV_SEARCH_COMPLETE 0x12
  391. #define HCI_EV_SEARCH_RDS_COMPLETE 0x13
  392. #define HCI_EV_SEARCH_LIST_COMPLETE 0x14
  393. #define HCI_REQ_DONE 0
  394. #define HCI_REQ_PEND 1
  395. #define HCI_REQ_CANCELED 2
  396. #define HCI_REQ_STATUS 3
  397. #define MAX_RAW_RDS_GRPS 21
  398. #define RDSGRP_DATA_OFFSET 0x1
  399. #define RDS_GRPS_ALL 0xFFFFFFFF
  400. /*RT PLUS*/
  401. #define DUMMY_CLASS 0
  402. #define RT_PLUS_LEN_1_TAG 3
  403. #define RT_ERT_FLAG_BIT 5
  404. #define ITEM_TOGGLE_BIT 4
  405. #define ITEM_RUNNING_BIT 3
  406. /*TAG1*/
  407. #define TAG1_MSB_OFFSET 3
  408. #define TAG1_MSB_MASK 7
  409. #define TAG1_LSB_OFFSET 5
  410. #define TAG1_POS_MSB_MASK 31
  411. #define TAG1_POS_MSB_OFFSET 1
  412. #define TAG1_POS_LSB_OFFSET 7
  413. #define TAG1_LEN_OFFSET 1
  414. #define TAG1_LEN_MASK 63
  415. /*TAG2*/
  416. #define TAG2_MSB_OFFSET 5
  417. #define TAG2_MSB_MASK 1
  418. #define TAG2_LSB_OFFSET 3
  419. #define TAG2_POS_MSB_MASK 7
  420. #define TAG2_POS_MSB_OFFSET 3
  421. #define TAG2_POS_LSB_OFFSET 5
  422. #define TAG2_LEN_MASK 31
  423. #define AGT_MASK 31
  424. /*Extract 5 left most bits of lsb of 2nd block*/
  425. #define AGT(x) (x & AGT_MASK)
  426. /*16 bits of 4th block*/
  427. #define AID(lsb, msb) ((msb << 8) | (lsb))
  428. /*Extract 5 right most bits of msb of 2nd block*/
  429. #define GTC(blk2msb) (blk2msb >> 3)
  430. #define GRP_3A 0x6
  431. #define RT_PLUS_AID 0x4bd7
  432. /*ERT*/
  433. #define ERT_AID 0x6552
  434. #define CARRIAGE_RETURN 0x000D
  435. #define MAX_ERT_SEGMENT 31
  436. #define ERT_FORMAT_DIR_BIT 1
  437. #define EXTRACT_BIT(data, bit_pos) ((data & (1 << bit_pos)) >> bit_pos)
  438. struct hci_ev_tune_status {
  439. __u8 sub_event;
  440. __le32 station_freq;
  441. __u8 serv_avble;
  442. __u8 rssi;
  443. __u8 stereo_prg;
  444. __u8 rds_sync_status;
  445. __u8 mute_mode;
  446. char sinr;
  447. __u8 intf_det_th;
  448. } __packed;
  449. struct rds_blk_data {
  450. __u8 rdsMsb;
  451. __u8 rdsLsb;
  452. __u8 blockStatus;
  453. } __packed;
  454. struct rds_grp_data {
  455. struct rds_blk_data rdsBlk[4];
  456. } __packed;
  457. struct hci_ev_rds_rx_data {
  458. __u8 num_rds_grps;
  459. struct rds_grp_data rds_grp_data[MAX_RAW_RDS_GRPS];
  460. } __packed;
  461. struct hci_ev_prg_service {
  462. __le16 pi_prg_id;
  463. __u8 pty_prg_type;
  464. __u8 ta_prg_code_type;
  465. __u8 ta_ann_code_flag;
  466. __u8 ms_switch_code_flag;
  467. __u8 dec_id_ctrl_code_flag;
  468. __u8 ps_num;
  469. __u8 prg_service_name[119];
  470. } __packed;
  471. struct hci_ev_radio_text {
  472. __le16 pi_prg_id;
  473. __u8 pty_prg_type;
  474. __u8 ta_prg_code_type;
  475. __u8 txt_ab_flag;
  476. __u8 radio_txt[64];
  477. } __packed;
  478. struct hci_ev_af_list {
  479. __le32 tune_freq;
  480. __le16 pi_code;
  481. __u8 af_size;
  482. __u8 af_list[FM_AF_LIST_MAX_SIZE];
  483. } __packed;
  484. struct hci_ev_cmd_complete {
  485. __u8 num_hci_cmd_pkts;
  486. __le16 cmd_opcode;
  487. } __packed;
  488. struct hci_ev_cmd_status {
  489. __u8 status;
  490. __u8 num_hci_cmd_pkts;
  491. __le16 status_opcode;
  492. } __packed;
  493. struct hci_ev_srch_st {
  494. __le32 station_freq;
  495. __u8 rds_cap;
  496. __u8 pty;
  497. __le16 status_opcode;
  498. } __packed;
  499. struct hci_ev_rel_freq {
  500. __u8 rel_freq_msb;
  501. __u8 rel_freq_lsb;
  502. } __packed;
  503. struct hci_ev_srch_list_compl {
  504. __u8 num_stations_found;
  505. struct hci_ev_rel_freq rel_freq[20];
  506. } __packed;
  507. /* ----- HCI Event Response ----- */
  508. struct hci_fm_conf_rsp {
  509. __u8 status;
  510. struct hci_fm_recv_conf_req recv_conf_rsp;
  511. } __packed;
  512. struct hci_fm_get_trans_conf_rsp {
  513. __u8 status;
  514. struct hci_fm_trans_conf_req_struct trans_conf_rsp;
  515. } __packed;
  516. struct hci_fm_sig_threshold_rsp {
  517. __u8 status;
  518. __u8 sig_threshold;
  519. } __packed;
  520. struct hci_fm_station_rsp {
  521. struct hci_ev_tune_status station_rsp;
  522. } __packed;
  523. struct hci_fm_prgm_srv_rsp {
  524. __u8 status;
  525. struct hci_ev_prg_service prg_srv;
  526. } __packed;
  527. struct hci_fm_radio_txt_rsp {
  528. __u8 status;
  529. struct hci_ev_radio_text rd_txt;
  530. } __packed;
  531. struct hci_fm_af_list_rsp {
  532. __u8 status;
  533. struct hci_ev_af_list rd_txt;
  534. } __packed;
  535. struct hci_fm_data_rd_rsp {
  536. __u8 status;
  537. __u8 ret_data_len;
  538. __u8 data[DEFAULT_DATA_SIZE];
  539. } __packed;
  540. struct hci_fm_feature_list_rsp {
  541. __u8 status;
  542. __u8 feature_mask;
  543. } __packed;
  544. struct hci_fm_dbg_param_rsp {
  545. __u8 status;
  546. __u8 blend;
  547. __u8 soft_mute;
  548. __u8 inf_blend;
  549. __u8 inf_soft_mute;
  550. __u8 pilot_pil;
  551. __u8 io_verc;
  552. __u8 in_det_out;
  553. } __packed;
  554. #define CLKSPURID_INDEX0 0
  555. #define CLKSPURID_INDEX1 5
  556. #define CLKSPURID_INDEX2 10
  557. #define CLKSPURID_INDEX3 15
  558. #define CLKSPURID_INDEX4 20
  559. #define CLKSPURID_INDEX5 25
  560. #define MAX_SPUR_FREQ_LIMIT 30
  561. #define CKK_SPUR 0x3B
  562. #define SPUR_DATA_SIZE 0x4
  563. #define SPUR_ENTRIES_PER_ID 0x5
  564. #define COMPUTE_SPUR(val) ((((val) - (76000)) / (50)))
  565. #define GET_FREQ(val, bit) ((bit == 1) ? ((val) >> 8) : ((val) & 0xFF))
  566. #define GET_SPUR_ENTRY_LEVEL(val) ((val) / (5))
  567. struct hci_fm_spur_data {
  568. __u32 freq[MAX_SPUR_FREQ_LIMIT];
  569. __s8 rmssi[MAX_SPUR_FREQ_LIMIT];
  570. __u8 enable[MAX_SPUR_FREQ_LIMIT];
  571. } __packed;
  572. /* HCI dev events */
  573. #define RADIO_HCI_DEV_REG 1
  574. #define RADIO_HCI_DEV_WRITE 2
  575. #define hci_req_lock(d) mutex_lock(&d->req_lock)
  576. #define hci_req_unlock(d) mutex_unlock(&d->req_lock)
  577. /* FM RDS */
  578. #define RDS_PTYPE 2
  579. #define RDS_PID_LOWER 1
  580. #define RDS_PID_HIGHER 0
  581. #define RDS_OFFSET 5
  582. #define RDS_PS_LENGTH_OFFSET 7
  583. #define RDS_STRING 8
  584. #define RDS_PS_DATA_OFFSET 8
  585. #define RDS_CONFIG_OFFSET 3
  586. #define RDS_AF_JUMP_OFFSET 4
  587. #define RDS_RT_OFFSET 0
  588. #define RDS_PS_ALL_OFFSET 1
  589. #define RDS_PS_SIMPLE_OFFSET 2
  590. #define RDS_AF_LIST_OFFSET 3
  591. #define RDS_GRP_3A 6
  592. #define PI_CODE_OFFSET 4
  593. #define AF_SIZE_OFFSET 6
  594. #define AF_LIST_OFFSET 7
  595. #define RT_A_B_FLAG_OFFSET 4
  596. /*FM states*/
  597. enum radio_state_t {
  598. FM_OFF,
  599. FM_RECV,
  600. FM_TRANS,
  601. FM_RESET,
  602. FM_CALIB,
  603. FM_TURNING_OFF,
  604. FM_RECV_TURNING_ON,
  605. FM_TRANS_TURNING_ON,
  606. FM_MAX_NO_STATES,
  607. };
  608. enum emphasis_type {
  609. FM_RX_EMP75 = 0x0,
  610. FM_RX_EMP50 = 0x1
  611. };
  612. enum channel_space_type {
  613. FM_RX_SPACE_200KHZ = 0x0,
  614. FM_RX_SPACE_100KHZ = 0x1,
  615. FM_RX_SPACE_50KHZ = 0x2
  616. };
  617. enum high_low_injection {
  618. AUTO_HI_LO_INJECTION = 0x0,
  619. LOW_SIDE_INJECTION = 0x1,
  620. HIGH_SIDE_INJECTION = 0x2
  621. };
  622. enum fm_rds_type {
  623. FM_RX_RDBS_SYSTEM = 0x0,
  624. FM_RX_RDS_SYSTEM = 0x1
  625. };
  626. enum iris_region_t {
  627. IRIS_REGION_US,
  628. IRIS_REGION_EU,
  629. IRIS_REGION_JAPAN,
  630. IRIS_REGION_JAPAN_WIDE,
  631. IRIS_REGION_OTHER
  632. };
  633. #define STD_BUF_SIZE (256)
  634. enum iris_buf_t {
  635. IRIS_BUF_SRCH_LIST,
  636. IRIS_BUF_EVENTS,
  637. IRIS_BUF_RT_RDS,
  638. IRIS_BUF_PS_RDS,
  639. IRIS_BUF_RAW_RDS,
  640. IRIS_BUF_AF_LIST,
  641. IRIS_BUF_PEEK,
  642. IRIS_BUF_SSBI_PEEK,
  643. IRIS_BUF_RDS_CNTRS,
  644. IRIS_BUF_RD_DEFAULT,
  645. IRIS_BUF_CAL_DATA,
  646. IRIS_BUF_RT_PLUS,
  647. IRIS_BUF_ERT,
  648. IRIS_BUF_MAX,
  649. };
  650. enum iris_xfr_t {
  651. IRIS_XFR_SYNC,
  652. IRIS_XFR_ERROR,
  653. IRIS_XFR_SRCH_LIST,
  654. IRIS_XFR_RT_RDS,
  655. IRIS_XFR_PS_RDS,
  656. IRIS_XFR_AF_LIST,
  657. IRIS_XFR_MAX
  658. };
  659. #undef FMDBG
  660. #ifdef FM_DEBUG
  661. #define FMDBG(fmt, args...) pr_info("iris_radio: " fmt, ##args)
  662. #else
  663. #define FMDBG(fmt, args...)
  664. #endif
  665. #undef FMDERR
  666. #define FMDERR(fmt, args...) pr_err("iris_radio: " fmt, ##args)
  667. /* Search options */
  668. enum search_t {
  669. SEEK,
  670. SCAN,
  671. SCAN_FOR_STRONG,
  672. SCAN_FOR_WEAK,
  673. RDS_SEEK_PTY,
  674. RDS_SCAN_PTY,
  675. RDS_SEEK_PI,
  676. RDS_AF_JUMP,
  677. };
  678. enum spur_entry_levels {
  679. ENTRY_0,
  680. ENTRY_1,
  681. ENTRY_2,
  682. ENTRY_3,
  683. ENTRY_4,
  684. ENTRY_5,
  685. };
  686. /* Band limits */
  687. #define REGION_US_EU_BAND_LOW 87500
  688. #define REGION_US_EU_BAND_HIGH 108000
  689. #define REGION_JAPAN_STANDARD_BAND_LOW 76000
  690. #define REGION_JAPAN_STANDARD_BAND_HIGH 90000
  691. #define REGION_JAPAN_WIDE_BAND_LOW 90000
  692. #define REGION_JAPAN_WIDE_BAND_HIGH 108000
  693. #define SRCH_MODE 0x07
  694. #define SRCH_DIR 0x08 /* 0-up 1-down */
  695. #define SCAN_DWELL 0x70
  696. #define SRCH_ON 0x80
  697. /* I/O Control */
  698. #define IOC_HRD_MUTE 0x03
  699. #define IOC_SFT_MUTE 0x01
  700. #define IOC_MON_STR 0x01
  701. #define IOC_SIG_BLND 0x01
  702. #define IOC_INTF_BLND 0x01
  703. #define IOC_ANTENNA 0x01
  704. /* RDS Control */
  705. #define RDS_ON 0x01
  706. #define RDS_BUF_SZ 100
  707. /* constants */
  708. #define RDS_BLOCKS_NUM (4)
  709. #define BYTES_PER_BLOCK (3)
  710. #define MAX_PS_LENGTH (108)
  711. #define MAX_RT_LENGTH (64)
  712. #define RDS_GRP_CNTR_LEN (36)
  713. #define RX_RT_DATA_LENGTH (63)
  714. /* Search direction */
  715. #define SRCH_DIR_UP (0)
  716. #define SRCH_DIR_DOWN (1)
  717. /*Search RDS stations*/
  718. #define SEARCH_RDS_STNS_MODE_OFFSET 4
  719. /*Search Station list */
  720. #define PARAMS_PER_STATION 0x08
  721. #define STN_NUM_OFFSET 0x01
  722. #define STN_FREQ_OFFSET 0x02
  723. #define KHZ_TO_MHZ 1000
  724. #define GET_MSB(x)((x >> 8) & 0xFF)
  725. #define GET_LSB(x)((x) & 0xFF)
  726. /* control options */
  727. #define CTRL_ON (1)
  728. #define CTRL_OFF (0)
  729. /*Diagnostic commands*/
  730. #define RIVA_PEEK_OPCODE 0x0D
  731. #define RIVA_POKE_OPCODE 0x0C
  732. #define PEEK_DATA_OFSET 0x1
  733. #define RIVA_PEEK_PARAM 0x6
  734. #define RIVA_PEEK_LEN_OFSET 0x6
  735. #define SSBI_PEEK_LEN 0x01
  736. /*Calibration data*/
  737. #define PROCS_CALIB_MODE 1
  738. #define PROCS_CALIB_SIZE 23
  739. #define DC_CALIB_MODE 2
  740. #define DC_CALIB_SIZE 48
  741. #define RSB_CALIB_MODE 3
  742. #define RSB_CALIB_SIZE 4
  743. #define CALIB_DATA_OFSET 2
  744. #define CALIB_MODE_OFSET 1
  745. #define MAX_CALIB_SIZE 75
  746. /* Channel validity */
  747. #define INVALID_CHANNEL (0)
  748. #define VALID_CHANNEL (1)
  749. struct hci_fm_set_cal_req_proc {
  750. __u8 mode;
  751. /*Max process calibration data size*/
  752. __u8 data[PROCS_CALIB_SIZE];
  753. } __packed;
  754. struct hci_fm_set_cal_req_dc {
  755. __u8 mode;
  756. /*Max DC calibration data size*/
  757. __u8 data[DC_CALIB_SIZE];
  758. } __packed;
  759. struct hci_cc_do_calibration_rsp {
  760. __u8 status;
  761. __u8 mode;
  762. __u8 data[MAX_CALIB_SIZE];
  763. } __packed;
  764. /* Low Power mode*/
  765. #define SIG_LEVEL_INTR (1 << 0)
  766. #define RDS_SYNC_INTR (1 << 1)
  767. #define AUDIO_CTRL_INTR (1 << 2)
  768. #define AF_JUMP_ENABLE (1 << 4)
  769. int hci_def_data_read(struct hci_fm_def_data_rd_req *arg,
  770. struct radio_hci_dev *hdev);
  771. int hci_def_data_write(struct hci_fm_def_data_wr_req *arg,
  772. struct radio_hci_dev *hdev);
  773. int hci_fm_do_calibration(__u8 *arg, struct radio_hci_dev *hdev);
  774. int hci_fm_do_calibration(__u8 *arg, struct radio_hci_dev *hdev);
  775. static inline int is_valid_tone(int tone)
  776. {
  777. if ((tone >= MIN_TX_TONE_VAL) &&
  778. (tone <= MAX_TX_TONE_VAL))
  779. return 1;
  780. else
  781. return 0;
  782. }
  783. static inline int is_valid_hard_mute(int hard_mute)
  784. {
  785. if ((hard_mute >= MIN_HARD_MUTE_VAL) &&
  786. (hard_mute <= MAX_HARD_MUTE_VAL))
  787. return 1;
  788. else
  789. return 0;
  790. }
  791. static inline int is_valid_srch_mode(int srch_mode)
  792. {
  793. if ((srch_mode >= MIN_SRCH_MODE) &&
  794. (srch_mode <= MAX_SRCH_MODE))
  795. return 1;
  796. else
  797. return 0;
  798. }
  799. static inline int is_valid_scan_dwell_prd(int scan_dwell_prd)
  800. {
  801. if ((scan_dwell_prd >= MIN_SCAN_DWELL) &&
  802. (scan_dwell_prd <= MAX_SCAN_DWELL))
  803. return 1;
  804. else
  805. return 0;
  806. }
  807. static inline int is_valid_sig_th(int sig_th)
  808. {
  809. if ((sig_th >= MIN_SIG_TH) &&
  810. (sig_th <= MAX_SIG_TH))
  811. return 1;
  812. else
  813. return 0;
  814. }
  815. static inline int is_valid_pty(int pty)
  816. {
  817. if ((pty >= MIN_PTY) &&
  818. (pty <= MAX_PTY))
  819. return 1;
  820. else
  821. return 0;
  822. }
  823. static inline int is_valid_pi(int pi)
  824. {
  825. if ((pi >= MIN_PI) &&
  826. (pi <= MAX_PI))
  827. return 1;
  828. else
  829. return 0;
  830. }
  831. static inline int is_valid_srch_station_cnt(int cnt)
  832. {
  833. if ((cnt >= MIN_SRCH_STATIONS_CNT) &&
  834. (cnt <= MAX_SRCH_STATIONS_CNT))
  835. return 1;
  836. else
  837. return 0;
  838. }
  839. static inline int is_valid_chan_spacing(int spacing)
  840. {
  841. if ((spacing >= MIN_CHAN_SPACING) &&
  842. (spacing <= MAX_CHAN_SPACING))
  843. return 1;
  844. else
  845. return 0;
  846. }
  847. static inline int is_valid_emphasis(int emphasis)
  848. {
  849. if ((emphasis >= MIN_EMPHASIS) &&
  850. (emphasis <= MAX_EMPHASIS))
  851. return 1;
  852. else
  853. return 0;
  854. }
  855. static inline int is_valid_rds_std(int rds_std)
  856. {
  857. if ((rds_std >= MIN_RDS_STD) &&
  858. (rds_std <= MAX_RDS_STD))
  859. return 1;
  860. else
  861. return 0;
  862. }
  863. static inline int is_valid_antenna(int antenna_type)
  864. {
  865. if ((antenna_type >= MIN_ANTENNA_VAL) &&
  866. (antenna_type <= MAX_ANTENNA_VAL))
  867. return 1;
  868. else
  869. return 0;
  870. }
  871. static inline int is_valid_ps_repeat_cnt(int cnt)
  872. {
  873. if ((cnt >= MIN_TX_PS_REPEAT_CNT) &&
  874. (cnt <= MAX_TX_PS_REPEAT_CNT))
  875. return 1;
  876. else
  877. return 0;
  878. }
  879. static inline int is_valid_soft_mute(int soft_mute)
  880. {
  881. if ((soft_mute >= MIN_SOFT_MUTE) &&
  882. (soft_mute <= MAX_SOFT_MUTE))
  883. return 1;
  884. else
  885. return 0;
  886. }
  887. static inline int is_valid_peek_len(int len)
  888. {
  889. if ((len >= MIN_PEEK_ACCESS_LEN) &&
  890. (len <= MAX_PEEK_ACCESS_LEN))
  891. return 1;
  892. else
  893. return 0;
  894. }
  895. static inline int is_valid_reset_cntr(int cntr)
  896. {
  897. if ((cntr >= MIN_RESET_CNTR) &&
  898. (cntr <= MAX_RESET_CNTR))
  899. return 1;
  900. else
  901. return 0;
  902. }
  903. static inline int is_valid_hlsi(int hlsi)
  904. {
  905. if ((hlsi >= MIN_HLSI) &&
  906. (hlsi <= MAX_HLSI))
  907. return 1;
  908. else
  909. return 0;
  910. }
  911. static inline int is_valid_notch_filter(int filter)
  912. {
  913. if ((filter >= MIN_NOTCH_FILTER) &&
  914. (filter <= MAX_NOTCH_FILTER))
  915. return 1;
  916. else
  917. return 0;
  918. }
  919. static inline int is_valid_intf_det_low_th(int th)
  920. {
  921. if ((th >= MIN_INTF_DET_OUT_LW_TH) &&
  922. (th <= MAX_INTF_DET_OUT_LW_TH))
  923. return 1;
  924. else
  925. return 0;
  926. }
  927. static inline int is_valid_intf_det_hgh_th(int th)
  928. {
  929. if ((th >= MIN_INTF_DET_OUT_HG_TH) &&
  930. (th <= MAX_INTF_DET_OUT_HG_TH))
  931. return 1;
  932. else
  933. return 0;
  934. }
  935. static inline int is_valid_sinr_th(int th)
  936. {
  937. if ((th >= MIN_SINR_TH) &&
  938. (th <= MAX_SINR_TH))
  939. return 1;
  940. else
  941. return 0;
  942. }
  943. static inline int is_valid_sinr_samples(int samples_cnt)
  944. {
  945. if ((samples_cnt >= MIN_SINR_SAMPLES) &&
  946. (samples_cnt <= MAX_SINR_SAMPLES))
  947. return 1;
  948. else
  949. return 0;
  950. }
  951. static inline int is_valid_fm_state(int state)
  952. {
  953. if ((state >= 0) && (state < FM_MAX_NO_STATES))
  954. return 1;
  955. else
  956. return 0;
  957. }
  958. #endif /* __RADIO_HCI_CORE_H */