drxk_hard.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  1. #include "drxk_map.h"
  2. #define DRXK_VERSION_MAJOR 0
  3. #define DRXK_VERSION_MINOR 9
  4. #define DRXK_VERSION_PATCH 4300
  5. #define HI_I2C_DELAY 42
  6. #define HI_I2C_BRIDGE_DELAY 350
  7. #define DRXK_MAX_RETRIES 100
  8. #define DRIVER_4400 1
  9. #define DRXX_JTAGID 0x039210D9
  10. #define DRXX_J_JTAGID 0x239310D9
  11. #define DRXX_K_JTAGID 0x039210D9
  12. #define DRX_UNKNOWN 254
  13. #define DRX_AUTO 255
  14. #define DRX_SCU_READY 0
  15. #define DRXK_MAX_WAITTIME (200)
  16. #define SCU_RESULT_OK 0
  17. #define SCU_RESULT_SIZE -4
  18. #define SCU_RESULT_INVPAR -3
  19. #define SCU_RESULT_UNKSTD -2
  20. #define SCU_RESULT_UNKCMD -1
  21. #ifndef DRXK_OFDM_TR_SHUTDOWN_TIMEOUT
  22. #define DRXK_OFDM_TR_SHUTDOWN_TIMEOUT (200)
  23. #endif
  24. #define DRXK_8VSB_MPEG_BIT_RATE 19392658UL /*bps*/
  25. #define DRXK_DVBT_MPEG_BIT_RATE 32000000UL /*bps*/
  26. #define DRXK_QAM16_MPEG_BIT_RATE 27000000UL /*bps*/
  27. #define DRXK_QAM32_MPEG_BIT_RATE 33000000UL /*bps*/
  28. #define DRXK_QAM64_MPEG_BIT_RATE 40000000UL /*bps*/
  29. #define DRXK_QAM128_MPEG_BIT_RATE 46000000UL /*bps*/
  30. #define DRXK_QAM256_MPEG_BIT_RATE 52000000UL /*bps*/
  31. #define DRXK_MAX_MPEG_BIT_RATE 52000000UL /*bps*/
  32. #define IQM_CF_OUT_ENA_OFDM__M 0x4
  33. #define IQM_FS_ADJ_SEL_B_QAM 0x1
  34. #define IQM_FS_ADJ_SEL_B_OFF 0x0
  35. #define IQM_FS_ADJ_SEL_B_VSB 0x2
  36. #define IQM_RC_ADJ_SEL_B_OFF 0x0
  37. #define IQM_RC_ADJ_SEL_B_QAM 0x1
  38. #define IQM_RC_ADJ_SEL_B_VSB 0x2
  39. enum operation_mode {
  40. OM_NONE,
  41. OM_QAM_ITU_A,
  42. OM_QAM_ITU_B,
  43. OM_QAM_ITU_C,
  44. OM_DVBT
  45. };
  46. enum drx_power_mode {
  47. DRX_POWER_UP = 0,
  48. DRX_POWER_MODE_1,
  49. DRX_POWER_MODE_2,
  50. DRX_POWER_MODE_3,
  51. DRX_POWER_MODE_4,
  52. DRX_POWER_MODE_5,
  53. DRX_POWER_MODE_6,
  54. DRX_POWER_MODE_7,
  55. DRX_POWER_MODE_8,
  56. DRX_POWER_MODE_9,
  57. DRX_POWER_MODE_10,
  58. DRX_POWER_MODE_11,
  59. DRX_POWER_MODE_12,
  60. DRX_POWER_MODE_13,
  61. DRX_POWER_MODE_14,
  62. DRX_POWER_MODE_15,
  63. DRX_POWER_MODE_16,
  64. DRX_POWER_DOWN = 255
  65. };
  66. /* Intermediate power mode for DRXK, power down OFDM clock domain */
  67. #ifndef DRXK_POWER_DOWN_OFDM
  68. #define DRXK_POWER_DOWN_OFDM DRX_POWER_MODE_1
  69. #endif
  70. /* Intermediate power mode for DRXK, power down core (sysclk) */
  71. #ifndef DRXK_POWER_DOWN_CORE
  72. #define DRXK_POWER_DOWN_CORE DRX_POWER_MODE_9
  73. #endif
  74. /* Intermediate power mode for DRXK, power down pll (only osc runs) */
  75. #ifndef DRXK_POWER_DOWN_PLL
  76. #define DRXK_POWER_DOWN_PLL DRX_POWER_MODE_10
  77. #endif
  78. enum agc_ctrl_mode {
  79. DRXK_AGC_CTRL_AUTO = 0,
  80. DRXK_AGC_CTRL_USER,
  81. DRXK_AGC_CTRL_OFF
  82. };
  83. enum e_drxk_state {
  84. DRXK_UNINITIALIZED = 0,
  85. DRXK_STOPPED,
  86. DRXK_DTV_STARTED,
  87. DRXK_ATV_STARTED,
  88. DRXK_POWERED_DOWN,
  89. DRXK_NO_DEV /* If drxk init failed */
  90. };
  91. enum e_drxk_coef_array_index {
  92. DRXK_COEF_IDX_MN = 0,
  93. DRXK_COEF_IDX_FM ,
  94. DRXK_COEF_IDX_L ,
  95. DRXK_COEF_IDX_LP ,
  96. DRXK_COEF_IDX_BG ,
  97. DRXK_COEF_IDX_DK ,
  98. DRXK_COEF_IDX_I ,
  99. DRXK_COEF_IDX_MAX
  100. };
  101. enum e_drxk_sif_attenuation {
  102. DRXK_SIF_ATTENUATION_0DB,
  103. DRXK_SIF_ATTENUATION_3DB,
  104. DRXK_SIF_ATTENUATION_6DB,
  105. DRXK_SIF_ATTENUATION_9DB
  106. };
  107. enum e_drxk_constellation {
  108. DRX_CONSTELLATION_BPSK = 0,
  109. DRX_CONSTELLATION_QPSK,
  110. DRX_CONSTELLATION_PSK8,
  111. DRX_CONSTELLATION_QAM16,
  112. DRX_CONSTELLATION_QAM32,
  113. DRX_CONSTELLATION_QAM64,
  114. DRX_CONSTELLATION_QAM128,
  115. DRX_CONSTELLATION_QAM256,
  116. DRX_CONSTELLATION_QAM512,
  117. DRX_CONSTELLATION_QAM1024,
  118. DRX_CONSTELLATION_UNKNOWN = DRX_UNKNOWN,
  119. DRX_CONSTELLATION_AUTO = DRX_AUTO
  120. };
  121. enum e_drxk_interleave_mode {
  122. DRXK_QAM_I12_J17 = 16,
  123. DRXK_QAM_I_UNKNOWN = DRX_UNKNOWN
  124. };
  125. enum {
  126. DRXK_SPIN_A1 = 0,
  127. DRXK_SPIN_A2,
  128. DRXK_SPIN_A3,
  129. DRXK_SPIN_UNKNOWN
  130. };
  131. enum drxk_cfg_dvbt_sqi_speed {
  132. DRXK_DVBT_SQI_SPEED_FAST = 0,
  133. DRXK_DVBT_SQI_SPEED_MEDIUM,
  134. DRXK_DVBT_SQI_SPEED_SLOW,
  135. DRXK_DVBT_SQI_SPEED_UNKNOWN = DRX_UNKNOWN
  136. } ;
  137. enum drx_fftmode_t {
  138. DRX_FFTMODE_2K = 0,
  139. DRX_FFTMODE_4K,
  140. DRX_FFTMODE_8K,
  141. DRX_FFTMODE_UNKNOWN = DRX_UNKNOWN,
  142. DRX_FFTMODE_AUTO = DRX_AUTO
  143. };
  144. enum drxmpeg_str_width_t {
  145. DRX_MPEG_STR_WIDTH_1,
  146. DRX_MPEG_STR_WIDTH_8
  147. };
  148. enum drx_qam_lock_range_t {
  149. DRX_QAM_LOCKRANGE_NORMAL,
  150. DRX_QAM_LOCKRANGE_EXTENDED
  151. };
  152. struct drxk_cfg_dvbt_echo_thres_t {
  153. u16 threshold;
  154. enum drx_fftmode_t fft_mode;
  155. } ;
  156. struct s_cfg_agc {
  157. enum agc_ctrl_mode ctrl_mode; /* off, user, auto */
  158. u16 output_level; /* range dependent on AGC */
  159. u16 min_output_level; /* range dependent on AGC */
  160. u16 max_output_level; /* range dependent on AGC */
  161. u16 speed; /* range dependent on AGC */
  162. u16 top; /* rf-agc take over point */
  163. u16 cut_off_current; /* rf-agc is accelerated if output current
  164. is below cut-off current */
  165. u16 ingain_tgt_max;
  166. u16 fast_clip_ctrl_delay;
  167. };
  168. struct s_cfg_pre_saw {
  169. u16 reference; /* pre SAW reference value, range 0 .. 31 */
  170. bool use_pre_saw; /* TRUE algorithms must use pre SAW sense */
  171. };
  172. struct drxk_ofdm_sc_cmd_t {
  173. u16 cmd; /* Command number */
  174. u16 subcmd; /* Sub-command parameter*/
  175. u16 param0; /* General purpous param */
  176. u16 param1; /* General purpous param */
  177. u16 param2; /* General purpous param */
  178. u16 param3; /* General purpous param */
  179. u16 param4; /* General purpous param */
  180. };
  181. struct drxk_state {
  182. struct dvb_frontend frontend;
  183. struct dtv_frontend_properties props;
  184. struct device *dev;
  185. struct i2c_adapter *i2c;
  186. u8 demod_address;
  187. void *priv;
  188. struct mutex mutex;
  189. u32 m_instance; /* Channel 1,2,3 or 4 */
  190. int m_chunk_size;
  191. u8 chunk[256];
  192. bool m_has_lna;
  193. bool m_has_dvbt;
  194. bool m_has_dvbc;
  195. bool m_has_audio;
  196. bool m_has_atv;
  197. bool m_has_oob;
  198. bool m_has_sawsw; /* TRUE if mat_tx is available */
  199. bool m_has_gpio1; /* TRUE if mat_rx is available */
  200. bool m_has_gpio2; /* TRUE if GPIO is available */
  201. bool m_has_irqn; /* TRUE if IRQN is available */
  202. u16 m_osc_clock_freq;
  203. u16 m_hi_cfg_timing_div;
  204. u16 m_hi_cfg_bridge_delay;
  205. u16 m_hi_cfg_wake_up_key;
  206. u16 m_hi_cfg_timeout;
  207. u16 m_hi_cfg_ctrl;
  208. s32 m_sys_clock_freq; /* system clock frequency in kHz */
  209. enum e_drxk_state m_drxk_state; /* State of Drxk (init,stopped,started) */
  210. enum operation_mode m_operation_mode; /* digital standards */
  211. struct s_cfg_agc m_vsb_rf_agc_cfg; /* settings for VSB RF-AGC */
  212. struct s_cfg_agc m_vsb_if_agc_cfg; /* settings for VSB IF-AGC */
  213. u16 m_vsb_pga_cfg; /* settings for VSB PGA */
  214. struct s_cfg_pre_saw m_vsb_pre_saw_cfg; /* settings for pre SAW sense */
  215. s32 m_Quality83percent; /* MER level (*0.1 dB) for 83% quality indication */
  216. s32 m_Quality93percent; /* MER level (*0.1 dB) for 93% quality indication */
  217. bool m_smart_ant_inverted;
  218. bool m_b_debug_enable_bridge;
  219. bool m_b_p_down_open_bridge; /* only open DRXK bridge before power-down once it has been accessed */
  220. bool m_b_power_down; /* Power down when not used */
  221. u32 m_iqm_fs_rate_ofs; /* frequency shift as written to DRXK register (28bit fixpoint) */
  222. bool m_enable_mpeg_output; /* If TRUE, enable MPEG output */
  223. bool m_insert_rs_byte; /* If TRUE, insert RS byte */
  224. bool m_enable_parallel; /* If TRUE, parallel out otherwise serial */
  225. bool m_invert_data; /* If TRUE, invert DATA signals */
  226. bool m_invert_err; /* If TRUE, invert ERR signal */
  227. bool m_invert_str; /* If TRUE, invert STR signals */
  228. bool m_invert_val; /* If TRUE, invert VAL signals */
  229. bool m_invert_clk; /* If TRUE, invert CLK signals */
  230. bool m_dvbc_static_clk;
  231. bool m_dvbt_static_clk; /* If TRUE, static MPEG clockrate will
  232. be used, otherwise clockrate will
  233. adapt to the bitrate of the TS */
  234. u32 m_dvbt_bitrate;
  235. u32 m_dvbc_bitrate;
  236. u8 m_ts_data_strength;
  237. u8 m_ts_clockk_strength;
  238. bool m_itut_annex_c; /* If true, uses ITU-T DVB-C Annex C, instead of Annex A */
  239. enum drxmpeg_str_width_t m_width_str; /* MPEG start width */
  240. u32 m_mpeg_ts_static_bitrate; /* Maximum bitrate in b/s in case
  241. static clockrate is selected */
  242. /* LARGE_INTEGER m_startTime; */ /* Contains the time of the last demod start */
  243. s32 m_mpeg_lock_time_out; /* WaitForLockStatus Timeout (counts from start time) */
  244. s32 m_demod_lock_time_out; /* WaitForLockStatus Timeout (counts from start time) */
  245. bool m_disable_te_ihandling;
  246. bool m_rf_agc_pol;
  247. bool m_if_agc_pol;
  248. struct s_cfg_agc m_atv_rf_agc_cfg; /* settings for ATV RF-AGC */
  249. struct s_cfg_agc m_atv_if_agc_cfg; /* settings for ATV IF-AGC */
  250. struct s_cfg_pre_saw m_atv_pre_saw_cfg; /* settings for ATV pre SAW sense */
  251. bool m_phase_correction_bypass;
  252. s16 m_atv_top_vid_peak;
  253. u16 m_atv_top_noise_th;
  254. enum e_drxk_sif_attenuation m_sif_attenuation;
  255. bool m_enable_cvbs_output;
  256. bool m_enable_sif_output;
  257. bool m_b_mirror_freq_spect;
  258. enum e_drxk_constellation m_constellation; /* constellation type of the channel */
  259. u32 m_curr_symbol_rate; /* Current QAM symbol rate */
  260. struct s_cfg_agc m_qam_rf_agc_cfg; /* settings for QAM RF-AGC */
  261. struct s_cfg_agc m_qam_if_agc_cfg; /* settings for QAM IF-AGC */
  262. u16 m_qam_pga_cfg; /* settings for QAM PGA */
  263. struct s_cfg_pre_saw m_qam_pre_saw_cfg; /* settings for QAM pre SAW sense */
  264. enum e_drxk_interleave_mode m_qam_interleave_mode; /* QAM Interleave mode */
  265. u16 m_fec_rs_plen;
  266. u16 m_fec_rs_prescale;
  267. enum drxk_cfg_dvbt_sqi_speed m_sqi_speed;
  268. u16 m_gpio;
  269. u16 m_gpio_cfg;
  270. struct s_cfg_agc m_dvbt_rf_agc_cfg; /* settings for QAM RF-AGC */
  271. struct s_cfg_agc m_dvbt_if_agc_cfg; /* settings for QAM IF-AGC */
  272. struct s_cfg_pre_saw m_dvbt_pre_saw_cfg; /* settings for QAM pre SAW sense */
  273. u16 m_agcfast_clip_ctrl_delay;
  274. bool m_adc_comp_passed;
  275. u16 m_adcCompCoef[64];
  276. u16 m_adc_state;
  277. u8 *m_microcode;
  278. int m_microcode_length;
  279. bool m_drxk_a3_rom_code;
  280. bool m_drxk_a3_patch_code;
  281. bool m_rfmirror;
  282. u8 m_device_spin;
  283. u32 m_iqm_rc_rate;
  284. enum drx_power_mode m_current_power_mode;
  285. /* when true, avoids other devices to use the I2C bus */
  286. bool drxk_i2c_exclusive_lock;
  287. /*
  288. * Configurable parameters at the driver. They stores the values found
  289. * at struct drxk_config.
  290. */
  291. u16 uio_mask; /* Bits used by UIO */
  292. bool enable_merr_cfg;
  293. bool single_master;
  294. bool no_i2c_bridge;
  295. bool antenna_dvbt;
  296. u16 antenna_gpio;
  297. enum fe_status fe_status;
  298. /* Firmware */
  299. const char *microcode_name;
  300. struct completion fw_wait_load;
  301. const struct firmware *fw;
  302. int qam_demod_parameter_count;
  303. };
  304. #define NEVER_LOCK 0
  305. #define NOT_LOCKED 1
  306. #define DEMOD_LOCK 2
  307. #define FEC_LOCK 3
  308. #define MPEG_LOCK 4