aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/dvb/frontends/tda827x.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/media/dvb/frontends/tda827x.c')
-rw-r--r--drivers/media/dvb/frontends/tda827x.c852
1 files changed, 0 insertions, 852 deletions
diff --git a/drivers/media/dvb/frontends/tda827x.c b/drivers/media/dvb/frontends/tda827x.c
deleted file mode 100644
index d30d2c9094d9..000000000000
--- a/drivers/media/dvb/frontends/tda827x.c
+++ /dev/null
@@ -1,852 +0,0 @@
1/*
2 *
3 * (c) 2005 Hartmut Hackmann
4 * (c) 2007 Michael Krufky
5 *
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#include <linux/module.h>
22#include <asm/types.h>
23#include <linux/dvb/frontend.h>
24#include <linux/videodev2.h>
25
26#include "tda827x.h"
27
28static int debug;
29module_param(debug, int, 0644);
30MODULE_PARM_DESC(debug, "Turn on/off frontend debugging (default:off).");
31
32#define dprintk(args...) \
33 do { \
34 if (debug) printk(KERN_DEBUG "tda827x: " args); \
35 } while (0)
36
37struct tda827x_priv {
38 int i2c_addr;
39 struct i2c_adapter *i2c_adap;
40 struct tda827x_config *cfg;
41
42 unsigned int sgIF;
43 unsigned char lpsel;
44
45 u32 frequency;
46 u32 bandwidth;
47};
48
49static void tda827x_set_std(struct dvb_frontend *fe,
50 struct analog_parameters *params)
51{
52 struct tda827x_priv *priv = fe->tuner_priv;
53 char *mode;
54
55 priv->lpsel = 0;
56 if (params->std & V4L2_STD_MN) {
57 priv->sgIF = 92;
58 priv->lpsel = 1;
59 mode = "MN";
60 } else if (params->std & V4L2_STD_B) {
61 priv->sgIF = 108;
62 mode = "B";
63 } else if (params->std & V4L2_STD_GH) {
64 priv->sgIF = 124;
65 mode = "GH";
66 } else if (params->std & V4L2_STD_PAL_I) {
67 priv->sgIF = 124;
68 mode = "I";
69 } else if (params->std & V4L2_STD_DK) {
70 priv->sgIF = 124;
71 mode = "DK";
72 } else if (params->std & V4L2_STD_SECAM_L) {
73 priv->sgIF = 124;
74 mode = "L";
75 } else if (params->std & V4L2_STD_SECAM_LC) {
76 priv->sgIF = 20;
77 mode = "LC";
78 } else {
79 priv->sgIF = 124;
80 mode = "xx";
81 }
82
83 if (params->mode == V4L2_TUNER_RADIO)
84 priv->sgIF = 88; /* if frequency is 5.5 MHz */
85
86 dprintk("setting tda827x to system %s\n", mode);
87}
88
89
90/* ------------------------------------------------------------------ */
91
92struct tda827x_data {
93 u32 lomax;
94 u8 spd;
95 u8 bs;
96 u8 bp;
97 u8 cp;
98 u8 gc3;
99 u8 div1p5;
100};
101
102static const struct tda827x_data tda827x_table[] = {
103 { .lomax = 62000000, .spd = 3, .bs = 2, .bp = 0, .cp = 0, .gc3 = 3, .div1p5 = 1},
104 { .lomax = 66000000, .spd = 3, .bs = 3, .bp = 0, .cp = 0, .gc3 = 3, .div1p5 = 1},
105 { .lomax = 76000000, .spd = 3, .bs = 1, .bp = 0, .cp = 0, .gc3 = 3, .div1p5 = 0},
106 { .lomax = 84000000, .spd = 3, .bs = 2, .bp = 0, .cp = 0, .gc3 = 3, .div1p5 = 0},
107 { .lomax = 93000000, .spd = 3, .bs = 2, .bp = 0, .cp = 0, .gc3 = 1, .div1p5 = 0},
108 { .lomax = 98000000, .spd = 3, .bs = 3, .bp = 0, .cp = 0, .gc3 = 1, .div1p5 = 0},
109 { .lomax = 109000000, .spd = 3, .bs = 3, .bp = 1, .cp = 0, .gc3 = 1, .div1p5 = 0},
110 { .lomax = 123000000, .spd = 2, .bs = 2, .bp = 1, .cp = 0, .gc3 = 1, .div1p5 = 1},
111 { .lomax = 133000000, .spd = 2, .bs = 3, .bp = 1, .cp = 0, .gc3 = 1, .div1p5 = 1},
112 { .lomax = 151000000, .spd = 2, .bs = 1, .bp = 1, .cp = 0, .gc3 = 1, .div1p5 = 0},
113 { .lomax = 154000000, .spd = 2, .bs = 2, .bp = 1, .cp = 0, .gc3 = 1, .div1p5 = 0},
114 { .lomax = 181000000, .spd = 2, .bs = 2, .bp = 1, .cp = 0, .gc3 = 0, .div1p5 = 0},
115 { .lomax = 185000000, .spd = 2, .bs = 2, .bp = 2, .cp = 0, .gc3 = 1, .div1p5 = 0},
116 { .lomax = 217000000, .spd = 2, .bs = 3, .bp = 2, .cp = 0, .gc3 = 1, .div1p5 = 0},
117 { .lomax = 244000000, .spd = 1, .bs = 2, .bp = 2, .cp = 0, .gc3 = 1, .div1p5 = 1},
118 { .lomax = 265000000, .spd = 1, .bs = 3, .bp = 2, .cp = 0, .gc3 = 1, .div1p5 = 1},
119 { .lomax = 302000000, .spd = 1, .bs = 1, .bp = 2, .cp = 0, .gc3 = 1, .div1p5 = 0},
120 { .lomax = 324000000, .spd = 1, .bs = 2, .bp = 2, .cp = 0, .gc3 = 1, .div1p5 = 0},
121 { .lomax = 370000000, .spd = 1, .bs = 2, .bp = 3, .cp = 0, .gc3 = 1, .div1p5 = 0},
122 { .lomax = 454000000, .spd = 1, .bs = 3, .bp = 3, .cp = 0, .gc3 = 1, .div1p5 = 0},
123 { .lomax = 493000000, .spd = 0, .bs = 2, .bp = 3, .cp = 0, .gc3 = 1, .div1p5 = 1},
124 { .lomax = 530000000, .spd = 0, .bs = 3, .bp = 3, .cp = 0, .gc3 = 1, .div1p5 = 1},
125 { .lomax = 554000000, .spd = 0, .bs = 1, .bp = 3, .cp = 0, .gc3 = 1, .div1p5 = 0},
126 { .lomax = 604000000, .spd = 0, .bs = 1, .bp = 4, .cp = 0, .gc3 = 0, .div1p5 = 0},
127 { .lomax = 696000000, .spd = 0, .bs = 2, .bp = 4, .cp = 0, .gc3 = 0, .div1p5 = 0},
128 { .lomax = 740000000, .spd = 0, .bs = 2, .bp = 4, .cp = 1, .gc3 = 0, .div1p5 = 0},
129 { .lomax = 820000000, .spd = 0, .bs = 3, .bp = 4, .cp = 0, .gc3 = 0, .div1p5 = 0},
130 { .lomax = 865000000, .spd = 0, .bs = 3, .bp = 4, .cp = 1, .gc3 = 0, .div1p5 = 0},
131 { .lomax = 0, .spd = 0, .bs = 0, .bp = 0, .cp = 0, .gc3 = 0, .div1p5 = 0}
132};
133
134static int tda827xo_set_params(struct dvb_frontend *fe,
135 struct dvb_frontend_parameters *params)
136{
137 struct tda827x_priv *priv = fe->tuner_priv;
138 u8 buf[14];
139
140 struct i2c_msg msg = { .addr = priv->i2c_addr, .flags = 0,
141 .buf = buf, .len = sizeof(buf) };
142 int i, tuner_freq, if_freq;
143 u32 N;
144
145 dprintk("%s:\n", __func__);
146 switch (params->u.ofdm.bandwidth) {
147 case BANDWIDTH_6_MHZ:
148 if_freq = 4000000;
149 break;
150 case BANDWIDTH_7_MHZ:
151 if_freq = 4500000;
152 break;
153 default: /* 8 MHz or Auto */
154 if_freq = 5000000;
155 break;
156 }
157 tuner_freq = params->frequency + if_freq;
158
159 i = 0;
160 while (tda827x_table[i].lomax < tuner_freq) {
161 if (tda827x_table[i + 1].lomax == 0)
162 break;
163 i++;
164 }
165
166 N = ((tuner_freq + 125000) / 250000) << (tda827x_table[i].spd + 2);
167 buf[0] = 0;
168 buf[1] = (N>>8) | 0x40;
169 buf[2] = N & 0xff;
170 buf[3] = 0;
171 buf[4] = 0x52;
172 buf[5] = (tda827x_table[i].spd << 6) + (tda827x_table[i].div1p5 << 5) +
173 (tda827x_table[i].bs << 3) +
174 tda827x_table[i].bp;
175 buf[6] = (tda827x_table[i].gc3 << 4) + 0x8f;
176 buf[7] = 0xbf;
177 buf[8] = 0x2a;
178 buf[9] = 0x05;
179 buf[10] = 0xff;
180 buf[11] = 0x00;
181 buf[12] = 0x00;
182 buf[13] = 0x40;
183
184 msg.len = 14;
185 if (fe->ops.i2c_gate_ctrl)
186 fe->ops.i2c_gate_ctrl(fe, 1);
187 if (i2c_transfer(priv->i2c_adap, &msg, 1) != 1) {
188 printk("%s: could not write to tuner at addr: 0x%02x\n",
189 __func__, priv->i2c_addr << 1);
190 return -EIO;
191 }
192 msleep(500);
193 /* correct CP value */
194 buf[0] = 0x30;
195 buf[1] = 0x50 + tda827x_table[i].cp;
196 msg.len = 2;
197
198 if (fe->ops.i2c_gate_ctrl)
199 fe->ops.i2c_gate_ctrl(fe, 1);
200 i2c_transfer(priv->i2c_adap, &msg, 1);
201
202 priv->frequency = tuner_freq - if_freq; // FIXME
203 priv->bandwidth = (fe->ops.info.type == FE_OFDM) ? params->u.ofdm.bandwidth : 0;
204
205 return 0;
206}
207
208static int tda827xo_sleep(struct dvb_frontend *fe)
209{
210 struct tda827x_priv *priv = fe->tuner_priv;
211 static u8 buf[] = { 0x30, 0xd0 };
212 struct i2c_msg msg = { .addr = priv->i2c_addr, .flags = 0,
213 .buf = buf, .len = sizeof(buf) };
214
215 dprintk("%s:\n", __func__);
216 if (fe->ops.i2c_gate_ctrl)
217 fe->ops.i2c_gate_ctrl(fe, 1);
218 i2c_transfer(priv->i2c_adap, &msg, 1);
219
220 if (priv->cfg && priv->cfg->sleep)
221 priv->cfg->sleep(fe);
222
223 return 0;
224}
225
226/* ------------------------------------------------------------------ */
227
228static int tda827xo_set_analog_params(struct dvb_frontend *fe,
229 struct analog_parameters *params)
230{
231 unsigned char tuner_reg[8];
232 unsigned char reg2[2];
233 u32 N;
234 int i;
235 struct tda827x_priv *priv = fe->tuner_priv;
236 struct i2c_msg msg = { .addr = priv->i2c_addr, .flags = 0 };
237 unsigned int freq = params->frequency;
238
239 tda827x_set_std(fe, params);
240
241 if (params->mode == V4L2_TUNER_RADIO)
242 freq = freq / 1000;
243
244 N = freq + priv->sgIF;
245
246 i = 0;
247 while (tda827x_table[i].lomax < N * 62500) {
248 if (tda827x_table[i + 1].lomax == 0)
249 break;
250 i++;
251 }
252
253 N = N << tda827x_table[i].spd;
254
255 tuner_reg[0] = 0;
256 tuner_reg[1] = (unsigned char)(N>>8);
257 tuner_reg[2] = (unsigned char) N;
258 tuner_reg[3] = 0x40;
259 tuner_reg[4] = 0x52 + (priv->lpsel << 5);
260 tuner_reg[5] = (tda827x_table[i].spd << 6) +
261 (tda827x_table[i].div1p5 << 5) +
262 (tda827x_table[i].bs << 3) + tda827x_table[i].bp;
263 tuner_reg[6] = 0x8f + (tda827x_table[i].gc3 << 4);
264 tuner_reg[7] = 0x8f;
265
266 msg.buf = tuner_reg;
267 msg.len = 8;
268 i2c_transfer(priv->i2c_adap, &msg, 1);
269
270 msg.buf = reg2;
271 msg.len = 2;
272 reg2[0] = 0x80;
273 reg2[1] = 0;
274 i2c_transfer(priv->i2c_adap, &msg, 1);
275
276 reg2[0] = 0x60;
277 reg2[1] = 0xbf;
278 i2c_transfer(priv->i2c_adap, &msg, 1);
279
280 reg2[0] = 0x30;
281 reg2[1] = tuner_reg[4] + 0x80;
282 i2c_transfer(priv->i2c_adap, &msg, 1);
283
284 msleep(1);
285 reg2[0] = 0x30;
286 reg2[1] = tuner_reg[4] + 4;
287 i2c_transfer(priv->i2c_adap, &msg, 1);
288
289 msleep(1);
290 reg2[0] = 0x30;
291 reg2[1] = tuner_reg[4];
292 i2c_transfer(priv->i2c_adap, &msg, 1);
293
294 msleep(550);
295 reg2[0] = 0x30;
296 reg2[1] = (tuner_reg[4] & 0xfc) + tda827x_table[i].cp;
297 i2c_transfer(priv->i2c_adap, &msg, 1);
298
299 reg2[0] = 0x60;
300 reg2[1] = 0x3f;
301 i2c_transfer(priv->i2c_adap, &msg, 1);
302
303 reg2[0] = 0x80;
304 reg2[1] = 0x08; /* Vsync en */
305 i2c_transfer(priv->i2c_adap, &msg, 1);
306
307 priv->frequency = freq * 62500;
308
309 return 0;
310}
311
312static void tda827xo_agcf(struct dvb_frontend *fe)
313{
314 struct tda827x_priv *priv = fe->tuner_priv;
315 unsigned char data[] = { 0x80, 0x0c };
316 struct i2c_msg msg = { .addr = priv->i2c_addr, .flags = 0,
317 .buf = data, .len = 2};
318
319 i2c_transfer(priv->i2c_adap, &msg, 1);
320}
321
322/* ------------------------------------------------------------------ */
323
324struct tda827xa_data {
325 u32 lomax;
326 u8 svco;
327 u8 spd;
328 u8 scr;
329 u8 sbs;
330 u8 gc3;
331};
332
333static const struct tda827xa_data tda827xa_dvbt[] = {
334 { .lomax = 56875000, .svco = 3, .spd = 4, .scr = 0, .sbs = 0, .gc3 = 1},
335 { .lomax = 67250000, .svco = 0, .spd = 3, .scr = 0, .sbs = 0, .gc3 = 1},
336 { .lomax = 81250000, .svco = 1, .spd = 3, .scr = 0, .sbs = 0, .gc3 = 1},
337 { .lomax = 97500000, .svco = 2, .spd = 3, .scr = 0, .sbs = 0, .gc3 = 1},
338 { .lomax = 113750000, .svco = 3, .spd = 3, .scr = 0, .sbs = 1, .gc3 = 1},
339 { .lomax = 134500000, .svco = 0, .spd = 2, .scr = 0, .sbs = 1, .gc3 = 1},
340 { .lomax = 154000000, .svco = 1, .spd = 2, .scr = 0, .sbs = 1, .gc3 = 1},
341 { .lomax = 162500000, .svco = 1, .spd = 2, .scr = 0, .sbs = 1, .gc3 = 1},
342 { .lomax = 183000000, .svco = 2, .spd = 2, .scr = 0, .sbs = 1, .gc3 = 1},
343 { .lomax = 195000000, .svco = 2, .spd = 2, .scr = 0, .sbs = 2, .gc3 = 1},
344 { .lomax = 227500000, .svco = 3, .spd = 2, .scr = 0, .sbs = 2, .gc3 = 1},
345 { .lomax = 269000000, .svco = 0, .spd = 1, .scr = 0, .sbs = 2, .gc3 = 1},
346 { .lomax = 290000000, .svco = 1, .spd = 1, .scr = 0, .sbs = 2, .gc3 = 1},
347 { .lomax = 325000000, .svco = 1, .spd = 1, .scr = 0, .sbs = 3, .gc3 = 1},
348 { .lomax = 390000000, .svco = 2, .spd = 1, .scr = 0, .sbs = 3, .gc3 = 1},
349 { .lomax = 455000000, .svco = 3, .spd = 1, .scr = 0, .sbs = 3, .gc3 = 1},
350 { .lomax = 520000000, .svco = 0, .spd = 0, .scr = 0, .sbs = 3, .gc3 = 1},
351 { .lomax = 538000000, .svco = 0, .spd = 0, .scr = 1, .sbs = 3, .gc3 = 1},
352 { .lomax = 550000000, .svco = 1, .spd = 0, .scr = 0, .sbs = 3, .gc3 = 1},
353 { .lomax = 620000000, .svco = 1, .spd = 0, .scr = 0, .sbs = 4, .gc3 = 0},
354 { .lomax = 650000000, .svco = 1, .spd = 0, .scr = 1, .sbs = 4, .gc3 = 0},
355 { .lomax = 700000000, .svco = 2, .spd = 0, .scr = 0, .sbs = 4, .gc3 = 0},
356 { .lomax = 780000000, .svco = 2, .spd = 0, .scr = 1, .sbs = 4, .gc3 = 0},
357 { .lomax = 820000000, .svco = 3, .spd = 0, .scr = 0, .sbs = 4, .gc3 = 0},
358 { .lomax = 870000000, .svco = 3, .spd = 0, .scr = 1, .sbs = 4, .gc3 = 0},
359 { .lomax = 911000000, .svco = 3, .spd = 0, .scr = 2, .sbs = 4, .gc3 = 0},
360 { .lomax = 0, .svco = 0, .spd = 0, .scr = 0, .sbs = 0, .gc3 = 0}
361};
362
363static struct tda827xa_data tda827xa_analog[] = {
364 { .lomax = 56875000, .svco = 3, .spd = 4, .scr = 0, .sbs = 0, .gc3 = 3},
365 { .lomax = 67250000, .svco = 0, .spd = 3, .scr = 0, .sbs = 0, .gc3 = 3},
366 { .lomax = 81250000, .svco = 1, .spd = 3, .scr = 0, .sbs = 0, .gc3 = 3},
367 { .lomax = 97500000, .svco = 2, .spd = 3, .scr = 0, .sbs = 0, .gc3 = 3},
368 { .lomax = 113750000, .svco = 3, .spd = 3, .scr = 0, .sbs = 1, .gc3 = 1},
369 { .lomax = 134500000, .svco = 0, .spd = 2, .scr = 0, .sbs = 1, .gc3 = 1},
370 { .lomax = 154000000, .svco = 1, .spd = 2, .scr = 0, .sbs = 1, .gc3 = 1},
371 { .lomax = 162500000, .svco = 1, .spd = 2, .scr = 0, .sbs = 1, .gc3 = 1},
372 { .lomax = 183000000, .svco = 2, .spd = 2, .scr = 0, .sbs = 1, .gc3 = 1},
373 { .lomax = 195000000, .svco = 2, .spd = 2, .scr = 0, .sbs = 2, .gc3 = 1},
374 { .lomax = 227500000, .svco = 3, .spd = 2, .scr = 0, .sbs = 2, .gc3 = 3},
375 { .lomax = 269000000, .svco = 0, .spd = 1, .scr = 0, .sbs = 2, .gc3 = 3},
376 { .lomax = 325000000, .svco = 1, .spd = 1, .scr = 0, .sbs = 2, .gc3 = 1},
377 { .lomax = 390000000, .svco = 2, .spd = 1, .scr = 0, .sbs = 3, .gc3 = 3},
378 { .lomax = 455000000, .svco = 3, .spd = 1, .scr = 0, .sbs = 3, .gc3 = 3},
379 { .lomax = 520000000, .svco = 0, .spd = 0, .scr = 0, .sbs = 3, .gc3 = 1},
380 { .lomax = 538000000, .svco = 0, .spd = 0, .scr = 1, .sbs = 3, .gc3 = 1},
381 { .lomax = 554000000, .svco = 1, .spd = 0, .scr = 0, .sbs = 3, .gc3 = 1},
382 { .lomax = 620000000, .svco = 1, .spd = 0, .scr = 0, .sbs = 4, .gc3 = 0},
383 { .lomax = 650000000, .svco = 1, .spd = 0, .scr = 1, .sbs = 4, .gc3 = 0},
384 { .lomax = 700000000, .svco = 2, .spd = 0, .scr = 0, .sbs = 4, .gc3 = 0},
385 { .lomax = 780000000, .svco = 2, .spd = 0, .scr = 1, .sbs = 4, .gc3 = 0},
386 { .lomax = 820000000, .svco = 3, .spd = 0, .scr = 0, .sbs = 4, .gc3 = 0},
387 { .lomax = 870000000, .svco = 3, .spd = 0, .scr = 1, .sbs = 4, .gc3 = 0},
388 { .lomax = 911000000, .svco = 3, .spd = 0, .scr = 2, .sbs = 4, .gc3 = 0},
389 { .lomax = 0, .svco = 0, .spd = 0, .scr = 0, .sbs = 0, .gc3 = 0}
390};
391
392static int tda827xa_sleep(struct dvb_frontend *fe)
393{
394 struct tda827x_priv *priv = fe->tuner_priv;
395 static u8 buf[] = { 0x30, 0x90 };
396 struct i2c_msg msg = { .addr = priv->i2c_addr, .flags = 0,
397 .buf = buf, .len = sizeof(buf) };
398
399 dprintk("%s:\n", __func__);
400 if (fe->ops.i2c_gate_ctrl)
401 fe->ops.i2c_gate_ctrl(fe, 1);
402
403 i2c_transfer(priv->i2c_adap, &msg, 1);
404
405 if (fe->ops.i2c_gate_ctrl)
406 fe->ops.i2c_gate_ctrl(fe, 0);
407
408 if (priv->cfg && priv->cfg->sleep)
409 priv->cfg->sleep(fe);
410
411 return 0;
412}
413
414static void tda827xa_lna_gain(struct dvb_frontend *fe, int high,
415 struct analog_parameters *params)
416{
417 struct tda827x_priv *priv = fe->tuner_priv;
418 unsigned char buf[] = {0x22, 0x01};
419 int arg;
420 int gp_func;
421 struct i2c_msg msg = { .addr = priv->cfg->switch_addr, .flags = 0,
422 .buf = buf, .len = sizeof(buf) };
423
424 if (NULL == priv->cfg) {
425 dprintk("tda827x_config not defined, cannot set LNA gain!\n");
426 return;
427 }
428 if (priv->cfg->config) {
429 if (high)
430 dprintk("setting LNA to high gain\n");
431 else
432 dprintk("setting LNA to low gain\n");
433 }
434 switch (priv->cfg->config) {
435 case 0: /* no LNA */
436 break;
437 case 1: /* switch is GPIO 0 of tda8290 */
438 case 2:
439 if (params == NULL) {
440 gp_func = 0;
441 arg = 0;
442 } else {
443 /* turn Vsync on */
444 gp_func = 1;
445 if (params->std & V4L2_STD_MN)
446 arg = 1;
447 else
448 arg = 0;
449 }
450 if (priv->cfg->tuner_callback)
451 priv->cfg->tuner_callback(priv->i2c_adap->algo_data,
452 gp_func, arg);
453 buf[1] = high ? 0 : 1;
454 if (priv->cfg->config == 2)
455 buf[1] = high ? 1 : 0;
456 i2c_transfer(priv->i2c_adap, &msg, 1);
457 break;
458 case 3: /* switch with GPIO of saa713x */
459 if (priv->cfg->tuner_callback)
460 priv->cfg->tuner_callback(priv->i2c_adap->algo_data, 0, high);
461 break;
462 }
463}
464
465static int tda827xa_set_params(struct dvb_frontend *fe,
466 struct dvb_frontend_parameters *params)
467{
468 struct tda827x_priv *priv = fe->tuner_priv;
469 u8 buf[11];
470
471 struct i2c_msg msg = { .addr = priv->i2c_addr, .flags = 0,
472 .buf = buf, .len = sizeof(buf) };
473
474 int i, tuner_freq, if_freq;
475 u32 N;
476
477 dprintk("%s:\n", __func__);
478
479 tda827xa_lna_gain(fe, 1, NULL);
480 msleep(20);
481
482 switch (params->u.ofdm.bandwidth) {
483 case BANDWIDTH_6_MHZ:
484 if_freq = 4000000;
485 break;
486 case BANDWIDTH_7_MHZ:
487 if_freq = 4500000;
488 break;
489 default: /* 8 MHz or Auto */
490 if_freq = 5000000;
491 break;
492 }
493 tuner_freq = params->frequency + if_freq;
494
495 i = 0;
496 while (tda827xa_dvbt[i].lomax < tuner_freq) {
497 if(tda827xa_dvbt[i + 1].lomax == 0)
498 break;
499 i++;
500 }
501
502 N = ((tuner_freq + 31250) / 62500) << tda827xa_dvbt[i].spd;
503 buf[0] = 0; // subaddress
504 buf[1] = N >> 8;
505 buf[2] = N & 0xff;
506 buf[3] = 0;
507 buf[4] = 0x16;
508 buf[5] = (tda827xa_dvbt[i].spd << 5) + (tda827xa_dvbt[i].svco << 3) +
509 tda827xa_dvbt[i].sbs;
510 buf[6] = 0x4b + (tda827xa_dvbt[i].gc3 << 4);
511 buf[7] = 0x1c;
512 buf[8] = 0x06;
513 buf[9] = 0x24;
514 buf[10] = 0x00;
515 msg.len = 11;
516 if (fe->ops.i2c_gate_ctrl)
517 fe->ops.i2c_gate_ctrl(fe, 1);
518 if (i2c_transfer(priv->i2c_adap, &msg, 1) != 1) {
519 printk("%s: could not write to tuner at addr: 0x%02x\n",
520 __func__, priv->i2c_addr << 1);
521 return -EIO;
522 }
523 buf[0] = 0x90;
524 buf[1] = 0xff;
525 buf[2] = 0x60;
526 buf[3] = 0x00;
527 buf[4] = 0x59; // lpsel, for 6MHz + 2
528 msg.len = 5;
529 if (fe->ops.i2c_gate_ctrl)
530 fe->ops.i2c_gate_ctrl(fe, 1);
531 i2c_transfer(priv->i2c_adap, &msg, 1);
532
533 buf[0] = 0xa0;
534 buf[1] = 0x40;
535 msg.len = 2;
536 if (fe->ops.i2c_gate_ctrl)
537 fe->ops.i2c_gate_ctrl(fe, 1);
538 i2c_transfer(priv->i2c_adap, &msg, 1);
539
540 msleep(11);
541 msg.flags = I2C_M_RD;
542 if (fe->ops.i2c_gate_ctrl)
543 fe->ops.i2c_gate_ctrl(fe, 1);
544 i2c_transfer(priv->i2c_adap, &msg, 1);
545 msg.flags = 0;
546
547 buf[1] >>= 4;
548 dprintk("tda8275a AGC2 gain is: %d\n", buf[1]);
549 if ((buf[1]) < 2) {
550 tda827xa_lna_gain(fe, 0, NULL);
551 buf[0] = 0x60;
552 buf[1] = 0x0c;
553 if (fe->ops.i2c_gate_ctrl)
554 fe->ops.i2c_gate_ctrl(fe, 1);
555 i2c_transfer(priv->i2c_adap, &msg, 1);
556 }
557
558 buf[0] = 0xc0;
559 buf[1] = 0x99; // lpsel, for 6MHz + 2
560 if (fe->ops.i2c_gate_ctrl)
561 fe->ops.i2c_gate_ctrl(fe, 1);
562 i2c_transfer(priv->i2c_adap, &msg, 1);
563
564 buf[0] = 0x60;
565 buf[1] = 0x3c;
566 if (fe->ops.i2c_gate_ctrl)
567 fe->ops.i2c_gate_ctrl(fe, 1);
568 i2c_transfer(priv->i2c_adap, &msg, 1);
569
570 /* correct CP value */
571 buf[0] = 0x30;
572 buf[1] = 0x10 + tda827xa_dvbt[i].scr;
573 if (fe->ops.i2c_gate_ctrl)
574 fe->ops.i2c_gate_ctrl(fe, 1);
575 i2c_transfer(priv->i2c_adap, &msg, 1);
576
577 msleep(163);
578 buf[0] = 0xc0;
579 buf[1] = 0x39; // lpsel, for 6MHz + 2
580 if (fe->ops.i2c_gate_ctrl)
581 fe->ops.i2c_gate_ctrl(fe, 1);
582 i2c_transfer(priv->i2c_adap, &msg, 1);
583
584 msleep(3);
585 /* freeze AGC1 */
586 buf[0] = 0x50;
587 buf[1] = 0x4f + (tda827xa_dvbt[i].gc3 << 4);
588 if (fe->ops.i2c_gate_ctrl)
589 fe->ops.i2c_gate_ctrl(fe, 1);
590 i2c_transfer(priv->i2c_adap, &msg, 1);
591
592 priv->frequency = tuner_freq - if_freq; // FIXME
593 priv->bandwidth = (fe->ops.info.type == FE_OFDM) ? params->u.ofdm.bandwidth : 0;
594
595 return 0;
596}
597
598
599static int tda827xa_set_analog_params(struct dvb_frontend *fe,
600 struct analog_parameters *params)
601{
602 unsigned char tuner_reg[11];
603 u32 N;
604 int i;
605 struct tda827x_priv *priv = fe->tuner_priv;
606 struct i2c_msg msg = { .addr = priv->i2c_addr, .flags = 0,
607 .buf = tuner_reg, .len = sizeof(tuner_reg) };
608 unsigned int freq = params->frequency;
609
610 tda827x_set_std(fe, params);
611
612 tda827xa_lna_gain(fe, 1, params);
613 msleep(10);
614
615 if (params->mode == V4L2_TUNER_RADIO)
616 freq = freq / 1000;
617
618 N = freq + priv->sgIF;
619
620 i = 0;
621 while (tda827xa_analog[i].lomax < N * 62500) {
622 if (tda827xa_analog[i + 1].lomax == 0)
623 break;
624 i++;
625 }
626
627 N = N << tda827xa_analog[i].spd;
628
629 tuner_reg[0] = 0;
630 tuner_reg[1] = (unsigned char)(N>>8);
631 tuner_reg[2] = (unsigned char) N;
632 tuner_reg[3] = 0;
633 tuner_reg[4] = 0x16;
634 tuner_reg[5] = (tda827xa_analog[i].spd << 5) +
635 (tda827xa_analog[i].svco << 3) +
636 tda827xa_analog[i].sbs;
637 tuner_reg[6] = 0x8b + (tda827xa_analog[i].gc3 << 4);
638 tuner_reg[7] = 0x1c;
639 tuner_reg[8] = 4;
640 tuner_reg[9] = 0x20;
641 tuner_reg[10] = 0x00;
642 msg.len = 11;
643 i2c_transfer(priv->i2c_adap, &msg, 1);
644
645 tuner_reg[0] = 0x90;
646 tuner_reg[1] = 0xff;
647 tuner_reg[2] = 0xe0;
648 tuner_reg[3] = 0;
649 tuner_reg[4] = 0x99 + (priv->lpsel << 1);
650 msg.len = 5;
651 i2c_transfer(priv->i2c_adap, &msg, 1);
652
653 tuner_reg[0] = 0xa0;
654 tuner_reg[1] = 0xc0;
655 msg.len = 2;
656 i2c_transfer(priv->i2c_adap, &msg, 1);
657
658 tuner_reg[0] = 0x30;
659 tuner_reg[1] = 0x10 + tda827xa_analog[i].scr;
660 i2c_transfer(priv->i2c_adap, &msg, 1);
661
662 msg.flags = I2C_M_RD;
663 i2c_transfer(priv->i2c_adap, &msg, 1);
664 msg.flags = 0;
665 tuner_reg[1] >>= 4;
666 dprintk("AGC2 gain is: %d\n", tuner_reg[1]);
667 if (tuner_reg[1] < 1)
668 tda827xa_lna_gain(fe, 0, params);
669
670 msleep(100);
671 tuner_reg[0] = 0x60;
672 tuner_reg[1] = 0x3c;
673 i2c_transfer(priv->i2c_adap, &msg, 1);
674
675 msleep(163);
676 tuner_reg[0] = 0x50;
677 tuner_reg[1] = 0x8f + (tda827xa_analog[i].gc3 << 4);
678 i2c_transfer(priv->i2c_adap, &msg, 1);
679
680 tuner_reg[0] = 0x80;
681 tuner_reg[1] = 0x28;
682 i2c_transfer(priv->i2c_adap, &msg, 1);
683
684 tuner_reg[0] = 0xb0;
685 tuner_reg[1] = 0x01;
686 i2c_transfer(priv->i2c_adap, &msg, 1);
687
688 tuner_reg[0] = 0xc0;
689 tuner_reg[1] = 0x19 + (priv->lpsel << 1);
690 i2c_transfer(priv->i2c_adap, &msg, 1);
691
692 priv->frequency = freq * 62500;
693
694 return 0;
695}
696
697static void tda827xa_agcf(struct dvb_frontend *fe)
698{
699 struct tda827x_priv *priv = fe->tuner_priv;
700 unsigned char data[] = {0x80, 0x2c};
701 struct i2c_msg msg = {.addr = priv->i2c_addr, .flags = 0,
702 .buf = data, .len = 2};
703 i2c_transfer(priv->i2c_adap, &msg, 1);
704}
705
706/* ------------------------------------------------------------------ */
707
708static int tda827x_release(struct dvb_frontend *fe)
709{
710 kfree(fe->tuner_priv);
711 fe->tuner_priv = NULL;
712 return 0;
713}
714
715static int tda827x_get_frequency(struct dvb_frontend *fe, u32 *frequency)
716{
717 struct tda827x_priv *priv = fe->tuner_priv;
718 *frequency = priv->frequency;
719 return 0;
720}
721
722static int tda827x_get_bandwidth(struct dvb_frontend *fe, u32 *bandwidth)
723{
724 struct tda827x_priv *priv = fe->tuner_priv;
725 *bandwidth = priv->bandwidth;
726 return 0;
727}
728
729static int tda827x_init(struct dvb_frontend *fe)
730{
731 struct tda827x_priv *priv = fe->tuner_priv;
732 dprintk("%s:\n", __func__);
733 if (priv->cfg && priv->cfg->init)
734 priv->cfg->init(fe);
735
736 return 0;
737}
738
739static int tda827x_probe_version(struct dvb_frontend *fe);
740
741static int tda827x_initial_init(struct dvb_frontend *fe)
742{
743 int ret;
744 ret = tda827x_probe_version(fe);
745 if (ret)
746 return ret;
747 return fe->ops.tuner_ops.init(fe);
748}
749
750static int tda827x_initial_sleep(struct dvb_frontend *fe)
751{
752 int ret;
753 ret = tda827x_probe_version(fe);
754 if (ret)
755 return ret;
756 return fe->ops.tuner_ops.sleep(fe);
757}
758
759static struct dvb_tuner_ops tda827xo_tuner_ops = {
760 .info = {
761 .name = "Philips TDA827X",
762 .frequency_min = 55000000,
763 .frequency_max = 860000000,
764 .frequency_step = 250000
765 },
766 .release = tda827x_release,
767 .init = tda827x_initial_init,
768 .sleep = tda827x_initial_sleep,
769 .set_params = tda827xo_set_params,
770 .set_analog_params = tda827xo_set_analog_params,
771 .get_frequency = tda827x_get_frequency,
772 .get_bandwidth = tda827x_get_bandwidth,
773};
774
775static struct dvb_tuner_ops tda827xa_tuner_ops = {
776 .info = {
777 .name = "Philips TDA827XA",
778 .frequency_min = 44000000,
779 .frequency_max = 906000000,
780 .frequency_step = 62500
781 },
782 .release = tda827x_release,
783 .init = tda827x_init,
784 .sleep = tda827xa_sleep,
785 .set_params = tda827xa_set_params,
786 .set_analog_params = tda827xa_set_analog_params,
787 .get_frequency = tda827x_get_frequency,
788 .get_bandwidth = tda827x_get_bandwidth,
789};
790
791static int tda827x_probe_version(struct dvb_frontend *fe)
792{ u8 data;
793 struct tda827x_priv *priv = fe->tuner_priv;
794 struct i2c_msg msg = { .addr = priv->i2c_addr, .flags = I2C_M_RD,
795 .buf = &data, .len = 1 };
796 if (fe->ops.i2c_gate_ctrl)
797 fe->ops.i2c_gate_ctrl(fe, 1);
798 if (i2c_transfer(priv->i2c_adap, &msg, 1) != 1) {
799 printk("%s: could not read from tuner at addr: 0x%02x\n",
800 __func__, msg.addr << 1);
801 return -EIO;
802 }
803 if ((data & 0x3c) == 0) {
804 dprintk("tda827x tuner found\n");
805 fe->ops.tuner_ops.init = tda827x_init;
806 fe->ops.tuner_ops.sleep = tda827xo_sleep;
807 if (priv->cfg)
808 priv->cfg->agcf = tda827xo_agcf;
809 } else {
810 dprintk("tda827xa tuner found\n");
811 memcpy(&fe->ops.tuner_ops, &tda827xa_tuner_ops, sizeof(struct dvb_tuner_ops));
812 if (priv->cfg)
813 priv->cfg->agcf = tda827xa_agcf;
814 }
815 return 0;
816}
817
818struct dvb_frontend *tda827x_attach(struct dvb_frontend *fe, int addr,
819 struct i2c_adapter *i2c,
820 struct tda827x_config *cfg)
821{
822 struct tda827x_priv *priv = NULL;
823
824 dprintk("%s:\n", __func__);
825 priv = kzalloc(sizeof(struct tda827x_priv), GFP_KERNEL);
826 if (priv == NULL)
827 return NULL;
828
829 priv->i2c_addr = addr;
830 priv->i2c_adap = i2c;
831 priv->cfg = cfg;
832 memcpy(&fe->ops.tuner_ops, &tda827xo_tuner_ops, sizeof(struct dvb_tuner_ops));
833 fe->tuner_priv = priv;
834
835 dprintk("type set to %s\n", fe->ops.tuner_ops.info.name);
836
837 return fe;
838}
839EXPORT_SYMBOL_GPL(tda827x_attach);
840
841MODULE_DESCRIPTION("DVB TDA827x driver");
842MODULE_AUTHOR("Hartmut Hackmann <hartmut.hackmann@t-online.de>");
843MODULE_AUTHOR("Michael Krufky <mkrufky@linuxtv.org>");
844MODULE_LICENSE("GPL");
845
846/*
847 * Overrides for Emacs so that we follow Linus's tabbing style.
848 * ---------------------------------------------------------------------------
849 * Local variables:
850 * c-basic-offset: 8
851 * End:
852 */