stb0899_priv.h 7.1 KB

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