174ba9207SThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-or-later */
2ccae7af2SMauro Carvalho Chehab /*
3ccae7af2SMauro Carvalho Chehab     tda18271-priv.h - private header for the NXP TDA18271 silicon tuner
4ccae7af2SMauro Carvalho Chehab 
5ccae7af2SMauro Carvalho Chehab     Copyright (C) 2007, 2008 Michael Krufky <mkrufky@linuxtv.org>
6ccae7af2SMauro Carvalho Chehab 
7ccae7af2SMauro Carvalho Chehab */
8ccae7af2SMauro Carvalho Chehab 
9ccae7af2SMauro Carvalho Chehab #ifndef __TDA18271_PRIV_H__
10ccae7af2SMauro Carvalho Chehab #define __TDA18271_PRIV_H__
11ccae7af2SMauro Carvalho Chehab 
1236dba13bSMauro Carvalho Chehab #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
1336dba13bSMauro Carvalho Chehab 
14ccae7af2SMauro Carvalho Chehab #include <linux/kernel.h>
15ccae7af2SMauro Carvalho Chehab #include <linux/types.h>
16ccae7af2SMauro Carvalho Chehab #include <linux/mutex.h>
17ccae7af2SMauro Carvalho Chehab #include "tuner-i2c.h"
18ccae7af2SMauro Carvalho Chehab #include "tda18271.h"
19ccae7af2SMauro Carvalho Chehab 
20ccae7af2SMauro Carvalho Chehab #define R_ID     0x00	/* ID byte                */
21ccae7af2SMauro Carvalho Chehab #define R_TM     0x01	/* Thermo byte            */
22ccae7af2SMauro Carvalho Chehab #define R_PL     0x02	/* Power level byte       */
23ccae7af2SMauro Carvalho Chehab #define R_EP1    0x03	/* Easy Prog byte 1       */
24ccae7af2SMauro Carvalho Chehab #define R_EP2    0x04	/* Easy Prog byte 2       */
25ccae7af2SMauro Carvalho Chehab #define R_EP3    0x05	/* Easy Prog byte 3       */
26ccae7af2SMauro Carvalho Chehab #define R_EP4    0x06	/* Easy Prog byte 4       */
27ccae7af2SMauro Carvalho Chehab #define R_EP5    0x07	/* Easy Prog byte 5       */
28ccae7af2SMauro Carvalho Chehab #define R_CPD    0x08	/* Cal Post-Divider byte  */
29ccae7af2SMauro Carvalho Chehab #define R_CD1    0x09	/* Cal Divider byte 1     */
30ccae7af2SMauro Carvalho Chehab #define R_CD2    0x0a	/* Cal Divider byte 2     */
31ccae7af2SMauro Carvalho Chehab #define R_CD3    0x0b	/* Cal Divider byte 3     */
32ccae7af2SMauro Carvalho Chehab #define R_MPD    0x0c	/* Main Post-Divider byte */
33ccae7af2SMauro Carvalho Chehab #define R_MD1    0x0d	/* Main Divider byte 1    */
34ccae7af2SMauro Carvalho Chehab #define R_MD2    0x0e	/* Main Divider byte 2    */
35ccae7af2SMauro Carvalho Chehab #define R_MD3    0x0f	/* Main Divider byte 3    */
36ccae7af2SMauro Carvalho Chehab #define R_EB1    0x10	/* Extended byte 1        */
37ccae7af2SMauro Carvalho Chehab #define R_EB2    0x11	/* Extended byte 2        */
38ccae7af2SMauro Carvalho Chehab #define R_EB3    0x12	/* Extended byte 3        */
39ccae7af2SMauro Carvalho Chehab #define R_EB4    0x13	/* Extended byte 4        */
40ccae7af2SMauro Carvalho Chehab #define R_EB5    0x14	/* Extended byte 5        */
41ccae7af2SMauro Carvalho Chehab #define R_EB6    0x15	/* Extended byte 6        */
42ccae7af2SMauro Carvalho Chehab #define R_EB7    0x16	/* Extended byte 7        */
43ccae7af2SMauro Carvalho Chehab #define R_EB8    0x17	/* Extended byte 8        */
44ccae7af2SMauro Carvalho Chehab #define R_EB9    0x18	/* Extended byte 9        */
45ccae7af2SMauro Carvalho Chehab #define R_EB10   0x19	/* Extended byte 10       */
46ccae7af2SMauro Carvalho Chehab #define R_EB11   0x1a	/* Extended byte 11       */
47ccae7af2SMauro Carvalho Chehab #define R_EB12   0x1b	/* Extended byte 12       */
48ccae7af2SMauro Carvalho Chehab #define R_EB13   0x1c	/* Extended byte 13       */
49ccae7af2SMauro Carvalho Chehab #define R_EB14   0x1d	/* Extended byte 14       */
50ccae7af2SMauro Carvalho Chehab #define R_EB15   0x1e	/* Extended byte 15       */
51ccae7af2SMauro Carvalho Chehab #define R_EB16   0x1f	/* Extended byte 16       */
52ccae7af2SMauro Carvalho Chehab #define R_EB17   0x20	/* Extended byte 17       */
53ccae7af2SMauro Carvalho Chehab #define R_EB18   0x21	/* Extended byte 18       */
54ccae7af2SMauro Carvalho Chehab #define R_EB19   0x22	/* Extended byte 19       */
55ccae7af2SMauro Carvalho Chehab #define R_EB20   0x23	/* Extended byte 20       */
56ccae7af2SMauro Carvalho Chehab #define R_EB21   0x24	/* Extended byte 21       */
57ccae7af2SMauro Carvalho Chehab #define R_EB22   0x25	/* Extended byte 22       */
58ccae7af2SMauro Carvalho Chehab #define R_EB23   0x26	/* Extended byte 23       */
59ccae7af2SMauro Carvalho Chehab 
60ccae7af2SMauro Carvalho Chehab #define TDA18271_NUM_REGS 39
61ccae7af2SMauro Carvalho Chehab 
62ccae7af2SMauro Carvalho Chehab /*---------------------------------------------------------------------*/
63ccae7af2SMauro Carvalho Chehab 
64ccae7af2SMauro Carvalho Chehab struct tda18271_rf_tracking_filter_cal {
65ccae7af2SMauro Carvalho Chehab 	u32 rfmax;
66ccae7af2SMauro Carvalho Chehab 	u8  rfband;
67ccae7af2SMauro Carvalho Chehab 	u32 rf1_def;
68ccae7af2SMauro Carvalho Chehab 	u32 rf2_def;
69ccae7af2SMauro Carvalho Chehab 	u32 rf3_def;
70ccae7af2SMauro Carvalho Chehab 	u32 rf1;
71ccae7af2SMauro Carvalho Chehab 	u32 rf2;
72ccae7af2SMauro Carvalho Chehab 	u32 rf3;
73ccae7af2SMauro Carvalho Chehab 	s32 rf_a1;
74ccae7af2SMauro Carvalho Chehab 	s32 rf_b1;
75ccae7af2SMauro Carvalho Chehab 	s32 rf_a2;
76ccae7af2SMauro Carvalho Chehab 	s32 rf_b2;
77ccae7af2SMauro Carvalho Chehab };
78ccae7af2SMauro Carvalho Chehab 
79ccae7af2SMauro Carvalho Chehab enum tda18271_pll {
80ccae7af2SMauro Carvalho Chehab 	TDA18271_MAIN_PLL,
81ccae7af2SMauro Carvalho Chehab 	TDA18271_CAL_PLL,
82ccae7af2SMauro Carvalho Chehab };
83ccae7af2SMauro Carvalho Chehab 
84ccae7af2SMauro Carvalho Chehab struct tda18271_map_layout;
85ccae7af2SMauro Carvalho Chehab 
86ccae7af2SMauro Carvalho Chehab enum tda18271_ver {
87ccae7af2SMauro Carvalho Chehab 	TDA18271HDC1,
88ccae7af2SMauro Carvalho Chehab 	TDA18271HDC2,
89ccae7af2SMauro Carvalho Chehab };
90ccae7af2SMauro Carvalho Chehab 
91ccae7af2SMauro Carvalho Chehab struct tda18271_priv {
92ccae7af2SMauro Carvalho Chehab 	unsigned char tda18271_regs[TDA18271_NUM_REGS];
93ccae7af2SMauro Carvalho Chehab 
94ccae7af2SMauro Carvalho Chehab 	struct list_head	hybrid_tuner_instance_list;
95ccae7af2SMauro Carvalho Chehab 	struct tuner_i2c_props	i2c_props;
96ccae7af2SMauro Carvalho Chehab 
97ccae7af2SMauro Carvalho Chehab 	enum tda18271_mode mode;
98ccae7af2SMauro Carvalho Chehab 	enum tda18271_role role;
99ccae7af2SMauro Carvalho Chehab 	enum tda18271_i2c_gate gate;
100ccae7af2SMauro Carvalho Chehab 	enum tda18271_ver id;
101ccae7af2SMauro Carvalho Chehab 	enum tda18271_output_options output_opt;
102ccae7af2SMauro Carvalho Chehab 	enum tda18271_small_i2c small_i2c;
103ccae7af2SMauro Carvalho Chehab 
104ccae7af2SMauro Carvalho Chehab 	unsigned int config; /* interface to saa713x / tda829x */
105ccae7af2SMauro Carvalho Chehab 	unsigned int cal_initialized:1;
106ccae7af2SMauro Carvalho Chehab 
107ccae7af2SMauro Carvalho Chehab 	u8 tm_rfcal;
108ccae7af2SMauro Carvalho Chehab 
109ccae7af2SMauro Carvalho Chehab 	struct tda18271_map_layout *maps;
110ccae7af2SMauro Carvalho Chehab 	struct tda18271_std_map std;
111ccae7af2SMauro Carvalho Chehab 	struct tda18271_rf_tracking_filter_cal rf_cal_state[8];
112ccae7af2SMauro Carvalho Chehab 
113ccae7af2SMauro Carvalho Chehab 	struct mutex lock;
114ccae7af2SMauro Carvalho Chehab 
115ccae7af2SMauro Carvalho Chehab 	u16 if_freq;
116ccae7af2SMauro Carvalho Chehab 
117ccae7af2SMauro Carvalho Chehab 	u32 frequency;
118ccae7af2SMauro Carvalho Chehab 	u32 bandwidth;
119ccae7af2SMauro Carvalho Chehab };
120ccae7af2SMauro Carvalho Chehab 
121ccae7af2SMauro Carvalho Chehab /*---------------------------------------------------------------------*/
122ccae7af2SMauro Carvalho Chehab 
123ccae7af2SMauro Carvalho Chehab extern int tda18271_debug;
124ccae7af2SMauro Carvalho Chehab 
125ccae7af2SMauro Carvalho Chehab #define DBG_INFO 1
126ccae7af2SMauro Carvalho Chehab #define DBG_MAP  2
127ccae7af2SMauro Carvalho Chehab #define DBG_REG  4
128ccae7af2SMauro Carvalho Chehab #define DBG_ADV  8
129ccae7af2SMauro Carvalho Chehab #define DBG_CAL  16
130ccae7af2SMauro Carvalho Chehab 
131ccae7af2SMauro Carvalho Chehab __attribute__((format(printf, 4, 5)))
1320f531e73SJoe Perches void _tda_printk(struct tda18271_priv *state, const char *level,
133ccae7af2SMauro Carvalho Chehab 		 const char *func, const char *fmt, ...);
134ccae7af2SMauro Carvalho Chehab 
135ccae7af2SMauro Carvalho Chehab #define tda_printk(st, lvl, fmt, arg...)			\
136ccae7af2SMauro Carvalho Chehab 	_tda_printk(st, lvl, __func__, fmt, ##arg)
137ccae7af2SMauro Carvalho Chehab 
138ccae7af2SMauro Carvalho Chehab #define tda_dprintk(st, lvl, fmt, arg...)			\
139ccae7af2SMauro Carvalho Chehab do {								\
140ccae7af2SMauro Carvalho Chehab 	if (tda18271_debug & lvl)				\
141ccae7af2SMauro Carvalho Chehab 		tda_printk(st, KERN_DEBUG, fmt, ##arg);		\
142ccae7af2SMauro Carvalho Chehab } while (0)
143ccae7af2SMauro Carvalho Chehab 
144ccae7af2SMauro Carvalho Chehab #define tda_info(fmt, arg...)	pr_info(fmt, ##arg)
145ccae7af2SMauro Carvalho Chehab #define tda_warn(fmt, arg...)	tda_printk(priv, KERN_WARNING, fmt, ##arg)
146ccae7af2SMauro Carvalho Chehab #define tda_err(fmt, arg...)	tda_printk(priv, KERN_ERR,     fmt, ##arg)
147ccae7af2SMauro Carvalho Chehab #define tda_dbg(fmt, arg...)	tda_dprintk(priv, DBG_INFO,    fmt, ##arg)
148ccae7af2SMauro Carvalho Chehab #define tda_map(fmt, arg...)	tda_dprintk(priv, DBG_MAP,     fmt, ##arg)
149ccae7af2SMauro Carvalho Chehab #define tda_reg(fmt, arg...)	tda_dprintk(priv, DBG_REG,     fmt, ##arg)
150ccae7af2SMauro Carvalho Chehab #define tda_cal(fmt, arg...)	tda_dprintk(priv, DBG_CAL,     fmt, ##arg)
151ccae7af2SMauro Carvalho Chehab 
152ccae7af2SMauro Carvalho Chehab #define tda_fail(ret)							     \
153ccae7af2SMauro Carvalho Chehab ({									     \
154ccae7af2SMauro Carvalho Chehab 	int __ret;							     \
155ccae7af2SMauro Carvalho Chehab 	__ret = (ret < 0);						     \
156ccae7af2SMauro Carvalho Chehab 	if (__ret)							     \
157ccae7af2SMauro Carvalho Chehab 		tda_printk(priv, KERN_ERR,				     \
158ccae7af2SMauro Carvalho Chehab 			   "error %d on line %d\n", ret, __LINE__);	     \
159ccae7af2SMauro Carvalho Chehab 	__ret;								     \
160ccae7af2SMauro Carvalho Chehab })
161ccae7af2SMauro Carvalho Chehab 
162ccae7af2SMauro Carvalho Chehab /*---------------------------------------------------------------------*/
163ccae7af2SMauro Carvalho Chehab 
164ccae7af2SMauro Carvalho Chehab enum tda18271_map_type {
165ccae7af2SMauro Carvalho Chehab 	/* tda18271_pll_map */
166ccae7af2SMauro Carvalho Chehab 	MAIN_PLL,
167ccae7af2SMauro Carvalho Chehab 	CAL_PLL,
168ccae7af2SMauro Carvalho Chehab 	/* tda18271_map */
169ccae7af2SMauro Carvalho Chehab 	RF_CAL,
170ccae7af2SMauro Carvalho Chehab 	RF_CAL_KMCO,
171ccae7af2SMauro Carvalho Chehab 	RF_CAL_DC_OVER_DT,
172ccae7af2SMauro Carvalho Chehab 	BP_FILTER,
173ccae7af2SMauro Carvalho Chehab 	RF_BAND,
174ccae7af2SMauro Carvalho Chehab 	GAIN_TAPER,
175ccae7af2SMauro Carvalho Chehab 	IR_MEASURE,
176ccae7af2SMauro Carvalho Chehab };
177ccae7af2SMauro Carvalho Chehab 
178ccae7af2SMauro Carvalho Chehab extern int tda18271_lookup_pll_map(struct dvb_frontend *fe,
179ccae7af2SMauro Carvalho Chehab 				   enum tda18271_map_type map_type,
180ccae7af2SMauro Carvalho Chehab 				   u32 *freq, u8 *post_div, u8 *div);
181ccae7af2SMauro Carvalho Chehab extern int tda18271_lookup_map(struct dvb_frontend *fe,
182ccae7af2SMauro Carvalho Chehab 			       enum tda18271_map_type map_type,
183ccae7af2SMauro Carvalho Chehab 			       u32 *freq, u8 *val);
184ccae7af2SMauro Carvalho Chehab 
185ccae7af2SMauro Carvalho Chehab extern int tda18271_lookup_thermometer(struct dvb_frontend *fe);
186ccae7af2SMauro Carvalho Chehab 
187ccae7af2SMauro Carvalho Chehab extern int tda18271_lookup_rf_band(struct dvb_frontend *fe,
188ccae7af2SMauro Carvalho Chehab 				   u32 *freq, u8 *rf_band);
189ccae7af2SMauro Carvalho Chehab 
190ccae7af2SMauro Carvalho Chehab extern int tda18271_lookup_cid_target(struct dvb_frontend *fe,
191ccae7af2SMauro Carvalho Chehab 				      u32 *freq, u8 *cid_target,
192ccae7af2SMauro Carvalho Chehab 				      u16 *count_limit);
193ccae7af2SMauro Carvalho Chehab 
194ccae7af2SMauro Carvalho Chehab extern int tda18271_assign_map_layout(struct dvb_frontend *fe);
195ccae7af2SMauro Carvalho Chehab 
196ccae7af2SMauro Carvalho Chehab /*---------------------------------------------------------------------*/
197ccae7af2SMauro Carvalho Chehab 
198ccae7af2SMauro Carvalho Chehab extern int tda18271_read_regs(struct dvb_frontend *fe);
199ccae7af2SMauro Carvalho Chehab extern int tda18271_read_extended(struct dvb_frontend *fe);
200ccae7af2SMauro Carvalho Chehab extern int tda18271_write_regs(struct dvb_frontend *fe, int idx, int len);
201ccae7af2SMauro Carvalho Chehab extern int tda18271_init_regs(struct dvb_frontend *fe);
202ccae7af2SMauro Carvalho Chehab 
203ccae7af2SMauro Carvalho Chehab extern int tda18271_charge_pump_source(struct dvb_frontend *fe,
204ccae7af2SMauro Carvalho Chehab 				       enum tda18271_pll pll, int force);
205ccae7af2SMauro Carvalho Chehab extern int tda18271_set_standby_mode(struct dvb_frontend *fe,
206ccae7af2SMauro Carvalho Chehab 				     int sm, int sm_lt, int sm_xt);
207ccae7af2SMauro Carvalho Chehab 
208ccae7af2SMauro Carvalho Chehab extern int tda18271_calc_main_pll(struct dvb_frontend *fe, u32 freq);
209ccae7af2SMauro Carvalho Chehab extern int tda18271_calc_cal_pll(struct dvb_frontend *fe, u32 freq);
210ccae7af2SMauro Carvalho Chehab 
211ccae7af2SMauro Carvalho Chehab extern int tda18271_calc_bp_filter(struct dvb_frontend *fe, u32 *freq);
212ccae7af2SMauro Carvalho Chehab extern int tda18271_calc_km(struct dvb_frontend *fe, u32 *freq);
213ccae7af2SMauro Carvalho Chehab extern int tda18271_calc_rf_band(struct dvb_frontend *fe, u32 *freq);
214ccae7af2SMauro Carvalho Chehab extern int tda18271_calc_gain_taper(struct dvb_frontend *fe, u32 *freq);
215ccae7af2SMauro Carvalho Chehab extern int tda18271_calc_ir_measure(struct dvb_frontend *fe, u32 *freq);
216ccae7af2SMauro Carvalho Chehab extern int tda18271_calc_rf_cal(struct dvb_frontend *fe, u32 *freq);
217ccae7af2SMauro Carvalho Chehab 
218ccae7af2SMauro Carvalho Chehab #endif /* __TDA18271_PRIV_H__ */
219