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