stv0900_priv.h 9.9 KB

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