2 STB0899 Multistandard Frontend driver
3 Copyright (C) Manu Abraham (abraham.manu@gmail.com)
5 Copyright (C) ST Microelectronics
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
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.
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., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #ifndef __STB0899_PRIV_H
23 #define __STB0899_PRIV_H
25 #include <media/dvb_frontend.h>
26 #include "stb0899_drv.h"
34 #define dprintk(x, y, z, format, arg...) do { \
36 if ((*x > FE_ERROR) && (*x > y)) \
37 printk(KERN_ERR "%s: " format "\n", __func__ , ##arg); \
38 else if ((*x > FE_NOTICE) && (*x > y)) \
39 printk(KERN_NOTICE "%s: " format "\n", __func__ , ##arg); \
40 else if ((*x > FE_INFO) && (*x > y)) \
41 printk(KERN_INFO "%s: " format "\n", __func__ , ##arg); \
42 else if ((*x > FE_DEBUG) && (*x > y)) \
43 printk(KERN_DEBUG "%s: " format "\n", __func__ , ##arg); \
46 printk(format, ##arg); \
50 #define INRANGE(val, x, y) (((x <= val) && (val <= y)) || \
51 ((y <= val) && (val <= x)) ? 1 : 0)
58 #define GETBYTE(x, y) (((x) >> (y)) & 0xff)
59 #define MAKEWORD32(a, b, c, d) (((a) << 24) | ((b) << 16) | ((c) << 8) | (d))
60 #define MAKEWORD16(a, b) (((a) << 8) | (b))
62 #define LSB(x) ((x & 0xff))
63 #define MSB(y) ((y >> 8) & 0xff)
66 #define STB0899_GETFIELD(bitf, val) ((val >> STB0899_OFFST_##bitf) & ((1 << STB0899_WIDTH_##bitf) - 1))
69 #define STB0899_SETFIELD(mask, val, width, offset) (mask & (~(((1 << width) - 1) << \
71 ((1 << width) - 1)) << offset)
73 #define STB0899_SETFIELD_VAL(bitf, mask, val) (mask = (mask & (~(((1 << STB0899_WIDTH_##bitf) - 1) <<\
74 STB0899_OFFST_##bitf))) | \
75 (val << STB0899_OFFST_##bitf))
148 STB0899_FEC_1_2
= 13,
149 STB0899_FEC_2_3
= 18,
150 STB0899_FEC_3_4
= 21,
151 STB0899_FEC_5_6
= 24,
152 STB0899_FEC_6_7
= 25,
156 struct stb0899_params
{
157 u32 freq
; /* Frequency */
158 u32 srate
; /* Symbol rate */
159 enum fe_code_rate fecrate
;
162 struct stb0899_internal
{
164 u32 freq
; /* Demod internal Frequency */
165 u32 srate
; /* Demod internal Symbol rate */
166 enum stb0899_fec fecrate
; /* Demod internal FEC rate */
167 s32 srch_range
; /* Demod internal Search Range */
168 s32 sub_range
; /* Demod current sub range (Hz) */
169 s32 tuner_step
; /* Tuner step (Hz) */
170 s32 tuner_offst
; /* Relative offset to carrier (Hz) */
171 u32 tuner_bw
; /* Current bandwidth of the tuner (Hz) */
173 s32 mclk
; /* Masterclock Divider factor (binary) */
174 s32 rolloff
; /* Current RollOff of the filter (x100) */
176 s16 derot_freq
; /* Current derotator frequency (Hz) */
179 s16 direction
; /* Current derotator search direction */
180 s16 derot_step
; /* Derotator step (binary value) */
181 s16 t_derot
; /* Derotator time constant (ms) */
182 s16 t_data
; /* Data recovery time constant (ms) */
183 s16 sub_dir
; /* Direction of the next sub range */
185 s16 t_agc1
; /* Agc1 time constant (ms) */
186 s16 t_agc2
; /* Agc2 time constant (ms) */
188 u32 lock
; /* Demod internal lock state */
189 enum stb0899_status status
; /* Demod internal status */
192 s32 agc_gain
; /* RF AGC Gain */
193 s32 center_freq
; /* Nominal carrier frequency */
194 s32 av_frame_coarse
; /* Coarse carrier freq search frames */
195 s32 av_frame_fine
; /* Fine carrier freq search frames */
197 s16 step_size
; /* Carrier frequency search step size */
199 enum stb0899_alpha rrc_alpha
;
200 enum stb0899_inversion inversion
;
201 enum stb0899_modcod modcod
;
202 u8 pilots
; /* Pilots found */
204 enum stb0899_frame frame_length
;
205 u8 v_status
; /* VSTATUS */
206 u8 err_ctrl
; /* ERRCTRLn */
209 struct stb0899_state
{
210 struct i2c_adapter
*i2c
;
211 struct stb0899_config
*config
;
212 struct dvb_frontend frontend
;
214 u32
*verbose
; /* Cached module verbosity level */
216 struct stb0899_internal internal
; /* Device internal parameters */
218 /* cached params from API */
219 enum fe_delivery_system delsys
;
220 struct stb0899_params params
;
222 u32 rx_freq
; /* DiSEqC 2.0 receiver freq */
223 struct mutex search_lock
;
226 extern int stb0899_read_reg(struct stb0899_state
*state
,
229 extern u32
_stb0899_read_s2reg(struct stb0899_state
*state
,
231 u32 stb0899_base_addr
,
232 u16 stb0899_reg_offset
);
234 extern int stb0899_read_regs(struct stb0899_state
*state
,
235 unsigned int reg
, u8
*buf
,
238 extern int stb0899_write_regs(struct stb0899_state
*state
,
239 unsigned int reg
, u8
*data
,
242 extern int stb0899_write_reg(struct stb0899_state
*state
,
246 extern int stb0899_write_s2reg(struct stb0899_state
*state
,
248 u32 stb0899_base_addr
,
249 u16 stb0899_reg_offset
,
252 extern int stb0899_i2c_gate_ctrl(struct dvb_frontend
*fe
, int enable
);
255 #define STB0899_READ_S2REG(DEVICE, REG) (_stb0899_read_s2reg(state, DEVICE, STB0899_BASE_##REG, STB0899_OFF0_##REG))
256 //#define STB0899_WRITE_S2REG(DEVICE, REG, DATA) (_stb0899_write_s2reg(state, DEVICE, STB0899_BASE_##REG, STB0899_OFF0_##REG, DATA))
259 extern enum stb0899_status
stb0899_dvbs_algo(struct stb0899_state
*state
);
260 extern enum stb0899_status
stb0899_dvbs2_algo(struct stb0899_state
*state
);
261 extern long stb0899_carr_width(struct stb0899_state
*state
);
263 #endif //__STB0899_PRIV_H