summaryrefslogtreecommitdiffstats
path: root/drivers/media/dvb-frontends/cxd2880/cxd2880_tnrdmd.h
blob: 9d809a251fc76701d8b47bb4b50928fd8beab43a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
/* SPDX-License-Identifier: GPL-2.0 */
/*
 * cxd2880_tnrdmd.h
 * Sony CXD2880 DVB-T2/T tuner + demodulator driver
 * common control interface
 *
 * Copyright (C) 2016, 2017, 2018 Sony Semiconductor Solutions Corporation
 */

#ifndef CXD2880_TNRDMD_H
#define CXD2880_TNRDMD_H

#include <linux/atomic.h>

#include "cxd2880_common.h"
#include "cxd2880_io.h"
#include "cxd2880_dtv.h"
#include "cxd2880_dvbt.h"
#include "cxd2880_dvbt2.h"

#define CXD2880_TNRDMD_MAX_CFG_MEM_COUNT 100

#define slvt_unfreeze_reg(tnr_dmd) ((void)((tnr_dmd)->io->write_reg\
((tnr_dmd)->io, CXD2880_IO_TGT_DMD, 0x01, 0x00)))

#define CXD2880_TNRDMD_INTERRUPT_TYPE_BUF_UNDERFLOW     0x0001
#define CXD2880_TNRDMD_INTERRUPT_TYPE_BUF_OVERFLOW      0x0002
#define CXD2880_TNRDMD_INTERRUPT_TYPE_BUF_ALMOST_EMPTY  0x0004
#define CXD2880_TNRDMD_INTERRUPT_TYPE_BUF_ALMOST_FULL   0x0008
#define CXD2880_TNRDMD_INTERRUPT_TYPE_BUF_RRDY	  0x0010
#define CXD2880_TNRDMD_INTERRUPT_TYPE_ILLEGAL_COMMAND      0x0020
#define CXD2880_TNRDMD_INTERRUPT_TYPE_ILLEGAL_ACCESS       0x0040
#define CXD2880_TNRDMD_INTERRUPT_TYPE_CPU_ERROR	    0x0100
#define CXD2880_TNRDMD_INTERRUPT_TYPE_LOCK		 0x0200
#define CXD2880_TNRDMD_INTERRUPT_TYPE_INV_LOCK	     0x0400
#define CXD2880_TNRDMD_INTERRUPT_TYPE_NOOFDM	       0x0800
#define CXD2880_TNRDMD_INTERRUPT_TYPE_EWS		  0x1000
#define CXD2880_TNRDMD_INTERRUPT_TYPE_EEW		  0x2000
#define CXD2880_TNRDMD_INTERRUPT_TYPE_FEC_FAIL	     0x4000

#define CXD2880_TNRDMD_INTERRUPT_LOCK_SEL_L1POST_OK	0x01
#define CXD2880_TNRDMD_INTERRUPT_LOCK_SEL_DMD_LOCK	 0x02
#define CXD2880_TNRDMD_INTERRUPT_LOCK_SEL_TS_LOCK	  0x04

enum cxd2880_tnrdmd_chip_id {
	CXD2880_TNRDMD_CHIP_ID_UNKNOWN = 0x00,
	CXD2880_TNRDMD_CHIP_ID_CXD2880_ES1_0X = 0x62,
	CXD2880_TNRDMD_CHIP_ID_CXD2880_ES1_11 = 0x6a
};

#define CXD2880_TNRDMD_CHIP_ID_VALID(chip_id) \
	(((chip_id) == CXD2880_TNRDMD_CHIP_ID_CXD2880_ES1_0X) || \
	 ((chip_id) == CXD2880_TNRDMD_CHIP_ID_CXD2880_ES1_11))

enum cxd2880_tnrdmd_state {
	CXD2880_TNRDMD_STATE_UNKNOWN,
	CXD2880_TNRDMD_STATE_SLEEP,
	CXD2880_TNRDMD_STATE_ACTIVE,
	CXD2880_TNRDMD_STATE_INVALID
};

enum cxd2880_tnrdmd_divermode {
	CXD2880_TNRDMD_DIVERMODE_SINGLE,
	CXD2880_TNRDMD_DIVERMODE_MAIN,
	CXD2880_TNRDMD_DIVERMODE_SUB
};

enum cxd2880_tnrdmd_clockmode {
	CXD2880_TNRDMD_CLOCKMODE_UNKNOWN,
	CXD2880_TNRDMD_CLOCKMODE_A,
	CXD2880_TNRDMD_CLOCKMODE_B,
	CXD2880_TNRDMD_CLOCKMODE_C
};

enum cxd2880_tnrdmd_tsout_if {
	CXD2880_TNRDMD_TSOUT_IF_TS,
	CXD2880_TNRDMD_TSOUT_IF_SPI,
	CXD2880_TNRDMD_TSOUT_IF_SDIO
};

