cxd2880_tnrdmd.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * cxd2880_tnrdmd.h
  4. * Sony CXD2880 DVB-T2/T tuner + demodulator driver
  5. * common control interface
  6. *
  7. * Copyright (C) 2016, 2017, 2018 Sony Semiconductor Solutions Corporation
  8. */
  9. #ifndef CXD2880_TNRDMD_H
  10. #define CXD2880_TNRDMD_H
  11. #include <linux/atomic.h>
  12. #include "cxd2880_common.h"
  13. #include "cxd2880_io.h"
  14. #include "cxd2880_dtv.h"
  15. #include "cxd2880_dvbt.h"
  16. #include "cxd2880_dvbt2.h"
  17. #define CXD2880_TNRDMD_MAX_CFG_MEM_COUNT 100
  18. #define slvt_unfreeze_reg(tnr_dmd) ((void)((tnr_dmd)->io->write_reg\
  19. ((tnr_dmd)->io, CXD2880_IO_TGT_DMD, 0x01, 0x00)))
  20. #define CXD2880_TNRDMD_INTERRUPT_TYPE_BUF_UNDERFLOW 0x0001
  21. #define CXD2880_TNRDMD_INTERRUPT_TYPE_BUF_OVERFLOW 0x0002
  22. #define CXD2880_TNRDMD_INTERRUPT_TYPE_BUF_ALMOST_EMPTY 0x0004
  23. #define CXD2880_TNRDMD_INTERRUPT_TYPE_BUF_ALMOST_FULL 0x0008
  24. #define CXD2880_TNRDMD_INTERRUPT_TYPE_BUF_RRDY 0x0010
  25. #define CXD2880_TNRDMD_INTERRUPT_TYPE_ILLEGAL_COMMAND 0x0020
  26. #define CXD2880_TNRDMD_INTERRUPT_TYPE_ILLEGAL_ACCESS 0x0040
  27. #define CXD2880_TNRDMD_INTERRUPT_TYPE_CPU_ERROR 0x0100
  28. #define CXD2880_TNRDMD_INTERRUPT_TYPE_LOCK 0x0200
  29. #define CXD2880_TNRDMD_INTERRUPT_TYPE_INV_LOCK 0x0400
  30. #define CXD2880_TNRDMD_INTERRUPT_TYPE_NOOFDM 0x0800
  31. #define CXD2880_TNRDMD_INTERRUPT_TYPE_EWS 0x1000
  32. #define CXD2880_TNRDMD_INTERRUPT_TYPE_EEW 0x2000
  33. #define CXD2880_TNRDMD_INTERRUPT_TYPE_FEC_FAIL 0x4000
  34. #define CXD2880_TNRDMD_INTERRUPT_LOCK_SEL_L1POST_OK 0x01
  35. #define CXD2880_TNRDMD_INTERRUPT_LOCK_SEL_DMD_LOCK 0x02
  36. #define CXD2880_TNRDMD_INTERRUPT_LOCK_SEL_TS_LOCK 0x04
  37. enum cxd2880_tnrdmd_chip_id {
  38. CXD2880_TNRDMD_CHIP_ID_UNKNOWN = 0x00,
  39. CXD2880_TNRDMD_CHIP_ID_CXD2880_ES1_0X = 0x62,
  40. CXD2880_TNRDMD_CHIP_ID_CXD2880_ES1_11 = 0x6a
  41. };
  42. #define CXD2880_TNRDMD_CHIP_ID_VALID(chip_id) \
  43. (((chip_id) == CXD2880_TNRDMD_CHIP_ID_CXD2880_ES1_0X) || \
  44. ((chip_id) == CXD2880_TNRDMD_CHIP_ID_CXD2880_ES1_11))
  45. enum cxd2880_tnrdmd_state {
  46. CXD2880_TNRDMD_STATE_UNKNOWN,
  47. CXD2880_TNRDMD_STATE_SLEEP,
  48. CXD2880_TNRDMD_STATE_ACTIVE,
  49. CXD2880_TNRDMD_STATE_INVALID
  50. };
  51. enum cxd2880_tnrdmd_divermode {
  52. CXD2880_TNRDMD_DIVERMODE_SINGLE,
  53. CXD2880_TNRDMD_DIVERMODE_MAIN,
  54. CXD2880_TNRDMD_DIVERMODE_SUB
  55. };
  56. enum cxd2880_tnrdmd_clockmode {
  57. CXD2880_TNRDMD_CLOCKMODE_UNKNOWN,
  58. CXD2880_TNRDMD_CLOCKMODE_A,
  59. CXD2880_TNRDMD_CLOCKMODE_B,
  60. CXD2880_TNRDMD_CLOCKMODE_C
  61. };
  62. enum cxd2880_tnrdmd_tsout_if {
  63. CXD2880_TNRDMD_TSOUT_IF_TS,
  64. CXD2880_TNRDMD_TSOUT_IF_SPI,
  65. CXD2880_TNRDMD_TSOUT_IF_SDIO
  66. };
  67. enum cxd2880_tnrdmd_xtal_share {
  68. CXD2880_TNRDMD_XTAL_SHARE_NONE,
  69. CXD2880_TNRDMD_XTAL_SHARE_EXTREF,
  70. CXD2880_TNRDMD_XTAL_SHARE_MASTER,
  71. CXD2880_TNRDMD_XTAL_SHARE_SLAVE
  72. };
  73. enum cxd2880_tnrdmd_spectrum_sense {
  74. CXD2880_TNRDMD_SPECTRUM_NORMAL,
  75. CXD2880_TNRDMD_SPECTRUM_INV
  76. };
  77. enum cxd2880_tnrdmd_cfg_id {
  78. CXD2880_TNRDMD_CFG_OUTPUT_SEL_MSB,
  79. CXD2880_TNRDMD_CFG_TSVALID_ACTIVE_HI,
  80. CXD2880_TNRDMD_CFG_TSSYNC_ACTIVE_HI,
  81. CXD2880_TNRDMD_CFG_TSERR_ACTIVE_HI,
  82. CXD2880_TNRDMD_CFG_LATCH_ON_POSEDGE,
  83. CXD2880_TNRDMD_CFG_TSCLK_CONT,
  84. CXD2880_TNRDMD_CFG_TSCLK_MASK,
  85. CXD2880_TNRDMD_CFG_TSVALID_MASK,
  86. CXD2880_TNRDMD_CFG_TSERR_MASK,
  87. CXD2880_TNRDMD_CFG_TSERR_VALID_DIS,
  88. CXD2880_TNRDMD_CFG_TSPIN_CURRENT,
  89. CXD2880_TNRDMD_CFG_TSPIN_PULLUP_MANUAL,
  90. CXD2880_TNRDMD_CFG_TSPIN_PULLUP,
  91. CXD2880_TNRDMD_CFG_TSCLK_FREQ,
  92. CXD2880_TNRDMD_CFG_TSBYTECLK_MANUAL,
  93. CXD2880_TNRDMD_CFG_TS_PACKET_GAP,
  94. CXD2880_TNRDMD_CFG_TS_BACKWARDS_COMPATIBLE,
  95. CXD2880_TNRDMD_CFG_PWM_VALUE,
  96. CXD2880_TNRDMD_CFG_INTERRUPT,
  97. CXD2880_TNRDMD_CFG_INTERRUPT_LOCK_SEL,
  98. CXD2880_TNRDMD_CFG_INTERRUPT_INV_LOCK_SEL,
  99. CXD2880_TNRDMD_CFG_TS_BUF_ALMOST_EMPTY_THRS,
  100. CXD2880_TNRDMD_CFG_TS_BUF_ALMOST_FULL_THRS,
  101. CXD2880_TNRDMD_CFG_TS_BUF_RRDY_THRS,
  102. CXD2880_TNRDMD_CFG_FIXED_CLOCKMODE,
  103. CXD2880_TNRDMD_CFG_CABLE_INPUT,
  104. CXD2880_TNRDMD_CFG_DVBT2_FEF_INTERMITTENT_BASE,
  105. CXD2880_TNRDMD_CFG_DVBT2_FEF_INTERMITTENT_LITE,
  106. CXD2880_TNRDMD_CFG_BLINDTUNE_DVBT2_FIRST,
  107. CXD2880_TNRDMD_CFG_DVBT_BERN_PERIOD,
  108. CXD2880_TNRDMD_CFG_DVBT_VBER_PERIOD,
  109. CXD2880_TNRDMD_CFG_DVBT_PER_MES,
  110. CXD2880_TNRDMD_CFG_DVBT2_BBER_MES,
  111. CXD2880_TNRDMD_CFG_DVBT2_LBER_MES,
  112. CXD2880_TNRDMD_CFG_DVBT2_PER_MES,
  113. };
  114. enum cxd2880_tnrdmd_lock_result {
  115. CXD2880_TNRDMD_LOCK_RESULT_NOTDETECT,
  116. CXD2880_TNRDMD_LOCK_RESULT_LOCKED,
  117. CXD2880_TNRDMD_LOCK_RESULT_UNLOCKED
  118. };
  119. enum cxd2880_tnrdmd_gpio_mode {
  120. CXD2880_TNRDMD_GPIO_MODE_OUTPUT = 0x00,
  121. CXD2880_TNRDMD_GPIO_MODE_INPUT = 0x01,
  122. CXD2880_TNRDMD_GPIO_MODE_INT = 0x02,
  123. CXD2880_TNRDMD_GPIO_MODE_FEC_FAIL = 0x03,
  124. CXD2880_TNRDMD_GPIO_MODE_PWM = 0x04,
  125. CXD2880_TNRDMD_GPIO_MODE_EWS = 0x05,
  126. CXD2880_TNRDMD_GPIO_MODE_EEW = 0x06
  127. };
  128. enum cxd2880_tnrdmd_serial_ts_clk {
  129. CXD2880_TNRDMD_SERIAL_TS_CLK_FULL,
  130. CXD2880_TNRDMD_SERIAL_TS_CLK_HALF
  131. };
  132. struct cxd2880_tnrdmd_cfg_mem {
  133. enum cxd2880_io_tgt tgt;
  134. u8 bank;
  135. u8 address;
  136. u8 value;
  137. u8 bit_mask;
  138. };
  139. struct cxd2880_tnrdmd_pid_cfg {
  140. u8 is_en;
  141. u16 pid;
  142. };
  143. struct cxd2880_tnrdmd_pid_ftr_cfg {
  144. u8 is_negative;
  145. struct cxd2880_tnrdmd_pid_cfg pid_cfg[32];
  146. };
  147. struct cxd2880_tnrdmd_lna_thrs {
  148. u8 off_on;
  149. u8 on_off;
  150. };
  151. struct cxd2880_tnrdmd_lna_thrs_tbl_air {
  152. struct cxd2880_tnrdmd_lna_thrs thrs[24];
  153. };
  154. struct cxd2880_tnrdmd_lna_thrs_tbl_cable {
  155. struct cxd2880_tnrdmd_lna_thrs thrs[32];
  156. };
  157. struct cxd2880_tnrdmd_create_param {
  158. enum cxd2880_tnrdmd_tsout_if ts_output_if;
  159. u8 en_internal_ldo;
  160. enum cxd2880_tnrdmd_xtal_share xtal_share_type;
  161. u8 xosc_cap;
  162. u8 xosc_i;
  163. u8 is_cxd2881gg;
  164. u8 stationary_use;
  165. };
  166. struct cxd2880_tnrdmd_diver_create_param {
  167. enum cxd2880_tnrdmd_tsout_if ts_output_if;
  168. u8 en_internal_ldo;
  169. u8 xosc_cap_main;
  170. u8 xosc_i_main;
  171. u8 xosc_i_sub;
  172. u8 is_cxd2881gg;
  173. u8 stationary_use;
  174. };
  175. struct cxd2880_tnrdmd {
  176. struct cxd2880_tnrdmd *diver_sub;
  177. struct cxd2880_io *io;
  178. struct cxd2880_tnrdmd_create_param create_param;
  179. enum cxd2880_tnrdmd_divermode diver_mode;
  180. enum cxd2880_tnrdmd_clockmode fixed_clk_mode;
  181. u8 is_cable_input;
  182. u8 en_fef_intmtnt_base;
  183. u8 en_fef_intmtnt_lite;
  184. u8 blind_tune_dvbt2_first;
  185. int (*rf_lvl_cmpstn)(struct cxd2880_tnrdmd *tnr_dmd,
  186. int *rf_lvl_db);
  187. struct cxd2880_tnrdmd_lna_thrs_tbl_air *lna_thrs_tbl_air;
  188. struct cxd2880_tnrdmd_lna_thrs_tbl_cable *lna_thrs_tbl_cable;
  189. u8 srl_ts_clk_mod_cnts;
  190. enum cxd2880_tnrdmd_serial_ts_clk srl_ts_clk_frq;
  191. u8 ts_byte_clk_manual_setting;
  192. u8 is_ts_backwards_compatible_mode;
  193. struct cxd2880_tnrdmd_cfg_mem cfg_mem[CXD2880_TNRDMD_MAX_CFG_MEM_COUNT];
  194. u8 cfg_mem_last_entry;
  195. struct cxd2880_tnrdmd_pid_ftr_cfg pid_ftr_cfg;
  196. u8 pid_ftr_cfg_en;
  197. void *user;
  198. enum cxd2880_tnrdmd_chip_id chip_id;
  199. enum cxd2880_tnrdmd_state state;
  200. enum cxd2880_tnrdmd_clockmode clk_mode;
  201. u32 frequency_khz;
  202. enum cxd2880_dtv_sys sys;
  203. enum cxd2880_dtv_bandwidth bandwidth;
  204. u8 scan_mode;
  205. atomic_t cancel;
  206. };
  207. int cxd2880_tnrdmd_create(struct cxd2880_tnrdmd *tnr_dmd,
  208. struct cxd2880_io *io,
  209. struct cxd2880_tnrdmd_create_param
  210. *create_param);
  211. int cxd2880_tnrdmd_diver_create(struct cxd2880_tnrdmd
  212. *tnr_dmd_main,
  213. struct cxd2880_io *io_main,
  214. struct cxd2880_tnrdmd *tnr_dmd_sub,
  215. struct cxd2880_io *io_sub,
  216. struct
  217. cxd2880_tnrdmd_diver_create_param
  218. *create_param);
  219. int cxd2880_tnrdmd_init1(struct cxd2880_tnrdmd *tnr_dmd);
  220. int cxd2880_tnrdmd_init2(struct cxd2880_tnrdmd *tnr_dmd);
  221. int cxd2880_tnrdmd_check_internal_cpu_status(struct cxd2880_tnrdmd
  222. *tnr_dmd,
  223. u8 *task_completed);
  224. int cxd2880_tnrdmd_common_tune_setting1(struct cxd2880_tnrdmd
  225. *tnr_dmd,
  226. enum cxd2880_dtv_sys sys,
  227. u32 frequency_khz,
  228. enum cxd2880_dtv_bandwidth
  229. bandwidth, u8 one_seg_opt,
  230. u8 one_seg_opt_shft_dir);
  231. int cxd2880_tnrdmd_common_tune_setting2(struct cxd2880_tnrdmd
  232. *tnr_dmd,
  233. enum cxd2880_dtv_sys sys,
  234. u8 en_fef_intmtnt_ctrl);
  235. int cxd2880_tnrdmd_sleep(struct cxd2880_tnrdmd *tnr_dmd);
  236. int cxd2880_tnrdmd_set_cfg(struct cxd2880_tnrdmd *tnr_dmd,
  237. enum cxd2880_tnrdmd_cfg_id id,
  238. int value);
  239. int cxd2880_tnrdmd_gpio_set_cfg(struct cxd2880_tnrdmd *tnr_dmd,
  240. u8 id,
  241. u8 en,
  242. enum cxd2880_tnrdmd_gpio_mode mode,
  243. u8 open_drain, u8 invert);
  244. int cxd2880_tnrdmd_gpio_set_cfg_sub(struct cxd2880_tnrdmd *tnr_dmd,
  245. u8 id,
  246. u8 en,
  247. enum cxd2880_tnrdmd_gpio_mode
  248. mode, u8 open_drain,
  249. u8 invert);
  250. int cxd2880_tnrdmd_gpio_read(struct cxd2880_tnrdmd *tnr_dmd,
  251. u8 id, u8 *value);
  252. int cxd2880_tnrdmd_gpio_read_sub(struct cxd2880_tnrdmd *tnr_dmd,
  253. u8 id, u8 *value);
  254. int cxd2880_tnrdmd_gpio_write(struct cxd2880_tnrdmd *tnr_dmd,
  255. u8 id, u8 value);
  256. int cxd2880_tnrdmd_gpio_write_sub(struct cxd2880_tnrdmd *tnr_dmd,
  257. u8 id, u8 value);
  258. int cxd2880_tnrdmd_interrupt_read(struct cxd2880_tnrdmd *tnr_dmd,
  259. u16 *value);
  260. int cxd2880_tnrdmd_interrupt_clear(struct cxd2880_tnrdmd *tnr_dmd,
  261. u16 value);
  262. int cxd2880_tnrdmd_ts_buf_clear(struct cxd2880_tnrdmd *tnr_dmd,
  263. u8 clear_overflow_flag,
  264. u8 clear_underflow_flag,
  265. u8 clear_buf);
  266. int cxd2880_tnrdmd_chip_id(struct cxd2880_tnrdmd *tnr_dmd,
  267. enum cxd2880_tnrdmd_chip_id *chip_id);
  268. int cxd2880_tnrdmd_set_and_save_reg_bits(struct cxd2880_tnrdmd
  269. *tnr_dmd,
  270. enum cxd2880_io_tgt tgt,
  271. u8 bank, u8 address,
  272. u8 value, u8 bit_mask);
  273. int cxd2880_tnrdmd_set_scan_mode(struct cxd2880_tnrdmd *tnr_dmd,
  274. enum cxd2880_dtv_sys sys,
  275. u8 scan_mode_end);
  276. int cxd2880_tnrdmd_set_pid_ftr(struct cxd2880_tnrdmd *tnr_dmd,
  277. struct cxd2880_tnrdmd_pid_ftr_cfg
  278. *pid_ftr_cfg);
  279. int cxd2880_tnrdmd_set_rf_lvl_cmpstn(struct cxd2880_tnrdmd
  280. *tnr_dmd,
  281. int (*rf_lvl_cmpstn)
  282. (struct cxd2880_tnrdmd *,
  283. int *));
  284. int cxd2880_tnrdmd_set_rf_lvl_cmpstn_sub(struct cxd2880_tnrdmd *tnr_dmd,
  285. int (*rf_lvl_cmpstn)
  286. (struct cxd2880_tnrdmd *,
  287. int *));
  288. int cxd2880_tnrdmd_set_lna_thrs(struct cxd2880_tnrdmd *tnr_dmd,
  289. struct
  290. cxd2880_tnrdmd_lna_thrs_tbl_air
  291. *tbl_air,
  292. struct
  293. cxd2880_tnrdmd_lna_thrs_tbl_cable
  294. *tbl_cable);
  295. int cxd2880_tnrdmd_set_lna_thrs_sub(struct cxd2880_tnrdmd *tnr_dmd,
  296. struct
  297. cxd2880_tnrdmd_lna_thrs_tbl_air
  298. *tbl_air,
  299. struct
  300. cxd2880_tnrdmd_lna_thrs_tbl_cable
  301. *tbl_cable);
  302. int cxd2880_tnrdmd_set_ts_pin_high_low(struct cxd2880_tnrdmd
  303. *tnr_dmd, u8 en, u8 value);
  304. int cxd2880_tnrdmd_set_ts_output(struct cxd2880_tnrdmd *tnr_dmd,
  305. u8 en);
  306. int slvt_freeze_reg(struct cxd2880_tnrdmd *tnr_dmd);
  307. #endif