fmdrv.h 6.3 KB

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