enum cxd2880_tnrdmd_xtal_share {
	CXD2880_TNRDMD_XTAL_SHARE_NONE,
	CXD2880_TNRDMD_XTAL_SHARE_EXTREF,
	CXD2880_TNRDMD_XTAL_SHARE_MASTER,
	CXD2880_TNRDMD_XTAL_SHARE_SLAVE
};

enum cxd2880_tnrdmd_spectrum_sense {
	CXD2880_TNRDMD_SPECTRUM_NORMAL,
	CXD2880_TNRDMD_SPECTRUM_INV
};

enum cxd2880_tnrdmd_cfg_id {
	CXD2880_TNRDMD_CFG_OUTPUT_SEL_MSB,
	CXD2880_TNRDMD_CFG_TSVALID_ACTIVE_HI,
	CXD2880_TNRDMD_CFG_TSSYNC_ACTIVE_HI,
	CXD2880_TNRDMD_CFG_TSERR_ACTIVE_HI,
	CXD2880_TNRDMD_CFG_LATCH_ON_POSEDGE,
	CXD2880_TNRDMD_CFG_TSCLK_CONT,
	CXD2880_TNRDMD_CFG_TSCLK_MASK,
	CXD2880_TNRDMD_CFG_TSVALID_MASK,
	CXD2880_TNRDMD_CFG_TSERR_MASK,
	CXD2880_TNRDMD_CFG_TSERR_VALID_DIS,
	CXD2880_TNRDMD_CFG_TSPIN_CURRENT,
	CXD2880_TNRDMD_CFG_TSPIN_PULLUP_MANUAL,
	CXD2880_TNRDMD_CFG_TSPIN_PULLUP,
	CXD2880_TNRDMD_CFG_TSCLK_FREQ,
	CXD2880_TNRDMD_CFG_TSBYTECLK_MANUAL,
	CXD2880_TNRDMD_CFG_TS_PACKET_GAP,
	CXD2880_TNRDMD_CFG_TS_BACKWARDS_COMPATIBLE,
	CXD2880_TNRDMD_CFG_PWM_VALUE,
	CXD2880_TNRDMD_CFG_INTERRUPT,
	CXD2880_TNRDMD_CFG_INTERRUPT_LOCK_SEL,
	CXD2880_TNRDMD_CFG_INTERRUPT_INV_LOCK_SEL,
	CXD2880_TNRDMD_CFG_TS_BUF_ALMOST_EMPTY_THRS,
	CXD2880_TNRDMD_CFG_TS_BUF_ALMOST_FULL_THRS,
	CXD2880_TNRDMD_CFG_TS_BUF_RRDY_THRS,
	CXD2880_TNRDMD_CFG_FIXED_CLOCKMODE,
	CXD2880_TNRDMD_CFG_CABLE_INPUT,
	CXD2880_TNRDMD_CFG_DVBT2_FEF_INTERMITTENT_BASE,
	CXD2880_TNRDMD_CFG_DVBT2_FEF_INTERMITTENT_LITE,
	CXD2880_TNRDMD_CFG_BLINDTUNE_DVBT2_FIRST,
	CXD2880_TNRDMD_CFG_DVBT_BERN_PERIOD,
	CXD2880_TNRDMD_CFG_DVBT_VBER_PERIOD,
	CXD2880_TNRDMD_CFG_DVBT_PER_MES,
	CXD2880_TNRDMD_CFG_DVBT2_BBER_MES,
	CXD2880_TNRDMD_CFG_DVBT2_LBER_MES,
	CXD2880_TNRDMD_CFG_DVBT2_PER_MES,
};

enum cxd2880_tnrdmd_lock_result {
	CXD2880_TNRDMD_LOCK_RESULT_NOTDETECT,
	CXD2880_TNRDMD_LOCK_RESULT_LOCKED,
	CXD2880_TNRDMD_LOCK_RESULT_UNLOCKED
};

enum cxd2880_tnrdmd_gpio_mode {
	CXD2880_TNRDMD_GPIO_MODE_OUTPUT = 0x00,
	CXD2880_TNRDMD_GPIO_MODE_INPUT = 0x01,
	CXD2880_TNRDMD_GPIO_MODE_INT = 0x02,
	CXD2880_TNRDMD_GPIO_MODE_FEC_FAIL = 0x03,
	CXD2880_TNRDMD_GPIO_MODE_PWM = 0x04,
	CXD2880_TNRDMD_GPIO_MODE_EWS = 0x05,
	CXD2880_TNRDMD_GPIO_MODE_EEW = 0x06
};

