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 "tuner-driver.h"
27 #include "tuner-simple.h"
31 /* standard i2c insmod options */
32 static unsigned short normal_i2c[] = {
33 #if defined(CONFIG_TUNER_TEA5761) || (defined(CONFIG_TUNER_TEA5761_MODULE) && defined(MODULE))
36 0x42, 0x43, 0x4a, 0x4b, /* tda8290 */
37 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67,
38 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,
44 /* insmod options used at init time => read/only */
45 static unsigned int addr = 0;
46 static unsigned int no_autodetect = 0;
47 static unsigned int show_i2c = 0;
49 /* insmod options used at runtime => read/write */
52 static unsigned int tv_range[2] = { 44, 958 };
53 static unsigned int radio_range[2] = { 65, 108 };
55 static char pal[] = "--";
56 static char secam[] = "--";
57 static char ntsc[] = "-";
60 module_param(addr, int, 0444);
61 module_param(no_autodetect, int, 0444);
62 module_param(show_i2c, int, 0444);
63 module_param_named(debug,tuner_debug, int, 0644);
64 module_param_string(pal, pal, sizeof(pal), 0644);
65 module_param_string(secam, secam, sizeof(secam), 0644);
66 module_param_string(ntsc, ntsc, sizeof(ntsc), 0644);
67 module_param_array(tv_range, int, NULL, 0644);
68 module_param_array(radio_range, int, NULL, 0644);
70 MODULE_DESCRIPTION("device driver for various TV and TV+FM radio tuners");
71 MODULE_AUTHOR("Ralph Metzler, Gerd Knorr, Gunther Mayer");
72 MODULE_LICENSE("GPL");
74 static struct i2c_driver driver;
75 static struct i2c_client client_template;
77 /* ---------------------------------------------------------------------- */
79 static void fe_set_freq(struct tuner *t, unsigned int freq)
81 struct dvb_tuner_ops *fe_tuner_ops = &t->fe.ops.tuner_ops;
83 struct analog_parameters params = {
86 .audmode = t->audmode,
90 if (NULL == fe_tuner_ops->set_analog_params) {
91 tuner_warn("Tuner frontend module has no way to set freq\n");
94 fe_tuner_ops->set_analog_params(&t->fe, ¶ms);
97 static void fe_release(struct tuner *t)
99 struct dvb_tuner_ops *fe_tuner_ops = &t->fe.ops.tuner_ops;
101 if (fe_tuner_ops->release)
102 fe_tuner_ops->release(&t->fe);
105 static void fe_standby(struct tuner *t)
107 struct dvb_tuner_ops *fe_tuner_ops = &t->fe.ops.tuner_ops;
109 if (fe_tuner_ops->sleep)
110 fe_tuner_ops->sleep(&t->fe);
113 static int fe_has_signal(struct tuner *t)
115 struct dvb_tuner_ops *fe_tuner_ops = &t->fe.ops.tuner_ops;
118 if (fe_tuner_ops->get_rf_strength)
119 fe_tuner_ops->get_rf_strength(&t->fe, &strength);
124 /* Set tuner frequency, freq in Units of 62.5kHz = 1/16MHz */
125 static void set_tv_freq(struct i2c_client *c, unsigned int freq)
127 struct tuner *t = i2c_get_clientdata(c);
129 if (t->type == UNSET) {
130 tuner_warn ("tuner type not set\n");
133 if (NULL == t->ops.set_tv_freq) {
134 tuner_warn ("Tuner has no way to set tv freq\n");
137 if (freq < tv_range[0] * 16 || freq > tv_range[1] * 16) {
138 tuner_dbg ("TV freq (%d.%02d) out of range (%d-%d)\n",
139 freq / 16, freq % 16 * 100 / 16, tv_range[0],
141 /* V4L2 spec: if the freq is not possible then the closest
142 possible value should be selected */
143 if (freq < tv_range[0] * 16)
144 freq = tv_range[0] * 16;
146 freq = tv_range[1] * 16;
148 t->ops.set_tv_freq(t, freq);
151 static void set_radio_freq(struct i2c_client *c, unsigned int freq)
153 struct tuner *t = i2c_get_clientdata(c);
155 if (t->type == UNSET) {
156 tuner_warn ("tuner type not set\n");
159 if (NULL == t->ops.set_radio_freq) {
160 tuner_warn ("tuner has no way to set radio frequency\n");
163 if (freq < radio_range[0] * 16000 || freq > radio_range[1] * 16000) {
164 tuner_dbg ("radio freq (%d.%02d) out of range (%d-%d)\n",
165 freq / 16000, freq % 16000 * 100 / 16000,
166 radio_range[0], radio_range[1]);
167 /* V4L2 spec: if the freq is not possible then the closest
168 possible value should be selected */
169 if (freq < radio_range[0] * 16000)
170 freq = radio_range[0] * 16000;
172 freq = radio_range[1] * 16000;
175 t->ops.set_radio_freq(t, freq);
178 static void set_freq(struct i2c_client *c, unsigned long freq)
180 struct tuner *t = i2c_get_clientdata(c);
183 case V4L2_TUNER_RADIO:
184 tuner_dbg("radio freq set to %lu.%02lu\n",
185 freq / 16000, freq % 16000 * 100 / 16000);
186 set_radio_freq(c, freq);
187 t->radio_freq = freq;
189 case V4L2_TUNER_ANALOG_TV:
190 case V4L2_TUNER_DIGITAL_TV:
191 tuner_dbg("tv freq set to %lu.%02lu\n",
192 freq / 16, freq % 16 * 100 / 16);
193 set_tv_freq(c, freq);
197 tuner_dbg("freq set: unknown mode: 0x%04x!\n",t->mode);
201 static void tuner_i2c_address_check(struct tuner *t)
203 if ((t->type == UNSET || t->type == TUNER_ABSENT) ||
204 ((t->i2c.addr < 0x64) || (t->i2c.addr > 0x6f)))
207 tuner_warn("====================== WARNING! ======================\n");
208 tuner_warn("Support for tuners in i2c address range 0x64 thru 0x6f\n");
209 tuner_warn("will soon be dropped. This message indicates that your\n");
210 tuner_warn("hardware has a %s tuner at i2c address 0x%02x.\n",
211 t->i2c.name, t->i2c.addr);
212 tuner_warn("To ensure continued support for your device, please\n");
213 tuner_warn("send a copy of this message, along with full dmesg\n");
214 tuner_warn("output to v4l-dvb-maintainer@linuxtv.org\n");
215 tuner_warn("Please use subject line: \"obsolete tuner i2c address.\"\n");
216 tuner_warn("driver: %s, addr: 0x%02x, type: %d (%s)\n",
217 t->i2c.adapter->name, t->i2c.addr, t->type,
218 tuners[t->type].name);
219 tuner_warn("====================== WARNING! ======================\n");
222 static void attach_tda8290(struct tuner *t)
224 struct tda8290_config cfg = {
225 .lna_cfg = &t->config,
226 .tuner_callback = t->tuner_callback
228 tda8290_attach(&t->fe, t->i2c.adapter, t->i2c.addr, &cfg);
231 static void attach_simple_tuner(struct tuner *t)
233 struct simple_tuner_config cfg = {
235 .tun = &tuners[t->type]
237 simple_tuner_attach(&t->fe, t->i2c.adapter, t->i2c.addr, &cfg);
240 static void set_type(struct i2c_client *c, unsigned int type,
241 unsigned int new_mode_mask, unsigned int new_config,
242 int (*tuner_callback) (void *dev, int command,int arg))
244 struct tuner *t = i2c_get_clientdata(c);
245 struct dvb_tuner_ops *fe_tuner_ops = &t->fe.ops.tuner_ops;
246 unsigned char buffer[4];
248 if (type == UNSET || type == TUNER_ABSENT) {
249 tuner_dbg ("tuner 0x%02x: Tuner type absent\n",c->addr);
253 if (type >= tuner_count) {
254 tuner_warn ("tuner 0x%02x: Tuner count greater than %d\n",c->addr,tuner_count);
259 t->config = new_config;
260 if (tuner_callback != NULL) {
261 tuner_dbg("defining GPIO callback\n");
262 t->tuner_callback = tuner_callback;
265 /* This code detects calls by card attach_inform */
266 if (NULL == t->i2c.dev.driver) {
267 tuner_dbg ("tuner 0x%02x: called during i2c_client register by adapter's attach_inform\n", c->addr);
272 /* discard private data, in case set_type() was previously called */
282 microtune_attach(&t->fe, t->i2c.adapter, t->i2c.addr);
284 case TUNER_PHILIPS_TDA8290:
290 if (tea5767_attach(&t->fe, t->i2c.adapter, t->i2c.addr) == NULL) {
291 t->type = TUNER_ABSENT;
292 t->mode_mask = T_UNINITIALIZED;
295 t->mode_mask = T_RADIO;
298 if (tea5761_attach(&t->fe, t->i2c.adapter, t->i2c.addr) == NULL) {
299 t->type = TUNER_ABSENT;
300 t->mode_mask = T_UNINITIALIZED;
303 t->mode_mask = T_RADIO;
305 case TUNER_PHILIPS_FMD1216ME_MK3:
310 i2c_master_send(c, buffer, 4);
314 i2c_master_send(c, buffer, 4);
315 attach_simple_tuner(t);
317 case TUNER_PHILIPS_TD1316:
322 i2c_master_send(c,buffer,4);
323 attach_simple_tuner(t);
326 xc2028_tuner_init(c);
329 tda9887_tuner_init(t);
332 attach_simple_tuner(t);
336 if (fe_tuner_ops->set_analog_params) {
337 strlcpy(t->i2c.name, fe_tuner_ops->info.name, sizeof(t->i2c.name));
339 t->ops.set_tv_freq = fe_set_freq;
340 t->ops.set_radio_freq = fe_set_freq;
341 t->ops.standby = fe_standby;
342 t->ops.release = fe_release;
343 t->ops.has_signal = fe_has_signal;
346 tuner_info("type set to %s\n", t->i2c.name);
348 if (t->mode_mask == T_UNINITIALIZED)
349 t->mode_mask = new_mode_mask;
351 set_freq(c, (V4L2_TUNER_RADIO == t->mode) ? t->radio_freq : t->tv_freq);
352 tuner_dbg("%s %s I2C addr 0x%02x with type %d used for 0x%02x\n",
353 c->adapter->name, c->driver->driver.name, c->addr << 1, type,
355 tuner_i2c_address_check(t);
359 * This function apply tuner config to tuner specified
360 * by tun_setup structure. I addr is unset, then admin status
361 * and tun addr status is more precise then current status,
362 * it's applied. Otherwise status and type are applied only to
363 * tuner with exactly the same addr.
366 static void set_addr(struct i2c_client *c, struct tuner_setup *tun_setup)
368 struct tuner *t = i2c_get_clientdata(c);
370 tuner_dbg("set addr for type %i\n", t->type);
372 if ( (t->type == UNSET && ((tun_setup->addr == ADDR_UNSET) &&
373 (t->mode_mask & tun_setup->mode_mask))) ||
374 (tun_setup->addr == c->addr)) {
375 set_type(c, tun_setup->type, tun_setup->mode_mask,
376 tun_setup->config, tun_setup->tuner_callback);
380 static inline int check_mode(struct tuner *t, char *cmd)
382 if ((1 << t->mode & t->mode_mask) == 0) {
387 case V4L2_TUNER_RADIO:
388 tuner_dbg("Cmd %s accepted for radio\n", cmd);
390 case V4L2_TUNER_ANALOG_TV:
391 tuner_dbg("Cmd %s accepted for analog TV\n", cmd);
393 case V4L2_TUNER_DIGITAL_TV:
394 tuner_dbg("Cmd %s accepted for digital TV\n", cmd);
400 /* get more precise norm info from insmod option */
401 static int tuner_fixup_std(struct tuner *t)
403 if ((t->std & V4L2_STD_PAL) == V4L2_STD_PAL) {
406 tuner_dbg ("insmod fixup: PAL => PAL-60\n");
407 t->std = V4L2_STD_PAL_60;
413 tuner_dbg ("insmod fixup: PAL => PAL-BG\n");
414 t->std = V4L2_STD_PAL_BG;
418 tuner_dbg ("insmod fixup: PAL => PAL-I\n");
419 t->std = V4L2_STD_PAL_I;
425 tuner_dbg ("insmod fixup: PAL => PAL-DK\n");
426 t->std = V4L2_STD_PAL_DK;
430 tuner_dbg ("insmod fixup: PAL => PAL-M\n");
431 t->std = V4L2_STD_PAL_M;
435 if (pal[1] == 'c' || pal[1] == 'C') {
436 tuner_dbg("insmod fixup: PAL => PAL-Nc\n");
437 t->std = V4L2_STD_PAL_Nc;
439 tuner_dbg ("insmod fixup: PAL => PAL-N\n");
440 t->std = V4L2_STD_PAL_N;
444 /* default parameter, do nothing */
447 tuner_warn ("pal= argument not recognised\n");
451 if ((t->std & V4L2_STD_SECAM) == V4L2_STD_SECAM) {
459 tuner_dbg("insmod fixup: SECAM => SECAM-BGH\n");
460 t->std = V4L2_STD_SECAM_B | V4L2_STD_SECAM_G | V4L2_STD_SECAM_H;
466 tuner_dbg ("insmod fixup: SECAM => SECAM-DK\n");
467 t->std = V4L2_STD_SECAM_DK;
471 if ((secam[1]=='C')||(secam[1]=='c')) {
472 tuner_dbg ("insmod fixup: SECAM => SECAM-L'\n");
473 t->std = V4L2_STD_SECAM_LC;
475 tuner_dbg ("insmod fixup: SECAM => SECAM-L\n");
476 t->std = V4L2_STD_SECAM_L;
480 /* default parameter, do nothing */
483 tuner_warn ("secam= argument not recognised\n");
488 if ((t->std & V4L2_STD_NTSC) == V4L2_STD_NTSC) {
492 tuner_dbg("insmod fixup: NTSC => NTSC-M\n");
493 t->std = V4L2_STD_NTSC_M;
497 tuner_dbg("insmod fixup: NTSC => NTSC_M_JP\n");
498 t->std = V4L2_STD_NTSC_M_JP;
502 tuner_dbg("insmod fixup: NTSC => NTSC_M_KR\n");
503 t->std = V4L2_STD_NTSC_M_KR;
506 /* default parameter, do nothing */
509 tuner_info("ntsc= argument not recognised\n");
516 static void tuner_status(struct tuner *t)
518 unsigned long freq, freq_fraction;
519 struct dvb_tuner_ops *fe_tuner_ops = &t->fe.ops.tuner_ops;
523 case V4L2_TUNER_RADIO: p = "radio"; break;
524 case V4L2_TUNER_ANALOG_TV: p = "analog TV"; break;
525 case V4L2_TUNER_DIGITAL_TV: p = "digital TV"; break;
526 default: p = "undefined"; break;
528 if (t->mode == V4L2_TUNER_RADIO) {
529 freq = t->radio_freq / 16000;
530 freq_fraction = (t->radio_freq % 16000) * 100 / 16000;
532 freq = t->tv_freq / 16;
533 freq_fraction = (t->tv_freq % 16) * 100 / 16;
535 tuner_info("Tuner mode: %s\n", p);
536 tuner_info("Frequency: %lu.%02lu MHz\n", freq, freq_fraction);
537 tuner_info("Standard: 0x%08lx\n", (unsigned long)t->std);
538 if (t->mode != V4L2_TUNER_RADIO)
540 if (fe_tuner_ops->get_status) {
543 fe_tuner_ops->get_status(&t->fe, &tuner_status);
544 if (tuner_status & TUNER_STATUS_LOCKED)
545 tuner_info("Tuner is locked.\n");
546 if (tuner_status & TUNER_STATUS_STEREO)
547 tuner_info("Stereo: yes\n");
549 if (t->ops.has_signal) {
550 tuner_info("Signal strength: %d\n", t->ops.has_signal(t));
552 if (t->ops.is_stereo) {
553 tuner_info("Stereo: %s\n", t->ops.is_stereo(t) ? "yes" : "no");
557 /* ---------------------------------------------------------------------- */
559 /* static vars: used only in tuner_attach and tuner_probe */
560 static unsigned default_mode_mask;
562 /* During client attach, set_type is called by adapter's attach_inform callback.
563 set_type must then be completed by tuner_attach.
565 static int tuner_attach(struct i2c_adapter *adap, int addr, int kind)
569 client_template.adapter = adap;
570 client_template.addr = addr;
572 t = kzalloc(sizeof(struct tuner), GFP_KERNEL);
575 memcpy(&t->i2c, &client_template, sizeof(struct i2c_client));
576 i2c_set_clientdata(&t->i2c, t);
578 t->audmode = V4L2_TUNER_MODE_STEREO;
579 t->mode_mask = T_UNINITIALIZED;
580 t->ops.tuner_status = tuner_status;
583 unsigned char buffer[16];
586 memset(buffer, 0, sizeof(buffer));
587 rc = i2c_master_recv(&t->i2c, buffer, sizeof(buffer));
588 tuner_info("I2C RECV = ");
590 printk("%02x ",buffer[i]);
593 /* HACK: This test were added to avoid tuner to probe tda9840 and tea6415c on the MXB card */
594 if (adap->id == I2C_HW_SAA7146 && addr < 0x4a)
597 /* autodetection code based on the i2c addr */
598 if (!no_autodetect) {
601 if (tea5761_autodetection(t->i2c.adapter, t->i2c.addr) != EINVAL) {
602 t->type = TUNER_TEA5761;
603 t->mode_mask = T_RADIO;
605 t->radio_freq = 87.5 * 16000; /* Sets freq to FM range */
606 default_mode_mask &= ~T_RADIO;
608 goto register_client;
615 /* If chip is not tda8290, don't register.
616 since it can be tda9887*/
617 if (tda8290_probe(t->i2c.adapter, t->i2c.addr) == 0) {
618 tuner_dbg("chip at addr %x is a tda8290\n", addr);
620 /* Default is being tda9887 */
621 t->type = TUNER_TDA9887;
622 t->mode_mask = T_RADIO | T_ANALOG_TV | T_DIGITAL_TV;
624 goto register_client;
628 if (tea5767_autodetection(t->i2c.adapter, t->i2c.addr) != EINVAL) {
629 t->type = TUNER_TEA5767;
630 t->mode_mask = T_RADIO;
632 t->radio_freq = 87.5 * 16000; /* Sets freq to FM range */
633 default_mode_mask &= ~T_RADIO;
635 goto register_client;
641 /* Initializes only the first adapter found */
642 if (default_mode_mask != T_UNINITIALIZED) {
643 tuner_dbg ("Setting mode_mask to 0x%02x\n", default_mode_mask);
644 t->mode_mask = default_mode_mask;
645 t->tv_freq = 400 * 16; /* Sets freq to VHF High */
646 t->radio_freq = 87.5 * 16000; /* Sets freq to FM range */
647 default_mode_mask = T_UNINITIALIZED;
650 /* Should be just before return */
652 tuner_info("chip found @ 0x%x (%s)\n", addr << 1, adap->name);
653 i2c_attach_client (&t->i2c);
654 set_type (&t->i2c,t->type, t->mode_mask, t->config, t->tuner_callback);
658 static int tuner_probe(struct i2c_adapter *adap)
661 normal_i2c[0] = addr;
662 normal_i2c[1] = I2C_CLIENT_END;
665 /* HACK: Ignore 0x6b and 0x6f on cx88 boards.
666 * FusionHDTV5 RT Gold has an ir receiver at 0x6b
667 * and an RTC at 0x6f which can get corrupted if probed.
669 if ((adap->id == I2C_HW_B_CX2388x) ||
670 (adap->id == I2C_HW_B_CX23885)) {
673 while (i < I2C_CLIENT_MAX_OPTS && ignore[i] != I2C_CLIENT_END)
675 if (i + 4 < I2C_CLIENT_MAX_OPTS) {
676 ignore[i+0] = adap->nr;
678 ignore[i+2] = adap->nr;
680 ignore[i+4] = I2C_CLIENT_END;
682 printk(KERN_WARNING "tuner: "
683 "too many options specified "
684 "in i2c probe ignore list!\n");
687 default_mode_mask = T_RADIO | T_ANALOG_TV | T_DIGITAL_TV;
689 if (adap->class & I2C_CLASS_TV_ANALOG)
690 return i2c_probe(adap, &addr_data, tuner_attach);
694 static int tuner_detach(struct i2c_client *client)
696 struct tuner *t = i2c_get_clientdata(client);
699 err = i2c_detach_client(&t->i2c);
702 ("Client deregistration failed, client not detached.\n");
716 * Switch tuner to other mode. If tuner support both tv and radio,
717 * set another frequency to some value (This is needed for some pal
718 * tuners to avoid locking). Otherwise, just put second tuner in
722 static inline int set_mode(struct i2c_client *client, struct tuner *t, int mode, char *cmd)
729 if (check_mode(t, cmd) == EINVAL) {
738 #define switch_v4l2() if (!t->using_v4l2) \
739 tuner_dbg("switching to v4l2\n"); \
742 static inline int check_v4l2(struct tuner *t)
744 /* bttv still uses both v4l1 and v4l2 calls to the tuner (v4l2 for
745 TV, v4l1 for radio), until that is fixed this code is disabled.
746 Otherwise the radio (v4l1) wouldn't tune after using the TV (v4l2)
751 static int tuner_command(struct i2c_client *client, unsigned int cmd, void *arg)
753 struct tuner *t = i2c_get_clientdata(client);
754 struct dvb_tuner_ops *fe_tuner_ops = &t->fe.ops.tuner_ops;
757 v4l_i2c_print_ioctl(&(t->i2c),cmd);
760 /* --- configuration --- */
761 case TUNER_SET_TYPE_ADDR:
762 tuner_dbg ("Calling set_type_addr for type=%d, addr=0x%02x, mode=0x%02x, config=0x%02x\n",
763 ((struct tuner_setup *)arg)->type,
764 ((struct tuner_setup *)arg)->addr,
765 ((struct tuner_setup *)arg)->mode_mask,
766 ((struct tuner_setup *)arg)->config);
768 set_addr(client, (struct tuner_setup *)arg);
771 if (set_mode(client, t, V4L2_TUNER_RADIO, "AUDC_SET_RADIO")
775 set_freq(client, t->radio_freq);
777 case TUNER_SET_STANDBY:
778 if (check_mode(t, "TUNER_SET_STANDBY") == EINVAL)
784 #ifdef CONFIG_VIDEO_V4L1
786 if (check_mode(t, "VIDIOCSAUDIO") == EINVAL)
788 if (check_v4l2(t) == EINVAL)
791 /* Should be implemented, since bttv calls it */
792 tuner_dbg("VIDIOCSAUDIO not implemented.\n");
796 static const v4l2_std_id map[] = {
797 [VIDEO_MODE_PAL] = V4L2_STD_PAL,
798 [VIDEO_MODE_NTSC] = V4L2_STD_NTSC_M,
799 [VIDEO_MODE_SECAM] = V4L2_STD_SECAM,
800 [4 /* bttv */ ] = V4L2_STD_PAL_M,
801 [5 /* bttv */ ] = V4L2_STD_PAL_N,
802 [6 /* bttv */ ] = V4L2_STD_NTSC_M_JP,
804 struct video_channel *vc = arg;
806 if (check_v4l2(t) == EINVAL)
809 if (set_mode(client,t,V4L2_TUNER_ANALOG_TV, "VIDIOCSCHAN")==EINVAL)
812 if (vc->norm < ARRAY_SIZE(map))
813 t->std = map[vc->norm];
816 set_tv_freq(client, t->tv_freq);
821 unsigned long *v = arg;
823 if (check_mode(t, "VIDIOCSFREQ") == EINVAL)
825 if (check_v4l2(t) == EINVAL)
828 set_freq(client, *v);
833 struct video_tuner *vt = arg;
835 if (check_mode(t, "VIDIOCGTUNER") == EINVAL)
837 if (check_v4l2(t) == EINVAL)
840 if (V4L2_TUNER_RADIO == t->mode) {
841 if (fe_tuner_ops->get_status) {
844 fe_tuner_ops->get_status(&t->fe, &tuner_status);
845 if (tuner_status & TUNER_STATUS_STEREO)
846 vt->flags |= VIDEO_TUNER_STEREO_ON;
848 vt->flags &= ~VIDEO_TUNER_STEREO_ON;
850 if (t->ops.is_stereo) {
851 if (t->ops.is_stereo(t))
853 VIDEO_TUNER_STEREO_ON;
856 ~VIDEO_TUNER_STEREO_ON;
859 if (t->ops.has_signal)
860 vt->signal = t->ops.has_signal(t);
862 vt->flags |= VIDEO_TUNER_LOW; /* Allow freqs at 62.5 Hz */
864 vt->rangelow = radio_range[0] * 16000;
865 vt->rangehigh = radio_range[1] * 16000;
868 vt->rangelow = tv_range[0] * 16;
869 vt->rangehigh = tv_range[1] * 16;
876 struct video_audio *va = arg;
878 if (check_mode(t, "VIDIOCGAUDIO") == EINVAL)
880 if (check_v4l2(t) == EINVAL)
883 if (V4L2_TUNER_RADIO == t->mode) {
884 if (fe_tuner_ops->get_status) {
887 fe_tuner_ops->get_status(&t->fe, &tuner_status);
888 va->mode = (tuner_status & TUNER_STATUS_STEREO)
889 ? VIDEO_SOUND_STEREO : VIDEO_SOUND_MONO;
890 } else if (t->ops.is_stereo)
891 va->mode = t->ops.is_stereo(t)
892 ? VIDEO_SOUND_STEREO : VIDEO_SOUND_MONO;
897 case TUNER_SET_CONFIG:
899 struct dvb_tuner_ops *fe_tuner_ops = &t->fe.ops.tuner_ops;
900 struct v4l2_priv_tun_config *cfg = arg;
902 if (t->type != cfg->tuner)
905 if (t->type == TUNER_TDA9887) {
906 t->tda9887_config = *(unsigned int *)cfg->priv;
907 set_freq(client, t->tv_freq);
911 if (NULL == fe_tuner_ops->set_config) {
912 tuner_warn("Tuner frontend module has no way to "
916 fe_tuner_ops->set_config(&t->fe, cfg->priv);
920 /* --- v4l ioctls --- */
921 /* take care: bttv does userspace copying, we'll get a
922 kernel pointer here... */
925 v4l2_std_id *id = arg;
927 if (set_mode (client, t, V4L2_TUNER_ANALOG_TV, "VIDIOC_S_STD")
936 set_freq(client, t->tv_freq);
939 case VIDIOC_S_FREQUENCY:
941 struct v4l2_frequency *f = arg;
943 if (set_mode (client, t, f->type, "VIDIOC_S_FREQUENCY")
947 set_freq(client,f->frequency);
951 case VIDIOC_G_FREQUENCY:
953 struct v4l2_frequency *f = arg;
955 if (check_mode(t, "VIDIOC_G_FREQUENCY") == EINVAL)
959 if (fe_tuner_ops->get_frequency) {
962 fe_tuner_ops->get_frequency(&t->fe, &abs_freq);
963 f->frequency = (V4L2_TUNER_RADIO == t->mode) ?
964 (abs_freq * 2 + 125/2) / 125 :
965 (abs_freq + 62500/2) / 62500;
968 f->frequency = (V4L2_TUNER_RADIO == t->mode) ?
969 t->radio_freq : t->tv_freq;
974 struct v4l2_tuner *tuner = arg;
976 if (check_mode(t, "VIDIOC_G_TUNER") == EINVAL)
980 tuner->type = t->mode;
982 tuner->afc=t->ops.get_afc(t);
983 if (t->mode == V4L2_TUNER_ANALOG_TV)
984 tuner->capability |= V4L2_TUNER_CAP_NORM;
985 if (t->mode != V4L2_TUNER_RADIO) {
986 tuner->rangelow = tv_range[0] * 16;
987 tuner->rangehigh = tv_range[1] * 16;
993 V4L2_TUNER_SUB_MONO | V4L2_TUNER_SUB_STEREO;
994 if (fe_tuner_ops->get_status) {
997 fe_tuner_ops->get_status(&t->fe, &tuner_status);
998 tuner->rxsubchans = (tuner_status & TUNER_STATUS_STEREO) ?
999 V4L2_TUNER_SUB_STEREO : V4L2_TUNER_SUB_MONO;
1001 if (t->ops.is_stereo) {
1002 tuner->rxsubchans = t->ops.is_stereo(t) ?
1003 V4L2_TUNER_SUB_STEREO : V4L2_TUNER_SUB_MONO;
1006 if (t->ops.has_signal)
1007 tuner->signal = t->ops.has_signal(t);
1008 tuner->capability |=
1009 V4L2_TUNER_CAP_LOW | V4L2_TUNER_CAP_STEREO;
1010 tuner->audmode = t->audmode;
1011 tuner->rangelow = radio_range[0] * 16000;
1012 tuner->rangehigh = radio_range[1] * 16000;
1015 case VIDIOC_S_TUNER:
1017 struct v4l2_tuner *tuner = arg;
1019 if (check_mode(t, "VIDIOC_S_TUNER") == EINVAL)
1024 /* do nothing unless we're a radio tuner */
1025 if (t->mode != V4L2_TUNER_RADIO)
1027 t->audmode = tuner->audmode;
1028 set_radio_freq(client, t->radio_freq);
1031 case VIDIOC_LOG_STATUS:
1032 if (t->ops.tuner_status)
1033 t->ops.tuner_status(t);
1040 static int tuner_suspend(struct i2c_client *c, pm_message_t state)
1042 struct tuner *t = i2c_get_clientdata (c);
1044 tuner_dbg ("suspend\n");
1045 /* FIXME: power down ??? */
1049 static int tuner_resume(struct i2c_client *c)
1051 struct tuner *t = i2c_get_clientdata (c);
1053 tuner_dbg ("resume\n");
1054 if (V4L2_TUNER_RADIO == t->mode) {
1056 set_freq(c, t->radio_freq);
1059 set_freq(c, t->tv_freq);
1064 /* ----------------------------------------------------------------------- */
1066 static struct i2c_driver driver = {
1067 .id = I2C_DRIVERID_TUNER,
1068 .attach_adapter = tuner_probe,
1069 .detach_client = tuner_detach,
1070 .command = tuner_command,
1071 .suspend = tuner_suspend,
1072 .resume = tuner_resume,
1077 static struct i2c_client client_template = {
1078 .name = "(tuner unset)",
1082 static int __init tuner_init_module(void)
1084 return i2c_add_driver(&driver);
1087 static void __exit tuner_cleanup_module(void)
1089 i2c_del_driver(&driver);
1092 module_init(tuner_init_module);
1093 module_exit(tuner_cleanup_module);
1096 * Overrides for Emacs so that we follow Linus's tabbing style.
1097 * ---------------------------------------------------------------------------