stv090x_priv.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. STV0900/0903 Multistandard Broadcast Frontend driver
  4. Copyright (C) Manu Abraham <abraham.manu@gmail.com>
  5. Copyright (C) ST Microelectronics
  6. */
  7. #ifndef __STV090x_PRIV_H
  8. #define __STV090x_PRIV_H
  9. #include <media/dvb_frontend.h>
  10. #define FE_ERROR 0
  11. #define FE_NOTICE 1
  12. #define FE_INFO 2
  13. #define FE_DEBUG 3
  14. #define FE_DEBUGREG 4
  15. #define dprintk(__y, __z, format, arg...) do { \
  16. if (__z) { \
  17. if ((verbose > FE_ERROR) && (verbose > __y)) \
  18. printk(KERN_ERR "%s: " format "\n", __func__ , ##arg); \
  19. else if ((verbose > FE_NOTICE) && (verbose > __y)) \
  20. printk(KERN_NOTICE "%s: " format "\n", __func__ , ##arg); \
  21. else if ((verbose > FE_INFO) && (verbose > __y)) \
  22. printk(KERN_INFO "%s: " format "\n", __func__ , ##arg); \
  23. else if ((verbose > FE_DEBUG) && (verbose > __y)) \
  24. printk(KERN_DEBUG "%s: " format "\n", __func__ , ##arg); \
  25. } else { \
  26. if (verbose > __y) \
  27. printk(format, ##arg); \
  28. } \
  29. } while (0)
  30. #define STV090x_READ_DEMOD(__state, __reg) (( \
  31. (__state)->demod == STV090x_DEMODULATOR_1) ? \
  32. stv090x_read_reg(__state, STV090x_P2_##__reg) : \
  33. stv090x_read_reg(__state, STV090x_P1_##__reg))
  34. #define STV090x_WRITE_DEMOD(__state, __reg, __data) (( \
  35. (__state)->demod == STV090x_DEMODULATOR_1) ? \
  36. stv090x_write_reg(__state, STV090x_P2_##__reg, __data) :\
  37. stv090x_write_reg(__state, STV090x_P1_##__reg, __data))
  38. #define STV090x_ADDR_OFFST(__state, __x) (( \
  39. (__state->demod) == STV090x_DEMODULATOR_1) ? \
  40. STV090x_P1_##__x : \
  41. STV090x_P2_##__x)
  42. #define STV090x_SETFIELD(mask, bitf, val) (mask = (mask & (~(((1 << STV090x_WIDTH_##bitf) - 1) <<\
  43. STV090x_OFFST_##bitf))) | \
  44. (val << STV090x_OFFST_##bitf))
  45. #define STV090x_GETFIELD(val, bitf) ((val >> STV090x_OFFST_##bitf) & ((1 << STV090x_WIDTH_##bitf) - 1))
  46. #define STV090x_SETFIELD_Px(mask, bitf, val) (mask = (mask & (~(((1 << STV090x_WIDTH_Px_##bitf) - 1) <<\
  47. STV090x_OFFST_Px_##bitf))) | \
  48. (val << STV090x_OFFST_Px_##bitf))
  49. #define STV090x_GETFIELD_Px(val, bitf) ((val >> STV090x_OFFST_Px_##bitf) & ((1 << STV090x_WIDTH_Px_##bitf) - 1))
  50. #define MAKEWORD16(__a, __b) (((__a) << 8) | (__b))
  51. #define MSB(__x) ((__x >> 8) & 0xff)
  52. #define LSB(__x) (__x & 0xff)
  53. #define STV090x_IQPOWER_THRESHOLD 30
  54. #define STV090x_SEARCH_AGC2_TH_CUT20 700
  55. #define STV090x_SEARCH_AGC2_TH_CUT30 1400
  56. #define STV090x_SEARCH_AGC2_TH(__ver) \
  57. ((__ver <= 0x20) ? \
  58. STV090x_SEARCH_AGC2_TH_CUT20 : \
  59. STV090x_SEARCH_AGC2_TH_CUT30)
  60. enum stv090x_signal_state {
  61. STV090x_NOAGC1,
  62. STV090x_NOCARRIER,
  63. STV090x_NODATA,
  64. STV090x_DATAOK,
  65. STV090x_RANGEOK,
  66. STV090x_OUTOFRANGE
  67. };
  68. enum stv090x_fec {
  69. STV090x_PR12 = 0,
  70. STV090x_PR23,
  71. STV090x_PR34,
  72. STV090x_PR45,
  73. STV090x_PR56,
  74. STV090x_PR67,
  75. STV090x_PR78,
  76. STV090x_PR89,
  77. STV090x_PR910,
  78. STV090x_PRERR
  79. };
  80. enum stv090x_modulation {
  81. STV090x_QPSK,
  82. STV090x_8PSK,
  83. STV090x_16APSK,
  84. STV090x_32APSK,
  85. STV090x_UNKNOWN
  86. };
  87. enum stv090x_frame {
  88. STV090x_LONG_FRAME,
  89. STV090x_SHORT_FRAME
  90. };
  91. enum stv090x_pilot {
  92. STV090x_PILOTS_OFF,
  93. STV090x_PILOTS_ON
  94. };
  95. enum stv090x_rolloff {
  96. STV090x_RO_35,
  97. STV090x_RO_25,
  98. STV090x_RO_20
  99. };
  100. enum stv090x_inversion {
  101. STV090x_IQ_AUTO,
  102. STV090x_IQ_NORMAL,
  103. STV090x_IQ_SWAP
  104. };
  105. enum stv090x_modcod {
  106. STV090x_DUMMY_PLF = 0,
  107. STV090x_QPSK_14,
  108. STV090x_QPSK_13,
  109. STV090x_QPSK_25,
  110. STV090x_QPSK_12,
  111. STV090x_QPSK_35,
  112. STV090x_QPSK_23,
  113. STV090x_QPSK_34,
  114. STV090x_QPSK_45,
  115. STV090x_QPSK_56,
  116. STV090x_QPSK_89,
  117. STV090x_QPSK_910,
  118. STV090x_8PSK_35,
  119. STV090x_8PSK_23,
  120. STV090x_8PSK_34,
  121. STV090x_8PSK_56,
  122. STV090x_8PSK_89,
  123. STV090x_8PSK_910,
  124. STV090x_16APSK_23,
  125. STV090x_16APSK_34,
  126. STV090x_16APSK_45,
  127. STV090x_16APSK_56,
  128. STV090x_16APSK_89,
  129. STV090x_16APSK_910,
  130. STV090x_32APSK_34,
  131. STV090x_32APSK_45,
  132. STV090x_32APSK_56,
  133. STV090x_32APSK_89,
  134. STV090x_32APSK_910,
  135. STV090x_MODCODE_UNKNOWN
  136. };
  137. enum stv090x_search {
  138. STV090x_SEARCH_DSS = 0,
  139. STV090x_SEARCH_DVBS1,
  140. STV090x_SEARCH_DVBS2,
  141. STV090x_SEARCH_AUTO
  142. };
  143. enum stv090x_algo {
  144. STV090x_BLIND_SEARCH,
  145. STV090x_COLD_SEARCH,
  146. STV090x_WARM_SEARCH
  147. };
  148. enum stv090x_delsys {
  149. STV090x_ERROR = 0,
  150. STV090x_DVBS1 = 1,
  151. STV090x_DVBS2,
  152. STV090x_DSS
  153. };
  154. struct stv090x_long_frame_crloop {
  155. enum stv090x_modcod modcod;
  156. u8 crl_pilots_on_2;
  157. u8 crl_pilots_off_2;
  158. u8 crl_pilots_on_5;
  159. u8 crl_pilots_off_5;
  160. u8 crl_pilots_on_10;
  161. u8 crl_pilots_off_10;
  162. u8 crl_pilots_on_20;
  163. u8 crl_pilots_off_20;
  164. u8 crl_pilots_on_30;
  165. u8 crl_pilots_off_30;
  166. };
  167. struct stv090x_short_frame_crloop {
  168. enum stv090x_modulation modulation;
  169. u8 crl_2; /* SR < 3M */
  170. u8 crl_5; /* 3 < SR <= 7M */
  171. u8 crl_10; /* 7 < SR <= 15M */
  172. u8 crl_20; /* 10 < SR <= 25M */
  173. u8 crl_30; /* 10 < SR <= 45M */
  174. };
  175. struct stv090x_reg {
  176. u16 addr;
  177. u8 data;
  178. };
  179. struct stv090x_tab {
  180. s32 real;
  181. s32 read;
  182. };
  183. struct stv090x_internal {
  184. struct i2c_adapter *i2c_adap;
  185. u8 i2c_addr;
  186. struct mutex demod_lock; /* Lock access to shared register */
  187. struct mutex tuner_lock; /* Lock access to tuners */
  188. s32 mclk; /* Masterclock Divider factor */
  189. u32 dev_ver;
  190. int num_used;
  191. };
  192. struct stv090x_state {
  193. enum stv090x_device device;
  194. enum stv090x_demodulator demod;
  195. enum stv090x_mode demod_mode;
  196. struct stv090x_internal *internal;
  197. struct i2c_adapter *i2c;
  198. struct stv090x_config *config;
  199. struct dvb_frontend frontend;
  200. u32 *verbose; /* Cached module verbosity */
  201. enum stv090x_delsys delsys;
  202. enum stv090x_fec fec;
  203. enum stv090x_modulation modulation;
  204. enum stv090x_modcod modcod;
  205. enum stv090x_search search_mode;
  206. enum stv090x_frame frame_len;
  207. enum stv090x_pilot pilots;
  208. enum stv090x_rolloff rolloff;
  209. enum stv090x_inversion inversion;
  210. enum stv090x_algo algo;
  211. u32 frequency;
  212. u32 srate;
  213. s32 tuner_bw;
  214. s32 search_range;
  215. s32 DemodTimeout;
  216. s32 FecTimeout;
  217. };
  218. #endif /* __STV090x_PRIV_H */