stb0899_priv.h 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  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 MIN(x, y) ((x) <= (y) ? (x) : (y))
  51. #define MAX(x, y) ((x) >= (y) ? (x) : (y))
  52. #define ABS(x) ((x) >= 0 ? (x) : -(x))
  53. #define LSB(x) ((x & 0xff))
  54. #define MSB(y) ((y >> 8) & 0xff)
  55. #define STB0899_GETFIELD(bitf, val) ((val >> STB0899_OFFST_##bitf) & ((1 << STB0899_WIDTH_##bitf) - 1))
  56. #define STB0899_SETFIELD(mask, val, width, offset) (mask & (~(((1 << width) - 1) << \
  57. offset))) | ((val & \
  58. ((1 << width) - 1)) << offset)
  59. #define STB0899_SETFIELD_VAL(bitf, mask, val) (mask = (mask & (~(((1 << STB0899_WIDTH_##bitf) - 1) <<\
  60. STB0899_OFFST_##bitf))) | \
  61. (val << STB0899_OFFST_##bitf))
  62. enum stb0899_status {
  63. NOAGC1 = 0,
  64. AGC1OK,
  65. NOTIMING,
  66. ANALOGCARRIER,
  67. TIMINGOK,
  68. NOAGC2,
  69. AGC2OK,
  70. NOCARRIER,
  71. CARRIEROK,
  72. NODATA,
  73. FALSELOCK,
  74. DATAOK,
  75. OUTOFRANGE,
  76. RANGEOK,
  77. DVBS2_DEMOD_LOCK,
  78. DVBS2_DEMOD_NOLOCK,
  79. DVBS2_FEC_LOCK,
  80. DVBS2_FEC_NOLOCK
  81. };
  82. enum stb0899_modcod {
  83. STB0899_DUMMY_PLF,
  84. STB0899_QPSK_14,
  85. STB0899_QPSK_13,
  86. STB0899_QPSK_25,
  87. STB0899_QPSK_12,
  88. STB0899_QPSK_35,
  89. STB0899_QPSK_23,
  90. STB0899_QPSK_34,
  91. STB0899_QPSK_45,
  92. STB0899_QPSK_56,
  93. STB0899_QPSK_89,
  94. STB0899_QPSK_910,
  95. STB0899_8PSK_35,
  96. STB0899_8PSK_23,
  97. STB0899_8PSK_34,
  98. STB0899_8PSK_56,
  99. STB0899_8PSK_89,
  100. STB0899_8PSK_910,
  101. STB0899_16APSK_23,
  102. STB0899_16APSK_34,
  103. STB0899_16APSK_45,
  104. STB0899_16APSK_56,
  105. STB0899_16APSK_89,
  106. STB0899_16APSK_910,
  107. STB0899_32APSK_34,
  108. STB0899_32APSK_45,
  109. STB0899_32APSK_56,
  110. STB0899_32APSK_89,
  111. STB0899_32APSK_910
  112. };
  113. enum stb0899_frame {
  114. STB0899_LONG_FRAME,
  115. STB0899_SHORT_FRAME
  116. };
  117. enum stb0899_alpha {
  118. RRC_20,
  119. RRC_25,
  120. RRC_35
  121. };
  122. struct stb0899_tab {
  123. s32 real;
  124. s32 read;
  125. };
  126. enum stb0899_fec {
  127. STB0899_FEC_1_2 = 13,
  128. STB0899_FEC_2_3 = 18,
  129. STB0899_FEC_3_4 = 21,
  130. STB0899_FEC_5_6 = 24,
  131. STB0899_FEC_6_7 = 25,
  132. STB0899_FEC_7_8 = 26
  133. };
  134. struct stb0899_params {
  135. u32 freq; /* Frequency */
  136. u32 srate; /* Symbol rate */
  137. enum fe_code_rate fecrate;
  138. };
  139. struct stb0899_internal {
  140. u32 master_clk;
  141. u32 freq; /* Demod internal Frequency */
  142. u32 srate; /* Demod internal Symbol rate */
  143. enum stb0899_fec fecrate; /* Demod internal FEC rate */
  144. u32 srch_range; /* Demod internal Search Range */
  145. u32 sub_range; /* Demod current sub range (Hz) */
  146. u32 tuner_step; /* Tuner step (Hz) */
  147. u32 tuner_offst; /* Relative offset to carrier (Hz) */
  148. u32 tuner_bw; /* Current bandwidth of the tuner (Hz) */
  149. s32 mclk; /* Masterclock Divider factor (binary) */
  150. s32 rolloff; /* Current RollOff of the filter (x100) */
  151. s16 derot_freq; /* Current derotator frequency (Hz) */
  152. s16 derot_percent;
  153. s16 direction; /* Current derotator search direction */
  154. s16 derot_step; /* Derotator step (binary value) */
  155. s16 t_derot; /* Derotator time constant (ms) */
  156. s16 t_data; /* Data recovery time constant (ms) */
  157. s16 sub_dir; /* Direction of the next sub range */
  158. s16 t_agc1; /* Agc1 time constant (ms) */
  159. s16 t_agc2; /* Agc2 time constant (ms) */
  160. u32 lock; /* Demod internal lock state */
  161. enum stb0899_status status; /* Demod internal status */
  162. /* DVB-S2 */
  163. s32 agc_gain; /* RF AGC Gain */
  164. s32 center_freq; /* Nominal carrier frequency */
  165. s32 av_frame_coarse; /* Coarse carrier freq search frames */
  166. s32 av_frame_fine; /* Fine carrier freq search frames */
  167. s16 step_size; /* Carrier frequency search step size */
  168. enum stb0899_alpha rrc_alpha;
  169. enum stb0899_inversion inversion;
  170. enum stb0899_modcod modcod;
  171. u8 pilots; /* Pilots found */
  172. enum stb0899_frame frame_length;
  173. u8 v_status; /* VSTATUS */
  174. u8 err_ctrl; /* ERRCTRLn */
  175. };
  176. struct stb0899_state {
  177. struct i2c_adapter *i2c;
  178. struct stb0899_config *config;
  179. struct dvb_frontend frontend;
  180. u32 *verbose; /* Cached module verbosity level */
  181. struct stb0899_internal internal; /* Device internal parameters */
  182. /* cached params from API */
  183. enum fe_delivery_system delsys;
  184. struct stb0899_params params;
  185. u32 rx_freq; /* DiSEqC 2.0 receiver freq */
  186. struct mutex search_lock;
  187. };
  188. /* stb0899.c */
  189. extern int stb0899_read_reg(struct stb0899_state *state,
  190. unsigned int reg);
  191. extern u32 _stb0899_read_s2reg(struct stb0899_state *state,
  192. u32 stb0899_i2cdev,
  193. u32 stb0899_base_addr,
  194. u16 stb0899_reg_offset);
  195. extern int stb0899_read_regs(struct stb0899_state *state,
  196. unsigned int reg, u8 *buf,
  197. u32 count);
  198. extern int stb0899_write_regs(struct stb0899_state *state,
  199. unsigned int reg, u8 *data,
  200. u32 count);
  201. extern int stb0899_write_reg(struct stb0899_state *state,
  202. unsigned int reg,
  203. u8 data);
  204. extern int stb0899_write_s2reg(struct stb0899_state *state,
  205. u32 stb0899_i2cdev,
  206. u32 stb0899_base_addr,
  207. u16 stb0899_reg_offset,
  208. u32 stb0899_data);
  209. extern int stb0899_i2c_gate_ctrl(struct dvb_frontend *fe, int enable);
  210. #define STB0899_READ_S2REG(DEVICE, REG) (_stb0899_read_s2reg(state, DEVICE, STB0899_BASE_##REG, STB0899_OFF0_##REG))
  211. //#define STB0899_WRITE_S2REG(DEVICE, REG, DATA) (_stb0899_write_s2reg(state, DEVICE, STB0899_BASE_##REG, STB0899_OFF0_##REG, DATA))
  212. /* stb0899_algo.c */
  213. extern enum stb0899_status stb0899_dvbs_algo(struct stb0899_state *state);
  214. extern enum stb0899_status stb0899_dvbs2_algo(struct stb0899_state *state);
  215. extern long stb0899_carr_width(struct stb0899_state *state);
  216. #endif //__STB0899_PRIV_H