fmdrv.h 6.2 KB

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