Manu Abraham | 8bd135b | 2007-07-03 09:53:42 -0300 | [diff] [blame] | 1 | /* |
| 2 | STB0899 Multistandard Frontend driver |
| 3 | Copyright (C) Manu Abraham (abraham.manu@gmail.com) |
| 4 | |
| 5 | Copyright (C) ST Microelectronics |
| 6 | |
| 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. |
| 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., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 20 | */ |
| 21 | |
| 22 | #ifndef __STB0899_PRIV_H |
| 23 | #define __STB0899_PRIV_H |
| 24 | |
| 25 | #include "dvb_frontend.h" |
| 26 | #include "stb0899_drv.h" |
| 27 | |
| 28 | #define FE_ERROR 0 |
| 29 | #define FE_NOTICE 1 |
| 30 | #define FE_INFO 2 |
| 31 | #define FE_DEBUG 3 |
| 32 | #define FE_DEBUGREG 4 |
| 33 | |
| 34 | #define dprintk(x, y, z, format, arg...) do { \ |
| 35 | if (z) { \ |
Reinhard Nissl | c615a27 | 2008-07-09 15:33:38 -0300 | [diff] [blame^] | 36 | if ((*x > FE_ERROR) && (*x > y)) \ |
Manu Abraham | 8bd135b | 2007-07-03 09:53:42 -0300 | [diff] [blame] | 37 | printk(KERN_ERR "%s: " format "\n", __func__ , ##arg); \ |
Reinhard Nissl | c615a27 | 2008-07-09 15:33:38 -0300 | [diff] [blame^] | 38 | else if ((*x > FE_NOTICE) && (*x > y)) \ |
Manu Abraham | 8bd135b | 2007-07-03 09:53:42 -0300 | [diff] [blame] | 39 | printk(KERN_NOTICE "%s: " format "\n", __func__ , ##arg); \ |
Reinhard Nissl | c615a27 | 2008-07-09 15:33:38 -0300 | [diff] [blame^] | 40 | else if ((*x > FE_INFO) && (*x > y)) \ |
Manu Abraham | 8bd135b | 2007-07-03 09:53:42 -0300 | [diff] [blame] | 41 | printk(KERN_INFO "%s: " format "\n", __func__ , ##arg); \ |
Reinhard Nissl | c615a27 | 2008-07-09 15:33:38 -0300 | [diff] [blame^] | 42 | else if ((*x > FE_DEBUG) && (*x > y)) \ |
Manu Abraham | 8bd135b | 2007-07-03 09:53:42 -0300 | [diff] [blame] | 43 | printk(KERN_DEBUG "%s: " format "\n", __func__ , ##arg); \ |
| 44 | } else { \ |
Reinhard Nissl | c615a27 | 2008-07-09 15:33:38 -0300 | [diff] [blame^] | 45 | if (*x > y) \ |
Manu Abraham | 8bd135b | 2007-07-03 09:53:42 -0300 | [diff] [blame] | 46 | printk(format, ##arg); \ |
| 47 | } \ |
| 48 | } while(0) |
| 49 | |
| 50 | #define INRANGE(val, x, y) (((x <= val) && (val <= y)) || \ |
| 51 | ((y <= val) && (val <= x)) ? 1 : 0) |
| 52 | |
| 53 | #define BYTE0 0 |
| 54 | #define BYTE1 8 |
| 55 | #define BYTE2 16 |
| 56 | #define BYTE3 24 |
| 57 | |
| 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)) |
| 61 | |
| 62 | #define MIN(x, y) ((x) <= (y) ? (x) : (y)) |
| 63 | #define MAX(x, y) ((x) >= (y) ? (x) : (y)) |
| 64 | #define ABS(x) ((x) >= 0 ? (x) : -(x)) |
| 65 | |
| 66 | #define LSB(x) ((x & 0xff)) |
| 67 | #define MSB(y) ((y >> 8) & 0xff) |
| 68 | |
| 69 | |
| 70 | #define STB0899_GETFIELD(bitf, val) ((val >> STB0899_OFFST_##bitf) & ((1 << STB0899_WIDTH_##bitf) - 1)) |
| 71 | |
| 72 | |
| 73 | #define STB0899_SETFIELD(mask, val, width, offset) (mask & (~(((1 << width) - 1) << \ |
| 74 | offset))) | ((val & \ |
| 75 | ((1 << width) - 1)) << offset) |
| 76 | |
| 77 | #define STB0899_SETFIELD_VAL(bitf, mask, val) (mask = (mask & (~(((1 << STB0899_WIDTH_##bitf) - 1) <<\ |
| 78 | STB0899_OFFST_##bitf))) | \ |
| 79 | (val << STB0899_OFFST_##bitf)) |
| 80 | |
| 81 | |
| 82 | enum stb0899_status { |
| 83 | NOAGC1 = 0, |
| 84 | AGC1OK, |
| 85 | NOTIMING, |
| 86 | ANALOGCARRIER, |
| 87 | TIMINGOK, |
| 88 | NOAGC2, |
| 89 | AGC2OK, |
| 90 | NOCARRIER, |
| 91 | CARRIEROK, |
| 92 | NODATA, |
| 93 | FALSELOCK, |
| 94 | DATAOK, |
| 95 | OUTOFRANGE, |
| 96 | RANGEOK, |
| 97 | DVBS2_DEMOD_LOCK, |
| 98 | DVBS2_DEMOD_NOLOCK, |
| 99 | DVBS2_FEC_LOCK, |
| 100 | DVBS2_FEC_NOLOCK |
| 101 | }; |
| 102 | |
| 103 | enum stb0899_modcod { |
| 104 | STB0899_DUMMY_PLF, |
| 105 | STB0899_QPSK_14, |
| 106 | STB0899_QPSK_13, |
| 107 | STB0899_QPSK_25, |
| 108 | STB0899_QPSK_12, |
| 109 | STB0899_QPSK_35, |
| 110 | STB0899_QPSK_23, |
| 111 | STB0899_QPSK_34, |
| 112 | STB0899_QPSK_45, |
| 113 | STB0899_QPSK_56, |
| 114 | STB0899_QPSK_89, |
| 115 | STB0899_QPSK_910, |
| 116 | STB0899_8PSK_35, |
| 117 | STB0899_8PSK_23, |
| 118 | STB0899_8PSK_34, |
| 119 | STB0899_8PSK_56, |
| 120 | STB0899_8PSK_89, |
| 121 | STB0899_8PSK_910, |
| 122 | STB0899_16APSK_23, |
| 123 | STB0899_16APSK_34, |
| 124 | STB0899_16APSK_45, |
| 125 | STB0899_16APSK_56, |
| 126 | STB0899_16APSK_89, |
| 127 | STB0899_16APSK_910, |
| 128 | STB0899_32APSK_34, |
| 129 | STB0899_32APSK_45, |
| 130 | STB0899_32APSK_56, |
| 131 | STB0899_32APSK_89, |
| 132 | STB0899_32APSK_910 |
| 133 | }; |
| 134 | |
| 135 | enum stb0899_frame { |
| 136 | STB0899_LONG_FRAME, |
| 137 | STB0899_SHORT_FRAME |
| 138 | }; |
| 139 | |
Manu Abraham | 8bd135b | 2007-07-03 09:53:42 -0300 | [diff] [blame] | 140 | enum stb0899_alpha { |
| 141 | RRC_20, |
| 142 | RRC_25, |
| 143 | RRC_35 |
| 144 | }; |
| 145 | |
| 146 | struct stb0899_tab { |
| 147 | s32 real; |
| 148 | s32 read; |
| 149 | }; |
| 150 | |
| 151 | enum stb0899_fec { |
| 152 | STB0899_FEC_1_2 = 13, |
| 153 | STB0899_FEC_2_3 = 18, |
| 154 | STB0899_FEC_3_4 = 21, |
| 155 | STB0899_FEC_5_6 = 24, |
| 156 | STB0899_FEC_6_7 = 25, |
| 157 | STB0899_FEC_7_8 = 26 |
| 158 | }; |
| 159 | |
| 160 | struct stb0899_params { |
| 161 | u32 freq; /* Frequency */ |
| 162 | u32 srate; /* Symbol rate */ |
| 163 | enum dvbfe_fec fecrate; |
| 164 | }; |
| 165 | |
| 166 | struct stb0899_internal { |
| 167 | u32 master_clk; |
| 168 | u32 freq; /* Demod internal Frequency */ |
| 169 | u32 srate; /* Demod internal Symbol rate */ |
| 170 | enum stb0899_fec fecrate; /* Demod internal FEC rate */ |
| 171 | u32 srch_range; /* Demod internal Search Range */ |
| 172 | u32 sub_range; /* Demod current sub range (Hz) */ |
| 173 | u32 tuner_step; /* Tuner step (Hz) */ |
| 174 | u32 tuner_offst; /* Relative offset to carrier (Hz) */ |
| 175 | u32 tuner_bw; /* Current bandwidth of the tuner (Hz) */ |
| 176 | |
| 177 | s32 mclk; /* Masterclock Divider factor (binary) */ |
| 178 | s32 rolloff; /* Current RollOff of the filter (x100) */ |
| 179 | |
| 180 | s16 derot_freq; /* Current derotator frequency (Hz) */ |
| 181 | s16 derot_percent; |
| 182 | |
| 183 | s16 direction; /* Current derotator search direction */ |
| 184 | s16 derot_step; /* Derotator step (binary value) */ |
Manu Abraham | 8bd135b | 2007-07-03 09:53:42 -0300 | [diff] [blame] | 185 | s16 t_derot; /* Derotator time constant (ms) */ |
| 186 | s16 t_data; /* Data recovery time constant (ms) */ |
| 187 | s16 sub_dir; /* Direction of the next sub range */ |
| 188 | |
| 189 | s16 t_agc1; /* Agc1 time constant (ms) */ |
| 190 | s16 t_agc2; /* Agc2 time constant (ms) */ |
| 191 | |
| 192 | u32 lock; /* Demod internal lock state */ |
| 193 | enum stb0899_status status; /* Demod internal status */ |
| 194 | |
| 195 | /* DVB-S2 */ |
| 196 | s32 agc_gain; /* RF AGC Gain */ |
| 197 | s32 center_freq; /* Nominal carrier frequency */ |
| 198 | s32 av_frame_coarse; /* Coarse carrier freq search frames */ |
| 199 | s32 av_frame_fine; /* Fine carrier freq search frames */ |
| 200 | |
| 201 | s16 step_size; /* Carrier frequency search step size */ |
| 202 | |
| 203 | enum stb0899_alpha rrc_alpha; |
| 204 | enum stb0899_inversion inversion; |
| 205 | enum stb0899_modcod modcod; |
| 206 | u8 pilots; /* Pilots found */ |
| 207 | |
| 208 | enum stb0899_frame frame_length; |
| 209 | u8 v_status; /* VSTATUS */ |
| 210 | u8 err_ctrl; /* ERRCTRLn */ |
| 211 | }; |
| 212 | |
| 213 | struct stb0899_state { |
| 214 | struct i2c_adapter *i2c; |
| 215 | struct stb0899_config *config; |
| 216 | struct dvb_frontend frontend; |
| 217 | |
Reinhard Nissl | c615a27 | 2008-07-09 15:33:38 -0300 | [diff] [blame^] | 218 | u32 *verbose; /* Cached module verbosity level */ |
Manu Abraham | 8bd135b | 2007-07-03 09:53:42 -0300 | [diff] [blame] | 219 | |
| 220 | struct stb0899_internal internal; /* Device internal parameters */ |
| 221 | |
| 222 | /* cached params from API */ |
| 223 | enum dvbfe_delsys delsys; |
| 224 | struct stb0899_params params; |
| 225 | |
| 226 | u32 rx_freq; /* DiSEqC 2.0 receiver freq */ |
| 227 | struct mutex search_lock; |
| 228 | }; |
| 229 | /* stb0899.c */ |
| 230 | extern int stb0899_read_reg(struct stb0899_state *state, |
| 231 | unsigned int reg); |
| 232 | |
| 233 | extern u32 _stb0899_read_s2reg(struct stb0899_state *state, |
| 234 | u32 stb0899_i2cdev, |
| 235 | u32 stb0899_base_addr, |
| 236 | u16 stb0899_reg_offset); |
| 237 | |
| 238 | extern int stb0899_read_regs(struct stb0899_state *state, |
| 239 | unsigned int reg, u8 *buf, |
Manu Abraham | 3d6a3beb | 2008-01-25 20:39:16 -0300 | [diff] [blame] | 240 | u32 count); |
Manu Abraham | 8bd135b | 2007-07-03 09:53:42 -0300 | [diff] [blame] | 241 | |
| 242 | extern int stb0899_write_regs(struct stb0899_state *state, |
| 243 | unsigned int reg, u8 *data, |
Manu Abraham | 85eabac | 2008-01-25 20:28:46 -0300 | [diff] [blame] | 244 | u32 count); |
Manu Abraham | 8bd135b | 2007-07-03 09:53:42 -0300 | [diff] [blame] | 245 | |
| 246 | extern int stb0899_write_reg(struct stb0899_state *state, |
| 247 | unsigned int reg, |
| 248 | u8 data); |
| 249 | |
| 250 | extern int stb0899_write_s2reg(struct stb0899_state *state, |
| 251 | u32 stb0899_i2cdev, |
| 252 | u32 stb0899_base_addr, |
| 253 | u16 stb0899_reg_offset, |
| 254 | u32 stb0899_data); |
| 255 | |
Manu Abraham | 40e8ce3 | 2008-02-03 19:37:02 -0300 | [diff] [blame] | 256 | extern int stb0899_i2c_gate_ctrl(struct dvb_frontend *fe, int enable); |
| 257 | |
Manu Abraham | 8bd135b | 2007-07-03 09:53:42 -0300 | [diff] [blame] | 258 | |
| 259 | #define STB0899_READ_S2REG(DEVICE, REG) (_stb0899_read_s2reg(state, DEVICE, STB0899_BASE_##REG, STB0899_OFF0_##REG)) |
| 260 | //#define STB0899_WRITE_S2REG(DEVICE, REG, DATA) (_stb0899_write_s2reg(state, DEVICE, STB0899_BASE_##REG, STB0899_OFF0_##REG, DATA)) |
| 261 | |
| 262 | /* stb0899_algo.c */ |
| 263 | extern enum stb0899_status stb0899_dvbs_algo(struct stb0899_state *state); |
| 264 | extern enum stb0899_status stb0899_dvbs2_algo(struct stb0899_state *state); |
| 265 | extern long stb0899_carr_width(struct stb0899_state *state); |
| 266 | |
| 267 | #endif //__STB0899_PRIV_H |