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.
20 This "tda8290" module was split apart from the original "tuner" module.
23 #include <linux/i2c.h>
24 #include <linux/delay.h>
25 #include <linux/videodev.h>
29 static int tuner_debug
= 0;
30 module_param_named(debug
, tuner_debug
, int, 0644);
31 MODULE_PARM_DESC(debug
, "enable verbose debug messages");
33 #define PREFIX "tda8290 "
35 /* ---------------------------------------------------------------------- */
38 struct tuner_i2c_props i2c_props
;
40 unsigned char tda8290_easy_mode
;
42 unsigned char tda827x_addr
;
43 unsigned char tda827x_ver
;
45 struct tda827x_config cfg
;
48 /*---------------------------------------------------------------------*/
50 static void tda8290_i2c_bridge(struct tuner
*t
, int close
)
52 struct tda8290_priv
*priv
= t
->priv
;
54 unsigned char enable
[2] = { 0x21, 0xC0 };
55 unsigned char disable
[2] = { 0x21, 0x00 };
59 tuner_i2c_xfer_send(&priv
->i2c_props
, msg
, 2);
60 /* let the bridge stabilize */
64 tuner_i2c_xfer_send(&priv
->i2c_props
, msg
, 2);
68 /*---------------------------------------------------------------------*/
70 static void set_audio(struct tuner
*t
)
72 struct tda8290_priv
*priv
= t
->priv
;
75 priv
->cfg
.tda827x_lpsel
= 0;
76 if (t
->std
& V4L2_STD_MN
) {
78 priv
->tda8290_easy_mode
= 0x01;
79 priv
->cfg
.tda827x_lpsel
= 1;
81 } else if (t
->std
& V4L2_STD_B
) {
83 priv
->tda8290_easy_mode
= 0x02;
85 } else if (t
->std
& V4L2_STD_GH
) {
87 priv
->tda8290_easy_mode
= 0x04;
89 } else if (t
->std
& V4L2_STD_PAL_I
) {
91 priv
->tda8290_easy_mode
= 0x08;
93 } else if (t
->std
& V4L2_STD_DK
) {
95 priv
->tda8290_easy_mode
= 0x10;
97 } else if (t
->std
& V4L2_STD_SECAM_L
) {
99 priv
->tda8290_easy_mode
= 0x20;
101 } else if (t
->std
& V4L2_STD_SECAM_LC
) {
103 priv
->tda8290_easy_mode
= 0x40;
106 priv
->cfg
.sgIF
= 124;
107 priv
->tda8290_easy_mode
= 0x10;
111 if (t
->mode
== V4L2_TUNER_RADIO
)
112 priv
->cfg
.sgIF
= 88; /* if frequency is 5.5 MHz */
114 tuner_dbg("setting tda8290 to system %s\n", mode
);
117 static void tda8290_set_freq(struct tuner
*t
, unsigned int freq
)
119 struct tda8290_priv
*priv
= t
->priv
;
120 unsigned char soft_reset
[] = { 0x00, 0x00 };
121 unsigned char easy_mode
[] = { 0x01, priv
->tda8290_easy_mode
};
122 unsigned char expert_mode
[] = { 0x01, 0x80 };
123 unsigned char agc_out_on
[] = { 0x02, 0x00 };
124 unsigned char gainset_off
[] = { 0x28, 0x14 };
125 unsigned char if_agc_spd
[] = { 0x0f, 0x88 };
126 unsigned char adc_head_6
[] = { 0x05, 0x04 };
127 unsigned char adc_head_9
[] = { 0x05, 0x02 };
128 unsigned char adc_head_12
[] = { 0x05, 0x01 };
129 unsigned char pll_bw_nom
[] = { 0x0d, 0x47 };
130 unsigned char pll_bw_low
[] = { 0x0d, 0x27 };
131 unsigned char gainset_2
[] = { 0x28, 0x64 };
132 unsigned char agc_rst_on
[] = { 0x0e, 0x0b };
133 unsigned char agc_rst_off
[] = { 0x0e, 0x09 };
134 unsigned char if_agc_set
[] = { 0x0f, 0x81 };
135 unsigned char addr_adc_sat
= 0x1a;
136 unsigned char addr_agc_stat
= 0x1d;
137 unsigned char addr_pll_stat
= 0x1b;
138 unsigned char adc_sat
, agc_stat
,
142 struct analog_parameters params
= {
145 .audmode
= t
->audmode
,
151 tuner_dbg("tda827xa config is 0x%02x\n", t
->config
);
152 tuner_i2c_xfer_send(&priv
->i2c_props
, easy_mode
, 2);
153 tuner_i2c_xfer_send(&priv
->i2c_props
, agc_out_on
, 2);
154 tuner_i2c_xfer_send(&priv
->i2c_props
, soft_reset
, 2);
157 expert_mode
[1] = priv
->tda8290_easy_mode
+ 0x80;
158 tuner_i2c_xfer_send(&priv
->i2c_props
, expert_mode
, 2);
159 tuner_i2c_xfer_send(&priv
->i2c_props
, gainset_off
, 2);
160 tuner_i2c_xfer_send(&priv
->i2c_props
, if_agc_spd
, 2);
161 if (priv
->tda8290_easy_mode
& 0x60)
162 tuner_i2c_xfer_send(&priv
->i2c_props
, adc_head_9
, 2);
164 tuner_i2c_xfer_send(&priv
->i2c_props
, adc_head_6
, 2);
165 tuner_i2c_xfer_send(&priv
->i2c_props
, pll_bw_nom
, 2);
167 tda8290_i2c_bridge(t
, 1);
169 if (t
->fe
.ops
.tuner_ops
.set_analog_params
)
170 t
->fe
.ops
.tuner_ops
.set_analog_params(&t
->fe
, ¶ms
);
172 for (i
= 0; i
< 3; i
++) {
173 tuner_i2c_xfer_send(&priv
->i2c_props
, &addr_pll_stat
, 1);
174 tuner_i2c_xfer_recv(&priv
->i2c_props
, &pll_stat
, 1);
175 if (pll_stat
& 0x80) {
176 tuner_i2c_xfer_send(&priv
->i2c_props
, &addr_adc_sat
, 1);
177 tuner_i2c_xfer_recv(&priv
->i2c_props
, &adc_sat
, 1);
178 tuner_i2c_xfer_send(&priv
->i2c_props
, &addr_agc_stat
, 1);
179 tuner_i2c_xfer_recv(&priv
->i2c_props
, &agc_stat
, 1);
180 tuner_dbg("tda8290 is locked, AGC: %d\n", agc_stat
);
183 tuner_dbg("tda8290 not locked, no signal?\n");
187 /* adjust headroom resp. gain */
188 if ((agc_stat
> 115) || (!(pll_stat
& 0x80) && (adc_sat
< 20))) {
189 tuner_dbg("adjust gain, step 1. Agc: %d, ADC stat: %d, lock: %d\n",
190 agc_stat
, adc_sat
, pll_stat
& 0x80);
191 tuner_i2c_xfer_send(&priv
->i2c_props
, gainset_2
, 2);
193 tuner_i2c_xfer_send(&priv
->i2c_props
, &addr_agc_stat
, 1);
194 tuner_i2c_xfer_recv(&priv
->i2c_props
, &agc_stat
, 1);
195 tuner_i2c_xfer_send(&priv
->i2c_props
, &addr_pll_stat
, 1);
196 tuner_i2c_xfer_recv(&priv
->i2c_props
, &pll_stat
, 1);
197 if ((agc_stat
> 115) || !(pll_stat
& 0x80)) {
198 tuner_dbg("adjust gain, step 2. Agc: %d, lock: %d\n",
199 agc_stat
, pll_stat
& 0x80);
201 priv
->cfg
.agcf(&t
->fe
);
203 tuner_i2c_xfer_send(&priv
->i2c_props
, &addr_agc_stat
, 1);
204 tuner_i2c_xfer_recv(&priv
->i2c_props
, &agc_stat
, 1);
205 tuner_i2c_xfer_send(&priv
->i2c_props
, &addr_pll_stat
, 1);
206 tuner_i2c_xfer_recv(&priv
->i2c_props
, &pll_stat
, 1);
207 if((agc_stat
> 115) || !(pll_stat
& 0x80)) {
208 tuner_dbg("adjust gain, step 3. Agc: %d\n", agc_stat
);
209 tuner_i2c_xfer_send(&priv
->i2c_props
, adc_head_12
, 2);
210 tuner_i2c_xfer_send(&priv
->i2c_props
, pll_bw_low
, 2);
216 /* l/ l' deadlock? */
217 if(priv
->tda8290_easy_mode
& 0x60) {
218 tuner_i2c_xfer_send(&priv
->i2c_props
, &addr_adc_sat
, 1);
219 tuner_i2c_xfer_recv(&priv
->i2c_props
, &adc_sat
, 1);
220 tuner_i2c_xfer_send(&priv
->i2c_props
, &addr_pll_stat
, 1);
221 tuner_i2c_xfer_recv(&priv
->i2c_props
, &pll_stat
, 1);
222 if ((adc_sat
> 20) || !(pll_stat
& 0x80)) {
223 tuner_dbg("trying to resolve SECAM L deadlock\n");
224 tuner_i2c_xfer_send(&priv
->i2c_props
, agc_rst_on
, 2);
226 tuner_i2c_xfer_send(&priv
->i2c_props
, agc_rst_off
, 2);
230 tda8290_i2c_bridge(t
, 0);
231 tuner_i2c_xfer_send(&priv
->i2c_props
, if_agc_set
, 2);
234 /*---------------------------------------------------------------------*/
236 static int tda8290_has_signal(struct tuner
*t
)
238 struct tda8290_priv
*priv
= t
->priv
;
240 unsigned char i2c_get_afc
[1] = { 0x1B };
241 unsigned char afc
= 0;
243 tuner_i2c_xfer_send(&priv
->i2c_props
, i2c_get_afc
, ARRAY_SIZE(i2c_get_afc
));
244 tuner_i2c_xfer_recv(&priv
->i2c_props
, &afc
, 1);
245 return (afc
& 0x80)? 65535:0;
248 /*---------------------------------------------------------------------*/
250 static void tda8290_standby(struct tuner
*t
)
252 struct tda8290_priv
*priv
= t
->priv
;
253 unsigned char cb1
[] = { 0x30, 0xD0 };
254 unsigned char tda8290_standby
[] = { 0x00, 0x02 };
255 unsigned char tda8290_agc_tri
[] = { 0x02, 0x20 };
256 struct i2c_msg msg
= {.addr
= priv
->tda827x_addr
, .flags
=0, .buf
=cb1
, .len
= 2};
258 tda8290_i2c_bridge(t
, 1);
259 if (priv
->tda827x_ver
!= 0)
261 i2c_transfer(priv
->i2c_props
.adap
, &msg
, 1);
262 tda8290_i2c_bridge(t
, 0);
263 tuner_i2c_xfer_send(&priv
->i2c_props
, tda8290_agc_tri
, 2);
264 tuner_i2c_xfer_send(&priv
->i2c_props
, tda8290_standby
, 2);
267 static void tda8290_init_if(struct tuner
*t
)
269 struct tda8290_priv
*priv
= t
->priv
;
271 unsigned char set_VS
[] = { 0x30, 0x6F };
272 unsigned char set_GP00_CF
[] = { 0x20, 0x01 };
273 unsigned char set_GP01_CF
[] = { 0x20, 0x0B };
275 if ((t
->config
== 1) || (t
->config
== 2))
276 tuner_i2c_xfer_send(&priv
->i2c_props
, set_GP00_CF
, 2);
278 tuner_i2c_xfer_send(&priv
->i2c_props
, set_GP01_CF
, 2);
279 tuner_i2c_xfer_send(&priv
->i2c_props
, set_VS
, 2);
282 static void tda8290_init_tuner(struct tuner
*t
)
284 struct tda8290_priv
*priv
= t
->priv
;
285 unsigned char tda8275_init
[] = { 0x00, 0x00, 0x00, 0x40, 0xdC, 0x04, 0xAf,
286 0x3F, 0x2A, 0x04, 0xFF, 0x00, 0x00, 0x40 };
287 unsigned char tda8275a_init
[] = { 0x00, 0x00, 0x00, 0x00, 0xdC, 0x05, 0x8b,
288 0x0c, 0x04, 0x20, 0xFF, 0x00, 0x00, 0x4b };
289 struct i2c_msg msg
= {.addr
= priv
->tda827x_addr
, .flags
=0,
290 .buf
=tda8275_init
, .len
= 14};
291 if (priv
->tda827x_ver
!= 0)
292 msg
.buf
= tda8275a_init
;
294 tda8290_i2c_bridge(t
, 1);
295 i2c_transfer(priv
->i2c_props
.adap
, &msg
, 1);
296 tda8290_i2c_bridge(t
, 0);
299 /*---------------------------------------------------------------------*/
301 static void tda8290_release(struct tuner
*t
)
303 if (t
->fe
.ops
.tuner_ops
.release
)
304 t
->fe
.ops
.tuner_ops
.release(&t
->fe
);
310 static struct tuner_operations tda8290_tuner_ops
= {
311 .set_tv_freq
= tda8290_set_freq
,
312 .set_radio_freq
= tda8290_set_freq
,
313 .has_signal
= tda8290_has_signal
,
314 .standby
= tda8290_standby
,
315 .release
= tda8290_release
,
318 int tda8290_attach(struct tuner
*t
)
320 struct tda8290_priv
*priv
= NULL
;
322 int i
, ret
, tuners_found
;
324 struct i2c_msg msg
= {.flags
=I2C_M_RD
, .buf
=&data
, .len
= 1};
326 priv
= kzalloc(sizeof(struct tda8290_priv
), GFP_KERNEL
);
331 priv
->i2c_props
.addr
= t
->i2c
.addr
;
332 priv
->i2c_props
.adap
= t
->i2c
.adapter
;
333 priv
->cfg
.config
= &t
->config
;
334 priv
->cfg
.tuner_callback
= t
->tuner_callback
;
336 tda8290_i2c_bridge(t
, 1);
337 /* probe for tuner chip */
340 for (i
=0x60; i
<= 0x63; i
++) {
342 ret
= i2c_transfer(priv
->i2c_props
.adap
, &msg
, 1);
345 tuner_addrs
= (tuner_addrs
<< 8) + i
;
348 /* if there is more than one tuner, we expect the right one is
349 behind the bridge and we choose the highest address that doesn't
352 tda8290_i2c_bridge(t
, 0);
354 for (i
= 0; i
< tuners_found
; i
++) {
355 msg
.addr
= tuner_addrs
& 0xff;
356 ret
= i2c_transfer(priv
->i2c_props
.adap
, &msg
, 1);
358 tuner_addrs
= tuner_addrs
>> 8;
362 if (tuner_addrs
== 0) {
364 tuner_info("could not clearly identify tuner address, defaulting to %x\n",
367 tuner_addrs
= tuner_addrs
& 0xff;
368 tuner_info("setting tuner address to %x\n", tuner_addrs
);
370 priv
->tda827x_addr
= tuner_addrs
;
371 msg
.addr
= tuner_addrs
;
373 tda8290_i2c_bridge(t
, 1);
375 ret
= i2c_transfer(priv
->i2c_props
.adap
, &msg
, 1);
377 tuner_warn("TDA827x access failed!\n");
379 if ((data
& 0x3c) == 0) {
380 strlcpy(t
->i2c
.name
, "tda8290+75", sizeof(t
->i2c
.name
));
381 priv
->tda827x_ver
= 0;
383 strlcpy(t
->i2c
.name
, "tda8290+75a", sizeof(t
->i2c
.name
));
384 priv
->tda827x_ver
= 2;
386 tda827x_attach(&t
->fe
, priv
->tda827x_addr
,
387 priv
->i2c_props
.adap
, &priv
->cfg
);
389 /* FIXME: tda827x module doesn't probe the tuner until
390 * tda827x_initial_sleep is called
392 if (t
->fe
.ops
.tuner_ops
.sleep
)
393 t
->fe
.ops
.tuner_ops
.sleep(&t
->fe
);
395 memcpy(&t
->ops
, &tda8290_tuner_ops
, sizeof(struct tuner_operations
));
397 tuner_info("type set to %s\n", t
->i2c
.name
);
399 priv
->cfg
.tda827x_lpsel
= 0;
400 t
->mode
= V4L2_TUNER_ANALOG_TV
;
402 tda8290_init_tuner(t
);
407 int tda8290_probe(struct tuner
*t
)
409 struct tuner_i2c_props i2c_props
= {
410 .adap
= t
->i2c
.adapter
,
414 unsigned char soft_reset
[] = { 0x00, 0x00 };
415 unsigned char easy_mode_b
[] = { 0x01, 0x02 };
416 unsigned char easy_mode_g
[] = { 0x01, 0x04 };
417 unsigned char restore_9886
[] = { 0x00, 0xd6, 0x30 };
418 unsigned char addr_dto_lsb
= 0x07;
421 tuner_i2c_xfer_send(&i2c_props
, easy_mode_b
, 2);
422 tuner_i2c_xfer_send(&i2c_props
, soft_reset
, 2);
423 tuner_i2c_xfer_send(&i2c_props
, &addr_dto_lsb
, 1);
424 tuner_i2c_xfer_recv(&i2c_props
, &data
, 1);
426 tuner_i2c_xfer_send(&i2c_props
, easy_mode_g
, 2);
427 tuner_i2c_xfer_send(&i2c_props
, soft_reset
, 2);
428 tuner_i2c_xfer_send(&i2c_props
, &addr_dto_lsb
, 1);
429 tuner_i2c_xfer_recv(&i2c_props
, &data
, 1);
434 tuner_i2c_xfer_send(&i2c_props
, restore_9886
, 3);
438 EXPORT_SYMBOL_GPL(tda8290_probe
);
439 EXPORT_SYMBOL_GPL(tda8290_attach
);
441 MODULE_DESCRIPTION("Philips TDA8290 + TDA8275 / TDA8275a tuner driver");
442 MODULE_AUTHOR("Gerd Knorr, Hartmut Hackmann");
443 MODULE_LICENSE("GPL");
446 * Overrides for Emacs so that we follow Linus's tabbing style.
447 * ---------------------------------------------------------------------------