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