stb0899_priv.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. STB0899 Multistandard Frontend driver
  4. Copyright (C) Manu Abraham ([email protected])
  5. Copyright (C) ST Microelectronics
  6. */
  7. #ifndef __STB0899_PRIV_H
  8. #define __STB0899_PRIV_H
  9. #include <media/dvb_frontend.h>
  10. #include "stb0899_drv.h"
  11. #define FE_ERROR 0
  12. #define FE_NOTICE 1
  13. #define FE_INFO 2
  14. #define FE_DEBUG 3
  15. #define FE_DEBUGREG 4
  16. #define dprintk(x, y, z, format, arg...) do { \
  17. if (z) { \
  18. if ((*x > FE_ERROR) && (*x > y)) \
  19. printk(KERN_ERR "%s: " format "\n", __func__ , ##arg); \
  20. else if ((*x > FE_NOTICE) && (*x > y)) \
  21. printk(KERN_NOTICE "%s: " format "\n", __func__ , ##arg); \
  22. else if ((*x > FE_INFO) && (*x > y)) \
  23. printk(KERN_INFO "%s: " format "\n", __func__ , ##arg); \
  24. else if ((*x > FE_DEBUG) && (*x > y)) \
  25. printk(KERN_DEBUG "%s: " format "\n", __func__ , ##arg); \
  26. } else { \
  27. if (*x > y) \
  28. printk(format, ##arg); \
  29. } \
  30. } while(0)
  31. #define INRANGE(val, x, y) (((x <= val) && (val <= y)) || \
  32. ((y <= val) && (val <= x)) ? 1 : 0)
  33. #define BYTE0 0
  34. #define BYTE1 8
  35. #define BYTE2 16
  36. #define BYTE3 24
  37. #define GETBYTE(x, y) (((x) >> (y)) & 0xff)
  38. #define MAKEWORD32(a, b, c, d) (((a) << 24) | ((b) << 16) | ((c) << 8) | (d))
  39. #define MAKEWORD16(a, b) (((a) << 8) | (b))
  40. #define LSB(x) ((x & 0xff))
  41. #define MSB(y) ((y >> 8) & 0xff)
  42. #define STB0899_GETFIELD(bitf, val) ((val >> STB0899_OFFST_##bitf) & ((1 << STB0899_WIDTH_##bitf) - 1))
  43. #define STB0899_SETFIELD(mask, val, width, offset) (mask & (~(((1 << width) - 1) << \
  44. offset))) | ((val & \
  45. ((1 << width) - 1)) << offset)
  46. #define STB0899_SETFIELD_VAL(bitf, mask, val) (mask = (mask & (~(((1 << STB0899_WIDTH_##bitf) - 1) <<\
  47. STB0899_OFFST_##bitf))) | \
  48. (val << STB0899_OFFST_##bitf))
  49. enum stb0899_status {
  50. NOAGC1 = 0,
  51. AGC1OK,
  52. NOTIMING,
  53. ANALOGCARRIER,
  54. TIMINGOK,
  55. NOAGC2,
  56. AGC2OK,
  57. NOCARRIER,
  58. CARRIEROK,
  59. NODATA,
  60. FALSELOCK,
  61. DATAOK,
  62. OUTOFRANGE,
  63. RANGEOK,
  64. DVBS2_DEMOD_LOCK,
  65. DVBS2_DEMOD_NOLOCK,
  66. DVBS2_FEC_LOCK,
  67. DVBS2_FEC_NOLOCK
  68. };
  69. enum stb0899_modcod {
  70. STB0899_DUMMY_PLF,
  71. STB0899_QPSK_14,
  72. STB0899_QPSK_13,
  73. STB0899_QPSK_25,
  74. STB0899_QPSK_12,
  75. STB0899_QPSK_35,
  76. STB0899_QPSK_23,
  77. STB0899_QPSK_34,
  78. STB0899_QPSK_45,
  79. STB0899_QPSK_56,
  80. STB0899_QPSK_89,
  81. STB0899_QPSK_910,
  82. STB0899_8PSK_35,
  83. STB0899_8PSK_23,
  84. STB0899_8PSK_34,
  85. STB0899_8PSK_56,
  86. STB0899_8PSK_89,
  87. STB0899_8PSK_910,
  88. STB0899_16APSK_23,
  89. STB0899_16APSK_34,
  90. STB0899_16APSK_45,
  91. STB0899_16APSK_56,
  92. STB0899_16APSK_89,
  93. STB0899_16APSK_910,
  94. STB0899_32APSK_34,
  95. STB0899_32APSK_45,
  96. STB0899_32APSK_56,
  97. STB0899_32APSK_89,
  98. STB0899_32APSK_910
  99. };
  100. enum stb0899_frame {
  101. STB0899_LONG_FRAME,
  102. STB0899_SHORT_FRAME
  103. };
  104. enum stb0899_alpha {
  105. RRC_20,
  106. RRC_25,
  107. RRC_35
  108. };
  109. struct stb0899_tab {
  110. s32 real;
  111. s32 read;
  112. };
  113. enum stb0899_fec {
  114. STB0899_FEC_1_2 = 13,
  115. STB0899_FEC_2_3 = 18,
  116. STB0899_FEC_3_4 = 21,
  117. STB0899_FEC_5_6 = 24,
  118. STB0899_FEC_6_7 = 25,
  119. STB0899_FEC_7_8 = 26
  120. };
  121. struct stb0899_params {
  122. u32 freq; /* Frequency */
  123. u32 srate; /* Symbol rate */
  124. enum fe_code_rate fecrate;
  125. };
  126. struct stb0899_internal {
  127. u32 master_clk;
  128. u32 freq; /* Demod internal Frequency */
  129. u32 srate; /* Demod internal Symbol rate */
  130. enum stb0899_fec fecrate; /* Demod internal FEC rate */
  131. s32 srch_range; /* Demod internal Search Range */
  132. s32 sub_range; /* Demod current sub range (Hz) */
  133. s32 tuner_step; /* Tuner step (Hz) */
  134. s32 tuner_offst; /* Relative offset to carrier (Hz) */
  135. u32 tuner_bw; /* Current bandwidth of the tuner (Hz) */
  136. s32 mclk; /* Masterclock Divider factor (binary) */
  137. s32 rolloff; /* Current RollOff of the filter (x100) */
  138. s16 derot_freq; /* Current derotator frequency (Hz) */
  139. s16 derot_percent;
  140. s16 direction; /* Current derotator search direction */
  141. s16 derot_step; /* Derotator step (binary value) */
  142. s16 t_derot; /* Derotator time constant (ms) */
  143. s16 t_data; /* Data recovery time constant (ms) */
  144. s16 sub_dir; /* Direction of the next sub range */
  145. s16 t_agc1; /* Agc1 time constant (ms) */
  146. s16 t_agc2; /* Agc2 time constant (ms) */
  147. u32 lock; /* Demod internal lock state */
  148. enum stb0899_status status; /* Demod internal status */
  149. /* DVB-S2 */
  150. s32 agc_gain; /* RF AGC Gain */
  151. s32 center_freq; /* Nominal carrier frequency */
  152. s32 av_frame_coarse; /* Coarse carrier freq search frames */
  153. s32 av_frame_fine; /* Fine carrier freq search frames */
  154. s16 step_size; /* Carrier frequency search step size */
  155. enum stb0899_alpha rrc_alpha;
  156. enum stb0899_inversion inversion;
  157. enum stb0899_modcod modcod;
  158. u8 pilots; /* Pilots found */
  159. enum stb0899_frame frame_length;
  160. u8 v_status; /* VSTATUS */
  161. u8 err_ctrl; /* ERRCTRLn */
  162. };
  163. struct stb0899_state {
  164. struct i2c_adapter *i2c;
  165. struct stb0899_config *config;
  166. struct dvb_frontend frontend;
  167. u32 *verbose; /* Cached module verbosity level */
  168. struct stb0899_internal internal; /* Device internal parameters */
  169. /* cached params from API */
  170. enum fe_delivery_system delsys;
  171. struct stb0899_params params;
  172. u32 rx_freq; /* DiSEqC 2.0 receiver freq */
  173. struct mutex search_lock;
  174. };
  175. /* stb0899.c */
  176. extern int stb0899_read_reg(struct stb0899_state *state,
  177. unsigned int reg);
  178. extern u32 _stb0899_read_s2reg(struct stb0899_state *state,
  179. u32 stb0899_i2cdev,
  180. u32 stb0899_base_addr,
  181. u16 stb0899_reg_offset);
  182. extern int stb0899_read_regs(struct stb0899_state *state,
  183. unsigned int reg, u8 *buf,
  184. u32 count);
  185. extern int stb0899_write_regs(struct stb0899_state *state,
  186. unsigned int reg, u8 *data,
  187. u32 count);
  188. extern int stb0899_write_reg(struct stb0899_state *state,
  189. unsigned int reg,
  190. u8 data);
  191. extern int stb0899_write_s2reg(struct stb0899_state *state,
  192. u32 stb0899_i2cdev,
  193. u32 stb0899_base_addr,
  194. u16 stb0899_reg_offset,
  195. u32 stb0899_data);
  196. extern int stb0899_i2c_gate_ctrl(struct dvb_frontend *fe, int enable);
  197. #define STB0899_READ_S2REG(DEVICE, REG) (_stb0899_read_s2reg(state, DEVICE, STB0899_BASE_##REG, STB0899_OFF0_##REG))
  198. //#define STB0899_WRITE_S2REG(DEVICE, REG, DATA) (_stb0899_write_s2reg(state, DEVICE, STB0899_BASE_##REG, STB0899_OFF0_##REG, DATA))
  199. /* stb0899_algo.c */
  200. extern enum stb0899_status stb0899_dvbs_algo(struct stb0899_state *state);
  201. extern enum stb0899_status stb0899_dvbs2_algo(struct stb0899_state *state);
  202. extern long stb0899_carr_width(struct stb0899_state *state);
  203. #endif //__STB0899_PRIV_H