blob: 7b939a5325fb970189feeb998913f37e49d11e19 [file] [log] [blame]
Michael Krufky6ca04de2007-11-23 16:52:15 -03001/*
2 tda18271-priv.h - private header for the NXP TDA18271 silicon tuner
3
Michael Krufky59067f72008-01-02 01:58:26 -03004 Copyright (C) 2007, 2008 Michael Krufky <mkrufky@linuxtv.org>
Michael Krufky6ca04de2007-11-23 16:52:15 -03005
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19*/
20
21#ifndef __TDA18271_PRIV_H__
22#define __TDA18271_PRIV_H__
23
Michael Krufkyb5f3e1e2007-12-02 16:36:05 -030024#include <linux/kernel.h>
Michael Krufky6ca04de2007-11-23 16:52:15 -030025#include <linux/types.h>
Michael Krufky8d316bf2008-01-06 15:31:35 -030026#include <linux/mutex.h>
Michael Krufkyd3714212007-12-24 14:38:41 -030027#include "tda18271.h"
Michael Krufky6ca04de2007-11-23 16:52:15 -030028
29#define R_ID 0x00 /* ID byte */
30#define R_TM 0x01 /* Thermo byte */
31#define R_PL 0x02 /* Power level byte */
32#define R_EP1 0x03 /* Easy Prog byte 1 */
33#define R_EP2 0x04 /* Easy Prog byte 2 */
34#define R_EP3 0x05 /* Easy Prog byte 3 */
35#define R_EP4 0x06 /* Easy Prog byte 4 */
36#define R_EP5 0x07 /* Easy Prog byte 5 */
37#define R_CPD 0x08 /* Cal Post-Divider byte */
38#define R_CD1 0x09 /* Cal Divider byte 1 */
39#define R_CD2 0x0a /* Cal Divider byte 2 */
40#define R_CD3 0x0b /* Cal Divider byte 3 */
41#define R_MPD 0x0c /* Main Post-Divider byte */
42#define R_MD1 0x0d /* Main Divider byte 1 */
43#define R_MD2 0x0e /* Main Divider byte 2 */
44#define R_MD3 0x0f /* Main Divider byte 3 */
45#define R_EB1 0x10 /* Extended byte 1 */
46#define R_EB2 0x11 /* Extended byte 2 */
47#define R_EB3 0x12 /* Extended byte 3 */
48#define R_EB4 0x13 /* Extended byte 4 */
49#define R_EB5 0x14 /* Extended byte 5 */
50#define R_EB6 0x15 /* Extended byte 6 */
51#define R_EB7 0x16 /* Extended byte 7 */
52#define R_EB8 0x17 /* Extended byte 8 */
53#define R_EB9 0x18 /* Extended byte 9 */
54#define R_EB10 0x19 /* Extended byte 10 */
55#define R_EB11 0x1a /* Extended byte 11 */
56#define R_EB12 0x1b /* Extended byte 12 */
57#define R_EB13 0x1c /* Extended byte 13 */
58#define R_EB14 0x1d /* Extended byte 14 */
59#define R_EB15 0x1e /* Extended byte 15 */
60#define R_EB16 0x1f /* Extended byte 16 */
61#define R_EB17 0x20 /* Extended byte 17 */
62#define R_EB18 0x21 /* Extended byte 18 */
63#define R_EB19 0x22 /* Extended byte 19 */
64#define R_EB20 0x23 /* Extended byte 20 */
65#define R_EB21 0x24 /* Extended byte 21 */
66#define R_EB22 0x25 /* Extended byte 22 */
67#define R_EB23 0x26 /* Extended byte 23 */
68
69#define TDA18271_NUM_REGS 39
70
Michael Krufkyd3714212007-12-24 14:38:41 -030071/*---------------------------------------------------------------------*/
72
Michael Krufky255b5112008-01-01 22:52:09 -030073struct tda18271_rf_tracking_filter_cal {
74 u32 rfmax;
75 u8 rfband;
76 u32 rf1_def;
77 u32 rf2_def;
78 u32 rf3_def;
79 u32 rf1;
80 u32 rf2;
81 u32 rf3;
82 int rf_a1;
83 int rf_b1;
84 int rf_a2;
85 int rf_b2;
86};
87
Michael Krufkyd3714212007-12-24 14:38:41 -030088enum tda18271_mode {
89 TDA18271_ANALOG,
90 TDA18271_DIGITAL,
91};
92
Michael Krufky255b5112008-01-01 22:52:09 -030093struct tda18271_map_layout;
94
95enum tda18271_ver {
96 TDA18271HDC1,
97 TDA18271HDC2,
98};
99
Michael Krufkyd3714212007-12-24 14:38:41 -0300100struct tda18271_priv {
101 u8 i2c_addr;
102 struct i2c_adapter *i2c_adap;
103 unsigned char tda18271_regs[TDA18271_NUM_REGS];
104
Michael Krufkya4f263b2008-01-06 15:52:56 -0300105 struct list_head tda18271_list;
106
Michael Krufkyd3714212007-12-24 14:38:41 -0300107 enum tda18271_mode mode;
108 enum tda18271_i2c_gate gate;
Michael Krufky255b5112008-01-01 22:52:09 -0300109 enum tda18271_ver id;
110
Michael Krufkya4f263b2008-01-06 15:52:56 -0300111 unsigned int count;
Michael Krufky09f83c42008-01-05 20:00:09 -0300112 unsigned int tm_rfcal;
Michael Krufky255b5112008-01-01 22:52:09 -0300113 unsigned int cal_initialized:1;
114
Michael Krufky255b5112008-01-01 22:52:09 -0300115 struct tda18271_map_layout *maps;
Michael Krufkyf21e0d72008-01-02 03:01:54 -0300116 struct tda18271_std_map std;
Michael Krufky255b5112008-01-01 22:52:09 -0300117 struct tda18271_rf_tracking_filter_cal rf_cal_state[8];
118
Michael Krufky8d316bf2008-01-06 15:31:35 -0300119 struct mutex lock;
120
Michael Krufkyd3714212007-12-24 14:38:41 -0300121 u32 frequency;
122 u32 bandwidth;
123};
124
125/*---------------------------------------------------------------------*/
126
Michael Krufkyb5f3e1e2007-12-02 16:36:05 -0300127extern int tda18271_debug;
Michael Krufky6ca04de2007-11-23 16:52:15 -0300128
Michael Krufkyb5f3e1e2007-12-02 16:36:05 -0300129#define DBG_INFO 1
130#define DBG_MAP 2
131#define DBG_REG 4
Michael Krufky255b5112008-01-01 22:52:09 -0300132#define DBG_ADV 8
Michael Krufkycf04d292008-01-09 00:34:30 -0300133#define DBG_CAL 16
Michael Krufky6ca04de2007-11-23 16:52:15 -0300134
Michael Krufky182519f2007-12-25 15:10:11 -0300135#define tda_printk(kern, fmt, arg...) \
136 printk(kern "%s: " fmt, __FUNCTION__, ##arg)
137
138#define dprintk(kern, lvl, fmt, arg...) do {\
139 if (tda18271_debug & lvl) \
140 tda_printk(kern, fmt, ##arg); } while (0)
141
142#define tda_info(fmt, arg...) printk(KERN_INFO fmt, ##arg)
143#define tda_warn(fmt, arg...) tda_printk(KERN_WARNING, fmt, ##arg)
144#define tda_err(fmt, arg...) tda_printk(KERN_ERR, fmt, ##arg)
145#define tda_dbg(fmt, arg...) dprintk(KERN_DEBUG, DBG_INFO, fmt, ##arg)
146#define tda_map(fmt, arg...) dprintk(KERN_DEBUG, DBG_MAP, fmt, ##arg)
147#define tda_reg(fmt, arg...) dprintk(KERN_DEBUG, DBG_REG, fmt, ##arg)
Michael Krufkycf04d292008-01-09 00:34:30 -0300148#define tda_cal(fmt, arg...) dprintk(KERN_DEBUG, DBG_CAL, fmt, ##arg)
Michael Krufkyb5f3e1e2007-12-02 16:36:05 -0300149
150/*---------------------------------------------------------------------*/
151
Michael Krufky2f27dfc2007-12-25 00:39:37 -0300152enum tda18271_map_type {
153 /* tda18271_pll_map */
154 MAIN_PLL,
155 CAL_PLL,
156 /* tda18271_map */
157 RF_CAL,
158 RF_CAL_KMCO,
Michael Krufky255b5112008-01-01 22:52:09 -0300159 RF_CAL_DC_OVER_DT,
Michael Krufky2f27dfc2007-12-25 00:39:37 -0300160 BP_FILTER,
161 RF_BAND,
162 GAIN_TAPER,
163 IR_MEASURE,
164};
Michael Krufkyb5f3e1e2007-12-02 16:36:05 -0300165
Michael Krufky255b5112008-01-01 22:52:09 -0300166extern int tda18271_lookup_pll_map(struct dvb_frontend *fe,
167 enum tda18271_map_type map_type,
Michael Krufky2f27dfc2007-12-25 00:39:37 -0300168 u32 *freq, u8 *post_div, u8 *div);
Michael Krufky255b5112008-01-01 22:52:09 -0300169extern int tda18271_lookup_map(struct dvb_frontend *fe,
170 enum tda18271_map_type map_type,
Michael Krufky2f27dfc2007-12-25 00:39:37 -0300171 u32 *freq, u8 *val);
Michael Krufky6ca04de2007-11-23 16:52:15 -0300172
Michael Krufky255b5112008-01-01 22:52:09 -0300173extern int tda18271_lookup_thermometer(struct dvb_frontend *fe);
174
175extern int tda18271_lookup_rf_band(struct dvb_frontend *fe,
176 u32 *freq, u8 *rf_band);
177
178extern int tda18271_lookup_cid_target(struct dvb_frontend *fe,
179 u32 *freq, u8 *cid_target,
180 u16 *count_limit);
181
182extern int tda18271_assign_map_layout(struct dvb_frontend *fe);
183
Michael Krufky59067f72008-01-02 01:58:26 -0300184/*---------------------------------------------------------------------*/
185
186extern int tda18271_read_regs(struct dvb_frontend *fe);
187extern int tda18271_read_extended(struct dvb_frontend *fe);
188extern int tda18271_write_regs(struct dvb_frontend *fe, int idx, int len);
189extern int tda18271_init_regs(struct dvb_frontend *fe);
190
Michael Krufky518d8732008-01-13 17:01:01 -0300191extern int tda18271_set_standby_mode(struct dvb_frontend *fe,
192 int sm, int sm_lt, int sm_xt);
193
Michael Krufky59067f72008-01-02 01:58:26 -0300194extern int tda18271_calc_main_pll(struct dvb_frontend *fe, u32 freq);
195extern int tda18271_calc_cal_pll(struct dvb_frontend *fe, u32 freq);
196
197extern int tda18271_calc_bp_filter(struct dvb_frontend *fe, u32 *freq);
198extern int tda18271_calc_km(struct dvb_frontend *fe, u32 *freq);
199extern int tda18271_calc_rf_band(struct dvb_frontend *fe, u32 *freq);
200extern int tda18271_calc_gain_taper(struct dvb_frontend *fe, u32 *freq);
201extern int tda18271_calc_ir_measure(struct dvb_frontend *fe, u32 *freq);
202extern int tda18271_calc_rf_cal(struct dvb_frontend *fe, u32 *freq);
203
Michael Krufky6ca04de2007-11-23 16:52:15 -0300204#endif /* __TDA18271_PRIV_H__ */
205
206/*
207 * Overrides for Emacs so that we follow Linus's tabbing style.
208 * ---------------------------------------------------------------------------
209 * Local variables:
210 * c-basic-offset: 8
211 * End:
212 */