stv0900_priv.h 9.2 KB

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