fm_interface.h 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. #ifndef __FM_INTERFACE_H__
  2. #define __FM_INTERFACE_H__
  3. #include <linux/cdev.h>
  4. #include <linux/workqueue.h>
  5. #include "fm_typedef.h"
  6. #include "fm_rds.h"
  7. #include "fm_utils.h"
  8. /******************************************************************************
  9. * STRUCTURE DEFINITIONS
  10. *****************************************************************************/
  11. enum fm_op_state {
  12. FM_STA_STOP = 0,
  13. FM_STA_PLAY = 1,
  14. FM_STA_TUNE = 2,
  15. FM_STA_SEEK = 3,
  16. FM_STA_SCAN = 4,
  17. FM_STA_RAMPDOWN = 5,
  18. FM_STA_UNKNOWN = 100,
  19. FM_STA_MAX
  20. };
  21. enum fm_pwr_state {
  22. FM_PWR_OFF = 0,
  23. FM_PWR_RX_ON = 1,
  24. FM_PWR_TX_ON = 2,
  25. FM_PWR_MAX
  26. };
  27. enum fm_antenna_type {
  28. FM_ANA_LONG = 0, /* long antenna */
  29. FM_ANA_SHORT = 1, /* short antenna */
  30. FM_ANA_MAX
  31. };
  32. struct fm_hw_info {
  33. fm_s32 chip_id; /* chip ID, eg. 6620 */
  34. fm_s32 eco_ver; /* chip ECO version, eg. E3 */
  35. fm_s32 rom_ver; /* FM DSP rom code version, eg. V2 */
  36. fm_s32 patch_ver; /* FM DSP patch version, eg. 1.11 */
  37. fm_s32 reserve;
  38. };
  39. struct fm_i2s_setting {
  40. fm_s32 onoff;
  41. fm_s32 mode;
  42. fm_s32 sample;
  43. };
  44. typedef enum {
  45. FM_I2S_ON = 0,
  46. FM_I2S_OFF,
  47. FM_I2S_STATE_ERR
  48. } fm_i2s_state_e;
  49. typedef enum {
  50. FM_I2S_MASTER = 0,
  51. FM_I2S_SLAVE,
  52. FM_I2S_MODE_ERR
  53. } fm_i2s_mode_e;
  54. typedef enum {
  55. FM_I2S_32K = 0,
  56. FM_I2S_44K,
  57. FM_I2S_48K,
  58. FM_I2S_SR_ERR
  59. } fm_i2s_sample_e;
  60. typedef struct fm_i2s_info {
  61. fm_s32 status; /*0:FM_I2S_ON, 1:FM_I2S_OFF,2:error */
  62. fm_s32 mode; /*0:FM_I2S_MASTER, 1:FM_I2S_SLAVE,2:error */
  63. fm_s32 rate; /*0:FM_I2S_32K:32000,1:FM_I2S_44K:44100,2:FM_I2S_48K:48000,3:error */
  64. } fm_i2s_info_t;
  65. typedef enum {
  66. FM_AUD_ANALOG = 0,
  67. FM_AUD_I2S = 1,
  68. FM_AUD_MRGIF = 2,
  69. FM_AUD_ERR
  70. } fm_audio_path_e;
  71. typedef enum {
  72. FM_I2S_PAD_CONN = 0, /* sco fm chip: e.g.6627 */
  73. FM_I2S_PAD_IO = 1, /* combo fm chip: e.g.6628 */
  74. FM_I2S_PAD_ERR
  75. } fm_i2s_pad_sel_e;
  76. typedef struct fm_audio_info {
  77. fm_audio_path_e aud_path;
  78. fm_i2s_info_t i2s_info;
  79. fm_i2s_pad_sel_e i2s_pad;
  80. } fm_audio_info_t;
  81. struct fm_platform {
  82. struct cdev cdev;
  83. dev_t dev_t;
  84. struct class *cls;
  85. struct device *dev;
  86. };
  87. struct fm {
  88. /* chip info */
  89. fm_u16 chip_id; /* chip id, such as 6616/6620/6626/6628 */
  90. fm_u16 device_id; /* chip version */
  91. /* basic run time info */
  92. fm_s32 ref; /* fm driver can be multi opened */
  93. fm_bool chipon; /* Chip power state */
  94. enum fm_pwr_state pwr_sta; /* FM module power state */
  95. enum fm_op_state op_sta; /* current operation state: tune, seek, scan ... */
  96. /* enum fm_audio_path aud_path; //I2S or Analog */
  97. fm_s32 vol; /* current audio volume from chip side */
  98. fm_bool mute; /* true: mute, false: playing */
  99. fm_bool rds_on; /* true: on, false: off */
  100. enum fm_antenna_type ana_type; /* long/short antenna */
  101. fm_bool via_bt; /* true: fm over bt controller; false: fm over host */
  102. fm_u16 min_freq; /* for UE, 875KHz */
  103. fm_u16 max_freq; /* for UE, 1080KHz */
  104. fm_u16 cur_freq; /* current frequency */
  105. fm_u8 band; /* UE/JAPAN/JPANWD */
  106. /*FM Tx */
  107. fm_u32 vcoon; /* TX VCO tracking ON duiration(ms) */
  108. fm_u32 vcooff; /* TX RTC VCO tracking interval(s) */
  109. fm_u32 txpwrctl; /* TX power contrl interval(s) */
  110. fm_u32 tx_pwr;
  111. fm_bool rdstx_on; /* false:rds tx off, true:rds tx on */
  112. fm_bool wholechiprst;
  113. /* RDS data */
  114. struct fm_flag_event *rds_event; /* pointer to rds event */
  115. struct rds_t *pstRDSData; /* rds spec data buffer */
  116. /* platform data */
  117. struct fm_platform platform; /* platform related members */
  118. struct fm_workthread *eint_wkthd;
  119. struct fm_workthread *timer_wkthd;
  120. struct fm_work *eint_wk;
  121. struct fm_work *rds_wk;
  122. struct fm_work *rst_wk; /* work for subsystem reset */
  123. /* Tx */
  124. struct fm_work *fm_tx_desense_wifi_work;
  125. struct fm_work *fm_tx_power_ctrl_work;
  126. };
  127. struct fm_callback {
  128. /* call backs */
  129. fm_u16 (*cur_freq_get)(void);
  130. fm_s32 (*cur_freq_set)(fm_u16 new_freq);
  131. /* fm_u16(*chan_para_get)(fm_u16 freq); //get channel parameter, HL side/ FA / ATJ */
  132. };
  133. struct fm_basic_interface {
  134. /* mt66x6 lib interfaces */
  135. fm_s32 (*low_pwr_wa)(fm_s32 onoff);
  136. fm_s32 (*pwron)(fm_s32 data);
  137. fm_s32 (*pwroff)(fm_s32 data);
  138. fm_s32 (*msdelay)(fm_u32 val);
  139. fm_s32 (*usdelay)(fm_u32 val);
  140. fm_s32 (*read)(fm_u8 addr, fm_u16 *val);
  141. fm_s32 (*write)(fm_u8 addr, fm_u16 val);
  142. fm_s32 (*top_read)(fm_u16 addr, fm_u32 *val);
  143. fm_s32 (*top_write)(fm_u16 addr, fm_u32 val);
  144. fm_s32 (*host_read)(fm_u32 addr, fm_u32 *val);
  145. fm_s32 (*host_write)(fm_u32 addr, fm_u32 val);
  146. fm_s32 (*setbits)(fm_u8 addr, fm_u16 bits, fm_u16 msk);
  147. fm_u16 (*chipid_get)(void);
  148. fm_s32 (*mute)(fm_bool mute);
  149. fm_s32 (*rampdown)(void);
  150. fm_s32 (*pwrupseq)(fm_u16 *chip_id, fm_u16 *device_id);
  151. fm_s32 (*pwrdownseq)(void);
  152. fm_bool (*setfreq)(fm_u16 freq);
  153. fm_bool (*seek)(fm_u16 min_freq, fm_u16 max_freq, fm_u16 *freq, fm_u16 dir, fm_u16 space);
  154. fm_s32 (*seekstop)(void);
  155. fm_bool (*scan)(fm_u16 min_freq, fm_u16 max_freq, fm_u16 *freq, fm_u16 *tbl,
  156. fm_u16 *tblsize, fm_u16 dir, fm_u16 space);
  157. fm_bool (*jammer_scan)(fm_u16 min_freq, fm_u16 max_freq, fm_u16 *freq, fm_u16 *tbl,
  158. fm_u16 *tblsize, fm_u16 dir, fm_u16 space);
  159. fm_s32 (*cqi_get)(fm_s8 *buf, fm_s32 buf_len);
  160. fm_s32 (*scanstop)(void);
  161. fm_s32 (*rssiget)(fm_s32 *rssi);
  162. fm_s32 (*volset)(fm_u8 vol);
  163. fm_s32 (*volget)(fm_u8 *vol);
  164. fm_s32 (*dumpreg)(void);
  165. fm_bool (*msget)(fm_u16 *ms); /* mono/stereo indicator get */
  166. fm_s32 (*msset)(fm_s32 ms); /* mono/stereo force set */
  167. fm_bool (*pamdget)(fm_u16 *pamd);
  168. fm_bool (*em)(fm_u16 group, fm_u16 item, fm_u32 val);
  169. fm_s32 (*anaswitch)(fm_s32 ana);
  170. fm_s32 (*anaget)(void);
  171. fm_s32 (*caparray_get)(fm_s32 *ca);
  172. fm_s32 (*i2s_set)(fm_s32 onoff, fm_s32 mode, fm_s32 sample);
  173. fm_s32 (*i2s_get)(fm_s32 *ponoff, fm_s32 *pmode, fm_s32 *psample);
  174. fm_s32 (*hwinfo_get)(struct fm_hw_info *req);
  175. fm_s32 (*is_dese_chan)(fm_u16 freq); /* check if this is a de-sense channel */
  176. fm_s32 (*softmute_tune)(fm_u16 freq, fm_s32 *rssi, fm_bool *valid);
  177. fm_s32 (*pre_search)(void);
  178. fm_s32 (*restore_search)(void);
  179. fm_s32 (*desense_check)(fm_u16 freq, fm_s32 rssi); /* check if this is a valid channel */
  180. fm_s32 (*get_freq_cqi)(fm_u16 freq, fm_s32 *cqi);
  181. fm_s32 (*cqi_log)(fm_s32 min_freq, fm_s32 max_freq, fm_s32 space, fm_s32 cnt); /* cqi log tool */
  182. fm_s32 (*fm_via_bt)(fm_bool flag); /* fm over BT:1:enable,0:disable */
  183. fm_s32 (*set_search_th)(fm_s32 idx, fm_s32 val, fm_s32 reserve);
  184. fm_s32 (*get_aud_info)(fm_audio_info_t *data);
  185. /*tx function */
  186. fm_s32 (*tx_support)(fm_s32 *sup);
  187. fm_s32 (*rdstx_enable)(fm_s32 *flag);
  188. fm_bool (*tune_tx)(fm_u16 freq);
  189. fm_s32 (*pwrupseq_tx)(void);
  190. fm_s32 (*pwrdownseq_tx)(void);
  191. fm_s32 (*tx_pwr_ctrl)(fm_u16 freq, fm_s32 *ctr);
  192. fm_s32 (*rtc_drift_ctrl)(fm_u16 freq, fm_s32 *ctr);
  193. fm_s32 (*tx_desense_wifi)(fm_u16 freq, fm_s32 *ctr);
  194. fm_s32 (*tx_scan)(fm_u16 min_freq, fm_u16 max_freq, fm_u16 *pFreq, fm_u16 *pScanTBL,
  195. fm_u16 *ScanTBLsize, fm_u16 scandir, fm_u16 space);
  196. };
  197. struct fm_rds_interface {
  198. /* rds lib interfaces */
  199. fm_s32 (*rds_blercheck)(rds_t *dst);
  200. fm_bool (*rds_onoff)(rds_t *dst, fm_bool onoff);
  201. fm_s32 (*rds_parser)(rds_t *rds_dst, struct rds_rx_t *rds_raw, fm_s32 rds_size, fm_u16(*getfreq) (void));
  202. fm_u16 (*rds_gbc_get)(void); /* good block counter */
  203. fm_u16 (*rds_bbc_get)(void); /* bad block counter */
  204. fm_u8 (*rds_bbr_get)(void); /* bad block ratio */
  205. fm_s32 (*rds_bc_reset)(void); /* reset block counter */
  206. fm_u32 (*rds_bci_get)(void); /* bler check interval */
  207. fm_s32 (*rds_log_get)(struct rds_rx_t *dst, fm_s32 *dst_len);
  208. fm_s32 (*rds_gc_get)(struct rds_group_cnt_t *dst, rds_t *rdsp);
  209. fm_s32 (*rds_gc_reset)(rds_t *rdsp);
  210. /*Tx */
  211. fm_s32 (*rds_tx)(fm_u16 pi, fm_u16 *ps, fm_u16 *other_rds, fm_u8 other_rds_cnt);
  212. fm_s32 (*rds_tx_enable)(void);
  213. fm_s32 (*rds_tx_disable)(void);
  214. fm_s32 (*rdstx_support)(fm_s32 *sup);
  215. };
  216. struct fm_lowlevel_ops {
  217. struct fm_callback cb;
  218. struct fm_basic_interface bi;
  219. struct fm_rds_interface ri;
  220. };
  221. #if (!defined(MT6620_FM) && !defined(MT6628_FM) && !defined(MT6627_FM) && !defined(MT6580_FM) && !defined(MT6630_FM))
  222. extern fm_s32 fm_low_ops_register(struct fm_lowlevel_ops *ops);
  223. extern fm_s32 fm_low_ops_unregister(struct fm_lowlevel_ops *ops);
  224. extern fm_s32 fm_rds_ops_register(struct fm_lowlevel_ops *ops);
  225. extern fm_s32 fm_rds_ops_unregister(struct fm_lowlevel_ops *ops);
  226. #endif
  227. #ifdef MT6620_FM
  228. extern fm_s32 MT6620fm_low_ops_register(struct fm_lowlevel_ops *ops);
  229. extern fm_s32 MT6620fm_low_ops_unregister(struct fm_lowlevel_ops *ops);
  230. extern fm_s32 MT6620fm_rds_ops_register(struct fm_lowlevel_ops *ops);
  231. extern fm_s32 MT6620fm_rds_ops_unregister(struct fm_lowlevel_ops *ops);
  232. #endif
  233. #ifdef MT6628_FM
  234. extern fm_s32 MT6628fm_low_ops_register(struct fm_lowlevel_ops *ops);
  235. extern fm_s32 MT6628fm_low_ops_unregister(struct fm_lowlevel_ops *ops);
  236. extern fm_s32 MT6628fm_rds_ops_register(struct fm_lowlevel_ops *ops);
  237. extern fm_s32 MT6628fm_rds_ops_unregister(struct fm_lowlevel_ops *ops);
  238. #endif
  239. #ifdef MT6627_FM
  240. extern fm_s32 MT6627fm_low_ops_register(struct fm_lowlevel_ops *ops);
  241. extern fm_s32 MT6627fm_low_ops_unregister(struct fm_lowlevel_ops *ops);
  242. extern fm_s32 MT6627fm_rds_ops_register(struct fm_lowlevel_ops *ops);
  243. extern fm_s32 MT6627fm_rds_ops_unregister(struct fm_lowlevel_ops *ops);
  244. #endif
  245. #ifdef MT6580_FM
  246. extern fm_s32 MT6580fm_low_ops_register(struct fm_lowlevel_ops *ops);
  247. extern fm_s32 MT6580fm_low_ops_unregister(struct fm_lowlevel_ops *ops);
  248. extern fm_s32 MT6580fm_rds_ops_register(struct fm_lowlevel_ops *ops);
  249. extern fm_s32 MT6580fm_rds_ops_unregister(struct fm_lowlevel_ops *ops);
  250. #endif
  251. #ifdef MT6630_FM
  252. extern fm_s32 MT6630fm_low_ops_register(struct fm_lowlevel_ops *ops);
  253. extern fm_s32 MT6630fm_low_ops_unregister(struct fm_lowlevel_ops *ops);
  254. extern fm_s32 MT6630fm_rds_ops_register(struct fm_lowlevel_ops *ops);
  255. extern fm_s32 MT6630fm_rds_ops_unregister(struct fm_lowlevel_ops *ops);
  256. #endif
  257. /*
  258. * fm_get_channel_space - get the spcace of gived channel
  259. * @freq - value in 760~1080 or 7600~10800
  260. *
  261. * Return 0, if 760~1080; return 1, if 7600 ~ 10800, else err code < 0
  262. */
  263. extern fm_s32 fm_get_channel_space(int freq);
  264. #endif /* __FM_INTERFACE_H__ */