drxk_hard.h 11 KB

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