rtl2832_priv.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429
  1. /*
  2. * Realtek RTL2832 DVB-T demodulator driver
  3. *
  4. * Copyright (C) 2012 Thomas Mair <thomas.mair86@gmail.com>
  5. * Copyright (C) 2012-2014 Antti Palosaari <crope@iki.fi>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License along
  18. * with this program; if not, write to the Free Software Foundation, Inc.,
  19. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  20. */
  21. #ifndef RTL2832_PRIV_H
  22. #define RTL2832_PRIV_H
  23. #include <linux/regmap.h>
  24. #include <linux/math64.h>
  25. #include <linux/bitops.h>
  26. #include "dvb_frontend.h"
  27. #include "dvb_math.h"
  28. #include "rtl2832.h"
  29. struct rtl2832_dev {
  30. struct rtl2832_platform_data *pdata;
  31. struct i2c_client *client;
  32. struct mutex regmap_mutex;
  33. struct regmap_config regmap_config;
  34. struct regmap *regmap;
  35. struct i2c_adapter *i2c_adapter_tuner;
  36. struct dvb_frontend fe;
  37. struct delayed_work stat_work;
  38. enum fe_status fe_status;
  39. u64 post_bit_error_prev; /* for old DVBv3 read_ber() calculation */
  40. u64 post_bit_error;
  41. u64 post_bit_count;
  42. bool sleeping;
  43. struct delayed_work i2c_gate_work;
  44. unsigned long filters; /* PID filter */
  45. };
  46. struct rtl2832_reg_entry {
  47. u16 start_address;
  48. u8 msb;
  49. u8 lsb;
  50. };
  51. struct rtl2832_reg_value {
  52. int reg;
  53. u32 value;
  54. };
  55. /* Demod register bit names */
  56. enum DVBT_REG_BIT_NAME {
  57. DVBT_SOFT_RST,
  58. DVBT_IIC_REPEAT,
  59. DVBT_TR_WAIT_MIN_8K,
  60. DVBT_RSD_BER_FAIL_VAL,
  61. DVBT_EN_BK_TRK,
  62. DVBT_REG_PI,
  63. DVBT_REG_PFREQ_1_0,
  64. DVBT_PD_DA8,
  65. DVBT_LOCK_TH,
  66. DVBT_BER_PASS_SCAL,
  67. DVBT_CE_FFSM_BYPASS,
  68. DVBT_ALPHAIIR_N,
  69. DVBT_ALPHAIIR_DIF,
  70. DVBT_EN_TRK_SPAN,
  71. DVBT_LOCK_TH_LEN,
  72. DVBT_CCI_THRE,
  73. DVBT_CCI_MON_SCAL,
  74. DVBT_CCI_M0,
  75. DVBT_CCI_M1,
  76. DVBT_CCI_M2,
  77. DVBT_CCI_M3,
  78. DVBT_SPEC_INIT_0,
  79. DVBT_SPEC_INIT_1,
  80. DVBT_SPEC_INIT_2,
  81. DVBT_AD_EN_REG,
  82. DVBT_AD_EN_REG1,
  83. DVBT_EN_BBIN,
  84. DVBT_MGD_THD0,
  85. DVBT_MGD_THD1,
  86. DVBT_MGD_THD2,
  87. DVBT_MGD_THD3,
  88. DVBT_MGD_THD4,
  89. DVBT_MGD_THD5,
  90. DVBT_MGD_THD6,
  91. DVBT_MGD_THD7,
  92. DVBT_EN_CACQ_NOTCH,
  93. DVBT_AD_AV_REF,
  94. DVBT_PIP_ON,
  95. DVBT_SCALE1_B92,
  96. DVBT_SCALE1_B93,
  97. DVBT_SCALE1_BA7,
  98. DVBT_SCALE1_BA9,
  99. DVBT_SCALE1_BAA,
  100. DVBT_SCALE1_BAB,
  101. DVBT_SCALE1_BAC,
  102. DVBT_SCALE1_BB0,
  103. DVBT_SCALE1_BB1,
  104. DVBT_KB_P1,
  105. DVBT_KB_P2,
  106. DVBT_KB_P3,
  107. DVBT_OPT_ADC_IQ,
  108. DVBT_AD_AVI,
  109. DVBT_AD_AVQ,
  110. DVBT_K1_CR_STEP12,
  111. DVBT_TRK_KS_P2,
  112. DVBT_TRK_KS_I2,
  113. DVBT_TR_THD_SET2,
  114. DVBT_TRK_KC_P2,
  115. DVBT_TRK_KC_I2,
  116. DVBT_CR_THD_SET2,
  117. DVBT_PSET_IFFREQ,
  118. DVBT_SPEC_INV,
  119. DVBT_BW_INDEX,
  120. DVBT_RSAMP_RATIO,
  121. DVBT_CFREQ_OFF_RATIO,
  122. DVBT_FSM_STAGE,
  123. DVBT_RX_CONSTEL,
  124. DVBT_RX_HIER,
  125. DVBT_RX_C_RATE_LP,
  126. DVBT_RX_C_RATE_HP,
  127. DVBT_GI_IDX,
  128. DVBT_FFT_MODE_IDX,
  129. DVBT_RSD_BER_EST,
  130. DVBT_CE_EST_EVM,
  131. DVBT_RF_AGC_VAL,
  132. DVBT_IF_AGC_VAL,
  133. DVBT_DAGC_VAL,
  134. DVBT_SFREQ_OFF,
  135. DVBT_CFREQ_OFF,
  136. DVBT_POLAR_RF_AGC,
  137. DVBT_POLAR_IF_AGC,
  138. DVBT_AAGC_HOLD,
  139. DVBT_EN_RF_AGC,
  140. DVBT_EN_IF_AGC,
  141. DVBT_IF_AGC_MIN,
  142. DVBT_IF_AGC_MAX,
  143. DVBT_RF_AGC_MIN,
  144. DVBT_RF_AGC_MAX,
  145. DVBT_IF_AGC_MAN,
  146. DVBT_IF_AGC_MAN_VAL,
  147. DVBT_RF_AGC_MAN,
  148. DVBT_RF_AGC_MAN_VAL,
  149. DVBT_DAGC_TRG_VAL,
  150. DVBT_AGC_TARG_VAL,
  151. DVBT_LOOP_GAIN_3_0,
  152. DVBT_LOOP_GAIN_4,
  153. DVBT_VTOP,
  154. DVBT_KRF,
  155. DVBT_AGC_TARG_VAL_0,
  156. DVBT_AGC_TARG_VAL_8_1,
  157. DVBT_AAGC_LOOP_GAIN,
  158. DVBT_LOOP_GAIN2_3_0,
  159. DVBT_LOOP_GAIN2_4,
  160. DVBT_LOOP_GAIN3,
  161. DVBT_VTOP1,
  162. DVBT_VTOP2,
  163. DVBT_VTOP3,
  164. DVBT_KRF1,
  165. DVBT_KRF2,
  166. DVBT_KRF3,
  167. DVBT_KRF4,
  168. DVBT_EN_GI_PGA,
  169. DVBT_THD_LOCK_UP,
  170. DVBT_THD_LOCK_DW,
  171. DVBT_THD_UP1,
  172. DVBT_THD_DW1,
  173. DVBT_INTER_CNT_LEN,
  174. DVBT_GI_PGA_STATE,
  175. DVBT_EN_AGC_PGA,
  176. DVBT_CKOUTPAR,
  177. DVBT_CKOUT_PWR,
  178. DVBT_SYNC_DUR,
  179. DVBT_ERR_DUR,
  180. DVBT_SYNC_LVL,
  181. DVBT_ERR_LVL,
  182. DVBT_VAL_LVL,
  183. DVBT_SERIAL,
  184. DVBT_SER_LSB,
  185. DVBT_CDIV_PH0,
  186. DVBT_CDIV_PH1,
  187. DVBT_MPEG_IO_OPT_2_2,
  188. DVBT_MPEG_IO_OPT_1_0,
  189. DVBT_CKOUTPAR_PIP,
  190. DVBT_CKOUT_PWR_PIP,
  191. DVBT_SYNC_LVL_PIP,
  192. DVBT_ERR_LVL_PIP,
  193. DVBT_VAL_LVL_PIP,
  194. DVBT_CKOUTPAR_PID,
  195. DVBT_CKOUT_PWR_PID,
  196. DVBT_SYNC_LVL_PID,
  197. DVBT_ERR_LVL_PID,
  198. DVBT_VAL_LVL_PID,
  199. DVBT_SM_PASS,
  200. DVBT_UPDATE_REG_2,
  201. DVBT_BTHD_P3,
  202. DVBT_BTHD_D3,
  203. DVBT_FUNC4_REG0,
  204. DVBT_FUNC4_REG1,
  205. DVBT_FUNC4_REG2,
  206. DVBT_FUNC4_REG3,
  207. DVBT_FUNC4_REG4,
  208. DVBT_FUNC4_REG5,
  209. DVBT_FUNC4_REG6,
  210. DVBT_FUNC4_REG7,
  211. DVBT_FUNC4_REG8,
  212. DVBT_FUNC4_REG9,
  213. DVBT_FUNC4_REG10,
  214. DVBT_FUNC5_REG0,
  215. DVBT_FUNC5_REG1,
  216. DVBT_FUNC5_REG2,
  217. DVBT_FUNC5_REG3,
  218. DVBT_FUNC5_REG4,
  219. DVBT_FUNC5_REG5,
  220. DVBT_FUNC5_REG6,
  221. DVBT_FUNC5_REG7,
  222. DVBT_FUNC5_REG8,
  223. DVBT_FUNC5_REG9,
  224. DVBT_FUNC5_REG10,
  225. DVBT_FUNC5_REG11,
  226. DVBT_FUNC5_REG12,
  227. DVBT_FUNC5_REG13,
  228. DVBT_FUNC5_REG14,
  229. DVBT_FUNC5_REG15,
  230. DVBT_FUNC5_REG16,
  231. DVBT_FUNC5_REG17,
  232. DVBT_FUNC5_REG18,
  233. DVBT_AD7_SETTING,
  234. DVBT_RSSI_R,
  235. DVBT_ACI_DET_IND,
  236. DVBT_REG_MON,
  237. DVBT_REG_MONSEL,
  238. DVBT_REG_GPE,
  239. DVBT_REG_GPO,
  240. DVBT_REG_4MSEL,
  241. DVBT_TEST_REG_1,
  242. DVBT_TEST_REG_2,
  243. DVBT_TEST_REG_3,
  244. DVBT_TEST_REG_4,
  245. DVBT_REG_BIT_NAME_ITEM_TERMINATOR,
  246. };
  247. static const struct rtl2832_reg_value rtl2832_tuner_init_fc2580[] = {
  248. {DVBT_DAGC_TRG_VAL, 0x39},
  249. {DVBT_AGC_TARG_VAL_0, 0x0},
  250. {DVBT_AGC_TARG_VAL_8_1, 0x5a},
  251. {DVBT_AAGC_LOOP_GAIN, 0x16},
  252. {DVBT_LOOP_GAIN2_3_0, 0x6},
  253. {DVBT_LOOP_GAIN2_4, 0x1},
  254. {DVBT_LOOP_GAIN3, 0x16},
  255. {DVBT_VTOP1, 0x35},
  256. {DVBT_VTOP2, 0x21},
  257. {DVBT_VTOP3, 0x21},
  258. {DVBT_KRF1, 0x0},
  259. {DVBT_KRF2, 0x40},
  260. {DVBT_KRF3, 0x10},
  261. {DVBT_KRF4, 0x10},
  262. {DVBT_IF_AGC_MIN, 0x80},
  263. {DVBT_IF_AGC_MAX, 0x7f},
  264. {DVBT_RF_AGC_MIN, 0x9c},
  265. {DVBT_RF_AGC_MAX, 0x7f},
  266. {DVBT_POLAR_RF_AGC, 0x0},
  267. {DVBT_POLAR_IF_AGC, 0x0},
  268. {DVBT_AD7_SETTING, 0xe9f4},
  269. };
  270. static const struct rtl2832_reg_value rtl2832_tuner_init_tua9001[] = {
  271. {DVBT_DAGC_TRG_VAL, 0x39},
  272. {DVBT_AGC_TARG_VAL_0, 0x0},
  273. {DVBT_AGC_TARG_VAL_8_1, 0x5a},
  274. {DVBT_AAGC_LOOP_GAIN, 0x16},
  275. {DVBT_LOOP_GAIN2_3_0, 0x6},
  276. {DVBT_LOOP_GAIN2_4, 0x1},
  277. {DVBT_LOOP_GAIN3, 0x16},
  278. {DVBT_VTOP1, 0x35},
  279. {DVBT_VTOP2, 0x21},
  280. {DVBT_VTOP3, 0x21},
  281. {DVBT_KRF1, 0x0},
  282. {DVBT_KRF2, 0x40},
  283. {DVBT_KRF3, 0x10},
  284. {DVBT_KRF4, 0x10},
  285. {DVBT_IF_AGC_MIN, 0x80},
  286. {DVBT_IF_AGC_MAX, 0x7f},
  287. {DVBT_RF_AGC_MIN, 0x9c},
  288. {DVBT_RF_AGC_MAX, 0x7f},
  289. {DVBT_POLAR_RF_AGC, 0x0},
  290. {DVBT_POLAR_IF_AGC, 0x0},
  291. {DVBT_AD7_SETTING, 0xe9f4},
  292. {DVBT_OPT_ADC_IQ, 0x1},
  293. {DVBT_AD_AVI, 0x0},
  294. {DVBT_AD_AVQ, 0x0},
  295. {DVBT_SPEC_INV, 0x0},
  296. };
  297. static const struct rtl2832_reg_value rtl2832_tuner_init_fc0012[] = {
  298. {DVBT_DAGC_TRG_VAL, 0x5a},
  299. {DVBT_AGC_TARG_VAL_0, 0x0},
  300. {DVBT_AGC_TARG_VAL_8_1, 0x5a},
  301. {DVBT_AAGC_LOOP_GAIN, 0x16},
  302. {DVBT_LOOP_GAIN2_3_0, 0x6},
  303. {DVBT_LOOP_GAIN2_4, 0x1},
  304. {DVBT_LOOP_GAIN3, 0x16},
  305. {DVBT_VTOP1, 0x35},
  306. {DVBT_VTOP2, 0x21},
  307. {DVBT_VTOP3, 0x21},
  308. {DVBT_KRF1, 0x0},
  309. {DVBT_KRF2, 0x40},
  310. {DVBT_KRF3, 0x10},
  311. {DVBT_KRF4, 0x10},
  312. {DVBT_IF_AGC_MIN, 0x80},
  313. {DVBT_IF_AGC_MAX, 0x7f},
  314. {DVBT_RF_AGC_MIN, 0x80},
  315. {DVBT_RF_AGC_MAX, 0x7f},
  316. {DVBT_POLAR_RF_AGC, 0x0},
  317. {DVBT_POLAR_IF_AGC, 0x0},
  318. {DVBT_AD7_SETTING, 0xe9bf},
  319. {DVBT_EN_GI_PGA, 0x0},
  320. {DVBT_THD_LOCK_UP, 0x0},
  321. {DVBT_THD_LOCK_DW, 0x0},
  322. {DVBT_THD_UP1, 0x11},
  323. {DVBT_THD_DW1, 0xef},
  324. {DVBT_INTER_CNT_LEN, 0xc},
  325. {DVBT_GI_PGA_STATE, 0x0},
  326. {DVBT_EN_AGC_PGA, 0x1},
  327. {DVBT_IF_AGC_MAN, 0x0},
  328. {DVBT_SPEC_INV, 0x0},
  329. };
  330. static const struct rtl2832_reg_value rtl2832_tuner_init_e4000[] = {
  331. {DVBT_DAGC_TRG_VAL, 0x5a},
  332. {DVBT_AGC_TARG_VAL_0, 0x0},
  333. {DVBT_AGC_TARG_VAL_8_1, 0x5a},
  334. {DVBT_AAGC_LOOP_GAIN, 0x18},
  335. {DVBT_LOOP_GAIN2_3_0, 0x8},
  336. {DVBT_LOOP_GAIN2_4, 0x1},
  337. {DVBT_LOOP_GAIN3, 0x18},
  338. {DVBT_VTOP1, 0x35},
  339. {DVBT_VTOP2, 0x21},
  340. {DVBT_VTOP3, 0x21},
  341. {DVBT_KRF1, 0x0},
  342. {DVBT_KRF2, 0x40},
  343. {DVBT_KRF3, 0x10},
  344. {DVBT_KRF4, 0x10},
  345. {DVBT_IF_AGC_MIN, 0x80},
  346. {DVBT_IF_AGC_MAX, 0x7f},
  347. {DVBT_RF_AGC_MIN, 0x80},
  348. {DVBT_RF_AGC_MAX, 0x7f},
  349. {DVBT_POLAR_RF_AGC, 0x0},
  350. {DVBT_POLAR_IF_AGC, 0x0},
  351. {DVBT_AD7_SETTING, 0xe9d4},
  352. {DVBT_EN_GI_PGA, 0x0},
  353. {DVBT_THD_LOCK_UP, 0x0},
  354. {DVBT_THD_LOCK_DW, 0x0},
  355. {DVBT_THD_UP1, 0x14},
  356. {DVBT_THD_DW1, 0xec},
  357. {DVBT_INTER_CNT_LEN, 0xc},
  358. {DVBT_GI_PGA_STATE, 0x0},
  359. {DVBT_EN_AGC_PGA, 0x1},
  360. {DVBT_REG_GPE, 0x1},
  361. {DVBT_REG_GPO, 0x1},
  362. {DVBT_REG_MONSEL, 0x1},
  363. {DVBT_REG_MON, 0x1},
  364. {DVBT_REG_4MSEL, 0x0},
  365. {DVBT_SPEC_INV, 0x0},
  366. };
  367. static const struct rtl2832_reg_value rtl2832_tuner_init_r820t[] = {
  368. {DVBT_DAGC_TRG_VAL, 0x39},
  369. {DVBT_AGC_TARG_VAL_0, 0x0},
  370. {DVBT_AGC_TARG_VAL_8_1, 0x40},
  371. {DVBT_AAGC_LOOP_GAIN, 0x16},
  372. {DVBT_LOOP_GAIN2_3_0, 0x8},
  373. {DVBT_LOOP_GAIN2_4, 0x1},
  374. {DVBT_LOOP_GAIN3, 0x18},
  375. {DVBT_VTOP1, 0x35},
  376. {DVBT_VTOP2, 0x21},
  377. {DVBT_VTOP3, 0x21},
  378. {DVBT_KRF1, 0x0},
  379. {DVBT_KRF2, 0x40},
  380. {DVBT_KRF3, 0x10},
  381. {DVBT_KRF4, 0x10},
  382. {DVBT_IF_AGC_MIN, 0x80},
  383. {DVBT_IF_AGC_MAX, 0x7f},
  384. {DVBT_RF_AGC_MIN, 0x80},
  385. {DVBT_RF_AGC_MAX, 0x7f},
  386. {DVBT_POLAR_RF_AGC, 0x0},
  387. {DVBT_POLAR_IF_AGC, 0x0},
  388. {DVBT_AD7_SETTING, 0xe9f4},
  389. {DVBT_SPEC_INV, 0x1},
  390. };
  391. static const struct rtl2832_reg_value rtl2832_tuner_init_si2157[] = {
  392. {DVBT_DAGC_TRG_VAL, 0x39},
  393. {DVBT_AGC_TARG_VAL_0, 0x0},
  394. {DVBT_AGC_TARG_VAL_8_1, 0x40},
  395. {DVBT_AAGC_LOOP_GAIN, 0x16},
  396. {DVBT_LOOP_GAIN2_3_0, 0x8},
  397. {DVBT_LOOP_GAIN2_4, 0x1},
  398. {DVBT_LOOP_GAIN3, 0x18},
  399. {DVBT_VTOP1, 0x35},
  400. {DVBT_VTOP2, 0x21},
  401. {DVBT_VTOP3, 0x21},
  402. {DVBT_KRF1, 0x0},
  403. {DVBT_KRF2, 0x40},
  404. {DVBT_KRF3, 0x10},
  405. {DVBT_KRF4, 0x10},
  406. {DVBT_IF_AGC_MIN, 0x80},
  407. {DVBT_IF_AGC_MAX, 0x7f},
  408. {DVBT_RF_AGC_MIN, 0x80},
  409. {DVBT_RF_AGC_MAX, 0x7f},
  410. {DVBT_POLAR_RF_AGC, 0x0},
  411. {DVBT_POLAR_IF_AGC, 0x0},
  412. {DVBT_AD7_SETTING, 0xe9f4},
  413. {DVBT_SPEC_INV, 0x0},
  414. };
  415. #endif /* RTL2832_PRIV_H */