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