drxk_hard.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  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 OperationMode {
  40. OM_NONE,
  41. OM_QAM_ITU_A,
  42. OM_QAM_ITU_B,
  43. OM_QAM_ITU_C,
  44. OM_DVBT
  45. };
  46. enum DRXPowerMode {
  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. /** /brief 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. /** /brief 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. /** /brief 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 { DRXK_AGC_CTRL_AUTO = 0, DRXK_AGC_CTRL_USER, DRXK_AGC_CTRL_OFF };
  79. enum EDrxkState {
  80. DRXK_UNINITIALIZED = 0,
  81. DRXK_STOPPED,
  82. DRXK_DTV_STARTED,
  83. DRXK_ATV_STARTED,
  84. DRXK_POWERED_DOWN,
  85. DRXK_NO_DEV /* If drxk init failed */
  86. };
  87. enum EDrxkCoefArrayIndex {
  88. DRXK_COEF_IDX_MN = 0,
  89. DRXK_COEF_IDX_FM ,
  90. DRXK_COEF_IDX_L ,
  91. DRXK_COEF_IDX_LP ,
  92. DRXK_COEF_IDX_BG ,
  93. DRXK_COEF_IDX_DK ,
  94. DRXK_COEF_IDX_I ,
  95. DRXK_COEF_IDX_MAX
  96. };
  97. enum EDrxkSifAttenuation {
  98. DRXK_SIF_ATTENUATION_0DB,
  99. DRXK_SIF_ATTENUATION_3DB,
  100. DRXK_SIF_ATTENUATION_6DB,
  101. DRXK_SIF_ATTENUATION_9DB
  102. };
  103. enum EDrxkConstellation {
  104. DRX_CONSTELLATION_BPSK = 0,
  105. DRX_CONSTELLATION_QPSK,
  106. DRX_CONSTELLATION_PSK8,
  107. DRX_CONSTELLATION_QAM16,
  108. DRX_CONSTELLATION_QAM32,
  109. DRX_CONSTELLATION_QAM64,
  110. DRX_CONSTELLATION_QAM128,
  111. DRX_CONSTELLATION_QAM256,
  112. DRX_CONSTELLATION_QAM512,
  113. DRX_CONSTELLATION_QAM1024,
  114. DRX_CONSTELLATION_UNKNOWN = DRX_UNKNOWN,
  115. DRX_CONSTELLATION_AUTO = DRX_AUTO
  116. };
  117. enum EDrxkInterleaveMode {
  118. DRXK_QAM_I12_J17 = 16,
  119. DRXK_QAM_I_UNKNOWN = DRX_UNKNOWN
  120. };
  121. enum {
  122. DRXK_SPIN_A1 = 0,
  123. DRXK_SPIN_A2,
  124. DRXK_SPIN_A3,
  125. DRXK_SPIN_UNKNOWN
  126. };
  127. enum DRXKCfgDvbtSqiSpeed {
  128. DRXK_DVBT_SQI_SPEED_FAST = 0,
  129. DRXK_DVBT_SQI_SPEED_MEDIUM,
  130. DRXK_DVBT_SQI_SPEED_SLOW,
  131. DRXK_DVBT_SQI_SPEED_UNKNOWN = DRX_UNKNOWN
  132. } ;
  133. enum DRXFftmode_t {
  134. DRX_FFTMODE_2K = 0,
  135. DRX_FFTMODE_4K,
  136. DRX_FFTMODE_8K,
  137. DRX_FFTMODE_UNKNOWN = DRX_UNKNOWN,
  138. DRX_FFTMODE_AUTO = DRX_AUTO
  139. };
  140. enum DRXMPEGStrWidth_t {
  141. DRX_MPEG_STR_WIDTH_1,
  142. DRX_MPEG_STR_WIDTH_8
  143. };
  144. enum DRXQamLockRange_t {
  145. DRX_QAM_LOCKRANGE_NORMAL,
  146. DRX_QAM_LOCKRANGE_EXTENDED
  147. };
  148. struct DRXKCfgDvbtEchoThres_t {
  149. u16 threshold;
  150. enum DRXFftmode_t fftMode;
  151. } ;
  152. struct SCfgAgc {
  153. enum AGC_CTRL_MODE ctrlMode; /* off, user, auto */
  154. u16 outputLevel; /* range dependent on AGC */
  155. u16 minOutputLevel; /* range dependent on AGC */
  156. u16 maxOutputLevel; /* range dependent on AGC */
  157. u16 speed; /* range dependent on AGC */
  158. u16 top; /* rf-agc take over point */
  159. u16 cutOffCurrent; /* rf-agc is accelerated if output current
  160. is below cut-off current */
  161. u16 IngainTgtMax;
  162. u16 FastClipCtrlDelay;
  163. };
  164. struct SCfgPreSaw {
  165. u16 reference; /* pre SAW reference value, range 0 .. 31 */
  166. bool usePreSaw; /* TRUE algorithms must use pre SAW sense */
  167. };
  168. struct DRXKOfdmScCmd_t {
  169. u16 cmd; /**< Command number */
  170. u16 subcmd; /**< Sub-command parameter*/
  171. u16 param0; /**< General purpous param */
  172. u16 param1; /**< General purpous param */
  173. u16 param2; /**< General purpous param */
  174. u16 param3; /**< General purpous param */
  175. u16 param4; /**< General purpous param */
  176. };
  177. struct drxk_state {
  178. struct dvb_frontend frontend;
  179. struct dtv_frontend_properties props;
  180. struct device *dev;
  181. struct i2c_adapter *i2c;
  182. u8 demod_address;
  183. void *priv;
  184. struct mutex mutex;
  185. u32 m_Instance; /**< Channel 1,2,3 or 4 */
  186. int m_ChunkSize;
  187. u8 Chunk[256];
  188. bool m_hasLNA;
  189. bool m_hasDVBT;
  190. bool m_hasDVBC;
  191. bool m_hasAudio;
  192. bool m_hasATV;
  193. bool m_hasOOB;
  194. bool m_hasSAWSW; /**< TRUE if mat_tx is available */
  195. bool m_hasGPIO1; /**< TRUE if mat_rx is available */
  196. bool m_hasGPIO2; /**< TRUE if GPIO is available */
  197. bool m_hasIRQN; /**< TRUE if IRQN is available */
  198. u16 m_oscClockFreq;
  199. u16 m_HICfgTimingDiv;
  200. u16 m_HICfgBridgeDelay;
  201. u16 m_HICfgWakeUpKey;
  202. u16 m_HICfgTimeout;
  203. u16 m_HICfgCtrl;
  204. s32 m_sysClockFreq; /**< system clock frequency in kHz */
  205. enum EDrxkState m_DrxkState; /**< State of Drxk (init,stopped,started) */
  206. enum OperationMode m_OperationMode; /**< digital standards */
  207. struct SCfgAgc m_vsbRfAgcCfg; /**< settings for VSB RF-AGC */
  208. struct SCfgAgc m_vsbIfAgcCfg; /**< settings for VSB IF-AGC */
  209. u16 m_vsbPgaCfg; /**< settings for VSB PGA */
  210. struct SCfgPreSaw m_vsbPreSawCfg; /**< settings for pre SAW sense */
  211. s32 m_Quality83percent; /**< MER level (*0.1 dB) for 83% quality indication */
  212. s32 m_Quality93percent; /**< MER level (*0.1 dB) for 93% quality indication */
  213. bool m_smartAntInverted;
  214. bool m_bDebugEnableBridge;
  215. bool m_bPDownOpenBridge; /**< only open DRXK bridge before power-down once it has been accessed */
  216. bool m_bPowerDown; /**< Power down when not used */
  217. u32 m_IqmFsRateOfs; /**< frequency shift as written to DRXK register (28bit fixpoint) */
  218. bool m_enableMPEGOutput; /**< If TRUE, enable MPEG output */
  219. bool m_insertRSByte; /**< If TRUE, insert RS byte */
  220. bool m_enableParallel; /**< If TRUE, parallel out otherwise serial */
  221. bool m_invertDATA; /**< If TRUE, invert DATA signals */
  222. bool m_invertERR; /**< If TRUE, invert ERR signal */
  223. bool m_invertSTR; /**< If TRUE, invert STR signals */
  224. bool m_invertVAL; /**< If TRUE, invert VAL signals */
  225. bool m_invertCLK; /**< If TRUE, invert CLK signals */
  226. bool m_DVBCStaticCLK;
  227. bool m_DVBTStaticCLK; /**< If TRUE, static MPEG clockrate will
  228. be used, otherwise clockrate will
  229. adapt to the bitrate of the TS */
  230. u32 m_DVBTBitrate;
  231. u32 m_DVBCBitrate;
  232. u8 m_TSDataStrength;
  233. u8 m_TSClockkStrength;
  234. bool m_itut_annex_c; /* If true, uses ITU-T DVB-C Annex C, instead of Annex A */
  235. enum DRXMPEGStrWidth_t m_widthSTR; /**< MPEG start width */
  236. u32 m_mpegTsStaticBitrate; /**< Maximum bitrate in b/s in case
  237. static clockrate is selected */
  238. /* LARGE_INTEGER m_StartTime; */ /**< Contains the time of the last demod start */
  239. s32 m_MpegLockTimeOut; /**< WaitForLockStatus Timeout (counts from start time) */
  240. s32 m_DemodLockTimeOut; /**< WaitForLockStatus Timeout (counts from start time) */
  241. bool m_disableTEIhandling;
  242. bool m_RfAgcPol;
  243. bool m_IfAgcPol;
  244. struct SCfgAgc m_atvRfAgcCfg; /**< settings for ATV RF-AGC */
  245. struct SCfgAgc m_atvIfAgcCfg; /**< settings for ATV IF-AGC */
  246. struct SCfgPreSaw m_atvPreSawCfg; /**< settings for ATV pre SAW sense */
  247. bool m_phaseCorrectionBypass;
  248. s16 m_atvTopVidPeak;
  249. u16 m_atvTopNoiseTh;
  250. enum EDrxkSifAttenuation m_sifAttenuation;
  251. bool m_enableCVBSOutput;
  252. bool m_enableSIFOutput;
  253. bool m_bMirrorFreqSpect;
  254. enum EDrxkConstellation m_Constellation; /**< Constellation type of the channel */
  255. u32 m_CurrSymbolRate; /**< Current QAM symbol rate */
  256. struct SCfgAgc m_qamRfAgcCfg; /**< settings for QAM RF-AGC */
  257. struct SCfgAgc m_qamIfAgcCfg; /**< settings for QAM IF-AGC */
  258. u16 m_qamPgaCfg; /**< settings for QAM PGA */
  259. struct SCfgPreSaw m_qamPreSawCfg; /**< settings for QAM pre SAW sense */
  260. enum EDrxkInterleaveMode m_qamInterleaveMode; /**< QAM Interleave mode */
  261. u16 m_fecRsPlen;
  262. u16 m_fecRsPrescale;
  263. enum DRXKCfgDvbtSqiSpeed m_sqiSpeed;
  264. u16 m_GPIO;
  265. u16 m_GPIOCfg;
  266. struct SCfgAgc m_dvbtRfAgcCfg; /**< settings for QAM RF-AGC */
  267. struct SCfgAgc m_dvbtIfAgcCfg; /**< settings for QAM IF-AGC */
  268. struct SCfgPreSaw m_dvbtPreSawCfg; /**< settings for QAM pre SAW sense */
  269. u16 m_agcFastClipCtrlDelay;
  270. bool m_adcCompPassed;
  271. u16 m_adcCompCoef[64];
  272. u16 m_adcState;
  273. u8 *m_microcode;
  274. int m_microcode_length;
  275. bool m_DRXK_A3_ROM_CODE;
  276. bool m_DRXK_A3_PATCH_CODE;
  277. bool m_rfmirror;
  278. u8 m_deviceSpin;
  279. u32 m_iqmRcRate;
  280. enum DRXPowerMode m_currentPowerMode;
  281. /* when true, avoids other devices to use the I2C bus */
  282. bool drxk_i2c_exclusive_lock;
  283. /*
  284. * Configurable parameters at the driver. They stores the values found
  285. * at struct drxk_config.
  286. */
  287. u16 UIO_mask; /* Bits used by UIO */
  288. bool enable_merr_cfg;
  289. bool single_master;
  290. bool no_i2c_bridge;
  291. bool antenna_dvbt;
  292. u16 antenna_gpio;
  293. /* Firmware */
  294. const char *microcode_name;
  295. struct completion fw_wait_load;
  296. const struct firmware *fw;
  297. int qam_demod_parameter_count;
  298. };
  299. #define NEVER_LOCK 0
  300. #define NOT_LOCKED 1
  301. #define DEMOD_LOCK 2
  302. #define FEC_LOCK 3
  303. #define MPEG_LOCK 4