tizen 2.4 release
[profile/mobile/platform/kernel/linux-3.10-sc7730.git] / drivers / media / radio / sc2331 / fmdrv.h
1 /*
2  * This program is free software; you can redistribute it and/or modify
3  * it under the terms of the GNU General Public License version 2 as
4  * published by the Free Software Foundation.
5
6  * You should have received a copy of the GNU General Public License
7  * along with this program; if not, write to the Free Software
8  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
9
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12  * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
13  * for more details.
14
15
16  *  Copyright (C) 2009-2014 Broadcom Corporation
17  */
18
19 /************************************************************************************
20  *
21  *  Filename:    fmdrv.h
22  *
23  *  Description: Common header for all FM driver sub-modules.
24  *
25  ***********************************************************************************/
26 #ifndef _FM_DRV_H
27 #define _FM_DRV_H
28
29 #include <linux/skbuff.h>
30 #include <linux/interrupt.h>
31 #include <sound/core.h>
32 #include <sound/initval.h>
33 #include <linux/timer.h>
34 #include <linux/version.h>
35 #include <linux/videodev2.h>
36
37 /*******************************************************************************
38 **  Constants & Macros
39 *******************************************************************************/
40 #define DEBUG 1
41 #define FM_DRV_VERSION            "1.00"
42
43 /* Should match with FM_DRV_VERSION */
44 #define FM_DRV_RADIO_VERSION      KERNEL_VERSION(1, 0, 0)
45 #define FM_DRV_NAME               "marlin_fmdrv"
46 #define FM_DRV_CARD_SHORT_NAME    "Mariln FM Radio"
47 #define FM_DRV_CARD_LONG_NAME     "Marlin FM Radio"
48
49 /* Flag info */
50 #define FM_CORE_READY                 3
51
52 #define FM_DRV_TX_TIMEOUT       (4*HZ)  /* 4 sec */
53 #define FM_DRV_RX_SEEK_TIMEOUT       (20*HZ)  /* 20 sec */
54
55 #define NO_OF_ENTRIES_IN_ARRAY(array) (sizeof(array) / sizeof(array[0]))
56
57 /* bits in register FM_RDS_SYS    0x00 */
58 #define FM_OFF                     0x00
59 #define FM_ON                      0x01
60 #define FM_RDS_ON                  0x02
61
62 /* bits in register I2C_FM_REG_AUD_CTL0  0x05 */
63 #define FM_RF_MUTE                 0x0001    /* bit0 */
64 #define FM_MANUAL_MUTE             0x0002    /* bit1 */
65 #define FM_Z_MUTE_LEFT_OFF         0x0004    /* bit2 */
66 #define FM_Z_MUTE_RITE_OFF         0x0008   /* bit3 */
67 #define FM_AUDIO_DAC_ON            0x0010    /* bit4 */
68 #define FM_AUDIO_I2S_ON            0x0020    /* bit5 */
69 #define FM_DEEMPHA_75_ON           0x0040    /* bit6 */
70 #define FM_AUDIO_BAND_WIDTH        0x0080    /* bit7 */
71
72 /* bits in register FM_REG_FM_CTRL  0x01 */
73 #define FM_BAND_REG_WEST           0x00
74 #define FM_BAND_REG_EAST           0x01
75 #define FM_STEREO_AUTO             0x02
76 #define FM_STEREO_MANUAL           0x04
77 #define FM_STEREO_SWITCH           0x08
78 #define FM_HI_LO_INJ               0x10
79
80 /* bits in register FM_REG_RDS_CTL0  0x02 */
81 #define FM_RDS_CTRL_RDS            0x00
82 #define FM_RDS_CTRL_RBDS           0x01
83 #define FM_RDS_CTRL_FIFO_FLUSH     0x02
84
85 /* the highest bit on I2C_FM_REG_PCM_ROUTE register */
86 #define FM_PCM_ROUTE_ON_BIT        0x80    /* FM on SCO */
87
88 #define FM_STEP_NONE               0xff
89
90 /* FM/RDS flag bits */
91 #define FM_RDS_FLAG_CLEAN_BIT       0x01 /* clean FM_RDS_FLAG region */
92 #define FM_RDS_FLAGSCH_FRZ_BIT          0x02 /* interrupt freeze */
93 #define FM_RDS_FLAG_SCH_BIT         0x04 /* Pending search_tune */
94
95 /* bits in I2C_FM_REG_FM_RDS_FLAG 0x12 */
96 #define I2C_MASK_SRH_TUNE_CMPL_BIT     (0x0001 << 0)    /* FM/RDS register search/tune cmpl bit */
97 #define I2C_MASK_SRH_TUNE_FAIL_BIT     (0x0001 << 1)    /* FM/RDS register search/tune fail bit */
98 #define I2C_MASK_RSSI_LOW_BIT          (0x0001 << 2)    /* FM/RDS registerRSSI low bit */
99 #define I2C_MASK_CARR_HI_ERR_BIT       (0x0001 << 3)    /* FM/RDS register carrier high err bit */
100 #define I2C_MASK_AUDIO_PAUSE_BIT       (0x0001 << 4)    /* audio has paused for the specific threshold and duration */
101 #define I2C_MASK_STEREO_DETC_BIT       (0x0001 << 5)    /* FM/RDS register search/tune cmpl bit */
102 #define I2C_MASK_STEREO_ACTIVE_BIT     (0x0001 << 6)    /* FM/RDS register search/tune fail bit */
103 /* second bytes of FM_RDS_FLG 0x13 */
104 #define I2C_MASK_RDS_FIFO_WLINE_BIT    (0x0100 << 1)    /* RDS tuples are currently available at
105                                                         a level >= waterline */
106 #define I2C_MASK_BB_MATCH_BIT          (0x0100 << 3)    /* PI code match found */
107 #define I2C_MASK_PI_MATCH_BIT          (0x0100 << 5)    /* PI code match found */
108
109 /* FM_REG_RDS_DATA 0x80 reading */
110 #define FM_RDS_END_TUPLE_1ST_BYTE     0x7c /* 1st byte of a RDS ending tuple */
111 #define FM_RDS_END_TUPLE_2ND_BYTE    0xff /* 2nd byte of a RDS ending tuple */
112 #define FM_RDS_END_TUPLE_3RD_BYTE    0xff /* 3rd byte of a RDS ending tuple */
113
114 /* FM/RDS flag bits used with fm_dev->rx.fm_rds_flag */
115 #define     FM_RDS_FLAG_CLEAN_BIT         0x01    /* clean FM_RDS_FLAG register */
116 #define     FM_RDS_FLAG_SCH_FRZ_BIT     0x02    /* interrupt freeze */
117 #define     FM_RDS_FLAG_SCH_BIT             0x04    /* pending search_tune */
118
119 #define     FM_RDS_UPD_TUPLE            64       /* 64 tuples per read(64*3 = 192 bytes),
120                                                     one tuple contains 1 RDS block  */
121
122
123 /* minimum and maximum value of start/stop SNR for stereo/mono blend */
124 #define     FM_START_SNR_MIN        0
125 #define     FM_START_SNR_MAX        63
126
127 #define     FM_STOP_SNR_MIN         0
128 #define     FM_STOP_SNR_MAX         63
129 /* minimum and maximum value of start/stop RSSI for stereo/mono blend */
130 #define     FM_START_RSSI_MIN       -128
131 #define     FM_START_RSSI_MAX       127
132
133 #define     FM_STOP_RSSI_MIN        -128
134 #define     FM_STOP_RSSI_MAX        127
135 /* minimum and maximum value of start SNR for soft mute */
136 #define     FM_START_MUTE_MIN       0
137 #define     FM_START_MUTE_MAX       63
138 /* minimum and maximum value of ultimate mute attenuation level */
139 #define     FM_STOP_ATTEN_MIN       -128
140 #define     FM_STOP_ATTEN_MAX       127
141 /* minimum and maximum value of mute rate */
142 #define     FM_MUTE_RATE_MIN        0
143 #define     FM_MUTE_RATE_MAX        63
144 /* minimum and maximum value of SNR reading adjustment */
145 #define     FM_SNR40_MIN            -128
146 #define     FM_SNR40_MAX            127
147
148
149
150
151 #define     FM_READ_1_BYTE_DATA     1
152 #define     FM_READ_2_BYTE_DATA     2
153
154 enum {
155     FM_MODE_OFF,
156     FM_MODE_TX,
157     FM_MODE_RX,
158     FM_MODE_ENTRY_MAX
159 };
160
161 enum fm_seek_tune_state
162 {
163     FM_STATE_NONE,
164     FM_STATE_TUNING,
165     FM_STATE_TUNE_CMPL,
166     FM_STATE_TUNE_ERR,
167     FM_STATE_SEEKING,
168     FM_STATE_SEEK_CMPL,
169     FM_STATE_SEEK_ERR
170 };
171
172 /*******************************************************************************
173 **  Type definitions
174 *******************************************************************************/
175
176 /* FM region (Europe/US, Japan) info */
177 struct region_info {
178     unsigned short  low_bound;   /* lowest frequency boundary */
179     unsigned short  high_bound;     /* highest frequency boundary */
180     unsigned char   deemphasis;     /* FM de-emphasis time constant */
181     unsigned char    scan_step;      /* scanning step */
182     unsigned char    fm_band;
183 };
184
185 /* RDS info */
186 struct fm_rds {
187     unsigned char rds_flag;     /* RX RDS on/off status */
188     /* RDS buffer */
189     wait_queue_head_t read_queue;
190     unsigned int buf_size;      /* Size is always multiple of 3 */
191     unsigned int wr_index;
192     unsigned int rd_index;
193     unsigned char *cbuffer;
194
195 };
196
197 /* FM RX mode info */
198 struct fm_rx {
199     struct region_info region;      /* Current selected band */
200     unsigned char curr_region;
201     unsigned int curr_freq;             /* Current RX frquency */
202     unsigned char curr_mute_mode;       /* Current mute mode */
203     unsigned short curr_volume;     /* Current volume level */
204     char  curr_snr_threshold;       /* Current SNR threshold level */
205     char  curr_cos_threshold;       /* Current COS threshold value */
206     unsigned char curr_rssi_threshold;  /* Current RSSI threshold value */
207     unsigned char curr_sch_mode;    /* current search mode */
208     unsigned char curr_noise_floor; /* current noise floor estimation */
209     unsigned char rds_mode;             /* RDS operation mode (RDS/RDBS) */
210     unsigned char curr_rssi;        /* Cached value of RSSI for the current frequency */
211     unsigned char audio_mode;
212     unsigned char audio_path;
213     unsigned short aud_ctrl;
214     unsigned char pcm_reg;
215     unsigned char sch_step;
216     unsigned char seek_direction;
217     unsigned char seek_wrap;
218     unsigned char curr_search_state;
219     unsigned short fm_rds_mask; /* FM/RDS interrupt mask */
220     unsigned short fm_rds_flag; /* FM/RDS interrupt flag */
221     unsigned char fm_func_mask;
222     struct fm_rds rds;
223
224     u8 af_mode;         /* Alternate frequency on/off */
225     u8 no_of_chans;     /* Number stations found */
226 };
227
228 struct fm_device_info {
229     unsigned int capabilities;   /* Device capabilities */
230     unsigned int tuner_capability;   /* Tuner capability */
231     enum v4l2_tuner_type type;
232     unsigned int rxsubchans;
233     unsigned int aud_mode;
234 };
235
236 struct fm_softmute_blend_config {
237     unsigned char start_snr;
238     unsigned char stop_snr;
239     signed char start_rssi;
240     signed char stop_rssi;
241     unsigned char start_mute;
242     signed char stop_atten;
243     unsigned char mute_rate;
244     signed char snr40;
245 };
246
247 /* FM driver operation structure */
248 struct fmdrv_ops {
249     struct video_device *radio_dev;      /* V4L2 video device pointer */
250     spinlock_t resp_skb_lock;               /* To protect access to received SKB */
251     spinlock_t rds_cbuff_lock;               /* To protect access to RDS Circular buffer */
252
253     long flag;                               /*  FM driver state machine info */
254     struct sk_buff_head rx_q;          /* RX queue */
255     struct tasklet_struct rx_task;      /* RX Tasklet */
256
257     struct sk_buff_head tx_q;          /* TX queue */
258     struct tasklet_struct tx_task;      /* TX Tasklet */
259     unsigned long last_tx_jiffies;      /* Timestamp of last pkt sent */
260     atomic_t tx_cnt;                         /* Number of packets can send at a time */
261
262     struct sk_buff *response_skb;       /* Response from the chip */
263     /* Main task completion handler */
264     struct completion maintask_completion;
265     /* Seek task completion handler */
266     struct completion seektask_completion;
267     /* Opcode of last command sent to the chip */
268     unsigned char last_sent_pkt_opcode;
269     /* Handler used for wakeup when response packet is received */
270     struct completion *response_completion;
271     unsigned char curr_fmmode;   /* Current FM chip mode (TX, RX, OFF) */
272         unsigned char aud_ctrl;         /* Current Audio Control (STEREO/MONO/NONE) */
273     struct fm_rx rx;                         /* FM receiver info */
274     struct fm_device_info device_info; /* FM Device info */
275     struct fm_softmute_blend_config softmute_blend_config;  /* FM Softmute and audio blend config */
276     unsigned char set_blndmute;    /* Current softmute and audio blending setting */
277     struct mutex mutex;
278     struct mutex completionmutex;
279 };
280 #endif