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