3 * i2c tv tuner chip device driver
4 * core core, i.e. kernel interfaces, registering and so on
7 #include <linux/module.h>
8 #include <linux/kernel.h>
9 #include <linux/string.h>
10 #include <linux/timer.h>
11 #include <linux/delay.h>
12 #include <linux/errno.h>
13 #include <linux/slab.h>
14 #include <linux/poll.h>
15 #include <linux/i2c.h>
16 #include <linux/types.h>
17 #include <linux/init.h>
18 #include <linux/videodev.h>
19 #include <media/tuner.h>
20 #include <media/tuner-types.h>
21 #include <media/v4l2-common.h>
22 #include <media/v4l2-i2c-drv-legacy.h>
23 #include "tuner-driver.h"
28 #include "tuner-xc2028.h"
29 #include "tuner-simple.h"
34 #define PREFIX t->i2c->driver->driver.name
36 /* standard i2c insmod options */
37 static unsigned short normal_i2c
[] = {
38 #if defined(CONFIG_TUNER_TEA5761) || (defined(CONFIG_TUNER_TEA5761_MODULE) && defined(MODULE))
41 0x42, 0x43, 0x4a, 0x4b, /* tda8290 */
42 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67,
43 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,
49 /* insmod options used at init time => read/only */
50 static unsigned int addr
= 0;
51 static unsigned int no_autodetect
= 0;
52 static unsigned int show_i2c
= 0;
54 /* insmod options used at runtime => read/write */
57 static unsigned int tv_range
[2] = { 44, 958 };
58 static unsigned int radio_range
[2] = { 65, 108 };
60 static char pal
[] = "--";
61 static char secam
[] = "--";
62 static char ntsc
[] = "-";
65 module_param(addr
, int, 0444);
66 module_param(no_autodetect
, int, 0444);
67 module_param(show_i2c
, int, 0444);
68 module_param_named(debug
,tuner_debug
, int, 0644);
69 module_param_string(pal
, pal
, sizeof(pal
), 0644);
70 module_param_string(secam
, secam
, sizeof(secam
), 0644);
71 module_param_string(ntsc
, ntsc
, sizeof(ntsc
), 0644);
72 module_param_array(tv_range
, int, NULL
, 0644);
73 module_param_array(radio_range
, int, NULL
, 0644);
75 MODULE_DESCRIPTION("device driver for various TV and TV+FM radio tuners");
76 MODULE_AUTHOR("Ralph Metzler, Gerd Knorr, Gunther Mayer");
77 MODULE_LICENSE("GPL");
79 /* ---------------------------------------------------------------------- */
81 static void fe_set_params(struct dvb_frontend
*fe
,
82 struct analog_parameters
*params
)
84 struct dvb_tuner_ops
*fe_tuner_ops
= &fe
->ops
.tuner_ops
;
85 struct tuner
*t
= fe
->analog_demod_priv
;
87 if (NULL
== fe_tuner_ops
->set_analog_params
) {
88 tuner_warn("Tuner frontend module has no way to set freq\n");
91 fe_tuner_ops
->set_analog_params(fe
, params
);
94 static void fe_release(struct dvb_frontend
*fe
)
96 if (fe
->ops
.tuner_ops
.release
)
97 fe
->ops
.tuner_ops
.release(fe
);
99 fe
->ops
.analog_demod_ops
= NULL
;
101 /* DO NOT kfree(fe->analog_demod_priv)
103 * If we are in this function, analog_demod_priv contains a pointer
104 * to struct tuner *t. This will be kfree'd in tuner_detach().
106 * Otherwise, fe->ops.analog_demod_ops->release will
107 * handle the cleanup for analog demodulator modules.
109 fe
->analog_demod_priv
= NULL
;
112 static void fe_standby(struct dvb_frontend
*fe
)
114 struct dvb_tuner_ops
*fe_tuner_ops
= &fe
->ops
.tuner_ops
;
116 if (fe_tuner_ops
->sleep
)
117 fe_tuner_ops
->sleep(fe
);
120 static int fe_has_signal(struct dvb_frontend
*fe
)
124 if (fe
->ops
.tuner_ops
.get_rf_strength
)
125 fe
->ops
.tuner_ops
.get_rf_strength(fe
, &strength
);
130 static void tuner_status(struct dvb_frontend
*fe
);
132 static struct analog_tuner_ops tuner_core_ops
= {
133 .set_params
= fe_set_params
,
134 .standby
= fe_standby
,
135 .release
= fe_release
,
136 .has_signal
= fe_has_signal
,
137 .tuner_status
= tuner_status
140 /* Set tuner frequency, freq in Units of 62.5kHz = 1/16MHz */
141 static void set_tv_freq(struct i2c_client
*c
, unsigned int freq
)
143 struct tuner
*t
= i2c_get_clientdata(c
);
144 struct analog_tuner_ops
*ops
= t
->fe
.ops
.analog_demod_ops
;
146 struct analog_parameters params
= {
148 .audmode
= t
->audmode
,
152 if (t
->type
== UNSET
) {
153 tuner_warn ("tuner type not set\n");
156 if ((NULL
== ops
) || (NULL
== ops
->set_params
)) {
157 tuner_warn ("Tuner has no way to set tv freq\n");
160 if (freq
< tv_range
[0] * 16 || freq
> tv_range
[1] * 16) {
161 tuner_dbg ("TV freq (%d.%02d) out of range (%d-%d)\n",
162 freq
/ 16, freq
% 16 * 100 / 16, tv_range
[0],
164 /* V4L2 spec: if the freq is not possible then the closest
165 possible value should be selected */
166 if (freq
< tv_range
[0] * 16)
167 freq
= tv_range
[0] * 16;
169 freq
= tv_range
[1] * 16;
171 params
.frequency
= freq
;
173 ops
->set_params(&t
->fe
, ¶ms
);
176 static void set_radio_freq(struct i2c_client
*c
, unsigned int freq
)
178 struct tuner
*t
= i2c_get_clientdata(c
);
179 struct analog_tuner_ops
*ops
= t
->fe
.ops
.analog_demod_ops
;
181 struct analog_parameters params
= {
183 .audmode
= t
->audmode
,
187 if (t
->type
== UNSET
) {
188 tuner_warn ("tuner type not set\n");
191 if ((NULL
== ops
) || (NULL
== ops
->set_params
)) {
192 tuner_warn ("tuner has no way to set radio frequency\n");
195 if (freq
< radio_range
[0] * 16000 || freq
> radio_range
[1] * 16000) {
196 tuner_dbg ("radio freq (%d.%02d) out of range (%d-%d)\n",
197 freq
/ 16000, freq
% 16000 * 100 / 16000,
198 radio_range
[0], radio_range
[1]);
199 /* V4L2 spec: if the freq is not possible then the closest
200 possible value should be selected */
201 if (freq
< radio_range
[0] * 16000)
202 freq
= radio_range
[0] * 16000;
204 freq
= radio_range
[1] * 16000;
206 params
.frequency
= freq
;
208 ops
->set_params(&t
->fe
, ¶ms
);
211 static void set_freq(struct i2c_client
*c
, unsigned long freq
)
213 struct tuner
*t
= i2c_get_clientdata(c
);
216 case V4L2_TUNER_RADIO
:
217 tuner_dbg("radio freq set to %lu.%02lu\n",
218 freq
/ 16000, freq
% 16000 * 100 / 16000);
219 set_radio_freq(c
, freq
);
220 t
->radio_freq
= freq
;
222 case V4L2_TUNER_ANALOG_TV
:
223 case V4L2_TUNER_DIGITAL_TV
:
224 tuner_dbg("tv freq set to %lu.%02lu\n",
225 freq
/ 16, freq
% 16 * 100 / 16);
226 set_tv_freq(c
, freq
);
230 tuner_dbg("freq set: unknown mode: 0x%04x!\n",t
->mode
);
234 static void tuner_i2c_address_check(struct tuner
*t
)
236 if ((t
->type
== UNSET
|| t
->type
== TUNER_ABSENT
) ||
237 ((t
->i2c
->addr
< 0x64) || (t
->i2c
->addr
> 0x6f)))
240 tuner_warn("====================== WARNING! ======================\n");
241 tuner_warn("Support for tuners in i2c address range 0x64 thru 0x6f\n");
242 tuner_warn("will soon be dropped. This message indicates that your\n");
243 tuner_warn("hardware has a %s tuner at i2c address 0x%02x.\n",
244 t
->i2c
->name
, t
->i2c
->addr
);
245 tuner_warn("To ensure continued support for your device, please\n");
246 tuner_warn("send a copy of this message, along with full dmesg\n");
247 tuner_warn("output to v4l-dvb-maintainer@linuxtv.org\n");
248 tuner_warn("Please use subject line: \"obsolete tuner i2c address.\"\n");
249 tuner_warn("driver: %s, addr: 0x%02x, type: %d (%s)\n",
250 t
->i2c
->adapter
->name
, t
->i2c
->addr
, t
->type
,
251 tuners
[t
->type
].name
);
252 tuner_warn("====================== WARNING! ======================\n");
255 static void attach_simple_tuner(struct tuner
*t
)
257 struct simple_tuner_config cfg
= {
259 .tun
= &tuners
[t
->type
]
261 simple_tuner_attach(&t
->fe
, t
->i2c
->adapter
, t
->i2c
->addr
, &cfg
);
264 static void set_type(struct i2c_client
*c
, unsigned int type
,
265 unsigned int new_mode_mask
, unsigned int new_config
,
266 int (*tuner_callback
) (void *dev
, int command
,int arg
))
268 struct tuner
*t
= i2c_get_clientdata(c
);
269 struct dvb_tuner_ops
*fe_tuner_ops
= &t
->fe
.ops
.tuner_ops
;
270 struct analog_tuner_ops
*ops
= t
->fe
.ops
.analog_demod_ops
;
271 unsigned char buffer
[4];
273 if (type
== UNSET
|| type
== TUNER_ABSENT
) {
274 tuner_dbg ("tuner 0x%02x: Tuner type absent\n",c
->addr
);
278 if (type
>= tuner_count
) {
279 tuner_warn ("tuner 0x%02x: Tuner count greater than %d\n",c
->addr
,tuner_count
);
284 t
->config
= new_config
;
285 if (tuner_callback
!= NULL
) {
286 tuner_dbg("defining GPIO callback\n");
287 t
->tuner_callback
= tuner_callback
;
290 if (t
->mode
== T_UNINITIALIZED
) {
291 tuner_dbg ("tuner 0x%02x: called during i2c_client register by adapter's attach_inform\n", c
->addr
);
296 /* discard private data, in case set_type() was previously called */
297 if (ops
&& ops
->release
)
298 ops
->release(&t
->fe
);
302 microtune_attach(&t
->fe
, t
->i2c
->adapter
, t
->i2c
->addr
);
304 case TUNER_PHILIPS_TDA8290
:
310 if (tea5767_attach(&t
->fe
, t
->i2c
->adapter
, t
->i2c
->addr
) == NULL
) {
311 t
->type
= TUNER_ABSENT
;
312 t
->mode_mask
= T_UNINITIALIZED
;
315 t
->mode_mask
= T_RADIO
;
318 if (tea5761_attach(&t
->fe
, t
->i2c
->adapter
, t
->i2c
->addr
) == NULL
) {
319 t
->type
= TUNER_ABSENT
;
320 t
->mode_mask
= T_UNINITIALIZED
;
323 t
->mode_mask
= T_RADIO
;
325 case TUNER_PHILIPS_FMD1216ME_MK3
:
330 i2c_master_send(c
, buffer
, 4);
334 i2c_master_send(c
, buffer
, 4);
335 attach_simple_tuner(t
);
337 case TUNER_PHILIPS_TD1316
:
342 i2c_master_send(c
,buffer
,4);
343 attach_simple_tuner(t
);
347 struct xc2028_config cfg
= {
348 .i2c_adap
= t
->i2c
->adapter
,
349 .i2c_addr
= t
->i2c
->addr
,
350 .video_dev
= c
->adapter
->algo_data
,
351 .callback
= t
->tuner_callback
,
353 if (!xc2028_attach(&t
->fe
, &cfg
)) {
354 t
->type
= TUNER_ABSENT
;
355 t
->mode_mask
= T_UNINITIALIZED
;
364 attach_simple_tuner(t
);
368 ops
= t
->fe
.ops
.analog_demod_ops
;
370 if (((NULL
== ops
) || (NULL
== ops
->set_params
)) &&
371 (fe_tuner_ops
->set_analog_params
)) {
372 strlcpy(t
->i2c
->name
, fe_tuner_ops
->info
.name
,
373 sizeof(t
->i2c
->name
));
375 t
->fe
.ops
.analog_demod_ops
= &tuner_core_ops
;
376 t
->fe
.analog_demod_priv
= t
;
379 tuner_dbg("type set to %s\n", t
->i2c
->name
);
381 if (t
->mode_mask
== T_UNINITIALIZED
)
382 t
->mode_mask
= new_mode_mask
;
384 set_freq(c
, (V4L2_TUNER_RADIO
== t
->mode
) ? t
->radio_freq
: t
->tv_freq
);
385 tuner_dbg("%s %s I2C addr 0x%02x with type %d used for 0x%02x\n",
386 c
->adapter
->name
, c
->driver
->driver
.name
, c
->addr
<< 1, type
,
388 tuner_i2c_address_check(t
);
392 * This function apply tuner config to tuner specified
393 * by tun_setup structure. I addr is unset, then admin status
394 * and tun addr status is more precise then current status,
395 * it's applied. Otherwise status and type are applied only to
396 * tuner with exactly the same addr.
399 static void set_addr(struct i2c_client
*c
, struct tuner_setup
*tun_setup
)
401 struct tuner
*t
= i2c_get_clientdata(c
);
403 tuner_dbg("set addr for type %i\n", t
->type
);
405 if ( (t
->type
== UNSET
&& ((tun_setup
->addr
== ADDR_UNSET
) &&
406 (t
->mode_mask
& tun_setup
->mode_mask
))) ||
407 (tun_setup
->addr
== c
->addr
)) {
408 set_type(c
, tun_setup
->type
, tun_setup
->mode_mask
,
409 tun_setup
->config
, tun_setup
->tuner_callback
);
413 static inline int check_mode(struct tuner
*t
, char *cmd
)
415 if ((1 << t
->mode
& t
->mode_mask
) == 0) {
420 case V4L2_TUNER_RADIO
:
421 tuner_dbg("Cmd %s accepted for radio\n", cmd
);
423 case V4L2_TUNER_ANALOG_TV
:
424 tuner_dbg("Cmd %s accepted for analog TV\n", cmd
);
426 case V4L2_TUNER_DIGITAL_TV
:
427 tuner_dbg("Cmd %s accepted for digital TV\n", cmd
);
433 /* get more precise norm info from insmod option */
434 static int tuner_fixup_std(struct tuner
*t
)
436 if ((t
->std
& V4L2_STD_PAL
) == V4L2_STD_PAL
) {
439 tuner_dbg ("insmod fixup: PAL => PAL-60\n");
440 t
->std
= V4L2_STD_PAL_60
;
446 tuner_dbg ("insmod fixup: PAL => PAL-BG\n");
447 t
->std
= V4L2_STD_PAL_BG
;
451 tuner_dbg ("insmod fixup: PAL => PAL-I\n");
452 t
->std
= V4L2_STD_PAL_I
;
458 tuner_dbg ("insmod fixup: PAL => PAL-DK\n");
459 t
->std
= V4L2_STD_PAL_DK
;
463 tuner_dbg ("insmod fixup: PAL => PAL-M\n");
464 t
->std
= V4L2_STD_PAL_M
;
468 if (pal
[1] == 'c' || pal
[1] == 'C') {
469 tuner_dbg("insmod fixup: PAL => PAL-Nc\n");
470 t
->std
= V4L2_STD_PAL_Nc
;
472 tuner_dbg ("insmod fixup: PAL => PAL-N\n");
473 t
->std
= V4L2_STD_PAL_N
;
477 /* default parameter, do nothing */
480 tuner_warn ("pal= argument not recognised\n");
484 if ((t
->std
& V4L2_STD_SECAM
) == V4L2_STD_SECAM
) {
492 tuner_dbg("insmod fixup: SECAM => SECAM-BGH\n");
493 t
->std
= V4L2_STD_SECAM_B
| V4L2_STD_SECAM_G
| V4L2_STD_SECAM_H
;
499 tuner_dbg ("insmod fixup: SECAM => SECAM-DK\n");
500 t
->std
= V4L2_STD_SECAM_DK
;
504 if ((secam
[1]=='C')||(secam
[1]=='c')) {
505 tuner_dbg ("insmod fixup: SECAM => SECAM-L'\n");
506 t
->std
= V4L2_STD_SECAM_LC
;
508 tuner_dbg ("insmod fixup: SECAM => SECAM-L\n");
509 t
->std
= V4L2_STD_SECAM_L
;
513 /* default parameter, do nothing */
516 tuner_warn ("secam= argument not recognised\n");
521 if ((t
->std
& V4L2_STD_NTSC
) == V4L2_STD_NTSC
) {
525 tuner_dbg("insmod fixup: NTSC => NTSC-M\n");
526 t
->std
= V4L2_STD_NTSC_M
;
530 tuner_dbg("insmod fixup: NTSC => NTSC_M_JP\n");
531 t
->std
= V4L2_STD_NTSC_M_JP
;
535 tuner_dbg("insmod fixup: NTSC => NTSC_M_KR\n");
536 t
->std
= V4L2_STD_NTSC_M_KR
;
539 /* default parameter, do nothing */
542 tuner_info("ntsc= argument not recognised\n");
549 static void tuner_status(struct dvb_frontend
*fe
)
551 struct tuner
*t
= fe
->analog_demod_priv
;
552 unsigned long freq
, freq_fraction
;
553 struct dvb_tuner_ops
*fe_tuner_ops
= &t
->fe
.ops
.tuner_ops
;
554 struct analog_tuner_ops
*ops
= t
->fe
.ops
.analog_demod_ops
;
558 case V4L2_TUNER_RADIO
: p
= "radio"; break;
559 case V4L2_TUNER_ANALOG_TV
: p
= "analog TV"; break;
560 case V4L2_TUNER_DIGITAL_TV
: p
= "digital TV"; break;
561 default: p
= "undefined"; break;
563 if (t
->mode
== V4L2_TUNER_RADIO
) {
564 freq
= t
->radio_freq
/ 16000;
565 freq_fraction
= (t
->radio_freq
% 16000) * 100 / 16000;
567 freq
= t
->tv_freq
/ 16;
568 freq_fraction
= (t
->tv_freq
% 16) * 100 / 16;
570 tuner_info("Tuner mode: %s\n", p
);
571 tuner_info("Frequency: %lu.%02lu MHz\n", freq
, freq_fraction
);
572 tuner_info("Standard: 0x%08lx\n", (unsigned long)t
->std
);
573 if (t
->mode
!= V4L2_TUNER_RADIO
)
575 if (fe_tuner_ops
->get_status
) {
578 fe_tuner_ops
->get_status(&t
->fe
, &tuner_status
);
579 if (tuner_status
& TUNER_STATUS_LOCKED
)
580 tuner_info("Tuner is locked.\n");
581 if (tuner_status
& TUNER_STATUS_STEREO
)
582 tuner_info("Stereo: yes\n");
586 tuner_info("Signal strength: %d\n",
587 ops
->has_signal(fe
));
589 tuner_info("Stereo: %s\n",
590 ops
->is_stereo(fe
) ? "yes" : "no");
594 /* ---------------------------------------------------------------------- */
597 * Switch tuner to other mode. If tuner support both tv and radio,
598 * set another frequency to some value (This is needed for some pal
599 * tuners to avoid locking). Otherwise, just put second tuner in
603 static inline int set_mode(struct i2c_client
*client
, struct tuner
*t
, int mode
, char *cmd
)
605 struct analog_tuner_ops
*ops
= t
->fe
.ops
.analog_demod_ops
;
612 if (check_mode(t
, cmd
) == EINVAL
) {
614 if (ops
&& ops
->standby
)
615 ops
->standby(&t
->fe
);
621 #define switch_v4l2() if (!t->using_v4l2) \
622 tuner_dbg("switching to v4l2\n"); \
625 static inline int check_v4l2(struct tuner
*t
)
627 /* bttv still uses both v4l1 and v4l2 calls to the tuner (v4l2 for
628 TV, v4l1 for radio), until that is fixed this code is disabled.
629 Otherwise the radio (v4l1) wouldn't tune after using the TV (v4l2)
634 static int tuner_command(struct i2c_client
*client
, unsigned int cmd
, void *arg
)
636 struct tuner
*t
= i2c_get_clientdata(client
);
637 struct dvb_tuner_ops
*fe_tuner_ops
= &t
->fe
.ops
.tuner_ops
;
638 struct analog_tuner_ops
*ops
= t
->fe
.ops
.analog_demod_ops
;
641 v4l_i2c_print_ioctl(client
,cmd
);
644 /* --- configuration --- */
645 case TUNER_SET_TYPE_ADDR
:
646 tuner_dbg ("Calling set_type_addr for type=%d, addr=0x%02x, mode=0x%02x, config=0x%02x\n",
647 ((struct tuner_setup
*)arg
)->type
,
648 ((struct tuner_setup
*)arg
)->addr
,
649 ((struct tuner_setup
*)arg
)->mode_mask
,
650 ((struct tuner_setup
*)arg
)->config
);
652 set_addr(client
, (struct tuner_setup
*)arg
);
655 if (set_mode(client
, t
, V4L2_TUNER_RADIO
, "AUDC_SET_RADIO")
659 set_freq(client
, t
->radio_freq
);
661 case TUNER_SET_STANDBY
:
662 if (check_mode(t
, "TUNER_SET_STANDBY") == EINVAL
)
665 if (ops
&& ops
->standby
)
666 ops
->standby(&t
->fe
);
668 #ifdef CONFIG_VIDEO_V4L1
670 if (check_mode(t
, "VIDIOCSAUDIO") == EINVAL
)
672 if (check_v4l2(t
) == EINVAL
)
675 /* Should be implemented, since bttv calls it */
676 tuner_dbg("VIDIOCSAUDIO not implemented.\n");
680 static const v4l2_std_id map
[] = {
681 [VIDEO_MODE_PAL
] = V4L2_STD_PAL
,
682 [VIDEO_MODE_NTSC
] = V4L2_STD_NTSC_M
,
683 [VIDEO_MODE_SECAM
] = V4L2_STD_SECAM
,
684 [4 /* bttv */ ] = V4L2_STD_PAL_M
,
685 [5 /* bttv */ ] = V4L2_STD_PAL_N
,
686 [6 /* bttv */ ] = V4L2_STD_NTSC_M_JP
,
688 struct video_channel
*vc
= arg
;
690 if (check_v4l2(t
) == EINVAL
)
693 if (set_mode(client
,t
,V4L2_TUNER_ANALOG_TV
, "VIDIOCSCHAN")==EINVAL
)
696 if (vc
->norm
< ARRAY_SIZE(map
))
697 t
->std
= map
[vc
->norm
];
700 set_tv_freq(client
, t
->tv_freq
);
705 unsigned long *v
= arg
;
707 if (check_mode(t
, "VIDIOCSFREQ") == EINVAL
)
709 if (check_v4l2(t
) == EINVAL
)
712 set_freq(client
, *v
);
717 struct video_tuner
*vt
= arg
;
719 if (check_mode(t
, "VIDIOCGTUNER") == EINVAL
)
721 if (check_v4l2(t
) == EINVAL
)
724 if (V4L2_TUNER_RADIO
== t
->mode
) {
725 if (fe_tuner_ops
->get_status
) {
728 fe_tuner_ops
->get_status(&t
->fe
, &tuner_status
);
729 if (tuner_status
& TUNER_STATUS_STEREO
)
730 vt
->flags
|= VIDEO_TUNER_STEREO_ON
;
732 vt
->flags
&= ~VIDEO_TUNER_STEREO_ON
;
734 if (ops
&& ops
->is_stereo
) {
735 if (ops
->is_stereo(&t
->fe
))
737 VIDEO_TUNER_STEREO_ON
;
740 ~VIDEO_TUNER_STEREO_ON
;
743 if (ops
&& ops
->has_signal
)
744 vt
->signal
= ops
->has_signal(&t
->fe
);
746 vt
->flags
|= VIDEO_TUNER_LOW
; /* Allow freqs at 62.5 Hz */
748 vt
->rangelow
= radio_range
[0] * 16000;
749 vt
->rangehigh
= radio_range
[1] * 16000;
752 vt
->rangelow
= tv_range
[0] * 16;
753 vt
->rangehigh
= tv_range
[1] * 16;
760 struct video_audio
*va
= arg
;
762 if (check_mode(t
, "VIDIOCGAUDIO") == EINVAL
)
764 if (check_v4l2(t
) == EINVAL
)
767 if (V4L2_TUNER_RADIO
== t
->mode
) {
768 if (fe_tuner_ops
->get_status
) {
771 fe_tuner_ops
->get_status(&t
->fe
, &tuner_status
);
772 va
->mode
= (tuner_status
& TUNER_STATUS_STEREO
)
773 ? VIDEO_SOUND_STEREO
: VIDEO_SOUND_MONO
;
774 } else if (ops
&& ops
->is_stereo
)
775 va
->mode
= ops
->is_stereo(&t
->fe
)
776 ? VIDEO_SOUND_STEREO
: VIDEO_SOUND_MONO
;
781 case TUNER_SET_CONFIG
:
783 struct dvb_tuner_ops
*fe_tuner_ops
= &t
->fe
.ops
.tuner_ops
;
784 struct v4l2_priv_tun_config
*cfg
= arg
;
786 if (t
->type
!= cfg
->tuner
)
789 if (t
->type
== TUNER_TDA9887
) {
790 t
->tda9887_config
= *(unsigned int *)cfg
->priv
;
791 set_freq(client
, t
->tv_freq
);
795 if (NULL
== fe_tuner_ops
->set_config
) {
796 tuner_warn("Tuner frontend module has no way to "
800 fe_tuner_ops
->set_config(&t
->fe
, cfg
->priv
);
804 /* --- v4l ioctls --- */
805 /* take care: bttv does userspace copying, we'll get a
806 kernel pointer here... */
809 v4l2_std_id
*id
= arg
;
811 if (set_mode (client
, t
, V4L2_TUNER_ANALOG_TV
, "VIDIOC_S_STD")
820 set_freq(client
, t
->tv_freq
);
823 case VIDIOC_S_FREQUENCY
:
825 struct v4l2_frequency
*f
= arg
;
827 if (set_mode (client
, t
, f
->type
, "VIDIOC_S_FREQUENCY")
831 set_freq(client
,f
->frequency
);
835 case VIDIOC_G_FREQUENCY
:
837 struct v4l2_frequency
*f
= arg
;
839 if (check_mode(t
, "VIDIOC_G_FREQUENCY") == EINVAL
)
843 if (fe_tuner_ops
->get_frequency
) {
846 fe_tuner_ops
->get_frequency(&t
->fe
, &abs_freq
);
847 f
->frequency
= (V4L2_TUNER_RADIO
== t
->mode
) ?
848 (abs_freq
* 2 + 125/2) / 125 :
849 (abs_freq
+ 62500/2) / 62500;
852 f
->frequency
= (V4L2_TUNER_RADIO
== t
->mode
) ?
853 t
->radio_freq
: t
->tv_freq
;
858 struct v4l2_tuner
*tuner
= arg
;
860 if (check_mode(t
, "VIDIOC_G_TUNER") == EINVAL
)
864 tuner
->type
= t
->mode
;
865 if (ops
&& ops
->get_afc
)
866 tuner
->afc
= ops
->get_afc(&t
->fe
);
867 if (t
->mode
== V4L2_TUNER_ANALOG_TV
)
868 tuner
->capability
|= V4L2_TUNER_CAP_NORM
;
869 if (t
->mode
!= V4L2_TUNER_RADIO
) {
870 tuner
->rangelow
= tv_range
[0] * 16;
871 tuner
->rangehigh
= tv_range
[1] * 16;
877 V4L2_TUNER_SUB_MONO
| V4L2_TUNER_SUB_STEREO
;
878 if (fe_tuner_ops
->get_status
) {
881 fe_tuner_ops
->get_status(&t
->fe
, &tuner_status
);
883 (tuner_status
& TUNER_STATUS_STEREO
) ?
884 V4L2_TUNER_SUB_STEREO
:
887 if (ops
&& ops
->is_stereo
) {
889 ops
->is_stereo(&t
->fe
) ?
890 V4L2_TUNER_SUB_STEREO
:
894 if (ops
&& ops
->has_signal
)
895 tuner
->signal
= ops
->has_signal(&t
->fe
);
897 V4L2_TUNER_CAP_LOW
| V4L2_TUNER_CAP_STEREO
;
898 tuner
->audmode
= t
->audmode
;
899 tuner
->rangelow
= radio_range
[0] * 16000;
900 tuner
->rangehigh
= radio_range
[1] * 16000;
905 struct v4l2_tuner
*tuner
= arg
;
907 if (check_mode(t
, "VIDIOC_S_TUNER") == EINVAL
)
912 /* do nothing unless we're a radio tuner */
913 if (t
->mode
!= V4L2_TUNER_RADIO
)
915 t
->audmode
= tuner
->audmode
;
916 set_radio_freq(client
, t
->radio_freq
);
919 case VIDIOC_LOG_STATUS
:
920 if (ops
&& ops
->tuner_status
)
921 ops
->tuner_status(&t
->fe
);
928 static int tuner_suspend(struct i2c_client
*c
, pm_message_t state
)
930 struct tuner
*t
= i2c_get_clientdata(c
);
932 tuner_dbg("suspend\n");
933 /* FIXME: power down ??? */
937 static int tuner_resume(struct i2c_client
*c
)
939 struct tuner
*t
= i2c_get_clientdata(c
);
941 tuner_dbg("resume\n");
942 if (V4L2_TUNER_RADIO
== t
->mode
) {
944 set_freq(c
, t
->radio_freq
);
947 set_freq(c
, t
->tv_freq
);
952 /* ---------------------------------------------------------------------- */
954 LIST_HEAD(tuner_list
);
956 /* Search for existing radio and/or TV tuners on the given I2C adapter.
957 Note that when this function is called from tuner_probe you can be
958 certain no other devices will be added/deleted at the same time, I2C
959 core protects against that. */
960 static void tuner_lookup(struct i2c_adapter
*adap
,
961 struct tuner
**radio
, struct tuner
**tv
)
968 list_for_each_entry(pos
, &tuner_list
, list
) {
971 if (pos
->i2c
->adapter
!= adap
||
972 pos
->i2c
->driver
->id
!= I2C_DRIVERID_TUNER
)
975 mode_mask
= pos
->mode_mask
& ~T_STANDBY
;
976 if (*radio
== NULL
&& mode_mask
== T_RADIO
)
978 /* Note: currently TDA9887 is the only demod-only
979 device. If other devices appear then we need to
980 make this test more general. */
981 else if (*tv
== NULL
&& pos
->type
!= TUNER_TDA9887
&&
982 (pos
->mode_mask
& (T_ANALOG_TV
| T_DIGITAL_TV
)))
987 /* During client attach, set_type is called by adapter's attach_inform callback.
988 set_type must then be completed by tuner_probe.
990 static int tuner_probe(struct i2c_client
*client
)
996 t
= kzalloc(sizeof(struct tuner
), GFP_KERNEL
);
1000 strlcpy(client
->name
, "(tuner unset)", sizeof(client
->name
));
1001 i2c_set_clientdata(client
, t
);
1003 t
->audmode
= V4L2_TUNER_MODE_STEREO
;
1004 t
->mode_mask
= T_UNINITIALIZED
;
1007 unsigned char buffer
[16];
1010 memset(buffer
, 0, sizeof(buffer
));
1011 rc
= i2c_master_recv(client
, buffer
, sizeof(buffer
));
1012 tuner_info("I2C RECV = ");
1013 for (i
= 0; i
< rc
; i
++)
1014 printk(KERN_CONT
"%02x ", buffer
[i
]);
1017 /* HACK: This test was added to avoid tuner to probe tda9840 and
1018 tea6415c on the MXB card */
1019 if (client
->adapter
->id
== I2C_HW_SAA7146
&& client
->addr
< 0x4a) {
1024 /* autodetection code based on the i2c addr */
1025 if (!no_autodetect
) {
1026 switch (client
->addr
) {
1028 if (tea5761_autodetection(t
->i2c
->adapter
, t
->i2c
->addr
)
1030 t
->type
= TUNER_TEA5761
;
1031 t
->mode_mask
= T_RADIO
;
1032 t
->mode
= T_STANDBY
;
1033 /* Sets freq to FM range */
1034 t
->radio_freq
= 87.5 * 16000;
1035 tuner_lookup(t
->i2c
->adapter
, &radio
, &tv
);
1037 tv
->mode_mask
&= ~T_RADIO
;
1039 goto register_client
;
1046 /* If chip is not tda8290, don't register.
1047 since it can be tda9887*/
1048 if (tda829x_probe(t
) == 0) {
1049 tuner_dbg("tda829x detected\n");
1051 /* Default is being tda9887 */
1052 t
->type
= TUNER_TDA9887
;
1053 t
->mode_mask
= T_RADIO
| T_ANALOG_TV
|
1055 t
->mode
= T_STANDBY
;
1056 goto register_client
;
1060 if (tea5767_autodetection(t
->i2c
->adapter
, t
->i2c
->addr
)
1062 t
->type
= TUNER_TEA5767
;
1063 t
->mode_mask
= T_RADIO
;
1064 t
->mode
= T_STANDBY
;
1065 /* Sets freq to FM range */
1066 t
->radio_freq
= 87.5 * 16000;
1067 tuner_lookup(t
->i2c
->adapter
, &radio
, &tv
);
1069 tv
->mode_mask
&= ~T_RADIO
;
1071 goto register_client
;
1077 /* Initializes only the first TV tuner on this adapter. Why only the
1078 first? Because there are some devices (notably the ones with TI
1079 tuners) that have more than one i2c address for the *same* device.
1080 Experience shows that, except for just one case, the first
1081 address is the right one. The exception is a Russian tuner
1082 (ACORP_Y878F). So, the desired behavior is just to enable the
1083 first found TV tuner. */
1084 tuner_lookup(t
->i2c
->adapter
, &radio
, &tv
);
1086 t
->mode_mask
= T_ANALOG_TV
| T_DIGITAL_TV
;
1088 t
->mode_mask
|= T_RADIO
;
1089 tuner_dbg("Setting mode_mask to 0x%02x\n", t
->mode_mask
);
1090 t
->tv_freq
= 400 * 16; /* Sets freq to VHF High */
1091 t
->radio_freq
= 87.5 * 16000; /* Sets freq to FM range */
1094 /* Should be just before return */
1096 tuner_info("chip found @ 0x%x (%s)\n", client
->addr
<< 1,
1097 client
->adapter
->name
);
1099 /* Sets a default mode */
1100 if (t
->mode_mask
& T_ANALOG_TV
) {
1101 t
->mode
= T_ANALOG_TV
;
1102 } else if (t
->mode_mask
& T_RADIO
) {
1105 t
->mode
= T_DIGITAL_TV
;
1107 set_type(client
, t
->type
, t
->mode_mask
, t
->config
, t
->tuner_callback
);
1108 list_add_tail(&t
->list
, &tuner_list
);
1112 static int tuner_legacy_probe(struct i2c_adapter
*adap
)
1115 normal_i2c
[0] = addr
;
1116 normal_i2c
[1] = I2C_CLIENT_END
;
1119 if ((adap
->class & I2C_CLASS_TV_ANALOG
) == 0)
1122 /* HACK: Ignore 0x6b and 0x6f on cx88 boards.
1123 * FusionHDTV5 RT Gold has an ir receiver at 0x6b
1124 * and an RTC at 0x6f which can get corrupted if probed.
1126 if ((adap
->id
== I2C_HW_B_CX2388x
) ||
1127 (adap
->id
== I2C_HW_B_CX23885
)) {
1130 while (i
< I2C_CLIENT_MAX_OPTS
&& ignore
[i
] != I2C_CLIENT_END
)
1132 if (i
+ 4 < I2C_CLIENT_MAX_OPTS
) {
1133 ignore
[i
+0] = adap
->nr
;
1135 ignore
[i
+2] = adap
->nr
;
1137 ignore
[i
+4] = I2C_CLIENT_END
;
1139 printk(KERN_WARNING
"tuner: "
1140 "too many options specified "
1141 "in i2c probe ignore list!\n");
1146 static int tuner_remove(struct i2c_client
*client
)
1148 struct tuner
*t
= i2c_get_clientdata(client
);
1149 struct analog_tuner_ops
*ops
= t
->fe
.ops
.analog_demod_ops
;
1151 if (ops
&& ops
->release
)
1152 ops
->release(&t
->fe
);
1159 /* ----------------------------------------------------------------------- */
1161 static struct v4l2_i2c_driver_data v4l2_i2c_data
= {
1163 .driverid
= I2C_DRIVERID_TUNER
,
1164 .command
= tuner_command
,
1165 .probe
= tuner_probe
,
1166 .remove
= tuner_remove
,
1167 .suspend
= tuner_suspend
,
1168 .resume
= tuner_resume
,
1169 .legacy_probe
= tuner_legacy_probe
,
1174 * Overrides for Emacs so that we follow Linus's tabbing style.
1175 * ---------------------------------------------------------------------------