1 /* 2 * stv0900_priv.h 3 * 4 * Driver for ST STV0900 satellite demodulator IC. 5 * 6 * Copyright (C) ST Microelectronics. 7 * Copyright (C) 2009 NetUP Inc. 8 * Copyright (C) 2009 Igor M. Liplianin <liplianin@netup.ru> 9 * 10 * This program is free software; you can redistribute it and/or modify 11 * it under the terms of the GNU General Public License as published by 12 * the Free Software Foundation; either version 2 of the License, or 13 * (at your option) any later version. 14 * 15 * This program is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * 19 * GNU General Public License for more details. 20 */ 21 22 #ifndef STV0900_PRIV_H 23 #define STV0900_PRIV_H 24 25 #include <linux/i2c.h> 26 27 #define INRANGE(X, Y, Z) ((((X) <= (Y)) && ((Y) <= (Z))) \ 28 || (((Z) <= (Y)) && ((Y) <= (X))) ? 1 : 0) 29 30 #ifndef MAKEWORD 31 #define MAKEWORD(X, Y) (((X) << 8) + (Y)) 32 #endif 33 34 #define LSB(X) (((X) & 0xFF)) 35 #define MSB(Y) (((Y) >> 8) & 0xFF) 36 37 #ifndef TRUE 38 #define TRUE (1 == 1) 39 #endif 40 #ifndef FALSE 41 #define FALSE (!TRUE) 42 #endif 43 44 #define dprintk(args...) \ 45 do { \ 46 if (stvdebug) \ 47 printk(KERN_DEBUG args); \ 48 } while (0) 49 50 #define STV0900_MAXLOOKUPSIZE 500 51 #define STV0900_BLIND_SEARCH_AGC2_TH 700 52 #define STV0900_BLIND_SEARCH_AGC2_TH_CUT30 1400 53 #define IQPOWER_THRESHOLD 30 54 55 /* One point of the lookup table */ 56 struct stv000_lookpoint { 57 s32 realval;/* real value */ 58 s32 regval;/* binary value */ 59 }; 60 61 /* Lookup table definition */ 62 struct stv0900_table{ 63 s32 size;/* Size of the lookup table */ 64 struct stv000_lookpoint table[STV0900_MAXLOOKUPSIZE];/* Lookup table */ 65 }; 66 67 enum fe_stv0900_error { 68 STV0900_NO_ERROR = 0, 69 STV0900_INVALID_HANDLE, 70 STV0900_BAD_PARAMETER, 71 STV0900_I2C_ERROR, 72 STV0900_SEARCH_FAILED, 73 }; 74 75 enum fe_stv0900_clock_type { 76 STV0900_USE_REGISTERS_DEFAULT, 77 STV0900_SERIAL_PUNCT_CLOCK,/*Serial punctured clock */ 78 STV0900_SERIAL_CONT_CLOCK,/*Serial continues clock */ 79 STV0900_PARALLEL_PUNCT_CLOCK,/*Parallel punctured clock */ 80 STV0900_DVBCI_CLOCK/*Parallel continues clock : DVBCI */ 81 }; 82 83 enum fe_stv0900_search_state { 84 STV0900_SEARCH = 0, 85 STV0900_PLH_DETECTED, 86 STV0900_DVBS2_FOUND, 87 STV0900_DVBS_FOUND 88 89 }; 90 91 enum fe_stv0900_ldpc_state { 92 STV0900_PATH1_OFF_PATH2_OFF = 0, 93 STV0900_PATH1_ON_PATH2_OFF = 1, 94 STV0900_PATH1_OFF_PATH2_ON = 2, 95 STV0900_PATH1_ON_PATH2_ON = 3 96 }; 97 98 enum fe_stv0900_signal_type { 99 STV0900_NOAGC1 = 0, 100 STV0900_AGC1OK, 101 STV0900_NOTIMING, 102 STV0900_ANALOGCARRIER, 103 STV0900_TIMINGOK, 104 STV0900_NOAGC2, 105 STV0900_AGC2OK, 106 STV0900_NOCARRIER, 107 STV0900_CARRIEROK, 108 STV0900_NODATA, 109 STV0900_DATAOK, 110 STV0900_OUTOFRANGE, 111 STV0900_RANGEOK 112 }; 113 114 enum fe_stv0900_demod_num { 115 STV0900_DEMOD_1, 116 STV0900_DEMOD_2 117 }; 118 119 enum fe_stv0900_tracking_standard { 120 STV0900_DVBS1_STANDARD,/* Found Standard*/ 121 STV0900_DVBS2_STANDARD, 122 STV0900_DSS_STANDARD, 123 STV0900_TURBOCODE_STANDARD, 124 STV0900_UNKNOWN_STANDARD 125 }; 126 127 enum fe_stv0900_search_standard { 128 STV0900_AUTO_SEARCH, 129 STV0900_SEARCH_DVBS1,/* Search Standard*/ 130 STV0900_SEARCH_DVBS2, 131 STV0900_SEARCH_DSS, 132 STV0900_SEARCH_TURBOCODE 133 }; 134 135 enum fe_stv0900_search_algo { 136 STV0900_BLIND_SEARCH,/* offset freq and SR are Unknown */ 137 STV0900_COLD_START,/* only the SR is known */ 138 STV0900_WARM_START/* offset freq and SR are known */ 139 }; 140 141 enum fe_stv0900_modulation { 142 STV0900_QPSK, 143 STV0900_8PSK, 144 STV0900_16APSK, 145 STV0900_32APSK, 146 STV0900_UNKNOWN 147 }; 148 149 enum fe_stv0900_modcode { 150 STV0900_DUMMY_PLF, 151 STV0900_QPSK_14, 152 STV0900_QPSK_13, 153 STV0900_QPSK_25, 154 STV0900_QPSK_12, 155 STV0900_QPSK_35, 156 STV0900_QPSK_23, 157 STV0900_QPSK_34, 158 STV0900_QPSK_45, 159 STV0900_QPSK_56, 160 STV0900_QPSK_89, 161 STV0900_QPSK_910, 162 STV0900_8PSK_35, 163 STV0900_8PSK_23, 164 STV0900_8PSK_34, 165 STV0900_8PSK_56, 166 STV0900_8PSK_89, 167 STV0900_8PSK_910, 168 STV0900_16APSK_23, 169 STV0900_16APSK_34, 170 STV0900_16APSK_45, 171 STV0900_16APSK_56, 172 STV0900_16APSK_89, 173 STV0900_16APSK_910, 174 STV0900_32APSK_34, 175 STV0900_32APSK_45, 176 STV0900_32APSK_56, 177 STV0900_32APSK_89, 178 STV0900_32APSK_910, 179 STV0900_MODCODE_UNKNOWN 180 }; 181 182 enum fe_stv0900_fec {/*DVBS1, DSS and turbo code puncture rate*/ 183 STV0900_FEC_1_2 = 0, 184 STV0900_FEC_2_3, 185 STV0900_FEC_3_4, 186 STV0900_FEC_4_5,/*for turbo code only*/ 187 STV0900_FEC_5_6, 188 STV0900_FEC_6_7,/*for DSS only */ 189 STV0900_FEC_7_8, 190 STV0900_FEC_8_9,/*for turbo code only*/ 191 STV0900_FEC_UNKNOWN 192 }; 193 194 enum fe_stv0900_frame_length { 195 STV0900_LONG_FRAME, 196 STV0900_SHORT_FRAME 197 }; 198 199 enum fe_stv0900_pilot { 200 STV0900_PILOTS_OFF, 201 STV0900_PILOTS_ON 202 }; 203 204 enum fe_stv0900_rolloff { 205 STV0900_35, 206 STV0900_25, 207 STV0900_20 208 }; 209 210 enum fe_stv0900_search_iq { 211 STV0900_IQ_AUTO, 212 STV0900_IQ_AUTO_NORMAL_FIRST, 213 STV0900_IQ_FORCE_NORMAL, 214 STV0900_IQ_FORCE_SWAPPED 215 }; 216 217 enum stv0900_iq_inversion { 218 STV0900_IQ_NORMAL, 219 STV0900_IQ_SWAPPED 220 }; 221 222 enum fe_stv0900_diseqc_mode { 223 STV0900_22KHZ_Continues = 0, 224 STV0900_DISEQC_2_3_PWM = 2, 225 STV0900_DISEQC_3_3_PWM = 3, 226 STV0900_DISEQC_2_3_ENVELOP = 4, 227 STV0900_DISEQC_3_3_ENVELOP = 5 228 }; 229 230 enum fe_stv0900_demod_mode { 231 STV0900_SINGLE = 0, 232 STV0900_DUAL 233 }; 234 235 struct stv0900_init_params{ 236 u32 dmd_ref_clk;/* Reference,Input clock for the demod in Hz */ 237 238 /* Demodulator Type (single demod or dual demod) */ 239 enum fe_stv0900_demod_mode demod_mode; 240 enum fe_stv0900_rolloff rolloff; 241 enum fe_stv0900_clock_type path1_ts_clock; 242 243 u8 tun1_maddress; 244 int tuner1_adc; 245 int tuner1_type; 246 247 /* IQ from the tuner1 to the demod */ 248 enum stv0900_iq_inversion tun1_iq_inv; 249 enum fe_stv0900_clock_type path2_ts_clock; 250 251 u8 tun2_maddress; 252 int tuner2_adc; 253 int tuner2_type; 254 255 /* IQ from the tuner2 to the demod */ 256 enum stv0900_iq_inversion tun2_iq_inv; 257 struct stv0900_reg *ts_config; 258 }; 259 260 struct stv0900_search_params { 261 enum fe_stv0900_demod_num path;/* Path Used demod1 or 2 */ 262 263 u32 frequency;/* Transponder frequency (in KHz) */ 264 u32 symbol_rate;/* Transponder symbol rate (in bds)*/ 265 u32 search_range;/* Range of the search (in Hz) */ 266 267 enum fe_stv0900_search_standard standard; 268 enum fe_stv0900_modulation modulation; 269 enum fe_stv0900_fec fec; 270 enum fe_stv0900_modcode modcode; 271 enum fe_stv0900_search_iq iq_inversion; 272 enum fe_stv0900_search_algo search_algo; 273 274 }; 275 276 struct stv0900_signal_info { 277 int locked;/* Transponder locked */ 278 u32 frequency;/* Transponder frequency (in KHz) */ 279 u32 symbol_rate;/* Transponder symbol rate (in Mbds) */ 280 281 enum fe_stv0900_tracking_standard standard; 282 enum fe_stv0900_fec fec; 283 enum fe_stv0900_modcode modcode; 284 enum fe_stv0900_modulation modulation; 285 enum fe_stv0900_pilot pilot; 286 enum fe_stv0900_frame_length frame_len; 287 enum stv0900_iq_inversion spectrum; 288 enum fe_stv0900_rolloff rolloff; 289 290 s32 Power;/* Power of the RF signal (dBm) */ 291 s32 C_N;/* Carrier to noise ratio (dB x10)*/ 292 u32 BER;/* Bit error rate (x10^7) */ 293 294 }; 295 296 struct stv0900_internal{ 297 s32 quartz; 298 s32 mclk; 299 /* manual RollOff for DVBS1/DSS only */ 300 enum fe_stv0900_rolloff rolloff; 301 /* Demodulator use for single demod or for dual demod) */ 302 enum fe_stv0900_demod_mode demod_mode; 303 304 /*Demods */ 305 s32 freq[2]; 306 s32 bw[2]; 307 s32 symbol_rate[2]; 308 s32 srch_range[2]; 309 /* for software/auto tuner */ 310 int tuner_type[2]; 311 312 /* algorithm for search Blind, Cold or Warm*/ 313 enum fe_stv0900_search_algo srch_algo[2]; 314 /* search standard: Auto, DVBS1/DSS only or DVBS2 only*/ 315 enum fe_stv0900_search_standard srch_standard[2]; 316 /* inversion search : auto, auto norma first, normal or inverted */ 317 enum fe_stv0900_search_iq srch_iq_inv[2]; 318 enum fe_stv0900_modcode modcode[2]; 319 enum fe_stv0900_modulation modulation[2]; 320 enum fe_stv0900_fec fec[2]; 321 322 struct stv0900_signal_info result[2]; 323 enum fe_stv0900_error err[2]; 324 325 326 struct i2c_adapter *i2c_adap; 327 u8 i2c_addr; 328 u8 clkmode;/* 0 for CLKI, 2 for XTALI */ 329 u8 chip_id; 330 struct stv0900_reg *ts_config; 331 enum fe_stv0900_error errs; 332 int dmds_used; 333 }; 334 335 /* state for each demod */ 336 struct stv0900_state { 337 /* pointer for internal params, one for each pair of demods */ 338 struct stv0900_internal *internal; 339 struct i2c_adapter *i2c_adap; 340 const struct stv0900_config *config; 341 struct dvb_frontend frontend; 342 int demod; 343 }; 344 345 extern int stvdebug; 346 347 extern s32 ge2comp(s32 a, s32 width); 348 349 extern void stv0900_write_reg(struct stv0900_internal *i_params, 350 u16 reg_addr, u8 reg_data); 351 352 extern u8 stv0900_read_reg(struct stv0900_internal *i_params, 353 u16 reg_addr); 354 355 extern void stv0900_write_bits(struct stv0900_internal *i_params, 356 u32 label, u8 val); 357 358 extern u8 stv0900_get_bits(struct stv0900_internal *i_params, 359 u32 label); 360 361 extern int stv0900_get_demod_lock(struct stv0900_internal *i_params, 362 enum fe_stv0900_demod_num demod, s32 time_out); 363 extern int stv0900_check_signal_presence(struct stv0900_internal *i_params, 364 enum fe_stv0900_demod_num demod); 365 366 extern enum fe_stv0900_signal_type stv0900_algo(struct dvb_frontend *fe); 367 368 extern void stv0900_set_tuner(struct dvb_frontend *fe, u32 frequency, 369 u32 bandwidth); 370 extern void stv0900_set_bandwidth(struct dvb_frontend *fe, u32 bandwidth); 371 372 extern void stv0900_start_search(struct stv0900_internal *i_params, 373 enum fe_stv0900_demod_num demod); 374 375 extern u8 stv0900_get_optim_carr_loop(s32 srate, 376 enum fe_stv0900_modcode modcode, 377 s32 pilot, u8 chip_id); 378 379 extern u8 stv0900_get_optim_short_carr_loop(s32 srate, 380 enum fe_stv0900_modulation modulation, 381 u8 chip_id); 382 383 extern void stv0900_stop_all_s2_modcod(struct stv0900_internal *i_params, 384 enum fe_stv0900_demod_num demod); 385 386 extern void stv0900_activate_s2_modcod(struct stv0900_internal *i_params, 387 enum fe_stv0900_demod_num demod); 388 389 extern void stv0900_activate_s2_modcod_single(struct stv0900_internal *i_params, 390 enum fe_stv0900_demod_num demod); 391 392 extern enum 393 fe_stv0900_tracking_standard stv0900_get_standard(struct dvb_frontend *fe, 394 enum fe_stv0900_demod_num demod); 395 396 extern u32 397 stv0900_get_freq_auto(struct stv0900_internal *intp, int demod); 398 399 extern void 400 stv0900_set_tuner_auto(struct stv0900_internal *intp, u32 Frequency, 401 u32 Bandwidth, int demod); 402 403 #endif 404