fmdrv.h 6.0 KB

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