aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media
diff options
context:
space:
mode:
authorIngo Molnar <mingo@elte.hu>2008-07-29 05:54:24 -0400
committerIngo Molnar <mingo@elte.hu>2008-07-29 05:54:24 -0400
commit3825c9e8d01e4310c40a3903a354c433c32a7b6f (patch)
tree87c94a8076bbb38bd2cf20ab9bc23d6f74f6a0a8 /drivers/media
parent5d7b605245b1aa1a9cd6549b1f57d69273eb0c37 (diff)
parent6e86841d05f371b5b9b86ce76c02aaee83352298 (diff)
Merge commit 'v2.6.27-rc1' into x86/microcode
Conflicts: arch/x86/kernel/microcode.c Manual resolutions: arch/x86/kernel/microcode_amd.c arch/x86/kernel/microcode_intel.c Signed-off-by: Ingo Molnar <mingo@elte.hu>
Diffstat (limited to 'drivers/media')
-rw-r--r--drivers/media/common/saa7146_fops.c2
-rw-r--r--drivers/media/common/saa7146_video.c19
-rw-r--r--drivers/media/common/tuners/Kconfig16
-rw-r--r--drivers/media/common/tuners/Makefile1
-rw-r--r--drivers/media/common/tuners/mt20xx.c3
-rw-r--r--drivers/media/common/tuners/mxl5007t.c1030
-rw-r--r--drivers/media/common/tuners/mxl5007t.h104
-rw-r--r--drivers/media/common/tuners/tda9887.c2
-rw-r--r--drivers/media/common/tuners/tuner-simple.c2
-rw-r--r--drivers/media/dvb/bt8xx/Kconfig2
-rw-r--r--drivers/media/dvb/dvb-usb/Kconfig10
-rw-r--r--drivers/media/dvb/dvb-usb/Makefile3
-rw-r--r--drivers/media/dvb/dvb-usb/anysee.c2
-rw-r--r--drivers/media/dvb/dvb-usb/dvb-usb-ids.h1
-rw-r--r--drivers/media/dvb/dvb-usb/dw2102.c425
-rw-r--r--drivers/media/dvb/dvb-usb/dw2102.h9
-rw-r--r--drivers/media/dvb/frontends/Kconfig38
-rw-r--r--drivers/media/dvb/frontends/Makefile1
-rw-r--r--drivers/media/dvb/frontends/drx397xD.c1504
-rw-r--r--drivers/media/dvb/frontends/drx397xD.h130
-rw-r--r--drivers/media/dvb/frontends/drx397xD_fw.h40
-rw-r--r--drivers/media/dvb/frontends/z0194a.h97
-rw-r--r--drivers/media/dvb/siano/smscoreapi.c14
-rw-r--r--drivers/media/dvb/siano/smsdvb.c4
-rw-r--r--drivers/media/dvb/ttpci/Kconfig4
-rw-r--r--drivers/media/dvb/ttusb-dec/Kconfig2
-rw-r--r--drivers/media/radio/dsbr100.c18
-rw-r--r--drivers/media/radio/miropcm20-radio.c3
-rw-r--r--drivers/media/radio/radio-aimslab.c14
-rw-r--r--drivers/media/radio/radio-aztech.c14
-rw-r--r--drivers/media/radio/radio-cadet.c14
-rw-r--r--drivers/media/radio/radio-gemtek-pci.c13
-rw-r--r--drivers/media/radio/radio-gemtek.c13
-rw-r--r--drivers/media/radio/radio-maestro.c12
-rw-r--r--drivers/media/radio/radio-maxiradio.c15
-rw-r--r--drivers/media/radio/radio-rtrack2.c14
-rw-r--r--drivers/media/radio/radio-sf16fmi.c14
-rw-r--r--drivers/media/radio/radio-sf16fmr2.c14
-rw-r--r--drivers/media/radio/radio-si470x.c22
-rw-r--r--drivers/media/radio/radio-terratec.c14
-rw-r--r--drivers/media/radio/radio-trust.c14
-rw-r--r--drivers/media/radio/radio-typhoon.c14
-rw-r--r--drivers/media/radio/radio-zoltrix.c14
-rw-r--r--drivers/media/video/Kconfig19
-rw-r--r--drivers/media/video/Makefile3
-rw-r--r--drivers/media/video/arv.c1
-rw-r--r--drivers/media/video/au0828/Kconfig1
-rw-r--r--drivers/media/video/au0828/au0828-cards.c12
-rw-r--r--drivers/media/video/au0828/au0828-cards.h1
-rw-r--r--drivers/media/video/au0828/au0828-dvb.c15
-rw-r--r--drivers/media/video/bt8xx/Kconfig2
-rw-r--r--drivers/media/video/bt8xx/bttv-driver.c58
-rw-r--r--drivers/media/video/bt8xx/bttv-risc.c1
-rw-r--r--drivers/media/video/bt8xx/bttv-vbi.c1
-rw-r--r--drivers/media/video/bw-qcam.c3
-rw-r--r--drivers/media/video/c-qcam.c3
-rw-r--r--drivers/media/video/cafe_ccic.c26
-rw-r--r--drivers/media/video/compat_ioctl32.c2
-rw-r--r--drivers/media/video/cpia.c2
-rw-r--r--drivers/media/video/cpia.h1
-rw-r--r--drivers/media/video/cpia2/cpia2_core.c1
-rw-r--r--drivers/media/video/cpia2/cpia2_v4l.c5
-rw-r--r--drivers/media/video/cs5345.c2
-rw-r--r--drivers/media/video/cs53l32a.c2
-rw-r--r--drivers/media/video/cx18/Kconfig2
-rw-r--r--drivers/media/video/cx18/cx18-av-audio.c111
-rw-r--r--drivers/media/video/cx18/cx18-driver.h1
-rw-r--r--drivers/media/video/cx18/cx18-firmware.c54
-rw-r--r--drivers/media/video/cx18/cx18-ioctl.c92
-rw-r--r--drivers/media/video/cx18/cx18-streams.c5
-rw-r--r--drivers/media/video/cx23885/Kconfig2
-rw-r--r--drivers/media/video/cx23885/cx23885-417.c19
-rw-r--r--drivers/media/video/cx23885/cx23885-cards.c54
-rw-r--r--drivers/media/video/cx23885/cx23885-core.c147
-rw-r--r--drivers/media/video/cx23885/cx23885-video.c19
-rw-r--r--drivers/media/video/cx25840/Kconfig2
-rw-r--r--drivers/media/video/cx25840/cx25840-core.c2
-rw-r--r--drivers/media/video/cx25840/cx25840-core.h2
-rw-r--r--drivers/media/video/cx88/Kconfig3
-rw-r--r--drivers/media/video/cx88/cx88-blackbird.c15
-rw-r--r--drivers/media/video/cx88/cx88-cards.c2
-rw-r--r--drivers/media/video/cx88/cx88-core.c3
-rw-r--r--drivers/media/video/cx88/cx88-video.c37
-rw-r--r--drivers/media/video/cx88/cx88.h4
-rw-r--r--drivers/media/video/em28xx/em28xx-cards.c977
-rw-r--r--drivers/media/video/em28xx/em28xx-dvb.c13
-rw-r--r--drivers/media/video/em28xx/em28xx-video.c61
-rw-r--r--drivers/media/video/em28xx/em28xx.h49
-rw-r--r--drivers/media/video/et61x251/et61x251_core.c5
-rw-r--r--drivers/media/video/gspca/conex.c9
-rw-r--r--drivers/media/video/gspca/etoms.c30
-rw-r--r--drivers/media/video/gspca/gspca.c43
-rw-r--r--drivers/media/video/gspca/mars.c9
-rw-r--r--drivers/media/video/gspca/ov519.c33
-rw-r--r--drivers/media/video/gspca/pac207.c29
-rw-r--r--drivers/media/video/gspca/pac7311.c22
-rw-r--r--drivers/media/video/gspca/sonixb.c484
-rw-r--r--drivers/media/video/gspca/sonixj.c492
-rw-r--r--drivers/media/video/gspca/spca500.c139
-rw-r--r--drivers/media/video/gspca/spca501.c75
-rw-r--r--drivers/media/video/gspca/spca505.c140
-rw-r--r--drivers/media/video/gspca/spca506.c121
-rw-r--r--drivers/media/video/gspca/spca508.c164
-rw-r--r--drivers/media/video/gspca/spca561.c62
-rw-r--r--drivers/media/video/gspca/stk014.c9
-rw-r--r--drivers/media/video/gspca/sunplus.c355
-rw-r--r--drivers/media/video/gspca/t613.c26
-rw-r--r--drivers/media/video/gspca/tv8532.c17
-rw-r--r--drivers/media/video/gspca/vc032x.c44
-rw-r--r--drivers/media/video/gspca/zc3xx.c486
-rw-r--r--drivers/media/video/ivtv/Kconfig2
-rw-r--r--drivers/media/video/ivtv/ivtv-driver.c5
-rw-r--r--drivers/media/video/ivtv/ivtv-driver.h1
-rw-r--r--drivers/media/video/ivtv/ivtv-ioctl.c130
-rw-r--r--drivers/media/video/ivtv/ivtv-streams.c7
-rw-r--r--drivers/media/video/m52790.c2
-rw-r--r--drivers/media/video/meye.c19
-rw-r--r--drivers/media/video/msp3400-driver.c2
-rw-r--r--drivers/media/video/msp3400-kthreads.c1
-rw-r--r--drivers/media/video/mt9m001.c2
-rw-r--r--drivers/media/video/ov511.c38
-rw-r--r--drivers/media/video/ov511.h1
-rw-r--r--drivers/media/video/planb.c2309
-rw-r--r--drivers/media/video/planb.h232
-rw-r--r--drivers/media/video/pms.c3
-rw-r--r--drivers/media/video/pvrusb2/Kconfig2
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-context.h4
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-devattr.c11
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-devattr.h26
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-fx2-cmd.h2
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-hdw.c9
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-i2c-core.c4
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-v4l2.c6
-rw-r--r--drivers/media/video/pwc/pwc-if.c16
-rw-r--r--drivers/media/video/pwc/pwc.h2
-rw-r--r--drivers/media/video/s2255drv.c130
-rw-r--r--drivers/media/video/saa5246a.c3
-rw-r--r--drivers/media/video/saa5249.c3
-rw-r--r--drivers/media/video/saa7134/Kconfig2
-rw-r--r--drivers/media/video/saa7134/saa7134-cards.c3
-rw-r--r--drivers/media/video/saa7134/saa7134-core.c16
-rw-r--r--drivers/media/video/saa7134/saa7134-empress.c54
-rw-r--r--drivers/media/video/saa7134/saa7134-video.c98
-rw-r--r--drivers/media/video/saa7134/saa7134.h7
-rw-r--r--drivers/media/video/saa717x.c1
-rw-r--r--drivers/media/video/saa7196.h117
-rw-r--r--drivers/media/video/se401.c2
-rw-r--r--drivers/media/video/se401.h1
-rw-r--r--drivers/media/video/sh_mobile_ceu_camera.c1
-rw-r--r--drivers/media/video/sn9c102/sn9c102.h1
-rw-r--r--drivers/media/video/sn9c102/sn9c102_core.c62
-rw-r--r--drivers/media/video/soc_camera.c68
-rw-r--r--drivers/media/video/stk-webcam.c69
-rw-r--r--drivers/media/video/stradis.c2
-rw-r--r--drivers/media/video/stv680.c52
-rw-r--r--drivers/media/video/tda7432.c3
-rw-r--r--drivers/media/video/tda9875.c2
-rw-r--r--drivers/media/video/tlv320aic23b.c2
-rw-r--r--drivers/media/video/tuner-core.c1
-rw-r--r--drivers/media/video/tveeprom.c122
-rw-r--r--drivers/media/video/tvp5150.c2
-rw-r--r--drivers/media/video/usbvideo/usbvideo.c4
-rw-r--r--drivers/media/video/usbvideo/usbvideo.h1
-rw-r--r--drivers/media/video/usbvideo/vicam.c3
-rw-r--r--drivers/media/video/usbvision/usbvision-core.c2
-rw-r--r--drivers/media/video/usbvision/usbvision-video.c113
-rw-r--r--drivers/media/video/uvc/uvc_ctrl.c15
-rw-r--r--drivers/media/video/uvc/uvc_driver.c4
-rw-r--r--drivers/media/video/uvc/uvc_v4l2.c1
-rw-r--r--drivers/media/video/v4l1-compat.c1
-rw-r--r--drivers/media/video/v4l2-common.c2
-rw-r--r--drivers/media/video/v4l2-dev.c422
-rw-r--r--drivers/media/video/v4l2-ioctl.c1875
-rw-r--r--drivers/media/video/videobuf-dma-contig.c8
-rw-r--r--drivers/media/video/videobuf-vmalloc.c2
-rw-r--r--drivers/media/video/videodev.c2262
-rw-r--r--drivers/media/video/vino.c4
-rw-r--r--drivers/media/video/vivi.c18
-rw-r--r--drivers/media/video/vp27smpx.c2
-rw-r--r--drivers/media/video/w9966.c5
-rw-r--r--drivers/media/video/w9968cf.c5
-rw-r--r--drivers/media/video/w9968cf.h2
-rw-r--r--drivers/media/video/wm8739.c2
-rw-r--r--drivers/media/video/wm8775.c2
-rw-r--r--drivers/media/video/zc0301/zc0301.h1
-rw-r--r--drivers/media/video/zc0301/zc0301_core.c2
-rw-r--r--drivers/media/video/zoran_card.c42
-rw-r--r--drivers/media/video/zoran_card.h2
-rw-r--r--drivers/media/video/zoran_driver.c7
-rw-r--r--drivers/media/video/zr364xx.c18
190 files changed, 8874 insertions, 7945 deletions
diff --git a/drivers/media/common/saa7146_fops.c b/drivers/media/common/saa7146_fops.c
index 171afe7da6b6..cf6a817d5059 100644
--- a/drivers/media/common/saa7146_fops.c
+++ b/drivers/media/common/saa7146_fops.c
@@ -563,7 +563,7 @@ int saa7146_unregister_device(struct video_device **vid, struct saa7146_dev* dev
563 563
564 DEB_EE(("dev:%p\n",dev)); 564 DEB_EE(("dev:%p\n",dev));
565 565
566 if( VFL_TYPE_GRABBER == (*vid)->type ) { 566 if ((*vid)->vfl_type == VFL_TYPE_GRABBER) {
567 vv->video_minor = -1; 567 vv->video_minor = -1;
568 } else { 568 } else {
569 vv->vbi_minor = -1; 569 vv->vbi_minor = -1;
diff --git a/drivers/media/common/saa7146_video.c b/drivers/media/common/saa7146_video.c
index a5e62750eea3..e8bc7abf2409 100644
--- a/drivers/media/common/saa7146_video.c
+++ b/drivers/media/common/saa7146_video.c
@@ -656,7 +656,7 @@ static int saa7146_pgtable_build(struct saa7146_dev *dev, struct saa7146_buf *bu
656 656
657 /* if we have a user buffer, the first page may not be 657 /* if we have a user buffer, the first page may not be
658 aligned to a page boundary. */ 658 aligned to a page boundary. */
659 pt1->offset = list->offset; 659 pt1->offset = dma->sglist->offset;
660 pt2->offset = pt1->offset+o1; 660 pt2->offset = pt1->offset+o1;
661 pt3->offset = pt1->offset+o2; 661 pt3->offset = pt1->offset+o2;
662 662
@@ -958,21 +958,18 @@ int saa7146_video_do_ioctl(struct inode *inode, struct file *file, unsigned int
958 case VIDIOC_ENUM_FMT: 958 case VIDIOC_ENUM_FMT:
959 { 959 {
960 struct v4l2_fmtdesc *f = arg; 960 struct v4l2_fmtdesc *f = arg;
961 int index;
962 961
963 switch (f->type) { 962 switch (f->type) {
964 case V4L2_BUF_TYPE_VIDEO_CAPTURE: 963 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
965 case V4L2_BUF_TYPE_VIDEO_OVERLAY: { 964 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
966 index = f->index; 965 if (f->index >= NUM_FORMATS)
967 if (index < 0 || index >= NUM_FORMATS) {
968 return -EINVAL; 966 return -EINVAL;
969 } 967 strlcpy((char *)f->description, formats[f->index].name,
970 memset(f,0,sizeof(*f)); 968 sizeof(f->description));
971 f->index = index; 969 f->pixelformat = formats[f->index].pixelformat;
972 strlcpy((char *)f->description,formats[index].name,sizeof(f->description)); 970 f->flags = 0;
973 f->pixelformat = formats[index].pixelformat; 971 memset(f->reserved, 0, sizeof(f->reserved));
974 break; 972 break;
975 }
976 default: 973 default:
977 return -EINVAL; 974 return -EINVAL;
978 } 975 }
diff --git a/drivers/media/common/tuners/Kconfig b/drivers/media/common/tuners/Kconfig
index 850d5689b14d..6f92beaa5ac8 100644
--- a/drivers/media/common/tuners/Kconfig
+++ b/drivers/media/common/tuners/Kconfig
@@ -21,9 +21,8 @@ config MEDIA_TUNER
21 tristate 21 tristate
22 default VIDEO_MEDIA && I2C 22 default VIDEO_MEDIA && I2C
23 depends on VIDEO_MEDIA && I2C 23 depends on VIDEO_MEDIA && I2C
24 select FW_LOADER if !MEDIA_TUNER_CUSTOMIZE && HOTPLUG 24 select MEDIA_TUNER_XC2028 if !MEDIA_TUNER_CUSTOMIZE
25 select MEDIA_TUNER_XC2028 if !MEDIA_TUNER_CUSTOMIZE && HOTPLUG 25 select MEDIA_TUNER_XC5000 if !MEDIA_TUNER_CUSTOMIZE
26 select MEDIA_TUNER_XC5000 if !MEDIA_TUNER_CUSTOMIZE && HOTPLUG
27 select MEDIA_TUNER_MT20XX if !MEDIA_TUNER_CUSTOMIZE 26 select MEDIA_TUNER_MT20XX if !MEDIA_TUNER_CUSTOMIZE
28 select MEDIA_TUNER_TDA8290 if !MEDIA_TUNER_CUSTOMIZE 27 select MEDIA_TUNER_TDA8290 if !MEDIA_TUNER_CUSTOMIZE
29 select MEDIA_TUNER_TEA5761 if !MEDIA_TUNER_CUSTOMIZE 28 select MEDIA_TUNER_TEA5761 if !MEDIA_TUNER_CUSTOMIZE
@@ -138,8 +137,6 @@ config MEDIA_TUNER_QT1010
138config MEDIA_TUNER_XC2028 137config MEDIA_TUNER_XC2028
139 tristate "XCeive xc2028/xc3028 tuners" 138 tristate "XCeive xc2028/xc3028 tuners"
140 depends on VIDEO_MEDIA && I2C 139 depends on VIDEO_MEDIA && I2C
141 depends on HOTPLUG
142 select FW_LOADER
143 default m if MEDIA_TUNER_CUSTOMIZE 140 default m if MEDIA_TUNER_CUSTOMIZE
144 help 141 help
145 Say Y here to include support for the xc2028/xc3028 tuners. 142 Say Y here to include support for the xc2028/xc3028 tuners.
@@ -147,8 +144,6 @@ config MEDIA_TUNER_XC2028
147config MEDIA_TUNER_XC5000 144config MEDIA_TUNER_XC5000
148 tristate "Xceive XC5000 silicon tuner" 145 tristate "Xceive XC5000 silicon tuner"
149 depends on VIDEO_MEDIA && I2C 146 depends on VIDEO_MEDIA && I2C
150 depends on HOTPLUG
151 select FW_LOADER
152 default m if DVB_FE_CUSTOMISE 147 default m if DVB_FE_CUSTOMISE
153 help 148 help
154 A driver for the silicon tuner XC5000 from Xceive. 149 A driver for the silicon tuner XC5000 from Xceive.
@@ -162,4 +157,11 @@ config MEDIA_TUNER_MXL5005S
162 help 157 help
163 A driver for the silicon tuner MXL5005S from MaxLinear. 158 A driver for the silicon tuner MXL5005S from MaxLinear.
164 159
160config MEDIA_TUNER_MXL5007T
161 tristate "MaxLinear MxL5007T silicon tuner"
162 depends on VIDEO_MEDIA && I2C
163 default m if DVB_FE_CUSTOMISE
164 help
165 A driver for the silicon tuner MxL5007T from MaxLinear.
166
165endif # MEDIA_TUNER_CUSTOMIZE 167endif # MEDIA_TUNER_CUSTOMIZE
diff --git a/drivers/media/common/tuners/Makefile b/drivers/media/common/tuners/Makefile
index 55f7e6706297..4dfbe5b8264f 100644
--- a/drivers/media/common/tuners/Makefile
+++ b/drivers/media/common/tuners/Makefile
@@ -21,6 +21,7 @@ obj-$(CONFIG_MEDIA_TUNER_MT2266) += mt2266.o
21obj-$(CONFIG_MEDIA_TUNER_QT1010) += qt1010.o 21obj-$(CONFIG_MEDIA_TUNER_QT1010) += qt1010.o
22obj-$(CONFIG_MEDIA_TUNER_MT2131) += mt2131.o 22obj-$(CONFIG_MEDIA_TUNER_MT2131) += mt2131.o
23obj-$(CONFIG_MEDIA_TUNER_MXL5005S) += mxl5005s.o 23obj-$(CONFIG_MEDIA_TUNER_MXL5005S) += mxl5005s.o
24obj-$(CONFIG_MEDIA_TUNER_MXL5007T) += mxl5007t.o
24 25
25EXTRA_CFLAGS += -Idrivers/media/dvb/dvb-core 26EXTRA_CFLAGS += -Idrivers/media/dvb/dvb-core
26EXTRA_CFLAGS += -Idrivers/media/dvb/frontends 27EXTRA_CFLAGS += -Idrivers/media/dvb/frontends
diff --git a/drivers/media/common/tuners/mt20xx.c b/drivers/media/common/tuners/mt20xx.c
index fbcb28233737..35b763a16d53 100644
--- a/drivers/media/common/tuners/mt20xx.c
+++ b/drivers/media/common/tuners/mt20xx.c
@@ -148,7 +148,8 @@ static int mt2032_compute_freq(struct dvb_frontend *fe,
148 tuner_dbg("mt2032: rfin=%d lo2=%d lo2n=%d lo2a=%d num=%d lo2freq=%d\n", 148 tuner_dbg("mt2032: rfin=%d lo2=%d lo2n=%d lo2a=%d num=%d lo2freq=%d\n",
149 rfin,lo2,lo2n,lo2a,lo2num,lo2freq); 149 rfin,lo2,lo2n,lo2a,lo2num,lo2freq);
150 150
151 if(lo1a<0 || lo1a>7 || lo1n<17 ||lo1n>48 || lo2a<0 ||lo2a >7 ||lo2n<17 || lo2n>30) { 151 if (lo1a > 7 || lo1n < 17 || lo1n > 48 || lo2a > 7 || lo2n < 17 ||
152 lo2n > 30) {
152 tuner_info("mt2032: frequency parameters out of range: %d %d %d %d\n", 153 tuner_info("mt2032: frequency parameters out of range: %d %d %d %d\n",
153 lo1a, lo1n, lo2a,lo2n); 154 lo1a, lo1n, lo2a,lo2n);
154 return(-1); 155 return(-1);
diff --git a/drivers/media/common/tuners/mxl5007t.c b/drivers/media/common/tuners/mxl5007t.c
new file mode 100644
index 000000000000..cb25e43502fe
--- /dev/null
+++ b/drivers/media/common/tuners/mxl5007t.c
@@ -0,0 +1,1030 @@
1/*
2 * mxl5007t.c - driver for the MaxLinear MxL5007T silicon tuner
3 *
4 * Copyright (C) 2008 Michael Krufky <mkrufky@linuxtv.org>
5 *
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.
10 *
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.
15 *
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.
19 */
20
21#include <linux/i2c.h>
22#include <linux/types.h>
23#include <linux/videodev2.h>
24#include "tuner-i2c.h"
25#include "mxl5007t.h"
26
27static DEFINE_MUTEX(mxl5007t_list_mutex);
28static LIST_HEAD(hybrid_tuner_instance_list);
29
30static int mxl5007t_debug;
31module_param_named(debug, mxl5007t_debug, int, 0644);
32MODULE_PARM_DESC(debug, "set debug level");
33
34/* ------------------------------------------------------------------------- */
35
36#define mxl_printk(kern, fmt, arg...) \
37 printk(kern "%s: " fmt "\n", __func__, ##arg)
38
39#define mxl_err(fmt, arg...) \
40 mxl_printk(KERN_ERR, "%d: " fmt, __LINE__, ##arg)
41
42#define mxl_warn(fmt, arg...) \
43 mxl_printk(KERN_WARNING, fmt, ##arg)
44
45#define mxl_info(fmt, arg...) \
46 mxl_printk(KERN_INFO, fmt, ##arg)
47
48#define mxl_debug(fmt, arg...) \
49({ \
50 if (mxl5007t_debug) \
51 mxl_printk(KERN_DEBUG, fmt, ##arg); \
52})
53
54#define mxl_fail(ret) \
55({ \
56 int __ret; \
57 __ret = (ret < 0); \
58 if (__ret) \
59 mxl_printk(KERN_ERR, "error %d on line %d", \
60 ret, __LINE__); \
61 __ret; \
62})
63
64/* ------------------------------------------------------------------------- */
65
66#define MHz 1000000
67
68enum mxl5007t_mode {
69 MxL_MODE_OTA_DVBT_ATSC = 0,
70 MxL_MODE_OTA_NTSC_PAL_GH = 1,
71 MxL_MODE_OTA_PAL_IB = 2,
72 MxL_MODE_OTA_PAL_D_SECAM_KL = 3,
73 MxL_MODE_OTA_ISDBT = 4,
74 MxL_MODE_CABLE_DIGITAL = 0x10,
75 MxL_MODE_CABLE_NTSC_PAL_GH = 0x11,
76 MxL_MODE_CABLE_PAL_IB = 0x12,
77 MxL_MODE_CABLE_PAL_D_SECAM_KL = 0x13,
78 MxL_MODE_CABLE_SCTE40 = 0x14,
79};
80
81enum mxl5007t_chip_version {
82 MxL_UNKNOWN_ID = 0x00,
83 MxL_5007_V1_F1 = 0x11,
84 MxL_5007_V1_F2 = 0x12,
85 MxL_5007_V2_100_F1 = 0x21,
86 MxL_5007_V2_100_F2 = 0x22,
87 MxL_5007_V2_200_F1 = 0x23,
88 MxL_5007_V2_200_F2 = 0x24,
89};
90
91struct reg_pair_t {
92 u8 reg;
93 u8 val;
94};
95
96/* ------------------------------------------------------------------------- */
97
98static struct reg_pair_t init_tab[] = {
99 { 0x0b, 0x44 }, /* XTAL */
100 { 0x0c, 0x60 }, /* IF */
101 { 0x10, 0x00 }, /* MISC */
102 { 0x12, 0xca }, /* IDAC */
103 { 0x16, 0x90 }, /* MODE */
104 { 0x32, 0x38 }, /* MODE Analog/Digital */
105 { 0xd8, 0x18 }, /* CLK_OUT_ENABLE */
106 { 0x2c, 0x34 }, /* OVERRIDE */
107 { 0x4d, 0x40 }, /* OVERRIDE */
108 { 0x7f, 0x02 }, /* OVERRIDE */
109 { 0x9a, 0x52 }, /* OVERRIDE */
110 { 0x48, 0x5a }, /* OVERRIDE */
111 { 0x76, 0x1a }, /* OVERRIDE */
112 { 0x6a, 0x48 }, /* OVERRIDE */
113 { 0x64, 0x28 }, /* OVERRIDE */
114 { 0x66, 0xe6 }, /* OVERRIDE */
115 { 0x35, 0x0e }, /* OVERRIDE */
116 { 0x7e, 0x01 }, /* OVERRIDE */
117 { 0x83, 0x00 }, /* OVERRIDE */
118 { 0x04, 0x0b }, /* OVERRIDE */
119 { 0x05, 0x01 }, /* TOP_MASTER_ENABLE */
120 { 0, 0 }
121};
122
123static struct reg_pair_t init_tab_cable[] = {
124 { 0x0b, 0x44 }, /* XTAL */
125 { 0x0c, 0x60 }, /* IF */
126 { 0x10, 0x00 }, /* MISC */
127 { 0x12, 0xca }, /* IDAC */
128 { 0x16, 0x90 }, /* MODE */
129 { 0x32, 0x38 }, /* MODE A/D */
130 { 0x71, 0x3f }, /* TOP1 */
131 { 0x72, 0x3f }, /* TOP2 */
132 { 0x74, 0x3f }, /* TOP3 */
133 { 0xd8, 0x18 }, /* CLK_OUT_ENABLE */
134 { 0x2c, 0x34 }, /* OVERRIDE */
135 { 0x4d, 0x40 }, /* OVERRIDE */
136 { 0x7f, 0x02 }, /* OVERRIDE */
137 { 0x9a, 0x52 }, /* OVERRIDE */
138 { 0x48, 0x5a }, /* OVERRIDE */
139 { 0x76, 0x1a }, /* OVERRIDE */
140 { 0x6a, 0x48 }, /* OVERRIDE */
141 { 0x64, 0x28 }, /* OVERRIDE */
142 { 0x66, 0xe6 }, /* OVERRIDE */
143 { 0x35, 0x0e }, /* OVERRIDE */
144 { 0x7e, 0x01 }, /* OVERRIDE */
145 { 0x04, 0x0b }, /* OVERRIDE */
146 { 0x68, 0xb4 }, /* OVERRIDE */
147 { 0x36, 0x00 }, /* OVERRIDE */
148 { 0x05, 0x01 }, /* TOP_MASTER_ENABLE */
149 { 0, 0 }
150};
151
152/* ------------------------------------------------------------------------- */
153
154static struct reg_pair_t reg_pair_rftune[] = {
155 { 0x11, 0x00 }, /* abort tune */
156 { 0x13, 0x15 },
157 { 0x14, 0x40 },
158 { 0x15, 0x0e },
159 { 0x11, 0x02 }, /* start tune */
160 { 0, 0 }
161};
162
163/* ------------------------------------------------------------------------- */
164
165struct mxl5007t_state {
166 struct list_head hybrid_tuner_instance_list;
167 struct tuner_i2c_props i2c_props;
168
169 struct mutex lock;
170
171 struct mxl5007t_config *config;
172
173 enum mxl5007t_chip_version chip_id;
174
175 struct reg_pair_t tab_init[ARRAY_SIZE(init_tab)];
176 struct reg_pair_t tab_init_cable[ARRAY_SIZE(init_tab_cable)];
177 struct reg_pair_t tab_rftune[ARRAY_SIZE(reg_pair_rftune)];
178
179 u32 frequency;
180 u32 bandwidth;
181};
182
183/* ------------------------------------------------------------------------- */
184
185/* called by _init and _rftun to manipulate the register arrays */
186
187static void set_reg_bits(struct reg_pair_t *reg_pair, u8 reg, u8 mask, u8 val)
188{
189 unsigned int i = 0;
190
191 while (reg_pair[i].reg || reg_pair[i].val) {
192 if (reg_pair[i].reg == reg) {
193 reg_pair[i].val &= ~mask;
194 reg_pair[i].val |= val;
195 }
196 i++;
197
198 }
199 return;
200}
201
202static void copy_reg_bits(struct reg_pair_t *reg_pair1,
203 struct reg_pair_t *reg_pair2)
204{
205 unsigned int i, j;
206
207 i = j = 0;
208
209 while (reg_pair1[i].reg || reg_pair1[i].val) {
210 while (reg_pair2[j].reg || reg_pair2[j].reg) {
211 if (reg_pair1[i].reg != reg_pair2[j].reg) {
212 j++;
213 continue;
214 }
215 reg_pair2[j].val = reg_pair1[i].val;
216 break;
217 }
218 i++;
219 }
220 return;
221}
222
223/* ------------------------------------------------------------------------- */
224
225static void mxl5007t_set_mode_bits(struct mxl5007t_state *state,
226 enum mxl5007t_mode mode,
227 s32 if_diff_out_level)
228{
229 switch (mode) {
230 case MxL_MODE_OTA_DVBT_ATSC:
231 set_reg_bits(state->tab_init, 0x32, 0x0f, 0x06);
232 set_reg_bits(state->tab_init, 0x35, 0xff, 0x0e);
233 break;
234 case MxL_MODE_OTA_ISDBT:
235 set_reg_bits(state->tab_init, 0x32, 0x0f, 0x06);
236 set_reg_bits(state->tab_init, 0x35, 0xff, 0x12);
237 break;
238 case MxL_MODE_OTA_NTSC_PAL_GH:
239 set_reg_bits(state->tab_init, 0x16, 0x70, 0x00);
240 set_reg_bits(state->tab_init, 0x32, 0xff, 0x85);
241 break;
242 case MxL_MODE_OTA_PAL_IB:
243 set_reg_bits(state->tab_init, 0x16, 0x70, 0x10);
244 set_reg_bits(state->tab_init, 0x32, 0xff, 0x85);
245 break;
246 case MxL_MODE_OTA_PAL_D_SECAM_KL:
247 set_reg_bits(state->tab_init, 0x16, 0x70, 0x20);
248 set_reg_bits(state->tab_init, 0x32, 0xff, 0x85);
249 break;
250 case MxL_MODE_CABLE_DIGITAL:
251 set_reg_bits(state->tab_init_cable, 0x71, 0xff, 0x01);
252 set_reg_bits(state->tab_init_cable, 0x72, 0xff,
253 8 - if_diff_out_level);
254 set_reg_bits(state->tab_init_cable, 0x74, 0xff, 0x17);
255 break;
256 case MxL_MODE_CABLE_NTSC_PAL_GH:
257 set_reg_bits(state->tab_init, 0x16, 0x70, 0x00);
258 set_reg_bits(state->tab_init, 0x32, 0xff, 0x85);
259 set_reg_bits(state->tab_init_cable, 0x71, 0xff, 0x01);
260 set_reg_bits(state->tab_init_cable, 0x72, 0xff,
261 8 - if_diff_out_level);
262 set_reg_bits(state->tab_init_cable, 0x74, 0xff, 0x17);
263 break;
264 case MxL_MODE_CABLE_PAL_IB:
265 set_reg_bits(state->tab_init, 0x16, 0x70, 0x10);
266 set_reg_bits(state->tab_init, 0x32, 0xff, 0x85);
267 set_reg_bits(state->tab_init_cable, 0x71, 0xff, 0x01);
268 set_reg_bits(state->tab_init_cable, 0x72, 0xff,
269 8 - if_diff_out_level);
270 set_reg_bits(state->tab_init_cable, 0x74, 0xff, 0x17);
271 break;
272 case MxL_MODE_CABLE_PAL_D_SECAM_KL:
273 set_reg_bits(state->tab_init, 0x16, 0x70, 0x20);
274 set_reg_bits(state->tab_init, 0x32, 0xff, 0x85);
275 set_reg_bits(state->tab_init_cable, 0x71, 0xff, 0x01);
276 set_reg_bits(state->tab_init_cable, 0x72, 0xff,
277 8 - if_diff_out_level);
278 set_reg_bits(state->tab_init_cable, 0x74, 0xff, 0x17);
279 break;
280 case MxL_MODE_CABLE_SCTE40:
281 set_reg_bits(state->tab_init_cable, 0x36, 0xff, 0x08);
282 set_reg_bits(state->tab_init_cable, 0x68, 0xff, 0xbc);
283 set_reg_bits(state->tab_init_cable, 0x71, 0xff, 0x01);
284 set_reg_bits(state->tab_init_cable, 0x72, 0xff,
285 8 - if_diff_out_level);
286 set_reg_bits(state->tab_init_cable, 0x74, 0xff, 0x17);
287 break;
288 default:
289 mxl_fail(-EINVAL);
290 }
291 return;
292}
293
294static void mxl5007t_set_if_freq_bits(struct mxl5007t_state *state,
295 enum mxl5007t_if_freq if_freq,
296 int invert_if)
297{
298 u8 val;
299
300 switch (if_freq) {
301 case MxL_IF_4_MHZ:
302 val = 0x00;
303 break;
304 case MxL_IF_4_5_MHZ:
305 val = 0x20;
306 break;
307 case MxL_IF_4_57_MHZ:
308 val = 0x30;
309 break;
310 case MxL_IF_5_MHZ:
311 val = 0x40;
312 break;
313 case MxL_IF_5_38_MHZ:
314 val = 0x50;
315 break;
316 case MxL_IF_6_MHZ:
317 val = 0x60;
318 break;
319 case MxL_IF_6_28_MHZ:
320 val = 0x70;
321 break;
322 case MxL_IF_9_1915_MHZ:
323 val = 0x80;
324 break;
325 case MxL_IF_35_25_MHZ:
326 val = 0x90;
327 break;
328 case MxL_IF_36_15_MHZ:
329 val = 0xa0;
330 break;
331 case MxL_IF_44_MHZ:
332 val = 0xb0;
333 break;
334 default:
335 mxl_fail(-EINVAL);
336 return;
337 }
338 set_reg_bits(state->tab_init, 0x0c, 0xf0, val);
339
340 /* set inverted IF or normal IF */
341 set_reg_bits(state->tab_init, 0x0c, 0x08, invert_if ? 0x08 : 0x00);
342
343 return;
344}
345
346static void mxl5007t_set_xtal_freq_bits(struct mxl5007t_state *state,
347 enum mxl5007t_xtal_freq xtal_freq)
348{
349 u8 val;
350
351 switch (xtal_freq) {
352 case MxL_XTAL_16_MHZ:
353 val = 0x00; /* select xtal freq & Ref Freq */
354 break;
355 case MxL_XTAL_20_MHZ:
356 val = 0x11;
357 break;
358 case MxL_XTAL_20_25_MHZ:
359 val = 0x22;
360 break;
361 case MxL_XTAL_20_48_MHZ:
362 val = 0x33;
363 break;
364 case MxL_XTAL_24_MHZ:
365 val = 0x44;
366 break;
367 case MxL_XTAL_25_MHZ:
368 val = 0x55;
369 break;
370 case MxL_XTAL_25_14_MHZ:
371 val = 0x66;
372 break;
373 case MxL_XTAL_27_MHZ:
374 val = 0x77;
375 break;
376 case MxL_XTAL_28_8_MHZ:
377 val = 0x88;
378 break;
379 case MxL_XTAL_32_MHZ:
380 val = 0x99;
381 break;
382 case MxL_XTAL_40_MHZ:
383 val = 0xaa;
384 break;
385 case MxL_XTAL_44_MHZ:
386 val = 0xbb;
387 break;
388 case MxL_XTAL_48_MHZ:
389 val = 0xcc;
390 break;
391 case MxL_XTAL_49_3811_MHZ:
392 val = 0xdd;
393 break;
394 default:
395 mxl_fail(-EINVAL);
396 return;
397 }
398 set_reg_bits(state->tab_init, 0x0b, 0xff, val);
399
400 return;
401}
402
403static struct reg_pair_t *mxl5007t_calc_init_regs(struct mxl5007t_state *state,
404 enum mxl5007t_mode mode)
405{
406 struct mxl5007t_config *cfg = state->config;
407
408 memcpy(&state->tab_init, &init_tab, sizeof(init_tab));
409 memcpy(&state->tab_init_cable, &init_tab_cable, sizeof(init_tab_cable));
410
411 mxl5007t_set_mode_bits(state, mode, cfg->if_diff_out_level);
412 mxl5007t_set_if_freq_bits(state, cfg->if_freq_hz, cfg->invert_if);
413 mxl5007t_set_xtal_freq_bits(state, cfg->xtal_freq_hz);
414
415 set_reg_bits(state->tab_init, 0x10, 0x40, cfg->loop_thru_enable << 6);
416
417 set_reg_bits(state->tab_init, 0xd8, 0x08, cfg->clk_out_enable << 3);
418
419 set_reg_bits(state->tab_init, 0x10, 0x07, cfg->clk_out_amp);
420
421 /* set IDAC to automatic mode control by AGC */
422 set_reg_bits(state->tab_init, 0x12, 0x80, 0x00);
423
424 if (mode >= MxL_MODE_CABLE_DIGITAL) {
425 copy_reg_bits(state->tab_init, state->tab_init_cable);
426 return state->tab_init_cable;
427 } else
428 return state->tab_init;
429}
430
431/* ------------------------------------------------------------------------- */
432
433enum mxl5007t_bw_mhz {
434 MxL_BW_6MHz = 6,
435 MxL_BW_7MHz = 7,
436 MxL_BW_8MHz = 8,
437};
438
439static void mxl5007t_set_bw_bits(struct mxl5007t_state *state,
440 enum mxl5007t_bw_mhz bw)
441{
442 u8 val;
443
444 switch (bw) {
445 case MxL_BW_6MHz:
446 val = 0x15; /* set DIG_MODEINDEX, DIG_MODEINDEX_A,
447 * and DIG_MODEINDEX_CSF */
448 break;
449 case MxL_BW_7MHz:
450 val = 0x21;
451 break;
452 case MxL_BW_8MHz:
453 val = 0x3f;
454 break;
455 default:
456 mxl_fail(-EINVAL);
457 return;
458 }
459 set_reg_bits(state->tab_rftune, 0x13, 0x3f, val);
460
461 return;
462}
463
464static struct
465reg_pair_t *mxl5007t_calc_rf_tune_regs(struct mxl5007t_state *state,
466 u32 rf_freq, enum mxl5007t_bw_mhz bw)
467{
468 u32 dig_rf_freq = 0;
469 u32 temp;
470 u32 frac_divider = 1000000;
471 unsigned int i;
472
473 memcpy(&state->tab_rftune, &reg_pair_rftune, sizeof(reg_pair_rftune));
474
475 mxl5007t_set_bw_bits(state, bw);
476
477 /* Convert RF frequency into 16 bits =>
478 * 10 bit integer (MHz) + 6 bit fraction */
479 dig_rf_freq = rf_freq / MHz;
480
481 temp = rf_freq % MHz;
482
483 for (i = 0; i < 6; i++) {
484 dig_rf_freq <<= 1;
485 frac_divider /= 2;
486 if (temp > frac_divider) {
487 temp -= frac_divider;
488 dig_rf_freq++;
489 }
490 }
491
492 /* add to have shift center point by 7.8124 kHz */
493 if (temp > 7812)
494 dig_rf_freq++;
495
496 set_reg_bits(state->tab_rftune, 0x14, 0xff, (u8)dig_rf_freq);
497 set_reg_bits(state->tab_rftune, 0x15, 0xff, (u8)(dig_rf_freq >> 8));
498
499 return state->tab_rftune;
500}
501
502/* ------------------------------------------------------------------------- */
503
504static int mxl5007t_write_reg(struct mxl5007t_state *state, u8 reg, u8 val)
505{
506 u8 buf[] = { reg, val };
507 struct i2c_msg msg = { .addr = state->i2c_props.addr, .flags = 0,
508 .buf = buf, .len = 2 };
509 int ret;
510
511 ret = i2c_transfer(state->i2c_props.adap, &msg, 1);
512 if (ret != 1) {
513 mxl_err("failed!");
514 return -EREMOTEIO;
515 }
516 return 0;
517}
518
519static int mxl5007t_write_regs(struct mxl5007t_state *state,
520 struct reg_pair_t *reg_pair)
521{
522 unsigned int i = 0;
523 int ret = 0;
524
525 while ((ret == 0) && (reg_pair[i].reg || reg_pair[i].val)) {
526 ret = mxl5007t_write_reg(state,
527 reg_pair[i].reg, reg_pair[i].val);
528 i++;
529 }
530 return ret;
531}
532
533static int mxl5007t_read_reg(struct mxl5007t_state *state, u8 reg, u8 *val)
534{
535 struct i2c_msg msg[] = {
536 { .addr = state->i2c_props.addr, .flags = 0,
537 .buf = &reg, .len = 1 },
538 { .addr = state->i2c_props.addr, .flags = I2C_M_RD,
539 .buf = val, .len = 1 },
540 };
541 int ret;
542
543 ret = i2c_transfer(state->i2c_props.adap, msg, 2);
544 if (ret != 2) {
545 mxl_err("failed!");
546 return -EREMOTEIO;
547 }
548 return 0;
549}
550
551static int mxl5007t_soft_reset(struct mxl5007t_state *state)
552{
553 u8 d = 0xff;
554 struct i2c_msg msg = { .addr = state->i2c_props.addr, .flags = 0,
555 .buf = &d, .len = 1 };
556
557 int ret = i2c_transfer(state->i2c_props.adap, &msg, 1);
558
559 if (ret != 1) {
560 mxl_err("failed!");
561 return -EREMOTEIO;
562 }
563 return 0;
564}
565
566static int mxl5007t_tuner_init(struct mxl5007t_state *state,
567 enum mxl5007t_mode mode)
568{
569 struct reg_pair_t *init_regs;
570 int ret;
571
572 ret = mxl5007t_soft_reset(state);
573 if (mxl_fail(ret))
574 goto fail;
575
576 /* calculate initialization reg array */
577 init_regs = mxl5007t_calc_init_regs(state, mode);
578
579 ret = mxl5007t_write_regs(state, init_regs);
580 if (mxl_fail(ret))
581 goto fail;
582 mdelay(1);
583
584 ret = mxl5007t_write_reg(state, 0x2c, 0x35);
585 mxl_fail(ret);
586fail:
587 return ret;
588}
589
590static int mxl5007t_tuner_rf_tune(struct mxl5007t_state *state, u32 rf_freq_hz,
591 enum mxl5007t_bw_mhz bw)
592{
593 struct reg_pair_t *rf_tune_regs;
594 int ret;
595
596 /* calculate channel change reg array */
597 rf_tune_regs = mxl5007t_calc_rf_tune_regs(state, rf_freq_hz, bw);
598
599 ret = mxl5007t_write_regs(state, rf_tune_regs);
600 if (mxl_fail(ret))
601 goto fail;
602 msleep(3);
603fail:
604 return ret;
605}
606
607/* ------------------------------------------------------------------------- */
608
609static int mxl5007t_synth_lock_status(struct mxl5007t_state *state,
610 int *rf_locked, int *ref_locked)
611{
612 u8 d;
613 int ret;
614
615 *rf_locked = 0;
616 *ref_locked = 0;
617
618 ret = mxl5007t_read_reg(state, 0xcf, &d);
619 if (mxl_fail(ret))
620 goto fail;
621
622 if ((d & 0x0c) == 0x0c)
623 *rf_locked = 1;
624
625 if ((d & 0x03) == 0x03)
626 *ref_locked = 1;
627fail:
628 return ret;
629}
630
631static int mxl5007t_check_rf_input_power(struct mxl5007t_state *state,
632 s32 *rf_input_level)
633{
634 u8 d1, d2;
635 int ret;
636
637 ret = mxl5007t_read_reg(state, 0xb7, &d1);
638 if (mxl_fail(ret))
639 goto fail;
640
641 ret = mxl5007t_read_reg(state, 0xbf, &d2);
642 if (mxl_fail(ret))
643 goto fail;
644
645 d2 = d2 >> 4;
646 if (d2 > 7)
647 d2 += 0xf0;
648
649 *rf_input_level = (s32)(d1 + d2 - 113);
650fail:
651 return ret;
652}
653
654/* ------------------------------------------------------------------------- */
655
656static int mxl5007t_get_status(struct dvb_frontend *fe, u32 *status)
657{
658 struct mxl5007t_state *state = fe->tuner_priv;
659 int rf_locked, ref_locked;
660 s32 rf_input_level;
661 int ret;
662
663 if (fe->ops.i2c_gate_ctrl)
664 fe->ops.i2c_gate_ctrl(fe, 1);
665
666 ret = mxl5007t_synth_lock_status(state, &rf_locked, &ref_locked);
667 if (mxl_fail(ret))
668 goto fail;
669 mxl_debug("%s%s", rf_locked ? "rf locked " : "",
670 ref_locked ? "ref locked" : "");
671
672 ret = mxl5007t_check_rf_input_power(state, &rf_input_level);
673 if (mxl_fail(ret))
674 goto fail;
675 mxl_debug("rf input power: %d", rf_input_level);
676fail:
677 if (fe->ops.i2c_gate_ctrl)
678 fe->ops.i2c_gate_ctrl(fe, 0);
679
680 return ret;
681}
682
683/* ------------------------------------------------------------------------- */
684
685static int mxl5007t_set_params(struct dvb_frontend *fe,
686 struct dvb_frontend_parameters *params)
687{
688 struct mxl5007t_state *state = fe->tuner_priv;
689 enum mxl5007t_bw_mhz bw;
690 enum mxl5007t_mode mode;
691 int ret;
692 u32 freq = params->frequency;
693
694 if (fe->ops.info.type == FE_ATSC) {
695 switch (params->u.vsb.modulation) {
696 case VSB_8:
697 case VSB_16:
698 mode = MxL_MODE_OTA_DVBT_ATSC;
699 break;
700 case QAM_64:
701 case QAM_256:
702 mode = MxL_MODE_CABLE_DIGITAL;
703 break;
704 default:
705 mxl_err("modulation not set!");
706 return -EINVAL;
707 }
708 bw = MxL_BW_6MHz;
709 } else if (fe->ops.info.type == FE_OFDM) {
710 switch (params->u.ofdm.bandwidth) {
711 case BANDWIDTH_6_MHZ:
712 bw = MxL_BW_6MHz;
713 break;
714 case BANDWIDTH_7_MHZ:
715 bw = MxL_BW_7MHz;
716 break;
717 case BANDWIDTH_8_MHZ:
718 bw = MxL_BW_8MHz;
719 break;
720 default:
721 mxl_err("bandwidth not set!");
722 return -EINVAL;
723 }
724 mode = MxL_MODE_OTA_DVBT_ATSC;
725 } else {
726 mxl_err("modulation type not supported!");
727 return -EINVAL;
728 }
729
730 if (fe->ops.i2c_gate_ctrl)
731 fe->ops.i2c_gate_ctrl(fe, 1);
732
733 mutex_lock(&state->lock);
734
735 ret = mxl5007t_tuner_init(state, mode);
736 if (mxl_fail(ret))
737 goto fail;
738
739 ret = mxl5007t_tuner_rf_tune(state, freq, bw);
740 if (mxl_fail(ret))
741 goto fail;
742
743 state->frequency = freq;
744 state->bandwidth = (fe->ops.info.type == FE_OFDM) ?
745 params->u.ofdm.bandwidth : 0;
746fail:
747 mutex_unlock(&state->lock);
748
749 if (fe->ops.i2c_gate_ctrl)
750 fe->ops.i2c_gate_ctrl(fe, 0);
751
752 return ret;
753}
754
755static int mxl5007t_set_analog_params(struct dvb_frontend *fe,
756 struct analog_parameters *params)
757{
758 struct mxl5007t_state *state = fe->tuner_priv;
759 enum mxl5007t_bw_mhz bw = 0; /* FIXME */
760 enum mxl5007t_mode cbl_mode;
761 enum mxl5007t_mode ota_mode;
762 char *mode_name;
763 int ret;
764 u32 freq = params->frequency * 62500;
765
766#define cable 1
767 if (params->std & V4L2_STD_MN) {
768 cbl_mode = MxL_MODE_CABLE_NTSC_PAL_GH;
769 ota_mode = MxL_MODE_OTA_NTSC_PAL_GH;
770 mode_name = "MN";
771 } else if (params->std & V4L2_STD_B) {
772 cbl_mode = MxL_MODE_CABLE_PAL_IB;
773 ota_mode = MxL_MODE_OTA_PAL_IB;
774 mode_name = "B";
775 } else if (params->std & V4L2_STD_GH) {
776 cbl_mode = MxL_MODE_CABLE_NTSC_PAL_GH;
777 ota_mode = MxL_MODE_OTA_NTSC_PAL_GH;
778 mode_name = "GH";
779 } else if (params->std & V4L2_STD_PAL_I) {
780 cbl_mode = MxL_MODE_CABLE_PAL_IB;
781 ota_mode = MxL_MODE_OTA_PAL_IB;
782 mode_name = "I";
783 } else if (params->std & V4L2_STD_DK) {
784 cbl_mode = MxL_MODE_CABLE_PAL_D_SECAM_KL;
785 ota_mode = MxL_MODE_OTA_PAL_D_SECAM_KL;
786 mode_name = "DK";
787 } else if (params->std & V4L2_STD_SECAM_L) {
788 cbl_mode = MxL_MODE_CABLE_PAL_D_SECAM_KL;
789 ota_mode = MxL_MODE_OTA_PAL_D_SECAM_KL;
790 mode_name = "L";
791 } else if (params->std & V4L2_STD_SECAM_LC) {
792 cbl_mode = MxL_MODE_CABLE_PAL_D_SECAM_KL;
793 ota_mode = MxL_MODE_OTA_PAL_D_SECAM_KL;
794 mode_name = "L'";
795 } else {
796 mode_name = "xx";
797 /* FIXME */
798 cbl_mode = MxL_MODE_CABLE_NTSC_PAL_GH;
799 ota_mode = MxL_MODE_OTA_NTSC_PAL_GH;
800 }
801 mxl_debug("setting mxl5007 to system %s", mode_name);
802
803 if (fe->ops.i2c_gate_ctrl)
804 fe->ops.i2c_gate_ctrl(fe, 1);
805
806 mutex_lock(&state->lock);
807
808 ret = mxl5007t_tuner_init(state, cable ? cbl_mode : ota_mode);
809 if (mxl_fail(ret))
810 goto fail;
811
812 ret = mxl5007t_tuner_rf_tune(state, freq, bw);
813 if (mxl_fail(ret))
814 goto fail;
815
816 state->frequency = freq;
817 state->bandwidth = 0;
818fail:
819 mutex_unlock(&state->lock);
820
821 if (fe->ops.i2c_gate_ctrl)
822 fe->ops.i2c_gate_ctrl(fe, 0);
823
824 return ret;
825}
826
827/* ------------------------------------------------------------------------- */
828
829static int mxl5007t_init(struct dvb_frontend *fe)
830{
831 struct mxl5007t_state *state = fe->tuner_priv;
832 int ret;
833 u8 d;
834
835 if (fe->ops.i2c_gate_ctrl)
836 fe->ops.i2c_gate_ctrl(fe, 1);
837
838 ret = mxl5007t_read_reg(state, 0x05, &d);
839 if (mxl_fail(ret))
840 goto fail;
841
842 ret = mxl5007t_write_reg(state, 0x05, d | 0x01);
843 mxl_fail(ret);
844fail:
845 if (fe->ops.i2c_gate_ctrl)
846 fe->ops.i2c_gate_ctrl(fe, 0);
847
848 return ret;
849}
850
851static int mxl5007t_sleep(struct dvb_frontend *fe)
852{
853 struct mxl5007t_state *state = fe->tuner_priv;
854 int ret;
855 u8 d;
856
857 if (fe->ops.i2c_gate_ctrl)
858 fe->ops.i2c_gate_ctrl(fe, 1);
859
860 ret = mxl5007t_read_reg(state, 0x05, &d);
861 if (mxl_fail(ret))
862 goto fail;
863
864 ret = mxl5007t_write_reg(state, 0x05, d & ~0x01);
865 mxl_fail(ret);
866fail:
867 if (fe->ops.i2c_gate_ctrl)
868 fe->ops.i2c_gate_ctrl(fe, 0);
869
870 return ret;
871}
872
873/* ------------------------------------------------------------------------- */
874
875static int mxl5007t_get_frequency(struct dvb_frontend *fe, u32 *frequency)
876{
877 struct mxl5007t_state *state = fe->tuner_priv;
878 *frequency = state->frequency;
879 return 0;
880}
881
882static int mxl5007t_get_bandwidth(struct dvb_frontend *fe, u32 *bandwidth)
883{
884 struct mxl5007t_state *state = fe->tuner_priv;
885 *bandwidth = state->bandwidth;
886 return 0;
887}
888
889static int mxl5007t_release(struct dvb_frontend *fe)
890{
891 struct mxl5007t_state *state = fe->tuner_priv;
892
893 mutex_lock(&mxl5007t_list_mutex);
894
895 if (state)
896 hybrid_tuner_release_state(state);
897
898 mutex_unlock(&mxl5007t_list_mutex);
899
900 fe->tuner_priv = NULL;
901
902 return 0;
903}
904
905/* ------------------------------------------------------------------------- */
906
907static struct dvb_tuner_ops mxl5007t_tuner_ops = {
908 .info = {
909 .name = "MaxLinear MxL5007T",
910 },
911 .init = mxl5007t_init,
912 .sleep = mxl5007t_sleep,
913 .set_params = mxl5007t_set_params,
914 .set_analog_params = mxl5007t_set_analog_params,
915 .get_status = mxl5007t_get_status,
916 .get_frequency = mxl5007t_get_frequency,
917 .get_bandwidth = mxl5007t_get_bandwidth,
918 .release = mxl5007t_release,
919};
920
921static int mxl5007t_get_chip_id(struct mxl5007t_state *state)
922{
923 char *name;
924 int ret;
925 u8 id;
926
927 ret = mxl5007t_read_reg(state, 0xd3, &id);
928 if (mxl_fail(ret))
929 goto fail;
930
931 switch (id) {
932 case MxL_5007_V1_F1:
933 name = "MxL5007.v1.f1";
934 break;
935 case MxL_5007_V1_F2:
936 name = "MxL5007.v1.f2";
937 break;
938 case MxL_5007_V2_100_F1:
939 name = "MxL5007.v2.100.f1";
940 break;
941 case MxL_5007_V2_100_F2:
942 name = "MxL5007.v2.100.f2";
943 break;
944 case MxL_5007_V2_200_F1:
945 name = "MxL5007.v2.200.f1";
946 break;
947 case MxL_5007_V2_200_F2:
948 name = "MxL5007.v2.200.f2";
949 break;
950 default:
951 name = "MxL5007T";
952 id = MxL_UNKNOWN_ID;
953 }
954 state->chip_id = id;
955 mxl_info("%s detected @ %d-%04x", name,
956 i2c_adapter_id(state->i2c_props.adap),
957 state->i2c_props.addr);
958 return 0;
959fail:
960 mxl_warn("unable to identify device @ %d-%04x",
961 i2c_adapter_id(state->i2c_props.adap),
962 state->i2c_props.addr);
963
964 state->chip_id = MxL_UNKNOWN_ID;
965 return ret;
966}
967
968struct dvb_frontend *mxl5007t_attach(struct dvb_frontend *fe,
969 struct i2c_adapter *i2c, u8 addr,
970 struct mxl5007t_config *cfg)
971{
972 struct mxl5007t_state *state = NULL;
973 int instance, ret;
974
975 mutex_lock(&mxl5007t_list_mutex);
976 instance = hybrid_tuner_request_state(struct mxl5007t_state, state,
977 hybrid_tuner_instance_list,
978 i2c, addr, "mxl5007");
979 switch (instance) {
980 case 0:
981 goto fail;
982 break;
983 case 1:
984 /* new tuner instance */
985 state->config = cfg;
986
987 mutex_init(&state->lock);
988
989 if (fe->ops.i2c_gate_ctrl)
990 fe->ops.i2c_gate_ctrl(fe, 1);
991
992 ret = mxl5007t_get_chip_id(state);
993
994 if (fe->ops.i2c_gate_ctrl)
995 fe->ops.i2c_gate_ctrl(fe, 0);
996
997 /* check return value of mxl5007t_get_chip_id */
998 if (mxl_fail(ret))
999 goto fail;
1000 break;
1001 default:
1002 /* existing tuner instance */
1003 break;
1004 }
1005 fe->tuner_priv = state;
1006 mutex_unlock(&mxl5007t_list_mutex);
1007
1008 memcpy(&fe->ops.tuner_ops, &mxl5007t_tuner_ops,
1009 sizeof(struct dvb_tuner_ops));
1010
1011 return fe;
1012fail:
1013 mutex_unlock(&mxl5007t_list_mutex);
1014
1015 mxl5007t_release(fe);
1016 return NULL;
1017}
1018EXPORT_SYMBOL_GPL(mxl5007t_attach);
1019MODULE_DESCRIPTION("MaxLinear MxL5007T Silicon IC tuner driver");
1020MODULE_AUTHOR("Michael Krufky <mkrufky@linuxtv.org>");
1021MODULE_LICENSE("GPL");
1022MODULE_VERSION("0.1");
1023
1024/*
1025 * Overrides for Emacs so that we follow Linus's tabbing style.
1026 * ---------------------------------------------------------------------------
1027 * Local variables:
1028 * c-basic-offset: 8
1029 * End:
1030 */
diff --git a/drivers/media/common/tuners/mxl5007t.h b/drivers/media/common/tuners/mxl5007t.h
new file mode 100644
index 000000000000..aa3eea0b5262
--- /dev/null
+++ b/drivers/media/common/tuners/mxl5007t.h
@@ -0,0 +1,104 @@
1/*
2 * mxl5007t.h - driver for the MaxLinear MxL5007T silicon tuner
3 *
4 * Copyright (C) 2008 Michael Krufky <mkrufky@linuxtv.org>
5 *
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.
10 *
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.
15 *
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.
19 */
20
21#ifndef __MXL5007T_H__
22#define __MXL5007T_H__
23
24#include "dvb_frontend.h"
25
26/* ------------------------------------------------------------------------- */
27
28enum mxl5007t_if_freq {
29 MxL_IF_4_MHZ, /* 4000000 */
30 MxL_IF_4_5_MHZ, /* 4500000 */
31 MxL_IF_4_57_MHZ, /* 4570000 */
32 MxL_IF_5_MHZ, /* 5000000 */
33 MxL_IF_5_38_MHZ, /* 5380000 */
34 MxL_IF_6_MHZ, /* 6000000 */
35 MxL_IF_6_28_MHZ, /* 6280000 */
36 MxL_IF_9_1915_MHZ, /* 9191500 */
37 MxL_IF_35_25_MHZ, /* 35250000 */
38 MxL_IF_36_15_MHZ, /* 36150000 */
39 MxL_IF_44_MHZ, /* 44000000 */
40};
41
42enum mxl5007t_xtal_freq {
43 MxL_XTAL_16_MHZ, /* 16000000 */
44 MxL_XTAL_20_MHZ, /* 20000000 */
45 MxL_XTAL_20_25_MHZ, /* 20250000 */
46 MxL_XTAL_20_48_MHZ, /* 20480000 */
47 MxL_XTAL_24_MHZ, /* 24000000 */
48 MxL_XTAL_25_MHZ, /* 25000000 */
49 MxL_XTAL_25_14_MHZ, /* 25140000 */
50 MxL_XTAL_27_MHZ, /* 27000000 */
51 MxL_XTAL_28_8_MHZ, /* 28800000 */
52 MxL_XTAL_32_MHZ, /* 32000000 */
53 MxL_XTAL_40_MHZ, /* 40000000 */
54 MxL_XTAL_44_MHZ, /* 44000000 */
55 MxL_XTAL_48_MHZ, /* 48000000 */
56 MxL_XTAL_49_3811_MHZ, /* 49381100 */
57};
58
59enum mxl5007t_clkout_amp {
60 MxL_CLKOUT_AMP_0_94V = 0,
61 MxL_CLKOUT_AMP_0_53V = 1,
62 MxL_CLKOUT_AMP_0_37V = 2,
63 MxL_CLKOUT_AMP_0_28V = 3,
64 MxL_CLKOUT_AMP_0_23V = 4,
65 MxL_CLKOUT_AMP_0_20V = 5,
66 MxL_CLKOUT_AMP_0_17V = 6,
67 MxL_CLKOUT_AMP_0_15V = 7,
68};
69
70struct mxl5007t_config {
71 s32 if_diff_out_level;
72 enum mxl5007t_clkout_amp clk_out_amp;
73 enum mxl5007t_xtal_freq xtal_freq_hz;
74 enum mxl5007t_if_freq if_freq_hz;
75 unsigned int invert_if:1;
76 unsigned int loop_thru_enable:1;
77 unsigned int clk_out_enable:1;
78};
79
80#if defined(CONFIG_MEDIA_TUNER_MXL5007T) || (defined(CONFIG_MEDIA_TUNER_MXL5007T_MODULE) && defined(MODULE))
81extern struct dvb_frontend *mxl5007t_attach(struct dvb_frontend *fe,
82 struct i2c_adapter *i2c, u8 addr,
83 struct mxl5007t_config *cfg);
84#else
85static inline struct dvb_frontend *mxl5007t_attach(struct dvb_frontend *fe,
86 struct i2c_adapter *i2c,
87 u8 addr,
88 struct mxl5007t_config *cfg)
89{
90 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
91 return NULL;
92}
93#endif
94
95#endif /* __MXL5007T_H__ */
96
97/*
98 * Overrides for Emacs so that we follow Linus's tabbing style.
99 * ---------------------------------------------------------------------------
100 * Local variables:
101 * c-basic-offset: 8
102 * End:
103 */
104
diff --git a/drivers/media/common/tuners/tda9887.c b/drivers/media/common/tuners/tda9887.c
index a0545ba957b0..72abf0b73486 100644
--- a/drivers/media/common/tuners/tda9887.c
+++ b/drivers/media/common/tuners/tda9887.c
@@ -6,7 +6,7 @@
6#include <linux/errno.h> 6#include <linux/errno.h>
7#include <linux/slab.h> 7#include <linux/slab.h>
8#include <linux/delay.h> 8#include <linux/delay.h>
9#include <linux/videodev.h> 9#include <linux/videodev2.h>
10#include <media/v4l2-common.h> 10#include <media/v4l2-common.h>
11#include <media/tuner.h> 11#include <media/tuner.h>
12#include "tuner-i2c.h" 12#include "tuner-i2c.h"
diff --git a/drivers/media/common/tuners/tuner-simple.c b/drivers/media/common/tuners/tuner-simple.c
index 266c255cf0d8..597e47f5d69c 100644
--- a/drivers/media/common/tuners/tuner-simple.c
+++ b/drivers/media/common/tuners/tuner-simple.c
@@ -6,7 +6,7 @@
6 */ 6 */
7#include <linux/delay.h> 7#include <linux/delay.h>
8#include <linux/i2c.h> 8#include <linux/i2c.h>
9#include <linux/videodev.h> 9#include <linux/videodev2.h>
10#include <media/tuner.h> 10#include <media/tuner.h>
11#include <media/v4l2-common.h> 11#include <media/v4l2-common.h>
12#include <media/tuner-types.h> 12#include <media/tuner-types.h>
diff --git a/drivers/media/dvb/bt8xx/Kconfig b/drivers/media/dvb/bt8xx/Kconfig
index 7588db1319d0..7e9c090fc04e 100644
--- a/drivers/media/dvb/bt8xx/Kconfig
+++ b/drivers/media/dvb/bt8xx/Kconfig
@@ -1,7 +1,6 @@
1config DVB_BT8XX 1config DVB_BT8XX
2 tristate "BT8xx based PCI cards" 2 tristate "BT8xx based PCI cards"
3 depends on DVB_CORE && PCI && I2C && VIDEO_BT848 3 depends on DVB_CORE && PCI && I2C && VIDEO_BT848
4 depends on HOTPLUG # due to FW_LOADER
5 select DVB_MT352 if !DVB_FE_CUSTOMISE 4 select DVB_MT352 if !DVB_FE_CUSTOMISE
6 select DVB_SP887X if !DVB_FE_CUSTOMISE 5 select DVB_SP887X if !DVB_FE_CUSTOMISE
7 select DVB_NXT6000 if !DVB_FE_CUSTOMISE 6 select DVB_NXT6000 if !DVB_FE_CUSTOMISE
@@ -10,7 +9,6 @@ config DVB_BT8XX
10 select DVB_LGDT330X if !DVB_FE_CUSTOMISE 9 select DVB_LGDT330X if !DVB_FE_CUSTOMISE
11 select DVB_ZL10353 if !DVB_FE_CUSTOMISE 10 select DVB_ZL10353 if !DVB_FE_CUSTOMISE
12 select MEDIA_TUNER_SIMPLE if !DVB_FE_CUSTOMISE 11 select MEDIA_TUNER_SIMPLE if !DVB_FE_CUSTOMISE
13 select FW_LOADER
14 help 12 help
15 Support for PCI cards based on the Bt8xx PCI bridge. Examples are 13 Support for PCI cards based on the Bt8xx PCI bridge. Examples are
16 the Nebula cards, the Pinnacle PCTV cards, the Twinhan DST cards, 14 the Nebula cards, the Pinnacle PCTV cards, the Twinhan DST cards,
diff --git a/drivers/media/dvb/dvb-usb/Kconfig b/drivers/media/dvb/dvb-usb/Kconfig
index a577c0f89f67..e84152b7576d 100644
--- a/drivers/media/dvb/dvb-usb/Kconfig
+++ b/drivers/media/dvb/dvb-usb/Kconfig
@@ -1,8 +1,6 @@
1config DVB_USB 1config DVB_USB
2 tristate "Support for various USB DVB devices" 2 tristate "Support for various USB DVB devices"
3 depends on DVB_CORE && USB && I2C && INPUT 3 depends on DVB_CORE && USB && I2C && INPUT
4 depends on HOTPLUG # due to FW_LOADER
5 select FW_LOADER
6 help 4 help
7 By enabling this you will be able to choose the various supported 5 By enabling this you will be able to choose the various supported
8 USB1.1 and USB2.0 DVB devices. 6 USB1.1 and USB2.0 DVB devices.
@@ -246,6 +244,14 @@ config DVB_USB_AF9005_REMOTE
246 Say Y here to support the default remote control decoding for the 244 Say Y here to support the default remote control decoding for the
247 Afatech AF9005 based receiver. 245 Afatech AF9005 based receiver.
248 246
247config DVB_USB_DW2102
248 tristate "DvbWorld 2102 DVB-S USB2.0 receiver"
249 depends on DVB_USB
250 select DVB_STV0299 if !DVB_FE_CUSTOMISE
251 select DVB_PLL if !DVB_FE_CUSTOMISE
252 help
253 Say Y here to support the DvbWorld 2102 DVB-S USB2.0 receiver.
254
249config DVB_USB_ANYSEE 255config DVB_USB_ANYSEE
250 tristate "Anysee DVB-T/C USB2.0 support" 256 tristate "Anysee DVB-T/C USB2.0 support"
251 depends on DVB_USB 257 depends on DVB_USB
diff --git a/drivers/media/dvb/dvb-usb/Makefile b/drivers/media/dvb/dvb-usb/Makefile
index 44c11e45e564..e206f1ea0027 100644
--- a/drivers/media/dvb/dvb-usb/Makefile
+++ b/drivers/media/dvb/dvb-usb/Makefile
@@ -64,6 +64,9 @@ obj-$(CONFIG_DVB_USB_AF9005_REMOTE) += dvb-usb-af9005-remote.o
64dvb-usb-anysee-objs = anysee.o 64dvb-usb-anysee-objs = anysee.o
65obj-$(CONFIG_DVB_USB_ANYSEE) += dvb-usb-anysee.o 65obj-$(CONFIG_DVB_USB_ANYSEE) += dvb-usb-anysee.o
66 66
67dvb-usb-dw2102-objs = dw2102.o
68obj-$(CONFIG_DVB_USB_DW2102) += dvb-usb-dw2102.o
69
67EXTRA_CFLAGS += -Idrivers/media/dvb/dvb-core/ -Idrivers/media/dvb/frontends/ 70EXTRA_CFLAGS += -Idrivers/media/dvb/dvb-core/ -Idrivers/media/dvb/frontends/
68# due to tuner-xc3028 71# due to tuner-xc3028
69EXTRA_CFLAGS += -Idrivers/media/common/tuners 72EXTRA_CFLAGS += -Idrivers/media/common/tuners
diff --git a/drivers/media/dvb/dvb-usb/anysee.c b/drivers/media/dvb/dvb-usb/anysee.c
index adfd4fc82efd..2f408d2e1ef3 100644
--- a/drivers/media/dvb/dvb-usb/anysee.c
+++ b/drivers/media/dvb/dvb-usb/anysee.c
@@ -43,7 +43,7 @@ module_param_named(debug, dvb_usb_anysee_debug, int, 0644);
43MODULE_PARM_DESC(debug, "set debugging level" DVB_USB_DEBUG_STATUS); 43MODULE_PARM_DESC(debug, "set debugging level" DVB_USB_DEBUG_STATUS);
44DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr); 44DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
45 45
46struct mutex anysee_usb_mutex; 46static struct mutex anysee_usb_mutex;
47 47
48static int anysee_ctrl_msg(struct dvb_usb_device *d, u8 *sbuf, u8 slen, 48static int anysee_ctrl_msg(struct dvb_usb_device *d, u8 *sbuf, u8 slen,
49 u8 *rbuf, u8 rlen) 49 u8 *rbuf, u8 rlen)
diff --git a/drivers/media/dvb/dvb-usb/dvb-usb-ids.h b/drivers/media/dvb/dvb-usb/dvb-usb-ids.h
index e5238b31e946..029b437caf9a 100644
--- a/drivers/media/dvb/dvb-usb/dvb-usb-ids.h
+++ b/drivers/media/dvb/dvb-usb/dvb-usb-ids.h
@@ -204,5 +204,6 @@
204#define USB_PID_ASUS_U3000 0x171f 204#define USB_PID_ASUS_U3000 0x171f
205#define USB_PID_ASUS_U3100 0x173f 205#define USB_PID_ASUS_U3100 0x173f
206#define USB_PID_YUAN_EC372S 0x1edc 206#define USB_PID_YUAN_EC372S 0x1edc
207#define USB_PID_DW2102 0x2102
207 208
208#endif 209#endif
diff --git a/drivers/media/dvb/dvb-usb/dw2102.c b/drivers/media/dvb/dvb-usb/dw2102.c
new file mode 100644
index 000000000000..a4d898b44e55
--- /dev/null
+++ b/drivers/media/dvb/dvb-usb/dw2102.c
@@ -0,0 +1,425 @@
1/* DVB USB framework compliant Linux driver for the DVBWorld DVB-S 2102 Card
2*
3* Copyright (C) 2008 Igor M. Liplianin (liplianin@me.by)
4*
5* This program is free software; you can redistribute it and/or modify it
6* under the terms of the GNU General Public License as published by the
7* Free Software Foundation, version 2.
8*
9* see Documentation/dvb/README.dvb-usb for more information
10*/
11#include <linux/version.h>
12#include "dw2102.h"
13#include "stv0299.h"
14#include "z0194a.h"
15
16#ifndef USB_PID_DW2102
17#define USB_PID_DW2102 0x2102
18#endif
19
20#define DW2102_READ_MSG 0
21#define DW2102_WRITE_MSG 1
22
23#define REG_1F_SYMBOLRATE_BYTE0 0x1f
24#define REG_20_SYMBOLRATE_BYTE1 0x20
25#define REG_21_SYMBOLRATE_BYTE2 0x21
26
27#define DW2102_VOLTAGE_CTRL (0x1800)
28#define DW2102_RC_QUERY (0x1a00)
29
30struct dw2102_state {
31 u32 last_key_pressed;
32};
33struct dw2102_rc_keys {
34 u32 keycode;
35 u32 event;
36};
37
38DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
39
40static int dw2102_op_rw(struct usb_device *dev, u8 request, u16 value,
41 u8 *data, u16 len, int flags)
42{
43 int ret;
44 u8 u8buf[len];
45
46 unsigned int pipe = (flags == DW2102_READ_MSG) ?
47 usb_rcvctrlpipe(dev, 0) : usb_sndctrlpipe(dev, 0);
48 u8 request_type = (flags == DW2102_READ_MSG) ? USB_DIR_IN : USB_DIR_OUT;
49
50 if (flags == DW2102_WRITE_MSG)
51 memcpy(u8buf, data, len);
52 ret = usb_control_msg(dev, pipe, request,
53 request_type | USB_TYPE_VENDOR, value, 0 , u8buf, len, 2000);
54
55 if (flags == DW2102_READ_MSG)
56 memcpy(data, u8buf, len);
57 return ret;
58}
59
60/* I2C */
61
62static int dw2102_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg msg[],
63 int num)
64{
65struct dvb_usb_device *d = i2c_get_adapdata(adap);
66 int i = 0, ret = 0;
67 u8 buf6[] = {0x2c, 0x05, 0xc0, 0, 0, 0, 0};
68 u8 request;
69 u16 value;
70
71 if (!d)
72 return -ENODEV;
73 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
74 return -EAGAIN;
75
76 switch (num) {
77 case 2:
78 /* read stv0299 register */
79 request = 0xb5;
80 value = msg[0].buf[0];/* register */
81 for (i = 0; i < msg[1].len; i++) {
82 value = value + i;
83 ret = dw2102_op_rw(d->udev, 0xb5,
84 value, buf6, 2, DW2102_READ_MSG);
85 msg[1].buf[i] = buf6[0];
86
87 }
88 break;
89 case 1:
90 switch (msg[0].addr) {
91 case 0x68:
92 /* write to stv0299 register */
93 buf6[0] = 0x2a;
94 buf6[1] = msg[0].buf[0];
95 buf6[2] = msg[0].buf[1];
96 ret = dw2102_op_rw(d->udev, 0xb2,
97 0, buf6, 3, DW2102_WRITE_MSG);
98 break;
99 case 0x60:
100 if (msg[0].flags == 0) {
101 /* write to tuner pll */
102 buf6[0] = 0x2c;
103 buf6[1] = 5;
104 buf6[2] = 0xc0;
105 buf6[3] = msg[0].buf[0];
106 buf6[4] = msg[0].buf[1];
107 buf6[5] = msg[0].buf[2];
108 buf6[6] = msg[0].buf[3];
109 ret = dw2102_op_rw(d->udev, 0xb2,
110 0, buf6, 7, DW2102_WRITE_MSG);
111 } else {
112 /* write to tuner pll */
113 ret = dw2102_op_rw(d->udev, 0xb5,
114 0, buf6, 1, DW2102_READ_MSG);
115 msg[0].buf[0] = buf6[0];
116 }
117 break;
118 case (DW2102_RC_QUERY):
119 ret = dw2102_op_rw(d->udev, 0xb8,
120 0, buf6, 2, DW2102_READ_MSG);
121 msg[0].buf[0] = buf6[0];
122 msg[0].buf[1] = buf6[1];
123 break;
124 case (DW2102_VOLTAGE_CTRL):
125 buf6[0] = 0x30;
126 buf6[1] = msg[0].buf[0];
127 ret = dw2102_op_rw(d->udev, 0xb2,
128 0, buf6, 2, DW2102_WRITE_MSG);
129 break;
130 }
131
132 break;
133 }
134
135 mutex_unlock(&d->i2c_mutex);
136 return num;
137}
138
139static u32 dw2102_i2c_func(struct i2c_adapter *adapter)
140{
141 return I2C_FUNC_I2C;
142}
143
144static struct i2c_algorithm dw2102_i2c_algo = {
145 .master_xfer = dw2102_i2c_transfer,
146 .functionality = dw2102_i2c_func,
147};
148
149static int dw2102_set_voltage(struct dvb_frontend *fe, fe_sec_voltage_t voltage)
150{
151 static u8 command_13v[1] = {0x00};
152 static u8 command_18v[1] = {0x01};
153 struct i2c_msg msg[] = {
154 {.addr = DW2102_VOLTAGE_CTRL, .flags = 0,
155 .buf = command_13v, .len = 1},
156 };
157
158 struct dvb_usb_adapter *udev_adap =
159 (struct dvb_usb_adapter *)(fe->dvb->priv);
160 if (voltage == SEC_VOLTAGE_18)
161 msg[0].buf = command_18v;
162 i2c_transfer(&udev_adap->dev->i2c_adap, msg, 1);
163 return 0;
164}
165
166static int dw2102_frontend_attach(struct dvb_usb_adapter *d)
167{
168 d->fe = dvb_attach(stv0299_attach, &sharp_z0194a_config,
169 &d->dev->i2c_adap);
170 if (d->fe != NULL) {
171 d->fe->ops.set_voltage = dw2102_set_voltage;
172 info("Attached stv0299!\n");
173 return 0;
174 }
175 return -EIO;
176}
177
178static int dw2102_tuner_attach(struct dvb_usb_adapter *adap)
179{
180 dvb_attach(dvb_pll_attach, adap->fe, 0x60,
181 &adap->dev->i2c_adap, DVB_PLL_OPERA1);
182 return 0;
183}
184
185static struct dvb_usb_rc_key dw2102_rc_keys[] = {
186 { 0xf8, 0x0a, KEY_Q }, /*power*/
187 { 0xf8, 0x0c, KEY_M }, /*mute*/
188 { 0xf8, 0x11, KEY_1 },
189 { 0xf8, 0x12, KEY_2 },
190 { 0xf8, 0x13, KEY_3 },
191 { 0xf8, 0x14, KEY_4 },
192 { 0xf8, 0x15, KEY_5 },
193 { 0xf8, 0x16, KEY_6 },
194 { 0xf8, 0x17, KEY_7 },
195 { 0xf8, 0x18, KEY_8 },
196 { 0xf8, 0x19, KEY_9 },
197 { 0xf8, 0x10, KEY_0 },
198 { 0xf8, 0x1c, KEY_PAGEUP }, /*ch+*/
199 { 0xf8, 0x0f, KEY_PAGEDOWN }, /*ch-*/
200 { 0xf8, 0x1a, KEY_O }, /*vol+*/
201 { 0xf8, 0x0e, KEY_Z }, /*vol-*/
202 { 0xf8, 0x04, KEY_R }, /*rec*/
203 { 0xf8, 0x09, KEY_D }, /*fav*/
204 { 0xf8, 0x08, KEY_BACKSPACE }, /*rewind*/
205 { 0xf8, 0x07, KEY_A }, /*fast*/
206 { 0xf8, 0x0b, KEY_P }, /*pause*/
207 { 0xf8, 0x02, KEY_ESC }, /*cancel*/
208 { 0xf8, 0x03, KEY_G }, /*tab*/
209 { 0xf8, 0x00, KEY_UP }, /*up*/
210 { 0xf8, 0x1f, KEY_ENTER }, /*ok*/
211 { 0xf8, 0x01, KEY_DOWN }, /*down*/
212 { 0xf8, 0x05, KEY_C }, /*cap*/
213 { 0xf8, 0x06, KEY_S }, /*stop*/
214 { 0xf8, 0x40, KEY_F }, /*full*/
215 { 0xf8, 0x1e, KEY_W }, /*tvmode*/
216 { 0xf8, 0x1b, KEY_B }, /*recall*/
217
218};
219
220
221
222static int dw2102_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
223{
224 struct dw2102_state *st = d->priv;
225 u8 key[2];
226 struct i2c_msg msg[] = {
227 {.addr = DW2102_RC_QUERY, .flags = I2C_M_RD, .buf = key,
228 .len = 2},
229 };
230 int i;
231
232 *state = REMOTE_NO_KEY_PRESSED;
233 if (dw2102_i2c_transfer(&d->i2c_adap, msg, 1) == 1) {
234 for (i = 0; i < ARRAY_SIZE(dw2102_rc_keys); i++) {
235 if (dw2102_rc_keys[i].data == msg[0].buf[0]) {
236 *state = REMOTE_KEY_PRESSED;
237 *event = dw2102_rc_keys[i].event;
238 st->last_key_pressed =
239 dw2102_rc_keys[i].event;
240 break;
241 }
242 st->last_key_pressed = 0;
243 }
244 }
245 /* info("key: %x %x\n",key[0],key[1]); */
246 return 0;
247}
248
249static struct usb_device_id dw2102_table[] = {
250 {USB_DEVICE(USB_VID_CYPRESS, USB_PID_DW2102)},
251 {USB_DEVICE(USB_VID_CYPRESS, 0x2101)},
252 { }
253};
254
255MODULE_DEVICE_TABLE(usb, dw2102_table);
256
257static int dw2102_load_firmware(struct usb_device *dev,
258 const struct firmware *frmwr)
259{
260 u8 *b, *p;
261 int ret = 0, i;
262 u8 reset;
263 u8 reset16 [] = {0, 0, 0, 0, 0, 0, 0};
264 const struct firmware *fw;
265 const char *filename = "dvb-usb-dw2101.fw";
266 switch (dev->descriptor.idProduct) {
267 case 0x2101:
268 ret = request_firmware(&fw, filename, &dev->dev);
269 if (ret != 0) {
270 err("did not find the firmware file. (%s) "
271 "Please see linux/Documentation/dvb/ for more details "
272 "on firmware-problems.", filename);
273 return ret;
274 }
275 break;
276 case USB_PID_DW2102:
277 fw = frmwr;
278 break;
279 }
280 info("start downloading DW2102 firmware");
281 p = kmalloc(fw->size, GFP_KERNEL);
282 reset = 1;
283 /*stop the CPU*/
284 dw2102_op_rw(dev, 0xa0, 0x7f92, &reset, 1, DW2102_WRITE_MSG);
285 dw2102_op_rw(dev, 0xa0, 0xe600, &reset, 1, DW2102_WRITE_MSG);
286
287 if (p != NULL) {
288 memcpy(p, fw->data, fw->size);
289 for (i = 0; i < fw->size; i += 0x40) {
290 b = (u8 *) p + i;
291 if (dw2102_op_rw
292 (dev, 0xa0, i, b , 0x40,
293 DW2102_WRITE_MSG) != 0x40
294 ) {
295 err("error while transferring firmware");
296 ret = -EINVAL;
297 break;
298 }
299 }
300 /* restart the CPU */
301 reset = 0;
302 if (ret || dw2102_op_rw
303 (dev, 0xa0, 0x7f92, &reset, 1,
304 DW2102_WRITE_MSG) != 1) {
305 err("could not restart the USB controller CPU.");
306 ret = -EINVAL;
307 }
308 if (ret || dw2102_op_rw
309 (dev, 0xa0, 0xe600, &reset, 1,
310 DW2102_WRITE_MSG) != 1) {
311 err("could not restart the USB controller CPU.");
312 ret = -EINVAL;
313 }
314 /* init registers */
315 switch (dev->descriptor.idProduct) {
316 case USB_PID_DW2102:
317 dw2102_op_rw
318 (dev, 0xbf, 0x0040, &reset, 0,
319 DW2102_WRITE_MSG);
320 dw2102_op_rw
321 (dev, 0xb9, 0x0000, &reset16[0], 2,
322 DW2102_READ_MSG);
323 break;
324 case 0x2101:
325 dw2102_op_rw
326 (dev, 0xbc, 0x0030, &reset16[0], 2,
327 DW2102_READ_MSG);
328 dw2102_op_rw
329 (dev, 0xba, 0x0000, &reset16[0], 7,
330 DW2102_READ_MSG);
331 dw2102_op_rw
332 (dev, 0xba, 0x0000, &reset16[0], 7,
333 DW2102_READ_MSG);
334 dw2102_op_rw
335 (dev, 0xb9, 0x0000, &reset16[0], 2,
336 DW2102_READ_MSG);
337 break;
338 }
339 kfree(p);
340 }
341 return ret;
342}
343
344static struct dvb_usb_device_properties dw2102_properties = {
345 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
346 .usb_ctrl = DEVICE_SPECIFIC,
347 .firmware = "dvb-usb-dw2102.fw",
348 .size_of_priv = sizeof(struct dw2102_state),
349 .no_reconnect = 1,
350
351 .i2c_algo = &dw2102_i2c_algo,
352 .rc_key_map = dw2102_rc_keys,
353 .rc_key_map_size = ARRAY_SIZE(dw2102_rc_keys),
354 .rc_interval = 150,
355 .rc_query = dw2102_rc_query,
356
357 .generic_bulk_ctrl_endpoint = 0x81,
358 /* parameter for the MPEG2-data transfer */
359 .num_adapters = 1,
360 .download_firmware = dw2102_load_firmware,
361 .adapter = {
362 {
363 .frontend_attach = dw2102_frontend_attach,
364 .streaming_ctrl = NULL,
365 .tuner_attach = dw2102_tuner_attach,
366 .stream = {
367 .type = USB_BULK,
368 .count = 8,
369 .endpoint = 0x82,
370 .u = {
371 .bulk = {
372 .buffersize = 4096,
373 }
374 }
375 },
376 }
377 },
378 .num_device_descs = 2,
379 .devices = {
380 {"DVBWorld DVB-S 2102 USB2.0",
381 {&dw2102_table[0], NULL},
382 {NULL},
383 },
384 {"DVBWorld DVB-S 2101 USB2.0",
385 {&dw2102_table[1], NULL},
386 {NULL},
387 },
388 }
389};
390
391static int dw2102_probe(struct usb_interface *intf,
392 const struct usb_device_id *id)
393{
394 return dvb_usb_device_init(intf, &dw2102_properties,
395 THIS_MODULE, NULL, adapter_nr);
396}
397
398static struct usb_driver dw2102_driver = {
399 .name = "dw2102",
400 .probe = dw2102_probe,
401 .disconnect = dvb_usb_device_exit,
402 .id_table = dw2102_table,
403};
404
405static int __init dw2102_module_init(void)
406{
407 int ret = usb_register(&dw2102_driver);
408 if (ret)
409 err("usb_register failed. Error number %d", ret);
410
411 return ret;
412}
413
414static void __exit dw2102_module_exit(void)
415{
416 usb_deregister(&dw2102_driver);
417}
418
419module_init(dw2102_module_init);
420module_exit(dw2102_module_exit);
421
422MODULE_AUTHOR("Igor M. Liplianin (c) liplianin@me.by");
423MODULE_DESCRIPTION("Driver for DVBWorld DVB-S 2101 2102 USB2.0 device");
424MODULE_VERSION("0.1");
425MODULE_LICENSE("GPL");
diff --git a/drivers/media/dvb/dvb-usb/dw2102.h b/drivers/media/dvb/dvb-usb/dw2102.h
new file mode 100644
index 000000000000..7a310f906837
--- /dev/null
+++ b/drivers/media/dvb/dvb-usb/dw2102.h
@@ -0,0 +1,9 @@
1#ifndef _DW2102_H_
2#define _DW2102_H_
3
4#define DVB_USB_LOG_PREFIX "dw2102"
5#include "dvb-usb.h"
6
7extern int dvb_usb_dw2102_debug;
8#define deb_xfer(args...) dprintk(dvb_usb_dw2102_debug, 0x02, args)
9#endif
diff --git a/drivers/media/dvb/frontends/Kconfig b/drivers/media/dvb/frontends/Kconfig
index c20553c4da1f..574dffe91b68 100644
--- a/drivers/media/dvb/frontends/Kconfig
+++ b/drivers/media/dvb/frontends/Kconfig
@@ -97,9 +97,8 @@ comment "DVB-T (terrestrial) frontends"
97 97
98config DVB_SP8870 98config DVB_SP8870
99 tristate "Spase sp8870 based" 99 tristate "Spase sp8870 based"
100 depends on DVB_CORE && I2C && HOTPLUG 100 depends on DVB_CORE && I2C
101 default m if DVB_FE_CUSTOMISE 101 default m if DVB_FE_CUSTOMISE
102 select FW_LOADER
103 help 102 help
104 A DVB-T tuner module. Say Y when you want to support this frontend. 103 A DVB-T tuner module. Say Y when you want to support this frontend.
105 104
@@ -110,9 +109,8 @@ config DVB_SP8870
110 109
111config DVB_SP887X 110config DVB_SP887X
112 tristate "Spase sp887x based" 111 tristate "Spase sp887x based"
113 depends on DVB_CORE && I2C && HOTPLUG 112 depends on DVB_CORE && I2C
114 default m if DVB_FE_CUSTOMISE 113 default m if DVB_FE_CUSTOMISE
115 select FW_LOADER
116 help 114 help
117 A DVB-T tuner module. Say Y when you want to support this frontend. 115 A DVB-T tuner module. Say Y when you want to support this frontend.
118 116
@@ -135,6 +133,20 @@ config DVB_CX22702
135 help 133 help
136 A DVB-T tuner module. Say Y when you want to support this frontend. 134 A DVB-T tuner module. Say Y when you want to support this frontend.
137 135
136config DVB_DRX397XD
137 tristate "Micronas DRX3975D/DRX3977D based"
138 depends on DVB_CORE && I2C && HOTPLUG
139 default m if DVB_FE_CUSTOMISE
140 select FW_LOADER
141 help
142 A DVB-T tuner module. Say Y when you want to support this frontend.
143
144 TODO:
145 This driver needs external firmware. Please use the command
146 "<kerneldir>/Documentation/dvb/get_dvb_firmware drx397xD" to
147 download/extract them, and then copy them to /usr/lib/hotplug/firmware
148 or /lib/firmware (depending on configuration of firmware hotplug).
149
138config DVB_L64781 150config DVB_L64781
139 tristate "LSI L64781" 151 tristate "LSI L64781"
140 depends on DVB_CORE && I2C 152 depends on DVB_CORE && I2C
@@ -144,9 +156,8 @@ config DVB_L64781
144 156
145config DVB_TDA1004X 157config DVB_TDA1004X
146 tristate "Philips TDA10045H/TDA10046H based" 158 tristate "Philips TDA10045H/TDA10046H based"
147 depends on DVB_CORE && I2C && HOTPLUG 159 depends on DVB_CORE && I2C
148 default m if DVB_FE_CUSTOMISE 160 default m if DVB_FE_CUSTOMISE
149 select FW_LOADER
150 help 161 help
151 A DVB-T tuner module. Say Y when you want to support this frontend. 162 A DVB-T tuner module. Say Y when you want to support this frontend.
152 163
@@ -211,9 +222,8 @@ config DVB_DIB7000P
211 222
212config DVB_TDA10048 223config DVB_TDA10048
213 tristate "Philips TDA10048HN based" 224 tristate "Philips TDA10048HN based"
214 depends on DVB_CORE && I2C && HOTPLUG 225 depends on DVB_CORE && I2C
215 default m if DVB_FE_CUSTOMISE 226 default m if DVB_FE_CUSTOMISE
216 select FW_LOADER
217 help 227 help
218 A DVB-T tuner module. Say Y when you want to support this frontend. 228 A DVB-T tuner module. Say Y when you want to support this frontend.
219 229
@@ -253,9 +263,8 @@ comment "ATSC (North American/Korean Terrestrial/Cable DTV) frontends"
253 263
254config DVB_NXT200X 264config DVB_NXT200X
255 tristate "NxtWave Communications NXT2002/NXT2004 based" 265 tristate "NxtWave Communications NXT2002/NXT2004 based"
256 depends on DVB_CORE && I2C && HOTPLUG 266 depends on DVB_CORE && I2C
257 default m if DVB_FE_CUSTOMISE 267 default m if DVB_FE_CUSTOMISE
258 select FW_LOADER
259 help 268 help
260 An ATSC 8VSB and QAM64/256 tuner module. Say Y when you want 269 An ATSC 8VSB and QAM64/256 tuner module. Say Y when you want
261 to support this frontend. 270 to support this frontend.
@@ -268,9 +277,8 @@ config DVB_NXT200X
268 277
269config DVB_OR51211 278config DVB_OR51211
270 tristate "Oren OR51211 based" 279 tristate "Oren OR51211 based"
271 depends on DVB_CORE && I2C && HOTPLUG 280 depends on DVB_CORE && I2C
272 default m if DVB_FE_CUSTOMISE 281 default m if DVB_FE_CUSTOMISE
273 select FW_LOADER
274 help 282 help
275 An ATSC 8VSB tuner module. Say Y when you want to support this frontend. 283 An ATSC 8VSB tuner module. Say Y when you want to support this frontend.
276 284
@@ -281,9 +289,8 @@ config DVB_OR51211
281 289
282config DVB_OR51132 290config DVB_OR51132
283 tristate "Oren OR51132 based" 291 tristate "Oren OR51132 based"
284 depends on DVB_CORE && I2C && HOTPLUG 292 depends on DVB_CORE && I2C
285 default m if DVB_FE_CUSTOMISE 293 default m if DVB_FE_CUSTOMISE
286 select FW_LOADER
287 help 294 help
288 An ATSC 8VSB and QAM64/256 tuner module. Say Y when you want 295 An ATSC 8VSB and QAM64/256 tuner module. Say Y when you want
289 to support this frontend. 296 to support this frontend.
@@ -297,9 +304,8 @@ config DVB_OR51132
297 304
298config DVB_BCM3510 305config DVB_BCM3510
299 tristate "Broadcom BCM3510" 306 tristate "Broadcom BCM3510"
300 depends on DVB_CORE && I2C && HOTPLUG 307 depends on DVB_CORE && I2C
301 default m if DVB_FE_CUSTOMISE 308 default m if DVB_FE_CUSTOMISE
302 select FW_LOADER
303 help 309 help
304 An ATSC 8VSB/16VSB and QAM64/256 tuner module. Say Y when you want to 310 An ATSC 8VSB/16VSB and QAM64/256 tuner module. Say Y when you want to
305 support this frontend. 311 support this frontend.
diff --git a/drivers/media/dvb/frontends/Makefile b/drivers/media/dvb/frontends/Makefile
index a89dc0fc4c6f..028da55611c0 100644
--- a/drivers/media/dvb/frontends/Makefile
+++ b/drivers/media/dvb/frontends/Makefile
@@ -25,6 +25,7 @@ obj-$(CONFIG_DVB_NXT6000) += nxt6000.o
25obj-$(CONFIG_DVB_MT352) += mt352.o 25obj-$(CONFIG_DVB_MT352) += mt352.o
26obj-$(CONFIG_DVB_ZL10353) += zl10353.o 26obj-$(CONFIG_DVB_ZL10353) += zl10353.o
27obj-$(CONFIG_DVB_CX22702) += cx22702.o 27obj-$(CONFIG_DVB_CX22702) += cx22702.o
28obj-$(CONFIG_DVB_DRX397XD) += drx397xD.o
28obj-$(CONFIG_DVB_TDA10021) += tda10021.o 29obj-$(CONFIG_DVB_TDA10021) += tda10021.o
29obj-$(CONFIG_DVB_TDA10023) += tda10023.o 30obj-$(CONFIG_DVB_TDA10023) += tda10023.o
30obj-$(CONFIG_DVB_STV0297) += stv0297.o 31obj-$(CONFIG_DVB_STV0297) += stv0297.o
diff --git a/drivers/media/dvb/frontends/drx397xD.c b/drivers/media/dvb/frontends/drx397xD.c
new file mode 100644
index 000000000000..3cbed874a6f8
--- /dev/null
+++ b/drivers/media/dvb/frontends/drx397xD.c
@@ -0,0 +1,1504 @@
1/*
2 * Driver for Micronas drx397xD demodulator
3 *
4 * Copyright (C) 2007 Henk Vergonet <Henk.Vergonet@gmail.com>
5 *
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.
10 *
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.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#define DEBUG /* uncomment if you want debugging output */
21#include <linux/kernel.h>
22#include <linux/module.h>
23#include <linux/moduleparam.h>
24#include <linux/init.h>
25#include <linux/device.h>
26#include <linux/delay.h>
27#include <linux/string.h>
28#include <linux/firmware.h>
29#include <asm/div64.h>
30
31#include "dvb_frontend.h"
32#include "drx397xD.h"
33
34static const char mod_name[] = "drx397xD";
35
36#define MAX_CLOCK_DRIFT 200 /* maximal 200 PPM allowed */
37
38#define F_SET_0D0h 1
39#define F_SET_0D4h 2
40
41typedef enum fw_ix {
42#define _FW_ENTRY(a, b) b
43#include "drx397xD_fw.h"
44} fw_ix_t;
45
46/* chip specifics */
47struct drx397xD_state {
48 struct i2c_adapter *i2c;
49 struct dvb_frontend frontend;
50 struct drx397xD_config config;
51 fw_ix_t chip_rev;
52 int flags;
53 u32 bandwidth_parm; /* internal bandwidth conversions */
54 u32 f_osc; /* w90: actual osc frequency [Hz] */
55};
56
57/*******************************************************************************
58 * Firmware
59 ******************************************************************************/
60
61static const char *blob_name[] = {
62#define _BLOB_ENTRY(a, b) a
63#include "drx397xD_fw.h"
64};
65
66typedef enum blob_ix {
67#define _BLOB_ENTRY(a, b) b
68#include "drx397xD_fw.h"
69} blob_ix_t;
70
71static struct {
72 const char *name;
73 const struct firmware *file;
74 rwlock_t lock;
75 int refcnt;
76 const u8 *data[ARRAY_SIZE(blob_name)];
77} fw[] = {
78#define _FW_ENTRY(a, b) { \
79 .name = a, \
80 .file = 0, \
81 .lock = RW_LOCK_UNLOCKED, \
82 .refcnt = 0, \
83 .data = { } }
84#include "drx397xD_fw.h"
85};
86
87/* use only with writer lock aquired */
88static void _drx_release_fw(struct drx397xD_state *s, fw_ix_t ix)
89{
90 memset(&fw[ix].data[0], 0, sizeof(fw[0].data));
91 if (fw[ix].file)
92 release_firmware(fw[ix].file);
93}
94
95static void drx_release_fw(struct drx397xD_state *s)
96{
97 fw_ix_t ix = s->chip_rev;
98
99 pr_debug("%s\n", __FUNCTION__);
100
101 write_lock(&fw[ix].lock);
102 if (fw[ix].refcnt) {
103 fw[ix].refcnt--;
104 if (fw[ix].refcnt == 0)
105 _drx_release_fw(s, ix);
106 }
107 write_unlock(&fw[ix].lock);
108}
109
110static int drx_load_fw(struct drx397xD_state *s, fw_ix_t ix)
111{
112 const u8 *data;
113 size_t size, len;
114 int i = 0, j, rc = -EINVAL;
115
116 pr_debug("%s\n", __FUNCTION__);
117
118 if (ix < 0 || ix >= ARRAY_SIZE(fw))
119 return -EINVAL;
120 s->chip_rev = ix;
121
122 write_lock(&fw[ix].lock);
123 if (fw[ix].file) {
124 rc = 0;
125 goto exit_ok;
126 }
127 memset(&fw[ix].data[0], 0, sizeof(fw[0].data));
128
129 if (request_firmware(&fw[ix].file, fw[ix].name, &s->i2c->dev) != 0) {
130 printk(KERN_ERR "%s: Firmware \"%s\" not available\n",
131 mod_name, fw[ix].name);
132 rc = -ENOENT;
133 goto exit_err;
134 }
135
136 if (!fw[ix].file->data || fw[ix].file->size < 10)
137 goto exit_corrupt;
138
139 data = fw[ix].file->data;
140 size = fw[ix].file->size;
141
142 if (data[i++] != 2) /* check firmware version */
143 goto exit_corrupt;
144
145 do {
146 switch (data[i++]) {
147 case 0x00: /* bytecode */
148 if (i >= size)
149 break;
150 i += data[i];
151 case 0x01: /* reset */
152 case 0x02: /* sleep */
153 i++;
154 break;
155 case 0xfe: /* name */
156 len = strnlen(&data[i], size - i);
157 if (i + len + 1 >= size)
158 goto exit_corrupt;
159 if (data[i + len + 1] != 0)
160 goto exit_corrupt;
161 for (j = 0; j < ARRAY_SIZE(blob_name); j++) {
162 if (strcmp(blob_name[j], &data[i]) == 0) {
163 fw[ix].data[j] = &data[i + len + 1];
164 pr_debug("Loading %s\n", blob_name[j]);
165 }
166 }
167 i += len + 1;
168 break;
169 case 0xff: /* file terminator */
170 if (i == size) {
171 rc = 0;
172 goto exit_ok;
173 }
174 default:
175 goto exit_corrupt;
176 }
177 } while (i < size);
178 exit_corrupt:
179 printk(KERN_ERR "%s: Firmware is corrupt\n", mod_name);
180 exit_err:
181 _drx_release_fw(s, ix);
182 fw[ix].refcnt--;
183 exit_ok:
184 fw[ix].refcnt++;
185 write_unlock(&fw[ix].lock);
186 return rc;
187}
188
189/*******************************************************************************
190 * i2c bus IO
191 ******************************************************************************/
192
193static int write_fw(struct drx397xD_state *s, blob_ix_t ix)
194{
195 struct i2c_msg msg = {.addr = s->config.demod_address,.flags = 0 };
196 const u8 *data;
197 int len, rc = 0, i = 0;
198
199 if (ix < 0 || ix >= ARRAY_SIZE(blob_name)) {
200 pr_debug("%s drx_fw_ix_t out of range\n", __FUNCTION__);
201 return -EINVAL;
202 }
203 pr_debug("%s %s\n", __FUNCTION__, blob_name[ix]);
204
205 read_lock(&fw[s->chip_rev].lock);
206 data = fw[s->chip_rev].data[ix];
207 if (!data) {
208 rc = -EINVAL;
209 goto exit_rc;
210 }
211
212 for (;;) {
213 switch (data[i++]) {
214 case 0: /* bytecode */
215 len = data[i++];
216 msg.len = len;
217 msg.buf = (__u8 *) &data[i];
218 if (i2c_transfer(s->i2c, &msg, 1) != 1) {
219 rc = -EIO;
220 goto exit_rc;
221 }
222 i += len;
223 break;
224 case 1: /* reset */
225 case 2: /* sleep */
226 i++;
227 break;
228 default:
229 goto exit_rc;
230 }
231 }
232 exit_rc:
233 read_unlock(&fw[s->chip_rev].lock);
234 return 0;
235}
236
237/* Function is not endian safe, use the RD16 wrapper below */
238static int _read16(struct drx397xD_state *s, u32 i2c_adr)
239{
240 int rc;
241 u8 a[4];
242 u16 v;
243 struct i2c_msg msg[2] = {
244 {
245 .addr = s->config.demod_address,
246 .flags = 0,
247 .buf = a,
248 .len = sizeof(a)
249 }
250 , {
251 .addr = s->config.demod_address,
252 .flags = I2C_M_RD,
253 .buf = (u8 *) & v,
254 .len = sizeof(v)
255 }
256 };
257
258 *(u32 *) a = i2c_adr;
259
260 rc = i2c_transfer(s->i2c, msg, 2);
261 if (rc != 2)
262 return -EIO;
263
264 return le16_to_cpu(v);
265}
266
267/* Function is not endian safe, use the WR16.. wrappers below */
268static int _write16(struct drx397xD_state *s, u32 i2c_adr, u16 val)
269{
270 u8 a[6];
271 int rc;
272 struct i2c_msg msg = {
273 .addr = s->config.demod_address,
274 .flags = 0,
275 .buf = a,
276 .len = sizeof(a)
277 };
278
279 *(u32 *) a = i2c_adr;
280 *(u16 *) & a[4] = val;
281
282 rc = i2c_transfer(s->i2c, &msg, 1);
283 if (rc != 1)
284 return -EIO;
285 return 0;
286}
287
288#define WR16(ss,adr, val) \
289 _write16(ss, I2C_ADR_C0(adr), cpu_to_le16(val))
290#define WR16_E0(ss,adr, val) \
291 _write16(ss, I2C_ADR_E0(adr), cpu_to_le16(val))
292#define RD16(ss,adr) \
293 _read16(ss, I2C_ADR_C0(adr))
294
295#define EXIT_RC( cmd ) if ( (rc = (cmd)) < 0) goto exit_rc
296
297/*******************************************************************************
298 * Tuner callback
299 ******************************************************************************/
300
301static int PLL_Set(struct drx397xD_state *s,
302 struct dvb_frontend_parameters *fep, int *df_tuner)
303{
304 struct dvb_frontend *fe = &s->frontend;
305 u32 f_tuner, f = fep->frequency;
306 int rc;
307
308 pr_debug("%s\n", __FUNCTION__);
309
310 if ((f > s->frontend.ops.tuner_ops.info.frequency_max) ||
311 (f < s->frontend.ops.tuner_ops.info.frequency_min))
312 return -EINVAL;
313
314 *df_tuner = 0;
315 if (!s->frontend.ops.tuner_ops.set_params ||
316 !s->frontend.ops.tuner_ops.get_frequency)
317 return -ENOSYS;
318
319 rc = s->frontend.ops.tuner_ops.set_params(fe, fep);
320 if (rc < 0)
321 return rc;
322
323 rc = s->frontend.ops.tuner_ops.get_frequency(fe, &f_tuner);
324 if (rc < 0)
325 return rc;
326
327 *df_tuner = f_tuner - f;
328 pr_debug("%s requested %d [Hz] tuner %d [Hz]\n", __FUNCTION__, f,
329 f_tuner);
330
331 return 0;
332}
333
334/*******************************************************************************
335 * Demodulator helper functions
336 ******************************************************************************/
337
338static int SC_WaitForReady(struct drx397xD_state *s)
339{
340 int cnt = 1000;
341 int rc;
342
343 pr_debug("%s\n", __FUNCTION__);
344
345 while (cnt--) {
346 rc = RD16(s, 0x820043);
347 if (rc == 0)
348 return 0;
349 }
350 return -1;
351}
352
353static int SC_SendCommand(struct drx397xD_state *s, int cmd)
354{
355 int rc;
356
357 pr_debug("%s\n", __FUNCTION__);
358
359 WR16(s, 0x820043, cmd);
360 SC_WaitForReady(s);
361 rc = RD16(s, 0x820042);
362 if ((rc & 0xffff) == 0xffff)
363 return -1;
364 return 0;
365}
366
367static int HI_Command(struct drx397xD_state *s, u16 cmd)
368{
369 int rc, cnt = 1000;
370
371 pr_debug("%s\n", __FUNCTION__);
372
373 rc = WR16(s, 0x420032, cmd);
374 if (rc < 0)
375 return rc;
376
377 do {
378 rc = RD16(s, 0x420032);
379 if (rc == 0) {
380 rc = RD16(s, 0x420031);
381 return rc;
382 }
383 if (rc < 0)
384 return rc;
385 } while (--cnt);
386 return rc;
387}
388
389static int HI_CfgCommand(struct drx397xD_state *s)
390{
391
392 pr_debug("%s\n", __FUNCTION__);
393
394 WR16(s, 0x420033, 0x3973);
395 WR16(s, 0x420034, s->config.w50); // code 4, log 4
396 WR16(s, 0x420035, s->config.w52); // code 15, log 9
397 WR16(s, 0x420036, s->config.demod_address << 1);
398 WR16(s, 0x420037, s->config.w56); // code (set_i2c ?? initX 1 ), log 1
399// WR16(s, 0x420033, 0x3973);
400 if ((s->config.w56 & 8) == 0)
401 return HI_Command(s, 3);
402 return WR16(s, 0x420032, 0x3);
403}
404
405static const u8 fastIncrDecLUT_15273[] = {
406 0x0e, 0x0f, 0x0f, 0x10, 0x11, 0x12, 0x12, 0x13, 0x14,
407 0x15, 0x16, 0x17, 0x18, 0x1a, 0x1b, 0x1c, 0x1d, 0x1f
408};
409
410static const u8 slowIncrDecLUT_15272[] = {
411 3, 4, 4, 5, 6
412};
413
414static int SetCfgIfAgc(struct drx397xD_state *s, struct drx397xD_CfgIfAgc *agc)
415{
416 u16 w06 = agc->w06;
417 u16 w08 = agc->w08;
418 u16 w0A = agc->w0A;
419 u16 w0C = agc->w0C;
420 int quot, rem, i, rc = -EINVAL;
421
422 pr_debug("%s\n", __FUNCTION__);
423
424 if (agc->w04 > 0x3ff)
425 goto exit_rc;
426
427 if (agc->d00 == 1) {
428 EXIT_RC(RD16(s, 0x0c20010));
429 rc &= ~0x10;
430 EXIT_RC(WR16(s, 0x0c20010, rc));
431 return WR16(s, 0x0c20030, agc->w04 & 0x7ff);
432 }
433
434 if (agc->d00 != 0)
435 goto exit_rc;
436 if (w0A < w08)
437 goto exit_rc;
438 if (w0A > 0x3ff)
439 goto exit_rc;
440 if (w0C > 0x3ff)
441 goto exit_rc;
442 if (w06 > 0x3ff)
443 goto exit_rc;
444
445 EXIT_RC(RD16(s, 0x0c20010));
446 rc |= 0x10;
447 EXIT_RC(WR16(s, 0x0c20010, rc));
448
449 EXIT_RC(WR16(s, 0x0c20025, (w06 >> 1) & 0x1ff));
450 EXIT_RC(WR16(s, 0x0c20031, (w0A - w08) >> 1));
451 EXIT_RC(WR16(s, 0x0c20032, ((w0A + w08) >> 1) - 0x1ff));
452
453 quot = w0C / 113;
454 rem = w0C % 113;
455 if (quot <= 8) {
456 quot = 8 - quot;
457 } else {
458 quot = 0;
459 rem += 113;
460 }
461
462 EXIT_RC(WR16(s, 0x0c20024, quot));
463
464 i = fastIncrDecLUT_15273[rem / 8];
465 EXIT_RC(WR16(s, 0x0c2002d, i));
466 EXIT_RC(WR16(s, 0x0c2002e, i));
467
468 i = slowIncrDecLUT_15272[rem / 28];
469 EXIT_RC(WR16(s, 0x0c2002b, i));
470 rc = WR16(s, 0x0c2002c, i);
471 exit_rc:
472 return rc;
473}
474
475static int SetCfgRfAgc(struct drx397xD_state *s, struct drx397xD_CfgRfAgc *agc)
476{
477 u16 w04 = agc->w04;
478 u16 w06 = agc->w06;
479 int rc = -1;
480
481 pr_debug("%s %d 0x%x 0x%x\n", __FUNCTION__, agc->d00, w04, w06);
482
483 if (w04 > 0x3ff)
484 goto exit_rc;
485
486 switch (agc->d00) {
487 case 1:
488 if (w04 == 0x3ff)
489 w04 = 0x400;
490
491 EXIT_RC(WR16(s, 0x0c20036, w04));
492 s->config.w9C &= ~2;
493 EXIT_RC(WR16(s, 0x0c20015, s->config.w9C));
494 EXIT_RC(RD16(s, 0x0c20010));
495 rc &= 0xbfdf;
496 EXIT_RC(WR16(s, 0x0c20010, rc));
497 EXIT_RC(RD16(s, 0x0c20013));
498 rc &= ~2;
499 break;
500 case 0:
501 // loc_8000659
502 s->config.w9C &= ~2;
503 EXIT_RC(WR16(s, 0x0c20015, s->config.w9C));
504 EXIT_RC(RD16(s, 0x0c20010));
505 rc &= 0xbfdf;
506 rc |= 0x4000;
507 EXIT_RC(WR16(s, 0x0c20010, rc));
508 EXIT_RC(WR16(s, 0x0c20051, (w06 >> 4) & 0x3f));
509 EXIT_RC(RD16(s, 0x0c20013));
510 rc &= ~2;
511 break;
512 default:
513 s->config.w9C |= 2;
514 EXIT_RC(WR16(s, 0x0c20015, s->config.w9C));
515 EXIT_RC(RD16(s, 0x0c20010));
516 rc &= 0xbfdf;
517 EXIT_RC(WR16(s, 0x0c20010, rc));
518
519 EXIT_RC(WR16(s, 0x0c20036, 0));
520
521 EXIT_RC(RD16(s, 0x0c20013));
522 rc |= 2;
523 }
524 rc = WR16(s, 0x0c20013, rc);
525 exit_rc:
526 return rc;
527}
528
529static int GetLockStatus(struct drx397xD_state *s, int *lockstat)
530{
531 int rc;
532
533 *lockstat = 0;
534
535 rc = RD16(s, 0x082004b);
536 if (rc < 0)
537 return rc;
538
539 if (s->config.d60 != 2)
540 return 0;
541
542 if ((rc & 7) == 7)
543 *lockstat |= 1;
544 if ((rc & 3) == 3)
545 *lockstat |= 2;
546 if (rc & 1)
547 *lockstat |= 4;
548 return 0;
549}
550
551static int CorrectSysClockDeviation(struct drx397xD_state *s)
552{
553 int rc = -EINVAL;
554 int lockstat;
555 u32 clk, clk_limit;
556
557 pr_debug("%s\n", __FUNCTION__);
558
559 if (s->config.d5C == 0) {
560 EXIT_RC(WR16(s, 0x08200e8, 0x010));
561 EXIT_RC(WR16(s, 0x08200e9, 0x113));
562 s->config.d5C = 1;
563 return rc;
564 }
565 if (s->config.d5C != 1)
566 goto exit_rc;
567
568 rc = RD16(s, 0x0820048);
569
570 rc = GetLockStatus(s, &lockstat);
571 if (rc < 0)
572 goto exit_rc;
573 if ((lockstat & 1) == 0)
574 goto exit_rc;
575
576 EXIT_RC(WR16(s, 0x0420033, 0x200));
577 EXIT_RC(WR16(s, 0x0420034, 0xc5));
578 EXIT_RC(WR16(s, 0x0420035, 0x10));
579 EXIT_RC(WR16(s, 0x0420036, 0x1));
580 EXIT_RC(WR16(s, 0x0420037, 0xa));
581 EXIT_RC(HI_Command(s, 6));
582 EXIT_RC(RD16(s, 0x0420040));
583 clk = rc;
584 EXIT_RC(RD16(s, 0x0420041));
585 clk |= rc << 16;
586
587 if (clk <= 0x26ffff)
588 goto exit_rc;
589 if (clk > 0x610000)
590 goto exit_rc;
591
592 if (!s->bandwidth_parm)
593 return -EINVAL;
594
595 /* round & convert to Hz */
596 clk = ((u64) (clk + 0x800000) * s->bandwidth_parm + (1 << 20)) >> 21;
597 clk_limit = s->config.f_osc * MAX_CLOCK_DRIFT / 1000;
598
599 if (clk - s->config.f_osc * 1000 + clk_limit <= 2 * clk_limit) {
600 s->f_osc = clk;
601 pr_debug("%s: osc %d %d [Hz]\n", __FUNCTION__,
602 s->config.f_osc * 1000, clk - s->config.f_osc * 1000);
603 }
604 rc = WR16(s, 0x08200e8, 0);
605 exit_rc:
606 return rc;
607}
608
609static int ConfigureMPEGOutput(struct drx397xD_state *s, int type)
610{
611 int rc, si, bp;
612
613 pr_debug("%s\n", __FUNCTION__);
614
615 si = s->config.wA0;
616 if (s->config.w98 == 0) {
617 si |= 1;
618 bp = 0;
619 } else {
620 si &= ~1;
621 bp = 0x200;
622 }
623 if (s->config.w9A == 0) {
624 si |= 0x80;
625 } else {
626 si &= ~0x80;
627 }
628
629 EXIT_RC(WR16(s, 0x2150045, 0));
630 EXIT_RC(WR16(s, 0x2150010, si));
631 EXIT_RC(WR16(s, 0x2150011, bp));
632 rc = WR16(s, 0x2150012, (type == 0 ? 0xfff : 0));
633 exit_rc:
634 return rc;
635}
636
637static int drx_tune(struct drx397xD_state *s,
638 struct dvb_frontend_parameters *fep)
639{
640 u16 v22 = 0;
641 u16 v1C = 0;
642 u16 v1A = 0;
643 u16 v18 = 0;
644 u32 edi = 0, ebx = 0, ebp = 0, edx = 0;
645 u16 v20 = 0, v1E = 0, v16 = 0, v14 = 0, v12 = 0, v10 = 0, v0E = 0;
646
647 int rc, df_tuner;
648 int a, b, c, d;
649 pr_debug("%s %d\n", __FUNCTION__, s->config.d60);
650
651 if (s->config.d60 != 2)
652 goto set_tuner;
653 rc = CorrectSysClockDeviation(s);
654 if (rc < 0)
655 goto set_tuner;
656
657 s->config.d60 = 1;
658 rc = ConfigureMPEGOutput(s, 0);
659 if (rc < 0)
660 goto set_tuner;
661 set_tuner:
662
663 rc = PLL_Set(s, fep, &df_tuner);
664 if (rc < 0) {
665 printk(KERN_ERR "Error in pll_set\n");
666 goto exit_rc;
667 }
668 msleep(200);
669
670 a = rc = RD16(s, 0x2150016);
671 if (rc < 0)
672 goto exit_rc;
673 b = rc = RD16(s, 0x2150010);
674 if (rc < 0)
675 goto exit_rc;
676 c = rc = RD16(s, 0x2150034);
677 if (rc < 0)
678 goto exit_rc;
679 d = rc = RD16(s, 0x2150035);
680 if (rc < 0)
681 goto exit_rc;
682 rc = WR16(s, 0x2150014, c);
683 rc = WR16(s, 0x2150015, d);
684 rc = WR16(s, 0x2150010, 0);
685 rc = WR16(s, 0x2150000, 2);
686 rc = WR16(s, 0x2150036, 0x0fff);
687 rc = WR16(s, 0x2150016, a);
688
689 rc = WR16(s, 0x2150010, 2);
690 rc = WR16(s, 0x2150007, 0);
691 rc = WR16(s, 0x2150000, 1);
692 rc = WR16(s, 0x2110000, 0);
693 rc = WR16(s, 0x0800000, 0);
694 rc = WR16(s, 0x2800000, 0);
695 rc = WR16(s, 0x2110010, 0x664);
696
697 rc = write_fw(s, DRXD_ResetECRAM);
698 rc = WR16(s, 0x2110000, 1);
699
700 rc = write_fw(s, DRXD_InitSC);
701 if (rc < 0)
702 goto exit_rc;
703
704 rc = SetCfgIfAgc(s, &s->config.ifagc);
705 if (rc < 0)
706 goto exit_rc;
707
708 rc = SetCfgRfAgc(s, &s->config.rfagc);
709 if (rc < 0)
710 goto exit_rc;
711
712 if (fep->u.ofdm.transmission_mode != TRANSMISSION_MODE_2K)
713 v22 = 1;
714 switch (fep->u.ofdm.transmission_mode) {
715 case TRANSMISSION_MODE_8K:
716 edi = 1;
717 if (s->chip_rev == DRXD_FW_B1)
718 break;
719
720 rc = WR16(s, 0x2010010, 0);
721 if (rc < 0)
722 break;
723 v1C = 0x63;
724 v1A = 0x53;
725 v18 = 0x43;
726 break;
727 default:
728 edi = 0;
729 if (s->chip_rev == DRXD_FW_B1)
730 break;
731
732 rc = WR16(s, 0x2010010, 1);
733 if (rc < 0)
734 break;
735
736 v1C = 0x61;
737 v1A = 0x47;
738 v18 = 0x41;
739 }
740
741 switch (fep->u.ofdm.guard_interval) {
742 case GUARD_INTERVAL_1_4:
743 edi |= 0x0c;
744 break;
745 case GUARD_INTERVAL_1_8:
746 edi |= 0x08;
747 break;
748 case GUARD_INTERVAL_1_16:
749 edi |= 0x04;
750 break;
751 case GUARD_INTERVAL_1_32:
752 break;
753 default:
754 v22 |= 2;
755 }
756
757 ebx = 0;
758 ebp = 0;
759 v20 = 0;
760 v1E = 0;
761 v16 = 0;
762 v14 = 0;
763 v12 = 0;
764 v10 = 0;
765 v0E = 0;
766
767 switch (fep->u.ofdm.hierarchy_information) {
768 case HIERARCHY_1:
769 edi |= 0x40;
770 if (s->chip_rev == DRXD_FW_B1)
771 break;
772 rc = WR16(s, 0x1c10047, 1);
773 if (rc < 0)
774 goto exit_rc;
775 rc = WR16(s, 0x2010012, 1);
776 if (rc < 0)
777 goto exit_rc;
778 ebx = 0x19f;
779 ebp = 0x1fb;
780 v20 = 0x0c0;
781 v1E = 0x195;
782 v16 = 0x1d6;
783 v14 = 0x1ef;
784 v12 = 4;
785 v10 = 5;
786 v0E = 5;
787 break;
788 case HIERARCHY_2:
789 edi |= 0x80;
790 if (s->chip_rev == DRXD_FW_B1)
791 break;
792 rc = WR16(s, 0x1c10047, 2);
793 if (rc < 0)
794 goto exit_rc;
795 rc = WR16(s, 0x2010012, 2);
796 if (rc < 0)
797 goto exit_rc;
798 ebx = 0x08f;
799 ebp = 0x12f;
800 v20 = 0x0c0;
801 v1E = 0x11e;
802 v16 = 0x1d6;
803 v14 = 0x15e;
804 v12 = 4;
805 v10 = 5;
806 v0E = 5;
807 break;
808 case HIERARCHY_4:
809 edi |= 0xc0;
810 if (s->chip_rev == DRXD_FW_B1)
811 break;
812 rc = WR16(s, 0x1c10047, 3);
813 if (rc < 0)
814 goto exit_rc;
815 rc = WR16(s, 0x2010012, 3);
816 if (rc < 0)
817 goto exit_rc;
818 ebx = 0x14d;
819 ebp = 0x197;
820 v20 = 0x0c0;
821 v1E = 0x1ce;
822 v16 = 0x1d6;
823 v14 = 0x11a;
824 v12 = 4;
825 v10 = 6;
826 v0E = 5;
827 break;
828 default:
829 v22 |= 8;
830 if (s->chip_rev == DRXD_FW_B1)
831 break;
832 rc = WR16(s, 0x1c10047, 0);
833 if (rc < 0)
834 goto exit_rc;
835 rc = WR16(s, 0x2010012, 0);
836 if (rc < 0)
837 goto exit_rc;
838 // QPSK QAM16 QAM64
839 ebx = 0x19f; // 62
840 ebp = 0x1fb; // 15
841 v20 = 0x16a; // 62
842 v1E = 0x195; // 62
843 v16 = 0x1bb; // 15
844 v14 = 0x1ef; // 15
845 v12 = 5; // 16
846 v10 = 5; // 16
847 v0E = 5; // 16
848 }
849
850 switch (fep->u.ofdm.constellation) {
851 default:
852 v22 |= 4;
853 case QPSK:
854 if (s->chip_rev == DRXD_FW_B1)
855 break;
856
857 rc = WR16(s, 0x1c10046, 0);
858 if (rc < 0)
859 goto exit_rc;
860 rc = WR16(s, 0x2010011, 0);
861 if (rc < 0)
862 goto exit_rc;
863 rc = WR16(s, 0x201001a, 0x10);
864 if (rc < 0)
865 goto exit_rc;
866 rc = WR16(s, 0x201001b, 0);
867 if (rc < 0)
868 goto exit_rc;
869 rc = WR16(s, 0x201001c, 0);
870 if (rc < 0)
871 goto exit_rc;
872 rc = WR16(s, 0x1c10062, v20);
873 if (rc < 0)
874 goto exit_rc;
875 rc = WR16(s, 0x1c1002a, v1C);
876 if (rc < 0)
877 goto exit_rc;
878 rc = WR16(s, 0x1c10015, v16);
879 if (rc < 0)
880 goto exit_rc;
881 rc = WR16(s, 0x1c10016, v12);
882 if (rc < 0)
883 goto exit_rc;
884 break;
885 case QAM_16:
886 edi |= 0x10;
887 if (s->chip_rev == DRXD_FW_B1)
888 break;
889
890 rc = WR16(s, 0x1c10046, 1);
891 if (rc < 0)
892 goto exit_rc;
893 rc = WR16(s, 0x2010011, 1);
894 if (rc < 0)
895 goto exit_rc;
896 rc = WR16(s, 0x201001a, 0x10);
897 if (rc < 0)
898 goto exit_rc;
899 rc = WR16(s, 0x201001b, 4);
900 if (rc < 0)
901 goto exit_rc;
902 rc = WR16(s, 0x201001c, 0);
903 if (rc < 0)
904 goto exit_rc;
905 rc = WR16(s, 0x1c10062, v1E);
906 if (rc < 0)
907 goto exit_rc;
908 rc = WR16(s, 0x1c1002a, v1A);
909 if (rc < 0)
910 goto exit_rc;
911 rc = WR16(s, 0x1c10015, v14);
912 if (rc < 0)
913 goto exit_rc;
914 rc = WR16(s, 0x1c10016, v10);
915 if (rc < 0)
916 goto exit_rc;
917 break;
918 case QAM_64:
919 edi |= 0x20;
920 rc = WR16(s, 0x1c10046, 2);
921 if (rc < 0)
922 goto exit_rc;
923 rc = WR16(s, 0x2010011, 2);
924 if (rc < 0)
925 goto exit_rc;
926 rc = WR16(s, 0x201001a, 0x20);
927 if (rc < 0)
928 goto exit_rc;
929 rc = WR16(s, 0x201001b, 8);
930 if (rc < 0)
931 goto exit_rc;
932 rc = WR16(s, 0x201001c, 2);
933 if (rc < 0)
934 goto exit_rc;
935 rc = WR16(s, 0x1c10062, ebx);
936 if (rc < 0)
937 goto exit_rc;
938 rc = WR16(s, 0x1c1002a, v18);
939 if (rc < 0)
940 goto exit_rc;
941 rc = WR16(s, 0x1c10015, ebp);
942 if (rc < 0)
943 goto exit_rc;
944 rc = WR16(s, 0x1c10016, v0E);
945 if (rc < 0)
946 goto exit_rc;
947 break;
948 }
949
950 if (s->config.s20d24 == 1) {
951 rc = WR16(s, 0x2010013, 0);
952 } else {
953 rc = WR16(s, 0x2010013, 1);
954 edi |= 0x1000;
955 }
956
957 switch (fep->u.ofdm.code_rate_HP) {
958 default:
959 v22 |= 0x10;
960 case FEC_1_2:
961 if (s->chip_rev == DRXD_FW_B1)
962 break;
963 rc = WR16(s, 0x2090011, 0);
964 break;
965 case FEC_2_3:
966 edi |= 0x200;
967 if (s->chip_rev == DRXD_FW_B1)
968 break;
969 rc = WR16(s, 0x2090011, 1);
970 break;
971 case FEC_3_4:
972 edi |= 0x400;
973 if (s->chip_rev == DRXD_FW_B1)
974 break;
975 rc = WR16(s, 0x2090011, 2);
976 break;
977 case FEC_5_6: /* 5 */
978 edi |= 0x600;
979 if (s->chip_rev == DRXD_FW_B1)
980 break;
981 rc = WR16(s, 0x2090011, 3);
982 break;
983 case FEC_7_8: /* 7 */
984 edi |= 0x800;
985 if (s->chip_rev == DRXD_FW_B1)
986 break;
987 rc = WR16(s, 0x2090011, 4);
988 break;
989 };
990 if (rc < 0)
991 goto exit_rc;
992
993 switch (fep->u.ofdm.bandwidth) {
994 default:
995 rc = -EINVAL;
996 goto exit_rc;
997 case BANDWIDTH_8_MHZ: /* 0 */
998 case BANDWIDTH_AUTO:
999 rc = WR16(s, 0x0c2003f, 0x32);
1000 s->bandwidth_parm = ebx = 0x8b8249; // 9142857
1001 edx = 0;
1002 break;
1003 case BANDWIDTH_7_MHZ:
1004 rc = WR16(s, 0x0c2003f, 0x3b);
1005 s->bandwidth_parm = ebx = 0x7a1200; // 8000000
1006 edx = 0x4807;
1007 break;
1008 case BANDWIDTH_6_MHZ:
1009 rc = WR16(s, 0x0c2003f, 0x47);
1010 s->bandwidth_parm = ebx = 0x68a1b6; // 6857142
1011 edx = 0x0f07;
1012 break;
1013 };
1014
1015 if (rc < 0)
1016 goto exit_rc;
1017
1018 rc = WR16(s, 0x08200ec, edx);
1019 if (rc < 0)
1020 goto exit_rc;
1021
1022 rc = RD16(s, 0x0820050);
1023 if (rc < 0)
1024 goto exit_rc;
1025 rc = WR16(s, 0x0820050, rc);
1026
1027 {
1028 /* Configure bandwidth specific factor */
1029 ebx = div64_u64(((u64) (s->f_osc) << 21) + (ebx >> 1),
1030 (u64)ebx) - 0x800000;
1031 EXIT_RC(WR16(s, 0x0c50010, ebx & 0xffff));
1032 EXIT_RC(WR16(s, 0x0c50011, ebx >> 16));
1033
1034 /* drx397xD oscillator calibration */
1035 ebx = div64_u64(((u64) (s->config.f_if + df_tuner) << 28) +
1036 (s->f_osc >> 1), (u64)s->f_osc);
1037 }
1038 ebx &= 0xfffffff;
1039 if (fep->inversion == INVERSION_ON)
1040 ebx = 0x10000000 - ebx;
1041
1042 EXIT_RC(WR16(s, 0x0c30010, ebx & 0xffff));
1043 EXIT_RC(WR16(s, 0x0c30011, ebx >> 16));
1044
1045 EXIT_RC(WR16(s, 0x0800000, 1));
1046 EXIT_RC(RD16(s, 0x0800000));
1047
1048
1049 EXIT_RC(SC_WaitForReady(s));
1050 EXIT_RC(WR16(s, 0x0820042, 0));
1051 EXIT_RC(WR16(s, 0x0820041, v22));
1052 EXIT_RC(WR16(s, 0x0820040, edi));
1053 EXIT_RC(SC_SendCommand(s, 3));
1054
1055 rc = RD16(s, 0x0800000);
1056
1057 SC_WaitForReady(s);
1058 WR16(s, 0x0820042, 0);
1059 WR16(s, 0x0820041, 1);
1060 WR16(s, 0x0820040, 1);
1061 SC_SendCommand(s, 1);
1062
1063// rc = WR16(s, 0x2150000, 1);
1064// if (rc < 0) goto exit_rc;
1065
1066 rc = WR16(s, 0x2150000, 2);
1067 rc = WR16(s, 0x2150016, a);
1068 rc = WR16(s, 0x2150010, 4);
1069 rc = WR16(s, 0x2150036, 0);
1070 rc = WR16(s, 0x2150000, 1);
1071 s->config.d60 = 2;
1072 exit_rc:
1073 return rc;
1074}
1075
1076/*******************************************************************************
1077 * DVB interface
1078 ******************************************************************************/
1079
1080static int drx397x_init(struct dvb_frontend *fe)
1081{
1082 struct drx397xD_state *s = fe->demodulator_priv;
1083 int rc;
1084
1085 pr_debug("%s\n", __FUNCTION__);
1086
1087 s->config.rfagc.d00 = 2; /* 0x7c */
1088 s->config.rfagc.w04 = 0;
1089 s->config.rfagc.w06 = 0x3ff;
1090
1091 s->config.ifagc.d00 = 0; /* 0x68 */
1092 s->config.ifagc.w04 = 0;
1093 s->config.ifagc.w06 = 140;
1094 s->config.ifagc.w08 = 0;
1095 s->config.ifagc.w0A = 0x3ff;
1096 s->config.ifagc.w0C = 0x388;
1097
1098 /* for signal strenght calculations */
1099 s->config.ss76 = 820;
1100 s->config.ss78 = 2200;
1101 s->config.ss7A = 150;
1102
1103 /* HI_CfgCommand */
1104 s->config.w50 = 4;
1105 s->config.w52 = 9; // 0xf;
1106
1107 s->config.f_if = 42800000; /* d14: intermediate frequency [Hz] */
1108 s->config.f_osc = 48000; /* s66 : oscillator frequency [kHz] */
1109 s->config.w92 = 12000; // 20000;
1110
1111 s->config.w9C = 0x000e;
1112 s->config.w9E = 0x0000;
1113
1114 /* ConfigureMPEGOutput params */
1115 s->config.wA0 = 4;
1116 s->config.w98 = 1; // 0;
1117 s->config.w9A = 1;
1118
1119 /* get chip revision */
1120 rc = RD16(s, 0x2410019);
1121 if (rc < 0)
1122 return -ENODEV;
1123
1124 if (rc == 0) {
1125 printk(KERN_INFO "%s: chip revision A2\n", mod_name);
1126 rc = drx_load_fw(s, DRXD_FW_A2);
1127 } else {
1128
1129 rc = (rc >> 12) - 3;
1130 switch (rc) {
1131 case 1:
1132 s->flags |= F_SET_0D4h;
1133 case 0:
1134 case 4:
1135 s->flags |= F_SET_0D0h;
1136 break;
1137 case 2:
1138 case 5:
1139 break;
1140 case 3:
1141 s->flags |= F_SET_0D4h;
1142 break;
1143 default:
1144 return -ENODEV;
1145 };
1146 printk(KERN_INFO "%s: chip revision B1.%d\n", mod_name, rc);
1147 rc = drx_load_fw(s, DRXD_FW_B1);
1148 }
1149 if (rc < 0)
1150 goto error;
1151
1152 rc = WR16(s, 0x0420033, 0x3973);
1153 if (rc < 0)
1154 goto error;
1155
1156 rc = HI_Command(s, 2);
1157
1158 msleep(1);
1159
1160 if (s->chip_rev == DRXD_FW_A2) {
1161 rc = WR16(s, 0x043012d, 0x47F);
1162 if (rc < 0)
1163 goto error;
1164 }
1165 rc = WR16_E0(s, 0x0400000, 0);
1166 if (rc < 0)
1167 goto error;
1168
1169 if (s->config.w92 > 20000 || s->config.w92 % 4000) {
1170 printk(KERN_ERR "%s: invalid osc frequency\n", mod_name);
1171 rc = -1;
1172 goto error;
1173 }
1174
1175 rc = WR16(s, 0x2410010, 1);
1176 if (rc < 0)
1177 goto error;
1178 rc = WR16(s, 0x2410011, 0x15);
1179 if (rc < 0)
1180 goto error;
1181 rc = WR16(s, 0x2410012, s->config.w92 / 4000);
1182 if (rc < 0)
1183 goto error;
1184#ifdef ORIG_FW
1185 rc = WR16(s, 0x2410015, 2);
1186 if (rc < 0)
1187 goto error;
1188#endif
1189 rc = WR16(s, 0x2410017, 0x3973);
1190 if (rc < 0)
1191 goto error;
1192
1193 s->f_osc = s->config.f_osc * 1000; /* initial estimator */
1194
1195 s->config.w56 = 1;
1196
1197 rc = HI_CfgCommand(s);
1198 if (rc < 0)
1199 goto error;
1200
1201 rc = write_fw(s, DRXD_InitAtomicRead);
1202 if (rc < 0)
1203 goto error;
1204
1205 if (s->chip_rev == DRXD_FW_A2) {
1206 rc = WR16(s, 0x2150013, 0);
1207 if (rc < 0)
1208 goto error;
1209 }
1210
1211 rc = WR16_E0(s, 0x0400002, 0);
1212 if (rc < 0)
1213 goto error;
1214 rc = WR16(s, 0x0400002, 0);
1215 if (rc < 0)
1216 goto error;
1217
1218 if (s->chip_rev == DRXD_FW_A2) {
1219 rc = write_fw(s, DRXD_ResetCEFR);
1220 if (rc < 0)
1221 goto error;
1222 }
1223 rc = write_fw(s, DRXD_microcode);
1224 if (rc < 0)
1225 goto error;
1226
1227 s->config.w9C = 0x0e;
1228 if (s->flags & F_SET_0D0h) {
1229 s->config.w9C = 0;
1230 rc = RD16(s, 0x0c20010);
1231 if (rc < 0)
1232 goto write_DRXD_InitFE_1;
1233
1234 rc &= ~0x1000;
1235 rc = WR16(s, 0x0c20010, rc);
1236 if (rc < 0)
1237 goto write_DRXD_InitFE_1;
1238
1239 rc = RD16(s, 0x0c20011);
1240 if (rc < 0)
1241 goto write_DRXD_InitFE_1;
1242
1243 rc &= ~0x8;
1244 rc = WR16(s, 0x0c20011, rc);
1245 if (rc < 0)
1246 goto write_DRXD_InitFE_1;
1247
1248 rc = WR16(s, 0x0c20012, 1);
1249 }
1250
1251 write_DRXD_InitFE_1:
1252
1253 rc = write_fw(s, DRXD_InitFE_1);
1254 if (rc < 0)
1255 goto error;
1256
1257 rc = 1;
1258 if (s->chip_rev == DRXD_FW_B1) {
1259 if (s->flags & F_SET_0D0h)
1260 rc = 0;
1261 } else {
1262 if (s->flags & F_SET_0D0h)
1263 rc = 4;
1264 }
1265
1266 rc = WR16(s, 0x0C20012, rc);
1267 if (rc < 0)
1268 goto error;
1269
1270 rc = WR16(s, 0x0C20013, s->config.w9E);
1271 if (rc < 0)
1272 goto error;
1273 rc = WR16(s, 0x0C20015, s->config.w9C);
1274 if (rc < 0)
1275 goto error;
1276
1277 rc = write_fw(s, DRXD_InitFE_2);
1278 if (rc < 0)
1279 goto error;
1280 rc = write_fw(s, DRXD_InitFT);
1281 if (rc < 0)
1282 goto error;
1283 rc = write_fw(s, DRXD_InitCP);
1284 if (rc < 0)
1285 goto error;
1286 rc = write_fw(s, DRXD_InitCE);
1287 if (rc < 0)
1288 goto error;
1289 rc = write_fw(s, DRXD_InitEQ);
1290 if (rc < 0)
1291 goto error;
1292 rc = write_fw(s, DRXD_InitEC);
1293 if (rc < 0)
1294 goto error;
1295 rc = write_fw(s, DRXD_InitSC);
1296 if (rc < 0)
1297 goto error;
1298
1299 rc = SetCfgIfAgc(s, &s->config.ifagc);
1300 if (rc < 0)
1301 goto error;
1302
1303 rc = SetCfgRfAgc(s, &s->config.rfagc);
1304 if (rc < 0)
1305 goto error;
1306
1307 rc = ConfigureMPEGOutput(s, 1);
1308 rc = WR16(s, 0x08201fe, 0x0017);
1309 rc = WR16(s, 0x08201ff, 0x0101);
1310
1311 s->config.d5C = 0;
1312 s->config.d60 = 1;
1313 s->config.d48 = 1;
1314 error:
1315 return rc;
1316}
1317
1318static int drx397x_get_frontend(struct dvb_frontend *fe,
1319 struct dvb_frontend_parameters *params)
1320{
1321 return 0;
1322}
1323
1324static int drx397x_set_frontend(struct dvb_frontend *fe,
1325 struct dvb_frontend_parameters *params)
1326{
1327 struct drx397xD_state *s = fe->demodulator_priv;
1328
1329 s->config.s20d24 = 1; // 0;
1330 return drx_tune(s, params);
1331}
1332
1333static int drx397x_get_tune_settings(struct dvb_frontend *fe,
1334 struct dvb_frontend_tune_settings
1335 *fe_tune_settings)
1336{
1337 fe_tune_settings->min_delay_ms = 10000;
1338 fe_tune_settings->step_size = 0;
1339 fe_tune_settings->max_drift = 0;
1340 return 0;
1341}
1342
1343static int drx397x_read_status(struct dvb_frontend *fe, fe_status_t * status)
1344{
1345 struct drx397xD_state *s = fe->demodulator_priv;
1346 int lockstat;
1347
1348 GetLockStatus(s, &lockstat);
1349 /* TODO */
1350// if (lockstat & 1)
1351// CorrectSysClockDeviation(s);
1352
1353 *status = 0;
1354 if (lockstat & 2) {
1355 CorrectSysClockDeviation(s);
1356 ConfigureMPEGOutput(s, 1);
1357 *status = FE_HAS_LOCK | FE_HAS_SYNC | FE_HAS_VITERBI;
1358 }
1359 if (lockstat & 4) {
1360 *status |= FE_HAS_CARRIER | FE_HAS_SIGNAL;
1361 }
1362
1363 return 0;
1364}
1365
1366static int drx397x_read_ber(struct dvb_frontend *fe, unsigned int *ber)
1367{
1368 *ber = 0;
1369 return 0;
1370}
1371
1372static int drx397x_read_snr(struct dvb_frontend *fe, u16 * snr)
1373{
1374 *snr = 0;
1375 return 0;
1376}
1377
1378static int drx397x_read_signal_strength(struct dvb_frontend *fe, u16 * strength)
1379{
1380 struct drx397xD_state *s = fe->demodulator_priv;
1381 int rc;
1382
1383 if (s->config.ifagc.d00 == 2) {
1384 *strength = 0xffff;
1385 return 0;
1386 }
1387 rc = RD16(s, 0x0c20035);
1388 if (rc < 0) {
1389 *strength = 0;
1390 return 0;
1391 }
1392 rc &= 0x3ff;
1393 /* Signal strength is calculated using the following formula:
1394 *
1395 * a = 2200 * 150 / (2200 + 150);
1396 * a = a * 3300 / (a + 820);
1397 * b = 2200 * 3300 / (2200 + 820);
1398 * c = (((b-a) * rc) >> 10 + a) << 4;
1399 * strength = ~c & 0xffff;
1400 *
1401 * The following does the same but with less rounding errors:
1402 */
1403 *strength = ~(7720 + (rc * 30744 >> 10));
1404 return 0;
1405}
1406
1407static int drx397x_read_ucblocks(struct dvb_frontend *fe,
1408 unsigned int *ucblocks)
1409{
1410 *ucblocks = 0;
1411 return 0;
1412}
1413
1414static int drx397x_sleep(struct dvb_frontend *fe)
1415{
1416 return 0;
1417}
1418
1419static void drx397x_release(struct dvb_frontend *fe)
1420{
1421 struct drx397xD_state *s = fe->demodulator_priv;
1422 printk(KERN_INFO "%s: release demodulator\n", mod_name);
1423 if (s) {
1424 drx_release_fw(s);
1425 kfree(s);
1426 }
1427
1428}
1429
1430static struct dvb_frontend_ops drx397x_ops = {
1431
1432 .info = {
1433 .name = "Micronas DRX397xD DVB-T Frontend",
1434 .type = FE_OFDM,
1435 .frequency_min = 47125000,
1436 .frequency_max = 855250000,
1437 .frequency_stepsize = 166667,
1438 .frequency_tolerance = 0,
1439 .caps = /* 0x0C01B2EAE */
1440 FE_CAN_FEC_1_2 | // = 0x2,
1441 FE_CAN_FEC_2_3 | // = 0x4,
1442 FE_CAN_FEC_3_4 | // = 0x8,
1443 FE_CAN_FEC_5_6 | // = 0x20,
1444 FE_CAN_FEC_7_8 | // = 0x80,
1445 FE_CAN_FEC_AUTO | // = 0x200,
1446 FE_CAN_QPSK | // = 0x400,
1447 FE_CAN_QAM_16 | // = 0x800,
1448 FE_CAN_QAM_64 | // = 0x2000,
1449 FE_CAN_QAM_AUTO | // = 0x10000,
1450 FE_CAN_TRANSMISSION_MODE_AUTO | // = 0x20000,
1451 FE_CAN_GUARD_INTERVAL_AUTO | // = 0x80000,
1452 FE_CAN_HIERARCHY_AUTO | // = 0x100000,
1453 FE_CAN_RECOVER | // = 0x40000000,
1454 FE_CAN_MUTE_TS // = 0x80000000
1455 },
1456
1457 .release = drx397x_release,
1458 .init = drx397x_init,
1459 .sleep = drx397x_sleep,
1460
1461 .set_frontend = drx397x_set_frontend,
1462 .get_tune_settings = drx397x_get_tune_settings,
1463 .get_frontend = drx397x_get_frontend,
1464
1465 .read_status = drx397x_read_status,
1466 .read_snr = drx397x_read_snr,
1467 .read_signal_strength = drx397x_read_signal_strength,
1468 .read_ber = drx397x_read_ber,
1469 .read_ucblocks = drx397x_read_ucblocks,
1470};
1471
1472struct dvb_frontend *drx397xD_attach(const struct drx397xD_config *config,
1473 struct i2c_adapter *i2c)
1474{
1475 struct drx397xD_state *s = NULL;
1476
1477 /* allocate memory for the internal state */
1478 s = kzalloc(sizeof(struct drx397xD_state), GFP_KERNEL);
1479 if (s == NULL)
1480 goto error;
1481
1482 /* setup the state */
1483 s->i2c = i2c;
1484 memcpy(&s->config, config, sizeof(struct drx397xD_config));
1485
1486 /* check if the demod is there */
1487 if (RD16(s, 0x2410019) < 0)
1488 goto error;
1489
1490 /* create dvb_frontend */
1491 memcpy(&s->frontend.ops, &drx397x_ops, sizeof(struct dvb_frontend_ops));
1492 s->frontend.demodulator_priv = s;
1493
1494 return &s->frontend;
1495 error:
1496 kfree(s);
1497 return NULL;
1498}
1499
1500MODULE_DESCRIPTION("Micronas DRX397xD DVB-T Frontend");
1501MODULE_AUTHOR("Henk Vergonet");
1502MODULE_LICENSE("GPL");
1503
1504EXPORT_SYMBOL(drx397xD_attach);
diff --git a/drivers/media/dvb/frontends/drx397xD.h b/drivers/media/dvb/frontends/drx397xD.h
new file mode 100644
index 000000000000..ddc7a07971b7
--- /dev/null
+++ b/drivers/media/dvb/frontends/drx397xD.h
@@ -0,0 +1,130 @@
1/*
2 * Driver for Micronas DVB-T drx397xD demodulator
3 *
4 * Copyright (C) 2007 Henk vergonet <Henk.Vergonet@gmail.com>
5 *
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.
10 *
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 *
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.=
20 */
21
22#ifndef _DRX397XD_H_INCLUDED
23#define _DRX397XD_H_INCLUDED
24
25#include <linux/dvb/frontend.h>
26
27#define DRX_F_STEPSIZE 166667
28#define DRX_F_OFFSET 36000000
29
30#define I2C_ADR_C0(x) \
31( (u32)cpu_to_le32( \
32 (u32)( \
33 (((u32)(x) & (u32)0x000000ffUL) ) | \
34 (((u32)(x) & (u32)0x0000ff00UL) << 16) | \
35 (((u32)(x) & (u32)0x0fff0000UL) >> 8) | \
36 ( (u32)0x00c00000UL) \
37 )) \
38)
39
40#define I2C_ADR_E0(x) \
41( (u32)cpu_to_le32( \
42 (u32)( \
43 (((u32)(x) & (u32)0x000000ffUL) ) | \
44 (((u32)(x) & (u32)0x0000ff00UL) << 16) | \
45 (((u32)(x) & (u32)0x0fff0000UL) >> 8) | \
46 ( (u32)0x00e00000UL) \
47 )) \
48)
49
50struct drx397xD_CfgRfAgc /* 0x7c */
51{
52 int d00; /* 2 */
53 u16 w04;
54 u16 w06;
55};
56
57struct drx397xD_CfgIfAgc /* 0x68 */
58{
59 int d00; /* 0 */
60 u16 w04; /* 0 */
61 u16 w06;
62 u16 w08;
63 u16 w0A;
64 u16 w0C;
65};
66
67struct drx397xD_s20 {
68 int d04;
69 u32 d18;
70 u32 d1C;
71 u32 d20;
72 u32 d14;
73 u32 d24;
74 u32 d0C;
75 u32 d08;
76};
77
78struct drx397xD_config
79{
80 /* demodulator's I2C address */
81 u8 demod_address; /* 0x0f */
82
83 struct drx397xD_CfgIfAgc ifagc; /* 0x68 */
84 struct drx397xD_CfgRfAgc rfagc; /* 0x7c */
85 u32 s20d24;
86
87 /* HI_CfgCommand parameters */
88 u16 w50, w52, /* w54, */ w56;
89
90 int d5C;
91 int d60;
92 int d48;
93 int d28;
94
95 u32 f_if; /* d14: intermediate frequency [Hz] */
96 /* 36000000 on Cinergy 2400i DT */
97 /* 42800000 on Pinnacle Hybrid PRO 330e */
98
99 u16 f_osc; /* s66: 48000 oscillator frequency [kHz] */
100
101 u16 w92; /* 20000 */
102
103 u16 wA0;
104 u16 w98;
105 u16 w9A;
106
107 u16 w9C; /* 0xe0 */
108 u16 w9E; /* 0x00 */
109
110 /* used for signal strength calculations in
111 drx397x_read_signal_strength
112 */
113 u16 ss78; // 2200
114 u16 ss7A; // 150
115 u16 ss76; // 820
116};
117
118#if defined(CONFIG_DVB_DRX397XD) || (defined(CONFIG_DVB_DRX397XD_MODULE) && defined(MODULE))
119extern struct dvb_frontend* drx397xD_attach(const struct drx397xD_config *config,
120 struct i2c_adapter *i2c);
121#else
122static inline struct dvb_frontend* drx397xD_attach(const struct drx397xD_config *config,
123 struct i2c_adapter *i2c)
124{
125 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __FUNCTION__);
126 return NULL;
127}
128#endif /* CONFIG_DVB_DRX397XD */
129
130#endif /* _DRX397XD_H_INCLUDED */
diff --git a/drivers/media/dvb/frontends/drx397xD_fw.h b/drivers/media/dvb/frontends/drx397xD_fw.h
new file mode 100644
index 000000000000..01de02a81cd4
--- /dev/null
+++ b/drivers/media/dvb/frontends/drx397xD_fw.h
@@ -0,0 +1,40 @@
1/*
2 * Firmware definitions for Micronas drx397xD
3 *
4 * Copyright (C) 2007 Henk Vergonet <Henk.Vergonet@gmail.com>
5 *
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.
10 *
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.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#ifdef _FW_ENTRY
21 _FW_ENTRY("drx397xD.A2.fw", DRXD_FW_A2 = 0 ),
22 _FW_ENTRY("drx397xD.B1.fw", DRXD_FW_B1 ),
23#undef _FW_ENTRY
24#endif /* _FW_ENTRY */
25
26#ifdef _BLOB_ENTRY
27 _BLOB_ENTRY("InitAtomicRead", DRXD_InitAtomicRead = 0 ),
28 _BLOB_ENTRY("InitCE", DRXD_InitCE ),
29 _BLOB_ENTRY("InitCP", DRXD_InitCP ),
30 _BLOB_ENTRY("InitEC", DRXD_InitEC ),
31 _BLOB_ENTRY("InitEQ", DRXD_InitEQ ),
32 _BLOB_ENTRY("InitFE_1", DRXD_InitFE_1 ),
33 _BLOB_ENTRY("InitFE_2", DRXD_InitFE_2 ),
34 _BLOB_ENTRY("InitFT", DRXD_InitFT ),
35 _BLOB_ENTRY("InitSC", DRXD_InitSC ),
36 _BLOB_ENTRY("ResetCEFR", DRXD_ResetCEFR ),
37 _BLOB_ENTRY("ResetECRAM", DRXD_ResetECRAM ),
38 _BLOB_ENTRY("microcode", DRXD_microcode ),
39#undef _BLOB_ENTRY
40#endif /* _BLOB_ENTRY */
diff --git a/drivers/media/dvb/frontends/z0194a.h b/drivers/media/dvb/frontends/z0194a.h
new file mode 100644
index 000000000000..d2876d2e1769
--- /dev/null
+++ b/drivers/media/dvb/frontends/z0194a.h
@@ -0,0 +1,97 @@
1/* z0194a.h Sharp z0194a tuner support
2*
3* Copyright (C) 2008 Igor M. Liplianin (liplianin@me.by)
4*
5* This program is free software; you can redistribute it and/or modify it
6* under the terms of the GNU General Public License as published by the
7* Free Software Foundation, version 2.
8*
9* see Documentation/dvb/README.dvb-usb for more information
10*/
11
12#ifndef Z0194A
13#define Z0194A
14
15static int sharp_z0194a__set_symbol_rate(struct dvb_frontend *fe,
16 u32 srate, u32 ratio)
17{
18 u8 aclk = 0;
19 u8 bclk = 0;
20
21 if (srate < 1500000) {
22 aclk = 0xb7; bclk = 0x47; }
23 else if (srate < 3000000) {
24 aclk = 0xb7; bclk = 0x4b; }
25 else if (srate < 7000000) {
26 aclk = 0xb7; bclk = 0x4f; }
27 else if (srate < 14000000) {
28 aclk = 0xb7; bclk = 0x53; }
29 else if (srate < 30000000) {
30 aclk = 0xb6; bclk = 0x53; }
31 else if (srate < 45000000) {
32 aclk = 0xb4; bclk = 0x51; }
33
34 stv0299_writereg(fe, 0x13, aclk);
35 stv0299_writereg(fe, 0x14, bclk);
36 stv0299_writereg(fe, 0x1f, (ratio >> 16) & 0xff);
37 stv0299_writereg(fe, 0x20, (ratio >> 8) & 0xff);
38 stv0299_writereg(fe, 0x21, (ratio) & 0xf0);
39
40 return 0;
41}
42
43static u8 sharp_z0194a__inittab[] = {
44 0x01, 0x15,
45 0x02, 0x00,
46 0x03, 0x00,
47 0x04, 0x7d, /* F22FR = 0x7d, F22 = f_VCO / 128 / 0x7d = 22 kHz */
48 0x05, 0x35, /* I2CT = 0, SCLT = 1, SDAT = 1 */
49 0x06, 0x40, /* DAC not used, set to high impendance mode */
50 0x07, 0x00, /* DAC LSB */
51 0x08, 0x40, /* DiSEqC off, LNB power on OP2/LOCK pin on */
52 0x09, 0x00, /* FIFO */
53 0x0c, 0x51, /* OP1 ctl = Normal, OP1 val = 1 (LNB Power ON) */
54 0x0d, 0x82, /* DC offset compensation = ON, beta_agc1 = 2 */
55 0x0e, 0x23, /* alpha_tmg = 2, beta_tmg = 3 */
56 0x10, 0x3f, /* AGC2 0x3d */
57 0x11, 0x84,
58 0x12, 0xb9,
59 0x15, 0xc9, /* lock detector threshold */
60 0x16, 0x00,
61 0x17, 0x00,
62 0x18, 0x00,
63 0x19, 0x00,
64 0x1a, 0x00,
65 0x1f, 0x50,
66 0x20, 0x00,
67 0x21, 0x00,
68 0x22, 0x00,
69 0x23, 0x00,
70 0x28, 0x00, /* out imp: normal out type: parallel FEC mode:0 */
71 0x29, 0x1e, /* 1/2 threshold */
72 0x2a, 0x14, /* 2/3 threshold */
73 0x2b, 0x0f, /* 3/4 threshold */
74 0x2c, 0x09, /* 5/6 threshold */
75 0x2d, 0x05, /* 7/8 threshold */
76 0x2e, 0x01,
77 0x31, 0x1f, /* test all FECs */
78 0x32, 0x19, /* viterbi and synchro search */
79 0x33, 0xfc, /* rs control */
80 0x34, 0x93, /* error control */
81 0x0f, 0x52,
82 0xff, 0xff
83};
84
85static struct stv0299_config sharp_z0194a_config = {
86 .demod_address = 0x68,
87 .inittab = sharp_z0194a__inittab,
88 .mclk = 88000000UL,
89 .invert = 1,
90 .skip_reinit = 0,
91 .lock_output = STV0299_LOCKOUTPUT_1,
92 .volt13_op0_op1 = STV0299_VOLT13_OP1,
93 .min_delay_ms = 100,
94 .set_symbol_rate = sharp_z0194a__set_symbol_rate,
95};
96
97#endif
diff --git a/drivers/media/dvb/siano/smscoreapi.c b/drivers/media/dvb/siano/smscoreapi.c
index b4b8ed795c95..c5f45fed69dc 100644
--- a/drivers/media/dvb/siano/smscoreapi.c
+++ b/drivers/media/dvb/siano/smscoreapi.c
@@ -110,12 +110,12 @@ struct smscore_registry_entry_t {
110 enum sms_device_type_st type; 110 enum sms_device_type_st type;
111}; 111};
112 112
113struct list_head g_smscore_notifyees; 113static struct list_head g_smscore_notifyees;
114struct list_head g_smscore_devices; 114static struct list_head g_smscore_devices;
115struct mutex g_smscore_deviceslock; 115static struct mutex g_smscore_deviceslock;
116 116
117struct list_head g_smscore_registry; 117static struct list_head g_smscore_registry;
118struct mutex g_smscore_registrylock; 118static struct mutex g_smscore_registrylock;
119 119
120static int default_mode = 4; 120static int default_mode = 4;
121 121
@@ -1187,7 +1187,7 @@ int smsclient_sendrequest(struct smscore_client_t *client,
1187} 1187}
1188 1188
1189 1189
1190int smscore_module_init(void) 1190static int __init smscore_module_init(void)
1191{ 1191{
1192 int rc = 0; 1192 int rc = 0;
1193 1193
@@ -1209,7 +1209,7 @@ int smscore_module_init(void)
1209 return rc; 1209 return rc;
1210} 1210}
1211 1211
1212void smscore_module_exit(void) 1212static void __exit smscore_module_exit(void)
1213{ 1213{
1214 1214
1215 kmutex_lock(&g_smscore_deviceslock); 1215 kmutex_lock(&g_smscore_deviceslock);
diff --git a/drivers/media/dvb/siano/smsdvb.c b/drivers/media/dvb/siano/smsdvb.c
index 6f9c18563867..229274a14110 100644
--- a/drivers/media/dvb/siano/smsdvb.c
+++ b/drivers/media/dvb/siano/smsdvb.c
@@ -27,8 +27,8 @@
27 27
28DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr); 28DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
29 29
30struct list_head g_smsdvb_clients; 30static struct list_head g_smsdvb_clients;
31struct mutex g_smsdvb_clientslock; 31static struct mutex g_smsdvb_clientslock;
32 32
33static int smsdvb_onresponse(void *context, struct smscore_buffer_t *cb) 33static int smsdvb_onresponse(void *context, struct smscore_buffer_t *cb)
34{ 34{
diff --git a/drivers/media/dvb/ttpci/Kconfig b/drivers/media/dvb/ttpci/Kconfig
index 87c973ac668b..41b5a988b619 100644
--- a/drivers/media/dvb/ttpci/Kconfig
+++ b/drivers/media/dvb/ttpci/Kconfig
@@ -5,8 +5,6 @@ config TTPCI_EEPROM
5config DVB_AV7110 5config DVB_AV7110
6 tristate "AV7110 cards" 6 tristate "AV7110 cards"
7 depends on DVB_CORE && PCI && I2C 7 depends on DVB_CORE && PCI && I2C
8 depends on HOTPLUG
9 select FW_LOADER if !DVB_AV7110_FIRMWARE
10 select TTPCI_EEPROM 8 select TTPCI_EEPROM
11 select VIDEO_SAA7146_VV 9 select VIDEO_SAA7146_VV
12 depends on VIDEO_DEV # dependencies of VIDEO_SAA7146_VV 10 depends on VIDEO_DEV # dependencies of VIDEO_SAA7146_VV
@@ -127,14 +125,12 @@ config DVB_BUDGET_AV
127 depends on DVB_BUDGET_CORE && I2C 125 depends on DVB_BUDGET_CORE && I2C
128 select VIDEO_SAA7146_VV 126 select VIDEO_SAA7146_VV
129 depends on VIDEO_DEV # dependencies of VIDEO_SAA7146_VV 127 depends on VIDEO_DEV # dependencies of VIDEO_SAA7146_VV
130 depends on HOTPLUG # dependency of FW_LOADER
131 select DVB_PLL if !DVB_FE_CUSTOMISE 128 select DVB_PLL if !DVB_FE_CUSTOMISE
132 select DVB_STV0299 if !DVB_FE_CUSTOMISE 129 select DVB_STV0299 if !DVB_FE_CUSTOMISE
133 select DVB_TDA1004X if !DVB_FE_CUSTOMISE 130 select DVB_TDA1004X if !DVB_FE_CUSTOMISE
134 select DVB_TDA10021 if !DVB_FE_CUSTOMISE 131 select DVB_TDA10021 if !DVB_FE_CUSTOMISE
135 select DVB_TDA10023 if !DVB_FE_CUSTOMISE 132 select DVB_TDA10023 if !DVB_FE_CUSTOMISE
136 select DVB_TUA6100 if !DVB_FE_CUSTOMISE 133 select DVB_TUA6100 if !DVB_FE_CUSTOMISE
137 select FW_LOADER
138 help 134 help
139 Support for simple SAA7146 based DVB cards 135 Support for simple SAA7146 based DVB cards
140 (so called Budget- or Nova-PCI cards) without onboard 136 (so called Budget- or Nova-PCI cards) without onboard
diff --git a/drivers/media/dvb/ttusb-dec/Kconfig b/drivers/media/dvb/ttusb-dec/Kconfig
index a23cc0aa17d3..d5f48a3102bd 100644
--- a/drivers/media/dvb/ttusb-dec/Kconfig
+++ b/drivers/media/dvb/ttusb-dec/Kconfig
@@ -1,8 +1,6 @@
1config DVB_TTUSB_DEC 1config DVB_TTUSB_DEC
2 tristate "Technotrend/Hauppauge USB DEC devices" 2 tristate "Technotrend/Hauppauge USB DEC devices"
3 depends on DVB_CORE && USB && INPUT 3 depends on DVB_CORE && USB && INPUT
4 depends on HOTPLUG # due to FW_LOADER
5 select FW_LOADER
6 select CRC32 4 select CRC32
7 help 5 help
8 Support for external USB adapters designed by Technotrend and 6 Support for external USB adapters designed by Technotrend and
diff --git a/drivers/media/radio/dsbr100.c b/drivers/media/radio/dsbr100.c
index 4e3f83e4e48f..1ed88f3abe61 100644
--- a/drivers/media/radio/dsbr100.c
+++ b/drivers/media/radio/dsbr100.c
@@ -85,6 +85,7 @@
85#include <linux/input.h> 85#include <linux/input.h>
86#include <linux/videodev2.h> 86#include <linux/videodev2.h>
87#include <media/v4l2-common.h> 87#include <media/v4l2-common.h>
88#include <media/v4l2-ioctl.h>
88#include <linux/usb.h> 89#include <linux/usb.h>
89 90
90/* 91/*
@@ -444,14 +445,7 @@ static const struct file_operations usb_dsbr100_fops = {
444 .llseek = no_llseek, 445 .llseek = no_llseek,
445}; 446};
446 447
447/* V4L2 interface */ 448static const struct v4l2_ioctl_ops usb_dsbr100_ioctl_ops = {
448static struct video_device dsbr100_videodev_template =
449{
450 .owner = THIS_MODULE,
451 .name = "D-Link DSB-R 100",
452 .type = VID_TYPE_TUNER,
453 .fops = &usb_dsbr100_fops,
454 .release = video_device_release,
455 .vidioc_querycap = vidioc_querycap, 449 .vidioc_querycap = vidioc_querycap,
456 .vidioc_g_tuner = vidioc_g_tuner, 450 .vidioc_g_tuner = vidioc_g_tuner,
457 .vidioc_s_tuner = vidioc_s_tuner, 451 .vidioc_s_tuner = vidioc_s_tuner,
@@ -466,6 +460,14 @@ static struct video_device dsbr100_videodev_template =
466 .vidioc_s_input = vidioc_s_input, 460 .vidioc_s_input = vidioc_s_input,
467}; 461};
468 462
463/* V4L2 interface */
464static struct video_device dsbr100_videodev_template = {
465 .name = "D-Link DSB-R 100",
466 .fops = &usb_dsbr100_fops,
467 .ioctl_ops = &usb_dsbr100_ioctl_ops,
468 .release = video_device_release,
469};
470
469/* check if the device is present and register with v4l and 471/* check if the device is present and register with v4l and
470usb if it is */ 472usb if it is */
471static int usb_dsbr100_probe(struct usb_interface *intf, 473static int usb_dsbr100_probe(struct usb_interface *intf,
diff --git a/drivers/media/radio/miropcm20-radio.c b/drivers/media/radio/miropcm20-radio.c
index 09fe6f1cdf14..7fd7ee2d32c1 100644
--- a/drivers/media/radio/miropcm20-radio.c
+++ b/drivers/media/radio/miropcm20-radio.c
@@ -23,6 +23,7 @@
23#include <linux/init.h> 23#include <linux/init.h>
24#include <linux/videodev.h> 24#include <linux/videodev.h>
25#include <media/v4l2-common.h> 25#include <media/v4l2-common.h>
26#include <media/v4l2-ioctl.h>
26#include "oss/aci.h" 27#include "oss/aci.h"
27#include "miropcm20-rds-core.h" 28#include "miropcm20-rds-core.h"
28 29
@@ -228,9 +229,7 @@ static const struct file_operations pcm20_fops = {
228}; 229};
229 230
230static struct video_device pcm20_radio = { 231static struct video_device pcm20_radio = {
231 .owner = THIS_MODULE,
232 .name = "Miro PCM 20 radio", 232 .name = "Miro PCM 20 radio",
233 .type = VID_TYPE_TUNER,
234 .fops = &pcm20_fops, 233 .fops = &pcm20_fops,
235 .priv = &pcm20_unit 234 .priv = &pcm20_unit
236}; 235};
diff --git a/drivers/media/radio/radio-aimslab.c b/drivers/media/radio/radio-aimslab.c
index 1ec18ed1a733..eba9209b3024 100644
--- a/drivers/media/radio/radio-aimslab.c
+++ b/drivers/media/radio/radio-aimslab.c
@@ -36,6 +36,7 @@
36#include <asm/uaccess.h> /* copy to/from user */ 36#include <asm/uaccess.h> /* copy to/from user */
37#include <linux/videodev2.h> /* kernel radio structs */ 37#include <linux/videodev2.h> /* kernel radio structs */
38#include <media/v4l2-common.h> 38#include <media/v4l2-common.h>
39#include <media/v4l2-ioctl.h>
39 40
40#include <linux/version.h> /* for KERNEL_VERSION MACRO */ 41#include <linux/version.h> /* for KERNEL_VERSION MACRO */
41#define RADIO_VERSION KERNEL_VERSION(0,0,2) 42#define RADIO_VERSION KERNEL_VERSION(0,0,2)
@@ -388,12 +389,7 @@ static const struct file_operations rtrack_fops = {
388 .llseek = no_llseek, 389 .llseek = no_llseek,
389}; 390};
390 391
391static struct video_device rtrack_radio= 392static const struct v4l2_ioctl_ops rtrack_ioctl_ops = {
392{
393 .owner = THIS_MODULE,
394 .name = "RadioTrack radio",
395 .type = VID_TYPE_TUNER,
396 .fops = &rtrack_fops,
397 .vidioc_querycap = vidioc_querycap, 393 .vidioc_querycap = vidioc_querycap,
398 .vidioc_g_tuner = vidioc_g_tuner, 394 .vidioc_g_tuner = vidioc_g_tuner,
399 .vidioc_s_tuner = vidioc_s_tuner, 395 .vidioc_s_tuner = vidioc_s_tuner,
@@ -408,6 +404,12 @@ static struct video_device rtrack_radio=
408 .vidioc_s_ctrl = vidioc_s_ctrl, 404 .vidioc_s_ctrl = vidioc_s_ctrl,
409}; 405};
410 406
407static struct video_device rtrack_radio = {
408 .name = "RadioTrack radio",
409 .fops = &rtrack_fops,
410 .ioctl_ops = &rtrack_ioctl_ops,
411};
412
411static int __init rtrack_init(void) 413static int __init rtrack_init(void)
412{ 414{
413 if(io==-1) 415 if(io==-1)
diff --git a/drivers/media/radio/radio-aztech.c b/drivers/media/radio/radio-aztech.c
index 46cdb549eac7..3fe5504428c5 100644
--- a/drivers/media/radio/radio-aztech.c
+++ b/drivers/media/radio/radio-aztech.c
@@ -33,6 +33,7 @@
33#include <asm/uaccess.h> /* copy to/from user */ 33#include <asm/uaccess.h> /* copy to/from user */
34#include <linux/videodev2.h> /* kernel radio structs */ 34#include <linux/videodev2.h> /* kernel radio structs */
35#include <media/v4l2-common.h> 35#include <media/v4l2-common.h>
36#include <media/v4l2-ioctl.h>
36 37
37#include <linux/version.h> /* for KERNEL_VERSION MACRO */ 38#include <linux/version.h> /* for KERNEL_VERSION MACRO */
38#define RADIO_VERSION KERNEL_VERSION(0,0,2) 39#define RADIO_VERSION KERNEL_VERSION(0,0,2)
@@ -352,12 +353,7 @@ static const struct file_operations aztech_fops = {
352 .llseek = no_llseek, 353 .llseek = no_llseek,
353}; 354};
354 355
355static struct video_device aztech_radio= 356static const struct v4l2_ioctl_ops aztech_ioctl_ops = {
356{
357 .owner = THIS_MODULE,
358 .name = "Aztech radio",
359 .type = VID_TYPE_TUNER,
360 .fops = &aztech_fops,
361 .vidioc_querycap = vidioc_querycap, 357 .vidioc_querycap = vidioc_querycap,
362 .vidioc_g_tuner = vidioc_g_tuner, 358 .vidioc_g_tuner = vidioc_g_tuner,
363 .vidioc_s_tuner = vidioc_s_tuner, 359 .vidioc_s_tuner = vidioc_s_tuner,
@@ -372,6 +368,12 @@ static struct video_device aztech_radio=
372 .vidioc_s_ctrl = vidioc_s_ctrl, 368 .vidioc_s_ctrl = vidioc_s_ctrl,
373}; 369};
374 370
371static struct video_device aztech_radio = {
372 .name = "Aztech radio",
373 .fops = &aztech_fops,
374 .ioctl_ops = &aztech_ioctl_ops,
375};
376
375module_param_named(debug,aztech_radio.debug, int, 0644); 377module_param_named(debug,aztech_radio.debug, int, 0644);
376MODULE_PARM_DESC(debug,"activates debug info"); 378MODULE_PARM_DESC(debug,"activates debug info");
377 379
diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
index b14db53ea456..6166e726ed72 100644
--- a/drivers/media/radio/radio-cadet.c
+++ b/drivers/media/radio/radio-cadet.c
@@ -39,6 +39,7 @@
39#include <asm/uaccess.h> /* copy to/from user */ 39#include <asm/uaccess.h> /* copy to/from user */
40#include <linux/videodev2.h> /* V4L2 API defs */ 40#include <linux/videodev2.h> /* V4L2 API defs */
41#include <media/v4l2-common.h> 41#include <media/v4l2-common.h>
42#include <media/v4l2-ioctl.h>
42#include <linux/param.h> 43#include <linux/param.h>
43#include <linux/pnp.h> 44#include <linux/pnp.h>
44 45
@@ -569,12 +570,7 @@ static const struct file_operations cadet_fops = {
569 .llseek = no_llseek, 570 .llseek = no_llseek,
570}; 571};
571 572
572static struct video_device cadet_radio= 573static const struct v4l2_ioctl_ops cadet_ioctl_ops = {
573{
574 .owner = THIS_MODULE,
575 .name = "Cadet radio",
576 .type = VID_TYPE_TUNER,
577 .fops = &cadet_fops,
578 .vidioc_querycap = vidioc_querycap, 574 .vidioc_querycap = vidioc_querycap,
579 .vidioc_g_tuner = vidioc_g_tuner, 575 .vidioc_g_tuner = vidioc_g_tuner,
580 .vidioc_s_tuner = vidioc_s_tuner, 576 .vidioc_s_tuner = vidioc_s_tuner,
@@ -589,6 +585,12 @@ static struct video_device cadet_radio=
589 .vidioc_s_input = vidioc_s_input, 585 .vidioc_s_input = vidioc_s_input,
590}; 586};
591 587
588static struct video_device cadet_radio = {
589 .name = "Cadet radio",
590 .fops = &cadet_fops,
591 .ioctl_ops = &cadet_ioctl_ops,
592};
593
592#ifdef CONFIG_PNP 594#ifdef CONFIG_PNP
593 595
594static struct pnp_device_id cadet_pnp_devices[] = { 596static struct pnp_device_id cadet_pnp_devices[] = {
diff --git a/drivers/media/radio/radio-gemtek-pci.c b/drivers/media/radio/radio-gemtek-pci.c
index de49be971480..36e754e3ffb2 100644
--- a/drivers/media/radio/radio-gemtek-pci.c
+++ b/drivers/media/radio/radio-gemtek-pci.c
@@ -46,6 +46,7 @@
46#include <linux/pci.h> 46#include <linux/pci.h>
47#include <linux/videodev2.h> 47#include <linux/videodev2.h>
48#include <media/v4l2-common.h> 48#include <media/v4l2-common.h>
49#include <media/v4l2-ioctl.h>
49#include <linux/errno.h> 50#include <linux/errno.h>
50 51
51#include <linux/version.h> /* for KERNEL_VERSION MACRO */ 52#include <linux/version.h> /* for KERNEL_VERSION MACRO */
@@ -374,11 +375,7 @@ static const struct file_operations gemtek_pci_fops = {
374 .llseek = no_llseek, 375 .llseek = no_llseek,
375}; 376};
376 377
377static struct video_device vdev_template = { 378static const struct v4l2_ioctl_ops gemtek_pci_ioctl_ops = {
378 .owner = THIS_MODULE,
379 .name = "Gemtek PCI Radio",
380 .type = VID_TYPE_TUNER,
381 .fops = &gemtek_pci_fops,
382 .vidioc_querycap = vidioc_querycap, 379 .vidioc_querycap = vidioc_querycap,
383 .vidioc_g_tuner = vidioc_g_tuner, 380 .vidioc_g_tuner = vidioc_g_tuner,
384 .vidioc_s_tuner = vidioc_s_tuner, 381 .vidioc_s_tuner = vidioc_s_tuner,
@@ -393,6 +390,12 @@ static struct video_device vdev_template = {
393 .vidioc_s_ctrl = vidioc_s_ctrl, 390 .vidioc_s_ctrl = vidioc_s_ctrl,
394}; 391};
395 392
393static struct video_device vdev_template = {
394 .name = "Gemtek PCI Radio",
395 .fops = &gemtek_pci_fops,
396 .ioctl_ops = &gemtek_pci_ioctl_ops,
397};
398
396static int __devinit gemtek_pci_probe( struct pci_dev *pci_dev, const struct pci_device_id *pci_id ) 399static int __devinit gemtek_pci_probe( struct pci_dev *pci_dev, const struct pci_device_id *pci_id )
397{ 400{
398 struct gemtek_pci_card *card; 401 struct gemtek_pci_card *card;
diff --git a/drivers/media/radio/radio-gemtek.c b/drivers/media/radio/radio-gemtek.c
index 81f6aeb1cd11..2b1a6221de6d 100644
--- a/drivers/media/radio/radio-gemtek.c
+++ b/drivers/media/radio/radio-gemtek.c
@@ -23,6 +23,7 @@
23#include <asm/io.h> /* outb, outb_p */ 23#include <asm/io.h> /* outb, outb_p */
24#include <asm/uaccess.h> /* copy to/from user */ 24#include <asm/uaccess.h> /* copy to/from user */
25#include <linux/videodev2.h> /* kernel radio structs */ 25#include <linux/videodev2.h> /* kernel radio structs */
26#include <media/v4l2-ioctl.h>
26#include <media/v4l2-common.h> 27#include <media/v4l2-common.h>
27#include <linux/spinlock.h> 28#include <linux/spinlock.h>
28 29
@@ -552,11 +553,7 @@ static int vidioc_s_audio(struct file *file, void *priv, struct v4l2_audio *a)
552 return 0; 553 return 0;
553} 554}
554 555
555static struct video_device gemtek_radio = { 556static const struct v4l2_ioctl_ops gemtek_ioctl_ops = {
556 .owner = THIS_MODULE,
557 .name = "GemTek Radio card",
558 .type = VID_TYPE_TUNER,
559 .fops = &gemtek_fops,
560 .vidioc_querycap = vidioc_querycap, 557 .vidioc_querycap = vidioc_querycap,
561 .vidioc_g_tuner = vidioc_g_tuner, 558 .vidioc_g_tuner = vidioc_g_tuner,
562 .vidioc_s_tuner = vidioc_s_tuner, 559 .vidioc_s_tuner = vidioc_s_tuner,
@@ -571,6 +568,12 @@ static struct video_device gemtek_radio = {
571 .vidioc_s_ctrl = vidioc_s_ctrl 568 .vidioc_s_ctrl = vidioc_s_ctrl
572}; 569};
573 570
571static struct video_device gemtek_radio = {
572 .name = "GemTek Radio card",
573 .fops = &gemtek_fops,
574 .ioctl_ops = &gemtek_ioctl_ops,
575};
576
574/* 577/*
575 * Initialization / cleanup related stuff. 578 * Initialization / cleanup related stuff.
576 */ 579 */
diff --git a/drivers/media/radio/radio-maestro.c b/drivers/media/radio/radio-maestro.c
index bddd3c409aa9..0ada1c697e8a 100644
--- a/drivers/media/radio/radio-maestro.c
+++ b/drivers/media/radio/radio-maestro.c
@@ -27,6 +27,7 @@
27#include <linux/pci.h> 27#include <linux/pci.h>
28#include <linux/videodev2.h> 28#include <linux/videodev2.h>
29#include <media/v4l2-common.h> 29#include <media/v4l2-common.h>
30#include <media/v4l2-ioctl.h>
30 31
31#include <linux/version.h> /* for KERNEL_VERSION MACRO */ 32#include <linux/version.h> /* for KERNEL_VERSION MACRO */
32#define RADIO_VERSION KERNEL_VERSION(0,0,6) 33#define RADIO_VERSION KERNEL_VERSION(0,0,6)
@@ -354,10 +355,7 @@ static u16 __devinit radio_power_on(struct radio_device *dev)
354 return (ofreq == radio_bits_get(dev)); 355 return (ofreq == radio_bits_get(dev));
355} 356}
356 357
357static struct video_device maestro_radio = { 358static const struct v4l2_ioctl_ops maestro_ioctl_ops = {
358 .name = "Maestro radio",
359 .type = VID_TYPE_TUNER,
360 .fops = &maestro_fops,
361 .vidioc_querycap = vidioc_querycap, 359 .vidioc_querycap = vidioc_querycap,
362 .vidioc_g_tuner = vidioc_g_tuner, 360 .vidioc_g_tuner = vidioc_g_tuner,
363 .vidioc_s_tuner = vidioc_s_tuner, 361 .vidioc_s_tuner = vidioc_s_tuner,
@@ -372,6 +370,12 @@ static struct video_device maestro_radio = {
372 .vidioc_s_ctrl = vidioc_s_ctrl, 370 .vidioc_s_ctrl = vidioc_s_ctrl,
373}; 371};
374 372
373static struct video_device maestro_radio = {
374 .name = "Maestro radio",
375 .fops = &maestro_fops,
376 .ioctl_ops = &maestro_ioctl_ops,
377};
378
375static int __devinit maestro_probe(struct pci_dev *pdev, 379static int __devinit maestro_probe(struct pci_dev *pdev,
376 const struct pci_device_id *ent) 380 const struct pci_device_id *ent)
377{ 381{
diff --git a/drivers/media/radio/radio-maxiradio.c b/drivers/media/radio/radio-maxiradio.c
index 0133ecf3e040..43c75497dc49 100644
--- a/drivers/media/radio/radio-maxiradio.c
+++ b/drivers/media/radio/radio-maxiradio.c
@@ -44,6 +44,7 @@
44#include <linux/pci.h> 44#include <linux/pci.h>
45#include <linux/videodev2.h> 45#include <linux/videodev2.h>
46#include <media/v4l2-common.h> 46#include <media/v4l2-common.h>
47#include <media/v4l2-ioctl.h>
47 48
48#define DRIVER_VERSION "0.77" 49#define DRIVER_VERSION "0.77"
49 50
@@ -373,13 +374,7 @@ static int vidioc_s_ctrl (struct file *file, void *priv,
373 return -EINVAL; 374 return -EINVAL;
374} 375}
375 376
376static struct video_device maxiradio_radio = 377static const struct v4l2_ioctl_ops maxiradio_ioctl_ops = {
377{
378 .owner = THIS_MODULE,
379 .name = "Maxi Radio FM2000 radio",
380 .type = VID_TYPE_TUNER,
381 .fops = &maxiradio_fops,
382
383 .vidioc_querycap = vidioc_querycap, 378 .vidioc_querycap = vidioc_querycap,
384 .vidioc_g_tuner = vidioc_g_tuner, 379 .vidioc_g_tuner = vidioc_g_tuner,
385 .vidioc_s_tuner = vidioc_s_tuner, 380 .vidioc_s_tuner = vidioc_s_tuner,
@@ -394,6 +389,12 @@ static struct video_device maxiradio_radio =
394 .vidioc_s_ctrl = vidioc_s_ctrl, 389 .vidioc_s_ctrl = vidioc_s_ctrl,
395}; 390};
396 391
392static struct video_device maxiradio_radio = {
393 .name = "Maxi Radio FM2000 radio",
394 .fops = &maxiradio_fops,
395 .ioctl_ops = &maxiradio_ioctl_ops,
396};
397
397static int __devinit maxiradio_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) 398static int __devinit maxiradio_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
398{ 399{
399 if(!request_region(pci_resource_start(pdev, 0), 400 if(!request_region(pci_resource_start(pdev, 0),
diff --git a/drivers/media/radio/radio-rtrack2.c b/drivers/media/radio/radio-rtrack2.c
index 070802103dc3..e2dde0807268 100644
--- a/drivers/media/radio/radio-rtrack2.c
+++ b/drivers/media/radio/radio-rtrack2.c
@@ -17,6 +17,7 @@
17#include <asm/uaccess.h> /* copy to/from user */ 17#include <asm/uaccess.h> /* copy to/from user */
18#include <linux/videodev2.h> /* kernel radio structs */ 18#include <linux/videodev2.h> /* kernel radio structs */
19#include <media/v4l2-common.h> 19#include <media/v4l2-common.h>
20#include <media/v4l2-ioctl.h>
20#include <linux/spinlock.h> 21#include <linux/spinlock.h>
21 22
22#include <linux/version.h> /* for KERNEL_VERSION MACRO */ 23#include <linux/version.h> /* for KERNEL_VERSION MACRO */
@@ -294,12 +295,7 @@ static const struct file_operations rtrack2_fops = {
294 .llseek = no_llseek, 295 .llseek = no_llseek,
295}; 296};
296 297
297static struct video_device rtrack2_radio= 298static const struct v4l2_ioctl_ops rtrack2_ioctl_ops = {
298{
299 .owner = THIS_MODULE,
300 .name = "RadioTrack II radio",
301 .type = VID_TYPE_TUNER,
302 .fops = &rtrack2_fops,
303 .vidioc_querycap = vidioc_querycap, 299 .vidioc_querycap = vidioc_querycap,
304 .vidioc_g_tuner = vidioc_g_tuner, 300 .vidioc_g_tuner = vidioc_g_tuner,
305 .vidioc_s_tuner = vidioc_s_tuner, 301 .vidioc_s_tuner = vidioc_s_tuner,
@@ -314,6 +310,12 @@ static struct video_device rtrack2_radio=
314 .vidioc_s_input = vidioc_s_input, 310 .vidioc_s_input = vidioc_s_input,
315}; 311};
316 312
313static struct video_device rtrack2_radio = {
314 .name = "RadioTrack II radio",
315 .fops = &rtrack2_fops,
316 .ioctl_ops = &rtrack2_ioctl_ops,
317};
318
317static int __init rtrack2_init(void) 319static int __init rtrack2_init(void)
318{ 320{
319 if(io==-1) 321 if(io==-1)
diff --git a/drivers/media/radio/radio-sf16fmi.c b/drivers/media/radio/radio-sf16fmi.c
index 66e052fd3909..bb5d92f104af 100644
--- a/drivers/media/radio/radio-sf16fmi.c
+++ b/drivers/media/radio/radio-sf16fmi.c
@@ -24,6 +24,7 @@
24#include <linux/delay.h> /* udelay */ 24#include <linux/delay.h> /* udelay */
25#include <linux/videodev2.h> /* kernel radio structs */ 25#include <linux/videodev2.h> /* kernel radio structs */
26#include <media/v4l2-common.h> 26#include <media/v4l2-common.h>
27#include <media/v4l2-ioctl.h>
27#include <linux/isapnp.h> 28#include <linux/isapnp.h>
28#include <asm/io.h> /* outb, outb_p */ 29#include <asm/io.h> /* outb, outb_p */
29#include <asm/uaccess.h> /* copy to/from user */ 30#include <asm/uaccess.h> /* copy to/from user */
@@ -294,12 +295,7 @@ static const struct file_operations fmi_fops = {
294 .llseek = no_llseek, 295 .llseek = no_llseek,
295}; 296};
296 297
297static struct video_device fmi_radio= 298static const struct v4l2_ioctl_ops fmi_ioctl_ops = {
298{
299 .owner = THIS_MODULE,
300 .name = "SF16FMx radio",
301 .type = VID_TYPE_TUNER,
302 .fops = &fmi_fops,
303 .vidioc_querycap = vidioc_querycap, 299 .vidioc_querycap = vidioc_querycap,
304 .vidioc_g_tuner = vidioc_g_tuner, 300 .vidioc_g_tuner = vidioc_g_tuner,
305 .vidioc_s_tuner = vidioc_s_tuner, 301 .vidioc_s_tuner = vidioc_s_tuner,
@@ -314,6 +310,12 @@ static struct video_device fmi_radio=
314 .vidioc_s_ctrl = vidioc_s_ctrl, 310 .vidioc_s_ctrl = vidioc_s_ctrl,
315}; 311};
316 312
313static struct video_device fmi_radio = {
314 .name = "SF16FMx radio",
315 .fops = &fmi_fops,
316 .ioctl_ops = &fmi_ioctl_ops,
317};
318
317/* ladis: this is my card. does any other types exist? */ 319/* ladis: this is my card. does any other types exist? */
318static struct isapnp_device_id id_table[] __devinitdata = { 320static struct isapnp_device_id id_table[] __devinitdata = {
319 { ISAPNP_ANY_ID, ISAPNP_ANY_ID, 321 { ISAPNP_ANY_ID, ISAPNP_ANY_ID,
diff --git a/drivers/media/radio/radio-sf16fmr2.c b/drivers/media/radio/radio-sf16fmr2.c
index b0ccf7cb5952..6290553d24be 100644
--- a/drivers/media/radio/radio-sf16fmr2.c
+++ b/drivers/media/radio/radio-sf16fmr2.c
@@ -22,6 +22,7 @@
22#include <asm/uaccess.h> /* copy to/from user */ 22#include <asm/uaccess.h> /* copy to/from user */
23#include <linux/videodev2.h> /* kernel radio structs */ 23#include <linux/videodev2.h> /* kernel radio structs */
24#include <media/v4l2-common.h> 24#include <media/v4l2-common.h>
25#include <media/v4l2-ioctl.h>
25#include <linux/mutex.h> 26#include <linux/mutex.h>
26 27
27static struct mutex lock; 28static struct mutex lock;
@@ -410,12 +411,7 @@ static const struct file_operations fmr2_fops = {
410 .llseek = no_llseek, 411 .llseek = no_llseek,
411}; 412};
412 413
413static struct video_device fmr2_radio= 414static const struct v4l2_ioctl_ops fmr2_ioctl_ops = {
414{
415 .owner = THIS_MODULE,
416 .name = "SF16FMR2 radio",
417 . type = VID_TYPE_TUNER,
418 .fops = &fmr2_fops,
419 .vidioc_querycap = vidioc_querycap, 415 .vidioc_querycap = vidioc_querycap,
420 .vidioc_g_tuner = vidioc_g_tuner, 416 .vidioc_g_tuner = vidioc_g_tuner,
421 .vidioc_s_tuner = vidioc_s_tuner, 417 .vidioc_s_tuner = vidioc_s_tuner,
@@ -430,6 +426,12 @@ static struct video_device fmr2_radio=
430 .vidioc_s_ctrl = vidioc_s_ctrl, 426 .vidioc_s_ctrl = vidioc_s_ctrl,
431}; 427};
432 428
429static struct video_device fmr2_radio = {
430 .name = "SF16FMR2 radio",
431 .fops = &fmr2_fops,
432 .ioctl_ops = &fmr2_ioctl_ops,
433};
434
433static int __init fmr2_init(void) 435static int __init fmr2_init(void)
434{ 436{
435 fmr2_unit.port = io; 437 fmr2_unit.port = io;
diff --git a/drivers/media/radio/radio-si470x.c b/drivers/media/radio/radio-si470x.c
index dc93a882b385..a4984ff87c9c 100644
--- a/drivers/media/radio/radio-si470x.c
+++ b/drivers/media/radio/radio-si470x.c
@@ -133,6 +133,7 @@
133#include <linux/videodev2.h> 133#include <linux/videodev2.h>
134#include <linux/mutex.h> 134#include <linux/mutex.h>
135#include <media/v4l2-common.h> 135#include <media/v4l2-common.h>
136#include <media/v4l2-ioctl.h>
136#include <media/rds.h> 137#include <media/rds.h>
137#include <asm/unaligned.h> 138#include <asm/unaligned.h>
138 139
@@ -1585,15 +1586,7 @@ done:
1585 return retval; 1586 return retval;
1586} 1587}
1587 1588
1588 1589static const struct v4l2_ioctl_ops si470x_ioctl_ops = {
1589/*
1590 * si470x_viddev_tamples - video device interface
1591 */
1592static struct video_device si470x_viddev_template = {
1593 .fops = &si470x_fops,
1594 .name = DRIVER_NAME,
1595 .type = VID_TYPE_TUNER,
1596 .release = video_device_release,
1597 .vidioc_querycap = si470x_vidioc_querycap, 1590 .vidioc_querycap = si470x_vidioc_querycap,
1598 .vidioc_g_input = si470x_vidioc_g_input, 1591 .vidioc_g_input = si470x_vidioc_g_input,
1599 .vidioc_s_input = si470x_vidioc_s_input, 1592 .vidioc_s_input = si470x_vidioc_s_input,
@@ -1607,7 +1600,16 @@ static struct video_device si470x_viddev_template = {
1607 .vidioc_g_frequency = si470x_vidioc_g_frequency, 1600 .vidioc_g_frequency = si470x_vidioc_g_frequency,
1608 .vidioc_s_frequency = si470x_vidioc_s_frequency, 1601 .vidioc_s_frequency = si470x_vidioc_s_frequency,
1609 .vidioc_s_hw_freq_seek = si470x_vidioc_s_hw_freq_seek, 1602 .vidioc_s_hw_freq_seek = si470x_vidioc_s_hw_freq_seek,
1610 .owner = THIS_MODULE, 1603};
1604
1605/*
1606 * si470x_viddev_tamples - video device interface
1607 */
1608static struct video_device si470x_viddev_template = {
1609 .fops = &si470x_fops,
1610 .ioctl_ops = &si470x_ioctl_ops,
1611 .name = DRIVER_NAME,
1612 .release = video_device_release,
1611}; 1613};
1612 1614
1613 1615
diff --git a/drivers/media/radio/radio-terratec.c b/drivers/media/radio/radio-terratec.c
index acc32080e9bd..cefa44fc5aed 100644
--- a/drivers/media/radio/radio-terratec.c
+++ b/drivers/media/radio/radio-terratec.c
@@ -32,6 +32,7 @@
32#include <asm/uaccess.h> /* copy to/from user */ 32#include <asm/uaccess.h> /* copy to/from user */
33#include <linux/videodev2.h> /* kernel radio structs */ 33#include <linux/videodev2.h> /* kernel radio structs */
34#include <media/v4l2-common.h> 34#include <media/v4l2-common.h>
35#include <media/v4l2-ioctl.h>
35#include <linux/spinlock.h> 36#include <linux/spinlock.h>
36 37
37#include <linux/version.h> /* for KERNEL_VERSION MACRO */ 38#include <linux/version.h> /* for KERNEL_VERSION MACRO */
@@ -366,12 +367,7 @@ static const struct file_operations terratec_fops = {
366 .llseek = no_llseek, 367 .llseek = no_llseek,
367}; 368};
368 369
369static struct video_device terratec_radio= 370static const struct v4l2_ioctl_ops terratec_ioctl_ops = {
370{
371 .owner = THIS_MODULE,
372 .name = "TerraTec ActiveRadio",
373 .type = VID_TYPE_TUNER,
374 .fops = &terratec_fops,
375 .vidioc_querycap = vidioc_querycap, 371 .vidioc_querycap = vidioc_querycap,
376 .vidioc_g_tuner = vidioc_g_tuner, 372 .vidioc_g_tuner = vidioc_g_tuner,
377 .vidioc_s_tuner = vidioc_s_tuner, 373 .vidioc_s_tuner = vidioc_s_tuner,
@@ -386,6 +382,12 @@ static struct video_device terratec_radio=
386 .vidioc_s_input = vidioc_s_input, 382 .vidioc_s_input = vidioc_s_input,
387}; 383};
388 384
385static struct video_device terratec_radio = {
386 .name = "TerraTec ActiveRadio",
387 .fops = &terratec_fops,
388 .ioctl_ops = &terratec_ioctl_ops,
389};
390
389static int __init terratec_init(void) 391static int __init terratec_init(void)
390{ 392{
391 if(io==-1) 393 if(io==-1)
diff --git a/drivers/media/radio/radio-trust.c b/drivers/media/radio/radio-trust.c
index 4ebdfbadeb9c..d70172d23edb 100644
--- a/drivers/media/radio/radio-trust.c
+++ b/drivers/media/radio/radio-trust.c
@@ -23,6 +23,7 @@
23#include <asm/uaccess.h> 23#include <asm/uaccess.h>
24#include <linux/videodev2.h> 24#include <linux/videodev2.h>
25#include <media/v4l2-common.h> 25#include <media/v4l2-common.h>
26#include <media/v4l2-ioctl.h>
26 27
27#include <linux/version.h> /* for KERNEL_VERSION MACRO */ 28#include <linux/version.h> /* for KERNEL_VERSION MACRO */
28#define RADIO_VERSION KERNEL_VERSION(0,0,2) 29#define RADIO_VERSION KERNEL_VERSION(0,0,2)
@@ -346,12 +347,7 @@ static const struct file_operations trust_fops = {
346 .llseek = no_llseek, 347 .llseek = no_llseek,
347}; 348};
348 349
349static struct video_device trust_radio= 350static const struct v4l2_ioctl_ops trust_ioctl_ops = {
350{
351 .owner = THIS_MODULE,
352 .name = "Trust FM Radio",
353 .type = VID_TYPE_TUNER,
354 .fops = &trust_fops,
355 .vidioc_querycap = vidioc_querycap, 351 .vidioc_querycap = vidioc_querycap,
356 .vidioc_g_tuner = vidioc_g_tuner, 352 .vidioc_g_tuner = vidioc_g_tuner,
357 .vidioc_s_tuner = vidioc_s_tuner, 353 .vidioc_s_tuner = vidioc_s_tuner,
@@ -366,6 +362,12 @@ static struct video_device trust_radio=
366 .vidioc_s_input = vidioc_s_input, 362 .vidioc_s_input = vidioc_s_input,
367}; 363};
368 364
365static struct video_device trust_radio = {
366 .name = "Trust FM Radio",
367 .fops = &trust_fops,
368 .ioctl_ops = &trust_ioctl_ops,
369};
370
369static int __init trust_init(void) 371static int __init trust_init(void)
370{ 372{
371 if(io == -1) { 373 if(io == -1) {
diff --git a/drivers/media/radio/radio-typhoon.c b/drivers/media/radio/radio-typhoon.c
index 18f2abd7e255..f8d62cfea774 100644
--- a/drivers/media/radio/radio-typhoon.c
+++ b/drivers/media/radio/radio-typhoon.c
@@ -40,6 +40,7 @@
40#include <asm/uaccess.h> /* copy to/from user */ 40#include <asm/uaccess.h> /* copy to/from user */
41#include <linux/videodev2.h> /* kernel radio structs */ 41#include <linux/videodev2.h> /* kernel radio structs */
42#include <media/v4l2-common.h> 42#include <media/v4l2-common.h>
43#include <media/v4l2-ioctl.h>
43 44
44#include <linux/version.h> /* for KERNEL_VERSION MACRO */ 45#include <linux/version.h> /* for KERNEL_VERSION MACRO */
45#define RADIO_VERSION KERNEL_VERSION(0,1,1) 46#define RADIO_VERSION KERNEL_VERSION(0,1,1)
@@ -344,12 +345,7 @@ static const struct file_operations typhoon_fops = {
344 .llseek = no_llseek, 345 .llseek = no_llseek,
345}; 346};
346 347
347static struct video_device typhoon_radio = 348static const struct v4l2_ioctl_ops typhoon_ioctl_ops = {
348{
349 .owner = THIS_MODULE,
350 .name = "Typhoon Radio",
351 .type = VID_TYPE_TUNER,
352 .fops = &typhoon_fops,
353 .vidioc_querycap = vidioc_querycap, 349 .vidioc_querycap = vidioc_querycap,
354 .vidioc_g_tuner = vidioc_g_tuner, 350 .vidioc_g_tuner = vidioc_g_tuner,
355 .vidioc_s_tuner = vidioc_s_tuner, 351 .vidioc_s_tuner = vidioc_s_tuner,
@@ -364,6 +360,12 @@ static struct video_device typhoon_radio =
364 .vidioc_s_ctrl = vidioc_s_ctrl, 360 .vidioc_s_ctrl = vidioc_s_ctrl,
365}; 361};
366 362
363static struct video_device typhoon_radio = {
364 .name = "Typhoon Radio",
365 .fops = &typhoon_fops,
366 .ioctl_ops = &typhoon_ioctl_ops,
367};
368
367#ifdef CONFIG_RADIO_TYPHOON_PROC_FS 369#ifdef CONFIG_RADIO_TYPHOON_PROC_FS
368 370
369static int typhoon_proc_show(struct seq_file *m, void *v) 371static int typhoon_proc_show(struct seq_file *m, void *v)
diff --git a/drivers/media/radio/radio-zoltrix.c b/drivers/media/radio/radio-zoltrix.c
index 43773c56c62f..9f17a332fa11 100644
--- a/drivers/media/radio/radio-zoltrix.c
+++ b/drivers/media/radio/radio-zoltrix.c
@@ -37,6 +37,7 @@
37#include <asm/uaccess.h> /* copy to/from user */ 37#include <asm/uaccess.h> /* copy to/from user */
38#include <linux/videodev2.h> /* kernel radio structs */ 38#include <linux/videodev2.h> /* kernel radio structs */
39#include <media/v4l2-common.h> 39#include <media/v4l2-common.h>
40#include <media/v4l2-ioctl.h>
40 41
41#include <linux/version.h> /* for KERNEL_VERSION MACRO */ 42#include <linux/version.h> /* for KERNEL_VERSION MACRO */
42#define RADIO_VERSION KERNEL_VERSION(0,0,2) 43#define RADIO_VERSION KERNEL_VERSION(0,0,2)
@@ -407,12 +408,7 @@ static const struct file_operations zoltrix_fops =
407 .llseek = no_llseek, 408 .llseek = no_llseek,
408}; 409};
409 410
410static struct video_device zoltrix_radio = 411static const struct v4l2_ioctl_ops zoltrix_ioctl_ops = {
411{
412 .owner = THIS_MODULE,
413 .name = "Zoltrix Radio Plus",
414 .type = VID_TYPE_TUNER,
415 .fops = &zoltrix_fops,
416 .vidioc_querycap = vidioc_querycap, 412 .vidioc_querycap = vidioc_querycap,
417 .vidioc_g_tuner = vidioc_g_tuner, 413 .vidioc_g_tuner = vidioc_g_tuner,
418 .vidioc_s_tuner = vidioc_s_tuner, 414 .vidioc_s_tuner = vidioc_s_tuner,
@@ -427,6 +423,12 @@ static struct video_device zoltrix_radio =
427 .vidioc_s_ctrl = vidioc_s_ctrl, 423 .vidioc_s_ctrl = vidioc_s_ctrl,
428}; 424};
429 425
426static struct video_device zoltrix_radio = {
427 .name = "Zoltrix Radio Plus",
428 .fops = &zoltrix_fops,
429 .ioctl_ops = &zoltrix_ioctl_ops,
430};
431
430static int __init zoltrix_init(void) 432static int __init zoltrix_init(void)
431{ 433{
432 if (io == -1) { 434 if (io == -1) {
diff --git a/drivers/media/video/Kconfig b/drivers/media/video/Kconfig
index f606d2951fde..d4a6e56a7135 100644
--- a/drivers/media/video/Kconfig
+++ b/drivers/media/video/Kconfig
@@ -487,17 +487,6 @@ config VIDEO_PMS
487 To compile this driver as a module, choose M here: the 487 To compile this driver as a module, choose M here: the
488 module will be called pms. 488 module will be called pms.
489 489
490config VIDEO_PLANB
491 tristate "PlanB Video-In on PowerMac"
492 depends on PPC_PMAC && VIDEO_V4L1 && BROKEN
493 help
494 PlanB is the V4L driver for the PowerMac 7x00/8x00 series video
495 input hardware. If you want to experiment with this, say Y.
496 Otherwise, or if you don't understand a word, say N. See
497 <http://www.cpu.lu/~mlan/linux/dev/planb.html> for more info.
498
499 Saying M will compile this driver as a module (planb).
500
501config VIDEO_BWQCAM 490config VIDEO_BWQCAM
502 tristate "Quickcam BW Video For Linux" 491 tristate "Quickcam BW Video For Linux"
503 depends on PARPORT && VIDEO_V4L1 492 depends on PARPORT && VIDEO_V4L1
@@ -806,13 +795,7 @@ menuconfig V4L_USB_DRIVERS
806 795
807if V4L_USB_DRIVERS && USB 796if V4L_USB_DRIVERS && USB
808 797
809config USB_VIDEO_CLASS 798source "drivers/media/video/uvc/Kconfig"
810 tristate "USB Video Class (UVC)"
811 ---help---
812 Support for the USB Video Class (UVC). Currently only video
813 input devices, such as webcams, are supported.
814
815 For more information see: <http://linux-uvc.berlios.de/>
816 799
817source "drivers/media/video/gspca/Kconfig" 800source "drivers/media/video/gspca/Kconfig"
818 801
diff --git a/drivers/media/video/Makefile b/drivers/media/video/Makefile
index 45d5db5abb1e..bbc6f8b82297 100644
--- a/drivers/media/video/Makefile
+++ b/drivers/media/video/Makefile
@@ -10,6 +10,8 @@ msp3400-objs := msp3400-driver.o msp3400-kthreads.o
10 10
11stkwebcam-objs := stk-webcam.o stk-sensor.o 11stkwebcam-objs := stk-webcam.o stk-sensor.o
12 12
13videodev-objs := v4l2-dev.o v4l2-ioctl.o
14
13obj-$(CONFIG_VIDEO_DEV) += videodev.o compat_ioctl32.o v4l2-int-device.o 15obj-$(CONFIG_VIDEO_DEV) += videodev.o compat_ioctl32.o v4l2-int-device.o
14 16
15obj-$(CONFIG_VIDEO_V4L2_COMMON) += v4l2-common.o 17obj-$(CONFIG_VIDEO_V4L2_COMMON) += v4l2-common.o
@@ -55,7 +57,6 @@ obj-$(CONFIG_VIDEO_ZORAN_DC30) += zr36050.o zr36016.o
55obj-$(CONFIG_VIDEO_ZORAN_ZR36060) += zr36060.o 57obj-$(CONFIG_VIDEO_ZORAN_ZR36060) += zr36060.o
56 58
57obj-$(CONFIG_VIDEO_PMS) += pms.o 59obj-$(CONFIG_VIDEO_PMS) += pms.o
58obj-$(CONFIG_VIDEO_PLANB) += planb.o
59obj-$(CONFIG_VIDEO_VINO) += vino.o indycam.o 60obj-$(CONFIG_VIDEO_VINO) += vino.o indycam.o
60obj-$(CONFIG_VIDEO_STRADIS) += stradis.o 61obj-$(CONFIG_VIDEO_STRADIS) += stradis.o
61obj-$(CONFIG_VIDEO_CPIA) += cpia.o 62obj-$(CONFIG_VIDEO_CPIA) += cpia.o
diff --git a/drivers/media/video/arv.c b/drivers/media/video/arv.c
index 8c7d1958856b..56ebfd5ef6fa 100644
--- a/drivers/media/video/arv.c
+++ b/drivers/media/video/arv.c
@@ -754,7 +754,6 @@ static const struct file_operations ar_fops = {
754}; 754};
755 755
756static struct video_device ar_template = { 756static struct video_device ar_template = {
757 .owner = THIS_MODULE,
758 .name = "Colour AR VGA", 757 .name = "Colour AR VGA",
759 .type = VID_TYPE_CAPTURE, 758 .type = VID_TYPE_CAPTURE,
760 .fops = &ar_fops, 759 .fops = &ar_fops,
diff --git a/drivers/media/video/au0828/Kconfig b/drivers/media/video/au0828/Kconfig
index 52b2491581a8..ed9a50f189fc 100644
--- a/drivers/media/video/au0828/Kconfig
+++ b/drivers/media/video/au0828/Kconfig
@@ -6,6 +6,7 @@ config VIDEO_AU0828
6 select VIDEO_TVEEPROM 6 select VIDEO_TVEEPROM
7 select DVB_AU8522 if !DVB_FE_CUSTOMIZE 7 select DVB_AU8522 if !DVB_FE_CUSTOMIZE
8 select MEDIA_TUNER_XC5000 if !DVB_FE_CUSTOMIZE 8 select MEDIA_TUNER_XC5000 if !DVB_FE_CUSTOMIZE
9 select MEDIA_TUNER_MXL5007T if !DVB_FE_CUSTOMIZE
9 ---help--- 10 ---help---
10 This is a video4linux driver for Auvitek's USB device. 11 This is a video4linux driver for Auvitek's USB device.
11 12
diff --git a/drivers/media/video/au0828/au0828-cards.c b/drivers/media/video/au0828/au0828-cards.c
index 898e12395e7c..443e59009762 100644
--- a/drivers/media/video/au0828/au0828-cards.c
+++ b/drivers/media/video/au0828/au0828-cards.c
@@ -32,6 +32,9 @@ struct au0828_board au0828_boards[] = {
32 [AU0828_BOARD_HAUPPAUGE_HVR950Q] = { 32 [AU0828_BOARD_HAUPPAUGE_HVR950Q] = {
33 .name = "Hauppauge HVR950Q", 33 .name = "Hauppauge HVR950Q",
34 }, 34 },
35 [AU0828_BOARD_HAUPPAUGE_HVR950Q_MXL] = {
36 .name = "Hauppauge HVR950Q rev xxF8",
37 },
35 [AU0828_BOARD_DVICO_FUSIONHDTV7] = { 38 [AU0828_BOARD_DVICO_FUSIONHDTV7] = {
36 .name = "DViCO FusionHDTV USB", 39 .name = "DViCO FusionHDTV USB",
37 }, 40 },
@@ -49,6 +52,7 @@ int au0828_tuner_callback(void *priv, int command, int arg)
49 switch (dev->board) { 52 switch (dev->board) {
50 case AU0828_BOARD_HAUPPAUGE_HVR850: 53 case AU0828_BOARD_HAUPPAUGE_HVR850:
51 case AU0828_BOARD_HAUPPAUGE_HVR950Q: 54 case AU0828_BOARD_HAUPPAUGE_HVR950Q:
55 case AU0828_BOARD_HAUPPAUGE_HVR950Q_MXL:
52 case AU0828_BOARD_DVICO_FUSIONHDTV7: 56 case AU0828_BOARD_DVICO_FUSIONHDTV7:
53 if (command == 0) { 57 if (command == 0) {
54 /* Tuner Reset Command from xc5000 */ 58 /* Tuner Reset Command from xc5000 */
@@ -110,6 +114,7 @@ void au0828_card_setup(struct au0828_dev *dev)
110 switch (dev->board) { 114 switch (dev->board) {
111 case AU0828_BOARD_HAUPPAUGE_HVR850: 115 case AU0828_BOARD_HAUPPAUGE_HVR850:
112 case AU0828_BOARD_HAUPPAUGE_HVR950Q: 116 case AU0828_BOARD_HAUPPAUGE_HVR950Q:
117 case AU0828_BOARD_HAUPPAUGE_HVR950Q_MXL:
113 if (dev->i2c_rc == 0) 118 if (dev->i2c_rc == 0)
114 hauppauge_eeprom(dev, eeprom+0xa0); 119 hauppauge_eeprom(dev, eeprom+0xa0);
115 break; 120 break;
@@ -128,6 +133,7 @@ void au0828_gpio_setup(struct au0828_dev *dev)
128 switch (dev->board) { 133 switch (dev->board) {
129 case AU0828_BOARD_HAUPPAUGE_HVR850: 134 case AU0828_BOARD_HAUPPAUGE_HVR850:
130 case AU0828_BOARD_HAUPPAUGE_HVR950Q: 135 case AU0828_BOARD_HAUPPAUGE_HVR950Q:
136 case AU0828_BOARD_HAUPPAUGE_HVR950Q_MXL:
131 /* GPIO's 137 /* GPIO's
132 * 4 - CS5340 138 * 4 - CS5340
133 * 5 - AU8522 Demodulator 139 * 5 - AU8522 Demodulator
@@ -193,6 +199,12 @@ struct usb_device_id au0828_usb_id_table [] = {
193 .driver_info = AU0828_BOARD_HAUPPAUGE_HVR950Q }, 199 .driver_info = AU0828_BOARD_HAUPPAUGE_HVR950Q },
194 { USB_DEVICE(0x0fd9, 0x0008), 200 { USB_DEVICE(0x0fd9, 0x0008),
195 .driver_info = AU0828_BOARD_HAUPPAUGE_HVR950Q }, 201 .driver_info = AU0828_BOARD_HAUPPAUGE_HVR950Q },
202 { USB_DEVICE(0x2040, 0x7201),
203 .driver_info = AU0828_BOARD_HAUPPAUGE_HVR950Q_MXL },
204 { USB_DEVICE(0x2040, 0x7211),
205 .driver_info = AU0828_BOARD_HAUPPAUGE_HVR950Q_MXL },
206 { USB_DEVICE(0x2040, 0x7281),
207 .driver_info = AU0828_BOARD_HAUPPAUGE_HVR950Q_MXL },
196 { }, 208 { },
197}; 209};
198 210
diff --git a/drivers/media/video/au0828/au0828-cards.h b/drivers/media/video/au0828/au0828-cards.h
index e26f54a961d0..c37f5fd0fa80 100644
--- a/drivers/media/video/au0828/au0828-cards.h
+++ b/drivers/media/video/au0828/au0828-cards.h
@@ -23,3 +23,4 @@
23#define AU0828_BOARD_HAUPPAUGE_HVR950Q 1 23#define AU0828_BOARD_HAUPPAUGE_HVR950Q 1
24#define AU0828_BOARD_HAUPPAUGE_HVR850 2 24#define AU0828_BOARD_HAUPPAUGE_HVR850 2
25#define AU0828_BOARD_DVICO_FUSIONHDTV7 3 25#define AU0828_BOARD_DVICO_FUSIONHDTV7 3
26#define AU0828_BOARD_HAUPPAUGE_HVR950Q_MXL 4
diff --git a/drivers/media/video/au0828/au0828-dvb.c b/drivers/media/video/au0828/au0828-dvb.c
index c6d470590380..584a83a94a2a 100644
--- a/drivers/media/video/au0828/au0828-dvb.c
+++ b/drivers/media/video/au0828/au0828-dvb.c
@@ -28,6 +28,7 @@
28#include "au0828.h" 28#include "au0828.h"
29#include "au8522.h" 29#include "au8522.h"
30#include "xc5000.h" 30#include "xc5000.h"
31#include "mxl5007t.h"
31 32
32DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr); 33DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
33 34
@@ -45,6 +46,11 @@ static struct xc5000_config hauppauge_hvr950q_tunerconfig = {
45 .tuner_callback = au0828_tuner_callback 46 .tuner_callback = au0828_tuner_callback
46}; 47};
47 48
49static struct mxl5007t_config mxl5007t_hvr950q_config = {
50 .xtal_freq_hz = MxL_XTAL_24_MHZ,
51 .if_freq_hz = MxL_IF_6_MHZ,
52};
53
48/*-------------------------------------------------------------------*/ 54/*-------------------------------------------------------------------*/
49static void urb_completion(struct urb *purb) 55static void urb_completion(struct urb *purb)
50{ 56{
@@ -342,6 +348,15 @@ int au0828_dvb_register(struct au0828_dev *dev)
342 &dev->i2c_adap, 348 &dev->i2c_adap,
343 &hauppauge_hvr950q_tunerconfig, dev); 349 &hauppauge_hvr950q_tunerconfig, dev);
344 break; 350 break;
351 case AU0828_BOARD_HAUPPAUGE_HVR950Q_MXL:
352 dvb->frontend = dvb_attach(au8522_attach,
353 &hauppauge_hvr950q_config,
354 &dev->i2c_adap);
355 if (dvb->frontend != NULL)
356 dvb_attach(mxl5007t_attach, dvb->frontend,
357 &dev->i2c_adap, 0x60,
358 &mxl5007t_hvr950q_config);
359 break;
345 default: 360 default:
346 printk(KERN_WARNING "The frontend of your DVB/ATSC card " 361 printk(KERN_WARNING "The frontend of your DVB/ATSC card "
347 "isn't supported yet\n"); 362 "isn't supported yet\n");
diff --git a/drivers/media/video/bt8xx/Kconfig b/drivers/media/video/bt8xx/Kconfig
index 24a34fc1f2b3..ce71e8e7b835 100644
--- a/drivers/media/video/bt8xx/Kconfig
+++ b/drivers/media/video/bt8xx/Kconfig
@@ -1,9 +1,7 @@
1config VIDEO_BT848 1config VIDEO_BT848
2 tristate "BT848 Video For Linux" 2 tristate "BT848 Video For Linux"
3 depends on VIDEO_DEV && PCI && I2C && VIDEO_V4L2 && INPUT 3 depends on VIDEO_DEV && PCI && I2C && VIDEO_V4L2 && INPUT
4 depends on HOTPLUG # due to FW_LOADER
5 select I2C_ALGOBIT 4 select I2C_ALGOBIT
6 select FW_LOADER
7 select VIDEO_BTCX 5 select VIDEO_BTCX
8 select VIDEOBUF_DMA_SG 6 select VIDEOBUF_DMA_SG
9 select VIDEO_IR 7 select VIDEO_IR
diff --git a/drivers/media/video/bt8xx/bttv-driver.c b/drivers/media/video/bt8xx/bttv-driver.c
index 0ea559a7fe59..85bf31ab8789 100644
--- a/drivers/media/video/bt8xx/bttv-driver.c
+++ b/drivers/media/video/bt8xx/bttv-driver.c
@@ -45,6 +45,7 @@
45#include <linux/kdev_t.h> 45#include <linux/kdev_t.h>
46#include "bttvp.h" 46#include "bttvp.h"
47#include <media/v4l2-common.h> 47#include <media/v4l2-common.h>
48#include <media/v4l2-ioctl.h>
48#include <media/tvaudio.h> 49#include <media/tvaudio.h>
49#include <media/msp3400.h> 50#include <media/msp3400.h>
50 51
@@ -163,8 +164,8 @@ MODULE_LICENSE("GPL");
163static ssize_t show_card(struct device *cd, 164static ssize_t show_card(struct device *cd,
164 struct device_attribute *attr, char *buf) 165 struct device_attribute *attr, char *buf)
165{ 166{
166 struct video_device *vfd = container_of(cd, struct video_device, class_dev); 167 struct video_device *vfd = container_of(cd, struct video_device, dev);
167 struct bttv *btv = dev_get_drvdata(vfd->dev); 168 struct bttv *btv = dev_get_drvdata(vfd->parent);
168 return sprintf(buf, "%d\n", btv ? btv->c.type : UNSET); 169 return sprintf(buf, "%d\n", btv ? btv->c.type : UNSET);
169} 170}
170static DEVICE_ATTR(card, S_IRUGO, show_card, NULL); 171static DEVICE_ATTR(card, S_IRUGO, show_card, NULL);
@@ -3357,10 +3358,7 @@ static const struct file_operations bttv_fops =
3357 .poll = bttv_poll, 3358 .poll = bttv_poll,
3358}; 3359};
3359 3360
3360static struct video_device bttv_video_template = 3361static const struct v4l2_ioctl_ops bttv_ioctl_ops = {
3361{
3362 .fops = &bttv_fops,
3363 .minor = -1,
3364 .vidioc_querycap = bttv_querycap, 3362 .vidioc_querycap = bttv_querycap,
3365 .vidioc_enum_fmt_vid_cap = bttv_enum_fmt_vid_cap, 3363 .vidioc_enum_fmt_vid_cap = bttv_enum_fmt_vid_cap,
3366 .vidioc_g_fmt_vid_cap = bttv_g_fmt_vid_cap, 3364 .vidioc_g_fmt_vid_cap = bttv_g_fmt_vid_cap,
@@ -3411,8 +3409,14 @@ static struct video_device bttv_video_template =
3411 .vidioc_g_register = bttv_g_register, 3409 .vidioc_g_register = bttv_g_register,
3412 .vidioc_s_register = bttv_s_register, 3410 .vidioc_s_register = bttv_s_register,
3413#endif 3411#endif
3414 .tvnorms = BTTV_NORMS, 3412};
3415 .current_norm = V4L2_STD_PAL, 3413
3414static struct video_device bttv_video_template = {
3415 .fops = &bttv_fops,
3416 .minor = -1,
3417 .ioctl_ops = &bttv_ioctl_ops,
3418 .tvnorms = BTTV_NORMS,
3419 .current_norm = V4L2_STD_PAL,
3416}; 3420};
3417 3421
3418/* ----------------------------------------------------------------------- */ 3422/* ----------------------------------------------------------------------- */
@@ -3635,10 +3639,7 @@ static const struct file_operations radio_fops =
3635 .poll = radio_poll, 3639 .poll = radio_poll,
3636}; 3640};
3637 3641
3638static struct video_device radio_template = 3642static const struct v4l2_ioctl_ops radio_ioctl_ops = {
3639{
3640 .fops = &radio_fops,
3641 .minor = -1,
3642 .vidioc_querycap = radio_querycap, 3643 .vidioc_querycap = radio_querycap,
3643 .vidioc_g_tuner = radio_g_tuner, 3644 .vidioc_g_tuner = radio_g_tuner,
3644 .vidioc_enum_input = radio_enum_input, 3645 .vidioc_enum_input = radio_enum_input,
@@ -3655,6 +3656,12 @@ static struct video_device radio_template =
3655 .vidioc_s_frequency = bttv_s_frequency, 3656 .vidioc_s_frequency = bttv_s_frequency,
3656}; 3657};
3657 3658
3659static struct video_device radio_template = {
3660 .fops = &radio_fops,
3661 .minor = -1,
3662 .ioctl_ops = &radio_ioctl_ops,
3663};
3664
3658/* ----------------------------------------------------------------------- */ 3665/* ----------------------------------------------------------------------- */
3659/* some debug code */ 3666/* some debug code */
3660 3667
@@ -4175,8 +4182,7 @@ static irqreturn_t bttv_irq(int irq, void *dev_id)
4175 4182
4176static struct video_device *vdev_init(struct bttv *btv, 4183static struct video_device *vdev_init(struct bttv *btv,
4177 const struct video_device *template, 4184 const struct video_device *template,
4178 const char *type_name, 4185 const char *type_name)
4179 const int type)
4180{ 4186{
4181 struct video_device *vfd; 4187 struct video_device *vfd;
4182 4188
@@ -4185,9 +4191,8 @@ static struct video_device *vdev_init(struct bttv *btv,
4185 return NULL; 4191 return NULL;
4186 *vfd = *template; 4192 *vfd = *template;
4187 vfd->minor = -1; 4193 vfd->minor = -1;
4188 vfd->dev = &btv->c.pci->dev; 4194 vfd->parent = &btv->c.pci->dev;
4189 vfd->release = video_device_release; 4195 vfd->release = video_device_release;
4190 vfd->type = type;
4191 vfd->debug = bttv_debug; 4196 vfd->debug = bttv_debug;
4192 snprintf(vfd->name, sizeof(vfd->name), "BT%d%s %s (%s)", 4197 snprintf(vfd->name, sizeof(vfd->name), "BT%d%s %s (%s)",
4193 btv->id, (btv->id==848 && btv->revision==0x12) ? "A" : "", 4198 btv->id, (btv->id==848 && btv->revision==0x12) ? "A" : "",
@@ -4223,20 +4228,11 @@ static void bttv_unregister_video(struct bttv *btv)
4223/* register video4linux devices */ 4228/* register video4linux devices */
4224static int __devinit bttv_register_video(struct bttv *btv) 4229static int __devinit bttv_register_video(struct bttv *btv)
4225{ 4230{
4226 int video_type = VID_TYPE_CAPTURE | 4231 if (no_overlay > 0)
4227 VID_TYPE_TUNER |
4228 VID_TYPE_CLIPPING|
4229 VID_TYPE_SCALES;
4230
4231 if (no_overlay <= 0) {
4232 bttv_video_template.type |= VID_TYPE_OVERLAY;
4233 } else {
4234 printk("bttv: Overlay support disabled.\n"); 4232 printk("bttv: Overlay support disabled.\n");
4235 }
4236 4233
4237 /* video */ 4234 /* video */
4238 btv->video_dev = vdev_init(btv, &bttv_video_template, 4235 btv->video_dev = vdev_init(btv, &bttv_video_template, "video");
4239 "video", video_type);
4240 4236
4241 if (NULL == btv->video_dev) 4237 if (NULL == btv->video_dev)
4242 goto err; 4238 goto err;
@@ -4244,7 +4240,7 @@ static int __devinit bttv_register_video(struct bttv *btv)
4244 goto err; 4240 goto err;
4245 printk(KERN_INFO "bttv%d: registered device video%d\n", 4241 printk(KERN_INFO "bttv%d: registered device video%d\n",
4246 btv->c.nr,btv->video_dev->minor & 0x1f); 4242 btv->c.nr,btv->video_dev->minor & 0x1f);
4247 if (device_create_file(&btv->video_dev->class_dev, 4243 if (device_create_file(&btv->video_dev->dev,
4248 &dev_attr_card)<0) { 4244 &dev_attr_card)<0) {
4249 printk(KERN_ERR "bttv%d: device_create_file 'card' " 4245 printk(KERN_ERR "bttv%d: device_create_file 'card' "
4250 "failed\n", btv->c.nr); 4246 "failed\n", btv->c.nr);
@@ -4252,8 +4248,7 @@ static int __devinit bttv_register_video(struct bttv *btv)
4252 } 4248 }
4253 4249
4254 /* vbi */ 4250 /* vbi */
4255 btv->vbi_dev = vdev_init(btv, &bttv_video_template, 4251 btv->vbi_dev = vdev_init(btv, &bttv_video_template, "vbi");
4256 "vbi", VID_TYPE_TUNER | VID_TYPE_TELETEXT);
4257 4252
4258 if (NULL == btv->vbi_dev) 4253 if (NULL == btv->vbi_dev)
4259 goto err; 4254 goto err;
@@ -4265,8 +4260,7 @@ static int __devinit bttv_register_video(struct bttv *btv)
4265 if (!btv->has_radio) 4260 if (!btv->has_radio)
4266 return 0; 4261 return 0;
4267 /* radio */ 4262 /* radio */
4268 btv->radio_dev = vdev_init(btv, &radio_template, 4263 btv->radio_dev = vdev_init(btv, &radio_template, "radio");
4269 "radio", VID_TYPE_TUNER);
4270 if (NULL == btv->radio_dev) 4264 if (NULL == btv->radio_dev)
4271 goto err; 4265 goto err;
4272 if (video_register_device(btv->radio_dev, VFL_TYPE_RADIO,radio_nr)<0) 4266 if (video_register_device(btv->radio_dev, VFL_TYPE_RADIO,radio_nr)<0)
diff --git a/drivers/media/video/bt8xx/bttv-risc.c b/drivers/media/video/bt8xx/bttv-risc.c
index 0af586876e72..649682aac1ac 100644
--- a/drivers/media/video/bt8xx/bttv-risc.c
+++ b/drivers/media/video/bt8xx/bttv-risc.c
@@ -31,6 +31,7 @@
31#include <linux/interrupt.h> 31#include <linux/interrupt.h>
32#include <asm/page.h> 32#include <asm/page.h>
33#include <asm/pgtable.h> 33#include <asm/pgtable.h>
34#include <media/v4l2-ioctl.h>
34 35
35#include "bttvp.h" 36#include "bttvp.h"
36 37
diff --git a/drivers/media/video/bt8xx/bttv-vbi.c b/drivers/media/video/bt8xx/bttv-vbi.c
index 68f28e5fa040..6819e21a3773 100644
--- a/drivers/media/video/bt8xx/bttv-vbi.c
+++ b/drivers/media/video/bt8xx/bttv-vbi.c
@@ -29,6 +29,7 @@
29#include <linux/kernel.h> 29#include <linux/kernel.h>
30#include <linux/interrupt.h> 30#include <linux/interrupt.h>
31#include <linux/kdev_t.h> 31#include <linux/kdev_t.h>
32#include <media/v4l2-ioctl.h>
32#include <asm/io.h> 33#include <asm/io.h>
33#include "bttvp.h" 34#include "bttvp.h"
34 35
diff --git a/drivers/media/video/bw-qcam.c b/drivers/media/video/bw-qcam.c
index b364adaae78d..d3b3268bace8 100644
--- a/drivers/media/video/bw-qcam.c
+++ b/drivers/media/video/bw-qcam.c
@@ -74,6 +74,7 @@ OTHER DEALINGS IN THE SOFTWARE.
74#include <linux/sched.h> 74#include <linux/sched.h>
75#include <linux/videodev.h> 75#include <linux/videodev.h>
76#include <media/v4l2-common.h> 76#include <media/v4l2-common.h>
77#include <media/v4l2-ioctl.h>
77#include <linux/mutex.h> 78#include <linux/mutex.h>
78#include <asm/uaccess.h> 79#include <asm/uaccess.h>
79 80
@@ -906,9 +907,7 @@ static const struct file_operations qcam_fops = {
906}; 907};
907static struct video_device qcam_template= 908static struct video_device qcam_template=
908{ 909{
909 .owner = THIS_MODULE,
910 .name = "Connectix Quickcam", 910 .name = "Connectix Quickcam",
911 .type = VID_TYPE_CAPTURE,
912 .fops = &qcam_fops, 911 .fops = &qcam_fops,
913}; 912};
914 913
diff --git a/drivers/media/video/c-qcam.c b/drivers/media/video/c-qcam.c
index fe1e67bb1ca8..fe9379b282d3 100644
--- a/drivers/media/video/c-qcam.c
+++ b/drivers/media/video/c-qcam.c
@@ -35,6 +35,7 @@
35#include <linux/sched.h> 35#include <linux/sched.h>
36#include <linux/videodev.h> 36#include <linux/videodev.h>
37#include <media/v4l2-common.h> 37#include <media/v4l2-common.h>
38#include <media/v4l2-ioctl.h>
38#include <linux/mutex.h> 39#include <linux/mutex.h>
39#include <linux/jiffies.h> 40#include <linux/jiffies.h>
40 41
@@ -701,9 +702,7 @@ static const struct file_operations qcam_fops = {
701 702
702static struct video_device qcam_template= 703static struct video_device qcam_template=
703{ 704{
704 .owner = THIS_MODULE,
705 .name = "Colour QuickCam", 705 .name = "Colour QuickCam",
706 .type = VID_TYPE_CAPTURE,
707 .fops = &qcam_fops, 706 .fops = &qcam_fops,
708}; 707};
709 708
diff --git a/drivers/media/video/cafe_ccic.c b/drivers/media/video/cafe_ccic.c
index d99453faaab7..c149b7d712e5 100644
--- a/drivers/media/video/cafe_ccic.c
+++ b/drivers/media/video/cafe_ccic.c
@@ -25,6 +25,7 @@
25#include <linux/spinlock.h> 25#include <linux/spinlock.h>
26#include <linux/videodev2.h> 26#include <linux/videodev2.h>
27#include <media/v4l2-common.h> 27#include <media/v4l2-common.h>
28#include <media/v4l2-ioctl.h>
28#include <media/v4l2-chip-ident.h> 29#include <media/v4l2-chip-ident.h>
29#include <linux/device.h> 30#include <linux/device.h>
30#include <linux/wait.h> 31#include <linux/wait.h>
@@ -1768,17 +1769,7 @@ static const struct file_operations cafe_v4l_fops = {
1768 .llseek = no_llseek, 1769 .llseek = no_llseek,
1769}; 1770};
1770 1771
1771static struct video_device cafe_v4l_template = { 1772static const struct v4l2_ioctl_ops cafe_v4l_ioctl_ops = {
1772 .name = "cafe",
1773 .type = VFL_TYPE_GRABBER,
1774 .type2 = VID_TYPE_CAPTURE,
1775 .minor = -1, /* Get one dynamically */
1776 .tvnorms = V4L2_STD_NTSC_M,
1777 .current_norm = V4L2_STD_NTSC_M, /* make mplayer happy */
1778
1779 .fops = &cafe_v4l_fops,
1780 .release = cafe_v4l_dev_release,
1781
1782 .vidioc_querycap = cafe_vidioc_querycap, 1773 .vidioc_querycap = cafe_vidioc_querycap,
1783 .vidioc_enum_fmt_vid_cap = cafe_vidioc_enum_fmt_vid_cap, 1774 .vidioc_enum_fmt_vid_cap = cafe_vidioc_enum_fmt_vid_cap,
1784 .vidioc_try_fmt_vid_cap = cafe_vidioc_try_fmt_vid_cap, 1775 .vidioc_try_fmt_vid_cap = cafe_vidioc_try_fmt_vid_cap,
@@ -1801,6 +1792,17 @@ static struct video_device cafe_v4l_template = {
1801 .vidioc_s_parm = cafe_vidioc_s_parm, 1792 .vidioc_s_parm = cafe_vidioc_s_parm,
1802}; 1793};
1803 1794
1795static struct video_device cafe_v4l_template = {
1796 .name = "cafe",
1797 .minor = -1, /* Get one dynamically */
1798 .tvnorms = V4L2_STD_NTSC_M,
1799 .current_norm = V4L2_STD_NTSC_M, /* make mplayer happy */
1800
1801 .fops = &cafe_v4l_fops,
1802 .ioctl_ops = &cafe_v4l_ioctl_ops,
1803 .release = cafe_v4l_dev_release,
1804};
1805
1804 1806
1805 1807
1806 1808
@@ -2157,7 +2159,7 @@ static int cafe_pci_probe(struct pci_dev *pdev,
2157 cam->v4ldev = cafe_v4l_template; 2159 cam->v4ldev = cafe_v4l_template;
2158 cam->v4ldev.debug = 0; 2160 cam->v4ldev.debug = 0;
2159// cam->v4ldev.debug = V4L2_DEBUG_IOCTL_ARG; 2161// cam->v4ldev.debug = V4L2_DEBUG_IOCTL_ARG;
2160 cam->v4ldev.dev = &pdev->dev; 2162 cam->v4ldev.parent = &pdev->dev;
2161 ret = video_register_device(&cam->v4ldev, VFL_TYPE_GRABBER, -1); 2163 ret = video_register_device(&cam->v4ldev, VFL_TYPE_GRABBER, -1);
2162 if (ret) 2164 if (ret)
2163 goto out_smbus; 2165 goto out_smbus;
diff --git a/drivers/media/video/compat_ioctl32.c b/drivers/media/video/compat_ioctl32.c
index 54de0cd482e9..bd5d9de5a008 100644
--- a/drivers/media/video/compat_ioctl32.c
+++ b/drivers/media/video/compat_ioctl32.c
@@ -17,7 +17,7 @@
17#include <linux/videodev2.h> 17#include <linux/videodev2.h>
18#include <linux/module.h> 18#include <linux/module.h>
19#include <linux/smp_lock.h> 19#include <linux/smp_lock.h>
20#include <media/v4l2-common.h> 20#include <media/v4l2-ioctl.h>
21 21
22#ifdef CONFIG_COMPAT 22#ifdef CONFIG_COMPAT
23 23
diff --git a/drivers/media/video/cpia.c b/drivers/media/video/cpia.c
index 2a81376ef503..dc8cc6115e2f 100644
--- a/drivers/media/video/cpia.c
+++ b/drivers/media/video/cpia.c
@@ -3799,9 +3799,7 @@ static const struct file_operations cpia_fops = {
3799}; 3799};
3800 3800
3801static struct video_device cpia_template = { 3801static struct video_device cpia_template = {
3802 .owner = THIS_MODULE,
3803 .name = "CPiA Camera", 3802 .name = "CPiA Camera",
3804 .type = VID_TYPE_CAPTURE,
3805 .fops = &cpia_fops, 3803 .fops = &cpia_fops,
3806}; 3804};
3807 3805
diff --git a/drivers/media/video/cpia.h b/drivers/media/video/cpia.h
index 5096058bf579..8f0cfee4b8a1 100644
--- a/drivers/media/video/cpia.h
+++ b/drivers/media/video/cpia.h
@@ -46,6 +46,7 @@
46#include <asm/uaccess.h> 46#include <asm/uaccess.h>
47#include <linux/videodev.h> 47#include <linux/videodev.h>
48#include <media/v4l2-common.h> 48#include <media/v4l2-common.h>
49#include <media/v4l2-ioctl.h>
49#include <linux/list.h> 50#include <linux/list.h>
50#include <linux/mutex.h> 51#include <linux/mutex.h>
51 52
diff --git a/drivers/media/video/cpia2/cpia2_core.c b/drivers/media/video/cpia2/cpia2_core.c
index f2e8b1c82c66..af8b9ec8e358 100644
--- a/drivers/media/video/cpia2/cpia2_core.c
+++ b/drivers/media/video/cpia2/cpia2_core.c
@@ -32,6 +32,7 @@
32#include "cpia2.h" 32#include "cpia2.h"
33 33
34#include <linux/slab.h> 34#include <linux/slab.h>
35#include <linux/mm.h>
35#include <linux/vmalloc.h> 36#include <linux/vmalloc.h>
36#include <linux/firmware.h> 37#include <linux/firmware.h>
37 38
diff --git a/drivers/media/video/cpia2/cpia2_v4l.c b/drivers/media/video/cpia2/cpia2_v4l.c
index 7ce2789fa976..515c8b57a60d 100644
--- a/drivers/media/video/cpia2/cpia2_v4l.c
+++ b/drivers/media/video/cpia2/cpia2_v4l.c
@@ -37,6 +37,7 @@
37#include <linux/sched.h> 37#include <linux/sched.h>
38#include <linux/slab.h> 38#include <linux/slab.h>
39#include <linux/init.h> 39#include <linux/init.h>
40#include <media/v4l2-ioctl.h>
40 41
41#include "cpia2.h" 42#include "cpia2.h"
42#include "cpia2dev.h" 43#include "cpia2dev.h"
@@ -1935,11 +1936,7 @@ static const struct file_operations fops_template = {
1935 1936
1936static struct video_device cpia2_template = { 1937static struct video_device cpia2_template = {
1937 /* I could not find any place for the old .initialize initializer?? */ 1938 /* I could not find any place for the old .initialize initializer?? */
1938 .owner= THIS_MODULE,
1939 .name= "CPiA2 Camera", 1939 .name= "CPiA2 Camera",
1940 .type= VID_TYPE_CAPTURE,
1941 .type2 = V4L2_CAP_VIDEO_CAPTURE |
1942 V4L2_CAP_STREAMING,
1943 .minor= -1, 1940 .minor= -1,
1944 .fops= &fops_template, 1941 .fops= &fops_template,
1945 .release= video_device_release, 1942 .release= video_device_release,
diff --git a/drivers/media/video/cs5345.c b/drivers/media/video/cs5345.c
index 1c3fa3a7470a..61d14d26686f 100644
--- a/drivers/media/video/cs5345.c
+++ b/drivers/media/video/cs5345.c
@@ -111,7 +111,7 @@ static int cs5345_command(struct i2c_client *client, unsigned cmd, void *arg)
111 if (cmd == VIDIOC_DBG_G_REGISTER) 111 if (cmd == VIDIOC_DBG_G_REGISTER)
112 reg->val = cs5345_read(client, reg->reg & 0x1f); 112 reg->val = cs5345_read(client, reg->reg & 0x1f);
113 else 113 else
114 cs5345_write(client, reg->reg & 0x1f, reg->val & 0x1f); 114 cs5345_write(client, reg->reg & 0x1f, reg->val & 0xff);
115 break; 115 break;
116 } 116 }
117#endif 117#endif
diff --git a/drivers/media/video/cs53l32a.c b/drivers/media/video/cs53l32a.c
index 645b339152d3..e30a589c0e18 100644
--- a/drivers/media/video/cs53l32a.c
+++ b/drivers/media/video/cs53l32a.c
@@ -26,7 +26,7 @@
26#include <asm/uaccess.h> 26#include <asm/uaccess.h>
27#include <linux/i2c.h> 27#include <linux/i2c.h>
28#include <linux/i2c-id.h> 28#include <linux/i2c-id.h>
29#include <linux/videodev.h> 29#include <linux/videodev2.h>
30#include <media/v4l2-common.h> 30#include <media/v4l2-common.h>
31#include <media/v4l2-chip-ident.h> 31#include <media/v4l2-chip-ident.h>
32#include <media/v4l2-i2c-drv-legacy.h> 32#include <media/v4l2-i2c-drv-legacy.h>
diff --git a/drivers/media/video/cx18/Kconfig b/drivers/media/video/cx18/Kconfig
index 9aefdc5ea79a..ef48565de7f1 100644
--- a/drivers/media/video/cx18/Kconfig
+++ b/drivers/media/video/cx18/Kconfig
@@ -2,9 +2,7 @@ config VIDEO_CX18
2 tristate "Conexant cx23418 MPEG encoder support" 2 tristate "Conexant cx23418 MPEG encoder support"
3 depends on VIDEO_V4L2 && DVB_CORE && PCI && I2C && EXPERIMENTAL 3 depends on VIDEO_V4L2 && DVB_CORE && PCI && I2C && EXPERIMENTAL
4 depends on INPUT # due to VIDEO_IR 4 depends on INPUT # due to VIDEO_IR
5 depends on HOTPLUG # due to FW_LOADER
6 select I2C_ALGOBIT 5 select I2C_ALGOBIT
7 select FW_LOADER
8 select VIDEO_IR 6 select VIDEO_IR
9 select VIDEO_TUNER 7 select VIDEO_TUNER
10 select VIDEO_TVEEPROM 8 select VIDEO_TVEEPROM
diff --git a/drivers/media/video/cx18/cx18-av-audio.c b/drivers/media/video/cx18/cx18-av-audio.c
index c40a286de1b9..0b55837880a7 100644
--- a/drivers/media/video/cx18/cx18-av-audio.c
+++ b/drivers/media/video/cx18/cx18-av-audio.c
@@ -30,7 +30,6 @@ static int set_audclk_freq(struct cx18 *cx, u32 freq)
30 if (freq != 32000 && freq != 44100 && freq != 48000) 30 if (freq != 32000 && freq != 44100 && freq != 48000)
31 return -EINVAL; 31 return -EINVAL;
32 32
33 /* common for all inputs and rates */
34 /* SA_MCLK_SEL=1, SA_MCLK_DIV=0x10 */ 33 /* SA_MCLK_SEL=1, SA_MCLK_DIV=0x10 */
35 cx18_av_write(cx, 0x127, 0x50); 34 cx18_av_write(cx, 0x127, 0x50);
36 35
@@ -38,15 +37,30 @@ static int set_audclk_freq(struct cx18 *cx, u32 freq)
38 switch (freq) { 37 switch (freq) {
39 case 32000: 38 case 32000:
40 /* VID_PLL and AUX_PLL */ 39 /* VID_PLL and AUX_PLL */
41 cx18_av_write4(cx, 0x108, 0x1006040f); 40 cx18_av_write4(cx, 0x108, 0x1408040f);
42 41
43 /* AUX_PLL_FRAC */ 42 /* AUX_PLL_FRAC */
44 cx18_av_write4(cx, 0x110, 0x01bb39ee); 43 /* 0x8.9504318a * 28,636,363.636 / 0x14 = 32000 * 384 */
44 cx18_av_write4(cx, 0x110, 0x012a0863);
45 45
46 /* src3/4/6_ctl = 0x0801f77f */ 46 /* src3/4/6_ctl */
47 /* 0x1.f77f = (4 * 15734.26) / 32000 */
47 cx18_av_write4(cx, 0x900, 0x0801f77f); 48 cx18_av_write4(cx, 0x900, 0x0801f77f);
48 cx18_av_write4(cx, 0x904, 0x0801f77f); 49 cx18_av_write4(cx, 0x904, 0x0801f77f);
49 cx18_av_write4(cx, 0x90c, 0x0801f77f); 50 cx18_av_write4(cx, 0x90c, 0x0801f77f);
51
52 /* SA_MCLK_SEL=1, SA_MCLK_DIV=0x14 */
53 cx18_av_write(cx, 0x127, 0x54);
54
55 /* AUD_COUNT = 0x2fff = 8 samples * 4 * 384 - 1 */
56 cx18_av_write4(cx, 0x12c, 0x11202fff);
57
58 /*
59 * EN_AV_LOCK = 1
60 * VID_COUNT = 0x0d2ef8 = 107999.000 * 8 =
61 * ((8 samples/32,000) * (13,500,000 * 8) * 4 - 1) * 8
62 */
63 cx18_av_write4(cx, 0x128, 0xa10d2ef8);
50 break; 64 break;
51 65
52 case 44100: 66 case 44100:
@@ -54,12 +68,24 @@ static int set_audclk_freq(struct cx18 *cx, u32 freq)
54 cx18_av_write4(cx, 0x108, 0x1009040f); 68 cx18_av_write4(cx, 0x108, 0x1009040f);
55 69
56 /* AUX_PLL_FRAC */ 70 /* AUX_PLL_FRAC */
57 cx18_av_write4(cx, 0x110, 0x00ec6bd6); 71 /* 0x9.7635e7 * 28,636,363.63 / 0x10 = 44100 * 384 */
72 cx18_av_write4(cx, 0x110, 0x00ec6bce);
58 73
59 /* src3/4/6_ctl = 0x08016d59 */ 74 /* src3/4/6_ctl */
75 /* 0x1.6d59 = (4 * 15734.26) / 44100 */
60 cx18_av_write4(cx, 0x900, 0x08016d59); 76 cx18_av_write4(cx, 0x900, 0x08016d59);
61 cx18_av_write4(cx, 0x904, 0x08016d59); 77 cx18_av_write4(cx, 0x904, 0x08016d59);
62 cx18_av_write4(cx, 0x90c, 0x08016d59); 78 cx18_av_write4(cx, 0x90c, 0x08016d59);
79
80 /* AUD_COUNT = 0x92ff = 49 samples * 2 * 384 - 1 */
81 cx18_av_write4(cx, 0x12c, 0x112092ff);
82
83 /*
84 * EN_AV_LOCK = 1
85 * VID_COUNT = 0x1d4bf8 = 239999.000 * 8 =
86 * ((49 samples/44,100) * (13,500,000 * 8) * 2 - 1) * 8
87 */
88 cx18_av_write4(cx, 0x128, 0xa11d4bf8);
63 break; 89 break;
64 90
65 case 48000: 91 case 48000:
@@ -67,12 +93,24 @@ static int set_audclk_freq(struct cx18 *cx, u32 freq)
67 cx18_av_write4(cx, 0x108, 0x100a040f); 93 cx18_av_write4(cx, 0x108, 0x100a040f);
68 94
69 /* AUX_PLL_FRAC */ 95 /* AUX_PLL_FRAC */
70 cx18_av_write4(cx, 0x110, 0x0098d6e5); 96 /* 0xa.4c6b6ea * 28,636,363.63 / 0x10 = 48000 * 384 */
97 cx18_av_write4(cx, 0x110, 0x0098d6dd);
71 98
72 /* src3/4/6_ctl = 0x08014faa */ 99 /* src3/4/6_ctl */
100 /* 0x1.4faa = (4 * 15734.26) / 48000 */
73 cx18_av_write4(cx, 0x900, 0x08014faa); 101 cx18_av_write4(cx, 0x900, 0x08014faa);
74 cx18_av_write4(cx, 0x904, 0x08014faa); 102 cx18_av_write4(cx, 0x904, 0x08014faa);
75 cx18_av_write4(cx, 0x90c, 0x08014faa); 103 cx18_av_write4(cx, 0x90c, 0x08014faa);
104
105 /* AUD_COUNT = 0x5fff = 4 samples * 16 * 384 - 1 */
106 cx18_av_write4(cx, 0x12c, 0x11205fff);
107
108 /*
109 * EN_AV_LOCK = 1
110 * VID_COUNT = 0x1193f8 = 143999.000 * 8 =
111 * ((4 samples/48,000) * (13,500,000 * 8) * 16 - 1) * 8
112 */
113 cx18_av_write4(cx, 0x128, 0xa11193f8);
76 break; 114 break;
77 } 115 }
78 } else { 116 } else {
@@ -82,18 +120,31 @@ static int set_audclk_freq(struct cx18 *cx, u32 freq)
82 cx18_av_write4(cx, 0x108, 0x1e08040f); 120 cx18_av_write4(cx, 0x108, 0x1e08040f);
83 121
84 /* AUX_PLL_FRAC */ 122 /* AUX_PLL_FRAC */
85 cx18_av_write4(cx, 0x110, 0x012a0869); 123 /* 0x8.9504318 * 28,636,363.63 / 0x1e = 32000 * 256 */
124 cx18_av_write4(cx, 0x110, 0x012a0863);
86 125
87 /* src1_ctl = 0x08010000 */ 126 /* src1_ctl */
127 /* 0x1.0000 = 32000/32000 */
88 cx18_av_write4(cx, 0x8f8, 0x08010000); 128 cx18_av_write4(cx, 0x8f8, 0x08010000);
89 129
90 /* src3/4/6_ctl = 0x08020000 */ 130 /* src3/4/6_ctl */
131 /* 0x2.0000 = 2 * (32000/32000) */
91 cx18_av_write4(cx, 0x900, 0x08020000); 132 cx18_av_write4(cx, 0x900, 0x08020000);
92 cx18_av_write4(cx, 0x904, 0x08020000); 133 cx18_av_write4(cx, 0x904, 0x08020000);
93 cx18_av_write4(cx, 0x90c, 0x08020000); 134 cx18_av_write4(cx, 0x90c, 0x08020000);
94 135
95 /* SA_MCLK_SEL=1, SA_MCLK_DIV=0x14 */ 136 /* SA_MCLK_SEL=1, SA_MCLK_DIV=0x14 */
96 cx18_av_write(cx, 0x127, 0x54); 137 cx18_av_write(cx, 0x127, 0x54);
138
139 /* AUD_COUNT = 0x1fff = 8 samples * 4 * 256 - 1 */
140 cx18_av_write4(cx, 0x12c, 0x11201fff);
141
142 /*
143 * EN_AV_LOCK = 1
144 * VID_COUNT = 0x0d2ef8 = 107999.000 * 8 =
145 * ((8 samples/32,000) * (13,500,000 * 8) * 4 - 1) * 8
146 */
147 cx18_av_write4(cx, 0x128, 0xa10d2ef8);
97 break; 148 break;
98 149
99 case 44100: 150 case 44100:
@@ -101,15 +152,28 @@ static int set_audclk_freq(struct cx18 *cx, u32 freq)
101 cx18_av_write4(cx, 0x108, 0x1809040f); 152 cx18_av_write4(cx, 0x108, 0x1809040f);
102 153
103 /* AUX_PLL_FRAC */ 154 /* AUX_PLL_FRAC */
104 cx18_av_write4(cx, 0x110, 0x00ec6bd6); 155 /* 0x9.7635e74 * 28,636,363.63 / 0x18 = 44100 * 256 */
156 cx18_av_write4(cx, 0x110, 0x00ec6bce);
105 157
106 /* src1_ctl = 0x08010000 */ 158 /* src1_ctl */
159 /* 0x1.60cd = 44100/32000 */
107 cx18_av_write4(cx, 0x8f8, 0x080160cd); 160 cx18_av_write4(cx, 0x8f8, 0x080160cd);
108 161
109 /* src3/4/6_ctl = 0x08020000 */ 162 /* src3/4/6_ctl */
163 /* 0x1.7385 = 2 * (32000/44100) */
110 cx18_av_write4(cx, 0x900, 0x08017385); 164 cx18_av_write4(cx, 0x900, 0x08017385);
111 cx18_av_write4(cx, 0x904, 0x08017385); 165 cx18_av_write4(cx, 0x904, 0x08017385);
112 cx18_av_write4(cx, 0x90c, 0x08017385); 166 cx18_av_write4(cx, 0x90c, 0x08017385);
167
168 /* AUD_COUNT = 0x61ff = 49 samples * 2 * 256 - 1 */
169 cx18_av_write4(cx, 0x12c, 0x112061ff);
170
171 /*
172 * EN_AV_LOCK = 1
173 * VID_COUNT = 0x1d4bf8 = 239999.000 * 8 =
174 * ((49 samples/44,100) * (13,500,000 * 8) * 2 - 1) * 8
175 */
176 cx18_av_write4(cx, 0x128, 0xa11d4bf8);
113 break; 177 break;
114 178
115 case 48000: 179 case 48000:
@@ -117,15 +181,28 @@ static int set_audclk_freq(struct cx18 *cx, u32 freq)
117 cx18_av_write4(cx, 0x108, 0x180a040f); 181 cx18_av_write4(cx, 0x108, 0x180a040f);
118 182
119 /* AUX_PLL_FRAC */ 183 /* AUX_PLL_FRAC */
120 cx18_av_write4(cx, 0x110, 0x0098d6e5); 184 /* 0xa.4c6b6ea * 28,636,363.63 / 0x18 = 48000 * 256 */
185 cx18_av_write4(cx, 0x110, 0x0098d6dd);
121 186
122 /* src1_ctl = 0x08010000 */ 187 /* src1_ctl */
188 /* 0x1.8000 = 48000/32000 */
123 cx18_av_write4(cx, 0x8f8, 0x08018000); 189 cx18_av_write4(cx, 0x8f8, 0x08018000);
124 190
125 /* src3/4/6_ctl = 0x08020000 */ 191 /* src3/4/6_ctl */
192 /* 0x1.5555 = 2 * (32000/48000) */
126 cx18_av_write4(cx, 0x900, 0x08015555); 193 cx18_av_write4(cx, 0x900, 0x08015555);
127 cx18_av_write4(cx, 0x904, 0x08015555); 194 cx18_av_write4(cx, 0x904, 0x08015555);
128 cx18_av_write4(cx, 0x90c, 0x08015555); 195 cx18_av_write4(cx, 0x90c, 0x08015555);
196
197 /* AUD_COUNT = 0x3fff = 4 samples * 16 * 256 - 1 */
198 cx18_av_write4(cx, 0x12c, 0x11203fff);
199
200 /*
201 * EN_AV_LOCK = 1
202 * VID_COUNT = 0x1193f8 = 143999.000 * 8 =
203 * ((4 samples/48,000) * (13,500,000 * 8) * 16 - 1) * 8
204 */
205 cx18_av_write4(cx, 0x128, 0xa11193f8);
129 break; 206 break;
130 } 207 }
131 } 208 }
diff --git a/drivers/media/video/cx18/cx18-driver.h b/drivers/media/video/cx18/cx18-driver.h
index 45e31b04730e..4801bc7fb5b2 100644
--- a/drivers/media/video/cx18/cx18-driver.h
+++ b/drivers/media/video/cx18/cx18-driver.h
@@ -46,6 +46,7 @@
46#include <linux/dvb/video.h> 46#include <linux/dvb/video.h>
47#include <linux/dvb/audio.h> 47#include <linux/dvb/audio.h>
48#include <media/v4l2-common.h> 48#include <media/v4l2-common.h>
49#include <media/v4l2-ioctl.h>
49#include <media/tuner.h> 50#include <media/tuner.h>
50#include "cx18-mailbox.h" 51#include "cx18-mailbox.h"
51#include "cx18-av-core.h" 52#include "cx18-av-core.h"
diff --git a/drivers/media/video/cx18/cx18-firmware.c b/drivers/media/video/cx18/cx18-firmware.c
index 2d630d9f7496..78fadd2ada5d 100644
--- a/drivers/media/video/cx18/cx18-firmware.c
+++ b/drivers/media/video/cx18/cx18-firmware.c
@@ -86,10 +86,6 @@
86 86
87#define CX18_DSP0_INTERRUPT_MASK 0xd0004C 87#define CX18_DSP0_INTERRUPT_MASK 0xd0004C
88 88
89/* Encoder/decoder firmware sizes */
90#define CX18_FW_CPU_SIZE (158332)
91#define CX18_FW_APU_SIZE (141200)
92
93#define APU_ROM_SYNC1 0x6D676553 /* "mgeS" */ 89#define APU_ROM_SYNC1 0x6D676553 /* "mgeS" */
94#define APU_ROM_SYNC2 0x72646548 /* "rdeH" */ 90#define APU_ROM_SYNC2 0x72646548 /* "rdeH" */
95 91
@@ -100,35 +96,22 @@ struct cx18_apu_rom_seghdr {
100 u32 size; 96 u32 size;
101}; 97};
102 98
103static int load_cpu_fw_direct(const char *fn, u8 __iomem *mem, struct cx18 *cx, long size) 99static int load_cpu_fw_direct(const char *fn, u8 __iomem *mem, struct cx18 *cx)
104{ 100{
105 const struct firmware *fw = NULL; 101 const struct firmware *fw = NULL;
106 int retries = 3;
107 int i, j; 102 int i, j;
103 unsigned size;
108 u32 __iomem *dst = (u32 __iomem *)mem; 104 u32 __iomem *dst = (u32 __iomem *)mem;
109 const u32 *src; 105 const u32 *src;
110 106
111retry: 107 if (request_firmware(&fw, fn, &cx->dev->dev)) {
112 if (!retries || request_firmware(&fw, fn, &cx->dev->dev)) { 108 CX18_ERR("Unable to open firmware %s\n", fn);
113 CX18_ERR("Unable to open firmware %s (must be %ld bytes)\n",
114 fn, size);
115 CX18_ERR("Did you put the firmware in the hotplug firmware directory?\n"); 109 CX18_ERR("Did you put the firmware in the hotplug firmware directory?\n");
116 return -ENOMEM; 110 return -ENOMEM;
117 } 111 }
118 112
119 src = (const u32 *)fw->data; 113 src = (const u32 *)fw->data;
120 114
121 if (fw->size != size) {
122 /* Due to race conditions in firmware loading (esp. with
123 udev <0.95) the wrong file was sometimes loaded. So we check
124 filesizes to see if at least the right-sized file was
125 loaded. If not, then we retry. */
126 CX18_INFO("retry: file loaded was not %s (expected size %ld, got %zd)\n",
127 fn, size, fw->size);
128 release_firmware(fw);
129 retries--;
130 goto retry;
131 }
132 for (i = 0; i < fw->size; i += 4096) { 115 for (i = 0; i < fw->size; i += 4096) {
133 setup_page(i); 116 setup_page(i);
134 for (j = i; j < fw->size && j < i + 4096; j += 4) { 117 for (j = i; j < fw->size && j < i + 4096; j += 4) {
@@ -145,15 +128,16 @@ retry:
145 } 128 }
146 if (!test_bit(CX18_F_I_LOADED_FW, &cx->i_flags)) 129 if (!test_bit(CX18_F_I_LOADED_FW, &cx->i_flags))
147 CX18_INFO("loaded %s firmware (%zd bytes)\n", fn, fw->size); 130 CX18_INFO("loaded %s firmware (%zd bytes)\n", fn, fw->size);
131 size = fw->size;
148 release_firmware(fw); 132 release_firmware(fw);
149 return size; 133 return size;
150} 134}
151 135
152static int load_apu_fw_direct(const char *fn, u8 __iomem *dst, struct cx18 *cx, long size) 136static int load_apu_fw_direct(const char *fn, u8 __iomem *dst, struct cx18 *cx)
153{ 137{
154 const struct firmware *fw = NULL; 138 const struct firmware *fw = NULL;
155 int retries = 3;
156 int i, j; 139 int i, j;
140 unsigned size;
157 const u32 *src; 141 const u32 *src;
158 struct cx18_apu_rom_seghdr seghdr; 142 struct cx18_apu_rom_seghdr seghdr;
159 const u8 *vers; 143 const u8 *vers;
@@ -161,10 +145,8 @@ static int load_apu_fw_direct(const char *fn, u8 __iomem *dst, struct cx18 *cx,
161 u32 apu_version = 0; 145 u32 apu_version = 0;
162 int sz; 146 int sz;
163 147
164retry: 148 if (request_firmware(&fw, fn, &cx->dev->dev)) {
165 if (!retries || request_firmware(&fw, fn, &cx->dev->dev)) { 149 CX18_ERR("unable to open firmware %s\n", fn);
166 CX18_ERR("unable to open firmware %s (must be %ld bytes)\n",
167 fn, size);
168 CX18_ERR("did you put the firmware in the hotplug firmware directory?\n"); 150 CX18_ERR("did you put the firmware in the hotplug firmware directory?\n");
169 return -ENOMEM; 151 return -ENOMEM;
170 } 152 }
@@ -173,19 +155,8 @@ retry:
173 vers = fw->data + sizeof(seghdr); 155 vers = fw->data + sizeof(seghdr);
174 sz = fw->size; 156 sz = fw->size;
175 157
176 if (fw->size != size) {
177 /* Due to race conditions in firmware loading (esp. with
178 udev <0.95) the wrong file was sometimes loaded. So we check
179 filesizes to see if at least the right-sized file was
180 loaded. If not, then we retry. */
181 CX18_INFO("retry: file loaded was not %s (expected size %ld, got %zd)\n",
182 fn, size, fw->size);
183 release_firmware(fw);
184 retries--;
185 goto retry;
186 }
187 apu_version = (vers[0] << 24) | (vers[4] << 16) | vers[32]; 158 apu_version = (vers[0] << 24) | (vers[4] << 16) | vers[32];
188 while (offset + sizeof(seghdr) < size) { 159 while (offset + sizeof(seghdr) < fw->size) {
189 /* TODO: byteswapping */ 160 /* TODO: byteswapping */
190 memcpy(&seghdr, src + offset / 4, sizeof(seghdr)); 161 memcpy(&seghdr, src + offset / 4, sizeof(seghdr));
191 offset += sizeof(seghdr); 162 offset += sizeof(seghdr);
@@ -215,6 +186,7 @@ retry:
215 if (!test_bit(CX18_F_I_LOADED_FW, &cx->i_flags)) 186 if (!test_bit(CX18_F_I_LOADED_FW, &cx->i_flags))
216 CX18_INFO("loaded %s firmware V%08x (%zd bytes)\n", 187 CX18_INFO("loaded %s firmware V%08x (%zd bytes)\n",
217 fn, apu_version, fw->size); 188 fn, apu_version, fw->size);
189 size = fw->size;
218 release_firmware(fw); 190 release_firmware(fw);
219 /* Clear bit0 for APU to start from 0 */ 191 /* Clear bit0 for APU to start from 0 */
220 write_reg(read_reg(0xc72030) & ~1, 0xc72030); 192 write_reg(read_reg(0xc72030) & ~1, 0xc72030);
@@ -340,7 +312,7 @@ int cx18_firmware_init(struct cx18 *cx)
340 /* Only if the processor is not running */ 312 /* Only if the processor is not running */
341 if (read_reg(CX18_PROC_SOFT_RESET) & 8) { 313 if (read_reg(CX18_PROC_SOFT_RESET) & 8) {
342 int sz = load_apu_fw_direct("v4l-cx23418-apu.fw", 314 int sz = load_apu_fw_direct("v4l-cx23418-apu.fw",
343 cx->enc_mem, cx, CX18_FW_APU_SIZE); 315 cx->enc_mem, cx);
344 316
345 write_enc(0xE51FF004, 0); 317 write_enc(0xE51FF004, 0);
346 write_enc(0xa00000, 4); /* todo: not hardcoded */ 318 write_enc(0xa00000, 4); /* todo: not hardcoded */
@@ -348,7 +320,7 @@ int cx18_firmware_init(struct cx18 *cx)
348 cx18_msleep_timeout(500, 0); 320 cx18_msleep_timeout(500, 0);
349 321
350 sz = sz <= 0 ? sz : load_cpu_fw_direct("v4l-cx23418-cpu.fw", 322 sz = sz <= 0 ? sz : load_cpu_fw_direct("v4l-cx23418-cpu.fw",
351 cx->enc_mem, cx, CX18_FW_CPU_SIZE); 323 cx->enc_mem, cx);
352 324
353 if (sz > 0) { 325 if (sz > 0) {
354 int retries = 0; 326 int retries = 0;
diff --git a/drivers/media/video/cx18/cx18-ioctl.c b/drivers/media/video/cx18/cx18-ioctl.c
index 0d74e59e503e..a7f839631d6a 100644
--- a/drivers/media/video/cx18/cx18-ioctl.c
+++ b/drivers/media/video/cx18/cx18-ioctl.c
@@ -787,50 +787,54 @@ int cx18_v4l2_ioctl(struct inode *inode, struct file *filp, unsigned int cmd,
787 return res; 787 return res;
788} 788}
789 789
790void cx18_set_funcs(struct video_device *vdev) 790static const struct v4l2_ioctl_ops cx18_ioctl_ops = {
791{ 791 .vidioc_querycap = cx18_querycap,
792 vdev->vidioc_querycap = cx18_querycap; 792 .vidioc_g_priority = cx18_g_priority,
793 vdev->vidioc_g_priority = cx18_g_priority; 793 .vidioc_s_priority = cx18_s_priority,
794 vdev->vidioc_s_priority = cx18_s_priority; 794 .vidioc_s_audio = cx18_s_audio,
795 vdev->vidioc_s_audio = cx18_s_audio; 795 .vidioc_g_audio = cx18_g_audio,
796 vdev->vidioc_g_audio = cx18_g_audio; 796 .vidioc_enumaudio = cx18_enumaudio,
797 vdev->vidioc_enumaudio = cx18_enumaudio; 797 .vidioc_enum_input = cx18_enum_input,
798 vdev->vidioc_enum_input = cx18_enum_input; 798 .vidioc_cropcap = cx18_cropcap,
799 vdev->vidioc_cropcap = cx18_cropcap; 799 .vidioc_s_crop = cx18_s_crop,
800 vdev->vidioc_s_crop = cx18_s_crop; 800 .vidioc_g_crop = cx18_g_crop,
801 vdev->vidioc_g_crop = cx18_g_crop; 801 .vidioc_g_input = cx18_g_input,
802 vdev->vidioc_g_input = cx18_g_input; 802 .vidioc_s_input = cx18_s_input,
803 vdev->vidioc_s_input = cx18_s_input; 803 .vidioc_g_frequency = cx18_g_frequency,
804 vdev->vidioc_g_frequency = cx18_g_frequency; 804 .vidioc_s_frequency = cx18_s_frequency,
805 vdev->vidioc_s_frequency = cx18_s_frequency; 805 .vidioc_s_tuner = cx18_s_tuner,
806 vdev->vidioc_s_tuner = cx18_s_tuner; 806 .vidioc_g_tuner = cx18_g_tuner,
807 vdev->vidioc_g_tuner = cx18_g_tuner; 807 .vidioc_g_enc_index = cx18_g_enc_index,
808 vdev->vidioc_g_enc_index = cx18_g_enc_index; 808 .vidioc_g_std = cx18_g_std,
809 vdev->vidioc_g_std = cx18_g_std; 809 .vidioc_s_std = cx18_s_std,
810 vdev->vidioc_s_std = cx18_s_std; 810 .vidioc_log_status = cx18_log_status,
811 vdev->vidioc_log_status = cx18_log_status; 811 .vidioc_enum_fmt_vid_cap = cx18_enum_fmt_vid_cap,
812 vdev->vidioc_enum_fmt_vid_cap = cx18_enum_fmt_vid_cap; 812 .vidioc_encoder_cmd = cx18_encoder_cmd,
813 vdev->vidioc_encoder_cmd = cx18_encoder_cmd; 813 .vidioc_try_encoder_cmd = cx18_try_encoder_cmd,
814 vdev->vidioc_try_encoder_cmd = cx18_try_encoder_cmd; 814 .vidioc_g_fmt_vid_cap = cx18_g_fmt_vid_cap,
815 vdev->vidioc_g_fmt_vid_cap = cx18_g_fmt_vid_cap; 815 .vidioc_g_fmt_vbi_cap = cx18_g_fmt_vbi_cap,
816 vdev->vidioc_g_fmt_vbi_cap = cx18_g_fmt_vbi_cap; 816 .vidioc_g_fmt_sliced_vbi_cap = cx18_g_fmt_sliced_vbi_cap,
817 vdev->vidioc_g_fmt_sliced_vbi_cap = cx18_g_fmt_sliced_vbi_cap; 817 .vidioc_s_fmt_vid_cap = cx18_s_fmt_vid_cap,
818 vdev->vidioc_s_fmt_vid_cap = cx18_s_fmt_vid_cap; 818 .vidioc_s_fmt_vbi_cap = cx18_s_fmt_vbi_cap,
819 vdev->vidioc_s_fmt_vbi_cap = cx18_s_fmt_vbi_cap; 819 .vidioc_s_fmt_sliced_vbi_cap = cx18_s_fmt_sliced_vbi_cap,
820 vdev->vidioc_s_fmt_sliced_vbi_cap = cx18_s_fmt_sliced_vbi_cap; 820 .vidioc_try_fmt_vid_cap = cx18_try_fmt_vid_cap,
821 vdev->vidioc_try_fmt_vid_cap = cx18_try_fmt_vid_cap; 821 .vidioc_try_fmt_vbi_cap = cx18_try_fmt_vbi_cap,
822 vdev->vidioc_try_fmt_vbi_cap = cx18_try_fmt_vbi_cap; 822 .vidioc_try_fmt_sliced_vbi_cap = cx18_try_fmt_sliced_vbi_cap,
823 vdev->vidioc_try_fmt_sliced_vbi_cap = cx18_try_fmt_sliced_vbi_cap; 823 .vidioc_g_sliced_vbi_cap = cx18_g_sliced_vbi_cap,
824 vdev->vidioc_g_sliced_vbi_cap = cx18_g_sliced_vbi_cap; 824 .vidioc_g_chip_ident = cx18_g_chip_ident,
825 vdev->vidioc_g_chip_ident = cx18_g_chip_ident;
826#ifdef CONFIG_VIDEO_ADV_DEBUG 825#ifdef CONFIG_VIDEO_ADV_DEBUG
827 vdev->vidioc_g_register = cx18_g_register; 826 .vidioc_g_register = cx18_g_register,
828 vdev->vidioc_s_register = cx18_s_register; 827 .vidioc_s_register = cx18_s_register,
829#endif 828#endif
830 vdev->vidioc_default = cx18_default; 829 .vidioc_default = cx18_default,
831 vdev->vidioc_queryctrl = cx18_queryctrl; 830 .vidioc_queryctrl = cx18_queryctrl,
832 vdev->vidioc_querymenu = cx18_querymenu; 831 .vidioc_querymenu = cx18_querymenu,
833 vdev->vidioc_g_ext_ctrls = cx18_g_ext_ctrls; 832 .vidioc_g_ext_ctrls = cx18_g_ext_ctrls,
834 vdev->vidioc_s_ext_ctrls = cx18_s_ext_ctrls; 833 .vidioc_s_ext_ctrls = cx18_s_ext_ctrls,
835 vdev->vidioc_try_ext_ctrls = cx18_try_ext_ctrls; 834 .vidioc_try_ext_ctrls = cx18_try_ext_ctrls,
835};
836
837void cx18_set_funcs(struct video_device *vdev)
838{
839 vdev->ioctl_ops = &cx18_ioctl_ops;
836} 840}
diff --git a/drivers/media/video/cx18/cx18-streams.c b/drivers/media/video/cx18/cx18-streams.c
index 1728b1d832a9..0da57f583bf7 100644
--- a/drivers/media/video/cx18/cx18-streams.c
+++ b/drivers/media/video/cx18/cx18-streams.c
@@ -187,14 +187,11 @@ static int cx18_prep_dev(struct cx18 *cx, int type)
187 return -ENOMEM; 187 return -ENOMEM;
188 } 188 }
189 189
190 s->v4l2dev->type =
191 VID_TYPE_CAPTURE | VID_TYPE_TUNER | VID_TYPE_TELETEXT |
192 VID_TYPE_CLIPPING | VID_TYPE_SCALES | VID_TYPE_MPEG_ENCODER;
193 snprintf(s->v4l2dev->name, sizeof(s->v4l2dev->name), "cx18-%d", 190 snprintf(s->v4l2dev->name, sizeof(s->v4l2dev->name), "cx18-%d",
194 cx->num); 191 cx->num);
195 192
196 s->v4l2dev->minor = minor; 193 s->v4l2dev->minor = minor;
197 s->v4l2dev->dev = &cx->dev->dev; 194 s->v4l2dev->parent = &cx->dev->dev;
198 s->v4l2dev->fops = cx18_stream_info[type].fops; 195 s->v4l2dev->fops = cx18_stream_info[type].fops;
199 s->v4l2dev->release = video_device_release; 196 s->v4l2dev->release = video_device_release;
200 s->v4l2dev->tvnorms = V4L2_STD_ALL; 197 s->v4l2dev->tvnorms = V4L2_STD_ALL;
diff --git a/drivers/media/video/cx23885/Kconfig b/drivers/media/video/cx23885/Kconfig
index 5cfb46bbdaa9..e60bd31b51a3 100644
--- a/drivers/media/video/cx23885/Kconfig
+++ b/drivers/media/video/cx23885/Kconfig
@@ -1,9 +1,7 @@
1config VIDEO_CX23885 1config VIDEO_CX23885
2 tristate "Conexant cx23885 (2388x successor) support" 2 tristate "Conexant cx23885 (2388x successor) support"
3 depends on DVB_CORE && VIDEO_DEV && PCI && I2C && INPUT 3 depends on DVB_CORE && VIDEO_DEV && PCI && I2C && INPUT
4 depends on HOTPLUG # due to FW_LOADER
5 select I2C_ALGOBIT 4 select I2C_ALGOBIT
6 select FW_LOADER
7 select VIDEO_BTCX 5 select VIDEO_BTCX
8 select VIDEO_TUNER 6 select VIDEO_TUNER
9 select VIDEO_TVEEPROM 7 select VIDEO_TVEEPROM
diff --git a/drivers/media/video/cx23885/cx23885-417.c b/drivers/media/video/cx23885/cx23885-417.c
index e7ef093265af..8118091568fc 100644
--- a/drivers/media/video/cx23885/cx23885-417.c
+++ b/drivers/media/video/cx23885/cx23885-417.c
@@ -32,6 +32,7 @@
32#include <linux/device.h> 32#include <linux/device.h>
33#include <linux/firmware.h> 33#include <linux/firmware.h>
34#include <media/v4l2-common.h> 34#include <media/v4l2-common.h>
35#include <media/v4l2-ioctl.h>
35#include <media/cx2341x.h> 36#include <media/cx2341x.h>
36 37
37#include "cx23885.h" 38#include "cx23885.h"
@@ -1699,14 +1700,7 @@ static struct file_operations mpeg_fops = {
1699 .llseek = no_llseek, 1700 .llseek = no_llseek,
1700}; 1701};
1701 1702
1702static struct video_device cx23885_mpeg_template = { 1703static const struct v4l2_ioctl_ops mpeg_ioctl_ops = {
1703 .name = "cx23885",
1704 .type = VID_TYPE_CAPTURE |
1705 VID_TYPE_TUNER |
1706 VID_TYPE_SCALES |
1707 VID_TYPE_MPEG_ENCODER,
1708 .fops = &mpeg_fops,
1709 .minor = -1,
1710 .vidioc_s_std = vidioc_s_std, 1704 .vidioc_s_std = vidioc_s_std,
1711 .vidioc_enum_input = vidioc_enum_input, 1705 .vidioc_enum_input = vidioc_enum_input,
1712 .vidioc_g_input = vidioc_g_input, 1706 .vidioc_g_input = vidioc_g_input,
@@ -1735,6 +1729,13 @@ static struct video_device cx23885_mpeg_template = {
1735 .vidioc_queryctrl = vidioc_queryctrl, 1729 .vidioc_queryctrl = vidioc_queryctrl,
1736}; 1730};
1737 1731
1732static struct video_device cx23885_mpeg_template = {
1733 .name = "cx23885",
1734 .fops = &mpeg_fops,
1735 .ioctl_ops = &mpeg_ioctl_ops,
1736 .minor = -1,
1737};
1738
1738void cx23885_417_unregister(struct cx23885_dev *dev) 1739void cx23885_417_unregister(struct cx23885_dev *dev)
1739{ 1740{
1740 dprintk(1, "%s()\n", __func__); 1741 dprintk(1, "%s()\n", __func__);
@@ -1766,7 +1767,7 @@ static struct video_device *cx23885_video_dev_alloc(
1766 vfd->minor = -1; 1767 vfd->minor = -1;
1767 snprintf(vfd->name, sizeof(vfd->name), "%s %s (%s)", dev->name, 1768 snprintf(vfd->name, sizeof(vfd->name), "%s %s (%s)", dev->name,
1768 type, cx23885_boards[tsport->dev->board].name); 1769 type, cx23885_boards[tsport->dev->board].name);
1769 vfd->dev = &pci->dev; 1770 vfd->parent = &pci->dev;
1770 vfd->release = video_device_release; 1771 vfd->release = video_device_release;
1771 return vfd; 1772 return vfd;
1772} 1773}
diff --git a/drivers/media/video/cx23885/cx23885-cards.c b/drivers/media/video/cx23885/cx23885-cards.c
index fd7112c11d35..a19de850955d 100644
--- a/drivers/media/video/cx23885/cx23885-cards.c
+++ b/drivers/media/video/cx23885/cx23885-cards.c
@@ -145,6 +145,7 @@ struct cx23885_board cx23885_boards[] = {
145 }, 145 },
146 [CX23885_BOARD_DVICO_FUSIONHDTV_7_DUAL_EXP] = { 146 [CX23885_BOARD_DVICO_FUSIONHDTV_7_DUAL_EXP] = {
147 .name = "DViCO FusionHDTV7 Dual Express", 147 .name = "DViCO FusionHDTV7 Dual Express",
148 .portb = CX23885_MPEG_DVB,
148 .portc = CX23885_MPEG_DVB, 149 .portc = CX23885_MPEG_DVB,
149 }, 150 },
150}; 151};
@@ -325,25 +326,41 @@ int cx23885_tuner_callback(void *priv, int command, int arg)
325{ 326{
326 struct cx23885_i2c *bus = priv; 327 struct cx23885_i2c *bus = priv;
327 struct cx23885_dev *dev = bus->dev; 328 struct cx23885_dev *dev = bus->dev;
329 u32 bitmask = 0;
330
331 if (command != 0) {
332 printk(KERN_ERR "%s(): Unknown command 0x%x.\n",
333 __func__, command);
334 return -EINVAL;
335 }
328 336
329 switch(dev->board) { 337 switch(dev->board) {
330 case CX23885_BOARD_HAUPPAUGE_HVR1500Q: 338 case CX23885_BOARD_HAUPPAUGE_HVR1500Q:
331 if(command == 0) { /* Tuner Reset Command from xc5000 */ 339 /* Tuner Reset Command from xc5000 */
332 /* Drive the tuner into reset and out */ 340 if (command == 0)
333 cx_clear(GP0_IO, 0x00000004); 341 bitmask = 0x04;
334 mdelay(200); 342 break;
335 cx_set(GP0_IO, 0x00000004); 343 case CX23885_BOARD_DVICO_FUSIONHDTV_7_DUAL_EXP:
336 return 0; 344 if (command == 0) {
337 } 345
338 else { 346 /* Two identical tuners on two different i2c buses,
339 printk(KERN_ERR 347 * we need to reset the correct gpio. */
340 "%s(): Unknow command.\n", __func__); 348 if (bus->nr == 0)
341 return -EINVAL; 349 bitmask = 0x01;
350 else if (bus->nr == 1)
351 bitmask = 0x04;
342 } 352 }
343 break; 353 break;
344 } 354 }
345 355
346 return 0; /* Should never be here */ 356 if (bitmask) {
357 /* Drive the tuner into reset and back out */
358 cx_clear(GP0_IO, bitmask);
359 mdelay(200);
360 cx_set(GP0_IO, bitmask);
361 }
362
363 return 0;
347} 364}
348 365
349void cx23885_gpio_setup(struct cx23885_dev *dev) 366void cx23885_gpio_setup(struct cx23885_dev *dev)
@@ -435,6 +452,19 @@ void cx23885_gpio_setup(struct cx23885_dev *dev)
435 mdelay(20); 452 mdelay(20);
436 cx_set(GP0_IO, 0x00050005); 453 cx_set(GP0_IO, 0x00050005);
437 break; 454 break;
455 case CX23885_BOARD_DVICO_FUSIONHDTV_7_DUAL_EXP:
456 /* GPIO-0 xc5000 tuner reset i2c bus 0 */
457 /* GPIO-1 s5h1409 demod reset i2c bus 0 */
458 /* GPIO-2 xc5000 tuner reset i2c bus 1 */
459 /* GPIO-3 s5h1409 demod reset i2c bus 0 */
460
461 /* Put the parts into reset and back */
462 cx_set(GP0_IO, 0x000f0000);
463 mdelay(20);
464 cx_clear(GP0_IO, 0x0000000f);
465 mdelay(20);
466 cx_set(GP0_IO, 0x000f000f);
467 break;
438 } 468 }
439} 469}
440 470
diff --git a/drivers/media/video/cx23885/cx23885-core.c b/drivers/media/video/cx23885/cx23885-core.c
index d17343ea0d33..6286a9cf957e 100644
--- a/drivers/media/video/cx23885/cx23885-core.c
+++ b/drivers/media/video/cx23885/cx23885-core.c
@@ -76,6 +76,117 @@ LIST_HEAD(cx23885_devlist);
76 * 0x00010ea0 0x00010xxx Free 76 * 0x00010ea0 0x00010xxx Free
77 */ 77 */
78 78
79static struct sram_channel cx23885_sram_channels[] = {
80 [SRAM_CH01] = {
81 .name = "VID A",
82 .cmds_start = 0x10000,
83 .ctrl_start = 0x10380,
84 .cdt = 0x104c0,
85 .fifo_start = 0x40,
86 .fifo_size = 0x2800,
87 .ptr1_reg = DMA1_PTR1,
88 .ptr2_reg = DMA1_PTR2,
89 .cnt1_reg = DMA1_CNT1,
90 .cnt2_reg = DMA1_CNT2,
91 },
92 [SRAM_CH02] = {
93 .name = "ch2",
94 .cmds_start = 0x0,
95 .ctrl_start = 0x0,
96 .cdt = 0x0,
97 .fifo_start = 0x0,
98 .fifo_size = 0x0,
99 .ptr1_reg = DMA2_PTR1,
100 .ptr2_reg = DMA2_PTR2,
101 .cnt1_reg = DMA2_CNT1,
102 .cnt2_reg = DMA2_CNT2,
103 },
104 [SRAM_CH03] = {
105 .name = "TS1 B",
106 .cmds_start = 0x100A0,
107 .ctrl_start = 0x10400,
108 .cdt = 0x10580,
109 .fifo_start = 0x5000,
110 .fifo_size = 0x1000,
111 .ptr1_reg = DMA3_PTR1,
112 .ptr2_reg = DMA3_PTR2,
113 .cnt1_reg = DMA3_CNT1,
114 .cnt2_reg = DMA3_CNT2,
115 },
116 [SRAM_CH04] = {
117 .name = "ch4",
118 .cmds_start = 0x0,
119 .ctrl_start = 0x0,
120 .cdt = 0x0,
121 .fifo_start = 0x0,
122 .fifo_size = 0x0,
123 .ptr1_reg = DMA4_PTR1,
124 .ptr2_reg = DMA4_PTR2,
125 .cnt1_reg = DMA4_CNT1,
126 .cnt2_reg = DMA4_CNT2,
127 },
128 [SRAM_CH05] = {
129 .name = "ch5",
130 .cmds_start = 0x0,
131 .ctrl_start = 0x0,
132 .cdt = 0x0,
133 .fifo_start = 0x0,
134 .fifo_size = 0x0,
135 .ptr1_reg = DMA5_PTR1,
136 .ptr2_reg = DMA5_PTR2,
137 .cnt1_reg = DMA5_CNT1,
138 .cnt2_reg = DMA5_CNT2,
139 },
140 [SRAM_CH06] = {
141 .name = "TS2 C",
142 .cmds_start = 0x10140,
143 .ctrl_start = 0x10440,
144 .cdt = 0x105e0,
145 .fifo_start = 0x6000,
146 .fifo_size = 0x1000,
147 .ptr1_reg = DMA5_PTR1,
148 .ptr2_reg = DMA5_PTR2,
149 .cnt1_reg = DMA5_CNT1,
150 .cnt2_reg = DMA5_CNT2,
151 },
152 [SRAM_CH07] = {
153 .name = "ch7",
154 .cmds_start = 0x0,
155 .ctrl_start = 0x0,
156 .cdt = 0x0,
157 .fifo_start = 0x0,
158 .fifo_size = 0x0,
159 .ptr1_reg = DMA6_PTR1,
160 .ptr2_reg = DMA6_PTR2,
161 .cnt1_reg = DMA6_CNT1,
162 .cnt2_reg = DMA6_CNT2,
163 },
164 [SRAM_CH08] = {
165 .name = "ch8",
166 .cmds_start = 0x0,
167 .ctrl_start = 0x0,
168 .cdt = 0x0,
169 .fifo_start = 0x0,
170 .fifo_size = 0x0,
171 .ptr1_reg = DMA7_PTR1,
172 .ptr2_reg = DMA7_PTR2,
173 .cnt1_reg = DMA7_CNT1,
174 .cnt2_reg = DMA7_CNT2,
175 },
176 [SRAM_CH09] = {
177 .name = "ch9",
178 .cmds_start = 0x0,
179 .ctrl_start = 0x0,
180 .cdt = 0x0,
181 .fifo_start = 0x0,
182 .fifo_size = 0x0,
183 .ptr1_reg = DMA8_PTR1,
184 .ptr2_reg = DMA8_PTR2,
185 .cnt1_reg = DMA8_CNT1,
186 .cnt2_reg = DMA8_CNT2,
187 },
188};
189
79static struct sram_channel cx23887_sram_channels[] = { 190static struct sram_channel cx23887_sram_channels[] = {
80 [SRAM_CH01] = { 191 [SRAM_CH01] = {
81 .name = "VID A", 192 .name = "VID A",
@@ -104,8 +215,8 @@ static struct sram_channel cx23887_sram_channels[] = {
104 [SRAM_CH03] = { 215 [SRAM_CH03] = {
105 .name = "TS1 B", 216 .name = "TS1 B",
106 .cmds_start = 0x100A0, 217 .cmds_start = 0x100A0,
107 .ctrl_start = 0x10780, 218 .ctrl_start = 0x10630,
108 .cdt = 0x10400, 219 .cdt = 0x10870,
109 .fifo_start = 0x5000, 220 .fifo_start = 0x5000,
110 .fifo_size = 0x1000, 221 .fifo_size = 0x1000,
111 .ptr1_reg = DMA3_PTR1, 222 .ptr1_reg = DMA3_PTR1,
@@ -140,7 +251,7 @@ static struct sram_channel cx23887_sram_channels[] = {
140 [SRAM_CH06] = { 251 [SRAM_CH06] = {
141 .name = "TS2 C", 252 .name = "TS2 C",
142 .cmds_start = 0x10140, 253 .cmds_start = 0x10140,
143 .ctrl_start = 0x10680, 254 .ctrl_start = 0x10670,
144 .cdt = 0x108d0, 255 .cdt = 0x108d0,
145 .fifo_start = 0x6000, 256 .fifo_start = 0x6000,
146 .fifo_size = 0x1000, 257 .fifo_size = 0x1000,
@@ -460,6 +571,7 @@ static void cx23885_reset(struct cx23885_dev *dev)
460 cx_write(AUDIO_INT_INT_STAT, 0xffffffff); 571 cx_write(AUDIO_INT_INT_STAT, 0xffffffff);
461 cx_write(AUDIO_EXT_INT_STAT, 0xffffffff); 572 cx_write(AUDIO_EXT_INT_STAT, 0xffffffff);
462 cx_write(CLK_DELAY, cx_read(CLK_DELAY) & 0x80000000); 573 cx_write(CLK_DELAY, cx_read(CLK_DELAY) & 0x80000000);
574 cx_write(PAD_CTRL, 0x00500300);
463 575
464 mdelay(100); 576 mdelay(100);
465 577
@@ -625,7 +737,6 @@ static int cx23885_dev_setup(struct cx23885_dev *dev)
625 atomic_inc(&dev->refcount); 737 atomic_inc(&dev->refcount);
626 738
627 dev->nr = cx23885_devcount++; 739 dev->nr = cx23885_devcount++;
628 dev->sram_channels = cx23887_sram_channels;
629 sprintf(dev->name, "cx23885[%d]", dev->nr); 740 sprintf(dev->name, "cx23885[%d]", dev->nr);
630 741
631 mutex_lock(&devlist); 742 mutex_lock(&devlist);
@@ -637,11 +748,13 @@ static int cx23885_dev_setup(struct cx23885_dev *dev)
637 dev->bridge = CX23885_BRIDGE_887; 748 dev->bridge = CX23885_BRIDGE_887;
638 /* Apply a sensible clock frequency for the PCIe bridge */ 749 /* Apply a sensible clock frequency for the PCIe bridge */
639 dev->clk_freq = 25000000; 750 dev->clk_freq = 25000000;
751 dev->sram_channels = cx23887_sram_channels;
640 } else 752 } else
641 if(dev->pci->device == 0x8852) { 753 if(dev->pci->device == 0x8852) {
642 dev->bridge = CX23885_BRIDGE_885; 754 dev->bridge = CX23885_BRIDGE_885;
643 /* Apply a sensible clock frequency for the PCIe bridge */ 755 /* Apply a sensible clock frequency for the PCIe bridge */
644 dev->clk_freq = 28000000; 756 dev->clk_freq = 28000000;
757 dev->sram_channels = cx23885_sram_channels;
645 } else 758 } else
646 BUG(); 759 BUG();
647 760
@@ -1010,8 +1123,9 @@ static void cx23885_tsport_reg_dump(struct cx23885_tsport *port)
1010 port->reg_gpcnt_ctl, cx_read(port->reg_gpcnt_ctl)); 1123 port->reg_gpcnt_ctl, cx_read(port->reg_gpcnt_ctl));
1011 dprintk(1, "%s() dma_ctl(0x%08X) 0x%08x\n", __func__, 1124 dprintk(1, "%s() dma_ctl(0x%08X) 0x%08x\n", __func__,
1012 port->reg_dma_ctl, cx_read(port->reg_dma_ctl)); 1125 port->reg_dma_ctl, cx_read(port->reg_dma_ctl));
1013 dprintk(1, "%s() src_sel(0x%08X) 0x%08x\n", __func__, 1126 if (port->reg_src_sel)
1014 port->reg_src_sel, cx_read(port->reg_src_sel)); 1127 dprintk(1, "%s() src_sel(0x%08X) 0x%08x\n", __func__,
1128 port->reg_src_sel, cx_read(port->reg_src_sel));
1015 dprintk(1, "%s() lngth(0x%08X) 0x%08x\n", __func__, 1129 dprintk(1, "%s() lngth(0x%08X) 0x%08x\n", __func__,
1016 port->reg_lngth, cx_read(port->reg_lngth)); 1130 port->reg_lngth, cx_read(port->reg_lngth));
1017 dprintk(1, "%s() hw_sop_ctrl(0x%08X) 0x%08x\n", __func__, 1131 dprintk(1, "%s() hw_sop_ctrl(0x%08X) 0x%08x\n", __func__,
@@ -1042,6 +1156,9 @@ static int cx23885_start_dma(struct cx23885_tsport *port,
1042 dprintk(1, "%s() w: %d, h: %d, f: %d\n", __func__, 1156 dprintk(1, "%s() w: %d, h: %d, f: %d\n", __func__,
1043 buf->vb.width, buf->vb.height, buf->vb.field); 1157 buf->vb.width, buf->vb.height, buf->vb.field);
1044 1158
1159 /* Stop the fifo and risc engine for this port */
1160 cx_clear(port->reg_dma_ctl, port->dma_ctl_val);
1161
1045 /* setup fifo + format */ 1162 /* setup fifo + format */
1046 cx23885_sram_channel_setup(dev, 1163 cx23885_sram_channel_setup(dev,
1047 &dev->sram_channels[ port->sram_chno ], 1164 &dev->sram_channels[ port->sram_chno ],
@@ -1083,7 +1200,21 @@ static int cx23885_start_dma(struct cx23885_tsport *port,
1083 cx_write(port->reg_gpcnt_ctl, 3); 1200 cx_write(port->reg_gpcnt_ctl, 3);
1084 q->count = 1; 1201 q->count = 1;
1085 1202
1086 if (cx23885_boards[dev->board].portb & CX23885_MPEG_ENCODER) { 1203 /* Set VIDB pins to input */
1204 if (cx23885_boards[dev->board].portb == CX23885_MPEG_DVB) {
1205 reg = cx_read(PAD_CTRL);
1206 reg &= ~0x3; /* Clear TS1_OE & TS1_SOP_OE */
1207 cx_write(PAD_CTRL, reg);
1208 }
1209
1210 /* Set VIDC pins to input */
1211 if (cx23885_boards[dev->board].portc == CX23885_MPEG_DVB) {
1212 reg = cx_read(PAD_CTRL);
1213 reg &= ~0x4; /* Clear TS2_SOP_OE */
1214 cx_write(PAD_CTRL, reg);
1215 }
1216
1217 if (cx23885_boards[dev->board].portb == CX23885_MPEG_ENCODER) {
1087 1218
1088 reg = cx_read(PAD_CTRL); 1219 reg = cx_read(PAD_CTRL);
1089 reg = reg & ~0x1; /* Clear TS1_OE */ 1220 reg = reg & ~0x1; /* Clear TS1_OE */
@@ -1133,7 +1264,7 @@ static int cx23885_stop_dma(struct cx23885_tsport *port)
1133 cx_clear(port->reg_ts_int_msk, port->ts_int_msk_val); 1264 cx_clear(port->reg_ts_int_msk, port->ts_int_msk_val);
1134 cx_clear(port->reg_dma_ctl, port->dma_ctl_val); 1265 cx_clear(port->reg_dma_ctl, port->dma_ctl_val);
1135 1266
1136 if (cx23885_boards[dev->board].portb & CX23885_MPEG_ENCODER) { 1267 if (cx23885_boards[dev->board].portb == CX23885_MPEG_ENCODER) {
1137 1268
1138 reg = cx_read(PAD_CTRL); 1269 reg = cx_read(PAD_CTRL);
1139 1270
diff --git a/drivers/media/video/cx23885/cx23885-video.c b/drivers/media/video/cx23885/cx23885-video.c
index 043fc4e5c586..ad2235dab5b1 100644
--- a/drivers/media/video/cx23885/cx23885-video.c
+++ b/drivers/media/video/cx23885/cx23885-video.c
@@ -33,6 +33,7 @@
33 33
34#include "cx23885.h" 34#include "cx23885.h"
35#include <media/v4l2-common.h> 35#include <media/v4l2-common.h>
36#include <media/v4l2-ioctl.h>
36 37
37#ifdef CONFIG_VIDEO_V4L1_COMPAT 38#ifdef CONFIG_VIDEO_V4L1_COMPAT
38/* Include V4L1 specific functions. Should be removed soon */ 39/* Include V4L1 specific functions. Should be removed soon */
@@ -326,7 +327,7 @@ struct video_device *cx23885_vdev_init(struct cx23885_dev *dev,
326 return NULL; 327 return NULL;
327 *vfd = *template; 328 *vfd = *template;
328 vfd->minor = -1; 329 vfd->minor = -1;
329 vfd->dev = &pci->dev; 330 vfd->parent = &pci->dev;
330 vfd->release = video_device_release; 331 vfd->release = video_device_release;
331 snprintf(vfd->name, sizeof(vfd->name), "%s %s (%s)", 332 snprintf(vfd->name, sizeof(vfd->name), "%s %s (%s)",
332 dev->name, type, cx23885_boards[dev->board].name); 333 dev->name, type, cx23885_boards[dev->board].name);
@@ -1433,12 +1434,7 @@ static const struct file_operations video_fops = {
1433 .llseek = no_llseek, 1434 .llseek = no_llseek,
1434}; 1435};
1435 1436
1436static struct video_device cx23885_vbi_template; 1437static const struct v4l2_ioctl_ops video_ioctl_ops = {
1437static struct video_device cx23885_video_template = {
1438 .name = "cx23885-video",
1439 .type = VID_TYPE_CAPTURE|VID_TYPE_TUNER|VID_TYPE_SCALES,
1440 .fops = &video_fops,
1441 .minor = -1,
1442 .vidioc_querycap = vidioc_querycap, 1438 .vidioc_querycap = vidioc_querycap,
1443 .vidioc_enum_fmt_vid_cap = vidioc_enum_fmt_vid_cap, 1439 .vidioc_enum_fmt_vid_cap = vidioc_enum_fmt_vid_cap,
1444 .vidioc_g_fmt_vid_cap = vidioc_g_fmt_vid_cap, 1440 .vidioc_g_fmt_vid_cap = vidioc_g_fmt_vid_cap,
@@ -1471,6 +1467,14 @@ static struct video_device cx23885_video_template = {
1471 .vidioc_g_register = vidioc_g_register, 1467 .vidioc_g_register = vidioc_g_register,
1472 .vidioc_s_register = vidioc_s_register, 1468 .vidioc_s_register = vidioc_s_register,
1473#endif 1469#endif
1470};
1471
1472static struct video_device cx23885_vbi_template;
1473static struct video_device cx23885_video_template = {
1474 .name = "cx23885-video",
1475 .fops = &video_fops,
1476 .minor = -1,
1477 .ioctl_ops = &video_ioctl_ops,
1474 .tvnorms = CX23885_NORMS, 1478 .tvnorms = CX23885_NORMS,
1475 .current_norm = V4L2_STD_NTSC_M, 1479 .current_norm = V4L2_STD_NTSC_M,
1476}; 1480};
@@ -1512,7 +1516,6 @@ int cx23885_video_register(struct cx23885_dev *dev)
1512 memcpy(&cx23885_vbi_template, &cx23885_video_template, 1516 memcpy(&cx23885_vbi_template, &cx23885_video_template,
1513 sizeof(cx23885_vbi_template)); 1517 sizeof(cx23885_vbi_template));
1514 strcpy(cx23885_vbi_template.name, "cx23885-vbi"); 1518 strcpy(cx23885_vbi_template.name, "cx23885-vbi");
1515 cx23885_vbi_template.type = VID_TYPE_TELETEXT|VID_TYPE_TUNER;
1516 1519
1517 dev->tvnorm = cx23885_video_template.current_norm; 1520 dev->tvnorm = cx23885_video_template.current_norm;
1518 1521
diff --git a/drivers/media/video/cx25840/Kconfig b/drivers/media/video/cx25840/Kconfig
index 448f4cd0ce34..de515dadadc2 100644
--- a/drivers/media/video/cx25840/Kconfig
+++ b/drivers/media/video/cx25840/Kconfig
@@ -1,8 +1,6 @@
1config VIDEO_CX25840 1config VIDEO_CX25840
2 tristate "Conexant CX2584x audio/video decoders" 2 tristate "Conexant CX2584x audio/video decoders"
3 depends on VIDEO_V4L2 && I2C && EXPERIMENTAL 3 depends on VIDEO_V4L2 && I2C && EXPERIMENTAL
4 depends on HOTPLUG # due to FW_LOADER
5 select FW_LOADER
6 ---help--- 4 ---help---
7 Support for the Conexant CX2584x audio/video decoders. 5 Support for the Conexant CX2584x audio/video decoders.
8 6
diff --git a/drivers/media/video/cx25840/cx25840-core.c b/drivers/media/video/cx25840/cx25840-core.c
index e7bf4f4c1319..209d3bcb5dbb 100644
--- a/drivers/media/video/cx25840/cx25840-core.c
+++ b/drivers/media/video/cx25840/cx25840-core.c
@@ -50,7 +50,7 @@ MODULE_LICENSE("GPL");
50 50
51static unsigned short normal_i2c[] = { 0x88 >> 1, I2C_CLIENT_END }; 51static unsigned short normal_i2c[] = { 0x88 >> 1, I2C_CLIENT_END };
52 52
53int cx25840_debug; 53static int cx25840_debug;
54 54
55module_param_named(debug,cx25840_debug, int, 0644); 55module_param_named(debug,cx25840_debug, int, 0644);
56 56
diff --git a/drivers/media/video/cx25840/cx25840-core.h b/drivers/media/video/cx25840/cx25840-core.h
index 72916ba975a8..b87337e590b4 100644
--- a/drivers/media/video/cx25840/cx25840-core.h
+++ b/drivers/media/video/cx25840/cx25840-core.h
@@ -24,8 +24,6 @@
24#include <linux/videodev2.h> 24#include <linux/videodev2.h>
25#include <linux/i2c.h> 25#include <linux/i2c.h>
26 26
27extern int cx25840_debug;
28
29/* ENABLE_PVR150_WORKAROUND activates a workaround for a hardware bug that is 27/* ENABLE_PVR150_WORKAROUND activates a workaround for a hardware bug that is
30 present in Hauppauge PVR-150 (and possibly PVR-500) cards that have 28 present in Hauppauge PVR-150 (and possibly PVR-500) cards that have
31 certain NTSC tuners (tveeprom tuner model numbers 85, 99 and 112). The 29 certain NTSC tuners (tveeprom tuner model numbers 85, 99 and 112). The
diff --git a/drivers/media/video/cx88/Kconfig b/drivers/media/video/cx88/Kconfig
index 10e20d8196dc..9dd7bdf659b9 100644
--- a/drivers/media/video/cx88/Kconfig
+++ b/drivers/media/video/cx88/Kconfig
@@ -33,9 +33,8 @@ config VIDEO_CX88_ALSA
33 33
34config VIDEO_CX88_BLACKBIRD 34config VIDEO_CX88_BLACKBIRD
35 tristate "Blackbird MPEG encoder support (cx2388x + cx23416)" 35 tristate "Blackbird MPEG encoder support (cx2388x + cx23416)"
36 depends on VIDEO_CX88 && HOTPLUG 36 depends on VIDEO_CX88
37 select VIDEO_CX2341X 37 select VIDEO_CX2341X
38 select FW_LOADER
39 ---help--- 38 ---help---
40 This adds support for MPEG encoder cards based on the 39 This adds support for MPEG encoder cards based on the
41 Blackbird reference design, using the Conexant 2388x 40 Blackbird reference design, using the Conexant 2388x
diff --git a/drivers/media/video/cx88/cx88-blackbird.c b/drivers/media/video/cx88/cx88-blackbird.c
index bfdca5847764..9a1374a38ec7 100644
--- a/drivers/media/video/cx88/cx88-blackbird.c
+++ b/drivers/media/video/cx88/cx88-blackbird.c
@@ -33,6 +33,7 @@
33#include <linux/device.h> 33#include <linux/device.h>
34#include <linux/firmware.h> 34#include <linux/firmware.h>
35#include <media/v4l2-common.h> 35#include <media/v4l2-common.h>
36#include <media/v4l2-ioctl.h>
36#include <media/cx2341x.h> 37#include <media/cx2341x.h>
37 38
38#include "cx88.h" 39#include "cx88.h"
@@ -1174,12 +1175,7 @@ static const struct file_operations mpeg_fops =
1174 .llseek = no_llseek, 1175 .llseek = no_llseek,
1175}; 1176};
1176 1177
1177static struct video_device cx8802_mpeg_template = 1178static const struct v4l2_ioctl_ops mpeg_ioctl_ops = {
1178{
1179 .name = "cx8802",
1180 .type = VID_TYPE_CAPTURE|VID_TYPE_TUNER|VID_TYPE_SCALES|VID_TYPE_MPEG_ENCODER,
1181 .fops = &mpeg_fops,
1182 .minor = -1,
1183 .vidioc_querymenu = vidioc_querymenu, 1179 .vidioc_querymenu = vidioc_querymenu,
1184 .vidioc_querycap = vidioc_querycap, 1180 .vidioc_querycap = vidioc_querycap,
1185 .vidioc_enum_fmt_vid_cap = vidioc_enum_fmt_vid_cap, 1181 .vidioc_enum_fmt_vid_cap = vidioc_enum_fmt_vid_cap,
@@ -1207,6 +1203,13 @@ static struct video_device cx8802_mpeg_template =
1207 .vidioc_g_tuner = vidioc_g_tuner, 1203 .vidioc_g_tuner = vidioc_g_tuner,
1208 .vidioc_s_tuner = vidioc_s_tuner, 1204 .vidioc_s_tuner = vidioc_s_tuner,
1209 .vidioc_s_std = vidioc_s_std, 1205 .vidioc_s_std = vidioc_s_std,
1206};
1207
1208static struct video_device cx8802_mpeg_template = {
1209 .name = "cx8802",
1210 .fops = &mpeg_fops,
1211 .ioctl_ops = &mpeg_ioctl_ops,
1212 .minor = -1,
1210 .tvnorms = CX88_NORMS, 1213 .tvnorms = CX88_NORMS,
1211 .current_norm = V4L2_STD_NTSC_M, 1214 .current_norm = V4L2_STD_NTSC_M,
1212}; 1215};
diff --git a/drivers/media/video/cx88/cx88-cards.c b/drivers/media/video/cx88/cx88-cards.c
index fa6d398e97b9..de199a206a15 100644
--- a/drivers/media/video/cx88/cx88-cards.c
+++ b/drivers/media/video/cx88/cx88-cards.c
@@ -1348,7 +1348,7 @@ static const struct cx88_board cx88_boards[] = {
1348 .tuner_addr = ADDR_UNSET, 1348 .tuner_addr = ADDR_UNSET,
1349 .radio_addr = ADDR_UNSET, 1349 .radio_addr = ADDR_UNSET,
1350 .tda9887_conf = TDA9887_PRESENT, 1350 .tda9887_conf = TDA9887_PRESENT,
1351 .audio_chip = AUDIO_CHIP_WM8775, 1351 .audio_chip = V4L2_IDENT_WM8775,
1352 .input = {{ 1352 .input = {{
1353 .type = CX88_VMUX_TELEVISION, 1353 .type = CX88_VMUX_TELEVISION,
1354 .vmux = 0, 1354 .vmux = 0,
diff --git a/drivers/media/video/cx88/cx88-core.c b/drivers/media/video/cx88/cx88-core.c
index 60eeda3057e9..d656fec59010 100644
--- a/drivers/media/video/cx88/cx88-core.c
+++ b/drivers/media/video/cx88/cx88-core.c
@@ -40,6 +40,7 @@
40 40
41#include "cx88.h" 41#include "cx88.h"
42#include <media/v4l2-common.h> 42#include <media/v4l2-common.h>
43#include <media/v4l2-ioctl.h>
43 44
44MODULE_DESCRIPTION("v4l2 driver module for cx2388x based TV cards"); 45MODULE_DESCRIPTION("v4l2 driver module for cx2388x based TV cards");
45MODULE_AUTHOR("Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]"); 46MODULE_AUTHOR("Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]");
@@ -1006,7 +1007,7 @@ struct video_device *cx88_vdev_init(struct cx88_core *core,
1006 return NULL; 1007 return NULL;
1007 *vfd = *template; 1008 *vfd = *template;
1008 vfd->minor = -1; 1009 vfd->minor = -1;
1009 vfd->dev = &pci->dev; 1010 vfd->parent = &pci->dev;
1010 vfd->release = video_device_release; 1011 vfd->release = video_device_release;
1011 snprintf(vfd->name, sizeof(vfd->name), "%s %s (%s)", 1012 snprintf(vfd->name, sizeof(vfd->name), "%s %s (%s)",
1012 core->name, type, core->board.name); 1013 core->name, type, core->board.name);
diff --git a/drivers/media/video/cx88/cx88-video.c b/drivers/media/video/cx88/cx88-video.c
index 0fed5cd2ccea..ef4d56ea0027 100644
--- a/drivers/media/video/cx88/cx88-video.c
+++ b/drivers/media/video/cx88/cx88-video.c
@@ -39,6 +39,7 @@
39 39
40#include "cx88.h" 40#include "cx88.h"
41#include <media/v4l2-common.h> 41#include <media/v4l2-common.h>
42#include <media/v4l2-ioctl.h>
42 43
43#ifdef CONFIG_VIDEO_V4L1_COMPAT 44#ifdef CONFIG_VIDEO_V4L1_COMPAT
44/* Include V4L1 specific functions. Should be removed soon */ 45/* Include V4L1 specific functions. Should be removed soon */
@@ -447,7 +448,7 @@ int cx88_video_mux(struct cx88_core *core, unsigned int input)
447 the initialization. Some boards may use different 448 the initialization. Some boards may use different
448 routes for different inputs. HVR-1300 surely does */ 449 routes for different inputs. HVR-1300 surely does */
449 if (core->board.audio_chip && 450 if (core->board.audio_chip &&
450 core->board.audio_chip == AUDIO_CHIP_WM8775) { 451 core->board.audio_chip == V4L2_IDENT_WM8775) {
451 struct v4l2_routing route; 452 struct v4l2_routing route;
452 453
453 route.input = INPUT(input).audioroute; 454 route.input = INPUT(input).audioroute;
@@ -1682,13 +1683,7 @@ static const struct file_operations video_fops =
1682 .llseek = no_llseek, 1683 .llseek = no_llseek,
1683}; 1684};
1684 1685
1685static struct video_device cx8800_vbi_template; 1686static const struct v4l2_ioctl_ops video_ioctl_ops = {
1686static struct video_device cx8800_video_template =
1687{
1688 .name = "cx8800-video",
1689 .type = VID_TYPE_CAPTURE|VID_TYPE_TUNER|VID_TYPE_SCALES,
1690 .fops = &video_fops,
1691 .minor = -1,
1692 .vidioc_querycap = vidioc_querycap, 1687 .vidioc_querycap = vidioc_querycap,
1693 .vidioc_enum_fmt_vid_cap = vidioc_enum_fmt_vid_cap, 1688 .vidioc_enum_fmt_vid_cap = vidioc_enum_fmt_vid_cap,
1694 .vidioc_g_fmt_vid_cap = vidioc_g_fmt_vid_cap, 1689 .vidioc_g_fmt_vid_cap = vidioc_g_fmt_vid_cap,
@@ -1721,6 +1716,15 @@ static struct video_device cx8800_video_template =
1721 .vidioc_g_register = vidioc_g_register, 1716 .vidioc_g_register = vidioc_g_register,
1722 .vidioc_s_register = vidioc_s_register, 1717 .vidioc_s_register = vidioc_s_register,
1723#endif 1718#endif
1719};
1720
1721static struct video_device cx8800_vbi_template;
1722
1723static struct video_device cx8800_video_template = {
1724 .name = "cx8800-video",
1725 .fops = &video_fops,
1726 .minor = -1,
1727 .ioctl_ops = &video_ioctl_ops,
1724 .tvnorms = CX88_NORMS, 1728 .tvnorms = CX88_NORMS,
1725 .current_norm = V4L2_STD_NTSC_M, 1729 .current_norm = V4L2_STD_NTSC_M,
1726}; 1730};
@@ -1735,12 +1739,7 @@ static const struct file_operations radio_fops =
1735 .llseek = no_llseek, 1739 .llseek = no_llseek,
1736}; 1740};
1737 1741
1738static struct video_device cx8800_radio_template = 1742static const struct v4l2_ioctl_ops radio_ioctl_ops = {
1739{
1740 .name = "cx8800-radio",
1741 .type = VID_TYPE_TUNER,
1742 .fops = &radio_fops,
1743 .minor = -1,
1744 .vidioc_querycap = radio_querycap, 1743 .vidioc_querycap = radio_querycap,
1745 .vidioc_g_tuner = radio_g_tuner, 1744 .vidioc_g_tuner = radio_g_tuner,
1746 .vidioc_enum_input = radio_enum_input, 1745 .vidioc_enum_input = radio_enum_input,
@@ -1759,6 +1758,13 @@ static struct video_device cx8800_radio_template =
1759#endif 1758#endif
1760}; 1759};
1761 1760
1761static struct video_device cx8800_radio_template = {
1762 .name = "cx8800-radio",
1763 .fops = &radio_fops,
1764 .minor = -1,
1765 .ioctl_ops = &radio_ioctl_ops,
1766};
1767
1762/* ----------------------------------------------------------- */ 1768/* ----------------------------------------------------------- */
1763 1769
1764static void cx8800_unregister_video(struct cx8800_dev *dev) 1770static void cx8800_unregister_video(struct cx8800_dev *dev)
@@ -1830,7 +1836,6 @@ static int __devinit cx8800_initdev(struct pci_dev *pci_dev,
1830 memcpy( &cx8800_vbi_template, &cx8800_video_template, 1836 memcpy( &cx8800_vbi_template, &cx8800_video_template,
1831 sizeof(cx8800_vbi_template) ); 1837 sizeof(cx8800_vbi_template) );
1832 strcpy(cx8800_vbi_template.name,"cx8800-vbi"); 1838 strcpy(cx8800_vbi_template.name,"cx8800-vbi");
1833 cx8800_vbi_template.type = VID_TYPE_TELETEXT|VID_TYPE_TUNER;
1834 1839
1835 /* initialize driver struct */ 1840 /* initialize driver struct */
1836 spin_lock_init(&dev->slock); 1841 spin_lock_init(&dev->slock);
@@ -1866,7 +1871,7 @@ static int __devinit cx8800_initdev(struct pci_dev *pci_dev,
1866 1871
1867 /* load and configure helper modules */ 1872 /* load and configure helper modules */
1868 1873
1869 if (core->board.audio_chip == AUDIO_CHIP_WM8775) 1874 if (core->board.audio_chip == V4L2_IDENT_WM8775)
1870 request_module("wm8775"); 1875 request_module("wm8775");
1871 1876
1872 switch (core->boardnr) { 1877 switch (core->boardnr) {
diff --git a/drivers/media/video/cx88/cx88.h b/drivers/media/video/cx88/cx88.h
index 14ac173f4071..54fe65094711 100644
--- a/drivers/media/video/cx88/cx88.h
+++ b/drivers/media/video/cx88/cx88.h
@@ -29,8 +29,8 @@
29#include <media/tuner.h> 29#include <media/tuner.h>
30#include <media/tveeprom.h> 30#include <media/tveeprom.h>
31#include <media/videobuf-dma-sg.h> 31#include <media/videobuf-dma-sg.h>
32#include <media/v4l2-chip-ident.h>
32#include <media/cx2341x.h> 33#include <media/cx2341x.h>
33#include <media/audiochip.h>
34#if defined(CONFIG_VIDEO_CX88_DVB) || defined(CONFIG_VIDEO_CX88_DVB_MODULE) 34#if defined(CONFIG_VIDEO_CX88_DVB) || defined(CONFIG_VIDEO_CX88_DVB_MODULE)
35#include <media/videobuf-dvb.h> 35#include <media/videobuf-dvb.h>
36#endif 36#endif
@@ -252,7 +252,7 @@ struct cx88_board {
252 struct cx88_input input[MAX_CX88_INPUT]; 252 struct cx88_input input[MAX_CX88_INPUT];
253 struct cx88_input radio; 253 struct cx88_input radio;
254 enum cx88_board_type mpeg; 254 enum cx88_board_type mpeg;
255 enum audiochip audio_chip; 255 unsigned int audio_chip;
256}; 256};
257 257
258struct cx88_subid { 258struct cx88_subid {
diff --git a/drivers/media/video/em28xx/em28xx-cards.c b/drivers/media/video/em28xx/em28xx-cards.c
index 05f0d5a15058..476ae44a62d2 100644
--- a/drivers/media/video/em28xx/em28xx-cards.c
+++ b/drivers/media/video/em28xx/em28xx-cards.c
@@ -32,8 +32,8 @@
32#include <media/saa7115.h> 32#include <media/saa7115.h>
33#include <media/tvp5150.h> 33#include <media/tvp5150.h>
34#include <media/tveeprom.h> 34#include <media/tveeprom.h>
35#include <media/audiochip.h>
36#include <media/v4l2-common.h> 35#include <media/v4l2-common.h>
36#include <media/v4l2-chip-ident.h>
37 37
38#include "em28xx.h" 38#include "em28xx.h"
39 39
@@ -52,6 +52,15 @@ struct em28xx_hash_table {
52}; 52};
53 53
54struct em28xx_board em28xx_boards[] = { 54struct em28xx_board em28xx_boards[] = {
55 [EM2750_BOARD_UNKNOWN] = {
56 .name = "Unknown EM2750/EM2751 webcam grabber",
57 .vchannels = 1,
58 .input = { {
59 .type = EM28XX_VMUX_COMPOSITE1,
60 .vmux = 0,
61 .amux = 0,
62 } },
63 },
55 [EM2800_BOARD_UNKNOWN] = { 64 [EM2800_BOARD_UNKNOWN] = {
56 .name = "Unknown EM2800 video grabber", 65 .name = "Unknown EM2800 video grabber",
57 .is_em2800 = 1, 66 .is_em2800 = 1,
@@ -73,6 +82,39 @@ struct em28xx_board em28xx_boards[] = {
73 .is_em2800 = 0, 82 .is_em2800 = 0,
74 .tuner_type = TUNER_ABSENT, 83 .tuner_type = TUNER_ABSENT,
75 }, 84 },
85 [EM2750_BOARD_DLCW_130] = {
86 /* Beijing Huaqi Information Digital Technology Co., Ltd */
87 .name = "Huaqi DLCW-130",
88 .valid = EM28XX_BOARD_NOT_VALIDATED,
89 .vchannels = 1,
90 .input = { {
91 .type = EM28XX_VMUX_COMPOSITE1,
92 .vmux = 0,
93 .amux = 0,
94 } },
95 },
96 [EM2800_BOARD_KWORLD_USB2800] = {
97 .name = "Kworld USB2800",
98 .valid = EM28XX_BOARD_NOT_VALIDATED,
99 .is_em2800 = 1,
100 .vchannels = 3,
101 .tuner_type = TUNER_PHILIPS_FCV1236D,
102 .tda9887_conf = TDA9887_PRESENT,
103 .decoder = EM28XX_SAA7113,
104 .input = { {
105 .type = EM28XX_VMUX_TELEVISION,
106 .vmux = SAA7115_COMPOSITE2,
107 .amux = 0,
108 }, {
109 .type = EM28XX_VMUX_COMPOSITE1,
110 .vmux = SAA7115_COMPOSITE0,
111 .amux = 1,
112 }, {
113 .type = EM28XX_VMUX_SVIDEO,
114 .vmux = SAA7115_SVIDEO3,
115 .amux = 1,
116 } },
117 },
76 [EM2820_BOARD_KWORLD_PVRTV2800RF] = { 118 [EM2820_BOARD_KWORLD_PVRTV2800RF] = {
77 .name = "Kworld PVR TV 2800 RF", 119 .name = "Kworld PVR TV 2800 RF",
78 .is_em2800 = 0, 120 .is_em2800 = 0,
@@ -151,6 +193,376 @@ struct em28xx_board em28xx_boards[] = {
151 MSP_DSP_IN_SCART, MSP_DSP_IN_SCART), 193 MSP_DSP_IN_SCART, MSP_DSP_IN_SCART),
152 } }, 194 } },
153 }, 195 },
196 [EM2820_BOARD_DLINK_USB_TV] = {
197 .name = "D-Link DUB-T210 TV Tuner",
198 .valid = EM28XX_BOARD_NOT_VALIDATED,
199 .vchannels = 3,
200 .is_em2800 = 0,
201 .tuner_type = TUNER_LG_PAL_NEW_TAPC,
202 .tda9887_conf = TDA9887_PRESENT,
203 .decoder = EM28XX_SAA7113,
204 .input = { {
205 .type = EM28XX_VMUX_TELEVISION,
206 .vmux = SAA7115_COMPOSITE2,
207 .amux = 1,
208 }, {
209 .type = EM28XX_VMUX_COMPOSITE1,
210 .vmux = SAA7115_COMPOSITE0,
211 .amux = 1,
212 }, {
213 .type = EM28XX_VMUX_SVIDEO,
214 .vmux = SAA7115_SVIDEO3,
215 .amux = 1,
216 } },
217 },
218 [EM2820_BOARD_HERCULES_SMART_TV_USB2] = {
219 .name = "Hercules Smart TV USB 2.0",
220 .valid = EM28XX_BOARD_NOT_VALIDATED,
221 .vchannels = 3,
222 .tuner_type = TUNER_LG_PAL_NEW_TAPC,
223 .tda9887_conf = TDA9887_PRESENT,
224 .decoder = EM28XX_SAA7113,
225 .input = { {
226 .type = EM28XX_VMUX_TELEVISION,
227 .vmux = SAA7115_COMPOSITE2,
228 .amux = 1,
229 }, {
230 .type = EM28XX_VMUX_COMPOSITE1,
231 .vmux = SAA7115_COMPOSITE0,
232 .amux = 1,
233 }, {
234 .type = EM28XX_VMUX_SVIDEO,
235 .vmux = SAA7115_SVIDEO3,
236 .amux = 1,
237 } },
238 },
239 [EM2820_BOARD_PINNACLE_USB_2_FM1216ME] = {
240 .name = "Pinnacle PCTV USB 2 (Philips FM1216ME)",
241 .valid = EM28XX_BOARD_NOT_VALIDATED,
242 .vchannels = 3,
243 .is_em2800 = 0,
244 .tuner_type = TUNER_PHILIPS_FM1216ME_MK3,
245 .tda9887_conf = TDA9887_PRESENT,
246 .decoder = EM28XX_SAA7113,
247 .input = { {
248 .type = EM28XX_VMUX_TELEVISION,
249 .vmux = SAA7115_COMPOSITE2,
250 .amux = 0,
251 }, {
252 .type = EM28XX_VMUX_COMPOSITE1,
253 .vmux = SAA7115_COMPOSITE0,
254 .amux = 1,
255 }, {
256 .type = EM28XX_VMUX_SVIDEO,
257 .vmux = SAA7115_SVIDEO3,
258 .amux = 1,
259 } },
260 },
261 [EM2820_BOARD_GADMEI_UTV310] = {
262 .name = "Gadmei UTV310",
263 .valid = EM28XX_BOARD_NOT_VALIDATED,
264 .vchannels = 3,
265 .tuner_type = TUNER_TNF_5335MF,
266 .tda9887_conf = TDA9887_PRESENT,
267 .decoder = EM28XX_SAA7113,
268 .input = { {
269 .type = EM28XX_VMUX_TELEVISION,
270 .vmux = SAA7115_COMPOSITE1,
271 .amux = 1,
272 }, {
273 .type = EM28XX_VMUX_COMPOSITE1,
274 .vmux = SAA7115_COMPOSITE0,
275 .amux = 1,
276 }, {
277 .type = EM28XX_VMUX_SVIDEO,
278 .vmux = SAA7115_SVIDEO3,
279 .amux = 1,
280 } },
281 },
282 [EM2820_BOARD_LEADTEK_WINFAST_USBII_DELUXE] = {
283 .name = "Leadtek Winfast USB II Deluxe",
284 .valid = EM28XX_BOARD_NOT_VALIDATED,
285 .vchannels = 3,
286 .tuner_type = TUNER_PHILIPS_FM1216ME_MK3,
287 .tda9887_conf = TDA9887_PRESENT,
288 .decoder = EM28XX_SAA7114,
289 .input = { {
290 .type = EM28XX_VMUX_TELEVISION,
291 .vmux = 2,
292 .amux = 0,
293 }, {
294 .type = EM28XX_VMUX_COMPOSITE1,
295 .vmux = 0,
296 .amux = 1,
297 }, {
298 .type = EM28XX_VMUX_SVIDEO,
299 .vmux = 9,
300 .amux = 1,
301 } },
302 },
303 [EM2820_BOARD_PINNACLE_DVC_100] = {
304 .name = "Pinnacle Dazzle DVC 100",
305 .valid = EM28XX_BOARD_NOT_VALIDATED,
306 .vchannels = 3,
307 .decoder = EM28XX_SAA7113,
308 .input = { {
309 .type = EM28XX_VMUX_COMPOSITE1,
310 .vmux = SAA7115_COMPOSITE0,
311 .amux = 1,
312 }, {
313 .type = EM28XX_VMUX_SVIDEO,
314 .vmux = SAA7115_SVIDEO3,
315 .amux = 1,
316 } },
317 },
318 [EM2820_BOARD_VIDEOLOGY_20K14XUSB] = {
319 .name = "Videology 20K14XUSB USB2.0",
320 .valid = EM28XX_BOARD_NOT_VALIDATED,
321 .vchannels = 1,
322 .input = { {
323 .type = EM28XX_VMUX_COMPOSITE1,
324 .vmux = 0,
325 .amux = 0,
326 } },
327 },
328 [EM2821_BOARD_PROLINK_PLAYTV_USB2] = {
329 .name = "SIIG AVTuner-PVR/Prolink PlayTV USB 2.0",
330 .valid = EM28XX_BOARD_NOT_VALIDATED,
331 .vchannels = 3,
332 .is_em2800 = 0,
333 .tuner_type = TUNER_LG_PAL_NEW_TAPC, /* unknown? */
334 .tda9887_conf = TDA9887_PRESENT, /* unknown? */
335 .decoder = EM28XX_SAA7113,
336 .input = { {
337 .type = EM28XX_VMUX_TELEVISION,
338 .vmux = SAA7115_COMPOSITE2,
339 .amux = 1,
340 }, {
341 .type = EM28XX_VMUX_COMPOSITE1,
342 .vmux = SAA7115_COMPOSITE0,
343 .amux = 1,
344 }, {
345 .type = EM28XX_VMUX_SVIDEO,
346 .vmux = SAA7115_SVIDEO3,
347 .amux = 1,
348 } },
349 },
350 [EM2821_BOARD_SUPERCOMP_USB_2] = {
351 .name = "Supercomp USB 2.0 TV",
352 .valid = EM28XX_BOARD_NOT_VALIDATED,
353 .vchannels = 3,
354 .is_em2800 = 0,
355 .tuner_type = TUNER_PHILIPS_FM1236_MK3,
356 .tda9887_conf = TDA9887_PRESENT |
357 TDA9887_PORT1_ACTIVE |
358 TDA9887_PORT2_ACTIVE,
359 .decoder = EM28XX_SAA7113,
360 .input = { {
361 .type = EM28XX_VMUX_TELEVISION,
362 .vmux = SAA7115_COMPOSITE2,
363 .amux = 1,
364 }, {
365 .type = EM28XX_VMUX_COMPOSITE1,
366 .vmux = SAA7115_COMPOSITE0,
367 .amux = 0,
368 }, {
369 .type = EM28XX_VMUX_SVIDEO,
370 .vmux = SAA7115_SVIDEO3,
371 .amux = 1,
372 } },
373 },
374 [EM2821_BOARD_USBGEAR_VD204] = {
375 .name = "Usbgear VD204v9",
376 .valid = EM28XX_BOARD_NOT_VALIDATED,
377 .vchannels = 2,
378 .decoder = EM28XX_SAA7113,
379 .input = { {
380 .type = EM28XX_VMUX_COMPOSITE1,
381 .vmux = SAA7115_COMPOSITE0,
382 .amux = 1,
383 }, {
384 .type = EM28XX_VMUX_SVIDEO,
385 .vmux = SAA7115_SVIDEO3,
386 .amux = 1,
387 } },
388 },
389 [EM2860_BOARD_NETGMBH_CAM] = {
390 /* Beijing Huaqi Information Digital Technology Co., Ltd */
391 .name = "NetGMBH Cam",
392 .valid = EM28XX_BOARD_NOT_VALIDATED,
393 .vchannels = 1,
394 .input = { {
395 .type = EM28XX_VMUX_COMPOSITE1,
396 .vmux = 0,
397 .amux = 0,
398 } },
399 },
400 [EM2860_BOARD_TYPHOON_DVD_MAKER] = {
401 .name = "Typhoon DVD Maker",
402 .valid = EM28XX_BOARD_NOT_VALIDATED,
403 .vchannels = 2,
404 .decoder = EM28XX_SAA7113,
405 .input = { {
406 .type = EM28XX_VMUX_COMPOSITE1,
407 .vmux = SAA7115_COMPOSITE0,
408 .amux = 1,
409 }, {
410 .type = EM28XX_VMUX_SVIDEO,
411 .vmux = SAA7115_SVIDEO3,
412 .amux = 1,
413 } },
414 },
415 [EM2860_BOARD_GADMEI_UTV330] = {
416 .name = "Gadmei UTV330",
417 .valid = EM28XX_BOARD_NOT_VALIDATED,
418 .vchannels = 3,
419 .tuner_type = TUNER_TNF_5335MF,
420 .tda9887_conf = TDA9887_PRESENT,
421 .decoder = EM28XX_SAA7113,
422 .input = { {
423 .type = EM28XX_VMUX_TELEVISION,
424 .vmux = SAA7115_COMPOSITE2,
425 .amux = 0,
426 }, {
427 .type = EM28XX_VMUX_COMPOSITE1,
428 .vmux = SAA7115_COMPOSITE0,
429 .amux = 1,
430 }, {
431 .type = EM28XX_VMUX_SVIDEO,
432 .vmux = SAA7115_SVIDEO3,
433 .amux = 1,
434 } },
435 },
436 [EM2860_BOARD_TERRATEC_HYBRID_XS] = {
437 .name = "Terratec Cinergy A Hybrid XS",
438 .valid = EM28XX_BOARD_NOT_VALIDATED,
439 .vchannels = 3,
440 .tuner_type = TUNER_XC2028,
441 .decoder = EM28XX_TVP5150,
442 .input = { {
443 .type = EM28XX_VMUX_TELEVISION,
444 .vmux = TVP5150_COMPOSITE0,
445 .amux = 0,
446 }, {
447 .type = EM28XX_VMUX_COMPOSITE1,
448 .vmux = TVP5150_COMPOSITE1,
449 .amux = 1,
450 }, {
451 .type = EM28XX_VMUX_SVIDEO,
452 .vmux = TVP5150_SVIDEO,
453 .amux = 1,
454 } },
455 },
456 [EM2861_BOARD_KWORLD_PVRTV_300U] = {
457 .name = "KWorld PVRTV 300U",
458 .valid = EM28XX_BOARD_NOT_VALIDATED,
459 .vchannels = 3,
460 .tuner_type = TUNER_XC2028,
461 .decoder = EM28XX_TVP5150,
462 .input = { {
463 .type = EM28XX_VMUX_TELEVISION,
464 .vmux = TVP5150_COMPOSITE0,
465 .amux = 0,
466 }, {
467 .type = EM28XX_VMUX_COMPOSITE1,
468 .vmux = TVP5150_COMPOSITE1,
469 .amux = 1,
470 }, {
471 .type = EM28XX_VMUX_SVIDEO,
472 .vmux = TVP5150_SVIDEO,
473 .amux = 1,
474 } },
475 },
476 [EM2861_BOARD_YAKUMO_MOVIE_MIXER] = {
477 .name = "Yakumo MovieMixer",
478 .valid = EM28XX_BOARD_NOT_VALIDATED,
479 .vchannels = 1,
480 .decoder = EM28XX_TVP5150,
481 .input = { {
482 .type = EM28XX_VMUX_TELEVISION,
483 .vmux = TVP5150_COMPOSITE0,
484 .amux = 0,
485 }, {
486 .type = EM28XX_VMUX_COMPOSITE1,
487 .vmux = TVP5150_COMPOSITE1,
488 .amux = 1,
489 }, {
490 .type = EM28XX_VMUX_SVIDEO,
491 .vmux = TVP5150_SVIDEO,
492 .amux = 1,
493 } },
494 },
495 [EM2861_BOARD_PLEXTOR_PX_TV100U] = {
496 .name = "Plextor ConvertX PX-TV100U",
497 .valid = EM28XX_BOARD_NOT_VALIDATED,
498 .vchannels = 3,
499 .tuner_type = TUNER_TNF_5335MF,
500 .tda9887_conf = TDA9887_PRESENT,
501 .decoder = EM28XX_TVP5150,
502 .input = { {
503 .type = EM28XX_VMUX_TELEVISION,
504 .vmux = TVP5150_COMPOSITE0,
505 .amux = 1,
506 }, {
507 .type = EM28XX_VMUX_COMPOSITE1,
508 .vmux = TVP5150_COMPOSITE1,
509 .amux = 1,
510 }, {
511 .type = EM28XX_VMUX_SVIDEO,
512 .vmux = TVP5150_SVIDEO,
513 .amux = 1,
514 } },
515 },
516 [EM2870_BOARD_TERRATEC_XS] = {
517 .name = "Terratec Cinergy T XS",
518 .valid = EM28XX_BOARD_NOT_VALIDATED,
519 .tuner_type = TUNER_XC2028,
520 },
521 [EM2870_BOARD_TERRATEC_XS_MT2060] = {
522 .name = "Terratec Cinergy T XS (MT2060)",
523 .valid = EM28XX_BOARD_NOT_VALIDATED,
524 .tuner_type = TUNER_ABSENT, /* MT2060 */
525 },
526 [EM2870_BOARD_KWORLD_350U] = {
527 .name = "Kworld 350 U DVB-T",
528 .valid = EM28XX_BOARD_NOT_VALIDATED,
529 .tuner_type = TUNER_XC2028,
530 },
531 [EM2870_BOARD_KWORLD_355U] = {
532 .name = "Kworld 355 U DVB-T",
533 .valid = EM28XX_BOARD_NOT_VALIDATED,
534 },
535 [EM2870_BOARD_PINNACLE_PCTV_DVB] = {
536 .name = "Pinnacle PCTV DVB-T",
537 .valid = EM28XX_BOARD_NOT_VALIDATED,
538 .tuner_type = TUNER_ABSENT, /* MT2060 */
539 },
540 [EM2870_BOARD_COMPRO_VIDEOMATE] = {
541 .name = "Compro, VideoMate U3",
542 .valid = EM28XX_BOARD_NOT_VALIDATED,
543 .tuner_type = TUNER_ABSENT, /* MT2060 */
544 },
545 [EM2880_BOARD_TERRATEC_HYBRID_XS_FR] = {
546 .name = "Terratec Hybrid XS Secam",
547 .valid = EM28XX_BOARD_NOT_VALIDATED,
548 .vchannels = 3,
549 .has_msp34xx = 1,
550 .tuner_type = TUNER_XC2028,
551 .decoder = EM28XX_TVP5150,
552 .input = { {
553 .type = EM28XX_VMUX_TELEVISION,
554 .vmux = TVP5150_COMPOSITE0,
555 .amux = 0,
556 }, {
557 .type = EM28XX_VMUX_COMPOSITE1,
558 .vmux = TVP5150_COMPOSITE1,
559 .amux = 1,
560 }, {
561 .type = EM28XX_VMUX_SVIDEO,
562 .vmux = TVP5150_SVIDEO,
563 .amux = 1,
564 } },
565 },
154 [EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900] = { 566 [EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900] = {
155 .name = "Hauppauge WinTV HVR 900", 567 .name = "Hauppauge WinTV HVR 900",
156 .vchannels = 3, 568 .vchannels = 3,
@@ -194,7 +606,7 @@ struct em28xx_board em28xx_boards[] = {
194 .amux = 1, 606 .amux = 1,
195 } }, 607 } },
196 }, 608 },
197 [EM2880_BOARD_HAUPPAUGE_WINTV_HVR_950] = { 609 [EM2883_BOARD_HAUPPAUGE_WINTV_HVR_950] = {
198 .name = "Hauppauge WinTV HVR 950", 610 .name = "Hauppauge WinTV HVR 950",
199 .vchannels = 3, 611 .vchannels = 3,
200 .tda9887_conf = TDA9887_PRESENT, 612 .tda9887_conf = TDA9887_PRESENT,
@@ -240,12 +652,36 @@ struct em28xx_board em28xx_boards[] = {
240 .amux = 1, 652 .amux = 1,
241 } }, 653 } },
242 }, 654 },
655 [EM2880_BOARD_AMD_ATI_TV_WONDER_HD_600] = {
656 .name = "AMD ATI TV Wonder HD 600",
657 .vchannels = 3,
658 .tda9887_conf = TDA9887_PRESENT,
659 .tuner_type = TUNER_XC2028,
660 .mts_firmware = 1,
661 .has_12mhz_i2s = 1,
662 .has_dvb = 1,
663 .decoder = EM28XX_TVP5150,
664 .input = { {
665 .type = EM28XX_VMUX_TELEVISION,
666 .vmux = TVP5150_COMPOSITE0,
667 .amux = 0,
668 }, {
669 .type = EM28XX_VMUX_COMPOSITE1,
670 .vmux = TVP5150_COMPOSITE1,
671 .amux = 1,
672 }, {
673 .type = EM28XX_VMUX_SVIDEO,
674 .vmux = TVP5150_SVIDEO,
675 .amux = 1,
676 } },
677 },
243 [EM2880_BOARD_TERRATEC_HYBRID_XS] = { 678 [EM2880_BOARD_TERRATEC_HYBRID_XS] = {
244 .name = "Terratec Hybrid XS", 679 .name = "Terratec Hybrid XS",
245 .vchannels = 3, 680 .vchannels = 3,
246 .tda9887_conf = TDA9887_PRESENT, 681 .tda9887_conf = TDA9887_PRESENT,
247 .tuner_type = TUNER_XC2028, 682 .tuner_type = TUNER_XC2028,
248 .decoder = EM28XX_TVP5150, 683 .decoder = EM28XX_TVP5150,
684 .has_dvb = 1,
249 .input = { { 685 .input = { {
250 .type = EM28XX_VMUX_TELEVISION, 686 .type = EM28XX_VMUX_TELEVISION,
251 .vmux = TVP5150_COMPOSITE0, 687 .vmux = TVP5150_COMPOSITE0,
@@ -328,6 +764,21 @@ struct em28xx_board em28xx_boards[] = {
328 .amux = 1, 764 .amux = 1,
329 } }, 765 } },
330 }, 766 },
767 [EM2800_BOARD_GRABBEEX_USB2800] = {
768 .name = "eMPIA Technology, Inc. GrabBeeX+ Video Encoder",
769 .is_em2800 = 1,
770 .vchannels = 2,
771 .decoder = EM28XX_SAA7113,
772 .input = { {
773 .type = EM28XX_VMUX_COMPOSITE1,
774 .vmux = SAA7115_COMPOSITE0,
775 .amux = 1,
776 }, {
777 .type = EM28XX_VMUX_SVIDEO,
778 .vmux = SAA7115_SVIDEO3,
779 .amux = 1,
780 } },
781 },
331 [EM2800_BOARD_LEADTEK_WINFAST_USBII] = { 782 [EM2800_BOARD_LEADTEK_WINFAST_USBII] = {
332 .name = "Leadtek Winfast USB II", 783 .name = "Leadtek Winfast USB II",
333 .is_em2800 = 1, 784 .is_em2800 = 1,
@@ -439,13 +890,232 @@ struct em28xx_board em28xx_boards[] = {
439 .amux = 0, 890 .amux = 0,
440 } }, 891 } },
441 }, 892 },
893 [EM2880_BOARD_MSI_DIGIVOX_AD] = {
894 .name = "MSI DigiVox A/D",
895 .valid = EM28XX_BOARD_NOT_VALIDATED,
896 .vchannels = 3,
897 .tuner_type = TUNER_XC2028,
898 .decoder = EM28XX_TVP5150,
899 .input = { {
900 .type = EM28XX_VMUX_TELEVISION,
901 .vmux = TVP5150_COMPOSITE0,
902 .amux = 0,
903 }, {
904 .type = EM28XX_VMUX_COMPOSITE1,
905 .vmux = TVP5150_COMPOSITE1,
906 .amux = 1,
907 }, {
908 .type = EM28XX_VMUX_SVIDEO,
909 .vmux = TVP5150_SVIDEO,
910 .amux = 1,
911 } },
912 },
913 [EM2880_BOARD_MSI_DIGIVOX_AD_II] = {
914 .name = "MSI DigiVox A/D II",
915 .valid = EM28XX_BOARD_NOT_VALIDATED,
916 .vchannels = 3,
917 .tuner_type = TUNER_XC2028,
918 .decoder = EM28XX_TVP5150,
919 .input = { {
920 .type = EM28XX_VMUX_TELEVISION,
921 .vmux = TVP5150_COMPOSITE0,
922 .amux = 0,
923 }, {
924 .type = EM28XX_VMUX_COMPOSITE1,
925 .vmux = TVP5150_COMPOSITE1,
926 .amux = 1,
927 }, {
928 .type = EM28XX_VMUX_SVIDEO,
929 .vmux = TVP5150_SVIDEO,
930 .amux = 1,
931 } },
932 },
933 [EM2880_BOARD_KWORLD_DVB_305U] = {
934 .name = "KWorld DVB-T 305U",
935 .valid = EM28XX_BOARD_NOT_VALIDATED,
936 .vchannels = 3,
937 .tuner_type = TUNER_XC2028,
938 .decoder = EM28XX_TVP5150,
939 .input = { {
940 .type = EM28XX_VMUX_TELEVISION,
941 .vmux = TVP5150_COMPOSITE0,
942 .amux = 0,
943 }, {
944 .type = EM28XX_VMUX_COMPOSITE1,
945 .vmux = TVP5150_COMPOSITE1,
946 .amux = 1,
947 }, {
948 .type = EM28XX_VMUX_SVIDEO,
949 .vmux = TVP5150_SVIDEO,
950 .amux = 1,
951 } },
952 },
953 [EM2880_BOARD_KWORLD_DVB_310U] = {
954 .name = "KWorld DVB-T 310U",
955 .valid = EM28XX_BOARD_NOT_VALIDATED,
956 .vchannels = 3,
957 .tuner_type = TUNER_XC2028,
958 .decoder = EM28XX_TVP5150,
959 .input = { {
960 .type = EM28XX_VMUX_TELEVISION,
961 .vmux = TVP5150_COMPOSITE0,
962 .amux = 0,
963 }, {
964 .type = EM28XX_VMUX_COMPOSITE1,
965 .vmux = TVP5150_COMPOSITE1,
966 .amux = 1,
967 }, {
968 .type = EM28XX_VMUX_SVIDEO,
969 .vmux = TVP5150_SVIDEO,
970 .amux = 1,
971 } },
972 },
973 [EM2881_BOARD_DNT_DA2_HYBRID] = {
974 .name = "DNT DA2 Hybrid",
975 .valid = EM28XX_BOARD_NOT_VALIDATED,
976 .vchannels = 3,
977 .tuner_type = TUNER_XC2028,
978 .decoder = EM28XX_TVP5150,
979 .input = { {
980 .type = EM28XX_VMUX_TELEVISION,
981 .vmux = TVP5150_COMPOSITE0,
982 .amux = 0,
983 }, {
984 .type = EM28XX_VMUX_COMPOSITE1,
985 .vmux = TVP5150_COMPOSITE1,
986 .amux = 1,
987 }, {
988 .type = EM28XX_VMUX_SVIDEO,
989 .vmux = TVP5150_SVIDEO,
990 .amux = 1,
991 } },
992 },
993 [EM2881_BOARD_PINNACLE_HYBRID_PRO] = {
994 .name = "Pinnacle Hybrid Pro",
995 .valid = EM28XX_BOARD_NOT_VALIDATED,
996 .vchannels = 3,
997 .tuner_type = TUNER_XC2028,
998 .decoder = EM28XX_TVP5150,
999 .input = { {
1000 .type = EM28XX_VMUX_TELEVISION,
1001 .vmux = TVP5150_COMPOSITE0,
1002 .amux = 0,
1003 }, {
1004 .type = EM28XX_VMUX_COMPOSITE1,
1005 .vmux = TVP5150_COMPOSITE1,
1006 .amux = 1,
1007 }, {
1008 .type = EM28XX_VMUX_SVIDEO,
1009 .vmux = TVP5150_SVIDEO,
1010 .amux = 1,
1011 } },
1012 },
1013 [EM2882_BOARD_PINNACLE_HYBRID_PRO] = {
1014 .name = "Pinnacle Hybrid Pro (2)",
1015 .valid = EM28XX_BOARD_NOT_VALIDATED,
1016 .vchannels = 3,
1017 .tuner_type = TUNER_XC2028,
1018 .decoder = EM28XX_TVP5150,
1019 .input = { {
1020 .type = EM28XX_VMUX_TELEVISION,
1021 .vmux = TVP5150_COMPOSITE0,
1022 .amux = 0,
1023 }, {
1024 .type = EM28XX_VMUX_COMPOSITE1,
1025 .vmux = TVP5150_COMPOSITE1,
1026 .amux = 1,
1027 }, {
1028 .type = EM28XX_VMUX_SVIDEO,
1029 .vmux = TVP5150_SVIDEO,
1030 .amux = 1,
1031 } },
1032 },
1033 [EM2882_BOARD_KWORLD_VS_DVBT] = {
1034 .name = "Kworld VS-DVB-T 323UR",
1035 .valid = EM28XX_BOARD_NOT_VALIDATED,
1036 .vchannels = 3,
1037 .tuner_type = TUNER_XC2028,
1038 .decoder = EM28XX_TVP5150,
1039 .input = { {
1040 .type = EM28XX_VMUX_TELEVISION,
1041 .vmux = TVP5150_COMPOSITE0,
1042 .amux = 0,
1043 }, {
1044 .type = EM28XX_VMUX_COMPOSITE1,
1045 .vmux = TVP5150_COMPOSITE1,
1046 .amux = 1,
1047 }, {
1048 .type = EM28XX_VMUX_SVIDEO,
1049 .vmux = TVP5150_SVIDEO,
1050 .amux = 1,
1051 } },
1052 },
1053 [EM2882_BOARD_TERRATEC_HYBRID_XS] = {
1054 .name = "Terratec Hybrid XS (em2882)",
1055 .valid = EM28XX_BOARD_NOT_VALIDATED,
1056 .vchannels = 3,
1057 .tuner_type = TUNER_XC2028,
1058 .decoder = EM28XX_TVP5150,
1059 .input = { {
1060 .type = EM28XX_VMUX_TELEVISION,
1061 .vmux = TVP5150_COMPOSITE0,
1062 .amux = 0,
1063 }, {
1064 .type = EM28XX_VMUX_COMPOSITE1,
1065 .vmux = TVP5150_COMPOSITE1,
1066 .amux = 1,
1067 }, {
1068 .type = EM28XX_VMUX_SVIDEO,
1069 .vmux = TVP5150_SVIDEO,
1070 .amux = 1,
1071 } },
1072 },
1073 [EM2883_BOARD_KWORLD_HYBRID_A316] = {
1074 .name = "Kworld PlusTV HD Hybrid 330",
1075 .valid = EM28XX_BOARD_NOT_VALIDATED,
1076 .vchannels = 3,
1077 .is_em2800 = 0,
1078 .tuner_type = TUNER_XC2028,
1079 .decoder = EM28XX_TVP5150,
1080 .input = { {
1081 .type = EM28XX_VMUX_TELEVISION,
1082 .vmux = TVP5150_COMPOSITE0,
1083 .amux = 0,
1084 }, {
1085 .type = EM28XX_VMUX_COMPOSITE1,
1086 .vmux = TVP5150_COMPOSITE1,
1087 .amux = 1,
1088 }, {
1089 .type = EM28XX_VMUX_SVIDEO,
1090 .vmux = TVP5150_SVIDEO,
1091 .amux = 1,
1092 } },
1093 },
1094 [EM2820_BOARD_COMPRO_VIDEOMATE_FORYOU] = {
1095 .name = "Compro VideoMate ForYou/Stereo",
1096 .vchannels = 2,
1097 .tuner_type = TUNER_LG_PAL_NEW_TAPC,
1098 .tda9887_conf = TDA9887_PRESENT,
1099 .decoder = EM28XX_TVP5150,
1100 .input = { {
1101 .type = EM28XX_VMUX_TELEVISION,
1102 .vmux = TVP5150_COMPOSITE0,
1103 .amux = EM28XX_AMUX_LINE_IN,
1104 }, {
1105 .type = EM28XX_VMUX_SVIDEO,
1106 .vmux = TVP5150_SVIDEO,
1107 .amux = EM28XX_AMUX_LINE_IN,
1108 } },
1109 },
442}; 1110};
443const unsigned int em28xx_bcount = ARRAY_SIZE(em28xx_boards); 1111const unsigned int em28xx_bcount = ARRAY_SIZE(em28xx_boards);
444 1112
445/* table of devices that work with this driver */ 1113/* table of devices that work with this driver */
446struct usb_device_id em28xx_id_table [] = { 1114struct usb_device_id em28xx_id_table [] = {
447 { USB_DEVICE(0xeb1a, 0x2750), 1115 { USB_DEVICE(0xeb1a, 0x2750),
448 .driver_info = EM2820_BOARD_UNKNOWN }, 1116 .driver_info = EM2750_BOARD_UNKNOWN },
1117 { USB_DEVICE(0xeb1a, 0x2751),
1118 .driver_info = EM2750_BOARD_UNKNOWN },
449 { USB_DEVICE(0xeb1a, 0x2800), 1119 { USB_DEVICE(0xeb1a, 0x2800),
450 .driver_info = EM2800_BOARD_UNKNOWN }, 1120 .driver_info = EM2800_BOARD_UNKNOWN },
451 { USB_DEVICE(0xeb1a, 0x2820), 1121 { USB_DEVICE(0xeb1a, 0x2820),
@@ -462,36 +1132,78 @@ struct usb_device_id em28xx_id_table [] = {
462 .driver_info = EM2820_BOARD_UNKNOWN }, 1132 .driver_info = EM2820_BOARD_UNKNOWN },
463 { USB_DEVICE(0xeb1a, 0x2883), 1133 { USB_DEVICE(0xeb1a, 0x2883),
464 .driver_info = EM2820_BOARD_UNKNOWN }, 1134 .driver_info = EM2820_BOARD_UNKNOWN },
1135 { USB_DEVICE(0xeb1a, 0xe300),
1136 .driver_info = EM2861_BOARD_KWORLD_PVRTV_300U },
1137 { USB_DEVICE(0xeb1a, 0xe305),
1138 .driver_info = EM2880_BOARD_KWORLD_DVB_305U },
1139 { USB_DEVICE(0xeb1a, 0xe310),
1140 .driver_info = EM2880_BOARD_MSI_DIGIVOX_AD },
1141 { USB_DEVICE(0xeb1a, 0xa316),
1142 .driver_info = EM2883_BOARD_KWORLD_HYBRID_A316 },
1143 { USB_DEVICE(0xeb1a, 0xe320),
1144 .driver_info = EM2880_BOARD_MSI_DIGIVOX_AD_II },
1145 { USB_DEVICE(0xeb1a, 0xe323),
1146 .driver_info = EM2882_BOARD_KWORLD_VS_DVBT },
1147 { USB_DEVICE(0xeb1a, 0xe350),
1148 .driver_info = EM2870_BOARD_KWORLD_350U },
1149 { USB_DEVICE(0xeb1a, 0xe355),
1150 .driver_info = EM2870_BOARD_KWORLD_355U },
1151 { USB_DEVICE(0xeb1a, 0x2801),
1152 .driver_info = EM2800_BOARD_GRABBEEX_USB2800 },
1153 { USB_DEVICE(0xeb1a, 0xe357),
1154 .driver_info = EM2870_BOARD_KWORLD_355U },
465 { USB_DEVICE(0x0ccd, 0x0036), 1155 { USB_DEVICE(0x0ccd, 0x0036),
466 .driver_info = EM2820_BOARD_TERRATEC_CINERGY_250 }, 1156 .driver_info = EM2820_BOARD_TERRATEC_CINERGY_250 },
467 { USB_DEVICE(0x2304, 0x0208), 1157 { USB_DEVICE(0x0ccd, 0x004c),
468 .driver_info = EM2820_BOARD_PINNACLE_USB_2 }, 1158 .driver_info = EM2880_BOARD_TERRATEC_HYBRID_XS_FR },
1159 { USB_DEVICE(0x0ccd, 0x004f),
1160 .driver_info = EM2860_BOARD_TERRATEC_HYBRID_XS },
1161 { USB_DEVICE(0x0ccd, 0x005e),
1162 .driver_info = EM2882_BOARD_TERRATEC_HYBRID_XS },
1163 { USB_DEVICE(0x0ccd, 0x0042),
1164 .driver_info = EM2880_BOARD_TERRATEC_HYBRID_XS },
1165 { USB_DEVICE(0x0ccd, 0x0043),
1166 .driver_info = EM2870_BOARD_TERRATEC_XS },
1167 { USB_DEVICE(0x0ccd, 0x0047),
1168 .driver_info = EM2880_BOARD_TERRATEC_PRODIGY_XS },
1169 { USB_DEVICE(0x185b, 0x2870),
1170 .driver_info = EM2870_BOARD_COMPRO_VIDEOMATE },
1171 { USB_DEVICE(0x185b, 0x2041),
1172 .driver_info = EM2820_BOARD_COMPRO_VIDEOMATE_FORYOU },
469 { USB_DEVICE(0x2040, 0x4200), 1173 { USB_DEVICE(0x2040, 0x4200),
470 .driver_info = EM2820_BOARD_HAUPPAUGE_WINTV_USB_2 }, 1174 .driver_info = EM2820_BOARD_HAUPPAUGE_WINTV_USB_2 },
471 { USB_DEVICE(0x2040, 0x4201), 1175 { USB_DEVICE(0x2040, 0x4201),
472 .driver_info = EM2820_BOARD_HAUPPAUGE_WINTV_USB_2 }, 1176 .driver_info = EM2820_BOARD_HAUPPAUGE_WINTV_USB_2 },
473 { USB_DEVICE(0x2304, 0x0207),
474 .driver_info = EM2820_BOARD_PINNACLE_DVC_90 },
475 { USB_DEVICE(0x2304, 0x021a),
476 .driver_info = EM2820_BOARD_PINNACLE_DVC_90 },
477 { USB_DEVICE(0x2304, 0x0227),
478 .driver_info = EM2880_BOARD_PINNACLE_PCTV_HD_PRO },
479 { USB_DEVICE(0x2040, 0x6500), 1177 { USB_DEVICE(0x2040, 0x6500),
480 .driver_info = EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900 }, 1178 .driver_info = EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900 },
481 { USB_DEVICE(0x2040, 0x6502), 1179 { USB_DEVICE(0x2040, 0x6502),
482 .driver_info = EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900_R2 }, 1180 .driver_info = EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900_R2 },
483 { USB_DEVICE(0x2040, 0x6513), /* HCW HVR-980 */ 1181 { USB_DEVICE(0x2040, 0x6513), /* HCW HVR-980 */
484 .driver_info = EM2880_BOARD_HAUPPAUGE_WINTV_HVR_950 }, 1182 .driver_info = EM2883_BOARD_HAUPPAUGE_WINTV_HVR_950 },
485 { USB_DEVICE(0x2040, 0x6517), /* HP HVR-950 */ 1183 { USB_DEVICE(0x2040, 0x6517), /* HP HVR-950 */
486 .driver_info = EM2880_BOARD_HAUPPAUGE_WINTV_HVR_950 }, 1184 .driver_info = EM2883_BOARD_HAUPPAUGE_WINTV_HVR_950 },
487 { USB_DEVICE(0x2040, 0x651b), /* RP HVR-950 */ 1185 { USB_DEVICE(0x2040, 0x651b), /* RP HVR-950 */
488 .driver_info = EM2880_BOARD_HAUPPAUGE_WINTV_HVR_950 }, 1186 .driver_info = EM2883_BOARD_HAUPPAUGE_WINTV_HVR_950 },
489 { USB_DEVICE(0x2040, 0x651f), /* HCW HVR-850 */ 1187 { USB_DEVICE(0x2040, 0x651f), /* HCW HVR-850 */
490 .driver_info = EM2880_BOARD_HAUPPAUGE_WINTV_HVR_950 }, 1188 .driver_info = EM2883_BOARD_HAUPPAUGE_WINTV_HVR_950 },
491 { USB_DEVICE(0x0ccd, 0x0042), 1189 { USB_DEVICE(0x0438, 0xb002),
492 .driver_info = EM2880_BOARD_TERRATEC_HYBRID_XS }, 1190 .driver_info = EM2880_BOARD_AMD_ATI_TV_WONDER_HD_600 },
493 { USB_DEVICE(0x0ccd, 0x0047), 1191 { USB_DEVICE(0x2001, 0xf112),
494 .driver_info = EM2880_BOARD_TERRATEC_PRODIGY_XS }, 1192 .driver_info = EM2820_BOARD_DLINK_USB_TV },
1193 { USB_DEVICE(0x2304, 0x0207),
1194 .driver_info = EM2820_BOARD_PINNACLE_DVC_90 },
1195 { USB_DEVICE(0x2304, 0x0208),
1196 .driver_info = EM2820_BOARD_PINNACLE_USB_2 },
1197 { USB_DEVICE(0x2304, 0x021a),
1198 .driver_info = EM2820_BOARD_PINNACLE_DVC_90 },
1199 { USB_DEVICE(0x2304, 0x0226),
1200 .driver_info = EM2882_BOARD_PINNACLE_HYBRID_PRO },
1201 { USB_DEVICE(0x2304, 0x0227),
1202 .driver_info = EM2880_BOARD_PINNACLE_PCTV_HD_PRO },
1203 { USB_DEVICE(0x0413, 0x6023),
1204 .driver_info = EM2800_BOARD_LEADTEK_WINFAST_USBII },
1205 { USB_DEVICE(0x093b, 0xa005),
1206 .driver_info = EM2861_BOARD_PLEXTOR_PX_TV100U },
495 { }, 1207 { },
496}; 1208};
497MODULE_DEVICE_TABLE(usb, em28xx_id_table); 1209MODULE_DEVICE_TABLE(usb, em28xx_id_table);
@@ -500,6 +1212,18 @@ MODULE_DEVICE_TABLE(usb, em28xx_id_table);
500 * Reset sequences for analog/digital modes 1212 * Reset sequences for analog/digital modes
501 */ 1213 */
502 1214
1215/* Reset for the most [analog] boards */
1216static struct em28xx_reg_seq default_analog[] = {
1217 {EM28XX_R08_GPIO, 0x6d, ~EM_GPIO_4, 10},
1218 { -1, -1, -1, -1},
1219};
1220
1221/* Reset for the most [digital] boards */
1222static struct em28xx_reg_seq default_digital[] = {
1223 {EM28XX_R08_GPIO, 0x6e, ~EM_GPIO_4, 10},
1224 { -1, -1, -1, -1},
1225};
1226
503/* Board Hauppauge WinTV HVR 900 analog */ 1227/* Board Hauppauge WinTV HVR 900 analog */
504static struct em28xx_reg_seq hauppauge_wintv_hvr_900_analog[] = { 1228static struct em28xx_reg_seq hauppauge_wintv_hvr_900_analog[] = {
505 {EM28XX_R08_GPIO, 0x2d, ~EM_GPIO_4, 10}, 1229 {EM28XX_R08_GPIO, 0x2d, ~EM_GPIO_4, 10},
@@ -515,14 +1239,42 @@ static struct em28xx_reg_seq hauppauge_wintv_hvr_900_digital[] = {
515 { -1, -1, -1, -1}, 1239 { -1, -1, -1, -1},
516}; 1240};
517 1241
518/* Board Hauppauge WinTV HVR 900 tuner_callback */ 1242/* Boards - EM2880 MSI DIGIVOX AD and EM2880_BOARD_MSI_DIGIVOX_AD_II */
519static struct em28xx_reg_seq hauppauge_wintv_hvr_900_tuner_callback[] = { 1243static struct em28xx_reg_seq em2880_msi_digivox_ad_analog[] = {
1244 {EM28XX_R08_GPIO, 0x69, ~EM_GPIO_4, 10},
1245 { -1, -1, -1, -1},
1246};
1247
1248/* Boards - EM2880 MSI DIGIVOX AD and EM2880_BOARD_MSI_DIGIVOX_AD_II */
1249static struct em28xx_reg_seq em2880_msi_digivox_ad_digital[] = {
1250 {EM28XX_R08_GPIO, 0x6a, ~EM_GPIO_4, 10},
1251 { -1, -1, -1, -1},
1252};
1253
1254/* Board - EM2870 Kworld 355u
1255 Analog - No input analog */
1256static struct em28xx_reg_seq em2870_kworld_355u_digital[] = {
1257 {EM2880_R04_GPO, 0x01, 0xff, 10},
1258 { -1, -1, -1, -1},
1259};
1260
1261/* Callback for the most boards */
1262static struct em28xx_reg_seq default_callback[] = {
520 {EM28XX_R08_GPIO, EM_GPIO_4, EM_GPIO_4, 10}, 1263 {EM28XX_R08_GPIO, EM_GPIO_4, EM_GPIO_4, 10},
521 {EM28XX_R08_GPIO, 0, EM_GPIO_4, 10}, 1264 {EM28XX_R08_GPIO, 0, EM_GPIO_4, 10},
522 {EM28XX_R08_GPIO, EM_GPIO_4, EM_GPIO_4, 10}, 1265 {EM28XX_R08_GPIO, EM_GPIO_4, EM_GPIO_4, 10},
523 { -1, -1, -1, -1}, 1266 { -1, -1, -1, -1},
524}; 1267};
525 1268
1269/* Callback for EM2882 TERRATEC HYBRID XS */
1270static struct em28xx_reg_seq em2882_terratec_hybrid_xs_digital[] = {
1271 {EM28XX_R08_GPIO, 0x2e, 0xff, 6},
1272 {EM28XX_R08_GPIO, 0x3e, ~EM_GPIO_4, 6},
1273 {EM2880_R04_GPO, 0x04, 0xff, 10},
1274 {EM2880_R04_GPO, 0x0c, 0xff, 10},
1275 { -1, -1, -1, -1},
1276};
1277
526/* 1278/*
527 * EEPROM hash table for devices with generic USB IDs 1279 * EEPROM hash table for devices with generic USB IDs
528 */ 1280 */
@@ -569,6 +1321,7 @@ static void em28xx_set_model(struct em28xx *dev)
569 dev->max_range_640_480 = em28xx_boards[dev->model].max_range_640_480; 1321 dev->max_range_640_480 = em28xx_boards[dev->model].max_range_640_480;
570 dev->has_dvb = em28xx_boards[dev->model].has_dvb; 1322 dev->has_dvb = em28xx_boards[dev->model].has_dvb;
571 dev->has_snapshot_button = em28xx_boards[dev->model].has_snapshot_button; 1323 dev->has_snapshot_button = em28xx_boards[dev->model].has_snapshot_button;
1324 dev->valid = em28xx_boards[dev->model].valid;
572} 1325}
573 1326
574/* Since em28xx_pre_card_setup() requires a proper dev->model, 1327/* Since em28xx_pre_card_setup() requires a proper dev->model,
@@ -604,19 +1357,171 @@ void em28xx_pre_card_setup(struct em28xx *dev)
604 case EM2880_BOARD_TERRATEC_PRODIGY_XS: 1357 case EM2880_BOARD_TERRATEC_PRODIGY_XS:
605 case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900: 1358 case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900:
606 case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900_R2: 1359 case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900_R2:
607 case EM2880_BOARD_TERRATEC_HYBRID_XS: 1360 case EM2860_BOARD_TERRATEC_HYBRID_XS:
608 case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_950: 1361 case EM2883_BOARD_HAUPPAUGE_WINTV_HVR_950:
609 case EM2880_BOARD_PINNACLE_PCTV_HD_PRO: 1362 case EM2880_BOARD_PINNACLE_PCTV_HD_PRO:
1363 case EM2882_BOARD_PINNACLE_HYBRID_PRO:
1364 case EM2883_BOARD_KWORLD_HYBRID_A316:
1365 case EM2880_BOARD_AMD_ATI_TV_WONDER_HD_600:
1366 em28xx_write_regs(dev, EM28XX_R0F_XCLK, "\x27", 1);
1367 em28xx_write_regs(dev, EM28XX_R06_I2C_CLK, "\x40", 1);
1368 msleep(50);
1369
1370 /* Sets GPO/GPIO sequences for this device */
1371 dev->analog_gpio = hauppauge_wintv_hvr_900_analog;
1372 dev->digital_gpio = hauppauge_wintv_hvr_900_digital;
1373 dev->tun_analog_gpio = default_callback;
1374 dev->tun_digital_gpio = default_callback;
1375 break;
1376
1377 case EM2882_BOARD_TERRATEC_HYBRID_XS:
610 em28xx_write_regs(dev, EM28XX_R0F_XCLK, "\x27", 1); 1378 em28xx_write_regs(dev, EM28XX_R0F_XCLK, "\x27", 1);
611 em28xx_write_regs(dev, EM28XX_R06_I2C_CLK, "\x40", 1); 1379 em28xx_write_regs(dev, EM28XX_R06_I2C_CLK, "\x40", 1);
612 msleep(50); 1380 msleep(50);
613 1381
1382 /* should be added ir_codes here */
1383
614 /* Sets GPO/GPIO sequences for this device */ 1384 /* Sets GPO/GPIO sequences for this device */
615 dev->analog_gpio = hauppauge_wintv_hvr_900_analog; 1385 dev->analog_gpio = hauppauge_wintv_hvr_900_analog;
616 dev->digital_gpio = hauppauge_wintv_hvr_900_digital; 1386 dev->digital_gpio = hauppauge_wintv_hvr_900_digital;
617 dev->tun_analog_gpio = hauppauge_wintv_hvr_900_tuner_callback; 1387 dev->tun_analog_gpio = default_callback;
618 dev->tun_digital_gpio = hauppauge_wintv_hvr_900_tuner_callback; 1388 dev->tun_digital_gpio = em2882_terratec_hybrid_xs_digital;
1389 break;
1390
1391 case EM2880_BOARD_TERRATEC_HYBRID_XS_FR:
1392 case EM2880_BOARD_TERRATEC_HYBRID_XS:
1393 case EM2870_BOARD_TERRATEC_XS:
1394 case EM2881_BOARD_PINNACLE_HYBRID_PRO:
1395 case EM2880_BOARD_KWORLD_DVB_310U:
1396 case EM2870_BOARD_KWORLD_350U:
1397 case EM2881_BOARD_DNT_DA2_HYBRID:
1398 em28xx_write_regs(dev, EM28XX_R0F_XCLK, "\x27", 1);
1399 em28xx_write_regs(dev, EM28XX_R06_I2C_CLK, "\x40", 1);
1400 msleep(50);
1401
1402 /* NOTE: EM2881_DNT_DA2_HYBRID spend 140 msleep for digital
1403 and analog commands. If this commands doesn't work,
1404 add this timer. */
619 1405
1406 /* Sets GPO/GPIO sequences for this device */
1407 dev->analog_gpio = default_analog;
1408 dev->digital_gpio = default_digital;
1409 dev->tun_analog_gpio = default_callback;
1410 dev->tun_digital_gpio = default_callback;
1411 break;
1412
1413 case EM2880_BOARD_MSI_DIGIVOX_AD:
1414 case EM2880_BOARD_MSI_DIGIVOX_AD_II:
1415 em28xx_write_regs(dev, EM28XX_R0F_XCLK, "\x27", 1);
1416 em28xx_write_regs(dev, EM28XX_R06_I2C_CLK, "\x40", 1);
1417 msleep(50);
1418
1419 /* Sets GPO/GPIO sequences for this device */
1420 dev->analog_gpio = em2880_msi_digivox_ad_analog;
1421 dev->digital_gpio = em2880_msi_digivox_ad_digital;
1422 dev->tun_analog_gpio = default_callback;
1423 dev->tun_digital_gpio = default_callback;
1424 break;
1425
1426 case EM2750_BOARD_UNKNOWN:
1427 case EM2750_BOARD_DLCW_130:
1428 em28xx_write_regs(dev, EM28XX_R0F_XCLK, "\x0a", 1);
1429 break;
1430
1431 case EM2861_BOARD_PLEXTOR_PX_TV100U:
1432 em28xx_write_regs(dev, EM28XX_R0F_XCLK, "\x27", 1);
1433 em28xx_write_regs(dev, EM28XX_R06_I2C_CLK, "\x40", 1);
1434 /* FIXME guess */
1435 /* Turn on analog audio output */
1436 em28xx_write_regs_req(dev, 0x00, 0x08, "\xfd", 1);
1437 break;
1438
1439 case EM2861_BOARD_KWORLD_PVRTV_300U:
1440 case EM2880_BOARD_KWORLD_DVB_305U:
1441 em28xx_write_regs(dev, EM28XX_R0F_XCLK, "\x27", 1);
1442 em28xx_write_regs(dev, EM28XX_R06_I2C_CLK, "\x4c", 1);
1443 msleep(10);
1444 em28xx_write_regs(dev, 0x08, "\x6d", 1);
1445 msleep(10);
1446 em28xx_write_regs(dev, 0x08, "\x7d", 1);
1447 msleep(10);
1448 break;
1449
1450 case EM2870_BOARD_KWORLD_355U:
1451 em28xx_write_regs(dev, EM28XX_R0F_XCLK, "\x27", 1);
1452 em28xx_write_regs(dev, EM28XX_R06_I2C_CLK, "\x40", 1);
1453 msleep(50);
1454
1455 /* Sets GPO/GPIO sequences for this device */
1456 dev->digital_gpio = em2870_kworld_355u_digital;
1457 break;
1458
1459 case EM2870_BOARD_COMPRO_VIDEOMATE:
1460 em28xx_write_regs(dev, EM28XX_R0F_XCLK, "\x27", 1);
1461 em28xx_write_regs(dev, EM28XX_R06_I2C_CLK, "\x40", 1);
1462 /* TODO: someone can do some cleanup here...
1463 not everything's needed */
1464 em28xx_write_regs(dev, 0x04, "\x00", 1);
1465 msleep(10);
1466 em28xx_write_regs(dev, 0x04, "\x01", 1);
1467 msleep(10);
1468 em28xx_write_regs(dev, 0x08, "\xfd", 1);
1469 mdelay(70);
1470 em28xx_write_regs(dev, 0x08, "\xfc", 1);
1471 mdelay(70);
1472 em28xx_write_regs(dev, 0x08, "\xdc", 1);
1473 mdelay(70);
1474 em28xx_write_regs(dev, 0x08, "\xfc", 1);
1475 mdelay(70);
1476 break;
1477
1478 case EM2870_BOARD_TERRATEC_XS_MT2060:
1479 em28xx_write_regs(dev, EM28XX_R0F_XCLK, "\x27", 1);
1480 em28xx_write_regs(dev, EM28XX_R06_I2C_CLK, "\x40", 1);
1481 /* this device needs some gpio writes to get the DVB-T
1482 demod work */
1483 em28xx_write_regs(dev, 0x08, "\xfe", 1);
1484 mdelay(70);
1485 em28xx_write_regs(dev, 0x08, "\xde", 1);
1486 mdelay(70);
1487 dev->em28xx_write_regs(dev, 0x08, "\xfe", 1);
1488 mdelay(70);
1489 break;
1490
1491 case EM2870_BOARD_PINNACLE_PCTV_DVB:
1492 em28xx_write_regs(dev, EM28XX_R06_I2C_CLK, "\x40", 1);
1493 /* this device needs some gpio writes to get the
1494 DVB-T demod work */
1495 em28xx_write_regs(dev, 0x08, "\xfe", 1);
1496 mdelay(70);
1497 em28xx_write_regs(dev, 0x08, "\xde", 1);
1498 mdelay(70);
1499 em28xx_write_regs(dev, 0x08, "\xfe", 1);
1500 mdelay(70);
1501 /* switch em2880 rc protocol */
1502 em28xx_write_regs(dev, EM28XX_R0F_XCLK, "\x22", 1);
1503 /* should be added ir_codes here */
1504 break;
1505
1506 case EM2820_BOARD_GADMEI_UTV310:
1507 em28xx_write_regs(dev, EM28XX_R0F_XCLK, "\x27", 1);
1508 em28xx_write_regs(dev, EM28XX_R06_I2C_CLK, "\x40", 1);
1509 /* Turn on analog audio output */
1510 em28xx_write_regs_req(dev, 0x00, 0x08, "\xfd", 1);
1511 break;
1512
1513 case EM2860_BOARD_GADMEI_UTV330:
1514 /* Turn on IR */
1515 em28xx_write_regs(dev, EM28XX_R0F_XCLK, "\x07", 1);
1516 em28xx_write_regs(dev, EM28XX_R06_I2C_CLK, "\x40", 1);
1517 /* should be added ir_codes here */
1518 break;
1519
1520 case EM2820_BOARD_MSI_VOX_USB_2:
1521 em28xx_write_regs(dev, EM28XX_R0F_XCLK, "\x27", 1);
1522 em28xx_write_regs(dev, EM28XX_R06_I2C_CLK, "\x40", 1);
1523 /* enables audio for that device */
1524 em28xx_write_regs_req(dev, 0x00, 0x08, "\xfd", 1);
620 break; 1525 break;
621 } 1526 }
622 1527
@@ -639,12 +1544,16 @@ static void em28xx_setup_xc3028(struct em28xx *dev, struct xc2028_ctrl *ctl)
639 case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900: 1544 case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900:
640 ctl->demod = XC3028_FE_ZARLINK456; 1545 ctl->demod = XC3028_FE_ZARLINK456;
641 break; 1546 break;
1547 case EM2880_BOARD_TERRATEC_HYBRID_XS:
1548 ctl->demod = XC3028_FE_ZARLINK456;
1549 break;
642 case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900_R2: 1550 case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900_R2:
643 /* djh - Not sure which demod we need here */ 1551 /* djh - Not sure which demod we need here */
644 ctl->demod = XC3028_FE_DEFAULT; 1552 ctl->demod = XC3028_FE_DEFAULT;
645 break; 1553 break;
646 case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_950: 1554 case EM2883_BOARD_HAUPPAUGE_WINTV_HVR_950:
647 case EM2880_BOARD_PINNACLE_PCTV_HD_PRO: 1555 case EM2880_BOARD_PINNACLE_PCTV_HD_PRO:
1556 case EM2880_BOARD_AMD_ATI_TV_WONDER_HD_600:
648 /* FIXME: Better to specify the needed IF */ 1557 /* FIXME: Better to specify the needed IF */
649 ctl->demod = XC3028_FE_DEFAULT; 1558 ctl->demod = XC3028_FE_DEFAULT;
650 break; 1559 break;
@@ -809,6 +1718,8 @@ void em28xx_set_ir(struct em28xx *dev, struct IR_i2c *ir)
809 break; 1718 break;
810 case (EM2800_BOARD_KWORLD_USB2800): 1719 case (EM2800_BOARD_KWORLD_USB2800):
811 break; 1720 break;
1721 case (EM2800_BOARD_GRABBEEX_USB2800):
1722 break;
812 } 1723 }
813} 1724}
814 1725
@@ -823,7 +1734,7 @@ void em28xx_card_setup(struct em28xx *dev)
823 case EM2820_BOARD_HAUPPAUGE_WINTV_USB_2: 1734 case EM2820_BOARD_HAUPPAUGE_WINTV_USB_2:
824 case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900: 1735 case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900:
825 case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900_R2: 1736 case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900_R2:
826 case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_950: 1737 case EM2883_BOARD_HAUPPAUGE_WINTV_HVR_950:
827 { 1738 {
828 struct tveeprom tv; 1739 struct tveeprom tv;
829#ifdef CONFIG_MODULES 1740#ifdef CONFIG_MODULES
@@ -836,7 +1747,7 @@ void em28xx_card_setup(struct em28xx *dev)
836 1747
837 dev->tuner_type = tv.tuner_type; 1748 dev->tuner_type = tv.tuner_type;
838 1749
839 if (tv.audio_processor == AUDIO_CHIP_MSP34XX) { 1750 if (tv.audio_processor == V4L2_IDENT_MSPX4XX) {
840 dev->i2s_speed = 2048000; 1751 dev->i2s_speed = 2048000;
841 dev->has_msp34xx = 1; 1752 dev->has_msp34xx = 1;
842 } 1753 }
@@ -854,11 +1765,21 @@ void em28xx_card_setup(struct em28xx *dev)
854 case EM2800_BOARD_UNKNOWN: 1765 case EM2800_BOARD_UNKNOWN:
855 if (!em28xx_hint_board(dev)) 1766 if (!em28xx_hint_board(dev))
856 em28xx_set_model(dev); 1767 em28xx_set_model(dev);
1768 break;
857 } 1769 }
858 1770
859 if (dev->has_snapshot_button) 1771 if (dev->has_snapshot_button)
860 em28xx_register_snapshot_button(dev); 1772 em28xx_register_snapshot_button(dev);
861 1773
1774 if (dev->valid == EM28XX_BOARD_NOT_VALIDATED) {
1775 em28xx_errdev("\n\n");
1776 em28xx_errdev("The support for this board weren't "
1777 "valid yet.\n");
1778 em28xx_errdev("Please send a report of having this working\n");
1779 em28xx_errdev("not to V4L mailing list (and/or to other "
1780 "addresses)\n\n");
1781 }
1782
862 /* Allow override tuner type by a module parameter */ 1783 /* Allow override tuner type by a module parameter */
863 if (tuner >= 0) 1784 if (tuner >= 0)
864 dev->tuner_type = tuner; 1785 dev->tuner_type = tuner;
diff --git a/drivers/media/video/em28xx/em28xx-dvb.c b/drivers/media/video/em28xx/em28xx-dvb.c
index cc61cfb23a4a..4b992bc0083c 100644
--- a/drivers/media/video/em28xx/em28xx-dvb.c
+++ b/drivers/media/video/em28xx/em28xx-dvb.c
@@ -6,6 +6,7 @@
6 (c) 2008 Devin Heitmueller <devin.heitmueller@gmail.com> 6 (c) 2008 Devin Heitmueller <devin.heitmueller@gmail.com>
7 - Fixes for the driver to properly work with HVR-950 7 - Fixes for the driver to properly work with HVR-950
8 - Fixes for the driver to properly work with Pinnacle PCTV HD Pro Stick 8 - Fixes for the driver to properly work with Pinnacle PCTV HD Pro Stick
9 - Fixes for the driver to properly work with AMD ATI TV Wonder HD 600
9 10
10 (c) 2008 Aidan Thornton <makosoft@googlemail.com> 11 (c) 2008 Aidan Thornton <makosoft@googlemail.com>
11 12
@@ -409,8 +410,9 @@ static int dvb_init(struct em28xx *dev)
409 em28xx_set_mode(dev, EM28XX_DIGITAL_MODE); 410 em28xx_set_mode(dev, EM28XX_DIGITAL_MODE);
410 /* init frontend */ 411 /* init frontend */
411 switch (dev->model) { 412 switch (dev->model) {
412 case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_950: 413 case EM2883_BOARD_HAUPPAUGE_WINTV_HVR_950:
413 case EM2880_BOARD_PINNACLE_PCTV_HD_PRO: 414 case EM2880_BOARD_PINNACLE_PCTV_HD_PRO:
415 case EM2880_BOARD_AMD_ATI_TV_WONDER_HD_600:
414 dvb->frontend = dvb_attach(lgdt330x_attach, 416 dvb->frontend = dvb_attach(lgdt330x_attach,
415 &em2880_lgdt3303_dev, 417 &em2880_lgdt3303_dev,
416 &dev->i2c_adap); 418 &dev->i2c_adap);
@@ -441,6 +443,15 @@ static int dvb_init(struct em28xx *dev)
441 } 443 }
442 break; 444 break;
443#endif 445#endif
446 case EM2880_BOARD_TERRATEC_HYBRID_XS:
447 dvb->frontend = dvb_attach(zl10353_attach,
448 &em28xx_zl10353_with_xc3028,
449 &dev->i2c_adap);
450 if (attach_xc3028(0x61, dev) < 0) {
451 result = -EINVAL;
452 goto out_free;
453 }
454 break;
444 default: 455 default:
445 printk(KERN_ERR "%s/2: The frontend of your DVB/ATSC card" 456 printk(KERN_ERR "%s/2: The frontend of your DVB/ATSC card"
446 " isn't supported yet\n", 457 " isn't supported yet\n",
diff --git a/drivers/media/video/em28xx/em28xx-video.c b/drivers/media/video/em28xx/em28xx-video.c
index 2d9f14d2a00b..49ab0629702e 100644
--- a/drivers/media/video/em28xx/em28xx-video.c
+++ b/drivers/media/video/em28xx/em28xx-video.c
@@ -38,6 +38,7 @@
38 38
39#include "em28xx.h" 39#include "em28xx.h"
40#include <media/v4l2-common.h> 40#include <media/v4l2-common.h>
41#include <media/v4l2-ioctl.h>
41#include <media/msp3400.h> 42#include <media/msp3400.h>
42#include <media/tuner.h> 43#include <media/tuner.h>
43 44
@@ -1763,20 +1764,7 @@ static const struct file_operations em28xx_v4l_fops = {
1763 .compat_ioctl = v4l_compat_ioctl32, 1764 .compat_ioctl = v4l_compat_ioctl32,
1764}; 1765};
1765 1766
1766static const struct file_operations radio_fops = { 1767static const struct v4l2_ioctl_ops video_ioctl_ops = {
1767 .owner = THIS_MODULE,
1768 .open = em28xx_v4l2_open,
1769 .release = em28xx_v4l2_close,
1770 .ioctl = video_ioctl2,
1771 .compat_ioctl = v4l_compat_ioctl32,
1772 .llseek = no_llseek,
1773};
1774
1775static const struct video_device em28xx_video_template = {
1776 .fops = &em28xx_v4l_fops,
1777 .release = video_device_release,
1778
1779 .minor = -1,
1780 .vidioc_querycap = vidioc_querycap, 1768 .vidioc_querycap = vidioc_querycap,
1781 .vidioc_enum_fmt_vid_cap = vidioc_enum_fmt_vid_cap, 1769 .vidioc_enum_fmt_vid_cap = vidioc_enum_fmt_vid_cap,
1782 .vidioc_g_fmt_vid_cap = vidioc_g_fmt_vid_cap, 1770 .vidioc_g_fmt_vid_cap = vidioc_g_fmt_vid_cap,
@@ -1814,16 +1802,29 @@ static const struct video_device em28xx_video_template = {
1814#ifdef CONFIG_VIDEO_V4L1_COMPAT 1802#ifdef CONFIG_VIDEO_V4L1_COMPAT
1815 .vidiocgmbuf = vidiocgmbuf, 1803 .vidiocgmbuf = vidiocgmbuf,
1816#endif 1804#endif
1805};
1806
1807static const struct video_device em28xx_video_template = {
1808 .fops = &em28xx_v4l_fops,
1809 .release = video_device_release,
1810 .ioctl_ops = &video_ioctl_ops,
1811
1812 .minor = -1,
1817 1813
1818 .tvnorms = V4L2_STD_ALL, 1814 .tvnorms = V4L2_STD_ALL,
1819 .current_norm = V4L2_STD_PAL, 1815 .current_norm = V4L2_STD_PAL,
1820}; 1816};
1821 1817
1822static struct video_device em28xx_radio_template = { 1818static const struct file_operations radio_fops = {
1823 .name = "em28xx-radio", 1819 .owner = THIS_MODULE,
1824 .type = VID_TYPE_TUNER, 1820 .open = em28xx_v4l2_open,
1825 .fops = &radio_fops, 1821 .release = em28xx_v4l2_close,
1826 .minor = -1, 1822 .ioctl = video_ioctl2,
1823 .compat_ioctl = v4l_compat_ioctl32,
1824 .llseek = no_llseek,
1825};
1826
1827static const struct v4l2_ioctl_ops radio_ioctl_ops = {
1827 .vidioc_querycap = radio_querycap, 1828 .vidioc_querycap = radio_querycap,
1828 .vidioc_g_tuner = radio_g_tuner, 1829 .vidioc_g_tuner = radio_g_tuner,
1829 .vidioc_enum_input = radio_enum_input, 1830 .vidioc_enum_input = radio_enum_input,
@@ -1842,6 +1843,13 @@ static struct video_device em28xx_radio_template = {
1842#endif 1843#endif
1843}; 1844};
1844 1845
1846static struct video_device em28xx_radio_template = {
1847 .name = "em28xx-radio",
1848 .fops = &radio_fops,
1849 .ioctl_ops = &radio_ioctl_ops,
1850 .minor = -1,
1851};
1852
1845/******************************** usb interface ******************************/ 1853/******************************** usb interface ******************************/
1846 1854
1847 1855
@@ -1882,7 +1890,6 @@ EXPORT_SYMBOL(em28xx_unregister_extension);
1882 1890
1883static struct video_device *em28xx_vdev_init(struct em28xx *dev, 1891static struct video_device *em28xx_vdev_init(struct em28xx *dev,
1884 const struct video_device *template, 1892 const struct video_device *template,
1885 const int type,
1886 const char *type_name) 1893 const char *type_name)
1887{ 1894{
1888 struct video_device *vfd; 1895 struct video_device *vfd;
@@ -1892,9 +1899,8 @@ static struct video_device *em28xx_vdev_init(struct em28xx *dev,
1892 return NULL; 1899 return NULL;
1893 *vfd = *template; 1900 *vfd = *template;
1894 vfd->minor = -1; 1901 vfd->minor = -1;
1895 vfd->dev = &dev->udev->dev; 1902 vfd->parent = &dev->udev->dev;
1896 vfd->release = video_device_release; 1903 vfd->release = video_device_release;
1897 vfd->type = type;
1898 vfd->debug = video_debug; 1904 vfd->debug = video_debug;
1899 1905
1900 snprintf(vfd->name, sizeof(vfd->name), "%s %s", 1906 snprintf(vfd->name, sizeof(vfd->name), "%s %s",
@@ -1972,14 +1978,11 @@ static int em28xx_init_dev(struct em28xx **devhandle, struct usb_device *udev,
1972 list_add_tail(&dev->devlist, &em28xx_devlist); 1978 list_add_tail(&dev->devlist, &em28xx_devlist);
1973 1979
1974 /* allocate and fill video video_device struct */ 1980 /* allocate and fill video video_device struct */
1975 dev->vdev = em28xx_vdev_init(dev, &em28xx_video_template, 1981 dev->vdev = em28xx_vdev_init(dev, &em28xx_video_template, "video");
1976 VID_TYPE_CAPTURE, "video");
1977 if (NULL == dev->vdev) { 1982 if (NULL == dev->vdev) {
1978 em28xx_errdev("cannot allocate video_device.\n"); 1983 em28xx_errdev("cannot allocate video_device.\n");
1979 goto fail_unreg; 1984 goto fail_unreg;
1980 } 1985 }
1981 if (dev->tuner_type != TUNER_ABSENT)
1982 dev->vdev->type |= VID_TYPE_TUNER;
1983 1986
1984 /* register v4l2 video video_device */ 1987 /* register v4l2 video video_device */
1985 retval = video_register_device(dev->vdev, VFL_TYPE_GRABBER, 1988 retval = video_register_device(dev->vdev, VFL_TYPE_GRABBER,
@@ -1991,8 +1994,7 @@ static int em28xx_init_dev(struct em28xx **devhandle, struct usb_device *udev,
1991 } 1994 }
1992 1995
1993 /* Allocate and fill vbi video_device struct */ 1996 /* Allocate and fill vbi video_device struct */
1994 dev->vbi_dev = em28xx_vdev_init(dev, &em28xx_video_template, 1997 dev->vbi_dev = em28xx_vdev_init(dev, &em28xx_video_template, "vbi");
1995 VFL_TYPE_VBI, "vbi");
1996 /* register v4l2 vbi video_device */ 1998 /* register v4l2 vbi video_device */
1997 if (video_register_device(dev->vbi_dev, VFL_TYPE_VBI, 1999 if (video_register_device(dev->vbi_dev, VFL_TYPE_VBI,
1998 vbi_nr[dev->devno]) < 0) { 2000 vbi_nr[dev->devno]) < 0) {
@@ -2002,8 +2004,7 @@ static int em28xx_init_dev(struct em28xx **devhandle, struct usb_device *udev,
2002 } 2004 }
2003 2005
2004 if (em28xx_boards[dev->model].radio.type == EM28XX_RADIO) { 2006 if (em28xx_boards[dev->model].radio.type == EM28XX_RADIO) {
2005 dev->radio_dev = em28xx_vdev_init(dev, &em28xx_radio_template, 2007 dev->radio_dev = em28xx_vdev_init(dev, &em28xx_radio_template, "radio");
2006 VFL_TYPE_RADIO, "radio");
2007 if (NULL == dev->radio_dev) { 2008 if (NULL == dev->radio_dev) {
2008 em28xx_errdev("cannot allocate video_device.\n"); 2009 em28xx_errdev("cannot allocate video_device.\n");
2009 goto fail_unreg; 2010 goto fail_unreg;
diff --git a/drivers/media/video/em28xx/em28xx.h b/drivers/media/video/em28xx/em28xx.h
index 89842c5d64a1..9a3310748685 100644
--- a/drivers/media/video/em28xx/em28xx.h
+++ b/drivers/media/video/em28xx/em28xx.h
@@ -54,15 +54,58 @@
54#define EM2880_BOARD_TERRATEC_PRODIGY_XS 13 54#define EM2880_BOARD_TERRATEC_PRODIGY_XS 13
55#define EM2820_BOARD_PROLINK_PLAYTV_USB2 14 55#define EM2820_BOARD_PROLINK_PLAYTV_USB2 14
56#define EM2800_BOARD_VGEAR_POCKETTV 15 56#define EM2800_BOARD_VGEAR_POCKETTV 15
57#define EM2880_BOARD_HAUPPAUGE_WINTV_HVR_950 16 57#define EM2883_BOARD_HAUPPAUGE_WINTV_HVR_950 16
58#define EM2880_BOARD_PINNACLE_PCTV_HD_PRO 17 58#define EM2880_BOARD_PINNACLE_PCTV_HD_PRO 17
59#define EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900_R2 18 59#define EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900_R2 18
60#define EM2860_BOARD_POINTNIX_INTRAORAL_CAMERA 19 60#define EM2860_BOARD_POINTNIX_INTRAORAL_CAMERA 19
61#define EM2880_BOARD_AMD_ATI_TV_WONDER_HD_600 20
62#define EM2800_BOARD_GRABBEEX_USB2800 21
63#define EM2750_BOARD_UNKNOWN 22
64#define EM2750_BOARD_DLCW_130 23
65#define EM2820_BOARD_DLINK_USB_TV 24
66#define EM2820_BOARD_GADMEI_UTV310 25
67#define EM2820_BOARD_HERCULES_SMART_TV_USB2 26
68#define EM2820_BOARD_PINNACLE_USB_2_FM1216ME 27
69#define EM2820_BOARD_LEADTEK_WINFAST_USBII_DELUXE 28
70#define EM2820_BOARD_PINNACLE_DVC_100 29
71#define EM2820_BOARD_VIDEOLOGY_20K14XUSB 30
72#define EM2821_BOARD_USBGEAR_VD204 31
73#define EM2821_BOARD_SUPERCOMP_USB_2 32
74#define EM2821_BOARD_PROLINK_PLAYTV_USB2 33
75#define EM2860_BOARD_TERRATEC_HYBRID_XS 34
76#define EM2860_BOARD_TYPHOON_DVD_MAKER 35
77#define EM2860_BOARD_NETGMBH_CAM 36
78#define EM2860_BOARD_GADMEI_UTV330 37
79#define EM2861_BOARD_YAKUMO_MOVIE_MIXER 38
80#define EM2861_BOARD_KWORLD_PVRTV_300U 39
81#define EM2861_BOARD_PLEXTOR_PX_TV100U 40
82#define EM2870_BOARD_KWORLD_350U 41
83#define EM2870_BOARD_KWORLD_355U 42
84#define EM2870_BOARD_TERRATEC_XS 43
85#define EM2870_BOARD_TERRATEC_XS_MT2060 44
86#define EM2870_BOARD_PINNACLE_PCTV_DVB 45
87#define EM2870_BOARD_COMPRO_VIDEOMATE 46
88#define EM2880_BOARD_KWORLD_DVB_305U 47
89#define EM2880_BOARD_KWORLD_DVB_310U 48
90#define EM2880_BOARD_MSI_DIGIVOX_AD 49
91#define EM2880_BOARD_MSI_DIGIVOX_AD_II 50
92#define EM2880_BOARD_TERRATEC_HYBRID_XS_FR 51
93#define EM2881_BOARD_DNT_DA2_HYBRID 52
94#define EM2881_BOARD_PINNACLE_HYBRID_PRO 53
95#define EM2882_BOARD_KWORLD_VS_DVBT 54
96#define EM2882_BOARD_TERRATEC_HYBRID_XS 55
97#define EM2882_BOARD_PINNACLE_HYBRID_PRO 56
98#define EM2883_BOARD_KWORLD_HYBRID_A316 57
99#define EM2820_BOARD_COMPRO_VIDEOMATE_FORYOU 58
61 100
62/* Limits minimum and default number of buffers */ 101/* Limits minimum and default number of buffers */
63#define EM28XX_MIN_BUF 4 102#define EM28XX_MIN_BUF 4
64#define EM28XX_DEF_BUF 8 103#define EM28XX_DEF_BUF 8
65 104
105/* Params for validated field */
106#define EM28XX_BOARD_NOT_VALIDATED 1
107#define EM28XX_BOARD_VALIDATED 0
108
66/* maximum number of em28xx boards */ 109/* maximum number of em28xx boards */
67#define EM28XX_MAXBOARDS 4 /*FIXME: should be bigger */ 110#define EM28XX_MAXBOARDS 4 /*FIXME: should be bigger */
68 111
@@ -251,6 +294,7 @@ struct em28xx_board {
251 unsigned int max_range_640_480:1; 294 unsigned int max_range_640_480:1;
252 unsigned int has_dvb:1; 295 unsigned int has_dvb:1;
253 unsigned int has_snapshot_button:1; 296 unsigned int has_snapshot_button:1;
297 unsigned int valid:1;
254 298
255 enum em28xx_decoder decoder; 299 enum em28xx_decoder decoder;
256 300
@@ -331,6 +375,7 @@ struct em28xx {
331 unsigned int max_range_640_480:1; 375 unsigned int max_range_640_480:1;
332 unsigned int has_dvb:1; 376 unsigned int has_dvb:1;
333 unsigned int has_snapshot_button:1; 377 unsigned int has_snapshot_button:1;
378 unsigned int valid:1; /* report for validated boards */
334 379
335 /* Some older em28xx chips needs a waiting time after writing */ 380 /* Some older em28xx chips needs a waiting time after writing */
336 unsigned int wait_after_write; 381 unsigned int wait_after_write;
@@ -360,7 +405,7 @@ struct em28xx {
360 v4l2_std_id norm; /* selected tv norm */ 405 v4l2_std_id norm; /* selected tv norm */
361 int ctl_freq; /* selected frequency */ 406 int ctl_freq; /* selected frequency */
362 unsigned int ctl_input; /* selected input */ 407 unsigned int ctl_input; /* selected input */
363 unsigned int ctl_ainput; /* slected audio input */ 408 unsigned int ctl_ainput;/* selected audio input */
364 int mute; 409 int mute;
365 int volume; 410 int volume;
366 /* frame properties */ 411 /* frame properties */
diff --git a/drivers/media/video/et61x251/et61x251_core.c b/drivers/media/video/et61x251/et61x251_core.c
index 15d037ae25c5..2d170d101c21 100644
--- a/drivers/media/video/et61x251/et61x251_core.c
+++ b/drivers/media/video/et61x251/et61x251_core.c
@@ -34,6 +34,7 @@
34#include <linux/mm.h> 34#include <linux/mm.h>
35#include <linux/vmalloc.h> 35#include <linux/vmalloc.h>
36#include <linux/page-flags.h> 36#include <linux/page-flags.h>
37#include <media/v4l2-ioctl.h>
37#include <asm/byteorder.h> 38#include <asm/byteorder.h>
38#include <asm/page.h> 39#include <asm/page.h>
39#include <asm/uaccess.h> 40#include <asm/uaccess.h>
@@ -985,7 +986,7 @@ static DEVICE_ATTR(i2c_val, S_IRUGO | S_IWUSR,
985 986
986static int et61x251_create_sysfs(struct et61x251_device* cam) 987static int et61x251_create_sysfs(struct et61x251_device* cam)
987{ 988{
988 struct device *classdev = &(cam->v4ldev->class_dev); 989 struct device *classdev = &(cam->v4ldev->dev);
989 int err = 0; 990 int err = 0;
990 991
991 if ((err = device_create_file(classdev, &dev_attr_reg))) 992 if ((err = device_create_file(classdev, &dev_attr_reg)))
@@ -2584,8 +2585,6 @@ et61x251_usb_probe(struct usb_interface* intf, const struct usb_device_id* id)
2584 } 2585 }
2585 2586
2586 strcpy(cam->v4ldev->name, "ET61X[12]51 PC Camera"); 2587 strcpy(cam->v4ldev->name, "ET61X[12]51 PC Camera");
2587 cam->v4ldev->owner = THIS_MODULE;
2588 cam->v4ldev->type = VID_TYPE_CAPTURE | VID_TYPE_SCALES;
2589 cam->v4ldev->fops = &et61x251_fops; 2588 cam->v4ldev->fops = &et61x251_fops;
2590 cam->v4ldev->minor = video_nr[dev_nr]; 2589 cam->v4ldev->minor = video_nr[dev_nr];
2591 cam->v4ldev->release = video_device_release; 2590 cam->v4ldev->release = video_device_release;
diff --git a/drivers/media/video/gspca/conex.c b/drivers/media/video/gspca/conex.c
index 013d593b0c67..44b0bffeb20e 100644
--- a/drivers/media/video/gspca/conex.c
+++ b/drivers/media/video/gspca/conex.c
@@ -25,9 +25,6 @@
25#define CONEX_CAM 1 /* special JPEG header */ 25#define CONEX_CAM 1 /* special JPEG header */
26#include "jpeg.h" 26#include "jpeg.h"
27 27
28#define DRIVER_VERSION_NUMBER KERNEL_VERSION(2, 1, 7)
29static const char version[] = "2.1.7";
30
31MODULE_AUTHOR("Michel Xhaard <mxhaard@users.sourceforge.net>"); 28MODULE_AUTHOR("Michel Xhaard <mxhaard@users.sourceforge.net>");
32MODULE_DESCRIPTION("GSPCA USB Conexant Camera Driver"); 29MODULE_DESCRIPTION("GSPCA USB Conexant Camera Driver");
33MODULE_LICENSE("GPL"); 30MODULE_LICENSE("GPL");
@@ -818,7 +815,6 @@ static int sd_config(struct gspca_dev *gspca_dev,
818 struct cam *cam; 815 struct cam *cam;
819 816
820 cam = &gspca_dev->cam; 817 cam = &gspca_dev->cam;
821 cam->dev_name = (char *) id->driver_info;
822 cam->epaddr = 0x01; 818 cam->epaddr = 0x01;
823 cam->cam_mode = vga_mode; 819 cam->cam_mode = vga_mode;
824 cam->nmodes = sizeof vga_mode / sizeof vga_mode[0]; 820 cam->nmodes = sizeof vga_mode / sizeof vga_mode[0];
@@ -1011,9 +1007,8 @@ static struct sd_desc sd_desc = {
1011}; 1007};
1012 1008
1013/* -- module initialisation -- */ 1009/* -- module initialisation -- */
1014#define DVNM(name) .driver_info = (kernel_ulong_t) name
1015static __devinitdata struct usb_device_id device_table[] = { 1010static __devinitdata struct usb_device_id device_table[] = {
1016 {USB_DEVICE(0x0572, 0x0041), DVNM("Creative Notebook cx11646")}, 1011 {USB_DEVICE(0x0572, 0x0041)},
1017 {} 1012 {}
1018}; 1013};
1019MODULE_DEVICE_TABLE(usb, device_table); 1014MODULE_DEVICE_TABLE(usb, device_table);
@@ -1038,7 +1033,7 @@ static int __init sd_mod_init(void)
1038{ 1033{
1039 if (usb_register(&sd_driver) < 0) 1034 if (usb_register(&sd_driver) < 0)
1040 return -1; 1035 return -1;
1041 PDEBUG(D_PROBE, "v%s registered", version); 1036 PDEBUG(D_PROBE, "registered");
1042 return 0; 1037 return 0;
1043} 1038}
1044static void __exit sd_mod_exit(void) 1039static void __exit sd_mod_exit(void)
diff --git a/drivers/media/video/gspca/etoms.c b/drivers/media/video/gspca/etoms.c
index 8ab4ea7201a9..c8c2f02fcf00 100644
--- a/drivers/media/video/gspca/etoms.c
+++ b/drivers/media/video/gspca/etoms.c
@@ -22,9 +22,6 @@
22 22
23#include "gspca.h" 23#include "gspca.h"
24 24
25#define DRIVER_VERSION_NUMBER KERNEL_VERSION(2, 1, 7)
26static const char version[] = "2.1.7";
27
28MODULE_AUTHOR("Michel Xhaard <mxhaard@users.sourceforge.net>"); 25MODULE_AUTHOR("Michel Xhaard <mxhaard@users.sourceforge.net>");
29MODULE_DESCRIPTION("Etoms USB Camera Driver"); 26MODULE_DESCRIPTION("Etoms USB Camera Driver");
30MODULE_LICENSE("GPL"); 27MODULE_LICENSE("GPL");
@@ -602,26 +599,10 @@ static int sd_config(struct gspca_dev *gspca_dev,
602{ 599{
603 struct sd *sd = (struct sd *) gspca_dev; 600 struct sd *sd = (struct sd *) gspca_dev;
604 struct cam *cam; 601 struct cam *cam;
605 __u16 vendor; 602
606 __u16 product;
607
608 vendor = id->idVendor;
609 product = id->idProduct;
610/* switch (vendor) { */
611/* case 0x102c: * Etoms */
612 switch (product) {
613 case 0x6151:
614 sd->sensor = SENSOR_PAS106; /* Etoms61x151 */
615 break;
616 case 0x6251:
617 sd->sensor = SENSOR_TAS5130CXX; /* Etoms61x251 */
618 break;
619/* } */
620/* break; */
621 }
622 cam = &gspca_dev->cam; 603 cam = &gspca_dev->cam;
623 cam->dev_name = (char *) id->driver_info;
624 cam->epaddr = 1; 604 cam->epaddr = 1;
605 sd->sensor = id->driver_info;
625 if (sd->sensor == SENSOR_PAS106) { 606 if (sd->sensor == SENSOR_PAS106) {
626 cam->cam_mode = sif_mode; 607 cam->cam_mode = sif_mode;
627 cam->nmodes = sizeof sif_mode / sizeof sif_mode[0]; 608 cam->nmodes = sizeof sif_mode / sizeof sif_mode[0];
@@ -911,12 +892,11 @@ static struct sd_desc sd_desc = {
911}; 892};
912 893
913/* -- module initialisation -- */ 894/* -- module initialisation -- */
914#define DVNM(name) .driver_info = (kernel_ulong_t) name
915static __devinitdata struct usb_device_id device_table[] = { 895static __devinitdata struct usb_device_id device_table[] = {
916#ifndef CONFIG_USB_ET61X251 896#ifndef CONFIG_USB_ET61X251
917 {USB_DEVICE(0x102c, 0x6151), DVNM("Qcam Sangha CIF")}, 897 {USB_DEVICE(0x102c, 0x6151), .driver_info = SENSOR_PAS106},
918#endif 898#endif
919 {USB_DEVICE(0x102c, 0x6251), DVNM("Qcam xxxxxx VGA")}, 899 {USB_DEVICE(0x102c, 0x6251), .driver_info = SENSOR_TAS5130CXX},
920 {} 900 {}
921}; 901};
922 902
@@ -942,7 +922,7 @@ static int __init sd_mod_init(void)
942{ 922{
943 if (usb_register(&sd_driver) < 0) 923 if (usb_register(&sd_driver) < 0)
944 return -1; 924 return -1;
945 PDEBUG(D_PROBE, "v%s registered", version); 925 PDEBUG(D_PROBE, "registered");
946 return 0; 926 return 0;
947} 927}
948 928
diff --git a/drivers/media/video/gspca/gspca.c b/drivers/media/video/gspca/gspca.c
index 16e367cec760..3a051c925ff6 100644
--- a/drivers/media/video/gspca/gspca.c
+++ b/drivers/media/video/gspca/gspca.c
@@ -32,6 +32,7 @@
32#include <asm/page.h> 32#include <asm/page.h>
33#include <linux/uaccess.h> 33#include <linux/uaccess.h>
34#include <linux/jiffies.h> 34#include <linux/jiffies.h>
35#include <media/v4l2-ioctl.h>
35 36
36#include "gspca.h" 37#include "gspca.h"
37 38
@@ -42,8 +43,7 @@ MODULE_AUTHOR("Jean-Francois Moine <http://moinejf.free.fr>");
42MODULE_DESCRIPTION("GSPCA USB Camera Driver"); 43MODULE_DESCRIPTION("GSPCA USB Camera Driver");
43MODULE_LICENSE("GPL"); 44MODULE_LICENSE("GPL");
44 45
45#define DRIVER_VERSION_NUMBER KERNEL_VERSION(2, 1, 7) 46#define DRIVER_VERSION_NUMBER KERNEL_VERSION(2, 2, 0)
46static const char version[] = "2.1.7";
47 47
48static int video_nr = -1; 48static int video_nr = -1;
49 49
@@ -209,6 +209,8 @@ struct gspca_frame *gspca_frame_add(struct gspca_dev *gspca_dev,
209 &frame->v4l2_buf.timestamp); 209 &frame->v4l2_buf.timestamp);
210 frame->v4l2_buf.sequence = ++gspca_dev->sequence; 210 frame->v4l2_buf.sequence = ++gspca_dev->sequence;
211 } else if (gspca_dev->last_packet_type == DISCARD_PACKET) { 211 } else if (gspca_dev->last_packet_type == DISCARD_PACKET) {
212 if (packet_type == LAST_PACKET)
213 gspca_dev->last_packet_type = packet_type;
212 return frame; 214 return frame;
213 } 215 }
214 216
@@ -399,7 +401,7 @@ static struct usb_host_endpoint *alt_isoc(struct usb_host_interface *alt,
399 * This routine may be called many times when the bandwidth is too small 401 * This routine may be called many times when the bandwidth is too small
400 * (the bandwidth is checked on urb submit). 402 * (the bandwidth is checked on urb submit).
401 */ 403 */
402struct usb_host_endpoint *get_isoc_ep(struct gspca_dev *gspca_dev) 404static struct usb_host_endpoint *get_isoc_ep(struct gspca_dev *gspca_dev)
403{ 405{
404 struct usb_interface *intf; 406 struct usb_interface *intf;
405 struct usb_host_endpoint *ep; 407 struct usb_host_endpoint *ep;
@@ -832,7 +834,16 @@ static int vidioc_querycap(struct file *file, void *priv,
832 834
833 memset(cap, 0, sizeof *cap); 835 memset(cap, 0, sizeof *cap);
834 strncpy(cap->driver, gspca_dev->sd_desc->name, sizeof cap->driver); 836 strncpy(cap->driver, gspca_dev->sd_desc->name, sizeof cap->driver);
835 strncpy(cap->card, gspca_dev->cam.dev_name, sizeof cap->card); 837/* strncpy(cap->card, gspca_dev->cam.dev_name, sizeof cap->card); */
838 if (gspca_dev->dev->product != NULL) {
839 strncpy(cap->card, gspca_dev->dev->product,
840 sizeof cap->card);
841 } else {
842 snprintf(cap->card, sizeof cap->card,
843 "USB Camera (%04x:%04x)",
844 le16_to_cpu(gspca_dev->dev->descriptor.idVendor),
845 le16_to_cpu(gspca_dev->dev->descriptor.idProduct));
846 }
836 strncpy(cap->bus_info, gspca_dev->dev->bus->bus_name, 847 strncpy(cap->bus_info, gspca_dev->dev->bus->bus_name,
837 sizeof cap->bus_info); 848 sizeof cap->bus_info);
838 cap->version = DRIVER_VERSION_NUMBER; 849 cap->version = DRIVER_VERSION_NUMBER;
@@ -1649,12 +1660,7 @@ static struct file_operations dev_fops = {
1649 .poll = dev_poll, 1660 .poll = dev_poll,
1650}; 1661};
1651 1662
1652static struct video_device gspca_template = { 1663static const struct v4l2_ioctl_ops dev_ioctl_ops = {
1653 .name = "gspca main driver",
1654 .type = VID_TYPE_CAPTURE,
1655 .fops = &dev_fops,
1656 .release = dev_release, /* mandatory */
1657 .minor = -1,
1658 .vidioc_querycap = vidioc_querycap, 1664 .vidioc_querycap = vidioc_querycap,
1659 .vidioc_dqbuf = vidioc_dqbuf, 1665 .vidioc_dqbuf = vidioc_dqbuf,
1660 .vidioc_qbuf = vidioc_qbuf, 1666 .vidioc_qbuf = vidioc_qbuf,
@@ -1683,6 +1689,14 @@ static struct video_device gspca_template = {
1683#endif 1689#endif
1684}; 1690};
1685 1691
1692static struct video_device gspca_template = {
1693 .name = "gspca main driver",
1694 .fops = &dev_fops,
1695 .ioctl_ops = &dev_ioctl_ops,
1696 .release = dev_release, /* mandatory */
1697 .minor = -1,
1698};
1699
1686/* 1700/*
1687 * probe and create a new gspca device 1701 * probe and create a new gspca device
1688 * 1702 *
@@ -1740,10 +1754,11 @@ int gspca_dev_probe(struct usb_interface *intf,
1740 1754
1741 /* init video stuff */ 1755 /* init video stuff */
1742 memcpy(&gspca_dev->vdev, &gspca_template, sizeof gspca_template); 1756 memcpy(&gspca_dev->vdev, &gspca_template, sizeof gspca_template);
1743 gspca_dev->vdev.dev = &dev->dev; 1757 gspca_dev->vdev.parent = &dev->dev;
1744 memcpy(&gspca_dev->fops, &dev_fops, sizeof gspca_dev->fops); 1758 memcpy(&gspca_dev->fops, &dev_fops, sizeof gspca_dev->fops);
1745 gspca_dev->vdev.fops = &gspca_dev->fops; 1759 gspca_dev->vdev.fops = &gspca_dev->fops;
1746 gspca_dev->fops.owner = module; /* module protection */ 1760 gspca_dev->fops.owner = module; /* module protection */
1761 gspca_dev->present = 1;
1747 ret = video_register_device(&gspca_dev->vdev, 1762 ret = video_register_device(&gspca_dev->vdev,
1748 VFL_TYPE_GRABBER, 1763 VFL_TYPE_GRABBER,
1749 video_nr); 1764 video_nr);
@@ -1752,7 +1767,6 @@ int gspca_dev_probe(struct usb_interface *intf,
1752 goto out; 1767 goto out;
1753 } 1768 }
1754 1769
1755 gspca_dev->present = 1;
1756 usb_set_intfdata(intf, gspca_dev); 1770 usb_set_intfdata(intf, gspca_dev);
1757 PDEBUG(D_PROBE, "probe ok"); 1771 PDEBUG(D_PROBE, "probe ok");
1758 return 0; 1772 return 0;
@@ -1885,7 +1899,10 @@ EXPORT_SYMBOL(gspca_auto_gain_n_exposure);
1885/* -- module insert / remove -- */ 1899/* -- module insert / remove -- */
1886static int __init gspca_init(void) 1900static int __init gspca_init(void)
1887{ 1901{
1888 info("main v%s registered", version); 1902 info("main v%d.%d.%d registered",
1903 (DRIVER_VERSION_NUMBER >> 16) & 0xff,
1904 (DRIVER_VERSION_NUMBER >> 8) & 0xff,
1905 DRIVER_VERSION_NUMBER & 0xff);
1889 return 0; 1906 return 0;
1890} 1907}
1891static void __exit gspca_exit(void) 1908static void __exit gspca_exit(void)
diff --git a/drivers/media/video/gspca/mars.c b/drivers/media/video/gspca/mars.c
index 88c2b02f380a..21c4ee56a10a 100644
--- a/drivers/media/video/gspca/mars.c
+++ b/drivers/media/video/gspca/mars.c
@@ -24,9 +24,6 @@
24#include "gspca.h" 24#include "gspca.h"
25#include "jpeg.h" 25#include "jpeg.h"
26 26
27#define DRIVER_VERSION_NUMBER KERNEL_VERSION(2, 1, 7)
28static const char version[] = "2.1.7";
29
30MODULE_AUTHOR("Michel Xhaard <mxhaard@users.sourceforge.net>"); 27MODULE_AUTHOR("Michel Xhaard <mxhaard@users.sourceforge.net>");
31MODULE_DESCRIPTION("GSPCA/Mars USB Camera Driver"); 28MODULE_DESCRIPTION("GSPCA/Mars USB Camera Driver");
32MODULE_LICENSE("GPL"); 29MODULE_LICENSE("GPL");
@@ -140,7 +137,6 @@ static int sd_config(struct gspca_dev *gspca_dev,
140 struct cam *cam; 137 struct cam *cam;
141 138
142 cam = &gspca_dev->cam; 139 cam = &gspca_dev->cam;
143 cam->dev_name = (char *) id->driver_info;
144 cam->epaddr = 0x01; 140 cam->epaddr = 0x01;
145 cam->cam_mode = vga_mode; 141 cam->cam_mode = vga_mode;
146 cam->nmodes = sizeof vga_mode / sizeof vga_mode[0]; 142 cam->nmodes = sizeof vga_mode / sizeof vga_mode[0];
@@ -424,9 +420,8 @@ static const struct sd_desc sd_desc = {
424}; 420};
425 421
426/* -- module initialisation -- */ 422/* -- module initialisation -- */
427#define DVNM(name) .driver_info = (kernel_ulong_t) name
428static const __devinitdata struct usb_device_id device_table[] = { 423static const __devinitdata struct usb_device_id device_table[] = {
429 {USB_DEVICE(0x093a, 0x050f), DVNM("Mars-Semi Pc-Camera")}, 424 {USB_DEVICE(0x093a, 0x050f)},
430 {} 425 {}
431}; 426};
432MODULE_DEVICE_TABLE(usb, device_table); 427MODULE_DEVICE_TABLE(usb, device_table);
@@ -451,7 +446,7 @@ static int __init sd_mod_init(void)
451{ 446{
452 if (usb_register(&sd_driver) < 0) 447 if (usb_register(&sd_driver) < 0)
453 return -1; 448 return -1;
454 PDEBUG(D_PROBE, "v%s registered", version); 449 PDEBUG(D_PROBE, "registered");
455 return 0; 450 return 0;
456} 451}
457static void __exit sd_mod_exit(void) 452static void __exit sd_mod_exit(void)
diff --git a/drivers/media/video/gspca/ov519.c b/drivers/media/video/gspca/ov519.c
index 08d99c3b78e2..83139efc4629 100644
--- a/drivers/media/video/gspca/ov519.c
+++ b/drivers/media/video/gspca/ov519.c
@@ -24,9 +24,6 @@
24 24
25#include "gspca.h" 25#include "gspca.h"
26 26
27#define DRIVER_VERSION_NUMBER KERNEL_VERSION(2, 1, 7)
28static const char version[] = "2.1.7";
29
30MODULE_AUTHOR("Jean-Francois Moine <http://moinejf.free.fr>"); 27MODULE_AUTHOR("Jean-Francois Moine <http://moinejf.free.fr>");
31MODULE_DESCRIPTION("OV519 USB Camera Driver"); 28MODULE_DESCRIPTION("OV519 USB Camera Driver");
32MODULE_LICENSE("GPL"); 29MODULE_LICENSE("GPL");
@@ -1375,7 +1372,6 @@ static int sd_config(struct gspca_dev *gspca_dev,
1375 cam->cam_mode = sif_mode; 1372 cam->cam_mode = sif_mode;
1376 cam->nmodes = sizeof sif_mode / sizeof sif_mode[0]; 1373 cam->nmodes = sizeof sif_mode / sizeof sif_mode[0];
1377 } 1374 }
1378 cam->dev_name = (char *) id->driver_info;
1379 sd->brightness = sd_ctrls[SD_BRIGHTNESS].qctrl.default_value; 1375 sd->brightness = sd_ctrls[SD_BRIGHTNESS].qctrl.default_value;
1380 sd->contrast = sd_ctrls[SD_CONTRAST].qctrl.default_value; 1376 sd->contrast = sd_ctrls[SD_CONTRAST].qctrl.default_value;
1381 sd->colors = sd_ctrls[SD_COLOR].qctrl.default_value; 1377 sd->colors = sd_ctrls[SD_COLOR].qctrl.default_value;
@@ -2129,21 +2125,20 @@ static const struct sd_desc sd_desc = {
2129}; 2125};
2130 2126
2131/* -- module initialisation -- */ 2127/* -- module initialisation -- */
2132#define DVNM(name) .driver_info = (kernel_ulong_t) name
2133static const __devinitdata struct usb_device_id device_table[] = { 2128static const __devinitdata struct usb_device_id device_table[] = {
2134 {USB_DEVICE(0x041e, 0x4052), DVNM("Creative Live! VISTA IM")}, 2129 {USB_DEVICE(0x041e, 0x4052)},
2135 {USB_DEVICE(0x041e, 0x405f), DVNM("Creative Live! VISTA VF0330")}, 2130 {USB_DEVICE(0x041e, 0x405f)},
2136 {USB_DEVICE(0x041e, 0x4060), DVNM("Creative Live! VISTA VF0350")}, 2131 {USB_DEVICE(0x041e, 0x4060)},
2137 {USB_DEVICE(0x041e, 0x4061), DVNM("Creative Live! VISTA VF0400")}, 2132 {USB_DEVICE(0x041e, 0x4061)},
2138 {USB_DEVICE(0x041e, 0x4064), DVNM("Creative Live! VISTA VF0420")}, 2133 {USB_DEVICE(0x041e, 0x4064)},
2139 {USB_DEVICE(0x041e, 0x4068), DVNM("Creative Live! VISTA VF0470")}, 2134 {USB_DEVICE(0x041e, 0x4068)},
2140 {USB_DEVICE(0x045e, 0x028c), DVNM("Microsoft xbox cam")}, 2135 {USB_DEVICE(0x045e, 0x028c)},
2141 {USB_DEVICE(0x054c, 0x0154), DVNM("Sonny toy4")}, 2136 {USB_DEVICE(0x054c, 0x0154)},
2142 {USB_DEVICE(0x054c, 0x0155), DVNM("Sonny toy5")}, 2137 {USB_DEVICE(0x054c, 0x0155)},
2143 {USB_DEVICE(0x05a9, 0x0519), DVNM("OmniVision")}, 2138 {USB_DEVICE(0x05a9, 0x0519)},
2144 {USB_DEVICE(0x05a9, 0x0530), DVNM("OmniVision")}, 2139 {USB_DEVICE(0x05a9, 0x0530)},
2145 {USB_DEVICE(0x05a9, 0x4519), DVNM("OmniVision")}, 2140 {USB_DEVICE(0x05a9, 0x4519)},
2146 {USB_DEVICE(0x05a9, 0x8519), DVNM("OmniVision")}, 2141 {USB_DEVICE(0x05a9, 0x8519)},
2147 {} 2142 {}
2148}; 2143};
2149#undef DVNAME 2144#undef DVNAME
@@ -2169,7 +2164,7 @@ static int __init sd_mod_init(void)
2169{ 2164{
2170 if (usb_register(&sd_driver) < 0) 2165 if (usb_register(&sd_driver) < 0)
2171 return -1; 2166 return -1;
2172 PDEBUG(D_PROBE, "v%s registered", version); 2167 PDEBUG(D_PROBE, "registered");
2173 return 0; 2168 return 0;
2174} 2169}
2175static void __exit sd_mod_exit(void) 2170static void __exit sd_mod_exit(void)
diff --git a/drivers/media/video/gspca/pac207.c b/drivers/media/video/gspca/pac207.c
index fa7abc411090..7ef18d578811 100644
--- a/drivers/media/video/gspca/pac207.c
+++ b/drivers/media/video/gspca/pac207.c
@@ -27,9 +27,6 @@
27 27
28#include "gspca.h" 28#include "gspca.h"
29 29
30#define DRIVER_VERSION_NUMBER KERNEL_VERSION(2, 1, 7)
31static const char version[] = "2.1.7";
32
33MODULE_AUTHOR("Hans de Goede <j.w.r.degoede@hhs.nl>"); 30MODULE_AUTHOR("Hans de Goede <j.w.r.degoede@hhs.nl>");
34MODULE_DESCRIPTION("Pixart PAC207"); 31MODULE_DESCRIPTION("Pixart PAC207");
35MODULE_LICENSE("GPL"); 32MODULE_LICENSE("GPL");
@@ -208,7 +205,7 @@ static int pac207_write_regs(struct gspca_dev *gspca_dev, u16 index,
208} 205}
209 206
210 207
211int pac207_write_reg(struct gspca_dev *gspca_dev, u16 index, u16 value) 208static int pac207_write_reg(struct gspca_dev *gspca_dev, u16 index, u16 value)
212{ 209{
213 struct usb_device *udev = gspca_dev->dev; 210 struct usb_device *udev = gspca_dev->dev;
214 int err; 211 int err;
@@ -223,8 +220,7 @@ int pac207_write_reg(struct gspca_dev *gspca_dev, u16 index, u16 value)
223 return err; 220 return err;
224} 221}
225 222
226 223static int pac207_read_reg(struct gspca_dev *gspca_dev, u16 index)
227int pac207_read_reg(struct gspca_dev *gspca_dev, u16 index)
228{ 224{
229 struct usb_device *udev = gspca_dev->dev; 225 struct usb_device *udev = gspca_dev->dev;
230 int res; 226 int res;
@@ -574,17 +570,16 @@ static const struct sd_desc sd_desc = {
574}; 570};
575 571
576/* -- module initialisation -- */ 572/* -- module initialisation -- */
577#define DVNM(name) .driver_info = (kernel_ulong_t) name
578static const __devinitdata struct usb_device_id device_table[] = { 573static const __devinitdata struct usb_device_id device_table[] = {
579 {USB_DEVICE(0x041e, 0x4028), DVNM("Creative Webcam Vista Plus")}, 574 {USB_DEVICE(0x041e, 0x4028)},
580 {USB_DEVICE(0x093a, 0x2460), DVNM("Q-Tec Webcam 100")}, 575 {USB_DEVICE(0x093a, 0x2460)},
581 {USB_DEVICE(0x093a, 0x2463), DVNM("Philips spc200nc pac207")}, 576 {USB_DEVICE(0x093a, 0x2463)},
582 {USB_DEVICE(0x093a, 0x2464), DVNM("Labtec Webcam 1200")}, 577 {USB_DEVICE(0x093a, 0x2464)},
583 {USB_DEVICE(0x093a, 0x2468), DVNM("PAC207")}, 578 {USB_DEVICE(0x093a, 0x2468)},
584 {USB_DEVICE(0x093a, 0x2470), DVNM("Genius GF112")}, 579 {USB_DEVICE(0x093a, 0x2470)},
585 {USB_DEVICE(0x093a, 0x2471), DVNM("Genius VideoCam GE111")}, 580 {USB_DEVICE(0x093a, 0x2471)},
586 {USB_DEVICE(0x093a, 0x2472), DVNM("Genius VideoCam GE110")}, 581 {USB_DEVICE(0x093a, 0x2472)},
587 {USB_DEVICE(0x2001, 0xf115), DVNM("D-Link DSB-C120")}, 582 {USB_DEVICE(0x2001, 0xf115)},
588 {} 583 {}
589}; 584};
590MODULE_DEVICE_TABLE(usb, device_table); 585MODULE_DEVICE_TABLE(usb, device_table);
@@ -609,7 +604,7 @@ static int __init sd_mod_init(void)
609{ 604{
610 if (usb_register(&sd_driver) < 0) 605 if (usb_register(&sd_driver) < 0)
611 return -1; 606 return -1;
612 PDEBUG(D_PROBE, "v%s registered", version); 607 PDEBUG(D_PROBE, "registered");
613 return 0; 608 return 0;
614} 609}
615static void __exit sd_mod_exit(void) 610static void __exit sd_mod_exit(void)
diff --git a/drivers/media/video/gspca/pac7311.c b/drivers/media/video/gspca/pac7311.c
index 5c052e31be4a..ea3d7021f401 100644
--- a/drivers/media/video/gspca/pac7311.c
+++ b/drivers/media/video/gspca/pac7311.c
@@ -23,9 +23,6 @@
23 23
24#include "gspca.h" 24#include "gspca.h"
25 25
26#define DRIVER_VERSION_NUMBER KERNEL_VERSION(2, 1, 7)
27static const char version[] = "2.1.7";
28
29MODULE_AUTHOR("Thomas Kaiser thomas@kaiser-linux.li"); 26MODULE_AUTHOR("Thomas Kaiser thomas@kaiser-linux.li");
30MODULE_DESCRIPTION("Pixart PAC7311"); 27MODULE_DESCRIPTION("Pixart PAC7311");
31MODULE_LICENSE("GPL"); 28MODULE_LICENSE("GPL");
@@ -266,7 +263,6 @@ static int sd_config(struct gspca_dev *gspca_dev,
266 reg_w(gspca_dev, 0x3e, 0x20); 263 reg_w(gspca_dev, 0x3e, 0x20);
267 264
268 cam = &gspca_dev->cam; 265 cam = &gspca_dev->cam;
269 cam->dev_name = (char *) id->driver_info;
270 cam->epaddr = 0x05; 266 cam->epaddr = 0x05;
271 cam->cam_mode = vga_mode; 267 cam->cam_mode = vga_mode;
272 cam->nmodes = ARRAY_SIZE(vga_mode); 268 cam->nmodes = ARRAY_SIZE(vga_mode);
@@ -713,16 +709,14 @@ static struct sd_desc sd_desc = {
713}; 709};
714 710
715/* -- module initialisation -- */ 711/* -- module initialisation -- */
716#define DVNM(name) .driver_info = (kernel_ulong_t) name
717static __devinitdata struct usb_device_id device_table[] = { 712static __devinitdata struct usb_device_id device_table[] = {
718 {USB_DEVICE(0x093a, 0x2600), DVNM("Typhoon")}, 713 {USB_DEVICE(0x093a, 0x2600)},
719 {USB_DEVICE(0x093a, 0x2601), DVNM("Philips SPC610NC")}, 714 {USB_DEVICE(0x093a, 0x2601)},
720 {USB_DEVICE(0x093a, 0x2603), DVNM("PAC7312")}, 715 {USB_DEVICE(0x093a, 0x2603)},
721 {USB_DEVICE(0x093a, 0x2608), DVNM("Trust WB-3300p")}, 716 {USB_DEVICE(0x093a, 0x2608)},
722 {USB_DEVICE(0x093a, 0x260e), DVNM("Gigaware VGA PC Camera")}, 717 {USB_DEVICE(0x093a, 0x260e)},
723 /* and also ', Trust WB-3350p, SIGMA cam 2350' */ 718 {USB_DEVICE(0x093a, 0x260f)},
724 {USB_DEVICE(0x093a, 0x260f), DVNM("SnakeCam")}, 719 {USB_DEVICE(0x093a, 0x2621)},
725 {USB_DEVICE(0x093a, 0x2621), DVNM("PAC731x")},
726 {} 720 {}
727}; 721};
728MODULE_DEVICE_TABLE(usb, device_table); 722MODULE_DEVICE_TABLE(usb, device_table);
@@ -747,7 +741,7 @@ static int __init sd_mod_init(void)
747{ 741{
748 if (usb_register(&sd_driver) < 0) 742 if (usb_register(&sd_driver) < 0)
749 return -1; 743 return -1;
750 PDEBUG(D_PROBE, "v%s registered", version); 744 PDEBUG(D_PROBE, "registered");
751 return 0; 745 return 0;
752} 746}
753static void __exit sd_mod_exit(void) 747static void __exit sd_mod_exit(void)
diff --git a/drivers/media/video/gspca/sonixb.c b/drivers/media/video/gspca/sonixb.c
index dbeebe8625c5..e18748c5a14d 100644
--- a/drivers/media/video/gspca/sonixb.c
+++ b/drivers/media/video/gspca/sonixb.c
@@ -24,9 +24,6 @@
24 24
25#include "gspca.h" 25#include "gspca.h"
26 26
27#define DRIVER_VERSION_NUMBER KERNEL_VERSION(2, 1, 8)
28static const char version[] = "2.1.8";
29
30MODULE_AUTHOR("Michel Xhaard <mxhaard@users.sourceforge.net>"); 27MODULE_AUTHOR("Michel Xhaard <mxhaard@users.sourceforge.net>");
31MODULE_DESCRIPTION("GSPCA/SN9C102 USB Camera Driver"); 28MODULE_DESCRIPTION("GSPCA/SN9C102 USB Camera Driver");
32MODULE_LICENSE("GPL"); 29MODULE_LICENSE("GPL");
@@ -44,25 +41,29 @@ struct sd {
44 unsigned char brightness; 41 unsigned char brightness;
45 unsigned char autogain; 42 unsigned char autogain;
46 unsigned char autogain_ignore_frames; 43 unsigned char autogain_ignore_frames;
44 unsigned char frames_to_drop;
47 unsigned char freq; /* light freq filter setting */ 45 unsigned char freq; /* light freq filter setting */
48 unsigned char saturation;
49 unsigned char hue;
50 unsigned char contrast;
51 46
52 unsigned char fr_h_sz; /* size of frame header */ 47 unsigned char fr_h_sz; /* size of frame header */
53 char sensor; /* Type of image sensor chip */ 48 char sensor; /* Type of image sensor chip */
54#define SENSOR_HV7131R 0 49#define SENSOR_HV7131R 0
55#define SENSOR_OV6650 1 50#define SENSOR_OV6650 1
56#define SENSOR_OV7630 2 51#define SENSOR_OV7630 2
57#define SENSOR_OV7630_3 3 52#define SENSOR_PAS106 3
58#define SENSOR_PAS106 4 53#define SENSOR_PAS202 4
59#define SENSOR_PAS202 5 54#define SENSOR_TAS5110 5
60#define SENSOR_TAS5110 6 55#define SENSOR_TAS5130CXX 6
61#define SENSOR_TAS5130CXX 7
62 char sensor_has_gain; 56 char sensor_has_gain;
63 __u8 sensor_addr; 57 __u8 sensor_addr;
58 __u8 reg11;
64}; 59};
65 60
61/* flags used in the device id table */
62#define F_GAIN 0x01 /* has gain */
63#define F_AUTO 0x02 /* has autogain */
64#define F_SIF 0x04 /* sif or vga */
65#define F_H18 0x08 /* long (18 b) or short (12 b) frame header */
66
66#define COMP2 0x8f 67#define COMP2 0x8f
67#define COMP 0xc7 /* 0x87 //0x07 */ 68#define COMP 0xc7 /* 0x87 //0x07 */
68#define COMP1 0xc9 /* 0x89 //0x09 */ 69#define COMP1 0xc9 /* 0x89 //0x09 */
@@ -92,12 +93,6 @@ static int sd_setautogain(struct gspca_dev *gspca_dev, __s32 val);
92static int sd_getautogain(struct gspca_dev *gspca_dev, __s32 *val); 93static int sd_getautogain(struct gspca_dev *gspca_dev, __s32 *val);
93static int sd_setfreq(struct gspca_dev *gspca_dev, __s32 val); 94static int sd_setfreq(struct gspca_dev *gspca_dev, __s32 val);
94static int sd_getfreq(struct gspca_dev *gspca_dev, __s32 *val); 95static int sd_getfreq(struct gspca_dev *gspca_dev, __s32 *val);
95static int sd_setsaturation(struct gspca_dev *gspca_dev, __s32 val);
96static int sd_getsaturation(struct gspca_dev *gspca_dev, __s32 *val);
97static int sd_sethue(struct gspca_dev *gspca_dev, __s32 val);
98static int sd_gethue(struct gspca_dev *gspca_dev, __s32 *val);
99static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val);
100static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val);
101 96
102static struct ctrl sd_ctrls[] = { 97static struct ctrl sd_ctrls[] = {
103 { 98 {
@@ -174,48 +169,6 @@ static struct ctrl sd_ctrls[] = {
174 .set = sd_setfreq, 169 .set = sd_setfreq,
175 .get = sd_getfreq, 170 .get = sd_getfreq,
176 }, 171 },
177 {
178 {
179 .id = V4L2_CID_SATURATION,
180 .type = V4L2_CTRL_TYPE_INTEGER,
181 .name = "Saturation",
182 .minimum = 0,
183 .maximum = 255,
184 .step = 1,
185#define SATURATION_DEF 127
186 .default_value = SATURATION_DEF,
187 },
188 .set = sd_setsaturation,
189 .get = sd_getsaturation,
190 },
191 {
192 {
193 .id = V4L2_CID_HUE,
194 .type = V4L2_CTRL_TYPE_INTEGER,
195 .name = "Hue",
196 .minimum = 0,
197 .maximum = 255,
198 .step = 1,
199#define HUE_DEF 127
200 .default_value = HUE_DEF,
201 },
202 .set = sd_sethue,
203 .get = sd_gethue,
204 },
205 {
206 {
207 .id = V4L2_CID_CONTRAST,
208 .type = V4L2_CTRL_TYPE_INTEGER,
209 .name = "Contrast",
210 .minimum = 0,
211 .maximum = 255,
212 .step = 1,
213#define CONTRAST_DEF 127
214 .default_value = CONTRAST_DEF,
215 },
216 .set = sd_setcontrast,
217 .get = sd_getcontrast,
218 },
219}; 172};
220 173
221static struct v4l2_pix_format vga_mode[] = { 174static struct v4l2_pix_format vga_mode[] = {
@@ -248,8 +201,6 @@ static struct v4l2_pix_format sif_mode[] = {
248 .priv = 0}, 201 .priv = 0},
249}; 202};
250 203
251static const __u8 probe_ov7630[] = {0x08, 0x44};
252
253static const __u8 initHv7131[] = { 204static const __u8 initHv7131[] = {
254 0x46, 0x77, 0x00, 0x04, 0x00, 0x00, 0x00, 0x80, 0x11, 0x00, 0x00, 0x00, 205 0x46, 0x77, 0x00, 0x04, 0x00, 0x00, 0x00, 0x80, 0x11, 0x00, 0x00, 0x00,
255 0x00, 0x00, 206 0x00, 0x00,
@@ -321,7 +272,7 @@ static const __u8 initOv7630_3[] = {
321 0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70, 0x80, /* r21 .. r28 */ 272 0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70, 0x80, /* r21 .. r28 */
322 0x90, 0xa0, 0xb0, 0xc0, 0xd0, 0xe0, 0xf0, 0xff /* r29 .. r30 */ 273 0x90, 0xa0, 0xb0, 0xc0, 0xd0, 0xe0, 0xf0, 0xff /* r29 .. r30 */
323}; 274};
324static const __u8 ov7630_sensor_init_com[][8] = { 275static const __u8 ov7630_sensor_init[][8] = {
325 {0xa0, 0x21, 0x12, 0x80, 0x00, 0x00, 0x00, 0x10}, 276 {0xa0, 0x21, 0x12, 0x80, 0x00, 0x00, 0x00, 0x10},
326 {0xb0, 0x21, 0x01, 0x77, 0x3a, 0x00, 0x00, 0x10}, 277 {0xb0, 0x21, 0x01, 0x77, 0x3a, 0x00, 0x00, 0x10},
327/* {0xd0, 0x21, 0x12, 0x7c, 0x01, 0x80, 0x34, 0x10}, jfm */ 278/* {0xd0, 0x21, 0x12, 0x7c, 0x01, 0x80, 0x34, 0x10}, jfm */
@@ -342,17 +293,6 @@ static const __u8 ov7630_sensor_init_com[][8] = {
342 {0xa0, 0x21, 0x7d, 0xf7, 0x8e, 0x00, 0x30, 0x10}, 293 {0xa0, 0x21, 0x7d, 0xf7, 0x8e, 0x00, 0x30, 0x10},
343 {0xd0, 0x21, 0x17, 0x1c, 0xbd, 0x06, 0xf6, 0x10}, 294 {0xd0, 0x21, 0x17, 0x1c, 0xbd, 0x06, 0xf6, 0x10},
344}; 295};
345static const __u8 ov7630_sensor_init[][8] = {
346 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* delay 200ms */
347 {0xa0, 0x21, 0x11, 0x01, 0xbd, 0x06, 0xf6, 0x10}, /* jfm */
348 {0xa0, 0x21, 0x10, 0x57, 0xbd, 0x06, 0xf6, 0x16},
349 {0xa0, 0x21, 0x76, 0x02, 0xbd, 0x06, 0xf6, 0x16},
350 {0xa0, 0x21, 0x00, 0x10, 0xbd, 0x06, 0xf6, 0x15}, /* gain */
351};
352static const __u8 ov7630_sensor_init_3[][8] = {
353 {0xa0, 0x21, 0x2a, 0xa0, 0x00, 0x00, 0x00, 0x10},
354 {0xa0, 0x21, 0x2a, 0x80, 0x00, 0x00, 0x00, 0x10},
355};
356 296
357static const __u8 initPas106[] = { 297static const __u8 initPas106[] = {
358 0x04, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x81, 0x40, 0x00, 0x00, 0x00, 298 0x04, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x81, 0x40, 0x00, 0x00, 0x00,
@@ -542,7 +482,6 @@ static void setbrightness(struct gspca_dev *gspca_dev)
542 482
543 switch (sd->sensor) { 483 switch (sd->sensor) {
544 case SENSOR_OV6650: 484 case SENSOR_OV6650:
545 case SENSOR_OV7630_3:
546 case SENSOR_OV7630: { 485 case SENSOR_OV7630: {
547 __u8 i2cOV[] = 486 __u8 i2cOV[] =
548 {0xa0, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x10}; 487 {0xa0, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x10};
@@ -635,7 +574,7 @@ static void setsensorgain(struct gspca_dev *gspca_dev)
635 case SENSOR_OV6650: 574 case SENSOR_OV6650:
636 gain >>= 1; 575 gain >>= 1;
637 /* fall thru */ 576 /* fall thru */
638 case SENSOR_OV7630_3: { 577 case SENSOR_OV7630: {
639 __u8 i2c[] = {0xa0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10}; 578 __u8 i2c[] = {0xa0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10};
640 579
641 i2c[1] = sd->sensor_addr; 580 i2c[1] = sd->sensor_addr;
@@ -690,7 +629,7 @@ static void setexposure(struct gspca_dev *gspca_dev)
690 break; 629 break;
691 } 630 }
692 case SENSOR_OV6650: 631 case SENSOR_OV6650:
693 case SENSOR_OV7630_3: { 632 case SENSOR_OV7630: {
694 /* The ov6650 / ov7630 have 2 registers which both influence 633 /* The ov6650 / ov7630 have 2 registers which both influence
695 exposure, register 11, whose low nibble sets the nr off fps 634 exposure, register 11, whose low nibble sets the nr off fps
696 according to: fps = 30 / (low_nibble + 1) 635 according to: fps = 30 / (low_nibble + 1)
@@ -705,16 +644,20 @@ static void setexposure(struct gspca_dev *gspca_dev)
705 The code maps our 0 - 510 ms exposure ctrl to these 2 644 The code maps our 0 - 510 ms exposure ctrl to these 2
706 registers, trying to keep fps as high as possible. 645 registers, trying to keep fps as high as possible.
707 */ 646 */
708 __u8 i2c[] = {0xb0, 0x00, 0x10, 0x00, 0xc0, 0x00, 0x00, 0x10}; 647 __u8 i2c[] = {0xb0, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x10};
709 int reg10, reg11; 648 int reg10, reg11, reg10_max;
649
710 /* ov6645 datasheet says reg10_max is 9a, but that uses 650 /* ov6645 datasheet says reg10_max is 9a, but that uses
711 tline * 2 * reg10 as formula for calculating texpo, the 651 tline * 2 * reg10 as formula for calculating texpo, the
712 ov6650 probably uses the same formula as the 7730 which uses 652 ov6650 probably uses the same formula as the 7730 which uses
713 tline * 4 * reg10, which explains why the reg10max we've 653 tline * 4 * reg10, which explains why the reg10max we've
714 found experimentally for the ov6650 is exactly half that of 654 found experimentally for the ov6650 is exactly half that of
715 the ov6645. The ov7630 datasheet says the max is 0x41. */ 655 the ov6645. The ov7630 datasheet says the max is 0x41. */
716 const int reg10_max = (sd->sensor == SENSOR_OV6650) 656 if (sd->sensor == SENSOR_OV6650) {
717 ? 0x4d : 0x41; 657 reg10_max = 0x4d;
658 i2c[4] = 0xc0; /* OV6650 needs non default vsync pol */
659 } else
660 reg10_max = 0x41;
718 661
719 reg11 = (60 * sd->exposure + 999) / 1000; 662 reg11 = (60 * sd->exposure + 999) / 1000;
720 if (reg11 < 1) 663 if (reg11 < 1)
@@ -735,20 +678,23 @@ static void setexposure(struct gspca_dev *gspca_dev)
735 else if (reg10 > reg10_max) 678 else if (reg10 > reg10_max)
736 reg10 = reg10_max; 679 reg10 = reg10_max;
737 680
681 /* In 640x480, if the reg11 has less than 3, the image is
682 unstable (not enough bandwidth). */
683 if (gspca_dev->width == 640 && reg11 < 3)
684 reg11 = 3;
685
738 /* Write reg 10 and reg11 low nibble */ 686 /* Write reg 10 and reg11 low nibble */
739 i2c[1] = sd->sensor_addr; 687 i2c[1] = sd->sensor_addr;
740 i2c[3] = reg10; 688 i2c[3] = reg10;
741 i2c[4] |= reg11 - 1; 689 i2c[4] |= reg11 - 1;
742 if (sd->sensor == SENSOR_OV7630_3) { 690
743 __u8 reg76 = reg10 & 0x03; 691 /* If register 11 didn't change, don't change it */
744 __u8 i2c_reg76[] = {0xa0, 0x21, 0x76, 0x00, 692 if (sd->reg11 == reg11 )
745 0x00, 0x00, 0x00, 0x10}; 693 i2c[0] = 0xa0;
746 reg10 >>= 2; 694
747 i2c_reg76[3] = reg76; 695 if (i2c_w(gspca_dev, i2c) == 0)
748 if (i2c_w(gspca_dev, i2c_reg76) < 0) 696 sd->reg11 = reg11;
749 PDEBUG(D_ERR, "i2c error exposure"); 697 else
750 }
751 if (i2c_w(gspca_dev, i2c) < 0)
752 PDEBUG(D_ERR, "i2c error exposure"); 698 PDEBUG(D_ERR, "i2c error exposure");
753 break; 699 break;
754 } 700 }
@@ -761,11 +707,11 @@ static void setfreq(struct gspca_dev *gspca_dev)
761 707
762 switch (sd->sensor) { 708 switch (sd->sensor) {
763 case SENSOR_OV6650: 709 case SENSOR_OV6650:
764 case SENSOR_OV7630_3: { 710 case SENSOR_OV7630: {
765 /* Framerate adjust register for artificial light 50 hz flicker 711 /* Framerate adjust register for artificial light 50 hz flicker
766 compensation, identical to ov6630 0x2b register, see ov6630 712 compensation, for the ov6650 this is identical to ov6630
767 datasheet. 713 0x2b register, see ov6630 datasheet.
768 0x4f -> (30 fps -> 25 fps), 0x00 -> no adjustment */ 714 0x4f / 0x8a -> (30 fps -> 25 fps), 0x00 -> no adjustment */
769 __u8 i2c[] = {0xa0, 0x00, 0x2b, 0x00, 0x00, 0x00, 0x00, 0x10}; 715 __u8 i2c[] = {0xa0, 0x00, 0x2b, 0x00, 0x00, 0x00, 0x00, 0x10};
770 switch (sd->freq) { 716 switch (sd->freq) {
771 default: 717 default:
@@ -786,69 +732,6 @@ static void setfreq(struct gspca_dev *gspca_dev)
786 } 732 }
787} 733}
788 734
789static void setsaturation(struct gspca_dev *gspca_dev)
790{
791 struct sd *sd = (struct sd *) gspca_dev;
792
793 switch (sd->sensor) {
794/* case SENSOR_OV6650: */
795 case SENSOR_OV7630_3:
796 case SENSOR_OV7630: {
797 __u8 i2c[] = {0xa0, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x10};
798 i2c[1] = sd->sensor_addr;
799 i2c[3] = sd->saturation & 0xf0;
800 if (i2c_w(gspca_dev, i2c) < 0)
801 PDEBUG(D_ERR, "i2c error setsaturation");
802 else
803 PDEBUG(D_CONF, "saturation set to: %d",
804 (int)sd->saturation);
805 break;
806 }
807 }
808}
809
810static void sethue(struct gspca_dev *gspca_dev)
811{
812 struct sd *sd = (struct sd *) gspca_dev;
813
814 switch (sd->sensor) {
815/* case SENSOR_OV6650: */
816 case SENSOR_OV7630_3:
817 case SENSOR_OV7630: {
818 __u8 i2c[] = {0xa0, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x10};
819 i2c[1] = sd->sensor_addr;
820 i2c[3] = 0x20 | (sd->hue >> 3);
821 if (i2c_w(gspca_dev, i2c) < 0)
822 PDEBUG(D_ERR, "i2c error setsaturation");
823 else
824 PDEBUG(D_CONF, "hue set to: %d", (int)sd->hue);
825 break;
826 }
827 }
828}
829
830static void setcontrast(struct gspca_dev *gspca_dev)
831{
832 struct sd *sd = (struct sd *) gspca_dev;
833
834 switch (sd->sensor) {
835/* case SENSOR_OV6650: */
836 case SENSOR_OV7630_3:
837 case SENSOR_OV7630: {
838 __u8 i2c[] = {0xa0, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x10};
839 i2c[1] = sd->sensor_addr;
840 i2c[3] = 0x20 | (sd->contrast >> 3);
841 if (i2c_w(gspca_dev, i2c) < 0)
842 PDEBUG(D_ERR, "i2c error setcontrast");
843 else
844 PDEBUG(D_CONF, "contrast set to: %d",
845 (int)sd->contrast);
846 break;
847 }
848 }
849}
850
851
852static void do_autogain(struct gspca_dev *gspca_dev) 735static void do_autogain(struct gspca_dev *gspca_dev)
853{ 736{
854 struct sd *sd = (struct sd *) gspca_dev; 737 struct sd *sd = (struct sd *) gspca_dev;
@@ -874,88 +757,32 @@ static int sd_config(struct gspca_dev *gspca_dev,
874{ 757{
875 struct sd *sd = (struct sd *) gspca_dev; 758 struct sd *sd = (struct sd *) gspca_dev;
876 struct cam *cam; 759 struct cam *cam;
877 __u16 product;
878 int sif = 0; 760 int sif = 0;
879 761
880 /* nctrls depends upon the sensor, so we use a per cam copy */ 762 /* nctrls depends upon the sensor, so we use a per cam copy */
881 memcpy(&sd->sd_desc, gspca_dev->sd_desc, sizeof(struct sd_desc)); 763 memcpy(&sd->sd_desc, gspca_dev->sd_desc, sizeof(struct sd_desc));
882 gspca_dev->sd_desc = &sd->sd_desc; 764 gspca_dev->sd_desc = &sd->sd_desc;
883 765
884 sd->fr_h_sz = 12; /* default size of the frame header */ 766 /* copy the webcam info from the device id */
885 sd->sd_desc.nctrls = 2; /* default nb of ctrls */ 767 sd->sensor = (id->driver_info >> 24) & 0xff;
886 sd->autogain = AUTOGAIN_DEF; /* default is autogain active */ 768 if (id->driver_info & (F_GAIN << 16))
887 769 sd->sensor_has_gain = 1;
888 product = id->idProduct; 770 if (id->driver_info & (F_AUTO << 16))
889/* switch (id->idVendor) { */ 771 sd->sd_desc.dq_callback = do_autogain;
890/* case 0x0c45: * Sonix */ 772 if (id->driver_info & (F_SIF << 16))
891 switch (product) { 773 sif = 1;
892 case 0x6001: /* SN9C102 */ 774 if (id->driver_info & (F_H18 << 16))
893 case 0x6005: /* SN9C101 */ 775 sd->fr_h_sz = 18; /* size of frame header */
894 case 0x6007: /* SN9C101 */ 776 else
895 sd->sensor = SENSOR_TAS5110; 777 sd->fr_h_sz = 12;
896 sd->sensor_has_gain = 1; 778 sd->sd_desc.nctrls = (id->driver_info >> 8) & 0xff;
897 sd->sd_desc.nctrls = 4; 779 sd->sensor_addr = id->driver_info & 0xff;
898 sd->sd_desc.dq_callback = do_autogain;
899 sif = 1;
900 break;
901 case 0x6009: /* SN9C101 */
902 case 0x600d: /* SN9C101 */
903 case 0x6029: /* SN9C101 */
904 sd->sensor = SENSOR_PAS106;
905 sif = 1;
906 break;
907 case 0x6011: /* SN9C101 - SN9C101G */
908 sd->sensor = SENSOR_OV6650;
909 sd->sensor_has_gain = 1;
910 sd->sensor_addr = 0x60;
911 sd->sd_desc.nctrls = 5;
912 sd->sd_desc.dq_callback = do_autogain;
913 sif = 1;
914 break;
915 case 0x6019: /* SN9C101 */
916 case 0x602c: /* SN9C102 */
917 case 0x602e: /* SN9C102 */
918 sd->sensor = SENSOR_OV7630;
919 sd->sensor_addr = 0x21;
920 break;
921 case 0x60b0: /* SN9C103 */
922 sd->sensor = SENSOR_OV7630_3;
923 sd->sensor_addr = 0x21;
924 sd->fr_h_sz = 18; /* size of frame header */
925 sd->sensor_has_gain = 1;
926 sd->sd_desc.nctrls = 8;
927 sd->sd_desc.dq_callback = do_autogain;
928 sd->autogain = 0;
929 break;
930 case 0x6024: /* SN9C102 */
931 case 0x6025: /* SN9C102 */
932 sd->sensor = SENSOR_TAS5130CXX;
933 break;
934 case 0x6028: /* SN9C102 */
935 sd->sensor = SENSOR_PAS202;
936 break;
937 case 0x602d: /* SN9C102 */
938 sd->sensor = SENSOR_HV7131R;
939 break;
940 case 0x60af: /* SN9C103 */
941 sd->sensor = SENSOR_PAS202;
942 sd->fr_h_sz = 18; /* size of frame header (?) */
943 break;
944 }
945/* break; */
946/* } */
947 780
948 cam = &gspca_dev->cam; 781 cam = &gspca_dev->cam;
949 cam->dev_name = (char *) id->driver_info;
950 cam->epaddr = 0x01; 782 cam->epaddr = 0x01;
951 if (!sif) { 783 if (!sif) {
952 cam->cam_mode = vga_mode; 784 cam->cam_mode = vga_mode;
953 cam->nmodes = ARRAY_SIZE(vga_mode); 785 cam->nmodes = ARRAY_SIZE(vga_mode);
954 if (sd->sensor == SENSOR_OV7630_3) {
955 /* We only have 320x240 & 640x480 */
956 cam->cam_mode++;
957 cam->nmodes--;
958 }
959 } else { 786 } else {
960 cam->cam_mode = sif_mode; 787 cam->cam_mode = sif_mode;
961 cam->nmodes = ARRAY_SIZE(sif_mode); 788 cam->nmodes = ARRAY_SIZE(sif_mode);
@@ -963,12 +790,9 @@ static int sd_config(struct gspca_dev *gspca_dev,
963 sd->brightness = BRIGHTNESS_DEF; 790 sd->brightness = BRIGHTNESS_DEF;
964 sd->gain = GAIN_DEF; 791 sd->gain = GAIN_DEF;
965 sd->exposure = EXPOSURE_DEF; 792 sd->exposure = EXPOSURE_DEF;
793 sd->autogain = AUTOGAIN_DEF;
966 sd->freq = FREQ_DEF; 794 sd->freq = FREQ_DEF;
967 sd->contrast = CONTRAST_DEF; 795
968 sd->saturation = SATURATION_DEF;
969 sd->hue = HUE_DEF;
970 if (sd->sensor == SENSOR_OV7630_3) /* jfm: from win trace */
971 reg_w(gspca_dev, 0x01, probe_ov7630, sizeof probe_ov7630);
972 return 0; 796 return 0;
973} 797}
974 798
@@ -1002,9 +826,8 @@ static void pas106_i2cinit(struct gspca_dev *gspca_dev)
1002static void sd_start(struct gspca_dev *gspca_dev) 826static void sd_start(struct gspca_dev *gspca_dev)
1003{ 827{
1004 struct sd *sd = (struct sd *) gspca_dev; 828 struct sd *sd = (struct sd *) gspca_dev;
1005 int mode, l; 829 int mode, l = 0x1f;
1006 const __u8 *sn9c10x; 830 const __u8 *sn9c10x;
1007 __u8 reg01, reg17;
1008 __u8 reg17_19[3]; 831 __u8 reg17_19[3];
1009 832
1010 mode = gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv; 833 mode = gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv;
@@ -1022,13 +845,11 @@ static void sd_start(struct gspca_dev *gspca_dev)
1022 reg17_19[2] = 0x20; 845 reg17_19[2] = 0x20;
1023 break; 846 break;
1024 case SENSOR_OV7630: 847 case SENSOR_OV7630:
1025 sn9c10x = initOv7630; 848 if (sd->fr_h_sz == 18) { /* SN9C103 */
1026 reg17_19[0] = 0x68; 849 sn9c10x = initOv7630_3;
1027 reg17_19[1] = (mode << 4) | COMP2; 850 l = sizeof initOv7630_3;
1028 reg17_19[2] = MCK_INIT1; 851 } else
1029 break; 852 sn9c10x = initOv7630;
1030 case SENSOR_OV7630_3:
1031 sn9c10x = initOv7630_3;
1032 reg17_19[0] = 0x68; 853 reg17_19[0] = 0x68;
1033 reg17_19[1] = (mode << 4) | COMP2; 854 reg17_19[1] = (mode << 4) | COMP2;
1034 reg17_19[2] = MCK_INIT1; 855 reg17_19[2] = MCK_INIT1;
@@ -1059,30 +880,11 @@ static void sd_start(struct gspca_dev *gspca_dev)
1059 reg17_19[2] = mode ? 0x23 : 0x43; 880 reg17_19[2] = mode ? 0x23 : 0x43;
1060 break; 881 break;
1061 } 882 }
1062 switch (sd->sensor) {
1063 case SENSOR_OV7630:
1064 reg01 = 0x06;
1065 reg17 = 0x29;
1066 l = sizeof initOv7630;
1067 break;
1068 case SENSOR_OV7630_3:
1069 reg01 = 0x44;
1070 reg17 = 0x68;
1071 l = sizeof initOv7630_3;
1072 break;
1073 default:
1074 reg01 = sn9c10x[0];
1075 reg17 = sn9c10x[0x17 - 1];
1076 l = 0x1f;
1077 break;
1078 }
1079 883
1080 /* reg 0x01 bit 2 video transfert on */ 884 /* reg 0x01 bit 2 video transfert on */
1081 reg_w(gspca_dev, 0x01, &reg01, 1); 885 reg_w(gspca_dev, 0x01, &sn9c10x[0x01 - 1], 1);
1082 /* reg 0x17 SensorClk enable inv Clk 0x60 */ 886 /* reg 0x17 SensorClk enable inv Clk 0x60 */
1083 reg_w(gspca_dev, 0x17, &reg17, 1); 887 reg_w(gspca_dev, 0x17, &sn9c10x[0x17 - 1], 1);
1084/*fixme: for ov7630 102
1085 reg_w(gspca_dev, 0x01, {0x06, sn9c10x[1]}, 2); */
1086 /* Set the registers from the template */ 888 /* Set the registers from the template */
1087 reg_w_big(gspca_dev, 0x01, sn9c10x, l); 889 reg_w_big(gspca_dev, 0x01, sn9c10x, l);
1088 switch (sd->sensor) { 890 switch (sd->sensor) {
@@ -1095,17 +897,13 @@ static void sd_start(struct gspca_dev *gspca_dev)
1095 sizeof ov6650_sensor_init); 897 sizeof ov6650_sensor_init);
1096 break; 898 break;
1097 case SENSOR_OV7630: 899 case SENSOR_OV7630:
1098 i2c_w_vector(gspca_dev, ov7630_sensor_init_com,
1099 sizeof ov7630_sensor_init_com);
1100 msleep(200);
1101 i2c_w_vector(gspca_dev, ov7630_sensor_init, 900 i2c_w_vector(gspca_dev, ov7630_sensor_init,
1102 sizeof ov7630_sensor_init); 901 sizeof ov7630_sensor_init);
1103 break; 902 if (sd->fr_h_sz == 18) { /* SN9C103 */
1104 case SENSOR_OV7630_3: 903 const __u8 i2c[] = { 0xa0, 0x21, 0x13, 0x80, 0x00,
1105 i2c_w_vector(gspca_dev, ov7630_sensor_init_com, 904 0x00, 0x00, 0x10 };
1106 sizeof ov7630_sensor_init_com); 905 i2c_w(gspca_dev, i2c);
1107 msleep(200); 906 }
1108 i2c_w(gspca_dev, ov7630_sensor_init_3[mode]);
1109 break; 907 break;
1110 case SENSOR_PAS106: 908 case SENSOR_PAS106:
1111 pas106_i2cinit(gspca_dev); 909 pas106_i2cinit(gspca_dev);
@@ -1145,14 +943,14 @@ static void sd_start(struct gspca_dev *gspca_dev)
1145 reg_w(gspca_dev, 0x18, &reg17_19[1], 2); 943 reg_w(gspca_dev, 0x18, &reg17_19[1], 2);
1146 msleep(20); 944 msleep(20);
1147 945
946 sd->reg11 = -1;
947
1148 setgain(gspca_dev); 948 setgain(gspca_dev);
1149 setbrightness(gspca_dev); 949 setbrightness(gspca_dev);
1150 setexposure(gspca_dev); 950 setexposure(gspca_dev);
1151 setfreq(gspca_dev); 951 setfreq(gspca_dev);
1152 setsaturation(gspca_dev);
1153 sethue(gspca_dev);
1154 setcontrast(gspca_dev);
1155 952
953 sd->frames_to_drop = 0;
1156 sd->autogain_ignore_frames = 0; 954 sd->autogain_ignore_frames = 0;
1157 atomic_set(&sd->avg_lum, -1); 955 atomic_set(&sd->avg_lum, -1);
1158} 956}
@@ -1198,21 +996,31 @@ static void sd_pkt_scan(struct gspca_dev *gspca_dev,
1198 && data[3 + i] == 0xc4 996 && data[3 + i] == 0xc4
1199 && data[4 + i] == 0xc4 997 && data[4 + i] == 0xc4
1200 && data[5 + i] == 0x96) { /* start of frame */ 998 && data[5 + i] == 0x96) { /* start of frame */
1201 frame = gspca_frame_add(gspca_dev, LAST_PACKET, 999 int lum = -1;
1202 frame, data, 0); 1000 int pkt_type = LAST_PACKET;
1001
1203 if (len - i < sd->fr_h_sz) { 1002 if (len - i < sd->fr_h_sz) {
1204 atomic_set(&sd->avg_lum, -1);
1205 PDEBUG(D_STREAM, "packet too short to" 1003 PDEBUG(D_STREAM, "packet too short to"
1206 " get avg brightness"); 1004 " get avg brightness");
1207 } else if (sd->fr_h_sz == 12) { 1005 } else if (sd->fr_h_sz == 12) {
1208 atomic_set(&sd->avg_lum, 1006 lum = data[i + 8] + (data[i + 9] << 8);
1209 data[i + 8] +
1210 (data[i + 9] << 8));
1211 } else { 1007 } else {
1212 atomic_set(&sd->avg_lum, 1008 lum = data[i + 9] +
1213 data[i + 9] + 1009 (data[i + 10] << 8);
1214 (data[i + 10] << 8)); 1010 }
1011 if (lum == 0) {
1012 lum = -1;
1013 sd->frames_to_drop = 2;
1014 }
1015 atomic_set(&sd->avg_lum, lum);
1016
1017 if (sd->frames_to_drop) {
1018 sd->frames_to_drop--;
1019 pkt_type = DISCARD_PACKET;
1215 } 1020 }
1021
1022 frame = gspca_frame_add(gspca_dev, pkt_type,
1023 frame, data, 0);
1216 data += i + sd->fr_h_sz; 1024 data += i + sd->fr_h_sz;
1217 len -= i + sd->fr_h_sz; 1025 len -= i + sd->fr_h_sz;
1218 gspca_frame_add(gspca_dev, FIRST_PACKET, 1026 gspca_frame_add(gspca_dev, FIRST_PACKET,
@@ -1327,60 +1135,6 @@ static int sd_getfreq(struct gspca_dev *gspca_dev, __s32 *val)
1327 return 0; 1135 return 0;
1328} 1136}
1329 1137
1330static int sd_setsaturation(struct gspca_dev *gspca_dev, __s32 val)
1331{
1332 struct sd *sd = (struct sd *) gspca_dev;
1333
1334 sd->saturation = val;
1335 if (gspca_dev->streaming)
1336 setsaturation(gspca_dev);
1337 return 0;
1338}
1339
1340static int sd_getsaturation(struct gspca_dev *gspca_dev, __s32 *val)
1341{
1342 struct sd *sd = (struct sd *) gspca_dev;
1343
1344 *val = sd->saturation;
1345 return 0;
1346}
1347
1348static int sd_sethue(struct gspca_dev *gspca_dev, __s32 val)
1349{
1350 struct sd *sd = (struct sd *) gspca_dev;
1351
1352 sd->hue = val;
1353 if (gspca_dev->streaming)
1354 sethue(gspca_dev);
1355 return 0;
1356}
1357
1358static int sd_gethue(struct gspca_dev *gspca_dev, __s32 *val)
1359{
1360 struct sd *sd = (struct sd *) gspca_dev;
1361
1362 *val = sd->hue;
1363 return 0;
1364}
1365
1366static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val)
1367{
1368 struct sd *sd = (struct sd *) gspca_dev;
1369
1370 sd->contrast = val;
1371 if (gspca_dev->streaming)
1372 setcontrast(gspca_dev);
1373 return 0;
1374}
1375
1376static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val)
1377{
1378 struct sd *sd = (struct sd *) gspca_dev;
1379
1380 *val = sd->contrast;
1381 return 0;
1382}
1383
1384static int sd_querymenu(struct gspca_dev *gspca_dev, 1138static int sd_querymenu(struct gspca_dev *gspca_dev,
1385 struct v4l2_querymenu *menu) 1139 struct v4l2_querymenu *menu)
1386{ 1140{
@@ -1418,27 +1172,47 @@ static const struct sd_desc sd_desc = {
1418}; 1172};
1419 1173
1420/* -- module initialisation -- */ 1174/* -- module initialisation -- */
1421#define DVNM(name) .driver_info = (kernel_ulong_t) name 1175#define SFCI(sensor, flags, nctrls, i2c_addr) \
1176 .driver_info = (SENSOR_ ## sensor << 24) \
1177 | ((flags) << 16) \
1178 | ((nctrls) << 8) \
1179 | (i2c_addr)
1422static __devinitdata struct usb_device_id device_table[] = { 1180static __devinitdata struct usb_device_id device_table[] = {
1423#ifndef CONFIG_USB_SN9C102 1181#ifndef CONFIG_USB_SN9C102
1424 {USB_DEVICE(0x0c45, 0x6001), DVNM("Genius VideoCAM NB")}, 1182 {USB_DEVICE(0x0c45, 0x6001), /* SN9C102 */
1425 {USB_DEVICE(0x0c45, 0x6005), DVNM("Sweex Tas5110")}, 1183 SFCI(TAS5110, F_GAIN|F_AUTO|F_SIF, 4, 0)},
1426 {USB_DEVICE(0x0c45, 0x6007), DVNM("Sonix sn9c101 + Tas5110D")}, 1184 {USB_DEVICE(0x0c45, 0x6005), /* SN9C101 */
1427 {USB_DEVICE(0x0c45, 0x6009), DVNM("spcaCam@120")}, 1185 SFCI(TAS5110, F_GAIN|F_AUTO|F_SIF, 4, 0)},
1428 {USB_DEVICE(0x0c45, 0x600d), DVNM("spcaCam@120")}, 1186 {USB_DEVICE(0x0c45, 0x6007), /* SN9C101 */
1187 SFCI(TAS5110, F_GAIN|F_AUTO|F_SIF, 4, 0)},
1188 {USB_DEVICE(0x0c45, 0x6009), /* SN9C101 */
1189 SFCI(PAS106, F_SIF, 2, 0)},
1190 {USB_DEVICE(0x0c45, 0x600d), /* SN9C101 */
1191 SFCI(PAS106, F_SIF, 2, 0)},
1429#endif 1192#endif
1430 {USB_DEVICE(0x0c45, 0x6011), DVNM("MAX Webcam Microdia")}, 1193 {USB_DEVICE(0x0c45, 0x6011), /* SN9C101 - SN9C101G */
1194 SFCI(OV6650, F_GAIN|F_AUTO|F_SIF, 5, 0x60)},
1431#ifndef CONFIG_USB_SN9C102 1195#ifndef CONFIG_USB_SN9C102
1432 {USB_DEVICE(0x0c45, 0x6019), DVNM("Generic Sonix OV7630")}, 1196 {USB_DEVICE(0x0c45, 0x6019), /* SN9C101 */
1433 {USB_DEVICE(0x0c45, 0x6024), DVNM("Generic Sonix Tas5130c")}, 1197 SFCI(OV7630, F_GAIN|F_AUTO, 5, 0x21)},
1434 {USB_DEVICE(0x0c45, 0x6025), DVNM("Xcam Shanga")}, 1198 {USB_DEVICE(0x0c45, 0x6024), /* SN9C102 */
1435 {USB_DEVICE(0x0c45, 0x6028), DVNM("Sonix Btc Pc380")}, 1199 SFCI(TAS5130CXX, 0, 2, 0)},
1436 {USB_DEVICE(0x0c45, 0x6029), DVNM("spcaCam@150")}, 1200 {USB_DEVICE(0x0c45, 0x6025), /* SN9C102 */
1437 {USB_DEVICE(0x0c45, 0x602c), DVNM("Generic Sonix OV7630")}, 1201 SFCI(TAS5130CXX, 0, 2, 0)},
1438 {USB_DEVICE(0x0c45, 0x602d), DVNM("LIC-200 LG")}, 1202 {USB_DEVICE(0x0c45, 0x6028), /* SN9C102 */
1439 {USB_DEVICE(0x0c45, 0x602e), DVNM("Genius VideoCam Messenger")}, 1203 SFCI(PAS202, 0, 2, 0)},
1440 {USB_DEVICE(0x0c45, 0x60af), DVNM("Trust WB3100P")}, 1204 {USB_DEVICE(0x0c45, 0x6029), /* SN9C101 */
1441 {USB_DEVICE(0x0c45, 0x60b0), DVNM("Genius VideoCam Look")}, 1205 SFCI(PAS106, F_SIF, 2, 0)},
1206 {USB_DEVICE(0x0c45, 0x602c), /* SN9C102 */
1207 SFCI(OV7630, F_GAIN|F_AUTO, 5, 0x21)},
1208 {USB_DEVICE(0x0c45, 0x602d), /* SN9C102 */
1209 SFCI(HV7131R, 0, 2, 0)},
1210 {USB_DEVICE(0x0c45, 0x602e), /* SN9C102 */
1211 SFCI(OV7630, F_GAIN|F_AUTO, 5, 0x21)},
1212 {USB_DEVICE(0x0c45, 0x60af), /* SN9C103 */
1213 SFCI(PAS202, F_H18, 2, 0)},
1214 {USB_DEVICE(0x0c45, 0x60b0), /* SN9C103 */
1215 SFCI(OV7630, F_GAIN|F_AUTO|F_H18, 5, 0x21)},
1442#endif 1216#endif
1443 {} 1217 {}
1444}; 1218};
@@ -1464,7 +1238,7 @@ static int __init sd_mod_init(void)
1464{ 1238{
1465 if (usb_register(&sd_driver) < 0) 1239 if (usb_register(&sd_driver) < 0)
1466 return -1; 1240 return -1;
1467 PDEBUG(D_PROBE, "v%s registered", version); 1241 PDEBUG(D_PROBE, "registered");
1468 return 0; 1242 return 0;
1469} 1243}
1470static void __exit sd_mod_exit(void) 1244static void __exit sd_mod_exit(void)
diff --git a/drivers/media/video/gspca/sonixj.c b/drivers/media/video/gspca/sonixj.c
index 3e68b9926956..33a3df1f6915 100644
--- a/drivers/media/video/gspca/sonixj.c
+++ b/drivers/media/video/gspca/sonixj.c
@@ -24,9 +24,6 @@
24#include "gspca.h" 24#include "gspca.h"
25#include "jpeg.h" 25#include "jpeg.h"
26 26
27#define DRIVER_VERSION_NUMBER KERNEL_VERSION(2, 1, 7)
28static const char version[] = "2.1.7";
29
30MODULE_AUTHOR("Michel Xhaard <mxhaard@users.sourceforge.net>"); 27MODULE_AUTHOR("Michel Xhaard <mxhaard@users.sourceforge.net>");
31MODULE_DESCRIPTION("GSPCA/SONIX JPEG USB Camera Driver"); 28MODULE_DESCRIPTION("GSPCA/SONIX JPEG USB Camera Driver");
32MODULE_LICENSE("GPL"); 29MODULE_LICENSE("GPL");
@@ -361,6 +358,7 @@ static const __u8 mo4000_sensor_init[][8] = {
361}; 358};
362static const __u8 ov7660_sensor_init[][8] = { 359static const __u8 ov7660_sensor_init[][8] = {
363 {0xa1, 0x21, 0x12, 0x80, 0x00, 0x00, 0x00, 0x10}, /* reset SCCB */ 360 {0xa1, 0x21, 0x12, 0x80, 0x00, 0x00, 0x00, 0x10}, /* reset SCCB */
361/* (delay 20ms) */
364 {0xa1, 0x21, 0x12, 0x05, 0x00, 0x00, 0x00, 0x10}, 362 {0xa1, 0x21, 0x12, 0x05, 0x00, 0x00, 0x00, 0x10},
365 /* Outformat ?? rawRGB */ 363 /* Outformat ?? rawRGB */
366 {0xa1, 0x21, 0x13, 0xb8, 0x00, 0x00, 0x00, 0x10}, /* init COM8 */ 364 {0xa1, 0x21, 0x13, 0xb8, 0x00, 0x00, 0x00, 0x10}, /* init COM8 */
@@ -539,13 +537,31 @@ static void reg_r(struct gspca_dev *gspca_dev,
539 value, 0, 537 value, 0,
540 gspca_dev->usb_buf, len, 538 gspca_dev->usb_buf, len,
541 500); 539 500);
540 PDEBUG(D_USBI, "reg_r [%02x] -> %02x", value, gspca_dev->usb_buf[0]);
542} 541}
543 542
543static void reg_w1(struct gspca_dev *gspca_dev,
544 __u16 value,
545 __u8 data)
546{
547 PDEBUG(D_USBO, "reg_w1 [%02x] = %02x", value, data);
548 gspca_dev->usb_buf[0] = data;
549 usb_control_msg(gspca_dev->dev,
550 usb_sndctrlpipe(gspca_dev->dev, 0),
551 0x08,
552 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
553 value,
554 0,
555 gspca_dev->usb_buf, 1,
556 500);
557}
544static void reg_w(struct gspca_dev *gspca_dev, 558static void reg_w(struct gspca_dev *gspca_dev,
545 __u16 value, 559 __u16 value,
546 const __u8 *buffer, 560 const __u8 *buffer,
547 int len) 561 int len)
548{ 562{
563 PDEBUG(D_USBO, "reg_w [%02x] = %02x %02x ..",
564 value, buffer[0], buffer[1]);
549 if (len <= sizeof gspca_dev->usb_buf) { 565 if (len <= sizeof gspca_dev->usb_buf) {
550 memcpy(gspca_dev->usb_buf, buffer, len); 566 memcpy(gspca_dev->usb_buf, buffer, len);
551 usb_control_msg(gspca_dev->dev, 567 usb_control_msg(gspca_dev->dev,
@@ -571,31 +587,42 @@ static void reg_w(struct gspca_dev *gspca_dev,
571 } 587 }
572} 588}
573 589
574/* I2C write 2 bytes */ 590/* I2C write 1 byte */
575static void i2c_w2(struct gspca_dev *gspca_dev, 591static void i2c_w1(struct gspca_dev *gspca_dev, __u8 reg, __u8 val)
576 const __u8 *buffer)
577{ 592{
578 struct sd *sd = (struct sd *) gspca_dev; 593 struct sd *sd = (struct sd *) gspca_dev;
579 __u8 mode[8];
580 594
581 /* is i2c ready */ 595 PDEBUG(D_USBO, "i2c_w2 [%02x] = %02x", reg, val);
582 mode[0] = 0x81 | (2 << 4); 596 gspca_dev->usb_buf[0] = 0x81 | (2 << 4); /* = a1 */
583 mode[1] = sd->i2c_base; 597 gspca_dev->usb_buf[1] = sd->i2c_base;
584 mode[2] = buffer[0]; 598 gspca_dev->usb_buf[2] = reg;
585 mode[3] = buffer[1]; 599 gspca_dev->usb_buf[3] = val;
586 mode[4] = 0; 600 gspca_dev->usb_buf[4] = 0;
587 mode[5] = 0; 601 gspca_dev->usb_buf[5] = 0;
588 mode[6] = 0; 602 gspca_dev->usb_buf[6] = 0;
589 mode[7] = 0x10; 603 gspca_dev->usb_buf[7] = 0x10;
590 reg_w(gspca_dev, 0x08, mode, 8); 604 usb_control_msg(gspca_dev->dev,
605 usb_sndctrlpipe(gspca_dev->dev, 0),
606 0x08,
607 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
608 0x08, /* value = i2c */
609 0,
610 gspca_dev->usb_buf, 8,
611 500);
591} 612}
592 613
593/* I2C write 8 bytes */ 614/* I2C write 8 bytes */
594static void i2c_w8(struct gspca_dev *gspca_dev, 615static void i2c_w8(struct gspca_dev *gspca_dev,
595 const __u8 *buffer) 616 const __u8 *buffer)
596{ 617{
597 reg_w(gspca_dev, 0x08, buffer, 8); 618 memcpy(gspca_dev->usb_buf, buffer, 8);
598 msleep(1); 619 usb_control_msg(gspca_dev->dev,
620 usb_sndctrlpipe(gspca_dev->dev, 0),
621 0x08,
622 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
623 0x08, 0, /* value, index */
624 gspca_dev->usb_buf, 8,
625 500);
599} 626}
600 627
601/* read 5 bytes in gspca_dev->usb_buf */ 628/* read 5 bytes in gspca_dev->usb_buf */
@@ -613,24 +640,21 @@ static void i2c_r5(struct gspca_dev *gspca_dev, __u8 reg)
613 mode[6] = 0; 640 mode[6] = 0;
614 mode[7] = 0x10; 641 mode[7] = 0x10;
615 i2c_w8(gspca_dev, mode); 642 i2c_w8(gspca_dev, mode);
643 msleep(2);
616 mode[0] = 0x81 | (5 << 4) | 0x02; 644 mode[0] = 0x81 | (5 << 4) | 0x02;
617 mode[2] = 0; 645 mode[2] = 0;
618 i2c_w8(gspca_dev, mode); 646 i2c_w8(gspca_dev, mode);
647 msleep(2);
619 reg_r(gspca_dev, 0x0a, 5); 648 reg_r(gspca_dev, 0x0a, 5);
620} 649}
621 650
622static int probesensor(struct gspca_dev *gspca_dev) 651static int probesensor(struct gspca_dev *gspca_dev)
623{ 652{
624 struct sd *sd = (struct sd *) gspca_dev; 653 struct sd *sd = (struct sd *) gspca_dev;
625 __u8 reg02;
626 static const __u8 datasend[] = { 2, 0 };
627 /* reg val1 val2 val3 val4 */
628 654
629 i2c_w2(gspca_dev, datasend); 655 i2c_w1(gspca_dev, 0x02, 0); /* sensor wakeup */
630/* should write 0xa1 0x11 0x02 0x00 0x00 0x00 0x00 the 0x10 is add by i2cw */
631 msleep(10); 656 msleep(10);
632 reg02 = 0x66; 657 reg_w1(gspca_dev, 0x02, 0x66); /* Gpio on */
633 reg_w(gspca_dev, 0x02, &reg02, 1); /* Gpio on */
634 msleep(10); 658 msleep(10);
635 i2c_r5(gspca_dev, 0); /* read sensor id */ 659 i2c_r5(gspca_dev, 0); /* read sensor id */
636 if (gspca_dev->usb_buf[0] == 0x02 660 if (gspca_dev->usb_buf[0] == 0x02
@@ -642,7 +666,7 @@ static int probesensor(struct gspca_dev *gspca_dev)
642 sd->sensor = SENSOR_HV7131R; 666 sd->sensor = SENSOR_HV7131R;
643 return SENSOR_HV7131R; 667 return SENSOR_HV7131R;
644 } 668 }
645 PDEBUG(D_PROBE, "Find Sensor %d %d %d", 669 PDEBUG(D_PROBE, "Find Sensor 0x%02x 0x%02x 0x%02x",
646 gspca_dev->usb_buf[0], gspca_dev->usb_buf[1], 670 gspca_dev->usb_buf[0], gspca_dev->usb_buf[1],
647 gspca_dev->usb_buf[2]); 671 gspca_dev->usb_buf[2]);
648 PDEBUG(D_PROBE, "Sensor sn9c102P Not found"); 672 PDEBUG(D_PROBE, "Sensor sn9c102P Not found");
@@ -653,8 +677,6 @@ static int configure_gpio(struct gspca_dev *gspca_dev,
653 const __u8 *sn9c1xx) 677 const __u8 *sn9c1xx)
654{ 678{
655 struct sd *sd = (struct sd *) gspca_dev; 679 struct sd *sd = (struct sd *) gspca_dev;
656 __u8 data;
657 __u8 regF1;
658 const __u8 *reg9a; 680 const __u8 *reg9a;
659 static const __u8 reg9a_def[] = 681 static const __u8 reg9a_def[] =
660 {0x08, 0x40, 0x20, 0x10, 0x00, 0x04}; 682 {0x08, 0x40, 0x20, 0x10, 0x00, 0x04};
@@ -663,15 +685,13 @@ static int configure_gpio(struct gspca_dev *gspca_dev,
663 static const __u8 reg9a_sn9c325[] = 685 static const __u8 reg9a_sn9c325[] =
664 {0x0a, 0x40, 0x38, 0x30, 0x00, 0x20}; 686 {0x0a, 0x40, 0x38, 0x30, 0x00, 0x20};
665 687
666 688 reg_w1(gspca_dev, 0xf1, 0x00);
667 regF1 = 0x00; 689 reg_w1(gspca_dev, 0x01, sn9c1xx[0]); /*fixme:jfm was [1] en v1*/
668 reg_w(gspca_dev, 0xf1, &regF1, 1);
669 reg_w(gspca_dev, 0x01, &sn9c1xx[0], 1); /*fixme:jfm was [1] en v1*/
670 690
671 /* configure gpio */ 691 /* configure gpio */
672 reg_w(gspca_dev, 0x01, &sn9c1xx[1], 2); 692 reg_w(gspca_dev, 0x01, &sn9c1xx[1], 2);
673 reg_w(gspca_dev, 0x08, &sn9c1xx[8], 2); 693 reg_w(gspca_dev, 0x08, &sn9c1xx[8], 2);
674 reg_w(gspca_dev, 0x17, &sn9c1xx[0x17], 5); /* jfm was 3 */ 694 reg_w(gspca_dev, 0x17, &sn9c1xx[0x17], 5); /* jfm len was 3 */
675 switch (sd->bridge) { 695 switch (sd->bridge) {
676 case BRIDGE_SN9C325: 696 case BRIDGE_SN9C325:
677 reg9a = reg9a_sn9c325; 697 reg9a = reg9a_sn9c325;
@@ -685,35 +705,25 @@ static int configure_gpio(struct gspca_dev *gspca_dev,
685 } 705 }
686 reg_w(gspca_dev, 0x9a, reg9a, 6); 706 reg_w(gspca_dev, 0x9a, reg9a, 6);
687 707
688 data = 0x60; /*fixme:jfm 60 00 00 (3) */ 708 reg_w1(gspca_dev, 0xd4, 0x60); /*fixme:jfm 60 00 00 (3) ? */
689 reg_w(gspca_dev, 0xd4, &data, 1);
690 709
691 reg_w(gspca_dev, 0x03, &sn9c1xx[3], 0x0f); 710 reg_w(gspca_dev, 0x03, &sn9c1xx[3], 0x0f);
692 711
693 switch (sd->bridge) { 712 switch (sd->bridge) {
694 case BRIDGE_SN9C120: /* from win trace */ 713 case BRIDGE_SN9C120: /* from win trace */
695 data = 0x61; 714 reg_w1(gspca_dev, 0x01, 0x61);
696 reg_w(gspca_dev, 0x01, &data, 1); 715 reg_w1(gspca_dev, 0x17, 0x20);
697 data = 0x20; 716 reg_w1(gspca_dev, 0x01, 0x60);
698 reg_w(gspca_dev, 0x17, &data, 1);
699 data = 0x60;
700 reg_w(gspca_dev, 0x01, &data, 1);
701 break; 717 break;
702 case BRIDGE_SN9C325: 718 case BRIDGE_SN9C325:
703 data = 0x43; 719 reg_w1(gspca_dev, 0x01, 0x43);
704 reg_w(gspca_dev, 0x01, &data, 1); 720 reg_w1(gspca_dev, 0x17, 0xae);
705 data = 0xae; 721 reg_w1(gspca_dev, 0x01, 0x42);
706 reg_w(gspca_dev, 0x17, &data, 1);
707 data = 0x42;
708 reg_w(gspca_dev, 0x01, &data, 1);
709 break; 722 break;
710 default: 723 default:
711 data = 0x43; 724 reg_w1(gspca_dev, 0x01, 0x43);
712 reg_w(gspca_dev, 0x01, &data, 1); 725 reg_w1(gspca_dev, 0x17, 0x61);
713 data = 0x61; 726 reg_w1(gspca_dev, 0x01, 0x42);
714 reg_w(gspca_dev, 0x17, &data, 1);
715 data = 0x42;
716 reg_w(gspca_dev, 0x01, &data, 1);
717 } 727 }
718 728
719 if (sd->sensor == SENSOR_HV7131R) { 729 if (sd->sensor == SENSOR_HV7131R) {
@@ -770,6 +780,9 @@ static void ov7660_InitSensor(struct gspca_dev *gspca_dev)
770{ 780{
771 int i = 0; 781 int i = 0;
772 782
783 i2c_w8(gspca_dev, ov7660_sensor_init[i]); /* reset SCCB */
784 i++;
785 msleep(20);
773 while (ov7660_sensor_init[i][0]) { 786 while (ov7660_sensor_init[i][0]) {
774 i2c_w8(gspca_dev, ov7660_sensor_init[i]); 787 i2c_w8(gspca_dev, ov7660_sensor_init[i]);
775 i++; 788 i++;
@@ -782,194 +795,16 @@ static int sd_config(struct gspca_dev *gspca_dev,
782{ 795{
783 struct sd *sd = (struct sd *) gspca_dev; 796 struct sd *sd = (struct sd *) gspca_dev;
784 struct cam *cam; 797 struct cam *cam;
785 __u16 vendor;
786 __u16 product;
787
788 vendor = id->idVendor;
789 product = id->idProduct;
790 sd->sensor = -1;
791 switch (vendor) {
792 case 0x0458: /* Genius */
793/* switch (product) {
794 case 0x7025: */
795 sd->bridge = BRIDGE_SN9C120;
796 sd->sensor = SENSOR_MI0360;
797 sd->i2c_base = 0x5d;
798/* break;
799 } */
800 break;
801 case 0x045e:
802/* switch (product) {
803 case 0x00f5:
804 case 0x00f7: */
805 sd->bridge = BRIDGE_SN9C105;
806 sd->sensor = SENSOR_OV7660;
807 sd->i2c_base = 0x21;
808/* break;
809 } */
810 break;
811 case 0x0471: /* Philips */
812/* switch (product) {
813 case 0x0327:
814 case 0x0328:
815 case 0x0330: */
816 sd->bridge = BRIDGE_SN9C105;
817 sd->sensor = SENSOR_MI0360;
818 sd->i2c_base = 0x5d;
819/* break;
820 } */
821 break;
822 case 0x0c45: /* Sonix */
823 switch (product) {
824 case 0x6040:
825 sd->bridge = BRIDGE_SN9C102P;
826/* sd->sensor = SENSOR_MI0360; * from BW600.inf */
827/*fixme: MI0360 base=5d ? */
828 sd->sensor = SENSOR_HV7131R; /* gspcav1 value */
829 sd->i2c_base = 0x11;
830 break;
831/* case 0x607a: * from BW600.inf
832 sd->bridge = BRIDGE_SN9C102P;
833 sd->sensor = SENSOR_OV7648;
834 sd->i2c_base = 0x??;
835 break; */
836 case 0x607c:
837 sd->bridge = BRIDGE_SN9C102P;
838 sd->sensor = SENSOR_HV7131R;
839 sd->i2c_base = 0x11;
840 break;
841/* case 0x607e: * from BW600.inf
842 sd->bridge = BRIDGE_SN9C102P;
843 sd->sensor = SENSOR_OV7630;
844 sd->i2c_base = 0x??;
845 break; */
846 case 0x60c0:
847 sd->bridge = BRIDGE_SN9C105;
848 sd->sensor = SENSOR_MI0360;
849 sd->i2c_base = 0x5d;
850 break;
851/* case 0x60c8: * from BW600.inf
852 sd->bridge = BRIDGE_SN9C105;
853 sd->sensor = SENSOR_OM6801;
854 sd->i2c_base = 0x??;
855 break; */
856/* case 0x60cc: * from BW600.inf
857 sd->bridge = BRIDGE_SN9C105;
858 sd->sensor = SENSOR_HV7131GP;
859 sd->i2c_base = 0x??;
860 break; */
861 case 0x60ec:
862 sd->bridge = BRIDGE_SN9C105;
863 sd->sensor = SENSOR_MO4000;
864 sd->i2c_base = 0x21;
865 break;
866/* case 0x60ef: * from BW600.inf
867 sd->bridge = BRIDGE_SN9C105;
868 sd->sensor = SENSOR_ICM105C;
869 sd->i2c_base = 0x??;
870 break; */
871/* case 0x60fa: * from BW600.inf
872 sd->bridge = BRIDGE_SN9C105;
873 sd->sensor = SENSOR_OV7648;
874 sd->i2c_base = 0x??;
875 break; */
876 case 0x60fb:
877 sd->bridge = BRIDGE_SN9C105;
878 sd->sensor = SENSOR_OV7660;
879 sd->i2c_base = 0x21;
880 break;
881 case 0x60fc:
882 sd->bridge = BRIDGE_SN9C105;
883 sd->sensor = SENSOR_HV7131R;
884 sd->i2c_base = 0x11;
885 break;
886/* case 0x60fe: * from BW600.inf
887 sd->bridge = BRIDGE_SN9C105;
888 sd->sensor = SENSOR_OV7630;
889 sd->i2c_base = 0x??;
890 break; */
891/* case 0x6108: * from BW600.inf
892 sd->bridge = BRIDGE_SN9C120;
893 sd->sensor = SENSOR_OM6801;
894 sd->i2c_base = 0x??;
895 break; */
896/* case 0x6122: * from BW600.inf
897 sd->bridge = BRIDGE_SN9C110;
898 sd->sensor = SENSOR_ICM105C;
899 sd->i2c_base = 0x??;
900 break; */
901 case 0x612a:
902/* sd->bridge = BRIDGE_SN9C110; * in BW600.inf */
903 sd->bridge = BRIDGE_SN9C325;
904 sd->sensor = SENSOR_OV7648;
905 sd->i2c_base = 0x21;
906/*fixme: sensor_init has base = 00 et 6e!*/
907 break;
908/* case 0x6123: * from BW600.inf
909 sd->bridge = BRIDGE_SN9C110;
910 sd->sensor = SENSOR_SanyoCCD;
911 sd->i2c_base = 0x??;
912 break; */
913 case 0x612c:
914 sd->bridge = BRIDGE_SN9C110;
915 sd->sensor = SENSOR_MO4000;
916 sd->i2c_base = 0x21;
917 break;
918/* case 0x612e: * from BW600.inf
919 sd->bridge = BRIDGE_SN9C110;
920 sd->sensor = SENSOR_OV7630;
921 sd->i2c_base = 0x??;
922 break; */
923/* case 0x612f: * from BW600.inf
924 sd->bridge = BRIDGE_SN9C110;
925 sd->sensor = SENSOR_ICM105C;
926 sd->i2c_base = 0x??;
927 break; */
928 case 0x6130:
929 sd->bridge = BRIDGE_SN9C120;
930 sd->sensor = SENSOR_MI0360;
931 sd->i2c_base = 0x5d;
932 break;
933 case 0x6138:
934 sd->bridge = BRIDGE_SN9C120;
935 sd->sensor = SENSOR_MO4000;
936 sd->i2c_base = 0x21;
937 break;
938/* case 0x613a: * from BW600.inf
939 sd->bridge = BRIDGE_SN9C120;
940 sd->sensor = SENSOR_OV7648;
941 sd->i2c_base = 0x??;
942 break; */
943 case 0x613b:
944 sd->bridge = BRIDGE_SN9C120;
945 sd->sensor = SENSOR_OV7660;
946 sd->i2c_base = 0x21;
947 break;
948 case 0x613c:
949 sd->bridge = BRIDGE_SN9C120;
950 sd->sensor = SENSOR_HV7131R;
951 sd->i2c_base = 0x11;
952 break;
953/* case 0x613e: * from BW600.inf
954 sd->bridge = BRIDGE_SN9C120;
955 sd->sensor = SENSOR_OV7630;
956 sd->i2c_base = 0x??;
957 break; */
958 }
959 break;
960 }
961 if (sd->sensor < 0) {
962 PDEBUG(D_ERR, "Invalid vendor/product %04x:%04x",
963 vendor, product);
964 return -EINVAL;
965 }
966 798
967 cam = &gspca_dev->cam; 799 cam = &gspca_dev->cam;
968 cam->dev_name = (char *) id->driver_info;
969 cam->epaddr = 0x01; 800 cam->epaddr = 0x01;
970 cam->cam_mode = vga_mode; 801 cam->cam_mode = vga_mode;
971 cam->nmodes = ARRAY_SIZE(vga_mode); 802 cam->nmodes = ARRAY_SIZE(vga_mode);
972 803
804 sd->bridge = id->driver_info >> 16;
805 sd->sensor = id->driver_info >> 8;
806 sd->i2c_base = id->driver_info;
807
973 sd->qindex = 4; /* set the quantization table */ 808 sd->qindex = 4; /* set the quantization table */
974 sd->brightness = BRIGHTNESS_DEF; 809 sd->brightness = BRIGHTNESS_DEF;
975 sd->contrast = CONTRAST_DEF; 810 sd->contrast = CONTRAST_DEF;
@@ -983,34 +818,26 @@ static int sd_open(struct gspca_dev *gspca_dev)
983{ 818{
984 struct sd *sd = (struct sd *) gspca_dev; 819 struct sd *sd = (struct sd *) gspca_dev;
985/* const __u8 *sn9c1xx; */ 820/* const __u8 *sn9c1xx; */
986 __u8 regF1;
987 __u8 regGpio[] = { 0x29, 0x74 }; 821 __u8 regGpio[] = { 0x29, 0x74 };
822 __u8 regF1;
988 823
989 /* setup a selector by bridge */ 824 /* setup a selector by bridge */
990 regF1 = 0x01; 825 reg_w1(gspca_dev, 0xf1, 0x01);
991 reg_w(gspca_dev, 0xf1, &regF1, 1);
992 reg_r(gspca_dev, 0x00, 1); /* -> regF1 = 0x00 */ 826 reg_r(gspca_dev, 0x00, 1); /* -> regF1 = 0x00 */
993 regF1 = gspca_dev->usb_buf[0]; 827 reg_w1(gspca_dev, 0xf1, gspca_dev->usb_buf[0]);
994 reg_w(gspca_dev, 0xf1, &regF1, 1);
995 reg_r(gspca_dev, 0x00, 1); 828 reg_r(gspca_dev, 0x00, 1);
996 regF1 = gspca_dev->usb_buf[0]; 829 regF1 = gspca_dev->usb_buf[0];
997 switch (sd->bridge) { 830 switch (sd->bridge) {
998 case BRIDGE_SN9C102P: 831 case BRIDGE_SN9C102P:
999 if (regF1 != 0x11) 832 if (regF1 != 0x11)
1000 return -ENODEV; 833 return -ENODEV;
1001 reg_w(gspca_dev, 0x02, &regGpio[1], 1); 834 reg_w1(gspca_dev, 0x02, regGpio[1]);
1002 break; 835 break;
1003 case BRIDGE_SN9C105: 836 case BRIDGE_SN9C105:
1004 if (regF1 != 0x11) 837 if (regF1 != 0x11)
1005 return -ENODEV; 838 return -ENODEV;
1006 reg_w(gspca_dev, 0x02, regGpio, 2); 839 reg_w(gspca_dev, 0x02, regGpio, 2);
1007 break; 840 break;
1008 case BRIDGE_SN9C110:
1009 if (regF1 != 0x12)
1010 return -ENODEV;
1011 regGpio[1] = 0x62;
1012 reg_w(gspca_dev, 0x02, &regGpio[1], 1);
1013 break;
1014 case BRIDGE_SN9C120: 841 case BRIDGE_SN9C120:
1015 if (regF1 != 0x12) 842 if (regF1 != 0x12)
1016 return -ENODEV; 843 return -ENODEV;
@@ -1018,16 +845,15 @@ static int sd_open(struct gspca_dev *gspca_dev)
1018 reg_w(gspca_dev, 0x02, regGpio, 2); 845 reg_w(gspca_dev, 0x02, regGpio, 2);
1019 break; 846 break;
1020 default: 847 default:
848/* case BRIDGE_SN9C110: */
1021/* case BRIDGE_SN9C325: */ 849/* case BRIDGE_SN9C325: */
1022 if (regF1 != 0x12) 850 if (regF1 != 0x12)
1023 return -ENODEV; 851 return -ENODEV;
1024 regGpio[1] = 0x62; 852 reg_w1(gspca_dev, 0x02, 0x62);
1025 reg_w(gspca_dev, 0x02, &regGpio[1], 1);
1026 break; 853 break;
1027 } 854 }
1028 855
1029 regF1 = 0x01; 856 reg_w1(gspca_dev, 0xf1, 0x01);
1030 reg_w(gspca_dev, 0xf1, &regF1, 1);
1031 857
1032 return 0; 858 return 0;
1033} 859}
@@ -1123,7 +949,7 @@ static void setbrightness(struct gspca_dev *gspca_dev)
1123 } 949 }
1124 950
1125 k2 = sd->brightness >> 10; 951 k2 = sd->brightness >> 10;
1126 reg_w(gspca_dev, 0x96, &k2, 1); 952 reg_w1(gspca_dev, 0x96, k2);
1127} 953}
1128 954
1129static void setcontrast(struct gspca_dev *gspca_dev) 955static void setcontrast(struct gspca_dev *gspca_dev)
@@ -1152,7 +978,7 @@ static void setcolors(struct gspca_dev *gspca_dev)
1152 data = (colour + 32) & 0x7f; /* blue */ 978 data = (colour + 32) & 0x7f; /* blue */
1153 else 979 else
1154 data = (-colour + 32) & 0x7f; /* red */ 980 data = (-colour + 32) & 0x7f; /* red */
1155 reg_w(gspca_dev, 0x05, &data, 1); 981 reg_w1(gspca_dev, 0x05, data);
1156} 982}
1157 983
1158/* -- start the camera -- */ 984/* -- start the camera -- */
@@ -1165,7 +991,6 @@ static void sd_start(struct gspca_dev *gspca_dev)
1165 __u8 reg17; 991 __u8 reg17;
1166 const __u8 *sn9c1xx; 992 const __u8 *sn9c1xx;
1167 int mode; 993 int mode;
1168 static const __u8 DC29[] = { 0x6a, 0x50, 0x00, 0x00, 0x50, 0x3c };
1169 static const __u8 C0[] = { 0x2d, 0x2d, 0x3a, 0x05, 0x04, 0x3f }; 994 static const __u8 C0[] = { 0x2d, 0x2d, 0x3a, 0x05, 0x04, 0x3f };
1170 static const __u8 CA[] = { 0x28, 0xd8, 0x14, 0xec }; 995 static const __u8 CA[] = { 0x28, 0xd8, 0x14, 0xec };
1171 static const __u8 CA_sn9c120[] = 996 static const __u8 CA_sn9c120[] =
@@ -1179,21 +1004,20 @@ static void sd_start(struct gspca_dev *gspca_dev)
1179 1004
1180/*fixme:jfm this sequence should appear at end of sd_start */ 1005/*fixme:jfm this sequence should appear at end of sd_start */
1181/* with 1006/* with
1182 data = 0x44; 1007 reg_w1(gspca_dev, 0x01, 0x44); */
1183 reg_w(gspca_dev, 0x01, &data, 1); */ 1008 reg_w1(gspca_dev, 0x15, sn9c1xx[0x15]);
1184 reg_w(gspca_dev, 0x15, &sn9c1xx[0x15], 1); 1009 reg_w1(gspca_dev, 0x16, sn9c1xx[0x16]);
1185 reg_w(gspca_dev, 0x16, &sn9c1xx[0x16], 1); 1010 reg_w1(gspca_dev, 0x12, sn9c1xx[0x12]);
1186 reg_w(gspca_dev, 0x12, &sn9c1xx[0x12], 1); 1011 reg_w1(gspca_dev, 0x13, sn9c1xx[0x13]);
1187 reg_w(gspca_dev, 0x13, &sn9c1xx[0x13], 1); 1012 reg_w1(gspca_dev, 0x18, sn9c1xx[0x18]);
1188 reg_w(gspca_dev, 0x18, &sn9c1xx[0x18], 1); 1013 reg_w1(gspca_dev, 0xd2, 0x6a); /* DC29 */
1189 reg_w(gspca_dev, 0xd2, &DC29[0], 1); 1014 reg_w1(gspca_dev, 0xd3, 0x50);
1190 reg_w(gspca_dev, 0xd3, &DC29[1], 1); 1015 reg_w1(gspca_dev, 0xc6, 0x00);
1191 reg_w(gspca_dev, 0xc6, &DC29[2], 1); 1016 reg_w1(gspca_dev, 0xc7, 0x00);
1192 reg_w(gspca_dev, 0xc7, &DC29[3], 1); 1017 reg_w1(gspca_dev, 0xc8, 0x50);
1193 reg_w(gspca_dev, 0xc8, &DC29[4], 1); 1018 reg_w1(gspca_dev, 0xc9, 0x3c);
1194 reg_w(gspca_dev, 0xc9, &DC29[5], 1);
1195/*fixme:jfm end of ending sequence */ 1019/*fixme:jfm end of ending sequence */
1196 reg_w(gspca_dev, 0x18, &sn9c1xx[0x18], 1); 1020 reg_w1(gspca_dev, 0x18, sn9c1xx[0x18]);
1197 switch (sd->bridge) { 1021 switch (sd->bridge) {
1198 case BRIDGE_SN9C325: 1022 case BRIDGE_SN9C325:
1199 data = 0xae; 1023 data = 0xae;
@@ -1205,11 +1029,11 @@ static void sd_start(struct gspca_dev *gspca_dev)
1205 data = 0x60; 1029 data = 0x60;
1206 break; 1030 break;
1207 } 1031 }
1208 reg_w(gspca_dev, 0x17, &data, 1); 1032 reg_w1(gspca_dev, 0x17, data);
1209 reg_w(gspca_dev, 0x05, &sn9c1xx[5], 1); 1033 reg_w1(gspca_dev, 0x05, sn9c1xx[5]);
1210 reg_w(gspca_dev, 0x07, &sn9c1xx[7], 1); 1034 reg_w1(gspca_dev, 0x07, sn9c1xx[7]);
1211 reg_w(gspca_dev, 0x06, &sn9c1xx[6], 1); 1035 reg_w1(gspca_dev, 0x06, sn9c1xx[6]);
1212 reg_w(gspca_dev, 0x14, &sn9c1xx[0x14], 1); 1036 reg_w1(gspca_dev, 0x14, sn9c1xx[0x14]);
1213 switch (sd->bridge) { 1037 switch (sd->bridge) {
1214 case BRIDGE_SN9C325: 1038 case BRIDGE_SN9C325:
1215 reg_w(gspca_dev, 0x20, regsn20_sn9c325, 1039 reg_w(gspca_dev, 0x20, regsn20_sn9c325,
@@ -1217,10 +1041,8 @@ static void sd_start(struct gspca_dev *gspca_dev)
1217 for (i = 0; i < 8; i++) 1041 for (i = 0; i < 8; i++)
1218 reg_w(gspca_dev, 0x84, reg84_sn9c325, 1042 reg_w(gspca_dev, 0x84, reg84_sn9c325,
1219 sizeof reg84_sn9c325); 1043 sizeof reg84_sn9c325);
1220 data = 0x0a; 1044 reg_w1(gspca_dev, 0x9a, 0x0a);
1221 reg_w(gspca_dev, 0x9a, &data, 1); 1045 reg_w1(gspca_dev, 0x99, 0x60);
1222 data = 0x60;
1223 reg_w(gspca_dev, 0x99, &data, 1);
1224 break; 1046 break;
1225 case BRIDGE_SN9C120: 1047 case BRIDGE_SN9C120:
1226 reg_w(gspca_dev, 0x20, regsn20_sn9c120, 1048 reg_w(gspca_dev, 0x20, regsn20_sn9c120,
@@ -1233,39 +1055,30 @@ static void sd_start(struct gspca_dev *gspca_dev)
1233 sizeof reg84_sn9c120_2); 1055 sizeof reg84_sn9c120_2);
1234 reg_w(gspca_dev, 0x84, reg84_sn9c120_3, 1056 reg_w(gspca_dev, 0x84, reg84_sn9c120_3,
1235 sizeof reg84_sn9c120_3); 1057 sizeof reg84_sn9c120_3);
1236 data = 0x05; 1058 reg_w1(gspca_dev, 0x9a, 0x05);
1237 reg_w(gspca_dev, 0x9a, &data, 1); 1059 reg_w1(gspca_dev, 0x99, 0x5b);
1238 data = 0x5b;
1239 reg_w(gspca_dev, 0x99, &data, 1);
1240 break; 1060 break;
1241 default: 1061 default:
1242 reg_w(gspca_dev, 0x20, regsn20, sizeof regsn20); 1062 reg_w(gspca_dev, 0x20, regsn20, sizeof regsn20);
1243 for (i = 0; i < 8; i++) 1063 for (i = 0; i < 8; i++)
1244 reg_w(gspca_dev, 0x84, reg84, sizeof reg84); 1064 reg_w(gspca_dev, 0x84, reg84, sizeof reg84);
1245 data = 0x08; 1065 reg_w1(gspca_dev, 0x9a, 0x08);
1246 reg_w(gspca_dev, 0x9a, &data, 1); 1066 reg_w1(gspca_dev, 0x99, 0x59);
1247 data = 0x59;
1248 reg_w(gspca_dev, 0x99, &data, 1);
1249 break; 1067 break;
1250 } 1068 }
1251 1069
1252 mode = gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv; 1070 mode = gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv;
1253 reg1 = 0x02; 1071 if (mode)
1072 reg1 = 0x46; /* 320 clk 48Mhz */
1073 else
1074 reg1 = 0x06; /* 640 clk 24Mz */
1254 reg17 = 0x61; 1075 reg17 = 0x61;
1255 switch (sd->sensor) { 1076 switch (sd->sensor) {
1256 case SENSOR_HV7131R: 1077 case SENSOR_HV7131R:
1257 hv7131R_InitSensor(gspca_dev); 1078 hv7131R_InitSensor(gspca_dev);
1258 if (mode)
1259 reg1 = 0x46; /* 320 clk 48Mhz */
1260 else
1261 reg1 = 0x06; /* 640 clk 24Mz */
1262 break; 1079 break;
1263 case SENSOR_MI0360: 1080 case SENSOR_MI0360:
1264 mi0360_InitSensor(gspca_dev); 1081 mi0360_InitSensor(gspca_dev);
1265 if (mode)
1266 reg1 = 0x46; /* 320 clk 48Mhz */
1267 else
1268 reg1 = 0x06; /* 640 clk 24Mz */
1269 break; 1082 break;
1270 case SENSOR_MO4000: 1083 case SENSOR_MO4000:
1271 mo4000_InitSensor(gspca_dev); 1084 mo4000_InitSensor(gspca_dev);
@@ -1274,13 +1087,13 @@ static void sd_start(struct gspca_dev *gspca_dev)
1274 reg1 = 0x06; /* clk 24Mz */ 1087 reg1 = 0x06; /* clk 24Mz */
1275 } else { 1088 } else {
1276 reg17 = 0x22; /* 640 MCKSIZE */ 1089 reg17 = 0x22; /* 640 MCKSIZE */
1277 reg1 = 0x06; /* 640 clk 24Mz */ 1090/* reg1 = 0x06; * 640 clk 24Mz (done) */
1278 } 1091 }
1279 break; 1092 break;
1280 case SENSOR_OV7648: 1093 case SENSOR_OV7648:
1094 ov7648_InitSensor(gspca_dev);
1281 reg17 = 0xa2; 1095 reg17 = 0xa2;
1282 reg1 = 0x44; 1096 reg1 = 0x44;
1283 ov7648_InitSensor(gspca_dev);
1284/* if (mode) 1097/* if (mode)
1285 ; * 320x2... 1098 ; * 320x2...
1286 else 1099 else
@@ -1292,7 +1105,7 @@ static void sd_start(struct gspca_dev *gspca_dev)
1292 if (mode) { 1105 if (mode) {
1293/* reg17 = 0x21; * 320 */ 1106/* reg17 = 0x21; * 320 */
1294/* reg1 = 0x44; */ 1107/* reg1 = 0x44; */
1295 reg1 = 0x46; 1108/* reg1 = 0x46; (done) */
1296 } else { 1109 } else {
1297 reg17 = 0xa2; /* 640 */ 1110 reg17 = 0xa2; /* 640 */
1298 reg1 = 0x40; 1111 reg1 = 0x40;
@@ -1321,16 +1134,16 @@ static void sd_start(struct gspca_dev *gspca_dev)
1321 1134
1322 /* here change size mode 0 -> VGA; 1 -> CIF */ 1135 /* here change size mode 0 -> VGA; 1 -> CIF */
1323 data = 0x40 | sn9c1xx[0x18] | (mode << 4); 1136 data = 0x40 | sn9c1xx[0x18] | (mode << 4);
1324 reg_w(gspca_dev, 0x18, &data, 1); 1137 reg_w1(gspca_dev, 0x18, data);
1325 1138
1326 reg_w(gspca_dev, 0x100, qtable4, 0x40); 1139 reg_w(gspca_dev, 0x100, qtable4, 0x40);
1327 reg_w(gspca_dev, 0x140, qtable4 + 0x40, 0x40); 1140 reg_w(gspca_dev, 0x140, qtable4 + 0x40, 0x40);
1328 1141
1329 data = sn9c1xx[0x18] | (mode << 4); 1142 data = sn9c1xx[0x18] | (mode << 4);
1330 reg_w(gspca_dev, 0x18, &data, 1); 1143 reg_w1(gspca_dev, 0x18, data);
1331 1144
1332 reg_w(gspca_dev, 0x17, &reg17, 1); 1145 reg_w1(gspca_dev, 0x17, reg17);
1333 reg_w(gspca_dev, 0x01, &reg1, 1); 1146 reg_w1(gspca_dev, 0x01, reg1);
1334 setbrightness(gspca_dev); 1147 setbrightness(gspca_dev);
1335 setcontrast(gspca_dev); 1148 setcontrast(gspca_dev);
1336} 1149}
@@ -1342,7 +1155,6 @@ static void sd_stopN(struct gspca_dev *gspca_dev)
1342 { 0xa1, 0x11, 0x02, 0x09, 0x00, 0x00, 0x00, 0x10 }; 1155 { 0xa1, 0x11, 0x02, 0x09, 0x00, 0x00, 0x00, 0x10 };
1343 static const __u8 stopmi0360[] = 1156 static const __u8 stopmi0360[] =
1344 { 0xb1, 0x5d, 0x07, 0x00, 0x00, 0x00, 0x00, 0x10 }; 1157 { 0xb1, 0x5d, 0x07, 0x00, 0x00, 0x00, 0x00, 0x10 };
1345 __u8 regF1;
1346 __u8 data; 1158 __u8 data;
1347 const __u8 *sn9c1xx; 1159 const __u8 *sn9c1xx;
1348 1160
@@ -1366,12 +1178,11 @@ static void sd_stopN(struct gspca_dev *gspca_dev)
1366 break; 1178 break;
1367 } 1179 }
1368 sn9c1xx = sn_tb[(int) sd->sensor]; 1180 sn9c1xx = sn_tb[(int) sd->sensor];
1369 reg_w(gspca_dev, 0x01, &sn9c1xx[1], 1); 1181 reg_w1(gspca_dev, 0x01, sn9c1xx[1]);
1370 reg_w(gspca_dev, 0x17, &sn9c1xx[0x17], 1); 1182 reg_w1(gspca_dev, 0x17, sn9c1xx[0x17]);
1371 reg_w(gspca_dev, 0x01, &sn9c1xx[1], 1); 1183 reg_w1(gspca_dev, 0x01, sn9c1xx[1]);
1372 reg_w(gspca_dev, 0x01, &data, 1); 1184 reg_w1(gspca_dev, 0x01, data);
1373 regF1 = 0x01; 1185 reg_w1(gspca_dev, 0xf1, 0x01);
1374 reg_w(gspca_dev, 0xf1, &regF1, 1);
1375} 1186}
1376 1187
1377static void sd_stop0(struct gspca_dev *gspca_dev) 1188static void sd_stop0(struct gspca_dev *gspca_dev)
@@ -1610,30 +1421,53 @@ static const struct sd_desc sd_desc = {
1610}; 1421};
1611 1422
1612/* -- module initialisation -- */ 1423/* -- module initialisation -- */
1613#define DVNM(name) .driver_info = (kernel_ulong_t) name 1424#define BSI(bridge, sensor, i2c_addr) \
1425 .driver_info = (BRIDGE_ ## bridge << 16) \
1426 | (SENSOR_ ## sensor << 8) \
1427 | (i2c_addr)
1614static const __devinitdata struct usb_device_id device_table[] = { 1428static const __devinitdata struct usb_device_id device_table[] = {
1615#ifndef CONFIG_USB_SN9C102 1429#ifndef CONFIG_USB_SN9C102
1616 {USB_DEVICE(0x0458, 0x7025), DVNM("Genius Eye 311Q")}, 1430 {USB_DEVICE(0x0458, 0x7025), BSI(SN9C120, MI0360, 0x5d)},
1617 {USB_DEVICE(0x045e, 0x00f5), DVNM("MicroSoft VX3000")}, 1431 {USB_DEVICE(0x045e, 0x00f5), BSI(SN9C105, OV7660, 0x21)},
1618 {USB_DEVICE(0x045e, 0x00f7), DVNM("MicroSoft VX1000")}, 1432 {USB_DEVICE(0x045e, 0x00f7), BSI(SN9C105, OV7660, 0x21)},
1619 {USB_DEVICE(0x0471, 0x0327), DVNM("Philips SPC 600 NC")}, 1433 {USB_DEVICE(0x0471, 0x0327), BSI(SN9C105, MI0360, 0x5d)},
1620 {USB_DEVICE(0x0471, 0x0328), DVNM("Philips SPC 700 NC")}, 1434 {USB_DEVICE(0x0471, 0x0328), BSI(SN9C105, MI0360, 0x5d)},
1621#endif 1435#endif
1622 {USB_DEVICE(0x0471, 0x0330), DVNM("Philips SPC 710NC")}, 1436 {USB_DEVICE(0x0471, 0x0330), BSI(SN9C105, MI0360, 0x5d)},
1623 {USB_DEVICE(0x0c45, 0x6040), DVNM("Speed NVC 350K")}, 1437 {USB_DEVICE(0x0c45, 0x6040), BSI(SN9C102P, HV7131R, 0x11)},
1624 {USB_DEVICE(0x0c45, 0x607c), DVNM("Sonix sn9c102p Hv7131R")}, 1438/* bw600.inf:
1625 {USB_DEVICE(0x0c45, 0x60c0), DVNM("Sangha Sn535")}, 1439 {USB_DEVICE(0x0c45, 0x6040), BSI(SN9C102P, MI0360, 0x5d)}, */
1626 {USB_DEVICE(0x0c45, 0x60ec), DVNM("SN9C105+MO4000")}, 1440/* {USB_DEVICE(0x0c45, 0x603a), BSI(SN9C102P, OV7648, 0x??)}, */
1627 {USB_DEVICE(0x0c45, 0x60fb), DVNM("Surfer NoName")}, 1441/* {USB_DEVICE(0x0c45, 0x607a), BSI(SN9C102P, OV7648, 0x??)}, */
1628 {USB_DEVICE(0x0c45, 0x60fc), DVNM("LG-LIC300")}, 1442 {USB_DEVICE(0x0c45, 0x607c), BSI(SN9C102P, HV7131R, 0x11)},
1629 {USB_DEVICE(0x0c45, 0x612a), DVNM("Avant Camera")}, 1443/* {USB_DEVICE(0x0c45, 0x607e), BSI(SN9C102P, OV7630, 0x??)}, */
1630 {USB_DEVICE(0x0c45, 0x612c), DVNM("Typhoon Rasy Cam 1.3MPix")}, 1444 {USB_DEVICE(0x0c45, 0x60c0), BSI(SN9C105, MI0360, 0x5d)},
1445/* {USB_DEVICE(0x0c45, 0x60c8), BSI(SN9C105, OM6801, 0x??)}, */
1446/* {USB_DEVICE(0x0c45, 0x60cc), BSI(SN9C105, HV7131GP, 0x??)}, */
1447 {USB_DEVICE(0x0c45, 0x60ec), BSI(SN9C105, MO4000, 0x21)},
1448/* {USB_DEVICE(0x0c45, 0x60ef), BSI(SN9C105, ICM105C, 0x??)}, */
1449/* {USB_DEVICE(0x0c45, 0x60fa), BSI(SN9C105, OV7648, 0x??)}, */
1450 {USB_DEVICE(0x0c45, 0x60fb), BSI(SN9C105, OV7660, 0x21)},
1451 {USB_DEVICE(0x0c45, 0x60fc), BSI(SN9C105, HV7131R, 0x11)},
1452/* {USB_DEVICE(0x0c45, 0x60fe), BSI(SN9C105, OV7630, 0x??)}, */
1453/* {USB_DEVICE(0x0c45, 0x6108), BSI(SN9C120, OM6801, 0x??)}, */
1454/* {USB_DEVICE(0x0c45, 0x6122), BSI(SN9C110, ICM105C, 0x??)}, */
1455/* {USB_DEVICE(0x0c45, 0x6123), BSI(SN9C110, SanyoCCD, 0x??)}, */
1456 {USB_DEVICE(0x0c45, 0x612a), BSI(SN9C325, OV7648, 0x21)},
1457/* bw600.inf:
1458 {USB_DEVICE(0x0c45, 0x612a), BSI(SN9C110, OV7648, 0x21)}, */
1459 {USB_DEVICE(0x0c45, 0x612c), BSI(SN9C110, MO4000, 0x21)},
1460/* {USB_DEVICE(0x0c45, 0x612e), BSI(SN9C110, OV7630, 0x??)}, */
1461/* {USB_DEVICE(0x0c45, 0x612f), BSI(SN9C110, ICM105C, 0x??)}, */
1631#ifndef CONFIG_USB_SN9C102 1462#ifndef CONFIG_USB_SN9C102
1632 {USB_DEVICE(0x0c45, 0x6130), DVNM("Sonix Pccam")}, 1463 {USB_DEVICE(0x0c45, 0x6130), BSI(SN9C120, MI0360, 0x5d)},
1633 {USB_DEVICE(0x0c45, 0x6138), DVNM("Sn9c120 Mo4000")}, 1464 {USB_DEVICE(0x0c45, 0x6138), BSI(SN9C120, MO4000, 0x21)},
1634 {USB_DEVICE(0x0c45, 0x613b), DVNM("Surfer SN-206")}, 1465/* {USB_DEVICE(0x0c45, 0x613a), BSI(SN9C120, OV7648, 0x??)}, */
1635 {USB_DEVICE(0x0c45, 0x613c), DVNM("Sonix Pccam168")}, 1466 {USB_DEVICE(0x0c45, 0x613b), BSI(SN9C120, OV7660, 0x21)},
1467 {USB_DEVICE(0x0c45, 0x613c), BSI(SN9C120, HV7131R, 0x11)},
1468/* {USB_DEVICE(0x0c45, 0x613e), BSI(SN9C120, OV7630, 0x??)}, */
1636#endif 1469#endif
1470 {USB_DEVICE(0x0c45, 0x6143), BSI(SN9C120, MI0360, 0x5d)},
1637 {} 1471 {}
1638}; 1472};
1639MODULE_DEVICE_TABLE(usb, device_table); 1473MODULE_DEVICE_TABLE(usb, device_table);
@@ -1658,7 +1492,7 @@ static int __init sd_mod_init(void)
1658{ 1492{
1659 if (usb_register(&sd_driver) < 0) 1493 if (usb_register(&sd_driver) < 0)
1660 return -1; 1494 return -1;
1661 info("v%s registered", version); 1495 info("registered");
1662 return 0; 1496 return 0;
1663} 1497}
1664static void __exit sd_mod_exit(void) 1498static void __exit sd_mod_exit(void)
diff --git a/drivers/media/video/gspca/spca500.c b/drivers/media/video/gspca/spca500.c
index 156206118795..17fe2c2a440d 100644
--- a/drivers/media/video/gspca/spca500.c
+++ b/drivers/media/video/gspca/spca500.c
@@ -24,9 +24,6 @@
24#include "gspca.h" 24#include "gspca.h"
25#include "jpeg.h" 25#include "jpeg.h"
26 26
27#define DRIVER_VERSION_NUMBER KERNEL_VERSION(2, 1, 7)
28static const char version[] = "2.1.7";
29
30MODULE_AUTHOR("Michel Xhaard <mxhaard@users.sourceforge.net>"); 27MODULE_AUTHOR("Michel Xhaard <mxhaard@users.sourceforge.net>");
31MODULE_DESCRIPTION("GSPCA/SPCA500 USB Camera Driver"); 28MODULE_DESCRIPTION("GSPCA/SPCA500 USB Camera Driver");
32MODULE_LICENSE("GPL"); 29MODULE_LICENSE("GPL");
@@ -630,109 +627,10 @@ static int sd_config(struct gspca_dev *gspca_dev,
630{ 627{
631 struct sd *sd = (struct sd *) gspca_dev; 628 struct sd *sd = (struct sd *) gspca_dev;
632 struct cam *cam; 629 struct cam *cam;
633 __u16 vendor; 630
634 __u16 product;
635
636 vendor = id->idVendor;
637 product = id->idProduct;
638 switch (vendor) {
639 case 0x040a: /* Kodak cameras */
640/* switch (product) { */
641/* case 0x0300: */
642 sd->subtype = KodakEZ200;
643/* break; */
644/* } */
645 break;
646 case 0x041e: /* Creative cameras */
647/* switch (product) { */
648/* case 0x400a: */
649 sd->subtype = CreativePCCam300;
650/* break; */
651/* } */
652 break;
653 case 0x046d: /* Logitech Labtec */
654 switch (product) {
655 case 0x0890:
656 sd->subtype = LogitechTraveler;
657 break;
658 case 0x0900:
659 sd->subtype = LogitechClickSmart310;
660 break;
661 case 0x0901:
662 sd->subtype = LogitechClickSmart510;
663 break;
664 }
665 break;
666 case 0x04a5: /* Benq */
667/* switch (product) { */
668/* case 0x300c: */
669 sd->subtype = BenqDC1016;
670/* break; */
671/* } */
672 break;
673 case 0x04fc: /* SunPlus */
674/* switch (product) { */
675/* case 0x7333: */
676 sd->subtype = PalmPixDC85;
677/* break; */
678/* } */
679 break;
680 case 0x055f: /* Mustek cameras */
681 switch (product) {
682 case 0xc200:
683 sd->subtype = MustekGsmart300;
684 break;
685 case 0xc220:
686 sd->subtype = Gsmartmini;
687 break;
688 }
689 break;
690 case 0x06bd: /* Agfa Cl20 */
691/* switch (product) { */
692/* case 0x0404: */
693 sd->subtype = AgfaCl20;
694/* break; */
695/* } */
696 break;
697 case 0x06be: /* Optimedia */
698/* switch (product) { */
699/* case 0x0800: */
700 sd->subtype = Optimedia;
701/* break; */
702/* } */
703 break;
704 case 0x084d: /* D-Link / Minton */
705/* switch (product) { */
706/* case 0x0003: * DSC-350 / S-Cam F5 */
707 sd->subtype = DLinkDSC350;
708/* break; */
709/* } */
710 break;
711 case 0x08ca: /* Aiptek */
712/* switch (product) { */
713/* case 0x0103: */
714 sd->subtype = AiptekPocketDV;
715/* break; */
716/* } */
717 break;
718 case 0x2899: /* ToptroIndustrial */
719/* switch (product) { */
720/* case 0x012c: */
721 sd->subtype = ToptroIndus;
722/* break; */
723/* } */
724 break;
725 case 0x8086: /* Intel */
726/* switch (product) { */
727/* case 0x0630: * Pocket PC Camera */
728 sd->subtype = IntelPocketPCCamera;
729/* break; */
730/* } */
731 break;
732 }
733 cam = &gspca_dev->cam; 631 cam = &gspca_dev->cam;
734 cam->dev_name = (char *) id->driver_info;
735 cam->epaddr = 0x01; 632 cam->epaddr = 0x01;
633 sd->subtype = id->driver_info;
736 if (sd->subtype != LogitechClickSmart310) { 634 if (sd->subtype != LogitechClickSmart310) {
737 cam->cam_mode = vga_mode; 635 cam->cam_mode = vga_mode;
738 cam->nmodes = sizeof vga_mode / sizeof vga_mode[0]; 636 cam->nmodes = sizeof vga_mode / sizeof vga_mode[0];
@@ -1162,23 +1060,22 @@ static struct sd_desc sd_desc = {
1162}; 1060};
1163 1061
1164/* -- module initialisation -- */ 1062/* -- module initialisation -- */
1165#define DVNM(name) .driver_info = (kernel_ulong_t) name
1166static const __devinitdata struct usb_device_id device_table[] = { 1063static const __devinitdata struct usb_device_id device_table[] = {
1167 {USB_DEVICE(0x040a, 0x0300), DVNM("Kodak EZ200")}, 1064 {USB_DEVICE(0x040a, 0x0300), .driver_info = KodakEZ200},
1168 {USB_DEVICE(0x041e, 0x400a), DVNM("Creative PC-CAM 300")}, 1065 {USB_DEVICE(0x041e, 0x400a), .driver_info = CreativePCCam300},
1169 {USB_DEVICE(0x046d, 0x0890), DVNM("Logitech QuickCam traveler")}, 1066 {USB_DEVICE(0x046d, 0x0890), .driver_info = LogitechTraveler},
1170 {USB_DEVICE(0x046d, 0x0900), DVNM("Logitech Inc. ClickSmart 310")}, 1067 {USB_DEVICE(0x046d, 0x0900), .driver_info = LogitechClickSmart310},
1171 {USB_DEVICE(0x046d, 0x0901), DVNM("Logitech Inc. ClickSmart 510")}, 1068 {USB_DEVICE(0x046d, 0x0901), .driver_info = LogitechClickSmart510},
1172 {USB_DEVICE(0x04a5, 0x300c), DVNM("Benq DC1016")}, 1069 {USB_DEVICE(0x04a5, 0x300c), .driver_info = BenqDC1016},
1173 {USB_DEVICE(0x04fc, 0x7333), DVNM("PalmPixDC85")}, 1070 {USB_DEVICE(0x04fc, 0x7333), .driver_info = PalmPixDC85},
1174 {USB_DEVICE(0x055f, 0xc200), DVNM("Mustek Gsmart 300")}, 1071 {USB_DEVICE(0x055f, 0xc200), .driver_info = MustekGsmart300},
1175 {USB_DEVICE(0x055f, 0xc220), DVNM("Gsmart Mini")}, 1072 {USB_DEVICE(0x055f, 0xc220), .driver_info = Gsmartmini},
1176 {USB_DEVICE(0x06bd, 0x0404), DVNM("Agfa CL20")}, 1073 {USB_DEVICE(0x06bd, 0x0404), .driver_info = AgfaCl20},
1177 {USB_DEVICE(0x06be, 0x0800), DVNM("Optimedia")}, 1074 {USB_DEVICE(0x06be, 0x0800), .driver_info = Optimedia},
1178 {USB_DEVICE(0x084d, 0x0003), DVNM("D-Link DSC-350")}, 1075 {USB_DEVICE(0x084d, 0x0003), .driver_info = DLinkDSC350},
1179 {USB_DEVICE(0x08ca, 0x0103), DVNM("Aiptek PocketDV")}, 1076 {USB_DEVICE(0x08ca, 0x0103), .driver_info = AiptekPocketDV},
1180 {USB_DEVICE(0x2899, 0x012c), DVNM("Toptro Industrial")}, 1077 {USB_DEVICE(0x2899, 0x012c), .driver_info = ToptroIndus},
1181 {USB_DEVICE(0x8086, 0x0630), DVNM("Intel Pocket PC Camera")}, 1078 {USB_DEVICE(0x8086, 0x0630), .driver_info = IntelPocketPCCamera},
1182 {} 1079 {}
1183}; 1080};
1184MODULE_DEVICE_TABLE(usb, device_table); 1081MODULE_DEVICE_TABLE(usb, device_table);
@@ -1203,7 +1100,7 @@ static int __init sd_mod_init(void)
1203{ 1100{
1204 if (usb_register(&sd_driver) < 0) 1101 if (usb_register(&sd_driver) < 0)
1205 return -1; 1102 return -1;
1206 PDEBUG(D_PROBE, "v%s registered", version); 1103 PDEBUG(D_PROBE, "registered");
1207 return 0; 1104 return 0;
1208} 1105}
1209static void __exit sd_mod_exit(void) 1106static void __exit sd_mod_exit(void)
diff --git a/drivers/media/video/gspca/spca501.c b/drivers/media/video/gspca/spca501.c
index 50e929de0203..51a3c3429ef0 100644
--- a/drivers/media/video/gspca/spca501.c
+++ b/drivers/media/video/gspca/spca501.c
@@ -23,9 +23,6 @@
23 23
24#include "gspca.h" 24#include "gspca.h"
25 25
26#define DRIVER_VERSION_NUMBER KERNEL_VERSION(2, 1, 7)
27static const char version[] = "2.1.7";
28
29MODULE_AUTHOR("Michel Xhaard <mxhaard@users.sourceforge.net>"); 26MODULE_AUTHOR("Michel Xhaard <mxhaard@users.sourceforge.net>");
30MODULE_DESCRIPTION("GSPCA/SPCA501 USB Camera Driver"); 27MODULE_DESCRIPTION("GSPCA/SPCA501 USB Camera Driver");
31MODULE_LICENSE("GPL"); 28MODULE_LICENSE("GPL");
@@ -1923,63 +1920,12 @@ static int sd_config(struct gspca_dev *gspca_dev,
1923{ 1920{
1924 struct sd *sd = (struct sd *) gspca_dev; 1921 struct sd *sd = (struct sd *) gspca_dev;
1925 struct cam *cam; 1922 struct cam *cam;
1926 __u16 vendor; 1923
1927 __u16 product;
1928
1929 vendor = id->idVendor;
1930 product = id->idProduct;
1931 switch (vendor) {
1932 case 0x0000: /* Unknow Camera */
1933/* switch (product) { */
1934/* case 0x0000: */
1935 sd->subtype = MystFromOriUnknownCamera;
1936/* break; */
1937/* } */
1938 break;
1939 case 0x040a: /* Kodak cameras */
1940/* switch (product) { */
1941/* case 0x0002: */
1942 sd->subtype = KodakDVC325;
1943/* break; */
1944/* } */
1945 break;
1946 case 0x0497: /* Smile International */
1947/* switch (product) { */
1948/* case 0xc001: */
1949 sd->subtype = SmileIntlCamera;
1950/* break; */
1951/* } */
1952 break;
1953 case 0x0506: /* 3COM cameras */
1954/* switch (product) { */
1955/* case 0x00df: */
1956 sd->subtype = ThreeComHomeConnectLite;
1957/* break; */
1958/* } */
1959 break;
1960 case 0x0733: /* Rebadged ViewQuest (Intel) and ViewQuest cameras */
1961 switch (product) {
1962 case 0x0401:
1963 sd->subtype = IntelCreateAndShare;
1964 break;
1965 case 0x0402:
1966 sd->subtype = ViewQuestM318B;
1967 break;
1968 }
1969 break;
1970 case 0x1776: /* Arowana */
1971/* switch (product) { */
1972/* case 0x501c: */
1973 sd->subtype = Arowana300KCMOSCamera;
1974/* break; */
1975/* } */
1976 break;
1977 }
1978 cam = &gspca_dev->cam; 1924 cam = &gspca_dev->cam;
1979 cam->dev_name = (char *) id->driver_info;
1980 cam->epaddr = 0x01; 1925 cam->epaddr = 0x01;
1981 cam->cam_mode = vga_mode; 1926 cam->cam_mode = vga_mode;
1982 cam->nmodes = sizeof vga_mode / sizeof vga_mode[0]; 1927 cam->nmodes = sizeof vga_mode / sizeof vga_mode[0];
1928 sd->subtype = id->driver_info;
1983 sd->brightness = sd_ctrls[MY_BRIGHTNESS].qctrl.default_value; 1929 sd->brightness = sd_ctrls[MY_BRIGHTNESS].qctrl.default_value;
1984 sd->contrast = sd_ctrls[MY_CONTRAST].qctrl.default_value; 1930 sd->contrast = sd_ctrls[MY_CONTRAST].qctrl.default_value;
1985 sd->colors = sd_ctrls[MY_COLOR].qctrl.default_value; 1931 sd->colors = sd_ctrls[MY_COLOR].qctrl.default_value;
@@ -2183,15 +2129,14 @@ static const struct sd_desc sd_desc = {
2183}; 2129};
2184 2130
2185/* -- module initialisation -- */ 2131/* -- module initialisation -- */
2186#define DVNM(name) .driver_info = (kernel_ulong_t) name
2187static const __devinitdata struct usb_device_id device_table[] = { 2132static const __devinitdata struct usb_device_id device_table[] = {
2188 {USB_DEVICE(0x040a, 0x0002), DVNM("Kodak DVC-325")}, 2133 {USB_DEVICE(0x040a, 0x0002), .driver_info = KodakDVC325},
2189 {USB_DEVICE(0x0497, 0xc001), DVNM("Smile International")}, 2134 {USB_DEVICE(0x0497, 0xc001), .driver_info = SmileIntlCamera},
2190 {USB_DEVICE(0x0506, 0x00df), DVNM("3Com HomeConnect Lite")}, 2135 {USB_DEVICE(0x0506, 0x00df), .driver_info = ThreeComHomeConnectLite},
2191 {USB_DEVICE(0x0733, 0x0401), DVNM("Intel Create and Share")}, 2136 {USB_DEVICE(0x0733, 0x0401), .driver_info = IntelCreateAndShare},
2192 {USB_DEVICE(0x0733, 0x0402), DVNM("ViewQuest M318B")}, 2137 {USB_DEVICE(0x0733, 0x0402), .driver_info = ViewQuestM318B},
2193 {USB_DEVICE(0x1776, 0x501c), DVNM("Arowana 300K CMOS Camera")}, 2138 {USB_DEVICE(0x1776, 0x501c), .driver_info = Arowana300KCMOSCamera},
2194 {USB_DEVICE(0x0000, 0x0000), DVNM("MystFromOri Unknow Camera")}, 2139 {USB_DEVICE(0x0000, 0x0000), .driver_info = MystFromOriUnknownCamera},
2195 {} 2140 {}
2196}; 2141};
2197MODULE_DEVICE_TABLE(usb, device_table); 2142MODULE_DEVICE_TABLE(usb, device_table);
@@ -2216,7 +2161,7 @@ static int __init sd_mod_init(void)
2216{ 2161{
2217 if (usb_register(&sd_driver) < 0) 2162 if (usb_register(&sd_driver) < 0)
2218 return -1; 2163 return -1;
2219 PDEBUG(D_PROBE, "v%s registered", version); 2164 PDEBUG(D_PROBE, "registered");
2220 return 0; 2165 return 0;
2221} 2166}
2222static void __exit sd_mod_exit(void) 2167static void __exit sd_mod_exit(void)
diff --git a/drivers/media/video/gspca/spca505.c b/drivers/media/video/gspca/spca505.c
index ddea6e140aa8..3c2be80cbd65 100644
--- a/drivers/media/video/gspca/spca505.c
+++ b/drivers/media/video/gspca/spca505.c
@@ -23,9 +23,6 @@
23 23
24#include "gspca.h" 24#include "gspca.h"
25 25
26#define DRIVER_VERSION_NUMBER KERNEL_VERSION(2, 1, 7)
27static const char version[] = "2.1.7";
28
29MODULE_AUTHOR("Michel Xhaard <mxhaard@users.sourceforge.net>"); 26MODULE_AUTHOR("Michel Xhaard <mxhaard@users.sourceforge.net>");
30MODULE_DESCRIPTION("GSPCA/SPCA505 USB Camera Driver"); 27MODULE_DESCRIPTION("GSPCA/SPCA505 USB Camera Driver");
31MODULE_LICENSE("GPL"); 28MODULE_LICENSE("GPL");
@@ -34,10 +31,6 @@ MODULE_LICENSE("GPL");
34struct sd { 31struct sd {
35 struct gspca_dev gspca_dev; /* !! must be the first item */ 32 struct gspca_dev gspca_dev; /* !! must be the first item */
36 33
37 int buflen;
38 unsigned char tmpbuf[640 * 480 * 3 / 2]; /* YYUV per line */
39 unsigned char tmpbuf2[640 * 480 * 2]; /* YUYV */
40
41 unsigned char brightness; 34 unsigned char brightness;
42 35
43 char subtype; 36 char subtype;
@@ -67,29 +60,29 @@ static struct ctrl sd_ctrls[] = {
67}; 60};
68 61
69static struct v4l2_pix_format vga_mode[] = { 62static struct v4l2_pix_format vga_mode[] = {
70 {160, 120, V4L2_PIX_FMT_YUYV, V4L2_FIELD_NONE, 63 {160, 120, V4L2_PIX_FMT_SPCA505, V4L2_FIELD_NONE,
71 .bytesperline = 160 * 2, 64 .bytesperline = 160 * 3,
72 .sizeimage = 160 * 120 * 2, 65 .sizeimage = 160 * 120 * 3 / 2,
73 .colorspace = V4L2_COLORSPACE_SRGB, 66 .colorspace = V4L2_COLORSPACE_SRGB,
74 .priv = 5}, 67 .priv = 5},
75 {176, 144, V4L2_PIX_FMT_YUYV, V4L2_FIELD_NONE, 68 {176, 144, V4L2_PIX_FMT_SPCA505, V4L2_FIELD_NONE,
76 .bytesperline = 176 * 2, 69 .bytesperline = 176 * 3,
77 .sizeimage = 176 * 144 * 2, 70 .sizeimage = 176 * 144 * 3 / 2,
78 .colorspace = V4L2_COLORSPACE_SRGB, 71 .colorspace = V4L2_COLORSPACE_SRGB,
79 .priv = 4}, 72 .priv = 4},
80 {320, 240, V4L2_PIX_FMT_YUYV, V4L2_FIELD_NONE, 73 {320, 240, V4L2_PIX_FMT_SPCA505, V4L2_FIELD_NONE,
81 .bytesperline = 320 * 2, 74 .bytesperline = 320 * 3,
82 .sizeimage = 320 * 240 * 2, 75 .sizeimage = 320 * 240 * 3 / 2,
83 .colorspace = V4L2_COLORSPACE_SRGB, 76 .colorspace = V4L2_COLORSPACE_SRGB,
84 .priv = 2}, 77 .priv = 2},
85 {352, 288, V4L2_PIX_FMT_YUYV, V4L2_FIELD_NONE, 78 {352, 288, V4L2_PIX_FMT_SPCA505, V4L2_FIELD_NONE,
86 .bytesperline = 352 * 2, 79 .bytesperline = 352 * 3,
87 .sizeimage = 352 * 288 * 2, 80 .sizeimage = 352 * 288 * 3 / 2,
88 .colorspace = V4L2_COLORSPACE_SRGB, 81 .colorspace = V4L2_COLORSPACE_SRGB,
89 .priv = 1}, 82 .priv = 1},
90 {640, 480, V4L2_PIX_FMT_YUYV, V4L2_FIELD_NONE, 83 {640, 480, V4L2_PIX_FMT_SPCA505, V4L2_FIELD_NONE,
91 .bytesperline = 640 * 2, 84 .bytesperline = 640 * 3,
92 .sizeimage = 640 * 480 * 2, 85 .sizeimage = 640 * 480 * 3 / 2,
93 .colorspace = V4L2_COLORSPACE_SRGB, 86 .colorspace = V4L2_COLORSPACE_SRGB,
94 .priv = 0}, 87 .priv = 0},
95}; 88};
@@ -641,33 +634,11 @@ static int sd_config(struct gspca_dev *gspca_dev,
641{ 634{
642 struct sd *sd = (struct sd *) gspca_dev; 635 struct sd *sd = (struct sd *) gspca_dev;
643 struct cam *cam; 636 struct cam *cam;
644 __u16 vendor;
645 __u16 product;
646
647 vendor = id->idVendor;
648 product = id->idProduct;
649 switch (vendor) {
650 case 0x041e: /* Creative cameras */
651/* switch (product) { */
652/* case 0x401d: * here505b */
653 sd->subtype = Nxultra;
654/* break; */
655/* } */
656 break;
657 case 0x0733: /* Rebadged ViewQuest (Intel) and ViewQuest cameras */
658/* switch (product) { */
659/* case 0x0430: */
660/* fixme: may be UsbGrabberPV321 BRIDGE_SPCA506 SENSOR_SAA7113 */
661 sd->subtype = IntelPCCameraPro;
662/* break; */
663/* } */
664 break;
665 }
666 637
667 cam = &gspca_dev->cam; 638 cam = &gspca_dev->cam;
668 cam->dev_name = (char *) id->driver_info;
669 cam->epaddr = 0x01; 639 cam->epaddr = 0x01;
670 cam->cam_mode = vga_mode; 640 cam->cam_mode = vga_mode;
641 sd->subtype = id->driver_info;
671 if (sd->subtype != IntelPCCameraPro) 642 if (sd->subtype != IntelPCCameraPro)
672 cam->nmodes = sizeof vga_mode / sizeof vga_mode[0]; 643 cam->nmodes = sizeof vga_mode / sizeof vga_mode[0];
673 else /* no 640x480 for IntelPCCameraPro */ 644 else /* no 640x480 for IntelPCCameraPro */
@@ -785,77 +756,30 @@ static void sd_close(struct gspca_dev *gspca_dev)
785 reg_write(gspca_dev->dev, 0x05, 0x11, 0xf); 756 reg_write(gspca_dev->dev, 0x05, 0x11, 0xf);
786} 757}
787 758
788/* convert YYUV per line to YUYV (YUV 4:2:2) */
789static void yyuv_decode(unsigned char *out,
790 unsigned char *in,
791 int width,
792 int height)
793{
794 unsigned char *Ui, *Vi, *yi, *yi1;
795 unsigned char *out1;
796 int i, j;
797
798 yi = in;
799 for (i = height / 2; --i >= 0; ) {
800 out1 = out + width * 2; /* next line */
801 yi1 = yi + width;
802 Ui = yi1 + width;
803 Vi = Ui + width / 2;
804 for (j = width / 2; --j >= 0; ) {
805 *out++ = 128 + *yi++;
806 *out++ = 128 + *Ui;
807 *out++ = 128 + *yi++;
808 *out++ = 128 + *Vi;
809
810 *out1++ = 128 + *yi1++;
811 *out1++ = 128 + *Ui++;
812 *out1++ = 128 + *yi1++;
813 *out1++ = 128 + *Vi++;
814 }
815 yi += width * 2;
816 out = out1;
817 }
818}
819
820static void sd_pkt_scan(struct gspca_dev *gspca_dev, 759static void sd_pkt_scan(struct gspca_dev *gspca_dev,
821 struct gspca_frame *frame, /* target */ 760 struct gspca_frame *frame, /* target */
822 __u8 *data, /* isoc packet */ 761 __u8 *data, /* isoc packet */
823 int len) /* iso packet length */ 762 int len) /* iso packet length */
824{ 763{
825 struct sd *sd = (struct sd *) gspca_dev;
826
827 switch (data[0]) { 764 switch (data[0]) {
828 case 0: /* start of frame */ 765 case 0: /* start of frame */
829 if (gspca_dev->last_packet_type == FIRST_PACKET) { 766 frame = gspca_frame_add(gspca_dev, LAST_PACKET, frame,
830 yyuv_decode(sd->tmpbuf2, sd->tmpbuf, 767 data, 0);
831 gspca_dev->width,
832 gspca_dev->height);
833 frame = gspca_frame_add(gspca_dev,
834 LAST_PACKET,
835 frame,
836 sd->tmpbuf2,
837 gspca_dev->width
838 * gspca_dev->height
839 * 2);
840 }
841 gspca_frame_add(gspca_dev, FIRST_PACKET, frame,
842 data, 0);
843 data += SPCA50X_OFFSET_DATA; 768 data += SPCA50X_OFFSET_DATA;
844 len -= SPCA50X_OFFSET_DATA; 769 len -= SPCA50X_OFFSET_DATA;
845 if (len > 0) 770 gspca_frame_add(gspca_dev, FIRST_PACKET, frame,
846 memcpy(sd->tmpbuf, data, len); 771 data, len);
847 else 772 break;
848 len = 0;
849 sd->buflen = len;
850 return;
851 case 0xff: /* drop */ 773 case 0xff: /* drop */
852/* gspca_dev->last_packet_type = DISCARD_PACKET; */ 774/* gspca_dev->last_packet_type = DISCARD_PACKET; */
853 return; 775 break;
776 default:
777 data += 1;
778 len -= 1;
779 gspca_frame_add(gspca_dev, FIRST_PACKET, frame,
780 data, len);
781 break;
854 } 782 }
855 data += 1;
856 len -= 1;
857 memcpy(&sd->tmpbuf[sd->buflen], data, len);
858 sd->buflen += len;
859} 783}
860 784
861static void setbrightness(struct gspca_dev *gspca_dev) 785static void setbrightness(struct gspca_dev *gspca_dev)
@@ -910,10 +834,10 @@ static const struct sd_desc sd_desc = {
910}; 834};
911 835
912/* -- module initialisation -- */ 836/* -- module initialisation -- */
913#define DVNM(name) .driver_info = (kernel_ulong_t) name
914static const __devinitdata struct usb_device_id device_table[] = { 837static const __devinitdata struct usb_device_id device_table[] = {
915 {USB_DEVICE(0x041e, 0x401d), DVNM("Creative Webcam NX ULTRA")}, 838 {USB_DEVICE(0x041e, 0x401d), .driver_info = Nxultra},
916 {USB_DEVICE(0x0733, 0x0430), DVNM("Intel PC Camera Pro")}, 839 {USB_DEVICE(0x0733, 0x0430), .driver_info = IntelPCCameraPro},
840/*fixme: may be UsbGrabberPV321 BRIDGE_SPCA506 SENSOR_SAA7113 */
917 {} 841 {}
918}; 842};
919MODULE_DEVICE_TABLE(usb, device_table); 843MODULE_DEVICE_TABLE(usb, device_table);
@@ -938,7 +862,7 @@ static int __init sd_mod_init(void)
938{ 862{
939 if (usb_register(&sd_driver) < 0) 863 if (usb_register(&sd_driver) < 0)
940 return -1; 864 return -1;
941 PDEBUG(D_PROBE, "v%s registered", version); 865 PDEBUG(D_PROBE, "registered");
942 return 0; 866 return 0;
943} 867}
944static void __exit sd_mod_exit(void) 868static void __exit sd_mod_exit(void)
diff --git a/drivers/media/video/gspca/spca506.c b/drivers/media/video/gspca/spca506.c
index 143203c1fd9f..6fe715c80ad2 100644
--- a/drivers/media/video/gspca/spca506.c
+++ b/drivers/media/video/gspca/spca506.c
@@ -25,9 +25,6 @@
25 25
26#include "gspca.h" 26#include "gspca.h"
27 27
28#define DRIVER_VERSION_NUMBER KERNEL_VERSION(2, 1, 7)
29static const char version[] = "2.1.7";
30
31MODULE_AUTHOR("Michel Xhaard <mxhaard@users.sourceforge.net>"); 28MODULE_AUTHOR("Michel Xhaard <mxhaard@users.sourceforge.net>");
32MODULE_DESCRIPTION("GSPCA/SPCA506 USB Camera Driver"); 29MODULE_DESCRIPTION("GSPCA/SPCA506 USB Camera Driver");
33MODULE_LICENSE("GPL"); 30MODULE_LICENSE("GPL");
@@ -36,10 +33,6 @@ MODULE_LICENSE("GPL");
36struct sd { 33struct sd {
37 struct gspca_dev gspca_dev; /* !! must be the first item */ 34 struct gspca_dev gspca_dev; /* !! must be the first item */
38 35
39 int buflen;
40 __u8 tmpbuf[640 * 480 * 3]; /* YYUV per line */
41 __u8 tmpbuf2[640 * 480 * 2]; /* YUYV */
42
43 unsigned char brightness; 36 unsigned char brightness;
44 unsigned char contrast; 37 unsigned char contrast;
45 unsigned char colors; 38 unsigned char colors;
@@ -118,29 +111,29 @@ static struct ctrl sd_ctrls[] = {
118}; 111};
119 112
120static struct v4l2_pix_format vga_mode[] = { 113static struct v4l2_pix_format vga_mode[] = {
121 {160, 120, V4L2_PIX_FMT_YUYV, V4L2_FIELD_NONE, 114 {160, 120, V4L2_PIX_FMT_SPCA505, V4L2_FIELD_NONE,
122 .bytesperline = 160 * 2, 115 .bytesperline = 160 * 3,
123 .sizeimage = 160 * 120 * 2, 116 .sizeimage = 160 * 120 * 3 / 2,
124 .colorspace = V4L2_COLORSPACE_SRGB, 117 .colorspace = V4L2_COLORSPACE_SRGB,
125 .priv = 5}, 118 .priv = 5},
126 {176, 144, V4L2_PIX_FMT_YUYV, V4L2_FIELD_NONE, 119 {176, 144, V4L2_PIX_FMT_SPCA505, V4L2_FIELD_NONE,
127 .bytesperline = 176 * 2, 120 .bytesperline = 176 * 3,
128 .sizeimage = 176 * 144 * 2, 121 .sizeimage = 176 * 144 * 3 / 2,
129 .colorspace = V4L2_COLORSPACE_SRGB, 122 .colorspace = V4L2_COLORSPACE_SRGB,
130 .priv = 4}, 123 .priv = 4},
131 {320, 240, V4L2_PIX_FMT_YUYV, V4L2_FIELD_NONE, 124 {320, 240, V4L2_PIX_FMT_SPCA505, V4L2_FIELD_NONE,
132 .bytesperline = 320 * 2, 125 .bytesperline = 320 * 3,
133 .sizeimage = 320 * 240 * 2, 126 .sizeimage = 320 * 240 * 3 / 2,
134 .colorspace = V4L2_COLORSPACE_SRGB, 127 .colorspace = V4L2_COLORSPACE_SRGB,
135 .priv = 2}, 128 .priv = 2},
136 {352, 288, V4L2_PIX_FMT_YUYV, V4L2_FIELD_NONE, 129 {352, 288, V4L2_PIX_FMT_SPCA505, V4L2_FIELD_NONE,
137 .bytesperline = 352 * 2, 130 .bytesperline = 352 * 3,
138 .sizeimage = 352 * 288 * 2, 131 .sizeimage = 352 * 288 * 3 / 2,
139 .colorspace = V4L2_COLORSPACE_SRGB, 132 .colorspace = V4L2_COLORSPACE_SRGB,
140 .priv = 1}, 133 .priv = 1},
141 {640, 480, V4L2_PIX_FMT_YUYV, V4L2_FIELD_NONE, 134 {640, 480, V4L2_PIX_FMT_SPCA505, V4L2_FIELD_NONE,
142 .bytesperline = 640 * 2, 135 .bytesperline = 640 * 3,
143 .sizeimage = 640 * 480 * 2, 136 .sizeimage = 640 * 480 * 3 / 2,
144 .colorspace = V4L2_COLORSPACE_SRGB, 137 .colorspace = V4L2_COLORSPACE_SRGB,
145 .priv = 0}, 138 .priv = 0},
146}; 139};
@@ -310,7 +303,6 @@ static int sd_config(struct gspca_dev *gspca_dev,
310 struct cam *cam; 303 struct cam *cam;
311 304
312 cam = &gspca_dev->cam; 305 cam = &gspca_dev->cam;
313 cam->dev_name = (char *) id->driver_info;
314 cam->epaddr = 0x01; 306 cam->epaddr = 0x01;
315 cam->cam_mode = vga_mode; 307 cam->cam_mode = vga_mode;
316 cam->nmodes = sizeof vga_mode / sizeof vga_mode[0]; 308 cam->nmodes = sizeof vga_mode / sizeof vga_mode[0];
@@ -576,77 +568,30 @@ static void sd_close(struct gspca_dev *gspca_dev)
576{ 568{
577} 569}
578 570
579/* convert YYUV per line to YUYV (YUV 4:2:2) */
580static void yyuv_decode(unsigned char *out,
581 unsigned char *in,
582 int width,
583 int height)
584{
585 unsigned char *Ui, *Vi, *yi, *yi1;
586 unsigned char *out1;
587 int i, j;
588
589 yi = in;
590 for (i = height / 2; --i >= 0; ) {
591 out1 = out + width * 2; /* next line */
592 yi1 = yi + width;
593 Ui = yi1 + width;
594 Vi = Ui + width / 2;
595 for (j = width / 2; --j >= 0; ) {
596 *out++ = 128 + *yi++;
597 *out++ = 128 + *Ui;
598 *out++ = 128 + *yi++;
599 *out++ = 128 + *Vi;
600
601 *out1++ = 128 + *yi1++;
602 *out1++ = 128 + *Ui++;
603 *out1++ = 128 + *yi1++;
604 *out1++ = 128 + *Vi++;
605 }
606 yi += width * 2;
607 out = out1;
608 }
609}
610
611static void sd_pkt_scan(struct gspca_dev *gspca_dev, 571static void sd_pkt_scan(struct gspca_dev *gspca_dev,
612 struct gspca_frame *frame, /* target */ 572 struct gspca_frame *frame, /* target */
613 __u8 *data, /* isoc packet */ 573 __u8 *data, /* isoc packet */
614 int len) /* iso packet length */ 574 int len) /* iso packet length */
615{ 575{
616 struct sd *sd = (struct sd *) gspca_dev;
617
618 switch (data[0]) { 576 switch (data[0]) {
619 case 0: /* start of frame */ 577 case 0: /* start of frame */
620 if (gspca_dev->last_packet_type == FIRST_PACKET) { 578 frame = gspca_frame_add(gspca_dev, LAST_PACKET, frame,
621 yyuv_decode(sd->tmpbuf2, sd->tmpbuf, 579 data, 0);
622 gspca_dev->width,
623 gspca_dev->height);
624 frame = gspca_frame_add(gspca_dev,
625 LAST_PACKET,
626 frame,
627 sd->tmpbuf2,
628 gspca_dev->width
629 * gspca_dev->height
630 * 2);
631 }
632 gspca_frame_add(gspca_dev, FIRST_PACKET, frame,
633 data, 0);
634 data += SPCA50X_OFFSET_DATA; 580 data += SPCA50X_OFFSET_DATA;
635 len -= SPCA50X_OFFSET_DATA; 581 len -= SPCA50X_OFFSET_DATA;
636 if (len > 0) 582 gspca_frame_add(gspca_dev, FIRST_PACKET, frame,
637 memcpy(sd->tmpbuf, data, len); 583 data, len);
638 else 584 break;
639 len = 0;
640 sd->buflen = len;
641 return;
642 case 0xff: /* drop */ 585 case 0xff: /* drop */
643/* gspca_dev->last_packet_type = DISCARD_PACKET; */ 586/* gspca_dev->last_packet_type = DISCARD_PACKET; */
644 return; 587 break;
588 default:
589 data += 1;
590 len -= 1;
591 gspca_frame_add(gspca_dev, FIRST_PACKET, frame,
592 data, len);
593 break;
645 } 594 }
646 data += 1;
647 len -= 1;
648 memcpy(&sd->tmpbuf[sd->buflen], data, len);
649 sd->buflen += len;
650} 595}
651 596
652static void setbrightness(struct gspca_dev *gspca_dev) 597static void setbrightness(struct gspca_dev *gspca_dev)
@@ -804,12 +749,12 @@ static struct sd_desc sd_desc = {
804}; 749};
805 750
806/* -- module initialisation -- */ 751/* -- module initialisation -- */
807#define DVNM(name) .driver_info = (kernel_ulong_t) name
808static __devinitdata struct usb_device_id device_table[] = { 752static __devinitdata struct usb_device_id device_table[] = {
809 {USB_DEVICE(0x06e1, 0xa190), DVNM("ADS Instant VCD")}, 753 {USB_DEVICE(0x06e1, 0xa190)},
810/* {USB_DEVICE(0x0733, 0x0430), DVNM("UsbGrabber PV321c")}, */ 754/*fixme: may be IntelPCCameraPro BRIDGE_SPCA505
811 {USB_DEVICE(0x0734, 0x043b), DVNM("3DeMon USB Capture aka")}, 755 {USB_DEVICE(0x0733, 0x0430)}, */
812 {USB_DEVICE(0x99fa, 0x8988), DVNM("Grandtec V.cap")}, 756 {USB_DEVICE(0x0734, 0x043b)},
757 {USB_DEVICE(0x99fa, 0x8988)},
813 {} 758 {}
814}; 759};
815MODULE_DEVICE_TABLE(usb, device_table); 760MODULE_DEVICE_TABLE(usb, device_table);
@@ -834,7 +779,7 @@ static int __init sd_mod_init(void)
834{ 779{
835 if (usb_register(&sd_driver) < 0) 780 if (usb_register(&sd_driver) < 0)
836 return -1; 781 return -1;
837 PDEBUG(D_PROBE, "v%s registered", version); 782 PDEBUG(D_PROBE, "registered");
838 return 0; 783 return 0;
839} 784}
840static void __exit sd_mod_exit(void) 785static void __exit sd_mod_exit(void)
diff --git a/drivers/media/video/gspca/spca508.c b/drivers/media/video/gspca/spca508.c
index d8cd93866a4a..b608a27ad115 100644
--- a/drivers/media/video/gspca/spca508.c
+++ b/drivers/media/video/gspca/spca508.c
@@ -22,9 +22,6 @@
22 22
23#include "gspca.h" 23#include "gspca.h"
24 24
25#define DRIVER_VERSION_NUMBER KERNEL_VERSION(2, 1, 7)
26static const char version[] = "2.1.7";
27
28MODULE_AUTHOR("Michel Xhaard <mxhaard@users.sourceforge.net>"); 25MODULE_AUTHOR("Michel Xhaard <mxhaard@users.sourceforge.net>");
29MODULE_DESCRIPTION("GSPCA/SPCA508 USB Camera Driver"); 26MODULE_DESCRIPTION("GSPCA/SPCA508 USB Camera Driver");
30MODULE_LICENSE("GPL"); 27MODULE_LICENSE("GPL");
@@ -33,10 +30,6 @@ MODULE_LICENSE("GPL");
33struct sd { 30struct sd {
34 struct gspca_dev gspca_dev; /* !! must be the first item */ 31 struct gspca_dev gspca_dev; /* !! must be the first item */
35 32
36 int buflen;
37 unsigned char tmpbuf[352 * 288 * 3 / 2]; /* YUVY per line */
38 unsigned char tmpbuf2[352 * 288 * 2]; /* YUYV */
39
40 unsigned char brightness; 33 unsigned char brightness;
41 34
42 char subtype; 35 char subtype;
@@ -71,23 +64,23 @@ static struct ctrl sd_ctrls[] = {
71 64
72static struct v4l2_pix_format sif_mode[] = { 65static struct v4l2_pix_format sif_mode[] = {
73 {160, 120, V4L2_PIX_FMT_YUYV, V4L2_FIELD_NONE, 66 {160, 120, V4L2_PIX_FMT_YUYV, V4L2_FIELD_NONE,
74 .bytesperline = 160 * 2, 67 .bytesperline = 160 * 3,
75 .sizeimage = 160 * 120 * 2, 68 .sizeimage = 160 * 120 * 3 / 2,
76 .colorspace = V4L2_COLORSPACE_SRGB, 69 .colorspace = V4L2_COLORSPACE_SRGB,
77 .priv = 3}, 70 .priv = 3},
78 {176, 144, V4L2_PIX_FMT_YUYV, V4L2_FIELD_NONE, 71 {176, 144, V4L2_PIX_FMT_YUYV, V4L2_FIELD_NONE,
79 .bytesperline = 176 * 2, 72 .bytesperline = 176 * 3,
80 .sizeimage = 176 * 144 * 2, 73 .sizeimage = 176 * 144 * 3 / 2,
81 .colorspace = V4L2_COLORSPACE_SRGB, 74 .colorspace = V4L2_COLORSPACE_SRGB,
82 .priv = 2}, 75 .priv = 2},
83 {320, 240, V4L2_PIX_FMT_YUYV, V4L2_FIELD_NONE, 76 {320, 240, V4L2_PIX_FMT_YUYV, V4L2_FIELD_NONE,
84 .bytesperline = 320 * 2, 77 .bytesperline = 320 * 3,
85 .sizeimage = 320 * 240 * 2, 78 .sizeimage = 320 * 240 * 3 / 2,
86 .colorspace = V4L2_COLORSPACE_SRGB, 79 .colorspace = V4L2_COLORSPACE_SRGB,
87 .priv = 1}, 80 .priv = 1},
88 {352, 288, V4L2_PIX_FMT_YUYV, V4L2_FIELD_NONE, 81 {352, 288, V4L2_PIX_FMT_YUYV, V4L2_FIELD_NONE,
89 .bytesperline = 352 * 2, 82 .bytesperline = 352 * 3,
90 .sizeimage = 352 * 288 * 2, 83 .sizeimage = 352 * 288 * 3 / 2,
91 .colorspace = V4L2_COLORSPACE_SRGB, 84 .colorspace = V4L2_COLORSPACE_SRGB,
92 .priv = 0}, 85 .priv = 0},
93}; 86};
@@ -1476,58 +1469,8 @@ static int sd_config(struct gspca_dev *gspca_dev,
1476{ 1469{
1477 struct sd *sd = (struct sd *) gspca_dev; 1470 struct sd *sd = (struct sd *) gspca_dev;
1478 struct cam *cam; 1471 struct cam *cam;
1479 __u16 product;
1480 int data1, data2; 1472 int data1, data2;
1481 1473
1482 product = id->idProduct;
1483 switch (id->idVendor) {
1484 case 0x0130: /* Clone webcam */
1485/* switch (product) { */
1486/* case 0x0130: */
1487 sd->subtype = HamaUSBSightcam; /* same as Hama 0010 */
1488/* break; */
1489/* } */
1490 break;
1491 case 0x041e: /* Creative cameras */
1492/* switch (product) { */
1493/* case 0x4018: */
1494 sd->subtype = CreativeVista;
1495/* break; */
1496/* } */
1497 break;
1498 case 0x0461: /* MicroInnovation */
1499/* switch (product) { */
1500/* case 0x0815: */
1501 sd->subtype = MicroInnovationIC200;
1502/* break; */
1503/* } */
1504 break;
1505 case 0x0733: /* Rebadged ViewQuest (Intel) and ViewQuest cameras */
1506/* switch (product) { */
1507/* case 0x110: */
1508 sd->subtype = ViewQuestVQ110;
1509/* break; */
1510/* } */
1511 break;
1512 case 0x0af9: /* Hama cameras */
1513 switch (product) {
1514 case 0x0010:
1515 sd->subtype = HamaUSBSightcam;
1516 break;
1517 case 0x0011:
1518 sd->subtype = HamaUSBSightcam2;
1519 break;
1520 }
1521 break;
1522 case 0x8086: /* Intel */
1523/* switch (product) { */
1524/* case 0x0110: */
1525 sd->subtype = IntelEasyPCCamera;
1526/* break; */
1527/* } */
1528 break;
1529 }
1530
1531 /* Read from global register the USB product and vendor IDs, just to 1474 /* Read from global register the USB product and vendor IDs, just to
1532 * prove that we can communicate with the device. This works, which 1475 * prove that we can communicate with the device. This works, which
1533 * confirms at we are communicating properly and that the device 1476 * confirms at we are communicating properly and that the device
@@ -1544,10 +1487,11 @@ static int sd_config(struct gspca_dev *gspca_dev,
1544 PDEBUG(D_PROBE, "Window 1 average luminance: %d", data1); 1487 PDEBUG(D_PROBE, "Window 1 average luminance: %d", data1);
1545 1488
1546 cam = &gspca_dev->cam; 1489 cam = &gspca_dev->cam;
1547 cam->dev_name = (char *) id->driver_info;
1548 cam->epaddr = 0x01; 1490 cam->epaddr = 0x01;
1549 cam->cam_mode = sif_mode; 1491 cam->cam_mode = sif_mode;
1550 cam->nmodes = ARRAY_SIZE(sif_mode); 1492 cam->nmodes = ARRAY_SIZE(sif_mode);
1493
1494 sd->subtype = id->driver_info;
1551 sd->brightness = BRIGHTNESS_DEF; 1495 sd->brightness = BRIGHTNESS_DEF;
1552 1496
1553 switch (sd->subtype) { 1497 switch (sd->subtype) {
@@ -1619,77 +1563,30 @@ static void sd_close(struct gspca_dev *gspca_dev)
1619{ 1563{
1620} 1564}
1621 1565
1622/* convert YUVY per line to YUYV (YUV 4:2:2) */
1623static void yuvy_decode(unsigned char *out,
1624 unsigned char *in,
1625 int width,
1626 int height)
1627{
1628 unsigned char *Ui, *Vi, *yi, *yi1;
1629 unsigned char *out1;
1630 int i, j;
1631
1632 yi = in;
1633 for (i = height / 2; --i >= 0; ) {
1634 out1 = out + width * 2; /* next line */
1635 Ui = yi + width;
1636 Vi = Ui + width / 2;
1637 yi1 = Vi + width / 2;
1638 for (j = width / 2; --j >= 0; ) {
1639 *out++ = 128 + *yi++;
1640 *out++ = 128 + *Ui;
1641 *out++ = 128 + *yi++;
1642 *out++ = 128 + *Vi;
1643
1644 *out1++ = 128 + *yi1++;
1645 *out1++ = 128 + *Ui++;
1646 *out1++ = 128 + *yi1++;
1647 *out1++ = 128 + *Vi++;
1648 }
1649 yi += width * 2;
1650 out = out1;
1651 }
1652}
1653
1654static void sd_pkt_scan(struct gspca_dev *gspca_dev, 1566static void sd_pkt_scan(struct gspca_dev *gspca_dev,
1655 struct gspca_frame *frame, /* target */ 1567 struct gspca_frame *frame, /* target */
1656 __u8 *data, /* isoc packet */ 1568 __u8 *data, /* isoc packet */
1657 int len) /* iso packet length */ 1569 int len) /* iso packet length */
1658{ 1570{
1659 struct sd *sd = (struct sd *) gspca_dev;
1660
1661 switch (data[0]) { 1571 switch (data[0]) {
1662 case 0: /* start of frame */ 1572 case 0: /* start of frame */
1663 if (gspca_dev->last_packet_type == FIRST_PACKET) { 1573 frame = gspca_frame_add(gspca_dev, LAST_PACKET, frame,
1664 yuvy_decode(sd->tmpbuf2, sd->tmpbuf, 1574 data, 0);
1665 gspca_dev->width,
1666 gspca_dev->height);
1667 frame = gspca_frame_add(gspca_dev,
1668 LAST_PACKET,
1669 frame,
1670 sd->tmpbuf2,
1671 gspca_dev->width
1672 * gspca_dev->height
1673 * 2);
1674 }
1675 gspca_frame_add(gspca_dev, FIRST_PACKET, frame,
1676 data, 0);
1677 data += SPCA508_OFFSET_DATA; 1575 data += SPCA508_OFFSET_DATA;
1678 len -= SPCA508_OFFSET_DATA; 1576 len -= SPCA508_OFFSET_DATA;
1679 if (len > 0) 1577 gspca_frame_add(gspca_dev, FIRST_PACKET, frame,
1680 memcpy(sd->tmpbuf, data, len); 1578 data, len);
1681 else 1579 break;
1682 len = 0;
1683 sd->buflen = len;
1684 return;
1685 case 0xff: /* drop */ 1580 case 0xff: /* drop */
1686/* gspca_dev->last_packet_type = DISCARD_PACKET; */ 1581/* gspca_dev->last_packet_type = DISCARD_PACKET; */
1687 return; 1582 break;
1583 default:
1584 data += 1;
1585 len -= 1;
1586 gspca_frame_add(gspca_dev, FIRST_PACKET, frame,
1587 data, len);
1588 break;
1688 } 1589 }
1689 data += 1;
1690 len -= 1;
1691 memcpy(&sd->tmpbuf[sd->buflen], data, len);
1692 sd->buflen += len;
1693} 1590}
1694 1591
1695static void setbrightness(struct gspca_dev *gspca_dev) 1592static void setbrightness(struct gspca_dev *gspca_dev)
@@ -1745,15 +1642,14 @@ static const struct sd_desc sd_desc = {
1745}; 1642};
1746 1643
1747/* -- module initialisation -- */ 1644/* -- module initialisation -- */
1748#define DVNM(name) .driver_info = (kernel_ulong_t) name
1749static const __devinitdata struct usb_device_id device_table[] = { 1645static const __devinitdata struct usb_device_id device_table[] = {
1750 {USB_DEVICE(0x0130, 0x0130), DVNM("Clone Digital Webcam 11043")}, 1646 {USB_DEVICE(0x0130, 0x0130), .driver_info = HamaUSBSightcam},
1751 {USB_DEVICE(0x041e, 0x4018), DVNM("Creative Webcam Vista (PD1100)")}, 1647 {USB_DEVICE(0x041e, 0x4018), .driver_info = CreativeVista},
1752 {USB_DEVICE(0x0461, 0x0815), DVNM("Micro Innovation IC200")}, 1648 {USB_DEVICE(0x0461, 0x0815), .driver_info = MicroInnovationIC200},
1753 {USB_DEVICE(0x0733, 0x0110), DVNM("ViewQuest VQ110")}, 1649 {USB_DEVICE(0x0733, 0x0110), .driver_info = ViewQuestVQ110},
1754 {USB_DEVICE(0x0af9, 0x0010), DVNM("Hama USB Sightcam 100")}, 1650 {USB_DEVICE(0x0af9, 0x0010), .driver_info = HamaUSBSightcam},
1755 {USB_DEVICE(0x0af9, 0x0011), DVNM("Hama USB Sightcam 100")}, 1651 {USB_DEVICE(0x0af9, 0x0011), .driver_info = HamaUSBSightcam2},
1756 {USB_DEVICE(0x8086, 0x0110), DVNM("Intel Easy PC Camera")}, 1652 {USB_DEVICE(0x8086, 0x0110), .driver_info = IntelEasyPCCamera},
1757 {} 1653 {}
1758}; 1654};
1759MODULE_DEVICE_TABLE(usb, device_table); 1655MODULE_DEVICE_TABLE(usb, device_table);
@@ -1778,7 +1674,7 @@ static int __init sd_mod_init(void)
1778{ 1674{
1779 if (usb_register(&sd_driver) < 0) 1675 if (usb_register(&sd_driver) < 0)
1780 return -1; 1676 return -1;
1781 PDEBUG(D_PROBE, "v%s registered", version); 1677 PDEBUG(D_PROBE, "registered");
1782 return 0; 1678 return 0;
1783} 1679}
1784static void __exit sd_mod_exit(void) 1680static void __exit sd_mod_exit(void)
diff --git a/drivers/media/video/gspca/spca561.c b/drivers/media/video/gspca/spca561.c
index b659bd0f788d..a26174508cb9 100644
--- a/drivers/media/video/gspca/spca561.c
+++ b/drivers/media/video/gspca/spca561.c
@@ -24,9 +24,6 @@
24 24
25#include "gspca.h" 25#include "gspca.h"
26 26
27#define DRIVER_VERSION_NUMBER KERNEL_VERSION(2, 1, 7)
28static const char version[] = "2.1.7";
29
30MODULE_AUTHOR("Michel Xhaard <mxhaard@users.sourceforge.net>"); 27MODULE_AUTHOR("Michel Xhaard <mxhaard@users.sourceforge.net>");
31MODULE_DESCRIPTION("GSPCA/SPCA561 USB Camera Driver"); 28MODULE_DESCRIPTION("GSPCA/SPCA561 USB Camera Driver");
32MODULE_LICENSE("GPL"); 29MODULE_LICENSE("GPL");
@@ -582,35 +579,15 @@ static int sd_config(struct gspca_dev *gspca_dev,
582 PDEBUG(D_PROBE, "Bad vendor / product from device"); 579 PDEBUG(D_PROBE, "Bad vendor / product from device");
583 return -EINVAL; 580 return -EINVAL;
584 } 581 }
585 switch (product) { 582
586 case 0x0928:
587 case 0x0929:
588 case 0x092a:
589 case 0x092b:
590 case 0x092c:
591 case 0x092d:
592 case 0x092e:
593 case 0x092f:
594 case 0x403b:
595 sd->chip_revision = Rev012A;
596 break;
597 default:
598/* case 0x0561:
599 case 0x0815: * ?? in spca508.c
600 case 0x401a:
601 case 0x7004:
602 case 0x7e50:
603 case 0xa001:
604 case 0xcdee: */
605 sd->chip_revision = Rev072A;
606 break;
607 }
608 cam = &gspca_dev->cam; 583 cam = &gspca_dev->cam;
609 cam->dev_name = (char *) id->driver_info; 584 cam->dev_name = (char *) id->driver_info;
610 cam->epaddr = 0x01; 585 cam->epaddr = 0x01;
611 gspca_dev->nbalt = 7 + 1; /* choose alternate 7 first */ 586 gspca_dev->nbalt = 7 + 1; /* choose alternate 7 first */
612 cam->cam_mode = sif_mode; 587 cam->cam_mode = sif_mode;
613 cam->nmodes = sizeof sif_mode / sizeof sif_mode[0]; 588 cam->nmodes = sizeof sif_mode / sizeof sif_mode[0];
589
590 sd->chip_revision = id->driver_info;
614 sd->brightness = sd_ctrls[SD_BRIGHTNESS].qctrl.default_value; 591 sd->brightness = sd_ctrls[SD_BRIGHTNESS].qctrl.default_value;
615 sd->contrast = sd_ctrls[SD_CONTRAST].qctrl.default_value; 592 sd->contrast = sd_ctrls[SD_CONTRAST].qctrl.default_value;
616 sd->autogain = sd_ctrls[SD_AUTOGAIN].qctrl.default_value; 593 sd->autogain = sd_ctrls[SD_AUTOGAIN].qctrl.default_value;
@@ -997,23 +974,22 @@ static const struct sd_desc sd_desc = {
997}; 974};
998 975
999/* -- module initialisation -- */ 976/* -- module initialisation -- */
1000#define DVNM(name) .driver_info = (kernel_ulong_t) name
1001static const __devinitdata struct usb_device_id device_table[] = { 977static const __devinitdata struct usb_device_id device_table[] = {
1002 {USB_DEVICE(0x041e, 0x401a), DVNM("Creative Webcam Vista (PD1100)")}, 978 {USB_DEVICE(0x041e, 0x401a), .driver_info = Rev072A},
1003 {USB_DEVICE(0x041e, 0x403b), DVNM("Creative Webcam Vista (VF0010)")}, 979 {USB_DEVICE(0x041e, 0x403b), .driver_info = Rev012A},
1004 {USB_DEVICE(0x0458, 0x7004), DVNM("Genius VideoCAM Express V2")}, 980 {USB_DEVICE(0x0458, 0x7004), .driver_info = Rev072A},
1005 {USB_DEVICE(0x046d, 0x0928), DVNM("Logitech QC Express Etch2")}, 981 {USB_DEVICE(0x046d, 0x0928), .driver_info = Rev012A},
1006 {USB_DEVICE(0x046d, 0x0929), DVNM("Labtec Webcam Elch2")}, 982 {USB_DEVICE(0x046d, 0x0929), .driver_info = Rev012A},
1007 {USB_DEVICE(0x046d, 0x092a), DVNM("Logitech QC for Notebook")}, 983 {USB_DEVICE(0x046d, 0x092a), .driver_info = Rev012A},
1008 {USB_DEVICE(0x046d, 0x092b), DVNM("Labtec Webcam Plus")}, 984 {USB_DEVICE(0x046d, 0x092b), .driver_info = Rev012A},
1009 {USB_DEVICE(0x046d, 0x092c), DVNM("Logitech QC chat Elch2")}, 985 {USB_DEVICE(0x046d, 0x092c), .driver_info = Rev012A},
1010 {USB_DEVICE(0x046d, 0x092d), DVNM("Logitech QC Elch2")}, 986 {USB_DEVICE(0x046d, 0x092d), .driver_info = Rev012A},
1011 {USB_DEVICE(0x046d, 0x092e), DVNM("Logitech QC Elch2")}, 987 {USB_DEVICE(0x046d, 0x092e), .driver_info = Rev012A},
1012 {USB_DEVICE(0x046d, 0x092f), DVNM("Logitech QC Elch2")}, 988 {USB_DEVICE(0x046d, 0x092f), .driver_info = Rev012A},
1013 {USB_DEVICE(0x04fc, 0x0561), DVNM("Flexcam 100")}, 989 {USB_DEVICE(0x04fc, 0x0561), .driver_info = Rev072A},
1014 {USB_DEVICE(0x060b, 0xa001), DVNM("Maxell Compact Pc PM3")}, 990 {USB_DEVICE(0x060b, 0xa001), .driver_info = Rev072A},
1015 {USB_DEVICE(0x10fd, 0x7e50), DVNM("FlyCam Usb 100")}, 991 {USB_DEVICE(0x10fd, 0x7e50), .driver_info = Rev072A},
1016 {USB_DEVICE(0xabcd, 0xcdee), DVNM("Petcam")}, 992 {USB_DEVICE(0xabcd, 0xcdee), .driver_info = Rev072A},
1017 {} 993 {}
1018}; 994};
1019 995
@@ -1039,7 +1015,7 @@ static int __init sd_mod_init(void)
1039{ 1015{
1040 if (usb_register(&sd_driver) < 0) 1016 if (usb_register(&sd_driver) < 0)
1041 return -1; 1017 return -1;
1042 PDEBUG(D_PROBE, "v%s registered", version); 1018 PDEBUG(D_PROBE, "registered");
1043 return 0; 1019 return 0;
1044} 1020}
1045static void __exit sd_mod_exit(void) 1021static void __exit sd_mod_exit(void)
diff --git a/drivers/media/video/gspca/stk014.c b/drivers/media/video/gspca/stk014.c
index c78ee0d3e59b..16219cf6a6d5 100644
--- a/drivers/media/video/gspca/stk014.c
+++ b/drivers/media/video/gspca/stk014.c
@@ -23,9 +23,6 @@
23#include "gspca.h" 23#include "gspca.h"
24#include "jpeg.h" 24#include "jpeg.h"
25 25
26#define DRIVER_VERSION_NUMBER KERNEL_VERSION(2, 1, 7)
27static const char version[] = "2.1.7";
28
29MODULE_AUTHOR("Jean-Francois Moine <http://moinejf.free.fr>"); 26MODULE_AUTHOR("Jean-Francois Moine <http://moinejf.free.fr>");
30MODULE_DESCRIPTION("Syntek DV4000 (STK014) USB Camera Driver"); 27MODULE_DESCRIPTION("Syntek DV4000 (STK014) USB Camera Driver");
31MODULE_LICENSE("GPL"); 28MODULE_LICENSE("GPL");
@@ -299,7 +296,6 @@ static int sd_config(struct gspca_dev *gspca_dev,
299 struct sd *sd = (struct sd *) gspca_dev; 296 struct sd *sd = (struct sd *) gspca_dev;
300 struct cam *cam = &gspca_dev->cam; 297 struct cam *cam = &gspca_dev->cam;
301 298
302 cam->dev_name = (char *) id->driver_info;
303 cam->epaddr = 0x02; 299 cam->epaddr = 0x02;
304 gspca_dev->cam.cam_mode = vga_mode; 300 gspca_dev->cam.cam_mode = vga_mode;
305 gspca_dev->cam.nmodes = ARRAY_SIZE(vga_mode); 301 gspca_dev->cam.nmodes = ARRAY_SIZE(vga_mode);
@@ -549,9 +545,8 @@ static const struct sd_desc sd_desc = {
549}; 545};
550 546
551/* -- module initialisation -- */ 547/* -- module initialisation -- */
552#define DVNM(name) .driver_info = (kernel_ulong_t) name
553static const __devinitdata struct usb_device_id device_table[] = { 548static const __devinitdata struct usb_device_id device_table[] = {
554 {USB_DEVICE(0x05e1, 0x0893), DVNM("Syntek DV4000")}, 549 {USB_DEVICE(0x05e1, 0x0893)},
555 {} 550 {}
556}; 551};
557MODULE_DEVICE_TABLE(usb, device_table); 552MODULE_DEVICE_TABLE(usb, device_table);
@@ -576,7 +571,7 @@ static int __init sd_mod_init(void)
576{ 571{
577 if (usb_register(&sd_driver) < 0) 572 if (usb_register(&sd_driver) < 0)
578 return -1; 573 return -1;
579 info("v%s registered", version); 574 info("registered");
580 return 0; 575 return 0;
581} 576}
582static void __exit sd_mod_exit(void) 577static void __exit sd_mod_exit(void)
diff --git a/drivers/media/video/gspca/sunplus.c b/drivers/media/video/gspca/sunplus.c
index abd7bef9b3d1..54efa48bee01 100644
--- a/drivers/media/video/gspca/sunplus.c
+++ b/drivers/media/video/gspca/sunplus.c
@@ -24,9 +24,6 @@
24#include "gspca.h" 24#include "gspca.h"
25#include "jpeg.h" 25#include "jpeg.h"
26 26
27#define DRIVER_VERSION_NUMBER KERNEL_VERSION(2, 1, 8)
28static const char version[] = "2.1.8";
29
30MODULE_AUTHOR("Michel Xhaard <mxhaard@users.sourceforge.net>"); 27MODULE_AUTHOR("Michel Xhaard <mxhaard@users.sourceforge.net>");
31MODULE_DESCRIPTION("GSPCA/SPCA5xx USB Camera Driver"); 28MODULE_DESCRIPTION("GSPCA/SPCA5xx USB Camera Driver");
32MODULE_LICENSE("GPL"); 29MODULE_LICENSE("GPL");
@@ -804,229 +801,29 @@ static int sd_config(struct gspca_dev *gspca_dev,
804 struct sd *sd = (struct sd *) gspca_dev; 801 struct sd *sd = (struct sd *) gspca_dev;
805 struct usb_device *dev = gspca_dev->dev; 802 struct usb_device *dev = gspca_dev->dev;
806 struct cam *cam; 803 struct cam *cam;
807 __u16 vendor; 804
808 __u16 product; 805 cam = &gspca_dev->cam;
809 __u8 fw; 806 cam->epaddr = 0x01;
810 807
811 vendor = id->idVendor; 808 sd->bridge = id->driver_info >> 8;
812 product = id->idProduct; 809 sd->subtype = id->driver_info;
813 switch (vendor) { 810
814 case 0x041e: /* Creative cameras */ 811 if (sd->subtype == AiptekMiniPenCam13) {
815/* switch (product) { */
816/* case 0x400b: */
817/* case 0x4012: */
818/* case 0x4013: */
819/* sd->bridge = BRIDGE_SPCA504C; */
820/* break; */
821/* } */
822 break;
823 case 0x0458: /* Genius KYE cameras */
824/* switch (product) { */
825/* case 0x7006: */
826 sd->bridge = BRIDGE_SPCA504B;
827/* break; */
828/* } */
829 break;
830 case 0x0461: /* MicroInnovation */
831/* switch (product) { */
832/* case 0x0821: */
833 sd->bridge = BRIDGE_SPCA533;
834/* break; */
835/* } */
836 break;
837 case 0x046d: /* Logitech Labtec */
838 switch (product) {
839 case 0x0905:
840 sd->subtype = LogitechClickSmart820;
841 sd->bridge = BRIDGE_SPCA533;
842 break;
843 case 0x0960:
844 sd->subtype = LogitechClickSmart420;
845 sd->bridge = BRIDGE_SPCA504C;
846 break;
847 }
848 break;
849 case 0x0471: /* Philips */
850/* switch (product) { */
851/* case 0x0322: */
852 sd->bridge = BRIDGE_SPCA504B;
853/* break; */
854/* } */
855 break;
856 case 0x04a5: /* Benq */
857 switch (product) {
858 case 0x3003:
859 sd->bridge = BRIDGE_SPCA504B;
860 break;
861 case 0x3008:
862 case 0x300a:
863 sd->bridge = BRIDGE_SPCA533;
864 break;
865 }
866 break;
867 case 0x04f1: /* JVC */
868/* switch (product) { */
869/* case 0x1001: */
870 sd->bridge = BRIDGE_SPCA504B;
871/* break; */
872/* } */
873 break;
874 case 0x04fc: /* SunPlus */
875 switch (product) {
876 case 0x500c:
877 sd->bridge = BRIDGE_SPCA504B;
878 break;
879 case 0x504a:
880/* try to get the firmware as some cam answer 2.0.1.2.2 812/* try to get the firmware as some cam answer 2.0.1.2.2
881 * and should be a spca504b then overwrite that setting */ 813 * and should be a spca504b then overwrite that setting */
882 reg_r(dev, 0x20, 0, gspca_dev->usb_buf, 1); 814 reg_r(dev, 0x20, 0, gspca_dev->usb_buf, 1);
883 fw = gspca_dev->usb_buf[0]; 815 switch (gspca_dev->usb_buf[0]) {
884 if (fw == 1) { 816 case 1:
885 sd->subtype = AiptekMiniPenCam13; 817 break; /* (right bridge/subtype) */
886 sd->bridge = BRIDGE_SPCA504; 818 case 2:
887 } else if (fw == 2) {
888 sd->bridge = BRIDGE_SPCA504B;
889 } else
890 return -ENODEV;
891 break;
892 case 0x504b:
893 sd->bridge = BRIDGE_SPCA504B;
894 break;
895 case 0x5330:
896 sd->bridge = BRIDGE_SPCA533;
897 break;
898 case 0x5360:
899 sd->bridge = BRIDGE_SPCA536;
900 break;
901 case 0xffff:
902 sd->bridge = BRIDGE_SPCA504B;
903 break;
904 }
905 break;
906 case 0x052b: /* ?? Megapix */
907/* switch (product) { */
908/* case 0x1513: */
909 sd->subtype = MegapixV4;
910 sd->bridge = BRIDGE_SPCA533;
911/* break; */
912/* } */
913 break;
914 case 0x0546: /* Polaroid */
915 switch (product) {
916 case 0x3155:
917 sd->bridge = BRIDGE_SPCA533;
918 break;
919 case 0x3191:
920 case 0x3273:
921 sd->bridge = BRIDGE_SPCA504B;
922 break;
923 }
924 break;
925 case 0x055f: /* Mustek cameras */
926 switch (product) {
927 case 0xc211:
928 sd->bridge = BRIDGE_SPCA536;
929 break;
930 case 0xc230:
931 case 0xc232:
932 sd->bridge = BRIDGE_SPCA533;
933 break;
934 case 0xc360:
935 sd->bridge = BRIDGE_SPCA536;
936 break;
937 case 0xc420:
938 sd->bridge = BRIDGE_SPCA504;
939 break;
940 case 0xc430:
941 case 0xc440:
942 sd->bridge = BRIDGE_SPCA533;
943 break;
944 case 0xc520:
945 sd->bridge = BRIDGE_SPCA504;
946 break;
947 case 0xc530:
948 case 0xc540:
949 case 0xc630:
950 case 0xc650:
951 sd->bridge = BRIDGE_SPCA533;
952 break;
953 }
954 break;
955 case 0x05da: /* Digital Dream cameras */
956/* switch (product) { */
957/* case 0x1018: */
958 sd->bridge = BRIDGE_SPCA504B; 819 sd->bridge = BRIDGE_SPCA504B;
959/* break; */ 820 sd->subtype = 0;
960/* } */
961 break;
962 case 0x06d6: /* Trust */
963/* switch (product) { */
964/* case 0x0031: */
965 sd->bridge = BRIDGE_SPCA533; /* SPCA533A */
966/* break; */
967/* } */
968 break;
969 case 0x0733: /* Rebadged ViewQuest (Intel) and ViewQuest cameras */
970 switch (product) {
971 case 0x1311:
972 case 0x1314:
973 case 0x2211:
974 case 0x2221:
975 sd->bridge = BRIDGE_SPCA533;
976 break;
977 case 0x3261:
978 case 0x3281:
979 sd->bridge = BRIDGE_SPCA536;
980 break;
981 }
982 break;
983 case 0x08ca: /* Aiptek */
984 switch (product) {
985 case 0x0104:
986 case 0x0106:
987 sd->bridge = BRIDGE_SPCA533;
988 break;
989 case 0x2008:
990 sd->bridge = BRIDGE_SPCA504B;
991 break;
992 case 0x2010:
993 sd->bridge = BRIDGE_SPCA533;
994 break;
995 case 0x2016:
996 case 0x2018:
997 sd->bridge = BRIDGE_SPCA504B;
998 break;
999 case 0x2020:
1000 case 0x2022:
1001 sd->bridge = BRIDGE_SPCA533;
1002 break;
1003 case 0x2024:
1004 sd->bridge = BRIDGE_SPCA536;
1005 break;
1006 case 0x2028:
1007 sd->bridge = BRIDGE_SPCA533;
1008 break;
1009 case 0x2040:
1010 case 0x2042:
1011 case 0x2050:
1012 case 0x2060:
1013 sd->bridge = BRIDGE_SPCA536;
1014 break; 821 break;
822 default:
823 return -ENODEV;
1015 } 824 }
1016 break;
1017 case 0x0d64: /* SunPlus */
1018/* switch (product) { */
1019/* case 0x0303: */
1020 sd->bridge = BRIDGE_SPCA536;
1021/* break; */
1022/* } */
1023 break;
1024 } 825 }
1025 826
1026 cam = &gspca_dev->cam;
1027 cam->dev_name = (char *) id->driver_info;
1028 cam->epaddr = 0x01;
1029
1030 switch (sd->bridge) { 827 switch (sd->bridge) {
1031 default: 828 default:
1032/* case BRIDGE_SPCA504B: */ 829/* case BRIDGE_SPCA504B: */
@@ -1581,65 +1378,67 @@ static const struct sd_desc sd_desc = {
1581}; 1378};
1582 1379
1583/* -- module initialisation -- */ 1380/* -- module initialisation -- */
1584#define DVNM(name) .driver_info = (kernel_ulong_t) name 1381#define BS(bridge, subtype) \
1382 .driver_info = (BRIDGE_ ## bridge << 8) \
1383 | (subtype)
1585static const __devinitdata struct usb_device_id device_table[] = { 1384static const __devinitdata struct usb_device_id device_table[] = {
1586 {USB_DEVICE(0x041e, 0x400b), DVNM("Creative PC-CAM 600")}, 1385 {USB_DEVICE(0x041e, 0x400b), BS(SPCA504C, 0)},
1587 {USB_DEVICE(0x041e, 0x4012), DVNM("PC-Cam350")}, 1386 {USB_DEVICE(0x041e, 0x4012), BS(SPCA504C, 0)},
1588 {USB_DEVICE(0x041e, 0x4013), DVNM("Creative Pccam750")}, 1387 {USB_DEVICE(0x041e, 0x4013), BS(SPCA504C, 0)},
1589 {USB_DEVICE(0x0458, 0x7006), DVNM("Genius Dsc 1.3 Smart")}, 1388 {USB_DEVICE(0x0458, 0x7006), BS(SPCA504B, 0)},
1590 {USB_DEVICE(0x0461, 0x0821), DVNM("Fujifilm MV-1")}, 1389 {USB_DEVICE(0x0461, 0x0821), BS(SPCA533, 0)},
1591 {USB_DEVICE(0x046d, 0x0905), DVNM("Logitech ClickSmart 820")}, 1390 {USB_DEVICE(0x046d, 0x0905), BS(SPCA533, LogitechClickSmart820)},
1592 {USB_DEVICE(0x046d, 0x0960), DVNM("Logitech ClickSmart 420")}, 1391 {USB_DEVICE(0x046d, 0x0960), BS(SPCA504C, LogitechClickSmart420)},
1593 {USB_DEVICE(0x0471, 0x0322), DVNM("Philips DMVC1300K")}, 1392 {USB_DEVICE(0x0471, 0x0322), BS(SPCA504B, 0)},
1594 {USB_DEVICE(0x04a5, 0x3003), DVNM("Benq DC 1300")}, 1393 {USB_DEVICE(0x04a5, 0x3003), BS(SPCA504B, 0)},
1595 {USB_DEVICE(0x04a5, 0x3008), DVNM("Benq DC 1500")}, 1394 {USB_DEVICE(0x04a5, 0x3008), BS(SPCA533, 0)},
1596 {USB_DEVICE(0x04a5, 0x300a), DVNM("Benq DC3410")}, 1395 {USB_DEVICE(0x04a5, 0x300a), BS(SPCA533, 0)},
1597 {USB_DEVICE(0x04f1, 0x1001), DVNM("JVC GC A50")}, 1396 {USB_DEVICE(0x04f1, 0x1001), BS(SPCA504B, 0)},
1598 {USB_DEVICE(0x04fc, 0x500c), DVNM("Sunplus CA500C")}, 1397 {USB_DEVICE(0x04fc, 0x500c), BS(SPCA504B, 0)},
1599 {USB_DEVICE(0x04fc, 0x504a), DVNM("Aiptek Mini PenCam 1.3")}, 1398 {USB_DEVICE(0x04fc, 0x504a), BS(SPCA504, AiptekMiniPenCam13)},
1600 {USB_DEVICE(0x04fc, 0x504b), DVNM("Maxell MaxPocket LE 1.3")}, 1399 {USB_DEVICE(0x04fc, 0x504b), BS(SPCA504B, 0)},
1601 {USB_DEVICE(0x04fc, 0x5330), DVNM("Digitrex 2110")}, 1400 {USB_DEVICE(0x04fc, 0x5330), BS(SPCA533, 0)},
1602 {USB_DEVICE(0x04fc, 0x5360), DVNM("Sunplus Generic")}, 1401 {USB_DEVICE(0x04fc, 0x5360), BS(SPCA536, 0)},
1603 {USB_DEVICE(0x04fc, 0xffff), DVNM("Pure DigitalDakota")}, 1402 {USB_DEVICE(0x04fc, 0xffff), BS(SPCA504B, 0)},
1604 {USB_DEVICE(0x052b, 0x1513), DVNM("Megapix V4")}, 1403 {USB_DEVICE(0x052b, 0x1513), BS(SPCA533, MegapixV4)},
1605 {USB_DEVICE(0x0546, 0x3155), DVNM("Polaroid PDC3070")}, 1404 {USB_DEVICE(0x0546, 0x3155), BS(SPCA533, 0)},
1606 {USB_DEVICE(0x0546, 0x3191), DVNM("Polaroid Ion 80")}, 1405 {USB_DEVICE(0x0546, 0x3191), BS(SPCA504B, 0)},
1607 {USB_DEVICE(0x0546, 0x3273), DVNM("Polaroid PDC2030")}, 1406 {USB_DEVICE(0x0546, 0x3273), BS(SPCA504B, 0)},
1608 {USB_DEVICE(0x055f, 0xc211), DVNM("Kowa Bs888e Microcamera")}, 1407 {USB_DEVICE(0x055f, 0xc211), BS(SPCA536, 0)},
1609 {USB_DEVICE(0x055f, 0xc230), DVNM("Mustek Digicam 330K")}, 1408 {USB_DEVICE(0x055f, 0xc230), BS(SPCA533, 0)},
1610 {USB_DEVICE(0x055f, 0xc232), DVNM("Mustek MDC3500")}, 1409 {USB_DEVICE(0x055f, 0xc232), BS(SPCA533, 0)},
1611 {USB_DEVICE(0x055f, 0xc360), DVNM("Mustek DV4000 Mpeg4 ")}, 1410 {USB_DEVICE(0x055f, 0xc360), BS(SPCA536, 0)},
1612 {USB_DEVICE(0x055f, 0xc420), DVNM("Mustek gSmart Mini 2")}, 1411 {USB_DEVICE(0x055f, 0xc420), BS(SPCA504, 0)},
1613 {USB_DEVICE(0x055f, 0xc430), DVNM("Mustek Gsmart LCD 2")}, 1412 {USB_DEVICE(0x055f, 0xc430), BS(SPCA533, 0)},
1614 {USB_DEVICE(0x055f, 0xc440), DVNM("Mustek DV 3000")}, 1413 {USB_DEVICE(0x055f, 0xc440), BS(SPCA533, 0)},
1615 {USB_DEVICE(0x055f, 0xc520), DVNM("Mustek gSmart Mini 3")}, 1414 {USB_DEVICE(0x055f, 0xc520), BS(SPCA504, 0)},
1616 {USB_DEVICE(0x055f, 0xc530), DVNM("Mustek Gsmart LCD 3")}, 1415 {USB_DEVICE(0x055f, 0xc530), BS(SPCA533, 0)},
1617 {USB_DEVICE(0x055f, 0xc540), DVNM("Gsmart D30")}, 1416 {USB_DEVICE(0x055f, 0xc540), BS(SPCA533, 0)},
1618 {USB_DEVICE(0x055f, 0xc630), DVNM("Mustek MDC4000")}, 1417 {USB_DEVICE(0x055f, 0xc630), BS(SPCA533, 0)},
1619 {USB_DEVICE(0x055f, 0xc650), DVNM("Mustek MDC5500Z")}, 1418 {USB_DEVICE(0x055f, 0xc650), BS(SPCA533, 0)},
1620 {USB_DEVICE(0x05da, 0x1018), DVNM("Digital Dream Enigma 1.3")}, 1419 {USB_DEVICE(0x05da, 0x1018), BS(SPCA504B, 0)},
1621 {USB_DEVICE(0x06d6, 0x0031), DVNM("Trust 610 LCD PowerC@m Zoom")}, 1420 {USB_DEVICE(0x06d6, 0x0031), BS(SPCA533, 0)},
1622 {USB_DEVICE(0x0733, 0x1311), DVNM("Digital Dream Epsilon 1.3")}, 1421 {USB_DEVICE(0x0733, 0x1311), BS(SPCA533, 0)},
1623 {USB_DEVICE(0x0733, 0x1314), DVNM("Mercury 2.1MEG Deluxe Classic Cam")}, 1422 {USB_DEVICE(0x0733, 0x1314), BS(SPCA533, 0)},
1624 {USB_DEVICE(0x0733, 0x2211), DVNM("Jenoptik jdc 21 LCD")}, 1423 {USB_DEVICE(0x0733, 0x2211), BS(SPCA533, 0)},
1625 {USB_DEVICE(0x0733, 0x2221), DVNM("Mercury Digital Pro 3.1p")}, 1424 {USB_DEVICE(0x0733, 0x2221), BS(SPCA533, 0)},
1626 {USB_DEVICE(0x0733, 0x3261), DVNM("Concord 3045 spca536a")}, 1425 {USB_DEVICE(0x0733, 0x3261), BS(SPCA536, 0)},
1627 {USB_DEVICE(0x0733, 0x3281), DVNM("Cyberpix S550V")}, 1426 {USB_DEVICE(0x0733, 0x3281), BS(SPCA536, 0)},
1628 {USB_DEVICE(0x08ca, 0x0104), DVNM("Aiptek PocketDVII 1.3")}, 1427 {USB_DEVICE(0x08ca, 0x0104), BS(SPCA533, 0)},
1629 {USB_DEVICE(0x08ca, 0x0106), DVNM("Aiptek Pocket DV3100+")}, 1428 {USB_DEVICE(0x08ca, 0x0106), BS(SPCA533, 0)},
1630 {USB_DEVICE(0x08ca, 0x2008), DVNM("Aiptek Mini PenCam 2 M")}, 1429 {USB_DEVICE(0x08ca, 0x2008), BS(SPCA504B, 0)},
1631 {USB_DEVICE(0x08ca, 0x2010), DVNM("Aiptek PocketCam 3M")}, 1430 {USB_DEVICE(0x08ca, 0x2010), BS(SPCA533, 0)},
1632 {USB_DEVICE(0x08ca, 0x2016), DVNM("Aiptek PocketCam 2 Mega")}, 1431 {USB_DEVICE(0x08ca, 0x2016), BS(SPCA504B, 0)},
1633 {USB_DEVICE(0x08ca, 0x2018), DVNM("Aiptek Pencam SD 2M")}, 1432 {USB_DEVICE(0x08ca, 0x2018), BS(SPCA504B, 0)},
1634 {USB_DEVICE(0x08ca, 0x2020), DVNM("Aiptek Slim 3000F")}, 1433 {USB_DEVICE(0x08ca, 0x2020), BS(SPCA533, 0)},
1635 {USB_DEVICE(0x08ca, 0x2022), DVNM("Aiptek Slim 3200")}, 1434 {USB_DEVICE(0x08ca, 0x2022), BS(SPCA533, 0)},
1636 {USB_DEVICE(0x08ca, 0x2024), DVNM("Aiptek DV3500 Mpeg4 ")}, 1435 {USB_DEVICE(0x08ca, 0x2024), BS(SPCA536, 0)},
1637 {USB_DEVICE(0x08ca, 0x2028), DVNM("Aiptek PocketCam4M")}, 1436 {USB_DEVICE(0x08ca, 0x2028), BS(SPCA533, 0)},
1638 {USB_DEVICE(0x08ca, 0x2040), DVNM("Aiptek PocketDV4100M")}, 1437 {USB_DEVICE(0x08ca, 0x2040), BS(SPCA536, 0)},
1639 {USB_DEVICE(0x08ca, 0x2042), DVNM("Aiptek PocketDV5100")}, 1438 {USB_DEVICE(0x08ca, 0x2042), BS(SPCA536, 0)},
1640 {USB_DEVICE(0x08ca, 0x2050), DVNM("Medion MD 41437")}, 1439 {USB_DEVICE(0x08ca, 0x2050), BS(SPCA536, 0)},
1641 {USB_DEVICE(0x08ca, 0x2060), DVNM("Aiptek PocketDV5300")}, 1440 {USB_DEVICE(0x08ca, 0x2060), BS(SPCA536, 0)},
1642 {USB_DEVICE(0x0d64, 0x0303), DVNM("Sunplus FashionCam DXG")}, 1441 {USB_DEVICE(0x0d64, 0x0303), BS(SPCA536, 0)},
1643 {} 1442 {}
1644}; 1443};
1645MODULE_DEVICE_TABLE(usb, device_table); 1444MODULE_DEVICE_TABLE(usb, device_table);
@@ -1664,7 +1463,7 @@ static int __init sd_mod_init(void)
1664{ 1463{
1665 if (usb_register(&sd_driver) < 0) 1464 if (usb_register(&sd_driver) < 0)
1666 return -1; 1465 return -1;
1667 PDEBUG(D_PROBE, "v%s registered", version); 1466 PDEBUG(D_PROBE, "registered");
1668 return 0; 1467 return 0;
1669} 1468}
1670static void __exit sd_mod_exit(void) 1469static void __exit sd_mod_exit(void)
diff --git a/drivers/media/video/gspca/t613.c b/drivers/media/video/gspca/t613.c
index 00f47e463a05..91b555c34c68 100644
--- a/drivers/media/video/gspca/t613.c
+++ b/drivers/media/video/gspca/t613.c
@@ -1,12 +1,4 @@
1/* 1/*
2 *Notes: * t613 + tas5130A
3 * * Focus to light do not balance well as in win.
4 * Quality in win is not good, but its kinda better.
5 * * Fix some "extraneous bytes", most of apps will show the image anyway
6 * * Gamma table, is there, but its really doing something?
7 * * 7~8 Fps, its ok, max on win its 10.
8 * Costantino Leandro
9 *
10 * V4L2 by Jean-Francois Moine <http://moinejf.free.fr> 2 * V4L2 by Jean-Francois Moine <http://moinejf.free.fr>
11 * 3 *
12 * This program is free software; you can redistribute it and/or modify 4 * This program is free software; you can redistribute it and/or modify
@@ -22,16 +14,22 @@
22 * You should have received a copy of the GNU General Public License 14 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software 15 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 *
18 *Notes: * t613 + tas5130A
19 * * Focus to light do not balance well as in win.
20 * Quality in win is not good, but its kinda better.
21 * * Fix some "extraneous bytes", most of apps will show the image anyway
22 * * Gamma table, is there, but its really doing something?
23 * * 7~8 Fps, its ok, max on win its 10.
24 * Costantino Leandro
25 */ 25 */
26 26
27#define MODULE_NAME "t613" 27#define MODULE_NAME "t613"
28
28#include "gspca.h" 29#include "gspca.h"
29#define DRIVER_VERSION_NUMBER KERNEL_VERSION(2, 1, 7)
30static const char version[] = "2.1.7";
31 30
32#define MAX_GAMMA 0x10 /* 0 to 15 */ 31#define MAX_GAMMA 0x10 /* 0 to 15 */
33 32
34/* From LUVCVIEW */
35#define V4L2_CID_EFFECTS (V4L2_CID_PRIVATE_BASE + 3) 33#define V4L2_CID_EFFECTS (V4L2_CID_PRIVATE_BASE + 3)
36 34
37MODULE_AUTHOR("Leandro Costantino <le_costantino@pixartargentina.com.ar>"); 35MODULE_AUTHOR("Leandro Costantino <le_costantino@pixartargentina.com.ar>");
@@ -424,7 +422,6 @@ static int sd_config(struct gspca_dev *gspca_dev,
424 struct cam *cam; 422 struct cam *cam;
425 423
426 cam = &gspca_dev->cam; 424 cam = &gspca_dev->cam;
427 cam->dev_name = (char *) id->driver_info;
428 cam->epaddr = 0x01; 425 cam->epaddr = 0x01;
429 426
430 cam->cam_mode = vga_mode_t16; 427 cam->cam_mode = vga_mode_t16;
@@ -998,9 +995,8 @@ static const struct sd_desc sd_desc = {
998}; 995};
999 996
1000/* -- module initialisation -- */ 997/* -- module initialisation -- */
1001#define DVNM(name) .driver_info = (kernel_ulong_t) name
1002static const __devinitdata struct usb_device_id device_table[] = { 998static const __devinitdata struct usb_device_id device_table[] = {
1003 {USB_DEVICE(0x17a1, 0x0128), DVNM("XPX Webcam")}, 999 {USB_DEVICE(0x17a1, 0x0128)},
1004 {} 1000 {}
1005}; 1001};
1006MODULE_DEVICE_TABLE(usb, device_table); 1002MODULE_DEVICE_TABLE(usb, device_table);
@@ -1025,7 +1021,7 @@ static int __init sd_mod_init(void)
1025{ 1021{
1026 if (usb_register(&sd_driver) < 0) 1022 if (usb_register(&sd_driver) < 0)
1027 return -1; 1023 return -1;
1028 PDEBUG(D_PROBE, "v%s registered", version); 1024 PDEBUG(D_PROBE, "registered");
1029 return 0; 1025 return 0;
1030} 1026}
1031static void __exit sd_mod_exit(void) 1027static void __exit sd_mod_exit(void)
diff --git a/drivers/media/video/gspca/tv8532.c b/drivers/media/video/gspca/tv8532.c
index 0b793899095f..1ff8ba2f7fe5 100644
--- a/drivers/media/video/gspca/tv8532.c
+++ b/drivers/media/video/gspca/tv8532.c
@@ -22,9 +22,6 @@
22 22
23#include "gspca.h" 23#include "gspca.h"
24 24
25#define DRIVER_VERSION_NUMBER KERNEL_VERSION(2, 1, 7)
26static const char version[] = "2.1.7";
27
28MODULE_AUTHOR("Michel Xhaard <mxhaard@users.sourceforge.net>"); 25MODULE_AUTHOR("Michel Xhaard <mxhaard@users.sourceforge.net>");
29MODULE_DESCRIPTION("TV8532 USB Camera Driver"); 26MODULE_DESCRIPTION("TV8532 USB Camera Driver");
30MODULE_LICENSE("GPL"); 27MODULE_LICENSE("GPL");
@@ -249,7 +246,6 @@ static int sd_config(struct gspca_dev *gspca_dev,
249 tv_8532WriteEEprom(gspca_dev); 246 tv_8532WriteEEprom(gspca_dev);
250 247
251 cam = &gspca_dev->cam; 248 cam = &gspca_dev->cam;
252 cam->dev_name = (char *) id->driver_info;
253 cam->epaddr = 1; 249 cam->epaddr = 1;
254 cam->cam_mode = sif_mode; 250 cam->cam_mode = sif_mode;
255 cam->nmodes = sizeof sif_mode / sizeof sif_mode[0]; 251 cam->nmodes = sizeof sif_mode / sizeof sif_mode[0];
@@ -624,13 +620,12 @@ static const struct sd_desc sd_desc = {
624}; 620};
625 621
626/* -- module initialisation -- */ 622/* -- module initialisation -- */
627#define DVNM(name) .driver_info = (kernel_ulong_t) name
628static const __devinitdata struct usb_device_id device_table[] = { 623static const __devinitdata struct usb_device_id device_table[] = {
629 {USB_DEVICE(0x046d, 0x0920), DVNM("QC Express")}, 624 {USB_DEVICE(0x046d, 0x0920)},
630 {USB_DEVICE(0x046d, 0x0921), DVNM("Labtec Webcam")}, 625 {USB_DEVICE(0x046d, 0x0921)},
631 {USB_DEVICE(0x0545, 0x808b), DVNM("Veo Stingray")}, 626 {USB_DEVICE(0x0545, 0x808b)},
632 {USB_DEVICE(0x0545, 0x8333), DVNM("Veo Stingray")}, 627 {USB_DEVICE(0x0545, 0x8333)},
633 {USB_DEVICE(0x0923, 0x010f), DVNM("ICM532 cams")}, 628 {USB_DEVICE(0x0923, 0x010f)},
634 {} 629 {}
635}; 630};
636 631
@@ -656,7 +651,7 @@ static int __init sd_mod_init(void)
656{ 651{
657 if (usb_register(&sd_driver) < 0) 652 if (usb_register(&sd_driver) < 0)
658 return -1; 653 return -1;
659 PDEBUG(D_PROBE, "v%s registered", version); 654 PDEBUG(D_PROBE, "registered");
660 return 0; 655 return 0;
661} 656}
662 657
diff --git a/drivers/media/video/gspca/vc032x.c b/drivers/media/video/gspca/vc032x.c
index fcf2c9e32573..a4221753e1bf 100644
--- a/drivers/media/video/gspca/vc032x.c
+++ b/drivers/media/video/gspca/vc032x.c
@@ -24,9 +24,6 @@
24 24
25#include "gspca.h" 25#include "gspca.h"
26 26
27#define DRIVER_VERSION_NUMBER KERNEL_VERSION(2, 1, 7)
28static const char version[] = "2.1.7";
29
30MODULE_AUTHOR("Michel Xhaard <mxhaard@users.sourceforge.net>"); 27MODULE_AUTHOR("Michel Xhaard <mxhaard@users.sourceforge.net>");
31MODULE_DESCRIPTION("GSPCA/VC032X USB Camera Driver"); 28MODULE_DESCRIPTION("GSPCA/VC032X USB Camera Driver");
32MODULE_LICENSE("GPL"); 29MODULE_LICENSE("GPL");
@@ -1419,30 +1416,10 @@ static int sd_config(struct gspca_dev *gspca_dev,
1419 struct usb_device *dev = gspca_dev->dev; 1416 struct usb_device *dev = gspca_dev->dev;
1420 struct cam *cam; 1417 struct cam *cam;
1421 int sensor; 1418 int sensor;
1422 __u16 product;
1423
1424 product = id->idProduct;
1425 sd->bridge = BRIDGE_VC0321;
1426 switch (id->idVendor) {
1427 case 0x0ac8: /* Vimicro z-star */
1428 switch (product) {
1429 case 0x0323:
1430 sd->bridge = BRIDGE_VC0323;
1431 break;
1432 }
1433 break;
1434 case 0x17ef: /* Lenovo */
1435/* switch (product) { */
1436/* case 0x4802: * Lenovo MI1310_SOC */
1437 sd->bridge = BRIDGE_VC0323;
1438/* break; */
1439/* } */
1440 break;
1441 }
1442 1419
1443 cam = &gspca_dev->cam; 1420 cam = &gspca_dev->cam;
1444 cam->dev_name = (char *) id->driver_info;
1445 cam->epaddr = 0x02; 1421 cam->epaddr = 0x02;
1422 sd->bridge = id->driver_info;
1446 if (sd->bridge == BRIDGE_VC0321) { 1423 if (sd->bridge == BRIDGE_VC0321) {
1447 cam->cam_mode = vc0321_mode; 1424 cam->cam_mode = vc0321_mode;
1448 cam->nmodes = ARRAY_SIZE(vc0321_mode); 1425 cam->nmodes = ARRAY_SIZE(vc0321_mode);
@@ -1771,16 +1748,15 @@ static const struct sd_desc sd_desc = {
1771}; 1748};
1772 1749
1773/* -- module initialisation -- */ 1750/* -- module initialisation -- */
1774#define DVNM(name) .driver_info = (kernel_ulong_t) name
1775static const __devinitdata struct usb_device_id device_table[] = { 1751static const __devinitdata struct usb_device_id device_table[] = {
1776 {USB_DEVICE(0x046d, 0x0892), DVNM("Logitech Orbicam")}, 1752 {USB_DEVICE(0x046d, 0x0892), .driver_info = BRIDGE_VC0321},
1777 {USB_DEVICE(0x046d, 0x0896), DVNM("Logitech Orbicam")}, 1753 {USB_DEVICE(0x046d, 0x0896), .driver_info = BRIDGE_VC0321},
1778 {USB_DEVICE(0x0ac8, 0x0321), DVNM("Vimicro generic vc0321")}, 1754 {USB_DEVICE(0x0ac8, 0x0321), .driver_info = BRIDGE_VC0321},
1779 {USB_DEVICE(0x0ac8, 0x0323), DVNM("Vimicro Vc0323")}, 1755 {USB_DEVICE(0x0ac8, 0x0323), .driver_info = BRIDGE_VC0323},
1780 {USB_DEVICE(0x0ac8, 0x0328), DVNM("A4Tech PK-130MG")}, 1756 {USB_DEVICE(0x0ac8, 0x0328), .driver_info = BRIDGE_VC0321},
1781 {USB_DEVICE(0x0ac8, 0xc001), DVNM("Sony embedded vimicro")}, 1757 {USB_DEVICE(0x0ac8, 0xc001), .driver_info = BRIDGE_VC0321},
1782 {USB_DEVICE(0x0ac8, 0xc002), DVNM("Sony embedded vimicro")}, 1758 {USB_DEVICE(0x0ac8, 0xc002), .driver_info = BRIDGE_VC0321},
1783 {USB_DEVICE(0x17ef, 0x4802), DVNM("Lenovo Vc0323+MI1310_SOC")}, 1759 {USB_DEVICE(0x17ef, 0x4802), .driver_info = BRIDGE_VC0323},
1784 {} 1760 {}
1785}; 1761};
1786MODULE_DEVICE_TABLE(usb, device_table); 1762MODULE_DEVICE_TABLE(usb, device_table);
@@ -1805,7 +1781,7 @@ static int __init sd_mod_init(void)
1805{ 1781{
1806 if (usb_register(&sd_driver) < 0) 1782 if (usb_register(&sd_driver) < 0)
1807 return -1; 1783 return -1;
1808 PDEBUG(D_PROBE, "v%s registered", version); 1784 PDEBUG(D_PROBE, "registered");
1809 return 0; 1785 return 0;
1810} 1786}
1811static void __exit sd_mod_exit(void) 1787static void __exit sd_mod_exit(void)
diff --git a/drivers/media/video/gspca/zc3xx.c b/drivers/media/video/gspca/zc3xx.c
index b761b11c5c6a..22a994ccb1d5 100644
--- a/drivers/media/video/gspca/zc3xx.c
+++ b/drivers/media/video/gspca/zc3xx.c
@@ -24,9 +24,6 @@
24 24
25#include "gspca.h" 25#include "gspca.h"
26 26
27#define DRIVER_VERSION_NUMBER KERNEL_VERSION(2, 1, 7)
28static const char version[] = "2.1.7";
29
30MODULE_AUTHOR("Michel Xhaard <mxhaard@users.sourceforge.net>, " 27MODULE_AUTHOR("Michel Xhaard <mxhaard@users.sourceforge.net>, "
31 "Serge A. Suchkov <Serge.A.S@tochka.ru>"); 28 "Serge A. Suchkov <Serge.A.S@tochka.ru>");
32MODULE_DESCRIPTION("GSPCA ZC03xx/VC3xx USB Camera Driver"); 29MODULE_DESCRIPTION("GSPCA ZC03xx/VC3xx USB Camera Driver");
@@ -49,7 +46,7 @@ struct sd {
49 __u8 sharpness; 46 __u8 sharpness;
50 47
51 char qindex; 48 char qindex;
52 char sensor; /* Type of image sensor chip */ 49 signed char sensor; /* Type of image sensor chip */
53/* !! values used in different tables */ 50/* !! values used in different tables */
54#define SENSOR_CS2102 0 51#define SENSOR_CS2102 0
55#define SENSOR_CS2102K 1 52#define SENSOR_CS2102K 1
@@ -2205,10 +2202,10 @@ static const struct usb_action hdcs2020xb_InitialScale[] = {
2205}; 2202};
2206static const struct usb_action hdcs2020b_50HZ[] = { 2203static const struct usb_action hdcs2020b_50HZ[] = {
2207 {0xa0, 0x00, ZC3XX_R019_AUTOADJUSTFPS}, /* 00,19,00,cc */ 2204 {0xa0, 0x00, ZC3XX_R019_AUTOADJUSTFPS}, /* 00,19,00,cc */
2208 {0xaa, 0x13, 0x0018}, /* 00,13,18,aa */ 2205 {0xaa, 0x13, 0x0018}, /* 00,13,18,aa */
2209 {0xaa, 0x14, 0x0001}, /* 00,14,01,aa */ 2206 {0xaa, 0x14, 0x0001}, /* 00,14,01,aa */
2210 {0xaa, 0x0e, 0x0005}, /* 00,0e,05,aa */ 2207 {0xaa, 0x0e, 0x0005}, /* 00,0e,05,aa */
2211 {0xaa, 0x19, 0x001f}, /* 00,19,1f,aa */ 2208 {0xaa, 0x19, 0x001f}, /* 00,19,1f,aa */
2212 {0xa0, 0x00, ZC3XX_R190_EXPOSURELIMITHIGH}, /* 01,90,00,cc */ 2209 {0xa0, 0x00, ZC3XX_R190_EXPOSURELIMITHIGH}, /* 01,90,00,cc */
2213 {0xa0, 0x02, ZC3XX_R191_EXPOSURELIMITMID}, /* 01,91,02,cc */ 2210 {0xa0, 0x02, ZC3XX_R191_EXPOSURELIMITMID}, /* 01,91,02,cc */
2214 {0xa0, 0x76, ZC3XX_R192_EXPOSURELIMITLOW}, /* 01,92,76,cc */ 2211 {0xa0, 0x76, ZC3XX_R192_EXPOSURELIMITLOW}, /* 01,92,76,cc */
@@ -2226,10 +2223,10 @@ static const struct usb_action hdcs2020b_50HZ[] = {
2226}; 2223};
2227static const struct usb_action hdcs2020b_60HZ[] = { 2224static const struct usb_action hdcs2020b_60HZ[] = {
2228 {0xa0, 0x00, ZC3XX_R019_AUTOADJUSTFPS}, /* 00,19,00,cc */ 2225 {0xa0, 0x00, ZC3XX_R019_AUTOADJUSTFPS}, /* 00,19,00,cc */
2229 {0xaa, 0x13, 0x0031}, /* 00,13,31,aa */ 2226 {0xaa, 0x13, 0x0031}, /* 00,13,31,aa */
2230 {0xaa, 0x14, 0x0001}, /* 00,14,01,aa */ 2227 {0xaa, 0x14, 0x0001}, /* 00,14,01,aa */
2231 {0xaa, 0x0e, 0x0004}, /* 00,0e,04,aa */ 2228 {0xaa, 0x0e, 0x0004}, /* 00,0e,04,aa */
2232 {0xaa, 0x19, 0x00cd}, /* 00,19,cd,aa */ 2229 {0xaa, 0x19, 0x00cd}, /* 00,19,cd,aa */
2233 {0xa0, 0x00, ZC3XX_R190_EXPOSURELIMITHIGH}, /* 01,90,00,cc */ 2230 {0xa0, 0x00, ZC3XX_R190_EXPOSURELIMITHIGH}, /* 01,90,00,cc */
2234 {0xa0, 0x02, ZC3XX_R191_EXPOSURELIMITMID}, /* 01,91,02,cc */ 2231 {0xa0, 0x02, ZC3XX_R191_EXPOSURELIMITMID}, /* 01,91,02,cc */
2235 {0xa0, 0x62, ZC3XX_R192_EXPOSURELIMITLOW}, /* 01,92,62,cc */ 2232 {0xa0, 0x62, ZC3XX_R192_EXPOSURELIMITLOW}, /* 01,92,62,cc */
@@ -2247,10 +2244,10 @@ static const struct usb_action hdcs2020b_60HZ[] = {
2247}; 2244};
2248static const struct usb_action hdcs2020b_NoFliker[] = { 2245static const struct usb_action hdcs2020b_NoFliker[] = {
2249 {0xa0, 0x00, ZC3XX_R019_AUTOADJUSTFPS}, /* 00,19,00,cc */ 2246 {0xa0, 0x00, ZC3XX_R019_AUTOADJUSTFPS}, /* 00,19,00,cc */
2250 {0xaa, 0x13, 0x0010}, /* 00,13,10,aa */ 2247 {0xaa, 0x13, 0x0010}, /* 00,13,10,aa */
2251 {0xaa, 0x14, 0x0001}, /* 00,14,01,aa */ 2248 {0xaa, 0x14, 0x0001}, /* 00,14,01,aa */
2252 {0xaa, 0x0e, 0x0004}, /* 00,0e,04,aa */ 2249 {0xaa, 0x0e, 0x0004}, /* 00,0e,04,aa */
2253 {0xaa, 0x19, 0x0000}, /* 00,19,00,aa */ 2250 {0xaa, 0x19, 0x0000}, /* 00,19,00,aa */
2254 {0xa0, 0x00, ZC3XX_R190_EXPOSURELIMITHIGH}, /* 01,90,00,cc */ 2251 {0xa0, 0x00, ZC3XX_R190_EXPOSURELIMITHIGH}, /* 01,90,00,cc */
2255 {0xa0, 0x02, ZC3XX_R191_EXPOSURELIMITMID}, /* 01,91,02,cc */ 2252 {0xa0, 0x02, ZC3XX_R191_EXPOSURELIMITMID}, /* 01,91,02,cc */
2256 {0xa0, 0x70, ZC3XX_R192_EXPOSURELIMITLOW}, /* 01,92,70,cc */ 2253 {0xa0, 0x70, ZC3XX_R192_EXPOSURELIMITLOW}, /* 01,92,70,cc */
@@ -4102,27 +4099,27 @@ static const struct usb_action pas106b_Initial_com[] = {
4102 4099
4103static const struct usb_action pas106b_Initial[] = { /* 176x144 */ 4100static const struct usb_action pas106b_Initial[] = { /* 176x144 */
4104/* JPEG control */ 4101/* JPEG control */
4105 {0xa0, 0x03, ZC3XX_R008_CLOCKSETTING}, /* ClockSetting */ 4102 {0xa0, 0x03, ZC3XX_R008_CLOCKSETTING},
4106/* Sream and Sensor specific */ 4103/* Sream and Sensor specific */
4107 {0xa0, 0x0f, ZC3XX_R010_CMOSSENSORSELECT}, /* CMOSSensorSelect */ 4104 {0xa0, 0x0f, ZC3XX_R010_CMOSSENSORSELECT},
4108/* Picture size */ 4105/* Picture size */
4109 {0xa0, 0x00, ZC3XX_R003_FRAMEWIDTHHIGH}, /* FrameWidthHigh 00 */ 4106 {0xa0, 0x00, ZC3XX_R003_FRAMEWIDTHHIGH},
4110 {0xa0, 0xb0, ZC3XX_R004_FRAMEWIDTHLOW}, /* FrameWidthLow B0 */ 4107 {0xa0, 0xb0, ZC3XX_R004_FRAMEWIDTHLOW},
4111 {0xa0, 0x00, ZC3XX_R005_FRAMEHEIGHTHIGH}, /* FrameHeightHigh 00 */ 4108 {0xa0, 0x00, ZC3XX_R005_FRAMEHEIGHTHIGH},
4112 {0xa0, 0x90, ZC3XX_R006_FRAMEHEIGHTLOW}, /* FrameHightLow 90 */ 4109 {0xa0, 0x90, ZC3XX_R006_FRAMEHEIGHTLOW},
4113/* System */ 4110/* System */
4114 {0xa0, 0x01, ZC3XX_R001_SYSTEMOPERATING}, /* SystemOperating */ 4111 {0xa0, 0x01, ZC3XX_R001_SYSTEMOPERATING},
4115/* Sream and Sensor specific */ 4112/* Sream and Sensor specific */
4116 {0xa0, 0x03, ZC3XX_R012_VIDEOCONTROLFUNC}, /* VideoControlFunction */ 4113 {0xa0, 0x03, ZC3XX_R012_VIDEOCONTROLFUNC},
4117 {0xa0, 0x01, ZC3XX_R012_VIDEOCONTROLFUNC}, /* VideoControlFunction */ 4114 {0xa0, 0x01, ZC3XX_R012_VIDEOCONTROLFUNC},
4118/* Sensor Interface */ 4115/* Sensor Interface */
4119 {0xa0, 0x08, ZC3XX_R08D_COMPABILITYMODE}, /* Compatibily Mode */ 4116 {0xa0, 0x08, ZC3XX_R08D_COMPABILITYMODE},
4120/* Window inside sensor array */ 4117/* Window inside sensor array */
4121 {0xa0, 0x03, ZC3XX_R09A_WINXSTARTLOW}, /* WinXStartLow */ 4118 {0xa0, 0x03, ZC3XX_R09A_WINXSTARTLOW},
4122 {0xa0, 0x00, ZC3XX_R11A_FIRSTYLOW}, /* FirstYLow */ 4119 {0xa0, 0x00, ZC3XX_R11A_FIRSTYLOW},
4123 {0xa0, 0x03, ZC3XX_R11C_FIRSTXLOW}, /* FirstxLow */ 4120 {0xa0, 0x03, ZC3XX_R11C_FIRSTXLOW},
4124 {0xa0, 0x28, ZC3XX_R09C_WINHEIGHTLOW}, /* WinHeightLow */ 4121 {0xa0, 0x28, ZC3XX_R09C_WINHEIGHTLOW},
4125 {0xa0, 0x68, ZC3XX_R09E_WINWIDTHLOW}, /* WinWidthLow */ 4122 {0xa0, 0x68, ZC3XX_R09E_WINWIDTHLOW},
4126/* Init the sensor */ 4123/* Init the sensor */
4127 {0xaa, 0x02, 0x0004}, 4124 {0xaa, 0x02, 0x0004},
4128 {0xaa, 0x08, 0x0000}, 4125 {0xaa, 0x08, 0x0000},
@@ -4135,40 +4132,40 @@ static const struct usb_action pas106b_Initial[] = { /* 176x144 */
4135 {0xaa, 0x14, 0x0081}, 4132 {0xaa, 0x14, 0x0081},
4136 4133
4137/* Other registors */ 4134/* Other registors */
4138 {0xa0, 0x37, ZC3XX_R101_SENSORCORRECTION}, /* SensorCorrection */ 4135 {0xa0, 0x37, ZC3XX_R101_SENSORCORRECTION},
4139/* Frame retreiving */ 4136/* Frame retreiving */
4140 {0xa0, 0x00, ZC3XX_R019_AUTOADJUSTFPS}, /* AutoAdjustFPS */ 4137 {0xa0, 0x00, ZC3XX_R019_AUTOADJUSTFPS},
4141/* Gains */ 4138/* Gains */
4142 {0xa0, 0xa0, ZC3XX_R1A8_DIGITALGAIN}, /* DigitalGain */ 4139 {0xa0, 0xa0, ZC3XX_R1A8_DIGITALGAIN},
4143/* Unknown */ 4140/* Unknown */
4144 {0xa0, 0x00, 0x01ad}, 4141 {0xa0, 0x00, 0x01ad},
4145/* Sharpness */ 4142/* Sharpness */
4146 {0xa0, 0x03, ZC3XX_R1C5_SHARPNESSMODE}, /* SharpnessMode */ 4143 {0xa0, 0x03, ZC3XX_R1C5_SHARPNESSMODE},
4147 {0xa0, 0x13, ZC3XX_R1CB_SHARPNESS05}, /* Sharpness05 */ 4144 {0xa0, 0x13, ZC3XX_R1CB_SHARPNESS05},
4148/* Other registors */ 4145/* Other registors */
4149 {0xa0, 0x0d, ZC3XX_R100_OPERATIONMODE}, /* OperationMode */ 4146 {0xa0, 0x0d, ZC3XX_R100_OPERATIONMODE},
4150/* Auto exposure and white balance */ 4147/* Auto exposure and white balance */
4151 {0xa0, 0x06, ZC3XX_R189_AWBSTATUS}, /* AWBStatus */ 4148 {0xa0, 0x06, ZC3XX_R189_AWBSTATUS},
4152/*Dead pixels */ 4149/*Dead pixels */
4153 {0xa0, 0x08, ZC3XX_R250_DEADPIXELSMODE}, /* DeadPixelsMode */ 4150 {0xa0, 0x08, ZC3XX_R250_DEADPIXELSMODE},
4154/* EEPROM */ 4151/* EEPROM */
4155 {0xa0, 0x08, ZC3XX_R301_EEPROMACCESS}, /* EEPROMAccess */ 4152 {0xa0, 0x08, ZC3XX_R301_EEPROMACCESS},
4156/* JPEG control */ 4153/* JPEG control */
4157 {0xa0, 0x03, ZC3XX_R008_CLOCKSETTING}, /* ClockSetting */ 4154 {0xa0, 0x03, ZC3XX_R008_CLOCKSETTING},
4158 {0xa0, 0x08, ZC3XX_R1C6_SHARPNESS00}, /* sharpness+ */ 4155 {0xa0, 0x08, ZC3XX_R1C6_SHARPNESS00},
4159 {0xa0, 0x0f, ZC3XX_R1CB_SHARPNESS05}, /* sharpness- */ 4156 {0xa0, 0x0f, ZC3XX_R1CB_SHARPNESS05},
4160/* Other registers */ 4157/* Other registers */
4161 {0xa0, 0x0d, ZC3XX_R100_OPERATIONMODE}, /* OperationMode */ 4158 {0xa0, 0x0d, ZC3XX_R100_OPERATIONMODE},
4162/* Auto exposure and white balance */ 4159/* Auto exposure and white balance */
4163 {0xa0, 0x06, ZC3XX_R189_AWBSTATUS}, /* AWBStatus */ 4160 {0xa0, 0x06, ZC3XX_R189_AWBSTATUS},
4164/*Dead pixels */ 4161/*Dead pixels */
4165 {0xa0, 0x08, ZC3XX_R250_DEADPIXELSMODE}, /* DeadPixelsMode */ 4162 {0xa0, 0x08, ZC3XX_R250_DEADPIXELSMODE},
4166/* EEPROM */ 4163/* EEPROM */
4167 {0xa0, 0x08, ZC3XX_R301_EEPROMACCESS}, /* EEPROMAccess */ 4164 {0xa0, 0x08, ZC3XX_R301_EEPROMACCESS},
4168/* JPEG control */ 4165/* JPEG control */
4169 {0xa0, 0x03, ZC3XX_R008_CLOCKSETTING}, /* ClockSetting */ 4166 {0xa0, 0x03, ZC3XX_R008_CLOCKSETTING},
4170 {0xa0, 0x08, ZC3XX_R1C6_SHARPNESS00}, /* sharpness+ */ 4167 {0xa0, 0x08, ZC3XX_R1C6_SHARPNESS00},
4171 {0xa0, 0x0f, ZC3XX_R1CB_SHARPNESS05}, /* sharpness- */ 4168 {0xa0, 0x0f, ZC3XX_R1CB_SHARPNESS05},
4172 4169
4173 {0xa0, 0x58, ZC3XX_R10A_RGB00}, /* matrix */ 4170 {0xa0, 0x58, ZC3XX_R10A_RGB00}, /* matrix */
4174 {0xa0, 0xf4, ZC3XX_R10B_RGB01}, 4171 {0xa0, 0xf4, ZC3XX_R10B_RGB01},
@@ -4180,67 +4177,67 @@ static const struct usb_action pas106b_Initial[] = { /* 176x144 */
4180 {0xa0, 0xf4, ZC3XX_R111_RGB21}, 4177 {0xa0, 0xf4, ZC3XX_R111_RGB21},
4181 {0xa0, 0x58, ZC3XX_R112_RGB22}, 4178 {0xa0, 0x58, ZC3XX_R112_RGB22},
4182/* Auto correction */ 4179/* Auto correction */
4183 {0xa0, 0x03, ZC3XX_R181_WINXSTART}, /* WinXstart */ 4180 {0xa0, 0x03, ZC3XX_R181_WINXSTART},
4184 {0xa0, 0x08, ZC3XX_R182_WINXWIDTH}, /* WinXWidth */ 4181 {0xa0, 0x08, ZC3XX_R182_WINXWIDTH},
4185 {0xa0, 0x16, ZC3XX_R183_WINXCENTER}, /* WinXCenter */ 4182 {0xa0, 0x16, ZC3XX_R183_WINXCENTER},
4186 {0xa0, 0x03, ZC3XX_R184_WINYSTART}, /* WinYStart */ 4183 {0xa0, 0x03, ZC3XX_R184_WINYSTART},
4187 {0xa0, 0x05, ZC3XX_R185_WINYWIDTH}, /* WinYWidth */ 4184 {0xa0, 0x05, ZC3XX_R185_WINYWIDTH},
4188 {0xa0, 0x14, ZC3XX_R186_WINYCENTER}, /* WinYCenter */ 4185 {0xa0, 0x14, ZC3XX_R186_WINYCENTER},
4189 {0xa0, 0x00, ZC3XX_R180_AUTOCORRECTENABLE}, /* AutoCorrectEnable */ 4186 {0xa0, 0x00, ZC3XX_R180_AUTOCORRECTENABLE},
4190 4187
4191/* Auto exposure and white balance */ 4188/* Auto exposure and white balance */
4192 {0xa0, 0x00, ZC3XX_R190_EXPOSURELIMITHIGH}, /* ExposureLimitHigh */ 4189 {0xa0, 0x00, ZC3XX_R190_EXPOSURELIMITHIGH},
4193 {0xa0, 0x03, ZC3XX_R191_EXPOSURELIMITMID}, /* ExposureLimitMid */ 4190 {0xa0, 0x03, ZC3XX_R191_EXPOSURELIMITMID},
4194 {0xa0, 0xb1, ZC3XX_R192_EXPOSURELIMITLOW}, /* ExposureLimitLow */ 4191 {0xa0, 0xb1, ZC3XX_R192_EXPOSURELIMITLOW},
4195 {0xa0, 0x00, ZC3XX_R195_ANTIFLICKERHIGH}, /* AntiFlickerHigh */ 4192 {0xa0, 0x00, ZC3XX_R195_ANTIFLICKERHIGH},
4196 {0xa0, 0x00, ZC3XX_R196_ANTIFLICKERMID}, /* AntiFlickerLow */ 4193 {0xa0, 0x00, ZC3XX_R196_ANTIFLICKERMID},
4197 {0xa0, 0x87, ZC3XX_R197_ANTIFLICKERLOW}, /* AntiFlickerLow */ 4194 {0xa0, 0x87, ZC3XX_R197_ANTIFLICKERLOW},
4198 {0xa0, 0x0c, ZC3XX_R18C_AEFREEZE}, /* AEBFreeze */ 4195 {0xa0, 0x0c, ZC3XX_R18C_AEFREEZE},
4199 {0xa0, 0x18, ZC3XX_R18F_AEUNFREEZE}, /* AEBUnfreeze */ 4196 {0xa0, 0x18, ZC3XX_R18F_AEUNFREEZE},
4200/* sensor on */ 4197/* sensor on */
4201 {0xaa, 0x07, 0x00b1}, 4198 {0xaa, 0x07, 0x00b1},
4202 {0xaa, 0x05, 0x0003}, 4199 {0xaa, 0x05, 0x0003},
4203 {0xaa, 0x04, 0x0001}, 4200 {0xaa, 0x04, 0x0001},
4204 {0xaa, 0x03, 0x003b}, 4201 {0xaa, 0x03, 0x003b},
4205/* Gains */ 4202/* Gains */
4206 {0xa0, 0x20, ZC3XX_R1A9_DIGITALLIMITDIFF}, /* DigitalLimitDiff */ 4203 {0xa0, 0x20, ZC3XX_R1A9_DIGITALLIMITDIFF},
4207 {0xa0, 0x26, ZC3XX_R1AA_DIGITALGAINSTEP}, /* DigitalGainStep */ 4204 {0xa0, 0x26, ZC3XX_R1AA_DIGITALGAINSTEP},
4208 {0xa0, 0xa0, ZC3XX_R11D_GLOBALGAIN}, /* GlobalGain */ 4205 {0xa0, 0xa0, ZC3XX_R11D_GLOBALGAIN},
4209 {0xa0, 0x60, ZC3XX_R11D_GLOBALGAIN}, /* GlobalGain */ 4206 {0xa0, 0x60, ZC3XX_R11D_GLOBALGAIN},
4210/* Auto correction */ 4207/* Auto correction */
4211 {0xa0, 0x40, ZC3XX_R180_AUTOCORRECTENABLE}, /* AutoCorrectEnable */ 4208 {0xa0, 0x40, ZC3XX_R180_AUTOCORRECTENABLE},
4212 {0xa1, 0x01, 0x0180}, /* AutoCorrectEnable */ 4209 {0xa1, 0x01, 0x0180}, /* AutoCorrectEnable */
4213 {0xa0, 0x42, ZC3XX_R180_AUTOCORRECTENABLE}, /* AutoCorrectEnable */ 4210 {0xa0, 0x42, ZC3XX_R180_AUTOCORRECTENABLE},
4214/* Gains */ 4211/* Gains */
4215 {0xa0, 0x40, ZC3XX_R116_RGAIN}, /* RGain */ 4212 {0xa0, 0x40, ZC3XX_R116_RGAIN},
4216 {0xa0, 0x40, ZC3XX_R117_GGAIN}, /* GGain */ 4213 {0xa0, 0x40, ZC3XX_R117_GGAIN},
4217 {0xa0, 0x40, ZC3XX_R118_BGAIN}, /* BGain */ 4214 {0xa0, 0x40, ZC3XX_R118_BGAIN},
4218 {} 4215 {}
4219}; 4216};
4220 4217
4221static const struct usb_action pas106b_InitialScale[] = { /* 352x288 */ 4218static const struct usb_action pas106b_InitialScale[] = { /* 352x288 */
4222/* JPEG control */ 4219/* JPEG control */
4223 {0xa0, 0x03, ZC3XX_R008_CLOCKSETTING}, /* ClockSetting */ 4220 {0xa0, 0x03, ZC3XX_R008_CLOCKSETTING},
4224/* Sream and Sensor specific */ 4221/* Sream and Sensor specific */
4225 {0xa0, 0x0f, ZC3XX_R010_CMOSSENSORSELECT}, /* CMOSSensorSelect */ 4222 {0xa0, 0x0f, ZC3XX_R010_CMOSSENSORSELECT},
4226/* Picture size */ 4223/* Picture size */
4227 {0xa0, 0x01, ZC3XX_R003_FRAMEWIDTHHIGH}, /* FrameWidthHigh */ 4224 {0xa0, 0x01, ZC3XX_R003_FRAMEWIDTHHIGH},
4228 {0xa0, 0x60, ZC3XX_R004_FRAMEWIDTHLOW}, /* FrameWidthLow */ 4225 {0xa0, 0x60, ZC3XX_R004_FRAMEWIDTHLOW},
4229 {0xa0, 0x01, ZC3XX_R005_FRAMEHEIGHTHIGH}, /* FrameHeightHigh */ 4226 {0xa0, 0x01, ZC3XX_R005_FRAMEHEIGHTHIGH},
4230 {0xa0, 0x20, ZC3XX_R006_FRAMEHEIGHTLOW}, /* FrameHightLow */ 4227 {0xa0, 0x20, ZC3XX_R006_FRAMEHEIGHTLOW},
4231/* System */ 4228/* System */
4232 {0xa0, 0x01, ZC3XX_R001_SYSTEMOPERATING}, /* SystemOperating */ 4229 {0xa0, 0x01, ZC3XX_R001_SYSTEMOPERATING},
4233/* Sream and Sensor specific */ 4230/* Sream and Sensor specific */
4234 {0xa0, 0x03, ZC3XX_R012_VIDEOCONTROLFUNC}, /* VideoControlFunction */ 4231 {0xa0, 0x03, ZC3XX_R012_VIDEOCONTROLFUNC},
4235 {0xa0, 0x01, ZC3XX_R012_VIDEOCONTROLFUNC}, /* VideoControlFunction */ 4232 {0xa0, 0x01, ZC3XX_R012_VIDEOCONTROLFUNC},
4236/* Sensor Interface */ 4233/* Sensor Interface */
4237 {0xa0, 0x08, ZC3XX_R08D_COMPABILITYMODE}, /* Compatibily Mode */ 4234 {0xa0, 0x08, ZC3XX_R08D_COMPABILITYMODE},
4238/* Window inside sensor array */ 4235/* Window inside sensor array */
4239 {0xa0, 0x03, ZC3XX_R09A_WINXSTARTLOW}, /* WinXStartLow */ 4236 {0xa0, 0x03, ZC3XX_R09A_WINXSTARTLOW},
4240 {0xa0, 0x00, ZC3XX_R11A_FIRSTYLOW}, /* FirstYLow */ 4237 {0xa0, 0x00, ZC3XX_R11A_FIRSTYLOW},
4241 {0xa0, 0x03, ZC3XX_R11C_FIRSTXLOW}, /* FirstxLow */ 4238 {0xa0, 0x03, ZC3XX_R11C_FIRSTXLOW},
4242 {0xa0, 0x28, ZC3XX_R09C_WINHEIGHTLOW}, /* WinHeightLow */ 4239 {0xa0, 0x28, ZC3XX_R09C_WINHEIGHTLOW},
4243 {0xa0, 0x68, ZC3XX_R09E_WINWIDTHLOW}, /* WinWidthLow */ 4240 {0xa0, 0x68, ZC3XX_R09E_WINWIDTHLOW},
4244/* Init the sensor */ 4241/* Init the sensor */
4245 {0xaa, 0x02, 0x0004}, 4242 {0xaa, 0x02, 0x0004},
4246 {0xaa, 0x08, 0x0000}, 4243 {0xaa, 0x08, 0x0000},
@@ -4253,41 +4250,41 @@ static const struct usb_action pas106b_InitialScale[] = { /* 352x288 */
4253 {0xaa, 0x14, 0x0081}, 4250 {0xaa, 0x14, 0x0081},
4254 4251
4255/* Other registors */ 4252/* Other registors */
4256 {0xa0, 0x37, ZC3XX_R101_SENSORCORRECTION}, /* SensorCorrection */ 4253 {0xa0, 0x37, ZC3XX_R101_SENSORCORRECTION},
4257/* Frame retreiving */ 4254/* Frame retreiving */
4258 {0xa0, 0x00, ZC3XX_R019_AUTOADJUSTFPS}, /* AutoAdjustFPS */ 4255 {0xa0, 0x00, ZC3XX_R019_AUTOADJUSTFPS},
4259/* Gains */ 4256/* Gains */
4260 {0xa0, 0xa0, ZC3XX_R1A8_DIGITALGAIN}, /* DigitalGain */ 4257 {0xa0, 0xa0, ZC3XX_R1A8_DIGITALGAIN},
4261/* Unknown */ 4258/* Unknown */
4262 {0xa0, 0x00, 0x01ad}, 4259 {0xa0, 0x00, 0x01ad},
4263/* Sharpness */ 4260/* Sharpness */
4264 {0xa0, 0x03, ZC3XX_R1C5_SHARPNESSMODE}, /* SharpnessMode */ 4261 {0xa0, 0x03, ZC3XX_R1C5_SHARPNESSMODE},
4265 {0xa0, 0x13, ZC3XX_R1CB_SHARPNESS05}, /* Sharpness05 */ 4262 {0xa0, 0x13, ZC3XX_R1CB_SHARPNESS05},
4266/* Other registors */ 4263/* Other registors */
4267 {0xa0, 0x0d, ZC3XX_R100_OPERATIONMODE}, /* OperationMode */ 4264 {0xa0, 0x0d, ZC3XX_R100_OPERATIONMODE},
4268/* Auto exposure and white balance */ 4265/* Auto exposure and white balance */
4269 {0xa0, 0x06, ZC3XX_R189_AWBSTATUS}, /* AWBStatus */ 4266 {0xa0, 0x06, ZC3XX_R189_AWBSTATUS},
4270 {0xa0, 0x80, ZC3XX_R18D_YTARGET}, /* ????????? */ 4267 {0xa0, 0x80, ZC3XX_R18D_YTARGET},
4271/*Dead pixels */ 4268/*Dead pixels */
4272 {0xa0, 0x08, ZC3XX_R250_DEADPIXELSMODE}, /* DeadPixelsMode */ 4269 {0xa0, 0x08, ZC3XX_R250_DEADPIXELSMODE},
4273/* EEPROM */ 4270/* EEPROM */
4274 {0xa0, 0x08, ZC3XX_R301_EEPROMACCESS}, /* EEPROMAccess */ 4271 {0xa0, 0x08, ZC3XX_R301_EEPROMACCESS},
4275/* JPEG control */ 4272/* JPEG control */
4276 {0xa0, 0x03, ZC3XX_R008_CLOCKSETTING}, /* ClockSetting */ 4273 {0xa0, 0x03, ZC3XX_R008_CLOCKSETTING},
4277 {0xa0, 0x08, ZC3XX_R1C6_SHARPNESS00}, /* sharpness+ */ 4274 {0xa0, 0x08, ZC3XX_R1C6_SHARPNESS00},
4278 {0xa0, 0x0f, ZC3XX_R1CB_SHARPNESS05}, /* sharpness- */ 4275 {0xa0, 0x0f, ZC3XX_R1CB_SHARPNESS05},
4279/* Other registers */ 4276/* Other registers */
4280 {0xa0, 0x0d, ZC3XX_R100_OPERATIONMODE}, /* OperationMode */ 4277 {0xa0, 0x0d, ZC3XX_R100_OPERATIONMODE},
4281/* Auto exposure and white balance */ 4278/* Auto exposure and white balance */
4282 {0xa0, 0x06, ZC3XX_R189_AWBSTATUS}, /* AWBStatus */ 4279 {0xa0, 0x06, ZC3XX_R189_AWBSTATUS},
4283/*Dead pixels */ 4280/*Dead pixels */
4284 {0xa0, 0x08, ZC3XX_R250_DEADPIXELSMODE}, /* DeadPixelsMode */ 4281 {0xa0, 0x08, ZC3XX_R250_DEADPIXELSMODE},
4285/* EEPROM */ 4282/* EEPROM */
4286 {0xa0, 0x08, ZC3XX_R301_EEPROMACCESS}, /* EEPROMAccess */ 4283 {0xa0, 0x08, ZC3XX_R301_EEPROMACCESS},
4287/* JPEG control */ 4284/* JPEG control */
4288 {0xa0, 0x03, ZC3XX_R008_CLOCKSETTING}, /* ClockSetting */ 4285 {0xa0, 0x03, ZC3XX_R008_CLOCKSETTING},
4289 {0xa0, 0x08, ZC3XX_R1C6_SHARPNESS00}, /* sharpness+ */ 4286 {0xa0, 0x08, ZC3XX_R1C6_SHARPNESS00},
4290 {0xa0, 0x0f, ZC3XX_R1CB_SHARPNESS05}, /* sharpness- */ 4287 {0xa0, 0x0f, ZC3XX_R1CB_SHARPNESS05},
4291 4288
4292 {0xa0, 0x58, ZC3XX_R10A_RGB00}, /* matrix */ 4289 {0xa0, 0x58, ZC3XX_R10A_RGB00}, /* matrix */
4293 {0xa0, 0xf4, ZC3XX_R10B_RGB01}, 4290 {0xa0, 0xf4, ZC3XX_R10B_RGB01},
@@ -4299,43 +4296,43 @@ static const struct usb_action pas106b_InitialScale[] = { /* 352x288 */
4299 {0xa0, 0xf4, ZC3XX_R111_RGB21}, 4296 {0xa0, 0xf4, ZC3XX_R111_RGB21},
4300 {0xa0, 0x58, ZC3XX_R112_RGB22}, 4297 {0xa0, 0x58, ZC3XX_R112_RGB22},
4301/* Auto correction */ 4298/* Auto correction */
4302 {0xa0, 0x03, ZC3XX_R181_WINXSTART}, /* WinXstart */ 4299 {0xa0, 0x03, ZC3XX_R181_WINXSTART},
4303 {0xa0, 0x08, ZC3XX_R182_WINXWIDTH}, /* WinXWidth */ 4300 {0xa0, 0x08, ZC3XX_R182_WINXWIDTH},
4304 {0xa0, 0x16, ZC3XX_R183_WINXCENTER}, /* WinXCenter */ 4301 {0xa0, 0x16, ZC3XX_R183_WINXCENTER},
4305 {0xa0, 0x03, ZC3XX_R184_WINYSTART}, /* WinYStart */ 4302 {0xa0, 0x03, ZC3XX_R184_WINYSTART},
4306 {0xa0, 0x05, ZC3XX_R185_WINYWIDTH}, /* WinYWidth */ 4303 {0xa0, 0x05, ZC3XX_R185_WINYWIDTH},
4307 {0xa0, 0x14, ZC3XX_R186_WINYCENTER}, /* WinYCenter */ 4304 {0xa0, 0x14, ZC3XX_R186_WINYCENTER},
4308 {0xa0, 0x00, ZC3XX_R180_AUTOCORRECTENABLE}, /* AutoCorrectEnable */ 4305 {0xa0, 0x00, ZC3XX_R180_AUTOCORRECTENABLE},
4309 4306
4310/* Auto exposure and white balance */ 4307/* Auto exposure and white balance */
4311 {0xa0, 0x00, ZC3XX_R190_EXPOSURELIMITHIGH}, /* ExposureLimitHigh 0 */ 4308 {0xa0, 0x00, ZC3XX_R190_EXPOSURELIMITHIGH},
4312 {0xa0, 0x03, ZC3XX_R191_EXPOSURELIMITMID}, /* ExposureLimitMid */ 4309 {0xa0, 0x03, ZC3XX_R191_EXPOSURELIMITMID},
4313 {0xa0, 0xb1, ZC3XX_R192_EXPOSURELIMITLOW}, /* ExposureLimitLow 0xb1 */ 4310 {0xa0, 0xb1, ZC3XX_R192_EXPOSURELIMITLOW},
4314 4311
4315 {0xa0, 0x00, ZC3XX_R195_ANTIFLICKERHIGH}, /* AntiFlickerHigh 0x00 */ 4312 {0xa0, 0x00, ZC3XX_R195_ANTIFLICKERHIGH},
4316 {0xa0, 0x00, ZC3XX_R196_ANTIFLICKERMID}, /* AntiFlickerLow 0x00 */ 4313 {0xa0, 0x00, ZC3XX_R196_ANTIFLICKERMID},
4317 {0xa0, 0x87, ZC3XX_R197_ANTIFLICKERLOW}, /* AntiFlickerLow 0x87 */ 4314 {0xa0, 0x87, ZC3XX_R197_ANTIFLICKERLOW},
4318 4315
4319 {0xa0, 0x10, ZC3XX_R18C_AEFREEZE}, /* AEBFreeze 0x10 0x0c */ 4316 {0xa0, 0x10, ZC3XX_R18C_AEFREEZE},
4320 {0xa0, 0x20, ZC3XX_R18F_AEUNFREEZE}, /* AEBUnfreeze 0x30 0x18 */ 4317 {0xa0, 0x20, ZC3XX_R18F_AEUNFREEZE},
4321/* sensor on */ 4318/* sensor on */
4322 {0xaa, 0x07, 0x00b1}, 4319 {0xaa, 0x07, 0x00b1},
4323 {0xaa, 0x05, 0x0003}, 4320 {0xaa, 0x05, 0x0003},
4324 {0xaa, 0x04, 0x0001}, 4321 {0xaa, 0x04, 0x0001},
4325 {0xaa, 0x03, 0x003b}, 4322 {0xaa, 0x03, 0x003b},
4326/* Gains */ 4323/* Gains */
4327 {0xa0, 0x20, ZC3XX_R1A9_DIGITALLIMITDIFF}, /* DigitalLimitDiff */ 4324 {0xa0, 0x20, ZC3XX_R1A9_DIGITALLIMITDIFF},
4328 {0xa0, 0x26, ZC3XX_R1AA_DIGITALGAINSTEP}, /* DigitalGainStep */ 4325 {0xa0, 0x26, ZC3XX_R1AA_DIGITALGAINSTEP},
4329 {0xa0, 0xa0, ZC3XX_R11D_GLOBALGAIN}, /* GlobalGain */ 4326 {0xa0, 0xa0, ZC3XX_R11D_GLOBALGAIN},
4330 {0xa0, 0x60, ZC3XX_R11D_GLOBALGAIN}, /* GlobalGain */ 4327 {0xa0, 0x60, ZC3XX_R11D_GLOBALGAIN},
4331/* Auto correction */ 4328/* Auto correction */
4332 {0xa0, 0x40, ZC3XX_R180_AUTOCORRECTENABLE}, /* AutoCorrectEnable */ 4329 {0xa0, 0x40, ZC3XX_R180_AUTOCORRECTENABLE},
4333 {0xa1, 0x01, 0x0180}, /* AutoCorrectEnable */ 4330 {0xa1, 0x01, 0x0180}, /* AutoCorrectEnable */
4334 {0xa0, 0x42, ZC3XX_R180_AUTOCORRECTENABLE}, /* AutoCorrectEnable */ 4331 {0xa0, 0x42, ZC3XX_R180_AUTOCORRECTENABLE},
4335/* Gains */ 4332/* Gains */
4336 {0xa0, 0x40, ZC3XX_R116_RGAIN}, /* RGain */ 4333 {0xa0, 0x40, ZC3XX_R116_RGAIN},
4337 {0xa0, 0x40, ZC3XX_R117_GGAIN}, /* GGain */ 4334 {0xa0, 0x40, ZC3XX_R117_GGAIN},
4338 {0xa0, 0x40, ZC3XX_R118_BGAIN}, /* BGain */ 4335 {0xa0, 0x40, ZC3XX_R118_BGAIN},
4339 4336
4340 {0xa0, 0x00, 0x0007}, /* AutoCorrectEnable */ 4337 {0xa0, 0x00, 0x0007}, /* AutoCorrectEnable */
4341 {0xa0, 0xff, ZC3XX_R018_FRAMELOST}, /* Frame adjust */ 4338 {0xa0, 0xff, ZC3XX_R018_FRAMELOST}, /* Frame adjust */
@@ -4459,8 +4456,8 @@ static const struct usb_action pb03303x_Initial[] = {
4459 {0xa0, 0x50, ZC3XX_R112_RGB22}, 4456 {0xa0, 0x50, ZC3XX_R112_RGB22},
4460 4457
4461 {0xa1, 0x01, 0x0008}, 4458 {0xa1, 0x01, 0x0008},
4462 {0xa0, 0x03, ZC3XX_R008_CLOCKSETTING}, /* clock ? */ 4459 {0xa0, 0x03, ZC3XX_R008_CLOCKSETTING},
4463 {0xa0, 0x08, ZC3XX_R1C6_SHARPNESS00}, /* sharpness+ */ 4460 {0xa0, 0x08, ZC3XX_R1C6_SHARPNESS00},
4464 {0xa1, 0x01, 0x01c8}, 4461 {0xa1, 0x01, 0x01c8},
4465 {0xa1, 0x01, 0x01c9}, 4462 {0xa1, 0x01, 0x01c9},
4466 {0xa1, 0x01, 0x01ca}, 4463 {0xa1, 0x01, 0x01ca},
@@ -5984,7 +5981,7 @@ static const struct usb_action tas5130c_vf0250_Initial[] = {
5984 {0xaa, 0x1b, 0x0000}, /* 00,1b,00,aa, */ 5981 {0xaa, 0x1b, 0x0000}, /* 00,1b,00,aa, */
5985 {0xaa, 0x13, 0x0002}, /* 00,13,02,aa, */ 5982 {0xaa, 0x13, 0x0002}, /* 00,13,02,aa, */
5986 {0xaa, 0x15, 0x0004}, /* 00,15,04,aa */ 5983 {0xaa, 0x15, 0x0004}, /* 00,15,04,aa */
5987 {0xaa, 0x01, 0x0000}, 5984/*?? {0xaa, 0x01, 0x0000}, */
5988 {0xaa, 0x01, 0x0000}, 5985 {0xaa, 0x01, 0x0000},
5989 {0xaa, 0x1a, 0x0000}, /* 00,1a,00,aa, */ 5986 {0xaa, 0x1a, 0x0000}, /* 00,1a,00,aa, */
5990 {0xaa, 0x1c, 0x0017}, /* 00,1c,17,aa, */ 5987 {0xaa, 0x1c, 0x0017}, /* 00,1c,17,aa, */
@@ -6000,8 +5997,8 @@ static const struct usb_action tas5130c_vf0250_Initial[] = {
6000 {0xaa, 0x0f, 0x00a0}, /* 00,0f,a0,aa, */ 5997 {0xaa, 0x0f, 0x00a0}, /* 00,0f,a0,aa, */
6001 {0xaa, 0x10, 0x0000}, /* 00,10,00,aa, */ 5998 {0xaa, 0x10, 0x0000}, /* 00,10,00,aa, */
6002 {0xaa, 0x11, 0x00a0}, /* 00,11,a0,aa, */ 5999 {0xaa, 0x11, 0x00a0}, /* 00,11,a0,aa, */
6003 {0xa0, 0x00, 0x0039}, 6000/*?? {0xa0, 0x00, 0x0039},
6004 {0xa1, 0x01, 0x0037}, 6001 {0xa1, 0x01, 0x0037}, */
6005 {0xaa, 0x16, 0x0001}, /* 00,16,01,aa, */ 6002 {0xaa, 0x16, 0x0001}, /* 00,16,01,aa, */
6006 {0xaa, 0x17, 0x00e8}, /* 00,17,e6,aa, (e6 -> e8) */ 6003 {0xaa, 0x17, 0x00e8}, /* 00,17,e6,aa, (e6 -> e8) */
6007 {0xaa, 0x18, 0x0002}, /* 00,18,02,aa, */ 6004 {0xaa, 0x18, 0x0002}, /* 00,18,02,aa, */
@@ -6272,7 +6269,7 @@ static void reg_w(struct usb_device *dev,
6272 __u8 value, 6269 __u8 value,
6273 __u16 index) 6270 __u16 index)
6274{ 6271{
6275 PDEBUG(D_USBO, "reg w %02x -> [%04x]", value, index); 6272 PDEBUG(D_USBO, "reg w [%04x] = %02x", index, value);
6276 reg_w_i(dev, value, index); 6273 reg_w_i(dev, value, index);
6277} 6274}
6278 6275
@@ -6280,17 +6277,17 @@ static __u16 i2c_read(struct gspca_dev *gspca_dev,
6280 __u8 reg) 6277 __u8 reg)
6281{ 6278{
6282 __u8 retbyte; 6279 __u8 retbyte;
6283 __u8 retval[2]; 6280 __u16 retval;
6284 6281
6285 reg_w_i(gspca_dev->dev, reg, 0x92); 6282 reg_w_i(gspca_dev->dev, reg, 0x92);
6286 reg_w_i(gspca_dev->dev, 0x02, 0x90); /* <- read command */ 6283 reg_w_i(gspca_dev->dev, 0x02, 0x90); /* <- read command */
6287 msleep(25); 6284 msleep(25);
6288 retbyte = reg_r_i(gspca_dev, 0x0091); /* read status */ 6285 retbyte = reg_r_i(gspca_dev, 0x0091); /* read status */
6289 retval[0] = reg_r_i(gspca_dev, 0x0095); /* read Lowbyte */ 6286 retval = reg_r_i(gspca_dev, 0x0095); /* read Lowbyte */
6290 retval[1] = reg_r_i(gspca_dev, 0x0096); /* read Hightbyte */ 6287 retval |= reg_r_i(gspca_dev, 0x0096) << 8; /* read Hightbyte */
6291 PDEBUG(D_USBO, "i2c r [%02x] -> (%02x) %02x%02x", 6288 PDEBUG(D_USBO, "i2c r [%02x] -> %04x (%02x)",
6292 reg, retbyte, retval[1], retval[0]); 6289 reg, retval, retbyte);
6293 return (retval[1] << 8) | retval[0]; 6290 return retval;
6294} 6291}
6295 6292
6296static __u8 i2c_write(struct gspca_dev *gspca_dev, 6293static __u8 i2c_write(struct gspca_dev *gspca_dev,
@@ -6306,7 +6303,7 @@ static __u8 i2c_write(struct gspca_dev *gspca_dev,
6306 reg_w_i(gspca_dev->dev, 0x01, 0x90); /* <- write command */ 6303 reg_w_i(gspca_dev->dev, 0x01, 0x90); /* <- write command */
6307 msleep(5); 6304 msleep(5);
6308 retbyte = reg_r_i(gspca_dev, 0x0091); /* read status */ 6305 retbyte = reg_r_i(gspca_dev, 0x0091); /* read status */
6309 PDEBUG(D_USBO, "i2c w [%02x] %02x%02x (%02x)", 6306 PDEBUG(D_USBO, "i2c w [%02x] = %02x%02x (%02x)",
6310 reg, valH, valL, retbyte); 6307 reg, valH, valL, retbyte);
6311 return retbyte; 6308 return retbyte;
6312} 6309}
@@ -6349,6 +6346,8 @@ static void setmatrix(struct gspca_dev *gspca_dev)
6349 {0x58, 0xf4, 0xf4, 0xf4, 0x58, 0xf4, 0xf4, 0xf4, 0x58}; 6346 {0x58, 0xf4, 0xf4, 0xf4, 0x58, 0xf4, 0xf4, 0xf4, 0x58};
6350 static const __u8 po2030_matrix[9] = 6347 static const __u8 po2030_matrix[9] =
6351 {0x60, 0xf0, 0xf0, 0xf0, 0x60, 0xf0, 0xf0, 0xf0, 0x60}; 6348 {0x60, 0xf0, 0xf0, 0xf0, 0x60, 0xf0, 0xf0, 0xf0, 0x60};
6349 static const __u8 vf0250_matrix[9] =
6350 {0x7b, 0xea, 0xea, 0xea, 0x7b, 0xea, 0xea, 0xea, 0x7b};
6352 6351
6353 switch (sd->sensor) { 6352 switch (sd->sensor) {
6354 case SENSOR_GC0305: 6353 case SENSOR_GC0305:
@@ -6363,8 +6362,9 @@ static void setmatrix(struct gspca_dev *gspca_dev)
6363 case SENSOR_PO2030: 6362 case SENSOR_PO2030:
6364 matrix = po2030_matrix; 6363 matrix = po2030_matrix;
6365 break; 6364 break;
6366 case SENSOR_TAS5130C_VF0250: /* no matrix? */ 6365 case SENSOR_TAS5130C_VF0250:
6367 return; 6366 matrix = vf0250_matrix;
6367 break;
6368 default: /* matrix already loaded */ 6368 default: /* matrix already loaded */
6369 return; 6369 return;
6370 } 6370 }
@@ -6744,7 +6744,7 @@ static int vga_2wr_probe(struct gspca_dev *gspca_dev)
6744 return 0x04; /* CS2102 */ 6744 return 0x04; /* CS2102 */
6745 6745
6746 start_2wr_probe(dev, 0x06); /* OmniVision */ 6746 start_2wr_probe(dev, 0x06); /* OmniVision */
6747 reg_w(dev, 0x08, 0x8d); 6747 reg_w(dev, 0x08, 0x008d);
6748 i2c_write(gspca_dev, 0x11, 0xaa, 0x00); 6748 i2c_write(gspca_dev, 0x11, 0xaa, 0x00);
6749 retbyte = i2c_read(gspca_dev, 0x11); 6749 retbyte = i2c_read(gspca_dev, 0x11);
6750 if (retbyte != 0) { 6750 if (retbyte != 0) {
@@ -6778,7 +6778,7 @@ static int vga_2wr_probe(struct gspca_dev *gspca_dev)
6778 return 0x0c; /* ICM105A */ 6778 return 0x0c; /* ICM105A */
6779 6779
6780 start_2wr_probe(dev, 0x0e); /* PAS202BCB */ 6780 start_2wr_probe(dev, 0x0e); /* PAS202BCB */
6781 reg_w(dev, 0x08, 0x8d); 6781 reg_w(dev, 0x08, 0x008d);
6782 i2c_write(gspca_dev, 0x03, 0xaa, 0x00); 6782 i2c_write(gspca_dev, 0x03, 0xaa, 0x00);
6783 msleep(500); 6783 msleep(500);
6784 retbyte = i2c_read(gspca_dev, 0x03); 6784 retbyte = i2c_read(gspca_dev, 0x03);
@@ -6830,7 +6830,6 @@ static const struct sensor_by_chipset_revision chipset_revision_sensor[] = {
6830 {0x8001, 0x13}, 6830 {0x8001, 0x13},
6831 {0x8000, 0x14}, /* CS2102K */ 6831 {0x8000, 0x14}, /* CS2102K */
6832 {0x8400, 0x15}, /* TAS5130K */ 6832 {0x8400, 0x15}, /* TAS5130K */
6833 {0, 0}
6834}; 6833};
6835 6834
6836static int vga_3wr_probe(struct gspca_dev *gspca_dev) 6835static int vga_3wr_probe(struct gspca_dev *gspca_dev)
@@ -6843,7 +6842,7 @@ static int vga_3wr_probe(struct gspca_dev *gspca_dev)
6843 6842
6844/*fixme: lack of 8b=b3 (11,12)-> 10, 8b=e0 (14,15,16)-> 12 found in gspcav1*/ 6843/*fixme: lack of 8b=b3 (11,12)-> 10, 8b=e0 (14,15,16)-> 12 found in gspcav1*/
6845 reg_w(dev, 0x02, 0x0010); 6844 reg_w(dev, 0x02, 0x0010);
6846 reg_r(gspca_dev, 0x10); 6845 reg_r(gspca_dev, 0x0010);
6847 reg_w(dev, 0x01, 0x0000); 6846 reg_w(dev, 0x01, 0x0000);
6848 reg_w(dev, 0x00, 0x0010); 6847 reg_w(dev, 0x00, 0x0010);
6849 reg_w(dev, 0x01, 0x0001); 6848 reg_w(dev, 0x01, 0x0001);
@@ -6869,17 +6868,15 @@ static int vga_3wr_probe(struct gspca_dev *gspca_dev)
6869 PDEBUG(D_PROBE, "probe 3wr vga 1 0x%04x", checkword); 6868 PDEBUG(D_PROBE, "probe 3wr vga 1 0x%04x", checkword);
6870 reg_r(gspca_dev, 0x0010); 6869 reg_r(gspca_dev, 0x0010);
6871 /* this is tested only once anyway */ 6870 /* this is tested only once anyway */
6872 i = 0; 6871 for (i = 0; i < ARRAY_SIZE(chipset_revision_sensor); i++) {
6873 while (chipset_revision_sensor[i].revision) {
6874 if (chipset_revision_sensor[i].revision == checkword) { 6872 if (chipset_revision_sensor[i].revision == checkword) {
6875 sd->chip_revision = checkword; 6873 sd->chip_revision = checkword;
6876 send_unknown(dev, SENSOR_PB0330); 6874 send_unknown(dev, SENSOR_PB0330);
6877 return chipset_revision_sensor[i].internal_sensor_id; 6875 return chipset_revision_sensor[i].internal_sensor_id;
6878 } 6876 }
6879 i++;
6880 } 6877 }
6881 6878
6882 reg_w(dev, 0x01, 0x0000); 6879 reg_w(dev, 0x01, 0x0000); /* check ?? */
6883 reg_w(dev, 0x01, 0x0001); 6880 reg_w(dev, 0x01, 0x0001);
6884 reg_w(dev, 0xdd, 0x008b); 6881 reg_w(dev, 0xdd, 0x008b);
6885 reg_w(dev, 0x0a, 0x0010); 6882 reg_w(dev, 0x0a, 0x0010);
@@ -6901,8 +6898,11 @@ static int vga_3wr_probe(struct gspca_dev *gspca_dev)
6901 retbyte = i2c_read(gspca_dev, 0x00); 6898 retbyte = i2c_read(gspca_dev, 0x00);
6902 if (retbyte != 0) { 6899 if (retbyte != 0) {
6903 PDEBUG(D_PROBE, "probe 3wr vga type %02x", retbyte); 6900 PDEBUG(D_PROBE, "probe 3wr vga type %02x", retbyte);
6904 send_unknown(dev, SENSOR_GC0305); 6901 if (retbyte == 0x11) /* VF0250 */
6905 return retbyte; /* 0x29 = gc0305 - should continue? */ 6902 return 0x0250;
6903 if (retbyte == 0x29) /* gc0305 */
6904 send_unknown(dev, SENSOR_GC0305);
6905 return retbyte;
6906 } 6906 }
6907 6907
6908 reg_w(dev, 0x01, 0x0000); /* check OmniVision */ 6908 reg_w(dev, 0x01, 0x0000); /* check OmniVision */
@@ -6918,18 +6918,18 @@ static int vga_3wr_probe(struct gspca_dev *gspca_dev)
6918 return 0x06; /* OmniVision confirm ? */ 6918 return 0x06; /* OmniVision confirm ? */
6919 } 6919 }
6920 6920
6921 reg_w(dev, 0x01, 0x00); 6921 reg_w(dev, 0x01, 0x0000);
6922 reg_w(dev, 0x00, 0x02); 6922 reg_w(dev, 0x00, 0x0002);
6923 reg_w(dev, 0x01, 0x10); 6923 reg_w(dev, 0x01, 0x0010);
6924 reg_w(dev, 0x01, 0x01); 6924 reg_w(dev, 0x01, 0x0001);
6925 reg_w(dev, 0xee, 0x8b); 6925 reg_w(dev, 0xee, 0x008b);
6926 reg_w(dev, 0x03, 0x12); 6926 reg_w(dev, 0x03, 0x0012);
6927/* msleep(150); */ 6927/* msleep(150); */
6928 reg_w(dev, 0x01, 0x12); 6928 reg_w(dev, 0x01, 0x0012);
6929 reg_w(dev, 0x05, 0x12); 6929 reg_w(dev, 0x05, 0x0012);
6930 retbyte = i2c_read(gspca_dev, 0x00); /* ID 0 */ 6930 retbyte = i2c_read(gspca_dev, 0x0000); /* ID 0 */
6931 checkword = retbyte << 8; 6931 checkword = retbyte << 8;
6932 retbyte = i2c_read(gspca_dev, 0x01); /* ID 1 */ 6932 retbyte = i2c_read(gspca_dev, 0x0001); /* ID 1 */
6933 checkword |= retbyte; 6933 checkword |= retbyte;
6934 PDEBUG(D_PROBE, "probe 3wr vga 2 0x%04x", checkword); 6934 PDEBUG(D_PROBE, "probe 3wr vga 2 0x%04x", checkword);
6935 if (checkword == 0x2030) { 6935 if (checkword == 0x2030) {
@@ -6939,14 +6939,14 @@ static int vga_3wr_probe(struct gspca_dev *gspca_dev)
6939 return checkword; 6939 return checkword;
6940 } 6940 }
6941 6941
6942 reg_w(dev, 0x01, 0x00); 6942 reg_w(dev, 0x01, 0x0000);
6943 reg_w(dev, 0x0a, 0x10); 6943 reg_w(dev, 0x0a, 0x0010);
6944 reg_w(dev, 0xd3, 0x8b); 6944 reg_w(dev, 0xd3, 0x008b);
6945 reg_w(dev, 0x01, 0x01); 6945 reg_w(dev, 0x01, 0x0001);
6946 reg_w(dev, 0x03, 0x12); 6946 reg_w(dev, 0x03, 0x0012);
6947 reg_w(dev, 0x01, 0x12); 6947 reg_w(dev, 0x01, 0x0012);
6948 reg_w(dev, 0x05, 0x01); 6948 reg_w(dev, 0x05, 0x0001);
6949 reg_w(dev, 0xd3, 0x8b); 6949 reg_w(dev, 0xd3, 0x008b);
6950 retbyte = i2c_read(gspca_dev, 0x01); 6950 retbyte = i2c_read(gspca_dev, 0x01);
6951 if (retbyte != 0) { 6951 if (retbyte != 0) {
6952 PDEBUG(D_PROBE, "probe 3wr vga type 0a ?"); 6952 PDEBUG(D_PROBE, "probe 3wr vga type 0a ?");
@@ -6962,7 +6962,9 @@ static int zcxx_probeSensor(struct gspca_dev *gspca_dev)
6962 6962
6963 switch (sd->sensor) { 6963 switch (sd->sensor) {
6964 case SENSOR_MC501CB: 6964 case SENSOR_MC501CB:
6965 return -1; /* don't probe */
6965 case SENSOR_TAS5130C_VF0250: 6966 case SENSOR_TAS5130C_VF0250:
6967 /* may probe but with write in reg 0x0010 */
6966 return -1; /* don't probe */ 6968 return -1; /* don't probe */
6967 } 6969 }
6968 sensor = vga_2wr_probe(gspca_dev); 6970 sensor = vga_2wr_probe(gspca_dev);
@@ -7010,30 +7012,7 @@ static int sd_config(struct gspca_dev *gspca_dev,
7010 7012
7011 /* define some sensors from the vendor/product */ 7013 /* define some sensors from the vendor/product */
7012 sd->sharpness = 2; 7014 sd->sharpness = 2;
7013 switch (id->idVendor) { 7015 sd->sensor = id->driver_info;
7014 case 0x041e: /* Creative */
7015 switch (id->idProduct) {
7016 case 0x4051: /* zc301 chips */
7017 case 0x4053:
7018 sd->sensor = SENSOR_TAS5130C_VF0250;
7019 break;
7020 }
7021 break;
7022 case 0x046d: /* Logitech Labtec */
7023 switch (id->idProduct) {
7024 case 0x08dd:
7025 sd->sensor = SENSOR_MC501CB;
7026 break;
7027 }
7028 break;
7029 case 0x0ac8: /* Vimicro z-star */
7030 switch (id->idProduct) {
7031 case 0x305b:
7032 sd->sensor = SENSOR_TAS5130C_VF0250;
7033 break;
7034 }
7035 break;
7036 }
7037 sensor = zcxx_probeSensor(gspca_dev); 7016 sensor = zcxx_probeSensor(gspca_dev);
7038 if (sensor >= 0) 7017 if (sensor >= 0)
7039 PDEBUG(D_PROBE, "probe sensor -> %02x", sensor); 7018 PDEBUG(D_PROBE, "probe sensor -> %02x", sensor);
@@ -7119,6 +7098,10 @@ static int sd_config(struct gspca_dev *gspca_dev,
7119 PDEBUG(D_PROBE, "Find Sensor GC0305"); 7098 PDEBUG(D_PROBE, "Find Sensor GC0305");
7120 sd->sensor = SENSOR_GC0305; 7099 sd->sensor = SENSOR_GC0305;
7121 break; 7100 break;
7101 case 0x0250:
7102 PDEBUG(D_PROBE, "Sensor Tas5130 (VF0250)");
7103 sd->sensor = SENSOR_TAS5130C_VF0250;
7104 break;
7122 case 0x2030: 7105 case 0x2030:
7123 PDEBUG(D_PROBE, "Find Sensor PO2030"); 7106 PDEBUG(D_PROBE, "Find Sensor PO2030");
7124 sd->sensor = SENSOR_PO2030; 7107 sd->sensor = SENSOR_PO2030;
@@ -7146,7 +7129,6 @@ static int sd_config(struct gspca_dev *gspca_dev,
7146 } 7129 }
7147 7130
7148 cam = &gspca_dev->cam; 7131 cam = &gspca_dev->cam;
7149 cam->dev_name = (char *) id->driver_info;
7150 cam->epaddr = 0x01; 7132 cam->epaddr = 0x01;
7151/*fixme:test*/ 7133/*fixme:test*/
7152 gspca_dev->nbalt--; 7134 gspca_dev->nbalt--;
@@ -7235,6 +7217,7 @@ static void sd_start(struct gspca_dev *gspca_dev)
7235 case SENSOR_GC0305: 7217 case SENSOR_GC0305:
7236 case SENSOR_OV7620: 7218 case SENSOR_OV7620:
7237 case SENSOR_PO2030: 7219 case SENSOR_PO2030:
7220 case SENSOR_TAS5130C_VF0250:
7238 msleep(100); /* ?? */ 7221 msleep(100); /* ?? */
7239 reg_r(gspca_dev, 0x0002); /* --> 0x40 */ 7222 reg_r(gspca_dev, 0x0002); /* --> 0x40 */
7240 reg_w(dev, 0x09, 0x01ad); /* (from win traces) */ 7223 reg_w(dev, 0x09, 0x01ad); /* (from win traces) */
@@ -7515,70 +7498,69 @@ static const struct sd_desc sd_desc = {
7515 .querymenu = sd_querymenu, 7498 .querymenu = sd_querymenu,
7516}; 7499};
7517 7500
7518#define DVNM(name) .driver_info = (kernel_ulong_t) name
7519static const __devinitdata struct usb_device_id device_table[] = { 7501static const __devinitdata struct usb_device_id device_table[] = {
7520 {USB_DEVICE(0x041e, 0x041e), DVNM("Creative WebCam Live!")}, 7502 {USB_DEVICE(0x041e, 0x041e)},
7521#ifndef CONFIG_USB_ZC0301 7503#ifndef CONFIG_USB_ZC0301
7522 {USB_DEVICE(0x041e, 0x4017), DVNM("Creative Webcam Mobile PD1090")}, 7504 {USB_DEVICE(0x041e, 0x4017)},
7523 {USB_DEVICE(0x041e, 0x401c), DVNM("Creative NX")}, 7505 {USB_DEVICE(0x041e, 0x401c)},
7524 {USB_DEVICE(0x041e, 0x401e), DVNM("Creative Nx Pro")}, 7506 {USB_DEVICE(0x041e, 0x401e)},
7525 {USB_DEVICE(0x041e, 0x401f), DVNM("Creative Webcam Notebook PD1171")}, 7507 {USB_DEVICE(0x041e, 0x401f)},
7526#endif 7508#endif
7527 {USB_DEVICE(0x041e, 0x4029), DVNM("Creative WebCam Vista Pro")}, 7509 {USB_DEVICE(0x041e, 0x4029)},
7528#ifndef CONFIG_USB_ZC0301 7510#ifndef CONFIG_USB_ZC0301
7529 {USB_DEVICE(0x041e, 0x4034), DVNM("Creative Instant P0620")}, 7511 {USB_DEVICE(0x041e, 0x4034)},
7530 {USB_DEVICE(0x041e, 0x4035), DVNM("Creative Instant P0620D")}, 7512 {USB_DEVICE(0x041e, 0x4035)},
7531 {USB_DEVICE(0x041e, 0x4036), DVNM("Creative Live !")}, 7513 {USB_DEVICE(0x041e, 0x4036)},
7532 {USB_DEVICE(0x041e, 0x403a), DVNM("Creative Nx Pro 2")}, 7514 {USB_DEVICE(0x041e, 0x403a)},
7533#endif 7515#endif
7534 {USB_DEVICE(0x041e, 0x4051), DVNM("Creative Notebook Pro (VF0250)")}, 7516 {USB_DEVICE(0x041e, 0x4051), .driver_info = SENSOR_TAS5130C_VF0250},
7535 {USB_DEVICE(0x041e, 0x4053), DVNM("Creative Live!Cam Video IM")}, 7517 {USB_DEVICE(0x041e, 0x4053), .driver_info = SENSOR_TAS5130C_VF0250},
7536#ifndef CONFIG_USB_ZC0301 7518#ifndef CONFIG_USB_ZC0301
7537 {USB_DEVICE(0x0458, 0x7007), DVNM("Genius VideoCam V2")}, 7519 {USB_DEVICE(0x0458, 0x7007)},
7538 {USB_DEVICE(0x0458, 0x700c), DVNM("Genius VideoCam V3")}, 7520 {USB_DEVICE(0x0458, 0x700c)},
7539 {USB_DEVICE(0x0458, 0x700f), DVNM("Genius VideoCam Web V2")}, 7521 {USB_DEVICE(0x0458, 0x700f)},
7540#endif 7522#endif
7541 {USB_DEVICE(0x0461, 0x0a00), DVNM("MicroInnovation WebCam320")}, 7523 {USB_DEVICE(0x0461, 0x0a00)},
7542 {USB_DEVICE(0x046d, 0x08a0), DVNM("Logitech QC IM")}, 7524 {USB_DEVICE(0x046d, 0x08a0)},
7543 {USB_DEVICE(0x046d, 0x08a1), DVNM("Logitech QC IM 0x08A1 +sound")}, 7525 {USB_DEVICE(0x046d, 0x08a1)},
7544 {USB_DEVICE(0x046d, 0x08a2), DVNM("Labtec Webcam Pro")}, 7526 {USB_DEVICE(0x046d, 0x08a2)},
7545 {USB_DEVICE(0x046d, 0x08a3), DVNM("Logitech QC Chat")}, 7527 {USB_DEVICE(0x046d, 0x08a3)},
7546 {USB_DEVICE(0x046d, 0x08a6), DVNM("Logitech QCim")}, 7528 {USB_DEVICE(0x046d, 0x08a6)},
7547 {USB_DEVICE(0x046d, 0x08a7), DVNM("Logitech QuickCam Image")}, 7529 {USB_DEVICE(0x046d, 0x08a7)},
7548 {USB_DEVICE(0x046d, 0x08a9), DVNM("Logitech Notebook Deluxe")}, 7530 {USB_DEVICE(0x046d, 0x08a9)},
7549 {USB_DEVICE(0x046d, 0x08aa), DVNM("Labtec Webcam Notebook")}, 7531 {USB_DEVICE(0x046d, 0x08aa)},
7550 {USB_DEVICE(0x046d, 0x08ac), DVNM("Logitech QuickCam Cool")}, 7532 {USB_DEVICE(0x046d, 0x08ac)},
7551 {USB_DEVICE(0x046d, 0x08ad), DVNM("Logitech QCCommunicate STX")}, 7533 {USB_DEVICE(0x046d, 0x08ad)},
7552#ifndef CONFIG_USB_ZC0301 7534#ifndef CONFIG_USB_ZC0301
7553 {USB_DEVICE(0x046d, 0x08ae), DVNM("Logitech QuickCam for Notebooks")}, 7535 {USB_DEVICE(0x046d, 0x08ae)},
7554#endif 7536#endif
7555 {USB_DEVICE(0x046d, 0x08af), DVNM("Logitech QuickCam Cool")}, 7537 {USB_DEVICE(0x046d, 0x08af)},
7556 {USB_DEVICE(0x046d, 0x08b9), DVNM("Logitech QC IM ???")}, 7538 {USB_DEVICE(0x046d, 0x08b9)},
7557 {USB_DEVICE(0x046d, 0x08d7), DVNM("Logitech QCam STX")}, 7539 {USB_DEVICE(0x046d, 0x08d7)},
7558 {USB_DEVICE(0x046d, 0x08d9), DVNM("Logitech QuickCam IM/Connect")}, 7540 {USB_DEVICE(0x046d, 0x08d9)},
7559 {USB_DEVICE(0x046d, 0x08d8), DVNM("Logitech Notebook Deluxe")}, 7541 {USB_DEVICE(0x046d, 0x08d8)},
7560 {USB_DEVICE(0x046d, 0x08da), DVNM("Logitech QuickCam Messenger")}, 7542 {USB_DEVICE(0x046d, 0x08da)},
7561 {USB_DEVICE(0x046d, 0x08dd), DVNM("Logitech QuickCam for Notebooks")}, 7543 {USB_DEVICE(0x046d, 0x08dd), .driver_info = SENSOR_MC501CB},
7562 {USB_DEVICE(0x0471, 0x0325), DVNM("Philips SPC 200 NC")}, 7544 {USB_DEVICE(0x0471, 0x0325)},
7563 {USB_DEVICE(0x0471, 0x0326), DVNM("Philips SPC 300 NC")}, 7545 {USB_DEVICE(0x0471, 0x0326)},
7564 {USB_DEVICE(0x0471, 0x032d), DVNM("Philips spc210nc")}, 7546 {USB_DEVICE(0x0471, 0x032d)},
7565 {USB_DEVICE(0x0471, 0x032e), DVNM("Philips spc315nc")}, 7547 {USB_DEVICE(0x0471, 0x032e)},
7566 {USB_DEVICE(0x055f, 0xc005), DVNM("Mustek Wcam300A")}, 7548 {USB_DEVICE(0x055f, 0xc005)},
7567#ifndef CONFIG_USB_ZC0301 7549#ifndef CONFIG_USB_ZC0301
7568 {USB_DEVICE(0x055f, 0xd003), DVNM("Mustek WCam300A")}, 7550 {USB_DEVICE(0x055f, 0xd003)},
7569 {USB_DEVICE(0x055f, 0xd004), DVNM("Mustek WCam300 AN")}, 7551 {USB_DEVICE(0x055f, 0xd004)},
7570#endif 7552#endif
7571 {USB_DEVICE(0x0698, 0x2003), DVNM("CTX M730V built in")}, 7553 {USB_DEVICE(0x0698, 0x2003)},
7572 {USB_DEVICE(0x0ac8, 0x0302), DVNM("Z-star Vimicro zc0302")}, 7554 {USB_DEVICE(0x0ac8, 0x0302)},
7573#ifndef CONFIG_USB_ZC0301 7555#ifndef CONFIG_USB_ZC0301
7574 {USB_DEVICE(0x0ac8, 0x301b), DVNM("Z-Star zc301b")}, 7556 {USB_DEVICE(0x0ac8, 0x301b)},
7575 {USB_DEVICE(0x0ac8, 0x303b), DVNM("Vimicro 0x303b")}, 7557 {USB_DEVICE(0x0ac8, 0x303b)},
7576#endif 7558#endif
7577 {USB_DEVICE(0x0ac8, 0x305b), DVNM("Z-star Vimicro zc0305b")}, 7559 {USB_DEVICE(0x0ac8, 0x305b), .driver_info = SENSOR_TAS5130C_VF0250},
7578#ifndef CONFIG_USB_ZC0301 7560#ifndef CONFIG_USB_ZC0301
7579 {USB_DEVICE(0x0ac8, 0x307b), DVNM("Z-Star 307b")}, 7561 {USB_DEVICE(0x0ac8, 0x307b)},
7580 {USB_DEVICE(0x10fd, 0x0128), DVNM("Typhoon Webshot II 300k 0x0128")}, 7562 {USB_DEVICE(0x10fd, 0x0128)},
7581 {USB_DEVICE(0x10fd, 0x8050), DVNM("Typhoon Webshot II USB 300k")}, 7563 {USB_DEVICE(0x10fd, 0x8050)},
7582#endif 7564#endif
7583 {} /* end of entry */ 7565 {} /* end of entry */
7584}; 7566};
@@ -7605,7 +7587,7 @@ static int __init sd_mod_init(void)
7605{ 7587{
7606 if (usb_register(&sd_driver) < 0) 7588 if (usb_register(&sd_driver) < 0)
7607 return -1; 7589 return -1;
7608 PDEBUG(D_PROBE, "v%s registered", version); 7590 PDEBUG(D_PROBE, "registered");
7609 return 0; 7591 return 0;
7610} 7592}
7611 7593
diff --git a/drivers/media/video/ivtv/Kconfig b/drivers/media/video/ivtv/Kconfig
index 5d7ee8fcdd50..0069898bddab 100644
--- a/drivers/media/video/ivtv/Kconfig
+++ b/drivers/media/video/ivtv/Kconfig
@@ -2,9 +2,7 @@ config VIDEO_IVTV
2 tristate "Conexant cx23416/cx23415 MPEG encoder/decoder support" 2 tristate "Conexant cx23416/cx23415 MPEG encoder/decoder support"
3 depends on VIDEO_V4L1 && VIDEO_V4L2 && PCI && I2C && EXPERIMENTAL 3 depends on VIDEO_V4L1 && VIDEO_V4L2 && PCI && I2C && EXPERIMENTAL
4 depends on INPUT # due to VIDEO_IR 4 depends on INPUT # due to VIDEO_IR
5 depends on HOTPLUG # due to FW_LOADER
6 select I2C_ALGOBIT 5 select I2C_ALGOBIT
7 select FW_LOADER
8 select VIDEO_IR 6 select VIDEO_IR
9 select VIDEO_TUNER 7 select VIDEO_TUNER
10 select VIDEO_TVEEPROM 8 select VIDEO_TVEEPROM
diff --git a/drivers/media/video/ivtv/ivtv-driver.c b/drivers/media/video/ivtv/ivtv-driver.c
index 41fd79279bb5..aea1664948ce 100644
--- a/drivers/media/video/ivtv/ivtv-driver.c
+++ b/drivers/media/video/ivtv/ivtv-driver.c
@@ -465,9 +465,8 @@ static void ivtv_process_eeprom(struct ivtv *itv)
465 if (itv->options.radio == -1) 465 if (itv->options.radio == -1)
466 itv->options.radio = (tv.has_radio != 0); 466 itv->options.radio = (tv.has_radio != 0);
467 /* only enable newi2c if an IR blaster is present */ 467 /* only enable newi2c if an IR blaster is present */
468 /* FIXME: for 2.6.20 the test against 2 should be removed */ 468 if (itv->options.newi2c == -1 && tv.has_ir) {
469 if (itv->options.newi2c == -1 && tv.has_ir != -1 && tv.has_ir != 2) { 469 itv->options.newi2c = (tv.has_ir & 4) ? 1 : 0;
470 itv->options.newi2c = (tv.has_ir & 2) ? 1 : 0;
471 if (itv->options.newi2c) { 470 if (itv->options.newi2c) {
472 IVTV_INFO("Reopen i2c bus for IR-blaster support\n"); 471 IVTV_INFO("Reopen i2c bus for IR-blaster support\n");
473 exit_ivtv_i2c(itv); 472 exit_ivtv_i2c(itv);
diff --git a/drivers/media/video/ivtv/ivtv-driver.h b/drivers/media/video/ivtv/ivtv-driver.h
index a08bb3331cfb..ab287b48fc2b 100644
--- a/drivers/media/video/ivtv/ivtv-driver.h
+++ b/drivers/media/video/ivtv/ivtv-driver.h
@@ -60,6 +60,7 @@
60#include <linux/dvb/video.h> 60#include <linux/dvb/video.h>
61#include <linux/dvb/audio.h> 61#include <linux/dvb/audio.h>
62#include <media/v4l2-common.h> 62#include <media/v4l2-common.h>
63#include <media/v4l2-ioctl.h>
63#include <media/tuner.h> 64#include <media/tuner.h>
64#include <media/cx2341x.h> 65#include <media/cx2341x.h>
65 66
diff --git a/drivers/media/video/ivtv/ivtv-ioctl.c b/drivers/media/video/ivtv/ivtv-ioctl.c
index 52e00a7f3110..61030309d0ad 100644
--- a/drivers/media/video/ivtv/ivtv-ioctl.c
+++ b/drivers/media/video/ivtv/ivtv-ioctl.c
@@ -1842,69 +1842,73 @@ int ivtv_v4l2_ioctl(struct inode *inode, struct file *filp, unsigned int cmd,
1842 return res; 1842 return res;
1843} 1843}
1844 1844
1845void ivtv_set_funcs(struct video_device *vdev) 1845static const struct v4l2_ioctl_ops ivtv_ioctl_ops = {
1846{ 1846 .vidioc_querycap = ivtv_querycap,
1847 vdev->vidioc_querycap = ivtv_querycap; 1847 .vidioc_g_priority = ivtv_g_priority,
1848 vdev->vidioc_g_priority = ivtv_g_priority; 1848 .vidioc_s_priority = ivtv_s_priority,
1849 vdev->vidioc_s_priority = ivtv_s_priority; 1849 .vidioc_s_audio = ivtv_s_audio,
1850 vdev->vidioc_s_audio = ivtv_s_audio; 1850 .vidioc_g_audio = ivtv_g_audio,
1851 vdev->vidioc_g_audio = ivtv_g_audio; 1851 .vidioc_enumaudio = ivtv_enumaudio,
1852 vdev->vidioc_enumaudio = ivtv_enumaudio; 1852 .vidioc_s_audout = ivtv_s_audout,
1853 vdev->vidioc_s_audout = ivtv_s_audout; 1853 .vidioc_g_audout = ivtv_g_audout,
1854 vdev->vidioc_g_audout = ivtv_g_audout; 1854 .vidioc_enum_input = ivtv_enum_input,
1855 vdev->vidioc_enum_input = ivtv_enum_input; 1855 .vidioc_enum_output = ivtv_enum_output,
1856 vdev->vidioc_enum_output = ivtv_enum_output; 1856 .vidioc_enumaudout = ivtv_enumaudout,
1857 vdev->vidioc_enumaudout = ivtv_enumaudout; 1857 .vidioc_cropcap = ivtv_cropcap,
1858 vdev->vidioc_cropcap = ivtv_cropcap; 1858 .vidioc_s_crop = ivtv_s_crop,
1859 vdev->vidioc_s_crop = ivtv_s_crop; 1859 .vidioc_g_crop = ivtv_g_crop,
1860 vdev->vidioc_g_crop = ivtv_g_crop; 1860 .vidioc_g_input = ivtv_g_input,
1861 vdev->vidioc_g_input = ivtv_g_input; 1861 .vidioc_s_input = ivtv_s_input,
1862 vdev->vidioc_s_input = ivtv_s_input; 1862 .vidioc_g_output = ivtv_g_output,
1863 vdev->vidioc_g_output = ivtv_g_output; 1863 .vidioc_s_output = ivtv_s_output,
1864 vdev->vidioc_s_output = ivtv_s_output; 1864 .vidioc_g_frequency = ivtv_g_frequency,
1865 vdev->vidioc_g_frequency = ivtv_g_frequency; 1865 .vidioc_s_frequency = ivtv_s_frequency,
1866 vdev->vidioc_s_frequency = ivtv_s_frequency; 1866 .vidioc_s_tuner = ivtv_s_tuner,
1867 vdev->vidioc_s_tuner = ivtv_s_tuner; 1867 .vidioc_g_tuner = ivtv_g_tuner,
1868 vdev->vidioc_g_tuner = ivtv_g_tuner; 1868 .vidioc_g_enc_index = ivtv_g_enc_index,
1869 vdev->vidioc_g_enc_index = ivtv_g_enc_index; 1869 .vidioc_g_fbuf = ivtv_g_fbuf,
1870 vdev->vidioc_g_fbuf = ivtv_g_fbuf; 1870 .vidioc_s_fbuf = ivtv_s_fbuf,
1871 vdev->vidioc_s_fbuf = ivtv_s_fbuf; 1871 .vidioc_g_std = ivtv_g_std,
1872 vdev->vidioc_g_std = ivtv_g_std; 1872 .vidioc_s_std = ivtv_s_std,
1873 vdev->vidioc_s_std = ivtv_s_std; 1873 .vidioc_overlay = ivtv_overlay,
1874 vdev->vidioc_overlay = ivtv_overlay; 1874 .vidioc_log_status = ivtv_log_status,
1875 vdev->vidioc_log_status = ivtv_log_status; 1875 .vidioc_enum_fmt_vid_cap = ivtv_enum_fmt_vid_cap,
1876 vdev->vidioc_enum_fmt_vid_cap = ivtv_enum_fmt_vid_cap; 1876 .vidioc_encoder_cmd = ivtv_encoder_cmd,
1877 vdev->vidioc_encoder_cmd = ivtv_encoder_cmd; 1877 .vidioc_try_encoder_cmd = ivtv_try_encoder_cmd,
1878 vdev->vidioc_try_encoder_cmd = ivtv_try_encoder_cmd; 1878 .vidioc_enum_fmt_vid_out = ivtv_enum_fmt_vid_out,
1879 vdev->vidioc_enum_fmt_vid_out = ivtv_enum_fmt_vid_out; 1879 .vidioc_g_fmt_vid_cap = ivtv_g_fmt_vid_cap,
1880 vdev->vidioc_g_fmt_vid_cap = ivtv_g_fmt_vid_cap; 1880 .vidioc_g_fmt_vbi_cap = ivtv_g_fmt_vbi_cap,
1881 vdev->vidioc_g_fmt_vbi_cap = ivtv_g_fmt_vbi_cap; 1881 .vidioc_g_fmt_sliced_vbi_cap = ivtv_g_fmt_sliced_vbi_cap,
1882 vdev->vidioc_g_fmt_sliced_vbi_cap = ivtv_g_fmt_sliced_vbi_cap; 1882 .vidioc_g_fmt_vid_out = ivtv_g_fmt_vid_out,
1883 vdev->vidioc_g_fmt_vid_out = ivtv_g_fmt_vid_out; 1883 .vidioc_g_fmt_vid_out_overlay = ivtv_g_fmt_vid_out_overlay,
1884 vdev->vidioc_g_fmt_vid_out_overlay = ivtv_g_fmt_vid_out_overlay; 1884 .vidioc_g_fmt_sliced_vbi_out = ivtv_g_fmt_sliced_vbi_out,
1885 vdev->vidioc_g_fmt_sliced_vbi_out = ivtv_g_fmt_sliced_vbi_out; 1885 .vidioc_s_fmt_vid_cap = ivtv_s_fmt_vid_cap,
1886 vdev->vidioc_s_fmt_vid_cap = ivtv_s_fmt_vid_cap; 1886 .vidioc_s_fmt_vbi_cap = ivtv_s_fmt_vbi_cap,
1887 vdev->vidioc_s_fmt_vbi_cap = ivtv_s_fmt_vbi_cap; 1887 .vidioc_s_fmt_sliced_vbi_cap = ivtv_s_fmt_sliced_vbi_cap,
1888 vdev->vidioc_s_fmt_sliced_vbi_cap = ivtv_s_fmt_sliced_vbi_cap; 1888 .vidioc_s_fmt_vid_out = ivtv_s_fmt_vid_out,
1889 vdev->vidioc_s_fmt_vid_out = ivtv_s_fmt_vid_out; 1889 .vidioc_s_fmt_vid_out_overlay = ivtv_s_fmt_vid_out_overlay,
1890 vdev->vidioc_s_fmt_vid_out_overlay = ivtv_s_fmt_vid_out_overlay; 1890 .vidioc_s_fmt_sliced_vbi_out = ivtv_s_fmt_sliced_vbi_out,
1891 vdev->vidioc_s_fmt_sliced_vbi_out = ivtv_s_fmt_sliced_vbi_out; 1891 .vidioc_try_fmt_vid_cap = ivtv_try_fmt_vid_cap,
1892 vdev->vidioc_try_fmt_vid_cap = ivtv_try_fmt_vid_cap; 1892 .vidioc_try_fmt_vbi_cap = ivtv_try_fmt_vbi_cap,
1893 vdev->vidioc_try_fmt_vbi_cap = ivtv_try_fmt_vbi_cap; 1893 .vidioc_try_fmt_sliced_vbi_cap = ivtv_try_fmt_sliced_vbi_cap,
1894 vdev->vidioc_try_fmt_sliced_vbi_cap = ivtv_try_fmt_sliced_vbi_cap; 1894 .vidioc_try_fmt_vid_out = ivtv_try_fmt_vid_out,
1895 vdev->vidioc_try_fmt_vid_out = ivtv_try_fmt_vid_out; 1895 .vidioc_try_fmt_vid_out_overlay = ivtv_try_fmt_vid_out_overlay,
1896 vdev->vidioc_try_fmt_vid_out_overlay = ivtv_try_fmt_vid_out_overlay; 1896 .vidioc_try_fmt_sliced_vbi_out = ivtv_try_fmt_sliced_vbi_out,
1897 vdev->vidioc_try_fmt_sliced_vbi_out = ivtv_try_fmt_sliced_vbi_out; 1897 .vidioc_g_sliced_vbi_cap = ivtv_g_sliced_vbi_cap,
1898 vdev->vidioc_g_sliced_vbi_cap = ivtv_g_sliced_vbi_cap; 1898 .vidioc_g_chip_ident = ivtv_g_chip_ident,
1899 vdev->vidioc_g_chip_ident = ivtv_g_chip_ident;
1900#ifdef CONFIG_VIDEO_ADV_DEBUG 1899#ifdef CONFIG_VIDEO_ADV_DEBUG
1901 vdev->vidioc_g_register = ivtv_g_register; 1900 .vidioc_g_register = ivtv_g_register,
1902 vdev->vidioc_s_register = ivtv_s_register; 1901 .vidioc_s_register = ivtv_s_register,
1903#endif 1902#endif
1904 vdev->vidioc_default = ivtv_default; 1903 .vidioc_default = ivtv_default,
1905 vdev->vidioc_queryctrl = ivtv_queryctrl; 1904 .vidioc_queryctrl = ivtv_queryctrl,
1906 vdev->vidioc_querymenu = ivtv_querymenu; 1905 .vidioc_querymenu = ivtv_querymenu,
1907 vdev->vidioc_g_ext_ctrls = ivtv_g_ext_ctrls; 1906 .vidioc_g_ext_ctrls = ivtv_g_ext_ctrls,
1908 vdev->vidioc_s_ext_ctrls = ivtv_s_ext_ctrls; 1907 .vidioc_s_ext_ctrls = ivtv_s_ext_ctrls,
1909 vdev->vidioc_try_ext_ctrls = ivtv_try_ext_ctrls; 1908 .vidioc_try_ext_ctrls = ivtv_try_ext_ctrls,
1909};
1910
1911void ivtv_set_funcs(struct video_device *vdev)
1912{
1913 vdev->ioctl_ops = &ivtv_ioctl_ops;
1910} 1914}
diff --git a/drivers/media/video/ivtv/ivtv-streams.c b/drivers/media/video/ivtv/ivtv-streams.c
index f8883b487f4a..54d2023b26c4 100644
--- a/drivers/media/video/ivtv/ivtv-streams.c
+++ b/drivers/media/video/ivtv/ivtv-streams.c
@@ -208,16 +208,11 @@ static int ivtv_prep_dev(struct ivtv *itv, int type)
208 return -ENOMEM; 208 return -ENOMEM;
209 } 209 }
210 210
211 s->v4l2dev->type = VID_TYPE_CAPTURE | VID_TYPE_TUNER | VID_TYPE_TELETEXT |
212 VID_TYPE_CLIPPING | VID_TYPE_SCALES | VID_TYPE_MPEG_ENCODER;
213 if (itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT) {
214 s->v4l2dev->type |= VID_TYPE_MPEG_DECODER;
215 }
216 snprintf(s->v4l2dev->name, sizeof(s->v4l2dev->name), "ivtv%d %s", 211 snprintf(s->v4l2dev->name, sizeof(s->v4l2dev->name), "ivtv%d %s",
217 itv->num, s->name); 212 itv->num, s->name);
218 213
219 s->v4l2dev->minor = minor; 214 s->v4l2dev->minor = minor;
220 s->v4l2dev->dev = &itv->dev->dev; 215 s->v4l2dev->parent = &itv->dev->dev;
221 s->v4l2dev->fops = ivtv_stream_info[type].fops; 216 s->v4l2dev->fops = ivtv_stream_info[type].fops;
222 s->v4l2dev->release = video_device_release; 217 s->v4l2dev->release = video_device_release;
223 s->v4l2dev->tvnorms = V4L2_STD_ALL; 218 s->v4l2dev->tvnorms = V4L2_STD_ALL;
diff --git a/drivers/media/video/m52790.c b/drivers/media/video/m52790.c
index 39bf6b114d50..89a781c6929d 100644
--- a/drivers/media/video/m52790.c
+++ b/drivers/media/video/m52790.c
@@ -26,7 +26,7 @@
26#include <asm/uaccess.h> 26#include <asm/uaccess.h>
27#include <linux/i2c.h> 27#include <linux/i2c.h>
28#include <linux/i2c-id.h> 28#include <linux/i2c-id.h>
29#include <linux/videodev.h> 29#include <linux/videodev2.h>
30#include <media/m52790.h> 30#include <media/m52790.h>
31#include <media/v4l2-common.h> 31#include <media/v4l2-common.h>
32#include <media/v4l2-chip-ident.h> 32#include <media/v4l2-chip-ident.h>
diff --git a/drivers/media/video/meye.c b/drivers/media/video/meye.c
index 2fb5854cf6f0..7c8ef6ac6c39 100644
--- a/drivers/media/video/meye.c
+++ b/drivers/media/video/meye.c
@@ -31,6 +31,7 @@
31#include <linux/init.h> 31#include <linux/init.h>
32#include <linux/videodev.h> 32#include <linux/videodev.h>
33#include <media/v4l2-common.h> 33#include <media/v4l2-common.h>
34#include <media/v4l2-ioctl.h>
34#include <asm/uaccess.h> 35#include <asm/uaccess.h>
35#include <asm/io.h> 36#include <asm/io.h>
36#include <linux/delay.h> 37#include <linux/delay.h>
@@ -1697,13 +1698,7 @@ static const struct file_operations meye_fops = {
1697 .llseek = no_llseek, 1698 .llseek = no_llseek,
1698}; 1699};
1699 1700
1700static struct video_device meye_template = { 1701static const struct v4l2_ioctl_ops meye_ioctl_ops = {
1701 .owner = THIS_MODULE,
1702 .name = "meye",
1703 .type = VID_TYPE_CAPTURE,
1704 .fops = &meye_fops,
1705 .release = video_device_release,
1706 .minor = -1,
1707 .vidioc_querycap = vidioc_querycap, 1702 .vidioc_querycap = vidioc_querycap,
1708 .vidioc_enum_input = vidioc_enum_input, 1703 .vidioc_enum_input = vidioc_enum_input,
1709 .vidioc_g_input = vidioc_g_input, 1704 .vidioc_g_input = vidioc_g_input,
@@ -1724,6 +1719,14 @@ static struct video_device meye_template = {
1724 .vidioc_default = vidioc_default, 1719 .vidioc_default = vidioc_default,
1725}; 1720};
1726 1721
1722static struct video_device meye_template = {
1723 .name = "meye",
1724 .fops = &meye_fops,
1725 .ioctl_ops = &meye_ioctl_ops,
1726 .release = video_device_release,
1727 .minor = -1,
1728};
1729
1727#ifdef CONFIG_PM 1730#ifdef CONFIG_PM
1728static int meye_suspend(struct pci_dev *pdev, pm_message_t state) 1731static int meye_suspend(struct pci_dev *pdev, pm_message_t state)
1729{ 1732{
@@ -1801,7 +1804,7 @@ static int __devinit meye_probe(struct pci_dev *pcidev,
1801 } 1804 }
1802 1805
1803 memcpy(meye.video_dev, &meye_template, sizeof(meye_template)); 1806 memcpy(meye.video_dev, &meye_template, sizeof(meye_template));
1804 meye.video_dev->dev = &meye.mchip_dev->dev; 1807 meye.video_dev->parent = &meye.mchip_dev->dev;
1805 1808
1806 if ((ret = sony_pic_camera_command(SONY_PIC_COMMAND_SETCAMERA, 1))) { 1809 if ((ret = sony_pic_camera_command(SONY_PIC_COMMAND_SETCAMERA, 1))) {
1807 printk(KERN_ERR "meye: unable to power on the camera\n"); 1810 printk(KERN_ERR "meye: unable to power on the camera\n");
diff --git a/drivers/media/video/msp3400-driver.c b/drivers/media/video/msp3400-driver.c
index 5691e019d195..3da74dcee902 100644
--- a/drivers/media/video/msp3400-driver.c
+++ b/drivers/media/video/msp3400-driver.c
@@ -51,9 +51,9 @@
51#include <linux/module.h> 51#include <linux/module.h>
52#include <linux/slab.h> 52#include <linux/slab.h>
53#include <linux/i2c.h> 53#include <linux/i2c.h>
54#include <linux/videodev.h>
55#include <linux/videodev2.h> 54#include <linux/videodev2.h>
56#include <media/v4l2-common.h> 55#include <media/v4l2-common.h>
56#include <media/v4l2-ioctl.h>
57#include <media/v4l2-i2c-drv-legacy.h> 57#include <media/v4l2-i2c-drv-legacy.h>
58#include <media/tvaudio.h> 58#include <media/tvaudio.h>
59#include <media/msp3400.h> 59#include <media/msp3400.h>
diff --git a/drivers/media/video/msp3400-kthreads.c b/drivers/media/video/msp3400-kthreads.c
index 1622f70e4dd0..846a14a61fd1 100644
--- a/drivers/media/video/msp3400-kthreads.c
+++ b/drivers/media/video/msp3400-kthreads.c
@@ -25,7 +25,6 @@
25#include <linux/slab.h> 25#include <linux/slab.h>
26#include <linux/i2c.h> 26#include <linux/i2c.h>
27#include <linux/freezer.h> 27#include <linux/freezer.h>
28#include <linux/videodev.h>
29#include <linux/videodev2.h> 28#include <linux/videodev2.h>
30#include <media/v4l2-common.h> 29#include <media/v4l2-common.h>
31#include <media/msp3400.h> 30#include <media/msp3400.h>
diff --git a/drivers/media/video/mt9m001.c b/drivers/media/video/mt9m001.c
index ee43499544c1..554d2295484e 100644
--- a/drivers/media/video/mt9m001.c
+++ b/drivers/media/video/mt9m001.c
@@ -120,7 +120,7 @@ static int mt9m001_init(struct soc_camera_device *icd)
120 int ret; 120 int ret;
121 121
122 /* Disable chip, synchronous option update */ 122 /* Disable chip, synchronous option update */
123 dev_dbg(icd->vdev->dev, "%s\n", __func__); 123 dev_dbg(icd->vdev->parent, "%s\n", __func__);
124 124
125 ret = reg_write(icd, MT9M001_RESET, 1); 125 ret = reg_write(icd, MT9M001_RESET, 1);
126 if (ret >= 0) 126 if (ret >= 0)
diff --git a/drivers/media/video/ov511.c b/drivers/media/video/ov511.c
index eafb0c7736e6..9edaca4371d7 100644
--- a/drivers/media/video/ov511.c
+++ b/drivers/media/video/ov511.c
@@ -4666,9 +4666,7 @@ static const struct file_operations ov511_fops = {
4666}; 4666};
4667 4667
4668static struct video_device vdev_template = { 4668static struct video_device vdev_template = {
4669 .owner = THIS_MODULE,
4670 .name = "OV511 USB Camera", 4669 .name = "OV511 USB Camera",
4671 .type = VID_TYPE_CAPTURE,
4672 .fops = &ov511_fops, 4670 .fops = &ov511_fops,
4673 .release = video_device_release, 4671 .release = video_device_release,
4674 .minor = -1, 4672 .minor = -1,
@@ -5661,43 +5659,43 @@ static int ov_create_sysfs(struct video_device *vdev)
5661{ 5659{
5662 int rc; 5660 int rc;
5663 5661
5664 rc = video_device_create_file(vdev, &dev_attr_custom_id); 5662 rc = device_create_file(&vdev->dev, &dev_attr_custom_id);
5665 if (rc) goto err; 5663 if (rc) goto err;
5666 rc = video_device_create_file(vdev, &dev_attr_model); 5664 rc = device_create_file(&vdev->dev, &dev_attr_model);
5667 if (rc) goto err_id; 5665 if (rc) goto err_id;
5668 rc = video_device_create_file(vdev, &dev_attr_bridge); 5666 rc = device_create_file(&vdev->dev, &dev_attr_bridge);
5669 if (rc) goto err_model; 5667 if (rc) goto err_model;
5670 rc = video_device_create_file(vdev, &dev_attr_sensor); 5668 rc = device_create_file(&vdev->dev, &dev_attr_sensor);
5671 if (rc) goto err_bridge; 5669 if (rc) goto err_bridge;
5672 rc = video_device_create_file(vdev, &dev_attr_brightness); 5670 rc = device_create_file(&vdev->dev, &dev_attr_brightness);
5673 if (rc) goto err_sensor; 5671 if (rc) goto err_sensor;
5674 rc = video_device_create_file(vdev, &dev_attr_saturation); 5672 rc = device_create_file(&vdev->dev, &dev_attr_saturation);
5675 if (rc) goto err_bright; 5673 if (rc) goto err_bright;
5676 rc = video_device_create_file(vdev, &dev_attr_contrast); 5674 rc = device_create_file(&vdev->dev, &dev_attr_contrast);
5677 if (rc) goto err_sat; 5675 if (rc) goto err_sat;
5678 rc = video_device_create_file(vdev, &dev_attr_hue); 5676 rc = device_create_file(&vdev->dev, &dev_attr_hue);
5679 if (rc) goto err_contrast; 5677 if (rc) goto err_contrast;
5680 rc = video_device_create_file(vdev, &dev_attr_exposure); 5678 rc = device_create_file(&vdev->dev, &dev_attr_exposure);
5681 if (rc) goto err_hue; 5679 if (rc) goto err_hue;
5682 5680
5683 return 0; 5681 return 0;
5684 5682
5685err_hue: 5683err_hue:
5686 video_device_remove_file(vdev, &dev_attr_hue); 5684 device_remove_file(&vdev->dev, &dev_attr_hue);
5687err_contrast: 5685err_contrast:
5688 video_device_remove_file(vdev, &dev_attr_contrast); 5686 device_remove_file(&vdev->dev, &dev_attr_contrast);
5689err_sat: 5687err_sat:
5690 video_device_remove_file(vdev, &dev_attr_saturation); 5688 device_remove_file(&vdev->dev, &dev_attr_saturation);
5691err_bright: 5689err_bright:
5692 video_device_remove_file(vdev, &dev_attr_brightness); 5690 device_remove_file(&vdev->dev, &dev_attr_brightness);
5693err_sensor: 5691err_sensor:
5694 video_device_remove_file(vdev, &dev_attr_sensor); 5692 device_remove_file(&vdev->dev, &dev_attr_sensor);
5695err_bridge: 5693err_bridge:
5696 video_device_remove_file(vdev, &dev_attr_bridge); 5694 device_remove_file(&vdev->dev, &dev_attr_bridge);
5697err_model: 5695err_model:
5698 video_device_remove_file(vdev, &dev_attr_model); 5696 device_remove_file(&vdev->dev, &dev_attr_model);
5699err_id: 5697err_id:
5700 video_device_remove_file(vdev, &dev_attr_custom_id); 5698 device_remove_file(&vdev->dev, &dev_attr_custom_id);
5701err: 5699err:
5702 return rc; 5700 return rc;
5703} 5701}
@@ -5833,7 +5831,7 @@ ov51x_probe(struct usb_interface *intf, const struct usb_device_id *id)
5833 goto error; 5831 goto error;
5834 5832
5835 memcpy(ov->vdev, &vdev_template, sizeof(*ov->vdev)); 5833 memcpy(ov->vdev, &vdev_template, sizeof(*ov->vdev));
5836 ov->vdev->dev = &intf->dev; 5834 ov->vdev->parent = &intf->dev;
5837 video_set_drvdata(ov->vdev, ov); 5835 video_set_drvdata(ov->vdev, ov);
5838 5836
5839 for (i = 0; i < OV511_MAX_UNIT_VIDEO; i++) { 5837 for (i = 0; i < OV511_MAX_UNIT_VIDEO; i++) {
diff --git a/drivers/media/video/ov511.h b/drivers/media/video/ov511.h
index 1010e51189b7..baded1262ca9 100644
--- a/drivers/media/video/ov511.h
+++ b/drivers/media/video/ov511.h
@@ -4,6 +4,7 @@
4#include <asm/uaccess.h> 4#include <asm/uaccess.h>
5#include <linux/videodev.h> 5#include <linux/videodev.h>
6#include <media/v4l2-common.h> 6#include <media/v4l2-common.h>
7#include <media/v4l2-ioctl.h>
7#include <linux/usb.h> 8#include <linux/usb.h>
8#include <linux/mutex.h> 9#include <linux/mutex.h>
9 10
diff --git a/drivers/media/video/planb.c b/drivers/media/video/planb.c
index 36047d4e70f6..e69de29bb2d1 100644
--- a/drivers/media/video/planb.c
+++ b/drivers/media/video/planb.c
@@ -1,2309 +0,0 @@
1/*
2 planb - PlanB frame grabber driver
3
4 PlanB is used in the 7x00/8x00 series of PowerMacintosh
5 Computers as video input DMA controller.
6
7 Copyright (C) 1998 Michel Lanners (mlan@cpu.lu)
8
9 Based largely on the bttv driver by Ralph Metzler (rjkm@thp.uni-koeln.de)
10
11 Additional debugging and coding by Takashi Oe (toe@unlserve.unl.edu)
12
13 This program is free software; you can redistribute it and/or modify
14 it under the terms of the GNU General Public License as published by
15 the Free Software Foundation; either version 2 of the License, or
16 (at your option) any later version.
17
18 This program is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with this program; if not, write to the Free Software
25 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26*/
27
28/* $Id: planb.c,v 1.18 1999/05/02 17:36:34 mlan Exp $ */
29
30#include <linux/init.h>
31#include <linux/errno.h>
32#include <linux/module.h>
33#include <linux/kernel.h>
34#include <linux/major.h>
35#include <linux/slab.h>
36#include <linux/types.h>
37#include <linux/pci.h>
38#include <linux/delay.h>
39#include <linux/vmalloc.h>
40#include <linux/mm.h>
41#include <linux/sched.h>
42#include <linux/videodev.h>
43#include <media/v4l2-common.h>
44#include <linux/wait.h>
45#include <asm/uaccess.h>
46#include <asm/io.h>
47#include <asm/prom.h>
48#include <asm/dbdma.h>
49#include <asm/pgtable.h>
50#include <asm/page.h>
51#include <asm/irq.h>
52#include <linux/mutex.h>
53
54#include "planb.h"
55#include "saa7196.h"
56
57/* Would you mind for some ugly debugging? */
58#if 0
59#define DEBUG(x...) printk(KERN_DEBUG ## x) /* Debug driver */
60#else
61#define DEBUG(x...) /* Don't debug driver */
62#endif
63
64#if 0
65#define IDEBUG(x...) printk(KERN_DEBUG ## x) /* Debug interrupt part */
66#else
67#define IDEBUG(x...) /* Don't debug interrupt part */
68#endif
69
70/* Ever seen a Mac with more than 1 of these? */
71#define PLANB_MAX 1
72
73static int planb_num;
74static struct planb planbs[PLANB_MAX];
75static volatile struct planb_registers *planb_regs;
76
77static int def_norm = PLANB_DEF_NORM; /* default norm */
78static int video_nr = -1;
79
80module_param(def_norm, int, 0);
81MODULE_PARM_DESC(def_norm, "Default startup norm (0=PAL, 1=NTSC, 2=SECAM)");
82module_param(video_nr, int, 0);
83MODULE_LICENSE("GPL");
84
85
86/* ------------------ PlanB Exported Functions ------------------ */
87static long planb_write(struct video_device *, const char *, unsigned long, int);
88static long planb_read(struct video_device *, char *, unsigned long, int);
89static int planb_open(struct video_device *, int);
90static void planb_close(struct video_device *);
91static int planb_ioctl(struct video_device *, unsigned int, void *);
92static int planb_init_done(struct video_device *);
93static int planb_mmap(struct video_device *, const char *, unsigned long);
94static void release_planb(void);
95int init_planbs(struct video_init *);
96
97/* ------------------ PlanB Internal Functions ------------------ */
98static int planb_prepare_open(struct planb *);
99static void planb_prepare_close(struct planb *);
100static void saa_write_reg(unsigned char, unsigned char);
101static unsigned char saa_status(int, struct planb *);
102static void saa_set(unsigned char, unsigned char, struct planb *);
103static void saa_init_regs(struct planb *);
104static int grabbuf_alloc(struct planb *);
105static int vgrab(struct planb *, struct video_mmap *);
106static void add_clip(struct planb *, struct video_clip *);
107static void fill_cmd_buff(struct planb *);
108static void cmd_buff(struct planb *);
109static volatile struct dbdma_cmd *setup_grab_cmd(int, struct planb *);
110static void overlay_start(struct planb *);
111static void overlay_stop(struct planb *);
112static inline void tab_cmd_dbdma(volatile struct dbdma_cmd *, unsigned short,
113 unsigned int);
114static inline void tab_cmd_store(volatile struct dbdma_cmd *, unsigned int,
115 unsigned int);
116static inline void tab_cmd_gen(volatile struct dbdma_cmd *, unsigned short,
117 unsigned short, unsigned int, unsigned int);
118static int init_planb(struct planb *);
119static int find_planb(void);
120static void planb_pre_capture(int, int, struct planb *);
121static volatile struct dbdma_cmd *cmd_geo_setup(volatile struct dbdma_cmd *,
122 int, int, int, int, int, struct planb *);
123static inline void planb_dbdma_stop(volatile struct dbdma_regs *);
124static unsigned int saa_geo_setup(int, int, int, int, struct planb *);
125static inline int overlay_is_active(struct planb *);
126
127/*******************************/
128/* Memory management functions */
129/*******************************/
130
131static int grabbuf_alloc(struct planb *pb)
132{
133 int i, npage;
134
135 npage = MAX_GBUFFERS * ((PLANB_MAX_FBUF / PAGE_SIZE + 1)
136#ifndef PLANB_GSCANLINE
137 + MAX_LNUM
138#endif /* PLANB_GSCANLINE */
139 );
140 if ((pb->rawbuf = kmalloc(npage
141 * sizeof(unsigned long), GFP_KERNEL)) == 0)
142 return -ENOMEM;
143 for (i = 0; i < npage; i++) {
144 pb->rawbuf[i] = (unsigned char *)__get_free_pages(GFP_KERNEL
145 |GFP_DMA, 0);
146 if (!pb->rawbuf[i])
147 break;
148 SetPageReserved(virt_to_page(pb->rawbuf[i]));
149 }
150 if (i-- < npage) {
151 printk(KERN_DEBUG "PlanB: init_grab: grab buffer not allocated\n");
152 for (; i > 0; i--) {
153 ClearPageReserved(virt_to_page(pb->rawbuf[i]));
154 free_pages((unsigned long)pb->rawbuf[i], 0);
155 }
156 kfree(pb->rawbuf);
157 return -ENOBUFS;
158 }
159 pb->rawbuf_size = npage;
160 return 0;
161}
162
163/*****************************/
164/* Hardware access functions */
165/*****************************/
166
167static void saa_write_reg(unsigned char addr, unsigned char val)
168{
169 planb_regs->saa_addr = addr; eieio();
170 planb_regs->saa_regval = val; eieio();
171 return;
172}
173
174/* return status byte 0 or 1: */
175static unsigned char saa_status(int byte, struct planb *pb)
176{
177 saa_regs[pb->win.norm][SAA7196_STDC] =
178 (saa_regs[pb->win.norm][SAA7196_STDC] & ~2) | ((byte & 1) << 1);
179 saa_write_reg (SAA7196_STDC, saa_regs[pb->win.norm][SAA7196_STDC]);
180
181 /* Let's wait 30msec for this one */
182 msleep_interruptible(30);
183
184 return (unsigned char)in_8 (&planb_regs->saa_status);
185}
186
187static void saa_set(unsigned char addr, unsigned char val, struct planb *pb)
188{
189 if(saa_regs[pb->win.norm][addr] != val) {
190 saa_regs[pb->win.norm][addr] = val;
191 saa_write_reg (addr, val);
192 }
193 return;
194}
195
196static void saa_init_regs(struct planb *pb)
197{
198 int i;
199
200 for (i = 0; i < SAA7196_NUMREGS; i++)
201 saa_write_reg (i, saa_regs[pb->win.norm][i]);
202}
203
204static unsigned int saa_geo_setup(int width, int height, int interlace, int bpp,
205 struct planb *pb)
206{
207 int ht, norm = pb->win.norm;
208
209 switch(bpp) {
210 case 2:
211 /* RGB555+a 1x16-bit + 16-bit transparent */
212 saa_regs[norm][SAA7196_FMTS] &= ~0x3;
213 break;
214 case 1:
215 case 4:
216 /* RGB888 1x24-bit + 8-bit transparent */
217 saa_regs[norm][SAA7196_FMTS] &= ~0x1;
218 saa_regs[norm][SAA7196_FMTS] |= 0x2;
219 break;
220 default:
221 return -EINVAL;
222 }
223 ht = (interlace ? height / 2 : height);
224 saa_regs[norm][SAA7196_OUTPIX] = (unsigned char) (width & 0x00ff);
225 saa_regs[norm][SAA7196_HFILT] = (saa_regs[norm][SAA7196_HFILT] & ~0x3)
226 | (width >> 8 & 0x3);
227 saa_regs[norm][SAA7196_OUTLINE] = (unsigned char) (ht & 0xff);
228 saa_regs[norm][SAA7196_VYP] = (saa_regs[norm][SAA7196_VYP] & ~0x3)
229 | (ht >> 8 & 0x3);
230 /* feed both fields if interlaced, or else feed only even fields */
231 saa_regs[norm][SAA7196_FMTS] = (interlace) ?
232 (saa_regs[norm][SAA7196_FMTS] & ~0x60)
233 : (saa_regs[norm][SAA7196_FMTS] | 0x60);
234 /* transparent mode; extended format enabled */
235 saa_regs[norm][SAA7196_DPATH] |= 0x3;
236
237 return 0;
238}
239
240/***************************/
241/* DBDMA support functions */
242/***************************/
243
244static inline void planb_dbdma_restart(volatile struct dbdma_regs *ch)
245{
246 out_le32(&ch->control, PLANB_CLR(RUN));
247 out_le32(&ch->control, PLANB_SET(RUN|WAKE) | PLANB_CLR(PAUSE));
248}
249
250static inline void planb_dbdma_stop(volatile struct dbdma_regs *ch)
251{
252 int i = 0;
253
254 out_le32(&ch->control, PLANB_CLR(RUN) | PLANB_SET(FLUSH));
255 while((in_le32(&ch->status) == (ACTIVE | FLUSH)) && (i < 999)) {
256 IDEBUG("PlanB: waiting for DMA to stop\n");
257 i++;
258 }
259}
260
261static inline void tab_cmd_dbdma(volatile struct dbdma_cmd *ch,
262 unsigned short command, unsigned int cmd_dep)
263{
264 st_le16(&ch->command, command);
265 st_le32(&ch->cmd_dep, cmd_dep);
266}
267
268static inline void tab_cmd_store(volatile struct dbdma_cmd *ch,
269 unsigned int phy_addr, unsigned int cmd_dep)
270{
271 st_le16(&ch->command, STORE_WORD | KEY_SYSTEM);
272 st_le16(&ch->req_count, 4);
273 st_le32(&ch->phy_addr, phy_addr);
274 st_le32(&ch->cmd_dep, cmd_dep);
275}
276
277static inline void tab_cmd_gen(volatile struct dbdma_cmd *ch,
278 unsigned short command, unsigned short req_count,
279 unsigned int phy_addr, unsigned int cmd_dep)
280{
281 st_le16(&ch->command, command);
282 st_le16(&ch->req_count, req_count);
283 st_le32(&ch->phy_addr, phy_addr);
284 st_le32(&ch->cmd_dep, cmd_dep);
285}
286
287static volatile struct dbdma_cmd *cmd_geo_setup(
288 volatile struct dbdma_cmd *c1, int width, int height, int interlace,
289 int bpp, int clip, struct planb *pb)
290{
291 int norm = pb->win.norm;
292
293 if((saa_geo_setup(width, height, interlace, bpp, pb)) != 0)
294 return (volatile struct dbdma_cmd *)NULL;
295 tab_cmd_store(c1++, (unsigned)(&pb->planb_base_phys->saa_addr),
296 SAA7196_FMTS);
297 tab_cmd_store(c1++, (unsigned)(&pb->planb_base_phys->saa_regval),
298 saa_regs[norm][SAA7196_FMTS]);
299 tab_cmd_store(c1++, (unsigned)(&pb->planb_base_phys->saa_addr),
300 SAA7196_DPATH);
301 tab_cmd_store(c1++, (unsigned)(&pb->planb_base_phys->saa_regval),
302 saa_regs[norm][SAA7196_DPATH]);
303 tab_cmd_store(c1++, (unsigned)(&pb->planb_base_phys->even),
304 bpp | ((clip)? PLANB_CLIPMASK: 0));
305 tab_cmd_store(c1++, (unsigned)(&pb->planb_base_phys->odd),
306 bpp | ((clip)? PLANB_CLIPMASK: 0));
307 tab_cmd_store(c1++, (unsigned)(&pb->planb_base_phys->saa_addr),
308 SAA7196_OUTPIX);
309 tab_cmd_store(c1++, (unsigned)(&pb->planb_base_phys->saa_regval),
310 saa_regs[norm][SAA7196_OUTPIX]);
311 tab_cmd_store(c1++, (unsigned)(&pb->planb_base_phys->saa_addr),
312 SAA7196_HFILT);
313 tab_cmd_store(c1++, (unsigned)(&pb->planb_base_phys->saa_regval),
314 saa_regs[norm][SAA7196_HFILT]);
315 tab_cmd_store(c1++, (unsigned)(&pb->planb_base_phys->saa_addr),
316 SAA7196_OUTLINE);
317 tab_cmd_store(c1++, (unsigned)(&pb->planb_base_phys->saa_regval),
318 saa_regs[norm][SAA7196_OUTLINE]);
319 tab_cmd_store(c1++, (unsigned)(&pb->planb_base_phys->saa_addr),
320 SAA7196_VYP);
321 tab_cmd_store(c1++, (unsigned)(&pb->planb_base_phys->saa_regval),
322 saa_regs[norm][SAA7196_VYP]);
323 return c1;
324}
325
326/******************************/
327/* misc. supporting functions */
328/******************************/
329
330static inline void planb_lock(struct planb *pb)
331{
332 mutex_lock(&pb->lock);
333}
334
335static inline void planb_unlock(struct planb *pb)
336{
337 mutex_unlock(&pb->lock);
338}
339
340/***************/
341/* Driver Core */
342/***************/
343
344static int planb_prepare_open(struct planb *pb)
345{
346 int i, size;
347
348 /* allocate memory for two plus alpha command buffers (size: max lines,
349 plus 40 commands handling, plus 1 alignment), plus dummy command buf,
350 plus clipmask buffer, plus frame grabbing status */
351 size = (pb->tab_size*(2+MAX_GBUFFERS*TAB_FACTOR)+1+MAX_GBUFFERS
352 * PLANB_DUMMY)*sizeof(struct dbdma_cmd)
353 +(PLANB_MAXLINES*((PLANB_MAXPIXELS+7)& ~7))/8
354 +MAX_GBUFFERS*sizeof(unsigned int);
355 if ((pb->priv_space = kzalloc (size, GFP_KERNEL)) == 0)
356 return -ENOMEM;
357 pb->overlay_last1 = pb->ch1_cmd = (volatile struct dbdma_cmd *)
358 DBDMA_ALIGN (pb->priv_space);
359 pb->overlay_last2 = pb->ch2_cmd = pb->ch1_cmd + pb->tab_size;
360 pb->ch1_cmd_phys = virt_to_bus(pb->ch1_cmd);
361 pb->cap_cmd[0] = pb->ch2_cmd + pb->tab_size;
362 pb->pre_cmd[0] = pb->cap_cmd[0] + pb->tab_size * TAB_FACTOR;
363 for (i = 1; i < MAX_GBUFFERS; i++) {
364 pb->cap_cmd[i] = pb->pre_cmd[i-1] + PLANB_DUMMY;
365 pb->pre_cmd[i] = pb->cap_cmd[i] + pb->tab_size * TAB_FACTOR;
366 }
367 pb->frame_stat=(volatile unsigned int *)(pb->pre_cmd[MAX_GBUFFERS-1]
368 + PLANB_DUMMY);
369 pb->mask = (unsigned char *)(pb->frame_stat+MAX_GBUFFERS);
370
371 pb->rawbuf = NULL;
372 pb->rawbuf_size = 0;
373 pb->grabbing = 0;
374 for (i = 0; i < MAX_GBUFFERS; i++) {
375 pb->frame_stat[i] = GBUFFER_UNUSED;
376 pb->gwidth[i] = 0;
377 pb->gheight[i] = 0;
378 pb->gfmt[i] = 0;
379 pb->gnorm_switch[i] = 0;
380#ifndef PLANB_GSCANLINE
381 pb->lsize[i] = 0;
382 pb->lnum[i] = 0;
383#endif /* PLANB_GSCANLINE */
384 }
385 pb->gcount = 0;
386 pb->suspend = 0;
387 pb->last_fr = -999;
388 pb->prev_last_fr = -999;
389
390 /* Reset DMA controllers */
391 planb_dbdma_stop(&pb->planb_base->ch2);
392 planb_dbdma_stop(&pb->planb_base->ch1);
393
394 return 0;
395}
396
397static void planb_prepare_close(struct planb *pb)
398{
399 int i;
400
401 /* make sure the dma's are idle */
402 planb_dbdma_stop(&pb->planb_base->ch2);
403 planb_dbdma_stop(&pb->planb_base->ch1);
404 /* free kernel memory of command buffers */
405 if(pb->priv_space != 0) {
406 kfree (pb->priv_space);
407 pb->priv_space = 0;
408 pb->cmd_buff_inited = 0;
409 }
410 if(pb->rawbuf) {
411 for (i = 0; i < pb->rawbuf_size; i++) {
412 ClearPageReserved(virt_to_page(pb->rawbuf[i]));
413 free_pages((unsigned long)pb->rawbuf[i], 0);
414 }
415 kfree(pb->rawbuf);
416 }
417 pb->rawbuf = NULL;
418}
419
420/*****************************/
421/* overlay support functions */
422/*****************************/
423
424static inline int overlay_is_active(struct planb *pb)
425{
426 unsigned int size = pb->tab_size * sizeof(struct dbdma_cmd);
427 unsigned int caddr = (unsigned)in_le32(&pb->planb_base->ch1.cmdptr);
428
429 return (in_le32(&pb->overlay_last1->cmd_dep) == pb->ch1_cmd_phys)
430 && (caddr < (pb->ch1_cmd_phys + size))
431 && (caddr >= (unsigned)pb->ch1_cmd_phys);
432}
433
434static void overlay_start(struct planb *pb)
435{
436
437 DEBUG("PlanB: overlay_start()\n");
438
439 if(ACTIVE & in_le32(&pb->planb_base->ch1.status)) {
440
441 DEBUG("PlanB: presumably, grabbing is in progress...\n");
442
443 planb_dbdma_stop(&pb->planb_base->ch2);
444 out_le32 (&pb->planb_base->ch2.cmdptr,
445 virt_to_bus(pb->ch2_cmd));
446 planb_dbdma_restart(&pb->planb_base->ch2);
447 st_le16 (&pb->ch1_cmd->command, DBDMA_NOP);
448 tab_cmd_dbdma(pb->last_cmd[pb->last_fr],
449 DBDMA_NOP | BR_ALWAYS,
450 virt_to_bus(pb->ch1_cmd));
451 eieio();
452 pb->prev_last_fr = pb->last_fr;
453 pb->last_fr = -2;
454 if(!(ACTIVE & in_le32(&pb->planb_base->ch1.status))) {
455 IDEBUG("PlanB: became inactive "
456 "in the mean time... reactivating\n");
457 planb_dbdma_stop(&pb->planb_base->ch1);
458 out_le32 (&pb->planb_base->ch1.cmdptr,
459 virt_to_bus(pb->ch1_cmd));
460 planb_dbdma_restart(&pb->planb_base->ch1);
461 }
462 } else {
463
464 DEBUG("PlanB: currently idle, so can do whatever\n");
465
466 planb_dbdma_stop(&pb->planb_base->ch2);
467 planb_dbdma_stop(&pb->planb_base->ch1);
468 st_le32 (&pb->planb_base->ch2.cmdptr,
469 virt_to_bus(pb->ch2_cmd));
470 st_le32 (&pb->planb_base->ch1.cmdptr,
471 virt_to_bus(pb->ch1_cmd));
472 out_le16 (&pb->ch1_cmd->command, DBDMA_NOP);
473 planb_dbdma_restart(&pb->planb_base->ch2);
474 planb_dbdma_restart(&pb->planb_base->ch1);
475 pb->last_fr = -1;
476 }
477 return;
478}
479
480static void overlay_stop(struct planb *pb)
481{
482 DEBUG("PlanB: overlay_stop()\n");
483
484 if(pb->last_fr == -1) {
485
486 DEBUG("PlanB: no grabbing, it seems...\n");
487
488 planb_dbdma_stop(&pb->planb_base->ch2);
489 planb_dbdma_stop(&pb->planb_base->ch1);
490 pb->last_fr = -999;
491 } else if(pb->last_fr == -2) {
492 unsigned int cmd_dep;
493 tab_cmd_dbdma(pb->cap_cmd[pb->prev_last_fr], DBDMA_STOP, 0);
494 eieio();
495 cmd_dep = (unsigned int)in_le32(&pb->overlay_last1->cmd_dep);
496 if(overlay_is_active(pb)) {
497
498 DEBUG("PlanB: overlay is currently active\n");
499
500 planb_dbdma_stop(&pb->planb_base->ch2);
501 planb_dbdma_stop(&pb->planb_base->ch1);
502 if(cmd_dep != pb->ch1_cmd_phys) {
503 out_le32(&pb->planb_base->ch1.cmdptr,
504 virt_to_bus(pb->overlay_last1));
505 planb_dbdma_restart(&pb->planb_base->ch1);
506 }
507 }
508 pb->last_fr = pb->prev_last_fr;
509 pb->prev_last_fr = -999;
510 }
511 return;
512}
513
514static void suspend_overlay(struct planb *pb)
515{
516 int fr = -1;
517 struct dbdma_cmd last;
518
519 DEBUG("PlanB: suspend_overlay: %d\n", pb->suspend);
520
521 if(pb->suspend++)
522 return;
523 if(ACTIVE & in_le32(&pb->planb_base->ch1.status)) {
524 if(pb->last_fr == -2) {
525 fr = pb->prev_last_fr;
526 memcpy(&last, (void*)pb->last_cmd[fr], sizeof(last));
527 tab_cmd_dbdma(pb->last_cmd[fr], DBDMA_STOP, 0);
528 }
529 if(overlay_is_active(pb)) {
530 planb_dbdma_stop(&pb->planb_base->ch2);
531 planb_dbdma_stop(&pb->planb_base->ch1);
532 pb->suspended.overlay = 1;
533 pb->suspended.frame = fr;
534 memcpy(&pb->suspended.cmd, &last, sizeof(last));
535 return;
536 }
537 }
538 pb->suspended.overlay = 0;
539 pb->suspended.frame = fr;
540 memcpy(&pb->suspended.cmd, &last, sizeof(last));
541 return;
542}
543
544static void resume_overlay(struct planb *pb)
545{
546
547 DEBUG("PlanB: resume_overlay: %d\n", pb->suspend);
548
549 if(pb->suspend > 1)
550 return;
551 if(pb->suspended.frame != -1) {
552 memcpy((void*)pb->last_cmd[pb->suspended.frame],
553 &pb->suspended.cmd, sizeof(pb->suspended.cmd));
554 }
555 if(ACTIVE & in_le32(&pb->planb_base->ch1.status)) {
556 goto finish;
557 }
558 if(pb->suspended.overlay) {
559
560 DEBUG("PlanB: overlay being resumed\n");
561
562 st_le16 (&pb->ch1_cmd->command, DBDMA_NOP);
563 st_le16 (&pb->ch2_cmd->command, DBDMA_NOP);
564 /* Set command buffer addresses */
565 st_le32(&pb->planb_base->ch1.cmdptr,
566 virt_to_bus(pb->overlay_last1));
567 out_le32(&pb->planb_base->ch2.cmdptr,
568 virt_to_bus(pb->overlay_last2));
569 /* Start the DMA controller */
570 out_le32 (&pb->planb_base->ch2.control,
571 PLANB_CLR(PAUSE) | PLANB_SET(RUN|WAKE));
572 out_le32 (&pb->planb_base->ch1.control,
573 PLANB_CLR(PAUSE) | PLANB_SET(RUN|WAKE));
574 } else if(pb->suspended.frame != -1) {
575 out_le32(&pb->planb_base->ch1.cmdptr,
576 virt_to_bus(pb->last_cmd[pb->suspended.frame]));
577 out_le32 (&pb->planb_base->ch1.control,
578 PLANB_CLR(PAUSE) | PLANB_SET(RUN|WAKE));
579 }
580
581finish:
582 pb->suspend--;
583 wake_up_interruptible(&pb->suspendq);
584}
585
586static void add_clip(struct planb *pb, struct video_clip *clip)
587{
588 volatile unsigned char *base;
589 int xc = clip->x, yc = clip->y;
590 int wc = clip->width, hc = clip->height;
591 int ww = pb->win.width, hw = pb->win.height;
592 int x, y, xtmp1, xtmp2;
593
594 DEBUG("PlanB: clip %dx%d+%d+%d\n", wc, hc, xc, yc);
595
596 if(xc < 0) {
597 wc += xc;
598 xc = 0;
599 }
600 if(yc < 0) {
601 hc += yc;
602 yc = 0;
603 }
604 if(xc + wc > ww)
605 wc = ww - xc;
606 if(wc <= 0) /* Nothing to do */
607 return;
608 if(yc + hc > hw)
609 hc = hw - yc;
610
611 for (y = yc; y < yc+hc; y++) {
612 xtmp1=xc>>3;
613 xtmp2=(xc+wc)>>3;
614 base = pb->mask + y*96;
615 if(xc != 0 || wc >= 8)
616 *(base + xtmp1) &= (unsigned char)(0x00ff &
617 (0xff00 >> (xc&7)));
618 for (x = xtmp1 + 1; x < xtmp2; x++) {
619 *(base + x) = 0;
620 }
621 if(xc < (ww & ~0x7))
622 *(base + xtmp2) &= (unsigned char)(0x00ff >>
623 ((xc+wc) & 7));
624 }
625
626 return;
627}
628
629static void fill_cmd_buff(struct planb *pb)
630{
631 int restore = 0;
632 volatile struct dbdma_cmd last;
633
634 DEBUG("PlanB: fill_cmd_buff()\n");
635
636 if(pb->overlay_last1 != pb->ch1_cmd) {
637 restore = 1;
638 last = *(pb->overlay_last1);
639 }
640 memset ((void *) pb->ch1_cmd, 0, 2 * pb->tab_size
641 * sizeof(struct dbdma_cmd));
642 cmd_buff (pb);
643 if(restore)
644 *(pb->overlay_last1) = last;
645 if(pb->suspended.overlay) {
646 unsigned long jump_addr = in_le32(&pb->overlay_last1->cmd_dep);
647 if(jump_addr != pb->ch1_cmd_phys) {
648 int i;
649
650 DEBUG("PlanB: adjusting ch1's jump address\n");
651
652 for(i = 0; i < MAX_GBUFFERS; i++) {
653 if(pb->need_pre_capture[i]) {
654 if(jump_addr == virt_to_bus(pb->pre_cmd[i]))
655 goto found;
656 } else {
657 if(jump_addr == virt_to_bus(pb->cap_cmd[i]))
658 goto found;
659 }
660 }
661
662 DEBUG("PlanB: not found...\n");
663
664 goto out;
665found:
666 if(pb->need_pre_capture[i])
667 out_le32(&pb->pre_cmd[i]->phy_addr,
668 virt_to_bus(pb->overlay_last1));
669 else
670 out_le32(&pb->cap_cmd[i]->phy_addr,
671 virt_to_bus(pb->overlay_last1));
672 }
673 }
674out:
675 pb->cmd_buff_inited = 1;
676
677 return;
678}
679
680static void cmd_buff(struct planb *pb)
681{
682 int i, bpp, count, nlines, stepsize, interlace;
683 unsigned long base, jump, addr_com, addr_dep;
684 volatile struct dbdma_cmd *c1 = pb->ch1_cmd;
685 volatile struct dbdma_cmd *c2 = pb->ch2_cmd;
686
687 interlace = pb->win.interlace;
688 bpp = pb->win.bpp;
689 count = (bpp * ((pb->win.x + pb->win.width > pb->win.swidth) ?
690 (pb->win.swidth - pb->win.x) : pb->win.width));
691 nlines = ((pb->win.y + pb->win.height > pb->win.sheight) ?
692 (pb->win.sheight - pb->win.y) : pb->win.height);
693
694 /* Do video in: */
695
696 /* Preamble commands: */
697 addr_com = virt_to_bus(c1);
698 addr_dep = virt_to_bus(&c1->cmd_dep);
699 tab_cmd_dbdma(c1++, DBDMA_NOP, 0);
700 jump = virt_to_bus(c1+16); /* 14 by cmd_geo_setup() and 2 for padding */
701 if((c1 = cmd_geo_setup(c1, pb->win.width, pb->win.height, interlace,
702 bpp, 1, pb)) == NULL) {
703 printk(KERN_WARNING "PlanB: encountered serious problems\n");
704 tab_cmd_dbdma(pb->ch1_cmd + 1, DBDMA_STOP, 0);
705 tab_cmd_dbdma(pb->ch2_cmd + 1, DBDMA_STOP, 0);
706 return;
707 }
708 tab_cmd_store(c1++, addr_com, (unsigned)(DBDMA_NOP | BR_ALWAYS) << 16);
709 tab_cmd_store(c1++, addr_dep, jump);
710 tab_cmd_store(c1++, (unsigned)(&pb->planb_base_phys->ch1.wait_sel),
711 PLANB_SET(FIELD_SYNC));
712 /* (1) wait for field sync to be set */
713 tab_cmd_dbdma(c1++, DBDMA_NOP | WAIT_IFCLR, 0);
714 tab_cmd_store(c1++, (unsigned)(&pb->planb_base_phys->ch1.br_sel),
715 PLANB_SET(ODD_FIELD));
716 /* wait for field sync to be cleared */
717 tab_cmd_dbdma(c1++, DBDMA_NOP | WAIT_IFSET, 0);
718 /* if not odd field, wait until field sync is set again */
719 tab_cmd_dbdma(c1, DBDMA_NOP | BR_IFSET, virt_to_bus(c1-3)); c1++;
720 /* assert ch_sync to ch2 */
721 tab_cmd_store(c1++, (unsigned)(&pb->planb_base_phys->ch2.control),
722 PLANB_SET(CH_SYNC));
723 tab_cmd_store(c1++, (unsigned)(&pb->planb_base_phys->ch1.br_sel),
724 PLANB_SET(DMA_ABORT));
725
726 base = (pb->frame_buffer_phys + pb->offset + pb->win.y * (pb->win.bpl
727 + pb->win.pad) + pb->win.x * bpp);
728
729 if (interlace) {
730 stepsize = 2;
731 jump = virt_to_bus(c1 + (nlines + 1) / 2);
732 } else {
733 stepsize = 1;
734 jump = virt_to_bus(c1 + nlines);
735 }
736
737 /* even field data: */
738 for (i=0; i < nlines; i += stepsize, c1++)
739 tab_cmd_gen(c1, INPUT_MORE | KEY_STREAM0 | BR_IFSET,
740 count, base + i * (pb->win.bpl + pb->win.pad), jump);
741
742 /* For non-interlaced, we use even fields only */
743 if (!interlace)
744 goto cmd_tab_data_end;
745
746 /* Resync to odd field */
747 /* (2) wait for field sync to be set */
748 tab_cmd_dbdma(c1++, DBDMA_NOP | WAIT_IFCLR, 0);
749 tab_cmd_store(c1++, (unsigned)(&pb->planb_base_phys->ch1.br_sel),
750 PLANB_SET(ODD_FIELD));
751 /* wait for field sync to be cleared */
752 tab_cmd_dbdma(c1++, DBDMA_NOP | WAIT_IFSET, 0);
753 /* if not odd field, wait until field sync is set again */
754 tab_cmd_dbdma(c1, DBDMA_NOP | BR_IFCLR, virt_to_bus(c1-3)); c1++;
755 /* assert ch_sync to ch2 */
756 tab_cmd_store(c1++, (unsigned)(&pb->planb_base_phys->ch2.control),
757 PLANB_SET(CH_SYNC));
758 tab_cmd_store(c1++, (unsigned)(&pb->planb_base_phys->ch1.br_sel),
759 PLANB_SET(DMA_ABORT));
760
761 /* odd field data: */
762 jump = virt_to_bus(c1 + nlines / 2);
763 for (i=1; i < nlines; i += stepsize, c1++)
764 tab_cmd_gen(c1, INPUT_MORE | KEY_STREAM0 | BR_IFSET, count,
765 base + i * (pb->win.bpl + pb->win.pad), jump);
766
767 /* And jump back to the start */
768cmd_tab_data_end:
769 pb->overlay_last1 = c1; /* keep a pointer to the last command */
770 tab_cmd_dbdma(c1, DBDMA_NOP | BR_ALWAYS, virt_to_bus(pb->ch1_cmd));
771
772 /* Clipmask command buffer */
773
774 /* Preamble commands: */
775 tab_cmd_dbdma(c2++, DBDMA_NOP, 0);
776 tab_cmd_store(c2++, (unsigned)(&pb->planb_base_phys->ch2.wait_sel),
777 PLANB_SET(CH_SYNC));
778 /* wait until ch1 asserts ch_sync */
779 tab_cmd_dbdma(c2++, DBDMA_NOP | WAIT_IFCLR, 0);
780 /* clear ch_sync asserted by ch1 */
781 tab_cmd_store(c2++, (unsigned)(&pb->planb_base_phys->ch2.control),
782 PLANB_CLR(CH_SYNC));
783 tab_cmd_store(c2++, (unsigned)(&pb->planb_base_phys->ch2.wait_sel),
784 PLANB_SET(FIELD_SYNC));
785 tab_cmd_store(c2++, (unsigned)(&pb->planb_base_phys->ch2.br_sel),
786 PLANB_SET(ODD_FIELD));
787
788 /* jump to end of even field if appropriate */
789 /* this points to (interlace)? pos. C: pos. B */
790 jump = (interlace) ? virt_to_bus(c2 + (nlines + 1) / 2 + 2):
791 virt_to_bus(c2 + nlines + 2);
792 /* if odd field, skip over to odd field clipmasking */
793 tab_cmd_dbdma(c2++, DBDMA_NOP | BR_IFSET, jump);
794
795 /* even field mask: */
796 tab_cmd_store(c2++, (unsigned)(&pb->planb_base_phys->ch2.br_sel),
797 PLANB_SET(DMA_ABORT));
798 /* this points to pos. B */
799 jump = (interlace) ? virt_to_bus(c2 + nlines + 1):
800 virt_to_bus(c2 + nlines);
801 base = virt_to_bus(pb->mask);
802 for (i=0; i < nlines; i += stepsize, c2++)
803 tab_cmd_gen(c2, OUTPUT_MORE | KEY_STREAM0 | BR_IFSET, 96,
804 base + i * 96, jump);
805
806 /* For non-interlaced, we use only even fields */
807 if(!interlace)
808 goto cmd_tab_mask_end;
809
810 /* odd field mask: */
811/* C */ tab_cmd_store(c2++, (unsigned)(&pb->planb_base_phys->ch2.br_sel),
812 PLANB_SET(DMA_ABORT));
813 /* this points to pos. B */
814 jump = virt_to_bus(c2 + nlines / 2);
815 base = virt_to_bus(pb->mask);
816 for (i=1; i < nlines; i += 2, c2++) /* abort if set */
817 tab_cmd_gen(c2, OUTPUT_MORE | KEY_STREAM0 | BR_IFSET, 96,
818 base + i * 96, jump);
819
820 /* Inform channel 1 and jump back to start */
821cmd_tab_mask_end:
822 /* ok, I just realized this is kind of flawed. */
823 /* this part is reached only after odd field clipmasking. */
824 /* wanna clean up? */
825 /* wait for field sync to be set */
826 /* corresponds to fsync (1) of ch1 */
827/* B */ tab_cmd_dbdma(c2++, DBDMA_NOP | WAIT_IFCLR, 0);
828 /* restart ch1, meant to clear any dead bit or something */
829 tab_cmd_store(c2++, (unsigned)(&pb->planb_base_phys->ch1.control),
830 PLANB_CLR(RUN));
831 tab_cmd_store(c2++, (unsigned)(&pb->planb_base_phys->ch1.control),
832 PLANB_SET(RUN));
833 pb->overlay_last2 = c2; /* keep a pointer to the last command */
834 /* start over even field clipmasking */
835 tab_cmd_dbdma(c2, DBDMA_NOP | BR_ALWAYS, virt_to_bus(pb->ch2_cmd));
836
837 eieio();
838 return;
839}
840
841/*********************************/
842/* grabdisplay support functions */
843/*********************************/
844
845static int palette2fmt[] = {
846 0,
847 PLANB_GRAY,
848 0,
849 0,
850 0,
851 PLANB_COLOUR32,
852 PLANB_COLOUR15,
853 0,
854 0,
855 0,
856 0,
857 0,
858 0,
859 0,
860 0,
861};
862
863#define PLANB_PALETTE_MAX 15
864
865static int vgrab(struct planb *pb, struct video_mmap *mp)
866{
867 unsigned int fr = mp->frame;
868 unsigned int format;
869
870 if(pb->rawbuf==NULL) {
871 int err;
872 if((err=grabbuf_alloc(pb)))
873 return err;
874 }
875
876 IDEBUG("PlanB: grab %d: %dx%d(%u)\n", pb->grabbing,
877 mp->width, mp->height, fr);
878
879 if(pb->grabbing >= MAX_GBUFFERS)
880 return -ENOBUFS;
881 if(fr > (MAX_GBUFFERS - 1) || fr < 0)
882 return -EINVAL;
883 if(mp->height <= 0 || mp->width <= 0)
884 return -EINVAL;
885 if(mp->format < 0 || mp->format >= PLANB_PALETTE_MAX)
886 return -EINVAL;
887 if((format = palette2fmt[mp->format]) == 0)
888 return -EINVAL;
889 if (mp->height * mp->width * format > PLANB_MAX_FBUF) /* format = bpp */
890 return -EINVAL;
891
892 planb_lock(pb);
893 if(mp->width != pb->gwidth[fr] || mp->height != pb->gheight[fr] ||
894 format != pb->gfmt[fr] || (pb->gnorm_switch[fr])) {
895 int i;
896#ifndef PLANB_GSCANLINE
897 unsigned int osize = pb->gwidth[fr] * pb->gheight[fr]
898 * pb->gfmt[fr];
899 unsigned int nsize = mp->width * mp->height * format;
900#endif
901
902 IDEBUG("PlanB: gwidth = %d, gheight = %d, mp->format = %u\n",
903 mp->width, mp->height, mp->format);
904
905#ifndef PLANB_GSCANLINE
906 if(pb->gnorm_switch[fr])
907 nsize = 0;
908 if (nsize < osize) {
909 for(i = pb->gbuf_idx[fr]; osize > 0; i++) {
910 memset((void *)pb->rawbuf[i], 0, PAGE_SIZE);
911 osize -= PAGE_SIZE;
912 }
913 }
914 for(i = pb->l_fr_addr_idx[fr]; i < pb->l_fr_addr_idx[fr]
915 + pb->lnum[fr]; i++)
916 memset((void *)pb->rawbuf[i], 0, PAGE_SIZE);
917#else
918/* XXX TODO */
919/*
920 if(pb->gnorm_switch[fr])
921 memset((void *)pb->gbuffer[fr], 0,
922 pb->gbytes_per_line * pb->gheight[fr]);
923 else {
924 if(mp->
925 for(i = 0; i < pb->gheight[fr]; i++) {
926 memset((void *)(pb->gbuffer[fr]
927 + pb->gbytes_per_line * i
928 }
929 }
930*/
931#endif
932 pb->gwidth[fr] = mp->width;
933 pb->gheight[fr] = mp->height;
934 pb->gfmt[fr] = format;
935 pb->last_cmd[fr] = setup_grab_cmd(fr, pb);
936 planb_pre_capture(fr, pb->gfmt[fr], pb); /* gfmt = bpp */
937 pb->need_pre_capture[fr] = 1;
938 pb->gnorm_switch[fr] = 0;
939 } else
940 pb->need_pre_capture[fr] = 0;
941 pb->frame_stat[fr] = GBUFFER_GRABBING;
942 if(!(ACTIVE & in_le32(&pb->planb_base->ch1.status))) {
943
944 IDEBUG("PlanB: ch1 inactive, initiating grabbing\n");
945
946 planb_dbdma_stop(&pb->planb_base->ch1);
947 if(pb->need_pre_capture[fr]) {
948
949 IDEBUG("PlanB: padding pre-capture sequence\n");
950
951 out_le32 (&pb->planb_base->ch1.cmdptr,
952 virt_to_bus(pb->pre_cmd[fr]));
953 } else {
954 tab_cmd_dbdma(pb->last_cmd[fr], DBDMA_STOP, 0);
955 tab_cmd_dbdma(pb->cap_cmd[fr], DBDMA_NOP, 0);
956 /* let's be on the safe side. here is not timing critical. */
957 tab_cmd_dbdma((pb->cap_cmd[fr] + 1), DBDMA_NOP, 0);
958 out_le32 (&pb->planb_base->ch1.cmdptr,
959 virt_to_bus(pb->cap_cmd[fr]));
960 }
961 planb_dbdma_restart(&pb->planb_base->ch1);
962 pb->last_fr = fr;
963 } else {
964 int i;
965
966 IDEBUG("PlanB: ch1 active, grabbing being queued\n");
967
968 if((pb->last_fr == -1) || ((pb->last_fr == -2) &&
969 overlay_is_active(pb))) {
970
971 IDEBUG("PlanB: overlay is active, grabbing defered\n");
972
973 tab_cmd_dbdma(pb->last_cmd[fr],
974 DBDMA_NOP | BR_ALWAYS,
975 virt_to_bus(pb->ch1_cmd));
976 if(pb->need_pre_capture[fr]) {
977
978 IDEBUG("PlanB: padding pre-capture sequence\n");
979
980 tab_cmd_store(pb->pre_cmd[fr],
981 virt_to_bus(&pb->overlay_last1->cmd_dep),
982 virt_to_bus(pb->ch1_cmd));
983 eieio();
984 out_le32 (&pb->overlay_last1->cmd_dep,
985 virt_to_bus(pb->pre_cmd[fr]));
986 } else {
987 tab_cmd_store(pb->cap_cmd[fr],
988 virt_to_bus(&pb->overlay_last1->cmd_dep),
989 virt_to_bus(pb->ch1_cmd));
990 tab_cmd_dbdma((pb->cap_cmd[fr] + 1),
991 DBDMA_NOP, 0);
992 eieio();
993 out_le32 (&pb->overlay_last1->cmd_dep,
994 virt_to_bus(pb->cap_cmd[fr]));
995 }
996 for(i = 0; overlay_is_active(pb) && i < 999; i++)
997 IDEBUG("PlanB: waiting for overlay done\n");
998 tab_cmd_dbdma(pb->ch1_cmd, DBDMA_NOP, 0);
999 pb->prev_last_fr = fr;
1000 pb->last_fr = -2;
1001 } else if(pb->last_fr == -2) {
1002
1003 IDEBUG("PlanB: mixed mode detected, grabbing"
1004 " will be done before activating overlay\n");
1005
1006 tab_cmd_dbdma(pb->ch1_cmd, DBDMA_NOP, 0);
1007 if(pb->need_pre_capture[fr]) {
1008
1009 IDEBUG("PlanB: padding pre-capture sequence\n");
1010
1011 tab_cmd_dbdma(pb->last_cmd[pb->prev_last_fr],
1012 DBDMA_NOP | BR_ALWAYS,
1013 virt_to_bus(pb->pre_cmd[fr]));
1014 eieio();
1015 } else {
1016 tab_cmd_dbdma(pb->cap_cmd[fr], DBDMA_NOP, 0);
1017 if(pb->gwidth[pb->prev_last_fr] !=
1018 pb->gwidth[fr]
1019 || pb->gheight[pb->prev_last_fr] !=
1020 pb->gheight[fr]
1021 || pb->gfmt[pb->prev_last_fr] !=
1022 pb->gfmt[fr])
1023 tab_cmd_dbdma((pb->cap_cmd[fr] + 1),
1024 DBDMA_NOP, 0);
1025 else
1026 tab_cmd_dbdma((pb->cap_cmd[fr] + 1),
1027 DBDMA_NOP | BR_ALWAYS,
1028 virt_to_bus(pb->cap_cmd[fr] + 16));
1029 tab_cmd_dbdma(pb->last_cmd[pb->prev_last_fr],
1030 DBDMA_NOP | BR_ALWAYS,
1031 virt_to_bus(pb->cap_cmd[fr]));
1032 eieio();
1033 }
1034 tab_cmd_dbdma(pb->last_cmd[fr],
1035 DBDMA_NOP | BR_ALWAYS,
1036 virt_to_bus(pb->ch1_cmd));
1037 eieio();
1038 pb->prev_last_fr = fr;
1039 pb->last_fr = -2;
1040 } else {
1041
1042 IDEBUG("PlanB: active grabbing session detected\n");
1043
1044 if(pb->need_pre_capture[fr]) {
1045
1046 IDEBUG("PlanB: padding pre-capture sequence\n");
1047
1048 tab_cmd_dbdma(pb->last_cmd[pb->last_fr],
1049 DBDMA_NOP | BR_ALWAYS,
1050 virt_to_bus(pb->pre_cmd[fr]));
1051 eieio();
1052 } else {
1053 tab_cmd_dbdma(pb->last_cmd[fr], DBDMA_STOP, 0);
1054 tab_cmd_dbdma(pb->cap_cmd[fr], DBDMA_NOP, 0);
1055 if(pb->gwidth[pb->last_fr] != pb->gwidth[fr]
1056 || pb->gheight[pb->last_fr] !=
1057 pb->gheight[fr]
1058 || pb->gfmt[pb->last_fr] !=
1059 pb->gfmt[fr])
1060 tab_cmd_dbdma((pb->cap_cmd[fr] + 1),
1061 DBDMA_NOP, 0);
1062 else
1063 tab_cmd_dbdma((pb->cap_cmd[fr] + 1),
1064 DBDMA_NOP | BR_ALWAYS,
1065 virt_to_bus(pb->cap_cmd[fr] + 16));
1066 tab_cmd_dbdma(pb->last_cmd[pb->last_fr],
1067 DBDMA_NOP | BR_ALWAYS,
1068 virt_to_bus(pb->cap_cmd[fr]));
1069 eieio();
1070 }
1071 pb->last_fr = fr;
1072 }
1073 if(!(ACTIVE & in_le32(&pb->planb_base->ch1.status))) {
1074
1075 IDEBUG("PlanB: became inactive in the mean time..."
1076 "reactivating\n");
1077
1078 planb_dbdma_stop(&pb->planb_base->ch1);
1079 out_le32 (&pb->planb_base->ch1.cmdptr,
1080 virt_to_bus(pb->cap_cmd[fr]));
1081 planb_dbdma_restart(&pb->planb_base->ch1);
1082 }
1083 }
1084 pb->grabbing++;
1085 planb_unlock(pb);
1086
1087 return 0;
1088}
1089
1090static void planb_pre_capture(int fr, int bpp, struct planb *pb)
1091{
1092 volatile struct dbdma_cmd *c1 = pb->pre_cmd[fr];
1093 int interlace = (pb->gheight[fr] > pb->maxlines/2)? 1: 0;
1094
1095 tab_cmd_dbdma(c1++, DBDMA_NOP, 0);
1096 if((c1 = cmd_geo_setup(c1, pb->gwidth[fr], pb->gheight[fr], interlace,
1097 bpp, 0, pb)) == NULL) {
1098 printk(KERN_WARNING "PlanB: encountered some problems\n");
1099 tab_cmd_dbdma(pb->pre_cmd[fr] + 1, DBDMA_STOP, 0);
1100 return;
1101 }
1102 /* Sync to even field */
1103 tab_cmd_store(c1++, (unsigned)(&pb->planb_base_phys->ch1.wait_sel),
1104 PLANB_SET(FIELD_SYNC));
1105 tab_cmd_dbdma(c1++, DBDMA_NOP | WAIT_IFCLR, 0);
1106 tab_cmd_store(c1++, (unsigned)(&pb->planb_base_phys->ch1.br_sel),
1107 PLANB_SET(ODD_FIELD));
1108 tab_cmd_dbdma(c1++, DBDMA_NOP | WAIT_IFSET, 0);
1109 tab_cmd_dbdma(c1, DBDMA_NOP | BR_IFSET, virt_to_bus(c1-3)); c1++;
1110 tab_cmd_dbdma(c1++, DBDMA_NOP | INTR_ALWAYS, 0);
1111 tab_cmd_store(c1++, (unsigned)(&pb->planb_base_phys->ch1.br_sel),
1112 PLANB_SET(DMA_ABORT));
1113 /* For non-interlaced, we use even fields only */
1114 if (pb->gheight[fr] <= pb->maxlines/2)
1115 goto cmd_tab_data_end;
1116 /* Sync to odd field */
1117 tab_cmd_dbdma(c1++, DBDMA_NOP | WAIT_IFCLR, 0);
1118 tab_cmd_store(c1++, (unsigned)(&pb->planb_base_phys->ch1.br_sel),
1119 PLANB_SET(ODD_FIELD));
1120 tab_cmd_dbdma(c1++, DBDMA_NOP | WAIT_IFSET, 0);
1121 tab_cmd_dbdma(c1, DBDMA_NOP | BR_IFCLR, virt_to_bus(c1-3)); c1++;
1122 tab_cmd_store(c1++, (unsigned)(&pb->planb_base_phys->ch1.br_sel),
1123 PLANB_SET(DMA_ABORT));
1124cmd_tab_data_end:
1125 tab_cmd_dbdma(c1, DBDMA_NOP | BR_ALWAYS, virt_to_bus(pb->cap_cmd[fr]));
1126
1127 eieio();
1128}
1129
1130static volatile struct dbdma_cmd *setup_grab_cmd(int fr, struct planb *pb)
1131{
1132 int i, bpp, count, nlines, stepsize, interlace;
1133#ifdef PLANB_GSCANLINE
1134 int scanline;
1135#else
1136 int nlpp, leftover1;
1137 unsigned long base;
1138#endif
1139 unsigned long jump;
1140 int pagei;
1141 volatile struct dbdma_cmd *c1;
1142 volatile struct dbdma_cmd *jump_addr;
1143
1144 c1 = pb->cap_cmd[fr];
1145 interlace = (pb->gheight[fr] > pb->maxlines/2)? 1: 0;
1146 bpp = pb->gfmt[fr]; /* gfmt = bpp */
1147 count = bpp * pb->gwidth[fr];
1148 nlines = pb->gheight[fr];
1149#ifdef PLANB_GSCANLINE
1150 scanline = pb->gbytes_per_line;
1151#else
1152 pb->lsize[fr] = count;
1153 pb->lnum[fr] = 0;
1154#endif
1155
1156 /* Do video in: */
1157
1158 /* Preamble commands: */
1159 tab_cmd_dbdma(c1++, DBDMA_NOP, 0);
1160 tab_cmd_dbdma(c1, DBDMA_NOP | BR_ALWAYS, virt_to_bus(c1 + 16)); c1++;
1161 if((c1 = cmd_geo_setup(c1, pb->gwidth[fr], pb->gheight[fr], interlace,
1162 bpp, 0, pb)) == NULL) {
1163 printk(KERN_WARNING "PlanB: encountered serious problems\n");
1164 tab_cmd_dbdma(pb->cap_cmd[fr] + 1, DBDMA_STOP, 0);
1165 return (pb->cap_cmd[fr] + 2);
1166 }
1167 tab_cmd_store(c1++, (unsigned)(&pb->planb_base_phys->ch1.wait_sel),
1168 PLANB_SET(FIELD_SYNC));
1169 tab_cmd_dbdma(c1++, DBDMA_NOP | WAIT_IFCLR, 0);
1170 tab_cmd_store(c1++, (unsigned)(&pb->planb_base_phys->ch1.br_sel),
1171 PLANB_SET(ODD_FIELD));
1172 tab_cmd_dbdma(c1++, DBDMA_NOP | WAIT_IFSET, 0);
1173 tab_cmd_dbdma(c1, DBDMA_NOP | BR_IFSET, virt_to_bus(c1-3)); c1++;
1174 tab_cmd_dbdma(c1++, DBDMA_NOP | INTR_ALWAYS, 0);
1175 tab_cmd_store(c1++, (unsigned)(&pb->planb_base_phys->ch1.br_sel),
1176 PLANB_SET(DMA_ABORT));
1177
1178 if (interlace) {
1179 stepsize = 2;
1180 jump_addr = c1 + TAB_FACTOR * (nlines + 1) / 2;
1181 } else {
1182 stepsize = 1;
1183 jump_addr = c1 + TAB_FACTOR * nlines;
1184 }
1185 jump = virt_to_bus(jump_addr);
1186
1187 /* even field data: */
1188
1189 pagei = pb->gbuf_idx[fr];
1190#ifdef PLANB_GSCANLINE
1191 for (i = 0; i < nlines; i += stepsize) {
1192 tab_cmd_gen(c1++, INPUT_MORE | BR_IFSET, count,
1193 virt_to_bus(pb->rawbuf[pagei
1194 + i * scanline / PAGE_SIZE]), jump);
1195 }
1196#else
1197 i = 0;
1198 leftover1 = 0;
1199 do {
1200 int j;
1201
1202 base = virt_to_bus(pb->rawbuf[pagei]);
1203 nlpp = (PAGE_SIZE - leftover1) / count / stepsize;
1204 for(j = 0; j < nlpp && i < nlines; j++, i += stepsize, c1++)
1205 tab_cmd_gen(c1, INPUT_MORE | KEY_STREAM0 | BR_IFSET,
1206 count, base + count * j * stepsize + leftover1, jump);
1207 if(i < nlines) {
1208 int lov0 = PAGE_SIZE - count * nlpp * stepsize - leftover1;
1209
1210 if(lov0 == 0)
1211 leftover1 = 0;
1212 else {
1213 if(lov0 >= count) {
1214 tab_cmd_gen(c1++, INPUT_MORE | BR_IFSET, count, base
1215 + count * nlpp * stepsize + leftover1, jump);
1216 } else {
1217 pb->l_to_addr[fr][pb->lnum[fr]] = pb->rawbuf[pagei]
1218 + count * nlpp * stepsize + leftover1;
1219 pb->l_to_next_idx[fr][pb->lnum[fr]] = pagei + 1;
1220 pb->l_to_next_size[fr][pb->lnum[fr]] = count - lov0;
1221 tab_cmd_gen(c1++, INPUT_MORE | BR_IFSET, count,
1222 virt_to_bus(pb->rawbuf[pb->l_fr_addr_idx[fr]
1223 + pb->lnum[fr]]), jump);
1224 if(++pb->lnum[fr] > MAX_LNUM)
1225 pb->lnum[fr]--;
1226 }
1227 leftover1 = count * stepsize - lov0;
1228 i += stepsize;
1229 }
1230 }
1231 pagei++;
1232 } while(i < nlines);
1233 tab_cmd_dbdma(c1, DBDMA_NOP | BR_ALWAYS, jump);
1234 c1 = jump_addr;
1235#endif /* PLANB_GSCANLINE */
1236
1237 /* For non-interlaced, we use even fields only */
1238 if (!interlace)
1239 goto cmd_tab_data_end;
1240
1241 /* Sync to odd field */
1242 tab_cmd_dbdma(c1++, DBDMA_NOP | WAIT_IFCLR, 0);
1243 tab_cmd_store(c1++, (unsigned)(&pb->planb_base_phys->ch1.br_sel),
1244 PLANB_SET(ODD_FIELD));
1245 tab_cmd_dbdma(c1++, DBDMA_NOP | WAIT_IFSET, 0);
1246 tab_cmd_dbdma(c1, DBDMA_NOP | BR_IFCLR, virt_to_bus(c1-3)); c1++;
1247 tab_cmd_store(c1++, (unsigned)(&pb->planb_base_phys->ch1.br_sel),
1248 PLANB_SET(DMA_ABORT));
1249
1250 /* odd field data: */
1251 jump_addr = c1 + TAB_FACTOR * nlines / 2;
1252 jump = virt_to_bus(jump_addr);
1253#ifdef PLANB_GSCANLINE
1254 for (i = 1; i < nlines; i += stepsize) {
1255 tab_cmd_gen(c1++, INPUT_MORE | BR_IFSET, count,
1256 virt_to_bus(pb->rawbuf[pagei
1257 + i * scanline / PAGE_SIZE]), jump);
1258 }
1259#else
1260 i = 1;
1261 leftover1 = 0;
1262 pagei = pb->gbuf_idx[fr];
1263 if(nlines <= 1)
1264 goto skip;
1265 do {
1266 int j;
1267
1268 base = virt_to_bus(pb->rawbuf[pagei]);
1269 nlpp = (PAGE_SIZE - leftover1) / count / stepsize;
1270 if(leftover1 >= count) {
1271 tab_cmd_gen(c1++, INPUT_MORE | KEY_STREAM0 | BR_IFSET, count,
1272 base + leftover1 - count, jump);
1273 i += stepsize;
1274 }
1275 for(j = 0; j < nlpp && i < nlines; j++, i += stepsize, c1++)
1276 tab_cmd_gen(c1, INPUT_MORE | KEY_STREAM0 | BR_IFSET, count,
1277 base + count * (j * stepsize + 1) + leftover1, jump);
1278 if(i < nlines) {
1279 int lov0 = PAGE_SIZE - count * nlpp * stepsize - leftover1;
1280
1281 if(lov0 == 0)
1282 leftover1 = 0;
1283 else {
1284 if(lov0 > count) {
1285 pb->l_to_addr[fr][pb->lnum[fr]] = pb->rawbuf[pagei]
1286 + count * (nlpp * stepsize + 1) + leftover1;
1287 pb->l_to_next_idx[fr][pb->lnum[fr]] = pagei + 1;
1288 pb->l_to_next_size[fr][pb->lnum[fr]] = count * stepsize
1289 - lov0;
1290 tab_cmd_gen(c1++, INPUT_MORE | BR_IFSET, count,
1291 virt_to_bus(pb->rawbuf[pb->l_fr_addr_idx[fr]
1292 + pb->lnum[fr]]), jump);
1293 if(++pb->lnum[fr] > MAX_LNUM)
1294 pb->lnum[fr]--;
1295 i += stepsize;
1296 }
1297 leftover1 = count * stepsize - lov0;
1298 }
1299 }
1300 pagei++;
1301 } while(i < nlines);
1302skip:
1303 tab_cmd_dbdma(c1, DBDMA_NOP | BR_ALWAYS, jump);
1304 c1 = jump_addr;
1305#endif /* PLANB_GSCANLINE */
1306
1307cmd_tab_data_end:
1308 tab_cmd_store(c1++, (unsigned)(&pb->planb_base_phys->intr_stat),
1309 (fr << 9) | PLANB_FRM_IRQ | PLANB_GEN_IRQ);
1310 /* stop it */
1311 tab_cmd_dbdma(c1, DBDMA_STOP, 0);
1312
1313 eieio();
1314 return c1;
1315}
1316
1317static irqreturn_t planb_irq(int irq, void *dev_id)
1318{
1319 unsigned int stat, astat;
1320 struct planb *pb = (struct planb *)dev_id;
1321
1322 IDEBUG("PlanB: planb_irq()\n");
1323
1324 /* get/clear interrupt status bits */
1325 eieio();
1326 stat = in_le32(&pb->planb_base->intr_stat);
1327 astat = stat & pb->intr_mask;
1328 out_le32(&pb->planb_base->intr_stat, PLANB_FRM_IRQ
1329 & ~astat & stat & ~PLANB_GEN_IRQ);
1330 IDEBUG("PlanB: stat = %X, astat = %X\n", stat, astat);
1331
1332 if(astat & PLANB_FRM_IRQ) {
1333 unsigned int fr = stat >> 9;
1334#ifndef PLANB_GSCANLINE
1335 int i;
1336#endif
1337 IDEBUG("PlanB: PLANB_FRM_IRQ\n");
1338
1339 pb->gcount++;
1340
1341 IDEBUG("PlanB: grab %d: fr = %d, gcount = %d\n",
1342 pb->grabbing, fr, pb->gcount);
1343#ifndef PLANB_GSCANLINE
1344 IDEBUG("PlanB: %d * %d bytes are being copied over\n",
1345 pb->lnum[fr], pb->lsize[fr]);
1346 for(i = 0; i < pb->lnum[fr]; i++) {
1347 int first = pb->lsize[fr] - pb->l_to_next_size[fr][i];
1348
1349 memcpy(pb->l_to_addr[fr][i],
1350 pb->rawbuf[pb->l_fr_addr_idx[fr] + i],
1351 first);
1352 memcpy(pb->rawbuf[pb->l_to_next_idx[fr][i]],
1353 pb->rawbuf[pb->l_fr_addr_idx[fr] + i] + first,
1354 pb->l_to_next_size[fr][i]);
1355 }
1356#endif
1357 pb->frame_stat[fr] = GBUFFER_DONE;
1358 pb->grabbing--;
1359 wake_up_interruptible(&pb->capq);
1360 return IRQ_HANDLED;
1361 }
1362 /* incorrect interrupts? */
1363 pb->intr_mask = PLANB_CLR_IRQ;
1364 out_le32(&pb->planb_base->intr_stat, PLANB_CLR_IRQ);
1365 printk(KERN_ERR "PlanB: IRQ lockup, cleared intrrupts"
1366 " unconditionally\n");
1367 return IRQ_HANDLED;
1368}
1369
1370/*******************************
1371 * Device Operations functions *
1372 *******************************/
1373
1374static int planb_open(struct video_device *dev, int mode)
1375{
1376 struct planb *pb = (struct planb *)dev;
1377
1378 if (pb->user == 0) {
1379 int err;
1380 if((err = planb_prepare_open(pb)) != 0)
1381 return err;
1382 }
1383 pb->user++;
1384
1385 DEBUG("PlanB: device opened\n");
1386 return 0;
1387}
1388
1389static void planb_close(struct video_device *dev)
1390{
1391 struct planb *pb = (struct planb *)dev;
1392
1393 if(pb->user < 1) /* ??? */
1394 return;
1395 planb_lock(pb);
1396 if (pb->user == 1) {
1397 if (pb->overlay) {
1398 planb_dbdma_stop(&pb->planb_base->ch2);
1399 planb_dbdma_stop(&pb->planb_base->ch1);
1400 pb->overlay = 0;
1401 }
1402 planb_prepare_close(pb);
1403 }
1404 pb->user--;
1405 planb_unlock(pb);
1406
1407 DEBUG("PlanB: device closed\n");
1408}
1409
1410static long planb_read(struct video_device *v, char *buf, unsigned long count,
1411 int nonblock)
1412{
1413 DEBUG("planb: read request\n");
1414 return -EINVAL;
1415}
1416
1417static long planb_write(struct video_device *v, const char *buf,
1418 unsigned long count, int nonblock)
1419{
1420 DEBUG("planb: write request\n");
1421 return -EINVAL;
1422}
1423
1424static int planb_ioctl(struct video_device *dev, unsigned int cmd, void *arg)
1425{
1426 struct planb *pb=(struct planb *)dev;
1427
1428 switch (cmd)
1429 {
1430 case VIDIOCGCAP:
1431 {
1432 struct video_capability b;
1433
1434 DEBUG("PlanB: IOCTL VIDIOCGCAP\n");
1435
1436 strcpy (b.name, pb->video_dev.name);
1437 b.type = VID_TYPE_OVERLAY | VID_TYPE_CLIPPING |
1438 VID_TYPE_FRAMERAM | VID_TYPE_SCALES |
1439 VID_TYPE_CAPTURE;
1440 b.channels = 2; /* composite & svhs */
1441 b.audios = 0;
1442 b.maxwidth = PLANB_MAXPIXELS;
1443 b.maxheight = PLANB_MAXLINES;
1444 b.minwidth = 32; /* wild guess */
1445 b.minheight = 32;
1446 if (copy_to_user(arg,&b,sizeof(b)))
1447 return -EFAULT;
1448 return 0;
1449 }
1450 case VIDIOCSFBUF:
1451 {
1452 struct video_buffer v;
1453 unsigned short bpp;
1454 unsigned int fmt;
1455
1456 DEBUG("PlanB: IOCTL VIDIOCSFBUF\n");
1457
1458 if (!capable(CAP_SYS_ADMIN)
1459 || !capable(CAP_SYS_RAWIO))
1460 return -EPERM;
1461 if (copy_from_user(&v, arg,sizeof(v)))
1462 return -EFAULT;
1463 planb_lock(pb);
1464 switch(v.depth) {
1465 case 8:
1466 bpp = 1;
1467 fmt = PLANB_GRAY;
1468 break;
1469 case 15:
1470 case 16:
1471 bpp = 2;
1472 fmt = PLANB_COLOUR15;
1473 break;
1474 case 24:
1475 case 32:
1476 bpp = 4;
1477 fmt = PLANB_COLOUR32;
1478 break;
1479 default:
1480 planb_unlock(pb);
1481 return -EINVAL;
1482 }
1483 if (bpp * v.width > v.bytesperline) {
1484 planb_unlock(pb);
1485 return -EINVAL;
1486 }
1487 pb->win.bpp = bpp;
1488 pb->win.color_fmt = fmt;
1489 pb->frame_buffer_phys = (unsigned long) v.base;
1490 pb->win.sheight = v.height;
1491 pb->win.swidth = v.width;
1492 pb->picture.depth = pb->win.depth = v.depth;
1493 pb->win.bpl = pb->win.bpp * pb->win.swidth;
1494 pb->win.pad = v.bytesperline - pb->win.bpl;
1495
1496 DEBUG("PlanB: Display at %p is %d by %d, bytedepth %d,"
1497 " bpl %d (+ %d)\n", v.base, v.width,v.height,
1498 pb->win.bpp, pb->win.bpl, pb->win.pad);
1499
1500 pb->cmd_buff_inited = 0;
1501 if(pb->overlay) {
1502 suspend_overlay(pb);
1503 fill_cmd_buff(pb);
1504 resume_overlay(pb);
1505 }
1506 planb_unlock(pb);
1507 return 0;
1508 }
1509 case VIDIOCGFBUF:
1510 {
1511 struct video_buffer v;
1512
1513 DEBUG("PlanB: IOCTL VIDIOCGFBUF\n");
1514
1515 v.base = (void *)pb->frame_buffer_phys;
1516 v.height = pb->win.sheight;
1517 v.width = pb->win.swidth;
1518 v.depth = pb->win.depth;
1519 v.bytesperline = pb->win.bpl + pb->win.pad;
1520 if (copy_to_user(arg, &v, sizeof(v)))
1521 return -EFAULT;
1522 return 0;
1523 }
1524 case VIDIOCCAPTURE:
1525 {
1526 int i;
1527
1528 if(copy_from_user(&i, arg, sizeof(i)))
1529 return -EFAULT;
1530 if(i==0) {
1531 DEBUG("PlanB: IOCTL VIDIOCCAPTURE Stop\n");
1532
1533 if (!(pb->overlay))
1534 return 0;
1535 planb_lock(pb);
1536 pb->overlay = 0;
1537 overlay_stop(pb);
1538 planb_unlock(pb);
1539 } else {
1540 DEBUG("PlanB: IOCTL VIDIOCCAPTURE Start\n");
1541
1542 if (pb->frame_buffer_phys == 0 ||
1543 pb->win.width == 0 ||
1544 pb->win.height == 0)
1545 return -EINVAL;
1546 if (pb->overlay)
1547 return 0;
1548 planb_lock(pb);
1549 pb->overlay = 1;
1550 if(!(pb->cmd_buff_inited))
1551 fill_cmd_buff(pb);
1552 overlay_start(pb);
1553 planb_unlock(pb);
1554 }
1555 return 0;
1556 }
1557 case VIDIOCGCHAN:
1558 {
1559 struct video_channel v;
1560
1561 DEBUG("PlanB: IOCTL VIDIOCGCHAN\n");
1562
1563 if(copy_from_user(&v, arg,sizeof(v)))
1564 return -EFAULT;
1565 v.flags = 0;
1566 v.tuners = 0;
1567 v.type = VIDEO_TYPE_CAMERA;
1568 v.norm = pb->win.norm;
1569 switch(v.channel)
1570 {
1571 case 0:
1572 strcpy(v.name,"Composite");
1573 break;
1574 case 1:
1575 strcpy(v.name,"SVHS");
1576 break;
1577 default:
1578 return -EINVAL;
1579 break;
1580 }
1581 if(copy_to_user(arg,&v,sizeof(v)))
1582 return -EFAULT;
1583
1584 return 0;
1585 }
1586 case VIDIOCSCHAN:
1587 {
1588 struct video_channel v;
1589
1590 DEBUG("PlanB: IOCTL VIDIOCSCHAN\n");
1591
1592 if(copy_from_user(&v, arg, sizeof(v)))
1593 return -EFAULT;
1594
1595 if (v.norm != pb->win.norm) {
1596 int i, maxlines;
1597
1598 switch (v.norm)
1599 {
1600 case VIDEO_MODE_PAL:
1601 case VIDEO_MODE_SECAM:
1602 maxlines = PLANB_MAXLINES;
1603 break;
1604 case VIDEO_MODE_NTSC:
1605 maxlines = PLANB_NTSC_MAXLINES;
1606 break;
1607 default:
1608 return -EINVAL;
1609 break;
1610 }
1611 planb_lock(pb);
1612 /* empty the grabbing queue */
1613 wait_event(pb->capq, !pb->grabbing);
1614 pb->maxlines = maxlines;
1615 pb->win.norm = v.norm;
1616 /* Stop overlay if running */
1617 suspend_overlay(pb);
1618 for(i = 0; i < MAX_GBUFFERS; i++)
1619 pb->gnorm_switch[i] = 1;
1620 /* I know it's an overkill, but.... */
1621 fill_cmd_buff(pb);
1622 /* ok, now init it accordingly */
1623 saa_init_regs (pb);
1624 /* restart overlay if it was running */
1625 resume_overlay(pb);
1626 planb_unlock(pb);
1627 }
1628
1629 switch(v.channel)
1630 {
1631 case 0: /* Composite */
1632 saa_set (SAA7196_IOCC,
1633 ((saa_regs[pb->win.norm][SAA7196_IOCC] &
1634 ~7) | 3), pb);
1635 break;
1636 case 1: /* SVHS */
1637 saa_set (SAA7196_IOCC,
1638 ((saa_regs[pb->win.norm][SAA7196_IOCC] &
1639 ~7) | 4), pb);
1640 break;
1641 default:
1642 return -EINVAL;
1643 break;
1644 }
1645
1646 return 0;
1647 }
1648 case VIDIOCGPICT:
1649 {
1650 struct video_picture vp = pb->picture;
1651
1652 DEBUG("PlanB: IOCTL VIDIOCGPICT\n");
1653
1654 switch(pb->win.color_fmt) {
1655 case PLANB_GRAY:
1656 vp.palette = VIDEO_PALETTE_GREY;
1657 case PLANB_COLOUR15:
1658 vp.palette = VIDEO_PALETTE_RGB555;
1659 break;
1660 case PLANB_COLOUR32:
1661 vp.palette = VIDEO_PALETTE_RGB32;
1662 break;
1663 default:
1664 vp.palette = 0;
1665 break;
1666 }
1667
1668 if(copy_to_user(arg,&vp,sizeof(vp)))
1669 return -EFAULT;
1670 return 0;
1671 }
1672 case VIDIOCSPICT:
1673 {
1674 struct video_picture vp;
1675
1676 DEBUG("PlanB: IOCTL VIDIOCSPICT\n");
1677
1678 if(copy_from_user(&vp,arg,sizeof(vp)))
1679 return -EFAULT;
1680 pb->picture = vp;
1681 /* Should we do sanity checks here? */
1682 saa_set (SAA7196_BRIG, (unsigned char)
1683 ((pb->picture.brightness) >> 8), pb);
1684 saa_set (SAA7196_HUEC, (unsigned char)
1685 ((pb->picture.hue) >> 8) ^ 0x80, pb);
1686 saa_set (SAA7196_CSAT, (unsigned char)
1687 ((pb->picture.colour) >> 9), pb);
1688 saa_set (SAA7196_CONT, (unsigned char)
1689 ((pb->picture.contrast) >> 9), pb);
1690
1691 return 0;
1692 }
1693 case VIDIOCSWIN:
1694 {
1695 struct video_window vw;
1696 struct video_clip clip;
1697 int i;
1698
1699 DEBUG("PlanB: IOCTL VIDIOCSWIN\n");
1700
1701 if(copy_from_user(&vw,arg,sizeof(vw)))
1702 return -EFAULT;
1703
1704 planb_lock(pb);
1705 /* Stop overlay if running */
1706 suspend_overlay(pb);
1707 pb->win.interlace = (vw.height > pb->maxlines/2)? 1: 0;
1708 if (pb->win.x != vw.x ||
1709 pb->win.y != vw.y ||
1710 pb->win.width != vw.width ||
1711 pb->win.height != vw.height ||
1712 !pb->cmd_buff_inited) {
1713 pb->win.x = vw.x;
1714 pb->win.y = vw.y;
1715 pb->win.width = vw.width;
1716 pb->win.height = vw.height;
1717 fill_cmd_buff(pb);
1718 }
1719 /* Reset clip mask */
1720 memset ((void *) pb->mask, 0xff, (pb->maxlines
1721 * ((PLANB_MAXPIXELS + 7) & ~7)) / 8);
1722 /* Add any clip rects */
1723 for (i = 0; i < vw.clipcount; i++) {
1724 if (copy_from_user(&clip, vw.clips + i,
1725 sizeof(struct video_clip)))
1726 return -EFAULT;
1727 add_clip(pb, &clip);
1728 }
1729 /* restart overlay if it was running */
1730 resume_overlay(pb);
1731 planb_unlock(pb);
1732 return 0;
1733 }
1734 case VIDIOCGWIN:
1735 {
1736 struct video_window vw;
1737
1738 DEBUG("PlanB: IOCTL VIDIOCGWIN\n");
1739
1740 vw.x=pb->win.x;
1741 vw.y=pb->win.y;
1742 vw.width=pb->win.width;
1743 vw.height=pb->win.height;
1744 vw.chromakey=0;
1745 vw.flags=0;
1746 if(pb->win.interlace)
1747 vw.flags|=VIDEO_WINDOW_INTERLACE;
1748 if(copy_to_user(arg,&vw,sizeof(vw)))
1749 return -EFAULT;
1750 return 0;
1751 }
1752 case VIDIOCSYNC: {
1753 int i;
1754
1755 IDEBUG("PlanB: IOCTL VIDIOCSYNC\n");
1756
1757 if(copy_from_user((void *)&i,arg,sizeof(int)))
1758 return -EFAULT;
1759
1760 IDEBUG("PlanB: sync to frame %d\n", i);
1761
1762 if(i > (MAX_GBUFFERS - 1) || i < 0)
1763 return -EINVAL;
1764chk_grab:
1765 switch (pb->frame_stat[i]) {
1766 case GBUFFER_UNUSED:
1767 return -EINVAL;
1768 case GBUFFER_GRABBING:
1769 IDEBUG("PlanB: waiting for grab"
1770 " done (%d)\n", i);
1771 interruptible_sleep_on(&pb->capq);
1772 if(signal_pending(current))
1773 return -EINTR;
1774 goto chk_grab;
1775 case GBUFFER_DONE:
1776 pb->frame_stat[i] = GBUFFER_UNUSED;
1777 break;
1778 }
1779 return 0;
1780 }
1781
1782 case VIDIOCMCAPTURE:
1783 {
1784 struct video_mmap vm;
1785 volatile unsigned int status;
1786
1787 IDEBUG("PlanB: IOCTL VIDIOCMCAPTURE\n");
1788
1789 if(copy_from_user((void *) &vm,(void *)arg,sizeof(vm)))
1790 return -EFAULT;
1791 status = pb->frame_stat[vm.frame];
1792 if (status != GBUFFER_UNUSED)
1793 return -EBUSY;
1794
1795 return vgrab(pb, &vm);
1796 }
1797
1798 case VIDIOCGMBUF:
1799 {
1800 int i;
1801 struct video_mbuf vm;
1802
1803 DEBUG("PlanB: IOCTL VIDIOCGMBUF\n");
1804
1805 memset(&vm, 0 , sizeof(vm));
1806 vm.size = PLANB_MAX_FBUF * MAX_GBUFFERS;
1807 vm.frames = MAX_GBUFFERS;
1808 for(i = 0; i<MAX_GBUFFERS; i++)
1809 vm.offsets[i] = PLANB_MAX_FBUF * i;
1810 if(copy_to_user((void *)arg, (void *)&vm, sizeof(vm)))
1811 return -EFAULT;
1812 return 0;
1813 }
1814
1815 case PLANBIOCGSAAREGS:
1816 {
1817 struct planb_saa_regs preg;
1818
1819 DEBUG("PlanB: IOCTL PLANBIOCGSAAREGS\n");
1820
1821 if(copy_from_user(&preg, arg, sizeof(preg)))
1822 return -EFAULT;
1823 if(preg.addr >= SAA7196_NUMREGS)
1824 return -EINVAL;
1825 preg.val = saa_regs[pb->win.norm][preg.addr];
1826 if(copy_to_user((void *)arg, (void *)&preg,
1827 sizeof(preg)))
1828 return -EFAULT;
1829 return 0;
1830 }
1831
1832 case PLANBIOCSSAAREGS:
1833 {
1834 struct planb_saa_regs preg;
1835
1836 DEBUG("PlanB: IOCTL PLANBIOCSSAAREGS\n");
1837
1838 if(copy_from_user(&preg, arg, sizeof(preg)))
1839 return -EFAULT;
1840 if(preg.addr >= SAA7196_NUMREGS)
1841 return -EINVAL;
1842 saa_set (preg.addr, preg.val, pb);
1843 return 0;
1844 }
1845
1846 case PLANBIOCGSTAT:
1847 {
1848 struct planb_stat_regs pstat;
1849
1850 DEBUG("PlanB: IOCTL PLANBIOCGSTAT\n");
1851
1852 pstat.ch1_stat = in_le32(&pb->planb_base->ch1.status);
1853 pstat.ch2_stat = in_le32(&pb->planb_base->ch2.status);
1854 pstat.saa_stat0 = saa_status(0, pb);
1855 pstat.saa_stat1 = saa_status(1, pb);
1856
1857 if(copy_to_user((void *)arg, (void *)&pstat,
1858 sizeof(pstat)))
1859 return -EFAULT;
1860 return 0;
1861 }
1862
1863 case PLANBIOCSMODE: {
1864 int v;
1865
1866 DEBUG("PlanB: IOCTL PLANBIOCSMODE\n");
1867
1868 if(copy_from_user(&v, arg, sizeof(v)))
1869 return -EFAULT;
1870
1871 switch(v)
1872 {
1873 case PLANB_TV_MODE:
1874 saa_set (SAA7196_STDC,
1875 (saa_regs[pb->win.norm][SAA7196_STDC] &
1876 0x7f), pb);
1877 break;
1878 case PLANB_VTR_MODE:
1879 saa_set (SAA7196_STDC,
1880 (saa_regs[pb->win.norm][SAA7196_STDC] |
1881 0x80), pb);
1882 break;
1883 default:
1884 return -EINVAL;
1885 break;
1886 }
1887 pb->win.mode = v;
1888 return 0;
1889 }
1890 case PLANBIOCGMODE: {
1891 int v=pb->win.mode;
1892
1893 DEBUG("PlanB: IOCTL PLANBIOCGMODE\n");
1894
1895 if(copy_to_user(arg,&v,sizeof(v)))
1896 return -EFAULT;
1897 return 0;
1898 }
1899#ifdef PLANB_GSCANLINE
1900 case PLANBG_GRAB_BPL: {
1901 int v=pb->gbytes_per_line;
1902
1903 DEBUG("PlanB: IOCTL PLANBG_GRAB_BPL\n");
1904
1905 if(copy_to_user(arg,&v,sizeof(v)))
1906 return -EFAULT;
1907 return 0;
1908 }
1909#endif /* PLANB_GSCANLINE */
1910 case PLANB_INTR_DEBUG: {
1911 int i;
1912
1913 DEBUG("PlanB: IOCTL PLANB_INTR_DEBUG\n");
1914
1915 if(copy_from_user(&i, arg, sizeof(i)))
1916 return -EFAULT;
1917
1918 /* avoid hang ups all together */
1919 for (i = 0; i < MAX_GBUFFERS; i++) {
1920 if(pb->frame_stat[i] == GBUFFER_GRABBING) {
1921 pb->frame_stat[i] = GBUFFER_DONE;
1922 }
1923 }
1924 if(pb->grabbing)
1925 pb->grabbing--;
1926 wake_up_interruptible(&pb->capq);
1927 return 0;
1928 }
1929 case PLANB_INV_REGS: {
1930 int i;
1931 struct planb_any_regs any;
1932
1933 DEBUG("PlanB: IOCTL PLANB_INV_REGS\n");
1934
1935 if(copy_from_user(&any, arg, sizeof(any)))
1936 return -EFAULT;
1937 if(any.offset < 0 || any.offset + any.bytes > 0x400)
1938 return -EINVAL;
1939 if(any.bytes > 128)
1940 return -EINVAL;
1941 for (i = 0; i < any.bytes; i++) {
1942 any.data[i] =
1943 in_8((unsigned char *)pb->planb_base
1944 + any.offset + i);
1945 }
1946 if(copy_to_user(arg,&any,sizeof(any)))
1947 return -EFAULT;
1948 return 0;
1949 }
1950 default:
1951 {
1952 DEBUG("PlanB: Unimplemented IOCTL\n");
1953 return -ENOIOCTLCMD;
1954 }
1955 /* Some IOCTLs are currently unsupported on PlanB */
1956 case VIDIOCGTUNER: {
1957 DEBUG("PlanB: IOCTL VIDIOCGTUNER\n");
1958 goto unimplemented; }
1959 case VIDIOCSTUNER: {
1960 DEBUG("PlanB: IOCTL VIDIOCSTUNER\n");
1961 goto unimplemented; }
1962 case VIDIOCSFREQ: {
1963 DEBUG("PlanB: IOCTL VIDIOCSFREQ\n");
1964 goto unimplemented; }
1965 case VIDIOCGFREQ: {
1966 DEBUG("PlanB: IOCTL VIDIOCGFREQ\n");
1967 goto unimplemented; }
1968 case VIDIOCKEY: {
1969 DEBUG("PlanB: IOCTL VIDIOCKEY\n");
1970 goto unimplemented; }
1971 case VIDIOCSAUDIO: {
1972 DEBUG("PlanB: IOCTL VIDIOCSAUDIO\n");
1973 goto unimplemented; }
1974 case VIDIOCGAUDIO: {
1975 DEBUG("PlanB: IOCTL VIDIOCGAUDIO\n");
1976 goto unimplemented; }
1977unimplemented:
1978 DEBUG(" Unimplemented\n");
1979 return -ENOIOCTLCMD;
1980 }
1981 return 0;
1982}
1983
1984static int planb_mmap(struct vm_area_struct *vma, struct video_device *dev, const char *adr, unsigned long size)
1985{
1986 int i;
1987 struct planb *pb = (struct planb *)dev;
1988 unsigned long start = (unsigned long)adr;
1989
1990 if (size > MAX_GBUFFERS * PLANB_MAX_FBUF)
1991 return -EINVAL;
1992 if (!pb->rawbuf) {
1993 int err;
1994 if((err=grabbuf_alloc(pb)))
1995 return err;
1996 }
1997 for (i = 0; i < pb->rawbuf_size; i++) {
1998 unsigned long pfn;
1999
2000 pfn = virt_to_phys((void *)pb->rawbuf[i]) >> PAGE_SHIFT;
2001 if (remap_pfn_range(vma, start, pfn, PAGE_SIZE, PAGE_SHARED))
2002 return -EAGAIN;
2003 start += PAGE_SIZE;
2004 if (size <= PAGE_SIZE)
2005 break;
2006 size -= PAGE_SIZE;
2007 }
2008 return 0;
2009}
2010
2011static struct video_device planb_template=
2012{
2013 .owner = THIS_MODULE,
2014 .name = PLANB_DEVICE_NAME,
2015 .type = VID_TYPE_OVERLAY,
2016 .open = planb_open,
2017 .close = planb_close,
2018 .read = planb_read,
2019 .write = planb_write,
2020 .ioctl = planb_ioctl,
2021 .mmap = planb_mmap, /* mmap? */
2022};
2023
2024static int init_planb(struct planb *pb)
2025{
2026 unsigned char saa_rev;
2027 int i, result;
2028
2029 memset ((void *) &pb->win, 0, sizeof (struct planb_window));
2030 /* Simple sanity check */
2031 if(def_norm >= NUM_SUPPORTED_NORM || def_norm < 0) {
2032 printk(KERN_ERR "PlanB: Option(s) invalid\n");
2033 return -2;
2034 }
2035 pb->win.norm = def_norm;
2036 pb->win.mode = PLANB_TV_MODE; /* TV mode */
2037 pb->win.interlace=1;
2038 pb->win.x=0;
2039 pb->win.y=0;
2040 pb->win.width=768; /* 640 */
2041 pb->win.height=576; /* 480 */
2042 pb->maxlines=576;
2043#if 0
2044 btv->win.cropwidth=768; /* 640 */
2045 btv->win.cropheight=576; /* 480 */
2046 btv->win.cropx=0;
2047 btv->win.cropy=0;
2048#endif
2049 pb->win.pad=0;
2050 pb->win.bpp=4;
2051 pb->win.depth=32;
2052 pb->win.color_fmt=PLANB_COLOUR32;
2053 pb->win.bpl=1024*pb->win.bpp;
2054 pb->win.swidth=1024;
2055 pb->win.sheight=768;
2056#ifdef PLANB_GSCANLINE
2057 if((pb->gbytes_per_line = PLANB_MAXPIXELS * 4) > PAGE_SIZE
2058 || (pb->gbytes_per_line <= 0))
2059 return -3;
2060 else {
2061 /* page align pb->gbytes_per_line for DMA purpose */
2062 for(i = PAGE_SIZE; pb->gbytes_per_line < (i>>1);)
2063 i>>=1;
2064 pb->gbytes_per_line = i;
2065 }
2066#endif
2067 pb->tab_size = PLANB_MAXLINES + 40;
2068 pb->suspend = 0;
2069 mutex_init(&pb->lock);
2070 pb->ch1_cmd = 0;
2071 pb->ch2_cmd = 0;
2072 pb->mask = 0;
2073 pb->priv_space = 0;
2074 pb->offset = 0;
2075 pb->user = 0;
2076 pb->overlay = 0;
2077 init_waitqueue_head(&pb->suspendq);
2078 pb->cmd_buff_inited = 0;
2079 pb->frame_buffer_phys = 0;
2080
2081 /* Reset DMA controllers */
2082 planb_dbdma_stop(&pb->planb_base->ch2);
2083 planb_dbdma_stop(&pb->planb_base->ch1);
2084
2085 saa_rev = (saa_status(0, pb) & 0xf0) >> 4;
2086 printk(KERN_INFO "PlanB: SAA7196 video processor rev. %d\n", saa_rev);
2087 /* Initialize the SAA registers in memory and on chip */
2088 saa_init_regs (pb);
2089
2090 /* clear interrupt mask */
2091 pb->intr_mask = PLANB_CLR_IRQ;
2092
2093 result = request_irq(pb->irq, planb_irq, 0, "PlanB", pb);
2094 if (result < 0) {
2095 if (result==-EINVAL)
2096 printk(KERN_ERR "PlanB: Bad irq number (%d) "
2097 "or handler\n", (int)pb->irq);
2098 else if (result==-EBUSY)
2099 printk(KERN_ERR "PlanB: I don't know why, "
2100 "but IRQ %d is busy\n", (int)pb->irq);
2101 return result;
2102 }
2103 disable_irq(pb->irq);
2104
2105 /* Now add the template and register the device unit. */
2106 memcpy(&pb->video_dev,&planb_template,sizeof(planb_template));
2107
2108 pb->picture.brightness=0x90<<8;
2109 pb->picture.contrast = 0x70 << 8;
2110 pb->picture.colour = 0x70<<8;
2111 pb->picture.hue = 0x8000;
2112 pb->picture.whiteness = 0;
2113 pb->picture.depth = pb->win.depth;
2114
2115 pb->frame_stat=NULL;
2116 init_waitqueue_head(&pb->capq);
2117 for(i=0; i<MAX_GBUFFERS; i++) {
2118 pb->gbuf_idx[i] = PLANB_MAX_FBUF * i / PAGE_SIZE;
2119 pb->gwidth[i]=0;
2120 pb->gheight[i]=0;
2121 pb->gfmt[i]=0;
2122 pb->cap_cmd[i]=NULL;
2123#ifndef PLANB_GSCANLINE
2124 pb->l_fr_addr_idx[i] = MAX_GBUFFERS * (PLANB_MAX_FBUF
2125 / PAGE_SIZE + 1) + MAX_LNUM * i;
2126 pb->lsize[i] = 0;
2127 pb->lnum[i] = 0;
2128#endif
2129 }
2130 pb->rawbuf=NULL;
2131 pb->grabbing=0;
2132
2133 /* enable interrupts */
2134 out_le32(&pb->planb_base->intr_stat, PLANB_CLR_IRQ);
2135 pb->intr_mask = PLANB_FRM_IRQ;
2136 enable_irq(pb->irq);
2137
2138 if(video_register_device(&pb->video_dev, VFL_TYPE_GRABBER, video_nr)<0)
2139 return -1;
2140
2141 return 0;
2142}
2143
2144/*
2145 * Scan for a PlanB controller, request the irq and map the io memory
2146 */
2147
2148static int find_planb(void)
2149{
2150 struct planb *pb;
2151 struct device_node *planb_devices;
2152 unsigned char dev_fn, confreg, bus;
2153 unsigned int old_base, new_base;
2154 unsigned int irq;
2155 struct pci_dev *pdev;
2156 int rc;
2157
2158 if (!machine_is(powermac))
2159 return 0;
2160
2161 planb_devices = of_find_node_by_name(NULL, "planb");
2162 if (planb_devices == 0) {
2163 planb_num=0;
2164 printk(KERN_WARNING "PlanB: no device found!\n");
2165 return planb_num;
2166 }
2167
2168 if (planb_devices->next != NULL)
2169 printk(KERN_ERR "Warning: only using first PlanB device!\n");
2170 pb = &planbs[0];
2171 planb_num = 1;
2172
2173 if (planb_devices->n_addrs != 1) {
2174 printk (KERN_WARNING "PlanB: expecting 1 address for planb "
2175 "(got %d)", planb_devices->n_addrs);
2176 of_node_put(planb_devices);
2177 return 0;
2178 }
2179
2180 if (planb_devices->n_intrs == 0) {
2181 printk(KERN_WARNING "PlanB: no intrs for device %s\n",
2182 planb_devices->full_name);
2183 of_node_put(planb_devices);
2184 return 0;
2185 } else {
2186 irq = planb_devices->intrs[0].line;
2187 }
2188
2189 /* Initialize PlanB's PCI registers */
2190
2191 /* There is a bug with the way OF assigns addresses
2192 to the devices behind the chaos bridge.
2193 control needs only 0x1000 of space, but decodes only
2194 the upper 16 bits. It therefore occupies a full 64K.
2195 OF assigns the planb controller memory within this space;
2196 so we need to change that here in order to access planb. */
2197
2198 /* We remap to 0xf1000000 in hope that nobody uses it ! */
2199
2200 bus = (planb_devices->addrs[0].space >> 16) & 0xff;
2201 dev_fn = (planb_devices->addrs[0].space >> 8) & 0xff;
2202 confreg = planb_devices->addrs[0].space & 0xff;
2203 old_base = planb_devices->addrs[0].address;
2204 new_base = 0xf1000000;
2205 of_node_put(planb_devices);
2206
2207 DEBUG("PlanB: Found on bus %d, dev %d, func %d, "
2208 "membase 0x%x (base reg. 0x%x)\n",
2209 bus, PCI_SLOT(dev_fn), PCI_FUNC(dev_fn), old_base, confreg);
2210
2211 pdev = pci_get_bus_and_slot(bus, dev_fn);
2212 if (!pdev) {
2213 printk(KERN_ERR "planb: cannot find slot\n");
2214 goto err_out;
2215 }
2216
2217 /* Enable response in memory space, bus mastering,
2218 use memory write and invalidate */
2219 rc = pci_enable_device(pdev);
2220 if (rc) {
2221 printk(KERN_ERR "planb: cannot enable PCI device %s\n",
2222 pci_name(pdev));
2223 goto err_out;
2224 }
2225 rc = pci_set_mwi(pdev);
2226 if (rc) {
2227 printk(KERN_ERR "planb: cannot enable MWI on PCI device %s\n",
2228 pci_name(pdev));
2229 goto err_out_disable;
2230 }
2231 pci_set_master(pdev);
2232
2233 /* Set the new base address */
2234 pci_write_config_dword (pdev, confreg, new_base);
2235
2236 planb_regs = (volatile struct planb_registers *)
2237 ioremap (new_base, 0x400);
2238 pb->planb_base = planb_regs;
2239 pb->planb_base_phys = (struct planb_registers *)new_base;
2240 pb->irq = irq;
2241 pb->dev = pdev;
2242
2243 return planb_num;
2244
2245err_out_disable:
2246 pci_disable_device(pdev);
2247err_out:
2248 /* FIXME handle error */ /* comment moved from pci_find_slot, above */
2249 pci_dev_put(pdev);
2250 return 0;
2251}
2252
2253static void release_planb(void)
2254{
2255 int i;
2256 struct planb *pb;
2257
2258 for (i=0;i<planb_num; i++)
2259 {
2260 pb=&planbs[i];
2261
2262 /* stop and flash DMAs unconditionally */
2263 planb_dbdma_stop(&pb->planb_base->ch2);
2264 planb_dbdma_stop(&pb->planb_base->ch1);
2265
2266 /* clear and free interrupts */
2267 pb->intr_mask = PLANB_CLR_IRQ;
2268 out_le32 (&pb->planb_base->intr_stat, PLANB_CLR_IRQ);
2269 free_irq(pb->irq, pb);
2270
2271 /* make sure all allocated memory are freed */
2272 planb_prepare_close(pb);
2273
2274 printk(KERN_INFO "PlanB: unregistering with v4l\n");
2275 video_unregister_device(&pb->video_dev);
2276
2277 pci_dev_put(pb->dev);
2278
2279 /* note that iounmap() does nothing on the PPC right now */
2280 iounmap ((void *)pb->planb_base);
2281 }
2282}
2283
2284static int __init init_planbs(void)
2285{
2286 int i;
2287
2288 if (find_planb()<=0)
2289 return -EIO;
2290
2291 for (i=0; i<planb_num; i++) {
2292 if (init_planb(&planbs[i])<0) {
2293 printk(KERN_ERR "PlanB: error registering device %d"
2294 " with v4l\n", i);
2295 release_planb();
2296 return -EIO;
2297 }
2298 printk(KERN_INFO "PlanB: registered device %d with v4l\n", i);
2299 }
2300 return 0;
2301}
2302
2303static void __exit exit_planbs(void)
2304{
2305 release_planb();
2306}
2307
2308module_init(init_planbs);
2309module_exit(exit_planbs);
diff --git a/drivers/media/video/planb.h b/drivers/media/video/planb.h
index e21b5735c103..e69de29bb2d1 100644
--- a/drivers/media/video/planb.h
+++ b/drivers/media/video/planb.h
@@ -1,232 +0,0 @@
1/*
2 planb - PlanB frame grabber driver
3
4 PlanB is used in the 7x00/8x00 series of PowerMacintosh
5 Computers as video input DMA controller.
6
7 Copyright (C) 1998 Michel Lanners (mlan@cpu.lu)
8
9 Based largely on the bttv driver by Ralph Metzler (rjkm@thp.uni-koeln.de)
10
11 Additional debugging and coding by Takashi Oe (toe@unlserve.unl.edu)
12
13
14 This program is free software; you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation; either version 2 of the License, or
17 (at your option) any later version.
18
19 This program is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU General Public License for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with this program; if not, write to the Free Software
26 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27*/
28
29/* $Id: planb.h,v 1.13 1999/05/03 19:28:56 mlan Exp $ */
30
31#ifndef _PLANB_H_
32#define _PLANB_H_
33
34#ifdef __KERNEL__
35#include <asm/dbdma.h>
36#include "saa7196.h"
37#endif /* __KERNEL__ */
38
39#define PLANB_DEVICE_NAME "Apple PlanB Video-In"
40#define PLANB_REV "1.0"
41
42#ifdef __KERNEL__
43//#define PLANB_GSCANLINE /* use this if apps have the notion of */
44 /* grab buffer scanline */
45/* This should be safe for both PAL and NTSC */
46#define PLANB_MAXPIXELS 768
47#define PLANB_MAXLINES 576
48#define PLANB_NTSC_MAXLINES 480
49
50/* Uncomment your preferred norm ;-) */
51#define PLANB_DEF_NORM VIDEO_MODE_PAL
52//#define PLANB_DEF_NORM VIDEO_MODE_NTSC
53//#define PLANB_DEF_NORM VIDEO_MODE_SECAM
54
55/* fields settings */
56#define PLANB_GRAY 0x1 /* 8-bit mono? */
57#define PLANB_COLOUR15 0x2 /* 16-bit mode */
58#define PLANB_COLOUR32 0x4 /* 32-bit mode */
59#define PLANB_CLIPMASK 0x8 /* hardware clipmasking */
60
61/* misc. flags for PlanB DMA operation */
62#define CH_SYNC 0x1 /* synchronize channels (set by ch1;
63 cleared by ch2) */
64#define FIELD_SYNC 0x2 /* used for the start of each field
65 (0 -> 1 -> 0 for ch1; 0 -> 1 for ch2) */
66#define EVEN_FIELD 0x0 /* even field is detected if unset */
67#define DMA_ABORT 0x2 /* error or just out of sync if set */
68#define ODD_FIELD 0x4 /* odd field is detected if set */
69
70/* for capture operations */
71#define MAX_GBUFFERS 2
72/* note PLANB_MAX_FBUF must be divisible by PAGE_SIZE */
73#ifdef PLANB_GSCANLINE
74#define PLANB_MAX_FBUF 0x240000 /* 576 * 1024 * 4 */
75#define TAB_FACTOR (1)
76#else
77#define PLANB_MAX_FBUF 0x1b0000 /* 576 * 768 * 4 */
78#define TAB_FACTOR (2)
79#endif
80#endif /* __KERNEL__ */
81
82struct planb_saa_regs {
83 unsigned char addr;
84 unsigned char val;
85};
86
87struct planb_stat_regs {
88 unsigned int ch1_stat;
89 unsigned int ch2_stat;
90 unsigned char saa_stat0;
91 unsigned char saa_stat1;
92};
93
94struct planb_any_regs {
95 unsigned int offset;
96 unsigned int bytes;
97 unsigned char data[128];
98};
99
100/* planb private ioctls */
101#define PLANBIOCGSAAREGS _IOWR('v', BASE_VIDIOCPRIVATE, struct planb_saa_regs) /* Read a saa7196 reg value */
102#define PLANBIOCSSAAREGS _IOW('v', BASE_VIDIOCPRIVATE + 1, struct planb_saa_regs) /* Set a saa7196 reg value */
103#define PLANBIOCGSTAT _IOR('v', BASE_VIDIOCPRIVATE + 2, struct planb_stat_regs) /* Read planb status */
104#define PLANB_TV_MODE 1
105#define PLANB_VTR_MODE 2
106#define PLANBIOCGMODE _IOR('v', BASE_VIDIOCPRIVATE + 3, int) /* Get TV/VTR mode */
107#define PLANBIOCSMODE _IOW('v', BASE_VIDIOCPRIVATE + 4, int) /* Set TV/VTR mode */
108
109#ifdef PLANB_GSCANLINE
110#define PLANBG_GRAB_BPL _IOR('v', BASE_VIDIOCPRIVATE + 5, int) /* # of bytes per scanline in grab buffer */
111#endif
112
113/* call wake_up_interruptible() with appropriate actions */
114#define PLANB_INTR_DEBUG _IOW('v', BASE_VIDIOCPRIVATE + 20, int)
115/* investigate which reg does what */
116#define PLANB_INV_REGS _IOWR('v', BASE_VIDIOCPRIVATE + 21, struct planb_any_regs)
117
118#ifdef __KERNEL__
119
120/* Potentially useful macros */
121#define PLANB_SET(x) ((x) << 16 | (x))
122#define PLANB_CLR(x) ((x) << 16)
123
124/* This represents the physical register layout */
125struct planb_registers {
126 volatile struct dbdma_regs ch1; /* 0x00: video in */
127 volatile unsigned int even; /* 0x40: even field setting */
128 volatile unsigned int odd; /* 0x44; odd field setting */
129 unsigned int pad1[14]; /* empty? */
130 volatile struct dbdma_regs ch2; /* 0x80: clipmask out */
131 unsigned int pad2[16]; /* 0xc0: empty? */
132 volatile unsigned int reg3; /* 0x100: ???? */
133 volatile unsigned int intr_stat; /* 0x104: irq status */
134#define PLANB_CLR_IRQ 0x00 /* clear Plan B interrupt */
135#define PLANB_GEN_IRQ 0x01 /* assert Plan B interrupt */
136#define PLANB_FRM_IRQ 0x0100 /* end of frame */
137 unsigned int pad3[1]; /* empty? */
138 volatile unsigned int reg5; /* 0x10c: ??? */
139 unsigned int pad4[60]; /* empty? */
140 volatile unsigned char saa_addr; /* 0x200: SAA subadr */
141 char pad5[3];
142 volatile unsigned char saa_regval; /* SAA7196 write reg. val */
143 char pad6[3];
144 volatile unsigned char saa_status; /* SAA7196 status byte */
145 /* There is more unused stuff here */
146};
147
148struct planb_window {
149 int x, y;
150 ushort width, height;
151 ushort bpp, bpl, depth, pad;
152 ushort swidth, sheight;
153 int norm;
154 int interlace;
155 u32 color_fmt;
156 int chromakey;
157 int mode; /* used to switch between TV/VTR modes */
158};
159
160struct planb_suspend {
161 int overlay;
162 int frame;
163 struct dbdma_cmd cmd;
164};
165
166struct planb {
167 struct video_device video_dev;
168 struct video_picture picture; /* Current picture params */
169 struct video_audio audio_dev; /* Current audio params */
170
171 volatile struct planb_registers *planb_base; /* virt base of planb */
172 struct planb_registers *planb_base_phys; /* phys base of planb */
173 void *priv_space; /* Org. alloc. mem for kfree */
174 int user;
175 unsigned int tab_size;
176 int maxlines;
177 struct mutex lock;
178 unsigned int irq; /* interrupt number */
179 volatile unsigned int intr_mask;
180 struct pci_dev *dev; /* Our PCI device */
181
182 int overlay; /* overlay running? */
183 struct planb_window win;
184 unsigned long frame_buffer_phys; /* We need phys for DMA */
185 int offset; /* offset of pixel 1 */
186 volatile struct dbdma_cmd *ch1_cmd; /* Video In DMA cmd buffer */
187 volatile struct dbdma_cmd *ch2_cmd; /* Clip Out DMA cmd buffer */
188 volatile struct dbdma_cmd *overlay_last1;
189 volatile struct dbdma_cmd *overlay_last2;
190 unsigned long ch1_cmd_phys;
191 volatile unsigned char *mask; /* Clipmask buffer */
192 int suspend;
193 wait_queue_head_t suspendq;
194 struct planb_suspend suspended;
195 int cmd_buff_inited; /* cmd buffer inited? */
196
197 int grabbing;
198 unsigned int gcount;
199 wait_queue_head_t capq;
200 int last_fr;
201 int prev_last_fr;
202 unsigned char **rawbuf;
203 int rawbuf_size;
204 int gbuf_idx[MAX_GBUFFERS];
205 volatile struct dbdma_cmd *cap_cmd[MAX_GBUFFERS];
206 volatile struct dbdma_cmd *last_cmd[MAX_GBUFFERS];
207 volatile struct dbdma_cmd *pre_cmd[MAX_GBUFFERS];
208 int need_pre_capture[MAX_GBUFFERS];
209#define PLANB_DUMMY 40 /* # of command buf's allocated for pre-capture seq. */
210 int gwidth[MAX_GBUFFERS], gheight[MAX_GBUFFERS];
211 unsigned int gfmt[MAX_GBUFFERS];
212 int gnorm_switch[MAX_GBUFFERS];
213 volatile unsigned int *frame_stat;
214#define GBUFFER_UNUSED 0x00U
215#define GBUFFER_GRABBING 0x01U
216#define GBUFFER_DONE 0x02U
217#ifdef PLANB_GSCANLINE
218 int gbytes_per_line;
219#else
220#define MAX_LNUM 431 /* change this if PLANB_MAXLINES or */
221 /* PLANB_MAXPIXELS changes */
222 int l_fr_addr_idx[MAX_GBUFFERS];
223 unsigned char *l_to_addr[MAX_GBUFFERS][MAX_LNUM];
224 int l_to_next_idx[MAX_GBUFFERS][MAX_LNUM];
225 int l_to_next_size[MAX_GBUFFERS][MAX_LNUM];
226 int lsize[MAX_GBUFFERS], lnum[MAX_GBUFFERS];
227#endif
228};
229
230#endif /* __KERNEL__ */
231
232#endif /* _PLANB_H_ */
diff --git a/drivers/media/video/pms.c b/drivers/media/video/pms.c
index 51b1461d8fb6..00425d743656 100644
--- a/drivers/media/video/pms.c
+++ b/drivers/media/video/pms.c
@@ -30,6 +30,7 @@
30#include <asm/io.h> 30#include <asm/io.h>
31#include <linux/videodev.h> 31#include <linux/videodev.h>
32#include <media/v4l2-common.h> 32#include <media/v4l2-common.h>
33#include <media/v4l2-ioctl.h>
33#include <linux/mutex.h> 34#include <linux/mutex.h>
34 35
35#include <asm/uaccess.h> 36#include <asm/uaccess.h>
@@ -894,9 +895,7 @@ static const struct file_operations pms_fops = {
894 895
895static struct video_device pms_template= 896static struct video_device pms_template=
896{ 897{
897 .owner = THIS_MODULE,
898 .name = "Mediavision PMS", 898 .name = "Mediavision PMS",
899 .type = VID_TYPE_CAPTURE,
900 .fops = &pms_fops, 899 .fops = &pms_fops,
901}; 900};
902 901
diff --git a/drivers/media/video/pvrusb2/Kconfig b/drivers/media/video/pvrusb2/Kconfig
index 4482b2c72ced..19eb274c9cd0 100644
--- a/drivers/media/video/pvrusb2/Kconfig
+++ b/drivers/media/video/pvrusb2/Kconfig
@@ -2,8 +2,6 @@ config VIDEO_PVRUSB2
2 tristate "Hauppauge WinTV-PVR USB2 support" 2 tristate "Hauppauge WinTV-PVR USB2 support"
3 depends on VIDEO_V4L2 && I2C 3 depends on VIDEO_V4L2 && I2C
4 depends on VIDEO_MEDIA # Avoids pvrusb = Y / DVB = M 4 depends on VIDEO_MEDIA # Avoids pvrusb = Y / DVB = M
5 depends on HOTPLUG # due to FW_LOADER
6 select FW_LOADER
7 select VIDEO_TUNER 5 select VIDEO_TUNER
8 select VIDEO_TVEEPROM 6 select VIDEO_TVEEPROM
9 select VIDEO_CX2341X 7 select VIDEO_CX2341X
diff --git a/drivers/media/video/pvrusb2/pvrusb2-context.h b/drivers/media/video/pvrusb2/pvrusb2-context.h
index 61801291c2af..d657e53bbfa3 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-context.h
+++ b/drivers/media/video/pvrusb2/pvrusb2-context.h
@@ -16,8 +16,8 @@
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 * 17 *
18 */ 18 */
19#ifndef __PVRUSB2_BASE_H 19#ifndef __PVRUSB2_CONTEXT_H
20#define __PVRUSB2_BASE_H 20#define __PVRUSB2_CONTEXT_H
21 21
22#include <linux/mutex.h> 22#include <linux/mutex.h>
23#include <linux/usb.h> 23#include <linux/usb.h>
diff --git a/drivers/media/video/pvrusb2/pvrusb2-devattr.c b/drivers/media/video/pvrusb2/pvrusb2-devattr.c
index 5d036e7e3f07..88e175168438 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-devattr.c
+++ b/drivers/media/video/pvrusb2/pvrusb2-devattr.c
@@ -97,13 +97,13 @@ static const struct pvr2_device_desc pvr2_device_24xxx = {
97 .flag_has_cx25840 = !0, 97 .flag_has_cx25840 = !0,
98 .flag_has_wm8775 = !0, 98 .flag_has_wm8775 = !0,
99 .flag_has_hauppauge_rom = !0, 99 .flag_has_hauppauge_rom = !0,
100 .flag_has_hauppauge_custom_ir = !0,
101 .flag_has_analogtuner = !0, 100 .flag_has_analogtuner = !0,
102 .flag_has_fmradio = !0, 101 .flag_has_fmradio = !0,
103 .flag_has_composite = !0, 102 .flag_has_composite = !0,
104 .flag_has_svideo = !0, 103 .flag_has_svideo = !0,
105 .signal_routing_scheme = PVR2_ROUTING_SCHEME_HAUPPAUGE, 104 .signal_routing_scheme = PVR2_ROUTING_SCHEME_HAUPPAUGE,
106 .led_scheme = PVR2_LED_SCHEME_HAUPPAUGE, 105 .led_scheme = PVR2_LED_SCHEME_HAUPPAUGE,
106 .ir_scheme = PVR2_IR_SCHEME_24XXX,
107}; 107};
108 108
109 109
@@ -330,7 +330,7 @@ static const char *pvr2_fw1_names_73xxx[] = {
330}; 330};
331 331
332static const struct pvr2_device_desc pvr2_device_73xxx = { 332static const struct pvr2_device_desc pvr2_device_73xxx = {
333 .description = "WinTV PVR USB2 Model Category 73xxx", 333 .description = "WinTV HVR-1900 Model Category 73xxx",
334 .shortname = "73xxx", 334 .shortname = "73xxx",
335 .client_modules.lst = pvr2_client_73xxx, 335 .client_modules.lst = pvr2_client_73xxx,
336 .client_modules.cnt = ARRAY_SIZE(pvr2_client_73xxx), 336 .client_modules.cnt = ARRAY_SIZE(pvr2_client_73xxx),
@@ -344,6 +344,7 @@ static const struct pvr2_device_desc pvr2_device_73xxx = {
344 .signal_routing_scheme = PVR2_ROUTING_SCHEME_HAUPPAUGE, 344 .signal_routing_scheme = PVR2_ROUTING_SCHEME_HAUPPAUGE,
345 .digital_control_scheme = PVR2_DIGITAL_SCHEME_HAUPPAUGE, 345 .digital_control_scheme = PVR2_DIGITAL_SCHEME_HAUPPAUGE,
346 .led_scheme = PVR2_LED_SCHEME_HAUPPAUGE, 346 .led_scheme = PVR2_LED_SCHEME_HAUPPAUGE,
347 .ir_scheme = PVR2_IR_SCHEME_ZILOG,
347#ifdef CONFIG_VIDEO_PVRUSB2_DVB 348#ifdef CONFIG_VIDEO_PVRUSB2_DVB
348 .dvb_props = &pvr2_73xxx_dvb_props, 349 .dvb_props = &pvr2_73xxx_dvb_props,
349#endif 350#endif
@@ -438,7 +439,7 @@ static const char *pvr2_fw1_names_75xxx[] = {
438}; 439};
439 440
440static const struct pvr2_device_desc pvr2_device_750xx = { 441static const struct pvr2_device_desc pvr2_device_750xx = {
441 .description = "WinTV PVR USB2 Model Category 750xx", 442 .description = "WinTV HVR-1950 Model Category 750xx",
442 .shortname = "750xx", 443 .shortname = "750xx",
443 .client_modules.lst = pvr2_client_75xxx, 444 .client_modules.lst = pvr2_client_75xxx,
444 .client_modules.cnt = ARRAY_SIZE(pvr2_client_75xxx), 445 .client_modules.cnt = ARRAY_SIZE(pvr2_client_75xxx),
@@ -453,13 +454,14 @@ static const struct pvr2_device_desc pvr2_device_750xx = {
453 .digital_control_scheme = PVR2_DIGITAL_SCHEME_HAUPPAUGE, 454 .digital_control_scheme = PVR2_DIGITAL_SCHEME_HAUPPAUGE,
454 .default_std_mask = V4L2_STD_NTSC_M, 455 .default_std_mask = V4L2_STD_NTSC_M,
455 .led_scheme = PVR2_LED_SCHEME_HAUPPAUGE, 456 .led_scheme = PVR2_LED_SCHEME_HAUPPAUGE,
457 .ir_scheme = PVR2_IR_SCHEME_ZILOG,
456#ifdef CONFIG_VIDEO_PVRUSB2_DVB 458#ifdef CONFIG_VIDEO_PVRUSB2_DVB
457 .dvb_props = &pvr2_750xx_dvb_props, 459 .dvb_props = &pvr2_750xx_dvb_props,
458#endif 460#endif
459}; 461};
460 462
461static const struct pvr2_device_desc pvr2_device_751xx = { 463static const struct pvr2_device_desc pvr2_device_751xx = {
462 .description = "WinTV PVR USB2 Model Category 751xx", 464 .description = "WinTV HVR-1950 Model Category 751xx",
463 .shortname = "751xx", 465 .shortname = "751xx",
464 .client_modules.lst = pvr2_client_75xxx, 466 .client_modules.lst = pvr2_client_75xxx,
465 .client_modules.cnt = ARRAY_SIZE(pvr2_client_75xxx), 467 .client_modules.cnt = ARRAY_SIZE(pvr2_client_75xxx),
@@ -474,6 +476,7 @@ static const struct pvr2_device_desc pvr2_device_751xx = {
474 .digital_control_scheme = PVR2_DIGITAL_SCHEME_HAUPPAUGE, 476 .digital_control_scheme = PVR2_DIGITAL_SCHEME_HAUPPAUGE,
475 .default_std_mask = V4L2_STD_NTSC_M, 477 .default_std_mask = V4L2_STD_NTSC_M,
476 .led_scheme = PVR2_LED_SCHEME_HAUPPAUGE, 478 .led_scheme = PVR2_LED_SCHEME_HAUPPAUGE,
479 .ir_scheme = PVR2_IR_SCHEME_ZILOG,
477#ifdef CONFIG_VIDEO_PVRUSB2_DVB 480#ifdef CONFIG_VIDEO_PVRUSB2_DVB
478 .dvb_props = &pvr2_751xx_dvb_props, 481 .dvb_props = &pvr2_751xx_dvb_props,
479#endif 482#endif
diff --git a/drivers/media/video/pvrusb2/pvrusb2-devattr.h b/drivers/media/video/pvrusb2/pvrusb2-devattr.h
index e23ce1d2edd7..cb3a33eb0276 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-devattr.h
+++ b/drivers/media/video/pvrusb2/pvrusb2-devattr.h
@@ -48,6 +48,10 @@ struct pvr2_string_table {
48#define PVR2_LED_SCHEME_NONE 0 48#define PVR2_LED_SCHEME_NONE 0
49#define PVR2_LED_SCHEME_HAUPPAUGE 1 49#define PVR2_LED_SCHEME_HAUPPAUGE 1
50 50
51#define PVR2_IR_SCHEME_NONE 0
52#define PVR2_IR_SCHEME_24XXX 1
53#define PVR2_IR_SCHEME_ZILOG 2
54
51/* This describes a particular hardware type (except for the USB device ID 55/* This describes a particular hardware type (except for the USB device ID
52 which must live in a separate structure due to environmental 56 which must live in a separate structure due to environmental
53 constraints). See the top of pvrusb2-hdw.c for where this is 57 constraints). See the top of pvrusb2-hdw.c for where this is
@@ -126,15 +130,19 @@ struct pvr2_device_desc {
126 ensure that it is found. */ 130 ensure that it is found. */
127 unsigned int flag_has_wm8775:1; 131 unsigned int flag_has_wm8775:1;
128 132
129 /* Device has IR hardware that can be faked into looking like a 133 /* Indicate any specialized IR scheme that might need to be
130 normal Hauppauge i2c IR receiver. This is currently very 134 supported by this driver. If not set, then it is assumed that
131 specific to the 24xxx device, where Hauppauge had replaced their 135 IR can work without help from the driver (which is frequently
132 'standard' I2C IR receiver with a bunch of FPGA logic controlled 136 the case). This is otherwise set to one of
133 directly via the FX2. Turning this on tells the pvrusb2 driver 137 PVR2_IR_SCHEME_xxxx. For "xxxx", the value "24XXX" indicates a
134 to virtualize the presence of the non-existant IR receiver chip and 138 Hauppauge 24xxx class device which has an FPGA-hosted IR
135 implement the virtual receiver in terms of appropriate FX2 139 receiver that can only be reached via FX2 command codes. In
136 commands. */ 140 that case the pvrusb2 driver will emulate the behavior of the
137 unsigned int flag_has_hauppauge_custom_ir:1; 141 older 29xxx device's IR receiver (a "virtual" I2C chip) in terms
142 of those command codes. For the value "ZILOG", we're dealing
143 with an IR chip that must be taken out of reset via another FX2
144 command code (which is the case for HVR-1950 devices). */
145 unsigned int ir_scheme:2;
138 146
139 /* These bits define which kinds of sources the device can handle. 147 /* These bits define which kinds of sources the device can handle.
140 Note: Digital tuner presence is inferred by the 148 Note: Digital tuner presence is inferred by the
diff --git a/drivers/media/video/pvrusb2/pvrusb2-fx2-cmd.h b/drivers/media/video/pvrusb2/pvrusb2-fx2-cmd.h
index b58369e7f30b..614755ea2ea3 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-fx2-cmd.h
+++ b/drivers/media/video/pvrusb2/pvrusb2-fx2-cmd.h
@@ -24,6 +24,8 @@
24#define FX2CMD_MEM_WRITE_DWORD 0x01u 24#define FX2CMD_MEM_WRITE_DWORD 0x01u
25#define FX2CMD_MEM_READ_DWORD 0x02u 25#define FX2CMD_MEM_READ_DWORD 0x02u
26 26
27#define FX2CMD_HCW_ZILOG_RESET 0x10u /* 1=reset 0=release */
28
27#define FX2CMD_MEM_READ_64BYTES 0x28u 29#define FX2CMD_MEM_READ_64BYTES 0x28u
28 30
29#define FX2CMD_REG_WRITE 0x04u 31#define FX2CMD_REG_WRITE 0x04u
diff --git a/drivers/media/video/pvrusb2/pvrusb2-hdw.c b/drivers/media/video/pvrusb2/pvrusb2-hdw.c
index a5217a2cf4c0..f051c6aa7f1f 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-hdw.c
+++ b/drivers/media/video/pvrusb2/pvrusb2-hdw.c
@@ -250,6 +250,7 @@ struct pvr2_fx2cmd_descdef {
250static const struct pvr2_fx2cmd_descdef pvr2_fx2cmd_desc[] = { 250static const struct pvr2_fx2cmd_descdef pvr2_fx2cmd_desc[] = {
251 {FX2CMD_MEM_WRITE_DWORD, "write encoder dword"}, 251 {FX2CMD_MEM_WRITE_DWORD, "write encoder dword"},
252 {FX2CMD_MEM_READ_DWORD, "read encoder dword"}, 252 {FX2CMD_MEM_READ_DWORD, "read encoder dword"},
253 {FX2CMD_HCW_ZILOG_RESET, "zilog IR reset control"},
253 {FX2CMD_MEM_READ_64BYTES, "read encoder 64bytes"}, 254 {FX2CMD_MEM_READ_64BYTES, "read encoder 64bytes"},
254 {FX2CMD_REG_WRITE, "write encoder register"}, 255 {FX2CMD_REG_WRITE, "write encoder register"},
255 {FX2CMD_REG_READ, "read encoder register"}, 256 {FX2CMD_REG_READ, "read encoder register"},
@@ -1711,6 +1712,14 @@ static void pvr2_hdw_setup_low(struct pvr2_hdw *hdw)
1711 if (!pvr2_hdw_dev_ok(hdw)) return; 1712 if (!pvr2_hdw_dev_ok(hdw)) return;
1712 } 1713 }
1713 1714
1715 /* Take the IR chip out of reset, if appropriate */
1716 if (hdw->hdw_desc->ir_scheme == PVR2_IR_SCHEME_ZILOG) {
1717 pvr2_issue_simple_cmd(hdw,
1718 FX2CMD_HCW_ZILOG_RESET |
1719 (1 << 8) |
1720 ((0) << 16));
1721 }
1722
1714 // This step MUST happen after the earlier powerup step. 1723 // This step MUST happen after the earlier powerup step.
1715 pvr2_i2c_core_init(hdw); 1724 pvr2_i2c_core_init(hdw);
1716 if (!pvr2_hdw_dev_ok(hdw)) return; 1725 if (!pvr2_hdw_dev_ok(hdw)) return;
diff --git a/drivers/media/video/pvrusb2/pvrusb2-i2c-core.c b/drivers/media/video/pvrusb2/pvrusb2-i2c-core.c
index 9d3c18b24744..e600576a6c4b 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-i2c-core.c
+++ b/drivers/media/video/pvrusb2/pvrusb2-i2c-core.c
@@ -979,7 +979,9 @@ void pvr2_i2c_core_init(struct pvr2_hdw *hdw)
979 printk(KERN_INFO "%s: IR disabled\n",hdw->name); 979 printk(KERN_INFO "%s: IR disabled\n",hdw->name);
980 hdw->i2c_func[0x18] = i2c_black_hole; 980 hdw->i2c_func[0x18] = i2c_black_hole;
981 } else if (ir_mode[hdw->unit_number] == 1) { 981 } else if (ir_mode[hdw->unit_number] == 1) {
982 if (hdw->hdw_desc->flag_has_hauppauge_custom_ir) { 982 if (hdw->hdw_desc->ir_scheme == PVR2_IR_SCHEME_24XXX) {
983 /* This comment is present PURELY to get
984 checkpatch.pl to STFU. Lovely, eh? */
983 hdw->i2c_func[0x18] = i2c_24xxx_ir; 985 hdw->i2c_func[0x18] = i2c_24xxx_ir;
984 } 986 }
985 } 987 }
diff --git a/drivers/media/video/pvrusb2/pvrusb2-v4l2.c b/drivers/media/video/pvrusb2/pvrusb2-v4l2.c
index 0d72dc470fef..00306faeac01 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-v4l2.c
+++ b/drivers/media/video/pvrusb2/pvrusb2-v4l2.c
@@ -30,6 +30,7 @@
30#include <linux/videodev2.h> 30#include <linux/videodev2.h>
31#include <media/v4l2-dev.h> 31#include <media/v4l2-dev.h>
32#include <media/v4l2-common.h> 32#include <media/v4l2-common.h>
33#include <media/v4l2-ioctl.h>
33 34
34struct pvr2_v4l2_dev; 35struct pvr2_v4l2_dev;
35struct pvr2_v4l2_fh; 36struct pvr2_v4l2_fh;
@@ -1160,11 +1161,6 @@ static const struct file_operations vdev_fops = {
1160 1161
1161 1162
1162static struct video_device vdev_template = { 1163static struct video_device vdev_template = {
1163 .owner = THIS_MODULE,
1164 .type = VID_TYPE_CAPTURE | VID_TYPE_TUNER,
1165 .type2 = (V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_VBI_CAPTURE
1166 | V4L2_CAP_TUNER | V4L2_CAP_AUDIO
1167 | V4L2_CAP_READWRITE),
1168 .fops = &vdev_fops, 1164 .fops = &vdev_fops,
1169}; 1165};
1170 1166
diff --git a/drivers/media/video/pwc/pwc-if.c b/drivers/media/video/pwc/pwc-if.c
index 423fa7c2d0c9..9aee7cb6f79a 100644
--- a/drivers/media/video/pwc/pwc-if.c
+++ b/drivers/media/video/pwc/pwc-if.c
@@ -165,9 +165,7 @@ static const struct file_operations pwc_fops = {
165 .llseek = no_llseek, 165 .llseek = no_llseek,
166}; 166};
167static struct video_device pwc_template = { 167static struct video_device pwc_template = {
168 .owner = THIS_MODULE,
169 .name = "Philips Webcam", /* Filled in later */ 168 .name = "Philips Webcam", /* Filled in later */
170 .type = VID_TYPE_CAPTURE,
171 .release = video_device_release, 169 .release = video_device_release,
172 .fops = &pwc_fops, 170 .fops = &pwc_fops,
173 .minor = -1, 171 .minor = -1,
@@ -1048,19 +1046,20 @@ static int pwc_create_sysfs_files(struct video_device *vdev)
1048 struct pwc_device *pdev = video_get_drvdata(vdev); 1046 struct pwc_device *pdev = video_get_drvdata(vdev);
1049 int rc; 1047 int rc;
1050 1048
1051 rc = video_device_create_file(vdev, &dev_attr_button); 1049 rc = device_create_file(&vdev->dev, &dev_attr_button);
1052 if (rc) 1050 if (rc)
1053 goto err; 1051 goto err;
1054 if (pdev->features & FEATURE_MOTOR_PANTILT) { 1052 if (pdev->features & FEATURE_MOTOR_PANTILT) {
1055 rc = video_device_create_file(vdev, &dev_attr_pan_tilt); 1053 rc = device_create_file(&vdev->dev, &dev_attr_pan_tilt);
1056 if (rc) goto err_button; 1054 if (rc) goto err_button;
1057 } 1055 }
1058 1056
1059 return 0; 1057 return 0;
1060 1058
1061err_button: 1059err_button:
1062 video_device_remove_file(vdev, &dev_attr_button); 1060 device_remove_file(&vdev->dev, &dev_attr_button);
1063err: 1061err:
1062 PWC_ERROR("Could not create sysfs files.\n");
1064 return rc; 1063 return rc;
1065} 1064}
1066 1065
@@ -1068,8 +1067,8 @@ static void pwc_remove_sysfs_files(struct video_device *vdev)
1068{ 1067{
1069 struct pwc_device *pdev = video_get_drvdata(vdev); 1068 struct pwc_device *pdev = video_get_drvdata(vdev);
1070 if (pdev->features & FEATURE_MOTOR_PANTILT) 1069 if (pdev->features & FEATURE_MOTOR_PANTILT)
1071 video_device_remove_file(vdev, &dev_attr_pan_tilt); 1070 device_remove_file(&vdev->dev, &dev_attr_pan_tilt);
1072 video_device_remove_file(vdev, &dev_attr_button); 1071 device_remove_file(&vdev->dev, &dev_attr_button);
1073} 1072}
1074 1073
1075#ifdef CONFIG_USB_PWC_DEBUG 1074#ifdef CONFIG_USB_PWC_DEBUG
@@ -1767,9 +1766,8 @@ static int usb_pwc_probe(struct usb_interface *intf, const struct usb_device_id
1767 return -ENOMEM; 1766 return -ENOMEM;
1768 } 1767 }
1769 memcpy(pdev->vdev, &pwc_template, sizeof(pwc_template)); 1768 memcpy(pdev->vdev, &pwc_template, sizeof(pwc_template));
1770 pdev->vdev->dev = &(udev->dev); 1769 pdev->vdev->parent = &(udev->dev);
1771 strcpy(pdev->vdev->name, name); 1770 strcpy(pdev->vdev->name, name);
1772 pdev->vdev->owner = THIS_MODULE;
1773 video_set_drvdata(pdev->vdev, pdev); 1771 video_set_drvdata(pdev->vdev, pdev);
1774 1772
1775 pdev->release = le16_to_cpu(udev->descriptor.bcdDevice); 1773 pdev->release = le16_to_cpu(udev->descriptor.bcdDevice);
diff --git a/drivers/media/video/pwc/pwc.h b/drivers/media/video/pwc/pwc.h
index 8e8e5b27e77e..74178754b39b 100644
--- a/drivers/media/video/pwc/pwc.h
+++ b/drivers/media/video/pwc/pwc.h
@@ -32,9 +32,11 @@
32#include <linux/smp_lock.h> 32#include <linux/smp_lock.h>
33#include <linux/version.h> 33#include <linux/version.h>
34#include <linux/mutex.h> 34#include <linux/mutex.h>
35#include <linux/mm.h>
35#include <asm/errno.h> 36#include <asm/errno.h>
36#include <linux/videodev.h> 37#include <linux/videodev.h>
37#include <media/v4l2-common.h> 38#include <media/v4l2-common.h>
39#include <media/v4l2-ioctl.h>
38 40
39#include "pwc-uncompress.h" 41#include "pwc-uncompress.h"
40#include <media/pwc-ioctl.h> 42#include <media/pwc-ioctl.h>
diff --git a/drivers/media/video/s2255drv.c b/drivers/media/video/s2255drv.c
index 04eb2c3fabd8..b1d09d8e2b85 100644
--- a/drivers/media/video/s2255drv.c
+++ b/drivers/media/video/s2255drv.c
@@ -47,8 +47,10 @@
47#include <linux/mutex.h> 47#include <linux/mutex.h>
48#include <linux/videodev2.h> 48#include <linux/videodev2.h>
49#include <linux/version.h> 49#include <linux/version.h>
50#include <linux/mm.h>
50#include <media/videobuf-vmalloc.h> 51#include <media/videobuf-vmalloc.h>
51#include <media/v4l2-common.h> 52#include <media/v4l2-common.h>
53#include <media/v4l2-ioctl.h>
52#include <linux/vmalloc.h> 54#include <linux/vmalloc.h>
53#include <linux/usb.h> 55#include <linux/usb.h>
54 56
@@ -184,6 +186,7 @@ struct s2255_dmaqueue {
184#define S2255_FW_LOADED_DSPWAIT 1 186#define S2255_FW_LOADED_DSPWAIT 1
185#define S2255_FW_SUCCESS 2 187#define S2255_FW_SUCCESS 2
186#define S2255_FW_FAILED 3 188#define S2255_FW_FAILED 3
189#define S2255_FW_DISCONNECTING 4
187 190
188struct s2255_fw { 191struct s2255_fw {
189 int fw_loaded; 192 int fw_loaded;
@@ -263,7 +266,6 @@ struct s2255_buffer {
263 266
264struct s2255_fh { 267struct s2255_fh {
265 struct s2255_dev *dev; 268 struct s2255_dev *dev;
266 unsigned int resources;
267 const struct s2255_fmt *fmt; 269 const struct s2255_fmt *fmt;
268 unsigned int width; 270 unsigned int width;
269 unsigned int height; 271 unsigned int height;
@@ -273,14 +275,9 @@ struct s2255_fh {
273 /* mode below is the desired mode. 275 /* mode below is the desired mode.
274 mode in s2255_dev is the current mode that was last set */ 276 mode in s2255_dev is the current mode that was last set */
275 struct s2255_mode mode; 277 struct s2255_mode mode;
278 int resources[MAX_CHANNELS];
276}; 279};
277 280
278/*
279 * TODO: fixme S2255_MAX_USERS. Do not limit open driver handles.
280 * Limit V4L to one stream at a time.
281 */
282#define S2255_MAX_USERS 1
283
284#define CUR_USB_FWVER 774 /* current cypress EEPROM firmware version */ 281#define CUR_USB_FWVER 774 /* current cypress EEPROM firmware version */
285#define S2255_MAJOR_VERSION 1 282#define S2255_MAJOR_VERSION 1
286#define S2255_MINOR_VERSION 13 283#define S2255_MINOR_VERSION 13
@@ -476,10 +473,9 @@ static void s2255_timer(unsigned long user_data)
476 dprintk(100, "s2255 timer\n"); 473 dprintk(100, "s2255 timer\n");
477 if (usb_submit_urb(data->fw_urb, GFP_ATOMIC) < 0) { 474 if (usb_submit_urb(data->fw_urb, GFP_ATOMIC) < 0) {
478 printk(KERN_ERR "s2255: can't submit urb\n"); 475 printk(KERN_ERR "s2255: can't submit urb\n");
479 if (data->fw) { 476 atomic_set(&data->fw_state, S2255_FW_FAILED);
480 release_firmware(data->fw); 477 /* wake up anything waiting for the firmware */
481 data->fw = NULL; 478 wake_up(&data->wait_fw);
482 }
483 return; 479 return;
484 } 480 }
485} 481}
@@ -509,13 +505,18 @@ static void s2255_fwchunk_complete(struct urb *urb)
509 struct usb_device *udev = urb->dev; 505 struct usb_device *udev = urb->dev;
510 int len; 506 int len;
511 dprintk(100, "udev %p urb %p", udev, urb); 507 dprintk(100, "udev %p urb %p", udev, urb);
512 /* TODO: fixme. reflect change in status */
513 if (urb->status) { 508 if (urb->status) {
514 dev_err(&udev->dev, "URB failed with status %d", urb->status); 509 dev_err(&udev->dev, "URB failed with status %d", urb->status);
510 atomic_set(&data->fw_state, S2255_FW_FAILED);
511 /* wake up anything waiting for the firmware */
512 wake_up(&data->wait_fw);
515 return; 513 return;
516 } 514 }
517 if (data->fw_urb == NULL) { 515 if (data->fw_urb == NULL) {
518 dev_err(&udev->dev, "early disconncect\n"); 516 dev_err(&udev->dev, "s2255 disconnected\n");
517 atomic_set(&data->fw_state, S2255_FW_FAILED);
518 /* wake up anything waiting for the firmware */
519 wake_up(&data->wait_fw);
519 return; 520 return;
520 } 521 }
521#define CHUNK_SIZE 512 522#define CHUNK_SIZE 512
@@ -789,7 +790,8 @@ static int res_get(struct s2255_dev *dev, struct s2255_fh *fh)
789 } 790 }
790 /* it's free, grab it */ 791 /* it's free, grab it */
791 dev->resources[fh->channel] = 1; 792 dev->resources[fh->channel] = 1;
792 dprintk(1, "res: get\n"); 793 fh->resources[fh->channel] = 1;
794 dprintk(1, "s2255: res: get\n");
793 mutex_unlock(&dev->lock); 795 mutex_unlock(&dev->lock);
794 return 1; 796 return 1;
795} 797}
@@ -799,9 +801,18 @@ static int res_locked(struct s2255_dev *dev, struct s2255_fh *fh)
799 return dev->resources[fh->channel]; 801 return dev->resources[fh->channel];
800} 802}
801 803
804static int res_check(struct s2255_fh *fh)
805{
806 return fh->resources[fh->channel];
807}
808
809
802static void res_free(struct s2255_dev *dev, struct s2255_fh *fh) 810static void res_free(struct s2255_dev *dev, struct s2255_fh *fh)
803{ 811{
812 mutex_lock(&dev->lock);
804 dev->resources[fh->channel] = 0; 813 dev->resources[fh->channel] = 0;
814 fh->resources[fh->channel] = 0;
815 mutex_unlock(&dev->lock);
805 dprintk(1, "res: put\n"); 816 dprintk(1, "res: put\n");
806} 817}
807 818
@@ -1232,7 +1243,7 @@ static int vidioc_streamon(struct file *file, void *priv, enum v4l2_buf_type i)
1232 } 1243 }
1233 1244
1234 if (!res_get(dev, fh)) { 1245 if (!res_get(dev, fh)) {
1235 dev_err(&dev->udev->dev, "res get busy\n"); 1246 dev_err(&dev->udev->dev, "s2255: stream busy\n");
1236 return -EBUSY; 1247 return -EBUSY;
1237 } 1248 }
1238 1249
@@ -1288,8 +1299,10 @@ static int vidioc_streamoff(struct file *file, void *priv, enum v4l2_buf_type i)
1288 } 1299 }
1289 s2255_stop_acquire(dev, fh->channel); 1300 s2255_stop_acquire(dev, fh->channel);
1290 res = videobuf_streamoff(&fh->vb_vidq); 1301 res = videobuf_streamoff(&fh->vb_vidq);
1302 if (res < 0)
1303 return res;
1291 res_free(dev, fh); 1304 res_free(dev, fh);
1292 return res; 1305 return 0;
1293} 1306}
1294 1307
1295static int vidioc_s_std(struct file *file, void *priv, v4l2_std_id *i) 1308static int vidioc_s_std(struct file *file, void *priv, v4l2_std_id *i)
@@ -1462,12 +1475,7 @@ static int s2255_open(struct inode *inode, struct file *file)
1462 mutex_lock(&dev->open_lock); 1475 mutex_lock(&dev->open_lock);
1463 1476
1464 dev->users[cur_channel]++; 1477 dev->users[cur_channel]++;
1465 if (dev->users[cur_channel] > S2255_MAX_USERS) { 1478 dprintk(4, "s2255: open_handles %d\n", dev->users[cur_channel]);
1466 dev->users[cur_channel]--;
1467 mutex_unlock(&dev->open_lock);
1468 printk(KERN_INFO "s2255drv: too many open handles!\n");
1469 return -EBUSY;
1470 }
1471 1479
1472 if (atomic_read(&dev->fw_data->fw_state) == S2255_FW_FAILED) { 1480 if (atomic_read(&dev->fw_data->fw_state) == S2255_FW_FAILED) {
1473 err("2255 firmware load failed. retrying.\n"); 1481 err("2255 firmware load failed. retrying.\n");
@@ -1478,7 +1486,8 @@ static int s2255_open(struct inode *inode, struct file *file)
1478 msecs_to_jiffies(S2255_LOAD_TIMEOUT)); 1486 msecs_to_jiffies(S2255_LOAD_TIMEOUT));
1479 if (atomic_read(&dev->fw_data->fw_state) 1487 if (atomic_read(&dev->fw_data->fw_state)
1480 != S2255_FW_SUCCESS) { 1488 != S2255_FW_SUCCESS) {
1481 printk(KERN_INFO "2255 FW load failed after 2 tries\n"); 1489 printk(KERN_INFO "2255 FW load failed.\n");
1490 dev->users[cur_channel]--;
1482 mutex_unlock(&dev->open_lock); 1491 mutex_unlock(&dev->open_lock);
1483 return -EFAULT; 1492 return -EFAULT;
1484 } 1493 }
@@ -1494,6 +1503,7 @@ static int s2255_open(struct inode *inode, struct file *file)
1494 != S2255_FW_SUCCESS) { 1503 != S2255_FW_SUCCESS) {
1495 printk(KERN_INFO "2255 firmware not loaded" 1504 printk(KERN_INFO "2255 firmware not loaded"
1496 "try again\n"); 1505 "try again\n");
1506 dev->users[cur_channel]--;
1497 mutex_unlock(&dev->open_lock); 1507 mutex_unlock(&dev->open_lock);
1498 return -EBUSY; 1508 return -EBUSY;
1499 } 1509 }
@@ -1502,6 +1512,7 @@ static int s2255_open(struct inode *inode, struct file *file)
1502 /* allocate + initialize per filehandle data */ 1512 /* allocate + initialize per filehandle data */
1503 fh = kzalloc(sizeof(*fh), GFP_KERNEL); 1513 fh = kzalloc(sizeof(*fh), GFP_KERNEL);
1504 if (NULL == fh) { 1514 if (NULL == fh) {
1515 dev->users[cur_channel]--;
1505 mutex_unlock(&dev->open_lock); 1516 mutex_unlock(&dev->open_lock);
1506 return -ENOMEM; 1517 return -ENOMEM;
1507 } 1518 }
@@ -1561,44 +1572,48 @@ static void s2255_destroy(struct kref *kref)
1561 printk(KERN_ERR "s2255drv: kref problem\n"); 1572 printk(KERN_ERR "s2255drv: kref problem\n");
1562 return; 1573 return;
1563 } 1574 }
1575
1576 /*
1577 * Wake up any firmware load waiting (only done in .open,
1578 * which holds the open_lock mutex)
1579 */
1580 atomic_set(&dev->fw_data->fw_state, S2255_FW_DISCONNECTING);
1581 wake_up(&dev->fw_data->wait_fw);
1582
1564 /* prevent s2255_disconnect from racing s2255_open */ 1583 /* prevent s2255_disconnect from racing s2255_open */
1565 mutex_lock(&dev->open_lock); 1584 mutex_lock(&dev->open_lock);
1566 s2255_exit_v4l(dev); 1585 s2255_exit_v4l(dev);
1567 /* device unregistered so no longer possible to open. open_mutex 1586 /*
1568 can be unlocked */ 1587 * device unregistered so no longer possible to open. open_mutex
1588 * can be unlocked and timers deleted afterwards.
1589 */
1569 mutex_unlock(&dev->open_lock); 1590 mutex_unlock(&dev->open_lock);
1570 1591
1571 /* board shutdown stops the read pipe if it is running */ 1592 /* board shutdown stops the read pipe if it is running */
1572 s2255_board_shutdown(dev); 1593 s2255_board_shutdown(dev);
1573 1594
1574 /* make sure firmware still not trying to load */ 1595 /* make sure firmware still not trying to load */
1596 del_timer(&dev->timer); /* only started in .probe and .open */
1597
1575 if (dev->fw_data->fw_urb) { 1598 if (dev->fw_data->fw_urb) {
1576 dprintk(2, "kill fw_urb\n"); 1599 dprintk(2, "kill fw_urb\n");
1577 usb_kill_urb(dev->fw_data->fw_urb); 1600 usb_kill_urb(dev->fw_data->fw_urb);
1578 usb_free_urb(dev->fw_data->fw_urb); 1601 usb_free_urb(dev->fw_data->fw_urb);
1579 dev->fw_data->fw_urb = NULL; 1602 dev->fw_data->fw_urb = NULL;
1580 } 1603 }
1604
1581 /* 1605 /*
1582 * TODO: fixme(above, below): potentially leaving timers alive. 1606 * delete the dsp_wait timer, which sets the firmware
1583 * do not ignore timeout below if 1607 * state on completion. This is done before fw_data
1584 * it occurs. 1608 * is freed below.
1585 */ 1609 */
1586 1610
1587 /* make sure we aren't waiting for the DSP */ 1611 del_timer(&dev->fw_data->dsp_wait); /* only started in .open */
1588 if (atomic_read(&dev->fw_data->fw_state) == S2255_FW_LOADED_DSPWAIT) {
1589 /* if we are, wait for the wakeup for fw_success or timeout */
1590 wait_event_timeout(dev->fw_data->wait_fw,
1591 (atomic_read(&dev->fw_data->fw_state)
1592 == S2255_FW_SUCCESS),
1593 msecs_to_jiffies(S2255_LOAD_TIMEOUT));
1594 }
1595 1612
1596 if (dev->fw_data) { 1613 if (dev->fw_data->fw)
1597 if (dev->fw_data->fw) 1614 release_firmware(dev->fw_data->fw);
1598 release_firmware(dev->fw_data->fw); 1615 kfree(dev->fw_data->pfw_data);
1599 kfree(dev->fw_data->pfw_data); 1616 kfree(dev->fw_data);
1600 kfree(dev->fw_data);
1601 }
1602 1617
1603 usb_put_dev(dev->udev); 1618 usb_put_dev(dev->udev);
1604 dprintk(1, "%s", __func__); 1619 dprintk(1, "%s", __func__);
@@ -1615,17 +1630,23 @@ static int s2255_close(struct inode *inode, struct file *file)
1615 1630
1616 mutex_lock(&dev->open_lock); 1631 mutex_lock(&dev->open_lock);
1617 1632
1618 if (dev->b_acquire[fh->channel]) 1633 /* turn off stream */
1619 s2255_stop_acquire(dev, fh->channel); 1634 if (res_check(fh)) {
1620 res_free(dev, fh); 1635 if (dev->b_acquire[fh->channel])
1636 s2255_stop_acquire(dev, fh->channel);
1637 videobuf_streamoff(&fh->vb_vidq);
1638 res_free(dev, fh);
1639 }
1640
1621 videobuf_mmap_free(&fh->vb_vidq); 1641 videobuf_mmap_free(&fh->vb_vidq);
1622 kfree(fh);
1623 dev->users[fh->channel]--; 1642 dev->users[fh->channel]--;
1643
1624 mutex_unlock(&dev->open_lock); 1644 mutex_unlock(&dev->open_lock);
1625 1645
1626 kref_put(&dev->kref, s2255_destroy); 1646 kref_put(&dev->kref, s2255_destroy);
1627 dprintk(1, "s2255: close called (minor=%d, users=%d)\n", 1647 dprintk(1, "s2255: close called (minor=%d, users=%d)\n",
1628 minor, dev->users[fh->channel]); 1648 minor, dev->users[fh->channel]);
1649 kfree(fh);
1629 return 0; 1650 return 0;
1630} 1651}
1631 1652
@@ -1658,12 +1679,7 @@ static const struct file_operations s2255_fops_v4l = {
1658 .llseek = no_llseek, 1679 .llseek = no_llseek,
1659}; 1680};
1660 1681
1661static struct video_device template = { 1682static const struct v4l2_ioctl_ops s2255_ioctl_ops = {
1662 .name = "s2255v",
1663 .type = VID_TYPE_CAPTURE,
1664 .fops = &s2255_fops_v4l,
1665 .minor = -1,
1666 .release = video_device_release,
1667 .vidioc_querycap = vidioc_querycap, 1683 .vidioc_querycap = vidioc_querycap,
1668 .vidioc_enum_fmt_vid_cap = vidioc_enum_fmt_vid_cap, 1684 .vidioc_enum_fmt_vid_cap = vidioc_enum_fmt_vid_cap,
1669 .vidioc_g_fmt_vid_cap = vidioc_g_fmt_vid_cap, 1685 .vidioc_g_fmt_vid_cap = vidioc_g_fmt_vid_cap,
@@ -1685,6 +1701,14 @@ static struct video_device template = {
1685#ifdef CONFIG_VIDEO_V4L1_COMPAT 1701#ifdef CONFIG_VIDEO_V4L1_COMPAT
1686 .vidiocgmbuf = vidioc_cgmbuf, 1702 .vidiocgmbuf = vidioc_cgmbuf,
1687#endif 1703#endif
1704};
1705
1706static struct video_device template = {
1707 .name = "s2255v",
1708 .fops = &s2255_fops_v4l,
1709 .ioctl_ops = &s2255_ioctl_ops,
1710 .minor = -1,
1711 .release = video_device_release,
1688 .tvnorms = S2255_NORMS, 1712 .tvnorms = S2255_NORMS,
1689 .current_norm = V4L2_STD_NTSC_M, 1713 .current_norm = V4L2_STD_NTSC_M,
1690}; 1714};
@@ -1706,7 +1730,7 @@ static int s2255_probe_v4l(struct s2255_dev *dev)
1706 /* register 4 video devices */ 1730 /* register 4 video devices */
1707 dev->vdev[i] = video_device_alloc(); 1731 dev->vdev[i] = video_device_alloc();
1708 memcpy(dev->vdev[i], &template, sizeof(struct video_device)); 1732 memcpy(dev->vdev[i], &template, sizeof(struct video_device));
1709 dev->vdev[i]->dev = &dev->interface->dev; 1733 dev->vdev[i]->parent = &dev->interface->dev;
1710 if (video_nr == -1) 1734 if (video_nr == -1)
1711 ret = video_register_device(dev->vdev[i], 1735 ret = video_register_device(dev->vdev[i],
1712 VFL_TYPE_GRABBER, 1736 VFL_TYPE_GRABBER,
diff --git a/drivers/media/video/saa5246a.c b/drivers/media/video/saa5246a.c
index 03e772130b55..6ee63e69b36c 100644
--- a/drivers/media/video/saa5246a.c
+++ b/drivers/media/video/saa5246a.c
@@ -46,6 +46,7 @@
46#include <linux/videotext.h> 46#include <linux/videotext.h>
47#include <linux/videodev.h> 47#include <linux/videodev.h>
48#include <media/v4l2-common.h> 48#include <media/v4l2-common.h>
49#include <media/v4l2-ioctl.h>
49#include <linux/mutex.h> 50#include <linux/mutex.h>
50 51
51#include "saa5246a.h" 52#include "saa5246a.h"
@@ -829,9 +830,7 @@ static const struct file_operations saa_fops = {
829 830
830static struct video_device saa_template = 831static struct video_device saa_template =
831{ 832{
832 .owner = THIS_MODULE,
833 .name = IF_NAME, 833 .name = IF_NAME,
834 .type = VID_TYPE_TELETEXT,
835 .fops = &saa_fops, 834 .fops = &saa_fops,
836 .release = video_device_release, 835 .release = video_device_release,
837 .minor = -1, 836 .minor = -1,
diff --git a/drivers/media/video/saa5249.c b/drivers/media/video/saa5249.c
index fde99d9ee71f..0d639738d4e6 100644
--- a/drivers/media/video/saa5249.c
+++ b/drivers/media/video/saa5249.c
@@ -57,6 +57,7 @@
57#include <linux/videotext.h> 57#include <linux/videotext.h>
58#include <linux/videodev.h> 58#include <linux/videodev.h>
59#include <media/v4l2-common.h> 59#include <media/v4l2-common.h>
60#include <media/v4l2-ioctl.h>
60#include <linux/mutex.h> 61#include <linux/mutex.h>
61 62
62 63
@@ -710,9 +711,7 @@ static const struct file_operations saa_fops = {
710 711
711static struct video_device saa_template = 712static struct video_device saa_template =
712{ 713{
713 .owner = THIS_MODULE,
714 .name = IF_NAME, 714 .name = IF_NAME,
715 .type = VID_TYPE_TELETEXT, /*| VID_TYPE_TUNER ?? */
716 .fops = &saa_fops, 715 .fops = &saa_fops,
717}; 716};
718 717
diff --git a/drivers/media/video/saa7134/Kconfig b/drivers/media/video/saa7134/Kconfig
index 83f076abce35..7021bbf5897b 100644
--- a/drivers/media/video/saa7134/Kconfig
+++ b/drivers/media/video/saa7134/Kconfig
@@ -27,9 +27,7 @@ config VIDEO_SAA7134_ALSA
27config VIDEO_SAA7134_DVB 27config VIDEO_SAA7134_DVB
28 tristate "DVB/ATSC Support for saa7134 based TV cards" 28 tristate "DVB/ATSC Support for saa7134 based TV cards"
29 depends on VIDEO_SAA7134 && DVB_CORE 29 depends on VIDEO_SAA7134 && DVB_CORE
30 depends on HOTPLUG # due to FW_LOADER
31 select VIDEOBUF_DVB 30 select VIDEOBUF_DVB
32 select FW_LOADER
33 select DVB_PLL if !DVB_FE_CUSTOMISE 31 select DVB_PLL if !DVB_FE_CUSTOMISE
34 select DVB_MT352 if !DVB_FE_CUSTOMISE 32 select DVB_MT352 if !DVB_FE_CUSTOMISE
35 select DVB_TDA1004X if !DVB_FE_CUSTOMISE 33 select DVB_TDA1004X if !DVB_FE_CUSTOMISE
diff --git a/drivers/media/video/saa7134/saa7134-cards.c b/drivers/media/video/saa7134/saa7134-cards.c
index 6893f998d292..98364d171def 100644
--- a/drivers/media/video/saa7134/saa7134-cards.c
+++ b/drivers/media/video/saa7134/saa7134-cards.c
@@ -5853,9 +5853,6 @@ int saa7134_board_init2(struct saa7134_dev *dev)
5853 unsigned char buf; 5853 unsigned char buf;
5854 int board; 5854 int board;
5855 5855
5856 dev->tuner_type = saa7134_boards[dev->board].tuner_type;
5857 dev->tuner_addr = saa7134_boards[dev->board].tuner_addr;
5858
5859 switch (dev->board) { 5856 switch (dev->board) {
5860 case SAA7134_BOARD_BMK_MPEX_NOTUNER: 5857 case SAA7134_BOARD_BMK_MPEX_NOTUNER:
5861 case SAA7134_BOARD_BMK_MPEX_TUNER: 5858 case SAA7134_BOARD_BMK_MPEX_TUNER:
diff --git a/drivers/media/video/saa7134/saa7134-core.c b/drivers/media/video/saa7134/saa7134-core.c
index cfee84ee7a88..75d618415f4f 100644
--- a/drivers/media/video/saa7134/saa7134-core.c
+++ b/drivers/media/video/saa7134/saa7134-core.c
@@ -798,7 +798,7 @@ static struct video_device *vdev_init(struct saa7134_dev *dev,
798 return NULL; 798 return NULL;
799 *vfd = *template; 799 *vfd = *template;
800 vfd->minor = -1; 800 vfd->minor = -1;
801 vfd->dev = &dev->pci->dev; 801 vfd->parent = &dev->pci->dev;
802 vfd->release = video_device_release; 802 vfd->release = video_device_release;
803 vfd->debug = video_debug; 803 vfd->debug = video_debug;
804 snprintf(vfd->name, sizeof(vfd->name), "%s %s (%s)", 804 snprintf(vfd->name, sizeof(vfd->name), "%s %s (%s)",
@@ -945,11 +945,12 @@ static int __devinit saa7134_initdev(struct pci_dev *pci_dev,
945 dev->board = SAA7134_BOARD_UNKNOWN; 945 dev->board = SAA7134_BOARD_UNKNOWN;
946 } 946 }
947 dev->autodetected = card[dev->nr] != dev->board; 947 dev->autodetected = card[dev->nr] != dev->board;
948 dev->tuner_type = saa7134_boards[dev->board].tuner_type; 948 dev->tuner_type = saa7134_boards[dev->board].tuner_type;
949 dev->tuner_addr = saa7134_boards[dev->board].tuner_addr;
949 dev->tda9887_conf = saa7134_boards[dev->board].tda9887_conf; 950 dev->tda9887_conf = saa7134_boards[dev->board].tda9887_conf;
950 if (UNSET != tuner[dev->nr]) 951 if (UNSET != tuner[dev->nr])
951 dev->tuner_type = tuner[dev->nr]; 952 dev->tuner_type = tuner[dev->nr];
952 printk(KERN_INFO "%s: subsystem: %04x:%04x, board: %s [card=%d,%s]\n", 953 printk(KERN_INFO "%s: subsystem: %04x:%04x, board: %s [card=%d,%s]\n",
953 dev->name,pci_dev->subsystem_vendor, 954 dev->name,pci_dev->subsystem_vendor,
954 pci_dev->subsystem_device,saa7134_boards[dev->board].name, 955 pci_dev->subsystem_device,saa7134_boards[dev->board].name,
955 dev->board, dev->autodetected ? 956 dev->board, dev->autodetected ?
@@ -1007,11 +1008,9 @@ static int __devinit saa7134_initdev(struct pci_dev *pci_dev,
1007 v4l2_prio_init(&dev->prio); 1008 v4l2_prio_init(&dev->prio);
1008 1009
1009 /* register v4l devices */ 1010 /* register v4l devices */
1010 if (saa7134_no_overlay <= 0) { 1011 if (saa7134_no_overlay > 0)
1011 saa7134_video_template.type |= VID_TYPE_OVERLAY; 1012 printk(KERN_INFO "%s: Overlay support disabled.\n", dev->name);
1012 } else { 1013
1013 printk("%s: Overlay support disabled.\n",dev->name);
1014 }
1015 dev->video_dev = vdev_init(dev,&saa7134_video_template,"video"); 1014 dev->video_dev = vdev_init(dev,&saa7134_video_template,"video");
1016 err = video_register_device(dev->video_dev,VFL_TYPE_GRABBER, 1015 err = video_register_device(dev->video_dev,VFL_TYPE_GRABBER,
1017 video_nr[dev->nr]); 1016 video_nr[dev->nr]);
@@ -1024,7 +1023,6 @@ static int __devinit saa7134_initdev(struct pci_dev *pci_dev,
1024 dev->name,dev->video_dev->minor & 0x1f); 1023 dev->name,dev->video_dev->minor & 0x1f);
1025 1024
1026 dev->vbi_dev = vdev_init(dev, &saa7134_video_template, "vbi"); 1025 dev->vbi_dev = vdev_init(dev, &saa7134_video_template, "vbi");
1027 dev->vbi_dev->type = VID_TYPE_TUNER | VID_TYPE_TELETEXT;
1028 1026
1029 err = video_register_device(dev->vbi_dev,VFL_TYPE_VBI, 1027 err = video_register_device(dev->vbi_dev,VFL_TYPE_VBI,
1030 vbi_nr[dev->nr]); 1028 vbi_nr[dev->nr]);
diff --git a/drivers/media/video/saa7134/saa7134-empress.c b/drivers/media/video/saa7134/saa7134-empress.c
index 2a5ab957542d..c0c5d7509c25 100644
--- a/drivers/media/video/saa7134/saa7134-empress.c
+++ b/drivers/media/video/saa7134/saa7134-empress.c
@@ -89,14 +89,14 @@ static int ts_open(struct inode *inode, struct file *file)
89 err = -EBUSY; 89 err = -EBUSY;
90 if (!mutex_trylock(&dev->empress_tsq.vb_lock)) 90 if (!mutex_trylock(&dev->empress_tsq.vb_lock))
91 goto done; 91 goto done;
92 if (dev->empress_users) 92 if (atomic_read(&dev->empress_users))
93 goto done_up; 93 goto done_up;
94 94
95 /* Unmute audio */ 95 /* Unmute audio */
96 saa_writeb(SAA7134_AUDIO_MUTE_CTRL, 96 saa_writeb(SAA7134_AUDIO_MUTE_CTRL,
97 saa_readb(SAA7134_AUDIO_MUTE_CTRL) & ~(1 << 6)); 97 saa_readb(SAA7134_AUDIO_MUTE_CTRL) & ~(1 << 6));
98 98
99 dev->empress_users++; 99 atomic_inc(&dev->empress_users);
100 file->private_data = dev; 100 file->private_data = dev;
101 err = 0; 101 err = 0;
102 102
@@ -110,8 +110,6 @@ static int ts_release(struct inode *inode, struct file *file)
110{ 110{
111 struct saa7134_dev *dev = file->private_data; 111 struct saa7134_dev *dev = file->private_data;
112 112
113 mutex_lock(&dev->empress_tsq.vb_lock);
114
115 videobuf_stop(&dev->empress_tsq); 113 videobuf_stop(&dev->empress_tsq);
116 videobuf_mmap_free(&dev->empress_tsq); 114 videobuf_mmap_free(&dev->empress_tsq);
117 115
@@ -122,9 +120,7 @@ static int ts_release(struct inode *inode, struct file *file)
122 saa_writeb(SAA7134_AUDIO_MUTE_CTRL, 120 saa_writeb(SAA7134_AUDIO_MUTE_CTRL,
123 saa_readb(SAA7134_AUDIO_MUTE_CTRL) | (1 << 6)); 121 saa_readb(SAA7134_AUDIO_MUTE_CTRL) | (1 << 6));
124 122
125 dev->empress_users--; 123 atomic_dec(&dev->empress_users);
126
127 mutex_unlock(&dev->empress_tsq.vb_lock);
128 124
129 return 0; 125 return 0;
130} 126}
@@ -333,6 +329,22 @@ static int empress_g_ext_ctrls(struct file *file, void *priv,
333 return saa7134_i2c_call_saa6752(dev, VIDIOC_G_EXT_CTRLS, ctrls); 329 return saa7134_i2c_call_saa6752(dev, VIDIOC_G_EXT_CTRLS, ctrls);
334} 330}
335 331
332static int empress_g_ctrl(struct file *file, void *priv,
333 struct v4l2_control *c)
334{
335 struct saa7134_dev *dev = file->private_data;
336
337 return saa7134_g_ctrl_internal(dev, NULL, c);
338}
339
340static int empress_s_ctrl(struct file *file, void *priv,
341 struct v4l2_control *c)
342{
343 struct saa7134_dev *dev = file->private_data;
344
345 return saa7134_s_ctrl_internal(dev, NULL, c);
346}
347
336static int empress_queryctrl(struct file *file, void *priv, 348static int empress_queryctrl(struct file *file, void *priv,
337 struct v4l2_queryctrl *c) 349 struct v4l2_queryctrl *c)
338{ 350{
@@ -400,16 +412,7 @@ static const struct file_operations ts_fops =
400 .llseek = no_llseek, 412 .llseek = no_llseek,
401}; 413};
402 414
403/* ----------------------------------------------------------- */ 415static const struct v4l2_ioctl_ops ts_ioctl_ops = {
404
405static struct video_device saa7134_empress_template =
406{
407 .name = "saa7134-empress",
408 .type = 0 /* FIXME */,
409 .type2 = 0 /* FIXME */,
410 .fops = &ts_fops,
411 .minor = -1,
412
413 .vidioc_querycap = empress_querycap, 416 .vidioc_querycap = empress_querycap,
414 .vidioc_enum_fmt_vid_cap = empress_enum_fmt_vid_cap, 417 .vidioc_enum_fmt_vid_cap = empress_enum_fmt_vid_cap,
415 .vidioc_s_fmt_vid_cap = empress_s_fmt_vid_cap, 418 .vidioc_s_fmt_vid_cap = empress_s_fmt_vid_cap,
@@ -428,8 +431,17 @@ static struct video_device saa7134_empress_template =
428 431
429 .vidioc_queryctrl = empress_queryctrl, 432 .vidioc_queryctrl = empress_queryctrl,
430 .vidioc_querymenu = empress_querymenu, 433 .vidioc_querymenu = empress_querymenu,
431 .vidioc_g_ctrl = saa7134_g_ctrl, 434 .vidioc_g_ctrl = empress_g_ctrl,
432 .vidioc_s_ctrl = saa7134_s_ctrl, 435 .vidioc_s_ctrl = empress_s_ctrl,
436};
437
438/* ----------------------------------------------------------- */
439
440static struct video_device saa7134_empress_template = {
441 .name = "saa7134-empress",
442 .fops = &ts_fops,
443 .minor = -1,
444 .ioctl_ops = &ts_ioctl_ops,
433 445
434 .tvnorms = SAA7134_NORMS, 446 .tvnorms = SAA7134_NORMS,
435 .current_norm = V4L2_STD_PAL, 447 .current_norm = V4L2_STD_PAL,
@@ -445,7 +457,7 @@ static void empress_signal_update(struct work_struct *work)
445 ts_reset_encoder(dev); 457 ts_reset_encoder(dev);
446 } else { 458 } else {
447 dprintk("video signal acquired\n"); 459 dprintk("video signal acquired\n");
448 if (dev->empress_users) 460 if (atomic_read(&dev->empress_users))
449 ts_init_encoder(dev); 461 ts_init_encoder(dev);
450 } 462 }
451} 463}
@@ -465,7 +477,7 @@ static int empress_init(struct saa7134_dev *dev)
465 if (NULL == dev->empress_dev) 477 if (NULL == dev->empress_dev)
466 return -ENOMEM; 478 return -ENOMEM;
467 *(dev->empress_dev) = saa7134_empress_template; 479 *(dev->empress_dev) = saa7134_empress_template;
468 dev->empress_dev->dev = &dev->pci->dev; 480 dev->empress_dev->parent = &dev->pci->dev;
469 dev->empress_dev->release = video_device_release; 481 dev->empress_dev->release = video_device_release;
470 snprintf(dev->empress_dev->name, sizeof(dev->empress_dev->name), 482 snprintf(dev->empress_dev->name, sizeof(dev->empress_dev->name),
471 "%s empress (%s)", dev->name, 483 "%s empress (%s)", dev->name,
diff --git a/drivers/media/video/saa7134/saa7134-video.c b/drivers/media/video/saa7134/saa7134-video.c
index 1a5137550e7a..68c268981861 100644
--- a/drivers/media/video/saa7134/saa7134-video.c
+++ b/drivers/media/video/saa7134/saa7134-video.c
@@ -1112,10 +1112,8 @@ static struct videobuf_queue_ops video_qops = {
1112 1112
1113/* ------------------------------------------------------------------ */ 1113/* ------------------------------------------------------------------ */
1114 1114
1115int saa7134_g_ctrl(struct file *file, void *priv, struct v4l2_control *c) 1115int saa7134_g_ctrl_internal(struct saa7134_dev *dev, struct saa7134_fh *fh, struct v4l2_control *c)
1116{ 1116{
1117 struct saa7134_fh *fh = priv;
1118 struct saa7134_dev *dev = fh->dev;
1119 const struct v4l2_queryctrl* ctrl; 1117 const struct v4l2_queryctrl* ctrl;
1120 1118
1121 ctrl = ctrl_by_id(c->id); 1119 ctrl = ctrl_by_id(c->id);
@@ -1160,20 +1158,31 @@ int saa7134_g_ctrl(struct file *file, void *priv, struct v4l2_control *c)
1160 } 1158 }
1161 return 0; 1159 return 0;
1162} 1160}
1163EXPORT_SYMBOL_GPL(saa7134_g_ctrl); 1161EXPORT_SYMBOL_GPL(saa7134_g_ctrl_internal);
1162
1163static int saa7134_g_ctrl(struct file *file, void *priv, struct v4l2_control *c)
1164{
1165 struct saa7134_fh *fh = priv;
1166
1167 return saa7134_g_ctrl_internal(fh->dev, fh, c);
1168}
1164 1169
1165int saa7134_s_ctrl(struct file *file, void *f, struct v4l2_control *c) 1170int saa7134_s_ctrl_internal(struct saa7134_dev *dev, struct saa7134_fh *fh, struct v4l2_control *c)
1166{ 1171{
1167 const struct v4l2_queryctrl* ctrl; 1172 const struct v4l2_queryctrl* ctrl;
1168 struct saa7134_fh *fh = f;
1169 struct saa7134_dev *dev = fh->dev;
1170 unsigned long flags; 1173 unsigned long flags;
1171 int restart_overlay = 0; 1174 int restart_overlay = 0;
1172 int err = -EINVAL; 1175 int err;
1173 1176
1174 err = v4l2_prio_check(&dev->prio, &fh->prio); 1177 /* When called from the empress code fh == NULL.
1175 if (0 != err) 1178 That needs to be fixed somehow, but for now this is
1176 return err; 1179 good enough. */
1180 if (fh) {
1181 err = v4l2_prio_check(&dev->prio, &fh->prio);
1182 if (0 != err)
1183 return err;
1184 }
1185 err = -EINVAL;
1177 1186
1178 mutex_lock(&dev->lock); 1187 mutex_lock(&dev->lock);
1179 1188
@@ -1274,7 +1283,14 @@ error:
1274 mutex_unlock(&dev->lock); 1283 mutex_unlock(&dev->lock);
1275 return err; 1284 return err;
1276} 1285}
1277EXPORT_SYMBOL_GPL(saa7134_s_ctrl); 1286EXPORT_SYMBOL_GPL(saa7134_s_ctrl_internal);
1287
1288static int saa7134_s_ctrl(struct file *file, void *f, struct v4l2_control *c)
1289{
1290 struct saa7134_fh *fh = f;
1291
1292 return saa7134_s_ctrl_internal(fh->dev, fh, c);
1293}
1278 1294
1279/* ------------------------------------------------------------------ */ 1295/* ------------------------------------------------------------------ */
1280 1296
@@ -2353,26 +2369,7 @@ static const struct file_operations video_fops =
2353 .llseek = no_llseek, 2369 .llseek = no_llseek,
2354}; 2370};
2355 2371
2356static const struct file_operations radio_fops = 2372static const struct v4l2_ioctl_ops video_ioctl_ops = {
2357{
2358 .owner = THIS_MODULE,
2359 .open = video_open,
2360 .release = video_release,
2361 .ioctl = video_ioctl2,
2362 .compat_ioctl = v4l_compat_ioctl32,
2363 .llseek = no_llseek,
2364};
2365
2366/* ----------------------------------------------------------- */
2367/* exported stuff */
2368
2369struct video_device saa7134_video_template =
2370{
2371 .name = "saa7134-video",
2372 .type = VID_TYPE_CAPTURE|VID_TYPE_TUNER |
2373 VID_TYPE_CLIPPING|VID_TYPE_SCALES,
2374 .fops = &video_fops,
2375 .minor = -1,
2376 .vidioc_querycap = saa7134_querycap, 2373 .vidioc_querycap = saa7134_querycap,
2377 .vidioc_enum_fmt_vid_cap = saa7134_enum_fmt_vid_cap, 2374 .vidioc_enum_fmt_vid_cap = saa7134_enum_fmt_vid_cap,
2378 .vidioc_g_fmt_vid_cap = saa7134_g_fmt_vid_cap, 2375 .vidioc_g_fmt_vid_cap = saa7134_g_fmt_vid_cap,
@@ -2421,16 +2418,18 @@ struct video_device saa7134_video_template =
2421 .vidioc_g_register = vidioc_g_register, 2418 .vidioc_g_register = vidioc_g_register,
2422 .vidioc_s_register = vidioc_s_register, 2419 .vidioc_s_register = vidioc_s_register,
2423#endif 2420#endif
2424 .tvnorms = SAA7134_NORMS,
2425 .current_norm = V4L2_STD_PAL,
2426}; 2421};
2427 2422
2428struct video_device saa7134_radio_template = 2423static const struct file_operations radio_fops = {
2429{ 2424 .owner = THIS_MODULE,
2430 .name = "saa7134-radio", 2425 .open = video_open,
2431 .type = VID_TYPE_TUNER, 2426 .release = video_release,
2432 .fops = &radio_fops, 2427 .ioctl = video_ioctl2,
2433 .minor = -1, 2428 .compat_ioctl = v4l_compat_ioctl32,
2429 .llseek = no_llseek,
2430};
2431
2432static const struct v4l2_ioctl_ops radio_ioctl_ops = {
2434 .vidioc_querycap = radio_querycap, 2433 .vidioc_querycap = radio_querycap,
2435 .vidioc_g_tuner = radio_g_tuner, 2434 .vidioc_g_tuner = radio_g_tuner,
2436 .vidioc_enum_input = radio_enum_input, 2435 .vidioc_enum_input = radio_enum_input,
@@ -2447,6 +2446,25 @@ struct video_device saa7134_radio_template =
2447 .vidioc_s_frequency = saa7134_s_frequency, 2446 .vidioc_s_frequency = saa7134_s_frequency,
2448}; 2447};
2449 2448
2449/* ----------------------------------------------------------- */
2450/* exported stuff */
2451
2452struct video_device saa7134_video_template = {
2453 .name = "saa7134-video",
2454 .fops = &video_fops,
2455 .ioctl_ops = &video_ioctl_ops,
2456 .minor = -1,
2457 .tvnorms = SAA7134_NORMS,
2458 .current_norm = V4L2_STD_PAL,
2459};
2460
2461struct video_device saa7134_radio_template = {
2462 .name = "saa7134-radio",
2463 .fops = &radio_fops,
2464 .ioctl_ops = &radio_ioctl_ops,
2465 .minor = -1,
2466};
2467
2450int saa7134_video_init1(struct saa7134_dev *dev) 2468int saa7134_video_init1(struct saa7134_dev *dev)
2451{ 2469{
2452 /* sanitycheck insmod options */ 2470 /* sanitycheck insmod options */
diff --git a/drivers/media/video/saa7134/saa7134.h b/drivers/media/video/saa7134/saa7134.h
index 6927cbea8624..a0884f639f65 100644
--- a/drivers/media/video/saa7134/saa7134.h
+++ b/drivers/media/video/saa7134/saa7134.h
@@ -34,6 +34,7 @@
34#include <asm/io.h> 34#include <asm/io.h>
35 35
36#include <media/v4l2-common.h> 36#include <media/v4l2-common.h>
37#include <media/v4l2-ioctl.h>
37#include <media/tuner.h> 38#include <media/tuner.h>
38#include <media/ir-common.h> 39#include <media/ir-common.h>
39#include <media/ir-kbd-i2c.h> 40#include <media/ir-kbd-i2c.h>
@@ -560,7 +561,7 @@ struct saa7134_dev {
560 /* SAA7134_MPEG_EMPRESS only */ 561 /* SAA7134_MPEG_EMPRESS only */
561 struct video_device *empress_dev; 562 struct video_device *empress_dev;
562 struct videobuf_queue empress_tsq; 563 struct videobuf_queue empress_tsq;
563 unsigned int empress_users; 564 atomic_t empress_users;
564 struct work_struct empress_workqueue; 565 struct work_struct empress_workqueue;
565 int empress_started; 566 int empress_started;
566 567
@@ -662,8 +663,8 @@ extern unsigned int video_debug;
662extern struct video_device saa7134_video_template; 663extern struct video_device saa7134_video_template;
663extern struct video_device saa7134_radio_template; 664extern struct video_device saa7134_radio_template;
664 665
665int saa7134_g_ctrl(struct file *file, void *priv, struct v4l2_control *c); 666int saa7134_s_ctrl_internal(struct saa7134_dev *dev, struct saa7134_fh *fh, struct v4l2_control *c);
666int saa7134_s_ctrl(struct file *file, void *f, struct v4l2_control *c); 667int saa7134_g_ctrl_internal(struct saa7134_dev *dev, struct saa7134_fh *fh, struct v4l2_control *c);
667int saa7134_queryctrl(struct file *file, void *priv, struct v4l2_queryctrl *c); 668int saa7134_queryctrl(struct file *file, void *priv, struct v4l2_queryctrl *c);
668 669
669int saa7134_videoport_init(struct saa7134_dev *dev); 670int saa7134_videoport_init(struct saa7134_dev *dev);
diff --git a/drivers/media/video/saa717x.c b/drivers/media/video/saa717x.c
index 2220f9569941..af60ede5310d 100644
--- a/drivers/media/video/saa717x.c
+++ b/drivers/media/video/saa717x.c
@@ -35,7 +35,6 @@
35#include <linux/kernel.h> 35#include <linux/kernel.h>
36#include <linux/sched.h> 36#include <linux/sched.h>
37 37
38#include <linux/videodev.h>
39#include <linux/videodev2.h> 38#include <linux/videodev2.h>
40#include <linux/i2c.h> 39#include <linux/i2c.h>
41#include <media/v4l2-common.h> 40#include <media/v4l2-common.h>
diff --git a/drivers/media/video/saa7196.h b/drivers/media/video/saa7196.h
index cd4b6354a7b3..e69de29bb2d1 100644
--- a/drivers/media/video/saa7196.h
+++ b/drivers/media/video/saa7196.h
@@ -1,117 +0,0 @@
1/*
2 Definitions for the Philips SAA7196 digital video decoder,
3 scaler, and clock generator circuit (DESCpro), as used in
4 the PlanB video input of the Powermac 7x00/8x00 series.
5
6 Copyright (C) 1998 Michel Lanners (mlan@cpu.lu)
7
8 The register defines are shamelessly copied from the meteor
9 driver out of NetBSD (with permission),
10 and are copyrighted (c) 1995 Mark Tinguely and Jim Lowe
11 (Thanks !)
12
13 Additional debugging and coding by Takashi Oe (toe@unlinfo.unl.edu)
14
15 The default values used for PlanB are my mistakes.
16*/
17
18/* $Id: saa7196.h,v 1.5 1999/03/26 23:28:47 mlan Exp $ */
19
20#ifndef _SAA7196_H_
21#define _SAA7196_H_
22
23#define SAA7196_NUMREGS 0x31 /* Number of registers (used)*/
24#define NUM_SUPPORTED_NORM 3 /* Number of supported norms by PlanB */
25
26/* Decoder part: */
27#define SAA7196_IDEL 0x00 /* Increment delay */
28#define SAA7196_HSB5 0x01 /* H-sync begin; 50 hz */
29#define SAA7196_HSS5 0x02 /* H-sync stop; 50 hz */
30#define SAA7196_HCB5 0x03 /* H-clamp begin; 50 hz */
31#define SAA7196_HCS5 0x04 /* H-clamp stop; 50 hz */
32#define SAA7196_HSP5 0x05 /* H-sync after PHI1; 50 hz */
33#define SAA7196_LUMC 0x06 /* Luminance control */
34#define SAA7196_HUEC 0x07 /* Hue control */
35#define SAA7196_CKTQ 0x08 /* Colour Killer Threshold QAM (PAL, NTSC) */
36#define SAA7196_CKTS 0x09 /* Colour Killer Threshold SECAM */
37#define SAA7196_PALS 0x0a /* PAL switch sensitivity */
38#define SAA7196_SECAMS 0x0b /* SECAM switch sensitivity */
39#define SAA7196_CGAINC 0x0c /* Chroma gain control */
40#define SAA7196_STDC 0x0d /* Standard/Mode control */
41#define SAA7196_IOCC 0x0e /* I/O and Clock Control */
42#define SAA7196_CTRL1 0x0f /* Control #1 */
43#define SAA7196_CTRL2 0x10 /* Control #2 */
44#define SAA7196_CGAINR 0x11 /* Chroma Gain Reference */
45#define SAA7196_CSAT 0x12 /* Chroma Saturation */
46#define SAA7196_CONT 0x13 /* Luminance Contrast */
47#define SAA7196_HSB6 0x14 /* H-sync begin; 60 hz */
48#define SAA7196_HSS6 0x15 /* H-sync stop; 60 hz */
49#define SAA7196_HCB6 0x16 /* H-clamp begin; 60 hz */
50#define SAA7196_HCS6 0x17 /* H-clamp stop; 60 hz */
51#define SAA7196_HSP6 0x18 /* H-sync after PHI1; 60 hz */
52#define SAA7196_BRIG 0x19 /* Luminance Brightness */
53
54/* Scaler part: */
55#define SAA7196_FMTS 0x20 /* Formats and sequence */
56#define SAA7196_OUTPIX 0x21 /* Output data pixel/line */
57#define SAA7196_INPIX 0x22 /* Input data pixel/line */
58#define SAA7196_HWS 0x23 /* Horiz. window start */
59#define SAA7196_HFILT 0x24 /* Horiz. filter */
60#define SAA7196_OUTLINE 0x25 /* Output data lines/field */
61#define SAA7196_INLINE 0x26 /* Input data lines/field */
62#define SAA7196_VWS 0x27 /* Vertical window start */
63#define SAA7196_VYP 0x28 /* AFS/vertical Y processing */
64#define SAA7196_VBS 0x29 /* Vertical Bypass start */
65#define SAA7196_VBCNT 0x2a /* Vertical Bypass count */
66#define SAA7196_VBP 0x2b /* veritcal Bypass Polarity */
67#define SAA7196_VLOW 0x2c /* Colour-keying lower V limit */
68#define SAA7196_VHIGH 0x2d /* Colour-keying upper V limit */
69#define SAA7196_ULOW 0x2e /* Colour-keying lower U limit */
70#define SAA7196_UHIGH 0x2f /* Colour-keying upper U limit */
71#define SAA7196_DPATH 0x30 /* Data path setting */
72
73/* Initialization default values: */
74
75unsigned char saa_regs[NUM_SUPPORTED_NORM][SAA7196_NUMREGS] = {
76
77/* PAL, 768x576 (no scaling), composite video-in */
78/* Decoder: */
79 { 0x50, 0x30, 0x00, 0xe8, 0xb6, 0xe5, 0x63, 0xff,
80 0xfe, 0xf0, 0xfe, 0xe0, 0x20, 0x06, 0x3b, 0x98,
81 0x00, 0x59, 0x41, 0x45, 0x34, 0x0a, 0xf4, 0xd2,
82 0xe9, 0xa2,
83/* Padding */
84 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
85/* Scaler: */
86 0x72, 0x80, 0x00, 0x03, 0x8d, 0x20, 0x20, 0x12,
87 0xa5, 0x12, 0x00, 0x00, 0x04, 0x00, 0x04, 0x00,
88 0x87 },
89
90/* NTSC, 640x480? (no scaling), composite video-in */
91/* Decoder: */
92 { 0x50, 0x30, 0x00, 0xe8, 0xb6, 0xe5, 0x50, 0x00,
93 0xf8, 0xf0, 0xfe, 0xe0, 0x00, 0x06, 0x3b, 0x98,
94 0x00, 0x2c, 0x3d, 0x40, 0x34, 0x0a, 0xf4, 0xd2,
95 0xe9, 0x98,
96/* Padding */
97 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
98/* Scaler: */
99 0x72, 0x80, 0x80, 0x03, 0x89, 0xf0, 0xf0, 0x0d,
100 0xa0, 0x0d, 0x00, 0x00, 0x04, 0x00, 0x04, 0x00,
101 0x87 },
102
103/* SECAM, 768x576 (no scaling), composite video-in */
104/* Decoder: */
105 { 0x50, 0x30, 0x00, 0xe8, 0xb6, 0xe5, 0x63, 0xff,
106 0xfe, 0xf0, 0xfe, 0xe0, 0x20, 0x07, 0x3b, 0x98,
107 0x00, 0x59, 0x41, 0x45, 0x34, 0x0a, 0xf4, 0xd2,
108 0xe9, 0xa2,
109/* Padding */
110 0x80, 0x80, 0x80, 0x80, 0x80, 0x80,
111/* Scaler: */
112 0x72, 0x80, 0x00, 0x03, 0x8d, 0x20, 0x20, 0x12,
113 0xa5, 0x12, 0x00, 0x00, 0x04, 0x00, 0x04, 0x00,
114 0x87 }
115 };
116
117#endif /* _SAA7196_H_ */
diff --git a/drivers/media/video/se401.c b/drivers/media/video/se401.c
index 1cd629380f71..f481277892da 100644
--- a/drivers/media/video/se401.c
+++ b/drivers/media/video/se401.c
@@ -1230,9 +1230,7 @@ static const struct file_operations se401_fops = {
1230 .llseek = no_llseek, 1230 .llseek = no_llseek,
1231}; 1231};
1232static struct video_device se401_template = { 1232static struct video_device se401_template = {
1233 .owner = THIS_MODULE,
1234 .name = "se401 USB camera", 1233 .name = "se401 USB camera",
1235 .type = VID_TYPE_CAPTURE,
1236 .fops = &se401_fops, 1234 .fops = &se401_fops,
1237}; 1235};
1238 1236
diff --git a/drivers/media/video/se401.h b/drivers/media/video/se401.h
index 835ef872e803..2ce685db5d8b 100644
--- a/drivers/media/video/se401.h
+++ b/drivers/media/video/se401.h
@@ -5,6 +5,7 @@
5#include <asm/uaccess.h> 5#include <asm/uaccess.h>
6#include <linux/videodev.h> 6#include <linux/videodev.h>
7#include <media/v4l2-common.h> 7#include <media/v4l2-common.h>
8#include <media/v4l2-ioctl.h>
8#include <linux/mutex.h> 9#include <linux/mutex.h>
9 10
10#define se401_DEBUG /* Turn on debug messages */ 11#define se401_DEBUG /* Turn on debug messages */
diff --git a/drivers/media/video/sh_mobile_ceu_camera.c b/drivers/media/video/sh_mobile_ceu_camera.c
index 012005e1a77b..f7ca3cb9340a 100644
--- a/drivers/media/video/sh_mobile_ceu_camera.c
+++ b/drivers/media/video/sh_mobile_ceu_camera.c
@@ -91,6 +91,7 @@ struct sh_mobile_ceu_dev {
91 void __iomem *base; 91 void __iomem *base;
92 unsigned long video_limit; 92 unsigned long video_limit;
93 93
94 /* lock used to protect videobuf */
94 spinlock_t lock; 95 spinlock_t lock;
95 struct list_head capture; 96 struct list_head capture;
96 struct videobuf_buffer *active; 97 struct videobuf_buffer *active;
diff --git a/drivers/media/video/sn9c102/sn9c102.h b/drivers/media/video/sn9c102/sn9c102.h
index 0c8d87d8d18d..cbfc44433b99 100644
--- a/drivers/media/video/sn9c102/sn9c102.h
+++ b/drivers/media/video/sn9c102/sn9c102.h
@@ -25,6 +25,7 @@
25#include <linux/usb.h> 25#include <linux/usb.h>
26#include <linux/videodev2.h> 26#include <linux/videodev2.h>
27#include <media/v4l2-common.h> 27#include <media/v4l2-common.h>
28#include <media/v4l2-ioctl.h>
28#include <linux/device.h> 29#include <linux/device.h>
29#include <linux/list.h> 30#include <linux/list.h>
30#include <linux/spinlock.h> 31#include <linux/spinlock.h>
diff --git a/drivers/media/video/sn9c102/sn9c102_core.c b/drivers/media/video/sn9c102/sn9c102_core.c
index 7f9c7bcf3c85..23408764d0ef 100644
--- a/drivers/media/video/sn9c102/sn9c102_core.c
+++ b/drivers/media/video/sn9c102/sn9c102_core.c
@@ -1038,8 +1038,7 @@ static ssize_t sn9c102_show_reg(struct device* cd,
1038 if (mutex_lock_interruptible(&sn9c102_sysfs_lock)) 1038 if (mutex_lock_interruptible(&sn9c102_sysfs_lock))
1039 return -ERESTARTSYS; 1039 return -ERESTARTSYS;
1040 1040
1041 cam = video_get_drvdata(container_of(cd, struct video_device, 1041 cam = video_get_drvdata(container_of(cd, struct video_device, dev));
1042 class_dev));
1043 if (!cam) { 1042 if (!cam) {
1044 mutex_unlock(&sn9c102_sysfs_lock); 1043 mutex_unlock(&sn9c102_sysfs_lock);
1045 return -ENODEV; 1044 return -ENODEV;
@@ -1064,8 +1063,7 @@ sn9c102_store_reg(struct device* cd, struct device_attribute *attr,
1064 if (mutex_lock_interruptible(&sn9c102_sysfs_lock)) 1063 if (mutex_lock_interruptible(&sn9c102_sysfs_lock))
1065 return -ERESTARTSYS; 1064 return -ERESTARTSYS;
1066 1065
1067 cam = video_get_drvdata(container_of(cd, struct video_device, 1066 cam = video_get_drvdata(container_of(cd, struct video_device, dev));
1068 class_dev));
1069 if (!cam) { 1067 if (!cam) {
1070 mutex_unlock(&sn9c102_sysfs_lock); 1068 mutex_unlock(&sn9c102_sysfs_lock);
1071 return -ENODEV; 1069 return -ENODEV;
@@ -1098,8 +1096,7 @@ static ssize_t sn9c102_show_val(struct device* cd,
1098 if (mutex_lock_interruptible(&sn9c102_sysfs_lock)) 1096 if (mutex_lock_interruptible(&sn9c102_sysfs_lock))
1099 return -ERESTARTSYS; 1097 return -ERESTARTSYS;
1100 1098
1101 cam = video_get_drvdata(container_of(cd, struct video_device, 1099 cam = video_get_drvdata(container_of(cd, struct video_device, dev));
1102 class_dev));
1103 if (!cam) { 1100 if (!cam) {
1104 mutex_unlock(&sn9c102_sysfs_lock); 1101 mutex_unlock(&sn9c102_sysfs_lock);
1105 return -ENODEV; 1102 return -ENODEV;
@@ -1132,8 +1129,7 @@ sn9c102_store_val(struct device* cd, struct device_attribute *attr,
1132 if (mutex_lock_interruptible(&sn9c102_sysfs_lock)) 1129 if (mutex_lock_interruptible(&sn9c102_sysfs_lock))
1133 return -ERESTARTSYS; 1130 return -ERESTARTSYS;
1134 1131
1135 cam = video_get_drvdata(container_of(cd, struct video_device, 1132 cam = video_get_drvdata(container_of(cd, struct video_device, dev));
1136 class_dev));
1137 if (!cam) { 1133 if (!cam) {
1138 mutex_unlock(&sn9c102_sysfs_lock); 1134 mutex_unlock(&sn9c102_sysfs_lock);
1139 return -ENODEV; 1135 return -ENODEV;
@@ -1170,8 +1166,7 @@ static ssize_t sn9c102_show_i2c_reg(struct device* cd,
1170 if (mutex_lock_interruptible(&sn9c102_sysfs_lock)) 1166 if (mutex_lock_interruptible(&sn9c102_sysfs_lock))
1171 return -ERESTARTSYS; 1167 return -ERESTARTSYS;
1172 1168
1173 cam = video_get_drvdata(container_of(cd, struct video_device, 1169 cam = video_get_drvdata(container_of(cd, struct video_device, dev));
1174 class_dev));
1175 if (!cam) { 1170 if (!cam) {
1176 mutex_unlock(&sn9c102_sysfs_lock); 1171 mutex_unlock(&sn9c102_sysfs_lock);
1177 return -ENODEV; 1172 return -ENODEV;
@@ -1198,8 +1193,7 @@ sn9c102_store_i2c_reg(struct device* cd, struct device_attribute *attr,
1198 if (mutex_lock_interruptible(&sn9c102_sysfs_lock)) 1193 if (mutex_lock_interruptible(&sn9c102_sysfs_lock))
1199 return -ERESTARTSYS; 1194 return -ERESTARTSYS;
1200 1195
1201 cam = video_get_drvdata(container_of(cd, struct video_device, 1196 cam = video_get_drvdata(container_of(cd, struct video_device, dev));
1202 class_dev));
1203 if (!cam) { 1197 if (!cam) {
1204 mutex_unlock(&sn9c102_sysfs_lock); 1198 mutex_unlock(&sn9c102_sysfs_lock);
1205 return -ENODEV; 1199 return -ENODEV;
@@ -1232,8 +1226,7 @@ static ssize_t sn9c102_show_i2c_val(struct device* cd,
1232 if (mutex_lock_interruptible(&sn9c102_sysfs_lock)) 1226 if (mutex_lock_interruptible(&sn9c102_sysfs_lock))
1233 return -ERESTARTSYS; 1227 return -ERESTARTSYS;
1234 1228
1235 cam = video_get_drvdata(container_of(cd, struct video_device, 1229 cam = video_get_drvdata(container_of(cd, struct video_device, dev));
1236 class_dev));
1237 if (!cam) { 1230 if (!cam) {
1238 mutex_unlock(&sn9c102_sysfs_lock); 1231 mutex_unlock(&sn9c102_sysfs_lock);
1239 return -ENODEV; 1232 return -ENODEV;
@@ -1271,8 +1264,7 @@ sn9c102_store_i2c_val(struct device* cd, struct device_attribute *attr,
1271 if (mutex_lock_interruptible(&sn9c102_sysfs_lock)) 1264 if (mutex_lock_interruptible(&sn9c102_sysfs_lock))
1272 return -ERESTARTSYS; 1265 return -ERESTARTSYS;
1273 1266
1274 cam = video_get_drvdata(container_of(cd, struct video_device, 1267 cam = video_get_drvdata(container_of(cd, struct video_device, dev));
1275 class_dev));
1276 if (!cam) { 1268 if (!cam) {
1277 mutex_unlock(&sn9c102_sysfs_lock); 1269 mutex_unlock(&sn9c102_sysfs_lock);
1278 return -ENODEV; 1270 return -ENODEV;
@@ -1318,8 +1310,7 @@ sn9c102_store_green(struct device* cd, struct device_attribute *attr,
1318 if (mutex_lock_interruptible(&sn9c102_sysfs_lock)) 1310 if (mutex_lock_interruptible(&sn9c102_sysfs_lock))
1319 return -ERESTARTSYS; 1311 return -ERESTARTSYS;
1320 1312
1321 cam = video_get_drvdata(container_of(cd, struct video_device, 1313 cam = video_get_drvdata(container_of(cd, struct video_device, dev));
1322 class_dev));
1323 if (!cam) { 1314 if (!cam) {
1324 mutex_unlock(&sn9c102_sysfs_lock); 1315 mutex_unlock(&sn9c102_sysfs_lock);
1325 return -ENODEV; 1316 return -ENODEV;
@@ -1400,8 +1391,7 @@ static ssize_t sn9c102_show_frame_header(struct device* cd,
1400 struct sn9c102_device* cam; 1391 struct sn9c102_device* cam;
1401 ssize_t count; 1392 ssize_t count;
1402 1393
1403 cam = video_get_drvdata(container_of(cd, struct video_device, 1394 cam = video_get_drvdata(container_of(cd, struct video_device, dev));
1404 class_dev));
1405 if (!cam) 1395 if (!cam)
1406 return -ENODEV; 1396 return -ENODEV;
1407 1397
@@ -1428,49 +1418,49 @@ static DEVICE_ATTR(frame_header, S_IRUGO, sn9c102_show_frame_header, NULL);
1428 1418
1429static int sn9c102_create_sysfs(struct sn9c102_device* cam) 1419static int sn9c102_create_sysfs(struct sn9c102_device* cam)
1430{ 1420{
1431 struct device *classdev = &(cam->v4ldev->class_dev); 1421 struct device *dev = &(cam->v4ldev->dev);
1432 int err = 0; 1422 int err = 0;
1433 1423
1434 if ((err = device_create_file(classdev, &dev_attr_reg))) 1424 if ((err = device_create_file(dev, &dev_attr_reg)))
1435 goto err_out; 1425 goto err_out;
1436 if ((err = device_create_file(classdev, &dev_attr_val))) 1426 if ((err = device_create_file(dev, &dev_attr_val)))
1437 goto err_reg; 1427 goto err_reg;
1438 if ((err = device_create_file(classdev, &dev_attr_frame_header))) 1428 if ((err = device_create_file(dev, &dev_attr_frame_header)))
1439 goto err_val; 1429 goto err_val;
1440 1430
1441 if (cam->sensor.sysfs_ops) { 1431 if (cam->sensor.sysfs_ops) {
1442 if ((err = device_create_file(classdev, &dev_attr_i2c_reg))) 1432 if ((err = device_create_file(dev, &dev_attr_i2c_reg)))
1443 goto err_frame_header; 1433 goto err_frame_header;
1444 if ((err = device_create_file(classdev, &dev_attr_i2c_val))) 1434 if ((err = device_create_file(dev, &dev_attr_i2c_val)))
1445 goto err_i2c_reg; 1435 goto err_i2c_reg;
1446 } 1436 }
1447 1437
1448 if (cam->bridge == BRIDGE_SN9C101 || cam->bridge == BRIDGE_SN9C102) { 1438 if (cam->bridge == BRIDGE_SN9C101 || cam->bridge == BRIDGE_SN9C102) {
1449 if ((err = device_create_file(classdev, &dev_attr_green))) 1439 if ((err = device_create_file(dev, &dev_attr_green)))
1450 goto err_i2c_val; 1440 goto err_i2c_val;
1451 } else { 1441 } else {
1452 if ((err = device_create_file(classdev, &dev_attr_blue))) 1442 if ((err = device_create_file(dev, &dev_attr_blue)))
1453 goto err_i2c_val; 1443 goto err_i2c_val;
1454 if ((err = device_create_file(classdev, &dev_attr_red))) 1444 if ((err = device_create_file(dev, &dev_attr_red)))
1455 goto err_blue; 1445 goto err_blue;
1456 } 1446 }
1457 1447
1458 return 0; 1448 return 0;
1459 1449
1460err_blue: 1450err_blue:
1461 device_remove_file(classdev, &dev_attr_blue); 1451 device_remove_file(dev, &dev_attr_blue);
1462err_i2c_val: 1452err_i2c_val:
1463 if (cam->sensor.sysfs_ops) 1453 if (cam->sensor.sysfs_ops)
1464 device_remove_file(classdev, &dev_attr_i2c_val); 1454 device_remove_file(dev, &dev_attr_i2c_val);
1465err_i2c_reg: 1455err_i2c_reg:
1466 if (cam->sensor.sysfs_ops) 1456 if (cam->sensor.sysfs_ops)
1467 device_remove_file(classdev, &dev_attr_i2c_reg); 1457 device_remove_file(dev, &dev_attr_i2c_reg);
1468err_frame_header: 1458err_frame_header:
1469 device_remove_file(classdev, &dev_attr_frame_header); 1459 device_remove_file(dev, &dev_attr_frame_header);
1470err_val: 1460err_val:
1471 device_remove_file(classdev, &dev_attr_val); 1461 device_remove_file(dev, &dev_attr_val);
1472err_reg: 1462err_reg:
1473 device_remove_file(classdev, &dev_attr_reg); 1463 device_remove_file(dev, &dev_attr_reg);
1474err_out: 1464err_out:
1475 return err; 1465 return err;
1476} 1466}
@@ -3319,8 +3309,6 @@ sn9c102_usb_probe(struct usb_interface* intf, const struct usb_device_id* id)
3319 } 3309 }
3320 3310
3321 strcpy(cam->v4ldev->name, "SN9C1xx PC Camera"); 3311 strcpy(cam->v4ldev->name, "SN9C1xx PC Camera");
3322 cam->v4ldev->owner = THIS_MODULE;
3323 cam->v4ldev->type = VID_TYPE_CAPTURE | VID_TYPE_SCALES;
3324 cam->v4ldev->fops = &sn9c102_fops; 3312 cam->v4ldev->fops = &sn9c102_fops;
3325 cam->v4ldev->minor = video_nr[dev_nr]; 3313 cam->v4ldev->minor = video_nr[dev_nr];
3326 cam->v4ldev->release = video_device_release; 3314 cam->v4ldev->release = video_device_release;
diff --git a/drivers/media/video/soc_camera.c b/drivers/media/video/soc_camera.c
index e39b98f1eca4..b6be5ee678b6 100644
--- a/drivers/media/video/soc_camera.c
+++ b/drivers/media/video/soc_camera.c
@@ -25,6 +25,7 @@
25#include <linux/vmalloc.h> 25#include <linux/vmalloc.h>
26 26
27#include <media/v4l2-common.h> 27#include <media/v4l2-common.h>
28#include <media/v4l2-ioctl.h>
28#include <media/v4l2-dev.h> 29#include <media/v4l2-dev.h>
29#include <media/videobuf-core.h> 30#include <media/videobuf-core.h>
30#include <media/soc_camera.h> 31#include <media/soc_camera.h>
@@ -193,7 +194,7 @@ static int soc_camera_open(struct inode *inode, struct file *file)
193 mutex_lock(&video_lock); 194 mutex_lock(&video_lock);
194 195
195 vdev = video_devdata(file); 196 vdev = video_devdata(file);
196 icd = container_of(vdev->dev, struct soc_camera_device, dev); 197 icd = container_of(vdev->parent, struct soc_camera_device, dev);
197 ici = to_soc_camera_host(icd->dev.parent); 198 ici = to_soc_camera_host(icd->dev.parent);
198 199
199 if (!try_module_get(icd->ops->owner)) { 200 if (!try_module_get(icd->ops->owner)) {
@@ -258,7 +259,7 @@ static int soc_camera_close(struct inode *inode, struct file *file)
258 259
259 vfree(icf); 260 vfree(icf);
260 261
261 dev_dbg(vdev->dev, "camera device close\n"); 262 dev_dbg(vdev->parent, "camera device close\n");
262 263
263 return 0; 264 return 0;
264} 265}
@@ -271,7 +272,7 @@ static ssize_t soc_camera_read(struct file *file, char __user *buf,
271 struct video_device *vdev = icd->vdev; 272 struct video_device *vdev = icd->vdev;
272 int err = -EINVAL; 273 int err = -EINVAL;
273 274
274 dev_err(vdev->dev, "camera device read not implemented\n"); 275 dev_err(vdev->parent, "camera device read not implemented\n");
275 276
276 return err; 277 return err;
277} 278}
@@ -861,6 +862,35 @@ void soc_camera_device_unregister(struct soc_camera_device *icd)
861} 862}
862EXPORT_SYMBOL(soc_camera_device_unregister); 863EXPORT_SYMBOL(soc_camera_device_unregister);
863 864
865static const struct v4l2_ioctl_ops soc_camera_ioctl_ops = {
866 .vidioc_querycap = soc_camera_querycap,
867 .vidioc_g_fmt_vid_cap = soc_camera_g_fmt_vid_cap,
868 .vidioc_enum_fmt_vid_cap = soc_camera_enum_fmt_vid_cap,
869 .vidioc_s_fmt_vid_cap = soc_camera_s_fmt_vid_cap,
870 .vidioc_enum_input = soc_camera_enum_input,
871 .vidioc_g_input = soc_camera_g_input,
872 .vidioc_s_input = soc_camera_s_input,
873 .vidioc_s_std = soc_camera_s_std,
874 .vidioc_reqbufs = soc_camera_reqbufs,
875 .vidioc_try_fmt_vid_cap = soc_camera_try_fmt_vid_cap,
876 .vidioc_querybuf = soc_camera_querybuf,
877 .vidioc_qbuf = soc_camera_qbuf,
878 .vidioc_dqbuf = soc_camera_dqbuf,
879 .vidioc_streamon = soc_camera_streamon,
880 .vidioc_streamoff = soc_camera_streamoff,
881 .vidioc_queryctrl = soc_camera_queryctrl,
882 .vidioc_g_ctrl = soc_camera_g_ctrl,
883 .vidioc_s_ctrl = soc_camera_s_ctrl,
884 .vidioc_cropcap = soc_camera_cropcap,
885 .vidioc_g_crop = soc_camera_g_crop,
886 .vidioc_s_crop = soc_camera_s_crop,
887 .vidioc_g_chip_ident = soc_camera_g_chip_ident,
888#ifdef CONFIG_VIDEO_ADV_DEBUG
889 .vidioc_g_register = soc_camera_g_register,
890 .vidioc_s_register = soc_camera_s_register,
891#endif
892};
893
864int soc_camera_video_start(struct soc_camera_device *icd) 894int soc_camera_video_start(struct soc_camera_device *icd)
865{ 895{
866 struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent); 896 struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent);
@@ -877,45 +907,19 @@ int soc_camera_video_start(struct soc_camera_device *icd)
877 907
878 strlcpy(vdev->name, ici->drv_name, sizeof(vdev->name)); 908 strlcpy(vdev->name, ici->drv_name, sizeof(vdev->name));
879 /* Maybe better &ici->dev */ 909 /* Maybe better &ici->dev */
880 vdev->dev = &icd->dev; 910 vdev->parent = &icd->dev;
881 vdev->type = VID_TYPE_CAPTURE;
882 vdev->current_norm = V4L2_STD_UNKNOWN; 911 vdev->current_norm = V4L2_STD_UNKNOWN;
883 vdev->fops = &soc_camera_fops; 912 vdev->fops = &soc_camera_fops;
913 vdev->ioctl_ops = &soc_camera_ioctl_ops;
884 vdev->release = video_device_release; 914 vdev->release = video_device_release;
885 vdev->minor = -1; 915 vdev->minor = -1;
886 vdev->tvnorms = V4L2_STD_UNKNOWN, 916 vdev->tvnorms = V4L2_STD_UNKNOWN,
887 vdev->vidioc_querycap = soc_camera_querycap;
888 vdev->vidioc_g_fmt_vid_cap = soc_camera_g_fmt_vid_cap;
889 vdev->vidioc_enum_fmt_vid_cap = soc_camera_enum_fmt_vid_cap;
890 vdev->vidioc_s_fmt_vid_cap = soc_camera_s_fmt_vid_cap;
891 vdev->vidioc_enum_input = soc_camera_enum_input;
892 vdev->vidioc_g_input = soc_camera_g_input;
893 vdev->vidioc_s_input = soc_camera_s_input;
894 vdev->vidioc_s_std = soc_camera_s_std;
895 vdev->vidioc_reqbufs = soc_camera_reqbufs;
896 vdev->vidioc_try_fmt_vid_cap = soc_camera_try_fmt_vid_cap;
897 vdev->vidioc_querybuf = soc_camera_querybuf;
898 vdev->vidioc_qbuf = soc_camera_qbuf;
899 vdev->vidioc_dqbuf = soc_camera_dqbuf;
900 vdev->vidioc_streamon = soc_camera_streamon;
901 vdev->vidioc_streamoff = soc_camera_streamoff;
902 vdev->vidioc_queryctrl = soc_camera_queryctrl;
903 vdev->vidioc_g_ctrl = soc_camera_g_ctrl;
904 vdev->vidioc_s_ctrl = soc_camera_s_ctrl;
905 vdev->vidioc_cropcap = soc_camera_cropcap;
906 vdev->vidioc_g_crop = soc_camera_g_crop;
907 vdev->vidioc_s_crop = soc_camera_s_crop;
908 vdev->vidioc_g_chip_ident = soc_camera_g_chip_ident;
909#ifdef CONFIG_VIDEO_ADV_DEBUG
910 vdev->vidioc_g_register = soc_camera_g_register;
911 vdev->vidioc_s_register = soc_camera_s_register;
912#endif
913 917
914 icd->current_fmt = &icd->formats[0]; 918 icd->current_fmt = &icd->formats[0];
915 919
916 err = video_register_device(vdev, VFL_TYPE_GRABBER, vdev->minor); 920 err = video_register_device(vdev, VFL_TYPE_GRABBER, vdev->minor);
917 if (err < 0) { 921 if (err < 0) {
918 dev_err(vdev->dev, "video_register_device failed\n"); 922 dev_err(vdev->parent, "video_register_device failed\n");
919 goto evidregd; 923 goto evidregd;
920 } 924 }
921 icd->vdev = vdev; 925 icd->vdev = vdev;
diff --git a/drivers/media/video/stk-webcam.c b/drivers/media/video/stk-webcam.c
index f308c38d744f..ad36af30e099 100644
--- a/drivers/media/video/stk-webcam.c
+++ b/drivers/media/video/stk-webcam.c
@@ -34,6 +34,7 @@
34#include <linux/vmalloc.h> 34#include <linux/vmalloc.h>
35#include <linux/videodev2.h> 35#include <linux/videodev2.h>
36#include <media/v4l2-common.h> 36#include <media/v4l2-common.h>
37#include <media/v4l2-ioctl.h>
37 38
38#include "stk-webcam.h" 39#include "stk-webcam.h"
39 40
@@ -340,17 +341,19 @@ static int stk_create_sysfs_files(struct video_device *vdev)
340{ 341{
341 int ret; 342 int ret;
342 343
343 ret = video_device_create_file(vdev, &dev_attr_brightness); 344 ret = device_create_file(&vdev->dev, &dev_attr_brightness);
344 ret += video_device_create_file(vdev, &dev_attr_hflip); 345 ret += device_create_file(&vdev->dev, &dev_attr_hflip);
345 ret += video_device_create_file(vdev, &dev_attr_vflip); 346 ret += device_create_file(&vdev->dev, &dev_attr_vflip);
347 if (ret)
348 STK_WARNING("Could not create sysfs files\n");
346 return ret; 349 return ret;
347} 350}
348 351
349static void stk_remove_sysfs_files(struct video_device *vdev) 352static void stk_remove_sysfs_files(struct video_device *vdev)
350{ 353{
351 video_device_remove_file(vdev, &dev_attr_brightness); 354 device_remove_file(&vdev->dev, &dev_attr_brightness);
352 video_device_remove_file(vdev, &dev_attr_hflip); 355 device_remove_file(&vdev->dev, &dev_attr_hflip);
353 video_device_remove_file(vdev, &dev_attr_vflip); 356 device_remove_file(&vdev->dev, &dev_attr_vflip);
354} 357}
355 358
356#else 359#else
@@ -442,18 +445,19 @@ static void stk_isoc_handler(struct urb *urb)
442 fb->v4lbuf.bytesused = 0; 445 fb->v4lbuf.bytesused = 0;
443 fill = fb->buffer; 446 fill = fb->buffer;
444 } else if (fb->v4lbuf.bytesused == dev->frame_size) { 447 } else if (fb->v4lbuf.bytesused == dev->frame_size) {
445 list_move_tail(dev->sio_avail.next, 448 if (list_is_singular(&dev->sio_avail)) {
446 &dev->sio_full); 449 /* Always reuse the last buffer */
447 wake_up(&dev->wait_frame); 450 fb->v4lbuf.bytesused = 0;
448 if (list_empty(&dev->sio_avail)) { 451 fill = fb->buffer;
449 (void) (printk_ratelimit() && 452 } else {
450 STK_ERROR("No buffer available\n")); 453 list_move_tail(dev->sio_avail.next,
451 goto resubmit; 454 &dev->sio_full);
455 wake_up(&dev->wait_frame);
456 fb = list_first_entry(&dev->sio_avail,
457 struct stk_sio_buffer, list);
458 fb->v4lbuf.bytesused = 0;
459 fill = fb->buffer;
452 } 460 }
453 fb = list_first_entry(&dev->sio_avail,
454 struct stk_sio_buffer, list);
455 fb->v4lbuf.bytesused = 0;
456 fill = fb->buffer;
457 } 461 }
458 } else { 462 } else {
459 framelen -= 4; 463 framelen -= 4;
@@ -1327,20 +1331,7 @@ static struct file_operations v4l_stk_fops = {
1327 .llseek = no_llseek 1331 .llseek = no_llseek
1328}; 1332};
1329 1333
1330static void stk_v4l_dev_release(struct video_device *vd) 1334static const struct v4l2_ioctl_ops v4l_stk_ioctl_ops = {
1331{
1332}
1333
1334static struct video_device stk_v4l_data = {
1335 .name = "stkwebcam",
1336 .type = VFL_TYPE_GRABBER,
1337 .type2 = VID_TYPE_CAPTURE,
1338 .minor = -1,
1339 .tvnorms = V4L2_STD_UNKNOWN,
1340 .current_norm = V4L2_STD_UNKNOWN,
1341 .fops = &v4l_stk_fops,
1342 .release = stk_v4l_dev_release,
1343
1344 .vidioc_querycap = stk_vidioc_querycap, 1335 .vidioc_querycap = stk_vidioc_querycap,
1345 .vidioc_enum_fmt_vid_cap = stk_vidioc_enum_fmt_vid_cap, 1336 .vidioc_enum_fmt_vid_cap = stk_vidioc_enum_fmt_vid_cap,
1346 .vidioc_try_fmt_vid_cap = stk_vidioc_try_fmt_vid_cap, 1337 .vidioc_try_fmt_vid_cap = stk_vidioc_try_fmt_vid_cap,
@@ -1362,6 +1353,20 @@ static struct video_device stk_v4l_data = {
1362 .vidioc_g_parm = stk_vidioc_g_parm, 1353 .vidioc_g_parm = stk_vidioc_g_parm,
1363}; 1354};
1364 1355
1356static void stk_v4l_dev_release(struct video_device *vd)
1357{
1358}
1359
1360static struct video_device stk_v4l_data = {
1361 .name = "stkwebcam",
1362 .minor = -1,
1363 .tvnorms = V4L2_STD_UNKNOWN,
1364 .current_norm = V4L2_STD_UNKNOWN,
1365 .fops = &v4l_stk_fops,
1366 .ioctl_ops = &v4l_stk_ioctl_ops,
1367 .release = stk_v4l_dev_release,
1368};
1369
1365 1370
1366static int stk_register_video_device(struct stk_camera *dev) 1371static int stk_register_video_device(struct stk_camera *dev)
1367{ 1372{
@@ -1369,7 +1374,7 @@ static int stk_register_video_device(struct stk_camera *dev)
1369 1374
1370 dev->vdev = stk_v4l_data; 1375 dev->vdev = stk_v4l_data;
1371 dev->vdev.debug = debug; 1376 dev->vdev.debug = debug;
1372 dev->vdev.dev = &dev->interface->dev; 1377 dev->vdev.parent = &dev->interface->dev;
1373 dev->vdev.priv = dev; 1378 dev->vdev.priv = dev;
1374 err = video_register_device(&dev->vdev, VFL_TYPE_GRABBER, -1); 1379 err = video_register_device(&dev->vdev, VFL_TYPE_GRABBER, -1);
1375 if (err) 1380 if (err)
diff --git a/drivers/media/video/stradis.c b/drivers/media/video/stradis.c
index c109511f21ea..276bded06ab3 100644
--- a/drivers/media/video/stradis.c
+++ b/drivers/media/video/stradis.c
@@ -43,6 +43,7 @@
43#include <linux/vmalloc.h> 43#include <linux/vmalloc.h>
44#include <linux/videodev.h> 44#include <linux/videodev.h>
45#include <media/v4l2-common.h> 45#include <media/v4l2-common.h>
46#include <media/v4l2-ioctl.h>
46 47
47#include "saa7146.h" 48#include "saa7146.h"
48#include "saa7146reg.h" 49#include "saa7146reg.h"
@@ -1918,7 +1919,6 @@ static const struct file_operations saa_fops = {
1918/* template for video_device-structure */ 1919/* template for video_device-structure */
1919static struct video_device saa_template = { 1920static struct video_device saa_template = {
1920 .name = "SAA7146A", 1921 .name = "SAA7146A",
1921 .type = VID_TYPE_CAPTURE | VID_TYPE_OVERLAY,
1922 .fops = &saa_fops, 1922 .fops = &saa_fops,
1923 .minor = -1, 1923 .minor = -1,
1924}; 1924};
diff --git a/drivers/media/video/stv680.c b/drivers/media/video/stv680.c
index d7f130bedb5f..56dc3d6b5b29 100644
--- a/drivers/media/video/stv680.c
+++ b/drivers/media/video/stv680.c
@@ -66,6 +66,7 @@
66#include <linux/errno.h> 66#include <linux/errno.h>
67#include <linux/videodev.h> 67#include <linux/videodev.h>
68#include <media/v4l2-common.h> 68#include <media/v4l2-common.h>
69#include <media/v4l2-ioctl.h>
69#include <linux/usb.h> 70#include <linux/usb.h>
70#include <linux/mutex.h> 71#include <linux/mutex.h>
71 72
@@ -524,53 +525,54 @@ static int stv680_create_sysfs_files(struct video_device *vdev)
524{ 525{
525 int rc; 526 int rc;
526 527
527 rc = video_device_create_file(vdev, &dev_attr_model); 528 rc = device_create_file(&vdev->dev, &dev_attr_model);
528 if (rc) goto err; 529 if (rc) goto err;
529 rc = video_device_create_file(vdev, &dev_attr_in_use); 530 rc = device_create_file(&vdev->dev, &dev_attr_in_use);
530 if (rc) goto err_model; 531 if (rc) goto err_model;
531 rc = video_device_create_file(vdev, &dev_attr_streaming); 532 rc = device_create_file(&vdev->dev, &dev_attr_streaming);
532 if (rc) goto err_inuse; 533 if (rc) goto err_inuse;
533 rc = video_device_create_file(vdev, &dev_attr_palette); 534 rc = device_create_file(&vdev->dev, &dev_attr_palette);
534 if (rc) goto err_stream; 535 if (rc) goto err_stream;
535 rc = video_device_create_file(vdev, &dev_attr_frames_total); 536 rc = device_create_file(&vdev->dev, &dev_attr_frames_total);
536 if (rc) goto err_pal; 537 if (rc) goto err_pal;
537 rc = video_device_create_file(vdev, &dev_attr_frames_read); 538 rc = device_create_file(&vdev->dev, &dev_attr_frames_read);
538 if (rc) goto err_framtot; 539 if (rc) goto err_framtot;
539 rc = video_device_create_file(vdev, &dev_attr_packets_dropped); 540 rc = device_create_file(&vdev->dev, &dev_attr_packets_dropped);
540 if (rc) goto err_framread; 541 if (rc) goto err_framread;
541 rc = video_device_create_file(vdev, &dev_attr_decoding_errors); 542 rc = device_create_file(&vdev->dev, &dev_attr_decoding_errors);
542 if (rc) goto err_dropped; 543 if (rc) goto err_dropped;
543 544
544 return 0; 545 return 0;
545 546
546err_dropped: 547err_dropped:
547 video_device_remove_file(vdev, &dev_attr_packets_dropped); 548 device_remove_file(&vdev->dev, &dev_attr_packets_dropped);
548err_framread: 549err_framread:
549 video_device_remove_file(vdev, &dev_attr_frames_read); 550 device_remove_file(&vdev->dev, &dev_attr_frames_read);
550err_framtot: 551err_framtot:
551 video_device_remove_file(vdev, &dev_attr_frames_total); 552 device_remove_file(&vdev->dev, &dev_attr_frames_total);
552err_pal: 553err_pal:
553 video_device_remove_file(vdev, &dev_attr_palette); 554 device_remove_file(&vdev->dev, &dev_attr_palette);
554err_stream: 555err_stream:
555 video_device_remove_file(vdev, &dev_attr_streaming); 556 device_remove_file(&vdev->dev, &dev_attr_streaming);
556err_inuse: 557err_inuse:
557 video_device_remove_file(vdev, &dev_attr_in_use); 558 device_remove_file(&vdev->dev, &dev_attr_in_use);
558err_model: 559err_model:
559 video_device_remove_file(vdev, &dev_attr_model); 560 device_remove_file(&vdev->dev, &dev_attr_model);
560err: 561err:
562 PDEBUG(0, "STV(e): Could not create sysfs files");
561 return rc; 563 return rc;
562} 564}
563 565
564static void stv680_remove_sysfs_files(struct video_device *vdev) 566static void stv680_remove_sysfs_files(struct video_device *vdev)
565{ 567{
566 video_device_remove_file(vdev, &dev_attr_model); 568 device_remove_file(&vdev->dev, &dev_attr_model);
567 video_device_remove_file(vdev, &dev_attr_in_use); 569 device_remove_file(&vdev->dev, &dev_attr_in_use);
568 video_device_remove_file(vdev, &dev_attr_streaming); 570 device_remove_file(&vdev->dev, &dev_attr_streaming);
569 video_device_remove_file(vdev, &dev_attr_palette); 571 device_remove_file(&vdev->dev, &dev_attr_palette);
570 video_device_remove_file(vdev, &dev_attr_frames_total); 572 device_remove_file(&vdev->dev, &dev_attr_frames_total);
571 video_device_remove_file(vdev, &dev_attr_frames_read); 573 device_remove_file(&vdev->dev, &dev_attr_frames_read);
572 video_device_remove_file(vdev, &dev_attr_packets_dropped); 574 device_remove_file(&vdev->dev, &dev_attr_packets_dropped);
573 video_device_remove_file(vdev, &dev_attr_decoding_errors); 575 device_remove_file(&vdev->dev, &dev_attr_decoding_errors);
574} 576}
575 577
576/******************************************************************** 578/********************************************************************
@@ -1400,9 +1402,7 @@ static const struct file_operations stv680_fops = {
1400 .llseek = no_llseek, 1402 .llseek = no_llseek,
1401}; 1403};
1402static struct video_device stv680_template = { 1404static struct video_device stv680_template = {
1403 .owner = THIS_MODULE,
1404 .name = "STV0680 USB camera", 1405 .name = "STV0680 USB camera",
1405 .type = VID_TYPE_CAPTURE,
1406 .fops = &stv680_fops, 1406 .fops = &stv680_fops,
1407 .release = video_device_release, 1407 .release = video_device_release,
1408 .minor = -1, 1408 .minor = -1,
@@ -1454,7 +1454,7 @@ static int stv680_probe (struct usb_interface *intf, const struct usb_device_id
1454 goto error; 1454 goto error;
1455 } 1455 }
1456 memcpy(stv680->vdev, &stv680_template, sizeof(stv680_template)); 1456 memcpy(stv680->vdev, &stv680_template, sizeof(stv680_template));
1457 stv680->vdev->dev = &intf->dev; 1457 stv680->vdev->parent = &intf->dev;
1458 video_set_drvdata(stv680->vdev, stv680); 1458 video_set_drvdata(stv680->vdev, stv680);
1459 1459
1460 memcpy (stv680->vdev->name, stv680->camera_name, strlen (stv680->camera_name)); 1460 memcpy (stv680->vdev->name, stv680->camera_name, strlen (stv680->camera_name));
diff --git a/drivers/media/video/tda7432.c b/drivers/media/video/tda7432.c
index ae75c187da79..4963d4264880 100644
--- a/drivers/media/video/tda7432.c
+++ b/drivers/media/video/tda7432.c
@@ -44,10 +44,11 @@
44#include <linux/delay.h> 44#include <linux/delay.h>
45#include <linux/errno.h> 45#include <linux/errno.h>
46#include <linux/slab.h> 46#include <linux/slab.h>
47#include <linux/videodev.h> 47#include <linux/videodev2.h>
48#include <linux/i2c.h> 48#include <linux/i2c.h>
49 49
50#include <media/v4l2-common.h> 50#include <media/v4l2-common.h>
51#include <media/v4l2-ioctl.h>
51#include <media/i2c-addr.h> 52#include <media/i2c-addr.h>
52 53
53#ifndef VIDEO_AUDIO_BALANCE 54#ifndef VIDEO_AUDIO_BALANCE
diff --git a/drivers/media/video/tda9875.c b/drivers/media/video/tda9875.c
index 7a8ce8fb46dc..792f0b079909 100644
--- a/drivers/media/video/tda9875.c
+++ b/drivers/media/video/tda9875.c
@@ -25,7 +25,7 @@
25#include <linux/delay.h> 25#include <linux/delay.h>
26#include <linux/errno.h> 26#include <linux/errno.h>
27#include <linux/slab.h> 27#include <linux/slab.h>
28#include <linux/videodev.h> 28#include <linux/videodev2.h>
29#include <media/v4l2-common.h> 29#include <media/v4l2-common.h>
30#include <linux/i2c.h> 30#include <linux/i2c.h>
31#include <linux/init.h> 31#include <linux/init.h>
diff --git a/drivers/media/video/tlv320aic23b.c b/drivers/media/video/tlv320aic23b.c
index 9220378a5637..281065b9dd2d 100644
--- a/drivers/media/video/tlv320aic23b.c
+++ b/drivers/media/video/tlv320aic23b.c
@@ -29,7 +29,7 @@
29#include <asm/uaccess.h> 29#include <asm/uaccess.h>
30#include <linux/i2c.h> 30#include <linux/i2c.h>
31#include <linux/i2c-id.h> 31#include <linux/i2c-id.h>
32#include <linux/videodev.h> 32#include <linux/videodev2.h>
33#include <media/v4l2-common.h> 33#include <media/v4l2-common.h>
34#include <media/v4l2-i2c-drv-legacy.h> 34#include <media/v4l2-i2c-drv-legacy.h>
35 35
diff --git a/drivers/media/video/tuner-core.c b/drivers/media/video/tuner-core.c
index 93d879dc510f..d806a3556eed 100644
--- a/drivers/media/video/tuner-core.c
+++ b/drivers/media/video/tuner-core.c
@@ -19,6 +19,7 @@
19#include <media/tuner.h> 19#include <media/tuner.h>
20#include <media/tuner-types.h> 20#include <media/tuner-types.h>
21#include <media/v4l2-common.h> 21#include <media/v4l2-common.h>
22#include <media/v4l2-ioctl.h>
22#include <media/v4l2-i2c-drv-legacy.h> 23#include <media/v4l2-i2c-drv-legacy.h>
23#include "mt20xx.h" 24#include "mt20xx.h"
24#include "tda8290.h" 25#include "tda8290.h"
diff --git a/drivers/media/video/tveeprom.c b/drivers/media/video/tveeprom.c
index 9da0e1807ffb..bcc32fa92a81 100644
--- a/drivers/media/video/tveeprom.c
+++ b/drivers/media/video/tveeprom.c
@@ -34,13 +34,13 @@
34#include <linux/kernel.h> 34#include <linux/kernel.h>
35#include <linux/init.h> 35#include <linux/init.h>
36#include <linux/types.h> 36#include <linux/types.h>
37#include <linux/videodev.h> 37#include <linux/videodev2.h>
38#include <linux/i2c.h> 38#include <linux/i2c.h>
39 39
40#include <media/tuner.h> 40#include <media/tuner.h>
41#include <media/tveeprom.h> 41#include <media/tveeprom.h>
42#include <media/v4l2-common.h> 42#include <media/v4l2-common.h>
43#include <media/audiochip.h> 43#include <media/v4l2-chip-ident.h>
44 44
45MODULE_DESCRIPTION("i2c Hauppauge eeprom decoder driver"); 45MODULE_DESCRIPTION("i2c Hauppauge eeprom decoder driver");
46MODULE_AUTHOR("John Klar"); 46MODULE_AUTHOR("John Klar");
@@ -261,70 +261,72 @@ hauppauge_tuner[] =
261 { TUNER_ABSENT, "MaxLinear MXL5005_v2"}, 261 { TUNER_ABSENT, "MaxLinear MXL5005_v2"},
262 { TUNER_PHILIPS_TDA8290, "Philips 18271_8295"}, 262 { TUNER_PHILIPS_TDA8290, "Philips 18271_8295"},
263 /* 150-159 */ 263 /* 150-159 */
264 { TUNER_ABSENT, "Xceive XC5000"}, 264 { TUNER_ABSENT, "Xceive XC5000"},
265}; 265};
266 266
267/* Use V4L2_IDENT_AMBIGUOUS for those audio 'chips' that are
268 * internal to a video chip, i.e. not a separate audio chip. */
267static struct HAUPPAUGE_AUDIOIC 269static struct HAUPPAUGE_AUDIOIC
268{ 270{
269 enum audiochip id; 271 u32 id;
270 char *name; 272 char *name;
271} 273}
272audioIC[] = 274audioIC[] =
273{ 275{
274 /* 0-4 */ 276 /* 0-4 */
275 {AUDIO_CHIP_NONE, "None"}, 277 { V4L2_IDENT_NONE, "None" },
276 {AUDIO_CHIP_TEA6300, "TEA6300"}, 278 { V4L2_IDENT_UNKNOWN, "TEA6300" },
277 {AUDIO_CHIP_TEA6300, "TEA6320"}, 279 { V4L2_IDENT_UNKNOWN, "TEA6320" },
278 {AUDIO_CHIP_TDA985X, "TDA9850"}, 280 { V4L2_IDENT_UNKNOWN, "TDA9850" },
279 {AUDIO_CHIP_MSP34XX, "MSP3400C"}, 281 { V4L2_IDENT_MSPX4XX, "MSP3400C" },
280 /* 5-9 */ 282 /* 5-9 */
281 {AUDIO_CHIP_MSP34XX, "MSP3410D"}, 283 { V4L2_IDENT_MSPX4XX, "MSP3410D" },
282 {AUDIO_CHIP_MSP34XX, "MSP3415"}, 284 { V4L2_IDENT_MSPX4XX, "MSP3415" },
283 {AUDIO_CHIP_MSP34XX, "MSP3430"}, 285 { V4L2_IDENT_MSPX4XX, "MSP3430" },
284 {AUDIO_CHIP_MSP34XX, "MSP3438"}, 286 { V4L2_IDENT_MSPX4XX, "MSP3438" },
285 {AUDIO_CHIP_UNKNOWN, "CS5331"}, 287 { V4L2_IDENT_UNKNOWN, "CS5331" },
286 /* 10-14 */ 288 /* 10-14 */
287 {AUDIO_CHIP_MSP34XX, "MSP3435"}, 289 { V4L2_IDENT_MSPX4XX, "MSP3435" },
288 {AUDIO_CHIP_MSP34XX, "MSP3440"}, 290 { V4L2_IDENT_MSPX4XX, "MSP3440" },
289 {AUDIO_CHIP_MSP34XX, "MSP3445"}, 291 { V4L2_IDENT_MSPX4XX, "MSP3445" },
290 {AUDIO_CHIP_MSP34XX, "MSP3411"}, 292 { V4L2_IDENT_MSPX4XX, "MSP3411" },
291 {AUDIO_CHIP_MSP34XX, "MSP3416"}, 293 { V4L2_IDENT_MSPX4XX, "MSP3416" },
292 /* 15-19 */ 294 /* 15-19 */
293 {AUDIO_CHIP_MSP34XX, "MSP3425"}, 295 { V4L2_IDENT_MSPX4XX, "MSP3425" },
294 {AUDIO_CHIP_MSP34XX, "MSP3451"}, 296 { V4L2_IDENT_MSPX4XX, "MSP3451" },
295 {AUDIO_CHIP_MSP34XX, "MSP3418"}, 297 { V4L2_IDENT_MSPX4XX, "MSP3418" },
296 {AUDIO_CHIP_UNKNOWN, "Type 0x12"}, 298 { V4L2_IDENT_UNKNOWN, "Type 0x12" },
297 {AUDIO_CHIP_UNKNOWN, "OKI7716"}, 299 { V4L2_IDENT_UNKNOWN, "OKI7716" },
298 /* 20-24 */ 300 /* 20-24 */
299 {AUDIO_CHIP_MSP34XX, "MSP4410"}, 301 { V4L2_IDENT_MSPX4XX, "MSP4410" },
300 {AUDIO_CHIP_MSP34XX, "MSP4420"}, 302 { V4L2_IDENT_MSPX4XX, "MSP4420" },
301 {AUDIO_CHIP_MSP34XX, "MSP4440"}, 303 { V4L2_IDENT_MSPX4XX, "MSP4440" },
302 {AUDIO_CHIP_MSP34XX, "MSP4450"}, 304 { V4L2_IDENT_MSPX4XX, "MSP4450" },
303 {AUDIO_CHIP_MSP34XX, "MSP4408"}, 305 { V4L2_IDENT_MSPX4XX, "MSP4408" },
304 /* 25-29 */ 306 /* 25-29 */
305 {AUDIO_CHIP_MSP34XX, "MSP4418"}, 307 { V4L2_IDENT_MSPX4XX, "MSP4418" },
306 {AUDIO_CHIP_MSP34XX, "MSP4428"}, 308 { V4L2_IDENT_MSPX4XX, "MSP4428" },
307 {AUDIO_CHIP_MSP34XX, "MSP4448"}, 309 { V4L2_IDENT_MSPX4XX, "MSP4448" },
308 {AUDIO_CHIP_MSP34XX, "MSP4458"}, 310 { V4L2_IDENT_MSPX4XX, "MSP4458" },
309 {AUDIO_CHIP_MSP34XX, "Type 0x1d"}, 311 { V4L2_IDENT_MSPX4XX, "Type 0x1d" },
310 /* 30-34 */ 312 /* 30-34 */
311 {AUDIO_CHIP_INTERNAL, "CX880"}, 313 { V4L2_IDENT_AMBIGUOUS, "CX880" },
312 {AUDIO_CHIP_INTERNAL, "CX881"}, 314 { V4L2_IDENT_AMBIGUOUS, "CX881" },
313 {AUDIO_CHIP_INTERNAL, "CX883"}, 315 { V4L2_IDENT_AMBIGUOUS, "CX883" },
314 {AUDIO_CHIP_INTERNAL, "CX882"}, 316 { V4L2_IDENT_AMBIGUOUS, "CX882" },
315 {AUDIO_CHIP_INTERNAL, "CX25840"}, 317 { V4L2_IDENT_AMBIGUOUS, "CX25840" },
316 /* 35-39 */ 318 /* 35-39 */
317 {AUDIO_CHIP_INTERNAL, "CX25841"}, 319 { V4L2_IDENT_AMBIGUOUS, "CX25841" },
318 {AUDIO_CHIP_INTERNAL, "CX25842"}, 320 { V4L2_IDENT_AMBIGUOUS, "CX25842" },
319 {AUDIO_CHIP_INTERNAL, "CX25843"}, 321 { V4L2_IDENT_AMBIGUOUS, "CX25843" },
320 {AUDIO_CHIP_INTERNAL, "CX23418"}, 322 { V4L2_IDENT_AMBIGUOUS, "CX23418" },
321 {AUDIO_CHIP_INTERNAL, "CX23885"}, 323 { V4L2_IDENT_AMBIGUOUS, "CX23885" },
322 /* 40-44 */ 324 /* 40-44 */
323 {AUDIO_CHIP_INTERNAL, "CX23888"}, 325 { V4L2_IDENT_AMBIGUOUS, "CX23888" },
324 {AUDIO_CHIP_INTERNAL, "SAA7131"}, 326 { V4L2_IDENT_AMBIGUOUS, "SAA7131" },
325 {AUDIO_CHIP_INTERNAL, "CX23887"}, 327 { V4L2_IDENT_AMBIGUOUS, "CX23887" },
326 {AUDIO_CHIP_INTERNAL, "SAA7164"}, 328 { V4L2_IDENT_AMBIGUOUS, "SAA7164" },
327 {AUDIO_CHIP_INTERNAL, "AU8522"}, 329 { V4L2_IDENT_AMBIGUOUS, "AU8522" },
328}; 330};
329 331
330/* This list is supplied by Hauppauge. Thanks! */ 332/* This list is supplied by Hauppauge. Thanks! */
@@ -483,7 +485,7 @@ void tveeprom_hauppauge_analog(struct i2c_client *c, struct tveeprom *tvee,
483 tvee->has_radio = eeprom_data[i+len-1]; 485 tvee->has_radio = eeprom_data[i+len-1];
484 /* old style tag, don't know how to detect 486 /* old style tag, don't know how to detect
485 IR presence, mark as unknown. */ 487 IR presence, mark as unknown. */
486 tvee->has_ir = -1; 488 tvee->has_ir = 0;
487 tvee->model = 489 tvee->model =
488 eeprom_data[i+8] + 490 eeprom_data[i+8] +
489 (eeprom_data[i+9] << 8); 491 (eeprom_data[i+9] << 8);
@@ -509,7 +511,7 @@ void tveeprom_hauppauge_analog(struct i2c_client *c, struct tveeprom *tvee,
509 if (audioic < ARRAY_SIZE(audioIC)) 511 if (audioic < ARRAY_SIZE(audioIC))
510 tvee->audio_processor = audioIC[audioic].id; 512 tvee->audio_processor = audioIC[audioic].id;
511 else 513 else
512 tvee->audio_processor = AUDIO_CHIP_UNKNOWN; 514 tvee->audio_processor = V4L2_IDENT_UNKNOWN;
513 break; 515 break;
514 516
515 /* case 0x03: tag 'EEInfo' */ 517 /* case 0x03: tag 'EEInfo' */
@@ -542,7 +544,7 @@ void tveeprom_hauppauge_analog(struct i2c_client *c, struct tveeprom *tvee,
542 if (audioic < ARRAY_SIZE(audioIC)) 544 if (audioic < ARRAY_SIZE(audioIC))
543 tvee->audio_processor = audioIC[audioic].id; 545 tvee->audio_processor = audioIC[audioic].id;
544 else 546 else
545 tvee->audio_processor = AUDIO_CHIP_UNKNOWN; 547 tvee->audio_processor = V4L2_IDENT_UNKNOWN;
546 548
547 break; 549 break;
548 550
@@ -603,7 +605,7 @@ void tveeprom_hauppauge_analog(struct i2c_client *c, struct tveeprom *tvee,
603 605
604 case 0x0f: 606 case 0x0f:
605 /* tag 'IRInfo' */ 607 /* tag 'IRInfo' */
606 tvee->has_ir = eeprom_data[i+1]; 608 tvee->has_ir = 1 | (eeprom_data[i+1] << 1);
607 break; 609 break;
608 610
609 /* case 0x10: tag 'VBIInfo' */ 611 /* case 0x10: tag 'VBIInfo' */
@@ -690,7 +692,7 @@ void tveeprom_hauppauge_analog(struct i2c_client *c, struct tveeprom *tvee,
690 t_fmt_name2[6], t_fmt_name2[7], t_format2); 692 t_fmt_name2[6], t_fmt_name2[7], t_format2);
691 if (audioic < 0) { 693 if (audioic < 0) {
692 tveeprom_info("audio processor is unknown (no idx)\n"); 694 tveeprom_info("audio processor is unknown (no idx)\n");
693 tvee->audio_processor = AUDIO_CHIP_UNKNOWN; 695 tvee->audio_processor = V4L2_IDENT_UNKNOWN;
694 } else { 696 } else {
695 if (audioic < ARRAY_SIZE(audioIC)) 697 if (audioic < ARRAY_SIZE(audioIC))
696 tveeprom_info("audio processor is %s (idx %d)\n", 698 tveeprom_info("audio processor is %s (idx %d)\n",
@@ -703,14 +705,14 @@ void tveeprom_hauppauge_analog(struct i2c_client *c, struct tveeprom *tvee,
703 tveeprom_info("decoder processor is %s (idx %d)\n", 705 tveeprom_info("decoder processor is %s (idx %d)\n",
704 STRM(decoderIC, tvee->decoder_processor), 706 STRM(decoderIC, tvee->decoder_processor),
705 tvee->decoder_processor); 707 tvee->decoder_processor);
706 if (tvee->has_ir == -1) 708 if (tvee->has_ir)
707 tveeprom_info("has %sradio\n",
708 tvee->has_radio ? "" : "no ");
709 else
710 tveeprom_info("has %sradio, has %sIR receiver, has %sIR transmitter\n", 709 tveeprom_info("has %sradio, has %sIR receiver, has %sIR transmitter\n",
711 tvee->has_radio ? "" : "no ", 710 tvee->has_radio ? "" : "no ",
712 (tvee->has_ir & 1) ? "" : "no ", 711 (tvee->has_ir & 2) ? "" : "no ",
713 (tvee->has_ir & 2) ? "" : "no "); 712 (tvee->has_ir & 4) ? "" : "no ");
713 else
714 tveeprom_info("has %sradio\n",
715 tvee->has_radio ? "" : "no ");
714} 716}
715EXPORT_SYMBOL(tveeprom_hauppauge_analog); 717EXPORT_SYMBOL(tveeprom_hauppauge_analog);
716 718
diff --git a/drivers/media/video/tvp5150.c b/drivers/media/video/tvp5150.c
index 6a3af1005f03..28af5ce5560d 100644
--- a/drivers/media/video/tvp5150.c
+++ b/drivers/media/video/tvp5150.c
@@ -6,7 +6,7 @@
6 */ 6 */
7 7
8#include <linux/i2c.h> 8#include <linux/i2c.h>
9#include <linux/videodev.h> 9#include <linux/videodev2.h>
10#include <linux/delay.h> 10#include <linux/delay.h>
11#include <linux/video_decoder.h> 11#include <linux/video_decoder.h>
12#include <media/v4l2-common.h> 12#include <media/v4l2-common.h>
diff --git a/drivers/media/video/usbvideo/usbvideo.c b/drivers/media/video/usbvideo/usbvideo.c
index 4128ee20b64e..bf1bc2f69b02 100644
--- a/drivers/media/video/usbvideo/usbvideo.c
+++ b/drivers/media/video/usbvideo/usbvideo.c
@@ -952,8 +952,6 @@ static const struct file_operations usbvideo_fops = {
952 .llseek = no_llseek, 952 .llseek = no_llseek,
953}; 953};
954static const struct video_device usbvideo_template = { 954static const struct video_device usbvideo_template = {
955 .owner = THIS_MODULE,
956 .type = VID_TYPE_CAPTURE,
957 .fops = &usbvideo_fops, 955 .fops = &usbvideo_fops,
958}; 956};
959 957
@@ -1040,7 +1038,7 @@ int usbvideo_RegisterVideoDevice(struct uvd *uvd)
1040 err("%s: uvd->dev == NULL", __func__); 1038 err("%s: uvd->dev == NULL", __func__);
1041 return -EINVAL; 1039 return -EINVAL;
1042 } 1040 }
1043 uvd->vdev.dev = &uvd->dev->dev; 1041 uvd->vdev.parent = &uvd->dev->dev;
1044 if (video_register_device(&uvd->vdev, VFL_TYPE_GRABBER, video_nr) == -1) { 1042 if (video_register_device(&uvd->vdev, VFL_TYPE_GRABBER, video_nr) == -1) {
1045 err("%s: video_register_device failed", __func__); 1043 err("%s: video_register_device failed", __func__);
1046 return -EPIPE; 1044 return -EPIPE;
diff --git a/drivers/media/video/usbvideo/usbvideo.h b/drivers/media/video/usbvideo/usbvideo.h
index 051775d4c726..c66985beb8c9 100644
--- a/drivers/media/video/usbvideo/usbvideo.h
+++ b/drivers/media/video/usbvideo/usbvideo.h
@@ -18,6 +18,7 @@
18 18
19#include <linux/videodev.h> 19#include <linux/videodev.h>
20#include <media/v4l2-common.h> 20#include <media/v4l2-common.h>
21#include <media/v4l2-ioctl.h>
21#include <linux/usb.h> 22#include <linux/usb.h>
22#include <linux/mutex.h> 23#include <linux/mutex.h>
23 24
diff --git a/drivers/media/video/usbvideo/vicam.c b/drivers/media/video/usbvideo/vicam.c
index 40d053e0d5bf..b7792451a299 100644
--- a/drivers/media/video/usbvideo/vicam.c
+++ b/drivers/media/video/usbvideo/vicam.c
@@ -41,6 +41,7 @@
41#include <linux/videodev.h> 41#include <linux/videodev.h>
42#include <linux/usb.h> 42#include <linux/usb.h>
43#include <linux/vmalloc.h> 43#include <linux/vmalloc.h>
44#include <linux/mm.h>
44#include <linux/slab.h> 45#include <linux/slab.h>
45#include <linux/mutex.h> 46#include <linux/mutex.h>
46#include <linux/firmware.h> 47#include <linux/firmware.h>
@@ -791,9 +792,7 @@ static const struct file_operations vicam_fops = {
791}; 792};
792 793
793static struct video_device vicam_template = { 794static struct video_device vicam_template = {
794 .owner = THIS_MODULE,
795 .name = "ViCam-based USB Camera", 795 .name = "ViCam-based USB Camera",
796 .type = VID_TYPE_CAPTURE,
797 .fops = &vicam_fops, 796 .fops = &vicam_fops,
798 .minor = -1, 797 .minor = -1,
799}; 798};
diff --git a/drivers/media/video/usbvision/usbvision-core.c b/drivers/media/video/usbvision/usbvision-core.c
index abf685464b7c..c317ed7a8482 100644
--- a/drivers/media/video/usbvision/usbvision-core.c
+++ b/drivers/media/video/usbvision/usbvision-core.c
@@ -30,7 +30,6 @@
30#include <linux/mm.h> 30#include <linux/mm.h>
31#include <linux/utsname.h> 31#include <linux/utsname.h>
32#include <linux/highmem.h> 32#include <linux/highmem.h>
33#include <linux/videodev.h>
34#include <linux/vmalloc.h> 33#include <linux/vmalloc.h>
35#include <linux/module.h> 34#include <linux/module.h>
36#include <linux/init.h> 35#include <linux/init.h>
@@ -43,7 +42,6 @@
43#include <media/saa7115.h> 42#include <media/saa7115.h>
44#include <media/v4l2-common.h> 43#include <media/v4l2-common.h>
45#include <media/tuner.h> 44#include <media/tuner.h>
46#include <media/audiochip.h>
47 45
48#include <linux/workqueue.h> 46#include <linux/workqueue.h>
49 47
diff --git a/drivers/media/video/usbvision/usbvision-video.c b/drivers/media/video/usbvision/usbvision-video.c
index cd6c41d67899..b977116a0dd9 100644
--- a/drivers/media/video/usbvision/usbvision-video.c
+++ b/drivers/media/video/usbvision/usbvision-video.c
@@ -53,7 +53,6 @@
53#include <linux/mm.h> 53#include <linux/mm.h>
54#include <linux/utsname.h> 54#include <linux/utsname.h>
55#include <linux/highmem.h> 55#include <linux/highmem.h>
56#include <linux/videodev.h>
57#include <linux/vmalloc.h> 56#include <linux/vmalloc.h>
58#include <linux/module.h> 57#include <linux/module.h>
59#include <linux/init.h> 58#include <linux/init.h>
@@ -65,8 +64,8 @@
65 64
66#include <media/saa7115.h> 65#include <media/saa7115.h>
67#include <media/v4l2-common.h> 66#include <media/v4l2-common.h>
67#include <media/v4l2-ioctl.h>
68#include <media/tuner.h> 68#include <media/tuner.h>
69#include <media/audiochip.h>
70 69
71#include <linux/workqueue.h> 70#include <linux/workqueue.h>
72 71
@@ -184,7 +183,7 @@ MODULE_ALIAS(DRIVER_ALIAS);
184static inline struct usb_usbvision *cd_to_usbvision(struct device *cd) 183static inline struct usb_usbvision *cd_to_usbvision(struct device *cd)
185{ 184{
186 struct video_device *vdev = 185 struct video_device *vdev =
187 container_of(cd, struct video_device, class_dev); 186 container_of(cd, struct video_device, dev);
188 return video_get_drvdata(vdev); 187 return video_get_drvdata(vdev);
189} 188}
190 189
@@ -199,7 +198,7 @@ static ssize_t show_model(struct device *cd,
199 struct device_attribute *attr, char *buf) 198 struct device_attribute *attr, char *buf)
200{ 199{
201 struct video_device *vdev = 200 struct video_device *vdev =
202 container_of(cd, struct video_device, class_dev); 201 container_of(cd, struct video_device, dev);
203 struct usb_usbvision *usbvision = video_get_drvdata(vdev); 202 struct usb_usbvision *usbvision = video_get_drvdata(vdev);
204 return sprintf(buf, "%s\n", 203 return sprintf(buf, "%s\n",
205 usbvision_device_data[usbvision->DevModel].ModelString); 204 usbvision_device_data[usbvision->DevModel].ModelString);
@@ -210,7 +209,7 @@ static ssize_t show_hue(struct device *cd,
210 struct device_attribute *attr, char *buf) 209 struct device_attribute *attr, char *buf)
211{ 210{
212 struct video_device *vdev = 211 struct video_device *vdev =
213 container_of(cd, struct video_device, class_dev); 212 container_of(cd, struct video_device, dev);
214 struct usb_usbvision *usbvision = video_get_drvdata(vdev); 213 struct usb_usbvision *usbvision = video_get_drvdata(vdev);
215 struct v4l2_control ctrl; 214 struct v4l2_control ctrl;
216 ctrl.id = V4L2_CID_HUE; 215 ctrl.id = V4L2_CID_HUE;
@@ -225,7 +224,7 @@ static ssize_t show_contrast(struct device *cd,
225 struct device_attribute *attr, char *buf) 224 struct device_attribute *attr, char *buf)
226{ 225{
227 struct video_device *vdev = 226 struct video_device *vdev =
228 container_of(cd, struct video_device, class_dev); 227 container_of(cd, struct video_device, dev);
229 struct usb_usbvision *usbvision = video_get_drvdata(vdev); 228 struct usb_usbvision *usbvision = video_get_drvdata(vdev);
230 struct v4l2_control ctrl; 229 struct v4l2_control ctrl;
231 ctrl.id = V4L2_CID_CONTRAST; 230 ctrl.id = V4L2_CID_CONTRAST;
@@ -240,7 +239,7 @@ static ssize_t show_brightness(struct device *cd,
240 struct device_attribute *attr, char *buf) 239 struct device_attribute *attr, char *buf)
241{ 240{
242 struct video_device *vdev = 241 struct video_device *vdev =
243 container_of(cd, struct video_device, class_dev); 242 container_of(cd, struct video_device, dev);
244 struct usb_usbvision *usbvision = video_get_drvdata(vdev); 243 struct usb_usbvision *usbvision = video_get_drvdata(vdev);
245 struct v4l2_control ctrl; 244 struct v4l2_control ctrl;
246 ctrl.id = V4L2_CID_BRIGHTNESS; 245 ctrl.id = V4L2_CID_BRIGHTNESS;
@@ -255,7 +254,7 @@ static ssize_t show_saturation(struct device *cd,
255 struct device_attribute *attr, char *buf) 254 struct device_attribute *attr, char *buf)
256{ 255{
257 struct video_device *vdev = 256 struct video_device *vdev =
258 container_of(cd, struct video_device, class_dev); 257 container_of(cd, struct video_device, dev);
259 struct usb_usbvision *usbvision = video_get_drvdata(vdev); 258 struct usb_usbvision *usbvision = video_get_drvdata(vdev);
260 struct v4l2_control ctrl; 259 struct v4l2_control ctrl;
261 ctrl.id = V4L2_CID_SATURATION; 260 ctrl.id = V4L2_CID_SATURATION;
@@ -270,7 +269,7 @@ static ssize_t show_streaming(struct device *cd,
270 struct device_attribute *attr, char *buf) 269 struct device_attribute *attr, char *buf)
271{ 270{
272 struct video_device *vdev = 271 struct video_device *vdev =
273 container_of(cd, struct video_device, class_dev); 272 container_of(cd, struct video_device, dev);
274 struct usb_usbvision *usbvision = video_get_drvdata(vdev); 273 struct usb_usbvision *usbvision = video_get_drvdata(vdev);
275 return sprintf(buf, "%s\n", 274 return sprintf(buf, "%s\n",
276 YES_NO(usbvision->streaming==Stream_On?1:0)); 275 YES_NO(usbvision->streaming==Stream_On?1:0));
@@ -281,7 +280,7 @@ static ssize_t show_compression(struct device *cd,
281 struct device_attribute *attr, char *buf) 280 struct device_attribute *attr, char *buf)
282{ 281{
283 struct video_device *vdev = 282 struct video_device *vdev =
284 container_of(cd, struct video_device, class_dev); 283 container_of(cd, struct video_device, dev);
285 struct usb_usbvision *usbvision = video_get_drvdata(vdev); 284 struct usb_usbvision *usbvision = video_get_drvdata(vdev);
286 return sprintf(buf, "%s\n", 285 return sprintf(buf, "%s\n",
287 YES_NO(usbvision->isocMode==ISOC_MODE_COMPRESS)); 286 YES_NO(usbvision->isocMode==ISOC_MODE_COMPRESS));
@@ -292,7 +291,7 @@ static ssize_t show_device_bridge(struct device *cd,
292 struct device_attribute *attr, char *buf) 291 struct device_attribute *attr, char *buf)
293{ 292{
294 struct video_device *vdev = 293 struct video_device *vdev =
295 container_of(cd, struct video_device, class_dev); 294 container_of(cd, struct video_device, dev);
296 struct usb_usbvision *usbvision = video_get_drvdata(vdev); 295 struct usb_usbvision *usbvision = video_get_drvdata(vdev);
297 return sprintf(buf, "%d\n", usbvision->bridgeType); 296 return sprintf(buf, "%d\n", usbvision->bridgeType);
298} 297}
@@ -304,40 +303,31 @@ static void usbvision_create_sysfs(struct video_device *vdev)
304 if (!vdev) 303 if (!vdev)
305 return; 304 return;
306 do { 305 do {
307 res = device_create_file(&vdev->class_dev, 306 res = device_create_file(&vdev->dev, &dev_attr_version);
308 &dev_attr_version);
309 if (res<0) 307 if (res<0)
310 break; 308 break;
311 res = device_create_file(&vdev->class_dev, 309 res = device_create_file(&vdev->dev, &dev_attr_model);
312 &dev_attr_model);
313 if (res<0) 310 if (res<0)
314 break; 311 break;
315 res = device_create_file(&vdev->class_dev, 312 res = device_create_file(&vdev->dev, &dev_attr_hue);
316 &dev_attr_hue);
317 if (res<0) 313 if (res<0)
318 break; 314 break;
319 res = device_create_file(&vdev->class_dev, 315 res = device_create_file(&vdev->dev, &dev_attr_contrast);
320 &dev_attr_contrast);
321 if (res<0) 316 if (res<0)
322 break; 317 break;
323 res = device_create_file(&vdev->class_dev, 318 res = device_create_file(&vdev->dev, &dev_attr_brightness);
324 &dev_attr_brightness);
325 if (res<0) 319 if (res<0)
326 break; 320 break;
327 res = device_create_file(&vdev->class_dev, 321 res = device_create_file(&vdev->dev, &dev_attr_saturation);
328 &dev_attr_saturation);
329 if (res<0) 322 if (res<0)
330 break; 323 break;
331 res = device_create_file(&vdev->class_dev, 324 res = device_create_file(&vdev->dev, &dev_attr_streaming);
332 &dev_attr_streaming);
333 if (res<0) 325 if (res<0)
334 break; 326 break;
335 res = device_create_file(&vdev->class_dev, 327 res = device_create_file(&vdev->dev, &dev_attr_compression);
336 &dev_attr_compression);
337 if (res<0) 328 if (res<0)
338 break; 329 break;
339 res = device_create_file(&vdev->class_dev, 330 res = device_create_file(&vdev->dev, &dev_attr_bridge);
340 &dev_attr_bridge);
341 if (res>=0) 331 if (res>=0)
342 return; 332 return;
343 } while (0); 333 } while (0);
@@ -348,24 +338,15 @@ static void usbvision_create_sysfs(struct video_device *vdev)
348static void usbvision_remove_sysfs(struct video_device *vdev) 338static void usbvision_remove_sysfs(struct video_device *vdev)
349{ 339{
350 if (vdev) { 340 if (vdev) {
351 device_remove_file(&vdev->class_dev, 341 device_remove_file(&vdev->dev, &dev_attr_version);
352 &dev_attr_version); 342 device_remove_file(&vdev->dev, &dev_attr_model);
353 device_remove_file(&vdev->class_dev, 343 device_remove_file(&vdev->dev, &dev_attr_hue);
354 &dev_attr_model); 344 device_remove_file(&vdev->dev, &dev_attr_contrast);
355 device_remove_file(&vdev->class_dev, 345 device_remove_file(&vdev->dev, &dev_attr_brightness);
356 &dev_attr_hue); 346 device_remove_file(&vdev->dev, &dev_attr_saturation);
357 device_remove_file(&vdev->class_dev, 347 device_remove_file(&vdev->dev, &dev_attr_streaming);
358 &dev_attr_contrast); 348 device_remove_file(&vdev->dev, &dev_attr_compression);
359 device_remove_file(&vdev->class_dev, 349 device_remove_file(&vdev->dev, &dev_attr_bridge);
360 &dev_attr_brightness);
361 device_remove_file(&vdev->class_dev,
362 &dev_attr_saturation);
363 device_remove_file(&vdev->class_dev,
364 &dev_attr_streaming);
365 device_remove_file(&vdev->class_dev,
366 &dev_attr_compression);
367 device_remove_file(&vdev->class_dev,
368 &dev_attr_bridge);
369 } 350 }
370} 351}
371 352
@@ -1388,13 +1369,8 @@ static const struct file_operations usbvision_fops = {
1388/* .poll = video_poll, */ 1369/* .poll = video_poll, */
1389 .compat_ioctl = v4l_compat_ioctl32, 1370 .compat_ioctl = v4l_compat_ioctl32,
1390}; 1371};
1391static struct video_device usbvision_video_template = { 1372
1392 .owner = THIS_MODULE, 1373static const struct v4l2_ioctl_ops usbvision_ioctl_ops = {
1393 .type = VID_TYPE_TUNER | VID_TYPE_CAPTURE,
1394 .fops = &usbvision_fops,
1395 .name = "usbvision-video",
1396 .release = video_device_release,
1397 .minor = -1,
1398 .vidioc_querycap = vidioc_querycap, 1374 .vidioc_querycap = vidioc_querycap,
1399 .vidioc_enum_fmt_vid_cap = vidioc_enum_fmt_vid_cap, 1375 .vidioc_enum_fmt_vid_cap = vidioc_enum_fmt_vid_cap,
1400 .vidioc_g_fmt_vid_cap = vidioc_g_fmt_vid_cap, 1376 .vidioc_g_fmt_vid_cap = vidioc_g_fmt_vid_cap,
@@ -1426,6 +1402,14 @@ static struct video_device usbvision_video_template = {
1426 .vidioc_g_register = vidioc_g_register, 1402 .vidioc_g_register = vidioc_g_register,
1427 .vidioc_s_register = vidioc_s_register, 1403 .vidioc_s_register = vidioc_s_register,
1428#endif 1404#endif
1405};
1406
1407static struct video_device usbvision_video_template = {
1408 .fops = &usbvision_fops,
1409 .ioctl_ops = &usbvision_ioctl_ops,
1410 .name = "usbvision-video",
1411 .release = video_device_release,
1412 .minor = -1,
1429 .tvnorms = USBVISION_NORMS, 1413 .tvnorms = USBVISION_NORMS,
1430 .current_norm = V4L2_STD_PAL 1414 .current_norm = V4L2_STD_PAL
1431}; 1415};
@@ -1441,14 +1425,7 @@ static const struct file_operations usbvision_radio_fops = {
1441 .compat_ioctl = v4l_compat_ioctl32, 1425 .compat_ioctl = v4l_compat_ioctl32,
1442}; 1426};
1443 1427
1444static struct video_device usbvision_radio_template= 1428static const struct v4l2_ioctl_ops usbvision_radio_ioctl_ops = {
1445{
1446 .owner = THIS_MODULE,
1447 .type = VID_TYPE_TUNER,
1448 .fops = &usbvision_radio_fops,
1449 .name = "usbvision-radio",
1450 .release = video_device_release,
1451 .minor = -1,
1452 .vidioc_querycap = vidioc_querycap, 1429 .vidioc_querycap = vidioc_querycap,
1453 .vidioc_enum_input = vidioc_enum_input, 1430 .vidioc_enum_input = vidioc_enum_input,
1454 .vidioc_g_input = vidioc_g_input, 1431 .vidioc_g_input = vidioc_g_input,
@@ -1462,6 +1439,14 @@ static struct video_device usbvision_radio_template=
1462 .vidioc_s_tuner = vidioc_s_tuner, 1439 .vidioc_s_tuner = vidioc_s_tuner,
1463 .vidioc_g_frequency = vidioc_g_frequency, 1440 .vidioc_g_frequency = vidioc_g_frequency,
1464 .vidioc_s_frequency = vidioc_s_frequency, 1441 .vidioc_s_frequency = vidioc_s_frequency,
1442};
1443
1444static struct video_device usbvision_radio_template = {
1445 .fops = &usbvision_radio_fops,
1446 .name = "usbvision-radio",
1447 .release = video_device_release,
1448 .minor = -1,
1449 .ioctl_ops = &usbvision_radio_ioctl_ops,
1465 1450
1466 .tvnorms = USBVISION_NORMS, 1451 .tvnorms = USBVISION_NORMS,
1467 .current_norm = V4L2_STD_PAL 1452 .current_norm = V4L2_STD_PAL
@@ -1479,8 +1464,6 @@ static const struct file_operations usbvision_vbi_fops = {
1479 1464
1480static struct video_device usbvision_vbi_template= 1465static struct video_device usbvision_vbi_template=
1481{ 1466{
1482 .owner = THIS_MODULE,
1483 .type = VID_TYPE_TUNER,
1484 .fops = &usbvision_vbi_fops, 1467 .fops = &usbvision_vbi_fops,
1485 .release = video_device_release, 1468 .release = video_device_release,
1486 .name = "usbvision-vbi", 1469 .name = "usbvision-vbi",
@@ -1506,7 +1489,7 @@ static struct video_device *usbvision_vdev_init(struct usb_usbvision *usbvision,
1506 } 1489 }
1507 *vdev = *vdev_template; 1490 *vdev = *vdev_template;
1508// vdev->minor = -1; 1491// vdev->minor = -1;
1509 vdev->dev = &usb_dev->dev; 1492 vdev->parent = &usb_dev->dev;
1510 snprintf(vdev->name, sizeof(vdev->name), "%s", name); 1493 snprintf(vdev->name, sizeof(vdev->name), "%s", name);
1511 video_set_drvdata(vdev, usbvision); 1494 video_set_drvdata(vdev, usbvision);
1512 return vdev; 1495 return vdev;
diff --git a/drivers/media/video/uvc/uvc_ctrl.c b/drivers/media/video/uvc/uvc_ctrl.c
index 3ae95512666f..626f4ad7e876 100644
--- a/drivers/media/video/uvc/uvc_ctrl.c
+++ b/drivers/media/video/uvc/uvc_ctrl.c
@@ -195,8 +195,8 @@ static struct uvc_menu_info power_line_frequency_controls[] = {
195}; 195};
196 196
197static struct uvc_menu_info exposure_auto_controls[] = { 197static struct uvc_menu_info exposure_auto_controls[] = {
198 { 1, "Manual Mode" },
199 { 2, "Auto Mode" }, 198 { 2, "Auto Mode" },
199 { 1, "Manual Mode" },
200 { 4, "Shutter Priority Mode" }, 200 { 4, "Shutter Priority Mode" },
201 { 8, "Aperture Priority Mode" }, 201 { 8, "Aperture Priority Mode" },
202}; 202};
@@ -592,6 +592,7 @@ int uvc_query_v4l2_ctrl(struct uvc_video_device *video,
592 if (ctrl == NULL) 592 if (ctrl == NULL)
593 return -EINVAL; 593 return -EINVAL;
594 594
595 memset(v4l2_ctrl, 0, sizeof *v4l2_ctrl);
595 v4l2_ctrl->id = mapping->id; 596 v4l2_ctrl->id = mapping->id;
596 v4l2_ctrl->type = mapping->v4l2_type; 597 v4l2_ctrl->type = mapping->v4l2_type;
597 strncpy(v4l2_ctrl->name, mapping->name, sizeof v4l2_ctrl->name); 598 strncpy(v4l2_ctrl->name, mapping->name, sizeof v4l2_ctrl->name);
@@ -608,7 +609,8 @@ int uvc_query_v4l2_ctrl(struct uvc_video_device *video,
608 v4l2_ctrl->default_value = uvc_get_le_value(data, mapping); 609 v4l2_ctrl->default_value = uvc_get_le_value(data, mapping);
609 } 610 }
610 611
611 if (mapping->v4l2_type == V4L2_CTRL_TYPE_MENU) { 612 switch (mapping->v4l2_type) {
613 case V4L2_CTRL_TYPE_MENU:
612 v4l2_ctrl->minimum = 0; 614 v4l2_ctrl->minimum = 0;
613 v4l2_ctrl->maximum = mapping->menu_count - 1; 615 v4l2_ctrl->maximum = mapping->menu_count - 1;
614 v4l2_ctrl->step = 1; 616 v4l2_ctrl->step = 1;
@@ -622,6 +624,15 @@ int uvc_query_v4l2_ctrl(struct uvc_video_device *video,
622 } 624 }
623 625
624 return 0; 626 return 0;
627
628 case V4L2_CTRL_TYPE_BOOLEAN:
629 v4l2_ctrl->minimum = 0;
630 v4l2_ctrl->maximum = 1;
631 v4l2_ctrl->step = 1;
632 return 0;
633
634 default:
635 break;
625 } 636 }
626 637
627 if (ctrl->info->flags & UVC_CONTROL_GET_MIN) { 638 if (ctrl->info->flags & UVC_CONTROL_GET_MIN) {
diff --git a/drivers/media/video/uvc/uvc_driver.c b/drivers/media/video/uvc/uvc_driver.c
index f2b2983fe062..b3c4d75e8490 100644
--- a/drivers/media/video/uvc/uvc_driver.c
+++ b/drivers/media/video/uvc/uvc_driver.c
@@ -1458,9 +1458,7 @@ static int uvc_register_video(struct uvc_device *dev)
1458 * unregistered before the reference is released, so we don't need to 1458 * unregistered before the reference is released, so we don't need to
1459 * get another one. 1459 * get another one.
1460 */ 1460 */
1461 vdev->dev = &dev->intf->dev; 1461 vdev->parent = &dev->intf->dev;
1462 vdev->type = 0;
1463 vdev->type2 = 0;
1464 vdev->minor = -1; 1462 vdev->minor = -1;
1465 vdev->fops = &uvc_fops; 1463 vdev->fops = &uvc_fops;
1466 vdev->release = video_device_release; 1464 vdev->release = video_device_release;
diff --git a/drivers/media/video/uvc/uvc_v4l2.c b/drivers/media/video/uvc/uvc_v4l2.c
index b5a11eb8f9fa..d7bd71be40a9 100644
--- a/drivers/media/video/uvc/uvc_v4l2.c
+++ b/drivers/media/video/uvc/uvc_v4l2.c
@@ -23,6 +23,7 @@
23#include <asm/atomic.h> 23#include <asm/atomic.h>
24 24
25#include <media/v4l2-common.h> 25#include <media/v4l2-common.h>
26#include <media/v4l2-ioctl.h>
26 27
27#include "uvcvideo.h" 28#include "uvcvideo.h"
28 29
diff --git a/drivers/media/video/v4l1-compat.c b/drivers/media/video/v4l1-compat.c
index a0f6c60279ec..79937d1031fc 100644
--- a/drivers/media/video/v4l1-compat.c
+++ b/drivers/media/video/v4l1-compat.c
@@ -30,6 +30,7 @@
30#include <linux/slab.h> 30#include <linux/slab.h>
31#include <linux/videodev.h> 31#include <linux/videodev.h>
32#include <media/v4l2-common.h> 32#include <media/v4l2-common.h>
33#include <media/v4l2-ioctl.h>
33 34
34#include <asm/uaccess.h> 35#include <asm/uaccess.h>
35#include <asm/system.h> 36#include <asm/system.h>
diff --git a/drivers/media/video/v4l2-common.c b/drivers/media/video/v4l2-common.c
index e9dd996fd5df..88ca13104417 100644
--- a/drivers/media/video/v4l2-common.c
+++ b/drivers/media/video/v4l2-common.c
@@ -64,7 +64,7 @@
64#include <linux/kmod.h> 64#include <linux/kmod.h>
65#endif 65#endif
66 66
67#include <linux/videodev.h> 67#include <linux/videodev2.h>
68 68
69MODULE_AUTHOR("Bill Dirks, Justin Schoeman, Gerd Knorr"); 69MODULE_AUTHOR("Bill Dirks, Justin Schoeman, Gerd Knorr");
70MODULE_DESCRIPTION("misc helper functions for v4l2 device drivers"); 70MODULE_DESCRIPTION("misc helper functions for v4l2 device drivers");
diff --git a/drivers/media/video/v4l2-dev.c b/drivers/media/video/v4l2-dev.c
new file mode 100644
index 000000000000..556615fe93de
--- /dev/null
+++ b/drivers/media/video/v4l2-dev.c
@@ -0,0 +1,422 @@
1/*
2 * Video capture interface for Linux version 2
3 *
4 * A generic video device interface for the LINUX operating system
5 * using a set of device structures/vectors for low level operations.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version
10 * 2 of the License, or (at your option) any later version.
11 *
12 * Authors: Alan Cox, <alan@redhat.com> (version 1)
13 * Mauro Carvalho Chehab <mchehab@infradead.org> (version 2)
14 *
15 * Fixes: 20000516 Claudio Matsuoka <claudio@conectiva.com>
16 * - Added procfs support
17 */
18
19#include <linux/module.h>
20#include <linux/types.h>
21#include <linux/kernel.h>
22#include <linux/mm.h>
23#include <linux/string.h>
24#include <linux/errno.h>
25#include <linux/init.h>
26#include <linux/kmod.h>
27#include <linux/slab.h>
28#include <linux/smp_lock.h>
29#include <asm/uaccess.h>
30#include <asm/system.h>
31
32#include <media/v4l2-common.h>
33
34#define VIDEO_NUM_DEVICES 256
35#define VIDEO_NAME "video4linux"
36
37/*
38 * sysfs stuff
39 */
40
41static ssize_t show_index(struct device *cd,
42 struct device_attribute *attr, char *buf)
43{
44 struct video_device *vfd = container_of(cd, struct video_device, dev);
45 return sprintf(buf, "%i\n", vfd->index);
46}
47
48static ssize_t show_name(struct device *cd,
49 struct device_attribute *attr, char *buf)
50{
51 struct video_device *vfd = container_of(cd, struct video_device, dev);
52 return sprintf(buf, "%.*s\n", (int)sizeof(vfd->name), vfd->name);
53}
54
55static struct device_attribute video_device_attrs[] = {
56 __ATTR(name, S_IRUGO, show_name, NULL),
57 __ATTR(index, S_IRUGO, show_index, NULL),
58 __ATTR_NULL
59};
60
61struct video_device *video_device_alloc(void)
62{
63 struct video_device *vfd;
64
65 vfd = kzalloc(sizeof(*vfd), GFP_KERNEL);
66 return vfd;
67}
68EXPORT_SYMBOL(video_device_alloc);
69
70void video_device_release(struct video_device *vfd)
71{
72 kfree(vfd);
73}
74EXPORT_SYMBOL(video_device_release);
75
76static void video_release(struct device *cd)
77{
78 struct video_device *vfd = container_of(cd, struct video_device, dev);
79
80#if 1
81 /* needed until all drivers are fixed */
82 if (!vfd->release)
83 return;
84#endif
85 vfd->release(vfd);
86}
87
88static struct class video_class = {
89 .name = VIDEO_NAME,
90 .dev_attrs = video_device_attrs,
91 .dev_release = video_release,
92};
93
94/*
95 * Active devices
96 */
97
98static struct video_device *video_device[VIDEO_NUM_DEVICES];
99static DEFINE_MUTEX(videodev_lock);
100
101struct video_device *video_devdata(struct file *file)
102{
103 return video_device[iminor(file->f_path.dentry->d_inode)];
104}
105EXPORT_SYMBOL(video_devdata);
106
107/*
108 * Open a video device - FIXME: Obsoleted
109 */
110static int video_open(struct inode *inode, struct file *file)
111{
112 unsigned int minor = iminor(inode);
113 int err = 0;
114 struct video_device *vfl;
115 const struct file_operations *old_fops;
116
117 if (minor >= VIDEO_NUM_DEVICES)
118 return -ENODEV;
119 lock_kernel();
120 mutex_lock(&videodev_lock);
121 vfl = video_device[minor];
122 if (vfl == NULL) {
123 mutex_unlock(&videodev_lock);
124 request_module("char-major-%d-%d", VIDEO_MAJOR, minor);
125 mutex_lock(&videodev_lock);
126 vfl = video_device[minor];
127 if (vfl == NULL) {
128 mutex_unlock(&videodev_lock);
129 unlock_kernel();
130 return -ENODEV;
131 }
132 }
133 old_fops = file->f_op;
134 file->f_op = fops_get(vfl->fops);
135 if (file->f_op->open)
136 err = file->f_op->open(inode, file);
137 if (err) {
138 fops_put(file->f_op);
139 file->f_op = fops_get(old_fops);
140 }
141 fops_put(old_fops);
142 mutex_unlock(&videodev_lock);
143 unlock_kernel();
144 return err;
145}
146
147/*
148 * open/release helper functions -- handle exclusive opens
149 * Should be removed soon
150 */
151int video_exclusive_open(struct inode *inode, struct file *file)
152{
153 struct video_device *vfl = video_devdata(file);
154 int retval = 0;
155
156 mutex_lock(&vfl->lock);
157 if (vfl->users)
158 retval = -EBUSY;
159 else
160 vfl->users++;
161 mutex_unlock(&vfl->lock);
162 return retval;
163}
164EXPORT_SYMBOL(video_exclusive_open);
165
166int video_exclusive_release(struct inode *inode, struct file *file)
167{
168 struct video_device *vfl = video_devdata(file);
169
170 vfl->users--;
171 return 0;
172}
173EXPORT_SYMBOL(video_exclusive_release);
174
175/**
176 * get_index - assign stream number based on parent device
177 * @vdev: video_device to assign index number to, vdev->dev should be assigned
178 * @num: -1 if auto assign, requested number otherwise
179 *
180 *
181 * returns -ENFILE if num is already in use, a free index number if
182 * successful.
183 */
184static int get_index(struct video_device *vdev, int num)
185{
186 u32 used = 0;
187 const int max_index = sizeof(used) * 8 - 1;
188 int i;
189
190 /* Currently a single v4l driver instance cannot create more than
191 32 devices.
192 Increase to u64 or an array of u32 if more are needed. */
193 if (num > max_index) {
194 printk(KERN_ERR "videodev: %s num is too large\n", __func__);
195 return -EINVAL;
196 }
197
198 for (i = 0; i < VIDEO_NUM_DEVICES; i++) {
199 if (video_device[i] != NULL &&
200 video_device[i] != vdev &&
201 video_device[i]->parent == vdev->parent) {
202 used |= 1 << video_device[i]->index;
203 }
204 }
205
206 if (num >= 0) {
207 if (used & (1 << num))
208 return -ENFILE;
209 return num;
210 }
211
212 i = ffz(used);
213 return i > max_index ? -ENFILE : i;
214}
215
216static const struct file_operations video_fops;
217
218int video_register_device(struct video_device *vfd, int type, int nr)
219{
220 return video_register_device_index(vfd, type, nr, -1);
221}
222EXPORT_SYMBOL(video_register_device);
223
224/**
225 * video_register_device - register video4linux devices
226 * @vfd: video device structure we want to register
227 * @type: type of device to register
228 * @nr: which device number (0 == /dev/video0, 1 == /dev/video1, ...
229 * -1 == first free)
230 *
231 * The registration code assigns minor numbers based on the type
232 * requested. -ENFILE is returned in all the device slots for this
233 * category are full. If not then the minor field is set and the
234 * driver initialize function is called (if non %NULL).
235 *
236 * Zero is returned on success.
237 *
238 * Valid types are
239 *
240 * %VFL_TYPE_GRABBER - A frame grabber
241 *
242 * %VFL_TYPE_VTX - A teletext device
243 *
244 * %VFL_TYPE_VBI - Vertical blank data (undecoded)
245 *
246 * %VFL_TYPE_RADIO - A radio card
247 */
248
249int video_register_device_index(struct video_device *vfd, int type, int nr,
250 int index)
251{
252 int i = 0;
253 int base;
254 int end;
255 int ret;
256 char *name_base;
257
258 switch (type) {
259 case VFL_TYPE_GRABBER:
260 base = MINOR_VFL_TYPE_GRABBER_MIN;
261 end = MINOR_VFL_TYPE_GRABBER_MAX+1;
262 name_base = "video";
263 break;
264 case VFL_TYPE_VTX:
265 base = MINOR_VFL_TYPE_VTX_MIN;
266 end = MINOR_VFL_TYPE_VTX_MAX+1;
267 name_base = "vtx";
268 break;
269 case VFL_TYPE_VBI:
270 base = MINOR_VFL_TYPE_VBI_MIN;
271 end = MINOR_VFL_TYPE_VBI_MAX+1;
272 name_base = "vbi";
273 break;
274 case VFL_TYPE_RADIO:
275 base = MINOR_VFL_TYPE_RADIO_MIN;
276 end = MINOR_VFL_TYPE_RADIO_MAX+1;
277 name_base = "radio";
278 break;
279 default:
280 printk(KERN_ERR "%s called with unknown type: %d\n",
281 __func__, type);
282 return -1;
283 }
284
285 /* pick a minor number */
286 mutex_lock(&videodev_lock);
287 if (nr >= 0 && nr < end-base) {
288 /* use the one the driver asked for */
289 i = base + nr;
290 if (NULL != video_device[i]) {
291 mutex_unlock(&videodev_lock);
292 return -ENFILE;
293 }
294 } else {
295 /* use first free */
296 for (i = base; i < end; i++)
297 if (NULL == video_device[i])
298 break;
299 if (i == end) {
300 mutex_unlock(&videodev_lock);
301 return -ENFILE;
302 }
303 }
304 video_device[i] = vfd;
305 vfd->vfl_type = type;
306 vfd->minor = i;
307
308 ret = get_index(vfd, index);
309 vfd->index = ret;
310
311 mutex_unlock(&videodev_lock);
312
313 if (ret < 0) {
314 printk(KERN_ERR "%s: get_index failed\n", __func__);
315 goto fail_minor;
316 }
317
318 mutex_init(&vfd->lock);
319
320 /* sysfs class */
321 memset(&vfd->dev, 0x00, sizeof(vfd->dev));
322 vfd->dev.class = &video_class;
323 vfd->dev.devt = MKDEV(VIDEO_MAJOR, vfd->minor);
324 if (vfd->parent)
325 vfd->dev.parent = vfd->parent;
326 sprintf(vfd->dev.bus_id, "%s%d", name_base, i - base);
327 ret = device_register(&vfd->dev);
328 if (ret < 0) {
329 printk(KERN_ERR "%s: device_register failed\n", __func__);
330 goto fail_minor;
331 }
332
333#if 1
334 /* needed until all drivers are fixed */
335 if (!vfd->release)
336 printk(KERN_WARNING "videodev: \"%s\" has no release callback. "
337 "Please fix your driver for proper sysfs support, see "
338 "http://lwn.net/Articles/36850/\n", vfd->name);
339#endif
340 return 0;
341
342fail_minor:
343 mutex_lock(&videodev_lock);
344 video_device[vfd->minor] = NULL;
345 vfd->minor = -1;
346 mutex_unlock(&videodev_lock);
347 return ret;
348}
349EXPORT_SYMBOL(video_register_device_index);
350
351/**
352 * video_unregister_device - unregister a video4linux device
353 * @vfd: the device to unregister
354 *
355 * This unregisters the passed device and deassigns the minor
356 * number. Future open calls will be met with errors.
357 */
358
359void video_unregister_device(struct video_device *vfd)
360{
361 mutex_lock(&videodev_lock);
362 if (video_device[vfd->minor] != vfd)
363 panic("videodev: bad unregister");
364
365 video_device[vfd->minor] = NULL;
366 device_unregister(&vfd->dev);
367 mutex_unlock(&videodev_lock);
368}
369EXPORT_SYMBOL(video_unregister_device);
370
371/*
372 * Video fs operations
373 */
374static const struct file_operations video_fops = {
375 .owner = THIS_MODULE,
376 .llseek = no_llseek,
377 .open = video_open,
378};
379
380/*
381 * Initialise video for linux
382 */
383
384static int __init videodev_init(void)
385{
386 int ret;
387
388 printk(KERN_INFO "Linux video capture interface: v2.00\n");
389 if (register_chrdev(VIDEO_MAJOR, VIDEO_NAME, &video_fops)) {
390 printk(KERN_WARNING "video_dev: unable to get major %d\n", VIDEO_MAJOR);
391 return -EIO;
392 }
393
394 ret = class_register(&video_class);
395 if (ret < 0) {
396 unregister_chrdev(VIDEO_MAJOR, VIDEO_NAME);
397 printk(KERN_WARNING "video_dev: class_register failed\n");
398 return -EIO;
399 }
400
401 return 0;
402}
403
404static void __exit videodev_exit(void)
405{
406 class_unregister(&video_class);
407 unregister_chrdev(VIDEO_MAJOR, VIDEO_NAME);
408}
409
410module_init(videodev_init)
411module_exit(videodev_exit)
412
413MODULE_AUTHOR("Alan Cox, Mauro Carvalho Chehab <mchehab@infradead.org>");
414MODULE_DESCRIPTION("Device registrar for Video4Linux drivers v2");
415MODULE_LICENSE("GPL");
416
417
418/*
419 * Local variables:
420 * c-basic-offset: 8
421 * End:
422 */
diff --git a/drivers/media/video/v4l2-ioctl.c b/drivers/media/video/v4l2-ioctl.c
new file mode 100644
index 000000000000..fdfe7739c96e
--- /dev/null
+++ b/drivers/media/video/v4l2-ioctl.c
@@ -0,0 +1,1875 @@
1/*
2 * Video capture interface for Linux version 2
3 *
4 * A generic framework to process V4L2 ioctl commands.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
10 *
11 * Authors: Alan Cox, <alan@redhat.com> (version 1)
12 * Mauro Carvalho Chehab <mchehab@infradead.org> (version 2)
13 */
14
15#include <linux/module.h>
16#include <linux/types.h>
17#include <linux/kernel.h>
18
19#define __OLD_VIDIOC_ /* To allow fixing old calls */
20#include <linux/videodev2.h>
21
22#ifdef CONFIG_VIDEO_V4L1
23#include <linux/videodev.h>
24#endif
25#include <media/v4l2-common.h>
26#include <media/v4l2-ioctl.h>
27#include <linux/video_decoder.h>
28
29#define dbgarg(cmd, fmt, arg...) \
30 do { \
31 if (vfd->debug & V4L2_DEBUG_IOCTL_ARG) { \
32 printk(KERN_DEBUG "%s: ", vfd->name); \
33 v4l_printk_ioctl(cmd); \
34 printk(" " fmt, ## arg); \
35 } \
36 } while (0)
37
38#define dbgarg2(fmt, arg...) \
39 do { \
40 if (vfd->debug & V4L2_DEBUG_IOCTL_ARG) \
41 printk(KERN_DEBUG "%s: " fmt, vfd->name, ## arg);\
42 } while (0)
43
44struct std_descr {
45 v4l2_std_id std;
46 const char *descr;
47};
48
49static const struct std_descr standards[] = {
50 { V4L2_STD_NTSC, "NTSC" },
51 { V4L2_STD_NTSC_M, "NTSC-M" },
52 { V4L2_STD_NTSC_M_JP, "NTSC-M-JP" },
53 { V4L2_STD_NTSC_M_KR, "NTSC-M-KR" },
54 { V4L2_STD_NTSC_443, "NTSC-443" },
55 { V4L2_STD_PAL, "PAL" },
56 { V4L2_STD_PAL_BG, "PAL-BG" },
57 { V4L2_STD_PAL_B, "PAL-B" },
58 { V4L2_STD_PAL_B1, "PAL-B1" },
59 { V4L2_STD_PAL_G, "PAL-G" },
60 { V4L2_STD_PAL_H, "PAL-H" },
61 { V4L2_STD_PAL_I, "PAL-I" },
62 { V4L2_STD_PAL_DK, "PAL-DK" },
63 { V4L2_STD_PAL_D, "PAL-D" },
64 { V4L2_STD_PAL_D1, "PAL-D1" },
65 { V4L2_STD_PAL_K, "PAL-K" },
66 { V4L2_STD_PAL_M, "PAL-M" },
67 { V4L2_STD_PAL_N, "PAL-N" },
68 { V4L2_STD_PAL_Nc, "PAL-Nc" },
69 { V4L2_STD_PAL_60, "PAL-60" },
70 { V4L2_STD_SECAM, "SECAM" },
71 { V4L2_STD_SECAM_B, "SECAM-B" },
72 { V4L2_STD_SECAM_G, "SECAM-G" },
73 { V4L2_STD_SECAM_H, "SECAM-H" },
74 { V4L2_STD_SECAM_DK, "SECAM-DK" },
75 { V4L2_STD_SECAM_D, "SECAM-D" },
76 { V4L2_STD_SECAM_K, "SECAM-K" },
77 { V4L2_STD_SECAM_K1, "SECAM-K1" },
78 { V4L2_STD_SECAM_L, "SECAM-L" },
79 { V4L2_STD_SECAM_LC, "SECAM-Lc" },
80 { 0, "Unknown" }
81};
82
83/* video4linux standard ID conversion to standard name
84 */
85const char *v4l2_norm_to_name(v4l2_std_id id)
86{
87 u32 myid = id;
88 int i;
89
90 /* HACK: ppc32 architecture doesn't have __ucmpdi2 function to handle
91 64 bit comparations. So, on that architecture, with some gcc
92 variants, compilation fails. Currently, the max value is 30bit wide.
93 */
94 BUG_ON(myid != id);
95
96 for (i = 0; standards[i].std; i++)
97 if (myid == standards[i].std)
98 break;
99 return standards[i].descr;
100}
101EXPORT_SYMBOL(v4l2_norm_to_name);
102
103/* Fill in the fields of a v4l2_standard structure according to the
104 'id' and 'transmission' parameters. Returns negative on error. */
105int v4l2_video_std_construct(struct v4l2_standard *vs,
106 int id, const char *name)
107{
108 u32 index = vs->index;
109
110 memset(vs, 0, sizeof(struct v4l2_standard));
111 vs->index = index;
112 vs->id = id;
113 if (id & V4L2_STD_525_60) {
114 vs->frameperiod.numerator = 1001;
115 vs->frameperiod.denominator = 30000;
116 vs->framelines = 525;
117 } else {
118 vs->frameperiod.numerator = 1;
119 vs->frameperiod.denominator = 25;
120 vs->framelines = 625;
121 }
122 strlcpy(vs->name, name, sizeof(vs->name));
123 return 0;
124}
125EXPORT_SYMBOL(v4l2_video_std_construct);
126
127/* ----------------------------------------------------------------- */
128/* some arrays for pretty-printing debug messages of enum types */
129
130const char *v4l2_field_names[] = {
131 [V4L2_FIELD_ANY] = "any",
132 [V4L2_FIELD_NONE] = "none",
133 [V4L2_FIELD_TOP] = "top",
134 [V4L2_FIELD_BOTTOM] = "bottom",
135 [V4L2_FIELD_INTERLACED] = "interlaced",
136 [V4L2_FIELD_SEQ_TB] = "seq-tb",
137 [V4L2_FIELD_SEQ_BT] = "seq-bt",
138 [V4L2_FIELD_ALTERNATE] = "alternate",
139 [V4L2_FIELD_INTERLACED_TB] = "interlaced-tb",
140 [V4L2_FIELD_INTERLACED_BT] = "interlaced-bt",
141};
142EXPORT_SYMBOL(v4l2_field_names);
143
144const char *v4l2_type_names[] = {
145 [V4L2_BUF_TYPE_VIDEO_CAPTURE] = "vid-cap",
146 [V4L2_BUF_TYPE_VIDEO_OVERLAY] = "vid-overlay",
147 [V4L2_BUF_TYPE_VIDEO_OUTPUT] = "vid-out",
148 [V4L2_BUF_TYPE_VBI_CAPTURE] = "vbi-cap",
149 [V4L2_BUF_TYPE_VBI_OUTPUT] = "vbi-out",
150 [V4L2_BUF_TYPE_SLICED_VBI_CAPTURE] = "sliced-vbi-cap",
151 [V4L2_BUF_TYPE_SLICED_VBI_OUTPUT] = "sliced-vbi-out",
152 [V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY] = "vid-out-overlay",
153};
154EXPORT_SYMBOL(v4l2_type_names);
155
156static const char *v4l2_memory_names[] = {
157 [V4L2_MEMORY_MMAP] = "mmap",
158 [V4L2_MEMORY_USERPTR] = "userptr",
159 [V4L2_MEMORY_OVERLAY] = "overlay",
160};
161
162#define prt_names(a, arr) ((((a) >= 0) && ((a) < ARRAY_SIZE(arr))) ? \
163 arr[a] : "unknown")
164
165/* ------------------------------------------------------------------ */
166/* debug help functions */
167
168#ifdef CONFIG_VIDEO_V4L1_COMPAT
169static const char *v4l1_ioctls[] = {
170 [_IOC_NR(VIDIOCGCAP)] = "VIDIOCGCAP",
171 [_IOC_NR(VIDIOCGCHAN)] = "VIDIOCGCHAN",
172 [_IOC_NR(VIDIOCSCHAN)] = "VIDIOCSCHAN",
173 [_IOC_NR(VIDIOCGTUNER)] = "VIDIOCGTUNER",
174 [_IOC_NR(VIDIOCSTUNER)] = "VIDIOCSTUNER",
175 [_IOC_NR(VIDIOCGPICT)] = "VIDIOCGPICT",
176 [_IOC_NR(VIDIOCSPICT)] = "VIDIOCSPICT",
177 [_IOC_NR(VIDIOCCAPTURE)] = "VIDIOCCAPTURE",
178 [_IOC_NR(VIDIOCGWIN)] = "VIDIOCGWIN",
179 [_IOC_NR(VIDIOCSWIN)] = "VIDIOCSWIN",
180 [_IOC_NR(VIDIOCGFBUF)] = "VIDIOCGFBUF",
181 [_IOC_NR(VIDIOCSFBUF)] = "VIDIOCSFBUF",
182 [_IOC_NR(VIDIOCKEY)] = "VIDIOCKEY",
183 [_IOC_NR(VIDIOCGFREQ)] = "VIDIOCGFREQ",
184 [_IOC_NR(VIDIOCSFREQ)] = "VIDIOCSFREQ",
185 [_IOC_NR(VIDIOCGAUDIO)] = "VIDIOCGAUDIO",
186 [_IOC_NR(VIDIOCSAUDIO)] = "VIDIOCSAUDIO",
187 [_IOC_NR(VIDIOCSYNC)] = "VIDIOCSYNC",
188 [_IOC_NR(VIDIOCMCAPTURE)] = "VIDIOCMCAPTURE",
189 [_IOC_NR(VIDIOCGMBUF)] = "VIDIOCGMBUF",
190 [_IOC_NR(VIDIOCGUNIT)] = "VIDIOCGUNIT",
191 [_IOC_NR(VIDIOCGCAPTURE)] = "VIDIOCGCAPTURE",
192 [_IOC_NR(VIDIOCSCAPTURE)] = "VIDIOCSCAPTURE",
193 [_IOC_NR(VIDIOCSPLAYMODE)] = "VIDIOCSPLAYMODE",
194 [_IOC_NR(VIDIOCSWRITEMODE)] = "VIDIOCSWRITEMODE",
195 [_IOC_NR(VIDIOCGPLAYINFO)] = "VIDIOCGPLAYINFO",
196 [_IOC_NR(VIDIOCSMICROCODE)] = "VIDIOCSMICROCODE",
197 [_IOC_NR(VIDIOCGVBIFMT)] = "VIDIOCGVBIFMT",
198 [_IOC_NR(VIDIOCSVBIFMT)] = "VIDIOCSVBIFMT"
199};
200#define V4L1_IOCTLS ARRAY_SIZE(v4l1_ioctls)
201#endif
202
203static const char *v4l2_ioctls[] = {
204 [_IOC_NR(VIDIOC_QUERYCAP)] = "VIDIOC_QUERYCAP",
205 [_IOC_NR(VIDIOC_RESERVED)] = "VIDIOC_RESERVED",
206 [_IOC_NR(VIDIOC_ENUM_FMT)] = "VIDIOC_ENUM_FMT",
207 [_IOC_NR(VIDIOC_G_FMT)] = "VIDIOC_G_FMT",
208 [_IOC_NR(VIDIOC_S_FMT)] = "VIDIOC_S_FMT",
209 [_IOC_NR(VIDIOC_REQBUFS)] = "VIDIOC_REQBUFS",
210 [_IOC_NR(VIDIOC_QUERYBUF)] = "VIDIOC_QUERYBUF",
211 [_IOC_NR(VIDIOC_G_FBUF)] = "VIDIOC_G_FBUF",
212 [_IOC_NR(VIDIOC_S_FBUF)] = "VIDIOC_S_FBUF",
213 [_IOC_NR(VIDIOC_OVERLAY)] = "VIDIOC_OVERLAY",
214 [_IOC_NR(VIDIOC_QBUF)] = "VIDIOC_QBUF",
215 [_IOC_NR(VIDIOC_DQBUF)] = "VIDIOC_DQBUF",
216 [_IOC_NR(VIDIOC_STREAMON)] = "VIDIOC_STREAMON",
217 [_IOC_NR(VIDIOC_STREAMOFF)] = "VIDIOC_STREAMOFF",
218 [_IOC_NR(VIDIOC_G_PARM)] = "VIDIOC_G_PARM",
219 [_IOC_NR(VIDIOC_S_PARM)] = "VIDIOC_S_PARM",
220 [_IOC_NR(VIDIOC_G_STD)] = "VIDIOC_G_STD",
221 [_IOC_NR(VIDIOC_S_STD)] = "VIDIOC_S_STD",
222 [_IOC_NR(VIDIOC_ENUMSTD)] = "VIDIOC_ENUMSTD",
223 [_IOC_NR(VIDIOC_ENUMINPUT)] = "VIDIOC_ENUMINPUT",
224 [_IOC_NR(VIDIOC_G_CTRL)] = "VIDIOC_G_CTRL",
225 [_IOC_NR(VIDIOC_S_CTRL)] = "VIDIOC_S_CTRL",
226 [_IOC_NR(VIDIOC_G_TUNER)] = "VIDIOC_G_TUNER",
227 [_IOC_NR(VIDIOC_S_TUNER)] = "VIDIOC_S_TUNER",
228 [_IOC_NR(VIDIOC_G_AUDIO)] = "VIDIOC_G_AUDIO",
229 [_IOC_NR(VIDIOC_S_AUDIO)] = "VIDIOC_S_AUDIO",
230 [_IOC_NR(VIDIOC_QUERYCTRL)] = "VIDIOC_QUERYCTRL",
231 [_IOC_NR(VIDIOC_QUERYMENU)] = "VIDIOC_QUERYMENU",
232 [_IOC_NR(VIDIOC_G_INPUT)] = "VIDIOC_G_INPUT",
233 [_IOC_NR(VIDIOC_S_INPUT)] = "VIDIOC_S_INPUT",
234 [_IOC_NR(VIDIOC_G_OUTPUT)] = "VIDIOC_G_OUTPUT",
235 [_IOC_NR(VIDIOC_S_OUTPUT)] = "VIDIOC_S_OUTPUT",
236 [_IOC_NR(VIDIOC_ENUMOUTPUT)] = "VIDIOC_ENUMOUTPUT",
237 [_IOC_NR(VIDIOC_G_AUDOUT)] = "VIDIOC_G_AUDOUT",
238 [_IOC_NR(VIDIOC_S_AUDOUT)] = "VIDIOC_S_AUDOUT",
239 [_IOC_NR(VIDIOC_G_MODULATOR)] = "VIDIOC_G_MODULATOR",
240 [_IOC_NR(VIDIOC_S_MODULATOR)] = "VIDIOC_S_MODULATOR",
241 [_IOC_NR(VIDIOC_G_FREQUENCY)] = "VIDIOC_G_FREQUENCY",
242 [_IOC_NR(VIDIOC_S_FREQUENCY)] = "VIDIOC_S_FREQUENCY",
243 [_IOC_NR(VIDIOC_CROPCAP)] = "VIDIOC_CROPCAP",
244 [_IOC_NR(VIDIOC_G_CROP)] = "VIDIOC_G_CROP",
245 [_IOC_NR(VIDIOC_S_CROP)] = "VIDIOC_S_CROP",
246 [_IOC_NR(VIDIOC_G_JPEGCOMP)] = "VIDIOC_G_JPEGCOMP",
247 [_IOC_NR(VIDIOC_S_JPEGCOMP)] = "VIDIOC_S_JPEGCOMP",
248 [_IOC_NR(VIDIOC_QUERYSTD)] = "VIDIOC_QUERYSTD",
249 [_IOC_NR(VIDIOC_TRY_FMT)] = "VIDIOC_TRY_FMT",
250 [_IOC_NR(VIDIOC_ENUMAUDIO)] = "VIDIOC_ENUMAUDIO",
251 [_IOC_NR(VIDIOC_ENUMAUDOUT)] = "VIDIOC_ENUMAUDOUT",
252 [_IOC_NR(VIDIOC_G_PRIORITY)] = "VIDIOC_G_PRIORITY",
253 [_IOC_NR(VIDIOC_S_PRIORITY)] = "VIDIOC_S_PRIORITY",
254 [_IOC_NR(VIDIOC_G_SLICED_VBI_CAP)] = "VIDIOC_G_SLICED_VBI_CAP",
255 [_IOC_NR(VIDIOC_LOG_STATUS)] = "VIDIOC_LOG_STATUS",
256 [_IOC_NR(VIDIOC_G_EXT_CTRLS)] = "VIDIOC_G_EXT_CTRLS",
257 [_IOC_NR(VIDIOC_S_EXT_CTRLS)] = "VIDIOC_S_EXT_CTRLS",
258 [_IOC_NR(VIDIOC_TRY_EXT_CTRLS)] = "VIDIOC_TRY_EXT_CTRLS",
259#if 1
260 [_IOC_NR(VIDIOC_ENUM_FRAMESIZES)] = "VIDIOC_ENUM_FRAMESIZES",
261 [_IOC_NR(VIDIOC_ENUM_FRAMEINTERVALS)] = "VIDIOC_ENUM_FRAMEINTERVALS",
262 [_IOC_NR(VIDIOC_G_ENC_INDEX)] = "VIDIOC_G_ENC_INDEX",
263 [_IOC_NR(VIDIOC_ENCODER_CMD)] = "VIDIOC_ENCODER_CMD",
264 [_IOC_NR(VIDIOC_TRY_ENCODER_CMD)] = "VIDIOC_TRY_ENCODER_CMD",
265
266 [_IOC_NR(VIDIOC_DBG_S_REGISTER)] = "VIDIOC_DBG_S_REGISTER",
267 [_IOC_NR(VIDIOC_DBG_G_REGISTER)] = "VIDIOC_DBG_G_REGISTER",
268
269 [_IOC_NR(VIDIOC_G_CHIP_IDENT)] = "VIDIOC_G_CHIP_IDENT",
270 [_IOC_NR(VIDIOC_S_HW_FREQ_SEEK)] = "VIDIOC_S_HW_FREQ_SEEK",
271#endif
272};
273#define V4L2_IOCTLS ARRAY_SIZE(v4l2_ioctls)
274
275static const char *v4l2_int_ioctls[] = {
276#ifdef CONFIG_VIDEO_V4L1_COMPAT
277 [_IOC_NR(DECODER_GET_CAPABILITIES)] = "DECODER_GET_CAPABILITIES",
278 [_IOC_NR(DECODER_GET_STATUS)] = "DECODER_GET_STATUS",
279 [_IOC_NR(DECODER_SET_NORM)] = "DECODER_SET_NORM",
280 [_IOC_NR(DECODER_SET_INPUT)] = "DECODER_SET_INPUT",
281 [_IOC_NR(DECODER_SET_OUTPUT)] = "DECODER_SET_OUTPUT",
282 [_IOC_NR(DECODER_ENABLE_OUTPUT)] = "DECODER_ENABLE_OUTPUT",
283 [_IOC_NR(DECODER_SET_PICTURE)] = "DECODER_SET_PICTURE",
284 [_IOC_NR(DECODER_SET_GPIO)] = "DECODER_SET_GPIO",
285 [_IOC_NR(DECODER_INIT)] = "DECODER_INIT",
286 [_IOC_NR(DECODER_SET_VBI_BYPASS)] = "DECODER_SET_VBI_BYPASS",
287 [_IOC_NR(DECODER_DUMP)] = "DECODER_DUMP",
288#endif
289 [_IOC_NR(AUDC_SET_RADIO)] = "AUDC_SET_RADIO",
290
291 [_IOC_NR(TUNER_SET_TYPE_ADDR)] = "TUNER_SET_TYPE_ADDR",
292 [_IOC_NR(TUNER_SET_STANDBY)] = "TUNER_SET_STANDBY",
293 [_IOC_NR(TUNER_SET_CONFIG)] = "TUNER_SET_CONFIG",
294
295 [_IOC_NR(VIDIOC_INT_S_TUNER_MODE)] = "VIDIOC_INT_S_TUNER_MODE",
296 [_IOC_NR(VIDIOC_INT_RESET)] = "VIDIOC_INT_RESET",
297 [_IOC_NR(VIDIOC_INT_AUDIO_CLOCK_FREQ)] = "VIDIOC_INT_AUDIO_CLOCK_FREQ",
298 [_IOC_NR(VIDIOC_INT_DECODE_VBI_LINE)] = "VIDIOC_INT_DECODE_VBI_LINE",
299 [_IOC_NR(VIDIOC_INT_S_VBI_DATA)] = "VIDIOC_INT_S_VBI_DATA",
300 [_IOC_NR(VIDIOC_INT_G_VBI_DATA)] = "VIDIOC_INT_G_VBI_DATA",
301 [_IOC_NR(VIDIOC_INT_I2S_CLOCK_FREQ)] = "VIDIOC_INT_I2S_CLOCK_FREQ",
302 [_IOC_NR(VIDIOC_INT_S_STANDBY)] = "VIDIOC_INT_S_STANDBY",
303 [_IOC_NR(VIDIOC_INT_S_AUDIO_ROUTING)] = "VIDIOC_INT_S_AUDIO_ROUTING",
304 [_IOC_NR(VIDIOC_INT_G_AUDIO_ROUTING)] = "VIDIOC_INT_G_AUDIO_ROUTING",
305 [_IOC_NR(VIDIOC_INT_S_VIDEO_ROUTING)] = "VIDIOC_INT_S_VIDEO_ROUTING",
306 [_IOC_NR(VIDIOC_INT_G_VIDEO_ROUTING)] = "VIDIOC_INT_G_VIDEO_ROUTING",
307 [_IOC_NR(VIDIOC_INT_S_CRYSTAL_FREQ)] = "VIDIOC_INT_S_CRYSTAL_FREQ",
308 [_IOC_NR(VIDIOC_INT_INIT)] = "VIDIOC_INT_INIT",
309 [_IOC_NR(VIDIOC_INT_G_STD_OUTPUT)] = "VIDIOC_INT_G_STD_OUTPUT",
310 [_IOC_NR(VIDIOC_INT_S_STD_OUTPUT)] = "VIDIOC_INT_S_STD_OUTPUT",
311};
312#define V4L2_INT_IOCTLS ARRAY_SIZE(v4l2_int_ioctls)
313
314/* Common ioctl debug function. This function can be used by
315 external ioctl messages as well as internal V4L ioctl */
316void v4l_printk_ioctl(unsigned int cmd)
317{
318 char *dir, *type;
319
320 switch (_IOC_TYPE(cmd)) {
321 case 'd':
322 if (_IOC_NR(cmd) >= V4L2_INT_IOCTLS) {
323 type = "v4l2_int";
324 break;
325 }
326 printk("%s", v4l2_int_ioctls[_IOC_NR(cmd)]);
327 return;
328#ifdef CONFIG_VIDEO_V4L1_COMPAT
329 case 'v':
330 if (_IOC_NR(cmd) >= V4L1_IOCTLS) {
331 type = "v4l1";
332 break;
333 }
334 printk("%s", v4l1_ioctls[_IOC_NR(cmd)]);
335 return;
336#endif
337 case 'V':
338 if (_IOC_NR(cmd) >= V4L2_IOCTLS) {
339 type = "v4l2";
340 break;
341 }
342 printk("%s", v4l2_ioctls[_IOC_NR(cmd)]);
343 return;
344 default:
345 type = "unknown";
346 }
347
348 switch (_IOC_DIR(cmd)) {
349 case _IOC_NONE: dir = "--"; break;
350 case _IOC_READ: dir = "r-"; break;
351 case _IOC_WRITE: dir = "-w"; break;
352 case _IOC_READ | _IOC_WRITE: dir = "rw"; break;
353 default: dir = "*ERR*"; break;
354 }
355 printk("%s ioctl '%c', dir=%s, #%d (0x%08x)",
356 type, _IOC_TYPE(cmd), dir, _IOC_NR(cmd), cmd);
357}
358EXPORT_SYMBOL(v4l_printk_ioctl);
359
360/*
361 * helper function -- handles userspace copying for ioctl arguments
362 */
363
364#ifdef __OLD_VIDIOC_
365static unsigned int
366video_fix_command(unsigned int cmd)
367{
368 switch (cmd) {
369 case VIDIOC_OVERLAY_OLD:
370 cmd = VIDIOC_OVERLAY;
371 break;
372 case VIDIOC_S_PARM_OLD:
373 cmd = VIDIOC_S_PARM;
374 break;
375 case VIDIOC_S_CTRL_OLD:
376 cmd = VIDIOC_S_CTRL;
377 break;
378 case VIDIOC_G_AUDIO_OLD:
379 cmd = VIDIOC_G_AUDIO;
380 break;
381 case VIDIOC_G_AUDOUT_OLD:
382 cmd = VIDIOC_G_AUDOUT;
383 break;
384 case VIDIOC_CROPCAP_OLD:
385 cmd = VIDIOC_CROPCAP;
386 break;
387 }
388 return cmd;
389}
390#endif
391
392/*
393 * Obsolete usercopy function - Should be removed soon
394 */
395int
396video_usercopy(struct inode *inode, struct file *file,
397 unsigned int cmd, unsigned long arg,
398 int (*func)(struct inode *inode, struct file *file,
399 unsigned int cmd, void *arg))
400{
401 char sbuf[128];
402 void *mbuf = NULL;
403 void *parg = NULL;
404 int err = -EINVAL;
405 int is_ext_ctrl;
406 size_t ctrls_size = 0;
407 void __user *user_ptr = NULL;
408
409#ifdef __OLD_VIDIOC_
410 cmd = video_fix_command(cmd);
411#endif
412 is_ext_ctrl = (cmd == VIDIOC_S_EXT_CTRLS || cmd == VIDIOC_G_EXT_CTRLS ||
413 cmd == VIDIOC_TRY_EXT_CTRLS);
414
415 /* Copy arguments into temp kernel buffer */
416 switch (_IOC_DIR(cmd)) {
417 case _IOC_NONE:
418 parg = NULL;
419 break;
420 case _IOC_READ:
421 case _IOC_WRITE:
422 case (_IOC_WRITE | _IOC_READ):
423 if (_IOC_SIZE(cmd) <= sizeof(sbuf)) {
424 parg = sbuf;
425 } else {
426 /* too big to allocate from stack */
427 mbuf = kmalloc(_IOC_SIZE(cmd), GFP_KERNEL);
428 if (NULL == mbuf)
429 return -ENOMEM;
430 parg = mbuf;
431 }
432
433 err = -EFAULT;
434 if (_IOC_DIR(cmd) & _IOC_WRITE)
435 if (copy_from_user(parg, (void __user *)arg, _IOC_SIZE(cmd)))
436 goto out;
437 break;
438 }
439 if (is_ext_ctrl) {
440 struct v4l2_ext_controls *p = parg;
441
442 /* In case of an error, tell the caller that it wasn't
443 a specific control that caused it. */
444 p->error_idx = p->count;
445 user_ptr = (void __user *)p->controls;
446 if (p->count) {
447 ctrls_size = sizeof(struct v4l2_ext_control) * p->count;
448 /* Note: v4l2_ext_controls fits in sbuf[] so mbuf is still NULL. */
449 mbuf = kmalloc(ctrls_size, GFP_KERNEL);
450 err = -ENOMEM;
451 if (NULL == mbuf)
452 goto out_ext_ctrl;
453 err = -EFAULT;
454 if (copy_from_user(mbuf, user_ptr, ctrls_size))
455 goto out_ext_ctrl;
456 p->controls = mbuf;
457 }
458 }
459
460 /* call driver */
461 err = func(inode, file, cmd, parg);
462 if (err == -ENOIOCTLCMD)
463 err = -EINVAL;
464 if (is_ext_ctrl) {
465 struct v4l2_ext_controls *p = parg;
466
467 p->controls = (void *)user_ptr;
468 if (p->count && err == 0 && copy_to_user(user_ptr, mbuf, ctrls_size))
469 err = -EFAULT;
470 goto out_ext_ctrl;
471 }
472 if (err < 0)
473 goto out;
474
475out_ext_ctrl:
476 /* Copy results into user buffer */
477 switch (_IOC_DIR(cmd)) {
478 case _IOC_READ:
479 case (_IOC_WRITE | _IOC_READ):
480 if (copy_to_user((void __user *)arg, parg, _IOC_SIZE(cmd)))
481 err = -EFAULT;
482 break;
483 }
484
485out:
486 kfree(mbuf);
487 return err;
488}
489EXPORT_SYMBOL(video_usercopy);
490
491static void dbgbuf(unsigned int cmd, struct video_device *vfd,
492 struct v4l2_buffer *p)
493{
494 struct v4l2_timecode *tc = &p->timecode;
495
496 dbgarg(cmd, "%02ld:%02d:%02d.%08ld index=%d, type=%s, "
497 "bytesused=%d, flags=0x%08d, "
498 "field=%0d, sequence=%d, memory=%s, offset/userptr=0x%08lx, length=%d\n",
499 p->timestamp.tv_sec / 3600,
500 (int)(p->timestamp.tv_sec / 60) % 60,
501 (int)(p->timestamp.tv_sec % 60),
502 p->timestamp.tv_usec,
503 p->index,
504 prt_names(p->type, v4l2_type_names),
505 p->bytesused, p->flags,
506 p->field, p->sequence,
507 prt_names(p->memory, v4l2_memory_names),
508 p->m.userptr, p->length);
509 dbgarg2("timecode=%02d:%02d:%02d type=%d, "
510 "flags=0x%08d, frames=%d, userbits=0x%08x\n",
511 tc->hours, tc->minutes, tc->seconds,
512 tc->type, tc->flags, tc->frames, *(__u32 *)tc->userbits);
513}
514
515static inline void dbgrect(struct video_device *vfd, char *s,
516 struct v4l2_rect *r)
517{
518 dbgarg2("%sRect start at %dx%d, size=%dx%d\n", s, r->left, r->top,
519 r->width, r->height);
520};
521
522static inline void v4l_print_pix_fmt(struct video_device *vfd,
523 struct v4l2_pix_format *fmt)
524{
525 dbgarg2("width=%d, height=%d, format=%c%c%c%c, field=%s, "
526 "bytesperline=%d sizeimage=%d, colorspace=%d\n",
527 fmt->width, fmt->height,
528 (fmt->pixelformat & 0xff),
529 (fmt->pixelformat >> 8) & 0xff,
530 (fmt->pixelformat >> 16) & 0xff,
531 (fmt->pixelformat >> 24) & 0xff,
532 prt_names(fmt->field, v4l2_field_names),
533 fmt->bytesperline, fmt->sizeimage, fmt->colorspace);
534};
535
536static inline void v4l_print_ext_ctrls(unsigned int cmd,
537 struct video_device *vfd, struct v4l2_ext_controls *c, int show_vals)
538{
539 __u32 i;
540
541 if (!(vfd->debug & V4L2_DEBUG_IOCTL_ARG))
542 return;
543 dbgarg(cmd, "");
544 printk(KERN_CONT "class=0x%x", c->ctrl_class);
545 for (i = 0; i < c->count; i++) {
546 if (show_vals)
547 printk(KERN_CONT " id/val=0x%x/0x%x",
548 c->controls[i].id, c->controls[i].value);
549 else
550 printk(KERN_CONT " id=0x%x", c->controls[i].id);
551 }
552 printk(KERN_CONT "\n");
553};
554
555static inline int check_ext_ctrls(struct v4l2_ext_controls *c, int allow_priv)
556{
557 __u32 i;
558
559 /* zero the reserved fields */
560 c->reserved[0] = c->reserved[1] = 0;
561 for (i = 0; i < c->count; i++) {
562 c->controls[i].reserved2[0] = 0;
563 c->controls[i].reserved2[1] = 0;
564 }
565 /* V4L2_CID_PRIVATE_BASE cannot be used as control class
566 when using extended controls.
567 Only when passed in through VIDIOC_G_CTRL and VIDIOC_S_CTRL
568 is it allowed for backwards compatibility.
569 */
570 if (!allow_priv && c->ctrl_class == V4L2_CID_PRIVATE_BASE)
571 return 0;
572 /* Check that all controls are from the same control class. */
573 for (i = 0; i < c->count; i++) {
574 if (V4L2_CTRL_ID2CLASS(c->controls[i].id) != c->ctrl_class) {
575 c->error_idx = i;
576 return 0;
577 }
578 }
579 return 1;
580}
581
582static int check_fmt(const struct v4l2_ioctl_ops *ops, enum v4l2_buf_type type)
583{
584 if (ops == NULL)
585 return -EINVAL;
586
587 switch (type) {
588 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
589 if (ops->vidioc_try_fmt_vid_cap)
590 return 0;
591 break;
592 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
593 if (ops->vidioc_try_fmt_vid_overlay)
594 return 0;
595 break;
596 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
597 if (ops->vidioc_try_fmt_vid_out)
598 return 0;
599 break;
600 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
601 if (ops->vidioc_try_fmt_vid_out_overlay)
602 return 0;
603 break;
604 case V4L2_BUF_TYPE_VBI_CAPTURE:
605 if (ops->vidioc_try_fmt_vbi_cap)
606 return 0;
607 break;
608 case V4L2_BUF_TYPE_VBI_OUTPUT:
609 if (ops->vidioc_try_fmt_vbi_out)
610 return 0;
611 break;
612 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
613 if (ops->vidioc_try_fmt_sliced_vbi_cap)
614 return 0;
615 break;
616 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
617 if (ops->vidioc_try_fmt_sliced_vbi_out)
618 return 0;
619 break;
620 case V4L2_BUF_TYPE_PRIVATE:
621 if (ops->vidioc_try_fmt_type_private)
622 return 0;
623 break;
624 }
625 return -EINVAL;
626}
627
628static int __video_do_ioctl(struct inode *inode, struct file *file,
629 unsigned int cmd, void *arg)
630{
631 struct video_device *vfd = video_devdata(file);
632 const struct v4l2_ioctl_ops *ops = vfd->ioctl_ops;
633 void *fh = file->private_data;
634 int ret = -EINVAL;
635
636 if ((vfd->debug & V4L2_DEBUG_IOCTL) &&
637 !(vfd->debug & V4L2_DEBUG_IOCTL_ARG)) {
638 v4l_print_ioctl(vfd->name, cmd);
639 printk(KERN_CONT "\n");
640 }
641
642 if (ops == NULL) {
643 printk(KERN_WARNING "videodev: \"%s\" has no ioctl_ops.\n",
644 vfd->name);
645 return -EINVAL;
646 }
647
648#ifdef CONFIG_VIDEO_V4L1_COMPAT
649 /***********************************************************
650 Handles calls to the obsoleted V4L1 API
651 Due to the nature of VIDIOCGMBUF, each driver that supports
652 V4L1 should implement its own handler for this ioctl.
653 ***********************************************************/
654
655 /* --- streaming capture ------------------------------------- */
656 if (cmd == VIDIOCGMBUF) {
657 struct video_mbuf *p = arg;
658
659 memset(p, 0, sizeof(*p));
660
661 if (!ops->vidiocgmbuf)
662 return ret;
663 ret = ops->vidiocgmbuf(file, fh, p);
664 if (!ret)
665 dbgarg(cmd, "size=%d, frames=%d, offsets=0x%08lx\n",
666 p->size, p->frames,
667 (unsigned long)p->offsets);
668 return ret;
669 }
670
671 /********************************************************
672 All other V4L1 calls are handled by v4l1_compat module.
673 Those calls will be translated into V4L2 calls, and
674 __video_do_ioctl will be called again, with one or more
675 V4L2 ioctls.
676 ********************************************************/
677 if (_IOC_TYPE(cmd) == 'v')
678 return v4l_compat_translate_ioctl(inode, file, cmd, arg,
679 __video_do_ioctl);
680#endif
681
682 switch (cmd) {
683 /* --- capabilities ------------------------------------------ */
684 case VIDIOC_QUERYCAP:
685 {
686 struct v4l2_capability *cap = (struct v4l2_capability *)arg;
687 memset(cap, 0, sizeof(*cap));
688
689 if (!ops->vidioc_querycap)
690 break;
691
692 ret = ops->vidioc_querycap(file, fh, cap);
693 if (!ret)
694 dbgarg(cmd, "driver=%s, card=%s, bus=%s, "
695 "version=0x%08x, "
696 "capabilities=0x%08x\n",
697 cap->driver, cap->card, cap->bus_info,
698 cap->version,
699 cap->capabilities);
700 break;
701 }
702
703 /* --- priority ------------------------------------------ */
704 case VIDIOC_G_PRIORITY:
705 {
706 enum v4l2_priority *p = arg;
707
708 if (!ops->vidioc_g_priority)
709 break;
710 ret = ops->vidioc_g_priority(file, fh, p);
711 if (!ret)
712 dbgarg(cmd, "priority is %d\n", *p);
713 break;
714 }
715 case VIDIOC_S_PRIORITY:
716 {
717 enum v4l2_priority *p = arg;
718
719 if (!ops->vidioc_s_priority)
720 break;
721 dbgarg(cmd, "setting priority to %d\n", *p);
722 ret = ops->vidioc_s_priority(file, fh, *p);
723 break;
724 }
725
726 /* --- capture ioctls ---------------------------------------- */
727 case VIDIOC_ENUM_FMT:
728 {
729 struct v4l2_fmtdesc *f = arg;
730 enum v4l2_buf_type type;
731 unsigned int index;
732
733 index = f->index;
734 type = f->type;
735 memset(f, 0, sizeof(*f));
736 f->index = index;
737 f->type = type;
738
739 switch (type) {
740 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
741 if (ops->vidioc_enum_fmt_vid_cap)
742 ret = ops->vidioc_enum_fmt_vid_cap(file, fh, f);
743 break;
744 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
745 if (ops->vidioc_enum_fmt_vid_overlay)
746 ret = ops->vidioc_enum_fmt_vid_overlay(file,
747 fh, f);
748 break;
749#if 1
750 /* V4L2_BUF_TYPE_VBI_CAPTURE should not support VIDIOC_ENUM_FMT
751 * according to the spec. The bttv and saa7134 drivers support
752 * it though, so just warn that this is deprecated and will be
753 * removed in the near future. */
754 case V4L2_BUF_TYPE_VBI_CAPTURE:
755 if (ops->vidioc_enum_fmt_vbi_cap) {
756 printk(KERN_WARNING "vidioc_enum_fmt_vbi_cap will be removed in 2.6.28!\n");
757 ret = ops->vidioc_enum_fmt_vbi_cap(file, fh, f);
758 }
759 break;
760#endif
761 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
762 if (ops->vidioc_enum_fmt_vid_out)
763 ret = ops->vidioc_enum_fmt_vid_out(file, fh, f);
764 break;
765 case V4L2_BUF_TYPE_PRIVATE:
766 if (ops->vidioc_enum_fmt_type_private)
767 ret = ops->vidioc_enum_fmt_type_private(file,
768 fh, f);
769 break;
770 default:
771 break;
772 }
773 if (!ret)
774 dbgarg(cmd, "index=%d, type=%d, flags=%d, "
775 "pixelformat=%c%c%c%c, description='%s'\n",
776 f->index, f->type, f->flags,
777 (f->pixelformat & 0xff),
778 (f->pixelformat >> 8) & 0xff,
779 (f->pixelformat >> 16) & 0xff,
780 (f->pixelformat >> 24) & 0xff,
781 f->description);
782 break;
783 }
784 case VIDIOC_G_FMT:
785 {
786 struct v4l2_format *f = (struct v4l2_format *)arg;
787
788 memset(f->fmt.raw_data, 0, sizeof(f->fmt.raw_data));
789
790 /* FIXME: Should be one dump per type */
791 dbgarg(cmd, "type=%s\n", prt_names(f->type, v4l2_type_names));
792
793 switch (f->type) {
794 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
795 if (ops->vidioc_g_fmt_vid_cap)
796 ret = ops->vidioc_g_fmt_vid_cap(file, fh, f);
797 if (!ret)
798 v4l_print_pix_fmt(vfd, &f->fmt.pix);
799 break;
800 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
801 if (ops->vidioc_g_fmt_vid_overlay)
802 ret = ops->vidioc_g_fmt_vid_overlay(file,
803 fh, f);
804 break;
805 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
806 if (ops->vidioc_g_fmt_vid_out)
807 ret = ops->vidioc_g_fmt_vid_out(file, fh, f);
808 if (!ret)
809 v4l_print_pix_fmt(vfd, &f->fmt.pix);
810 break;
811 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
812 if (ops->vidioc_g_fmt_vid_out_overlay)
813 ret = ops->vidioc_g_fmt_vid_out_overlay(file,
814 fh, f);
815 break;
816 case V4L2_BUF_TYPE_VBI_CAPTURE:
817 if (ops->vidioc_g_fmt_vbi_cap)
818 ret = ops->vidioc_g_fmt_vbi_cap(file, fh, f);
819 break;
820 case V4L2_BUF_TYPE_VBI_OUTPUT:
821 if (ops->vidioc_g_fmt_vbi_out)
822 ret = ops->vidioc_g_fmt_vbi_out(file, fh, f);
823 break;
824 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
825 if (ops->vidioc_g_fmt_sliced_vbi_cap)
826 ret = ops->vidioc_g_fmt_sliced_vbi_cap(file,
827 fh, f);
828 break;
829 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
830 if (ops->vidioc_g_fmt_sliced_vbi_out)
831 ret = ops->vidioc_g_fmt_sliced_vbi_out(file,
832 fh, f);
833 break;
834 case V4L2_BUF_TYPE_PRIVATE:
835 if (ops->vidioc_g_fmt_type_private)
836 ret = ops->vidioc_g_fmt_type_private(file,
837 fh, f);
838 break;
839 }
840
841 break;
842 }
843 case VIDIOC_S_FMT:
844 {
845 struct v4l2_format *f = (struct v4l2_format *)arg;
846
847 /* FIXME: Should be one dump per type */
848 dbgarg(cmd, "type=%s\n", prt_names(f->type, v4l2_type_names));
849
850 switch (f->type) {
851 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
852 v4l_print_pix_fmt(vfd, &f->fmt.pix);
853 if (ops->vidioc_s_fmt_vid_cap)
854 ret = ops->vidioc_s_fmt_vid_cap(file, fh, f);
855 break;
856 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
857 if (ops->vidioc_s_fmt_vid_overlay)
858 ret = ops->vidioc_s_fmt_vid_overlay(file,
859 fh, f);
860 break;
861 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
862 v4l_print_pix_fmt(vfd, &f->fmt.pix);
863 if (ops->vidioc_s_fmt_vid_out)
864 ret = ops->vidioc_s_fmt_vid_out(file, fh, f);
865 break;
866 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
867 if (ops->vidioc_s_fmt_vid_out_overlay)
868 ret = ops->vidioc_s_fmt_vid_out_overlay(file,
869 fh, f);
870 break;
871 case V4L2_BUF_TYPE_VBI_CAPTURE:
872 if (ops->vidioc_s_fmt_vbi_cap)
873 ret = ops->vidioc_s_fmt_vbi_cap(file, fh, f);
874 break;
875 case V4L2_BUF_TYPE_VBI_OUTPUT:
876 if (ops->vidioc_s_fmt_vbi_out)
877 ret = ops->vidioc_s_fmt_vbi_out(file, fh, f);
878 break;
879 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
880 if (ops->vidioc_s_fmt_sliced_vbi_cap)
881 ret = ops->vidioc_s_fmt_sliced_vbi_cap(file,
882 fh, f);
883 break;
884 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
885 if (ops->vidioc_s_fmt_sliced_vbi_out)
886 ret = ops->vidioc_s_fmt_sliced_vbi_out(file,
887 fh, f);
888 break;
889 case V4L2_BUF_TYPE_PRIVATE:
890 if (ops->vidioc_s_fmt_type_private)
891 ret = ops->vidioc_s_fmt_type_private(file,
892 fh, f);
893 break;
894 }
895 break;
896 }
897 case VIDIOC_TRY_FMT:
898 {
899 struct v4l2_format *f = (struct v4l2_format *)arg;
900
901 /* FIXME: Should be one dump per type */
902 dbgarg(cmd, "type=%s\n", prt_names(f->type,
903 v4l2_type_names));
904 switch (f->type) {
905 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
906 if (ops->vidioc_try_fmt_vid_cap)
907 ret = ops->vidioc_try_fmt_vid_cap(file, fh, f);
908 if (!ret)
909 v4l_print_pix_fmt(vfd, &f->fmt.pix);
910 break;
911 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
912 if (ops->vidioc_try_fmt_vid_overlay)
913 ret = ops->vidioc_try_fmt_vid_overlay(file,
914 fh, f);
915 break;
916 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
917 if (ops->vidioc_try_fmt_vid_out)
918 ret = ops->vidioc_try_fmt_vid_out(file, fh, f);
919 if (!ret)
920 v4l_print_pix_fmt(vfd, &f->fmt.pix);
921 break;
922 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
923 if (ops->vidioc_try_fmt_vid_out_overlay)
924 ret = ops->vidioc_try_fmt_vid_out_overlay(file,
925 fh, f);
926 break;
927 case V4L2_BUF_TYPE_VBI_CAPTURE:
928 if (ops->vidioc_try_fmt_vbi_cap)
929 ret = ops->vidioc_try_fmt_vbi_cap(file, fh, f);
930 break;
931 case V4L2_BUF_TYPE_VBI_OUTPUT:
932 if (ops->vidioc_try_fmt_vbi_out)
933 ret = ops->vidioc_try_fmt_vbi_out(file, fh, f);
934 break;
935 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
936 if (ops->vidioc_try_fmt_sliced_vbi_cap)
937 ret = ops->vidioc_try_fmt_sliced_vbi_cap(file,
938 fh, f);
939 break;
940 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
941 if (ops->vidioc_try_fmt_sliced_vbi_out)
942 ret = ops->vidioc_try_fmt_sliced_vbi_out(file,
943 fh, f);
944 break;
945 case V4L2_BUF_TYPE_PRIVATE:
946 if (ops->vidioc_try_fmt_type_private)
947 ret = ops->vidioc_try_fmt_type_private(file,
948 fh, f);
949 break;
950 }
951
952 break;
953 }
954 /* FIXME: Those buf reqs could be handled here,
955 with some changes on videobuf to allow its header to be included at
956 videodev2.h or being merged at videodev2.
957 */
958 case VIDIOC_REQBUFS:
959 {
960 struct v4l2_requestbuffers *p = arg;
961
962 if (!ops->vidioc_reqbufs)
963 break;
964 ret = check_fmt(ops, p->type);
965 if (ret)
966 break;
967
968 ret = ops->vidioc_reqbufs(file, fh, p);
969 dbgarg(cmd, "count=%d, type=%s, memory=%s\n",
970 p->count,
971 prt_names(p->type, v4l2_type_names),
972 prt_names(p->memory, v4l2_memory_names));
973 break;
974 }
975 case VIDIOC_QUERYBUF:
976 {
977 struct v4l2_buffer *p = arg;
978
979 if (!ops->vidioc_querybuf)
980 break;
981 ret = check_fmt(ops, p->type);
982 if (ret)
983 break;
984
985 ret = ops->vidioc_querybuf(file, fh, p);
986 if (!ret)
987 dbgbuf(cmd, vfd, p);
988 break;
989 }
990 case VIDIOC_QBUF:
991 {
992 struct v4l2_buffer *p = arg;
993
994 if (!ops->vidioc_qbuf)
995 break;
996 ret = check_fmt(ops, p->type);
997 if (ret)
998 break;
999
1000 ret = ops->vidioc_qbuf(file, fh, p);
1001 if (!ret)
1002 dbgbuf(cmd, vfd, p);
1003 break;
1004 }
1005 case VIDIOC_DQBUF:
1006 {
1007 struct v4l2_buffer *p = arg;
1008
1009 if (!ops->vidioc_dqbuf)
1010 break;
1011 ret = check_fmt(ops, p->type);
1012 if (ret)
1013 break;
1014
1015 ret = ops->vidioc_dqbuf(file, fh, p);
1016 if (!ret)
1017 dbgbuf(cmd, vfd, p);
1018 break;
1019 }
1020 case VIDIOC_OVERLAY:
1021 {
1022 int *i = arg;
1023
1024 if (!ops->vidioc_overlay)
1025 break;
1026 dbgarg(cmd, "value=%d\n", *i);
1027 ret = ops->vidioc_overlay(file, fh, *i);
1028 break;
1029 }
1030 case VIDIOC_G_FBUF:
1031 {
1032 struct v4l2_framebuffer *p = arg;
1033
1034 if (!ops->vidioc_g_fbuf)
1035 break;
1036 ret = ops->vidioc_g_fbuf(file, fh, arg);
1037 if (!ret) {
1038 dbgarg(cmd, "capability=0x%x, flags=%d, base=0x%08lx\n",
1039 p->capability, p->flags,
1040 (unsigned long)p->base);
1041 v4l_print_pix_fmt(vfd, &p->fmt);
1042 }
1043 break;
1044 }
1045 case VIDIOC_S_FBUF:
1046 {
1047 struct v4l2_framebuffer *p = arg;
1048
1049 if (!ops->vidioc_s_fbuf)
1050 break;
1051 dbgarg(cmd, "capability=0x%x, flags=%d, base=0x%08lx\n",
1052 p->capability, p->flags, (unsigned long)p->base);
1053 v4l_print_pix_fmt(vfd, &p->fmt);
1054 ret = ops->vidioc_s_fbuf(file, fh, arg);
1055 break;
1056 }
1057 case VIDIOC_STREAMON:
1058 {
1059 enum v4l2_buf_type i = *(int *)arg;
1060
1061 if (!ops->vidioc_streamon)
1062 break;
1063 dbgarg(cmd, "type=%s\n", prt_names(i, v4l2_type_names));
1064 ret = ops->vidioc_streamon(file, fh, i);
1065 break;
1066 }
1067 case VIDIOC_STREAMOFF:
1068 {
1069 enum v4l2_buf_type i = *(int *)arg;
1070
1071 if (!ops->vidioc_streamoff)
1072 break;
1073 dbgarg(cmd, "type=%s\n", prt_names(i, v4l2_type_names));
1074 ret = ops->vidioc_streamoff(file, fh, i);
1075 break;
1076 }
1077 /* ---------- tv norms ---------- */
1078 case VIDIOC_ENUMSTD:
1079 {
1080 struct v4l2_standard *p = arg;
1081 v4l2_std_id id = vfd->tvnorms, curr_id = 0;
1082 unsigned int index = p->index, i, j = 0;
1083 const char *descr = "";
1084
1085 /* Return norm array in a canonical way */
1086 for (i = 0; i <= index && id; i++) {
1087 /* last std value in the standards array is 0, so this
1088 while always ends there since (id & 0) == 0. */
1089 while ((id & standards[j].std) != standards[j].std)
1090 j++;
1091 curr_id = standards[j].std;
1092 descr = standards[j].descr;
1093 j++;
1094 if (curr_id == 0)
1095 break;
1096 if (curr_id != V4L2_STD_PAL &&
1097 curr_id != V4L2_STD_SECAM &&
1098 curr_id != V4L2_STD_NTSC)
1099 id &= ~curr_id;
1100 }
1101 if (i <= index)
1102 return -EINVAL;
1103
1104 v4l2_video_std_construct(p, curr_id, descr);
1105 p->index = index;
1106
1107 dbgarg(cmd, "index=%d, id=0x%Lx, name=%s, fps=%d/%d, "
1108 "framelines=%d\n", p->index,
1109 (unsigned long long)p->id, p->name,
1110 p->frameperiod.numerator,
1111 p->frameperiod.denominator,
1112 p->framelines);
1113
1114 ret = 0;
1115 break;
1116 }
1117 case VIDIOC_G_STD:
1118 {
1119 v4l2_std_id *id = arg;
1120
1121 ret = 0;
1122 /* Calls the specific handler */
1123 if (ops->vidioc_g_std)
1124 ret = ops->vidioc_g_std(file, fh, id);
1125 else
1126 *id = vfd->current_norm;
1127
1128 if (!ret)
1129 dbgarg(cmd, "std=0x%08Lx\n", (long long unsigned)*id);
1130 break;
1131 }
1132 case VIDIOC_S_STD:
1133 {
1134 v4l2_std_id *id = arg, norm;
1135
1136 dbgarg(cmd, "std=%08Lx\n", (long long unsigned)*id);
1137
1138 norm = (*id) & vfd->tvnorms;
1139 if (vfd->tvnorms && !norm) /* Check if std is supported */
1140 break;
1141
1142 /* Calls the specific handler */
1143 if (ops->vidioc_s_std)
1144 ret = ops->vidioc_s_std(file, fh, &norm);
1145 else
1146 ret = -EINVAL;
1147
1148 /* Updates standard information */
1149 if (ret >= 0)
1150 vfd->current_norm = norm;
1151 break;
1152 }
1153 case VIDIOC_QUERYSTD:
1154 {
1155 v4l2_std_id *p = arg;
1156
1157 if (!ops->vidioc_querystd)
1158 break;
1159 ret = ops->vidioc_querystd(file, fh, arg);
1160 if (!ret)
1161 dbgarg(cmd, "detected std=%08Lx\n",
1162 (unsigned long long)*p);
1163 break;
1164 }
1165 /* ------ input switching ---------- */
1166 /* FIXME: Inputs can be handled inside videodev2 */
1167 case VIDIOC_ENUMINPUT:
1168 {
1169 struct v4l2_input *p = arg;
1170 int i = p->index;
1171
1172 if (!ops->vidioc_enum_input)
1173 break;
1174 memset(p, 0, sizeof(*p));
1175 p->index = i;
1176
1177 ret = ops->vidioc_enum_input(file, fh, p);
1178 if (!ret)
1179 dbgarg(cmd, "index=%d, name=%s, type=%d, "
1180 "audioset=%d, "
1181 "tuner=%d, std=%08Lx, status=%d\n",
1182 p->index, p->name, p->type, p->audioset,
1183 p->tuner,
1184 (unsigned long long)p->std,
1185 p->status);
1186 break;
1187 }
1188 case VIDIOC_G_INPUT:
1189 {
1190 unsigned int *i = arg;
1191
1192 if (!ops->vidioc_g_input)
1193 break;
1194 ret = ops->vidioc_g_input(file, fh, i);
1195 if (!ret)
1196 dbgarg(cmd, "value=%d\n", *i);
1197 break;
1198 }
1199 case VIDIOC_S_INPUT:
1200 {
1201 unsigned int *i = arg;
1202
1203 if (!ops->vidioc_s_input)
1204 break;
1205 dbgarg(cmd, "value=%d\n", *i);
1206 ret = ops->vidioc_s_input(file, fh, *i);
1207 break;
1208 }
1209
1210 /* ------ output switching ---------- */
1211 case VIDIOC_ENUMOUTPUT:
1212 {
1213 struct v4l2_output *p = arg;
1214 int i = p->index;
1215
1216 if (!ops->vidioc_enum_output)
1217 break;
1218 memset(p, 0, sizeof(*p));
1219 p->index = i;
1220
1221 ret = ops->vidioc_enum_output(file, fh, p);
1222 if (!ret)
1223 dbgarg(cmd, "index=%d, name=%s, type=%d, "
1224 "audioset=0x%x, "
1225 "modulator=%d, std=0x%08Lx\n",
1226 p->index, p->name, p->type, p->audioset,
1227 p->modulator, (unsigned long long)p->std);
1228 break;
1229 }
1230 case VIDIOC_G_OUTPUT:
1231 {
1232 unsigned int *i = arg;
1233
1234 if (!ops->vidioc_g_output)
1235 break;
1236 ret = ops->vidioc_g_output(file, fh, i);
1237 if (!ret)
1238 dbgarg(cmd, "value=%d\n", *i);
1239 break;
1240 }
1241 case VIDIOC_S_OUTPUT:
1242 {
1243 unsigned int *i = arg;
1244
1245 if (!ops->vidioc_s_output)
1246 break;
1247 dbgarg(cmd, "value=%d\n", *i);
1248 ret = ops->vidioc_s_output(file, fh, *i);
1249 break;
1250 }
1251
1252 /* --- controls ---------------------------------------------- */
1253 case VIDIOC_QUERYCTRL:
1254 {
1255 struct v4l2_queryctrl *p = arg;
1256
1257 if (!ops->vidioc_queryctrl)
1258 break;
1259 ret = ops->vidioc_queryctrl(file, fh, p);
1260 if (!ret)
1261 dbgarg(cmd, "id=0x%x, type=%d, name=%s, min/max=%d/%d, "
1262 "step=%d, default=%d, flags=0x%08x\n",
1263 p->id, p->type, p->name,
1264 p->minimum, p->maximum,
1265 p->step, p->default_value, p->flags);
1266 else
1267 dbgarg(cmd, "id=0x%x\n", p->id);
1268 break;
1269 }
1270 case VIDIOC_G_CTRL:
1271 {
1272 struct v4l2_control *p = arg;
1273
1274 if (ops->vidioc_g_ctrl)
1275 ret = ops->vidioc_g_ctrl(file, fh, p);
1276 else if (ops->vidioc_g_ext_ctrls) {
1277 struct v4l2_ext_controls ctrls;
1278 struct v4l2_ext_control ctrl;
1279
1280 ctrls.ctrl_class = V4L2_CTRL_ID2CLASS(p->id);
1281 ctrls.count = 1;
1282 ctrls.controls = &ctrl;
1283 ctrl.id = p->id;
1284 ctrl.value = p->value;
1285 if (check_ext_ctrls(&ctrls, 1)) {
1286 ret = ops->vidioc_g_ext_ctrls(file, fh, &ctrls);
1287 if (ret == 0)
1288 p->value = ctrl.value;
1289 }
1290 } else
1291 break;
1292 if (!ret)
1293 dbgarg(cmd, "id=0x%x, value=%d\n", p->id, p->value);
1294 else
1295 dbgarg(cmd, "id=0x%x\n", p->id);
1296 break;
1297 }
1298 case VIDIOC_S_CTRL:
1299 {
1300 struct v4l2_control *p = arg;
1301 struct v4l2_ext_controls ctrls;
1302 struct v4l2_ext_control ctrl;
1303
1304 if (!ops->vidioc_s_ctrl && !ops->vidioc_s_ext_ctrls)
1305 break;
1306
1307 dbgarg(cmd, "id=0x%x, value=%d\n", p->id, p->value);
1308
1309 if (ops->vidioc_s_ctrl) {
1310 ret = ops->vidioc_s_ctrl(file, fh, p);
1311 break;
1312 }
1313 if (!ops->vidioc_s_ext_ctrls)
1314 break;
1315
1316 ctrls.ctrl_class = V4L2_CTRL_ID2CLASS(p->id);
1317 ctrls.count = 1;
1318 ctrls.controls = &ctrl;
1319 ctrl.id = p->id;
1320 ctrl.value = p->value;
1321 if (check_ext_ctrls(&ctrls, 1))
1322 ret = ops->vidioc_s_ext_ctrls(file, fh, &ctrls);
1323 break;
1324 }
1325 case VIDIOC_G_EXT_CTRLS:
1326 {
1327 struct v4l2_ext_controls *p = arg;
1328
1329 p->error_idx = p->count;
1330 if (!ops->vidioc_g_ext_ctrls)
1331 break;
1332 if (check_ext_ctrls(p, 0))
1333 ret = ops->vidioc_g_ext_ctrls(file, fh, p);
1334 v4l_print_ext_ctrls(cmd, vfd, p, !ret);
1335 break;
1336 }
1337 case VIDIOC_S_EXT_CTRLS:
1338 {
1339 struct v4l2_ext_controls *p = arg;
1340
1341 p->error_idx = p->count;
1342 if (!ops->vidioc_s_ext_ctrls)
1343 break;
1344 v4l_print_ext_ctrls(cmd, vfd, p, 1);
1345 if (check_ext_ctrls(p, 0))
1346 ret = ops->vidioc_s_ext_ctrls(file, fh, p);
1347 break;
1348 }
1349 case VIDIOC_TRY_EXT_CTRLS:
1350 {
1351 struct v4l2_ext_controls *p = arg;
1352
1353 p->error_idx = p->count;
1354 if (!ops->vidioc_try_ext_ctrls)
1355 break;
1356 v4l_print_ext_ctrls(cmd, vfd, p, 1);
1357 if (check_ext_ctrls(p, 0))
1358 ret = ops->vidioc_try_ext_ctrls(file, fh, p);
1359 break;
1360 }
1361 case VIDIOC_QUERYMENU:
1362 {
1363 struct v4l2_querymenu *p = arg;
1364
1365 if (!ops->vidioc_querymenu)
1366 break;
1367 ret = ops->vidioc_querymenu(file, fh, p);
1368 if (!ret)
1369 dbgarg(cmd, "id=0x%x, index=%d, name=%s\n",
1370 p->id, p->index, p->name);
1371 else
1372 dbgarg(cmd, "id=0x%x, index=%d\n",
1373 p->id, p->index);
1374 break;
1375 }
1376 /* --- audio ---------------------------------------------- */
1377 case VIDIOC_ENUMAUDIO:
1378 {
1379 struct v4l2_audio *p = arg;
1380
1381 if (!ops->vidioc_enumaudio)
1382 break;
1383 ret = ops->vidioc_enumaudio(file, fh, p);
1384 if (!ret)
1385 dbgarg(cmd, "index=%d, name=%s, capability=0x%x, "
1386 "mode=0x%x\n", p->index, p->name,
1387 p->capability, p->mode);
1388 else
1389 dbgarg(cmd, "index=%d\n", p->index);
1390 break;
1391 }
1392 case VIDIOC_G_AUDIO:
1393 {
1394 struct v4l2_audio *p = arg;
1395 __u32 index = p->index;
1396
1397 if (!ops->vidioc_g_audio)
1398 break;
1399
1400 memset(p, 0, sizeof(*p));
1401 p->index = index;
1402 ret = ops->vidioc_g_audio(file, fh, p);
1403 if (!ret)
1404 dbgarg(cmd, "index=%d, name=%s, capability=0x%x, "
1405 "mode=0x%x\n", p->index,
1406 p->name, p->capability, p->mode);
1407 else
1408 dbgarg(cmd, "index=%d\n", p->index);
1409 break;
1410 }
1411 case VIDIOC_S_AUDIO:
1412 {
1413 struct v4l2_audio *p = arg;
1414
1415 if (!ops->vidioc_s_audio)
1416 break;
1417 dbgarg(cmd, "index=%d, name=%s, capability=0x%x, "
1418 "mode=0x%x\n", p->index, p->name,
1419 p->capability, p->mode);
1420 ret = ops->vidioc_s_audio(file, fh, p);
1421 break;
1422 }
1423 case VIDIOC_ENUMAUDOUT:
1424 {
1425 struct v4l2_audioout *p = arg;
1426
1427 if (!ops->vidioc_enumaudout)
1428 break;
1429 dbgarg(cmd, "Enum for index=%d\n", p->index);
1430 ret = ops->vidioc_enumaudout(file, fh, p);
1431 if (!ret)
1432 dbgarg2("index=%d, name=%s, capability=%d, "
1433 "mode=%d\n", p->index, p->name,
1434 p->capability, p->mode);
1435 break;
1436 }
1437 case VIDIOC_G_AUDOUT:
1438 {
1439 struct v4l2_audioout *p = arg;
1440
1441 if (!ops->vidioc_g_audout)
1442 break;
1443 dbgarg(cmd, "Enum for index=%d\n", p->index);
1444 ret = ops->vidioc_g_audout(file, fh, p);
1445 if (!ret)
1446 dbgarg2("index=%d, name=%s, capability=%d, "
1447 "mode=%d\n", p->index, p->name,
1448 p->capability, p->mode);
1449 break;
1450 }
1451 case VIDIOC_S_AUDOUT:
1452 {
1453 struct v4l2_audioout *p = arg;
1454
1455 if (!ops->vidioc_s_audout)
1456 break;
1457 dbgarg(cmd, "index=%d, name=%s, capability=%d, "
1458 "mode=%d\n", p->index, p->name,
1459 p->capability, p->mode);
1460
1461 ret = ops->vidioc_s_audout(file, fh, p);
1462 break;
1463 }
1464 case VIDIOC_G_MODULATOR:
1465 {
1466 struct v4l2_modulator *p = arg;
1467
1468 if (!ops->vidioc_g_modulator)
1469 break;
1470 ret = ops->vidioc_g_modulator(file, fh, p);
1471 if (!ret)
1472 dbgarg(cmd, "index=%d, name=%s, "
1473 "capability=%d, rangelow=%d,"
1474 " rangehigh=%d, txsubchans=%d\n",
1475 p->index, p->name, p->capability,
1476 p->rangelow, p->rangehigh,
1477 p->txsubchans);
1478 break;
1479 }
1480 case VIDIOC_S_MODULATOR:
1481 {
1482 struct v4l2_modulator *p = arg;
1483
1484 if (!ops->vidioc_s_modulator)
1485 break;
1486 dbgarg(cmd, "index=%d, name=%s, capability=%d, "
1487 "rangelow=%d, rangehigh=%d, txsubchans=%d\n",
1488 p->index, p->name, p->capability, p->rangelow,
1489 p->rangehigh, p->txsubchans);
1490 ret = ops->vidioc_s_modulator(file, fh, p);
1491 break;
1492 }
1493 case VIDIOC_G_CROP:
1494 {
1495 struct v4l2_crop *p = arg;
1496
1497 if (!ops->vidioc_g_crop)
1498 break;
1499 dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names));
1500 ret = ops->vidioc_g_crop(file, fh, p);
1501 if (!ret)
1502 dbgrect(vfd, "", &p->c);
1503 break;
1504 }
1505 case VIDIOC_S_CROP:
1506 {
1507 struct v4l2_crop *p = arg;
1508
1509 if (!ops->vidioc_s_crop)
1510 break;
1511 dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names));
1512 dbgrect(vfd, "", &p->c);
1513 ret = ops->vidioc_s_crop(file, fh, p);
1514 break;
1515 }
1516 case VIDIOC_CROPCAP:
1517 {
1518 struct v4l2_cropcap *p = arg;
1519
1520 /*FIXME: Should also show v4l2_fract pixelaspect */
1521 if (!ops->vidioc_cropcap)
1522 break;
1523 dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names));
1524 ret = ops->vidioc_cropcap(file, fh, p);
1525 if (!ret) {
1526 dbgrect(vfd, "bounds ", &p->bounds);
1527 dbgrect(vfd, "defrect ", &p->defrect);
1528 }
1529 break;
1530 }
1531 case VIDIOC_G_JPEGCOMP:
1532 {
1533 struct v4l2_jpegcompression *p = arg;
1534
1535 if (!ops->vidioc_g_jpegcomp)
1536 break;
1537 ret = ops->vidioc_g_jpegcomp(file, fh, p);
1538 if (!ret)
1539 dbgarg(cmd, "quality=%d, APPn=%d, "
1540 "APP_len=%d, COM_len=%d, "
1541 "jpeg_markers=%d\n",
1542 p->quality, p->APPn, p->APP_len,
1543 p->COM_len, p->jpeg_markers);
1544 break;
1545 }
1546 case VIDIOC_S_JPEGCOMP:
1547 {
1548 struct v4l2_jpegcompression *p = arg;
1549
1550 if (!ops->vidioc_g_jpegcomp)
1551 break;
1552 dbgarg(cmd, "quality=%d, APPn=%d, APP_len=%d, "
1553 "COM_len=%d, jpeg_markers=%d\n",
1554 p->quality, p->APPn, p->APP_len,
1555 p->COM_len, p->jpeg_markers);
1556 ret = ops->vidioc_s_jpegcomp(file, fh, p);
1557 break;
1558 }
1559 case VIDIOC_G_ENC_INDEX:
1560 {
1561 struct v4l2_enc_idx *p = arg;
1562
1563 if (!ops->vidioc_g_enc_index)
1564 break;
1565 ret = ops->vidioc_g_enc_index(file, fh, p);
1566 if (!ret)
1567 dbgarg(cmd, "entries=%d, entries_cap=%d\n",
1568 p->entries, p->entries_cap);
1569 break;
1570 }
1571 case VIDIOC_ENCODER_CMD:
1572 {
1573 struct v4l2_encoder_cmd *p = arg;
1574
1575 if (!ops->vidioc_encoder_cmd)
1576 break;
1577 memset(&p->raw, 0, sizeof(p->raw));
1578 ret = ops->vidioc_encoder_cmd(file, fh, p);
1579 if (!ret)
1580 dbgarg(cmd, "cmd=%d, flags=%x\n", p->cmd, p->flags);
1581 break;
1582 }
1583 case VIDIOC_TRY_ENCODER_CMD:
1584 {
1585 struct v4l2_encoder_cmd *p = arg;
1586
1587 if (!ops->vidioc_try_encoder_cmd)
1588 break;
1589 memset(&p->raw, 0, sizeof(p->raw));
1590 ret = ops->vidioc_try_encoder_cmd(file, fh, p);
1591 if (!ret)
1592 dbgarg(cmd, "cmd=%d, flags=%x\n", p->cmd, p->flags);
1593 break;
1594 }
1595 case VIDIOC_G_PARM:
1596 {
1597 struct v4l2_streamparm *p = arg;
1598 __u32 type = p->type;
1599
1600 memset(p, 0, sizeof(*p));
1601 p->type = type;
1602
1603 if (ops->vidioc_g_parm) {
1604 ret = ops->vidioc_g_parm(file, fh, p);
1605 } else {
1606 struct v4l2_standard s;
1607
1608 if (p->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1609 return -EINVAL;
1610
1611 v4l2_video_std_construct(&s, vfd->current_norm,
1612 v4l2_norm_to_name(vfd->current_norm));
1613
1614 p->parm.capture.timeperframe = s.frameperiod;
1615 ret = 0;
1616 }
1617
1618 dbgarg(cmd, "type=%d\n", p->type);
1619 break;
1620 }
1621 case VIDIOC_S_PARM:
1622 {
1623 struct v4l2_streamparm *p = arg;
1624
1625 if (!ops->vidioc_s_parm)
1626 break;
1627 dbgarg(cmd, "type=%d\n", p->type);
1628 ret = ops->vidioc_s_parm(file, fh, p);
1629 break;
1630 }
1631 case VIDIOC_G_TUNER:
1632 {
1633 struct v4l2_tuner *p = arg;
1634 __u32 index = p->index;
1635
1636 if (!ops->vidioc_g_tuner)
1637 break;
1638
1639 memset(p, 0, sizeof(*p));
1640 p->index = index;
1641
1642 ret = ops->vidioc_g_tuner(file, fh, p);
1643 if (!ret)
1644 dbgarg(cmd, "index=%d, name=%s, type=%d, "
1645 "capability=0x%x, rangelow=%d, "
1646 "rangehigh=%d, signal=%d, afc=%d, "
1647 "rxsubchans=0x%x, audmode=%d\n",
1648 p->index, p->name, p->type,
1649 p->capability, p->rangelow,
1650 p->rangehigh, p->signal, p->afc,
1651 p->rxsubchans, p->audmode);
1652 break;
1653 }
1654 case VIDIOC_S_TUNER:
1655 {
1656 struct v4l2_tuner *p = arg;
1657
1658 if (!ops->vidioc_s_tuner)
1659 break;
1660 dbgarg(cmd, "index=%d, name=%s, type=%d, "
1661 "capability=0x%x, rangelow=%d, "
1662 "rangehigh=%d, signal=%d, afc=%d, "
1663 "rxsubchans=0x%x, audmode=%d\n",
1664 p->index, p->name, p->type,
1665 p->capability, p->rangelow,
1666 p->rangehigh, p->signal, p->afc,
1667 p->rxsubchans, p->audmode);
1668 ret = ops->vidioc_s_tuner(file, fh, p);
1669 break;
1670 }
1671 case VIDIOC_G_FREQUENCY:
1672 {
1673 struct v4l2_frequency *p = arg;
1674
1675 if (!ops->vidioc_g_frequency)
1676 break;
1677
1678 memset(p->reserved, 0, sizeof(p->reserved));
1679
1680 ret = ops->vidioc_g_frequency(file, fh, p);
1681 if (!ret)
1682 dbgarg(cmd, "tuner=%d, type=%d, frequency=%d\n",
1683 p->tuner, p->type, p->frequency);
1684 break;
1685 }
1686 case VIDIOC_S_FREQUENCY:
1687 {
1688 struct v4l2_frequency *p = arg;
1689
1690 if (!ops->vidioc_s_frequency)
1691 break;
1692 dbgarg(cmd, "tuner=%d, type=%d, frequency=%d\n",
1693 p->tuner, p->type, p->frequency);
1694 ret = ops->vidioc_s_frequency(file, fh, p);
1695 break;
1696 }
1697 case VIDIOC_G_SLICED_VBI_CAP:
1698 {
1699 struct v4l2_sliced_vbi_cap *p = arg;
1700 __u32 type = p->type;
1701
1702 if (!ops->vidioc_g_sliced_vbi_cap)
1703 break;
1704 memset(p, 0, sizeof(*p));
1705 p->type = type;
1706 dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names));
1707 ret = ops->vidioc_g_sliced_vbi_cap(file, fh, p);
1708 if (!ret)
1709 dbgarg2("service_set=%d\n", p->service_set);
1710 break;
1711 }
1712 case VIDIOC_LOG_STATUS:
1713 {
1714 if (!ops->vidioc_log_status)
1715 break;
1716 ret = ops->vidioc_log_status(file, fh);
1717 break;
1718 }
1719#ifdef CONFIG_VIDEO_ADV_DEBUG
1720 case VIDIOC_DBG_G_REGISTER:
1721 {
1722 struct v4l2_register *p = arg;
1723
1724 if (!capable(CAP_SYS_ADMIN))
1725 ret = -EPERM;
1726 else if (ops->vidioc_g_register)
1727 ret = ops->vidioc_g_register(file, fh, p);
1728 break;
1729 }
1730 case VIDIOC_DBG_S_REGISTER:
1731 {
1732 struct v4l2_register *p = arg;
1733
1734 if (!capable(CAP_SYS_ADMIN))
1735 ret = -EPERM;
1736 else if (ops->vidioc_s_register)
1737 ret = ops->vidioc_s_register(file, fh, p);
1738 break;
1739 }
1740#endif
1741 case VIDIOC_G_CHIP_IDENT:
1742 {
1743 struct v4l2_chip_ident *p = arg;
1744
1745 if (!ops->vidioc_g_chip_ident)
1746 break;
1747 ret = ops->vidioc_g_chip_ident(file, fh, p);
1748 if (!ret)
1749 dbgarg(cmd, "chip_ident=%u, revision=0x%x\n", p->ident, p->revision);
1750 break;
1751 }
1752 case VIDIOC_S_HW_FREQ_SEEK:
1753 {
1754 struct v4l2_hw_freq_seek *p = arg;
1755
1756 if (!ops->vidioc_s_hw_freq_seek)
1757 break;
1758 dbgarg(cmd,
1759 "tuner=%d, type=%d, seek_upward=%d, wrap_around=%d\n",
1760 p->tuner, p->type, p->seek_upward, p->wrap_around);
1761 ret = ops->vidioc_s_hw_freq_seek(file, fh, p);
1762 break;
1763 }
1764 default:
1765 {
1766 if (!ops->vidioc_default)
1767 break;
1768 ret = ops->vidioc_default(file, fh, cmd, arg);
1769 break;
1770 }
1771 } /* switch */
1772
1773 if (vfd->debug & V4L2_DEBUG_IOCTL_ARG) {
1774 if (ret < 0) {
1775 v4l_print_ioctl(vfd->name, cmd);
1776 printk(KERN_CONT " error %d\n", ret);
1777 }
1778 }
1779
1780 return ret;
1781}
1782
1783int video_ioctl2(struct inode *inode, struct file *file,
1784 unsigned int cmd, unsigned long arg)
1785{
1786 char sbuf[128];
1787 void *mbuf = NULL;
1788 void *parg = NULL;
1789 int err = -EINVAL;
1790 int is_ext_ctrl;
1791 size_t ctrls_size = 0;
1792 void __user *user_ptr = NULL;
1793
1794#ifdef __OLD_VIDIOC_
1795 cmd = video_fix_command(cmd);
1796#endif
1797 is_ext_ctrl = (cmd == VIDIOC_S_EXT_CTRLS || cmd == VIDIOC_G_EXT_CTRLS ||
1798 cmd == VIDIOC_TRY_EXT_CTRLS);
1799
1800 /* Copy arguments into temp kernel buffer */
1801 switch (_IOC_DIR(cmd)) {
1802 case _IOC_NONE:
1803 parg = NULL;
1804 break;
1805 case _IOC_READ:
1806 case _IOC_WRITE:
1807 case (_IOC_WRITE | _IOC_READ):
1808 if (_IOC_SIZE(cmd) <= sizeof(sbuf)) {
1809 parg = sbuf;
1810 } else {
1811 /* too big to allocate from stack */
1812 mbuf = kmalloc(_IOC_SIZE(cmd), GFP_KERNEL);
1813 if (NULL == mbuf)
1814 return -ENOMEM;
1815 parg = mbuf;
1816 }
1817
1818 err = -EFAULT;
1819 if (_IOC_DIR(cmd) & _IOC_WRITE)
1820 if (copy_from_user(parg, (void __user *)arg, _IOC_SIZE(cmd)))
1821 goto out;
1822 break;
1823 }
1824
1825 if (is_ext_ctrl) {
1826 struct v4l2_ext_controls *p = parg;
1827
1828 /* In case of an error, tell the caller that it wasn't
1829 a specific control that caused it. */
1830 p->error_idx = p->count;
1831 user_ptr = (void __user *)p->controls;
1832 if (p->count) {
1833 ctrls_size = sizeof(struct v4l2_ext_control) * p->count;
1834 /* Note: v4l2_ext_controls fits in sbuf[] so mbuf is still NULL. */
1835 mbuf = kmalloc(ctrls_size, GFP_KERNEL);
1836 err = -ENOMEM;
1837 if (NULL == mbuf)
1838 goto out_ext_ctrl;
1839 err = -EFAULT;
1840 if (copy_from_user(mbuf, user_ptr, ctrls_size))
1841 goto out_ext_ctrl;
1842 p->controls = mbuf;
1843 }
1844 }
1845
1846 /* Handles IOCTL */
1847 err = __video_do_ioctl(inode, file, cmd, parg);
1848 if (err == -ENOIOCTLCMD)
1849 err = -EINVAL;
1850 if (is_ext_ctrl) {
1851 struct v4l2_ext_controls *p = parg;
1852
1853 p->controls = (void *)user_ptr;
1854 if (p->count && err == 0 && copy_to_user(user_ptr, mbuf, ctrls_size))
1855 err = -EFAULT;
1856 goto out_ext_ctrl;
1857 }
1858 if (err < 0)
1859 goto out;
1860
1861out_ext_ctrl:
1862 /* Copy results into user buffer */
1863 switch (_IOC_DIR(cmd)) {
1864 case _IOC_READ:
1865 case (_IOC_WRITE | _IOC_READ):
1866 if (copy_to_user((void __user *)arg, parg, _IOC_SIZE(cmd)))
1867 err = -EFAULT;
1868 break;
1869 }
1870
1871out:
1872 kfree(mbuf);
1873 return err;
1874}
1875EXPORT_SYMBOL(video_ioctl2);
diff --git a/drivers/media/video/videobuf-dma-contig.c b/drivers/media/video/videobuf-dma-contig.c
index 03f20acb668c..31944b11e6ea 100644
--- a/drivers/media/video/videobuf-dma-contig.c
+++ b/drivers/media/video/videobuf-dma-contig.c
@@ -28,10 +28,10 @@ struct videobuf_dma_contig_memory {
28}; 28};
29 29
30#define MAGIC_DC_MEM 0x0733ac61 30#define MAGIC_DC_MEM 0x0733ac61
31#define MAGIC_CHECK(is, should) \ 31#define MAGIC_CHECK(is, should) \
32 if (unlikely((is) != (should))) { \ 32 if (unlikely((is) != (should))) { \
33 pr_err("magic mismatch: %x expected %x\n", is, should); \ 33 pr_err("magic mismatch: %x expected %x\n", (is), (should)); \
34 BUG(); \ 34 BUG(); \
35 } 35 }
36 36
37static void 37static void
diff --git a/drivers/media/video/videobuf-vmalloc.c b/drivers/media/video/videobuf-vmalloc.c
index a868b7ed75ff..be65a2fb3976 100644
--- a/drivers/media/video/videobuf-vmalloc.c
+++ b/drivers/media/video/videobuf-vmalloc.c
@@ -203,7 +203,7 @@ static int __videobuf_iolock (struct videobuf_queue* q,
203 return 0; 203 return 0;
204 204
205 /* FIXME: to properly support USERPTR, remap should occur. 205 /* FIXME: to properly support USERPTR, remap should occur.
206 The code bellow won't work, since mem->vma = NULL 206 The code below won't work, since mem->vma = NULL
207 */ 207 */
208 /* Try to remap memory */ 208 /* Try to remap memory */
209 rc = remap_vmalloc_range(mem->vma, (void *)vb->baddr, 0); 209 rc = remap_vmalloc_range(mem->vma, (void *)vb->baddr, 0);
diff --git a/drivers/media/video/videodev.c b/drivers/media/video/videodev.c
index 6616e6570557..e69de29bb2d1 100644
--- a/drivers/media/video/videodev.c
+++ b/drivers/media/video/videodev.c
@@ -1,2262 +0,0 @@
1/*
2 * Video capture interface for Linux version 2
3 *
4 * A generic video device interface for the LINUX operating system
5 * using a set of device structures/vectors for low level operations.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version
10 * 2 of the License, or (at your option) any later version.
11 *
12 * Authors: Alan Cox, <alan@redhat.com> (version 1)
13 * Mauro Carvalho Chehab <mchehab@infradead.org> (version 2)
14 *
15 * Fixes: 20000516 Claudio Matsuoka <claudio@conectiva.com>
16 * - Added procfs support
17 */
18
19#define dbgarg(cmd, fmt, arg...) \
20 do { \
21 if (vfd->debug & V4L2_DEBUG_IOCTL_ARG) { \
22 printk(KERN_DEBUG "%s: ", vfd->name); \
23 v4l_printk_ioctl(cmd); \
24 printk(" " fmt, ## arg); \
25 } \
26 } while (0)
27
28#define dbgarg2(fmt, arg...) \
29 do { \
30 if (vfd->debug & V4L2_DEBUG_IOCTL_ARG) \
31 printk(KERN_DEBUG "%s: " fmt, vfd->name, ## arg);\
32 } while (0)
33
34#include <linux/module.h>
35#include <linux/types.h>
36#include <linux/kernel.h>
37#include <linux/mm.h>
38#include <linux/string.h>
39#include <linux/errno.h>
40#include <linux/init.h>
41#include <linux/kmod.h>
42#include <linux/slab.h>
43#include <linux/smp_lock.h>
44#include <asm/uaccess.h>
45#include <asm/system.h>
46
47#define __OLD_VIDIOC_ /* To allow fixing old calls*/
48#include <linux/videodev2.h>
49
50#ifdef CONFIG_VIDEO_V4L1
51#include <linux/videodev.h>
52#endif
53#include <media/v4l2-common.h>
54#include <linux/video_decoder.h>
55
56#define VIDEO_NUM_DEVICES 256
57#define VIDEO_NAME "video4linux"
58
59struct std_descr {
60 v4l2_std_id std;
61 const char *descr;
62};
63
64static const struct std_descr standards[] = {
65 { V4L2_STD_NTSC, "NTSC" },
66 { V4L2_STD_NTSC_M, "NTSC-M" },
67 { V4L2_STD_NTSC_M_JP, "NTSC-M-JP" },
68 { V4L2_STD_NTSC_M_KR, "NTSC-M-KR" },
69 { V4L2_STD_NTSC_443, "NTSC-443" },
70 { V4L2_STD_PAL, "PAL" },
71 { V4L2_STD_PAL_BG, "PAL-BG" },
72 { V4L2_STD_PAL_B, "PAL-B" },
73 { V4L2_STD_PAL_B1, "PAL-B1" },
74 { V4L2_STD_PAL_G, "PAL-G" },
75 { V4L2_STD_PAL_H, "PAL-H" },
76 { V4L2_STD_PAL_I, "PAL-I" },
77 { V4L2_STD_PAL_DK, "PAL-DK" },
78 { V4L2_STD_PAL_D, "PAL-D" },
79 { V4L2_STD_PAL_D1, "PAL-D1" },
80 { V4L2_STD_PAL_K, "PAL-K" },
81 { V4L2_STD_PAL_M, "PAL-M" },
82 { V4L2_STD_PAL_N, "PAL-N" },
83 { V4L2_STD_PAL_Nc, "PAL-Nc" },
84 { V4L2_STD_PAL_60, "PAL-60" },
85 { V4L2_STD_SECAM, "SECAM" },
86 { V4L2_STD_SECAM_B, "SECAM-B" },
87 { V4L2_STD_SECAM_G, "SECAM-G" },
88 { V4L2_STD_SECAM_H, "SECAM-H" },
89 { V4L2_STD_SECAM_DK, "SECAM-DK" },
90 { V4L2_STD_SECAM_D, "SECAM-D" },
91 { V4L2_STD_SECAM_K, "SECAM-K" },
92 { V4L2_STD_SECAM_K1, "SECAM-K1" },
93 { V4L2_STD_SECAM_L, "SECAM-L" },
94 { V4L2_STD_SECAM_LC, "SECAM-Lc" },
95 { 0, "Unknown" }
96};
97
98/* video4linux standard ID conversion to standard name
99 */
100const char *v4l2_norm_to_name(v4l2_std_id id)
101{
102 u32 myid = id;
103 int i;
104
105 /* HACK: ppc32 architecture doesn't have __ucmpdi2 function to handle
106 64 bit comparations. So, on that architecture, with some gcc
107 variants, compilation fails. Currently, the max value is 30bit wide.
108 */
109 BUG_ON(myid != id);
110
111 for (i = 0; standards[i].std; i++)
112 if (myid == standards[i].std)
113 break;
114 return standards[i].descr;
115}
116EXPORT_SYMBOL(v4l2_norm_to_name);
117
118/* Fill in the fields of a v4l2_standard structure according to the
119 'id' and 'transmission' parameters. Returns negative on error. */
120int v4l2_video_std_construct(struct v4l2_standard *vs,
121 int id, const char *name)
122{
123 u32 index = vs->index;
124
125 memset(vs, 0, sizeof(struct v4l2_standard));
126 vs->index = index;
127 vs->id = id;
128 if (id & V4L2_STD_525_60) {
129 vs->frameperiod.numerator = 1001;
130 vs->frameperiod.denominator = 30000;
131 vs->framelines = 525;
132 } else {
133 vs->frameperiod.numerator = 1;
134 vs->frameperiod.denominator = 25;
135 vs->framelines = 625;
136 }
137 strlcpy(vs->name, name, sizeof(vs->name));
138 return 0;
139}
140EXPORT_SYMBOL(v4l2_video_std_construct);
141
142/* ----------------------------------------------------------------- */
143/* some arrays for pretty-printing debug messages of enum types */
144
145const char *v4l2_field_names[] = {
146 [V4L2_FIELD_ANY] = "any",
147 [V4L2_FIELD_NONE] = "none",
148 [V4L2_FIELD_TOP] = "top",
149 [V4L2_FIELD_BOTTOM] = "bottom",
150 [V4L2_FIELD_INTERLACED] = "interlaced",
151 [V4L2_FIELD_SEQ_TB] = "seq-tb",
152 [V4L2_FIELD_SEQ_BT] = "seq-bt",
153 [V4L2_FIELD_ALTERNATE] = "alternate",
154 [V4L2_FIELD_INTERLACED_TB] = "interlaced-tb",
155 [V4L2_FIELD_INTERLACED_BT] = "interlaced-bt",
156};
157EXPORT_SYMBOL(v4l2_field_names);
158
159const char *v4l2_type_names[] = {
160 [V4L2_BUF_TYPE_VIDEO_CAPTURE] = "vid-cap",
161 [V4L2_BUF_TYPE_VIDEO_OVERLAY] = "vid-overlay",
162 [V4L2_BUF_TYPE_VIDEO_OUTPUT] = "vid-out",
163 [V4L2_BUF_TYPE_VBI_CAPTURE] = "vbi-cap",
164 [V4L2_BUF_TYPE_VBI_OUTPUT] = "vbi-out",
165 [V4L2_BUF_TYPE_SLICED_VBI_CAPTURE] = "sliced-vbi-cap",
166 [V4L2_BUF_TYPE_SLICED_VBI_OUTPUT] = "sliced-vbi-out",
167 [V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY] = "vid-out-overlay",
168};
169EXPORT_SYMBOL(v4l2_type_names);
170
171static const char *v4l2_memory_names[] = {
172 [V4L2_MEMORY_MMAP] = "mmap",
173 [V4L2_MEMORY_USERPTR] = "userptr",
174 [V4L2_MEMORY_OVERLAY] = "overlay",
175};
176
177#define prt_names(a, arr) ((((a) >= 0) && ((a) < ARRAY_SIZE(arr))) ? \
178 arr[a] : "unknown")
179
180/* ------------------------------------------------------------------ */
181/* debug help functions */
182
183#ifdef CONFIG_VIDEO_V4L1_COMPAT
184static const char *v4l1_ioctls[] = {
185 [_IOC_NR(VIDIOCGCAP)] = "VIDIOCGCAP",
186 [_IOC_NR(VIDIOCGCHAN)] = "VIDIOCGCHAN",
187 [_IOC_NR(VIDIOCSCHAN)] = "VIDIOCSCHAN",
188 [_IOC_NR(VIDIOCGTUNER)] = "VIDIOCGTUNER",
189 [_IOC_NR(VIDIOCSTUNER)] = "VIDIOCSTUNER",
190 [_IOC_NR(VIDIOCGPICT)] = "VIDIOCGPICT",
191 [_IOC_NR(VIDIOCSPICT)] = "VIDIOCSPICT",
192 [_IOC_NR(VIDIOCCAPTURE)] = "VIDIOCCAPTURE",
193 [_IOC_NR(VIDIOCGWIN)] = "VIDIOCGWIN",
194 [_IOC_NR(VIDIOCSWIN)] = "VIDIOCSWIN",
195 [_IOC_NR(VIDIOCGFBUF)] = "VIDIOCGFBUF",
196 [_IOC_NR(VIDIOCSFBUF)] = "VIDIOCSFBUF",
197 [_IOC_NR(VIDIOCKEY)] = "VIDIOCKEY",
198 [_IOC_NR(VIDIOCGFREQ)] = "VIDIOCGFREQ",
199 [_IOC_NR(VIDIOCSFREQ)] = "VIDIOCSFREQ",
200 [_IOC_NR(VIDIOCGAUDIO)] = "VIDIOCGAUDIO",
201 [_IOC_NR(VIDIOCSAUDIO)] = "VIDIOCSAUDIO",
202 [_IOC_NR(VIDIOCSYNC)] = "VIDIOCSYNC",
203 [_IOC_NR(VIDIOCMCAPTURE)] = "VIDIOCMCAPTURE",
204 [_IOC_NR(VIDIOCGMBUF)] = "VIDIOCGMBUF",
205 [_IOC_NR(VIDIOCGUNIT)] = "VIDIOCGUNIT",
206 [_IOC_NR(VIDIOCGCAPTURE)] = "VIDIOCGCAPTURE",
207 [_IOC_NR(VIDIOCSCAPTURE)] = "VIDIOCSCAPTURE",
208 [_IOC_NR(VIDIOCSPLAYMODE)] = "VIDIOCSPLAYMODE",
209 [_IOC_NR(VIDIOCSWRITEMODE)] = "VIDIOCSWRITEMODE",
210 [_IOC_NR(VIDIOCGPLAYINFO)] = "VIDIOCGPLAYINFO",
211 [_IOC_NR(VIDIOCSMICROCODE)] = "VIDIOCSMICROCODE",
212 [_IOC_NR(VIDIOCGVBIFMT)] = "VIDIOCGVBIFMT",
213 [_IOC_NR(VIDIOCSVBIFMT)] = "VIDIOCSVBIFMT"
214};
215#define V4L1_IOCTLS ARRAY_SIZE(v4l1_ioctls)
216#endif
217
218static const char *v4l2_ioctls[] = {
219 [_IOC_NR(VIDIOC_QUERYCAP)] = "VIDIOC_QUERYCAP",
220 [_IOC_NR(VIDIOC_RESERVED)] = "VIDIOC_RESERVED",
221 [_IOC_NR(VIDIOC_ENUM_FMT)] = "VIDIOC_ENUM_FMT",
222 [_IOC_NR(VIDIOC_G_FMT)] = "VIDIOC_G_FMT",
223 [_IOC_NR(VIDIOC_S_FMT)] = "VIDIOC_S_FMT",
224 [_IOC_NR(VIDIOC_REQBUFS)] = "VIDIOC_REQBUFS",
225 [_IOC_NR(VIDIOC_QUERYBUF)] = "VIDIOC_QUERYBUF",
226 [_IOC_NR(VIDIOC_G_FBUF)] = "VIDIOC_G_FBUF",
227 [_IOC_NR(VIDIOC_S_FBUF)] = "VIDIOC_S_FBUF",
228 [_IOC_NR(VIDIOC_OVERLAY)] = "VIDIOC_OVERLAY",
229 [_IOC_NR(VIDIOC_QBUF)] = "VIDIOC_QBUF",
230 [_IOC_NR(VIDIOC_DQBUF)] = "VIDIOC_DQBUF",
231 [_IOC_NR(VIDIOC_STREAMON)] = "VIDIOC_STREAMON",
232 [_IOC_NR(VIDIOC_STREAMOFF)] = "VIDIOC_STREAMOFF",
233 [_IOC_NR(VIDIOC_G_PARM)] = "VIDIOC_G_PARM",
234 [_IOC_NR(VIDIOC_S_PARM)] = "VIDIOC_S_PARM",
235 [_IOC_NR(VIDIOC_G_STD)] = "VIDIOC_G_STD",
236 [_IOC_NR(VIDIOC_S_STD)] = "VIDIOC_S_STD",
237 [_IOC_NR(VIDIOC_ENUMSTD)] = "VIDIOC_ENUMSTD",
238 [_IOC_NR(VIDIOC_ENUMINPUT)] = "VIDIOC_ENUMINPUT",
239 [_IOC_NR(VIDIOC_G_CTRL)] = "VIDIOC_G_CTRL",
240 [_IOC_NR(VIDIOC_S_CTRL)] = "VIDIOC_S_CTRL",
241 [_IOC_NR(VIDIOC_G_TUNER)] = "VIDIOC_G_TUNER",
242 [_IOC_NR(VIDIOC_S_TUNER)] = "VIDIOC_S_TUNER",
243 [_IOC_NR(VIDIOC_G_AUDIO)] = "VIDIOC_G_AUDIO",
244 [_IOC_NR(VIDIOC_S_AUDIO)] = "VIDIOC_S_AUDIO",
245 [_IOC_NR(VIDIOC_QUERYCTRL)] = "VIDIOC_QUERYCTRL",
246 [_IOC_NR(VIDIOC_QUERYMENU)] = "VIDIOC_QUERYMENU",
247 [_IOC_NR(VIDIOC_G_INPUT)] = "VIDIOC_G_INPUT",
248 [_IOC_NR(VIDIOC_S_INPUT)] = "VIDIOC_S_INPUT",
249 [_IOC_NR(VIDIOC_G_OUTPUT)] = "VIDIOC_G_OUTPUT",
250 [_IOC_NR(VIDIOC_S_OUTPUT)] = "VIDIOC_S_OUTPUT",
251 [_IOC_NR(VIDIOC_ENUMOUTPUT)] = "VIDIOC_ENUMOUTPUT",
252 [_IOC_NR(VIDIOC_G_AUDOUT)] = "VIDIOC_G_AUDOUT",
253 [_IOC_NR(VIDIOC_S_AUDOUT)] = "VIDIOC_S_AUDOUT",
254 [_IOC_NR(VIDIOC_G_MODULATOR)] = "VIDIOC_G_MODULATOR",
255 [_IOC_NR(VIDIOC_S_MODULATOR)] = "VIDIOC_S_MODULATOR",
256 [_IOC_NR(VIDIOC_G_FREQUENCY)] = "VIDIOC_G_FREQUENCY",
257 [_IOC_NR(VIDIOC_S_FREQUENCY)] = "VIDIOC_S_FREQUENCY",
258 [_IOC_NR(VIDIOC_CROPCAP)] = "VIDIOC_CROPCAP",
259 [_IOC_NR(VIDIOC_G_CROP)] = "VIDIOC_G_CROP",
260 [_IOC_NR(VIDIOC_S_CROP)] = "VIDIOC_S_CROP",
261 [_IOC_NR(VIDIOC_G_JPEGCOMP)] = "VIDIOC_G_JPEGCOMP",
262 [_IOC_NR(VIDIOC_S_JPEGCOMP)] = "VIDIOC_S_JPEGCOMP",
263 [_IOC_NR(VIDIOC_QUERYSTD)] = "VIDIOC_QUERYSTD",
264 [_IOC_NR(VIDIOC_TRY_FMT)] = "VIDIOC_TRY_FMT",
265 [_IOC_NR(VIDIOC_ENUMAUDIO)] = "VIDIOC_ENUMAUDIO",
266 [_IOC_NR(VIDIOC_ENUMAUDOUT)] = "VIDIOC_ENUMAUDOUT",
267 [_IOC_NR(VIDIOC_G_PRIORITY)] = "VIDIOC_G_PRIORITY",
268 [_IOC_NR(VIDIOC_S_PRIORITY)] = "VIDIOC_S_PRIORITY",
269 [_IOC_NR(VIDIOC_G_SLICED_VBI_CAP)] = "VIDIOC_G_SLICED_VBI_CAP",
270 [_IOC_NR(VIDIOC_LOG_STATUS)] = "VIDIOC_LOG_STATUS",
271 [_IOC_NR(VIDIOC_G_EXT_CTRLS)] = "VIDIOC_G_EXT_CTRLS",
272 [_IOC_NR(VIDIOC_S_EXT_CTRLS)] = "VIDIOC_S_EXT_CTRLS",
273 [_IOC_NR(VIDIOC_TRY_EXT_CTRLS)] = "VIDIOC_TRY_EXT_CTRLS",
274#if 1
275 [_IOC_NR(VIDIOC_ENUM_FRAMESIZES)] = "VIDIOC_ENUM_FRAMESIZES",
276 [_IOC_NR(VIDIOC_ENUM_FRAMEINTERVALS)] = "VIDIOC_ENUM_FRAMEINTERVALS",
277 [_IOC_NR(VIDIOC_G_ENC_INDEX)] = "VIDIOC_G_ENC_INDEX",
278 [_IOC_NR(VIDIOC_ENCODER_CMD)] = "VIDIOC_ENCODER_CMD",
279 [_IOC_NR(VIDIOC_TRY_ENCODER_CMD)] = "VIDIOC_TRY_ENCODER_CMD",
280
281 [_IOC_NR(VIDIOC_DBG_S_REGISTER)] = "VIDIOC_DBG_S_REGISTER",
282 [_IOC_NR(VIDIOC_DBG_G_REGISTER)] = "VIDIOC_DBG_G_REGISTER",
283
284 [_IOC_NR(VIDIOC_G_CHIP_IDENT)] = "VIDIOC_G_CHIP_IDENT",
285 [_IOC_NR(VIDIOC_S_HW_FREQ_SEEK)] = "VIDIOC_S_HW_FREQ_SEEK",
286#endif
287};
288#define V4L2_IOCTLS ARRAY_SIZE(v4l2_ioctls)
289
290static const char *v4l2_int_ioctls[] = {
291#ifdef CONFIG_VIDEO_V4L1_COMPAT
292 [_IOC_NR(DECODER_GET_CAPABILITIES)] = "DECODER_GET_CAPABILITIES",
293 [_IOC_NR(DECODER_GET_STATUS)] = "DECODER_GET_STATUS",
294 [_IOC_NR(DECODER_SET_NORM)] = "DECODER_SET_NORM",
295 [_IOC_NR(DECODER_SET_INPUT)] = "DECODER_SET_INPUT",
296 [_IOC_NR(DECODER_SET_OUTPUT)] = "DECODER_SET_OUTPUT",
297 [_IOC_NR(DECODER_ENABLE_OUTPUT)] = "DECODER_ENABLE_OUTPUT",
298 [_IOC_NR(DECODER_SET_PICTURE)] = "DECODER_SET_PICTURE",
299 [_IOC_NR(DECODER_SET_GPIO)] = "DECODER_SET_GPIO",
300 [_IOC_NR(DECODER_INIT)] = "DECODER_INIT",
301 [_IOC_NR(DECODER_SET_VBI_BYPASS)] = "DECODER_SET_VBI_BYPASS",
302 [_IOC_NR(DECODER_DUMP)] = "DECODER_DUMP",
303#endif
304 [_IOC_NR(AUDC_SET_RADIO)] = "AUDC_SET_RADIO",
305
306 [_IOC_NR(TUNER_SET_TYPE_ADDR)] = "TUNER_SET_TYPE_ADDR",
307 [_IOC_NR(TUNER_SET_STANDBY)] = "TUNER_SET_STANDBY",
308 [_IOC_NR(TUNER_SET_CONFIG)] = "TUNER_SET_CONFIG",
309
310 [_IOC_NR(VIDIOC_INT_S_TUNER_MODE)] = "VIDIOC_INT_S_TUNER_MODE",
311 [_IOC_NR(VIDIOC_INT_RESET)] = "VIDIOC_INT_RESET",
312 [_IOC_NR(VIDIOC_INT_AUDIO_CLOCK_FREQ)] = "VIDIOC_INT_AUDIO_CLOCK_FREQ",
313 [_IOC_NR(VIDIOC_INT_DECODE_VBI_LINE)] = "VIDIOC_INT_DECODE_VBI_LINE",
314 [_IOC_NR(VIDIOC_INT_S_VBI_DATA)] = "VIDIOC_INT_S_VBI_DATA",
315 [_IOC_NR(VIDIOC_INT_G_VBI_DATA)] = "VIDIOC_INT_G_VBI_DATA",
316 [_IOC_NR(VIDIOC_INT_I2S_CLOCK_FREQ)] = "VIDIOC_INT_I2S_CLOCK_FREQ",
317 [_IOC_NR(VIDIOC_INT_S_STANDBY)] = "VIDIOC_INT_S_STANDBY",
318 [_IOC_NR(VIDIOC_INT_S_AUDIO_ROUTING)] = "VIDIOC_INT_S_AUDIO_ROUTING",
319 [_IOC_NR(VIDIOC_INT_G_AUDIO_ROUTING)] = "VIDIOC_INT_G_AUDIO_ROUTING",
320 [_IOC_NR(VIDIOC_INT_S_VIDEO_ROUTING)] = "VIDIOC_INT_S_VIDEO_ROUTING",
321 [_IOC_NR(VIDIOC_INT_G_VIDEO_ROUTING)] = "VIDIOC_INT_G_VIDEO_ROUTING",
322 [_IOC_NR(VIDIOC_INT_S_CRYSTAL_FREQ)] = "VIDIOC_INT_S_CRYSTAL_FREQ",
323 [_IOC_NR(VIDIOC_INT_INIT)] = "VIDIOC_INT_INIT",
324 [_IOC_NR(VIDIOC_INT_G_STD_OUTPUT)] = "VIDIOC_INT_G_STD_OUTPUT",
325 [_IOC_NR(VIDIOC_INT_S_STD_OUTPUT)] = "VIDIOC_INT_S_STD_OUTPUT",
326};
327#define V4L2_INT_IOCTLS ARRAY_SIZE(v4l2_int_ioctls)
328
329/* Common ioctl debug function. This function can be used by
330 external ioctl messages as well as internal V4L ioctl */
331void v4l_printk_ioctl(unsigned int cmd)
332{
333 char *dir, *type;
334
335 switch (_IOC_TYPE(cmd)) {
336 case 'd':
337 if (_IOC_NR(cmd) >= V4L2_INT_IOCTLS) {
338 type = "v4l2_int";
339 break;
340 }
341 printk("%s", v4l2_int_ioctls[_IOC_NR(cmd)]);
342 return;
343#ifdef CONFIG_VIDEO_V4L1_COMPAT
344 case 'v':
345 if (_IOC_NR(cmd) >= V4L1_IOCTLS) {
346 type = "v4l1";
347 break;
348 }
349 printk("%s", v4l1_ioctls[_IOC_NR(cmd)]);
350 return;
351#endif
352 case 'V':
353 if (_IOC_NR(cmd) >= V4L2_IOCTLS) {
354 type = "v4l2";
355 break;
356 }
357 printk("%s", v4l2_ioctls[_IOC_NR(cmd)]);
358 return;
359 default:
360 type = "unknown";
361 }
362
363 switch (_IOC_DIR(cmd)) {
364 case _IOC_NONE: dir = "--"; break;
365 case _IOC_READ: dir = "r-"; break;
366 case _IOC_WRITE: dir = "-w"; break;
367 case _IOC_READ | _IOC_WRITE: dir = "rw"; break;
368 default: dir = "*ERR*"; break;
369 }
370 printk("%s ioctl '%c', dir=%s, #%d (0x%08x)",
371 type, _IOC_TYPE(cmd), dir, _IOC_NR(cmd), cmd);
372}
373EXPORT_SYMBOL(v4l_printk_ioctl);
374
375/*
376 * sysfs stuff
377 */
378
379static ssize_t show_index(struct device *cd,
380 struct device_attribute *attr, char *buf)
381{
382 struct video_device *vfd = container_of(cd, struct video_device,
383 class_dev);
384 return sprintf(buf, "%i\n", vfd->index);
385}
386
387static ssize_t show_name(struct device *cd,
388 struct device_attribute *attr, char *buf)
389{
390 struct video_device *vfd = container_of(cd, struct video_device,
391 class_dev);
392 return sprintf(buf, "%.*s\n", (int)sizeof(vfd->name), vfd->name);
393}
394
395static struct device_attribute video_device_attrs[] = {
396 __ATTR(name, S_IRUGO, show_name, NULL),
397 __ATTR(index, S_IRUGO, show_index, NULL),
398 __ATTR_NULL
399};
400
401struct video_device *video_device_alloc(void)
402{
403 struct video_device *vfd;
404
405 vfd = kzalloc(sizeof(*vfd),GFP_KERNEL);
406 return vfd;
407}
408EXPORT_SYMBOL(video_device_alloc);
409
410void video_device_release(struct video_device *vfd)
411{
412 kfree(vfd);
413}
414EXPORT_SYMBOL(video_device_release);
415
416static void video_release(struct device *cd)
417{
418 struct video_device *vfd = container_of(cd, struct video_device,
419 class_dev);
420
421#if 1
422 /* needed until all drivers are fixed */
423 if (!vfd->release)
424 return;
425#endif
426 vfd->release(vfd);
427}
428
429static struct class video_class = {
430 .name = VIDEO_NAME,
431 .dev_attrs = video_device_attrs,
432 .dev_release = video_release,
433};
434
435/*
436 * Active devices
437 */
438
439static struct video_device *video_device[VIDEO_NUM_DEVICES];
440static DEFINE_MUTEX(videodev_lock);
441
442struct video_device* video_devdata(struct file *file)
443{
444 return video_device[iminor(file->f_path.dentry->d_inode)];
445}
446EXPORT_SYMBOL(video_devdata);
447
448/*
449 * Open a video device - FIXME: Obsoleted
450 */
451static int video_open(struct inode *inode, struct file *file)
452{
453 unsigned int minor = iminor(inode);
454 int err = 0;
455 struct video_device *vfl;
456 const struct file_operations *old_fops;
457
458 if(minor>=VIDEO_NUM_DEVICES)
459 return -ENODEV;
460 lock_kernel();
461 mutex_lock(&videodev_lock);
462 vfl=video_device[minor];
463 if(vfl==NULL) {
464 mutex_unlock(&videodev_lock);
465 request_module("char-major-%d-%d", VIDEO_MAJOR, minor);
466 mutex_lock(&videodev_lock);
467 vfl=video_device[minor];
468 if (vfl==NULL) {
469 mutex_unlock(&videodev_lock);
470 unlock_kernel();
471 return -ENODEV;
472 }
473 }
474 old_fops = file->f_op;
475 file->f_op = fops_get(vfl->fops);
476 if(file->f_op->open)
477 err = file->f_op->open(inode,file);
478 if (err) {
479 fops_put(file->f_op);
480 file->f_op = fops_get(old_fops);
481 }
482 fops_put(old_fops);
483 mutex_unlock(&videodev_lock);
484 unlock_kernel();
485 return err;
486}
487
488/*
489 * helper function -- handles userspace copying for ioctl arguments
490 */
491
492#ifdef __OLD_VIDIOC_
493static unsigned int
494video_fix_command(unsigned int cmd)
495{
496 switch (cmd) {
497 case VIDIOC_OVERLAY_OLD:
498 cmd = VIDIOC_OVERLAY;
499 break;
500 case VIDIOC_S_PARM_OLD:
501 cmd = VIDIOC_S_PARM;
502 break;
503 case VIDIOC_S_CTRL_OLD:
504 cmd = VIDIOC_S_CTRL;
505 break;
506 case VIDIOC_G_AUDIO_OLD:
507 cmd = VIDIOC_G_AUDIO;
508 break;
509 case VIDIOC_G_AUDOUT_OLD:
510 cmd = VIDIOC_G_AUDOUT;
511 break;
512 case VIDIOC_CROPCAP_OLD:
513 cmd = VIDIOC_CROPCAP;
514 break;
515 }
516 return cmd;
517}
518#endif
519
520/*
521 * Obsolete usercopy function - Should be removed soon
522 */
523int
524video_usercopy(struct inode *inode, struct file *file,
525 unsigned int cmd, unsigned long arg,
526 int (*func)(struct inode *inode, struct file *file,
527 unsigned int cmd, void *arg))
528{
529 char sbuf[128];
530 void *mbuf = NULL;
531 void *parg = NULL;
532 int err = -EINVAL;
533 int is_ext_ctrl;
534 size_t ctrls_size = 0;
535 void __user *user_ptr = NULL;
536
537#ifdef __OLD_VIDIOC_
538 cmd = video_fix_command(cmd);
539#endif
540 is_ext_ctrl = (cmd == VIDIOC_S_EXT_CTRLS || cmd == VIDIOC_G_EXT_CTRLS ||
541 cmd == VIDIOC_TRY_EXT_CTRLS);
542
543 /* Copy arguments into temp kernel buffer */
544 switch (_IOC_DIR(cmd)) {
545 case _IOC_NONE:
546 parg = NULL;
547 break;
548 case _IOC_READ:
549 case _IOC_WRITE:
550 case (_IOC_WRITE | _IOC_READ):
551 if (_IOC_SIZE(cmd) <= sizeof(sbuf)) {
552 parg = sbuf;
553 } else {
554 /* too big to allocate from stack */
555 mbuf = kmalloc(_IOC_SIZE(cmd),GFP_KERNEL);
556 if (NULL == mbuf)
557 return -ENOMEM;
558 parg = mbuf;
559 }
560
561 err = -EFAULT;
562 if (_IOC_DIR(cmd) & _IOC_WRITE)
563 if (copy_from_user(parg, (void __user *)arg, _IOC_SIZE(cmd)))
564 goto out;
565 break;
566 }
567 if (is_ext_ctrl) {
568 struct v4l2_ext_controls *p = parg;
569
570 /* In case of an error, tell the caller that it wasn't
571 a specific control that caused it. */
572 p->error_idx = p->count;
573 user_ptr = (void __user *)p->controls;
574 if (p->count) {
575 ctrls_size = sizeof(struct v4l2_ext_control) * p->count;
576 /* Note: v4l2_ext_controls fits in sbuf[] so mbuf is still NULL. */
577 mbuf = kmalloc(ctrls_size, GFP_KERNEL);
578 err = -ENOMEM;
579 if (NULL == mbuf)
580 goto out_ext_ctrl;
581 err = -EFAULT;
582 if (copy_from_user(mbuf, user_ptr, ctrls_size))
583 goto out_ext_ctrl;
584 p->controls = mbuf;
585 }
586 }
587
588 /* call driver */
589 err = func(inode, file, cmd, parg);
590 if (err == -ENOIOCTLCMD)
591 err = -EINVAL;
592 if (is_ext_ctrl) {
593 struct v4l2_ext_controls *p = parg;
594
595 p->controls = (void *)user_ptr;
596 if (p->count && err == 0 && copy_to_user(user_ptr, mbuf, ctrls_size))
597 err = -EFAULT;
598 goto out_ext_ctrl;
599 }
600 if (err < 0)
601 goto out;
602
603out_ext_ctrl:
604 /* Copy results into user buffer */
605 switch (_IOC_DIR(cmd))
606 {
607 case _IOC_READ:
608 case (_IOC_WRITE | _IOC_READ):
609 if (copy_to_user((void __user *)arg, parg, _IOC_SIZE(cmd)))
610 err = -EFAULT;
611 break;
612 }
613
614out:
615 kfree(mbuf);
616 return err;
617}
618EXPORT_SYMBOL(video_usercopy);
619
620/*
621 * open/release helper functions -- handle exclusive opens
622 * Should be removed soon
623 */
624int video_exclusive_open(struct inode *inode, struct file *file)
625{
626 struct video_device *vfl = video_devdata(file);
627 int retval = 0;
628
629 mutex_lock(&vfl->lock);
630 if (vfl->users) {
631 retval = -EBUSY;
632 } else {
633 vfl->users++;
634 }
635 mutex_unlock(&vfl->lock);
636 return retval;
637}
638EXPORT_SYMBOL(video_exclusive_open);
639
640int video_exclusive_release(struct inode *inode, struct file *file)
641{
642 struct video_device *vfl = video_devdata(file);
643
644 vfl->users--;
645 return 0;
646}
647EXPORT_SYMBOL(video_exclusive_release);
648
649static void dbgbuf(unsigned int cmd, struct video_device *vfd,
650 struct v4l2_buffer *p)
651{
652 struct v4l2_timecode *tc=&p->timecode;
653
654 dbgarg (cmd, "%02ld:%02d:%02d.%08ld index=%d, type=%s, "
655 "bytesused=%d, flags=0x%08d, "
656 "field=%0d, sequence=%d, memory=%s, offset/userptr=0x%08lx, length=%d\n",
657 (p->timestamp.tv_sec/3600),
658 (int)(p->timestamp.tv_sec/60)%60,
659 (int)(p->timestamp.tv_sec%60),
660 p->timestamp.tv_usec,
661 p->index,
662 prt_names(p->type, v4l2_type_names),
663 p->bytesused, p->flags,
664 p->field, p->sequence,
665 prt_names(p->memory, v4l2_memory_names),
666 p->m.userptr, p->length);
667 dbgarg2("timecode=%02d:%02d:%02d type=%d, "
668 "flags=0x%08d, frames=%d, userbits=0x%08x\n",
669 tc->hours,tc->minutes,tc->seconds,
670 tc->type, tc->flags, tc->frames, *(__u32 *) tc->userbits);
671}
672
673static inline void dbgrect(struct video_device *vfd, char *s,
674 struct v4l2_rect *r)
675{
676 dbgarg2("%sRect start at %dx%d, size=%dx%d\n", s, r->left, r->top,
677 r->width, r->height);
678};
679
680static inline void v4l_print_pix_fmt (struct video_device *vfd,
681 struct v4l2_pix_format *fmt)
682{
683 dbgarg2 ("width=%d, height=%d, format=%c%c%c%c, field=%s, "
684 "bytesperline=%d sizeimage=%d, colorspace=%d\n",
685 fmt->width,fmt->height,
686 (fmt->pixelformat & 0xff),
687 (fmt->pixelformat >> 8) & 0xff,
688 (fmt->pixelformat >> 16) & 0xff,
689 (fmt->pixelformat >> 24) & 0xff,
690 prt_names(fmt->field, v4l2_field_names),
691 fmt->bytesperline, fmt->sizeimage, fmt->colorspace);
692};
693
694static inline void v4l_print_ext_ctrls(unsigned int cmd,
695 struct video_device *vfd, struct v4l2_ext_controls *c, int show_vals)
696{
697 __u32 i;
698
699 if (!(vfd->debug & V4L2_DEBUG_IOCTL_ARG))
700 return;
701 dbgarg(cmd, "");
702 printk(KERN_CONT "class=0x%x", c->ctrl_class);
703 for (i = 0; i < c->count; i++) {
704 if (show_vals)
705 printk(KERN_CONT " id/val=0x%x/0x%x",
706 c->controls[i].id, c->controls[i].value);
707 else
708 printk(KERN_CONT " id=0x%x", c->controls[i].id);
709 }
710 printk(KERN_CONT "\n");
711};
712
713static inline int check_ext_ctrls(struct v4l2_ext_controls *c, int allow_priv)
714{
715 __u32 i;
716
717 /* zero the reserved fields */
718 c->reserved[0] = c->reserved[1] = 0;
719 for (i = 0; i < c->count; i++) {
720 c->controls[i].reserved2[0] = 0;
721 c->controls[i].reserved2[1] = 0;
722 }
723 /* V4L2_CID_PRIVATE_BASE cannot be used as control class
724 when using extended controls.
725 Only when passed in through VIDIOC_G_CTRL and VIDIOC_S_CTRL
726 is it allowed for backwards compatibility.
727 */
728 if (!allow_priv && c->ctrl_class == V4L2_CID_PRIVATE_BASE)
729 return 0;
730 /* Check that all controls are from the same control class. */
731 for (i = 0; i < c->count; i++) {
732 if (V4L2_CTRL_ID2CLASS(c->controls[i].id) != c->ctrl_class) {
733 c->error_idx = i;
734 return 0;
735 }
736 }
737 return 1;
738}
739
740static int check_fmt (struct video_device *vfd, enum v4l2_buf_type type)
741{
742 switch (type) {
743 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
744 if (vfd->vidioc_try_fmt_vid_cap)
745 return (0);
746 break;
747 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
748 if (vfd->vidioc_try_fmt_vid_overlay)
749 return (0);
750 break;
751 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
752 if (vfd->vidioc_try_fmt_vid_out)
753 return (0);
754 break;
755 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
756 if (vfd->vidioc_try_fmt_vid_out_overlay)
757 return (0);
758 break;
759 case V4L2_BUF_TYPE_VBI_CAPTURE:
760 if (vfd->vidioc_try_fmt_vbi_cap)
761 return (0);
762 break;
763 case V4L2_BUF_TYPE_VBI_OUTPUT:
764 if (vfd->vidioc_try_fmt_vbi_out)
765 return (0);
766 break;
767 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
768 if (vfd->vidioc_try_fmt_sliced_vbi_cap)
769 return (0);
770 break;
771 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
772 if (vfd->vidioc_try_fmt_sliced_vbi_out)
773 return (0);
774 break;
775 case V4L2_BUF_TYPE_PRIVATE:
776 if (vfd->vidioc_try_fmt_type_private)
777 return (0);
778 break;
779 }
780 return (-EINVAL);
781}
782
783static int __video_do_ioctl(struct inode *inode, struct file *file,
784 unsigned int cmd, void *arg)
785{
786 struct video_device *vfd = video_devdata(file);
787 void *fh = file->private_data;
788 int ret = -EINVAL;
789
790 if ( (vfd->debug & V4L2_DEBUG_IOCTL) &&
791 !(vfd->debug & V4L2_DEBUG_IOCTL_ARG)) {
792 v4l_print_ioctl(vfd->name, cmd);
793 printk("\n");
794 }
795
796#ifdef CONFIG_VIDEO_V4L1_COMPAT
797 /***********************************************************
798 Handles calls to the obsoleted V4L1 API
799 Due to the nature of VIDIOCGMBUF, each driver that supports
800 V4L1 should implement its own handler for this ioctl.
801 ***********************************************************/
802
803 /* --- streaming capture ------------------------------------- */
804 if (cmd == VIDIOCGMBUF) {
805 struct video_mbuf *p=arg;
806
807 memset(p, 0, sizeof(*p));
808
809 if (!vfd->vidiocgmbuf)
810 return ret;
811 ret=vfd->vidiocgmbuf(file, fh, p);
812 if (!ret)
813 dbgarg (cmd, "size=%d, frames=%d, offsets=0x%08lx\n",
814 p->size, p->frames,
815 (unsigned long)p->offsets);
816 return ret;
817 }
818
819 /********************************************************
820 All other V4L1 calls are handled by v4l1_compat module.
821 Those calls will be translated into V4L2 calls, and
822 __video_do_ioctl will be called again, with one or more
823 V4L2 ioctls.
824 ********************************************************/
825 if (_IOC_TYPE(cmd)=='v')
826 return v4l_compat_translate_ioctl(inode,file,cmd,arg,
827 __video_do_ioctl);
828#endif
829
830 switch(cmd) {
831 /* --- capabilities ------------------------------------------ */
832 case VIDIOC_QUERYCAP:
833 {
834 struct v4l2_capability *cap = (struct v4l2_capability*)arg;
835 memset(cap, 0, sizeof(*cap));
836
837 if (!vfd->vidioc_querycap)
838 break;
839
840 ret=vfd->vidioc_querycap(file, fh, cap);
841 if (!ret)
842 dbgarg (cmd, "driver=%s, card=%s, bus=%s, "
843 "version=0x%08x, "
844 "capabilities=0x%08x\n",
845 cap->driver,cap->card,cap->bus_info,
846 cap->version,
847 cap->capabilities);
848 break;
849 }
850
851 /* --- priority ------------------------------------------ */
852 case VIDIOC_G_PRIORITY:
853 {
854 enum v4l2_priority *p=arg;
855
856 if (!vfd->vidioc_g_priority)
857 break;
858 ret=vfd->vidioc_g_priority(file, fh, p);
859 if (!ret)
860 dbgarg(cmd, "priority is %d\n", *p);
861 break;
862 }
863 case VIDIOC_S_PRIORITY:
864 {
865 enum v4l2_priority *p=arg;
866
867 if (!vfd->vidioc_s_priority)
868 break;
869 dbgarg(cmd, "setting priority to %d\n", *p);
870 ret=vfd->vidioc_s_priority(file, fh, *p);
871 break;
872 }
873
874 /* --- capture ioctls ---------------------------------------- */
875 case VIDIOC_ENUM_FMT:
876 {
877 struct v4l2_fmtdesc *f = arg;
878 enum v4l2_buf_type type;
879 unsigned int index;
880
881 index = f->index;
882 type = f->type;
883 memset(f,0,sizeof(*f));
884 f->index = index;
885 f->type = type;
886
887 switch (type) {
888 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
889 if (vfd->vidioc_enum_fmt_vid_cap)
890 ret = vfd->vidioc_enum_fmt_vid_cap(file, fh, f);
891 break;
892 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
893 if (vfd->vidioc_enum_fmt_vid_overlay)
894 ret = vfd->vidioc_enum_fmt_vid_overlay(file,
895 fh, f);
896 break;
897#if 1
898 /* V4L2_BUF_TYPE_VBI_CAPTURE should not support VIDIOC_ENUM_FMT
899 * according to the spec. The bttv and saa7134 drivers support
900 * it though, so just warn that this is deprecated and will be
901 * removed in the near future. */
902 case V4L2_BUF_TYPE_VBI_CAPTURE:
903 if (vfd->vidioc_enum_fmt_vbi_cap) {
904 printk(KERN_WARNING "vidioc_enum_fmt_vbi_cap will be removed in 2.6.28!\n");
905 ret = vfd->vidioc_enum_fmt_vbi_cap(file, fh, f);
906 }
907 break;
908#endif
909 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
910 if (vfd->vidioc_enum_fmt_vid_out)
911 ret = vfd->vidioc_enum_fmt_vid_out(file, fh, f);
912 break;
913 case V4L2_BUF_TYPE_PRIVATE:
914 if (vfd->vidioc_enum_fmt_type_private)
915 ret = vfd->vidioc_enum_fmt_type_private(file,
916 fh, f);
917 break;
918 default:
919 break;
920 }
921 if (!ret)
922 dbgarg (cmd, "index=%d, type=%d, flags=%d, "
923 "pixelformat=%c%c%c%c, description='%s'\n",
924 f->index, f->type, f->flags,
925 (f->pixelformat & 0xff),
926 (f->pixelformat >> 8) & 0xff,
927 (f->pixelformat >> 16) & 0xff,
928 (f->pixelformat >> 24) & 0xff,
929 f->description);
930 break;
931 }
932 case VIDIOC_G_FMT:
933 {
934 struct v4l2_format *f = (struct v4l2_format *)arg;
935
936 memset(f->fmt.raw_data, 0, sizeof(f->fmt.raw_data));
937
938 /* FIXME: Should be one dump per type */
939 dbgarg(cmd, "type=%s\n", prt_names(f->type, v4l2_type_names));
940
941 switch (f->type) {
942 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
943 if (vfd->vidioc_g_fmt_vid_cap)
944 ret = vfd->vidioc_g_fmt_vid_cap(file, fh, f);
945 if (!ret)
946 v4l_print_pix_fmt(vfd, &f->fmt.pix);
947 break;
948 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
949 if (vfd->vidioc_g_fmt_vid_overlay)
950 ret = vfd->vidioc_g_fmt_vid_overlay(file,
951 fh, f);
952 break;
953 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
954 if (vfd->vidioc_g_fmt_vid_out)
955 ret = vfd->vidioc_g_fmt_vid_out(file, fh, f);
956 if (!ret)
957 v4l_print_pix_fmt(vfd, &f->fmt.pix);
958 break;
959 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
960 if (vfd->vidioc_g_fmt_vid_out_overlay)
961 ret = vfd->vidioc_g_fmt_vid_out_overlay(file,
962 fh, f);
963 break;
964 case V4L2_BUF_TYPE_VBI_CAPTURE:
965 if (vfd->vidioc_g_fmt_vbi_cap)
966 ret = vfd->vidioc_g_fmt_vbi_cap(file, fh, f);
967 break;
968 case V4L2_BUF_TYPE_VBI_OUTPUT:
969 if (vfd->vidioc_g_fmt_vbi_out)
970 ret = vfd->vidioc_g_fmt_vbi_out(file, fh, f);
971 break;
972 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
973 if (vfd->vidioc_g_fmt_sliced_vbi_cap)
974 ret = vfd->vidioc_g_fmt_sliced_vbi_cap(file,
975 fh, f);
976 break;
977 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
978 if (vfd->vidioc_g_fmt_sliced_vbi_out)
979 ret = vfd->vidioc_g_fmt_sliced_vbi_out(file,
980 fh, f);
981 break;
982 case V4L2_BUF_TYPE_PRIVATE:
983 if (vfd->vidioc_g_fmt_type_private)
984 ret = vfd->vidioc_g_fmt_type_private(file,
985 fh, f);
986 break;
987 }
988
989 break;
990 }
991 case VIDIOC_S_FMT:
992 {
993 struct v4l2_format *f = (struct v4l2_format *)arg;
994
995 /* FIXME: Should be one dump per type */
996 dbgarg(cmd, "type=%s\n", prt_names(f->type, v4l2_type_names));
997
998 switch (f->type) {
999 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
1000 v4l_print_pix_fmt(vfd, &f->fmt.pix);
1001 if (vfd->vidioc_s_fmt_vid_cap)
1002 ret = vfd->vidioc_s_fmt_vid_cap(file, fh, f);
1003 break;
1004 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
1005 if (vfd->vidioc_s_fmt_vid_overlay)
1006 ret = vfd->vidioc_s_fmt_vid_overlay(file,
1007 fh, f);
1008 break;
1009 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
1010 v4l_print_pix_fmt(vfd, &f->fmt.pix);
1011 if (vfd->vidioc_s_fmt_vid_out)
1012 ret = vfd->vidioc_s_fmt_vid_out(file, fh, f);
1013 break;
1014 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
1015 if (vfd->vidioc_s_fmt_vid_out_overlay)
1016 ret = vfd->vidioc_s_fmt_vid_out_overlay(file,
1017 fh, f);
1018 break;
1019 case V4L2_BUF_TYPE_VBI_CAPTURE:
1020 if (vfd->vidioc_s_fmt_vbi_cap)
1021 ret = vfd->vidioc_s_fmt_vbi_cap(file, fh, f);
1022 break;
1023 case V4L2_BUF_TYPE_VBI_OUTPUT:
1024 if (vfd->vidioc_s_fmt_vbi_out)
1025 ret = vfd->vidioc_s_fmt_vbi_out(file, fh, f);
1026 break;
1027 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
1028 if (vfd->vidioc_s_fmt_sliced_vbi_cap)
1029 ret = vfd->vidioc_s_fmt_sliced_vbi_cap(file,
1030 fh, f);
1031 break;
1032 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
1033 if (vfd->vidioc_s_fmt_sliced_vbi_out)
1034 ret = vfd->vidioc_s_fmt_sliced_vbi_out(file,
1035 fh, f);
1036 break;
1037 case V4L2_BUF_TYPE_PRIVATE:
1038 if (vfd->vidioc_s_fmt_type_private)
1039 ret = vfd->vidioc_s_fmt_type_private(file,
1040 fh, f);
1041 break;
1042 }
1043 break;
1044 }
1045 case VIDIOC_TRY_FMT:
1046 {
1047 struct v4l2_format *f = (struct v4l2_format *)arg;
1048
1049 /* FIXME: Should be one dump per type */
1050 dbgarg (cmd, "type=%s\n", prt_names(f->type,
1051 v4l2_type_names));
1052 switch (f->type) {
1053 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
1054 if (vfd->vidioc_try_fmt_vid_cap)
1055 ret = vfd->vidioc_try_fmt_vid_cap(file, fh, f);
1056 if (!ret)
1057 v4l_print_pix_fmt(vfd, &f->fmt.pix);
1058 break;
1059 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
1060 if (vfd->vidioc_try_fmt_vid_overlay)
1061 ret = vfd->vidioc_try_fmt_vid_overlay(file,
1062 fh, f);
1063 break;
1064 case V4L2_BUF_TYPE_VIDEO_OUTPUT:
1065 if (vfd->vidioc_try_fmt_vid_out)
1066 ret = vfd->vidioc_try_fmt_vid_out(file, fh, f);
1067 if (!ret)
1068 v4l_print_pix_fmt(vfd, &f->fmt.pix);
1069 break;
1070 case V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY:
1071 if (vfd->vidioc_try_fmt_vid_out_overlay)
1072 ret = vfd->vidioc_try_fmt_vid_out_overlay(file,
1073 fh, f);
1074 break;
1075 case V4L2_BUF_TYPE_VBI_CAPTURE:
1076 if (vfd->vidioc_try_fmt_vbi_cap)
1077 ret = vfd->vidioc_try_fmt_vbi_cap(file, fh, f);
1078 break;
1079 case V4L2_BUF_TYPE_VBI_OUTPUT:
1080 if (vfd->vidioc_try_fmt_vbi_out)
1081 ret = vfd->vidioc_try_fmt_vbi_out(file, fh, f);
1082 break;
1083 case V4L2_BUF_TYPE_SLICED_VBI_CAPTURE:
1084 if (vfd->vidioc_try_fmt_sliced_vbi_cap)
1085 ret = vfd->vidioc_try_fmt_sliced_vbi_cap(file,
1086 fh, f);
1087 break;
1088 case V4L2_BUF_TYPE_SLICED_VBI_OUTPUT:
1089 if (vfd->vidioc_try_fmt_sliced_vbi_out)
1090 ret = vfd->vidioc_try_fmt_sliced_vbi_out(file,
1091 fh, f);
1092 break;
1093 case V4L2_BUF_TYPE_PRIVATE:
1094 if (vfd->vidioc_try_fmt_type_private)
1095 ret = vfd->vidioc_try_fmt_type_private(file,
1096 fh, f);
1097 break;
1098 }
1099
1100 break;
1101 }
1102 /* FIXME: Those buf reqs could be handled here,
1103 with some changes on videobuf to allow its header to be included at
1104 videodev2.h or being merged at videodev2.
1105 */
1106 case VIDIOC_REQBUFS:
1107 {
1108 struct v4l2_requestbuffers *p=arg;
1109
1110 if (!vfd->vidioc_reqbufs)
1111 break;
1112 ret = check_fmt (vfd, p->type);
1113 if (ret)
1114 break;
1115
1116 ret=vfd->vidioc_reqbufs(file, fh, p);
1117 dbgarg (cmd, "count=%d, type=%s, memory=%s\n",
1118 p->count,
1119 prt_names(p->type, v4l2_type_names),
1120 prt_names(p->memory, v4l2_memory_names));
1121 break;
1122 }
1123 case VIDIOC_QUERYBUF:
1124 {
1125 struct v4l2_buffer *p=arg;
1126
1127 if (!vfd->vidioc_querybuf)
1128 break;
1129 ret = check_fmt (vfd, p->type);
1130 if (ret)
1131 break;
1132
1133 ret=vfd->vidioc_querybuf(file, fh, p);
1134 if (!ret)
1135 dbgbuf(cmd,vfd,p);
1136 break;
1137 }
1138 case VIDIOC_QBUF:
1139 {
1140 struct v4l2_buffer *p=arg;
1141
1142 if (!vfd->vidioc_qbuf)
1143 break;
1144 ret = check_fmt (vfd, p->type);
1145 if (ret)
1146 break;
1147
1148 ret=vfd->vidioc_qbuf(file, fh, p);
1149 if (!ret)
1150 dbgbuf(cmd,vfd,p);
1151 break;
1152 }
1153 case VIDIOC_DQBUF:
1154 {
1155 struct v4l2_buffer *p=arg;
1156 if (!vfd->vidioc_dqbuf)
1157 break;
1158 ret = check_fmt (vfd, p->type);
1159 if (ret)
1160 break;
1161
1162 ret=vfd->vidioc_dqbuf(file, fh, p);
1163 if (!ret)
1164 dbgbuf(cmd,vfd,p);
1165 break;
1166 }
1167 case VIDIOC_OVERLAY:
1168 {
1169 int *i = arg;
1170
1171 if (!vfd->vidioc_overlay)
1172 break;
1173 dbgarg (cmd, "value=%d\n",*i);
1174 ret=vfd->vidioc_overlay(file, fh, *i);
1175 break;
1176 }
1177 case VIDIOC_G_FBUF:
1178 {
1179 struct v4l2_framebuffer *p = arg;
1180
1181 if (!vfd->vidioc_g_fbuf)
1182 break;
1183 ret = vfd->vidioc_g_fbuf(file, fh, arg);
1184 if (!ret) {
1185 dbgarg(cmd, "capability=0x%x, flags=%d, base=0x%08lx\n",
1186 p->capability, p->flags,
1187 (unsigned long)p->base);
1188 v4l_print_pix_fmt(vfd, &p->fmt);
1189 }
1190 break;
1191 }
1192 case VIDIOC_S_FBUF:
1193 {
1194 struct v4l2_framebuffer *p = arg;
1195
1196 if (!vfd->vidioc_s_fbuf)
1197 break;
1198 dbgarg(cmd, "capability=0x%x, flags=%d, base=0x%08lx\n",
1199 p->capability, p->flags, (unsigned long)p->base);
1200 v4l_print_pix_fmt(vfd, &p->fmt);
1201 ret = vfd->vidioc_s_fbuf(file, fh, arg);
1202 break;
1203 }
1204 case VIDIOC_STREAMON:
1205 {
1206 enum v4l2_buf_type i = *(int *)arg;
1207 if (!vfd->vidioc_streamon)
1208 break;
1209 dbgarg(cmd, "type=%s\n", prt_names(i, v4l2_type_names));
1210 ret=vfd->vidioc_streamon(file, fh,i);
1211 break;
1212 }
1213 case VIDIOC_STREAMOFF:
1214 {
1215 enum v4l2_buf_type i = *(int *)arg;
1216
1217 if (!vfd->vidioc_streamoff)
1218 break;
1219 dbgarg(cmd, "type=%s\n", prt_names(i, v4l2_type_names));
1220 ret=vfd->vidioc_streamoff(file, fh, i);
1221 break;
1222 }
1223 /* ---------- tv norms ---------- */
1224 case VIDIOC_ENUMSTD:
1225 {
1226 struct v4l2_standard *p = arg;
1227 v4l2_std_id id = vfd->tvnorms, curr_id = 0;
1228 unsigned int index = p->index, i, j = 0;
1229 const char *descr = "";
1230
1231 /* Return norm array in a canonical way */
1232 for (i = 0; i <= index && id; i++) {
1233 /* last std value in the standards array is 0, so this
1234 while always ends there since (id & 0) == 0. */
1235 while ((id & standards[j].std) != standards[j].std)
1236 j++;
1237 curr_id = standards[j].std;
1238 descr = standards[j].descr;
1239 j++;
1240 if (curr_id == 0)
1241 break;
1242 if (curr_id != V4L2_STD_PAL &&
1243 curr_id != V4L2_STD_SECAM &&
1244 curr_id != V4L2_STD_NTSC)
1245 id &= ~curr_id;
1246 }
1247 if (i <= index)
1248 return -EINVAL;
1249
1250 v4l2_video_std_construct(p, curr_id, descr);
1251 p->index = index;
1252
1253 dbgarg(cmd, "index=%d, id=0x%Lx, name=%s, fps=%d/%d, "
1254 "framelines=%d\n", p->index,
1255 (unsigned long long)p->id, p->name,
1256 p->frameperiod.numerator,
1257 p->frameperiod.denominator,
1258 p->framelines);
1259
1260 ret = 0;
1261 break;
1262 }
1263 case VIDIOC_G_STD:
1264 {
1265 v4l2_std_id *id = arg;
1266
1267 ret = 0;
1268 /* Calls the specific handler */
1269 if (vfd->vidioc_g_std)
1270 ret = vfd->vidioc_g_std(file, fh, id);
1271 else
1272 *id = vfd->current_norm;
1273
1274 if (!ret)
1275 dbgarg(cmd, "std=0x%08Lx\n", (long long unsigned)*id);
1276 break;
1277 }
1278 case VIDIOC_S_STD:
1279 {
1280 v4l2_std_id *id = arg,norm;
1281
1282 dbgarg(cmd, "std=%08Lx\n", (long long unsigned)*id);
1283
1284 norm = (*id) & vfd->tvnorms;
1285 if ( vfd->tvnorms && !norm) /* Check if std is supported */
1286 break;
1287
1288 /* Calls the specific handler */
1289 if (vfd->vidioc_s_std)
1290 ret=vfd->vidioc_s_std(file, fh, &norm);
1291 else
1292 ret=-EINVAL;
1293
1294 /* Updates standard information */
1295 if (ret>=0)
1296 vfd->current_norm=norm;
1297
1298 break;
1299 }
1300 case VIDIOC_QUERYSTD:
1301 {
1302 v4l2_std_id *p=arg;
1303
1304 if (!vfd->vidioc_querystd)
1305 break;
1306 ret=vfd->vidioc_querystd(file, fh, arg);
1307 if (!ret)
1308 dbgarg (cmd, "detected std=%08Lx\n",
1309 (unsigned long long)*p);
1310 break;
1311 }
1312 /* ------ input switching ---------- */
1313 /* FIXME: Inputs can be handled inside videodev2 */
1314 case VIDIOC_ENUMINPUT:
1315 {
1316 struct v4l2_input *p=arg;
1317 int i=p->index;
1318
1319 if (!vfd->vidioc_enum_input)
1320 break;
1321 memset(p, 0, sizeof(*p));
1322 p->index=i;
1323
1324 ret=vfd->vidioc_enum_input(file, fh, p);
1325 if (!ret)
1326 dbgarg (cmd, "index=%d, name=%s, type=%d, "
1327 "audioset=%d, "
1328 "tuner=%d, std=%08Lx, status=%d\n",
1329 p->index,p->name,p->type,p->audioset,
1330 p->tuner,
1331 (unsigned long long)p->std,
1332 p->status);
1333 break;
1334 }
1335 case VIDIOC_G_INPUT:
1336 {
1337 unsigned int *i = arg;
1338
1339 if (!vfd->vidioc_g_input)
1340 break;
1341 ret=vfd->vidioc_g_input(file, fh, i);
1342 if (!ret)
1343 dbgarg (cmd, "value=%d\n",*i);
1344 break;
1345 }
1346 case VIDIOC_S_INPUT:
1347 {
1348 unsigned int *i = arg;
1349
1350 if (!vfd->vidioc_s_input)
1351 break;
1352 dbgarg (cmd, "value=%d\n",*i);
1353 ret=vfd->vidioc_s_input(file, fh, *i);
1354 break;
1355 }
1356
1357 /* ------ output switching ---------- */
1358 case VIDIOC_ENUMOUTPUT:
1359 {
1360 struct v4l2_output *p = arg;
1361 int i = p->index;
1362
1363 if (!vfd->vidioc_enum_output)
1364 break;
1365 memset(p, 0, sizeof(*p));
1366 p->index = i;
1367
1368 ret = vfd->vidioc_enum_output(file, fh, p);
1369 if (!ret)
1370 dbgarg(cmd, "index=%d, name=%s, type=%d, "
1371 "audioset=0x%x, "
1372 "modulator=%d, std=0x%08Lx\n",
1373 p->index, p->name, p->type, p->audioset,
1374 p->modulator, (unsigned long long)p->std);
1375 break;
1376 }
1377 case VIDIOC_G_OUTPUT:
1378 {
1379 unsigned int *i = arg;
1380
1381 if (!vfd->vidioc_g_output)
1382 break;
1383 ret=vfd->vidioc_g_output(file, fh, i);
1384 if (!ret)
1385 dbgarg (cmd, "value=%d\n",*i);
1386 break;
1387 }
1388 case VIDIOC_S_OUTPUT:
1389 {
1390 unsigned int *i = arg;
1391
1392 if (!vfd->vidioc_s_output)
1393 break;
1394 dbgarg (cmd, "value=%d\n",*i);
1395 ret=vfd->vidioc_s_output(file, fh, *i);
1396 break;
1397 }
1398
1399 /* --- controls ---------------------------------------------- */
1400 case VIDIOC_QUERYCTRL:
1401 {
1402 struct v4l2_queryctrl *p = arg;
1403
1404 if (!vfd->vidioc_queryctrl)
1405 break;
1406 ret = vfd->vidioc_queryctrl(file, fh, p);
1407 if (!ret)
1408 dbgarg(cmd, "id=0x%x, type=%d, name=%s, min/max=%d/%d, "
1409 "step=%d, default=%d, flags=0x%08x\n",
1410 p->id, p->type, p->name,
1411 p->minimum, p->maximum,
1412 p->step, p->default_value, p->flags);
1413 else
1414 dbgarg(cmd, "id=0x%x\n", p->id);
1415 break;
1416 }
1417 case VIDIOC_G_CTRL:
1418 {
1419 struct v4l2_control *p = arg;
1420
1421 if (vfd->vidioc_g_ctrl)
1422 ret = vfd->vidioc_g_ctrl(file, fh, p);
1423 else if (vfd->vidioc_g_ext_ctrls) {
1424 struct v4l2_ext_controls ctrls;
1425 struct v4l2_ext_control ctrl;
1426
1427 ctrls.ctrl_class = V4L2_CTRL_ID2CLASS(p->id);
1428 ctrls.count = 1;
1429 ctrls.controls = &ctrl;
1430 ctrl.id = p->id;
1431 ctrl.value = p->value;
1432 if (check_ext_ctrls(&ctrls, 1)) {
1433 ret = vfd->vidioc_g_ext_ctrls(file, fh, &ctrls);
1434 if (ret == 0)
1435 p->value = ctrl.value;
1436 }
1437 } else
1438 break;
1439 if (!ret)
1440 dbgarg(cmd, "id=0x%x, value=%d\n", p->id, p->value);
1441 else
1442 dbgarg(cmd, "id=0x%x\n", p->id);
1443 break;
1444 }
1445 case VIDIOC_S_CTRL:
1446 {
1447 struct v4l2_control *p = arg;
1448 struct v4l2_ext_controls ctrls;
1449 struct v4l2_ext_control ctrl;
1450
1451 if (!vfd->vidioc_s_ctrl && !vfd->vidioc_s_ext_ctrls)
1452 break;
1453
1454 dbgarg(cmd, "id=0x%x, value=%d\n", p->id, p->value);
1455
1456 if (vfd->vidioc_s_ctrl) {
1457 ret = vfd->vidioc_s_ctrl(file, fh, p);
1458 break;
1459 }
1460 if (!vfd->vidioc_s_ext_ctrls)
1461 break;
1462
1463 ctrls.ctrl_class = V4L2_CTRL_ID2CLASS(p->id);
1464 ctrls.count = 1;
1465 ctrls.controls = &ctrl;
1466 ctrl.id = p->id;
1467 ctrl.value = p->value;
1468 if (check_ext_ctrls(&ctrls, 1))
1469 ret = vfd->vidioc_s_ext_ctrls(file, fh, &ctrls);
1470 break;
1471 }
1472 case VIDIOC_G_EXT_CTRLS:
1473 {
1474 struct v4l2_ext_controls *p = arg;
1475
1476 p->error_idx = p->count;
1477 if (!vfd->vidioc_g_ext_ctrls)
1478 break;
1479 if (check_ext_ctrls(p, 0))
1480 ret = vfd->vidioc_g_ext_ctrls(file, fh, p);
1481 v4l_print_ext_ctrls(cmd, vfd, p, !ret);
1482 break;
1483 }
1484 case VIDIOC_S_EXT_CTRLS:
1485 {
1486 struct v4l2_ext_controls *p = arg;
1487
1488 p->error_idx = p->count;
1489 if (!vfd->vidioc_s_ext_ctrls)
1490 break;
1491 v4l_print_ext_ctrls(cmd, vfd, p, 1);
1492 if (check_ext_ctrls(p, 0))
1493 ret = vfd->vidioc_s_ext_ctrls(file, fh, p);
1494 break;
1495 }
1496 case VIDIOC_TRY_EXT_CTRLS:
1497 {
1498 struct v4l2_ext_controls *p = arg;
1499
1500 p->error_idx = p->count;
1501 if (!vfd->vidioc_try_ext_ctrls)
1502 break;
1503 v4l_print_ext_ctrls(cmd, vfd, p, 1);
1504 if (check_ext_ctrls(p, 0))
1505 ret = vfd->vidioc_try_ext_ctrls(file, fh, p);
1506 break;
1507 }
1508 case VIDIOC_QUERYMENU:
1509 {
1510 struct v4l2_querymenu *p = arg;
1511
1512 if (!vfd->vidioc_querymenu)
1513 break;
1514 ret = vfd->vidioc_querymenu(file, fh, p);
1515 if (!ret)
1516 dbgarg(cmd, "id=0x%x, index=%d, name=%s\n",
1517 p->id, p->index, p->name);
1518 else
1519 dbgarg(cmd, "id=0x%x, index=%d\n",
1520 p->id, p->index);
1521 break;
1522 }
1523 /* --- audio ---------------------------------------------- */
1524 case VIDIOC_ENUMAUDIO:
1525 {
1526 struct v4l2_audio *p = arg;
1527
1528 if (!vfd->vidioc_enumaudio)
1529 break;
1530 ret = vfd->vidioc_enumaudio(file, fh, p);
1531 if (!ret)
1532 dbgarg(cmd, "index=%d, name=%s, capability=0x%x, "
1533 "mode=0x%x\n", p->index, p->name,
1534 p->capability, p->mode);
1535 else
1536 dbgarg(cmd, "index=%d\n", p->index);
1537 break;
1538 }
1539 case VIDIOC_G_AUDIO:
1540 {
1541 struct v4l2_audio *p = arg;
1542 __u32 index = p->index;
1543
1544 if (!vfd->vidioc_g_audio)
1545 break;
1546
1547 memset(p, 0, sizeof(*p));
1548 p->index = index;
1549 ret = vfd->vidioc_g_audio(file, fh, p);
1550 if (!ret)
1551 dbgarg(cmd, "index=%d, name=%s, capability=0x%x, "
1552 "mode=0x%x\n", p->index,
1553 p->name, p->capability, p->mode);
1554 else
1555 dbgarg(cmd, "index=%d\n", p->index);
1556 break;
1557 }
1558 case VIDIOC_S_AUDIO:
1559 {
1560 struct v4l2_audio *p = arg;
1561
1562 if (!vfd->vidioc_s_audio)
1563 break;
1564 dbgarg(cmd, "index=%d, name=%s, capability=0x%x, "
1565 "mode=0x%x\n", p->index, p->name,
1566 p->capability, p->mode);
1567 ret = vfd->vidioc_s_audio(file, fh, p);
1568 break;
1569 }
1570 case VIDIOC_ENUMAUDOUT:
1571 {
1572 struct v4l2_audioout *p=arg;
1573
1574 if (!vfd->vidioc_enumaudout)
1575 break;
1576 dbgarg(cmd, "Enum for index=%d\n", p->index);
1577 ret=vfd->vidioc_enumaudout(file, fh, p);
1578 if (!ret)
1579 dbgarg2("index=%d, name=%s, capability=%d, "
1580 "mode=%d\n", p->index, p->name,
1581 p->capability,p->mode);
1582 break;
1583 }
1584 case VIDIOC_G_AUDOUT:
1585 {
1586 struct v4l2_audioout *p=arg;
1587
1588 if (!vfd->vidioc_g_audout)
1589 break;
1590 dbgarg(cmd, "Enum for index=%d\n", p->index);
1591 ret=vfd->vidioc_g_audout(file, fh, p);
1592 if (!ret)
1593 dbgarg2("index=%d, name=%s, capability=%d, "
1594 "mode=%d\n", p->index, p->name,
1595 p->capability,p->mode);
1596 break;
1597 }
1598 case VIDIOC_S_AUDOUT:
1599 {
1600 struct v4l2_audioout *p=arg;
1601
1602 if (!vfd->vidioc_s_audout)
1603 break;
1604 dbgarg(cmd, "index=%d, name=%s, capability=%d, "
1605 "mode=%d\n", p->index, p->name,
1606 p->capability,p->mode);
1607
1608 ret=vfd->vidioc_s_audout(file, fh, p);
1609 break;
1610 }
1611 case VIDIOC_G_MODULATOR:
1612 {
1613 struct v4l2_modulator *p=arg;
1614 if (!vfd->vidioc_g_modulator)
1615 break;
1616 ret=vfd->vidioc_g_modulator(file, fh, p);
1617 if (!ret)
1618 dbgarg(cmd, "index=%d, name=%s, "
1619 "capability=%d, rangelow=%d,"
1620 " rangehigh=%d, txsubchans=%d\n",
1621 p->index, p->name,p->capability,
1622 p->rangelow, p->rangehigh,
1623 p->txsubchans);
1624 break;
1625 }
1626 case VIDIOC_S_MODULATOR:
1627 {
1628 struct v4l2_modulator *p=arg;
1629 if (!vfd->vidioc_s_modulator)
1630 break;
1631 dbgarg(cmd, "index=%d, name=%s, capability=%d, "
1632 "rangelow=%d, rangehigh=%d, txsubchans=%d\n",
1633 p->index, p->name,p->capability,p->rangelow,
1634 p->rangehigh,p->txsubchans);
1635 ret=vfd->vidioc_s_modulator(file, fh, p);
1636 break;
1637 }
1638 case VIDIOC_G_CROP:
1639 {
1640 struct v4l2_crop *p=arg;
1641 if (!vfd->vidioc_g_crop)
1642 break;
1643 dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names));
1644 ret=vfd->vidioc_g_crop(file, fh, p);
1645 if (!ret) {
1646 dbgrect(vfd, "", &p->c);
1647 }
1648 break;
1649 }
1650 case VIDIOC_S_CROP:
1651 {
1652 struct v4l2_crop *p=arg;
1653 if (!vfd->vidioc_s_crop)
1654 break;
1655 dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names));
1656 dbgrect(vfd, "", &p->c);
1657 ret=vfd->vidioc_s_crop(file, fh, p);
1658 break;
1659 }
1660 case VIDIOC_CROPCAP:
1661 {
1662 struct v4l2_cropcap *p = arg;
1663
1664 /*FIXME: Should also show v4l2_fract pixelaspect */
1665 if (!vfd->vidioc_cropcap)
1666 break;
1667 dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names));
1668 ret = vfd->vidioc_cropcap(file, fh, p);
1669 if (!ret) {
1670 dbgrect(vfd, "bounds ", &p->bounds);
1671 dbgrect(vfd, "defrect ", &p->defrect);
1672 }
1673 break;
1674 }
1675 case VIDIOC_G_JPEGCOMP:
1676 {
1677 struct v4l2_jpegcompression *p=arg;
1678 if (!vfd->vidioc_g_jpegcomp)
1679 break;
1680 ret=vfd->vidioc_g_jpegcomp(file, fh, p);
1681 if (!ret)
1682 dbgarg (cmd, "quality=%d, APPn=%d, "
1683 "APP_len=%d, COM_len=%d, "
1684 "jpeg_markers=%d\n",
1685 p->quality,p->APPn,p->APP_len,
1686 p->COM_len,p->jpeg_markers);
1687 break;
1688 }
1689 case VIDIOC_S_JPEGCOMP:
1690 {
1691 struct v4l2_jpegcompression *p=arg;
1692 if (!vfd->vidioc_g_jpegcomp)
1693 break;
1694 dbgarg (cmd, "quality=%d, APPn=%d, APP_len=%d, "
1695 "COM_len=%d, jpeg_markers=%d\n",
1696 p->quality,p->APPn,p->APP_len,
1697 p->COM_len,p->jpeg_markers);
1698 ret=vfd->vidioc_s_jpegcomp(file, fh, p);
1699 break;
1700 }
1701 case VIDIOC_G_ENC_INDEX:
1702 {
1703 struct v4l2_enc_idx *p=arg;
1704
1705 if (!vfd->vidioc_g_enc_index)
1706 break;
1707 ret=vfd->vidioc_g_enc_index(file, fh, p);
1708 if (!ret)
1709 dbgarg (cmd, "entries=%d, entries_cap=%d\n",
1710 p->entries,p->entries_cap);
1711 break;
1712 }
1713 case VIDIOC_ENCODER_CMD:
1714 {
1715 struct v4l2_encoder_cmd *p = arg;
1716
1717 if (!vfd->vidioc_encoder_cmd)
1718 break;
1719 memset(&p->raw, 0, sizeof(p->raw));
1720 ret = vfd->vidioc_encoder_cmd(file, fh, p);
1721 if (!ret)
1722 dbgarg(cmd, "cmd=%d, flags=%x\n", p->cmd, p->flags);
1723 break;
1724 }
1725 case VIDIOC_TRY_ENCODER_CMD:
1726 {
1727 struct v4l2_encoder_cmd *p = arg;
1728
1729 if (!vfd->vidioc_try_encoder_cmd)
1730 break;
1731 memset(&p->raw, 0, sizeof(p->raw));
1732 ret = vfd->vidioc_try_encoder_cmd(file, fh, p);
1733 if (!ret)
1734 dbgarg(cmd, "cmd=%d, flags=%x\n", p->cmd, p->flags);
1735 break;
1736 }
1737 case VIDIOC_G_PARM:
1738 {
1739 struct v4l2_streamparm *p=arg;
1740 __u32 type=p->type;
1741
1742 memset(p,0,sizeof(*p));
1743 p->type=type;
1744
1745 if (vfd->vidioc_g_parm) {
1746 ret=vfd->vidioc_g_parm(file, fh, p);
1747 } else {
1748 struct v4l2_standard s;
1749
1750 if (p->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1751 return -EINVAL;
1752
1753 v4l2_video_std_construct(&s, vfd->current_norm,
1754 v4l2_norm_to_name(vfd->current_norm));
1755
1756 p->parm.capture.timeperframe = s.frameperiod;
1757 ret=0;
1758 }
1759
1760 dbgarg (cmd, "type=%d\n", p->type);
1761 break;
1762 }
1763 case VIDIOC_S_PARM:
1764 {
1765 struct v4l2_streamparm *p=arg;
1766 if (!vfd->vidioc_s_parm)
1767 break;
1768 dbgarg (cmd, "type=%d\n", p->type);
1769 ret=vfd->vidioc_s_parm(file, fh, p);
1770 break;
1771 }
1772 case VIDIOC_G_TUNER:
1773 {
1774 struct v4l2_tuner *p = arg;
1775 __u32 index = p->index;
1776
1777 if (!vfd->vidioc_g_tuner)
1778 break;
1779
1780 memset(p, 0, sizeof(*p));
1781 p->index = index;
1782
1783 ret = vfd->vidioc_g_tuner(file, fh, p);
1784 if (!ret)
1785 dbgarg(cmd, "index=%d, name=%s, type=%d, "
1786 "capability=0x%x, rangelow=%d, "
1787 "rangehigh=%d, signal=%d, afc=%d, "
1788 "rxsubchans=0x%x, audmode=%d\n",
1789 p->index, p->name, p->type,
1790 p->capability, p->rangelow,
1791 p->rangehigh, p->signal, p->afc,
1792 p->rxsubchans, p->audmode);
1793 break;
1794 }
1795 case VIDIOC_S_TUNER:
1796 {
1797 struct v4l2_tuner *p = arg;
1798
1799 if (!vfd->vidioc_s_tuner)
1800 break;
1801 dbgarg(cmd, "index=%d, name=%s, type=%d, "
1802 "capability=0x%x, rangelow=%d, "
1803 "rangehigh=%d, signal=%d, afc=%d, "
1804 "rxsubchans=0x%x, audmode=%d\n",
1805 p->index, p->name, p->type,
1806 p->capability, p->rangelow,
1807 p->rangehigh, p->signal, p->afc,
1808 p->rxsubchans, p->audmode);
1809 ret = vfd->vidioc_s_tuner(file, fh, p);
1810 break;
1811 }
1812 case VIDIOC_G_FREQUENCY:
1813 {
1814 struct v4l2_frequency *p = arg;
1815
1816 if (!vfd->vidioc_g_frequency)
1817 break;
1818
1819 memset(p->reserved, 0, sizeof(p->reserved));
1820
1821 ret = vfd->vidioc_g_frequency(file, fh, p);
1822 if (!ret)
1823 dbgarg(cmd, "tuner=%d, type=%d, frequency=%d\n",
1824 p->tuner, p->type, p->frequency);
1825 break;
1826 }
1827 case VIDIOC_S_FREQUENCY:
1828 {
1829 struct v4l2_frequency *p=arg;
1830 if (!vfd->vidioc_s_frequency)
1831 break;
1832 dbgarg (cmd, "tuner=%d, type=%d, frequency=%d\n",
1833 p->tuner,p->type,p->frequency);
1834 ret=vfd->vidioc_s_frequency(file, fh, p);
1835 break;
1836 }
1837 case VIDIOC_G_SLICED_VBI_CAP:
1838 {
1839 struct v4l2_sliced_vbi_cap *p = arg;
1840 __u32 type = p->type;
1841
1842 if (!vfd->vidioc_g_sliced_vbi_cap)
1843 break;
1844 memset(p, 0, sizeof(*p));
1845 p->type = type;
1846 dbgarg(cmd, "type=%s\n", prt_names(p->type, v4l2_type_names));
1847 ret = vfd->vidioc_g_sliced_vbi_cap(file, fh, p);
1848 if (!ret)
1849 dbgarg2("service_set=%d\n", p->service_set);
1850 break;
1851 }
1852 case VIDIOC_LOG_STATUS:
1853 {
1854 if (!vfd->vidioc_log_status)
1855 break;
1856 ret=vfd->vidioc_log_status(file, fh);
1857 break;
1858 }
1859#ifdef CONFIG_VIDEO_ADV_DEBUG
1860 case VIDIOC_DBG_G_REGISTER:
1861 {
1862 struct v4l2_register *p=arg;
1863 if (!capable(CAP_SYS_ADMIN))
1864 ret=-EPERM;
1865 else if (vfd->vidioc_g_register)
1866 ret=vfd->vidioc_g_register(file, fh, p);
1867 break;
1868 }
1869 case VIDIOC_DBG_S_REGISTER:
1870 {
1871 struct v4l2_register *p=arg;
1872 if (!capable(CAP_SYS_ADMIN))
1873 ret=-EPERM;
1874 else if (vfd->vidioc_s_register)
1875 ret=vfd->vidioc_s_register(file, fh, p);
1876 break;
1877 }
1878#endif
1879 case VIDIOC_G_CHIP_IDENT:
1880 {
1881 struct v4l2_chip_ident *p=arg;
1882 if (!vfd->vidioc_g_chip_ident)
1883 break;
1884 ret=vfd->vidioc_g_chip_ident(file, fh, p);
1885 if (!ret)
1886 dbgarg (cmd, "chip_ident=%u, revision=0x%x\n", p->ident, p->revision);
1887 break;
1888 }
1889 default:
1890 {
1891 if (!vfd->vidioc_default)
1892 break;
1893 ret = vfd->vidioc_default(file, fh, cmd, arg);
1894 break;
1895 }
1896 case VIDIOC_S_HW_FREQ_SEEK:
1897 {
1898 struct v4l2_hw_freq_seek *p = arg;
1899 if (!vfd->vidioc_s_hw_freq_seek)
1900 break;
1901 dbgarg(cmd,
1902 "tuner=%d, type=%d, seek_upward=%d, wrap_around=%d\n",
1903 p->tuner, p->type, p->seek_upward, p->wrap_around);
1904 ret = vfd->vidioc_s_hw_freq_seek(file, fh, p);
1905 break;
1906 }
1907 } /* switch */
1908
1909 if (vfd->debug & V4L2_DEBUG_IOCTL_ARG) {
1910 if (ret < 0) {
1911 v4l_print_ioctl(vfd->name, cmd);
1912 printk(KERN_CONT " error %d\n", ret);
1913 }
1914 }
1915
1916 return ret;
1917}
1918
1919int video_ioctl2 (struct inode *inode, struct file *file,
1920 unsigned int cmd, unsigned long arg)
1921{
1922 char sbuf[128];
1923 void *mbuf = NULL;
1924 void *parg = NULL;
1925 int err = -EINVAL;
1926 int is_ext_ctrl;
1927 size_t ctrls_size = 0;
1928 void __user *user_ptr = NULL;
1929
1930#ifdef __OLD_VIDIOC_
1931 cmd = video_fix_command(cmd);
1932#endif
1933 is_ext_ctrl = (cmd == VIDIOC_S_EXT_CTRLS || cmd == VIDIOC_G_EXT_CTRLS ||
1934 cmd == VIDIOC_TRY_EXT_CTRLS);
1935
1936 /* Copy arguments into temp kernel buffer */
1937 switch (_IOC_DIR(cmd)) {
1938 case _IOC_NONE:
1939 parg = NULL;
1940 break;
1941 case _IOC_READ:
1942 case _IOC_WRITE:
1943 case (_IOC_WRITE | _IOC_READ):
1944 if (_IOC_SIZE(cmd) <= sizeof(sbuf)) {
1945 parg = sbuf;
1946 } else {
1947 /* too big to allocate from stack */
1948 mbuf = kmalloc(_IOC_SIZE(cmd),GFP_KERNEL);
1949 if (NULL == mbuf)
1950 return -ENOMEM;
1951 parg = mbuf;
1952 }
1953
1954 err = -EFAULT;
1955 if (_IOC_DIR(cmd) & _IOC_WRITE)
1956 if (copy_from_user(parg, (void __user *)arg, _IOC_SIZE(cmd)))
1957 goto out;
1958 break;
1959 }
1960
1961 if (is_ext_ctrl) {
1962 struct v4l2_ext_controls *p = parg;
1963
1964 /* In case of an error, tell the caller that it wasn't
1965 a specific control that caused it. */
1966 p->error_idx = p->count;
1967 user_ptr = (void __user *)p->controls;
1968 if (p->count) {
1969 ctrls_size = sizeof(struct v4l2_ext_control) * p->count;
1970 /* Note: v4l2_ext_controls fits in sbuf[] so mbuf is still NULL. */
1971 mbuf = kmalloc(ctrls_size, GFP_KERNEL);
1972 err = -ENOMEM;
1973 if (NULL == mbuf)
1974 goto out_ext_ctrl;
1975 err = -EFAULT;
1976 if (copy_from_user(mbuf, user_ptr, ctrls_size))
1977 goto out_ext_ctrl;
1978 p->controls = mbuf;
1979 }
1980 }
1981
1982 /* Handles IOCTL */
1983 err = __video_do_ioctl(inode, file, cmd, parg);
1984 if (err == -ENOIOCTLCMD)
1985 err = -EINVAL;
1986 if (is_ext_ctrl) {
1987 struct v4l2_ext_controls *p = parg;
1988
1989 p->controls = (void *)user_ptr;
1990 if (p->count && err == 0 && copy_to_user(user_ptr, mbuf, ctrls_size))
1991 err = -EFAULT;
1992 goto out_ext_ctrl;
1993 }
1994 if (err < 0)
1995 goto out;
1996
1997out_ext_ctrl:
1998 /* Copy results into user buffer */
1999 switch (_IOC_DIR(cmd))
2000 {
2001 case _IOC_READ:
2002 case (_IOC_WRITE | _IOC_READ):
2003 if (copy_to_user((void __user *)arg, parg, _IOC_SIZE(cmd)))
2004 err = -EFAULT;
2005 break;
2006 }
2007
2008out:
2009 kfree(mbuf);
2010 return err;
2011}
2012EXPORT_SYMBOL(video_ioctl2);
2013
2014/**
2015 * get_index - assign stream number based on parent device
2016 * @vdev: video_device to assign index number to, vdev->dev should be assigned
2017 * @num: -1 if auto assign, requested number otherwise
2018 *
2019 *
2020 * returns -ENFILE if num is already in use, a free index number if
2021 * successful.
2022 */
2023static int get_index(struct video_device *vdev, int num)
2024{
2025 u32 used = 0;
2026 const int max_index = sizeof(used) * 8 - 1;
2027 int i;
2028
2029 /* Currently a single v4l driver instance cannot create more than
2030 32 devices.
2031 Increase to u64 or an array of u32 if more are needed. */
2032 if (num > max_index) {
2033 printk(KERN_ERR "videodev: %s num is too large\n", __func__);
2034 return -EINVAL;
2035 }
2036
2037 for (i = 0; i < VIDEO_NUM_DEVICES; i++) {
2038 if (video_device[i] != NULL &&
2039 video_device[i] != vdev &&
2040 video_device[i]->dev == vdev->dev) {
2041 used |= 1 << video_device[i]->index;
2042 }
2043 }
2044
2045 if (num >= 0) {
2046 if (used & (1 << num))
2047 return -ENFILE;
2048 return num;
2049 }
2050
2051 i = ffz(used);
2052 return i > max_index ? -ENFILE : i;
2053}
2054
2055static const struct file_operations video_fops;
2056
2057int video_register_device(struct video_device *vfd, int type, int nr)
2058{
2059 return video_register_device_index(vfd, type, nr, -1);
2060}
2061EXPORT_SYMBOL(video_register_device);
2062
2063/**
2064 * video_register_device - register video4linux devices
2065 * @vfd: video device structure we want to register
2066 * @type: type of device to register
2067 * @nr: which device number (0 == /dev/video0, 1 == /dev/video1, ...
2068 * -1 == first free)
2069 *
2070 * The registration code assigns minor numbers based on the type
2071 * requested. -ENFILE is returned in all the device slots for this
2072 * category are full. If not then the minor field is set and the
2073 * driver initialize function is called (if non %NULL).
2074 *
2075 * Zero is returned on success.
2076 *
2077 * Valid types are
2078 *
2079 * %VFL_TYPE_GRABBER - A frame grabber
2080 *
2081 * %VFL_TYPE_VTX - A teletext device
2082 *
2083 * %VFL_TYPE_VBI - Vertical blank data (undecoded)
2084 *
2085 * %VFL_TYPE_RADIO - A radio card
2086 */
2087
2088int video_register_device_index(struct video_device *vfd, int type, int nr,
2089 int index)
2090{
2091 int i=0;
2092 int base;
2093 int end;
2094 int ret;
2095 char *name_base;
2096
2097 switch(type)
2098 {
2099 case VFL_TYPE_GRABBER:
2100 base=MINOR_VFL_TYPE_GRABBER_MIN;
2101 end=MINOR_VFL_TYPE_GRABBER_MAX+1;
2102 name_base = "video";
2103 break;
2104 case VFL_TYPE_VTX:
2105 base=MINOR_VFL_TYPE_VTX_MIN;
2106 end=MINOR_VFL_TYPE_VTX_MAX+1;
2107 name_base = "vtx";
2108 break;
2109 case VFL_TYPE_VBI:
2110 base=MINOR_VFL_TYPE_VBI_MIN;
2111 end=MINOR_VFL_TYPE_VBI_MAX+1;
2112 name_base = "vbi";
2113 break;
2114 case VFL_TYPE_RADIO:
2115 base=MINOR_VFL_TYPE_RADIO_MIN;
2116 end=MINOR_VFL_TYPE_RADIO_MAX+1;
2117 name_base = "radio";
2118 break;
2119 default:
2120 printk(KERN_ERR "%s called with unknown type: %d\n",
2121 __func__, type);
2122 return -1;
2123 }
2124
2125 /* pick a minor number */
2126 mutex_lock(&videodev_lock);
2127 if (nr >= 0 && nr < end-base) {
2128 /* use the one the driver asked for */
2129 i = base+nr;
2130 if (NULL != video_device[i]) {
2131 mutex_unlock(&videodev_lock);
2132 return -ENFILE;
2133 }
2134 } else {
2135 /* use first free */
2136 for(i=base;i<end;i++)
2137 if (NULL == video_device[i])
2138 break;
2139 if (i == end) {
2140 mutex_unlock(&videodev_lock);
2141 return -ENFILE;
2142 }
2143 }
2144 video_device[i]=vfd;
2145 vfd->minor=i;
2146
2147 ret = get_index(vfd, index);
2148 vfd->index = ret;
2149
2150 mutex_unlock(&videodev_lock);
2151
2152 if (ret < 0) {
2153 printk(KERN_ERR "%s: get_index failed\n", __func__);
2154 goto fail_minor;
2155 }
2156
2157 mutex_init(&vfd->lock);
2158
2159 /* sysfs class */
2160 memset(&vfd->class_dev, 0x00, sizeof(vfd->class_dev));
2161 vfd->class_dev.class = &video_class;
2162 vfd->class_dev.devt = MKDEV(VIDEO_MAJOR, vfd->minor);
2163 if (vfd->dev)
2164 vfd->class_dev.parent = vfd->dev;
2165 sprintf(vfd->class_dev.bus_id, "%s%d", name_base, i - base);
2166 ret = device_register(&vfd->class_dev);
2167 if (ret < 0) {
2168 printk(KERN_ERR "%s: device_register failed\n", __func__);
2169 goto fail_minor;
2170 }
2171
2172#if 1
2173 /* needed until all drivers are fixed */
2174 if (!vfd->release)
2175 printk(KERN_WARNING "videodev: \"%s\" has no release callback. "
2176 "Please fix your driver for proper sysfs support, see "
2177 "http://lwn.net/Articles/36850/\n", vfd->name);
2178#endif
2179 return 0;
2180
2181fail_minor:
2182 mutex_lock(&videodev_lock);
2183 video_device[vfd->minor] = NULL;
2184 vfd->minor = -1;
2185 mutex_unlock(&videodev_lock);
2186 return ret;
2187}
2188EXPORT_SYMBOL(video_register_device_index);
2189
2190/**
2191 * video_unregister_device - unregister a video4linux device
2192 * @vfd: the device to unregister
2193 *
2194 * This unregisters the passed device and deassigns the minor
2195 * number. Future open calls will be met with errors.
2196 */
2197
2198void video_unregister_device(struct video_device *vfd)
2199{
2200 mutex_lock(&videodev_lock);
2201 if(video_device[vfd->minor]!=vfd)
2202 panic("videodev: bad unregister");
2203
2204 video_device[vfd->minor]=NULL;
2205 device_unregister(&vfd->class_dev);
2206 mutex_unlock(&videodev_lock);
2207}
2208EXPORT_SYMBOL(video_unregister_device);
2209
2210/*
2211 * Video fs operations
2212 */
2213static const struct file_operations video_fops=
2214{
2215 .owner = THIS_MODULE,
2216 .llseek = no_llseek,
2217 .open = video_open,
2218};
2219
2220/*
2221 * Initialise video for linux
2222 */
2223
2224static int __init videodev_init(void)
2225{
2226 int ret;
2227
2228 printk(KERN_INFO "Linux video capture interface: v2.00\n");
2229 if (register_chrdev(VIDEO_MAJOR, VIDEO_NAME, &video_fops)) {
2230 printk(KERN_WARNING "video_dev: unable to get major %d\n", VIDEO_MAJOR);
2231 return -EIO;
2232 }
2233
2234 ret = class_register(&video_class);
2235 if (ret < 0) {
2236 unregister_chrdev(VIDEO_MAJOR, VIDEO_NAME);
2237 printk(KERN_WARNING "video_dev: class_register failed\n");
2238 return -EIO;
2239 }
2240
2241 return 0;
2242}
2243
2244static void __exit videodev_exit(void)
2245{
2246 class_unregister(&video_class);
2247 unregister_chrdev(VIDEO_MAJOR, VIDEO_NAME);
2248}
2249
2250module_init(videodev_init)
2251module_exit(videodev_exit)
2252
2253MODULE_AUTHOR("Alan Cox, Mauro Carvalho Chehab <mchehab@infradead.org>");
2254MODULE_DESCRIPTION("Device registrar for Video4Linux drivers v2");
2255MODULE_LICENSE("GPL");
2256
2257
2258/*
2259 * Local variables:
2260 * c-basic-offset: 8
2261 * End:
2262 */
diff --git a/drivers/media/video/vino.c b/drivers/media/video/vino.c
index 01ea99c9bc1a..3989b0eded28 100644
--- a/drivers/media/video/vino.c
+++ b/drivers/media/video/vino.c
@@ -38,7 +38,7 @@
38#include <linux/i2c.h> 38#include <linux/i2c.h>
39#include <linux/i2c-algo-sgi.h> 39#include <linux/i2c-algo-sgi.h>
40 40
41#include <linux/videodev.h> 41#include <linux/videodev2.h>
42#include <media/v4l2-common.h> 42#include <media/v4l2-common.h>
43#include <linux/video_decoder.h> 43#include <linux/video_decoder.h>
44#include <linux/mutex.h> 44#include <linux/mutex.h>
@@ -4385,8 +4385,6 @@ static const struct file_operations vino_fops = {
4385 4385
4386static struct video_device v4l_device_template = { 4386static struct video_device v4l_device_template = {
4387 .name = "NOT SET", 4387 .name = "NOT SET",
4388 /*.type = VID_TYPE_CAPTURE | VID_TYPE_SUBCAPTURE | */
4389 /* VID_TYPE_CLIPPING | VID_TYPE_SCALES, VID_TYPE_OVERLAY */
4390 .fops = &vino_fops, 4388 .fops = &vino_fops,
4391 .minor = -1, 4389 .minor = -1,
4392}; 4390};
diff --git a/drivers/media/video/vivi.c b/drivers/media/video/vivi.c
index 059b01c11dc1..3518af071a2e 100644
--- a/drivers/media/video/vivi.c
+++ b/drivers/media/video/vivi.c
@@ -35,6 +35,7 @@
35#include <linux/interrupt.h> 35#include <linux/interrupt.h>
36#include <media/videobuf-vmalloc.h> 36#include <media/videobuf-vmalloc.h>
37#include <media/v4l2-common.h> 37#include <media/v4l2-common.h>
38#include <media/v4l2-ioctl.h>
38#include <linux/kthread.h> 39#include <linux/kthread.h>
39#include <linux/highmem.h> 40#include <linux/highmem.h>
40#include <linux/freezer.h> 41#include <linux/freezer.h>
@@ -1065,13 +1066,7 @@ static const struct file_operations vivi_fops = {
1065 .llseek = no_llseek, 1066 .llseek = no_llseek,
1066}; 1067};
1067 1068
1068static struct video_device vivi_template = { 1069static const struct v4l2_ioctl_ops vivi_ioctl_ops = {
1069 .name = "vivi",
1070 .type = VID_TYPE_CAPTURE,
1071 .fops = &vivi_fops,
1072 .minor = -1,
1073 .release = video_device_release,
1074
1075 .vidioc_querycap = vidioc_querycap, 1070 .vidioc_querycap = vidioc_querycap,
1076 .vidioc_enum_fmt_vid_cap = vidioc_enum_fmt_vid_cap, 1071 .vidioc_enum_fmt_vid_cap = vidioc_enum_fmt_vid_cap,
1077 .vidioc_g_fmt_vid_cap = vidioc_g_fmt_vid_cap, 1072 .vidioc_g_fmt_vid_cap = vidioc_g_fmt_vid_cap,
@@ -1093,6 +1088,15 @@ static struct video_device vivi_template = {
1093#ifdef CONFIG_VIDEO_V4L1_COMPAT 1088#ifdef CONFIG_VIDEO_V4L1_COMPAT
1094 .vidiocgmbuf = vidiocgmbuf, 1089 .vidiocgmbuf = vidiocgmbuf,
1095#endif 1090#endif
1091};
1092
1093static struct video_device vivi_template = {
1094 .name = "vivi",
1095 .fops = &vivi_fops,
1096 .ioctl_ops = &vivi_ioctl_ops,
1097 .minor = -1,
1098 .release = video_device_release,
1099
1096 .tvnorms = V4L2_STD_525_60, 1100 .tvnorms = V4L2_STD_525_60,
1097 .current_norm = V4L2_STD_NTSC_M, 1101 .current_norm = V4L2_STD_NTSC_M,
1098}; 1102};
diff --git a/drivers/media/video/vp27smpx.c b/drivers/media/video/vp27smpx.c
index cbecb3cbbbaa..577956c5410b 100644
--- a/drivers/media/video/vp27smpx.c
+++ b/drivers/media/video/vp27smpx.c
@@ -27,7 +27,7 @@
27#include <asm/uaccess.h> 27#include <asm/uaccess.h>
28#include <linux/i2c.h> 28#include <linux/i2c.h>
29#include <linux/i2c-id.h> 29#include <linux/i2c-id.h>
30#include <linux/videodev.h> 30#include <linux/videodev2.h>
31#include <media/v4l2-common.h> 31#include <media/v4l2-common.h>
32#include <media/v4l2-chip-ident.h> 32#include <media/v4l2-chip-ident.h>
33#include <media/v4l2-i2c-drv.h> 33#include <media/v4l2-i2c-drv.h>
diff --git a/drivers/media/video/w9966.c b/drivers/media/video/w9966.c
index 33f702698a56..9402f40095b4 100644
--- a/drivers/media/video/w9966.c
+++ b/drivers/media/video/w9966.c
@@ -57,8 +57,9 @@
57#include <linux/module.h> 57#include <linux/module.h>
58#include <linux/init.h> 58#include <linux/init.h>
59#include <linux/delay.h> 59#include <linux/delay.h>
60#include <linux/videodev.h> 60#include <linux/videodev2.h>
61#include <media/v4l2-common.h> 61#include <media/v4l2-common.h>
62#include <media/v4l2-ioctl.h>
62#include <linux/parport.h> 63#include <linux/parport.h>
63 64
64/*#define DEBUG*/ /* Undef me for production */ 65/*#define DEBUG*/ /* Undef me for production */
@@ -195,9 +196,7 @@ static const struct file_operations w9966_fops = {
195 .llseek = no_llseek, 196 .llseek = no_llseek,
196}; 197};
197static struct video_device w9966_template = { 198static struct video_device w9966_template = {
198 .owner = THIS_MODULE,
199 .name = W9966_DRIVERNAME, 199 .name = W9966_DRIVERNAME,
200 .type = VID_TYPE_CAPTURE | VID_TYPE_SCALES,
201 .fops = &w9966_fops, 200 .fops = &w9966_fops,
202}; 201};
203 202
diff --git a/drivers/media/video/w9968cf.c b/drivers/media/video/w9968cf.c
index 840522442d07..168baabe4659 100644
--- a/drivers/media/video/w9968cf.c
+++ b/drivers/media/video/w9968cf.c
@@ -42,6 +42,7 @@
42#include <asm/page.h> 42#include <asm/page.h>
43#include <asm/uaccess.h> 43#include <asm/uaccess.h>
44#include <linux/page-flags.h> 44#include <linux/page-flags.h>
45#include <media/v4l2-ioctl.h>
45 46
46#include "w9968cf.h" 47#include "w9968cf.h"
47#include "w9968cf_decoder.h" 48#include "w9968cf_decoder.h"
@@ -3549,13 +3550,11 @@ w9968cf_usb_probe(struct usb_interface* intf, const struct usb_device_id* id)
3549 } 3550 }
3550 3551
3551 strcpy(cam->v4ldev->name, symbolic(camlist, mod_id)); 3552 strcpy(cam->v4ldev->name, symbolic(camlist, mod_id));
3552 cam->v4ldev->owner = THIS_MODULE;
3553 cam->v4ldev->type = VID_TYPE_CAPTURE | VID_TYPE_SCALES;
3554 cam->v4ldev->fops = &w9968cf_fops; 3553 cam->v4ldev->fops = &w9968cf_fops;
3555 cam->v4ldev->minor = video_nr[dev_nr]; 3554 cam->v4ldev->minor = video_nr[dev_nr];
3556 cam->v4ldev->release = video_device_release; 3555 cam->v4ldev->release = video_device_release;
3557 video_set_drvdata(cam->v4ldev, cam); 3556 video_set_drvdata(cam->v4ldev, cam);
3558 cam->v4ldev->dev = &cam->dev; 3557 cam->v4ldev->parent = &cam->dev;
3559 3558
3560 err = video_register_device(cam->v4ldev, VFL_TYPE_GRABBER, 3559 err = video_register_device(cam->v4ldev, VFL_TYPE_GRABBER,
3561 video_nr[dev_nr]); 3560 video_nr[dev_nr]);
diff --git a/drivers/media/video/w9968cf.h b/drivers/media/video/w9968cf.h
index 3c95316bc030..30032e15e23c 100644
--- a/drivers/media/video/w9968cf.h
+++ b/drivers/media/video/w9968cf.h
@@ -21,7 +21,7 @@
21#ifndef _W9968CF_H_ 21#ifndef _W9968CF_H_
22#define _W9968CF_H_ 22#define _W9968CF_H_
23 23
24#include <linux/videodev.h> 24#include <linux/videodev2.h>
25#include <linux/usb.h> 25#include <linux/usb.h>
26#include <linux/i2c.h> 26#include <linux/i2c.h>
27#include <linux/device.h> 27#include <linux/device.h>
diff --git a/drivers/media/video/wm8739.c b/drivers/media/video/wm8739.c
index 7be47a255853..95c79ad80487 100644
--- a/drivers/media/video/wm8739.c
+++ b/drivers/media/video/wm8739.c
@@ -27,7 +27,7 @@
27#include <asm/uaccess.h> 27#include <asm/uaccess.h>
28#include <linux/i2c.h> 28#include <linux/i2c.h>
29#include <linux/i2c-id.h> 29#include <linux/i2c-id.h>
30#include <linux/videodev.h> 30#include <linux/videodev2.h>
31#include <media/v4l2-common.h> 31#include <media/v4l2-common.h>
32#include <media/v4l2-chip-ident.h> 32#include <media/v4l2-chip-ident.h>
33#include <media/v4l2-i2c-drv.h> 33#include <media/v4l2-i2c-drv.h>
diff --git a/drivers/media/video/wm8775.c b/drivers/media/video/wm8775.c
index c2ab70a04a74..48df661d4fc3 100644
--- a/drivers/media/video/wm8775.c
+++ b/drivers/media/video/wm8775.c
@@ -31,7 +31,7 @@
31#include <asm/uaccess.h> 31#include <asm/uaccess.h>
32#include <linux/i2c.h> 32#include <linux/i2c.h>
33#include <linux/i2c-id.h> 33#include <linux/i2c-id.h>
34#include <linux/videodev.h> 34#include <linux/videodev2.h>
35#include <media/v4l2-common.h> 35#include <media/v4l2-common.h>
36#include <media/v4l2-chip-ident.h> 36#include <media/v4l2-chip-ident.h>
37#include <media/v4l2-i2c-drv-legacy.h> 37#include <media/v4l2-i2c-drv-legacy.h>
diff --git a/drivers/media/video/zc0301/zc0301.h b/drivers/media/video/zc0301/zc0301.h
index 7bbab541a309..b1b5cceb4baa 100644
--- a/drivers/media/video/zc0301/zc0301.h
+++ b/drivers/media/video/zc0301/zc0301.h
@@ -25,6 +25,7 @@
25#include <linux/usb.h> 25#include <linux/usb.h>
26#include <linux/videodev2.h> 26#include <linux/videodev2.h>
27#include <media/v4l2-common.h> 27#include <media/v4l2-common.h>
28#include <media/v4l2-ioctl.h>
28#include <linux/device.h> 29#include <linux/device.h>
29#include <linux/list.h> 30#include <linux/list.h>
30#include <linux/spinlock.h> 31#include <linux/spinlock.h>
diff --git a/drivers/media/video/zc0301/zc0301_core.c b/drivers/media/video/zc0301/zc0301_core.c
index e5c4e9f5193f..550ce7bd5c87 100644
--- a/drivers/media/video/zc0301/zc0301_core.c
+++ b/drivers/media/video/zc0301/zc0301_core.c
@@ -1985,8 +1985,6 @@ zc0301_usb_probe(struct usb_interface* intf, const struct usb_device_id* id)
1985 } 1985 }
1986 1986
1987 strcpy(cam->v4ldev->name, "ZC0301[P] PC Camera"); 1987 strcpy(cam->v4ldev->name, "ZC0301[P] PC Camera");
1988 cam->v4ldev->owner = THIS_MODULE;
1989 cam->v4ldev->type = VID_TYPE_CAPTURE | VID_TYPE_SCALES;
1990 cam->v4ldev->fops = &zc0301_fops; 1988 cam->v4ldev->fops = &zc0301_fops;
1991 cam->v4ldev->minor = video_nr[dev_nr]; 1989 cam->v4ldev->minor = video_nr[dev_nr];
1992 cam->v4ldev->release = video_device_release; 1990 cam->v4ldev->release = video_device_release;
diff --git a/drivers/media/video/zoran_card.c b/drivers/media/video/zoran_card.c
index 0929edb2d4f1..d842a7cb99d2 100644
--- a/drivers/media/video/zoran_card.c
+++ b/drivers/media/video/zoran_card.c
@@ -161,7 +161,7 @@ static struct pci_device_id zr36067_pci_tbl[] = {
161MODULE_DEVICE_TABLE(pci, zr36067_pci_tbl); 161MODULE_DEVICE_TABLE(pci, zr36067_pci_tbl);
162 162
163int zoran_num; /* number of Buzs in use */ 163int zoran_num; /* number of Buzs in use */
164struct zoran zoran[BUZ_MAX]; 164struct zoran *zoran[BUZ_MAX];
165 165
166/* videocodec bus functions ZR36060 */ 166/* videocodec bus functions ZR36060 */
167static u32 167static u32
@@ -355,9 +355,15 @@ i2cid_to_modulename (u16 i2c_id)
355 case I2C_DRIVERID_BT856: 355 case I2C_DRIVERID_BT856:
356 name = "bt856"; 356 name = "bt856";
357 break; 357 break;
358 case I2C_DRIVERID_BT866:
359 name = "bt866";
360 break;
358 case I2C_DRIVERID_VPX3220: 361 case I2C_DRIVERID_VPX3220:
359 name = "vpx3220"; 362 name = "vpx3220";
360 break; 363 break;
364 case I2C_DRIVERID_KS0127:
365 name = "ks0127";
366 break;
361 } 367 }
362 368
363 return name; 369 return name;
@@ -1164,7 +1170,7 @@ static void
1164zoran_release (struct zoran *zr) 1170zoran_release (struct zoran *zr)
1165{ 1171{
1166 if (!zr->initialized) 1172 if (!zr->initialized)
1167 return; 1173 goto exit_free;
1168 /* unregister videocodec bus */ 1174 /* unregister videocodec bus */
1169 if (zr->codec) { 1175 if (zr->codec) {
1170 struct videocodec_master *master = zr->codec->master_data; 1176 struct videocodec_master *master = zr->codec->master_data;
@@ -1192,6 +1198,8 @@ zoran_release (struct zoran *zr)
1192 iounmap(zr->zr36057_mem); 1198 iounmap(zr->zr36057_mem);
1193 pci_disable_device(zr->pci_dev); 1199 pci_disable_device(zr->pci_dev);
1194 video_unregister_device(zr->video_dev); 1200 video_unregister_device(zr->video_dev);
1201exit_free:
1202 kfree(zr);
1195} 1203}
1196 1204
1197void 1205void
@@ -1269,8 +1277,14 @@ find_zr36057 (void)
1269 while (zoran_num < BUZ_MAX && 1277 while (zoran_num < BUZ_MAX &&
1270 (dev = pci_get_device(PCI_VENDOR_ID_ZORAN, PCI_DEVICE_ID_ZORAN_36057, dev)) != NULL) { 1278 (dev = pci_get_device(PCI_VENDOR_ID_ZORAN, PCI_DEVICE_ID_ZORAN_36057, dev)) != NULL) {
1271 card_num = card[zoran_num]; 1279 card_num = card[zoran_num];
1272 zr = &zoran[zoran_num]; 1280 zr = kzalloc(sizeof(struct zoran), GFP_KERNEL);
1273 memset(zr, 0, sizeof(struct zoran)); // Just in case if previous cycle failed 1281 if (!zr) {
1282 dprintk(1,
1283 KERN_ERR
1284 "%s: find_zr36057() - kzalloc failed\n",
1285 ZORAN_NAME);
1286 continue;
1287 }
1274 zr->pci_dev = dev; 1288 zr->pci_dev = dev;
1275 //zr->zr36057_mem = NULL; 1289 //zr->zr36057_mem = NULL;
1276 zr->id = zoran_num; 1290 zr->id = zoran_num;
@@ -1278,7 +1292,7 @@ find_zr36057 (void)
1278 spin_lock_init(&zr->spinlock); 1292 spin_lock_init(&zr->spinlock);
1279 mutex_init(&zr->resource_lock); 1293 mutex_init(&zr->resource_lock);
1280 if (pci_enable_device(dev)) 1294 if (pci_enable_device(dev))
1281 continue; 1295 goto zr_free_mem;
1282 zr->zr36057_adr = pci_resource_start(zr->pci_dev, 0); 1296 zr->zr36057_adr = pci_resource_start(zr->pci_dev, 0);
1283 pci_read_config_byte(zr->pci_dev, PCI_CLASS_REVISION, 1297 pci_read_config_byte(zr->pci_dev, PCI_CLASS_REVISION,
1284 &zr->revision); 1298 &zr->revision);
@@ -1294,7 +1308,7 @@ find_zr36057 (void)
1294 KERN_ERR 1308 KERN_ERR
1295 "%s: find_zr36057() - no card specified, please use the card=X insmod option\n", 1309 "%s: find_zr36057() - no card specified, please use the card=X insmod option\n",
1296 ZR_DEVNAME(zr)); 1310 ZR_DEVNAME(zr));
1297 continue; 1311 goto zr_free_mem;
1298 } 1312 }
1299 } else { 1313 } else {
1300 int i; 1314 int i;
@@ -1333,7 +1347,7 @@ find_zr36057 (void)
1333 KERN_ERR 1347 KERN_ERR
1334 "%s: find_zr36057() - unknown card\n", 1348 "%s: find_zr36057() - unknown card\n",
1335 ZR_DEVNAME(zr)); 1349 ZR_DEVNAME(zr));
1336 continue; 1350 goto zr_free_mem;
1337 } 1351 }
1338 } 1352 }
1339 } 1353 }
@@ -1343,7 +1357,7 @@ find_zr36057 (void)
1343 KERN_ERR 1357 KERN_ERR
1344 "%s: find_zr36057() - invalid cardnum %d\n", 1358 "%s: find_zr36057() - invalid cardnum %d\n",
1345 ZR_DEVNAME(zr), card_num); 1359 ZR_DEVNAME(zr), card_num);
1346 continue; 1360 goto zr_free_mem;
1347 } 1361 }
1348 1362
1349 /* even though we make this a non pointer and thus 1363 /* even though we make this a non pointer and thus
@@ -1361,7 +1375,7 @@ find_zr36057 (void)
1361 KERN_ERR 1375 KERN_ERR
1362 "%s: find_zr36057() - ioremap failed\n", 1376 "%s: find_zr36057() - ioremap failed\n",
1363 ZR_DEVNAME(zr)); 1377 ZR_DEVNAME(zr));
1364 continue; 1378 goto zr_free_mem;
1365 } 1379 }
1366 1380
1367 result = request_irq(zr->pci_dev->irq, 1381 result = request_irq(zr->pci_dev->irq,
@@ -1530,7 +1544,7 @@ find_zr36057 (void)
1530 } 1544 }
1531 /* Success so keep the pci_dev referenced */ 1545 /* Success so keep the pci_dev referenced */
1532 pci_dev_get(zr->pci_dev); 1546 pci_dev_get(zr->pci_dev);
1533 zoran_num++; 1547 zoran[zoran_num++] = zr;
1534 continue; 1548 continue;
1535 1549
1536 // Init errors 1550 // Init errors
@@ -1549,6 +1563,8 @@ find_zr36057 (void)
1549 free_irq(zr->pci_dev->irq, zr); 1563 free_irq(zr->pci_dev->irq, zr);
1550 zr_unmap: 1564 zr_unmap:
1551 iounmap(zr->zr36057_mem); 1565 iounmap(zr->zr36057_mem);
1566 zr_free_mem:
1567 kfree(zr);
1552 continue; 1568 continue;
1553 } 1569 }
1554 if (dev) /* Clean up ref count on early exit */ 1570 if (dev) /* Clean up ref count on early exit */
@@ -1620,7 +1636,7 @@ init_dc10_cards (void)
1620 1636
1621 /* take care of Natoma chipset and a revision 1 zr36057 */ 1637 /* take care of Natoma chipset and a revision 1 zr36057 */
1622 for (i = 0; i < zoran_num; i++) { 1638 for (i = 0; i < zoran_num; i++) {
1623 struct zoran *zr = &zoran[i]; 1639 struct zoran *zr = zoran[i];
1624 1640
1625 if ((pci_pci_problems & PCIPCI_NATOMA) && zr->revision <= 1) { 1641 if ((pci_pci_problems & PCIPCI_NATOMA) && zr->revision <= 1) {
1626 zr->jpg_buffers.need_contiguous = 1; 1642 zr->jpg_buffers.need_contiguous = 1;
@@ -1632,7 +1648,7 @@ init_dc10_cards (void)
1632 1648
1633 if (zr36057_init(zr) < 0) { 1649 if (zr36057_init(zr) < 0) {
1634 for (i = 0; i < zoran_num; i++) 1650 for (i = 0; i < zoran_num; i++)
1635 zoran_release(&zoran[i]); 1651 zoran_release(zoran[i]);
1636 return -EIO; 1652 return -EIO;
1637 } 1653 }
1638 zoran_proc_init(zr); 1654 zoran_proc_init(zr);
@@ -1647,7 +1663,7 @@ unload_dc10_cards (void)
1647 int i; 1663 int i;
1648 1664
1649 for (i = 0; i < zoran_num; i++) 1665 for (i = 0; i < zoran_num; i++)
1650 zoran_release(&zoran[i]); 1666 zoran_release(zoran[i]);
1651} 1667}
1652 1668
1653module_init(init_dc10_cards); 1669module_init(init_dc10_cards);
diff --git a/drivers/media/video/zoran_card.h b/drivers/media/video/zoran_card.h
index 1b5c4171cf9c..e4dc9d29b404 100644
--- a/drivers/media/video/zoran_card.h
+++ b/drivers/media/video/zoran_card.h
@@ -41,7 +41,7 @@ extern int zr36067_debug;
41/* Anybody who uses more than four? */ 41/* Anybody who uses more than four? */
42#define BUZ_MAX 4 42#define BUZ_MAX 4
43extern int zoran_num; 43extern int zoran_num;
44extern struct zoran zoran[BUZ_MAX]; 44extern struct zoran *zoran[BUZ_MAX];
45 45
46extern struct video_device zoran_template; 46extern struct video_device zoran_template;
47 47
diff --git a/drivers/media/video/zoran_driver.c b/drivers/media/video/zoran_driver.c
index c0675921fe20..ec6f59674b10 100644
--- a/drivers/media/video/zoran_driver.c
+++ b/drivers/media/video/zoran_driver.c
@@ -71,6 +71,7 @@
71 71
72#include <linux/videodev.h> 72#include <linux/videodev.h>
73#include <media/v4l2-common.h> 73#include <media/v4l2-common.h>
74#include <media/v4l2-ioctl.h>
74#include "videocodec.h" 75#include "videocodec.h"
75 76
76#include <asm/byteorder.h> 77#include <asm/byteorder.h>
@@ -1212,8 +1213,8 @@ zoran_open (struct inode *inode,
1212 1213
1213 /* find the device */ 1214 /* find the device */
1214 for (i = 0; i < zoran_num; i++) { 1215 for (i = 0; i < zoran_num; i++) {
1215 if (zoran[i].video_dev->minor == minor) { 1216 if (zoran[i]->video_dev->minor == minor) {
1216 zr = &zoran[i]; 1217 zr = zoran[i];
1217 break; 1218 break;
1218 } 1219 }
1219 } 1220 }
@@ -4643,8 +4644,6 @@ static const struct file_operations zoran_fops = {
4643 4644
4644struct video_device zoran_template __devinitdata = { 4645struct video_device zoran_template __devinitdata = {
4645 .name = ZORAN_NAME, 4646 .name = ZORAN_NAME,
4646 .type = ZORAN_VID_TYPE,
4647 .type2 = ZORAN_V4L2_VID_FLAGS,
4648 .fops = &zoran_fops, 4647 .fops = &zoran_fops,
4649 .release = &zoran_vdev_release, 4648 .release = &zoran_vdev_release,
4650 .minor = -1 4649 .minor = -1
diff --git a/drivers/media/video/zr364xx.c b/drivers/media/video/zr364xx.c
index 485df2e36132..18d1c4ba79fb 100644
--- a/drivers/media/video/zr364xx.c
+++ b/drivers/media/video/zr364xx.c
@@ -35,6 +35,7 @@
35#include <linux/proc_fs.h> 35#include <linux/proc_fs.h>
36#include <linux/highmem.h> 36#include <linux/highmem.h>
37#include <media/v4l2-common.h> 37#include <media/v4l2-common.h>
38#include <media/v4l2-ioctl.h>
38 39
39 40
40/* Version Information */ 41/* Version Information */
@@ -761,14 +762,7 @@ static const struct file_operations zr364xx_fops = {
761 .llseek = no_llseek, 762 .llseek = no_llseek,
762}; 763};
763 764
764static struct video_device zr364xx_template = { 765static const struct v4l2_ioctl_ops zr364xx_ioctl_ops = {
765 .owner = THIS_MODULE,
766 .name = DRIVER_DESC,
767 .type = VID_TYPE_CAPTURE,
768 .fops = &zr364xx_fops,
769 .release = video_device_release,
770 .minor = -1,
771
772 .vidioc_querycap = zr364xx_vidioc_querycap, 766 .vidioc_querycap = zr364xx_vidioc_querycap,
773 .vidioc_enum_fmt_vid_cap = zr364xx_vidioc_enum_fmt_vid_cap, 767 .vidioc_enum_fmt_vid_cap = zr364xx_vidioc_enum_fmt_vid_cap,
774 .vidioc_try_fmt_vid_cap = zr364xx_vidioc_try_fmt_vid_cap, 768 .vidioc_try_fmt_vid_cap = zr364xx_vidioc_try_fmt_vid_cap,
@@ -784,6 +778,14 @@ static struct video_device zr364xx_template = {
784 .vidioc_s_ctrl = zr364xx_vidioc_s_ctrl, 778 .vidioc_s_ctrl = zr364xx_vidioc_s_ctrl,
785}; 779};
786 780
781static struct video_device zr364xx_template = {
782 .name = DRIVER_DESC,
783 .fops = &zr364xx_fops,
784 .ioctl_ops = &zr364xx_ioctl_ops,
785 .release = video_device_release,
786 .minor = -1,
787};
788
787 789
788 790
789/*******************/ 791/*******************/