aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/video/tda8290.c
diff options
context:
space:
mode:
authorMichael Krufky <mkrufky@linuxtv.org>2007-08-25 18:08:45 -0400
committerMauro Carvalho Chehab <mchehab@infradead.org>2008-01-25 16:01:05 -0500
commit746d9732dbd5b95c3ba36230e2814fa2c391a311 (patch)
treebb63bc3eeea67bedd6b92727280ea8a35d5656b5 /drivers/media/video/tda8290.c
parentde3fe21ba2fdc0733ad4e555b95121baeba7fcd5 (diff)
V4L/DVB (6433): Move all tda8275/8275a tuning code from tda8290 module into tda827x module
Add analog tuning support to tda827x dvb_frontend tuner module. Convert tda8290 module back to native tuner interface. The tda8290 analog demodulator will be handled the same way as tda9887. The tuner.ko module (tuner-core) will pass commands to tda8290 via the tuner_operations interface. tda8290 will communicate with tda827x via the dvb_frontend interface, while passing a pointer to a private data structure. Signed-off-by: Michael Krufky <mkrufky@linuxtv.org> Reviewed-by: Hans Verkuil <hverkuil@xs4all.nl> Signed-off-by: Mauro Carvalho Chehab <mchehab@infradead.org>
Diffstat (limited to 'drivers/media/video/tda8290.c')
-rw-r--r--drivers/media/video/tda8290.c566
1 files changed, 106 insertions, 460 deletions
diff --git a/drivers/media/video/tda8290.c b/drivers/media/video/tda8290.c
index 0e5cf459d3ed..5d30cbcd7361 100644
--- a/drivers/media/video/tda8290.c
+++ b/drivers/media/video/tda8290.c
@@ -23,11 +23,11 @@
23#include <linux/i2c.h> 23#include <linux/i2c.h>
24#include <linux/delay.h> 24#include <linux/delay.h>
25#include <linux/videodev.h> 25#include <linux/videodev.h>
26#include "tuner-i2c.h"
27#include "tda8290.h" 26#include "tda8290.h"
27#include "tda827x.h"
28 28
29static int debug = 0; 29static int tuner_debug = 0;
30module_param(debug, int, 0644); 30module_param_named(debug, tuner_debug, int, 0644);
31MODULE_PARM_DESC(debug, "enable verbose debug messages"); 31MODULE_PARM_DESC(debug, "enable verbose debug messages");
32 32
33#define PREFIX "tda8290 " 33#define PREFIX "tda8290 "
@@ -38,332 +38,18 @@ struct tda8290_priv {
38 struct tuner_i2c_props i2c_props; 38 struct tuner_i2c_props i2c_props;
39 39
40 unsigned char tda8290_easy_mode; 40 unsigned char tda8290_easy_mode;
41 unsigned char tda827x_lpsel; 41
42 unsigned char tda827x_addr; 42 unsigned char tda827x_addr;
43 unsigned char tda827x_ver; 43 unsigned char tda827x_ver;
44 unsigned int sgIF;
45
46 u32 frequency;
47
48 unsigned int *lna_cfg;
49 int (*tuner_callback) (void *dev, int command,int arg);
50};
51
52/* ---------------------------------------------------------------------- */
53
54struct tda827x_data {
55 u32 lomax;
56 u8 spd;
57 u8 bs;
58 u8 bp;
59 u8 cp;
60 u8 gc3;
61 u8 div1p5;
62};
63 44
64 /* Note lomax entry is lo / 62500 */ 45 struct tda827x_config cfg;
65
66static struct tda827x_data tda827x_analog[] = {
67 { .lomax = 992, .spd = 3, .bs = 2, .bp = 0, .cp = 0, .gc3 = 3, .div1p5 = 1}, /* 62 MHz */
68 { .lomax = 1056, .spd = 3, .bs = 3, .bp = 0, .cp = 0, .gc3 = 3, .div1p5 = 1}, /* 66 MHz */
69 { .lomax = 1216, .spd = 3, .bs = 1, .bp = 0, .cp = 0, .gc3 = 3, .div1p5 = 0}, /* 76 MHz */
70 { .lomax = 1344, .spd = 3, .bs = 2, .bp = 0, .cp = 0, .gc3 = 3, .div1p5 = 0}, /* 84 MHz */
71 { .lomax = 1488, .spd = 3, .bs = 2, .bp = 0, .cp = 0, .gc3 = 1, .div1p5 = 0}, /* 93 MHz */
72 { .lomax = 1568, .spd = 3, .bs = 3, .bp = 0, .cp = 0, .gc3 = 1, .div1p5 = 0}, /* 98 MHz */
73 { .lomax = 1744, .spd = 3, .bs = 3, .bp = 1, .cp = 0, .gc3 = 1, .div1p5 = 0}, /* 109 MHz */
74 { .lomax = 1968, .spd = 2, .bs = 2, .bp = 1, .cp = 0, .gc3 = 1, .div1p5 = 1}, /* 123 MHz */
75 { .lomax = 2128, .spd = 2, .bs = 3, .bp = 1, .cp = 0, .gc3 = 1, .div1p5 = 1}, /* 133 MHz */
76 { .lomax = 2416, .spd = 2, .bs = 1, .bp = 1, .cp = 0, .gc3 = 1, .div1p5 = 0}, /* 151 MHz */
77 { .lomax = 2464, .spd = 2, .bs = 2, .bp = 1, .cp = 0, .gc3 = 1, .div1p5 = 0}, /* 154 MHz */
78 { .lomax = 2896, .spd = 2, .bs = 2, .bp = 1, .cp = 0, .gc3 = 0, .div1p5 = 0}, /* 181 MHz */
79 { .lomax = 2960, .spd = 2, .bs = 2, .bp = 2, .cp = 0, .gc3 = 1, .div1p5 = 0}, /* 185 MHz */
80 { .lomax = 3472, .spd = 2, .bs = 3, .bp = 2, .cp = 0, .gc3 = 1, .div1p5 = 0}, /* 217 MHz */
81 { .lomax = 3904, .spd = 1, .bs = 2, .bp = 2, .cp = 0, .gc3 = 1, .div1p5 = 1}, /* 244 MHz */
82 { .lomax = 4240, .spd = 1, .bs = 3, .bp = 2, .cp = 0, .gc3 = 1, .div1p5 = 1}, /* 265 MHz */
83 { .lomax = 4832, .spd = 1, .bs = 1, .bp = 2, .cp = 0, .gc3 = 1, .div1p5 = 0}, /* 302 MHz */
84 { .lomax = 5184, .spd = 1, .bs = 2, .bp = 2, .cp = 0, .gc3 = 1, .div1p5 = 0}, /* 324 MHz */
85 { .lomax = 5920, .spd = 1, .bs = 2, .bp = 3, .cp = 0, .gc3 = 1, .div1p5 = 0}, /* 370 MHz */
86 { .lomax = 7264, .spd = 1, .bs = 3, .bp = 3, .cp = 0, .gc3 = 1, .div1p5 = 0}, /* 454 MHz */
87 { .lomax = 7888, .spd = 0, .bs = 2, .bp = 3, .cp = 0, .gc3 = 1, .div1p5 = 1}, /* 493 MHz */
88 { .lomax = 8480, .spd = 0, .bs = 3, .bp = 3, .cp = 0, .gc3 = 1, .div1p5 = 1}, /* 530 MHz */
89 { .lomax = 8864, .spd = 0, .bs = 1, .bp = 3, .cp = 0, .gc3 = 1, .div1p5 = 0}, /* 554 MHz */
90 { .lomax = 9664, .spd = 0, .bs = 1, .bp = 4, .cp = 0, .gc3 = 0, .div1p5 = 0}, /* 604 MHz */
91 { .lomax = 11088, .spd = 0, .bs = 2, .bp = 4, .cp = 0, .gc3 = 0, .div1p5 = 0}, /* 696 MHz */
92 { .lomax = 11840, .spd = 0, .bs = 2, .bp = 4, .cp = 1, .gc3 = 0, .div1p5 = 0}, /* 740 MHz */
93 { .lomax = 13120, .spd = 0, .bs = 3, .bp = 4, .cp = 0, .gc3 = 0, .div1p5 = 0}, /* 820 MHz */
94 { .lomax = 13840, .spd = 0, .bs = 3, .bp = 4, .cp = 1, .gc3 = 0, .div1p5 = 0}, /* 865 MHz */
95 { .lomax = 0, .spd = 0, .bs = 0, .bp = 0, .cp = 0, .gc3 = 0, .div1p5 = 0} /* End */
96}; 46};
97 47
98static void tda827x_set_analog_params(struct dvb_frontend *fe,
99 struct analog_parameters *params)
100{
101 unsigned char tuner_reg[8];
102 unsigned char reg2[2];
103 u32 N;
104 int i;
105 struct tda8290_priv *priv = fe->tuner_priv;
106 struct i2c_msg msg = {.addr = priv->tda827x_addr, .flags = 0};
107 unsigned int freq = params->frequency;
108
109 if (params->mode == V4L2_TUNER_RADIO)
110 freq = freq / 1000;
111
112 N = freq + priv->sgIF;
113 i = 0;
114 while (tda827x_analog[i].lomax < N) {
115 if(tda827x_analog[i + 1].lomax == 0)
116 break;
117 i++;
118 }
119
120 N = N << tda827x_analog[i].spd;
121
122 tuner_reg[0] = 0;
123 tuner_reg[1] = (unsigned char)(N>>8);
124 tuner_reg[2] = (unsigned char) N;
125 tuner_reg[3] = 0x40;
126 tuner_reg[4] = 0x52 + (priv->tda827x_lpsel << 5);
127 tuner_reg[5] = (tda827x_analog[i].spd << 6) + (tda827x_analog[i].div1p5 <<5) +
128 (tda827x_analog[i].bs <<3) + tda827x_analog[i].bp;
129 tuner_reg[6] = 0x8f + (tda827x_analog[i].gc3 << 4);
130 tuner_reg[7] = 0x8f;
131
132 msg.buf = tuner_reg;
133 msg.len = 8;
134 i2c_transfer(priv->i2c_props.adap, &msg, 1);
135
136 msg.buf= reg2;
137 msg.len = 2;
138 reg2[0] = 0x80;
139 reg2[1] = 0;
140 i2c_transfer(priv->i2c_props.adap, &msg, 1);
141
142 reg2[0] = 0x60;
143 reg2[1] = 0xbf;
144 i2c_transfer(priv->i2c_props.adap, &msg, 1);
145
146 reg2[0] = 0x30;
147 reg2[1] = tuner_reg[4] + 0x80;
148 i2c_transfer(priv->i2c_props.adap, &msg, 1);
149
150 msleep(1);
151 reg2[0] = 0x30;
152 reg2[1] = tuner_reg[4] + 4;
153 i2c_transfer(priv->i2c_props.adap, &msg, 1);
154
155 msleep(1);
156 reg2[0] = 0x30;
157 reg2[1] = tuner_reg[4];
158 i2c_transfer(priv->i2c_props.adap, &msg, 1);
159
160 msleep(550);
161 reg2[0] = 0x30;
162 reg2[1] = (tuner_reg[4] & 0xfc) + tda827x_analog[i].cp ;
163 i2c_transfer(priv->i2c_props.adap, &msg, 1);
164
165 reg2[0] = 0x60;
166 reg2[1] = 0x3f;
167 i2c_transfer(priv->i2c_props.adap, &msg, 1);
168
169 reg2[0] = 0x80;
170 reg2[1] = 0x08; // Vsync en
171 i2c_transfer(priv->i2c_props.adap, &msg, 1);
172}
173
174static void tda827x_agcf(struct dvb_frontend *fe)
175{
176 struct tda8290_priv *priv = fe->tuner_priv;
177 unsigned char data[] = {0x80, 0x0c};
178 struct i2c_msg msg = {.addr = priv->tda827x_addr, .buf = data,
179 .flags = 0, .len = 2};
180 i2c_transfer(priv->i2c_props.adap, &msg, 1);
181}
182
183/* ---------------------------------------------------------------------- */
184
185struct tda827xa_data {
186 u32 lomax;
187 u8 svco;
188 u8 spd;
189 u8 scr;
190 u8 sbs;
191 u8 gc3;
192};
193
194static struct tda827xa_data tda827xa_analog[] = {
195 { .lomax = 910, .svco = 3, .spd = 4, .scr = 0, .sbs = 0, .gc3 = 3}, /* 56.875 MHz */
196 { .lomax = 1076, .svco = 0, .spd = 3, .scr = 0, .sbs = 0, .gc3 = 3}, /* 67.25 MHz */
197 { .lomax = 1300, .svco = 1, .spd = 3, .scr = 0, .sbs = 0, .gc3 = 3}, /* 81.25 MHz */
198 { .lomax = 1560, .svco = 2, .spd = 3, .scr = 0, .sbs = 0, .gc3 = 3}, /* 97.5 MHz */
199 { .lomax = 1820, .svco = 3, .spd = 3, .scr = 0, .sbs = 1, .gc3 = 1}, /* 113.75 MHz */
200 { .lomax = 2152, .svco = 0, .spd = 2, .scr = 0, .sbs = 1, .gc3 = 1}, /* 134.5 MHz */
201 { .lomax = 2464, .svco = 1, .spd = 2, .scr = 0, .sbs = 1, .gc3 = 1}, /* 154 MHz */
202 { .lomax = 2600, .svco = 1, .spd = 2, .scr = 0, .sbs = 1, .gc3 = 1}, /* 162.5 MHz */
203 { .lomax = 2928, .svco = 2, .spd = 2, .scr = 0, .sbs = 1, .gc3 = 1}, /* 183 MHz */
204 { .lomax = 3120, .svco = 2, .spd = 2, .scr = 0, .sbs = 2, .gc3 = 1}, /* 195 MHz */
205 { .lomax = 3640, .svco = 3, .spd = 2, .scr = 0, .sbs = 2, .gc3 = 3}, /* 227.5 MHz */
206 { .lomax = 4304, .svco = 0, .spd = 1, .scr = 0, .sbs = 2, .gc3 = 3}, /* 269 MHz */
207 { .lomax = 5200, .svco = 1, .spd = 1, .scr = 0, .sbs = 2, .gc3 = 1}, /* 325 MHz */
208 { .lomax = 6240, .svco = 2, .spd = 1, .scr = 0, .sbs = 3, .gc3 = 3}, /* 390 MHz */
209 { .lomax = 7280, .svco = 3, .spd = 1, .scr = 0, .sbs = 3, .gc3 = 3}, /* 455 MHz */
210 { .lomax = 8320, .svco = 0, .spd = 0, .scr = 0, .sbs = 3, .gc3 = 1}, /* 520 MHz */
211 { .lomax = 8608, .svco = 0, .spd = 0, .scr = 1, .sbs = 3, .gc3 = 1}, /* 538 MHz */
212 { .lomax = 8864, .svco = 1, .spd = 0, .scr = 0, .sbs = 3, .gc3 = 1}, /* 554 MHz */
213 { .lomax = 9920, .svco = 1, .spd = 0, .scr = 0, .sbs = 4, .gc3 = 0}, /* 620 MHz */
214 { .lomax = 10400, .svco = 1, .spd = 0, .scr = 1, .sbs = 4, .gc3 = 0}, /* 650 MHz */
215 { .lomax = 11200, .svco = 2, .spd = 0, .scr = 0, .sbs = 4, .gc3 = 0}, /* 700 MHz */
216 { .lomax = 12480, .svco = 2, .spd = 0, .scr = 1, .sbs = 4, .gc3 = 0}, /* 780 MHz */
217 { .lomax = 13120, .svco = 3, .spd = 0, .scr = 0, .sbs = 4, .gc3 = 0}, /* 820 MHz */
218 { .lomax = 13920, .svco = 3, .spd = 0, .scr = 1, .sbs = 4, .gc3 = 0}, /* 870 MHz */
219 { .lomax = 14576, .svco = 3, .spd = 0, .scr = 2, .sbs = 4, .gc3 = 0}, /* 911 MHz */
220 { .lomax = 0, .svco = 0, .spd = 0, .scr = 0, .sbs = 0, .gc3 = 0} /* End */
221};
222
223static void tda827xa_lna_gain(struct dvb_frontend *fe, int high,
224 struct analog_parameters *params)
225{
226 struct tda8290_priv *priv = fe->tuner_priv;
227 unsigned char buf[] = {0x22, 0x01};
228 int arg;
229 struct i2c_msg msg = {.addr = priv->i2c_props.addr, .flags = 0, .buf = buf, .len = sizeof(buf)};
230
231 if ((priv->lna_cfg == NULL) || (priv->tuner_callback == NULL))
232 return;
233
234 if (*priv->lna_cfg) {
235 if (high)
236 tuner_dbg("setting LNA to high gain\n");
237 else
238 tuner_dbg("setting LNA to low gain\n");
239 }
240 switch (*priv->lna_cfg) {
241 case 0: /* no LNA */
242 break;
243 case 1: /* switch is GPIO 0 of tda8290 */
244 case 2:
245 /* turn Vsync on */
246 if (params->std & V4L2_STD_MN)
247 arg = 1;
248 else
249 arg = 0;
250 if (priv->tuner_callback)
251 priv->tuner_callback(priv->i2c_props.adap->algo_data, 1, arg);
252 buf[1] = high ? 0 : 1;
253 if (*priv->lna_cfg == 2)
254 buf[1] = high ? 1 : 0;
255 i2c_transfer(priv->i2c_props.adap, &msg, 1);
256 break;
257 case 3: /* switch with GPIO of saa713x */
258 if (priv->tuner_callback)
259 priv->tuner_callback(priv->i2c_props.adap->algo_data, 0, high);
260 break;
261 }
262}
263
264static void tda827xa_set_analog_params(struct dvb_frontend *fe,
265 struct analog_parameters *params)
266{
267 unsigned char tuner_reg[11];
268 u32 N;
269 int i;
270 struct tda8290_priv *priv = fe->tuner_priv;
271 struct i2c_msg msg = {.addr = priv->tda827x_addr, .flags = 0, .buf = tuner_reg};
272 unsigned int freq = params->frequency;
273
274 tda827xa_lna_gain(fe, 1, params);
275 msleep(10);
276
277 if (params->mode == V4L2_TUNER_RADIO)
278 freq = freq / 1000;
279
280 N = freq + priv->sgIF;
281 i = 0;
282 while (tda827xa_analog[i].lomax < N) {
283 if(tda827xa_analog[i + 1].lomax == 0)
284 break;
285 i++;
286 }
287
288 N = N << tda827xa_analog[i].spd;
289
290 tuner_reg[0] = 0;
291 tuner_reg[1] = (unsigned char)(N>>8);
292 tuner_reg[2] = (unsigned char) N;
293 tuner_reg[3] = 0;
294 tuner_reg[4] = 0x16;
295 tuner_reg[5] = (tda827xa_analog[i].spd << 5) + (tda827xa_analog[i].svco << 3) +
296 tda827xa_analog[i].sbs;
297 tuner_reg[6] = 0x8b + (tda827xa_analog[i].gc3 << 4);
298 tuner_reg[7] = 0x1c;
299 tuner_reg[8] = 4;
300 tuner_reg[9] = 0x20;
301 tuner_reg[10] = 0x00;
302 msg.len = 11;
303 i2c_transfer(priv->i2c_props.adap, &msg, 1);
304
305 tuner_reg[0] = 0x90;
306 tuner_reg[1] = 0xff;
307 tuner_reg[2] = 0xe0;
308 tuner_reg[3] = 0;
309 tuner_reg[4] = 0x99 + (priv->tda827x_lpsel << 1);
310 msg.len = 5;
311 i2c_transfer(priv->i2c_props.adap, &msg, 1);
312
313 tuner_reg[0] = 0xa0;
314 tuner_reg[1] = 0xc0;
315 msg.len = 2;
316 i2c_transfer(priv->i2c_props.adap, &msg, 1);
317
318 tuner_reg[0] = 0x30;
319 tuner_reg[1] = 0x10 + tda827xa_analog[i].scr;
320 i2c_transfer(priv->i2c_props.adap, &msg, 1);
321
322 msg.flags = I2C_M_RD;
323 i2c_transfer(priv->i2c_props.adap, &msg, 1);
324 msg.flags = 0;
325 tuner_reg[1] >>= 4;
326 tuner_dbg("AGC2 gain is: %d\n", tuner_reg[1]);
327 if (tuner_reg[1] < 1)
328 tda827xa_lna_gain(fe, 0, params);
329
330 msleep(100);
331 tuner_reg[0] = 0x60;
332 tuner_reg[1] = 0x3c;
333 i2c_transfer(priv->i2c_props.adap, &msg, 1);
334
335 msleep(163);
336 tuner_reg[0] = 0x50;
337 tuner_reg[1] = 0x8f + (tda827xa_analog[i].gc3 << 4);
338 i2c_transfer(priv->i2c_props.adap, &msg, 1);
339
340 tuner_reg[0] = 0x80;
341 tuner_reg[1] = 0x28;
342 i2c_transfer(priv->i2c_props.adap, &msg, 1);
343
344 tuner_reg[0] = 0xb0;
345 tuner_reg[1] = 0x01;
346 i2c_transfer(priv->i2c_props.adap, &msg, 1);
347
348 tuner_reg[0] = 0xc0;
349 tuner_reg[1] = 0x19 + (priv->tda827x_lpsel << 1);
350 i2c_transfer(priv->i2c_props.adap, &msg, 1);
351}
352
353static void tda827xa_agcf(struct dvb_frontend *fe)
354{
355 struct tda8290_priv *priv = fe->tuner_priv;
356 unsigned char data[] = {0x80, 0x2c};
357 struct i2c_msg msg = {.addr = priv->tda827x_addr, .buf = data,
358 .flags = 0, .len = 2};
359 i2c_transfer(priv->i2c_props.adap, &msg, 1);
360}
361
362/*---------------------------------------------------------------------*/ 48/*---------------------------------------------------------------------*/
363 49
364static void tda8290_i2c_bridge(struct dvb_frontend *fe, int close) 50static void tda8290_i2c_bridge(struct tuner *t, int close)
365{ 51{
366 struct tda8290_priv *priv = fe->tuner_priv; 52 struct tda8290_priv *priv = t->priv;
367 53
368 unsigned char enable[2] = { 0x21, 0xC0 }; 54 unsigned char enable[2] = { 0x21, 0xC0 };
369 unsigned char disable[2] = { 0x21, 0x00 }; 55 unsigned char disable[2] = { 0x21, 0x00 };
@@ -381,58 +67,56 @@ static void tda8290_i2c_bridge(struct dvb_frontend *fe, int close)
381 67
382/*---------------------------------------------------------------------*/ 68/*---------------------------------------------------------------------*/
383 69
384static void set_audio(struct dvb_frontend *fe, 70static void set_audio(struct tuner *t)
385 struct analog_parameters *params)
386{ 71{
387 struct tda8290_priv *priv = fe->tuner_priv; 72 struct tda8290_priv *priv = t->priv;
388 char* mode; 73 char* mode;
389 74
390 priv->tda827x_lpsel = 0; 75 priv->cfg.tda827x_lpsel = 0;
391 if (params->std & V4L2_STD_MN) { 76 if (t->std & V4L2_STD_MN) {
392 priv->sgIF = 92; 77 priv->cfg.sgIF = 92;
393 priv->tda8290_easy_mode = 0x01; 78 priv->tda8290_easy_mode = 0x01;
394 priv->tda827x_lpsel = 1; 79 priv->cfg.tda827x_lpsel = 1;
395 mode = "MN"; 80 mode = "MN";
396 } else if (params->std & V4L2_STD_B) { 81 } else if (t->std & V4L2_STD_B) {
397 priv->sgIF = 108; 82 priv->cfg.sgIF = 108;
398 priv->tda8290_easy_mode = 0x02; 83 priv->tda8290_easy_mode = 0x02;
399 mode = "B"; 84 mode = "B";
400 } else if (params->std & V4L2_STD_GH) { 85 } else if (t->std & V4L2_STD_GH) {
401 priv->sgIF = 124; 86 priv->cfg.sgIF = 124;
402 priv->tda8290_easy_mode = 0x04; 87 priv->tda8290_easy_mode = 0x04;
403 mode = "GH"; 88 mode = "GH";
404 } else if (params->std & V4L2_STD_PAL_I) { 89 } else if (t->std & V4L2_STD_PAL_I) {
405 priv->sgIF = 124; 90 priv->cfg.sgIF = 124;
406 priv->tda8290_easy_mode = 0x08; 91 priv->tda8290_easy_mode = 0x08;
407 mode = "I"; 92 mode = "I";
408 } else if (params->std & V4L2_STD_DK) { 93 } else if (t->std & V4L2_STD_DK) {
409 priv->sgIF = 124; 94 priv->cfg.sgIF = 124;
410 priv->tda8290_easy_mode = 0x10; 95 priv->tda8290_easy_mode = 0x10;
411 mode = "DK"; 96 mode = "DK";
412 } else if (params->std & V4L2_STD_SECAM_L) { 97 } else if (t->std & V4L2_STD_SECAM_L) {
413 priv->sgIF = 124; 98 priv->cfg.sgIF = 124;
414 priv->tda8290_easy_mode = 0x20; 99 priv->tda8290_easy_mode = 0x20;
415 mode = "L"; 100 mode = "L";
416 } else if (params->std & V4L2_STD_SECAM_LC) { 101 } else if (t->std & V4L2_STD_SECAM_LC) {
417 priv->sgIF = 20; 102 priv->cfg.sgIF = 20;
418 priv->tda8290_easy_mode = 0x40; 103 priv->tda8290_easy_mode = 0x40;
419 mode = "LC"; 104 mode = "LC";
420 } else { 105 } else {
421 priv->sgIF = 124; 106 priv->cfg.sgIF = 124;
422 priv->tda8290_easy_mode = 0x10; 107 priv->tda8290_easy_mode = 0x10;
423 mode = "xx"; 108 mode = "xx";
424 } 109 }
425 110
426 if (params->mode == V4L2_TUNER_RADIO) 111 if (t->mode == V4L2_TUNER_RADIO)
427 priv->sgIF = 88; /* if frequency is 5.5 MHz */ 112 priv->cfg.sgIF = 88; /* if frequency is 5.5 MHz */
428 113
429 tuner_dbg("setting tda8290 to system %s\n", mode); 114 tuner_dbg("setting tda8290 to system %s\n", mode);
430} 115}
431 116
432static int tda8290_set_params(struct dvb_frontend *fe, 117static void tda8290_set_freq(struct tuner *t, unsigned int freq)
433 struct analog_parameters *params)
434{ 118{
435 struct tda8290_priv *priv = fe->tuner_priv; 119 struct tda8290_priv *priv = t->priv;
436 unsigned char soft_reset[] = { 0x00, 0x00 }; 120 unsigned char soft_reset[] = { 0x00, 0x00 };
437 unsigned char easy_mode[] = { 0x01, priv->tda8290_easy_mode }; 121 unsigned char easy_mode[] = { 0x01, priv->tda8290_easy_mode };
438 unsigned char expert_mode[] = { 0x01, 0x80 }; 122 unsigned char expert_mode[] = { 0x01, 0x80 };
@@ -455,10 +139,16 @@ static int tda8290_set_params(struct dvb_frontend *fe,
455 pll_stat; 139 pll_stat;
456 int i; 140 int i;
457 141
458 set_audio(fe, params); 142 struct analog_parameters params = {
143 .frequency = freq,
144 .mode = t->mode,
145 .audmode = t->audmode,
146 .std = t->std
147 };
148
149 set_audio(t);
459 150
460 if (priv->lna_cfg) 151 tuner_dbg("tda827xa config is 0x%02x\n", t->config);
461 tuner_dbg("tda827xa config is 0x%02x\n", *priv->lna_cfg);
462 tuner_i2c_xfer_send(&priv->i2c_props, easy_mode, 2); 152 tuner_i2c_xfer_send(&priv->i2c_props, easy_mode, 2);
463 tuner_i2c_xfer_send(&priv->i2c_props, agc_out_on, 2); 153 tuner_i2c_xfer_send(&priv->i2c_props, agc_out_on, 2);
464 tuner_i2c_xfer_send(&priv->i2c_props, soft_reset, 2); 154 tuner_i2c_xfer_send(&priv->i2c_props, soft_reset, 2);
@@ -474,11 +164,11 @@ static int tda8290_set_params(struct dvb_frontend *fe,
474 tuner_i2c_xfer_send(&priv->i2c_props, adc_head_6, 2); 164 tuner_i2c_xfer_send(&priv->i2c_props, adc_head_6, 2);
475 tuner_i2c_xfer_send(&priv->i2c_props, pll_bw_nom, 2); 165 tuner_i2c_xfer_send(&priv->i2c_props, pll_bw_nom, 2);
476 166
477 tda8290_i2c_bridge(fe, 1); 167 tda8290_i2c_bridge(t, 1);
478 if (priv->tda827x_ver != 0) 168
479 tda827xa_set_analog_params(fe, params); 169 if (t->fe.ops.tuner_ops.set_analog_params)
480 else 170 t->fe.ops.tuner_ops.set_analog_params(&t->fe, &params);
481 tda827x_set_analog_params(fe, params); 171
482 for (i = 0; i < 3; i++) { 172 for (i = 0; i < 3; i++) {
483 tuner_i2c_xfer_send(&priv->i2c_props, &addr_pll_stat, 1); 173 tuner_i2c_xfer_send(&priv->i2c_props, &addr_pll_stat, 1);
484 tuner_i2c_xfer_recv(&priv->i2c_props, &pll_stat, 1); 174 tuner_i2c_xfer_recv(&priv->i2c_props, &pll_stat, 1);
@@ -507,10 +197,8 @@ static int tda8290_set_params(struct dvb_frontend *fe,
507 if ((agc_stat > 115) || !(pll_stat & 0x80)) { 197 if ((agc_stat > 115) || !(pll_stat & 0x80)) {
508 tuner_dbg("adjust gain, step 2. Agc: %d, lock: %d\n", 198 tuner_dbg("adjust gain, step 2. Agc: %d, lock: %d\n",
509 agc_stat, pll_stat & 0x80); 199 agc_stat, pll_stat & 0x80);
510 if (priv->tda827x_ver != 0) 200 if (priv->cfg.agcf)
511 tda827xa_agcf(fe); 201 priv->cfg.agcf(&t->fe);
512 else
513 tda827x_agcf(fe);
514 msleep(100); 202 msleep(100);
515 tuner_i2c_xfer_send(&priv->i2c_props, &addr_agc_stat, 1); 203 tuner_i2c_xfer_send(&priv->i2c_props, &addr_agc_stat, 1);
516 tuner_i2c_xfer_recv(&priv->i2c_props, &agc_stat, 1); 204 tuner_i2c_xfer_recv(&priv->i2c_props, &agc_stat, 1);
@@ -539,94 +227,61 @@ static int tda8290_set_params(struct dvb_frontend *fe,
539 } 227 }
540 } 228 }
541 229
542 tda8290_i2c_bridge(fe, 0); 230 tda8290_i2c_bridge(t, 0);
543 tuner_i2c_xfer_send(&priv->i2c_props, if_agc_set, 2); 231 tuner_i2c_xfer_send(&priv->i2c_props, if_agc_set, 2);
544
545 priv->frequency = (V4L2_TUNER_RADIO == params->mode) ?
546 params->frequency * 125 / 2 : params->frequency * 62500;
547
548 return 0;
549} 232}
550 233
551/*---------------------------------------------------------------------*/ 234/*---------------------------------------------------------------------*/
552 235
553static int tda8290_has_signal(struct dvb_frontend *fe) 236static int tda8290_has_signal(struct tuner *t)
554{ 237{
555 struct tda8290_priv *priv = fe->tuner_priv; 238 struct tda8290_priv *priv = t->priv;
556 int ret;
557 239
558 unsigned char i2c_get_afc[1] = { 0x1B }; 240 unsigned char i2c_get_afc[1] = { 0x1B };
559 unsigned char afc = 0; 241 unsigned char afc = 0;
560 242
561 /* for now, report based on afc status */
562 tuner_i2c_xfer_send(&priv->i2c_props, i2c_get_afc, ARRAY_SIZE(i2c_get_afc)); 243 tuner_i2c_xfer_send(&priv->i2c_props, i2c_get_afc, ARRAY_SIZE(i2c_get_afc));
563 tuner_i2c_xfer_recv(&priv->i2c_props, &afc, 1); 244 tuner_i2c_xfer_recv(&priv->i2c_props, &afc, 1);
564 245 return (afc & 0x80)? 65535:0;
565 ret = (afc & 0x80) ? 65535 : 0;
566
567 tuner_dbg("AFC status: %d\n", ret);
568
569 return ret;
570}
571
572static int tda8290_get_status(struct dvb_frontend *fe, u32 *status)
573{
574 *status = 0;
575
576 if (tda8290_has_signal(fe))
577 *status = TUNER_STATUS_LOCKED;
578
579 return 0;
580}
581
582static int tda8290_get_rf_strength(struct dvb_frontend *fe, u16 *strength)
583{
584 *strength = tda8290_has_signal(fe);
585
586 return 0;
587} 246}
588 247
589/*---------------------------------------------------------------------*/ 248/*---------------------------------------------------------------------*/
590 249
591static int tda8290_standby(struct dvb_frontend *fe) 250static void tda8290_standby(struct tuner *t)
592{ 251{
593 struct tda8290_priv *priv = fe->tuner_priv; 252 struct tda8290_priv *priv = t->priv;
594 unsigned char cb1[] = { 0x30, 0xD0 }; 253 unsigned char cb1[] = { 0x30, 0xD0 };
595 unsigned char tda8290_standby[] = { 0x00, 0x02 }; 254 unsigned char tda8290_standby[] = { 0x00, 0x02 };
596 unsigned char tda8290_agc_tri[] = { 0x02, 0x20 }; 255 unsigned char tda8290_agc_tri[] = { 0x02, 0x20 };
597 struct i2c_msg msg = {.addr = priv->tda827x_addr, .flags=0, .buf=cb1, .len = 2}; 256 struct i2c_msg msg = {.addr = priv->tda827x_addr, .flags=0, .buf=cb1, .len = 2};
598 257
599 tda8290_i2c_bridge(fe, 1); 258 tda8290_i2c_bridge(t, 1);
600 if (priv->tda827x_ver != 0) 259 if (priv->tda827x_ver != 0)
601 cb1[1] = 0x90; 260 cb1[1] = 0x90;
602 i2c_transfer(priv->i2c_props.adap, &msg, 1); 261 i2c_transfer(priv->i2c_props.adap, &msg, 1);
603 tda8290_i2c_bridge(fe, 0); 262 tda8290_i2c_bridge(t, 0);
604 tuner_i2c_xfer_send(&priv->i2c_props, tda8290_agc_tri, 2); 263 tuner_i2c_xfer_send(&priv->i2c_props, tda8290_agc_tri, 2);
605 tuner_i2c_xfer_send(&priv->i2c_props, tda8290_standby, 2); 264 tuner_i2c_xfer_send(&priv->i2c_props, tda8290_standby, 2);
606
607 return 0;
608} 265}
609 266
610 267static void tda8290_init_if(struct tuner *t)
611static void tda8290_init_if(struct dvb_frontend *fe)
612{ 268{
613 struct tda8290_priv *priv = fe->tuner_priv; 269 struct tda8290_priv *priv = t->priv;
614 270
615 unsigned char set_VS[] = { 0x30, 0x6F }; 271 unsigned char set_VS[] = { 0x30, 0x6F };
616 unsigned char set_GP00_CF[] = { 0x20, 0x01 }; 272 unsigned char set_GP00_CF[] = { 0x20, 0x01 };
617 unsigned char set_GP01_CF[] = { 0x20, 0x0B }; 273 unsigned char set_GP01_CF[] = { 0x20, 0x0B };
618 274
619 if ((priv->lna_cfg) && 275 if ((t->config == 1) || (t->config == 2))
620 ((*priv->lna_cfg == 1) || (*priv->lna_cfg == 2)))
621 tuner_i2c_xfer_send(&priv->i2c_props, set_GP00_CF, 2); 276 tuner_i2c_xfer_send(&priv->i2c_props, set_GP00_CF, 2);
622 else 277 else
623 tuner_i2c_xfer_send(&priv->i2c_props, set_GP01_CF, 2); 278 tuner_i2c_xfer_send(&priv->i2c_props, set_GP01_CF, 2);
624 tuner_i2c_xfer_send(&priv->i2c_props, set_VS, 2); 279 tuner_i2c_xfer_send(&priv->i2c_props, set_VS, 2);
625} 280}
626 281
627static void tda8290_init_tuner(struct dvb_frontend *fe) 282static void tda8290_init_tuner(struct tuner *t)
628{ 283{
629 struct tda8290_priv *priv = fe->tuner_priv; 284 struct tda8290_priv *priv = t->priv;
630 unsigned char tda8275_init[] = { 0x00, 0x00, 0x00, 0x40, 0xdC, 0x04, 0xAf, 285 unsigned char tda8275_init[] = { 0x00, 0x00, 0x00, 0x40, 0xdC, 0x04, 0xAf,
631 0x3F, 0x2A, 0x04, 0xFF, 0x00, 0x00, 0x40 }; 286 0x3F, 0x2A, 0x04, 0xFF, 0x00, 0x00, 0x40 };
632 unsigned char tda8275a_init[] = { 0x00, 0x00, 0x00, 0x00, 0xdC, 0x05, 0x8b, 287 unsigned char tda8275a_init[] = { 0x00, 0x00, 0x00, 0x00, 0xdC, 0x05, 0x8b,
@@ -636,41 +291,31 @@ static void tda8290_init_tuner(struct dvb_frontend *fe)
636 if (priv->tda827x_ver != 0) 291 if (priv->tda827x_ver != 0)
637 msg.buf = tda8275a_init; 292 msg.buf = tda8275a_init;
638 293
639 tda8290_i2c_bridge(fe, 1); 294 tda8290_i2c_bridge(t, 1);
640 i2c_transfer(priv->i2c_props.adap, &msg, 1); 295 i2c_transfer(priv->i2c_props.adap, &msg, 1);
641 tda8290_i2c_bridge(fe, 0); 296 tda8290_i2c_bridge(t, 0);
642} 297}
643 298
644/*---------------------------------------------------------------------*/ 299/*---------------------------------------------------------------------*/
645 300
646static int tda8290_release(struct dvb_frontend *fe) 301static void tda8290_release(struct tuner *t)
647{ 302{
648 kfree(fe->tuner_priv); 303 if (t->fe.ops.tuner_ops.release)
649 fe->tuner_priv = NULL; 304 t->fe.ops.tuner_ops.release(&t->fe);
650
651 return 0;
652}
653 305
654static int tda8290_get_frequency(struct dvb_frontend *fe, u32 *frequency) 306 kfree(t->priv);
655{ 307 t->priv = NULL;
656 struct tda8290_priv *priv = fe->tuner_priv;
657 *frequency = priv->frequency;
658 return 0;
659} 308}
660 309
661static struct dvb_tuner_ops tda8290_tuner_ops = { 310static struct tuner_operations tda8290_tuner_ops = {
662 .sleep = tda8290_standby, 311 .set_tv_freq = tda8290_set_freq,
663 .set_analog_params = tda8290_set_params, 312 .set_radio_freq = tda8290_set_freq,
664 .release = tda8290_release, 313 .has_signal = tda8290_has_signal,
665 .get_frequency = tda8290_get_frequency, 314 .standby = tda8290_standby,
666 .get_status = tda8290_get_status, 315 .release = tda8290_release,
667 .get_rf_strength = tda8290_get_rf_strength,
668}; 316};
669 317
670struct dvb_frontend *tda8290_attach(struct dvb_frontend *fe, 318int tda8290_attach(struct tuner *t)
671 struct i2c_adapter* i2c_adap,
672 u8 i2c_addr,
673 struct tda8290_config *cfg)
674{ 319{
675 struct tda8290_priv *priv = NULL; 320 struct tda8290_priv *priv = NULL;
676 u8 data; 321 u8 data;
@@ -680,17 +325,15 @@ struct dvb_frontend *tda8290_attach(struct dvb_frontend *fe,
680 325
681 priv = kzalloc(sizeof(struct tda8290_priv), GFP_KERNEL); 326 priv = kzalloc(sizeof(struct tda8290_priv), GFP_KERNEL);
682 if (priv == NULL) 327 if (priv == NULL)
683 return NULL; 328 return -ENOMEM;
684 fe->tuner_priv = priv; 329 t->priv = priv;
685 330
686 priv->i2c_props.addr = i2c_addr; 331 priv->i2c_props.addr = t->i2c.addr;
687 priv->i2c_props.adap = i2c_adap; 332 priv->i2c_props.adap = t->i2c.adapter;
688 if (cfg) { 333 priv->cfg.config = &t->config;
689 priv->lna_cfg = cfg->lna_cfg; 334 priv->cfg.tuner_callback = t->tuner_callback;
690 priv->tuner_callback = cfg->tuner_callback;
691 }
692 335
693 tda8290_i2c_bridge(fe, 1); 336 tda8290_i2c_bridge(t, 1);
694 /* probe for tuner chip */ 337 /* probe for tuner chip */
695 tuners_found = 0; 338 tuners_found = 0;
696 tuner_addrs = 0; 339 tuner_addrs = 0;
@@ -706,7 +349,7 @@ struct dvb_frontend *tda8290_attach(struct dvb_frontend *fe,
706 behind the bridge and we choose the highest address that doesn't 349 behind the bridge and we choose the highest address that doesn't
707 give a response now 350 give a response now
708 */ 351 */
709 tda8290_i2c_bridge(fe, 0); 352 tda8290_i2c_bridge(t, 0);
710 if(tuners_found > 1) 353 if(tuners_found > 1)
711 for (i = 0; i < tuners_found; i++) { 354 for (i = 0; i < tuners_found; i++) {
712 msg.addr = tuner_addrs & 0xff; 355 msg.addr = tuner_addrs & 0xff;
@@ -727,42 +370,45 @@ struct dvb_frontend *tda8290_attach(struct dvb_frontend *fe,
727 priv->tda827x_addr = tuner_addrs; 370 priv->tda827x_addr = tuner_addrs;
728 msg.addr = tuner_addrs; 371 msg.addr = tuner_addrs;
729 372
730 tda8290_i2c_bridge(fe, 1); 373 tda8290_i2c_bridge(t, 1);
374
731 ret = i2c_transfer(priv->i2c_props.adap, &msg, 1); 375 ret = i2c_transfer(priv->i2c_props.adap, &msg, 1);
732 if( ret != 1) 376 if( ret != 1)
733 tuner_warn("TDA827x access failed!\n"); 377 tuner_warn("TDA827x access failed!\n");
734 378
735 memcpy(&fe->ops.tuner_ops, &tda8290_tuner_ops,
736 sizeof(struct dvb_tuner_ops));
737
738 if ((data & 0x3c) == 0) { 379 if ((data & 0x3c) == 0) {
739 strlcpy(fe->ops.tuner_ops.info.name, "tda8290+75", 380 strlcpy(t->i2c.name, "tda8290+75", sizeof(t->i2c.name));
740 sizeof(fe->ops.tuner_ops.info.name));
741 fe->ops.tuner_ops.info.frequency_min = 55000000;
742 fe->ops.tuner_ops.info.frequency_max = 860000000;
743 fe->ops.tuner_ops.info.frequency_step = 250000;
744 priv->tda827x_ver = 0; 381 priv->tda827x_ver = 0;
745 } else { 382 } else {
746 strlcpy(fe->ops.tuner_ops.info.name, "tda8290+75a", 383 strlcpy(t->i2c.name, "tda8290+75a", sizeof(t->i2c.name));
747 sizeof(fe->ops.tuner_ops.info.name));
748 fe->ops.tuner_ops.info.frequency_min = 44000000;
749 fe->ops.tuner_ops.info.frequency_max = 906000000;
750 fe->ops.tuner_ops.info.frequency_step = 62500;
751 priv->tda827x_ver = 2; 384 priv->tda827x_ver = 2;
752 } 385 }
386 tda827x_attach(&t->fe, priv->tda827x_addr,
387 priv->i2c_props.adap, &priv->cfg);
388
389 /* FIXME: tda827x module doesn't probe the tuner until
390 * tda827x_initial_sleep is called
391 */
392 if (t->fe.ops.tuner_ops.sleep)
393 t->fe.ops.tuner_ops.sleep(&t->fe);
753 394
754 priv->tda827x_lpsel = 0; 395 memcpy(&t->ops, &tda8290_tuner_ops, sizeof(struct tuner_operations));
755 396
756 tda8290_init_tuner(fe); 397 tuner_info("type set to %s\n", t->i2c.name);
757 tda8290_init_if(fe); 398
758 return fe; 399 priv->cfg.tda827x_lpsel = 0;
400 t->mode = V4L2_TUNER_ANALOG_TV;
401
402 tda8290_init_tuner(t);
403 tda8290_init_if(t);
404 return 0;
759} 405}
760 406
761int tda8290_probe(struct i2c_adapter* i2c_adap, u8 i2c_addr) 407int tda8290_probe(struct tuner *t)
762{ 408{
763 struct tuner_i2c_props i2c_props = { 409 struct tuner_i2c_props i2c_props = {
764 .adap = i2c_adap, 410 .adap = t->i2c.adapter,
765 .addr = i2c_addr 411 .addr = t->i2c.addr
766 }; 412 };
767 413
768 unsigned char soft_reset[] = { 0x00, 0x00 }; 414 unsigned char soft_reset[] = { 0x00, 0x00 };