enum cxd2880_tnrdmd_serial_ts_clk {
	CXD2880_TNRDMD_SERIAL_TS_CLK_FULL,
	CXD2880_TNRDMD_SERIAL_TS_CLK_HALF
};

struct cxd2880_tnrdmd_cfg_mem {
	enum cxd2880_io_tgt tgt;
	u8 bank;
	u8 address;
	u8 value;
	u8 bit_mask;
};

struct cxd2880_tnrdmd_pid_cfg {
	u8 is_en;
	u16 pid;
};

struct cxd2880_tnrdmd_pid_ftr_cfg {
	u8 is_negative;
	struct cxd2880_tnrdmd_pid_cfg pid_cfg[32];
};

struct cxd2880_tnrdmd_lna_thrs {
	u8 off_on;
	u8 on_off;
};

struct cxd2880_tnrdmd_lna_thrs_tbl_air {
	struct cxd2880_tnrdmd_lna_thrs thrs[24];
};

struct cxd2880_tnrdmd_lna_thrs_tbl_cable {
	struct cxd2880_tnrdmd_lna_thrs thrs[32];
};

struct cxd2880_tnrdmd_create_param {
	enum cxd2880_tnrdmd_tsout_if ts_output_if;
	u8 en_internal_ldo;
	enum cxd2880_tnrdmd_xtal_share xtal_share_type;
	u8 xosc_cap;
	u8 xosc_i;
	u8 is_cxd2881gg;
	u8 stationary_use;
};

struct cxd2880_tnrdmd_diver_create_param {
	enum cxd2880_tnrdmd_tsout_if ts_output_if;
	u8 en_internal_ldo;
	u8 xosc_cap_main;
	u8 xosc_i_main;
	u8 xosc_i_sub;
	u8 is_cxd2881gg;
	u8 stationary_use;
};

struct cxd2880_tnrdmd {
	struct cxd2880_tnrdmd *diver_sub;
	struct cxd2880_io *io;
	struct cxd2880_tnrdmd_create_param create_param;
	enum cxd2880_tnrdmd_divermode diver_mode;
	enum cxd2880_tnrdmd_clockmode fixed_clk_mode;
	u8 is_cable_input;
	u8 en_fef_intmtnt_base;
	u8 en_fef_intmtnt_lite;
	u8 blind_tune_dvbt2_first;
	int (*rf_lvl_cmpstn)(struct cxd2880_tnrdmd *tnr_dmd,
			     int *rf_lvl_db);
	struct cxd2880_tnrdmd_lna_thrs_tbl_air *lna_thrs_tbl_air;
	struct cxd2880_tnrdmd_lna_thrs_tbl_cable *lna_thrs_tbl_cable;
	u8 srl_ts_clk_mod_cnts;
	enum cxd2880_tnrdmd_serial_ts_clk srl_ts_clk_frq;
	u8 ts_byte_clk_manual_setting;
	u8 is_ts_backwards_compatible_mode;
	struct cxd2880_tnrdmd_cfg_mem cfg_mem[CXD2880_TNRDMD_MAX_CFG_MEM_COUNT];
	u8 cfg_mem_last_entry;
	struct cxd2880_tnrdmd_pid_ftr_cfg pid_ftr_cfg;
	u8 pid_ftr_cfg_en;
	void *user;
	enum cxd2880_tnrdmd_chip_id chip_id;
	enum cxd2880_tnrdmd_state state;
	enum cxd2880_tnrdmd_clockmode clk_mode;
	u32 frequency_khz;
	enum cxd2880_dtv_sys sys;
	enum cxd2880_dtv_bandwidth bandwidth;
	u8 scan_mode;
	atomic_t cancel;
};

int cxd2880_tnrdmd_create(struct cxd2880_tnrdmd *tnr_dmd,
			  struct cxd2880_io *io,
			  struct cxd2880_tnrdmd_create_param
			  *create_param);

int cxd2880_tnrdmd_diver_create(struct cxd2880_tnrdmd
				*tnr_dmd_main,
				struct cxd2880_io *io_main,
				struct cxd2880_tnrdmd *tnr_dmd_sub,
				struct cxd2880_io *io_sub,
				struct
				cxd2880_tnrdmd_diver_create_param
				*create_param);

int cxd2880_tnrdmd_init1(struct cxd2880_tnrdmd *tnr_dmd);

int cxd2880_tnrdmd_init2(struct cxd2880_tnrdmd *tnr_dmd);

int cxd2880_tnrdmd_check_internal_cpu_status(struct cxd2880_tnrdmd
					     *tnr_dmd,
					     u8 *task_completed);

int cxd2880_tnrdmd_common_tune_setting1(struct cxd2880_tnrdmd
					*tnr_dmd,
					enum cxd2880_dtv_sys sys,
					u32 frequency_khz,
					enum cxd2880_dtv_bandwidth
					bandwidth, u8 one_seg_opt,
					u8 one_seg_opt_shft_dir);

