3 i2c tv tuner chip device driver
4 controls the philips tda8290+75 tuner chip combo.
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.
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.
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.
21 #include <linux/i2c.h>
22 #include <linux/videodev.h>
23 #include <linux/delay.h>
24 #include "tuner-driver.h"
26 /* ---------------------------------------------------------------------- */
29 unsigned char tda8290_easy_mode
;
30 unsigned char tda827x_lpsel
;
31 unsigned char tda827x_addr
;
32 unsigned char tda827x_ver
;
36 /* ---------------------------------------------------------------------- */
48 /* Note lomax entry is lo / 62500 */
50 static struct tda827x_data tda827x_analog
[] = {
51 { .lomax
= 992, .spd
= 3, .bs
= 2, .bp
= 0, .cp
= 0, .gc3
= 3, .div1p5
= 1}, /* 62 MHz */
52 { .lomax
= 1056, .spd
= 3, .bs
= 3, .bp
= 0, .cp
= 0, .gc3
= 3, .div1p5
= 1}, /* 66 MHz */
53 { .lomax
= 1216, .spd
= 3, .bs
= 1, .bp
= 0, .cp
= 0, .gc3
= 3, .div1p5
= 0}, /* 76 MHz */
54 { .lomax
= 1344, .spd
= 3, .bs
= 2, .bp
= 0, .cp
= 0, .gc3
= 3, .div1p5
= 0}, /* 84 MHz */
55 { .lomax
= 1488, .spd
= 3, .bs
= 2, .bp
= 0, .cp
= 0, .gc3
= 1, .div1p5
= 0}, /* 93 MHz */
56 { .lomax
= 1568, .spd
= 3, .bs
= 3, .bp
= 0, .cp
= 0, .gc3
= 1, .div1p5
= 0}, /* 98 MHz */
57 { .lomax
= 1744, .spd
= 3, .bs
= 3, .bp
= 1, .cp
= 0, .gc3
= 1, .div1p5
= 0}, /* 109 MHz */
58 { .lomax
= 1968, .spd
= 2, .bs
= 2, .bp
= 1, .cp
= 0, .gc3
= 1, .div1p5
= 1}, /* 123 MHz */
59 { .lomax
= 2128, .spd
= 2, .bs
= 3, .bp
= 1, .cp
= 0, .gc3
= 1, .div1p5
= 1}, /* 133 MHz */
60 { .lomax
= 2416, .spd
= 2, .bs
= 1, .bp
= 1, .cp
= 0, .gc3
= 1, .div1p5
= 0}, /* 151 MHz */
61 { .lomax
= 2464, .spd
= 2, .bs
= 2, .bp
= 1, .cp
= 0, .gc3
= 1, .div1p5
= 0}, /* 154 MHz */
62 { .lomax
= 2896, .spd
= 2, .bs
= 2, .bp
= 1, .cp
= 0, .gc3
= 0, .div1p5
= 0}, /* 181 MHz */
63 { .lomax
= 2960, .spd
= 2, .bs
= 2, .bp
= 2, .cp
= 0, .gc3
= 1, .div1p5
= 0}, /* 185 MHz */
64 { .lomax
= 3472, .spd
= 2, .bs
= 3, .bp
= 2, .cp
= 0, .gc3
= 1, .div1p5
= 0}, /* 217 MHz */
65 { .lomax
= 3904, .spd
= 1, .bs
= 2, .bp
= 2, .cp
= 0, .gc3
= 1, .div1p5
= 1}, /* 244 MHz */
66 { .lomax
= 4240, .spd
= 1, .bs
= 3, .bp
= 2, .cp
= 0, .gc3
= 1, .div1p5
= 1}, /* 265 MHz */
67 { .lomax
= 4832, .spd
= 1, .bs
= 1, .bp
= 2, .cp
= 0, .gc3
= 1, .div1p5
= 0}, /* 302 MHz */
68 { .lomax
= 5184, .spd
= 1, .bs
= 2, .bp
= 2, .cp
= 0, .gc3
= 1, .div1p5
= 0}, /* 324 MHz */
69 { .lomax
= 5920, .spd
= 1, .bs
= 2, .bp
= 3, .cp
= 0, .gc3
= 1, .div1p5
= 0}, /* 370 MHz */
70 { .lomax
= 7264, .spd
= 1, .bs
= 3, .bp
= 3, .cp
= 0, .gc3
= 1, .div1p5
= 0}, /* 454 MHz */
71 { .lomax
= 7888, .spd
= 0, .bs
= 2, .bp
= 3, .cp
= 0, .gc3
= 1, .div1p5
= 1}, /* 493 MHz */
72 { .lomax
= 8480, .spd
= 0, .bs
= 3, .bp
= 3, .cp
= 0, .gc3
= 1, .div1p5
= 1}, /* 530 MHz */
73 { .lomax
= 8864, .spd
= 0, .bs
= 1, .bp
= 3, .cp
= 0, .gc3
= 1, .div1p5
= 0}, /* 554 MHz */
74 { .lomax
= 9664, .spd
= 0, .bs
= 1, .bp
= 4, .cp
= 0, .gc3
= 0, .div1p5
= 0}, /* 604 MHz */
75 { .lomax
= 11088, .spd
= 0, .bs
= 2, .bp
= 4, .cp
= 0, .gc3
= 0, .div1p5
= 0}, /* 696 MHz */
76 { .lomax
= 11840, .spd
= 0, .bs
= 2, .bp
= 4, .cp
= 1, .gc3
= 0, .div1p5
= 0}, /* 740 MHz */
77 { .lomax
= 13120, .spd
= 0, .bs
= 3, .bp
= 4, .cp
= 0, .gc3
= 0, .div1p5
= 0}, /* 820 MHz */
78 { .lomax
= 13840, .spd
= 0, .bs
= 3, .bp
= 4, .cp
= 1, .gc3
= 0, .div1p5
= 0}, /* 865 MHz */
79 { .lomax
= 0, .spd
= 0, .bs
= 0, .bp
= 0, .cp
= 0, .gc3
= 0, .div1p5
= 0} /* End */
82 static void tda827x_tune(struct i2c_client
*c
, u16 ifc
, unsigned int freq
)
84 unsigned char tuner_reg
[8];
85 unsigned char reg2
[2];
88 struct tuner
*t
= i2c_get_clientdata(c
);
89 struct tda8290_priv
*priv
= t
->priv
;
90 struct i2c_msg msg
= {.addr
= priv
->tda827x_addr
, .flags
= 0};
92 if (t
->mode
== V4L2_TUNER_RADIO
)
97 while (tda827x_analog
[i
].lomax
< N
) {
98 if(tda827x_analog
[i
+ 1].lomax
== 0)
103 N
= N
<< tda827x_analog
[i
].spd
;
106 tuner_reg
[1] = (unsigned char)(N
>>8);
107 tuner_reg
[2] = (unsigned char) N
;
109 tuner_reg
[4] = 0x52 + (priv
->tda827x_lpsel
<< 5);
110 tuner_reg
[5] = (tda827x_analog
[i
].spd
<< 6) + (tda827x_analog
[i
].div1p5
<<5) +
111 (tda827x_analog
[i
].bs
<<3) + tda827x_analog
[i
].bp
;
112 tuner_reg
[6] = 0x8f + (tda827x_analog
[i
].gc3
<< 4);
117 i2c_transfer(c
->adapter
, &msg
, 1);
123 i2c_transfer(c
->adapter
, &msg
, 1);
127 i2c_transfer(c
->adapter
, &msg
, 1);
130 reg2
[1] = tuner_reg
[4] + 0x80;
131 i2c_transfer(c
->adapter
, &msg
, 1);
135 reg2
[1] = tuner_reg
[4] + 4;
136 i2c_transfer(c
->adapter
, &msg
, 1);
140 reg2
[1] = tuner_reg
[4];
141 i2c_transfer(c
->adapter
, &msg
, 1);
145 reg2
[1] = (tuner_reg
[4] & 0xfc) + tda827x_analog
[i
].cp
;
146 i2c_transfer(c
->adapter
, &msg
, 1);
150 i2c_transfer(c
->adapter
, &msg
, 1);
153 reg2
[1] = 0x08; // Vsync en
154 i2c_transfer(c
->adapter
, &msg
, 1);
157 static void tda827x_agcf(struct i2c_client
*c
)
159 struct tuner
*t
= i2c_get_clientdata(c
);
160 struct tda8290_priv
*priv
= t
->priv
;
161 unsigned char data
[] = {0x80, 0x0c};
162 struct i2c_msg msg
= {.addr
= priv
->tda827x_addr
, .buf
= data
,
163 .flags
= 0, .len
= 2};
164 i2c_transfer(c
->adapter
, &msg
, 1);
167 /* ---------------------------------------------------------------------- */
169 struct tda827xa_data
{
178 static struct tda827xa_data tda827xa_analog
[] = {
179 { .lomax
= 910, .svco
= 3, .spd
= 4, .scr
= 0, .sbs
= 0, .gc3
= 3}, /* 56.875 MHz */
180 { .lomax
= 1076, .svco
= 0, .spd
= 3, .scr
= 0, .sbs
= 0, .gc3
= 3}, /* 67.25 MHz */
181 { .lomax
= 1300, .svco
= 1, .spd
= 3, .scr
= 0, .sbs
= 0, .gc3
= 3}, /* 81.25 MHz */
182 { .lomax
= 1560, .svco
= 2, .spd
= 3, .scr
= 0, .sbs
= 0, .gc3
= 3}, /* 97.5 MHz */
183 { .lomax
= 1820, .svco
= 3, .spd
= 3, .scr
= 0, .sbs
= 1, .gc3
= 1}, /* 113.75 MHz */
184 { .lomax
= 2152, .svco
= 0, .spd
= 2, .scr
= 0, .sbs
= 1, .gc3
= 1}, /* 134.5 MHz */
185 { .lomax
= 2464, .svco
= 1, .spd
= 2, .scr
= 0, .sbs
= 1, .gc3
= 1}, /* 154 MHz */
186 { .lomax
= 2600, .svco
= 1, .spd
= 2, .scr
= 0, .sbs
= 1, .gc3
= 1}, /* 162.5 MHz */
187 { .lomax
= 2928, .svco
= 2, .spd
= 2, .scr
= 0, .sbs
= 1, .gc3
= 1}, /* 183 MHz */
188 { .lomax
= 3120, .svco
= 2, .spd
= 2, .scr
= 0, .sbs
= 2, .gc3
= 1}, /* 195 MHz */
189 { .lomax
= 3640, .svco
= 3, .spd
= 2, .scr
= 0, .sbs
= 2, .gc3
= 3}, /* 227.5 MHz */
190 { .lomax
= 4304, .svco
= 0, .spd
= 1, .scr
= 0, .sbs
= 2, .gc3
= 3}, /* 269 MHz */
191 { .lomax
= 5200, .svco
= 1, .spd
= 1, .scr
= 0, .sbs
= 2, .gc3
= 1}, /* 325 MHz */
192 { .lomax
= 6240, .svco
= 2, .spd
= 1, .scr
= 0, .sbs
= 3, .gc3
= 3}, /* 390 MHz */
193 { .lomax
= 7280, .svco
= 3, .spd
= 1, .scr
= 0, .sbs
= 3, .gc3
= 3}, /* 455 MHz */
194 { .lomax
= 8320, .svco
= 0, .spd
= 0, .scr
= 0, .sbs
= 3, .gc3
= 1}, /* 520 MHz */
195 { .lomax
= 8608, .svco
= 0, .spd
= 0, .scr
= 1, .sbs
= 3, .gc3
= 1}, /* 538 MHz */
196 { .lomax
= 8864, .svco
= 1, .spd
= 0, .scr
= 0, .sbs
= 3, .gc3
= 1}, /* 554 MHz */
197 { .lomax
= 9920, .svco
= 1, .spd
= 0, .scr
= 0, .sbs
= 4, .gc3
= 0}, /* 620 MHz */
198 { .lomax
= 10400, .svco
= 1, .spd
= 0, .scr
= 1, .sbs
= 4, .gc3
= 0}, /* 650 MHz */
199 { .lomax
= 11200, .svco
= 2, .spd
= 0, .scr
= 0, .sbs
= 4, .gc3
= 0}, /* 700 MHz */
200 { .lomax
= 12480, .svco
= 2, .spd
= 0, .scr
= 1, .sbs
= 4, .gc3
= 0}, /* 780 MHz */
201 { .lomax
= 13120, .svco
= 3, .spd
= 0, .scr
= 0, .sbs
= 4, .gc3
= 0}, /* 820 MHz */
202 { .lomax
= 13920, .svco
= 3, .spd
= 0, .scr
= 1, .sbs
= 4, .gc3
= 0}, /* 870 MHz */
203 { .lomax
= 14576, .svco
= 3, .spd
= 0, .scr
= 2, .sbs
= 4, .gc3
= 0}, /* 911 MHz */
204 { .lomax
= 0, .svco
= 0, .spd
= 0, .scr
= 0, .sbs
= 0, .gc3
= 0} /* End */
207 static void tda827xa_lna_gain(struct i2c_client
*c
, int high
)
209 struct tuner
*t
= i2c_get_clientdata(c
);
210 unsigned char buf
[] = {0x22, 0x01};
212 struct i2c_msg msg
= {.addr
= c
->addr
, .flags
= 0, .buf
= buf
, .len
= sizeof(buf
)};
215 tuner_dbg("setting LNA to high gain\n");
217 tuner_dbg("setting LNA to low gain\n");
222 case 1: /* switch is GPIO 0 of tda8290 */
225 if (t
->std
& V4L2_STD_MN
)
229 if (t
->tuner_callback
)
230 t
->tuner_callback(c
->adapter
->algo_data
, 1, arg
);
231 buf
[1] = high
? 0 : 1;
233 buf
[1] = high
? 1 : 0;
234 i2c_transfer(c
->adapter
, &msg
, 1);
236 case 3: /* switch with GPIO of saa713x */
237 if (t
->tuner_callback
)
238 t
->tuner_callback(c
->adapter
->algo_data
, 0, high
);
243 static void tda827xa_tune(struct i2c_client
*c
, u16 ifc
, unsigned int freq
)
245 unsigned char tuner_reg
[11];
248 struct tuner
*t
= i2c_get_clientdata(c
);
249 struct tda8290_priv
*priv
= t
->priv
;
250 struct i2c_msg msg
= {.addr
= priv
->tda827x_addr
, .flags
= 0, .buf
= tuner_reg
};
252 tda827xa_lna_gain( c
, 1);
255 if (t
->mode
== V4L2_TUNER_RADIO
)
260 while (tda827xa_analog
[i
].lomax
< N
) {
261 if(tda827xa_analog
[i
+ 1].lomax
== 0)
266 N
= N
<< tda827xa_analog
[i
].spd
;
269 tuner_reg
[1] = (unsigned char)(N
>>8);
270 tuner_reg
[2] = (unsigned char) N
;
273 tuner_reg
[5] = (tda827xa_analog
[i
].spd
<< 5) + (tda827xa_analog
[i
].svco
<< 3) +
274 tda827xa_analog
[i
].sbs
;
275 tuner_reg
[6] = 0x8b + (tda827xa_analog
[i
].gc3
<< 4);
279 tuner_reg
[10] = 0x00;
281 i2c_transfer(c
->adapter
, &msg
, 1);
287 tuner_reg
[4] = 0x99 + (priv
->tda827x_lpsel
<< 1);
289 i2c_transfer(c
->adapter
, &msg
, 1);
294 i2c_transfer(c
->adapter
, &msg
, 1);
297 tuner_reg
[1] = 0x10 + tda827xa_analog
[i
].scr
;
298 i2c_transfer(c
->adapter
, &msg
, 1);
300 msg
.flags
= I2C_M_RD
;
301 i2c_transfer(c
->adapter
, &msg
, 1);
304 tuner_dbg("AGC2 gain is: %d\n", tuner_reg
[1]);
305 if (tuner_reg
[1] < 1)
306 tda827xa_lna_gain( c
, 0);
311 i2c_transfer(c
->adapter
, &msg
, 1);
315 tuner_reg
[1] = 0x8f + (tda827xa_analog
[i
].gc3
<< 4);
316 i2c_transfer(c
->adapter
, &msg
, 1);
320 i2c_transfer(c
->adapter
, &msg
, 1);
324 i2c_transfer(c
->adapter
, &msg
, 1);
327 tuner_reg
[1] = 0x19 + (priv
->tda827x_lpsel
<< 1);
328 i2c_transfer(c
->adapter
, &msg
, 1);
331 static void tda827xa_agcf(struct i2c_client
*c
)
333 struct tuner
*t
= i2c_get_clientdata(c
);
334 struct tda8290_priv
*priv
= t
->priv
;
335 unsigned char data
[] = {0x80, 0x2c};
336 struct i2c_msg msg
= {.addr
= priv
->tda827x_addr
, .buf
= data
,
337 .flags
= 0, .len
= 2};
338 i2c_transfer(c
->adapter
, &msg
, 1);
341 /*---------------------------------------------------------------------*/
343 static void tda8290_i2c_bridge(struct i2c_client
*c
, int close
)
345 unsigned char enable
[2] = { 0x21, 0xC0 };
346 unsigned char disable
[2] = { 0x21, 0x00 };
350 i2c_master_send(c
, msg
, 2);
351 /* let the bridge stabilize */
355 i2c_master_send(c
, msg
, 2);
359 /*---------------------------------------------------------------------*/
361 static int tda8290_tune(struct i2c_client
*c
, u16 ifc
, unsigned int freq
)
363 struct tuner
*t
= i2c_get_clientdata(c
);
364 struct tda8290_priv
*priv
= t
->priv
;
365 unsigned char soft_reset
[] = { 0x00, 0x00 };
366 unsigned char easy_mode
[] = { 0x01, priv
->tda8290_easy_mode
};
367 unsigned char expert_mode
[] = { 0x01, 0x80 };
368 unsigned char agc_out_on
[] = { 0x02, 0x00 };
369 unsigned char gainset_off
[] = { 0x28, 0x14 };
370 unsigned char if_agc_spd
[] = { 0x0f, 0x88 };
371 unsigned char adc_head_6
[] = { 0x05, 0x04 };
372 unsigned char adc_head_9
[] = { 0x05, 0x02 };
373 unsigned char adc_head_12
[] = { 0x05, 0x01 };
374 unsigned char pll_bw_nom
[] = { 0x0d, 0x47 };
375 unsigned char pll_bw_low
[] = { 0x0d, 0x27 };
376 unsigned char gainset_2
[] = { 0x28, 0x64 };
377 unsigned char agc_rst_on
[] = { 0x0e, 0x0b };
378 unsigned char agc_rst_off
[] = { 0x0e, 0x09 };
379 unsigned char if_agc_set
[] = { 0x0f, 0x81 };
380 unsigned char addr_adc_sat
= 0x1a;
381 unsigned char addr_agc_stat
= 0x1d;
382 unsigned char addr_pll_stat
= 0x1b;
383 unsigned char adc_sat
, agc_stat
,
387 tuner_dbg("tda827xa config is 0x%02x\n", t
->config
);
388 i2c_master_send(c
, easy_mode
, 2);
389 i2c_master_send(c
, agc_out_on
, 2);
390 i2c_master_send(c
, soft_reset
, 2);
393 expert_mode
[1] = priv
->tda8290_easy_mode
+ 0x80;
394 i2c_master_send(c
, expert_mode
, 2);
395 i2c_master_send(c
, gainset_off
, 2);
396 i2c_master_send(c
, if_agc_spd
, 2);
397 if (priv
->tda8290_easy_mode
& 0x60)
398 i2c_master_send(c
, adc_head_9
, 2);
400 i2c_master_send(c
, adc_head_6
, 2);
401 i2c_master_send(c
, pll_bw_nom
, 2);
403 tda8290_i2c_bridge(c
, 1);
404 if (priv
->tda827x_ver
!= 0)
405 tda827xa_tune(c
, ifc
, freq
);
407 tda827x_tune(c
, ifc
, freq
);
408 for (i
= 0; i
< 3; i
++) {
409 i2c_master_send(c
, &addr_pll_stat
, 1);
410 i2c_master_recv(c
, &pll_stat
, 1);
411 if (pll_stat
& 0x80) {
412 i2c_master_send(c
, &addr_adc_sat
, 1);
413 i2c_master_recv(c
, &adc_sat
, 1);
414 i2c_master_send(c
, &addr_agc_stat
, 1);
415 i2c_master_recv(c
, &agc_stat
, 1);
416 tuner_dbg("tda8290 is locked, AGC: %d\n", agc_stat
);
419 tuner_dbg("tda8290 not locked, no signal?\n");
423 /* adjust headroom resp. gain */
424 if ((agc_stat
> 115) || (!(pll_stat
& 0x80) && (adc_sat
< 20))) {
425 tuner_dbg("adjust gain, step 1. Agc: %d, ADC stat: %d, lock: %d\n",
426 agc_stat
, adc_sat
, pll_stat
& 0x80);
427 i2c_master_send(c
, gainset_2
, 2);
429 i2c_master_send(c
, &addr_agc_stat
, 1);
430 i2c_master_recv(c
, &agc_stat
, 1);
431 i2c_master_send(c
, &addr_pll_stat
, 1);
432 i2c_master_recv(c
, &pll_stat
, 1);
433 if ((agc_stat
> 115) || !(pll_stat
& 0x80)) {
434 tuner_dbg("adjust gain, step 2. Agc: %d, lock: %d\n",
435 agc_stat
, pll_stat
& 0x80);
436 if (priv
->tda827x_ver
!= 0)
441 i2c_master_send(c
, &addr_agc_stat
, 1);
442 i2c_master_recv(c
, &agc_stat
, 1);
443 i2c_master_send(c
, &addr_pll_stat
, 1);
444 i2c_master_recv(c
, &pll_stat
, 1);
445 if((agc_stat
> 115) || !(pll_stat
& 0x80)) {
446 tuner_dbg("adjust gain, step 3. Agc: %d\n", agc_stat
);
447 i2c_master_send(c
, adc_head_12
, 2);
448 i2c_master_send(c
, pll_bw_low
, 2);
454 /* l/ l' deadlock? */
455 if(priv
->tda8290_easy_mode
& 0x60) {
456 i2c_master_send(c
, &addr_adc_sat
, 1);
457 i2c_master_recv(c
, &adc_sat
, 1);
458 i2c_master_send(c
, &addr_pll_stat
, 1);
459 i2c_master_recv(c
, &pll_stat
, 1);
460 if ((adc_sat
> 20) || !(pll_stat
& 0x80)) {
461 tuner_dbg("trying to resolve SECAM L deadlock\n");
462 i2c_master_send(c
, agc_rst_on
, 2);
464 i2c_master_send(c
, agc_rst_off
, 2);
468 tda8290_i2c_bridge(c
, 0);
469 i2c_master_send(c
, if_agc_set
, 2);
473 /*---------------------------------------------------------------------*/
475 static void set_audio(struct tuner
*t
)
477 struct tda8290_priv
*priv
= t
->priv
;
480 priv
->tda827x_lpsel
= 0;
481 if (t
->std
& V4L2_STD_MN
) {
483 priv
->tda8290_easy_mode
= 0x01;
484 priv
->tda827x_lpsel
= 1;
486 } else if (t
->std
& V4L2_STD_B
) {
488 priv
->tda8290_easy_mode
= 0x02;
490 } else if (t
->std
& V4L2_STD_GH
) {
492 priv
->tda8290_easy_mode
= 0x04;
494 } else if (t
->std
& V4L2_STD_PAL_I
) {
496 priv
->tda8290_easy_mode
= 0x08;
498 } else if (t
->std
& V4L2_STD_DK
) {
500 priv
->tda8290_easy_mode
= 0x10;
502 } else if (t
->std
& V4L2_STD_SECAM_L
) {
504 priv
->tda8290_easy_mode
= 0x20;
506 } else if (t
->std
& V4L2_STD_SECAM_LC
) {
508 priv
->tda8290_easy_mode
= 0x40;
512 priv
->tda8290_easy_mode
= 0x10;
515 tuner_dbg("setting tda8290 to system %s\n", mode
);
518 static void set_tv_freq(struct i2c_client
*c
, unsigned int freq
)
520 struct tuner
*t
= i2c_get_clientdata(c
);
521 struct tda8290_priv
*priv
= t
->priv
;
524 tda8290_tune(c
, priv
->sgIF
, freq
);
527 static void set_radio_freq(struct i2c_client
*c
, unsigned int freq
)
529 /* if frequency is 5.5 MHz */
530 tda8290_tune(c
, 88, freq
);
533 static int has_signal(struct i2c_client
*c
)
535 unsigned char i2c_get_afc
[1] = { 0x1B };
536 unsigned char afc
= 0;
538 i2c_master_send(c
, i2c_get_afc
, ARRAY_SIZE(i2c_get_afc
));
539 i2c_master_recv(c
, &afc
, 1);
540 return (afc
& 0x80)? 65535:0;
543 /*---------------------------------------------------------------------*/
545 static void standby(struct i2c_client
*c
)
547 struct tuner
*t
= i2c_get_clientdata(c
);
548 struct tda8290_priv
*priv
= t
->priv
;
549 unsigned char cb1
[] = { 0x30, 0xD0 };
550 unsigned char tda8290_standby
[] = { 0x00, 0x02 };
551 unsigned char tda8290_agc_tri
[] = { 0x02, 0x20 };
552 struct i2c_msg msg
= {.addr
= priv
->tda827x_addr
, .flags
=0, .buf
=cb1
, .len
= 2};
554 tda8290_i2c_bridge(c
, 1);
555 if (priv
->tda827x_ver
!= 0)
557 i2c_transfer(c
->adapter
, &msg
, 1);
558 tda8290_i2c_bridge(c
, 0);
559 i2c_master_send(c
, tda8290_agc_tri
, 2);
560 i2c_master_send(c
, tda8290_standby
, 2);
564 static void tda8290_init_if(struct i2c_client
*c
)
566 struct tuner
*t
= i2c_get_clientdata(c
);
567 unsigned char set_VS
[] = { 0x30, 0x6F };
568 unsigned char set_GP00_CF
[] = { 0x20, 0x01 };
569 unsigned char set_GP01_CF
[] = { 0x20, 0x0B };
571 if ((t
->config
== 1) || (t
->config
== 2))
572 i2c_master_send(c
, set_GP00_CF
, 2);
574 i2c_master_send(c
, set_GP01_CF
, 2);
575 i2c_master_send(c
, set_VS
, 2);
578 static void tda8290_init_tuner(struct i2c_client
*c
)
580 struct tuner
*t
= i2c_get_clientdata(c
);
581 struct tda8290_priv
*priv
= t
->priv
;
582 unsigned char tda8275_init
[] = { 0x00, 0x00, 0x00, 0x40, 0xdC, 0x04, 0xAf,
583 0x3F, 0x2A, 0x04, 0xFF, 0x00, 0x00, 0x40 };
584 unsigned char tda8275a_init
[] = { 0x00, 0x00, 0x00, 0x00, 0xdC, 0x05, 0x8b,
585 0x0c, 0x04, 0x20, 0xFF, 0x00, 0x00, 0x4b };
586 struct i2c_msg msg
= {.addr
= priv
->tda827x_addr
, .flags
=0,
587 .buf
=tda8275_init
, .len
= 14};
588 if (priv
->tda827x_ver
!= 0)
589 msg
.buf
= tda8275a_init
;
591 tda8290_i2c_bridge(c
, 1);
592 i2c_transfer(c
->adapter
, &msg
, 1);
593 tda8290_i2c_bridge(c
, 0);
596 /*---------------------------------------------------------------------*/
598 static void tda8290_release(struct i2c_client
*c
)
600 struct tuner
*t
= i2c_get_clientdata(c
);
606 static struct tuner_operations tda8290_tuner_ops
= {
607 .set_tv_freq
= set_tv_freq
,
608 .set_radio_freq
= set_radio_freq
,
609 .has_signal
= has_signal
,
611 .release
= tda8290_release
,
614 int tda8290_init(struct i2c_client
*c
)
616 struct tda8290_priv
*priv
= NULL
;
617 struct tuner
*t
= i2c_get_clientdata(c
);
619 int i
, ret
, tuners_found
;
621 struct i2c_msg msg
= {.flags
=I2C_M_RD
, .buf
=&data
, .len
= 1};
623 priv
= kzalloc(sizeof(struct tda8290_priv
), GFP_KERNEL
);
628 tda8290_i2c_bridge(c
, 1);
629 /* probe for tuner chip */
632 for (i
=0x60; i
<= 0x63; i
++) {
634 ret
= i2c_transfer(c
->adapter
, &msg
, 1);
637 tuner_addrs
= (tuner_addrs
<< 8) + i
;
640 /* if there is more than one tuner, we expect the right one is
641 behind the bridge and we choose the highest address that doesn't
644 tda8290_i2c_bridge(c
, 0);
646 for (i
= 0; i
< tuners_found
; i
++) {
647 msg
.addr
= tuner_addrs
& 0xff;
648 ret
= i2c_transfer(c
->adapter
, &msg
, 1);
650 tuner_addrs
= tuner_addrs
>> 8;
654 if (tuner_addrs
== 0) {
656 tuner_info ("could not clearly identify tuner address, defaulting to %x\n",
659 tuner_addrs
= tuner_addrs
& 0xff;
660 tuner_info ("setting tuner address to %x\n", tuner_addrs
);
662 priv
->tda827x_addr
= tuner_addrs
;
663 msg
.addr
= tuner_addrs
;
665 tda8290_i2c_bridge(c
, 1);
666 ret
= i2c_transfer(c
->adapter
, &msg
, 1);
668 tuner_warn ("TDA827x access failed!\n");
669 if ((data
& 0x3c) == 0) {
670 strlcpy(c
->name
, "tda8290+75", sizeof(c
->name
));
671 priv
->tda827x_ver
= 0;
673 strlcpy(c
->name
, "tda8290+75a", sizeof(c
->name
));
674 priv
->tda827x_ver
= 2;
676 tuner_info("type set to %s\n", c
->name
);
678 memcpy(&t
->ops
, &tda8290_tuner_ops
, sizeof(struct tuner_operations
));
680 priv
->tda827x_lpsel
= 0;
681 t
->mode
= V4L2_TUNER_ANALOG_TV
;
683 tda8290_init_tuner(c
);
688 int tda8290_probe(struct i2c_client
*c
)
690 unsigned char soft_reset
[] = { 0x00, 0x00 };
691 unsigned char easy_mode_b
[] = { 0x01, 0x02 };
692 unsigned char easy_mode_g
[] = { 0x01, 0x04 };
693 unsigned char restore_9886
[] = { 0x00, 0xd6, 0x30 };
694 unsigned char addr_dto_lsb
= 0x07;
697 i2c_master_send(c
, easy_mode_b
, 2);
698 i2c_master_send(c
, soft_reset
, 2);
699 i2c_master_send(c
, &addr_dto_lsb
, 1);
700 i2c_master_recv(c
, &data
, 1);
702 i2c_master_send(c
, easy_mode_g
, 2);
703 i2c_master_send(c
, soft_reset
, 2);
704 i2c_master_send(c
, &addr_dto_lsb
, 1);
705 i2c_master_recv(c
, &data
, 1);
710 i2c_master_send(c
, restore_9886
, 3);
715 * Overrides for Emacs so that we follow Linus's tabbing style.
716 * ---------------------------------------------------------------------------