radio-iris.h 26 KB

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