aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHans Verkuil <hverkuil@xs4all.nl>2008-09-06 14:40:25 -0400
committerMauro Carvalho Chehab <mchehab@redhat.com>2008-10-12 07:37:00 -0400
commit707ecf4603a9439dcf409e13c5e9ed4e164ddfff (patch)
tree276b2ff411c90e42716f71be52bfa4e9d7ece382
parent6bd6dff6318397b1127dd256b65dde007306b8ea (diff)
V4L/DVB (8941): mxb/tda9840: cleanups, use module saa7115 instead of saa7111.
Cleanup tda9840 and use a v4l2 API to get the tuner subchannels. Do some cleanups in mxb and switch to saa7115 instead of the saa7111 module. Signed-off-by: Hans Verkuil <hverkuil@xs4all.nl> Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
-rw-r--r--drivers/media/video/Kconfig2
-rw-r--r--drivers/media/video/mxb.c213
-rw-r--r--drivers/media/video/tda9840.c112
-rw-r--r--drivers/media/video/tda9840.h21
4 files changed, 122 insertions, 226 deletions
diff --git a/drivers/media/video/Kconfig b/drivers/media/video/Kconfig
index 7f7482bff142..e28e292fe202 100644
--- a/drivers/media/video/Kconfig
+++ b/drivers/media/video/Kconfig
@@ -691,7 +691,7 @@ config VIDEO_MXB
691 depends on PCI && VIDEO_V4L1 && I2C 691 depends on PCI && VIDEO_V4L1 && I2C
692 select VIDEO_SAA7146_VV 692 select VIDEO_SAA7146_VV
693 select VIDEO_TUNER 693 select VIDEO_TUNER
694 select VIDEO_SAA7111 if VIDEO_HELPER_CHIPS_AUTO 694 select VIDEO_SAA7115 if VIDEO_HELPER_CHIPS_AUTO
695 select VIDEO_TDA9840 if VIDEO_HELPER_CHIPS_AUTO 695 select VIDEO_TDA9840 if VIDEO_HELPER_CHIPS_AUTO
696 select VIDEO_TEA6415C if VIDEO_HELPER_CHIPS_AUTO 696 select VIDEO_TEA6415C if VIDEO_HELPER_CHIPS_AUTO
697 select VIDEO_TEA6420 if VIDEO_HELPER_CHIPS_AUTO 697 select VIDEO_TEA6420 if VIDEO_HELPER_CHIPS_AUTO
diff --git a/drivers/media/video/mxb.c b/drivers/media/video/mxb.c
index 7c9820c72a6f..621d17408297 100644
--- a/drivers/media/video/mxb.c
+++ b/drivers/media/video/mxb.c
@@ -27,6 +27,7 @@
27#include <media/tuner.h> 27#include <media/tuner.h>
28#include <linux/video_decoder.h> 28#include <linux/video_decoder.h>
29#include <media/v4l2-common.h> 29#include <media/v4l2-common.h>
30#include <media/saa7115.h>
30 31
31#include "mxb.h" 32#include "mxb.h"
32#include "tea6415c.h" 33#include "tea6415c.h"
@@ -122,6 +123,8 @@ static struct saa7146_extension_ioctls ioctls[] = {
122 { VIDIOC_S_FREQUENCY, SAA7146_EXCLUSIVE }, 123 { VIDIOC_S_FREQUENCY, SAA7146_EXCLUSIVE },
123 { VIDIOC_G_AUDIO, SAA7146_EXCLUSIVE }, 124 { VIDIOC_G_AUDIO, SAA7146_EXCLUSIVE },
124 { VIDIOC_S_AUDIO, SAA7146_EXCLUSIVE }, 125 { VIDIOC_S_AUDIO, SAA7146_EXCLUSIVE },
126 { VIDIOC_DBG_G_REGISTER, SAA7146_EXCLUSIVE },
127 { VIDIOC_DBG_S_REGISTER, SAA7146_EXCLUSIVE },
125 { MXB_S_AUDIO_CD, SAA7146_EXCLUSIVE }, /* custom control */ 128 { MXB_S_AUDIO_CD, SAA7146_EXCLUSIVE }, /* custom control */
126 { MXB_S_AUDIO_LINE, SAA7146_EXCLUSIVE }, /* custom control */ 129 { MXB_S_AUDIO_LINE, SAA7146_EXCLUSIVE }, /* custom control */
127 { 0, 0 } 130 { 0, 0 }
@@ -154,20 +157,20 @@ static int mxb_check_clients(struct device *dev, void *data)
154 struct mxb* mxb = data; 157 struct mxb* mxb = data;
155 struct i2c_client *client = i2c_verify_client(dev); 158 struct i2c_client *client = i2c_verify_client(dev);
156 159
157 if( !client ) 160 if (!client)
158 return 0; 161 return 0;
159 162
160 if( I2C_ADDR_TEA6420_1 == client->addr ) 163 if (I2C_ADDR_TEA6420_1 == client->addr)
161 mxb->tea6420_1 = client; 164 mxb->tea6420_1 = client;
162 if( I2C_ADDR_TEA6420_2 == client->addr ) 165 if (I2C_ADDR_TEA6420_2 == client->addr)
163 mxb->tea6420_2 = client; 166 mxb->tea6420_2 = client;
164 if( I2C_TEA6415C_2 == client->addr ) 167 if (I2C_TEA6415C_2 == client->addr)
165 mxb->tea6415c = client; 168 mxb->tea6415c = client;
166 if( I2C_ADDR_TDA9840 == client->addr ) 169 if (I2C_ADDR_TDA9840 == client->addr)
167 mxb->tda9840 = client; 170 mxb->tda9840 = client;
168 if( I2C_SAA7111 == client->addr ) 171 if (I2C_SAA7111 == client->addr)
169 mxb->saa7111a = client; 172 mxb->saa7111a = client;
170 if( 0x60 == client->addr ) 173 if (0x60 == client->addr)
171 mxb->tuner = client; 174 mxb->tuner = client;
172 175
173 return 0; 176 return 0;
@@ -178,23 +181,28 @@ static int mxb_probe(struct saa7146_dev* dev)
178 struct mxb* mxb = NULL; 181 struct mxb* mxb = NULL;
179 int result; 182 int result;
180 183
181 if ((result = request_module("saa7111")) < 0) { 184 result = request_module("saa7115");
185 if (result < 0) {
182 printk("mxb: saa7111 i2c module not available.\n"); 186 printk("mxb: saa7111 i2c module not available.\n");
183 return -ENODEV; 187 return -ENODEV;
184 } 188 }
185 if ((result = request_module("tea6420")) < 0) { 189 result = request_module("tea6420");
190 if (result < 0) {
186 printk("mxb: tea6420 i2c module not available.\n"); 191 printk("mxb: tea6420 i2c module not available.\n");
187 return -ENODEV; 192 return -ENODEV;
188 } 193 }
189 if ((result = request_module("tea6415c")) < 0) { 194 result = request_module("tea6415c");
195 if (result < 0) {
190 printk("mxb: tea6415c i2c module not available.\n"); 196 printk("mxb: tea6415c i2c module not available.\n");
191 return -ENODEV; 197 return -ENODEV;
192 } 198 }
193 if ((result = request_module("tda9840")) < 0) { 199 result = request_module("tda9840");
200 if (result < 0) {
194 printk("mxb: tda9840 i2c module not available.\n"); 201 printk("mxb: tda9840 i2c module not available.\n");
195 return -ENODEV; 202 return -ENODEV;
196 } 203 }
197 if ((result = request_module("tuner")) < 0) { 204 result = request_module("tuner");
205 if (result < 0) {
198 printk("mxb: tuner i2c module not available.\n"); 206 printk("mxb: tuner i2c module not available.\n");
199 return -ENODEV; 207 return -ENODEV;
200 } 208 }
@@ -293,37 +301,6 @@ static struct {
293 {-1, { 0} } 301 {-1, { 0} }
294}; 302};
295 303
296static const unsigned char mxb_saa7111_init[] = {
297 0x00, 0x00, /* 00 - ID byte */
298 0x01, 0x00, /* 01 - reserved */
299
300 /*front end */
301 0x02, 0xd8, /* 02 - FUSE=x, GUDL=x, MODE=x */
302 0x03, 0x23, /* 03 - HLNRS=0, VBSL=1, WPOFF=0, HOLDG=0, GAFIX=0, GAI1=256, GAI2=256 */
303 0x04, 0x00, /* 04 - GAI1=256 */
304 0x05, 0x00, /* 05 - GAI2=256 */
305
306 /* decoder */
307 0x06, 0xf0, /* 06 - HSB at xx(50Hz) / xx(60Hz) pixels after end of last line */
308 0x07, 0x30, /* 07 - HSS at xx(50Hz) / xx(60Hz) pixels after end of last line */
309 0x08, 0xa8, /* 08 - AUFD=x, FSEL=x, EXFIL=x, VTRC=x, HPLL=x, VNOI=x */
310 0x09, 0x02, /* 09 - BYPS=x, PREF=x, BPSS=x, VBLB=x, UPTCV=x, APER=x */
311 0x0a, 0x80, /* 0a - BRIG=128 */
312 0x0b, 0x47, /* 0b - CONT=1.109 */
313 0x0c, 0x40, /* 0c - SATN=1.0 */
314 0x0d, 0x00, /* 0d - HUE=0 */
315 0x0e, 0x01, /* 0e - CDTO=0, CSTD=0, DCCF=0, FCTC=0, CHBW=1 */
316 0x0f, 0x00, /* 0f - reserved */
317 0x10, 0xd0, /* 10 - OFTS=x, HDEL=x, VRLN=x, YDEL=x */
318 0x11, 0x8c, /* 11 - GPSW=x, CM99=x, FECO=x, COMPO=x, OEYC=1, OEHV=1, VIPB=0, COLO=0 */
319 0x12, 0x80, /* 12 - xx output control 2 */
320 0x13, 0x30, /* 13 - xx output control 3 */
321 0x14, 0x00, /* 14 - reserved */
322 0x15, 0x15, /* 15 - VBI */
323 0x16, 0x04, /* 16 - VBI */
324 0x17, 0x00, /* 17 - VBI */
325};
326
327/* bring hardware to a sane state. this has to be done, just in case someone 304/* bring hardware to a sane state. this has to be done, just in case someone
328 wants to capture from this device before it has been properly initialized. 305 wants to capture from this device before it has been properly initialized.
329 the capture engine would badly fail, because no valid signal arrives on the 306 the capture engine would badly fail, because no valid signal arrives on the
@@ -331,37 +308,29 @@ static const unsigned char mxb_saa7111_init[] = {
331static int mxb_init_done(struct saa7146_dev* dev) 308static int mxb_init_done(struct saa7146_dev* dev)
332{ 309{
333 struct mxb* mxb = (struct mxb*)dev->ext_priv; 310 struct mxb* mxb = (struct mxb*)dev->ext_priv;
334 struct video_decoder_init init;
335 struct i2c_msg msg; 311 struct i2c_msg msg;
336 struct tuner_setup tun_setup; 312 struct tuner_setup tun_setup;
337 v4l2_std_id std = V4L2_STD_PAL_BG; 313 v4l2_std_id std = V4L2_STD_PAL_BG;
314 struct v4l2_routing route;
338 315
339 int i = 0, err = 0; 316 int i = 0, err = 0;
340 struct tea6415c_multiplex vm; 317 struct tea6415c_multiplex vm;
341 318
342 /* select video mode in saa7111a */ 319 /* select video mode in saa7111a */
343 i = VIDEO_MODE_PAL;
344 /* fixme: currently pointless: gets overwritten by configuration below */ 320 /* fixme: currently pointless: gets overwritten by configuration below */
345 mxb->saa7111a->driver->command(mxb->saa7111a,DECODER_SET_NORM, &i); 321 mxb->saa7111a->driver->command(mxb->saa7111a, VIDIOC_S_STD, &std);
346
347 /* write configuration to saa7111a */
348 init.data = mxb_saa7111_init;
349 init.len = sizeof(mxb_saa7111_init);
350 mxb->saa7111a->driver->command(mxb->saa7111a,DECODER_INIT, &init);
351 322
352 /* select tuner-output on saa7111a */ 323 /* select tuner-output on saa7111a */
353 i = 0; 324 i = 0;
354 mxb->saa7111a->driver->command(mxb->saa7111a,DECODER_SET_INPUT, &i); 325 route.input = SAA7115_COMPOSITE0;
355 326 route.output = SAA7111_FMT_CCIR | SAA7111_VBI_BYPASS;
356 /* enable vbi bypass */ 327 mxb->saa7111a->driver->command(mxb->saa7111a, VIDIOC_INT_S_VIDEO_ROUTING, &route);
357 i = 1;
358 mxb->saa7111a->driver->command(mxb->saa7111a,DECODER_SET_VBI_BYPASS, &i);
359 328
360 /* select a tuner type */ 329 /* select a tuner type */
361 tun_setup.mode_mask = T_ANALOG_TV; 330 tun_setup.mode_mask = T_ANALOG_TV;
362 tun_setup.addr = ADDR_UNSET; 331 tun_setup.addr = ADDR_UNSET;
363 tun_setup.type = TUNER_PHILIPS_PAL; 332 tun_setup.type = TUNER_PHILIPS_PAL;
364 mxb->tuner->driver->command(mxb->tuner,TUNER_SET_TYPE_ADDR, &tun_setup); 333 mxb->tuner->driver->command(mxb->tuner, TUNER_SET_TYPE_ADDR, &tun_setup);
365 /* tune in some frequency on tuner */ 334 /* tune in some frequency on tuner */
366 mxb->cur_freq.tuner = 0; 335 mxb->cur_freq.tuner = 0;
367 mxb->cur_freq.type = V4L2_TUNER_ANALOG_TV; 336 mxb->cur_freq.type = V4L2_TUNER_ANALOG_TV;
@@ -393,7 +362,6 @@ static int mxb_init_done(struct saa7146_dev* dev)
393 mxb->cur_mute = 1; 362 mxb->cur_mute = 1;
394 363
395 mxb->cur_mode = V4L2_TUNER_MODE_STEREO; 364 mxb->cur_mode = V4L2_TUNER_MODE_STEREO;
396 mxb->tda9840->driver->command(mxb->tda9840, TDA9840_SWITCH, &mxb->cur_mode);
397 365
398 /* check if the saa7740 (aka 'sound arena module') is present 366 /* check if the saa7740 (aka 'sound arena module') is present
399 on the mxb. if so, we must initialize it. due to lack of 367 on the mxb. if so, we must initialize it. due to lack of
@@ -626,7 +594,8 @@ static int mxb_ioctl(struct saa7146_fh *fh, unsigned int cmd, void *arg)
626 case VIDIOC_S_INPUT: 594 case VIDIOC_S_INPUT:
627 { 595 {
628 int input = *(int *)arg; 596 int input = *(int *)arg;
629 struct tea6415c_multiplex vm; 597 struct tea6415c_multiplex vm;
598 struct v4l2_routing route;
630 int i = 0; 599 int i = 0;
631 600
632 DEB_EE(("VIDIOC_S_INPUT %d.\n",input)); 601 DEB_EE(("VIDIOC_S_INPUT %d.\n",input));
@@ -635,19 +604,6 @@ static int mxb_ioctl(struct saa7146_fh *fh, unsigned int cmd, void *arg)
635 return -EINVAL; 604 return -EINVAL;
636 } 605 }
637 606
638 /* fixme: locke das setzen des inputs mit hilfe des mutexes
639 mutex_lock(&dev->lock);
640 video_mux(dev,*i);
641 mutex_unlock(&dev->lock);
642 */
643
644 /* fixme: check if streaming capture
645 if ( 0 != dev->streaming ) {
646 DEB_D(("VIDIOC_S_INPUT illegal while streaming.\n"));
647 return -EPERM;
648 }
649 */
650
651 mxb->cur_input = input; 607 mxb->cur_input = input;
652 608
653 saa7146_set_hps_source_and_sync(dev, input_port_selection[input].hps_source, input_port_selection[input].hps_sync); 609 saa7146_set_hps_source_and_sync(dev, input_port_selection[input].hps_source, input_port_selection[input].hps_sync);
@@ -658,7 +614,7 @@ static int mxb_ioctl(struct saa7146_fh *fh, unsigned int cmd, void *arg)
658 614
659 case TUNER: 615 case TUNER:
660 { 616 {
661 i = 0; 617 i = SAA7115_COMPOSITE0;
662 vm.in = 3; 618 vm.in = 3;
663 vm.out = 17; 619 vm.out = 17;
664 620
@@ -675,19 +631,19 @@ static int mxb_ioctl(struct saa7146_fh *fh, unsigned int cmd, void *arg)
675 { 631 {
676 /* nothing to be done here. aux3_yc is 632 /* nothing to be done here. aux3_yc is
677 directly connected to the saa711a */ 633 directly connected to the saa711a */
678 i = 5; 634 i = SAA7115_SVIDEO1;
679 break; 635 break;
680 } 636 }
681 case AUX3: 637 case AUX3:
682 { 638 {
683 /* nothing to be done here. aux3 is 639 /* nothing to be done here. aux3 is
684 directly connected to the saa711a */ 640 directly connected to the saa711a */
685 i = 1; 641 i = SAA7115_COMPOSITE1;
686 break; 642 break;
687 } 643 }
688 case AUX1: 644 case AUX1:
689 { 645 {
690 i = 0; 646 i = SAA7115_COMPOSITE0;
691 vm.in = 1; 647 vm.in = 1;
692 vm.out = 17; 648 vm.out = 17;
693 break; 649 break;
@@ -712,9 +668,10 @@ static int mxb_ioctl(struct saa7146_fh *fh, unsigned int cmd, void *arg)
712 } 668 }
713 669
714 /* switch video in saa7111a */ 670 /* switch video in saa7111a */
715 if ( 0 != mxb->saa7111a->driver->command(mxb->saa7111a,DECODER_SET_INPUT, &i)) { 671 route.input = i;
672 route.output = 0;
673 if (mxb->saa7111a->driver->command(mxb->saa7111a, VIDIOC_INT_S_VIDEO_ROUTING, &route))
716 printk("VIDIOC_S_INPUT: could not address saa7111a #1.\n"); 674 printk("VIDIOC_S_INPUT: could not address saa7111a #1.\n");
717 }
718 675
719 /* switch the audio-source only if necessary */ 676 /* switch the audio-source only if necessary */
720 if( 0 == mxb->cur_mute ) { 677 if( 0 == mxb->cur_mute ) {
@@ -727,105 +684,35 @@ static int mxb_ioctl(struct saa7146_fh *fh, unsigned int cmd, void *arg)
727 case VIDIOC_G_TUNER: 684 case VIDIOC_G_TUNER:
728 { 685 {
729 struct v4l2_tuner *t = arg; 686 struct v4l2_tuner *t = arg;
730 int byte = 0;
731 687
732 if( 0 != t->index ) { 688 if (t->index) {
733 DEB_D(("VIDIOC_G_TUNER: channel %d does not have a tuner attached.\n", t->index)); 689 DEB_D(("VIDIOC_G_TUNER: channel %d does not have a tuner attached.\n", t->index));
734 return -EINVAL; 690 return -EINVAL;
735 } 691 }
736 692
737 DEB_EE(("VIDIOC_G_TUNER: %d\n", t->index)); 693 DEB_EE(("VIDIOC_G_TUNER: %d\n", t->index));
738 694
739 memset(t,0,sizeof(*t)); 695 memset(t, 0, sizeof(*t));
696 i2c_clients_command(&mxb->i2c_adapter, cmd, arg);
740 697
741 strlcpy(t->name, "Television", sizeof(t->name)); 698 strlcpy(t->name, "TV Tuner", sizeof(t->name));
742 t->type = V4L2_TUNER_ANALOG_TV; 699 t->type = V4L2_TUNER_ANALOG_TV;
743 t->capability = V4L2_TUNER_CAP_NORM | V4L2_TUNER_CAP_STEREO | V4L2_TUNER_CAP_LANG1 | V4L2_TUNER_CAP_LANG2 | V4L2_TUNER_CAP_SAP; 700 t->capability = V4L2_TUNER_CAP_NORM | V4L2_TUNER_CAP_STEREO | \
744 t->rangelow = 772; /* 48.25 MHZ / 62.5 kHz = 772, see fi1216mk2-specs, page 2 */ 701 V4L2_TUNER_CAP_LANG1 | V4L2_TUNER_CAP_LANG2 | V4L2_TUNER_CAP_SAP;
745 t->rangehigh = 13684; /* 855.25 MHz / 62.5 kHz = 13684 */
746 /* FIXME: add the real signal strength here */
747 t->signal = 0xffff;
748 t->afc = 0;
749 mxb->tda9840->driver->command(mxb->tda9840,TDA9840_DETECT, &byte);
750 t->audmode = mxb->cur_mode; 702 t->audmode = mxb->cur_mode;
751
752 if( byte < 0 ) {
753 t->rxsubchans = V4L2_TUNER_SUB_MONO;
754 } else {
755 switch(byte) {
756 case TDA9840_MONO_DETECT: {
757 t->rxsubchans = V4L2_TUNER_SUB_MONO;
758 DEB_D(("VIDIOC_G_TUNER: V4L2_TUNER_MODE_MONO.\n"));
759 break;
760 }
761 case TDA9840_DUAL_DETECT: {
762 t->rxsubchans = V4L2_TUNER_SUB_LANG1 | V4L2_TUNER_SUB_LANG2;
763 DEB_D(("VIDIOC_G_TUNER: V4L2_TUNER_MODE_LANG1.\n"));
764 break;
765 }
766 case TDA9840_STEREO_DETECT: {
767 t->rxsubchans = V4L2_TUNER_SUB_STEREO | V4L2_TUNER_SUB_MONO;
768 DEB_D(("VIDIOC_G_TUNER: V4L2_TUNER_MODE_STEREO.\n"));
769 break;
770 }
771 default: { /* TDA9840_INCORRECT_DETECT */
772 t->rxsubchans = V4L2_TUNER_MODE_MONO;
773 DEB_D(("VIDIOC_G_TUNER: TDA9840_INCORRECT_DETECT => V4L2_TUNER_MODE_MONO\n"));
774 break;
775 }
776 }
777 }
778
779 return 0; 703 return 0;
780 } 704 }
781 case VIDIOC_S_TUNER: 705 case VIDIOC_S_TUNER:
782 { 706 {
783 struct v4l2_tuner *t = arg; 707 struct v4l2_tuner *t = arg;
784 int result = 0;
785 int byte = 0;
786 708
787 if( 0 != t->index ) { 709 if (t->index) {
788 DEB_D(("VIDIOC_S_TUNER: channel %d does not have a tuner attached.\n",t->index)); 710 DEB_D(("VIDIOC_S_TUNER: channel %d does not have a tuner attached.\n",t->index));
789 return -EINVAL; 711 return -EINVAL;
790 } 712 }
791 713
792 switch(t->audmode) { 714 mxb->cur_mode = t->audmode;
793 case V4L2_TUNER_MODE_STEREO: { 715 i2c_clients_command(&mxb->i2c_adapter, cmd, arg);
794 mxb->cur_mode = V4L2_TUNER_MODE_STEREO;
795 byte = TDA9840_SET_STEREO;
796 DEB_D(("VIDIOC_S_TUNER: V4L2_TUNER_MODE_STEREO\n"));
797 break;
798 }
799 case V4L2_TUNER_MODE_LANG1_LANG2: {
800 mxb->cur_mode = V4L2_TUNER_MODE_LANG1_LANG2;
801 byte = TDA9840_SET_BOTH;
802 DEB_D(("VIDIOC_S_TUNER: V4L2_TUNER_MODE_LANG1_LANG2\n"));
803 break;
804 }
805 case V4L2_TUNER_MODE_LANG1: {
806 mxb->cur_mode = V4L2_TUNER_MODE_LANG1;
807 byte = TDA9840_SET_LANG1;
808 DEB_D(("VIDIOC_S_TUNER: V4L2_TUNER_MODE_LANG1\n"));
809 break;
810 }
811 case V4L2_TUNER_MODE_LANG2: {
812 mxb->cur_mode = V4L2_TUNER_MODE_LANG2;
813 byte = TDA9840_SET_LANG2;
814 DEB_D(("VIDIOC_S_TUNER: V4L2_TUNER_MODE_LANG2\n"));
815 break;
816 }
817 default: { /* case V4L2_TUNER_MODE_MONO: {*/
818 mxb->cur_mode = V4L2_TUNER_MODE_MONO;
819 byte = TDA9840_SET_MONO;
820 DEB_D(("VIDIOC_S_TUNER: TDA9840_SET_MONO\n"));
821 break;
822 }
823 }
824
825 if( 0 != (result = mxb->tda9840->driver->command(mxb->tda9840, TDA9840_SWITCH, &byte))) {
826 printk("VIDIOC_S_TUNER error. result:%d, byte:%d\n",result,byte);
827 }
828
829 return 0; 716 return 0;
830 } 717 }
831 case VIDIOC_G_FREQUENCY: 718 case VIDIOC_G_FREQUENCY:
@@ -852,8 +739,8 @@ static int mxb_ioctl(struct saa7146_fh *fh, unsigned int cmd, void *arg)
852 if (V4L2_TUNER_ANALOG_TV != f->type) 739 if (V4L2_TUNER_ANALOG_TV != f->type)
853 return -EINVAL; 740 return -EINVAL;
854 741
855 if(0 != mxb->cur_input) { 742 if (mxb->cur_input) {
856 DEB_D(("VIDIOC_S_FREQ: channel %d does not have a tuner!\n",mxb->cur_input)); 743 DEB_D(("VIDIOC_S_FREQ: channel %d does not have a tuner!\n", mxb->cur_input));
857 return -EINVAL; 744 return -EINVAL;
858 } 745 }
859 746
@@ -921,6 +808,10 @@ static int mxb_ioctl(struct saa7146_fh *fh, unsigned int cmd, void *arg)
921 DEB_D(("VIDIOC_S_AUDIO %d.\n",a->index)); 808 DEB_D(("VIDIOC_S_AUDIO %d.\n",a->index));
922 return 0; 809 return 0;
923 } 810 }
811 case VIDIOC_DBG_S_REGISTER:
812 case VIDIOC_DBG_G_REGISTER:
813 i2c_clients_command(&mxb->i2c_adapter, cmd, arg);
814 break;
924 default: 815 default:
925/* 816/*
926 DEB2(printk("does not handle this ioctl.\n")); 817 DEB2(printk("does not handle this ioctl.\n"));
@@ -943,7 +834,7 @@ static int std_callback(struct saa7146_dev *dev, struct saa7146_standard *standa
943 /* set the 7146 gpio register -- I don't know what this does exactly */ 834 /* set the 7146 gpio register -- I don't know what this does exactly */
944 saa7146_write(dev, GPIO_CTRL, 0x00404050); 835 saa7146_write(dev, GPIO_CTRL, 0x00404050);
945 /* unset the 7111 gpio register -- I don't know what this does exactly */ 836 /* unset the 7111 gpio register -- I don't know what this does exactly */
946 mxb->saa7111a->driver->command(mxb->saa7111a, DECODER_SET_GPIO, &zero); 837 mxb->saa7111a->driver->command(mxb->saa7111a, VIDIOC_INT_S_GPIO, &zero);
947 mxb->tuner->driver->command(mxb->tuner, VIDIOC_S_STD, &std); 838 mxb->tuner->driver->command(mxb->tuner, VIDIOC_S_STD, &std);
948 } else { 839 } else {
949 v4l2_std_id std = V4L2_STD_PAL_BG; 840 v4l2_std_id std = V4L2_STD_PAL_BG;
@@ -952,7 +843,7 @@ static int std_callback(struct saa7146_dev *dev, struct saa7146_standard *standa
952 /* set the 7146 gpio register -- I don't know what this does exactly */ 843 /* set the 7146 gpio register -- I don't know what this does exactly */
953 saa7146_write(dev, GPIO_CTRL, 0x00404050); 844 saa7146_write(dev, GPIO_CTRL, 0x00404050);
954 /* set the 7111 gpio register -- I don't know what this does exactly */ 845 /* set the 7111 gpio register -- I don't know what this does exactly */
955 mxb->saa7111a->driver->command(mxb->saa7111a, DECODER_SET_GPIO, &one); 846 mxb->saa7111a->driver->command(mxb->saa7111a, VIDIOC_INT_S_GPIO, &one);
956 mxb->tuner->driver->command(mxb->tuner, VIDIOC_S_STD, &std); 847 mxb->tuner->driver->command(mxb->tuner, VIDIOC_S_STD, &std);
957 } 848 }
958 return 0; 849 return 0;
diff --git a/drivers/media/video/tda9840.c b/drivers/media/video/tda9840.c
index 57deeb893318..77bfd24ecfae 100644
--- a/drivers/media/video/tda9840.c
+++ b/drivers/media/video/tda9840.c
@@ -47,6 +47,15 @@ MODULE_PARM_DESC(debug, "Debug level (0-1)");
47#define STEREO_ADJUST 0x03 47#define STEREO_ADJUST 0x03
48#define TEST 0x04 48#define TEST 0x04
49 49
50#define TDA9840_SET_MUTE 0x00
51#define TDA9840_SET_MONO 0x10
52#define TDA9840_SET_STEREO 0x2a
53#define TDA9840_SET_LANG1 0x12
54#define TDA9840_SET_LANG2 0x1e
55#define TDA9840_SET_BOTH 0x1a
56#define TDA9840_SET_BOTH_R 0x16
57#define TDA9840_SET_EXTERNAL 0x7a
58
50/* addresses to scan, found only at 0x42 (7-Bit) */ 59/* addresses to scan, found only at 0x42 (7-Bit) */
51static unsigned short normal_i2c[] = { I2C_ADDR_TDA9840, I2C_CLIENT_END }; 60static unsigned short normal_i2c[] = { I2C_ADDR_TDA9840, I2C_CLIENT_END };
52 61
@@ -62,26 +71,74 @@ static void tda9840_write(struct i2c_client *client, u8 reg, u8 val)
62 71
63static int tda9840_command(struct i2c_client *client, unsigned cmd, void *arg) 72static int tda9840_command(struct i2c_client *client, unsigned cmd, void *arg)
64{ 73{
65 int result; 74 int result = 0;
66 int byte = *(int *)arg; 75 int byte = *(int *)arg;
67 76
68 switch (cmd) { 77 switch (cmd) {
69 case TDA9840_SWITCH: 78 case VIDIOC_S_TUNER: {
79 struct v4l2_tuner *t = arg;
80 int byte;
81
82 if (t->index)
83 return -EINVAL;
84
85 switch (t->audmode) {
86 case V4L2_TUNER_MODE_STEREO:
87 byte = TDA9840_SET_STEREO;
88 break;
89 case V4L2_TUNER_MODE_LANG1_LANG2:
90 byte = TDA9840_SET_BOTH;
91 break;
92 case V4L2_TUNER_MODE_LANG1:
93 byte = TDA9840_SET_LANG1;
94 break;
95 case V4L2_TUNER_MODE_LANG2:
96 byte = TDA9840_SET_LANG2;
97 break;
98 default:
99 byte = TDA9840_SET_MONO;
100 break;
101 }
70 v4l_dbg(1, debug, client, "TDA9840_SWITCH: 0x%02x\n", byte); 102 v4l_dbg(1, debug, client, "TDA9840_SWITCH: 0x%02x\n", byte);
103 tda9840_write(client, SWITCH, byte);
104 break;
105 }
106
107 case VIDIOC_G_TUNER: {
108 struct v4l2_tuner *t = arg;
109 u8 byte;
71 110
72 if (byte != TDA9840_SET_MONO 111 t->rxsubchans = V4L2_TUNER_SUB_MONO;
73 && byte != TDA9840_SET_MUTE 112 if (1 != i2c_master_recv(client, &byte, 1)) {
74 && byte != TDA9840_SET_STEREO 113 v4l_dbg(1, debug, client,
75 && byte != TDA9840_SET_LANG1 114 "i2c_master_recv() failed\n");
76 && byte != TDA9840_SET_LANG2 115 return -EIO;
77 && byte != TDA9840_SET_BOTH 116 }
78 && byte != TDA9840_SET_BOTH_R 117
79 && byte != TDA9840_SET_EXTERNAL) { 118 if (byte & 0x80) {
119 v4l_dbg(1, debug, client,
120 "TDA9840_DETECT: register contents invalid\n");
80 return -EINVAL; 121 return -EINVAL;
81 } 122 }
82 123
83 tda9840_write(client, SWITCH, byte); 124 v4l_dbg(1, debug, client, "TDA9840_DETECT: byte: 0x%02x\n", byte);
125
126 switch (byte & 0x60) {
127 case 0x00:
128 t->rxsubchans = V4L2_TUNER_SUB_MONO;
129 break;
130 case 0x20:
131 t->rxsubchans = V4L2_TUNER_SUB_LANG1 | V4L2_TUNER_SUB_LANG2;
132 break;
133 case 0x40:
134 t->rxsubchans = V4L2_TUNER_SUB_STEREO | V4L2_TUNER_SUB_MONO;
135 break;
136 default: /* Incorrect detect */
137 t->rxsubchans = V4L2_TUNER_MODE_MONO;
138 break;
139 }
84 break; 140 break;
141 }
85 142
86 case TDA9840_LEVEL_ADJUST: 143 case TDA9840_LEVEL_ADJUST:
87 v4l_dbg(1, debug, client, "TDA9840_LEVEL_ADJUST: %d\n", byte); 144 v4l_dbg(1, debug, client, "TDA9840_LEVEL_ADJUST: %d\n", byte);
@@ -115,36 +172,6 @@ static int tda9840_command(struct i2c_client *client, unsigned cmd, void *arg)
115 172
116 tda9840_write(client, STEREO_ADJUST, byte); 173 tda9840_write(client, STEREO_ADJUST, byte);
117 break; 174 break;
118
119 case TDA9840_DETECT: {
120 int *ret = (int *)arg;
121
122 byte = i2c_smbus_read_byte_data(client, STEREO_ADJUST);
123 if (byte == -1) {
124 v4l_dbg(1, debug, client,
125 "i2c_smbus_read_byte_data() failed\n");
126 return -EIO;
127 }
128
129 if (byte & 0x80) {
130 v4l_dbg(1, debug, client,
131 "TDA9840_DETECT: register contents invalid\n");
132 return -EINVAL;
133 }
134
135 v4l_dbg(1, debug, client, "TDA9840_DETECT: byte: 0x%02x\n", byte);
136 *ret = (byte & 0x60) >> 5;
137 result = 0;
138 break;
139 }
140 case TDA9840_TEST:
141 v4l_dbg(1, debug, client, "TDA9840_TEST: 0x%02x\n", byte);
142
143 /* mask out irrelevant bits */
144 byte &= 0x3;
145
146 tda9840_write(client, TEST, byte);
147 break;
148 default: 175 default:
149 return -ENOIOCTLCMD; 176 return -ENOIOCTLCMD;
150 } 177 }
@@ -174,8 +201,7 @@ static int tda9840_probe(struct i2c_client *client,
174 byte = 0; 201 byte = 0;
175 result = tda9840_command(client, TDA9840_LEVEL_ADJUST, &byte); 202 result = tda9840_command(client, TDA9840_LEVEL_ADJUST, &byte);
176 result += tda9840_command(client, TDA9840_STEREO_ADJUST, &byte); 203 result += tda9840_command(client, TDA9840_STEREO_ADJUST, &byte);
177 byte = TDA9840_SET_MONO; 204 tda9840_write(client, SWITCH, TDA9840_SET_STEREO);
178 result = tda9840_command(client, TDA9840_SWITCH, &byte);
179 if (result) { 205 if (result) {
180 v4l_dbg(1, debug, client, "could not initialize tda9840\n"); 206 v4l_dbg(1, debug, client, "could not initialize tda9840\n");
181 return -ENODEV; 207 return -ENODEV;
diff --git a/drivers/media/video/tda9840.h b/drivers/media/video/tda9840.h
index 7da8432cdca7..dc12ae7caf6f 100644
--- a/drivers/media/video/tda9840.h
+++ b/drivers/media/video/tda9840.h
@@ -3,24 +3,6 @@
3 3
4#define I2C_ADDR_TDA9840 0x42 4#define I2C_ADDR_TDA9840 0x42
5 5
6#define TDA9840_DETECT _IOR('v',1,int)
7/* return values for TDA9840_DETCT */
8#define TDA9840_MONO_DETECT 0x0
9#define TDA9840_DUAL_DETECT 0x1
10#define TDA9840_STEREO_DETECT 0x2
11#define TDA9840_INCORRECT_DETECT 0x3
12
13#define TDA9840_SWITCH _IOW('v',2,int)
14/* modes than can be set with TDA9840_SWITCH */
15#define TDA9840_SET_MUTE 0x00
16#define TDA9840_SET_MONO 0x10
17#define TDA9840_SET_STEREO 0x2a
18#define TDA9840_SET_LANG1 0x12
19#define TDA9840_SET_LANG2 0x1e
20#define TDA9840_SET_BOTH 0x1a
21#define TDA9840_SET_BOTH_R 0x16
22#define TDA9840_SET_EXTERNAL 0x7a
23
24/* values may range between +2.5 and -2.0; 6/* values may range between +2.5 and -2.0;
25 the value has to be multiplied with 10 */ 7 the value has to be multiplied with 10 */
26#define TDA9840_LEVEL_ADJUST _IOW('v',3,int) 8#define TDA9840_LEVEL_ADJUST _IOW('v',3,int)
@@ -29,7 +11,4 @@
29 the value has to be multiplied with 10 */ 11 the value has to be multiplied with 10 */
30#define TDA9840_STEREO_ADJUST _IOW('v',4,int) 12#define TDA9840_STEREO_ADJUST _IOW('v',4,int)
31 13
32/* currently not implemented */
33#define TDA9840_TEST _IOW('v',5,int)
34
35#endif 14#endif