int cxd2880_tnrdmd_common_tune_setting2(struct cxd2880_tnrdmd
					*tnr_dmd,
					enum cxd2880_dtv_sys sys,
					u8 en_fef_intmtnt_ctrl);

int cxd2880_tnrdmd_sleep(struct cxd2880_tnrdmd *tnr_dmd);

int cxd2880_tnrdmd_set_cfg(struct cxd2880_tnrdmd *tnr_dmd,
			   enum cxd2880_tnrdmd_cfg_id id,
			   int value);

int cxd2880_tnrdmd_gpio_set_cfg(struct cxd2880_tnrdmd *tnr_dmd,
				u8 id,
				u8 en,
				enum cxd2880_tnrdmd_gpio_mode mode,
				u8 open_drain, u8 invert);

int cxd2880_tnrdmd_gpio_set_cfg_sub(struct cxd2880_tnrdmd *tnr_dmd,
				    u8 id,
				    u8 en,
				    enum cxd2880_tnrdmd_gpio_mode
				    mode, u8 open_drain,
				    u8 invert);

int cxd2880_tnrdmd_gpio_read(struct cxd2880_tnrdmd *tnr_dmd,
			     u8 id, u8 *value);

int cxd2880_tnrdmd_gpio_read_sub(struct cxd2880_tnrdmd *tnr_dmd,
				 u8 id, u8 *value);

int cxd2880_tnrdmd_gpio_write(struct cxd2880_tnrdmd *tnr_dmd,
			      u8 id, u8 value);

int cxd2880_tnrdmd_gpio_write_sub(struct cxd2880_tnrdmd *tnr_dmd,
				  u8 id, u8 value);

int cxd2880_tnrdmd_interrupt_read(struct cxd2880_tnrdmd *tnr_dmd,
				  u16 *value);

int cxd2880_tnrdmd_interrupt_clear(struct cxd2880_tnrdmd *tnr_dmd,
				   u16 value);

int cxd2880_tnrdmd_ts_buf_clear(struct cxd2880_tnrdmd *tnr_dmd,
				u8 clear_overflow_flag,
				u8 clear_underflow_flag,
				u8 clear_buf);

int cxd2880_tnrdmd_chip_id(struct cxd2880_tnrdmd *tnr_dmd,
			   enum cxd2880_tnrdmd_chip_id *chip_id);

int cxd2880_tnrdmd_set_and_save_reg_bits(struct cxd2880_tnrdmd
					 *tnr_dmd,
					 enum cxd2880_io_tgt tgt,
					 u8 bank, u8 address,
					 u8 value, u8 bit_mask);

int cxd2880_tnrdmd_set_scan_mode(struct cxd2880_tnrdmd *tnr_dmd,
				 enum cxd2880_dtv_sys sys,
				 u8 scan_mode_end);

int cxd2880_tnrdmd_set_pid_ftr(struct cxd2880_tnrdmd *tnr_dmd,
			       struct cxd2880_tnrdmd_pid_ftr_cfg
			       *pid_ftr_cfg);

int cxd2880_tnrdmd_set_rf_lvl_cmpstn(struct cxd2880_tnrdmd
				     *tnr_dmd,
				     int (*rf_lvl_cmpstn)
				     (struct cxd2880_tnrdmd *,
				     int *));

int cxd2880_tnrdmd_set_rf_lvl_cmpstn_sub(struct cxd2880_tnrdmd *tnr_dmd,
					 int (*rf_lvl_cmpstn)
					 (struct cxd2880_tnrdmd *,
					 int *));

int cxd2880_tnrdmd_set_lna_thrs(struct cxd2880_tnrdmd *tnr_dmd,
				struct
				cxd2880_tnrdmd_lna_thrs_tbl_air
				*tbl_air,
				struct
				cxd2880_tnrdmd_lna_thrs_tbl_cable
				*tbl_cable);

int cxd2880_tnrdmd_set_lna_thrs_sub(struct cxd2880_tnrdmd *tnr_dmd,
				    struct
				    cxd2880_tnrdmd_lna_thrs_tbl_air
				    *tbl_air,
				    struct
				    cxd2880_tnrdmd_lna_thrs_tbl_cable
				    *tbl_cable);

int cxd2880_tnrdmd_set_ts_pin_high_low(struct cxd2880_tnrdmd
				       *tnr_dmd, u8 en, u8 value);

int cxd2880_tnrdmd_set_ts_output(struct cxd2880_tnrdmd *tnr_dmd,
				 u8 en);

int slvt_freeze_reg(struct cxd2880_tnrdmd *tnr_dmd);

#endif