fmdrv.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * FM Driver for Connectivity chip of Texas Instruments.
  4. *
  5. * Common header for all FM driver sub-modules.
  6. *
  7. * Copyright (C) 2011 Texas Instruments
  8. */
  9. #ifndef _FM_DRV_H
  10. #define _FM_DRV_H
  11. #include <linux/skbuff.h>
  12. #include <linux/interrupt.h>
  13. #include <sound/core.h>
  14. #include <sound/initval.h>
  15. #include <linux/timer.h>
  16. #include <media/v4l2-ioctl.h>
  17. #include <media/v4l2-common.h>
  18. #include <media/v4l2-device.h>
  19. #include <media/v4l2-ctrls.h>
  20. #define FM_DRV_VERSION "0.1.1"
  21. #define FM_DRV_NAME "ti_fmdrv"
  22. #define FM_DRV_CARD_SHORT_NAME "TI FM Radio"
  23. #define FM_DRV_CARD_LONG_NAME "Texas Instruments FM Radio"
  24. /* Flag info */
  25. #define FM_INTTASK_RUNNING 0
  26. #define FM_INTTASK_SCHEDULE_PENDING 1
  27. #define FM_FW_DW_INPROGRESS 2
  28. #define FM_CORE_READY 3
  29. #define FM_CORE_TRANSPORT_READY 4
  30. #define FM_AF_SWITCH_INPROGRESS 5
  31. #define FM_CORE_TX_XMITING 6
  32. #define FM_TUNE_COMPLETE 0x1
  33. #define FM_BAND_LIMIT 0x2
  34. #define FM_DRV_TX_TIMEOUT (5*HZ) /* 5 seconds */
  35. #define FM_DRV_RX_SEEK_TIMEOUT (20*HZ) /* 20 seconds */
  36. #define fmerr(format, ...) \
  37. printk(KERN_ERR "fmdrv: " format, ## __VA_ARGS__)
  38. #define fmwarn(format, ...) \
  39. printk(KERN_WARNING "fmdrv: " format, ##__VA_ARGS__)
  40. #ifdef DEBUG
  41. #define fmdbg(format, ...) \
  42. printk(KERN_DEBUG "fmdrv: " format, ## __VA_ARGS__)
  43. #else /* DEBUG */
  44. #define fmdbg(format, ...) do {} while(0)
  45. #endif
  46. enum {
  47. FM_MODE_OFF,
  48. FM_MODE_TX,
  49. FM_MODE_RX,
  50. FM_MODE_ENTRY_MAX
  51. };
  52. #define FM_RX_RDS_INFO_FIELD_MAX 8 /* 4 Group * 2 Bytes */
  53. /* RX RDS data format */
  54. struct fm_rdsdata_format {
  55. union {
  56. struct {
  57. u8 buff[FM_RX_RDS_INFO_FIELD_MAX];
  58. } groupdatabuff;
  59. struct {
  60. u16 pidata;
  61. u8 blk_b[2];
  62. u8 blk_c[2];
  63. u8 blk_d[2];
  64. } groupgeneral;
  65. struct {
  66. u16 pidata;
  67. u8 blk_b[2];
  68. u8 af[2];
  69. u8 ps[2];
  70. } group0A;
  71. struct {
  72. u16 pi[2];
  73. u8 blk_b[2];
  74. u8 ps[2];
  75. } group0B;
  76. } data;
  77. };
  78. /* FM region (Europe/US, Japan) info */
  79. struct region_info {
  80. u32 chanl_space;
  81. u32 bot_freq;
  82. u32 top_freq;
  83. u8 fm_band;
  84. };
  85. struct fmdev;
  86. typedef void (*int_handler_prototype) (struct fmdev *);
  87. /* FM Interrupt processing related info */
  88. struct fm_irq {
  89. u8 stage;
  90. u16 flag; /* FM interrupt flag */
  91. u16 mask; /* FM interrupt mask */
  92. /* Interrupt process timeout handler */
  93. struct timer_list timer;
  94. u8 retry;
  95. int_handler_prototype *handlers;
  96. };
  97. /* RDS info */
  98. struct fm_rds {
  99. u8 flag; /* RX RDS on/off status */
  100. u8 last_blk_idx; /* Last received RDS block */
  101. /* RDS buffer */
  102. wait_queue_head_t read_queue;
  103. u32 buf_size; /* Size is always multiple of 3 */
  104. u32 wr_idx;
  105. u32 rd_idx;
  106. u8 *buff;
  107. };
  108. #define FM_RDS_MAX_AF_LIST 25
  109. /*
  110. * Current RX channel Alternate Frequency cache.
  111. * This info is used to switch to other freq (AF)
  112. * when current channel signal strength is below RSSI threshold.
  113. */
  114. struct tuned_station_info {
  115. u16 picode;
  116. u32 af_cache[FM_RDS_MAX_AF_LIST];
  117. u8 afcache_size;
  118. u8 af_list_max;
  119. };
  120. /* FM RX mode info */
  121. struct fm_rx {
  122. struct region_info region; /* Current selected band */
  123. u32 freq; /* Current RX frquency */
  124. u8 mute_mode; /* Current mute mode */
  125. u8 deemphasis_mode; /* Current deemphasis mode */
  126. /* RF dependent soft mute mode */
  127. u8 rf_depend_mute;
  128. u16 volume; /* Current volume level */
  129. u16 rssi_threshold; /* Current RSSI threshold level */
  130. /* Holds the index of the current AF jump */
  131. u8 afjump_idx;
  132. /* Will hold the frequency before the jump */
  133. u32 freq_before_jump;
  134. u8 rds_mode; /* RDS operation mode (RDS/RDBS) */
  135. u8 af_mode; /* Alternate frequency on/off */
  136. struct tuned_station_info stat_info;
  137. struct fm_rds rds;
  138. };
  139. #define FMTX_RDS_TXT_STR_SIZE 25
  140. /*
  141. * FM TX RDS data
  142. *
  143. * @ text_type: is the text following PS or RT
  144. * @ text: radio text string which could either be PS or RT
  145. * @ af_freq: alternate frequency for Tx
  146. * TODO: to be declared in application
  147. */
  148. struct tx_rds {
  149. u8 text_type;
  150. u8 text[FMTX_RDS_TXT_STR_SIZE];
  151. u8 flag;
  152. u32 af_freq;
  153. };
  154. /*
  155. * FM TX global data
  156. *
  157. * @ pwr_lvl: Power Level of the Transmission from mixer control
  158. * @ xmit_state: Transmission state = Updated locally upon Start/Stop
  159. * @ audio_io: i2S/Analog
  160. * @ tx_frq: Transmission frequency
  161. */
  162. struct fmtx_data {
  163. u8 pwr_lvl;
  164. u8 xmit_state;
  165. u8 audio_io;
  166. u8 region;
  167. u16 aud_mode;
  168. u32 preemph;
  169. u32 tx_frq;
  170. struct tx_rds rds;
  171. };
  172. /* FM driver operation structure */
  173. struct fmdev {
  174. struct video_device *radio_dev; /* V4L2 video device pointer */
  175. struct v4l2_device v4l2_dev; /* V4L2 top level struct */
  176. struct snd_card *card; /* Card which holds FM mixer controls */
  177. u16 asci_id;
  178. spinlock_t rds_buff_lock; /* To protect access to RDS buffer */
  179. spinlock_t resp_skb_lock; /* To protect access to received SKB */
  180. long flag; /* FM driver state machine info */
  181. int streg_cbdata; /* status of ST registration */
  182. struct sk_buff_head rx_q; /* RX queue */
  183. struct tasklet_struct rx_task; /* RX Tasklet */
  184. struct sk_buff_head tx_q; /* TX queue */
  185. struct tasklet_struct tx_task; /* TX Tasklet */
  186. unsigned long last_tx_jiffies; /* Timestamp of last pkt sent */
  187. atomic_t tx_cnt; /* Number of packets can send at a time */
  188. struct sk_buff *resp_skb; /* Response from the chip */
  189. /* Main task completion handler */
  190. struct completion maintask_comp;
  191. /* Opcode of last command sent to the chip */
  192. u8 pre_op;
  193. /* Handler used for wakeup when response packet is received */
  194. struct completion *resp_comp;
  195. struct fm_irq irq_info;
  196. u8 curr_fmmode; /* Current FM chip mode (TX, RX, OFF) */
  197. struct fm_rx rx; /* FM receiver info */
  198. struct fmtx_data tx_data;
  199. /* V4L2 ctrl framework handler*/
  200. struct v4l2_ctrl_handler ctrl_handler;
  201. /* For core assisted locking */
  202. struct mutex mutex;
  203. };
  204. #endif